1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, 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_Util
; use Exp_Util
;
38 with Fname
; use Fname
;
39 with Freeze
; use Freeze
;
41 with Lib
.Xref
; use Lib
.Xref
;
42 with Namet
.Sp
; use Namet
.Sp
;
43 with Nlists
; use Nlists
;
44 with Nmake
; use Nmake
;
45 with Output
; use Output
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Aux
; use Sem_Aux
;
51 with Sem_Attr
; use Sem_Attr
;
52 with Sem_Ch6
; use Sem_Ch6
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Disp
; use Sem_Disp
;
55 with Sem_Elab
; use Sem_Elab
;
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 Data Structures --
77 ---------------------------
79 Invalid_Binder_Values
: array (Scalar_Id
) of Entity_Id
:= (others => Empty
);
80 -- A collection to hold the entities of the variables declared in package
81 -- System.Scalar_Values which describe the invalid values of scalar types.
83 Invalid_Binder_Values_Set
: Boolean := False;
84 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
86 Invalid_Floats
: array (Float_Scalar_Id
) of Ureal
:= (others => No_Ureal
);
87 -- A collection to hold the invalid values of float types as specified by
88 -- pragma Initialize_Scalars.
90 Invalid_Integers
: array (Integer_Scalar_Id
) of Uint
:= (others => No_Uint
);
91 -- A collection to hold the invalid values of integer types as specified
92 -- by pragma Initialize_Scalars.
94 -----------------------
95 -- Local Subprograms --
96 -----------------------
98 function Build_Component_Subtype
101 T
: Entity_Id
) return Node_Id
;
102 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
103 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
104 -- Loc is the source location, T is the original subtype.
106 procedure Examine_Array_Bounds
108 All_Static
: out Boolean;
109 Has_Empty
: out Boolean);
110 -- Inspect the index constraints of array type Typ. Flag All_Static is set
111 -- when all ranges are static. Flag Has_Empty is set only when All_Static
112 -- is set and indicates that at least one range is empty.
114 function Has_Enabled_Property
115 (Item_Id
: Entity_Id
;
116 Property
: Name_Id
) return Boolean;
117 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
118 -- Determine whether an abstract state or a variable denoted by entity
119 -- Item_Id has enabled property Property.
121 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
122 -- T is a derived tagged type. Check whether the type extension is null.
123 -- If the parent type is fully initialized, T can be treated as such.
125 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
126 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
127 -- with discriminants whose default values are static, examine only the
128 -- components in the selected variant to determine whether all of them
131 type Null_Status_Kind
is
133 -- This value indicates that a subexpression is known to have a null
134 -- value at compile time.
137 -- This value indicates that a subexpression is known to have a non-null
138 -- value at compile time.
141 -- This value indicates that it cannot be determined at compile time
142 -- whether a subexpression yields a null or non-null value.
144 function Null_Status
(N
: Node_Id
) return Null_Status_Kind
;
145 -- Determine whether subexpression N of an access type yields a null value,
146 -- a non-null value, or the value cannot be determined at compile time. The
147 -- routine does not take simple flow diagnostics into account, it relies on
148 -- static facts such as the presence of null exclusions.
150 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean;
151 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean;
152 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
153 -- the time being. New_Requires_Transient_Scope is used by default; the
154 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
155 -- instead. The intent is to use this temporarily to measure before/after
156 -- efficiency. Note: when this temporary code is removed, the documentation
157 -- of dQ in debug.adb should be removed.
159 procedure Results_Differ
163 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
164 -- routine will be removed eventially when New_Requires_Transient_Scope
165 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
168 function Subprogram_Name
(N
: Node_Id
) return String;
169 -- Return the fully qualified name of the enclosing subprogram for the
170 -- given node N, with file:line:col information appended, e.g.
171 -- "subp:file:line:col", corresponding to the source location of the
172 -- body of the subprogram.
174 ------------------------------
175 -- Abstract_Interface_List --
176 ------------------------------
178 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
182 if Is_Concurrent_Type
(Typ
) then
184 -- If we are dealing with a synchronized subtype, go to the base
185 -- type, whose declaration has the interface list.
187 Nod
:= Declaration_Node
(Base_Type
(Typ
));
189 if Nkind_In
(Nod
, N_Full_Type_Declaration
,
190 N_Private_Type_Declaration
)
195 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
196 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
197 Nod
:= Type_Definition
(Parent
(Typ
));
199 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
200 if Present
(Full_View
(Typ
))
202 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
204 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
206 -- If the full-view is not available we cannot do anything else
207 -- here (the source has errors).
213 -- Support for generic formals with interfaces is still missing ???
215 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
220 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
224 elsif Ekind
(Typ
) = E_Record_Subtype
then
225 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
227 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
229 -- Recurse, because parent may still be a private extension. Also
230 -- note that the full view of the subtype or the full view of its
231 -- base type may (both) be unavailable.
233 return Abstract_Interface_List
(Etype
(Typ
));
235 elsif Ekind
(Typ
) = E_Record_Type
then
236 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
237 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
239 Nod
:= Type_Definition
(Parent
(Typ
));
242 -- Otherwise the type is of a kind which does not implement interfaces
248 return Interface_List
(Nod
);
249 end Abstract_Interface_List
;
251 --------------------------------
252 -- Add_Access_Type_To_Process --
253 --------------------------------
255 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
259 Ensure_Freeze_Node
(E
);
260 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
264 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
268 end Add_Access_Type_To_Process
;
270 --------------------------
271 -- Add_Block_Identifier --
272 --------------------------
274 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
275 Loc
: constant Source_Ptr
:= Sloc
(N
);
278 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
280 -- The block already has a label, return its entity
282 if Present
(Identifier
(N
)) then
283 Id
:= Entity
(Identifier
(N
));
285 -- Create a new block label and set its attributes
288 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
289 Set_Etype
(Id
, Standard_Void_Type
);
292 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
293 Set_Block_Node
(Id
, Identifier
(N
));
295 end Add_Block_Identifier
;
297 ----------------------------
298 -- Add_Global_Declaration --
299 ----------------------------
301 procedure Add_Global_Declaration
(N
: Node_Id
) is
302 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
305 if No
(Declarations
(Aux_Node
)) then
306 Set_Declarations
(Aux_Node
, New_List
);
309 Append_To
(Declarations
(Aux_Node
), N
);
311 end Add_Global_Declaration
;
313 --------------------------------
314 -- Address_Integer_Convert_OK --
315 --------------------------------
317 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
319 if Allow_Integer_Address
320 and then ((Is_Descendant_Of_Address
(T1
)
321 and then Is_Private_Type
(T1
)
322 and then Is_Integer_Type
(T2
))
324 (Is_Descendant_Of_Address
(T2
)
325 and then Is_Private_Type
(T2
)
326 and then Is_Integer_Type
(T1
)))
332 end Address_Integer_Convert_OK
;
338 function Address_Value
(N
: Node_Id
) return Node_Id
is
343 -- For constant, get constant expression
345 if Is_Entity_Name
(Expr
)
346 and then Ekind
(Entity
(Expr
)) = E_Constant
348 Expr
:= Constant_Value
(Entity
(Expr
));
350 -- For unchecked conversion, get result to convert
352 elsif Nkind
(Expr
) = N_Unchecked_Type_Conversion
then
353 Expr
:= Expression
(Expr
);
355 -- For (common case) of To_Address call, get argument
357 elsif Nkind
(Expr
) = N_Function_Call
358 and then Is_Entity_Name
(Name
(Expr
))
359 and then Is_RTE
(Entity
(Name
(Expr
)), RE_To_Address
)
361 Expr
:= First
(Parameter_Associations
(Expr
));
363 if Nkind
(Expr
) = N_Parameter_Association
then
364 Expr
:= Explicit_Actual_Parameter
(Expr
);
367 -- We finally have the real expression
381 -- For now, just 8/16/32/64
383 function Addressable
(V
: Uint
) return Boolean is
385 return V
= Uint_8
or else
391 function Addressable
(V
: Int
) return Boolean is
399 ---------------------------------
400 -- Aggregate_Constraint_Checks --
401 ---------------------------------
403 procedure Aggregate_Constraint_Checks
405 Check_Typ
: Entity_Id
)
407 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
410 if Raises_Constraint_Error
(Exp
) then
414 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
415 -- component's type to force the appropriate accessibility checks.
417 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
418 -- force the corresponding run-time check
420 if Is_Access_Type
(Check_Typ
)
421 and then Is_Local_Anonymous_Access
(Check_Typ
)
423 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
424 Analyze_And_Resolve
(Exp
, Check_Typ
);
425 Check_Unset_Reference
(Exp
);
428 -- What follows is really expansion activity, so check that expansion
429 -- is on and is allowed. In GNATprove mode, we also want check flags to
430 -- be added in the tree, so that the formal verification can rely on
431 -- those to be present. In GNATprove mode for formal verification, some
432 -- treatment typically only done during expansion needs to be performed
433 -- on the tree, but it should not be applied inside generics. Otherwise,
434 -- this breaks the name resolution mechanism for generic instances.
436 if not Expander_Active
437 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
442 if Is_Access_Type
(Check_Typ
)
443 and then Can_Never_Be_Null
(Check_Typ
)
444 and then not Can_Never_Be_Null
(Exp_Typ
)
446 Install_Null_Excluding_Check
(Exp
);
449 -- First check if we have to insert discriminant checks
451 if Has_Discriminants
(Exp_Typ
) then
452 Apply_Discriminant_Check
(Exp
, Check_Typ
);
454 -- Next emit length checks for array aggregates
456 elsif Is_Array_Type
(Exp_Typ
) then
457 Apply_Length_Check
(Exp
, Check_Typ
);
459 -- Finally emit scalar and string checks. If we are dealing with a
460 -- scalar literal we need to check by hand because the Etype of
461 -- literals is not necessarily correct.
463 elsif Is_Scalar_Type
(Exp_Typ
)
464 and then Compile_Time_Known_Value
(Exp
)
466 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
467 Apply_Compile_Time_Constraint_Error
468 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
469 Ent
=> Base_Type
(Check_Typ
),
470 Typ
=> Base_Type
(Check_Typ
));
472 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
473 Apply_Compile_Time_Constraint_Error
474 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
478 elsif not Range_Checks_Suppressed
(Check_Typ
) then
479 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
482 -- Verify that target type is also scalar, to prevent view anomalies
483 -- in instantiations.
485 elsif (Is_Scalar_Type
(Exp_Typ
)
486 or else Nkind
(Exp
) = N_String_Literal
)
487 and then Is_Scalar_Type
(Check_Typ
)
488 and then Exp_Typ
/= Check_Typ
490 if Is_Entity_Name
(Exp
)
491 and then Ekind
(Entity
(Exp
)) = E_Constant
493 -- If expression is a constant, it is worthwhile checking whether
494 -- it is a bound of the type.
496 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
497 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
499 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
500 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
505 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
506 Analyze_And_Resolve
(Exp
, Check_Typ
);
507 Check_Unset_Reference
(Exp
);
510 -- Could use a comment on this case ???
513 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
514 Analyze_And_Resolve
(Exp
, Check_Typ
);
515 Check_Unset_Reference
(Exp
);
519 end Aggregate_Constraint_Checks
;
521 -----------------------
522 -- Alignment_In_Bits --
523 -----------------------
525 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
527 return Alignment
(E
) * System_Storage_Unit
;
528 end Alignment_In_Bits
;
530 --------------------------------------
531 -- All_Composite_Constraints_Static --
532 --------------------------------------
534 function All_Composite_Constraints_Static
535 (Constr
: Node_Id
) return Boolean
538 if No
(Constr
) or else Error_Posted
(Constr
) then
542 case Nkind
(Constr
) is
544 if Nkind
(Constr
) in N_Has_Entity
545 and then Present
(Entity
(Constr
))
547 if Is_Type
(Entity
(Constr
)) then
549 not Is_Discrete_Type
(Entity
(Constr
))
550 or else Is_OK_Static_Subtype
(Entity
(Constr
));
553 elsif Nkind
(Constr
) = N_Range
then
555 Is_OK_Static_Expression
(Low_Bound
(Constr
))
557 Is_OK_Static_Expression
(High_Bound
(Constr
));
559 elsif Nkind
(Constr
) = N_Attribute_Reference
560 and then Attribute_Name
(Constr
) = Name_Range
563 Is_OK_Static_Expression
564 (Type_Low_Bound
(Etype
(Prefix
(Constr
))))
566 Is_OK_Static_Expression
567 (Type_High_Bound
(Etype
(Prefix
(Constr
))));
571 not Present
(Etype
(Constr
)) -- previous error
572 or else not Is_Discrete_Type
(Etype
(Constr
))
573 or else Is_OK_Static_Expression
(Constr
);
575 when N_Discriminant_Association
=>
576 return All_Composite_Constraints_Static
(Expression
(Constr
));
578 when N_Range_Constraint
=>
580 All_Composite_Constraints_Static
(Range_Expression
(Constr
));
582 when N_Index_Or_Discriminant_Constraint
=>
584 One_Cstr
: Entity_Id
;
586 One_Cstr
:= First
(Constraints
(Constr
));
587 while Present
(One_Cstr
) loop
588 if not All_Composite_Constraints_Static
(One_Cstr
) then
598 when N_Subtype_Indication
=>
600 All_Composite_Constraints_Static
(Subtype_Mark
(Constr
))
602 All_Composite_Constraints_Static
(Constraint
(Constr
));
607 end All_Composite_Constraints_Static
;
609 ------------------------
610 -- Append_Entity_Name --
611 ------------------------
613 procedure Append_Entity_Name
(Buf
: in out Bounded_String
; E
: Entity_Id
) is
614 Temp
: Bounded_String
;
616 procedure Inner
(E
: Entity_Id
);
617 -- Inner recursive routine, keep outer routine nonrecursive to ease
618 -- debugging when we get strange results from this routine.
624 procedure Inner
(E
: Entity_Id
) is
628 -- If entity has an internal name, skip by it, and print its scope.
629 -- Note that we strip a final R from the name before the test; this
630 -- is needed for some cases of instantiations.
633 E_Name
: Bounded_String
;
636 Append
(E_Name
, Chars
(E
));
638 if E_Name
.Chars
(E_Name
.Length
) = 'R' then
639 E_Name
.Length
:= E_Name
.Length
- 1;
642 if Is_Internal_Name
(E_Name
) then
650 -- Just print entity name if its scope is at the outer level
652 if Scop
= Standard_Standard
then
655 -- If scope comes from source, write scope and entity
657 elsif Comes_From_Source
(Scop
) then
658 Append_Entity_Name
(Temp
, Scop
);
661 -- If in wrapper package skip past it
663 elsif Present
(Scop
) and then Is_Wrapper_Package
(Scop
) then
664 Append_Entity_Name
(Temp
, Scope
(Scop
));
667 -- Otherwise nothing to output (happens in unnamed block statements)
676 E_Name
: Bounded_String
;
679 Append_Unqualified_Decoded
(E_Name
, Chars
(E
));
681 -- Remove trailing upper-case letters from the name (useful for
682 -- dealing with some cases of internal names generated in the case
683 -- of references from within a generic).
685 while E_Name
.Length
> 1
686 and then E_Name
.Chars
(E_Name
.Length
) in 'A' .. 'Z'
688 E_Name
.Length
:= E_Name
.Length
- 1;
691 -- Adjust casing appropriately (gets name from source if possible)
693 Adjust_Name_Case
(E_Name
, Sloc
(E
));
694 Append
(Temp
, E_Name
);
698 -- Start of processing for Append_Entity_Name
703 end Append_Entity_Name
;
705 ---------------------------------
706 -- Append_Inherited_Subprogram --
707 ---------------------------------
709 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
710 Par
: constant Entity_Id
:= Alias
(S
);
711 -- The parent subprogram
713 Scop
: constant Entity_Id
:= Scope
(Par
);
714 -- The scope of definition of the parent subprogram
716 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
717 -- The derived type of which S is a primitive operation
723 if Ekind
(Current_Scope
) = E_Package
724 and then In_Private_Part
(Current_Scope
)
725 and then Has_Private_Declaration
(Typ
)
726 and then Is_Tagged_Type
(Typ
)
727 and then Scop
= Current_Scope
729 -- The inherited operation is available at the earliest place after
730 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
731 -- relevant for type extensions. If the parent operation appears
732 -- after the type extension, the operation is not visible.
735 (Visible_Declarations
736 (Package_Specification
(Current_Scope
)));
737 while Present
(Decl
) loop
738 if Nkind
(Decl
) = N_Private_Extension_Declaration
739 and then Defining_Entity
(Decl
) = Typ
741 if Sloc
(Decl
) > Sloc
(Par
) then
742 Next_E
:= Next_Entity
(Par
);
743 Link_Entities
(Par
, S
);
744 Link_Entities
(S
, Next_E
);
756 -- If partial view is not a type extension, or it appears before the
757 -- subprogram declaration, insert normally at end of entity list.
759 Append_Entity
(S
, Current_Scope
);
760 end Append_Inherited_Subprogram
;
762 -----------------------------------------
763 -- Apply_Compile_Time_Constraint_Error --
764 -----------------------------------------
766 procedure Apply_Compile_Time_Constraint_Error
769 Reason
: RT_Exception_Code
;
770 Ent
: Entity_Id
:= Empty
;
771 Typ
: Entity_Id
:= Empty
;
772 Loc
: Source_Ptr
:= No_Location
;
773 Rep
: Boolean := True;
774 Warn
: Boolean := False)
776 Stat
: constant Boolean := Is_Static_Expression
(N
);
777 R_Stat
: constant Node_Id
:=
778 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
789 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
791 -- In GNATprove mode, do not replace the node with an exception raised.
792 -- In such a case, either the call to Compile_Time_Constraint_Error
793 -- issues an error which stops analysis, or it issues a warning in
794 -- a few cases where a suitable check flag is set for GNATprove to
795 -- generate a check message.
797 if not Rep
or GNATprove_Mode
then
801 -- Now we replace the node by an N_Raise_Constraint_Error node
802 -- This does not need reanalyzing, so set it as analyzed now.
805 Set_Analyzed
(N
, True);
808 Set_Raises_Constraint_Error
(N
);
810 -- Now deal with possible local raise handling
812 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
814 -- If the original expression was marked as static, the result is
815 -- still marked as static, but the Raises_Constraint_Error flag is
816 -- always set so that further static evaluation is not attempted.
819 Set_Is_Static_Expression
(N
);
821 end Apply_Compile_Time_Constraint_Error
;
823 ---------------------------
824 -- Async_Readers_Enabled --
825 ---------------------------
827 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
829 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
830 end Async_Readers_Enabled
;
832 ---------------------------
833 -- Async_Writers_Enabled --
834 ---------------------------
836 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
838 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
839 end Async_Writers_Enabled
;
841 --------------------------------------
842 -- Available_Full_View_Of_Component --
843 --------------------------------------
845 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
846 ST
: constant Entity_Id
:= Scope
(T
);
847 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
849 return In_Open_Scopes
(ST
)
850 and then In_Open_Scopes
(SCT
)
851 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
852 end Available_Full_View_Of_Component
;
858 procedure Bad_Attribute
861 Warn
: Boolean := False)
864 Error_Msg_Warn
:= Warn
;
865 Error_Msg_N
("unrecognized attribute&<<", N
);
867 -- Check for possible misspelling
869 Error_Msg_Name_1
:= First_Attribute_Name
;
870 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
871 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
872 Error_Msg_N
-- CODEFIX
873 ("\possible misspelling of %<<", N
);
877 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
881 --------------------------------
882 -- Bad_Predicated_Subtype_Use --
883 --------------------------------
885 procedure Bad_Predicated_Subtype_Use
889 Suggest_Static
: Boolean := False)
894 -- Avoid cascaded errors
896 if Error_Posted
(N
) then
900 if Inside_A_Generic
then
901 Gen
:= Current_Scope
;
902 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
910 if Is_Generic_Formal
(Typ
) and then Is_Discrete_Type
(Typ
) then
911 Set_No_Predicate_On_Actual
(Typ
);
914 elsif Has_Predicates
(Typ
) then
915 if Is_Generic_Actual_Type
(Typ
) then
917 -- The restriction on loop parameters is only that the type
918 -- should have no dynamic predicates.
920 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
921 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
922 and then Is_OK_Static_Subtype
(Typ
)
927 Gen
:= Current_Scope
;
928 while not Is_Generic_Instance
(Gen
) loop
932 pragma Assert
(Present
(Gen
));
934 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
935 Error_Msg_Warn
:= SPARK_Mode
/= On
;
936 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
937 Error_Msg_F
("\Program_Error [<<", N
);
940 Make_Raise_Program_Error
(Sloc
(N
),
941 Reason
=> PE_Bad_Predicated_Generic_Type
));
944 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
948 Error_Msg_FE
(Msg
, N
, Typ
);
951 -- Emit an optional suggestion on how to remedy the error if the
952 -- context warrants it.
954 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
955 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
958 end Bad_Predicated_Subtype_Use
;
960 -----------------------------------------
961 -- Bad_Unordered_Enumeration_Reference --
962 -----------------------------------------
964 function Bad_Unordered_Enumeration_Reference
966 T
: Entity_Id
) return Boolean
969 return Is_Enumeration_Type
(T
)
970 and then Warn_On_Unordered_Enumeration_Type
971 and then not Is_Generic_Type
(T
)
972 and then Comes_From_Source
(N
)
973 and then not Has_Pragma_Ordered
(T
)
974 and then not In_Same_Extended_Unit
(N
, T
);
975 end Bad_Unordered_Enumeration_Reference
;
977 ----------------------------
978 -- Begin_Keyword_Location --
979 ----------------------------
981 function Begin_Keyword_Location
(N
: Node_Id
) return Source_Ptr
is
985 pragma Assert
(Nkind_In
(N
, N_Block_Statement
,
991 HSS
:= Handled_Statement_Sequence
(N
);
993 -- When the handled sequence of statements comes from source, the
994 -- location of the "begin" keyword is that of the sequence itself.
995 -- Note that an internal construct may inherit a source sequence.
997 if Comes_From_Source
(HSS
) then
1000 -- The parser generates an internal handled sequence of statements to
1001 -- capture the location of the "begin" keyword if present in the source.
1002 -- Since there are no source statements, the location of the "begin"
1003 -- keyword is effectively that of the "end" keyword.
1005 elsif Comes_From_Source
(N
) then
1008 -- Otherwise the construct is internal and should carry the location of
1009 -- the original construct which prompted its creation.
1014 end Begin_Keyword_Location
;
1016 --------------------------
1017 -- Build_Actual_Subtype --
1018 --------------------------
1020 function Build_Actual_Subtype
1022 N
: Node_Or_Entity_Id
) return Node_Id
1025 -- Normally Sloc (N), but may point to corresponding body in some cases
1027 Constraints
: List_Id
;
1033 Disc_Type
: Entity_Id
;
1039 if Nkind
(N
) = N_Defining_Identifier
then
1040 Obj
:= New_Occurrence_Of
(N
, Loc
);
1042 -- If this is a formal parameter of a subprogram declaration, and
1043 -- we are compiling the body, we want the declaration for the
1044 -- actual subtype to carry the source position of the body, to
1045 -- prevent anomalies in gdb when stepping through the code.
1047 if Is_Formal
(N
) then
1049 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
1051 if Nkind
(Decl
) = N_Subprogram_Declaration
1052 and then Present
(Corresponding_Body
(Decl
))
1054 Loc
:= Sloc
(Corresponding_Body
(Decl
));
1063 if Is_Array_Type
(T
) then
1064 Constraints
:= New_List
;
1065 for J
in 1 .. Number_Dimensions
(T
) loop
1067 -- Build an array subtype declaration with the nominal subtype and
1068 -- the bounds of the actual. Add the declaration in front of the
1069 -- local declarations for the subprogram, for analysis before any
1070 -- reference to the formal in the body.
1073 Make_Attribute_Reference
(Loc
,
1075 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
1076 Attribute_Name
=> Name_First
,
1077 Expressions
=> New_List
(
1078 Make_Integer_Literal
(Loc
, J
)));
1081 Make_Attribute_Reference
(Loc
,
1083 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
1084 Attribute_Name
=> Name_Last
,
1085 Expressions
=> New_List
(
1086 Make_Integer_Literal
(Loc
, J
)));
1088 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1091 -- If the type has unknown discriminants there is no constrained
1092 -- subtype to build. This is never called for a formal or for a
1093 -- lhs, so returning the type is ok ???
1095 elsif Has_Unknown_Discriminants
(T
) then
1099 Constraints
:= New_List
;
1101 -- Type T is a generic derived type, inherit the discriminants from
1104 if Is_Private_Type
(T
)
1105 and then No
(Full_View
(T
))
1107 -- T was flagged as an error if it was declared as a formal
1108 -- derived type with known discriminants. In this case there
1109 -- is no need to look at the parent type since T already carries
1110 -- its own discriminants.
1112 and then not Error_Posted
(T
)
1114 Disc_Type
:= Etype
(Base_Type
(T
));
1119 Discr
:= First_Discriminant
(Disc_Type
);
1120 while Present
(Discr
) loop
1121 Append_To
(Constraints
,
1122 Make_Selected_Component
(Loc
,
1124 Duplicate_Subexpr_No_Checks
(Obj
),
1125 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
1126 Next_Discriminant
(Discr
);
1130 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
1131 Set_Is_Internal
(Subt
);
1134 Make_Subtype_Declaration
(Loc
,
1135 Defining_Identifier
=> Subt
,
1136 Subtype_Indication
=>
1137 Make_Subtype_Indication
(Loc
,
1138 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
1140 Make_Index_Or_Discriminant_Constraint
(Loc
,
1141 Constraints
=> Constraints
)));
1143 Mark_Rewrite_Insertion
(Decl
);
1145 end Build_Actual_Subtype
;
1147 ---------------------------------------
1148 -- Build_Actual_Subtype_Of_Component --
1149 ---------------------------------------
1151 function Build_Actual_Subtype_Of_Component
1153 N
: Node_Id
) return Node_Id
1155 Loc
: constant Source_Ptr
:= Sloc
(N
);
1156 P
: constant Node_Id
:= Prefix
(N
);
1159 Index_Typ
: Entity_Id
;
1161 Desig_Typ
: Entity_Id
;
1162 -- This is either a copy of T, or if T is an access type, then it is
1163 -- the directly designated type of this access type.
1165 function Build_Actual_Array_Constraint
return List_Id
;
1166 -- If one or more of the bounds of the component depends on
1167 -- discriminants, build actual constraint using the discriminants
1170 function Build_Actual_Record_Constraint
return List_Id
;
1171 -- Similar to previous one, for discriminated components constrained
1172 -- by the discriminant of the enclosing object.
1174 -----------------------------------
1175 -- Build_Actual_Array_Constraint --
1176 -----------------------------------
1178 function Build_Actual_Array_Constraint
return List_Id
is
1179 Constraints
: constant List_Id
:= New_List
;
1187 Indx
:= First_Index
(Desig_Typ
);
1188 while Present
(Indx
) loop
1189 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1190 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1192 if Denotes_Discriminant
(Old_Lo
) then
1194 Make_Selected_Component
(Loc
,
1195 Prefix
=> New_Copy_Tree
(P
),
1196 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1199 Lo
:= New_Copy_Tree
(Old_Lo
);
1201 -- The new bound will be reanalyzed in the enclosing
1202 -- declaration. For literal bounds that come from a type
1203 -- declaration, the type of the context must be imposed, so
1204 -- insure that analysis will take place. For non-universal
1205 -- types this is not strictly necessary.
1207 Set_Analyzed
(Lo
, False);
1210 if Denotes_Discriminant
(Old_Hi
) then
1212 Make_Selected_Component
(Loc
,
1213 Prefix
=> New_Copy_Tree
(P
),
1214 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1217 Hi
:= New_Copy_Tree
(Old_Hi
);
1218 Set_Analyzed
(Hi
, False);
1221 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1226 end Build_Actual_Array_Constraint
;
1228 ------------------------------------
1229 -- Build_Actual_Record_Constraint --
1230 ------------------------------------
1232 function Build_Actual_Record_Constraint
return List_Id
is
1233 Constraints
: constant List_Id
:= New_List
;
1238 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1239 while Present
(D
) loop
1240 if Denotes_Discriminant
(Node
(D
)) then
1241 D_Val
:= Make_Selected_Component
(Loc
,
1242 Prefix
=> New_Copy_Tree
(P
),
1243 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1246 D_Val
:= New_Copy_Tree
(Node
(D
));
1249 Append
(D_Val
, Constraints
);
1254 end Build_Actual_Record_Constraint
;
1256 -- Start of processing for Build_Actual_Subtype_Of_Component
1259 -- Why the test for Spec_Expression mode here???
1261 if In_Spec_Expression
then
1264 -- More comments for the rest of this body would be good ???
1266 elsif Nkind
(N
) = N_Explicit_Dereference
then
1267 if Is_Composite_Type
(T
)
1268 and then not Is_Constrained
(T
)
1269 and then not (Is_Class_Wide_Type
(T
)
1270 and then Is_Constrained
(Root_Type
(T
)))
1271 and then not Has_Unknown_Discriminants
(T
)
1273 -- If the type of the dereference is already constrained, it is an
1276 if Is_Array_Type
(Etype
(N
))
1277 and then Is_Constrained
(Etype
(N
))
1281 Remove_Side_Effects
(P
);
1282 return Build_Actual_Subtype
(T
, N
);
1289 if Ekind
(T
) = E_Access_Subtype
then
1290 Desig_Typ
:= Designated_Type
(T
);
1295 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1296 Id
:= First_Index
(Desig_Typ
);
1297 while Present
(Id
) loop
1298 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1300 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1302 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1304 Remove_Side_Effects
(P
);
1306 Build_Component_Subtype
1307 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1313 elsif Is_Composite_Type
(Desig_Typ
)
1314 and then Has_Discriminants
(Desig_Typ
)
1315 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1317 if Is_Private_Type
(Desig_Typ
)
1318 and then No
(Discriminant_Constraint
(Desig_Typ
))
1320 Desig_Typ
:= Full_View
(Desig_Typ
);
1323 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1324 while Present
(D
) loop
1325 if Denotes_Discriminant
(Node
(D
)) then
1326 Remove_Side_Effects
(P
);
1328 Build_Component_Subtype
(
1329 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1336 -- If none of the above, the actual and nominal subtypes are the same
1339 end Build_Actual_Subtype_Of_Component
;
1341 ---------------------------------
1342 -- Build_Class_Wide_Clone_Body --
1343 ---------------------------------
1345 procedure Build_Class_Wide_Clone_Body
1346 (Spec_Id
: Entity_Id
;
1349 Loc
: constant Source_Ptr
:= Sloc
(Bod
);
1350 Clone_Id
: constant Entity_Id
:= Class_Wide_Clone
(Spec_Id
);
1351 Clone_Body
: Node_Id
;
1354 -- The declaration of the class-wide clone was created when the
1355 -- corresponding class-wide condition was analyzed.
1358 Make_Subprogram_Body
(Loc
,
1360 Copy_Subprogram_Spec
(Parent
(Clone_Id
)),
1361 Declarations
=> Declarations
(Bod
),
1362 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(Bod
));
1364 -- The new operation is internal and overriding indicators do not apply
1365 -- (the original primitive may have carried one).
1367 Set_Must_Override
(Specification
(Clone_Body
), False);
1369 -- If the subprogram body is the proper body of a stub, insert the
1370 -- subprogram after the stub, i.e. the same declarative region as
1371 -- the original sugprogram.
1373 if Nkind
(Parent
(Bod
)) = N_Subunit
then
1374 Insert_After
(Corresponding_Stub
(Parent
(Bod
)), Clone_Body
);
1377 Insert_Before
(Bod
, Clone_Body
);
1380 Analyze
(Clone_Body
);
1381 end Build_Class_Wide_Clone_Body
;
1383 ---------------------------------
1384 -- Build_Class_Wide_Clone_Call --
1385 ---------------------------------
1387 function Build_Class_Wide_Clone_Call
1390 Spec_Id
: Entity_Id
;
1391 Spec
: Node_Id
) return Node_Id
1393 Clone_Id
: constant Entity_Id
:= Class_Wide_Clone
(Spec_Id
);
1394 Par_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Spec_Id
);
1400 New_F_Spec
: Entity_Id
;
1401 New_Formal
: Entity_Id
;
1404 Actuals
:= Empty_List
;
1405 Formal
:= First_Formal
(Spec_Id
);
1406 New_F_Spec
:= First
(Parameter_Specifications
(Spec
));
1408 -- Build parameter association for call to class-wide clone.
1410 while Present
(Formal
) loop
1411 New_Formal
:= Defining_Identifier
(New_F_Spec
);
1413 -- If controlling argument and operation is inherited, add conversion
1414 -- to parent type for the call.
1416 if Etype
(Formal
) = Par_Type
1417 and then not Is_Empty_List
(Decls
)
1420 Make_Type_Conversion
(Loc
,
1421 New_Occurrence_Of
(Par_Type
, Loc
),
1422 New_Occurrence_Of
(New_Formal
, Loc
)));
1425 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1428 Next_Formal
(Formal
);
1432 if Ekind
(Spec_Id
) = E_Procedure
then
1434 Make_Procedure_Call_Statement
(Loc
,
1435 Name
=> New_Occurrence_Of
(Clone_Id
, Loc
),
1436 Parameter_Associations
=> Actuals
);
1439 Make_Simple_Return_Statement
(Loc
,
1441 Make_Function_Call
(Loc
,
1442 Name
=> New_Occurrence_Of
(Clone_Id
, Loc
),
1443 Parameter_Associations
=> Actuals
));
1447 Make_Subprogram_Body
(Loc
,
1449 Copy_Subprogram_Spec
(Spec
),
1450 Declarations
=> Decls
,
1451 Handled_Statement_Sequence
=>
1452 Make_Handled_Sequence_Of_Statements
(Loc
,
1453 Statements
=> New_List
(Call
),
1454 End_Label
=> Make_Identifier
(Loc
, Chars
(Spec_Id
))));
1457 end Build_Class_Wide_Clone_Call
;
1459 ---------------------------------
1460 -- Build_Class_Wide_Clone_Decl --
1461 ---------------------------------
1463 procedure Build_Class_Wide_Clone_Decl
(Spec_Id
: Entity_Id
) is
1464 Loc
: constant Source_Ptr
:= Sloc
(Spec_Id
);
1465 Clone_Id
: constant Entity_Id
:=
1466 Make_Defining_Identifier
(Loc
,
1467 New_External_Name
(Chars
(Spec_Id
), Suffix
=> "CL"));
1473 Spec
:= Copy_Subprogram_Spec
(Parent
(Spec_Id
));
1474 Set_Must_Override
(Spec
, False);
1475 Set_Must_Not_Override
(Spec
, False);
1476 Set_Defining_Unit_Name
(Spec
, Clone_Id
);
1478 Decl
:= Make_Subprogram_Declaration
(Loc
, Spec
);
1479 Append
(Decl
, List_Containing
(Unit_Declaration_Node
(Spec_Id
)));
1481 -- Link clone to original subprogram, for use when building body and
1482 -- wrapper call to inherited operation.
1484 Set_Class_Wide_Clone
(Spec_Id
, Clone_Id
);
1485 end Build_Class_Wide_Clone_Decl
;
1487 -----------------------------
1488 -- Build_Component_Subtype --
1489 -----------------------------
1491 function Build_Component_Subtype
1494 T
: Entity_Id
) return Node_Id
1500 -- Unchecked_Union components do not require component subtypes
1502 if Is_Unchecked_Union
(T
) then
1506 Subt
:= Make_Temporary
(Loc
, 'S');
1507 Set_Is_Internal
(Subt
);
1510 Make_Subtype_Declaration
(Loc
,
1511 Defining_Identifier
=> Subt
,
1512 Subtype_Indication
=>
1513 Make_Subtype_Indication
(Loc
,
1514 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1516 Make_Index_Or_Discriminant_Constraint
(Loc
,
1517 Constraints
=> C
)));
1519 Mark_Rewrite_Insertion
(Decl
);
1521 end Build_Component_Subtype
;
1523 ---------------------------
1524 -- Build_Default_Subtype --
1525 ---------------------------
1527 function Build_Default_Subtype
1529 N
: Node_Id
) return Entity_Id
1531 Loc
: constant Source_Ptr
:= Sloc
(N
);
1535 -- The base type that is to be constrained by the defaults
1538 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1542 Bas
:= Base_Type
(T
);
1544 -- If T is non-private but its base type is private, this is the
1545 -- completion of a subtype declaration whose parent type is private
1546 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1547 -- are to be found in the full view of the base. Check that the private
1548 -- status of T and its base differ.
1550 if Is_Private_Type
(Bas
)
1551 and then not Is_Private_Type
(T
)
1552 and then Present
(Full_View
(Bas
))
1554 Bas
:= Full_View
(Bas
);
1557 Disc
:= First_Discriminant
(T
);
1559 if No
(Discriminant_Default_Value
(Disc
)) then
1564 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1565 Constraints
: constant List_Id
:= New_List
;
1569 while Present
(Disc
) loop
1570 Append_To
(Constraints
,
1571 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1572 Next_Discriminant
(Disc
);
1576 Make_Subtype_Declaration
(Loc
,
1577 Defining_Identifier
=> Act
,
1578 Subtype_Indication
=>
1579 Make_Subtype_Indication
(Loc
,
1580 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1582 Make_Index_Or_Discriminant_Constraint
(Loc
,
1583 Constraints
=> Constraints
)));
1585 Insert_Action
(N
, Decl
);
1587 -- If the context is a component declaration the subtype declaration
1588 -- will be analyzed when the enclosing type is frozen, otherwise do
1591 if Ekind
(Current_Scope
) /= E_Record_Type
then
1597 end Build_Default_Subtype
;
1599 --------------------------------------------
1600 -- Build_Discriminal_Subtype_Of_Component --
1601 --------------------------------------------
1603 function Build_Discriminal_Subtype_Of_Component
1604 (T
: Entity_Id
) return Node_Id
1606 Loc
: constant Source_Ptr
:= Sloc
(T
);
1610 function Build_Discriminal_Array_Constraint
return List_Id
;
1611 -- If one or more of the bounds of the component depends on
1612 -- discriminants, build actual constraint using the discriminants
1615 function Build_Discriminal_Record_Constraint
return List_Id
;
1616 -- Similar to previous one, for discriminated components constrained by
1617 -- the discriminant of the enclosing object.
1619 ----------------------------------------
1620 -- Build_Discriminal_Array_Constraint --
1621 ----------------------------------------
1623 function Build_Discriminal_Array_Constraint
return List_Id
is
1624 Constraints
: constant List_Id
:= New_List
;
1632 Indx
:= First_Index
(T
);
1633 while Present
(Indx
) loop
1634 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1635 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1637 if Denotes_Discriminant
(Old_Lo
) then
1638 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1641 Lo
:= New_Copy_Tree
(Old_Lo
);
1644 if Denotes_Discriminant
(Old_Hi
) then
1645 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1648 Hi
:= New_Copy_Tree
(Old_Hi
);
1651 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1656 end Build_Discriminal_Array_Constraint
;
1658 -----------------------------------------
1659 -- Build_Discriminal_Record_Constraint --
1660 -----------------------------------------
1662 function Build_Discriminal_Record_Constraint
return List_Id
is
1663 Constraints
: constant List_Id
:= New_List
;
1668 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1669 while Present
(D
) loop
1670 if Denotes_Discriminant
(Node
(D
)) then
1672 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1674 D_Val
:= New_Copy_Tree
(Node
(D
));
1677 Append
(D_Val
, Constraints
);
1682 end Build_Discriminal_Record_Constraint
;
1684 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1687 if Ekind
(T
) = E_Array_Subtype
then
1688 Id
:= First_Index
(T
);
1689 while Present
(Id
) loop
1690 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1692 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1694 return Build_Component_Subtype
1695 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1701 elsif Ekind
(T
) = E_Record_Subtype
1702 and then Has_Discriminants
(T
)
1703 and then not Has_Unknown_Discriminants
(T
)
1705 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1706 while Present
(D
) loop
1707 if Denotes_Discriminant
(Node
(D
)) then
1708 return Build_Component_Subtype
1709 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1716 -- If none of the above, the actual and nominal subtypes are the same
1719 end Build_Discriminal_Subtype_Of_Component
;
1721 ------------------------------
1722 -- Build_Elaboration_Entity --
1723 ------------------------------
1725 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1726 Loc
: constant Source_Ptr
:= Sloc
(N
);
1728 Elab_Ent
: Entity_Id
;
1730 procedure Set_Package_Name
(Ent
: Entity_Id
);
1731 -- Given an entity, sets the fully qualified name of the entity in
1732 -- Name_Buffer, with components separated by double underscores. This
1733 -- is a recursive routine that climbs the scope chain to Standard.
1735 ----------------------
1736 -- Set_Package_Name --
1737 ----------------------
1739 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1741 if Scope
(Ent
) /= Standard_Standard
then
1742 Set_Package_Name
(Scope
(Ent
));
1745 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1747 Name_Buffer
(Name_Len
+ 1) := '_';
1748 Name_Buffer
(Name_Len
+ 2) := '_';
1749 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1750 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1754 Get_Name_String
(Chars
(Ent
));
1756 end Set_Package_Name
;
1758 -- Start of processing for Build_Elaboration_Entity
1761 -- Ignore call if already constructed
1763 if Present
(Elaboration_Entity
(Spec_Id
)) then
1766 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1767 -- no role in analysis.
1769 elsif ASIS_Mode
then
1772 -- Do not generate an elaboration entity in GNATprove move because the
1773 -- elaboration counter is a form of expansion.
1775 elsif GNATprove_Mode
then
1778 -- See if we need elaboration entity
1780 -- We always need an elaboration entity when preserving control flow, as
1781 -- we want to remain explicit about the unit's elaboration order.
1783 elsif Opt
.Suppress_Control_Flow_Optimizations
then
1786 -- We always need an elaboration entity for the dynamic elaboration
1787 -- model, since it is needed to properly generate the PE exception for
1788 -- access before elaboration.
1790 elsif Dynamic_Elaboration_Checks
then
1793 -- For the static model, we don't need the elaboration counter if this
1794 -- unit is sure to have no elaboration code, since that means there
1795 -- is no elaboration unit to be called. Note that we can't just decide
1796 -- after the fact by looking to see whether there was elaboration code,
1797 -- because that's too late to make this decision.
1799 elsif Restriction_Active
(No_Elaboration_Code
) then
1802 -- Similarly, for the static model, we can skip the elaboration counter
1803 -- if we have the No_Multiple_Elaboration restriction, since for the
1804 -- static model, that's the only purpose of the counter (to avoid
1805 -- multiple elaboration).
1807 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1811 -- Here we need the elaboration entity
1813 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1814 -- name with dots replaced by double underscore. We have to manually
1815 -- construct this name, since it will be elaborated in the outer scope,
1816 -- and thus will not have the unit name automatically prepended.
1818 Set_Package_Name
(Spec_Id
);
1819 Add_Str_To_Name_Buffer
("_E");
1821 -- Create elaboration counter
1823 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1824 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1827 Make_Object_Declaration
(Loc
,
1828 Defining_Identifier
=> Elab_Ent
,
1829 Object_Definition
=>
1830 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1831 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1833 Push_Scope
(Standard_Standard
);
1834 Add_Global_Declaration
(Decl
);
1837 -- Reset True_Constant indication, since we will indeed assign a value
1838 -- to the variable in the binder main. We also kill the Current_Value
1839 -- and Last_Assignment fields for the same reason.
1841 Set_Is_True_Constant
(Elab_Ent
, False);
1842 Set_Current_Value
(Elab_Ent
, Empty
);
1843 Set_Last_Assignment
(Elab_Ent
, Empty
);
1845 -- We do not want any further qualification of the name (if we did not
1846 -- do this, we would pick up the name of the generic package in the case
1847 -- of a library level generic instantiation).
1849 Set_Has_Qualified_Name
(Elab_Ent
);
1850 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1851 end Build_Elaboration_Entity
;
1853 --------------------------------
1854 -- Build_Explicit_Dereference --
1855 --------------------------------
1857 procedure Build_Explicit_Dereference
1861 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1866 -- An entity of a type with a reference aspect is overloaded with
1867 -- both interpretations: with and without the dereference. Now that
1868 -- the dereference is made explicit, set the type of the node properly,
1869 -- to prevent anomalies in the backend. Same if the expression is an
1870 -- overloaded function call whose return type has a reference aspect.
1872 if Is_Entity_Name
(Expr
) then
1873 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1875 -- The designated entity will not be examined again when resolving
1876 -- the dereference, so generate a reference to it now.
1878 Generate_Reference
(Entity
(Expr
), Expr
);
1880 elsif Nkind
(Expr
) = N_Function_Call
then
1882 -- If the name of the indexing function is overloaded, locate the one
1883 -- whose return type has an implicit dereference on the desired
1884 -- discriminant, and set entity and type of function call.
1886 if Is_Overloaded
(Name
(Expr
)) then
1887 Get_First_Interp
(Name
(Expr
), I
, It
);
1889 while Present
(It
.Nam
) loop
1890 if Ekind
((It
.Typ
)) = E_Record_Type
1891 and then First_Entity
((It
.Typ
)) = Disc
1893 Set_Entity
(Name
(Expr
), It
.Nam
);
1894 Set_Etype
(Name
(Expr
), Etype
(It
.Nam
));
1898 Get_Next_Interp
(I
, It
);
1902 -- Set type of call from resolved function name.
1904 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1907 Set_Is_Overloaded
(Expr
, False);
1909 -- The expression will often be a generalized indexing that yields a
1910 -- container element that is then dereferenced, in which case the
1911 -- generalized indexing call is also non-overloaded.
1913 if Nkind
(Expr
) = N_Indexed_Component
1914 and then Present
(Generalized_Indexing
(Expr
))
1916 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1920 Make_Explicit_Dereference
(Loc
,
1922 Make_Selected_Component
(Loc
,
1923 Prefix
=> Relocate_Node
(Expr
),
1924 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1925 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1926 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1927 end Build_Explicit_Dereference
;
1929 ---------------------------
1930 -- Build_Overriding_Spec --
1931 ---------------------------
1933 function Build_Overriding_Spec
1935 Typ
: Entity_Id
) return Node_Id
1937 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1938 Par_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Op
);
1939 Spec
: constant Node_Id
:= Specification
(Unit_Declaration_Node
(Op
));
1941 Formal_Spec
: Node_Id
;
1942 Formal_Type
: Node_Id
;
1946 New_Spec
:= Copy_Subprogram_Spec
(Spec
);
1948 Formal_Spec
:= First
(Parameter_Specifications
(New_Spec
));
1949 while Present
(Formal_Spec
) loop
1950 Formal_Type
:= Parameter_Type
(Formal_Spec
);
1952 if Is_Entity_Name
(Formal_Type
)
1953 and then Entity
(Formal_Type
) = Par_Typ
1955 Rewrite
(Formal_Type
, New_Occurrence_Of
(Typ
, Loc
));
1958 -- Nothing needs to be done for access parameters
1964 end Build_Overriding_Spec
;
1966 -----------------------------------
1967 -- Cannot_Raise_Constraint_Error --
1968 -----------------------------------
1970 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1972 if Compile_Time_Known_Value
(Expr
) then
1975 elsif Do_Range_Check
(Expr
) then
1978 elsif Raises_Constraint_Error
(Expr
) then
1982 case Nkind
(Expr
) is
1983 when N_Identifier
=>
1986 when N_Expanded_Name
=>
1989 when N_Selected_Component
=>
1990 return not Do_Discriminant_Check
(Expr
);
1992 when N_Attribute_Reference
=>
1993 if Do_Overflow_Check
(Expr
) then
1996 elsif No
(Expressions
(Expr
)) then
2004 N
:= First
(Expressions
(Expr
));
2005 while Present
(N
) loop
2006 if Cannot_Raise_Constraint_Error
(N
) then
2017 when N_Type_Conversion
=>
2018 if Do_Overflow_Check
(Expr
)
2019 or else Do_Length_Check
(Expr
)
2020 or else Do_Tag_Check
(Expr
)
2024 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
2027 when N_Unchecked_Type_Conversion
=>
2028 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
2031 if Do_Overflow_Check
(Expr
) then
2034 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2041 if Do_Division_Check
(Expr
)
2043 Do_Overflow_Check
(Expr
)
2048 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
2050 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2069 | N_Op_Shift_Right_Arithmetic
2073 if Do_Overflow_Check
(Expr
) then
2077 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
2079 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2086 end Cannot_Raise_Constraint_Error
;
2088 -----------------------------------------
2089 -- Check_Dynamically_Tagged_Expression --
2090 -----------------------------------------
2092 procedure Check_Dynamically_Tagged_Expression
2095 Related_Nod
: Node_Id
)
2098 pragma Assert
(Is_Tagged_Type
(Typ
));
2100 -- In order to avoid spurious errors when analyzing the expanded code,
2101 -- this check is done only for nodes that come from source and for
2102 -- actuals of generic instantiations.
2104 if (Comes_From_Source
(Related_Nod
)
2105 or else In_Generic_Actual
(Expr
))
2106 and then (Is_Class_Wide_Type
(Etype
(Expr
))
2107 or else Is_Dynamically_Tagged
(Expr
))
2108 and then not Is_Class_Wide_Type
(Typ
)
2110 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
2112 end Check_Dynamically_Tagged_Expression
;
2114 --------------------------
2115 -- Check_Fully_Declared --
2116 --------------------------
2118 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
2120 if Ekind
(T
) = E_Incomplete_Type
then
2122 -- Ada 2005 (AI-50217): If the type is available through a limited
2123 -- with_clause, verify that its full view has been analyzed.
2125 if From_Limited_With
(T
)
2126 and then Present
(Non_Limited_View
(T
))
2127 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2129 -- The non-limited view is fully declared
2135 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2138 -- Need comments for these tests ???
2140 elsif Has_Private_Component
(T
)
2141 and then not Is_Generic_Type
(Root_Type
(T
))
2142 and then not In_Spec_Expression
2144 -- Special case: if T is the anonymous type created for a single
2145 -- task or protected object, use the name of the source object.
2147 if Is_Concurrent_Type
(T
)
2148 and then not Comes_From_Source
(T
)
2149 and then Nkind
(N
) = N_Object_Declaration
2152 ("type of& has incomplete component",
2153 N
, Defining_Identifier
(N
));
2156 ("premature usage of incomplete}",
2157 N
, First_Subtype
(T
));
2160 end Check_Fully_Declared
;
2162 -------------------------------------------
2163 -- Check_Function_With_Address_Parameter --
2164 -------------------------------------------
2166 procedure Check_Function_With_Address_Parameter
(Subp_Id
: Entity_Id
) is
2171 F
:= First_Formal
(Subp_Id
);
2172 while Present
(F
) loop
2175 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
2179 if Is_Descendant_Of_Address
(T
) or else Is_Limited_Type
(T
) then
2180 Set_Is_Pure
(Subp_Id
, False);
2186 end Check_Function_With_Address_Parameter
;
2188 -------------------------------------
2189 -- Check_Function_Writable_Actuals --
2190 -------------------------------------
2192 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2193 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2194 Identifiers_List
: Elist_Id
:= No_Elist
;
2195 Aggr_Error_Node
: Node_Id
:= Empty
;
2196 Error_Node
: Node_Id
:= Empty
;
2198 procedure Collect_Identifiers
(N
: Node_Id
);
2199 -- In a single traversal of subtree N collect in Writable_Actuals_List
2200 -- all the actuals of functions with writable actuals, and in the list
2201 -- Identifiers_List collect all the identifiers that are not actuals of
2202 -- functions with writable actuals. If a writable actual is referenced
2203 -- twice as writable actual then Error_Node is set to reference its
2204 -- second occurrence, the error is reported, and the tree traversal
2207 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
2208 -- Preanalyze N without reporting errors. Very dubious, you can't just
2209 -- go analyzing things more than once???
2211 -------------------------
2212 -- Collect_Identifiers --
2213 -------------------------
2215 procedure Collect_Identifiers
(N
: Node_Id
) is
2217 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2218 -- Process a single node during the tree traversal to collect the
2219 -- writable actuals of functions and all the identifiers which are
2220 -- not writable actuals of functions.
2222 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2223 -- Returns True if List has a node whose Entity is Entity (N)
2229 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2230 Is_Writable_Actual
: Boolean := False;
2234 if Nkind
(N
) = N_Identifier
then
2236 -- No analysis possible if the entity is not decorated
2238 if No
(Entity
(N
)) then
2241 -- Don't collect identifiers of packages, called functions, etc
2243 elsif Ekind_In
(Entity
(N
), E_Package
,
2250 -- For rewritten nodes, continue the traversal in the original
2251 -- subtree. Needed to handle aggregates in original expressions
2252 -- extracted from the tree by Remove_Side_Effects.
2254 elsif Is_Rewrite_Substitution
(N
) then
2255 Collect_Identifiers
(Original_Node
(N
));
2258 -- For now we skip aggregate discriminants, since they require
2259 -- performing the analysis in two phases to identify conflicts:
2260 -- first one analyzing discriminants and second one analyzing
2261 -- the rest of components (since at run time, discriminants are
2262 -- evaluated prior to components): too much computation cost
2263 -- to identify a corner case???
2265 elsif Nkind
(Parent
(N
)) = N_Component_Association
2266 and then Nkind_In
(Parent
(Parent
(N
)),
2268 N_Extension_Aggregate
)
2271 Choice
: constant Node_Id
:= First
(Choices
(Parent
(N
)));
2274 if Ekind
(Entity
(N
)) = E_Discriminant
then
2277 elsif Expression
(Parent
(N
)) = N
2278 and then Nkind
(Choice
) = N_Identifier
2279 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2285 -- Analyze if N is a writable actual of a function
2287 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2289 Call
: constant Node_Id
:= Parent
(N
);
2294 Id
:= Get_Called_Entity
(Call
);
2296 -- In case of previous error, no check is possible
2302 if Ekind_In
(Id
, E_Function
, E_Generic_Function
)
2303 and then Has_Out_Or_In_Out_Parameter
(Id
)
2305 Formal
:= First_Formal
(Id
);
2306 Actual
:= First_Actual
(Call
);
2307 while Present
(Actual
) and then Present
(Formal
) loop
2309 if Ekind_In
(Formal
, E_Out_Parameter
,
2312 Is_Writable_Actual
:= True;
2318 Next_Formal
(Formal
);
2319 Next_Actual
(Actual
);
2325 if Is_Writable_Actual
then
2327 -- Skip checking the error in non-elementary types since
2328 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2329 -- store this actual in Writable_Actuals_List since it is
2330 -- needed to perform checks on other constructs that have
2331 -- arbitrary order of evaluation (for example, aggregates).
2333 if not Is_Elementary_Type
(Etype
(N
)) then
2334 if not Contains
(Writable_Actuals_List
, N
) then
2335 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2338 -- Second occurrence of an elementary type writable actual
2340 elsif Contains
(Writable_Actuals_List
, N
) then
2342 -- Report the error on the second occurrence of the
2343 -- identifier. We cannot assume that N is the second
2344 -- occurrence (according to their location in the
2345 -- sources), since Traverse_Func walks through Field2
2346 -- last (see comment in the body of Traverse_Func).
2352 Elmt
:= First_Elmt
(Writable_Actuals_List
);
2353 while Present
(Elmt
)
2354 and then Entity
(Node
(Elmt
)) /= Entity
(N
)
2359 if Sloc
(N
) > Sloc
(Node
(Elmt
)) then
2362 Error_Node
:= Node
(Elmt
);
2366 ("value may be affected by call to & "
2367 & "because order of evaluation is arbitrary",
2372 -- First occurrence of a elementary type writable actual
2375 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2379 if Identifiers_List
= No_Elist
then
2380 Identifiers_List
:= New_Elmt_List
;
2383 Append_Unique_Elmt
(N
, Identifiers_List
);
2396 N
: Node_Id
) return Boolean
2398 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2403 if List
= No_Elist
then
2407 Elmt
:= First_Elmt
(List
);
2408 while Present
(Elmt
) loop
2409 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2423 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2424 -- The traversal procedure
2426 -- Start of processing for Collect_Identifiers
2429 if Present
(Error_Node
) then
2433 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2438 end Collect_Identifiers
;
2440 -------------------------------
2441 -- Preanalyze_Without_Errors --
2442 -------------------------------
2444 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2445 Status
: constant Boolean := Get_Ignore_Errors
;
2447 Set_Ignore_Errors
(True);
2449 Set_Ignore_Errors
(Status
);
2450 end Preanalyze_Without_Errors
;
2452 -- Start of processing for Check_Function_Writable_Actuals
2455 -- The check only applies to Ada 2012 code on which Check_Actuals has
2456 -- been set, and only to constructs that have multiple constituents
2457 -- whose order of evaluation is not specified by the language.
2459 if Ada_Version
< Ada_2012
2460 or else not Check_Actuals
(N
)
2461 or else (not (Nkind
(N
) in N_Op
)
2462 and then not (Nkind
(N
) in N_Membership_Test
)
2463 and then not Nkind_In
(N
, N_Range
,
2465 N_Extension_Aggregate
,
2466 N_Full_Type_Declaration
,
2468 N_Procedure_Call_Statement
,
2469 N_Entry_Call_Statement
))
2470 or else (Nkind
(N
) = N_Full_Type_Declaration
2471 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2473 -- In addition, this check only applies to source code, not to code
2474 -- generated by constraint checks.
2476 or else not Comes_From_Source
(N
)
2481 -- If a construct C has two or more direct constituents that are names
2482 -- or expressions whose evaluation may occur in an arbitrary order, at
2483 -- least one of which contains a function call with an in out or out
2484 -- parameter, then the construct is legal only if: for each name N that
2485 -- is passed as a parameter of mode in out or out to some inner function
2486 -- call C2 (not including the construct C itself), there is no other
2487 -- name anywhere within a direct constituent of the construct C other
2488 -- than the one containing C2, that is known to refer to the same
2489 -- object (RM 6.4.1(6.17/3)).
2493 Collect_Identifiers
(Low_Bound
(N
));
2494 Collect_Identifiers
(High_Bound
(N
));
2496 when N_Membership_Test
2503 Collect_Identifiers
(Left_Opnd
(N
));
2505 if Present
(Right_Opnd
(N
)) then
2506 Collect_Identifiers
(Right_Opnd
(N
));
2509 if Nkind_In
(N
, N_In
, N_Not_In
)
2510 and then Present
(Alternatives
(N
))
2512 Expr
:= First
(Alternatives
(N
));
2513 while Present
(Expr
) loop
2514 Collect_Identifiers
(Expr
);
2521 when N_Full_Type_Declaration
=>
2523 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2524 -- Return the record part of this record type definition
2526 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2527 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2529 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2530 return Record_Extension_Part
(Type_Def
);
2534 end Get_Record_Part
;
2537 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2538 Rec
: Node_Id
:= Get_Record_Part
(N
);
2541 -- No need to perform any analysis if the record has no
2544 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2548 -- Collect the identifiers starting from the deepest
2549 -- derivation. Done to report the error in the deepest
2553 if Present
(Component_List
(Rec
)) then
2554 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2555 while Present
(Comp
) loop
2556 if Nkind
(Comp
) = N_Component_Declaration
2557 and then Present
(Expression
(Comp
))
2559 Collect_Identifiers
(Expression
(Comp
));
2566 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2567 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2570 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2571 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2575 when N_Entry_Call_Statement
2579 Id
: constant Entity_Id
:= Get_Called_Entity
(N
);
2584 Formal
:= First_Formal
(Id
);
2585 Actual
:= First_Actual
(N
);
2586 while Present
(Actual
) and then Present
(Formal
) loop
2587 if Ekind_In
(Formal
, E_Out_Parameter
,
2590 Collect_Identifiers
(Actual
);
2593 Next_Formal
(Formal
);
2594 Next_Actual
(Actual
);
2599 | N_Extension_Aggregate
2604 Comp_Expr
: Node_Id
;
2607 -- Handle the N_Others_Choice of array aggregates with static
2608 -- bounds. There is no need to perform this analysis in
2609 -- aggregates without static bounds since we cannot evaluate
2610 -- if the N_Others_Choice covers several elements. There is
2611 -- no need to handle the N_Others choice of record aggregates
2612 -- since at this stage it has been already expanded by
2613 -- Resolve_Record_Aggregate.
2615 if Is_Array_Type
(Etype
(N
))
2616 and then Nkind
(N
) = N_Aggregate
2617 and then Present
(Aggregate_Bounds
(N
))
2618 and then Compile_Time_Known_Bounds
(Etype
(N
))
2619 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2621 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2624 Count_Components
: Uint
:= Uint_0
;
2625 Num_Components
: Uint
;
2626 Others_Assoc
: Node_Id
;
2627 Others_Choice
: Node_Id
:= Empty
;
2628 Others_Box_Present
: Boolean := False;
2631 -- Count positional associations
2633 if Present
(Expressions
(N
)) then
2634 Comp_Expr
:= First
(Expressions
(N
));
2635 while Present
(Comp_Expr
) loop
2636 Count_Components
:= Count_Components
+ 1;
2641 -- Count the rest of elements and locate the N_Others
2644 Assoc
:= First
(Component_Associations
(N
));
2645 while Present
(Assoc
) loop
2646 Choice
:= First
(Choices
(Assoc
));
2647 while Present
(Choice
) loop
2648 if Nkind
(Choice
) = N_Others_Choice
then
2649 Others_Assoc
:= Assoc
;
2650 Others_Choice
:= Choice
;
2651 Others_Box_Present
:= Box_Present
(Assoc
);
2653 -- Count several components
2655 elsif Nkind_In
(Choice
, N_Range
,
2656 N_Subtype_Indication
)
2657 or else (Is_Entity_Name
(Choice
)
2658 and then Is_Type
(Entity
(Choice
)))
2663 Get_Index_Bounds
(Choice
, L
, H
);
2665 (Compile_Time_Known_Value
(L
)
2666 and then Compile_Time_Known_Value
(H
));
2669 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2672 -- Count single component. No other case available
2673 -- since we are handling an aggregate with static
2677 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2678 or else Nkind
(Choice
) = N_Identifier
2679 or else Nkind
(Choice
) = N_Integer_Literal
);
2681 Count_Components
:= Count_Components
+ 1;
2691 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2692 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2694 pragma Assert
(Count_Components
<= Num_Components
);
2696 -- Handle the N_Others choice if it covers several
2699 if Present
(Others_Choice
)
2700 and then (Num_Components
- Count_Components
) > 1
2702 if not Others_Box_Present
then
2704 -- At this stage, if expansion is active, the
2705 -- expression of the others choice has not been
2706 -- analyzed. Hence we generate a duplicate and
2707 -- we analyze it silently to have available the
2708 -- minimum decoration required to collect the
2711 if not Expander_Active
then
2712 Comp_Expr
:= Expression
(Others_Assoc
);
2715 New_Copy_Tree
(Expression
(Others_Assoc
));
2716 Preanalyze_Without_Errors
(Comp_Expr
);
2719 Collect_Identifiers
(Comp_Expr
);
2721 if Writable_Actuals_List
/= No_Elist
then
2723 -- As suggested by Robert, at current stage we
2724 -- report occurrences of this case as warnings.
2727 ("writable function parameter may affect "
2728 & "value in other component because order "
2729 & "of evaluation is unspecified??",
2730 Node
(First_Elmt
(Writable_Actuals_List
)));
2736 -- For an array aggregate, a discrete_choice_list that has
2737 -- a nonstatic range is considered as two or more separate
2738 -- occurrences of the expression (RM 6.4.1(20/3)).
2740 elsif Is_Array_Type
(Etype
(N
))
2741 and then Nkind
(N
) = N_Aggregate
2742 and then Present
(Aggregate_Bounds
(N
))
2743 and then not Compile_Time_Known_Bounds
(Etype
(N
))
2745 -- Collect identifiers found in the dynamic bounds
2748 Count_Components
: Natural := 0;
2749 Low
, High
: Node_Id
;
2752 Assoc
:= First
(Component_Associations
(N
));
2753 while Present
(Assoc
) loop
2754 Choice
:= First
(Choices
(Assoc
));
2755 while Present
(Choice
) loop
2756 if Nkind_In
(Choice
, N_Range
,
2757 N_Subtype_Indication
)
2758 or else (Is_Entity_Name
(Choice
)
2759 and then Is_Type
(Entity
(Choice
)))
2761 Get_Index_Bounds
(Choice
, Low
, High
);
2763 if not Compile_Time_Known_Value
(Low
) then
2764 Collect_Identifiers
(Low
);
2766 if No
(Aggr_Error_Node
) then
2767 Aggr_Error_Node
:= Low
;
2771 if not Compile_Time_Known_Value
(High
) then
2772 Collect_Identifiers
(High
);
2774 if No
(Aggr_Error_Node
) then
2775 Aggr_Error_Node
:= High
;
2779 -- The RM rule is violated if there is more than
2780 -- a single choice in a component association.
2783 Count_Components
:= Count_Components
+ 1;
2785 if No
(Aggr_Error_Node
)
2786 and then Count_Components
> 1
2788 Aggr_Error_Node
:= Choice
;
2791 if not Compile_Time_Known_Value
(Choice
) then
2792 Collect_Identifiers
(Choice
);
2804 -- Handle ancestor part of extension aggregates
2806 if Nkind
(N
) = N_Extension_Aggregate
then
2807 Collect_Identifiers
(Ancestor_Part
(N
));
2810 -- Handle positional associations
2812 if Present
(Expressions
(N
)) then
2813 Comp_Expr
:= First
(Expressions
(N
));
2814 while Present
(Comp_Expr
) loop
2815 if not Is_OK_Static_Expression
(Comp_Expr
) then
2816 Collect_Identifiers
(Comp_Expr
);
2823 -- Handle discrete associations
2825 if Present
(Component_Associations
(N
)) then
2826 Assoc
:= First
(Component_Associations
(N
));
2827 while Present
(Assoc
) loop
2829 if not Box_Present
(Assoc
) then
2830 Choice
:= First
(Choices
(Assoc
));
2831 while Present
(Choice
) loop
2833 -- For now we skip discriminants since it requires
2834 -- performing the analysis in two phases: first one
2835 -- analyzing discriminants and second one analyzing
2836 -- the rest of components since discriminants are
2837 -- evaluated prior to components: too much extra
2838 -- work to detect a corner case???
2840 if Nkind
(Choice
) in N_Has_Entity
2841 and then Present
(Entity
(Choice
))
2842 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2846 elsif Box_Present
(Assoc
) then
2850 if not Analyzed
(Expression
(Assoc
)) then
2852 New_Copy_Tree
(Expression
(Assoc
));
2853 Set_Parent
(Comp_Expr
, Parent
(N
));
2854 Preanalyze_Without_Errors
(Comp_Expr
);
2856 Comp_Expr
:= Expression
(Assoc
);
2859 Collect_Identifiers
(Comp_Expr
);
2875 -- No further action needed if we already reported an error
2877 if Present
(Error_Node
) then
2881 -- Check violation of RM 6.20/3 in aggregates
2883 if Present
(Aggr_Error_Node
)
2884 and then Writable_Actuals_List
/= No_Elist
2887 ("value may be affected by call in other component because they "
2888 & "are evaluated in unspecified order",
2889 Node
(First_Elmt
(Writable_Actuals_List
)));
2893 -- Check if some writable argument of a function is referenced
2895 if Writable_Actuals_List
/= No_Elist
2896 and then Identifiers_List
/= No_Elist
2903 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2904 while Present
(Elmt_1
) loop
2905 Elmt_2
:= First_Elmt
(Identifiers_List
);
2906 while Present
(Elmt_2
) loop
2907 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2908 case Nkind
(Parent
(Node
(Elmt_2
))) is
2910 | N_Component_Association
2911 | N_Component_Declaration
2914 ("value may be affected by call in other "
2915 & "component because they are evaluated "
2916 & "in unspecified order",
2923 ("value may be affected by call in other "
2924 & "alternative because they are evaluated "
2925 & "in unspecified order",
2930 ("value of actual may be affected by call in "
2931 & "other actual because they are evaluated "
2932 & "in unspecified order",
2944 end Check_Function_Writable_Actuals
;
2946 --------------------------------
2947 -- Check_Implicit_Dereference --
2948 --------------------------------
2950 procedure Check_Implicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
2956 if Nkind
(N
) = N_Indexed_Component
2957 and then Present
(Generalized_Indexing
(N
))
2959 Nam
:= Generalized_Indexing
(N
);
2964 if Ada_Version
< Ada_2012
2965 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2969 elsif not Comes_From_Source
(N
)
2970 and then Nkind
(N
) /= N_Indexed_Component
2974 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
2978 Disc
:= First_Discriminant
(Typ
);
2979 while Present
(Disc
) loop
2980 if Has_Implicit_Dereference
(Disc
) then
2981 Desig
:= Designated_Type
(Etype
(Disc
));
2982 Add_One_Interp
(Nam
, Disc
, Desig
);
2984 -- If the node is a generalized indexing, add interpretation
2985 -- to that node as well, for subsequent resolution.
2987 if Nkind
(N
) = N_Indexed_Component
then
2988 Add_One_Interp
(N
, Disc
, Desig
);
2991 -- If the operation comes from a generic unit and the context
2992 -- is a selected component, the selector name may be global
2993 -- and set in the instance already. Remove the entity to
2994 -- force resolution of the selected component, and the
2995 -- generation of an explicit dereference if needed.
2998 and then Nkind
(Parent
(Nam
)) = N_Selected_Component
3000 Set_Entity
(Selector_Name
(Parent
(Nam
)), Empty
);
3006 Next_Discriminant
(Disc
);
3009 end Check_Implicit_Dereference
;
3011 ----------------------------------
3012 -- Check_Internal_Protected_Use --
3013 ----------------------------------
3015 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
3023 while Present
(S
) loop
3024 if S
= Standard_Standard
then
3027 elsif Ekind
(S
) = E_Function
3028 and then Ekind
(Scope
(S
)) = E_Protected_Type
3038 and then Scope
(Nam
) = Prot
3039 and then Ekind
(Nam
) /= E_Function
3041 -- An indirect function call (e.g. a callback within a protected
3042 -- function body) is not statically illegal. If the access type is
3043 -- anonymous and is the type of an access parameter, the scope of Nam
3044 -- will be the protected type, but it is not a protected operation.
3046 if Ekind
(Nam
) = E_Subprogram_Type
3047 and then Nkind
(Associated_Node_For_Itype
(Nam
)) =
3048 N_Function_Specification
3052 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
3054 ("within protected function cannot use protected procedure in "
3055 & "renaming or as generic actual", N
);
3057 elsif Nkind
(N
) = N_Attribute_Reference
then
3059 ("within protected function cannot take access of protected "
3064 ("within protected function, protected object is constant", N
);
3066 ("\cannot call operation that may modify it", N
);
3070 -- Verify that an internal call does not appear within a precondition
3071 -- of a protected operation. This implements AI12-0166.
3072 -- The precondition aspect has been rewritten as a pragma Precondition
3073 -- and we check whether the scope of the called subprogram is the same
3074 -- as that of the entity to which the aspect applies.
3076 if Convention
(Nam
) = Convention_Protected
then
3082 while Present
(P
) loop
3083 if Nkind
(P
) = N_Pragma
3084 and then Chars
(Pragma_Identifier
(P
)) = Name_Precondition
3085 and then From_Aspect_Specification
(P
)
3087 Scope
(Entity
(Corresponding_Aspect
(P
))) = Scope
(Nam
)
3090 ("internal call cannot appear in precondition of "
3091 & "protected operation", N
);
3094 elsif Nkind
(P
) = N_Pragma
3095 and then Chars
(Pragma_Identifier
(P
)) = Name_Contract_Cases
3097 -- Check whether call is in a case guard. It is legal in a
3101 while Present
(P
) loop
3102 if Nkind
(Parent
(P
)) = N_Component_Association
3103 and then P
/= Expression
(Parent
(P
))
3106 ("internal call cannot appear in case guard in a "
3107 & "contract case", N
);
3115 elsif Nkind
(P
) = N_Parameter_Specification
3116 and then Scope
(Current_Scope
) = Scope
(Nam
)
3117 and then Nkind_In
(Parent
(P
), N_Entry_Declaration
,
3118 N_Subprogram_Declaration
)
3121 ("internal call cannot appear in default for formal of "
3122 & "protected operation", N
);
3130 end Check_Internal_Protected_Use
;
3132 ---------------------------------------
3133 -- Check_Later_Vs_Basic_Declarations --
3134 ---------------------------------------
3136 procedure Check_Later_Vs_Basic_Declarations
3138 During_Parsing
: Boolean)
3140 Body_Sloc
: Source_Ptr
;
3143 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
3144 -- Return whether Decl is considered as a declarative item.
3145 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3146 -- When During_Parsing is False, the semantics of SPARK is followed.
3148 -------------------------------
3149 -- Is_Later_Declarative_Item --
3150 -------------------------------
3152 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
3154 if Nkind
(Decl
) in N_Later_Decl_Item
then
3157 elsif Nkind
(Decl
) = N_Pragma
then
3160 elsif During_Parsing
then
3163 -- In SPARK, a package declaration is not considered as a later
3164 -- declarative item.
3166 elsif Nkind
(Decl
) = N_Package_Declaration
then
3169 -- In SPARK, a renaming is considered as a later declarative item
3171 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
3177 end Is_Later_Declarative_Item
;
3179 -- Start of processing for Check_Later_Vs_Basic_Declarations
3182 Decl
:= First
(Decls
);
3184 -- Loop through sequence of basic declarative items
3186 Outer
: while Present
(Decl
) loop
3187 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
3188 and then Nkind
(Decl
) not in N_Body_Stub
3192 -- Once a body is encountered, we only allow later declarative
3193 -- items. The inner loop checks the rest of the list.
3196 Body_Sloc
:= Sloc
(Decl
);
3198 Inner
: while Present
(Decl
) loop
3199 if not Is_Later_Declarative_Item
(Decl
) then
3200 if During_Parsing
then
3201 if Ada_Version
= Ada_83
then
3202 Error_Msg_Sloc
:= Body_Sloc
;
3204 ("(Ada 83) decl cannot appear after body#", Decl
);
3207 Error_Msg_Sloc
:= Body_Sloc
;
3208 Check_SPARK_05_Restriction
3209 ("decl cannot appear after body#", Decl
);
3217 end Check_Later_Vs_Basic_Declarations
;
3219 ---------------------------
3220 -- Check_No_Hidden_State --
3221 ---------------------------
3223 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
3224 Context
: Entity_Id
:= Empty
;
3225 Not_Visible
: Boolean := False;
3229 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
3231 -- Nothing to do for internally-generated abstract states and variables
3232 -- because they do not represent the hidden state of the source unit.
3234 if not Comes_From_Source
(Id
) then
3238 -- Find the proper context where the object or state appears
3241 while Present
(Scop
) loop
3244 -- Keep track of the context's visibility
3246 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
3248 -- Prevent the search from going too far
3250 if Context
= Standard_Standard
then
3253 -- Objects and states that appear immediately within a subprogram or
3254 -- inside a construct nested within a subprogram do not introduce a
3255 -- hidden state. They behave as local variable declarations.
3257 elsif Is_Subprogram
(Context
) then
3260 -- When examining a package body, use the entity of the spec as it
3261 -- carries the abstract state declarations.
3263 elsif Ekind
(Context
) = E_Package_Body
then
3264 Context
:= Spec_Entity
(Context
);
3267 -- Stop the traversal when a package subject to a null abstract state
3270 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
3271 and then Has_Null_Abstract_State
(Context
)
3276 Scop
:= Scope
(Scop
);
3279 -- At this point we know that there is at least one package with a null
3280 -- abstract state in visibility. Emit an error message unconditionally
3281 -- if the entity being processed is a state because the placement of the
3282 -- related package is irrelevant. This is not the case for objects as
3283 -- the intermediate context matters.
3285 if Present
(Context
)
3286 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
3288 Error_Msg_N
("cannot introduce hidden state &", Id
);
3289 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
3291 end Check_No_Hidden_State
;
3293 ----------------------------------------
3294 -- Check_Nonvolatile_Function_Profile --
3295 ----------------------------------------
3297 procedure Check_Nonvolatile_Function_Profile
(Func_Id
: Entity_Id
) is
3301 -- Inspect all formal parameters
3303 Formal
:= First_Formal
(Func_Id
);
3304 while Present
(Formal
) loop
3305 if Is_Effectively_Volatile
(Etype
(Formal
)) then
3307 ("nonvolatile function & cannot have a volatile parameter",
3311 Next_Formal
(Formal
);
3314 -- Inspect the return type
3316 if Is_Effectively_Volatile
(Etype
(Func_Id
)) then
3318 ("nonvolatile function & cannot have a volatile return type",
3319 Result_Definition
(Parent
(Func_Id
)), Func_Id
);
3321 end Check_Nonvolatile_Function_Profile
;
3323 -----------------------------
3324 -- Check_Part_Of_Reference --
3325 -----------------------------
3327 procedure Check_Part_Of_Reference
(Var_Id
: Entity_Id
; Ref
: Node_Id
) is
3328 function Is_Enclosing_Package_Body
3329 (Body_Decl
: Node_Id
;
3330 Obj_Id
: Entity_Id
) return Boolean;
3331 pragma Inline
(Is_Enclosing_Package_Body
);
3332 -- Determine whether package body Body_Decl or its corresponding spec
3333 -- immediately encloses the declaration of object Obj_Id.
3335 function Is_Internal_Declaration_Or_Body
3336 (Decl
: Node_Id
) return Boolean;
3337 pragma Inline
(Is_Internal_Declaration_Or_Body
);
3338 -- Determine whether declaration or body denoted by Decl is internal
3340 function Is_Single_Declaration_Or_Body
3342 Conc_Typ
: Entity_Id
) return Boolean;
3343 pragma Inline
(Is_Single_Declaration_Or_Body
);
3344 -- Determine whether protected/task declaration or body denoted by Decl
3345 -- belongs to single concurrent type Conc_Typ.
3347 function Is_Single_Task_Pragma
3349 Task_Typ
: Entity_Id
) return Boolean;
3350 pragma Inline
(Is_Single_Task_Pragma
);
3351 -- Determine whether pragma Prag belongs to single task type Task_Typ
3353 -------------------------------
3354 -- Is_Enclosing_Package_Body --
3355 -------------------------------
3357 function Is_Enclosing_Package_Body
3358 (Body_Decl
: Node_Id
;
3359 Obj_Id
: Entity_Id
) return Boolean
3361 Obj_Context
: Node_Id
;
3364 -- Find the context of the object declaration
3366 Obj_Context
:= Parent
(Declaration_Node
(Obj_Id
));
3368 if Nkind
(Obj_Context
) = N_Package_Specification
then
3369 Obj_Context
:= Parent
(Obj_Context
);
3372 -- The object appears immediately within the package body
3374 if Obj_Context
= Body_Decl
then
3377 -- The object appears immediately within the corresponding spec
3379 elsif Nkind
(Obj_Context
) = N_Package_Declaration
3380 and then Unit_Declaration_Node
(Corresponding_Spec
(Body_Decl
)) =
3387 end Is_Enclosing_Package_Body
;
3389 -------------------------------------
3390 -- Is_Internal_Declaration_Or_Body --
3391 -------------------------------------
3393 function Is_Internal_Declaration_Or_Body
3394 (Decl
: Node_Id
) return Boolean
3397 if Comes_From_Source
(Decl
) then
3400 -- A body generated for an expression function which has not been
3401 -- inserted into the tree yet (In_Spec_Expression is True) is not
3402 -- considered internal.
3404 elsif Nkind
(Decl
) = N_Subprogram_Body
3405 and then Was_Expression_Function
(Decl
)
3406 and then not In_Spec_Expression
3412 end Is_Internal_Declaration_Or_Body
;
3414 -----------------------------------
3415 -- Is_Single_Declaration_Or_Body --
3416 -----------------------------------
3418 function Is_Single_Declaration_Or_Body
3420 Conc_Typ
: Entity_Id
) return Boolean
3422 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Decl
);
3426 Present
(Anonymous_Object
(Spec_Id
))
3427 and then Anonymous_Object
(Spec_Id
) = Conc_Typ
;
3428 end Is_Single_Declaration_Or_Body
;
3430 ---------------------------
3431 -- Is_Single_Task_Pragma --
3432 ---------------------------
3434 function Is_Single_Task_Pragma
3436 Task_Typ
: Entity_Id
) return Boolean
3438 Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(Prag
);
3441 -- To qualify, the pragma must be associated with single task type
3445 Is_Single_Task_Object
(Task_Typ
)
3446 and then Nkind
(Decl
) = N_Object_Declaration
3447 and then Defining_Entity
(Decl
) = Task_Typ
;
3448 end Is_Single_Task_Pragma
;
3452 Conc_Obj
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
3457 -- Start of processing for Check_Part_Of_Reference
3460 -- Nothing to do when the variable was recorded, but did not become a
3461 -- constituent of a single concurrent type.
3463 if No
(Conc_Obj
) then
3467 -- Traverse the parent chain looking for a suitable context for the
3468 -- reference to the concurrent constituent.
3471 Par
:= Parent
(Prev
);
3472 while Present
(Par
) loop
3473 if Nkind
(Par
) = N_Pragma
then
3474 Prag_Nam
:= Pragma_Name
(Par
);
3476 -- A concurrent constituent is allowed to appear in pragmas
3477 -- Initial_Condition and Initializes as this is part of the
3478 -- elaboration checks for the constituent (SPARK RM 9(3)).
3480 if Nam_In
(Prag_Nam
, Name_Initial_Condition
, Name_Initializes
) then
3483 -- When the reference appears within pragma Depends or Global,
3484 -- check whether the pragma applies to a single task type. Note
3485 -- that the pragma may not encapsulated by the type definition,
3486 -- but this is still a valid context.
3488 elsif Nam_In
(Prag_Nam
, Name_Depends
, Name_Global
)
3489 and then Is_Single_Task_Pragma
(Par
, Conc_Obj
)
3494 -- The reference appears somewhere in the definition of a single
3495 -- concurrent type (SPARK RM 9(3)).
3497 elsif Nkind_In
(Par
, N_Single_Protected_Declaration
,
3498 N_Single_Task_Declaration
)
3499 and then Defining_Entity
(Par
) = Conc_Obj
3503 -- The reference appears within the declaration or body of a single
3504 -- concurrent type (SPARK RM 9(3)).
3506 elsif Nkind_In
(Par
, N_Protected_Body
,
3507 N_Protected_Type_Declaration
,
3509 N_Task_Type_Declaration
)
3510 and then Is_Single_Declaration_Or_Body
(Par
, Conc_Obj
)
3514 -- The reference appears within the statement list of the object's
3515 -- immediately enclosing package (SPARK RM 9(3)).
3517 elsif Nkind
(Par
) = N_Package_Body
3518 and then Nkind
(Prev
) = N_Handled_Sequence_Of_Statements
3519 and then Is_Enclosing_Package_Body
(Par
, Var_Id
)
3523 -- The reference has been relocated within an internally generated
3524 -- package or subprogram. Assume that the reference is legal as the
3525 -- real check was already performed in the original context of the
3528 elsif Nkind_In
(Par
, N_Package_Body
,
3529 N_Package_Declaration
,
3531 N_Subprogram_Declaration
)
3532 and then Is_Internal_Declaration_Or_Body
(Par
)
3536 -- The reference has been relocated to an inlined body for GNATprove.
3537 -- Assume that the reference is legal as the real check was already
3538 -- performed in the original context of the reference.
3540 elsif GNATprove_Mode
3541 and then Nkind
(Par
) = N_Subprogram_Body
3542 and then Chars
(Defining_Entity
(Par
)) = Name_uParent
3548 Par
:= Parent
(Prev
);
3551 -- At this point it is known that the reference does not appear within a
3555 ("reference to variable & cannot appear in this context", Ref
, Var_Id
);
3556 Error_Msg_Name_1
:= Chars
(Var_Id
);
3558 if Is_Single_Protected_Object
(Conc_Obj
) then
3560 ("\% is constituent of single protected type &", Ref
, Conc_Obj
);
3564 ("\% is constituent of single task type &", Ref
, Conc_Obj
);
3566 end Check_Part_Of_Reference
;
3568 ------------------------------------------
3569 -- Check_Potentially_Blocking_Operation --
3570 ------------------------------------------
3572 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
3576 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3577 -- When pragma Detect_Blocking is active, the run time will raise
3578 -- Program_Error. Here we only issue a warning, since we generally
3579 -- support the use of potentially blocking operations in the absence
3582 -- Indirect blocking through a subprogram call cannot be diagnosed
3583 -- statically without interprocedural analysis, so we do not attempt
3586 S
:= Scope
(Current_Scope
);
3587 while Present
(S
) and then S
/= Standard_Standard
loop
3588 if Is_Protected_Type
(S
) then
3590 ("potentially blocking operation in protected operation??", N
);
3596 end Check_Potentially_Blocking_Operation
;
3598 ------------------------------------
3599 -- Check_Previous_Null_Procedure --
3600 ------------------------------------
3602 procedure Check_Previous_Null_Procedure
3607 if Ekind
(Prev
) = E_Procedure
3608 and then Nkind
(Parent
(Prev
)) = N_Procedure_Specification
3609 and then Null_Present
(Parent
(Prev
))
3611 Error_Msg_Sloc
:= Sloc
(Prev
);
3613 ("declaration cannot complete previous null procedure#", Decl
);
3615 end Check_Previous_Null_Procedure
;
3617 ---------------------------------
3618 -- Check_Result_And_Post_State --
3619 ---------------------------------
3621 procedure Check_Result_And_Post_State
(Subp_Id
: Entity_Id
) is
3622 procedure Check_Result_And_Post_State_In_Pragma
3624 Result_Seen
: in out Boolean);
3625 -- Determine whether pragma Prag mentions attribute 'Result and whether
3626 -- the pragma contains an expression that evaluates differently in pre-
3627 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3628 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3630 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean;
3631 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3632 -- formal parameter.
3634 -------------------------------------------
3635 -- Check_Result_And_Post_State_In_Pragma --
3636 -------------------------------------------
3638 procedure Check_Result_And_Post_State_In_Pragma
3640 Result_Seen
: in out Boolean)
3642 procedure Check_Conjunct
(Expr
: Node_Id
);
3643 -- Check an individual conjunct in a conjunction of Boolean
3644 -- expressions, connected by "and" or "and then" operators.
3646 procedure Check_Conjuncts
(Expr
: Node_Id
);
3647 -- Apply the post-state check to every conjunct in an expression, in
3648 -- case this is a conjunction of Boolean expressions. Otherwise apply
3649 -- it to the expression as a whole.
3651 procedure Check_Expression
(Expr
: Node_Id
);
3652 -- Perform the 'Result and post-state checks on a given expression
3654 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
3655 -- Attempt to find attribute 'Result in a subtree denoted by N
3657 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
3658 -- Determine whether source node N denotes "True" or "False"
3660 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
3661 -- Determine whether a subtree denoted by N mentions any construct
3662 -- that denotes a post-state.
3664 procedure Check_Function_Result
is
3665 new Traverse_Proc
(Is_Function_Result
);
3667 --------------------
3668 -- Check_Conjunct --
3669 --------------------
3671 procedure Check_Conjunct
(Expr
: Node_Id
) is
3672 function Adjust_Message
(Msg
: String) return String;
3673 -- Prepend a prefix to the input message Msg denoting that the
3674 -- message applies to a conjunct in the expression, when this
3677 function Applied_On_Conjunct
return Boolean;
3678 -- Returns True if the message applies to a conjunct in the
3679 -- expression, instead of the whole expression.
3681 function Has_Global_Output
(Subp
: Entity_Id
) return Boolean;
3682 -- Returns True if Subp has an output in its Global contract
3684 function Has_No_Output
(Subp
: Entity_Id
) return Boolean;
3685 -- Returns True if Subp has no declared output: no function
3686 -- result, no output parameter, and no output in its Global
3689 --------------------
3690 -- Adjust_Message --
3691 --------------------
3693 function Adjust_Message
(Msg
: String) return String is
3695 if Applied_On_Conjunct
then
3696 return "conjunct in " & Msg
;
3702 -------------------------
3703 -- Applied_On_Conjunct --
3704 -------------------------
3706 function Applied_On_Conjunct
return Boolean is
3708 -- Expr is the conjunct of an enclosing "and" expression
3710 return Nkind
(Parent
(Expr
)) in N_Subexpr
3712 -- or Expr is a conjunct of an enclosing "and then"
3713 -- expression in a postcondition aspect that was split into
3714 -- multiple pragmas. The first conjunct has the "and then"
3715 -- expression as Original_Node, and other conjuncts have
3716 -- Split_PCC set to True.
3718 or else Nkind
(Original_Node
(Expr
)) = N_And_Then
3719 or else Split_PPC
(Prag
);
3720 end Applied_On_Conjunct
;
3722 -----------------------
3723 -- Has_Global_Output --
3724 -----------------------
3726 function Has_Global_Output
(Subp
: Entity_Id
) return Boolean is
3727 Global
: constant Node_Id
:= Get_Pragma
(Subp
, Pragma_Global
);
3736 List
:= Expression
(Get_Argument
(Global
, Subp
));
3738 -- Empty list (no global items) or single global item
3739 -- declaration (only input items).
3741 if Nkind_In
(List
, N_Null
,
3744 N_Selected_Component
)
3748 -- Simple global list (only input items) or moded global list
3751 elsif Nkind
(List
) = N_Aggregate
then
3752 if Present
(Expressions
(List
)) then
3756 Assoc
:= First
(Component_Associations
(List
));
3757 while Present
(Assoc
) loop
3758 if Chars
(First
(Choices
(Assoc
))) /= Name_Input
then
3768 -- To accommodate partial decoration of disabled SPARK
3769 -- features, this routine may be called with illegal input.
3770 -- If this is the case, do not raise Program_Error.
3775 end Has_Global_Output
;
3781 function Has_No_Output
(Subp
: Entity_Id
) return Boolean is
3785 -- A function has its result as output
3787 if Ekind
(Subp
) = E_Function
then
3791 -- An OUT or IN OUT parameter is an output
3793 Param
:= First_Formal
(Subp
);
3794 while Present
(Param
) loop
3795 if Ekind_In
(Param
, E_Out_Parameter
, E_In_Out_Parameter
) then
3799 Next_Formal
(Param
);
3802 -- An item of mode Output or In_Out in the Global contract is
3805 if Has_Global_Output
(Subp
) then
3815 -- Error node when reporting a warning on a (refined)
3818 -- Start of processing for Check_Conjunct
3821 if Applied_On_Conjunct
then
3827 -- Do not report missing reference to outcome in postcondition if
3828 -- either the postcondition is trivially True or False, or if the
3829 -- subprogram is ghost and has no declared output.
3831 if not Is_Trivial_Boolean
(Expr
)
3832 and then not Mentions_Post_State
(Expr
)
3833 and then not (Is_Ghost_Entity
(Subp_Id
)
3834 and then Has_No_Output
(Subp_Id
))
3836 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
3837 Error_Msg_NE
(Adjust_Message
3838 ("contract case does not check the outcome of calling "
3839 & "&?T?"), Expr
, Subp_Id
);
3841 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
3842 Error_Msg_NE
(Adjust_Message
3843 ("refined postcondition does not check the outcome of "
3844 & "calling &?T?"), Err_Node
, Subp_Id
);
3847 Error_Msg_NE
(Adjust_Message
3848 ("postcondition does not check the outcome of calling "
3849 & "&?T?"), Err_Node
, Subp_Id
);
3854 ---------------------
3855 -- Check_Conjuncts --
3856 ---------------------
3858 procedure Check_Conjuncts
(Expr
: Node_Id
) is
3860 if Nkind_In
(Expr
, N_Op_And
, N_And_Then
) then
3861 Check_Conjuncts
(Left_Opnd
(Expr
));
3862 Check_Conjuncts
(Right_Opnd
(Expr
));
3864 Check_Conjunct
(Expr
);
3866 end Check_Conjuncts
;
3868 ----------------------
3869 -- Check_Expression --
3870 ----------------------
3872 procedure Check_Expression
(Expr
: Node_Id
) is
3874 if not Is_Trivial_Boolean
(Expr
) then
3875 Check_Function_Result
(Expr
);
3876 Check_Conjuncts
(Expr
);
3878 end Check_Expression
;
3880 ------------------------
3881 -- Is_Function_Result --
3882 ------------------------
3884 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
3886 if Is_Attribute_Result
(N
) then
3887 Result_Seen
:= True;
3890 -- Warn on infinite recursion if call is to current function
3892 elsif Nkind
(N
) = N_Function_Call
3893 and then Is_Entity_Name
(Name
(N
))
3894 and then Entity
(Name
(N
)) = Subp_Id
3895 and then not Is_Potentially_Unevaluated
(N
)
3898 ("call to & within its postcondition will lead to infinite "
3899 & "recursion?", N
, Subp_Id
);
3902 -- Continue the traversal
3907 end Is_Function_Result
;
3909 ------------------------
3910 -- Is_Trivial_Boolean --
3911 ------------------------
3913 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
3916 Comes_From_Source
(N
)
3917 and then Is_Entity_Name
(N
)
3918 and then (Entity
(N
) = Standard_True
3920 Entity
(N
) = Standard_False
);
3921 end Is_Trivial_Boolean
;
3923 -------------------------
3924 -- Mentions_Post_State --
3925 -------------------------
3927 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
3928 Post_State_Seen
: Boolean := False;
3930 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3931 -- Attempt to find a construct that denotes a post-state. If this
3932 -- is the case, set flag Post_State_Seen.
3938 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3942 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3943 Post_State_Seen
:= True;
3946 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3949 -- Treat an undecorated reference as OK
3953 -- A reference to an assignable entity is considered a
3954 -- change in the post-state of a subprogram.
3956 or else Ekind_In
(Ent
, E_Generic_In_Out_Parameter
,
3961 -- The reference may be modified through a dereference
3963 or else (Is_Access_Type
(Etype
(Ent
))
3964 and then Nkind
(Parent
(N
)) =
3965 N_Selected_Component
)
3967 Post_State_Seen
:= True;
3971 elsif Nkind
(N
) = N_Attribute_Reference
then
3972 if Attribute_Name
(N
) = Name_Old
then
3975 elsif Attribute_Name
(N
) = Name_Result
then
3976 Post_State_Seen
:= True;
3984 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3986 -- Start of processing for Mentions_Post_State
3989 Find_Post_State
(N
);
3991 return Post_State_Seen
;
3992 end Mentions_Post_State
;
3996 Expr
: constant Node_Id
:=
3998 (First
(Pragma_Argument_Associations
(Prag
)));
3999 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
4002 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4005 -- Examine all consequences
4007 if Nam
= Name_Contract_Cases
then
4008 CCase
:= First
(Component_Associations
(Expr
));
4009 while Present
(CCase
) loop
4010 Check_Expression
(Expression
(CCase
));
4015 -- Examine the expression of a postcondition
4017 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
,
4018 Name_Refined_Post
));
4019 Check_Expression
(Expr
);
4021 end Check_Result_And_Post_State_In_Pragma
;
4023 --------------------------
4024 -- Has_In_Out_Parameter --
4025 --------------------------
4027 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean is
4031 -- Traverse the formals looking for an IN OUT parameter
4033 Formal
:= First_Formal
(Subp_Id
);
4034 while Present
(Formal
) loop
4035 if Ekind
(Formal
) = E_In_Out_Parameter
then
4039 Next_Formal
(Formal
);
4043 end Has_In_Out_Parameter
;
4047 Items
: constant Node_Id
:= Contract
(Subp_Id
);
4048 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp_Id
);
4049 Case_Prag
: Node_Id
:= Empty
;
4050 Post_Prag
: Node_Id
:= Empty
;
4052 Seen_In_Case
: Boolean := False;
4053 Seen_In_Post
: Boolean := False;
4054 Spec_Id
: Entity_Id
;
4056 -- Start of processing for Check_Result_And_Post_State
4059 -- The lack of attribute 'Result or a post-state is classified as a
4060 -- suspicious contract. Do not perform the check if the corresponding
4061 -- swich is not set.
4063 if not Warn_On_Suspicious_Contract
then
4066 -- Nothing to do if there is no contract
4068 elsif No
(Items
) then
4072 -- Retrieve the entity of the subprogram spec (if any)
4074 if Nkind
(Subp_Decl
) = N_Subprogram_Body
4075 and then Present
(Corresponding_Spec
(Subp_Decl
))
4077 Spec_Id
:= Corresponding_Spec
(Subp_Decl
);
4079 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4080 and then Present
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
4082 Spec_Id
:= Corresponding_Spec_Of_Stub
(Subp_Decl
);
4088 -- Examine all postconditions for attribute 'Result and a post-state
4090 Prag
:= Pre_Post_Conditions
(Items
);
4091 while Present
(Prag
) loop
4092 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
4093 Name_Postcondition
, Name_Refined_Post
)
4094 and then not Error_Posted
(Prag
)
4097 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Post
);
4100 Prag
:= Next_Pragma
(Prag
);
4103 -- Examine the contract cases of the subprogram for attribute 'Result
4104 -- and a post-state.
4106 Prag
:= Contract_Test_Cases
(Items
);
4107 while Present
(Prag
) loop
4108 if Pragma_Name
(Prag
) = Name_Contract_Cases
4109 and then not Error_Posted
(Prag
)
4112 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Case
);
4115 Prag
:= Next_Pragma
(Prag
);
4118 -- Do not emit any errors if the subprogram is not a function
4120 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
4123 -- Regardless of whether the function has postconditions or contract
4124 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4125 -- parameter is always treated as a result.
4127 elsif Has_In_Out_Parameter
(Spec_Id
) then
4130 -- The function has both a postcondition and contract cases and they do
4131 -- not mention attribute 'Result.
4133 elsif Present
(Case_Prag
)
4134 and then not Seen_In_Case
4135 and then Present
(Post_Prag
)
4136 and then not Seen_In_Post
4139 ("neither postcondition nor contract cases mention function "
4140 & "result?T?", Post_Prag
);
4142 -- The function has contract cases only and they do not mention
4143 -- attribute 'Result.
4145 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
4146 Error_Msg_N
("contract cases do not mention result?T?", Case_Prag
);
4148 -- The function has postconditions only and they do not mention
4149 -- attribute 'Result.
4151 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
4153 ("postcondition does not mention function result?T?", Post_Prag
);
4155 end Check_Result_And_Post_State
;
4157 -----------------------------
4158 -- Check_State_Refinements --
4159 -----------------------------
4161 procedure Check_State_Refinements
4163 Is_Main_Unit
: Boolean := False)
4165 procedure Check_Package
(Pack
: Node_Id
);
4166 -- Verify that all abstract states of a [generic] package denoted by its
4167 -- declarative node Pack have proper refinement. Recursively verify the
4168 -- visible and private declarations of the [generic] package for other
4171 procedure Check_Packages_In
(Decls
: List_Id
);
4172 -- Seek out [generic] package declarations within declarative list Decls
4173 -- and verify the status of their abstract state refinement.
4175 function SPARK_Mode_Is_Off
(N
: Node_Id
) return Boolean;
4176 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4182 procedure Check_Package
(Pack
: Node_Id
) is
4183 Body_Id
: constant Entity_Id
:= Corresponding_Body
(Pack
);
4184 Spec
: constant Node_Id
:= Specification
(Pack
);
4185 States
: constant Elist_Id
:=
4186 Abstract_States
(Defining_Entity
(Pack
));
4188 State_Elmt
: Elmt_Id
;
4189 State_Id
: Entity_Id
;
4192 -- Do not verify proper state refinement when the package is subject
4193 -- to pragma SPARK_Mode Off because this disables the requirement for
4194 -- state refinement.
4196 if SPARK_Mode_Is_Off
(Pack
) then
4199 -- State refinement can only occur in a completing package body. Do
4200 -- not verify proper state refinement when the body is subject to
4201 -- pragma SPARK_Mode Off because this disables the requirement for
4202 -- state refinement.
4204 elsif Present
(Body_Id
)
4205 and then SPARK_Mode_Is_Off
(Unit_Declaration_Node
(Body_Id
))
4209 -- Do not verify proper state refinement when the package is an
4210 -- instance as this check was already performed in the generic.
4212 elsif Present
(Generic_Parent
(Spec
)) then
4215 -- Otherwise examine the contents of the package
4218 if Present
(States
) then
4219 State_Elmt
:= First_Elmt
(States
);
4220 while Present
(State_Elmt
) loop
4221 State_Id
:= Node
(State_Elmt
);
4223 -- Emit an error when a non-null state lacks any form of
4226 if not Is_Null_State
(State_Id
)
4227 and then not Has_Null_Refinement
(State_Id
)
4228 and then not Has_Non_Null_Refinement
(State_Id
)
4230 Error_Msg_N
("state & requires refinement", State_Id
);
4233 Next_Elmt
(State_Elmt
);
4237 Check_Packages_In
(Visible_Declarations
(Spec
));
4238 Check_Packages_In
(Private_Declarations
(Spec
));
4242 -----------------------
4243 -- Check_Packages_In --
4244 -----------------------
4246 procedure Check_Packages_In
(Decls
: List_Id
) is
4250 if Present
(Decls
) then
4251 Decl
:= First
(Decls
);
4252 while Present
(Decl
) loop
4253 if Nkind_In
(Decl
, N_Generic_Package_Declaration
,
4254 N_Package_Declaration
)
4256 Check_Package
(Decl
);
4262 end Check_Packages_In
;
4264 -----------------------
4265 -- SPARK_Mode_Is_Off --
4266 -----------------------
4268 function SPARK_Mode_Is_Off
(N
: Node_Id
) return Boolean is
4269 Id
: constant Entity_Id
:= Defining_Entity
(N
);
4270 Prag
: constant Node_Id
:= SPARK_Pragma
(Id
);
4273 -- Default the mode to "off" when the context is an instance and all
4274 -- SPARK_Mode pragmas found within are to be ignored.
4276 if Ignore_SPARK_Mode_Pragmas
(Id
) then
4282 and then Get_SPARK_Mode_From_Annotation
(Prag
) = Off
;
4284 end SPARK_Mode_Is_Off
;
4286 -- Start of processing for Check_State_Refinements
4289 -- A block may declare a nested package
4291 if Nkind
(Context
) = N_Block_Statement
then
4292 Check_Packages_In
(Declarations
(Context
));
4294 -- An entry, protected, subprogram, or task body may declare a nested
4297 elsif Nkind_In
(Context
, N_Entry_Body
,
4302 -- Do not verify proper state refinement when the body is subject to
4303 -- pragma SPARK_Mode Off because this disables the requirement for
4304 -- state refinement.
4306 if not SPARK_Mode_Is_Off
(Context
) then
4307 Check_Packages_In
(Declarations
(Context
));
4310 -- A package body may declare a nested package
4312 elsif Nkind
(Context
) = N_Package_Body
then
4313 Check_Package
(Unit_Declaration_Node
(Corresponding_Spec
(Context
)));
4315 -- Do not verify proper state refinement when the body is subject to
4316 -- pragma SPARK_Mode Off because this disables the requirement for
4317 -- state refinement.
4319 if not SPARK_Mode_Is_Off
(Context
) then
4320 Check_Packages_In
(Declarations
(Context
));
4323 -- A library level [generic] package may declare a nested package
4325 elsif Nkind_In
(Context
, N_Generic_Package_Declaration
,
4326 N_Package_Declaration
)
4327 and then Is_Main_Unit
4329 Check_Package
(Context
);
4331 end Check_State_Refinements
;
4333 ------------------------------
4334 -- Check_Unprotected_Access --
4335 ------------------------------
4337 procedure Check_Unprotected_Access
4341 Cont_Encl_Typ
: Entity_Id
;
4342 Pref_Encl_Typ
: Entity_Id
;
4344 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
4345 -- Check whether Obj is a private component of a protected object.
4346 -- Return the protected type where the component resides, Empty
4349 function Is_Public_Operation
return Boolean;
4350 -- Verify that the enclosing operation is callable from outside the
4351 -- protected object, to minimize false positives.
4353 ------------------------------
4354 -- Enclosing_Protected_Type --
4355 ------------------------------
4357 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
4359 if Is_Entity_Name
(Obj
) then
4361 Ent
: Entity_Id
:= Entity
(Obj
);
4364 -- The object can be a renaming of a private component, use
4365 -- the original record component.
4367 if Is_Prival
(Ent
) then
4368 Ent
:= Prival_Link
(Ent
);
4371 if Is_Protected_Type
(Scope
(Ent
)) then
4377 -- For indexed and selected components, recursively check the prefix
4379 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
4380 return Enclosing_Protected_Type
(Prefix
(Obj
));
4382 -- The object does not denote a protected component
4387 end Enclosing_Protected_Type
;
4389 -------------------------
4390 -- Is_Public_Operation --
4391 -------------------------
4393 function Is_Public_Operation
return Boolean is
4399 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
4400 if Scope
(S
) = Pref_Encl_Typ
then
4401 E
:= First_Entity
(Pref_Encl_Typ
);
4403 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
4417 end Is_Public_Operation
;
4419 -- Start of processing for Check_Unprotected_Access
4422 if Nkind
(Expr
) = N_Attribute_Reference
4423 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
4425 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
4426 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
4428 -- Check whether we are trying to export a protected component to a
4429 -- context with an equal or lower access level.
4431 if Present
(Pref_Encl_Typ
)
4432 and then No
(Cont_Encl_Typ
)
4433 and then Is_Public_Operation
4434 and then Scope_Depth
(Pref_Encl_Typ
) >=
4435 Object_Access_Level
(Context
)
4438 ("??possible unprotected access to protected data", Expr
);
4441 end Check_Unprotected_Access
;
4443 ------------------------------
4444 -- Check_Unused_Body_States --
4445 ------------------------------
4447 procedure Check_Unused_Body_States
(Body_Id
: Entity_Id
) is
4448 procedure Process_Refinement_Clause
4451 -- Inspect all constituents of refinement clause Clause and remove any
4452 -- matches from body state list States.
4454 procedure Report_Unused_Body_States
(States
: Elist_Id
);
4455 -- Emit errors for each abstract state or object found in list States
4457 -------------------------------
4458 -- Process_Refinement_Clause --
4459 -------------------------------
4461 procedure Process_Refinement_Clause
4465 procedure Process_Constituent
(Constit
: Node_Id
);
4466 -- Remove constituent Constit from body state list States
4468 -------------------------
4469 -- Process_Constituent --
4470 -------------------------
4472 procedure Process_Constituent
(Constit
: Node_Id
) is
4473 Constit_Id
: Entity_Id
;
4476 -- Guard against illegal constituents. Only abstract states and
4477 -- objects can appear on the right hand side of a refinement.
4479 if Is_Entity_Name
(Constit
) then
4480 Constit_Id
:= Entity_Of
(Constit
);
4482 if Present
(Constit_Id
)
4483 and then Ekind_In
(Constit_Id
, E_Abstract_State
,
4487 Remove
(States
, Constit_Id
);
4490 end Process_Constituent
;
4496 -- Start of processing for Process_Refinement_Clause
4499 if Nkind
(Clause
) = N_Component_Association
then
4500 Constit
:= Expression
(Clause
);
4502 -- Multiple constituents appear as an aggregate
4504 if Nkind
(Constit
) = N_Aggregate
then
4505 Constit
:= First
(Expressions
(Constit
));
4506 while Present
(Constit
) loop
4507 Process_Constituent
(Constit
);
4511 -- Various forms of a single constituent
4514 Process_Constituent
(Constit
);
4517 end Process_Refinement_Clause
;
4519 -------------------------------
4520 -- Report_Unused_Body_States --
4521 -------------------------------
4523 procedure Report_Unused_Body_States
(States
: Elist_Id
) is
4524 Posted
: Boolean := False;
4525 State_Elmt
: Elmt_Id
;
4526 State_Id
: Entity_Id
;
4529 if Present
(States
) then
4530 State_Elmt
:= First_Elmt
(States
);
4531 while Present
(State_Elmt
) loop
4532 State_Id
:= Node
(State_Elmt
);
4534 -- Constants are part of the hidden state of a package, but the
4535 -- compiler cannot determine whether they have variable input
4536 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4537 -- hidden state. Do not emit an error when a constant does not
4538 -- participate in a state refinement, even though it acts as a
4541 if Ekind
(State_Id
) = E_Constant
then
4544 -- Generate an error message of the form:
4546 -- body of package ... has unused hidden states
4547 -- abstract state ... defined at ...
4548 -- variable ... defined at ...
4554 ("body of package & has unused hidden states", Body_Id
);
4557 Error_Msg_Sloc
:= Sloc
(State_Id
);
4559 if Ekind
(State_Id
) = E_Abstract_State
then
4561 ("\abstract state & defined #", Body_Id
, State_Id
);
4564 SPARK_Msg_NE
("\variable & defined #", Body_Id
, State_Id
);
4568 Next_Elmt
(State_Elmt
);
4571 end Report_Unused_Body_States
;
4575 Prag
: constant Node_Id
:= Get_Pragma
(Body_Id
, Pragma_Refined_State
);
4576 Spec_Id
: constant Entity_Id
:= Spec_Entity
(Body_Id
);
4580 -- Start of processing for Check_Unused_Body_States
4583 -- Inspect the clauses of pragma Refined_State and determine whether all
4584 -- visible states declared within the package body participate in the
4587 if Present
(Prag
) then
4588 Clause
:= Expression
(Get_Argument
(Prag
, Spec_Id
));
4589 States
:= Collect_Body_States
(Body_Id
);
4591 -- Multiple non-null state refinements appear as an aggregate
4593 if Nkind
(Clause
) = N_Aggregate
then
4594 Clause
:= First
(Component_Associations
(Clause
));
4595 while Present
(Clause
) loop
4596 Process_Refinement_Clause
(Clause
, States
);
4600 -- Various forms of a single state refinement
4603 Process_Refinement_Clause
(Clause
, States
);
4606 -- Ensure that all abstract states and objects declared in the
4607 -- package body state space are utilized as constituents.
4609 Report_Unused_Body_States
(States
);
4611 end Check_Unused_Body_States
;
4617 function Choice_List
(N
: Node_Id
) return List_Id
is
4619 if Nkind
(N
) = N_Iterated_Component_Association
then
4620 return Discrete_Choices
(N
);
4626 -------------------------
4627 -- Collect_Body_States --
4628 -------------------------
4630 function Collect_Body_States
(Body_Id
: Entity_Id
) return Elist_Id
is
4631 function Is_Visible_Object
(Obj_Id
: Entity_Id
) return Boolean;
4632 -- Determine whether object Obj_Id is a suitable visible state of a
4635 procedure Collect_Visible_States
4636 (Pack_Id
: Entity_Id
;
4637 States
: in out Elist_Id
);
4638 -- Gather the entities of all abstract states and objects declared in
4639 -- the visible state space of package Pack_Id.
4641 ----------------------------
4642 -- Collect_Visible_States --
4643 ----------------------------
4645 procedure Collect_Visible_States
4646 (Pack_Id
: Entity_Id
;
4647 States
: in out Elist_Id
)
4649 Item_Id
: Entity_Id
;
4652 -- Traverse the entity chain of the package and inspect all visible
4655 Item_Id
:= First_Entity
(Pack_Id
);
4656 while Present
(Item_Id
) and then not In_Private_Part
(Item_Id
) loop
4658 -- Do not consider internally generated items as those cannot be
4659 -- named and participate in refinement.
4661 if not Comes_From_Source
(Item_Id
) then
4664 elsif Ekind
(Item_Id
) = E_Abstract_State
then
4665 Append_New_Elmt
(Item_Id
, States
);
4667 elsif Ekind_In
(Item_Id
, E_Constant
, E_Variable
)
4668 and then Is_Visible_Object
(Item_Id
)
4670 Append_New_Elmt
(Item_Id
, States
);
4672 -- Recursively gather the visible states of a nested package
4674 elsif Ekind
(Item_Id
) = E_Package
then
4675 Collect_Visible_States
(Item_Id
, States
);
4678 Next_Entity
(Item_Id
);
4680 end Collect_Visible_States
;
4682 -----------------------
4683 -- Is_Visible_Object --
4684 -----------------------
4686 function Is_Visible_Object
(Obj_Id
: Entity_Id
) return Boolean is
4688 -- Objects that map generic formals to their actuals are not visible
4689 -- from outside the generic instantiation.
4691 if Present
(Corresponding_Generic_Association
4692 (Declaration_Node
(Obj_Id
)))
4696 -- Constituents of a single protected/task type act as components of
4697 -- the type and are not visible from outside the type.
4699 elsif Ekind
(Obj_Id
) = E_Variable
4700 and then Present
(Encapsulating_State
(Obj_Id
))
4701 and then Is_Single_Concurrent_Object
(Encapsulating_State
(Obj_Id
))
4708 end Is_Visible_Object
;
4712 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Body_Id
);
4714 Item_Id
: Entity_Id
;
4715 States
: Elist_Id
:= No_Elist
;
4717 -- Start of processing for Collect_Body_States
4720 -- Inspect the declarations of the body looking for source objects,
4721 -- packages and package instantiations. Note that even though this
4722 -- processing is very similar to Collect_Visible_States, a package
4723 -- body does not have a First/Next_Entity list.
4725 Decl
:= First
(Declarations
(Body_Decl
));
4726 while Present
(Decl
) loop
4728 -- Capture source objects as internally generated temporaries cannot
4729 -- be named and participate in refinement.
4731 if Nkind
(Decl
) = N_Object_Declaration
then
4732 Item_Id
:= Defining_Entity
(Decl
);
4734 if Comes_From_Source
(Item_Id
)
4735 and then Is_Visible_Object
(Item_Id
)
4737 Append_New_Elmt
(Item_Id
, States
);
4740 -- Capture the visible abstract states and objects of a source
4741 -- package [instantiation].
4743 elsif Nkind
(Decl
) = N_Package_Declaration
then
4744 Item_Id
:= Defining_Entity
(Decl
);
4746 if Comes_From_Source
(Item_Id
) then
4747 Collect_Visible_States
(Item_Id
, States
);
4755 end Collect_Body_States
;
4757 ------------------------
4758 -- Collect_Interfaces --
4759 ------------------------
4761 procedure Collect_Interfaces
4763 Ifaces_List
: out Elist_Id
;
4764 Exclude_Parents
: Boolean := False;
4765 Use_Full_View
: Boolean := True)
4767 procedure Collect
(Typ
: Entity_Id
);
4768 -- Subsidiary subprogram used to traverse the whole list
4769 -- of directly and indirectly implemented interfaces
4775 procedure Collect
(Typ
: Entity_Id
) is
4776 Ancestor
: Entity_Id
;
4784 -- Handle private types and subtypes
4787 and then Is_Private_Type
(Typ
)
4788 and then Present
(Full_View
(Typ
))
4790 Full_T
:= Full_View
(Typ
);
4792 if Ekind
(Full_T
) = E_Record_Subtype
then
4793 Full_T
:= Etype
(Typ
);
4795 if Present
(Full_View
(Full_T
)) then
4796 Full_T
:= Full_View
(Full_T
);
4801 -- Include the ancestor if we are generating the whole list of
4802 -- abstract interfaces.
4804 if Etype
(Full_T
) /= Typ
4806 -- Protect the frontend against wrong sources. For example:
4809 -- type A is tagged null record;
4810 -- type B is new A with private;
4811 -- type C is new A with private;
4813 -- type B is new C with null record;
4814 -- type C is new B with null record;
4817 and then Etype
(Full_T
) /= T
4819 Ancestor
:= Etype
(Full_T
);
4822 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
4823 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
4827 -- Traverse the graph of ancestor interfaces
4829 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
4830 Id
:= First
(Abstract_Interface_List
(Full_T
));
4831 while Present
(Id
) loop
4832 Iface
:= Etype
(Id
);
4834 -- Protect against wrong uses. For example:
4835 -- type I is interface;
4836 -- type O is tagged null record;
4837 -- type Wrong is new I and O with null record; -- ERROR
4839 if Is_Interface
(Iface
) then
4841 and then Etype
(T
) /= T
4842 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
4847 Append_Unique_Elmt
(Iface
, Ifaces_List
);
4856 -- Start of processing for Collect_Interfaces
4859 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
4860 Ifaces_List
:= New_Elmt_List
;
4862 end Collect_Interfaces
;
4864 ----------------------------------
4865 -- Collect_Interface_Components --
4866 ----------------------------------
4868 procedure Collect_Interface_Components
4869 (Tagged_Type
: Entity_Id
;
4870 Components_List
: out Elist_Id
)
4872 procedure Collect
(Typ
: Entity_Id
);
4873 -- Subsidiary subprogram used to climb to the parents
4879 procedure Collect
(Typ
: Entity_Id
) is
4880 Tag_Comp
: Entity_Id
;
4881 Parent_Typ
: Entity_Id
;
4884 -- Handle private types
4886 if Present
(Full_View
(Etype
(Typ
))) then
4887 Parent_Typ
:= Full_View
(Etype
(Typ
));
4889 Parent_Typ
:= Etype
(Typ
);
4892 if Parent_Typ
/= Typ
4894 -- Protect the frontend against wrong sources. For example:
4897 -- type A is tagged null record;
4898 -- type B is new A with private;
4899 -- type C is new A with private;
4901 -- type B is new C with null record;
4902 -- type C is new B with null record;
4905 and then Parent_Typ
/= Tagged_Type
4907 Collect
(Parent_Typ
);
4910 -- Collect the components containing tags of secondary dispatch
4913 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
4914 while Present
(Tag_Comp
) loop
4915 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
4916 Append_Elmt
(Tag_Comp
, Components_List
);
4918 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
4922 -- Start of processing for Collect_Interface_Components
4925 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
4926 and then Is_Tagged_Type
(Tagged_Type
));
4928 Components_List
:= New_Elmt_List
;
4929 Collect
(Tagged_Type
);
4930 end Collect_Interface_Components
;
4932 -----------------------------
4933 -- Collect_Interfaces_Info --
4934 -----------------------------
4936 procedure Collect_Interfaces_Info
4938 Ifaces_List
: out Elist_Id
;
4939 Components_List
: out Elist_Id
;
4940 Tags_List
: out Elist_Id
)
4942 Comps_List
: Elist_Id
;
4943 Comp_Elmt
: Elmt_Id
;
4944 Comp_Iface
: Entity_Id
;
4945 Iface_Elmt
: Elmt_Id
;
4948 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
4949 -- Search for the secondary tag associated with the interface type
4950 -- Iface that is implemented by T.
4956 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
4959 if not Is_CPP_Class
(T
) then
4960 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
4962 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
4966 and then Is_Tag
(Node
(ADT
))
4967 and then Related_Type
(Node
(ADT
)) /= Iface
4969 -- Skip secondary dispatch table referencing thunks to user
4970 -- defined primitives covered by this interface.
4972 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
4975 -- Skip secondary dispatch tables of Ada types
4977 if not Is_CPP_Class
(T
) then
4979 -- Skip secondary dispatch table referencing thunks to
4980 -- predefined primitives.
4982 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
4985 -- Skip secondary dispatch table referencing user-defined
4986 -- primitives covered by this interface.
4988 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
4991 -- Skip secondary dispatch table referencing predefined
4994 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
4999 pragma Assert
(Is_Tag
(Node
(ADT
)));
5003 -- Start of processing for Collect_Interfaces_Info
5006 Collect_Interfaces
(T
, Ifaces_List
);
5007 Collect_Interface_Components
(T
, Comps_List
);
5009 -- Search for the record component and tag associated with each
5010 -- interface type of T.
5012 Components_List
:= New_Elmt_List
;
5013 Tags_List
:= New_Elmt_List
;
5015 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5016 while Present
(Iface_Elmt
) loop
5017 Iface
:= Node
(Iface_Elmt
);
5019 -- Associate the primary tag component and the primary dispatch table
5020 -- with all the interfaces that are parents of T
5022 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
5023 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
5024 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
5026 -- Otherwise search for the tag component and secondary dispatch
5030 Comp_Elmt
:= First_Elmt
(Comps_List
);
5031 while Present
(Comp_Elmt
) loop
5032 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
5034 if Comp_Iface
= Iface
5035 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
5037 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
5038 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
5042 Next_Elmt
(Comp_Elmt
);
5044 pragma Assert
(Present
(Comp_Elmt
));
5047 Next_Elmt
(Iface_Elmt
);
5049 end Collect_Interfaces_Info
;
5051 ---------------------
5052 -- Collect_Parents --
5053 ---------------------
5055 procedure Collect_Parents
5057 List
: out Elist_Id
;
5058 Use_Full_View
: Boolean := True)
5060 Current_Typ
: Entity_Id
:= T
;
5061 Parent_Typ
: Entity_Id
;
5064 List
:= New_Elmt_List
;
5066 -- No action if the if the type has no parents
5068 if T
= Etype
(T
) then
5073 Parent_Typ
:= Etype
(Current_Typ
);
5075 if Is_Private_Type
(Parent_Typ
)
5076 and then Present
(Full_View
(Parent_Typ
))
5077 and then Use_Full_View
5079 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5082 Append_Elmt
(Parent_Typ
, List
);
5084 exit when Parent_Typ
= Current_Typ
;
5085 Current_Typ
:= Parent_Typ
;
5087 end Collect_Parents
;
5089 ----------------------------------
5090 -- Collect_Primitive_Operations --
5091 ----------------------------------
5093 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
5094 B_Type
: constant Entity_Id
:= Base_Type
(T
);
5096 function Match
(E
: Entity_Id
) return Boolean;
5097 -- True if E's base type is B_Type, or E is of an anonymous access type
5098 -- and the base type of its designated type is B_Type.
5104 function Match
(E
: Entity_Id
) return Boolean is
5105 Etyp
: Entity_Id
:= Etype
(E
);
5108 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
5109 Etyp
:= Designated_Type
(Etyp
);
5112 -- In Ada 2012 a primitive operation may have a formal of an
5113 -- incomplete view of the parent type.
5115 return Base_Type
(Etyp
) = B_Type
5117 (Ada_Version
>= Ada_2012
5118 and then Ekind
(Etyp
) = E_Incomplete_Type
5119 and then Full_View
(Etyp
) = B_Type
);
5124 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
5125 B_Scope
: Entity_Id
:= Scope
(B_Type
);
5127 Eq_Prims_List
: Elist_Id
:= No_Elist
;
5130 Is_Type_In_Pkg
: Boolean;
5131 Formal_Derived
: Boolean := False;
5134 -- Start of processing for Collect_Primitive_Operations
5137 -- For tagged types, the primitive operations are collected as they
5138 -- are declared, and held in an explicit list which is simply returned.
5140 if Is_Tagged_Type
(B_Type
) then
5141 return Primitive_Operations
(B_Type
);
5143 -- An untagged generic type that is a derived type inherits the
5144 -- primitive operations of its parent type. Other formal types only
5145 -- have predefined operators, which are not explicitly represented.
5147 elsif Is_Generic_Type
(B_Type
) then
5148 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
5149 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
5150 N_Formal_Derived_Type_Definition
5152 Formal_Derived
:= True;
5154 return New_Elmt_List
;
5158 Op_List
:= New_Elmt_List
;
5160 if B_Scope
= Standard_Standard
then
5161 if B_Type
= Standard_String
then
5162 Append_Elmt
(Standard_Op_Concat
, Op_List
);
5164 elsif B_Type
= Standard_Wide_String
then
5165 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
5171 -- Locate the primitive subprograms of the type
5174 -- The primitive operations appear after the base type, except if the
5175 -- derivation happens within the private part of B_Scope and the type
5176 -- is a private type, in which case both the type and some primitive
5177 -- operations may appear before the base type, and the list of
5178 -- candidates starts after the type.
5180 if In_Open_Scopes
(B_Scope
)
5181 and then Scope
(T
) = B_Scope
5182 and then In_Private_Part
(B_Scope
)
5184 Id
:= Next_Entity
(T
);
5186 -- In Ada 2012, If the type has an incomplete partial view, there may
5187 -- be primitive operations declared before the full view, so we need
5188 -- to start scanning from the incomplete view, which is earlier on
5189 -- the entity chain.
5191 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
5192 and then Present
(Incomplete_View
(Parent
(B_Type
)))
5194 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
5196 -- If T is a derived from a type with an incomplete view declared
5197 -- elsewhere, that incomplete view is irrelevant, we want the
5198 -- operations in the scope of T.
5200 if Scope
(Id
) /= Scope
(B_Type
) then
5201 Id
:= Next_Entity
(B_Type
);
5205 Id
:= Next_Entity
(B_Type
);
5208 -- Set flag if this is a type in a package spec
5211 Is_Package_Or_Generic_Package
(B_Scope
)
5213 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
5216 while Present
(Id
) loop
5218 -- Test whether the result type or any of the parameter types of
5219 -- each subprogram following the type match that type when the
5220 -- type is declared in a package spec, is a derived type, or the
5221 -- subprogram is marked as primitive. (The Is_Primitive test is
5222 -- needed to find primitives of nonderived types in declarative
5223 -- parts that happen to override the predefined "=" operator.)
5225 -- Note that generic formal subprograms are not considered to be
5226 -- primitive operations and thus are never inherited.
5228 if Is_Overloadable
(Id
)
5229 and then (Is_Type_In_Pkg
5230 or else Is_Derived_Type
(B_Type
)
5231 or else Is_Primitive
(Id
))
5232 and then Nkind
(Parent
(Parent
(Id
)))
5233 not in N_Formal_Subprogram_Declaration
5241 Formal
:= First_Formal
(Id
);
5242 while Present
(Formal
) loop
5243 if Match
(Formal
) then
5248 Next_Formal
(Formal
);
5252 -- For a formal derived type, the only primitives are the ones
5253 -- inherited from the parent type. Operations appearing in the
5254 -- package declaration are not primitive for it.
5257 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
5259 -- In the special case of an equality operator aliased to
5260 -- an overriding dispatching equality belonging to the same
5261 -- type, we don't include it in the list of primitives.
5262 -- This avoids inheriting multiple equality operators when
5263 -- deriving from untagged private types whose full type is
5264 -- tagged, which can otherwise cause ambiguities. Note that
5265 -- this should only happen for this kind of untagged parent
5266 -- type, since normally dispatching operations are inherited
5267 -- using the type's Primitive_Operations list.
5269 if Chars
(Id
) = Name_Op_Eq
5270 and then Is_Dispatching_Operation
(Id
)
5271 and then Present
(Alias
(Id
))
5272 and then Present
(Overridden_Operation
(Alias
(Id
)))
5273 and then Base_Type
(Etype
(First_Entity
(Id
))) =
5274 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
5278 -- Include the subprogram in the list of primitives
5281 Append_Elmt
(Id
, Op_List
);
5283 -- Save collected equality primitives for later filtering
5284 -- (if we are processing a private type for which we can
5285 -- collect several candidates).
5287 if Inherits_From_Tagged_Full_View
(T
)
5288 and then Chars
(Id
) = Name_Op_Eq
5289 and then Etype
(First_Formal
(Id
)) =
5290 Etype
(Next_Formal
(First_Formal
(Id
)))
5292 if No
(Eq_Prims_List
) then
5293 Eq_Prims_List
:= New_Elmt_List
;
5296 Append_Elmt
(Id
, Eq_Prims_List
);
5304 -- For a type declared in System, some of its operations may
5305 -- appear in the target-specific extension to System.
5308 and then B_Scope
= RTU_Entity
(System
)
5309 and then Present_System_Aux
5311 B_Scope
:= System_Aux_Id
;
5312 Id
:= First_Entity
(System_Aux_Id
);
5316 -- Filter collected equality primitives
5318 if Inherits_From_Tagged_Full_View
(T
)
5319 and then Present
(Eq_Prims_List
)
5322 First
: constant Elmt_Id
:= First_Elmt
(Eq_Prims_List
);
5326 pragma Assert
(No
(Next_Elmt
(First
))
5327 or else No
(Next_Elmt
(Next_Elmt
(First
))));
5329 -- No action needed if we have collected a single equality
5332 if Present
(Next_Elmt
(First
)) then
5333 Second
:= Next_Elmt
(First
);
5335 if Is_Dispatching_Operation
5336 (Ultimate_Alias
(Node
(First
)))
5338 Remove
(Op_List
, Node
(First
));
5340 elsif Is_Dispatching_Operation
5341 (Ultimate_Alias
(Node
(Second
)))
5343 Remove
(Op_List
, Node
(Second
));
5346 pragma Assert
(False);
5347 raise Program_Error
;
5355 end Collect_Primitive_Operations
;
5357 -----------------------------------
5358 -- Compile_Time_Constraint_Error --
5359 -----------------------------------
5361 function Compile_Time_Constraint_Error
5364 Ent
: Entity_Id
:= Empty
;
5365 Loc
: Source_Ptr
:= No_Location
;
5366 Warn
: Boolean := False) return Node_Id
5368 Msgc
: String (1 .. Msg
'Length + 3);
5369 -- Copy of message, with room for possible ?? or << and ! at end
5375 -- Start of processing for Compile_Time_Constraint_Error
5378 -- If this is a warning, convert it into an error if we are in code
5379 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5380 -- warning. The rationale is that a compile-time constraint error should
5381 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5382 -- a few cases we prefer to issue a warning and generate both a suitable
5383 -- run-time error in GNAT and a suitable check message in GNATprove.
5384 -- Those cases are those that likely correspond to deactivated SPARK
5385 -- code, so that this kind of code can be compiled and analyzed instead
5386 -- of being rejected.
5388 Error_Msg_Warn
:= Warn
or SPARK_Mode
/= On
;
5390 -- A static constraint error in an instance body is not a fatal error.
5391 -- we choose to inhibit the message altogether, because there is no
5392 -- obvious node (for now) on which to post it. On the other hand the
5393 -- offending node must be replaced with a constraint_error in any case.
5395 -- No messages are generated if we already posted an error on this node
5397 if not Error_Posted
(N
) then
5398 if Loc
/= No_Location
then
5404 -- Copy message to Msgc, converting any ? in the message into <
5405 -- instead, so that we have an error in GNATprove mode.
5409 for J
in 1 .. Msgl
loop
5410 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
- 1) /= ''') then
5413 Msgc
(J
) := Msg
(J
);
5417 -- Message is a warning, even in Ada 95 case
5419 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
5422 -- In Ada 83, all messages are warnings. In the private part and the
5423 -- body of an instance, constraint_checks are only warnings. We also
5424 -- make this a warning if the Warn parameter is set.
5427 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
5428 or else In_Instance_Not_Visible
5436 -- Otherwise we have a real error message (Ada 95 static case) and we
5437 -- make this an unconditional message. Note that in the warning case
5438 -- we do not make the message unconditional, it seems reasonable to
5439 -- delete messages like this (about exceptions that will be raised)
5448 -- One more test, skip the warning if the related expression is
5449 -- statically unevaluated, since we don't want to warn about what
5450 -- will happen when something is evaluated if it never will be
5453 if not Is_Statically_Unevaluated
(N
) then
5454 if Present
(Ent
) then
5455 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
5457 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
5462 -- Check whether the context is an Init_Proc
5464 if Inside_Init_Proc
then
5466 Conc_Typ
: constant Entity_Id
:=
5467 Corresponding_Concurrent_Type
5468 (Entity
(Parameter_Type
(First
5469 (Parameter_Specifications
5470 (Parent
(Current_Scope
))))));
5473 -- Don't complain if the corresponding concurrent type
5474 -- doesn't come from source (i.e. a single task/protected
5477 if Present
(Conc_Typ
)
5478 and then not Comes_From_Source
(Conc_Typ
)
5481 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
5484 if GNATprove_Mode
then
5486 ("\& would have been raised for objects of this "
5487 & "type", N
, Standard_Constraint_Error
, Eloc
);
5490 ("\& will be raised for objects of this type??",
5491 N
, Standard_Constraint_Error
, Eloc
);
5497 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
5501 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
5502 Set_Error_Posted
(N
);
5508 end Compile_Time_Constraint_Error
;
5510 -----------------------
5511 -- Conditional_Delay --
5512 -----------------------
5514 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
5516 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
5517 Set_Has_Delayed_Freeze
(New_Ent
);
5519 end Conditional_Delay
;
5521 -------------------------
5522 -- Copy_Component_List --
5523 -------------------------
5525 function Copy_Component_List
5527 Loc
: Source_Ptr
) return List_Id
5530 Comps
: constant List_Id
:= New_List
;
5533 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
5534 while Present
(Comp
) loop
5535 if Comes_From_Source
(Comp
) then
5537 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
5540 Make_Component_Declaration
(Loc
,
5541 Defining_Identifier
=>
5542 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
5543 Component_Definition
=>
5545 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
5549 Next_Component
(Comp
);
5553 end Copy_Component_List
;
5555 -------------------------
5556 -- Copy_Parameter_List --
5557 -------------------------
5559 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
5560 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
5565 if No
(First_Formal
(Subp_Id
)) then
5569 Formal
:= First_Formal
(Subp_Id
);
5570 while Present
(Formal
) loop
5572 Make_Parameter_Specification
(Loc
,
5573 Defining_Identifier
=>
5574 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
5575 In_Present
=> In_Present
(Parent
(Formal
)),
5576 Out_Present
=> Out_Present
(Parent
(Formal
)),
5578 New_Occurrence_Of
(Etype
(Formal
), Loc
),
5580 New_Copy_Tree
(Expression
(Parent
(Formal
)))));
5582 Next_Formal
(Formal
);
5587 end Copy_Parameter_List
;
5589 ----------------------------
5590 -- Copy_SPARK_Mode_Aspect --
5591 ----------------------------
5593 procedure Copy_SPARK_Mode_Aspect
(From
: Node_Id
; To
: Node_Id
) is
5594 pragma Assert
(not Has_Aspects
(To
));
5598 if Has_Aspects
(From
) then
5599 Asp
:= Find_Aspect
(Defining_Entity
(From
), Aspect_SPARK_Mode
);
5601 if Present
(Asp
) then
5602 Set_Aspect_Specifications
(To
, New_List
(New_Copy_Tree
(Asp
)));
5603 Set_Has_Aspects
(To
, True);
5606 end Copy_SPARK_Mode_Aspect
;
5608 --------------------------
5609 -- Copy_Subprogram_Spec --
5610 --------------------------
5612 function Copy_Subprogram_Spec
(Spec
: Node_Id
) return Node_Id
is
5614 Formal_Spec
: Node_Id
;
5618 -- The structure of the original tree must be replicated without any
5619 -- alterations. Use New_Copy_Tree for this purpose.
5621 Result
:= New_Copy_Tree
(Spec
);
5623 -- However, the spec of a null procedure carries the corresponding null
5624 -- statement of the body (created by the parser), and this cannot be
5625 -- shared with the new subprogram spec.
5627 if Nkind
(Result
) = N_Procedure_Specification
then
5628 Set_Null_Statement
(Result
, Empty
);
5631 -- Create a new entity for the defining unit name
5633 Def_Id
:= Defining_Unit_Name
(Result
);
5634 Set_Defining_Unit_Name
(Result
,
5635 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
5637 -- Create new entities for the formal parameters
5639 if Present
(Parameter_Specifications
(Result
)) then
5640 Formal_Spec
:= First
(Parameter_Specifications
(Result
));
5641 while Present
(Formal_Spec
) loop
5642 Def_Id
:= Defining_Identifier
(Formal_Spec
);
5643 Set_Defining_Identifier
(Formal_Spec
,
5644 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
5651 end Copy_Subprogram_Spec
;
5653 --------------------------------
5654 -- Corresponding_Generic_Type --
5655 --------------------------------
5657 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
5663 if not Is_Generic_Actual_Type
(T
) then
5666 -- If the actual is the actual of an enclosing instance, resolution
5667 -- was correct in the generic.
5669 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
5670 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
5672 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
5679 if Is_Wrapper_Package
(Inst
) then
5680 Inst
:= Related_Instance
(Inst
);
5685 (Specification
(Unit_Declaration_Node
(Inst
)));
5687 -- Generic actual has the same name as the corresponding formal
5689 Typ
:= First_Entity
(Gen
);
5690 while Present
(Typ
) loop
5691 if Chars
(Typ
) = Chars
(T
) then
5700 end Corresponding_Generic_Type
;
5702 --------------------
5703 -- Current_Entity --
5704 --------------------
5706 -- The currently visible definition for a given identifier is the
5707 -- one most chained at the start of the visibility chain, i.e. the
5708 -- one that is referenced by the Node_Id value of the name of the
5709 -- given identifier.
5711 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
5713 return Get_Name_Entity_Id
(Chars
(N
));
5716 -----------------------------
5717 -- Current_Entity_In_Scope --
5718 -----------------------------
5720 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
5722 CS
: constant Entity_Id
:= Current_Scope
;
5724 Transient_Case
: constant Boolean := Scope_Is_Transient
;
5727 E
:= Get_Name_Entity_Id
(Chars
(N
));
5729 and then Scope
(E
) /= CS
5730 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
5736 end Current_Entity_In_Scope
;
5742 function Current_Scope
return Entity_Id
is
5744 if Scope_Stack
.Last
= -1 then
5745 return Standard_Standard
;
5748 C
: constant Entity_Id
:=
5749 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
5754 return Standard_Standard
;
5760 ----------------------------
5761 -- Current_Scope_No_Loops --
5762 ----------------------------
5764 function Current_Scope_No_Loops
return Entity_Id
is
5768 -- Examine the scope stack starting from the current scope and skip any
5769 -- internally generated loops.
5772 while Present
(S
) and then S
/= Standard_Standard
loop
5773 if Ekind
(S
) = E_Loop
and then not Comes_From_Source
(S
) then
5781 end Current_Scope_No_Loops
;
5783 ------------------------
5784 -- Current_Subprogram --
5785 ------------------------
5787 function Current_Subprogram
return Entity_Id
is
5788 Scop
: constant Entity_Id
:= Current_Scope
;
5790 if Is_Subprogram_Or_Generic_Subprogram
(Scop
) then
5793 return Enclosing_Subprogram
(Scop
);
5795 end Current_Subprogram
;
5797 ----------------------------------
5798 -- Deepest_Type_Access_Level --
5799 ----------------------------------
5801 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
5803 if Ekind
(Typ
) = E_Anonymous_Access_Type
5804 and then not Is_Local_Anonymous_Access
(Typ
)
5805 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
5807 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5811 Scope_Depth
(Enclosing_Dynamic_Scope
5812 (Defining_Identifier
5813 (Associated_Node_For_Itype
(Typ
))));
5815 -- For generic formal type, return Int'Last (infinite).
5816 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5818 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
5819 return UI_From_Int
(Int
'Last);
5822 return Type_Access_Level
(Typ
);
5824 end Deepest_Type_Access_Level
;
5826 ---------------------
5827 -- Defining_Entity --
5828 ---------------------
5830 function Defining_Entity
5832 Empty_On_Errors
: Boolean := False;
5833 Concurrent_Subunit
: Boolean := False) return Entity_Id
5837 when N_Abstract_Subprogram_Declaration
5838 | N_Expression_Function
5839 | N_Formal_Subprogram_Declaration
5840 | N_Generic_Package_Declaration
5841 | N_Generic_Subprogram_Declaration
5842 | N_Package_Declaration
5844 | N_Subprogram_Body_Stub
5845 | N_Subprogram_Declaration
5846 | N_Subprogram_Renaming_Declaration
5848 return Defining_Entity
(Specification
(N
));
5850 when N_Component_Declaration
5851 | N_Defining_Program_Unit_Name
5852 | N_Discriminant_Specification
5854 | N_Entry_Declaration
5855 | N_Entry_Index_Specification
5856 | N_Exception_Declaration
5857 | N_Exception_Renaming_Declaration
5858 | N_Formal_Object_Declaration
5859 | N_Formal_Package_Declaration
5860 | N_Formal_Type_Declaration
5861 | N_Full_Type_Declaration
5862 | N_Implicit_Label_Declaration
5863 | N_Incomplete_Type_Declaration
5864 | N_Iterator_Specification
5865 | N_Loop_Parameter_Specification
5866 | N_Number_Declaration
5867 | N_Object_Declaration
5868 | N_Object_Renaming_Declaration
5869 | N_Package_Body_Stub
5870 | N_Parameter_Specification
5871 | N_Private_Extension_Declaration
5872 | N_Private_Type_Declaration
5874 | N_Protected_Body_Stub
5875 | N_Protected_Type_Declaration
5876 | N_Single_Protected_Declaration
5877 | N_Single_Task_Declaration
5878 | N_Subtype_Declaration
5881 | N_Task_Type_Declaration
5883 return Defining_Identifier
(N
);
5887 Bod
: constant Node_Id
:= Proper_Body
(N
);
5888 Orig_Bod
: constant Node_Id
:= Original_Node
(Bod
);
5891 -- Retrieve the entity of the original protected or task body
5892 -- if requested by the caller.
5894 if Concurrent_Subunit
5895 and then Nkind
(Bod
) = N_Null_Statement
5896 and then Nkind_In
(Orig_Bod
, N_Protected_Body
, N_Task_Body
)
5898 return Defining_Entity
(Orig_Bod
);
5900 return Defining_Entity
(Bod
);
5904 when N_Function_Instantiation
5905 | N_Function_Specification
5906 | N_Generic_Function_Renaming_Declaration
5907 | N_Generic_Package_Renaming_Declaration
5908 | N_Generic_Procedure_Renaming_Declaration
5910 | N_Package_Instantiation
5911 | N_Package_Renaming_Declaration
5912 | N_Package_Specification
5913 | N_Procedure_Instantiation
5914 | N_Procedure_Specification
5917 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
5918 Err
: Entity_Id
:= Empty
;
5921 if Nkind
(Nam
) in N_Entity
then
5924 -- For Error, make up a name and attach to declaration so we
5925 -- can continue semantic analysis.
5927 elsif Nam
= Error
then
5928 if Empty_On_Errors
then
5931 Err
:= Make_Temporary
(Sloc
(N
), 'T');
5932 Set_Defining_Unit_Name
(N
, Err
);
5937 -- If not an entity, get defining identifier
5940 return Defining_Identifier
(Nam
);
5944 when N_Block_Statement
5947 return Entity
(Identifier
(N
));
5950 if Empty_On_Errors
then
5953 raise Program_Error
;
5956 end Defining_Entity
;
5958 --------------------------
5959 -- Denotes_Discriminant --
5960 --------------------------
5962 function Denotes_Discriminant
5964 Check_Concurrent
: Boolean := False) return Boolean
5969 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
5975 -- If we are checking for a protected type, the discriminant may have
5976 -- been rewritten as the corresponding discriminal of the original type
5977 -- or of the corresponding concurrent record, depending on whether we
5978 -- are in the spec or body of the protected type.
5980 return Ekind
(E
) = E_Discriminant
5983 and then Ekind
(E
) = E_In_Parameter
5984 and then Present
(Discriminal_Link
(E
))
5986 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
5988 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
5989 end Denotes_Discriminant
;
5991 -------------------------
5992 -- Denotes_Same_Object --
5993 -------------------------
5995 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
5996 function Is_Renaming
(N
: Node_Id
) return Boolean;
5997 -- Return true if N names a renaming entity
5999 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
6000 -- For renamings, return False if the prefix of any dereference within
6001 -- the renamed object_name is a variable, or any expression within the
6002 -- renamed object_name contains references to variables or calls on
6003 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6009 function Is_Renaming
(N
: Node_Id
) return Boolean is
6012 Is_Entity_Name
(N
) and then Present
(Renamed_Entity
(Entity
(N
)));
6015 -----------------------
6016 -- Is_Valid_Renaming --
6017 -----------------------
6019 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
6020 function Check_Renaming
(N
: Node_Id
) return Boolean;
6021 -- Recursive function used to traverse all the prefixes of N
6023 --------------------
6024 -- Check_Renaming --
6025 --------------------
6027 function Check_Renaming
(N
: Node_Id
) return Boolean is
6030 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
6035 if Nkind
(N
) = N_Indexed_Component
then
6040 Indx
:= First
(Expressions
(N
));
6041 while Present
(Indx
) loop
6042 if not Is_OK_Static_Expression
(Indx
) then
6051 if Has_Prefix
(N
) then
6053 P
: constant Node_Id
:= Prefix
(N
);
6056 if Nkind
(N
) = N_Explicit_Dereference
6057 and then Is_Variable
(P
)
6061 elsif Is_Entity_Name
(P
)
6062 and then Ekind
(Entity
(P
)) = E_Function
6066 elsif Nkind
(P
) = N_Function_Call
then
6070 -- Recursion to continue traversing the prefix of the
6071 -- renaming expression
6073 return Check_Renaming
(P
);
6080 -- Start of processing for Is_Valid_Renaming
6083 return Check_Renaming
(N
);
6084 end Is_Valid_Renaming
;
6088 Obj1
: Node_Id
:= A1
;
6089 Obj2
: Node_Id
:= A2
;
6091 -- Start of processing for Denotes_Same_Object
6094 -- Both names statically denote the same stand-alone object or parameter
6095 -- (RM 6.4.1(6.5/3))
6097 if Is_Entity_Name
(Obj1
)
6098 and then Is_Entity_Name
(Obj2
)
6099 and then Entity
(Obj1
) = Entity
(Obj2
)
6104 -- For renamings, the prefix of any dereference within the renamed
6105 -- object_name is not a variable, and any expression within the
6106 -- renamed object_name contains no references to variables nor
6107 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6109 if Is_Renaming
(Obj1
) then
6110 if Is_Valid_Renaming
(Obj1
) then
6111 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
6117 if Is_Renaming
(Obj2
) then
6118 if Is_Valid_Renaming
(Obj2
) then
6119 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
6125 -- No match if not same node kind (such cases are handled by
6126 -- Denotes_Same_Prefix)
6128 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
6131 -- After handling valid renamings, one of the two names statically
6132 -- denoted a renaming declaration whose renamed object_name is known
6133 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6135 elsif Is_Entity_Name
(Obj1
) then
6136 if Is_Entity_Name
(Obj2
) then
6137 return Entity
(Obj1
) = Entity
(Obj2
);
6142 -- Both names are selected_components, their prefixes are known to
6143 -- denote the same object, and their selector_names denote the same
6144 -- component (RM 6.4.1(6.6/3)).
6146 elsif Nkind
(Obj1
) = N_Selected_Component
then
6147 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
6149 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
6151 -- Both names are dereferences and the dereferenced names are known to
6152 -- denote the same object (RM 6.4.1(6.7/3))
6154 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
6155 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
6157 -- Both names are indexed_components, their prefixes are known to denote
6158 -- the same object, and each of the pairs of corresponding index values
6159 -- are either both static expressions with the same static value or both
6160 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6162 elsif Nkind
(Obj1
) = N_Indexed_Component
then
6163 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
6171 Indx1
:= First
(Expressions
(Obj1
));
6172 Indx2
:= First
(Expressions
(Obj2
));
6173 while Present
(Indx1
) loop
6175 -- Indexes must denote the same static value or same object
6177 if Is_OK_Static_Expression
(Indx1
) then
6178 if not Is_OK_Static_Expression
(Indx2
) then
6181 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
6185 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
6197 -- Both names are slices, their prefixes are known to denote the same
6198 -- object, and the two slices have statically matching index constraints
6199 -- (RM 6.4.1(6.9/3))
6201 elsif Nkind
(Obj1
) = N_Slice
6202 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
6205 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
6208 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
6209 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
6211 -- Check whether bounds are statically identical. There is no
6212 -- attempt to detect partial overlap of slices.
6214 return Denotes_Same_Object
(Lo1
, Lo2
)
6216 Denotes_Same_Object
(Hi1
, Hi2
);
6219 -- In the recursion, literals appear as indexes
6221 elsif Nkind
(Obj1
) = N_Integer_Literal
6223 Nkind
(Obj2
) = N_Integer_Literal
6225 return Intval
(Obj1
) = Intval
(Obj2
);
6230 end Denotes_Same_Object
;
6232 -------------------------
6233 -- Denotes_Same_Prefix --
6234 -------------------------
6236 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
6238 if Is_Entity_Name
(A1
) then
6239 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
6240 and then not Is_Access_Type
(Etype
(A1
))
6242 return Denotes_Same_Object
(A1
, Prefix
(A2
))
6243 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
6248 elsif Is_Entity_Name
(A2
) then
6249 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
6251 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
6253 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
6256 Root1
, Root2
: Node_Id
;
6257 Depth1
, Depth2
: Nat
:= 0;
6260 Root1
:= Prefix
(A1
);
6261 while not Is_Entity_Name
(Root1
) loop
6263 (Root1
, N_Selected_Component
, N_Indexed_Component
)
6267 Root1
:= Prefix
(Root1
);
6270 Depth1
:= Depth1
+ 1;
6273 Root2
:= Prefix
(A2
);
6274 while not Is_Entity_Name
(Root2
) loop
6275 if not Nkind_In
(Root2
, N_Selected_Component
,
6276 N_Indexed_Component
)
6280 Root2
:= Prefix
(Root2
);
6283 Depth2
:= Depth2
+ 1;
6286 -- If both have the same depth and they do not denote the same
6287 -- object, they are disjoint and no warning is needed.
6289 if Depth1
= Depth2
then
6292 elsif Depth1
> Depth2
then
6293 Root1
:= Prefix
(A1
);
6294 for J
in 1 .. Depth1
- Depth2
- 1 loop
6295 Root1
:= Prefix
(Root1
);
6298 return Denotes_Same_Object
(Root1
, A2
);
6301 Root2
:= Prefix
(A2
);
6302 for J
in 1 .. Depth2
- Depth1
- 1 loop
6303 Root2
:= Prefix
(Root2
);
6306 return Denotes_Same_Object
(A1
, Root2
);
6313 end Denotes_Same_Prefix
;
6315 ----------------------
6316 -- Denotes_Variable --
6317 ----------------------
6319 function Denotes_Variable
(N
: Node_Id
) return Boolean is
6321 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
6322 end Denotes_Variable
;
6324 -----------------------------
6325 -- Depends_On_Discriminant --
6326 -----------------------------
6328 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
6333 Get_Index_Bounds
(N
, L
, H
);
6334 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
6335 end Depends_On_Discriminant
;
6337 -------------------------
6338 -- Designate_Same_Unit --
6339 -------------------------
6341 function Designate_Same_Unit
6343 Name2
: Node_Id
) return Boolean
6345 K1
: constant Node_Kind
:= Nkind
(Name1
);
6346 K2
: constant Node_Kind
:= Nkind
(Name2
);
6348 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
6349 -- Returns the parent unit name node of a defining program unit name
6350 -- or the prefix if N is a selected component or an expanded name.
6352 function Select_Node
(N
: Node_Id
) return Node_Id
;
6353 -- Returns the defining identifier node of a defining program unit
6354 -- name or the selector node if N is a selected component or an
6361 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
6363 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
6374 function Select_Node
(N
: Node_Id
) return Node_Id
is
6376 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
6377 return Defining_Identifier
(N
);
6379 return Selector_Name
(N
);
6383 -- Start of processing for Designate_Same_Unit
6386 if Nkind_In
(K1
, N_Identifier
, N_Defining_Identifier
)
6388 Nkind_In
(K2
, N_Identifier
, N_Defining_Identifier
)
6390 return Chars
(Name1
) = Chars
(Name2
);
6392 elsif Nkind_In
(K1
, N_Expanded_Name
,
6393 N_Selected_Component
,
6394 N_Defining_Program_Unit_Name
)
6396 Nkind_In
(K2
, N_Expanded_Name
,
6397 N_Selected_Component
,
6398 N_Defining_Program_Unit_Name
)
6401 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
6403 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
6408 end Designate_Same_Unit
;
6410 ---------------------------------------------
6411 -- Diagnose_Iterated_Component_Association --
6412 ---------------------------------------------
6414 procedure Diagnose_Iterated_Component_Association
(N
: Node_Id
) is
6415 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
6419 -- Determine whether the iterated component association appears within
6420 -- an aggregate. If this is the case, raise Program_Error because the
6421 -- iterated component association cannot be left in the tree as is and
6422 -- must always be processed by the related aggregate.
6425 while Present
(Aggr
) loop
6426 if Nkind
(Aggr
) = N_Aggregate
then
6427 raise Program_Error
;
6429 -- Prevent the search from going too far
6431 elsif Is_Body_Or_Package_Declaration
(Aggr
) then
6435 Aggr
:= Parent
(Aggr
);
6438 -- At this point it is known that the iterated component association is
6439 -- not within an aggregate. This is really a quantified expression with
6440 -- a missing "all" or "some" quantifier.
6442 Error_Msg_N
("missing quantifier", Def_Id
);
6444 -- Rewrite the iterated component association as True to prevent any
6447 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
6449 end Diagnose_Iterated_Component_Association
;
6451 ---------------------------------
6452 -- Dynamic_Accessibility_Level --
6453 ---------------------------------
6455 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
6456 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6458 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
6459 -- Construct an integer literal representing an accessibility level
6460 -- with its type set to Natural.
6462 ------------------------
6463 -- Make_Level_Literal --
6464 ------------------------
6466 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
6467 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
6470 Set_Etype
(Result
, Standard_Natural
);
6472 end Make_Level_Literal
;
6478 -- Start of processing for Dynamic_Accessibility_Level
6481 if Is_Entity_Name
(Expr
) then
6484 if Present
(Renamed_Object
(E
)) then
6485 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
6488 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
6489 if Present
(Extra_Accessibility
(E
)) then
6490 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
6495 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6497 case Nkind
(Expr
) is
6499 -- For access discriminant, the level of the enclosing object
6501 when N_Selected_Component
=>
6502 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
6503 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
6504 E_Anonymous_Access_Type
6506 return Make_Level_Literal
(Object_Access_Level
(Expr
));
6509 when N_Attribute_Reference
=>
6510 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
6512 -- For X'Access, the level of the prefix X
6514 when Attribute_Access
=>
6515 return Make_Level_Literal
6516 (Object_Access_Level
(Prefix
(Expr
)));
6518 -- Treat the unchecked attributes as library-level
6520 when Attribute_Unchecked_Access
6521 | Attribute_Unrestricted_Access
6523 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
6525 -- No other access-valued attributes
6528 raise Program_Error
;
6533 -- Unimplemented: depends on context. As an actual parameter where
6534 -- formal type is anonymous, use
6535 -- Scope_Depth (Current_Scope) + 1.
6536 -- For other cases, see 3.10.2(14/3) and following. ???
6540 when N_Type_Conversion
=>
6541 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
6543 -- Handle type conversions introduced for a rename of an
6544 -- Ada 2012 stand-alone object of an anonymous access type.
6546 return Dynamic_Accessibility_Level
(Expression
(Expr
));
6553 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
6554 end Dynamic_Accessibility_Level
;
6556 ------------------------
6557 -- Discriminated_Size --
6558 ------------------------
6560 function Discriminated_Size
(Comp
: Entity_Id
) return Boolean is
6561 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean;
6562 -- Check whether the bound of an index is non-static and does denote
6563 -- a discriminant, in which case any object of the type (protected or
6564 -- otherwise) will have a non-static size.
6566 ----------------------
6567 -- Non_Static_Bound --
6568 ----------------------
6570 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean is
6572 if Is_OK_Static_Expression
(Bound
) then
6575 -- If the bound is given by a discriminant it is non-static
6576 -- (A static constraint replaces the reference with the value).
6577 -- In an protected object the discriminant has been replaced by
6578 -- the corresponding discriminal within the protected operation.
6580 elsif Is_Entity_Name
(Bound
)
6582 (Ekind
(Entity
(Bound
)) = E_Discriminant
6583 or else Present
(Discriminal_Link
(Entity
(Bound
))))
6590 end Non_Static_Bound
;
6594 Typ
: constant Entity_Id
:= Etype
(Comp
);
6597 -- Start of processing for Discriminated_Size
6600 if not Is_Array_Type
(Typ
) then
6604 if Ekind
(Typ
) = E_Array_Subtype
then
6605 Index
:= First_Index
(Typ
);
6606 while Present
(Index
) loop
6607 if Non_Static_Bound
(Low_Bound
(Index
))
6608 or else Non_Static_Bound
(High_Bound
(Index
))
6620 end Discriminated_Size
;
6622 -----------------------------------
6623 -- Effective_Extra_Accessibility --
6624 -----------------------------------
6626 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
6628 if Present
(Renamed_Object
(Id
))
6629 and then Is_Entity_Name
(Renamed_Object
(Id
))
6631 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
6633 return Extra_Accessibility
(Id
);
6635 end Effective_Extra_Accessibility
;
6637 -----------------------------
6638 -- Effective_Reads_Enabled --
6639 -----------------------------
6641 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
6643 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
6644 end Effective_Reads_Enabled
;
6646 ------------------------------
6647 -- Effective_Writes_Enabled --
6648 ------------------------------
6650 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
6652 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
6653 end Effective_Writes_Enabled
;
6655 ------------------------------
6656 -- Enclosing_Comp_Unit_Node --
6657 ------------------------------
6659 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
6660 Current_Node
: Node_Id
;
6664 while Present
(Current_Node
)
6665 and then Nkind
(Current_Node
) /= N_Compilation_Unit
6667 Current_Node
:= Parent
(Current_Node
);
6670 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
6673 return Current_Node
;
6675 end Enclosing_Comp_Unit_Node
;
6677 --------------------------
6678 -- Enclosing_CPP_Parent --
6679 --------------------------
6681 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
6682 Parent_Typ
: Entity_Id
:= Typ
;
6685 while not Is_CPP_Class
(Parent_Typ
)
6686 and then Etype
(Parent_Typ
) /= Parent_Typ
6688 Parent_Typ
:= Etype
(Parent_Typ
);
6690 if Is_Private_Type
(Parent_Typ
) then
6691 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6695 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
6697 end Enclosing_CPP_Parent
;
6699 ---------------------------
6700 -- Enclosing_Declaration --
6701 ---------------------------
6703 function Enclosing_Declaration
(N
: Node_Id
) return Node_Id
is
6704 Decl
: Node_Id
:= N
;
6707 while Present
(Decl
)
6708 and then not (Nkind
(Decl
) in N_Declaration
6710 Nkind
(Decl
) in N_Later_Decl_Item
6712 Nkind
(Decl
) = N_Number_Declaration
)
6714 Decl
:= Parent
(Decl
);
6718 end Enclosing_Declaration
;
6720 ----------------------------
6721 -- Enclosing_Generic_Body --
6722 ----------------------------
6724 function Enclosing_Generic_Body
6725 (N
: Node_Id
) return Node_Id
6733 while Present
(P
) loop
6734 if Nkind
(P
) = N_Package_Body
6735 or else Nkind
(P
) = N_Subprogram_Body
6737 Spec
:= Corresponding_Spec
(P
);
6739 if Present
(Spec
) then
6740 Decl
:= Unit_Declaration_Node
(Spec
);
6742 if Nkind
(Decl
) = N_Generic_Package_Declaration
6743 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
6754 end Enclosing_Generic_Body
;
6756 ----------------------------
6757 -- Enclosing_Generic_Unit --
6758 ----------------------------
6760 function Enclosing_Generic_Unit
6761 (N
: Node_Id
) return Node_Id
6769 while Present
(P
) loop
6770 if Nkind
(P
) = N_Generic_Package_Declaration
6771 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
6775 elsif Nkind
(P
) = N_Package_Body
6776 or else Nkind
(P
) = N_Subprogram_Body
6778 Spec
:= Corresponding_Spec
(P
);
6780 if Present
(Spec
) then
6781 Decl
:= Unit_Declaration_Node
(Spec
);
6783 if Nkind
(Decl
) = N_Generic_Package_Declaration
6784 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
6795 end Enclosing_Generic_Unit
;
6797 -------------------------------
6798 -- Enclosing_Lib_Unit_Entity --
6799 -------------------------------
6801 function Enclosing_Lib_Unit_Entity
6802 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
6804 Unit_Entity
: Entity_Id
;
6807 -- Look for enclosing library unit entity by following scope links.
6808 -- Equivalent to, but faster than indexing through the scope stack.
6811 while (Present
(Scope
(Unit_Entity
))
6812 and then Scope
(Unit_Entity
) /= Standard_Standard
)
6813 and not Is_Child_Unit
(Unit_Entity
)
6815 Unit_Entity
:= Scope
(Unit_Entity
);
6819 end Enclosing_Lib_Unit_Entity
;
6821 -----------------------------
6822 -- Enclosing_Lib_Unit_Node --
6823 -----------------------------
6825 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
6826 Encl_Unit
: Node_Id
;
6829 Encl_Unit
:= Enclosing_Comp_Unit_Node
(N
);
6830 while Present
(Encl_Unit
)
6831 and then Nkind
(Unit
(Encl_Unit
)) = N_Subunit
6833 Encl_Unit
:= Library_Unit
(Encl_Unit
);
6836 pragma Assert
(Nkind
(Encl_Unit
) = N_Compilation_Unit
);
6838 end Enclosing_Lib_Unit_Node
;
6840 -----------------------
6841 -- Enclosing_Package --
6842 -----------------------
6844 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
6845 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
6848 if Dynamic_Scope
= Standard_Standard
then
6849 return Standard_Standard
;
6851 elsif Dynamic_Scope
= Empty
then
6854 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
6857 return Dynamic_Scope
;
6860 return Enclosing_Package
(Dynamic_Scope
);
6862 end Enclosing_Package
;
6864 -------------------------------------
6865 -- Enclosing_Package_Or_Subprogram --
6866 -------------------------------------
6868 function Enclosing_Package_Or_Subprogram
(E
: Entity_Id
) return Entity_Id
is
6873 while Present
(S
) loop
6874 if Is_Package_Or_Generic_Package
(S
)
6875 or else Ekind
(S
) = E_Package_Body
6879 elsif Is_Subprogram_Or_Generic_Subprogram
(S
)
6880 or else Ekind
(S
) = E_Subprogram_Body
6890 end Enclosing_Package_Or_Subprogram
;
6892 --------------------------
6893 -- Enclosing_Subprogram --
6894 --------------------------
6896 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
6897 Dyn_Scop
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
6900 if Dyn_Scop
= Standard_Standard
then
6903 elsif Dyn_Scop
= Empty
then
6906 elsif Ekind
(Dyn_Scop
) = E_Subprogram_Body
then
6907 return Corresponding_Spec
(Parent
(Parent
(Dyn_Scop
)));
6909 elsif Ekind_In
(Dyn_Scop
, E_Block
, E_Return_Statement
) then
6910 return Enclosing_Subprogram
(Dyn_Scop
);
6912 elsif Ekind
(Dyn_Scop
) = E_Entry
then
6914 -- For a task entry, return the enclosing subprogram of the
6917 if Ekind
(Scope
(Dyn_Scop
)) = E_Task_Type
then
6918 return Enclosing_Subprogram
(Dyn_Scop
);
6920 -- A protected entry is rewritten as a protected procedure which is
6921 -- the desired enclosing subprogram. This is relevant when unnesting
6922 -- a procedure local to an entry body.
6925 return Protected_Body_Subprogram
(Dyn_Scop
);
6928 elsif Ekind
(Dyn_Scop
) = E_Task_Type
then
6929 return Get_Task_Body_Procedure
(Dyn_Scop
);
6931 -- The scope may appear as a private type or as a private extension
6932 -- whose completion is a task or protected type.
6934 elsif Ekind_In
(Dyn_Scop
, E_Limited_Private_Type
,
6935 E_Record_Type_With_Private
)
6936 and then Present
(Full_View
(Dyn_Scop
))
6937 and then Ekind_In
(Full_View
(Dyn_Scop
), E_Task_Type
, E_Protected_Type
)
6939 return Get_Task_Body_Procedure
(Full_View
(Dyn_Scop
));
6941 -- No body is generated if the protected operation is eliminated
6943 elsif Convention
(Dyn_Scop
) = Convention_Protected
6944 and then not Is_Eliminated
(Dyn_Scop
)
6945 and then Present
(Protected_Body_Subprogram
(Dyn_Scop
))
6947 return Protected_Body_Subprogram
(Dyn_Scop
);
6952 end Enclosing_Subprogram
;
6954 --------------------------
6955 -- End_Keyword_Location --
6956 --------------------------
6958 function End_Keyword_Location
(N
: Node_Id
) return Source_Ptr
is
6959 function End_Label_Loc
(Nod
: Node_Id
) return Source_Ptr
;
6960 -- Return the source location of Nod's end label according to the
6961 -- following precedence rules:
6963 -- 1) If the end label exists, return its location
6964 -- 2) If Nod exists, return its location
6965 -- 3) Return the location of N
6971 function End_Label_Loc
(Nod
: Node_Id
) return Source_Ptr
is
6975 if Present
(Nod
) then
6976 Label
:= End_Label
(Nod
);
6978 if Present
(Label
) then
6979 return Sloc
(Label
);
6993 -- Start of processing for End_Keyword_Location
6996 if Nkind_In
(N
, N_Block_Statement
,
7002 Owner
:= Handled_Statement_Sequence
(N
);
7004 elsif Nkind
(N
) = N_Package_Declaration
then
7005 Owner
:= Specification
(N
);
7007 elsif Nkind
(N
) = N_Protected_Body
then
7010 elsif Nkind_In
(N
, N_Protected_Type_Declaration
,
7011 N_Single_Protected_Declaration
)
7013 Owner
:= Protected_Definition
(N
);
7015 elsif Nkind_In
(N
, N_Single_Task_Declaration
,
7016 N_Task_Type_Declaration
)
7018 Owner
:= Task_Definition
(N
);
7020 -- This routine should not be called with other contexts
7023 pragma Assert
(False);
7027 return End_Label_Loc
(Owner
);
7028 end End_Keyword_Location
;
7030 ------------------------
7031 -- Ensure_Freeze_Node --
7032 ------------------------
7034 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
7037 if No
(Freeze_Node
(E
)) then
7038 FN
:= Make_Freeze_Entity
(Sloc
(E
));
7039 Set_Has_Delayed_Freeze
(E
);
7040 Set_Freeze_Node
(E
, FN
);
7041 Set_Access_Types_To_Process
(FN
, No_Elist
);
7042 Set_TSS_Elist
(FN
, No_Elist
);
7045 end Ensure_Freeze_Node
;
7051 procedure Enter_Name
(Def_Id
: Entity_Id
) is
7052 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
7053 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
7054 S
: constant Entity_Id
:= Current_Scope
;
7057 Generate_Definition
(Def_Id
);
7059 -- Add new name to current scope declarations. Check for duplicate
7060 -- declaration, which may or may not be a genuine error.
7064 -- Case of previous entity entered because of a missing declaration
7065 -- or else a bad subtype indication. Best is to use the new entity,
7066 -- and make the previous one invisible.
7068 if Etype
(E
) = Any_Type
then
7069 Set_Is_Immediately_Visible
(E
, False);
7071 -- Case of renaming declaration constructed for package instances.
7072 -- if there is an explicit declaration with the same identifier,
7073 -- the renaming is not immediately visible any longer, but remains
7074 -- visible through selected component notation.
7076 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
7077 and then not Comes_From_Source
(E
)
7079 Set_Is_Immediately_Visible
(E
, False);
7081 -- The new entity may be the package renaming, which has the same
7082 -- same name as a generic formal which has been seen already.
7084 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
7085 and then not Comes_From_Source
(Def_Id
)
7087 Set_Is_Immediately_Visible
(E
, False);
7089 -- For a fat pointer corresponding to a remote access to subprogram,
7090 -- we use the same identifier as the RAS type, so that the proper
7091 -- name appears in the stub. This type is only retrieved through
7092 -- the RAS type and never by visibility, and is not added to the
7093 -- visibility list (see below).
7095 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
7096 and then Ekind
(Def_Id
) = E_Record_Type
7097 and then Present
(Corresponding_Remote_Type
(Def_Id
))
7101 -- Case of an implicit operation or derived literal. The new entity
7102 -- hides the implicit one, which is removed from all visibility,
7103 -- i.e. the entity list of its scope, and homonym chain of its name.
7105 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
7106 or else Is_Internal
(E
)
7109 Decl
: constant Node_Id
:= Parent
(E
);
7111 Prev_Vis
: Entity_Id
;
7114 -- If E is an implicit declaration, it cannot be the first
7115 -- entity in the scope.
7117 Prev
:= First_Entity
(Current_Scope
);
7118 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
7124 -- If E is not on the entity chain of the current scope,
7125 -- it is an implicit declaration in the generic formal
7126 -- part of a generic subprogram. When analyzing the body,
7127 -- the generic formals are visible but not on the entity
7128 -- chain of the subprogram. The new entity will become
7129 -- the visible one in the body.
7132 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
7136 Link_Entities
(Prev
, Next_Entity
(E
));
7138 if No
(Next_Entity
(Prev
)) then
7139 Set_Last_Entity
(Current_Scope
, Prev
);
7142 if E
= Current_Entity
(E
) then
7146 Prev_Vis
:= Current_Entity
(E
);
7147 while Homonym
(Prev_Vis
) /= E
loop
7148 Prev_Vis
:= Homonym
(Prev_Vis
);
7152 if Present
(Prev_Vis
) then
7154 -- Skip E in the visibility chain
7156 Set_Homonym
(Prev_Vis
, Homonym
(E
));
7159 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
7164 -- This section of code could use a comment ???
7166 elsif Present
(Etype
(E
))
7167 and then Is_Concurrent_Type
(Etype
(E
))
7172 -- If the homograph is a protected component renaming, it should not
7173 -- be hiding the current entity. Such renamings are treated as weak
7176 elsif Is_Prival
(E
) then
7177 Set_Is_Immediately_Visible
(E
, False);
7179 -- In this case the current entity is a protected component renaming.
7180 -- Perform minimal decoration by setting the scope and return since
7181 -- the prival should not be hiding other visible entities.
7183 elsif Is_Prival
(Def_Id
) then
7184 Set_Scope
(Def_Id
, Current_Scope
);
7187 -- Analogous to privals, the discriminal generated for an entry index
7188 -- parameter acts as a weak declaration. Perform minimal decoration
7189 -- to avoid bogus errors.
7191 elsif Is_Discriminal
(Def_Id
)
7192 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
7194 Set_Scope
(Def_Id
, Current_Scope
);
7197 -- In the body or private part of an instance, a type extension may
7198 -- introduce a component with the same name as that of an actual. The
7199 -- legality rule is not enforced, but the semantics of the full type
7200 -- with two components of same name are not clear at this point???
7202 elsif In_Instance_Not_Visible
then
7205 -- When compiling a package body, some child units may have become
7206 -- visible. They cannot conflict with local entities that hide them.
7208 elsif Is_Child_Unit
(E
)
7209 and then In_Open_Scopes
(Scope
(E
))
7210 and then not Is_Immediately_Visible
(E
)
7214 -- Conversely, with front-end inlining we may compile the parent body
7215 -- first, and a child unit subsequently. The context is now the
7216 -- parent spec, and body entities are not visible.
7218 elsif Is_Child_Unit
(Def_Id
)
7219 and then Is_Package_Body_Entity
(E
)
7220 and then not In_Package_Body
(Current_Scope
)
7224 -- Case of genuine duplicate declaration
7227 Error_Msg_Sloc
:= Sloc
(E
);
7229 -- If the previous declaration is an incomplete type declaration
7230 -- this may be an attempt to complete it with a private type. The
7231 -- following avoids confusing cascaded errors.
7233 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
7234 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
7237 ("incomplete type cannot be completed with a private " &
7238 "declaration", Parent
(Def_Id
));
7239 Set_Is_Immediately_Visible
(E
, False);
7240 Set_Full_View
(E
, Def_Id
);
7242 -- An inherited component of a record conflicts with a new
7243 -- discriminant. The discriminant is inserted first in the scope,
7244 -- but the error should be posted on it, not on the component.
7246 elsif Ekind
(E
) = E_Discriminant
7247 and then Present
(Scope
(Def_Id
))
7248 and then Scope
(Def_Id
) /= Current_Scope
7250 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7251 Error_Msg_N
("& conflicts with declaration#", E
);
7254 -- If the name of the unit appears in its own context clause, a
7255 -- dummy package with the name has already been created, and the
7256 -- error emitted. Try to continue quietly.
7258 elsif Error_Posted
(E
)
7259 and then Sloc
(E
) = No_Location
7260 and then Nkind
(Parent
(E
)) = N_Package_Specification
7261 and then Current_Scope
= Standard_Standard
7263 Set_Scope
(Def_Id
, Current_Scope
);
7267 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
7269 -- Avoid cascaded messages with duplicate components in
7272 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
7277 if Nkind
(Parent
(Parent
(Def_Id
))) =
7278 N_Generic_Subprogram_Declaration
7280 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
7282 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
7285 -- If entity is in standard, then we are in trouble, because it
7286 -- means that we have a library package with a duplicated name.
7287 -- That's hard to recover from, so abort.
7289 if S
= Standard_Standard
then
7290 raise Unrecoverable_Error
;
7292 -- Otherwise we continue with the declaration. Having two
7293 -- identical declarations should not cause us too much trouble.
7301 -- If we fall through, declaration is OK, at least OK enough to continue
7303 -- If Def_Id is a discriminant or a record component we are in the midst
7304 -- of inheriting components in a derived record definition. Preserve
7305 -- their Ekind and Etype.
7307 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
7310 -- If a type is already set, leave it alone (happens when a type
7311 -- declaration is reanalyzed following a call to the optimizer).
7313 elsif Present
(Etype
(Def_Id
)) then
7316 -- Otherwise, the kind E_Void insures that premature uses of the entity
7317 -- will be detected. Any_Type insures that no cascaded errors will occur
7320 Set_Ekind
(Def_Id
, E_Void
);
7321 Set_Etype
(Def_Id
, Any_Type
);
7324 -- Inherited discriminants and components in derived record types are
7325 -- immediately visible. Itypes are not.
7327 -- Unless the Itype is for a record type with a corresponding remote
7328 -- type (what is that about, it was not commented ???)
7330 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
7332 ((not Is_Record_Type
(Def_Id
)
7333 or else No
(Corresponding_Remote_Type
(Def_Id
)))
7334 and then not Is_Itype
(Def_Id
))
7336 Set_Is_Immediately_Visible
(Def_Id
);
7337 Set_Current_Entity
(Def_Id
);
7340 Set_Homonym
(Def_Id
, C
);
7341 Append_Entity
(Def_Id
, S
);
7342 Set_Public_Status
(Def_Id
);
7344 -- Declaring a homonym is not allowed in SPARK ...
7346 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
7348 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
7349 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
7350 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
7353 -- ... unless the new declaration is in a subprogram, and the
7354 -- visible declaration is a variable declaration or a parameter
7355 -- specification outside that subprogram.
7357 if Present
(Enclosing_Subp
)
7358 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
7359 N_Parameter_Specification
)
7360 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
7364 -- ... or the new declaration is in a package, and the visible
7365 -- declaration occurs outside that package.
7367 elsif Present
(Enclosing_Pack
)
7368 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
7372 -- ... or the new declaration is a component declaration in a
7373 -- record type definition.
7375 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
7378 -- Don't issue error for non-source entities
7380 elsif Comes_From_Source
(Def_Id
)
7381 and then Comes_From_Source
(C
)
7383 Error_Msg_Sloc
:= Sloc
(C
);
7384 Check_SPARK_05_Restriction
7385 ("redeclaration of identifier &#", Def_Id
);
7390 -- Warn if new entity hides an old one
7392 if Warn_On_Hiding
and then Present
(C
)
7394 -- Don't warn for record components since they always have a well
7395 -- defined scope which does not confuse other uses. Note that in
7396 -- some cases, Ekind has not been set yet.
7398 and then Ekind
(C
) /= E_Component
7399 and then Ekind
(C
) /= E_Discriminant
7400 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
7401 and then Ekind
(Def_Id
) /= E_Component
7402 and then Ekind
(Def_Id
) /= E_Discriminant
7403 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
7405 -- Don't warn for one character variables. It is too common to use
7406 -- such variables as locals and will just cause too many false hits.
7408 and then Length_Of_Name
(Chars
(C
)) /= 1
7410 -- Don't warn for non-source entities
7412 and then Comes_From_Source
(C
)
7413 and then Comes_From_Source
(Def_Id
)
7415 -- Don't warn unless entity in question is in extended main source
7417 and then In_Extended_Main_Source_Unit
(Def_Id
)
7419 -- Finally, the hidden entity must be either immediately visible or
7420 -- use visible (i.e. from a used package).
7423 (Is_Immediately_Visible
(C
)
7425 Is_Potentially_Use_Visible
(C
))
7427 Error_Msg_Sloc
:= Sloc
(C
);
7428 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
7436 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
7441 -- Assume that the arbitrary node does not have an entity
7445 if Is_Entity_Name
(N
) then
7448 -- Follow a possible chain of renamings to reach the earliest renamed
7452 and then Is_Object
(Id
)
7453 and then Present
(Renamed_Object
(Id
))
7455 Ren
:= Renamed_Object
(Id
);
7457 -- The reference renames an abstract state or a whole object
7460 -- Ren : ... renames Obj;
7462 if Is_Entity_Name
(Ren
) then
7464 -- Do not follow a renaming that goes through a generic formal,
7465 -- because these entities are hidden and must not be referenced
7466 -- from outside the generic.
7468 if Is_Hidden
(Entity
(Ren
)) then
7475 -- The reference renames a function result. Check the original
7476 -- node in case expansion relocates the function call.
7478 -- Ren : ... renames Func_Call;
7480 elsif Nkind
(Original_Node
(Ren
)) = N_Function_Call
then
7483 -- Otherwise the reference renames something which does not yield
7484 -- an abstract state or a whole object. Treat the reference as not
7485 -- having a proper entity for SPARK legality purposes.
7497 --------------------------
7498 -- Examine_Array_Bounds --
7499 --------------------------
7501 procedure Examine_Array_Bounds
7503 All_Static
: out Boolean;
7504 Has_Empty
: out Boolean)
7506 function Is_OK_Static_Bound
(Bound
: Node_Id
) return Boolean;
7507 -- Determine whether bound Bound is a suitable static bound
7509 ------------------------
7510 -- Is_OK_Static_Bound --
7511 ------------------------
7513 function Is_OK_Static_Bound
(Bound
: Node_Id
) return Boolean is
7516 not Error_Posted
(Bound
)
7517 and then Is_OK_Static_Expression
(Bound
);
7518 end Is_OK_Static_Bound
;
7526 -- Start of processing for Examine_Array_Bounds
7529 -- An unconstrained array type does not have static bounds, and it is
7530 -- not known whether they are empty or not.
7532 if not Is_Constrained
(Typ
) then
7533 All_Static
:= False;
7536 -- A string literal has static bounds, and is not empty as long as it
7537 -- contains at least one character.
7539 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
7541 Has_Empty
:= String_Literal_Length
(Typ
) > 0;
7544 -- Assume that all bounds are static and not empty
7549 -- Examine each index
7551 Index
:= First_Index
(Typ
);
7552 while Present
(Index
) loop
7553 if Is_Discrete_Type
(Etype
(Index
)) then
7554 Get_Index_Bounds
(Index
, Lo_Bound
, Hi_Bound
);
7556 if Is_OK_Static_Bound
(Lo_Bound
)
7558 Is_OK_Static_Bound
(Hi_Bound
)
7560 -- The static bounds produce an empty range
7562 if Is_Null_Range
(Lo_Bound
, Hi_Bound
) then
7566 -- Otherwise at least one of the bounds is not static
7569 All_Static
:= False;
7572 -- Otherwise the index is non-discrete, therefore not static
7575 All_Static
:= False;
7580 end Examine_Array_Bounds
;
7582 --------------------------
7583 -- Explain_Limited_Type --
7584 --------------------------
7586 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
7590 -- For array, component type must be limited
7592 if Is_Array_Type
(T
) then
7593 Error_Msg_Node_2
:= T
;
7595 ("\component type& of type& is limited", N
, Component_Type
(T
));
7596 Explain_Limited_Type
(Component_Type
(T
), N
);
7598 elsif Is_Record_Type
(T
) then
7600 -- No need for extra messages if explicit limited record
7602 if Is_Limited_Record
(Base_Type
(T
)) then
7606 -- Otherwise find a limited component. Check only components that
7607 -- come from source, or inherited components that appear in the
7608 -- source of the ancestor.
7610 C
:= First_Component
(T
);
7611 while Present
(C
) loop
7612 if Is_Limited_Type
(Etype
(C
))
7614 (Comes_From_Source
(C
)
7616 (Present
(Original_Record_Component
(C
))
7618 Comes_From_Source
(Original_Record_Component
(C
))))
7620 Error_Msg_Node_2
:= T
;
7621 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
7622 Explain_Limited_Type
(Etype
(C
), N
);
7629 -- The type may be declared explicitly limited, even if no component
7630 -- of it is limited, in which case we fall out of the loop.
7633 end Explain_Limited_Type
;
7635 ---------------------------------------
7636 -- Expression_Of_Expression_Function --
7637 ---------------------------------------
7639 function Expression_Of_Expression_Function
7640 (Subp
: Entity_Id
) return Node_Id
7642 Expr_Func
: Node_Id
;
7645 pragma Assert
(Is_Expression_Function_Or_Completion
(Subp
));
7647 if Nkind
(Original_Node
(Subprogram_Spec
(Subp
))) =
7648 N_Expression_Function
7650 Expr_Func
:= Original_Node
(Subprogram_Spec
(Subp
));
7652 elsif Nkind
(Original_Node
(Subprogram_Body
(Subp
))) =
7653 N_Expression_Function
7655 Expr_Func
:= Original_Node
(Subprogram_Body
(Subp
));
7658 pragma Assert
(False);
7662 return Original_Node
(Expression
(Expr_Func
));
7663 end Expression_Of_Expression_Function
;
7665 -------------------------------
7666 -- Extensions_Visible_Status --
7667 -------------------------------
7669 function Extensions_Visible_Status
7670 (Id
: Entity_Id
) return Extensions_Visible_Mode
7679 -- When a formal parameter is subject to Extensions_Visible, the pragma
7680 -- is stored in the contract of related subprogram.
7682 if Is_Formal
(Id
) then
7685 elsif Is_Subprogram_Or_Generic_Subprogram
(Id
) then
7688 -- No other construct carries this pragma
7691 return Extensions_Visible_None
;
7694 Prag
:= Get_Pragma
(Subp
, Pragma_Extensions_Visible
);
7696 -- In certain cases analysis may request the Extensions_Visible status
7697 -- of an expression function before the pragma has been analyzed yet.
7698 -- Inspect the declarative items after the expression function looking
7699 -- for the pragma (if any).
7701 if No
(Prag
) and then Is_Expression_Function
(Subp
) then
7702 Decl
:= Next
(Unit_Declaration_Node
(Subp
));
7703 while Present
(Decl
) loop
7704 if Nkind
(Decl
) = N_Pragma
7705 and then Pragma_Name
(Decl
) = Name_Extensions_Visible
7710 -- A source construct ends the region where Extensions_Visible may
7711 -- appear, stop the traversal. An expanded expression function is
7712 -- no longer a source construct, but it must still be recognized.
7714 elsif Comes_From_Source
(Decl
)
7716 (Nkind_In
(Decl
, N_Subprogram_Body
,
7717 N_Subprogram_Declaration
)
7718 and then Is_Expression_Function
(Defining_Entity
(Decl
)))
7727 -- Extract the value from the Boolean expression (if any)
7729 if Present
(Prag
) then
7730 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
7732 if Present
(Arg
) then
7733 Expr
:= Get_Pragma_Arg
(Arg
);
7735 -- When the associated subprogram is an expression function, the
7736 -- argument of the pragma may not have been analyzed.
7738 if not Analyzed
(Expr
) then
7739 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
7742 -- Guard against cascading errors when the argument of pragma
7743 -- Extensions_Visible is not a valid static Boolean expression.
7745 if Error_Posted
(Expr
) then
7746 return Extensions_Visible_None
;
7748 elsif Is_True
(Expr_Value
(Expr
)) then
7749 return Extensions_Visible_True
;
7752 return Extensions_Visible_False
;
7755 -- Otherwise the aspect or pragma defaults to True
7758 return Extensions_Visible_True
;
7761 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7762 -- directly specified. In SPARK code, its value defaults to "False".
7764 elsif SPARK_Mode
= On
then
7765 return Extensions_Visible_False
;
7767 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7771 return Extensions_Visible_True
;
7773 end Extensions_Visible_Status
;
7779 procedure Find_Actual
7781 Formal
: out Entity_Id
;
7784 Context
: constant Node_Id
:= Parent
(N
);
7789 if Nkind_In
(Context
, N_Indexed_Component
, N_Selected_Component
)
7790 and then N
= Prefix
(Context
)
7792 Find_Actual
(Context
, Formal
, Call
);
7795 elsif Nkind
(Context
) = N_Parameter_Association
7796 and then N
= Explicit_Actual_Parameter
(Context
)
7798 Call
:= Parent
(Context
);
7800 elsif Nkind_In
(Context
, N_Entry_Call_Statement
,
7802 N_Procedure_Call_Statement
)
7812 -- If we have a call to a subprogram look for the parameter. Note that
7813 -- we exclude overloaded calls, since we don't know enough to be sure
7814 -- of giving the right answer in this case.
7816 if Nkind_In
(Call
, N_Entry_Call_Statement
,
7818 N_Procedure_Call_Statement
)
7820 Call_Nam
:= Name
(Call
);
7822 -- A call to a protected or task entry appears as a selected
7823 -- component rather than an expanded name.
7825 if Nkind
(Call_Nam
) = N_Selected_Component
then
7826 Call_Nam
:= Selector_Name
(Call_Nam
);
7829 if Is_Entity_Name
(Call_Nam
)
7830 and then Present
(Entity
(Call_Nam
))
7831 and then Is_Overloadable
(Entity
(Call_Nam
))
7832 and then not Is_Overloaded
(Call_Nam
)
7834 -- If node is name in call it is not an actual
7836 if N
= Call_Nam
then
7842 -- Fall here if we are definitely a parameter
7844 Actual
:= First_Actual
(Call
);
7845 Formal
:= First_Formal
(Entity
(Call_Nam
));
7846 while Present
(Formal
) and then Present
(Actual
) loop
7850 -- An actual that is the prefix in a prefixed call may have
7851 -- been rewritten in the call, after the deferred reference
7852 -- was collected. Check if sloc and kinds and names match.
7854 elsif Sloc
(Actual
) = Sloc
(N
)
7855 and then Nkind
(Actual
) = N_Identifier
7856 and then Nkind
(Actual
) = Nkind
(N
)
7857 and then Chars
(Actual
) = Chars
(N
)
7862 Actual
:= Next_Actual
(Actual
);
7863 Formal
:= Next_Formal
(Formal
);
7869 -- Fall through here if we did not find matching actual
7875 ---------------------------
7876 -- Find_Body_Discriminal --
7877 ---------------------------
7879 function Find_Body_Discriminal
7880 (Spec_Discriminant
: Entity_Id
) return Entity_Id
7886 -- If expansion is suppressed, then the scope can be the concurrent type
7887 -- itself rather than a corresponding concurrent record type.
7889 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
7890 Tsk
:= Scope
(Spec_Discriminant
);
7893 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
7895 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
7898 -- Find discriminant of original concurrent type, and use its current
7899 -- discriminal, which is the renaming within the task/protected body.
7901 Disc
:= First_Discriminant
(Tsk
);
7902 while Present
(Disc
) loop
7903 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
7904 return Discriminal
(Disc
);
7907 Next_Discriminant
(Disc
);
7910 -- That loop should always succeed in finding a matching entry and
7911 -- returning. Fatal error if not.
7913 raise Program_Error
;
7914 end Find_Body_Discriminal
;
7916 -------------------------------------
7917 -- Find_Corresponding_Discriminant --
7918 -------------------------------------
7920 function Find_Corresponding_Discriminant
7922 Typ
: Entity_Id
) return Entity_Id
7924 Par_Disc
: Entity_Id
;
7925 Old_Disc
: Entity_Id
;
7926 New_Disc
: Entity_Id
;
7929 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
7931 -- The original type may currently be private, and the discriminant
7932 -- only appear on its full view.
7934 if Is_Private_Type
(Scope
(Par_Disc
))
7935 and then not Has_Discriminants
(Scope
(Par_Disc
))
7936 and then Present
(Full_View
(Scope
(Par_Disc
)))
7938 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
7940 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
7943 if Is_Class_Wide_Type
(Typ
) then
7944 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
7946 New_Disc
:= First_Discriminant
(Typ
);
7949 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
7950 if Old_Disc
= Par_Disc
then
7954 Next_Discriminant
(Old_Disc
);
7955 Next_Discriminant
(New_Disc
);
7958 -- Should always find it
7960 raise Program_Error
;
7961 end Find_Corresponding_Discriminant
;
7967 function Find_DIC_Type
(Typ
: Entity_Id
) return Entity_Id
is
7968 Curr_Typ
: Entity_Id
;
7969 -- The current type being examined in the parent hierarchy traversal
7971 DIC_Typ
: Entity_Id
;
7972 -- The type which carries the DIC pragma. This variable denotes the
7973 -- partial view when private types are involved.
7975 Par_Typ
: Entity_Id
;
7976 -- The parent type of the current type. This variable denotes the full
7977 -- view when private types are involved.
7980 -- The input type defines its own DIC pragma, therefore it is the owner
7982 if Has_Own_DIC
(Typ
) then
7985 -- Otherwise the DIC pragma is inherited from a parent type
7988 pragma Assert
(Has_Inherited_DIC
(Typ
));
7990 -- Climb the parent chain
7994 -- Inspect the parent type. Do not consider subtypes as they
7995 -- inherit the DIC attributes from their base types.
7997 DIC_Typ
:= Base_Type
(Etype
(Curr_Typ
));
7999 -- Look at the full view of a private type because the type may
8000 -- have a hidden parent introduced in the full view.
8004 if Is_Private_Type
(Par_Typ
)
8005 and then Present
(Full_View
(Par_Typ
))
8007 Par_Typ
:= Full_View
(Par_Typ
);
8010 -- Stop the climb once the nearest parent type which defines a DIC
8011 -- pragma of its own is encountered or when the root of the parent
8012 -- chain is reached.
8014 exit when Has_Own_DIC
(DIC_Typ
) or else Curr_Typ
= Par_Typ
;
8016 Curr_Typ
:= Par_Typ
;
8023 ----------------------------------
8024 -- Find_Enclosing_Iterator_Loop --
8025 ----------------------------------
8027 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
8032 -- Traverse the scope chain looking for an iterator loop. Such loops are
8033 -- usually transformed into blocks, hence the use of Original_Node.
8036 while Present
(S
) and then S
/= Standard_Standard
loop
8037 if Ekind
(S
) = E_Loop
8038 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
8040 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
8042 if Nkind
(Constr
) = N_Loop_Statement
8043 and then Present
(Iteration_Scheme
(Constr
))
8044 and then Nkind
(Iterator_Specification
8045 (Iteration_Scheme
(Constr
))) =
8046 N_Iterator_Specification
8056 end Find_Enclosing_Iterator_Loop
;
8058 --------------------------
8059 -- Find_Enclosing_Scope --
8060 --------------------------
8062 function Find_Enclosing_Scope
(N
: Node_Id
) return Entity_Id
is
8066 -- Examine the parent chain looking for a construct which defines a
8070 while Present
(Par
) loop
8073 -- The construct denotes a declaration, the proper scope is its
8076 when N_Entry_Declaration
8077 | N_Expression_Function
8078 | N_Full_Type_Declaration
8079 | N_Generic_Package_Declaration
8080 | N_Generic_Subprogram_Declaration
8081 | N_Package_Declaration
8082 | N_Private_Extension_Declaration
8083 | N_Protected_Type_Declaration
8084 | N_Single_Protected_Declaration
8085 | N_Single_Task_Declaration
8086 | N_Subprogram_Declaration
8087 | N_Task_Type_Declaration
8089 return Defining_Entity
(Par
);
8091 -- The construct denotes a body, the proper scope is the entity of
8092 -- the corresponding spec or that of the body if the body does not
8093 -- complete a previous declaration.
8101 return Unique_Defining_Entity
(Par
);
8105 -- Blocks carry either a source or an internally-generated scope,
8106 -- unless the block is a byproduct of exception handling.
8108 when N_Block_Statement
=>
8109 if not Exception_Junk
(Par
) then
8110 return Entity
(Identifier
(Par
));
8113 -- Loops carry an internally-generated scope
8115 when N_Loop_Statement
=>
8116 return Entity
(Identifier
(Par
));
8118 -- Extended return statements carry an internally-generated scope
8120 when N_Extended_Return_Statement
=>
8121 return Return_Statement_Entity
(Par
);
8123 -- A traversal from a subunit continues via the corresponding stub
8126 Par
:= Corresponding_Stub
(Par
);
8132 Par
:= Parent
(Par
);
8135 return Standard_Standard
;
8136 end Find_Enclosing_Scope
;
8138 ------------------------------------
8139 -- Find_Loop_In_Conditional_Block --
8140 ------------------------------------
8142 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
8148 if Nkind
(Stmt
) = N_If_Statement
then
8149 Stmt
:= First
(Then_Statements
(Stmt
));
8152 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
8154 -- Inspect the statements of the conditional block. In general the loop
8155 -- should be the first statement in the statement sequence of the block,
8156 -- but the finalization machinery may have introduced extra object
8159 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
8160 while Present
(Stmt
) loop
8161 if Nkind
(Stmt
) = N_Loop_Statement
then
8168 -- The expansion of attribute 'Loop_Entry produced a malformed block
8170 raise Program_Error
;
8171 end Find_Loop_In_Conditional_Block
;
8173 --------------------------
8174 -- Find_Overlaid_Entity --
8175 --------------------------
8177 procedure Find_Overlaid_Entity
8179 Ent
: out Entity_Id
;
8185 -- We are looking for one of the two following forms:
8187 -- for X'Address use Y'Address
8191 -- Const : constant Address := expr;
8193 -- for X'Address use Const;
8195 -- In the second case, the expr is either Y'Address, or recursively a
8196 -- constant that eventually references Y'Address.
8201 if Nkind
(N
) = N_Attribute_Definition_Clause
8202 and then Chars
(N
) = Name_Address
8204 Expr
:= Expression
(N
);
8206 -- This loop checks the form of the expression for Y'Address,
8207 -- using recursion to deal with intermediate constants.
8210 -- Check for Y'Address
8212 if Nkind
(Expr
) = N_Attribute_Reference
8213 and then Attribute_Name
(Expr
) = Name_Address
8215 Expr
:= Prefix
(Expr
);
8218 -- Check for Const where Const is a constant entity
8220 elsif Is_Entity_Name
(Expr
)
8221 and then Ekind
(Entity
(Expr
)) = E_Constant
8223 Expr
:= Constant_Value
(Entity
(Expr
));
8225 -- Anything else does not need checking
8232 -- This loop checks the form of the prefix for an entity, using
8233 -- recursion to deal with intermediate components.
8236 -- Check for Y where Y is an entity
8238 if Is_Entity_Name
(Expr
) then
8239 Ent
:= Entity
(Expr
);
8242 -- Check for components
8245 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
8247 Expr
:= Prefix
(Expr
);
8250 -- Anything else does not need checking
8257 end Find_Overlaid_Entity
;
8259 -------------------------
8260 -- Find_Parameter_Type --
8261 -------------------------
8263 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
8265 if Nkind
(Param
) /= N_Parameter_Specification
then
8268 -- For an access parameter, obtain the type from the formal entity
8269 -- itself, because access to subprogram nodes do not carry a type.
8270 -- Shouldn't we always use the formal entity ???
8272 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
8273 return Etype
(Defining_Identifier
(Param
));
8276 return Etype
(Parameter_Type
(Param
));
8278 end Find_Parameter_Type
;
8280 -----------------------------------
8281 -- Find_Placement_In_State_Space --
8282 -----------------------------------
8284 procedure Find_Placement_In_State_Space
8285 (Item_Id
: Entity_Id
;
8286 Placement
: out State_Space_Kind
;
8287 Pack_Id
: out Entity_Id
)
8289 Context
: Entity_Id
;
8292 -- Assume that the item does not appear in the state space of a package
8294 Placement
:= Not_In_Package
;
8297 -- Climb the scope stack and examine the enclosing context
8299 Context
:= Scope
(Item_Id
);
8300 while Present
(Context
) and then Context
/= Standard_Standard
loop
8301 if Is_Package_Or_Generic_Package
(Context
) then
8304 -- A package body is a cut off point for the traversal as the item
8305 -- cannot be visible to the outside from this point on. Note that
8306 -- this test must be done first as a body is also classified as a
8309 if In_Package_Body
(Context
) then
8310 Placement
:= Body_State_Space
;
8313 -- The private part of a package is a cut off point for the
8314 -- traversal as the item cannot be visible to the outside from
8317 elsif In_Private_Part
(Context
) then
8318 Placement
:= Private_State_Space
;
8321 -- When the item appears in the visible state space of a package,
8322 -- continue to climb the scope stack as this may not be the final
8326 Placement
:= Visible_State_Space
;
8328 -- The visible state space of a child unit acts as the proper
8329 -- placement of an item.
8331 if Is_Child_Unit
(Context
) then
8336 -- The item or its enclosing package appear in a construct that has
8340 Placement
:= Not_In_Package
;
8344 Context
:= Scope
(Context
);
8346 end Find_Placement_In_State_Space
;
8348 -----------------------
8349 -- Find_Primitive_Eq --
8350 -----------------------
8352 function Find_Primitive_Eq
(Typ
: Entity_Id
) return Entity_Id
is
8353 function Find_Eq_Prim
(Prims_List
: Elist_Id
) return Entity_Id
;
8354 -- Search for the equality primitive; return Empty if the primitive is
8361 function Find_Eq_Prim
(Prims_List
: Elist_Id
) return Entity_Id
is
8363 Prim_Elmt
: Elmt_Id
;
8366 Prim_Elmt
:= First_Elmt
(Prims_List
);
8367 while Present
(Prim_Elmt
) loop
8368 Prim
:= Node
(Prim_Elmt
);
8370 -- Locate primitive equality with the right signature
8372 if Chars
(Prim
) = Name_Op_Eq
8373 and then Etype
(First_Formal
(Prim
)) =
8374 Etype
(Next_Formal
(First_Formal
(Prim
)))
8375 and then Base_Type
(Etype
(Prim
)) = Standard_Boolean
8380 Next_Elmt
(Prim_Elmt
);
8388 Eq_Prim
: Entity_Id
;
8389 Full_Type
: Entity_Id
;
8391 -- Start of processing for Find_Primitive_Eq
8394 if Is_Private_Type
(Typ
) then
8395 Full_Type
:= Underlying_Type
(Typ
);
8400 if No
(Full_Type
) then
8404 Full_Type
:= Base_Type
(Full_Type
);
8406 -- When the base type itself is private, use the full view
8408 if Is_Private_Type
(Full_Type
) then
8409 Full_Type
:= Underlying_Type
(Full_Type
);
8412 if Is_Class_Wide_Type
(Full_Type
) then
8413 Full_Type
:= Root_Type
(Full_Type
);
8416 if not Is_Tagged_Type
(Full_Type
) then
8417 Eq_Prim
:= Find_Eq_Prim
(Collect_Primitive_Operations
(Typ
));
8419 -- If this is an untagged private type completed with a derivation of
8420 -- an untagged private type whose full view is a tagged type, we use
8421 -- the primitive operations of the private parent type (since it does
8422 -- not have a full view, and also because its equality primitive may
8423 -- have been overridden in its untagged full view). If no equality was
8424 -- defined for it then take its dispatching equality primitive.
8426 elsif Inherits_From_Tagged_Full_View
(Typ
) then
8427 Eq_Prim
:= Find_Eq_Prim
(Collect_Primitive_Operations
(Typ
));
8429 if No
(Eq_Prim
) then
8430 Eq_Prim
:= Find_Eq_Prim
(Primitive_Operations
(Full_Type
));
8434 Eq_Prim
:= Find_Eq_Prim
(Primitive_Operations
(Full_Type
));
8438 end Find_Primitive_Eq
;
8440 ------------------------
8441 -- Find_Specific_Type --
8442 ------------------------
8444 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
8445 Typ
: Entity_Id
:= Root_Type
(CW
);
8448 if Ekind
(Typ
) = E_Incomplete_Type
then
8449 if From_Limited_With
(Typ
) then
8450 Typ
:= Non_Limited_View
(Typ
);
8452 Typ
:= Full_View
(Typ
);
8456 if Is_Private_Type
(Typ
)
8457 and then not Is_Tagged_Type
(Typ
)
8458 and then Present
(Full_View
(Typ
))
8460 return Full_View
(Typ
);
8464 end Find_Specific_Type
;
8466 -----------------------------
8467 -- Find_Static_Alternative --
8468 -----------------------------
8470 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
8471 Expr
: constant Node_Id
:= Expression
(N
);
8472 Val
: constant Uint
:= Expr_Value
(Expr
);
8477 Alt
:= First
(Alternatives
(N
));
8480 if Nkind
(Alt
) /= N_Pragma
then
8481 Choice
:= First
(Discrete_Choices
(Alt
));
8482 while Present
(Choice
) loop
8484 -- Others choice, always matches
8486 if Nkind
(Choice
) = N_Others_Choice
then
8489 -- Range, check if value is in the range
8491 elsif Nkind
(Choice
) = N_Range
then
8493 Val
>= Expr_Value
(Low_Bound
(Choice
))
8495 Val
<= Expr_Value
(High_Bound
(Choice
));
8497 -- Choice is a subtype name. Note that we know it must
8498 -- be a static subtype, since otherwise it would have
8499 -- been diagnosed as illegal.
8501 elsif Is_Entity_Name
(Choice
)
8502 and then Is_Type
(Entity
(Choice
))
8504 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
8505 Assume_Valid
=> False);
8507 -- Choice is a subtype indication
8509 elsif Nkind
(Choice
) = N_Subtype_Indication
then
8511 C
: constant Node_Id
:= Constraint
(Choice
);
8512 R
: constant Node_Id
:= Range_Expression
(C
);
8516 Val
>= Expr_Value
(Low_Bound
(R
))
8518 Val
<= Expr_Value
(High_Bound
(R
));
8521 -- Choice is a simple expression
8524 exit Search
when Val
= Expr_Value
(Choice
);
8532 pragma Assert
(Present
(Alt
));
8535 -- The above loop *must* terminate by finding a match, since we know the
8536 -- case statement is valid, and the value of the expression is known at
8537 -- compile time. When we fall out of the loop, Alt points to the
8538 -- alternative that we know will be selected at run time.
8541 end Find_Static_Alternative
;
8547 function First_Actual
(Node
: Node_Id
) return Node_Id
is
8551 if No
(Parameter_Associations
(Node
)) then
8555 N
:= First
(Parameter_Associations
(Node
));
8557 if Nkind
(N
) = N_Parameter_Association
then
8558 return First_Named_Actual
(Node
);
8568 function First_Global
8570 Global_Mode
: Name_Id
;
8571 Refined
: Boolean := False) return Node_Id
8573 function First_From_Global_List
8575 Global_Mode
: Name_Id
:= Name_Input
) return Entity_Id
;
8576 -- Get the first item with suitable mode from List
8578 ----------------------------
8579 -- First_From_Global_List --
8580 ----------------------------
8582 function First_From_Global_List
8584 Global_Mode
: Name_Id
:= Name_Input
) return Entity_Id
8589 -- Empty list (no global items)
8591 if Nkind
(List
) = N_Null
then
8594 -- Single global item declaration (only input items)
8596 elsif Nkind_In
(List
, N_Expanded_Name
,
8598 N_Selected_Component
)
8600 if Global_Mode
= Name_Input
then
8606 -- Simple global list (only input items) or moded global list
8609 elsif Nkind
(List
) = N_Aggregate
then
8610 if Present
(Expressions
(List
)) then
8611 if Global_Mode
= Name_Input
then
8612 return First
(Expressions
(List
));
8618 Assoc
:= First
(Component_Associations
(List
));
8619 while Present
(Assoc
) loop
8621 -- When we find the desired mode in an association, call
8622 -- recursively First_From_Global_List as if the mode was
8623 -- Name_Input, in order to reuse the existing machinery
8624 -- for the other cases.
8626 if Chars
(First
(Choices
(Assoc
))) = Global_Mode
then
8627 return First_From_Global_List
(Expression
(Assoc
));
8636 -- To accommodate partial decoration of disabled SPARK features,
8637 -- this routine may be called with illegal input. If this is the
8638 -- case, do not raise Program_Error.
8643 end First_From_Global_List
;
8647 Global
: Node_Id
:= Empty
;
8648 Body_Id
: Entity_Id
;
8651 pragma Assert
(Global_Mode
= Name_Input
8652 or else Global_Mode
= Name_Output
8653 or else Global_Mode
= Name_In_Out
8654 or else Global_Mode
= Name_Proof_In
);
8656 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8657 -- case, it can only be located on the body entity.
8660 Body_Id
:= Subprogram_Body_Entity
(Subp
);
8661 if Present
(Body_Id
) then
8662 Global
:= Get_Pragma
(Body_Id
, Pragma_Refined_Global
);
8665 Global
:= Get_Pragma
(Subp
, Pragma_Global
);
8668 -- No corresponding global if pragma is not present
8673 -- Otherwise retrieve the corresponding list of items depending on the
8677 return First_From_Global_List
8678 (Expression
(Get_Argument
(Global
, Subp
)), Global_Mode
);
8686 function Fix_Msg
(Id
: Entity_Id
; Msg
: String) return String is
8687 Is_Task
: constant Boolean :=
8688 Ekind_In
(Id
, E_Task_Body
, E_Task_Type
)
8689 or else Is_Single_Task_Object
(Id
);
8690 Msg_Last
: constant Natural := Msg
'Last;
8691 Msg_Index
: Natural;
8692 Res
: String (Msg
'Range) := (others => ' ');
8693 Res_Index
: Natural;
8696 -- Copy all characters from the input message Msg to result Res with
8697 -- suitable replacements.
8699 Msg_Index
:= Msg
'First;
8700 Res_Index
:= Res
'First;
8701 while Msg_Index
<= Msg_Last
loop
8703 -- Replace "subprogram" with a different word
8705 if Msg_Index
<= Msg_Last
- 10
8706 and then Msg
(Msg_Index
.. Msg_Index
+ 9) = "subprogram"
8708 if Ekind_In
(Id
, E_Entry
, E_Entry_Family
) then
8709 Res
(Res_Index
.. Res_Index
+ 4) := "entry";
8710 Res_Index
:= Res_Index
+ 5;
8713 Res
(Res_Index
.. Res_Index
+ 8) := "task type";
8714 Res_Index
:= Res_Index
+ 9;
8717 Res
(Res_Index
.. Res_Index
+ 9) := "subprogram";
8718 Res_Index
:= Res_Index
+ 10;
8721 Msg_Index
:= Msg_Index
+ 10;
8723 -- Replace "protected" with a different word
8725 elsif Msg_Index
<= Msg_Last
- 9
8726 and then Msg
(Msg_Index
.. Msg_Index
+ 8) = "protected"
8729 Res
(Res_Index
.. Res_Index
+ 3) := "task";
8730 Res_Index
:= Res_Index
+ 4;
8731 Msg_Index
:= Msg_Index
+ 9;
8733 -- Otherwise copy the character
8736 Res
(Res_Index
) := Msg
(Msg_Index
);
8737 Msg_Index
:= Msg_Index
+ 1;
8738 Res_Index
:= Res_Index
+ 1;
8742 return Res
(Res
'First .. Res_Index
- 1);
8745 -------------------------
8746 -- From_Nested_Package --
8747 -------------------------
8749 function From_Nested_Package
(T
: Entity_Id
) return Boolean is
8750 Pack
: constant Entity_Id
:= Scope
(T
);
8754 Ekind
(Pack
) = E_Package
8755 and then not Is_Frozen
(Pack
)
8756 and then not Scope_Within_Or_Same
(Current_Scope
, Pack
)
8757 and then In_Open_Scopes
(Scope
(Pack
));
8758 end From_Nested_Package
;
8760 -----------------------
8761 -- Gather_Components --
8762 -----------------------
8764 procedure Gather_Components
8766 Comp_List
: Node_Id
;
8767 Governed_By
: List_Id
;
8769 Report_Errors
: out Boolean)
8773 Discrete_Choice
: Node_Id
;
8774 Comp_Item
: Node_Id
;
8776 Discrim
: Entity_Id
;
8777 Discrim_Name
: Node_Id
;
8778 Discrim_Value
: Node_Id
;
8781 Report_Errors
:= False;
8783 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
8786 elsif Present
(Component_Items
(Comp_List
)) then
8787 Comp_Item
:= First
(Component_Items
(Comp_List
));
8793 while Present
(Comp_Item
) loop
8795 -- Skip the tag of a tagged record, the interface tags, as well
8796 -- as all items that are not user components (anonymous types,
8797 -- rep clauses, Parent field, controller field).
8799 if Nkind
(Comp_Item
) = N_Component_Declaration
then
8801 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
8803 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
8804 Append_Elmt
(Comp
, Into
);
8812 if No
(Variant_Part
(Comp_List
)) then
8815 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
8816 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
8819 -- Look for the discriminant that governs this variant part.
8820 -- The discriminant *must* be in the Governed_By List
8822 Assoc
:= First
(Governed_By
);
8823 Find_Constraint
: loop
8824 Discrim
:= First
(Choices
(Assoc
));
8825 exit Find_Constraint
when
8826 Chars
(Discrim_Name
) = Chars
(Discrim
)
8828 (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
8829 and then Chars
(Corresponding_Discriminant
8830 (Entity
(Discrim
))) = Chars
(Discrim_Name
))
8832 Chars
(Original_Record_Component
(Entity
(Discrim
))) =
8833 Chars
(Discrim_Name
);
8835 if No
(Next
(Assoc
)) then
8836 if not Is_Constrained
(Typ
) and then Is_Derived_Type
(Typ
) then
8838 -- If the type is a tagged type with inherited discriminants,
8839 -- use the stored constraint on the parent in order to find
8840 -- the values of discriminants that are otherwise hidden by an
8841 -- explicit constraint. Renamed discriminants are handled in
8844 -- If several parent discriminants are renamed by a single
8845 -- discriminant of the derived type, the call to obtain the
8846 -- Corresponding_Discriminant field only retrieves the last
8847 -- of them. We recover the constraint on the others from the
8848 -- Stored_Constraint as well.
8850 -- An inherited discriminant may have been constrained in a
8851 -- later ancestor (not the immediate parent) so we must examine
8852 -- the stored constraint of all of them to locate the inherited
8858 T
: Entity_Id
:= Typ
;
8861 while Is_Derived_Type
(T
) loop
8862 if Present
(Stored_Constraint
(T
)) then
8863 D
:= First_Discriminant
(Etype
(T
));
8864 C
:= First_Elmt
(Stored_Constraint
(T
));
8865 while Present
(D
) and then Present
(C
) loop
8866 if Chars
(Discrim_Name
) = Chars
(D
) then
8867 if Is_Entity_Name
(Node
(C
))
8868 and then Entity
(Node
(C
)) = Entity
(Discrim
)
8870 -- D is renamed by Discrim, whose value is
8877 Make_Component_Association
(Sloc
(Typ
),
8879 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
8880 Duplicate_Subexpr_No_Checks
(Node
(C
)));
8883 exit Find_Constraint
;
8886 Next_Discriminant
(D
);
8891 -- Discriminant may be inherited from ancestor
8899 if No
(Next
(Assoc
)) then
8901 (" missing value for discriminant&",
8902 First
(Governed_By
), Discrim_Name
);
8904 Report_Errors
:= True;
8909 end loop Find_Constraint
;
8911 Discrim_Value
:= Expression
(Assoc
);
8913 if not Is_OK_Static_Expression
(Discrim_Value
) then
8915 -- If the variant part is governed by a discriminant of the type
8916 -- this is an error. If the variant part and the discriminant are
8917 -- inherited from an ancestor this is legal (AI05-120) unless the
8918 -- components are being gathered for an aggregate, in which case
8919 -- the caller must check Report_Errors.
8921 if Scope
(Original_Record_Component
8922 ((Entity
(First
(Choices
(Assoc
)))))) = Typ
8925 ("value for discriminant & must be static!",
8926 Discrim_Value
, Discrim
);
8927 Why_Not_Static
(Discrim_Value
);
8930 Report_Errors
:= True;
8934 Search_For_Discriminant_Value
: declare
8940 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
8943 Find_Discrete_Value
: while Present
(Variant
) loop
8944 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
8945 while Present
(Discrete_Choice
) loop
8946 exit Find_Discrete_Value
when
8947 Nkind
(Discrete_Choice
) = N_Others_Choice
;
8949 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
8951 UI_Low
:= Expr_Value
(Low
);
8952 UI_High
:= Expr_Value
(High
);
8954 exit Find_Discrete_Value
when
8955 UI_Low
<= UI_Discrim_Value
8957 UI_High
>= UI_Discrim_Value
;
8959 Next
(Discrete_Choice
);
8962 Next_Non_Pragma
(Variant
);
8963 end loop Find_Discrete_Value
;
8964 end Search_For_Discriminant_Value
;
8966 -- The case statement must include a variant that corresponds to the
8967 -- value of the discriminant, unless the discriminant type has a
8968 -- static predicate. In that case the absence of an others_choice that
8969 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8972 and then not Has_Static_Predicate
(Etype
(Discrim_Name
))
8975 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
8976 Report_Errors
:= True;
8980 -- If we have found the corresponding choice, recursively add its
8981 -- components to the Into list. The nested components are part of
8982 -- the same record type.
8984 if Present
(Variant
) then
8986 (Typ
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
8988 end Gather_Components
;
8990 ------------------------
8991 -- Get_Actual_Subtype --
8992 ------------------------
8994 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
8995 Typ
: constant Entity_Id
:= Etype
(N
);
8996 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
9005 -- If what we have is an identifier that references a subprogram
9006 -- formal, or a variable or constant object, then we get the actual
9007 -- subtype from the referenced entity if one has been built.
9009 if Nkind
(N
) = N_Identifier
9011 (Is_Formal
(Entity
(N
))
9012 or else Ekind
(Entity
(N
)) = E_Constant
9013 or else Ekind
(Entity
(N
)) = E_Variable
)
9014 and then Present
(Actual_Subtype
(Entity
(N
)))
9016 return Actual_Subtype
(Entity
(N
));
9018 -- Actual subtype of unchecked union is always itself. We never need
9019 -- the "real" actual subtype. If we did, we couldn't get it anyway
9020 -- because the discriminant is not available. The restrictions on
9021 -- Unchecked_Union are designed to make sure that this is OK.
9023 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
9026 -- Here for the unconstrained case, we must find actual subtype
9027 -- No actual subtype is available, so we must build it on the fly.
9029 -- Checking the type, not the underlying type, for constrainedness
9030 -- seems to be necessary. Maybe all the tests should be on the type???
9032 elsif (not Is_Constrained
(Typ
))
9033 and then (Is_Array_Type
(Utyp
)
9034 or else (Is_Record_Type
(Utyp
)
9035 and then Has_Discriminants
(Utyp
)))
9036 and then not Has_Unknown_Discriminants
(Utyp
)
9037 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
9039 -- Nothing to do if in spec expression (why not???)
9041 if In_Spec_Expression
then
9044 elsif Is_Private_Type
(Typ
) and then not Has_Discriminants
(Typ
) then
9046 -- If the type has no discriminants, there is no subtype to
9047 -- build, even if the underlying type is discriminated.
9051 -- Else build the actual subtype
9054 Decl
:= Build_Actual_Subtype
(Typ
, N
);
9055 Atyp
:= Defining_Identifier
(Decl
);
9057 -- If Build_Actual_Subtype generated a new declaration then use it
9061 -- The actual subtype is an Itype, so analyze the declaration,
9062 -- but do not attach it to the tree, to get the type defined.
9064 Set_Parent
(Decl
, N
);
9065 Set_Is_Itype
(Atyp
);
9066 Analyze
(Decl
, Suppress
=> All_Checks
);
9067 Set_Associated_Node_For_Itype
(Atyp
, N
);
9068 Set_Has_Delayed_Freeze
(Atyp
, False);
9070 -- We need to freeze the actual subtype immediately. This is
9071 -- needed, because otherwise this Itype will not get frozen
9072 -- at all, and it is always safe to freeze on creation because
9073 -- any associated types must be frozen at this point.
9075 Freeze_Itype
(Atyp
, N
);
9078 -- Otherwise we did not build a declaration, so return original
9085 -- For all remaining cases, the actual subtype is the same as
9086 -- the nominal type.
9091 end Get_Actual_Subtype
;
9093 -------------------------------------
9094 -- Get_Actual_Subtype_If_Available --
9095 -------------------------------------
9097 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
9098 Typ
: constant Entity_Id
:= Etype
(N
);
9101 -- If what we have is an identifier that references a subprogram
9102 -- formal, or a variable or constant object, then we get the actual
9103 -- subtype from the referenced entity if one has been built.
9105 if Nkind
(N
) = N_Identifier
9107 (Is_Formal
(Entity
(N
))
9108 or else Ekind
(Entity
(N
)) = E_Constant
9109 or else Ekind
(Entity
(N
)) = E_Variable
)
9110 and then Present
(Actual_Subtype
(Entity
(N
)))
9112 return Actual_Subtype
(Entity
(N
));
9114 -- Otherwise the Etype of N is returned unchanged
9119 end Get_Actual_Subtype_If_Available
;
9121 ------------------------
9122 -- Get_Body_From_Stub --
9123 ------------------------
9125 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
9127 return Proper_Body
(Unit
(Library_Unit
(N
)));
9128 end Get_Body_From_Stub
;
9130 ---------------------
9131 -- Get_Cursor_Type --
9132 ---------------------
9134 function Get_Cursor_Type
9136 Typ
: Entity_Id
) return Entity_Id
9140 First_Op
: Entity_Id
;
9144 -- If error already detected, return
9146 if Error_Posted
(Aspect
) then
9150 -- The cursor type for an Iterable aspect is the return type of a
9151 -- non-overloaded First primitive operation. Locate association for
9154 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
9156 while Present
(Assoc
) loop
9157 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
9158 First_Op
:= Expression
(Assoc
);
9165 if First_Op
= Any_Id
then
9166 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
9172 -- Locate function with desired name and profile in scope of type
9173 -- In the rare case where the type is an integer type, a base type
9174 -- is created for it, check that the base type of the first formal
9175 -- of First matches the base type of the domain.
9177 Func
:= First_Entity
(Scope
(Typ
));
9178 while Present
(Func
) loop
9179 if Chars
(Func
) = Chars
(First_Op
)
9180 and then Ekind
(Func
) = E_Function
9181 and then Present
(First_Formal
(Func
))
9182 and then Base_Type
(Etype
(First_Formal
(Func
))) = Base_Type
(Typ
)
9183 and then No
(Next_Formal
(First_Formal
(Func
)))
9185 if Cursor
/= Any_Type
then
9187 ("Operation First for iterable type must be unique", Aspect
);
9190 Cursor
:= Etype
(Func
);
9197 -- If not found, no way to resolve remaining primitives.
9199 if Cursor
= Any_Type
then
9201 ("No legal primitive operation First for Iterable type", Aspect
);
9205 end Get_Cursor_Type
;
9207 function Get_Cursor_Type
(Typ
: Entity_Id
) return Entity_Id
is
9209 return Etype
(Get_Iterable_Type_Primitive
(Typ
, Name_First
));
9210 end Get_Cursor_Type
;
9212 -------------------------------
9213 -- Get_Default_External_Name --
9214 -------------------------------
9216 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
9218 Get_Decoded_Name_String
(Chars
(E
));
9220 if Opt
.External_Name_Imp_Casing
= Uppercase
then
9221 Set_Casing
(All_Upper_Case
);
9223 Set_Casing
(All_Lower_Case
);
9227 Make_String_Literal
(Sloc
(E
),
9228 Strval
=> String_From_Name_Buffer
);
9229 end Get_Default_External_Name
;
9231 --------------------------
9232 -- Get_Enclosing_Object --
9233 --------------------------
9235 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
9237 if Is_Entity_Name
(N
) then
9241 when N_Indexed_Component
9242 | N_Selected_Component
9245 -- If not generating code, a dereference may be left implicit.
9246 -- In thoses cases, return Empty.
9248 if Is_Access_Type
(Etype
(Prefix
(N
))) then
9251 return Get_Enclosing_Object
(Prefix
(N
));
9254 when N_Type_Conversion
=>
9255 return Get_Enclosing_Object
(Expression
(N
));
9261 end Get_Enclosing_Object
;
9263 ---------------------------
9264 -- Get_Enum_Lit_From_Pos --
9265 ---------------------------
9267 function Get_Enum_Lit_From_Pos
9270 Loc
: Source_Ptr
) return Node_Id
9272 Btyp
: Entity_Id
:= Base_Type
(T
);
9277 -- In the case where the literal is of type Character, Wide_Character
9278 -- or Wide_Wide_Character or of a type derived from them, there needs
9279 -- to be some special handling since there is no explicit chain of
9280 -- literals to search. Instead, an N_Character_Literal node is created
9281 -- with the appropriate Char_Code and Chars fields.
9283 if Is_Standard_Character_Type
(T
) then
9284 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
9287 Make_Character_Literal
(Loc
,
9289 Char_Literal_Value
=> Pos
);
9291 -- For all other cases, we have a complete table of literals, and
9292 -- we simply iterate through the chain of literal until the one
9293 -- with the desired position value is found.
9296 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
9297 Btyp
:= Full_View
(Btyp
);
9300 Lit
:= First_Literal
(Btyp
);
9302 -- Position in the enumeration type starts at 0
9304 if UI_To_Int
(Pos
) < 0 then
9305 raise Constraint_Error
;
9308 for J
in 1 .. UI_To_Int
(Pos
) loop
9311 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9312 -- inside the loop to avoid calling Next_Literal on Empty.
9315 raise Constraint_Error
;
9319 -- Create a new node from Lit, with source location provided by Loc
9320 -- if not equal to No_Location, or by copying the source location of
9325 if LLoc
= No_Location
then
9329 return New_Occurrence_Of
(Lit
, LLoc
);
9331 end Get_Enum_Lit_From_Pos
;
9333 ------------------------
9334 -- Get_Generic_Entity --
9335 ------------------------
9337 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
9338 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
9340 if Present
(Renamed_Object
(Ent
)) then
9341 return Renamed_Object
(Ent
);
9345 end Get_Generic_Entity
;
9347 -------------------------------------
9348 -- Get_Incomplete_View_Of_Ancestor --
9349 -------------------------------------
9351 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
9352 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
9353 Par_Scope
: Entity_Id
;
9354 Par_Type
: Entity_Id
;
9357 -- The incomplete view of an ancestor is only relevant for private
9358 -- derived types in child units.
9360 if not Is_Derived_Type
(E
)
9361 or else not Is_Child_Unit
(Cur_Unit
)
9366 Par_Scope
:= Scope
(Cur_Unit
);
9367 if No
(Par_Scope
) then
9371 Par_Type
:= Etype
(Base_Type
(E
));
9373 -- Traverse list of ancestor types until we find one declared in
9374 -- a parent or grandparent unit (two levels seem sufficient).
9376 while Present
(Par_Type
) loop
9377 if Scope
(Par_Type
) = Par_Scope
9378 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
9382 elsif not Is_Derived_Type
(Par_Type
) then
9386 Par_Type
:= Etype
(Base_Type
(Par_Type
));
9390 -- If none found, there is no relevant ancestor type.
9394 end Get_Incomplete_View_Of_Ancestor
;
9396 ----------------------
9397 -- Get_Index_Bounds --
9398 ----------------------
9400 procedure Get_Index_Bounds
9404 Use_Full_View
: Boolean := False)
9406 function Scalar_Range_Of_Type
(Typ
: Entity_Id
) return Node_Id
;
9407 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9408 -- Typ qualifies, the scalar range is obtained from the full view of the
9411 --------------------------
9412 -- Scalar_Range_Of_Type --
9413 --------------------------
9415 function Scalar_Range_Of_Type
(Typ
: Entity_Id
) return Node_Id
is
9416 T
: Entity_Id
:= Typ
;
9419 if Use_Full_View
and then Present
(Full_View
(T
)) then
9423 return Scalar_Range
(T
);
9424 end Scalar_Range_Of_Type
;
9428 Kind
: constant Node_Kind
:= Nkind
(N
);
9431 -- Start of processing for Get_Index_Bounds
9434 if Kind
= N_Range
then
9436 H
:= High_Bound
(N
);
9438 elsif Kind
= N_Subtype_Indication
then
9439 Rng
:= Range_Expression
(Constraint
(N
));
9447 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
9448 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
9451 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
9452 Rng
:= Scalar_Range_Of_Type
(Entity
(N
));
9454 if Error_Posted
(Rng
) then
9458 elsif Nkind
(Rng
) = N_Subtype_Indication
then
9459 Get_Index_Bounds
(Rng
, L
, H
);
9462 L
:= Low_Bound
(Rng
);
9463 H
:= High_Bound
(Rng
);
9467 -- N is an expression, indicating a range with one value
9472 end Get_Index_Bounds
;
9474 -----------------------------
9475 -- Get_Interfacing_Aspects --
9476 -----------------------------
9478 procedure Get_Interfacing_Aspects
9479 (Iface_Asp
: Node_Id
;
9480 Conv_Asp
: out Node_Id
;
9481 EN_Asp
: out Node_Id
;
9482 Expo_Asp
: out Node_Id
;
9483 Imp_Asp
: out Node_Id
;
9484 LN_Asp
: out Node_Id
;
9485 Do_Checks
: Boolean := False)
9487 procedure Save_Or_Duplication_Error
9489 To
: in out Node_Id
);
9490 -- Save the value of aspect Asp in node To. If To already has a value,
9491 -- then this is considered a duplicate use of aspect. Emit an error if
9492 -- flag Do_Checks is set.
9494 -------------------------------
9495 -- Save_Or_Duplication_Error --
9496 -------------------------------
9498 procedure Save_Or_Duplication_Error
9500 To
: in out Node_Id
)
9503 -- Detect an extra aspect and issue an error
9505 if Present
(To
) then
9507 Error_Msg_Name_1
:= Chars
(Identifier
(Asp
));
9508 Error_Msg_Sloc
:= Sloc
(To
);
9509 Error_Msg_N
("aspect % previously given #", Asp
);
9512 -- Otherwise capture the aspect
9517 end Save_Or_Duplication_Error
;
9524 -- The following variables capture each individual aspect
9526 Conv
: Node_Id
:= Empty
;
9527 EN
: Node_Id
:= Empty
;
9528 Expo
: Node_Id
:= Empty
;
9529 Imp
: Node_Id
:= Empty
;
9530 LN
: Node_Id
:= Empty
;
9532 -- Start of processing for Get_Interfacing_Aspects
9535 -- The input interfacing aspect should reside in an aspect specification
9538 pragma Assert
(Is_List_Member
(Iface_Asp
));
9540 -- Examine the aspect specifications of the related entity. Find and
9541 -- capture all interfacing aspects. Detect duplicates and emit errors
9544 Asp
:= First
(List_Containing
(Iface_Asp
));
9545 while Present
(Asp
) loop
9546 Asp_Id
:= Get_Aspect_Id
(Asp
);
9548 if Asp_Id
= Aspect_Convention
then
9549 Save_Or_Duplication_Error
(Asp
, Conv
);
9551 elsif Asp_Id
= Aspect_External_Name
then
9552 Save_Or_Duplication_Error
(Asp
, EN
);
9554 elsif Asp_Id
= Aspect_Export
then
9555 Save_Or_Duplication_Error
(Asp
, Expo
);
9557 elsif Asp_Id
= Aspect_Import
then
9558 Save_Or_Duplication_Error
(Asp
, Imp
);
9560 elsif Asp_Id
= Aspect_Link_Name
then
9561 Save_Or_Duplication_Error
(Asp
, LN
);
9572 end Get_Interfacing_Aspects
;
9574 ---------------------------------
9575 -- Get_Iterable_Type_Primitive --
9576 ---------------------------------
9578 function Get_Iterable_Type_Primitive
9580 Nam
: Name_Id
) return Entity_Id
9582 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
9590 Assoc
:= First
(Component_Associations
(Funcs
));
9591 while Present
(Assoc
) loop
9592 if Chars
(First
(Choices
(Assoc
))) = Nam
then
9593 return Entity
(Expression
(Assoc
));
9596 Assoc
:= Next
(Assoc
);
9601 end Get_Iterable_Type_Primitive
;
9603 ----------------------------------
9604 -- Get_Library_Unit_Name_String --
9605 ----------------------------------
9607 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
9608 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
9611 Get_Unit_Name_String
(Unit_Name_Id
);
9613 -- Remove seven last character (" (spec)" or " (body)")
9615 Name_Len
:= Name_Len
- 7;
9616 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
9617 end Get_Library_Unit_Name_String
;
9619 --------------------------
9620 -- Get_Max_Queue_Length --
9621 --------------------------
9623 function Get_Max_Queue_Length
(Id
: Entity_Id
) return Uint
is
9624 pragma Assert
(Is_Entry
(Id
));
9625 Prag
: constant Entity_Id
:= Get_Pragma
(Id
, Pragma_Max_Queue_Length
);
9628 -- A value of 0 represents no maximum specified, and entries and entry
9629 -- families with no Max_Queue_Length aspect or pragma default to it.
9631 if not Present
(Prag
) then
9635 return Intval
(Expression
(First
(Pragma_Argument_Associations
(Prag
))));
9636 end Get_Max_Queue_Length
;
9638 ------------------------
9639 -- Get_Name_Entity_Id --
9640 ------------------------
9642 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
9644 return Entity_Id
(Get_Name_Table_Int
(Id
));
9645 end Get_Name_Entity_Id
;
9647 ------------------------------
9648 -- Get_Name_From_CTC_Pragma --
9649 ------------------------------
9651 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
9652 Arg
: constant Node_Id
:=
9653 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
9655 return Strval
(Expr_Value_S
(Arg
));
9656 end Get_Name_From_CTC_Pragma
;
9658 -----------------------
9659 -- Get_Parent_Entity --
9660 -----------------------
9662 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
9664 if Nkind
(Unit
) = N_Package_Body
9665 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
9667 return Defining_Entity
9668 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
9669 elsif Nkind
(Unit
) = N_Package_Instantiation
then
9670 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
9672 return Defining_Entity
(Unit
);
9674 end Get_Parent_Entity
;
9680 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
9682 return Get_Pragma_Id
(Pragma_Name_Unmapped
(N
));
9685 ------------------------
9686 -- Get_Qualified_Name --
9687 ------------------------
9689 function Get_Qualified_Name
9691 Suffix
: Entity_Id
:= Empty
) return Name_Id
9693 Suffix_Nam
: Name_Id
:= No_Name
;
9696 if Present
(Suffix
) then
9697 Suffix_Nam
:= Chars
(Suffix
);
9700 return Get_Qualified_Name
(Chars
(Id
), Suffix_Nam
, Scope
(Id
));
9701 end Get_Qualified_Name
;
9703 function Get_Qualified_Name
9705 Suffix
: Name_Id
:= No_Name
;
9706 Scop
: Entity_Id
:= Current_Scope
) return Name_Id
9708 procedure Add_Scope
(S
: Entity_Id
);
9709 -- Add the fully qualified form of scope S to the name buffer. The
9717 procedure Add_Scope
(S
: Entity_Id
) is
9722 elsif S
= Standard_Standard
then
9726 Add_Scope
(Scope
(S
));
9727 Get_Name_String_And_Append
(Chars
(S
));
9728 Add_Str_To_Name_Buffer
("__");
9732 -- Start of processing for Get_Qualified_Name
9738 -- Append the base name after all scopes have been chained
9740 Get_Name_String_And_Append
(Nam
);
9742 -- Append the suffix (if present)
9744 if Suffix
/= No_Name
then
9745 Add_Str_To_Name_Buffer
("__");
9746 Get_Name_String_And_Append
(Suffix
);
9750 end Get_Qualified_Name
;
9752 -----------------------
9753 -- Get_Reason_String --
9754 -----------------------
9756 procedure Get_Reason_String
(N
: Node_Id
) is
9758 if Nkind
(N
) = N_String_Literal
then
9759 Store_String_Chars
(Strval
(N
));
9761 elsif Nkind
(N
) = N_Op_Concat
then
9762 Get_Reason_String
(Left_Opnd
(N
));
9763 Get_Reason_String
(Right_Opnd
(N
));
9765 -- If not of required form, error
9769 ("Reason for pragma Warnings has wrong form", N
);
9771 ("\must be string literal or concatenation of string literals", N
);
9774 end Get_Reason_String
;
9776 --------------------------------
9777 -- Get_Reference_Discriminant --
9778 --------------------------------
9780 function Get_Reference_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
9784 D
:= First_Discriminant
(Typ
);
9785 while Present
(D
) loop
9786 if Has_Implicit_Dereference
(D
) then
9789 Next_Discriminant
(D
);
9793 end Get_Reference_Discriminant
;
9795 ---------------------------
9796 -- Get_Referenced_Object --
9797 ---------------------------
9799 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
9804 while Is_Entity_Name
(R
)
9805 and then Present
(Renamed_Object
(Entity
(R
)))
9807 R
:= Renamed_Object
(Entity
(R
));
9811 end Get_Referenced_Object
;
9813 ------------------------
9814 -- Get_Renamed_Entity --
9815 ------------------------
9817 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
9822 while Present
(Renamed_Entity
(R
)) loop
9823 R
:= Renamed_Entity
(R
);
9827 end Get_Renamed_Entity
;
9829 -----------------------
9830 -- Get_Return_Object --
9831 -----------------------
9833 function Get_Return_Object
(N
: Node_Id
) return Entity_Id
is
9837 Decl
:= First
(Return_Object_Declarations
(N
));
9838 while Present
(Decl
) loop
9839 exit when Nkind
(Decl
) = N_Object_Declaration
9840 and then Is_Return_Object
(Defining_Identifier
(Decl
));
9844 pragma Assert
(Present
(Decl
));
9845 return Defining_Identifier
(Decl
);
9846 end Get_Return_Object
;
9848 ---------------------------
9849 -- Get_Subprogram_Entity --
9850 ---------------------------
9852 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
9854 Subp_Id
: Entity_Id
;
9857 if Nkind
(Nod
) = N_Accept_Statement
then
9858 Subp
:= Entry_Direct_Name
(Nod
);
9860 elsif Nkind
(Nod
) = N_Slice
then
9861 Subp
:= Prefix
(Nod
);
9867 -- Strip the subprogram call
9870 if Nkind_In
(Subp
, N_Explicit_Dereference
,
9871 N_Indexed_Component
,
9872 N_Selected_Component
)
9874 Subp
:= Prefix
(Subp
);
9876 elsif Nkind_In
(Subp
, N_Type_Conversion
,
9877 N_Unchecked_Type_Conversion
)
9879 Subp
:= Expression
(Subp
);
9886 -- Extract the entity of the subprogram call
9888 if Is_Entity_Name
(Subp
) then
9889 Subp_Id
:= Entity
(Subp
);
9891 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
9892 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
9895 if Is_Subprogram
(Subp_Id
) then
9901 -- The search did not find a construct that denotes a subprogram
9906 end Get_Subprogram_Entity
;
9908 -----------------------------
9909 -- Get_Task_Body_Procedure --
9910 -----------------------------
9912 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Entity_Id
is
9914 -- Note: A task type may be the completion of a private type with
9915 -- discriminants. When performing elaboration checks on a task
9916 -- declaration, the current view of the type may be the private one,
9917 -- and the procedure that holds the body of the task is held in its
9920 -- This is an odd function, why not have Task_Body_Procedure do
9921 -- the following digging???
9923 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
9924 end Get_Task_Body_Procedure
;
9926 -------------------------
9927 -- Get_User_Defined_Eq --
9928 -------------------------
9930 function Get_User_Defined_Eq
(E
: Entity_Id
) return Entity_Id
is
9935 Prim
:= First_Elmt
(Collect_Primitive_Operations
(E
));
9936 while Present
(Prim
) loop
9939 if Chars
(Op
) = Name_Op_Eq
9940 and then Etype
(Op
) = Standard_Boolean
9941 and then Etype
(First_Formal
(Op
)) = E
9942 and then Etype
(Next_Formal
(First_Formal
(Op
))) = E
9951 end Get_User_Defined_Eq
;
9959 Priv_Typ
: out Entity_Id
;
9960 Full_Typ
: out Entity_Id
;
9961 Full_Base
: out Entity_Id
;
9962 CRec_Typ
: out Entity_Id
)
9964 IP_View
: Entity_Id
;
9967 -- Assume that none of the views can be recovered
9974 -- The input type is the corresponding record type of a protected or a
9977 if Ekind
(Typ
) = E_Record_Type
9978 and then Is_Concurrent_Record_Type
(Typ
)
9981 Full_Typ
:= Corresponding_Concurrent_Type
(CRec_Typ
);
9982 Full_Base
:= Base_Type
(Full_Typ
);
9983 Priv_Typ
:= Incomplete_Or_Partial_View
(Full_Typ
);
9985 -- Otherwise the input type denotes an arbitrary type
9988 IP_View
:= Incomplete_Or_Partial_View
(Typ
);
9990 -- The input type denotes the full view of a private type
9992 if Present
(IP_View
) then
9993 Priv_Typ
:= IP_View
;
9996 -- The input type is a private type
9998 elsif Is_Private_Type
(Typ
) then
10000 Full_Typ
:= Full_View
(Priv_Typ
);
10002 -- Otherwise the input type does not have any views
10008 if Present
(Full_Typ
) then
10009 Full_Base
:= Base_Type
(Full_Typ
);
10011 if Ekind_In
(Full_Typ
, E_Protected_Type
, E_Task_Type
) then
10012 CRec_Typ
:= Corresponding_Record_Type
(Full_Typ
);
10018 -----------------------
10019 -- Has_Access_Values --
10020 -----------------------
10022 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
10023 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
10026 -- Case of a private type which is not completed yet. This can only
10027 -- happen in the case of a generic format type appearing directly, or
10028 -- as a component of the type to which this function is being applied
10029 -- at the top level. Return False in this case, since we certainly do
10030 -- not know that the type contains access types.
10035 elsif Is_Access_Type
(Typ
) then
10038 elsif Is_Array_Type
(Typ
) then
10039 return Has_Access_Values
(Component_Type
(Typ
));
10041 elsif Is_Record_Type
(Typ
) then
10046 -- Loop to Check components
10048 Comp
:= First_Component_Or_Discriminant
(Typ
);
10049 while Present
(Comp
) loop
10051 -- Check for access component, tag field does not count, even
10052 -- though it is implemented internally using an access type.
10054 if Has_Access_Values
(Etype
(Comp
))
10055 and then Chars
(Comp
) /= Name_uTag
10060 Next_Component_Or_Discriminant
(Comp
);
10069 end Has_Access_Values
;
10071 ------------------------------
10072 -- Has_Compatible_Alignment --
10073 ------------------------------
10075 function Has_Compatible_Alignment
10078 Layout_Done
: Boolean) return Alignment_Result
10080 function Has_Compatible_Alignment_Internal
10083 Layout_Done
: Boolean;
10084 Default
: Alignment_Result
) return Alignment_Result
;
10085 -- This is the internal recursive function that actually does the work.
10086 -- There is one additional parameter, which says what the result should
10087 -- be if no alignment information is found, and there is no definite
10088 -- indication of compatible alignments. At the outer level, this is set
10089 -- to Unknown, but for internal recursive calls in the case where types
10090 -- are known to be correct, it is set to Known_Compatible.
10092 ---------------------------------------
10093 -- Has_Compatible_Alignment_Internal --
10094 ---------------------------------------
10096 function Has_Compatible_Alignment_Internal
10099 Layout_Done
: Boolean;
10100 Default
: Alignment_Result
) return Alignment_Result
10102 Result
: Alignment_Result
:= Known_Compatible
;
10103 -- Holds the current status of the result. Note that once a value of
10104 -- Known_Incompatible is set, it is sticky and does not get changed
10105 -- to Unknown (the value in Result only gets worse as we go along,
10108 Offs
: Uint
:= No_Uint
;
10109 -- Set to a factor of the offset from the base object when Expr is a
10110 -- selected or indexed component, based on Component_Bit_Offset and
10111 -- Component_Size respectively. A negative value is used to represent
10112 -- a value which is not known at compile time.
10114 procedure Check_Prefix
;
10115 -- Checks the prefix recursively in the case where the expression
10116 -- is an indexed or selected component.
10118 procedure Set_Result
(R
: Alignment_Result
);
10119 -- If R represents a worse outcome (unknown instead of known
10120 -- compatible, or known incompatible), then set Result to R.
10126 procedure Check_Prefix
is
10128 -- The subtlety here is that in doing a recursive call to check
10129 -- the prefix, we have to decide what to do in the case where we
10130 -- don't find any specific indication of an alignment problem.
10132 -- At the outer level, we normally set Unknown as the result in
10133 -- this case, since we can only set Known_Compatible if we really
10134 -- know that the alignment value is OK, but for the recursive
10135 -- call, in the case where the types match, and we have not
10136 -- specified a peculiar alignment for the object, we are only
10137 -- concerned about suspicious rep clauses, the default case does
10138 -- not affect us, since the compiler will, in the absence of such
10139 -- rep clauses, ensure that the alignment is correct.
10141 if Default
= Known_Compatible
10143 (Etype
(Obj
) = Etype
(Expr
)
10144 and then (Unknown_Alignment
(Obj
)
10146 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
10149 (Has_Compatible_Alignment_Internal
10150 (Obj
, Prefix
(Expr
), Layout_Done
, Known_Compatible
));
10152 -- In all other cases, we need a full check on the prefix
10156 (Has_Compatible_Alignment_Internal
10157 (Obj
, Prefix
(Expr
), Layout_Done
, Unknown
));
10165 procedure Set_Result
(R
: Alignment_Result
) is
10172 -- Start of processing for Has_Compatible_Alignment_Internal
10175 -- If Expr is a selected component, we must make sure there is no
10176 -- potentially troublesome component clause and that the record is
10177 -- not packed if the layout is not done.
10179 if Nkind
(Expr
) = N_Selected_Component
then
10181 -- Packing generates unknown alignment if layout is not done
10183 if Is_Packed
(Etype
(Prefix
(Expr
))) and then not Layout_Done
then
10184 Set_Result
(Unknown
);
10187 -- Check prefix and component offset
10190 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
10192 -- If Expr is an indexed component, we must make sure there is no
10193 -- potentially troublesome Component_Size clause and that the array
10194 -- is not bit-packed if the layout is not done.
10196 elsif Nkind
(Expr
) = N_Indexed_Component
then
10198 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
10201 -- Packing generates unknown alignment if layout is not done
10203 if Is_Bit_Packed_Array
(Typ
) and then not Layout_Done
then
10204 Set_Result
(Unknown
);
10207 -- Check prefix and component offset (or at least size)
10210 Offs
:= Indexed_Component_Bit_Offset
(Expr
);
10211 if Offs
= No_Uint
then
10212 Offs
:= Component_Size
(Typ
);
10217 -- If we have a null offset, the result is entirely determined by
10218 -- the base object and has already been computed recursively.
10220 if Offs
= Uint_0
then
10223 -- Case where we know the alignment of the object
10225 elsif Known_Alignment
(Obj
) then
10227 ObjA
: constant Uint
:= Alignment
(Obj
);
10228 ExpA
: Uint
:= No_Uint
;
10229 SizA
: Uint
:= No_Uint
;
10232 -- If alignment of Obj is 1, then we are always OK
10235 Set_Result
(Known_Compatible
);
10237 -- Alignment of Obj is greater than 1, so we need to check
10240 -- If we have an offset, see if it is compatible
10242 if Offs
/= No_Uint
and Offs
> Uint_0
then
10243 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
10244 Set_Result
(Known_Incompatible
);
10247 -- See if Expr is an object with known alignment
10249 elsif Is_Entity_Name
(Expr
)
10250 and then Known_Alignment
(Entity
(Expr
))
10252 ExpA
:= Alignment
(Entity
(Expr
));
10254 -- Otherwise, we can use the alignment of the type of
10255 -- Expr given that we already checked for
10256 -- discombobulating rep clauses for the cases of indexed
10257 -- and selected components above.
10259 elsif Known_Alignment
(Etype
(Expr
)) then
10260 ExpA
:= Alignment
(Etype
(Expr
));
10262 -- Otherwise the alignment is unknown
10265 Set_Result
(Default
);
10268 -- If we got an alignment, see if it is acceptable
10270 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
10271 Set_Result
(Known_Incompatible
);
10274 -- If Expr is not a piece of a larger object, see if size
10275 -- is given. If so, check that it is not too small for the
10276 -- required alignment.
10278 if Offs
/= No_Uint
then
10281 -- See if Expr is an object with known size
10283 elsif Is_Entity_Name
(Expr
)
10284 and then Known_Static_Esize
(Entity
(Expr
))
10286 SizA
:= Esize
(Entity
(Expr
));
10288 -- Otherwise, we check the object size of the Expr type
10290 elsif Known_Static_Esize
(Etype
(Expr
)) then
10291 SizA
:= Esize
(Etype
(Expr
));
10294 -- If we got a size, see if it is a multiple of the Obj
10295 -- alignment, if not, then the alignment cannot be
10296 -- acceptable, since the size is always a multiple of the
10299 if SizA
/= No_Uint
then
10300 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
10301 Set_Result
(Known_Incompatible
);
10307 -- If we do not know required alignment, any non-zero offset is a
10308 -- potential problem (but certainly may be OK, so result is unknown).
10310 elsif Offs
/= No_Uint
then
10311 Set_Result
(Unknown
);
10313 -- If we can't find the result by direct comparison of alignment
10314 -- values, then there is still one case that we can determine known
10315 -- result, and that is when we can determine that the types are the
10316 -- same, and no alignments are specified. Then we known that the
10317 -- alignments are compatible, even if we don't know the alignment
10318 -- value in the front end.
10320 elsif Etype
(Obj
) = Etype
(Expr
) then
10322 -- Types are the same, but we have to check for possible size
10323 -- and alignments on the Expr object that may make the alignment
10324 -- different, even though the types are the same.
10326 if Is_Entity_Name
(Expr
) then
10328 -- First check alignment of the Expr object. Any alignment less
10329 -- than Maximum_Alignment is worrisome since this is the case
10330 -- where we do not know the alignment of Obj.
10332 if Known_Alignment
(Entity
(Expr
))
10333 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
10334 Ttypes
.Maximum_Alignment
10336 Set_Result
(Unknown
);
10338 -- Now check size of Expr object. Any size that is not an
10339 -- even multiple of Maximum_Alignment is also worrisome
10340 -- since it may cause the alignment of the object to be less
10341 -- than the alignment of the type.
10343 elsif Known_Static_Esize
(Entity
(Expr
))
10345 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
10346 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
10349 Set_Result
(Unknown
);
10351 -- Otherwise same type is decisive
10354 Set_Result
(Known_Compatible
);
10358 -- Another case to deal with is when there is an explicit size or
10359 -- alignment clause when the types are not the same. If so, then the
10360 -- result is Unknown. We don't need to do this test if the Default is
10361 -- Unknown, since that result will be set in any case.
10363 elsif Default
/= Unknown
10364 and then (Has_Size_Clause
(Etype
(Expr
))
10366 Has_Alignment_Clause
(Etype
(Expr
)))
10368 Set_Result
(Unknown
);
10370 -- If no indication found, set default
10373 Set_Result
(Default
);
10376 -- Return worst result found
10379 end Has_Compatible_Alignment_Internal
;
10381 -- Start of processing for Has_Compatible_Alignment
10384 -- If Obj has no specified alignment, then set alignment from the type
10385 -- alignment. Perhaps we should always do this, but for sure we should
10386 -- do it when there is an address clause since we can do more if the
10387 -- alignment is known.
10389 if Unknown_Alignment
(Obj
) then
10390 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
10393 -- Now do the internal call that does all the work
10396 Has_Compatible_Alignment_Internal
(Obj
, Expr
, Layout_Done
, Unknown
);
10397 end Has_Compatible_Alignment
;
10399 ----------------------
10400 -- Has_Declarations --
10401 ----------------------
10403 function Has_Declarations
(N
: Node_Id
) return Boolean is
10405 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
10407 N_Compilation_Unit_Aux
,
10413 N_Package_Specification
);
10414 end Has_Declarations
;
10416 ---------------------------------
10417 -- Has_Defaulted_Discriminants --
10418 ---------------------------------
10420 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
10422 return Has_Discriminants
(Typ
)
10423 and then Present
(First_Discriminant
(Typ
))
10424 and then Present
(Discriminant_Default_Value
10425 (First_Discriminant
(Typ
)));
10426 end Has_Defaulted_Discriminants
;
10428 -------------------
10429 -- Has_Denormals --
10430 -------------------
10432 function Has_Denormals
(E
: Entity_Id
) return Boolean is
10434 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
10437 -------------------------------------------
10438 -- Has_Discriminant_Dependent_Constraint --
10439 -------------------------------------------
10441 function Has_Discriminant_Dependent_Constraint
10442 (Comp
: Entity_Id
) return Boolean
10444 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
10445 Subt_Indic
: Node_Id
;
10450 -- Discriminants can't depend on discriminants
10452 if Ekind
(Comp
) = E_Discriminant
then
10456 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
10458 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
10459 Constr
:= Constraint
(Subt_Indic
);
10461 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
10462 Assn
:= First
(Constraints
(Constr
));
10463 while Present
(Assn
) loop
10464 case Nkind
(Assn
) is
10467 | N_Subtype_Indication
10469 if Depends_On_Discriminant
(Assn
) then
10473 when N_Discriminant_Association
=>
10474 if Depends_On_Discriminant
(Expression
(Assn
)) then
10489 end Has_Discriminant_Dependent_Constraint
;
10491 --------------------------------------
10492 -- Has_Effectively_Volatile_Profile --
10493 --------------------------------------
10495 function Has_Effectively_Volatile_Profile
10496 (Subp_Id
: Entity_Id
) return Boolean
10498 Formal
: Entity_Id
;
10501 -- Inspect the formal parameters looking for an effectively volatile
10504 Formal
:= First_Formal
(Subp_Id
);
10505 while Present
(Formal
) loop
10506 if Is_Effectively_Volatile
(Etype
(Formal
)) then
10510 Next_Formal
(Formal
);
10513 -- Inspect the return type of functions
10515 if Ekind_In
(Subp_Id
, E_Function
, E_Generic_Function
)
10516 and then Is_Effectively_Volatile
(Etype
(Subp_Id
))
10522 end Has_Effectively_Volatile_Profile
;
10524 --------------------------
10525 -- Has_Enabled_Property --
10526 --------------------------
10528 function Has_Enabled_Property
10529 (Item_Id
: Entity_Id
;
10530 Property
: Name_Id
) return Boolean
10532 function Protected_Object_Has_Enabled_Property
return Boolean;
10533 -- Determine whether a protected object denoted by Item_Id has the
10534 -- property enabled.
10536 function State_Has_Enabled_Property
return Boolean;
10537 -- Determine whether a state denoted by Item_Id has the property enabled
10539 function Variable_Has_Enabled_Property
return Boolean;
10540 -- Determine whether a variable denoted by Item_Id has the property
10543 -------------------------------------------
10544 -- Protected_Object_Has_Enabled_Property --
10545 -------------------------------------------
10547 function Protected_Object_Has_Enabled_Property
return Boolean is
10548 Constits
: constant Elist_Id
:= Part_Of_Constituents
(Item_Id
);
10549 Constit_Elmt
: Elmt_Id
;
10550 Constit_Id
: Entity_Id
;
10553 -- Protected objects always have the properties Async_Readers and
10554 -- Async_Writers (SPARK RM 7.1.2(16)).
10556 if Property
= Name_Async_Readers
10557 or else Property
= Name_Async_Writers
10561 -- Protected objects that have Part_Of components also inherit their
10562 -- properties Effective_Reads and Effective_Writes
10563 -- (SPARK RM 7.1.2(16)).
10565 elsif Present
(Constits
) then
10566 Constit_Elmt
:= First_Elmt
(Constits
);
10567 while Present
(Constit_Elmt
) loop
10568 Constit_Id
:= Node
(Constit_Elmt
);
10570 if Has_Enabled_Property
(Constit_Id
, Property
) then
10574 Next_Elmt
(Constit_Elmt
);
10579 end Protected_Object_Has_Enabled_Property
;
10581 --------------------------------
10582 -- State_Has_Enabled_Property --
10583 --------------------------------
10585 function State_Has_Enabled_Property
return Boolean is
10586 Decl
: constant Node_Id
:= Parent
(Item_Id
);
10588 procedure Find_Simple_Properties
10589 (Has_External
: out Boolean;
10590 Has_Synchronous
: out Boolean);
10591 -- Extract the simple properties associated with declaration Decl
10593 function Is_Enabled_External_Property
return Boolean;
10594 -- Determine whether property Property appears within the external
10595 -- property list of declaration Decl, and return its status.
10597 ----------------------------
10598 -- Find_Simple_Properties --
10599 ----------------------------
10601 procedure Find_Simple_Properties
10602 (Has_External
: out Boolean;
10603 Has_Synchronous
: out Boolean)
10608 -- Assume that none of the properties are available
10610 Has_External
:= False;
10611 Has_Synchronous
:= False;
10613 Opt
:= First
(Expressions
(Decl
));
10614 while Present
(Opt
) loop
10615 if Nkind
(Opt
) = N_Identifier
then
10616 if Chars
(Opt
) = Name_External
then
10617 Has_External
:= True;
10619 elsif Chars
(Opt
) = Name_Synchronous
then
10620 Has_Synchronous
:= True;
10626 end Find_Simple_Properties
;
10628 ----------------------------------
10629 -- Is_Enabled_External_Property --
10630 ----------------------------------
10632 function Is_Enabled_External_Property
return Boolean is
10636 Prop_Nam
: Node_Id
;
10640 Opt
:= First
(Component_Associations
(Decl
));
10641 while Present
(Opt
) loop
10642 Opt_Nam
:= First
(Choices
(Opt
));
10644 if Nkind
(Opt_Nam
) = N_Identifier
10645 and then Chars
(Opt_Nam
) = Name_External
10647 Props
:= Expression
(Opt
);
10649 -- Multiple properties appear as an aggregate
10651 if Nkind
(Props
) = N_Aggregate
then
10653 -- Simple property form
10655 Prop
:= First
(Expressions
(Props
));
10656 while Present
(Prop
) loop
10657 if Chars
(Prop
) = Property
then
10664 -- Property with expression form
10666 Prop
:= First
(Component_Associations
(Props
));
10667 while Present
(Prop
) loop
10668 Prop_Nam
:= First
(Choices
(Prop
));
10670 -- The property can be represented in two ways:
10671 -- others => <value>
10672 -- <property> => <value>
10674 if Nkind
(Prop_Nam
) = N_Others_Choice
10675 or else (Nkind
(Prop_Nam
) = N_Identifier
10676 and then Chars
(Prop_Nam
) = Property
)
10678 return Is_True
(Expr_Value
(Expression
(Prop
)));
10687 return Chars
(Props
) = Property
;
10695 end Is_Enabled_External_Property
;
10699 Has_External
: Boolean;
10700 Has_Synchronous
: Boolean;
10702 -- Start of processing for State_Has_Enabled_Property
10705 -- The declaration of an external abstract state appears as an
10706 -- extension aggregate. If this is not the case, properties can
10709 if Nkind
(Decl
) /= N_Extension_Aggregate
then
10713 Find_Simple_Properties
(Has_External
, Has_Synchronous
);
10715 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10717 if Has_External
then
10720 -- Option External may enable or disable specific properties
10722 elsif Is_Enabled_External_Property
then
10725 -- Simple option Synchronous
10727 -- enables disables
10728 -- Asynch_Readers Effective_Reads
10729 -- Asynch_Writers Effective_Writes
10731 -- Note that both forms of External have higher precedence than
10732 -- Synchronous (SPARK RM 7.1.4(10)).
10734 elsif Has_Synchronous
then
10735 return Nam_In
(Property
, Name_Async_Readers
, Name_Async_Writers
);
10739 end State_Has_Enabled_Property
;
10741 -----------------------------------
10742 -- Variable_Has_Enabled_Property --
10743 -----------------------------------
10745 function Variable_Has_Enabled_Property
return Boolean is
10746 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
10747 -- Determine whether property pragma Prag (if present) denotes an
10748 -- enabled property.
10754 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
10758 if Present
(Prag
) then
10759 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
10761 -- The pragma has an optional Boolean expression, the related
10762 -- property is enabled only when the expression evaluates to
10765 if Present
(Arg1
) then
10766 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
)));
10768 -- Otherwise the lack of expression enables the property by
10775 -- The property was never set in the first place
10784 AR
: constant Node_Id
:=
10785 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
10786 AW
: constant Node_Id
:=
10787 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
10788 ER
: constant Node_Id
:=
10789 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
10790 EW
: constant Node_Id
:=
10791 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
10793 -- Start of processing for Variable_Has_Enabled_Property
10796 -- A non-effectively volatile object can never possess external
10799 if not Is_Effectively_Volatile
(Item_Id
) then
10802 -- External properties related to variables come in two flavors -
10803 -- explicit and implicit. The explicit case is characterized by the
10804 -- presence of a property pragma with an optional Boolean flag. The
10805 -- property is enabled when the flag evaluates to True or the flag is
10806 -- missing altogether.
10808 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
10811 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
10814 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
10817 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
10820 -- The implicit case lacks all property pragmas
10822 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
10823 if Is_Protected_Type
(Etype
(Item_Id
)) then
10824 return Protected_Object_Has_Enabled_Property
;
10832 end Variable_Has_Enabled_Property
;
10834 -- Start of processing for Has_Enabled_Property
10837 -- Abstract states and variables have a flexible scheme of specifying
10838 -- external properties.
10840 if Ekind
(Item_Id
) = E_Abstract_State
then
10841 return State_Has_Enabled_Property
;
10843 elsif Ekind
(Item_Id
) = E_Variable
then
10844 return Variable_Has_Enabled_Property
;
10846 -- By default, protected objects only have the properties Async_Readers
10847 -- and Async_Writers. If they have Part_Of components, they also inherit
10848 -- their properties Effective_Reads and Effective_Writes
10849 -- (SPARK RM 7.1.2(16)).
10851 elsif Ekind
(Item_Id
) = E_Protected_Object
then
10852 return Protected_Object_Has_Enabled_Property
;
10854 -- Otherwise a property is enabled when the related item is effectively
10858 return Is_Effectively_Volatile
(Item_Id
);
10860 end Has_Enabled_Property
;
10862 -------------------------------------
10863 -- Has_Full_Default_Initialization --
10864 -------------------------------------
10866 function Has_Full_Default_Initialization
(Typ
: Entity_Id
) return Boolean is
10870 -- A type subject to pragma Default_Initial_Condition may be fully
10871 -- default initialized depending on inheritance and the argument of
10872 -- the pragma. Since any type may act as the full view of a private
10873 -- type, this check must be performed prior to the specialized tests
10876 if Has_Fully_Default_Initializing_DIC_Pragma
(Typ
) then
10880 -- A scalar type is fully default initialized if it is subject to aspect
10883 if Is_Scalar_Type
(Typ
) then
10884 return Has_Default_Aspect
(Typ
);
10886 -- An array type is fully default initialized if its element type is
10887 -- scalar and the array type carries aspect Default_Component_Value or
10888 -- the element type is fully default initialized.
10890 elsif Is_Array_Type
(Typ
) then
10892 Has_Default_Aspect
(Typ
)
10893 or else Has_Full_Default_Initialization
(Component_Type
(Typ
));
10895 -- A protected type, record type, or type extension is fully default
10896 -- initialized if all its components either carry an initialization
10897 -- expression or have a type that is fully default initialized. The
10898 -- parent type of a type extension must be fully default initialized.
10900 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
10902 -- Inspect all entities defined in the scope of the type, looking for
10903 -- uninitialized components.
10905 Comp
:= First_Entity
(Typ
);
10906 while Present
(Comp
) loop
10907 if Ekind
(Comp
) = E_Component
10908 and then Comes_From_Source
(Comp
)
10909 and then No
(Expression
(Parent
(Comp
)))
10910 and then not Has_Full_Default_Initialization
(Etype
(Comp
))
10915 Next_Entity
(Comp
);
10918 -- Ensure that the parent type of a type extension is fully default
10921 if Etype
(Typ
) /= Typ
10922 and then not Has_Full_Default_Initialization
(Etype
(Typ
))
10927 -- If we get here, then all components and parent portion are fully
10928 -- default initialized.
10932 -- A task type is fully default initialized by default
10934 elsif Is_Task_Type
(Typ
) then
10937 -- Otherwise the type is not fully default initialized
10942 end Has_Full_Default_Initialization
;
10944 -----------------------------------------------
10945 -- Has_Fully_Default_Initializing_DIC_Pragma --
10946 -----------------------------------------------
10948 function Has_Fully_Default_Initializing_DIC_Pragma
10949 (Typ
: Entity_Id
) return Boolean
10955 -- A type that inherits pragma Default_Initial_Condition from a parent
10956 -- type is automatically fully default initialized.
10958 if Has_Inherited_DIC
(Typ
) then
10961 -- Otherwise the type is fully default initialized only when the pragma
10962 -- appears without an argument, or the argument is non-null.
10964 elsif Has_Own_DIC
(Typ
) then
10965 Prag
:= Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
10966 pragma Assert
(Present
(Prag
));
10967 Args
:= Pragma_Argument_Associations
(Prag
);
10969 -- The pragma appears without an argument in which case it defaults
10975 -- The pragma appears with a non-null expression
10977 elsif Nkind
(Get_Pragma_Arg
(First
(Args
))) /= N_Null
then
10983 end Has_Fully_Default_Initializing_DIC_Pragma
;
10985 --------------------
10986 -- Has_Infinities --
10987 --------------------
10989 function Has_Infinities
(E
: Entity_Id
) return Boolean is
10992 Is_Floating_Point_Type
(E
)
10993 and then Nkind
(Scalar_Range
(E
)) = N_Range
10994 and then Includes_Infinities
(Scalar_Range
(E
));
10995 end Has_Infinities
;
10997 --------------------
10998 -- Has_Interfaces --
10999 --------------------
11001 function Has_Interfaces
11003 Use_Full_View
: Boolean := True) return Boolean
11005 Typ
: Entity_Id
:= Base_Type
(T
);
11008 -- Handle concurrent types
11010 if Is_Concurrent_Type
(Typ
) then
11011 Typ
:= Corresponding_Record_Type
(Typ
);
11014 if not Present
(Typ
)
11015 or else not Is_Record_Type
(Typ
)
11016 or else not Is_Tagged_Type
(Typ
)
11021 -- Handle private types
11023 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
11024 Typ
:= Full_View
(Typ
);
11027 -- Handle concurrent record types
11029 if Is_Concurrent_Record_Type
(Typ
)
11030 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
11036 if Is_Interface
(Typ
)
11038 (Is_Record_Type
(Typ
)
11039 and then Present
(Interfaces
(Typ
))
11040 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
11045 exit when Etype
(Typ
) = Typ
11047 -- Handle private types
11049 or else (Present
(Full_View
(Etype
(Typ
)))
11050 and then Full_View
(Etype
(Typ
)) = Typ
)
11052 -- Protect frontend against wrong sources with cyclic derivations
11054 or else Etype
(Typ
) = T
;
11056 -- Climb to the ancestor type handling private types
11058 if Present
(Full_View
(Etype
(Typ
))) then
11059 Typ
:= Full_View
(Etype
(Typ
));
11061 Typ
:= Etype
(Typ
);
11066 end Has_Interfaces
;
11068 --------------------------
11069 -- Has_Max_Queue_Length --
11070 --------------------------
11072 function Has_Max_Queue_Length
(Id
: Entity_Id
) return Boolean is
11075 Ekind
(Id
) = E_Entry
11076 and then Present
(Get_Pragma
(Id
, Pragma_Max_Queue_Length
));
11077 end Has_Max_Queue_Length
;
11079 ---------------------------------
11080 -- Has_No_Obvious_Side_Effects --
11081 ---------------------------------
11083 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
11085 -- For now handle literals, constants, and non-volatile variables and
11086 -- expressions combining these with operators or short circuit forms.
11088 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
11091 elsif Nkind
(N
) = N_Character_Literal
then
11094 elsif Nkind
(N
) in N_Unary_Op
then
11095 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
11097 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
11098 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
11100 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
11102 elsif Nkind
(N
) = N_Expression_With_Actions
11103 and then Is_Empty_List
(Actions
(N
))
11105 return Has_No_Obvious_Side_Effects
(Expression
(N
));
11107 elsif Nkind
(N
) in N_Has_Entity
then
11108 return Present
(Entity
(N
))
11109 and then Ekind_In
(Entity
(N
), E_Variable
,
11111 E_Enumeration_Literal
,
11114 E_In_Out_Parameter
)
11115 and then not Is_Volatile
(Entity
(N
));
11120 end Has_No_Obvious_Side_Effects
;
11122 -----------------------------
11123 -- Has_Non_Null_Refinement --
11124 -----------------------------
11126 function Has_Non_Null_Refinement
(Id
: Entity_Id
) return Boolean is
11127 Constits
: Elist_Id
;
11130 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
11131 Constits
:= Refinement_Constituents
(Id
);
11133 -- For a refinement to be non-null, the first constituent must be
11134 -- anything other than null.
11138 and then Nkind
(Node
(First_Elmt
(Constits
))) /= N_Null
;
11139 end Has_Non_Null_Refinement
;
11141 -----------------------------
11142 -- Has_Non_Null_Statements --
11143 -----------------------------
11145 function Has_Non_Null_Statements
(L
: List_Id
) return Boolean is
11149 if Is_Non_Empty_List
(L
) then
11153 if Nkind
(Node
) /= N_Null_Statement
then
11158 exit when Node
= Empty
;
11163 end Has_Non_Null_Statements
;
11165 ----------------------------------
11166 -- Has_Non_Trivial_Precondition --
11167 ----------------------------------
11169 function Has_Non_Trivial_Precondition
(Subp
: Entity_Id
) return Boolean is
11170 Pre
: constant Node_Id
:= Find_Aspect
(Subp
, Aspect_Pre
);
11175 and then Class_Present
(Pre
)
11176 and then not Is_Entity_Name
(Expression
(Pre
));
11177 end Has_Non_Trivial_Precondition
;
11179 -------------------
11180 -- Has_Null_Body --
11181 -------------------
11183 function Has_Null_Body
(Proc_Id
: Entity_Id
) return Boolean is
11184 Body_Id
: Entity_Id
;
11191 Spec
:= Parent
(Proc_Id
);
11192 Decl
:= Parent
(Spec
);
11194 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11196 if Nkind
(Spec
) = N_Procedure_Specification
11197 and then Nkind
(Decl
) = N_Subprogram_Declaration
11199 Body_Id
:= Corresponding_Body
(Decl
);
11201 -- The body acts as a spec
11204 Body_Id
:= Proc_Id
;
11207 -- The body will be generated later
11209 if No
(Body_Id
) then
11213 Spec
:= Parent
(Body_Id
);
11214 Decl
:= Parent
(Spec
);
11217 (Nkind
(Spec
) = N_Procedure_Specification
11218 and then Nkind
(Decl
) = N_Subprogram_Body
);
11220 Stmt1
:= First
(Statements
(Handled_Statement_Sequence
(Decl
)));
11222 -- Look for a null statement followed by an optional return
11225 if Nkind
(Stmt1
) = N_Null_Statement
then
11226 Stmt2
:= Next
(Stmt1
);
11228 if Present
(Stmt2
) then
11229 return Nkind
(Stmt2
) = N_Simple_Return_Statement
;
11238 ------------------------
11239 -- Has_Null_Exclusion --
11240 ------------------------
11242 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
11245 when N_Access_Definition
11246 | N_Access_Function_Definition
11247 | N_Access_Procedure_Definition
11248 | N_Access_To_Object_Definition
11250 | N_Derived_Type_Definition
11251 | N_Function_Specification
11252 | N_Subtype_Declaration
11254 return Null_Exclusion_Present
(N
);
11256 when N_Component_Definition
11257 | N_Formal_Object_Declaration
11258 | N_Object_Renaming_Declaration
11260 if Present
(Subtype_Mark
(N
)) then
11261 return Null_Exclusion_Present
(N
);
11262 else pragma Assert
(Present
(Access_Definition
(N
)));
11263 return Null_Exclusion_Present
(Access_Definition
(N
));
11266 when N_Discriminant_Specification
=>
11267 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
11268 return Null_Exclusion_Present
(Discriminant_Type
(N
));
11270 return Null_Exclusion_Present
(N
);
11273 when N_Object_Declaration
=>
11274 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
11275 return Null_Exclusion_Present
(Object_Definition
(N
));
11277 return Null_Exclusion_Present
(N
);
11280 when N_Parameter_Specification
=>
11281 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
11282 return Null_Exclusion_Present
(Parameter_Type
(N
));
11284 return Null_Exclusion_Present
(N
);
11290 end Has_Null_Exclusion
;
11292 ------------------------
11293 -- Has_Null_Extension --
11294 ------------------------
11296 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
11297 B
: constant Entity_Id
:= Base_Type
(T
);
11302 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
11303 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
11305 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
11307 if Present
(Ext
) then
11308 if Null_Present
(Ext
) then
11311 Comps
:= Component_List
(Ext
);
11313 -- The null component list is rewritten during analysis to
11314 -- include the parent component. Any other component indicates
11315 -- that the extension was not originally null.
11317 return Null_Present
(Comps
)
11318 or else No
(Next
(First
(Component_Items
(Comps
))));
11327 end Has_Null_Extension
;
11329 -------------------------
11330 -- Has_Null_Refinement --
11331 -------------------------
11333 function Has_Null_Refinement
(Id
: Entity_Id
) return Boolean is
11334 Constits
: Elist_Id
;
11337 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
11338 Constits
:= Refinement_Constituents
(Id
);
11340 -- For a refinement to be null, the state's sole constituent must be a
11345 and then Nkind
(Node
(First_Elmt
(Constits
))) = N_Null
;
11346 end Has_Null_Refinement
;
11348 -------------------------------
11349 -- Has_Overriding_Initialize --
11350 -------------------------------
11352 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
11353 BT
: constant Entity_Id
:= Base_Type
(T
);
11357 if Is_Controlled
(BT
) then
11358 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
11361 elsif Present
(Primitive_Operations
(BT
)) then
11362 P
:= First_Elmt
(Primitive_Operations
(BT
));
11363 while Present
(P
) loop
11365 Init
: constant Entity_Id
:= Node
(P
);
11366 Formal
: constant Entity_Id
:= First_Formal
(Init
);
11368 if Ekind
(Init
) = E_Procedure
11369 and then Chars
(Init
) = Name_Initialize
11370 and then Comes_From_Source
(Init
)
11371 and then Present
(Formal
)
11372 and then Etype
(Formal
) = BT
11373 and then No
(Next_Formal
(Formal
))
11374 and then (Ada_Version
< Ada_2012
11375 or else not Null_Present
(Parent
(Init
)))
11385 -- Here if type itself does not have a non-null Initialize operation:
11386 -- check immediate ancestor.
11388 if Is_Derived_Type
(BT
)
11389 and then Has_Overriding_Initialize
(Etype
(BT
))
11396 end Has_Overriding_Initialize
;
11398 --------------------------------------
11399 -- Has_Preelaborable_Initialization --
11400 --------------------------------------
11402 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
11405 procedure Check_Components
(E
: Entity_Id
);
11406 -- Check component/discriminant chain, sets Has_PE False if a component
11407 -- or discriminant does not meet the preelaborable initialization rules.
11409 ----------------------
11410 -- Check_Components --
11411 ----------------------
11413 procedure Check_Components
(E
: Entity_Id
) is
11418 -- Loop through entities of record or protected type
11421 while Present
(Ent
) loop
11423 -- We are interested only in components and discriminants
11427 case Ekind
(Ent
) is
11428 when E_Component
=>
11430 -- Get default expression if any. If there is no declaration
11431 -- node, it means we have an internal entity. The parent and
11432 -- tag fields are examples of such entities. For such cases,
11433 -- we just test the type of the entity.
11435 if Present
(Declaration_Node
(Ent
)) then
11436 Exp
:= Expression
(Declaration_Node
(Ent
));
11439 when E_Discriminant
=>
11441 -- Note: for a renamed discriminant, the Declaration_Node
11442 -- may point to the one from the ancestor, and have a
11443 -- different expression, so use the proper attribute to
11444 -- retrieve the expression from the derived constraint.
11446 Exp
:= Discriminant_Default_Value
(Ent
);
11449 goto Check_Next_Entity
;
11452 -- A component has PI if it has no default expression and the
11453 -- component type has PI.
11456 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
11461 -- Require the default expression to be preelaborable
11463 elsif not Is_Preelaborable_Construct
(Exp
) then
11468 <<Check_Next_Entity
>>
11471 end Check_Components
;
11473 -- Start of processing for Has_Preelaborable_Initialization
11476 -- Immediate return if already marked as known preelaborable init. This
11477 -- covers types for which this function has already been called once
11478 -- and returned True (in which case the result is cached), and also
11479 -- types to which a pragma Preelaborable_Initialization applies.
11481 if Known_To_Have_Preelab_Init
(E
) then
11485 -- If the type is a subtype representing a generic actual type, then
11486 -- test whether its base type has preelaborable initialization since
11487 -- the subtype representing the actual does not inherit this attribute
11488 -- from the actual or formal. (but maybe it should???)
11490 if Is_Generic_Actual_Type
(E
) then
11491 return Has_Preelaborable_Initialization
(Base_Type
(E
));
11494 -- All elementary types have preelaborable initialization
11496 if Is_Elementary_Type
(E
) then
11499 -- Array types have PI if the component type has PI
11501 elsif Is_Array_Type
(E
) then
11502 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
11504 -- A derived type has preelaborable initialization if its parent type
11505 -- has preelaborable initialization and (in the case of a derived record
11506 -- extension) if the non-inherited components all have preelaborable
11507 -- initialization. However, a user-defined controlled type with an
11508 -- overriding Initialize procedure does not have preelaborable
11511 elsif Is_Derived_Type
(E
) then
11513 -- If the derived type is a private extension then it doesn't have
11514 -- preelaborable initialization.
11516 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
11520 -- First check whether ancestor type has preelaborable initialization
11522 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
11524 -- If OK, check extension components (if any)
11526 if Has_PE
and then Is_Record_Type
(E
) then
11527 Check_Components
(First_Entity
(E
));
11530 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11531 -- with a user defined Initialize procedure does not have PI. If
11532 -- the type is untagged, the control primitives come from a component
11533 -- that has already been checked.
11536 and then Is_Controlled
(E
)
11537 and then Is_Tagged_Type
(E
)
11538 and then Has_Overriding_Initialize
(E
)
11543 -- Private types not derived from a type having preelaborable init and
11544 -- that are not marked with pragma Preelaborable_Initialization do not
11545 -- have preelaborable initialization.
11547 elsif Is_Private_Type
(E
) then
11550 -- Record type has PI if it is non private and all components have PI
11552 elsif Is_Record_Type
(E
) then
11554 Check_Components
(First_Entity
(E
));
11556 -- Protected types must not have entries, and components must meet
11557 -- same set of rules as for record components.
11559 elsif Is_Protected_Type
(E
) then
11560 if Has_Entries
(E
) then
11564 Check_Components
(First_Entity
(E
));
11565 Check_Components
(First_Private_Entity
(E
));
11568 -- Type System.Address always has preelaborable initialization
11570 elsif Is_RTE
(E
, RE_Address
) then
11573 -- In all other cases, type does not have preelaborable initialization
11579 -- If type has preelaborable initialization, cache result
11582 Set_Known_To_Have_Preelab_Init
(E
);
11586 end Has_Preelaborable_Initialization
;
11592 function Has_Prefix
(N
: Node_Id
) return Boolean is
11595 Nkind_In
(N
, N_Attribute_Reference
,
11597 N_Explicit_Dereference
,
11598 N_Indexed_Component
,
11600 N_Selected_Component
,
11604 ---------------------------
11605 -- Has_Private_Component --
11606 ---------------------------
11608 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
11609 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
11610 Component
: Entity_Id
;
11613 if Error_Posted
(Type_Id
)
11614 or else Error_Posted
(Btype
)
11619 if Is_Class_Wide_Type
(Btype
) then
11620 Btype
:= Root_Type
(Btype
);
11623 if Is_Private_Type
(Btype
) then
11625 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
11628 if No
(Full_View
(Btype
)) then
11629 return not Is_Generic_Type
(Btype
)
11631 not Is_Generic_Type
(Root_Type
(Btype
));
11633 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
11636 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
11640 elsif Is_Array_Type
(Btype
) then
11641 return Has_Private_Component
(Component_Type
(Btype
));
11643 elsif Is_Record_Type
(Btype
) then
11644 Component
:= First_Component
(Btype
);
11645 while Present
(Component
) loop
11646 if Has_Private_Component
(Etype
(Component
)) then
11650 Next_Component
(Component
);
11655 elsif Is_Protected_Type
(Btype
)
11656 and then Present
(Corresponding_Record_Type
(Btype
))
11658 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
11663 end Has_Private_Component
;
11665 ----------------------
11666 -- Has_Signed_Zeros --
11667 ----------------------
11669 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
11671 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
11672 end Has_Signed_Zeros
;
11674 ------------------------------
11675 -- Has_Significant_Contract --
11676 ------------------------------
11678 function Has_Significant_Contract
(Subp_Id
: Entity_Id
) return Boolean is
11679 Subp_Nam
: constant Name_Id
:= Chars
(Subp_Id
);
11682 -- _Finalizer procedure
11684 if Subp_Nam
= Name_uFinalizer
then
11687 -- _Postconditions procedure
11689 elsif Subp_Nam
= Name_uPostconditions
then
11692 -- Predicate function
11694 elsif Ekind
(Subp_Id
) = E_Function
11695 and then Is_Predicate_Function
(Subp_Id
)
11701 elsif Get_TSS_Name
(Subp_Id
) /= TSS_Null
then
11707 end Has_Significant_Contract
;
11709 -----------------------------
11710 -- Has_Static_Array_Bounds --
11711 -----------------------------
11713 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
11714 All_Static
: Boolean;
11718 Examine_Array_Bounds
(Typ
, All_Static
, Dummy
);
11721 end Has_Static_Array_Bounds
;
11723 ---------------------------------------
11724 -- Has_Static_Non_Empty_Array_Bounds --
11725 ---------------------------------------
11727 function Has_Static_Non_Empty_Array_Bounds
(Typ
: Node_Id
) return Boolean is
11728 All_Static
: Boolean;
11729 Has_Empty
: Boolean;
11732 Examine_Array_Bounds
(Typ
, All_Static
, Has_Empty
);
11734 return All_Static
and not Has_Empty
;
11735 end Has_Static_Non_Empty_Array_Bounds
;
11741 function Has_Stream
(T
: Entity_Id
) return Boolean is
11748 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
11751 elsif Is_Array_Type
(T
) then
11752 return Has_Stream
(Component_Type
(T
));
11754 elsif Is_Record_Type
(T
) then
11755 E
:= First_Component
(T
);
11756 while Present
(E
) loop
11757 if Has_Stream
(Etype
(E
)) then
11760 Next_Component
(E
);
11766 elsif Is_Private_Type
(T
) then
11767 return Has_Stream
(Underlying_Type
(T
));
11778 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
11780 Get_Name_String
(Chars
(E
));
11781 return Name_Buffer
(Name_Len
) = Suffix
;
11788 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
11790 Get_Name_String
(Chars
(E
));
11791 Add_Char_To_Name_Buffer
(Suffix
);
11795 -------------------
11796 -- Remove_Suffix --
11797 -------------------
11799 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
11801 pragma Assert
(Has_Suffix
(E
, Suffix
));
11802 Get_Name_String
(Chars
(E
));
11803 Name_Len
:= Name_Len
- 1;
11807 ----------------------------------
11808 -- Replace_Null_By_Null_Address --
11809 ----------------------------------
11811 procedure Replace_Null_By_Null_Address
(N
: Node_Id
) is
11812 procedure Replace_Null_Operand
(Op
: Node_Id
; Other_Op
: Node_Id
);
11813 -- Replace operand Op with a reference to Null_Address when the operand
11814 -- denotes a null Address. Other_Op denotes the other operand.
11816 --------------------------
11817 -- Replace_Null_Operand --
11818 --------------------------
11820 procedure Replace_Null_Operand
(Op
: Node_Id
; Other_Op
: Node_Id
) is
11822 -- Check the type of the complementary operand since the N_Null node
11823 -- has not been decorated yet.
11825 if Nkind
(Op
) = N_Null
11826 and then Is_Descendant_Of_Address
(Etype
(Other_Op
))
11828 Rewrite
(Op
, New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(Op
)));
11830 end Replace_Null_Operand
;
11832 -- Start of processing for Replace_Null_By_Null_Address
11835 pragma Assert
(Relaxed_RM_Semantics
);
11836 pragma Assert
(Nkind_In
(N
, N_Null
,
11844 if Nkind
(N
) = N_Null
then
11845 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
11849 L
: constant Node_Id
:= Left_Opnd
(N
);
11850 R
: constant Node_Id
:= Right_Opnd
(N
);
11853 Replace_Null_Operand
(L
, Other_Op
=> R
);
11854 Replace_Null_Operand
(R
, Other_Op
=> L
);
11857 end Replace_Null_By_Null_Address
;
11859 --------------------------
11860 -- Has_Tagged_Component --
11861 --------------------------
11863 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
11867 if Is_Private_Type
(Typ
) and then Present
(Underlying_Type
(Typ
)) then
11868 return Has_Tagged_Component
(Underlying_Type
(Typ
));
11870 elsif Is_Array_Type
(Typ
) then
11871 return Has_Tagged_Component
(Component_Type
(Typ
));
11873 elsif Is_Tagged_Type
(Typ
) then
11876 elsif Is_Record_Type
(Typ
) then
11877 Comp
:= First_Component
(Typ
);
11878 while Present
(Comp
) loop
11879 if Has_Tagged_Component
(Etype
(Comp
)) then
11883 Next_Component
(Comp
);
11891 end Has_Tagged_Component
;
11893 -----------------------------
11894 -- Has_Undefined_Reference --
11895 -----------------------------
11897 function Has_Undefined_Reference
(Expr
: Node_Id
) return Boolean is
11898 Has_Undef_Ref
: Boolean := False;
11899 -- Flag set when expression Expr contains at least one undefined
11902 function Is_Undefined_Reference
(N
: Node_Id
) return Traverse_Result
;
11903 -- Determine whether N denotes a reference and if it does, whether it is
11906 ----------------------------
11907 -- Is_Undefined_Reference --
11908 ----------------------------
11910 function Is_Undefined_Reference
(N
: Node_Id
) return Traverse_Result
is
11912 if Is_Entity_Name
(N
)
11913 and then Present
(Entity
(N
))
11914 and then Entity
(N
) = Any_Id
11916 Has_Undef_Ref
:= True;
11921 end Is_Undefined_Reference
;
11923 procedure Find_Undefined_References
is
11924 new Traverse_Proc
(Is_Undefined_Reference
);
11926 -- Start of processing for Has_Undefined_Reference
11929 Find_Undefined_References
(Expr
);
11931 return Has_Undef_Ref
;
11932 end Has_Undefined_Reference
;
11934 ----------------------------
11935 -- Has_Volatile_Component --
11936 ----------------------------
11938 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
11942 if Has_Volatile_Components
(Typ
) then
11945 elsif Is_Array_Type
(Typ
) then
11946 return Is_Volatile
(Component_Type
(Typ
));
11948 elsif Is_Record_Type
(Typ
) then
11949 Comp
:= First_Component
(Typ
);
11950 while Present
(Comp
) loop
11951 if Is_Volatile_Object
(Comp
) then
11955 Comp
:= Next_Component
(Comp
);
11960 end Has_Volatile_Component
;
11962 -------------------------
11963 -- Implementation_Kind --
11964 -------------------------
11966 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
11967 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
11970 pragma Assert
(Present
(Impl_Prag
));
11971 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
11972 return Chars
(Get_Pragma_Arg
(Arg
));
11973 end Implementation_Kind
;
11975 --------------------------
11976 -- Implements_Interface --
11977 --------------------------
11979 function Implements_Interface
11980 (Typ_Ent
: Entity_Id
;
11981 Iface_Ent
: Entity_Id
;
11982 Exclude_Parents
: Boolean := False) return Boolean
11984 Ifaces_List
: Elist_Id
;
11986 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
11987 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
11990 if Is_Class_Wide_Type
(Typ
) then
11991 Typ
:= Root_Type
(Typ
);
11994 if not Has_Interfaces
(Typ
) then
11998 if Is_Class_Wide_Type
(Iface
) then
11999 Iface
:= Root_Type
(Iface
);
12002 Collect_Interfaces
(Typ
, Ifaces_List
);
12004 Elmt
:= First_Elmt
(Ifaces_List
);
12005 while Present
(Elmt
) loop
12006 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
12007 and then Exclude_Parents
12011 elsif Node
(Elmt
) = Iface
then
12019 end Implements_Interface
;
12021 ------------------------------------
12022 -- In_Assertion_Expression_Pragma --
12023 ------------------------------------
12025 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
12027 Prag
: Node_Id
:= Empty
;
12030 -- Climb the parent chain looking for an enclosing pragma
12033 while Present
(Par
) loop
12034 if Nkind
(Par
) = N_Pragma
then
12038 -- Precondition-like pragmas are expanded into if statements, check
12039 -- the original node instead.
12041 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
12042 Prag
:= Original_Node
(Par
);
12045 -- The expansion of attribute 'Old generates a constant to capture
12046 -- the result of the prefix. If the parent traversal reaches
12047 -- one of these constants, then the node technically came from a
12048 -- postcondition-like pragma. Note that the Ekind is not tested here
12049 -- because N may be the expression of an object declaration which is
12050 -- currently being analyzed. Such objects carry Ekind of E_Void.
12052 elsif Nkind
(Par
) = N_Object_Declaration
12053 and then Constant_Present
(Par
)
12054 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
12058 -- Prevent the search from going too far
12060 elsif Is_Body_Or_Package_Declaration
(Par
) then
12064 Par
:= Parent
(Par
);
12069 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
12070 end In_Assertion_Expression_Pragma
;
12072 ----------------------
12073 -- In_Generic_Scope --
12074 ----------------------
12076 function In_Generic_Scope
(E
: Entity_Id
) return Boolean is
12081 while Present
(S
) and then S
/= Standard_Standard
loop
12082 if Is_Generic_Unit
(S
) then
12090 end In_Generic_Scope
;
12096 function In_Instance
return Boolean is
12097 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
12101 S
:= Current_Scope
;
12102 while Present
(S
) and then S
/= Standard_Standard
loop
12103 if Is_Generic_Instance
(S
) then
12105 -- A child instance is always compiled in the context of a parent
12106 -- instance. Nevertheless, the actuals are not analyzed in an
12107 -- instance context. We detect this case by examining the current
12108 -- compilation unit, which must be a child instance, and checking
12109 -- that it is not currently on the scope stack.
12111 if Is_Child_Unit
(Curr_Unit
)
12112 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
12113 N_Package_Instantiation
12114 and then not In_Open_Scopes
(Curr_Unit
)
12128 ----------------------
12129 -- In_Instance_Body --
12130 ----------------------
12132 function In_Instance_Body
return Boolean is
12136 S
:= Current_Scope
;
12137 while Present
(S
) and then S
/= Standard_Standard
loop
12138 if Ekind_In
(S
, E_Function
, E_Procedure
)
12139 and then Is_Generic_Instance
(S
)
12143 elsif Ekind
(S
) = E_Package
12144 and then In_Package_Body
(S
)
12145 and then Is_Generic_Instance
(S
)
12154 end In_Instance_Body
;
12156 -----------------------------
12157 -- In_Instance_Not_Visible --
12158 -----------------------------
12160 function In_Instance_Not_Visible
return Boolean is
12164 S
:= Current_Scope
;
12165 while Present
(S
) and then S
/= Standard_Standard
loop
12166 if Ekind_In
(S
, E_Function
, E_Procedure
)
12167 and then Is_Generic_Instance
(S
)
12171 elsif Ekind
(S
) = E_Package
12172 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
12173 and then Is_Generic_Instance
(S
)
12182 end In_Instance_Not_Visible
;
12184 ------------------------------
12185 -- In_Instance_Visible_Part --
12186 ------------------------------
12188 function In_Instance_Visible_Part
12189 (Id
: Entity_Id
:= Current_Scope
) return Boolean
12195 while Present
(Inst
) and then Inst
/= Standard_Standard
loop
12196 if Ekind
(Inst
) = E_Package
12197 and then Is_Generic_Instance
(Inst
)
12198 and then not In_Package_Body
(Inst
)
12199 and then not In_Private_Part
(Inst
)
12204 Inst
:= Scope
(Inst
);
12208 end In_Instance_Visible_Part
;
12210 ---------------------
12211 -- In_Package_Body --
12212 ---------------------
12214 function In_Package_Body
return Boolean is
12218 S
:= Current_Scope
;
12219 while Present
(S
) and then S
/= Standard_Standard
loop
12220 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
12228 end In_Package_Body
;
12230 --------------------------
12231 -- In_Pragma_Expression --
12232 --------------------------
12234 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
12241 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
12247 end In_Pragma_Expression
;
12249 ---------------------------
12250 -- In_Pre_Post_Condition --
12251 ---------------------------
12253 function In_Pre_Post_Condition
(N
: Node_Id
) return Boolean is
12255 Prag
: Node_Id
:= Empty
;
12256 Prag_Id
: Pragma_Id
;
12259 -- Climb the parent chain looking for an enclosing pragma
12262 while Present
(Par
) loop
12263 if Nkind
(Par
) = N_Pragma
then
12267 -- Prevent the search from going too far
12269 elsif Is_Body_Or_Package_Declaration
(Par
) then
12273 Par
:= Parent
(Par
);
12276 if Present
(Prag
) then
12277 Prag_Id
:= Get_Pragma_Id
(Prag
);
12280 Prag_Id
= Pragma_Post
12281 or else Prag_Id
= Pragma_Post_Class
12282 or else Prag_Id
= Pragma_Postcondition
12283 or else Prag_Id
= Pragma_Pre
12284 or else Prag_Id
= Pragma_Pre_Class
12285 or else Prag_Id
= Pragma_Precondition
;
12287 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12292 end In_Pre_Post_Condition
;
12294 -------------------------------------
12295 -- In_Reverse_Storage_Order_Object --
12296 -------------------------------------
12298 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
12300 Btyp
: Entity_Id
:= Empty
;
12303 -- Climb up indexed components
12307 case Nkind
(Pref
) is
12308 when N_Selected_Component
=>
12309 Pref
:= Prefix
(Pref
);
12312 when N_Indexed_Component
=>
12313 Pref
:= Prefix
(Pref
);
12321 if Present
(Pref
) then
12322 Btyp
:= Base_Type
(Etype
(Pref
));
12325 return Present
(Btyp
)
12326 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
12327 and then Reverse_Storage_Order
(Btyp
);
12328 end In_Reverse_Storage_Order_Object
;
12330 ------------------------------
12331 -- In_Same_Declarative_Part --
12332 ------------------------------
12334 function In_Same_Declarative_Part
12335 (Context
: Node_Id
;
12336 N
: Node_Id
) return Boolean
12338 Cont
: Node_Id
:= Context
;
12342 if Nkind
(Cont
) = N_Compilation_Unit_Aux
then
12343 Cont
:= Parent
(Cont
);
12347 while Present
(Nod
) loop
12351 elsif Nkind_In
(Nod
, N_Accept_Statement
,
12353 N_Compilation_Unit
,
12356 N_Package_Declaration
,
12363 elsif Nkind
(Nod
) = N_Subunit
then
12364 Nod
:= Corresponding_Stub
(Nod
);
12367 Nod
:= Parent
(Nod
);
12372 end In_Same_Declarative_Part
;
12374 --------------------------------------
12375 -- In_Subprogram_Or_Concurrent_Unit --
12376 --------------------------------------
12378 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
12383 -- Use scope chain to check successively outer scopes
12385 E
:= Current_Scope
;
12389 if K
in Subprogram_Kind
12390 or else K
in Concurrent_Kind
12391 or else K
in Generic_Subprogram_Kind
12395 elsif E
= Standard_Standard
then
12401 end In_Subprogram_Or_Concurrent_Unit
;
12407 function In_Subtree
(N
: Node_Id
; Root
: Node_Id
) return Boolean is
12412 while Present
(Curr
) loop
12413 if Curr
= Root
then
12417 Curr
:= Parent
(Curr
);
12427 function In_Subtree
12430 Root2
: Node_Id
) return Boolean
12436 while Present
(Curr
) loop
12437 if Curr
= Root1
or else Curr
= Root2
then
12441 Curr
:= Parent
(Curr
);
12447 ---------------------
12448 -- In_Visible_Part --
12449 ---------------------
12451 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
12453 return Is_Package_Or_Generic_Package
(Scope_Id
)
12454 and then In_Open_Scopes
(Scope_Id
)
12455 and then not In_Package_Body
(Scope_Id
)
12456 and then not In_Private_Part
(Scope_Id
);
12457 end In_Visible_Part
;
12459 --------------------------------
12460 -- Incomplete_Or_Partial_View --
12461 --------------------------------
12463 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
12464 function Inspect_Decls
12466 Taft
: Boolean := False) return Entity_Id
;
12467 -- Check whether a declarative region contains the incomplete or partial
12470 -------------------
12471 -- Inspect_Decls --
12472 -------------------
12474 function Inspect_Decls
12476 Taft
: Boolean := False) return Entity_Id
12482 Decl
:= First
(Decls
);
12483 while Present
(Decl
) loop
12486 -- The partial view of a Taft-amendment type is an incomplete
12490 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
12491 Match
:= Defining_Identifier
(Decl
);
12494 -- Otherwise look for a private type whose full view matches the
12495 -- input type. Note that this checks full_type_declaration nodes
12496 -- to account for derivations from a private type where the type
12497 -- declaration hold the partial view and the full view is an
12500 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
12501 N_Private_Extension_Declaration
,
12502 N_Private_Type_Declaration
)
12504 Match
:= Defining_Identifier
(Decl
);
12507 -- Guard against unanalyzed entities
12510 and then Is_Type
(Match
)
12511 and then Present
(Full_View
(Match
))
12512 and then Full_View
(Match
) = Id
12527 -- Start of processing for Incomplete_Or_Partial_View
12530 -- Deferred constant or incomplete type case
12532 Prev
:= Current_Entity_In_Scope
(Id
);
12535 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
12536 and then Present
(Full_View
(Prev
))
12537 and then Full_View
(Prev
) = Id
12542 -- Private or Taft amendment type case
12545 Pkg
: constant Entity_Id
:= Scope
(Id
);
12546 Pkg_Decl
: Node_Id
:= Pkg
;
12550 and then Ekind_In
(Pkg
, E_Generic_Package
, E_Package
)
12552 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
12553 Pkg_Decl
:= Parent
(Pkg_Decl
);
12556 -- It is knows that Typ has a private view, look for it in the
12557 -- visible declarations of the enclosing scope. A special case
12558 -- of this is when the two views have been exchanged - the full
12559 -- appears earlier than the private.
12561 if Has_Private_Declaration
(Id
) then
12562 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
12564 -- Exchanged view case, look in the private declarations
12567 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
12572 -- Otherwise if this is the package body, then Typ is a potential
12573 -- Taft amendment type. The incomplete view should be located in
12574 -- the private declarations of the enclosing scope.
12576 elsif In_Package_Body
(Pkg
) then
12577 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
12582 -- The type has no incomplete or private view
12585 end Incomplete_Or_Partial_View
;
12587 ---------------------------------------
12588 -- Incomplete_View_From_Limited_With --
12589 ---------------------------------------
12591 function Incomplete_View_From_Limited_With
12592 (Typ
: Entity_Id
) return Entity_Id
12595 -- It might make sense to make this an attribute in Einfo, and set it
12596 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12597 -- slots for new attributes, and it seems a bit simpler to just search
12598 -- the Limited_View (if it exists) for an incomplete type whose
12599 -- Non_Limited_View is Typ.
12601 if Ekind
(Scope
(Typ
)) = E_Package
12602 and then Present
(Limited_View
(Scope
(Typ
)))
12605 Ent
: Entity_Id
:= First_Entity
(Limited_View
(Scope
(Typ
)));
12607 while Present
(Ent
) loop
12608 if Ekind
(Ent
) in Incomplete_Kind
12609 and then Non_Limited_View
(Ent
) = Typ
12614 Ent
:= Next_Entity
(Ent
);
12620 end Incomplete_View_From_Limited_With
;
12622 ----------------------------------
12623 -- Indexed_Component_Bit_Offset --
12624 ----------------------------------
12626 function Indexed_Component_Bit_Offset
(N
: Node_Id
) return Uint
is
12627 Exp
: constant Node_Id
:= First
(Expressions
(N
));
12628 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
12629 Off
: constant Uint
:= Component_Size
(Typ
);
12633 -- Return early if the component size is not known or variable
12635 if Off
= No_Uint
or else Off
< Uint_0
then
12639 -- Deal with the degenerate case of an empty component
12641 if Off
= Uint_0
then
12645 -- Check that both the index value and the low bound are known
12647 if not Compile_Time_Known_Value
(Exp
) then
12651 Ind
:= First_Index
(Typ
);
12656 if Nkind
(Ind
) = N_Subtype_Indication
then
12657 Ind
:= Constraint
(Ind
);
12659 if Nkind
(Ind
) = N_Range_Constraint
then
12660 Ind
:= Range_Expression
(Ind
);
12664 if Nkind
(Ind
) /= N_Range
12665 or else not Compile_Time_Known_Value
(Low_Bound
(Ind
))
12670 -- Return the scaled offset
12672 return Off
* (Expr_Value
(Exp
) - Expr_Value
(Low_Bound
((Ind
))));
12673 end Indexed_Component_Bit_Offset
;
12675 ----------------------------
12676 -- Inherit_Rep_Item_Chain --
12677 ----------------------------
12679 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
12681 Next_Item
: Node_Id
;
12684 -- There are several inheritance scenarios to consider depending on
12685 -- whether both types have rep item chains and whether the destination
12686 -- type already inherits part of the source type's rep item chain.
12688 -- 1) The source type lacks a rep item chain
12689 -- From_Typ ---> Empty
12691 -- Typ --------> Item (or Empty)
12693 -- In this case inheritance cannot take place because there are no items
12696 -- 2) The destination type lacks a rep item chain
12697 -- From_Typ ---> Item ---> ...
12699 -- Typ --------> Empty
12701 -- Inheritance takes place by setting the First_Rep_Item of the
12702 -- destination type to the First_Rep_Item of the source type.
12703 -- From_Typ ---> Item ---> ...
12705 -- Typ -----------+
12707 -- 3.1) Both source and destination types have at least one rep item.
12708 -- The destination type does NOT inherit a rep item from the source
12710 -- From_Typ ---> Item ---> Item
12712 -- Typ --------> Item ---> Item
12714 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12715 -- of the destination type to the First_Rep_Item of the source type.
12716 -- From_Typ -------------------> Item ---> Item
12718 -- Typ --------> Item ---> Item --+
12720 -- 3.2) Both source and destination types have at least one rep item.
12721 -- The destination type DOES inherit part of the rep item chain of the
12723 -- From_Typ ---> Item ---> Item ---> Item
12725 -- Typ --------> Item ------+
12727 -- This rare case arises when the full view of a private extension must
12728 -- inherit the rep item chain from the full view of its parent type and
12729 -- the full view of the parent type contains extra rep items. Currently
12730 -- only invariants may lead to such form of inheritance.
12732 -- type From_Typ is tagged private
12733 -- with Type_Invariant'Class => Item_2;
12735 -- type Typ is new From_Typ with private
12736 -- with Type_Invariant => Item_4;
12738 -- At this point the rep item chains contain the following items
12740 -- From_Typ -----------> Item_2 ---> Item_3
12742 -- Typ --------> Item_4 --+
12744 -- The full views of both types may introduce extra invariants
12746 -- type From_Typ is tagged null record
12747 -- with Type_Invariant => Item_1;
12749 -- type Typ is new From_Typ with null record;
12751 -- The full view of Typ would have to inherit any new rep items added to
12752 -- the full view of From_Typ.
12754 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12756 -- Typ --------> Item_4 --+
12758 -- To achieve this form of inheritance, the destination type must first
12759 -- sever the link between its own rep chain and that of the source type,
12760 -- then inheritance 3.1 takes place.
12762 -- Case 1: The source type lacks a rep item chain
12764 if No
(First_Rep_Item
(From_Typ
)) then
12767 -- Case 2: The destination type lacks a rep item chain
12769 elsif No
(First_Rep_Item
(Typ
)) then
12770 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
12772 -- Case 3: Both the source and destination types have at least one rep
12773 -- item. Traverse the rep item chain of the destination type to find the
12778 Next_Item
:= First_Rep_Item
(Typ
);
12779 while Present
(Next_Item
) loop
12781 -- Detect a link between the destination type's rep chain and that
12782 -- of the source type. There are two possibilities:
12787 -- From_Typ ---> Item_1 --->
12789 -- Typ -----------+
12796 -- From_Typ ---> Item_1 ---> Item_2 --->
12798 -- Typ --------> Item_3 ------+
12802 if Has_Rep_Item
(From_Typ
, Next_Item
) then
12807 Next_Item
:= Next_Rep_Item
(Next_Item
);
12810 -- Inherit the source type's rep item chain
12812 if Present
(Item
) then
12813 Set_Next_Rep_Item
(Item
, First_Rep_Item
(From_Typ
));
12815 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
12818 end Inherit_Rep_Item_Chain
;
12820 ------------------------------------
12821 -- Inherits_From_Tagged_Full_View --
12822 ------------------------------------
12824 function Inherits_From_Tagged_Full_View
(Typ
: Entity_Id
) return Boolean is
12826 return Is_Private_Type
(Typ
)
12827 and then Present
(Full_View
(Typ
))
12828 and then Is_Private_Type
(Full_View
(Typ
))
12829 and then not Is_Tagged_Type
(Full_View
(Typ
))
12830 and then Present
(Underlying_Type
(Full_View
(Typ
)))
12831 and then Is_Tagged_Type
(Underlying_Type
(Full_View
(Typ
)));
12832 end Inherits_From_Tagged_Full_View
;
12834 ---------------------------------
12835 -- Insert_Explicit_Dereference --
12836 ---------------------------------
12838 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
12839 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
12840 Ent
: Entity_Id
:= Empty
;
12847 Save_Interps
(N
, New_Prefix
);
12850 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
12851 Prefix
=> New_Prefix
));
12853 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
12855 if Is_Overloaded
(New_Prefix
) then
12857 -- The dereference is also overloaded, and its interpretations are
12858 -- the designated types of the interpretations of the original node.
12860 Set_Etype
(N
, Any_Type
);
12862 Get_First_Interp
(New_Prefix
, I
, It
);
12863 while Present
(It
.Nam
) loop
12866 if Is_Access_Type
(T
) then
12867 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
12870 Get_Next_Interp
(I
, It
);
12876 -- Prefix is unambiguous: mark the original prefix (which might
12877 -- Come_From_Source) as a reference, since the new (relocated) one
12878 -- won't be taken into account.
12880 if Is_Entity_Name
(New_Prefix
) then
12881 Ent
:= Entity
(New_Prefix
);
12882 Pref
:= New_Prefix
;
12884 -- For a retrieval of a subcomponent of some composite object,
12885 -- retrieve the ultimate entity if there is one.
12887 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
12888 N_Indexed_Component
)
12890 Pref
:= Prefix
(New_Prefix
);
12891 while Present
(Pref
)
12892 and then Nkind_In
(Pref
, N_Selected_Component
,
12893 N_Indexed_Component
)
12895 Pref
:= Prefix
(Pref
);
12898 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
12899 Ent
:= Entity
(Pref
);
12903 -- Place the reference on the entity node
12905 if Present
(Ent
) then
12906 Generate_Reference
(Ent
, Pref
);
12909 end Insert_Explicit_Dereference
;
12911 ------------------------------------------
12912 -- Inspect_Deferred_Constant_Completion --
12913 ------------------------------------------
12915 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
12919 Decl
:= First
(Decls
);
12920 while Present
(Decl
) loop
12922 -- Deferred constant signature
12924 if Nkind
(Decl
) = N_Object_Declaration
12925 and then Constant_Present
(Decl
)
12926 and then No
(Expression
(Decl
))
12928 -- No need to check internally generated constants
12930 and then Comes_From_Source
(Decl
)
12932 -- The constant is not completed. A full object declaration or a
12933 -- pragma Import complete a deferred constant.
12935 and then not Has_Completion
(Defining_Identifier
(Decl
))
12938 ("constant declaration requires initialization expression",
12939 Defining_Identifier
(Decl
));
12942 Decl
:= Next
(Decl
);
12944 end Inspect_Deferred_Constant_Completion
;
12946 -------------------------------
12947 -- Install_Elaboration_Model --
12948 -------------------------------
12950 procedure Install_Elaboration_Model
(Unit_Id
: Entity_Id
) is
12951 function Find_Elaboration_Checks_Pragma
(L
: List_Id
) return Node_Id
;
12952 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
12953 -- Empty if there is no such pragma.
12955 ------------------------------------
12956 -- Find_Elaboration_Checks_Pragma --
12957 ------------------------------------
12959 function Find_Elaboration_Checks_Pragma
(L
: List_Id
) return Node_Id
is
12964 while Present
(Item
) loop
12965 if Nkind
(Item
) = N_Pragma
12966 and then Pragma_Name
(Item
) = Name_Elaboration_Checks
12975 end Find_Elaboration_Checks_Pragma
;
12984 -- Start of processing for Install_Elaboration_Model
12987 -- Nothing to do when the unit does not exist
12989 if No
(Unit_Id
) then
12993 Unit
:= Parent
(Unit_Declaration_Node
(Unit_Id
));
12995 -- Nothing to do when the unit is not a library unit
12997 if Nkind
(Unit
) /= N_Compilation_Unit
then
13001 Prag
:= Find_Elaboration_Checks_Pragma
(Context_Items
(Unit
));
13003 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13004 -- elaboration model as specified by the pragma.
13006 if Present
(Prag
) then
13007 Args
:= Pragma_Argument_Associations
(Prag
);
13009 -- Guard against an illegal pragma. The sole argument must be an
13010 -- identifier which specifies either Dynamic or Static model.
13012 if Present
(Args
) then
13013 Model
:= Get_Pragma_Arg
(First
(Args
));
13015 if Nkind
(Model
) = N_Identifier
then
13016 Dynamic_Elaboration_Checks
:= Chars
(Model
) = Name_Dynamic
;
13020 end Install_Elaboration_Model
;
13022 -----------------------------
13023 -- Install_Generic_Formals --
13024 -----------------------------
13026 procedure Install_Generic_Formals
(Subp_Id
: Entity_Id
) is
13030 pragma Assert
(Is_Generic_Subprogram
(Subp_Id
));
13032 E
:= First_Entity
(Subp_Id
);
13033 while Present
(E
) loop
13034 Install_Entity
(E
);
13037 end Install_Generic_Formals
;
13039 ------------------------
13040 -- Install_SPARK_Mode --
13041 ------------------------
13043 procedure Install_SPARK_Mode
(Mode
: SPARK_Mode_Type
; Prag
: Node_Id
) is
13045 SPARK_Mode
:= Mode
;
13046 SPARK_Mode_Pragma
:= Prag
;
13047 end Install_SPARK_Mode
;
13049 --------------------------
13050 -- Invalid_Scalar_Value --
13051 --------------------------
13053 function Invalid_Scalar_Value
13055 Scal_Typ
: Scalar_Id
) return Node_Id
13057 function Invalid_Binder_Value
return Node_Id
;
13058 -- Return a reference to the corresponding invalid value for type
13059 -- Scal_Typ as defined in unit System.Scalar_Values.
13061 function Invalid_Float_Value
return Node_Id
;
13062 -- Return the invalid value of float type Scal_Typ
13064 function Invalid_Integer_Value
return Node_Id
;
13065 -- Return the invalid value of integer type Scal_Typ
13067 procedure Set_Invalid_Binder_Values
;
13068 -- Set the contents of collection Invalid_Binder_Values
13070 --------------------------
13071 -- Invalid_Binder_Value --
13072 --------------------------
13074 function Invalid_Binder_Value
return Node_Id
is
13075 Val_Id
: Entity_Id
;
13078 -- Initialize the collection of invalid binder values the first time
13081 Set_Invalid_Binder_Values
;
13083 -- Obtain the corresponding variable from System.Scalar_Values which
13084 -- holds the invalid value for this type.
13086 Val_Id
:= Invalid_Binder_Values
(Scal_Typ
);
13087 pragma Assert
(Present
(Val_Id
));
13089 return New_Occurrence_Of
(Val_Id
, Loc
);
13090 end Invalid_Binder_Value
;
13092 -------------------------
13093 -- Invalid_Float_Value --
13094 -------------------------
13096 function Invalid_Float_Value
return Node_Id
is
13097 Value
: constant Ureal
:= Invalid_Floats
(Scal_Typ
);
13100 -- Pragma Invalid_Scalars did not specify an invalid value for this
13101 -- type. Fall back to the value provided by the binder.
13103 if Value
= No_Ureal
then
13104 return Invalid_Binder_Value
;
13106 return Make_Real_Literal
(Loc
, Realval
=> Value
);
13108 end Invalid_Float_Value
;
13110 ---------------------------
13111 -- Invalid_Integer_Value --
13112 ---------------------------
13114 function Invalid_Integer_Value
return Node_Id
is
13115 Value
: constant Uint
:= Invalid_Integers
(Scal_Typ
);
13118 -- Pragma Invalid_Scalars did not specify an invalid value for this
13119 -- type. Fall back to the value provided by the binder.
13121 if Value
= No_Uint
then
13122 return Invalid_Binder_Value
;
13124 return Make_Integer_Literal
(Loc
, Intval
=> Value
);
13126 end Invalid_Integer_Value
;
13128 -------------------------------
13129 -- Set_Invalid_Binder_Values --
13130 -------------------------------
13132 procedure Set_Invalid_Binder_Values
is
13134 if not Invalid_Binder_Values_Set
then
13135 Invalid_Binder_Values_Set
:= True;
13137 -- Initialize the contents of the collection once since RTE calls
13140 Invalid_Binder_Values
:=
13141 (Name_Short_Float
=> RTE
(RE_IS_Isf
),
13142 Name_Float
=> RTE
(RE_IS_Ifl
),
13143 Name_Long_Float
=> RTE
(RE_IS_Ilf
),
13144 Name_Long_Long_Float
=> RTE
(RE_IS_Ill
),
13145 Name_Signed_8
=> RTE
(RE_IS_Is1
),
13146 Name_Signed_16
=> RTE
(RE_IS_Is2
),
13147 Name_Signed_32
=> RTE
(RE_IS_Is4
),
13148 Name_Signed_64
=> RTE
(RE_IS_Is8
),
13149 Name_Unsigned_8
=> RTE
(RE_IS_Iu1
),
13150 Name_Unsigned_16
=> RTE
(RE_IS_Iu2
),
13151 Name_Unsigned_32
=> RTE
(RE_IS_Iu4
),
13152 Name_Unsigned_64
=> RTE
(RE_IS_Iu8
));
13154 end Set_Invalid_Binder_Values
;
13156 -- Start of processing for Invalid_Scalar_Value
13159 if Scal_Typ
in Float_Scalar_Id
then
13160 return Invalid_Float_Value
;
13162 else pragma Assert
(Scal_Typ
in Integer_Scalar_Id
);
13163 return Invalid_Integer_Value
;
13165 end Invalid_Scalar_Value
;
13167 -----------------------------
13168 -- Is_Actual_Out_Parameter --
13169 -----------------------------
13171 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
13172 Formal
: Entity_Id
;
13175 Find_Actual
(N
, Formal
, Call
);
13176 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
13177 end Is_Actual_Out_Parameter
;
13179 -------------------------
13180 -- Is_Actual_Parameter --
13181 -------------------------
13183 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
13184 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
13188 when N_Parameter_Association
=>
13189 return N
= Explicit_Actual_Parameter
(Parent
(N
));
13191 when N_Subprogram_Call
=>
13192 return Is_List_Member
(N
)
13194 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
13199 end Is_Actual_Parameter
;
13201 --------------------------------
13202 -- Is_Actual_Tagged_Parameter --
13203 --------------------------------
13205 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
13206 Formal
: Entity_Id
;
13209 Find_Actual
(N
, Formal
, Call
);
13210 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
13211 end Is_Actual_Tagged_Parameter
;
13213 ---------------------
13214 -- Is_Aliased_View --
13215 ---------------------
13217 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
13221 if Is_Entity_Name
(Obj
) then
13228 or else (Present
(Renamed_Object
(E
))
13229 and then Is_Aliased_View
(Renamed_Object
(E
)))))
13231 or else ((Is_Formal
(E
) or else Is_Formal_Object
(E
))
13232 and then Is_Tagged_Type
(Etype
(E
)))
13234 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
13236 -- Current instance of type, either directly or as rewritten
13237 -- reference to the current object.
13239 or else (Is_Entity_Name
(Original_Node
(Obj
))
13240 and then Present
(Entity
(Original_Node
(Obj
)))
13241 and then Is_Type
(Entity
(Original_Node
(Obj
))))
13243 or else (Is_Type
(E
) and then E
= Current_Scope
)
13245 or else (Is_Incomplete_Or_Private_Type
(E
)
13246 and then Full_View
(E
) = Current_Scope
)
13248 -- Ada 2012 AI05-0053: the return object of an extended return
13249 -- statement is aliased if its type is immutably limited.
13251 or else (Is_Return_Object
(E
)
13252 and then Is_Limited_View
(Etype
(E
)));
13254 elsif Nkind
(Obj
) = N_Selected_Component
then
13255 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
13257 elsif Nkind
(Obj
) = N_Indexed_Component
then
13258 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
13260 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
13261 and then Has_Aliased_Components
13262 (Designated_Type
(Etype
(Prefix
(Obj
)))));
13264 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
13265 return Is_Tagged_Type
(Etype
(Obj
))
13266 and then Is_Aliased_View
(Expression
(Obj
));
13268 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
13269 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
13274 end Is_Aliased_View
;
13276 -------------------------
13277 -- Is_Ancestor_Package --
13278 -------------------------
13280 function Is_Ancestor_Package
13282 E2
: Entity_Id
) return Boolean
13288 while Present
(Par
) and then Par
/= Standard_Standard
loop
13293 Par
:= Scope
(Par
);
13297 end Is_Ancestor_Package
;
13299 ----------------------
13300 -- Is_Atomic_Object --
13301 ----------------------
13303 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
13304 function Is_Atomic_Entity
(Id
: Entity_Id
) return Boolean;
13305 pragma Inline
(Is_Atomic_Entity
);
13306 -- Determine whether arbitrary entity Id is either atomic or has atomic
13309 function Is_Atomic_Prefix
(Pref
: Node_Id
) return Boolean;
13310 -- Determine whether prefix Pref of an indexed or selected component is
13311 -- an atomic object.
13313 ----------------------
13314 -- Is_Atomic_Entity --
13315 ----------------------
13317 function Is_Atomic_Entity
(Id
: Entity_Id
) return Boolean is
13319 return Is_Atomic
(Id
) or else Has_Atomic_Components
(Id
);
13320 end Is_Atomic_Entity
;
13322 ----------------------
13323 -- Is_Atomic_Prefix --
13324 ----------------------
13326 function Is_Atomic_Prefix
(Pref
: Node_Id
) return Boolean is
13327 Typ
: constant Entity_Id
:= Etype
(Pref
);
13330 if Is_Access_Type
(Typ
) then
13331 return Has_Atomic_Components
(Designated_Type
(Typ
));
13333 elsif Is_Atomic_Entity
(Typ
) then
13336 elsif Is_Entity_Name
(Pref
)
13337 and then Is_Atomic_Entity
(Entity
(Pref
))
13341 elsif Nkind
(Pref
) = N_Indexed_Component
then
13342 return Is_Atomic_Prefix
(Prefix
(Pref
));
13344 elsif Nkind
(Pref
) = N_Selected_Component
then
13346 Is_Atomic_Prefix
(Prefix
(Pref
))
13347 or else Is_Atomic
(Entity
(Selector_Name
(Pref
)));
13351 end Is_Atomic_Prefix
;
13353 -- Start of processing for Is_Atomic_Object
13356 if Is_Entity_Name
(N
) then
13357 return Is_Atomic_Object_Entity
(Entity
(N
));
13359 elsif Nkind
(N
) = N_Indexed_Component
then
13360 return Is_Atomic
(Etype
(N
)) or else Is_Atomic_Prefix
(Prefix
(N
));
13362 elsif Nkind
(N
) = N_Selected_Component
then
13364 Is_Atomic
(Etype
(N
))
13365 or else Is_Atomic_Prefix
(Prefix
(N
))
13366 or else Is_Atomic
(Entity
(Selector_Name
(N
)));
13370 end Is_Atomic_Object
;
13372 -----------------------------
13373 -- Is_Atomic_Object_Entity --
13374 -----------------------------
13376 function Is_Atomic_Object_Entity
(Id
: Entity_Id
) return Boolean is
13380 and then (Is_Atomic
(Id
) or else Is_Atomic
(Etype
(Id
)));
13381 end Is_Atomic_Object_Entity
;
13383 -----------------------------
13384 -- Is_Atomic_Or_VFA_Object --
13385 -----------------------------
13387 function Is_Atomic_Or_VFA_Object
(N
: Node_Id
) return Boolean is
13389 return Is_Atomic_Object
(N
)
13390 or else (Is_Object_Reference
(N
)
13391 and then Is_Entity_Name
(N
)
13392 and then (Is_Volatile_Full_Access
(Entity
(N
))
13394 Is_Volatile_Full_Access
(Etype
(Entity
(N
)))));
13395 end Is_Atomic_Or_VFA_Object
;
13397 -------------------------
13398 -- Is_Attribute_Result --
13399 -------------------------
13401 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
13403 return Nkind
(N
) = N_Attribute_Reference
13404 and then Attribute_Name
(N
) = Name_Result
;
13405 end Is_Attribute_Result
;
13407 -------------------------
13408 -- Is_Attribute_Update --
13409 -------------------------
13411 function Is_Attribute_Update
(N
: Node_Id
) return Boolean is
13413 return Nkind
(N
) = N_Attribute_Reference
13414 and then Attribute_Name
(N
) = Name_Update
;
13415 end Is_Attribute_Update
;
13417 ------------------------------------
13418 -- Is_Body_Or_Package_Declaration --
13419 ------------------------------------
13421 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
13423 return Is_Body
(N
) or else Nkind
(N
) = N_Package_Declaration
;
13424 end Is_Body_Or_Package_Declaration
;
13426 -----------------------
13427 -- Is_Bounded_String --
13428 -----------------------
13430 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
13431 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
13434 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13435 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13436 -- be True for all the Bounded_String types in instances of the
13437 -- Generic_Bounded_Length generics, and for types derived from those.
13439 return Present
(Under
)
13440 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
13441 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
13442 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
13443 end Is_Bounded_String
;
13445 ---------------------
13446 -- Is_CCT_Instance --
13447 ---------------------
13449 function Is_CCT_Instance
13450 (Ref_Id
: Entity_Id
;
13451 Context_Id
: Entity_Id
) return Boolean
13454 pragma Assert
(Ekind_In
(Ref_Id
, E_Protected_Type
, E_Task_Type
));
13456 if Is_Single_Task_Object
(Context_Id
) then
13457 return Scope_Within_Or_Same
(Etype
(Context_Id
), Ref_Id
);
13460 pragma Assert
(Ekind_In
(Context_Id
, E_Entry
,
13468 Is_Record_Type
(Context_Id
));
13469 return Scope_Within_Or_Same
(Context_Id
, Ref_Id
);
13471 end Is_CCT_Instance
;
13473 -------------------------
13474 -- Is_Child_Or_Sibling --
13475 -------------------------
13477 function Is_Child_Or_Sibling
13478 (Pack_1
: Entity_Id
;
13479 Pack_2
: Entity_Id
) return Boolean
13481 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
13482 -- Given an arbitrary package, return the number of "climbs" necessary
13483 -- to reach scope Standard_Standard.
13485 procedure Equalize_Depths
13486 (Pack
: in out Entity_Id
;
13487 Depth
: in out Nat
;
13488 Depth_To_Reach
: Nat
);
13489 -- Given an arbitrary package, its depth and a target depth to reach,
13490 -- climb the scope chain until the said depth is reached. The pointer
13491 -- to the package and its depth a modified during the climb.
13493 ----------------------------
13494 -- Distance_From_Standard --
13495 ----------------------------
13497 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
13504 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
13506 Scop
:= Scope
(Scop
);
13510 end Distance_From_Standard
;
13512 ---------------------
13513 -- Equalize_Depths --
13514 ---------------------
13516 procedure Equalize_Depths
13517 (Pack
: in out Entity_Id
;
13518 Depth
: in out Nat
;
13519 Depth_To_Reach
: Nat
)
13522 -- The package must be at a greater or equal depth
13524 if Depth
< Depth_To_Reach
then
13525 raise Program_Error
;
13528 -- Climb the scope chain until the desired depth is reached
13530 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
13531 Pack
:= Scope
(Pack
);
13532 Depth
:= Depth
- 1;
13534 end Equalize_Depths
;
13538 P_1
: Entity_Id
:= Pack_1
;
13539 P_1_Child
: Boolean := False;
13540 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
13541 P_2
: Entity_Id
:= Pack_2
;
13542 P_2_Child
: Boolean := False;
13543 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
13545 -- Start of processing for Is_Child_Or_Sibling
13549 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
13551 -- Both packages denote the same entity, therefore they cannot be
13552 -- children or siblings.
13557 -- One of the packages is at a deeper level than the other. Note that
13558 -- both may still come from different hierarchies.
13566 elsif P_1_Depth
> P_2_Depth
then
13569 Depth
=> P_1_Depth
,
13570 Depth_To_Reach
=> P_2_Depth
);
13579 elsif P_2_Depth
> P_1_Depth
then
13582 Depth
=> P_2_Depth
,
13583 Depth_To_Reach
=> P_1_Depth
);
13587 -- At this stage the package pointers have been elevated to the same
13588 -- depth. If the related entities are the same, then one package is a
13589 -- potential child of the other:
13593 -- X became P_1 P_2 or vice versa
13599 return Is_Child_Unit
(Pack_1
);
13601 else pragma Assert
(P_2_Child
);
13602 return Is_Child_Unit
(Pack_2
);
13605 -- The packages may come from the same package chain or from entirely
13606 -- different hierarcies. To determine this, climb the scope stack until
13607 -- a common root is found.
13609 -- (root) (root 1) (root 2)
13614 while Present
(P_1
) and then Present
(P_2
) loop
13616 -- The two packages may be siblings
13619 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
13622 P_1
:= Scope
(P_1
);
13623 P_2
:= Scope
(P_2
);
13628 end Is_Child_Or_Sibling
;
13630 -----------------------------
13631 -- Is_Concurrent_Interface --
13632 -----------------------------
13634 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
13636 return Is_Interface
(T
)
13638 (Is_Protected_Interface
(T
)
13639 or else Is_Synchronized_Interface
(T
)
13640 or else Is_Task_Interface
(T
));
13641 end Is_Concurrent_Interface
;
13643 -----------------------
13644 -- Is_Constant_Bound --
13645 -----------------------
13647 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
13649 if Compile_Time_Known_Value
(Exp
) then
13652 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
13653 return Is_Constant_Object
(Entity
(Exp
))
13654 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
13656 elsif Nkind
(Exp
) in N_Binary_Op
then
13657 return Is_Constant_Bound
(Left_Opnd
(Exp
))
13658 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
13659 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
13664 end Is_Constant_Bound
;
13666 ---------------------------
13667 -- Is_Container_Element --
13668 ---------------------------
13670 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
13671 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
13672 Pref
: constant Node_Id
:= Prefix
(Exp
);
13675 -- Call to an indexing aspect
13677 Cont_Typ
: Entity_Id
;
13678 -- The type of the container being accessed
13680 Elem_Typ
: Entity_Id
;
13681 -- Its element type
13683 Indexing
: Entity_Id
;
13684 Is_Const
: Boolean;
13685 -- Indicates that constant indexing is used, and the element is thus
13688 Ref_Typ
: Entity_Id
;
13689 -- The reference type returned by the indexing operation
13692 -- If C is a container, in a context that imposes the element type of
13693 -- that container, the indexing notation C (X) is rewritten as:
13695 -- Indexing (C, X).Discr.all
13697 -- where Indexing is one of the indexing aspects of the container.
13698 -- If the context does not require a reference, the construct can be
13703 -- First, verify that the construct has the proper form
13705 if not Expander_Active
then
13708 elsif Nkind
(Pref
) /= N_Selected_Component
then
13711 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
13715 Call
:= Prefix
(Pref
);
13716 Ref_Typ
:= Etype
(Call
);
13719 if not Has_Implicit_Dereference
(Ref_Typ
)
13720 or else No
(First
(Parameter_Associations
(Call
)))
13721 or else not Is_Entity_Name
(Name
(Call
))
13726 -- Retrieve type of container object, and its iterator aspects
13728 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
13729 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
13732 if No
(Indexing
) then
13734 -- Container should have at least one indexing operation
13738 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
13740 -- This may be a variable indexing operation
13742 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
13745 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
13754 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
13756 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
13760 -- Check that the expression is not the target of an assignment, in
13761 -- which case the rewriting is not possible.
13763 if not Is_Const
then
13769 while Present
(Par
)
13771 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
13772 and then Par
= Name
(Parent
(Par
))
13776 -- A renaming produces a reference, and the transformation
13779 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
13783 (Nkind
(Parent
(Par
)), N_Function_Call
,
13784 N_Procedure_Call_Statement
,
13785 N_Entry_Call_Statement
)
13787 -- Check that the element is not part of an actual for an
13788 -- in-out parameter.
13795 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
13796 A
:= First
(Parameter_Associations
(Parent
(Par
)));
13797 while Present
(F
) loop
13798 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
13807 -- E_In_Parameter in a call: element is not modified.
13812 Par
:= Parent
(Par
);
13817 -- The expression has the proper form and the context requires the
13818 -- element type. Retrieve the Element function of the container and
13819 -- rewrite the construct as a call to it.
13825 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
13826 while Present
(Op
) loop
13827 exit when Chars
(Node
(Op
)) = Name_Element
;
13836 Make_Function_Call
(Loc
,
13837 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
13838 Parameter_Associations
=> Parameter_Associations
(Call
)));
13839 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
13843 end Is_Container_Element
;
13845 ----------------------------
13846 -- Is_Contract_Annotation --
13847 ----------------------------
13849 function Is_Contract_Annotation
(Item
: Node_Id
) return Boolean is
13851 return Is_Package_Contract_Annotation
(Item
)
13853 Is_Subprogram_Contract_Annotation
(Item
);
13854 end Is_Contract_Annotation
;
13856 --------------------------------------
13857 -- Is_Controlling_Limited_Procedure --
13858 --------------------------------------
13860 function Is_Controlling_Limited_Procedure
13861 (Proc_Nam
: Entity_Id
) return Boolean
13864 Param_Typ
: Entity_Id
:= Empty
;
13867 if Ekind
(Proc_Nam
) = E_Procedure
13868 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
13872 (First
(Parameter_Specifications
(Parent
(Proc_Nam
))));
13874 -- The formal may be an anonymous access type
13876 if Nkind
(Param
) = N_Access_Definition
then
13877 Param_Typ
:= Entity
(Subtype_Mark
(Param
));
13879 Param_Typ
:= Etype
(Param
);
13882 -- In the case where an Itype was created for a dispatchin call, the
13883 -- procedure call has been rewritten. The actual may be an access to
13884 -- interface type in which case it is the designated type that is the
13885 -- controlling type.
13887 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
13888 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
13890 Present
(Parameter_Associations
13891 (Associated_Node_For_Itype
(Proc_Nam
)))
13894 Etype
(First
(Parameter_Associations
13895 (Associated_Node_For_Itype
(Proc_Nam
))));
13897 if Ekind
(Param_Typ
) = E_Anonymous_Access_Type
then
13898 Param_Typ
:= Directly_Designated_Type
(Param_Typ
);
13902 if Present
(Param_Typ
) then
13904 Is_Interface
(Param_Typ
)
13905 and then Is_Limited_Record
(Param_Typ
);
13909 end Is_Controlling_Limited_Procedure
;
13911 -----------------------------
13912 -- Is_CPP_Constructor_Call --
13913 -----------------------------
13915 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
13917 return Nkind
(N
) = N_Function_Call
13918 and then Is_CPP_Class
(Etype
(Etype
(N
)))
13919 and then Is_Constructor
(Entity
(Name
(N
)))
13920 and then Is_Imported
(Entity
(Name
(N
)));
13921 end Is_CPP_Constructor_Call
;
13923 -------------------------
13924 -- Is_Current_Instance --
13925 -------------------------
13927 function Is_Current_Instance
(N
: Node_Id
) return Boolean is
13928 Typ
: constant Entity_Id
:= Entity
(N
);
13932 -- Simplest case: entity is a concurrent type and we are currently
13933 -- inside the body. This will eventually be expanded into a call to
13934 -- Self (for tasks) or _object (for protected objects).
13936 if Is_Concurrent_Type
(Typ
) and then In_Open_Scopes
(Typ
) then
13940 -- Check whether the context is a (sub)type declaration for the
13944 while Present
(P
) loop
13945 if Nkind_In
(P
, N_Full_Type_Declaration
,
13946 N_Private_Type_Declaration
,
13947 N_Subtype_Declaration
)
13948 and then Comes_From_Source
(P
)
13949 and then Defining_Entity
(P
) = Typ
13953 -- A subtype name may appear in an aspect specification for a
13954 -- Predicate_Failure aspect, for which we do not construct a
13955 -- wrapper procedure. The subtype will be replaced by the
13956 -- expression being tested when the corresponding predicate
13957 -- check is expanded.
13959 elsif Nkind
(P
) = N_Aspect_Specification
13960 and then Nkind
(Parent
(P
)) = N_Subtype_Declaration
13964 elsif Nkind
(P
) = N_Pragma
13965 and then Get_Pragma_Id
(P
) = Pragma_Predicate_Failure
13974 -- In any other context this is not a current occurrence
13977 end Is_Current_Instance
;
13979 --------------------
13980 -- Is_Declaration --
13981 --------------------
13983 function Is_Declaration
13985 Body_OK
: Boolean := True;
13986 Concurrent_OK
: Boolean := True;
13987 Formal_OK
: Boolean := True;
13988 Generic_OK
: Boolean := True;
13989 Instantiation_OK
: Boolean := True;
13990 Renaming_OK
: Boolean := True;
13991 Stub_OK
: Boolean := True;
13992 Subprogram_OK
: Boolean := True;
13993 Type_OK
: Boolean := True) return Boolean
13998 -- Body declarations
14000 when N_Proper_Body
=>
14003 -- Concurrent type declarations
14005 when N_Protected_Type_Declaration
14006 | N_Single_Protected_Declaration
14007 | N_Single_Task_Declaration
14008 | N_Task_Type_Declaration
14010 return Concurrent_OK
or Type_OK
;
14012 -- Formal declarations
14014 when N_Formal_Abstract_Subprogram_Declaration
14015 | N_Formal_Concrete_Subprogram_Declaration
14016 | N_Formal_Object_Declaration
14017 | N_Formal_Package_Declaration
14018 | N_Formal_Type_Declaration
14022 -- Generic declarations
14024 when N_Generic_Package_Declaration
14025 | N_Generic_Subprogram_Declaration
14029 -- Generic instantiations
14031 when N_Function_Instantiation
14032 | N_Package_Instantiation
14033 | N_Procedure_Instantiation
14035 return Instantiation_OK
;
14037 -- Generic renaming declarations
14039 when N_Generic_Renaming_Declaration
=>
14040 return Generic_OK
or Renaming_OK
;
14042 -- Renaming declarations
14044 when N_Exception_Renaming_Declaration
14045 | N_Object_Renaming_Declaration
14046 | N_Package_Renaming_Declaration
14047 | N_Subprogram_Renaming_Declaration
14049 return Renaming_OK
;
14051 -- Stub declarations
14053 when N_Body_Stub
=>
14056 -- Subprogram declarations
14058 when N_Abstract_Subprogram_Declaration
14059 | N_Entry_Declaration
14060 | N_Expression_Function
14061 | N_Subprogram_Declaration
14063 return Subprogram_OK
;
14065 -- Type declarations
14067 when N_Full_Type_Declaration
14068 | N_Incomplete_Type_Declaration
14069 | N_Private_Extension_Declaration
14070 | N_Private_Type_Declaration
14071 | N_Subtype_Declaration
14077 when N_Component_Declaration
14078 | N_Exception_Declaration
14079 | N_Implicit_Label_Declaration
14080 | N_Number_Declaration
14081 | N_Object_Declaration
14082 | N_Package_Declaration
14089 end Is_Declaration
;
14091 --------------------------------
14092 -- Is_Declared_Within_Variant --
14093 --------------------------------
14095 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
14096 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
14097 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
14099 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
14100 end Is_Declared_Within_Variant
;
14102 ----------------------------------------------
14103 -- Is_Dependent_Component_Of_Mutable_Object --
14104 ----------------------------------------------
14106 function Is_Dependent_Component_Of_Mutable_Object
14107 (Object
: Node_Id
) return Boolean
14110 Prefix_Type
: Entity_Id
;
14111 P_Aliased
: Boolean := False;
14114 Deref
: Node_Id
:= Object
;
14115 -- Dereference node, in something like X.all.Y(2)
14117 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14120 -- Find the dereference node if any
14122 while Nkind_In
(Deref
, N_Indexed_Component
,
14123 N_Selected_Component
,
14126 Deref
:= Prefix
(Deref
);
14129 -- Ada 2005: If we have a component or slice of a dereference,
14130 -- something like X.all.Y (2), and the type of X is access-to-constant,
14131 -- Is_Variable will return False, because it is indeed a constant
14132 -- view. But it might be a view of a variable object, so we want the
14133 -- following condition to be True in that case.
14135 if Is_Variable
(Object
)
14136 or else (Ada_Version
>= Ada_2005
14137 and then Nkind
(Deref
) = N_Explicit_Dereference
)
14139 if Nkind
(Object
) = N_Selected_Component
then
14140 P
:= Prefix
(Object
);
14141 Prefix_Type
:= Etype
(P
);
14143 if Is_Entity_Name
(P
) then
14144 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
14145 Prefix_Type
:= Base_Type
(Prefix_Type
);
14148 if Is_Aliased
(Entity
(P
)) then
14152 -- A discriminant check on a selected component may be expanded
14153 -- into a dereference when removing side effects. Recover the
14154 -- original node and its type, which may be unconstrained.
14156 elsif Nkind
(P
) = N_Explicit_Dereference
14157 and then not (Comes_From_Source
(P
))
14159 P
:= Original_Node
(P
);
14160 Prefix_Type
:= Etype
(P
);
14163 -- Check for prefix being an aliased component???
14169 -- A heap object is constrained by its initial value
14171 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14172 -- the dereferenced case, since the access value might denote an
14173 -- unconstrained aliased object, whereas in Ada 95 the designated
14174 -- object is guaranteed to be constrained. A worst-case assumption
14175 -- has to apply in Ada 2005 because we can't tell at compile
14176 -- time whether the object is "constrained by its initial value",
14177 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14178 -- rules (these rules are acknowledged to need fixing). We don't
14179 -- impose this more stringent checking for earlier Ada versions or
14180 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14181 -- benefit, though it's unclear on why using -gnat95 would not be
14184 if Ada_Version
< Ada_2005
or else Relaxed_RM_Semantics
then
14185 if Is_Access_Type
(Prefix_Type
)
14186 or else Nkind
(P
) = N_Explicit_Dereference
14191 else pragma Assert
(Ada_Version
>= Ada_2005
);
14192 if Is_Access_Type
(Prefix_Type
) then
14194 -- If the access type is pool-specific, and there is no
14195 -- constrained partial view of the designated type, then the
14196 -- designated object is known to be constrained.
14198 if Ekind
(Prefix_Type
) = E_Access_Type
14199 and then not Object_Type_Has_Constrained_Partial_View
14200 (Typ
=> Designated_Type
(Prefix_Type
),
14201 Scop
=> Current_Scope
)
14205 -- Otherwise (general access type, or there is a constrained
14206 -- partial view of the designated type), we need to check
14207 -- based on the designated type.
14210 Prefix_Type
:= Designated_Type
(Prefix_Type
);
14216 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
14218 -- As per AI-0017, the renaming is illegal in a generic body, even
14219 -- if the subtype is indefinite.
14221 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14223 if not Is_Constrained
(Prefix_Type
)
14224 and then (Is_Definite_Subtype
(Prefix_Type
)
14226 (Is_Generic_Type
(Prefix_Type
)
14227 and then Ekind
(Current_Scope
) = E_Generic_Package
14228 and then In_Package_Body
(Current_Scope
)))
14230 and then (Is_Declared_Within_Variant
(Comp
)
14231 or else Has_Discriminant_Dependent_Constraint
(Comp
))
14232 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
14236 -- If the prefix is of an access type at this point, then we want
14237 -- to return False, rather than calling this function recursively
14238 -- on the access object (which itself might be a discriminant-
14239 -- dependent component of some other object, but that isn't
14240 -- relevant to checking the object passed to us). This avoids
14241 -- issuing wrong errors when compiling with -gnatc, where there
14242 -- can be implicit dereferences that have not been expanded.
14244 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
14249 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
14252 elsif Nkind
(Object
) = N_Indexed_Component
14253 or else Nkind
(Object
) = N_Slice
14255 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
14257 -- A type conversion that Is_Variable is a view conversion:
14258 -- go back to the denoted object.
14260 elsif Nkind
(Object
) = N_Type_Conversion
then
14262 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
14267 end Is_Dependent_Component_Of_Mutable_Object
;
14269 ---------------------
14270 -- Is_Dereferenced --
14271 ---------------------
14273 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
14274 P
: constant Node_Id
:= Parent
(N
);
14276 return Nkind_In
(P
, N_Selected_Component
,
14277 N_Explicit_Dereference
,
14278 N_Indexed_Component
,
14280 and then Prefix
(P
) = N
;
14281 end Is_Dereferenced
;
14283 ----------------------
14284 -- Is_Descendant_Of --
14285 ----------------------
14287 function Is_Descendant_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
14292 pragma Assert
(Nkind
(T1
) in N_Entity
);
14293 pragma Assert
(Nkind
(T2
) in N_Entity
);
14295 T
:= Base_Type
(T1
);
14297 -- Immediate return if the types match
14302 -- Comment needed here ???
14304 elsif Ekind
(T
) = E_Class_Wide_Type
then
14305 return Etype
(T
) = T2
;
14313 -- Done if we found the type we are looking for
14318 -- Done if no more derivations to check
14325 -- Following test catches error cases resulting from prev errors
14327 elsif No
(Etyp
) then
14330 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
14333 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
14337 T
:= Base_Type
(Etyp
);
14340 end Is_Descendant_Of
;
14342 ----------------------------------------
14343 -- Is_Descendant_Of_Suspension_Object --
14344 ----------------------------------------
14346 function Is_Descendant_Of_Suspension_Object
14347 (Typ
: Entity_Id
) return Boolean
14349 Cur_Typ
: Entity_Id
;
14350 Par_Typ
: Entity_Id
;
14353 -- Climb the type derivation chain checking each parent type against
14354 -- Suspension_Object.
14356 Cur_Typ
:= Base_Type
(Typ
);
14357 while Present
(Cur_Typ
) loop
14358 Par_Typ
:= Etype
(Cur_Typ
);
14360 -- The current type is a match
14362 if Is_Suspension_Object
(Cur_Typ
) then
14365 -- Stop the traversal once the root of the derivation chain has been
14366 -- reached. In that case the current type is its own base type.
14368 elsif Cur_Typ
= Par_Typ
then
14372 Cur_Typ
:= Base_Type
(Par_Typ
);
14376 end Is_Descendant_Of_Suspension_Object
;
14378 ---------------------------------------------
14379 -- Is_Double_Precision_Floating_Point_Type --
14380 ---------------------------------------------
14382 function Is_Double_Precision_Floating_Point_Type
14383 (E
: Entity_Id
) return Boolean is
14385 return Is_Floating_Point_Type
(E
)
14386 and then Machine_Radix_Value
(E
) = Uint_2
14387 and then Machine_Mantissa_Value
(E
) = UI_From_Int
(53)
14388 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_10
14389 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_10
);
14390 end Is_Double_Precision_Floating_Point_Type
;
14392 -----------------------------
14393 -- Is_Effectively_Volatile --
14394 -----------------------------
14396 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
14398 if Is_Type
(Id
) then
14400 -- An arbitrary type is effectively volatile when it is subject to
14401 -- pragma Atomic or Volatile.
14403 if Is_Volatile
(Id
) then
14406 -- An array type is effectively volatile when it is subject to pragma
14407 -- Atomic_Components or Volatile_Components or its component type is
14408 -- effectively volatile.
14410 elsif Is_Array_Type
(Id
) then
14412 Anc
: Entity_Id
:= Base_Type
(Id
);
14414 if Is_Private_Type
(Anc
) then
14415 Anc
:= Full_View
(Anc
);
14418 -- Test for presence of ancestor, as the full view of a private
14419 -- type may be missing in case of error.
14422 Has_Volatile_Components
(Id
)
14425 and then Is_Effectively_Volatile
(Component_Type
(Anc
)));
14428 -- A protected type is always volatile
14430 elsif Is_Protected_Type
(Id
) then
14433 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14434 -- automatically volatile.
14436 elsif Is_Descendant_Of_Suspension_Object
(Id
) then
14439 -- Otherwise the type is not effectively volatile
14445 -- Otherwise Id denotes an object
14450 or else Has_Volatile_Components
(Id
)
14451 or else Is_Effectively_Volatile
(Etype
(Id
));
14453 end Is_Effectively_Volatile
;
14455 ------------------------------------
14456 -- Is_Effectively_Volatile_Object --
14457 ------------------------------------
14459 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
14461 if Is_Entity_Name
(N
) then
14462 return Is_Effectively_Volatile
(Entity
(N
));
14464 elsif Nkind
(N
) = N_Indexed_Component
then
14465 return Is_Effectively_Volatile_Object
(Prefix
(N
));
14467 elsif Nkind
(N
) = N_Selected_Component
then
14469 Is_Effectively_Volatile_Object
(Prefix
(N
))
14471 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
14476 end Is_Effectively_Volatile_Object
;
14478 -------------------
14479 -- Is_Entry_Body --
14480 -------------------
14482 function Is_Entry_Body
(Id
: Entity_Id
) return Boolean is
14485 Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
14486 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Body
;
14489 --------------------------
14490 -- Is_Entry_Declaration --
14491 --------------------------
14493 function Is_Entry_Declaration
(Id
: Entity_Id
) return Boolean is
14496 Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
14497 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Declaration
;
14498 end Is_Entry_Declaration
;
14500 ------------------------------------
14501 -- Is_Expanded_Priority_Attribute --
14502 ------------------------------------
14504 function Is_Expanded_Priority_Attribute
(E
: Entity_Id
) return Boolean is
14507 Nkind
(E
) = N_Function_Call
14508 and then not Configurable_Run_Time_Mode
14509 and then (Entity
(Name
(E
)) = RTE
(RE_Get_Ceiling
)
14510 or else Entity
(Name
(E
)) = RTE
(RO_PE_Get_Ceiling
));
14511 end Is_Expanded_Priority_Attribute
;
14513 ----------------------------
14514 -- Is_Expression_Function --
14515 ----------------------------
14517 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
14519 if Ekind_In
(Subp
, E_Function
, E_Subprogram_Body
) then
14521 Nkind
(Original_Node
(Unit_Declaration_Node
(Subp
))) =
14522 N_Expression_Function
;
14526 end Is_Expression_Function
;
14528 ------------------------------------------
14529 -- Is_Expression_Function_Or_Completion --
14530 ------------------------------------------
14532 function Is_Expression_Function_Or_Completion
14533 (Subp
: Entity_Id
) return Boolean
14535 Subp_Decl
: Node_Id
;
14538 if Ekind
(Subp
) = E_Function
then
14539 Subp_Decl
:= Unit_Declaration_Node
(Subp
);
14541 -- The function declaration is either an expression function or is
14542 -- completed by an expression function body.
14545 Is_Expression_Function
(Subp
)
14546 or else (Nkind
(Subp_Decl
) = N_Subprogram_Declaration
14547 and then Present
(Corresponding_Body
(Subp_Decl
))
14548 and then Is_Expression_Function
14549 (Corresponding_Body
(Subp_Decl
)));
14551 elsif Ekind
(Subp
) = E_Subprogram_Body
then
14552 return Is_Expression_Function
(Subp
);
14557 end Is_Expression_Function_Or_Completion
;
14559 -----------------------
14560 -- Is_EVF_Expression --
14561 -----------------------
14563 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
14564 Orig_N
: constant Node_Id
:= Original_Node
(N
);
14570 -- Detect a reference to a formal parameter of a specific tagged type
14571 -- whose related subprogram is subject to pragma Expresions_Visible with
14574 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
14579 and then Is_Specific_Tagged_Type
(Etype
(Id
))
14580 and then Extensions_Visible_Status
(Id
) =
14581 Extensions_Visible_False
;
14583 -- A case expression is an EVF expression when it contains at least one
14584 -- EVF dependent_expression. Note that a case expression may have been
14585 -- expanded, hence the use of Original_Node.
14587 elsif Nkind
(Orig_N
) = N_Case_Expression
then
14588 Alt
:= First
(Alternatives
(Orig_N
));
14589 while Present
(Alt
) loop
14590 if Is_EVF_Expression
(Expression
(Alt
)) then
14597 -- An if expression is an EVF expression when it contains at least one
14598 -- EVF dependent_expression. Note that an if expression may have been
14599 -- expanded, hence the use of Original_Node.
14601 elsif Nkind
(Orig_N
) = N_If_Expression
then
14602 Expr
:= Next
(First
(Expressions
(Orig_N
)));
14603 while Present
(Expr
) loop
14604 if Is_EVF_Expression
(Expr
) then
14611 -- A qualified expression or a type conversion is an EVF expression when
14612 -- its operand is an EVF expression.
14614 elsif Nkind_In
(N
, N_Qualified_Expression
,
14615 N_Unchecked_Type_Conversion
,
14618 return Is_EVF_Expression
(Expression
(N
));
14620 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14621 -- their prefix denotes an EVF expression.
14623 elsif Nkind
(N
) = N_Attribute_Reference
14624 and then Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
14628 return Is_EVF_Expression
(Prefix
(N
));
14632 end Is_EVF_Expression
;
14638 function Is_False
(U
: Uint
) return Boolean is
14643 ---------------------------
14644 -- Is_Fixed_Model_Number --
14645 ---------------------------
14647 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
14648 S
: constant Ureal
:= Small_Value
(T
);
14649 M
: Urealp
.Save_Mark
;
14654 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
14655 Urealp
.Release
(M
);
14657 end Is_Fixed_Model_Number
;
14659 -------------------------------
14660 -- Is_Fully_Initialized_Type --
14661 -------------------------------
14663 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
14667 if Is_Scalar_Type
(Typ
) then
14669 -- A scalar type with an aspect Default_Value is fully initialized
14671 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14672 -- of a scalar type, but we don't take that into account here, since
14673 -- we don't want these to affect warnings.
14675 return Has_Default_Aspect
(Typ
);
14677 elsif Is_Access_Type
(Typ
) then
14680 elsif Is_Array_Type
(Typ
) then
14681 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
14682 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
14687 -- An interesting case, if we have a constrained type one of whose
14688 -- bounds is known to be null, then there are no elements to be
14689 -- initialized, so all the elements are initialized.
14691 if Is_Constrained
(Typ
) then
14694 Indx_Typ
: Entity_Id
;
14695 Lbd
, Hbd
: Node_Id
;
14698 Indx
:= First_Index
(Typ
);
14699 while Present
(Indx
) loop
14700 if Etype
(Indx
) = Any_Type
then
14703 -- If index is a range, use directly
14705 elsif Nkind
(Indx
) = N_Range
then
14706 Lbd
:= Low_Bound
(Indx
);
14707 Hbd
:= High_Bound
(Indx
);
14710 Indx_Typ
:= Etype
(Indx
);
14712 if Is_Private_Type
(Indx_Typ
) then
14713 Indx_Typ
:= Full_View
(Indx_Typ
);
14716 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
14719 Lbd
:= Type_Low_Bound
(Indx_Typ
);
14720 Hbd
:= Type_High_Bound
(Indx_Typ
);
14724 if Compile_Time_Known_Value
(Lbd
)
14726 Compile_Time_Known_Value
(Hbd
)
14728 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
14738 -- If no null indexes, then type is not fully initialized
14744 elsif Is_Record_Type
(Typ
) then
14745 if Has_Discriminants
(Typ
)
14747 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
14748 and then Is_Fully_Initialized_Variant
(Typ
)
14753 -- We consider bounded string types to be fully initialized, because
14754 -- otherwise we get false alarms when the Data component is not
14755 -- default-initialized.
14757 if Is_Bounded_String
(Typ
) then
14761 -- Controlled records are considered to be fully initialized if
14762 -- there is a user defined Initialize routine. This may not be
14763 -- entirely correct, but as the spec notes, we are guessing here
14764 -- what is best from the point of view of issuing warnings.
14766 if Is_Controlled
(Typ
) then
14768 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
14771 if Present
(Utyp
) then
14773 Init
: constant Entity_Id
:=
14774 (Find_Optional_Prim_Op
14775 (Underlying_Type
(Typ
), Name_Initialize
));
14779 and then Comes_From_Source
(Init
)
14780 and then not In_Predefined_Unit
(Init
)
14784 elsif Has_Null_Extension
(Typ
)
14786 Is_Fully_Initialized_Type
14787 (Etype
(Base_Type
(Typ
)))
14796 -- Otherwise see if all record components are initialized
14802 Ent
:= First_Entity
(Typ
);
14803 while Present
(Ent
) loop
14804 if Ekind
(Ent
) = E_Component
14805 and then (No
(Parent
(Ent
))
14806 or else No
(Expression
(Parent
(Ent
))))
14807 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
14809 -- Special VM case for tag components, which need to be
14810 -- defined in this case, but are never initialized as VMs
14811 -- are using other dispatching mechanisms. Ignore this
14812 -- uninitialized case. Note that this applies both to the
14813 -- uTag entry and the main vtable pointer (CPP_Class case).
14815 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
14824 -- No uninitialized components, so type is fully initialized.
14825 -- Note that this catches the case of no components as well.
14829 elsif Is_Concurrent_Type
(Typ
) then
14832 elsif Is_Private_Type
(Typ
) then
14834 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
14840 return Is_Fully_Initialized_Type
(U
);
14847 end Is_Fully_Initialized_Type
;
14849 ----------------------------------
14850 -- Is_Fully_Initialized_Variant --
14851 ----------------------------------
14853 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
14854 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
14855 Constraints
: constant List_Id
:= New_List
;
14856 Components
: constant Elist_Id
:= New_Elmt_List
;
14857 Comp_Elmt
: Elmt_Id
;
14859 Comp_List
: Node_Id
;
14861 Discr_Val
: Node_Id
;
14863 Report_Errors
: Boolean;
14864 pragma Warnings
(Off
, Report_Errors
);
14867 if Serious_Errors_Detected
> 0 then
14871 if Is_Record_Type
(Typ
)
14872 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
14873 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
14875 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
14877 Discr
:= First_Discriminant
(Typ
);
14878 while Present
(Discr
) loop
14879 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
14880 Discr_Val
:= Expression
(Parent
(Discr
));
14882 if Present
(Discr_Val
)
14883 and then Is_OK_Static_Expression
(Discr_Val
)
14885 Append_To
(Constraints
,
14886 Make_Component_Association
(Loc
,
14887 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
14888 Expression
=> New_Copy
(Discr_Val
)));
14896 Next_Discriminant
(Discr
);
14901 Comp_List
=> Comp_List
,
14902 Governed_By
=> Constraints
,
14903 Into
=> Components
,
14904 Report_Errors
=> Report_Errors
);
14906 -- Check that each component present is fully initialized
14908 Comp_Elmt
:= First_Elmt
(Components
);
14909 while Present
(Comp_Elmt
) loop
14910 Comp_Id
:= Node
(Comp_Elmt
);
14912 if Ekind
(Comp_Id
) = E_Component
14913 and then (No
(Parent
(Comp_Id
))
14914 or else No
(Expression
(Parent
(Comp_Id
))))
14915 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
14920 Next_Elmt
(Comp_Elmt
);
14925 elsif Is_Private_Type
(Typ
) then
14927 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
14933 return Is_Fully_Initialized_Variant
(U
);
14940 end Is_Fully_Initialized_Variant
;
14942 ------------------------------------
14943 -- Is_Generic_Declaration_Or_Body --
14944 ------------------------------------
14946 function Is_Generic_Declaration_Or_Body
(Decl
: Node_Id
) return Boolean is
14947 Spec_Decl
: Node_Id
;
14950 -- Package/subprogram body
14952 if Nkind_In
(Decl
, N_Package_Body
, N_Subprogram_Body
)
14953 and then Present
(Corresponding_Spec
(Decl
))
14955 Spec_Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(Decl
));
14957 -- Package/subprogram body stub
14959 elsif Nkind_In
(Decl
, N_Package_Body_Stub
, N_Subprogram_Body_Stub
)
14960 and then Present
(Corresponding_Spec_Of_Stub
(Decl
))
14963 Unit_Declaration_Node
(Corresponding_Spec_Of_Stub
(Decl
));
14971 -- Rather than inspecting the defining entity of the spec declaration,
14972 -- look at its Nkind. This takes care of the case where the analysis of
14973 -- a generic body modifies the Ekind of its spec to allow for recursive
14977 Nkind_In
(Spec_Decl
, N_Generic_Package_Declaration
,
14978 N_Generic_Subprogram_Declaration
);
14979 end Is_Generic_Declaration_Or_Body
;
14981 ----------------------------
14982 -- Is_Inherited_Operation --
14983 ----------------------------
14985 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
14986 pragma Assert
(Is_Overloadable
(E
));
14987 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
14989 return Kind
= N_Full_Type_Declaration
14990 or else Kind
= N_Private_Extension_Declaration
14991 or else Kind
= N_Subtype_Declaration
14992 or else (Ekind
(E
) = E_Enumeration_Literal
14993 and then Is_Derived_Type
(Etype
(E
)));
14994 end Is_Inherited_Operation
;
14996 -------------------------------------
14997 -- Is_Inherited_Operation_For_Type --
14998 -------------------------------------
15000 function Is_Inherited_Operation_For_Type
15002 Typ
: Entity_Id
) return Boolean
15005 -- Check that the operation has been created by the type declaration
15007 return Is_Inherited_Operation
(E
)
15008 and then Defining_Identifier
(Parent
(E
)) = Typ
;
15009 end Is_Inherited_Operation_For_Type
;
15011 --------------------------------------
15012 -- Is_Inlinable_Expression_Function --
15013 --------------------------------------
15015 function Is_Inlinable_Expression_Function
15016 (Subp
: Entity_Id
) return Boolean
15018 Return_Expr
: Node_Id
;
15021 if Is_Expression_Function_Or_Completion
(Subp
)
15022 and then Has_Pragma_Inline_Always
(Subp
)
15023 and then Needs_No_Actuals
(Subp
)
15024 and then No
(Contract
(Subp
))
15025 and then not Is_Dispatching_Operation
(Subp
)
15026 and then Needs_Finalization
(Etype
(Subp
))
15027 and then not Is_Class_Wide_Type
(Etype
(Subp
))
15028 and then not (Has_Invariants
(Etype
(Subp
)))
15029 and then Present
(Subprogram_Body
(Subp
))
15030 and then Was_Expression_Function
(Subprogram_Body
(Subp
))
15032 Return_Expr
:= Expression_Of_Expression_Function
(Subp
);
15034 -- The returned object must not have a qualified expression and its
15035 -- nominal subtype must be statically compatible with the result
15036 -- subtype of the expression function.
15039 Nkind
(Return_Expr
) = N_Identifier
15040 and then Etype
(Return_Expr
) = Etype
(Subp
);
15044 end Is_Inlinable_Expression_Function
;
15050 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
15051 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean;
15052 -- Determine whether type Iter_Typ is a predefined forward or reversible
15055 ----------------------
15056 -- Denotes_Iterator --
15057 ----------------------
15059 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean is
15061 -- Check that the name matches, and that the ultimate ancestor is in
15062 -- a predefined unit, i.e the one that declares iterator interfaces.
15065 Nam_In
(Chars
(Iter_Typ
), Name_Forward_Iterator
,
15066 Name_Reversible_Iterator
)
15067 and then In_Predefined_Unit
(Root_Type
(Iter_Typ
));
15068 end Denotes_Iterator
;
15072 Iface_Elmt
: Elmt_Id
;
15075 -- Start of processing for Is_Iterator
15078 -- The type may be a subtype of a descendant of the proper instance of
15079 -- the predefined interface type, so we must use the root type of the
15080 -- given type. The same is done for Is_Reversible_Iterator.
15082 if Is_Class_Wide_Type
(Typ
)
15083 and then Denotes_Iterator
(Root_Type
(Typ
))
15087 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
15090 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
15094 Collect_Interfaces
(Typ
, Ifaces
);
15096 Iface_Elmt
:= First_Elmt
(Ifaces
);
15097 while Present
(Iface_Elmt
) loop
15098 if Denotes_Iterator
(Node
(Iface_Elmt
)) then
15102 Next_Elmt
(Iface_Elmt
);
15109 ----------------------------
15110 -- Is_Iterator_Over_Array --
15111 ----------------------------
15113 function Is_Iterator_Over_Array
(N
: Node_Id
) return Boolean is
15114 Container
: constant Node_Id
:= Name
(N
);
15115 Container_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Container
));
15117 return Is_Array_Type
(Container_Typ
);
15118 end Is_Iterator_Over_Array
;
15124 -- We seem to have a lot of overlapping functions that do similar things
15125 -- (testing for left hand sides or lvalues???).
15127 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
15128 P
: constant Node_Id
:= Parent
(N
);
15131 -- Return True if we are the left hand side of an assignment statement
15133 if Nkind
(P
) = N_Assignment_Statement
then
15134 if Name
(P
) = N
then
15140 -- Case of prefix of indexed or selected component or slice
15142 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
15143 and then N
= Prefix
(P
)
15145 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15146 -- If P is an LHS, then N is also effectively an LHS, but there
15147 -- is an important exception. If N is of an access type, then
15148 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15149 -- case this makes N.all a left hand side but not N itself.
15151 -- If we don't know the type yet, this is the case where we return
15152 -- Unknown, since the answer depends on the type which is unknown.
15154 if No
(Etype
(N
)) then
15157 -- We have an Etype set, so we can check it
15159 elsif Is_Access_Type
(Etype
(N
)) then
15162 -- OK, not access type case, so just test whole expression
15168 -- All other cases are not left hand sides
15175 -----------------------------
15176 -- Is_Library_Level_Entity --
15177 -----------------------------
15179 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
15181 -- The following is a small optimization, and it also properly handles
15182 -- discriminals, which in task bodies might appear in expressions before
15183 -- the corresponding procedure has been created, and which therefore do
15184 -- not have an assigned scope.
15186 if Is_Formal
(E
) then
15190 -- Normal test is simply that the enclosing dynamic scope is Standard
15192 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
15193 end Is_Library_Level_Entity
;
15195 --------------------------------
15196 -- Is_Limited_Class_Wide_Type --
15197 --------------------------------
15199 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
15202 Is_Class_Wide_Type
(Typ
)
15203 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
15204 end Is_Limited_Class_Wide_Type
;
15206 ---------------------------------
15207 -- Is_Local_Variable_Reference --
15208 ---------------------------------
15210 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
15212 if not Is_Entity_Name
(Expr
) then
15217 Ent
: constant Entity_Id
:= Entity
(Expr
);
15218 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
15220 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
15223 return Present
(Sub
) and then Sub
= Current_Subprogram
;
15227 end Is_Local_Variable_Reference
;
15229 -----------------------
15230 -- Is_Name_Reference --
15231 -----------------------
15233 function Is_Name_Reference
(N
: Node_Id
) return Boolean is
15235 if Is_Entity_Name
(N
) then
15236 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
15240 when N_Indexed_Component
15244 Is_Name_Reference
(Prefix
(N
))
15245 or else Is_Access_Type
(Etype
(Prefix
(N
)));
15247 -- Attributes 'Input, 'Old and 'Result produce objects
15249 when N_Attribute_Reference
=>
15251 Nam_In
(Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
15253 when N_Selected_Component
=>
15255 Is_Name_Reference
(Selector_Name
(N
))
15257 (Is_Name_Reference
(Prefix
(N
))
15258 or else Is_Access_Type
(Etype
(Prefix
(N
))));
15260 when N_Explicit_Dereference
=>
15263 -- A view conversion of a tagged name is a name reference
15265 when N_Type_Conversion
=>
15267 Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
15268 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
15269 and then Is_Name_Reference
(Expression
(N
));
15271 -- An unchecked type conversion is considered to be a name if the
15272 -- operand is a name (this construction arises only as a result of
15273 -- expansion activities).
15275 when N_Unchecked_Type_Conversion
=>
15276 return Is_Name_Reference
(Expression
(N
));
15281 end Is_Name_Reference
;
15283 ------------------------------------
15284 -- Is_Non_Preelaborable_Construct --
15285 ------------------------------------
15287 function Is_Non_Preelaborable_Construct
(N
: Node_Id
) return Boolean is
15289 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15290 -- intentionally unnested to avoid deep indentation of code.
15292 Non_Preelaborable
: exception;
15293 -- This exception is raised when the construct violates preelaborability
15294 -- to terminate the recursion.
15296 procedure Visit
(Nod
: Node_Id
);
15297 -- Semantically inspect construct Nod to determine whether it violates
15298 -- preelaborability. This routine raises Non_Preelaborable.
15300 procedure Visit_List
(List
: List_Id
);
15301 pragma Inline
(Visit_List
);
15302 -- Invoke Visit on each element of list List. This routine raises
15303 -- Non_Preelaborable.
15305 procedure Visit_Pragma
(Prag
: Node_Id
);
15306 pragma Inline
(Visit_Pragma
);
15307 -- Semantically inspect pragma Prag to determine whether it violates
15308 -- preelaborability. This routine raises Non_Preelaborable.
15310 procedure Visit_Subexpression
(Expr
: Node_Id
);
15311 pragma Inline
(Visit_Subexpression
);
15312 -- Semantically inspect expression Expr to determine whether it violates
15313 -- preelaborability. This routine raises Non_Preelaborable.
15319 procedure Visit
(Nod
: Node_Id
) is
15321 case Nkind
(Nod
) is
15325 when N_Component_Declaration
=>
15327 -- Defining_Identifier is left out because it is not relevant
15328 -- for preelaborability.
15330 Visit
(Component_Definition
(Nod
));
15331 Visit
(Expression
(Nod
));
15333 when N_Derived_Type_Definition
=>
15335 -- Interface_List is left out because it is not relevant for
15336 -- preelaborability.
15338 Visit
(Record_Extension_Part
(Nod
));
15339 Visit
(Subtype_Indication
(Nod
));
15341 when N_Entry_Declaration
=>
15343 -- A protected type with at leat one entry is not preelaborable
15344 -- while task types are never preelaborable. This renders entry
15345 -- declarations non-preelaborable.
15347 raise Non_Preelaborable
;
15349 when N_Full_Type_Declaration
=>
15351 -- Defining_Identifier and Discriminant_Specifications are left
15352 -- out because they are not relevant for preelaborability.
15354 Visit
(Type_Definition
(Nod
));
15356 when N_Function_Instantiation
15357 | N_Package_Instantiation
15358 | N_Procedure_Instantiation
15360 -- Defining_Unit_Name and Name are left out because they are
15361 -- not relevant for preelaborability.
15363 Visit_List
(Generic_Associations
(Nod
));
15365 when N_Object_Declaration
=>
15367 -- Defining_Identifier is left out because it is not relevant
15368 -- for preelaborability.
15370 Visit
(Object_Definition
(Nod
));
15372 if Has_Init_Expression
(Nod
) then
15373 Visit
(Expression
(Nod
));
15375 elsif not Has_Preelaborable_Initialization
15376 (Etype
(Defining_Entity
(Nod
)))
15378 raise Non_Preelaborable
;
15381 when N_Private_Extension_Declaration
15382 | N_Subtype_Declaration
15384 -- Defining_Identifier, Discriminant_Specifications, and
15385 -- Interface_List are left out because they are not relevant
15386 -- for preelaborability.
15388 Visit
(Subtype_Indication
(Nod
));
15390 when N_Protected_Type_Declaration
15391 | N_Single_Protected_Declaration
15393 -- Defining_Identifier, Discriminant_Specifications, and
15394 -- Interface_List are left out because they are not relevant
15395 -- for preelaborability.
15397 Visit
(Protected_Definition
(Nod
));
15399 -- A [single] task type is never preelaborable
15401 when N_Single_Task_Declaration
15402 | N_Task_Type_Declaration
15404 raise Non_Preelaborable
;
15409 Visit_Pragma
(Nod
);
15413 when N_Statement_Other_Than_Procedure_Call
=>
15414 if Nkind
(Nod
) /= N_Null_Statement
then
15415 raise Non_Preelaborable
;
15421 Visit_Subexpression
(Nod
);
15425 when N_Access_To_Object_Definition
=>
15426 Visit
(Subtype_Indication
(Nod
));
15428 when N_Case_Expression_Alternative
=>
15429 Visit
(Expression
(Nod
));
15430 Visit_List
(Discrete_Choices
(Nod
));
15432 when N_Component_Definition
=>
15433 Visit
(Access_Definition
(Nod
));
15434 Visit
(Subtype_Indication
(Nod
));
15436 when N_Component_List
=>
15437 Visit_List
(Component_Items
(Nod
));
15438 Visit
(Variant_Part
(Nod
));
15440 when N_Constrained_Array_Definition
=>
15441 Visit_List
(Discrete_Subtype_Definitions
(Nod
));
15442 Visit
(Component_Definition
(Nod
));
15444 when N_Delta_Constraint
15445 | N_Digits_Constraint
15447 -- Delta_Expression and Digits_Expression are left out because
15448 -- they are not relevant for preelaborability.
15450 Visit
(Range_Constraint
(Nod
));
15452 when N_Discriminant_Specification
=>
15454 -- Defining_Identifier and Expression are left out because they
15455 -- are not relevant for preelaborability.
15457 Visit
(Discriminant_Type
(Nod
));
15459 when N_Generic_Association
=>
15461 -- Selector_Name is left out because it is not relevant for
15462 -- preelaborability.
15464 Visit
(Explicit_Generic_Actual_Parameter
(Nod
));
15466 when N_Index_Or_Discriminant_Constraint
=>
15467 Visit_List
(Constraints
(Nod
));
15469 when N_Iterator_Specification
=>
15471 -- Defining_Identifier is left out because it is not relevant
15472 -- for preelaborability.
15474 Visit
(Name
(Nod
));
15475 Visit
(Subtype_Indication
(Nod
));
15477 when N_Loop_Parameter_Specification
=>
15479 -- Defining_Identifier is left out because it is not relevant
15480 -- for preelaborability.
15482 Visit
(Discrete_Subtype_Definition
(Nod
));
15484 when N_Protected_Definition
=>
15486 -- End_Label is left out because it is not relevant for
15487 -- preelaborability.
15489 Visit_List
(Private_Declarations
(Nod
));
15490 Visit_List
(Visible_Declarations
(Nod
));
15492 when N_Range_Constraint
=>
15493 Visit
(Range_Expression
(Nod
));
15495 when N_Record_Definition
15498 -- End_Label, Discrete_Choices, and Interface_List are left out
15499 -- because they are not relevant for preelaborability.
15501 Visit
(Component_List
(Nod
));
15503 when N_Subtype_Indication
=>
15505 -- Subtype_Mark is left out because it is not relevant for
15506 -- preelaborability.
15508 Visit
(Constraint
(Nod
));
15510 when N_Unconstrained_Array_Definition
=>
15512 -- Subtype_Marks is left out because it is not relevant for
15513 -- preelaborability.
15515 Visit
(Component_Definition
(Nod
));
15517 when N_Variant_Part
=>
15519 -- Name is left out because it is not relevant for
15520 -- preelaborability.
15522 Visit_List
(Variants
(Nod
));
15535 procedure Visit_List
(List
: List_Id
) is
15539 if Present
(List
) then
15540 Nod
:= First
(List
);
15541 while Present
(Nod
) loop
15552 procedure Visit_Pragma
(Prag
: Node_Id
) is
15554 case Get_Pragma_Id
(Prag
) is
15556 | Pragma_Assert_And_Cut
15558 | Pragma_Async_Readers
15559 | Pragma_Async_Writers
15560 | Pragma_Attribute_Definition
15562 | Pragma_Constant_After_Elaboration
15564 | Pragma_Deadline_Floor
15565 | Pragma_Dispatching_Domain
15566 | Pragma_Effective_Reads
15567 | Pragma_Effective_Writes
15568 | Pragma_Extensions_Visible
15570 | Pragma_Secondary_Stack_Size
15572 | Pragma_Volatile_Function
15574 Visit_List
(Pragma_Argument_Associations
(Prag
));
15583 -------------------------
15584 -- Visit_Subexpression --
15585 -------------------------
15587 procedure Visit_Subexpression
(Expr
: Node_Id
) is
15588 procedure Visit_Aggregate
(Aggr
: Node_Id
);
15589 pragma Inline
(Visit_Aggregate
);
15590 -- Semantically inspect aggregate Aggr to determine whether it
15591 -- violates preelaborability.
15593 ---------------------
15594 -- Visit_Aggregate --
15595 ---------------------
15597 procedure Visit_Aggregate
(Aggr
: Node_Id
) is
15599 if not Is_Preelaborable_Aggregate
(Aggr
) then
15600 raise Non_Preelaborable
;
15602 end Visit_Aggregate
;
15604 -- Start of processing for Visit_Subexpression
15607 case Nkind
(Expr
) is
15609 | N_Qualified_Expression
15610 | N_Type_Conversion
15611 | N_Unchecked_Expression
15612 | N_Unchecked_Type_Conversion
15614 -- Subpool_Handle_Name and Subtype_Mark are left out because
15615 -- they are not relevant for preelaborability.
15617 Visit
(Expression
(Expr
));
15620 | N_Extension_Aggregate
15622 Visit_Aggregate
(Expr
);
15624 when N_Attribute_Reference
15625 | N_Explicit_Dereference
15628 -- Attribute_Name and Expressions are left out because they are
15629 -- not relevant for preelaborability.
15631 Visit
(Prefix
(Expr
));
15633 when N_Case_Expression
=>
15635 -- End_Span is left out because it is not relevant for
15636 -- preelaborability.
15638 Visit_List
(Alternatives
(Expr
));
15639 Visit
(Expression
(Expr
));
15641 when N_Delta_Aggregate
=>
15642 Visit_Aggregate
(Expr
);
15643 Visit
(Expression
(Expr
));
15645 when N_Expression_With_Actions
=>
15646 Visit_List
(Actions
(Expr
));
15647 Visit
(Expression
(Expr
));
15649 when N_If_Expression
=>
15650 Visit_List
(Expressions
(Expr
));
15652 when N_Quantified_Expression
=>
15653 Visit
(Condition
(Expr
));
15654 Visit
(Iterator_Specification
(Expr
));
15655 Visit
(Loop_Parameter_Specification
(Expr
));
15658 Visit
(High_Bound
(Expr
));
15659 Visit
(Low_Bound
(Expr
));
15662 Visit
(Discrete_Range
(Expr
));
15663 Visit
(Prefix
(Expr
));
15669 -- The evaluation of an object name is not preelaborable,
15670 -- unless the name is a static expression (checked further
15671 -- below), or statically denotes a discriminant.
15673 if Is_Entity_Name
(Expr
) then
15674 Object_Name
: declare
15675 Id
: constant Entity_Id
:= Entity
(Expr
);
15678 if Is_Object
(Id
) then
15679 if Ekind
(Id
) = E_Discriminant
then
15682 elsif Ekind_In
(Id
, E_Constant
, E_In_Parameter
)
15683 and then Present
(Discriminal_Link
(Id
))
15688 raise Non_Preelaborable
;
15693 -- A non-static expression is not preelaborable
15695 elsif not Is_OK_Static_Expression
(Expr
) then
15696 raise Non_Preelaborable
;
15699 end Visit_Subexpression
;
15701 -- Start of processing for Is_Non_Preelaborable_Construct
15706 -- At this point it is known that the construct is preelaborable
15712 -- The elaboration of the construct performs an action which violates
15713 -- preelaborability.
15715 when Non_Preelaborable
=>
15717 end Is_Non_Preelaborable_Construct
;
15719 ---------------------------------
15720 -- Is_Nontrivial_DIC_Procedure --
15721 ---------------------------------
15723 function Is_Nontrivial_DIC_Procedure
(Id
: Entity_Id
) return Boolean is
15724 Body_Decl
: Node_Id
;
15728 if Ekind
(Id
) = E_Procedure
and then Is_DIC_Procedure
(Id
) then
15730 Unit_Declaration_Node
15731 (Corresponding_Body
(Unit_Declaration_Node
(Id
)));
15733 -- The body of the Default_Initial_Condition procedure must contain
15734 -- at least one statement, otherwise the generation of the subprogram
15737 pragma Assert
(Present
(Handled_Statement_Sequence
(Body_Decl
)));
15739 -- To qualify as nontrivial, the first statement of the procedure
15740 -- must be a check in the form of an if statement. If the original
15741 -- Default_Initial_Condition expression was folded, then the first
15742 -- statement is not a check.
15744 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Body_Decl
)));
15747 Nkind
(Stmt
) = N_If_Statement
15748 and then Nkind
(Original_Node
(Stmt
)) = N_Pragma
;
15752 end Is_Nontrivial_DIC_Procedure
;
15754 -------------------------
15755 -- Is_Null_Record_Type --
15756 -------------------------
15758 function Is_Null_Record_Type
(T
: Entity_Id
) return Boolean is
15759 Decl
: constant Node_Id
:= Parent
(T
);
15761 return Nkind
(Decl
) = N_Full_Type_Declaration
15762 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
15764 (No
(Component_List
(Type_Definition
(Decl
)))
15765 or else Null_Present
(Component_List
(Type_Definition
(Decl
))));
15766 end Is_Null_Record_Type
;
15768 ---------------------
15769 -- Is_Object_Image --
15770 ---------------------
15772 function Is_Object_Image
(Prefix
: Node_Id
) return Boolean is
15774 -- When the type of the prefix is not scalar, then the prefix is not
15775 -- valid in any scenario.
15777 if not Is_Scalar_Type
(Etype
(Prefix
)) then
15781 -- Here we test for the case that the prefix is not a type and assume
15782 -- if it is not then it must be a named value or an object reference.
15783 -- This is because the parser always checks that prefixes of attributes
15786 return not (Is_Entity_Name
(Prefix
) and then Is_Type
(Entity
(Prefix
)));
15787 end Is_Object_Image
;
15789 -------------------------
15790 -- Is_Object_Reference --
15791 -------------------------
15793 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
15794 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
15795 -- Determine whether N is the name of an internally-generated renaming
15797 --------------------------------------
15798 -- Is_Internally_Generated_Renaming --
15799 --------------------------------------
15801 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
15806 while Present
(P
) loop
15807 if Nkind
(P
) = N_Object_Renaming_Declaration
then
15808 return not Comes_From_Source
(P
);
15809 elsif Is_List_Member
(P
) then
15817 end Is_Internally_Generated_Renaming
;
15819 -- Start of processing for Is_Object_Reference
15822 if Is_Entity_Name
(N
) then
15823 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
15827 when N_Indexed_Component
15831 Is_Object_Reference
(Prefix
(N
))
15832 or else Is_Access_Type
(Etype
(Prefix
(N
)));
15834 -- In Ada 95, a function call is a constant object; a procedure
15837 -- Note that predefined operators are functions as well, and so
15838 -- are attributes that are (can be renamed as) functions.
15844 return Etype
(N
) /= Standard_Void_Type
;
15846 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
15847 -- objects, even though they are not functions.
15849 when N_Attribute_Reference
=>
15851 Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
15854 or else Is_Function_Attribute_Name
(Attribute_Name
(N
));
15856 when N_Selected_Component
=>
15858 Is_Object_Reference
(Selector_Name
(N
))
15860 (Is_Object_Reference
(Prefix
(N
))
15861 or else Is_Access_Type
(Etype
(Prefix
(N
))));
15863 -- An explicit dereference denotes an object, except that a
15864 -- conditional expression gets turned into an explicit dereference
15865 -- in some cases, and conditional expressions are not object
15868 when N_Explicit_Dereference
=>
15869 return not Nkind_In
(Original_Node
(N
), N_Case_Expression
,
15872 -- A view conversion of a tagged object is an object reference
15874 when N_Type_Conversion
=>
15875 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
15876 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
15877 and then Is_Object_Reference
(Expression
(N
));
15879 -- An unchecked type conversion is considered to be an object if
15880 -- the operand is an object (this construction arises only as a
15881 -- result of expansion activities).
15883 when N_Unchecked_Type_Conversion
=>
15886 -- Allow string literals to act as objects as long as they appear
15887 -- in internally-generated renamings. The expansion of iterators
15888 -- may generate such renamings when the range involves a string
15891 when N_String_Literal
=>
15892 return Is_Internally_Generated_Renaming
(Parent
(N
));
15894 -- AI05-0003: In Ada 2012 a qualified expression is a name.
15895 -- This allows disambiguation of function calls and the use
15896 -- of aggregates in more contexts.
15898 when N_Qualified_Expression
=>
15899 if Ada_Version
< Ada_2012
then
15902 return Is_Object_Reference
(Expression
(N
))
15903 or else Nkind
(Expression
(N
)) = N_Aggregate
;
15910 end Is_Object_Reference
;
15912 -----------------------------------
15913 -- Is_OK_Variable_For_Out_Formal --
15914 -----------------------------------
15916 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
15918 Note_Possible_Modification
(AV
, Sure
=> True);
15920 -- We must reject parenthesized variable names. Comes_From_Source is
15921 -- checked because there are currently cases where the compiler violates
15922 -- this rule (e.g. passing a task object to its controlled Initialize
15923 -- routine). This should be properly documented in sinfo???
15925 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
15928 -- A variable is always allowed
15930 elsif Is_Variable
(AV
) then
15933 -- Generalized indexing operations are rewritten as explicit
15934 -- dereferences, and it is only during resolution that we can
15935 -- check whether the context requires an access_to_variable type.
15937 elsif Nkind
(AV
) = N_Explicit_Dereference
15938 and then Ada_Version
>= Ada_2012
15939 and then Nkind
(Original_Node
(AV
)) = N_Indexed_Component
15940 and then Present
(Etype
(Original_Node
(AV
)))
15941 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
15943 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
15945 -- Unchecked conversions are allowed only if they come from the
15946 -- generated code, which sometimes uses unchecked conversions for out
15947 -- parameters in cases where code generation is unaffected. We tell
15948 -- source unchecked conversions by seeing if they are rewrites of
15949 -- an original Unchecked_Conversion function call, or of an explicit
15950 -- conversion of a function call or an aggregate (as may happen in the
15951 -- expansion of a packed array aggregate).
15953 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
15954 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
15957 elsif Comes_From_Source
(AV
)
15958 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
15962 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
15963 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
15969 -- Normal type conversions are allowed if argument is a variable
15971 elsif Nkind
(AV
) = N_Type_Conversion
then
15972 if Is_Variable
(Expression
(AV
))
15973 and then Paren_Count
(Expression
(AV
)) = 0
15975 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
15978 -- We also allow a non-parenthesized expression that raises
15979 -- constraint error if it rewrites what used to be a variable
15981 elsif Raises_Constraint_Error
(Expression
(AV
))
15982 and then Paren_Count
(Expression
(AV
)) = 0
15983 and then Is_Variable
(Original_Node
(Expression
(AV
)))
15987 -- Type conversion of something other than a variable
15993 -- If this node is rewritten, then test the original form, if that is
15994 -- OK, then we consider the rewritten node OK (for example, if the
15995 -- original node is a conversion, then Is_Variable will not be true
15996 -- but we still want to allow the conversion if it converts a variable).
15998 elsif Is_Rewrite_Substitution
(AV
) then
16000 -- In Ada 2012, the explicit dereference may be a rewritten call to a
16001 -- Reference function.
16003 if Ada_Version
>= Ada_2012
16004 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
16006 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
16009 -- Check that this is not a constant reference.
16011 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
16013 elsif Has_Implicit_Dereference
(Etype
(Original_Node
(AV
))) then
16015 not Is_Access_Constant
(Etype
16016 (Get_Reference_Discriminant
(Etype
(Original_Node
(AV
)))));
16019 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
16022 -- All other non-variables are rejected
16027 end Is_OK_Variable_For_Out_Formal
;
16029 ----------------------------
16030 -- Is_OK_Volatile_Context --
16031 ----------------------------
16033 function Is_OK_Volatile_Context
16034 (Context
: Node_Id
;
16035 Obj_Ref
: Node_Id
) return Boolean
16037 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean;
16038 -- Determine whether an arbitrary node denotes a call to a protected
16039 -- entry, function, or procedure in prefixed form where the prefix is
16042 function Within_Check
(Nod
: Node_Id
) return Boolean;
16043 -- Determine whether an arbitrary node appears in a check node
16045 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean;
16046 -- Determine whether an arbitrary entity appears in a volatile function
16048 ---------------------------------
16049 -- Is_Protected_Operation_Call --
16050 ---------------------------------
16052 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean is
16057 -- A call to a protected operations retains its selected component
16058 -- form as opposed to other prefixed calls that are transformed in
16061 if Nkind
(Nod
) = N_Selected_Component
then
16062 Pref
:= Prefix
(Nod
);
16063 Subp
:= Selector_Name
(Nod
);
16067 and then Present
(Etype
(Pref
))
16068 and then Is_Protected_Type
(Etype
(Pref
))
16069 and then Is_Entity_Name
(Subp
)
16070 and then Present
(Entity
(Subp
))
16071 and then Ekind_In
(Entity
(Subp
), E_Entry
,
16078 end Is_Protected_Operation_Call
;
16084 function Within_Check
(Nod
: Node_Id
) return Boolean is
16088 -- Climb the parent chain looking for a check node
16091 while Present
(Par
) loop
16092 if Nkind
(Par
) in N_Raise_xxx_Error
then
16095 -- Prevent the search from going too far
16097 elsif Is_Body_Or_Package_Declaration
(Par
) then
16101 Par
:= Parent
(Par
);
16107 ------------------------------
16108 -- Within_Volatile_Function --
16109 ------------------------------
16111 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean is
16112 Func_Id
: Entity_Id
;
16115 -- Traverse the scope stack looking for a [generic] function
16118 while Present
(Func_Id
) and then Func_Id
/= Standard_Standard
loop
16119 if Ekind_In
(Func_Id
, E_Function
, E_Generic_Function
) then
16120 return Is_Volatile_Function
(Func_Id
);
16123 Func_Id
:= Scope
(Func_Id
);
16127 end Within_Volatile_Function
;
16131 Obj_Id
: Entity_Id
;
16133 -- Start of processing for Is_OK_Volatile_Context
16136 -- The volatile object appears on either side of an assignment
16138 if Nkind
(Context
) = N_Assignment_Statement
then
16141 -- The volatile object is part of the initialization expression of
16144 elsif Nkind
(Context
) = N_Object_Declaration
16145 and then Present
(Expression
(Context
))
16146 and then Expression
(Context
) = Obj_Ref
16148 Obj_Id
:= Defining_Entity
(Context
);
16150 -- The volatile object acts as the initialization expression of an
16151 -- extended return statement. This is valid context as long as the
16152 -- function is volatile.
16154 if Is_Return_Object
(Obj_Id
) then
16155 return Within_Volatile_Function
(Obj_Id
);
16157 -- Otherwise this is a normal object initialization
16163 -- The volatile object acts as the name of a renaming declaration
16165 elsif Nkind
(Context
) = N_Object_Renaming_Declaration
16166 and then Name
(Context
) = Obj_Ref
16170 -- The volatile object appears as an actual parameter in a call to an
16171 -- instance of Unchecked_Conversion whose result is renamed.
16173 elsif Nkind
(Context
) = N_Function_Call
16174 and then Is_Entity_Name
(Name
(Context
))
16175 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
16176 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
16180 -- The volatile object is actually the prefix in a protected entry,
16181 -- function, or procedure call.
16183 elsif Is_Protected_Operation_Call
(Context
) then
16186 -- The volatile object appears as the expression of a simple return
16187 -- statement that applies to a volatile function.
16189 elsif Nkind
(Context
) = N_Simple_Return_Statement
16190 and then Expression
(Context
) = Obj_Ref
16193 Within_Volatile_Function
(Return_Statement_Entity
(Context
));
16195 -- The volatile object appears as the prefix of a name occurring in a
16196 -- non-interfering context.
16198 elsif Nkind_In
(Context
, N_Attribute_Reference
,
16199 N_Explicit_Dereference
,
16200 N_Indexed_Component
,
16201 N_Selected_Component
,
16203 and then Prefix
(Context
) = Obj_Ref
16204 and then Is_OK_Volatile_Context
16205 (Context
=> Parent
(Context
),
16206 Obj_Ref
=> Context
)
16210 -- The volatile object appears as the prefix of attributes Address,
16211 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16212 -- Position, Size, Storage_Size.
16214 elsif Nkind
(Context
) = N_Attribute_Reference
16215 and then Prefix
(Context
) = Obj_Ref
16216 and then Nam_In
(Attribute_Name
(Context
), Name_Address
,
16218 Name_Component_Size
,
16230 -- The volatile object appears as the expression of a type conversion
16231 -- occurring in a non-interfering context.
16233 elsif Nkind_In
(Context
, N_Type_Conversion
,
16234 N_Unchecked_Type_Conversion
)
16235 and then Expression
(Context
) = Obj_Ref
16236 and then Is_OK_Volatile_Context
16237 (Context
=> Parent
(Context
),
16238 Obj_Ref
=> Context
)
16242 -- The volatile object appears as the expression in a delay statement
16244 elsif Nkind
(Context
) in N_Delay_Statement
then
16247 -- Allow references to volatile objects in various checks. This is not a
16248 -- direct SPARK 2014 requirement.
16250 elsif Within_Check
(Context
) then
16253 -- Assume that references to effectively volatile objects that appear
16254 -- as actual parameters in a subprogram call are always legal. A full
16255 -- legality check is done when the actuals are resolved (see routine
16256 -- Resolve_Actuals).
16258 elsif Within_Subprogram_Call
(Context
) then
16261 -- Otherwise the context is not suitable for an effectively volatile
16267 end Is_OK_Volatile_Context
;
16269 ------------------------------------
16270 -- Is_Package_Contract_Annotation --
16271 ------------------------------------
16273 function Is_Package_Contract_Annotation
(Item
: Node_Id
) return Boolean is
16277 if Nkind
(Item
) = N_Aspect_Specification
then
16278 Nam
:= Chars
(Identifier
(Item
));
16280 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
16281 Nam
:= Pragma_Name
(Item
);
16284 return Nam
= Name_Abstract_State
16285 or else Nam
= Name_Initial_Condition
16286 or else Nam
= Name_Initializes
16287 or else Nam
= Name_Refined_State
;
16288 end Is_Package_Contract_Annotation
;
16290 -----------------------------------
16291 -- Is_Partially_Initialized_Type --
16292 -----------------------------------
16294 function Is_Partially_Initialized_Type
16296 Include_Implicit
: Boolean := True) return Boolean
16299 if Is_Scalar_Type
(Typ
) then
16302 elsif Is_Access_Type
(Typ
) then
16303 return Include_Implicit
;
16305 elsif Is_Array_Type
(Typ
) then
16307 -- If component type is partially initialized, so is array type
16309 if Is_Partially_Initialized_Type
16310 (Component_Type
(Typ
), Include_Implicit
)
16314 -- Otherwise we are only partially initialized if we are fully
16315 -- initialized (this is the empty array case, no point in us
16316 -- duplicating that code here).
16319 return Is_Fully_Initialized_Type
(Typ
);
16322 elsif Is_Record_Type
(Typ
) then
16324 -- A discriminated type is always partially initialized if in
16327 if Has_Discriminants
(Typ
) and then Include_Implicit
then
16330 -- A tagged type is always partially initialized
16332 elsif Is_Tagged_Type
(Typ
) then
16335 -- Case of non-discriminated record
16341 Component_Present
: Boolean := False;
16342 -- Set True if at least one component is present. If no
16343 -- components are present, then record type is fully
16344 -- initialized (another odd case, like the null array).
16347 -- Loop through components
16349 Ent
:= First_Entity
(Typ
);
16350 while Present
(Ent
) loop
16351 if Ekind
(Ent
) = E_Component
then
16352 Component_Present
:= True;
16354 -- If a component has an initialization expression then
16355 -- the enclosing record type is partially initialized
16357 if Present
(Parent
(Ent
))
16358 and then Present
(Expression
(Parent
(Ent
)))
16362 -- If a component is of a type which is itself partially
16363 -- initialized, then the enclosing record type is also.
16365 elsif Is_Partially_Initialized_Type
16366 (Etype
(Ent
), Include_Implicit
)
16375 -- No initialized components found. If we found any components
16376 -- they were all uninitialized so the result is false.
16378 if Component_Present
then
16381 -- But if we found no components, then all the components are
16382 -- initialized so we consider the type to be initialized.
16390 -- Concurrent types are always fully initialized
16392 elsif Is_Concurrent_Type
(Typ
) then
16395 -- For a private type, go to underlying type. If there is no underlying
16396 -- type then just assume this partially initialized. Not clear if this
16397 -- can happen in a non-error case, but no harm in testing for this.
16399 elsif Is_Private_Type
(Typ
) then
16401 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
16406 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
16410 -- For any other type (are there any?) assume partially initialized
16415 end Is_Partially_Initialized_Type
;
16417 ------------------------------------
16418 -- Is_Potentially_Persistent_Type --
16419 ------------------------------------
16421 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
16426 -- For private type, test corresponding full type
16428 if Is_Private_Type
(T
) then
16429 return Is_Potentially_Persistent_Type
(Full_View
(T
));
16431 -- Scalar types are potentially persistent
16433 elsif Is_Scalar_Type
(T
) then
16436 -- Record type is potentially persistent if not tagged and the types of
16437 -- all it components are potentially persistent, and no component has
16438 -- an initialization expression.
16440 elsif Is_Record_Type
(T
)
16441 and then not Is_Tagged_Type
(T
)
16442 and then not Is_Partially_Initialized_Type
(T
)
16444 Comp
:= First_Component
(T
);
16445 while Present
(Comp
) loop
16446 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
16449 Next_Entity
(Comp
);
16455 -- Array type is potentially persistent if its component type is
16456 -- potentially persistent and if all its constraints are static.
16458 elsif Is_Array_Type
(T
) then
16459 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
16463 Indx
:= First_Index
(T
);
16464 while Present
(Indx
) loop
16465 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
16474 -- All other types are not potentially persistent
16479 end Is_Potentially_Persistent_Type
;
16481 --------------------------------
16482 -- Is_Potentially_Unevaluated --
16483 --------------------------------
16485 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
16493 -- A postcondition whose expression is a short-circuit is broken down
16494 -- into individual aspects for better exception reporting. The original
16495 -- short-circuit expression is rewritten as the second operand, and an
16496 -- occurrence of 'Old in that operand is potentially unevaluated.
16497 -- See sem_ch13.adb for details of this transformation. The reference
16498 -- to 'Old may appear within an expression, so we must look for the
16499 -- enclosing pragma argument in the tree that contains the reference.
16501 while Present
(Par
)
16502 and then Nkind
(Par
) /= N_Pragma_Argument_Association
16504 if Is_Rewrite_Substitution
(Par
)
16505 and then Nkind
(Original_Node
(Par
)) = N_And_Then
16510 Par
:= Parent
(Par
);
16513 -- Other cases; 'Old appears within other expression (not the top-level
16514 -- conjunct in a postcondition) with a potentially unevaluated operand.
16516 Par
:= Parent
(Expr
);
16517 while not Nkind_In
(Par
, N_And_Then
,
16523 N_Quantified_Expression
)
16526 Par
:= Parent
(Par
);
16528 -- If the context is not an expression, or if is the result of
16529 -- expansion of an enclosing construct (such as another attribute)
16530 -- the predicate does not apply.
16532 if Nkind
(Par
) = N_Case_Expression_Alternative
then
16535 elsif Nkind
(Par
) not in N_Subexpr
16536 or else not Comes_From_Source
(Par
)
16542 if Nkind
(Par
) = N_If_Expression
then
16543 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
16545 elsif Nkind
(Par
) = N_Case_Expression
then
16546 return Expr
/= Expression
(Par
);
16548 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
16549 return Expr
= Right_Opnd
(Par
);
16551 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
16553 -- If the membership includes several alternatives, only the first is
16554 -- definitely evaluated.
16556 if Present
(Alternatives
(Par
)) then
16557 return Expr
/= First
(Alternatives
(Par
));
16559 -- If this is a range membership both bounds are evaluated
16565 elsif Nkind
(Par
) = N_Quantified_Expression
then
16566 return Expr
= Condition
(Par
);
16571 end Is_Potentially_Unevaluated
;
16573 -----------------------------------------
16574 -- Is_Predefined_Dispatching_Operation --
16575 -----------------------------------------
16577 function Is_Predefined_Dispatching_Operation
16578 (E
: Entity_Id
) return Boolean
16580 TSS_Name
: TSS_Name_Type
;
16583 if not Is_Dispatching_Operation
(E
) then
16587 Get_Name_String
(Chars
(E
));
16589 -- Most predefined primitives have internally generated names. Equality
16590 -- must be treated differently; the predefined operation is recognized
16591 -- as a homogeneous binary operator that returns Boolean.
16593 if Name_Len
> TSS_Name_Type
'Last then
16596 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
16598 if Nam_In
(Chars
(E
), Name_uAssign
, Name_uSize
)
16600 (Chars
(E
) = Name_Op_Eq
16601 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
16602 or else TSS_Name
= TSS_Deep_Adjust
16603 or else TSS_Name
= TSS_Deep_Finalize
16604 or else TSS_Name
= TSS_Stream_Input
16605 or else TSS_Name
= TSS_Stream_Output
16606 or else TSS_Name
= TSS_Stream_Read
16607 or else TSS_Name
= TSS_Stream_Write
16608 or else Is_Predefined_Interface_Primitive
(E
)
16615 end Is_Predefined_Dispatching_Operation
;
16617 ---------------------------------------
16618 -- Is_Predefined_Interface_Primitive --
16619 ---------------------------------------
16621 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
16623 -- In VM targets we don't restrict the functionality of this test to
16624 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16625 -- these primitives.
16627 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
16628 and then Nam_In
(Chars
(E
), Name_uDisp_Asynchronous_Select
,
16629 Name_uDisp_Conditional_Select
,
16630 Name_uDisp_Get_Prim_Op_Kind
,
16631 Name_uDisp_Get_Task_Id
,
16632 Name_uDisp_Requeue
,
16633 Name_uDisp_Timed_Select
);
16634 end Is_Predefined_Interface_Primitive
;
16636 ---------------------------------------
16637 -- Is_Predefined_Internal_Operation --
16638 ---------------------------------------
16640 function Is_Predefined_Internal_Operation
16641 (E
: Entity_Id
) return Boolean
16643 TSS_Name
: TSS_Name_Type
;
16646 if not Is_Dispatching_Operation
(E
) then
16650 Get_Name_String
(Chars
(E
));
16652 -- Most predefined primitives have internally generated names. Equality
16653 -- must be treated differently; the predefined operation is recognized
16654 -- as a homogeneous binary operator that returns Boolean.
16656 if Name_Len
> TSS_Name_Type
'Last then
16659 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
16661 if Nam_In
(Chars
(E
), Name_uSize
, Name_uAssign
)
16663 (Chars
(E
) = Name_Op_Eq
16664 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
16665 or else TSS_Name
= TSS_Deep_Adjust
16666 or else TSS_Name
= TSS_Deep_Finalize
16667 or else Is_Predefined_Interface_Primitive
(E
)
16674 end Is_Predefined_Internal_Operation
;
16676 --------------------------------
16677 -- Is_Preelaborable_Aggregate --
16678 --------------------------------
16680 function Is_Preelaborable_Aggregate
(Aggr
: Node_Id
) return Boolean is
16681 Aggr_Typ
: constant Entity_Id
:= Etype
(Aggr
);
16682 Array_Aggr
: constant Boolean := Is_Array_Type
(Aggr_Typ
);
16684 Anc_Part
: Node_Id
;
16687 Comp_Typ
: Entity_Id
:= Empty
; -- init to avoid warning
16692 Comp_Typ
:= Component_Type
(Aggr_Typ
);
16695 -- Inspect the ancestor part
16697 if Nkind
(Aggr
) = N_Extension_Aggregate
then
16698 Anc_Part
:= Ancestor_Part
(Aggr
);
16700 -- The ancestor denotes a subtype mark
16702 if Is_Entity_Name
(Anc_Part
)
16703 and then Is_Type
(Entity
(Anc_Part
))
16705 if not Has_Preelaborable_Initialization
(Entity
(Anc_Part
)) then
16709 -- Otherwise the ancestor denotes an expression
16711 elsif not Is_Preelaborable_Construct
(Anc_Part
) then
16716 -- Inspect the positional associations
16718 Expr
:= First
(Expressions
(Aggr
));
16719 while Present
(Expr
) loop
16720 if not Is_Preelaborable_Construct
(Expr
) then
16727 -- Inspect the named associations
16729 Assoc
:= First
(Component_Associations
(Aggr
));
16730 while Present
(Assoc
) loop
16732 -- Inspect the choices of the current named association
16734 Choice
:= First
(Choices
(Assoc
));
16735 while Present
(Choice
) loop
16738 -- For a choice to be preelaborable, it must denote either a
16739 -- static range or a static expression.
16741 if Nkind
(Choice
) = N_Others_Choice
then
16744 elsif Nkind
(Choice
) = N_Range
then
16745 if not Is_OK_Static_Range
(Choice
) then
16749 elsif not Is_OK_Static_Expression
(Choice
) then
16754 Comp_Typ
:= Etype
(Choice
);
16760 -- The type of the choice must have preelaborable initialization if
16761 -- the association carries a <>.
16763 pragma Assert
(Present
(Comp_Typ
));
16764 if Box_Present
(Assoc
) then
16765 if not Has_Preelaborable_Initialization
(Comp_Typ
) then
16769 -- The type of the expression must have preelaborable initialization
16771 elsif not Is_Preelaborable_Construct
(Expression
(Assoc
)) then
16778 -- At this point the aggregate is preelaborable
16781 end Is_Preelaborable_Aggregate
;
16783 --------------------------------
16784 -- Is_Preelaborable_Construct --
16785 --------------------------------
16787 function Is_Preelaborable_Construct
(N
: Node_Id
) return Boolean is
16791 if Nkind_In
(N
, N_Aggregate
, N_Extension_Aggregate
) then
16792 return Is_Preelaborable_Aggregate
(N
);
16794 -- Attributes are allowed in general, even if their prefix is a formal
16795 -- type. It seems that certain attributes known not to be static might
16796 -- not be allowed, but there are no rules to prevent them.
16798 elsif Nkind
(N
) = N_Attribute_Reference
then
16803 elsif Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
16806 elsif Nkind
(N
) = N_Qualified_Expression
then
16807 return Is_Preelaborable_Construct
(Expression
(N
));
16809 -- Names are preelaborable when they denote a discriminant of an
16810 -- enclosing type. Discriminals are also considered for this check.
16812 elsif Is_Entity_Name
(N
)
16813 and then Present
(Entity
(N
))
16815 (Ekind
(Entity
(N
)) = E_Discriminant
16816 or else (Ekind_In
(Entity
(N
), E_Constant
, E_In_Parameter
)
16817 and then Present
(Discriminal_Link
(Entity
(N
)))))
16823 elsif Nkind
(N
) = N_Null
then
16826 -- Otherwise the construct is not preelaborable
16831 end Is_Preelaborable_Construct
;
16833 ---------------------------------
16834 -- Is_Protected_Self_Reference --
16835 ---------------------------------
16837 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
16839 function In_Access_Definition
(N
: Node_Id
) return Boolean;
16840 -- Returns true if N belongs to an access definition
16842 --------------------------
16843 -- In_Access_Definition --
16844 --------------------------
16846 function In_Access_Definition
(N
: Node_Id
) return Boolean is
16851 while Present
(P
) loop
16852 if Nkind
(P
) = N_Access_Definition
then
16860 end In_Access_Definition
;
16862 -- Start of processing for Is_Protected_Self_Reference
16865 -- Verify that prefix is analyzed and has the proper form. Note that
16866 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
16867 -- produce the address of an entity, do not analyze their prefix
16868 -- because they denote entities that are not necessarily visible.
16869 -- Neither of them can apply to a protected type.
16871 return Ada_Version
>= Ada_2005
16872 and then Is_Entity_Name
(N
)
16873 and then Present
(Entity
(N
))
16874 and then Is_Protected_Type
(Entity
(N
))
16875 and then In_Open_Scopes
(Entity
(N
))
16876 and then not In_Access_Definition
(N
);
16877 end Is_Protected_Self_Reference
;
16879 -----------------------------
16880 -- Is_RCI_Pkg_Spec_Or_Body --
16881 -----------------------------
16883 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
16885 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
16886 -- Return True if the unit of Cunit is an RCI package declaration
16888 ---------------------------
16889 -- Is_RCI_Pkg_Decl_Cunit --
16890 ---------------------------
16892 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
16893 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
16896 if Nkind
(The_Unit
) /= N_Package_Declaration
then
16900 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
16901 end Is_RCI_Pkg_Decl_Cunit
;
16903 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
16906 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
16908 (Nkind
(Unit
(Cunit
)) = N_Package_Body
16909 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
16910 end Is_RCI_Pkg_Spec_Or_Body
;
16912 -----------------------------------------
16913 -- Is_Remote_Access_To_Class_Wide_Type --
16914 -----------------------------------------
16916 function Is_Remote_Access_To_Class_Wide_Type
16917 (E
: Entity_Id
) return Boolean
16920 -- A remote access to class-wide type is a general access to object type
16921 -- declared in the visible part of a Remote_Types or Remote_Call_
16924 return Ekind
(E
) = E_General_Access_Type
16925 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
16926 end Is_Remote_Access_To_Class_Wide_Type
;
16928 -----------------------------------------
16929 -- Is_Remote_Access_To_Subprogram_Type --
16930 -----------------------------------------
16932 function Is_Remote_Access_To_Subprogram_Type
16933 (E
: Entity_Id
) return Boolean
16936 return (Ekind
(E
) = E_Access_Subprogram_Type
16937 or else (Ekind
(E
) = E_Record_Type
16938 and then Present
(Corresponding_Remote_Type
(E
))))
16939 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
16940 end Is_Remote_Access_To_Subprogram_Type
;
16942 --------------------
16943 -- Is_Remote_Call --
16944 --------------------
16946 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
16948 if Nkind
(N
) not in N_Subprogram_Call
then
16950 -- An entry call cannot be remote
16954 elsif Nkind
(Name
(N
)) in N_Has_Entity
16955 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
16957 -- A subprogram declared in the spec of a RCI package is remote
16961 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
16962 and then Is_Remote_Access_To_Subprogram_Type
16963 (Etype
(Prefix
(Name
(N
))))
16965 -- The dereference of a RAS is a remote call
16969 elsif Present
(Controlling_Argument
(N
))
16970 and then Is_Remote_Access_To_Class_Wide_Type
16971 (Etype
(Controlling_Argument
(N
)))
16973 -- Any primitive operation call with a controlling argument of
16974 -- a RACW type is a remote call.
16979 -- All other calls are local calls
16982 end Is_Remote_Call
;
16984 ----------------------
16985 -- Is_Renamed_Entry --
16986 ----------------------
16988 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
16989 Orig_Node
: Node_Id
:= Empty
;
16990 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
16992 function Is_Entry
(Nam
: Node_Id
) return Boolean;
16993 -- Determine whether Nam is an entry. Traverse selectors if there are
16994 -- nested selected components.
17000 function Is_Entry
(Nam
: Node_Id
) return Boolean is
17002 if Nkind
(Nam
) = N_Selected_Component
then
17003 return Is_Entry
(Selector_Name
(Nam
));
17006 return Ekind
(Entity
(Nam
)) = E_Entry
;
17009 -- Start of processing for Is_Renamed_Entry
17012 if Present
(Alias
(Proc_Nam
)) then
17013 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
17016 -- Look for a rewritten subprogram renaming declaration
17018 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
17019 and then Present
(Original_Node
(Subp_Decl
))
17021 Orig_Node
:= Original_Node
(Subp_Decl
);
17024 -- The rewritten subprogram is actually an entry
17026 if Present
(Orig_Node
)
17027 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
17028 and then Is_Entry
(Name
(Orig_Node
))
17034 end Is_Renamed_Entry
;
17036 -----------------------------
17037 -- Is_Renaming_Declaration --
17038 -----------------------------
17040 function Is_Renaming_Declaration
(N
: Node_Id
) return Boolean is
17043 when N_Exception_Renaming_Declaration
17044 | N_Generic_Function_Renaming_Declaration
17045 | N_Generic_Package_Renaming_Declaration
17046 | N_Generic_Procedure_Renaming_Declaration
17047 | N_Object_Renaming_Declaration
17048 | N_Package_Renaming_Declaration
17049 | N_Subprogram_Renaming_Declaration
17056 end Is_Renaming_Declaration
;
17058 ----------------------------
17059 -- Is_Reversible_Iterator --
17060 ----------------------------
17062 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
17063 Ifaces_List
: Elist_Id
;
17064 Iface_Elmt
: Elmt_Id
;
17068 if Is_Class_Wide_Type
(Typ
)
17069 and then Chars
(Root_Type
(Typ
)) = Name_Reversible_Iterator
17070 and then In_Predefined_Unit
(Root_Type
(Typ
))
17074 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
17078 Collect_Interfaces
(Typ
, Ifaces_List
);
17080 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
17081 while Present
(Iface_Elmt
) loop
17082 Iface
:= Node
(Iface_Elmt
);
17083 if Chars
(Iface
) = Name_Reversible_Iterator
17084 and then In_Predefined_Unit
(Iface
)
17089 Next_Elmt
(Iface_Elmt
);
17094 end Is_Reversible_Iterator
;
17096 ----------------------
17097 -- Is_Selector_Name --
17098 ----------------------
17100 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
17102 if not Is_List_Member
(N
) then
17104 P
: constant Node_Id
:= Parent
(N
);
17106 return Nkind_In
(P
, N_Expanded_Name
,
17107 N_Generic_Association
,
17108 N_Parameter_Association
,
17109 N_Selected_Component
)
17110 and then Selector_Name
(P
) = N
;
17115 L
: constant List_Id
:= List_Containing
(N
);
17116 P
: constant Node_Id
:= Parent
(L
);
17118 return (Nkind
(P
) = N_Discriminant_Association
17119 and then Selector_Names
(P
) = L
)
17121 (Nkind
(P
) = N_Component_Association
17122 and then Choices
(P
) = L
);
17125 end Is_Selector_Name
;
17127 ---------------------------------
17128 -- Is_Single_Concurrent_Object --
17129 ---------------------------------
17131 function Is_Single_Concurrent_Object
(Id
: Entity_Id
) return Boolean is
17134 Is_Single_Protected_Object
(Id
) or else Is_Single_Task_Object
(Id
);
17135 end Is_Single_Concurrent_Object
;
17137 -------------------------------
17138 -- Is_Single_Concurrent_Type --
17139 -------------------------------
17141 function Is_Single_Concurrent_Type
(Id
: Entity_Id
) return Boolean is
17144 Ekind_In
(Id
, E_Protected_Type
, E_Task_Type
)
17145 and then Is_Single_Concurrent_Type_Declaration
17146 (Declaration_Node
(Id
));
17147 end Is_Single_Concurrent_Type
;
17149 -------------------------------------------
17150 -- Is_Single_Concurrent_Type_Declaration --
17151 -------------------------------------------
17153 function Is_Single_Concurrent_Type_Declaration
17154 (N
: Node_Id
) return Boolean
17157 return Nkind_In
(Original_Node
(N
), N_Single_Protected_Declaration
,
17158 N_Single_Task_Declaration
);
17159 end Is_Single_Concurrent_Type_Declaration
;
17161 ---------------------------------------------
17162 -- Is_Single_Precision_Floating_Point_Type --
17163 ---------------------------------------------
17165 function Is_Single_Precision_Floating_Point_Type
17166 (E
: Entity_Id
) return Boolean is
17168 return Is_Floating_Point_Type
(E
)
17169 and then Machine_Radix_Value
(E
) = Uint_2
17170 and then Machine_Mantissa_Value
(E
) = Uint_24
17171 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_7
17172 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_7
);
17173 end Is_Single_Precision_Floating_Point_Type
;
17175 --------------------------------
17176 -- Is_Single_Protected_Object --
17177 --------------------------------
17179 function Is_Single_Protected_Object
(Id
: Entity_Id
) return Boolean is
17182 Ekind
(Id
) = E_Variable
17183 and then Ekind
(Etype
(Id
)) = E_Protected_Type
17184 and then Is_Single_Concurrent_Type
(Etype
(Id
));
17185 end Is_Single_Protected_Object
;
17187 ---------------------------
17188 -- Is_Single_Task_Object --
17189 ---------------------------
17191 function Is_Single_Task_Object
(Id
: Entity_Id
) return Boolean is
17194 Ekind
(Id
) = E_Variable
17195 and then Ekind
(Etype
(Id
)) = E_Task_Type
17196 and then Is_Single_Concurrent_Type
(Etype
(Id
));
17197 end Is_Single_Task_Object
;
17199 -------------------------------------
17200 -- Is_SPARK_05_Initialization_Expr --
17201 -------------------------------------
17203 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
17206 Comp_Assn
: Node_Id
;
17207 Orig_N
: constant Node_Id
:= Original_Node
(N
);
17212 if not Comes_From_Source
(Orig_N
) then
17216 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
17218 case Nkind
(Orig_N
) is
17219 when N_Character_Literal
17220 | N_Integer_Literal
17226 when N_Expanded_Name
17229 if Is_Entity_Name
(Orig_N
)
17230 and then Present
(Entity
(Orig_N
)) -- needed in some cases
17232 case Ekind
(Entity
(Orig_N
)) is
17234 | E_Enumeration_Literal
17241 if Is_Type
(Entity
(Orig_N
)) then
17249 when N_Qualified_Expression
17250 | N_Type_Conversion
17252 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
17255 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
17258 | N_Membership_Test
17261 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
17263 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
17266 | N_Extension_Aggregate
17268 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
17270 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
17273 Expr
:= First
(Expressions
(Orig_N
));
17274 while Present
(Expr
) loop
17275 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
17283 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
17284 while Present
(Comp_Assn
) loop
17285 Expr
:= Expression
(Comp_Assn
);
17287 -- Note: test for Present here needed for box assocation
17290 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
17299 when N_Attribute_Reference
=>
17300 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
17301 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
17304 Expr
:= First
(Expressions
(Orig_N
));
17305 while Present
(Expr
) loop
17306 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
17314 -- Selected components might be expanded named not yet resolved, so
17315 -- default on the safe side. (Eg on sparklex.ads)
17317 when N_Selected_Component
=>
17326 end Is_SPARK_05_Initialization_Expr
;
17328 ----------------------------------
17329 -- Is_SPARK_05_Object_Reference --
17330 ----------------------------------
17332 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
17334 if Is_Entity_Name
(N
) then
17335 return Present
(Entity
(N
))
17337 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
17338 or else Ekind
(Entity
(N
)) in Formal_Kind
);
17342 when N_Selected_Component
=>
17343 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
17349 end Is_SPARK_05_Object_Reference
;
17351 -----------------------------
17352 -- Is_Specific_Tagged_Type --
17353 -----------------------------
17355 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
17356 Full_Typ
: Entity_Id
;
17359 -- Handle private types
17361 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
17362 Full_Typ
:= Full_View
(Typ
);
17367 -- A specific tagged type is a non-class-wide tagged type
17369 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
17370 end Is_Specific_Tagged_Type
;
17376 function Is_Statement
(N
: Node_Id
) return Boolean is
17379 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
17380 or else Nkind
(N
) = N_Procedure_Call_Statement
;
17383 ---------------------------------------
17384 -- Is_Subprogram_Contract_Annotation --
17385 ---------------------------------------
17387 function Is_Subprogram_Contract_Annotation
17388 (Item
: Node_Id
) return Boolean
17393 if Nkind
(Item
) = N_Aspect_Specification
then
17394 Nam
:= Chars
(Identifier
(Item
));
17396 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
17397 Nam
:= Pragma_Name
(Item
);
17400 return Nam
= Name_Contract_Cases
17401 or else Nam
= Name_Depends
17402 or else Nam
= Name_Extensions_Visible
17403 or else Nam
= Name_Global
17404 or else Nam
= Name_Post
17405 or else Nam
= Name_Post_Class
17406 or else Nam
= Name_Postcondition
17407 or else Nam
= Name_Pre
17408 or else Nam
= Name_Pre_Class
17409 or else Nam
= Name_Precondition
17410 or else Nam
= Name_Refined_Depends
17411 or else Nam
= Name_Refined_Global
17412 or else Nam
= Name_Refined_Post
17413 or else Nam
= Name_Test_Case
;
17414 end Is_Subprogram_Contract_Annotation
;
17416 --------------------------------------------------
17417 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17418 --------------------------------------------------
17420 function Is_Subprogram_Stub_Without_Prior_Declaration
17421 (N
: Node_Id
) return Boolean
17424 -- A subprogram stub without prior declaration serves as declaration for
17425 -- the actual subprogram body. As such, it has an attached defining
17426 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
17428 return Nkind
(N
) = N_Subprogram_Body_Stub
17429 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
17430 end Is_Subprogram_Stub_Without_Prior_Declaration
;
17432 ---------------------------
17433 -- Is_Suitable_Primitive --
17434 ---------------------------
17436 function Is_Suitable_Primitive
(Subp_Id
: Entity_Id
) return Boolean is
17438 -- The Default_Initial_Condition and invariant procedures must not be
17439 -- treated as primitive operations even when they apply to a tagged
17440 -- type. These routines must not act as targets of dispatching calls
17441 -- because they already utilize class-wide-precondition semantics to
17442 -- handle inheritance and overriding.
17444 if Ekind
(Subp_Id
) = E_Procedure
17445 and then (Is_DIC_Procedure
(Subp_Id
)
17447 Is_Invariant_Procedure
(Subp_Id
))
17453 end Is_Suitable_Primitive
;
17455 --------------------------
17456 -- Is_Suspension_Object --
17457 --------------------------
17459 function Is_Suspension_Object
(Id
: Entity_Id
) return Boolean is
17461 -- This approach does an exact name match rather than to rely on
17462 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17463 -- front end at point where all auxiliary tables are locked and any
17464 -- modifications to them are treated as violations. Do not tamper with
17465 -- the tables, instead examine the Chars fields of all the scopes of Id.
17468 Chars
(Id
) = Name_Suspension_Object
17469 and then Present
(Scope
(Id
))
17470 and then Chars
(Scope
(Id
)) = Name_Synchronous_Task_Control
17471 and then Present
(Scope
(Scope
(Id
)))
17472 and then Chars
(Scope
(Scope
(Id
))) = Name_Ada
17473 and then Present
(Scope
(Scope
(Scope
(Id
))))
17474 and then Scope
(Scope
(Scope
(Id
))) = Standard_Standard
;
17475 end Is_Suspension_Object
;
17477 ----------------------------
17478 -- Is_Synchronized_Object --
17479 ----------------------------
17481 function Is_Synchronized_Object
(Id
: Entity_Id
) return Boolean is
17485 if Is_Object
(Id
) then
17487 -- The object is synchronized if it is of a type that yields a
17488 -- synchronized object.
17490 if Yields_Synchronized_Object
(Etype
(Id
)) then
17493 -- The object is synchronized if it is atomic and Async_Writers is
17496 elsif Is_Atomic_Object_Entity
(Id
)
17497 and then Async_Writers_Enabled
(Id
)
17501 -- A constant is a synchronized object by default
17503 elsif Ekind
(Id
) = E_Constant
then
17506 -- A variable is a synchronized object if it is subject to pragma
17507 -- Constant_After_Elaboration.
17509 elsif Ekind
(Id
) = E_Variable
then
17510 Prag
:= Get_Pragma
(Id
, Pragma_Constant_After_Elaboration
);
17512 return Present
(Prag
) and then Is_Enabled_Pragma
(Prag
);
17516 -- Otherwise the input is not an object or it does not qualify as a
17517 -- synchronized object.
17520 end Is_Synchronized_Object
;
17522 ---------------------------------
17523 -- Is_Synchronized_Tagged_Type --
17524 ---------------------------------
17526 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
17527 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
17530 -- A task or protected type derived from an interface is a tagged type.
17531 -- Such a tagged type is called a synchronized tagged type, as are
17532 -- synchronized interfaces and private extensions whose declaration
17533 -- includes the reserved word synchronized.
17535 return (Is_Tagged_Type
(E
)
17536 and then (Kind
= E_Task_Type
17538 Kind
= E_Protected_Type
))
17541 and then Is_Synchronized_Interface
(E
))
17543 (Ekind
(E
) = E_Record_Type_With_Private
17544 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
17545 and then (Synchronized_Present
(Parent
(E
))
17546 or else Is_Synchronized_Interface
(Etype
(E
))));
17547 end Is_Synchronized_Tagged_Type
;
17553 function Is_Transfer
(N
: Node_Id
) return Boolean is
17554 Kind
: constant Node_Kind
:= Nkind
(N
);
17557 if Kind
= N_Simple_Return_Statement
17559 Kind
= N_Extended_Return_Statement
17561 Kind
= N_Goto_Statement
17563 Kind
= N_Raise_Statement
17565 Kind
= N_Requeue_Statement
17569 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
17570 and then No
(Condition
(N
))
17574 elsif Kind
= N_Procedure_Call_Statement
17575 and then Is_Entity_Name
(Name
(N
))
17576 and then Present
(Entity
(Name
(N
)))
17577 and then No_Return
(Entity
(Name
(N
)))
17581 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
17593 function Is_True
(U
: Uint
) return Boolean is
17598 --------------------------------------
17599 -- Is_Unchecked_Conversion_Instance --
17600 --------------------------------------
17602 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
17606 -- Look for a function whose generic parent is the predefined intrinsic
17607 -- function Unchecked_Conversion, or for one that renames such an
17610 if Ekind
(Id
) = E_Function
then
17611 Par
:= Parent
(Id
);
17613 if Nkind
(Par
) = N_Function_Specification
then
17614 Par
:= Generic_Parent
(Par
);
17616 if Present
(Par
) then
17618 Chars
(Par
) = Name_Unchecked_Conversion
17619 and then Is_Intrinsic_Subprogram
(Par
)
17620 and then In_Predefined_Unit
(Par
);
17623 Present
(Alias
(Id
))
17624 and then Is_Unchecked_Conversion_Instance
(Alias
(Id
));
17630 end Is_Unchecked_Conversion_Instance
;
17632 -------------------------------
17633 -- Is_Universal_Numeric_Type --
17634 -------------------------------
17636 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
17638 return T
= Universal_Integer
or else T
= Universal_Real
;
17639 end Is_Universal_Numeric_Type
;
17641 ------------------------------
17642 -- Is_User_Defined_Equality --
17643 ------------------------------
17645 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean is
17647 return Ekind
(Id
) = E_Function
17648 and then Chars
(Id
) = Name_Op_Eq
17649 and then Comes_From_Source
(Id
)
17651 -- Internally generated equalities have a full type declaration
17652 -- as their parent.
17654 and then Nkind
(Parent
(Id
)) = N_Function_Specification
;
17655 end Is_User_Defined_Equality
;
17657 --------------------------------------
17658 -- Is_Validation_Variable_Reference --
17659 --------------------------------------
17661 function Is_Validation_Variable_Reference
(N
: Node_Id
) return Boolean is
17662 Var
: constant Node_Id
:= Unqual_Conv
(N
);
17663 Var_Id
: Entity_Id
;
17668 if Is_Entity_Name
(Var
) then
17669 Var_Id
:= Entity
(Var
);
17674 and then Ekind
(Var_Id
) = E_Variable
17675 and then Present
(Validated_Object
(Var_Id
));
17676 end Is_Validation_Variable_Reference
;
17678 ----------------------------
17679 -- Is_Variable_Size_Array --
17680 ----------------------------
17682 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
17686 pragma Assert
(Is_Array_Type
(E
));
17688 -- Check if some index is initialized with a non-constant value
17690 Idx
:= First_Index
(E
);
17691 while Present
(Idx
) loop
17692 if Nkind
(Idx
) = N_Range
then
17693 if not Is_Constant_Bound
(Low_Bound
(Idx
))
17694 or else not Is_Constant_Bound
(High_Bound
(Idx
))
17700 Idx
:= Next_Index
(Idx
);
17704 end Is_Variable_Size_Array
;
17706 -----------------------------
17707 -- Is_Variable_Size_Record --
17708 -----------------------------
17710 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
17712 Comp_Typ
: Entity_Id
;
17715 pragma Assert
(Is_Record_Type
(E
));
17717 Comp
:= First_Entity
(E
);
17718 while Present
(Comp
) loop
17719 Comp_Typ
:= Etype
(Comp
);
17721 -- Recursive call if the record type has discriminants
17723 if Is_Record_Type
(Comp_Typ
)
17724 and then Has_Discriminants
(Comp_Typ
)
17725 and then Is_Variable_Size_Record
(Comp_Typ
)
17729 elsif Is_Array_Type
(Comp_Typ
)
17730 and then Is_Variable_Size_Array
(Comp_Typ
)
17735 Next_Entity
(Comp
);
17739 end Is_Variable_Size_Record
;
17745 function Is_Variable
17747 Use_Original_Node
: Boolean := True) return Boolean
17749 Orig_Node
: Node_Id
;
17751 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
17752 -- Within a protected function, the private components of the enclosing
17753 -- protected type are constants. A function nested within a (protected)
17754 -- procedure is not itself protected. Within the body of a protected
17755 -- function the current instance of the protected type is a constant.
17757 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
17758 -- Prefixes can involve implicit dereferences, in which case we must
17759 -- test for the case of a reference of a constant access type, which can
17760 -- can never be a variable.
17762 ---------------------------
17763 -- In_Protected_Function --
17764 ---------------------------
17766 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
17771 -- E is the current instance of a type
17773 if Is_Type
(E
) then
17782 if not Is_Protected_Type
(Prot
) then
17786 S
:= Current_Scope
;
17787 while Present
(S
) and then S
/= Prot
loop
17788 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
17797 end In_Protected_Function
;
17799 ------------------------
17800 -- Is_Variable_Prefix --
17801 ------------------------
17803 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
17805 if Is_Access_Type
(Etype
(P
)) then
17806 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
17808 -- For the case of an indexed component whose prefix has a packed
17809 -- array type, the prefix has been rewritten into a type conversion.
17810 -- Determine variable-ness from the converted expression.
17812 elsif Nkind
(P
) = N_Type_Conversion
17813 and then not Comes_From_Source
(P
)
17814 and then Is_Array_Type
(Etype
(P
))
17815 and then Is_Packed
(Etype
(P
))
17817 return Is_Variable
(Expression
(P
));
17820 return Is_Variable
(P
);
17822 end Is_Variable_Prefix
;
17824 -- Start of processing for Is_Variable
17827 -- Special check, allow x'Deref(expr) as a variable
17829 if Nkind
(N
) = N_Attribute_Reference
17830 and then Attribute_Name
(N
) = Name_Deref
17835 -- Check if we perform the test on the original node since this may be a
17836 -- test of syntactic categories which must not be disturbed by whatever
17837 -- rewriting might have occurred. For example, an aggregate, which is
17838 -- certainly NOT a variable, could be turned into a variable by
17841 if Use_Original_Node
then
17842 Orig_Node
:= Original_Node
(N
);
17847 -- Definitely OK if Assignment_OK is set. Since this is something that
17848 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
17850 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
17853 -- Normally we go to the original node, but there is one exception where
17854 -- we use the rewritten node, namely when it is an explicit dereference.
17855 -- The generated code may rewrite a prefix which is an access type with
17856 -- an explicit dereference. The dereference is a variable, even though
17857 -- the original node may not be (since it could be a constant of the
17860 -- In Ada 2005 we have a further case to consider: the prefix may be a
17861 -- function call given in prefix notation. The original node appears to
17862 -- be a selected component, but we need to examine the call.
17864 elsif Nkind
(N
) = N_Explicit_Dereference
17865 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
17866 and then Present
(Etype
(Orig_Node
))
17867 and then Is_Access_Type
(Etype
(Orig_Node
))
17869 -- Note that if the prefix is an explicit dereference that does not
17870 -- come from source, we must check for a rewritten function call in
17871 -- prefixed notation before other forms of rewriting, to prevent a
17875 (Nkind
(Orig_Node
) = N_Function_Call
17876 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
17878 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
17880 -- in Ada 2012, the dereference may have been added for a type with
17881 -- a declared implicit dereference aspect. Check that it is not an
17882 -- access to constant.
17884 elsif Nkind
(N
) = N_Explicit_Dereference
17885 and then Present
(Etype
(Orig_Node
))
17886 and then Ada_Version
>= Ada_2012
17887 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
17889 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
17891 -- A function call is never a variable
17893 elsif Nkind
(N
) = N_Function_Call
then
17896 -- All remaining checks use the original node
17898 elsif Is_Entity_Name
(Orig_Node
)
17899 and then Present
(Entity
(Orig_Node
))
17902 E
: constant Entity_Id
:= Entity
(Orig_Node
);
17903 K
: constant Entity_Kind
:= Ekind
(E
);
17906 if Is_Loop_Parameter
(E
) then
17910 return (K
= E_Variable
17911 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
17912 or else (K
= E_Component
17913 and then not In_Protected_Function
(E
))
17914 or else K
= E_Out_Parameter
17915 or else K
= E_In_Out_Parameter
17916 or else K
= E_Generic_In_Out_Parameter
17918 -- Current instance of type. If this is a protected type, check
17919 -- we are not within the body of one of its protected functions.
17921 or else (Is_Type
(E
)
17922 and then In_Open_Scopes
(E
)
17923 and then not In_Protected_Function
(E
))
17925 or else (Is_Incomplete_Or_Private_Type
(E
)
17926 and then In_Open_Scopes
(Full_View
(E
)));
17930 case Nkind
(Orig_Node
) is
17931 when N_Indexed_Component
17934 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
17936 when N_Selected_Component
=>
17937 return (Is_Variable
(Selector_Name
(Orig_Node
))
17938 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
17940 (Nkind
(N
) = N_Expanded_Name
17941 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
17943 -- For an explicit dereference, the type of the prefix cannot
17944 -- be an access to constant or an access to subprogram.
17946 when N_Explicit_Dereference
=>
17948 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
17950 return Is_Access_Type
(Typ
)
17951 and then not Is_Access_Constant
(Root_Type
(Typ
))
17952 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
17955 -- The type conversion is the case where we do not deal with the
17956 -- context dependent special case of an actual parameter. Thus
17957 -- the type conversion is only considered a variable for the
17958 -- purposes of this routine if the target type is tagged. However,
17959 -- a type conversion is considered to be a variable if it does not
17960 -- come from source (this deals for example with the conversions
17961 -- of expressions to their actual subtypes).
17963 when N_Type_Conversion
=>
17964 return Is_Variable
(Expression
(Orig_Node
))
17966 (not Comes_From_Source
(Orig_Node
)
17968 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
17970 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
17972 -- GNAT allows an unchecked type conversion as a variable. This
17973 -- only affects the generation of internal expanded code, since
17974 -- calls to instantiations of Unchecked_Conversion are never
17975 -- considered variables (since they are function calls).
17977 when N_Unchecked_Type_Conversion
=>
17978 return Is_Variable
(Expression
(Orig_Node
));
17986 ---------------------------
17987 -- Is_Visibly_Controlled --
17988 ---------------------------
17990 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
17991 Root
: constant Entity_Id
:= Root_Type
(T
);
17993 return Chars
(Scope
(Root
)) = Name_Finalization
17994 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
17995 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
17996 end Is_Visibly_Controlled
;
17998 --------------------------
17999 -- Is_Volatile_Function --
18000 --------------------------
18002 function Is_Volatile_Function
(Func_Id
: Entity_Id
) return Boolean is
18004 pragma Assert
(Ekind_In
(Func_Id
, E_Function
, E_Generic_Function
));
18006 -- A function declared within a protected type is volatile
18008 if Is_Protected_Type
(Scope
(Func_Id
)) then
18011 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18012 -- either the source or the target are effectively volatile.
18014 elsif Is_Unchecked_Conversion_Instance
(Func_Id
)
18015 and then Has_Effectively_Volatile_Profile
(Func_Id
)
18019 -- Otherwise the function is treated as volatile if it is subject to
18020 -- enabled pragma Volatile_Function.
18024 Is_Enabled_Pragma
(Get_Pragma
(Func_Id
, Pragma_Volatile_Function
));
18026 end Is_Volatile_Function
;
18028 ------------------------
18029 -- Is_Volatile_Object --
18030 ------------------------
18032 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
18033 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
18034 -- If prefix is an implicit dereference, examine designated type
18036 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
18037 -- Determines if given object has volatile components
18039 ------------------------
18040 -- Is_Volatile_Prefix --
18041 ------------------------
18043 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
18044 Typ
: constant Entity_Id
:= Etype
(N
);
18047 if Is_Access_Type
(Typ
) then
18049 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
18052 return Is_Volatile
(Dtyp
)
18053 or else Has_Volatile_Components
(Dtyp
);
18057 return Object_Has_Volatile_Components
(N
);
18059 end Is_Volatile_Prefix
;
18061 ------------------------------------
18062 -- Object_Has_Volatile_Components --
18063 ------------------------------------
18065 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
18066 Typ
: constant Entity_Id
:= Etype
(N
);
18069 if Is_Volatile
(Typ
)
18070 or else Has_Volatile_Components
(Typ
)
18074 elsif Is_Entity_Name
(N
)
18075 and then (Has_Volatile_Components
(Entity
(N
))
18076 or else Is_Volatile
(Entity
(N
)))
18080 elsif Nkind
(N
) = N_Indexed_Component
18081 or else Nkind
(N
) = N_Selected_Component
18083 return Is_Volatile_Prefix
(Prefix
(N
));
18088 end Object_Has_Volatile_Components
;
18090 -- Start of processing for Is_Volatile_Object
18093 if Nkind
(N
) = N_Defining_Identifier
then
18094 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
18096 elsif Nkind
(N
) = N_Expanded_Name
then
18097 return Is_Volatile_Object
(Entity
(N
));
18099 elsif Is_Volatile
(Etype
(N
))
18100 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
18104 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
18105 and then Is_Volatile_Prefix
(Prefix
(N
))
18109 elsif Nkind
(N
) = N_Selected_Component
18110 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
18117 end Is_Volatile_Object
;
18119 -----------------------------
18120 -- Iterate_Call_Parameters --
18121 -----------------------------
18123 procedure Iterate_Call_Parameters
(Call
: Node_Id
) is
18124 Actual
: Node_Id
:= First_Actual
(Call
);
18125 Formal
: Entity_Id
:= First_Formal
(Get_Called_Entity
(Call
));
18128 while Present
(Formal
) and then Present
(Actual
) loop
18129 Handle_Parameter
(Formal
, Actual
);
18131 Next_Formal
(Formal
);
18132 Next_Actual
(Actual
);
18135 pragma Assert
(No
(Formal
));
18136 pragma Assert
(No
(Actual
));
18137 end Iterate_Call_Parameters
;
18139 ---------------------------
18140 -- Itype_Has_Declaration --
18141 ---------------------------
18143 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
18145 pragma Assert
(Is_Itype
(Id
));
18146 return Present
(Parent
(Id
))
18147 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
18148 N_Subtype_Declaration
)
18149 and then Defining_Entity
(Parent
(Id
)) = Id
;
18150 end Itype_Has_Declaration
;
18152 -------------------------
18153 -- Kill_Current_Values --
18154 -------------------------
18156 procedure Kill_Current_Values
18158 Last_Assignment_Only
: Boolean := False)
18161 if Is_Assignable
(Ent
) then
18162 Set_Last_Assignment
(Ent
, Empty
);
18165 if Is_Object
(Ent
) then
18166 if not Last_Assignment_Only
then
18168 Set_Current_Value
(Ent
, Empty
);
18170 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18171 -- for a constant. Once the constant is elaborated, its value is
18172 -- not changed, therefore the associated flags that describe the
18173 -- value should not be modified either.
18175 if Ekind
(Ent
) = E_Constant
then
18178 -- Non-constant entities
18181 if not Can_Never_Be_Null
(Ent
) then
18182 Set_Is_Known_Non_Null
(Ent
, False);
18185 Set_Is_Known_Null
(Ent
, False);
18187 -- Reset the Is_Known_Valid flag unless the type is always
18188 -- valid. This does not apply to a loop parameter because its
18189 -- bounds are defined by the loop header and therefore always
18192 if not Is_Known_Valid
(Etype
(Ent
))
18193 and then Ekind
(Ent
) /= E_Loop_Parameter
18195 Set_Is_Known_Valid
(Ent
, False);
18200 end Kill_Current_Values
;
18202 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
18205 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
18206 -- Clear current value for entity E and all entities chained to E
18208 ------------------------------------------
18209 -- Kill_Current_Values_For_Entity_Chain --
18210 ------------------------------------------
18212 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
18216 while Present
(Ent
) loop
18217 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
18220 end Kill_Current_Values_For_Entity_Chain
;
18222 -- Start of processing for Kill_Current_Values
18225 -- Kill all saved checks, a special case of killing saved values
18227 if not Last_Assignment_Only
then
18231 -- Loop through relevant scopes, which includes the current scope and
18232 -- any parent scopes if the current scope is a block or a package.
18234 S
:= Current_Scope
;
18237 -- Clear current values of all entities in current scope
18239 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
18241 -- If scope is a package, also clear current values of all private
18242 -- entities in the scope.
18244 if Is_Package_Or_Generic_Package
(S
)
18245 or else Is_Concurrent_Type
(S
)
18247 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
18250 -- If this is a not a subprogram, deal with parents
18252 if not Is_Subprogram
(S
) then
18254 exit Scope_Loop
when S
= Standard_Standard
;
18258 end loop Scope_Loop
;
18259 end Kill_Current_Values
;
18261 --------------------------
18262 -- Kill_Size_Check_Code --
18263 --------------------------
18265 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
18267 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
18268 and then Present
(Size_Check_Code
(E
))
18270 Remove
(Size_Check_Code
(E
));
18271 Set_Size_Check_Code
(E
, Empty
);
18273 end Kill_Size_Check_Code
;
18275 --------------------
18276 -- Known_Non_Null --
18277 --------------------
18279 function Known_Non_Null
(N
: Node_Id
) return Boolean is
18280 Status
: constant Null_Status_Kind
:= Null_Status
(N
);
18287 -- The expression yields a non-null value ignoring simple flow analysis
18289 if Status
= Is_Non_Null
then
18292 -- Otherwise check whether N is a reference to an entity that appears
18293 -- within a conditional construct.
18295 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
18297 -- First check if we are in decisive conditional
18299 Get_Current_Value_Condition
(N
, Op
, Val
);
18301 if Known_Null
(Val
) then
18302 if Op
= N_Op_Eq
then
18304 elsif Op
= N_Op_Ne
then
18309 -- If OK to do replacement, test Is_Known_Non_Null flag
18313 if OK_To_Do_Constant_Replacement
(Id
) then
18314 return Is_Known_Non_Null
(Id
);
18318 -- Otherwise it is not possible to determine whether N yields a non-null
18322 end Known_Non_Null
;
18328 function Known_Null
(N
: Node_Id
) return Boolean is
18329 Status
: constant Null_Status_Kind
:= Null_Status
(N
);
18336 -- The expression yields a null value ignoring simple flow analysis
18338 if Status
= Is_Null
then
18341 -- Otherwise check whether N is a reference to an entity that appears
18342 -- within a conditional construct.
18344 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
18346 -- First check if we are in decisive conditional
18348 Get_Current_Value_Condition
(N
, Op
, Val
);
18350 if Known_Null
(Val
) then
18351 if Op
= N_Op_Eq
then
18353 elsif Op
= N_Op_Ne
then
18358 -- If OK to do replacement, test Is_Known_Null flag
18362 if OK_To_Do_Constant_Replacement
(Id
) then
18363 return Is_Known_Null
(Id
);
18367 -- Otherwise it is not possible to determine whether N yields a null
18373 --------------------------
18374 -- Known_To_Be_Assigned --
18375 --------------------------
18377 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
18378 P
: constant Node_Id
:= Parent
(N
);
18383 -- Test left side of assignment
18385 when N_Assignment_Statement
=>
18386 return N
= Name
(P
);
18388 -- Function call arguments are never lvalues
18390 when N_Function_Call
=>
18393 -- Positional parameter for procedure or accept call
18395 when N_Accept_Statement
18396 | N_Procedure_Call_Statement
18404 Proc
:= Get_Subprogram_Entity
(P
);
18410 -- If we are not a list member, something is strange, so
18411 -- be conservative and return False.
18413 if not Is_List_Member
(N
) then
18417 -- We are going to find the right formal by stepping forward
18418 -- through the formals, as we step backwards in the actuals.
18420 Form
:= First_Formal
(Proc
);
18423 -- If no formal, something is weird, so be conservative
18424 -- and return False.
18431 exit when No
(Act
);
18432 Next_Formal
(Form
);
18435 return Ekind
(Form
) /= E_In_Parameter
;
18438 -- Named parameter for procedure or accept call
18440 when N_Parameter_Association
=>
18446 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
18452 -- Loop through formals to find the one that matches
18454 Form
:= First_Formal
(Proc
);
18456 -- If no matching formal, that's peculiar, some kind of
18457 -- previous error, so return False to be conservative.
18458 -- Actually this also happens in legal code in the case
18459 -- where P is a parameter association for an Extra_Formal???
18465 -- Else test for match
18467 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
18468 return Ekind
(Form
) /= E_In_Parameter
;
18471 Next_Formal
(Form
);
18475 -- Test for appearing in a conversion that itself appears
18476 -- in an lvalue context, since this should be an lvalue.
18478 when N_Type_Conversion
=>
18479 return Known_To_Be_Assigned
(P
);
18481 -- All other references are definitely not known to be modifications
18486 end Known_To_Be_Assigned
;
18488 ---------------------------
18489 -- Last_Source_Statement --
18490 ---------------------------
18492 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
18496 N
:= Last
(Statements
(HSS
));
18497 while Present
(N
) loop
18498 exit when Comes_From_Source
(N
);
18503 end Last_Source_Statement
;
18505 -----------------------
18506 -- Mark_Coextensions --
18507 -----------------------
18509 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
18510 Is_Dynamic
: Boolean;
18511 -- Indicates whether the context causes nested coextensions to be
18512 -- dynamic or static
18514 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
18515 -- Recognize an allocator node and label it as a dynamic coextension
18517 --------------------
18518 -- Mark_Allocator --
18519 --------------------
18521 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
18523 if Nkind
(N
) = N_Allocator
then
18525 Set_Is_Static_Coextension
(N
, False);
18526 Set_Is_Dynamic_Coextension
(N
);
18528 -- If the allocator expression is potentially dynamic, it may
18529 -- be expanded out of order and require dynamic allocation
18530 -- anyway, so we treat the coextension itself as dynamic.
18531 -- Potential optimization ???
18533 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
18534 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
18536 Set_Is_Static_Coextension
(N
, False);
18537 Set_Is_Dynamic_Coextension
(N
);
18539 Set_Is_Dynamic_Coextension
(N
, False);
18540 Set_Is_Static_Coextension
(N
);
18545 end Mark_Allocator
;
18547 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
18549 -- Start of processing for Mark_Coextensions
18552 -- An allocator that appears on the right-hand side of an assignment is
18553 -- treated as a potentially dynamic coextension when the right-hand side
18554 -- is an allocator or a qualified expression.
18556 -- Obj := new ...'(new Coextension ...);
18558 if Nkind
(Context_Nod
) = N_Assignment_Statement
then
18560 Nkind_In
(Expression
(Context_Nod
), N_Allocator
,
18561 N_Qualified_Expression
);
18563 -- An allocator that appears within the expression of a simple return
18564 -- statement is treated as a potentially dynamic coextension when the
18565 -- expression is either aggregate, allocator, or qualified expression.
18567 -- return (new Coextension ...);
18568 -- return new ...'(new Coextension ...);
18570 elsif Nkind
(Context_Nod
) = N_Simple_Return_Statement
then
18572 Nkind_In
(Expression
(Context_Nod
), N_Aggregate
,
18574 N_Qualified_Expression
);
18576 -- An alloctor that appears within the initialization expression of an
18577 -- object declaration is considered a potentially dynamic coextension
18578 -- when the initialization expression is an allocator or a qualified
18581 -- Obj : ... := new ...'(new Coextension ...);
18583 -- A similar case arises when the object declaration is part of an
18584 -- extended return statement.
18586 -- return Obj : ... := new ...'(new Coextension ...);
18587 -- return Obj : ... := (new Coextension ...);
18589 elsif Nkind
(Context_Nod
) = N_Object_Declaration
then
18591 Nkind_In
(Root_Nod
, N_Allocator
, N_Qualified_Expression
)
18593 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
18595 -- This routine should not be called with constructs that cannot contain
18599 raise Program_Error
;
18602 Mark_Allocators
(Root_Nod
);
18603 end Mark_Coextensions
;
18605 ---------------------------------
18606 -- Mark_Elaboration_Attributes --
18607 ---------------------------------
18609 procedure Mark_Elaboration_Attributes
18610 (N_Id
: Node_Or_Entity_Id
;
18611 Checks
: Boolean := False;
18612 Level
: Boolean := False;
18613 Modes
: Boolean := False;
18614 Warnings
: Boolean := False)
18616 function Elaboration_Checks_OK
18617 (Target_Id
: Entity_Id
;
18618 Context_Id
: Entity_Id
) return Boolean;
18619 -- Determine whether elaboration checks are enabled for target Target_Id
18620 -- which resides within context Context_Id.
18622 procedure Mark_Elaboration_Attributes_Id
(Id
: Entity_Id
);
18623 -- Preserve relevant attributes of the context in arbitrary entity Id
18625 procedure Mark_Elaboration_Attributes_Node
(N
: Node_Id
);
18626 -- Preserve relevant attributes of the context in arbitrary node N
18628 ---------------------------
18629 -- Elaboration_Checks_OK --
18630 ---------------------------
18632 function Elaboration_Checks_OK
18633 (Target_Id
: Entity_Id
;
18634 Context_Id
: Entity_Id
) return Boolean
18636 Encl_Scop
: Entity_Id
;
18639 -- Elaboration checks are suppressed for the target
18641 if Elaboration_Checks_Suppressed
(Target_Id
) then
18645 -- Otherwise elaboration checks are OK for the target, but may be
18646 -- suppressed for the context where the target is declared.
18648 Encl_Scop
:= Context_Id
;
18649 while Present
(Encl_Scop
) and then Encl_Scop
/= Standard_Standard
loop
18650 if Elaboration_Checks_Suppressed
(Encl_Scop
) then
18654 Encl_Scop
:= Scope
(Encl_Scop
);
18657 -- Neither the target nor its declarative context have elaboration
18658 -- checks suppressed.
18661 end Elaboration_Checks_OK
;
18663 ------------------------------------
18664 -- Mark_Elaboration_Attributes_Id --
18665 ------------------------------------
18667 procedure Mark_Elaboration_Attributes_Id
(Id
: Entity_Id
) is
18669 -- Mark the status of elaboration checks in effect. Do not reset the
18670 -- status in case the entity is reanalyzed with checks suppressed.
18672 if Checks
and then not Is_Elaboration_Checks_OK_Id
(Id
) then
18673 Set_Is_Elaboration_Checks_OK_Id
(Id
,
18674 Elaboration_Checks_OK
18676 Context_Id
=> Scope
(Id
)));
18679 -- Mark the status of elaboration warnings in effect. Do not reset
18680 -- the status in case the entity is reanalyzed with warnings off.
18682 if Warnings
and then not Is_Elaboration_Warnings_OK_Id
(Id
) then
18683 Set_Is_Elaboration_Warnings_OK_Id
(Id
, Elab_Warnings
);
18685 end Mark_Elaboration_Attributes_Id
;
18687 --------------------------------------
18688 -- Mark_Elaboration_Attributes_Node --
18689 --------------------------------------
18691 procedure Mark_Elaboration_Attributes_Node
(N
: Node_Id
) is
18692 function Extract_Name
(N
: Node_Id
) return Node_Id
;
18693 -- Obtain the Name attribute of call or instantiation N
18699 function Extract_Name
(N
: Node_Id
) return Node_Id
is
18705 -- A call to an entry family appears in indexed form
18707 if Nkind
(Nam
) = N_Indexed_Component
then
18708 Nam
:= Prefix
(Nam
);
18711 -- The name may also appear in qualified form
18713 if Nkind
(Nam
) = N_Selected_Component
then
18714 Nam
:= Selector_Name
(Nam
);
18722 Context_Id
: Entity_Id
;
18725 -- Start of processing for Mark_Elaboration_Attributes_Node
18728 -- Mark the status of elaboration checks in effect. Do not reset the
18729 -- status in case the node is reanalyzed with checks suppressed.
18731 if Checks
and then not Is_Elaboration_Checks_OK_Node
(N
) then
18733 -- Assignments, attribute references, and variable references do
18734 -- not have a "declarative" context.
18736 Context_Id
:= Empty
;
18738 -- The status of elaboration checks for calls and instantiations
18739 -- depends on the most recent pragma Suppress/Unsuppress, as well
18740 -- as the suppression status of the context where the target is
18744 -- function Func ...;
18748 -- procedure Main is
18749 -- pragma Suppress (Elaboration_Checks, Pack);
18750 -- X : ... := Pack.Func;
18753 -- In the example above, the call to Func has elaboration checks
18754 -- enabled because there is no active general purpose suppression
18755 -- pragma, however the elaboration checks of Pack are explicitly
18756 -- suppressed. As a result the elaboration checks of the call must
18757 -- be disabled in order to preserve this dependency.
18759 if Nkind_In
(N
, N_Entry_Call_Statement
,
18761 N_Function_Instantiation
,
18762 N_Package_Instantiation
,
18763 N_Procedure_Call_Statement
,
18764 N_Procedure_Instantiation
)
18766 Nam
:= Extract_Name
(N
);
18768 if Is_Entity_Name
(Nam
) and then Present
(Entity
(Nam
)) then
18769 Context_Id
:= Scope
(Entity
(Nam
));
18773 Set_Is_Elaboration_Checks_OK_Node
(N
,
18774 Elaboration_Checks_OK
18775 (Target_Id
=> Empty
,
18776 Context_Id
=> Context_Id
));
18779 -- Mark the enclosing level of the node. Do not reset the status in
18780 -- case the node is relocated and reanalyzed.
18782 if Level
and then not Is_Declaration_Level_Node
(N
) then
18783 Set_Is_Declaration_Level_Node
(N
,
18784 Find_Enclosing_Level
(N
) = Declaration_Level
);
18787 -- Mark the Ghost and SPARK mode in effect
18790 if Ghost_Mode
= Ignore
then
18791 Set_Is_Ignored_Ghost_Node
(N
);
18794 if SPARK_Mode
= On
then
18795 Set_Is_SPARK_Mode_On_Node
(N
);
18799 -- Mark the status of elaboration warnings in effect. Do not reset
18800 -- the status in case the node is reanalyzed with warnings off.
18802 if Warnings
and then not Is_Elaboration_Warnings_OK_Node
(N
) then
18803 Set_Is_Elaboration_Warnings_OK_Node
(N
, Elab_Warnings
);
18805 end Mark_Elaboration_Attributes_Node
;
18807 -- Start of processing for Mark_Elaboration_Attributes
18810 -- Do not capture any elaboration-related attributes when switch -gnatH
18811 -- (legacy elaboration checking mode enabled) is in effect because the
18812 -- attributes are useless to the legacy model.
18814 if Legacy_Elaboration_Checks
then
18818 if Nkind
(N_Id
) in N_Entity
then
18819 Mark_Elaboration_Attributes_Id
(N_Id
);
18821 Mark_Elaboration_Attributes_Node
(N_Id
);
18823 end Mark_Elaboration_Attributes
;
18825 ----------------------------------
18826 -- Matching_Static_Array_Bounds --
18827 ----------------------------------
18829 function Matching_Static_Array_Bounds
18831 R_Typ
: Node_Id
) return Boolean
18833 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
18834 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
18836 L_Index
: Node_Id
:= Empty
; -- init to ...
18837 R_Index
: Node_Id
:= Empty
; -- ...avoid warnings
18846 if L_Ndims
/= R_Ndims
then
18850 -- Unconstrained types do not have static bounds
18852 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
18856 -- First treat specially the first dimension, as the lower bound and
18857 -- length of string literals are not stored like those of arrays.
18859 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
18860 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
18861 L_Len
:= String_Literal_Length
(L_Typ
);
18863 L_Index
:= First_Index
(L_Typ
);
18864 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
18866 if Is_OK_Static_Expression
(L_Low
)
18868 Is_OK_Static_Expression
(L_High
)
18870 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
18873 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
18880 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
18881 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
18882 R_Len
:= String_Literal_Length
(R_Typ
);
18884 R_Index
:= First_Index
(R_Typ
);
18885 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
18887 if Is_OK_Static_Expression
(R_Low
)
18889 Is_OK_Static_Expression
(R_High
)
18891 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
18894 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
18901 if (Is_OK_Static_Expression
(L_Low
)
18903 Is_OK_Static_Expression
(R_Low
))
18904 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
18905 and then L_Len
= R_Len
18912 -- Then treat all other dimensions
18914 for Indx
in 2 .. L_Ndims
loop
18918 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
18919 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
18921 if (Is_OK_Static_Expression
(L_Low
) and then
18922 Is_OK_Static_Expression
(L_High
) and then
18923 Is_OK_Static_Expression
(R_Low
) and then
18924 Is_OK_Static_Expression
(R_High
))
18925 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
18927 Expr_Value
(L_High
) = Expr_Value
(R_High
))
18935 -- If we fall through the loop, all indexes matched
18938 end Matching_Static_Array_Bounds
;
18940 -------------------
18941 -- May_Be_Lvalue --
18942 -------------------
18944 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
18945 P
: constant Node_Id
:= Parent
(N
);
18950 -- Test left side of assignment
18952 when N_Assignment_Statement
=>
18953 return N
= Name
(P
);
18955 -- Test prefix of component or attribute. Note that the prefix of an
18956 -- explicit or implicit dereference cannot be an l-value. In the case
18957 -- of a 'Read attribute, the reference can be an actual in the
18958 -- argument list of the attribute.
18960 when N_Attribute_Reference
=>
18961 return (N
= Prefix
(P
)
18962 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
)))
18964 Attribute_Name
(P
) = Name_Read
;
18966 -- For an expanded name, the name is an lvalue if the expanded name
18967 -- is an lvalue, but the prefix is never an lvalue, since it is just
18968 -- the scope where the name is found.
18970 when N_Expanded_Name
=>
18971 if N
= Prefix
(P
) then
18972 return May_Be_Lvalue
(P
);
18977 -- For a selected component A.B, A is certainly an lvalue if A.B is.
18978 -- B is a little interesting, if we have A.B := 3, there is some
18979 -- discussion as to whether B is an lvalue or not, we choose to say
18980 -- it is. Note however that A is not an lvalue if it is of an access
18981 -- type since this is an implicit dereference.
18983 when N_Selected_Component
=>
18985 and then Present
(Etype
(N
))
18986 and then Is_Access_Type
(Etype
(N
))
18990 return May_Be_Lvalue
(P
);
18993 -- For an indexed component or slice, the index or slice bounds is
18994 -- never an lvalue. The prefix is an lvalue if the indexed component
18995 -- or slice is an lvalue, except if it is an access type, where we
18996 -- have an implicit dereference.
18998 when N_Indexed_Component
19002 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
19006 return May_Be_Lvalue
(P
);
19009 -- Prefix of a reference is an lvalue if the reference is an lvalue
19011 when N_Reference
=>
19012 return May_Be_Lvalue
(P
);
19014 -- Prefix of explicit dereference is never an lvalue
19016 when N_Explicit_Dereference
=>
19019 -- Positional parameter for subprogram, entry, or accept call.
19020 -- In older versions of Ada function call arguments are never
19021 -- lvalues. In Ada 2012 functions can have in-out parameters.
19023 when N_Accept_Statement
19024 | N_Entry_Call_Statement
19025 | N_Subprogram_Call
19027 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
19031 -- The following mechanism is clumsy and fragile. A single flag
19032 -- set in Resolve_Actuals would be preferable ???
19040 Proc
:= Get_Subprogram_Entity
(P
);
19046 -- If we are not a list member, something is strange, so be
19047 -- conservative and return True.
19049 if not Is_List_Member
(N
) then
19053 -- We are going to find the right formal by stepping forward
19054 -- through the formals, as we step backwards in the actuals.
19056 Form
:= First_Formal
(Proc
);
19059 -- If no formal, something is weird, so be conservative and
19067 exit when No
(Act
);
19068 Next_Formal
(Form
);
19071 return Ekind
(Form
) /= E_In_Parameter
;
19074 -- Named parameter for procedure or accept call
19076 when N_Parameter_Association
=>
19082 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
19088 -- Loop through formals to find the one that matches
19090 Form
:= First_Formal
(Proc
);
19092 -- If no matching formal, that's peculiar, some kind of
19093 -- previous error, so return True to be conservative.
19094 -- Actually happens with legal code for an unresolved call
19095 -- where we may get the wrong homonym???
19101 -- Else test for match
19103 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
19104 return Ekind
(Form
) /= E_In_Parameter
;
19107 Next_Formal
(Form
);
19111 -- Test for appearing in a conversion that itself appears in an
19112 -- lvalue context, since this should be an lvalue.
19114 when N_Type_Conversion
=>
19115 return May_Be_Lvalue
(P
);
19117 -- Test for appearance in object renaming declaration
19119 when N_Object_Renaming_Declaration
=>
19122 -- All other references are definitely not lvalues
19133 function Might_Raise
(N
: Node_Id
) return Boolean is
19134 Result
: Boolean := False;
19136 function Process
(N
: Node_Id
) return Traverse_Result
;
19137 -- Set Result to True if we find something that could raise an exception
19143 function Process
(N
: Node_Id
) return Traverse_Result
is
19145 if Nkind_In
(N
, N_Procedure_Call_Statement
,
19148 N_Raise_Constraint_Error
,
19149 N_Raise_Program_Error
,
19150 N_Raise_Storage_Error
)
19159 procedure Set_Result
is new Traverse_Proc
(Process
);
19161 -- Start of processing for Might_Raise
19164 -- False if exceptions can't be propagated
19166 if No_Exception_Handlers_Set
then
19170 -- If the checks handled by the back end are not disabled, we cannot
19171 -- ensure that no exception will be raised.
19173 if not Access_Checks_Suppressed
(Empty
)
19174 or else not Discriminant_Checks_Suppressed
(Empty
)
19175 or else not Range_Checks_Suppressed
(Empty
)
19176 or else not Index_Checks_Suppressed
(Empty
)
19177 or else Opt
.Stack_Checking_Enabled
19186 --------------------------------
19187 -- Nearest_Enclosing_Instance --
19188 --------------------------------
19190 function Nearest_Enclosing_Instance
(E
: Entity_Id
) return Entity_Id
is
19195 while Present
(Inst
) and then Inst
/= Standard_Standard
loop
19196 if Is_Generic_Instance
(Inst
) then
19200 Inst
:= Scope
(Inst
);
19204 end Nearest_Enclosing_Instance
;
19206 ----------------------
19207 -- Needs_One_Actual --
19208 ----------------------
19210 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
19211 Formal
: Entity_Id
;
19214 -- Ada 2005 or later, and formals present. The first formal must be
19215 -- of a type that supports prefix notation: a controlling argument,
19216 -- a class-wide type, or an access to such.
19218 if Ada_Version
>= Ada_2005
19219 and then Present
(First_Formal
(E
))
19220 and then No
(Default_Value
(First_Formal
(E
)))
19222 (Is_Controlling_Formal
(First_Formal
(E
))
19223 or else Is_Class_Wide_Type
(Etype
(First_Formal
(E
)))
19224 or else Is_Anonymous_Access_Type
(Etype
(First_Formal
(E
))))
19226 Formal
:= Next_Formal
(First_Formal
(E
));
19227 while Present
(Formal
) loop
19228 if No
(Default_Value
(Formal
)) then
19232 Next_Formal
(Formal
);
19237 -- Ada 83/95 or no formals
19242 end Needs_One_Actual
;
19244 ---------------------------------
19245 -- Needs_Simple_Initialization --
19246 ---------------------------------
19248 function Needs_Simple_Initialization
19250 Consider_IS
: Boolean := True) return Boolean
19252 Consider_IS_NS
: constant Boolean :=
19253 Normalize_Scalars
or (Initialize_Scalars
and Consider_IS
);
19256 -- Never need initialization if it is suppressed
19258 if Initialization_Suppressed
(Typ
) then
19262 -- Check for private type, in which case test applies to the underlying
19263 -- type of the private type.
19265 if Is_Private_Type
(Typ
) then
19267 RT
: constant Entity_Id
:= Underlying_Type
(Typ
);
19269 if Present
(RT
) then
19270 return Needs_Simple_Initialization
(RT
);
19276 -- Scalar type with Default_Value aspect requires initialization
19278 elsif Is_Scalar_Type
(Typ
) and then Has_Default_Aspect
(Typ
) then
19281 -- Cases needing simple initialization are access types, and, if pragma
19282 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19285 elsif Is_Access_Type
(Typ
)
19286 or else (Consider_IS_NS
and then (Is_Scalar_Type
(Typ
)))
19290 -- If Initialize/Normalize_Scalars is in effect, string objects also
19291 -- need initialization, unless they are created in the course of
19292 -- expanding an aggregate (since in the latter case they will be
19293 -- filled with appropriate initializing values before they are used).
19295 elsif Consider_IS_NS
19296 and then Is_Standard_String_Type
(Typ
)
19298 (not Is_Itype
(Typ
)
19299 or else Nkind
(Associated_Node_For_Itype
(Typ
)) /= N_Aggregate
)
19306 end Needs_Simple_Initialization
;
19308 -------------------------------------
19309 -- Needs_Variable_Reference_Marker --
19310 -------------------------------------
19312 function Needs_Variable_Reference_Marker
19314 Calls_OK
: Boolean) return Boolean
19316 function Within_Suitable_Context
(Ref
: Node_Id
) return Boolean;
19317 -- Deteremine whether variable reference Ref appears within a suitable
19318 -- context that allows the creation of a marker.
19320 -----------------------------
19321 -- Within_Suitable_Context --
19322 -----------------------------
19324 function Within_Suitable_Context
(Ref
: Node_Id
) return Boolean is
19329 while Present
(Par
) loop
19331 -- The context is not suitable when the reference appears within
19332 -- the formal part of an instantiation which acts as compilation
19333 -- unit because there is no proper list for the insertion of the
19336 if Nkind
(Par
) = N_Generic_Association
19337 and then Nkind
(Parent
(Par
)) in N_Generic_Instantiation
19338 and then Nkind
(Parent
(Parent
(Par
))) = N_Compilation_Unit
19342 -- The context is not suitable when the reference appears within
19343 -- a pragma. If the pragma has run-time semantics, the reference
19344 -- will be reconsidered once the pragma is expanded.
19346 elsif Nkind
(Par
) = N_Pragma
then
19349 -- The context is not suitable when the reference appears within a
19350 -- subprogram call, and the caller requests this behavior.
19353 and then Nkind_In
(Par
, N_Entry_Call_Statement
,
19355 N_Procedure_Call_Statement
)
19359 -- Prevent the search from going too far
19361 elsif Is_Body_Or_Package_Declaration
(Par
) then
19365 Par
:= Parent
(Par
);
19369 end Within_Suitable_Context
;
19374 Var_Id
: Entity_Id
;
19376 -- Start of processing for Needs_Variable_Reference_Marker
19379 -- No marker needs to be created when switch -gnatH (legacy elaboration
19380 -- checking mode enabled) is in effect because the legacy ABE mechanism
19381 -- does not use markers.
19383 if Legacy_Elaboration_Checks
then
19386 -- No marker needs to be created for ASIS because ABE diagnostics and
19387 -- checks are not performed in this mode.
19389 elsif ASIS_Mode
then
19392 -- No marker needs to be created when the reference is preanalyzed
19393 -- because the marker will be inserted in the wrong place.
19395 elsif Preanalysis_Active
then
19398 -- Only references warrant a marker
19400 elsif not Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
19403 -- Only source references warrant a marker
19405 elsif not Comes_From_Source
(N
) then
19408 -- No marker needs to be created when the reference is erroneous, left
19409 -- in a bad state, or does not denote a variable.
19411 elsif not (Present
(Entity
(N
))
19412 and then Ekind
(Entity
(N
)) = E_Variable
19413 and then Entity
(N
) /= Any_Id
)
19418 Var_Id
:= Entity
(N
);
19419 Prag
:= SPARK_Pragma
(Var_Id
);
19421 -- Both the variable and reference must appear in SPARK_Mode On regions
19422 -- because this elaboration scenario falls under the SPARK rules.
19424 if not (Comes_From_Source
(Var_Id
)
19425 and then Present
(Prag
)
19426 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
19427 and then Is_SPARK_Mode_On_Node
(N
))
19431 -- No marker needs to be created when the reference does not appear
19432 -- within a suitable context (see body for details).
19434 -- Performance note: parent traversal
19436 elsif not Within_Suitable_Context
(N
) then
19440 -- At this point it is known that the variable reference will play a
19441 -- role in ABE diagnostics and requires a marker.
19444 end Needs_Variable_Reference_Marker
;
19446 ------------------------
19447 -- New_Copy_List_Tree --
19448 ------------------------
19450 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
19455 if List
= No_List
then
19462 while Present
(E
) loop
19463 Append
(New_Copy_Tree
(E
), NL
);
19469 end New_Copy_List_Tree
;
19471 -------------------
19472 -- New_Copy_Tree --
19473 -------------------
19475 -- The following tables play a key role in replicating entities and Itypes.
19476 -- They are intentionally declared at the library level rather than within
19477 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19478 -- optimization saves up to 2% of the entire compilation time spent in the
19479 -- front end. Care should be taken to reset the tables on each new call to
19482 NCT_Table_Max
: constant := 511;
19484 subtype NCT_Table_Index
is Nat
range 0 .. NCT_Table_Max
- 1;
19486 function NCT_Table_Hash
(Key
: Node_Or_Entity_Id
) return NCT_Table_Index
;
19487 -- Obtain the hash value of node or entity Key
19489 --------------------
19490 -- NCT_Table_Hash --
19491 --------------------
19493 function NCT_Table_Hash
(Key
: Node_Or_Entity_Id
) return NCT_Table_Index
is
19495 return NCT_Table_Index
(Key
mod NCT_Table_Max
);
19496 end NCT_Table_Hash
;
19498 ----------------------
19499 -- NCT_New_Entities --
19500 ----------------------
19502 -- The following table maps old entities and Itypes to their corresponding
19503 -- new entities and Itypes.
19507 package NCT_New_Entities
is new Simple_HTable
(
19508 Header_Num
=> NCT_Table_Index
,
19509 Element
=> Entity_Id
,
19510 No_Element
=> Empty
,
19512 Hash
=> NCT_Table_Hash
,
19515 ------------------------
19516 -- NCT_Pending_Itypes --
19517 ------------------------
19519 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19520 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19521 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19522 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19524 -- Ppp -> (Xxx, Yyy, Zzz)
19526 -- The set is expressed as an Elist
19528 package NCT_Pending_Itypes
is new Simple_HTable
(
19529 Header_Num
=> NCT_Table_Index
,
19530 Element
=> Elist_Id
,
19531 No_Element
=> No_Elist
,
19533 Hash
=> NCT_Table_Hash
,
19536 NCT_Tables_In_Use
: Boolean := False;
19537 -- This flag keeps track of whether the two tables NCT_New_Entities and
19538 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19539 -- where certain operations are not performed if the tables are not in
19540 -- use. This saves up to 8% of the entire compilation time spent in the
19543 -------------------
19544 -- New_Copy_Tree --
19545 -------------------
19547 function New_Copy_Tree
19549 Map
: Elist_Id
:= No_Elist
;
19550 New_Sloc
: Source_Ptr
:= No_Location
;
19551 New_Scope
: Entity_Id
:= Empty
;
19552 Scopes_In_EWA_OK
: Boolean := False) return Node_Id
19554 -- This routine performs low-level tree manipulations and needs access
19555 -- to the internals of the tree.
19557 use Atree
.Unchecked_Access
;
19558 use Atree_Private_Part
;
19560 EWA_Level
: Nat
:= 0;
19561 -- This counter keeps track of how many N_Expression_With_Actions nodes
19562 -- are encountered during a depth-first traversal of the subtree. These
19563 -- nodes may define new entities in their Actions lists and thus require
19564 -- special processing.
19566 EWA_Inner_Scope_Level
: Nat
:= 0;
19567 -- This counter keeps track of how many scoping constructs appear within
19568 -- an N_Expression_With_Actions node.
19570 procedure Add_New_Entity
(Old_Id
: Entity_Id
; New_Id
: Entity_Id
);
19571 pragma Inline
(Add_New_Entity
);
19572 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19573 -- value New_Id. Old_Id is an entity which appears within the Actions
19574 -- list of an N_Expression_With_Actions node, or within an entity map.
19575 -- New_Id is the corresponding new entity generated during Phase 1.
19577 procedure Add_Pending_Itype
(Assoc_Nod
: Node_Id
; Itype
: Entity_Id
);
19578 pragma Inline
(Add_New_Entity
);
19579 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19580 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19583 procedure Build_NCT_Tables
(Entity_Map
: Elist_Id
);
19584 pragma Inline
(Build_NCT_Tables
);
19585 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19586 -- information supplied in entity map Entity_Map. The format of the
19587 -- entity map must be as follows:
19589 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19591 function Copy_Any_Node_With_Replacement
19592 (N
: Node_Or_Entity_Id
) return Node_Or_Entity_Id
;
19593 pragma Inline
(Copy_Any_Node_With_Replacement
);
19594 -- Replicate entity or node N by invoking one of the following routines:
19596 -- Copy_Node_With_Replacement
19597 -- Corresponding_Entity
19599 function Copy_Elist_With_Replacement
(List
: Elist_Id
) return Elist_Id
;
19600 -- Replicate the elements of entity list List
19602 function Copy_Field_With_Replacement
19604 Old_Par
: Node_Id
:= Empty
;
19605 New_Par
: Node_Id
:= Empty
;
19606 Semantic
: Boolean := False) return Union_Id
;
19607 -- Replicate field Field by invoking one of the following routines:
19609 -- Copy_Elist_With_Replacement
19610 -- Copy_List_With_Replacement
19611 -- Copy_Node_With_Replacement
19612 -- Corresponding_Entity
19614 -- If the field is not an entity list, entity, itype, syntactic list,
19615 -- or node, then the field is returned unchanged. The routine always
19616 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19617 -- the expected parent of a syntactic field. New_Par is the new parent
19618 -- associated with a replicated syntactic field. Flag Semantic should
19619 -- be set when the input is a semantic field.
19621 function Copy_List_With_Replacement
(List
: List_Id
) return List_Id
;
19622 -- Replicate the elements of syntactic list List
19624 function Copy_Node_With_Replacement
(N
: Node_Id
) return Node_Id
;
19625 -- Replicate node N
19627 function Corresponding_Entity
(Id
: Entity_Id
) return Entity_Id
;
19628 pragma Inline
(Corresponding_Entity
);
19629 -- Return the corresponding new entity of Id generated during Phase 1.
19630 -- If there is no such entity, return Id.
19632 function In_Entity_Map
19634 Entity_Map
: Elist_Id
) return Boolean;
19635 pragma Inline
(In_Entity_Map
);
19636 -- Determine whether entity Id is one of the old ids specified in entity
19637 -- map Entity_Map. The format of the entity map must be as follows:
19639 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19641 procedure Update_CFS_Sloc
(N
: Node_Or_Entity_Id
);
19642 pragma Inline
(Update_CFS_Sloc
);
19643 -- Update the Comes_From_Source and Sloc attributes of node or entity N
19645 procedure Update_First_Real_Statement
19646 (Old_HSS
: Node_Id
;
19647 New_HSS
: Node_Id
);
19648 pragma Inline
(Update_First_Real_Statement
);
19649 -- Update semantic attribute First_Real_Statement of handled sequence of
19650 -- statements New_HSS based on handled sequence of statements Old_HSS.
19652 procedure Update_Named_Associations
19653 (Old_Call
: Node_Id
;
19654 New_Call
: Node_Id
);
19655 pragma Inline
(Update_Named_Associations
);
19656 -- Update semantic chain First/Next_Named_Association of call New_call
19657 -- based on call Old_Call.
19659 procedure Update_New_Entities
(Entity_Map
: Elist_Id
);
19660 pragma Inline
(Update_New_Entities
);
19661 -- Update the semantic attributes of all new entities generated during
19662 -- Phase 1 that do not appear in entity map Entity_Map. The format of
19663 -- the entity map must be as follows:
19665 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19667 procedure Update_Pending_Itypes
19668 (Old_Assoc
: Node_Id
;
19669 New_Assoc
: Node_Id
);
19670 pragma Inline
(Update_Pending_Itypes
);
19671 -- Update semantic attribute Associated_Node_For_Itype to refer to node
19672 -- New_Assoc for all itypes whose associated node is Old_Assoc.
19674 procedure Update_Semantic_Fields
(Id
: Entity_Id
);
19675 pragma Inline
(Update_Semantic_Fields
);
19676 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
19679 procedure Visit_Any_Node
(N
: Node_Or_Entity_Id
);
19680 pragma Inline
(Visit_Any_Node
);
19681 -- Visit entity of node N by invoking one of the following routines:
19687 procedure Visit_Elist
(List
: Elist_Id
);
19688 -- Visit the elements of entity list List
19690 procedure Visit_Entity
(Id
: Entity_Id
);
19691 -- Visit entity Id. This action may create a new entity of Id and save
19692 -- it in table NCT_New_Entities.
19694 procedure Visit_Field
19696 Par_Nod
: Node_Id
:= Empty
;
19697 Semantic
: Boolean := False);
19698 -- Visit field Field by invoking one of the following routines:
19706 -- If the field is not an entity list, entity, itype, syntactic list,
19707 -- or node, then the field is not visited. The routine always visits
19708 -- valid syntactic fields. Par_Nod is the expected parent of the
19709 -- syntactic field. Flag Semantic should be set when the input is a
19712 procedure Visit_Itype
(Itype
: Entity_Id
);
19713 -- Visit itype Itype. This action may create a new entity for Itype and
19714 -- save it in table NCT_New_Entities. In addition, the routine may map
19715 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
19717 procedure Visit_List
(List
: List_Id
);
19718 -- Visit the elements of syntactic list List
19720 procedure Visit_Node
(N
: Node_Id
);
19723 procedure Visit_Semantic_Fields
(Id
: Entity_Id
);
19724 pragma Inline
(Visit_Semantic_Fields
);
19725 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
19726 -- fields of entity or itype Id.
19728 --------------------
19729 -- Add_New_Entity --
19730 --------------------
19732 procedure Add_New_Entity
(Old_Id
: Entity_Id
; New_Id
: Entity_Id
) is
19734 pragma Assert
(Present
(Old_Id
));
19735 pragma Assert
(Present
(New_Id
));
19736 pragma Assert
(Nkind
(Old_Id
) in N_Entity
);
19737 pragma Assert
(Nkind
(New_Id
) in N_Entity
);
19739 NCT_Tables_In_Use
:= True;
19741 -- Sanity check the NCT_New_Entities table. No previous mapping with
19742 -- key Old_Id should exist.
19744 pragma Assert
(No
(NCT_New_Entities
.Get
(Old_Id
)));
19746 -- Establish the mapping
19748 -- Old_Id -> New_Id
19750 NCT_New_Entities
.Set
(Old_Id
, New_Id
);
19751 end Add_New_Entity
;
19753 -----------------------
19754 -- Add_Pending_Itype --
19755 -----------------------
19757 procedure Add_Pending_Itype
(Assoc_Nod
: Node_Id
; Itype
: Entity_Id
) is
19761 pragma Assert
(Present
(Assoc_Nod
));
19762 pragma Assert
(Present
(Itype
));
19763 pragma Assert
(Nkind
(Itype
) in N_Entity
);
19764 pragma Assert
(Is_Itype
(Itype
));
19766 NCT_Tables_In_Use
:= True;
19768 -- It is not possible to sanity check the NCT_Pendint_Itypes table
19769 -- directly because a single node may act as the associated node for
19770 -- multiple itypes.
19772 Itypes
:= NCT_Pending_Itypes
.Get
(Assoc_Nod
);
19774 if No
(Itypes
) then
19775 Itypes
:= New_Elmt_List
;
19776 NCT_Pending_Itypes
.Set
(Assoc_Nod
, Itypes
);
19779 -- Establish the mapping
19781 -- Assoc_Nod -> (Itype, ...)
19783 -- Avoid inserting the same itype multiple times. This involves a
19784 -- linear search, however the set of itypes with the same associated
19785 -- node is very small.
19787 Append_Unique_Elmt
(Itype
, Itypes
);
19788 end Add_Pending_Itype
;
19790 ----------------------
19791 -- Build_NCT_Tables --
19792 ----------------------
19794 procedure Build_NCT_Tables
(Entity_Map
: Elist_Id
) is
19796 Old_Id
: Entity_Id
;
19797 New_Id
: Entity_Id
;
19800 -- Nothing to do when there is no entity map
19802 if No
(Entity_Map
) then
19806 Elmt
:= First_Elmt
(Entity_Map
);
19807 while Present
(Elmt
) loop
19809 -- Extract the (Old_Id, New_Id) pair from the entity map
19811 Old_Id
:= Node
(Elmt
);
19814 New_Id
:= Node
(Elmt
);
19817 -- Establish the following mapping within table NCT_New_Entities
19819 -- Old_Id -> New_Id
19821 Add_New_Entity
(Old_Id
, New_Id
);
19823 -- Establish the following mapping within table NCT_Pending_Itypes
19824 -- when the new entity is an itype.
19826 -- Assoc_Nod -> (New_Id, ...)
19828 -- IMPORTANT: the associated node is that of the old itype because
19829 -- the node will be replicated in Phase 2.
19831 if Is_Itype
(Old_Id
) then
19833 (Assoc_Nod
=> Associated_Node_For_Itype
(Old_Id
),
19837 end Build_NCT_Tables
;
19839 ------------------------------------
19840 -- Copy_Any_Node_With_Replacement --
19841 ------------------------------------
19843 function Copy_Any_Node_With_Replacement
19844 (N
: Node_Or_Entity_Id
) return Node_Or_Entity_Id
19847 if Nkind
(N
) in N_Entity
then
19848 return Corresponding_Entity
(N
);
19850 return Copy_Node_With_Replacement
(N
);
19852 end Copy_Any_Node_With_Replacement
;
19854 ---------------------------------
19855 -- Copy_Elist_With_Replacement --
19856 ---------------------------------
19858 function Copy_Elist_With_Replacement
(List
: Elist_Id
) return Elist_Id
is
19863 -- Copy the contents of the old list. Note that the list itself may
19864 -- be empty, in which case the routine returns a new empty list. This
19865 -- avoids sharing lists between subtrees. The element of an entity
19866 -- list could be an entity or a node, hence the invocation of routine
19867 -- Copy_Any_Node_With_Replacement.
19869 if Present
(List
) then
19870 Result
:= New_Elmt_List
;
19872 Elmt
:= First_Elmt
(List
);
19873 while Present
(Elmt
) loop
19875 (Copy_Any_Node_With_Replacement
(Node
(Elmt
)), Result
);
19880 -- Otherwise the list does not exist
19883 Result
:= No_Elist
;
19887 end Copy_Elist_With_Replacement
;
19889 ---------------------------------
19890 -- Copy_Field_With_Replacement --
19891 ---------------------------------
19893 function Copy_Field_With_Replacement
19895 Old_Par
: Node_Id
:= Empty
;
19896 New_Par
: Node_Id
:= Empty
;
19897 Semantic
: Boolean := False) return Union_Id
19900 -- The field is empty
19902 if Field
= Union_Id
(Empty
) then
19905 -- The field is an entity/itype/node
19907 elsif Field
in Node_Range
then
19909 Old_N
: constant Node_Id
:= Node_Id
(Field
);
19910 Syntactic
: constant Boolean := Parent
(Old_N
) = Old_Par
;
19915 -- The field is an entity/itype
19917 if Nkind
(Old_N
) in N_Entity
then
19919 -- An entity/itype is always replicated
19921 New_N
:= Corresponding_Entity
(Old_N
);
19923 -- Update the parent pointer when the entity is a syntactic
19924 -- field. Note that itypes do not have parent pointers.
19926 if Syntactic
and then New_N
/= Old_N
then
19927 Set_Parent
(New_N
, New_Par
);
19930 -- The field is a node
19933 -- A node is replicated when it is either a syntactic field
19934 -- or when the caller treats it as a semantic attribute.
19936 if Syntactic
or else Semantic
then
19937 New_N
:= Copy_Node_With_Replacement
(Old_N
);
19939 -- Update the parent pointer when the node is a syntactic
19942 if Syntactic
and then New_N
/= Old_N
then
19943 Set_Parent
(New_N
, New_Par
);
19946 -- Otherwise the node is returned unchanged
19953 return Union_Id
(New_N
);
19956 -- The field is an entity list
19958 elsif Field
in Elist_Range
then
19959 return Union_Id
(Copy_Elist_With_Replacement
(Elist_Id
(Field
)));
19961 -- The field is a syntactic list
19963 elsif Field
in List_Range
then
19965 Old_List
: constant List_Id
:= List_Id
(Field
);
19966 Syntactic
: constant Boolean := Parent
(Old_List
) = Old_Par
;
19968 New_List
: List_Id
;
19971 -- A list is replicated when it is either a syntactic field or
19972 -- when the caller treats it as a semantic attribute.
19974 if Syntactic
or else Semantic
then
19975 New_List
:= Copy_List_With_Replacement
(Old_List
);
19977 -- Update the parent pointer when the list is a syntactic
19980 if Syntactic
and then New_List
/= Old_List
then
19981 Set_Parent
(New_List
, New_Par
);
19984 -- Otherwise the list is returned unchanged
19987 New_List
:= Old_List
;
19990 return Union_Id
(New_List
);
19993 -- Otherwise the field denotes an attribute that does not need to be
19994 -- replicated (Chars, literals, etc).
19999 end Copy_Field_With_Replacement
;
20001 --------------------------------
20002 -- Copy_List_With_Replacement --
20003 --------------------------------
20005 function Copy_List_With_Replacement
(List
: List_Id
) return List_Id
is
20010 -- Copy the contents of the old list. Note that the list itself may
20011 -- be empty, in which case the routine returns a new empty list. This
20012 -- avoids sharing lists between subtrees. The element of a syntactic
20013 -- list is always a node, never an entity or itype, hence the call to
20014 -- routine Copy_Node_With_Replacement.
20016 if Present
(List
) then
20017 Result
:= New_List
;
20019 Elmt
:= First
(List
);
20020 while Present
(Elmt
) loop
20021 Append
(Copy_Node_With_Replacement
(Elmt
), Result
);
20026 -- Otherwise the list does not exist
20033 end Copy_List_With_Replacement
;
20035 --------------------------------
20036 -- Copy_Node_With_Replacement --
20037 --------------------------------
20039 function Copy_Node_With_Replacement
(N
: Node_Id
) return Node_Id
is
20043 -- Assume that the node must be returned unchanged
20047 if N
> Empty_Or_Error
then
20048 pragma Assert
(Nkind
(N
) not in N_Entity
);
20050 Result
:= New_Copy
(N
);
20052 Set_Field1
(Result
,
20053 Copy_Field_With_Replacement
20054 (Field
=> Field1
(Result
),
20056 New_Par
=> Result
));
20058 Set_Field2
(Result
,
20059 Copy_Field_With_Replacement
20060 (Field
=> Field2
(Result
),
20062 New_Par
=> Result
));
20064 Set_Field3
(Result
,
20065 Copy_Field_With_Replacement
20066 (Field
=> Field3
(Result
),
20068 New_Par
=> Result
));
20070 Set_Field4
(Result
,
20071 Copy_Field_With_Replacement
20072 (Field
=> Field4
(Result
),
20074 New_Par
=> Result
));
20076 Set_Field5
(Result
,
20077 Copy_Field_With_Replacement
20078 (Field
=> Field5
(Result
),
20080 New_Par
=> Result
));
20082 -- Update the Comes_From_Source and Sloc attributes of the node
20083 -- in case the caller has supplied new values.
20085 Update_CFS_Sloc
(Result
);
20087 -- Update the Associated_Node_For_Itype attribute of all itypes
20088 -- created during Phase 1 whose associated node is N. As a result
20089 -- the Associated_Node_For_Itype refers to the replicated node.
20090 -- No action needs to be taken when the Associated_Node_For_Itype
20091 -- refers to an entity because this was already handled during
20092 -- Phase 1, in Visit_Itype.
20094 Update_Pending_Itypes
20096 New_Assoc
=> Result
);
20098 -- Update the First/Next_Named_Association chain for a replicated
20101 if Nkind_In
(N
, N_Entry_Call_Statement
,
20103 N_Procedure_Call_Statement
)
20105 Update_Named_Associations
20107 New_Call
=> Result
);
20109 -- Update the Renamed_Object attribute of a replicated object
20112 elsif Nkind
(N
) = N_Object_Renaming_Declaration
then
20113 Set_Renamed_Object
(Defining_Entity
(Result
), Name
(Result
));
20115 -- Update the First_Real_Statement attribute of a replicated
20116 -- handled sequence of statements.
20118 elsif Nkind
(N
) = N_Handled_Sequence_Of_Statements
then
20119 Update_First_Real_Statement
20121 New_HSS
=> Result
);
20126 end Copy_Node_With_Replacement
;
20128 --------------------------
20129 -- Corresponding_Entity --
20130 --------------------------
20132 function Corresponding_Entity
(Id
: Entity_Id
) return Entity_Id
is
20133 New_Id
: Entity_Id
;
20134 Result
: Entity_Id
;
20137 -- Assume that the entity must be returned unchanged
20141 if Id
> Empty_Or_Error
then
20142 pragma Assert
(Nkind
(Id
) in N_Entity
);
20144 -- Determine whether the entity has a corresponding new entity
20145 -- generated during Phase 1 and if it does, use it.
20147 if NCT_Tables_In_Use
then
20148 New_Id
:= NCT_New_Entities
.Get
(Id
);
20150 if Present
(New_Id
) then
20157 end Corresponding_Entity
;
20159 -------------------
20160 -- In_Entity_Map --
20161 -------------------
20163 function In_Entity_Map
20165 Entity_Map
: Elist_Id
) return Boolean
20168 Old_Id
: Entity_Id
;
20171 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20172 -- step always skips the New_Id portion of the pair.
20174 if Present
(Entity_Map
) then
20175 Elmt
:= First_Elmt
(Entity_Map
);
20176 while Present
(Elmt
) loop
20177 Old_Id
:= Node
(Elmt
);
20179 if Old_Id
= Id
then
20191 ---------------------
20192 -- Update_CFS_Sloc --
20193 ---------------------
20195 procedure Update_CFS_Sloc
(N
: Node_Or_Entity_Id
) is
20197 -- A new source location defaults the Comes_From_Source attribute
20199 if New_Sloc
/= No_Location
then
20200 Set_Comes_From_Source
(N
, Default_Node
.Comes_From_Source
);
20201 Set_Sloc
(N
, New_Sloc
);
20203 end Update_CFS_Sloc
;
20205 ---------------------------------
20206 -- Update_First_Real_Statement --
20207 ---------------------------------
20209 procedure Update_First_Real_Statement
20210 (Old_HSS
: Node_Id
;
20213 Old_First_Stmt
: constant Node_Id
:= First_Real_Statement
(Old_HSS
);
20215 New_Stmt
: Node_Id
;
20216 Old_Stmt
: Node_Id
;
20219 -- Recreate the First_Real_Statement attribute of a handled sequence
20220 -- of statements by traversing the statement lists of both sequences
20223 if Present
(Old_First_Stmt
) then
20224 New_Stmt
:= First
(Statements
(New_HSS
));
20225 Old_Stmt
:= First
(Statements
(Old_HSS
));
20226 while Present
(Old_Stmt
) and then Old_Stmt
/= Old_First_Stmt
loop
20231 pragma Assert
(Present
(New_Stmt
));
20232 pragma Assert
(Present
(Old_Stmt
));
20234 Set_First_Real_Statement
(New_HSS
, New_Stmt
);
20236 end Update_First_Real_Statement
;
20238 -------------------------------
20239 -- Update_Named_Associations --
20240 -------------------------------
20242 procedure Update_Named_Associations
20243 (Old_Call
: Node_Id
;
20244 New_Call
: Node_Id
)
20247 New_Next
: Node_Id
;
20249 Old_Next
: Node_Id
;
20252 -- Recreate the First/Next_Named_Actual chain of a call by traversing
20253 -- the chains of both the old and new calls in parallel.
20255 New_Act
:= First
(Parameter_Associations
(New_Call
));
20256 Old_Act
:= First
(Parameter_Associations
(Old_Call
));
20257 while Present
(Old_Act
) loop
20258 if Nkind
(Old_Act
) = N_Parameter_Association
20259 and then Present
(Next_Named_Actual
(Old_Act
))
20261 if First_Named_Actual
(Old_Call
) =
20262 Explicit_Actual_Parameter
(Old_Act
)
20264 Set_First_Named_Actual
(New_Call
,
20265 Explicit_Actual_Parameter
(New_Act
));
20268 -- Scan the actual parameter list to find the next suitable
20269 -- named actual. Note that the list may be out of order.
20271 New_Next
:= First
(Parameter_Associations
(New_Call
));
20272 Old_Next
:= First
(Parameter_Associations
(Old_Call
));
20273 while Nkind
(Old_Next
) /= N_Parameter_Association
20274 or else Explicit_Actual_Parameter
(Old_Next
) /=
20275 Next_Named_Actual
(Old_Act
)
20281 Set_Next_Named_Actual
(New_Act
,
20282 Explicit_Actual_Parameter
(New_Next
));
20288 end Update_Named_Associations
;
20290 -------------------------
20291 -- Update_New_Entities --
20292 -------------------------
20294 procedure Update_New_Entities
(Entity_Map
: Elist_Id
) is
20295 New_Id
: Entity_Id
:= Empty
;
20296 Old_Id
: Entity_Id
:= Empty
;
20299 if NCT_Tables_In_Use
then
20300 NCT_New_Entities
.Get_First
(Old_Id
, New_Id
);
20302 -- Update the semantic fields of all new entities created during
20303 -- Phase 1 which were not supplied via an entity map.
20304 -- ??? Is there a better way of distinguishing those?
20306 while Present
(Old_Id
) and then Present
(New_Id
) loop
20307 if not (Present
(Entity_Map
)
20308 and then In_Entity_Map
(Old_Id
, Entity_Map
))
20310 Update_Semantic_Fields
(New_Id
);
20313 NCT_New_Entities
.Get_Next
(Old_Id
, New_Id
);
20316 end Update_New_Entities
;
20318 ---------------------------
20319 -- Update_Pending_Itypes --
20320 ---------------------------
20322 procedure Update_Pending_Itypes
20323 (Old_Assoc
: Node_Id
;
20324 New_Assoc
: Node_Id
)
20330 if NCT_Tables_In_Use
then
20331 Itypes
:= NCT_Pending_Itypes
.Get
(Old_Assoc
);
20333 -- Update the Associated_Node_For_Itype attribute for all itypes
20334 -- which originally refer to Old_Assoc to designate New_Assoc.
20336 if Present
(Itypes
) then
20337 Item
:= First_Elmt
(Itypes
);
20338 while Present
(Item
) loop
20339 Set_Associated_Node_For_Itype
(Node
(Item
), New_Assoc
);
20345 end Update_Pending_Itypes
;
20347 ----------------------------
20348 -- Update_Semantic_Fields --
20349 ----------------------------
20351 procedure Update_Semantic_Fields
(Id
: Entity_Id
) is
20353 -- Discriminant_Constraint
20355 if Is_Type
(Id
) and then Has_Discriminants
(Base_Type
(Id
)) then
20356 Set_Discriminant_Constraint
(Id
, Elist_Id
(
20357 Copy_Field_With_Replacement
20358 (Field
=> Union_Id
(Discriminant_Constraint
(Id
)),
20359 Semantic
=> True)));
20364 Set_Etype
(Id
, Node_Id
(
20365 Copy_Field_With_Replacement
20366 (Field
=> Union_Id
(Etype
(Id
)),
20367 Semantic
=> True)));
20370 -- Packed_Array_Impl_Type
20372 if Is_Array_Type
(Id
) then
20373 if Present
(First_Index
(Id
)) then
20374 Set_First_Index
(Id
, First
(List_Id
(
20375 Copy_Field_With_Replacement
20376 (Field
=> Union_Id
(List_Containing
(First_Index
(Id
))),
20377 Semantic
=> True))));
20380 if Is_Packed
(Id
) then
20381 Set_Packed_Array_Impl_Type
(Id
, Node_Id
(
20382 Copy_Field_With_Replacement
20383 (Field
=> Union_Id
(Packed_Array_Impl_Type
(Id
)),
20384 Semantic
=> True)));
20390 Set_Prev_Entity
(Id
, Node_Id
(
20391 Copy_Field_With_Replacement
20392 (Field
=> Union_Id
(Prev_Entity
(Id
)),
20393 Semantic
=> True)));
20397 Set_Next_Entity
(Id
, Node_Id
(
20398 Copy_Field_With_Replacement
20399 (Field
=> Union_Id
(Next_Entity
(Id
)),
20400 Semantic
=> True)));
20404 if Is_Discrete_Type
(Id
) then
20405 Set_Scalar_Range
(Id
, Node_Id
(
20406 Copy_Field_With_Replacement
20407 (Field
=> Union_Id
(Scalar_Range
(Id
)),
20408 Semantic
=> True)));
20413 -- Update the scope when the caller specified an explicit one
20415 if Present
(New_Scope
) then
20416 Set_Scope
(Id
, New_Scope
);
20418 Set_Scope
(Id
, Node_Id
(
20419 Copy_Field_With_Replacement
20420 (Field
=> Union_Id
(Scope
(Id
)),
20421 Semantic
=> True)));
20423 end Update_Semantic_Fields
;
20425 --------------------
20426 -- Visit_Any_Node --
20427 --------------------
20429 procedure Visit_Any_Node
(N
: Node_Or_Entity_Id
) is
20431 if Nkind
(N
) in N_Entity
then
20432 if Is_Itype
(N
) then
20440 end Visit_Any_Node
;
20446 procedure Visit_Elist
(List
: Elist_Id
) is
20450 -- The element of an entity list could be an entity, itype, or a
20451 -- node, hence the call to Visit_Any_Node.
20453 if Present
(List
) then
20454 Elmt
:= First_Elmt
(List
);
20455 while Present
(Elmt
) loop
20456 Visit_Any_Node
(Node
(Elmt
));
20467 procedure Visit_Entity
(Id
: Entity_Id
) is
20468 New_Id
: Entity_Id
;
20471 pragma Assert
(Nkind
(Id
) in N_Entity
);
20472 pragma Assert
(not Is_Itype
(Id
));
20474 -- Nothing to do when the entity is not defined in the Actions list
20475 -- of an N_Expression_With_Actions node.
20477 if EWA_Level
= 0 then
20480 -- Nothing to do when the entity is defined in a scoping construct
20481 -- within an N_Expression_With_Actions node, unless the caller has
20482 -- requested their replication.
20484 -- ??? should this restriction be eliminated?
20486 elsif EWA_Inner_Scope_Level
> 0 and then not Scopes_In_EWA_OK
then
20489 -- Nothing to do when the entity does not denote a construct that
20490 -- may appear within an N_Expression_With_Actions node. Relaxing
20491 -- this restriction leads to a performance penalty.
20493 -- ??? this list is flaky, and may hide dormant bugs
20495 elsif not Ekind_In
(Id
, E_Block
,
20500 and then not Is_Type
(Id
)
20504 -- Nothing to do when the entity was already visited
20506 elsif NCT_Tables_In_Use
20507 and then Present
(NCT_New_Entities
.Get
(Id
))
20511 -- Nothing to do when the declaration node of the entity is not in
20512 -- the subtree being replicated.
20514 elsif not In_Subtree
20515 (N
=> Declaration_Node
(Id
),
20521 -- Create a new entity by directly copying the old entity. This
20522 -- action causes all attributes of the old entity to be inherited.
20524 New_Id
:= New_Copy
(Id
);
20526 -- Create a new name for the new entity because the back end needs
20527 -- distinct names for debugging purposes.
20529 Set_Chars
(New_Id
, New_Internal_Name
('T'));
20531 -- Update the Comes_From_Source and Sloc attributes of the entity in
20532 -- case the caller has supplied new values.
20534 Update_CFS_Sloc
(New_Id
);
20536 -- Establish the following mapping within table NCT_New_Entities:
20540 Add_New_Entity
(Id
, New_Id
);
20542 -- Deal with the semantic fields of entities. The fields are visited
20543 -- because they may mention entities which reside within the subtree
20546 Visit_Semantic_Fields
(Id
);
20553 procedure Visit_Field
20555 Par_Nod
: Node_Id
:= Empty
;
20556 Semantic
: Boolean := False)
20559 -- The field is empty
20561 if Field
= Union_Id
(Empty
) then
20564 -- The field is an entity/itype/node
20566 elsif Field
in Node_Range
then
20568 N
: constant Node_Id
:= Node_Id
(Field
);
20571 -- The field is an entity/itype
20573 if Nkind
(N
) in N_Entity
then
20575 -- Itypes are always visited
20577 if Is_Itype
(N
) then
20580 -- An entity is visited when it is either a syntactic field
20581 -- or when the caller treats it as a semantic attribute.
20583 elsif Parent
(N
) = Par_Nod
or else Semantic
then
20587 -- The field is a node
20590 -- A node is visited when it is either a syntactic field or
20591 -- when the caller treats it as a semantic attribute.
20593 if Parent
(N
) = Par_Nod
or else Semantic
then
20599 -- The field is an entity list
20601 elsif Field
in Elist_Range
then
20602 Visit_Elist
(Elist_Id
(Field
));
20604 -- The field is a syntax list
20606 elsif Field
in List_Range
then
20608 List
: constant List_Id
:= List_Id
(Field
);
20611 -- A syntax list is visited when it is either a syntactic field
20612 -- or when the caller treats it as a semantic attribute.
20614 if Parent
(List
) = Par_Nod
or else Semantic
then
20619 -- Otherwise the field denotes information which does not need to be
20620 -- visited (chars, literals, etc.).
20631 procedure Visit_Itype
(Itype
: Entity_Id
) is
20632 New_Assoc
: Node_Id
;
20633 New_Itype
: Entity_Id
;
20634 Old_Assoc
: Node_Id
;
20637 pragma Assert
(Nkind
(Itype
) in N_Entity
);
20638 pragma Assert
(Is_Itype
(Itype
));
20640 -- Itypes that describe the designated type of access to subprograms
20641 -- have the structure of subprogram declarations, with signatures,
20642 -- etc. Either we duplicate the signatures completely, or choose to
20643 -- share such itypes, which is fine because their elaboration will
20644 -- have no side effects.
20646 if Ekind
(Itype
) = E_Subprogram_Type
then
20649 -- Nothing to do if the itype was already visited
20651 elsif NCT_Tables_In_Use
20652 and then Present
(NCT_New_Entities
.Get
(Itype
))
20656 -- Nothing to do if the associated node of the itype is not within
20657 -- the subtree being replicated.
20659 elsif not In_Subtree
20660 (N
=> Associated_Node_For_Itype
(Itype
),
20666 -- Create a new itype by directly copying the old itype. This action
20667 -- causes all attributes of the old itype to be inherited.
20669 New_Itype
:= New_Copy
(Itype
);
20671 -- Create a new name for the new itype because the back end requires
20672 -- distinct names for debugging purposes.
20674 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
20676 -- Update the Comes_From_Source and Sloc attributes of the itype in
20677 -- case the caller has supplied new values.
20679 Update_CFS_Sloc
(New_Itype
);
20681 -- Establish the following mapping within table NCT_New_Entities:
20683 -- Itype -> New_Itype
20685 Add_New_Entity
(Itype
, New_Itype
);
20687 -- The new itype must be unfrozen because the resulting subtree may
20688 -- be inserted anywhere and cause an earlier or later freezing.
20690 if Present
(Freeze_Node
(New_Itype
)) then
20691 Set_Freeze_Node
(New_Itype
, Empty
);
20692 Set_Is_Frozen
(New_Itype
, False);
20695 -- If a record subtype is simply copied, the entity list will be
20696 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
20697 -- ??? What does this do?
20699 if Ekind_In
(Itype
, E_Class_Wide_Subtype
, E_Record_Subtype
) then
20700 Set_Cloned_Subtype
(New_Itype
, Itype
);
20703 -- The associated node may denote an entity, in which case it may
20704 -- already have a new corresponding entity created during a prior
20705 -- call to Visit_Entity or Visit_Itype for the same subtree.
20708 -- Old_Assoc ---------> New_Assoc
20710 -- Created by Visit_Itype
20711 -- Itype -------------> New_Itype
20712 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
20714 -- In the example above, Old_Assoc is an arbitrary entity that was
20715 -- already visited for the same subtree and has a corresponding new
20716 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
20717 -- of copying entities, however it must be updated to New_Assoc.
20719 Old_Assoc
:= Associated_Node_For_Itype
(Itype
);
20721 if Nkind
(Old_Assoc
) in N_Entity
then
20722 if NCT_Tables_In_Use
then
20723 New_Assoc
:= NCT_New_Entities
.Get
(Old_Assoc
);
20725 if Present
(New_Assoc
) then
20726 Set_Associated_Node_For_Itype
(New_Itype
, New_Assoc
);
20730 -- Otherwise the associated node denotes a node. Postpone the update
20731 -- until Phase 2 when the node is replicated. Establish the following
20732 -- mapping within table NCT_Pending_Itypes:
20734 -- Old_Assoc -> (New_Type, ...)
20737 Add_Pending_Itype
(Old_Assoc
, New_Itype
);
20740 -- Deal with the semantic fields of itypes. The fields are visited
20741 -- because they may mention entities that reside within the subtree
20744 Visit_Semantic_Fields
(Itype
);
20751 procedure Visit_List
(List
: List_Id
) is
20755 -- Note that the element of a syntactic list is always a node, never
20756 -- an entity or itype, hence the call to Visit_Node.
20758 if Present
(List
) then
20759 Elmt
:= First
(List
);
20760 while Present
(Elmt
) loop
20772 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
20774 pragma Assert
(Nkind
(N
) not in N_Entity
);
20776 if Nkind
(N
) = N_Expression_With_Actions
then
20777 EWA_Level
:= EWA_Level
+ 1;
20779 elsif EWA_Level
> 0
20780 and then Nkind_In
(N
, N_Block_Statement
,
20782 N_Subprogram_Declaration
)
20784 EWA_Inner_Scope_Level
:= EWA_Inner_Scope_Level
+ 1;
20788 (Field
=> Field1
(N
),
20792 (Field
=> Field2
(N
),
20796 (Field
=> Field3
(N
),
20800 (Field
=> Field4
(N
),
20804 (Field
=> Field5
(N
),
20808 and then Nkind_In
(N
, N_Block_Statement
,
20810 N_Subprogram_Declaration
)
20812 EWA_Inner_Scope_Level
:= EWA_Inner_Scope_Level
- 1;
20814 elsif Nkind
(N
) = N_Expression_With_Actions
then
20815 EWA_Level
:= EWA_Level
- 1;
20819 ---------------------------
20820 -- Visit_Semantic_Fields --
20821 ---------------------------
20823 procedure Visit_Semantic_Fields
(Id
: Entity_Id
) is
20825 pragma Assert
(Nkind
(Id
) in N_Entity
);
20827 -- Discriminant_Constraint
20829 if Is_Type
(Id
) and then Has_Discriminants
(Base_Type
(Id
)) then
20831 (Field
=> Union_Id
(Discriminant_Constraint
(Id
)),
20838 (Field
=> Union_Id
(Etype
(Id
)),
20842 -- Packed_Array_Impl_Type
20844 if Is_Array_Type
(Id
) then
20845 if Present
(First_Index
(Id
)) then
20847 (Field
=> Union_Id
(List_Containing
(First_Index
(Id
))),
20851 if Is_Packed
(Id
) then
20853 (Field
=> Union_Id
(Packed_Array_Impl_Type
(Id
)),
20860 if Is_Discrete_Type
(Id
) then
20862 (Field
=> Union_Id
(Scalar_Range
(Id
)),
20865 end Visit_Semantic_Fields
;
20867 -- Start of processing for New_Copy_Tree
20870 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
20871 -- shallow copies for each node within, and then updating the child and
20872 -- parent pointers accordingly. This process is straightforward, however
20873 -- the routine must deal with the following complications:
20875 -- * Entities defined within N_Expression_With_Actions nodes must be
20876 -- replicated rather than shared to avoid introducing two identical
20877 -- symbols within the same scope. Note that no other expression can
20878 -- currently define entities.
20881 -- Source_Low : ...;
20882 -- Source_High : ...;
20884 -- <reference to Source_Low>
20885 -- <reference to Source_High>
20888 -- New_Copy_Tree handles this case by first creating new entities
20889 -- and then updating all existing references to point to these new
20896 -- <reference to New_Low>
20897 -- <reference to New_High>
20900 -- * Itypes defined within the subtree must be replicated to avoid any
20901 -- dependencies on invalid or inaccessible data.
20903 -- subtype Source_Itype is ... range Source_Low .. Source_High;
20905 -- New_Copy_Tree handles this case by first creating a new itype in
20906 -- the same fashion as entities, and then updating various relevant
20909 -- subtype New_Itype is ... range New_Low .. New_High;
20911 -- * The Associated_Node_For_Itype field of itypes must be updated to
20912 -- reference the proper replicated entity or node.
20914 -- * Semantic fields of entities such as Etype and Scope must be
20915 -- updated to reference the proper replicated entities.
20917 -- * Semantic fields of nodes such as First_Real_Statement must be
20918 -- updated to reference the proper replicated nodes.
20920 -- To meet all these demands, routine New_Copy_Tree is split into two
20923 -- Phase 1 traverses the tree in order to locate entities and itypes
20924 -- defined within the subtree. New entities are generated and saved in
20925 -- table NCT_New_Entities. The semantic fields of all new entities and
20926 -- itypes are then updated accordingly.
20928 -- Phase 2 traverses the tree in order to replicate each node. Various
20929 -- semantic fields of nodes and entities are updated accordingly.
20931 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
20932 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
20935 if NCT_Tables_In_Use
then
20936 NCT_Tables_In_Use
:= False;
20938 NCT_New_Entities
.Reset
;
20939 NCT_Pending_Itypes
.Reset
;
20942 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
20943 -- supplied by a linear entity map. The tables offer faster access to
20946 Build_NCT_Tables
(Map
);
20948 -- Execute Phase 1. Traverse the subtree and generate new entities for
20949 -- the following cases:
20951 -- * An entity defined within an N_Expression_With_Actions node
20953 -- * An itype referenced within the subtree where the associated node
20954 -- is also in the subtree.
20956 -- All new entities are accessible via table NCT_New_Entities, which
20957 -- contains mappings of the form:
20959 -- Old_Entity -> New_Entity
20960 -- Old_Itype -> New_Itype
20962 -- In addition, the associated nodes of all new itypes are mapped in
20963 -- table NCT_Pending_Itypes:
20965 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
20967 Visit_Any_Node
(Source
);
20969 -- Update the semantic attributes of all new entities generated during
20970 -- Phase 1 before starting Phase 2. The updates could be performed in
20971 -- routine Corresponding_Entity, however this may cause the same entity
20972 -- to be updated multiple times, effectively generating useless nodes.
20973 -- Keeping the updates separates from Phase 2 ensures that only one set
20974 -- of attributes is generated for an entity at any one time.
20976 Update_New_Entities
(Map
);
20978 -- Execute Phase 2. Replicate the source subtree one node at a time.
20979 -- The following transformations take place:
20981 -- * References to entities and itypes are updated to refer to the
20982 -- new entities and itypes generated during Phase 1.
20984 -- * All Associated_Node_For_Itype attributes of itypes are updated
20985 -- to refer to the new replicated Associated_Node_For_Itype.
20987 return Copy_Node_With_Replacement
(Source
);
20990 -------------------------
20991 -- New_External_Entity --
20992 -------------------------
20994 function New_External_Entity
20995 (Kind
: Entity_Kind
;
20996 Scope_Id
: Entity_Id
;
20997 Sloc_Value
: Source_Ptr
;
20998 Related_Id
: Entity_Id
;
20999 Suffix
: Character;
21000 Suffix_Index
: Int
:= 0;
21001 Prefix
: Character := ' ') return Entity_Id
21003 N
: constant Entity_Id
:=
21004 Make_Defining_Identifier
(Sloc_Value
,
21006 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
21009 Set_Ekind
(N
, Kind
);
21010 Set_Is_Internal
(N
, True);
21011 Append_Entity
(N
, Scope_Id
);
21012 Set_Public_Status
(N
);
21014 if Kind
in Type_Kind
then
21015 Init_Size_Align
(N
);
21019 end New_External_Entity
;
21021 -------------------------
21022 -- New_Internal_Entity --
21023 -------------------------
21025 function New_Internal_Entity
21026 (Kind
: Entity_Kind
;
21027 Scope_Id
: Entity_Id
;
21028 Sloc_Value
: Source_Ptr
;
21029 Id_Char
: Character) return Entity_Id
21031 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
21034 Set_Ekind
(N
, Kind
);
21035 Set_Is_Internal
(N
, True);
21036 Append_Entity
(N
, Scope_Id
);
21038 if Kind
in Type_Kind
then
21039 Init_Size_Align
(N
);
21043 end New_Internal_Entity
;
21049 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
21050 Par
: constant Node_Id
:= Parent
(Actual_Id
);
21054 -- If we are pointing at a positional parameter, it is a member of a
21055 -- node list (the list of parameters), and the next parameter is the
21056 -- next node on the list, unless we hit a parameter association, then
21057 -- we shift to using the chain whose head is the First_Named_Actual in
21058 -- the parent, and then is threaded using the Next_Named_Actual of the
21059 -- Parameter_Association. All this fiddling is because the original node
21060 -- list is in the textual call order, and what we need is the
21061 -- declaration order.
21063 if Is_List_Member
(Actual_Id
) then
21064 N
:= Next
(Actual_Id
);
21066 if Nkind
(N
) = N_Parameter_Association
then
21068 -- In case of a build-in-place call, the call will no longer be a
21069 -- call; it will have been rewritten.
21071 if Nkind_In
(Par
, N_Entry_Call_Statement
,
21073 N_Procedure_Call_Statement
)
21075 return First_Named_Actual
(Par
);
21077 -- In case of a call rewritten in GNATprove mode while "inlining
21078 -- for proof" go to the original call.
21080 elsif Nkind
(Par
) = N_Null_Statement
then
21084 Nkind
(Original_Node
(Par
)) in N_Subprogram_Call
);
21086 return First_Named_Actual
(Original_Node
(Par
));
21095 return Next_Named_Actual
(Parent
(Actual_Id
));
21099 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
21101 Actual_Id
:= Next_Actual
(Actual_Id
);
21108 function Next_Global
(Node
: Node_Id
) return Node_Id
is
21110 -- The global item may either be in a list, or by itself, in which case
21111 -- there is no next global item with the same mode.
21113 if Is_List_Member
(Node
) then
21114 return Next
(Node
);
21120 procedure Next_Global
(Node
: in out Node_Id
) is
21122 Node
:= Next_Global
(Node
);
21125 ----------------------------------
21126 -- New_Requires_Transient_Scope --
21127 ----------------------------------
21129 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
21130 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean;
21131 -- This is called for untagged records and protected types, with
21132 -- nondefaulted discriminants. Returns True if the size of function
21133 -- results is known at the call site, False otherwise. Returns False
21134 -- if there is a variant part that depends on the discriminants of
21135 -- this type, or if there is an array constrained by the discriminants
21136 -- of this type. ???Currently, this is overly conservative (the array
21137 -- could be nested inside some other record that is constrained by
21138 -- nondiscriminants). That is, the recursive calls are too conservative.
21140 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean;
21141 -- Returns True if Typ is a nonlimited record with defaulted
21142 -- discriminants whose max size makes it unsuitable for allocating on
21143 -- the primary stack.
21145 ------------------------------
21146 -- Caller_Known_Size_Record --
21147 ------------------------------
21149 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean is
21150 pragma Assert
(Typ
= Underlying_Type
(Typ
));
21153 if Has_Variant_Part
(Typ
) and then not Is_Definite_Subtype
(Typ
) then
21161 Comp
:= First_Entity
(Typ
);
21162 while Present
(Comp
) loop
21164 -- Only look at E_Component entities. No need to look at
21165 -- E_Discriminant entities, and we must ignore internal
21166 -- subtypes generated for constrained components.
21168 if Ekind
(Comp
) = E_Component
then
21170 Comp_Type
: constant Entity_Id
:=
21171 Underlying_Type
(Etype
(Comp
));
21174 if Is_Record_Type
(Comp_Type
)
21176 Is_Protected_Type
(Comp_Type
)
21178 if not Caller_Known_Size_Record
(Comp_Type
) then
21182 elsif Is_Array_Type
(Comp_Type
) then
21183 if Size_Depends_On_Discriminant
(Comp_Type
) then
21190 Next_Entity
(Comp
);
21195 end Caller_Known_Size_Record
;
21197 ------------------------------
21198 -- Large_Max_Size_Mutable --
21199 ------------------------------
21201 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean is
21202 pragma Assert
(Typ
= Underlying_Type
(Typ
));
21204 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean;
21205 -- Returns true if the discrete type T has a large range
21207 ----------------------------
21208 -- Is_Large_Discrete_Type --
21209 ----------------------------
21211 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean is
21212 Threshold
: constant Int
:= 16;
21213 -- Arbitrary threshold above which we consider it "large". We want
21214 -- a fairly large threshold, because these large types really
21215 -- shouldn't have default discriminants in the first place, in
21219 return UI_To_Int
(RM_Size
(T
)) > Threshold
;
21220 end Is_Large_Discrete_Type
;
21222 -- Start of processing for Large_Max_Size_Mutable
21225 if Is_Record_Type
(Typ
)
21226 and then not Is_Limited_View
(Typ
)
21227 and then Has_Defaulted_Discriminants
(Typ
)
21229 -- Loop through the components, looking for an array whose upper
21230 -- bound(s) depends on discriminants, where both the subtype of
21231 -- the discriminant and the index subtype are too large.
21237 Comp
:= First_Entity
(Typ
);
21238 while Present
(Comp
) loop
21239 if Ekind
(Comp
) = E_Component
then
21241 Comp_Type
: constant Entity_Id
:=
21242 Underlying_Type
(Etype
(Comp
));
21249 if Is_Array_Type
(Comp_Type
) then
21250 Indx
:= First_Index
(Comp_Type
);
21252 while Present
(Indx
) loop
21253 Ityp
:= Etype
(Indx
);
21254 Hi
:= Type_High_Bound
(Ityp
);
21256 if Nkind
(Hi
) = N_Identifier
21257 and then Ekind
(Entity
(Hi
)) = E_Discriminant
21258 and then Is_Large_Discrete_Type
(Ityp
)
21259 and then Is_Large_Discrete_Type
21260 (Etype
(Entity
(Hi
)))
21271 Next_Entity
(Comp
);
21277 end Large_Max_Size_Mutable
;
21279 -- Local declarations
21281 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
21283 -- Start of processing for New_Requires_Transient_Scope
21286 -- This is a private type which is not completed yet. This can only
21287 -- happen in a default expression (of a formal parameter or of a
21288 -- record component). Do not expand transient scope in this case.
21293 -- Do not expand transient scope for non-existent procedure return or
21294 -- string literal types.
21296 elsif Typ
= Standard_Void_Type
21297 or else Ekind
(Typ
) = E_String_Literal_Subtype
21301 -- If Typ is a generic formal incomplete type, then we want to look at
21302 -- the actual type.
21304 elsif Ekind
(Typ
) = E_Record_Subtype
21305 and then Present
(Cloned_Subtype
(Typ
))
21307 return New_Requires_Transient_Scope
(Cloned_Subtype
(Typ
));
21309 -- Functions returning specific tagged types may dispatch on result, so
21310 -- their returned value is allocated on the secondary stack, even in the
21311 -- definite case. We must treat nondispatching functions the same way,
21312 -- because access-to-function types can point at both, so the calling
21313 -- conventions must be compatible. Is_Tagged_Type includes controlled
21314 -- types and class-wide types. Controlled type temporaries need
21317 -- ???It's not clear why we need to return noncontrolled types with
21318 -- controlled components on the secondary stack.
21320 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
21323 -- Untagged definite subtypes are known size. This includes all
21324 -- elementary [sub]types. Tasks are known size even if they have
21325 -- discriminants. So we return False here, with one exception:
21326 -- For a type like:
21327 -- type T (Last : Natural := 0) is
21328 -- X : String (1 .. Last);
21330 -- we return True. That's because for "P(F(...));", where F returns T,
21331 -- we don't know the size of the result at the call site, so if we
21332 -- allocated it on the primary stack, we would have to allocate the
21333 -- maximum size, which is way too big.
21335 elsif Is_Definite_Subtype
(Typ
) or else Is_Task_Type
(Typ
) then
21336 return Large_Max_Size_Mutable
(Typ
);
21338 -- Indefinite (discriminated) untagged record or protected type
21340 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
21341 return not Caller_Known_Size_Record
(Typ
);
21343 -- Unconstrained array
21346 pragma Assert
(Is_Array_Type
(Typ
) and not Is_Definite_Subtype
(Typ
));
21349 end New_Requires_Transient_Scope
;
21351 --------------------------
21352 -- No_Heap_Finalization --
21353 --------------------------
21355 function No_Heap_Finalization
(Typ
: Entity_Id
) return Boolean is
21357 if Ekind_In
(Typ
, E_Access_Type
, E_General_Access_Type
)
21358 and then Is_Library_Level_Entity
(Typ
)
21360 -- A global No_Heap_Finalization pragma applies to all library-level
21361 -- named access-to-object types.
21363 if Present
(No_Heap_Finalization_Pragma
) then
21366 -- The library-level named access-to-object type itself is subject to
21367 -- pragma No_Heap_Finalization.
21369 elsif Present
(Get_Pragma
(Typ
, Pragma_No_Heap_Finalization
)) then
21375 end No_Heap_Finalization
;
21377 -----------------------
21378 -- Normalize_Actuals --
21379 -----------------------
21381 -- Chain actuals according to formals of subprogram. If there are no named
21382 -- associations, the chain is simply the list of Parameter Associations,
21383 -- since the order is the same as the declaration order. If there are named
21384 -- associations, then the First_Named_Actual field in the N_Function_Call
21385 -- or N_Procedure_Call_Statement node points to the Parameter_Association
21386 -- node for the parameter that comes first in declaration order. The
21387 -- remaining named parameters are then chained in declaration order using
21388 -- Next_Named_Actual.
21390 -- This routine also verifies that the number of actuals is compatible with
21391 -- the number and default values of formals, but performs no type checking
21392 -- (type checking is done by the caller).
21394 -- If the matching succeeds, Success is set to True and the caller proceeds
21395 -- with type-checking. If the match is unsuccessful, then Success is set to
21396 -- False, and the caller attempts a different interpretation, if there is
21399 -- If the flag Report is on, the call is not overloaded, and a failure to
21400 -- match can be reported here, rather than in the caller.
21402 procedure Normalize_Actuals
21406 Success
: out Boolean)
21408 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
21409 Actual
: Node_Id
:= Empty
;
21410 Formal
: Entity_Id
;
21411 Last
: Node_Id
:= Empty
;
21412 First_Named
: Node_Id
:= Empty
;
21415 Formals_To_Match
: Integer := 0;
21416 Actuals_To_Match
: Integer := 0;
21418 procedure Chain
(A
: Node_Id
);
21419 -- Add named actual at the proper place in the list, using the
21420 -- Next_Named_Actual link.
21422 function Reporting
return Boolean;
21423 -- Determines if an error is to be reported. To report an error, we
21424 -- need Report to be True, and also we do not report errors caused
21425 -- by calls to init procs that occur within other init procs. Such
21426 -- errors must always be cascaded errors, since if all the types are
21427 -- declared correctly, the compiler will certainly build decent calls.
21433 procedure Chain
(A
: Node_Id
) is
21437 -- Call node points to first actual in list
21439 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
21442 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
21446 Set_Next_Named_Actual
(Last
, Empty
);
21453 function Reporting
return Boolean is
21458 elsif not Within_Init_Proc
then
21461 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
21469 -- Start of processing for Normalize_Actuals
21472 if Is_Access_Type
(S
) then
21474 -- The name in the call is a function call that returns an access
21475 -- to subprogram. The designated type has the list of formals.
21477 Formal
:= First_Formal
(Designated_Type
(S
));
21479 Formal
:= First_Formal
(S
);
21482 while Present
(Formal
) loop
21483 Formals_To_Match
:= Formals_To_Match
+ 1;
21484 Next_Formal
(Formal
);
21487 -- Find if there is a named association, and verify that no positional
21488 -- associations appear after named ones.
21490 if Present
(Actuals
) then
21491 Actual
:= First
(Actuals
);
21494 while Present
(Actual
)
21495 and then Nkind
(Actual
) /= N_Parameter_Association
21497 Actuals_To_Match
:= Actuals_To_Match
+ 1;
21501 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
21503 -- Most common case: positional notation, no defaults
21508 elsif Actuals_To_Match
> Formals_To_Match
then
21510 -- Too many actuals: will not work
21513 if Is_Entity_Name
(Name
(N
)) then
21514 Error_Msg_N
("too many arguments in call to&", Name
(N
));
21516 Error_Msg_N
("too many arguments in call", N
);
21524 First_Named
:= Actual
;
21526 while Present
(Actual
) loop
21527 if Nkind
(Actual
) /= N_Parameter_Association
then
21529 ("positional parameters not allowed after named ones", Actual
);
21534 Actuals_To_Match
:= Actuals_To_Match
+ 1;
21540 if Present
(Actuals
) then
21541 Actual
:= First
(Actuals
);
21544 Formal
:= First_Formal
(S
);
21545 while Present
(Formal
) loop
21547 -- Match the formals in order. If the corresponding actual is
21548 -- positional, nothing to do. Else scan the list of named actuals
21549 -- to find the one with the right name.
21551 if Present
(Actual
)
21552 and then Nkind
(Actual
) /= N_Parameter_Association
21555 Actuals_To_Match
:= Actuals_To_Match
- 1;
21556 Formals_To_Match
:= Formals_To_Match
- 1;
21559 -- For named parameters, search the list of actuals to find
21560 -- one that matches the next formal name.
21562 Actual
:= First_Named
;
21564 while Present
(Actual
) loop
21565 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
21568 Actuals_To_Match
:= Actuals_To_Match
- 1;
21569 Formals_To_Match
:= Formals_To_Match
- 1;
21577 if Ekind
(Formal
) /= E_In_Parameter
21578 or else No
(Default_Value
(Formal
))
21581 if (Comes_From_Source
(S
)
21582 or else Sloc
(S
) = Standard_Location
)
21583 and then Is_Overloadable
(S
)
21587 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
21589 N_Parameter_Association
)
21590 and then Ekind
(S
) /= E_Function
21592 Set_Etype
(N
, Etype
(S
));
21595 Error_Msg_Name_1
:= Chars
(S
);
21596 Error_Msg_Sloc
:= Sloc
(S
);
21598 ("missing argument for parameter & "
21599 & "in call to % declared #", N
, Formal
);
21602 elsif Is_Overloadable
(S
) then
21603 Error_Msg_Name_1
:= Chars
(S
);
21605 -- Point to type derivation that generated the
21608 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
21611 ("missing argument for parameter & "
21612 & "in call to % (inherited) #", N
, Formal
);
21616 ("missing argument for parameter &", N
, Formal
);
21624 Formals_To_Match
:= Formals_To_Match
- 1;
21629 Next_Formal
(Formal
);
21632 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
21639 -- Find some superfluous named actual that did not get
21640 -- attached to the list of associations.
21642 Actual
:= First
(Actuals
);
21643 while Present
(Actual
) loop
21644 if Nkind
(Actual
) = N_Parameter_Association
21645 and then Actual
/= Last
21646 and then No
(Next_Named_Actual
(Actual
))
21648 -- A validity check may introduce a copy of a call that
21649 -- includes an extra actual (for example for an unrelated
21650 -- accessibility check). Check that the extra actual matches
21651 -- some extra formal, which must exist already because
21652 -- subprogram must be frozen at this point.
21654 if Present
(Extra_Formals
(S
))
21655 and then not Comes_From_Source
(Actual
)
21656 and then Nkind
(Actual
) = N_Parameter_Association
21657 and then Chars
(Extra_Formals
(S
)) =
21658 Chars
(Selector_Name
(Actual
))
21663 ("unmatched actual & in call", Selector_Name
(Actual
));
21675 end Normalize_Actuals
;
21677 --------------------------------
21678 -- Note_Possible_Modification --
21679 --------------------------------
21681 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
21682 Modification_Comes_From_Source
: constant Boolean :=
21683 Comes_From_Source
(Parent
(N
));
21689 -- Loop to find referenced entity, if there is one
21695 if Is_Entity_Name
(Exp
) then
21696 Ent
:= Entity
(Exp
);
21698 -- If the entity is missing, it is an undeclared identifier,
21699 -- and there is nothing to annotate.
21705 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
21707 P
: constant Node_Id
:= Prefix
(Exp
);
21710 -- In formal verification mode, keep track of all reads and
21711 -- writes through explicit dereferences.
21713 if GNATprove_Mode
then
21714 SPARK_Specific
.Generate_Dereference
(N
, 'm');
21717 if Nkind
(P
) = N_Selected_Component
21718 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
21720 -- Case of a reference to an entry formal
21722 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
21724 elsif Nkind
(P
) = N_Identifier
21725 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
21726 and then Present
(Expression
(Parent
(Entity
(P
))))
21727 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
21730 -- Case of a reference to a value on which side effects have
21733 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
21741 elsif Nkind_In
(Exp
, N_Type_Conversion
,
21742 N_Unchecked_Type_Conversion
)
21744 Exp
:= Expression
(Exp
);
21747 elsif Nkind_In
(Exp
, N_Slice
,
21748 N_Indexed_Component
,
21749 N_Selected_Component
)
21751 -- Special check, if the prefix is an access type, then return
21752 -- since we are modifying the thing pointed to, not the prefix.
21753 -- When we are expanding, most usually the prefix is replaced
21754 -- by an explicit dereference, and this test is not needed, but
21755 -- in some cases (notably -gnatc mode and generics) when we do
21756 -- not do full expansion, we need this special test.
21758 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
21761 -- Otherwise go to prefix and keep going
21764 Exp
:= Prefix
(Exp
);
21768 -- All other cases, not a modification
21774 -- Now look for entity being referenced
21776 if Present
(Ent
) then
21777 if Is_Object
(Ent
) then
21778 if Comes_From_Source
(Exp
)
21779 or else Modification_Comes_From_Source
21781 -- Give warning if pragma unmodified is given and we are
21782 -- sure this is a modification.
21784 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
21786 -- Note that the entity may be present only as a result
21787 -- of pragma Unused.
21789 if Has_Pragma_Unused
(Ent
) then
21790 Error_Msg_NE
("??pragma Unused given for &!", N
, Ent
);
21793 ("??pragma Unmodified given for &!", N
, Ent
);
21797 Set_Never_Set_In_Source
(Ent
, False);
21800 Set_Is_True_Constant
(Ent
, False);
21801 Set_Current_Value
(Ent
, Empty
);
21802 Set_Is_Known_Null
(Ent
, False);
21804 if not Can_Never_Be_Null
(Ent
) then
21805 Set_Is_Known_Non_Null
(Ent
, False);
21808 -- Follow renaming chain
21810 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
21811 and then Present
(Renamed_Object
(Ent
))
21813 Exp
:= Renamed_Object
(Ent
);
21815 -- If the entity is the loop variable in an iteration over
21816 -- a container, retrieve container expression to indicate
21817 -- possible modification.
21819 if Present
(Related_Expression
(Ent
))
21820 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
21821 N_Iterator_Specification
21823 Exp
:= Original_Node
(Related_Expression
(Ent
));
21828 -- The expression may be the renaming of a subcomponent of an
21829 -- array or container. The assignment to the subcomponent is
21830 -- a modification of the container.
21832 elsif Comes_From_Source
(Original_Node
(Exp
))
21833 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
21834 N_Indexed_Component
)
21836 Exp
:= Prefix
(Original_Node
(Exp
));
21840 -- Generate a reference only if the assignment comes from
21841 -- source. This excludes, for example, calls to a dispatching
21842 -- assignment operation when the left-hand side is tagged. In
21843 -- GNATprove mode, we need those references also on generated
21844 -- code, as these are used to compute the local effects of
21847 if Modification_Comes_From_Source
or GNATprove_Mode
then
21848 Generate_Reference
(Ent
, Exp
, 'm');
21850 -- If the target of the assignment is the bound variable
21851 -- in an iterator, indicate that the corresponding array
21852 -- or container is also modified.
21854 if Ada_Version
>= Ada_2012
21855 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
21858 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
21861 -- TBD : in the full version of the construct, the
21862 -- domain of iteration can be given by an expression.
21864 if Is_Entity_Name
(Domain
) then
21865 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
21866 Set_Is_True_Constant
(Entity
(Domain
), False);
21867 Set_Never_Set_In_Source
(Entity
(Domain
), False);
21876 -- If we are sure this is a modification from source, and we know
21877 -- this modifies a constant, then give an appropriate warning.
21880 and then Modification_Comes_From_Source
21881 and then Overlays_Constant
(Ent
)
21882 and then Address_Clause_Overlay_Warnings
21885 Addr
: constant Node_Id
:= Address_Clause
(Ent
);
21890 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
21892 Error_Msg_Sloc
:= Sloc
(Addr
);
21894 ("??constant& may be modified via address clause#",
21905 end Note_Possible_Modification
;
21911 function Null_Status
(N
: Node_Id
) return Null_Status_Kind
is
21912 function Is_Null_Excluding_Def
(Def
: Node_Id
) return Boolean;
21913 -- Determine whether definition Def carries a null exclusion
21915 function Null_Status_Of_Entity
(Id
: Entity_Id
) return Null_Status_Kind
;
21916 -- Determine the null status of arbitrary entity Id
21918 function Null_Status_Of_Type
(Typ
: Entity_Id
) return Null_Status_Kind
;
21919 -- Determine the null status of type Typ
21921 ---------------------------
21922 -- Is_Null_Excluding_Def --
21923 ---------------------------
21925 function Is_Null_Excluding_Def
(Def
: Node_Id
) return Boolean is
21928 Nkind_In
(Def
, N_Access_Definition
,
21929 N_Access_Function_Definition
,
21930 N_Access_Procedure_Definition
,
21931 N_Access_To_Object_Definition
,
21932 N_Component_Definition
,
21933 N_Derived_Type_Definition
)
21934 and then Null_Exclusion_Present
(Def
);
21935 end Is_Null_Excluding_Def
;
21937 ---------------------------
21938 -- Null_Status_Of_Entity --
21939 ---------------------------
21941 function Null_Status_Of_Entity
21942 (Id
: Entity_Id
) return Null_Status_Kind
21944 Decl
: constant Node_Id
:= Declaration_Node
(Id
);
21948 -- The value of an imported or exported entity may be set externally
21949 -- regardless of a null exclusion. As a result, the value cannot be
21950 -- determined statically.
21952 if Is_Imported
(Id
) or else Is_Exported
(Id
) then
21955 elsif Nkind_In
(Decl
, N_Component_Declaration
,
21956 N_Discriminant_Specification
,
21957 N_Formal_Object_Declaration
,
21958 N_Object_Declaration
,
21959 N_Object_Renaming_Declaration
,
21960 N_Parameter_Specification
)
21962 -- A component declaration yields a non-null value when either
21963 -- its component definition or access definition carries a null
21966 if Nkind
(Decl
) = N_Component_Declaration
then
21967 Def
:= Component_Definition
(Decl
);
21969 if Is_Null_Excluding_Def
(Def
) then
21970 return Is_Non_Null
;
21973 Def
:= Access_Definition
(Def
);
21975 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
21976 return Is_Non_Null
;
21979 -- A formal object declaration yields a non-null value if its
21980 -- access definition carries a null exclusion. If the object is
21981 -- default initialized, then the value depends on the expression.
21983 elsif Nkind
(Decl
) = N_Formal_Object_Declaration
then
21984 Def
:= Access_Definition
(Decl
);
21986 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
21987 return Is_Non_Null
;
21990 -- A constant may yield a null or non-null value depending on its
21991 -- initialization expression.
21993 elsif Ekind
(Id
) = E_Constant
then
21994 return Null_Status
(Constant_Value
(Id
));
21996 -- The construct yields a non-null value when it has a null
21999 elsif Null_Exclusion_Present
(Decl
) then
22000 return Is_Non_Null
;
22002 -- An object renaming declaration yields a non-null value if its
22003 -- access definition carries a null exclusion. Otherwise the value
22004 -- depends on the renamed name.
22006 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
22007 Def
:= Access_Definition
(Decl
);
22009 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
22010 return Is_Non_Null
;
22013 return Null_Status
(Name
(Decl
));
22018 -- At this point the declaration of the entity does not carry a null
22019 -- exclusion and lacks an initialization expression. Check the status
22022 return Null_Status_Of_Type
(Etype
(Id
));
22023 end Null_Status_Of_Entity
;
22025 -------------------------
22026 -- Null_Status_Of_Type --
22027 -------------------------
22029 function Null_Status_Of_Type
(Typ
: Entity_Id
) return Null_Status_Kind
is
22034 -- Traverse the type chain looking for types with null exclusion
22037 while Present
(Curr
) and then Etype
(Curr
) /= Curr
loop
22038 Decl
:= Parent
(Curr
);
22040 -- Guard against itypes which do not always have declarations. A
22041 -- type yields a non-null value if it carries a null exclusion.
22043 if Present
(Decl
) then
22044 if Nkind
(Decl
) = N_Full_Type_Declaration
22045 and then Is_Null_Excluding_Def
(Type_Definition
(Decl
))
22047 return Is_Non_Null
;
22049 elsif Nkind
(Decl
) = N_Subtype_Declaration
22050 and then Null_Exclusion_Present
(Decl
)
22052 return Is_Non_Null
;
22056 Curr
:= Etype
(Curr
);
22059 -- The type chain does not contain any null excluding types
22062 end Null_Status_Of_Type
;
22064 -- Start of processing for Null_Status
22067 -- An allocator always creates a non-null value
22069 if Nkind
(N
) = N_Allocator
then
22070 return Is_Non_Null
;
22072 -- Taking the 'Access of something yields a non-null value
22074 elsif Nkind
(N
) = N_Attribute_Reference
22075 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
22076 Name_Unchecked_Access
,
22077 Name_Unrestricted_Access
)
22079 return Is_Non_Null
;
22081 -- "null" yields null
22083 elsif Nkind
(N
) = N_Null
then
22086 -- Check the status of the operand of a type conversion
22088 elsif Nkind
(N
) = N_Type_Conversion
then
22089 return Null_Status
(Expression
(N
));
22091 -- The input denotes a reference to an entity. Determine whether the
22092 -- entity or its type yields a null or non-null value.
22094 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
22095 return Null_Status_Of_Entity
(Entity
(N
));
22098 -- Otherwise it is not possible to determine the null status of the
22099 -- subexpression at compile time without resorting to simple flow
22105 --------------------------------------
22106 -- Null_To_Null_Address_Convert_OK --
22107 --------------------------------------
22109 function Null_To_Null_Address_Convert_OK
22111 Typ
: Entity_Id
:= Empty
) return Boolean
22114 if not Relaxed_RM_Semantics
then
22118 if Nkind
(N
) = N_Null
then
22119 return Present
(Typ
) and then Is_Descendant_Of_Address
(Typ
);
22121 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
, N_Op_Ne
)
22124 L
: constant Node_Id
:= Left_Opnd
(N
);
22125 R
: constant Node_Id
:= Right_Opnd
(N
);
22128 -- We check the Etype of the complementary operand since the
22129 -- N_Null node is not decorated at this stage.
22132 ((Nkind
(L
) = N_Null
22133 and then Is_Descendant_Of_Address
(Etype
(R
)))
22135 (Nkind
(R
) = N_Null
22136 and then Is_Descendant_Of_Address
(Etype
(L
))));
22141 end Null_To_Null_Address_Convert_OK
;
22143 ---------------------------------
22144 -- Number_Of_Elements_In_Array --
22145 ---------------------------------
22147 function Number_Of_Elements_In_Array
(T
: Entity_Id
) return Int
is
22155 pragma Assert
(Is_Array_Type
(T
));
22157 Indx
:= First_Index
(T
);
22158 while Present
(Indx
) loop
22159 Typ
:= Underlying_Type
(Etype
(Indx
));
22161 -- Never look at junk bounds of a generic type
22163 if Is_Generic_Type
(Typ
) then
22167 -- Check the array bounds are known at compile time and return zero
22168 -- if they are not.
22170 Low
:= Type_Low_Bound
(Typ
);
22171 High
:= Type_High_Bound
(Typ
);
22173 if not Compile_Time_Known_Value
(Low
) then
22175 elsif not Compile_Time_Known_Value
(High
) then
22179 Num
* UI_To_Int
((Expr_Value
(High
) - Expr_Value
(Low
) + 1));
22186 end Number_Of_Elements_In_Array
;
22188 -------------------------
22189 -- Object_Access_Level --
22190 -------------------------
22192 -- Returns the static accessibility level of the view denoted by Obj. Note
22193 -- that the value returned is the result of a call to Scope_Depth. Only
22194 -- scope depths associated with dynamic scopes can actually be returned.
22195 -- Since only relative levels matter for accessibility checking, the fact
22196 -- that the distance between successive levels of accessibility is not
22197 -- always one is immaterial (invariant: if level(E2) is deeper than
22198 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
22200 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
22201 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
22202 -- Determine whether N is a construct of the form
22203 -- Some_Type (Operand._tag'Address)
22204 -- This construct appears in the context of dispatching calls.
22206 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
22207 -- An explicit dereference is created when removing side effects from
22208 -- expressions for constraint checking purposes. In this case a local
22209 -- access type is created for it. The correct access level is that of
22210 -- the original source node. We detect this case by noting that the
22211 -- prefix of the dereference is created by an object declaration whose
22212 -- initial expression is a reference.
22214 -----------------------------
22215 -- Is_Interface_Conversion --
22216 -----------------------------
22218 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
22220 return Nkind
(N
) = N_Unchecked_Type_Conversion
22221 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
22222 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
22223 end Is_Interface_Conversion
;
22229 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
22230 Pref
: constant Node_Id
:= Prefix
(Obj
);
22232 if Is_Entity_Name
(Pref
)
22233 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
22234 and then Present
(Expression
(Parent
(Entity
(Pref
))))
22235 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
22237 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
22247 -- Start of processing for Object_Access_Level
22250 if Nkind
(Obj
) = N_Defining_Identifier
22251 or else Is_Entity_Name
(Obj
)
22253 if Nkind
(Obj
) = N_Defining_Identifier
then
22259 if Is_Prival
(E
) then
22260 E
:= Prival_Link
(E
);
22263 -- If E is a type then it denotes a current instance. For this case
22264 -- we add one to the normal accessibility level of the type to ensure
22265 -- that current instances are treated as always being deeper than
22266 -- than the level of any visible named access type (see 3.10.2(21)).
22268 if Is_Type
(E
) then
22269 return Type_Access_Level
(E
) + 1;
22271 elsif Present
(Renamed_Object
(E
)) then
22272 return Object_Access_Level
(Renamed_Object
(E
));
22274 -- Similarly, if E is a component of the current instance of a
22275 -- protected type, any instance of it is assumed to be at a deeper
22276 -- level than the type. For a protected object (whose type is an
22277 -- anonymous protected type) its components are at the same level
22278 -- as the type itself.
22280 elsif not Is_Overloadable
(E
)
22281 and then Ekind
(Scope
(E
)) = E_Protected_Type
22282 and then Comes_From_Source
(Scope
(E
))
22284 return Type_Access_Level
(Scope
(E
)) + 1;
22287 -- Aliased formals of functions take their access level from the
22288 -- point of call, i.e. require a dynamic check. For static check
22289 -- purposes, this is smaller than the level of the subprogram
22290 -- itself. For procedures the aliased makes no difference.
22293 and then Is_Aliased
(E
)
22294 and then Ekind
(Scope
(E
)) = E_Function
22296 return Type_Access_Level
(Etype
(E
));
22299 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
22303 elsif Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
22304 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
22305 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
22307 return Object_Access_Level
(Prefix
(Obj
));
22310 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
22312 -- If the prefix is a selected access discriminant then we make a
22313 -- recursive call on the prefix, which will in turn check the level
22314 -- of the prefix object of the selected discriminant.
22316 -- In Ada 2012, if the discriminant has implicit dereference and
22317 -- the context is a selected component, treat this as an object of
22318 -- unknown scope (see below). This is necessary in compile-only mode;
22319 -- otherwise expansion will already have transformed the prefix into
22322 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
22323 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
22325 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
22327 (not Has_Implicit_Dereference
22328 (Entity
(Selector_Name
(Prefix
(Obj
))))
22329 or else Nkind
(Parent
(Obj
)) /= N_Selected_Component
)
22331 return Object_Access_Level
(Prefix
(Obj
));
22333 -- Detect an interface conversion in the context of a dispatching
22334 -- call. Use the original form of the conversion to find the access
22335 -- level of the operand.
22337 elsif Is_Interface
(Etype
(Obj
))
22338 and then Is_Interface_Conversion
(Prefix
(Obj
))
22339 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
22341 return Object_Access_Level
(Original_Node
(Obj
));
22343 elsif not Comes_From_Source
(Obj
) then
22345 Ref
: constant Node_Id
:= Reference_To
(Obj
);
22347 if Present
(Ref
) then
22348 return Object_Access_Level
(Ref
);
22350 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
22355 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
22358 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
22359 return Object_Access_Level
(Expression
(Obj
));
22361 elsif Nkind
(Obj
) = N_Function_Call
then
22363 -- Function results are objects, so we get either the access level of
22364 -- the function or, in the case of an indirect call, the level of the
22365 -- access-to-subprogram type. (This code is used for Ada 95, but it
22366 -- looks wrong, because it seems that we should be checking the level
22367 -- of the call itself, even for Ada 95. However, using the Ada 2005
22368 -- version of the code causes regressions in several tests that are
22369 -- compiled with -gnat95. ???)
22371 if Ada_Version
< Ada_2005
then
22372 if Is_Entity_Name
(Name
(Obj
)) then
22373 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
22375 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
22378 -- For Ada 2005, the level of the result object of a function call is
22379 -- defined to be the level of the call's innermost enclosing master.
22380 -- We determine that by querying the depth of the innermost enclosing
22384 Return_Master_Scope_Depth_Of_Call
: declare
22385 function Innermost_Master_Scope_Depth
22386 (N
: Node_Id
) return Uint
;
22387 -- Returns the scope depth of the given node's innermost
22388 -- enclosing dynamic scope (effectively the accessibility
22389 -- level of the innermost enclosing master).
22391 ----------------------------------
22392 -- Innermost_Master_Scope_Depth --
22393 ----------------------------------
22395 function Innermost_Master_Scope_Depth
22396 (N
: Node_Id
) return Uint
22398 Node_Par
: Node_Id
:= Parent
(N
);
22401 -- Locate the nearest enclosing node (by traversing Parents)
22402 -- that Defining_Entity can be applied to, and return the
22403 -- depth of that entity's nearest enclosing dynamic scope.
22405 while Present
(Node_Par
) loop
22406 case Nkind
(Node_Par
) is
22407 when N_Abstract_Subprogram_Declaration
22408 | N_Block_Statement
22410 | N_Component_Declaration
22412 | N_Entry_Declaration
22413 | N_Exception_Declaration
22414 | N_Formal_Object_Declaration
22415 | N_Formal_Package_Declaration
22416 | N_Formal_Subprogram_Declaration
22417 | N_Formal_Type_Declaration
22418 | N_Full_Type_Declaration
22419 | N_Function_Specification
22420 | N_Generic_Declaration
22421 | N_Generic_Instantiation
22422 | N_Implicit_Label_Declaration
22423 | N_Incomplete_Type_Declaration
22424 | N_Loop_Parameter_Specification
22425 | N_Number_Declaration
22426 | N_Object_Declaration
22427 | N_Package_Declaration
22428 | N_Package_Specification
22429 | N_Parameter_Specification
22430 | N_Private_Extension_Declaration
22431 | N_Private_Type_Declaration
22432 | N_Procedure_Specification
22434 | N_Protected_Type_Declaration
22435 | N_Renaming_Declaration
22436 | N_Single_Protected_Declaration
22437 | N_Single_Task_Declaration
22438 | N_Subprogram_Declaration
22439 | N_Subtype_Declaration
22441 | N_Task_Type_Declaration
22444 (Nearest_Dynamic_Scope
22445 (Defining_Entity
(Node_Par
)));
22447 -- For a return statement within a function, return
22448 -- the depth of the function itself. This is not just
22449 -- a small optimization, but matters when analyzing
22450 -- the expression in an expression function before
22451 -- the body is created.
22453 when N_Simple_Return_Statement
=>
22454 if Ekind
(Current_Scope
) = E_Function
then
22455 return Scope_Depth
(Current_Scope
);
22462 Node_Par
:= Parent
(Node_Par
);
22465 pragma Assert
(False);
22467 -- Should never reach the following return
22469 return Scope_Depth
(Current_Scope
) + 1;
22470 end Innermost_Master_Scope_Depth
;
22472 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22475 return Innermost_Master_Scope_Depth
(Obj
);
22476 end Return_Master_Scope_Depth_Of_Call
;
22479 -- For convenience we handle qualified expressions, even though they
22480 -- aren't technically object names.
22482 elsif Nkind
(Obj
) = N_Qualified_Expression
then
22483 return Object_Access_Level
(Expression
(Obj
));
22485 -- Ditto for aggregates. They have the level of the temporary that
22486 -- will hold their value.
22488 elsif Nkind
(Obj
) = N_Aggregate
then
22489 return Object_Access_Level
(Current_Scope
);
22491 -- Otherwise return the scope level of Standard. (If there are cases
22492 -- that fall through to this point they will be treated as having
22493 -- global accessibility for now. ???)
22496 return Scope_Depth
(Standard_Standard
);
22498 end Object_Access_Level
;
22500 ----------------------------------
22501 -- Old_Requires_Transient_Scope --
22502 ----------------------------------
22504 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
22505 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
22508 -- This is a private type which is not completed yet. This can only
22509 -- happen in a default expression (of a formal parameter or of a
22510 -- record component). Do not expand transient scope in this case.
22515 -- Do not expand transient scope for non-existent procedure return
22517 elsif Typ
= Standard_Void_Type
then
22520 -- Elementary types do not require a transient scope
22522 elsif Is_Elementary_Type
(Typ
) then
22525 -- Generally, indefinite subtypes require a transient scope, since the
22526 -- back end cannot generate temporaries, since this is not a valid type
22527 -- for declaring an object. It might be possible to relax this in the
22528 -- future, e.g. by declaring the maximum possible space for the type.
22530 elsif not Is_Definite_Subtype
(Typ
) then
22533 -- Functions returning tagged types may dispatch on result so their
22534 -- returned value is allocated on the secondary stack. Controlled
22535 -- type temporaries need finalization.
22537 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
22542 elsif Is_Record_Type
(Typ
) then
22547 Comp
:= First_Entity
(Typ
);
22548 while Present
(Comp
) loop
22549 if Ekind
(Comp
) = E_Component
then
22551 -- ???It's not clear we need a full recursive call to
22552 -- Old_Requires_Transient_Scope here. Note that the
22553 -- following can't happen.
22555 pragma Assert
(Is_Definite_Subtype
(Etype
(Comp
)));
22556 pragma Assert
(not Has_Controlled_Component
(Etype
(Comp
)));
22558 if Old_Requires_Transient_Scope
(Etype
(Comp
)) then
22563 Next_Entity
(Comp
);
22569 -- String literal types never require transient scope
22571 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
22574 -- Array type. Note that we already know that this is a constrained
22575 -- array, since unconstrained arrays will fail the indefinite test.
22577 elsif Is_Array_Type
(Typ
) then
22579 -- If component type requires a transient scope, the array does too
22581 if Old_Requires_Transient_Scope
(Component_Type
(Typ
)) then
22584 -- Otherwise, we only need a transient scope if the size depends on
22585 -- the value of one or more discriminants.
22588 return Size_Depends_On_Discriminant
(Typ
);
22591 -- All other cases do not require a transient scope
22594 pragma Assert
(Is_Protected_Type
(Typ
) or else Is_Task_Type
(Typ
));
22597 end Old_Requires_Transient_Scope
;
22599 ---------------------------------
22600 -- Original_Aspect_Pragma_Name --
22601 ---------------------------------
22603 function Original_Aspect_Pragma_Name
(N
: Node_Id
) return Name_Id
is
22605 Item_Nam
: Name_Id
;
22608 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
22612 -- The pragma was generated to emulate an aspect, use the original
22613 -- aspect specification.
22615 if Nkind
(Item
) = N_Pragma
and then From_Aspect_Specification
(Item
) then
22616 Item
:= Corresponding_Aspect
(Item
);
22619 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
22620 -- Post and Post_Class rewrite their pragma identifier to preserve the
22622 -- ??? this is kludgey
22624 if Nkind
(Item
) = N_Pragma
then
22625 Item_Nam
:= Chars
(Original_Node
(Pragma_Identifier
(Item
)));
22628 pragma Assert
(Nkind
(Item
) = N_Aspect_Specification
);
22629 Item_Nam
:= Chars
(Identifier
(Item
));
22632 -- Deal with 'Class by converting the name to its _XXX form
22634 if Class_Present
(Item
) then
22635 if Item_Nam
= Name_Invariant
then
22636 Item_Nam
:= Name_uInvariant
;
22638 elsif Item_Nam
= Name_Post
then
22639 Item_Nam
:= Name_uPost
;
22641 elsif Item_Nam
= Name_Pre
then
22642 Item_Nam
:= Name_uPre
;
22644 elsif Nam_In
(Item_Nam
, Name_Type_Invariant
,
22645 Name_Type_Invariant_Class
)
22647 Item_Nam
:= Name_uType_Invariant
;
22649 -- Nothing to do for other cases (e.g. a Check that derived from
22650 -- Pre_Class and has the flag set). Also we do nothing if the name
22651 -- is already in special _xxx form.
22657 end Original_Aspect_Pragma_Name
;
22659 --------------------------------------
22660 -- Original_Corresponding_Operation --
22661 --------------------------------------
22663 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
22665 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
22668 -- If S is an inherited primitive S2 the original corresponding
22669 -- operation of S is the original corresponding operation of S2
22671 if Present
(Alias
(S
))
22672 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
22674 return Original_Corresponding_Operation
(Alias
(S
));
22676 -- If S overrides an inherited subprogram S2 the original corresponding
22677 -- operation of S is the original corresponding operation of S2
22679 elsif Present
(Overridden_Operation
(S
)) then
22680 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
22682 -- otherwise it is S itself
22687 end Original_Corresponding_Operation
;
22689 -------------------
22690 -- Output_Entity --
22691 -------------------
22693 procedure Output_Entity
(Id
: Entity_Id
) is
22697 Scop
:= Scope
(Id
);
22699 -- The entity may lack a scope when it is in the process of being
22700 -- analyzed. Use the current scope as an approximation.
22703 Scop
:= Current_Scope
;
22706 Output_Name
(Chars
(Id
), Scop
);
22713 procedure Output_Name
(Nam
: Name_Id
; Scop
: Entity_Id
:= Current_Scope
) is
22717 (Get_Qualified_Name
22724 ----------------------
22725 -- Policy_In_Effect --
22726 ----------------------
22728 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
22729 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
22730 -- Determine the mode of a policy in a N_Pragma list
22732 --------------------
22733 -- Policy_In_List --
22734 --------------------
22736 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
22743 while Present
(Prag
) loop
22744 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
22745 Arg2
:= Next
(Arg1
);
22747 Arg1
:= Get_Pragma_Arg
(Arg1
);
22748 Arg2
:= Get_Pragma_Arg
(Arg2
);
22750 -- The current Check_Policy pragma matches the requested policy or
22751 -- appears in the single argument form (Assertion, policy_id).
22753 if Nam_In
(Chars
(Arg1
), Name_Assertion
, Policy
) then
22754 return Chars
(Arg2
);
22757 Prag
:= Next_Pragma
(Prag
);
22761 end Policy_In_List
;
22767 -- Start of processing for Policy_In_Effect
22770 if not Is_Valid_Assertion_Kind
(Policy
) then
22771 raise Program_Error
;
22774 -- Inspect all policy pragmas that appear within scopes (if any)
22776 Kind
:= Policy_In_List
(Check_Policy_List
);
22778 -- Inspect all configuration policy pragmas (if any)
22780 if Kind
= No_Name
then
22781 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
22784 -- The context lacks policy pragmas, determine the mode based on whether
22785 -- assertions are enabled at the configuration level. This ensures that
22786 -- the policy is preserved when analyzing generics.
22788 if Kind
= No_Name
then
22789 if Assertions_Enabled_Config
then
22790 Kind
:= Name_Check
;
22792 Kind
:= Name_Ignore
;
22796 -- In CodePeer mode and GNATprove mode, we need to consider all
22797 -- assertions, unless they are disabled. Force Name_Check on
22798 -- ignored assertions.
22800 if Nam_In
(Kind
, Name_Ignore
, Name_Off
)
22801 and then (CodePeer_Mode
or GNATprove_Mode
)
22803 Kind
:= Name_Check
;
22807 end Policy_In_Effect
;
22809 ----------------------------------
22810 -- Predicate_Tests_On_Arguments --
22811 ----------------------------------
22813 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
22815 -- Always test predicates on indirect call
22817 if Ekind
(Subp
) = E_Subprogram_Type
then
22820 -- Do not test predicates on call to generated default Finalize, since
22821 -- we are not interested in whether something we are finalizing (and
22822 -- typically destroying) satisfies its predicates.
22824 elsif Chars
(Subp
) = Name_Finalize
22825 and then not Comes_From_Source
(Subp
)
22829 -- Do not test predicates on any internally generated routines
22831 elsif Is_Internal_Name
(Chars
(Subp
)) then
22834 -- Do not test predicates on call to Init_Proc, since if needed the
22835 -- predicate test will occur at some other point.
22837 elsif Is_Init_Proc
(Subp
) then
22840 -- Do not test predicates on call to predicate function, since this
22841 -- would cause infinite recursion.
22843 elsif Ekind
(Subp
) = E_Function
22844 and then (Is_Predicate_Function
(Subp
)
22846 Is_Predicate_Function_M
(Subp
))
22850 -- For now, no other exceptions
22855 end Predicate_Tests_On_Arguments
;
22857 -----------------------
22858 -- Private_Component --
22859 -----------------------
22861 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
22862 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
22864 function Trace_Components
22866 Check
: Boolean) return Entity_Id
;
22867 -- Recursive function that does the work, and checks against circular
22868 -- definition for each subcomponent type.
22870 ----------------------
22871 -- Trace_Components --
22872 ----------------------
22874 function Trace_Components
22876 Check
: Boolean) return Entity_Id
22878 Btype
: constant Entity_Id
:= Base_Type
(T
);
22879 Component
: Entity_Id
;
22881 Candidate
: Entity_Id
:= Empty
;
22884 if Check
and then Btype
= Ancestor
then
22885 Error_Msg_N
("circular type definition", Type_Id
);
22889 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
22890 if Present
(Full_View
(Btype
))
22891 and then Is_Record_Type
(Full_View
(Btype
))
22892 and then not Is_Frozen
(Btype
)
22894 -- To indicate that the ancestor depends on a private type, the
22895 -- current Btype is sufficient. However, to check for circular
22896 -- definition we must recurse on the full view.
22898 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
22900 if Candidate
= Any_Type
then
22910 elsif Is_Array_Type
(Btype
) then
22911 return Trace_Components
(Component_Type
(Btype
), True);
22913 elsif Is_Record_Type
(Btype
) then
22914 Component
:= First_Entity
(Btype
);
22915 while Present
(Component
)
22916 and then Comes_From_Source
(Component
)
22918 -- Skip anonymous types generated by constrained components
22920 if not Is_Type
(Component
) then
22921 P
:= Trace_Components
(Etype
(Component
), True);
22923 if Present
(P
) then
22924 if P
= Any_Type
then
22932 Next_Entity
(Component
);
22940 end Trace_Components
;
22942 -- Start of processing for Private_Component
22945 return Trace_Components
(Type_Id
, False);
22946 end Private_Component
;
22948 ---------------------------
22949 -- Primitive_Names_Match --
22950 ---------------------------
22952 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
22953 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
22954 -- Given an internal name, returns the corresponding non-internal name
22956 ------------------------
22957 -- Non_Internal_Name --
22958 ------------------------
22960 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
22962 Get_Name_String
(Chars
(E
));
22963 Name_Len
:= Name_Len
- 1;
22965 end Non_Internal_Name
;
22967 -- Start of processing for Primitive_Names_Match
22970 pragma Assert
(Present
(E1
) and then Present
(E2
));
22972 return Chars
(E1
) = Chars
(E2
)
22974 (not Is_Internal_Name
(Chars
(E1
))
22975 and then Is_Internal_Name
(Chars
(E2
))
22976 and then Non_Internal_Name
(E2
) = Chars
(E1
))
22978 (not Is_Internal_Name
(Chars
(E2
))
22979 and then Is_Internal_Name
(Chars
(E1
))
22980 and then Non_Internal_Name
(E1
) = Chars
(E2
))
22982 (Is_Predefined_Dispatching_Operation
(E1
)
22983 and then Is_Predefined_Dispatching_Operation
(E2
)
22984 and then Same_TSS
(E1
, E2
))
22986 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
22987 end Primitive_Names_Match
;
22989 -----------------------
22990 -- Process_End_Label --
22991 -----------------------
22993 procedure Process_End_Label
23002 Label_Ref
: Boolean;
23003 -- Set True if reference to end label itself is required
23006 -- Gets set to the operator symbol or identifier that references the
23007 -- entity Ent. For the child unit case, this is the identifier from the
23008 -- designator. For other cases, this is simply Endl.
23010 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
23011 -- N is an identifier node that appears as a parent unit reference in
23012 -- the case where Ent is a child unit. This procedure generates an
23013 -- appropriate cross-reference entry. E is the corresponding entity.
23015 -------------------------
23016 -- Generate_Parent_Ref --
23017 -------------------------
23019 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
23021 -- If names do not match, something weird, skip reference
23023 if Chars
(E
) = Chars
(N
) then
23025 -- Generate the reference. We do NOT consider this as a reference
23026 -- for unreferenced symbol purposes.
23028 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
23030 if Style_Check
then
23031 Style
.Check_Identifier
(N
, E
);
23034 end Generate_Parent_Ref
;
23036 -- Start of processing for Process_End_Label
23039 -- If no node, ignore. This happens in some error situations, and
23040 -- also for some internally generated structures where no end label
23041 -- references are required in any case.
23047 -- Nothing to do if no End_Label, happens for internally generated
23048 -- constructs where we don't want an end label reference anyway. Also
23049 -- nothing to do if Endl is a string literal, which means there was
23050 -- some prior error (bad operator symbol)
23052 Endl
:= End_Label
(N
);
23054 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
23058 -- Reference node is not in extended main source unit
23060 if not In_Extended_Main_Source_Unit
(N
) then
23062 -- Generally we do not collect references except for the extended
23063 -- main source unit. The one exception is the 'e' entry for a
23064 -- package spec, where it is useful for a client to have the
23065 -- ending information to define scopes.
23071 Label_Ref
:= False;
23073 -- For this case, we can ignore any parent references, but we
23074 -- need the package name itself for the 'e' entry.
23076 if Nkind
(Endl
) = N_Designator
then
23077 Endl
:= Identifier
(Endl
);
23081 -- Reference is in extended main source unit
23086 -- For designator, generate references for the parent entries
23088 if Nkind
(Endl
) = N_Designator
then
23090 -- Generate references for the prefix if the END line comes from
23091 -- source (otherwise we do not need these references) We climb the
23092 -- scope stack to find the expected entities.
23094 if Comes_From_Source
(Endl
) then
23095 Nam
:= Name
(Endl
);
23096 Scop
:= Current_Scope
;
23097 while Nkind
(Nam
) = N_Selected_Component
loop
23098 Scop
:= Scope
(Scop
);
23099 exit when No
(Scop
);
23100 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
23101 Nam
:= Prefix
(Nam
);
23104 if Present
(Scop
) then
23105 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
23109 Endl
:= Identifier
(Endl
);
23113 -- If the end label is not for the given entity, then either we have
23114 -- some previous error, or this is a generic instantiation for which
23115 -- we do not need to make a cross-reference in this case anyway. In
23116 -- either case we simply ignore the call.
23118 if Chars
(Ent
) /= Chars
(Endl
) then
23122 -- If label was really there, then generate a normal reference and then
23123 -- adjust the location in the end label to point past the name (which
23124 -- should almost always be the semicolon).
23126 Loc
:= Sloc
(Endl
);
23128 if Comes_From_Source
(Endl
) then
23130 -- If a label reference is required, then do the style check and
23131 -- generate an l-type cross-reference entry for the label
23134 if Style_Check
then
23135 Style
.Check_Identifier
(Endl
, Ent
);
23138 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
23141 -- Set the location to point past the label (normally this will
23142 -- mean the semicolon immediately following the label). This is
23143 -- done for the sake of the 'e' or 't' entry generated below.
23145 Get_Decoded_Name_String
(Chars
(Endl
));
23146 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
23149 -- In SPARK mode, no missing label is allowed for packages and
23150 -- subprogram bodies. Detect those cases by testing whether
23151 -- Process_End_Label was called for a body (Typ = 't') or a package.
23153 if Restriction_Check_Required
(SPARK_05
)
23154 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
23156 Error_Msg_Node_1
:= Endl
;
23157 Check_SPARK_05_Restriction
23158 ("`END &` required", Endl
, Force
=> True);
23162 -- Now generate the e/t reference
23164 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
23166 -- Restore Sloc, in case modified above, since we have an identifier
23167 -- and the normal Sloc should be left set in the tree.
23169 Set_Sloc
(Endl
, Loc
);
23170 end Process_End_Label
;
23172 --------------------------------
23173 -- Propagate_Concurrent_Flags --
23174 --------------------------------
23176 procedure Propagate_Concurrent_Flags
23178 Comp_Typ
: Entity_Id
)
23181 if Has_Task
(Comp_Typ
) then
23182 Set_Has_Task
(Typ
);
23185 if Has_Protected
(Comp_Typ
) then
23186 Set_Has_Protected
(Typ
);
23189 if Has_Timing_Event
(Comp_Typ
) then
23190 Set_Has_Timing_Event
(Typ
);
23192 end Propagate_Concurrent_Flags
;
23194 ------------------------------
23195 -- Propagate_DIC_Attributes --
23196 ------------------------------
23198 procedure Propagate_DIC_Attributes
23200 From_Typ
: Entity_Id
)
23202 DIC_Proc
: Entity_Id
;
23205 if Present
(Typ
) and then Present
(From_Typ
) then
23206 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
23208 -- Nothing to do if both the source and the destination denote the
23211 if From_Typ
= Typ
then
23215 DIC_Proc
:= DIC_Procedure
(From_Typ
);
23217 -- The setting of the attributes is intentionally conservative. This
23218 -- prevents accidental clobbering of enabled attributes.
23220 if Has_Inherited_DIC
(From_Typ
)
23221 and then not Has_Inherited_DIC
(Typ
)
23223 Set_Has_Inherited_DIC
(Typ
);
23226 if Has_Own_DIC
(From_Typ
) and then not Has_Own_DIC
(Typ
) then
23227 Set_Has_Own_DIC
(Typ
);
23230 if Present
(DIC_Proc
) and then No
(DIC_Procedure
(Typ
)) then
23231 Set_DIC_Procedure
(Typ
, DIC_Proc
);
23234 end Propagate_DIC_Attributes
;
23236 ------------------------------------
23237 -- Propagate_Invariant_Attributes --
23238 ------------------------------------
23240 procedure Propagate_Invariant_Attributes
23242 From_Typ
: Entity_Id
)
23244 Full_IP
: Entity_Id
;
23245 Part_IP
: Entity_Id
;
23248 if Present
(Typ
) and then Present
(From_Typ
) then
23249 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
23251 -- Nothing to do if both the source and the destination denote the
23254 if From_Typ
= Typ
then
23258 Full_IP
:= Invariant_Procedure
(From_Typ
);
23259 Part_IP
:= Partial_Invariant_Procedure
(From_Typ
);
23261 -- The setting of the attributes is intentionally conservative. This
23262 -- prevents accidental clobbering of enabled attributes.
23264 if Has_Inheritable_Invariants
(From_Typ
)
23265 and then not Has_Inheritable_Invariants
(Typ
)
23267 Set_Has_Inheritable_Invariants
(Typ
);
23270 if Has_Inherited_Invariants
(From_Typ
)
23271 and then not Has_Inherited_Invariants
(Typ
)
23273 Set_Has_Inherited_Invariants
(Typ
);
23276 if Has_Own_Invariants
(From_Typ
)
23277 and then not Has_Own_Invariants
(Typ
)
23279 Set_Has_Own_Invariants
(Typ
);
23282 if Present
(Full_IP
) and then No
(Invariant_Procedure
(Typ
)) then
23283 Set_Invariant_Procedure
(Typ
, Full_IP
);
23286 if Present
(Part_IP
) and then No
(Partial_Invariant_Procedure
(Typ
))
23288 Set_Partial_Invariant_Procedure
(Typ
, Part_IP
);
23291 end Propagate_Invariant_Attributes
;
23293 ---------------------------------------
23294 -- Record_Possible_Part_Of_Reference --
23295 ---------------------------------------
23297 procedure Record_Possible_Part_Of_Reference
23298 (Var_Id
: Entity_Id
;
23301 Encap
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
23305 -- The variable is a constituent of a single protected/task type. Such
23306 -- a variable acts as a component of the type and must appear within a
23307 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
23308 -- verify its legality now.
23310 if Present
(Encap
) and then Is_Single_Concurrent_Object
(Encap
) then
23311 Check_Part_Of_Reference
(Var_Id
, Ref
);
23313 -- The variable is subject to pragma Part_Of and may eventually become a
23314 -- constituent of a single protected/task type. Record the reference to
23315 -- verify its placement when the contract of the variable is analyzed.
23317 elsif Present
(Get_Pragma
(Var_Id
, Pragma_Part_Of
)) then
23318 Refs
:= Part_Of_References
(Var_Id
);
23321 Refs
:= New_Elmt_List
;
23322 Set_Part_Of_References
(Var_Id
, Refs
);
23325 Append_Elmt
(Ref
, Refs
);
23327 end Record_Possible_Part_Of_Reference
;
23333 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
23334 Seen
: Boolean := False;
23336 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
23337 -- Determine whether node N denotes a reference to Id. If this is the
23338 -- case, set global flag Seen to True and stop the traversal.
23344 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
23346 if Is_Entity_Name
(N
)
23347 and then Present
(Entity
(N
))
23348 and then Entity
(N
) = Id
23357 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
23359 -- Start of processing for Referenced
23362 Inspect_Expression
(Expr
);
23366 ------------------------------------
23367 -- References_Generic_Formal_Type --
23368 ------------------------------------
23370 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
23372 function Process
(N
: Node_Id
) return Traverse_Result
;
23373 -- Process one node in search for generic formal type
23379 function Process
(N
: Node_Id
) return Traverse_Result
is
23381 if Nkind
(N
) in N_Has_Entity
then
23383 E
: constant Entity_Id
:= Entity
(N
);
23385 if Present
(E
) then
23386 if Is_Generic_Type
(E
) then
23388 elsif Present
(Etype
(E
))
23389 and then Is_Generic_Type
(Etype
(E
))
23400 function Traverse
is new Traverse_Func
(Process
);
23401 -- Traverse tree to look for generic type
23404 if Inside_A_Generic
then
23405 return Traverse
(N
) = Abandon
;
23409 end References_Generic_Formal_Type
;
23411 -------------------------------
23412 -- Remove_Entity_And_Homonym --
23413 -------------------------------
23415 procedure Remove_Entity_And_Homonym
(Id
: Entity_Id
) is
23417 Remove_Entity
(Id
);
23418 Remove_Homonym
(Id
);
23419 end Remove_Entity_And_Homonym
;
23421 --------------------
23422 -- Remove_Homonym --
23423 --------------------
23425 procedure Remove_Homonym
(Id
: Entity_Id
) is
23427 Prev
: Entity_Id
:= Empty
;
23430 if Id
= Current_Entity
(Id
) then
23431 if Present
(Homonym
(Id
)) then
23432 Set_Current_Entity
(Homonym
(Id
));
23434 Set_Name_Entity_Id
(Chars
(Id
), Empty
);
23438 Hom
:= Current_Entity
(Id
);
23439 while Present
(Hom
) and then Hom
/= Id
loop
23441 Hom
:= Homonym
(Hom
);
23444 -- If Id is not on the homonym chain, nothing to do
23446 if Present
(Hom
) then
23447 Set_Homonym
(Prev
, Homonym
(Id
));
23450 end Remove_Homonym
;
23452 ------------------------------
23453 -- Remove_Overloaded_Entity --
23454 ------------------------------
23456 procedure Remove_Overloaded_Entity
(Id
: Entity_Id
) is
23457 procedure Remove_Primitive_Of
(Typ
: Entity_Id
);
23458 -- Remove primitive subprogram Id from the list of primitives that
23459 -- belong to type Typ.
23461 -------------------------
23462 -- Remove_Primitive_Of --
23463 -------------------------
23465 procedure Remove_Primitive_Of
(Typ
: Entity_Id
) is
23469 if Is_Tagged_Type
(Typ
) then
23470 Prims
:= Direct_Primitive_Operations
(Typ
);
23472 if Present
(Prims
) then
23473 Remove
(Prims
, Id
);
23476 end Remove_Primitive_Of
;
23480 Formal
: Entity_Id
;
23482 -- Start of processing for Remove_Overloaded_Entity
23485 Remove_Entity_And_Homonym
(Id
);
23487 -- The entity denotes a primitive subprogram. Remove it from the list of
23488 -- primitives of the associated controlling type.
23490 if Ekind_In
(Id
, E_Function
, E_Procedure
) and then Is_Primitive
(Id
) then
23491 Formal
:= First_Formal
(Id
);
23492 while Present
(Formal
) loop
23493 if Is_Controlling_Formal
(Formal
) then
23494 Remove_Primitive_Of
(Etype
(Formal
));
23498 Next_Formal
(Formal
);
23501 if Ekind
(Id
) = E_Function
and then Has_Controlling_Result
(Id
) then
23502 Remove_Primitive_Of
(Etype
(Id
));
23505 end Remove_Overloaded_Entity
;
23507 ---------------------
23508 -- Rep_To_Pos_Flag --
23509 ---------------------
23511 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
23513 return New_Occurrence_Of
23514 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
23515 end Rep_To_Pos_Flag
;
23517 --------------------
23518 -- Require_Entity --
23519 --------------------
23521 procedure Require_Entity
(N
: Node_Id
) is
23523 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
23524 if Total_Errors_Detected
/= 0 then
23525 Set_Entity
(N
, Any_Id
);
23527 raise Program_Error
;
23530 end Require_Entity
;
23532 ------------------------------
23533 -- Requires_Transient_Scope --
23534 ------------------------------
23536 -- A transient scope is required when variable-sized temporaries are
23537 -- allocated on the secondary stack, or when finalization actions must be
23538 -- generated before the next instruction.
23540 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
23541 Old_Result
: constant Boolean := Old_Requires_Transient_Scope
(Id
);
23544 if Debug_Flag_QQ
then
23549 New_Result
: constant Boolean := New_Requires_Transient_Scope
(Id
);
23552 -- Assert that we're not putting things on the secondary stack if we
23553 -- didn't before; we are trying to AVOID secondary stack when
23556 if not Old_Result
then
23557 pragma Assert
(not New_Result
);
23561 if New_Result
/= Old_Result
then
23562 Results_Differ
(Id
, Old_Result
, New_Result
);
23567 end Requires_Transient_Scope
;
23569 --------------------
23570 -- Results_Differ --
23571 --------------------
23573 procedure Results_Differ
23579 if False then -- False to disable; True for debugging
23580 Treepr
.Print_Tree_Node
(Id
);
23582 if Old_Val
= New_Val
then
23583 raise Program_Error
;
23586 end Results_Differ
;
23588 --------------------------
23589 -- Reset_Analyzed_Flags --
23590 --------------------------
23592 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
23593 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
23594 -- Function used to reset Analyzed flags in tree. Note that we do
23595 -- not reset Analyzed flags in entities, since there is no need to
23596 -- reanalyze entities, and indeed, it is wrong to do so, since it
23597 -- can result in generating auxiliary stuff more than once.
23599 --------------------
23600 -- Clear_Analyzed --
23601 --------------------
23603 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
23605 if Nkind
(N
) not in N_Entity
then
23606 Set_Analyzed
(N
, False);
23610 end Clear_Analyzed
;
23612 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
23614 -- Start of processing for Reset_Analyzed_Flags
23617 Reset_Analyzed
(N
);
23618 end Reset_Analyzed_Flags
;
23620 ------------------------
23621 -- Restore_SPARK_Mode --
23622 ------------------------
23624 procedure Restore_SPARK_Mode
23625 (Mode
: SPARK_Mode_Type
;
23629 SPARK_Mode
:= Mode
;
23630 SPARK_Mode_Pragma
:= Prag
;
23631 end Restore_SPARK_Mode
;
23633 --------------------------------
23634 -- Returns_Unconstrained_Type --
23635 --------------------------------
23637 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
23639 return Ekind
(Subp
) = E_Function
23640 and then not Is_Scalar_Type
(Etype
(Subp
))
23641 and then not Is_Access_Type
(Etype
(Subp
))
23642 and then not Is_Constrained
(Etype
(Subp
));
23643 end Returns_Unconstrained_Type
;
23645 ----------------------------
23646 -- Root_Type_Of_Full_View --
23647 ----------------------------
23649 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
23650 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
23653 -- The root type of the full view may itself be a private type. Keep
23654 -- looking for the ultimate derivation parent.
23656 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
23657 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
23661 end Root_Type_Of_Full_View
;
23663 ---------------------------
23664 -- Safe_To_Capture_Value --
23665 ---------------------------
23667 function Safe_To_Capture_Value
23670 Cond
: Boolean := False) return Boolean
23673 -- The only entities for which we track constant values are variables
23674 -- which are not renamings, constants, out parameters, and in out
23675 -- parameters, so check if we have this case.
23677 -- Note: it may seem odd to track constant values for constants, but in
23678 -- fact this routine is used for other purposes than simply capturing
23679 -- the value. In particular, the setting of Known[_Non]_Null.
23681 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
23683 Ekind_In
(Ent
, E_Constant
, E_Out_Parameter
, E_In_Out_Parameter
)
23687 -- For conditionals, we also allow loop parameters and all formals,
23688 -- including in parameters.
23690 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
23693 -- For all other cases, not just unsafe, but impossible to capture
23694 -- Current_Value, since the above are the only entities which have
23695 -- Current_Value fields.
23701 -- Skip if volatile or aliased, since funny things might be going on in
23702 -- these cases which we cannot necessarily track. Also skip any variable
23703 -- for which an address clause is given, or whose address is taken. Also
23704 -- never capture value of library level variables (an attempt to do so
23705 -- can occur in the case of package elaboration code).
23707 if Treat_As_Volatile
(Ent
)
23708 or else Is_Aliased
(Ent
)
23709 or else Present
(Address_Clause
(Ent
))
23710 or else Address_Taken
(Ent
)
23711 or else (Is_Library_Level_Entity
(Ent
)
23712 and then Ekind
(Ent
) = E_Variable
)
23717 -- OK, all above conditions are met. We also require that the scope of
23718 -- the reference be the same as the scope of the entity, not counting
23719 -- packages and blocks and loops.
23722 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
23723 R_Scope
: Entity_Id
;
23726 R_Scope
:= Current_Scope
;
23727 while R_Scope
/= Standard_Standard
loop
23728 exit when R_Scope
= E_Scope
;
23730 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
23733 R_Scope
:= Scope
(R_Scope
);
23738 -- We also require that the reference does not appear in a context
23739 -- where it is not sure to be executed (i.e. a conditional context
23740 -- or an exception handler). We skip this if Cond is True, since the
23741 -- capturing of values from conditional tests handles this ok.
23754 -- Seems dubious that case expressions are not handled here ???
23757 while Present
(P
) loop
23758 if Nkind
(P
) = N_If_Statement
23759 or else Nkind
(P
) = N_Case_Statement
23760 or else (Nkind
(P
) in N_Short_Circuit
23761 and then Desc
= Right_Opnd
(P
))
23762 or else (Nkind
(P
) = N_If_Expression
23763 and then Desc
/= First
(Expressions
(P
)))
23764 or else Nkind
(P
) = N_Exception_Handler
23765 or else Nkind
(P
) = N_Selective_Accept
23766 or else Nkind
(P
) = N_Conditional_Entry_Call
23767 or else Nkind
(P
) = N_Timed_Entry_Call
23768 or else Nkind
(P
) = N_Asynchronous_Select
23776 -- A special Ada 2012 case: the original node may be part
23777 -- of the else_actions of a conditional expression, in which
23778 -- case it might not have been expanded yet, and appears in
23779 -- a non-syntactic list of actions. In that case it is clearly
23780 -- not safe to save a value.
23783 and then Is_List_Member
(Desc
)
23784 and then No
(Parent
(List_Containing
(Desc
)))
23792 -- OK, looks safe to set value
23795 end Safe_To_Capture_Value
;
23801 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
23802 K1
: constant Node_Kind
:= Nkind
(N1
);
23803 K2
: constant Node_Kind
:= Nkind
(N2
);
23806 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
23807 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
23809 return Chars
(N1
) = Chars
(N2
);
23811 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
23812 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
23814 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
23815 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
23826 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
23827 N1
: constant Node_Id
:= Original_Node
(Node1
);
23828 N2
: constant Node_Id
:= Original_Node
(Node2
);
23829 -- We do the tests on original nodes, since we are most interested
23830 -- in the original source, not any expansion that got in the way.
23832 K1
: constant Node_Kind
:= Nkind
(N1
);
23833 K2
: constant Node_Kind
:= Nkind
(N2
);
23836 -- First case, both are entities with same entity
23838 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
23840 EN1
: constant Entity_Id
:= Entity
(N1
);
23841 EN2
: constant Entity_Id
:= Entity
(N2
);
23843 if Present
(EN1
) and then Present
(EN2
)
23844 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
23845 or else Is_Formal
(EN1
))
23853 -- Second case, selected component with same selector, same record
23855 if K1
= N_Selected_Component
23856 and then K2
= N_Selected_Component
23857 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
23859 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
23861 -- Third case, indexed component with same subscripts, same array
23863 elsif K1
= N_Indexed_Component
23864 and then K2
= N_Indexed_Component
23865 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
23870 E1
:= First
(Expressions
(N1
));
23871 E2
:= First
(Expressions
(N2
));
23872 while Present
(E1
) loop
23873 if not Same_Value
(E1
, E2
) then
23884 -- Fourth case, slice of same array with same bounds
23887 and then K2
= N_Slice
23888 and then Nkind
(Discrete_Range
(N1
)) = N_Range
23889 and then Nkind
(Discrete_Range
(N2
)) = N_Range
23890 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
23891 Low_Bound
(Discrete_Range
(N2
)))
23892 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
23893 High_Bound
(Discrete_Range
(N2
)))
23895 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
23897 -- All other cases, not clearly the same object
23908 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
23913 elsif not Is_Constrained
(T1
)
23914 and then not Is_Constrained
(T2
)
23915 and then Base_Type
(T1
) = Base_Type
(T2
)
23919 -- For now don't bother with case of identical constraints, to be
23920 -- fiddled with later on perhaps (this is only used for optimization
23921 -- purposes, so it is not critical to do a best possible job)
23932 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
23934 if Compile_Time_Known_Value
(Node1
)
23935 and then Compile_Time_Known_Value
(Node2
)
23937 -- Handle properly compile-time expressions that are not
23940 if Is_String_Type
(Etype
(Node1
)) then
23941 return Expr_Value_S
(Node1
) = Expr_Value_S
(Node2
);
23944 return Expr_Value
(Node1
) = Expr_Value
(Node2
);
23947 elsif Same_Object
(Node1
, Node2
) then
23954 --------------------
23955 -- Set_SPARK_Mode --
23956 --------------------
23958 procedure Set_SPARK_Mode
(Context
: Entity_Id
) is
23960 -- Do not consider illegal or partially decorated constructs
23962 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
23965 elsif Present
(SPARK_Pragma
(Context
)) then
23967 (Mode
=> Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Context
)),
23968 Prag
=> SPARK_Pragma
(Context
));
23970 end Set_SPARK_Mode
;
23972 -------------------------
23973 -- Scalar_Part_Present --
23974 -------------------------
23976 function Scalar_Part_Present
(Typ
: Entity_Id
) return Boolean is
23977 Val_Typ
: constant Entity_Id
:= Validated_View
(Typ
);
23981 if Is_Scalar_Type
(Val_Typ
) then
23984 elsif Is_Array_Type
(Val_Typ
) then
23985 return Scalar_Part_Present
(Component_Type
(Val_Typ
));
23987 elsif Is_Record_Type
(Val_Typ
) then
23988 Field
:= First_Component_Or_Discriminant
(Val_Typ
);
23989 while Present
(Field
) loop
23990 if Scalar_Part_Present
(Etype
(Field
)) then
23994 Next_Component_Or_Discriminant
(Field
);
23999 end Scalar_Part_Present
;
24001 ------------------------
24002 -- Scope_Is_Transient --
24003 ------------------------
24005 function Scope_Is_Transient
return Boolean is
24007 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
24008 end Scope_Is_Transient
;
24014 function Scope_Within
24015 (Inner
: Entity_Id
;
24016 Outer
: Entity_Id
) return Boolean
24022 while Present
(Curr
) and then Curr
/= Standard_Standard
loop
24023 Curr
:= Scope
(Curr
);
24025 if Curr
= Outer
then
24028 -- A selective accept body appears within a task type, but the
24029 -- enclosing subprogram is the procedure of the task body.
24031 elsif Ekind
(Curr
) = E_Task_Type
24032 and then Outer
= Task_Body_Procedure
(Curr
)
24036 -- Ditto for the body of a protected operation
24038 elsif Is_Subprogram
(Curr
)
24039 and then Outer
= Protected_Body_Subprogram
(Curr
)
24043 -- Outside of its scope, a synchronized type may just be private
24045 elsif Is_Private_Type
(Curr
)
24046 and then Present
(Full_View
(Curr
))
24047 and then Is_Concurrent_Type
(Full_View
(Curr
))
24049 return Scope_Within
(Full_View
(Curr
), Outer
);
24056 --------------------------
24057 -- Scope_Within_Or_Same --
24058 --------------------------
24060 function Scope_Within_Or_Same
24061 (Inner
: Entity_Id
;
24062 Outer
: Entity_Id
) return Boolean
24068 while Present
(Curr
) and then Curr
/= Standard_Standard
loop
24069 if Curr
= Outer
then
24073 Curr
:= Scope
(Curr
);
24077 end Scope_Within_Or_Same
;
24079 --------------------
24080 -- Set_Convention --
24081 --------------------
24083 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
24085 Basic_Set_Convention
(E
, Val
);
24088 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
24089 and then Has_Foreign_Convention
(E
)
24091 Set_Can_Use_Internal_Rep
(E
, False);
24094 -- If E is an object, including a component, and the type of E is an
24095 -- anonymous access type with no convention set, then also set the
24096 -- convention of the anonymous access type. We do not do this for
24097 -- anonymous protected types, since protected types always have the
24098 -- default convention.
24100 if Present
(Etype
(E
))
24101 and then (Is_Object
(E
)
24103 -- Allow E_Void (happens for pragma Convention appearing
24104 -- in the middle of a record applying to a component)
24106 or else Ekind
(E
) = E_Void
)
24109 Typ
: constant Entity_Id
:= Etype
(E
);
24112 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
24113 E_Anonymous_Access_Subprogram_Type
)
24114 and then not Has_Convention_Pragma
(Typ
)
24116 Basic_Set_Convention
(Typ
, Val
);
24117 Set_Has_Convention_Pragma
(Typ
);
24119 -- And for the access subprogram type, deal similarly with the
24120 -- designated E_Subprogram_Type, which is always internal.
24122 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
24124 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
24126 if Ekind
(Dtype
) = E_Subprogram_Type
24127 and then not Has_Convention_Pragma
(Dtype
)
24129 Basic_Set_Convention
(Dtype
, Val
);
24130 Set_Has_Convention_Pragma
(Dtype
);
24137 end Set_Convention
;
24139 ------------------------
24140 -- Set_Current_Entity --
24141 ------------------------
24143 -- The given entity is to be set as the currently visible definition of its
24144 -- associated name (i.e. the Node_Id associated with its name). All we have
24145 -- to do is to get the name from the identifier, and then set the
24146 -- associated Node_Id to point to the given entity.
24148 procedure Set_Current_Entity
(E
: Entity_Id
) is
24150 Set_Name_Entity_Id
(Chars
(E
), E
);
24151 end Set_Current_Entity
;
24153 ---------------------------
24154 -- Set_Debug_Info_Needed --
24155 ---------------------------
24157 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
24159 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
24160 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
24161 -- Used to set debug info in a related node if not set already
24163 --------------------------------------
24164 -- Set_Debug_Info_Needed_If_Not_Set --
24165 --------------------------------------
24167 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
24169 if Present
(E
) and then not Needs_Debug_Info
(E
) then
24170 Set_Debug_Info_Needed
(E
);
24172 -- For a private type, indicate that the full view also needs
24173 -- debug information.
24176 and then Is_Private_Type
(E
)
24177 and then Present
(Full_View
(E
))
24179 Set_Debug_Info_Needed
(Full_View
(E
));
24182 end Set_Debug_Info_Needed_If_Not_Set
;
24184 -- Start of processing for Set_Debug_Info_Needed
24187 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
24188 -- indicates that Debug_Info_Needed is never required for the entity.
24189 -- Nothing to do if entity comes from a predefined file. Library files
24190 -- are compiled without debug information, but inlined bodies of these
24191 -- routines may appear in user code, and debug information on them ends
24192 -- up complicating debugging the user code.
24195 or else Debug_Info_Off
(T
)
24199 elsif In_Inlined_Body
and then In_Predefined_Unit
(T
) then
24200 Set_Needs_Debug_Info
(T
, False);
24203 -- Set flag in entity itself. Note that we will go through the following
24204 -- circuitry even if the flag is already set on T. That's intentional,
24205 -- it makes sure that the flag will be set in subsidiary entities.
24207 Set_Needs_Debug_Info
(T
);
24209 -- Set flag on subsidiary entities if not set already
24211 if Is_Object
(T
) then
24212 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
24214 elsif Is_Type
(T
) then
24215 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
24217 if Is_Record_Type
(T
) then
24219 Ent
: Entity_Id
:= First_Entity
(T
);
24221 while Present
(Ent
) loop
24222 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
24227 -- For a class wide subtype, we also need debug information
24228 -- for the equivalent type.
24230 if Ekind
(T
) = E_Class_Wide_Subtype
then
24231 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
24234 elsif Is_Array_Type
(T
) then
24235 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
24238 Indx
: Node_Id
:= First_Index
(T
);
24240 while Present
(Indx
) loop
24241 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
24242 Indx
:= Next_Index
(Indx
);
24246 -- For a packed array type, we also need debug information for
24247 -- the type used to represent the packed array. Conversely, we
24248 -- also need it for the former if we need it for the latter.
24250 if Is_Packed
(T
) then
24251 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
24254 if Is_Packed_Array_Impl_Type
(T
) then
24255 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
24258 elsif Is_Access_Type
(T
) then
24259 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
24261 elsif Is_Private_Type
(T
) then
24263 FV
: constant Entity_Id
:= Full_View
(T
);
24266 Set_Debug_Info_Needed_If_Not_Set
(FV
);
24268 -- If the full view is itself a derived private type, we need
24269 -- debug information on its underlying type.
24272 and then Is_Private_Type
(FV
)
24273 and then Present
(Underlying_Full_View
(FV
))
24275 Set_Needs_Debug_Info
(Underlying_Full_View
(FV
));
24279 elsif Is_Protected_Type
(T
) then
24280 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
24282 elsif Is_Scalar_Type
(T
) then
24284 -- If the subrange bounds are materialized by dedicated constant
24285 -- objects, also include them in the debug info to make sure the
24286 -- debugger can properly use them.
24288 if Present
(Scalar_Range
(T
))
24289 and then Nkind
(Scalar_Range
(T
)) = N_Range
24292 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
24293 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
24296 if Is_Entity_Name
(Low_Bnd
) then
24297 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
24300 if Is_Entity_Name
(High_Bnd
) then
24301 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
24307 end Set_Debug_Info_Needed
;
24309 ----------------------------
24310 -- Set_Entity_With_Checks --
24311 ----------------------------
24313 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
24314 Val_Actual
: Entity_Id
;
24316 Post_Node
: Node_Id
;
24319 -- Unconditionally set the entity
24321 Set_Entity
(N
, Val
);
24323 -- The node to post on is the selector in the case of an expanded name,
24324 -- and otherwise the node itself.
24326 if Nkind
(N
) = N_Expanded_Name
then
24327 Post_Node
:= Selector_Name
(N
);
24332 -- Check for violation of No_Fixed_IO
24334 if Restriction_Check_Required
(No_Fixed_IO
)
24336 ((RTU_Loaded
(Ada_Text_IO
)
24337 and then (Is_RTE
(Val
, RE_Decimal_IO
)
24339 Is_RTE
(Val
, RE_Fixed_IO
)))
24342 (RTU_Loaded
(Ada_Wide_Text_IO
)
24343 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
24345 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
24348 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
24349 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
24351 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
24353 -- A special extra check, don't complain about a reference from within
24354 -- the Ada.Interrupts package itself!
24356 and then not In_Same_Extended_Unit
(N
, Val
)
24358 Check_Restriction
(No_Fixed_IO
, Post_Node
);
24361 -- Remaining checks are only done on source nodes. Note that we test
24362 -- for violation of No_Fixed_IO even on non-source nodes, because the
24363 -- cases for checking violations of this restriction are instantiations
24364 -- where the reference in the instance has Comes_From_Source False.
24366 if not Comes_From_Source
(N
) then
24370 -- Check for violation of No_Abort_Statements, which is triggered by
24371 -- call to Ada.Task_Identification.Abort_Task.
24373 if Restriction_Check_Required
(No_Abort_Statements
)
24374 and then (Is_RTE
(Val
, RE_Abort_Task
))
24376 -- A special extra check, don't complain about a reference from within
24377 -- the Ada.Task_Identification package itself!
24379 and then not In_Same_Extended_Unit
(N
, Val
)
24381 Check_Restriction
(No_Abort_Statements
, Post_Node
);
24384 if Val
= Standard_Long_Long_Integer
then
24385 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
24388 -- Check for violation of No_Dynamic_Attachment
24390 if Restriction_Check_Required
(No_Dynamic_Attachment
)
24391 and then RTU_Loaded
(Ada_Interrupts
)
24392 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
24393 Is_RTE
(Val
, RE_Is_Attached
) or else
24394 Is_RTE
(Val
, RE_Current_Handler
) or else
24395 Is_RTE
(Val
, RE_Attach_Handler
) or else
24396 Is_RTE
(Val
, RE_Exchange_Handler
) or else
24397 Is_RTE
(Val
, RE_Detach_Handler
) or else
24398 Is_RTE
(Val
, RE_Reference
))
24400 -- A special extra check, don't complain about a reference from within
24401 -- the Ada.Interrupts package itself!
24403 and then not In_Same_Extended_Unit
(N
, Val
)
24405 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
24408 -- Check for No_Implementation_Identifiers
24410 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
24412 -- We have an implementation defined entity if it is marked as
24413 -- implementation defined, or is defined in a package marked as
24414 -- implementation defined. However, library packages themselves
24415 -- are excluded (we don't want to flag Interfaces itself, just
24416 -- the entities within it).
24418 if (Is_Implementation_Defined
(Val
)
24420 (Present
(Scope
(Val
))
24421 and then Is_Implementation_Defined
(Scope
(Val
))))
24422 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
24423 and then Is_Library_Level_Entity
(Val
))
24425 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
24429 -- Do the style check
24432 and then not Suppress_Style_Checks
(Val
)
24433 and then not In_Instance
24435 if Nkind
(N
) = N_Identifier
then
24437 elsif Nkind
(N
) = N_Expanded_Name
then
24438 Nod
:= Selector_Name
(N
);
24443 -- A special situation arises for derived operations, where we want
24444 -- to do the check against the parent (since the Sloc of the derived
24445 -- operation points to the derived type declaration itself).
24448 while not Comes_From_Source
(Val_Actual
)
24449 and then Nkind
(Val_Actual
) in N_Entity
24450 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
24451 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
24452 and then Present
(Alias
(Val_Actual
))
24454 Val_Actual
:= Alias
(Val_Actual
);
24457 -- Renaming declarations for generic actuals do not come from source,
24458 -- and have a different name from that of the entity they rename, so
24459 -- there is no style check to perform here.
24461 if Chars
(Nod
) = Chars
(Val_Actual
) then
24462 Style
.Check_Identifier
(Nod
, Val_Actual
);
24466 Set_Entity
(N
, Val
);
24467 end Set_Entity_With_Checks
;
24469 ------------------------------
24470 -- Set_Invalid_Scalar_Value --
24471 ------------------------------
24473 procedure Set_Invalid_Scalar_Value
24474 (Scal_Typ
: Float_Scalar_Id
;
24477 Slot
: Ureal
renames Invalid_Floats
(Scal_Typ
);
24480 -- Detect an attempt to set a different value for the same scalar type
24482 pragma Assert
(Slot
= No_Ureal
);
24484 end Set_Invalid_Scalar_Value
;
24486 ------------------------------
24487 -- Set_Invalid_Scalar_Value --
24488 ------------------------------
24490 procedure Set_Invalid_Scalar_Value
24491 (Scal_Typ
: Integer_Scalar_Id
;
24494 Slot
: Uint
renames Invalid_Integers
(Scal_Typ
);
24497 -- Detect an attempt to set a different value for the same scalar type
24499 pragma Assert
(Slot
= No_Uint
);
24501 end Set_Invalid_Scalar_Value
;
24503 ------------------------
24504 -- Set_Name_Entity_Id --
24505 ------------------------
24507 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
24509 Set_Name_Table_Int
(Id
, Int
(Val
));
24510 end Set_Name_Entity_Id
;
24512 ---------------------
24513 -- Set_Next_Actual --
24514 ---------------------
24516 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
24518 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
24519 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
24521 end Set_Next_Actual
;
24523 ----------------------------------
24524 -- Set_Optimize_Alignment_Flags --
24525 ----------------------------------
24527 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
24529 if Optimize_Alignment
= 'S' then
24530 Set_Optimize_Alignment_Space
(E
);
24531 elsif Optimize_Alignment
= 'T' then
24532 Set_Optimize_Alignment_Time
(E
);
24534 end Set_Optimize_Alignment_Flags
;
24536 -----------------------
24537 -- Set_Public_Status --
24538 -----------------------
24540 procedure Set_Public_Status
(Id
: Entity_Id
) is
24541 S
: constant Entity_Id
:= Current_Scope
;
24543 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
24544 -- Determines if E is defined within handled statement sequence or
24545 -- an if statement, returns True if so, False otherwise.
24547 ----------------------
24548 -- Within_HSS_Or_If --
24549 ----------------------
24551 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
24554 N
:= Declaration_Node
(E
);
24561 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
24567 end Within_HSS_Or_If
;
24569 -- Start of processing for Set_Public_Status
24572 -- Everything in the scope of Standard is public
24574 if S
= Standard_Standard
then
24575 Set_Is_Public
(Id
);
24577 -- Entity is definitely not public if enclosing scope is not public
24579 elsif not Is_Public
(S
) then
24582 -- An object or function declaration that occurs in a handled sequence
24583 -- of statements or within an if statement is the declaration for a
24584 -- temporary object or local subprogram generated by the expander. It
24585 -- never needs to be made public and furthermore, making it public can
24586 -- cause back end problems.
24588 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
24589 N_Function_Specification
)
24590 and then Within_HSS_Or_If
(Id
)
24594 -- Entities in public packages or records are public
24596 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
24597 Set_Is_Public
(Id
);
24599 -- The bounds of an entry family declaration can generate object
24600 -- declarations that are visible to the back-end, e.g. in the
24601 -- the declaration of a composite type that contains tasks.
24603 elsif Is_Concurrent_Type
(S
)
24604 and then not Has_Completion
(S
)
24605 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
24607 Set_Is_Public
(Id
);
24609 end Set_Public_Status
;
24611 -----------------------------
24612 -- Set_Referenced_Modified --
24613 -----------------------------
24615 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
24619 -- Deal with indexed or selected component where prefix is modified
24621 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
24622 Pref
:= Prefix
(N
);
24624 -- If prefix is access type, then it is the designated object that is
24625 -- being modified, which means we have no entity to set the flag on.
24627 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
24630 -- Otherwise chase the prefix
24633 Set_Referenced_Modified
(Pref
, Out_Param
);
24636 -- Otherwise see if we have an entity name (only other case to process)
24638 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
24639 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
24640 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
24642 end Set_Referenced_Modified
;
24648 procedure Set_Rep_Info
(T1
: Entity_Id
; T2
: Entity_Id
) is
24650 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
24651 Set_Is_Independent
(T1
, Is_Independent
(T2
));
24652 Set_Is_Volatile_Full_Access
(T1
, Is_Volatile_Full_Access
(T2
));
24654 if Is_Base_Type
(T1
) then
24655 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
24659 ----------------------------
24660 -- Set_Scope_Is_Transient --
24661 ----------------------------
24663 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
24665 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
24666 end Set_Scope_Is_Transient
;
24668 -------------------
24669 -- Set_Size_Info --
24670 -------------------
24672 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
24674 -- We copy Esize, but not RM_Size, since in general RM_Size is
24675 -- subtype specific and does not get inherited by all subtypes.
24677 Set_Esize
(T1
, Esize
(T2
));
24678 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
24680 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
24682 Is_Discrete_Or_Fixed_Point_Type
(T2
)
24684 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
24687 Set_Alignment
(T1
, Alignment
(T2
));
24690 ------------------------------
24691 -- Should_Ignore_Pragma_Par --
24692 ------------------------------
24694 function Should_Ignore_Pragma_Par
(Prag_Name
: Name_Id
) return Boolean is
24695 pragma Assert
(Compiler_State
= Parsing
);
24696 -- This one can't work during semantic analysis, because we don't have a
24697 -- correct Current_Source_File.
24699 Result
: constant Boolean :=
24700 Get_Name_Table_Boolean3
(Prag_Name
)
24701 and then not Is_Internal_File_Name
24702 (File_Name
(Current_Source_File
));
24705 end Should_Ignore_Pragma_Par
;
24707 ------------------------------
24708 -- Should_Ignore_Pragma_Sem --
24709 ------------------------------
24711 function Should_Ignore_Pragma_Sem
(N
: Node_Id
) return Boolean is
24712 pragma Assert
(Compiler_State
= Analyzing
);
24713 Prag_Name
: constant Name_Id
:= Pragma_Name
(N
);
24714 Result
: constant Boolean :=
24715 Get_Name_Table_Boolean3
(Prag_Name
)
24716 and then not In_Internal_Unit
(N
);
24720 end Should_Ignore_Pragma_Sem
;
24722 --------------------
24723 -- Static_Boolean --
24724 --------------------
24726 function Static_Boolean
(N
: Node_Id
) return Uint
is
24728 Analyze_And_Resolve
(N
, Standard_Boolean
);
24731 or else Error_Posted
(N
)
24732 or else Etype
(N
) = Any_Type
24737 if Is_OK_Static_Expression
(N
) then
24738 if not Raises_Constraint_Error
(N
) then
24739 return Expr_Value
(N
);
24744 elsif Etype
(N
) = Any_Type
then
24748 Flag_Non_Static_Expr
24749 ("static boolean expression required here", N
);
24752 end Static_Boolean
;
24754 --------------------
24755 -- Static_Integer --
24756 --------------------
24758 function Static_Integer
(N
: Node_Id
) return Uint
is
24760 Analyze_And_Resolve
(N
, Any_Integer
);
24763 or else Error_Posted
(N
)
24764 or else Etype
(N
) = Any_Type
24769 if Is_OK_Static_Expression
(N
) then
24770 if not Raises_Constraint_Error
(N
) then
24771 return Expr_Value
(N
);
24776 elsif Etype
(N
) = Any_Type
then
24780 Flag_Non_Static_Expr
24781 ("static integer expression required here", N
);
24784 end Static_Integer
;
24786 --------------------------
24787 -- Statically_Different --
24788 --------------------------
24790 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
24791 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
24792 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
24794 return Is_Entity_Name
(R1
)
24795 and then Is_Entity_Name
(R2
)
24796 and then Entity
(R1
) /= Entity
(R2
)
24797 and then not Is_Formal
(Entity
(R1
))
24798 and then not Is_Formal
(Entity
(R2
));
24799 end Statically_Different
;
24801 --------------------------------------
24802 -- Subject_To_Loop_Entry_Attributes --
24803 --------------------------------------
24805 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
24811 -- The expansion mechanism transform a loop subject to at least one
24812 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
24813 -- the conditional part.
24815 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
24816 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
24818 Stmt
:= Original_Node
(N
);
24822 Nkind
(Stmt
) = N_Loop_Statement
24823 and then Present
(Identifier
(Stmt
))
24824 and then Present
(Entity
(Identifier
(Stmt
)))
24825 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
24826 end Subject_To_Loop_Entry_Attributes
;
24828 -----------------------------
24829 -- Subprogram_Access_Level --
24830 -----------------------------
24832 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
24834 if Present
(Alias
(Subp
)) then
24835 return Subprogram_Access_Level
(Alias
(Subp
));
24837 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
24839 end Subprogram_Access_Level
;
24841 ---------------------
24842 -- Subprogram_Name --
24843 ---------------------
24845 function Subprogram_Name
(N
: Node_Id
) return String is
24846 Buf
: Bounded_String
;
24847 Ent
: Node_Id
:= N
;
24851 while Present
(Ent
) loop
24852 case Nkind
(Ent
) is
24853 when N_Subprogram_Body
=>
24854 Ent
:= Defining_Unit_Name
(Specification
(Ent
));
24857 when N_Subprogram_Declaration
=>
24858 Nod
:= Corresponding_Body
(Ent
);
24860 if Present
(Nod
) then
24863 Ent
:= Defining_Unit_Name
(Specification
(Ent
));
24868 when N_Subprogram_Instantiation
24870 | N_Package_Specification
24872 Ent
:= Defining_Unit_Name
(Ent
);
24875 when N_Protected_Type_Declaration
=>
24876 Ent
:= Corresponding_Body
(Ent
);
24879 when N_Protected_Body
24882 Ent
:= Defining_Identifier
(Ent
);
24889 Ent
:= Parent
(Ent
);
24893 return "unknown subprogram:unknown file:0:0";
24896 -- If the subprogram is a child unit, use its simple name to start the
24897 -- construction of the fully qualified name.
24899 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
24900 Ent
:= Defining_Identifier
(Ent
);
24903 Append_Entity_Name
(Buf
, Ent
);
24905 -- Append homonym number if needed
24907 if Nkind
(N
) in N_Entity
and then Has_Homonym
(N
) then
24909 H
: Entity_Id
:= Homonym
(N
);
24913 while Present
(H
) loop
24914 if Scope
(H
) = Scope
(N
) then
24928 -- Append source location of Ent to Buf so that the string will
24929 -- look like "subp:file:line:col".
24932 Loc
: constant Source_Ptr
:= Sloc
(Ent
);
24935 Append
(Buf
, Reference_Name
(Get_Source_File_Index
(Loc
)));
24937 Append
(Buf
, Nat
(Get_Logical_Line_Number
(Loc
)));
24939 Append
(Buf
, Nat
(Get_Column_Number
(Loc
)));
24943 end Subprogram_Name
;
24945 -------------------------------
24946 -- Support_Atomic_Primitives --
24947 -------------------------------
24949 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
24953 -- Verify the alignment of Typ is known
24955 if not Known_Alignment
(Typ
) then
24959 if Known_Static_Esize
(Typ
) then
24960 Size
:= UI_To_Int
(Esize
(Typ
));
24962 -- If the Esize (Object_Size) is unknown at compile time, look at the
24963 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
24965 elsif Known_Static_RM_Size
(Typ
) then
24966 Size
:= UI_To_Int
(RM_Size
(Typ
));
24968 -- Otherwise, the size is considered to be unknown.
24974 -- Check that the size of the component is 8, 16, 32, or 64 bits and
24975 -- that Typ is properly aligned.
24978 when 8 |
16 |
32 |
64 =>
24979 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
24984 end Support_Atomic_Primitives
;
24990 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
24992 if Debug_Flag_W
then
24993 for J
in 0 .. Scope_Stack
.Last
loop
24998 Write_Name
(Chars
(E
));
24999 Write_Str
(" from ");
25000 Write_Location
(Sloc
(N
));
25005 -----------------------
25006 -- Transfer_Entities --
25007 -----------------------
25009 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
25010 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
25011 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25012 -- Set_Public_Status. If successful and Id denotes a record type, set
25013 -- the Is_Public attribute of its fields.
25015 --------------------------
25016 -- Set_Public_Status_Of --
25017 --------------------------
25019 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
25023 if not Is_Public
(Id
) then
25024 Set_Public_Status
(Id
);
25026 -- When the input entity is a public record type, ensure that all
25027 -- its internal fields are also exposed to the linker. The fields
25028 -- of a class-wide type are never made public.
25031 and then Is_Record_Type
(Id
)
25032 and then not Is_Class_Wide_Type
(Id
)
25034 Field
:= First_Entity
(Id
);
25035 while Present
(Field
) loop
25036 Set_Is_Public
(Field
);
25037 Next_Entity
(Field
);
25041 end Set_Public_Status_Of
;
25045 Full_Id
: Entity_Id
;
25048 -- Start of processing for Transfer_Entities
25051 Id
:= First_Entity
(From
);
25053 if Present
(Id
) then
25055 -- Merge the entity chain of the source scope with that of the
25056 -- destination scope.
25058 if Present
(Last_Entity
(To
)) then
25059 Link_Entities
(Last_Entity
(To
), Id
);
25061 Set_First_Entity
(To
, Id
);
25064 Set_Last_Entity
(To
, Last_Entity
(From
));
25066 -- Inspect the entities of the source scope and update their Scope
25069 while Present
(Id
) loop
25070 Set_Scope
(Id
, To
);
25071 Set_Public_Status_Of
(Id
);
25073 -- Handle an internally generated full view for a private type
25075 if Is_Private_Type
(Id
)
25076 and then Present
(Full_View
(Id
))
25077 and then Is_Itype
(Full_View
(Id
))
25079 Full_Id
:= Full_View
(Id
);
25081 Set_Scope
(Full_Id
, To
);
25082 Set_Public_Status_Of
(Full_Id
);
25088 Set_First_Entity
(From
, Empty
);
25089 Set_Last_Entity
(From
, Empty
);
25091 end Transfer_Entities
;
25093 -----------------------
25094 -- Type_Access_Level --
25095 -----------------------
25097 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
25101 Btyp
:= Base_Type
(Typ
);
25103 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
25104 -- simply use the level where the type is declared. This is true for
25105 -- stand-alone object declarations, and for anonymous access types
25106 -- associated with components the level is the same as that of the
25107 -- enclosing composite type. However, special treatment is needed for
25108 -- the cases of access parameters, return objects of an anonymous access
25109 -- type, and, in Ada 95, access discriminants of limited types.
25111 if Is_Access_Type
(Btyp
) then
25112 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
25114 -- If the type is a nonlocal anonymous access type (such as for
25115 -- an access parameter) we treat it as being declared at the
25116 -- library level to ensure that names such as X.all'access don't
25117 -- fail static accessibility checks.
25119 if not Is_Local_Anonymous_Access
(Typ
) then
25120 return Scope_Depth
(Standard_Standard
);
25122 -- If this is a return object, the accessibility level is that of
25123 -- the result subtype of the enclosing function. The test here is
25124 -- little complicated, because we have to account for extended
25125 -- return statements that have been rewritten as blocks, in which
25126 -- case we have to find and the Is_Return_Object attribute of the
25127 -- itype's associated object. It would be nice to find a way to
25128 -- simplify this test, but it doesn't seem worthwhile to add a new
25129 -- flag just for purposes of this test. ???
25131 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
25134 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
25135 N_Object_Declaration
25136 and then Is_Return_Object
25137 (Defining_Identifier
25138 (Associated_Node_For_Itype
(Btyp
))))
25144 Scop
:= Scope
(Scope
(Btyp
));
25145 while Present
(Scop
) loop
25146 exit when Ekind
(Scop
) = E_Function
;
25147 Scop
:= Scope
(Scop
);
25150 -- Treat the return object's type as having the level of the
25151 -- function's result subtype (as per RM05-6.5(5.3/2)).
25153 return Type_Access_Level
(Etype
(Scop
));
25158 Btyp
:= Root_Type
(Btyp
);
25160 -- The accessibility level of anonymous access types associated with
25161 -- discriminants is that of the current instance of the type, and
25162 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
25164 -- AI-402: access discriminants have accessibility based on the
25165 -- object rather than the type in Ada 2005, so the above paragraph
25168 -- ??? Needs completion with rules from AI-416
25170 if Ada_Version
<= Ada_95
25171 and then Ekind
(Typ
) = E_Anonymous_Access_Type
25172 and then Present
(Associated_Node_For_Itype
(Typ
))
25173 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
25174 N_Discriminant_Specification
25176 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
25180 -- Return library level for a generic formal type. This is done because
25181 -- RM(10.3.2) says that "The statically deeper relationship does not
25182 -- apply to ... a descendant of a generic formal type". Rather than
25183 -- checking at each point where a static accessibility check is
25184 -- performed to see if we are dealing with a formal type, this rule is
25185 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
25186 -- return extreme values for a formal type; Deepest_Type_Access_Level
25187 -- returns Int'Last. By calling the appropriate function from among the
25188 -- two, we ensure that the static accessibility check will pass if we
25189 -- happen to run into a formal type. More specifically, we should call
25190 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
25191 -- call occurs as part of a static accessibility check and the error
25192 -- case is the case where the type's level is too shallow (as opposed
25195 if Is_Generic_Type
(Root_Type
(Btyp
)) then
25196 return Scope_Depth
(Standard_Standard
);
25199 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
25200 end Type_Access_Level
;
25202 ------------------------------------
25203 -- Type_Without_Stream_Operation --
25204 ------------------------------------
25206 function Type_Without_Stream_Operation
25208 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
25210 BT
: constant Entity_Id
:= Base_Type
(T
);
25211 Op_Missing
: Boolean;
25214 if not Restriction_Active
(No_Default_Stream_Attributes
) then
25218 if Is_Elementary_Type
(T
) then
25219 if Op
= TSS_Null
then
25221 No
(TSS
(BT
, TSS_Stream_Read
))
25222 or else No
(TSS
(BT
, TSS_Stream_Write
));
25225 Op_Missing
:= No
(TSS
(BT
, Op
));
25234 elsif Is_Array_Type
(T
) then
25235 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
25237 elsif Is_Record_Type
(T
) then
25243 Comp
:= First_Component
(T
);
25244 while Present
(Comp
) loop
25245 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
25247 if Present
(C_Typ
) then
25251 Next_Component
(Comp
);
25257 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
25258 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
25262 end Type_Without_Stream_Operation
;
25264 ----------------------------
25265 -- Unique_Defining_Entity --
25266 ----------------------------
25268 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
25270 return Unique_Entity
(Defining_Entity
(N
));
25271 end Unique_Defining_Entity
;
25273 -------------------
25274 -- Unique_Entity --
25275 -------------------
25277 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
25278 U
: Entity_Id
:= E
;
25284 if Present
(Full_View
(E
)) then
25285 U
:= Full_View
(E
);
25289 if Nkind
(Parent
(E
)) = N_Entry_Body
then
25291 Prot_Item
: Entity_Id
;
25292 Prot_Type
: Entity_Id
;
25295 if Ekind
(E
) = E_Entry
then
25296 Prot_Type
:= Scope
(E
);
25298 -- Bodies of entry families are nested within an extra scope
25299 -- that contains an entry index declaration.
25302 Prot_Type
:= Scope
(Scope
(E
));
25305 -- A protected type may be declared as a private type, in
25306 -- which case we need to get its full view.
25308 if Is_Private_Type
(Prot_Type
) then
25309 Prot_Type
:= Full_View
(Prot_Type
);
25312 -- Full view may not be present on error, in which case
25313 -- return E by default.
25315 if Present
(Prot_Type
) then
25316 pragma Assert
(Ekind
(Prot_Type
) = E_Protected_Type
);
25318 -- Traverse the entity list of the protected type and
25319 -- locate an entry declaration which matches the entry
25322 Prot_Item
:= First_Entity
(Prot_Type
);
25323 while Present
(Prot_Item
) loop
25324 if Ekind
(Prot_Item
) in Entry_Kind
25325 and then Corresponding_Body
(Parent
(Prot_Item
)) = E
25331 Next_Entity
(Prot_Item
);
25337 when Formal_Kind
=>
25338 if Present
(Spec_Entity
(E
)) then
25339 U
:= Spec_Entity
(E
);
25342 when E_Package_Body
=>
25345 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
25349 if Nkind
(P
) = N_Package_Body
25350 and then Present
(Corresponding_Spec
(P
))
25352 U
:= Corresponding_Spec
(P
);
25354 elsif Nkind
(P
) = N_Package_Body_Stub
25355 and then Present
(Corresponding_Spec_Of_Stub
(P
))
25357 U
:= Corresponding_Spec_Of_Stub
(P
);
25360 when E_Protected_Body
=>
25363 if Nkind
(P
) = N_Protected_Body
25364 and then Present
(Corresponding_Spec
(P
))
25366 U
:= Corresponding_Spec
(P
);
25368 elsif Nkind
(P
) = N_Protected_Body_Stub
25369 and then Present
(Corresponding_Spec_Of_Stub
(P
))
25371 U
:= Corresponding_Spec_Of_Stub
(P
);
25373 if Is_Single_Protected_Object
(U
) then
25378 if Is_Private_Type
(U
) then
25379 U
:= Full_View
(U
);
25382 when E_Subprogram_Body
=>
25385 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
25391 if Nkind
(P
) = N_Subprogram_Body
25392 and then Present
(Corresponding_Spec
(P
))
25394 U
:= Corresponding_Spec
(P
);
25396 elsif Nkind
(P
) = N_Subprogram_Body_Stub
25397 and then Present
(Corresponding_Spec_Of_Stub
(P
))
25399 U
:= Corresponding_Spec_Of_Stub
(P
);
25401 elsif Nkind
(P
) = N_Subprogram_Renaming_Declaration
then
25402 U
:= Corresponding_Spec
(P
);
25405 when E_Task_Body
=>
25408 if Nkind
(P
) = N_Task_Body
25409 and then Present
(Corresponding_Spec
(P
))
25411 U
:= Corresponding_Spec
(P
);
25413 elsif Nkind
(P
) = N_Task_Body_Stub
25414 and then Present
(Corresponding_Spec_Of_Stub
(P
))
25416 U
:= Corresponding_Spec_Of_Stub
(P
);
25418 if Is_Single_Task_Object
(U
) then
25423 if Is_Private_Type
(U
) then
25424 U
:= Full_View
(U
);
25428 if Present
(Full_View
(E
)) then
25429 U
:= Full_View
(E
);
25443 function Unique_Name
(E
: Entity_Id
) return String is
25445 -- Names in E_Subprogram_Body or E_Package_Body entities are not
25446 -- reliable, as they may not include the overloading suffix. Instead,
25447 -- when looking for the name of E or one of its enclosing scope, we get
25448 -- the name of the corresponding Unique_Entity.
25450 U
: constant Entity_Id
:= Unique_Entity
(E
);
25452 function This_Name
return String;
25458 function This_Name
return String is
25460 return Get_Name_String
(Chars
(U
));
25463 -- Start of processing for Unique_Name
25466 if E
= Standard_Standard
25467 or else Has_Fully_Qualified_Name
(E
)
25471 elsif Ekind
(E
) = E_Enumeration_Literal
then
25472 return Unique_Name
(Etype
(E
)) & "__" & This_Name
;
25476 S
: constant Entity_Id
:= Scope
(U
);
25477 pragma Assert
(Present
(S
));
25480 -- Prefix names of predefined types with standard__, but leave
25481 -- names of user-defined packages and subprograms without prefix
25482 -- (even if technically they are nested in the Standard package).
25484 if S
= Standard_Standard
then
25485 if Ekind
(U
) = E_Package
or else Is_Subprogram
(U
) then
25488 return Unique_Name
(S
) & "__" & This_Name
;
25491 -- For intances of generic subprograms use the name of the related
25492 -- instace and skip the scope of its wrapper package.
25494 elsif Is_Wrapper_Package
(S
) then
25495 pragma Assert
(Scope
(S
) = Scope
(Related_Instance
(S
)));
25496 -- Wrapper package and the instantiation are in the same scope
25499 Enclosing_Name
: constant String :=
25500 Unique_Name
(Scope
(S
)) & "__" &
25501 Get_Name_String
(Chars
(Related_Instance
(S
)));
25504 if Is_Subprogram
(U
)
25505 and then not Is_Generic_Actual_Subprogram
(U
)
25507 return Enclosing_Name
;
25509 return Enclosing_Name
& "__" & This_Name
;
25514 return Unique_Name
(S
) & "__" & This_Name
;
25520 ---------------------
25521 -- Unit_Is_Visible --
25522 ---------------------
25524 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
25525 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
25526 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
25528 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
25529 -- For a child unit, check whether unit appears in a with_clause
25532 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
25533 -- Scan the context clause of one compilation unit looking for a
25534 -- with_clause for the unit in question.
25536 ----------------------------
25537 -- Unit_In_Parent_Context --
25538 ----------------------------
25540 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
25542 if Unit_In_Context
(Par_Unit
) then
25545 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
25546 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
25551 end Unit_In_Parent_Context
;
25553 ---------------------
25554 -- Unit_In_Context --
25555 ---------------------
25557 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
25561 Clause
:= First
(Context_Items
(Comp_Unit
));
25562 while Present
(Clause
) loop
25563 if Nkind
(Clause
) = N_With_Clause
then
25564 if Library_Unit
(Clause
) = U
then
25567 -- The with_clause may denote a renaming of the unit we are
25568 -- looking for, eg. Text_IO which renames Ada.Text_IO.
25571 Renamed_Entity
(Entity
(Name
(Clause
))) =
25572 Defining_Entity
(Unit
(U
))
25582 end Unit_In_Context
;
25584 -- Start of processing for Unit_Is_Visible
25587 -- The currrent unit is directly visible
25592 elsif Unit_In_Context
(Curr
) then
25595 -- If the current unit is a body, check the context of the spec
25597 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
25599 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
25600 and then not Acts_As_Spec
(Unit
(Curr
)))
25602 if Unit_In_Context
(Library_Unit
(Curr
)) then
25607 -- If the spec is a child unit, examine the parents
25609 if Is_Child_Unit
(Curr_Entity
) then
25610 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
25612 Unit_In_Parent_Context
25613 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
25615 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
25621 end Unit_Is_Visible
;
25623 ------------------------------
25624 -- Universal_Interpretation --
25625 ------------------------------
25627 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
25628 Index
: Interp_Index
;
25632 -- The argument may be a formal parameter of an operator or subprogram
25633 -- with multiple interpretations, or else an expression for an actual.
25635 if Nkind
(Opnd
) = N_Defining_Identifier
25636 or else not Is_Overloaded
(Opnd
)
25638 if Etype
(Opnd
) = Universal_Integer
25639 or else Etype
(Opnd
) = Universal_Real
25641 return Etype
(Opnd
);
25647 Get_First_Interp
(Opnd
, Index
, It
);
25648 while Present
(It
.Typ
) loop
25649 if It
.Typ
= Universal_Integer
25650 or else It
.Typ
= Universal_Real
25655 Get_Next_Interp
(Index
, It
);
25660 end Universal_Interpretation
;
25666 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
25668 -- Recurse to handle unlikely case of multiple levels of qualification
25670 if Nkind
(Expr
) = N_Qualified_Expression
then
25671 return Unqualify
(Expression
(Expr
));
25673 -- Normal case, not a qualified expression
25684 function Unqual_Conv
(Expr
: Node_Id
) return Node_Id
is
25686 -- Recurse to handle unlikely case of multiple levels of qualification
25687 -- and/or conversion.
25689 if Nkind_In
(Expr
, N_Qualified_Expression
,
25691 N_Unchecked_Type_Conversion
)
25693 return Unqual_Conv
(Expression
(Expr
));
25695 -- Normal case, not a qualified expression
25702 --------------------
25703 -- Validated_View --
25704 --------------------
25706 function Validated_View
(Typ
: Entity_Id
) return Entity_Id
is
25707 Continue
: Boolean;
25708 Val_Typ
: Entity_Id
;
25712 Val_Typ
:= Base_Type
(Typ
);
25714 -- Obtain the full view of the input type by stripping away concurrency,
25715 -- derivations, and privacy.
25717 while Continue
loop
25720 if Is_Concurrent_Type
(Val_Typ
) then
25721 if Present
(Corresponding_Record_Type
(Val_Typ
)) then
25723 Val_Typ
:= Corresponding_Record_Type
(Val_Typ
);
25726 elsif Is_Derived_Type
(Val_Typ
) then
25728 Val_Typ
:= Etype
(Val_Typ
);
25730 elsif Is_Private_Type
(Val_Typ
) then
25731 if Present
(Underlying_Full_View
(Val_Typ
)) then
25733 Val_Typ
:= Underlying_Full_View
(Val_Typ
);
25735 elsif Present
(Full_View
(Val_Typ
)) then
25737 Val_Typ
:= Full_View
(Val_Typ
);
25743 end Validated_View
;
25745 -----------------------
25746 -- Visible_Ancestors --
25747 -----------------------
25749 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
25755 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
25757 -- Collect all the parents and progenitors of Typ. If the full-view of
25758 -- private parents and progenitors is available then it is used to
25759 -- generate the list of visible ancestors; otherwise their partial
25760 -- view is added to the resulting list.
25765 Use_Full_View
=> True);
25769 Ifaces_List
=> List_2
,
25770 Exclude_Parents
=> True,
25771 Use_Full_View
=> True);
25773 -- Join the two lists. Avoid duplications because an interface may
25774 -- simultaneously be parent and progenitor of a type.
25776 Elmt
:= First_Elmt
(List_2
);
25777 while Present
(Elmt
) loop
25778 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
25783 end Visible_Ancestors
;
25785 ----------------------
25786 -- Within_Init_Proc --
25787 ----------------------
25789 function Within_Init_Proc
return Boolean is
25793 S
:= Current_Scope
;
25794 while not Is_Overloadable
(S
) loop
25795 if S
= Standard_Standard
then
25802 return Is_Init_Proc
(S
);
25803 end Within_Init_Proc
;
25805 ---------------------------
25806 -- Within_Protected_Type --
25807 ---------------------------
25809 function Within_Protected_Type
(E
: Entity_Id
) return Boolean is
25810 Scop
: Entity_Id
:= Scope
(E
);
25813 while Present
(Scop
) loop
25814 if Ekind
(Scop
) = E_Protected_Type
then
25818 Scop
:= Scope
(Scop
);
25822 end Within_Protected_Type
;
25828 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
25830 return Scope_Within_Or_Same
(Scope
(E
), S
);
25833 ----------------------------
25834 -- Within_Subprogram_Call --
25835 ----------------------------
25837 function Within_Subprogram_Call
(N
: Node_Id
) return Boolean is
25841 -- Climb the parent chain looking for a function or procedure call
25844 while Present
(Par
) loop
25845 if Nkind_In
(Par
, N_Entry_Call_Statement
,
25847 N_Procedure_Call_Statement
)
25851 -- Prevent the search from going too far
25853 elsif Is_Body_Or_Package_Declaration
(Par
) then
25857 Par
:= Parent
(Par
);
25861 end Within_Subprogram_Call
;
25867 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
25868 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
25869 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
25871 Matching_Field
: Entity_Id
;
25872 -- Entity to give a more precise suggestion on how to write a one-
25873 -- element positional aggregate.
25875 function Has_One_Matching_Field
return Boolean;
25876 -- Determines if Expec_Type is a record type with a single component or
25877 -- discriminant whose type matches the found type or is one dimensional
25878 -- array whose component type matches the found type. In the case of
25879 -- one discriminant, we ignore the variant parts. That's not accurate,
25880 -- but good enough for the warning.
25882 ----------------------------
25883 -- Has_One_Matching_Field --
25884 ----------------------------
25886 function Has_One_Matching_Field
return Boolean is
25890 Matching_Field
:= Empty
;
25892 if Is_Array_Type
(Expec_Type
)
25893 and then Number_Dimensions
(Expec_Type
) = 1
25894 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
25896 -- Use type name if available. This excludes multidimensional
25897 -- arrays and anonymous arrays.
25899 if Comes_From_Source
(Expec_Type
) then
25900 Matching_Field
:= Expec_Type
;
25902 -- For an assignment, use name of target
25904 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
25905 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
25907 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
25912 elsif not Is_Record_Type
(Expec_Type
) then
25916 E
:= First_Entity
(Expec_Type
);
25921 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
25922 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
25931 if not Covers
(Etype
(E
), Found_Type
) then
25934 elsif Present
(Next_Entity
(E
))
25935 and then (Ekind
(E
) = E_Component
25936 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
25941 Matching_Field
:= E
;
25945 end Has_One_Matching_Field
;
25947 -- Start of processing for Wrong_Type
25950 -- Don't output message if either type is Any_Type, or if a message
25951 -- has already been posted for this node. We need to do the latter
25952 -- check explicitly (it is ordinarily done in Errout), because we
25953 -- are using ! to force the output of the error messages.
25955 if Expec_Type
= Any_Type
25956 or else Found_Type
= Any_Type
25957 or else Error_Posted
(Expr
)
25961 -- If one of the types is a Taft-Amendment type and the other it its
25962 -- completion, it must be an illegal use of a TAT in the spec, for
25963 -- which an error was already emitted. Avoid cascaded errors.
25965 elsif Is_Incomplete_Type
(Expec_Type
)
25966 and then Has_Completion_In_Body
(Expec_Type
)
25967 and then Full_View
(Expec_Type
) = Etype
(Expr
)
25971 elsif Is_Incomplete_Type
(Etype
(Expr
))
25972 and then Has_Completion_In_Body
(Etype
(Expr
))
25973 and then Full_View
(Etype
(Expr
)) = Expec_Type
25977 -- In an instance, there is an ongoing problem with completion of
25978 -- type derived from private types. Their structure is what Gigi
25979 -- expects, but the Etype is the parent type rather than the
25980 -- derived private type itself. Do not flag error in this case. The
25981 -- private completion is an entity without a parent, like an Itype.
25982 -- Similarly, full and partial views may be incorrect in the instance.
25983 -- There is no simple way to insure that it is consistent ???
25985 -- A similar view discrepancy can happen in an inlined body, for the
25986 -- same reason: inserted body may be outside of the original package
25987 -- and only partial views are visible at the point of insertion.
25989 elsif In_Instance
or else In_Inlined_Body
then
25990 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
25992 (Has_Private_Declaration
(Expected_Type
)
25993 or else Has_Private_Declaration
(Etype
(Expr
)))
25994 and then No
(Parent
(Expected_Type
))
25998 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
25999 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
26003 elsif Is_Private_Type
(Expected_Type
)
26004 and then Present
(Full_View
(Expected_Type
))
26005 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
26009 -- Conversely, type of expression may be the private one
26011 elsif Is_Private_Type
(Base_Type
(Etype
(Expr
)))
26012 and then Full_View
(Base_Type
(Etype
(Expr
))) = Expected_Type
26018 -- An interesting special check. If the expression is parenthesized
26019 -- and its type corresponds to the type of the sole component of the
26020 -- expected record type, or to the component type of the expected one
26021 -- dimensional array type, then assume we have a bad aggregate attempt.
26023 if Nkind
(Expr
) in N_Subexpr
26024 and then Paren_Count
(Expr
) /= 0
26025 and then Has_One_Matching_Field
26027 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
26029 if Present
(Matching_Field
) then
26030 if Is_Array_Type
(Expec_Type
) then
26032 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
26035 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
26039 -- Another special check, if we are looking for a pool-specific access
26040 -- type and we found an E_Access_Attribute_Type, then we have the case
26041 -- of an Access attribute being used in a context which needs a pool-
26042 -- specific type, which is never allowed. The one extra check we make
26043 -- is that the expected designated type covers the Found_Type.
26045 elsif Is_Access_Type
(Expec_Type
)
26046 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
26047 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
26048 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
26050 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
26052 Error_Msg_N
-- CODEFIX
26053 ("result must be general access type!", Expr
);
26054 Error_Msg_NE
-- CODEFIX
26055 ("add ALL to }!", Expr
, Expec_Type
);
26057 -- Another special check, if the expected type is an integer type,
26058 -- but the expression is of type System.Address, and the parent is
26059 -- an addition or subtraction operation whose left operand is the
26060 -- expression in question and whose right operand is of an integral
26061 -- type, then this is an attempt at address arithmetic, so give
26062 -- appropriate message.
26064 elsif Is_Integer_Type
(Expec_Type
)
26065 and then Is_RTE
(Found_Type
, RE_Address
)
26066 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
26067 and then Expr
= Left_Opnd
(Parent
(Expr
))
26068 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
26071 ("address arithmetic not predefined in package System",
26074 ("\possible missing with/use of System.Storage_Elements",
26078 -- If the expected type is an anonymous access type, as for access
26079 -- parameters and discriminants, the error is on the designated types.
26081 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
26082 if Comes_From_Source
(Expec_Type
) then
26083 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
26086 ("expected an access type with designated}",
26087 Expr
, Designated_Type
(Expec_Type
));
26090 if Is_Access_Type
(Found_Type
)
26091 and then not Comes_From_Source
(Found_Type
)
26094 ("\\found an access type with designated}!",
26095 Expr
, Designated_Type
(Found_Type
));
26097 if From_Limited_With
(Found_Type
) then
26098 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
26099 Error_Msg_Qual_Level
:= 99;
26100 Error_Msg_NE
-- CODEFIX
26101 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
26102 Error_Msg_Qual_Level
:= 0;
26104 Error_Msg_NE
("found}!", Expr
, Found_Type
);
26108 -- Normal case of one type found, some other type expected
26111 -- If the names of the two types are the same, see if some number
26112 -- of levels of qualification will help. Don't try more than three
26113 -- levels, and if we get to standard, it's no use (and probably
26114 -- represents an error in the compiler) Also do not bother with
26115 -- internal scope names.
26118 Expec_Scope
: Entity_Id
;
26119 Found_Scope
: Entity_Id
;
26122 Expec_Scope
:= Expec_Type
;
26123 Found_Scope
:= Found_Type
;
26125 for Levels
in Nat
range 0 .. 3 loop
26126 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
26127 Error_Msg_Qual_Level
:= Levels
;
26131 Expec_Scope
:= Scope
(Expec_Scope
);
26132 Found_Scope
:= Scope
(Found_Scope
);
26134 exit when Expec_Scope
= Standard_Standard
26135 or else Found_Scope
= Standard_Standard
26136 or else not Comes_From_Source
(Expec_Scope
)
26137 or else not Comes_From_Source
(Found_Scope
);
26141 if Is_Record_Type
(Expec_Type
)
26142 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
26144 Error_Msg_NE
("expected}!", Expr
,
26145 Corresponding_Remote_Type
(Expec_Type
));
26147 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
26150 if Is_Entity_Name
(Expr
)
26151 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
26153 Error_Msg_N
("\\found package name!", Expr
);
26155 elsif Is_Entity_Name
(Expr
)
26156 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
26158 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
26160 ("found procedure name, possibly missing Access attribute!",
26164 ("\\found procedure name instead of function!", Expr
);
26167 elsif Nkind
(Expr
) = N_Function_Call
26168 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
26169 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
26170 and then No
(Parameter_Associations
(Expr
))
26173 ("found function name, possibly missing Access attribute!",
26176 -- Catch common error: a prefix or infix operator which is not
26177 -- directly visible because the type isn't.
26179 elsif Nkind
(Expr
) in N_Op
26180 and then Is_Overloaded
(Expr
)
26181 and then not Is_Immediately_Visible
(Expec_Type
)
26182 and then not Is_Potentially_Use_Visible
(Expec_Type
)
26183 and then not In_Use
(Expec_Type
)
26184 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
26187 ("operator of the type is not directly visible!", Expr
);
26189 elsif Ekind
(Found_Type
) = E_Void
26190 and then Present
(Parent
(Found_Type
))
26191 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
26193 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
26196 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
26199 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
26200 -- of the same modular type, and (M1 and M2) = 0 was intended.
26202 if Expec_Type
= Standard_Boolean
26203 and then Is_Modular_Integer_Type
(Found_Type
)
26204 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
26205 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
26208 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
26209 L
: constant Node_Id
:= Left_Opnd
(Op
);
26210 R
: constant Node_Id
:= Right_Opnd
(Op
);
26213 -- The case for the message is when the left operand of the
26214 -- comparison is the same modular type, or when it is an
26215 -- integer literal (or other universal integer expression),
26216 -- which would have been typed as the modular type if the
26217 -- parens had been there.
26219 if (Etype
(L
) = Found_Type
26221 Etype
(L
) = Universal_Integer
)
26222 and then Is_Integer_Type
(Etype
(R
))
26225 ("\\possible missing parens for modular operation", Expr
);
26230 -- Reset error message qualification indication
26232 Error_Msg_Qual_Level
:= 0;
26236 --------------------------------
26237 -- Yields_Synchronized_Object --
26238 --------------------------------
26240 function Yields_Synchronized_Object
(Typ
: Entity_Id
) return Boolean is
26241 Has_Sync_Comp
: Boolean := False;
26245 -- An array type yields a synchronized object if its component type
26246 -- yields a synchronized object.
26248 if Is_Array_Type
(Typ
) then
26249 return Yields_Synchronized_Object
(Component_Type
(Typ
));
26251 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
26252 -- yields a synchronized object by default.
26254 elsif Is_Descendant_Of_Suspension_Object
(Typ
) then
26257 -- A protected type yields a synchronized object by default
26259 elsif Is_Protected_Type
(Typ
) then
26262 -- A record type or type extension yields a synchronized object when its
26263 -- discriminants (if any) lack default values and all components are of
26264 -- a type that yelds a synchronized object.
26266 elsif Is_Record_Type
(Typ
) then
26268 -- Inspect all entities defined in the scope of the type, looking for
26269 -- components of a type that does not yeld a synchronized object or
26270 -- for discriminants with default values.
26272 Id
:= First_Entity
(Typ
);
26273 while Present
(Id
) loop
26274 if Comes_From_Source
(Id
) then
26275 if Ekind
(Id
) = E_Component
then
26276 if Yields_Synchronized_Object
(Etype
(Id
)) then
26277 Has_Sync_Comp
:= True;
26279 -- The component does not yield a synchronized object
26285 elsif Ekind
(Id
) = E_Discriminant
26286 and then Present
(Expression
(Parent
(Id
)))
26295 -- Ensure that the parent type of a type extension yields a
26296 -- synchronized object.
26298 if Etype
(Typ
) /= Typ
26299 and then not Yields_Synchronized_Object
(Etype
(Typ
))
26304 -- If we get here, then all discriminants lack default values and all
26305 -- components are of a type that yields a synchronized object.
26307 return Has_Sync_Comp
;
26309 -- A synchronized interface type yields a synchronized object by default
26311 elsif Is_Synchronized_Interface
(Typ
) then
26314 -- A task type yelds a synchronized object by default
26316 elsif Is_Task_Type
(Typ
) then
26319 -- Otherwise the type does not yield a synchronized object
26324 end Yields_Synchronized_Object
;
26326 ---------------------------
26327 -- Yields_Universal_Type --
26328 ---------------------------
26330 function Yields_Universal_Type
(N
: Node_Id
) return Boolean is
26332 -- Integer and real literals are of a universal type
26334 if Nkind_In
(N
, N_Integer_Literal
, N_Real_Literal
) then
26337 -- The values of certain attributes are of a universal type
26339 elsif Nkind
(N
) = N_Attribute_Reference
then
26341 Universal_Type_Attribute
(Get_Attribute_Id
(Attribute_Name
(N
)));
26343 -- ??? There are possibly other cases to consider
26348 end Yields_Universal_Type
;
26351 Erroutc
.Subprogram_Name_Ptr
:= Subprogram_Name
'Access;