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
, N_Identifier
) then
8597 if Global_Mode
= Name_Input
then
8603 -- Simple global list (only input items) or moded global list
8606 elsif Nkind
(List
) = N_Aggregate
then
8607 if Present
(Expressions
(List
)) then
8608 if Global_Mode
= Name_Input
then
8609 return First
(Expressions
(List
));
8615 Assoc
:= First
(Component_Associations
(List
));
8616 while Present
(Assoc
) loop
8618 -- When we find the desired mode in an association, call
8619 -- recursively First_From_Global_List as if the mode was
8620 -- Name_Input, in order to reuse the existing machinery
8621 -- for the other cases.
8623 if Chars
(First
(Choices
(Assoc
))) = Global_Mode
then
8624 return First_From_Global_List
(Expression
(Assoc
));
8633 -- To accommodate partial decoration of disabled SPARK features,
8634 -- this routine may be called with illegal input. If this is the
8635 -- case, do not raise Program_Error.
8640 end First_From_Global_List
;
8644 Global
: Node_Id
:= Empty
;
8645 Body_Id
: Entity_Id
;
8648 pragma Assert
(Nam_In
(Global_Mode
, Name_In_Out
,
8653 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8654 -- case, it can only be located on the body entity.
8657 Body_Id
:= Subprogram_Body_Entity
(Subp
);
8658 if Present
(Body_Id
) then
8659 Global
:= Get_Pragma
(Body_Id
, Pragma_Refined_Global
);
8662 Global
:= Get_Pragma
(Subp
, Pragma_Global
);
8665 -- No corresponding global if pragma is not present
8670 -- Otherwise retrieve the corresponding list of items depending on the
8674 return First_From_Global_List
8675 (Expression
(Get_Argument
(Global
, Subp
)), Global_Mode
);
8683 function Fix_Msg
(Id
: Entity_Id
; Msg
: String) return String is
8684 Is_Task
: constant Boolean :=
8685 Ekind_In
(Id
, E_Task_Body
, E_Task_Type
)
8686 or else Is_Single_Task_Object
(Id
);
8687 Msg_Last
: constant Natural := Msg
'Last;
8688 Msg_Index
: Natural;
8689 Res
: String (Msg
'Range) := (others => ' ');
8690 Res_Index
: Natural;
8693 -- Copy all characters from the input message Msg to result Res with
8694 -- suitable replacements.
8696 Msg_Index
:= Msg
'First;
8697 Res_Index
:= Res
'First;
8698 while Msg_Index
<= Msg_Last
loop
8700 -- Replace "subprogram" with a different word
8702 if Msg_Index
<= Msg_Last
- 10
8703 and then Msg
(Msg_Index
.. Msg_Index
+ 9) = "subprogram"
8705 if Ekind_In
(Id
, E_Entry
, E_Entry_Family
) then
8706 Res
(Res_Index
.. Res_Index
+ 4) := "entry";
8707 Res_Index
:= Res_Index
+ 5;
8710 Res
(Res_Index
.. Res_Index
+ 8) := "task type";
8711 Res_Index
:= Res_Index
+ 9;
8714 Res
(Res_Index
.. Res_Index
+ 9) := "subprogram";
8715 Res_Index
:= Res_Index
+ 10;
8718 Msg_Index
:= Msg_Index
+ 10;
8720 -- Replace "protected" with a different word
8722 elsif Msg_Index
<= Msg_Last
- 9
8723 and then Msg
(Msg_Index
.. Msg_Index
+ 8) = "protected"
8726 Res
(Res_Index
.. Res_Index
+ 3) := "task";
8727 Res_Index
:= Res_Index
+ 4;
8728 Msg_Index
:= Msg_Index
+ 9;
8730 -- Otherwise copy the character
8733 Res
(Res_Index
) := Msg
(Msg_Index
);
8734 Msg_Index
:= Msg_Index
+ 1;
8735 Res_Index
:= Res_Index
+ 1;
8739 return Res
(Res
'First .. Res_Index
- 1);
8742 -------------------------
8743 -- From_Nested_Package --
8744 -------------------------
8746 function From_Nested_Package
(T
: Entity_Id
) return Boolean is
8747 Pack
: constant Entity_Id
:= Scope
(T
);
8751 Ekind
(Pack
) = E_Package
8752 and then not Is_Frozen
(Pack
)
8753 and then not Scope_Within_Or_Same
(Current_Scope
, Pack
)
8754 and then In_Open_Scopes
(Scope
(Pack
));
8755 end From_Nested_Package
;
8757 -----------------------
8758 -- Gather_Components --
8759 -----------------------
8761 procedure Gather_Components
8763 Comp_List
: Node_Id
;
8764 Governed_By
: List_Id
;
8766 Report_Errors
: out Boolean)
8770 Discrete_Choice
: Node_Id
;
8771 Comp_Item
: Node_Id
;
8773 Discrim
: Entity_Id
;
8774 Discrim_Name
: Node_Id
;
8775 Discrim_Value
: Node_Id
;
8778 Report_Errors
:= False;
8780 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
8783 elsif Present
(Component_Items
(Comp_List
)) then
8784 Comp_Item
:= First
(Component_Items
(Comp_List
));
8790 while Present
(Comp_Item
) loop
8792 -- Skip the tag of a tagged record, the interface tags, as well
8793 -- as all items that are not user components (anonymous types,
8794 -- rep clauses, Parent field, controller field).
8796 if Nkind
(Comp_Item
) = N_Component_Declaration
then
8798 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
8800 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
8801 Append_Elmt
(Comp
, Into
);
8809 if No
(Variant_Part
(Comp_List
)) then
8812 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
8813 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
8816 -- Look for the discriminant that governs this variant part.
8817 -- The discriminant *must* be in the Governed_By List
8819 Assoc
:= First
(Governed_By
);
8820 Find_Constraint
: loop
8821 Discrim
:= First
(Choices
(Assoc
));
8822 exit Find_Constraint
when
8823 Chars
(Discrim_Name
) = Chars
(Discrim
)
8825 (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
8826 and then Chars
(Corresponding_Discriminant
8827 (Entity
(Discrim
))) = Chars
(Discrim_Name
))
8829 Chars
(Original_Record_Component
(Entity
(Discrim
))) =
8830 Chars
(Discrim_Name
);
8832 if No
(Next
(Assoc
)) then
8833 if not Is_Constrained
(Typ
) and then Is_Derived_Type
(Typ
) then
8835 -- If the type is a tagged type with inherited discriminants,
8836 -- use the stored constraint on the parent in order to find
8837 -- the values of discriminants that are otherwise hidden by an
8838 -- explicit constraint. Renamed discriminants are handled in
8841 -- If several parent discriminants are renamed by a single
8842 -- discriminant of the derived type, the call to obtain the
8843 -- Corresponding_Discriminant field only retrieves the last
8844 -- of them. We recover the constraint on the others from the
8845 -- Stored_Constraint as well.
8847 -- An inherited discriminant may have been constrained in a
8848 -- later ancestor (not the immediate parent) so we must examine
8849 -- the stored constraint of all of them to locate the inherited
8855 T
: Entity_Id
:= Typ
;
8858 while Is_Derived_Type
(T
) loop
8859 if Present
(Stored_Constraint
(T
)) then
8860 D
:= First_Discriminant
(Etype
(T
));
8861 C
:= First_Elmt
(Stored_Constraint
(T
));
8862 while Present
(D
) and then Present
(C
) loop
8863 if Chars
(Discrim_Name
) = Chars
(D
) then
8864 if Is_Entity_Name
(Node
(C
))
8865 and then Entity
(Node
(C
)) = Entity
(Discrim
)
8867 -- D is renamed by Discrim, whose value is
8874 Make_Component_Association
(Sloc
(Typ
),
8876 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
8877 Duplicate_Subexpr_No_Checks
(Node
(C
)));
8880 exit Find_Constraint
;
8883 Next_Discriminant
(D
);
8888 -- Discriminant may be inherited from ancestor
8896 if No
(Next
(Assoc
)) then
8898 (" missing value for discriminant&",
8899 First
(Governed_By
), Discrim_Name
);
8901 Report_Errors
:= True;
8906 end loop Find_Constraint
;
8908 Discrim_Value
:= Expression
(Assoc
);
8910 if not Is_OK_Static_Expression
(Discrim_Value
) then
8912 -- If the variant part is governed by a discriminant of the type
8913 -- this is an error. If the variant part and the discriminant are
8914 -- inherited from an ancestor this is legal (AI05-120) unless the
8915 -- components are being gathered for an aggregate, in which case
8916 -- the caller must check Report_Errors.
8918 if Scope
(Original_Record_Component
8919 ((Entity
(First
(Choices
(Assoc
)))))) = Typ
8922 ("value for discriminant & must be static!",
8923 Discrim_Value
, Discrim
);
8924 Why_Not_Static
(Discrim_Value
);
8927 Report_Errors
:= True;
8931 Search_For_Discriminant_Value
: declare
8937 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
8940 Find_Discrete_Value
: while Present
(Variant
) loop
8941 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
8942 while Present
(Discrete_Choice
) loop
8943 exit Find_Discrete_Value
when
8944 Nkind
(Discrete_Choice
) = N_Others_Choice
;
8946 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
8948 UI_Low
:= Expr_Value
(Low
);
8949 UI_High
:= Expr_Value
(High
);
8951 exit Find_Discrete_Value
when
8952 UI_Low
<= UI_Discrim_Value
8954 UI_High
>= UI_Discrim_Value
;
8956 Next
(Discrete_Choice
);
8959 Next_Non_Pragma
(Variant
);
8960 end loop Find_Discrete_Value
;
8961 end Search_For_Discriminant_Value
;
8963 -- The case statement must include a variant that corresponds to the
8964 -- value of the discriminant, unless the discriminant type has a
8965 -- static predicate. In that case the absence of an others_choice that
8966 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8969 and then not Has_Static_Predicate
(Etype
(Discrim_Name
))
8972 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
8973 Report_Errors
:= True;
8977 -- If we have found the corresponding choice, recursively add its
8978 -- components to the Into list. The nested components are part of
8979 -- the same record type.
8981 if Present
(Variant
) then
8983 (Typ
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
8985 end Gather_Components
;
8987 ------------------------
8988 -- Get_Actual_Subtype --
8989 ------------------------
8991 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
8992 Typ
: constant Entity_Id
:= Etype
(N
);
8993 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
9002 -- If what we have is an identifier that references a subprogram
9003 -- formal, or a variable or constant object, then we get the actual
9004 -- subtype from the referenced entity if one has been built.
9006 if Nkind
(N
) = N_Identifier
9008 (Is_Formal
(Entity
(N
))
9009 or else Ekind
(Entity
(N
)) = E_Constant
9010 or else Ekind
(Entity
(N
)) = E_Variable
)
9011 and then Present
(Actual_Subtype
(Entity
(N
)))
9013 return Actual_Subtype
(Entity
(N
));
9015 -- Actual subtype of unchecked union is always itself. We never need
9016 -- the "real" actual subtype. If we did, we couldn't get it anyway
9017 -- because the discriminant is not available. The restrictions on
9018 -- Unchecked_Union are designed to make sure that this is OK.
9020 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
9023 -- Here for the unconstrained case, we must find actual subtype
9024 -- No actual subtype is available, so we must build it on the fly.
9026 -- Checking the type, not the underlying type, for constrainedness
9027 -- seems to be necessary. Maybe all the tests should be on the type???
9029 elsif (not Is_Constrained
(Typ
))
9030 and then (Is_Array_Type
(Utyp
)
9031 or else (Is_Record_Type
(Utyp
)
9032 and then Has_Discriminants
(Utyp
)))
9033 and then not Has_Unknown_Discriminants
(Utyp
)
9034 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
9036 -- Nothing to do if in spec expression (why not???)
9038 if In_Spec_Expression
then
9041 elsif Is_Private_Type
(Typ
) and then not Has_Discriminants
(Typ
) then
9043 -- If the type has no discriminants, there is no subtype to
9044 -- build, even if the underlying type is discriminated.
9048 -- Else build the actual subtype
9051 Decl
:= Build_Actual_Subtype
(Typ
, N
);
9052 Atyp
:= Defining_Identifier
(Decl
);
9054 -- If Build_Actual_Subtype generated a new declaration then use it
9058 -- The actual subtype is an Itype, so analyze the declaration,
9059 -- but do not attach it to the tree, to get the type defined.
9061 Set_Parent
(Decl
, N
);
9062 Set_Is_Itype
(Atyp
);
9063 Analyze
(Decl
, Suppress
=> All_Checks
);
9064 Set_Associated_Node_For_Itype
(Atyp
, N
);
9065 Set_Has_Delayed_Freeze
(Atyp
, False);
9067 -- We need to freeze the actual subtype immediately. This is
9068 -- needed, because otherwise this Itype will not get frozen
9069 -- at all, and it is always safe to freeze on creation because
9070 -- any associated types must be frozen at this point.
9072 Freeze_Itype
(Atyp
, N
);
9075 -- Otherwise we did not build a declaration, so return original
9082 -- For all remaining cases, the actual subtype is the same as
9083 -- the nominal type.
9088 end Get_Actual_Subtype
;
9090 -------------------------------------
9091 -- Get_Actual_Subtype_If_Available --
9092 -------------------------------------
9094 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
9095 Typ
: constant Entity_Id
:= Etype
(N
);
9098 -- If what we have is an identifier that references a subprogram
9099 -- formal, or a variable or constant object, then we get the actual
9100 -- subtype from the referenced entity if one has been built.
9102 if Nkind
(N
) = N_Identifier
9104 (Is_Formal
(Entity
(N
))
9105 or else Ekind
(Entity
(N
)) = E_Constant
9106 or else Ekind
(Entity
(N
)) = E_Variable
)
9107 and then Present
(Actual_Subtype
(Entity
(N
)))
9109 return Actual_Subtype
(Entity
(N
));
9111 -- Otherwise the Etype of N is returned unchanged
9116 end Get_Actual_Subtype_If_Available
;
9118 ------------------------
9119 -- Get_Body_From_Stub --
9120 ------------------------
9122 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
9124 return Proper_Body
(Unit
(Library_Unit
(N
)));
9125 end Get_Body_From_Stub
;
9127 ---------------------
9128 -- Get_Cursor_Type --
9129 ---------------------
9131 function Get_Cursor_Type
9133 Typ
: Entity_Id
) return Entity_Id
9137 First_Op
: Entity_Id
;
9141 -- If error already detected, return
9143 if Error_Posted
(Aspect
) then
9147 -- The cursor type for an Iterable aspect is the return type of a
9148 -- non-overloaded First primitive operation. Locate association for
9151 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
9153 while Present
(Assoc
) loop
9154 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
9155 First_Op
:= Expression
(Assoc
);
9162 if First_Op
= Any_Id
then
9163 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
9169 -- Locate function with desired name and profile in scope of type
9170 -- In the rare case where the type is an integer type, a base type
9171 -- is created for it, check that the base type of the first formal
9172 -- of First matches the base type of the domain.
9174 Func
:= First_Entity
(Scope
(Typ
));
9175 while Present
(Func
) loop
9176 if Chars
(Func
) = Chars
(First_Op
)
9177 and then Ekind
(Func
) = E_Function
9178 and then Present
(First_Formal
(Func
))
9179 and then Base_Type
(Etype
(First_Formal
(Func
))) = Base_Type
(Typ
)
9180 and then No
(Next_Formal
(First_Formal
(Func
)))
9182 if Cursor
/= Any_Type
then
9184 ("Operation First for iterable type must be unique", Aspect
);
9187 Cursor
:= Etype
(Func
);
9194 -- If not found, no way to resolve remaining primitives.
9196 if Cursor
= Any_Type
then
9198 ("No legal primitive operation First for Iterable type", Aspect
);
9202 end Get_Cursor_Type
;
9204 function Get_Cursor_Type
(Typ
: Entity_Id
) return Entity_Id
is
9206 return Etype
(Get_Iterable_Type_Primitive
(Typ
, Name_First
));
9207 end Get_Cursor_Type
;
9209 -------------------------------
9210 -- Get_Default_External_Name --
9211 -------------------------------
9213 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
9215 Get_Decoded_Name_String
(Chars
(E
));
9217 if Opt
.External_Name_Imp_Casing
= Uppercase
then
9218 Set_Casing
(All_Upper_Case
);
9220 Set_Casing
(All_Lower_Case
);
9224 Make_String_Literal
(Sloc
(E
),
9225 Strval
=> String_From_Name_Buffer
);
9226 end Get_Default_External_Name
;
9228 --------------------------
9229 -- Get_Enclosing_Object --
9230 --------------------------
9232 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
9234 if Is_Entity_Name
(N
) then
9238 when N_Indexed_Component
9239 | N_Selected_Component
9242 -- If not generating code, a dereference may be left implicit.
9243 -- In thoses cases, return Empty.
9245 if Is_Access_Type
(Etype
(Prefix
(N
))) then
9248 return Get_Enclosing_Object
(Prefix
(N
));
9251 when N_Type_Conversion
=>
9252 return Get_Enclosing_Object
(Expression
(N
));
9258 end Get_Enclosing_Object
;
9260 ---------------------------
9261 -- Get_Enum_Lit_From_Pos --
9262 ---------------------------
9264 function Get_Enum_Lit_From_Pos
9267 Loc
: Source_Ptr
) return Node_Id
9269 Btyp
: Entity_Id
:= Base_Type
(T
);
9274 -- In the case where the literal is of type Character, Wide_Character
9275 -- or Wide_Wide_Character or of a type derived from them, there needs
9276 -- to be some special handling since there is no explicit chain of
9277 -- literals to search. Instead, an N_Character_Literal node is created
9278 -- with the appropriate Char_Code and Chars fields.
9280 if Is_Standard_Character_Type
(T
) then
9281 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
9284 Make_Character_Literal
(Loc
,
9286 Char_Literal_Value
=> Pos
);
9288 -- For all other cases, we have a complete table of literals, and
9289 -- we simply iterate through the chain of literal until the one
9290 -- with the desired position value is found.
9293 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
9294 Btyp
:= Full_View
(Btyp
);
9297 Lit
:= First_Literal
(Btyp
);
9299 -- Position in the enumeration type starts at 0
9301 if UI_To_Int
(Pos
) < 0 then
9302 raise Constraint_Error
;
9305 for J
in 1 .. UI_To_Int
(Pos
) loop
9308 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9309 -- inside the loop to avoid calling Next_Literal on Empty.
9312 raise Constraint_Error
;
9316 -- Create a new node from Lit, with source location provided by Loc
9317 -- if not equal to No_Location, or by copying the source location of
9322 if LLoc
= No_Location
then
9326 return New_Occurrence_Of
(Lit
, LLoc
);
9328 end Get_Enum_Lit_From_Pos
;
9330 ------------------------
9331 -- Get_Generic_Entity --
9332 ------------------------
9334 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
9335 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
9337 if Present
(Renamed_Object
(Ent
)) then
9338 return Renamed_Object
(Ent
);
9342 end Get_Generic_Entity
;
9344 -------------------------------------
9345 -- Get_Incomplete_View_Of_Ancestor --
9346 -------------------------------------
9348 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
9349 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
9350 Par_Scope
: Entity_Id
;
9351 Par_Type
: Entity_Id
;
9354 -- The incomplete view of an ancestor is only relevant for private
9355 -- derived types in child units.
9357 if not Is_Derived_Type
(E
)
9358 or else not Is_Child_Unit
(Cur_Unit
)
9363 Par_Scope
:= Scope
(Cur_Unit
);
9364 if No
(Par_Scope
) then
9368 Par_Type
:= Etype
(Base_Type
(E
));
9370 -- Traverse list of ancestor types until we find one declared in
9371 -- a parent or grandparent unit (two levels seem sufficient).
9373 while Present
(Par_Type
) loop
9374 if Scope
(Par_Type
) = Par_Scope
9375 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
9379 elsif not Is_Derived_Type
(Par_Type
) then
9383 Par_Type
:= Etype
(Base_Type
(Par_Type
));
9387 -- If none found, there is no relevant ancestor type.
9391 end Get_Incomplete_View_Of_Ancestor
;
9393 ----------------------
9394 -- Get_Index_Bounds --
9395 ----------------------
9397 procedure Get_Index_Bounds
9401 Use_Full_View
: Boolean := False)
9403 function Scalar_Range_Of_Type
(Typ
: Entity_Id
) return Node_Id
;
9404 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9405 -- Typ qualifies, the scalar range is obtained from the full view of the
9408 --------------------------
9409 -- Scalar_Range_Of_Type --
9410 --------------------------
9412 function Scalar_Range_Of_Type
(Typ
: Entity_Id
) return Node_Id
is
9413 T
: Entity_Id
:= Typ
;
9416 if Use_Full_View
and then Present
(Full_View
(T
)) then
9420 return Scalar_Range
(T
);
9421 end Scalar_Range_Of_Type
;
9425 Kind
: constant Node_Kind
:= Nkind
(N
);
9428 -- Start of processing for Get_Index_Bounds
9431 if Kind
= N_Range
then
9433 H
:= High_Bound
(N
);
9435 elsif Kind
= N_Subtype_Indication
then
9436 Rng
:= Range_Expression
(Constraint
(N
));
9444 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
9445 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
9448 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
9449 Rng
:= Scalar_Range_Of_Type
(Entity
(N
));
9451 if Error_Posted
(Rng
) then
9455 elsif Nkind
(Rng
) = N_Subtype_Indication
then
9456 Get_Index_Bounds
(Rng
, L
, H
);
9459 L
:= Low_Bound
(Rng
);
9460 H
:= High_Bound
(Rng
);
9464 -- N is an expression, indicating a range with one value
9469 end Get_Index_Bounds
;
9471 -----------------------------
9472 -- Get_Interfacing_Aspects --
9473 -----------------------------
9475 procedure Get_Interfacing_Aspects
9476 (Iface_Asp
: Node_Id
;
9477 Conv_Asp
: out Node_Id
;
9478 EN_Asp
: out Node_Id
;
9479 Expo_Asp
: out Node_Id
;
9480 Imp_Asp
: out Node_Id
;
9481 LN_Asp
: out Node_Id
;
9482 Do_Checks
: Boolean := False)
9484 procedure Save_Or_Duplication_Error
9486 To
: in out Node_Id
);
9487 -- Save the value of aspect Asp in node To. If To already has a value,
9488 -- then this is considered a duplicate use of aspect. Emit an error if
9489 -- flag Do_Checks is set.
9491 -------------------------------
9492 -- Save_Or_Duplication_Error --
9493 -------------------------------
9495 procedure Save_Or_Duplication_Error
9497 To
: in out Node_Id
)
9500 -- Detect an extra aspect and issue an error
9502 if Present
(To
) then
9504 Error_Msg_Name_1
:= Chars
(Identifier
(Asp
));
9505 Error_Msg_Sloc
:= Sloc
(To
);
9506 Error_Msg_N
("aspect % previously given #", Asp
);
9509 -- Otherwise capture the aspect
9514 end Save_Or_Duplication_Error
;
9521 -- The following variables capture each individual aspect
9523 Conv
: Node_Id
:= Empty
;
9524 EN
: Node_Id
:= Empty
;
9525 Expo
: Node_Id
:= Empty
;
9526 Imp
: Node_Id
:= Empty
;
9527 LN
: Node_Id
:= Empty
;
9529 -- Start of processing for Get_Interfacing_Aspects
9532 -- The input interfacing aspect should reside in an aspect specification
9535 pragma Assert
(Is_List_Member
(Iface_Asp
));
9537 -- Examine the aspect specifications of the related entity. Find and
9538 -- capture all interfacing aspects. Detect duplicates and emit errors
9541 Asp
:= First
(List_Containing
(Iface_Asp
));
9542 while Present
(Asp
) loop
9543 Asp_Id
:= Get_Aspect_Id
(Asp
);
9545 if Asp_Id
= Aspect_Convention
then
9546 Save_Or_Duplication_Error
(Asp
, Conv
);
9548 elsif Asp_Id
= Aspect_External_Name
then
9549 Save_Or_Duplication_Error
(Asp
, EN
);
9551 elsif Asp_Id
= Aspect_Export
then
9552 Save_Or_Duplication_Error
(Asp
, Expo
);
9554 elsif Asp_Id
= Aspect_Import
then
9555 Save_Or_Duplication_Error
(Asp
, Imp
);
9557 elsif Asp_Id
= Aspect_Link_Name
then
9558 Save_Or_Duplication_Error
(Asp
, LN
);
9569 end Get_Interfacing_Aspects
;
9571 ---------------------------------
9572 -- Get_Iterable_Type_Primitive --
9573 ---------------------------------
9575 function Get_Iterable_Type_Primitive
9577 Nam
: Name_Id
) return Entity_Id
9579 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
9587 Assoc
:= First
(Component_Associations
(Funcs
));
9588 while Present
(Assoc
) loop
9589 if Chars
(First
(Choices
(Assoc
))) = Nam
then
9590 return Entity
(Expression
(Assoc
));
9593 Assoc
:= Next
(Assoc
);
9598 end Get_Iterable_Type_Primitive
;
9600 ----------------------------------
9601 -- Get_Library_Unit_Name_String --
9602 ----------------------------------
9604 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
9605 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
9608 Get_Unit_Name_String
(Unit_Name_Id
);
9610 -- Remove seven last character (" (spec)" or " (body)")
9612 Name_Len
:= Name_Len
- 7;
9613 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
9614 end Get_Library_Unit_Name_String
;
9616 --------------------------
9617 -- Get_Max_Queue_Length --
9618 --------------------------
9620 function Get_Max_Queue_Length
(Id
: Entity_Id
) return Uint
is
9621 pragma Assert
(Is_Entry
(Id
));
9622 Prag
: constant Entity_Id
:= Get_Pragma
(Id
, Pragma_Max_Queue_Length
);
9625 -- A value of 0 represents no maximum specified, and entries and entry
9626 -- families with no Max_Queue_Length aspect or pragma default to it.
9628 if not Present
(Prag
) then
9632 return Intval
(Expression
(First
(Pragma_Argument_Associations
(Prag
))));
9633 end Get_Max_Queue_Length
;
9635 ------------------------
9636 -- Get_Name_Entity_Id --
9637 ------------------------
9639 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
9641 return Entity_Id
(Get_Name_Table_Int
(Id
));
9642 end Get_Name_Entity_Id
;
9644 ------------------------------
9645 -- Get_Name_From_CTC_Pragma --
9646 ------------------------------
9648 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
9649 Arg
: constant Node_Id
:=
9650 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
9652 return Strval
(Expr_Value_S
(Arg
));
9653 end Get_Name_From_CTC_Pragma
;
9655 -----------------------
9656 -- Get_Parent_Entity --
9657 -----------------------
9659 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
9661 if Nkind
(Unit
) = N_Package_Body
9662 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
9664 return Defining_Entity
9665 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
9666 elsif Nkind
(Unit
) = N_Package_Instantiation
then
9667 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
9669 return Defining_Entity
(Unit
);
9671 end Get_Parent_Entity
;
9677 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
9679 return Get_Pragma_Id
(Pragma_Name_Unmapped
(N
));
9682 ------------------------
9683 -- Get_Qualified_Name --
9684 ------------------------
9686 function Get_Qualified_Name
9688 Suffix
: Entity_Id
:= Empty
) return Name_Id
9690 Suffix_Nam
: Name_Id
:= No_Name
;
9693 if Present
(Suffix
) then
9694 Suffix_Nam
:= Chars
(Suffix
);
9697 return Get_Qualified_Name
(Chars
(Id
), Suffix_Nam
, Scope
(Id
));
9698 end Get_Qualified_Name
;
9700 function Get_Qualified_Name
9702 Suffix
: Name_Id
:= No_Name
;
9703 Scop
: Entity_Id
:= Current_Scope
) return Name_Id
9705 procedure Add_Scope
(S
: Entity_Id
);
9706 -- Add the fully qualified form of scope S to the name buffer. The
9714 procedure Add_Scope
(S
: Entity_Id
) is
9719 elsif S
= Standard_Standard
then
9723 Add_Scope
(Scope
(S
));
9724 Get_Name_String_And_Append
(Chars
(S
));
9725 Add_Str_To_Name_Buffer
("__");
9729 -- Start of processing for Get_Qualified_Name
9735 -- Append the base name after all scopes have been chained
9737 Get_Name_String_And_Append
(Nam
);
9739 -- Append the suffix (if present)
9741 if Suffix
/= No_Name
then
9742 Add_Str_To_Name_Buffer
("__");
9743 Get_Name_String_And_Append
(Suffix
);
9747 end Get_Qualified_Name
;
9749 -----------------------
9750 -- Get_Reason_String --
9751 -----------------------
9753 procedure Get_Reason_String
(N
: Node_Id
) is
9755 if Nkind
(N
) = N_String_Literal
then
9756 Store_String_Chars
(Strval
(N
));
9758 elsif Nkind
(N
) = N_Op_Concat
then
9759 Get_Reason_String
(Left_Opnd
(N
));
9760 Get_Reason_String
(Right_Opnd
(N
));
9762 -- If not of required form, error
9766 ("Reason for pragma Warnings has wrong form", N
);
9768 ("\must be string literal or concatenation of string literals", N
);
9771 end Get_Reason_String
;
9773 --------------------------------
9774 -- Get_Reference_Discriminant --
9775 --------------------------------
9777 function Get_Reference_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
9781 D
:= First_Discriminant
(Typ
);
9782 while Present
(D
) loop
9783 if Has_Implicit_Dereference
(D
) then
9786 Next_Discriminant
(D
);
9790 end Get_Reference_Discriminant
;
9792 ---------------------------
9793 -- Get_Referenced_Object --
9794 ---------------------------
9796 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
9801 while Is_Entity_Name
(R
)
9802 and then Present
(Renamed_Object
(Entity
(R
)))
9804 R
:= Renamed_Object
(Entity
(R
));
9808 end Get_Referenced_Object
;
9810 ------------------------
9811 -- Get_Renamed_Entity --
9812 ------------------------
9814 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
9819 while Present
(Renamed_Entity
(R
)) loop
9820 R
:= Renamed_Entity
(R
);
9824 end Get_Renamed_Entity
;
9826 -----------------------
9827 -- Get_Return_Object --
9828 -----------------------
9830 function Get_Return_Object
(N
: Node_Id
) return Entity_Id
is
9834 Decl
:= First
(Return_Object_Declarations
(N
));
9835 while Present
(Decl
) loop
9836 exit when Nkind
(Decl
) = N_Object_Declaration
9837 and then Is_Return_Object
(Defining_Identifier
(Decl
));
9841 pragma Assert
(Present
(Decl
));
9842 return Defining_Identifier
(Decl
);
9843 end Get_Return_Object
;
9845 ---------------------------
9846 -- Get_Subprogram_Entity --
9847 ---------------------------
9849 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
9851 Subp_Id
: Entity_Id
;
9854 if Nkind
(Nod
) = N_Accept_Statement
then
9855 Subp
:= Entry_Direct_Name
(Nod
);
9857 elsif Nkind
(Nod
) = N_Slice
then
9858 Subp
:= Prefix
(Nod
);
9864 -- Strip the subprogram call
9867 if Nkind_In
(Subp
, N_Explicit_Dereference
,
9868 N_Indexed_Component
,
9869 N_Selected_Component
)
9871 Subp
:= Prefix
(Subp
);
9873 elsif Nkind_In
(Subp
, N_Type_Conversion
,
9874 N_Unchecked_Type_Conversion
)
9876 Subp
:= Expression
(Subp
);
9883 -- Extract the entity of the subprogram call
9885 if Is_Entity_Name
(Subp
) then
9886 Subp_Id
:= Entity
(Subp
);
9888 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
9889 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
9892 if Is_Subprogram
(Subp_Id
) then
9898 -- The search did not find a construct that denotes a subprogram
9903 end Get_Subprogram_Entity
;
9905 -----------------------------
9906 -- Get_Task_Body_Procedure --
9907 -----------------------------
9909 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Entity_Id
is
9911 -- Note: A task type may be the completion of a private type with
9912 -- discriminants. When performing elaboration checks on a task
9913 -- declaration, the current view of the type may be the private one,
9914 -- and the procedure that holds the body of the task is held in its
9917 -- This is an odd function, why not have Task_Body_Procedure do
9918 -- the following digging???
9920 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
9921 end Get_Task_Body_Procedure
;
9923 -------------------------
9924 -- Get_User_Defined_Eq --
9925 -------------------------
9927 function Get_User_Defined_Eq
(E
: Entity_Id
) return Entity_Id
is
9932 Prim
:= First_Elmt
(Collect_Primitive_Operations
(E
));
9933 while Present
(Prim
) loop
9936 if Chars
(Op
) = Name_Op_Eq
9937 and then Etype
(Op
) = Standard_Boolean
9938 and then Etype
(First_Formal
(Op
)) = E
9939 and then Etype
(Next_Formal
(First_Formal
(Op
))) = E
9948 end Get_User_Defined_Eq
;
9956 Priv_Typ
: out Entity_Id
;
9957 Full_Typ
: out Entity_Id
;
9958 Full_Base
: out Entity_Id
;
9959 CRec_Typ
: out Entity_Id
)
9961 IP_View
: Entity_Id
;
9964 -- Assume that none of the views can be recovered
9971 -- The input type is the corresponding record type of a protected or a
9974 if Ekind
(Typ
) = E_Record_Type
9975 and then Is_Concurrent_Record_Type
(Typ
)
9978 Full_Typ
:= Corresponding_Concurrent_Type
(CRec_Typ
);
9979 Full_Base
:= Base_Type
(Full_Typ
);
9980 Priv_Typ
:= Incomplete_Or_Partial_View
(Full_Typ
);
9982 -- Otherwise the input type denotes an arbitrary type
9985 IP_View
:= Incomplete_Or_Partial_View
(Typ
);
9987 -- The input type denotes the full view of a private type
9989 if Present
(IP_View
) then
9990 Priv_Typ
:= IP_View
;
9993 -- The input type is a private type
9995 elsif Is_Private_Type
(Typ
) then
9997 Full_Typ
:= Full_View
(Priv_Typ
);
9999 -- Otherwise the input type does not have any views
10005 if Present
(Full_Typ
) then
10006 Full_Base
:= Base_Type
(Full_Typ
);
10008 if Ekind_In
(Full_Typ
, E_Protected_Type
, E_Task_Type
) then
10009 CRec_Typ
:= Corresponding_Record_Type
(Full_Typ
);
10015 -----------------------
10016 -- Has_Access_Values --
10017 -----------------------
10019 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
10020 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
10023 -- Case of a private type which is not completed yet. This can only
10024 -- happen in the case of a generic format type appearing directly, or
10025 -- as a component of the type to which this function is being applied
10026 -- at the top level. Return False in this case, since we certainly do
10027 -- not know that the type contains access types.
10032 elsif Is_Access_Type
(Typ
) then
10035 elsif Is_Array_Type
(Typ
) then
10036 return Has_Access_Values
(Component_Type
(Typ
));
10038 elsif Is_Record_Type
(Typ
) then
10043 -- Loop to Check components
10045 Comp
:= First_Component_Or_Discriminant
(Typ
);
10046 while Present
(Comp
) loop
10048 -- Check for access component, tag field does not count, even
10049 -- though it is implemented internally using an access type.
10051 if Has_Access_Values
(Etype
(Comp
))
10052 and then Chars
(Comp
) /= Name_uTag
10057 Next_Component_Or_Discriminant
(Comp
);
10066 end Has_Access_Values
;
10068 ------------------------------
10069 -- Has_Compatible_Alignment --
10070 ------------------------------
10072 function Has_Compatible_Alignment
10075 Layout_Done
: Boolean) return Alignment_Result
10077 function Has_Compatible_Alignment_Internal
10080 Layout_Done
: Boolean;
10081 Default
: Alignment_Result
) return Alignment_Result
;
10082 -- This is the internal recursive function that actually does the work.
10083 -- There is one additional parameter, which says what the result should
10084 -- be if no alignment information is found, and there is no definite
10085 -- indication of compatible alignments. At the outer level, this is set
10086 -- to Unknown, but for internal recursive calls in the case where types
10087 -- are known to be correct, it is set to Known_Compatible.
10089 ---------------------------------------
10090 -- Has_Compatible_Alignment_Internal --
10091 ---------------------------------------
10093 function Has_Compatible_Alignment_Internal
10096 Layout_Done
: Boolean;
10097 Default
: Alignment_Result
) return Alignment_Result
10099 Result
: Alignment_Result
:= Known_Compatible
;
10100 -- Holds the current status of the result. Note that once a value of
10101 -- Known_Incompatible is set, it is sticky and does not get changed
10102 -- to Unknown (the value in Result only gets worse as we go along,
10105 Offs
: Uint
:= No_Uint
;
10106 -- Set to a factor of the offset from the base object when Expr is a
10107 -- selected or indexed component, based on Component_Bit_Offset and
10108 -- Component_Size respectively. A negative value is used to represent
10109 -- a value which is not known at compile time.
10111 procedure Check_Prefix
;
10112 -- Checks the prefix recursively in the case where the expression
10113 -- is an indexed or selected component.
10115 procedure Set_Result
(R
: Alignment_Result
);
10116 -- If R represents a worse outcome (unknown instead of known
10117 -- compatible, or known incompatible), then set Result to R.
10123 procedure Check_Prefix
is
10125 -- The subtlety here is that in doing a recursive call to check
10126 -- the prefix, we have to decide what to do in the case where we
10127 -- don't find any specific indication of an alignment problem.
10129 -- At the outer level, we normally set Unknown as the result in
10130 -- this case, since we can only set Known_Compatible if we really
10131 -- know that the alignment value is OK, but for the recursive
10132 -- call, in the case where the types match, and we have not
10133 -- specified a peculiar alignment for the object, we are only
10134 -- concerned about suspicious rep clauses, the default case does
10135 -- not affect us, since the compiler will, in the absence of such
10136 -- rep clauses, ensure that the alignment is correct.
10138 if Default
= Known_Compatible
10140 (Etype
(Obj
) = Etype
(Expr
)
10141 and then (Unknown_Alignment
(Obj
)
10143 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
10146 (Has_Compatible_Alignment_Internal
10147 (Obj
, Prefix
(Expr
), Layout_Done
, Known_Compatible
));
10149 -- In all other cases, we need a full check on the prefix
10153 (Has_Compatible_Alignment_Internal
10154 (Obj
, Prefix
(Expr
), Layout_Done
, Unknown
));
10162 procedure Set_Result
(R
: Alignment_Result
) is
10169 -- Start of processing for Has_Compatible_Alignment_Internal
10172 -- If Expr is a selected component, we must make sure there is no
10173 -- potentially troublesome component clause and that the record is
10174 -- not packed if the layout is not done.
10176 if Nkind
(Expr
) = N_Selected_Component
then
10178 -- Packing generates unknown alignment if layout is not done
10180 if Is_Packed
(Etype
(Prefix
(Expr
))) and then not Layout_Done
then
10181 Set_Result
(Unknown
);
10184 -- Check prefix and component offset
10187 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
10189 -- If Expr is an indexed component, we must make sure there is no
10190 -- potentially troublesome Component_Size clause and that the array
10191 -- is not bit-packed if the layout is not done.
10193 elsif Nkind
(Expr
) = N_Indexed_Component
then
10195 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
10198 -- Packing generates unknown alignment if layout is not done
10200 if Is_Bit_Packed_Array
(Typ
) and then not Layout_Done
then
10201 Set_Result
(Unknown
);
10204 -- Check prefix and component offset (or at least size)
10207 Offs
:= Indexed_Component_Bit_Offset
(Expr
);
10208 if Offs
= No_Uint
then
10209 Offs
:= Component_Size
(Typ
);
10214 -- If we have a null offset, the result is entirely determined by
10215 -- the base object and has already been computed recursively.
10217 if Offs
= Uint_0
then
10220 -- Case where we know the alignment of the object
10222 elsif Known_Alignment
(Obj
) then
10224 ObjA
: constant Uint
:= Alignment
(Obj
);
10225 ExpA
: Uint
:= No_Uint
;
10226 SizA
: Uint
:= No_Uint
;
10229 -- If alignment of Obj is 1, then we are always OK
10232 Set_Result
(Known_Compatible
);
10234 -- Alignment of Obj is greater than 1, so we need to check
10237 -- If we have an offset, see if it is compatible
10239 if Offs
/= No_Uint
and Offs
> Uint_0
then
10240 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
10241 Set_Result
(Known_Incompatible
);
10244 -- See if Expr is an object with known alignment
10246 elsif Is_Entity_Name
(Expr
)
10247 and then Known_Alignment
(Entity
(Expr
))
10249 ExpA
:= Alignment
(Entity
(Expr
));
10251 -- Otherwise, we can use the alignment of the type of
10252 -- Expr given that we already checked for
10253 -- discombobulating rep clauses for the cases of indexed
10254 -- and selected components above.
10256 elsif Known_Alignment
(Etype
(Expr
)) then
10257 ExpA
:= Alignment
(Etype
(Expr
));
10259 -- Otherwise the alignment is unknown
10262 Set_Result
(Default
);
10265 -- If we got an alignment, see if it is acceptable
10267 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
10268 Set_Result
(Known_Incompatible
);
10271 -- If Expr is not a piece of a larger object, see if size
10272 -- is given. If so, check that it is not too small for the
10273 -- required alignment.
10275 if Offs
/= No_Uint
then
10278 -- See if Expr is an object with known size
10280 elsif Is_Entity_Name
(Expr
)
10281 and then Known_Static_Esize
(Entity
(Expr
))
10283 SizA
:= Esize
(Entity
(Expr
));
10285 -- Otherwise, we check the object size of the Expr type
10287 elsif Known_Static_Esize
(Etype
(Expr
)) then
10288 SizA
:= Esize
(Etype
(Expr
));
10291 -- If we got a size, see if it is a multiple of the Obj
10292 -- alignment, if not, then the alignment cannot be
10293 -- acceptable, since the size is always a multiple of the
10296 if SizA
/= No_Uint
then
10297 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
10298 Set_Result
(Known_Incompatible
);
10304 -- If we do not know required alignment, any non-zero offset is a
10305 -- potential problem (but certainly may be OK, so result is unknown).
10307 elsif Offs
/= No_Uint
then
10308 Set_Result
(Unknown
);
10310 -- If we can't find the result by direct comparison of alignment
10311 -- values, then there is still one case that we can determine known
10312 -- result, and that is when we can determine that the types are the
10313 -- same, and no alignments are specified. Then we known that the
10314 -- alignments are compatible, even if we don't know the alignment
10315 -- value in the front end.
10317 elsif Etype
(Obj
) = Etype
(Expr
) then
10319 -- Types are the same, but we have to check for possible size
10320 -- and alignments on the Expr object that may make the alignment
10321 -- different, even though the types are the same.
10323 if Is_Entity_Name
(Expr
) then
10325 -- First check alignment of the Expr object. Any alignment less
10326 -- than Maximum_Alignment is worrisome since this is the case
10327 -- where we do not know the alignment of Obj.
10329 if Known_Alignment
(Entity
(Expr
))
10330 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
10331 Ttypes
.Maximum_Alignment
10333 Set_Result
(Unknown
);
10335 -- Now check size of Expr object. Any size that is not an
10336 -- even multiple of Maximum_Alignment is also worrisome
10337 -- since it may cause the alignment of the object to be less
10338 -- than the alignment of the type.
10340 elsif Known_Static_Esize
(Entity
(Expr
))
10342 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
10343 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
10346 Set_Result
(Unknown
);
10348 -- Otherwise same type is decisive
10351 Set_Result
(Known_Compatible
);
10355 -- Another case to deal with is when there is an explicit size or
10356 -- alignment clause when the types are not the same. If so, then the
10357 -- result is Unknown. We don't need to do this test if the Default is
10358 -- Unknown, since that result will be set in any case.
10360 elsif Default
/= Unknown
10361 and then (Has_Size_Clause
(Etype
(Expr
))
10363 Has_Alignment_Clause
(Etype
(Expr
)))
10365 Set_Result
(Unknown
);
10367 -- If no indication found, set default
10370 Set_Result
(Default
);
10373 -- Return worst result found
10376 end Has_Compatible_Alignment_Internal
;
10378 -- Start of processing for Has_Compatible_Alignment
10381 -- If Obj has no specified alignment, then set alignment from the type
10382 -- alignment. Perhaps we should always do this, but for sure we should
10383 -- do it when there is an address clause since we can do more if the
10384 -- alignment is known.
10386 if Unknown_Alignment
(Obj
) then
10387 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
10390 -- Now do the internal call that does all the work
10393 Has_Compatible_Alignment_Internal
(Obj
, Expr
, Layout_Done
, Unknown
);
10394 end Has_Compatible_Alignment
;
10396 ----------------------
10397 -- Has_Declarations --
10398 ----------------------
10400 function Has_Declarations
(N
: Node_Id
) return Boolean is
10402 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
10404 N_Compilation_Unit_Aux
,
10410 N_Package_Specification
);
10411 end Has_Declarations
;
10413 ---------------------------------
10414 -- Has_Defaulted_Discriminants --
10415 ---------------------------------
10417 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
10419 return Has_Discriminants
(Typ
)
10420 and then Present
(First_Discriminant
(Typ
))
10421 and then Present
(Discriminant_Default_Value
10422 (First_Discriminant
(Typ
)));
10423 end Has_Defaulted_Discriminants
;
10425 -------------------
10426 -- Has_Denormals --
10427 -------------------
10429 function Has_Denormals
(E
: Entity_Id
) return Boolean is
10431 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
10434 -------------------------------------------
10435 -- Has_Discriminant_Dependent_Constraint --
10436 -------------------------------------------
10438 function Has_Discriminant_Dependent_Constraint
10439 (Comp
: Entity_Id
) return Boolean
10441 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
10442 Subt_Indic
: Node_Id
;
10447 -- Discriminants can't depend on discriminants
10449 if Ekind
(Comp
) = E_Discriminant
then
10453 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
10455 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
10456 Constr
:= Constraint
(Subt_Indic
);
10458 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
10459 Assn
:= First
(Constraints
(Constr
));
10460 while Present
(Assn
) loop
10461 case Nkind
(Assn
) is
10464 | N_Subtype_Indication
10466 if Depends_On_Discriminant
(Assn
) then
10470 when N_Discriminant_Association
=>
10471 if Depends_On_Discriminant
(Expression
(Assn
)) then
10486 end Has_Discriminant_Dependent_Constraint
;
10488 --------------------------------------
10489 -- Has_Effectively_Volatile_Profile --
10490 --------------------------------------
10492 function Has_Effectively_Volatile_Profile
10493 (Subp_Id
: Entity_Id
) return Boolean
10495 Formal
: Entity_Id
;
10498 -- Inspect the formal parameters looking for an effectively volatile
10501 Formal
:= First_Formal
(Subp_Id
);
10502 while Present
(Formal
) loop
10503 if Is_Effectively_Volatile
(Etype
(Formal
)) then
10507 Next_Formal
(Formal
);
10510 -- Inspect the return type of functions
10512 if Ekind_In
(Subp_Id
, E_Function
, E_Generic_Function
)
10513 and then Is_Effectively_Volatile
(Etype
(Subp_Id
))
10519 end Has_Effectively_Volatile_Profile
;
10521 --------------------------
10522 -- Has_Enabled_Property --
10523 --------------------------
10525 function Has_Enabled_Property
10526 (Item_Id
: Entity_Id
;
10527 Property
: Name_Id
) return Boolean
10529 function Protected_Object_Has_Enabled_Property
return Boolean;
10530 -- Determine whether a protected object denoted by Item_Id has the
10531 -- property enabled.
10533 function State_Has_Enabled_Property
return Boolean;
10534 -- Determine whether a state denoted by Item_Id has the property enabled
10536 function Variable_Has_Enabled_Property
return Boolean;
10537 -- Determine whether a variable denoted by Item_Id has the property
10540 -------------------------------------------
10541 -- Protected_Object_Has_Enabled_Property --
10542 -------------------------------------------
10544 function Protected_Object_Has_Enabled_Property
return Boolean is
10545 Constits
: constant Elist_Id
:= Part_Of_Constituents
(Item_Id
);
10546 Constit_Elmt
: Elmt_Id
;
10547 Constit_Id
: Entity_Id
;
10550 -- Protected objects always have the properties Async_Readers and
10551 -- Async_Writers (SPARK RM 7.1.2(16)).
10553 if Property
= Name_Async_Readers
10554 or else Property
= Name_Async_Writers
10558 -- Protected objects that have Part_Of components also inherit their
10559 -- properties Effective_Reads and Effective_Writes
10560 -- (SPARK RM 7.1.2(16)).
10562 elsif Present
(Constits
) then
10563 Constit_Elmt
:= First_Elmt
(Constits
);
10564 while Present
(Constit_Elmt
) loop
10565 Constit_Id
:= Node
(Constit_Elmt
);
10567 if Has_Enabled_Property
(Constit_Id
, Property
) then
10571 Next_Elmt
(Constit_Elmt
);
10576 end Protected_Object_Has_Enabled_Property
;
10578 --------------------------------
10579 -- State_Has_Enabled_Property --
10580 --------------------------------
10582 function State_Has_Enabled_Property
return Boolean is
10583 Decl
: constant Node_Id
:= Parent
(Item_Id
);
10585 procedure Find_Simple_Properties
10586 (Has_External
: out Boolean;
10587 Has_Synchronous
: out Boolean);
10588 -- Extract the simple properties associated with declaration Decl
10590 function Is_Enabled_External_Property
return Boolean;
10591 -- Determine whether property Property appears within the external
10592 -- property list of declaration Decl, and return its status.
10594 ----------------------------
10595 -- Find_Simple_Properties --
10596 ----------------------------
10598 procedure Find_Simple_Properties
10599 (Has_External
: out Boolean;
10600 Has_Synchronous
: out Boolean)
10605 -- Assume that none of the properties are available
10607 Has_External
:= False;
10608 Has_Synchronous
:= False;
10610 Opt
:= First
(Expressions
(Decl
));
10611 while Present
(Opt
) loop
10612 if Nkind
(Opt
) = N_Identifier
then
10613 if Chars
(Opt
) = Name_External
then
10614 Has_External
:= True;
10616 elsif Chars
(Opt
) = Name_Synchronous
then
10617 Has_Synchronous
:= True;
10623 end Find_Simple_Properties
;
10625 ----------------------------------
10626 -- Is_Enabled_External_Property --
10627 ----------------------------------
10629 function Is_Enabled_External_Property
return Boolean is
10633 Prop_Nam
: Node_Id
;
10637 Opt
:= First
(Component_Associations
(Decl
));
10638 while Present
(Opt
) loop
10639 Opt_Nam
:= First
(Choices
(Opt
));
10641 if Nkind
(Opt_Nam
) = N_Identifier
10642 and then Chars
(Opt_Nam
) = Name_External
10644 Props
:= Expression
(Opt
);
10646 -- Multiple properties appear as an aggregate
10648 if Nkind
(Props
) = N_Aggregate
then
10650 -- Simple property form
10652 Prop
:= First
(Expressions
(Props
));
10653 while Present
(Prop
) loop
10654 if Chars
(Prop
) = Property
then
10661 -- Property with expression form
10663 Prop
:= First
(Component_Associations
(Props
));
10664 while Present
(Prop
) loop
10665 Prop_Nam
:= First
(Choices
(Prop
));
10667 -- The property can be represented in two ways:
10668 -- others => <value>
10669 -- <property> => <value>
10671 if Nkind
(Prop_Nam
) = N_Others_Choice
10672 or else (Nkind
(Prop_Nam
) = N_Identifier
10673 and then Chars
(Prop_Nam
) = Property
)
10675 return Is_True
(Expr_Value
(Expression
(Prop
)));
10684 return Chars
(Props
) = Property
;
10692 end Is_Enabled_External_Property
;
10696 Has_External
: Boolean;
10697 Has_Synchronous
: Boolean;
10699 -- Start of processing for State_Has_Enabled_Property
10702 -- The declaration of an external abstract state appears as an
10703 -- extension aggregate. If this is not the case, properties can
10706 if Nkind
(Decl
) /= N_Extension_Aggregate
then
10710 Find_Simple_Properties
(Has_External
, Has_Synchronous
);
10712 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10714 if Has_External
then
10717 -- Option External may enable or disable specific properties
10719 elsif Is_Enabled_External_Property
then
10722 -- Simple option Synchronous
10724 -- enables disables
10725 -- Asynch_Readers Effective_Reads
10726 -- Asynch_Writers Effective_Writes
10728 -- Note that both forms of External have higher precedence than
10729 -- Synchronous (SPARK RM 7.1.4(10)).
10731 elsif Has_Synchronous
then
10732 return Nam_In
(Property
, Name_Async_Readers
, Name_Async_Writers
);
10736 end State_Has_Enabled_Property
;
10738 -----------------------------------
10739 -- Variable_Has_Enabled_Property --
10740 -----------------------------------
10742 function Variable_Has_Enabled_Property
return Boolean is
10743 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
10744 -- Determine whether property pragma Prag (if present) denotes an
10745 -- enabled property.
10751 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
10755 if Present
(Prag
) then
10756 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
10758 -- The pragma has an optional Boolean expression, the related
10759 -- property is enabled only when the expression evaluates to
10762 if Present
(Arg1
) then
10763 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
)));
10765 -- Otherwise the lack of expression enables the property by
10772 -- The property was never set in the first place
10781 AR
: constant Node_Id
:=
10782 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
10783 AW
: constant Node_Id
:=
10784 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
10785 ER
: constant Node_Id
:=
10786 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
10787 EW
: constant Node_Id
:=
10788 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
10790 -- Start of processing for Variable_Has_Enabled_Property
10793 -- A non-effectively volatile object can never possess external
10796 if not Is_Effectively_Volatile
(Item_Id
) then
10799 -- External properties related to variables come in two flavors -
10800 -- explicit and implicit. The explicit case is characterized by the
10801 -- presence of a property pragma with an optional Boolean flag. The
10802 -- property is enabled when the flag evaluates to True or the flag is
10803 -- missing altogether.
10805 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
10808 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
10811 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
10814 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
10817 -- The implicit case lacks all property pragmas
10819 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
10820 if Is_Protected_Type
(Etype
(Item_Id
)) then
10821 return Protected_Object_Has_Enabled_Property
;
10829 end Variable_Has_Enabled_Property
;
10831 -- Start of processing for Has_Enabled_Property
10834 -- Abstract states and variables have a flexible scheme of specifying
10835 -- external properties.
10837 if Ekind
(Item_Id
) = E_Abstract_State
then
10838 return State_Has_Enabled_Property
;
10840 elsif Ekind
(Item_Id
) = E_Variable
then
10841 return Variable_Has_Enabled_Property
;
10843 -- By default, protected objects only have the properties Async_Readers
10844 -- and Async_Writers. If they have Part_Of components, they also inherit
10845 -- their properties Effective_Reads and Effective_Writes
10846 -- (SPARK RM 7.1.2(16)).
10848 elsif Ekind
(Item_Id
) = E_Protected_Object
then
10849 return Protected_Object_Has_Enabled_Property
;
10851 -- Otherwise a property is enabled when the related item is effectively
10855 return Is_Effectively_Volatile
(Item_Id
);
10857 end Has_Enabled_Property
;
10859 -------------------------------------
10860 -- Has_Full_Default_Initialization --
10861 -------------------------------------
10863 function Has_Full_Default_Initialization
(Typ
: Entity_Id
) return Boolean is
10867 -- A type subject to pragma Default_Initial_Condition may be fully
10868 -- default initialized depending on inheritance and the argument of
10869 -- the pragma. Since any type may act as the full view of a private
10870 -- type, this check must be performed prior to the specialized tests
10873 if Has_Fully_Default_Initializing_DIC_Pragma
(Typ
) then
10877 -- A scalar type is fully default initialized if it is subject to aspect
10880 if Is_Scalar_Type
(Typ
) then
10881 return Has_Default_Aspect
(Typ
);
10883 -- An array type is fully default initialized if its element type is
10884 -- scalar and the array type carries aspect Default_Component_Value or
10885 -- the element type is fully default initialized.
10887 elsif Is_Array_Type
(Typ
) then
10889 Has_Default_Aspect
(Typ
)
10890 or else Has_Full_Default_Initialization
(Component_Type
(Typ
));
10892 -- A protected type, record type, or type extension is fully default
10893 -- initialized if all its components either carry an initialization
10894 -- expression or have a type that is fully default initialized. The
10895 -- parent type of a type extension must be fully default initialized.
10897 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
10899 -- Inspect all entities defined in the scope of the type, looking for
10900 -- uninitialized components.
10902 Comp
:= First_Entity
(Typ
);
10903 while Present
(Comp
) loop
10904 if Ekind
(Comp
) = E_Component
10905 and then Comes_From_Source
(Comp
)
10906 and then No
(Expression
(Parent
(Comp
)))
10907 and then not Has_Full_Default_Initialization
(Etype
(Comp
))
10912 Next_Entity
(Comp
);
10915 -- Ensure that the parent type of a type extension is fully default
10918 if Etype
(Typ
) /= Typ
10919 and then not Has_Full_Default_Initialization
(Etype
(Typ
))
10924 -- If we get here, then all components and parent portion are fully
10925 -- default initialized.
10929 -- A task type is fully default initialized by default
10931 elsif Is_Task_Type
(Typ
) then
10934 -- Otherwise the type is not fully default initialized
10939 end Has_Full_Default_Initialization
;
10941 -----------------------------------------------
10942 -- Has_Fully_Default_Initializing_DIC_Pragma --
10943 -----------------------------------------------
10945 function Has_Fully_Default_Initializing_DIC_Pragma
10946 (Typ
: Entity_Id
) return Boolean
10952 -- A type that inherits pragma Default_Initial_Condition from a parent
10953 -- type is automatically fully default initialized.
10955 if Has_Inherited_DIC
(Typ
) then
10958 -- Otherwise the type is fully default initialized only when the pragma
10959 -- appears without an argument, or the argument is non-null.
10961 elsif Has_Own_DIC
(Typ
) then
10962 Prag
:= Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
10963 pragma Assert
(Present
(Prag
));
10964 Args
:= Pragma_Argument_Associations
(Prag
);
10966 -- The pragma appears without an argument in which case it defaults
10972 -- The pragma appears with a non-null expression
10974 elsif Nkind
(Get_Pragma_Arg
(First
(Args
))) /= N_Null
then
10980 end Has_Fully_Default_Initializing_DIC_Pragma
;
10982 --------------------
10983 -- Has_Infinities --
10984 --------------------
10986 function Has_Infinities
(E
: Entity_Id
) return Boolean is
10989 Is_Floating_Point_Type
(E
)
10990 and then Nkind
(Scalar_Range
(E
)) = N_Range
10991 and then Includes_Infinities
(Scalar_Range
(E
));
10992 end Has_Infinities
;
10994 --------------------
10995 -- Has_Interfaces --
10996 --------------------
10998 function Has_Interfaces
11000 Use_Full_View
: Boolean := True) return Boolean
11002 Typ
: Entity_Id
:= Base_Type
(T
);
11005 -- Handle concurrent types
11007 if Is_Concurrent_Type
(Typ
) then
11008 Typ
:= Corresponding_Record_Type
(Typ
);
11011 if not Present
(Typ
)
11012 or else not Is_Record_Type
(Typ
)
11013 or else not Is_Tagged_Type
(Typ
)
11018 -- Handle private types
11020 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
11021 Typ
:= Full_View
(Typ
);
11024 -- Handle concurrent record types
11026 if Is_Concurrent_Record_Type
(Typ
)
11027 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
11033 if Is_Interface
(Typ
)
11035 (Is_Record_Type
(Typ
)
11036 and then Present
(Interfaces
(Typ
))
11037 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
11042 exit when Etype
(Typ
) = Typ
11044 -- Handle private types
11046 or else (Present
(Full_View
(Etype
(Typ
)))
11047 and then Full_View
(Etype
(Typ
)) = Typ
)
11049 -- Protect frontend against wrong sources with cyclic derivations
11051 or else Etype
(Typ
) = T
;
11053 -- Climb to the ancestor type handling private types
11055 if Present
(Full_View
(Etype
(Typ
))) then
11056 Typ
:= Full_View
(Etype
(Typ
));
11058 Typ
:= Etype
(Typ
);
11063 end Has_Interfaces
;
11065 --------------------------
11066 -- Has_Max_Queue_Length --
11067 --------------------------
11069 function Has_Max_Queue_Length
(Id
: Entity_Id
) return Boolean is
11072 Ekind
(Id
) = E_Entry
11073 and then Present
(Get_Pragma
(Id
, Pragma_Max_Queue_Length
));
11074 end Has_Max_Queue_Length
;
11076 ---------------------------------
11077 -- Has_No_Obvious_Side_Effects --
11078 ---------------------------------
11080 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
11082 -- For now handle literals, constants, and non-volatile variables and
11083 -- expressions combining these with operators or short circuit forms.
11085 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
11088 elsif Nkind
(N
) = N_Character_Literal
then
11091 elsif Nkind
(N
) in N_Unary_Op
then
11092 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
11094 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
11095 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
11097 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
11099 elsif Nkind
(N
) = N_Expression_With_Actions
11100 and then Is_Empty_List
(Actions
(N
))
11102 return Has_No_Obvious_Side_Effects
(Expression
(N
));
11104 elsif Nkind
(N
) in N_Has_Entity
then
11105 return Present
(Entity
(N
))
11106 and then Ekind_In
(Entity
(N
), E_Variable
,
11108 E_Enumeration_Literal
,
11111 E_In_Out_Parameter
)
11112 and then not Is_Volatile
(Entity
(N
));
11117 end Has_No_Obvious_Side_Effects
;
11119 -----------------------------
11120 -- Has_Non_Null_Refinement --
11121 -----------------------------
11123 function Has_Non_Null_Refinement
(Id
: Entity_Id
) return Boolean is
11124 Constits
: Elist_Id
;
11127 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
11128 Constits
:= Refinement_Constituents
(Id
);
11130 -- For a refinement to be non-null, the first constituent must be
11131 -- anything other than null.
11135 and then Nkind
(Node
(First_Elmt
(Constits
))) /= N_Null
;
11136 end Has_Non_Null_Refinement
;
11138 -----------------------------
11139 -- Has_Non_Null_Statements --
11140 -----------------------------
11142 function Has_Non_Null_Statements
(L
: List_Id
) return Boolean is
11146 if Is_Non_Empty_List
(L
) then
11150 if Nkind
(Node
) /= N_Null_Statement
then
11155 exit when Node
= Empty
;
11160 end Has_Non_Null_Statements
;
11162 ----------------------------------
11163 -- Has_Non_Trivial_Precondition --
11164 ----------------------------------
11166 function Has_Non_Trivial_Precondition
(Subp
: Entity_Id
) return Boolean is
11167 Pre
: constant Node_Id
:= Find_Aspect
(Subp
, Aspect_Pre
);
11172 and then Class_Present
(Pre
)
11173 and then not Is_Entity_Name
(Expression
(Pre
));
11174 end Has_Non_Trivial_Precondition
;
11176 -------------------
11177 -- Has_Null_Body --
11178 -------------------
11180 function Has_Null_Body
(Proc_Id
: Entity_Id
) return Boolean is
11181 Body_Id
: Entity_Id
;
11188 Spec
:= Parent
(Proc_Id
);
11189 Decl
:= Parent
(Spec
);
11191 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11193 if Nkind
(Spec
) = N_Procedure_Specification
11194 and then Nkind
(Decl
) = N_Subprogram_Declaration
11196 Body_Id
:= Corresponding_Body
(Decl
);
11198 -- The body acts as a spec
11201 Body_Id
:= Proc_Id
;
11204 -- The body will be generated later
11206 if No
(Body_Id
) then
11210 Spec
:= Parent
(Body_Id
);
11211 Decl
:= Parent
(Spec
);
11214 (Nkind
(Spec
) = N_Procedure_Specification
11215 and then Nkind
(Decl
) = N_Subprogram_Body
);
11217 Stmt1
:= First
(Statements
(Handled_Statement_Sequence
(Decl
)));
11219 -- Look for a null statement followed by an optional return
11222 if Nkind
(Stmt1
) = N_Null_Statement
then
11223 Stmt2
:= Next
(Stmt1
);
11225 if Present
(Stmt2
) then
11226 return Nkind
(Stmt2
) = N_Simple_Return_Statement
;
11235 ------------------------
11236 -- Has_Null_Exclusion --
11237 ------------------------
11239 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
11242 when N_Access_Definition
11243 | N_Access_Function_Definition
11244 | N_Access_Procedure_Definition
11245 | N_Access_To_Object_Definition
11247 | N_Derived_Type_Definition
11248 | N_Function_Specification
11249 | N_Subtype_Declaration
11251 return Null_Exclusion_Present
(N
);
11253 when N_Component_Definition
11254 | N_Formal_Object_Declaration
11255 | N_Object_Renaming_Declaration
11257 if Present
(Subtype_Mark
(N
)) then
11258 return Null_Exclusion_Present
(N
);
11259 else pragma Assert
(Present
(Access_Definition
(N
)));
11260 return Null_Exclusion_Present
(Access_Definition
(N
));
11263 when N_Discriminant_Specification
=>
11264 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
11265 return Null_Exclusion_Present
(Discriminant_Type
(N
));
11267 return Null_Exclusion_Present
(N
);
11270 when N_Object_Declaration
=>
11271 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
11272 return Null_Exclusion_Present
(Object_Definition
(N
));
11274 return Null_Exclusion_Present
(N
);
11277 when N_Parameter_Specification
=>
11278 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
11279 return Null_Exclusion_Present
(Parameter_Type
(N
));
11281 return Null_Exclusion_Present
(N
);
11287 end Has_Null_Exclusion
;
11289 ------------------------
11290 -- Has_Null_Extension --
11291 ------------------------
11293 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
11294 B
: constant Entity_Id
:= Base_Type
(T
);
11299 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
11300 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
11302 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
11304 if Present
(Ext
) then
11305 if Null_Present
(Ext
) then
11308 Comps
:= Component_List
(Ext
);
11310 -- The null component list is rewritten during analysis to
11311 -- include the parent component. Any other component indicates
11312 -- that the extension was not originally null.
11314 return Null_Present
(Comps
)
11315 or else No
(Next
(First
(Component_Items
(Comps
))));
11324 end Has_Null_Extension
;
11326 -------------------------
11327 -- Has_Null_Refinement --
11328 -------------------------
11330 function Has_Null_Refinement
(Id
: Entity_Id
) return Boolean is
11331 Constits
: Elist_Id
;
11334 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
11335 Constits
:= Refinement_Constituents
(Id
);
11337 -- For a refinement to be null, the state's sole constituent must be a
11342 and then Nkind
(Node
(First_Elmt
(Constits
))) = N_Null
;
11343 end Has_Null_Refinement
;
11345 -------------------------------
11346 -- Has_Overriding_Initialize --
11347 -------------------------------
11349 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
11350 BT
: constant Entity_Id
:= Base_Type
(T
);
11354 if Is_Controlled
(BT
) then
11355 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
11358 elsif Present
(Primitive_Operations
(BT
)) then
11359 P
:= First_Elmt
(Primitive_Operations
(BT
));
11360 while Present
(P
) loop
11362 Init
: constant Entity_Id
:= Node
(P
);
11363 Formal
: constant Entity_Id
:= First_Formal
(Init
);
11365 if Ekind
(Init
) = E_Procedure
11366 and then Chars
(Init
) = Name_Initialize
11367 and then Comes_From_Source
(Init
)
11368 and then Present
(Formal
)
11369 and then Etype
(Formal
) = BT
11370 and then No
(Next_Formal
(Formal
))
11371 and then (Ada_Version
< Ada_2012
11372 or else not Null_Present
(Parent
(Init
)))
11382 -- Here if type itself does not have a non-null Initialize operation:
11383 -- check immediate ancestor.
11385 if Is_Derived_Type
(BT
)
11386 and then Has_Overriding_Initialize
(Etype
(BT
))
11393 end Has_Overriding_Initialize
;
11395 --------------------------------------
11396 -- Has_Preelaborable_Initialization --
11397 --------------------------------------
11399 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
11402 procedure Check_Components
(E
: Entity_Id
);
11403 -- Check component/discriminant chain, sets Has_PE False if a component
11404 -- or discriminant does not meet the preelaborable initialization rules.
11406 ----------------------
11407 -- Check_Components --
11408 ----------------------
11410 procedure Check_Components
(E
: Entity_Id
) is
11415 -- Loop through entities of record or protected type
11418 while Present
(Ent
) loop
11420 -- We are interested only in components and discriminants
11424 case Ekind
(Ent
) is
11425 when E_Component
=>
11427 -- Get default expression if any. If there is no declaration
11428 -- node, it means we have an internal entity. The parent and
11429 -- tag fields are examples of such entities. For such cases,
11430 -- we just test the type of the entity.
11432 if Present
(Declaration_Node
(Ent
)) then
11433 Exp
:= Expression
(Declaration_Node
(Ent
));
11436 when E_Discriminant
=>
11438 -- Note: for a renamed discriminant, the Declaration_Node
11439 -- may point to the one from the ancestor, and have a
11440 -- different expression, so use the proper attribute to
11441 -- retrieve the expression from the derived constraint.
11443 Exp
:= Discriminant_Default_Value
(Ent
);
11446 goto Check_Next_Entity
;
11449 -- A component has PI if it has no default expression and the
11450 -- component type has PI.
11453 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
11458 -- Require the default expression to be preelaborable
11460 elsif not Is_Preelaborable_Construct
(Exp
) then
11465 <<Check_Next_Entity
>>
11468 end Check_Components
;
11470 -- Start of processing for Has_Preelaborable_Initialization
11473 -- Immediate return if already marked as known preelaborable init. This
11474 -- covers types for which this function has already been called once
11475 -- and returned True (in which case the result is cached), and also
11476 -- types to which a pragma Preelaborable_Initialization applies.
11478 if Known_To_Have_Preelab_Init
(E
) then
11482 -- If the type is a subtype representing a generic actual type, then
11483 -- test whether its base type has preelaborable initialization since
11484 -- the subtype representing the actual does not inherit this attribute
11485 -- from the actual or formal. (but maybe it should???)
11487 if Is_Generic_Actual_Type
(E
) then
11488 return Has_Preelaborable_Initialization
(Base_Type
(E
));
11491 -- All elementary types have preelaborable initialization
11493 if Is_Elementary_Type
(E
) then
11496 -- Array types have PI if the component type has PI
11498 elsif Is_Array_Type
(E
) then
11499 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
11501 -- A derived type has preelaborable initialization if its parent type
11502 -- has preelaborable initialization and (in the case of a derived record
11503 -- extension) if the non-inherited components all have preelaborable
11504 -- initialization. However, a user-defined controlled type with an
11505 -- overriding Initialize procedure does not have preelaborable
11508 elsif Is_Derived_Type
(E
) then
11510 -- If the derived type is a private extension then it doesn't have
11511 -- preelaborable initialization.
11513 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
11517 -- First check whether ancestor type has preelaborable initialization
11519 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
11521 -- If OK, check extension components (if any)
11523 if Has_PE
and then Is_Record_Type
(E
) then
11524 Check_Components
(First_Entity
(E
));
11527 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11528 -- with a user defined Initialize procedure does not have PI. If
11529 -- the type is untagged, the control primitives come from a component
11530 -- that has already been checked.
11533 and then Is_Controlled
(E
)
11534 and then Is_Tagged_Type
(E
)
11535 and then Has_Overriding_Initialize
(E
)
11540 -- Private types not derived from a type having preelaborable init and
11541 -- that are not marked with pragma Preelaborable_Initialization do not
11542 -- have preelaborable initialization.
11544 elsif Is_Private_Type
(E
) then
11547 -- Record type has PI if it is non private and all components have PI
11549 elsif Is_Record_Type
(E
) then
11551 Check_Components
(First_Entity
(E
));
11553 -- Protected types must not have entries, and components must meet
11554 -- same set of rules as for record components.
11556 elsif Is_Protected_Type
(E
) then
11557 if Has_Entries
(E
) then
11561 Check_Components
(First_Entity
(E
));
11562 Check_Components
(First_Private_Entity
(E
));
11565 -- Type System.Address always has preelaborable initialization
11567 elsif Is_RTE
(E
, RE_Address
) then
11570 -- In all other cases, type does not have preelaborable initialization
11576 -- If type has preelaborable initialization, cache result
11579 Set_Known_To_Have_Preelab_Init
(E
);
11583 end Has_Preelaborable_Initialization
;
11589 function Has_Prefix
(N
: Node_Id
) return Boolean is
11592 Nkind_In
(N
, N_Attribute_Reference
,
11594 N_Explicit_Dereference
,
11595 N_Indexed_Component
,
11597 N_Selected_Component
,
11601 ---------------------------
11602 -- Has_Private_Component --
11603 ---------------------------
11605 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
11606 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
11607 Component
: Entity_Id
;
11610 if Error_Posted
(Type_Id
)
11611 or else Error_Posted
(Btype
)
11616 if Is_Class_Wide_Type
(Btype
) then
11617 Btype
:= Root_Type
(Btype
);
11620 if Is_Private_Type
(Btype
) then
11622 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
11625 if No
(Full_View
(Btype
)) then
11626 return not Is_Generic_Type
(Btype
)
11628 not Is_Generic_Type
(Root_Type
(Btype
));
11630 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
11633 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
11637 elsif Is_Array_Type
(Btype
) then
11638 return Has_Private_Component
(Component_Type
(Btype
));
11640 elsif Is_Record_Type
(Btype
) then
11641 Component
:= First_Component
(Btype
);
11642 while Present
(Component
) loop
11643 if Has_Private_Component
(Etype
(Component
)) then
11647 Next_Component
(Component
);
11652 elsif Is_Protected_Type
(Btype
)
11653 and then Present
(Corresponding_Record_Type
(Btype
))
11655 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
11660 end Has_Private_Component
;
11662 ----------------------
11663 -- Has_Signed_Zeros --
11664 ----------------------
11666 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
11668 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
11669 end Has_Signed_Zeros
;
11671 ------------------------------
11672 -- Has_Significant_Contract --
11673 ------------------------------
11675 function Has_Significant_Contract
(Subp_Id
: Entity_Id
) return Boolean is
11676 Subp_Nam
: constant Name_Id
:= Chars
(Subp_Id
);
11679 -- _Finalizer procedure
11681 if Subp_Nam
= Name_uFinalizer
then
11684 -- _Postconditions procedure
11686 elsif Subp_Nam
= Name_uPostconditions
then
11689 -- Predicate function
11691 elsif Ekind
(Subp_Id
) = E_Function
11692 and then Is_Predicate_Function
(Subp_Id
)
11698 elsif Get_TSS_Name
(Subp_Id
) /= TSS_Null
then
11704 end Has_Significant_Contract
;
11706 -----------------------------
11707 -- Has_Static_Array_Bounds --
11708 -----------------------------
11710 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
11711 All_Static
: Boolean;
11715 Examine_Array_Bounds
(Typ
, All_Static
, Dummy
);
11718 end Has_Static_Array_Bounds
;
11720 ---------------------------------------
11721 -- Has_Static_Non_Empty_Array_Bounds --
11722 ---------------------------------------
11724 function Has_Static_Non_Empty_Array_Bounds
(Typ
: Node_Id
) return Boolean is
11725 All_Static
: Boolean;
11726 Has_Empty
: Boolean;
11729 Examine_Array_Bounds
(Typ
, All_Static
, Has_Empty
);
11731 return All_Static
and not Has_Empty
;
11732 end Has_Static_Non_Empty_Array_Bounds
;
11738 function Has_Stream
(T
: Entity_Id
) return Boolean is
11745 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
11748 elsif Is_Array_Type
(T
) then
11749 return Has_Stream
(Component_Type
(T
));
11751 elsif Is_Record_Type
(T
) then
11752 E
:= First_Component
(T
);
11753 while Present
(E
) loop
11754 if Has_Stream
(Etype
(E
)) then
11757 Next_Component
(E
);
11763 elsif Is_Private_Type
(T
) then
11764 return Has_Stream
(Underlying_Type
(T
));
11775 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
11777 Get_Name_String
(Chars
(E
));
11778 return Name_Buffer
(Name_Len
) = Suffix
;
11785 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
11787 Get_Name_String
(Chars
(E
));
11788 Add_Char_To_Name_Buffer
(Suffix
);
11792 -------------------
11793 -- Remove_Suffix --
11794 -------------------
11796 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
11798 pragma Assert
(Has_Suffix
(E
, Suffix
));
11799 Get_Name_String
(Chars
(E
));
11800 Name_Len
:= Name_Len
- 1;
11804 ----------------------------------
11805 -- Replace_Null_By_Null_Address --
11806 ----------------------------------
11808 procedure Replace_Null_By_Null_Address
(N
: Node_Id
) is
11809 procedure Replace_Null_Operand
(Op
: Node_Id
; Other_Op
: Node_Id
);
11810 -- Replace operand Op with a reference to Null_Address when the operand
11811 -- denotes a null Address. Other_Op denotes the other operand.
11813 --------------------------
11814 -- Replace_Null_Operand --
11815 --------------------------
11817 procedure Replace_Null_Operand
(Op
: Node_Id
; Other_Op
: Node_Id
) is
11819 -- Check the type of the complementary operand since the N_Null node
11820 -- has not been decorated yet.
11822 if Nkind
(Op
) = N_Null
11823 and then Is_Descendant_Of_Address
(Etype
(Other_Op
))
11825 Rewrite
(Op
, New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(Op
)));
11827 end Replace_Null_Operand
;
11829 -- Start of processing for Replace_Null_By_Null_Address
11832 pragma Assert
(Relaxed_RM_Semantics
);
11833 pragma Assert
(Nkind_In
(N
, N_Null
,
11841 if Nkind
(N
) = N_Null
then
11842 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
11846 L
: constant Node_Id
:= Left_Opnd
(N
);
11847 R
: constant Node_Id
:= Right_Opnd
(N
);
11850 Replace_Null_Operand
(L
, Other_Op
=> R
);
11851 Replace_Null_Operand
(R
, Other_Op
=> L
);
11854 end Replace_Null_By_Null_Address
;
11856 --------------------------
11857 -- Has_Tagged_Component --
11858 --------------------------
11860 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
11864 if Is_Private_Type
(Typ
) and then Present
(Underlying_Type
(Typ
)) then
11865 return Has_Tagged_Component
(Underlying_Type
(Typ
));
11867 elsif Is_Array_Type
(Typ
) then
11868 return Has_Tagged_Component
(Component_Type
(Typ
));
11870 elsif Is_Tagged_Type
(Typ
) then
11873 elsif Is_Record_Type
(Typ
) then
11874 Comp
:= First_Component
(Typ
);
11875 while Present
(Comp
) loop
11876 if Has_Tagged_Component
(Etype
(Comp
)) then
11880 Next_Component
(Comp
);
11888 end Has_Tagged_Component
;
11890 -----------------------------
11891 -- Has_Undefined_Reference --
11892 -----------------------------
11894 function Has_Undefined_Reference
(Expr
: Node_Id
) return Boolean is
11895 Has_Undef_Ref
: Boolean := False;
11896 -- Flag set when expression Expr contains at least one undefined
11899 function Is_Undefined_Reference
(N
: Node_Id
) return Traverse_Result
;
11900 -- Determine whether N denotes a reference and if it does, whether it is
11903 ----------------------------
11904 -- Is_Undefined_Reference --
11905 ----------------------------
11907 function Is_Undefined_Reference
(N
: Node_Id
) return Traverse_Result
is
11909 if Is_Entity_Name
(N
)
11910 and then Present
(Entity
(N
))
11911 and then Entity
(N
) = Any_Id
11913 Has_Undef_Ref
:= True;
11918 end Is_Undefined_Reference
;
11920 procedure Find_Undefined_References
is
11921 new Traverse_Proc
(Is_Undefined_Reference
);
11923 -- Start of processing for Has_Undefined_Reference
11926 Find_Undefined_References
(Expr
);
11928 return Has_Undef_Ref
;
11929 end Has_Undefined_Reference
;
11931 ----------------------------
11932 -- Has_Volatile_Component --
11933 ----------------------------
11935 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
11939 if Has_Volatile_Components
(Typ
) then
11942 elsif Is_Array_Type
(Typ
) then
11943 return Is_Volatile
(Component_Type
(Typ
));
11945 elsif Is_Record_Type
(Typ
) then
11946 Comp
:= First_Component
(Typ
);
11947 while Present
(Comp
) loop
11948 if Is_Volatile_Object
(Comp
) then
11952 Comp
:= Next_Component
(Comp
);
11957 end Has_Volatile_Component
;
11959 -------------------------
11960 -- Implementation_Kind --
11961 -------------------------
11963 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
11964 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
11967 pragma Assert
(Present
(Impl_Prag
));
11968 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
11969 return Chars
(Get_Pragma_Arg
(Arg
));
11970 end Implementation_Kind
;
11972 --------------------------
11973 -- Implements_Interface --
11974 --------------------------
11976 function Implements_Interface
11977 (Typ_Ent
: Entity_Id
;
11978 Iface_Ent
: Entity_Id
;
11979 Exclude_Parents
: Boolean := False) return Boolean
11981 Ifaces_List
: Elist_Id
;
11983 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
11984 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
11987 if Is_Class_Wide_Type
(Typ
) then
11988 Typ
:= Root_Type
(Typ
);
11991 if not Has_Interfaces
(Typ
) then
11995 if Is_Class_Wide_Type
(Iface
) then
11996 Iface
:= Root_Type
(Iface
);
11999 Collect_Interfaces
(Typ
, Ifaces_List
);
12001 Elmt
:= First_Elmt
(Ifaces_List
);
12002 while Present
(Elmt
) loop
12003 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
12004 and then Exclude_Parents
12008 elsif Node
(Elmt
) = Iface
then
12016 end Implements_Interface
;
12018 ------------------------------------
12019 -- In_Assertion_Expression_Pragma --
12020 ------------------------------------
12022 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
12024 Prag
: Node_Id
:= Empty
;
12027 -- Climb the parent chain looking for an enclosing pragma
12030 while Present
(Par
) loop
12031 if Nkind
(Par
) = N_Pragma
then
12035 -- Precondition-like pragmas are expanded into if statements, check
12036 -- the original node instead.
12038 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
12039 Prag
:= Original_Node
(Par
);
12042 -- The expansion of attribute 'Old generates a constant to capture
12043 -- the result of the prefix. If the parent traversal reaches
12044 -- one of these constants, then the node technically came from a
12045 -- postcondition-like pragma. Note that the Ekind is not tested here
12046 -- because N may be the expression of an object declaration which is
12047 -- currently being analyzed. Such objects carry Ekind of E_Void.
12049 elsif Nkind
(Par
) = N_Object_Declaration
12050 and then Constant_Present
(Par
)
12051 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
12055 -- Prevent the search from going too far
12057 elsif Is_Body_Or_Package_Declaration
(Par
) then
12061 Par
:= Parent
(Par
);
12066 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
12067 end In_Assertion_Expression_Pragma
;
12069 ----------------------
12070 -- In_Generic_Scope --
12071 ----------------------
12073 function In_Generic_Scope
(E
: Entity_Id
) return Boolean is
12078 while Present
(S
) and then S
/= Standard_Standard
loop
12079 if Is_Generic_Unit
(S
) then
12087 end In_Generic_Scope
;
12093 function In_Instance
return Boolean is
12094 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
12098 S
:= Current_Scope
;
12099 while Present
(S
) and then S
/= Standard_Standard
loop
12100 if Is_Generic_Instance
(S
) then
12102 -- A child instance is always compiled in the context of a parent
12103 -- instance. Nevertheless, the actuals are not analyzed in an
12104 -- instance context. We detect this case by examining the current
12105 -- compilation unit, which must be a child instance, and checking
12106 -- that it is not currently on the scope stack.
12108 if Is_Child_Unit
(Curr_Unit
)
12109 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
12110 N_Package_Instantiation
12111 and then not In_Open_Scopes
(Curr_Unit
)
12125 ----------------------
12126 -- In_Instance_Body --
12127 ----------------------
12129 function In_Instance_Body
return Boolean is
12133 S
:= Current_Scope
;
12134 while Present
(S
) and then S
/= Standard_Standard
loop
12135 if Ekind_In
(S
, E_Function
, E_Procedure
)
12136 and then Is_Generic_Instance
(S
)
12140 elsif Ekind
(S
) = E_Package
12141 and then In_Package_Body
(S
)
12142 and then Is_Generic_Instance
(S
)
12151 end In_Instance_Body
;
12153 -----------------------------
12154 -- In_Instance_Not_Visible --
12155 -----------------------------
12157 function In_Instance_Not_Visible
return Boolean is
12161 S
:= Current_Scope
;
12162 while Present
(S
) and then S
/= Standard_Standard
loop
12163 if Ekind_In
(S
, E_Function
, E_Procedure
)
12164 and then Is_Generic_Instance
(S
)
12168 elsif Ekind
(S
) = E_Package
12169 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
12170 and then Is_Generic_Instance
(S
)
12179 end In_Instance_Not_Visible
;
12181 ------------------------------
12182 -- In_Instance_Visible_Part --
12183 ------------------------------
12185 function In_Instance_Visible_Part
12186 (Id
: Entity_Id
:= Current_Scope
) return Boolean
12192 while Present
(Inst
) and then Inst
/= Standard_Standard
loop
12193 if Ekind
(Inst
) = E_Package
12194 and then Is_Generic_Instance
(Inst
)
12195 and then not In_Package_Body
(Inst
)
12196 and then not In_Private_Part
(Inst
)
12201 Inst
:= Scope
(Inst
);
12205 end In_Instance_Visible_Part
;
12207 ---------------------
12208 -- In_Package_Body --
12209 ---------------------
12211 function In_Package_Body
return Boolean is
12215 S
:= Current_Scope
;
12216 while Present
(S
) and then S
/= Standard_Standard
loop
12217 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
12225 end In_Package_Body
;
12227 --------------------------
12228 -- In_Pragma_Expression --
12229 --------------------------
12231 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
12238 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
12244 end In_Pragma_Expression
;
12246 ---------------------------
12247 -- In_Pre_Post_Condition --
12248 ---------------------------
12250 function In_Pre_Post_Condition
(N
: Node_Id
) return Boolean is
12252 Prag
: Node_Id
:= Empty
;
12253 Prag_Id
: Pragma_Id
;
12256 -- Climb the parent chain looking for an enclosing pragma
12259 while Present
(Par
) loop
12260 if Nkind
(Par
) = N_Pragma
then
12264 -- Prevent the search from going too far
12266 elsif Is_Body_Or_Package_Declaration
(Par
) then
12270 Par
:= Parent
(Par
);
12273 if Present
(Prag
) then
12274 Prag_Id
:= Get_Pragma_Id
(Prag
);
12277 Prag_Id
= Pragma_Post
12278 or else Prag_Id
= Pragma_Post_Class
12279 or else Prag_Id
= Pragma_Postcondition
12280 or else Prag_Id
= Pragma_Pre
12281 or else Prag_Id
= Pragma_Pre_Class
12282 or else Prag_Id
= Pragma_Precondition
;
12284 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12289 end In_Pre_Post_Condition
;
12291 -------------------------------------
12292 -- In_Reverse_Storage_Order_Object --
12293 -------------------------------------
12295 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
12297 Btyp
: Entity_Id
:= Empty
;
12300 -- Climb up indexed components
12304 case Nkind
(Pref
) is
12305 when N_Selected_Component
=>
12306 Pref
:= Prefix
(Pref
);
12309 when N_Indexed_Component
=>
12310 Pref
:= Prefix
(Pref
);
12318 if Present
(Pref
) then
12319 Btyp
:= Base_Type
(Etype
(Pref
));
12322 return Present
(Btyp
)
12323 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
12324 and then Reverse_Storage_Order
(Btyp
);
12325 end In_Reverse_Storage_Order_Object
;
12327 ------------------------------
12328 -- In_Same_Declarative_Part --
12329 ------------------------------
12331 function In_Same_Declarative_Part
12332 (Context
: Node_Id
;
12333 N
: Node_Id
) return Boolean
12335 Cont
: Node_Id
:= Context
;
12339 if Nkind
(Cont
) = N_Compilation_Unit_Aux
then
12340 Cont
:= Parent
(Cont
);
12344 while Present
(Nod
) loop
12348 elsif Nkind_In
(Nod
, N_Accept_Statement
,
12350 N_Compilation_Unit
,
12353 N_Package_Declaration
,
12360 elsif Nkind
(Nod
) = N_Subunit
then
12361 Nod
:= Corresponding_Stub
(Nod
);
12364 Nod
:= Parent
(Nod
);
12369 end In_Same_Declarative_Part
;
12371 --------------------------------------
12372 -- In_Subprogram_Or_Concurrent_Unit --
12373 --------------------------------------
12375 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
12380 -- Use scope chain to check successively outer scopes
12382 E
:= Current_Scope
;
12386 if K
in Subprogram_Kind
12387 or else K
in Concurrent_Kind
12388 or else K
in Generic_Subprogram_Kind
12392 elsif E
= Standard_Standard
then
12398 end In_Subprogram_Or_Concurrent_Unit
;
12404 function In_Subtree
(N
: Node_Id
; Root
: Node_Id
) return Boolean is
12409 while Present
(Curr
) loop
12410 if Curr
= Root
then
12414 Curr
:= Parent
(Curr
);
12424 function In_Subtree
12427 Root2
: Node_Id
) return Boolean
12433 while Present
(Curr
) loop
12434 if Curr
= Root1
or else Curr
= Root2
then
12438 Curr
:= Parent
(Curr
);
12444 ---------------------
12445 -- In_Visible_Part --
12446 ---------------------
12448 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
12450 return Is_Package_Or_Generic_Package
(Scope_Id
)
12451 and then In_Open_Scopes
(Scope_Id
)
12452 and then not In_Package_Body
(Scope_Id
)
12453 and then not In_Private_Part
(Scope_Id
);
12454 end In_Visible_Part
;
12456 --------------------------------
12457 -- Incomplete_Or_Partial_View --
12458 --------------------------------
12460 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
12461 function Inspect_Decls
12463 Taft
: Boolean := False) return Entity_Id
;
12464 -- Check whether a declarative region contains the incomplete or partial
12467 -------------------
12468 -- Inspect_Decls --
12469 -------------------
12471 function Inspect_Decls
12473 Taft
: Boolean := False) return Entity_Id
12479 Decl
:= First
(Decls
);
12480 while Present
(Decl
) loop
12483 -- The partial view of a Taft-amendment type is an incomplete
12487 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
12488 Match
:= Defining_Identifier
(Decl
);
12491 -- Otherwise look for a private type whose full view matches the
12492 -- input type. Note that this checks full_type_declaration nodes
12493 -- to account for derivations from a private type where the type
12494 -- declaration hold the partial view and the full view is an
12497 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
12498 N_Private_Extension_Declaration
,
12499 N_Private_Type_Declaration
)
12501 Match
:= Defining_Identifier
(Decl
);
12504 -- Guard against unanalyzed entities
12507 and then Is_Type
(Match
)
12508 and then Present
(Full_View
(Match
))
12509 and then Full_View
(Match
) = Id
12524 -- Start of processing for Incomplete_Or_Partial_View
12527 -- Deferred constant or incomplete type case
12529 Prev
:= Current_Entity_In_Scope
(Id
);
12532 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
12533 and then Present
(Full_View
(Prev
))
12534 and then Full_View
(Prev
) = Id
12539 -- Private or Taft amendment type case
12542 Pkg
: constant Entity_Id
:= Scope
(Id
);
12543 Pkg_Decl
: Node_Id
:= Pkg
;
12547 and then Ekind_In
(Pkg
, E_Generic_Package
, E_Package
)
12549 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
12550 Pkg_Decl
:= Parent
(Pkg_Decl
);
12553 -- It is knows that Typ has a private view, look for it in the
12554 -- visible declarations of the enclosing scope. A special case
12555 -- of this is when the two views have been exchanged - the full
12556 -- appears earlier than the private.
12558 if Has_Private_Declaration
(Id
) then
12559 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
12561 -- Exchanged view case, look in the private declarations
12564 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
12569 -- Otherwise if this is the package body, then Typ is a potential
12570 -- Taft amendment type. The incomplete view should be located in
12571 -- the private declarations of the enclosing scope.
12573 elsif In_Package_Body
(Pkg
) then
12574 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
12579 -- The type has no incomplete or private view
12582 end Incomplete_Or_Partial_View
;
12584 ---------------------------------------
12585 -- Incomplete_View_From_Limited_With --
12586 ---------------------------------------
12588 function Incomplete_View_From_Limited_With
12589 (Typ
: Entity_Id
) return Entity_Id
12592 -- It might make sense to make this an attribute in Einfo, and set it
12593 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12594 -- slots for new attributes, and it seems a bit simpler to just search
12595 -- the Limited_View (if it exists) for an incomplete type whose
12596 -- Non_Limited_View is Typ.
12598 if Ekind
(Scope
(Typ
)) = E_Package
12599 and then Present
(Limited_View
(Scope
(Typ
)))
12602 Ent
: Entity_Id
:= First_Entity
(Limited_View
(Scope
(Typ
)));
12604 while Present
(Ent
) loop
12605 if Ekind
(Ent
) in Incomplete_Kind
12606 and then Non_Limited_View
(Ent
) = Typ
12611 Ent
:= Next_Entity
(Ent
);
12617 end Incomplete_View_From_Limited_With
;
12619 ----------------------------------
12620 -- Indexed_Component_Bit_Offset --
12621 ----------------------------------
12623 function Indexed_Component_Bit_Offset
(N
: Node_Id
) return Uint
is
12624 Exp
: constant Node_Id
:= First
(Expressions
(N
));
12625 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
12626 Off
: constant Uint
:= Component_Size
(Typ
);
12630 -- Return early if the component size is not known or variable
12632 if Off
= No_Uint
or else Off
< Uint_0
then
12636 -- Deal with the degenerate case of an empty component
12638 if Off
= Uint_0
then
12642 -- Check that both the index value and the low bound are known
12644 if not Compile_Time_Known_Value
(Exp
) then
12648 Ind
:= First_Index
(Typ
);
12653 if Nkind
(Ind
) = N_Subtype_Indication
then
12654 Ind
:= Constraint
(Ind
);
12656 if Nkind
(Ind
) = N_Range_Constraint
then
12657 Ind
:= Range_Expression
(Ind
);
12661 if Nkind
(Ind
) /= N_Range
12662 or else not Compile_Time_Known_Value
(Low_Bound
(Ind
))
12667 -- Return the scaled offset
12669 return Off
* (Expr_Value
(Exp
) - Expr_Value
(Low_Bound
((Ind
))));
12670 end Indexed_Component_Bit_Offset
;
12672 ----------------------------
12673 -- Inherit_Rep_Item_Chain --
12674 ----------------------------
12676 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
12678 Next_Item
: Node_Id
;
12681 -- There are several inheritance scenarios to consider depending on
12682 -- whether both types have rep item chains and whether the destination
12683 -- type already inherits part of the source type's rep item chain.
12685 -- 1) The source type lacks a rep item chain
12686 -- From_Typ ---> Empty
12688 -- Typ --------> Item (or Empty)
12690 -- In this case inheritance cannot take place because there are no items
12693 -- 2) The destination type lacks a rep item chain
12694 -- From_Typ ---> Item ---> ...
12696 -- Typ --------> Empty
12698 -- Inheritance takes place by setting the First_Rep_Item of the
12699 -- destination type to the First_Rep_Item of the source type.
12700 -- From_Typ ---> Item ---> ...
12702 -- Typ -----------+
12704 -- 3.1) Both source and destination types have at least one rep item.
12705 -- The destination type does NOT inherit a rep item from the source
12707 -- From_Typ ---> Item ---> Item
12709 -- Typ --------> Item ---> Item
12711 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12712 -- of the destination type to the First_Rep_Item of the source type.
12713 -- From_Typ -------------------> Item ---> Item
12715 -- Typ --------> Item ---> Item --+
12717 -- 3.2) Both source and destination types have at least one rep item.
12718 -- The destination type DOES inherit part of the rep item chain of the
12720 -- From_Typ ---> Item ---> Item ---> Item
12722 -- Typ --------> Item ------+
12724 -- This rare case arises when the full view of a private extension must
12725 -- inherit the rep item chain from the full view of its parent type and
12726 -- the full view of the parent type contains extra rep items. Currently
12727 -- only invariants may lead to such form of inheritance.
12729 -- type From_Typ is tagged private
12730 -- with Type_Invariant'Class => Item_2;
12732 -- type Typ is new From_Typ with private
12733 -- with Type_Invariant => Item_4;
12735 -- At this point the rep item chains contain the following items
12737 -- From_Typ -----------> Item_2 ---> Item_3
12739 -- Typ --------> Item_4 --+
12741 -- The full views of both types may introduce extra invariants
12743 -- type From_Typ is tagged null record
12744 -- with Type_Invariant => Item_1;
12746 -- type Typ is new From_Typ with null record;
12748 -- The full view of Typ would have to inherit any new rep items added to
12749 -- the full view of From_Typ.
12751 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12753 -- Typ --------> Item_4 --+
12755 -- To achieve this form of inheritance, the destination type must first
12756 -- sever the link between its own rep chain and that of the source type,
12757 -- then inheritance 3.1 takes place.
12759 -- Case 1: The source type lacks a rep item chain
12761 if No
(First_Rep_Item
(From_Typ
)) then
12764 -- Case 2: The destination type lacks a rep item chain
12766 elsif No
(First_Rep_Item
(Typ
)) then
12767 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
12769 -- Case 3: Both the source and destination types have at least one rep
12770 -- item. Traverse the rep item chain of the destination type to find the
12775 Next_Item
:= First_Rep_Item
(Typ
);
12776 while Present
(Next_Item
) loop
12778 -- Detect a link between the destination type's rep chain and that
12779 -- of the source type. There are two possibilities:
12784 -- From_Typ ---> Item_1 --->
12786 -- Typ -----------+
12793 -- From_Typ ---> Item_1 ---> Item_2 --->
12795 -- Typ --------> Item_3 ------+
12799 if Has_Rep_Item
(From_Typ
, Next_Item
) then
12804 Next_Item
:= Next_Rep_Item
(Next_Item
);
12807 -- Inherit the source type's rep item chain
12809 if Present
(Item
) then
12810 Set_Next_Rep_Item
(Item
, First_Rep_Item
(From_Typ
));
12812 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
12815 end Inherit_Rep_Item_Chain
;
12817 ------------------------------------
12818 -- Inherits_From_Tagged_Full_View --
12819 ------------------------------------
12821 function Inherits_From_Tagged_Full_View
(Typ
: Entity_Id
) return Boolean is
12823 return Is_Private_Type
(Typ
)
12824 and then Present
(Full_View
(Typ
))
12825 and then Is_Private_Type
(Full_View
(Typ
))
12826 and then not Is_Tagged_Type
(Full_View
(Typ
))
12827 and then Present
(Underlying_Type
(Full_View
(Typ
)))
12828 and then Is_Tagged_Type
(Underlying_Type
(Full_View
(Typ
)));
12829 end Inherits_From_Tagged_Full_View
;
12831 ---------------------------------
12832 -- Insert_Explicit_Dereference --
12833 ---------------------------------
12835 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
12836 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
12837 Ent
: Entity_Id
:= Empty
;
12844 Save_Interps
(N
, New_Prefix
);
12847 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
12848 Prefix
=> New_Prefix
));
12850 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
12852 if Is_Overloaded
(New_Prefix
) then
12854 -- The dereference is also overloaded, and its interpretations are
12855 -- the designated types of the interpretations of the original node.
12857 Set_Etype
(N
, Any_Type
);
12859 Get_First_Interp
(New_Prefix
, I
, It
);
12860 while Present
(It
.Nam
) loop
12863 if Is_Access_Type
(T
) then
12864 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
12867 Get_Next_Interp
(I
, It
);
12873 -- Prefix is unambiguous: mark the original prefix (which might
12874 -- Come_From_Source) as a reference, since the new (relocated) one
12875 -- won't be taken into account.
12877 if Is_Entity_Name
(New_Prefix
) then
12878 Ent
:= Entity
(New_Prefix
);
12879 Pref
:= New_Prefix
;
12881 -- For a retrieval of a subcomponent of some composite object,
12882 -- retrieve the ultimate entity if there is one.
12884 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
12885 N_Indexed_Component
)
12887 Pref
:= Prefix
(New_Prefix
);
12888 while Present
(Pref
)
12889 and then Nkind_In
(Pref
, N_Selected_Component
,
12890 N_Indexed_Component
)
12892 Pref
:= Prefix
(Pref
);
12895 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
12896 Ent
:= Entity
(Pref
);
12900 -- Place the reference on the entity node
12902 if Present
(Ent
) then
12903 Generate_Reference
(Ent
, Pref
);
12906 end Insert_Explicit_Dereference
;
12908 ------------------------------------------
12909 -- Inspect_Deferred_Constant_Completion --
12910 ------------------------------------------
12912 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
12916 Decl
:= First
(Decls
);
12917 while Present
(Decl
) loop
12919 -- Deferred constant signature
12921 if Nkind
(Decl
) = N_Object_Declaration
12922 and then Constant_Present
(Decl
)
12923 and then No
(Expression
(Decl
))
12925 -- No need to check internally generated constants
12927 and then Comes_From_Source
(Decl
)
12929 -- The constant is not completed. A full object declaration or a
12930 -- pragma Import complete a deferred constant.
12932 and then not Has_Completion
(Defining_Identifier
(Decl
))
12935 ("constant declaration requires initialization expression",
12936 Defining_Identifier
(Decl
));
12939 Decl
:= Next
(Decl
);
12941 end Inspect_Deferred_Constant_Completion
;
12943 -------------------------------
12944 -- Install_Elaboration_Model --
12945 -------------------------------
12947 procedure Install_Elaboration_Model
(Unit_Id
: Entity_Id
) is
12948 function Find_Elaboration_Checks_Pragma
(L
: List_Id
) return Node_Id
;
12949 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
12950 -- Empty if there is no such pragma.
12952 ------------------------------------
12953 -- Find_Elaboration_Checks_Pragma --
12954 ------------------------------------
12956 function Find_Elaboration_Checks_Pragma
(L
: List_Id
) return Node_Id
is
12961 while Present
(Item
) loop
12962 if Nkind
(Item
) = N_Pragma
12963 and then Pragma_Name
(Item
) = Name_Elaboration_Checks
12972 end Find_Elaboration_Checks_Pragma
;
12981 -- Start of processing for Install_Elaboration_Model
12984 -- Nothing to do when the unit does not exist
12986 if No
(Unit_Id
) then
12990 Unit
:= Parent
(Unit_Declaration_Node
(Unit_Id
));
12992 -- Nothing to do when the unit is not a library unit
12994 if Nkind
(Unit
) /= N_Compilation_Unit
then
12998 Prag
:= Find_Elaboration_Checks_Pragma
(Context_Items
(Unit
));
13000 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13001 -- elaboration model as specified by the pragma.
13003 if Present
(Prag
) then
13004 Args
:= Pragma_Argument_Associations
(Prag
);
13006 -- Guard against an illegal pragma. The sole argument must be an
13007 -- identifier which specifies either Dynamic or Static model.
13009 if Present
(Args
) then
13010 Model
:= Get_Pragma_Arg
(First
(Args
));
13012 if Nkind
(Model
) = N_Identifier
then
13013 Dynamic_Elaboration_Checks
:= Chars
(Model
) = Name_Dynamic
;
13017 end Install_Elaboration_Model
;
13019 -----------------------------
13020 -- Install_Generic_Formals --
13021 -----------------------------
13023 procedure Install_Generic_Formals
(Subp_Id
: Entity_Id
) is
13027 pragma Assert
(Is_Generic_Subprogram
(Subp_Id
));
13029 E
:= First_Entity
(Subp_Id
);
13030 while Present
(E
) loop
13031 Install_Entity
(E
);
13034 end Install_Generic_Formals
;
13036 ------------------------
13037 -- Install_SPARK_Mode --
13038 ------------------------
13040 procedure Install_SPARK_Mode
(Mode
: SPARK_Mode_Type
; Prag
: Node_Id
) is
13042 SPARK_Mode
:= Mode
;
13043 SPARK_Mode_Pragma
:= Prag
;
13044 end Install_SPARK_Mode
;
13046 --------------------------
13047 -- Invalid_Scalar_Value --
13048 --------------------------
13050 function Invalid_Scalar_Value
13052 Scal_Typ
: Scalar_Id
) return Node_Id
13054 function Invalid_Binder_Value
return Node_Id
;
13055 -- Return a reference to the corresponding invalid value for type
13056 -- Scal_Typ as defined in unit System.Scalar_Values.
13058 function Invalid_Float_Value
return Node_Id
;
13059 -- Return the invalid value of float type Scal_Typ
13061 function Invalid_Integer_Value
return Node_Id
;
13062 -- Return the invalid value of integer type Scal_Typ
13064 procedure Set_Invalid_Binder_Values
;
13065 -- Set the contents of collection Invalid_Binder_Values
13067 --------------------------
13068 -- Invalid_Binder_Value --
13069 --------------------------
13071 function Invalid_Binder_Value
return Node_Id
is
13072 Val_Id
: Entity_Id
;
13075 -- Initialize the collection of invalid binder values the first time
13078 Set_Invalid_Binder_Values
;
13080 -- Obtain the corresponding variable from System.Scalar_Values which
13081 -- holds the invalid value for this type.
13083 Val_Id
:= Invalid_Binder_Values
(Scal_Typ
);
13084 pragma Assert
(Present
(Val_Id
));
13086 return New_Occurrence_Of
(Val_Id
, Loc
);
13087 end Invalid_Binder_Value
;
13089 -------------------------
13090 -- Invalid_Float_Value --
13091 -------------------------
13093 function Invalid_Float_Value
return Node_Id
is
13094 Value
: constant Ureal
:= Invalid_Floats
(Scal_Typ
);
13097 -- Pragma Invalid_Scalars did not specify an invalid value for this
13098 -- type. Fall back to the value provided by the binder.
13100 if Value
= No_Ureal
then
13101 return Invalid_Binder_Value
;
13103 return Make_Real_Literal
(Loc
, Realval
=> Value
);
13105 end Invalid_Float_Value
;
13107 ---------------------------
13108 -- Invalid_Integer_Value --
13109 ---------------------------
13111 function Invalid_Integer_Value
return Node_Id
is
13112 Value
: constant Uint
:= Invalid_Integers
(Scal_Typ
);
13115 -- Pragma Invalid_Scalars did not specify an invalid value for this
13116 -- type. Fall back to the value provided by the binder.
13118 if Value
= No_Uint
then
13119 return Invalid_Binder_Value
;
13121 return Make_Integer_Literal
(Loc
, Intval
=> Value
);
13123 end Invalid_Integer_Value
;
13125 -------------------------------
13126 -- Set_Invalid_Binder_Values --
13127 -------------------------------
13129 procedure Set_Invalid_Binder_Values
is
13131 if not Invalid_Binder_Values_Set
then
13132 Invalid_Binder_Values_Set
:= True;
13134 -- Initialize the contents of the collection once since RTE calls
13137 Invalid_Binder_Values
:=
13138 (Name_Short_Float
=> RTE
(RE_IS_Isf
),
13139 Name_Float
=> RTE
(RE_IS_Ifl
),
13140 Name_Long_Float
=> RTE
(RE_IS_Ilf
),
13141 Name_Long_Long_Float
=> RTE
(RE_IS_Ill
),
13142 Name_Signed_8
=> RTE
(RE_IS_Is1
),
13143 Name_Signed_16
=> RTE
(RE_IS_Is2
),
13144 Name_Signed_32
=> RTE
(RE_IS_Is4
),
13145 Name_Signed_64
=> RTE
(RE_IS_Is8
),
13146 Name_Unsigned_8
=> RTE
(RE_IS_Iu1
),
13147 Name_Unsigned_16
=> RTE
(RE_IS_Iu2
),
13148 Name_Unsigned_32
=> RTE
(RE_IS_Iu4
),
13149 Name_Unsigned_64
=> RTE
(RE_IS_Iu8
));
13151 end Set_Invalid_Binder_Values
;
13153 -- Start of processing for Invalid_Scalar_Value
13156 if Scal_Typ
in Float_Scalar_Id
then
13157 return Invalid_Float_Value
;
13159 else pragma Assert
(Scal_Typ
in Integer_Scalar_Id
);
13160 return Invalid_Integer_Value
;
13162 end Invalid_Scalar_Value
;
13164 -----------------------------
13165 -- Is_Actual_Out_Parameter --
13166 -----------------------------
13168 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
13169 Formal
: Entity_Id
;
13172 Find_Actual
(N
, Formal
, Call
);
13173 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
13174 end Is_Actual_Out_Parameter
;
13176 -------------------------
13177 -- Is_Actual_Parameter --
13178 -------------------------
13180 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
13181 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
13185 when N_Parameter_Association
=>
13186 return N
= Explicit_Actual_Parameter
(Parent
(N
));
13188 when N_Subprogram_Call
=>
13189 return Is_List_Member
(N
)
13191 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
13196 end Is_Actual_Parameter
;
13198 --------------------------------
13199 -- Is_Actual_Tagged_Parameter --
13200 --------------------------------
13202 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
13203 Formal
: Entity_Id
;
13206 Find_Actual
(N
, Formal
, Call
);
13207 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
13208 end Is_Actual_Tagged_Parameter
;
13210 ---------------------
13211 -- Is_Aliased_View --
13212 ---------------------
13214 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
13218 if Is_Entity_Name
(Obj
) then
13225 or else (Present
(Renamed_Object
(E
))
13226 and then Is_Aliased_View
(Renamed_Object
(E
)))))
13228 or else ((Is_Formal
(E
) or else Is_Formal_Object
(E
))
13229 and then Is_Tagged_Type
(Etype
(E
)))
13231 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
13233 -- Current instance of type, either directly or as rewritten
13234 -- reference to the current object.
13236 or else (Is_Entity_Name
(Original_Node
(Obj
))
13237 and then Present
(Entity
(Original_Node
(Obj
)))
13238 and then Is_Type
(Entity
(Original_Node
(Obj
))))
13240 or else (Is_Type
(E
) and then E
= Current_Scope
)
13242 or else (Is_Incomplete_Or_Private_Type
(E
)
13243 and then Full_View
(E
) = Current_Scope
)
13245 -- Ada 2012 AI05-0053: the return object of an extended return
13246 -- statement is aliased if its type is immutably limited.
13248 or else (Is_Return_Object
(E
)
13249 and then Is_Limited_View
(Etype
(E
)));
13251 elsif Nkind
(Obj
) = N_Selected_Component
then
13252 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
13254 elsif Nkind
(Obj
) = N_Indexed_Component
then
13255 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
13257 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
13258 and then Has_Aliased_Components
13259 (Designated_Type
(Etype
(Prefix
(Obj
)))));
13261 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
13262 return Is_Tagged_Type
(Etype
(Obj
))
13263 and then Is_Aliased_View
(Expression
(Obj
));
13265 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
13266 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
13271 end Is_Aliased_View
;
13273 -------------------------
13274 -- Is_Ancestor_Package --
13275 -------------------------
13277 function Is_Ancestor_Package
13279 E2
: Entity_Id
) return Boolean
13285 while Present
(Par
) and then Par
/= Standard_Standard
loop
13290 Par
:= Scope
(Par
);
13294 end Is_Ancestor_Package
;
13296 ----------------------
13297 -- Is_Atomic_Object --
13298 ----------------------
13300 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
13301 function Is_Atomic_Entity
(Id
: Entity_Id
) return Boolean;
13302 pragma Inline
(Is_Atomic_Entity
);
13303 -- Determine whether arbitrary entity Id is either atomic or has atomic
13306 function Is_Atomic_Prefix
(Pref
: Node_Id
) return Boolean;
13307 -- Determine whether prefix Pref of an indexed or selected component is
13308 -- an atomic object.
13310 ----------------------
13311 -- Is_Atomic_Entity --
13312 ----------------------
13314 function Is_Atomic_Entity
(Id
: Entity_Id
) return Boolean is
13316 return Is_Atomic
(Id
) or else Has_Atomic_Components
(Id
);
13317 end Is_Atomic_Entity
;
13319 ----------------------
13320 -- Is_Atomic_Prefix --
13321 ----------------------
13323 function Is_Atomic_Prefix
(Pref
: Node_Id
) return Boolean is
13324 Typ
: constant Entity_Id
:= Etype
(Pref
);
13327 if Is_Access_Type
(Typ
) then
13328 return Has_Atomic_Components
(Designated_Type
(Typ
));
13330 elsif Is_Atomic_Entity
(Typ
) then
13333 elsif Is_Entity_Name
(Pref
)
13334 and then Is_Atomic_Entity
(Entity
(Pref
))
13338 elsif Nkind
(Pref
) = N_Indexed_Component
then
13339 return Is_Atomic_Prefix
(Prefix
(Pref
));
13341 elsif Nkind
(Pref
) = N_Selected_Component
then
13343 Is_Atomic_Prefix
(Prefix
(Pref
))
13344 or else Is_Atomic
(Entity
(Selector_Name
(Pref
)));
13348 end Is_Atomic_Prefix
;
13350 -- Start of processing for Is_Atomic_Object
13353 if Is_Entity_Name
(N
) then
13354 return Is_Atomic_Object_Entity
(Entity
(N
));
13356 elsif Nkind
(N
) = N_Indexed_Component
then
13357 return Is_Atomic
(Etype
(N
)) or else Is_Atomic_Prefix
(Prefix
(N
));
13359 elsif Nkind
(N
) = N_Selected_Component
then
13361 Is_Atomic
(Etype
(N
))
13362 or else Is_Atomic_Prefix
(Prefix
(N
))
13363 or else Is_Atomic
(Entity
(Selector_Name
(N
)));
13367 end Is_Atomic_Object
;
13369 -----------------------------
13370 -- Is_Atomic_Object_Entity --
13371 -----------------------------
13373 function Is_Atomic_Object_Entity
(Id
: Entity_Id
) return Boolean is
13377 and then (Is_Atomic
(Id
) or else Is_Atomic
(Etype
(Id
)));
13378 end Is_Atomic_Object_Entity
;
13380 -----------------------------
13381 -- Is_Atomic_Or_VFA_Object --
13382 -----------------------------
13384 function Is_Atomic_Or_VFA_Object
(N
: Node_Id
) return Boolean is
13386 return Is_Atomic_Object
(N
)
13387 or else (Is_Object_Reference
(N
)
13388 and then Is_Entity_Name
(N
)
13389 and then (Is_Volatile_Full_Access
(Entity
(N
))
13391 Is_Volatile_Full_Access
(Etype
(Entity
(N
)))));
13392 end Is_Atomic_Or_VFA_Object
;
13394 -------------------------
13395 -- Is_Attribute_Result --
13396 -------------------------
13398 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
13400 return Nkind
(N
) = N_Attribute_Reference
13401 and then Attribute_Name
(N
) = Name_Result
;
13402 end Is_Attribute_Result
;
13404 -------------------------
13405 -- Is_Attribute_Update --
13406 -------------------------
13408 function Is_Attribute_Update
(N
: Node_Id
) return Boolean is
13410 return Nkind
(N
) = N_Attribute_Reference
13411 and then Attribute_Name
(N
) = Name_Update
;
13412 end Is_Attribute_Update
;
13414 ------------------------------------
13415 -- Is_Body_Or_Package_Declaration --
13416 ------------------------------------
13418 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
13420 return Is_Body
(N
) or else Nkind
(N
) = N_Package_Declaration
;
13421 end Is_Body_Or_Package_Declaration
;
13423 -----------------------
13424 -- Is_Bounded_String --
13425 -----------------------
13427 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
13428 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
13431 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13432 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13433 -- be True for all the Bounded_String types in instances of the
13434 -- Generic_Bounded_Length generics, and for types derived from those.
13436 return Present
(Under
)
13437 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
13438 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
13439 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
13440 end Is_Bounded_String
;
13442 ---------------------
13443 -- Is_CCT_Instance --
13444 ---------------------
13446 function Is_CCT_Instance
13447 (Ref_Id
: Entity_Id
;
13448 Context_Id
: Entity_Id
) return Boolean
13451 pragma Assert
(Ekind_In
(Ref_Id
, E_Protected_Type
, E_Task_Type
));
13453 if Is_Single_Task_Object
(Context_Id
) then
13454 return Scope_Within_Or_Same
(Etype
(Context_Id
), Ref_Id
);
13457 pragma Assert
(Ekind_In
(Context_Id
, E_Entry
,
13465 Is_Record_Type
(Context_Id
));
13466 return Scope_Within_Or_Same
(Context_Id
, Ref_Id
);
13468 end Is_CCT_Instance
;
13470 -------------------------
13471 -- Is_Child_Or_Sibling --
13472 -------------------------
13474 function Is_Child_Or_Sibling
13475 (Pack_1
: Entity_Id
;
13476 Pack_2
: Entity_Id
) return Boolean
13478 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
13479 -- Given an arbitrary package, return the number of "climbs" necessary
13480 -- to reach scope Standard_Standard.
13482 procedure Equalize_Depths
13483 (Pack
: in out Entity_Id
;
13484 Depth
: in out Nat
;
13485 Depth_To_Reach
: Nat
);
13486 -- Given an arbitrary package, its depth and a target depth to reach,
13487 -- climb the scope chain until the said depth is reached. The pointer
13488 -- to the package and its depth a modified during the climb.
13490 ----------------------------
13491 -- Distance_From_Standard --
13492 ----------------------------
13494 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
13501 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
13503 Scop
:= Scope
(Scop
);
13507 end Distance_From_Standard
;
13509 ---------------------
13510 -- Equalize_Depths --
13511 ---------------------
13513 procedure Equalize_Depths
13514 (Pack
: in out Entity_Id
;
13515 Depth
: in out Nat
;
13516 Depth_To_Reach
: Nat
)
13519 -- The package must be at a greater or equal depth
13521 if Depth
< Depth_To_Reach
then
13522 raise Program_Error
;
13525 -- Climb the scope chain until the desired depth is reached
13527 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
13528 Pack
:= Scope
(Pack
);
13529 Depth
:= Depth
- 1;
13531 end Equalize_Depths
;
13535 P_1
: Entity_Id
:= Pack_1
;
13536 P_1_Child
: Boolean := False;
13537 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
13538 P_2
: Entity_Id
:= Pack_2
;
13539 P_2_Child
: Boolean := False;
13540 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
13542 -- Start of processing for Is_Child_Or_Sibling
13546 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
13548 -- Both packages denote the same entity, therefore they cannot be
13549 -- children or siblings.
13554 -- One of the packages is at a deeper level than the other. Note that
13555 -- both may still come from different hierarchies.
13563 elsif P_1_Depth
> P_2_Depth
then
13566 Depth
=> P_1_Depth
,
13567 Depth_To_Reach
=> P_2_Depth
);
13576 elsif P_2_Depth
> P_1_Depth
then
13579 Depth
=> P_2_Depth
,
13580 Depth_To_Reach
=> P_1_Depth
);
13584 -- At this stage the package pointers have been elevated to the same
13585 -- depth. If the related entities are the same, then one package is a
13586 -- potential child of the other:
13590 -- X became P_1 P_2 or vice versa
13596 return Is_Child_Unit
(Pack_1
);
13598 else pragma Assert
(P_2_Child
);
13599 return Is_Child_Unit
(Pack_2
);
13602 -- The packages may come from the same package chain or from entirely
13603 -- different hierarcies. To determine this, climb the scope stack until
13604 -- a common root is found.
13606 -- (root) (root 1) (root 2)
13611 while Present
(P_1
) and then Present
(P_2
) loop
13613 -- The two packages may be siblings
13616 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
13619 P_1
:= Scope
(P_1
);
13620 P_2
:= Scope
(P_2
);
13625 end Is_Child_Or_Sibling
;
13627 -----------------------------
13628 -- Is_Concurrent_Interface --
13629 -----------------------------
13631 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
13633 return Is_Interface
(T
)
13635 (Is_Protected_Interface
(T
)
13636 or else Is_Synchronized_Interface
(T
)
13637 or else Is_Task_Interface
(T
));
13638 end Is_Concurrent_Interface
;
13640 -----------------------
13641 -- Is_Constant_Bound --
13642 -----------------------
13644 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
13646 if Compile_Time_Known_Value
(Exp
) then
13649 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
13650 return Is_Constant_Object
(Entity
(Exp
))
13651 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
13653 elsif Nkind
(Exp
) in N_Binary_Op
then
13654 return Is_Constant_Bound
(Left_Opnd
(Exp
))
13655 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
13656 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
13661 end Is_Constant_Bound
;
13663 ---------------------------
13664 -- Is_Container_Element --
13665 ---------------------------
13667 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
13668 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
13669 Pref
: constant Node_Id
:= Prefix
(Exp
);
13672 -- Call to an indexing aspect
13674 Cont_Typ
: Entity_Id
;
13675 -- The type of the container being accessed
13677 Elem_Typ
: Entity_Id
;
13678 -- Its element type
13680 Indexing
: Entity_Id
;
13681 Is_Const
: Boolean;
13682 -- Indicates that constant indexing is used, and the element is thus
13685 Ref_Typ
: Entity_Id
;
13686 -- The reference type returned by the indexing operation
13689 -- If C is a container, in a context that imposes the element type of
13690 -- that container, the indexing notation C (X) is rewritten as:
13692 -- Indexing (C, X).Discr.all
13694 -- where Indexing is one of the indexing aspects of the container.
13695 -- If the context does not require a reference, the construct can be
13700 -- First, verify that the construct has the proper form
13702 if not Expander_Active
then
13705 elsif Nkind
(Pref
) /= N_Selected_Component
then
13708 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
13712 Call
:= Prefix
(Pref
);
13713 Ref_Typ
:= Etype
(Call
);
13716 if not Has_Implicit_Dereference
(Ref_Typ
)
13717 or else No
(First
(Parameter_Associations
(Call
)))
13718 or else not Is_Entity_Name
(Name
(Call
))
13723 -- Retrieve type of container object, and its iterator aspects
13725 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
13726 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
13729 if No
(Indexing
) then
13731 -- Container should have at least one indexing operation
13735 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
13737 -- This may be a variable indexing operation
13739 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
13742 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
13751 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
13753 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
13757 -- Check that the expression is not the target of an assignment, in
13758 -- which case the rewriting is not possible.
13760 if not Is_Const
then
13766 while Present
(Par
)
13768 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
13769 and then Par
= Name
(Parent
(Par
))
13773 -- A renaming produces a reference, and the transformation
13776 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
13780 (Nkind
(Parent
(Par
)), N_Function_Call
,
13781 N_Procedure_Call_Statement
,
13782 N_Entry_Call_Statement
)
13784 -- Check that the element is not part of an actual for an
13785 -- in-out parameter.
13792 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
13793 A
:= First
(Parameter_Associations
(Parent
(Par
)));
13794 while Present
(F
) loop
13795 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
13804 -- E_In_Parameter in a call: element is not modified.
13809 Par
:= Parent
(Par
);
13814 -- The expression has the proper form and the context requires the
13815 -- element type. Retrieve the Element function of the container and
13816 -- rewrite the construct as a call to it.
13822 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
13823 while Present
(Op
) loop
13824 exit when Chars
(Node
(Op
)) = Name_Element
;
13833 Make_Function_Call
(Loc
,
13834 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
13835 Parameter_Associations
=> Parameter_Associations
(Call
)));
13836 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
13840 end Is_Container_Element
;
13842 ----------------------------
13843 -- Is_Contract_Annotation --
13844 ----------------------------
13846 function Is_Contract_Annotation
(Item
: Node_Id
) return Boolean is
13848 return Is_Package_Contract_Annotation
(Item
)
13850 Is_Subprogram_Contract_Annotation
(Item
);
13851 end Is_Contract_Annotation
;
13853 --------------------------------------
13854 -- Is_Controlling_Limited_Procedure --
13855 --------------------------------------
13857 function Is_Controlling_Limited_Procedure
13858 (Proc_Nam
: Entity_Id
) return Boolean
13861 Param_Typ
: Entity_Id
:= Empty
;
13864 if Ekind
(Proc_Nam
) = E_Procedure
13865 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
13869 (First
(Parameter_Specifications
(Parent
(Proc_Nam
))));
13871 -- The formal may be an anonymous access type
13873 if Nkind
(Param
) = N_Access_Definition
then
13874 Param_Typ
:= Entity
(Subtype_Mark
(Param
));
13876 Param_Typ
:= Etype
(Param
);
13879 -- In the case where an Itype was created for a dispatchin call, the
13880 -- procedure call has been rewritten. The actual may be an access to
13881 -- interface type in which case it is the designated type that is the
13882 -- controlling type.
13884 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
13885 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
13887 Present
(Parameter_Associations
13888 (Associated_Node_For_Itype
(Proc_Nam
)))
13891 Etype
(First
(Parameter_Associations
13892 (Associated_Node_For_Itype
(Proc_Nam
))));
13894 if Ekind
(Param_Typ
) = E_Anonymous_Access_Type
then
13895 Param_Typ
:= Directly_Designated_Type
(Param_Typ
);
13899 if Present
(Param_Typ
) then
13901 Is_Interface
(Param_Typ
)
13902 and then Is_Limited_Record
(Param_Typ
);
13906 end Is_Controlling_Limited_Procedure
;
13908 -----------------------------
13909 -- Is_CPP_Constructor_Call --
13910 -----------------------------
13912 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
13914 return Nkind
(N
) = N_Function_Call
13915 and then Is_CPP_Class
(Etype
(Etype
(N
)))
13916 and then Is_Constructor
(Entity
(Name
(N
)))
13917 and then Is_Imported
(Entity
(Name
(N
)));
13918 end Is_CPP_Constructor_Call
;
13920 -------------------------
13921 -- Is_Current_Instance --
13922 -------------------------
13924 function Is_Current_Instance
(N
: Node_Id
) return Boolean is
13925 Typ
: constant Entity_Id
:= Entity
(N
);
13929 -- Simplest case: entity is a concurrent type and we are currently
13930 -- inside the body. This will eventually be expanded into a call to
13931 -- Self (for tasks) or _object (for protected objects).
13933 if Is_Concurrent_Type
(Typ
) and then In_Open_Scopes
(Typ
) then
13937 -- Check whether the context is a (sub)type declaration for the
13941 while Present
(P
) loop
13942 if Nkind_In
(P
, N_Full_Type_Declaration
,
13943 N_Private_Type_Declaration
,
13944 N_Subtype_Declaration
)
13945 and then Comes_From_Source
(P
)
13946 and then Defining_Entity
(P
) = Typ
13950 -- A subtype name may appear in an aspect specification for a
13951 -- Predicate_Failure aspect, for which we do not construct a
13952 -- wrapper procedure. The subtype will be replaced by the
13953 -- expression being tested when the corresponding predicate
13954 -- check is expanded.
13956 elsif Nkind
(P
) = N_Aspect_Specification
13957 and then Nkind
(Parent
(P
)) = N_Subtype_Declaration
13961 elsif Nkind
(P
) = N_Pragma
13962 and then Get_Pragma_Id
(P
) = Pragma_Predicate_Failure
13971 -- In any other context this is not a current occurrence
13974 end Is_Current_Instance
;
13976 --------------------
13977 -- Is_Declaration --
13978 --------------------
13980 function Is_Declaration
13982 Body_OK
: Boolean := True;
13983 Concurrent_OK
: Boolean := True;
13984 Formal_OK
: Boolean := True;
13985 Generic_OK
: Boolean := True;
13986 Instantiation_OK
: Boolean := True;
13987 Renaming_OK
: Boolean := True;
13988 Stub_OK
: Boolean := True;
13989 Subprogram_OK
: Boolean := True;
13990 Type_OK
: Boolean := True) return Boolean
13995 -- Body declarations
13997 when N_Proper_Body
=>
14000 -- Concurrent type declarations
14002 when N_Protected_Type_Declaration
14003 | N_Single_Protected_Declaration
14004 | N_Single_Task_Declaration
14005 | N_Task_Type_Declaration
14007 return Concurrent_OK
or Type_OK
;
14009 -- Formal declarations
14011 when N_Formal_Abstract_Subprogram_Declaration
14012 | N_Formal_Concrete_Subprogram_Declaration
14013 | N_Formal_Object_Declaration
14014 | N_Formal_Package_Declaration
14015 | N_Formal_Type_Declaration
14019 -- Generic declarations
14021 when N_Generic_Package_Declaration
14022 | N_Generic_Subprogram_Declaration
14026 -- Generic instantiations
14028 when N_Function_Instantiation
14029 | N_Package_Instantiation
14030 | N_Procedure_Instantiation
14032 return Instantiation_OK
;
14034 -- Generic renaming declarations
14036 when N_Generic_Renaming_Declaration
=>
14037 return Generic_OK
or Renaming_OK
;
14039 -- Renaming declarations
14041 when N_Exception_Renaming_Declaration
14042 | N_Object_Renaming_Declaration
14043 | N_Package_Renaming_Declaration
14044 | N_Subprogram_Renaming_Declaration
14046 return Renaming_OK
;
14048 -- Stub declarations
14050 when N_Body_Stub
=>
14053 -- Subprogram declarations
14055 when N_Abstract_Subprogram_Declaration
14056 | N_Entry_Declaration
14057 | N_Expression_Function
14058 | N_Subprogram_Declaration
14060 return Subprogram_OK
;
14062 -- Type declarations
14064 when N_Full_Type_Declaration
14065 | N_Incomplete_Type_Declaration
14066 | N_Private_Extension_Declaration
14067 | N_Private_Type_Declaration
14068 | N_Subtype_Declaration
14074 when N_Component_Declaration
14075 | N_Exception_Declaration
14076 | N_Implicit_Label_Declaration
14077 | N_Number_Declaration
14078 | N_Object_Declaration
14079 | N_Package_Declaration
14086 end Is_Declaration
;
14088 --------------------------------
14089 -- Is_Declared_Within_Variant --
14090 --------------------------------
14092 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
14093 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
14094 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
14096 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
14097 end Is_Declared_Within_Variant
;
14099 ----------------------------------------------
14100 -- Is_Dependent_Component_Of_Mutable_Object --
14101 ----------------------------------------------
14103 function Is_Dependent_Component_Of_Mutable_Object
14104 (Object
: Node_Id
) return Boolean
14107 Prefix_Type
: Entity_Id
;
14108 P_Aliased
: Boolean := False;
14111 Deref
: Node_Id
:= Object
;
14112 -- Dereference node, in something like X.all.Y(2)
14114 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14117 -- Find the dereference node if any
14119 while Nkind_In
(Deref
, N_Indexed_Component
,
14120 N_Selected_Component
,
14123 Deref
:= Prefix
(Deref
);
14126 -- Ada 2005: If we have a component or slice of a dereference,
14127 -- something like X.all.Y (2), and the type of X is access-to-constant,
14128 -- Is_Variable will return False, because it is indeed a constant
14129 -- view. But it might be a view of a variable object, so we want the
14130 -- following condition to be True in that case.
14132 if Is_Variable
(Object
)
14133 or else (Ada_Version
>= Ada_2005
14134 and then Nkind
(Deref
) = N_Explicit_Dereference
)
14136 if Nkind
(Object
) = N_Selected_Component
then
14137 P
:= Prefix
(Object
);
14138 Prefix_Type
:= Etype
(P
);
14140 if Is_Entity_Name
(P
) then
14141 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
14142 Prefix_Type
:= Base_Type
(Prefix_Type
);
14145 if Is_Aliased
(Entity
(P
)) then
14149 -- A discriminant check on a selected component may be expanded
14150 -- into a dereference when removing side effects. Recover the
14151 -- original node and its type, which may be unconstrained.
14153 elsif Nkind
(P
) = N_Explicit_Dereference
14154 and then not (Comes_From_Source
(P
))
14156 P
:= Original_Node
(P
);
14157 Prefix_Type
:= Etype
(P
);
14160 -- Check for prefix being an aliased component???
14166 -- A heap object is constrained by its initial value
14168 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14169 -- the dereferenced case, since the access value might denote an
14170 -- unconstrained aliased object, whereas in Ada 95 the designated
14171 -- object is guaranteed to be constrained. A worst-case assumption
14172 -- has to apply in Ada 2005 because we can't tell at compile
14173 -- time whether the object is "constrained by its initial value",
14174 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14175 -- rules (these rules are acknowledged to need fixing). We don't
14176 -- impose this more stringent checking for earlier Ada versions or
14177 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14178 -- benefit, though it's unclear on why using -gnat95 would not be
14181 if Ada_Version
< Ada_2005
or else Relaxed_RM_Semantics
then
14182 if Is_Access_Type
(Prefix_Type
)
14183 or else Nkind
(P
) = N_Explicit_Dereference
14188 else pragma Assert
(Ada_Version
>= Ada_2005
);
14189 if Is_Access_Type
(Prefix_Type
) then
14191 -- If the access type is pool-specific, and there is no
14192 -- constrained partial view of the designated type, then the
14193 -- designated object is known to be constrained.
14195 if Ekind
(Prefix_Type
) = E_Access_Type
14196 and then not Object_Type_Has_Constrained_Partial_View
14197 (Typ
=> Designated_Type
(Prefix_Type
),
14198 Scop
=> Current_Scope
)
14202 -- Otherwise (general access type, or there is a constrained
14203 -- partial view of the designated type), we need to check
14204 -- based on the designated type.
14207 Prefix_Type
:= Designated_Type
(Prefix_Type
);
14213 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
14215 -- As per AI-0017, the renaming is illegal in a generic body, even
14216 -- if the subtype is indefinite.
14218 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14220 if not Is_Constrained
(Prefix_Type
)
14221 and then (Is_Definite_Subtype
(Prefix_Type
)
14223 (Is_Generic_Type
(Prefix_Type
)
14224 and then Ekind
(Current_Scope
) = E_Generic_Package
14225 and then In_Package_Body
(Current_Scope
)))
14227 and then (Is_Declared_Within_Variant
(Comp
)
14228 or else Has_Discriminant_Dependent_Constraint
(Comp
))
14229 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
14233 -- If the prefix is of an access type at this point, then we want
14234 -- to return False, rather than calling this function recursively
14235 -- on the access object (which itself might be a discriminant-
14236 -- dependent component of some other object, but that isn't
14237 -- relevant to checking the object passed to us). This avoids
14238 -- issuing wrong errors when compiling with -gnatc, where there
14239 -- can be implicit dereferences that have not been expanded.
14241 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
14246 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
14249 elsif Nkind
(Object
) = N_Indexed_Component
14250 or else Nkind
(Object
) = N_Slice
14252 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
14254 -- A type conversion that Is_Variable is a view conversion:
14255 -- go back to the denoted object.
14257 elsif Nkind
(Object
) = N_Type_Conversion
then
14259 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
14264 end Is_Dependent_Component_Of_Mutable_Object
;
14266 ---------------------
14267 -- Is_Dereferenced --
14268 ---------------------
14270 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
14271 P
: constant Node_Id
:= Parent
(N
);
14273 return Nkind_In
(P
, N_Selected_Component
,
14274 N_Explicit_Dereference
,
14275 N_Indexed_Component
,
14277 and then Prefix
(P
) = N
;
14278 end Is_Dereferenced
;
14280 ----------------------
14281 -- Is_Descendant_Of --
14282 ----------------------
14284 function Is_Descendant_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
14289 pragma Assert
(Nkind
(T1
) in N_Entity
);
14290 pragma Assert
(Nkind
(T2
) in N_Entity
);
14292 T
:= Base_Type
(T1
);
14294 -- Immediate return if the types match
14299 -- Comment needed here ???
14301 elsif Ekind
(T
) = E_Class_Wide_Type
then
14302 return Etype
(T
) = T2
;
14310 -- Done if we found the type we are looking for
14315 -- Done if no more derivations to check
14322 -- Following test catches error cases resulting from prev errors
14324 elsif No
(Etyp
) then
14327 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
14330 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
14334 T
:= Base_Type
(Etyp
);
14337 end Is_Descendant_Of
;
14339 ----------------------------------------
14340 -- Is_Descendant_Of_Suspension_Object --
14341 ----------------------------------------
14343 function Is_Descendant_Of_Suspension_Object
14344 (Typ
: Entity_Id
) return Boolean
14346 Cur_Typ
: Entity_Id
;
14347 Par_Typ
: Entity_Id
;
14350 -- Climb the type derivation chain checking each parent type against
14351 -- Suspension_Object.
14353 Cur_Typ
:= Base_Type
(Typ
);
14354 while Present
(Cur_Typ
) loop
14355 Par_Typ
:= Etype
(Cur_Typ
);
14357 -- The current type is a match
14359 if Is_Suspension_Object
(Cur_Typ
) then
14362 -- Stop the traversal once the root of the derivation chain has been
14363 -- reached. In that case the current type is its own base type.
14365 elsif Cur_Typ
= Par_Typ
then
14369 Cur_Typ
:= Base_Type
(Par_Typ
);
14373 end Is_Descendant_Of_Suspension_Object
;
14375 ---------------------------------------------
14376 -- Is_Double_Precision_Floating_Point_Type --
14377 ---------------------------------------------
14379 function Is_Double_Precision_Floating_Point_Type
14380 (E
: Entity_Id
) return Boolean is
14382 return Is_Floating_Point_Type
(E
)
14383 and then Machine_Radix_Value
(E
) = Uint_2
14384 and then Machine_Mantissa_Value
(E
) = UI_From_Int
(53)
14385 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_10
14386 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_10
);
14387 end Is_Double_Precision_Floating_Point_Type
;
14389 -----------------------------
14390 -- Is_Effectively_Volatile --
14391 -----------------------------
14393 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
14395 if Is_Type
(Id
) then
14397 -- An arbitrary type is effectively volatile when it is subject to
14398 -- pragma Atomic or Volatile.
14400 if Is_Volatile
(Id
) then
14403 -- An array type is effectively volatile when it is subject to pragma
14404 -- Atomic_Components or Volatile_Components or its component type is
14405 -- effectively volatile.
14407 elsif Is_Array_Type
(Id
) then
14409 Anc
: Entity_Id
:= Base_Type
(Id
);
14411 if Is_Private_Type
(Anc
) then
14412 Anc
:= Full_View
(Anc
);
14415 -- Test for presence of ancestor, as the full view of a private
14416 -- type may be missing in case of error.
14419 Has_Volatile_Components
(Id
)
14422 and then Is_Effectively_Volatile
(Component_Type
(Anc
)));
14425 -- A protected type is always volatile
14427 elsif Is_Protected_Type
(Id
) then
14430 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14431 -- automatically volatile.
14433 elsif Is_Descendant_Of_Suspension_Object
(Id
) then
14436 -- Otherwise the type is not effectively volatile
14442 -- Otherwise Id denotes an object
14447 or else Has_Volatile_Components
(Id
)
14448 or else Is_Effectively_Volatile
(Etype
(Id
));
14450 end Is_Effectively_Volatile
;
14452 ------------------------------------
14453 -- Is_Effectively_Volatile_Object --
14454 ------------------------------------
14456 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
14458 if Is_Entity_Name
(N
) then
14459 return Is_Effectively_Volatile
(Entity
(N
));
14461 elsif Nkind
(N
) = N_Indexed_Component
then
14462 return Is_Effectively_Volatile_Object
(Prefix
(N
));
14464 elsif Nkind
(N
) = N_Selected_Component
then
14466 Is_Effectively_Volatile_Object
(Prefix
(N
))
14468 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
14473 end Is_Effectively_Volatile_Object
;
14475 -------------------
14476 -- Is_Entry_Body --
14477 -------------------
14479 function Is_Entry_Body
(Id
: Entity_Id
) return Boolean is
14482 Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
14483 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Body
;
14486 --------------------------
14487 -- Is_Entry_Declaration --
14488 --------------------------
14490 function Is_Entry_Declaration
(Id
: Entity_Id
) return Boolean is
14493 Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
14494 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Declaration
;
14495 end Is_Entry_Declaration
;
14497 ------------------------------------
14498 -- Is_Expanded_Priority_Attribute --
14499 ------------------------------------
14501 function Is_Expanded_Priority_Attribute
(E
: Entity_Id
) return Boolean is
14504 Nkind
(E
) = N_Function_Call
14505 and then not Configurable_Run_Time_Mode
14506 and then (Entity
(Name
(E
)) = RTE
(RE_Get_Ceiling
)
14507 or else Entity
(Name
(E
)) = RTE
(RO_PE_Get_Ceiling
));
14508 end Is_Expanded_Priority_Attribute
;
14510 ----------------------------
14511 -- Is_Expression_Function --
14512 ----------------------------
14514 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
14516 if Ekind_In
(Subp
, E_Function
, E_Subprogram_Body
) then
14518 Nkind
(Original_Node
(Unit_Declaration_Node
(Subp
))) =
14519 N_Expression_Function
;
14523 end Is_Expression_Function
;
14525 ------------------------------------------
14526 -- Is_Expression_Function_Or_Completion --
14527 ------------------------------------------
14529 function Is_Expression_Function_Or_Completion
14530 (Subp
: Entity_Id
) return Boolean
14532 Subp_Decl
: Node_Id
;
14535 if Ekind
(Subp
) = E_Function
then
14536 Subp_Decl
:= Unit_Declaration_Node
(Subp
);
14538 -- The function declaration is either an expression function or is
14539 -- completed by an expression function body.
14542 Is_Expression_Function
(Subp
)
14543 or else (Nkind
(Subp_Decl
) = N_Subprogram_Declaration
14544 and then Present
(Corresponding_Body
(Subp_Decl
))
14545 and then Is_Expression_Function
14546 (Corresponding_Body
(Subp_Decl
)));
14548 elsif Ekind
(Subp
) = E_Subprogram_Body
then
14549 return Is_Expression_Function
(Subp
);
14554 end Is_Expression_Function_Or_Completion
;
14556 -----------------------
14557 -- Is_EVF_Expression --
14558 -----------------------
14560 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
14561 Orig_N
: constant Node_Id
:= Original_Node
(N
);
14567 -- Detect a reference to a formal parameter of a specific tagged type
14568 -- whose related subprogram is subject to pragma Expresions_Visible with
14571 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
14576 and then Is_Specific_Tagged_Type
(Etype
(Id
))
14577 and then Extensions_Visible_Status
(Id
) =
14578 Extensions_Visible_False
;
14580 -- A case expression is an EVF expression when it contains at least one
14581 -- EVF dependent_expression. Note that a case expression may have been
14582 -- expanded, hence the use of Original_Node.
14584 elsif Nkind
(Orig_N
) = N_Case_Expression
then
14585 Alt
:= First
(Alternatives
(Orig_N
));
14586 while Present
(Alt
) loop
14587 if Is_EVF_Expression
(Expression
(Alt
)) then
14594 -- An if expression is an EVF expression when it contains at least one
14595 -- EVF dependent_expression. Note that an if expression may have been
14596 -- expanded, hence the use of Original_Node.
14598 elsif Nkind
(Orig_N
) = N_If_Expression
then
14599 Expr
:= Next
(First
(Expressions
(Orig_N
)));
14600 while Present
(Expr
) loop
14601 if Is_EVF_Expression
(Expr
) then
14608 -- A qualified expression or a type conversion is an EVF expression when
14609 -- its operand is an EVF expression.
14611 elsif Nkind_In
(N
, N_Qualified_Expression
,
14612 N_Unchecked_Type_Conversion
,
14615 return Is_EVF_Expression
(Expression
(N
));
14617 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14618 -- their prefix denotes an EVF expression.
14620 elsif Nkind
(N
) = N_Attribute_Reference
14621 and then Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
14625 return Is_EVF_Expression
(Prefix
(N
));
14629 end Is_EVF_Expression
;
14635 function Is_False
(U
: Uint
) return Boolean is
14640 ---------------------------
14641 -- Is_Fixed_Model_Number --
14642 ---------------------------
14644 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
14645 S
: constant Ureal
:= Small_Value
(T
);
14646 M
: Urealp
.Save_Mark
;
14651 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
14652 Urealp
.Release
(M
);
14654 end Is_Fixed_Model_Number
;
14656 -------------------------------
14657 -- Is_Fully_Initialized_Type --
14658 -------------------------------
14660 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
14664 if Is_Scalar_Type
(Typ
) then
14666 -- A scalar type with an aspect Default_Value is fully initialized
14668 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14669 -- of a scalar type, but we don't take that into account here, since
14670 -- we don't want these to affect warnings.
14672 return Has_Default_Aspect
(Typ
);
14674 elsif Is_Access_Type
(Typ
) then
14677 elsif Is_Array_Type
(Typ
) then
14678 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
14679 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
14684 -- An interesting case, if we have a constrained type one of whose
14685 -- bounds is known to be null, then there are no elements to be
14686 -- initialized, so all the elements are initialized.
14688 if Is_Constrained
(Typ
) then
14691 Indx_Typ
: Entity_Id
;
14692 Lbd
, Hbd
: Node_Id
;
14695 Indx
:= First_Index
(Typ
);
14696 while Present
(Indx
) loop
14697 if Etype
(Indx
) = Any_Type
then
14700 -- If index is a range, use directly
14702 elsif Nkind
(Indx
) = N_Range
then
14703 Lbd
:= Low_Bound
(Indx
);
14704 Hbd
:= High_Bound
(Indx
);
14707 Indx_Typ
:= Etype
(Indx
);
14709 if Is_Private_Type
(Indx_Typ
) then
14710 Indx_Typ
:= Full_View
(Indx_Typ
);
14713 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
14716 Lbd
:= Type_Low_Bound
(Indx_Typ
);
14717 Hbd
:= Type_High_Bound
(Indx_Typ
);
14721 if Compile_Time_Known_Value
(Lbd
)
14723 Compile_Time_Known_Value
(Hbd
)
14725 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
14735 -- If no null indexes, then type is not fully initialized
14741 elsif Is_Record_Type
(Typ
) then
14742 if Has_Discriminants
(Typ
)
14744 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
14745 and then Is_Fully_Initialized_Variant
(Typ
)
14750 -- We consider bounded string types to be fully initialized, because
14751 -- otherwise we get false alarms when the Data component is not
14752 -- default-initialized.
14754 if Is_Bounded_String
(Typ
) then
14758 -- Controlled records are considered to be fully initialized if
14759 -- there is a user defined Initialize routine. This may not be
14760 -- entirely correct, but as the spec notes, we are guessing here
14761 -- what is best from the point of view of issuing warnings.
14763 if Is_Controlled
(Typ
) then
14765 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
14768 if Present
(Utyp
) then
14770 Init
: constant Entity_Id
:=
14771 (Find_Optional_Prim_Op
14772 (Underlying_Type
(Typ
), Name_Initialize
));
14776 and then Comes_From_Source
(Init
)
14777 and then not In_Predefined_Unit
(Init
)
14781 elsif Has_Null_Extension
(Typ
)
14783 Is_Fully_Initialized_Type
14784 (Etype
(Base_Type
(Typ
)))
14793 -- Otherwise see if all record components are initialized
14799 Ent
:= First_Entity
(Typ
);
14800 while Present
(Ent
) loop
14801 if Ekind
(Ent
) = E_Component
14802 and then (No
(Parent
(Ent
))
14803 or else No
(Expression
(Parent
(Ent
))))
14804 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
14806 -- Special VM case for tag components, which need to be
14807 -- defined in this case, but are never initialized as VMs
14808 -- are using other dispatching mechanisms. Ignore this
14809 -- uninitialized case. Note that this applies both to the
14810 -- uTag entry and the main vtable pointer (CPP_Class case).
14812 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
14821 -- No uninitialized components, so type is fully initialized.
14822 -- Note that this catches the case of no components as well.
14826 elsif Is_Concurrent_Type
(Typ
) then
14829 elsif Is_Private_Type
(Typ
) then
14831 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
14837 return Is_Fully_Initialized_Type
(U
);
14844 end Is_Fully_Initialized_Type
;
14846 ----------------------------------
14847 -- Is_Fully_Initialized_Variant --
14848 ----------------------------------
14850 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
14851 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
14852 Constraints
: constant List_Id
:= New_List
;
14853 Components
: constant Elist_Id
:= New_Elmt_List
;
14854 Comp_Elmt
: Elmt_Id
;
14856 Comp_List
: Node_Id
;
14858 Discr_Val
: Node_Id
;
14860 Report_Errors
: Boolean;
14861 pragma Warnings
(Off
, Report_Errors
);
14864 if Serious_Errors_Detected
> 0 then
14868 if Is_Record_Type
(Typ
)
14869 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
14870 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
14872 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
14874 Discr
:= First_Discriminant
(Typ
);
14875 while Present
(Discr
) loop
14876 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
14877 Discr_Val
:= Expression
(Parent
(Discr
));
14879 if Present
(Discr_Val
)
14880 and then Is_OK_Static_Expression
(Discr_Val
)
14882 Append_To
(Constraints
,
14883 Make_Component_Association
(Loc
,
14884 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
14885 Expression
=> New_Copy
(Discr_Val
)));
14893 Next_Discriminant
(Discr
);
14898 Comp_List
=> Comp_List
,
14899 Governed_By
=> Constraints
,
14900 Into
=> Components
,
14901 Report_Errors
=> Report_Errors
);
14903 -- Check that each component present is fully initialized
14905 Comp_Elmt
:= First_Elmt
(Components
);
14906 while Present
(Comp_Elmt
) loop
14907 Comp_Id
:= Node
(Comp_Elmt
);
14909 if Ekind
(Comp_Id
) = E_Component
14910 and then (No
(Parent
(Comp_Id
))
14911 or else No
(Expression
(Parent
(Comp_Id
))))
14912 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
14917 Next_Elmt
(Comp_Elmt
);
14922 elsif Is_Private_Type
(Typ
) then
14924 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
14930 return Is_Fully_Initialized_Variant
(U
);
14937 end Is_Fully_Initialized_Variant
;
14939 ------------------------------------
14940 -- Is_Generic_Declaration_Or_Body --
14941 ------------------------------------
14943 function Is_Generic_Declaration_Or_Body
(Decl
: Node_Id
) return Boolean is
14944 Spec_Decl
: Node_Id
;
14947 -- Package/subprogram body
14949 if Nkind_In
(Decl
, N_Package_Body
, N_Subprogram_Body
)
14950 and then Present
(Corresponding_Spec
(Decl
))
14952 Spec_Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(Decl
));
14954 -- Package/subprogram body stub
14956 elsif Nkind_In
(Decl
, N_Package_Body_Stub
, N_Subprogram_Body_Stub
)
14957 and then Present
(Corresponding_Spec_Of_Stub
(Decl
))
14960 Unit_Declaration_Node
(Corresponding_Spec_Of_Stub
(Decl
));
14968 -- Rather than inspecting the defining entity of the spec declaration,
14969 -- look at its Nkind. This takes care of the case where the analysis of
14970 -- a generic body modifies the Ekind of its spec to allow for recursive
14974 Nkind_In
(Spec_Decl
, N_Generic_Package_Declaration
,
14975 N_Generic_Subprogram_Declaration
);
14976 end Is_Generic_Declaration_Or_Body
;
14978 ----------------------------
14979 -- Is_Inherited_Operation --
14980 ----------------------------
14982 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
14983 pragma Assert
(Is_Overloadable
(E
));
14984 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
14986 return Kind
= N_Full_Type_Declaration
14987 or else Kind
= N_Private_Extension_Declaration
14988 or else Kind
= N_Subtype_Declaration
14989 or else (Ekind
(E
) = E_Enumeration_Literal
14990 and then Is_Derived_Type
(Etype
(E
)));
14991 end Is_Inherited_Operation
;
14993 -------------------------------------
14994 -- Is_Inherited_Operation_For_Type --
14995 -------------------------------------
14997 function Is_Inherited_Operation_For_Type
14999 Typ
: Entity_Id
) return Boolean
15002 -- Check that the operation has been created by the type declaration
15004 return Is_Inherited_Operation
(E
)
15005 and then Defining_Identifier
(Parent
(E
)) = Typ
;
15006 end Is_Inherited_Operation_For_Type
;
15008 --------------------------------------
15009 -- Is_Inlinable_Expression_Function --
15010 --------------------------------------
15012 function Is_Inlinable_Expression_Function
15013 (Subp
: Entity_Id
) return Boolean
15015 Return_Expr
: Node_Id
;
15018 if Is_Expression_Function_Or_Completion
(Subp
)
15019 and then Has_Pragma_Inline_Always
(Subp
)
15020 and then Needs_No_Actuals
(Subp
)
15021 and then No
(Contract
(Subp
))
15022 and then not Is_Dispatching_Operation
(Subp
)
15023 and then Needs_Finalization
(Etype
(Subp
))
15024 and then not Is_Class_Wide_Type
(Etype
(Subp
))
15025 and then not (Has_Invariants
(Etype
(Subp
)))
15026 and then Present
(Subprogram_Body
(Subp
))
15027 and then Was_Expression_Function
(Subprogram_Body
(Subp
))
15029 Return_Expr
:= Expression_Of_Expression_Function
(Subp
);
15031 -- The returned object must not have a qualified expression and its
15032 -- nominal subtype must be statically compatible with the result
15033 -- subtype of the expression function.
15036 Nkind
(Return_Expr
) = N_Identifier
15037 and then Etype
(Return_Expr
) = Etype
(Subp
);
15041 end Is_Inlinable_Expression_Function
;
15047 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
15048 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean;
15049 -- Determine whether type Iter_Typ is a predefined forward or reversible
15052 ----------------------
15053 -- Denotes_Iterator --
15054 ----------------------
15056 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean is
15058 -- Check that the name matches, and that the ultimate ancestor is in
15059 -- a predefined unit, i.e the one that declares iterator interfaces.
15062 Nam_In
(Chars
(Iter_Typ
), Name_Forward_Iterator
,
15063 Name_Reversible_Iterator
)
15064 and then In_Predefined_Unit
(Root_Type
(Iter_Typ
));
15065 end Denotes_Iterator
;
15069 Iface_Elmt
: Elmt_Id
;
15072 -- Start of processing for Is_Iterator
15075 -- The type may be a subtype of a descendant of the proper instance of
15076 -- the predefined interface type, so we must use the root type of the
15077 -- given type. The same is done for Is_Reversible_Iterator.
15079 if Is_Class_Wide_Type
(Typ
)
15080 and then Denotes_Iterator
(Root_Type
(Typ
))
15084 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
15087 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
15091 Collect_Interfaces
(Typ
, Ifaces
);
15093 Iface_Elmt
:= First_Elmt
(Ifaces
);
15094 while Present
(Iface_Elmt
) loop
15095 if Denotes_Iterator
(Node
(Iface_Elmt
)) then
15099 Next_Elmt
(Iface_Elmt
);
15106 ----------------------------
15107 -- Is_Iterator_Over_Array --
15108 ----------------------------
15110 function Is_Iterator_Over_Array
(N
: Node_Id
) return Boolean is
15111 Container
: constant Node_Id
:= Name
(N
);
15112 Container_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Container
));
15114 return Is_Array_Type
(Container_Typ
);
15115 end Is_Iterator_Over_Array
;
15121 -- We seem to have a lot of overlapping functions that do similar things
15122 -- (testing for left hand sides or lvalues???).
15124 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
15125 P
: constant Node_Id
:= Parent
(N
);
15128 -- Return True if we are the left hand side of an assignment statement
15130 if Nkind
(P
) = N_Assignment_Statement
then
15131 if Name
(P
) = N
then
15137 -- Case of prefix of indexed or selected component or slice
15139 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
15140 and then N
= Prefix
(P
)
15142 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15143 -- If P is an LHS, then N is also effectively an LHS, but there
15144 -- is an important exception. If N is of an access type, then
15145 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15146 -- case this makes N.all a left hand side but not N itself.
15148 -- If we don't know the type yet, this is the case where we return
15149 -- Unknown, since the answer depends on the type which is unknown.
15151 if No
(Etype
(N
)) then
15154 -- We have an Etype set, so we can check it
15156 elsif Is_Access_Type
(Etype
(N
)) then
15159 -- OK, not access type case, so just test whole expression
15165 -- All other cases are not left hand sides
15172 -----------------------------
15173 -- Is_Library_Level_Entity --
15174 -----------------------------
15176 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
15178 -- The following is a small optimization, and it also properly handles
15179 -- discriminals, which in task bodies might appear in expressions before
15180 -- the corresponding procedure has been created, and which therefore do
15181 -- not have an assigned scope.
15183 if Is_Formal
(E
) then
15187 -- Normal test is simply that the enclosing dynamic scope is Standard
15189 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
15190 end Is_Library_Level_Entity
;
15192 --------------------------------
15193 -- Is_Limited_Class_Wide_Type --
15194 --------------------------------
15196 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
15199 Is_Class_Wide_Type
(Typ
)
15200 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
15201 end Is_Limited_Class_Wide_Type
;
15203 ---------------------------------
15204 -- Is_Local_Variable_Reference --
15205 ---------------------------------
15207 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
15209 if not Is_Entity_Name
(Expr
) then
15214 Ent
: constant Entity_Id
:= Entity
(Expr
);
15215 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
15217 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
15220 return Present
(Sub
) and then Sub
= Current_Subprogram
;
15224 end Is_Local_Variable_Reference
;
15226 -----------------------
15227 -- Is_Name_Reference --
15228 -----------------------
15230 function Is_Name_Reference
(N
: Node_Id
) return Boolean is
15232 if Is_Entity_Name
(N
) then
15233 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
15237 when N_Indexed_Component
15241 Is_Name_Reference
(Prefix
(N
))
15242 or else Is_Access_Type
(Etype
(Prefix
(N
)));
15244 -- Attributes 'Input, 'Old and 'Result produce objects
15246 when N_Attribute_Reference
=>
15248 Nam_In
(Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
15250 when N_Selected_Component
=>
15252 Is_Name_Reference
(Selector_Name
(N
))
15254 (Is_Name_Reference
(Prefix
(N
))
15255 or else Is_Access_Type
(Etype
(Prefix
(N
))));
15257 when N_Explicit_Dereference
=>
15260 -- A view conversion of a tagged name is a name reference
15262 when N_Type_Conversion
=>
15264 Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
15265 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
15266 and then Is_Name_Reference
(Expression
(N
));
15268 -- An unchecked type conversion is considered to be a name if the
15269 -- operand is a name (this construction arises only as a result of
15270 -- expansion activities).
15272 when N_Unchecked_Type_Conversion
=>
15273 return Is_Name_Reference
(Expression
(N
));
15278 end Is_Name_Reference
;
15280 ------------------------------------
15281 -- Is_Non_Preelaborable_Construct --
15282 ------------------------------------
15284 function Is_Non_Preelaborable_Construct
(N
: Node_Id
) return Boolean is
15286 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15287 -- intentionally unnested to avoid deep indentation of code.
15289 Non_Preelaborable
: exception;
15290 -- This exception is raised when the construct violates preelaborability
15291 -- to terminate the recursion.
15293 procedure Visit
(Nod
: Node_Id
);
15294 -- Semantically inspect construct Nod to determine whether it violates
15295 -- preelaborability. This routine raises Non_Preelaborable.
15297 procedure Visit_List
(List
: List_Id
);
15298 pragma Inline
(Visit_List
);
15299 -- Invoke Visit on each element of list List. This routine raises
15300 -- Non_Preelaborable.
15302 procedure Visit_Pragma
(Prag
: Node_Id
);
15303 pragma Inline
(Visit_Pragma
);
15304 -- Semantically inspect pragma Prag to determine whether it violates
15305 -- preelaborability. This routine raises Non_Preelaborable.
15307 procedure Visit_Subexpression
(Expr
: Node_Id
);
15308 pragma Inline
(Visit_Subexpression
);
15309 -- Semantically inspect expression Expr to determine whether it violates
15310 -- preelaborability. This routine raises Non_Preelaborable.
15316 procedure Visit
(Nod
: Node_Id
) is
15318 case Nkind
(Nod
) is
15322 when N_Component_Declaration
=>
15324 -- Defining_Identifier is left out because it is not relevant
15325 -- for preelaborability.
15327 Visit
(Component_Definition
(Nod
));
15328 Visit
(Expression
(Nod
));
15330 when N_Derived_Type_Definition
=>
15332 -- Interface_List is left out because it is not relevant for
15333 -- preelaborability.
15335 Visit
(Record_Extension_Part
(Nod
));
15336 Visit
(Subtype_Indication
(Nod
));
15338 when N_Entry_Declaration
=>
15340 -- A protected type with at leat one entry is not preelaborable
15341 -- while task types are never preelaborable. This renders entry
15342 -- declarations non-preelaborable.
15344 raise Non_Preelaborable
;
15346 when N_Full_Type_Declaration
=>
15348 -- Defining_Identifier and Discriminant_Specifications are left
15349 -- out because they are not relevant for preelaborability.
15351 Visit
(Type_Definition
(Nod
));
15353 when N_Function_Instantiation
15354 | N_Package_Instantiation
15355 | N_Procedure_Instantiation
15357 -- Defining_Unit_Name and Name are left out because they are
15358 -- not relevant for preelaborability.
15360 Visit_List
(Generic_Associations
(Nod
));
15362 when N_Object_Declaration
=>
15364 -- Defining_Identifier is left out because it is not relevant
15365 -- for preelaborability.
15367 Visit
(Object_Definition
(Nod
));
15369 if Has_Init_Expression
(Nod
) then
15370 Visit
(Expression
(Nod
));
15372 elsif not Has_Preelaborable_Initialization
15373 (Etype
(Defining_Entity
(Nod
)))
15375 raise Non_Preelaborable
;
15378 when N_Private_Extension_Declaration
15379 | N_Subtype_Declaration
15381 -- Defining_Identifier, Discriminant_Specifications, and
15382 -- Interface_List are left out because they are not relevant
15383 -- for preelaborability.
15385 Visit
(Subtype_Indication
(Nod
));
15387 when N_Protected_Type_Declaration
15388 | N_Single_Protected_Declaration
15390 -- Defining_Identifier, Discriminant_Specifications, and
15391 -- Interface_List are left out because they are not relevant
15392 -- for preelaborability.
15394 Visit
(Protected_Definition
(Nod
));
15396 -- A [single] task type is never preelaborable
15398 when N_Single_Task_Declaration
15399 | N_Task_Type_Declaration
15401 raise Non_Preelaborable
;
15406 Visit_Pragma
(Nod
);
15410 when N_Statement_Other_Than_Procedure_Call
=>
15411 if Nkind
(Nod
) /= N_Null_Statement
then
15412 raise Non_Preelaborable
;
15418 Visit_Subexpression
(Nod
);
15422 when N_Access_To_Object_Definition
=>
15423 Visit
(Subtype_Indication
(Nod
));
15425 when N_Case_Expression_Alternative
=>
15426 Visit
(Expression
(Nod
));
15427 Visit_List
(Discrete_Choices
(Nod
));
15429 when N_Component_Definition
=>
15430 Visit
(Access_Definition
(Nod
));
15431 Visit
(Subtype_Indication
(Nod
));
15433 when N_Component_List
=>
15434 Visit_List
(Component_Items
(Nod
));
15435 Visit
(Variant_Part
(Nod
));
15437 when N_Constrained_Array_Definition
=>
15438 Visit_List
(Discrete_Subtype_Definitions
(Nod
));
15439 Visit
(Component_Definition
(Nod
));
15441 when N_Delta_Constraint
15442 | N_Digits_Constraint
15444 -- Delta_Expression and Digits_Expression are left out because
15445 -- they are not relevant for preelaborability.
15447 Visit
(Range_Constraint
(Nod
));
15449 when N_Discriminant_Specification
=>
15451 -- Defining_Identifier and Expression are left out because they
15452 -- are not relevant for preelaborability.
15454 Visit
(Discriminant_Type
(Nod
));
15456 when N_Generic_Association
=>
15458 -- Selector_Name is left out because it is not relevant for
15459 -- preelaborability.
15461 Visit
(Explicit_Generic_Actual_Parameter
(Nod
));
15463 when N_Index_Or_Discriminant_Constraint
=>
15464 Visit_List
(Constraints
(Nod
));
15466 when N_Iterator_Specification
=>
15468 -- Defining_Identifier is left out because it is not relevant
15469 -- for preelaborability.
15471 Visit
(Name
(Nod
));
15472 Visit
(Subtype_Indication
(Nod
));
15474 when N_Loop_Parameter_Specification
=>
15476 -- Defining_Identifier is left out because it is not relevant
15477 -- for preelaborability.
15479 Visit
(Discrete_Subtype_Definition
(Nod
));
15481 when N_Protected_Definition
=>
15483 -- End_Label is left out because it is not relevant for
15484 -- preelaborability.
15486 Visit_List
(Private_Declarations
(Nod
));
15487 Visit_List
(Visible_Declarations
(Nod
));
15489 when N_Range_Constraint
=>
15490 Visit
(Range_Expression
(Nod
));
15492 when N_Record_Definition
15495 -- End_Label, Discrete_Choices, and Interface_List are left out
15496 -- because they are not relevant for preelaborability.
15498 Visit
(Component_List
(Nod
));
15500 when N_Subtype_Indication
=>
15502 -- Subtype_Mark is left out because it is not relevant for
15503 -- preelaborability.
15505 Visit
(Constraint
(Nod
));
15507 when N_Unconstrained_Array_Definition
=>
15509 -- Subtype_Marks is left out because it is not relevant for
15510 -- preelaborability.
15512 Visit
(Component_Definition
(Nod
));
15514 when N_Variant_Part
=>
15516 -- Name is left out because it is not relevant for
15517 -- preelaborability.
15519 Visit_List
(Variants
(Nod
));
15532 procedure Visit_List
(List
: List_Id
) is
15536 if Present
(List
) then
15537 Nod
:= First
(List
);
15538 while Present
(Nod
) loop
15549 procedure Visit_Pragma
(Prag
: Node_Id
) is
15551 case Get_Pragma_Id
(Prag
) is
15553 | Pragma_Assert_And_Cut
15555 | Pragma_Async_Readers
15556 | Pragma_Async_Writers
15557 | Pragma_Attribute_Definition
15559 | Pragma_Constant_After_Elaboration
15561 | Pragma_Deadline_Floor
15562 | Pragma_Dispatching_Domain
15563 | Pragma_Effective_Reads
15564 | Pragma_Effective_Writes
15565 | Pragma_Extensions_Visible
15567 | Pragma_Secondary_Stack_Size
15569 | Pragma_Volatile_Function
15571 Visit_List
(Pragma_Argument_Associations
(Prag
));
15580 -------------------------
15581 -- Visit_Subexpression --
15582 -------------------------
15584 procedure Visit_Subexpression
(Expr
: Node_Id
) is
15585 procedure Visit_Aggregate
(Aggr
: Node_Id
);
15586 pragma Inline
(Visit_Aggregate
);
15587 -- Semantically inspect aggregate Aggr to determine whether it
15588 -- violates preelaborability.
15590 ---------------------
15591 -- Visit_Aggregate --
15592 ---------------------
15594 procedure Visit_Aggregate
(Aggr
: Node_Id
) is
15596 if not Is_Preelaborable_Aggregate
(Aggr
) then
15597 raise Non_Preelaborable
;
15599 end Visit_Aggregate
;
15601 -- Start of processing for Visit_Subexpression
15604 case Nkind
(Expr
) is
15606 | N_Qualified_Expression
15607 | N_Type_Conversion
15608 | N_Unchecked_Expression
15609 | N_Unchecked_Type_Conversion
15611 -- Subpool_Handle_Name and Subtype_Mark are left out because
15612 -- they are not relevant for preelaborability.
15614 Visit
(Expression
(Expr
));
15617 | N_Extension_Aggregate
15619 Visit_Aggregate
(Expr
);
15621 when N_Attribute_Reference
15622 | N_Explicit_Dereference
15625 -- Attribute_Name and Expressions are left out because they are
15626 -- not relevant for preelaborability.
15628 Visit
(Prefix
(Expr
));
15630 when N_Case_Expression
=>
15632 -- End_Span is left out because it is not relevant for
15633 -- preelaborability.
15635 Visit_List
(Alternatives
(Expr
));
15636 Visit
(Expression
(Expr
));
15638 when N_Delta_Aggregate
=>
15639 Visit_Aggregate
(Expr
);
15640 Visit
(Expression
(Expr
));
15642 when N_Expression_With_Actions
=>
15643 Visit_List
(Actions
(Expr
));
15644 Visit
(Expression
(Expr
));
15646 when N_If_Expression
=>
15647 Visit_List
(Expressions
(Expr
));
15649 when N_Quantified_Expression
=>
15650 Visit
(Condition
(Expr
));
15651 Visit
(Iterator_Specification
(Expr
));
15652 Visit
(Loop_Parameter_Specification
(Expr
));
15655 Visit
(High_Bound
(Expr
));
15656 Visit
(Low_Bound
(Expr
));
15659 Visit
(Discrete_Range
(Expr
));
15660 Visit
(Prefix
(Expr
));
15666 -- The evaluation of an object name is not preelaborable,
15667 -- unless the name is a static expression (checked further
15668 -- below), or statically denotes a discriminant.
15670 if Is_Entity_Name
(Expr
) then
15671 Object_Name
: declare
15672 Id
: constant Entity_Id
:= Entity
(Expr
);
15675 if Is_Object
(Id
) then
15676 if Ekind
(Id
) = E_Discriminant
then
15679 elsif Ekind_In
(Id
, E_Constant
, E_In_Parameter
)
15680 and then Present
(Discriminal_Link
(Id
))
15685 raise Non_Preelaborable
;
15690 -- A non-static expression is not preelaborable
15692 elsif not Is_OK_Static_Expression
(Expr
) then
15693 raise Non_Preelaborable
;
15696 end Visit_Subexpression
;
15698 -- Start of processing for Is_Non_Preelaborable_Construct
15703 -- At this point it is known that the construct is preelaborable
15709 -- The elaboration of the construct performs an action which violates
15710 -- preelaborability.
15712 when Non_Preelaborable
=>
15714 end Is_Non_Preelaborable_Construct
;
15716 ---------------------------------
15717 -- Is_Nontrivial_DIC_Procedure --
15718 ---------------------------------
15720 function Is_Nontrivial_DIC_Procedure
(Id
: Entity_Id
) return Boolean is
15721 Body_Decl
: Node_Id
;
15725 if Ekind
(Id
) = E_Procedure
and then Is_DIC_Procedure
(Id
) then
15727 Unit_Declaration_Node
15728 (Corresponding_Body
(Unit_Declaration_Node
(Id
)));
15730 -- The body of the Default_Initial_Condition procedure must contain
15731 -- at least one statement, otherwise the generation of the subprogram
15734 pragma Assert
(Present
(Handled_Statement_Sequence
(Body_Decl
)));
15736 -- To qualify as nontrivial, the first statement of the procedure
15737 -- must be a check in the form of an if statement. If the original
15738 -- Default_Initial_Condition expression was folded, then the first
15739 -- statement is not a check.
15741 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Body_Decl
)));
15744 Nkind
(Stmt
) = N_If_Statement
15745 and then Nkind
(Original_Node
(Stmt
)) = N_Pragma
;
15749 end Is_Nontrivial_DIC_Procedure
;
15751 -------------------------
15752 -- Is_Null_Record_Type --
15753 -------------------------
15755 function Is_Null_Record_Type
(T
: Entity_Id
) return Boolean is
15756 Decl
: constant Node_Id
:= Parent
(T
);
15758 return Nkind
(Decl
) = N_Full_Type_Declaration
15759 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
15761 (No
(Component_List
(Type_Definition
(Decl
)))
15762 or else Null_Present
(Component_List
(Type_Definition
(Decl
))));
15763 end Is_Null_Record_Type
;
15765 ---------------------
15766 -- Is_Object_Image --
15767 ---------------------
15769 function Is_Object_Image
(Prefix
: Node_Id
) return Boolean is
15771 -- When the type of the prefix is not scalar, then the prefix is not
15772 -- valid in any scenario.
15774 if not Is_Scalar_Type
(Etype
(Prefix
)) then
15778 -- Here we test for the case that the prefix is not a type and assume
15779 -- if it is not then it must be a named value or an object reference.
15780 -- This is because the parser always checks that prefixes of attributes
15783 return not (Is_Entity_Name
(Prefix
) and then Is_Type
(Entity
(Prefix
)));
15784 end Is_Object_Image
;
15786 -------------------------
15787 -- Is_Object_Reference --
15788 -------------------------
15790 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
15791 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
15792 -- Determine whether N is the name of an internally-generated renaming
15794 --------------------------------------
15795 -- Is_Internally_Generated_Renaming --
15796 --------------------------------------
15798 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
15803 while Present
(P
) loop
15804 if Nkind
(P
) = N_Object_Renaming_Declaration
then
15805 return not Comes_From_Source
(P
);
15806 elsif Is_List_Member
(P
) then
15814 end Is_Internally_Generated_Renaming
;
15816 -- Start of processing for Is_Object_Reference
15819 if Is_Entity_Name
(N
) then
15820 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
15824 when N_Indexed_Component
15828 Is_Object_Reference
(Prefix
(N
))
15829 or else Is_Access_Type
(Etype
(Prefix
(N
)));
15831 -- In Ada 95, a function call is a constant object; a procedure
15834 -- Note that predefined operators are functions as well, and so
15835 -- are attributes that are (can be renamed as) functions.
15841 return Etype
(N
) /= Standard_Void_Type
;
15843 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
15844 -- objects, even though they are not functions.
15846 when N_Attribute_Reference
=>
15848 Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
15851 or else Is_Function_Attribute_Name
(Attribute_Name
(N
));
15853 when N_Selected_Component
=>
15855 Is_Object_Reference
(Selector_Name
(N
))
15857 (Is_Object_Reference
(Prefix
(N
))
15858 or else Is_Access_Type
(Etype
(Prefix
(N
))));
15860 -- An explicit dereference denotes an object, except that a
15861 -- conditional expression gets turned into an explicit dereference
15862 -- in some cases, and conditional expressions are not object
15865 when N_Explicit_Dereference
=>
15866 return not Nkind_In
(Original_Node
(N
), N_Case_Expression
,
15869 -- A view conversion of a tagged object is an object reference
15871 when N_Type_Conversion
=>
15872 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
15873 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
15874 and then Is_Object_Reference
(Expression
(N
));
15876 -- An unchecked type conversion is considered to be an object if
15877 -- the operand is an object (this construction arises only as a
15878 -- result of expansion activities).
15880 when N_Unchecked_Type_Conversion
=>
15883 -- Allow string literals to act as objects as long as they appear
15884 -- in internally-generated renamings. The expansion of iterators
15885 -- may generate such renamings when the range involves a string
15888 when N_String_Literal
=>
15889 return Is_Internally_Generated_Renaming
(Parent
(N
));
15891 -- AI05-0003: In Ada 2012 a qualified expression is a name.
15892 -- This allows disambiguation of function calls and the use
15893 -- of aggregates in more contexts.
15895 when N_Qualified_Expression
=>
15896 if Ada_Version
< Ada_2012
then
15899 return Is_Object_Reference
(Expression
(N
))
15900 or else Nkind
(Expression
(N
)) = N_Aggregate
;
15907 end Is_Object_Reference
;
15909 -----------------------------------
15910 -- Is_OK_Variable_For_Out_Formal --
15911 -----------------------------------
15913 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
15915 Note_Possible_Modification
(AV
, Sure
=> True);
15917 -- We must reject parenthesized variable names. Comes_From_Source is
15918 -- checked because there are currently cases where the compiler violates
15919 -- this rule (e.g. passing a task object to its controlled Initialize
15920 -- routine). This should be properly documented in sinfo???
15922 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
15925 -- A variable is always allowed
15927 elsif Is_Variable
(AV
) then
15930 -- Generalized indexing operations are rewritten as explicit
15931 -- dereferences, and it is only during resolution that we can
15932 -- check whether the context requires an access_to_variable type.
15934 elsif Nkind
(AV
) = N_Explicit_Dereference
15935 and then Ada_Version
>= Ada_2012
15936 and then Nkind
(Original_Node
(AV
)) = N_Indexed_Component
15937 and then Present
(Etype
(Original_Node
(AV
)))
15938 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
15940 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
15942 -- Unchecked conversions are allowed only if they come from the
15943 -- generated code, which sometimes uses unchecked conversions for out
15944 -- parameters in cases where code generation is unaffected. We tell
15945 -- source unchecked conversions by seeing if they are rewrites of
15946 -- an original Unchecked_Conversion function call, or of an explicit
15947 -- conversion of a function call or an aggregate (as may happen in the
15948 -- expansion of a packed array aggregate).
15950 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
15951 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
15954 elsif Comes_From_Source
(AV
)
15955 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
15959 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
15960 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
15966 -- Normal type conversions are allowed if argument is a variable
15968 elsif Nkind
(AV
) = N_Type_Conversion
then
15969 if Is_Variable
(Expression
(AV
))
15970 and then Paren_Count
(Expression
(AV
)) = 0
15972 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
15975 -- We also allow a non-parenthesized expression that raises
15976 -- constraint error if it rewrites what used to be a variable
15978 elsif Raises_Constraint_Error
(Expression
(AV
))
15979 and then Paren_Count
(Expression
(AV
)) = 0
15980 and then Is_Variable
(Original_Node
(Expression
(AV
)))
15984 -- Type conversion of something other than a variable
15990 -- If this node is rewritten, then test the original form, if that is
15991 -- OK, then we consider the rewritten node OK (for example, if the
15992 -- original node is a conversion, then Is_Variable will not be true
15993 -- but we still want to allow the conversion if it converts a variable).
15995 elsif Is_Rewrite_Substitution
(AV
) then
15997 -- In Ada 2012, the explicit dereference may be a rewritten call to a
15998 -- Reference function.
16000 if Ada_Version
>= Ada_2012
16001 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
16003 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
16006 -- Check that this is not a constant reference.
16008 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
16010 elsif Has_Implicit_Dereference
(Etype
(Original_Node
(AV
))) then
16012 not Is_Access_Constant
(Etype
16013 (Get_Reference_Discriminant
(Etype
(Original_Node
(AV
)))));
16016 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
16019 -- All other non-variables are rejected
16024 end Is_OK_Variable_For_Out_Formal
;
16026 ----------------------------
16027 -- Is_OK_Volatile_Context --
16028 ----------------------------
16030 function Is_OK_Volatile_Context
16031 (Context
: Node_Id
;
16032 Obj_Ref
: Node_Id
) return Boolean
16034 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean;
16035 -- Determine whether an arbitrary node denotes a call to a protected
16036 -- entry, function, or procedure in prefixed form where the prefix is
16039 function Within_Check
(Nod
: Node_Id
) return Boolean;
16040 -- Determine whether an arbitrary node appears in a check node
16042 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean;
16043 -- Determine whether an arbitrary entity appears in a volatile function
16045 ---------------------------------
16046 -- Is_Protected_Operation_Call --
16047 ---------------------------------
16049 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean is
16054 -- A call to a protected operations retains its selected component
16055 -- form as opposed to other prefixed calls that are transformed in
16058 if Nkind
(Nod
) = N_Selected_Component
then
16059 Pref
:= Prefix
(Nod
);
16060 Subp
:= Selector_Name
(Nod
);
16064 and then Present
(Etype
(Pref
))
16065 and then Is_Protected_Type
(Etype
(Pref
))
16066 and then Is_Entity_Name
(Subp
)
16067 and then Present
(Entity
(Subp
))
16068 and then Ekind_In
(Entity
(Subp
), E_Entry
,
16075 end Is_Protected_Operation_Call
;
16081 function Within_Check
(Nod
: Node_Id
) return Boolean is
16085 -- Climb the parent chain looking for a check node
16088 while Present
(Par
) loop
16089 if Nkind
(Par
) in N_Raise_xxx_Error
then
16092 -- Prevent the search from going too far
16094 elsif Is_Body_Or_Package_Declaration
(Par
) then
16098 Par
:= Parent
(Par
);
16104 ------------------------------
16105 -- Within_Volatile_Function --
16106 ------------------------------
16108 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean is
16109 Func_Id
: Entity_Id
;
16112 -- Traverse the scope stack looking for a [generic] function
16115 while Present
(Func_Id
) and then Func_Id
/= Standard_Standard
loop
16116 if Ekind_In
(Func_Id
, E_Function
, E_Generic_Function
) then
16117 return Is_Volatile_Function
(Func_Id
);
16120 Func_Id
:= Scope
(Func_Id
);
16124 end Within_Volatile_Function
;
16128 Obj_Id
: Entity_Id
;
16130 -- Start of processing for Is_OK_Volatile_Context
16133 -- The volatile object appears on either side of an assignment
16135 if Nkind
(Context
) = N_Assignment_Statement
then
16138 -- The volatile object is part of the initialization expression of
16141 elsif Nkind
(Context
) = N_Object_Declaration
16142 and then Present
(Expression
(Context
))
16143 and then Expression
(Context
) = Obj_Ref
16145 Obj_Id
:= Defining_Entity
(Context
);
16147 -- The volatile object acts as the initialization expression of an
16148 -- extended return statement. This is valid context as long as the
16149 -- function is volatile.
16151 if Is_Return_Object
(Obj_Id
) then
16152 return Within_Volatile_Function
(Obj_Id
);
16154 -- Otherwise this is a normal object initialization
16160 -- The volatile object acts as the name of a renaming declaration
16162 elsif Nkind
(Context
) = N_Object_Renaming_Declaration
16163 and then Name
(Context
) = Obj_Ref
16167 -- The volatile object appears as an actual parameter in a call to an
16168 -- instance of Unchecked_Conversion whose result is renamed.
16170 elsif Nkind
(Context
) = N_Function_Call
16171 and then Is_Entity_Name
(Name
(Context
))
16172 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
16173 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
16177 -- The volatile object is actually the prefix in a protected entry,
16178 -- function, or procedure call.
16180 elsif Is_Protected_Operation_Call
(Context
) then
16183 -- The volatile object appears as the expression of a simple return
16184 -- statement that applies to a volatile function.
16186 elsif Nkind
(Context
) = N_Simple_Return_Statement
16187 and then Expression
(Context
) = Obj_Ref
16190 Within_Volatile_Function
(Return_Statement_Entity
(Context
));
16192 -- The volatile object appears as the prefix of a name occurring in a
16193 -- non-interfering context.
16195 elsif Nkind_In
(Context
, N_Attribute_Reference
,
16196 N_Explicit_Dereference
,
16197 N_Indexed_Component
,
16198 N_Selected_Component
,
16200 and then Prefix
(Context
) = Obj_Ref
16201 and then Is_OK_Volatile_Context
16202 (Context
=> Parent
(Context
),
16203 Obj_Ref
=> Context
)
16207 -- The volatile object appears as the prefix of attributes Address,
16208 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16209 -- Position, Size, Storage_Size.
16211 elsif Nkind
(Context
) = N_Attribute_Reference
16212 and then Prefix
(Context
) = Obj_Ref
16213 and then Nam_In
(Attribute_Name
(Context
), Name_Address
,
16215 Name_Component_Size
,
16227 -- The volatile object appears as the expression of a type conversion
16228 -- occurring in a non-interfering context.
16230 elsif Nkind_In
(Context
, N_Type_Conversion
,
16231 N_Unchecked_Type_Conversion
)
16232 and then Expression
(Context
) = Obj_Ref
16233 and then Is_OK_Volatile_Context
16234 (Context
=> Parent
(Context
),
16235 Obj_Ref
=> Context
)
16239 -- The volatile object appears as the expression in a delay statement
16241 elsif Nkind
(Context
) in N_Delay_Statement
then
16244 -- Allow references to volatile objects in various checks. This is not a
16245 -- direct SPARK 2014 requirement.
16247 elsif Within_Check
(Context
) then
16250 -- Assume that references to effectively volatile objects that appear
16251 -- as actual parameters in a subprogram call are always legal. A full
16252 -- legality check is done when the actuals are resolved (see routine
16253 -- Resolve_Actuals).
16255 elsif Within_Subprogram_Call
(Context
) then
16258 -- Otherwise the context is not suitable for an effectively volatile
16264 end Is_OK_Volatile_Context
;
16266 ------------------------------------
16267 -- Is_Package_Contract_Annotation --
16268 ------------------------------------
16270 function Is_Package_Contract_Annotation
(Item
: Node_Id
) return Boolean is
16274 if Nkind
(Item
) = N_Aspect_Specification
then
16275 Nam
:= Chars
(Identifier
(Item
));
16277 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
16278 Nam
:= Pragma_Name
(Item
);
16281 return Nam
= Name_Abstract_State
16282 or else Nam
= Name_Initial_Condition
16283 or else Nam
= Name_Initializes
16284 or else Nam
= Name_Refined_State
;
16285 end Is_Package_Contract_Annotation
;
16287 -----------------------------------
16288 -- Is_Partially_Initialized_Type --
16289 -----------------------------------
16291 function Is_Partially_Initialized_Type
16293 Include_Implicit
: Boolean := True) return Boolean
16296 if Is_Scalar_Type
(Typ
) then
16299 elsif Is_Access_Type
(Typ
) then
16300 return Include_Implicit
;
16302 elsif Is_Array_Type
(Typ
) then
16304 -- If component type is partially initialized, so is array type
16306 if Is_Partially_Initialized_Type
16307 (Component_Type
(Typ
), Include_Implicit
)
16311 -- Otherwise we are only partially initialized if we are fully
16312 -- initialized (this is the empty array case, no point in us
16313 -- duplicating that code here).
16316 return Is_Fully_Initialized_Type
(Typ
);
16319 elsif Is_Record_Type
(Typ
) then
16321 -- A discriminated type is always partially initialized if in
16324 if Has_Discriminants
(Typ
) and then Include_Implicit
then
16327 -- A tagged type is always partially initialized
16329 elsif Is_Tagged_Type
(Typ
) then
16332 -- Case of non-discriminated record
16338 Component_Present
: Boolean := False;
16339 -- Set True if at least one component is present. If no
16340 -- components are present, then record type is fully
16341 -- initialized (another odd case, like the null array).
16344 -- Loop through components
16346 Ent
:= First_Entity
(Typ
);
16347 while Present
(Ent
) loop
16348 if Ekind
(Ent
) = E_Component
then
16349 Component_Present
:= True;
16351 -- If a component has an initialization expression then
16352 -- the enclosing record type is partially initialized
16354 if Present
(Parent
(Ent
))
16355 and then Present
(Expression
(Parent
(Ent
)))
16359 -- If a component is of a type which is itself partially
16360 -- initialized, then the enclosing record type is also.
16362 elsif Is_Partially_Initialized_Type
16363 (Etype
(Ent
), Include_Implicit
)
16372 -- No initialized components found. If we found any components
16373 -- they were all uninitialized so the result is false.
16375 if Component_Present
then
16378 -- But if we found no components, then all the components are
16379 -- initialized so we consider the type to be initialized.
16387 -- Concurrent types are always fully initialized
16389 elsif Is_Concurrent_Type
(Typ
) then
16392 -- For a private type, go to underlying type. If there is no underlying
16393 -- type then just assume this partially initialized. Not clear if this
16394 -- can happen in a non-error case, but no harm in testing for this.
16396 elsif Is_Private_Type
(Typ
) then
16398 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
16403 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
16407 -- For any other type (are there any?) assume partially initialized
16412 end Is_Partially_Initialized_Type
;
16414 ------------------------------------
16415 -- Is_Potentially_Persistent_Type --
16416 ------------------------------------
16418 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
16423 -- For private type, test corresponding full type
16425 if Is_Private_Type
(T
) then
16426 return Is_Potentially_Persistent_Type
(Full_View
(T
));
16428 -- Scalar types are potentially persistent
16430 elsif Is_Scalar_Type
(T
) then
16433 -- Record type is potentially persistent if not tagged and the types of
16434 -- all it components are potentially persistent, and no component has
16435 -- an initialization expression.
16437 elsif Is_Record_Type
(T
)
16438 and then not Is_Tagged_Type
(T
)
16439 and then not Is_Partially_Initialized_Type
(T
)
16441 Comp
:= First_Component
(T
);
16442 while Present
(Comp
) loop
16443 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
16446 Next_Entity
(Comp
);
16452 -- Array type is potentially persistent if its component type is
16453 -- potentially persistent and if all its constraints are static.
16455 elsif Is_Array_Type
(T
) then
16456 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
16460 Indx
:= First_Index
(T
);
16461 while Present
(Indx
) loop
16462 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
16471 -- All other types are not potentially persistent
16476 end Is_Potentially_Persistent_Type
;
16478 --------------------------------
16479 -- Is_Potentially_Unevaluated --
16480 --------------------------------
16482 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
16490 -- A postcondition whose expression is a short-circuit is broken down
16491 -- into individual aspects for better exception reporting. The original
16492 -- short-circuit expression is rewritten as the second operand, and an
16493 -- occurrence of 'Old in that operand is potentially unevaluated.
16494 -- See sem_ch13.adb for details of this transformation. The reference
16495 -- to 'Old may appear within an expression, so we must look for the
16496 -- enclosing pragma argument in the tree that contains the reference.
16498 while Present
(Par
)
16499 and then Nkind
(Par
) /= N_Pragma_Argument_Association
16501 if Is_Rewrite_Substitution
(Par
)
16502 and then Nkind
(Original_Node
(Par
)) = N_And_Then
16507 Par
:= Parent
(Par
);
16510 -- Other cases; 'Old appears within other expression (not the top-level
16511 -- conjunct in a postcondition) with a potentially unevaluated operand.
16513 Par
:= Parent
(Expr
);
16514 while not Nkind_In
(Par
, N_And_Then
,
16520 N_Quantified_Expression
)
16523 Par
:= Parent
(Par
);
16525 -- If the context is not an expression, or if is the result of
16526 -- expansion of an enclosing construct (such as another attribute)
16527 -- the predicate does not apply.
16529 if Nkind
(Par
) = N_Case_Expression_Alternative
then
16532 elsif Nkind
(Par
) not in N_Subexpr
16533 or else not Comes_From_Source
(Par
)
16539 if Nkind
(Par
) = N_If_Expression
then
16540 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
16542 elsif Nkind
(Par
) = N_Case_Expression
then
16543 return Expr
/= Expression
(Par
);
16545 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
16546 return Expr
= Right_Opnd
(Par
);
16548 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
16550 -- If the membership includes several alternatives, only the first is
16551 -- definitely evaluated.
16553 if Present
(Alternatives
(Par
)) then
16554 return Expr
/= First
(Alternatives
(Par
));
16556 -- If this is a range membership both bounds are evaluated
16562 elsif Nkind
(Par
) = N_Quantified_Expression
then
16563 return Expr
= Condition
(Par
);
16568 end Is_Potentially_Unevaluated
;
16570 -----------------------------------------
16571 -- Is_Predefined_Dispatching_Operation --
16572 -----------------------------------------
16574 function Is_Predefined_Dispatching_Operation
16575 (E
: Entity_Id
) return Boolean
16577 TSS_Name
: TSS_Name_Type
;
16580 if not Is_Dispatching_Operation
(E
) then
16584 Get_Name_String
(Chars
(E
));
16586 -- Most predefined primitives have internally generated names. Equality
16587 -- must be treated differently; the predefined operation is recognized
16588 -- as a homogeneous binary operator that returns Boolean.
16590 if Name_Len
> TSS_Name_Type
'Last then
16593 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
16595 if Nam_In
(Chars
(E
), Name_uAssign
, Name_uSize
)
16597 (Chars
(E
) = Name_Op_Eq
16598 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
16599 or else TSS_Name
= TSS_Deep_Adjust
16600 or else TSS_Name
= TSS_Deep_Finalize
16601 or else TSS_Name
= TSS_Stream_Input
16602 or else TSS_Name
= TSS_Stream_Output
16603 or else TSS_Name
= TSS_Stream_Read
16604 or else TSS_Name
= TSS_Stream_Write
16605 or else Is_Predefined_Interface_Primitive
(E
)
16612 end Is_Predefined_Dispatching_Operation
;
16614 ---------------------------------------
16615 -- Is_Predefined_Interface_Primitive --
16616 ---------------------------------------
16618 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
16620 -- In VM targets we don't restrict the functionality of this test to
16621 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16622 -- these primitives.
16624 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
16625 and then Nam_In
(Chars
(E
), Name_uDisp_Asynchronous_Select
,
16626 Name_uDisp_Conditional_Select
,
16627 Name_uDisp_Get_Prim_Op_Kind
,
16628 Name_uDisp_Get_Task_Id
,
16629 Name_uDisp_Requeue
,
16630 Name_uDisp_Timed_Select
);
16631 end Is_Predefined_Interface_Primitive
;
16633 ---------------------------------------
16634 -- Is_Predefined_Internal_Operation --
16635 ---------------------------------------
16637 function Is_Predefined_Internal_Operation
16638 (E
: Entity_Id
) return Boolean
16640 TSS_Name
: TSS_Name_Type
;
16643 if not Is_Dispatching_Operation
(E
) then
16647 Get_Name_String
(Chars
(E
));
16649 -- Most predefined primitives have internally generated names. Equality
16650 -- must be treated differently; the predefined operation is recognized
16651 -- as a homogeneous binary operator that returns Boolean.
16653 if Name_Len
> TSS_Name_Type
'Last then
16656 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
16658 if Nam_In
(Chars
(E
), Name_uSize
, Name_uAssign
)
16660 (Chars
(E
) = Name_Op_Eq
16661 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
16662 or else TSS_Name
= TSS_Deep_Adjust
16663 or else TSS_Name
= TSS_Deep_Finalize
16664 or else Is_Predefined_Interface_Primitive
(E
)
16671 end Is_Predefined_Internal_Operation
;
16673 --------------------------------
16674 -- Is_Preelaborable_Aggregate --
16675 --------------------------------
16677 function Is_Preelaborable_Aggregate
(Aggr
: Node_Id
) return Boolean is
16678 Aggr_Typ
: constant Entity_Id
:= Etype
(Aggr
);
16679 Array_Aggr
: constant Boolean := Is_Array_Type
(Aggr_Typ
);
16681 Anc_Part
: Node_Id
;
16684 Comp_Typ
: Entity_Id
:= Empty
; -- init to avoid warning
16689 Comp_Typ
:= Component_Type
(Aggr_Typ
);
16692 -- Inspect the ancestor part
16694 if Nkind
(Aggr
) = N_Extension_Aggregate
then
16695 Anc_Part
:= Ancestor_Part
(Aggr
);
16697 -- The ancestor denotes a subtype mark
16699 if Is_Entity_Name
(Anc_Part
)
16700 and then Is_Type
(Entity
(Anc_Part
))
16702 if not Has_Preelaborable_Initialization
(Entity
(Anc_Part
)) then
16706 -- Otherwise the ancestor denotes an expression
16708 elsif not Is_Preelaborable_Construct
(Anc_Part
) then
16713 -- Inspect the positional associations
16715 Expr
:= First
(Expressions
(Aggr
));
16716 while Present
(Expr
) loop
16717 if not Is_Preelaborable_Construct
(Expr
) then
16724 -- Inspect the named associations
16726 Assoc
:= First
(Component_Associations
(Aggr
));
16727 while Present
(Assoc
) loop
16729 -- Inspect the choices of the current named association
16731 Choice
:= First
(Choices
(Assoc
));
16732 while Present
(Choice
) loop
16735 -- For a choice to be preelaborable, it must denote either a
16736 -- static range or a static expression.
16738 if Nkind
(Choice
) = N_Others_Choice
then
16741 elsif Nkind
(Choice
) = N_Range
then
16742 if not Is_OK_Static_Range
(Choice
) then
16746 elsif not Is_OK_Static_Expression
(Choice
) then
16751 Comp_Typ
:= Etype
(Choice
);
16757 -- The type of the choice must have preelaborable initialization if
16758 -- the association carries a <>.
16760 pragma Assert
(Present
(Comp_Typ
));
16761 if Box_Present
(Assoc
) then
16762 if not Has_Preelaborable_Initialization
(Comp_Typ
) then
16766 -- The type of the expression must have preelaborable initialization
16768 elsif not Is_Preelaborable_Construct
(Expression
(Assoc
)) then
16775 -- At this point the aggregate is preelaborable
16778 end Is_Preelaborable_Aggregate
;
16780 --------------------------------
16781 -- Is_Preelaborable_Construct --
16782 --------------------------------
16784 function Is_Preelaborable_Construct
(N
: Node_Id
) return Boolean is
16788 if Nkind_In
(N
, N_Aggregate
, N_Extension_Aggregate
) then
16789 return Is_Preelaborable_Aggregate
(N
);
16791 -- Attributes are allowed in general, even if their prefix is a formal
16792 -- type. It seems that certain attributes known not to be static might
16793 -- not be allowed, but there are no rules to prevent them.
16795 elsif Nkind
(N
) = N_Attribute_Reference
then
16800 elsif Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
16803 elsif Nkind
(N
) = N_Qualified_Expression
then
16804 return Is_Preelaborable_Construct
(Expression
(N
));
16806 -- Names are preelaborable when they denote a discriminant of an
16807 -- enclosing type. Discriminals are also considered for this check.
16809 elsif Is_Entity_Name
(N
)
16810 and then Present
(Entity
(N
))
16812 (Ekind
(Entity
(N
)) = E_Discriminant
16813 or else (Ekind_In
(Entity
(N
), E_Constant
, E_In_Parameter
)
16814 and then Present
(Discriminal_Link
(Entity
(N
)))))
16820 elsif Nkind
(N
) = N_Null
then
16823 -- Otherwise the construct is not preelaborable
16828 end Is_Preelaborable_Construct
;
16830 ---------------------------------
16831 -- Is_Protected_Self_Reference --
16832 ---------------------------------
16834 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
16836 function In_Access_Definition
(N
: Node_Id
) return Boolean;
16837 -- Returns true if N belongs to an access definition
16839 --------------------------
16840 -- In_Access_Definition --
16841 --------------------------
16843 function In_Access_Definition
(N
: Node_Id
) return Boolean is
16848 while Present
(P
) loop
16849 if Nkind
(P
) = N_Access_Definition
then
16857 end In_Access_Definition
;
16859 -- Start of processing for Is_Protected_Self_Reference
16862 -- Verify that prefix is analyzed and has the proper form. Note that
16863 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
16864 -- produce the address of an entity, do not analyze their prefix
16865 -- because they denote entities that are not necessarily visible.
16866 -- Neither of them can apply to a protected type.
16868 return Ada_Version
>= Ada_2005
16869 and then Is_Entity_Name
(N
)
16870 and then Present
(Entity
(N
))
16871 and then Is_Protected_Type
(Entity
(N
))
16872 and then In_Open_Scopes
(Entity
(N
))
16873 and then not In_Access_Definition
(N
);
16874 end Is_Protected_Self_Reference
;
16876 -----------------------------
16877 -- Is_RCI_Pkg_Spec_Or_Body --
16878 -----------------------------
16880 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
16882 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
16883 -- Return True if the unit of Cunit is an RCI package declaration
16885 ---------------------------
16886 -- Is_RCI_Pkg_Decl_Cunit --
16887 ---------------------------
16889 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
16890 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
16893 if Nkind
(The_Unit
) /= N_Package_Declaration
then
16897 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
16898 end Is_RCI_Pkg_Decl_Cunit
;
16900 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
16903 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
16905 (Nkind
(Unit
(Cunit
)) = N_Package_Body
16906 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
16907 end Is_RCI_Pkg_Spec_Or_Body
;
16909 -----------------------------------------
16910 -- Is_Remote_Access_To_Class_Wide_Type --
16911 -----------------------------------------
16913 function Is_Remote_Access_To_Class_Wide_Type
16914 (E
: Entity_Id
) return Boolean
16917 -- A remote access to class-wide type is a general access to object type
16918 -- declared in the visible part of a Remote_Types or Remote_Call_
16921 return Ekind
(E
) = E_General_Access_Type
16922 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
16923 end Is_Remote_Access_To_Class_Wide_Type
;
16925 -----------------------------------------
16926 -- Is_Remote_Access_To_Subprogram_Type --
16927 -----------------------------------------
16929 function Is_Remote_Access_To_Subprogram_Type
16930 (E
: Entity_Id
) return Boolean
16933 return (Ekind
(E
) = E_Access_Subprogram_Type
16934 or else (Ekind
(E
) = E_Record_Type
16935 and then Present
(Corresponding_Remote_Type
(E
))))
16936 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
16937 end Is_Remote_Access_To_Subprogram_Type
;
16939 --------------------
16940 -- Is_Remote_Call --
16941 --------------------
16943 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
16945 if Nkind
(N
) not in N_Subprogram_Call
then
16947 -- An entry call cannot be remote
16951 elsif Nkind
(Name
(N
)) in N_Has_Entity
16952 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
16954 -- A subprogram declared in the spec of a RCI package is remote
16958 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
16959 and then Is_Remote_Access_To_Subprogram_Type
16960 (Etype
(Prefix
(Name
(N
))))
16962 -- The dereference of a RAS is a remote call
16966 elsif Present
(Controlling_Argument
(N
))
16967 and then Is_Remote_Access_To_Class_Wide_Type
16968 (Etype
(Controlling_Argument
(N
)))
16970 -- Any primitive operation call with a controlling argument of
16971 -- a RACW type is a remote call.
16976 -- All other calls are local calls
16979 end Is_Remote_Call
;
16981 ----------------------
16982 -- Is_Renamed_Entry --
16983 ----------------------
16985 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
16986 Orig_Node
: Node_Id
:= Empty
;
16987 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
16989 function Is_Entry
(Nam
: Node_Id
) return Boolean;
16990 -- Determine whether Nam is an entry. Traverse selectors if there are
16991 -- nested selected components.
16997 function Is_Entry
(Nam
: Node_Id
) return Boolean is
16999 if Nkind
(Nam
) = N_Selected_Component
then
17000 return Is_Entry
(Selector_Name
(Nam
));
17003 return Ekind
(Entity
(Nam
)) = E_Entry
;
17006 -- Start of processing for Is_Renamed_Entry
17009 if Present
(Alias
(Proc_Nam
)) then
17010 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
17013 -- Look for a rewritten subprogram renaming declaration
17015 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
17016 and then Present
(Original_Node
(Subp_Decl
))
17018 Orig_Node
:= Original_Node
(Subp_Decl
);
17021 -- The rewritten subprogram is actually an entry
17023 if Present
(Orig_Node
)
17024 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
17025 and then Is_Entry
(Name
(Orig_Node
))
17031 end Is_Renamed_Entry
;
17033 -----------------------------
17034 -- Is_Renaming_Declaration --
17035 -----------------------------
17037 function Is_Renaming_Declaration
(N
: Node_Id
) return Boolean is
17040 when N_Exception_Renaming_Declaration
17041 | N_Generic_Function_Renaming_Declaration
17042 | N_Generic_Package_Renaming_Declaration
17043 | N_Generic_Procedure_Renaming_Declaration
17044 | N_Object_Renaming_Declaration
17045 | N_Package_Renaming_Declaration
17046 | N_Subprogram_Renaming_Declaration
17053 end Is_Renaming_Declaration
;
17055 ----------------------------
17056 -- Is_Reversible_Iterator --
17057 ----------------------------
17059 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
17060 Ifaces_List
: Elist_Id
;
17061 Iface_Elmt
: Elmt_Id
;
17065 if Is_Class_Wide_Type
(Typ
)
17066 and then Chars
(Root_Type
(Typ
)) = Name_Reversible_Iterator
17067 and then In_Predefined_Unit
(Root_Type
(Typ
))
17071 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
17075 Collect_Interfaces
(Typ
, Ifaces_List
);
17077 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
17078 while Present
(Iface_Elmt
) loop
17079 Iface
:= Node
(Iface_Elmt
);
17080 if Chars
(Iface
) = Name_Reversible_Iterator
17081 and then In_Predefined_Unit
(Iface
)
17086 Next_Elmt
(Iface_Elmt
);
17091 end Is_Reversible_Iterator
;
17093 ----------------------
17094 -- Is_Selector_Name --
17095 ----------------------
17097 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
17099 if not Is_List_Member
(N
) then
17101 P
: constant Node_Id
:= Parent
(N
);
17103 return Nkind_In
(P
, N_Expanded_Name
,
17104 N_Generic_Association
,
17105 N_Parameter_Association
,
17106 N_Selected_Component
)
17107 and then Selector_Name
(P
) = N
;
17112 L
: constant List_Id
:= List_Containing
(N
);
17113 P
: constant Node_Id
:= Parent
(L
);
17115 return (Nkind
(P
) = N_Discriminant_Association
17116 and then Selector_Names
(P
) = L
)
17118 (Nkind
(P
) = N_Component_Association
17119 and then Choices
(P
) = L
);
17122 end Is_Selector_Name
;
17124 ---------------------------------
17125 -- Is_Single_Concurrent_Object --
17126 ---------------------------------
17128 function Is_Single_Concurrent_Object
(Id
: Entity_Id
) return Boolean is
17131 Is_Single_Protected_Object
(Id
) or else Is_Single_Task_Object
(Id
);
17132 end Is_Single_Concurrent_Object
;
17134 -------------------------------
17135 -- Is_Single_Concurrent_Type --
17136 -------------------------------
17138 function Is_Single_Concurrent_Type
(Id
: Entity_Id
) return Boolean is
17141 Ekind_In
(Id
, E_Protected_Type
, E_Task_Type
)
17142 and then Is_Single_Concurrent_Type_Declaration
17143 (Declaration_Node
(Id
));
17144 end Is_Single_Concurrent_Type
;
17146 -------------------------------------------
17147 -- Is_Single_Concurrent_Type_Declaration --
17148 -------------------------------------------
17150 function Is_Single_Concurrent_Type_Declaration
17151 (N
: Node_Id
) return Boolean
17154 return Nkind_In
(Original_Node
(N
), N_Single_Protected_Declaration
,
17155 N_Single_Task_Declaration
);
17156 end Is_Single_Concurrent_Type_Declaration
;
17158 ---------------------------------------------
17159 -- Is_Single_Precision_Floating_Point_Type --
17160 ---------------------------------------------
17162 function Is_Single_Precision_Floating_Point_Type
17163 (E
: Entity_Id
) return Boolean is
17165 return Is_Floating_Point_Type
(E
)
17166 and then Machine_Radix_Value
(E
) = Uint_2
17167 and then Machine_Mantissa_Value
(E
) = Uint_24
17168 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_7
17169 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_7
);
17170 end Is_Single_Precision_Floating_Point_Type
;
17172 --------------------------------
17173 -- Is_Single_Protected_Object --
17174 --------------------------------
17176 function Is_Single_Protected_Object
(Id
: Entity_Id
) return Boolean is
17179 Ekind
(Id
) = E_Variable
17180 and then Ekind
(Etype
(Id
)) = E_Protected_Type
17181 and then Is_Single_Concurrent_Type
(Etype
(Id
));
17182 end Is_Single_Protected_Object
;
17184 ---------------------------
17185 -- Is_Single_Task_Object --
17186 ---------------------------
17188 function Is_Single_Task_Object
(Id
: Entity_Id
) return Boolean is
17191 Ekind
(Id
) = E_Variable
17192 and then Ekind
(Etype
(Id
)) = E_Task_Type
17193 and then Is_Single_Concurrent_Type
(Etype
(Id
));
17194 end Is_Single_Task_Object
;
17196 -------------------------------------
17197 -- Is_SPARK_05_Initialization_Expr --
17198 -------------------------------------
17200 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
17203 Comp_Assn
: Node_Id
;
17204 Orig_N
: constant Node_Id
:= Original_Node
(N
);
17209 if not Comes_From_Source
(Orig_N
) then
17213 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
17215 case Nkind
(Orig_N
) is
17216 when N_Character_Literal
17217 | N_Integer_Literal
17223 when N_Expanded_Name
17226 if Is_Entity_Name
(Orig_N
)
17227 and then Present
(Entity
(Orig_N
)) -- needed in some cases
17229 case Ekind
(Entity
(Orig_N
)) is
17231 | E_Enumeration_Literal
17238 if Is_Type
(Entity
(Orig_N
)) then
17246 when N_Qualified_Expression
17247 | N_Type_Conversion
17249 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
17252 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
17255 | N_Membership_Test
17258 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
17260 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
17263 | N_Extension_Aggregate
17265 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
17267 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
17270 Expr
:= First
(Expressions
(Orig_N
));
17271 while Present
(Expr
) loop
17272 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
17280 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
17281 while Present
(Comp_Assn
) loop
17282 Expr
:= Expression
(Comp_Assn
);
17284 -- Note: test for Present here needed for box assocation
17287 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
17296 when N_Attribute_Reference
=>
17297 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
17298 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
17301 Expr
:= First
(Expressions
(Orig_N
));
17302 while Present
(Expr
) loop
17303 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
17311 -- Selected components might be expanded named not yet resolved, so
17312 -- default on the safe side. (Eg on sparklex.ads)
17314 when N_Selected_Component
=>
17323 end Is_SPARK_05_Initialization_Expr
;
17325 ----------------------------------
17326 -- Is_SPARK_05_Object_Reference --
17327 ----------------------------------
17329 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
17331 if Is_Entity_Name
(N
) then
17332 return Present
(Entity
(N
))
17334 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
17335 or else Ekind
(Entity
(N
)) in Formal_Kind
);
17339 when N_Selected_Component
=>
17340 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
17346 end Is_SPARK_05_Object_Reference
;
17348 -----------------------------
17349 -- Is_Specific_Tagged_Type --
17350 -----------------------------
17352 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
17353 Full_Typ
: Entity_Id
;
17356 -- Handle private types
17358 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
17359 Full_Typ
:= Full_View
(Typ
);
17364 -- A specific tagged type is a non-class-wide tagged type
17366 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
17367 end Is_Specific_Tagged_Type
;
17373 function Is_Statement
(N
: Node_Id
) return Boolean is
17376 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
17377 or else Nkind
(N
) = N_Procedure_Call_Statement
;
17380 ---------------------------------------
17381 -- Is_Subprogram_Contract_Annotation --
17382 ---------------------------------------
17384 function Is_Subprogram_Contract_Annotation
17385 (Item
: Node_Id
) return Boolean
17390 if Nkind
(Item
) = N_Aspect_Specification
then
17391 Nam
:= Chars
(Identifier
(Item
));
17393 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
17394 Nam
:= Pragma_Name
(Item
);
17397 return Nam
= Name_Contract_Cases
17398 or else Nam
= Name_Depends
17399 or else Nam
= Name_Extensions_Visible
17400 or else Nam
= Name_Global
17401 or else Nam
= Name_Post
17402 or else Nam
= Name_Post_Class
17403 or else Nam
= Name_Postcondition
17404 or else Nam
= Name_Pre
17405 or else Nam
= Name_Pre_Class
17406 or else Nam
= Name_Precondition
17407 or else Nam
= Name_Refined_Depends
17408 or else Nam
= Name_Refined_Global
17409 or else Nam
= Name_Refined_Post
17410 or else Nam
= Name_Test_Case
;
17411 end Is_Subprogram_Contract_Annotation
;
17413 --------------------------------------------------
17414 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17415 --------------------------------------------------
17417 function Is_Subprogram_Stub_Without_Prior_Declaration
17418 (N
: Node_Id
) return Boolean
17421 -- A subprogram stub without prior declaration serves as declaration for
17422 -- the actual subprogram body. As such, it has an attached defining
17423 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
17425 return Nkind
(N
) = N_Subprogram_Body_Stub
17426 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
17427 end Is_Subprogram_Stub_Without_Prior_Declaration
;
17429 ---------------------------
17430 -- Is_Suitable_Primitive --
17431 ---------------------------
17433 function Is_Suitable_Primitive
(Subp_Id
: Entity_Id
) return Boolean is
17435 -- The Default_Initial_Condition and invariant procedures must not be
17436 -- treated as primitive operations even when they apply to a tagged
17437 -- type. These routines must not act as targets of dispatching calls
17438 -- because they already utilize class-wide-precondition semantics to
17439 -- handle inheritance and overriding.
17441 if Ekind
(Subp_Id
) = E_Procedure
17442 and then (Is_DIC_Procedure
(Subp_Id
)
17444 Is_Invariant_Procedure
(Subp_Id
))
17450 end Is_Suitable_Primitive
;
17452 --------------------------
17453 -- Is_Suspension_Object --
17454 --------------------------
17456 function Is_Suspension_Object
(Id
: Entity_Id
) return Boolean is
17458 -- This approach does an exact name match rather than to rely on
17459 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17460 -- front end at point where all auxiliary tables are locked and any
17461 -- modifications to them are treated as violations. Do not tamper with
17462 -- the tables, instead examine the Chars fields of all the scopes of Id.
17465 Chars
(Id
) = Name_Suspension_Object
17466 and then Present
(Scope
(Id
))
17467 and then Chars
(Scope
(Id
)) = Name_Synchronous_Task_Control
17468 and then Present
(Scope
(Scope
(Id
)))
17469 and then Chars
(Scope
(Scope
(Id
))) = Name_Ada
17470 and then Present
(Scope
(Scope
(Scope
(Id
))))
17471 and then Scope
(Scope
(Scope
(Id
))) = Standard_Standard
;
17472 end Is_Suspension_Object
;
17474 ----------------------------
17475 -- Is_Synchronized_Object --
17476 ----------------------------
17478 function Is_Synchronized_Object
(Id
: Entity_Id
) return Boolean is
17482 if Is_Object
(Id
) then
17484 -- The object is synchronized if it is of a type that yields a
17485 -- synchronized object.
17487 if Yields_Synchronized_Object
(Etype
(Id
)) then
17490 -- The object is synchronized if it is atomic and Async_Writers is
17493 elsif Is_Atomic_Object_Entity
(Id
)
17494 and then Async_Writers_Enabled
(Id
)
17498 -- A constant is a synchronized object by default
17500 elsif Ekind
(Id
) = E_Constant
then
17503 -- A variable is a synchronized object if it is subject to pragma
17504 -- Constant_After_Elaboration.
17506 elsif Ekind
(Id
) = E_Variable
then
17507 Prag
:= Get_Pragma
(Id
, Pragma_Constant_After_Elaboration
);
17509 return Present
(Prag
) and then Is_Enabled_Pragma
(Prag
);
17513 -- Otherwise the input is not an object or it does not qualify as a
17514 -- synchronized object.
17517 end Is_Synchronized_Object
;
17519 ---------------------------------
17520 -- Is_Synchronized_Tagged_Type --
17521 ---------------------------------
17523 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
17524 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
17527 -- A task or protected type derived from an interface is a tagged type.
17528 -- Such a tagged type is called a synchronized tagged type, as are
17529 -- synchronized interfaces and private extensions whose declaration
17530 -- includes the reserved word synchronized.
17532 return (Is_Tagged_Type
(E
)
17533 and then (Kind
= E_Task_Type
17535 Kind
= E_Protected_Type
))
17538 and then Is_Synchronized_Interface
(E
))
17540 (Ekind
(E
) = E_Record_Type_With_Private
17541 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
17542 and then (Synchronized_Present
(Parent
(E
))
17543 or else Is_Synchronized_Interface
(Etype
(E
))));
17544 end Is_Synchronized_Tagged_Type
;
17550 function Is_Transfer
(N
: Node_Id
) return Boolean is
17551 Kind
: constant Node_Kind
:= Nkind
(N
);
17554 if Kind
= N_Simple_Return_Statement
17556 Kind
= N_Extended_Return_Statement
17558 Kind
= N_Goto_Statement
17560 Kind
= N_Raise_Statement
17562 Kind
= N_Requeue_Statement
17566 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
17567 and then No
(Condition
(N
))
17571 elsif Kind
= N_Procedure_Call_Statement
17572 and then Is_Entity_Name
(Name
(N
))
17573 and then Present
(Entity
(Name
(N
)))
17574 and then No_Return
(Entity
(Name
(N
)))
17578 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
17590 function Is_True
(U
: Uint
) return Boolean is
17595 --------------------------------------
17596 -- Is_Unchecked_Conversion_Instance --
17597 --------------------------------------
17599 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
17603 -- Look for a function whose generic parent is the predefined intrinsic
17604 -- function Unchecked_Conversion, or for one that renames such an
17607 if Ekind
(Id
) = E_Function
then
17608 Par
:= Parent
(Id
);
17610 if Nkind
(Par
) = N_Function_Specification
then
17611 Par
:= Generic_Parent
(Par
);
17613 if Present
(Par
) then
17615 Chars
(Par
) = Name_Unchecked_Conversion
17616 and then Is_Intrinsic_Subprogram
(Par
)
17617 and then In_Predefined_Unit
(Par
);
17620 Present
(Alias
(Id
))
17621 and then Is_Unchecked_Conversion_Instance
(Alias
(Id
));
17627 end Is_Unchecked_Conversion_Instance
;
17629 -------------------------------
17630 -- Is_Universal_Numeric_Type --
17631 -------------------------------
17633 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
17635 return T
= Universal_Integer
or else T
= Universal_Real
;
17636 end Is_Universal_Numeric_Type
;
17638 ------------------------------
17639 -- Is_User_Defined_Equality --
17640 ------------------------------
17642 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean is
17644 return Ekind
(Id
) = E_Function
17645 and then Chars
(Id
) = Name_Op_Eq
17646 and then Comes_From_Source
(Id
)
17648 -- Internally generated equalities have a full type declaration
17649 -- as their parent.
17651 and then Nkind
(Parent
(Id
)) = N_Function_Specification
;
17652 end Is_User_Defined_Equality
;
17654 --------------------------------------
17655 -- Is_Validation_Variable_Reference --
17656 --------------------------------------
17658 function Is_Validation_Variable_Reference
(N
: Node_Id
) return Boolean is
17659 Var
: constant Node_Id
:= Unqual_Conv
(N
);
17660 Var_Id
: Entity_Id
;
17665 if Is_Entity_Name
(Var
) then
17666 Var_Id
:= Entity
(Var
);
17671 and then Ekind
(Var_Id
) = E_Variable
17672 and then Present
(Validated_Object
(Var_Id
));
17673 end Is_Validation_Variable_Reference
;
17675 ----------------------------
17676 -- Is_Variable_Size_Array --
17677 ----------------------------
17679 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
17683 pragma Assert
(Is_Array_Type
(E
));
17685 -- Check if some index is initialized with a non-constant value
17687 Idx
:= First_Index
(E
);
17688 while Present
(Idx
) loop
17689 if Nkind
(Idx
) = N_Range
then
17690 if not Is_Constant_Bound
(Low_Bound
(Idx
))
17691 or else not Is_Constant_Bound
(High_Bound
(Idx
))
17697 Idx
:= Next_Index
(Idx
);
17701 end Is_Variable_Size_Array
;
17703 -----------------------------
17704 -- Is_Variable_Size_Record --
17705 -----------------------------
17707 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
17709 Comp_Typ
: Entity_Id
;
17712 pragma Assert
(Is_Record_Type
(E
));
17714 Comp
:= First_Component
(E
);
17715 while Present
(Comp
) loop
17716 Comp_Typ
:= Underlying_Type
(Etype
(Comp
));
17718 -- Recursive call if the record type has discriminants
17720 if Is_Record_Type
(Comp_Typ
)
17721 and then Has_Discriminants
(Comp_Typ
)
17722 and then Is_Variable_Size_Record
(Comp_Typ
)
17726 elsif Is_Array_Type
(Comp_Typ
)
17727 and then Is_Variable_Size_Array
(Comp_Typ
)
17732 Next_Component
(Comp
);
17736 end Is_Variable_Size_Record
;
17742 function Is_Variable
17744 Use_Original_Node
: Boolean := True) return Boolean
17746 Orig_Node
: Node_Id
;
17748 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
17749 -- Within a protected function, the private components of the enclosing
17750 -- protected type are constants. A function nested within a (protected)
17751 -- procedure is not itself protected. Within the body of a protected
17752 -- function the current instance of the protected type is a constant.
17754 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
17755 -- Prefixes can involve implicit dereferences, in which case we must
17756 -- test for the case of a reference of a constant access type, which can
17757 -- can never be a variable.
17759 ---------------------------
17760 -- In_Protected_Function --
17761 ---------------------------
17763 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
17768 -- E is the current instance of a type
17770 if Is_Type
(E
) then
17779 if not Is_Protected_Type
(Prot
) then
17783 S
:= Current_Scope
;
17784 while Present
(S
) and then S
/= Prot
loop
17785 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
17794 end In_Protected_Function
;
17796 ------------------------
17797 -- Is_Variable_Prefix --
17798 ------------------------
17800 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
17802 if Is_Access_Type
(Etype
(P
)) then
17803 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
17805 -- For the case of an indexed component whose prefix has a packed
17806 -- array type, the prefix has been rewritten into a type conversion.
17807 -- Determine variable-ness from the converted expression.
17809 elsif Nkind
(P
) = N_Type_Conversion
17810 and then not Comes_From_Source
(P
)
17811 and then Is_Array_Type
(Etype
(P
))
17812 and then Is_Packed
(Etype
(P
))
17814 return Is_Variable
(Expression
(P
));
17817 return Is_Variable
(P
);
17819 end Is_Variable_Prefix
;
17821 -- Start of processing for Is_Variable
17824 -- Special check, allow x'Deref(expr) as a variable
17826 if Nkind
(N
) = N_Attribute_Reference
17827 and then Attribute_Name
(N
) = Name_Deref
17832 -- Check if we perform the test on the original node since this may be a
17833 -- test of syntactic categories which must not be disturbed by whatever
17834 -- rewriting might have occurred. For example, an aggregate, which is
17835 -- certainly NOT a variable, could be turned into a variable by
17838 if Use_Original_Node
then
17839 Orig_Node
:= Original_Node
(N
);
17844 -- Definitely OK if Assignment_OK is set. Since this is something that
17845 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
17847 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
17850 -- Normally we go to the original node, but there is one exception where
17851 -- we use the rewritten node, namely when it is an explicit dereference.
17852 -- The generated code may rewrite a prefix which is an access type with
17853 -- an explicit dereference. The dereference is a variable, even though
17854 -- the original node may not be (since it could be a constant of the
17857 -- In Ada 2005 we have a further case to consider: the prefix may be a
17858 -- function call given in prefix notation. The original node appears to
17859 -- be a selected component, but we need to examine the call.
17861 elsif Nkind
(N
) = N_Explicit_Dereference
17862 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
17863 and then Present
(Etype
(Orig_Node
))
17864 and then Is_Access_Type
(Etype
(Orig_Node
))
17866 -- Note that if the prefix is an explicit dereference that does not
17867 -- come from source, we must check for a rewritten function call in
17868 -- prefixed notation before other forms of rewriting, to prevent a
17872 (Nkind
(Orig_Node
) = N_Function_Call
17873 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
17875 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
17877 -- in Ada 2012, the dereference may have been added for a type with
17878 -- a declared implicit dereference aspect. Check that it is not an
17879 -- access to constant.
17881 elsif Nkind
(N
) = N_Explicit_Dereference
17882 and then Present
(Etype
(Orig_Node
))
17883 and then Ada_Version
>= Ada_2012
17884 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
17886 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
17888 -- A function call is never a variable
17890 elsif Nkind
(N
) = N_Function_Call
then
17893 -- All remaining checks use the original node
17895 elsif Is_Entity_Name
(Orig_Node
)
17896 and then Present
(Entity
(Orig_Node
))
17899 E
: constant Entity_Id
:= Entity
(Orig_Node
);
17900 K
: constant Entity_Kind
:= Ekind
(E
);
17903 if Is_Loop_Parameter
(E
) then
17907 return (K
= E_Variable
17908 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
17909 or else (K
= E_Component
17910 and then not In_Protected_Function
(E
))
17911 or else K
= E_Out_Parameter
17912 or else K
= E_In_Out_Parameter
17913 or else K
= E_Generic_In_Out_Parameter
17915 -- Current instance of type. If this is a protected type, check
17916 -- we are not within the body of one of its protected functions.
17918 or else (Is_Type
(E
)
17919 and then In_Open_Scopes
(E
)
17920 and then not In_Protected_Function
(E
))
17922 or else (Is_Incomplete_Or_Private_Type
(E
)
17923 and then In_Open_Scopes
(Full_View
(E
)));
17927 case Nkind
(Orig_Node
) is
17928 when N_Indexed_Component
17931 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
17933 when N_Selected_Component
=>
17934 return (Is_Variable
(Selector_Name
(Orig_Node
))
17935 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
17937 (Nkind
(N
) = N_Expanded_Name
17938 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
17940 -- For an explicit dereference, the type of the prefix cannot
17941 -- be an access to constant or an access to subprogram.
17943 when N_Explicit_Dereference
=>
17945 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
17947 return Is_Access_Type
(Typ
)
17948 and then not Is_Access_Constant
(Root_Type
(Typ
))
17949 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
17952 -- The type conversion is the case where we do not deal with the
17953 -- context dependent special case of an actual parameter. Thus
17954 -- the type conversion is only considered a variable for the
17955 -- purposes of this routine if the target type is tagged. However,
17956 -- a type conversion is considered to be a variable if it does not
17957 -- come from source (this deals for example with the conversions
17958 -- of expressions to their actual subtypes).
17960 when N_Type_Conversion
=>
17961 return Is_Variable
(Expression
(Orig_Node
))
17963 (not Comes_From_Source
(Orig_Node
)
17965 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
17967 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
17969 -- GNAT allows an unchecked type conversion as a variable. This
17970 -- only affects the generation of internal expanded code, since
17971 -- calls to instantiations of Unchecked_Conversion are never
17972 -- considered variables (since they are function calls).
17974 when N_Unchecked_Type_Conversion
=>
17975 return Is_Variable
(Expression
(Orig_Node
));
17983 ---------------------------
17984 -- Is_Visibly_Controlled --
17985 ---------------------------
17987 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
17988 Root
: constant Entity_Id
:= Root_Type
(T
);
17990 return Chars
(Scope
(Root
)) = Name_Finalization
17991 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
17992 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
17993 end Is_Visibly_Controlled
;
17995 --------------------------
17996 -- Is_Volatile_Function --
17997 --------------------------
17999 function Is_Volatile_Function
(Func_Id
: Entity_Id
) return Boolean is
18001 pragma Assert
(Ekind_In
(Func_Id
, E_Function
, E_Generic_Function
));
18003 -- A function declared within a protected type is volatile
18005 if Is_Protected_Type
(Scope
(Func_Id
)) then
18008 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18009 -- either the source or the target are effectively volatile.
18011 elsif Is_Unchecked_Conversion_Instance
(Func_Id
)
18012 and then Has_Effectively_Volatile_Profile
(Func_Id
)
18016 -- Otherwise the function is treated as volatile if it is subject to
18017 -- enabled pragma Volatile_Function.
18021 Is_Enabled_Pragma
(Get_Pragma
(Func_Id
, Pragma_Volatile_Function
));
18023 end Is_Volatile_Function
;
18025 ------------------------
18026 -- Is_Volatile_Object --
18027 ------------------------
18029 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
18030 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
18031 -- If prefix is an implicit dereference, examine designated type
18033 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
18034 -- Determines if given object has volatile components
18036 ------------------------
18037 -- Is_Volatile_Prefix --
18038 ------------------------
18040 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
18041 Typ
: constant Entity_Id
:= Etype
(N
);
18044 if Is_Access_Type
(Typ
) then
18046 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
18049 return Is_Volatile
(Dtyp
)
18050 or else Has_Volatile_Components
(Dtyp
);
18054 return Object_Has_Volatile_Components
(N
);
18056 end Is_Volatile_Prefix
;
18058 ------------------------------------
18059 -- Object_Has_Volatile_Components --
18060 ------------------------------------
18062 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
18063 Typ
: constant Entity_Id
:= Etype
(N
);
18066 if Is_Volatile
(Typ
)
18067 or else Has_Volatile_Components
(Typ
)
18071 elsif Is_Entity_Name
(N
)
18072 and then (Has_Volatile_Components
(Entity
(N
))
18073 or else Is_Volatile
(Entity
(N
)))
18077 elsif Nkind
(N
) = N_Indexed_Component
18078 or else Nkind
(N
) = N_Selected_Component
18080 return Is_Volatile_Prefix
(Prefix
(N
));
18085 end Object_Has_Volatile_Components
;
18087 -- Start of processing for Is_Volatile_Object
18090 if Nkind
(N
) = N_Defining_Identifier
then
18091 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
18093 elsif Nkind
(N
) = N_Expanded_Name
then
18094 return Is_Volatile_Object
(Entity
(N
));
18096 elsif Is_Volatile
(Etype
(N
))
18097 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
18101 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
18102 and then Is_Volatile_Prefix
(Prefix
(N
))
18106 elsif Nkind
(N
) = N_Selected_Component
18107 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
18114 end Is_Volatile_Object
;
18116 -----------------------------
18117 -- Iterate_Call_Parameters --
18118 -----------------------------
18120 procedure Iterate_Call_Parameters
(Call
: Node_Id
) is
18121 Actual
: Node_Id
:= First_Actual
(Call
);
18122 Formal
: Entity_Id
:= First_Formal
(Get_Called_Entity
(Call
));
18125 while Present
(Formal
) and then Present
(Actual
) loop
18126 Handle_Parameter
(Formal
, Actual
);
18128 Next_Formal
(Formal
);
18129 Next_Actual
(Actual
);
18132 pragma Assert
(No
(Formal
));
18133 pragma Assert
(No
(Actual
));
18134 end Iterate_Call_Parameters
;
18136 ---------------------------
18137 -- Itype_Has_Declaration --
18138 ---------------------------
18140 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
18142 pragma Assert
(Is_Itype
(Id
));
18143 return Present
(Parent
(Id
))
18144 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
18145 N_Subtype_Declaration
)
18146 and then Defining_Entity
(Parent
(Id
)) = Id
;
18147 end Itype_Has_Declaration
;
18149 -------------------------
18150 -- Kill_Current_Values --
18151 -------------------------
18153 procedure Kill_Current_Values
18155 Last_Assignment_Only
: Boolean := False)
18158 if Is_Assignable
(Ent
) then
18159 Set_Last_Assignment
(Ent
, Empty
);
18162 if Is_Object
(Ent
) then
18163 if not Last_Assignment_Only
then
18165 Set_Current_Value
(Ent
, Empty
);
18167 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18168 -- for a constant. Once the constant is elaborated, its value is
18169 -- not changed, therefore the associated flags that describe the
18170 -- value should not be modified either.
18172 if Ekind
(Ent
) = E_Constant
then
18175 -- Non-constant entities
18178 if not Can_Never_Be_Null
(Ent
) then
18179 Set_Is_Known_Non_Null
(Ent
, False);
18182 Set_Is_Known_Null
(Ent
, False);
18184 -- Reset the Is_Known_Valid flag unless the type is always
18185 -- valid. This does not apply to a loop parameter because its
18186 -- bounds are defined by the loop header and therefore always
18189 if not Is_Known_Valid
(Etype
(Ent
))
18190 and then Ekind
(Ent
) /= E_Loop_Parameter
18192 Set_Is_Known_Valid
(Ent
, False);
18197 end Kill_Current_Values
;
18199 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
18202 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
18203 -- Clear current value for entity E and all entities chained to E
18205 ------------------------------------------
18206 -- Kill_Current_Values_For_Entity_Chain --
18207 ------------------------------------------
18209 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
18213 while Present
(Ent
) loop
18214 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
18217 end Kill_Current_Values_For_Entity_Chain
;
18219 -- Start of processing for Kill_Current_Values
18222 -- Kill all saved checks, a special case of killing saved values
18224 if not Last_Assignment_Only
then
18228 -- Loop through relevant scopes, which includes the current scope and
18229 -- any parent scopes if the current scope is a block or a package.
18231 S
:= Current_Scope
;
18234 -- Clear current values of all entities in current scope
18236 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
18238 -- If scope is a package, also clear current values of all private
18239 -- entities in the scope.
18241 if Is_Package_Or_Generic_Package
(S
)
18242 or else Is_Concurrent_Type
(S
)
18244 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
18247 -- If this is a not a subprogram, deal with parents
18249 if not Is_Subprogram
(S
) then
18251 exit Scope_Loop
when S
= Standard_Standard
;
18255 end loop Scope_Loop
;
18256 end Kill_Current_Values
;
18258 --------------------------
18259 -- Kill_Size_Check_Code --
18260 --------------------------
18262 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
18264 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
18265 and then Present
(Size_Check_Code
(E
))
18267 Remove
(Size_Check_Code
(E
));
18268 Set_Size_Check_Code
(E
, Empty
);
18270 end Kill_Size_Check_Code
;
18272 --------------------
18273 -- Known_Non_Null --
18274 --------------------
18276 function Known_Non_Null
(N
: Node_Id
) return Boolean is
18277 Status
: constant Null_Status_Kind
:= Null_Status
(N
);
18284 -- The expression yields a non-null value ignoring simple flow analysis
18286 if Status
= Is_Non_Null
then
18289 -- Otherwise check whether N is a reference to an entity that appears
18290 -- within a conditional construct.
18292 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
18294 -- First check if we are in decisive conditional
18296 Get_Current_Value_Condition
(N
, Op
, Val
);
18298 if Known_Null
(Val
) then
18299 if Op
= N_Op_Eq
then
18301 elsif Op
= N_Op_Ne
then
18306 -- If OK to do replacement, test Is_Known_Non_Null flag
18310 if OK_To_Do_Constant_Replacement
(Id
) then
18311 return Is_Known_Non_Null
(Id
);
18315 -- Otherwise it is not possible to determine whether N yields a non-null
18319 end Known_Non_Null
;
18325 function Known_Null
(N
: Node_Id
) return Boolean is
18326 Status
: constant Null_Status_Kind
:= Null_Status
(N
);
18333 -- The expression yields a null value ignoring simple flow analysis
18335 if Status
= Is_Null
then
18338 -- Otherwise check whether N is a reference to an entity that appears
18339 -- within a conditional construct.
18341 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
18343 -- First check if we are in decisive conditional
18345 Get_Current_Value_Condition
(N
, Op
, Val
);
18347 if Known_Null
(Val
) then
18348 if Op
= N_Op_Eq
then
18350 elsif Op
= N_Op_Ne
then
18355 -- If OK to do replacement, test Is_Known_Null flag
18359 if OK_To_Do_Constant_Replacement
(Id
) then
18360 return Is_Known_Null
(Id
);
18364 -- Otherwise it is not possible to determine whether N yields a null
18370 --------------------------
18371 -- Known_To_Be_Assigned --
18372 --------------------------
18374 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
18375 P
: constant Node_Id
:= Parent
(N
);
18380 -- Test left side of assignment
18382 when N_Assignment_Statement
=>
18383 return N
= Name
(P
);
18385 -- Function call arguments are never lvalues
18387 when N_Function_Call
=>
18390 -- Positional parameter for procedure or accept call
18392 when N_Accept_Statement
18393 | N_Procedure_Call_Statement
18401 Proc
:= Get_Subprogram_Entity
(P
);
18407 -- If we are not a list member, something is strange, so
18408 -- be conservative and return False.
18410 if not Is_List_Member
(N
) then
18414 -- We are going to find the right formal by stepping forward
18415 -- through the formals, as we step backwards in the actuals.
18417 Form
:= First_Formal
(Proc
);
18420 -- If no formal, something is weird, so be conservative
18421 -- and return False.
18428 exit when No
(Act
);
18429 Next_Formal
(Form
);
18432 return Ekind
(Form
) /= E_In_Parameter
;
18435 -- Named parameter for procedure or accept call
18437 when N_Parameter_Association
=>
18443 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
18449 -- Loop through formals to find the one that matches
18451 Form
:= First_Formal
(Proc
);
18453 -- If no matching formal, that's peculiar, some kind of
18454 -- previous error, so return False to be conservative.
18455 -- Actually this also happens in legal code in the case
18456 -- where P is a parameter association for an Extra_Formal???
18462 -- Else test for match
18464 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
18465 return Ekind
(Form
) /= E_In_Parameter
;
18468 Next_Formal
(Form
);
18472 -- Test for appearing in a conversion that itself appears
18473 -- in an lvalue context, since this should be an lvalue.
18475 when N_Type_Conversion
=>
18476 return Known_To_Be_Assigned
(P
);
18478 -- All other references are definitely not known to be modifications
18483 end Known_To_Be_Assigned
;
18485 ---------------------------
18486 -- Last_Source_Statement --
18487 ---------------------------
18489 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
18493 N
:= Last
(Statements
(HSS
));
18494 while Present
(N
) loop
18495 exit when Comes_From_Source
(N
);
18500 end Last_Source_Statement
;
18502 -----------------------
18503 -- Mark_Coextensions --
18504 -----------------------
18506 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
18507 Is_Dynamic
: Boolean;
18508 -- Indicates whether the context causes nested coextensions to be
18509 -- dynamic or static
18511 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
18512 -- Recognize an allocator node and label it as a dynamic coextension
18514 --------------------
18515 -- Mark_Allocator --
18516 --------------------
18518 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
18520 if Nkind
(N
) = N_Allocator
then
18522 Set_Is_Static_Coextension
(N
, False);
18523 Set_Is_Dynamic_Coextension
(N
);
18525 -- If the allocator expression is potentially dynamic, it may
18526 -- be expanded out of order and require dynamic allocation
18527 -- anyway, so we treat the coextension itself as dynamic.
18528 -- Potential optimization ???
18530 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
18531 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
18533 Set_Is_Static_Coextension
(N
, False);
18534 Set_Is_Dynamic_Coextension
(N
);
18536 Set_Is_Dynamic_Coextension
(N
, False);
18537 Set_Is_Static_Coextension
(N
);
18542 end Mark_Allocator
;
18544 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
18546 -- Start of processing for Mark_Coextensions
18549 -- An allocator that appears on the right-hand side of an assignment is
18550 -- treated as a potentially dynamic coextension when the right-hand side
18551 -- is an allocator or a qualified expression.
18553 -- Obj := new ...'(new Coextension ...);
18555 if Nkind
(Context_Nod
) = N_Assignment_Statement
then
18557 Nkind_In
(Expression
(Context_Nod
), N_Allocator
,
18558 N_Qualified_Expression
);
18560 -- An allocator that appears within the expression of a simple return
18561 -- statement is treated as a potentially dynamic coextension when the
18562 -- expression is either aggregate, allocator, or qualified expression.
18564 -- return (new Coextension ...);
18565 -- return new ...'(new Coextension ...);
18567 elsif Nkind
(Context_Nod
) = N_Simple_Return_Statement
then
18569 Nkind_In
(Expression
(Context_Nod
), N_Aggregate
,
18571 N_Qualified_Expression
);
18573 -- An alloctor that appears within the initialization expression of an
18574 -- object declaration is considered a potentially dynamic coextension
18575 -- when the initialization expression is an allocator or a qualified
18578 -- Obj : ... := new ...'(new Coextension ...);
18580 -- A similar case arises when the object declaration is part of an
18581 -- extended return statement.
18583 -- return Obj : ... := new ...'(new Coextension ...);
18584 -- return Obj : ... := (new Coextension ...);
18586 elsif Nkind
(Context_Nod
) = N_Object_Declaration
then
18588 Nkind_In
(Root_Nod
, N_Allocator
, N_Qualified_Expression
)
18590 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
18592 -- This routine should not be called with constructs that cannot contain
18596 raise Program_Error
;
18599 Mark_Allocators
(Root_Nod
);
18600 end Mark_Coextensions
;
18602 ---------------------------------
18603 -- Mark_Elaboration_Attributes --
18604 ---------------------------------
18606 procedure Mark_Elaboration_Attributes
18607 (N_Id
: Node_Or_Entity_Id
;
18608 Checks
: Boolean := False;
18609 Level
: Boolean := False;
18610 Modes
: Boolean := False;
18611 Warnings
: Boolean := False)
18613 function Elaboration_Checks_OK
18614 (Target_Id
: Entity_Id
;
18615 Context_Id
: Entity_Id
) return Boolean;
18616 -- Determine whether elaboration checks are enabled for target Target_Id
18617 -- which resides within context Context_Id.
18619 procedure Mark_Elaboration_Attributes_Id
(Id
: Entity_Id
);
18620 -- Preserve relevant attributes of the context in arbitrary entity Id
18622 procedure Mark_Elaboration_Attributes_Node
(N
: Node_Id
);
18623 -- Preserve relevant attributes of the context in arbitrary node N
18625 ---------------------------
18626 -- Elaboration_Checks_OK --
18627 ---------------------------
18629 function Elaboration_Checks_OK
18630 (Target_Id
: Entity_Id
;
18631 Context_Id
: Entity_Id
) return Boolean
18633 Encl_Scop
: Entity_Id
;
18636 -- Elaboration checks are suppressed for the target
18638 if Elaboration_Checks_Suppressed
(Target_Id
) then
18642 -- Otherwise elaboration checks are OK for the target, but may be
18643 -- suppressed for the context where the target is declared.
18645 Encl_Scop
:= Context_Id
;
18646 while Present
(Encl_Scop
) and then Encl_Scop
/= Standard_Standard
loop
18647 if Elaboration_Checks_Suppressed
(Encl_Scop
) then
18651 Encl_Scop
:= Scope
(Encl_Scop
);
18654 -- Neither the target nor its declarative context have elaboration
18655 -- checks suppressed.
18658 end Elaboration_Checks_OK
;
18660 ------------------------------------
18661 -- Mark_Elaboration_Attributes_Id --
18662 ------------------------------------
18664 procedure Mark_Elaboration_Attributes_Id
(Id
: Entity_Id
) is
18666 -- Mark the status of elaboration checks in effect. Do not reset the
18667 -- status in case the entity is reanalyzed with checks suppressed.
18669 if Checks
and then not Is_Elaboration_Checks_OK_Id
(Id
) then
18670 Set_Is_Elaboration_Checks_OK_Id
(Id
,
18671 Elaboration_Checks_OK
18673 Context_Id
=> Scope
(Id
)));
18676 -- Mark the status of elaboration warnings in effect. Do not reset
18677 -- the status in case the entity is reanalyzed with warnings off.
18679 if Warnings
and then not Is_Elaboration_Warnings_OK_Id
(Id
) then
18680 Set_Is_Elaboration_Warnings_OK_Id
(Id
, Elab_Warnings
);
18682 end Mark_Elaboration_Attributes_Id
;
18684 --------------------------------------
18685 -- Mark_Elaboration_Attributes_Node --
18686 --------------------------------------
18688 procedure Mark_Elaboration_Attributes_Node
(N
: Node_Id
) is
18689 function Extract_Name
(N
: Node_Id
) return Node_Id
;
18690 -- Obtain the Name attribute of call or instantiation N
18696 function Extract_Name
(N
: Node_Id
) return Node_Id
is
18702 -- A call to an entry family appears in indexed form
18704 if Nkind
(Nam
) = N_Indexed_Component
then
18705 Nam
:= Prefix
(Nam
);
18708 -- The name may also appear in qualified form
18710 if Nkind
(Nam
) = N_Selected_Component
then
18711 Nam
:= Selector_Name
(Nam
);
18719 Context_Id
: Entity_Id
;
18722 -- Start of processing for Mark_Elaboration_Attributes_Node
18725 -- Mark the status of elaboration checks in effect. Do not reset the
18726 -- status in case the node is reanalyzed with checks suppressed.
18728 if Checks
and then not Is_Elaboration_Checks_OK_Node
(N
) then
18730 -- Assignments, attribute references, and variable references do
18731 -- not have a "declarative" context.
18733 Context_Id
:= Empty
;
18735 -- The status of elaboration checks for calls and instantiations
18736 -- depends on the most recent pragma Suppress/Unsuppress, as well
18737 -- as the suppression status of the context where the target is
18741 -- function Func ...;
18745 -- procedure Main is
18746 -- pragma Suppress (Elaboration_Checks, Pack);
18747 -- X : ... := Pack.Func;
18750 -- In the example above, the call to Func has elaboration checks
18751 -- enabled because there is no active general purpose suppression
18752 -- pragma, however the elaboration checks of Pack are explicitly
18753 -- suppressed. As a result the elaboration checks of the call must
18754 -- be disabled in order to preserve this dependency.
18756 if Nkind_In
(N
, N_Entry_Call_Statement
,
18758 N_Function_Instantiation
,
18759 N_Package_Instantiation
,
18760 N_Procedure_Call_Statement
,
18761 N_Procedure_Instantiation
)
18763 Nam
:= Extract_Name
(N
);
18765 if Is_Entity_Name
(Nam
) and then Present
(Entity
(Nam
)) then
18766 Context_Id
:= Scope
(Entity
(Nam
));
18770 Set_Is_Elaboration_Checks_OK_Node
(N
,
18771 Elaboration_Checks_OK
18772 (Target_Id
=> Empty
,
18773 Context_Id
=> Context_Id
));
18776 -- Mark the enclosing level of the node. Do not reset the status in
18777 -- case the node is relocated and reanalyzed.
18779 if Level
and then not Is_Declaration_Level_Node
(N
) then
18780 Set_Is_Declaration_Level_Node
(N
,
18781 Find_Enclosing_Level
(N
) = Declaration_Level
);
18784 -- Mark the Ghost and SPARK mode in effect
18787 if Ghost_Mode
= Ignore
then
18788 Set_Is_Ignored_Ghost_Node
(N
);
18791 if SPARK_Mode
= On
then
18792 Set_Is_SPARK_Mode_On_Node
(N
);
18796 -- Mark the status of elaboration warnings in effect. Do not reset
18797 -- the status in case the node is reanalyzed with warnings off.
18799 if Warnings
and then not Is_Elaboration_Warnings_OK_Node
(N
) then
18800 Set_Is_Elaboration_Warnings_OK_Node
(N
, Elab_Warnings
);
18802 end Mark_Elaboration_Attributes_Node
;
18804 -- Start of processing for Mark_Elaboration_Attributes
18807 -- Do not capture any elaboration-related attributes when switch -gnatH
18808 -- (legacy elaboration checking mode enabled) is in effect because the
18809 -- attributes are useless to the legacy model.
18811 if Legacy_Elaboration_Checks
then
18815 if Nkind
(N_Id
) in N_Entity
then
18816 Mark_Elaboration_Attributes_Id
(N_Id
);
18818 Mark_Elaboration_Attributes_Node
(N_Id
);
18820 end Mark_Elaboration_Attributes
;
18822 ----------------------------------
18823 -- Matching_Static_Array_Bounds --
18824 ----------------------------------
18826 function Matching_Static_Array_Bounds
18828 R_Typ
: Node_Id
) return Boolean
18830 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
18831 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
18833 L_Index
: Node_Id
:= Empty
; -- init to ...
18834 R_Index
: Node_Id
:= Empty
; -- ...avoid warnings
18843 if L_Ndims
/= R_Ndims
then
18847 -- Unconstrained types do not have static bounds
18849 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
18853 -- First treat specially the first dimension, as the lower bound and
18854 -- length of string literals are not stored like those of arrays.
18856 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
18857 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
18858 L_Len
:= String_Literal_Length
(L_Typ
);
18860 L_Index
:= First_Index
(L_Typ
);
18861 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
18863 if Is_OK_Static_Expression
(L_Low
)
18865 Is_OK_Static_Expression
(L_High
)
18867 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
18870 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
18877 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
18878 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
18879 R_Len
:= String_Literal_Length
(R_Typ
);
18881 R_Index
:= First_Index
(R_Typ
);
18882 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
18884 if Is_OK_Static_Expression
(R_Low
)
18886 Is_OK_Static_Expression
(R_High
)
18888 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
18891 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
18898 if (Is_OK_Static_Expression
(L_Low
)
18900 Is_OK_Static_Expression
(R_Low
))
18901 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
18902 and then L_Len
= R_Len
18909 -- Then treat all other dimensions
18911 for Indx
in 2 .. L_Ndims
loop
18915 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
18916 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
18918 if (Is_OK_Static_Expression
(L_Low
) and then
18919 Is_OK_Static_Expression
(L_High
) and then
18920 Is_OK_Static_Expression
(R_Low
) and then
18921 Is_OK_Static_Expression
(R_High
))
18922 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
18924 Expr_Value
(L_High
) = Expr_Value
(R_High
))
18932 -- If we fall through the loop, all indexes matched
18935 end Matching_Static_Array_Bounds
;
18937 -------------------
18938 -- May_Be_Lvalue --
18939 -------------------
18941 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
18942 P
: constant Node_Id
:= Parent
(N
);
18947 -- Test left side of assignment
18949 when N_Assignment_Statement
=>
18950 return N
= Name
(P
);
18952 -- Test prefix of component or attribute. Note that the prefix of an
18953 -- explicit or implicit dereference cannot be an l-value. In the case
18954 -- of a 'Read attribute, the reference can be an actual in the
18955 -- argument list of the attribute.
18957 when N_Attribute_Reference
=>
18958 return (N
= Prefix
(P
)
18959 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
)))
18961 Attribute_Name
(P
) = Name_Read
;
18963 -- For an expanded name, the name is an lvalue if the expanded name
18964 -- is an lvalue, but the prefix is never an lvalue, since it is just
18965 -- the scope where the name is found.
18967 when N_Expanded_Name
=>
18968 if N
= Prefix
(P
) then
18969 return May_Be_Lvalue
(P
);
18974 -- For a selected component A.B, A is certainly an lvalue if A.B is.
18975 -- B is a little interesting, if we have A.B := 3, there is some
18976 -- discussion as to whether B is an lvalue or not, we choose to say
18977 -- it is. Note however that A is not an lvalue if it is of an access
18978 -- type since this is an implicit dereference.
18980 when N_Selected_Component
=>
18982 and then Present
(Etype
(N
))
18983 and then Is_Access_Type
(Etype
(N
))
18987 return May_Be_Lvalue
(P
);
18990 -- For an indexed component or slice, the index or slice bounds is
18991 -- never an lvalue. The prefix is an lvalue if the indexed component
18992 -- or slice is an lvalue, except if it is an access type, where we
18993 -- have an implicit dereference.
18995 when N_Indexed_Component
18999 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
19003 return May_Be_Lvalue
(P
);
19006 -- Prefix of a reference is an lvalue if the reference is an lvalue
19008 when N_Reference
=>
19009 return May_Be_Lvalue
(P
);
19011 -- Prefix of explicit dereference is never an lvalue
19013 when N_Explicit_Dereference
=>
19016 -- Positional parameter for subprogram, entry, or accept call.
19017 -- In older versions of Ada function call arguments are never
19018 -- lvalues. In Ada 2012 functions can have in-out parameters.
19020 when N_Accept_Statement
19021 | N_Entry_Call_Statement
19022 | N_Subprogram_Call
19024 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
19028 -- The following mechanism is clumsy and fragile. A single flag
19029 -- set in Resolve_Actuals would be preferable ???
19037 Proc
:= Get_Subprogram_Entity
(P
);
19043 -- If we are not a list member, something is strange, so be
19044 -- conservative and return True.
19046 if not Is_List_Member
(N
) then
19050 -- We are going to find the right formal by stepping forward
19051 -- through the formals, as we step backwards in the actuals.
19053 Form
:= First_Formal
(Proc
);
19056 -- If no formal, something is weird, so be conservative and
19064 exit when No
(Act
);
19065 Next_Formal
(Form
);
19068 return Ekind
(Form
) /= E_In_Parameter
;
19071 -- Named parameter for procedure or accept call
19073 when N_Parameter_Association
=>
19079 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
19085 -- Loop through formals to find the one that matches
19087 Form
:= First_Formal
(Proc
);
19089 -- If no matching formal, that's peculiar, some kind of
19090 -- previous error, so return True to be conservative.
19091 -- Actually happens with legal code for an unresolved call
19092 -- where we may get the wrong homonym???
19098 -- Else test for match
19100 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
19101 return Ekind
(Form
) /= E_In_Parameter
;
19104 Next_Formal
(Form
);
19108 -- Test for appearing in a conversion that itself appears in an
19109 -- lvalue context, since this should be an lvalue.
19111 when N_Type_Conversion
=>
19112 return May_Be_Lvalue
(P
);
19114 -- Test for appearance in object renaming declaration
19116 when N_Object_Renaming_Declaration
=>
19119 -- All other references are definitely not lvalues
19130 function Might_Raise
(N
: Node_Id
) return Boolean is
19131 Result
: Boolean := False;
19133 function Process
(N
: Node_Id
) return Traverse_Result
;
19134 -- Set Result to True if we find something that could raise an exception
19140 function Process
(N
: Node_Id
) return Traverse_Result
is
19142 if Nkind_In
(N
, N_Procedure_Call_Statement
,
19145 N_Raise_Constraint_Error
,
19146 N_Raise_Program_Error
,
19147 N_Raise_Storage_Error
)
19156 procedure Set_Result
is new Traverse_Proc
(Process
);
19158 -- Start of processing for Might_Raise
19161 -- False if exceptions can't be propagated
19163 if No_Exception_Handlers_Set
then
19167 -- If the checks handled by the back end are not disabled, we cannot
19168 -- ensure that no exception will be raised.
19170 if not Access_Checks_Suppressed
(Empty
)
19171 or else not Discriminant_Checks_Suppressed
(Empty
)
19172 or else not Range_Checks_Suppressed
(Empty
)
19173 or else not Index_Checks_Suppressed
(Empty
)
19174 or else Opt
.Stack_Checking_Enabled
19183 --------------------------------
19184 -- Nearest_Enclosing_Instance --
19185 --------------------------------
19187 function Nearest_Enclosing_Instance
(E
: Entity_Id
) return Entity_Id
is
19192 while Present
(Inst
) and then Inst
/= Standard_Standard
loop
19193 if Is_Generic_Instance
(Inst
) then
19197 Inst
:= Scope
(Inst
);
19201 end Nearest_Enclosing_Instance
;
19203 ----------------------
19204 -- Needs_One_Actual --
19205 ----------------------
19207 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
19208 Formal
: Entity_Id
;
19211 -- Ada 2005 or later, and formals present. The first formal must be
19212 -- of a type that supports prefix notation: a controlling argument,
19213 -- a class-wide type, or an access to such.
19215 if Ada_Version
>= Ada_2005
19216 and then Present
(First_Formal
(E
))
19217 and then No
(Default_Value
(First_Formal
(E
)))
19219 (Is_Controlling_Formal
(First_Formal
(E
))
19220 or else Is_Class_Wide_Type
(Etype
(First_Formal
(E
)))
19221 or else Is_Anonymous_Access_Type
(Etype
(First_Formal
(E
))))
19223 Formal
:= Next_Formal
(First_Formal
(E
));
19224 while Present
(Formal
) loop
19225 if No
(Default_Value
(Formal
)) then
19229 Next_Formal
(Formal
);
19234 -- Ada 83/95 or no formals
19239 end Needs_One_Actual
;
19241 ---------------------------------
19242 -- Needs_Simple_Initialization --
19243 ---------------------------------
19245 function Needs_Simple_Initialization
19247 Consider_IS
: Boolean := True) return Boolean
19249 Consider_IS_NS
: constant Boolean :=
19250 Normalize_Scalars
or (Initialize_Scalars
and Consider_IS
);
19253 -- Never need initialization if it is suppressed
19255 if Initialization_Suppressed
(Typ
) then
19259 -- Check for private type, in which case test applies to the underlying
19260 -- type of the private type.
19262 if Is_Private_Type
(Typ
) then
19264 RT
: constant Entity_Id
:= Underlying_Type
(Typ
);
19266 if Present
(RT
) then
19267 return Needs_Simple_Initialization
(RT
);
19273 -- Scalar type with Default_Value aspect requires initialization
19275 elsif Is_Scalar_Type
(Typ
) and then Has_Default_Aspect
(Typ
) then
19278 -- Cases needing simple initialization are access types, and, if pragma
19279 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19282 elsif Is_Access_Type
(Typ
)
19283 or else (Consider_IS_NS
and then (Is_Scalar_Type
(Typ
)))
19287 -- If Initialize/Normalize_Scalars is in effect, string objects also
19288 -- need initialization, unless they are created in the course of
19289 -- expanding an aggregate (since in the latter case they will be
19290 -- filled with appropriate initializing values before they are used).
19292 elsif Consider_IS_NS
19293 and then Is_Standard_String_Type
(Typ
)
19295 (not Is_Itype
(Typ
)
19296 or else Nkind
(Associated_Node_For_Itype
(Typ
)) /= N_Aggregate
)
19303 end Needs_Simple_Initialization
;
19305 -------------------------------------
19306 -- Needs_Variable_Reference_Marker --
19307 -------------------------------------
19309 function Needs_Variable_Reference_Marker
19311 Calls_OK
: Boolean) return Boolean
19313 function Within_Suitable_Context
(Ref
: Node_Id
) return Boolean;
19314 -- Deteremine whether variable reference Ref appears within a suitable
19315 -- context that allows the creation of a marker.
19317 -----------------------------
19318 -- Within_Suitable_Context --
19319 -----------------------------
19321 function Within_Suitable_Context
(Ref
: Node_Id
) return Boolean is
19326 while Present
(Par
) loop
19328 -- The context is not suitable when the reference appears within
19329 -- the formal part of an instantiation which acts as compilation
19330 -- unit because there is no proper list for the insertion of the
19333 if Nkind
(Par
) = N_Generic_Association
19334 and then Nkind
(Parent
(Par
)) in N_Generic_Instantiation
19335 and then Nkind
(Parent
(Parent
(Par
))) = N_Compilation_Unit
19339 -- The context is not suitable when the reference appears within
19340 -- a pragma. If the pragma has run-time semantics, the reference
19341 -- will be reconsidered once the pragma is expanded.
19343 elsif Nkind
(Par
) = N_Pragma
then
19346 -- The context is not suitable when the reference appears within a
19347 -- subprogram call, and the caller requests this behavior.
19350 and then Nkind_In
(Par
, N_Entry_Call_Statement
,
19352 N_Procedure_Call_Statement
)
19356 -- Prevent the search from going too far
19358 elsif Is_Body_Or_Package_Declaration
(Par
) then
19362 Par
:= Parent
(Par
);
19366 end Within_Suitable_Context
;
19371 Var_Id
: Entity_Id
;
19373 -- Start of processing for Needs_Variable_Reference_Marker
19376 -- No marker needs to be created when switch -gnatH (legacy elaboration
19377 -- checking mode enabled) is in effect because the legacy ABE mechanism
19378 -- does not use markers.
19380 if Legacy_Elaboration_Checks
then
19383 -- No marker needs to be created for ASIS because ABE diagnostics and
19384 -- checks are not performed in this mode.
19386 elsif ASIS_Mode
then
19389 -- No marker needs to be created when the reference is preanalyzed
19390 -- because the marker will be inserted in the wrong place.
19392 elsif Preanalysis_Active
then
19395 -- Only references warrant a marker
19397 elsif not Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
19400 -- Only source references warrant a marker
19402 elsif not Comes_From_Source
(N
) then
19405 -- No marker needs to be created when the reference is erroneous, left
19406 -- in a bad state, or does not denote a variable.
19408 elsif not (Present
(Entity
(N
))
19409 and then Ekind
(Entity
(N
)) = E_Variable
19410 and then Entity
(N
) /= Any_Id
)
19415 Var_Id
:= Entity
(N
);
19416 Prag
:= SPARK_Pragma
(Var_Id
);
19418 -- Both the variable and reference must appear in SPARK_Mode On regions
19419 -- because this elaboration scenario falls under the SPARK rules.
19421 if not (Comes_From_Source
(Var_Id
)
19422 and then Present
(Prag
)
19423 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
19424 and then Is_SPARK_Mode_On_Node
(N
))
19428 -- No marker needs to be created when the reference does not appear
19429 -- within a suitable context (see body for details).
19431 -- Performance note: parent traversal
19433 elsif not Within_Suitable_Context
(N
) then
19437 -- At this point it is known that the variable reference will play a
19438 -- role in ABE diagnostics and requires a marker.
19441 end Needs_Variable_Reference_Marker
;
19443 ------------------------
19444 -- New_Copy_List_Tree --
19445 ------------------------
19447 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
19452 if List
= No_List
then
19459 while Present
(E
) loop
19460 Append
(New_Copy_Tree
(E
), NL
);
19466 end New_Copy_List_Tree
;
19468 -------------------
19469 -- New_Copy_Tree --
19470 -------------------
19472 -- The following tables play a key role in replicating entities and Itypes.
19473 -- They are intentionally declared at the library level rather than within
19474 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19475 -- optimization saves up to 2% of the entire compilation time spent in the
19476 -- front end. Care should be taken to reset the tables on each new call to
19479 NCT_Table_Max
: constant := 511;
19481 subtype NCT_Table_Index
is Nat
range 0 .. NCT_Table_Max
- 1;
19483 function NCT_Table_Hash
(Key
: Node_Or_Entity_Id
) return NCT_Table_Index
;
19484 -- Obtain the hash value of node or entity Key
19486 --------------------
19487 -- NCT_Table_Hash --
19488 --------------------
19490 function NCT_Table_Hash
(Key
: Node_Or_Entity_Id
) return NCT_Table_Index
is
19492 return NCT_Table_Index
(Key
mod NCT_Table_Max
);
19493 end NCT_Table_Hash
;
19495 ----------------------
19496 -- NCT_New_Entities --
19497 ----------------------
19499 -- The following table maps old entities and Itypes to their corresponding
19500 -- new entities and Itypes.
19504 package NCT_New_Entities
is new Simple_HTable
(
19505 Header_Num
=> NCT_Table_Index
,
19506 Element
=> Entity_Id
,
19507 No_Element
=> Empty
,
19509 Hash
=> NCT_Table_Hash
,
19512 ------------------------
19513 -- NCT_Pending_Itypes --
19514 ------------------------
19516 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19517 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19518 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19519 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19521 -- Ppp -> (Xxx, Yyy, Zzz)
19523 -- The set is expressed as an Elist
19525 package NCT_Pending_Itypes
is new Simple_HTable
(
19526 Header_Num
=> NCT_Table_Index
,
19527 Element
=> Elist_Id
,
19528 No_Element
=> No_Elist
,
19530 Hash
=> NCT_Table_Hash
,
19533 NCT_Tables_In_Use
: Boolean := False;
19534 -- This flag keeps track of whether the two tables NCT_New_Entities and
19535 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19536 -- where certain operations are not performed if the tables are not in
19537 -- use. This saves up to 8% of the entire compilation time spent in the
19540 -------------------
19541 -- New_Copy_Tree --
19542 -------------------
19544 function New_Copy_Tree
19546 Map
: Elist_Id
:= No_Elist
;
19547 New_Sloc
: Source_Ptr
:= No_Location
;
19548 New_Scope
: Entity_Id
:= Empty
;
19549 Scopes_In_EWA_OK
: Boolean := False) return Node_Id
19551 -- This routine performs low-level tree manipulations and needs access
19552 -- to the internals of the tree.
19554 use Atree
.Unchecked_Access
;
19555 use Atree_Private_Part
;
19557 EWA_Level
: Nat
:= 0;
19558 -- This counter keeps track of how many N_Expression_With_Actions nodes
19559 -- are encountered during a depth-first traversal of the subtree. These
19560 -- nodes may define new entities in their Actions lists and thus require
19561 -- special processing.
19563 EWA_Inner_Scope_Level
: Nat
:= 0;
19564 -- This counter keeps track of how many scoping constructs appear within
19565 -- an N_Expression_With_Actions node.
19567 procedure Add_New_Entity
(Old_Id
: Entity_Id
; New_Id
: Entity_Id
);
19568 pragma Inline
(Add_New_Entity
);
19569 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19570 -- value New_Id. Old_Id is an entity which appears within the Actions
19571 -- list of an N_Expression_With_Actions node, or within an entity map.
19572 -- New_Id is the corresponding new entity generated during Phase 1.
19574 procedure Add_Pending_Itype
(Assoc_Nod
: Node_Id
; Itype
: Entity_Id
);
19575 pragma Inline
(Add_New_Entity
);
19576 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19577 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19580 procedure Build_NCT_Tables
(Entity_Map
: Elist_Id
);
19581 pragma Inline
(Build_NCT_Tables
);
19582 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19583 -- information supplied in entity map Entity_Map. The format of the
19584 -- entity map must be as follows:
19586 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19588 function Copy_Any_Node_With_Replacement
19589 (N
: Node_Or_Entity_Id
) return Node_Or_Entity_Id
;
19590 pragma Inline
(Copy_Any_Node_With_Replacement
);
19591 -- Replicate entity or node N by invoking one of the following routines:
19593 -- Copy_Node_With_Replacement
19594 -- Corresponding_Entity
19596 function Copy_Elist_With_Replacement
(List
: Elist_Id
) return Elist_Id
;
19597 -- Replicate the elements of entity list List
19599 function Copy_Field_With_Replacement
19601 Old_Par
: Node_Id
:= Empty
;
19602 New_Par
: Node_Id
:= Empty
;
19603 Semantic
: Boolean := False) return Union_Id
;
19604 -- Replicate field Field by invoking one of the following routines:
19606 -- Copy_Elist_With_Replacement
19607 -- Copy_List_With_Replacement
19608 -- Copy_Node_With_Replacement
19609 -- Corresponding_Entity
19611 -- If the field is not an entity list, entity, itype, syntactic list,
19612 -- or node, then the field is returned unchanged. The routine always
19613 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19614 -- the expected parent of a syntactic field. New_Par is the new parent
19615 -- associated with a replicated syntactic field. Flag Semantic should
19616 -- be set when the input is a semantic field.
19618 function Copy_List_With_Replacement
(List
: List_Id
) return List_Id
;
19619 -- Replicate the elements of syntactic list List
19621 function Copy_Node_With_Replacement
(N
: Node_Id
) return Node_Id
;
19622 -- Replicate node N
19624 function Corresponding_Entity
(Id
: Entity_Id
) return Entity_Id
;
19625 pragma Inline
(Corresponding_Entity
);
19626 -- Return the corresponding new entity of Id generated during Phase 1.
19627 -- If there is no such entity, return Id.
19629 function In_Entity_Map
19631 Entity_Map
: Elist_Id
) return Boolean;
19632 pragma Inline
(In_Entity_Map
);
19633 -- Determine whether entity Id is one of the old ids specified in entity
19634 -- map Entity_Map. The format of the entity map must be as follows:
19636 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19638 procedure Update_CFS_Sloc
(N
: Node_Or_Entity_Id
);
19639 pragma Inline
(Update_CFS_Sloc
);
19640 -- Update the Comes_From_Source and Sloc attributes of node or entity N
19642 procedure Update_First_Real_Statement
19643 (Old_HSS
: Node_Id
;
19644 New_HSS
: Node_Id
);
19645 pragma Inline
(Update_First_Real_Statement
);
19646 -- Update semantic attribute First_Real_Statement of handled sequence of
19647 -- statements New_HSS based on handled sequence of statements Old_HSS.
19649 procedure Update_Named_Associations
19650 (Old_Call
: Node_Id
;
19651 New_Call
: Node_Id
);
19652 pragma Inline
(Update_Named_Associations
);
19653 -- Update semantic chain First/Next_Named_Association of call New_call
19654 -- based on call Old_Call.
19656 procedure Update_New_Entities
(Entity_Map
: Elist_Id
);
19657 pragma Inline
(Update_New_Entities
);
19658 -- Update the semantic attributes of all new entities generated during
19659 -- Phase 1 that do not appear in entity map Entity_Map. The format of
19660 -- the entity map must be as follows:
19662 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19664 procedure Update_Pending_Itypes
19665 (Old_Assoc
: Node_Id
;
19666 New_Assoc
: Node_Id
);
19667 pragma Inline
(Update_Pending_Itypes
);
19668 -- Update semantic attribute Associated_Node_For_Itype to refer to node
19669 -- New_Assoc for all itypes whose associated node is Old_Assoc.
19671 procedure Update_Semantic_Fields
(Id
: Entity_Id
);
19672 pragma Inline
(Update_Semantic_Fields
);
19673 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
19676 procedure Visit_Any_Node
(N
: Node_Or_Entity_Id
);
19677 pragma Inline
(Visit_Any_Node
);
19678 -- Visit entity of node N by invoking one of the following routines:
19684 procedure Visit_Elist
(List
: Elist_Id
);
19685 -- Visit the elements of entity list List
19687 procedure Visit_Entity
(Id
: Entity_Id
);
19688 -- Visit entity Id. This action may create a new entity of Id and save
19689 -- it in table NCT_New_Entities.
19691 procedure Visit_Field
19693 Par_Nod
: Node_Id
:= Empty
;
19694 Semantic
: Boolean := False);
19695 -- Visit field Field by invoking one of the following routines:
19703 -- If the field is not an entity list, entity, itype, syntactic list,
19704 -- or node, then the field is not visited. The routine always visits
19705 -- valid syntactic fields. Par_Nod is the expected parent of the
19706 -- syntactic field. Flag Semantic should be set when the input is a
19709 procedure Visit_Itype
(Itype
: Entity_Id
);
19710 -- Visit itype Itype. This action may create a new entity for Itype and
19711 -- save it in table NCT_New_Entities. In addition, the routine may map
19712 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
19714 procedure Visit_List
(List
: List_Id
);
19715 -- Visit the elements of syntactic list List
19717 procedure Visit_Node
(N
: Node_Id
);
19720 procedure Visit_Semantic_Fields
(Id
: Entity_Id
);
19721 pragma Inline
(Visit_Semantic_Fields
);
19722 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
19723 -- fields of entity or itype Id.
19725 --------------------
19726 -- Add_New_Entity --
19727 --------------------
19729 procedure Add_New_Entity
(Old_Id
: Entity_Id
; New_Id
: Entity_Id
) is
19731 pragma Assert
(Present
(Old_Id
));
19732 pragma Assert
(Present
(New_Id
));
19733 pragma Assert
(Nkind
(Old_Id
) in N_Entity
);
19734 pragma Assert
(Nkind
(New_Id
) in N_Entity
);
19736 NCT_Tables_In_Use
:= True;
19738 -- Sanity check the NCT_New_Entities table. No previous mapping with
19739 -- key Old_Id should exist.
19741 pragma Assert
(No
(NCT_New_Entities
.Get
(Old_Id
)));
19743 -- Establish the mapping
19745 -- Old_Id -> New_Id
19747 NCT_New_Entities
.Set
(Old_Id
, New_Id
);
19748 end Add_New_Entity
;
19750 -----------------------
19751 -- Add_Pending_Itype --
19752 -----------------------
19754 procedure Add_Pending_Itype
(Assoc_Nod
: Node_Id
; Itype
: Entity_Id
) is
19758 pragma Assert
(Present
(Assoc_Nod
));
19759 pragma Assert
(Present
(Itype
));
19760 pragma Assert
(Nkind
(Itype
) in N_Entity
);
19761 pragma Assert
(Is_Itype
(Itype
));
19763 NCT_Tables_In_Use
:= True;
19765 -- It is not possible to sanity check the NCT_Pendint_Itypes table
19766 -- directly because a single node may act as the associated node for
19767 -- multiple itypes.
19769 Itypes
:= NCT_Pending_Itypes
.Get
(Assoc_Nod
);
19771 if No
(Itypes
) then
19772 Itypes
:= New_Elmt_List
;
19773 NCT_Pending_Itypes
.Set
(Assoc_Nod
, Itypes
);
19776 -- Establish the mapping
19778 -- Assoc_Nod -> (Itype, ...)
19780 -- Avoid inserting the same itype multiple times. This involves a
19781 -- linear search, however the set of itypes with the same associated
19782 -- node is very small.
19784 Append_Unique_Elmt
(Itype
, Itypes
);
19785 end Add_Pending_Itype
;
19787 ----------------------
19788 -- Build_NCT_Tables --
19789 ----------------------
19791 procedure Build_NCT_Tables
(Entity_Map
: Elist_Id
) is
19793 Old_Id
: Entity_Id
;
19794 New_Id
: Entity_Id
;
19797 -- Nothing to do when there is no entity map
19799 if No
(Entity_Map
) then
19803 Elmt
:= First_Elmt
(Entity_Map
);
19804 while Present
(Elmt
) loop
19806 -- Extract the (Old_Id, New_Id) pair from the entity map
19808 Old_Id
:= Node
(Elmt
);
19811 New_Id
:= Node
(Elmt
);
19814 -- Establish the following mapping within table NCT_New_Entities
19816 -- Old_Id -> New_Id
19818 Add_New_Entity
(Old_Id
, New_Id
);
19820 -- Establish the following mapping within table NCT_Pending_Itypes
19821 -- when the new entity is an itype.
19823 -- Assoc_Nod -> (New_Id, ...)
19825 -- IMPORTANT: the associated node is that of the old itype because
19826 -- the node will be replicated in Phase 2.
19828 if Is_Itype
(Old_Id
) then
19830 (Assoc_Nod
=> Associated_Node_For_Itype
(Old_Id
),
19834 end Build_NCT_Tables
;
19836 ------------------------------------
19837 -- Copy_Any_Node_With_Replacement --
19838 ------------------------------------
19840 function Copy_Any_Node_With_Replacement
19841 (N
: Node_Or_Entity_Id
) return Node_Or_Entity_Id
19844 if Nkind
(N
) in N_Entity
then
19845 return Corresponding_Entity
(N
);
19847 return Copy_Node_With_Replacement
(N
);
19849 end Copy_Any_Node_With_Replacement
;
19851 ---------------------------------
19852 -- Copy_Elist_With_Replacement --
19853 ---------------------------------
19855 function Copy_Elist_With_Replacement
(List
: Elist_Id
) return Elist_Id
is
19860 -- Copy the contents of the old list. Note that the list itself may
19861 -- be empty, in which case the routine returns a new empty list. This
19862 -- avoids sharing lists between subtrees. The element of an entity
19863 -- list could be an entity or a node, hence the invocation of routine
19864 -- Copy_Any_Node_With_Replacement.
19866 if Present
(List
) then
19867 Result
:= New_Elmt_List
;
19869 Elmt
:= First_Elmt
(List
);
19870 while Present
(Elmt
) loop
19872 (Copy_Any_Node_With_Replacement
(Node
(Elmt
)), Result
);
19877 -- Otherwise the list does not exist
19880 Result
:= No_Elist
;
19884 end Copy_Elist_With_Replacement
;
19886 ---------------------------------
19887 -- Copy_Field_With_Replacement --
19888 ---------------------------------
19890 function Copy_Field_With_Replacement
19892 Old_Par
: Node_Id
:= Empty
;
19893 New_Par
: Node_Id
:= Empty
;
19894 Semantic
: Boolean := False) return Union_Id
19897 -- The field is empty
19899 if Field
= Union_Id
(Empty
) then
19902 -- The field is an entity/itype/node
19904 elsif Field
in Node_Range
then
19906 Old_N
: constant Node_Id
:= Node_Id
(Field
);
19907 Syntactic
: constant Boolean := Parent
(Old_N
) = Old_Par
;
19912 -- The field is an entity/itype
19914 if Nkind
(Old_N
) in N_Entity
then
19916 -- An entity/itype is always replicated
19918 New_N
:= Corresponding_Entity
(Old_N
);
19920 -- Update the parent pointer when the entity is a syntactic
19921 -- field. Note that itypes do not have parent pointers.
19923 if Syntactic
and then New_N
/= Old_N
then
19924 Set_Parent
(New_N
, New_Par
);
19927 -- The field is a node
19930 -- A node is replicated when it is either a syntactic field
19931 -- or when the caller treats it as a semantic attribute.
19933 if Syntactic
or else Semantic
then
19934 New_N
:= Copy_Node_With_Replacement
(Old_N
);
19936 -- Update the parent pointer when the node is a syntactic
19939 if Syntactic
and then New_N
/= Old_N
then
19940 Set_Parent
(New_N
, New_Par
);
19943 -- Otherwise the node is returned unchanged
19950 return Union_Id
(New_N
);
19953 -- The field is an entity list
19955 elsif Field
in Elist_Range
then
19956 return Union_Id
(Copy_Elist_With_Replacement
(Elist_Id
(Field
)));
19958 -- The field is a syntactic list
19960 elsif Field
in List_Range
then
19962 Old_List
: constant List_Id
:= List_Id
(Field
);
19963 Syntactic
: constant Boolean := Parent
(Old_List
) = Old_Par
;
19965 New_List
: List_Id
;
19968 -- A list is replicated when it is either a syntactic field or
19969 -- when the caller treats it as a semantic attribute.
19971 if Syntactic
or else Semantic
then
19972 New_List
:= Copy_List_With_Replacement
(Old_List
);
19974 -- Update the parent pointer when the list is a syntactic
19977 if Syntactic
and then New_List
/= Old_List
then
19978 Set_Parent
(New_List
, New_Par
);
19981 -- Otherwise the list is returned unchanged
19984 New_List
:= Old_List
;
19987 return Union_Id
(New_List
);
19990 -- Otherwise the field denotes an attribute that does not need to be
19991 -- replicated (Chars, literals, etc).
19996 end Copy_Field_With_Replacement
;
19998 --------------------------------
19999 -- Copy_List_With_Replacement --
20000 --------------------------------
20002 function Copy_List_With_Replacement
(List
: List_Id
) return List_Id
is
20007 -- Copy the contents of the old list. Note that the list itself may
20008 -- be empty, in which case the routine returns a new empty list. This
20009 -- avoids sharing lists between subtrees. The element of a syntactic
20010 -- list is always a node, never an entity or itype, hence the call to
20011 -- routine Copy_Node_With_Replacement.
20013 if Present
(List
) then
20014 Result
:= New_List
;
20016 Elmt
:= First
(List
);
20017 while Present
(Elmt
) loop
20018 Append
(Copy_Node_With_Replacement
(Elmt
), Result
);
20023 -- Otherwise the list does not exist
20030 end Copy_List_With_Replacement
;
20032 --------------------------------
20033 -- Copy_Node_With_Replacement --
20034 --------------------------------
20036 function Copy_Node_With_Replacement
(N
: Node_Id
) return Node_Id
is
20040 -- Assume that the node must be returned unchanged
20044 if N
> Empty_Or_Error
then
20045 pragma Assert
(Nkind
(N
) not in N_Entity
);
20047 Result
:= New_Copy
(N
);
20049 Set_Field1
(Result
,
20050 Copy_Field_With_Replacement
20051 (Field
=> Field1
(Result
),
20053 New_Par
=> Result
));
20055 Set_Field2
(Result
,
20056 Copy_Field_With_Replacement
20057 (Field
=> Field2
(Result
),
20059 New_Par
=> Result
));
20061 Set_Field3
(Result
,
20062 Copy_Field_With_Replacement
20063 (Field
=> Field3
(Result
),
20065 New_Par
=> Result
));
20067 Set_Field4
(Result
,
20068 Copy_Field_With_Replacement
20069 (Field
=> Field4
(Result
),
20071 New_Par
=> Result
));
20073 Set_Field5
(Result
,
20074 Copy_Field_With_Replacement
20075 (Field
=> Field5
(Result
),
20077 New_Par
=> Result
));
20079 -- Update the Comes_From_Source and Sloc attributes of the node
20080 -- in case the caller has supplied new values.
20082 Update_CFS_Sloc
(Result
);
20084 -- Update the Associated_Node_For_Itype attribute of all itypes
20085 -- created during Phase 1 whose associated node is N. As a result
20086 -- the Associated_Node_For_Itype refers to the replicated node.
20087 -- No action needs to be taken when the Associated_Node_For_Itype
20088 -- refers to an entity because this was already handled during
20089 -- Phase 1, in Visit_Itype.
20091 Update_Pending_Itypes
20093 New_Assoc
=> Result
);
20095 -- Update the First/Next_Named_Association chain for a replicated
20098 if Nkind_In
(N
, N_Entry_Call_Statement
,
20100 N_Procedure_Call_Statement
)
20102 Update_Named_Associations
20104 New_Call
=> Result
);
20106 -- Update the Renamed_Object attribute of a replicated object
20109 elsif Nkind
(N
) = N_Object_Renaming_Declaration
then
20110 Set_Renamed_Object
(Defining_Entity
(Result
), Name
(Result
));
20112 -- Update the First_Real_Statement attribute of a replicated
20113 -- handled sequence of statements.
20115 elsif Nkind
(N
) = N_Handled_Sequence_Of_Statements
then
20116 Update_First_Real_Statement
20118 New_HSS
=> Result
);
20123 end Copy_Node_With_Replacement
;
20125 --------------------------
20126 -- Corresponding_Entity --
20127 --------------------------
20129 function Corresponding_Entity
(Id
: Entity_Id
) return Entity_Id
is
20130 New_Id
: Entity_Id
;
20131 Result
: Entity_Id
;
20134 -- Assume that the entity must be returned unchanged
20138 if Id
> Empty_Or_Error
then
20139 pragma Assert
(Nkind
(Id
) in N_Entity
);
20141 -- Determine whether the entity has a corresponding new entity
20142 -- generated during Phase 1 and if it does, use it.
20144 if NCT_Tables_In_Use
then
20145 New_Id
:= NCT_New_Entities
.Get
(Id
);
20147 if Present
(New_Id
) then
20154 end Corresponding_Entity
;
20156 -------------------
20157 -- In_Entity_Map --
20158 -------------------
20160 function In_Entity_Map
20162 Entity_Map
: Elist_Id
) return Boolean
20165 Old_Id
: Entity_Id
;
20168 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20169 -- step always skips the New_Id portion of the pair.
20171 if Present
(Entity_Map
) then
20172 Elmt
:= First_Elmt
(Entity_Map
);
20173 while Present
(Elmt
) loop
20174 Old_Id
:= Node
(Elmt
);
20176 if Old_Id
= Id
then
20188 ---------------------
20189 -- Update_CFS_Sloc --
20190 ---------------------
20192 procedure Update_CFS_Sloc
(N
: Node_Or_Entity_Id
) is
20194 -- A new source location defaults the Comes_From_Source attribute
20196 if New_Sloc
/= No_Location
then
20197 Set_Comes_From_Source
(N
, Default_Node
.Comes_From_Source
);
20198 Set_Sloc
(N
, New_Sloc
);
20200 end Update_CFS_Sloc
;
20202 ---------------------------------
20203 -- Update_First_Real_Statement --
20204 ---------------------------------
20206 procedure Update_First_Real_Statement
20207 (Old_HSS
: Node_Id
;
20210 Old_First_Stmt
: constant Node_Id
:= First_Real_Statement
(Old_HSS
);
20212 New_Stmt
: Node_Id
;
20213 Old_Stmt
: Node_Id
;
20216 -- Recreate the First_Real_Statement attribute of a handled sequence
20217 -- of statements by traversing the statement lists of both sequences
20220 if Present
(Old_First_Stmt
) then
20221 New_Stmt
:= First
(Statements
(New_HSS
));
20222 Old_Stmt
:= First
(Statements
(Old_HSS
));
20223 while Present
(Old_Stmt
) and then Old_Stmt
/= Old_First_Stmt
loop
20228 pragma Assert
(Present
(New_Stmt
));
20229 pragma Assert
(Present
(Old_Stmt
));
20231 Set_First_Real_Statement
(New_HSS
, New_Stmt
);
20233 end Update_First_Real_Statement
;
20235 -------------------------------
20236 -- Update_Named_Associations --
20237 -------------------------------
20239 procedure Update_Named_Associations
20240 (Old_Call
: Node_Id
;
20241 New_Call
: Node_Id
)
20244 New_Next
: Node_Id
;
20246 Old_Next
: Node_Id
;
20249 -- Recreate the First/Next_Named_Actual chain of a call by traversing
20250 -- the chains of both the old and new calls in parallel.
20252 New_Act
:= First
(Parameter_Associations
(New_Call
));
20253 Old_Act
:= First
(Parameter_Associations
(Old_Call
));
20254 while Present
(Old_Act
) loop
20255 if Nkind
(Old_Act
) = N_Parameter_Association
20256 and then Present
(Next_Named_Actual
(Old_Act
))
20258 if First_Named_Actual
(Old_Call
) =
20259 Explicit_Actual_Parameter
(Old_Act
)
20261 Set_First_Named_Actual
(New_Call
,
20262 Explicit_Actual_Parameter
(New_Act
));
20265 -- Scan the actual parameter list to find the next suitable
20266 -- named actual. Note that the list may be out of order.
20268 New_Next
:= First
(Parameter_Associations
(New_Call
));
20269 Old_Next
:= First
(Parameter_Associations
(Old_Call
));
20270 while Nkind
(Old_Next
) /= N_Parameter_Association
20271 or else Explicit_Actual_Parameter
(Old_Next
) /=
20272 Next_Named_Actual
(Old_Act
)
20278 Set_Next_Named_Actual
(New_Act
,
20279 Explicit_Actual_Parameter
(New_Next
));
20285 end Update_Named_Associations
;
20287 -------------------------
20288 -- Update_New_Entities --
20289 -------------------------
20291 procedure Update_New_Entities
(Entity_Map
: Elist_Id
) is
20292 New_Id
: Entity_Id
:= Empty
;
20293 Old_Id
: Entity_Id
:= Empty
;
20296 if NCT_Tables_In_Use
then
20297 NCT_New_Entities
.Get_First
(Old_Id
, New_Id
);
20299 -- Update the semantic fields of all new entities created during
20300 -- Phase 1 which were not supplied via an entity map.
20301 -- ??? Is there a better way of distinguishing those?
20303 while Present
(Old_Id
) and then Present
(New_Id
) loop
20304 if not (Present
(Entity_Map
)
20305 and then In_Entity_Map
(Old_Id
, Entity_Map
))
20307 Update_Semantic_Fields
(New_Id
);
20310 NCT_New_Entities
.Get_Next
(Old_Id
, New_Id
);
20313 end Update_New_Entities
;
20315 ---------------------------
20316 -- Update_Pending_Itypes --
20317 ---------------------------
20319 procedure Update_Pending_Itypes
20320 (Old_Assoc
: Node_Id
;
20321 New_Assoc
: Node_Id
)
20327 if NCT_Tables_In_Use
then
20328 Itypes
:= NCT_Pending_Itypes
.Get
(Old_Assoc
);
20330 -- Update the Associated_Node_For_Itype attribute for all itypes
20331 -- which originally refer to Old_Assoc to designate New_Assoc.
20333 if Present
(Itypes
) then
20334 Item
:= First_Elmt
(Itypes
);
20335 while Present
(Item
) loop
20336 Set_Associated_Node_For_Itype
(Node
(Item
), New_Assoc
);
20342 end Update_Pending_Itypes
;
20344 ----------------------------
20345 -- Update_Semantic_Fields --
20346 ----------------------------
20348 procedure Update_Semantic_Fields
(Id
: Entity_Id
) is
20350 -- Discriminant_Constraint
20352 if Is_Type
(Id
) and then Has_Discriminants
(Base_Type
(Id
)) then
20353 Set_Discriminant_Constraint
(Id
, Elist_Id
(
20354 Copy_Field_With_Replacement
20355 (Field
=> Union_Id
(Discriminant_Constraint
(Id
)),
20356 Semantic
=> True)));
20361 Set_Etype
(Id
, Node_Id
(
20362 Copy_Field_With_Replacement
20363 (Field
=> Union_Id
(Etype
(Id
)),
20364 Semantic
=> True)));
20367 -- Packed_Array_Impl_Type
20369 if Is_Array_Type
(Id
) then
20370 if Present
(First_Index
(Id
)) then
20371 Set_First_Index
(Id
, First
(List_Id
(
20372 Copy_Field_With_Replacement
20373 (Field
=> Union_Id
(List_Containing
(First_Index
(Id
))),
20374 Semantic
=> True))));
20377 if Is_Packed
(Id
) then
20378 Set_Packed_Array_Impl_Type
(Id
, Node_Id
(
20379 Copy_Field_With_Replacement
20380 (Field
=> Union_Id
(Packed_Array_Impl_Type
(Id
)),
20381 Semantic
=> True)));
20387 Set_Prev_Entity
(Id
, Node_Id
(
20388 Copy_Field_With_Replacement
20389 (Field
=> Union_Id
(Prev_Entity
(Id
)),
20390 Semantic
=> True)));
20394 Set_Next_Entity
(Id
, Node_Id
(
20395 Copy_Field_With_Replacement
20396 (Field
=> Union_Id
(Next_Entity
(Id
)),
20397 Semantic
=> True)));
20401 if Is_Discrete_Type
(Id
) then
20402 Set_Scalar_Range
(Id
, Node_Id
(
20403 Copy_Field_With_Replacement
20404 (Field
=> Union_Id
(Scalar_Range
(Id
)),
20405 Semantic
=> True)));
20410 -- Update the scope when the caller specified an explicit one
20412 if Present
(New_Scope
) then
20413 Set_Scope
(Id
, New_Scope
);
20415 Set_Scope
(Id
, Node_Id
(
20416 Copy_Field_With_Replacement
20417 (Field
=> Union_Id
(Scope
(Id
)),
20418 Semantic
=> True)));
20420 end Update_Semantic_Fields
;
20422 --------------------
20423 -- Visit_Any_Node --
20424 --------------------
20426 procedure Visit_Any_Node
(N
: Node_Or_Entity_Id
) is
20428 if Nkind
(N
) in N_Entity
then
20429 if Is_Itype
(N
) then
20437 end Visit_Any_Node
;
20443 procedure Visit_Elist
(List
: Elist_Id
) is
20447 -- The element of an entity list could be an entity, itype, or a
20448 -- node, hence the call to Visit_Any_Node.
20450 if Present
(List
) then
20451 Elmt
:= First_Elmt
(List
);
20452 while Present
(Elmt
) loop
20453 Visit_Any_Node
(Node
(Elmt
));
20464 procedure Visit_Entity
(Id
: Entity_Id
) is
20465 New_Id
: Entity_Id
;
20468 pragma Assert
(Nkind
(Id
) in N_Entity
);
20469 pragma Assert
(not Is_Itype
(Id
));
20471 -- Nothing to do when the entity is not defined in the Actions list
20472 -- of an N_Expression_With_Actions node.
20474 if EWA_Level
= 0 then
20477 -- Nothing to do when the entity is defined in a scoping construct
20478 -- within an N_Expression_With_Actions node, unless the caller has
20479 -- requested their replication.
20481 -- ??? should this restriction be eliminated?
20483 elsif EWA_Inner_Scope_Level
> 0 and then not Scopes_In_EWA_OK
then
20486 -- Nothing to do when the entity does not denote a construct that
20487 -- may appear within an N_Expression_With_Actions node. Relaxing
20488 -- this restriction leads to a performance penalty.
20490 -- ??? this list is flaky, and may hide dormant bugs
20492 elsif not Ekind_In
(Id
, E_Block
,
20497 and then not Is_Type
(Id
)
20501 -- Nothing to do when the entity was already visited
20503 elsif NCT_Tables_In_Use
20504 and then Present
(NCT_New_Entities
.Get
(Id
))
20508 -- Nothing to do when the declaration node of the entity is not in
20509 -- the subtree being replicated.
20511 elsif not In_Subtree
20512 (N
=> Declaration_Node
(Id
),
20518 -- Create a new entity by directly copying the old entity. This
20519 -- action causes all attributes of the old entity to be inherited.
20521 New_Id
:= New_Copy
(Id
);
20523 -- Create a new name for the new entity because the back end needs
20524 -- distinct names for debugging purposes.
20526 Set_Chars
(New_Id
, New_Internal_Name
('T'));
20528 -- Update the Comes_From_Source and Sloc attributes of the entity in
20529 -- case the caller has supplied new values.
20531 Update_CFS_Sloc
(New_Id
);
20533 -- Establish the following mapping within table NCT_New_Entities:
20537 Add_New_Entity
(Id
, New_Id
);
20539 -- Deal with the semantic fields of entities. The fields are visited
20540 -- because they may mention entities which reside within the subtree
20543 Visit_Semantic_Fields
(Id
);
20550 procedure Visit_Field
20552 Par_Nod
: Node_Id
:= Empty
;
20553 Semantic
: Boolean := False)
20556 -- The field is empty
20558 if Field
= Union_Id
(Empty
) then
20561 -- The field is an entity/itype/node
20563 elsif Field
in Node_Range
then
20565 N
: constant Node_Id
:= Node_Id
(Field
);
20568 -- The field is an entity/itype
20570 if Nkind
(N
) in N_Entity
then
20572 -- Itypes are always visited
20574 if Is_Itype
(N
) then
20577 -- An entity is visited when it is either a syntactic field
20578 -- or when the caller treats it as a semantic attribute.
20580 elsif Parent
(N
) = Par_Nod
or else Semantic
then
20584 -- The field is a node
20587 -- A node is visited when it is either a syntactic field or
20588 -- when the caller treats it as a semantic attribute.
20590 if Parent
(N
) = Par_Nod
or else Semantic
then
20596 -- The field is an entity list
20598 elsif Field
in Elist_Range
then
20599 Visit_Elist
(Elist_Id
(Field
));
20601 -- The field is a syntax list
20603 elsif Field
in List_Range
then
20605 List
: constant List_Id
:= List_Id
(Field
);
20608 -- A syntax list is visited when it is either a syntactic field
20609 -- or when the caller treats it as a semantic attribute.
20611 if Parent
(List
) = Par_Nod
or else Semantic
then
20616 -- Otherwise the field denotes information which does not need to be
20617 -- visited (chars, literals, etc.).
20628 procedure Visit_Itype
(Itype
: Entity_Id
) is
20629 New_Assoc
: Node_Id
;
20630 New_Itype
: Entity_Id
;
20631 Old_Assoc
: Node_Id
;
20634 pragma Assert
(Nkind
(Itype
) in N_Entity
);
20635 pragma Assert
(Is_Itype
(Itype
));
20637 -- Itypes that describe the designated type of access to subprograms
20638 -- have the structure of subprogram declarations, with signatures,
20639 -- etc. Either we duplicate the signatures completely, or choose to
20640 -- share such itypes, which is fine because their elaboration will
20641 -- have no side effects.
20643 if Ekind
(Itype
) = E_Subprogram_Type
then
20646 -- Nothing to do if the itype was already visited
20648 elsif NCT_Tables_In_Use
20649 and then Present
(NCT_New_Entities
.Get
(Itype
))
20653 -- Nothing to do if the associated node of the itype is not within
20654 -- the subtree being replicated.
20656 elsif not In_Subtree
20657 (N
=> Associated_Node_For_Itype
(Itype
),
20663 -- Create a new itype by directly copying the old itype. This action
20664 -- causes all attributes of the old itype to be inherited.
20666 New_Itype
:= New_Copy
(Itype
);
20668 -- Create a new name for the new itype because the back end requires
20669 -- distinct names for debugging purposes.
20671 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
20673 -- Update the Comes_From_Source and Sloc attributes of the itype in
20674 -- case the caller has supplied new values.
20676 Update_CFS_Sloc
(New_Itype
);
20678 -- Establish the following mapping within table NCT_New_Entities:
20680 -- Itype -> New_Itype
20682 Add_New_Entity
(Itype
, New_Itype
);
20684 -- The new itype must be unfrozen because the resulting subtree may
20685 -- be inserted anywhere and cause an earlier or later freezing.
20687 if Present
(Freeze_Node
(New_Itype
)) then
20688 Set_Freeze_Node
(New_Itype
, Empty
);
20689 Set_Is_Frozen
(New_Itype
, False);
20692 -- If a record subtype is simply copied, the entity list will be
20693 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
20694 -- ??? What does this do?
20696 if Ekind_In
(Itype
, E_Class_Wide_Subtype
, E_Record_Subtype
) then
20697 Set_Cloned_Subtype
(New_Itype
, Itype
);
20700 -- The associated node may denote an entity, in which case it may
20701 -- already have a new corresponding entity created during a prior
20702 -- call to Visit_Entity or Visit_Itype for the same subtree.
20705 -- Old_Assoc ---------> New_Assoc
20707 -- Created by Visit_Itype
20708 -- Itype -------------> New_Itype
20709 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
20711 -- In the example above, Old_Assoc is an arbitrary entity that was
20712 -- already visited for the same subtree and has a corresponding new
20713 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
20714 -- of copying entities, however it must be updated to New_Assoc.
20716 Old_Assoc
:= Associated_Node_For_Itype
(Itype
);
20718 if Nkind
(Old_Assoc
) in N_Entity
then
20719 if NCT_Tables_In_Use
then
20720 New_Assoc
:= NCT_New_Entities
.Get
(Old_Assoc
);
20722 if Present
(New_Assoc
) then
20723 Set_Associated_Node_For_Itype
(New_Itype
, New_Assoc
);
20727 -- Otherwise the associated node denotes a node. Postpone the update
20728 -- until Phase 2 when the node is replicated. Establish the following
20729 -- mapping within table NCT_Pending_Itypes:
20731 -- Old_Assoc -> (New_Type, ...)
20734 Add_Pending_Itype
(Old_Assoc
, New_Itype
);
20737 -- Deal with the semantic fields of itypes. The fields are visited
20738 -- because they may mention entities that reside within the subtree
20741 Visit_Semantic_Fields
(Itype
);
20748 procedure Visit_List
(List
: List_Id
) is
20752 -- Note that the element of a syntactic list is always a node, never
20753 -- an entity or itype, hence the call to Visit_Node.
20755 if Present
(List
) then
20756 Elmt
:= First
(List
);
20757 while Present
(Elmt
) loop
20769 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
20771 pragma Assert
(Nkind
(N
) not in N_Entity
);
20773 if Nkind
(N
) = N_Expression_With_Actions
then
20774 EWA_Level
:= EWA_Level
+ 1;
20776 elsif EWA_Level
> 0
20777 and then Nkind_In
(N
, N_Block_Statement
,
20779 N_Subprogram_Declaration
)
20781 EWA_Inner_Scope_Level
:= EWA_Inner_Scope_Level
+ 1;
20785 (Field
=> Field1
(N
),
20789 (Field
=> Field2
(N
),
20793 (Field
=> Field3
(N
),
20797 (Field
=> Field4
(N
),
20801 (Field
=> Field5
(N
),
20805 and then Nkind_In
(N
, N_Block_Statement
,
20807 N_Subprogram_Declaration
)
20809 EWA_Inner_Scope_Level
:= EWA_Inner_Scope_Level
- 1;
20811 elsif Nkind
(N
) = N_Expression_With_Actions
then
20812 EWA_Level
:= EWA_Level
- 1;
20816 ---------------------------
20817 -- Visit_Semantic_Fields --
20818 ---------------------------
20820 procedure Visit_Semantic_Fields
(Id
: Entity_Id
) is
20822 pragma Assert
(Nkind
(Id
) in N_Entity
);
20824 -- Discriminant_Constraint
20826 if Is_Type
(Id
) and then Has_Discriminants
(Base_Type
(Id
)) then
20828 (Field
=> Union_Id
(Discriminant_Constraint
(Id
)),
20835 (Field
=> Union_Id
(Etype
(Id
)),
20839 -- Packed_Array_Impl_Type
20841 if Is_Array_Type
(Id
) then
20842 if Present
(First_Index
(Id
)) then
20844 (Field
=> Union_Id
(List_Containing
(First_Index
(Id
))),
20848 if Is_Packed
(Id
) then
20850 (Field
=> Union_Id
(Packed_Array_Impl_Type
(Id
)),
20857 if Is_Discrete_Type
(Id
) then
20859 (Field
=> Union_Id
(Scalar_Range
(Id
)),
20862 end Visit_Semantic_Fields
;
20864 -- Start of processing for New_Copy_Tree
20867 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
20868 -- shallow copies for each node within, and then updating the child and
20869 -- parent pointers accordingly. This process is straightforward, however
20870 -- the routine must deal with the following complications:
20872 -- * Entities defined within N_Expression_With_Actions nodes must be
20873 -- replicated rather than shared to avoid introducing two identical
20874 -- symbols within the same scope. Note that no other expression can
20875 -- currently define entities.
20878 -- Source_Low : ...;
20879 -- Source_High : ...;
20881 -- <reference to Source_Low>
20882 -- <reference to Source_High>
20885 -- New_Copy_Tree handles this case by first creating new entities
20886 -- and then updating all existing references to point to these new
20893 -- <reference to New_Low>
20894 -- <reference to New_High>
20897 -- * Itypes defined within the subtree must be replicated to avoid any
20898 -- dependencies on invalid or inaccessible data.
20900 -- subtype Source_Itype is ... range Source_Low .. Source_High;
20902 -- New_Copy_Tree handles this case by first creating a new itype in
20903 -- the same fashion as entities, and then updating various relevant
20906 -- subtype New_Itype is ... range New_Low .. New_High;
20908 -- * The Associated_Node_For_Itype field of itypes must be updated to
20909 -- reference the proper replicated entity or node.
20911 -- * Semantic fields of entities such as Etype and Scope must be
20912 -- updated to reference the proper replicated entities.
20914 -- * Semantic fields of nodes such as First_Real_Statement must be
20915 -- updated to reference the proper replicated nodes.
20917 -- To meet all these demands, routine New_Copy_Tree is split into two
20920 -- Phase 1 traverses the tree in order to locate entities and itypes
20921 -- defined within the subtree. New entities are generated and saved in
20922 -- table NCT_New_Entities. The semantic fields of all new entities and
20923 -- itypes are then updated accordingly.
20925 -- Phase 2 traverses the tree in order to replicate each node. Various
20926 -- semantic fields of nodes and entities are updated accordingly.
20928 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
20929 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
20932 if NCT_Tables_In_Use
then
20933 NCT_Tables_In_Use
:= False;
20935 NCT_New_Entities
.Reset
;
20936 NCT_Pending_Itypes
.Reset
;
20939 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
20940 -- supplied by a linear entity map. The tables offer faster access to
20943 Build_NCT_Tables
(Map
);
20945 -- Execute Phase 1. Traverse the subtree and generate new entities for
20946 -- the following cases:
20948 -- * An entity defined within an N_Expression_With_Actions node
20950 -- * An itype referenced within the subtree where the associated node
20951 -- is also in the subtree.
20953 -- All new entities are accessible via table NCT_New_Entities, which
20954 -- contains mappings of the form:
20956 -- Old_Entity -> New_Entity
20957 -- Old_Itype -> New_Itype
20959 -- In addition, the associated nodes of all new itypes are mapped in
20960 -- table NCT_Pending_Itypes:
20962 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
20964 Visit_Any_Node
(Source
);
20966 -- Update the semantic attributes of all new entities generated during
20967 -- Phase 1 before starting Phase 2. The updates could be performed in
20968 -- routine Corresponding_Entity, however this may cause the same entity
20969 -- to be updated multiple times, effectively generating useless nodes.
20970 -- Keeping the updates separates from Phase 2 ensures that only one set
20971 -- of attributes is generated for an entity at any one time.
20973 Update_New_Entities
(Map
);
20975 -- Execute Phase 2. Replicate the source subtree one node at a time.
20976 -- The following transformations take place:
20978 -- * References to entities and itypes are updated to refer to the
20979 -- new entities and itypes generated during Phase 1.
20981 -- * All Associated_Node_For_Itype attributes of itypes are updated
20982 -- to refer to the new replicated Associated_Node_For_Itype.
20984 return Copy_Node_With_Replacement
(Source
);
20987 -------------------------
20988 -- New_External_Entity --
20989 -------------------------
20991 function New_External_Entity
20992 (Kind
: Entity_Kind
;
20993 Scope_Id
: Entity_Id
;
20994 Sloc_Value
: Source_Ptr
;
20995 Related_Id
: Entity_Id
;
20996 Suffix
: Character;
20997 Suffix_Index
: Int
:= 0;
20998 Prefix
: Character := ' ') return Entity_Id
21000 N
: constant Entity_Id
:=
21001 Make_Defining_Identifier
(Sloc_Value
,
21003 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
21006 Set_Ekind
(N
, Kind
);
21007 Set_Is_Internal
(N
, True);
21008 Append_Entity
(N
, Scope_Id
);
21009 Set_Public_Status
(N
);
21011 if Kind
in Type_Kind
then
21012 Init_Size_Align
(N
);
21016 end New_External_Entity
;
21018 -------------------------
21019 -- New_Internal_Entity --
21020 -------------------------
21022 function New_Internal_Entity
21023 (Kind
: Entity_Kind
;
21024 Scope_Id
: Entity_Id
;
21025 Sloc_Value
: Source_Ptr
;
21026 Id_Char
: Character) return Entity_Id
21028 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
21031 Set_Ekind
(N
, Kind
);
21032 Set_Is_Internal
(N
, True);
21033 Append_Entity
(N
, Scope_Id
);
21035 if Kind
in Type_Kind
then
21036 Init_Size_Align
(N
);
21040 end New_Internal_Entity
;
21046 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
21047 Par
: constant Node_Id
:= Parent
(Actual_Id
);
21051 -- If we are pointing at a positional parameter, it is a member of a
21052 -- node list (the list of parameters), and the next parameter is the
21053 -- next node on the list, unless we hit a parameter association, then
21054 -- we shift to using the chain whose head is the First_Named_Actual in
21055 -- the parent, and then is threaded using the Next_Named_Actual of the
21056 -- Parameter_Association. All this fiddling is because the original node
21057 -- list is in the textual call order, and what we need is the
21058 -- declaration order.
21060 if Is_List_Member
(Actual_Id
) then
21061 N
:= Next
(Actual_Id
);
21063 if Nkind
(N
) = N_Parameter_Association
then
21065 -- In case of a build-in-place call, the call will no longer be a
21066 -- call; it will have been rewritten.
21068 if Nkind_In
(Par
, N_Entry_Call_Statement
,
21070 N_Procedure_Call_Statement
)
21072 return First_Named_Actual
(Par
);
21074 -- In case of a call rewritten in GNATprove mode while "inlining
21075 -- for proof" go to the original call.
21077 elsif Nkind
(Par
) = N_Null_Statement
then
21081 Nkind
(Original_Node
(Par
)) in N_Subprogram_Call
);
21083 return First_Named_Actual
(Original_Node
(Par
));
21092 return Next_Named_Actual
(Parent
(Actual_Id
));
21096 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
21098 Actual_Id
:= Next_Actual
(Actual_Id
);
21105 function Next_Global
(Node
: Node_Id
) return Node_Id
is
21107 -- The global item may either be in a list, or by itself, in which case
21108 -- there is no next global item with the same mode.
21110 if Is_List_Member
(Node
) then
21111 return Next
(Node
);
21117 procedure Next_Global
(Node
: in out Node_Id
) is
21119 Node
:= Next_Global
(Node
);
21122 ----------------------------------
21123 -- New_Requires_Transient_Scope --
21124 ----------------------------------
21126 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
21127 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean;
21128 -- This is called for untagged records and protected types, with
21129 -- nondefaulted discriminants. Returns True if the size of function
21130 -- results is known at the call site, False otherwise. Returns False
21131 -- if there is a variant part that depends on the discriminants of
21132 -- this type, or if there is an array constrained by the discriminants
21133 -- of this type. ???Currently, this is overly conservative (the array
21134 -- could be nested inside some other record that is constrained by
21135 -- nondiscriminants). That is, the recursive calls are too conservative.
21137 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean;
21138 -- Returns True if Typ is a nonlimited record with defaulted
21139 -- discriminants whose max size makes it unsuitable for allocating on
21140 -- the primary stack.
21142 ------------------------------
21143 -- Caller_Known_Size_Record --
21144 ------------------------------
21146 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean is
21147 pragma Assert
(Typ
= Underlying_Type
(Typ
));
21150 if Has_Variant_Part
(Typ
) and then not Is_Definite_Subtype
(Typ
) then
21158 Comp
:= First_Entity
(Typ
);
21159 while Present
(Comp
) loop
21161 -- Only look at E_Component entities. No need to look at
21162 -- E_Discriminant entities, and we must ignore internal
21163 -- subtypes generated for constrained components.
21165 if Ekind
(Comp
) = E_Component
then
21167 Comp_Type
: constant Entity_Id
:=
21168 Underlying_Type
(Etype
(Comp
));
21171 if Is_Record_Type
(Comp_Type
)
21173 Is_Protected_Type
(Comp_Type
)
21175 if not Caller_Known_Size_Record
(Comp_Type
) then
21179 elsif Is_Array_Type
(Comp_Type
) then
21180 if Size_Depends_On_Discriminant
(Comp_Type
) then
21187 Next_Entity
(Comp
);
21192 end Caller_Known_Size_Record
;
21194 ------------------------------
21195 -- Large_Max_Size_Mutable --
21196 ------------------------------
21198 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean is
21199 pragma Assert
(Typ
= Underlying_Type
(Typ
));
21201 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean;
21202 -- Returns true if the discrete type T has a large range
21204 ----------------------------
21205 -- Is_Large_Discrete_Type --
21206 ----------------------------
21208 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean is
21209 Threshold
: constant Int
:= 16;
21210 -- Arbitrary threshold above which we consider it "large". We want
21211 -- a fairly large threshold, because these large types really
21212 -- shouldn't have default discriminants in the first place, in
21216 return UI_To_Int
(RM_Size
(T
)) > Threshold
;
21217 end Is_Large_Discrete_Type
;
21219 -- Start of processing for Large_Max_Size_Mutable
21222 if Is_Record_Type
(Typ
)
21223 and then not Is_Limited_View
(Typ
)
21224 and then Has_Defaulted_Discriminants
(Typ
)
21226 -- Loop through the components, looking for an array whose upper
21227 -- bound(s) depends on discriminants, where both the subtype of
21228 -- the discriminant and the index subtype are too large.
21234 Comp
:= First_Entity
(Typ
);
21235 while Present
(Comp
) loop
21236 if Ekind
(Comp
) = E_Component
then
21238 Comp_Type
: constant Entity_Id
:=
21239 Underlying_Type
(Etype
(Comp
));
21246 if Is_Array_Type
(Comp_Type
) then
21247 Indx
:= First_Index
(Comp_Type
);
21249 while Present
(Indx
) loop
21250 Ityp
:= Etype
(Indx
);
21251 Hi
:= Type_High_Bound
(Ityp
);
21253 if Nkind
(Hi
) = N_Identifier
21254 and then Ekind
(Entity
(Hi
)) = E_Discriminant
21255 and then Is_Large_Discrete_Type
(Ityp
)
21256 and then Is_Large_Discrete_Type
21257 (Etype
(Entity
(Hi
)))
21268 Next_Entity
(Comp
);
21274 end Large_Max_Size_Mutable
;
21276 -- Local declarations
21278 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
21280 -- Start of processing for New_Requires_Transient_Scope
21283 -- This is a private type which is not completed yet. This can only
21284 -- happen in a default expression (of a formal parameter or of a
21285 -- record component). Do not expand transient scope in this case.
21290 -- Do not expand transient scope for non-existent procedure return or
21291 -- string literal types.
21293 elsif Typ
= Standard_Void_Type
21294 or else Ekind
(Typ
) = E_String_Literal_Subtype
21298 -- If Typ is a generic formal incomplete type, then we want to look at
21299 -- the actual type.
21301 elsif Ekind
(Typ
) = E_Record_Subtype
21302 and then Present
(Cloned_Subtype
(Typ
))
21304 return New_Requires_Transient_Scope
(Cloned_Subtype
(Typ
));
21306 -- Functions returning specific tagged types may dispatch on result, so
21307 -- their returned value is allocated on the secondary stack, even in the
21308 -- definite case. We must treat nondispatching functions the same way,
21309 -- because access-to-function types can point at both, so the calling
21310 -- conventions must be compatible. Is_Tagged_Type includes controlled
21311 -- types and class-wide types. Controlled type temporaries need
21314 -- ???It's not clear why we need to return noncontrolled types with
21315 -- controlled components on the secondary stack.
21317 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
21320 -- Untagged definite subtypes are known size. This includes all
21321 -- elementary [sub]types. Tasks are known size even if they have
21322 -- discriminants. So we return False here, with one exception:
21323 -- For a type like:
21324 -- type T (Last : Natural := 0) is
21325 -- X : String (1 .. Last);
21327 -- we return True. That's because for "P(F(...));", where F returns T,
21328 -- we don't know the size of the result at the call site, so if we
21329 -- allocated it on the primary stack, we would have to allocate the
21330 -- maximum size, which is way too big.
21332 elsif Is_Definite_Subtype
(Typ
) or else Is_Task_Type
(Typ
) then
21333 return Large_Max_Size_Mutable
(Typ
);
21335 -- Indefinite (discriminated) untagged record or protected type
21337 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
21338 return not Caller_Known_Size_Record
(Typ
);
21340 -- Unconstrained array
21343 pragma Assert
(Is_Array_Type
(Typ
) and not Is_Definite_Subtype
(Typ
));
21346 end New_Requires_Transient_Scope
;
21348 --------------------------
21349 -- No_Heap_Finalization --
21350 --------------------------
21352 function No_Heap_Finalization
(Typ
: Entity_Id
) return Boolean is
21354 if Ekind_In
(Typ
, E_Access_Type
, E_General_Access_Type
)
21355 and then Is_Library_Level_Entity
(Typ
)
21357 -- A global No_Heap_Finalization pragma applies to all library-level
21358 -- named access-to-object types.
21360 if Present
(No_Heap_Finalization_Pragma
) then
21363 -- The library-level named access-to-object type itself is subject to
21364 -- pragma No_Heap_Finalization.
21366 elsif Present
(Get_Pragma
(Typ
, Pragma_No_Heap_Finalization
)) then
21372 end No_Heap_Finalization
;
21374 -----------------------
21375 -- Normalize_Actuals --
21376 -----------------------
21378 -- Chain actuals according to formals of subprogram. If there are no named
21379 -- associations, the chain is simply the list of Parameter Associations,
21380 -- since the order is the same as the declaration order. If there are named
21381 -- associations, then the First_Named_Actual field in the N_Function_Call
21382 -- or N_Procedure_Call_Statement node points to the Parameter_Association
21383 -- node for the parameter that comes first in declaration order. The
21384 -- remaining named parameters are then chained in declaration order using
21385 -- Next_Named_Actual.
21387 -- This routine also verifies that the number of actuals is compatible with
21388 -- the number and default values of formals, but performs no type checking
21389 -- (type checking is done by the caller).
21391 -- If the matching succeeds, Success is set to True and the caller proceeds
21392 -- with type-checking. If the match is unsuccessful, then Success is set to
21393 -- False, and the caller attempts a different interpretation, if there is
21396 -- If the flag Report is on, the call is not overloaded, and a failure to
21397 -- match can be reported here, rather than in the caller.
21399 procedure Normalize_Actuals
21403 Success
: out Boolean)
21405 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
21406 Actual
: Node_Id
:= Empty
;
21407 Formal
: Entity_Id
;
21408 Last
: Node_Id
:= Empty
;
21409 First_Named
: Node_Id
:= Empty
;
21412 Formals_To_Match
: Integer := 0;
21413 Actuals_To_Match
: Integer := 0;
21415 procedure Chain
(A
: Node_Id
);
21416 -- Add named actual at the proper place in the list, using the
21417 -- Next_Named_Actual link.
21419 function Reporting
return Boolean;
21420 -- Determines if an error is to be reported. To report an error, we
21421 -- need Report to be True, and also we do not report errors caused
21422 -- by calls to init procs that occur within other init procs. Such
21423 -- errors must always be cascaded errors, since if all the types are
21424 -- declared correctly, the compiler will certainly build decent calls.
21430 procedure Chain
(A
: Node_Id
) is
21434 -- Call node points to first actual in list
21436 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
21439 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
21443 Set_Next_Named_Actual
(Last
, Empty
);
21450 function Reporting
return Boolean is
21455 elsif not Within_Init_Proc
then
21458 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
21466 -- Start of processing for Normalize_Actuals
21469 if Is_Access_Type
(S
) then
21471 -- The name in the call is a function call that returns an access
21472 -- to subprogram. The designated type has the list of formals.
21474 Formal
:= First_Formal
(Designated_Type
(S
));
21476 Formal
:= First_Formal
(S
);
21479 while Present
(Formal
) loop
21480 Formals_To_Match
:= Formals_To_Match
+ 1;
21481 Next_Formal
(Formal
);
21484 -- Find if there is a named association, and verify that no positional
21485 -- associations appear after named ones.
21487 if Present
(Actuals
) then
21488 Actual
:= First
(Actuals
);
21491 while Present
(Actual
)
21492 and then Nkind
(Actual
) /= N_Parameter_Association
21494 Actuals_To_Match
:= Actuals_To_Match
+ 1;
21498 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
21500 -- Most common case: positional notation, no defaults
21505 elsif Actuals_To_Match
> Formals_To_Match
then
21507 -- Too many actuals: will not work
21510 if Is_Entity_Name
(Name
(N
)) then
21511 Error_Msg_N
("too many arguments in call to&", Name
(N
));
21513 Error_Msg_N
("too many arguments in call", N
);
21521 First_Named
:= Actual
;
21523 while Present
(Actual
) loop
21524 if Nkind
(Actual
) /= N_Parameter_Association
then
21526 ("positional parameters not allowed after named ones", Actual
);
21531 Actuals_To_Match
:= Actuals_To_Match
+ 1;
21537 if Present
(Actuals
) then
21538 Actual
:= First
(Actuals
);
21541 Formal
:= First_Formal
(S
);
21542 while Present
(Formal
) loop
21544 -- Match the formals in order. If the corresponding actual is
21545 -- positional, nothing to do. Else scan the list of named actuals
21546 -- to find the one with the right name.
21548 if Present
(Actual
)
21549 and then Nkind
(Actual
) /= N_Parameter_Association
21552 Actuals_To_Match
:= Actuals_To_Match
- 1;
21553 Formals_To_Match
:= Formals_To_Match
- 1;
21556 -- For named parameters, search the list of actuals to find
21557 -- one that matches the next formal name.
21559 Actual
:= First_Named
;
21561 while Present
(Actual
) loop
21562 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
21565 Actuals_To_Match
:= Actuals_To_Match
- 1;
21566 Formals_To_Match
:= Formals_To_Match
- 1;
21574 if Ekind
(Formal
) /= E_In_Parameter
21575 or else No
(Default_Value
(Formal
))
21578 if (Comes_From_Source
(S
)
21579 or else Sloc
(S
) = Standard_Location
)
21580 and then Is_Overloadable
(S
)
21584 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
21586 N_Parameter_Association
)
21587 and then Ekind
(S
) /= E_Function
21589 Set_Etype
(N
, Etype
(S
));
21592 Error_Msg_Name_1
:= Chars
(S
);
21593 Error_Msg_Sloc
:= Sloc
(S
);
21595 ("missing argument for parameter & "
21596 & "in call to % declared #", N
, Formal
);
21599 elsif Is_Overloadable
(S
) then
21600 Error_Msg_Name_1
:= Chars
(S
);
21602 -- Point to type derivation that generated the
21605 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
21608 ("missing argument for parameter & "
21609 & "in call to % (inherited) #", N
, Formal
);
21613 ("missing argument for parameter &", N
, Formal
);
21621 Formals_To_Match
:= Formals_To_Match
- 1;
21626 Next_Formal
(Formal
);
21629 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
21636 -- Find some superfluous named actual that did not get
21637 -- attached to the list of associations.
21639 Actual
:= First
(Actuals
);
21640 while Present
(Actual
) loop
21641 if Nkind
(Actual
) = N_Parameter_Association
21642 and then Actual
/= Last
21643 and then No
(Next_Named_Actual
(Actual
))
21645 -- A validity check may introduce a copy of a call that
21646 -- includes an extra actual (for example for an unrelated
21647 -- accessibility check). Check that the extra actual matches
21648 -- some extra formal, which must exist already because
21649 -- subprogram must be frozen at this point.
21651 if Present
(Extra_Formals
(S
))
21652 and then not Comes_From_Source
(Actual
)
21653 and then Nkind
(Actual
) = N_Parameter_Association
21654 and then Chars
(Extra_Formals
(S
)) =
21655 Chars
(Selector_Name
(Actual
))
21660 ("unmatched actual & in call", Selector_Name
(Actual
));
21672 end Normalize_Actuals
;
21674 --------------------------------
21675 -- Note_Possible_Modification --
21676 --------------------------------
21678 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
21679 Modification_Comes_From_Source
: constant Boolean :=
21680 Comes_From_Source
(Parent
(N
));
21686 -- Loop to find referenced entity, if there is one
21692 if Is_Entity_Name
(Exp
) then
21693 Ent
:= Entity
(Exp
);
21695 -- If the entity is missing, it is an undeclared identifier,
21696 -- and there is nothing to annotate.
21702 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
21704 P
: constant Node_Id
:= Prefix
(Exp
);
21707 -- In formal verification mode, keep track of all reads and
21708 -- writes through explicit dereferences.
21710 if GNATprove_Mode
then
21711 SPARK_Specific
.Generate_Dereference
(N
, 'm');
21714 if Nkind
(P
) = N_Selected_Component
21715 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
21717 -- Case of a reference to an entry formal
21719 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
21721 elsif Nkind
(P
) = N_Identifier
21722 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
21723 and then Present
(Expression
(Parent
(Entity
(P
))))
21724 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
21727 -- Case of a reference to a value on which side effects have
21730 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
21738 elsif Nkind_In
(Exp
, N_Type_Conversion
,
21739 N_Unchecked_Type_Conversion
)
21741 Exp
:= Expression
(Exp
);
21744 elsif Nkind_In
(Exp
, N_Slice
,
21745 N_Indexed_Component
,
21746 N_Selected_Component
)
21748 -- Special check, if the prefix is an access type, then return
21749 -- since we are modifying the thing pointed to, not the prefix.
21750 -- When we are expanding, most usually the prefix is replaced
21751 -- by an explicit dereference, and this test is not needed, but
21752 -- in some cases (notably -gnatc mode and generics) when we do
21753 -- not do full expansion, we need this special test.
21755 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
21758 -- Otherwise go to prefix and keep going
21761 Exp
:= Prefix
(Exp
);
21765 -- All other cases, not a modification
21771 -- Now look for entity being referenced
21773 if Present
(Ent
) then
21774 if Is_Object
(Ent
) then
21775 if Comes_From_Source
(Exp
)
21776 or else Modification_Comes_From_Source
21778 -- Give warning if pragma unmodified is given and we are
21779 -- sure this is a modification.
21781 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
21783 -- Note that the entity may be present only as a result
21784 -- of pragma Unused.
21786 if Has_Pragma_Unused
(Ent
) then
21787 Error_Msg_NE
("??pragma Unused given for &!", N
, Ent
);
21790 ("??pragma Unmodified given for &!", N
, Ent
);
21794 Set_Never_Set_In_Source
(Ent
, False);
21797 Set_Is_True_Constant
(Ent
, False);
21798 Set_Current_Value
(Ent
, Empty
);
21799 Set_Is_Known_Null
(Ent
, False);
21801 if not Can_Never_Be_Null
(Ent
) then
21802 Set_Is_Known_Non_Null
(Ent
, False);
21805 -- Follow renaming chain
21807 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
21808 and then Present
(Renamed_Object
(Ent
))
21810 Exp
:= Renamed_Object
(Ent
);
21812 -- If the entity is the loop variable in an iteration over
21813 -- a container, retrieve container expression to indicate
21814 -- possible modification.
21816 if Present
(Related_Expression
(Ent
))
21817 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
21818 N_Iterator_Specification
21820 Exp
:= Original_Node
(Related_Expression
(Ent
));
21825 -- The expression may be the renaming of a subcomponent of an
21826 -- array or container. The assignment to the subcomponent is
21827 -- a modification of the container.
21829 elsif Comes_From_Source
(Original_Node
(Exp
))
21830 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
21831 N_Indexed_Component
)
21833 Exp
:= Prefix
(Original_Node
(Exp
));
21837 -- Generate a reference only if the assignment comes from
21838 -- source. This excludes, for example, calls to a dispatching
21839 -- assignment operation when the left-hand side is tagged. In
21840 -- GNATprove mode, we need those references also on generated
21841 -- code, as these are used to compute the local effects of
21844 if Modification_Comes_From_Source
or GNATprove_Mode
then
21845 Generate_Reference
(Ent
, Exp
, 'm');
21847 -- If the target of the assignment is the bound variable
21848 -- in an iterator, indicate that the corresponding array
21849 -- or container is also modified.
21851 if Ada_Version
>= Ada_2012
21852 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
21855 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
21858 -- TBD : in the full version of the construct, the
21859 -- domain of iteration can be given by an expression.
21861 if Is_Entity_Name
(Domain
) then
21862 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
21863 Set_Is_True_Constant
(Entity
(Domain
), False);
21864 Set_Never_Set_In_Source
(Entity
(Domain
), False);
21873 -- If we are sure this is a modification from source, and we know
21874 -- this modifies a constant, then give an appropriate warning.
21877 and then Modification_Comes_From_Source
21878 and then Overlays_Constant
(Ent
)
21879 and then Address_Clause_Overlay_Warnings
21882 Addr
: constant Node_Id
:= Address_Clause
(Ent
);
21887 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
21889 Error_Msg_Sloc
:= Sloc
(Addr
);
21891 ("??constant& may be modified via address clause#",
21902 end Note_Possible_Modification
;
21908 function Null_Status
(N
: Node_Id
) return Null_Status_Kind
is
21909 function Is_Null_Excluding_Def
(Def
: Node_Id
) return Boolean;
21910 -- Determine whether definition Def carries a null exclusion
21912 function Null_Status_Of_Entity
(Id
: Entity_Id
) return Null_Status_Kind
;
21913 -- Determine the null status of arbitrary entity Id
21915 function Null_Status_Of_Type
(Typ
: Entity_Id
) return Null_Status_Kind
;
21916 -- Determine the null status of type Typ
21918 ---------------------------
21919 -- Is_Null_Excluding_Def --
21920 ---------------------------
21922 function Is_Null_Excluding_Def
(Def
: Node_Id
) return Boolean is
21925 Nkind_In
(Def
, N_Access_Definition
,
21926 N_Access_Function_Definition
,
21927 N_Access_Procedure_Definition
,
21928 N_Access_To_Object_Definition
,
21929 N_Component_Definition
,
21930 N_Derived_Type_Definition
)
21931 and then Null_Exclusion_Present
(Def
);
21932 end Is_Null_Excluding_Def
;
21934 ---------------------------
21935 -- Null_Status_Of_Entity --
21936 ---------------------------
21938 function Null_Status_Of_Entity
21939 (Id
: Entity_Id
) return Null_Status_Kind
21941 Decl
: constant Node_Id
:= Declaration_Node
(Id
);
21945 -- The value of an imported or exported entity may be set externally
21946 -- regardless of a null exclusion. As a result, the value cannot be
21947 -- determined statically.
21949 if Is_Imported
(Id
) or else Is_Exported
(Id
) then
21952 elsif Nkind_In
(Decl
, N_Component_Declaration
,
21953 N_Discriminant_Specification
,
21954 N_Formal_Object_Declaration
,
21955 N_Object_Declaration
,
21956 N_Object_Renaming_Declaration
,
21957 N_Parameter_Specification
)
21959 -- A component declaration yields a non-null value when either
21960 -- its component definition or access definition carries a null
21963 if Nkind
(Decl
) = N_Component_Declaration
then
21964 Def
:= Component_Definition
(Decl
);
21966 if Is_Null_Excluding_Def
(Def
) then
21967 return Is_Non_Null
;
21970 Def
:= Access_Definition
(Def
);
21972 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
21973 return Is_Non_Null
;
21976 -- A formal object declaration yields a non-null value if its
21977 -- access definition carries a null exclusion. If the object is
21978 -- default initialized, then the value depends on the expression.
21980 elsif Nkind
(Decl
) = N_Formal_Object_Declaration
then
21981 Def
:= Access_Definition
(Decl
);
21983 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
21984 return Is_Non_Null
;
21987 -- A constant may yield a null or non-null value depending on its
21988 -- initialization expression.
21990 elsif Ekind
(Id
) = E_Constant
then
21991 return Null_Status
(Constant_Value
(Id
));
21993 -- The construct yields a non-null value when it has a null
21996 elsif Null_Exclusion_Present
(Decl
) then
21997 return Is_Non_Null
;
21999 -- An object renaming declaration yields a non-null value if its
22000 -- access definition carries a null exclusion. Otherwise the value
22001 -- depends on the renamed name.
22003 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
22004 Def
:= Access_Definition
(Decl
);
22006 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
22007 return Is_Non_Null
;
22010 return Null_Status
(Name
(Decl
));
22015 -- At this point the declaration of the entity does not carry a null
22016 -- exclusion and lacks an initialization expression. Check the status
22019 return Null_Status_Of_Type
(Etype
(Id
));
22020 end Null_Status_Of_Entity
;
22022 -------------------------
22023 -- Null_Status_Of_Type --
22024 -------------------------
22026 function Null_Status_Of_Type
(Typ
: Entity_Id
) return Null_Status_Kind
is
22031 -- Traverse the type chain looking for types with null exclusion
22034 while Present
(Curr
) and then Etype
(Curr
) /= Curr
loop
22035 Decl
:= Parent
(Curr
);
22037 -- Guard against itypes which do not always have declarations. A
22038 -- type yields a non-null value if it carries a null exclusion.
22040 if Present
(Decl
) then
22041 if Nkind
(Decl
) = N_Full_Type_Declaration
22042 and then Is_Null_Excluding_Def
(Type_Definition
(Decl
))
22044 return Is_Non_Null
;
22046 elsif Nkind
(Decl
) = N_Subtype_Declaration
22047 and then Null_Exclusion_Present
(Decl
)
22049 return Is_Non_Null
;
22053 Curr
:= Etype
(Curr
);
22056 -- The type chain does not contain any null excluding types
22059 end Null_Status_Of_Type
;
22061 -- Start of processing for Null_Status
22064 -- An allocator always creates a non-null value
22066 if Nkind
(N
) = N_Allocator
then
22067 return Is_Non_Null
;
22069 -- Taking the 'Access of something yields a non-null value
22071 elsif Nkind
(N
) = N_Attribute_Reference
22072 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
22073 Name_Unchecked_Access
,
22074 Name_Unrestricted_Access
)
22076 return Is_Non_Null
;
22078 -- "null" yields null
22080 elsif Nkind
(N
) = N_Null
then
22083 -- Check the status of the operand of a type conversion
22085 elsif Nkind
(N
) = N_Type_Conversion
then
22086 return Null_Status
(Expression
(N
));
22088 -- The input denotes a reference to an entity. Determine whether the
22089 -- entity or its type yields a null or non-null value.
22091 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
22092 return Null_Status_Of_Entity
(Entity
(N
));
22095 -- Otherwise it is not possible to determine the null status of the
22096 -- subexpression at compile time without resorting to simple flow
22102 --------------------------------------
22103 -- Null_To_Null_Address_Convert_OK --
22104 --------------------------------------
22106 function Null_To_Null_Address_Convert_OK
22108 Typ
: Entity_Id
:= Empty
) return Boolean
22111 if not Relaxed_RM_Semantics
then
22115 if Nkind
(N
) = N_Null
then
22116 return Present
(Typ
) and then Is_Descendant_Of_Address
(Typ
);
22118 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
, N_Op_Ne
)
22121 L
: constant Node_Id
:= Left_Opnd
(N
);
22122 R
: constant Node_Id
:= Right_Opnd
(N
);
22125 -- We check the Etype of the complementary operand since the
22126 -- N_Null node is not decorated at this stage.
22129 ((Nkind
(L
) = N_Null
22130 and then Is_Descendant_Of_Address
(Etype
(R
)))
22132 (Nkind
(R
) = N_Null
22133 and then Is_Descendant_Of_Address
(Etype
(L
))));
22138 end Null_To_Null_Address_Convert_OK
;
22140 ---------------------------------
22141 -- Number_Of_Elements_In_Array --
22142 ---------------------------------
22144 function Number_Of_Elements_In_Array
(T
: Entity_Id
) return Int
is
22152 pragma Assert
(Is_Array_Type
(T
));
22154 Indx
:= First_Index
(T
);
22155 while Present
(Indx
) loop
22156 Typ
:= Underlying_Type
(Etype
(Indx
));
22158 -- Never look at junk bounds of a generic type
22160 if Is_Generic_Type
(Typ
) then
22164 -- Check the array bounds are known at compile time and return zero
22165 -- if they are not.
22167 Low
:= Type_Low_Bound
(Typ
);
22168 High
:= Type_High_Bound
(Typ
);
22170 if not Compile_Time_Known_Value
(Low
) then
22172 elsif not Compile_Time_Known_Value
(High
) then
22176 Num
* UI_To_Int
((Expr_Value
(High
) - Expr_Value
(Low
) + 1));
22183 end Number_Of_Elements_In_Array
;
22185 -------------------------
22186 -- Object_Access_Level --
22187 -------------------------
22189 -- Returns the static accessibility level of the view denoted by Obj. Note
22190 -- that the value returned is the result of a call to Scope_Depth. Only
22191 -- scope depths associated with dynamic scopes can actually be returned.
22192 -- Since only relative levels matter for accessibility checking, the fact
22193 -- that the distance between successive levels of accessibility is not
22194 -- always one is immaterial (invariant: if level(E2) is deeper than
22195 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
22197 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
22198 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
22199 -- Determine whether N is a construct of the form
22200 -- Some_Type (Operand._tag'Address)
22201 -- This construct appears in the context of dispatching calls.
22203 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
22204 -- An explicit dereference is created when removing side effects from
22205 -- expressions for constraint checking purposes. In this case a local
22206 -- access type is created for it. The correct access level is that of
22207 -- the original source node. We detect this case by noting that the
22208 -- prefix of the dereference is created by an object declaration whose
22209 -- initial expression is a reference.
22211 -----------------------------
22212 -- Is_Interface_Conversion --
22213 -----------------------------
22215 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
22217 return Nkind
(N
) = N_Unchecked_Type_Conversion
22218 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
22219 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
22220 end Is_Interface_Conversion
;
22226 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
22227 Pref
: constant Node_Id
:= Prefix
(Obj
);
22229 if Is_Entity_Name
(Pref
)
22230 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
22231 and then Present
(Expression
(Parent
(Entity
(Pref
))))
22232 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
22234 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
22244 -- Start of processing for Object_Access_Level
22247 if Nkind
(Obj
) = N_Defining_Identifier
22248 or else Is_Entity_Name
(Obj
)
22250 if Nkind
(Obj
) = N_Defining_Identifier
then
22256 if Is_Prival
(E
) then
22257 E
:= Prival_Link
(E
);
22260 -- If E is a type then it denotes a current instance. For this case
22261 -- we add one to the normal accessibility level of the type to ensure
22262 -- that current instances are treated as always being deeper than
22263 -- than the level of any visible named access type (see 3.10.2(21)).
22265 if Is_Type
(E
) then
22266 return Type_Access_Level
(E
) + 1;
22268 elsif Present
(Renamed_Object
(E
)) then
22269 return Object_Access_Level
(Renamed_Object
(E
));
22271 -- Similarly, if E is a component of the current instance of a
22272 -- protected type, any instance of it is assumed to be at a deeper
22273 -- level than the type. For a protected object (whose type is an
22274 -- anonymous protected type) its components are at the same level
22275 -- as the type itself.
22277 elsif not Is_Overloadable
(E
)
22278 and then Ekind
(Scope
(E
)) = E_Protected_Type
22279 and then Comes_From_Source
(Scope
(E
))
22281 return Type_Access_Level
(Scope
(E
)) + 1;
22284 -- Aliased formals of functions take their access level from the
22285 -- point of call, i.e. require a dynamic check. For static check
22286 -- purposes, this is smaller than the level of the subprogram
22287 -- itself. For procedures the aliased makes no difference.
22290 and then Is_Aliased
(E
)
22291 and then Ekind
(Scope
(E
)) = E_Function
22293 return Type_Access_Level
(Etype
(E
));
22296 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
22300 elsif Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
22301 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
22302 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
22304 return Object_Access_Level
(Prefix
(Obj
));
22307 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
22309 -- If the prefix is a selected access discriminant then we make a
22310 -- recursive call on the prefix, which will in turn check the level
22311 -- of the prefix object of the selected discriminant.
22313 -- In Ada 2012, if the discriminant has implicit dereference and
22314 -- the context is a selected component, treat this as an object of
22315 -- unknown scope (see below). This is necessary in compile-only mode;
22316 -- otherwise expansion will already have transformed the prefix into
22319 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
22320 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
22322 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
22324 (not Has_Implicit_Dereference
22325 (Entity
(Selector_Name
(Prefix
(Obj
))))
22326 or else Nkind
(Parent
(Obj
)) /= N_Selected_Component
)
22328 return Object_Access_Level
(Prefix
(Obj
));
22330 -- Detect an interface conversion in the context of a dispatching
22331 -- call. Use the original form of the conversion to find the access
22332 -- level of the operand.
22334 elsif Is_Interface
(Etype
(Obj
))
22335 and then Is_Interface_Conversion
(Prefix
(Obj
))
22336 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
22338 return Object_Access_Level
(Original_Node
(Obj
));
22340 elsif not Comes_From_Source
(Obj
) then
22342 Ref
: constant Node_Id
:= Reference_To
(Obj
);
22344 if Present
(Ref
) then
22345 return Object_Access_Level
(Ref
);
22347 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
22352 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
22355 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
22356 return Object_Access_Level
(Expression
(Obj
));
22358 elsif Nkind
(Obj
) = N_Function_Call
then
22360 -- Function results are objects, so we get either the access level of
22361 -- the function or, in the case of an indirect call, the level of the
22362 -- access-to-subprogram type. (This code is used for Ada 95, but it
22363 -- looks wrong, because it seems that we should be checking the level
22364 -- of the call itself, even for Ada 95. However, using the Ada 2005
22365 -- version of the code causes regressions in several tests that are
22366 -- compiled with -gnat95. ???)
22368 if Ada_Version
< Ada_2005
then
22369 if Is_Entity_Name
(Name
(Obj
)) then
22370 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
22372 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
22375 -- For Ada 2005, the level of the result object of a function call is
22376 -- defined to be the level of the call's innermost enclosing master.
22377 -- We determine that by querying the depth of the innermost enclosing
22381 Return_Master_Scope_Depth_Of_Call
: declare
22382 function Innermost_Master_Scope_Depth
22383 (N
: Node_Id
) return Uint
;
22384 -- Returns the scope depth of the given node's innermost
22385 -- enclosing dynamic scope (effectively the accessibility
22386 -- level of the innermost enclosing master).
22388 ----------------------------------
22389 -- Innermost_Master_Scope_Depth --
22390 ----------------------------------
22392 function Innermost_Master_Scope_Depth
22393 (N
: Node_Id
) return Uint
22395 Node_Par
: Node_Id
:= Parent
(N
);
22398 -- Locate the nearest enclosing node (by traversing Parents)
22399 -- that Defining_Entity can be applied to, and return the
22400 -- depth of that entity's nearest enclosing dynamic scope.
22402 while Present
(Node_Par
) loop
22403 case Nkind
(Node_Par
) is
22404 when N_Abstract_Subprogram_Declaration
22405 | N_Block_Statement
22407 | N_Component_Declaration
22409 | N_Entry_Declaration
22410 | N_Exception_Declaration
22411 | N_Formal_Object_Declaration
22412 | N_Formal_Package_Declaration
22413 | N_Formal_Subprogram_Declaration
22414 | N_Formal_Type_Declaration
22415 | N_Full_Type_Declaration
22416 | N_Function_Specification
22417 | N_Generic_Declaration
22418 | N_Generic_Instantiation
22419 | N_Implicit_Label_Declaration
22420 | N_Incomplete_Type_Declaration
22421 | N_Loop_Parameter_Specification
22422 | N_Number_Declaration
22423 | N_Object_Declaration
22424 | N_Package_Declaration
22425 | N_Package_Specification
22426 | N_Parameter_Specification
22427 | N_Private_Extension_Declaration
22428 | N_Private_Type_Declaration
22429 | N_Procedure_Specification
22431 | N_Protected_Type_Declaration
22432 | N_Renaming_Declaration
22433 | N_Single_Protected_Declaration
22434 | N_Single_Task_Declaration
22435 | N_Subprogram_Declaration
22436 | N_Subtype_Declaration
22438 | N_Task_Type_Declaration
22441 (Nearest_Dynamic_Scope
22442 (Defining_Entity
(Node_Par
)));
22444 -- For a return statement within a function, return
22445 -- the depth of the function itself. This is not just
22446 -- a small optimization, but matters when analyzing
22447 -- the expression in an expression function before
22448 -- the body is created.
22450 when N_Simple_Return_Statement
=>
22451 if Ekind
(Current_Scope
) = E_Function
then
22452 return Scope_Depth
(Current_Scope
);
22459 Node_Par
:= Parent
(Node_Par
);
22462 pragma Assert
(False);
22464 -- Should never reach the following return
22466 return Scope_Depth
(Current_Scope
) + 1;
22467 end Innermost_Master_Scope_Depth
;
22469 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22472 return Innermost_Master_Scope_Depth
(Obj
);
22473 end Return_Master_Scope_Depth_Of_Call
;
22476 -- For convenience we handle qualified expressions, even though they
22477 -- aren't technically object names.
22479 elsif Nkind
(Obj
) = N_Qualified_Expression
then
22480 return Object_Access_Level
(Expression
(Obj
));
22482 -- Ditto for aggregates. They have the level of the temporary that
22483 -- will hold their value.
22485 elsif Nkind
(Obj
) = N_Aggregate
then
22486 return Object_Access_Level
(Current_Scope
);
22488 -- Otherwise return the scope level of Standard. (If there are cases
22489 -- that fall through to this point they will be treated as having
22490 -- global accessibility for now. ???)
22493 return Scope_Depth
(Standard_Standard
);
22495 end Object_Access_Level
;
22497 ----------------------------------
22498 -- Old_Requires_Transient_Scope --
22499 ----------------------------------
22501 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
22502 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
22505 -- This is a private type which is not completed yet. This can only
22506 -- happen in a default expression (of a formal parameter or of a
22507 -- record component). Do not expand transient scope in this case.
22512 -- Do not expand transient scope for non-existent procedure return
22514 elsif Typ
= Standard_Void_Type
then
22517 -- Elementary types do not require a transient scope
22519 elsif Is_Elementary_Type
(Typ
) then
22522 -- Generally, indefinite subtypes require a transient scope, since the
22523 -- back end cannot generate temporaries, since this is not a valid type
22524 -- for declaring an object. It might be possible to relax this in the
22525 -- future, e.g. by declaring the maximum possible space for the type.
22527 elsif not Is_Definite_Subtype
(Typ
) then
22530 -- Functions returning tagged types may dispatch on result so their
22531 -- returned value is allocated on the secondary stack. Controlled
22532 -- type temporaries need finalization.
22534 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
22539 elsif Is_Record_Type
(Typ
) then
22544 Comp
:= First_Entity
(Typ
);
22545 while Present
(Comp
) loop
22546 if Ekind
(Comp
) = E_Component
then
22548 -- ???It's not clear we need a full recursive call to
22549 -- Old_Requires_Transient_Scope here. Note that the
22550 -- following can't happen.
22552 pragma Assert
(Is_Definite_Subtype
(Etype
(Comp
)));
22553 pragma Assert
(not Has_Controlled_Component
(Etype
(Comp
)));
22555 if Old_Requires_Transient_Scope
(Etype
(Comp
)) then
22560 Next_Entity
(Comp
);
22566 -- String literal types never require transient scope
22568 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
22571 -- Array type. Note that we already know that this is a constrained
22572 -- array, since unconstrained arrays will fail the indefinite test.
22574 elsif Is_Array_Type
(Typ
) then
22576 -- If component type requires a transient scope, the array does too
22578 if Old_Requires_Transient_Scope
(Component_Type
(Typ
)) then
22581 -- Otherwise, we only need a transient scope if the size depends on
22582 -- the value of one or more discriminants.
22585 return Size_Depends_On_Discriminant
(Typ
);
22588 -- All other cases do not require a transient scope
22591 pragma Assert
(Is_Protected_Type
(Typ
) or else Is_Task_Type
(Typ
));
22594 end Old_Requires_Transient_Scope
;
22596 ---------------------------------
22597 -- Original_Aspect_Pragma_Name --
22598 ---------------------------------
22600 function Original_Aspect_Pragma_Name
(N
: Node_Id
) return Name_Id
is
22602 Item_Nam
: Name_Id
;
22605 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
22609 -- The pragma was generated to emulate an aspect, use the original
22610 -- aspect specification.
22612 if Nkind
(Item
) = N_Pragma
and then From_Aspect_Specification
(Item
) then
22613 Item
:= Corresponding_Aspect
(Item
);
22616 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
22617 -- Post and Post_Class rewrite their pragma identifier to preserve the
22619 -- ??? this is kludgey
22621 if Nkind
(Item
) = N_Pragma
then
22622 Item_Nam
:= Chars
(Original_Node
(Pragma_Identifier
(Item
)));
22625 pragma Assert
(Nkind
(Item
) = N_Aspect_Specification
);
22626 Item_Nam
:= Chars
(Identifier
(Item
));
22629 -- Deal with 'Class by converting the name to its _XXX form
22631 if Class_Present
(Item
) then
22632 if Item_Nam
= Name_Invariant
then
22633 Item_Nam
:= Name_uInvariant
;
22635 elsif Item_Nam
= Name_Post
then
22636 Item_Nam
:= Name_uPost
;
22638 elsif Item_Nam
= Name_Pre
then
22639 Item_Nam
:= Name_uPre
;
22641 elsif Nam_In
(Item_Nam
, Name_Type_Invariant
,
22642 Name_Type_Invariant_Class
)
22644 Item_Nam
:= Name_uType_Invariant
;
22646 -- Nothing to do for other cases (e.g. a Check that derived from
22647 -- Pre_Class and has the flag set). Also we do nothing if the name
22648 -- is already in special _xxx form.
22654 end Original_Aspect_Pragma_Name
;
22656 --------------------------------------
22657 -- Original_Corresponding_Operation --
22658 --------------------------------------
22660 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
22662 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
22665 -- If S is an inherited primitive S2 the original corresponding
22666 -- operation of S is the original corresponding operation of S2
22668 if Present
(Alias
(S
))
22669 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
22671 return Original_Corresponding_Operation
(Alias
(S
));
22673 -- If S overrides an inherited subprogram S2 the original corresponding
22674 -- operation of S is the original corresponding operation of S2
22676 elsif Present
(Overridden_Operation
(S
)) then
22677 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
22679 -- otherwise it is S itself
22684 end Original_Corresponding_Operation
;
22686 -------------------
22687 -- Output_Entity --
22688 -------------------
22690 procedure Output_Entity
(Id
: Entity_Id
) is
22694 Scop
:= Scope
(Id
);
22696 -- The entity may lack a scope when it is in the process of being
22697 -- analyzed. Use the current scope as an approximation.
22700 Scop
:= Current_Scope
;
22703 Output_Name
(Chars
(Id
), Scop
);
22710 procedure Output_Name
(Nam
: Name_Id
; Scop
: Entity_Id
:= Current_Scope
) is
22714 (Get_Qualified_Name
22721 ----------------------
22722 -- Policy_In_Effect --
22723 ----------------------
22725 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
22726 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
22727 -- Determine the mode of a policy in a N_Pragma list
22729 --------------------
22730 -- Policy_In_List --
22731 --------------------
22733 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
22740 while Present
(Prag
) loop
22741 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
22742 Arg2
:= Next
(Arg1
);
22744 Arg1
:= Get_Pragma_Arg
(Arg1
);
22745 Arg2
:= Get_Pragma_Arg
(Arg2
);
22747 -- The current Check_Policy pragma matches the requested policy or
22748 -- appears in the single argument form (Assertion, policy_id).
22750 if Nam_In
(Chars
(Arg1
), Name_Assertion
, Policy
) then
22751 return Chars
(Arg2
);
22754 Prag
:= Next_Pragma
(Prag
);
22758 end Policy_In_List
;
22764 -- Start of processing for Policy_In_Effect
22767 if not Is_Valid_Assertion_Kind
(Policy
) then
22768 raise Program_Error
;
22771 -- Inspect all policy pragmas that appear within scopes (if any)
22773 Kind
:= Policy_In_List
(Check_Policy_List
);
22775 -- Inspect all configuration policy pragmas (if any)
22777 if Kind
= No_Name
then
22778 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
22781 -- The context lacks policy pragmas, determine the mode based on whether
22782 -- assertions are enabled at the configuration level. This ensures that
22783 -- the policy is preserved when analyzing generics.
22785 if Kind
= No_Name
then
22786 if Assertions_Enabled_Config
then
22787 Kind
:= Name_Check
;
22789 Kind
:= Name_Ignore
;
22793 -- In CodePeer mode and GNATprove mode, we need to consider all
22794 -- assertions, unless they are disabled. Force Name_Check on
22795 -- ignored assertions.
22797 if Nam_In
(Kind
, Name_Ignore
, Name_Off
)
22798 and then (CodePeer_Mode
or GNATprove_Mode
)
22800 Kind
:= Name_Check
;
22804 end Policy_In_Effect
;
22806 ----------------------------------
22807 -- Predicate_Tests_On_Arguments --
22808 ----------------------------------
22810 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
22812 -- Always test predicates on indirect call
22814 if Ekind
(Subp
) = E_Subprogram_Type
then
22817 -- Do not test predicates on call to generated default Finalize, since
22818 -- we are not interested in whether something we are finalizing (and
22819 -- typically destroying) satisfies its predicates.
22821 elsif Chars
(Subp
) = Name_Finalize
22822 and then not Comes_From_Source
(Subp
)
22826 -- Do not test predicates on any internally generated routines
22828 elsif Is_Internal_Name
(Chars
(Subp
)) then
22831 -- Do not test predicates on call to Init_Proc, since if needed the
22832 -- predicate test will occur at some other point.
22834 elsif Is_Init_Proc
(Subp
) then
22837 -- Do not test predicates on call to predicate function, since this
22838 -- would cause infinite recursion.
22840 elsif Ekind
(Subp
) = E_Function
22841 and then (Is_Predicate_Function
(Subp
)
22843 Is_Predicate_Function_M
(Subp
))
22847 -- For now, no other exceptions
22852 end Predicate_Tests_On_Arguments
;
22854 -----------------------
22855 -- Private_Component --
22856 -----------------------
22858 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
22859 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
22861 function Trace_Components
22863 Check
: Boolean) return Entity_Id
;
22864 -- Recursive function that does the work, and checks against circular
22865 -- definition for each subcomponent type.
22867 ----------------------
22868 -- Trace_Components --
22869 ----------------------
22871 function Trace_Components
22873 Check
: Boolean) return Entity_Id
22875 Btype
: constant Entity_Id
:= Base_Type
(T
);
22876 Component
: Entity_Id
;
22878 Candidate
: Entity_Id
:= Empty
;
22881 if Check
and then Btype
= Ancestor
then
22882 Error_Msg_N
("circular type definition", Type_Id
);
22886 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
22887 if Present
(Full_View
(Btype
))
22888 and then Is_Record_Type
(Full_View
(Btype
))
22889 and then not Is_Frozen
(Btype
)
22891 -- To indicate that the ancestor depends on a private type, the
22892 -- current Btype is sufficient. However, to check for circular
22893 -- definition we must recurse on the full view.
22895 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
22897 if Candidate
= Any_Type
then
22907 elsif Is_Array_Type
(Btype
) then
22908 return Trace_Components
(Component_Type
(Btype
), True);
22910 elsif Is_Record_Type
(Btype
) then
22911 Component
:= First_Entity
(Btype
);
22912 while Present
(Component
)
22913 and then Comes_From_Source
(Component
)
22915 -- Skip anonymous types generated by constrained components
22917 if not Is_Type
(Component
) then
22918 P
:= Trace_Components
(Etype
(Component
), True);
22920 if Present
(P
) then
22921 if P
= Any_Type
then
22929 Next_Entity
(Component
);
22937 end Trace_Components
;
22939 -- Start of processing for Private_Component
22942 return Trace_Components
(Type_Id
, False);
22943 end Private_Component
;
22945 ---------------------------
22946 -- Primitive_Names_Match --
22947 ---------------------------
22949 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
22950 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
22951 -- Given an internal name, returns the corresponding non-internal name
22953 ------------------------
22954 -- Non_Internal_Name --
22955 ------------------------
22957 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
22959 Get_Name_String
(Chars
(E
));
22960 Name_Len
:= Name_Len
- 1;
22962 end Non_Internal_Name
;
22964 -- Start of processing for Primitive_Names_Match
22967 pragma Assert
(Present
(E1
) and then Present
(E2
));
22969 return Chars
(E1
) = Chars
(E2
)
22971 (not Is_Internal_Name
(Chars
(E1
))
22972 and then Is_Internal_Name
(Chars
(E2
))
22973 and then Non_Internal_Name
(E2
) = Chars
(E1
))
22975 (not Is_Internal_Name
(Chars
(E2
))
22976 and then Is_Internal_Name
(Chars
(E1
))
22977 and then Non_Internal_Name
(E1
) = Chars
(E2
))
22979 (Is_Predefined_Dispatching_Operation
(E1
)
22980 and then Is_Predefined_Dispatching_Operation
(E2
)
22981 and then Same_TSS
(E1
, E2
))
22983 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
22984 end Primitive_Names_Match
;
22986 -----------------------
22987 -- Process_End_Label --
22988 -----------------------
22990 procedure Process_End_Label
22999 Label_Ref
: Boolean;
23000 -- Set True if reference to end label itself is required
23003 -- Gets set to the operator symbol or identifier that references the
23004 -- entity Ent. For the child unit case, this is the identifier from the
23005 -- designator. For other cases, this is simply Endl.
23007 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
23008 -- N is an identifier node that appears as a parent unit reference in
23009 -- the case where Ent is a child unit. This procedure generates an
23010 -- appropriate cross-reference entry. E is the corresponding entity.
23012 -------------------------
23013 -- Generate_Parent_Ref --
23014 -------------------------
23016 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
23018 -- If names do not match, something weird, skip reference
23020 if Chars
(E
) = Chars
(N
) then
23022 -- Generate the reference. We do NOT consider this as a reference
23023 -- for unreferenced symbol purposes.
23025 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
23027 if Style_Check
then
23028 Style
.Check_Identifier
(N
, E
);
23031 end Generate_Parent_Ref
;
23033 -- Start of processing for Process_End_Label
23036 -- If no node, ignore. This happens in some error situations, and
23037 -- also for some internally generated structures where no end label
23038 -- references are required in any case.
23044 -- Nothing to do if no End_Label, happens for internally generated
23045 -- constructs where we don't want an end label reference anyway. Also
23046 -- nothing to do if Endl is a string literal, which means there was
23047 -- some prior error (bad operator symbol)
23049 Endl
:= End_Label
(N
);
23051 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
23055 -- Reference node is not in extended main source unit
23057 if not In_Extended_Main_Source_Unit
(N
) then
23059 -- Generally we do not collect references except for the extended
23060 -- main source unit. The one exception is the 'e' entry for a
23061 -- package spec, where it is useful for a client to have the
23062 -- ending information to define scopes.
23068 Label_Ref
:= False;
23070 -- For this case, we can ignore any parent references, but we
23071 -- need the package name itself for the 'e' entry.
23073 if Nkind
(Endl
) = N_Designator
then
23074 Endl
:= Identifier
(Endl
);
23078 -- Reference is in extended main source unit
23083 -- For designator, generate references for the parent entries
23085 if Nkind
(Endl
) = N_Designator
then
23087 -- Generate references for the prefix if the END line comes from
23088 -- source (otherwise we do not need these references) We climb the
23089 -- scope stack to find the expected entities.
23091 if Comes_From_Source
(Endl
) then
23092 Nam
:= Name
(Endl
);
23093 Scop
:= Current_Scope
;
23094 while Nkind
(Nam
) = N_Selected_Component
loop
23095 Scop
:= Scope
(Scop
);
23096 exit when No
(Scop
);
23097 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
23098 Nam
:= Prefix
(Nam
);
23101 if Present
(Scop
) then
23102 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
23106 Endl
:= Identifier
(Endl
);
23110 -- If the end label is not for the given entity, then either we have
23111 -- some previous error, or this is a generic instantiation for which
23112 -- we do not need to make a cross-reference in this case anyway. In
23113 -- either case we simply ignore the call.
23115 if Chars
(Ent
) /= Chars
(Endl
) then
23119 -- If label was really there, then generate a normal reference and then
23120 -- adjust the location in the end label to point past the name (which
23121 -- should almost always be the semicolon).
23123 Loc
:= Sloc
(Endl
);
23125 if Comes_From_Source
(Endl
) then
23127 -- If a label reference is required, then do the style check and
23128 -- generate an l-type cross-reference entry for the label
23131 if Style_Check
then
23132 Style
.Check_Identifier
(Endl
, Ent
);
23135 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
23138 -- Set the location to point past the label (normally this will
23139 -- mean the semicolon immediately following the label). This is
23140 -- done for the sake of the 'e' or 't' entry generated below.
23142 Get_Decoded_Name_String
(Chars
(Endl
));
23143 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
23146 -- In SPARK mode, no missing label is allowed for packages and
23147 -- subprogram bodies. Detect those cases by testing whether
23148 -- Process_End_Label was called for a body (Typ = 't') or a package.
23150 if Restriction_Check_Required
(SPARK_05
)
23151 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
23153 Error_Msg_Node_1
:= Endl
;
23154 Check_SPARK_05_Restriction
23155 ("`END &` required", Endl
, Force
=> True);
23159 -- Now generate the e/t reference
23161 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
23163 -- Restore Sloc, in case modified above, since we have an identifier
23164 -- and the normal Sloc should be left set in the tree.
23166 Set_Sloc
(Endl
, Loc
);
23167 end Process_End_Label
;
23169 --------------------------------
23170 -- Propagate_Concurrent_Flags --
23171 --------------------------------
23173 procedure Propagate_Concurrent_Flags
23175 Comp_Typ
: Entity_Id
)
23178 if Has_Task
(Comp_Typ
) then
23179 Set_Has_Task
(Typ
);
23182 if Has_Protected
(Comp_Typ
) then
23183 Set_Has_Protected
(Typ
);
23186 if Has_Timing_Event
(Comp_Typ
) then
23187 Set_Has_Timing_Event
(Typ
);
23189 end Propagate_Concurrent_Flags
;
23191 ------------------------------
23192 -- Propagate_DIC_Attributes --
23193 ------------------------------
23195 procedure Propagate_DIC_Attributes
23197 From_Typ
: Entity_Id
)
23199 DIC_Proc
: Entity_Id
;
23202 if Present
(Typ
) and then Present
(From_Typ
) then
23203 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
23205 -- Nothing to do if both the source and the destination denote the
23208 if From_Typ
= Typ
then
23212 DIC_Proc
:= DIC_Procedure
(From_Typ
);
23214 -- The setting of the attributes is intentionally conservative. This
23215 -- prevents accidental clobbering of enabled attributes.
23217 if Has_Inherited_DIC
(From_Typ
)
23218 and then not Has_Inherited_DIC
(Typ
)
23220 Set_Has_Inherited_DIC
(Typ
);
23223 if Has_Own_DIC
(From_Typ
) and then not Has_Own_DIC
(Typ
) then
23224 Set_Has_Own_DIC
(Typ
);
23227 if Present
(DIC_Proc
) and then No
(DIC_Procedure
(Typ
)) then
23228 Set_DIC_Procedure
(Typ
, DIC_Proc
);
23231 end Propagate_DIC_Attributes
;
23233 ------------------------------------
23234 -- Propagate_Invariant_Attributes --
23235 ------------------------------------
23237 procedure Propagate_Invariant_Attributes
23239 From_Typ
: Entity_Id
)
23241 Full_IP
: Entity_Id
;
23242 Part_IP
: Entity_Id
;
23245 if Present
(Typ
) and then Present
(From_Typ
) then
23246 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
23248 -- Nothing to do if both the source and the destination denote the
23251 if From_Typ
= Typ
then
23255 Full_IP
:= Invariant_Procedure
(From_Typ
);
23256 Part_IP
:= Partial_Invariant_Procedure
(From_Typ
);
23258 -- The setting of the attributes is intentionally conservative. This
23259 -- prevents accidental clobbering of enabled attributes.
23261 if Has_Inheritable_Invariants
(From_Typ
)
23262 and then not Has_Inheritable_Invariants
(Typ
)
23264 Set_Has_Inheritable_Invariants
(Typ
);
23267 if Has_Inherited_Invariants
(From_Typ
)
23268 and then not Has_Inherited_Invariants
(Typ
)
23270 Set_Has_Inherited_Invariants
(Typ
);
23273 if Has_Own_Invariants
(From_Typ
)
23274 and then not Has_Own_Invariants
(Typ
)
23276 Set_Has_Own_Invariants
(Typ
);
23279 if Present
(Full_IP
) and then No
(Invariant_Procedure
(Typ
)) then
23280 Set_Invariant_Procedure
(Typ
, Full_IP
);
23283 if Present
(Part_IP
) and then No
(Partial_Invariant_Procedure
(Typ
))
23285 Set_Partial_Invariant_Procedure
(Typ
, Part_IP
);
23288 end Propagate_Invariant_Attributes
;
23290 ---------------------------------------
23291 -- Record_Possible_Part_Of_Reference --
23292 ---------------------------------------
23294 procedure Record_Possible_Part_Of_Reference
23295 (Var_Id
: Entity_Id
;
23298 Encap
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
23302 -- The variable is a constituent of a single protected/task type. Such
23303 -- a variable acts as a component of the type and must appear within a
23304 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
23305 -- verify its legality now.
23307 if Present
(Encap
) and then Is_Single_Concurrent_Object
(Encap
) then
23308 Check_Part_Of_Reference
(Var_Id
, Ref
);
23310 -- The variable is subject to pragma Part_Of and may eventually become a
23311 -- constituent of a single protected/task type. Record the reference to
23312 -- verify its placement when the contract of the variable is analyzed.
23314 elsif Present
(Get_Pragma
(Var_Id
, Pragma_Part_Of
)) then
23315 Refs
:= Part_Of_References
(Var_Id
);
23318 Refs
:= New_Elmt_List
;
23319 Set_Part_Of_References
(Var_Id
, Refs
);
23322 Append_Elmt
(Ref
, Refs
);
23324 end Record_Possible_Part_Of_Reference
;
23330 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
23331 Seen
: Boolean := False;
23333 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
23334 -- Determine whether node N denotes a reference to Id. If this is the
23335 -- case, set global flag Seen to True and stop the traversal.
23341 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
23343 if Is_Entity_Name
(N
)
23344 and then Present
(Entity
(N
))
23345 and then Entity
(N
) = Id
23354 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
23356 -- Start of processing for Referenced
23359 Inspect_Expression
(Expr
);
23363 ------------------------------------
23364 -- References_Generic_Formal_Type --
23365 ------------------------------------
23367 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
23369 function Process
(N
: Node_Id
) return Traverse_Result
;
23370 -- Process one node in search for generic formal type
23376 function Process
(N
: Node_Id
) return Traverse_Result
is
23378 if Nkind
(N
) in N_Has_Entity
then
23380 E
: constant Entity_Id
:= Entity
(N
);
23382 if Present
(E
) then
23383 if Is_Generic_Type
(E
) then
23385 elsif Present
(Etype
(E
))
23386 and then Is_Generic_Type
(Etype
(E
))
23397 function Traverse
is new Traverse_Func
(Process
);
23398 -- Traverse tree to look for generic type
23401 if Inside_A_Generic
then
23402 return Traverse
(N
) = Abandon
;
23406 end References_Generic_Formal_Type
;
23408 -------------------------------
23409 -- Remove_Entity_And_Homonym --
23410 -------------------------------
23412 procedure Remove_Entity_And_Homonym
(Id
: Entity_Id
) is
23414 Remove_Entity
(Id
);
23415 Remove_Homonym
(Id
);
23416 end Remove_Entity_And_Homonym
;
23418 --------------------
23419 -- Remove_Homonym --
23420 --------------------
23422 procedure Remove_Homonym
(Id
: Entity_Id
) is
23424 Prev
: Entity_Id
:= Empty
;
23427 if Id
= Current_Entity
(Id
) then
23428 if Present
(Homonym
(Id
)) then
23429 Set_Current_Entity
(Homonym
(Id
));
23431 Set_Name_Entity_Id
(Chars
(Id
), Empty
);
23435 Hom
:= Current_Entity
(Id
);
23436 while Present
(Hom
) and then Hom
/= Id
loop
23438 Hom
:= Homonym
(Hom
);
23441 -- If Id is not on the homonym chain, nothing to do
23443 if Present
(Hom
) then
23444 Set_Homonym
(Prev
, Homonym
(Id
));
23447 end Remove_Homonym
;
23449 ------------------------------
23450 -- Remove_Overloaded_Entity --
23451 ------------------------------
23453 procedure Remove_Overloaded_Entity
(Id
: Entity_Id
) is
23454 procedure Remove_Primitive_Of
(Typ
: Entity_Id
);
23455 -- Remove primitive subprogram Id from the list of primitives that
23456 -- belong to type Typ.
23458 -------------------------
23459 -- Remove_Primitive_Of --
23460 -------------------------
23462 procedure Remove_Primitive_Of
(Typ
: Entity_Id
) is
23466 if Is_Tagged_Type
(Typ
) then
23467 Prims
:= Direct_Primitive_Operations
(Typ
);
23469 if Present
(Prims
) then
23470 Remove
(Prims
, Id
);
23473 end Remove_Primitive_Of
;
23477 Formal
: Entity_Id
;
23479 -- Start of processing for Remove_Overloaded_Entity
23482 Remove_Entity_And_Homonym
(Id
);
23484 -- The entity denotes a primitive subprogram. Remove it from the list of
23485 -- primitives of the associated controlling type.
23487 if Ekind_In
(Id
, E_Function
, E_Procedure
) and then Is_Primitive
(Id
) then
23488 Formal
:= First_Formal
(Id
);
23489 while Present
(Formal
) loop
23490 if Is_Controlling_Formal
(Formal
) then
23491 Remove_Primitive_Of
(Etype
(Formal
));
23495 Next_Formal
(Formal
);
23498 if Ekind
(Id
) = E_Function
and then Has_Controlling_Result
(Id
) then
23499 Remove_Primitive_Of
(Etype
(Id
));
23502 end Remove_Overloaded_Entity
;
23504 ---------------------
23505 -- Rep_To_Pos_Flag --
23506 ---------------------
23508 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
23510 return New_Occurrence_Of
23511 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
23512 end Rep_To_Pos_Flag
;
23514 --------------------
23515 -- Require_Entity --
23516 --------------------
23518 procedure Require_Entity
(N
: Node_Id
) is
23520 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
23521 if Total_Errors_Detected
/= 0 then
23522 Set_Entity
(N
, Any_Id
);
23524 raise Program_Error
;
23527 end Require_Entity
;
23529 ------------------------------
23530 -- Requires_Transient_Scope --
23531 ------------------------------
23533 -- A transient scope is required when variable-sized temporaries are
23534 -- allocated on the secondary stack, or when finalization actions must be
23535 -- generated before the next instruction.
23537 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
23538 Old_Result
: constant Boolean := Old_Requires_Transient_Scope
(Id
);
23541 if Debug_Flag_QQ
then
23546 New_Result
: constant Boolean := New_Requires_Transient_Scope
(Id
);
23549 -- Assert that we're not putting things on the secondary stack if we
23550 -- didn't before; we are trying to AVOID secondary stack when
23553 if not Old_Result
then
23554 pragma Assert
(not New_Result
);
23558 if New_Result
/= Old_Result
then
23559 Results_Differ
(Id
, Old_Result
, New_Result
);
23564 end Requires_Transient_Scope
;
23566 --------------------
23567 -- Results_Differ --
23568 --------------------
23570 procedure Results_Differ
23576 if False then -- False to disable; True for debugging
23577 Treepr
.Print_Tree_Node
(Id
);
23579 if Old_Val
= New_Val
then
23580 raise Program_Error
;
23583 end Results_Differ
;
23585 --------------------------
23586 -- Reset_Analyzed_Flags --
23587 --------------------------
23589 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
23590 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
23591 -- Function used to reset Analyzed flags in tree. Note that we do
23592 -- not reset Analyzed flags in entities, since there is no need to
23593 -- reanalyze entities, and indeed, it is wrong to do so, since it
23594 -- can result in generating auxiliary stuff more than once.
23596 --------------------
23597 -- Clear_Analyzed --
23598 --------------------
23600 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
23602 if Nkind
(N
) not in N_Entity
then
23603 Set_Analyzed
(N
, False);
23607 end Clear_Analyzed
;
23609 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
23611 -- Start of processing for Reset_Analyzed_Flags
23614 Reset_Analyzed
(N
);
23615 end Reset_Analyzed_Flags
;
23617 ------------------------
23618 -- Restore_SPARK_Mode --
23619 ------------------------
23621 procedure Restore_SPARK_Mode
23622 (Mode
: SPARK_Mode_Type
;
23626 SPARK_Mode
:= Mode
;
23627 SPARK_Mode_Pragma
:= Prag
;
23628 end Restore_SPARK_Mode
;
23630 --------------------------------
23631 -- Returns_Unconstrained_Type --
23632 --------------------------------
23634 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
23636 return Ekind
(Subp
) = E_Function
23637 and then not Is_Scalar_Type
(Etype
(Subp
))
23638 and then not Is_Access_Type
(Etype
(Subp
))
23639 and then not Is_Constrained
(Etype
(Subp
));
23640 end Returns_Unconstrained_Type
;
23642 ----------------------------
23643 -- Root_Type_Of_Full_View --
23644 ----------------------------
23646 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
23647 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
23650 -- The root type of the full view may itself be a private type. Keep
23651 -- looking for the ultimate derivation parent.
23653 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
23654 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
23658 end Root_Type_Of_Full_View
;
23660 ---------------------------
23661 -- Safe_To_Capture_Value --
23662 ---------------------------
23664 function Safe_To_Capture_Value
23667 Cond
: Boolean := False) return Boolean
23670 -- The only entities for which we track constant values are variables
23671 -- which are not renamings, constants, out parameters, and in out
23672 -- parameters, so check if we have this case.
23674 -- Note: it may seem odd to track constant values for constants, but in
23675 -- fact this routine is used for other purposes than simply capturing
23676 -- the value. In particular, the setting of Known[_Non]_Null.
23678 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
23680 Ekind_In
(Ent
, E_Constant
, E_Out_Parameter
, E_In_Out_Parameter
)
23684 -- For conditionals, we also allow loop parameters and all formals,
23685 -- including in parameters.
23687 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
23690 -- For all other cases, not just unsafe, but impossible to capture
23691 -- Current_Value, since the above are the only entities which have
23692 -- Current_Value fields.
23698 -- Skip if volatile or aliased, since funny things might be going on in
23699 -- these cases which we cannot necessarily track. Also skip any variable
23700 -- for which an address clause is given, or whose address is taken. Also
23701 -- never capture value of library level variables (an attempt to do so
23702 -- can occur in the case of package elaboration code).
23704 if Treat_As_Volatile
(Ent
)
23705 or else Is_Aliased
(Ent
)
23706 or else Present
(Address_Clause
(Ent
))
23707 or else Address_Taken
(Ent
)
23708 or else (Is_Library_Level_Entity
(Ent
)
23709 and then Ekind
(Ent
) = E_Variable
)
23714 -- OK, all above conditions are met. We also require that the scope of
23715 -- the reference be the same as the scope of the entity, not counting
23716 -- packages and blocks and loops.
23719 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
23720 R_Scope
: Entity_Id
;
23723 R_Scope
:= Current_Scope
;
23724 while R_Scope
/= Standard_Standard
loop
23725 exit when R_Scope
= E_Scope
;
23727 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
23730 R_Scope
:= Scope
(R_Scope
);
23735 -- We also require that the reference does not appear in a context
23736 -- where it is not sure to be executed (i.e. a conditional context
23737 -- or an exception handler). We skip this if Cond is True, since the
23738 -- capturing of values from conditional tests handles this ok.
23751 -- Seems dubious that case expressions are not handled here ???
23754 while Present
(P
) loop
23755 if Nkind
(P
) = N_If_Statement
23756 or else Nkind
(P
) = N_Case_Statement
23757 or else (Nkind
(P
) in N_Short_Circuit
23758 and then Desc
= Right_Opnd
(P
))
23759 or else (Nkind
(P
) = N_If_Expression
23760 and then Desc
/= First
(Expressions
(P
)))
23761 or else Nkind
(P
) = N_Exception_Handler
23762 or else Nkind
(P
) = N_Selective_Accept
23763 or else Nkind
(P
) = N_Conditional_Entry_Call
23764 or else Nkind
(P
) = N_Timed_Entry_Call
23765 or else Nkind
(P
) = N_Asynchronous_Select
23773 -- A special Ada 2012 case: the original node may be part
23774 -- of the else_actions of a conditional expression, in which
23775 -- case it might not have been expanded yet, and appears in
23776 -- a non-syntactic list of actions. In that case it is clearly
23777 -- not safe to save a value.
23780 and then Is_List_Member
(Desc
)
23781 and then No
(Parent
(List_Containing
(Desc
)))
23789 -- OK, looks safe to set value
23792 end Safe_To_Capture_Value
;
23798 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
23799 K1
: constant Node_Kind
:= Nkind
(N1
);
23800 K2
: constant Node_Kind
:= Nkind
(N2
);
23803 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
23804 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
23806 return Chars
(N1
) = Chars
(N2
);
23808 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
23809 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
23811 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
23812 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
23823 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
23824 N1
: constant Node_Id
:= Original_Node
(Node1
);
23825 N2
: constant Node_Id
:= Original_Node
(Node2
);
23826 -- We do the tests on original nodes, since we are most interested
23827 -- in the original source, not any expansion that got in the way.
23829 K1
: constant Node_Kind
:= Nkind
(N1
);
23830 K2
: constant Node_Kind
:= Nkind
(N2
);
23833 -- First case, both are entities with same entity
23835 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
23837 EN1
: constant Entity_Id
:= Entity
(N1
);
23838 EN2
: constant Entity_Id
:= Entity
(N2
);
23840 if Present
(EN1
) and then Present
(EN2
)
23841 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
23842 or else Is_Formal
(EN1
))
23850 -- Second case, selected component with same selector, same record
23852 if K1
= N_Selected_Component
23853 and then K2
= N_Selected_Component
23854 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
23856 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
23858 -- Third case, indexed component with same subscripts, same array
23860 elsif K1
= N_Indexed_Component
23861 and then K2
= N_Indexed_Component
23862 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
23867 E1
:= First
(Expressions
(N1
));
23868 E2
:= First
(Expressions
(N2
));
23869 while Present
(E1
) loop
23870 if not Same_Value
(E1
, E2
) then
23881 -- Fourth case, slice of same array with same bounds
23884 and then K2
= N_Slice
23885 and then Nkind
(Discrete_Range
(N1
)) = N_Range
23886 and then Nkind
(Discrete_Range
(N2
)) = N_Range
23887 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
23888 Low_Bound
(Discrete_Range
(N2
)))
23889 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
23890 High_Bound
(Discrete_Range
(N2
)))
23892 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
23894 -- All other cases, not clearly the same object
23905 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
23910 elsif not Is_Constrained
(T1
)
23911 and then not Is_Constrained
(T2
)
23912 and then Base_Type
(T1
) = Base_Type
(T2
)
23916 -- For now don't bother with case of identical constraints, to be
23917 -- fiddled with later on perhaps (this is only used for optimization
23918 -- purposes, so it is not critical to do a best possible job)
23929 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
23931 if Compile_Time_Known_Value
(Node1
)
23932 and then Compile_Time_Known_Value
(Node2
)
23934 -- Handle properly compile-time expressions that are not
23937 if Is_String_Type
(Etype
(Node1
)) then
23938 return Expr_Value_S
(Node1
) = Expr_Value_S
(Node2
);
23941 return Expr_Value
(Node1
) = Expr_Value
(Node2
);
23944 elsif Same_Object
(Node1
, Node2
) then
23951 --------------------
23952 -- Set_SPARK_Mode --
23953 --------------------
23955 procedure Set_SPARK_Mode
(Context
: Entity_Id
) is
23957 -- Do not consider illegal or partially decorated constructs
23959 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
23962 elsif Present
(SPARK_Pragma
(Context
)) then
23964 (Mode
=> Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Context
)),
23965 Prag
=> SPARK_Pragma
(Context
));
23967 end Set_SPARK_Mode
;
23969 -------------------------
23970 -- Scalar_Part_Present --
23971 -------------------------
23973 function Scalar_Part_Present
(Typ
: Entity_Id
) return Boolean is
23974 Val_Typ
: constant Entity_Id
:= Validated_View
(Typ
);
23978 if Is_Scalar_Type
(Val_Typ
) then
23981 elsif Is_Array_Type
(Val_Typ
) then
23982 return Scalar_Part_Present
(Component_Type
(Val_Typ
));
23984 elsif Is_Record_Type
(Val_Typ
) then
23985 Field
:= First_Component_Or_Discriminant
(Val_Typ
);
23986 while Present
(Field
) loop
23987 if Scalar_Part_Present
(Etype
(Field
)) then
23991 Next_Component_Or_Discriminant
(Field
);
23996 end Scalar_Part_Present
;
23998 ------------------------
23999 -- Scope_Is_Transient --
24000 ------------------------
24002 function Scope_Is_Transient
return Boolean is
24004 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
24005 end Scope_Is_Transient
;
24011 function Scope_Within
24012 (Inner
: Entity_Id
;
24013 Outer
: Entity_Id
) return Boolean
24019 while Present
(Curr
) and then Curr
/= Standard_Standard
loop
24020 Curr
:= Scope
(Curr
);
24022 if Curr
= Outer
then
24025 -- A selective accept body appears within a task type, but the
24026 -- enclosing subprogram is the procedure of the task body.
24028 elsif Ekind
(Curr
) = E_Task_Type
24029 and then Outer
= Task_Body_Procedure
(Curr
)
24033 -- Ditto for the body of a protected operation
24035 elsif Is_Subprogram
(Curr
)
24036 and then Outer
= Protected_Body_Subprogram
(Curr
)
24040 -- Outside of its scope, a synchronized type may just be private
24042 elsif Is_Private_Type
(Curr
)
24043 and then Present
(Full_View
(Curr
))
24044 and then Is_Concurrent_Type
(Full_View
(Curr
))
24046 return Scope_Within
(Full_View
(Curr
), Outer
);
24053 --------------------------
24054 -- Scope_Within_Or_Same --
24055 --------------------------
24057 function Scope_Within_Or_Same
24058 (Inner
: Entity_Id
;
24059 Outer
: Entity_Id
) return Boolean
24065 while Present
(Curr
) and then Curr
/= Standard_Standard
loop
24066 if Curr
= Outer
then
24070 Curr
:= Scope
(Curr
);
24074 end Scope_Within_Or_Same
;
24076 --------------------
24077 -- Set_Convention --
24078 --------------------
24080 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
24082 Basic_Set_Convention
(E
, Val
);
24085 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
24086 and then Has_Foreign_Convention
(E
)
24088 Set_Can_Use_Internal_Rep
(E
, False);
24091 -- If E is an object, including a component, and the type of E is an
24092 -- anonymous access type with no convention set, then also set the
24093 -- convention of the anonymous access type. We do not do this for
24094 -- anonymous protected types, since protected types always have the
24095 -- default convention.
24097 if Present
(Etype
(E
))
24098 and then (Is_Object
(E
)
24100 -- Allow E_Void (happens for pragma Convention appearing
24101 -- in the middle of a record applying to a component)
24103 or else Ekind
(E
) = E_Void
)
24106 Typ
: constant Entity_Id
:= Etype
(E
);
24109 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
24110 E_Anonymous_Access_Subprogram_Type
)
24111 and then not Has_Convention_Pragma
(Typ
)
24113 Basic_Set_Convention
(Typ
, Val
);
24114 Set_Has_Convention_Pragma
(Typ
);
24116 -- And for the access subprogram type, deal similarly with the
24117 -- designated E_Subprogram_Type, which is always internal.
24119 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
24121 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
24123 if Ekind
(Dtype
) = E_Subprogram_Type
24124 and then not Has_Convention_Pragma
(Dtype
)
24126 Basic_Set_Convention
(Dtype
, Val
);
24127 Set_Has_Convention_Pragma
(Dtype
);
24134 end Set_Convention
;
24136 ------------------------
24137 -- Set_Current_Entity --
24138 ------------------------
24140 -- The given entity is to be set as the currently visible definition of its
24141 -- associated name (i.e. the Node_Id associated with its name). All we have
24142 -- to do is to get the name from the identifier, and then set the
24143 -- associated Node_Id to point to the given entity.
24145 procedure Set_Current_Entity
(E
: Entity_Id
) is
24147 Set_Name_Entity_Id
(Chars
(E
), E
);
24148 end Set_Current_Entity
;
24150 ---------------------------
24151 -- Set_Debug_Info_Needed --
24152 ---------------------------
24154 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
24156 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
24157 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
24158 -- Used to set debug info in a related node if not set already
24160 --------------------------------------
24161 -- Set_Debug_Info_Needed_If_Not_Set --
24162 --------------------------------------
24164 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
24166 if Present
(E
) and then not Needs_Debug_Info
(E
) then
24167 Set_Debug_Info_Needed
(E
);
24169 -- For a private type, indicate that the full view also needs
24170 -- debug information.
24173 and then Is_Private_Type
(E
)
24174 and then Present
(Full_View
(E
))
24176 Set_Debug_Info_Needed
(Full_View
(E
));
24179 end Set_Debug_Info_Needed_If_Not_Set
;
24181 -- Start of processing for Set_Debug_Info_Needed
24184 -- Nothing to do if there is no available entity
24189 -- Nothing to do for an entity with suppressed debug information
24191 elsif Debug_Info_Off
(T
) then
24194 -- Nothing to do for an ignored Ghost entity because the entity will be
24195 -- eliminated from the tree.
24197 elsif Is_Ignored_Ghost_Entity
(T
) then
24200 -- Nothing to do if entity comes from a predefined file. Library files
24201 -- are compiled without debug information, but inlined bodies of these
24202 -- routines may appear in user code, and debug information on them ends
24203 -- up complicating debugging the user code.
24205 elsif In_Inlined_Body
and then In_Predefined_Unit
(T
) then
24206 Set_Needs_Debug_Info
(T
, False);
24209 -- Set flag in entity itself. Note that we will go through the following
24210 -- circuitry even if the flag is already set on T. That's intentional,
24211 -- it makes sure that the flag will be set in subsidiary entities.
24213 Set_Needs_Debug_Info
(T
);
24215 -- Set flag on subsidiary entities if not set already
24217 if Is_Object
(T
) then
24218 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
24220 elsif Is_Type
(T
) then
24221 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
24223 if Is_Record_Type
(T
) then
24225 Ent
: Entity_Id
:= First_Entity
(T
);
24227 while Present
(Ent
) loop
24228 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
24233 -- For a class wide subtype, we also need debug information
24234 -- for the equivalent type.
24236 if Ekind
(T
) = E_Class_Wide_Subtype
then
24237 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
24240 elsif Is_Array_Type
(T
) then
24241 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
24244 Indx
: Node_Id
:= First_Index
(T
);
24246 while Present
(Indx
) loop
24247 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
24248 Indx
:= Next_Index
(Indx
);
24252 -- For a packed array type, we also need debug information for
24253 -- the type used to represent the packed array. Conversely, we
24254 -- also need it for the former if we need it for the latter.
24256 if Is_Packed
(T
) then
24257 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
24260 if Is_Packed_Array_Impl_Type
(T
) then
24261 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
24264 elsif Is_Access_Type
(T
) then
24265 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
24267 elsif Is_Private_Type
(T
) then
24269 FV
: constant Entity_Id
:= Full_View
(T
);
24272 Set_Debug_Info_Needed_If_Not_Set
(FV
);
24274 -- If the full view is itself a derived private type, we need
24275 -- debug information on its underlying type.
24278 and then Is_Private_Type
(FV
)
24279 and then Present
(Underlying_Full_View
(FV
))
24281 Set_Needs_Debug_Info
(Underlying_Full_View
(FV
));
24285 elsif Is_Protected_Type
(T
) then
24286 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
24288 elsif Is_Scalar_Type
(T
) then
24290 -- If the subrange bounds are materialized by dedicated constant
24291 -- objects, also include them in the debug info to make sure the
24292 -- debugger can properly use them.
24294 if Present
(Scalar_Range
(T
))
24295 and then Nkind
(Scalar_Range
(T
)) = N_Range
24298 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
24299 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
24302 if Is_Entity_Name
(Low_Bnd
) then
24303 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
24306 if Is_Entity_Name
(High_Bnd
) then
24307 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
24313 end Set_Debug_Info_Needed
;
24315 ----------------------------
24316 -- Set_Entity_With_Checks --
24317 ----------------------------
24319 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
24320 Val_Actual
: Entity_Id
;
24322 Post_Node
: Node_Id
;
24325 -- Unconditionally set the entity
24327 Set_Entity
(N
, Val
);
24329 -- The node to post on is the selector in the case of an expanded name,
24330 -- and otherwise the node itself.
24332 if Nkind
(N
) = N_Expanded_Name
then
24333 Post_Node
:= Selector_Name
(N
);
24338 -- Check for violation of No_Fixed_IO
24340 if Restriction_Check_Required
(No_Fixed_IO
)
24342 ((RTU_Loaded
(Ada_Text_IO
)
24343 and then (Is_RTE
(Val
, RE_Decimal_IO
)
24345 Is_RTE
(Val
, RE_Fixed_IO
)))
24348 (RTU_Loaded
(Ada_Wide_Text_IO
)
24349 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
24351 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
24354 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
24355 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
24357 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
24359 -- A special extra check, don't complain about a reference from within
24360 -- the Ada.Interrupts package itself!
24362 and then not In_Same_Extended_Unit
(N
, Val
)
24364 Check_Restriction
(No_Fixed_IO
, Post_Node
);
24367 -- Remaining checks are only done on source nodes. Note that we test
24368 -- for violation of No_Fixed_IO even on non-source nodes, because the
24369 -- cases for checking violations of this restriction are instantiations
24370 -- where the reference in the instance has Comes_From_Source False.
24372 if not Comes_From_Source
(N
) then
24376 -- Check for violation of No_Abort_Statements, which is triggered by
24377 -- call to Ada.Task_Identification.Abort_Task.
24379 if Restriction_Check_Required
(No_Abort_Statements
)
24380 and then (Is_RTE
(Val
, RE_Abort_Task
))
24382 -- A special extra check, don't complain about a reference from within
24383 -- the Ada.Task_Identification package itself!
24385 and then not In_Same_Extended_Unit
(N
, Val
)
24387 Check_Restriction
(No_Abort_Statements
, Post_Node
);
24390 if Val
= Standard_Long_Long_Integer
then
24391 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
24394 -- Check for violation of No_Dynamic_Attachment
24396 if Restriction_Check_Required
(No_Dynamic_Attachment
)
24397 and then RTU_Loaded
(Ada_Interrupts
)
24398 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
24399 Is_RTE
(Val
, RE_Is_Attached
) or else
24400 Is_RTE
(Val
, RE_Current_Handler
) or else
24401 Is_RTE
(Val
, RE_Attach_Handler
) or else
24402 Is_RTE
(Val
, RE_Exchange_Handler
) or else
24403 Is_RTE
(Val
, RE_Detach_Handler
) or else
24404 Is_RTE
(Val
, RE_Reference
))
24406 -- A special extra check, don't complain about a reference from within
24407 -- the Ada.Interrupts package itself!
24409 and then not In_Same_Extended_Unit
(N
, Val
)
24411 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
24414 -- Check for No_Implementation_Identifiers
24416 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
24418 -- We have an implementation defined entity if it is marked as
24419 -- implementation defined, or is defined in a package marked as
24420 -- implementation defined. However, library packages themselves
24421 -- are excluded (we don't want to flag Interfaces itself, just
24422 -- the entities within it).
24424 if (Is_Implementation_Defined
(Val
)
24426 (Present
(Scope
(Val
))
24427 and then Is_Implementation_Defined
(Scope
(Val
))))
24428 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
24429 and then Is_Library_Level_Entity
(Val
))
24431 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
24435 -- Do the style check
24438 and then not Suppress_Style_Checks
(Val
)
24439 and then not In_Instance
24441 if Nkind
(N
) = N_Identifier
then
24443 elsif Nkind
(N
) = N_Expanded_Name
then
24444 Nod
:= Selector_Name
(N
);
24449 -- A special situation arises for derived operations, where we want
24450 -- to do the check against the parent (since the Sloc of the derived
24451 -- operation points to the derived type declaration itself).
24454 while not Comes_From_Source
(Val_Actual
)
24455 and then Nkind
(Val_Actual
) in N_Entity
24456 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
24457 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
24458 and then Present
(Alias
(Val_Actual
))
24460 Val_Actual
:= Alias
(Val_Actual
);
24463 -- Renaming declarations for generic actuals do not come from source,
24464 -- and have a different name from that of the entity they rename, so
24465 -- there is no style check to perform here.
24467 if Chars
(Nod
) = Chars
(Val_Actual
) then
24468 Style
.Check_Identifier
(Nod
, Val_Actual
);
24472 Set_Entity
(N
, Val
);
24473 end Set_Entity_With_Checks
;
24475 ------------------------------
24476 -- Set_Invalid_Scalar_Value --
24477 ------------------------------
24479 procedure Set_Invalid_Scalar_Value
24480 (Scal_Typ
: Float_Scalar_Id
;
24483 Slot
: Ureal
renames Invalid_Floats
(Scal_Typ
);
24486 -- Detect an attempt to set a different value for the same scalar type
24488 pragma Assert
(Slot
= No_Ureal
);
24490 end Set_Invalid_Scalar_Value
;
24492 ------------------------------
24493 -- Set_Invalid_Scalar_Value --
24494 ------------------------------
24496 procedure Set_Invalid_Scalar_Value
24497 (Scal_Typ
: Integer_Scalar_Id
;
24500 Slot
: Uint
renames Invalid_Integers
(Scal_Typ
);
24503 -- Detect an attempt to set a different value for the same scalar type
24505 pragma Assert
(Slot
= No_Uint
);
24507 end Set_Invalid_Scalar_Value
;
24509 ------------------------
24510 -- Set_Name_Entity_Id --
24511 ------------------------
24513 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
24515 Set_Name_Table_Int
(Id
, Int
(Val
));
24516 end Set_Name_Entity_Id
;
24518 ---------------------
24519 -- Set_Next_Actual --
24520 ---------------------
24522 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
24524 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
24525 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
24527 end Set_Next_Actual
;
24529 ----------------------------------
24530 -- Set_Optimize_Alignment_Flags --
24531 ----------------------------------
24533 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
24535 if Optimize_Alignment
= 'S' then
24536 Set_Optimize_Alignment_Space
(E
);
24537 elsif Optimize_Alignment
= 'T' then
24538 Set_Optimize_Alignment_Time
(E
);
24540 end Set_Optimize_Alignment_Flags
;
24542 -----------------------
24543 -- Set_Public_Status --
24544 -----------------------
24546 procedure Set_Public_Status
(Id
: Entity_Id
) is
24547 S
: constant Entity_Id
:= Current_Scope
;
24549 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
24550 -- Determines if E is defined within handled statement sequence or
24551 -- an if statement, returns True if so, False otherwise.
24553 ----------------------
24554 -- Within_HSS_Or_If --
24555 ----------------------
24557 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
24560 N
:= Declaration_Node
(E
);
24567 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
24573 end Within_HSS_Or_If
;
24575 -- Start of processing for Set_Public_Status
24578 -- Everything in the scope of Standard is public
24580 if S
= Standard_Standard
then
24581 Set_Is_Public
(Id
);
24583 -- Entity is definitely not public if enclosing scope is not public
24585 elsif not Is_Public
(S
) then
24588 -- An object or function declaration that occurs in a handled sequence
24589 -- of statements or within an if statement is the declaration for a
24590 -- temporary object or local subprogram generated by the expander. It
24591 -- never needs to be made public and furthermore, making it public can
24592 -- cause back end problems.
24594 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
24595 N_Function_Specification
)
24596 and then Within_HSS_Or_If
(Id
)
24600 -- Entities in public packages or records are public
24602 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
24603 Set_Is_Public
(Id
);
24605 -- The bounds of an entry family declaration can generate object
24606 -- declarations that are visible to the back-end, e.g. in the
24607 -- the declaration of a composite type that contains tasks.
24609 elsif Is_Concurrent_Type
(S
)
24610 and then not Has_Completion
(S
)
24611 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
24613 Set_Is_Public
(Id
);
24615 end Set_Public_Status
;
24617 -----------------------------
24618 -- Set_Referenced_Modified --
24619 -----------------------------
24621 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
24625 -- Deal with indexed or selected component where prefix is modified
24627 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
24628 Pref
:= Prefix
(N
);
24630 -- If prefix is access type, then it is the designated object that is
24631 -- being modified, which means we have no entity to set the flag on.
24633 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
24636 -- Otherwise chase the prefix
24639 Set_Referenced_Modified
(Pref
, Out_Param
);
24642 -- Otherwise see if we have an entity name (only other case to process)
24644 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
24645 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
24646 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
24648 end Set_Referenced_Modified
;
24654 procedure Set_Rep_Info
(T1
: Entity_Id
; T2
: Entity_Id
) is
24656 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
24657 Set_Is_Independent
(T1
, Is_Independent
(T2
));
24658 Set_Is_Volatile_Full_Access
(T1
, Is_Volatile_Full_Access
(T2
));
24660 if Is_Base_Type
(T1
) then
24661 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
24665 ----------------------------
24666 -- Set_Scope_Is_Transient --
24667 ----------------------------
24669 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
24671 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
24672 end Set_Scope_Is_Transient
;
24674 -------------------
24675 -- Set_Size_Info --
24676 -------------------
24678 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
24680 -- We copy Esize, but not RM_Size, since in general RM_Size is
24681 -- subtype specific and does not get inherited by all subtypes.
24683 Set_Esize
(T1
, Esize
(T2
));
24684 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
24686 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
24688 Is_Discrete_Or_Fixed_Point_Type
(T2
)
24690 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
24693 Set_Alignment
(T1
, Alignment
(T2
));
24696 ------------------------------
24697 -- Should_Ignore_Pragma_Par --
24698 ------------------------------
24700 function Should_Ignore_Pragma_Par
(Prag_Name
: Name_Id
) return Boolean is
24701 pragma Assert
(Compiler_State
= Parsing
);
24702 -- This one can't work during semantic analysis, because we don't have a
24703 -- correct Current_Source_File.
24705 Result
: constant Boolean :=
24706 Get_Name_Table_Boolean3
(Prag_Name
)
24707 and then not Is_Internal_File_Name
24708 (File_Name
(Current_Source_File
));
24711 end Should_Ignore_Pragma_Par
;
24713 ------------------------------
24714 -- Should_Ignore_Pragma_Sem --
24715 ------------------------------
24717 function Should_Ignore_Pragma_Sem
(N
: Node_Id
) return Boolean is
24718 pragma Assert
(Compiler_State
= Analyzing
);
24719 Prag_Name
: constant Name_Id
:= Pragma_Name
(N
);
24720 Result
: constant Boolean :=
24721 Get_Name_Table_Boolean3
(Prag_Name
)
24722 and then not In_Internal_Unit
(N
);
24726 end Should_Ignore_Pragma_Sem
;
24728 --------------------
24729 -- Static_Boolean --
24730 --------------------
24732 function Static_Boolean
(N
: Node_Id
) return Uint
is
24734 Analyze_And_Resolve
(N
, Standard_Boolean
);
24737 or else Error_Posted
(N
)
24738 or else Etype
(N
) = Any_Type
24743 if Is_OK_Static_Expression
(N
) then
24744 if not Raises_Constraint_Error
(N
) then
24745 return Expr_Value
(N
);
24750 elsif Etype
(N
) = Any_Type
then
24754 Flag_Non_Static_Expr
24755 ("static boolean expression required here", N
);
24758 end Static_Boolean
;
24760 --------------------
24761 -- Static_Integer --
24762 --------------------
24764 function Static_Integer
(N
: Node_Id
) return Uint
is
24766 Analyze_And_Resolve
(N
, Any_Integer
);
24769 or else Error_Posted
(N
)
24770 or else Etype
(N
) = Any_Type
24775 if Is_OK_Static_Expression
(N
) then
24776 if not Raises_Constraint_Error
(N
) then
24777 return Expr_Value
(N
);
24782 elsif Etype
(N
) = Any_Type
then
24786 Flag_Non_Static_Expr
24787 ("static integer expression required here", N
);
24790 end Static_Integer
;
24792 --------------------------
24793 -- Statically_Different --
24794 --------------------------
24796 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
24797 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
24798 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
24800 return Is_Entity_Name
(R1
)
24801 and then Is_Entity_Name
(R2
)
24802 and then Entity
(R1
) /= Entity
(R2
)
24803 and then not Is_Formal
(Entity
(R1
))
24804 and then not Is_Formal
(Entity
(R2
));
24805 end Statically_Different
;
24807 --------------------------------------
24808 -- Subject_To_Loop_Entry_Attributes --
24809 --------------------------------------
24811 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
24817 -- The expansion mechanism transform a loop subject to at least one
24818 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
24819 -- the conditional part.
24821 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
24822 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
24824 Stmt
:= Original_Node
(N
);
24828 Nkind
(Stmt
) = N_Loop_Statement
24829 and then Present
(Identifier
(Stmt
))
24830 and then Present
(Entity
(Identifier
(Stmt
)))
24831 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
24832 end Subject_To_Loop_Entry_Attributes
;
24834 -----------------------------
24835 -- Subprogram_Access_Level --
24836 -----------------------------
24838 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
24840 if Present
(Alias
(Subp
)) then
24841 return Subprogram_Access_Level
(Alias
(Subp
));
24843 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
24845 end Subprogram_Access_Level
;
24847 ---------------------
24848 -- Subprogram_Name --
24849 ---------------------
24851 function Subprogram_Name
(N
: Node_Id
) return String is
24852 Buf
: Bounded_String
;
24853 Ent
: Node_Id
:= N
;
24857 while Present
(Ent
) loop
24858 case Nkind
(Ent
) is
24859 when N_Subprogram_Body
=>
24860 Ent
:= Defining_Unit_Name
(Specification
(Ent
));
24863 when N_Subprogram_Declaration
=>
24864 Nod
:= Corresponding_Body
(Ent
);
24866 if Present
(Nod
) then
24869 Ent
:= Defining_Unit_Name
(Specification
(Ent
));
24874 when N_Subprogram_Instantiation
24876 | N_Package_Specification
24878 Ent
:= Defining_Unit_Name
(Ent
);
24881 when N_Protected_Type_Declaration
=>
24882 Ent
:= Corresponding_Body
(Ent
);
24885 when N_Protected_Body
24888 Ent
:= Defining_Identifier
(Ent
);
24895 Ent
:= Parent
(Ent
);
24899 return "unknown subprogram:unknown file:0:0";
24902 -- If the subprogram is a child unit, use its simple name to start the
24903 -- construction of the fully qualified name.
24905 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
24906 Ent
:= Defining_Identifier
(Ent
);
24909 Append_Entity_Name
(Buf
, Ent
);
24911 -- Append homonym number if needed
24913 if Nkind
(N
) in N_Entity
and then Has_Homonym
(N
) then
24915 H
: Entity_Id
:= Homonym
(N
);
24919 while Present
(H
) loop
24920 if Scope
(H
) = Scope
(N
) then
24934 -- Append source location of Ent to Buf so that the string will
24935 -- look like "subp:file:line:col".
24938 Loc
: constant Source_Ptr
:= Sloc
(Ent
);
24941 Append
(Buf
, Reference_Name
(Get_Source_File_Index
(Loc
)));
24943 Append
(Buf
, Nat
(Get_Logical_Line_Number
(Loc
)));
24945 Append
(Buf
, Nat
(Get_Column_Number
(Loc
)));
24949 end Subprogram_Name
;
24951 -------------------------------
24952 -- Support_Atomic_Primitives --
24953 -------------------------------
24955 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
24959 -- Verify the alignment of Typ is known
24961 if not Known_Alignment
(Typ
) then
24965 if Known_Static_Esize
(Typ
) then
24966 Size
:= UI_To_Int
(Esize
(Typ
));
24968 -- If the Esize (Object_Size) is unknown at compile time, look at the
24969 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
24971 elsif Known_Static_RM_Size
(Typ
) then
24972 Size
:= UI_To_Int
(RM_Size
(Typ
));
24974 -- Otherwise, the size is considered to be unknown.
24980 -- Check that the size of the component is 8, 16, 32, or 64 bits and
24981 -- that Typ is properly aligned.
24984 when 8 |
16 |
32 |
64 =>
24985 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
24990 end Support_Atomic_Primitives
;
24996 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
24998 if Debug_Flag_W
then
24999 for J
in 0 .. Scope_Stack
.Last
loop
25004 Write_Name
(Chars
(E
));
25005 Write_Str
(" from ");
25006 Write_Location
(Sloc
(N
));
25011 -----------------------
25012 -- Transfer_Entities --
25013 -----------------------
25015 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
25016 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
25017 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25018 -- Set_Public_Status. If successful and Id denotes a record type, set
25019 -- the Is_Public attribute of its fields.
25021 --------------------------
25022 -- Set_Public_Status_Of --
25023 --------------------------
25025 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
25029 if not Is_Public
(Id
) then
25030 Set_Public_Status
(Id
);
25032 -- When the input entity is a public record type, ensure that all
25033 -- its internal fields are also exposed to the linker. The fields
25034 -- of a class-wide type are never made public.
25037 and then Is_Record_Type
(Id
)
25038 and then not Is_Class_Wide_Type
(Id
)
25040 Field
:= First_Entity
(Id
);
25041 while Present
(Field
) loop
25042 Set_Is_Public
(Field
);
25043 Next_Entity
(Field
);
25047 end Set_Public_Status_Of
;
25051 Full_Id
: Entity_Id
;
25054 -- Start of processing for Transfer_Entities
25057 Id
:= First_Entity
(From
);
25059 if Present
(Id
) then
25061 -- Merge the entity chain of the source scope with that of the
25062 -- destination scope.
25064 if Present
(Last_Entity
(To
)) then
25065 Link_Entities
(Last_Entity
(To
), Id
);
25067 Set_First_Entity
(To
, Id
);
25070 Set_Last_Entity
(To
, Last_Entity
(From
));
25072 -- Inspect the entities of the source scope and update their Scope
25075 while Present
(Id
) loop
25076 Set_Scope
(Id
, To
);
25077 Set_Public_Status_Of
(Id
);
25079 -- Handle an internally generated full view for a private type
25081 if Is_Private_Type
(Id
)
25082 and then Present
(Full_View
(Id
))
25083 and then Is_Itype
(Full_View
(Id
))
25085 Full_Id
:= Full_View
(Id
);
25087 Set_Scope
(Full_Id
, To
);
25088 Set_Public_Status_Of
(Full_Id
);
25094 Set_First_Entity
(From
, Empty
);
25095 Set_Last_Entity
(From
, Empty
);
25097 end Transfer_Entities
;
25099 -----------------------
25100 -- Type_Access_Level --
25101 -----------------------
25103 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
25107 Btyp
:= Base_Type
(Typ
);
25109 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
25110 -- simply use the level where the type is declared. This is true for
25111 -- stand-alone object declarations, and for anonymous access types
25112 -- associated with components the level is the same as that of the
25113 -- enclosing composite type. However, special treatment is needed for
25114 -- the cases of access parameters, return objects of an anonymous access
25115 -- type, and, in Ada 95, access discriminants of limited types.
25117 if Is_Access_Type
(Btyp
) then
25118 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
25120 -- If the type is a nonlocal anonymous access type (such as for
25121 -- an access parameter) we treat it as being declared at the
25122 -- library level to ensure that names such as X.all'access don't
25123 -- fail static accessibility checks.
25125 if not Is_Local_Anonymous_Access
(Typ
) then
25126 return Scope_Depth
(Standard_Standard
);
25128 -- If this is a return object, the accessibility level is that of
25129 -- the result subtype of the enclosing function. The test here is
25130 -- little complicated, because we have to account for extended
25131 -- return statements that have been rewritten as blocks, in which
25132 -- case we have to find and the Is_Return_Object attribute of the
25133 -- itype's associated object. It would be nice to find a way to
25134 -- simplify this test, but it doesn't seem worthwhile to add a new
25135 -- flag just for purposes of this test. ???
25137 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
25140 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
25141 N_Object_Declaration
25142 and then Is_Return_Object
25143 (Defining_Identifier
25144 (Associated_Node_For_Itype
(Btyp
))))
25150 Scop
:= Scope
(Scope
(Btyp
));
25151 while Present
(Scop
) loop
25152 exit when Ekind
(Scop
) = E_Function
;
25153 Scop
:= Scope
(Scop
);
25156 -- Treat the return object's type as having the level of the
25157 -- function's result subtype (as per RM05-6.5(5.3/2)).
25159 return Type_Access_Level
(Etype
(Scop
));
25164 Btyp
:= Root_Type
(Btyp
);
25166 -- The accessibility level of anonymous access types associated with
25167 -- discriminants is that of the current instance of the type, and
25168 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
25170 -- AI-402: access discriminants have accessibility based on the
25171 -- object rather than the type in Ada 2005, so the above paragraph
25174 -- ??? Needs completion with rules from AI-416
25176 if Ada_Version
<= Ada_95
25177 and then Ekind
(Typ
) = E_Anonymous_Access_Type
25178 and then Present
(Associated_Node_For_Itype
(Typ
))
25179 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
25180 N_Discriminant_Specification
25182 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
25186 -- Return library level for a generic formal type. This is done because
25187 -- RM(10.3.2) says that "The statically deeper relationship does not
25188 -- apply to ... a descendant of a generic formal type". Rather than
25189 -- checking at each point where a static accessibility check is
25190 -- performed to see if we are dealing with a formal type, this rule is
25191 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
25192 -- return extreme values for a formal type; Deepest_Type_Access_Level
25193 -- returns Int'Last. By calling the appropriate function from among the
25194 -- two, we ensure that the static accessibility check will pass if we
25195 -- happen to run into a formal type. More specifically, we should call
25196 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
25197 -- call occurs as part of a static accessibility check and the error
25198 -- case is the case where the type's level is too shallow (as opposed
25201 if Is_Generic_Type
(Root_Type
(Btyp
)) then
25202 return Scope_Depth
(Standard_Standard
);
25205 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
25206 end Type_Access_Level
;
25208 ------------------------------------
25209 -- Type_Without_Stream_Operation --
25210 ------------------------------------
25212 function Type_Without_Stream_Operation
25214 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
25216 BT
: constant Entity_Id
:= Base_Type
(T
);
25217 Op_Missing
: Boolean;
25220 if not Restriction_Active
(No_Default_Stream_Attributes
) then
25224 if Is_Elementary_Type
(T
) then
25225 if Op
= TSS_Null
then
25227 No
(TSS
(BT
, TSS_Stream_Read
))
25228 or else No
(TSS
(BT
, TSS_Stream_Write
));
25231 Op_Missing
:= No
(TSS
(BT
, Op
));
25240 elsif Is_Array_Type
(T
) then
25241 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
25243 elsif Is_Record_Type
(T
) then
25249 Comp
:= First_Component
(T
);
25250 while Present
(Comp
) loop
25251 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
25253 if Present
(C_Typ
) then
25257 Next_Component
(Comp
);
25263 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
25264 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
25268 end Type_Without_Stream_Operation
;
25270 ---------------------
25271 -- Ultimate_Prefix --
25272 ---------------------
25274 function Ultimate_Prefix
(N
: Node_Id
) return Node_Id
is
25279 while Nkind_In
(Pref
, N_Explicit_Dereference
,
25280 N_Indexed_Component
,
25281 N_Selected_Component
,
25284 Pref
:= Prefix
(Pref
);
25288 end Ultimate_Prefix
;
25290 ----------------------------
25291 -- Unique_Defining_Entity --
25292 ----------------------------
25294 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
25296 return Unique_Entity
(Defining_Entity
(N
));
25297 end Unique_Defining_Entity
;
25299 -------------------
25300 -- Unique_Entity --
25301 -------------------
25303 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
25304 U
: Entity_Id
:= E
;
25310 if Present
(Full_View
(E
)) then
25311 U
:= Full_View
(E
);
25315 if Nkind
(Parent
(E
)) = N_Entry_Body
then
25317 Prot_Item
: Entity_Id
;
25318 Prot_Type
: Entity_Id
;
25321 if Ekind
(E
) = E_Entry
then
25322 Prot_Type
:= Scope
(E
);
25324 -- Bodies of entry families are nested within an extra scope
25325 -- that contains an entry index declaration.
25328 Prot_Type
:= Scope
(Scope
(E
));
25331 -- A protected type may be declared as a private type, in
25332 -- which case we need to get its full view.
25334 if Is_Private_Type
(Prot_Type
) then
25335 Prot_Type
:= Full_View
(Prot_Type
);
25338 -- Full view may not be present on error, in which case
25339 -- return E by default.
25341 if Present
(Prot_Type
) then
25342 pragma Assert
(Ekind
(Prot_Type
) = E_Protected_Type
);
25344 -- Traverse the entity list of the protected type and
25345 -- locate an entry declaration which matches the entry
25348 Prot_Item
:= First_Entity
(Prot_Type
);
25349 while Present
(Prot_Item
) loop
25350 if Ekind
(Prot_Item
) in Entry_Kind
25351 and then Corresponding_Body
(Parent
(Prot_Item
)) = E
25357 Next_Entity
(Prot_Item
);
25363 when Formal_Kind
=>
25364 if Present
(Spec_Entity
(E
)) then
25365 U
:= Spec_Entity
(E
);
25368 when E_Package_Body
=>
25371 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
25375 if Nkind
(P
) = N_Package_Body
25376 and then Present
(Corresponding_Spec
(P
))
25378 U
:= Corresponding_Spec
(P
);
25380 elsif Nkind
(P
) = N_Package_Body_Stub
25381 and then Present
(Corresponding_Spec_Of_Stub
(P
))
25383 U
:= Corresponding_Spec_Of_Stub
(P
);
25386 when E_Protected_Body
=>
25389 if Nkind
(P
) = N_Protected_Body
25390 and then Present
(Corresponding_Spec
(P
))
25392 U
:= Corresponding_Spec
(P
);
25394 elsif Nkind
(P
) = N_Protected_Body_Stub
25395 and then Present
(Corresponding_Spec_Of_Stub
(P
))
25397 U
:= Corresponding_Spec_Of_Stub
(P
);
25399 if Is_Single_Protected_Object
(U
) then
25404 if Is_Private_Type
(U
) then
25405 U
:= Full_View
(U
);
25408 when E_Subprogram_Body
=>
25411 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
25417 if Nkind
(P
) = N_Subprogram_Body
25418 and then Present
(Corresponding_Spec
(P
))
25420 U
:= Corresponding_Spec
(P
);
25422 elsif Nkind
(P
) = N_Subprogram_Body_Stub
25423 and then Present
(Corresponding_Spec_Of_Stub
(P
))
25425 U
:= Corresponding_Spec_Of_Stub
(P
);
25427 elsif Nkind
(P
) = N_Subprogram_Renaming_Declaration
then
25428 U
:= Corresponding_Spec
(P
);
25431 when E_Task_Body
=>
25434 if Nkind
(P
) = N_Task_Body
25435 and then Present
(Corresponding_Spec
(P
))
25437 U
:= Corresponding_Spec
(P
);
25439 elsif Nkind
(P
) = N_Task_Body_Stub
25440 and then Present
(Corresponding_Spec_Of_Stub
(P
))
25442 U
:= Corresponding_Spec_Of_Stub
(P
);
25444 if Is_Single_Task_Object
(U
) then
25449 if Is_Private_Type
(U
) then
25450 U
:= Full_View
(U
);
25454 if Present
(Full_View
(E
)) then
25455 U
:= Full_View
(E
);
25469 function Unique_Name
(E
: Entity_Id
) return String is
25471 -- Names in E_Subprogram_Body or E_Package_Body entities are not
25472 -- reliable, as they may not include the overloading suffix. Instead,
25473 -- when looking for the name of E or one of its enclosing scope, we get
25474 -- the name of the corresponding Unique_Entity.
25476 U
: constant Entity_Id
:= Unique_Entity
(E
);
25478 function This_Name
return String;
25484 function This_Name
return String is
25486 return Get_Name_String
(Chars
(U
));
25489 -- Start of processing for Unique_Name
25492 if E
= Standard_Standard
25493 or else Has_Fully_Qualified_Name
(E
)
25497 elsif Ekind
(E
) = E_Enumeration_Literal
then
25498 return Unique_Name
(Etype
(E
)) & "__" & This_Name
;
25502 S
: constant Entity_Id
:= Scope
(U
);
25503 pragma Assert
(Present
(S
));
25506 -- Prefix names of predefined types with standard__, but leave
25507 -- names of user-defined packages and subprograms without prefix
25508 -- (even if technically they are nested in the Standard package).
25510 if S
= Standard_Standard
then
25511 if Ekind
(U
) = E_Package
or else Is_Subprogram
(U
) then
25514 return Unique_Name
(S
) & "__" & This_Name
;
25517 -- For intances of generic subprograms use the name of the related
25518 -- instace and skip the scope of its wrapper package.
25520 elsif Is_Wrapper_Package
(S
) then
25521 pragma Assert
(Scope
(S
) = Scope
(Related_Instance
(S
)));
25522 -- Wrapper package and the instantiation are in the same scope
25525 Enclosing_Name
: constant String :=
25526 Unique_Name
(Scope
(S
)) & "__" &
25527 Get_Name_String
(Chars
(Related_Instance
(S
)));
25530 if Is_Subprogram
(U
)
25531 and then not Is_Generic_Actual_Subprogram
(U
)
25533 return Enclosing_Name
;
25535 return Enclosing_Name
& "__" & This_Name
;
25540 return Unique_Name
(S
) & "__" & This_Name
;
25546 ---------------------
25547 -- Unit_Is_Visible --
25548 ---------------------
25550 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
25551 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
25552 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
25554 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
25555 -- For a child unit, check whether unit appears in a with_clause
25558 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
25559 -- Scan the context clause of one compilation unit looking for a
25560 -- with_clause for the unit in question.
25562 ----------------------------
25563 -- Unit_In_Parent_Context --
25564 ----------------------------
25566 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
25568 if Unit_In_Context
(Par_Unit
) then
25571 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
25572 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
25577 end Unit_In_Parent_Context
;
25579 ---------------------
25580 -- Unit_In_Context --
25581 ---------------------
25583 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
25587 Clause
:= First
(Context_Items
(Comp_Unit
));
25588 while Present
(Clause
) loop
25589 if Nkind
(Clause
) = N_With_Clause
then
25590 if Library_Unit
(Clause
) = U
then
25593 -- The with_clause may denote a renaming of the unit we are
25594 -- looking for, eg. Text_IO which renames Ada.Text_IO.
25597 Renamed_Entity
(Entity
(Name
(Clause
))) =
25598 Defining_Entity
(Unit
(U
))
25608 end Unit_In_Context
;
25610 -- Start of processing for Unit_Is_Visible
25613 -- The currrent unit is directly visible
25618 elsif Unit_In_Context
(Curr
) then
25621 -- If the current unit is a body, check the context of the spec
25623 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
25625 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
25626 and then not Acts_As_Spec
(Unit
(Curr
)))
25628 if Unit_In_Context
(Library_Unit
(Curr
)) then
25633 -- If the spec is a child unit, examine the parents
25635 if Is_Child_Unit
(Curr_Entity
) then
25636 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
25638 Unit_In_Parent_Context
25639 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
25641 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
25647 end Unit_Is_Visible
;
25649 ------------------------------
25650 -- Universal_Interpretation --
25651 ------------------------------
25653 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
25654 Index
: Interp_Index
;
25658 -- The argument may be a formal parameter of an operator or subprogram
25659 -- with multiple interpretations, or else an expression for an actual.
25661 if Nkind
(Opnd
) = N_Defining_Identifier
25662 or else not Is_Overloaded
(Opnd
)
25664 if Etype
(Opnd
) = Universal_Integer
25665 or else Etype
(Opnd
) = Universal_Real
25667 return Etype
(Opnd
);
25673 Get_First_Interp
(Opnd
, Index
, It
);
25674 while Present
(It
.Typ
) loop
25675 if It
.Typ
= Universal_Integer
25676 or else It
.Typ
= Universal_Real
25681 Get_Next_Interp
(Index
, It
);
25686 end Universal_Interpretation
;
25692 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
25694 -- Recurse to handle unlikely case of multiple levels of qualification
25696 if Nkind
(Expr
) = N_Qualified_Expression
then
25697 return Unqualify
(Expression
(Expr
));
25699 -- Normal case, not a qualified expression
25710 function Unqual_Conv
(Expr
: Node_Id
) return Node_Id
is
25712 -- Recurse to handle unlikely case of multiple levels of qualification
25713 -- and/or conversion.
25715 if Nkind_In
(Expr
, N_Qualified_Expression
,
25717 N_Unchecked_Type_Conversion
)
25719 return Unqual_Conv
(Expression
(Expr
));
25721 -- Normal case, not a qualified expression
25728 --------------------
25729 -- Validated_View --
25730 --------------------
25732 function Validated_View
(Typ
: Entity_Id
) return Entity_Id
is
25733 Continue
: Boolean;
25734 Val_Typ
: Entity_Id
;
25738 Val_Typ
:= Base_Type
(Typ
);
25740 -- Obtain the full view of the input type by stripping away concurrency,
25741 -- derivations, and privacy.
25743 while Continue
loop
25746 if Is_Concurrent_Type
(Val_Typ
) then
25747 if Present
(Corresponding_Record_Type
(Val_Typ
)) then
25749 Val_Typ
:= Corresponding_Record_Type
(Val_Typ
);
25752 elsif Is_Derived_Type
(Val_Typ
) then
25754 Val_Typ
:= Etype
(Val_Typ
);
25756 elsif Is_Private_Type
(Val_Typ
) then
25757 if Present
(Underlying_Full_View
(Val_Typ
)) then
25759 Val_Typ
:= Underlying_Full_View
(Val_Typ
);
25761 elsif Present
(Full_View
(Val_Typ
)) then
25763 Val_Typ
:= Full_View
(Val_Typ
);
25769 end Validated_View
;
25771 -----------------------
25772 -- Visible_Ancestors --
25773 -----------------------
25775 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
25781 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
25783 -- Collect all the parents and progenitors of Typ. If the full-view of
25784 -- private parents and progenitors is available then it is used to
25785 -- generate the list of visible ancestors; otherwise their partial
25786 -- view is added to the resulting list.
25791 Use_Full_View
=> True);
25795 Ifaces_List
=> List_2
,
25796 Exclude_Parents
=> True,
25797 Use_Full_View
=> True);
25799 -- Join the two lists. Avoid duplications because an interface may
25800 -- simultaneously be parent and progenitor of a type.
25802 Elmt
:= First_Elmt
(List_2
);
25803 while Present
(Elmt
) loop
25804 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
25809 end Visible_Ancestors
;
25811 ----------------------
25812 -- Within_Init_Proc --
25813 ----------------------
25815 function Within_Init_Proc
return Boolean is
25819 S
:= Current_Scope
;
25820 while not Is_Overloadable
(S
) loop
25821 if S
= Standard_Standard
then
25828 return Is_Init_Proc
(S
);
25829 end Within_Init_Proc
;
25831 ---------------------------
25832 -- Within_Protected_Type --
25833 ---------------------------
25835 function Within_Protected_Type
(E
: Entity_Id
) return Boolean is
25836 Scop
: Entity_Id
:= Scope
(E
);
25839 while Present
(Scop
) loop
25840 if Ekind
(Scop
) = E_Protected_Type
then
25844 Scop
:= Scope
(Scop
);
25848 end Within_Protected_Type
;
25854 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
25856 return Scope_Within_Or_Same
(Scope
(E
), S
);
25859 ----------------------------
25860 -- Within_Subprogram_Call --
25861 ----------------------------
25863 function Within_Subprogram_Call
(N
: Node_Id
) return Boolean is
25867 -- Climb the parent chain looking for a function or procedure call
25870 while Present
(Par
) loop
25871 if Nkind_In
(Par
, N_Entry_Call_Statement
,
25873 N_Procedure_Call_Statement
)
25877 -- Prevent the search from going too far
25879 elsif Is_Body_Or_Package_Declaration
(Par
) then
25883 Par
:= Parent
(Par
);
25887 end Within_Subprogram_Call
;
25893 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
25894 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
25895 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
25897 Matching_Field
: Entity_Id
;
25898 -- Entity to give a more precise suggestion on how to write a one-
25899 -- element positional aggregate.
25901 function Has_One_Matching_Field
return Boolean;
25902 -- Determines if Expec_Type is a record type with a single component or
25903 -- discriminant whose type matches the found type or is one dimensional
25904 -- array whose component type matches the found type. In the case of
25905 -- one discriminant, we ignore the variant parts. That's not accurate,
25906 -- but good enough for the warning.
25908 ----------------------------
25909 -- Has_One_Matching_Field --
25910 ----------------------------
25912 function Has_One_Matching_Field
return Boolean is
25916 Matching_Field
:= Empty
;
25918 if Is_Array_Type
(Expec_Type
)
25919 and then Number_Dimensions
(Expec_Type
) = 1
25920 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
25922 -- Use type name if available. This excludes multidimensional
25923 -- arrays and anonymous arrays.
25925 if Comes_From_Source
(Expec_Type
) then
25926 Matching_Field
:= Expec_Type
;
25928 -- For an assignment, use name of target
25930 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
25931 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
25933 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
25938 elsif not Is_Record_Type
(Expec_Type
) then
25942 E
:= First_Entity
(Expec_Type
);
25947 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
25948 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
25957 if not Covers
(Etype
(E
), Found_Type
) then
25960 elsif Present
(Next_Entity
(E
))
25961 and then (Ekind
(E
) = E_Component
25962 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
25967 Matching_Field
:= E
;
25971 end Has_One_Matching_Field
;
25973 -- Start of processing for Wrong_Type
25976 -- Don't output message if either type is Any_Type, or if a message
25977 -- has already been posted for this node. We need to do the latter
25978 -- check explicitly (it is ordinarily done in Errout), because we
25979 -- are using ! to force the output of the error messages.
25981 if Expec_Type
= Any_Type
25982 or else Found_Type
= Any_Type
25983 or else Error_Posted
(Expr
)
25987 -- If one of the types is a Taft-Amendment type and the other it its
25988 -- completion, it must be an illegal use of a TAT in the spec, for
25989 -- which an error was already emitted. Avoid cascaded errors.
25991 elsif Is_Incomplete_Type
(Expec_Type
)
25992 and then Has_Completion_In_Body
(Expec_Type
)
25993 and then Full_View
(Expec_Type
) = Etype
(Expr
)
25997 elsif Is_Incomplete_Type
(Etype
(Expr
))
25998 and then Has_Completion_In_Body
(Etype
(Expr
))
25999 and then Full_View
(Etype
(Expr
)) = Expec_Type
26003 -- In an instance, there is an ongoing problem with completion of
26004 -- type derived from private types. Their structure is what Gigi
26005 -- expects, but the Etype is the parent type rather than the
26006 -- derived private type itself. Do not flag error in this case. The
26007 -- private completion is an entity without a parent, like an Itype.
26008 -- Similarly, full and partial views may be incorrect in the instance.
26009 -- There is no simple way to insure that it is consistent ???
26011 -- A similar view discrepancy can happen in an inlined body, for the
26012 -- same reason: inserted body may be outside of the original package
26013 -- and only partial views are visible at the point of insertion.
26015 elsif In_Instance
or else In_Inlined_Body
then
26016 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
26018 (Has_Private_Declaration
(Expected_Type
)
26019 or else Has_Private_Declaration
(Etype
(Expr
)))
26020 and then No
(Parent
(Expected_Type
))
26024 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
26025 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
26029 elsif Is_Private_Type
(Expected_Type
)
26030 and then Present
(Full_View
(Expected_Type
))
26031 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
26035 -- Conversely, type of expression may be the private one
26037 elsif Is_Private_Type
(Base_Type
(Etype
(Expr
)))
26038 and then Full_View
(Base_Type
(Etype
(Expr
))) = Expected_Type
26044 -- An interesting special check. If the expression is parenthesized
26045 -- and its type corresponds to the type of the sole component of the
26046 -- expected record type, or to the component type of the expected one
26047 -- dimensional array type, then assume we have a bad aggregate attempt.
26049 if Nkind
(Expr
) in N_Subexpr
26050 and then Paren_Count
(Expr
) /= 0
26051 and then Has_One_Matching_Field
26053 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
26055 if Present
(Matching_Field
) then
26056 if Is_Array_Type
(Expec_Type
) then
26058 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
26061 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
26065 -- Another special check, if we are looking for a pool-specific access
26066 -- type and we found an E_Access_Attribute_Type, then we have the case
26067 -- of an Access attribute being used in a context which needs a pool-
26068 -- specific type, which is never allowed. The one extra check we make
26069 -- is that the expected designated type covers the Found_Type.
26071 elsif Is_Access_Type
(Expec_Type
)
26072 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
26073 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
26074 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
26076 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
26078 Error_Msg_N
-- CODEFIX
26079 ("result must be general access type!", Expr
);
26080 Error_Msg_NE
-- CODEFIX
26081 ("add ALL to }!", Expr
, Expec_Type
);
26083 -- Another special check, if the expected type is an integer type,
26084 -- but the expression is of type System.Address, and the parent is
26085 -- an addition or subtraction operation whose left operand is the
26086 -- expression in question and whose right operand is of an integral
26087 -- type, then this is an attempt at address arithmetic, so give
26088 -- appropriate message.
26090 elsif Is_Integer_Type
(Expec_Type
)
26091 and then Is_RTE
(Found_Type
, RE_Address
)
26092 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
26093 and then Expr
= Left_Opnd
(Parent
(Expr
))
26094 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
26097 ("address arithmetic not predefined in package System",
26100 ("\possible missing with/use of System.Storage_Elements",
26104 -- If the expected type is an anonymous access type, as for access
26105 -- parameters and discriminants, the error is on the designated types.
26107 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
26108 if Comes_From_Source
(Expec_Type
) then
26109 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
26112 ("expected an access type with designated}",
26113 Expr
, Designated_Type
(Expec_Type
));
26116 if Is_Access_Type
(Found_Type
)
26117 and then not Comes_From_Source
(Found_Type
)
26120 ("\\found an access type with designated}!",
26121 Expr
, Designated_Type
(Found_Type
));
26123 if From_Limited_With
(Found_Type
) then
26124 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
26125 Error_Msg_Qual_Level
:= 99;
26126 Error_Msg_NE
-- CODEFIX
26127 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
26128 Error_Msg_Qual_Level
:= 0;
26130 Error_Msg_NE
("found}!", Expr
, Found_Type
);
26134 -- Normal case of one type found, some other type expected
26137 -- If the names of the two types are the same, see if some number
26138 -- of levels of qualification will help. Don't try more than three
26139 -- levels, and if we get to standard, it's no use (and probably
26140 -- represents an error in the compiler) Also do not bother with
26141 -- internal scope names.
26144 Expec_Scope
: Entity_Id
;
26145 Found_Scope
: Entity_Id
;
26148 Expec_Scope
:= Expec_Type
;
26149 Found_Scope
:= Found_Type
;
26151 for Levels
in Nat
range 0 .. 3 loop
26152 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
26153 Error_Msg_Qual_Level
:= Levels
;
26157 Expec_Scope
:= Scope
(Expec_Scope
);
26158 Found_Scope
:= Scope
(Found_Scope
);
26160 exit when Expec_Scope
= Standard_Standard
26161 or else Found_Scope
= Standard_Standard
26162 or else not Comes_From_Source
(Expec_Scope
)
26163 or else not Comes_From_Source
(Found_Scope
);
26167 if Is_Record_Type
(Expec_Type
)
26168 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
26170 Error_Msg_NE
("expected}!", Expr
,
26171 Corresponding_Remote_Type
(Expec_Type
));
26173 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
26176 if Is_Entity_Name
(Expr
)
26177 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
26179 Error_Msg_N
("\\found package name!", Expr
);
26181 elsif Is_Entity_Name
(Expr
)
26182 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
26184 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
26186 ("found procedure name, possibly missing Access attribute!",
26190 ("\\found procedure name instead of function!", Expr
);
26193 elsif Nkind
(Expr
) = N_Function_Call
26194 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
26195 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
26196 and then No
(Parameter_Associations
(Expr
))
26199 ("found function name, possibly missing Access attribute!",
26202 -- Catch common error: a prefix or infix operator which is not
26203 -- directly visible because the type isn't.
26205 elsif Nkind
(Expr
) in N_Op
26206 and then Is_Overloaded
(Expr
)
26207 and then not Is_Immediately_Visible
(Expec_Type
)
26208 and then not Is_Potentially_Use_Visible
(Expec_Type
)
26209 and then not In_Use
(Expec_Type
)
26210 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
26213 ("operator of the type is not directly visible!", Expr
);
26215 elsif Ekind
(Found_Type
) = E_Void
26216 and then Present
(Parent
(Found_Type
))
26217 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
26219 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
26222 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
26225 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
26226 -- of the same modular type, and (M1 and M2) = 0 was intended.
26228 if Expec_Type
= Standard_Boolean
26229 and then Is_Modular_Integer_Type
(Found_Type
)
26230 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
26231 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
26234 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
26235 L
: constant Node_Id
:= Left_Opnd
(Op
);
26236 R
: constant Node_Id
:= Right_Opnd
(Op
);
26239 -- The case for the message is when the left operand of the
26240 -- comparison is the same modular type, or when it is an
26241 -- integer literal (or other universal integer expression),
26242 -- which would have been typed as the modular type if the
26243 -- parens had been there.
26245 if (Etype
(L
) = Found_Type
26247 Etype
(L
) = Universal_Integer
)
26248 and then Is_Integer_Type
(Etype
(R
))
26251 ("\\possible missing parens for modular operation", Expr
);
26256 -- Reset error message qualification indication
26258 Error_Msg_Qual_Level
:= 0;
26262 --------------------------------
26263 -- Yields_Synchronized_Object --
26264 --------------------------------
26266 function Yields_Synchronized_Object
(Typ
: Entity_Id
) return Boolean is
26267 Has_Sync_Comp
: Boolean := False;
26271 -- An array type yields a synchronized object if its component type
26272 -- yields a synchronized object.
26274 if Is_Array_Type
(Typ
) then
26275 return Yields_Synchronized_Object
(Component_Type
(Typ
));
26277 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
26278 -- yields a synchronized object by default.
26280 elsif Is_Descendant_Of_Suspension_Object
(Typ
) then
26283 -- A protected type yields a synchronized object by default
26285 elsif Is_Protected_Type
(Typ
) then
26288 -- A record type or type extension yields a synchronized object when its
26289 -- discriminants (if any) lack default values and all components are of
26290 -- a type that yelds a synchronized object.
26292 elsif Is_Record_Type
(Typ
) then
26294 -- Inspect all entities defined in the scope of the type, looking for
26295 -- components of a type that does not yeld a synchronized object or
26296 -- for discriminants with default values.
26298 Id
:= First_Entity
(Typ
);
26299 while Present
(Id
) loop
26300 if Comes_From_Source
(Id
) then
26301 if Ekind
(Id
) = E_Component
then
26302 if Yields_Synchronized_Object
(Etype
(Id
)) then
26303 Has_Sync_Comp
:= True;
26305 -- The component does not yield a synchronized object
26311 elsif Ekind
(Id
) = E_Discriminant
26312 and then Present
(Expression
(Parent
(Id
)))
26321 -- Ensure that the parent type of a type extension yields a
26322 -- synchronized object.
26324 if Etype
(Typ
) /= Typ
26325 and then not Yields_Synchronized_Object
(Etype
(Typ
))
26330 -- If we get here, then all discriminants lack default values and all
26331 -- components are of a type that yields a synchronized object.
26333 return Has_Sync_Comp
;
26335 -- A synchronized interface type yields a synchronized object by default
26337 elsif Is_Synchronized_Interface
(Typ
) then
26340 -- A task type yelds a synchronized object by default
26342 elsif Is_Task_Type
(Typ
) then
26345 -- Otherwise the type does not yield a synchronized object
26350 end Yields_Synchronized_Object
;
26352 ---------------------------
26353 -- Yields_Universal_Type --
26354 ---------------------------
26356 function Yields_Universal_Type
(N
: Node_Id
) return Boolean is
26358 -- Integer and real literals are of a universal type
26360 if Nkind_In
(N
, N_Integer_Literal
, N_Real_Literal
) then
26363 -- The values of certain attributes are of a universal type
26365 elsif Nkind
(N
) = N_Attribute_Reference
then
26367 Universal_Type_Attribute
(Get_Attribute_Id
(Attribute_Name
(N
)));
26369 -- ??? There are possibly other cases to consider
26374 end Yields_Universal_Type
;
26377 Erroutc
.Subprogram_Name_Ptr
:= Subprogram_Name
'Access;