1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
27 with Casing
; use Casing
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
.Utils
; use Einfo
.Utils
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Erroutc
; use Erroutc
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Ch11
; use Exp_Ch11
;
36 with Exp_Util
; use Exp_Util
;
37 with Fname
; use Fname
;
38 with Freeze
; use Freeze
;
39 with Itypes
; use Itypes
;
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_Cat
; use Sem_Cat
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch8
; use Sem_Ch8
;
55 with Sem_Ch13
; use Sem_Ch13
;
56 with Sem_Disp
; use Sem_Disp
;
57 with Sem_Elab
; use Sem_Elab
;
58 with Sem_Eval
; use Sem_Eval
;
59 with Sem_Prag
; use Sem_Prag
;
60 with Sem_Res
; use Sem_Res
;
61 with Sem_Warn
; use Sem_Warn
;
62 with Sem_Type
; use Sem_Type
;
63 with Sinfo
; use Sinfo
;
64 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
65 with Sinfo
.Utils
; use Sinfo
.Utils
;
66 with Sinput
; use Sinput
;
67 with Stand
; use Stand
;
69 with Stringt
; use Stringt
;
70 with Targparm
; use Targparm
;
71 with Tbuild
; use Tbuild
;
72 with Ttypes
; use Ttypes
;
73 with Uname
; use Uname
;
74 with Warnsw
; use Warnsw
;
76 with GNAT
.Heap_Sort_G
;
77 with GNAT
.HTable
; use GNAT
.HTable
;
79 package body Sem_Util
is
81 ---------------------------
82 -- Local Data Structures --
83 ---------------------------
85 Invalid_Binder_Values
: array (Scalar_Id
) of Entity_Id
:= (others => Empty
);
86 -- A collection to hold the entities of the variables declared in package
87 -- System.Scalar_Values which describe the invalid values of scalar types.
89 Invalid_Binder_Values_Set
: Boolean := False;
90 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
92 Invalid_Floats
: array (Float_Scalar_Id
) of Ureal
:= (others => No_Ureal
);
93 -- A collection to hold the invalid values of float types as specified by
94 -- pragma Initialize_Scalars.
96 Invalid_Integers
: array (Integer_Scalar_Id
) of Uint
:= (others => No_Uint
);
97 -- A collection to hold the invalid values of integer types as specified
98 -- by pragma Initialize_Scalars.
100 -----------------------
101 -- Local Subprograms --
102 -----------------------
104 function Build_Component_Subtype
107 T
: Entity_Id
) return Node_Id
;
108 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
109 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
110 -- Loc is the source location, T is the original subtype.
112 procedure Examine_Array_Bounds
114 All_Static
: out Boolean;
115 Has_Empty
: out Boolean);
116 -- Inspect the index constraints of array type Typ. Flag All_Static is set
117 -- when all ranges are static. Flag Has_Empty is set only when All_Static
118 -- is set and indicates that at least one range is empty.
120 function Has_Enabled_Property
121 (Item_Id
: Entity_Id
;
122 Property
: Name_Id
) return Boolean;
123 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
124 -- Determine whether the state abstraction, object, or type denoted by
125 -- entity Item_Id has enabled property Property.
127 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
128 -- T is a derived tagged type. Check whether the type extension is null.
129 -- If the parent type is fully initialized, T can be treated as such.
131 function Is_Atomic_Object_Entity
(Id
: Entity_Id
) return Boolean;
132 -- Determine whether arbitrary entity Id denotes an atomic object as per
136 with function Is_Effectively_Volatile_Entity
137 (Id
: Entity_Id
) return Boolean;
138 -- Function to use on object and type entities
139 function Is_Effectively_Volatile_Object_Shared
140 (N
: Node_Id
) return Boolean;
141 -- Shared function used to detect effectively volatile objects and
142 -- effectively volatile objects for reading.
144 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
145 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
146 -- with discriminants whose default values are static, examine only the
147 -- components in the selected variant to determine whether all of them
150 function Is_Preelaborable_Function
(Id
: Entity_Id
) return Boolean;
151 -- Ada 2022: Determine whether the specified function is suitable as the
152 -- name of a call in a preelaborable construct (RM 10.2.1(7/5)).
154 type Null_Status_Kind
is
156 -- This value indicates that a subexpression is known to have a null
157 -- value at compile time.
160 -- This value indicates that a subexpression is known to have a non-null
161 -- value at compile time.
164 -- This value indicates that it cannot be determined at compile time
165 -- whether a subexpression yields a null or non-null value.
167 function Null_Status
(N
: Node_Id
) return Null_Status_Kind
;
168 -- Determine whether subexpression N of an access type yields a null value,
169 -- a non-null value, or the value cannot be determined at compile time. The
170 -- routine does not take simple flow diagnostics into account, it relies on
171 -- static facts such as the presence of null exclusions.
173 function Subprogram_Name
(N
: Node_Id
) return String;
174 -- Return the fully qualified name of the enclosing subprogram for the
175 -- given node N, with file:line:col information appended, e.g.
176 -- "subp:file:line:col", corresponding to the source location of the
177 -- body of the subprogram.
179 -----------------------------
180 -- Abstract_Interface_List --
181 -----------------------------
183 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
187 if Is_Concurrent_Type
(Typ
) then
189 -- If we are dealing with a synchronized subtype, go to the base
190 -- type, whose declaration has the interface list.
192 Nod
:= Declaration_Node
(Base_Type
(Typ
));
194 if Nkind
(Nod
) in N_Full_Type_Declaration | N_Private_Type_Declaration
199 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
200 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
201 Nod
:= Type_Definition
(Parent
(Typ
));
203 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
204 if Present
(Full_View
(Typ
))
206 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
208 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
210 -- If the full-view is not available we cannot do anything else
211 -- here (the source has errors).
217 -- Support for generic formals with interfaces is still missing ???
219 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
224 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
228 elsif Ekind
(Typ
) = E_Record_Subtype
then
229 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
231 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
233 -- Recurse, because parent may still be a private extension. Also
234 -- note that the full view of the subtype or the full view of its
235 -- base type may (both) be unavailable.
237 return Abstract_Interface_List
(Etype
(Typ
));
239 elsif Ekind
(Typ
) = E_Record_Type
then
240 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
241 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
243 Nod
:= Type_Definition
(Parent
(Typ
));
246 -- Otherwise the type is of a kind which does not implement interfaces
252 return Interface_List
(Nod
);
253 end Abstract_Interface_List
;
255 ----------------------------------
256 -- Acquire_Warning_Match_String --
257 ----------------------------------
259 function Acquire_Warning_Match_String
(Str_Lit
: Node_Id
) return String is
260 S
: constant String := To_String
(Strval
(Str_Lit
));
265 -- Put "*" before or after or both, if it's not already there
268 F
: constant Boolean := S
(S
'First) = '*';
269 L
: constant Boolean := S
(S
'Last) = '*';
281 return "*" & S
& "*";
286 end Acquire_Warning_Match_String
;
288 --------------------------------
289 -- Add_Access_Type_To_Process --
290 --------------------------------
292 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
296 Ensure_Freeze_Node
(E
);
297 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
301 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
305 end Add_Access_Type_To_Process
;
307 --------------------------
308 -- Add_Block_Identifier --
309 --------------------------
311 procedure Add_Block_Identifier
314 Scope
: Entity_Id
:= Current_Scope
)
316 Loc
: constant Source_Ptr
:= Sloc
(N
);
319 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
321 -- The block already has a label, return its entity
323 if Present
(Identifier
(N
)) then
324 Id
:= Entity
(Identifier
(N
));
326 -- Create a new block label and set its attributes
329 Id
:= New_Internal_Entity
(E_Block
, Scope
, Loc
, 'B');
330 Set_Etype
(Id
, Standard_Void_Type
);
332 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
333 Set_Block_Node
(Id
, Identifier
(N
));
335 end Add_Block_Identifier
;
337 ----------------------------
338 -- Add_Global_Declaration --
339 ----------------------------
341 procedure Add_Global_Declaration
(N
: Node_Id
) is
342 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
345 if No
(Declarations
(Aux_Node
)) then
346 Set_Declarations
(Aux_Node
, New_List
);
349 Append_To
(Declarations
(Aux_Node
), N
);
351 end Add_Global_Declaration
;
353 --------------------------------
354 -- Address_Integer_Convert_OK --
355 --------------------------------
357 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
359 if Allow_Integer_Address
360 and then ((Is_Descendant_Of_Address
(T1
)
361 and then Is_Private_Type
(T1
)
362 and then Is_Integer_Type
(T2
))
364 (Is_Descendant_Of_Address
(T2
)
365 and then Is_Private_Type
(T2
)
366 and then Is_Integer_Type
(T1
)))
372 end Address_Integer_Convert_OK
;
378 function Address_Value
(N
: Node_Id
) return Node_Id
is
383 -- For constant, get constant expression
385 if Is_Entity_Name
(Expr
)
386 and then Ekind
(Entity
(Expr
)) = E_Constant
388 Expr
:= Constant_Value
(Entity
(Expr
));
390 -- For unchecked conversion, get result to convert
392 elsif Nkind
(Expr
) = N_Unchecked_Type_Conversion
then
393 Expr
:= Expression
(Expr
);
395 -- For (common case) of To_Address call, get argument
397 elsif Nkind
(Expr
) = N_Function_Call
398 and then Is_Entity_Name
(Name
(Expr
))
399 and then Is_RTE
(Entity
(Name
(Expr
)), RE_To_Address
)
401 Expr
:= First_Actual
(Expr
);
403 -- We finally have the real expression
417 function Addressable
(V
: Uint
) return Boolean is
423 return V
= Uint_8
or else
427 (V
= Uint_128
and then System_Max_Integer_Size
= 128);
430 function Addressable
(V
: Int
) return Boolean is
436 V
= System_Max_Integer_Size
;
439 ---------------------------------
440 -- Aggregate_Constraint_Checks --
441 ---------------------------------
443 procedure Aggregate_Constraint_Checks
445 Check_Typ
: Entity_Id
)
447 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
450 if Raises_Constraint_Error
(Exp
) then
454 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
455 -- component's type to force the appropriate accessibility checks.
457 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
458 -- force the corresponding run-time check
460 if Is_Access_Type
(Check_Typ
)
461 and then Is_Local_Anonymous_Access
(Check_Typ
)
463 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
464 Analyze_And_Resolve
(Exp
, Check_Typ
);
465 Check_Unset_Reference
(Exp
);
468 -- What follows is really expansion activity, so check that expansion
469 -- is on and is allowed. In GNATprove mode, we also want check flags to
470 -- be added in the tree, so that the formal verification can rely on
471 -- those to be present. In GNATprove mode for formal verification, some
472 -- treatment typically only done during expansion needs to be performed
473 -- on the tree, but it should not be applied inside generics. Otherwise,
474 -- this breaks the name resolution mechanism for generic instances.
476 if not Expander_Active
477 and not (GNATprove_Mode
and not Inside_A_Generic
)
482 if Is_Access_Type
(Check_Typ
)
483 and then Can_Never_Be_Null
(Check_Typ
)
484 and then not Can_Never_Be_Null
(Exp_Typ
)
486 Install_Null_Excluding_Check
(Exp
);
489 -- First check if we have to insert discriminant checks
491 if Has_Discriminants
(Exp_Typ
) then
492 Apply_Discriminant_Check
(Exp
, Check_Typ
);
494 -- Next emit length checks for array aggregates
496 elsif Is_Array_Type
(Exp_Typ
) then
497 Apply_Length_Check
(Exp
, Check_Typ
);
499 -- Finally emit scalar and string checks. If we are dealing with a
500 -- scalar literal we need to check by hand because the Etype of
501 -- literals is not necessarily correct.
503 elsif Is_Scalar_Type
(Exp_Typ
)
504 and then Compile_Time_Known_Value
(Exp
)
506 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
507 Apply_Compile_Time_Constraint_Error
508 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
509 Ent
=> Base_Type
(Check_Typ
),
510 Typ
=> Base_Type
(Check_Typ
));
512 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
513 Apply_Compile_Time_Constraint_Error
514 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
518 elsif not Range_Checks_Suppressed
(Check_Typ
) then
519 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
522 -- Verify that target type is also scalar, to prevent view anomalies
523 -- in instantiations.
525 elsif (Is_Scalar_Type
(Exp_Typ
)
526 or else Nkind
(Exp
) = N_String_Literal
)
527 and then Is_Scalar_Type
(Check_Typ
)
528 and then Exp_Typ
/= Check_Typ
530 -- If expression is a constant, it is worthwhile checking whether it
531 -- is a bound of the type.
533 if Is_Entity_Name
(Exp
)
534 and then Ekind
(Entity
(Exp
)) = E_Constant
536 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
537 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
539 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
540 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
546 -- Change Exp into Check_Typ'(Exp) to ensure that range checks are
547 -- performed at run time.
549 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
550 Analyze_And_Resolve
(Exp
, Check_Typ
);
551 Check_Unset_Reference
(Exp
);
554 end Aggregate_Constraint_Checks
;
556 -----------------------
557 -- Alignment_In_Bits --
558 -----------------------
560 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
562 return Alignment
(E
) * System_Storage_Unit
;
563 end Alignment_In_Bits
;
565 --------------------------------------
566 -- All_Composite_Constraints_Static --
567 --------------------------------------
569 function All_Composite_Constraints_Static
570 (Constr
: Node_Id
) return Boolean
573 if No
(Constr
) or else Error_Posted
(Constr
) then
577 case Nkind
(Constr
) is
579 if Nkind
(Constr
) in N_Has_Entity
580 and then Present
(Entity
(Constr
))
582 if Is_Type
(Entity
(Constr
)) then
584 not Is_Discrete_Type
(Entity
(Constr
))
585 or else Is_OK_Static_Subtype
(Entity
(Constr
));
588 elsif Nkind
(Constr
) = N_Range
then
590 Is_OK_Static_Expression
(Low_Bound
(Constr
))
592 Is_OK_Static_Expression
(High_Bound
(Constr
));
594 elsif Nkind
(Constr
) = N_Attribute_Reference
595 and then Attribute_Name
(Constr
) = Name_Range
598 Is_OK_Static_Expression
599 (Type_Low_Bound
(Etype
(Prefix
(Constr
))))
601 Is_OK_Static_Expression
602 (Type_High_Bound
(Etype
(Prefix
(Constr
))));
606 No
(Etype
(Constr
)) -- previous error
607 or else not Is_Discrete_Type
(Etype
(Constr
))
608 or else Is_OK_Static_Expression
(Constr
);
610 when N_Discriminant_Association
=>
611 return All_Composite_Constraints_Static
(Expression
(Constr
));
613 when N_Range_Constraint
=>
615 All_Composite_Constraints_Static
(Range_Expression
(Constr
));
617 when N_Index_Or_Discriminant_Constraint
=>
619 One_Cstr
: Entity_Id
;
621 One_Cstr
:= First
(Constraints
(Constr
));
622 while Present
(One_Cstr
) loop
623 if not All_Composite_Constraints_Static
(One_Cstr
) then
633 when N_Subtype_Indication
=>
635 All_Composite_Constraints_Static
(Subtype_Mark
(Constr
))
637 All_Composite_Constraints_Static
(Constraint
(Constr
));
642 end All_Composite_Constraints_Static
;
644 ------------------------
645 -- Append_Entity_Name --
646 ------------------------
648 procedure Append_Entity_Name
(Buf
: in out Bounded_String
; E
: Entity_Id
) is
649 Temp
: Bounded_String
;
651 procedure Inner
(E
: Entity_Id
);
652 -- Inner recursive routine, keep outer routine nonrecursive to ease
653 -- debugging when we get strange results from this routine.
659 procedure Inner
(E
: Entity_Id
) is
663 -- If entity has an internal name, skip by it, and print its scope.
664 -- Note that we strip a final R from the name before the test; this
665 -- is needed for some cases of instantiations.
668 E_Name
: Bounded_String
;
671 Append
(E_Name
, Chars
(E
));
673 if E_Name
.Chars
(E_Name
.Length
) = 'R' then
674 E_Name
.Length
:= E_Name
.Length
- 1;
677 if Is_Internal_Name
(E_Name
) then
685 -- Just print entity name if its scope is at the outer level
687 if Scop
= Standard_Standard
then
690 -- If scope comes from source, write scope and entity
692 elsif Comes_From_Source
(Scop
) then
693 Append_Entity_Name
(Temp
, Scop
);
696 -- If in wrapper package skip past it
698 elsif Present
(Scop
) and then Is_Wrapper_Package
(Scop
) then
699 Append_Entity_Name
(Temp
, Scope
(Scop
));
702 -- Otherwise nothing to output (happens in unnamed block statements)
711 E_Name
: Bounded_String
;
714 Append_Unqualified_Decoded
(E_Name
, Chars
(E
));
716 -- Remove trailing upper-case letters from the name (useful for
717 -- dealing with some cases of internal names generated in the case
718 -- of references from within a generic).
720 while E_Name
.Length
> 1
721 and then E_Name
.Chars
(E_Name
.Length
) in 'A' .. 'Z'
723 E_Name
.Length
:= E_Name
.Length
- 1;
726 -- Adjust casing appropriately (gets name from source if possible)
728 Adjust_Name_Case
(E_Name
, Sloc
(E
));
729 Append
(Temp
, E_Name
);
733 -- Start of processing for Append_Entity_Name
738 end Append_Entity_Name
;
740 ---------------------------------
741 -- Append_Inherited_Subprogram --
742 ---------------------------------
744 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
745 Par
: constant Entity_Id
:= Alias
(S
);
746 -- The parent subprogram
748 Scop
: constant Entity_Id
:= Scope
(Par
);
749 -- The scope of definition of the parent subprogram
751 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
752 -- The derived type of which S is a primitive operation
758 if Ekind
(Current_Scope
) = E_Package
759 and then In_Private_Part
(Current_Scope
)
760 and then Has_Private_Declaration
(Typ
)
761 and then Is_Tagged_Type
(Typ
)
762 and then Scop
= Current_Scope
764 -- The inherited operation is available at the earliest place after
765 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
766 -- relevant for type extensions. If the parent operation appears
767 -- after the type extension, the operation is not visible.
770 (Visible_Declarations
771 (Package_Specification
(Current_Scope
)));
772 while Present
(Decl
) loop
773 if Nkind
(Decl
) = N_Private_Extension_Declaration
774 and then Defining_Entity
(Decl
) = Typ
776 if Sloc
(Decl
) > Sloc
(Par
) then
777 Next_E
:= Next_Entity
(Par
);
778 Link_Entities
(Par
, S
);
779 Link_Entities
(S
, Next_E
);
791 -- If partial view is not a type extension, or it appears before the
792 -- subprogram declaration, insert normally at end of entity list.
794 Append_Entity
(S
, Current_Scope
);
795 end Append_Inherited_Subprogram
;
797 -----------------------------------------
798 -- Apply_Compile_Time_Constraint_Error --
799 -----------------------------------------
801 procedure Apply_Compile_Time_Constraint_Error
804 Reason
: RT_Exception_Code
;
805 Ent
: Entity_Id
:= Empty
;
806 Typ
: Entity_Id
:= Empty
;
807 Loc
: Source_Ptr
:= No_Location
;
808 Warn
: Boolean := False;
809 Emit_Message
: Boolean := True)
811 Stat
: constant Boolean := Is_Static_Expression
(N
);
812 R_Stat
: constant Node_Id
:=
813 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
825 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
828 -- Now we replace the node by an N_Raise_Constraint_Error node
829 -- This does not need reanalyzing, so set it as analyzed now.
832 Set_Analyzed
(N
, True);
835 Set_Raises_Constraint_Error
(N
);
837 -- Now deal with possible local raise handling
839 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
841 -- If the original expression was marked as static, the result is
842 -- still marked as static, but the Raises_Constraint_Error flag is
843 -- always set so that further static evaluation is not attempted.
846 Set_Is_Static_Expression
(N
);
848 end Apply_Compile_Time_Constraint_Error
;
850 ---------------------------
851 -- Async_Readers_Enabled --
852 ---------------------------
854 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
856 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
857 end Async_Readers_Enabled
;
859 ---------------------------
860 -- Async_Writers_Enabled --
861 ---------------------------
863 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
865 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
866 end Async_Writers_Enabled
;
868 --------------------------------------
869 -- Available_Full_View_Of_Component --
870 --------------------------------------
872 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
873 ST
: constant Entity_Id
:= Scope
(T
);
874 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
876 return In_Open_Scopes
(ST
)
877 and then In_Open_Scopes
(SCT
)
878 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
879 end Available_Full_View_Of_Component
;
888 Warn
: Boolean := False)
891 Error_Msg_Warn
:= Warn
;
892 Error_Msg_N
("<<& is not a valid aspect identifier", N
);
894 -- Check bad spelling
895 Error_Msg_Name_1
:= Aspect_Spell_Check
(Nam
);
896 if Error_Msg_Name_1
/= No_Name
then
897 Error_Msg_N
-- CODEFIX
898 ("\<<possible misspelling of %", N
);
906 procedure Bad_Attribute
909 Warn
: Boolean := False)
912 Error_Msg_Warn
:= Warn
;
913 Error_Msg_N
("<<unrecognized attribute&", N
);
915 -- Check for possible misspelling
917 Error_Msg_Name_1
:= Attribute_Spell_Check
(Nam
);
918 if Error_Msg_Name_1
/= No_Name
then
919 Error_Msg_N
-- CODEFIX
920 ("\<<possible misspelling of %", N
);
924 --------------------------------
925 -- Bad_Predicated_Subtype_Use --
926 --------------------------------
928 procedure Bad_Predicated_Subtype_Use
932 Suggest_Static
: Boolean := False)
937 -- Avoid cascaded errors
939 if Error_Posted
(N
) then
943 if Inside_A_Generic
then
944 Gen
:= Current_Scope
;
945 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
953 if Is_Generic_Formal
(Typ
) and then Is_Discrete_Type
(Typ
) then
954 Set_No_Predicate_On_Actual
(Typ
);
957 elsif Has_Predicates
(Typ
) then
958 if Is_Generic_Actual_Type
(Typ
) then
960 -- The restriction on loop parameters is only that the type
961 -- should only have static predicates.
963 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
964 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
965 and then not Has_Ghost_Predicate_Aspect
(Typ
)
966 and then Is_OK_Static_Subtype
(Typ
)
971 Gen
:= Current_Scope
;
972 while not Is_Generic_Instance
(Gen
) loop
976 pragma Assert
(Present
(Gen
));
978 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
979 Error_Msg_Warn
:= SPARK_Mode
/= On
;
980 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
981 Error_Msg_F
("\Program_Error [<<", N
);
984 Make_Raise_Program_Error
(Sloc
(N
),
985 Reason
=> PE_Bad_Predicated_Generic_Type
));
988 Error_Msg_FE
(Msg
, N
, Typ
);
992 Error_Msg_FE
(Msg
, N
, Typ
);
995 -- Suggest to use First_Valid/Last_Valid instead of First/Last/Range
996 -- if the predicate is static.
998 if not Has_Dynamic_Predicate_Aspect
(Typ
)
999 and then not Has_Ghost_Predicate_Aspect
(Typ
)
1000 and then Has_Static_Predicate
(Typ
)
1001 and then Nkind
(N
) = N_Attribute_Reference
1004 Aname
: constant Name_Id
:= Attribute_Name
(N
);
1005 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
1008 when Attribute_First
=>
1009 Error_Msg_F
("\use attribute First_Valid instead", N
);
1010 when Attribute_Last
=>
1011 Error_Msg_F
("\use attribute Last_Valid instead", N
);
1012 when Attribute_Range
=>
1013 Error_Msg_F
("\use attributes First_Valid and "
1014 & "Last_Valid instead", N
);
1021 -- Emit an optional suggestion on how to remedy the error if the
1022 -- context warrants it.
1024 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
1025 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
1028 end Bad_Predicated_Subtype_Use
;
1030 -----------------------------------------
1031 -- Bad_Unordered_Enumeration_Reference --
1032 -----------------------------------------
1034 function Bad_Unordered_Enumeration_Reference
1036 T
: Entity_Id
) return Boolean
1039 return Is_Enumeration_Type
(T
)
1040 and then Warn_On_Unordered_Enumeration_Type
1041 and then not Is_Generic_Type
(T
)
1042 and then Comes_From_Source
(N
)
1043 and then not Has_Pragma_Ordered
(T
)
1044 and then not In_Same_Extended_Unit
(N
, T
);
1045 end Bad_Unordered_Enumeration_Reference
;
1047 ----------------------------
1048 -- Begin_Keyword_Location --
1049 ----------------------------
1051 function Begin_Keyword_Location
(N
: Node_Id
) return Source_Ptr
is
1063 HSS
:= Handled_Statement_Sequence
(N
);
1065 -- When the handled sequence of statements comes from source, the
1066 -- location of the "begin" keyword is that of the sequence itself.
1067 -- Note that an internal construct may inherit a source sequence.
1069 if Comes_From_Source
(HSS
) then
1072 -- The parser generates an internal handled sequence of statements to
1073 -- capture the location of the "begin" keyword if present in the source.
1074 -- Since there are no source statements, the location of the "begin"
1075 -- keyword is effectively that of the "end" keyword.
1077 elsif Comes_From_Source
(N
) then
1080 -- Otherwise the construct is internal and should carry the location of
1081 -- the original construct which prompted its creation.
1086 end Begin_Keyword_Location
;
1088 --------------------------
1089 -- Build_Actual_Subtype --
1090 --------------------------
1092 function Build_Actual_Subtype
1094 N
: Node_Or_Entity_Id
) return Node_Id
1097 -- Normally Sloc (N), but may point to corresponding body in some cases
1099 Constraints
: List_Id
;
1105 Disc_Type
: Entity_Id
;
1112 if Nkind
(N
) = N_Defining_Identifier
then
1113 Obj
:= New_Occurrence_Of
(N
, Loc
);
1115 -- If this is a formal parameter of a subprogram declaration, and
1116 -- we are compiling the body, we want the declaration for the
1117 -- actual subtype to carry the source position of the body, to
1118 -- prevent anomalies in gdb when stepping through the code.
1120 if Is_Formal
(N
) then
1122 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
1124 if Nkind
(Decl
) = N_Subprogram_Declaration
1125 and then Present
(Corresponding_Body
(Decl
))
1127 Loc
:= Sloc
(Corresponding_Body
(Decl
));
1136 if Is_Array_Type
(T
) then
1137 Constraints
:= New_List
;
1138 Index
:= First_Index
(T
);
1140 for J
in 1 .. Number_Dimensions
(T
) loop
1142 -- Build an array subtype declaration with the nominal subtype and
1143 -- the bounds of the actual. Add the declaration in front of the
1144 -- local declarations for the subprogram, for analysis before any
1145 -- reference to the formal in the body.
1147 -- If this is for an index with a fixed lower bound, then use
1148 -- the fixed lower bound as the lower bound of the actual
1149 -- subtype's corresponding index.
1151 if not Is_Constrained
(T
)
1152 and then Is_Fixed_Lower_Bound_Index_Subtype
(Etype
(Index
))
1154 Lo
:= New_Copy_Tree
(Type_Low_Bound
(Etype
(Index
)));
1158 Make_Attribute_Reference
(Loc
,
1160 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
1161 Attribute_Name
=> Name_First
,
1162 Expressions
=> New_List
(
1163 Make_Integer_Literal
(Loc
, J
)));
1167 Make_Attribute_Reference
(Loc
,
1169 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
1170 Attribute_Name
=> Name_Last
,
1171 Expressions
=> New_List
(
1172 Make_Integer_Literal
(Loc
, J
)));
1174 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1179 -- If the type has unknown discriminants there is no constrained
1180 -- subtype to build. This is never called for a formal or for a
1181 -- lhs, so returning the type is ok ???
1183 elsif Has_Unknown_Discriminants
(T
) then
1187 Constraints
:= New_List
;
1189 -- Type T is a generic derived type, inherit the discriminants from
1192 if Is_Private_Type
(T
)
1193 and then No
(Full_View
(T
))
1195 -- T was flagged as an error if it was declared as a formal
1196 -- derived type with known discriminants. In this case there
1197 -- is no need to look at the parent type since T already carries
1198 -- its own discriminants.
1200 and then not Error_Posted
(T
)
1202 Disc_Type
:= Etype
(Base_Type
(T
));
1207 Discr
:= First_Discriminant
(Disc_Type
);
1208 while Present
(Discr
) loop
1209 Append_To
(Constraints
,
1210 Make_Selected_Component
(Loc
,
1212 Duplicate_Subexpr_No_Checks
(Obj
),
1213 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
1214 Next_Discriminant
(Discr
);
1218 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
1219 Set_Is_Internal
(Subt
);
1222 Make_Subtype_Declaration
(Loc
,
1223 Defining_Identifier
=> Subt
,
1224 Subtype_Indication
=>
1225 Make_Subtype_Indication
(Loc
,
1226 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
1228 Make_Index_Or_Discriminant_Constraint
(Loc
,
1229 Constraints
=> Constraints
)));
1231 Mark_Rewrite_Insertion
(Decl
);
1233 end Build_Actual_Subtype
;
1235 ---------------------------------------
1236 -- Build_Actual_Subtype_Of_Component --
1237 ---------------------------------------
1239 function Build_Actual_Subtype_Of_Component
1241 N
: Node_Id
) return Node_Id
1243 Loc
: constant Source_Ptr
:= Sloc
(N
);
1244 P
: constant Node_Id
:= Prefix
(N
);
1248 Index_Typ
: Entity_Id
;
1249 Sel
: Entity_Id
:= Empty
;
1251 Desig_Typ
: Entity_Id
;
1252 -- This is either a copy of T, or if T is an access type, then it is
1253 -- the directly designated type of this access type.
1255 function Build_Access_Record_Constraint
(C
: List_Id
) return List_Id
;
1256 -- If the record component is a constrained access to the current
1257 -- record, the subtype has not been constructed during analysis of
1258 -- the enclosing record type (see Analyze_Access). In that case, build
1259 -- a constrained access subtype after replacing references to the
1260 -- enclosing discriminants with the corresponding discriminant values
1263 function Build_Actual_Array_Constraint
return List_Id
;
1264 -- If one or more of the bounds of the component depends on
1265 -- discriminants, build actual constraint using the discriminants
1266 -- of the prefix, as above.
1268 function Build_Actual_Record_Constraint
return List_Id
;
1269 -- Similar to previous one, for discriminated components constrained
1270 -- by the discriminant of the enclosing object.
1272 function Build_Discriminant_Reference
1273 (Discrim_Name
: Node_Id
; Obj
: Node_Id
:= P
) return Node_Id
;
1274 -- Build a reference to the discriminant denoted by Discrim_Name.
1275 -- The prefix of the result is usually Obj, but it could be
1276 -- a prefix of Obj in some corner cases.
1278 function Copy_And_Maybe_Dereference
(N
: Node_Id
) return Node_Id
;
1279 -- Copy the subtree rooted at N and insert an explicit dereference if it
1280 -- is of an access type.
1282 -----------------------------------
1283 -- Build_Actual_Array_Constraint --
1284 -----------------------------------
1286 function Build_Actual_Array_Constraint
return List_Id
is
1287 Constraints
: constant List_Id
:= New_List
;
1295 Indx
:= First_Index
(Desig_Typ
);
1296 while Present
(Indx
) loop
1297 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1298 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1300 if Denotes_Discriminant
(Old_Lo
) then
1301 Lo
:= Build_Discriminant_Reference
(Old_Lo
);
1303 Lo
:= New_Copy_Tree
(Old_Lo
);
1305 -- The new bound will be reanalyzed in the enclosing
1306 -- declaration. For literal bounds that come from a type
1307 -- declaration, the type of the context must be imposed, so
1308 -- insure that analysis will take place. For non-universal
1309 -- types this is not strictly necessary.
1311 Set_Analyzed
(Lo
, False);
1314 if Denotes_Discriminant
(Old_Hi
) then
1315 Hi
:= Build_Discriminant_Reference
(Old_Hi
);
1317 Hi
:= New_Copy_Tree
(Old_Hi
);
1318 Set_Analyzed
(Hi
, False);
1321 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1326 end Build_Actual_Array_Constraint
;
1328 ------------------------------------
1329 -- Build_Actual_Record_Constraint --
1330 ------------------------------------
1332 function Build_Actual_Record_Constraint
return List_Id
is
1333 Constraints
: constant List_Id
:= New_List
;
1338 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1339 while Present
(D
) loop
1340 if Denotes_Discriminant
(Node
(D
)) then
1341 D_Val
:= Build_Discriminant_Reference
(Node
(D
));
1343 D_Val
:= New_Copy_Tree
(Node
(D
));
1346 Append
(D_Val
, Constraints
);
1351 end Build_Actual_Record_Constraint
;
1353 ----------------------------------
1354 -- Build_Discriminant_Reference --
1355 ----------------------------------
1357 function Build_Discriminant_Reference
1358 (Discrim_Name
: Node_Id
; Obj
: Node_Id
:= P
) return Node_Id
1360 Discrim
: constant Entity_Id
:= Entity
(Discrim_Name
);
1362 function Obj_Is_Good_Prefix
return Boolean;
1363 -- Returns True if Obj.Discrim makes sense; that is, if
1364 -- Obj has Discrim as one of its discriminants (or is an
1365 -- access value that designates such an object).
1367 ------------------------
1368 -- Obj_Is_Good_Prefix --
1369 ------------------------
1371 function Obj_Is_Good_Prefix
return Boolean is
1372 Obj_Type
: Entity_Id
:=
1373 Implementation_Base_Type
(Etype
(Obj
));
1375 Discriminated_Type
: constant Entity_Id
:=
1376 Implementation_Base_Type
1377 (Scope
(Original_Record_Component
(Discrim
)));
1379 -- The order of the following two tests matters in the
1380 -- access-to-class-wide case.
1382 if Is_Access_Type
(Obj_Type
) then
1383 Obj_Type
:= Implementation_Base_Type
1384 (Designated_Type
(Obj_Type
));
1387 if Is_Class_Wide_Type
(Obj_Type
) then
1388 Obj_Type
:= Implementation_Base_Type
1389 (Find_Specific_Type
(Obj_Type
));
1392 -- If a type T1 defines a discriminant D1, then Obj.D1 is ok (for
1393 -- our purposes here) if T1 is an ancestor of the type of Obj.
1394 -- So that's what we would like to test for here.
1395 -- The bad news: Is_Ancestor is only defined in the tagged case.
1396 -- The good news: in the untagged case, Implementation_Base_Type
1397 -- looks through derived types so we can use a simpler test.
1399 if Is_Tagged_Type
(Discriminated_Type
) then
1400 return Is_Ancestor
(Discriminated_Type
, Obj_Type
);
1402 return Discriminated_Type
= Obj_Type
;
1404 end Obj_Is_Good_Prefix
;
1406 -- Start of processing for Build_Discriminant_Reference
1409 if not Obj_Is_Good_Prefix
then
1410 -- If the given discriminant is not a component of the given
1411 -- object, then try the enclosing object.
1413 if Nkind
(Obj
) = N_Selected_Component
then
1414 return Build_Discriminant_Reference
1415 (Discrim_Name
=> Discrim_Name
,
1416 Obj
=> Prefix
(Obj
));
1417 elsif Nkind
(Obj
) in N_Has_Entity
1418 and then Nkind
(Parent
(Entity
(Obj
))) =
1419 N_Object_Renaming_Declaration
1421 -- Look through a renaming (a corner case of a corner case).
1422 return Build_Discriminant_Reference
1423 (Discrim_Name
=> Discrim_Name
,
1424 Obj
=> Name
(Parent
(Entity
(Obj
))));
1426 -- We are in some unexpected case here, so revert to the
1427 -- old behavior (by falling through to it).
1432 return Make_Selected_Component
(Loc
,
1433 Prefix
=> Copy_And_Maybe_Dereference
(Obj
),
1434 Selector_Name
=> New_Occurrence_Of
(Discrim
, Loc
));
1435 end Build_Discriminant_Reference
;
1437 ------------------------------------
1438 -- Build_Access_Record_Constraint --
1439 ------------------------------------
1441 function Build_Access_Record_Constraint
(C
: List_Id
) return List_Id
is
1442 Constraints
: constant List_Id
:= New_List
;
1447 -- Retrieve the constraint from the component declaration, because
1448 -- the component subtype has not been constructed and the component
1449 -- type is an unconstrained access.
1452 while Present
(D
) loop
1453 if Nkind
(D
) = N_Discriminant_Association
1454 and then Denotes_Discriminant
(Expression
(D
))
1456 D_Val
:= New_Copy_Tree
(D
);
1457 Set_Expression
(D_Val
,
1458 Make_Selected_Component
(Loc
,
1459 Prefix
=> Copy_And_Maybe_Dereference
(P
),
1461 New_Occurrence_Of
(Entity
(Expression
(D
)), Loc
)));
1463 elsif Denotes_Discriminant
(D
) then
1464 D_Val
:= Make_Selected_Component
(Loc
,
1465 Prefix
=> Copy_And_Maybe_Dereference
(P
),
1466 Selector_Name
=> New_Occurrence_Of
(Entity
(D
), Loc
));
1469 D_Val
:= New_Copy_Tree
(D
);
1472 Append
(D_Val
, Constraints
);
1477 end Build_Access_Record_Constraint
;
1479 --------------------------------
1480 -- Copy_And_Maybe_Dereference --
1481 --------------------------------
1483 function Copy_And_Maybe_Dereference
(N
: Node_Id
) return Node_Id
is
1484 New_N
: constant Node_Id
:= New_Copy_Tree
(N
);
1487 if Is_Access_Type
(Etype
(N
)) then
1488 return Make_Explicit_Dereference
(Sloc
(Parent
(N
)), New_N
);
1493 end Copy_And_Maybe_Dereference
;
1495 -- Start of processing for Build_Actual_Subtype_Of_Component
1498 -- The subtype does not need to be created for a selected component
1499 -- in a Spec_Expression.
1501 if In_Spec_Expression
then
1504 -- More comments for the rest of this body would be good ???
1506 elsif Nkind
(N
) = N_Explicit_Dereference
then
1507 if Is_Composite_Type
(T
)
1508 and then not Is_Constrained
(T
)
1509 and then not (Is_Class_Wide_Type
(T
)
1510 and then Is_Constrained
(Root_Type
(T
)))
1511 and then not Has_Unknown_Discriminants
(T
)
1513 -- If the type of the dereference is already constrained, it is an
1516 if Is_Array_Type
(Etype
(N
))
1517 and then Is_Constrained
(Etype
(N
))
1521 Remove_Side_Effects
(P
);
1522 return Build_Actual_Subtype
(T
, N
);
1529 elsif Nkind
(N
) = N_Selected_Component
then
1530 -- The entity of the selected component allows us to retrieve
1531 -- the original constraint from its component declaration.
1533 Sel
:= Entity
(Selector_Name
(N
));
1534 if Parent_Kind
(Sel
) /= N_Component_Declaration
then
1539 if Is_Access_Type
(T
) then
1540 Desig_Typ
:= Designated_Type
(T
);
1546 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1547 Id
:= First_Index
(Desig_Typ
);
1549 -- Check whether an index bound is constrained by a discriminant
1551 while Present
(Id
) loop
1552 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1554 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1556 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1558 Remove_Side_Effects
(P
);
1560 Build_Component_Subtype
1561 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1567 elsif Is_Composite_Type
(Desig_Typ
)
1568 and then Has_Discriminants
(Desig_Typ
)
1569 and then not Is_Empty_Elmt_List
(Discriminant_Constraint
(Desig_Typ
))
1570 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1572 if Is_Private_Type
(Desig_Typ
)
1573 and then No
(Discriminant_Constraint
(Desig_Typ
))
1575 Desig_Typ
:= Full_View
(Desig_Typ
);
1578 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1579 while Present
(D
) loop
1580 if Denotes_Discriminant
(Node
(D
)) then
1581 Remove_Side_Effects
(P
);
1583 Build_Component_Subtype
(
1584 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1590 -- Special processing for an access record component that is
1591 -- the target of an assignment. If the designated type is an
1592 -- unconstrained discriminated record we create its actual
1595 elsif Ekind
(T
) = E_Access_Type
1596 and then Present
(Sel
)
1597 and then Has_Per_Object_Constraint
(Sel
)
1598 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
1599 and then N
= Name
(Parent
(N
))
1600 -- and then not Inside_Init_Proc
1601 -- and then Has_Discriminants (Desig_Typ)
1602 -- and then not Is_Constrained (Desig_Typ)
1605 S_Indic
: constant Node_Id
:=
1607 (Component_Definition
(Parent
(Sel
))));
1610 if Nkind
(S_Indic
) = N_Subtype_Indication
then
1611 Discs
:= Constraints
(Constraint
(S_Indic
));
1613 Remove_Side_Effects
(P
);
1614 return Build_Component_Subtype
1615 (Build_Access_Record_Constraint
(Discs
), Loc
, T
);
1622 -- If none of the above, the actual and nominal subtypes are the same
1625 end Build_Actual_Subtype_Of_Component
;
1627 -----------------------------
1628 -- Build_Component_Subtype --
1629 -----------------------------
1631 function Build_Component_Subtype
1634 T
: Entity_Id
) return Node_Id
1640 -- Unchecked_Union components do not require component subtypes
1642 if Is_Unchecked_Union
(T
) then
1646 Subt
:= Make_Temporary
(Loc
, 'S');
1647 Set_Is_Internal
(Subt
);
1650 Make_Subtype_Declaration
(Loc
,
1651 Defining_Identifier
=> Subt
,
1652 Subtype_Indication
=>
1653 Make_Subtype_Indication
(Loc
,
1654 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1656 Make_Index_Or_Discriminant_Constraint
(Loc
,
1657 Constraints
=> C
)));
1659 Mark_Rewrite_Insertion
(Decl
);
1661 end Build_Component_Subtype
;
1663 -----------------------------
1664 -- Build_Constrained_Itype --
1665 -----------------------------
1667 procedure Build_Constrained_Itype
1670 New_Assoc_List
: List_Id
)
1672 Constrs
: constant List_Id
:= New_List
;
1673 Loc
: constant Source_Ptr
:= Sloc
(N
);
1676 New_Assoc
: Node_Id
;
1677 Subtyp_Decl
: Node_Id
;
1680 New_Assoc
:= First
(New_Assoc_List
);
1681 while Present
(New_Assoc
) loop
1683 -- There is exactly one choice in the component association (and
1684 -- it is either a discriminant, a component or the others clause).
1685 pragma Assert
(List_Length
(Choices
(New_Assoc
)) = 1);
1687 -- Duplicate expression for the discriminant and put it on the
1688 -- list of constraints for the itype declaration.
1690 if Is_Entity_Name
(First
(Choices
(New_Assoc
)))
1692 Ekind
(Entity
(First
(Choices
(New_Assoc
)))) = E_Discriminant
1694 Append_To
(Constrs
, Duplicate_Subexpr
(Expression
(New_Assoc
)));
1700 if Has_Unknown_Discriminants
(Typ
)
1701 and then Present
(Underlying_Record_View
(Typ
))
1704 Make_Subtype_Indication
(Loc
,
1706 New_Occurrence_Of
(Underlying_Record_View
(Typ
), Loc
),
1708 Make_Index_Or_Discriminant_Constraint
(Loc
,
1709 Constraints
=> Constrs
));
1712 Make_Subtype_Indication
(Loc
,
1714 New_Occurrence_Of
(Base_Type
(Typ
), Loc
),
1716 Make_Index_Or_Discriminant_Constraint
(Loc
,
1717 Constraints
=> Constrs
));
1720 Def_Id
:= Create_Itype
(Ekind
(Typ
), N
);
1723 Make_Subtype_Declaration
(Loc
,
1724 Defining_Identifier
=> Def_Id
,
1725 Subtype_Indication
=> Indic
);
1726 Set_Parent
(Subtyp_Decl
, Parent
(N
));
1728 -- Itypes must be analyzed with checks off (see itypes.ads)
1730 Analyze
(Subtyp_Decl
, Suppress
=> All_Checks
);
1732 Set_Etype
(N
, Def_Id
);
1733 end Build_Constrained_Itype
;
1735 ---------------------------
1736 -- Build_Default_Subtype --
1737 ---------------------------
1739 function Build_Default_Subtype
1741 N
: Node_Id
) return Entity_Id
1743 Loc
: constant Source_Ptr
:= Sloc
(N
);
1747 -- The base type that is to be constrained by the defaults
1750 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1754 Bas
:= Base_Type
(T
);
1756 -- If T is non-private but its base type is private, this is the
1757 -- completion of a subtype declaration whose parent type is private
1758 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1759 -- are to be found in the full view of the base. Check that the private
1760 -- status of T and its base differ.
1762 if Is_Private_Type
(Bas
)
1763 and then not Is_Private_Type
(T
)
1764 and then Present
(Full_View
(Bas
))
1766 Bas
:= Full_View
(Bas
);
1769 Disc
:= First_Discriminant
(T
);
1771 if No
(Discriminant_Default_Value
(Disc
)) then
1776 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1777 Constraints
: constant List_Id
:= New_List
;
1781 while Present
(Disc
) loop
1782 Append_To
(Constraints
,
1783 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1784 Next_Discriminant
(Disc
);
1788 Make_Subtype_Declaration
(Loc
,
1789 Defining_Identifier
=> Act
,
1790 Subtype_Indication
=>
1791 Make_Subtype_Indication
(Loc
,
1792 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1794 Make_Index_Or_Discriminant_Constraint
(Loc
,
1795 Constraints
=> Constraints
)));
1797 Insert_Action
(N
, Decl
);
1799 -- If the context is a component declaration the subtype declaration
1800 -- will be analyzed when the enclosing type is frozen, otherwise do
1803 if Ekind
(Current_Scope
) /= E_Record_Type
then
1809 end Build_Default_Subtype
;
1811 ------------------------------
1812 -- Build_Default_Subtype_OK --
1813 ------------------------------
1815 function Build_Default_Subtype_OK
(T
: Entity_Id
) return Boolean is
1818 if Is_Constrained
(T
) then
1820 -- We won't build a new subtype if T is constrained
1825 return Is_Definite_Subtype
(T
) and then Is_Inherently_Limited_Type
(T
);
1826 end Build_Default_Subtype_OK
;
1828 --------------------------------------------
1829 -- Build_Discriminal_Subtype_Of_Component --
1830 --------------------------------------------
1832 function Build_Discriminal_Subtype_Of_Component
1833 (T
: Entity_Id
) return Node_Id
1835 Loc
: constant Source_Ptr
:= Sloc
(T
);
1839 function Build_Discriminal_Array_Constraint
return List_Id
;
1840 -- If one or more of the bounds of the component depends on
1841 -- discriminants, build actual constraint using the discriminants
1844 function Build_Discriminal_Record_Constraint
return List_Id
;
1845 -- Similar to previous one, for discriminated components constrained by
1846 -- the discriminant of the enclosing object.
1848 ----------------------------------------
1849 -- Build_Discriminal_Array_Constraint --
1850 ----------------------------------------
1852 function Build_Discriminal_Array_Constraint
return List_Id
is
1853 Constraints
: constant List_Id
:= New_List
;
1861 Indx
:= First_Index
(T
);
1862 while Present
(Indx
) loop
1863 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1864 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1866 if Denotes_Discriminant
(Old_Lo
) then
1867 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1870 Lo
:= New_Copy_Tree
(Old_Lo
);
1873 if Denotes_Discriminant
(Old_Hi
) then
1874 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1877 Hi
:= New_Copy_Tree
(Old_Hi
);
1880 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1885 end Build_Discriminal_Array_Constraint
;
1887 -----------------------------------------
1888 -- Build_Discriminal_Record_Constraint --
1889 -----------------------------------------
1891 function Build_Discriminal_Record_Constraint
return List_Id
is
1892 Constraints
: constant List_Id
:= New_List
;
1897 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1898 while Present
(D
) loop
1899 if Denotes_Discriminant
(Node
(D
)) then
1901 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1903 D_Val
:= New_Copy_Tree
(Node
(D
));
1906 Append
(D_Val
, Constraints
);
1911 end Build_Discriminal_Record_Constraint
;
1913 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1916 if Ekind
(T
) = E_Array_Subtype
then
1917 Id
:= First_Index
(T
);
1918 while Present
(Id
) loop
1919 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1921 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1923 return Build_Component_Subtype
1924 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1930 elsif Ekind
(T
) = E_Record_Subtype
1931 and then Has_Discriminants
(T
)
1932 and then not Has_Unknown_Discriminants
(T
)
1934 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1935 while Present
(D
) loop
1936 if Denotes_Discriminant
(Node
(D
)) then
1937 return Build_Component_Subtype
1938 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1945 -- If none of the above, the actual and nominal subtypes are the same
1948 end Build_Discriminal_Subtype_Of_Component
;
1950 ------------------------------
1951 -- Build_Elaboration_Entity --
1952 ------------------------------
1954 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1955 Loc
: constant Source_Ptr
:= Sloc
(N
);
1957 Elab_Ent
: Entity_Id
;
1959 procedure Set_Package_Name
(Ent
: Entity_Id
);
1960 -- Given an entity, sets the fully qualified name of the entity in
1961 -- Name_Buffer, with components separated by double underscores. This
1962 -- is a recursive routine that climbs the scope chain to Standard.
1964 ----------------------
1965 -- Set_Package_Name --
1966 ----------------------
1968 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1970 if Scope
(Ent
) /= Standard_Standard
then
1971 Set_Package_Name
(Scope
(Ent
));
1974 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1976 Name_Buffer
(Name_Len
+ 1) := '_';
1977 Name_Buffer
(Name_Len
+ 2) := '_';
1978 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1979 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1983 Get_Name_String
(Chars
(Ent
));
1985 end Set_Package_Name
;
1987 -- Start of processing for Build_Elaboration_Entity
1990 -- Ignore call if already constructed
1992 if Present
(Elaboration_Entity
(Spec_Id
)) then
1995 -- Do not generate an elaboration entity in GNATprove move because the
1996 -- elaboration counter is a form of expansion.
1998 elsif GNATprove_Mode
then
2001 -- See if we need elaboration entity
2003 -- We always need an elaboration entity when preserving control flow, as
2004 -- we want to remain explicit about the unit's elaboration order.
2006 elsif Opt
.Suppress_Control_Flow_Optimizations
then
2009 -- We always need an elaboration entity for the dynamic elaboration
2010 -- model, since it is needed to properly generate the PE exception for
2011 -- access before elaboration.
2013 elsif Dynamic_Elaboration_Checks
then
2016 -- For the static model, we don't need the elaboration counter if this
2017 -- unit is sure to have no elaboration code, since that means there
2018 -- is no elaboration unit to be called. Note that we can't just decide
2019 -- after the fact by looking to see whether there was elaboration code,
2020 -- because that's too late to make this decision.
2022 elsif Restriction_Active
(No_Elaboration_Code
) then
2025 -- Similarly, for the static model, we can skip the elaboration counter
2026 -- if we have the No_Multiple_Elaboration restriction, since for the
2027 -- static model, that's the only purpose of the counter (to avoid
2028 -- multiple elaboration).
2030 elsif Restriction_Active
(No_Multiple_Elaboration
) then
2034 -- Here we need the elaboration entity
2036 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
2037 -- name with dots replaced by double underscore. We have to manually
2038 -- construct this name, since it will be elaborated in the outer scope,
2039 -- and thus will not have the unit name automatically prepended.
2041 Set_Package_Name
(Spec_Id
);
2042 Add_Str_To_Name_Buffer
("_E");
2044 -- Create elaboration counter
2046 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
2047 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
2050 Make_Object_Declaration
(Loc
,
2051 Defining_Identifier
=> Elab_Ent
,
2052 Object_Definition
=>
2053 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
2054 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
2056 Push_Scope
(Standard_Standard
);
2057 Add_Global_Declaration
(Decl
);
2060 -- Reset True_Constant indication, since we will indeed assign a value
2061 -- to the variable in the binder main. We also kill the Current_Value
2062 -- and Last_Assignment fields for the same reason.
2064 Set_Is_True_Constant
(Elab_Ent
, False);
2065 Set_Current_Value
(Elab_Ent
, Empty
);
2066 Set_Last_Assignment
(Elab_Ent
, Empty
);
2068 -- We do not want any further qualification of the name (if we did not
2069 -- do this, we would pick up the name of the generic package in the case
2070 -- of a library level generic instantiation).
2072 Set_Has_Qualified_Name
(Elab_Ent
);
2073 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
2074 end Build_Elaboration_Entity
;
2076 --------------------------------
2077 -- Build_Explicit_Dereference --
2078 --------------------------------
2080 procedure Build_Explicit_Dereference
2084 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
2089 -- An entity of a type with a reference aspect is overloaded with
2090 -- both interpretations: with and without the dereference. Now that
2091 -- the dereference is made explicit, set the type of the node properly,
2092 -- to prevent anomalies in the backend. Same if the expression is an
2093 -- overloaded function call whose return type has a reference aspect.
2095 if Is_Entity_Name
(Expr
) then
2096 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
2098 -- The designated entity will not be examined again when resolving
2099 -- the dereference, so generate a reference to it now.
2101 Generate_Reference
(Entity
(Expr
), Expr
);
2103 elsif Nkind
(Expr
) = N_Function_Call
then
2105 -- If the name of the indexing function is overloaded, locate the one
2106 -- whose return type has an implicit dereference on the desired
2107 -- discriminant, and set entity and type of function call.
2109 if Is_Overloaded
(Name
(Expr
)) then
2110 Get_First_Interp
(Name
(Expr
), I
, It
);
2112 while Present
(It
.Nam
) loop
2113 if Ekind
((It
.Typ
)) = E_Record_Type
2114 and then First_Entity
((It
.Typ
)) = Disc
2116 Set_Entity
(Name
(Expr
), It
.Nam
);
2117 Set_Etype
(Name
(Expr
), Etype
(It
.Nam
));
2121 Get_Next_Interp
(I
, It
);
2125 -- Set type of call from resolved function name.
2127 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
2130 Set_Is_Overloaded
(Expr
, False);
2132 -- The expression will often be a generalized indexing that yields a
2133 -- container element that is then dereferenced, in which case the
2134 -- generalized indexing call is also non-overloaded.
2136 if Nkind
(Expr
) = N_Indexed_Component
2137 and then Present
(Generalized_Indexing
(Expr
))
2139 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
2143 Make_Explicit_Dereference
(Loc
,
2145 Make_Selected_Component
(Loc
,
2146 Prefix
=> Relocate_Node
(Expr
),
2147 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
2148 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
2149 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
2150 end Build_Explicit_Dereference
;
2152 ---------------------------
2153 -- Build_Overriding_Spec --
2154 ---------------------------
2156 function Build_Overriding_Spec
2158 Typ
: Entity_Id
) return Node_Id
2160 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2161 Par_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Op
);
2162 Spec
: constant Node_Id
:= Specification
(Unit_Declaration_Node
(Op
));
2164 Formal_Spec
: Node_Id
;
2165 Formal_Type
: Node_Id
;
2169 New_Spec
:= Copy_Subprogram_Spec
(Spec
);
2171 Formal_Spec
:= First
(Parameter_Specifications
(New_Spec
));
2172 while Present
(Formal_Spec
) loop
2173 Formal_Type
:= Parameter_Type
(Formal_Spec
);
2175 if Is_Entity_Name
(Formal_Type
)
2176 and then Entity
(Formal_Type
) = Par_Typ
2178 Rewrite
(Formal_Type
, New_Occurrence_Of
(Typ
, Loc
));
2180 elsif Nkind
(Formal_Type
) = N_Access_Definition
2181 and then Entity
(Subtype_Mark
(Formal_Type
)) = Par_Typ
2183 Rewrite
(Subtype_Mark
(Formal_Type
), New_Occurrence_Of
(Typ
, Loc
));
2190 end Build_Overriding_Spec
;
2196 function Build_Subtype
2197 (Related_Node
: Node_Id
;
2200 Constraints
: List_Id
)
2204 Subtyp_Decl
: Node_Id
;
2206 Btyp
: Entity_Id
:= Base_Type
(Typ
);
2209 -- The Related_Node better be here or else we won't be able to
2210 -- attach new itypes to a node in the tree.
2212 pragma Assert
(Present
(Related_Node
));
2214 -- If the view of the component's type is incomplete or private
2215 -- with unknown discriminants, then the constraint must be applied
2216 -- to the full type.
2218 if Has_Unknown_Discriminants
(Btyp
)
2219 and then Present
(Underlying_Type
(Btyp
))
2221 Btyp
:= Underlying_Type
(Btyp
);
2225 Make_Subtype_Indication
(Loc
,
2226 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
2228 Make_Index_Or_Discriminant_Constraint
(Loc
, Constraints
));
2230 Def_Id
:= Create_Itype
(Ekind
(Typ
), Related_Node
);
2233 Make_Subtype_Declaration
(Loc
,
2234 Defining_Identifier
=> Def_Id
,
2235 Subtype_Indication
=> Indic
);
2237 Set_Parent
(Subtyp_Decl
, Parent
(Related_Node
));
2239 -- Itypes must be analyzed with checks off (see package Itypes)
2241 Analyze
(Subtyp_Decl
, Suppress
=> All_Checks
);
2243 if Is_Itype
(Def_Id
) and then Has_Predicates
(Typ
) then
2244 Inherit_Predicate_Flags
(Def_Id
, Typ
);
2246 -- Indicate where the predicate function may be found
2248 if Is_Itype
(Typ
) then
2249 if Present
(Predicate_Function
(Def_Id
)) then
2252 elsif Present
(Predicate_Function
(Typ
)) then
2253 Set_Predicate_Function
(Def_Id
, Predicate_Function
(Typ
));
2256 Set_Predicated_Parent
(Def_Id
, Predicated_Parent
(Typ
));
2259 elsif No
(Predicate_Function
(Def_Id
)) then
2260 Set_Predicated_Parent
(Def_Id
, Typ
);
2267 -----------------------------------
2268 -- Cannot_Raise_Constraint_Error --
2269 -----------------------------------
2271 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
2273 function List_Cannot_Raise_CE
(L
: List_Id
) return Boolean;
2274 -- Returns True if none of the list members cannot possibly raise
2275 -- Constraint_Error.
2277 --------------------------
2278 -- List_Cannot_Raise_CE --
2279 --------------------------
2281 function List_Cannot_Raise_CE
(L
: List_Id
) return Boolean is
2285 while Present
(N
) loop
2286 if Cannot_Raise_Constraint_Error
(N
) then
2294 end List_Cannot_Raise_CE
;
2296 -- Start of processing for Cannot_Raise_Constraint_Error
2299 if Compile_Time_Known_Value
(Expr
) then
2302 elsif Do_Range_Check
(Expr
) then
2305 elsif Raises_Constraint_Error
(Expr
) then
2309 case Nkind
(Expr
) is
2310 when N_Identifier
=>
2313 when N_Expanded_Name
=>
2316 when N_Indexed_Component
=>
2317 return not Do_Range_Check
(Expr
)
2318 and then Cannot_Raise_Constraint_Error
(Prefix
(Expr
))
2319 and then List_Cannot_Raise_CE
(Expressions
(Expr
));
2321 when N_Selected_Component
=>
2322 return not Do_Discriminant_Check
(Expr
)
2323 and then Cannot_Raise_Constraint_Error
(Prefix
(Expr
));
2325 when N_Attribute_Reference
=>
2326 if Do_Overflow_Check
(Expr
) then
2329 elsif No
(Expressions
(Expr
)) then
2333 return List_Cannot_Raise_CE
(Expressions
(Expr
));
2336 when N_Type_Conversion
=>
2337 if Do_Overflow_Check
(Expr
)
2338 or else Do_Length_Check
(Expr
)
2342 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
2345 when N_Unchecked_Type_Conversion
=>
2346 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
2349 if Do_Overflow_Check
(Expr
) then
2352 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2359 if Do_Division_Check
(Expr
)
2361 Do_Overflow_Check
(Expr
)
2366 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
2368 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2387 | N_Op_Shift_Right_Arithmetic
2391 if Do_Overflow_Check
(Expr
) then
2395 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
2397 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2404 end Cannot_Raise_Constraint_Error
;
2406 -------------------------------
2407 -- Check_Ambiguous_Aggregate --
2408 -------------------------------
2410 procedure Check_Ambiguous_Aggregate
(Call
: Node_Id
) is
2414 if All_Extensions_Allowed
then
2415 Actual
:= First_Actual
(Call
);
2416 while Present
(Actual
) loop
2417 if Nkind
(Actual
) = N_Aggregate
then
2419 ("\add type qualification to aggregate actual", Actual
);
2422 Next_Actual
(Actual
);
2425 end Check_Ambiguous_Aggregate
;
2427 -----------------------------------------
2428 -- Check_Dynamically_Tagged_Expression --
2429 -----------------------------------------
2431 procedure Check_Dynamically_Tagged_Expression
2434 Related_Nod
: Node_Id
)
2437 pragma Assert
(Is_Tagged_Type
(Typ
));
2439 -- In order to avoid spurious errors when analyzing the expanded code,
2440 -- this check is done only for nodes that come from source and for
2441 -- actuals of generic instantiations.
2443 if (Comes_From_Source
(Related_Nod
)
2444 or else In_Generic_Actual
(Expr
))
2445 and then (Is_Class_Wide_Type
(Etype
(Expr
))
2446 or else Is_Dynamically_Tagged
(Expr
))
2447 and then not Is_Class_Wide_Type
(Typ
)
2449 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
2451 end Check_Dynamically_Tagged_Expression
;
2453 --------------------------
2454 -- Check_Fully_Declared --
2455 --------------------------
2457 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
2459 if Ekind
(T
) = E_Incomplete_Type
then
2461 -- Ada 2005 (AI-50217): If the type is available through a limited
2462 -- with_clause, verify that its full view has been analyzed.
2464 if From_Limited_With
(T
)
2465 and then Present
(Non_Limited_View
(T
))
2466 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2468 -- The non-limited view is fully declared
2474 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2477 -- Need comments for these tests ???
2479 elsif Has_Private_Component
(T
)
2480 and then not Is_Generic_Type
(Root_Type
(T
))
2481 and then not In_Spec_Expression
2483 -- Special case: if T is the anonymous type created for a single
2484 -- task or protected object, use the name of the source object.
2486 if Is_Concurrent_Type
(T
)
2487 and then not Comes_From_Source
(T
)
2488 and then Nkind
(N
) = N_Object_Declaration
2491 ("type of& has incomplete component",
2492 N
, Defining_Identifier
(N
));
2495 ("premature usage of incomplete}",
2496 N
, First_Subtype
(T
));
2499 end Check_Fully_Declared
;
2501 -------------------------------------------
2502 -- Check_Function_With_Address_Parameter --
2503 -------------------------------------------
2505 procedure Check_Function_With_Address_Parameter
(Subp_Id
: Entity_Id
) is
2510 F
:= First_Formal
(Subp_Id
);
2511 while Present
(F
) loop
2514 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
2518 if Is_Descendant_Of_Address
(T
) or else Is_Limited_Type
(T
) then
2519 Set_Is_Pure
(Subp_Id
, False);
2525 end Check_Function_With_Address_Parameter
;
2527 -------------------------------------
2528 -- Check_Function_Writable_Actuals --
2529 -------------------------------------
2531 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2532 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2533 Identifiers_List
: Elist_Id
:= No_Elist
;
2534 Aggr_Error_Node
: Node_Id
:= Empty
;
2535 Error_Node
: Node_Id
:= Empty
;
2537 procedure Collect_Identifiers
(N
: Node_Id
);
2538 -- In a single traversal of subtree N collect in Writable_Actuals_List
2539 -- all the actuals of functions with writable actuals, and in the list
2540 -- Identifiers_List collect all the identifiers that are not actuals of
2541 -- functions with writable actuals. If a writable actual is referenced
2542 -- twice as writable actual then Error_Node is set to reference its
2543 -- second occurrence, the error is reported, and the tree traversal
2546 -------------------------
2547 -- Collect_Identifiers --
2548 -------------------------
2550 procedure Collect_Identifiers
(N
: Node_Id
) is
2552 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2553 -- Process a single node during the tree traversal to collect the
2554 -- writable actuals of functions and all the identifiers which are
2555 -- not writable actuals of functions.
2557 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2558 -- Returns True if List has a node whose Entity is Entity (N)
2564 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2565 Is_Writable_Actual
: Boolean := False;
2566 Id
: Entity_Id
:= Empty
;
2567 -- Default init of Id for CodePeer
2570 if Nkind
(N
) = N_Identifier
then
2572 -- No analysis possible if the entity is not decorated
2574 if No
(Entity
(N
)) then
2577 -- Don't collect identifiers of packages, called functions, etc
2579 elsif Ekind
(Entity
(N
)) in
2580 E_Package | E_Function | E_Procedure | E_Entry
2584 -- For rewritten nodes, continue the traversal in the original
2585 -- subtree. Needed to handle aggregates in original expressions
2586 -- extracted from the tree by Remove_Side_Effects.
2588 elsif Is_Rewrite_Substitution
(N
) then
2589 Collect_Identifiers
(Original_Node
(N
));
2592 -- For now we skip aggregate discriminants, since they require
2593 -- performing the analysis in two phases to identify conflicts:
2594 -- first one analyzing discriminants and second one analyzing
2595 -- the rest of components (since at run time, discriminants are
2596 -- evaluated prior to components): too much computation cost
2597 -- to identify a corner case???
2599 elsif Nkind
(Parent
(N
)) = N_Component_Association
2600 and then Nkind
(Parent
(Parent
(N
))) in
2601 N_Aggregate | N_Extension_Aggregate
2604 Choice
: constant Node_Id
:= First
(Choices
(Parent
(N
)));
2607 if Ekind
(Entity
(N
)) = E_Discriminant
then
2610 elsif Expression
(Parent
(N
)) = N
2611 and then Nkind
(Choice
) = N_Identifier
2612 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2618 -- Analyze if N is a writable actual of a function
2620 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2622 Call
: constant Node_Id
:= Parent
(N
);
2627 Id
:= Get_Called_Entity
(Call
);
2629 -- In case of previous error, no check is possible
2635 if Ekind
(Id
) in E_Function | E_Generic_Function
2636 and then Has_Out_Or_In_Out_Parameter
(Id
)
2638 Formal
:= First_Formal
(Id
);
2639 Actual
:= First_Actual
(Call
);
2640 while Present
(Actual
) and then Present
(Formal
) loop
2642 if Ekind
(Formal
) in E_Out_Parameter
2643 | E_In_Out_Parameter
2645 Is_Writable_Actual
:= True;
2651 Next_Formal
(Formal
);
2652 Next_Actual
(Actual
);
2658 if Is_Writable_Actual
then
2660 -- Skip checking the error in non-elementary types since
2661 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2662 -- store this actual in Writable_Actuals_List since it is
2663 -- needed to perform checks on other constructs that have
2664 -- arbitrary order of evaluation (for example, aggregates).
2666 if not Is_Elementary_Type
(Etype
(N
)) then
2667 if not Contains
(Writable_Actuals_List
, N
) then
2668 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2671 -- Second occurrence of an elementary type writable actual
2673 elsif Contains
(Writable_Actuals_List
, N
) then
2675 -- Report the error on the second occurrence of the
2676 -- identifier. We cannot assume that N is the second
2677 -- occurrence (according to their location in the
2678 -- sources), since Traverse_Func walks through Field2
2679 -- last (see comment in the body of Traverse_Func).
2685 Elmt
:= First_Elmt
(Writable_Actuals_List
);
2686 while Present
(Elmt
)
2687 and then Entity
(Node
(Elmt
)) /= Entity
(N
)
2692 if Sloc
(N
) > Sloc
(Node
(Elmt
)) then
2695 Error_Node
:= Node
(Elmt
);
2699 ("value may be affected by call to & "
2700 & "because order of evaluation is arbitrary",
2705 -- First occurrence of a elementary type writable actual
2708 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2712 if No
(Identifiers_List
) then
2713 Identifiers_List
:= New_Elmt_List
;
2716 Append_Unique_Elmt
(N
, Identifiers_List
);
2729 N
: Node_Id
) return Boolean
2731 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2740 Elmt
:= First_Elmt
(List
);
2741 while Present
(Elmt
) loop
2742 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2756 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2757 -- The traversal procedure
2759 -- Start of processing for Collect_Identifiers
2762 if Present
(Error_Node
) then
2766 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2771 end Collect_Identifiers
;
2773 -- Start of processing for Check_Function_Writable_Actuals
2776 -- The check only applies to Ada 2012 code on which Check_Actuals has
2777 -- been set, and only to constructs that have multiple constituents
2778 -- whose order of evaluation is not specified by the language.
2780 if Ada_Version
< Ada_2012
2781 or else not Check_Actuals
(N
)
2782 or else Nkind
(N
) not in N_Op
2786 | N_Extension_Aggregate
2787 | N_Full_Type_Declaration
2789 | N_Procedure_Call_Statement
2790 | N_Entry_Call_Statement
2791 or else (Nkind
(N
) = N_Full_Type_Declaration
2792 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2794 -- In addition, this check only applies to source code, not to code
2795 -- generated by constraint checks.
2797 or else not Comes_From_Source
(N
)
2802 -- If a construct C has two or more direct constituents that are names
2803 -- or expressions whose evaluation may occur in an arbitrary order, at
2804 -- least one of which contains a function call with an in out or out
2805 -- parameter, then the construct is legal only if: for each name N that
2806 -- is passed as a parameter of mode in out or out to some inner function
2807 -- call C2 (not including the construct C itself), there is no other
2808 -- name anywhere within a direct constituent of the construct C other
2809 -- than the one containing C2, that is known to refer to the same
2810 -- object (RM 6.4.1(6.17/3)).
2814 Collect_Identifiers
(Low_Bound
(N
));
2815 Collect_Identifiers
(High_Bound
(N
));
2817 when N_Membership_Test
2824 Collect_Identifiers
(Left_Opnd
(N
));
2826 if Present
(Right_Opnd
(N
)) then
2827 Collect_Identifiers
(Right_Opnd
(N
));
2830 if Nkind
(N
) in N_Membership_Test
then
2831 Expr
:= First
(Alternatives
(N
));
2832 while Present
(Expr
) loop
2833 Collect_Identifiers
(Expr
);
2840 when N_Full_Type_Declaration
=>
2842 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2843 -- Return the record part of this record type definition
2845 ---------------------
2846 -- Get_Record_Part --
2847 ---------------------
2849 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2850 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2852 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2853 return Record_Extension_Part
(Type_Def
);
2857 end Get_Record_Part
;
2860 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2861 Rec
: Node_Id
:= Get_Record_Part
(N
);
2864 -- No need to perform any analysis if the record has no
2867 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2871 -- Collect the identifiers starting from the deepest
2872 -- derivation. Done to report the error in the deepest
2876 if Present
(Component_List
(Rec
)) then
2877 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2878 while Present
(Comp
) loop
2879 if Nkind
(Comp
) = N_Component_Declaration
2880 and then Present
(Expression
(Comp
))
2882 Collect_Identifiers
(Expression
(Comp
));
2889 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2890 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2893 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2894 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2898 when N_Entry_Call_Statement
2902 Id
: constant Entity_Id
:= Get_Called_Entity
(N
);
2907 Formal
:= First_Formal
(Id
);
2908 Actual
:= First_Actual
(N
);
2909 while Present
(Actual
) and then Present
(Formal
) loop
2910 if Ekind
(Formal
) in E_Out_Parameter | E_In_Out_Parameter
2912 Collect_Identifiers
(Actual
);
2915 Next_Formal
(Formal
);
2916 Next_Actual
(Actual
);
2921 | N_Extension_Aggregate
2926 Comp_Expr
: Node_Id
;
2929 -- Handle the N_Others_Choice of array aggregates with static
2930 -- bounds. There is no need to perform this analysis in
2931 -- aggregates without static bounds since we cannot evaluate
2932 -- if the N_Others_Choice covers several elements. There is
2933 -- no need to handle the N_Others choice of record aggregates
2934 -- since at this stage it has been already expanded by
2935 -- Resolve_Record_Aggregate.
2937 if Is_Array_Type
(Etype
(N
))
2938 and then Nkind
(N
) = N_Aggregate
2939 and then Present
(Aggregate_Bounds
(N
))
2940 and then Compile_Time_Known_Bounds
(Etype
(N
))
2941 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2943 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2946 Count_Components
: Uint
:= Uint_0
;
2947 Num_Components
: Uint
;
2948 Others_Assoc
: Node_Id
:= Empty
;
2949 Others_Choice
: Node_Id
:= Empty
;
2950 Others_Box_Present
: Boolean := False;
2953 -- Count positional associations
2955 if Present
(Expressions
(N
)) then
2956 Comp_Expr
:= First
(Expressions
(N
));
2957 while Present
(Comp_Expr
) loop
2958 Count_Components
:= Count_Components
+ 1;
2963 -- Count the rest of elements and locate the N_Others
2966 Assoc
:= First
(Component_Associations
(N
));
2967 while Present
(Assoc
) loop
2968 Choice
:= First
(Choices
(Assoc
));
2969 while Present
(Choice
) loop
2970 if Nkind
(Choice
) = N_Others_Choice
then
2971 Others_Assoc
:= Assoc
;
2972 Others_Choice
:= Choice
;
2973 Others_Box_Present
:= Box_Present
(Assoc
);
2975 -- Count several components
2977 elsif Nkind
(Choice
) in
2978 N_Range | N_Subtype_Indication
2979 or else (Is_Entity_Name
(Choice
)
2980 and then Is_Type
(Entity
(Choice
)))
2985 Get_Index_Bounds
(Choice
, L
, H
);
2987 (Compile_Time_Known_Value
(L
)
2988 and then Compile_Time_Known_Value
(H
));
2991 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2994 -- Count single component. No other case available
2995 -- since we are handling an aggregate with static
2999 pragma Assert
(Is_OK_Static_Expression
(Choice
)
3000 or else Nkind
(Choice
) = N_Identifier
3001 or else Nkind
(Choice
) = N_Integer_Literal
);
3003 Count_Components
:= Count_Components
+ 1;
3013 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
3014 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
3016 pragma Assert
(Count_Components
<= Num_Components
);
3018 -- Handle the N_Others choice if it covers several
3021 if Present
(Others_Choice
)
3022 and then (Num_Components
- Count_Components
) > 1
3024 if not Others_Box_Present
then
3026 -- At this stage, if expansion is active, the
3027 -- expression of the others choice has not been
3028 -- analyzed. Hence we generate a duplicate and
3029 -- we analyze it silently to have available the
3030 -- minimum decoration required to collect the
3033 pragma Assert
(Present
(Others_Assoc
));
3035 if not Expander_Active
then
3036 Comp_Expr
:= Expression
(Others_Assoc
);
3039 New_Copy_Tree
(Expression
(Others_Assoc
));
3040 Preanalyze_Without_Errors
(Comp_Expr
);
3043 Collect_Identifiers
(Comp_Expr
);
3045 if Present
(Writable_Actuals_List
) then
3047 -- As suggested by Robert, at current stage we
3048 -- report occurrences of this case as warnings.
3051 ("writable function parameter may affect "
3052 & "value in other component because order "
3053 & "of evaluation is unspecified??",
3054 Node
(First_Elmt
(Writable_Actuals_List
)));
3060 -- For an array aggregate, a discrete_choice_list that has
3061 -- a nonstatic range is considered as two or more separate
3062 -- occurrences of the expression (RM 6.4.1(20/3)).
3064 elsif Is_Array_Type
(Etype
(N
))
3065 and then Nkind
(N
) = N_Aggregate
3066 and then Present
(Aggregate_Bounds
(N
))
3067 and then not Compile_Time_Known_Bounds
(Etype
(N
))
3069 -- Collect identifiers found in the dynamic bounds
3072 Count_Components
: Natural := 0;
3073 Low
, High
: Node_Id
;
3076 Assoc
:= First
(Component_Associations
(N
));
3077 while Present
(Assoc
) loop
3078 Choice
:= First
(Choices
(Assoc
));
3079 while Present
(Choice
) loop
3080 if Nkind
(Choice
) in
3081 N_Range | N_Subtype_Indication
3082 or else (Is_Entity_Name
(Choice
)
3083 and then Is_Type
(Entity
(Choice
)))
3085 Get_Index_Bounds
(Choice
, Low
, High
);
3087 if not Compile_Time_Known_Value
(Low
) then
3088 Collect_Identifiers
(Low
);
3090 if No
(Aggr_Error_Node
) then
3091 Aggr_Error_Node
:= Low
;
3095 if not Compile_Time_Known_Value
(High
) then
3096 Collect_Identifiers
(High
);
3098 if No
(Aggr_Error_Node
) then
3099 Aggr_Error_Node
:= High
;
3103 -- The RM rule is violated if there is more than
3104 -- a single choice in a component association.
3107 Count_Components
:= Count_Components
+ 1;
3109 if No
(Aggr_Error_Node
)
3110 and then Count_Components
> 1
3112 Aggr_Error_Node
:= Choice
;
3115 if not Compile_Time_Known_Value
(Choice
) then
3116 Collect_Identifiers
(Choice
);
3128 -- Handle ancestor part of extension aggregates
3130 if Nkind
(N
) = N_Extension_Aggregate
then
3131 Collect_Identifiers
(Ancestor_Part
(N
));
3134 -- Handle positional associations
3136 if Present
(Expressions
(N
)) then
3137 Comp_Expr
:= First
(Expressions
(N
));
3138 while Present
(Comp_Expr
) loop
3139 if not Is_OK_Static_Expression
(Comp_Expr
) then
3140 Collect_Identifiers
(Comp_Expr
);
3147 -- Handle discrete associations
3149 if Present
(Component_Associations
(N
)) then
3150 Assoc
:= First
(Component_Associations
(N
));
3151 while Present
(Assoc
) loop
3153 if not Box_Present
(Assoc
) then
3154 Choice
:= First
(Choices
(Assoc
));
3155 while Present
(Choice
) loop
3157 -- For now we skip discriminants since it requires
3158 -- performing the analysis in two phases: first one
3159 -- analyzing discriminants and second one analyzing
3160 -- the rest of components since discriminants are
3161 -- evaluated prior to components: too much extra
3162 -- work to detect a corner case???
3164 if Nkind
(Choice
) in N_Has_Entity
3165 and then Present
(Entity
(Choice
))
3166 and then Ekind
(Entity
(Choice
)) = E_Discriminant
3170 elsif Box_Present
(Assoc
) then
3174 if not Analyzed
(Expression
(Assoc
)) then
3176 New_Copy_Tree
(Expression
(Assoc
));
3177 Set_Parent
(Comp_Expr
, Parent
(N
));
3178 Preanalyze_Without_Errors
(Comp_Expr
);
3180 Comp_Expr
:= Expression
(Assoc
);
3183 Collect_Identifiers
(Comp_Expr
);
3199 -- No further action needed if we already reported an error
3201 if Present
(Error_Node
) then
3205 -- Check violation of RM 6.20/3 in aggregates
3207 if Present
(Aggr_Error_Node
)
3208 and then Present
(Writable_Actuals_List
)
3211 ("value may be affected by call in other component because they "
3212 & "are evaluated in unspecified order",
3213 Node
(First_Elmt
(Writable_Actuals_List
)));
3217 -- Check if some writable argument of a function is referenced
3219 if Present
(Writable_Actuals_List
)
3220 and then Present
(Identifiers_List
)
3227 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
3228 while Present
(Elmt_1
) loop
3229 Elmt_2
:= First_Elmt
(Identifiers_List
);
3230 while Present
(Elmt_2
) loop
3231 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
3232 case Nkind
(Parent
(Node
(Elmt_2
))) is
3234 | N_Component_Association
3235 | N_Component_Declaration
3238 ("value may be affected by call in other "
3239 & "component because they are evaluated "
3240 & "in unspecified order",
3243 when N_Membership_Test
=>
3245 ("value may be affected by call in other "
3246 & "alternative because they are evaluated "
3247 & "in unspecified order",
3252 ("value of actual may be affected by call in "
3253 & "other actual because they are evaluated "
3254 & "in unspecified order",
3266 end Check_Function_Writable_Actuals
;
3268 --------------------------------
3269 -- Check_Implicit_Dereference --
3270 --------------------------------
3272 procedure Check_Implicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
3278 if Nkind
(N
) = N_Indexed_Component
3279 and then Present
(Generalized_Indexing
(N
))
3281 Nam
:= Generalized_Indexing
(N
);
3286 if Ada_Version
< Ada_2012
3287 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
3291 elsif not Comes_From_Source
(N
)
3292 and then Nkind
(N
) /= N_Indexed_Component
3296 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
3300 Disc
:= First_Discriminant
(Typ
);
3301 while Present
(Disc
) loop
3302 if Has_Implicit_Dereference
(Disc
) then
3303 Desig
:= Designated_Type
(Etype
(Disc
));
3304 Add_One_Interp
(Nam
, Disc
, Desig
);
3306 -- If the node is a generalized indexing, add interpretation
3307 -- to that node as well, for subsequent resolution.
3309 if Nkind
(N
) = N_Indexed_Component
then
3310 Add_One_Interp
(N
, Disc
, Desig
);
3313 -- If the operation comes from a generic unit and the context
3314 -- is a selected component, the selector name may be global
3315 -- and set in the instance already. Remove the entity to
3316 -- force resolution of the selected component, and the
3317 -- generation of an explicit dereference if needed.
3320 and then Nkind
(Parent
(Nam
)) = N_Selected_Component
3322 Set_Entity
(Selector_Name
(Parent
(Nam
)), Empty
);
3328 Next_Discriminant
(Disc
);
3331 end Check_Implicit_Dereference
;
3333 ----------------------------------
3334 -- Check_Internal_Protected_Use --
3335 ----------------------------------
3337 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
3345 while Present
(S
) loop
3346 if S
= Standard_Standard
then
3349 elsif Ekind
(S
) = E_Function
3350 and then Ekind
(Scope
(S
)) = E_Protected_Type
3360 and then Scope
(Nam
) = Prot
3361 and then Ekind
(Nam
) /= E_Function
3363 -- An indirect function call (e.g. a callback within a protected
3364 -- function body) is not statically illegal. If the access type is
3365 -- anonymous and is the type of an access parameter, the scope of Nam
3366 -- will be the protected type, but it is not a protected operation.
3368 if Ekind
(Nam
) = E_Subprogram_Type
3369 and then Nkind
(Associated_Node_For_Itype
(Nam
)) =
3370 N_Function_Specification
3374 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
3376 ("within protected function cannot use protected procedure in "
3377 & "renaming or as generic actual", N
);
3379 elsif Nkind
(N
) = N_Attribute_Reference
then
3381 ("within protected function cannot take access of protected "
3386 ("within protected function, protected object is constant", N
);
3388 ("\cannot call operation that may modify it", N
);
3392 -- Verify that an internal call does not appear within a precondition
3393 -- of a protected operation. This implements AI12-0166.
3394 -- The precondition aspect has been rewritten as a pragma Precondition
3395 -- and we check whether the scope of the called subprogram is the same
3396 -- as that of the entity to which the aspect applies.
3398 if Convention
(Nam
) = Convention_Protected
then
3404 while Present
(P
) loop
3405 if Nkind
(P
) = N_Pragma
3406 and then Chars
(Pragma_Identifier
(P
)) = Name_Precondition
3407 and then From_Aspect_Specification
(P
)
3409 Scope
(Entity
(Corresponding_Aspect
(P
))) = Scope
(Nam
)
3412 ("internal call cannot appear in precondition of "
3413 & "protected operation", N
);
3416 elsif Nkind
(P
) = N_Pragma
3417 and then Chars
(Pragma_Identifier
(P
)) = Name_Contract_Cases
3419 -- Check whether call is in a case guard. It is legal in a
3423 while Present
(P
) loop
3424 if Nkind
(Parent
(P
)) = N_Component_Association
3425 and then P
/= Expression
(Parent
(P
))
3428 ("internal call cannot appear in case guard in a "
3429 & "contract case", N
);
3437 elsif Nkind
(P
) = N_Parameter_Specification
3438 and then Scope
(Current_Scope
) = Scope
(Nam
)
3439 and then Nkind
(Parent
(P
)) in
3440 N_Entry_Declaration | N_Subprogram_Declaration
3443 ("internal call cannot appear in default for formal of "
3444 & "protected operation", N
);
3447 -- Prevent the search from going too far
3449 elsif Is_Body_Or_Package_Declaration
(P
) then
3457 end Check_Internal_Protected_Use
;
3459 ---------------------------------------
3460 -- Check_Later_Vs_Basic_Declarations --
3461 ---------------------------------------
3463 procedure Check_Later_Vs_Basic_Declarations
3465 During_Parsing
: Boolean)
3467 Body_Sloc
: Source_Ptr
;
3470 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
3471 -- Return whether Decl is considered as a declarative item.
3472 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3473 -- When During_Parsing is False, the semantics of SPARK is followed.
3475 -------------------------------
3476 -- Is_Later_Declarative_Item --
3477 -------------------------------
3479 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
3481 if Nkind
(Decl
) in N_Later_Decl_Item
then
3484 elsif Nkind
(Decl
) = N_Pragma
then
3487 elsif During_Parsing
then
3490 -- In SPARK, a package declaration is not considered as a later
3491 -- declarative item.
3493 elsif Nkind
(Decl
) = N_Package_Declaration
then
3496 -- In SPARK, a renaming is considered as a later declarative item
3498 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
3504 end Is_Later_Declarative_Item
;
3506 -- Start of processing for Check_Later_Vs_Basic_Declarations
3509 Decl
:= First
(Decls
);
3511 -- Loop through sequence of basic declarative items
3513 Outer
: while Present
(Decl
) loop
3514 if Nkind
(Decl
) not in
3515 N_Subprogram_Body | N_Package_Body | N_Task_Body
3516 and then Nkind
(Decl
) not in N_Body_Stub
3520 -- Once a body is encountered, we only allow later declarative
3521 -- items. The inner loop checks the rest of the list.
3524 Body_Sloc
:= Sloc
(Decl
);
3526 Inner
: while Present
(Decl
) loop
3527 if not Is_Later_Declarative_Item
(Decl
) then
3528 if During_Parsing
then
3529 if Ada_Version
= Ada_83
then
3530 Error_Msg_Sloc
:= Body_Sloc
;
3532 ("(Ada 83) decl cannot appear after body#", Decl
);
3541 end Check_Later_Vs_Basic_Declarations
;
3543 ---------------------------
3544 -- Check_No_Hidden_State --
3545 ---------------------------
3547 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
3548 Context
: Entity_Id
:= Empty
;
3549 Not_Visible
: Boolean := False;
3553 pragma Assert
(Ekind
(Id
) in E_Abstract_State | E_Variable
);
3555 -- Nothing to do for internally-generated abstract states and variables
3556 -- because they do not represent the hidden state of the source unit.
3558 if not Comes_From_Source
(Id
) then
3562 -- Find the proper context where the object or state appears
3565 while Present
(Scop
) loop
3568 -- Keep track of the context's visibility
3570 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
3572 -- Prevent the search from going too far
3574 if Context
= Standard_Standard
then
3577 -- Objects and states that appear immediately within a subprogram or
3578 -- entry inside a construct nested within a subprogram do not
3579 -- introduce a hidden state. They behave as local variable
3580 -- declarations. The same is true for elaboration code inside a block
3583 elsif Is_Subprogram_Or_Entry
(Context
)
3584 or else Ekind
(Context
) in E_Block | E_Task_Type
3589 -- Stop the traversal when a package subject to a null abstract state
3592 if Is_Package_Or_Generic_Package
(Context
)
3593 and then Has_Null_Abstract_State
(Context
)
3598 Scop
:= Scope
(Scop
);
3601 -- At this point we know that there is at least one package with a null
3602 -- abstract state in visibility. Emit an error message unconditionally
3603 -- if the entity being processed is a state because the placement of the
3604 -- related package is irrelevant. This is not the case for objects as
3605 -- the intermediate context matters.
3607 if Present
(Context
)
3608 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
3610 Error_Msg_N
("cannot introduce hidden state &", Id
);
3611 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
3613 end Check_No_Hidden_State
;
3615 ---------------------------------------------
3616 -- Check_Nonoverridable_Aspect_Consistency --
3617 ---------------------------------------------
3619 procedure Check_Inherited_Nonoverridable_Aspects
3620 (Inheritor
: Entity_Id
;
3621 Interface_List
: List_Id
;
3622 Parent_Type
: Entity_Id
) is
3624 -- array needed for iterating over subtype values
3625 Nonoverridable_Aspects
: constant array (Positive range <>) of
3626 Nonoverridable_Aspect_Id
:=
3627 (Aspect_Default_Iterator
,
3628 Aspect_Iterator_Element
,
3629 Aspect_Implicit_Dereference
,
3630 Aspect_Constant_Indexing
,
3631 Aspect_Variable_Indexing
,
3633 Aspect_Max_Entry_Queue_Length
3634 -- , Aspect_No_Controlled_Parts
3637 -- Note that none of these 8 aspects can be specified (for a type)
3638 -- via a pragma. For 7 of them, the corresponding pragma does not
3639 -- exist. The Pragma_Id enumeration type does include
3640 -- Pragma_Max_Entry_Queue_Length, but that pragma is only use to
3641 -- specify the aspect for a protected entry or entry family, not for
3642 -- a type, and therefore cannot introduce the sorts of inheritance
3643 -- issues that we are concerned with in this procedure.
3645 type Entity_Array
is array (Nat
range <>) of Entity_Id
;
3647 function Ancestor_Entities
return Entity_Array
;
3648 -- Returns all progenitors (including parent type, if present)
3650 procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3651 (Aspect
: Nonoverridable_Aspect_Id
;
3652 Ancestor_1
: Entity_Id
;
3653 Aspect_Spec_1
: Node_Id
;
3654 Ancestor_2
: Entity_Id
;
3655 Aspect_Spec_2
: Node_Id
);
3656 -- A given aspect has been specified for each of two ancestors;
3657 -- check that the two aspect specifications are compatible (see
3658 -- RM 13.1.1(18.5) and AI12-0211).
3660 -----------------------
3661 -- Ancestor_Entities --
3662 -----------------------
3664 function Ancestor_Entities
return Entity_Array
is
3665 Ifc_Count
: constant Nat
:= List_Length
(Interface_List
);
3666 Ifc_Ancestors
: Entity_Array
(1 .. Ifc_Count
);
3667 Ifc
: Node_Id
:= First
(Interface_List
);
3669 for Idx
in Ifc_Ancestors
'Range loop
3670 Ifc_Ancestors
(Idx
) := Entity
(Ifc
);
3671 pragma Assert
(Present
(Ifc_Ancestors
(Idx
)));
3674 pragma Assert
(No
(Ifc
));
3675 if Present
(Parent_Type
) then
3676 return Parent_Type
& Ifc_Ancestors
;
3678 return Ifc_Ancestors
;
3680 end Ancestor_Entities
;
3682 -------------------------------------------------------
3683 -- Check_Consistency_For_One_Aspect_Of_Two_Ancestors --
3684 -------------------------------------------------------
3686 procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3687 (Aspect
: Nonoverridable_Aspect_Id
;
3688 Ancestor_1
: Entity_Id
;
3689 Aspect_Spec_1
: Node_Id
;
3690 Ancestor_2
: Entity_Id
;
3691 Aspect_Spec_2
: Node_Id
) is
3693 if not Is_Confirming
(Aspect
, Aspect_Spec_1
, Aspect_Spec_2
) then
3694 Error_Msg_Name_1
:= Aspect_Names
(Aspect
);
3695 Error_Msg_Name_2
:= Chars
(Ancestor_1
);
3696 Error_Msg_Name_3
:= Chars
(Ancestor_2
);
3699 "incompatible % aspects inherited from ancestors % and %",
3702 end Check_Consistency_For_One_Aspect_Of_Two_Ancestors
;
3704 Ancestors
: constant Entity_Array
:= Ancestor_Entities
;
3706 -- start of processing for Check_Inherited_Nonoverridable_Aspects
3708 -- No Ada_Version check here; AI12-0211 is a binding interpretation.
3710 if Ancestors
'Length < 2 then
3711 return; -- Inconsistency impossible; it takes 2 to disagree.
3712 elsif In_Instance_Body
then
3713 return; -- No legality checking in an instance body.
3716 for Aspect
of Nonoverridable_Aspects
loop
3718 First_Ancestor_With_Aspect
: Entity_Id
:= Empty
;
3719 First_Aspect_Spec
, Current_Aspect_Spec
: Node_Id
:= Empty
;
3721 for Ancestor
of Ancestors
loop
3722 Current_Aspect_Spec
:= Find_Aspect
(Ancestor
, Aspect
);
3723 if Present
(Current_Aspect_Spec
) then
3724 if Present
(First_Ancestor_With_Aspect
) then
3725 Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3727 Ancestor_1
=> First_Ancestor_With_Aspect
,
3728 Aspect_Spec_1
=> First_Aspect_Spec
,
3729 Ancestor_2
=> Ancestor
,
3730 Aspect_Spec_2
=> Current_Aspect_Spec
);
3732 First_Ancestor_With_Aspect
:= Ancestor
;
3733 First_Aspect_Spec
:= Current_Aspect_Spec
;
3739 end Check_Inherited_Nonoverridable_Aspects
;
3745 function Check_Parents
(N
: Node_Id
; List
: Elist_Id
) return Boolean is
3748 (Parent_Node
: Node_Id
;
3749 N
: Node_Id
) return Traverse_Result
;
3750 -- Process a single node.
3757 (Parent_Node
: Node_Id
;
3758 N
: Node_Id
) return Traverse_Result
is
3760 if Nkind
(N
) = N_Identifier
3761 and then Parent
(N
) /= Parent_Node
3762 and then Present
(Entity
(N
))
3763 and then Contains
(List
, Entity
(N
))
3771 function Traverse
is new Traverse_Func_With_Parent
(Check_Node
);
3773 -- Start of processing for Check_Parents
3776 return Traverse
(N
) = OK
;
3779 -----------------------------
3780 -- Check_Part_Of_Reference --
3781 -----------------------------
3783 procedure Check_Part_Of_Reference
(Var_Id
: Entity_Id
; Ref
: Node_Id
) is
3784 function Is_Enclosing_Package_Body
3785 (Body_Decl
: Node_Id
;
3786 Obj_Id
: Entity_Id
) return Boolean;
3787 pragma Inline
(Is_Enclosing_Package_Body
);
3788 -- Determine whether package body Body_Decl or its corresponding spec
3789 -- immediately encloses the declaration of object Obj_Id.
3791 function Is_Internal_Declaration_Or_Body
3792 (Decl
: Node_Id
) return Boolean;
3793 pragma Inline
(Is_Internal_Declaration_Or_Body
);
3794 -- Determine whether declaration or body denoted by Decl is internal
3796 function Is_Single_Declaration_Or_Body
3798 Conc_Typ
: Entity_Id
) return Boolean;
3799 pragma Inline
(Is_Single_Declaration_Or_Body
);
3800 -- Determine whether protected/task declaration or body denoted by Decl
3801 -- belongs to single concurrent type Conc_Typ.
3803 function Is_Single_Task_Pragma
3805 Task_Typ
: Entity_Id
) return Boolean;
3806 pragma Inline
(Is_Single_Task_Pragma
);
3807 -- Determine whether pragma Prag belongs to single task type Task_Typ
3809 -------------------------------
3810 -- Is_Enclosing_Package_Body --
3811 -------------------------------
3813 function Is_Enclosing_Package_Body
3814 (Body_Decl
: Node_Id
;
3815 Obj_Id
: Entity_Id
) return Boolean
3817 Obj_Context
: Node_Id
;
3820 -- Find the context of the object declaration
3822 Obj_Context
:= Parent
(Declaration_Node
(Obj_Id
));
3824 if Nkind
(Obj_Context
) = N_Package_Specification
then
3825 Obj_Context
:= Parent
(Obj_Context
);
3828 -- The object appears immediately within the package body
3830 if Obj_Context
= Body_Decl
then
3833 -- The object appears immediately within the corresponding spec
3835 elsif Nkind
(Obj_Context
) = N_Package_Declaration
3836 and then Unit_Declaration_Node
(Corresponding_Spec
(Body_Decl
)) =
3843 end Is_Enclosing_Package_Body
;
3845 -------------------------------------
3846 -- Is_Internal_Declaration_Or_Body --
3847 -------------------------------------
3849 function Is_Internal_Declaration_Or_Body
3850 (Decl
: Node_Id
) return Boolean
3853 if Comes_From_Source
(Decl
) then
3856 -- A body generated for an expression function which has not been
3857 -- inserted into the tree yet (In_Spec_Expression is True) is not
3858 -- considered internal.
3860 elsif Nkind
(Decl
) = N_Subprogram_Body
3861 and then Was_Expression_Function
(Decl
)
3862 and then not In_Spec_Expression
3868 end Is_Internal_Declaration_Or_Body
;
3870 -----------------------------------
3871 -- Is_Single_Declaration_Or_Body --
3872 -----------------------------------
3874 function Is_Single_Declaration_Or_Body
3876 Conc_Typ
: Entity_Id
) return Boolean
3878 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Decl
);
3882 Present
(Anonymous_Object
(Spec_Id
))
3883 and then Anonymous_Object
(Spec_Id
) = Conc_Typ
;
3884 end Is_Single_Declaration_Or_Body
;
3886 ---------------------------
3887 -- Is_Single_Task_Pragma --
3888 ---------------------------
3890 function Is_Single_Task_Pragma
3892 Task_Typ
: Entity_Id
) return Boolean
3894 Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(Prag
);
3897 -- To qualify, the pragma must be associated with single task type
3901 Is_Single_Task_Object
(Task_Typ
)
3902 and then Nkind
(Decl
) = N_Object_Declaration
3903 and then Defining_Entity
(Decl
) = Task_Typ
;
3904 end Is_Single_Task_Pragma
;
3908 Conc_Obj
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
3913 -- Start of processing for Check_Part_Of_Reference
3916 -- Nothing to do when the variable was recorded, but did not become a
3917 -- constituent of a single concurrent type.
3919 if No
(Conc_Obj
) then
3923 -- Traverse the parent chain looking for a suitable context for the
3924 -- reference to the concurrent constituent.
3927 Par
:= Parent
(Prev
);
3928 while Present
(Par
) loop
3929 if Nkind
(Par
) = N_Pragma
then
3930 Prag_Nam
:= Pragma_Name
(Par
);
3932 -- A concurrent constituent is allowed to appear in pragmas
3933 -- Initial_Condition and Initializes as this is part of the
3934 -- elaboration checks for the constituent (SPARK RM 9(3)).
3936 if Prag_Nam
in Name_Initial_Condition | Name_Initializes
then
3939 -- When the reference appears within pragma Depends or Global,
3940 -- check whether the pragma applies to a single task type. Note
3941 -- that the pragma may not encapsulated by the type definition,
3942 -- but this is still a valid context.
3944 elsif Prag_Nam
in Name_Depends | Name_Global
3945 and then Is_Single_Task_Pragma
(Par
, Conc_Obj
)
3950 -- The reference appears somewhere in the definition of a single
3951 -- concurrent type (SPARK RM 9(3)).
3953 elsif Nkind
(Par
) in
3954 N_Single_Protected_Declaration | N_Single_Task_Declaration
3955 and then Defining_Entity
(Par
) = Conc_Obj
3959 -- The reference appears within the declaration or body of a single
3960 -- concurrent type (SPARK RM 9(3)).
3962 elsif Nkind
(Par
) in N_Protected_Body
3963 | N_Protected_Type_Declaration
3965 | N_Task_Type_Declaration
3966 and then Is_Single_Declaration_Or_Body
(Par
, Conc_Obj
)
3970 -- The reference appears within the statement list of the object's
3971 -- immediately enclosing package (SPARK RM 9(3)).
3973 elsif Nkind
(Par
) = N_Package_Body
3974 and then Nkind
(Prev
) = N_Handled_Sequence_Of_Statements
3975 and then Is_Enclosing_Package_Body
(Par
, Var_Id
)
3979 -- The reference has been relocated within an internally generated
3980 -- package or subprogram. Assume that the reference is legal as the
3981 -- real check was already performed in the original context of the
3984 elsif Nkind
(Par
) in N_Package_Body
3985 | N_Package_Declaration
3987 | N_Subprogram_Declaration
3988 and then Is_Internal_Declaration_Or_Body
(Par
)
3992 -- The reference has been relocated to an inlined body for GNATprove.
3993 -- Assume that the reference is legal as the real check was already
3994 -- performed in the original context of the reference.
3996 elsif GNATprove_Mode
3997 and then Nkind
(Par
) = N_Subprogram_Body
3998 and then Chars
(Defining_Entity
(Par
)) = Name_uParent
4004 Par
:= Parent
(Prev
);
4007 -- At this point it is known that the reference does not appear within a
4011 ("reference to variable & cannot appear in this context", Ref
, Var_Id
);
4012 Error_Msg_Name_1
:= Chars
(Var_Id
);
4014 if Is_Single_Protected_Object
(Conc_Obj
) then
4016 ("\% is constituent of single protected type &", Ref
, Conc_Obj
);
4020 ("\% is constituent of single task type &", Ref
, Conc_Obj
);
4022 end Check_Part_Of_Reference
;
4024 ------------------------------------------
4025 -- Check_Potentially_Blocking_Operation --
4026 ------------------------------------------
4028 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
4032 -- N is one of the potentially blocking operations listed in 9.5.1(8).
4033 -- When pragma Detect_Blocking is active, the run time will raise
4034 -- Program_Error. Here we only issue a warning, since we generally
4035 -- support the use of potentially blocking operations in the absence
4038 -- Indirect blocking through a subprogram call cannot be diagnosed
4039 -- statically without interprocedural analysis, so we do not attempt
4042 S
:= Scope
(Current_Scope
);
4043 while Present
(S
) and then S
/= Standard_Standard
loop
4044 if Is_Protected_Type
(S
) then
4046 ("potentially blocking operation in protected operation??", N
);
4052 end Check_Potentially_Blocking_Operation
;
4054 ------------------------------------
4055 -- Check_Previous_Null_Procedure --
4056 ------------------------------------
4058 procedure Check_Previous_Null_Procedure
4063 if Ekind
(Prev
) = E_Procedure
4064 and then Nkind
(Parent
(Prev
)) = N_Procedure_Specification
4065 and then Null_Present
(Parent
(Prev
))
4067 Error_Msg_Sloc
:= Sloc
(Prev
);
4069 ("declaration cannot complete previous null procedure#", Decl
);
4071 end Check_Previous_Null_Procedure
;
4073 ---------------------------------
4074 -- Check_Result_And_Post_State --
4075 ---------------------------------
4077 procedure Check_Result_And_Post_State
(Subp_Id
: Entity_Id
) is
4078 procedure Check_Result_And_Post_State_In_Pragma
4080 Result_Seen
: in out Boolean);
4081 -- Determine whether pragma Prag mentions attribute 'Result and whether
4082 -- the pragma contains an expression that evaluates differently in pre-
4083 -- and post-state. Prag is a [refined] postcondition or a contract-cases
4084 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
4086 -------------------------------------------
4087 -- Check_Result_And_Post_State_In_Pragma --
4088 -------------------------------------------
4090 procedure Check_Result_And_Post_State_In_Pragma
4092 Result_Seen
: in out Boolean)
4094 procedure Check_Conjunct
(Expr
: Node_Id
);
4095 -- Check an individual conjunct in a conjunction of Boolean
4096 -- expressions, connected by "and" or "and then" operators.
4098 procedure Check_Conjuncts
(Expr
: Node_Id
);
4099 -- Apply the post-state check to every conjunct in an expression, in
4100 -- case this is a conjunction of Boolean expressions. Otherwise apply
4101 -- it to the expression as a whole.
4103 procedure Check_Expression
(Expr
: Node_Id
);
4104 -- Perform the 'Result and post-state checks on a given expression
4106 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
4107 -- Attempt to find attribute 'Result in a subtree denoted by N
4109 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
4110 -- Determine whether a subtree denoted by N mentions any construct
4111 -- that denotes a post-state.
4113 procedure Check_Function_Result
is
4114 new Traverse_Proc
(Is_Function_Result
);
4116 --------------------
4117 -- Check_Conjunct --
4118 --------------------
4120 procedure Check_Conjunct
(Expr
: Node_Id
) is
4121 function Adjust_Message
(Msg
: String) return String;
4122 -- Prepend a prefix to the input message Msg denoting that the
4123 -- message applies to a conjunct in the expression, when this
4126 function Applied_On_Conjunct
return Boolean;
4127 -- Returns True if the message applies to a conjunct in the
4128 -- expression, instead of the whole expression.
4130 function Has_Global_Output
(Subp
: Entity_Id
) return Boolean;
4131 -- Returns True if Subp has an output in its Global contract
4133 function Has_No_Output
(Subp
: Entity_Id
) return Boolean;
4134 -- Returns True if Subp has no declared output: no function
4135 -- result, no output parameter, and no output in its Global
4138 --------------------
4139 -- Adjust_Message --
4140 --------------------
4142 function Adjust_Message
(Msg
: String) return String is
4144 if Applied_On_Conjunct
then
4145 return "conjunct in " & Msg
;
4151 -------------------------
4152 -- Applied_On_Conjunct --
4153 -------------------------
4155 function Applied_On_Conjunct
return Boolean is
4157 -- Expr is the conjunct of an enclosing "and" expression
4159 return Nkind
(Parent
(Expr
)) in N_Subexpr
4161 -- or Expr is a conjunct of an enclosing "and then"
4162 -- expression in a postcondition aspect that was split into
4163 -- multiple pragmas. The first conjunct has the "and then"
4164 -- expression as Original_Node, and other conjuncts have
4165 -- Split_PCC set to True.
4167 or else Nkind
(Original_Node
(Expr
)) = N_And_Then
4168 or else Split_PPC
(Prag
);
4169 end Applied_On_Conjunct
;
4171 -----------------------
4172 -- Has_Global_Output --
4173 -----------------------
4175 function Has_Global_Output
(Subp
: Entity_Id
) return Boolean is
4176 Global
: constant Node_Id
:= Get_Pragma
(Subp
, Pragma_Global
);
4185 List
:= Expression
(Get_Argument
(Global
, Subp
));
4187 -- Empty list (no global items) or single global item
4188 -- declaration (only input items).
4190 if Nkind
(List
) in N_Null
4193 | N_Selected_Component
4197 -- Simple global list (only input items) or moded global list
4200 elsif Nkind
(List
) = N_Aggregate
then
4201 if Present
(Expressions
(List
)) then
4205 Assoc
:= First
(Component_Associations
(List
));
4206 while Present
(Assoc
) loop
4207 if Chars
(First
(Choices
(Assoc
))) /= Name_Input
then
4217 -- To accommodate partial decoration of disabled SPARK
4218 -- features, this routine may be called with illegal input.
4219 -- If this is the case, do not raise Program_Error.
4224 end Has_Global_Output
;
4230 function Has_No_Output
(Subp
: Entity_Id
) return Boolean is
4234 -- A function has its result as output
4236 if Ekind
(Subp
) = E_Function
then
4240 -- An OUT or IN OUT parameter is an output
4242 Param
:= First_Formal
(Subp
);
4243 while Present
(Param
) loop
4244 if Ekind
(Param
) in E_Out_Parameter | E_In_Out_Parameter
then
4248 Next_Formal
(Param
);
4251 -- An item of mode Output or In_Out in the Global contract is
4254 if Has_Global_Output
(Subp
) then
4264 -- Error node when reporting a warning on a (refined)
4267 -- Start of processing for Check_Conjunct
4270 if Applied_On_Conjunct
then
4276 -- Do not report missing reference to outcome in postcondition if
4277 -- either the postcondition is trivially True or False, or if the
4278 -- subprogram is ghost and has no declared output.
4280 if not Is_Trivial_Boolean
(Expr
)
4281 and then not Mentions_Post_State
(Expr
)
4282 and then not (Is_Ghost_Entity
(Subp_Id
)
4283 and then Has_No_Output
(Subp_Id
))
4284 and then not Is_Wrapper
(Subp_Id
)
4286 case Pragma_Name
(Prag
) is
4287 when Name_Contract_Cases
=>
4288 Error_Msg_NE
(Adjust_Message
4289 ("contract case does not check the outcome of calling "
4290 & "&?.t?"), Expr
, Subp_Id
);
4292 when Name_Refined_Post
=>
4293 Error_Msg_NE
(Adjust_Message
4294 ("refined postcondition does not check the outcome of "
4295 & "calling &?.t?"), Err_Node
, Subp_Id
);
4297 when Name_Postcondition
=>
4298 Error_Msg_NE
(Adjust_Message
4299 ("postcondition does not check the outcome of calling "
4300 & "&?.t?"), Err_Node
, Subp_Id
);
4302 when others => pragma Assert
(False);
4307 ---------------------
4308 -- Check_Conjuncts --
4309 ---------------------
4311 procedure Check_Conjuncts
(Expr
: Node_Id
) is
4313 if Nkind
(Expr
) in N_Op_And | N_And_Then
then
4314 Check_Conjuncts
(Left_Opnd
(Expr
));
4315 Check_Conjuncts
(Right_Opnd
(Expr
));
4317 Check_Conjunct
(Expr
);
4319 end Check_Conjuncts
;
4321 ----------------------
4322 -- Check_Expression --
4323 ----------------------
4325 procedure Check_Expression
(Expr
: Node_Id
) is
4327 if not Is_Trivial_Boolean
(Expr
) then
4328 Check_Function_Result
(Expr
);
4329 Check_Conjuncts
(Expr
);
4331 end Check_Expression
;
4333 ------------------------
4334 -- Is_Function_Result --
4335 ------------------------
4337 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
4339 if Is_Attribute_Result
(N
) then
4340 Result_Seen
:= True;
4343 -- Warn on infinite recursion if call is to current function
4345 elsif Nkind
(N
) = N_Function_Call
4346 and then Is_Entity_Name
(Name
(N
))
4347 and then Entity
(Name
(N
)) = Subp_Id
4348 and then not Is_Potentially_Unevaluated
(N
)
4351 ("call to & within its postcondition will lead to infinite "
4352 & "recursion?", N
, Subp_Id
);
4355 -- Continue the traversal
4360 end Is_Function_Result
;
4362 -------------------------
4363 -- Mentions_Post_State --
4364 -------------------------
4366 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
4367 Post_State_Seen
: Boolean := False;
4369 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
4370 -- Attempt to find a construct that denotes a post-state. If this
4371 -- is the case, set flag Post_State_Seen.
4377 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
4381 if Nkind
(N
) in N_Explicit_Dereference | N_Function_Call
then
4382 Post_State_Seen
:= True;
4385 elsif Nkind
(N
) in N_Expanded_Name | N_Identifier
then
4388 -- Treat an undecorated reference as OK
4392 -- A reference to an assignable entity is considered a
4393 -- change in the post-state of a subprogram.
4395 or else Ekind
(Ent
) in E_Generic_In_Out_Parameter
4396 | E_In_Out_Parameter
4400 -- The reference may be modified through a dereference
4402 or else (Is_Access_Type
(Etype
(Ent
))
4403 and then Nkind
(Parent
(N
)) =
4404 N_Selected_Component
)
4406 Post_State_Seen
:= True;
4410 elsif Nkind
(N
) = N_Attribute_Reference
then
4411 if Attribute_Name
(N
) = Name_Old
then
4414 elsif Attribute_Name
(N
) = Name_Result
then
4415 Post_State_Seen
:= True;
4423 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
4425 -- Start of processing for Mentions_Post_State
4428 Find_Post_State
(N
);
4430 return Post_State_Seen
;
4431 end Mentions_Post_State
;
4435 Expr
: constant Node_Id
:=
4437 (First
(Pragma_Argument_Associations
(Prag
)));
4438 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
4441 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4444 -- Examine all consequences
4446 if Nam
= Name_Contract_Cases
then
4447 CCase
:= First
(Component_Associations
(Expr
));
4448 while Present
(CCase
) loop
4449 Check_Expression
(Expression
(CCase
));
4454 -- Examine the expression of a postcondition
4456 else pragma Assert
(Nam
in Name_Postcondition | Name_Refined_Post
);
4457 Check_Expression
(Expr
);
4459 end Check_Result_And_Post_State_In_Pragma
;
4463 Items
: constant Node_Id
:= Contract
(Subp_Id
);
4464 Case_Prag
: Node_Id
:= Empty
;
4465 Post_Prag
: Node_Id
:= Empty
;
4467 Seen_In_Case
: Boolean := False;
4468 Seen_In_Post
: Boolean := False;
4469 Spec_Id
: constant Entity_Id
:= Unique_Entity
(Subp_Id
);
4471 -- Start of processing for Check_Result_And_Post_State
4474 -- Do not check in instances, because we already checked the generic
4479 -- The lack of attribute 'Result or a post-state is classified as a
4480 -- suspicious contract. Do not perform the check if the corresponding
4481 -- switch is not set.
4483 elsif not Warn_On_Suspicious_Contract
then
4486 -- Nothing to do if there is no contract
4488 elsif No
(Items
) then
4491 -- If the subprogram has a contract Exceptional_Cases, it is often
4492 -- useful to refer only to the pre-state in the postcondition, to
4493 -- indicate when the subprogram might terminate normally.
4495 elsif Present
(Get_Pragma
(Subp_Id
, Pragma_Exceptional_Cases
)) then
4498 -- Same if the subprogram has a contract Always_Terminates => Cond,
4499 -- where Cond is not syntactically True.
4503 Prag
: constant Node_Id
:=
4504 Get_Pragma
(Subp_Id
, Pragma_Always_Terminates
);
4507 and then Present
(Pragma_Argument_Associations
(Prag
))
4510 Cond
: constant Node_Id
:=
4512 (First
(Pragma_Argument_Associations
(Prag
)));
4514 if not Compile_Time_Known_Value
(Cond
)
4515 or else not Is_True
(Expr_Value
(Cond
))
4524 -- Examine all postconditions for attribute 'Result and a post-state
4526 Prag
:= Pre_Post_Conditions
(Items
);
4527 while Present
(Prag
) loop
4528 if Pragma_Name_Unmapped
(Prag
)
4529 in Name_Postcondition | Name_Refined_Post
4530 and then not Error_Posted
(Prag
)
4533 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Post
);
4536 Prag
:= Next_Pragma
(Prag
);
4539 -- Examine the contract cases of the subprogram for attribute 'Result
4540 -- and a post-state.
4542 Prag
:= Contract_Test_Cases
(Items
);
4543 while Present
(Prag
) loop
4544 if Pragma_Name
(Prag
) = Name_Contract_Cases
4545 and then not Error_Posted
(Prag
)
4548 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Case
);
4551 Prag
:= Next_Pragma
(Prag
);
4554 -- Do not emit any errors if the subprogram is not a function
4556 if Ekind
(Spec_Id
) not in E_Function | E_Generic_Function
then
4559 -- Regardless of whether the function has postconditions or contract
4560 -- cases, or whether they mention attribute 'Result, an [IN] OUT formal
4561 -- parameter is always treated as a result.
4563 elsif Has_Out_Or_In_Out_Parameter
(Spec_Id
) then
4566 -- The function has both a postcondition and contract cases and they do
4567 -- not mention attribute 'Result.
4569 elsif Present
(Case_Prag
)
4570 and then not Seen_In_Case
4571 and then Present
(Post_Prag
)
4572 and then not Seen_In_Post
4575 ("neither postcondition nor contract cases mention function "
4576 & "result?.t?", Post_Prag
);
4578 -- The function has contract cases only and they do not mention
4579 -- attribute 'Result.
4581 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
4583 ("contract cases do not mention function result?.t?", Case_Prag
);
4585 -- The function has non-trivial postconditions only and they do not
4586 -- mention attribute 'Result.
4588 elsif Present
(Post_Prag
)
4589 and then not Seen_In_Post
4590 and then not Is_Trivial_Boolean
4591 (Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Post_Prag
))))
4594 ("postcondition does not mention function result?.t?", Post_Prag
);
4596 end Check_Result_And_Post_State
;
4598 -----------------------------
4599 -- Check_State_Refinements --
4600 -----------------------------
4602 procedure Check_State_Refinements
4604 Is_Main_Unit
: Boolean := False)
4606 procedure Check_Package
(Pack
: Node_Id
);
4607 -- Verify that all abstract states of a [generic] package denoted by its
4608 -- declarative node Pack have proper refinement. Recursively verify the
4609 -- visible and private declarations of the [generic] package for other
4612 procedure Check_Packages_In
(Decls
: List_Id
);
4613 -- Seek out [generic] package declarations within declarative list Decls
4614 -- and verify the status of their abstract state refinement.
4616 function SPARK_Mode_Is_Off
(N
: Node_Id
) return Boolean;
4617 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4623 procedure Check_Package
(Pack
: Node_Id
) is
4624 Body_Id
: constant Entity_Id
:= Corresponding_Body
(Pack
);
4625 Spec
: constant Node_Id
:= Specification
(Pack
);
4626 States
: constant Elist_Id
:=
4627 Abstract_States
(Defining_Entity
(Pack
));
4629 State_Elmt
: Elmt_Id
;
4630 State_Id
: Entity_Id
;
4633 -- Do not verify proper state refinement when the package is subject
4634 -- to pragma SPARK_Mode Off because this disables the requirement for
4635 -- state refinement.
4637 if SPARK_Mode_Is_Off
(Pack
) then
4640 -- State refinement can only occur in a completing package body. Do
4641 -- not verify proper state refinement when the body is subject to
4642 -- pragma SPARK_Mode Off because this disables the requirement for
4643 -- state refinement.
4645 elsif Present
(Body_Id
)
4646 and then SPARK_Mode_Is_Off
(Unit_Declaration_Node
(Body_Id
))
4650 -- Do not verify proper state refinement when the package is an
4651 -- instance as this check was already performed in the generic.
4653 elsif Present
(Generic_Parent
(Spec
)) then
4656 -- Otherwise examine the contents of the package
4659 if Present
(States
) then
4660 State_Elmt
:= First_Elmt
(States
);
4661 while Present
(State_Elmt
) loop
4662 State_Id
:= Node
(State_Elmt
);
4664 -- Emit an error when a non-null state lacks refinement,
4665 -- but has Part_Of constituents or there is a package
4666 -- body (SPARK RM 7.1.4(4)). Constituents in private
4667 -- child packages, which are not known at this stage,
4668 -- independently require the existence of a package body.
4670 if not Is_Null_State
(State_Id
)
4671 and then No
(Refinement_Constituents
(State_Id
))
4673 (Present
(Part_Of_Constituents
(State_Id
))
4677 Error_Msg_N
("state & requires refinement", State_Id
);
4678 Error_Msg_N
("\package body should have Refined_State "
4679 & "for state & with constituents", State_Id
);
4682 Next_Elmt
(State_Elmt
);
4686 Check_Packages_In
(Visible_Declarations
(Spec
));
4687 Check_Packages_In
(Private_Declarations
(Spec
));
4691 -----------------------
4692 -- Check_Packages_In --
4693 -----------------------
4695 procedure Check_Packages_In
(Decls
: List_Id
) is
4699 if Present
(Decls
) then
4700 Decl
:= First
(Decls
);
4701 while Present
(Decl
) loop
4702 if Nkind
(Decl
) in N_Generic_Package_Declaration
4703 | N_Package_Declaration
4705 Check_Package
(Decl
);
4711 end Check_Packages_In
;
4713 -----------------------
4714 -- SPARK_Mode_Is_Off --
4715 -----------------------
4717 function SPARK_Mode_Is_Off
(N
: Node_Id
) return Boolean is
4718 Id
: constant Entity_Id
:= Defining_Entity
(N
);
4719 Prag
: constant Node_Id
:= SPARK_Pragma
(Id
);
4722 -- Default the mode to "off" when the context is an instance and all
4723 -- SPARK_Mode pragmas found within are to be ignored.
4725 if Ignore_SPARK_Mode_Pragmas
(Id
) then
4731 and then Get_SPARK_Mode_From_Annotation
(Prag
) = Off
;
4733 end SPARK_Mode_Is_Off
;
4735 -- Start of processing for Check_State_Refinements
4738 -- A block may declare a nested package
4740 if Nkind
(Context
) = N_Block_Statement
then
4741 Check_Packages_In
(Declarations
(Context
));
4743 -- An entry, protected, subprogram, or task body may declare a nested
4746 elsif Nkind
(Context
) in N_Entry_Body
4751 -- Do not verify proper state refinement when the body is subject to
4752 -- pragma SPARK_Mode Off because this disables the requirement for
4753 -- state refinement.
4755 if not SPARK_Mode_Is_Off
(Context
) then
4756 Check_Packages_In
(Declarations
(Context
));
4759 -- A package body may declare a nested package
4761 elsif Nkind
(Context
) = N_Package_Body
then
4762 Check_Package
(Unit_Declaration_Node
(Corresponding_Spec
(Context
)));
4764 -- Do not verify proper state refinement when the body is subject to
4765 -- pragma SPARK_Mode Off because this disables the requirement for
4766 -- state refinement.
4768 if not SPARK_Mode_Is_Off
(Context
) then
4769 Check_Packages_In
(Declarations
(Context
));
4772 -- A library level [generic] package may declare a nested package
4774 elsif Nkind
(Context
) in
4775 N_Generic_Package_Declaration | N_Package_Declaration
4776 and then Is_Main_Unit
4778 Check_Package
(Context
);
4780 end Check_State_Refinements
;
4782 ------------------------------
4783 -- Check_Unprotected_Access --
4784 ------------------------------
4786 procedure Check_Unprotected_Access
4790 Cont_Encl_Typ
: Entity_Id
;
4791 Pref_Encl_Typ
: Entity_Id
;
4793 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
4794 -- Check whether Obj is a private component of a protected object.
4795 -- Return the protected type where the component resides, Empty
4798 function Is_Public_Operation
return Boolean;
4799 -- Verify that the enclosing operation is callable from outside the
4800 -- protected object, to minimize false positives.
4802 ------------------------------
4803 -- Enclosing_Protected_Type --
4804 ------------------------------
4806 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
4808 if Is_Entity_Name
(Obj
) then
4810 Ent
: Entity_Id
:= Entity
(Obj
);
4813 -- The object can be a renaming of a private component, use
4814 -- the original record component.
4816 if Is_Prival
(Ent
) then
4817 Ent
:= Prival_Link
(Ent
);
4820 if Is_Protected_Type
(Scope
(Ent
)) then
4826 -- For indexed and selected components, recursively check the prefix
4828 if Nkind
(Obj
) in N_Indexed_Component | N_Selected_Component
then
4829 return Enclosing_Protected_Type
(Prefix
(Obj
));
4831 -- The object does not denote a protected component
4836 end Enclosing_Protected_Type
;
4838 -------------------------
4839 -- Is_Public_Operation --
4840 -------------------------
4842 function Is_Public_Operation
return Boolean is
4848 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
4849 if Scope
(S
) = Pref_Encl_Typ
then
4850 E
:= First_Entity
(Pref_Encl_Typ
);
4852 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
4866 end Is_Public_Operation
;
4868 -- Start of processing for Check_Unprotected_Access
4871 if Nkind
(Expr
) = N_Attribute_Reference
4872 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
4874 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
4875 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
4877 -- Check whether we are trying to export a protected component to a
4878 -- context with an equal or lower access level.
4880 if Present
(Pref_Encl_Typ
)
4881 and then No
(Cont_Encl_Typ
)
4882 and then Is_Public_Operation
4883 and then Scope_Depth
(Pref_Encl_Typ
)
4884 >= Static_Accessibility_Level
4885 (Context
, Object_Decl_Level
)
4888 ("??possible unprotected access to protected data", Expr
);
4891 end Check_Unprotected_Access
;
4893 ------------------------------
4894 -- Check_Unused_Body_States --
4895 ------------------------------
4897 procedure Check_Unused_Body_States
(Body_Id
: Entity_Id
) is
4898 procedure Process_Refinement_Clause
4901 -- Inspect all constituents of refinement clause Clause and remove any
4902 -- matches from body state list States.
4904 procedure Report_Unused_Body_States
(States
: Elist_Id
);
4905 -- Emit errors for each abstract state or object found in list States
4907 -------------------------------
4908 -- Process_Refinement_Clause --
4909 -------------------------------
4911 procedure Process_Refinement_Clause
4915 procedure Process_Constituent
(Constit
: Node_Id
);
4916 -- Remove constituent Constit from body state list States
4918 -------------------------
4919 -- Process_Constituent --
4920 -------------------------
4922 procedure Process_Constituent
(Constit
: Node_Id
) is
4923 Constit_Id
: Entity_Id
;
4926 -- Guard against illegal constituents. Only abstract states and
4927 -- objects can appear on the right hand side of a refinement.
4929 if Is_Entity_Name
(Constit
) then
4930 Constit_Id
:= Entity_Of
(Constit
);
4932 if Present
(Constit_Id
)
4933 and then Ekind
(Constit_Id
) in
4934 E_Abstract_State | E_Constant | E_Variable
4936 Remove
(States
, Constit_Id
);
4939 end Process_Constituent
;
4945 -- Start of processing for Process_Refinement_Clause
4948 if Nkind
(Clause
) = N_Component_Association
then
4949 Constit
:= Expression
(Clause
);
4951 -- Multiple constituents appear as an aggregate
4953 if Nkind
(Constit
) = N_Aggregate
then
4954 Constit
:= First
(Expressions
(Constit
));
4955 while Present
(Constit
) loop
4956 Process_Constituent
(Constit
);
4960 -- Various forms of a single constituent
4963 Process_Constituent
(Constit
);
4966 end Process_Refinement_Clause
;
4968 -------------------------------
4969 -- Report_Unused_Body_States --
4970 -------------------------------
4972 procedure Report_Unused_Body_States
(States
: Elist_Id
) is
4973 Posted
: Boolean := False;
4974 State_Elmt
: Elmt_Id
;
4975 State_Id
: Entity_Id
;
4978 if Present
(States
) then
4979 State_Elmt
:= First_Elmt
(States
);
4980 while Present
(State_Elmt
) loop
4981 State_Id
:= Node
(State_Elmt
);
4983 -- Constants are part of the hidden state of a package, but the
4984 -- compiler cannot determine whether they have variable input
4985 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4986 -- hidden state. Do not emit an error when a constant does not
4987 -- participate in a state refinement, even though it acts as a
4990 if Ekind
(State_Id
) = E_Constant
then
4993 -- Overlays do not contribute to package state
4995 elsif Ekind
(State_Id
) = E_Variable
4996 and then Present
(Ultimate_Overlaid_Entity
(State_Id
))
5000 -- Generate an error message of the form:
5002 -- body of package ... has unused hidden states
5003 -- abstract state ... defined at ...
5004 -- variable ... defined at ...
5010 ("body of package & has unused hidden states", Body_Id
);
5013 Error_Msg_Sloc
:= Sloc
(State_Id
);
5015 if Ekind
(State_Id
) = E_Abstract_State
then
5017 ("\abstract state & defined #", Body_Id
, State_Id
);
5020 SPARK_Msg_NE
("\variable & defined #", Body_Id
, State_Id
);
5024 Next_Elmt
(State_Elmt
);
5027 end Report_Unused_Body_States
;
5031 Prag
: constant Node_Id
:= Get_Pragma
(Body_Id
, Pragma_Refined_State
);
5032 Spec_Id
: constant Entity_Id
:= Spec_Entity
(Body_Id
);
5036 -- Start of processing for Check_Unused_Body_States
5039 -- Inspect the clauses of pragma Refined_State and determine whether all
5040 -- visible states declared within the package body participate in the
5043 if Present
(Prag
) then
5044 Clause
:= Expression
(Get_Argument
(Prag
, Spec_Id
));
5045 States
:= Collect_Body_States
(Body_Id
);
5047 -- Multiple non-null state refinements appear as an aggregate
5049 if Nkind
(Clause
) = N_Aggregate
then
5050 Clause
:= First
(Component_Associations
(Clause
));
5051 while Present
(Clause
) loop
5052 Process_Refinement_Clause
(Clause
, States
);
5056 -- Various forms of a single state refinement
5059 Process_Refinement_Clause
(Clause
, States
);
5062 -- Ensure that all abstract states and objects declared in the
5063 -- package body state space are utilized as constituents.
5065 Report_Unused_Body_States
(States
);
5067 end Check_Unused_Body_States
;
5073 function Choice_List
(N
: Node_Id
) return List_Id
is
5075 if Nkind
(N
) = N_Iterated_Component_Association
then
5076 return Discrete_Choices
(N
);
5082 ---------------------
5083 -- Class_Condition --
5084 ---------------------
5086 function Class_Condition
5087 (Kind
: Condition_Kind
;
5088 Subp
: Entity_Id
) return Node_Id
is
5092 when Class_Postcondition
=>
5093 return Class_Postconditions
(Subp
);
5095 when Class_Precondition
=>
5096 return Class_Preconditions
(Subp
);
5098 when Ignored_Class_Postcondition
=>
5099 return Ignored_Class_Postconditions
(Subp
);
5101 when Ignored_Class_Precondition
=>
5102 return Ignored_Class_Preconditions
(Subp
);
5104 end Class_Condition
;
5106 -------------------------
5107 -- Collect_Body_States --
5108 -------------------------
5110 function Collect_Body_States
(Body_Id
: Entity_Id
) return Elist_Id
is
5111 function Is_Visible_Object
(Obj_Id
: Entity_Id
) return Boolean;
5112 -- Determine whether object Obj_Id is a suitable visible state of a
5115 procedure Collect_Visible_States
5116 (Pack_Id
: Entity_Id
;
5117 States
: in out Elist_Id
);
5118 -- Gather the entities of all abstract states and objects declared in
5119 -- the visible state space of package Pack_Id.
5121 ----------------------------
5122 -- Collect_Visible_States --
5123 ----------------------------
5125 procedure Collect_Visible_States
5126 (Pack_Id
: Entity_Id
;
5127 States
: in out Elist_Id
)
5129 Item_Id
: Entity_Id
;
5132 -- Traverse the entity chain of the package and inspect all visible
5135 Item_Id
:= First_Entity
(Pack_Id
);
5136 while Present
(Item_Id
) and then not In_Private_Part
(Item_Id
) loop
5138 -- Do not consider internally generated items as those cannot be
5139 -- named and participate in refinement.
5141 if not Comes_From_Source
(Item_Id
) then
5144 elsif Ekind
(Item_Id
) = E_Abstract_State
then
5145 Append_New_Elmt
(Item_Id
, States
);
5147 elsif Ekind
(Item_Id
) in E_Constant | E_Variable
5148 and then Is_Visible_Object
(Item_Id
)
5150 Append_New_Elmt
(Item_Id
, States
);
5152 -- Recursively gather the visible states of a nested package
5153 -- except for nested package renamings.
5155 elsif Ekind
(Item_Id
) = E_Package
5156 and then No
(Renamed_Entity
(Item_Id
))
5158 Collect_Visible_States
(Item_Id
, States
);
5161 Next_Entity
(Item_Id
);
5163 end Collect_Visible_States
;
5165 -----------------------
5166 -- Is_Visible_Object --
5167 -----------------------
5169 function Is_Visible_Object
(Obj_Id
: Entity_Id
) return Boolean is
5171 -- Objects that map generic formals to their actuals are not visible
5172 -- from outside the generic instantiation.
5174 if Present
(Corresponding_Generic_Association
5175 (Declaration_Node
(Obj_Id
)))
5179 -- Constituents of a single protected/task type act as components of
5180 -- the type and are not visible from outside the type.
5182 elsif Ekind
(Obj_Id
) = E_Variable
5183 and then Present
(Encapsulating_State
(Obj_Id
))
5184 and then Is_Single_Concurrent_Object
(Encapsulating_State
(Obj_Id
))
5191 end Is_Visible_Object
;
5195 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Body_Id
);
5197 Item_Id
: Entity_Id
;
5198 States
: Elist_Id
:= No_Elist
;
5200 -- Start of processing for Collect_Body_States
5203 -- Inspect the declarations of the body looking for source objects,
5204 -- packages and package instantiations. Note that even though this
5205 -- processing is very similar to Collect_Visible_States, a package
5206 -- body does not have a First/Next_Entity list.
5208 Decl
:= First
(Declarations
(Body_Decl
));
5209 while Present
(Decl
) loop
5211 -- Capture source objects as internally generated temporaries cannot
5212 -- be named and participate in refinement.
5214 if Nkind
(Decl
) = N_Object_Declaration
then
5215 Item_Id
:= Defining_Entity
(Decl
);
5217 if Comes_From_Source
(Item_Id
)
5218 and then Is_Visible_Object
(Item_Id
)
5220 Append_New_Elmt
(Item_Id
, States
);
5223 -- Capture the visible abstract states and objects of a source
5224 -- package [instantiation].
5226 elsif Nkind
(Decl
) = N_Package_Declaration
then
5227 Item_Id
:= Defining_Entity
(Decl
);
5229 if Comes_From_Source
(Item_Id
) then
5230 Collect_Visible_States
(Item_Id
, States
);
5238 end Collect_Body_States
;
5240 ------------------------
5241 -- Collect_Interfaces --
5242 ------------------------
5244 procedure Collect_Interfaces
5246 Ifaces_List
: out Elist_Id
;
5247 Exclude_Parents
: Boolean := False;
5248 Use_Full_View
: Boolean := True)
5250 procedure Collect
(Typ
: Entity_Id
);
5251 -- Subsidiary subprogram used to traverse the whole list
5252 -- of directly and indirectly implemented interfaces
5258 procedure Collect
(Typ
: Entity_Id
) is
5259 Ancestor
: Entity_Id
;
5267 -- Handle private types and subtypes
5270 and then Is_Private_Type
(Typ
)
5271 and then Present
(Full_View
(Typ
))
5273 Full_T
:= Full_View
(Typ
);
5275 if Ekind
(Full_T
) = E_Record_Subtype
then
5276 Full_T
:= Etype
(Typ
);
5278 if Present
(Full_View
(Full_T
)) then
5279 Full_T
:= Full_View
(Full_T
);
5284 -- Include the ancestor if we are generating the whole list of
5285 -- abstract interfaces.
5287 if Etype
(Full_T
) /= Typ
5289 -- Protect the frontend against wrong sources. For example:
5292 -- type A is tagged null record;
5293 -- type B is new A with private;
5294 -- type C is new A with private;
5296 -- type B is new C with null record;
5297 -- type C is new B with null record;
5300 and then Etype
(Full_T
) /= T
5302 Ancestor
:= Etype
(Full_T
);
5305 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
5306 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
5310 -- Traverse the graph of ancestor interfaces
5312 Id
:= First
(Abstract_Interface_List
(Full_T
));
5313 while Present
(Id
) loop
5314 Iface
:= Etype
(Id
);
5316 -- Protect against wrong uses. For example:
5317 -- type I is interface;
5318 -- type O is tagged null record;
5319 -- type Wrong is new I and O with null record; -- ERROR
5321 if Is_Interface
(Iface
) then
5323 and then Etype
(T
) /= T
5324 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
5329 Append_Unique_Elmt
(Iface
, Ifaces_List
);
5337 -- Start of processing for Collect_Interfaces
5340 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
5341 Ifaces_List
:= New_Elmt_List
;
5343 end Collect_Interfaces
;
5345 ----------------------------------
5346 -- Collect_Interface_Components --
5347 ----------------------------------
5349 procedure Collect_Interface_Components
5350 (Tagged_Type
: Entity_Id
;
5351 Components_List
: out Elist_Id
)
5353 procedure Collect
(Typ
: Entity_Id
);
5354 -- Subsidiary subprogram used to climb to the parents
5360 procedure Collect
(Typ
: Entity_Id
) is
5361 Tag_Comp
: Entity_Id
;
5362 Parent_Typ
: Entity_Id
;
5365 -- Handle private types
5367 if Present
(Full_View
(Etype
(Typ
))) then
5368 Parent_Typ
:= Full_View
(Etype
(Typ
));
5370 Parent_Typ
:= Etype
(Typ
);
5373 if Parent_Typ
/= Typ
5375 -- Protect the frontend against wrong sources. For example:
5378 -- type A is tagged null record;
5379 -- type B is new A with private;
5380 -- type C is new A with private;
5382 -- type B is new C with null record;
5383 -- type C is new B with null record;
5386 and then Parent_Typ
/= Tagged_Type
5388 Collect
(Parent_Typ
);
5391 -- Collect the components containing tags of secondary dispatch
5394 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
5395 while Present
(Tag_Comp
) loop
5396 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
5397 Append_Elmt
(Tag_Comp
, Components_List
);
5399 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
5403 -- Start of processing for Collect_Interface_Components
5406 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
5407 and then Is_Tagged_Type
(Tagged_Type
));
5409 Components_List
:= New_Elmt_List
;
5410 Collect
(Tagged_Type
);
5411 end Collect_Interface_Components
;
5413 -----------------------------
5414 -- Collect_Interfaces_Info --
5415 -----------------------------
5417 procedure Collect_Interfaces_Info
5419 Ifaces_List
: out Elist_Id
;
5420 Components_List
: out Elist_Id
;
5421 Tags_List
: out Elist_Id
)
5423 Comps_List
: Elist_Id
;
5424 Comp_Elmt
: Elmt_Id
;
5425 Comp_Iface
: Entity_Id
;
5426 Iface_Elmt
: Elmt_Id
;
5429 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
5430 -- Search for the secondary tag associated with the interface type
5431 -- Iface that is implemented by T.
5437 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
5440 if not Is_CPP_Class
(T
) then
5441 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
5443 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
5447 and then Is_Tag
(Node
(ADT
))
5448 and then Related_Type
(Node
(ADT
)) /= Iface
5450 -- Skip secondary dispatch table referencing thunks to user
5451 -- defined primitives covered by this interface.
5453 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
5456 -- Skip secondary dispatch tables of Ada types
5458 if not Is_CPP_Class
(T
) then
5460 -- Skip secondary dispatch table referencing thunks to
5461 -- predefined primitives.
5463 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
5466 -- Skip secondary dispatch table referencing user-defined
5467 -- primitives covered by this interface.
5469 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
5472 -- Skip secondary dispatch table referencing predefined
5475 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
5480 pragma Assert
(Is_Tag
(Node
(ADT
)));
5484 -- Start of processing for Collect_Interfaces_Info
5487 Collect_Interfaces
(T
, Ifaces_List
);
5488 Collect_Interface_Components
(T
, Comps_List
);
5490 -- Search for the record component and tag associated with each
5491 -- interface type of T.
5493 Components_List
:= New_Elmt_List
;
5494 Tags_List
:= New_Elmt_List
;
5496 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
5497 while Present
(Iface_Elmt
) loop
5498 Iface
:= Node
(Iface_Elmt
);
5500 -- Associate the primary tag component and the primary dispatch table
5501 -- with all the interfaces that are parents of T
5503 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
5504 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
5505 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
5507 -- Otherwise search for the tag component and secondary dispatch
5511 Comp_Elmt
:= First_Elmt
(Comps_List
);
5512 while Present
(Comp_Elmt
) loop
5513 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
5515 if Comp_Iface
= Iface
5516 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
5518 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
5519 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
5523 Next_Elmt
(Comp_Elmt
);
5525 pragma Assert
(Present
(Comp_Elmt
));
5528 Next_Elmt
(Iface_Elmt
);
5530 end Collect_Interfaces_Info
;
5532 ---------------------
5533 -- Collect_Parents --
5534 ---------------------
5536 procedure Collect_Parents
5538 List
: out Elist_Id
;
5539 Use_Full_View
: Boolean := True)
5541 Current_Typ
: Entity_Id
:= T
;
5542 Parent_Typ
: Entity_Id
;
5545 List
:= New_Elmt_List
;
5547 -- No action if the if the type has no parents
5549 if T
= Etype
(T
) then
5554 Parent_Typ
:= Etype
(Current_Typ
);
5556 if Is_Private_Type
(Parent_Typ
)
5557 and then Present
(Full_View
(Parent_Typ
))
5558 and then Use_Full_View
5560 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5563 Append_Elmt
(Parent_Typ
, List
);
5565 exit when Parent_Typ
= Current_Typ
;
5566 Current_Typ
:= Parent_Typ
;
5568 end Collect_Parents
;
5570 ----------------------------------
5571 -- Collect_Primitive_Operations --
5572 ----------------------------------
5574 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
5575 B_Type
: constant Entity_Id
:= Base_Type
(T
);
5577 function Match
(E
: Entity_Id
) return Boolean;
5578 -- True if E's base type is B_Type, or E is of an anonymous access type
5579 -- and the base type of its designated type is B_Type.
5585 function Match
(E
: Entity_Id
) return Boolean is
5586 Etyp
: Entity_Id
:= Etype
(E
);
5589 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
5590 Etyp
:= Designated_Type
(Etyp
);
5593 -- In Ada 2012 a primitive operation may have a formal of an
5594 -- incomplete view of the parent type.
5596 return Base_Type
(Etyp
) = B_Type
5598 (Ada_Version
>= Ada_2012
5599 and then Ekind
(Etyp
) = E_Incomplete_Type
5600 and then Full_View
(Etyp
) = B_Type
);
5605 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
5606 B_Scope
: Entity_Id
:= Scope
(B_Type
);
5608 Eq_Prims_List
: Elist_Id
:= No_Elist
;
5611 Is_Type_In_Pkg
: Boolean;
5612 Formal_Derived
: Boolean := False;
5615 -- Start of processing for Collect_Primitive_Operations
5618 -- For tagged types, the primitive operations are collected as they
5619 -- are declared, and held in an explicit list which is simply returned.
5621 if Is_Tagged_Type
(B_Type
) then
5622 return Primitive_Operations
(B_Type
);
5624 -- An untagged generic type that is a derived type inherits the
5625 -- primitive operations of its parent type. Other formal types only
5626 -- have predefined operators, which are not explicitly represented.
5628 elsif Is_Generic_Type
(B_Type
) then
5629 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
5630 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
5631 N_Formal_Derived_Type_Definition
5633 Formal_Derived
:= True;
5635 return New_Elmt_List
;
5639 Op_List
:= New_Elmt_List
;
5641 if B_Scope
= Standard_Standard
then
5642 if B_Type
= Standard_String
then
5643 Append_Elmt
(Standard_Op_Concat
, Op_List
);
5645 elsif B_Type
= Standard_Wide_String
then
5646 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
5652 -- Locate the primitive subprograms of the type
5655 -- The primitive operations appear after the base type, except if the
5656 -- derivation happens within the private part of B_Scope and the type
5657 -- is a private type, in which case both the type and some primitive
5658 -- operations may appear before the base type, and the list of
5659 -- candidates starts after the type.
5661 if In_Open_Scopes
(B_Scope
)
5662 and then Scope
(T
) = B_Scope
5663 and then In_Private_Part
(B_Scope
)
5665 Id
:= Next_Entity
(T
);
5667 -- In Ada 2012, If the type has an incomplete partial view, there may
5668 -- be primitive operations declared before the full view, so we need
5669 -- to start scanning from the incomplete view, which is earlier on
5670 -- the entity chain.
5672 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
5673 and then Present
(Incomplete_View
(Parent
(B_Type
)))
5675 Id
:= Incomplete_View
(Parent
(B_Type
));
5677 -- If T is a derived from a type with an incomplete view declared
5678 -- elsewhere, that incomplete view is irrelevant, we want the
5679 -- operations in the scope of T.
5681 if Scope
(Id
) /= Scope
(B_Type
) then
5682 Id
:= Next_Entity
(B_Type
);
5686 Id
:= Next_Entity
(B_Type
);
5689 -- Set flag if this is a type in a package spec
5692 Is_Package_Or_Generic_Package
(B_Scope
)
5694 Parent_Kind
(Declaration_Node
(First_Subtype
(T
))) /=
5697 while Present
(Id
) loop
5699 -- Test whether the result type or any of the parameter types of
5700 -- each subprogram following the type match that type when the
5701 -- type is declared in a package spec, is a derived type, or the
5702 -- subprogram is marked as primitive. (The Is_Primitive test is
5703 -- needed to find primitives of nonderived types in declarative
5704 -- parts that happen to override the predefined "=" operator.)
5706 -- Note that generic formal subprograms are not considered to be
5707 -- primitive operations and thus are never inherited.
5709 if Is_Overloadable
(Id
)
5710 and then (Is_Type_In_Pkg
5711 or else Is_Derived_Type
(B_Type
)
5712 or else Is_Primitive
(Id
))
5713 and then Parent_Kind
(Parent
(Id
))
5714 not in N_Formal_Subprogram_Declaration
5722 Formal
:= First_Formal
(Id
);
5723 while Present
(Formal
) loop
5724 if Match
(Formal
) then
5729 Next_Formal
(Formal
);
5733 -- For a formal derived type, the only primitives are the ones
5734 -- inherited from the parent type. Operations appearing in the
5735 -- package declaration are not primitive for it.
5738 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
5740 -- In the special case of an equality operator aliased to
5741 -- an overriding dispatching equality belonging to the same
5742 -- type, we don't include it in the list of primitives.
5743 -- This avoids inheriting multiple equality operators when
5744 -- deriving from untagged private types whose full type is
5745 -- tagged, which can otherwise cause ambiguities. Note that
5746 -- this should only happen for this kind of untagged parent
5747 -- type, since normally dispatching operations are inherited
5748 -- using the type's Primitive_Operations list.
5750 if Chars
(Id
) = Name_Op_Eq
5751 and then Is_Dispatching_Operation
(Id
)
5752 and then Present
(Alias
(Id
))
5753 and then Present
(Overridden_Operation
(Alias
(Id
)))
5754 and then Base_Type
(Etype
(First_Entity
(Id
))) =
5755 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
5759 -- Include the subprogram in the list of primitives
5762 Append_Elmt
(Id
, Op_List
);
5764 -- Save collected equality primitives for later filtering
5765 -- (if we are processing a private type for which we can
5766 -- collect several candidates).
5768 if Inherits_From_Tagged_Full_View
(T
)
5769 and then Chars
(Id
) = Name_Op_Eq
5770 and then Etype
(First_Formal
(Id
)) =
5771 Etype
(Next_Formal
(First_Formal
(Id
)))
5773 Append_New_Elmt
(Id
, Eq_Prims_List
);
5781 -- For a type declared in System, some of its operations may
5782 -- appear in the target-specific extension to System.
5785 and then Is_RTU
(B_Scope
, System
)
5786 and then Present_System_Aux
5788 B_Scope
:= System_Aux_Id
;
5789 Id
:= First_Entity
(System_Aux_Id
);
5793 -- Filter collected equality primitives
5795 if Inherits_From_Tagged_Full_View
(T
)
5796 and then Present
(Eq_Prims_List
)
5799 First
: constant Elmt_Id
:= First_Elmt
(Eq_Prims_List
);
5803 pragma Assert
(No
(Next_Elmt
(First
))
5804 or else No
(Next_Elmt
(Next_Elmt
(First
))));
5806 -- No action needed if we have collected a single equality
5809 if Present
(Next_Elmt
(First
)) then
5810 Second
:= Next_Elmt
(First
);
5812 if Is_Dispatching_Operation
5813 (Ultimate_Alias
(Node
(First
)))
5815 Remove
(Op_List
, Node
(First
));
5817 elsif Is_Dispatching_Operation
5818 (Ultimate_Alias
(Node
(Second
)))
5820 Remove
(Op_List
, Node
(Second
));
5823 raise Program_Error
;
5831 end Collect_Primitive_Operations
;
5833 -----------------------------------
5834 -- Compile_Time_Constraint_Error --
5835 -----------------------------------
5837 function Compile_Time_Constraint_Error
5840 Ent
: Entity_Id
:= Empty
;
5841 Loc
: Source_Ptr
:= No_Location
;
5842 Warn
: Boolean := False;
5843 Extra_Msg
: String := "") return Node_Id
5845 Msgc
: String (1 .. Msg
'Length + 3);
5846 -- Copy of message, with room for possible ?? or << and ! at end
5853 -- If this is a warning, convert it into an error if we are in code
5854 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5855 -- warning. The rationale is that a compile-time constraint error should
5856 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5857 -- a few cases we prefer to issue a warning and generate both a suitable
5858 -- run-time error in GNAT and a suitable check message in GNATprove.
5859 -- Those cases are those that likely correspond to deactivated SPARK
5860 -- code, so that this kind of code can be compiled and analyzed instead
5861 -- of being rejected.
5863 Error_Msg_Warn
:= Warn
or SPARK_Mode
/= On
;
5865 -- A static constraint error in an instance body is not a fatal error.
5866 -- We choose to inhibit the message altogether, because there is no
5867 -- obvious node (for now) on which to post it. On the other hand the
5868 -- offending node must be replaced with a constraint_error in any case.
5870 -- No messages are generated if we already posted an error on this node
5872 if not Error_Posted
(N
) then
5873 if Loc
/= No_Location
then
5879 -- Copy message to Msgc, converting any ? in the message into <
5880 -- instead, so that we have an error in GNATprove mode.
5884 for J
in 1 .. Msgl
loop
5885 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
- 1) /= ''') then
5888 Msgc
(J
) := Msg
(J
);
5892 -- Message is a warning, even in Ada 95 case
5894 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
5897 -- In Ada 83, all messages are warnings. In the private part and the
5898 -- body of an instance, constraint_checks are only warnings. We also
5899 -- make this a warning if the Warn parameter is set.
5902 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
5903 or else In_Instance_Not_Visible
5911 -- Otherwise we have a real error message (Ada 95 static case) and we
5912 -- make this an unconditional message. Note that in the warning case
5913 -- we do not make the message unconditional, it seems reasonable to
5914 -- delete messages like this (about exceptions that will be raised)
5923 -- One more test, skip the warning if the related expression is
5924 -- statically unevaluated, since we don't want to warn about what
5925 -- will happen when something is evaluated if it never will be
5928 -- Suppress error reporting when checking that the expression of a
5929 -- static expression function is a potentially static expression,
5930 -- because we don't want additional errors being reported during the
5931 -- preanalysis of the expression (see Analyze_Expression_Function).
5933 if not Is_Statically_Unevaluated
(N
)
5934 and then not Checking_Potentially_Static_Expression
5936 if Present
(Ent
) then
5937 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
5939 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
5942 -- Emit any extra message as a continuation
5944 if Extra_Msg
/= "" then
5945 Error_Msg_N
('\' & Extra_Msg
, N
);
5950 -- Check whether the context is an Init_Proc
5952 if Inside_Init_Proc
then
5954 Init_Proc_Type
: constant Entity_Id
:=
5955 Etype
(First_Formal
(Current_Scope_No_Loops
));
5957 Conc_Typ
: constant Entity_Id
:=
5958 (if Present
(Init_Proc_Type
)
5959 and then Ekind
(Init_Proc_Type
) = E_Record_Type
5960 then Corresponding_Concurrent_Type
(Init_Proc_Type
)
5964 -- Don't complain if the corresponding concurrent type
5965 -- doesn't come from source (i.e. a single task/protected
5968 if Present
(Conc_Typ
)
5969 and then not Comes_From_Source
(Conc_Typ
)
5971 Error_Msg
("\& [<<", Eloc
, N
);
5974 if GNATprove_Mode
then
5976 ("\Constraint_Error would have been raised"
5977 & " for objects of this type", Eloc
, N
);
5980 ("\Constraint_Error will be raised"
5981 & " for objects of this type??", Eloc
, N
);
5987 Error_Msg
("\Constraint_Error [<<", Eloc
, N
);
5991 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
5992 Set_Error_Posted
(N
);
5998 end Compile_Time_Constraint_Error
;
6000 ----------------------------
6001 -- Compute_Returns_By_Ref --
6002 ----------------------------
6004 procedure Compute_Returns_By_Ref
(Func
: Entity_Id
) is
6005 Kind
: constant Entity_Kind
:= Ekind
(Func
);
6006 Typ
: constant Entity_Id
:= Etype
(Func
);
6009 -- Nothing to do for procedures
6011 if Kind
in E_Procedure | E_Generic_Procedure
6012 or else (Kind
= E_Subprogram_Type
and then Typ
= Standard_Void_Type
)
6016 -- The build-in-place protocols return a reference to the result
6018 elsif Is_Build_In_Place_Function
(Func
) then
6019 Set_Returns_By_Ref
(Func
);
6021 -- In Ada 95, limited types are returned by reference, but not if the
6022 -- convention is other than Ada.
6024 elsif Is_Inherently_Limited_Type
(Typ
)
6025 and then not Has_Foreign_Convention
(Func
)
6027 Set_Returns_By_Ref
(Func
);
6029 end Compute_Returns_By_Ref
;
6031 --------------------------------
6032 -- Collect_Types_In_Hierarchy --
6033 --------------------------------
6035 function Collect_Types_In_Hierarchy
6037 Examine_Components
: Boolean := False) return Elist_Id
6041 procedure Process_Type
(Typ
: Entity_Id
);
6042 -- Collect type Typ if it satisfies function Predicate. Do so for its
6043 -- parent type, base type, progenitor types, and any component types.
6049 procedure Process_Type
(Typ
: Entity_Id
) is
6051 Iface_Elmt
: Elmt_Id
;
6054 if not Is_Type
(Typ
) or else Error_Posted
(Typ
) then
6058 -- Collect the current type if it satisfies the predicate
6060 if Predicate
(Typ
) then
6061 Append_Elmt
(Typ
, Results
);
6064 -- Process component types
6066 if Examine_Components
then
6068 -- Examine components and discriminants
6070 if Is_Concurrent_Type
(Typ
)
6071 or else Is_Incomplete_Or_Private_Type
(Typ
)
6072 or else Is_Record_Type
(Typ
)
6073 or else Has_Discriminants
(Typ
)
6075 Comp
:= First_Component_Or_Discriminant
(Typ
);
6077 while Present
(Comp
) loop
6078 Process_Type
(Etype
(Comp
));
6080 Next_Component_Or_Discriminant
(Comp
);
6083 -- Examine array components
6085 elsif Ekind
(Typ
) = E_Array_Type
then
6086 Process_Type
(Component_Type
(Typ
));
6090 -- Examine parent type
6092 if Etype
(Typ
) /= Typ
then
6093 -- Prevent infinite recursion, which can happen in illegal
6094 -- programs. Silently return if illegal. For now, just deal
6095 -- with the 2-type cycle case. Larger cycles will get
6096 -- SIGSEGV at compile time from running out of stack.
6098 if Etype
(Etype
(Typ
)) = Typ
then
6099 if Total_Errors_Detected
= 0 then
6100 raise Program_Error
;
6106 Process_Type
(Etype
(Typ
));
6109 -- Examine base type
6111 if Base_Type
(Typ
) /= Typ
then
6112 Process_Type
(Base_Type
(Typ
));
6115 -- Examine interfaces
6117 if Is_Record_Type
(Typ
)
6118 and then Present
(Interfaces
(Typ
))
6120 Iface_Elmt
:= First_Elmt
(Interfaces
(Typ
));
6121 while Present
(Iface_Elmt
) loop
6122 Process_Type
(Node
(Iface_Elmt
));
6124 Next_Elmt
(Iface_Elmt
);
6129 -- Start of processing for Collect_Types_In_Hierarchy
6132 Results
:= New_Elmt_List
;
6135 end Collect_Types_In_Hierarchy
;
6137 -----------------------
6138 -- Conditional_Delay --
6139 -----------------------
6141 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
6143 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
6144 Set_Has_Delayed_Freeze
(New_Ent
);
6146 end Conditional_Delay
;
6148 -------------------------
6149 -- Copy_Component_List --
6150 -------------------------
6152 function Copy_Component_List
6154 Loc
: Source_Ptr
) return List_Id
6157 Comps
: constant List_Id
:= New_List
;
6160 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
6161 while Present
(Comp
) loop
6162 if Comes_From_Source
(Comp
) then
6164 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
6167 Make_Component_Declaration
(Loc
,
6168 Defining_Identifier
=>
6169 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
6170 Component_Definition
=>
6172 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
6176 Next_Component
(Comp
);
6180 end Copy_Component_List
;
6182 -----------------------
6183 -- Copy_Ghost_Aspect --
6184 -----------------------
6186 procedure Copy_Ghost_Aspect
(From
: Node_Id
; To
: Node_Id
) is
6187 pragma Assert
(not Has_Aspects
(To
));
6191 if Has_Aspects
(From
) then
6192 Asp
:= Find_Aspect
(Defining_Entity
(From
), Aspect_Ghost
);
6194 if Present
(Asp
) then
6195 Set_Aspect_Specifications
(To
, New_List
(New_Copy_Tree
(Asp
)));
6198 end Copy_Ghost_Aspect
;
6200 -------------------------
6201 -- Copy_Parameter_List --
6202 -------------------------
6204 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
6205 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
6207 Formal
: Entity_Id
:= First_Formal
(Subp_Id
);
6210 if Present
(Formal
) then
6212 while Present
(Formal
) loop
6214 Make_Parameter_Specification
(Loc
,
6215 Defining_Identifier
=>
6216 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
6217 In_Present
=> In_Present
(Parent
(Formal
)),
6218 Out_Present
=> Out_Present
(Parent
(Formal
)),
6220 New_Occurrence_Of
(Etype
(Formal
), Loc
),
6222 New_Copy_Tree
(Expression
(Parent
(Formal
)))));
6224 Next_Formal
(Formal
);
6231 end Copy_Parameter_List
;
6233 ----------------------------
6234 -- Copy_SPARK_Mode_Aspect --
6235 ----------------------------
6237 procedure Copy_SPARK_Mode_Aspect
(From
: Node_Id
; To
: Node_Id
) is
6238 pragma Assert
(not Has_Aspects
(To
));
6242 if Has_Aspects
(From
) then
6243 Asp
:= Find_Aspect
(Defining_Entity
(From
), Aspect_SPARK_Mode
);
6245 if Present
(Asp
) then
6246 Set_Aspect_Specifications
(To
, New_List
(New_Copy_Tree
(Asp
)));
6249 end Copy_SPARK_Mode_Aspect
;
6251 --------------------------
6252 -- Copy_Subprogram_Spec --
6253 --------------------------
6255 function Copy_Subprogram_Spec
6257 New_Sloc
: Source_Ptr
:= No_Location
) return Node_Id
6260 Formal_Spec
: Node_Id
;
6264 -- The structure of the original tree must be replicated without any
6265 -- alterations. Use New_Copy_Tree for this purpose.
6267 Result
:= New_Copy_Tree
(Spec
, New_Sloc
=> New_Sloc
);
6269 -- However, the spec of a null procedure carries the corresponding null
6270 -- statement of the body (created by the parser), and this cannot be
6271 -- shared with the new subprogram spec.
6273 if Nkind
(Result
) = N_Procedure_Specification
then
6274 Set_Null_Statement
(Result
, Empty
);
6277 -- Create a new entity for the defining unit name
6279 Def_Id
:= Defining_Unit_Name
(Result
);
6280 Set_Defining_Unit_Name
(Result
,
6281 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
6283 -- Create new entities for the formal parameters
6285 Formal_Spec
:= First
(Parameter_Specifications
(Result
));
6286 while Present
(Formal_Spec
) loop
6287 Def_Id
:= Defining_Identifier
(Formal_Spec
);
6288 Set_Defining_Identifier
(Formal_Spec
,
6289 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
6295 end Copy_Subprogram_Spec
;
6297 --------------------------------
6298 -- Corresponding_Generic_Type --
6299 --------------------------------
6301 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
6307 if not Is_Generic_Actual_Type
(T
) then
6310 -- If the actual is the actual of an enclosing instance, resolution
6311 -- was correct in the generic.
6313 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
6314 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
6316 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
6323 if Is_Wrapper_Package
(Inst
) then
6324 Inst
:= Related_Instance
(Inst
);
6329 (Specification
(Unit_Declaration_Node
(Inst
)));
6331 -- Generic actual has the same name as the corresponding formal
6333 Typ
:= First_Entity
(Gen
);
6334 while Present
(Typ
) loop
6335 if Chars
(Typ
) = Chars
(T
) then
6344 end Corresponding_Generic_Type
;
6346 --------------------------------
6347 -- Corresponding_Primitive_Op --
6348 --------------------------------
6350 function Corresponding_Primitive_Op
6351 (Ancestor_Op
: Entity_Id
;
6352 Descendant_Type
: Entity_Id
) return Entity_Id
6354 function Find_Untagged_Type_Of
(Prim
: Entity_Id
) return Entity_Id
;
6355 -- Search for the untagged type of the primitive operation Prim.
6357 function Profile_Matches_Ancestor
(S
: Entity_Id
) return Boolean;
6358 -- Returns True if subprogram S has the proper profile for an
6359 -- overriding of Ancestor_Op (that is, corresponding formals either
6360 -- have the same type, or are corresponding controlling formals,
6361 -- and similarly for result types).
6363 ---------------------------
6364 -- Find_Untagged_Type_Of --
6365 ---------------------------
6367 function Find_Untagged_Type_Of
(Prim
: Entity_Id
) return Entity_Id
is
6368 E
: Entity_Id
:= First_Entity
(Scope
(Prim
));
6371 while Present
(E
) and then E
/= Prim
loop
6372 if not Is_Tagged_Type
(E
)
6373 and then Contains
(Direct_Primitive_Operations
(E
), Prim
)
6381 pragma Assert
(False);
6383 end Find_Untagged_Type_Of
;
6385 Typ
: constant Entity_Id
:=
6386 (if Is_Dispatching_Operation
(Ancestor_Op
)
6387 then Find_Dispatching_Type
(Ancestor_Op
)
6388 else Find_Untagged_Type_Of
(Ancestor_Op
));
6390 ------------------------------
6391 -- Profile_Matches_Ancestor --
6392 ------------------------------
6394 function Profile_Matches_Ancestor
(S
: Entity_Id
) return Boolean is
6395 F1
: Entity_Id
:= First_Formal
(Ancestor_Op
);
6396 F2
: Entity_Id
:= First_Formal
(S
);
6399 if Ekind
(Ancestor_Op
) /= Ekind
(S
) then
6403 -- ??? This should probably account for anonymous access formals,
6404 -- but the parent function (Corresponding_Primitive_Op) is currently
6405 -- only called for user-defined literal functions, which can't have
6406 -- such formals. But if this is ever used in a more general context
6407 -- it should be extended to handle such formals (and result types).
6409 while Present
(F1
) and then Present
(F2
) loop
6410 if Etype
(F1
) = Etype
(F2
)
6411 or else Is_Ancestor
(Typ
, Etype
(F2
))
6422 and then (Etype
(Ancestor_Op
) = Etype
(S
)
6423 or else Is_Ancestor
(Typ
, Etype
(S
)));
6424 end Profile_Matches_Ancestor
;
6431 -- Start of processing for Corresponding_Primitive_Op
6434 pragma Assert
(Is_Ancestor
(Typ
, Descendant_Type
)
6435 or else Is_Progenitor
(Typ
, Descendant_Type
));
6437 Elmt
:= First_Elmt
(Primitive_Operations
(Descendant_Type
));
6439 while Present
(Elmt
) loop
6440 Subp
:= Node
(Elmt
);
6442 -- For regular primitives we need to check the profile against
6443 -- the ancestor when the name matches the name of Ancestor_Op,
6444 -- but for predefined dispatching operations we cannot rely on
6445 -- the name of the primitive to identify a candidate since their
6446 -- name is internally built by adding a suffix to the name of the
6449 if Chars
(Subp
) = Chars
(Ancestor_Op
)
6450 or else Is_Predefined_Dispatching_Operation
(Subp
)
6452 -- Handle case where Ancestor_Op is a primitive of a progenitor.
6453 -- We rely on internal entities that map interface primitives:
6454 -- their attribute Interface_Alias references the interface
6455 -- primitive, and their Alias attribute references the primitive
6456 -- of Descendant_Type implementing that interface primitive.
6458 if Present
(Interface_Alias
(Subp
)) then
6459 if Interface_Alias
(Subp
) = Ancestor_Op
then
6460 return Alias
(Subp
);
6463 -- Otherwise, return subprogram when profile matches its ancestor
6465 elsif Profile_Matches_Ancestor
(Subp
) then
6473 pragma Assert
(False);
6475 end Corresponding_Primitive_Op
;
6477 --------------------
6478 -- Current_Entity --
6479 --------------------
6481 -- The currently visible definition for a given identifier is the
6482 -- one most chained at the start of the visibility chain, i.e. the
6483 -- one that is referenced by the Node_Id value of the name of the
6484 -- given identifier.
6486 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
6488 return Get_Name_Entity_Id
(Chars
(N
));
6491 -----------------------------
6492 -- Current_Entity_In_Scope --
6493 -----------------------------
6495 function Current_Entity_In_Scope
(N
: Name_Id
) return Entity_Id
is
6496 CS
: constant Entity_Id
:= Current_Scope
;
6501 E
:= Get_Name_Entity_Id
(N
);
6506 elsif Scope_Is_Transient
then
6507 while Present
(E
) loop
6508 exit when Scope
(E
) = CS
or else Scope
(E
) = Scope
(CS
);
6514 while Present
(E
) loop
6515 exit when Scope
(E
) = CS
;
6522 end Current_Entity_In_Scope
;
6524 -----------------------------
6525 -- Current_Entity_In_Scope --
6526 -----------------------------
6528 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
6530 return Current_Entity_In_Scope
(Chars
(N
));
6531 end Current_Entity_In_Scope
;
6537 function Current_Scope
return Entity_Id
is
6539 if Scope_Stack
.Last
= -1 then
6540 return Standard_Standard
;
6543 C
: constant Entity_Id
:=
6544 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
6549 return Standard_Standard
;
6555 ----------------------------
6556 -- Current_Scope_No_Loops --
6557 ----------------------------
6559 function Current_Scope_No_Loops
return Entity_Id
is
6563 -- Examine the scope stack starting from the current scope and skip any
6564 -- internally generated loops.
6567 while Present
(S
) and then S
/= Standard_Standard
loop
6568 if Ekind
(S
) = E_Loop
and then not Comes_From_Source
(S
) then
6576 end Current_Scope_No_Loops
;
6578 ------------------------
6579 -- Current_Subprogram --
6580 ------------------------
6582 function Current_Subprogram
return Entity_Id
is
6583 Scop
: constant Entity_Id
:= Current_Scope
;
6585 if Is_Subprogram_Or_Generic_Subprogram
(Scop
) then
6588 return Enclosing_Subprogram
(Scop
);
6590 end Current_Subprogram
;
6592 ------------------------------
6593 -- CW_Or_Needs_Finalization --
6594 ------------------------------
6596 function CW_Or_Needs_Finalization
(Typ
: Entity_Id
) return Boolean is
6598 return Is_Class_Wide_Type
(Typ
) or else Needs_Finalization
(Typ
);
6599 end CW_Or_Needs_Finalization
;
6601 ---------------------
6602 -- Defining_Entity --
6603 ---------------------
6605 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
6606 Ent
: constant Entity_Id
:= Defining_Entity_Or_Empty
(N
);
6609 if Present
(Ent
) then
6613 raise Program_Error
;
6615 end Defining_Entity
;
6617 ------------------------------
6618 -- Defining_Entity_Or_Empty --
6619 ------------------------------
6621 function Defining_Entity_Or_Empty
(N
: Node_Id
) return Entity_Id
is
6624 when N_Abstract_Subprogram_Declaration
6625 | N_Expression_Function
6626 | N_Formal_Subprogram_Declaration
6627 | N_Generic_Package_Declaration
6628 | N_Generic_Subprogram_Declaration
6629 | N_Package_Declaration
6631 | N_Subprogram_Body_Stub
6632 | N_Subprogram_Declaration
6633 | N_Subprogram_Renaming_Declaration
6635 return Defining_Entity
(Specification
(N
));
6637 when N_Component_Declaration
6638 | N_Defining_Program_Unit_Name
6639 | N_Discriminant_Specification
6641 | N_Entry_Declaration
6642 | N_Entry_Index_Specification
6643 | N_Exception_Declaration
6644 | N_Exception_Renaming_Declaration
6645 | N_Formal_Object_Declaration
6646 | N_Formal_Package_Declaration
6647 | N_Formal_Type_Declaration
6648 | N_Full_Type_Declaration
6649 | N_Implicit_Label_Declaration
6650 | N_Incomplete_Type_Declaration
6651 | N_Iterator_Specification
6652 | N_Loop_Parameter_Specification
6653 | N_Number_Declaration
6654 | N_Object_Declaration
6655 | N_Object_Renaming_Declaration
6656 | N_Package_Body_Stub
6657 | N_Parameter_Specification
6658 | N_Private_Extension_Declaration
6659 | N_Private_Type_Declaration
6661 | N_Protected_Body_Stub
6662 | N_Protected_Type_Declaration
6663 | N_Single_Protected_Declaration
6664 | N_Single_Task_Declaration
6665 | N_Subtype_Declaration
6668 | N_Task_Type_Declaration
6670 return Defining_Identifier
(N
);
6672 when N_Compilation_Unit
=>
6673 return Defining_Entity
(Unit
(N
));
6676 return Defining_Entity
(Proper_Body
(N
));
6678 when N_Function_Instantiation
6679 | N_Function_Specification
6680 | N_Generic_Function_Renaming_Declaration
6681 | N_Generic_Package_Renaming_Declaration
6682 | N_Generic_Procedure_Renaming_Declaration
6684 | N_Package_Instantiation
6685 | N_Package_Renaming_Declaration
6686 | N_Package_Specification
6687 | N_Procedure_Instantiation
6688 | N_Procedure_Specification
6691 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
6692 Err
: Entity_Id
:= Empty
;
6695 if Nkind
(Nam
) in N_Entity
then
6698 -- For Error, make up a name and attach to declaration so we
6699 -- can continue semantic analysis.
6701 elsif Nam
= Error
then
6702 Err
:= Make_Temporary
(Sloc
(N
), 'T');
6703 Set_Defining_Unit_Name
(N
, Err
);
6707 -- If not an entity, get defining identifier
6710 return Defining_Identifier
(Nam
);
6714 when N_Block_Statement
6717 return Entity
(Identifier
(N
));
6722 end Defining_Entity_Or_Empty
;
6724 --------------------------
6725 -- Denotes_Discriminant --
6726 --------------------------
6728 function Denotes_Discriminant
6730 Check_Concurrent
: Boolean := False) return Boolean
6735 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
6741 -- If we are checking for a protected type, the discriminant may have
6742 -- been rewritten as the corresponding discriminal of the original type
6743 -- or of the corresponding concurrent record, depending on whether we
6744 -- are in the spec or body of the protected type.
6746 return Ekind
(E
) = E_Discriminant
6749 and then Ekind
(E
) = E_In_Parameter
6750 and then Present
(Discriminal_Link
(E
))
6752 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
6754 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
6755 end Denotes_Discriminant
;
6757 -------------------------
6758 -- Denotes_Same_Object --
6759 -------------------------
6761 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
6762 function Is_Object_Renaming
(N
: Node_Id
) return Boolean;
6763 -- Return true if N names an object renaming entity
6765 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
6766 -- For renamings, return False if the prefix of any dereference within
6767 -- the renamed object_name is a variable, or any expression within the
6768 -- renamed object_name contains references to variables or calls on
6769 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6771 ------------------------
6772 -- Is_Object_Renaming --
6773 ------------------------
6775 function Is_Object_Renaming
(N
: Node_Id
) return Boolean is
6777 return Is_Entity_Name
(N
)
6778 and then Ekind
(Entity
(N
)) in E_Variable | E_Constant
6779 and then Present
(Renamed_Object
(Entity
(N
)));
6780 end Is_Object_Renaming
;
6782 -----------------------
6783 -- Is_Valid_Renaming --
6784 -----------------------
6786 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
6788 if Is_Object_Renaming
(N
)
6789 and then not Is_Valid_Renaming
(Renamed_Object
(Entity
(N
)))
6794 -- Check if any expression within the renamed object_name contains no
6795 -- references to variables nor calls on nonstatic functions.
6797 if Nkind
(N
) = N_Indexed_Component
then
6802 Indx
:= First
(Expressions
(N
));
6803 while Present
(Indx
) loop
6804 if not Is_OK_Static_Expression
(Indx
) then
6812 elsif Nkind
(N
) = N_Slice
then
6814 Rng
: constant Node_Id
:= Discrete_Range
(N
);
6816 -- Bounds specified as a range
6818 if Nkind
(Rng
) = N_Range
then
6819 if not Is_OK_Static_Range
(Rng
) then
6823 -- Bounds specified as a constrained subtype indication
6825 elsif Nkind
(Rng
) = N_Subtype_Indication
then
6826 if not Is_OK_Static_Range
6827 (Range_Expression
(Constraint
(Rng
)))
6832 -- Bounds specified as a subtype name
6834 elsif not Is_OK_Static_Expression
(Rng
) then
6840 if Has_Prefix
(N
) then
6842 P
: constant Node_Id
:= Prefix
(N
);
6845 if Nkind
(N
) = N_Explicit_Dereference
6846 and then Is_Variable
(P
)
6850 elsif Is_Entity_Name
(P
)
6851 and then Ekind
(Entity
(P
)) = E_Function
6855 elsif Nkind
(P
) = N_Function_Call
then
6859 -- Recursion to continue traversing the prefix of the
6860 -- renaming expression
6862 return Is_Valid_Renaming
(P
);
6867 end Is_Valid_Renaming
;
6869 -- Start of processing for Denotes_Same_Object
6872 -- Both names statically denote the same stand-alone object or
6873 -- parameter (RM 6.4.1(6.6/3)).
6875 if Is_Entity_Name
(A1
)
6876 and then Is_Entity_Name
(A2
)
6877 and then Entity
(A1
) = Entity
(A2
)
6881 -- Both names are selected_components, their prefixes are known to
6882 -- denote the same object, and their selector_names denote the same
6883 -- component (RM 6.4.1(6.7/3)).
6885 elsif Nkind
(A1
) = N_Selected_Component
6886 and then Nkind
(A2
) = N_Selected_Component
6888 return Denotes_Same_Object
(Prefix
(A1
), Prefix
(A2
))
6890 Entity
(Selector_Name
(A1
)) = Entity
(Selector_Name
(A2
));
6892 -- Both names are dereferences and the dereferenced names are known to
6893 -- denote the same object (RM 6.4.1(6.8/3)).
6895 elsif Nkind
(A1
) = N_Explicit_Dereference
6896 and then Nkind
(A2
) = N_Explicit_Dereference
6898 return Denotes_Same_Object
(Prefix
(A1
), Prefix
(A2
));
6900 -- Both names are indexed_components, their prefixes are known to denote
6901 -- the same object, and each of the pairs of corresponding index values
6902 -- are either both static expressions with the same static value or both
6903 -- names that are known to denote the same object (RM 6.4.1(6.9/3)).
6905 elsif Nkind
(A1
) = N_Indexed_Component
6906 and then Nkind
(A2
) = N_Indexed_Component
6908 if not Denotes_Same_Object
(Prefix
(A1
), Prefix
(A2
)) then
6916 Indx1
:= First
(Expressions
(A1
));
6917 Indx2
:= First
(Expressions
(A2
));
6918 while Present
(Indx1
) loop
6920 -- Indexes must denote the same static value or same object
6922 if Is_OK_Static_Expression
(Indx1
) then
6923 if not Is_OK_Static_Expression
(Indx2
) then
6926 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
6930 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
6942 -- Both names are slices, their prefixes are known to denote the same
6943 -- object, and the two slices have statically matching index constraints
6944 -- (RM 6.4.1(6.10/3)).
6946 elsif Nkind
(A1
) = N_Slice
6947 and then Nkind
(A2
) = N_Slice
6949 if not Denotes_Same_Object
(Prefix
(A1
), Prefix
(A2
)) then
6953 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
6956 Get_Index_Bounds
(Discrete_Range
(A1
), Lo1
, Hi1
);
6957 Get_Index_Bounds
(Discrete_Range
(A2
), Lo2
, Hi2
);
6959 -- Check whether bounds are statically identical. There is no
6960 -- attempt to detect partial overlap of slices.
6962 return Is_OK_Static_Expression
(Lo1
)
6963 and then Is_OK_Static_Expression
(Lo2
)
6964 and then Is_OK_Static_Expression
(Hi1
)
6965 and then Is_OK_Static_Expression
(Hi2
)
6966 and then Expr_Value
(Lo1
) = Expr_Value
(Lo2
)
6967 and then Expr_Value
(Hi1
) = Expr_Value
(Hi2
);
6971 -- One of the two names statically denotes a renaming declaration whose
6972 -- renamed object_name is known to denote the same object as the other;
6973 -- the prefix of any dereference within the renamed object_name is not a
6974 -- variable, and any expression within the renamed object_name contains
6975 -- no references to variables nor calls on nonstatic functions (RM
6978 elsif Is_Object_Renaming
(A1
)
6979 and then Is_Valid_Renaming
(A1
)
6981 return Denotes_Same_Object
(Renamed_Object
(Entity
(A1
)), A2
);
6983 elsif Is_Object_Renaming
(A2
)
6984 and then Is_Valid_Renaming
(A2
)
6986 return Denotes_Same_Object
(A1
, Renamed_Object
(Entity
(A2
)));
6991 end Denotes_Same_Object
;
6993 -------------------------
6994 -- Denotes_Same_Prefix --
6995 -------------------------
6997 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
6999 if Is_Entity_Name
(A1
) then
7000 if Nkind
(A2
) in N_Selected_Component | N_Indexed_Component
7001 and then not Is_Access_Type
(Etype
(A1
))
7003 return Denotes_Same_Object
(A1
, Prefix
(A2
))
7004 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
7009 elsif Is_Entity_Name
(A2
) then
7010 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
7012 elsif Nkind
(A1
) in N_Selected_Component | N_Indexed_Component | N_Slice
7014 Nkind
(A2
) in N_Selected_Component | N_Indexed_Component | N_Slice
7017 Root1
, Root2
: Node_Id
;
7018 Depth1
, Depth2
: Nat
:= 0;
7021 Root1
:= Prefix
(A1
);
7022 while not Is_Entity_Name
(Root1
) loop
7023 if Nkind
(Root1
) not in
7024 N_Selected_Component | N_Indexed_Component
7028 Root1
:= Prefix
(Root1
);
7031 Depth1
:= Depth1
+ 1;
7034 Root2
:= Prefix
(A2
);
7035 while not Is_Entity_Name
(Root2
) loop
7036 if Nkind
(Root2
) not in
7037 N_Selected_Component | N_Indexed_Component
7041 Root2
:= Prefix
(Root2
);
7044 Depth2
:= Depth2
+ 1;
7047 -- If both have the same depth and they do not denote the same
7048 -- object, they are disjoint and no warning is needed.
7050 if Depth1
= Depth2
then
7053 elsif Depth1
> Depth2
then
7054 Root1
:= Prefix
(A1
);
7055 for J
in 1 .. Depth1
- Depth2
- 1 loop
7056 Root1
:= Prefix
(Root1
);
7059 return Denotes_Same_Object
(Root1
, A2
);
7062 Root2
:= Prefix
(A2
);
7063 for J
in 1 .. Depth2
- Depth1
- 1 loop
7064 Root2
:= Prefix
(Root2
);
7067 return Denotes_Same_Object
(A1
, Root2
);
7074 end Denotes_Same_Prefix
;
7076 ----------------------
7077 -- Denotes_Variable --
7078 ----------------------
7080 function Denotes_Variable
(N
: Node_Id
) return Boolean is
7082 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
7083 end Denotes_Variable
;
7085 -----------------------------
7086 -- Depends_On_Discriminant --
7087 -----------------------------
7089 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
7094 Get_Index_Bounds
(N
, L
, H
);
7095 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
7096 end Depends_On_Discriminant
;
7098 -------------------------------------
7099 -- Derivation_Too_Early_To_Inherit --
7100 -------------------------------------
7102 function Derivation_Too_Early_To_Inherit
7103 (Typ
: Entity_Id
; Streaming_Op
: TSS_Name_Type
) return Boolean is
7105 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
7106 Parent_Type
: Entity_Id
;
7110 -- Start of processing for Derivation_Too_Early_To_Inherit
7113 if Is_Derived_Type
(Btyp
) then
7114 Parent_Type
:= Implementation_Base_Type
(Etype
(Btyp
));
7115 pragma Assert
(Parent_Type
/= Btyp
);
7117 if Has_Stream_Attribute_Definition
7118 (Parent_Type
, Streaming_Op
, Real_Rep
=> Real_Rep
)
7120 and then In_Same_Extended_Unit
(Btyp
, Parent_Type
)
7121 and then Instantiation
(Get_Source_File_Index
(Sloc
(Btyp
))) =
7122 Instantiation
(Get_Source_File_Index
(Sloc
(Parent_Type
)))
7124 return Earlier_In_Extended_Unit
(Btyp
, Real_Rep
);
7129 end Derivation_Too_Early_To_Inherit
;
7131 -------------------------
7132 -- Designate_Same_Unit --
7133 -------------------------
7135 function Designate_Same_Unit
7137 Name2
: Node_Id
) return Boolean
7139 K1
: constant Node_Kind
:= Nkind
(Name1
);
7140 K2
: constant Node_Kind
:= Nkind
(Name2
);
7142 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
7143 -- Returns the parent unit name node of a defining program unit name
7144 -- or the prefix if N is a selected component or an expanded name.
7146 function Select_Node
(N
: Node_Id
) return Node_Id
;
7147 -- Returns the defining identifier node of a defining program unit
7148 -- name or the selector node if N is a selected component or an
7155 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
7157 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
7168 function Select_Node
(N
: Node_Id
) return Node_Id
is
7170 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
7171 return Defining_Identifier
(N
);
7173 return Selector_Name
(N
);
7177 -- Start of processing for Designate_Same_Unit
7180 if K1
in N_Identifier | N_Defining_Identifier
7182 K2
in N_Identifier | N_Defining_Identifier
7184 return Chars
(Name1
) = Chars
(Name2
);
7186 elsif K1
in N_Expanded_Name
7187 | N_Selected_Component
7188 | N_Defining_Program_Unit_Name
7190 K2
in N_Expanded_Name
7191 | N_Selected_Component
7192 | N_Defining_Program_Unit_Name
7195 Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
))
7197 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
7202 end Designate_Same_Unit
;
7204 ---------------------------------------------
7205 -- Diagnose_Iterated_Component_Association --
7206 ---------------------------------------------
7208 procedure Diagnose_Iterated_Component_Association
(N
: Node_Id
) is
7209 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
7213 -- Determine whether the iterated component association appears within
7214 -- an aggregate. If this is the case, raise Program_Error because the
7215 -- iterated component association cannot be left in the tree as is and
7216 -- must always be processed by the related aggregate.
7219 while Present
(Aggr
) loop
7220 if Nkind
(Aggr
) = N_Aggregate
then
7221 raise Program_Error
;
7223 -- Prevent the search from going too far
7225 elsif Is_Body_Or_Package_Declaration
(Aggr
) then
7229 Aggr
:= Parent
(Aggr
);
7232 -- At this point it is known that the iterated component association is
7233 -- not within an aggregate. This is really a quantified expression with
7234 -- a missing "all" or "some" quantifier.
7236 Error_Msg_N
("missing quantifier", Def_Id
);
7238 -- Rewrite the iterated component association as True to prevent any
7241 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
7243 end Diagnose_Iterated_Component_Association
;
7245 ------------------------
7246 -- Discriminated_Size --
7247 ------------------------
7249 function Discriminated_Size
(Comp
: Entity_Id
) return Boolean is
7250 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean;
7251 -- Check whether the bound of an index is non-static and does denote
7252 -- a discriminant, in which case any object of the type (protected or
7253 -- otherwise) will have a non-static size.
7255 ----------------------
7256 -- Non_Static_Bound --
7257 ----------------------
7259 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean is
7261 if Is_OK_Static_Expression
(Bound
) then
7264 -- If the bound is given by a discriminant it is non-static
7265 -- (A static constraint replaces the reference with the value).
7266 -- In an protected object the discriminant has been replaced by
7267 -- the corresponding discriminal within the protected operation.
7269 elsif Is_Entity_Name
(Bound
)
7271 (Ekind
(Entity
(Bound
)) = E_Discriminant
7272 or else Present
(Discriminal_Link
(Entity
(Bound
))))
7279 end Non_Static_Bound
;
7283 Typ
: constant Entity_Id
:= Etype
(Comp
);
7286 -- Start of processing for Discriminated_Size
7289 if not Is_Array_Type
(Typ
) then
7293 if Ekind
(Typ
) = E_Array_Subtype
then
7294 Index
:= First_Index
(Typ
);
7295 while Present
(Index
) loop
7296 if Non_Static_Bound
(Low_Bound
(Index
))
7297 or else Non_Static_Bound
(High_Bound
(Index
))
7309 end Discriminated_Size
;
7311 -----------------------------
7312 -- Effective_Reads_Enabled --
7313 -----------------------------
7315 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
7317 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
7318 end Effective_Reads_Enabled
;
7320 ------------------------------
7321 -- Effective_Writes_Enabled --
7322 ------------------------------
7324 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
7326 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
7327 end Effective_Writes_Enabled
;
7329 ------------------------------
7330 -- Enclosing_Comp_Unit_Node --
7331 ------------------------------
7333 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
7334 Current_Node
: Node_Id
;
7338 while Present
(Current_Node
)
7339 and then Nkind
(Current_Node
) /= N_Compilation_Unit
7341 Current_Node
:= Parent
(Current_Node
);
7344 return Current_Node
;
7345 end Enclosing_Comp_Unit_Node
;
7347 --------------------------
7348 -- Enclosing_CPP_Parent --
7349 --------------------------
7351 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
7352 Parent_Typ
: Entity_Id
:= Typ
;
7355 while not Is_CPP_Class
(Parent_Typ
)
7356 and then Etype
(Parent_Typ
) /= Parent_Typ
7358 Parent_Typ
:= Etype
(Parent_Typ
);
7360 if Is_Private_Type
(Parent_Typ
) then
7361 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
7365 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
7367 end Enclosing_CPP_Parent
;
7369 ---------------------------
7370 -- Enclosing_Declaration --
7371 ---------------------------
7373 function Enclosing_Declaration
(N
: Node_Id
) return Node_Id
is
7374 Decl
: Node_Id
:= N
;
7377 while Present
(Decl
)
7378 and then not (Nkind
(Decl
) in N_Declaration
7380 Nkind
(Decl
) in N_Later_Decl_Item
7382 Nkind
(Decl
) in N_Renaming_Declaration
7384 Nkind
(Decl
) = N_Number_Declaration
)
7386 Decl
:= Parent
(Decl
);
7390 end Enclosing_Declaration
;
7392 ----------------------------------------
7393 -- Enclosing_Declaration_Or_Statement --
7394 ----------------------------------------
7396 function Enclosing_Declaration_Or_Statement
7397 (N
: Node_Id
) return Node_Id
7403 while Present
(Par
) loop
7404 if Is_Declaration
(Par
) or else Is_Statement
(Par
) then
7407 -- Prevent the search from going too far
7409 elsif Is_Body_Or_Package_Declaration
(Par
) then
7413 Par
:= Parent
(Par
);
7417 end Enclosing_Declaration_Or_Statement
;
7419 ----------------------------
7420 -- Enclosing_Generic_Body --
7421 ----------------------------
7423 function Enclosing_Generic_Body
(N
: Node_Id
) return Node_Id
is
7425 Spec_Id
: Entity_Id
;
7429 while Present
(Par
) loop
7430 if Nkind
(Par
) in N_Package_Body | N_Subprogram_Body
then
7431 Spec_Id
:= Corresponding_Spec
(Par
);
7433 if Present
(Spec_Id
)
7434 and then Nkind
(Unit_Declaration_Node
(Spec_Id
)) in
7435 N_Generic_Declaration
7441 Par
:= Parent
(Par
);
7445 end Enclosing_Generic_Body
;
7447 ----------------------------
7448 -- Enclosing_Generic_Unit --
7449 ----------------------------
7451 function Enclosing_Generic_Unit
(N
: Node_Id
) return Node_Id
is
7453 Spec_Decl
: Node_Id
;
7454 Spec_Id
: Entity_Id
;
7458 while Present
(Par
) loop
7459 if Nkind
(Par
) in N_Generic_Declaration
then
7462 elsif Nkind
(Par
) in N_Package_Body | N_Subprogram_Body
then
7463 Spec_Id
:= Corresponding_Spec
(Par
);
7465 if Present
(Spec_Id
) then
7466 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
7468 if Nkind
(Spec_Decl
) in N_Generic_Declaration
then
7474 Par
:= Parent
(Par
);
7478 end Enclosing_Generic_Unit
;
7484 function Enclosing_HSS
(Stmt
: Node_Id
) return Node_Id
is
7487 pragma Assert
(Is_Statement
(Stmt
));
7489 Par
:= Parent
(Stmt
);
7490 while Present
(Par
) loop
7492 if Nkind
(Par
) = N_Handled_Sequence_Of_Statements
then
7495 -- Prevent the search from going too far
7497 elsif Is_Body_Or_Package_Declaration
(Par
) then
7502 Par
:= Parent
(Par
);
7508 -------------------------------
7509 -- Enclosing_Lib_Unit_Entity --
7510 -------------------------------
7512 function Enclosing_Lib_Unit_Entity
7513 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
7515 Unit_Entity
: Entity_Id
;
7518 -- Look for enclosing library unit entity by following scope links.
7519 -- Equivalent to, but faster than indexing through the scope stack.
7522 while (Present
(Scope
(Unit_Entity
))
7523 and then Scope
(Unit_Entity
) /= Standard_Standard
)
7524 and not Is_Child_Unit
(Unit_Entity
)
7526 Unit_Entity
:= Scope
(Unit_Entity
);
7530 end Enclosing_Lib_Unit_Entity
;
7532 -----------------------------
7533 -- Enclosing_Lib_Unit_Node --
7534 -----------------------------
7536 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
7537 Encl_Unit
: Node_Id
;
7540 Encl_Unit
:= Enclosing_Comp_Unit_Node
(N
);
7541 while Present
(Encl_Unit
)
7542 and then Nkind
(Unit
(Encl_Unit
)) = N_Subunit
7544 Encl_Unit
:= Library_Unit
(Encl_Unit
);
7547 pragma Assert
(Nkind
(Encl_Unit
) = N_Compilation_Unit
);
7549 end Enclosing_Lib_Unit_Node
;
7551 -----------------------
7552 -- Enclosing_Package --
7553 -----------------------
7555 function Enclosing_Package
(N
: Node_Or_Entity_Id
) return Entity_Id
is
7556 Dynamic_Scope
: Entity_Id
;
7559 -- Obtain the enclosing scope when N is a Node_Id - taking care to
7560 -- handle the case when the enclosing scope is already a package.
7562 if Nkind
(N
) not in N_Entity
then
7564 Encl_Scop
: constant Entity_Id
:= Find_Enclosing_Scope
(N
);
7566 if No
(Encl_Scop
) then
7568 elsif Ekind
(Encl_Scop
) in
7569 E_Generic_Package | E_Package | E_Package_Body
7574 return Enclosing_Package
(Encl_Scop
);
7578 -- When N is already an Entity_Id proceed
7580 Dynamic_Scope
:= Enclosing_Dynamic_Scope
(N
);
7581 if Dynamic_Scope
= Standard_Standard
then
7582 return Standard_Standard
;
7584 elsif Dynamic_Scope
= Empty
then
7587 elsif Ekind
(Dynamic_Scope
) in
7588 E_Generic_Package | E_Package | E_Package_Body
7590 return Dynamic_Scope
;
7593 return Enclosing_Package
(Dynamic_Scope
);
7595 end Enclosing_Package
;
7597 -------------------------------------
7598 -- Enclosing_Package_Or_Subprogram --
7599 -------------------------------------
7601 function Enclosing_Package_Or_Subprogram
(E
: Entity_Id
) return Entity_Id
is
7606 while Present
(S
) loop
7607 if Is_Package_Or_Generic_Package
(S
)
7608 or else Is_Subprogram_Or_Generic_Subprogram
(S
)
7618 end Enclosing_Package_Or_Subprogram
;
7620 --------------------------
7621 -- Enclosing_Subprogram --
7622 --------------------------
7624 function Enclosing_Subprogram
(N
: Node_Or_Entity_Id
) return Entity_Id
is
7625 Dyn_Scop
: Entity_Id
;
7626 Encl_Scop
: Entity_Id
;
7629 -- Obtain the enclosing scope when N is a Node_Id - taking care to
7630 -- handle the case when the enclosing scope is already a subprogram.
7632 if Nkind
(N
) not in N_Entity
then
7633 Encl_Scop
:= Find_Enclosing_Scope
(N
);
7635 if No
(Encl_Scop
) then
7637 elsif Ekind
(Encl_Scop
) in Subprogram_Kind
then
7641 return Enclosing_Subprogram
(Encl_Scop
);
7644 -- When N is already an Entity_Id proceed
7646 Dyn_Scop
:= Enclosing_Dynamic_Scope
(N
);
7647 if Dyn_Scop
= Standard_Standard
then
7650 elsif Dyn_Scop
= Empty
then
7653 elsif Ekind
(Dyn_Scop
) = E_Subprogram_Body
then
7654 return Corresponding_Spec
(Parent
(Parent
(Dyn_Scop
)));
7656 elsif Ekind
(Dyn_Scop
) in E_Block | E_Loop | E_Return_Statement
then
7657 return Enclosing_Subprogram
(Dyn_Scop
);
7659 elsif Ekind
(Dyn_Scop
) in E_Entry | E_Entry_Family
then
7661 -- For a task entry or entry family, return the enclosing subprogram
7662 -- of the task itself.
7664 if Ekind
(Scope
(Dyn_Scop
)) = E_Task_Type
then
7665 return Enclosing_Subprogram
(Dyn_Scop
);
7667 -- A protected entry or entry family is rewritten as a protected
7668 -- procedure which is the desired enclosing subprogram. This is
7669 -- relevant when unnesting a procedure local to an entry body.
7672 return Protected_Body_Subprogram
(Dyn_Scop
);
7675 elsif Ekind
(Dyn_Scop
) = E_Task_Type
then
7676 return Get_Task_Body_Procedure
(Dyn_Scop
);
7678 -- The scope may appear as a private type or as a private extension
7679 -- whose completion is a task or protected type.
7681 elsif Ekind
(Dyn_Scop
) in
7682 E_Limited_Private_Type | E_Record_Type_With_Private
7683 and then Present
(Full_View
(Dyn_Scop
))
7684 and then Ekind
(Full_View
(Dyn_Scop
)) in E_Task_Type | E_Protected_Type
7686 return Get_Task_Body_Procedure
(Full_View
(Dyn_Scop
));
7688 -- No body is generated if the protected operation is eliminated
7690 elsif not Is_Eliminated
(Dyn_Scop
)
7691 and then Present
(Protected_Body_Subprogram
(Dyn_Scop
))
7693 return Protected_Body_Subprogram
(Dyn_Scop
);
7698 end Enclosing_Subprogram
;
7700 --------------------------
7701 -- End_Keyword_Location --
7702 --------------------------
7704 function End_Keyword_Location
(N
: Node_Id
) return Source_Ptr
is
7705 function End_Label_Loc
(Nod
: Node_Id
) return Source_Ptr
;
7706 -- Return the source location of Nod's end label according to the
7707 -- following precedence rules:
7709 -- 1) If the end label exists, return its location
7710 -- 2) If Nod exists, return its location
7711 -- 3) Return the location of N
7717 function End_Label_Loc
(Nod
: Node_Id
) return Source_Ptr
is
7721 if Present
(Nod
) then
7722 Label
:= End_Label
(Nod
);
7724 if Present
(Label
) then
7725 return Sloc
(Label
);
7737 Owner
: Node_Id
:= Empty
;
7739 -- Start of processing for End_Keyword_Location
7742 if Nkind
(N
) in N_Block_Statement
7748 Owner
:= Handled_Statement_Sequence
(N
);
7750 elsif Nkind
(N
) = N_Package_Declaration
then
7751 Owner
:= Specification
(N
);
7753 elsif Nkind
(N
) = N_Protected_Body
then
7756 elsif Nkind
(N
) in N_Protected_Type_Declaration
7757 | N_Single_Protected_Declaration
7759 Owner
:= Protected_Definition
(N
);
7761 elsif Nkind
(N
) in N_Single_Task_Declaration | N_Task_Type_Declaration
7763 Owner
:= Task_Definition
(N
);
7765 -- This routine should not be called with other contexts
7768 pragma Assert
(False);
7772 return End_Label_Loc
(Owner
);
7773 end End_Keyword_Location
;
7775 ------------------------
7776 -- Ensure_Freeze_Node --
7777 ------------------------
7779 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
7782 if No
(Freeze_Node
(E
)) then
7783 FN
:= Make_Freeze_Entity
(Sloc
(E
));
7784 Set_Has_Delayed_Freeze
(E
);
7785 Set_Freeze_Node
(E
, FN
);
7786 Set_Access_Types_To_Process
(FN
, No_Elist
);
7787 Set_TSS_Elist
(FN
, No_Elist
);
7790 end Ensure_Freeze_Node
;
7796 procedure Enter_Name
(Def_Id
: Entity_Id
) is
7797 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
7798 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
7799 S
: constant Entity_Id
:= Current_Scope
;
7802 Generate_Definition
(Def_Id
);
7804 -- Add new name to current scope declarations. Check for duplicate
7805 -- declaration, which may or may not be a genuine error.
7809 -- Case of previous entity entered because of a missing declaration
7810 -- or else a bad subtype indication. Best is to use the new entity,
7811 -- and make the previous one invisible.
7813 if Etype
(E
) = Any_Type
then
7814 Set_Is_Immediately_Visible
(E
, False);
7816 -- Case of renaming declaration constructed for package instances.
7817 -- if there is an explicit declaration with the same identifier,
7818 -- the renaming is not immediately visible any longer, but remains
7819 -- visible through selected component notation.
7821 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
7822 and then not Comes_From_Source
(E
)
7824 Set_Is_Immediately_Visible
(E
, False);
7826 -- The new entity may be the package renaming, which has the same
7827 -- same name as a generic formal which has been seen already.
7829 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
7830 and then not Comes_From_Source
(Def_Id
)
7832 Set_Is_Immediately_Visible
(E
, False);
7834 -- For a fat pointer corresponding to a remote access to subprogram,
7835 -- we use the same identifier as the RAS type, so that the proper
7836 -- name appears in the stub. This type is only retrieved through
7837 -- the RAS type and never by visibility, and is not added to the
7838 -- visibility list (see below).
7840 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
7841 and then Ekind
(Def_Id
) = E_Record_Type
7842 and then Present
(Corresponding_Remote_Type
(Def_Id
))
7846 -- Case of an implicit operation or derived literal. The new entity
7847 -- hides the implicit one, which is removed from all visibility,
7848 -- i.e. the entity list of its scope, and homonym chain of its name.
7850 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
7851 or else Is_Internal
(E
)
7854 Decl
: constant Node_Id
:= Parent
(E
);
7856 Prev_Vis
: Entity_Id
;
7859 -- If E is an implicit declaration, it cannot be the first
7860 -- entity in the scope.
7862 Prev
:= First_Entity
(Current_Scope
);
7863 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
7869 -- If E is not on the entity chain of the current scope,
7870 -- it is an implicit declaration in the generic formal
7871 -- part of a generic subprogram. When analyzing the body,
7872 -- the generic formals are visible but not on the entity
7873 -- chain of the subprogram. The new entity will become
7874 -- the visible one in the body.
7877 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
7881 Link_Entities
(Prev
, Next_Entity
(E
));
7883 if No
(Next_Entity
(Prev
)) then
7884 Set_Last_Entity
(Current_Scope
, Prev
);
7887 if E
= Current_Entity
(E
) then
7891 Prev_Vis
:= Current_Entity
(E
);
7892 while Homonym
(Prev_Vis
) /= E
loop
7893 Prev_Vis
:= Homonym
(Prev_Vis
);
7897 if Present
(Prev_Vis
) then
7899 -- Skip E in the visibility chain
7901 Set_Homonym
(Prev_Vis
, Homonym
(E
));
7904 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
7907 -- The inherited operation cannot be retrieved
7908 -- by name, even though it may remain accesssible
7909 -- in some cases involving subprogram bodies without
7910 -- specs appearing in with_clauses..
7912 Set_Is_Immediately_Visible
(E
, False);
7916 -- This section of code could use a comment ???
7918 elsif Present
(Etype
(E
))
7919 and then Is_Concurrent_Type
(Etype
(E
))
7924 -- If the homograph is a protected component renaming, it should not
7925 -- be hiding the current entity. Such renamings are treated as weak
7928 elsif Is_Prival
(E
) then
7929 Set_Is_Immediately_Visible
(E
, False);
7931 -- In this case the current entity is a protected component renaming.
7932 -- Perform minimal decoration by setting the scope and return since
7933 -- the prival should not be hiding other visible entities.
7935 elsif Is_Prival
(Def_Id
) then
7936 Set_Scope
(Def_Id
, Current_Scope
);
7939 -- Analogous to privals, the discriminal generated for an entry index
7940 -- parameter acts as a weak declaration. Perform minimal decoration
7941 -- to avoid bogus errors.
7943 elsif Is_Discriminal
(Def_Id
)
7944 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
7946 Set_Scope
(Def_Id
, Current_Scope
);
7949 -- In the body or private part of an instance, a type extension may
7950 -- introduce a component with the same name as that of an actual. The
7951 -- legality rule is not enforced, but the semantics of the full type
7952 -- with two components of same name are not clear at this point???
7954 elsif In_Instance_Not_Visible
then
7957 -- When compiling a package body, some child units may have become
7958 -- visible. They cannot conflict with local entities that hide them.
7960 elsif Is_Child_Unit
(E
)
7961 and then In_Open_Scopes
(Scope
(E
))
7962 and then not Is_Immediately_Visible
(E
)
7966 -- Conversely, with front-end inlining we may compile the parent body
7967 -- first, and a child unit subsequently. The context is now the
7968 -- parent spec, and body entities are not visible.
7970 elsif Is_Child_Unit
(Def_Id
)
7971 and then Is_Package_Body_Entity
(E
)
7972 and then not In_Package_Body
(Current_Scope
)
7976 -- Case of genuine duplicate declaration
7979 Error_Msg_Sloc
:= Sloc
(E
);
7981 -- If the previous declaration is an incomplete type declaration
7982 -- this may be an attempt to complete it with a private type. The
7983 -- following avoids confusing cascaded errors.
7985 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
7986 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
7989 ("incomplete type cannot be completed with a private " &
7990 "declaration", Parent
(Def_Id
));
7991 Set_Is_Immediately_Visible
(E
, False);
7992 Set_Full_View
(E
, Def_Id
);
7994 -- An inherited component of a record conflicts with a new
7995 -- discriminant. The discriminant is inserted first in the scope,
7996 -- but the error should be posted on it, not on the component.
7998 elsif Ekind
(E
) = E_Discriminant
7999 and then Present
(Scope
(Def_Id
))
8000 and then Scope
(Def_Id
) /= Current_Scope
8002 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8003 Error_Msg_N
("& conflicts with declaration#", E
);
8006 -- If the name of the unit appears in its own context clause, a
8007 -- dummy package with the name has already been created, and the
8008 -- error emitted. Try to continue quietly.
8010 elsif Error_Posted
(E
)
8011 and then Sloc
(E
) = No_Location
8012 and then Nkind
(Parent
(E
)) = N_Package_Specification
8013 and then Current_Scope
= Standard_Standard
8015 Set_Scope
(Def_Id
, Current_Scope
);
8019 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
8021 -- Avoid cascaded messages with duplicate components in
8024 if Ekind
(E
) in E_Component | E_Discriminant
then
8029 if Nkind
(Parent
(Parent
(Def_Id
))) =
8030 N_Generic_Subprogram_Declaration
8032 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
8034 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
8037 -- If entity is in standard, then we are in trouble, because it
8038 -- means that we have a library package with a duplicated name.
8039 -- That's hard to recover from, so abort.
8041 if S
= Standard_Standard
then
8042 raise Unrecoverable_Error
;
8044 -- Otherwise we continue with the declaration. Having two
8045 -- identical declarations should not cause us too much trouble.
8053 -- If we fall through, declaration is OK, at least OK enough to continue
8055 -- If Def_Id is a discriminant or a record component we are in the midst
8056 -- of inheriting components in a derived record definition. Preserve
8057 -- their Ekind and Etype.
8059 if Ekind
(Def_Id
) in E_Discriminant | E_Component
then
8062 -- If a type is already set, leave it alone (happens when a type
8063 -- declaration is reanalyzed following a call to the optimizer).
8065 elsif Present
(Etype
(Def_Id
)) then
8069 Set_Etype
(Def_Id
, Any_Type
); -- avoid cascaded errors
8072 -- All entities except Itypes are immediately visible
8074 if not Is_Itype
(Def_Id
) then
8075 Set_Is_Immediately_Visible
(Def_Id
);
8076 Set_Current_Entity
(Def_Id
);
8079 Set_Homonym
(Def_Id
, C
);
8080 Append_Entity
(Def_Id
, S
);
8081 Set_Public_Status
(Def_Id
);
8083 -- Warn if new entity hides an old one
8085 if Warn_On_Hiding
and then Present
(C
) then
8086 Warn_On_Hiding_Entity
(Def_Id
, Hidden
=> C
, Visible
=> Def_Id
,
8087 On_Use_Clause
=> False);
8095 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
8100 -- Assume that the arbitrary node does not have an entity
8104 if Is_Entity_Name
(N
) then
8107 -- Follow a possible chain of renamings to reach the earliest renamed
8111 and then Is_Object
(Id
)
8112 and then Present
(Renamed_Object
(Id
))
8114 Ren
:= Renamed_Object
(Id
);
8116 -- The reference renames an abstract state or a whole object
8119 -- Ren : ... renames Obj;
8121 if Is_Entity_Name
(Ren
) then
8123 -- Do not follow a renaming that goes through a generic formal,
8124 -- because these entities are hidden and must not be referenced
8125 -- from outside the generic.
8127 if Is_Hidden
(Entity
(Ren
)) then
8134 -- The reference renames a function result. Check the original
8135 -- node in case expansion relocates the function call.
8137 -- Ren : ... renames Func_Call;
8139 elsif Nkind
(Original_Node
(Ren
)) = N_Function_Call
then
8142 -- Otherwise the reference renames something which does not yield
8143 -- an abstract state or a whole object. Treat the reference as not
8144 -- having a proper entity for SPARK legality purposes.
8156 --------------------------
8157 -- Examine_Array_Bounds --
8158 --------------------------
8160 procedure Examine_Array_Bounds
8162 All_Static
: out Boolean;
8163 Has_Empty
: out Boolean)
8165 function Is_OK_Static_Bound
(Bound
: Node_Id
) return Boolean;
8166 -- Determine whether bound Bound is a suitable static bound
8168 ------------------------
8169 -- Is_OK_Static_Bound --
8170 ------------------------
8172 function Is_OK_Static_Bound
(Bound
: Node_Id
) return Boolean is
8175 not Error_Posted
(Bound
)
8176 and then Is_OK_Static_Expression
(Bound
);
8177 end Is_OK_Static_Bound
;
8185 -- Start of processing for Examine_Array_Bounds
8188 -- An unconstrained array type does not have static bounds, and it is
8189 -- not known whether they are empty or not.
8191 if not Is_Constrained
(Typ
) then
8192 All_Static
:= False;
8195 -- A string literal has static bounds, and is not empty as long as it
8196 -- contains at least one character.
8198 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
8200 Has_Empty
:= String_Literal_Length
(Typ
) > 0;
8203 -- Assume that all bounds are static and not empty
8208 -- Examine each index
8210 Index
:= First_Index
(Typ
);
8211 while Present
(Index
) loop
8212 if Is_Discrete_Type
(Etype
(Index
)) then
8213 Get_Index_Bounds
(Index
, Lo_Bound
, Hi_Bound
);
8215 if Is_OK_Static_Bound
(Lo_Bound
)
8217 Is_OK_Static_Bound
(Hi_Bound
)
8219 -- The static bounds produce an empty range
8221 if Is_Null_Range
(Lo_Bound
, Hi_Bound
) then
8225 -- Otherwise at least one of the bounds is not static
8228 All_Static
:= False;
8231 -- Otherwise the index is non-discrete, therefore not static
8234 All_Static
:= False;
8239 end Examine_Array_Bounds
;
8245 function Exceptions_OK
return Boolean is
8248 not (Restriction_Active
(No_Exception_Handlers
) or else
8249 Restriction_Active
(No_Exception_Propagation
) or else
8250 Restriction_Active
(No_Exceptions
));
8253 --------------------------
8254 -- Explain_Limited_Type --
8255 --------------------------
8257 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
8261 -- For array, component type must be limited
8263 if Is_Array_Type
(T
) then
8264 Error_Msg_Node_2
:= T
;
8266 ("\component type& of type& is limited", N
, Component_Type
(T
));
8267 Explain_Limited_Type
(Component_Type
(T
), N
);
8269 elsif Is_Record_Type
(T
) then
8271 -- No need for extra messages if explicit limited record
8273 if Is_Limited_Record
(Base_Type
(T
)) then
8277 -- Otherwise find a limited component. Check only components that
8278 -- come from source, or inherited components that appear in the
8279 -- source of the ancestor.
8281 C
:= First_Component
(T
);
8282 while Present
(C
) loop
8283 if Is_Limited_Type
(Etype
(C
))
8285 (Comes_From_Source
(C
)
8287 (Present
(Original_Record_Component
(C
))
8289 Comes_From_Source
(Original_Record_Component
(C
))))
8291 Error_Msg_Node_2
:= T
;
8292 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
8293 Explain_Limited_Type
(Etype
(C
), N
);
8300 -- The type may be declared explicitly limited, even if no component
8301 -- of it is limited, in which case we fall out of the loop.
8304 end Explain_Limited_Type
;
8306 ---------------------------------------
8307 -- Expression_Of_Expression_Function --
8308 ---------------------------------------
8310 function Expression_Of_Expression_Function
8311 (Subp
: Entity_Id
) return Node_Id
8313 Expr_Func
: Node_Id
:= Empty
;
8316 pragma Assert
(Is_Expression_Function_Or_Completion
(Subp
));
8318 if Nkind
(Original_Node
(Subprogram_Spec
(Subp
))) =
8319 N_Expression_Function
8321 Expr_Func
:= Original_Node
(Subprogram_Spec
(Subp
));
8323 elsif Nkind
(Original_Node
(Subprogram_Body
(Subp
))) =
8324 N_Expression_Function
8326 Expr_Func
:= Original_Node
(Subprogram_Body
(Subp
));
8329 pragma Assert
(False);
8333 return Original_Node
(Expression
(Expr_Func
));
8334 end Expression_Of_Expression_Function
;
8336 -------------------------------
8337 -- Extensions_Visible_Status --
8338 -------------------------------
8340 function Extensions_Visible_Status
8341 (Id
: Entity_Id
) return Extensions_Visible_Mode
8350 -- When a formal parameter is subject to Extensions_Visible, the pragma
8351 -- is stored in the contract of related subprogram.
8353 if Is_Formal
(Id
) then
8356 elsif Is_Subprogram_Or_Generic_Subprogram
(Id
) then
8359 -- No other construct carries this pragma
8362 return Extensions_Visible_None
;
8365 Prag
:= Get_Pragma
(Subp
, Pragma_Extensions_Visible
);
8367 -- In certain cases analysis may request the Extensions_Visible status
8368 -- of an expression function before the pragma has been analyzed yet.
8369 -- Inspect the declarative items after the expression function looking
8370 -- for the pragma (if any).
8372 if No
(Prag
) and then Is_Expression_Function
(Subp
) then
8373 Decl
:= Next
(Unit_Declaration_Node
(Subp
));
8374 while Present
(Decl
) loop
8375 if Nkind
(Decl
) = N_Pragma
8376 and then Pragma_Name
(Decl
) = Name_Extensions_Visible
8381 -- A source construct ends the region where Extensions_Visible may
8382 -- appear, stop the traversal. An expanded expression function is
8383 -- no longer a source construct, but it must still be recognized.
8385 elsif Comes_From_Source
(Decl
)
8387 (Nkind
(Decl
) in N_Subprogram_Body | N_Subprogram_Declaration
8388 and then Is_Expression_Function
(Defining_Entity
(Decl
)))
8397 -- Extract the value from the Boolean expression (if any)
8399 if Present
(Prag
) then
8400 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
8402 if Present
(Arg
) then
8403 Expr
:= Get_Pragma_Arg
(Arg
);
8405 -- When the associated subprogram is an expression function, the
8406 -- argument of the pragma may not have been analyzed.
8408 if not Analyzed
(Expr
) then
8409 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
8412 -- Guard against cascading errors when the argument of pragma
8413 -- Extensions_Visible is not a valid static Boolean expression.
8415 if Error_Posted
(Expr
) then
8416 return Extensions_Visible_None
;
8418 elsif Is_True
(Expr_Value
(Expr
)) then
8419 return Extensions_Visible_True
;
8422 return Extensions_Visible_False
;
8425 -- Otherwise the aspect or pragma defaults to True
8428 return Extensions_Visible_True
;
8431 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
8432 -- directly specified. In SPARK code, its value defaults to "False".
8434 elsif SPARK_Mode
= On
then
8435 return Extensions_Visible_False
;
8437 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
8441 return Extensions_Visible_True
;
8443 end Extensions_Visible_Status
;
8449 procedure Find_Actual
8451 Formal
: out Entity_Id
;
8454 Context
: constant Node_Id
:= Parent
(N
);
8457 Call_Ent
: Node_Id
:= Empty
;
8460 if Nkind
(Context
) in N_Indexed_Component | N_Selected_Component
8461 and then N
= Prefix
(Context
)
8463 Find_Actual
(Context
, Formal
, Call
);
8466 elsif Nkind
(Context
) = N_Parameter_Association
8467 and then N
= Explicit_Actual_Parameter
(Context
)
8469 Call
:= Parent
(Context
);
8471 elsif Nkind
(Context
) in N_Entry_Call_Statement
8473 | N_Procedure_Call_Statement
8483 -- If we have a call to a subprogram look for the parameter. Note that
8484 -- we exclude overloaded calls, since we don't know enough to be sure
8485 -- of giving the right answer in this case.
8487 if Nkind
(Call
) in N_Entry_Call_Statement
8489 | N_Procedure_Call_Statement
8491 Call_Nam
:= Name
(Call
);
8493 -- A call to an entry family may appear as an indexed component
8495 if Nkind
(Call_Nam
) = N_Indexed_Component
then
8496 Call_Nam
:= Prefix
(Call_Nam
);
8499 -- A call to a protected or task entry appears as a selected
8500 -- component rather than an expanded name.
8502 if Nkind
(Call_Nam
) = N_Selected_Component
then
8503 Call_Nam
:= Selector_Name
(Call_Nam
);
8506 -- If Call_Nam is an entity name, get its entity
8508 if Is_Entity_Name
(Call_Nam
) then
8509 Call_Ent
:= Entity
(Call_Nam
);
8511 -- If it is a dereference, get the designated subprogram type
8513 elsif Nkind
(Call_Nam
) = N_Explicit_Dereference
then
8515 Typ
: Entity_Id
:= Etype
(Prefix
(Call_Nam
));
8517 if Present
(Full_View
(Typ
)) then
8518 Typ
:= Full_View
(Typ
);
8519 elsif Is_Private_Type
(Typ
)
8520 and then Present
(Underlying_Full_View
(Typ
))
8522 Typ
:= Underlying_Full_View
(Typ
);
8525 if Is_Access_Type
(Typ
) then
8526 Call_Ent
:= Directly_Designated_Type
(Typ
);
8528 pragma Assert
(Has_Implicit_Dereference
(Typ
));
8536 if Present
(Call_Ent
)
8537 and then (Is_Generic_Subprogram
(Call_Ent
)
8538 or else Is_Overloadable
(Call_Ent
)
8539 or else Ekind
(Call_Ent
) in E_Entry_Family
8541 | E_Subprogram_Type
)
8542 and then not Is_Overloaded
(Call_Nam
)
8544 -- If node is name in call it is not an actual
8546 if N
= Call_Nam
then
8552 -- Fall here if we are definitely a parameter
8554 Actual
:= First_Actual
(Call
);
8555 Formal
:= First_Formal
(Call_Ent
);
8556 while Present
(Formal
) and then Present
(Actual
) loop
8560 -- An actual that is the prefix in a prefixed call may have
8561 -- been rewritten in the call. Check if sloc and kinds and
8564 elsif Sloc
(Actual
) = Sloc
(N
)
8565 and then Nkind
(Actual
) = N_Identifier
8566 and then Nkind
(Actual
) = Nkind
(N
)
8567 and then Chars
(Actual
) = Chars
(N
)
8572 Next_Actual
(Actual
);
8573 Next_Formal
(Formal
);
8579 -- Fall through here if we did not find matching actual
8585 ---------------------------
8586 -- Find_Body_Discriminal --
8587 ---------------------------
8589 function Find_Body_Discriminal
8590 (Spec_Discriminant
: Entity_Id
) return Entity_Id
8596 -- If expansion is suppressed, then the scope can be the concurrent type
8597 -- itself rather than a corresponding concurrent record type.
8599 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
8600 Tsk
:= Scope
(Spec_Discriminant
);
8603 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
8605 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
8608 -- Find discriminant of original concurrent type, and use its current
8609 -- discriminal, which is the renaming within the task/protected body.
8611 Disc
:= First_Discriminant
(Tsk
);
8612 while Present
(Disc
) loop
8613 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
8614 return Discriminal
(Disc
);
8617 Next_Discriminant
(Disc
);
8620 -- That loop should always succeed in finding a matching entry and
8621 -- returning. Fatal error if not.
8623 raise Program_Error
;
8624 end Find_Body_Discriminal
;
8626 -------------------------------------
8627 -- Find_Corresponding_Discriminant --
8628 -------------------------------------
8630 function Find_Corresponding_Discriminant
8632 Typ
: Entity_Id
) return Entity_Id
8634 Par_Disc
: Entity_Id
;
8635 Old_Disc
: Entity_Id
;
8636 New_Disc
: Entity_Id
;
8639 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
8641 -- The original type may currently be private, and the discriminant
8642 -- only appear on its full view.
8644 if Is_Private_Type
(Scope
(Par_Disc
))
8645 and then not Has_Discriminants
(Scope
(Par_Disc
))
8646 and then Present
(Full_View
(Scope
(Par_Disc
)))
8648 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
8650 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
8653 if Is_Class_Wide_Type
(Typ
) then
8654 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
8656 New_Disc
:= First_Discriminant
(Typ
);
8659 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
8660 if Old_Disc
= Par_Disc
then
8664 Next_Discriminant
(Old_Disc
);
8665 Next_Discriminant
(New_Disc
);
8668 -- Should always find it
8670 raise Program_Error
;
8671 end Find_Corresponding_Discriminant
;
8677 function Find_DIC_Type
(Typ
: Entity_Id
) return Entity_Id
is
8678 Curr_Typ
: Entity_Id
;
8679 -- The current type being examined in the parent hierarchy traversal
8681 DIC_Typ
: Entity_Id
;
8682 -- The type which carries the DIC pragma. This variable denotes the
8683 -- partial view when private types are involved.
8685 Par_Typ
: Entity_Id
;
8686 -- The parent type of the current type. This variable denotes the full
8687 -- view when private types are involved.
8690 -- The input type defines its own DIC pragma, therefore it is the owner
8692 if Has_Own_DIC
(Typ
) then
8695 -- Otherwise the DIC pragma is inherited from a parent type
8698 pragma Assert
(Has_Inherited_DIC
(Typ
));
8700 -- Climb the parent chain
8704 -- Inspect the parent type. Do not consider subtypes as they
8705 -- inherit the DIC attributes from their base types.
8707 DIC_Typ
:= Base_Type
(Etype
(Curr_Typ
));
8709 -- Look at the full view of a private type because the type may
8710 -- have a hidden parent introduced in the full view.
8714 if Is_Private_Type
(Par_Typ
)
8715 and then Present
(Full_View
(Par_Typ
))
8717 Par_Typ
:= Full_View
(Par_Typ
);
8720 -- Stop the climb once the nearest parent type which defines a DIC
8721 -- pragma of its own is encountered or when the root of the parent
8722 -- chain is reached.
8724 exit when Has_Own_DIC
(DIC_Typ
) or else Curr_Typ
= Par_Typ
;
8726 Curr_Typ
:= Par_Typ
;
8733 ----------------------------------
8734 -- Find_Enclosing_Iterator_Loop --
8735 ----------------------------------
8737 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
8742 -- Traverse the scope chain looking for an iterator loop. Such loops are
8743 -- usually transformed into blocks, hence the use of Original_Node.
8746 while Present
(S
) and then S
/= Standard_Standard
loop
8747 if Ekind
(S
) = E_Loop
8748 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
8750 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
8752 if Nkind
(Constr
) = N_Loop_Statement
8753 and then Present
(Iteration_Scheme
(Constr
))
8754 and then Nkind
(Iterator_Specification
8755 (Iteration_Scheme
(Constr
))) =
8756 N_Iterator_Specification
8766 end Find_Enclosing_Iterator_Loop
;
8768 --------------------------
8769 -- Find_Enclosing_Scope --
8770 --------------------------
8772 function Find_Enclosing_Scope
(N
: Node_Id
) return Scope_Kind_Id
is
8776 -- If N is an entity, simply return its Scope
8778 if Nkind
(N
) in N_Entity
then
8782 -- Examine the parent chain looking for a construct which defines a
8786 while Present
(Par
) loop
8789 -- The construct denotes a declaration, the proper scope is its
8792 when N_Entry_Declaration
8793 | N_Expression_Function
8794 | N_Full_Type_Declaration
8795 | N_Generic_Package_Declaration
8796 | N_Generic_Subprogram_Declaration
8797 | N_Package_Declaration
8798 | N_Private_Extension_Declaration
8799 | N_Protected_Type_Declaration
8800 | N_Single_Protected_Declaration
8801 | N_Single_Task_Declaration
8802 | N_Subprogram_Declaration
8803 | N_Task_Type_Declaration
8805 return Defining_Entity
(Par
);
8807 -- The construct denotes a body, the proper scope is the entity of
8808 -- the corresponding spec or that of the body if the body does not
8809 -- complete a previous declaration.
8817 return Unique_Defining_Entity
(Par
);
8821 -- Blocks carry either a source or an internally-generated scope,
8822 -- unless the block is a byproduct of exception handling.
8824 when N_Block_Statement
=>
8825 if not Exception_Junk
(Par
) then
8826 return Entity
(Identifier
(Par
));
8829 -- Loops carry an internally-generated scope
8831 when N_Loop_Statement
=>
8832 return Entity
(Identifier
(Par
));
8834 -- Extended return statements carry an internally-generated scope
8836 when N_Extended_Return_Statement
=>
8837 return Return_Statement_Entity
(Par
);
8839 -- A traversal from a subunit continues via the corresponding stub
8842 Par
:= Corresponding_Stub
(Par
);
8848 Par
:= Parent
(Par
);
8851 return Standard_Standard
;
8852 end Find_Enclosing_Scope
;
8854 ------------------------------------
8855 -- Find_Loop_In_Conditional_Block --
8856 ------------------------------------
8858 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
8864 if Nkind
(Stmt
) = N_If_Statement
then
8865 Stmt
:= First
(Then_Statements
(Stmt
));
8868 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
8870 -- Inspect the statements of the conditional block. In general the loop
8871 -- should be the first statement in the statement sequence of the block,
8872 -- but the finalization machinery may have introduced extra object
8875 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
8876 while Present
(Stmt
) loop
8877 if Nkind
(Stmt
) = N_Loop_Statement
then
8884 -- The expansion of attribute 'Loop_Entry produced a malformed block
8886 raise Program_Error
;
8887 end Find_Loop_In_Conditional_Block
;
8889 --------------------------
8890 -- Find_Overlaid_Entity --
8891 --------------------------
8893 procedure Find_Overlaid_Entity
8895 Ent
: out Entity_Id
;
8899 (Nkind
(N
) = N_Attribute_Definition_Clause
8900 and then Chars
(N
) = Name_Address
);
8905 -- We are looking for one of the two following forms:
8907 -- for X'Address use Y'Address
8911 -- Const : constant Address := expr;
8913 -- for X'Address use Const;
8915 -- In the second case, the expr is either Y'Address, or recursively a
8916 -- constant that eventually references Y'Address.
8921 Expr
:= Expression
(N
);
8923 -- This loop checks the form of the expression for Y'Address, using
8924 -- recursion to deal with intermediate constants.
8927 -- Check for Y'Address
8929 if Nkind
(Expr
) = N_Attribute_Reference
8930 and then Attribute_Name
(Expr
) = Name_Address
8932 Expr
:= Prefix
(Expr
);
8935 -- Check for Const where Const is a constant entity
8937 elsif Is_Entity_Name
(Expr
)
8938 and then Ekind
(Entity
(Expr
)) = E_Constant
8940 Expr
:= Constant_Value
(Entity
(Expr
));
8942 -- Anything else does not need checking
8949 -- This loop checks the form of the prefix for an entity, using
8950 -- recursion to deal with intermediate components.
8953 -- Check for Y where Y is an entity
8955 if Is_Entity_Name
(Expr
) then
8956 Ent
:= Entity
(Expr
);
8958 -- If expansion is disabled, then we might see an entity of a
8959 -- protected component or of a discriminant of a concurrent unit.
8960 -- Ignore such entities, because further warnings for overlays
8961 -- expect this routine to only collect entities of entire objects.
8963 if Ekind
(Ent
) in E_Component | E_Discriminant
then
8965 (not Expander_Active
8966 and then Is_Concurrent_Type
(Scope
(Ent
)));
8971 -- Check for components
8973 elsif Nkind
(Expr
) in N_Selected_Component | N_Indexed_Component
then
8974 Expr
:= Prefix
(Expr
);
8977 -- Anything else does not need checking
8983 end Find_Overlaid_Entity
;
8985 -------------------------
8986 -- Find_Parameter_Type --
8987 -------------------------
8989 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
8991 if Nkind
(Param
) /= N_Parameter_Specification
then
8994 -- For an access parameter, obtain the type from the formal entity
8995 -- itself, because access to subprogram nodes do not carry a type.
8996 -- Shouldn't we always use the formal entity ???
8998 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
8999 return Etype
(Defining_Identifier
(Param
));
9002 return Etype
(Parameter_Type
(Param
));
9004 end Find_Parameter_Type
;
9006 -----------------------------------
9007 -- Find_Placement_In_State_Space --
9008 -----------------------------------
9010 procedure Find_Placement_In_State_Space
9011 (Item_Id
: Entity_Id
;
9012 Placement
: out State_Space_Kind
;
9013 Pack_Id
: out Entity_Id
)
9015 function Inside_Package_Body
(Id
: Entity_Id
) return Boolean;
9016 function Inside_Private_Part
(Id
: Entity_Id
) return Boolean;
9017 -- Return True if Id is declared directly within the package body
9018 -- and the package private parts, respectively. We cannot use
9019 -- In_Private_Part/In_Body_Part flags, as these are only set during the
9020 -- analysis of the package itself, while Find_Placement_In_State_Space
9021 -- can be called on an entity of another package.
9023 ------------------------
9024 -- Inside_Package_Body --
9025 ------------------------
9027 function Inside_Package_Body
(Id
: Entity_Id
) return Boolean is
9028 Spec_Id
: constant Entity_Id
:= Scope
(Id
);
9029 Body_Decl
: constant Opt_N_Package_Body_Id
:= Package_Body
(Spec_Id
);
9030 Decl
: constant Node_Id
:= Enclosing_Declaration
(Id
);
9032 if Present
(Body_Decl
)
9033 and then Is_List_Member
(Decl
)
9034 and then List_Containing
(Decl
) = Declarations
(Body_Decl
)
9040 end Inside_Package_Body
;
9042 -------------------------
9043 -- Inside_Private_Part --
9044 -------------------------
9046 function Inside_Private_Part
(Id
: Entity_Id
) return Boolean is
9047 Spec_Id
: constant Entity_Id
:= Scope
(Id
);
9048 Private_Decls
: constant List_Id
:=
9049 Private_Declarations
(Package_Specification
(Spec_Id
));
9050 Decl
: constant Node_Id
:= Enclosing_Declaration
(Id
);
9052 if Is_List_Member
(Decl
)
9053 and then List_Containing
(Decl
) = Private_Decls
9057 elsif Ekind
(Id
) = E_Package
9058 and then Is_Private_Library_Unit
(Id
)
9065 end Inside_Private_Part
;
9069 Context
: Entity_Id
;
9071 -- Start of processing for Find_Placement_In_State_Space
9074 -- Assume that the item does not appear in the state space of a package
9076 Placement
:= Not_In_Package
;
9078 -- Climb the scope stack and examine the enclosing context
9081 Pack_Id
:= Scope
(Context
);
9082 while Present
(Pack_Id
) and then Pack_Id
/= Standard_Standard
loop
9083 if Is_Package_Or_Generic_Package
(Pack_Id
) then
9085 -- A package body is a cut off point for the traversal as the
9086 -- item cannot be visible to the outside from this point on.
9088 if Inside_Package_Body
(Context
) then
9089 Placement
:= Body_State_Space
;
9092 -- The private part of a package is a cut off point for the
9093 -- traversal as the item cannot be visible to the outside
9094 -- from this point on.
9096 elsif Inside_Private_Part
(Context
) then
9097 Placement
:= Private_State_Space
;
9100 -- When the item appears in the visible state space of a package,
9101 -- continue to climb the scope stack as this may not be the final
9105 Placement
:= Visible_State_Space
;
9107 -- The visible state space of a child unit acts as the proper
9108 -- placement of an item, unless this is a private child unit.
9110 if Is_Child_Unit
(Pack_Id
)
9111 and then not Is_Private_Library_Unit
(Pack_Id
)
9117 -- The item or its enclosing package appear in a construct that has
9121 Placement
:= Not_In_Package
;
9126 Context
:= Scope
(Context
);
9127 Pack_Id
:= Scope
(Context
);
9129 end Find_Placement_In_State_Space
;
9131 -----------------------
9132 -- Find_Primitive_Eq --
9133 -----------------------
9135 function Find_Primitive_Eq
(Typ
: Entity_Id
) return Entity_Id
is
9136 function Find_Eq_Prim
(Prims_List
: Elist_Id
) return Entity_Id
;
9137 -- Search for the equality primitive; return Empty if the primitive is
9144 function Find_Eq_Prim
(Prims_List
: Elist_Id
) return Entity_Id
is
9146 Prim_Elmt
: Elmt_Id
;
9149 Prim_Elmt
:= First_Elmt
(Prims_List
);
9150 while Present
(Prim_Elmt
) loop
9151 Prim
:= Node
(Prim_Elmt
);
9153 -- Locate primitive equality with the right signature
9155 if Chars
(Prim
) = Name_Op_Eq
9156 and then Etype
(First_Formal
(Prim
)) =
9157 Etype
(Next_Formal
(First_Formal
(Prim
)))
9158 and then Base_Type
(Etype
(Prim
)) = Standard_Boolean
9163 Next_Elmt
(Prim_Elmt
);
9171 Eq_Prim
: Entity_Id
;
9172 Full_Type
: Entity_Id
;
9174 -- Start of processing for Find_Primitive_Eq
9177 if Is_Private_Type
(Typ
) then
9178 Full_Type
:= Underlying_Type
(Typ
);
9183 if No
(Full_Type
) then
9187 Full_Type
:= Base_Type
(Full_Type
);
9189 -- When the base type itself is private, use the full view
9191 if Is_Private_Type
(Full_Type
) then
9192 Full_Type
:= Underlying_Type
(Full_Type
);
9195 if Is_Class_Wide_Type
(Full_Type
) then
9196 Full_Type
:= Root_Type
(Full_Type
);
9199 if not Is_Tagged_Type
(Full_Type
) then
9200 Eq_Prim
:= Find_Eq_Prim
(Collect_Primitive_Operations
(Typ
));
9202 -- If this is an untagged private type completed with a derivation of
9203 -- an untagged private type whose full view is a tagged type, we use
9204 -- the primitive operations of the private parent type (since it does
9205 -- not have a full view, and also because its equality primitive may
9206 -- have been overridden in its untagged full view). If no equality was
9207 -- defined for it then take its dispatching equality primitive.
9209 elsif Inherits_From_Tagged_Full_View
(Typ
) then
9210 Eq_Prim
:= Find_Eq_Prim
(Collect_Primitive_Operations
(Typ
));
9212 if No
(Eq_Prim
) then
9213 Eq_Prim
:= Find_Eq_Prim
(Primitive_Operations
(Full_Type
));
9217 Eq_Prim
:= Find_Eq_Prim
(Primitive_Operations
(Full_Type
));
9221 end Find_Primitive_Eq
;
9223 ------------------------
9224 -- Find_Specific_Type --
9225 ------------------------
9227 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
9228 Typ
: Entity_Id
:= Root_Type
(CW
);
9231 if Ekind
(Typ
) = E_Incomplete_Type
then
9232 if From_Limited_With
(Typ
) then
9233 Typ
:= Non_Limited_View
(Typ
);
9235 Typ
:= Full_View
(Typ
);
9239 if Is_Private_Type
(Typ
)
9240 and then not Is_Tagged_Type
(Typ
)
9241 and then Present
(Full_View
(Typ
))
9243 return Full_View
(Typ
);
9247 end Find_Specific_Type
;
9249 -----------------------------
9250 -- Find_Static_Alternative --
9251 -----------------------------
9253 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
9254 Expr
: constant Node_Id
:= Expression
(N
);
9255 Val
: constant Uint
:= Expr_Value
(Expr
);
9260 Alt
:= First
(Alternatives
(N
));
9263 if Nkind
(Alt
) /= N_Pragma
then
9264 Choice
:= First
(Discrete_Choices
(Alt
));
9265 while Present
(Choice
) loop
9267 -- Others choice, always matches
9269 if Nkind
(Choice
) = N_Others_Choice
then
9272 -- Range, check if value is in the range
9274 elsif Nkind
(Choice
) = N_Range
then
9276 Val
>= Expr_Value
(Low_Bound
(Choice
))
9278 Val
<= Expr_Value
(High_Bound
(Choice
));
9280 -- Choice is a subtype name. Note that we know it must
9281 -- be a static subtype, since otherwise it would have
9282 -- been diagnosed as illegal.
9284 elsif Is_Entity_Name
(Choice
)
9285 and then Is_Type
(Entity
(Choice
))
9287 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
9288 Assume_Valid
=> False);
9290 -- Choice is a subtype indication
9292 elsif Nkind
(Choice
) = N_Subtype_Indication
then
9294 C
: constant Node_Id
:= Constraint
(Choice
);
9295 R
: constant Node_Id
:= Range_Expression
(C
);
9299 Val
>= Expr_Value
(Low_Bound
(R
))
9301 Val
<= Expr_Value
(High_Bound
(R
));
9304 -- Choice is a simple expression
9307 exit Search
when Val
= Expr_Value
(Choice
);
9315 pragma Assert
(Present
(Alt
));
9318 -- The above loop *must* terminate by finding a match, since we know the
9319 -- case statement is valid, and the value of the expression is known at
9320 -- compile time. When we fall out of the loop, Alt points to the
9321 -- alternative that we know will be selected at run time.
9324 end Find_Static_Alternative
;
9330 function First_Actual
(Node
: Node_Id
) return Node_Id
is
9334 if No
(Parameter_Associations
(Node
)) then
9338 N
:= First
(Parameter_Associations
(Node
));
9340 if Nkind
(N
) = N_Parameter_Association
then
9341 return First_Named_Actual
(Node
);
9351 function First_Global
9353 Global_Mode
: Name_Id
;
9354 Refined
: Boolean := False) return Node_Id
9356 function First_From_Global_List
9358 Global_Mode
: Name_Id
:= Name_Input
) return Entity_Id
;
9359 -- Get the first item with suitable mode from List
9361 ----------------------------
9362 -- First_From_Global_List --
9363 ----------------------------
9365 function First_From_Global_List
9367 Global_Mode
: Name_Id
:= Name_Input
) return Entity_Id
9372 -- Empty list (no global items)
9374 if Nkind
(List
) = N_Null
then
9377 -- Single global item declaration (only input items)
9379 elsif Nkind
(List
) in N_Expanded_Name | N_Identifier
then
9380 if Global_Mode
= Name_Input
then
9386 -- Simple global list (only input items) or moded global list
9389 elsif Nkind
(List
) = N_Aggregate
then
9390 if Present
(Expressions
(List
)) then
9391 if Global_Mode
= Name_Input
then
9392 return First
(Expressions
(List
));
9398 Assoc
:= First
(Component_Associations
(List
));
9399 while Present
(Assoc
) loop
9401 -- When we find the desired mode in an association, call
9402 -- recursively First_From_Global_List as if the mode was
9403 -- Name_Input, in order to reuse the existing machinery
9404 -- for the other cases.
9406 if Chars
(First
(Choices
(Assoc
))) = Global_Mode
then
9407 return First_From_Global_List
(Expression
(Assoc
));
9416 -- To accommodate partial decoration of disabled SPARK features,
9417 -- this routine may be called with illegal input. If this is the
9418 -- case, do not raise Program_Error.
9423 end First_From_Global_List
;
9427 Global
: Node_Id
:= Empty
;
9428 Body_Id
: Entity_Id
;
9430 -- Start of processing for First_Global
9433 pragma Assert
(Global_Mode
in Name_In_Out
9438 -- Retrieve the suitable pragma Global or Refined_Global. In the second
9439 -- case, it can only be located on the body entity.
9442 if Is_Subprogram_Or_Generic_Subprogram
(Subp
) then
9443 Body_Id
:= Subprogram_Body_Entity
(Subp
);
9445 elsif Is_Entry
(Subp
) or else Is_Task_Type
(Subp
) then
9446 Body_Id
:= Corresponding_Body
(Parent
(Subp
));
9448 -- ??? It should be possible to retrieve the Refined_Global on the
9449 -- task body associated to the task object. This is not yet possible.
9451 elsif Is_Single_Task_Object
(Subp
) then
9458 if Present
(Body_Id
) then
9459 Global
:= Get_Pragma
(Body_Id
, Pragma_Refined_Global
);
9462 Global
:= Get_Pragma
(Subp
, Pragma_Global
);
9465 -- No corresponding global if pragma is not present
9470 -- Otherwise retrieve the corresponding list of items depending on the
9474 return First_From_Global_List
9475 (Expression
(Get_Argument
(Global
, Subp
)), Global_Mode
);
9483 function Fix_Msg
(Id
: Entity_Id
; Msg
: String) return String is
9484 Is_Task
: constant Boolean :=
9485 Ekind
(Id
) in E_Task_Body | E_Task_Type
9486 or else Is_Single_Task_Object
(Id
);
9487 Msg_Last
: constant Natural := Msg
'Last;
9488 Msg_Index
: Natural;
9489 Res
: String (Msg
'Range) := (others => ' ');
9490 Res_Index
: Natural;
9493 -- Copy all characters from the input message Msg to result Res with
9494 -- suitable replacements.
9496 Msg_Index
:= Msg
'First;
9497 Res_Index
:= Res
'First;
9498 while Msg_Index
<= Msg_Last
loop
9500 -- Replace "subprogram" with a different word
9502 if Msg_Index
<= Msg_Last
- 10
9503 and then Msg
(Msg_Index
.. Msg_Index
+ 9) = "subprogram"
9505 if Is_Entry
(Id
) then
9506 Res
(Res_Index
.. Res_Index
+ 4) := "entry";
9507 Res_Index
:= Res_Index
+ 5;
9510 Res
(Res_Index
.. Res_Index
+ 8) := "task type";
9511 Res_Index
:= Res_Index
+ 9;
9514 Res
(Res_Index
.. Res_Index
+ 9) := "subprogram";
9515 Res_Index
:= Res_Index
+ 10;
9518 Msg_Index
:= Msg_Index
+ 10;
9520 -- Replace "protected" with a different word
9522 elsif Msg_Index
<= Msg_Last
- 9
9523 and then Msg
(Msg_Index
.. Msg_Index
+ 8) = "protected"
9526 Res
(Res_Index
.. Res_Index
+ 3) := "task";
9527 Res_Index
:= Res_Index
+ 4;
9528 Msg_Index
:= Msg_Index
+ 9;
9530 -- Otherwise copy the character
9533 Res
(Res_Index
) := Msg
(Msg_Index
);
9534 Msg_Index
:= Msg_Index
+ 1;
9535 Res_Index
:= Res_Index
+ 1;
9539 return Res
(Res
'First .. Res_Index
- 1);
9542 -------------------------
9543 -- From_Nested_Package --
9544 -------------------------
9546 function From_Nested_Package
(T
: Entity_Id
) return Boolean is
9547 Pack
: constant Entity_Id
:= Scope
(T
);
9551 Ekind
(Pack
) = E_Package
9552 and then not Is_Frozen
(Pack
)
9553 and then not Scope_Within_Or_Same
(Current_Scope
, Pack
)
9554 and then In_Open_Scopes
(Scope
(Pack
));
9555 end From_Nested_Package
;
9557 -----------------------
9558 -- Gather_Components --
9559 -----------------------
9561 procedure Gather_Components
9563 Comp_List
: Node_Id
;
9564 Governed_By
: List_Id
;
9566 Report_Errors
: out Boolean;
9567 Allow_Compile_Time
: Boolean := False;
9568 Include_Interface_Tag
: Boolean := False)
9572 Discrete_Choice
: Node_Id
;
9573 Comp_Item
: Node_Id
;
9574 Discrim
: Entity_Id
;
9575 Discrim_Name
: Node_Id
;
9577 type Discriminant_Value_Status
is
9578 (Static_Expr
, Static_Subtype
, Bad
);
9579 subtype Good_Discrim_Value_Status
is Discriminant_Value_Status
9580 range Static_Expr
.. Static_Subtype
; -- range excludes Bad
9582 Discrim_Value
: Node_Id
;
9583 Discrim_Value_Subtype
: Node_Id
;
9584 Discrim_Value_Status
: Discriminant_Value_Status
:= Bad
;
9586 function OK_Scope_For_Discrim_Value_Error_Messages
return Boolean is
9587 (Scope
(Original_Record_Component
9588 (Entity
(First
(Choices
(Assoc
))))) = Typ
);
9589 -- Used to avoid generating error messages having a source position
9590 -- which refers to somewhere (e.g., a discriminant value in a derived
9591 -- tagged type declaration) unrelated to the offending construct. This
9592 -- is required for correctness - clients of Gather_Components such as
9593 -- Sem_Ch3.Create_Constrained_Components depend on this function
9594 -- returning True while processing semantically correct examples;
9595 -- generating an error message in this case would be wrong.
9598 Report_Errors
:= False;
9600 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
9604 Comp_Item
:= First
(Component_Items
(Comp_List
));
9605 while Present
(Comp_Item
) loop
9607 -- Skip the tag of a tagged record, as well as all items that are not
9608 -- user components (anonymous types, rep clauses, Parent field,
9609 -- controller field).
9611 if Nkind
(Comp_Item
) = N_Component_Declaration
then
9613 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
9615 if not (Is_Tag
(Comp
)
9617 (Include_Interface_Tag
9618 and then Etype
(Comp
) = RTE
(RE_Interface_Tag
)))
9619 and then Chars
(Comp
) /= Name_uParent
9621 Append_Elmt
(Comp
, Into
);
9629 if No
(Variant_Part
(Comp_List
)) then
9632 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
9633 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
9636 -- Look for the discriminant that governs this variant part.
9637 -- The discriminant *must* be in the Governed_By List
9639 Assoc
:= First
(Governed_By
);
9640 Find_Constraint
: loop
9641 Discrim
:= First
(Choices
(Assoc
));
9642 pragma Assert
(No
(Next
(Discrim
)));
9644 exit Find_Constraint
when
9645 Chars
(Discrim_Name
) = Chars
(Discrim
)
9647 (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
9648 and then Chars
(Corresponding_Discriminant
9649 (Entity
(Discrim
))) = Chars
(Discrim_Name
))
9651 Chars
(Original_Record_Component
(Entity
(Discrim
))) =
9652 Chars
(Discrim_Name
);
9654 if No
(Next
(Assoc
)) then
9655 if not Is_Constrained
(Typ
) and then Is_Derived_Type
(Typ
) then
9657 -- If the type is a tagged type with inherited discriminants,
9658 -- use the stored constraint on the parent in order to find
9659 -- the values of discriminants that are otherwise hidden by an
9660 -- explicit constraint. Renamed discriminants are handled in
9663 -- If several parent discriminants are renamed by a single
9664 -- discriminant of the derived type, the call to obtain the
9665 -- Corresponding_Discriminant field only retrieves the last
9666 -- of them. We recover the constraint on the others from the
9667 -- Stored_Constraint as well.
9669 -- An inherited discriminant may have been constrained in a
9670 -- later ancestor (not the immediate parent) so we must examine
9671 -- the stored constraint of all of them to locate the inherited
9677 T
: Entity_Id
:= Typ
;
9680 while Is_Derived_Type
(T
) loop
9681 if Present
(Stored_Constraint
(T
)) then
9682 D
:= First_Discriminant
(Etype
(T
));
9683 C
:= First_Elmt
(Stored_Constraint
(T
));
9684 while Present
(D
) and then Present
(C
) loop
9685 if Chars
(Discrim_Name
) = Chars
(D
) then
9686 if Is_Entity_Name
(Node
(C
))
9687 and then Entity
(Node
(C
)) = Entity
(Discrim
)
9689 -- D is renamed by Discrim, whose value is
9696 Make_Component_Association
(Sloc
(Typ
),
9698 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
9699 Duplicate_Subexpr_No_Checks
(Node
(C
)));
9702 exit Find_Constraint
;
9705 Next_Discriminant
(D
);
9710 -- Discriminant may be inherited from ancestor
9722 ("missing value for discriminant&",
9723 First
(Governed_By
), Discrim_Name
);
9725 Report_Errors
:= True;
9728 end loop Find_Constraint
;
9730 Discrim_Value
:= Expression
(Assoc
);
9732 if Is_OK_Static_Expression
(Discrim_Value
)
9733 or else (Allow_Compile_Time
9734 and then Compile_Time_Known_Value
(Discrim_Value
))
9736 Discrim_Value_Status
:= Static_Expr
;
9738 if Ada_Version
>= Ada_2022
then
9739 if Is_Rewrite_Substitution
(Discrim_Value
)
9740 and then Nkind
(Discrim_Value
) = N_Type_Conversion
9741 and then Etype
(Original_Node
(Discrim_Value
))
9742 = Etype
(Expression
(Discrim_Value
))
9744 Discrim_Value_Subtype
:= Etype
(Original_Node
(Discrim_Value
));
9745 -- An unhelpful (for this code) type conversion may be
9746 -- introduced in some cases; deal with it.
9748 Discrim_Value_Subtype
:= Etype
(Discrim_Value
);
9751 if Is_OK_Static_Subtype
(Discrim_Value_Subtype
) and then
9752 not Is_Null_Range
(Type_Low_Bound
(Discrim_Value_Subtype
),
9753 Type_High_Bound
(Discrim_Value_Subtype
))
9755 -- Is_Null_Range test doesn't account for predicates, as in
9756 -- subtype Null_By_Predicate is Natural
9757 -- with Static_Predicate => Null_By_Predicate < 0;
9758 -- so test for that null case separately.
9760 if not Has_Static_Predicate
(Discrim_Value_Subtype
)
9761 or else Present
(First
(Static_Discrete_Predicate
9762 (Discrim_Value_Subtype
)))
9764 Discrim_Value_Status
:= Static_Subtype
;
9769 if Discrim_Value_Status
= Bad
then
9771 -- If the variant part is governed by a discriminant of the type
9772 -- this is an error. If the variant part and the discriminant are
9773 -- inherited from an ancestor this is legal (AI05-220) unless the
9774 -- components are being gathered for an aggregate, in which case
9775 -- the caller must check Report_Errors.
9777 -- In Ada 2022 the above rules are relaxed. A nonstatic governing
9778 -- discriminant is OK as long as it has a static subtype and
9779 -- every value of that subtype (and there must be at least one)
9780 -- selects the same variant.
9782 if OK_Scope_For_Discrim_Value_Error_Messages
then
9783 if Ada_Version
>= Ada_2022
then
9785 ("value for discriminant & must be static or " &
9786 "discriminant's nominal subtype must be static " &
9788 Discrim_Value
, Discrim
);
9791 ("value for discriminant & must be static!",
9792 Discrim_Value
, Discrim
);
9794 Why_Not_Static
(Discrim_Value
);
9797 Report_Errors
:= True;
9802 Search_For_Discriminant_Value
: declare
9808 UI_Discrim_Value
: Uint
;
9811 case Good_Discrim_Value_Status
'(Discrim_Value_Status) is
9813 UI_Discrim_Value := Expr_Value (Discrim_Value);
9814 when Static_Subtype =>
9815 -- Arbitrarily pick one value of the subtype and look
9816 -- for the variant associated with that value; we will
9817 -- check later that the same variant is associated with
9818 -- all of the other values of the subtype.
9819 if Has_Static_Predicate (Discrim_Value_Subtype) then
9821 Range_Or_Expr : constant Node_Id :=
9822 First (Static_Discrete_Predicate
9823 (Discrim_Value_Subtype));
9825 if Nkind (Range_Or_Expr) = N_Range then
9827 Expr_Value (Low_Bound (Range_Or_Expr));
9829 UI_Discrim_Value := Expr_Value (Range_Or_Expr);
9834 := Expr_Value (Type_Low_Bound (Discrim_Value_Subtype));
9838 Find_Discrete_Value : while Present (Variant) loop
9840 -- If a choice is a subtype with a static predicate, it must
9841 -- be rewritten as an explicit list of non-predicated choices.
9843 Expand_Static_Predicates_In_Choices (Variant);
9845 Discrete_Choice := First (Discrete_Choices (Variant));
9846 while Present (Discrete_Choice) loop
9847 exit Find_Discrete_Value when
9848 Nkind (Discrete_Choice) = N_Others_Choice;
9850 Get_Index_Bounds (Discrete_Choice, Low, High);
9852 UI_Low := Expr_Value (Low);
9853 UI_High := Expr_Value (High);
9855 exit Find_Discrete_Value when
9856 UI_Low <= UI_Discrim_Value
9858 UI_High >= UI_Discrim_Value;
9860 Next (Discrete_Choice);
9863 Next_Non_Pragma (Variant);
9864 end loop Find_Discrete_Value;
9865 end Search_For_Discriminant_Value;
9867 -- The case statement must include a variant that corresponds to the
9868 -- value of the discriminant, unless the discriminant type has a
9869 -- static predicate. In that case the absence of an others_choice that
9870 -- would cover this value becomes a run-time error (3.8.1 (21.1/2)).
9873 and then not Has_Static_Predicate (Etype (Discrim_Name))
9876 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9877 Report_Errors := True;
9881 -- If we have found the corresponding choice, recursively add its
9882 -- components to the Into list. The nested components are part of
9883 -- the same record type.
9885 if Present (Variant) then
9886 if Discrim_Value_Status = Static_Subtype then
9888 Discrim_Value_Subtype_Intervals
9889 : constant Interval_Lists.Discrete_Interval_List
9890 := Interval_Lists.Type_Intervals (Discrim_Value_Subtype);
9893 : constant Interval_Lists.Discrete_Interval_List
9894 := Interval_Lists.Choice_List_Intervals
9895 (Discrete_Choices => Discrete_Choices (Variant));
9897 if not Interval_Lists.Is_Subset
9898 (Subset => Discrim_Value_Subtype_Intervals,
9899 Of_Set => Variant_Intervals)
9901 if OK_Scope_For_Discrim_Value_Error_Messages then
9903 ("no single variant is associated with all values of " &
9904 "the subtype of discriminant value &",
9905 Discrim_Value, Discrim);
9907 Report_Errors := True;
9914 (Typ, Component_List (Variant), Governed_By, Into,
9915 Report_Errors, Allow_Compile_Time);
9917 end Gather_Components;
9919 ------------------------
9920 -- Get_Actual_Subtype --
9921 ------------------------
9923 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9924 Typ : constant Entity_Id := Etype (N);
9925 Utyp : Entity_Id := Underlying_Type (Typ);
9934 -- If what we have is an identifier that references a subprogram
9935 -- formal, or a variable or constant object, then we get the actual
9936 -- subtype from the referenced entity if one has been built.
9938 if Nkind (N) in N_Identifier | N_Expanded_Name
9940 (Is_Formal (Entity (N))
9941 or else Ekind (Entity (N)) = E_Constant
9942 or else Ekind (Entity (N)) = E_Variable)
9943 and then Present (Actual_Subtype (Entity (N)))
9945 return Actual_Subtype (Entity (N));
9947 -- Similarly, if we have an explicit dereference, then we get the
9948 -- actual subtype from the node itself if one has been built.
9950 elsif Nkind (N) = N_Explicit_Dereference
9951 and then Present (Actual_Designated_Subtype (N))
9953 return Actual_Designated_Subtype (N);
9955 -- Actual subtype of unchecked union is always itself. We never need
9956 -- the "real" actual subtype. If we did, we couldn't get it anyway
9957 -- because the discriminant is not available. The restrictions on
9958 -- Unchecked_Union are designed to make sure that this is OK.
9960 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9963 -- Here for the unconstrained case, we must find actual subtype
9964 -- No actual subtype is available, so we must build it on the fly.
9966 -- Checking the type, not the underlying type, for constrainedness
9967 -- seems to be necessary. Maybe all the tests should be on the type???
9969 elsif not Is_Constrained (Typ)
9970 and then (Is_Array_Type (Utyp)
9971 or else (Is_Record_Type (Utyp)
9972 and then Has_Discriminants (Utyp)))
9973 and then not Has_Unknown_Discriminants (Utyp)
9974 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9976 -- Nothing to do if in spec expression (why not???)
9978 if In_Spec_Expression then
9981 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9983 -- If the type has no discriminants, there is no subtype to
9984 -- build, even if the underlying type is discriminated.
9988 -- Else build the actual subtype
9991 Decl := Build_Actual_Subtype (Typ, N);
9993 -- The call may yield a declaration, or just return the entity
9999 Atyp := Defining_Identifier (Decl);
10001 -- If Build_Actual_Subtype generated a new declaration then use it
10003 if Atyp /= Typ then
10005 -- The actual subtype is an Itype, so analyze the declaration,
10006 -- but do not attach it to the tree, to get the type defined.
10008 Set_Parent (Decl, N);
10009 Set_Is_Itype (Atyp);
10010 Analyze (Decl, Suppress => All_Checks);
10011 Set_Associated_Node_For_Itype (Atyp, N);
10012 if Expander_Active then
10013 Set_Has_Delayed_Freeze (Atyp, False);
10015 -- We need to freeze the actual subtype immediately. This is
10016 -- needed because otherwise this Itype will not get frozen
10017 -- at all; it is always safe to freeze on creation because
10018 -- any associated types must be frozen at this point.
10020 -- On the other hand, if we are performing preanalysis on
10021 -- a conjured-up copy of a name (see calls to
10022 -- Preanalyze_Range in sem_ch5.adb) then we don't want
10023 -- to freeze Atyp, now or ever. In this case, the tree
10024 -- we eventually pass to the back end should contain no
10025 -- references to Atyp (and a freeze node would contain
10026 -- such a reference). That's why Expander_Active is tested.
10028 Freeze_Itype (Atyp, N);
10032 -- Otherwise we did not build a declaration, so return original
10039 -- For all remaining cases, the actual subtype is the same as
10040 -- the nominal type.
10045 end Get_Actual_Subtype;
10047 -------------------------------------
10048 -- Get_Actual_Subtype_If_Available --
10049 -------------------------------------
10051 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
10053 -- If what we have is an identifier that references a subprogram
10054 -- formal, or a variable or constant object, then we get the actual
10055 -- subtype from the referenced entity if one has been built.
10057 if Nkind (N) in N_Identifier | N_Expanded_Name
10059 (Is_Formal (Entity (N))
10060 or else Ekind (Entity (N)) = E_Constant
10061 or else Ekind (Entity (N)) = E_Variable)
10062 and then Present (Actual_Subtype (Entity (N)))
10064 return Actual_Subtype (Entity (N));
10066 -- Similarly, if we have an explicit dereference, then we get the
10067 -- actual subtype from the node itself if one has been built.
10069 elsif Nkind (N) = N_Explicit_Dereference
10070 and then Present (Actual_Designated_Subtype (N))
10072 return Actual_Designated_Subtype (N);
10074 -- Otherwise the Etype of N is returned unchanged
10079 end Get_Actual_Subtype_If_Available;
10081 ------------------------
10082 -- Get_Body_From_Stub --
10083 ------------------------
10085 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
10087 return Proper_Body (Unit (Library_Unit (N)));
10088 end Get_Body_From_Stub;
10090 ---------------------
10091 -- Get_Cursor_Type --
10092 ---------------------
10094 function Get_Cursor_Type
10096 Typ : Entity_Id) return Entity_Id
10100 First_Op : Entity_Id;
10101 Cursor : Entity_Id;
10104 -- If error already detected, return
10106 if Error_Posted (Aspect) then
10110 -- The cursor type for an Iterable aspect is the return type of a
10111 -- non-overloaded First primitive operation. Locate association for
10114 Assoc := First (Component_Associations (Expression (Aspect)));
10115 First_Op := Any_Id;
10116 while Present (Assoc) loop
10117 if Chars (First (Choices (Assoc))) = Name_First then
10118 First_Op := Expression (Assoc);
10125 if First_Op = Any_Id then
10126 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
10129 elsif not Analyzed (First_Op) then
10130 Analyze (First_Op);
10133 Cursor := Any_Type;
10135 -- Locate function with desired name and profile in scope of type
10136 -- In the rare case where the type is an integer type, a base type
10137 -- is created for it, check that the base type of the first formal
10138 -- of First matches the base type of the domain.
10140 Func := First_Entity (Scope (Typ));
10141 while Present (Func) loop
10142 if Chars (Func) = Chars (First_Op)
10143 and then Ekind (Func) = E_Function
10144 and then Present (First_Formal (Func))
10145 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
10146 and then No (Next_Formal (First_Formal (Func)))
10148 if Cursor /= Any_Type then
10150 ("operation First for iterable type must be unique", Aspect);
10153 Cursor := Etype (Func);
10157 Next_Entity (Func);
10160 -- If not found, no way to resolve remaining primitives
10162 if Cursor = Any_Type then
10164 ("primitive operation for Iterable type must appear in the same "
10165 & "list of declarations as the type", Aspect);
10169 end Get_Cursor_Type;
10171 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
10173 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
10174 end Get_Cursor_Type;
10176 -------------------------------
10177 -- Get_Default_External_Name --
10178 -------------------------------
10180 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
10182 Get_Decoded_Name_String (Chars (E));
10184 if Opt.External_Name_Imp_Casing = Uppercase then
10185 Set_Casing (All_Upper_Case);
10187 Set_Casing (All_Lower_Case);
10191 Make_String_Literal (Sloc (E),
10192 Strval => String_From_Name_Buffer);
10193 end Get_Default_External_Name;
10195 --------------------------
10196 -- Get_Enclosing_Object --
10197 --------------------------
10199 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
10201 if Is_Entity_Name (N) then
10205 when N_Indexed_Component
10206 | N_Selected_Component
10209 -- If not generating code, a dereference may be left implicit.
10210 -- In thoses cases, return Empty.
10212 if Is_Access_Type (Etype (Prefix (N))) then
10215 return Get_Enclosing_Object (Prefix (N));
10218 when N_Type_Conversion =>
10219 return Get_Enclosing_Object (Expression (N));
10225 end Get_Enclosing_Object;
10227 -------------------------------
10228 -- Get_Enclosing_Deep_Object --
10229 -------------------------------
10231 function Get_Enclosing_Deep_Object (N : Node_Id) return Entity_Id is
10233 if Is_Entity_Name (N) then
10237 when N_Explicit_Dereference
10238 | N_Indexed_Component
10239 | N_Selected_Component
10242 return Get_Enclosing_Deep_Object (Prefix (N));
10244 when N_Type_Conversion =>
10245 return Get_Enclosing_Deep_Object (Expression (N));
10251 end Get_Enclosing_Deep_Object;
10253 ---------------------------
10254 -- Get_Enum_Lit_From_Pos --
10255 ---------------------------
10257 function Get_Enum_Lit_From_Pos
10260 Loc : Source_Ptr) return Node_Id
10262 Btyp : Entity_Id := Base_Type (T);
10267 -- In the case where the literal is of type Character, Wide_Character
10268 -- or Wide_Wide_Character or of a type derived from them, there needs
10269 -- to be some special handling since there is no explicit chain of
10270 -- literals to search. Instead, an N_Character_Literal node is created
10271 -- with the appropriate Char_Code and Chars fields.
10273 if Is_Standard_Character_Type (T) then
10274 Set_Character_Literal_Name (UI_To_CC (Pos));
10277 Make_Character_Literal (Loc,
10278 Chars => Name_Find,
10279 Char_Literal_Value => Pos);
10281 -- For all other cases, we have a complete table of literals, and
10282 -- we simply iterate through the chain of literal until the one
10283 -- with the desired position value is found.
10286 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
10287 Btyp := Full_View (Btyp);
10290 Lit := First_Literal (Btyp);
10292 -- Position in the enumeration type starts at 0
10295 raise Constraint_Error;
10298 for J in 1 .. UI_To_Int (Pos) loop
10299 Next_Literal (Lit);
10301 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
10302 -- inside the loop to avoid calling Next_Literal on Empty.
10305 raise Constraint_Error;
10309 -- Create a new node from Lit, with source location provided by Loc
10310 -- if not equal to No_Location, or by copying the source location of
10315 if LLoc = No_Location then
10316 LLoc := Sloc (Lit);
10319 return New_Occurrence_Of (Lit, LLoc);
10321 end Get_Enum_Lit_From_Pos;
10323 ----------------------
10324 -- Get_Fullest_View --
10325 ----------------------
10327 function Get_Fullest_View
10329 Include_PAT : Boolean := True;
10330 Recurse : Boolean := True) return Entity_Id
10332 New_E : Entity_Id := Empty;
10335 -- Prevent cascaded errors
10341 -- Look at each kind of entity to see where we may need to go deeper.
10344 when Incomplete_Kind =>
10345 if From_Limited_With (E) then
10346 New_E := Non_Limited_View (E);
10347 elsif Present (Full_View (E)) then
10348 New_E := Full_View (E);
10349 elsif Ekind (E) = E_Incomplete_Subtype then
10350 New_E := Etype (E);
10353 when Private_Kind =>
10354 if Present (Underlying_Full_View (E)) then
10355 New_E := Underlying_Full_View (E);
10356 elsif Present (Full_View (E)) then
10357 New_E := Full_View (E);
10358 elsif Etype (E) /= E then
10359 New_E := Etype (E);
10363 if Include_PAT and then Present (Packed_Array_Impl_Type (E)) then
10364 New_E := Packed_Array_Impl_Type (E);
10367 when E_Record_Subtype =>
10368 if Present (Cloned_Subtype (E)) then
10369 New_E := Cloned_Subtype (E);
10372 when E_Class_Wide_Type =>
10373 New_E := Root_Type (E);
10375 when E_Class_Wide_Subtype =>
10376 if Present (Equivalent_Type (E)) then
10377 New_E := Equivalent_Type (E);
10378 elsif Present (Cloned_Subtype (E)) then
10379 New_E := Cloned_Subtype (E);
10382 when E_Protected_Subtype
10387 if Present (Corresponding_Record_Type (E)) then
10388 New_E := Corresponding_Record_Type (E);
10391 when E_Access_Protected_Subprogram_Type
10392 | E_Anonymous_Access_Protected_Subprogram_Type
10394 if Present (Equivalent_Type (E)) then
10395 New_E := Equivalent_Type (E);
10398 when E_Access_Subtype =>
10399 New_E := Base_Type (E);
10405 -- If we found a fuller view, either return it or recurse. Otherwise,
10406 -- return our input.
10408 return (if No (New_E) then E
10409 elsif Recurse then Get_Fullest_View (New_E, Include_PAT, Recurse)
10411 end Get_Fullest_View;
10413 ------------------------
10414 -- Get_Generic_Entity --
10415 ------------------------
10417 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
10418 Ent : constant Entity_Id := Entity (Name (N));
10420 if Present (Renamed_Entity (Ent)) then
10421 return Renamed_Entity (Ent);
10425 end Get_Generic_Entity;
10427 -------------------------------------
10428 -- Get_Incomplete_View_Of_Ancestor --
10429 -------------------------------------
10431 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
10432 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10433 Par_Scope : Entity_Id;
10434 Par_Type : Entity_Id;
10437 -- The incomplete view of an ancestor is only relevant for private
10438 -- derived types in child units.
10440 if not Is_Derived_Type (E)
10441 or else not Is_Child_Unit (Cur_Unit)
10446 Par_Scope := Scope (Cur_Unit);
10447 if No (Par_Scope) then
10451 Par_Type := Etype (Base_Type (E));
10453 -- Traverse list of ancestor types until we find one declared in
10454 -- a parent or grandparent unit (two levels seem sufficient).
10456 while Present (Par_Type) loop
10457 if Scope (Par_Type) = Par_Scope
10458 or else Scope (Par_Type) = Scope (Par_Scope)
10462 elsif not Is_Derived_Type (Par_Type) then
10466 Par_Type := Etype (Base_Type (Par_Type));
10470 -- If none found, there is no relevant ancestor type.
10474 end Get_Incomplete_View_Of_Ancestor;
10476 ----------------------
10477 -- Get_Index_Bounds --
10478 ----------------------
10480 procedure Get_Index_Bounds
10484 Use_Full_View : Boolean := False)
10486 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
10487 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
10488 -- Typ qualifies, the scalar range is obtained from the full view of the
10491 --------------------------
10492 -- Scalar_Range_Of_Type --
10493 --------------------------
10495 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
10496 T : Entity_Id := Typ;
10499 if Use_Full_View and then Present (Full_View (T)) then
10500 T := Full_View (T);
10503 return Scalar_Range (T);
10504 end Scalar_Range_Of_Type;
10508 Kind : constant Node_Kind := Nkind (N);
10511 -- Start of processing for Get_Index_Bounds
10514 if Kind = N_Range then
10515 L := Low_Bound (N);
10516 H := High_Bound (N);
10518 elsif Kind = N_Subtype_Indication then
10519 Rng := Range_Expression (Constraint (N));
10521 if Rng = Error then
10527 L := Low_Bound (Range_Expression (Constraint (N)));
10528 H := High_Bound (Range_Expression (Constraint (N)));
10531 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
10532 Rng := Scalar_Range_Of_Type (Entity (N));
10534 if Error_Posted (Rng) then
10538 elsif Nkind (Rng) = N_Subtype_Indication then
10539 Get_Index_Bounds (Rng, L, H);
10542 L := Low_Bound (Rng);
10543 H := High_Bound (Rng);
10547 -- N is an expression, indicating a range with one value
10552 end Get_Index_Bounds;
10554 function Get_Index_Bounds
10556 Use_Full_View : Boolean := False) return Range_Nodes is
10557 Result : Range_Nodes;
10559 Get_Index_Bounds (N, Result.First, Result.Last, Use_Full_View);
10561 end Get_Index_Bounds;
10563 function Get_Index_Bounds
10565 Use_Full_View : Boolean := False) return Range_Values is
10566 Nodes : constant Range_Nodes := Get_Index_Bounds (N, Use_Full_View);
10568 return (Expr_Value (Nodes.First), Expr_Value (Nodes.Last));
10569 end Get_Index_Bounds;
10571 -----------------------------
10572 -- Get_Interfacing_Aspects --
10573 -----------------------------
10575 procedure Get_Interfacing_Aspects
10576 (Iface_Asp : Node_Id;
10577 Conv_Asp : out Node_Id;
10578 EN_Asp : out Node_Id;
10579 Expo_Asp : out Node_Id;
10580 Imp_Asp : out Node_Id;
10581 LN_Asp : out Node_Id;
10582 Do_Checks : Boolean := False)
10584 procedure Save_Or_Duplication_Error
10586 To : in out Node_Id);
10587 -- Save the value of aspect Asp in node To. If To already has a value,
10588 -- then this is considered a duplicate use of aspect. Emit an error if
10589 -- flag Do_Checks is set.
10591 -------------------------------
10592 -- Save_Or_Duplication_Error --
10593 -------------------------------
10595 procedure Save_Or_Duplication_Error
10597 To : in out Node_Id)
10600 -- Detect an extra aspect and issue an error
10602 if Present (To) then
10604 Error_Msg_Name_1 := Chars (Identifier (Asp));
10605 Error_Msg_Sloc := Sloc (To);
10606 Error_Msg_N ("aspect % previously given #", Asp);
10609 -- Otherwise capture the aspect
10614 end Save_Or_Duplication_Error;
10619 Asp_Id : Aspect_Id;
10621 -- The following variables capture each individual aspect
10623 Conv : Node_Id := Empty;
10624 EN : Node_Id := Empty;
10625 Expo : Node_Id := Empty;
10626 Imp : Node_Id := Empty;
10627 LN : Node_Id := Empty;
10629 -- Start of processing for Get_Interfacing_Aspects
10632 -- The input interfacing aspect should reside in an aspect specification
10635 pragma Assert (Is_List_Member (Iface_Asp));
10637 -- Examine the aspect specifications of the related entity. Find and
10638 -- capture all interfacing aspects. Detect duplicates and emit errors
10641 Asp := First (List_Containing (Iface_Asp));
10642 while Present (Asp) loop
10643 Asp_Id := Get_Aspect_Id (Asp);
10645 if Asp_Id = Aspect_Convention then
10646 Save_Or_Duplication_Error (Asp, Conv);
10648 elsif Asp_Id = Aspect_External_Name then
10649 Save_Or_Duplication_Error (Asp, EN);
10651 elsif Asp_Id = Aspect_Export then
10652 Save_Or_Duplication_Error (Asp, Expo);
10654 elsif Asp_Id = Aspect_Import then
10655 Save_Or_Duplication_Error (Asp, Imp);
10657 elsif Asp_Id = Aspect_Link_Name then
10658 Save_Or_Duplication_Error (Asp, LN);
10669 end Get_Interfacing_Aspects;
10671 ---------------------------------
10672 -- Get_Iterable_Type_Primitive --
10673 ---------------------------------
10675 function Get_Iterable_Type_Primitive
10677 Nam : Name_Id) return Entity_Id
10682 Nam in Name_Element
10689 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
10697 Assoc := First (Component_Associations (Funcs));
10698 while Present (Assoc) loop
10699 if Chars (First (Choices (Assoc))) = Nam then
10700 return Entity (Expression (Assoc));
10708 end Get_Iterable_Type_Primitive;
10710 ---------------------------
10711 -- Get_Library_Unit_Name --
10712 ---------------------------
10714 function Get_Library_Unit_Name (Decl_Node : Node_Id) return String_Id is
10715 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
10716 Buf : Bounded_String;
10718 Get_Unit_Name_String (Buf, Unit_Name_Id);
10720 -- Remove the last seven characters (" (spec)" or " (body)")
10722 Buf.Length := Buf.Length - 7;
10723 pragma Assert (Buf.Chars (Buf.Length + 1) = ' ');
10725 return String_From_Name_Buffer (Buf);
10726 end Get_Library_Unit_Name;
10728 --------------------------
10729 -- Get_Max_Queue_Length --
10730 --------------------------
10732 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
10733 pragma Assert (Is_Entry (Id));
10734 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
10738 -- A value of 0 or -1 represents no maximum specified, and entries and
10739 -- entry families with no Max_Queue_Length aspect or pragma default to
10747 (Expression (First (Pragma_Argument_Associations (Prag))));
10749 -- Since -1 and 0 are equivalent, return 0 for instances of -1 for
10757 end Get_Max_Queue_Length;
10759 ------------------------
10760 -- Get_Name_Entity_Id --
10761 ------------------------
10763 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
10765 return Entity_Id (Get_Name_Table_Int (Id));
10766 end Get_Name_Entity_Id;
10768 ------------------------------
10769 -- Get_Name_From_CTC_Pragma --
10770 ------------------------------
10772 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
10773 Arg : constant Node_Id :=
10774 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
10776 return Strval (Expr_Value_S (Arg));
10777 end Get_Name_From_CTC_Pragma;
10779 -----------------------
10780 -- Get_Parent_Entity --
10781 -----------------------
10783 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
10785 if Nkind (Unit) = N_Package_Body
10786 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
10788 return Defining_Entity
10789 (Specification (Instance_Spec (Original_Node (Unit))));
10790 elsif Nkind (Unit) = N_Package_Instantiation then
10791 return Defining_Entity (Specification (Instance_Spec (Unit)));
10793 return Defining_Entity (Unit);
10795 end Get_Parent_Entity;
10797 -------------------
10798 -- Get_Pragma_Id --
10799 -------------------
10801 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
10803 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
10806 ------------------------
10807 -- Get_Qualified_Name --
10808 ------------------------
10810 function Get_Qualified_Name
10812 Suffix : Entity_Id := Empty) return Name_Id
10814 Suffix_Nam : Name_Id := No_Name;
10817 if Present (Suffix) then
10818 Suffix_Nam := Chars (Suffix);
10821 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
10822 end Get_Qualified_Name;
10824 function Get_Qualified_Name
10826 Suffix : Name_Id := No_Name;
10827 Scop : Entity_Id := Current_Scope) return Name_Id
10829 procedure Add_Scope (S : Entity_Id);
10830 -- Add the fully qualified form of scope S to the name buffer. The
10838 procedure Add_Scope (S : Entity_Id) is
10843 elsif S = Standard_Standard then
10847 Add_Scope (Scope (S));
10848 Get_Name_String_And_Append (Chars (S));
10849 Add_Str_To_Name_Buffer ("__");
10853 -- Start of processing for Get_Qualified_Name
10859 -- Append the base name after all scopes have been chained
10861 Get_Name_String_And_Append (Nam);
10863 -- Append the suffix (if present)
10865 if Suffix /= No_Name then
10866 Add_Str_To_Name_Buffer ("__");
10867 Get_Name_String_And_Append (Suffix);
10871 end Get_Qualified_Name;
10873 -----------------------
10874 -- Get_Reason_String --
10875 -----------------------
10877 procedure Get_Reason_String (N : Node_Id) is
10879 if Nkind (N) = N_String_Literal then
10880 Store_String_Chars (Strval (N));
10882 elsif Nkind (N) = N_Op_Concat then
10883 Get_Reason_String (Left_Opnd (N));
10884 Get_Reason_String (Right_Opnd (N));
10886 -- If not of required form, error
10890 ("Reason for pragma Warnings has wrong form", N);
10892 ("\must be string literal or concatenation of string literals", N);
10895 end Get_Reason_String;
10897 --------------------------------
10898 -- Get_Reference_Discriminant --
10899 --------------------------------
10901 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
10905 D := First_Discriminant (Typ);
10906 while Present (D) loop
10907 if Has_Implicit_Dereference (D) then
10910 Next_Discriminant (D);
10914 end Get_Reference_Discriminant;
10916 ---------------------------
10917 -- Get_Referenced_Object --
10918 ---------------------------
10920 function Get_Referenced_Object (N : Node_Id) return Node_Id is
10925 while Is_Entity_Name (R)
10926 and then Is_Object (Entity (R))
10927 and then Present (Renamed_Object (Entity (R)))
10929 R := Renamed_Object (Entity (R));
10933 end Get_Referenced_Object;
10935 ------------------------
10936 -- Get_Renamed_Entity --
10937 ------------------------
10939 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
10940 R : Entity_Id := E;
10942 while Present (Renamed_Entity (R)) loop
10943 R := Renamed_Entity (R);
10947 end Get_Renamed_Entity;
10949 -----------------------
10950 -- Get_Return_Object --
10951 -----------------------
10953 function Get_Return_Object (N : Node_Id) return Entity_Id is
10957 Decl := First (Return_Object_Declarations (N));
10958 while Present (Decl) loop
10959 exit when Nkind (Decl) = N_Object_Declaration
10960 and then Is_Return_Object (Defining_Identifier (Decl));
10964 pragma Assert (Present (Decl));
10965 return Defining_Identifier (Decl);
10966 end Get_Return_Object;
10968 ---------------------------
10969 -- Get_Subprogram_Entity --
10970 ---------------------------
10972 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
10974 Subp_Id : Entity_Id;
10977 if Nkind (Nod) = N_Accept_Statement then
10978 Subp := Entry_Direct_Name (Nod);
10980 elsif Nkind (Nod) = N_Slice then
10981 Subp := Prefix (Nod);
10984 Subp := Name (Nod);
10987 -- Strip the subprogram call
10990 if Nkind (Subp) in N_Explicit_Dereference
10991 | N_Indexed_Component
10992 | N_Selected_Component
10994 Subp := Prefix (Subp);
10996 elsif Nkind (Subp) in N_Type_Conversion
10997 | N_Unchecked_Type_Conversion
10999 Subp := Expression (Subp);
11006 -- Extract the entity of the subprogram call
11008 if Is_Entity_Name (Subp) then
11009 Subp_Id := Entity (Subp);
11011 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
11012 Subp_Id := Directly_Designated_Type (Subp_Id);
11015 if Is_Subprogram (Subp_Id) then
11021 -- The search did not find a construct that denotes a subprogram
11026 end Get_Subprogram_Entity;
11028 -----------------------------
11029 -- Get_Task_Body_Procedure --
11030 -----------------------------
11032 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
11034 -- Note: A task type may be the completion of a private type with
11035 -- discriminants. When performing elaboration checks on a task
11036 -- declaration, the current view of the type may be the private one,
11037 -- and the procedure that holds the body of the task is held in its
11038 -- underlying type.
11040 -- This is an odd function, why not have Task_Body_Procedure do
11041 -- the following digging???
11043 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
11044 end Get_Task_Body_Procedure;
11046 -------------------------------
11047 -- Get_User_Defined_Equality --
11048 -------------------------------
11050 function Get_User_Defined_Equality (E : Entity_Id) return Entity_Id is
11054 Prim := First_Elmt (Collect_Primitive_Operations (E));
11055 while Present (Prim) loop
11056 if Is_User_Defined_Equality (Node (Prim)) then
11057 return Node (Prim);
11064 end Get_User_Defined_Equality;
11070 procedure Get_Views
11072 Priv_Typ : out Entity_Id;
11073 Full_Typ : out Entity_Id;
11074 UFull_Typ : out Entity_Id;
11075 CRec_Typ : out Entity_Id)
11077 IP_View : Entity_Id;
11080 -- Assume that none of the views can be recovered
11084 UFull_Typ := Empty;
11087 -- The input type is the corresponding record type of a protected or a
11090 if Ekind (Typ) = E_Record_Type
11091 and then Is_Concurrent_Record_Type (Typ)
11094 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
11095 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
11097 -- Otherwise the input type denotes an arbitrary type
11100 IP_View := Incomplete_Or_Partial_View (Typ);
11102 -- The input type denotes the full view of a private type
11104 if Present (IP_View) then
11105 Priv_Typ := IP_View;
11108 -- The input type is a private type
11110 elsif Is_Private_Type (Typ) then
11112 Full_Typ := Full_View (Priv_Typ);
11114 -- Otherwise the input type does not have any views
11120 if Present (Full_Typ) and then Is_Private_Type (Full_Typ) then
11121 UFull_Typ := Underlying_Full_View (Full_Typ);
11123 if Present (UFull_Typ)
11124 and then Ekind (UFull_Typ) in E_Protected_Type | E_Task_Type
11126 CRec_Typ := Corresponding_Record_Type (UFull_Typ);
11130 if Present (Full_Typ)
11131 and then Ekind (Full_Typ) in E_Protected_Type | E_Task_Type
11133 CRec_Typ := Corresponding_Record_Type (Full_Typ);
11139 ------------------------------
11140 -- Has_Compatible_Alignment --
11141 ------------------------------
11143 function Has_Compatible_Alignment
11146 Layout_Done : Boolean) return Alignment_Result
11148 function Has_Compatible_Alignment_Internal
11151 Layout_Done : Boolean;
11152 Default : Alignment_Result) return Alignment_Result;
11153 -- This is the internal recursive function that actually does the work.
11154 -- There is one additional parameter, which says what the result should
11155 -- be if no alignment information is found, and there is no definite
11156 -- indication of compatible alignments. At the outer level, this is set
11157 -- to Unknown, but for internal recursive calls in the case where types
11158 -- are known to be correct, it is set to Known_Compatible.
11160 ---------------------------------------
11161 -- Has_Compatible_Alignment_Internal --
11162 ---------------------------------------
11164 function Has_Compatible_Alignment_Internal
11167 Layout_Done : Boolean;
11168 Default : Alignment_Result) return Alignment_Result
11170 Result : Alignment_Result := Known_Compatible;
11171 -- Holds the current status of the result. Note that once a value of
11172 -- Known_Incompatible is set, it is sticky and does not get changed
11173 -- to Unknown (the value in Result only gets worse as we go along,
11176 Offs : Uint := No_Uint;
11177 -- Set to a factor of the offset from the base object when Expr is a
11178 -- selected or indexed component, based on Component_Bit_Offset and
11179 -- Component_Size respectively. A negative value is used to represent
11180 -- a value that is not known at compile time.
11182 procedure Check_Prefix;
11183 -- Checks the prefix recursively in the case where the expression
11184 -- is an indexed or selected component.
11186 procedure Set_Result (R : Alignment_Result);
11187 -- If R represents a worse outcome (unknown instead of known
11188 -- compatible, or known incompatible), then set Result to R.
11194 procedure Check_Prefix is
11196 -- The subtlety here is that in doing a recursive call to check
11197 -- the prefix, we have to decide what to do in the case where we
11198 -- don't find any specific indication of an alignment problem.
11200 -- At the outer level, we normally set Unknown as the result in
11201 -- this case, since we can only set Known_Compatible if we really
11202 -- know that the alignment value is OK, but for the recursive
11203 -- call, in the case where the types match, and we have not
11204 -- specified a peculiar alignment for the object, we are only
11205 -- concerned about suspicious rep clauses, the default case does
11206 -- not affect us, since the compiler will, in the absence of such
11207 -- rep clauses, ensure that the alignment is correct.
11209 if Default = Known_Compatible
11211 (Etype (Obj) = Etype (Expr)
11212 and then (not Known_Alignment (Obj)
11214 Alignment (Obj) = Alignment (Etype (Obj))))
11217 (Has_Compatible_Alignment_Internal
11218 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
11220 -- In all other cases, we need a full check on the prefix
11224 (Has_Compatible_Alignment_Internal
11225 (Obj, Prefix (Expr), Layout_Done, Unknown));
11233 procedure Set_Result (R : Alignment_Result) is
11240 -- Start of processing for Has_Compatible_Alignment_Internal
11243 -- If Expr is a selected component, we must make sure there is no
11244 -- potentially troublesome component clause and that the record is
11245 -- not packed if the layout is not done.
11247 if Nkind (Expr) = N_Selected_Component then
11249 -- Packing generates unknown alignment if layout is not done
11251 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
11252 Set_Result (Unknown);
11255 -- Check prefix and component offset
11258 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
11260 -- If Expr is an indexed component, we must make sure there is no
11261 -- potentially troublesome Component_Size clause and that the array
11262 -- is not bit-packed if the layout is not done.
11264 elsif Nkind (Expr) = N_Indexed_Component then
11266 Typ : constant Entity_Id := Etype (Prefix (Expr));
11269 -- Packing generates unknown alignment if layout is not done
11271 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
11272 Set_Result (Unknown);
11275 -- Check prefix and component offset (or at least size)
11278 Offs := Indexed_Component_Bit_Offset (Expr);
11280 Offs := Component_Size (Typ);
11285 -- If we have a null offset, the result is entirely determined by
11286 -- the base object and has already been computed recursively.
11288 if Present (Offs) and then Offs = Uint_0 then
11291 -- Case where we know the alignment of the object
11293 elsif Known_Alignment (Obj) then
11295 ObjA : constant Uint := Alignment (Obj);
11296 ExpA : Uint := No_Uint;
11297 SizA : Uint := No_Uint;
11300 -- If alignment of Obj is 1, then we are always OK
11303 Set_Result (Known_Compatible);
11305 -- Alignment of Obj is greater than 1, so we need to check
11308 -- If we have an offset, see if it is compatible
11310 if Present (Offs) and then Offs > Uint_0 then
11311 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
11312 Set_Result (Known_Incompatible);
11315 -- See if Expr is an object with known alignment
11317 elsif Is_Entity_Name (Expr)
11318 and then Known_Alignment (Entity (Expr))
11321 ExpA := Alignment (Entity (Expr));
11323 -- Otherwise, we can use the alignment of the type of Expr
11324 -- given that we already checked for discombobulating rep
11325 -- clauses for the cases of indexed and selected components
11328 elsif Known_Alignment (Etype (Expr)) then
11329 ExpA := Alignment (Etype (Expr));
11331 -- Otherwise the alignment is unknown
11334 Set_Result (Default);
11337 -- If we got an alignment, see if it is acceptable
11339 if Present (ExpA) and then ExpA < ObjA then
11340 Set_Result (Known_Incompatible);
11343 -- If Expr is a component or an entire object with a known
11344 -- alignment, then we are fine. Otherwise, if its size is
11345 -- known, it must be big enough for the required alignment.
11347 if Present (Offs) then
11350 -- See if Expr is an object with known size
11352 elsif Is_Entity_Name (Expr)
11353 and then Known_Static_Esize (Entity (Expr))
11355 SizA := Esize (Entity (Expr));
11357 -- Otherwise, we check the object size of the Expr type
11359 elsif Known_Static_Esize (Etype (Expr)) then
11360 SizA := Esize (Etype (Expr));
11363 -- If we got a size, see if it is a multiple of the Obj
11364 -- alignment; if not, then the alignment cannot be
11365 -- acceptable, since the size is always a multiple of the
11368 if Present (SizA) then
11369 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
11370 Set_Result (Known_Incompatible);
11376 -- If we do not know required alignment, any non-zero offset is a
11377 -- potential problem (but certainly may be OK, so result is unknown).
11379 elsif Present (Offs) then
11380 Set_Result (Unknown);
11382 -- If we can't find the result by direct comparison of alignment
11383 -- values, then there is still one case that we can determine known
11384 -- result, and that is when we can determine that the types are the
11385 -- same, and no alignments are specified. Then we known that the
11386 -- alignments are compatible, even if we don't know the alignment
11387 -- value in the front end.
11389 elsif Etype (Obj) = Etype (Expr) then
11391 -- Types are the same, but we have to check for possible size
11392 -- and alignments on the Expr object that may make the alignment
11393 -- different, even though the types are the same.
11395 if Is_Entity_Name (Expr) then
11397 -- First check alignment of the Expr object. Any alignment less
11398 -- than Maximum_Alignment is worrisome since this is the case
11399 -- where we do not know the alignment of Obj.
11401 if Known_Alignment (Entity (Expr))
11402 and then Alignment (Entity (Expr)) < Ttypes.Maximum_Alignment
11404 Set_Result (Unknown);
11406 -- Now check size of Expr object. Any size that is not an even
11407 -- multiple of Maximum_Alignment is also worrisome since it
11408 -- may cause the alignment of the object to be less than the
11409 -- alignment of the type.
11411 elsif Known_Static_Esize (Entity (Expr))
11413 Esize (Entity (Expr)) mod
11414 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit)
11417 Set_Result (Unknown);
11419 -- Otherwise same type is decisive
11422 Set_Result (Known_Compatible);
11426 -- Another case to deal with is when there is an explicit size or
11427 -- alignment clause when the types are not the same. If so, then the
11428 -- result is Unknown. We don't need to do this test if the Default is
11429 -- Unknown, since that result will be set in any case.
11431 elsif Default /= Unknown
11432 and then (Has_Size_Clause (Etype (Expr))
11434 Has_Alignment_Clause (Etype (Expr)))
11436 Set_Result (Unknown);
11438 -- If no indication found, set default
11441 Set_Result (Default);
11444 -- Return worst result found
11447 end Has_Compatible_Alignment_Internal;
11449 -- Start of processing for Has_Compatible_Alignment
11452 -- If Obj has no specified alignment, then set alignment from the type
11453 -- alignment. Perhaps we should always do this, but for sure we should
11454 -- do it when there is an address clause since we can do more if the
11455 -- alignment is known.
11457 if not Known_Alignment (Obj) and then Known_Alignment (Etype (Obj)) then
11458 Set_Alignment (Obj, Alignment (Etype (Obj)));
11461 -- Now do the internal call that does all the work
11464 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
11465 end Has_Compatible_Alignment;
11467 ----------------------
11468 -- Has_Declarations --
11469 ----------------------
11471 function Has_Declarations (N : Node_Id) return Boolean is
11473 return Nkind (N) in N_Accept_Statement
11474 | N_Block_Statement
11475 | N_Compilation_Unit_Aux
11479 | N_Subprogram_Body
11481 | N_Package_Specification;
11482 end Has_Declarations;
11484 ---------------------------------
11485 -- Has_Defaulted_Discriminants --
11486 ---------------------------------
11488 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
11490 return Has_Discriminants (Typ)
11491 and then Present (Discriminant_Default_Value
11492 (First_Discriminant (Typ)));
11493 end Has_Defaulted_Discriminants;
11495 -------------------
11496 -- Has_Denormals --
11497 -------------------
11499 function Has_Denormals (E : Entity_Id) return Boolean is
11501 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
11504 -------------------------------------------
11505 -- Has_Discriminant_Dependent_Constraint --
11506 -------------------------------------------
11508 function Has_Discriminant_Dependent_Constraint
11509 (Comp : Entity_Id) return Boolean
11511 Comp_Decl : constant Node_Id := Parent (Comp);
11512 Subt_Indic : Node_Id;
11517 -- Discriminants can't depend on discriminants
11519 if Ekind (Comp) = E_Discriminant then
11523 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
11525 if Nkind (Subt_Indic) = N_Subtype_Indication then
11526 Constr := Constraint (Subt_Indic);
11528 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
11529 Assn := First (Constraints (Constr));
11530 while Present (Assn) loop
11531 case Nkind (Assn) is
11534 | N_Subtype_Indication
11536 if Depends_On_Discriminant (Assn) then
11540 when N_Discriminant_Association =>
11541 if Depends_On_Discriminant (Expression (Assn)) then
11556 end Has_Discriminant_Dependent_Constraint;
11558 --------------------------------------
11559 -- Has_Effectively_Volatile_Profile --
11560 --------------------------------------
11562 function Has_Effectively_Volatile_Profile
11563 (Subp_Id : Entity_Id) return Boolean
11565 Formal : Entity_Id;
11568 -- Inspect the formal parameters looking for an effectively volatile
11569 -- type for reading.
11571 Formal := First_Formal (Subp_Id);
11572 while Present (Formal) loop
11573 if Is_Effectively_Volatile_For_Reading (Etype (Formal)) then
11577 Next_Formal (Formal);
11580 -- Inspect the return type of functions
11582 if Ekind (Subp_Id) in E_Function | E_Generic_Function
11583 and then Is_Effectively_Volatile_For_Reading (Etype (Subp_Id))
11589 end Has_Effectively_Volatile_Profile;
11591 --------------------------
11592 -- Has_Enabled_Property --
11593 --------------------------
11595 function Has_Enabled_Property
11596 (Item_Id : Entity_Id;
11597 Property : Name_Id) return Boolean
11599 function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean;
11600 -- Determine whether a protected type or variable denoted by Item_Id
11601 -- has the property enabled.
11603 function State_Has_Enabled_Property return Boolean;
11604 -- Determine whether a state denoted by Item_Id has the property enabled
11606 function Type_Or_Variable_Has_Enabled_Property
11607 (Item_Id : Entity_Id) return Boolean;
11608 -- Determine whether type or variable denoted by Item_Id has the
11609 -- property enabled.
11611 -----------------------------------------------------
11612 -- Protected_Type_Or_Variable_Has_Enabled_Property --
11613 -----------------------------------------------------
11615 function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean
11618 -- Protected entities always have the properties Async_Readers and
11619 -- Async_Writers (SPARK RM 7.1.2(16)).
11621 if Property = Name_Async_Readers
11622 or else Property = Name_Async_Writers
11626 -- Protected objects that have Part_Of components also inherit their
11627 -- properties Effective_Reads and Effective_Writes
11628 -- (SPARK RM 7.1.2(16)).
11630 elsif Is_Single_Protected_Object (Item_Id) then
11632 Constit_Elmt : Elmt_Id;
11633 Constit_Id : Entity_Id;
11634 Constits : constant Elist_Id
11635 := Part_Of_Constituents (Item_Id);
11637 if Present (Constits) then
11638 Constit_Elmt := First_Elmt (Constits);
11639 while Present (Constit_Elmt) loop
11640 Constit_Id := Node (Constit_Elmt);
11642 if Has_Enabled_Property (Constit_Id, Property) then
11646 Next_Elmt (Constit_Elmt);
11653 end Protected_Type_Or_Variable_Has_Enabled_Property;
11655 --------------------------------
11656 -- State_Has_Enabled_Property --
11657 --------------------------------
11659 function State_Has_Enabled_Property return Boolean is
11660 Decl : constant Node_Id := Parent (Item_Id);
11662 procedure Find_Simple_Properties
11663 (Has_External : out Boolean;
11664 Has_Synchronous : out Boolean);
11665 -- Extract the simple properties associated with declaration Decl
11667 function Is_Enabled_External_Property return Boolean;
11668 -- Determine whether property Property appears within the external
11669 -- property list of declaration Decl, and return its status.
11671 ----------------------------
11672 -- Find_Simple_Properties --
11673 ----------------------------
11675 procedure Find_Simple_Properties
11676 (Has_External : out Boolean;
11677 Has_Synchronous : out Boolean)
11682 -- Assume that none of the properties are available
11684 Has_External := False;
11685 Has_Synchronous := False;
11687 Opt := First (Expressions (Decl));
11688 while Present (Opt) loop
11689 if Nkind (Opt) = N_Identifier then
11690 if Chars (Opt) = Name_External then
11691 Has_External := True;
11693 elsif Chars (Opt) = Name_Synchronous then
11694 Has_Synchronous := True;
11700 end Find_Simple_Properties;
11702 ----------------------------------
11703 -- Is_Enabled_External_Property --
11704 ----------------------------------
11706 function Is_Enabled_External_Property return Boolean is
11710 Prop_Nam : Node_Id;
11714 Opt := First (Component_Associations (Decl));
11715 while Present (Opt) loop
11716 Opt_Nam := First (Choices (Opt));
11718 if Nkind (Opt_Nam) = N_Identifier
11719 and then Chars (Opt_Nam) = Name_External
11721 Props := Expression (Opt);
11723 -- Multiple properties appear as an aggregate
11725 if Nkind (Props) = N_Aggregate then
11727 -- Simple property form
11729 Prop := First (Expressions (Props));
11730 while Present (Prop) loop
11731 if Chars (Prop) = Property then
11738 -- Property with expression form
11740 Prop := First (Component_Associations (Props));
11741 while Present (Prop) loop
11742 Prop_Nam := First (Choices (Prop));
11744 -- The property can be represented in two ways:
11745 -- others => <value>
11746 -- <property> => <value>
11748 if Nkind (Prop_Nam) = N_Others_Choice
11749 or else (Nkind (Prop_Nam) = N_Identifier
11750 and then Chars (Prop_Nam) = Property)
11752 return Is_True (Expr_Value (Expression (Prop)));
11761 return Chars (Props) = Property;
11769 end Is_Enabled_External_Property;
11773 Has_External : Boolean;
11774 Has_Synchronous : Boolean;
11776 -- Start of processing for State_Has_Enabled_Property
11779 -- The declaration of an external abstract state appears as an
11780 -- extension aggregate. If this is not the case, properties can
11783 if Nkind (Decl) /= N_Extension_Aggregate then
11787 Find_Simple_Properties (Has_External, Has_Synchronous);
11789 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
11791 if Has_External then
11794 -- Option External may enable or disable specific properties
11796 elsif Is_Enabled_External_Property then
11799 -- Simple option Synchronous
11801 -- enables disables
11802 -- Async_Readers Effective_Reads
11803 -- Async_Writers Effective_Writes
11805 -- Note that both forms of External have higher precedence than
11806 -- Synchronous (SPARK RM 7.1.4(9)).
11808 elsif Has_Synchronous then
11809 return Property in Name_Async_Readers | Name_Async_Writers;
11813 end State_Has_Enabled_Property;
11815 -------------------------------------------
11816 -- Type_Or_Variable_Has_Enabled_Property --
11817 -------------------------------------------
11819 function Type_Or_Variable_Has_Enabled_Property
11820 (Item_Id : Entity_Id) return Boolean
11822 AR : constant Node_Id :=
11823 Get_Pragma (Item_Id, Pragma_Async_Readers);
11824 AW : constant Node_Id :=
11825 Get_Pragma (Item_Id, Pragma_Async_Writers);
11826 ER : constant Node_Id :=
11827 Get_Pragma (Item_Id, Pragma_Effective_Reads);
11828 EW : constant Node_Id :=
11829 Get_Pragma (Item_Id, Pragma_Effective_Writes);
11831 Is_Derived_Type_With_Volatile_Parent_Type : constant Boolean :=
11832 Is_Derived_Type (Item_Id)
11833 and then Is_Effectively_Volatile (Etype (Base_Type (Item_Id)));
11836 -- A non-effectively volatile object can never possess external
11839 if not Is_Effectively_Volatile (Item_Id) then
11842 -- External properties related to variables come in two flavors -
11843 -- explicit and implicit. The explicit case is characterized by the
11844 -- presence of a property pragma with an optional Boolean flag. The
11845 -- property is enabled when the flag evaluates to True or the flag is
11846 -- missing altogether.
11848 elsif Property = Name_Async_Readers and then Present (AR) then
11849 return Is_Enabled_Pragma (AR);
11851 elsif Property = Name_Async_Writers and then Present (AW) then
11852 return Is_Enabled_Pragma (AW);
11854 elsif Property = Name_Effective_Reads and then Present (ER) then
11855 return Is_Enabled_Pragma (ER);
11857 elsif Property = Name_Effective_Writes and then Present (EW) then
11858 return Is_Enabled_Pragma (EW);
11860 -- If other properties are set explicitly, then this one is set
11861 -- implicitly to False, except in the case of a derived type
11862 -- whose parent type is volatile (in that case, we will inherit
11863 -- from the parent type, below).
11865 elsif (Present (AR)
11866 or else Present (AW)
11867 or else Present (ER)
11868 or else Present (EW))
11869 and then not Is_Derived_Type_With_Volatile_Parent_Type
11873 -- For a private type (including subtype of a private types), look at
11876 elsif Is_Private_Type (Item_Id) and then Present (Full_View (Item_Id))
11878 return Type_Or_Variable_Has_Enabled_Property (Full_View (Item_Id));
11880 -- For a derived type whose parent type is volatile, the
11881 -- property may be inherited (but ignore a non-volatile parent).
11883 elsif Is_Derived_Type_With_Volatile_Parent_Type then
11884 return Type_Or_Variable_Has_Enabled_Property
11885 (First_Subtype (Etype (Base_Type (Item_Id))));
11887 -- For a subtype, the property will be inherited from its base type.
11889 elsif Is_Type (Item_Id)
11890 and then not Is_Base_Type (Item_Id)
11892 return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id));
11894 -- If not specified explicitly for an object and its type
11895 -- is effectively volatile, then take result from the type.
11897 elsif Is_Object (Item_Id)
11898 and then Is_Effectively_Volatile (Etype (Item_Id))
11900 return Has_Enabled_Property (Etype (Item_Id), Property);
11902 -- The implicit case lacks all property pragmas
11904 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
11905 if Is_Protected_Type (Etype (Item_Id)) then
11906 return Protected_Type_Or_Variable_Has_Enabled_Property;
11914 end Type_Or_Variable_Has_Enabled_Property;
11916 -- Start of processing for Has_Enabled_Property
11919 -- Abstract states and variables have a flexible scheme of specifying
11920 -- external properties.
11922 if Ekind (Item_Id) = E_Abstract_State then
11923 return State_Has_Enabled_Property;
11925 elsif Ekind (Item_Id) in E_Variable | E_Constant then
11926 return Type_Or_Variable_Has_Enabled_Property (Item_Id);
11928 -- Other objects can only inherit properties through their type. We
11929 -- cannot call directly Type_Or_Variable_Has_Enabled_Property on
11930 -- these as they don't have contracts attached, which is expected by
11933 elsif Is_Object (Item_Id) then
11934 return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id));
11936 elsif Is_Type (Item_Id) then
11937 return Type_Or_Variable_Has_Enabled_Property
11938 (Item_Id => First_Subtype (Item_Id));
11940 -- Otherwise a property is enabled when the related item is effectively
11944 return Is_Effectively_Volatile (Item_Id);
11946 end Has_Enabled_Property;
11948 -------------------------------------
11949 -- Has_Full_Default_Initialization --
11950 -------------------------------------
11952 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
11956 -- A type subject to pragma Default_Initial_Condition may be fully
11957 -- default initialized depending on inheritance and the argument of
11958 -- the pragma. Since any type may act as the full view of a private
11959 -- type, this check must be performed prior to the specialized tests
11962 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
11966 -- A scalar type is fully default initialized if it is subject to aspect
11969 if Is_Scalar_Type (Typ) then
11970 return Has_Default_Aspect (Typ);
11972 -- An access type is fully default initialized by default
11974 elsif Is_Access_Type (Typ) then
11977 -- An array type is fully default initialized if its element type is
11978 -- scalar and the array type carries aspect Default_Component_Value or
11979 -- the element type is fully default initialized.
11981 elsif Is_Array_Type (Typ) then
11983 Has_Default_Aspect (Typ)
11984 or else Has_Full_Default_Initialization (Component_Type (Typ));
11986 -- A protected type, record type, or type extension is fully default
11987 -- initialized if all its components either carry an initialization
11988 -- expression or have a type that is fully default initialized. The
11989 -- parent type of a type extension must be fully default initialized.
11991 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
11993 -- Inspect all entities defined in the scope of the type, looking for
11994 -- uninitialized components.
11996 Comp := First_Component (Typ);
11997 while Present (Comp) loop
11998 if Comes_From_Source (Comp)
11999 and then No (Expression (Parent (Comp)))
12000 and then not Has_Full_Default_Initialization (Etype (Comp))
12005 Next_Component (Comp);
12008 -- Ensure that the parent type of a type extension is fully default
12011 if Etype (Typ) /= Typ
12012 and then not Has_Full_Default_Initialization (Etype (Typ))
12017 -- If we get here, then all components and parent portion are fully
12018 -- default initialized.
12022 -- A task type is fully default initialized by default
12024 elsif Is_Task_Type (Typ) then
12027 -- Otherwise the type is not fully default initialized
12032 end Has_Full_Default_Initialization;
12034 -----------------------------------------------
12035 -- Has_Fully_Default_Initializing_DIC_Pragma --
12036 -----------------------------------------------
12038 function Has_Fully_Default_Initializing_DIC_Pragma
12039 (Typ : Entity_Id) return Boolean
12045 -- A type that inherits pragma Default_Initial_Condition from a parent
12046 -- type is automatically fully default initialized.
12048 if Has_Inherited_DIC (Typ) then
12051 -- Otherwise the type is fully default initialized only when the pragma
12052 -- appears without an argument, or the argument is non-null.
12054 elsif Has_Own_DIC (Typ) then
12055 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
12056 pragma Assert (Present (Prag));
12057 Args := Pragma_Argument_Associations (Prag);
12059 -- The pragma appears without an argument in which case it defaults
12065 -- The pragma appears with a non-null expression
12067 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
12073 end Has_Fully_Default_Initializing_DIC_Pragma;
12075 ---------------------------------
12076 -- Has_Inferable_Discriminants --
12077 ---------------------------------
12079 function Has_Inferable_Discriminants (N : Node_Id) return Boolean is
12081 function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean;
12082 -- Determines whether the left-most prefix of a selected component is a
12083 -- formal parameter in a subprogram. Assumes N is a selected component.
12085 --------------------------------
12086 -- Prefix_Is_Formal_Parameter --
12087 --------------------------------
12089 function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean is
12090 Sel_Comp : Node_Id;
12093 -- Move to the left-most prefix by climbing up the tree
12096 while Present (Parent (Sel_Comp))
12097 and then Nkind (Parent (Sel_Comp)) = N_Selected_Component
12099 Sel_Comp := Parent (Sel_Comp);
12102 return Is_Formal (Entity (Prefix (Sel_Comp)));
12103 end Prefix_Is_Formal_Parameter;
12105 -- Start of processing for Has_Inferable_Discriminants
12108 -- For selected components, the subtype of the selector must be a
12109 -- constrained Unchecked_Union. If the component is subject to a
12110 -- per-object constraint, then the enclosing object must either be
12111 -- a regular discriminated type or must have inferable discriminants.
12113 if Nkind (N) = N_Selected_Component then
12114 -- The call to Has_Inferable_Discriminants will determine whether
12115 -- the selector has a constrained Unchecked_Union nominal type.
12117 if not Has_Inferable_Discriminants (Selector_Name (N)) then
12121 -- A small hack. If we have a per-object constrained selected
12122 -- component of a formal parameter, return True since we do not
12123 -- know the actual parameter association yet.
12125 return not Has_Per_Object_Constraint (Entity (Selector_Name (N)))
12126 or else not Is_Unchecked_Union (Etype (Prefix (N)))
12127 or else Has_Inferable_Discriminants (Prefix (N))
12128 or else Prefix_Is_Formal_Parameter (N);
12130 -- A qualified expression has inferable discriminants if its subtype
12131 -- mark is a constrained Unchecked_Union subtype.
12133 elsif Nkind (N) = N_Qualified_Expression then
12134 return Is_Unchecked_Union (Etype (Subtype_Mark (N)))
12135 and then Is_Constrained (Etype (Subtype_Mark (N)));
12137 -- For all other names, it is sufficient to have a constrained
12138 -- Unchecked_Union nominal subtype.
12141 return Is_Unchecked_Union (Etype (N))
12142 and then Is_Constrained (Etype (N));
12144 end Has_Inferable_Discriminants;
12146 --------------------
12147 -- Has_Infinities --
12148 --------------------
12150 function Has_Infinities (E : Entity_Id) return Boolean is
12153 Is_Floating_Point_Type (E)
12154 and then Nkind (Scalar_Range (E)) = N_Range
12155 and then Includes_Infinities (Scalar_Range (E));
12156 end Has_Infinities;
12158 --------------------
12159 -- Has_Interfaces --
12160 --------------------
12162 function Has_Interfaces
12164 Use_Full_View : Boolean := True) return Boolean
12166 Typ : Entity_Id := Base_Type (T);
12169 -- Handle concurrent types
12171 if Is_Concurrent_Type (Typ) then
12172 Typ := Corresponding_Record_Type (Typ);
12176 or else not Is_Record_Type (Typ)
12177 or else not Is_Tagged_Type (Typ)
12182 -- Handle private types
12184 if Use_Full_View and then Present (Full_View (Typ)) then
12185 Typ := Full_View (Typ);
12188 -- Handle concurrent record types
12190 if Is_Concurrent_Record_Type (Typ)
12191 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
12197 if Is_Interface (Typ)
12199 (Is_Record_Type (Typ)
12200 and then Present (Interfaces (Typ))
12201 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
12206 exit when Etype (Typ) = Typ
12208 -- Handle private types
12210 or else (Present (Full_View (Etype (Typ)))
12211 and then Full_View (Etype (Typ)) = Typ)
12213 -- Protect frontend against wrong sources with cyclic derivations
12215 or else Etype (Typ) = T;
12217 -- Climb to the ancestor type handling private types
12219 if Present (Full_View (Etype (Typ))) then
12220 Typ := Full_View (Etype (Typ));
12222 Typ := Etype (Typ);
12227 end Has_Interfaces;
12229 --------------------------
12230 -- Has_Max_Queue_Length --
12231 --------------------------
12233 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
12236 Ekind (Id) = E_Entry
12237 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
12238 end Has_Max_Queue_Length;
12240 ---------------------------------
12241 -- Has_No_Obvious_Side_Effects --
12242 ---------------------------------
12244 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
12246 -- For now handle literals, constants, and non-volatile variables and
12247 -- expressions combining these with operators or short circuit forms.
12249 if Nkind (N) in N_Numeric_Or_String_Literal then
12252 elsif Nkind (N) = N_Character_Literal then
12255 elsif Nkind (N) in N_Unary_Op then
12256 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
12258 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
12259 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
12261 Has_No_Obvious_Side_Effects (Right_Opnd (N));
12263 elsif Nkind (N) = N_Expression_With_Actions
12264 and then Is_Empty_List (Actions (N))
12266 return Has_No_Obvious_Side_Effects (Expression (N));
12268 elsif Nkind (N) in N_Has_Entity then
12269 return Present (Entity (N))
12271 Ekind (Entity (N)) in
12272 E_Variable | E_Constant | E_Enumeration_Literal |
12273 E_In_Parameter | E_Out_Parameter | E_In_Out_Parameter
12274 and then not Is_Volatile (Entity (N));
12279 end Has_No_Obvious_Side_Effects;
12281 -----------------------------
12282 -- Has_Non_Null_Refinement --
12283 -----------------------------
12285 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
12286 Constits : Elist_Id;
12289 pragma Assert (Ekind (Id) = E_Abstract_State);
12290 Constits := Refinement_Constituents (Id);
12292 -- For a refinement to be non-null, the first constituent must be
12293 -- anything other than null.
12297 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
12298 end Has_Non_Null_Refinement;
12300 -----------------------------
12301 -- Has_Non_Null_Statements --
12302 -----------------------------
12304 function Has_Non_Null_Statements (L : List_Id) return Boolean is
12310 while Present (Node) loop
12311 if Nkind (Node) not in N_Null_Statement | N_Call_Marker then
12319 end Has_Non_Null_Statements;
12321 ----------------------------------
12322 -- Is_Access_Subprogram_Wrapper --
12323 ----------------------------------
12325 function Is_Access_Subprogram_Wrapper (E : Entity_Id) return Boolean is
12326 Formal : constant Entity_Id := Last_Formal (E);
12328 return Present (Formal)
12329 and then Ekind (Etype (Formal)) in Access_Subprogram_Kind
12330 and then Access_Subprogram_Wrapper
12331 (Directly_Designated_Type (Etype (Formal))) = E;
12332 end Is_Access_Subprogram_Wrapper;
12334 ---------------------------
12335 -- Is_Explicitly_Aliased --
12336 ---------------------------
12338 function Is_Explicitly_Aliased (N : Node_Id) return Boolean is
12340 return Is_Formal (N)
12341 and then Present (Parent (N))
12342 and then Nkind (Parent (N)) = N_Parameter_Specification
12343 and then Aliased_Present (Parent (N));
12344 end Is_Explicitly_Aliased;
12346 ----------------------------
12347 -- Is_Container_Aggregate --
12348 ----------------------------
12350 function Is_Container_Aggregate (Exp : Node_Id) return Boolean is
12352 function Is_Record_Aggregate return Boolean is
12353 (Is_Parenthesis_Aggregate (Exp));
12354 -- Given an aggregate whose type is a record type with specified
12355 -- Aggregate aspect, we determine whether it is a record aggregate or
12356 -- a container aggregate by ckecking whether it uses parentheses () or
12357 -- square brackets []. If the code where the aggregate occurs can see
12358 -- only a partial view of the aggregate's type then the aggregate cannot
12359 -- be a record type and must then use []; an aggregate of a private type
12360 -- has to be a container aggregate and must then use [].
12363 return Nkind (Exp) = N_Aggregate
12364 and then Has_Aspect (Etype (Exp), Aspect_Aggregate)
12365 and then not Is_Record_Aggregate;
12366 end Is_Container_Aggregate;
12368 ---------------------------------
12369 -- Side_Effect_Free_Statements --
12370 ---------------------------------
12372 function Side_Effect_Free_Statements (L : List_Id) return Boolean is
12378 while Present (Node) loop
12379 case Nkind (Node) is
12380 when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error =>
12383 when N_Object_Declaration =>
12384 if Present (Expression (Node))
12385 and then not Side_Effect_Free (Expression (Node))
12398 end Side_Effect_Free_Statements;
12400 ---------------------------
12401 -- Side_Effect_Free_Loop --
12402 ---------------------------
12404 function Side_Effect_Free_Loop (N : Node_Id) return Boolean is
12410 -- If this is not a loop (e.g. because the loop has been rewritten),
12411 -- then return false.
12413 if Nkind (N) /= N_Loop_Statement then
12417 -- First check the statements
12419 if Side_Effect_Free_Statements (Statements (N)) then
12421 -- Then check the loop condition/indexes
12423 if Present (Iteration_Scheme (N)) then
12424 Scheme := Iteration_Scheme (N);
12426 if Present (Condition (Scheme))
12427 or else Present (Iterator_Specification (Scheme))
12430 elsif Present (Loop_Parameter_Specification (Scheme)) then
12431 Spec := Loop_Parameter_Specification (Scheme);
12432 Subt := Discrete_Subtype_Definition (Spec);
12434 if Present (Subt) then
12435 if Nkind (Subt) = N_Range then
12436 return Side_Effect_Free (Low_Bound (Subt))
12437 and then Side_Effect_Free (High_Bound (Subt));
12439 -- subtype indication
12449 end Side_Effect_Free_Loop;
12451 ----------------------------------
12452 -- Has_Non_Trivial_Precondition --
12453 ----------------------------------
12455 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
12456 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre,
12457 Class_Present => True);
12461 and then not Is_Entity_Name (Expression (Pre));
12462 end Has_Non_Trivial_Precondition;
12464 -------------------
12465 -- Has_Null_Body --
12466 -------------------
12468 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
12469 Body_Id : Entity_Id;
12476 Spec := Parent (Proc_Id);
12477 Decl := Parent (Spec);
12479 -- Retrieve the entity of the procedure body (e.g. invariant proc).
12481 if Nkind (Spec) = N_Procedure_Specification
12482 and then Nkind (Decl) = N_Subprogram_Declaration
12484 Body_Id := Corresponding_Body (Decl);
12486 -- The body acts as a spec
12489 Body_Id := Proc_Id;
12492 -- The body will be generated later
12494 if No (Body_Id) then
12498 Spec := Parent (Body_Id);
12499 Decl := Parent (Spec);
12502 (Nkind (Spec) = N_Procedure_Specification
12503 and then Nkind (Decl) = N_Subprogram_Body);
12505 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
12507 -- Look for a null statement followed by an optional return
12510 if Nkind (Stmt1) = N_Null_Statement then
12511 Stmt2 := Next (Stmt1);
12513 if Present (Stmt2) then
12514 return Nkind (Stmt2) = N_Simple_Return_Statement;
12523 ------------------------
12524 -- Has_Null_Exclusion --
12525 ------------------------
12527 function Has_Null_Exclusion (N : Node_Id) return Boolean is
12530 when N_Access_Definition
12531 | N_Access_Function_Definition
12532 | N_Access_Procedure_Definition
12533 | N_Access_To_Object_Definition
12535 | N_Derived_Type_Definition
12536 | N_Function_Specification
12537 | N_Subtype_Declaration
12539 return Null_Exclusion_Present (N);
12541 when N_Component_Definition
12542 | N_Formal_Object_Declaration
12544 if Present (Subtype_Mark (N)) then
12545 return Null_Exclusion_Present (N);
12546 else pragma Assert (Present (Access_Definition (N)));
12547 return Null_Exclusion_Present (Access_Definition (N));
12550 when N_Object_Renaming_Declaration =>
12551 if Present (Subtype_Mark (N)) then
12552 return Null_Exclusion_Present (N);
12553 elsif Present (Access_Definition (N)) then
12554 return Null_Exclusion_Present (Access_Definition (N));
12556 return False; -- Case of no subtype in renaming (AI12-0275)
12559 when N_Discriminant_Specification =>
12560 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
12561 return Null_Exclusion_Present (Discriminant_Type (N));
12563 return Null_Exclusion_Present (N);
12566 when N_Object_Declaration =>
12567 if Nkind (Object_Definition (N)) = N_Access_Definition then
12568 return Null_Exclusion_Present (Object_Definition (N));
12570 return Null_Exclusion_Present (N);
12573 when N_Parameter_Specification =>
12574 if Nkind (Parameter_Type (N)) = N_Access_Definition then
12575 return Null_Exclusion_Present (Parameter_Type (N))
12576 or else Null_Exclusion_Present (N);
12578 return Null_Exclusion_Present (N);
12584 end Has_Null_Exclusion;
12586 ------------------------
12587 -- Has_Null_Extension --
12588 ------------------------
12590 function Has_Null_Extension (T : Entity_Id) return Boolean is
12591 B : constant Entity_Id := Base_Type (T);
12596 if Nkind (Parent (B)) = N_Full_Type_Declaration
12597 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
12599 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
12601 if Present (Ext) then
12602 if Null_Present (Ext) then
12605 Comps := Component_List (Ext);
12607 -- The null component list is rewritten during analysis to
12608 -- include the parent component. Any other component indicates
12609 -- that the extension was not originally null.
12611 return Null_Present (Comps)
12612 or else No (Next (First (Component_Items (Comps))));
12621 end Has_Null_Extension;
12623 -------------------------
12624 -- Has_Null_Refinement --
12625 -------------------------
12627 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
12628 Constits : Elist_Id;
12631 pragma Assert (Ekind (Id) = E_Abstract_State);
12632 Constits := Refinement_Constituents (Id);
12634 -- For a refinement to be null, the state's sole constituent must be a
12639 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
12640 end Has_Null_Refinement;
12642 ------------------------------------------
12643 -- Has_Nonstatic_Class_Wide_Pre_Or_Post --
12644 ------------------------------------------
12646 function Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post
12647 (Subp : Entity_Id) return Boolean
12649 Disp_Type : constant Entity_Id := Find_Dispatching_Type (Subp);
12651 Pragma_Arg : Node_Id;
12654 if Present (Disp_Type)
12655 and then Is_Abstract_Type (Disp_Type)
12656 and then Present (Contract (Subp))
12658 Prag := Pre_Post_Conditions (Contract (Subp));
12660 while Present (Prag) loop
12661 if Pragma_Name (Prag) in Name_Precondition | Name_Postcondition
12662 and then Class_Present (Prag)
12666 (Pragma_Argument_Associations (Prag));
12668 if not Is_Static_Expression (Expression (Pragma_Arg)) then
12673 Prag := Next_Pragma (Prag);
12678 end Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post;
12680 -------------------------------
12681 -- Has_Overriding_Initialize --
12682 -------------------------------
12684 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
12685 BT : constant Entity_Id := Base_Type (T);
12689 if Is_Controlled (BT) then
12690 if Is_RTU (Scope (BT), Ada_Finalization) then
12693 elsif Present (Primitive_Operations (BT)) then
12694 P := First_Elmt (Primitive_Operations (BT));
12695 while Present (P) loop
12697 Init : constant Entity_Id := Node (P);
12698 Formal : constant Entity_Id := First_Formal (Init);
12700 if Ekind (Init) = E_Procedure
12701 and then Chars (Init) = Name_Initialize
12702 and then Comes_From_Source (Init)
12703 and then Present (Formal)
12704 and then Etype (Formal) = BT
12705 and then No (Next_Formal (Formal))
12706 and then (Ada_Version < Ada_2012
12707 or else not Null_Present (Parent (Init)))
12717 -- Here if type itself does not have a non-null Initialize operation:
12718 -- check immediate ancestor.
12720 if Is_Derived_Type (BT)
12721 and then Has_Overriding_Initialize (Etype (BT))
12728 end Has_Overriding_Initialize;
12730 --------------------------------------
12731 -- Has_Preelaborable_Initialization --
12732 --------------------------------------
12734 function Has_Preelaborable_Initialization
12736 Preelab_Init_Expr : Node_Id := Empty) return Boolean
12740 procedure Check_Components (E : Entity_Id);
12741 -- Check component/discriminant chain, sets Has_PE False if a component
12742 -- or discriminant does not meet the preelaborable initialization rules.
12744 function Type_Named_In_Preelab_Init_Expression
12746 Expr : Node_Id) return Boolean;
12747 -- Returns True iff Typ'Preelaborable_Initialization occurs in Expr
12748 -- (where Expr may be a conjunction of one or more P_I attributes).
12750 ----------------------
12751 -- Check_Components --
12752 ----------------------
12754 procedure Check_Components (E : Entity_Id) is
12759 -- Loop through components and discriminants of record or protected
12762 Ent := First_Component_Or_Discriminant (E);
12763 while Present (Ent) loop
12765 case Ekind (Ent) is
12766 when E_Component =>
12768 -- Get default expression if any. If there is no declaration
12769 -- node, it means we have an internal entity. The parent and
12770 -- tag fields are examples of such entities. For such cases,
12771 -- we just test the type of the entity.
12773 if Present (Declaration_Node (Ent)) then
12774 Exp := Expression (Declaration_Node (Ent));
12779 when E_Discriminant =>
12781 -- Note: for a renamed discriminant, the Declaration_Node
12782 -- may point to the one from the ancestor, and have a
12783 -- different expression, so use the proper attribute to
12784 -- retrieve the expression from the derived constraint.
12786 Exp := Discriminant_Default_Value (Ent);
12789 raise Program_Error;
12792 -- A component has PI if it has no default expression and the
12793 -- component type has PI.
12796 if not Has_Preelaborable_Initialization
12797 (Etype (Ent), Preelab_Init_Expr)
12803 -- Require the default expression to be preelaborable
12805 elsif not Is_Preelaborable_Construct (Exp) then
12810 Next_Component_Or_Discriminant (Ent);
12812 end Check_Components;
12814 --------------------------------------
12815 -- Type_Named_In_Preelab_Expression --
12816 --------------------------------------
12818 function Type_Named_In_Preelab_Init_Expression
12820 Expr : Node_Id) return Boolean
12823 -- Return True if Expr is a Preelaborable_Initialization attribute
12824 -- and the prefix is a subtype that has the same type as Typ.
12826 if Nkind (Expr) = N_Attribute_Reference
12827 and then Attribute_Name (Expr) = Name_Preelaborable_Initialization
12828 and then Is_Entity_Name (Prefix (Expr))
12829 and then Base_Type (Entity (Prefix (Expr))) = Base_Type (Typ)
12833 -- In the case where Expr is a conjunction, test whether either
12834 -- operand is a Preelaborable_Initialization attribute whose prefix
12835 -- has the same type as Typ, and return True if so.
12837 elsif Nkind (Expr) = N_Op_And
12839 (Type_Named_In_Preelab_Init_Expression (Typ, Left_Opnd (Expr))
12841 Type_Named_In_Preelab_Init_Expression (Typ, Right_Opnd (Expr)))
12845 -- Typ not named in a Preelaborable_Initialization attribute of Expr
12850 end Type_Named_In_Preelab_Init_Expression;
12852 -- Start of processing for Has_Preelaborable_Initialization
12855 -- Immediate return if already marked as known preelaborable init. This
12856 -- covers types for which this function has already been called once
12857 -- and returned True (in which case the result is cached), and also
12858 -- types to which a pragma Preelaborable_Initialization applies.
12860 if Known_To_Have_Preelab_Init (E) then
12864 -- If the type is a subtype representing a generic actual type, then
12865 -- test whether its base type has preelaborable initialization since
12866 -- the subtype representing the actual does not inherit this attribute
12867 -- from the actual or formal. (but maybe it should???)
12869 if Is_Generic_Actual_Type (E) then
12870 return Has_Preelaborable_Initialization (Base_Type (E));
12873 -- All elementary types have preelaborable initialization
12875 if Is_Elementary_Type (E) then
12878 -- Array types have PI if the component type has PI
12880 elsif Is_Array_Type (E) then
12881 Has_PE := Has_Preelaborable_Initialization
12882 (Component_Type (E), Preelab_Init_Expr);
12884 -- A derived type has preelaborable initialization if its parent type
12885 -- has preelaborable initialization and (in the case of a derived record
12886 -- extension) if the non-inherited components all have preelaborable
12887 -- initialization. However, a user-defined controlled type with an
12888 -- overriding Initialize procedure does not have preelaborable
12891 elsif Is_Derived_Type (E) then
12893 -- When the rule of RM 10.2.1(11.8/5) applies, we presume a component
12894 -- of a generic formal derived type has preelaborable initialization.
12895 -- (See comment on spec of Has_Preelaborable_Initialization.)
12897 if Is_Generic_Type (E)
12898 and then Present (Preelab_Init_Expr)
12900 Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr)
12905 -- If the derived type is a private extension then it doesn't have
12906 -- preelaborable initialization.
12908 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
12912 -- First check whether ancestor type has preelaborable initialization
12914 Has_PE := Has_Preelaborable_Initialization
12915 (Etype (Base_Type (E)), Preelab_Init_Expr);
12917 -- If OK, check extension components (if any)
12919 if Has_PE and then Is_Record_Type (E) then
12920 Check_Components (E);
12923 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
12924 -- with a user defined Initialize procedure does not have PI. If
12925 -- the type is untagged, the control primitives come from a component
12926 -- that has already been checked.
12929 and then Is_Controlled (E)
12930 and then Is_Tagged_Type (E)
12931 and then Has_Overriding_Initialize (E)
12936 -- Private types not derived from a type having preelaborable init and
12937 -- that are not marked with pragma Preelaborable_Initialization do not
12938 -- have preelaborable initialization.
12940 elsif Is_Private_Type (E) then
12942 -- When the rule of RM 10.2.1(11.8/5) applies, we presume a component
12943 -- of a generic formal private type has preelaborable initialization.
12944 -- (See comment on spec of Has_Preelaborable_Initialization.)
12946 if Is_Generic_Type (E)
12947 and then Present (Preelab_Init_Expr)
12949 Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr)
12956 -- Record type has PI if it is non private and all components have PI
12958 elsif Is_Record_Type (E) then
12960 Check_Components (E);
12962 -- Protected types must not have entries, and components must meet
12963 -- same set of rules as for record components.
12965 elsif Is_Protected_Type (E) then
12966 if Has_Entries (E) then
12970 Check_Components (E);
12973 -- Type System.Address always has preelaborable initialization
12975 elsif Is_RTE (E, RE_Address) then
12978 -- In all other cases, type does not have preelaborable initialization
12984 -- If type has preelaborable initialization, cache result
12987 Set_Known_To_Have_Preelab_Init (E);
12991 end Has_Preelaborable_Initialization;
12997 function Has_Prefix (N : Node_Id) return Boolean is
12999 return Nkind (N) in
13000 N_Attribute_Reference | N_Expanded_Name | N_Explicit_Dereference |
13001 N_Indexed_Component | N_Reference | N_Selected_Component |
13005 ---------------------------
13006 -- Has_Private_Component --
13007 ---------------------------
13009 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
13010 Btype : Entity_Id := Base_Type (Type_Id);
13011 Component : Entity_Id;
13014 if Error_Posted (Type_Id)
13015 or else Error_Posted (Btype)
13020 if Is_Class_Wide_Type (Btype) then
13021 Btype := Root_Type (Btype);
13024 if Is_Private_Type (Btype) then
13026 UT : constant Entity_Id := Underlying_Type (Btype);
13029 if No (Full_View (Btype)) then
13030 return not Is_Generic_Type (Btype)
13032 not Is_Generic_Type (Root_Type (Btype));
13034 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
13037 return not Is_Frozen (UT) and then Has_Private_Component (UT);
13041 elsif Is_Array_Type (Btype) then
13042 return Has_Private_Component (Component_Type (Btype));
13044 elsif Is_Record_Type (Btype) then
13045 Component := First_Component (Btype);
13046 while Present (Component) loop
13047 if Has_Private_Component (Etype (Component)) then
13051 Next_Component (Component);
13056 elsif Is_Protected_Type (Btype)
13057 and then Present (Corresponding_Record_Type (Btype))
13059 return Has_Private_Component (Corresponding_Record_Type (Btype));
13064 end Has_Private_Component;
13066 --------------------------------
13067 -- Has_Relaxed_Initialization --
13068 --------------------------------
13070 function Has_Relaxed_Initialization (E : Entity_Id) return Boolean is
13072 function Denotes_Relaxed_Parameter
13076 -- Returns True iff expression Expr denotes a formal parameter or
13077 -- function Param (through its attribute Result).
13079 -------------------------------
13080 -- Denotes_Relaxed_Parameter --
13081 -------------------------------
13083 function Denotes_Relaxed_Parameter
13085 Param : Entity_Id) return Boolean is
13087 if Nkind (Expr) in N_Identifier | N_Expanded_Name then
13088 return Entity (Expr) = Param;
13090 pragma Assert (Is_Attribute_Result (Expr));
13091 return Entity (Prefix (Expr)) = Param;
13093 end Denotes_Relaxed_Parameter;
13095 -- Start of processing for Has_Relaxed_Initialization
13098 -- When analyzing, we checked all syntax legality rules for the aspect
13099 -- Relaxed_Initialization, but didn't store the property anywhere (e.g.
13100 -- as an Einfo flag). To query the property we look directly at the AST,
13101 -- but now without any syntactic checks.
13104 -- Abstract states have option Relaxed_Initialization
13106 when E_Abstract_State =>
13107 return Is_Relaxed_Initialization_State (E);
13109 -- Constants have this aspect attached directly; for deferred
13110 -- constants, the aspect is attached to the partial view.
13113 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13115 -- Variables have this aspect attached directly
13118 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13120 -- Types have this aspect attached directly (though we only allow it
13121 -- to be specified for the first subtype). For private types, the
13122 -- aspect is attached to the partial view.
13125 pragma Assert (Is_First_Subtype (E));
13126 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13128 -- Formal parameters and functions have the Relaxed_Initialization
13129 -- aspect attached to the subprogram entity and must be listed in
13130 -- the aspect expression.
13136 Subp_Id : Entity_Id;
13137 Aspect_Expr : Node_Id;
13138 Param_Expr : Node_Id;
13142 if Is_Formal (E) then
13143 Subp_Id := Scope (E);
13148 if Has_Aspect (Subp_Id, Aspect_Relaxed_Initialization) then
13150 Find_Value_Of_Aspect
13151 (Subp_Id, Aspect_Relaxed_Initialization);
13153 -- Aspect expression is either an aggregate with an optional
13154 -- Boolean expression (which defaults to True), e.g.:
13156 -- function F (X : Integer) return Integer
13157 -- with Relaxed_Initialization => (X => True, F'Result);
13159 if Nkind (Aspect_Expr) = N_Aggregate then
13161 if Present (Component_Associations (Aspect_Expr)) then
13162 Assoc := First (Component_Associations (Aspect_Expr));
13164 while Present (Assoc) loop
13165 if Denotes_Relaxed_Parameter
13166 (First (Choices (Assoc)), E)
13170 (Static_Boolean (Expression (Assoc)));
13177 Param_Expr := First (Expressions (Aspect_Expr));
13179 while Present (Param_Expr) loop
13180 if Denotes_Relaxed_Parameter (Param_Expr, E) then
13189 -- or it is a single identifier, e.g.:
13191 -- function F (X : Integer) return Integer
13192 -- with Relaxed_Initialization => X;
13195 return Denotes_Relaxed_Parameter (Aspect_Expr, E);
13203 raise Program_Error;
13205 end Has_Relaxed_Initialization;
13207 ----------------------
13208 -- Has_Signed_Zeros --
13209 ----------------------
13211 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
13213 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
13214 end Has_Signed_Zeros;
13216 ------------------------------
13217 -- Has_Significant_Contract --
13218 ------------------------------
13220 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
13221 Subp_Nam : constant Name_Id := Chars (Subp_Id);
13224 -- _Finalizer procedure
13226 if Subp_Nam = Name_uFinalizer then
13229 -- _Wrapped_Statements procedure which gets generated as part of the
13230 -- expansion of postconditions.
13232 elsif Subp_Nam = Name_uWrapped_Statements then
13235 -- Predicate function
13237 elsif Ekind (Subp_Id) = E_Function
13238 and then Is_Predicate_Function (Subp_Id)
13244 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
13250 end Has_Significant_Contract;
13252 -----------------------------
13253 -- Has_Static_Array_Bounds --
13254 -----------------------------
13256 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
13257 All_Static : Boolean;
13261 Examine_Array_Bounds (Typ, All_Static, Dummy);
13264 end Has_Static_Array_Bounds;
13266 ---------------------------------------
13267 -- Has_Static_Non_Empty_Array_Bounds --
13268 ---------------------------------------
13270 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
13271 All_Static : Boolean;
13272 Has_Empty : Boolean;
13275 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
13277 return All_Static and not Has_Empty;
13278 end Has_Static_Non_Empty_Array_Bounds;
13284 function Has_Stream (T : Entity_Id) return Boolean is
13291 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
13294 elsif Is_Array_Type (T) then
13295 return Has_Stream (Component_Type (T));
13297 elsif Is_Record_Type (T) then
13298 E := First_Component (T);
13299 while Present (E) loop
13300 if Has_Stream (Etype (E)) then
13303 Next_Component (E);
13309 elsif Is_Private_Type (T) then
13310 return Has_Stream (Underlying_Type (T));
13321 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
13323 Get_Name_String (Chars (E));
13324 return Name_Buffer (Name_Len) = Suffix;
13331 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
13333 Get_Name_String (Chars (E));
13334 Add_Char_To_Name_Buffer (Suffix);
13338 -------------------
13339 -- Remove_Suffix --
13340 -------------------
13342 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
13344 pragma Assert (Has_Suffix (E, Suffix));
13345 Get_Name_String (Chars (E));
13346 Name_Len := Name_Len - 1;
13350 ----------------------------------
13351 -- Replace_Null_By_Null_Address --
13352 ----------------------------------
13354 procedure Replace_Null_By_Null_Address (N : Node_Id) is
13355 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
13356 -- Replace operand Op with a reference to Null_Address when the operand
13357 -- denotes a null Address. Other_Op denotes the other operand.
13359 --------------------------
13360 -- Replace_Null_Operand --
13361 --------------------------
13363 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
13365 -- Check the type of the complementary operand since the N_Null node
13366 -- has not been decorated yet.
13368 if Nkind (Op) = N_Null
13369 and then Is_Descendant_Of_Address (Etype (Other_Op))
13371 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
13373 end Replace_Null_Operand;
13375 -- Start of processing for Replace_Null_By_Null_Address
13378 pragma Assert (Relaxed_RM_Semantics);
13379 pragma Assert (Nkind (N) in N_Null | N_Op_Compare);
13381 if Nkind (N) = N_Null then
13382 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
13386 L : constant Node_Id := Left_Opnd (N);
13387 R : constant Node_Id := Right_Opnd (N);
13390 Replace_Null_Operand (L, Other_Op => R);
13391 Replace_Null_Operand (R, Other_Op => L);
13394 end Replace_Null_By_Null_Address;
13396 --------------------------
13397 -- Has_Tagged_Component --
13398 --------------------------
13400 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
13404 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
13405 return Has_Tagged_Component (Underlying_Type (Typ));
13407 elsif Is_Array_Type (Typ) then
13408 return Has_Tagged_Component (Component_Type (Typ));
13410 elsif Is_Tagged_Type (Typ) then
13413 elsif Is_Record_Type (Typ) then
13414 Comp := First_Component (Typ);
13415 while Present (Comp) loop
13416 if Has_Tagged_Component (Etype (Comp)) then
13420 Next_Component (Comp);
13428 end Has_Tagged_Component;
13430 -----------------------------
13431 -- Has_Undefined_Reference --
13432 -----------------------------
13434 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
13435 Has_Undef_Ref : Boolean := False;
13436 -- Flag set when expression Expr contains at least one undefined
13439 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
13440 -- Determine whether N denotes a reference and if it does, whether it is
13443 ----------------------------
13444 -- Is_Undefined_Reference --
13445 ----------------------------
13447 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
13449 if Is_Entity_Name (N)
13450 and then Present (Entity (N))
13451 and then Entity (N) = Any_Id
13453 Has_Undef_Ref := True;
13458 end Is_Undefined_Reference;
13460 procedure Find_Undefined_References is
13461 new Traverse_Proc (Is_Undefined_Reference);
13463 -- Start of processing for Has_Undefined_Reference
13466 Find_Undefined_References (Expr);
13468 return Has_Undef_Ref;
13469 end Has_Undefined_Reference;
13471 ----------------------------------------
13472 -- Has_Effectively_Volatile_Component --
13473 ----------------------------------------
13475 function Has_Effectively_Volatile_Component
13476 (Typ : Entity_Id) return Boolean
13481 if Has_Volatile_Components (Typ) then
13484 elsif Is_Array_Type (Typ) then
13485 return Is_Effectively_Volatile (Component_Type (Typ));
13487 elsif Is_Record_Type (Typ) then
13488 Comp := First_Component (Typ);
13489 while Present (Comp) loop
13490 if Is_Effectively_Volatile (Etype (Comp)) then
13494 Next_Component (Comp);
13499 end Has_Effectively_Volatile_Component;
13501 ----------------------------
13502 -- Has_Volatile_Component --
13503 ----------------------------
13505 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
13509 if Has_Volatile_Components (Typ) then
13512 elsif Is_Array_Type (Typ) then
13513 return Is_Volatile (Component_Type (Typ));
13515 elsif Is_Record_Type (Typ) then
13516 Comp := First_Component (Typ);
13517 while Present (Comp) loop
13518 if Is_Volatile_Object_Ref (Comp) then
13522 Next_Component (Comp);
13527 end Has_Volatile_Component;
13529 -------------------------
13530 -- Implementation_Kind --
13531 -------------------------
13533 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
13534 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
13537 pragma Assert (Present (Impl_Prag));
13538 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
13539 return Chars (Get_Pragma_Arg (Arg));
13540 end Implementation_Kind;
13542 --------------------------
13543 -- Implements_Interface --
13544 --------------------------
13546 function Implements_Interface
13547 (Typ_Ent : Entity_Id;
13548 Iface_Ent : Entity_Id;
13549 Exclude_Parents : Boolean := False) return Boolean
13551 Ifaces_List : Elist_Id;
13553 Iface : Entity_Id := Base_Type (Iface_Ent);
13554 Typ : Entity_Id := Base_Type (Typ_Ent);
13557 if Is_Class_Wide_Type (Typ) then
13558 Typ := Root_Type (Typ);
13561 if not Has_Interfaces (Typ) then
13565 if Is_Class_Wide_Type (Iface) then
13566 Iface := Root_Type (Iface);
13569 Collect_Interfaces (Typ, Ifaces_List);
13571 Elmt := First_Elmt (Ifaces_List);
13572 while Present (Elmt) loop
13573 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
13574 and then Exclude_Parents
13578 elsif Node (Elmt) = Iface then
13586 end Implements_Interface;
13588 --------------------------------
13589 -- Implicitly_Designated_Type --
13590 --------------------------------
13592 function Implicitly_Designated_Type (Typ : Entity_Id) return Entity_Id is
13593 Desig : constant Entity_Id := Designated_Type (Typ);
13596 -- An implicit dereference is a legal occurrence of an incomplete type
13597 -- imported through a limited_with clause, if the full view is visible.
13599 if Is_Incomplete_Type (Desig)
13600 and then From_Limited_With (Desig)
13601 and then not From_Limited_With (Scope (Desig))
13603 (Is_Immediately_Visible (Scope (Desig))
13605 (Is_Child_Unit (Scope (Desig))
13606 and then Is_Visible_Lib_Unit (Scope (Desig))))
13608 return Available_View (Desig);
13612 end Implicitly_Designated_Type;
13614 ------------------------------------
13615 -- In_Assertion_Expression_Pragma --
13616 ------------------------------------
13618 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
13620 Prag : Node_Id := Empty;
13623 -- Climb the parent chain looking for an enclosing pragma
13626 while Present (Par) loop
13627 if Nkind (Par) = N_Pragma then
13631 -- Precondition-like pragmas are expanded into if statements, check
13632 -- the original node instead.
13634 elsif Nkind (Original_Node (Par)) = N_Pragma then
13635 Prag := Original_Node (Par);
13638 -- The expansion of attribute 'Old generates a
constant to capture
13639 -- the result of the prefix. If the parent traversal reaches
13640 -- one of these constants, then the node technically came from a
13641 -- postcondition-like pragma. Note that the Ekind is not tested here
13642 -- because N may be the expression of an object declaration which is
13643 -- currently being analyzed. Such objects carry Ekind of E_Void.
13645 elsif Nkind
(Par
) = N_Object_Declaration
13646 and then Constant_Present
(Par
)
13647 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
13651 -- Prevent the search from going too far
13653 elsif Is_Body_Or_Package_Declaration
(Par
) then
13657 Par
:= Parent
(Par
);
13662 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
13663 end In_Assertion_Expression_Pragma
;
13665 -------------------
13666 -- In_Check_Node --
13667 -------------------
13669 function In_Check_Node
(N
: Node_Id
) return Boolean is
13670 Par
: Node_Id
:= Parent
(N
);
13672 while Present
(Par
) loop
13673 if Nkind
(Par
) in N_Raise_xxx_Error
then
13676 -- Prevent the search from going too far
13678 elsif Is_Body_Or_Package_Declaration
(Par
) then
13682 Par
:= Parent
(Par
);
13689 -------------------------------
13690 -- In_Generic_Formal_Package --
13691 -------------------------------
13693 function In_Generic_Formal_Package
(E
: Entity_Id
) return Boolean is
13698 while Present
(Par
) loop
13699 if Nkind
(Par
) = N_Formal_Package_Declaration
13700 or else Nkind
(Original_Node
(Par
)) = N_Formal_Package_Declaration
13705 Par
:= Parent
(Par
);
13709 end In_Generic_Formal_Package
;
13711 ----------------------
13712 -- In_Generic_Scope --
13713 ----------------------
13715 function In_Generic_Scope
(E
: Entity_Id
) return Boolean is
13720 while Present
(S
) and then S
/= Standard_Standard
loop
13721 if Is_Generic_Unit
(S
) then
13729 end In_Generic_Scope
;
13735 function In_Instance
return Boolean is
13736 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
13740 S
:= Current_Scope
;
13741 while Present
(S
) and then S
/= Standard_Standard
loop
13742 if Is_Generic_Instance
(S
) then
13744 -- A child instance is always compiled in the context of a parent
13745 -- instance. Nevertheless, its actuals must not be analyzed in an
13746 -- instance context. We detect this case by examining the current
13747 -- compilation unit, which must be a child instance, and checking
13748 -- that it has not been analyzed yet.
13750 if Is_Child_Unit
(Curr_Unit
)
13751 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
13752 N_Package_Instantiation
13753 and then Ekind
(Curr_Unit
) = E_Void
13767 ----------------------
13768 -- In_Instance_Body --
13769 ----------------------
13771 function In_Instance_Body
return Boolean is
13775 S
:= Current_Scope
;
13776 while Present
(S
) and then S
/= Standard_Standard
loop
13777 if Ekind
(S
) in E_Function | E_Procedure
13778 and then Is_Generic_Instance
(S
)
13782 elsif Ekind
(S
) = E_Package
13783 and then In_Package_Body
(S
)
13784 and then Is_Generic_Instance
(S
)
13793 end In_Instance_Body
;
13795 -----------------------------
13796 -- In_Instance_Not_Visible --
13797 -----------------------------
13799 function In_Instance_Not_Visible
return Boolean is
13803 S
:= Current_Scope
;
13804 while Present
(S
) and then S
/= Standard_Standard
loop
13805 if Ekind
(S
) in E_Function | E_Procedure
13806 and then Is_Generic_Instance
(S
)
13810 elsif Ekind
(S
) = E_Package
13811 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
13812 and then Is_Generic_Instance
(S
)
13821 end In_Instance_Not_Visible
;
13823 ------------------------------
13824 -- In_Instance_Visible_Part --
13825 ------------------------------
13827 function In_Instance_Visible_Part
13828 (Id
: Entity_Id
:= Current_Scope
) return Boolean
13834 while Present
(Inst
) and then Inst
/= Standard_Standard
loop
13835 if Ekind
(Inst
) = E_Package
13836 and then Is_Generic_Instance
(Inst
)
13837 and then not In_Package_Body
(Inst
)
13838 and then not In_Private_Part
(Inst
)
13843 Inst
:= Scope
(Inst
);
13847 end In_Instance_Visible_Part
;
13849 ---------------------
13850 -- In_Package_Body --
13851 ---------------------
13853 function In_Package_Body
return Boolean is
13857 S
:= Current_Scope
;
13858 while Present
(S
) and then S
/= Standard_Standard
loop
13859 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
13867 end In_Package_Body
;
13869 --------------------------
13870 -- In_Pragma_Expression --
13871 --------------------------
13873 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
13881 -- Prevent the search from going too far
13883 elsif Is_Body_Or_Package_Declaration
(P
) then
13886 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
13893 end In_Pragma_Expression
;
13895 ---------------------------
13896 -- In_Pre_Post_Condition --
13897 ---------------------------
13899 function In_Pre_Post_Condition
13900 (N
: Node_Id
; Class_Wide_Only
: Boolean := False) return Boolean
13903 Prag
: Node_Id
:= Empty
;
13904 Prag_Id
: Pragma_Id
;
13907 -- Climb the parent chain looking for an enclosing pragma
13910 while Present
(Par
) loop
13911 if Nkind
(Par
) = N_Pragma
then
13915 -- Prevent the search from going too far
13917 elsif Is_Body_Or_Package_Declaration
(Par
) then
13921 Par
:= Parent
(Par
);
13924 if Present
(Prag
) then
13925 Prag_Id
:= Get_Pragma_Id
(Prag
);
13927 if Class_Wide_Only
then
13929 Prag_Id
= Pragma_Post_Class
13930 or else Prag_Id
= Pragma_Pre_Class
13931 or else (Class_Present
(Prag
)
13932 and then (Prag_Id
= Pragma_Post
13933 or else Prag_Id
= Pragma_Postcondition
13934 or else Prag_Id
= Pragma_Pre
13935 or else Prag_Id
= Pragma_Precondition
));
13938 Prag_Id
= Pragma_Post
13939 or else Prag_Id
= Pragma_Post_Class
13940 or else Prag_Id
= Pragma_Postcondition
13941 or else Prag_Id
= Pragma_Pre
13942 or else Prag_Id
= Pragma_Pre_Class
13943 or else Prag_Id
= Pragma_Precondition
;
13946 -- Otherwise the node is not enclosed by a pre/postcondition pragma
13951 end In_Pre_Post_Condition
;
13953 ------------------------------
13954 -- In_Quantified_Expression --
13955 ------------------------------
13957 function In_Quantified_Expression
(N
: Node_Id
) return Boolean is
13965 -- Prevent the search from going too far
13967 elsif Is_Body_Or_Package_Declaration
(P
) then
13970 elsif Nkind
(P
) = N_Quantified_Expression
then
13976 end In_Quantified_Expression
;
13978 -------------------------------------
13979 -- In_Reverse_Storage_Order_Object --
13980 -------------------------------------
13982 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
13984 Btyp
: Entity_Id
:= Empty
;
13987 -- Climb up indexed components
13991 case Nkind
(Pref
) is
13992 when N_Selected_Component
=>
13993 Pref
:= Prefix
(Pref
);
13996 when N_Indexed_Component
=>
13997 Pref
:= Prefix
(Pref
);
14005 if Present
(Pref
) then
14006 Btyp
:= Base_Type
(Etype
(Pref
));
14009 return Present
(Btyp
)
14010 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
14011 and then Reverse_Storage_Order
(Btyp
);
14012 end In_Reverse_Storage_Order_Object
;
14014 ------------------------------
14015 -- In_Same_Declarative_Part --
14016 ------------------------------
14018 function In_Same_Declarative_Part
14019 (Context
: Node_Id
;
14020 N
: Node_Id
) return Boolean
14022 Cont
: Node_Id
:= Context
;
14026 if Nkind
(Cont
) = N_Compilation_Unit_Aux
then
14027 Cont
:= Parent
(Cont
);
14031 while Present
(Nod
) loop
14035 elsif Nkind
(Nod
) in N_Accept_Statement
14036 | N_Block_Statement
14037 | N_Compilation_Unit
14040 | N_Package_Declaration
14042 | N_Subprogram_Body
14047 elsif Nkind
(Nod
) = N_Subunit
then
14048 Nod
:= Corresponding_Stub
(Nod
);
14051 Nod
:= Parent
(Nod
);
14056 end In_Same_Declarative_Part
;
14058 --------------------------------------
14059 -- In_Subprogram_Or_Concurrent_Unit --
14060 --------------------------------------
14062 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
14067 -- Use scope chain to check successively outer scopes
14069 E
:= Current_Scope
;
14073 if K
in Subprogram_Kind
14074 or else K
in Concurrent_Kind
14075 or else K
in Generic_Subprogram_Kind
14079 elsif E
= Standard_Standard
then
14085 end In_Subprogram_Or_Concurrent_Unit
;
14091 function In_Subtree
(N
: Node_Id
; Root
: Node_Id
) return Boolean is
14096 while Present
(Curr
) loop
14097 if Curr
= Root
then
14101 Curr
:= Parent
(Curr
);
14111 function In_Subtree
14114 Root2
: Node_Id
) return Boolean
14120 while Present
(Curr
) loop
14121 if Curr
= Root1
or else Curr
= Root2
then
14125 Curr
:= Parent
(Curr
);
14131 ---------------------
14132 -- In_Return_Value --
14133 ---------------------
14135 function In_Return_Value
(Expr
: Node_Id
) return Boolean is
14137 Prev_Par
: Node_Id
;
14139 In_Function_Call
: Boolean := False;
14142 -- Move through parent nodes to determine if Expr contributes to the
14143 -- return value of the current subprogram.
14147 while Present
(Par
) loop
14149 case Nkind
(Par
) is
14150 -- Ignore ranges and they don't contribute to the result
14155 -- An object declaration whose parent is an extended return
14156 -- statement is a return object.
14158 when N_Object_Declaration
=>
14159 if Present
(Parent
(Par
))
14160 and then Nkind
(Parent
(Par
)) = N_Extended_Return_Statement
14165 -- We hit a simple return statement, so we know we are in one
14167 when N_Simple_Return_Statement
=>
14170 -- Only include one nexting level of function calls
14172 when N_Function_Call
=>
14173 if not In_Function_Call
then
14174 In_Function_Call
:= True;
14176 -- When the function return type has implicit dereference
14177 -- specified we know it cannot directly contribute to the
14180 if Present
(Etype
(Par
))
14181 and then Has_Implicit_Dereference
14182 (Get_Full_View
(Etype
(Par
)))
14190 -- Check if we are on the right-hand side of an assignment
14191 -- statement to a return object.
14193 -- This is not specified in the RM ???
14195 when N_Assignment_Statement
=>
14196 if Prev_Par
= Name
(Par
) then
14201 while Present
(Pre
) loop
14202 if Is_Entity_Name
(Pre
)
14203 and then Is_Return_Object
(Entity
(Pre
))
14208 exit when Nkind
(Pre
) not in N_Selected_Component
14209 | N_Indexed_Component
14212 Pre
:= Prefix
(Pre
);
14215 -- Otherwise, we hit a master which was not relevant
14218 if Is_Master
(Par
) then
14223 -- Iterate up to the next parent, keeping track of the previous one
14226 Par
:= Parent
(Par
);
14230 end In_Return_Value
;
14232 -----------------------------------------
14233 -- In_Statement_Condition_With_Actions --
14234 -----------------------------------------
14236 function In_Statement_Condition_With_Actions
(N
: Node_Id
) return Boolean is
14237 Prev
: Node_Id
:= N
;
14238 P
: Node_Id
:= Parent
(N
);
14239 -- P and Prev will be used for traversing the AST, while maintaining an
14240 -- invariant that P = Parent (Prev).
14242 while Present
(P
) loop
14243 if Nkind
(P
) = N_Iteration_Scheme
14244 and then Prev
= Condition
(P
)
14248 elsif Nkind
(P
) = N_Elsif_Part
14249 and then Prev
= Condition
(P
)
14253 -- No point in going beyond statements
14255 elsif Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
14256 | N_Procedure_Call_Statement
14260 -- Prevent the search from going too far
14262 elsif Is_Body_Or_Package_Declaration
(P
) then
14271 end In_Statement_Condition_With_Actions
;
14273 ---------------------
14274 -- In_Visible_Part --
14275 ---------------------
14277 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
14279 return Is_Package_Or_Generic_Package
(Scope_Id
)
14280 and then In_Open_Scopes
(Scope_Id
)
14281 and then not In_Package_Body
(Scope_Id
)
14282 and then not In_Private_Part
(Scope_Id
);
14283 end In_Visible_Part
;
14285 --------------------------------
14286 -- Incomplete_Or_Partial_View --
14287 --------------------------------
14289 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
14290 S
: constant Entity_Id
:= Scope
(Id
);
14292 function Inspect_Decls
14294 Taft
: Boolean := False) return Entity_Id
;
14295 -- Check whether a declarative region contains the incomplete or partial
14298 -------------------
14299 -- Inspect_Decls --
14300 -------------------
14302 function Inspect_Decls
14304 Taft
: Boolean := False) return Entity_Id
14310 Decl
:= First
(Decls
);
14311 while Present
(Decl
) loop
14314 -- The partial view of a Taft-amendment type is an incomplete
14318 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
14319 Match
:= Defining_Identifier
(Decl
);
14322 -- Otherwise look for a private type whose full view matches the
14323 -- input type. Note that this checks full_type_declaration nodes
14324 -- to account for derivations from a private type where the type
14325 -- declaration hold the partial view and the full view is an
14328 elsif Nkind
(Decl
) in N_Full_Type_Declaration
14329 | N_Private_Extension_Declaration
14330 | N_Private_Type_Declaration
14332 Match
:= Defining_Identifier
(Decl
);
14335 -- Guard against unanalyzed entities
14338 and then Is_Type
(Match
)
14339 and then Present
(Full_View
(Match
))
14340 and then Full_View
(Match
) = Id
14355 -- Start of processing for Incomplete_Or_Partial_View
14358 -- Deferred constant or incomplete type case
14360 Prev
:= Current_Entity
(Id
);
14362 while Present
(Prev
) loop
14363 exit when Scope
(Prev
) = S
;
14365 Prev
:= Homonym
(Prev
);
14369 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
14370 and then Present
(Full_View
(Prev
))
14371 and then Full_View
(Prev
) = Id
14376 -- Private or Taft amendment type case
14378 if Present
(S
) and then Is_Package_Or_Generic_Package
(S
) then
14380 Pkg_Decl
: constant Node_Id
:= Package_Specification
(S
);
14383 -- It is knows that Typ has a private view, look for it in the
14384 -- visible declarations of the enclosing scope. A special case
14385 -- of this is when the two views have been exchanged - the full
14386 -- appears earlier than the private.
14388 if Has_Private_Declaration
(Id
) then
14389 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
14391 -- Exchanged view case, look in the private declarations
14394 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
14399 -- Otherwise if this is the package body, then Typ is a potential
14400 -- Taft amendment type. The incomplete view should be located in
14401 -- the private declarations of the enclosing scope.
14403 elsif In_Package_Body
(S
) then
14404 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
14409 -- The type has no incomplete or private view
14412 end Incomplete_Or_Partial_View
;
14414 ---------------------------------------
14415 -- Incomplete_View_From_Limited_With --
14416 ---------------------------------------
14418 function Incomplete_View_From_Limited_With
14419 (Typ
: Entity_Id
) return Entity_Id
14422 -- It might make sense to make this an attribute in Einfo, and set it
14423 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
14424 -- slots for new attributes, and it seems a bit simpler to just search
14425 -- the Limited_View (if it exists) for an incomplete type whose
14426 -- Non_Limited_View is Typ.
14428 if Ekind
(Scope
(Typ
)) = E_Package
14429 and then Present
(Limited_View
(Scope
(Typ
)))
14432 Ent
: Entity_Id
:= First_Entity
(Limited_View
(Scope
(Typ
)));
14434 while Present
(Ent
) loop
14435 if Is_Incomplete_Type
(Ent
)
14436 and then Non_Limited_View
(Ent
) = Typ
14447 end Incomplete_View_From_Limited_With
;
14449 ----------------------------------
14450 -- Indexed_Component_Bit_Offset --
14451 ----------------------------------
14453 function Indexed_Component_Bit_Offset
(N
: Node_Id
) return Uint
is
14454 Exp
: constant Node_Id
:= First
(Expressions
(N
));
14455 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
14456 Off
: constant Uint
:= Component_Size
(Typ
);
14460 -- Return early if the component size is not known or variable
14462 if No
(Off
) or else Off
< Uint_0
then
14466 -- Deal with the degenerate case of an empty component
14468 if Off
= Uint_0
then
14472 -- Check that both the index value and the low bound are known
14474 if not Compile_Time_Known_Value
(Exp
) then
14478 Ind
:= First_Index
(Typ
);
14483 -- Do not attempt to compute offsets within multi-dimensional arrays
14485 if Present
(Next_Index
(Ind
)) then
14489 if Nkind
(Ind
) = N_Subtype_Indication
then
14490 Ind
:= Constraint
(Ind
);
14492 if Nkind
(Ind
) = N_Range_Constraint
then
14493 Ind
:= Range_Expression
(Ind
);
14497 if Nkind
(Ind
) /= N_Range
14498 or else not Compile_Time_Known_Value
(Low_Bound
(Ind
))
14503 -- Return the scaled offset
14505 return Off
* (Expr_Value
(Exp
) - Expr_Value
(Low_Bound
(Ind
)));
14506 end Indexed_Component_Bit_Offset
;
14508 -----------------------------
14509 -- Inherit_Predicate_Flags --
14510 -----------------------------
14512 procedure Inherit_Predicate_Flags
14513 (Subt
, Par
: Entity_Id
;
14514 Only_Flags
: Boolean := False)
14517 if Ada_Version
< Ada_2012
14518 or else Present
(Predicate_Function
(Subt
))
14523 Set_Has_Predicates
(Subt
, Has_Predicates
(Par
));
14524 Set_Has_Static_Predicate_Aspect
14525 (Subt
, Has_Static_Predicate_Aspect
(Par
));
14526 Set_Has_Dynamic_Predicate_Aspect
14527 (Subt
, Has_Dynamic_Predicate_Aspect
(Par
));
14528 Set_Has_Ghost_Predicate_Aspect
14529 (Subt
, Has_Ghost_Predicate_Aspect
(Par
));
14531 -- A named subtype does not inherit the predicate function of its
14532 -- parent but an itype declared for a loop index needs the discrete
14533 -- predicate information of its parent to execute the loop properly.
14534 -- A non-discrete type may has a static predicate (for example True)
14535 -- but has no static_discrete_predicate.
14538 and then Is_Itype
(Subt
)
14539 and then Present
(Predicate_Function
(Par
))
14541 Set_Subprograms_For_Type
(Subt
, Subprograms_For_Type
(Par
));
14543 if Has_Static_Predicate
(Par
) and then Is_Discrete_Type
(Par
) then
14544 Set_Static_Discrete_Predicate
14545 (Subt
, Static_Discrete_Predicate
(Par
));
14548 end Inherit_Predicate_Flags
;
14550 ----------------------------
14551 -- Inherit_Rep_Item_Chain --
14552 ----------------------------
14554 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
14556 Next_Item
: Node_Id
;
14559 -- There are several inheritance scenarios to consider depending on
14560 -- whether both types have rep item chains and whether the destination
14561 -- type already inherits part of the source type's rep item chain.
14563 -- 1) The source type lacks a rep item chain
14564 -- From_Typ ---> Empty
14566 -- Typ --------> Item (or Empty)
14568 -- In this case inheritance cannot take place because there are no items
14571 -- 2) The destination type lacks a rep item chain
14572 -- From_Typ ---> Item ---> ...
14574 -- Typ --------> Empty
14576 -- Inheritance takes place by setting the First_Rep_Item of the
14577 -- destination type to the First_Rep_Item of the source type.
14578 -- From_Typ ---> Item ---> ...
14580 -- Typ -----------+
14582 -- 3.1) Both source and destination types have at least one rep item.
14583 -- The destination type does NOT inherit a rep item from the source
14585 -- From_Typ ---> Item ---> Item
14587 -- Typ --------> Item ---> Item
14589 -- Inheritance takes place by setting the Next_Rep_Item of the last item
14590 -- of the destination type to the First_Rep_Item of the source type.
14591 -- From_Typ -------------------> Item ---> Item
14593 -- Typ --------> Item ---> Item --+
14595 -- 3.2) Both source and destination types have at least one rep item.
14596 -- The destination type DOES inherit part of the rep item chain of the
14598 -- From_Typ ---> Item ---> Item ---> Item
14600 -- Typ --------> Item ------+
14602 -- This rare case arises when the full view of a private extension must
14603 -- inherit the rep item chain from the full view of its parent type and
14604 -- the full view of the parent type contains extra rep items. Currently
14605 -- only invariants may lead to such form of inheritance.
14607 -- type From_Typ is tagged private
14608 -- with Type_Invariant'Class => Item_2;
14610 -- type Typ is new From_Typ with private
14611 -- with Type_Invariant => Item_4;
14613 -- At this point the rep item chains contain the following items
14615 -- From_Typ -----------> Item_2 ---> Item_3
14617 -- Typ --------> Item_4 --+
14619 -- The full views of both types may introduce extra invariants
14621 -- type From_Typ is tagged null record
14622 -- with Type_Invariant => Item_1;
14624 -- type Typ is new From_Typ with null record;
14626 -- The full view of Typ would have to inherit any new rep items added to
14627 -- the full view of From_Typ.
14629 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
14631 -- Typ --------> Item_4 --+
14633 -- To achieve this form of inheritance, the destination type must first
14634 -- sever the link between its own rep chain and that of the source type,
14635 -- then inheritance 3.1 takes place.
14637 -- Case 1: The source type lacks a rep item chain
14639 if No
(First_Rep_Item
(From_Typ
)) then
14642 -- Case 2: The destination type lacks a rep item chain
14644 elsif No
(First_Rep_Item
(Typ
)) then
14645 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
14647 -- Case 3: Both the source and destination types have at least one rep
14648 -- item. Traverse the rep item chain of the destination type to find the
14653 Next_Item
:= First_Rep_Item
(Typ
);
14654 while Present
(Next_Item
) loop
14656 -- Detect a link between the destination type's rep chain and that
14657 -- of the source type. There are two possibilities:
14662 -- From_Typ ---> Item_1 --->
14664 -- Typ -----------+
14671 -- From_Typ ---> Item_1 ---> Item_2 --->
14673 -- Typ --------> Item_3 ------+
14677 if Present_In_Rep_Item
(From_Typ
, Next_Item
) then
14682 Next_Item
:= Next_Rep_Item
(Next_Item
);
14685 -- Inherit the source type's rep item chain
14687 if Present
(Item
) then
14688 Set_Next_Rep_Item
(Item
, First_Rep_Item
(From_Typ
));
14690 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
14693 end Inherit_Rep_Item_Chain
;
14695 ------------------------------------
14696 -- Inherits_From_Tagged_Full_View --
14697 ------------------------------------
14699 function Inherits_From_Tagged_Full_View
(Typ
: Entity_Id
) return Boolean is
14701 return Is_Private_Type
(Typ
)
14702 and then Present
(Full_View
(Typ
))
14703 and then Is_Private_Type
(Full_View
(Typ
))
14704 and then not Is_Tagged_Type
(Full_View
(Typ
))
14705 and then Present
(Underlying_Type
(Full_View
(Typ
)))
14706 and then Is_Tagged_Type
(Underlying_Type
(Full_View
(Typ
)));
14707 end Inherits_From_Tagged_Full_View
;
14709 ---------------------------------
14710 -- Insert_Explicit_Dereference --
14711 ---------------------------------
14713 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
14714 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
14715 Ent
: Entity_Id
:= Empty
;
14716 Pref
: Node_Id
:= Empty
;
14722 Save_Interps
(N
, New_Prefix
);
14725 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
14726 Prefix
=> New_Prefix
));
14728 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
14730 if Is_Overloaded
(New_Prefix
) then
14732 -- The dereference is also overloaded, and its interpretations are
14733 -- the designated types of the interpretations of the original node.
14735 Set_Etype
(N
, Any_Type
);
14737 Get_First_Interp
(New_Prefix
, I
, It
);
14738 while Present
(It
.Nam
) loop
14741 if Is_Access_Type
(T
) then
14742 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
14745 Get_Next_Interp
(I
, It
);
14749 -- Prefix is unambiguous: mark the original prefix (which might
14750 -- Come_From_Source) as a reference, since the new (relocated) one
14751 -- won't be taken into account.
14753 if Is_Entity_Name
(New_Prefix
) then
14754 Ent
:= Entity
(New_Prefix
);
14755 Pref
:= New_Prefix
;
14757 -- For a retrieval of a subcomponent of some composite object,
14758 -- retrieve the ultimate entity if there is one.
14760 elsif Nkind
(New_Prefix
) in N_Selected_Component | N_Indexed_Component
14762 Pref
:= Prefix
(New_Prefix
);
14763 while Present
(Pref
)
14764 and then Nkind
(Pref
) in
14765 N_Selected_Component | N_Indexed_Component
14767 Pref
:= Prefix
(Pref
);
14770 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
14771 Ent
:= Entity
(Pref
);
14775 -- Place the reference on the entity node
14777 if Present
(Ent
) then
14778 Generate_Reference
(Ent
, Pref
);
14781 end Insert_Explicit_Dereference
;
14783 ------------------------------------------
14784 -- Inspect_Deferred_Constant_Completion --
14785 ------------------------------------------
14787 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
14791 Decl
:= First
(Decls
);
14792 while Present
(Decl
) loop
14794 -- Deferred constant signature
14796 if Nkind
(Decl
) = N_Object_Declaration
14797 and then Constant_Present
(Decl
)
14798 and then No
(Expression
(Decl
))
14800 -- No need to check internally generated constants
14802 and then Comes_From_Source
(Decl
)
14804 -- The constant is not completed. A full object declaration or a
14805 -- pragma Import complete a deferred constant.
14807 and then not Has_Completion
(Defining_Identifier
(Decl
))
14810 ("constant declaration requires initialization expression",
14811 Defining_Identifier
(Decl
));
14816 end Inspect_Deferred_Constant_Completion
;
14818 -------------------------------
14819 -- Install_Elaboration_Model --
14820 -------------------------------
14822 procedure Install_Elaboration_Model
(Unit_Id
: Entity_Id
) is
14823 function Find_Elaboration_Checks_Pragma
(L
: List_Id
) return Node_Id
;
14824 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
14825 -- Empty if there is no such pragma.
14827 ------------------------------------
14828 -- Find_Elaboration_Checks_Pragma --
14829 ------------------------------------
14831 function Find_Elaboration_Checks_Pragma
(L
: List_Id
) return Node_Id
is
14836 while Present
(Item
) loop
14837 if Nkind
(Item
) = N_Pragma
14838 and then Pragma_Name
(Item
) = Name_Elaboration_Checks
14847 end Find_Elaboration_Checks_Pragma
;
14856 -- Start of processing for Install_Elaboration_Model
14859 -- Nothing to do when the unit does not exist
14861 if No
(Unit_Id
) then
14865 Unit
:= Parent
(Unit_Declaration_Node
(Unit_Id
));
14867 -- Nothing to do when the unit is not a library unit
14869 if Nkind
(Unit
) /= N_Compilation_Unit
then
14873 Prag
:= Find_Elaboration_Checks_Pragma
(Context_Items
(Unit
));
14875 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
14876 -- elaboration model as specified by the pragma.
14878 if Present
(Prag
) then
14879 Args
:= Pragma_Argument_Associations
(Prag
);
14881 -- Guard against an illegal pragma. The sole argument must be an
14882 -- identifier which specifies either Dynamic or Static model.
14884 if Present
(Args
) then
14885 Model
:= Get_Pragma_Arg
(First
(Args
));
14887 if Nkind
(Model
) = N_Identifier
then
14888 Dynamic_Elaboration_Checks
:= Chars
(Model
) = Name_Dynamic
;
14892 end Install_Elaboration_Model
;
14894 -----------------------------
14895 -- Install_Generic_Formals --
14896 -----------------------------
14898 procedure Install_Generic_Formals
(Subp_Id
: Entity_Id
) is
14902 pragma Assert
(Is_Generic_Subprogram
(Subp_Id
));
14904 E
:= First_Entity
(Subp_Id
);
14905 while Present
(E
) loop
14906 Install_Entity
(E
);
14909 end Install_Generic_Formals
;
14911 ------------------------
14912 -- Install_SPARK_Mode --
14913 ------------------------
14915 procedure Install_SPARK_Mode
(Mode
: SPARK_Mode_Type
; Prag
: Node_Id
) is
14917 SPARK_Mode
:= Mode
;
14918 SPARK_Mode_Pragma
:= Prag
;
14919 end Install_SPARK_Mode
;
14921 --------------------------
14922 -- Invalid_Scalar_Value --
14923 --------------------------
14925 function Invalid_Scalar_Value
14927 Scal_Typ
: Scalar_Id
) return Node_Id
14929 function Invalid_Binder_Value
return Node_Id
;
14930 -- Return a reference to the corresponding invalid value for type
14931 -- Scal_Typ as defined in unit System.Scalar_Values.
14933 function Invalid_Float_Value
return Node_Id
;
14934 -- Return the invalid value of float type Scal_Typ
14936 function Invalid_Integer_Value
return Node_Id
;
14937 -- Return the invalid value of integer type Scal_Typ
14939 procedure Set_Invalid_Binder_Values
;
14940 -- Set the contents of collection Invalid_Binder_Values
14942 --------------------------
14943 -- Invalid_Binder_Value --
14944 --------------------------
14946 function Invalid_Binder_Value
return Node_Id
is
14947 Val_Id
: Entity_Id
;
14950 -- Initialize the collection of invalid binder values the first time
14953 Set_Invalid_Binder_Values
;
14955 -- Obtain the corresponding variable from System.Scalar_Values which
14956 -- holds the invalid value for this type.
14958 Val_Id
:= Invalid_Binder_Values
(Scal_Typ
);
14959 pragma Assert
(Present
(Val_Id
));
14961 return New_Occurrence_Of
(Val_Id
, Loc
);
14962 end Invalid_Binder_Value
;
14964 -------------------------
14965 -- Invalid_Float_Value --
14966 -------------------------
14968 function Invalid_Float_Value
return Node_Id
is
14969 Value
: constant Ureal
:= Invalid_Floats
(Scal_Typ
);
14972 -- Pragma Invalid_Scalars did not specify an invalid value for this
14973 -- type. Fall back to the value provided by the binder.
14975 if Value
= No_Ureal
then
14976 return Invalid_Binder_Value
;
14978 return Make_Real_Literal
(Loc
, Realval
=> Value
);
14980 end Invalid_Float_Value
;
14982 ---------------------------
14983 -- Invalid_Integer_Value --
14984 ---------------------------
14986 function Invalid_Integer_Value
return Node_Id
is
14987 Value
: constant Uint
:= Invalid_Integers
(Scal_Typ
);
14990 -- Pragma Invalid_Scalars did not specify an invalid value for this
14991 -- type. Fall back to the value provided by the binder.
14994 return Invalid_Binder_Value
;
14996 return Make_Integer_Literal
(Loc
, Intval
=> Value
);
14998 end Invalid_Integer_Value
;
15000 -------------------------------
15001 -- Set_Invalid_Binder_Values --
15002 -------------------------------
15004 procedure Set_Invalid_Binder_Values
is
15006 if not Invalid_Binder_Values_Set
then
15007 Invalid_Binder_Values_Set
:= True;
15009 -- Initialize the contents of the collection once since RTE calls
15012 Invalid_Binder_Values
:=
15013 (Name_Short_Float
=> RTE
(RE_IS_Isf
),
15014 Name_Float
=> RTE
(RE_IS_Ifl
),
15015 Name_Long_Float
=> RTE
(RE_IS_Ilf
),
15016 Name_Long_Long_Float
=> RTE
(RE_IS_Ill
),
15017 Name_Signed_8
=> RTE
(RE_IS_Is1
),
15018 Name_Signed_16
=> RTE
(RE_IS_Is2
),
15019 Name_Signed_32
=> RTE
(RE_IS_Is4
),
15020 Name_Signed_64
=> RTE
(RE_IS_Is8
),
15021 Name_Signed_128
=> Empty
,
15022 Name_Unsigned_8
=> RTE
(RE_IS_Iu1
),
15023 Name_Unsigned_16
=> RTE
(RE_IS_Iu2
),
15024 Name_Unsigned_32
=> RTE
(RE_IS_Iu4
),
15025 Name_Unsigned_64
=> RTE
(RE_IS_Iu8
),
15026 Name_Unsigned_128
=> Empty
);
15028 if System_Max_Integer_Size
< 128 then
15029 Invalid_Binder_Values
(Name_Signed_128
) := RTE
(RE_IS_Is8
);
15030 Invalid_Binder_Values
(Name_Unsigned_128
) := RTE
(RE_IS_Iu8
);
15032 Invalid_Binder_Values
(Name_Signed_128
) := RTE
(RE_IS_Is16
);
15033 Invalid_Binder_Values
(Name_Unsigned_128
) := RTE
(RE_IS_Iu16
);
15036 end Set_Invalid_Binder_Values
;
15038 -- Start of processing for Invalid_Scalar_Value
15041 if Scal_Typ
in Float_Scalar_Id
then
15042 return Invalid_Float_Value
;
15044 else pragma Assert
(Scal_Typ
in Integer_Scalar_Id
);
15045 return Invalid_Integer_Value
;
15047 end Invalid_Scalar_Value
;
15049 ------------------------
15050 -- Is_Access_Variable --
15051 ------------------------
15053 function Is_Access_Variable
(E
: Entity_Id
) return Boolean is
15055 return Is_Access_Type
(E
)
15056 and then not Is_Access_Constant
(E
)
15057 and then Ekind
(Directly_Designated_Type
(E
)) /= E_Subprogram_Type
;
15058 end Is_Access_Variable
;
15060 -----------------------------
15061 -- Is_Actual_Out_Parameter --
15062 -----------------------------
15064 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
15065 Formal
: Entity_Id
;
15068 Find_Actual
(N
, Formal
, Call
);
15069 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
15070 end Is_Actual_Out_Parameter
;
15072 --------------------------------
15073 -- Is_Actual_In_Out_Parameter --
15074 --------------------------------
15076 function Is_Actual_In_Out_Parameter
(N
: Node_Id
) return Boolean is
15077 Formal
: Entity_Id
;
15080 Find_Actual
(N
, Formal
, Call
);
15081 return Present
(Formal
) and then Ekind
(Formal
) = E_In_Out_Parameter
;
15082 end Is_Actual_In_Out_Parameter
;
15084 ---------------------------------------
15085 -- Is_Actual_Out_Or_In_Out_Parameter --
15086 ---------------------------------------
15088 function Is_Actual_Out_Or_In_Out_Parameter
(N
: Node_Id
) return Boolean is
15089 Formal
: Entity_Id
;
15092 Find_Actual
(N
, Formal
, Call
);
15093 return Present
(Formal
)
15094 and then Ekind
(Formal
) in E_Out_Parameter | E_In_Out_Parameter
;
15095 end Is_Actual_Out_Or_In_Out_Parameter
;
15097 -------------------------
15098 -- Is_Actual_Parameter --
15099 -------------------------
15101 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
15102 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
15106 when N_Parameter_Association
=>
15107 return N
= Explicit_Actual_Parameter
(Parent
(N
));
15109 when N_Entry_Call_Statement
15110 | N_Subprogram_Call
15112 return Is_List_Member
(N
)
15114 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
15119 end Is_Actual_Parameter
;
15121 ---------------------
15122 -- Is_Aliased_View --
15123 ---------------------
15125 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
15129 if Is_Entity_Name
(Obj
) then
15136 or else (Present
(Renamed_Object
(E
))
15137 and then Is_Aliased_View
(Renamed_Object
(E
)))))
15139 or else ((Is_Formal
(E
) or else Is_Formal_Object
(E
))
15140 and then Is_Tagged_Type
(Etype
(E
)))
15142 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
15144 -- Current instance of type, either directly or as rewritten
15145 -- reference to the current object.
15147 or else (Is_Entity_Name
(Original_Node
(Obj
))
15148 and then Present
(Entity
(Original_Node
(Obj
)))
15149 and then Is_Type
(Entity
(Original_Node
(Obj
))))
15151 or else (Is_Type
(E
) and then E
= Current_Scope
)
15153 or else (Is_Incomplete_Or_Private_Type
(E
)
15154 and then Full_View
(E
) = Current_Scope
)
15156 -- Ada 2012 AI05-0053: the return object of an extended return
15157 -- statement is aliased if its type is immutably limited.
15159 or else (Is_Return_Object
(E
)
15160 and then Is_Inherently_Limited_Type
(Etype
(E
)))
15162 -- The current instance of a limited type is aliased, so
15163 -- we want to allow uses of T'Access in the init proc for
15164 -- a limited type T. However, we don't want to mark the formal
15165 -- parameter as being aliased since that could impact callers.
15167 or else (Is_Formal
(E
)
15168 and then Chars
(E
) = Name_uInit
15169 and then Is_Inherently_Limited_Type
(Etype
(E
)));
15171 elsif Nkind
(Obj
) = N_Selected_Component
then
15172 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
15174 elsif Nkind
(Obj
) = N_Indexed_Component
then
15175 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
15177 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
15178 and then Has_Aliased_Components
15179 (Designated_Type
(Etype
(Prefix
(Obj
)))));
15181 elsif Nkind
(Obj
) in N_Unchecked_Type_Conversion | N_Type_Conversion
then
15182 return Is_Tagged_Type
(Etype
(Obj
))
15183 and then Is_Aliased_View
(Expression
(Obj
));
15185 -- Ada 2022 AI12-0228
15187 elsif Nkind
(Obj
) = N_Qualified_Expression
15188 and then Ada_Version
>= Ada_2012
15190 return Is_Aliased_View
(Expression
(Obj
));
15192 -- The dereference of an access-to-object value denotes an aliased view,
15193 -- but this routine uses the rules of the language so we need to exclude
15194 -- rewritten constructs that introduce artificial dereferences.
15196 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
15197 return not Is_Captured_Function_Call
(Obj
)
15199 (Nkind
(Parent
(Obj
)) = N_Object_Renaming_Declaration
15200 and then Is_Return_Object
(Defining_Entity
(Parent
(Obj
))));
15205 end Is_Aliased_View
;
15207 -------------------------
15208 -- Is_Ancestor_Package --
15209 -------------------------
15211 function Is_Ancestor_Package
15213 E2
: Entity_Id
) return Boolean
15219 while Present
(Par
) and then Par
/= Standard_Standard
loop
15224 Par
:= Scope
(Par
);
15228 end Is_Ancestor_Package
;
15230 ----------------------
15231 -- Is_Atomic_Object --
15232 ----------------------
15234 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
15235 function Prefix_Has_Atomic_Components
(P
: Node_Id
) return Boolean;
15236 -- Determine whether prefix P has atomic components. This requires the
15237 -- presence of an Atomic_Components aspect/pragma.
15239 ---------------------------------
15240 -- Prefix_Has_Atomic_Components --
15241 ---------------------------------
15243 function Prefix_Has_Atomic_Components
(P
: Node_Id
) return Boolean is
15244 Typ
: constant Entity_Id
:= Etype
(P
);
15247 if Is_Access_Type
(Typ
) then
15248 return Has_Atomic_Components
(Designated_Type
(Typ
));
15250 elsif Has_Atomic_Components
(Typ
) then
15253 elsif Is_Entity_Name
(P
)
15254 and then Has_Atomic_Components
(Entity
(P
))
15261 end Prefix_Has_Atomic_Components
;
15263 -- Start of processing for Is_Atomic_Object
15266 if Is_Entity_Name
(N
) then
15267 return Is_Atomic_Object_Entity
(Entity
(N
));
15269 elsif Is_Atomic
(Etype
(N
)) then
15272 elsif Nkind
(N
) = N_Indexed_Component
then
15273 return Prefix_Has_Atomic_Components
(Prefix
(N
));
15275 elsif Nkind
(N
) = N_Selected_Component
then
15276 return Is_Atomic
(Entity
(Selector_Name
(N
)));
15281 end Is_Atomic_Object
;
15283 -----------------------------
15284 -- Is_Atomic_Object_Entity --
15285 -----------------------------
15287 function Is_Atomic_Object_Entity
(Id
: Entity_Id
) return Boolean is
15291 and then (Is_Atomic
(Id
) or else Is_Atomic
(Etype
(Id
)));
15292 end Is_Atomic_Object_Entity
;
15294 -----------------------------
15295 -- Is_Attribute_Loop_Entry --
15296 -----------------------------
15298 function Is_Attribute_Loop_Entry
(N
: Node_Id
) return Boolean is
15300 return Nkind
(N
) = N_Attribute_Reference
15301 and then Attribute_Name
(N
) = Name_Loop_Entry
;
15302 end Is_Attribute_Loop_Entry
;
15304 ----------------------
15305 -- Is_Attribute_Old --
15306 ----------------------
15308 function Is_Attribute_Old
(N
: Node_Id
) return Boolean is
15310 return Nkind
(N
) = N_Attribute_Reference
15311 and then Attribute_Name
(N
) = Name_Old
;
15312 end Is_Attribute_Old
;
15314 -------------------------
15315 -- Is_Attribute_Result --
15316 -------------------------
15318 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
15320 return Nkind
(N
) = N_Attribute_Reference
15321 and then Attribute_Name
(N
) = Name_Result
;
15322 end Is_Attribute_Result
;
15324 -------------------------
15325 -- Is_Attribute_Update --
15326 -------------------------
15328 function Is_Attribute_Update
(N
: Node_Id
) return Boolean is
15330 return Nkind
(N
) = N_Attribute_Reference
15331 and then Attribute_Name
(N
) = Name_Update
;
15332 end Is_Attribute_Update
;
15334 ------------------------------------
15335 -- Is_Body_Or_Package_Declaration --
15336 ------------------------------------
15338 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
15340 return Is_Body
(N
) or else Nkind
(N
) = N_Package_Declaration
;
15341 end Is_Body_Or_Package_Declaration
;
15343 -----------------------
15344 -- Is_Bounded_String --
15345 -----------------------
15347 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
15348 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
15351 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
15352 -- Super_String, or one of the [Wide_]Wide_ versions. This will
15353 -- be True for all the Bounded_String types in instances of the
15354 -- Generic_Bounded_Length generics, and for types derived from those.
15356 return Present
(Under
)
15357 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
15358 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
15359 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
15360 end Is_Bounded_String
;
15362 -------------------------------
15363 -- Is_By_Protected_Procedure --
15364 -------------------------------
15366 function Is_By_Protected_Procedure
(Id
: Entity_Id
) return Boolean is
15368 return Ekind
(Id
) = E_Procedure
15369 and then Present
(Get_Rep_Pragma
(Id
, Name_Implemented
))
15370 and then Implementation_Kind
(Id
) = Name_By_Protected_Procedure
;
15371 end Is_By_Protected_Procedure
;
15373 ---------------------
15374 -- Is_CCT_Instance --
15375 ---------------------
15377 function Is_CCT_Instance
15378 (Ref_Id
: Entity_Id
;
15379 Context_Id
: Entity_Id
) return Boolean
15382 pragma Assert
(Ekind
(Ref_Id
) in E_Protected_Type | E_Task_Type
);
15384 if Is_Single_Task_Object
(Context_Id
) then
15385 return Scope_Within_Or_Same
(Etype
(Context_Id
), Ref_Id
);
15389 (Ekind
(Context_Id
) in
15390 E_Entry | E_Entry_Family | E_Function | E_Package |
15391 E_Procedure | E_Protected_Type | E_Task_Type
15392 or else Is_Record_Type
(Context_Id
));
15393 return Scope_Within_Or_Same
(Context_Id
, Ref_Id
);
15395 end Is_CCT_Instance
;
15397 -------------------------
15398 -- Is_Child_Or_Sibling --
15399 -------------------------
15401 function Is_Child_Or_Sibling
15402 (Pack_1
: Entity_Id
;
15403 Pack_2
: Entity_Id
) return Boolean
15405 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
15406 -- Given an arbitrary package, return the number of "climbs" necessary
15407 -- to reach scope Standard_Standard.
15409 procedure Equalize_Depths
15410 (Pack
: in out Entity_Id
;
15411 Depth
: in out Nat
;
15412 Depth_To_Reach
: Nat
);
15413 -- Given an arbitrary package, its depth and a target depth to reach,
15414 -- climb the scope chain until the said depth is reached. The pointer
15415 -- to the package and its depth a modified during the climb.
15417 ----------------------------
15418 -- Distance_From_Standard --
15419 ----------------------------
15421 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
15428 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
15430 Scop
:= Scope
(Scop
);
15434 end Distance_From_Standard
;
15436 ---------------------
15437 -- Equalize_Depths --
15438 ---------------------
15440 procedure Equalize_Depths
15441 (Pack
: in out Entity_Id
;
15442 Depth
: in out Nat
;
15443 Depth_To_Reach
: Nat
)
15446 -- The package must be at a greater or equal depth
15448 if Depth
< Depth_To_Reach
then
15449 raise Program_Error
;
15452 -- Climb the scope chain until the desired depth is reached
15454 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
15455 Pack
:= Scope
(Pack
);
15456 Depth
:= Depth
- 1;
15458 end Equalize_Depths
;
15462 P_1
: Entity_Id
:= Pack_1
;
15463 P_1_Child
: Boolean := False;
15464 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
15465 P_2
: Entity_Id
:= Pack_2
;
15466 P_2_Child
: Boolean := False;
15467 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
15469 -- Start of processing for Is_Child_Or_Sibling
15473 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
15475 -- Both packages denote the same entity, therefore they cannot be
15476 -- children or siblings.
15481 -- One of the packages is at a deeper level than the other. Note that
15482 -- both may still come from different hierarchies.
15490 elsif P_1_Depth
> P_2_Depth
then
15493 Depth
=> P_1_Depth
,
15494 Depth_To_Reach
=> P_2_Depth
);
15503 elsif P_2_Depth
> P_1_Depth
then
15506 Depth
=> P_2_Depth
,
15507 Depth_To_Reach
=> P_1_Depth
);
15511 -- At this stage the package pointers have been elevated to the same
15512 -- depth. If the related entities are the same, then one package is a
15513 -- potential child of the other:
15517 -- X became P_1 P_2 or vice versa
15523 return Is_Child_Unit
(Pack_1
);
15525 else pragma Assert
(P_2_Child
);
15526 return Is_Child_Unit
(Pack_2
);
15529 -- The packages may come from the same package chain or from entirely
15530 -- different hierarchies. To determine this, climb the scope stack until
15531 -- a common root is found.
15533 -- (root) (root 1) (root 2)
15538 while Present
(P_1
) and then Present
(P_2
) loop
15540 -- The two packages may be siblings
15543 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
15546 P_1
:= Scope
(P_1
);
15547 P_2
:= Scope
(P_2
);
15552 end Is_Child_Or_Sibling
;
15554 -------------------
15555 -- Is_Confirming --
15556 -------------------
15558 function Is_Confirming
(Aspect
: Nonoverridable_Aspect_Id
;
15559 Aspect_Spec_1
, Aspect_Spec_2
: Node_Id
)
15561 function Names_Match
(Nm1
, Nm2
: Node_Id
) return Boolean;
15567 function Names_Match
(Nm1
, Nm2
: Node_Id
) return Boolean is
15569 if Nkind
(Nm1
) /= Nkind
(Nm2
) then
15571 -- This may be too restrictive given that visibility
15572 -- may allow an identifier in one case and an expanded
15573 -- name in the other.
15575 case Nkind
(Nm1
) is
15576 when N_Identifier
=>
15577 return Name_Equals
(Chars
(Nm1
), Chars
(Nm2
));
15579 when N_Expanded_Name
=>
15580 -- An inherited operation has the same name as its
15581 -- ancestor, but they may have different scopes.
15582 -- This may be too permissive for Iterator_Element, which
15583 -- is intended to be identical in parent and derived type.
15585 return Names_Match
(Selector_Name
(Nm1
),
15586 Selector_Name
(Nm2
));
15589 return True; -- needed for Aggregate aspect checking
15592 -- e.g., 'Class attribute references
15593 if Is_Entity_Name
(Nm1
) and Is_Entity_Name
(Nm2
) then
15594 return Entity
(Nm1
) = Entity
(Nm2
);
15597 raise Program_Error
;
15601 -- allow users to disable "shall be confirming" check, at least for now
15602 if Relaxed_RM_Semantics
then
15606 -- ??? Type conversion here (along with "when others =>" below) is a
15607 -- workaround for a bootstrapping problem related to casing on a
15608 -- static-predicate-bearing subtype.
15610 case Aspect_Id
(Aspect
) is
15611 -- name-valued aspects; compare text of names, not resolution.
15612 when Aspect_Default_Iterator
15613 | Aspect_Iterator_Element
15614 | Aspect_Constant_Indexing
15615 | Aspect_Variable_Indexing
=>
15617 Item_1
: constant Node_Id
:= Aspect_Rep_Item
(Aspect_Spec_1
);
15618 Item_2
: constant Node_Id
:= Aspect_Rep_Item
(Aspect_Spec_2
);
15620 if Nkind
(Item_1
) /= N_Attribute_Definition_Clause
15621 or Nkind
(Item_2
) /= N_Attribute_Definition_Clause
15623 pragma Assert
(Serious_Errors_Detected
> 0);
15627 return Names_Match
(Expression
(Item_1
),
15628 Expression
(Item_2
));
15631 -- A confirming aspect for Implicit_Derenfence on a derived type
15632 -- has already been checked in Analyze_Aspect_Implicit_Dereference,
15633 -- including the presence of renamed discriminants.
15635 when Aspect_Implicit_Dereference
=>
15639 when Aspect_Aggregate
=>
15650 Assign_Indexed_2
: Node_Id
:= Empty
;
15652 Parse_Aspect_Aggregate
15653 (N
=> Expression
(Aspect_Spec_1
),
15654 Empty_Subp
=> Empty_1
,
15655 Add_Named_Subp
=> Add_Named_1
,
15656 Add_Unnamed_Subp
=> Add_Unnamed_1
,
15657 New_Indexed_Subp
=> New_Indexed_1
,
15658 Assign_Indexed_Subp
=> Assign_Indexed_1
);
15659 Parse_Aspect_Aggregate
15660 (N
=> Expression
(Aspect_Spec_2
),
15661 Empty_Subp
=> Empty_2
,
15662 Add_Named_Subp
=> Add_Named_2
,
15663 Add_Unnamed_Subp
=> Add_Unnamed_2
,
15664 New_Indexed_Subp
=> New_Indexed_2
,
15665 Assign_Indexed_Subp
=> Assign_Indexed_2
);
15667 Names_Match
(Empty_1
, Empty_2
) and then
15668 Names_Match
(Add_Named_1
, Add_Named_2
) and then
15669 Names_Match
(Add_Unnamed_1
, Add_Unnamed_2
) and then
15670 Names_Match
(New_Indexed_1
, New_Indexed_2
) and then
15671 Names_Match
(Assign_Indexed_1
, Assign_Indexed_2
);
15674 -- Checking for this aspect is performed elsewhere during freezing
15675 when Aspect_No_Controlled_Parts
=>
15678 -- scalar-valued aspects; compare (static) values.
15679 when Aspect_Max_Entry_Queue_Length
=>
15680 -- This should be unreachable. Max_Entry_Queue_Length is
15681 -- supported only for protected entries, not for types.
15682 pragma Assert
(Serious_Errors_Detected
/= 0);
15686 raise Program_Error
;
15690 -----------------------------
15691 -- Is_Concurrent_Interface --
15692 -----------------------------
15694 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
15696 return Is_Protected_Interface
(T
)
15697 or else Is_Synchronized_Interface
(T
)
15698 or else Is_Task_Interface
(T
);
15699 end Is_Concurrent_Interface
;
15701 ------------------------------------------------------
15702 -- Is_Conjunction_Of_Formal_Preelab_Init_Attributes --
15703 ------------------------------------------------------
15705 function Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15706 (Expr
: Node_Id
) return Boolean
15709 function Is_Formal_Preelab_Init_Attribute
15710 (N
: Node_Id
) return Boolean;
15711 -- Returns True if N is a Preelaborable_Initialization attribute
15712 -- applied to a generic formal type, or N's Original_Node is such
15715 --------------------------------------
15716 -- Is_Formal_Preelab_Init_Attribute --
15717 --------------------------------------
15719 function Is_Formal_Preelab_Init_Attribute
15720 (N
: Node_Id
) return Boolean
15722 Orig_N
: constant Node_Id
:= Original_Node
(N
);
15725 return Nkind
(Orig_N
) = N_Attribute_Reference
15726 and then Attribute_Name
(Orig_N
) = Name_Preelaborable_Initialization
15727 and then Is_Entity_Name
(Prefix
(Orig_N
))
15728 and then Is_Generic_Type
(Entity
(Prefix
(Orig_N
)));
15729 end Is_Formal_Preelab_Init_Attribute
;
15731 -- Start of Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15734 return Is_Formal_Preelab_Init_Attribute
(Expr
)
15735 or else (Nkind
(Expr
) = N_Op_And
15737 Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15740 Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15741 (Right_Opnd
(Expr
)));
15742 end Is_Conjunction_Of_Formal_Preelab_Init_Attributes
;
15744 -----------------------
15745 -- Is_Constant_Bound --
15746 -----------------------
15748 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
15750 if Compile_Time_Known_Value
(Exp
) then
15753 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
15754 return Is_Constant_Object
(Entity
(Exp
))
15755 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
15757 elsif Nkind
(Exp
) in N_Binary_Op
then
15758 return Is_Constant_Bound
(Left_Opnd
(Exp
))
15759 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
15760 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
15765 end Is_Constant_Bound
;
15767 ---------------------------
15768 -- Is_Container_Element --
15769 ---------------------------
15771 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
15772 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
15773 Pref
: constant Node_Id
:= Prefix
(Exp
);
15776 -- Call to an indexing aspect
15778 Cont_Typ
: Entity_Id
;
15779 -- The type of the container being accessed
15781 Elem_Typ
: Entity_Id
;
15782 -- Its element type
15784 Indexing
: Entity_Id
;
15785 Is_Const
: Boolean;
15786 -- Indicates that constant indexing is used, and the element is thus
15789 Ref_Typ
: Entity_Id
;
15790 -- The reference type returned by the indexing operation
15793 -- If C is a container, in a context that imposes the element type of
15794 -- that container, the indexing notation C (X) is rewritten as:
15796 -- Indexing (C, X).Discr.all
15798 -- where Indexing is one of the indexing aspects of the container.
15799 -- If the context does not require a reference, the construct can be
15804 -- First, verify that the construct has the proper form
15806 if not Expander_Active
then
15809 elsif Nkind
(Pref
) /= N_Selected_Component
then
15812 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
15816 Call
:= Prefix
(Pref
);
15817 Ref_Typ
:= Etype
(Call
);
15820 if not Has_Implicit_Dereference
(Ref_Typ
)
15821 or else No
(First
(Parameter_Associations
(Call
)))
15822 or else not Is_Entity_Name
(Name
(Call
))
15827 -- Retrieve type of container object, and its iterator aspects
15829 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
15830 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
15833 if No
(Indexing
) then
15835 -- Container should have at least one indexing operation
15839 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
15841 -- This may be a variable indexing operation
15843 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
15846 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
15855 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
15857 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
15861 -- Check that the expression is not the target of an assignment, in
15862 -- which case the rewriting is not possible.
15864 if not Is_Const
then
15870 while Present
(Par
)
15872 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
15873 and then Par
= Name
(Parent
(Par
))
15877 -- A renaming produces a reference, and the transformation
15880 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
15883 elsif Nkind
(Parent
(Par
)) in
15885 N_Procedure_Call_Statement |
15886 N_Entry_Call_Statement
15888 -- Check that the element is not part of an actual for an
15889 -- in-out parameter.
15896 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
15897 A
:= First
(Parameter_Associations
(Parent
(Par
)));
15898 while Present
(F
) loop
15899 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
15908 -- E_In_Parameter in a call: element is not modified.
15913 Par
:= Parent
(Par
);
15918 -- The expression has the proper form and the context requires the
15919 -- element type. Retrieve the Element function of the container and
15920 -- rewrite the construct as a call to it.
15926 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
15927 while Present
(Op
) loop
15928 exit when Chars
(Node
(Op
)) = Name_Element
;
15937 Make_Function_Call
(Loc
,
15938 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
15939 Parameter_Associations
=> Parameter_Associations
(Call
)));
15940 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
15944 end Is_Container_Element
;
15946 ----------------------------
15947 -- Is_Contract_Annotation --
15948 ----------------------------
15950 function Is_Contract_Annotation
(Item
: Node_Id
) return Boolean is
15952 return Is_Package_Contract_Annotation
(Item
)
15954 Is_Subprogram_Contract_Annotation
(Item
);
15955 end Is_Contract_Annotation
;
15957 --------------------------------------
15958 -- Is_Controlling_Limited_Procedure --
15959 --------------------------------------
15961 function Is_Controlling_Limited_Procedure
15962 (Proc_Nam
: Entity_Id
) return Boolean
15965 Param_Typ
: Entity_Id
:= Empty
;
15968 if Ekind
(Proc_Nam
) = E_Procedure
15969 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
15973 (First
(Parameter_Specifications
(Parent
(Proc_Nam
))));
15975 -- The formal may be an anonymous access type
15977 if Nkind
(Param
) = N_Access_Definition
then
15978 Param_Typ
:= Entity
(Subtype_Mark
(Param
));
15980 Param_Typ
:= Etype
(Param
);
15983 -- In the case where an Itype was created for a dispatchin call, the
15984 -- procedure call has been rewritten. The actual may be an access to
15985 -- interface type in which case it is the designated type that is the
15986 -- controlling type.
15988 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
15989 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
15991 Present
(Parameter_Associations
15992 (Associated_Node_For_Itype
(Proc_Nam
)))
15995 Etype
(First
(Parameter_Associations
15996 (Associated_Node_For_Itype
(Proc_Nam
))));
15998 if Ekind
(Param_Typ
) = E_Anonymous_Access_Type
then
15999 Param_Typ
:= Directly_Designated_Type
(Param_Typ
);
16003 if Present
(Param_Typ
) then
16005 Is_Interface
(Param_Typ
)
16006 and then Is_Limited_Record
(Param_Typ
);
16010 end Is_Controlling_Limited_Procedure
;
16012 -----------------------------
16013 -- Is_CPP_Constructor_Call --
16014 -----------------------------
16016 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
16017 Ret_Typ
: Entity_Id
;
16020 if Nkind
(N
) /= N_Function_Call
then
16024 Ret_Typ
:= Base_Type
(Etype
(N
));
16026 if Is_Class_Wide_Type
(Ret_Typ
) then
16027 Ret_Typ
:= Root_Type
(Ret_Typ
);
16030 if Is_Private_Type
(Ret_Typ
) then
16031 Ret_Typ
:= Underlying_Type
(Ret_Typ
);
16034 return Present
(Ret_Typ
)
16035 and then Is_CPP_Class
(Ret_Typ
)
16036 and then Is_Constructor
(Entity
(Name
(N
)))
16037 and then Is_Imported
(Entity
(Name
(N
)));
16038 end Is_CPP_Constructor_Call
;
16040 -------------------------
16041 -- Is_Current_Instance --
16042 -------------------------
16044 function Is_Current_Instance
(N
: Node_Id
) return Boolean is
16045 Typ
: constant Entity_Id
:= Entity
(N
);
16049 -- Simplest case: entity is a concurrent type and we are currently
16050 -- inside the body. This will eventually be expanded into a call to
16051 -- Self (for tasks) or _object (for protected objects).
16053 if Is_Concurrent_Type
(Typ
) and then In_Open_Scopes
(Typ
) then
16057 -- Check whether the context is a (sub)type declaration for the
16061 while Present
(P
) loop
16062 if Nkind
(P
) in N_Full_Type_Declaration
16063 | N_Private_Type_Declaration
16064 | N_Subtype_Declaration
16065 and then Comes_From_Source
(P
)
16067 -- If the type has a previous incomplete declaration, the
16068 -- reference in the type definition may have the incomplete
16069 -- view. So, here we detect if this incomplete view is a current
16070 -- instance by checking if its full view is the entity of the
16071 -- full declaration begin analyzed.
16074 (Defining_Entity
(P
) = Typ
16076 (Ekind
(Typ
) = E_Incomplete_Type
16077 and then Full_View
(Typ
) = Defining_Entity
(P
)))
16081 -- A subtype name may appear in an aspect specification for a
16082 -- Predicate_Failure aspect, for which we do not construct a
16083 -- wrapper procedure. The subtype will be replaced by the
16084 -- expression being tested when the corresponding predicate
16085 -- check is expanded. It may also appear in the pragma Predicate
16086 -- expression during legality checking.
16088 elsif Nkind
(P
) = N_Aspect_Specification
16089 and then Nkind
(Parent
(P
)) = N_Subtype_Declaration
16090 and then Underlying_Type
(Defining_Identifier
(Parent
(P
))) =
16091 Underlying_Type
(Typ
)
16095 elsif Nkind
(P
) = N_Pragma
16096 and then Get_Pragma_Id
(P
) in Pragma_Predicate
16097 | Pragma_Predicate_Failure
16100 Arg
: constant Entity_Id
:=
16101 Entity
(Expression
(Get_Argument
(P
)));
16103 if Underlying_Type
(Arg
) = Underlying_Type
(Typ
) then
16113 -- In any other context this is not a current occurrence
16116 end Is_Current_Instance
;
16118 --------------------------------------------------
16119 -- Is_Current_Instance_Reference_In_Type_Aspect --
16120 --------------------------------------------------
16122 function Is_Current_Instance_Reference_In_Type_Aspect
16123 (N
: Node_Id
) return Boolean
16126 -- When a current_instance is referenced within an aspect_specification
16127 -- of a type or subtype, it will show up as a reference to the formal
16128 -- parameter of the aspect's associated subprogram rather than as a
16129 -- reference to the type or subtype itself (in fact, the original name
16130 -- is never even analyzed). We check for predicate, invariant, and
16131 -- Default_Initial_Condition subprograms (in theory there could be
16132 -- other cases added, in which case this function will need updating).
16134 if Is_Entity_Name
(N
) then
16135 return Present
(Entity
(N
))
16136 and then Ekind
(Entity
(N
)) = E_In_Parameter
16137 and then Ekind
(Scope
(Entity
(N
))) in E_Function | E_Procedure
16139 (Is_Predicate_Function
(Scope
(Entity
(N
)))
16140 or else Is_Invariant_Procedure
(Scope
(Entity
(N
)))
16141 or else Is_Partial_Invariant_Procedure
(Scope
(Entity
(N
)))
16142 or else Is_DIC_Procedure
(Scope
(Entity
(N
))));
16146 when N_Indexed_Component
16150 Is_Current_Instance_Reference_In_Type_Aspect
(Prefix
(N
));
16152 when N_Selected_Component
=>
16154 Is_Current_Instance_Reference_In_Type_Aspect
(Prefix
(N
));
16156 when N_Type_Conversion
=>
16157 return Is_Current_Instance_Reference_In_Type_Aspect
16160 when N_Qualified_Expression
=>
16161 return Is_Current_Instance_Reference_In_Type_Aspect
16168 end Is_Current_Instance_Reference_In_Type_Aspect
;
16170 --------------------
16171 -- Is_Declaration --
16172 --------------------
16174 function Is_Declaration
16176 Body_OK
: Boolean := True;
16177 Concurrent_OK
: Boolean := True;
16178 Formal_OK
: Boolean := True;
16179 Generic_OK
: Boolean := True;
16180 Instantiation_OK
: Boolean := True;
16181 Renaming_OK
: Boolean := True;
16182 Stub_OK
: Boolean := True;
16183 Subprogram_OK
: Boolean := True;
16184 Type_OK
: Boolean := True) return Boolean
16189 -- Body declarations
16191 when N_Proper_Body
=>
16194 -- Concurrent type declarations
16196 when N_Protected_Type_Declaration
16197 | N_Single_Protected_Declaration
16198 | N_Single_Task_Declaration
16199 | N_Task_Type_Declaration
16201 return Concurrent_OK
or Type_OK
;
16203 -- Formal declarations
16205 when N_Formal_Abstract_Subprogram_Declaration
16206 | N_Formal_Concrete_Subprogram_Declaration
16207 | N_Formal_Object_Declaration
16208 | N_Formal_Package_Declaration
16209 | N_Formal_Type_Declaration
16213 -- Generic declarations
16215 when N_Generic_Package_Declaration
16216 | N_Generic_Subprogram_Declaration
16220 -- Generic instantiations
16222 when N_Function_Instantiation
16223 | N_Package_Instantiation
16224 | N_Procedure_Instantiation
16226 return Instantiation_OK
;
16228 -- Generic renaming declarations
16230 when N_Generic_Renaming_Declaration
=>
16231 return Generic_OK
or Renaming_OK
;
16233 -- Renaming declarations
16235 when N_Exception_Renaming_Declaration
16236 | N_Object_Renaming_Declaration
16237 | N_Package_Renaming_Declaration
16238 | N_Subprogram_Renaming_Declaration
16240 return Renaming_OK
;
16242 -- Stub declarations
16244 when N_Body_Stub
=>
16247 -- Subprogram declarations
16249 when N_Abstract_Subprogram_Declaration
16250 | N_Entry_Declaration
16251 | N_Expression_Function
16252 | N_Subprogram_Declaration
16254 return Subprogram_OK
;
16256 -- Type declarations
16258 when N_Full_Type_Declaration
16259 | N_Incomplete_Type_Declaration
16260 | N_Private_Extension_Declaration
16261 | N_Private_Type_Declaration
16262 | N_Subtype_Declaration
16268 when N_Component_Declaration
16269 | N_Exception_Declaration
16270 | N_Implicit_Label_Declaration
16271 | N_Number_Declaration
16272 | N_Object_Declaration
16273 | N_Package_Declaration
16280 end Is_Declaration
;
16282 --------------------------------
16283 -- Is_Declared_Within_Variant --
16284 --------------------------------
16286 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
16287 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
16288 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
16290 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
16291 end Is_Declared_Within_Variant
;
16293 ----------------------------------------------
16294 -- Is_Dependent_Component_Of_Mutable_Object --
16295 ----------------------------------------------
16297 function Is_Dependent_Component_Of_Mutable_Object
16298 (Object
: Node_Id
) return Boolean
16301 Prefix_Type
: Entity_Id
;
16302 P_Aliased
: Boolean := False;
16305 Deref
: Node_Id
:= Original_Node
(Object
);
16306 -- Dereference node, in something like X.all.Y(2)
16308 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
16311 -- Find the dereference node if any
16313 while Nkind
(Deref
) in
16314 N_Indexed_Component | N_Selected_Component | N_Slice
16316 Deref
:= Original_Node
(Prefix
(Deref
));
16319 -- If the prefix is a qualified expression of a variable, then function
16320 -- Is_Variable will return False for that because a qualified expression
16321 -- denotes a constant view, so we need to get the name being qualified
16322 -- so we can test below whether that's a variable (or a dereference).
16324 if Nkind
(Deref
) = N_Qualified_Expression
then
16325 Deref
:= Expression
(Deref
);
16328 -- Ada 2005: If we have a component or slice of a dereference, something
16329 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
16330 -- will return False, because it is indeed a constant view. But it might
16331 -- be a view of a variable object, so we want the following condition to
16332 -- be True in that case.
16334 if Is_Variable
(Object
)
16335 or else Is_Variable
(Deref
)
16337 (Ada_Version
>= Ada_2005
16338 and then (Nkind
(Deref
) = N_Explicit_Dereference
16339 or else (Present
(Etype
(Deref
))
16340 and then Is_Access_Type
(Etype
(Deref
)))))
16342 if Nkind
(Object
) = N_Selected_Component
then
16344 -- If the selector is not a component, then we definitely return
16345 -- False (it could be a function selector in a prefix form call
16346 -- occurring in an iterator specification).
16348 if (Present
(Entity
(Selector_Name
(Object
)))
16349 and then Ekind
(Entity
(Selector_Name
(Object
))) not in
16350 E_Component | E_Discriminant
)
16353 and then Nkind
(Parent
(Selector_Name
(Object
)))
16359 -- Get the original node of the prefix in case it has been
16360 -- rewritten, which can occur, for example, in qualified
16361 -- expression cases. Also, a discriminant check on a selected
16362 -- component may be expanded into a dereference when removing
16363 -- side effects, and the subtype of the original node may be
16366 P
:= Original_Node
(Prefix
(Object
));
16367 Prefix_Type
:= Etype
(P
);
16369 -- If the prefix is a qualified expression, we want to look at its
16372 if Nkind
(P
) = N_Qualified_Expression
then
16373 P
:= Expression
(P
);
16374 Prefix_Type
:= Etype
(P
);
16377 if Is_Entity_Name
(P
) then
16378 -- The Etype may not be set on P (which is wrong) in certain
16379 -- corner cases involving the deprecated front-end inlining of
16380 -- subprograms (via -gnatN), so use the Etype set on the
16381 -- the entity for these instances since we know it is present.
16383 if No
(Prefix_Type
) then
16384 Prefix_Type
:= Etype
(Entity
(P
));
16387 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
16388 Prefix_Type
:= Base_Type
(Prefix_Type
);
16391 if Is_Aliased
(Entity
(P
)) then
16395 -- For explicit dereferences we get the access prefix so we can
16396 -- treat this similarly to implicit dereferences and examine the
16397 -- kind of the access type and its designated subtype further
16400 elsif Nkind
(P
) = N_Explicit_Dereference
then
16402 Prefix_Type
:= Etype
(P
);
16405 -- Check for prefix being an aliased component???
16410 -- A heap object is constrained by its initial value
16412 -- Ada 2005 (AI-363): Always assume the object could be mutable in
16413 -- the dereferenced case, since the access value might denote an
16414 -- unconstrained aliased object, whereas in Ada 95 the designated
16415 -- object is guaranteed to be constrained. A worst-case assumption
16416 -- has to apply in Ada 2005 because we can't tell at compile
16417 -- time whether the object is "constrained by its initial value",
16418 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
16419 -- rules (these rules are acknowledged to need fixing). We don't
16420 -- impose this more stringent checking for earlier Ada versions or
16421 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
16422 -- benefit, though it's unclear on why using -gnat95 would not be
16425 if Ada_Version
< Ada_2005
or else Relaxed_RM_Semantics
then
16426 if Is_Access_Type
(Prefix_Type
)
16427 or else Nkind
(P
) = N_Explicit_Dereference
16432 else pragma Assert
(Ada_Version
>= Ada_2005
);
16433 if Is_Access_Type
(Prefix_Type
) then
16434 -- We need to make sure we have the base subtype, in case
16435 -- this is actually an access subtype (whose Ekind will be
16436 -- E_Access_Subtype).
16438 Prefix_Type
:= Etype
(Prefix_Type
);
16440 -- If the access type is pool-specific, and there is no
16441 -- constrained partial view of the designated type, then the
16442 -- designated object is known to be constrained. If it's a
16443 -- formal access type and the renaming is in the generic
16444 -- spec, we also treat it as pool-specific (known to be
16445 -- constrained), but assume the worst if in the generic body
16446 -- (see RM 3.3(23.3/3)).
16448 if Ekind
(Prefix_Type
) = E_Access_Type
16449 and then (not Is_Generic_Type
(Prefix_Type
)
16450 or else not In_Generic_Body
(Current_Scope
))
16451 and then not Object_Type_Has_Constrained_Partial_View
16452 (Typ
=> Designated_Type
(Prefix_Type
),
16453 Scop
=> Current_Scope
)
16457 -- Otherwise (general access type, or there is a constrained
16458 -- partial view of the designated type), we need to check
16459 -- based on the designated type.
16462 Prefix_Type
:= Designated_Type
(Prefix_Type
);
16468 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
16470 -- As per AI-0017, the renaming is illegal in a generic body, even
16471 -- if the subtype is indefinite (only applies to prefixes of an
16472 -- untagged formal type, see RM 3.3 (23.11/3)).
16474 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
16476 if not Is_Constrained
(Prefix_Type
)
16477 and then (Is_Definite_Subtype
(Prefix_Type
)
16479 (not Is_Tagged_Type
(Prefix_Type
)
16480 and then Is_Generic_Type
(Prefix_Type
)
16481 and then In_Generic_Body
(Current_Scope
)))
16483 and then (Is_Declared_Within_Variant
(Comp
)
16484 or else Has_Discriminant_Dependent_Constraint
(Comp
))
16485 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
16489 -- If the prefix is of an access type at this point, then we want
16490 -- to return False, rather than calling this function recursively
16491 -- on the access object (which itself might be a discriminant-
16492 -- dependent component of some other object, but that isn't
16493 -- relevant to checking the object passed to us). This avoids
16494 -- issuing wrong errors when compiling with -gnatc, where there
16495 -- can be implicit dereferences that have not been expanded.
16497 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
16502 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
16505 elsif Nkind
(Object
) = N_Indexed_Component
16506 or else Nkind
(Object
) = N_Slice
16508 return Is_Dependent_Component_Of_Mutable_Object
16509 (Original_Node
(Prefix
(Object
)));
16511 -- A type conversion that Is_Variable is a view conversion:
16512 -- go back to the denoted object.
16514 elsif Nkind
(Object
) = N_Type_Conversion
then
16516 Is_Dependent_Component_Of_Mutable_Object
16517 (Original_Node
(Expression
(Object
)));
16522 end Is_Dependent_Component_Of_Mutable_Object
;
16524 ---------------------
16525 -- Is_Dereferenced --
16526 ---------------------
16528 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
16529 P
: constant Node_Id
:= Parent
(N
);
16531 return Nkind
(P
) in N_Selected_Component
16532 | N_Explicit_Dereference
16533 | N_Indexed_Component
16535 and then Prefix
(P
) = N
;
16536 end Is_Dereferenced
;
16538 ----------------------
16539 -- Is_Descendant_Of --
16540 ----------------------
16542 function Is_Descendant_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
16547 pragma Assert
(Nkind
(T1
) in N_Entity
);
16548 pragma Assert
(Nkind
(T2
) in N_Entity
);
16550 T
:= Base_Type
(T1
);
16552 -- Immediate return if the types match
16557 -- Comment needed here ???
16559 elsif Ekind
(T
) = E_Class_Wide_Type
then
16560 return Etype
(T
) = T2
;
16568 -- Done if we found the type we are looking for
16573 -- Done if no more derivations to check
16580 -- Following test catches error cases resulting from prev errors
16582 elsif No
(Etyp
) then
16585 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
16588 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
16592 T
:= Base_Type
(Etyp
);
16595 end Is_Descendant_Of
;
16597 ----------------------------------------
16598 -- Is_Descendant_Of_Suspension_Object --
16599 ----------------------------------------
16601 function Is_Descendant_Of_Suspension_Object
16602 (Typ
: Entity_Id
) return Boolean
16604 Cur_Typ
: Entity_Id
;
16605 Par_Typ
: Entity_Id
;
16608 -- Climb the type derivation chain checking each parent type against
16609 -- Suspension_Object.
16611 Cur_Typ
:= Base_Type
(Typ
);
16612 while Present
(Cur_Typ
) loop
16613 Par_Typ
:= Etype
(Cur_Typ
);
16615 -- The current type is a match
16617 if Is_RTE
(Cur_Typ
, RE_Suspension_Object
) then
16620 -- Stop the traversal once the root of the derivation chain has been
16621 -- reached. In that case the current type is its own base type.
16623 elsif Cur_Typ
= Par_Typ
then
16627 Cur_Typ
:= Base_Type
(Par_Typ
);
16631 end Is_Descendant_Of_Suspension_Object
;
16633 ---------------------------------------------
16634 -- Is_Double_Precision_Floating_Point_Type --
16635 ---------------------------------------------
16637 function Is_Double_Precision_Floating_Point_Type
16638 (E
: Entity_Id
) return Boolean is
16640 return Is_Floating_Point_Type
(E
)
16641 and then Machine_Radix_Value
(E
) = Uint_2
16642 and then Machine_Mantissa_Value
(E
) = UI_From_Int
(53)
16643 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_10
16644 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_10
);
16645 end Is_Double_Precision_Floating_Point_Type
;
16647 -----------------------------
16648 -- Is_Effectively_Volatile --
16649 -----------------------------
16651 function Is_Effectively_Volatile
16653 Ignore_Protected
: Boolean := False) return Boolean is
16655 if Is_Type
(Id
) then
16657 -- An arbitrary type is effectively volatile when it is subject to
16658 -- pragma Atomic or Volatile, unless No_Caching is enabled.
16660 if Is_Volatile
(Id
)
16661 and then not No_Caching_Enabled
(Id
)
16665 -- An array type is effectively volatile when it is subject to pragma
16666 -- Atomic_Components or Volatile_Components or its component type is
16667 -- effectively volatile.
16669 elsif Is_Array_Type
(Id
) then
16670 if Has_Volatile_Components
(Id
) then
16674 Anc
: Entity_Id
:= Base_Type
(Id
);
16676 if Is_Private_Type
(Anc
) then
16677 Anc
:= Full_View
(Anc
);
16680 -- Test for presence of ancestor, as the full view of a
16681 -- private type may be missing in case of error.
16683 return Present
(Anc
)
16684 and then Is_Effectively_Volatile
16685 (Component_Type
(Anc
), Ignore_Protected
);
16689 -- A protected type is always volatile unless Ignore_Protected is
16692 elsif Is_Protected_Type
(Id
) and then not Ignore_Protected
then
16695 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
16696 -- automatically volatile.
16698 elsif Is_Descendant_Of_Suspension_Object
(Id
) then
16701 -- Otherwise the type is not effectively volatile
16707 -- Otherwise Id denotes an object
16709 else pragma Assert
(Is_Object
(Id
));
16710 -- A volatile object for which No_Caching is enabled is not
16711 -- effectively volatile.
16716 (Ekind
(Id
) = E_Variable
and then No_Caching_Enabled
(Id
)))
16717 or else Has_Volatile_Components
(Id
)
16718 or else Is_Effectively_Volatile
(Etype
(Id
), Ignore_Protected
);
16720 end Is_Effectively_Volatile
;
16722 -----------------------------------------
16723 -- Is_Effectively_Volatile_For_Reading --
16724 -----------------------------------------
16726 function Is_Effectively_Volatile_For_Reading
16728 Ignore_Protected
: Boolean := False) return Boolean
16731 -- A concurrent type is effectively volatile for reading, except for a
16732 -- protected type when Ignore_Protected is True.
16734 if Is_Task_Type
(Id
)
16735 or else (Is_Protected_Type
(Id
) and then not Ignore_Protected
)
16739 elsif Is_Effectively_Volatile
(Id
, Ignore_Protected
) then
16741 -- Other volatile types and objects are effectively volatile for
16742 -- reading when they have property Async_Writers or Effective_Reads
16743 -- set to True. This includes the case of an array type whose
16744 -- Volatile_Components aspect is True (hence it is effectively
16745 -- volatile) which does not have the properties Async_Writers
16746 -- and Effective_Reads set to False.
16748 if Async_Writers_Enabled
(Id
)
16749 or else Effective_Reads_Enabled
(Id
)
16753 -- In addition, an array type is effectively volatile for reading
16754 -- when its component type is effectively volatile for reading.
16756 elsif Is_Array_Type
(Id
) then
16758 Anc
: Entity_Id
:= Base_Type
(Id
);
16760 if Is_Private_Type
(Anc
) then
16761 Anc
:= Full_View
(Anc
);
16764 -- Test for presence of ancestor, as the full view of a
16765 -- private type may be missing in case of error.
16767 return Present
(Anc
)
16768 and then Is_Effectively_Volatile_For_Reading
16769 (Component_Type
(Anc
), Ignore_Protected
);
16776 end Is_Effectively_Volatile_For_Reading
;
16778 ------------------------------------
16779 -- Is_Effectively_Volatile_Object --
16780 ------------------------------------
16782 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
16783 function Is_Effectively_Volatile
(E
: Entity_Id
) return Boolean is
16784 (Is_Effectively_Volatile
(E
, Ignore_Protected
=> False));
16786 function Is_Effectively_Volatile_Object_Inst
16787 is new Is_Effectively_Volatile_Object_Shared
(Is_Effectively_Volatile
);
16789 return Is_Effectively_Volatile_Object_Inst
(N
);
16790 end Is_Effectively_Volatile_Object
;
16792 ------------------------------------------------
16793 -- Is_Effectively_Volatile_Object_For_Reading --
16794 ------------------------------------------------
16796 function Is_Effectively_Volatile_Object_For_Reading
16797 (N
: Node_Id
) return Boolean
16799 function Is_Effectively_Volatile_For_Reading
16800 (E
: Entity_Id
) return Boolean
16801 is (Is_Effectively_Volatile_For_Reading
(E
, Ignore_Protected
=> False));
16803 function Is_Effectively_Volatile_Object_For_Reading_Inst
16804 is new Is_Effectively_Volatile_Object_Shared
16805 (Is_Effectively_Volatile_For_Reading
);
16807 return Is_Effectively_Volatile_Object_For_Reading_Inst
(N
);
16808 end Is_Effectively_Volatile_Object_For_Reading
;
16810 -------------------------------------------
16811 -- Is_Effectively_Volatile_Object_Shared --
16812 -------------------------------------------
16814 function Is_Effectively_Volatile_Object_Shared
16815 (N
: Node_Id
) return Boolean
16818 if Is_Entity_Name
(N
) then
16819 return Is_Object
(Entity
(N
))
16820 and then Is_Effectively_Volatile_Entity
(Entity
(N
));
16822 elsif Nkind
(N
) in N_Indexed_Component | N_Slice
then
16823 return Is_Effectively_Volatile_Object_Shared
(Prefix
(N
));
16825 elsif Nkind
(N
) = N_Selected_Component
then
16827 Is_Effectively_Volatile_Object_Shared
(Prefix
(N
))
16829 Is_Effectively_Volatile_Object_Shared
(Selector_Name
(N
));
16831 elsif Nkind
(N
) in N_Qualified_Expression
16832 | N_Unchecked_Type_Conversion
16833 | N_Type_Conversion
16835 return Is_Effectively_Volatile_Object_Shared
(Expression
(N
));
16840 end Is_Effectively_Volatile_Object_Shared
;
16842 ----------------------------------------
16843 -- Is_Entity_Of_Quantified_Expression --
16844 ----------------------------------------
16846 function Is_Entity_Of_Quantified_Expression
(Id
: Entity_Id
) return Boolean
16848 Par
: constant Node_Id
:= Parent
(Id
);
16851 return (Nkind
(Par
) = N_Loop_Parameter_Specification
16852 or else Nkind
(Par
) = N_Iterator_Specification
)
16853 and then Defining_Identifier
(Par
) = Id
16854 and then Nkind
(Parent
(Par
)) = N_Quantified_Expression
;
16855 end Is_Entity_Of_Quantified_Expression
;
16857 -------------------
16858 -- Is_Entry_Body --
16859 -------------------
16861 function Is_Entry_Body
(Id
: Entity_Id
) return Boolean is
16865 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Body
;
16868 --------------------------
16869 -- Is_Entry_Declaration --
16870 --------------------------
16872 function Is_Entry_Declaration
(Id
: Entity_Id
) return Boolean is
16876 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Declaration
;
16877 end Is_Entry_Declaration
;
16879 ------------------------------------
16880 -- Is_Expanded_Priority_Attribute --
16881 ------------------------------------
16883 function Is_Expanded_Priority_Attribute
(E
: Entity_Id
) return Boolean is
16886 Nkind
(E
) = N_Function_Call
16887 and then not Configurable_Run_Time_Mode
16888 and then Nkind
(Original_Node
(E
)) = N_Attribute_Reference
16889 and then (Is_RTE
(Entity
(Name
(E
)), RE_Get_Ceiling
)
16890 or else Is_RTE
(Entity
(Name
(E
)), RO_PE_Get_Ceiling
));
16891 end Is_Expanded_Priority_Attribute
;
16893 ----------------------------
16894 -- Is_Expression_Function --
16895 ----------------------------
16897 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
16899 if Ekind
(Subp
) in E_Function | E_Subprogram_Body
then
16901 Nkind
(Original_Node
(Unit_Declaration_Node
(Subp
))) =
16902 N_Expression_Function
;
16906 end Is_Expression_Function
;
16908 ------------------------------------------
16909 -- Is_Expression_Function_Or_Completion --
16910 ------------------------------------------
16912 function Is_Expression_Function_Or_Completion
16913 (Subp
: Entity_Id
) return Boolean
16915 Subp_Decl
: Node_Id
;
16918 if Ekind
(Subp
) = E_Function
then
16919 Subp_Decl
:= Unit_Declaration_Node
(Subp
);
16921 -- The function declaration is either an expression function or is
16922 -- completed by an expression function body.
16925 Is_Expression_Function
(Subp
)
16926 or else (Nkind
(Subp_Decl
) = N_Subprogram_Declaration
16927 and then Present
(Corresponding_Body
(Subp_Decl
))
16928 and then Is_Expression_Function
16929 (Corresponding_Body
(Subp_Decl
)));
16931 elsif Ekind
(Subp
) = E_Subprogram_Body
then
16932 return Is_Expression_Function
(Subp
);
16937 end Is_Expression_Function_Or_Completion
;
16939 -----------------------------------------------
16940 -- Is_Extended_Precision_Floating_Point_Type --
16941 -----------------------------------------------
16943 function Is_Extended_Precision_Floating_Point_Type
16944 (E
: Entity_Id
) return Boolean is
16946 return Is_Floating_Point_Type
(E
)
16947 and then Machine_Radix_Value
(E
) = Uint_2
16948 and then Machine_Mantissa_Value
(E
) = Uint_64
16949 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_14
16950 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_14
);
16951 end Is_Extended_Precision_Floating_Point_Type
;
16953 -----------------------
16954 -- Is_EVF_Expression --
16955 -----------------------
16957 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
16958 Orig_N
: constant Node_Id
:= Original_Node
(N
);
16964 -- Detect a reference to a formal parameter of a specific tagged type
16965 -- whose related subprogram is subject to pragma Expresions_Visible with
16968 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
16973 and then Is_Specific_Tagged_Type
(Etype
(Id
))
16974 and then Extensions_Visible_Status
(Id
) =
16975 Extensions_Visible_False
;
16977 -- A case expression is an EVF expression when it contains at least one
16978 -- EVF dependent_expression. Note that a case expression may have been
16979 -- expanded, hence the use of Original_Node.
16981 elsif Nkind
(Orig_N
) = N_Case_Expression
then
16982 Alt
:= First
(Alternatives
(Orig_N
));
16983 while Present
(Alt
) loop
16984 if Is_EVF_Expression
(Expression
(Alt
)) then
16991 -- An if expression is an EVF expression when it contains at least one
16992 -- EVF dependent_expression. Note that an if expression may have been
16993 -- expanded, hence the use of Original_Node.
16995 elsif Nkind
(Orig_N
) = N_If_Expression
then
16996 Expr
:= Next
(First
(Expressions
(Orig_N
)));
16997 while Present
(Expr
) loop
16998 if Is_EVF_Expression
(Expr
) then
17005 -- A qualified expression or a type conversion is an EVF expression when
17006 -- its operand is an EVF expression.
17008 elsif Nkind
(N
) in N_Qualified_Expression
17009 | N_Unchecked_Type_Conversion
17010 | N_Type_Conversion
17012 return Is_EVF_Expression
(Expression
(N
));
17014 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
17015 -- their prefix denotes an EVF expression.
17017 elsif Nkind
(N
) = N_Attribute_Reference
17018 and then Attribute_Name
(N
) in Name_Loop_Entry
17022 return Is_EVF_Expression
(Prefix
(N
));
17026 end Is_EVF_Expression
;
17032 function Is_False
(U
: Opt_Ubool
) return Boolean is
17034 return not Is_True
(U
);
17037 ---------------------------
17038 -- Is_Fixed_Model_Number --
17039 ---------------------------
17041 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
17042 S
: constant Ureal
:= Small_Value
(T
);
17043 M
: Urealp
.Save_Mark
;
17048 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
17049 Urealp
.Release
(M
);
17051 end Is_Fixed_Model_Number
;
17053 -----------------------------
17054 -- Is_Full_Access_Object --
17055 -----------------------------
17057 function Is_Full_Access_Object
(N
: Node_Id
) return Boolean is
17059 return Is_Atomic_Object
(N
)
17060 or else Is_Volatile_Full_Access_Object_Ref
(N
);
17061 end Is_Full_Access_Object
;
17063 -------------------------------
17064 -- Is_Fully_Initialized_Type --
17065 -------------------------------
17067 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
17071 if Is_Scalar_Type
(Typ
) then
17073 -- A scalar type with an aspect Default_Value is fully initialized
17075 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
17076 -- of a scalar type, but we don't take that into account here, since
17077 -- we don't want these to affect warnings.
17079 return Has_Default_Aspect
(Typ
);
17081 elsif Is_Access_Type
(Typ
) then
17084 elsif Is_Array_Type
(Typ
) then
17085 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
17086 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
17091 -- An interesting case, if we have a constrained type one of whose
17092 -- bounds is known to be null, then there are no elements to be
17093 -- initialized, so all the elements are initialized.
17095 if Is_Constrained
(Typ
) then
17098 Indx_Typ
: Entity_Id
;
17099 Lbd
, Hbd
: Node_Id
;
17102 Indx
:= First_Index
(Typ
);
17103 while Present
(Indx
) loop
17104 if Etype
(Indx
) = Any_Type
then
17107 -- If index is a range, use directly
17109 elsif Nkind
(Indx
) = N_Range
then
17110 Lbd
:= Low_Bound
(Indx
);
17111 Hbd
:= High_Bound
(Indx
);
17114 Indx_Typ
:= Etype
(Indx
);
17116 if Is_Private_Type
(Indx_Typ
) then
17117 Indx_Typ
:= Full_View
(Indx_Typ
);
17120 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
17123 Lbd
:= Type_Low_Bound
(Indx_Typ
);
17124 Hbd
:= Type_High_Bound
(Indx_Typ
);
17128 if Compile_Time_Known_Value
(Lbd
)
17130 Compile_Time_Known_Value
(Hbd
)
17132 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
17142 -- If no null indexes, then type is not fully initialized
17148 elsif Is_Record_Type
(Typ
) then
17149 if Has_Defaulted_Discriminants
(Typ
)
17150 and then Is_Fully_Initialized_Variant
(Typ
)
17155 -- We consider bounded string types to be fully initialized, because
17156 -- otherwise we get false alarms when the Data component is not
17157 -- default-initialized.
17159 if Is_Bounded_String
(Typ
) then
17163 -- Controlled records are considered to be fully initialized if
17164 -- there is a user defined Initialize routine. This may not be
17165 -- entirely correct, but as the spec notes, we are guessing here
17166 -- what is best from the point of view of issuing warnings.
17168 if Is_Controlled
(Typ
) then
17170 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
17173 if Present
(Utyp
) then
17175 Init
: constant Entity_Id
:=
17176 (Find_Optional_Prim_Op
17177 (Utyp
, Name_Initialize
));
17181 and then Comes_From_Source
(Init
)
17182 and then not In_Predefined_Unit
(Init
)
17186 elsif Has_Null_Extension
(Typ
)
17188 Is_Fully_Initialized_Type
17189 (Etype
(Base_Type
(Typ
)))
17198 -- Otherwise see if all record components are initialized
17204 Comp
:= First_Component
(Typ
);
17205 while Present
(Comp
) loop
17206 if (No
(Parent
(Comp
))
17207 or else No
(Expression
(Parent
(Comp
))))
17208 and then not Is_Fully_Initialized_Type
(Etype
(Comp
))
17210 -- Special VM case for tag components, which need to be
17211 -- defined in this case, but are never initialized as VMs
17212 -- are using other dispatching mechanisms. Ignore this
17213 -- uninitialized case. Note that this applies both to the
17214 -- uTag entry and the main vtable pointer (CPP_Class case).
17216 and then (Tagged_Type_Expansion
or else not Is_Tag
(Comp
))
17221 Next_Component
(Comp
);
17225 -- No uninitialized components, so type is fully initialized.
17226 -- Note that this catches the case of no components as well.
17230 elsif Is_Concurrent_Type
(Typ
) then
17233 elsif Is_Private_Type
(Typ
) then
17235 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
17241 return Is_Fully_Initialized_Type
(U
);
17248 end Is_Fully_Initialized_Type
;
17250 ----------------------------------
17251 -- Is_Fully_Initialized_Variant --
17252 ----------------------------------
17254 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
17255 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
17256 Constraints
: constant List_Id
:= New_List
;
17257 Components
: constant Elist_Id
:= New_Elmt_List
;
17258 Comp_Elmt
: Elmt_Id
;
17260 Comp_List
: Node_Id
;
17262 Discr_Val
: Node_Id
;
17264 Report_Errors
: Boolean;
17265 pragma Warnings
(Off
, Report_Errors
);
17268 if Serious_Errors_Detected
> 0 then
17272 if Is_Record_Type
(Typ
)
17273 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
17274 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
17276 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
17278 Discr
:= First_Discriminant
(Typ
);
17279 while Present
(Discr
) loop
17280 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
17281 Discr_Val
:= Expression
(Parent
(Discr
));
17283 if Present
(Discr_Val
)
17284 and then Is_OK_Static_Expression
(Discr_Val
)
17286 Append_To
(Constraints
,
17287 Make_Component_Association
(Loc
,
17288 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
17289 Expression
=> New_Copy
(Discr_Val
)));
17297 Next_Discriminant
(Discr
);
17302 Comp_List
=> Comp_List
,
17303 Governed_By
=> Constraints
,
17304 Into
=> Components
,
17305 Report_Errors
=> Report_Errors
);
17307 -- Check that each component present is fully initialized
17309 Comp_Elmt
:= First_Elmt
(Components
);
17310 while Present
(Comp_Elmt
) loop
17311 Comp_Id
:= Node
(Comp_Elmt
);
17313 if Ekind
(Comp_Id
) = E_Component
17314 and then (No
(Parent
(Comp_Id
))
17315 or else No
(Expression
(Parent
(Comp_Id
))))
17316 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
17321 Next_Elmt
(Comp_Elmt
);
17326 elsif Is_Private_Type
(Typ
) then
17328 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
17334 return Is_Fully_Initialized_Variant
(U
);
17341 end Is_Fully_Initialized_Variant
;
17343 -----------------------------------
17344 -- Is_Function_With_Side_Effects --
17345 -----------------------------------
17347 function Is_Function_With_Side_Effects
(Subp
: Entity_Id
) return Boolean is
17350 Prag
: constant Node_Id
:= Get_Pragma
(Subp
, Pragma_Side_Effects
);
17353 -- Extract the value from the Boolean expression (if any)
17355 if Present
(Prag
) then
17356 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
17358 if Present
(Arg
) then
17359 Expr
:= Get_Pragma_Arg
(Arg
);
17361 return Is_True
(Expr_Value
(Expr
));
17363 -- Otherwise the aspect or pragma defaults to True
17371 end Is_Function_With_Side_Effects
;
17373 ------------------------------------
17374 -- Is_Generic_Declaration_Or_Body --
17375 ------------------------------------
17377 function Is_Generic_Declaration_Or_Body
(Decl
: Node_Id
) return Boolean is
17378 Spec_Decl
: Node_Id
;
17381 -- Package/subprogram body
17383 if Nkind
(Decl
) in N_Package_Body | N_Subprogram_Body
17384 and then Present
(Corresponding_Spec
(Decl
))
17386 Spec_Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(Decl
));
17388 -- Package/subprogram body stub
17390 elsif Nkind
(Decl
) in N_Package_Body_Stub | N_Subprogram_Body_Stub
17391 and then Present
(Corresponding_Spec_Of_Stub
(Decl
))
17394 Unit_Declaration_Node
(Corresponding_Spec_Of_Stub
(Decl
));
17402 -- Rather than inspecting the defining entity of the spec declaration,
17403 -- look at its Nkind. This takes care of the case where the analysis of
17404 -- a generic body modifies the Ekind of its spec to allow for recursive
17407 return Nkind
(Spec_Decl
) in N_Generic_Declaration
;
17408 end Is_Generic_Declaration_Or_Body
;
17410 ---------------------------
17411 -- Is_Independent_Object --
17412 ---------------------------
17414 function Is_Independent_Object
(N
: Node_Id
) return Boolean is
17415 function Is_Independent_Object_Entity
(Id
: Entity_Id
) return Boolean;
17416 -- Determine whether arbitrary entity Id denotes an object that is
17419 function Prefix_Has_Independent_Components
(P
: Node_Id
) return Boolean;
17420 -- Determine whether prefix P has independent components. This requires
17421 -- the presence of an Independent_Components aspect/pragma.
17423 ------------------------------------
17424 -- Is_Independent_Object_Entity --
17425 ------------------------------------
17427 function Is_Independent_Object_Entity
(Id
: Entity_Id
) return Boolean is
17431 and then (Is_Independent
(Id
)
17433 Is_Independent
(Etype
(Id
)));
17434 end Is_Independent_Object_Entity
;
17436 -------------------------------------
17437 -- Prefix_Has_Independent_Components --
17438 -------------------------------------
17440 function Prefix_Has_Independent_Components
(P
: Node_Id
) return Boolean
17442 Typ
: constant Entity_Id
:= Etype
(P
);
17445 if Is_Access_Type
(Typ
) then
17446 return Has_Independent_Components
(Designated_Type
(Typ
));
17448 elsif Has_Independent_Components
(Typ
) then
17451 elsif Is_Entity_Name
(P
)
17452 and then Has_Independent_Components
(Entity
(P
))
17459 end Prefix_Has_Independent_Components
;
17461 -- Start of processing for Is_Independent_Object
17464 if Is_Entity_Name
(N
) then
17465 return Is_Independent_Object_Entity
(Entity
(N
));
17467 elsif Is_Independent
(Etype
(N
)) then
17470 elsif Nkind
(N
) = N_Indexed_Component
then
17471 return Prefix_Has_Independent_Components
(Prefix
(N
));
17473 elsif Nkind
(N
) = N_Selected_Component
then
17474 return Prefix_Has_Independent_Components
(Prefix
(N
))
17475 or else Is_Independent
(Entity
(Selector_Name
(N
)));
17480 end Is_Independent_Object
;
17482 ----------------------------
17483 -- Is_Inherited_Operation --
17484 ----------------------------
17486 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
17487 pragma Assert
(Is_Overloadable
(E
));
17488 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
17490 return Kind
= N_Full_Type_Declaration
17491 or else Kind
= N_Private_Extension_Declaration
17492 or else Kind
= N_Subtype_Declaration
17493 or else (Ekind
(E
) = E_Enumeration_Literal
17494 and then Is_Derived_Type
(Etype
(E
)));
17495 end Is_Inherited_Operation
;
17497 --------------------------------------
17498 -- Is_Inlinable_Expression_Function --
17499 --------------------------------------
17501 function Is_Inlinable_Expression_Function
17502 (Subp
: Entity_Id
) return Boolean
17504 Return_Expr
: Node_Id
;
17507 if Is_Expression_Function_Or_Completion
(Subp
)
17508 and then Has_Pragma_Inline_Always
(Subp
)
17509 and then Needs_No_Actuals
(Subp
)
17510 and then No
(Contract
(Subp
))
17511 and then not Is_Dispatching_Operation
(Subp
)
17512 and then Needs_Finalization
(Etype
(Subp
))
17513 and then not Is_Class_Wide_Type
(Etype
(Subp
))
17514 and then not Has_Invariants
(Etype
(Subp
))
17515 and then Present
(Subprogram_Body
(Subp
))
17516 and then Was_Expression_Function
(Subprogram_Body
(Subp
))
17518 Return_Expr
:= Expression_Of_Expression_Function
(Subp
);
17520 -- The returned object must not have a qualified expression and its
17521 -- nominal subtype must be statically compatible with the result
17522 -- subtype of the expression function.
17525 Nkind
(Return_Expr
) = N_Identifier
17526 and then Etype
(Return_Expr
) = Etype
(Subp
);
17530 end Is_Inlinable_Expression_Function
;
17532 -----------------------
17533 -- Is_Internal_Block --
17534 -----------------------
17536 function Is_Internal_Block
(N
: Node_Id
) return Boolean is
17538 return Nkind
(N
) = N_Block_Statement
17539 and then Is_Internal
(Entity
(Identifier
(N
)));
17540 end Is_Internal_Block
;
17546 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
17547 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean;
17548 -- Determine whether type Iter_Typ is a predefined forward or reversible
17551 ----------------------
17552 -- Denotes_Iterator --
17553 ----------------------
17555 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean is
17557 -- Check that the name matches, and that the ultimate ancestor is in
17558 -- a predefined unit, i.e the one that declares iterator interfaces.
17561 Chars
(Iter_Typ
) in Name_Forward_Iterator | Name_Reversible_Iterator
17562 and then In_Predefined_Unit
(Root_Type
(Iter_Typ
));
17563 end Denotes_Iterator
;
17567 Iface_Elmt
: Elmt_Id
;
17570 -- Start of processing for Is_Iterator
17573 -- The type may be a subtype of a descendant of the proper instance of
17574 -- the predefined interface type, so we must use the root type of the
17575 -- given type. The same is done for Is_Reversible_Iterator.
17577 if Is_Class_Wide_Type
(Typ
)
17578 and then Denotes_Iterator
(Root_Type
(Typ
))
17582 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
17585 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
17589 Collect_Interfaces
(Typ
, Ifaces
);
17591 Iface_Elmt
:= First_Elmt
(Ifaces
);
17592 while Present
(Iface_Elmt
) loop
17593 if Denotes_Iterator
(Node
(Iface_Elmt
)) then
17597 Next_Elmt
(Iface_Elmt
);
17604 ----------------------------
17605 -- Is_Iterator_Over_Array --
17606 ----------------------------
17608 function Is_Iterator_Over_Array
(N
: Node_Id
) return Boolean is
17609 Container
: constant Node_Id
:= Name
(N
);
17610 Container_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Container
));
17612 return Is_Array_Type
(Container_Typ
);
17613 end Is_Iterator_Over_Array
;
17615 --------------------------
17616 -- Known_To_Be_Assigned --
17617 --------------------------
17619 function Known_To_Be_Assigned
17621 Only_LHS
: Boolean := False) return Boolean
17623 function Known_Assn
(N
: Node_Id
) return Boolean is
17624 (Known_To_Be_Assigned
(N
, Only_LHS
));
17625 -- Local function to simplify the passing of parameters for recursive
17628 P
: constant Node_Id
:= Parent
(N
);
17629 Form
: Entity_Id
:= Empty
;
17630 Call
: Node_Id
:= Empty
;
17632 -- Start of processing for Known_To_Be_Assigned
17635 -- Check for out parameters
17637 Find_Actual
(N
, Form
, Call
);
17639 if Present
(Form
) then
17640 return Ekind
(Form
) /= E_In_Parameter
and then not Only_LHS
;
17643 -- Otherwise look at the parent
17647 -- Test left side of assignment
17649 when N_Assignment_Statement
=>
17650 return N
= Name
(P
);
17652 -- Test prefix of component or attribute. Note that the prefix of an
17653 -- explicit or implicit dereference cannot be an l-value. In the case
17654 -- of a 'Read attribute, the reference can be an actual in the
17655 -- argument list of the attribute.
17657 when N_Attribute_Reference
=>
17659 not Only_LHS
and then
17661 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
)))
17663 Attribute_Name
(P
) = Name_Read
);
17665 -- For an expanded name, the name is an lvalue if the expanded name
17666 -- is an lvalue, but the prefix is never an lvalue, since it is just
17667 -- the scope where the name is found.
17669 when N_Expanded_Name
=>
17670 if N
= Prefix
(P
) then
17671 return Known_Assn
(P
);
17676 -- For a selected component A.B, A is certainly an lvalue if A.B is.
17677 -- B is a little interesting, if we have A.B := 3, there is some
17678 -- discussion as to whether B is an lvalue or not, we choose to say
17679 -- it is. Note however that A is not an lvalue if it is of an access
17680 -- type since this is an implicit dereference.
17682 when N_Selected_Component
=>
17684 and then Present
(Etype
(N
))
17685 and then Is_Access_Type
(Etype
(N
))
17689 return Known_Assn
(P
);
17692 -- For an indexed component or slice, the index or slice bounds is
17693 -- never an lvalue. The prefix is an lvalue if the indexed component
17694 -- or slice is an lvalue, except if it is an access type, where we
17695 -- have an implicit dereference.
17697 when N_Indexed_Component | N_Slice
=>
17699 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
17703 return Known_Assn
(P
);
17706 -- Prefix of a reference is an lvalue if the reference is an lvalue
17708 when N_Reference
=>
17709 return Known_Assn
(P
);
17711 -- Prefix of explicit dereference is never an lvalue
17713 when N_Explicit_Dereference
=>
17716 -- Test for appearing in a conversion that itself appears in an
17717 -- lvalue context, since this should be an lvalue.
17719 when N_Type_Conversion
=>
17720 return Known_Assn
(P
);
17722 -- Test for appearance in object renaming declaration
17724 when N_Object_Renaming_Declaration
=>
17725 return not Only_LHS
;
17727 -- All other references are definitely not lvalues
17732 end Known_To_Be_Assigned
;
17734 -----------------------------
17735 -- Is_Library_Level_Entity --
17736 -----------------------------
17738 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
17740 -- The following is a small optimization, and it also properly handles
17741 -- discriminals, which in task bodies might appear in expressions before
17742 -- the corresponding procedure has been created, and which therefore do
17743 -- not have an assigned scope.
17745 if Is_Formal
(E
) then
17748 -- If we somehow got an empty value for Scope, the tree must be
17749 -- malformed. Rather than blow up we return True in this case.
17751 elsif No
(Scope
(E
)) then
17754 -- Handle loops since Enclosing_Dynamic_Scope skips them; required to
17755 -- properly handle entities local to quantified expressions in library
17756 -- level specifications.
17758 elsif Ekind
(Scope
(E
)) = E_Loop
then
17762 -- Normal test is simply that the enclosing dynamic scope is Standard
17764 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
17765 end Is_Library_Level_Entity
;
17767 --------------------------------
17768 -- Is_Limited_Class_Wide_Type --
17769 --------------------------------
17771 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
17774 Is_Class_Wide_Type
(Typ
)
17775 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
17776 end Is_Limited_Class_Wide_Type
;
17778 ---------------------------------
17779 -- Is_Local_Variable_Reference --
17780 ---------------------------------
17782 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
17784 if not Is_Entity_Name
(Expr
) then
17789 Ent
: constant Entity_Id
:= Entity
(Expr
);
17790 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
17793 not in E_Variable | E_In_Out_Parameter | E_Out_Parameter
17797 return Present
(Sub
) and then Sub
= Current_Subprogram
;
17801 end Is_Local_Variable_Reference
;
17807 function Is_Master
(N
: Node_Id
) return Boolean is
17808 Disable_Subexpression_Masters
: constant Boolean := True;
17811 if Nkind
(N
) in N_Subprogram_Body | N_Task_Body | N_Entry_Body
17812 or else Is_Statement
(N
)
17817 -- We avoid returning True when the master is a subexpression described
17818 -- in RM 7.6.1(3/2) for the proposes of accessibility level calculation
17819 -- in Accessibility_Level_Helper.Innermost_Master_Scope_Depth ???
17821 if not Disable_Subexpression_Masters
17822 and then Nkind
(N
) in N_Subexpr
17825 Par
: Node_Id
:= N
;
17827 subtype N_Simple_Statement_Other_Than_Simple_Return
17828 is Node_Kind
with Static_Predicate
=>
17829 N_Simple_Statement_Other_Than_Simple_Return
17830 in N_Abort_Statement
17831 | N_Assignment_Statement
17833 | N_Delay_Statement
17834 | N_Entry_Call_Statement
17838 | N_Raise_Statement
17839 | N_Requeue_Statement
17841 | N_Procedure_Call_Statement
;
17843 while Present
(Par
) loop
17844 Par
:= Parent
(Par
);
17845 if Nkind
(Par
) in N_Subexpr |
17846 N_Simple_Statement_Other_Than_Simple_Return
17859 -----------------------
17860 -- Is_Name_Reference --
17861 -----------------------
17863 function Is_Name_Reference
(N
: Node_Id
) return Boolean is
17865 if Is_Entity_Name
(N
) then
17866 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
17870 when N_Indexed_Component
17874 Is_Name_Reference
(Prefix
(N
))
17875 or else Is_Access_Type
(Etype
(Prefix
(N
)));
17877 -- Attributes 'Input, 'Old and 'Result produce objects
17879 when N_Attribute_Reference
=>
17880 return Attribute_Name
(N
) in Name_Input | Name_Old | Name_Result
;
17882 when N_Selected_Component
=>
17884 Is_Name_Reference
(Selector_Name
(N
))
17886 (Is_Name_Reference
(Prefix
(N
))
17887 or else Is_Access_Type
(Etype
(Prefix
(N
))));
17889 when N_Explicit_Dereference
=>
17892 -- A view conversion of a tagged name is a name reference
17894 when N_Type_Conversion
=>
17896 Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
17897 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
17898 and then Is_Name_Reference
(Expression
(N
));
17900 -- An unchecked type conversion is considered to be a name if the
17901 -- operand is a name (this construction arises only as a result of
17902 -- expansion activities).
17904 when N_Unchecked_Type_Conversion
=>
17905 return Is_Name_Reference
(Expression
(N
));
17910 end Is_Name_Reference
;
17912 --------------------------
17913 -- Is_Newly_Constructed --
17914 --------------------------
17916 function Is_Newly_Constructed
17917 (Exp
: Node_Id
; Context_Requires_NC
: Boolean) return Boolean
17919 Original_Exp
: constant Node_Id
:= Original_Node
(Exp
);
17921 function Is_NC
(Exp
: Node_Id
) return Boolean is
17922 (Is_Newly_Constructed
(Exp
, Context_Requires_NC
));
17924 -- If the context requires that the expression shall be newly
17925 -- constructed, then "True" is a good result in the sense that the
17926 -- expression satisfies the requirements of the context (and "False"
17927 -- is analogously a bad result). If the context requires that the
17928 -- expression shall *not* be newly constructed, then things are
17929 -- reversed: "False" is the good value and "True" is the bad value.
17931 Good_Result
: constant Boolean := Context_Requires_NC
;
17932 Bad_Result
: constant Boolean := not Good_Result
;
17934 case Nkind
(Original_Exp
) is
17936 | N_Extension_Aggregate
17942 when N_Identifier
=>
17943 return Present
(Entity
(Original_Exp
))
17944 and then Ekind
(Entity
(Original_Exp
)) = E_Function
;
17946 when N_Qualified_Expression
=>
17947 return Is_NC
(Expression
(Original_Exp
));
17949 when N_Type_Conversion
17950 | N_Unchecked_Type_Conversion
17952 if Is_View_Conversion
(Original_Exp
) then
17953 return Is_NC
(Expression
(Original_Exp
));
17954 elsif not Comes_From_Source
(Exp
) then
17955 if Exp
/= Original_Exp
then
17956 return Is_NC
(Original_Exp
);
17958 return Is_NC
(Expression
(Original_Exp
));
17964 when N_Explicit_Dereference
17965 | N_Indexed_Component
17966 | N_Selected_Component
17968 return Nkind
(Exp
) = N_Function_Call
;
17970 -- A use of 'Input is a function call, hence allowed. Normally the
17971 -- attribute will be changed to a call, but the attribute by itself
17972 -- can occur with -gnatc.
17974 when N_Attribute_Reference
=>
17975 return Attribute_Name
(Original_Exp
) = Name_Input
;
17977 -- "return raise ..." is OK
17979 when N_Raise_Expression
=>
17980 return Good_Result
;
17982 -- For a case expression, all dependent expressions must be legal
17984 when N_Case_Expression
=>
17989 Alt
:= First
(Alternatives
(Original_Exp
));
17990 while Present
(Alt
) loop
17991 if Is_NC
(Expression
(Alt
)) = Bad_Result
then
17998 return Good_Result
;
18001 -- For an if expression, all dependent expressions must be legal
18003 when N_If_Expression
=>
18005 Then_Expr
: constant Node_Id
:=
18006 Next
(First
(Expressions
(Original_Exp
)));
18007 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
18009 if Is_NC
(Then_Expr
) = Bad_Result
18010 or else Is_NC
(Else_Expr
) = Bad_Result
18014 return Good_Result
;
18021 end Is_Newly_Constructed
;
18023 ------------------------------------
18024 -- Is_Non_Preelaborable_Construct --
18025 ------------------------------------
18027 function Is_Non_Preelaborable_Construct
(N
: Node_Id
) return Boolean is
18029 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
18030 -- intentionally unnested to avoid deep indentation of code.
18032 Non_Preelaborable
: exception;
18033 -- This exception is raised when the construct violates preelaborability
18034 -- to terminate the recursion.
18036 procedure Visit
(Nod
: Node_Id
);
18037 -- Semantically inspect construct Nod to determine whether it violates
18038 -- preelaborability. This routine raises Non_Preelaborable.
18040 procedure Visit_List
(List
: List_Id
);
18041 pragma Inline
(Visit_List
);
18042 -- Invoke Visit on each element of list List. This routine raises
18043 -- Non_Preelaborable.
18045 procedure Visit_Pragma
(Prag
: Node_Id
);
18046 pragma Inline
(Visit_Pragma
);
18047 -- Semantically inspect pragma Prag to determine whether it violates
18048 -- preelaborability. This routine raises Non_Preelaborable.
18050 procedure Visit_Subexpression
(Expr
: Node_Id
);
18051 pragma Inline
(Visit_Subexpression
);
18052 -- Semantically inspect expression Expr to determine whether it violates
18053 -- preelaborability. This routine raises Non_Preelaborable.
18059 procedure Visit
(Nod
: Node_Id
) is
18061 case Nkind
(Nod
) is
18065 when N_Component_Declaration
=>
18067 -- Defining_Identifier is left out because it is not relevant
18068 -- for preelaborability.
18070 Visit
(Component_Definition
(Nod
));
18071 Visit
(Expression
(Nod
));
18073 when N_Derived_Type_Definition
=>
18075 -- Interface_List is left out because it is not relevant for
18076 -- preelaborability.
18078 Visit
(Record_Extension_Part
(Nod
));
18079 Visit
(Subtype_Indication
(Nod
));
18081 when N_Entry_Declaration
=>
18083 -- A protected type with at leat one entry is not preelaborable
18084 -- while task types are never preelaborable. This renders entry
18085 -- declarations non-preelaborable.
18087 raise Non_Preelaborable
;
18089 when N_Full_Type_Declaration
=>
18091 -- Defining_Identifier and Discriminant_Specifications are left
18092 -- out because they are not relevant for preelaborability.
18094 Visit
(Type_Definition
(Nod
));
18096 when N_Function_Instantiation
18097 | N_Package_Instantiation
18098 | N_Procedure_Instantiation
18100 -- Defining_Unit_Name and Name are left out because they are
18101 -- not relevant for preelaborability.
18103 Visit_List
(Generic_Associations
(Nod
));
18105 when N_Object_Declaration
=>
18107 -- Defining_Identifier is left out because it is not relevant
18108 -- for preelaborability.
18110 Visit
(Object_Definition
(Nod
));
18112 if Has_Init_Expression
(Nod
) then
18113 Visit
(Expression
(Nod
));
18115 elsif not Constant_Present
(Nod
)
18116 and then not Has_Preelaborable_Initialization
18117 (Etype
(Defining_Entity
(Nod
)))
18119 raise Non_Preelaborable
;
18122 when N_Private_Extension_Declaration
18123 | N_Subtype_Declaration
18125 -- Defining_Identifier, Discriminant_Specifications, and
18126 -- Interface_List are left out because they are not relevant
18127 -- for preelaborability.
18129 Visit
(Subtype_Indication
(Nod
));
18131 when N_Protected_Type_Declaration
18132 | N_Single_Protected_Declaration
18134 -- Defining_Identifier, Discriminant_Specifications, and
18135 -- Interface_List are left out because they are not relevant
18136 -- for preelaborability.
18138 Visit
(Protected_Definition
(Nod
));
18140 -- A [single] task type is never preelaborable
18142 when N_Single_Task_Declaration
18143 | N_Task_Type_Declaration
18145 raise Non_Preelaborable
;
18150 Visit_Pragma
(Nod
);
18154 when N_Statement_Other_Than_Procedure_Call
=>
18155 if Nkind
(Nod
) /= N_Null_Statement
then
18156 raise Non_Preelaborable
;
18162 Visit_Subexpression
(Nod
);
18166 when N_Access_To_Object_Definition
=>
18167 Visit
(Subtype_Indication
(Nod
));
18169 when N_Case_Expression_Alternative
=>
18170 Visit
(Expression
(Nod
));
18171 Visit_List
(Discrete_Choices
(Nod
));
18173 when N_Component_Definition
=>
18174 Visit
(Access_Definition
(Nod
));
18175 Visit
(Subtype_Indication
(Nod
));
18177 when N_Component_List
=>
18178 Visit_List
(Component_Items
(Nod
));
18179 Visit
(Variant_Part
(Nod
));
18181 when N_Constrained_Array_Definition
=>
18182 Visit_List
(Discrete_Subtype_Definitions
(Nod
));
18183 Visit
(Component_Definition
(Nod
));
18185 when N_Delta_Constraint
18186 | N_Digits_Constraint
18188 -- Delta_Expression and Digits_Expression are left out because
18189 -- they are not relevant for preelaborability.
18191 Visit
(Range_Constraint
(Nod
));
18193 when N_Discriminant_Specification
=>
18195 -- Defining_Identifier and Expression are left out because they
18196 -- are not relevant for preelaborability.
18198 Visit
(Discriminant_Type
(Nod
));
18200 when N_Generic_Association
=>
18202 -- Selector_Name is left out because it is not relevant for
18203 -- preelaborability.
18205 Visit
(Explicit_Generic_Actual_Parameter
(Nod
));
18207 when N_Index_Or_Discriminant_Constraint
=>
18208 Visit_List
(Constraints
(Nod
));
18210 when N_Iterator_Specification
=>
18212 -- Defining_Identifier is left out because it is not relevant
18213 -- for preelaborability.
18215 Visit
(Name
(Nod
));
18216 Visit
(Subtype_Indication
(Nod
));
18218 when N_Loop_Parameter_Specification
=>
18220 -- Defining_Identifier is left out because it is not relevant
18221 -- for preelaborability.
18223 Visit
(Discrete_Subtype_Definition
(Nod
));
18225 when N_Parameter_Association
=>
18226 Visit
(Explicit_Actual_Parameter
(N
));
18228 when N_Protected_Definition
=>
18230 -- End_Label is left out because it is not relevant for
18231 -- preelaborability.
18233 Visit_List
(Private_Declarations
(Nod
));
18234 Visit_List
(Visible_Declarations
(Nod
));
18236 when N_Range_Constraint
=>
18237 Visit
(Range_Expression
(Nod
));
18239 when N_Record_Definition
18242 -- End_Label, Discrete_Choices, and Interface_List are left out
18243 -- because they are not relevant for preelaborability.
18245 Visit
(Component_List
(Nod
));
18247 when N_Subtype_Indication
=>
18249 -- Subtype_Mark is left out because it is not relevant for
18250 -- preelaborability.
18252 Visit
(Constraint
(Nod
));
18254 when N_Unconstrained_Array_Definition
=>
18256 -- Subtype_Marks is left out because it is not relevant for
18257 -- preelaborability.
18259 Visit
(Component_Definition
(Nod
));
18261 when N_Variant_Part
=>
18263 -- Name is left out because it is not relevant for
18264 -- preelaborability.
18266 Visit_List
(Variants
(Nod
));
18279 procedure Visit_List
(List
: List_Id
) is
18283 Nod
:= First
(List
);
18284 while Present
(Nod
) loop
18294 procedure Visit_Pragma
(Prag
: Node_Id
) is
18296 case Get_Pragma_Id
(Prag
) is
18298 | Pragma_Assert_And_Cut
18300 | Pragma_Async_Readers
18301 | Pragma_Async_Writers
18302 | Pragma_Attribute_Definition
18304 | Pragma_Constant_After_Elaboration
18306 | Pragma_Deadline_Floor
18307 | Pragma_Dispatching_Domain
18308 | Pragma_Effective_Reads
18309 | Pragma_Effective_Writes
18310 | Pragma_Extensions_Visible
18312 | Pragma_Secondary_Stack_Size
18314 | Pragma_Volatile_Function
18316 Visit_List
(Pragma_Argument_Associations
(Prag
));
18325 -------------------------
18326 -- Visit_Subexpression --
18327 -------------------------
18329 procedure Visit_Subexpression
(Expr
: Node_Id
) is
18330 procedure Visit_Aggregate
(Aggr
: Node_Id
);
18331 pragma Inline
(Visit_Aggregate
);
18332 -- Semantically inspect aggregate Aggr to determine whether it
18333 -- violates preelaborability.
18335 ---------------------
18336 -- Visit_Aggregate --
18337 ---------------------
18339 procedure Visit_Aggregate
(Aggr
: Node_Id
) is
18341 if not Is_Preelaborable_Aggregate
(Aggr
) then
18342 raise Non_Preelaborable
;
18344 end Visit_Aggregate
;
18346 -- Start of processing for Visit_Subexpression
18349 case Nkind
(Expr
) is
18351 | N_Qualified_Expression
18352 | N_Type_Conversion
18353 | N_Unchecked_Expression
18354 | N_Unchecked_Type_Conversion
18356 -- Subpool_Handle_Name and Subtype_Mark are left out because
18357 -- they are not relevant for preelaborability.
18359 Visit
(Expression
(Expr
));
18362 | N_Extension_Aggregate
18364 Visit_Aggregate
(Expr
);
18366 when N_Attribute_Reference
18367 | N_Explicit_Dereference
18370 -- Attribute_Name and Expressions are left out because they are
18371 -- not relevant for preelaborability.
18373 Visit
(Prefix
(Expr
));
18375 when N_Case_Expression
=>
18377 -- End_Span is left out because it is not relevant for
18378 -- preelaborability.
18380 Visit_List
(Alternatives
(Expr
));
18381 Visit
(Expression
(Expr
));
18383 when N_Delta_Aggregate
=>
18384 Visit_Aggregate
(Expr
);
18385 Visit
(Expression
(Expr
));
18387 when N_Expression_With_Actions
=>
18388 Visit_List
(Actions
(Expr
));
18389 Visit
(Expression
(Expr
));
18391 when N_Function_Call
=>
18393 -- Ada 2022 (AI12-0175): Calls to certain functions that are
18394 -- essentially unchecked conversions are preelaborable.
18396 if Ada_Version
>= Ada_2022
18397 and then Nkind
(Expr
) = N_Function_Call
18398 and then Is_Entity_Name
(Name
(Expr
))
18399 and then Is_Preelaborable_Function
(Entity
(Name
(Expr
)))
18401 Visit_List
(Parameter_Associations
(Expr
));
18403 raise Non_Preelaborable
;
18406 when N_If_Expression
=>
18407 Visit_List
(Expressions
(Expr
));
18409 when N_Quantified_Expression
=>
18410 Visit
(Condition
(Expr
));
18411 Visit
(Iterator_Specification
(Expr
));
18412 Visit
(Loop_Parameter_Specification
(Expr
));
18415 Visit
(High_Bound
(Expr
));
18416 Visit
(Low_Bound
(Expr
));
18419 Visit
(Discrete_Range
(Expr
));
18420 Visit
(Prefix
(Expr
));
18426 -- The evaluation of an object name is not preelaborable,
18427 -- unless the name is a static expression (checked further
18428 -- below), or statically denotes a discriminant.
18430 if Is_Entity_Name
(Expr
) then
18431 Object_Name
: declare
18432 Id
: constant Entity_Id
:= Entity
(Expr
);
18435 if Is_Object
(Id
) then
18436 if Ekind
(Id
) = E_Discriminant
then
18439 elsif Ekind
(Id
) in E_Constant | E_In_Parameter
18440 and then Present
(Discriminal_Link
(Id
))
18445 raise Non_Preelaborable
;
18450 -- A non-static expression is not preelaborable
18452 elsif not Is_OK_Static_Expression
(Expr
) then
18453 raise Non_Preelaborable
;
18456 end Visit_Subexpression
;
18458 -- Start of processing for Is_Non_Preelaborable_Construct
18463 -- At this point it is known that the construct is preelaborable
18469 -- The elaboration of the construct performs an action which violates
18470 -- preelaborability.
18472 when Non_Preelaborable
=>
18474 end Is_Non_Preelaborable_Construct
;
18476 ---------------------------------
18477 -- Is_Nontrivial_DIC_Procedure --
18478 ---------------------------------
18480 function Is_Nontrivial_DIC_Procedure
(Id
: Entity_Id
) return Boolean is
18481 Body_Decl
: Node_Id
;
18485 if Ekind
(Id
) = E_Procedure
and then Is_DIC_Procedure
(Id
) then
18487 Unit_Declaration_Node
18488 (Corresponding_Body
(Unit_Declaration_Node
(Id
)));
18490 -- The body of the Default_Initial_Condition procedure must contain
18491 -- at least one statement, otherwise the generation of the subprogram
18494 pragma Assert
(Present
(Handled_Statement_Sequence
(Body_Decl
)));
18496 -- To qualify as nontrivial, the first statement of the procedure
18497 -- must be a check in the form of an if statement. If the original
18498 -- Default_Initial_Condition expression was folded, then the first
18499 -- statement is not a check.
18501 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Body_Decl
)));
18504 Nkind
(Stmt
) = N_If_Statement
18505 and then Nkind
(Original_Node
(Stmt
)) = N_Pragma
;
18509 end Is_Nontrivial_DIC_Procedure
;
18511 -----------------------
18512 -- Is_Null_Extension --
18513 -----------------------
18515 function Is_Null_Extension
18516 (T
: Entity_Id
; Ignore_Privacy
: Boolean := False) return Boolean
18518 Type_Decl
: Node_Id
;
18519 Type_Def
: Node_Id
;
18521 pragma Assert
(not Is_Class_Wide_Type
(T
));
18523 if Ignore_Privacy
then
18524 Type_Decl
:= Parent
(Underlying_Type
(Base_Type
(T
)));
18526 Type_Decl
:= Parent
(Base_Type
(T
));
18527 if Nkind
(Type_Decl
) /= N_Full_Type_Declaration
then
18531 pragma Assert
(Nkind
(Type_Decl
) = N_Full_Type_Declaration
);
18532 Type_Def
:= Type_Definition
(Type_Decl
);
18533 if Present
(Discriminant_Specifications
(Type_Decl
))
18534 or else Nkind
(Type_Def
) /= N_Derived_Type_Definition
18535 or else not Is_Tagged_Type
(T
)
18536 or else No
(Record_Extension_Part
(Type_Def
))
18541 return Is_Null_Record_Definition
(Record_Extension_Part
(Type_Def
));
18542 end Is_Null_Extension
;
18544 --------------------------
18545 -- Is_Null_Extension_Of --
18546 --------------------------
18548 function Is_Null_Extension_Of
18549 (Descendant
, Ancestor
: Entity_Id
) return Boolean
18551 Ancestor_Type
: constant Entity_Id
18552 := Underlying_Type
(Base_Type
(Ancestor
));
18553 Descendant_Type
: Entity_Id
:= Underlying_Type
(Base_Type
(Descendant
));
18555 pragma Assert
(not Is_Class_Wide_Type
(Descendant
));
18556 pragma Assert
(not Is_Class_Wide_Type
(Ancestor
));
18557 pragma Assert
(Descendant_Type
/= Ancestor_Type
);
18559 while Descendant_Type
/= Ancestor_Type
loop
18560 if not Is_Null_Extension
18561 (Descendant_Type
, Ignore_Privacy
=> True)
18565 Descendant_Type
:= Etype
(Subtype_Indication
18566 (Type_Definition
(Parent
(Descendant_Type
))));
18567 Descendant_Type
:= Underlying_Type
(Base_Type
(Descendant_Type
));
18570 end Is_Null_Extension_Of
;
18572 -------------------------------
18573 -- Is_Null_Record_Definition --
18574 -------------------------------
18576 function Is_Null_Record_Definition
(Record_Def
: Node_Id
) return Boolean is
18579 -- Testing Null_Present is just an optimization, not required.
18581 if Null_Present
(Record_Def
) then
18583 elsif Present
(Variant_Part
(Component_List
(Record_Def
))) then
18585 elsif No
(Component_List
(Record_Def
)) then
18589 Item
:= First_Non_Pragma
(Component_Items
(Component_List
(Record_Def
)));
18591 while Present
(Item
) loop
18592 if Nkind
(Item
) = N_Component_Declaration
18593 and then Is_Internal_Name
(Chars
(Defining_Identifier
(Item
)))
18599 Next_Non_Pragma
(Item
);
18603 end Is_Null_Record_Definition
;
18605 -------------------------
18606 -- Is_Null_Record_Type --
18607 -------------------------
18609 function Is_Null_Record_Type
18610 (T
: Entity_Id
; Ignore_Privacy
: Boolean := False) return Boolean
18613 Type_Def
: Node_Id
;
18615 if not Is_Record_Type
(T
) then
18619 if Ignore_Privacy
then
18620 Decl
:= Parent
(Underlying_Type
(Base_Type
(T
)));
18622 Decl
:= Parent
(Base_Type
(T
));
18623 if Nkind
(Decl
) /= N_Full_Type_Declaration
then
18627 pragma Assert
(Nkind
(Decl
) = N_Full_Type_Declaration
);
18628 Type_Def
:= Type_Definition
(Decl
);
18630 if Has_Discriminants
(Defining_Identifier
(Decl
)) then
18634 case Nkind
(Type_Def
) is
18635 when N_Record_Definition
=>
18636 return Is_Null_Record_Definition
(Type_Def
);
18637 when N_Derived_Type_Definition
=>
18638 if not Is_Null_Record_Type
18639 (Etype
(Subtype_Indication
(Type_Def
)),
18640 Ignore_Privacy
=> Ignore_Privacy
)
18643 elsif not Is_Tagged_Type
(T
) then
18646 return Is_Null_Extension
(T
, Ignore_Privacy
=> Ignore_Privacy
);
18651 end Is_Null_Record_Type
;
18653 ---------------------
18654 -- Is_Object_Image --
18655 ---------------------
18657 function Is_Object_Image
(Prefix
: Node_Id
) return Boolean is
18659 -- Here we test for the case that the prefix is not a type and assume
18660 -- if it is not then it must be a named value or an object reference.
18661 -- This is because the parser always checks that prefixes of attributes
18664 return not (Is_Entity_Name
(Prefix
)
18665 and then Is_Type
(Entity
(Prefix
))
18666 and then not Is_Current_Instance
(Prefix
));
18667 end Is_Object_Image
;
18669 -------------------------
18670 -- Is_Object_Reference --
18671 -------------------------
18673 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
18674 function Safe_Prefix
(N
: Node_Id
) return Node_Id
;
18675 -- Return Prefix (N) unless it has been rewritten as an
18676 -- N_Raise_xxx_Error node, in which case return its original node.
18682 function Safe_Prefix
(N
: Node_Id
) return Node_Id
is
18684 if Nkind
(Prefix
(N
)) in N_Raise_xxx_Error
then
18685 return Original_Node
(Prefix
(N
));
18692 -- AI12-0068: Note that a current instance reference in a type or
18693 -- subtype's aspect_specification is considered a value, not an object
18694 -- (see RM 8.6(18/5)).
18696 if Is_Entity_Name
(N
) then
18697 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
))
18698 and then not Is_Current_Instance_Reference_In_Type_Aspect
(N
);
18702 when N_Indexed_Component
18706 Is_Object_Reference
(Safe_Prefix
(N
))
18707 or else Is_Access_Type
(Etype
(Safe_Prefix
(N
)));
18709 -- In Ada 95, a function call is a constant object; a procedure
18712 -- Note that predefined operators are functions as well, and so
18713 -- are attributes that are (can be renamed as) functions.
18715 when N_Function_Call
18718 return Etype
(N
) /= Standard_Void_Type
;
18720 -- Attributes references 'Loop_Entry, 'Old, 'Priority and 'Result
18721 -- yield objects, even though they are not functions.
18723 when N_Attribute_Reference
=>
18725 Attribute_Name
(N
) in Name_Loop_Entry
18729 or else Is_Function_Attribute_Name
(Attribute_Name
(N
));
18731 when N_Selected_Component
=>
18733 Is_Object_Reference
(Selector_Name
(N
))
18735 (Is_Object_Reference
(Safe_Prefix
(N
))
18736 or else Is_Access_Type
(Etype
(Safe_Prefix
(N
))));
18738 -- An explicit dereference denotes an object, except that a
18739 -- conditional expression gets turned into an explicit dereference
18740 -- in some cases, and conditional expressions are not object
18743 when N_Explicit_Dereference
=>
18744 return Nkind
(Original_Node
(N
)) not in
18745 N_Case_Expression | N_If_Expression
;
18747 -- A view conversion of a tagged object is an object reference
18749 when N_Type_Conversion
=>
18750 if Ada_Version
<= Ada_2012
then
18751 -- A view conversion of a tagged object is an object
18753 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
18754 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
18755 and then Is_Object_Reference
(Expression
(N
));
18758 -- AI12-0226: In Ada 2022 a value conversion of an object is
18761 return Is_Object_Reference
(Expression
(N
));
18764 -- An unchecked type conversion is considered to be an object if
18765 -- the operand is an object (this construction arises only as a
18766 -- result of expansion activities).
18768 when N_Unchecked_Type_Conversion
=>
18771 -- AI05-0003: In Ada 2012 a qualified expression is a name.
18772 -- This allows disambiguation of function calls and the use
18773 -- of aggregates in more contexts.
18775 when N_Qualified_Expression
=>
18776 return Ada_Version
>= Ada_2012
18777 and then Is_Object_Reference
(Expression
(N
));
18779 -- In Ada 95 an aggregate is an object reference
18782 | N_Delta_Aggregate
18783 | N_Extension_Aggregate
18785 return Ada_Version
>= Ada_95
;
18787 -- A string literal is not an object reference, but it might come
18788 -- from rewriting of an object reference, e.g. from folding of an
18791 when N_String_Literal
=>
18792 return Is_Rewrite_Substitution
(N
)
18793 and then Is_Object_Reference
(Original_Node
(N
));
18795 -- AI12-0125: Target name represents a constant object
18797 when N_Target_Name
=>
18804 end Is_Object_Reference
;
18806 -----------------------------------
18807 -- Is_OK_Variable_For_Out_Formal --
18808 -----------------------------------
18810 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
18812 Note_Possible_Modification
(AV
, Sure
=> True);
18814 -- We must reject parenthesized variable names. Comes_From_Source is
18815 -- checked because there are currently cases where the compiler violates
18816 -- this rule (e.g. passing a task object to its controlled Initialize
18817 -- routine). This should be properly documented in sinfo???
18819 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
18822 -- A variable is always allowed
18824 elsif Is_Variable
(AV
) then
18827 -- Generalized indexing operations are rewritten as explicit
18828 -- dereferences, and it is only during resolution that we can
18829 -- check whether the context requires an access_to_variable type.
18831 elsif Nkind
(AV
) = N_Explicit_Dereference
18832 and then Present
(Etype
(Original_Node
(AV
)))
18833 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
18834 and then Ada_Version
>= Ada_2012
18836 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
18838 -- Unchecked conversions are allowed only if they come from the
18839 -- generated code, which sometimes uses unchecked conversions for out
18840 -- parameters in cases where code generation is unaffected. We tell
18841 -- source unchecked conversions by seeing if they are rewrites of
18842 -- an original Unchecked_Conversion function call, or of an explicit
18843 -- conversion of a function call or an aggregate (as may happen in the
18844 -- expansion of a packed array aggregate).
18846 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
18847 if Nkind
(Original_Node
(AV
)) in N_Function_Call | N_Aggregate
then
18850 elsif Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
then
18853 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
18854 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
18860 -- Normal type conversions are allowed if argument is a variable
18862 elsif Nkind
(AV
) = N_Type_Conversion
then
18863 if Is_Variable
(Expression
(AV
))
18864 and then Paren_Count
(Expression
(AV
)) = 0
18866 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
18869 -- We also allow a non-parenthesized expression that raises
18870 -- constraint error if it rewrites what used to be a variable
18872 elsif Raises_Constraint_Error
(Expression
(AV
))
18873 and then Paren_Count
(Expression
(AV
)) = 0
18874 and then Is_Variable
(Original_Node
(Expression
(AV
)))
18878 -- Type conversion of something other than a variable
18884 -- If this node is rewritten, then test the original form, if that is
18885 -- OK, then we consider the rewritten node OK (for example, if the
18886 -- original node is a conversion, then Is_Variable will not be true
18887 -- but we still want to allow the conversion if it converts a variable).
18889 elsif Is_Rewrite_Substitution
(AV
) then
18890 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
18892 -- All other non-variables are rejected
18897 end Is_OK_Variable_For_Out_Formal
;
18899 ----------------------------
18900 -- Is_OK_Volatile_Context --
18901 ----------------------------
18903 function Is_OK_Volatile_Context
18904 (Context
: Node_Id
;
18906 Check_Actuals
: Boolean) return Boolean
18908 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean;
18909 -- Determine whether an arbitrary node denotes a call to a protected
18910 -- entry, function, or procedure in prefixed form where the prefix is
18913 function Within_Check
(Nod
: Node_Id
) return Boolean;
18914 -- Determine whether an arbitrary node appears in a check node
18916 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean;
18917 -- Determine whether an arbitrary entity appears in a volatile function
18919 ---------------------------------
18920 -- Is_Protected_Operation_Call --
18921 ---------------------------------
18923 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean is
18928 -- A call to a protected operations retains its selected component
18929 -- form as opposed to other prefixed calls that are transformed in
18932 if Nkind
(Nod
) = N_Selected_Component
then
18933 Pref
:= Prefix
(Nod
);
18934 Subp
:= Selector_Name
(Nod
);
18938 and then Present
(Etype
(Pref
))
18939 and then Is_Protected_Type
(Etype
(Pref
))
18940 and then Is_Entity_Name
(Subp
)
18941 and then Present
(Entity
(Subp
))
18942 and then Ekind
(Entity
(Subp
)) in
18943 E_Entry | E_Entry_Family | E_Function | E_Procedure
;
18947 end Is_Protected_Operation_Call
;
18953 function Within_Check
(Nod
: Node_Id
) return Boolean is
18957 -- Climb the parent chain looking for a check node
18960 while Present
(Par
) loop
18961 if Nkind
(Par
) in N_Raise_xxx_Error
then
18964 -- Prevent the search from going too far
18966 elsif Is_Body_Or_Package_Declaration
(Par
) then
18970 Par
:= Parent
(Par
);
18976 ------------------------------
18977 -- Within_Volatile_Function --
18978 ------------------------------
18980 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean is
18981 pragma Assert
(Ekind
(Id
) = E_Return_Statement
);
18983 Func_Id
: constant Entity_Id
:= Return_Applies_To
(Id
);
18986 pragma Assert
(Ekind
(Func_Id
) in E_Function | E_Generic_Function
);
18988 return Is_Volatile_Function
(Func_Id
);
18989 end Within_Volatile_Function
;
18993 Obj_Id
: Entity_Id
;
18995 -- Start of processing for Is_OK_Volatile_Context
18998 -- Ignore context restriction when doing preanalysis, e.g. on a copy of
18999 -- an expression function, because this copy is not fully decorated and
19000 -- it is not possible to reliably decide the legality of the context.
19001 -- Any violations will be reported anyway when doing the full analysis.
19003 if not Full_Analysis
then
19007 -- For actual parameters within explicit parameter associations switch
19008 -- the context to the corresponding subprogram call.
19010 if Nkind
(Context
) = N_Parameter_Association
then
19011 return Is_OK_Volatile_Context
(Context
=> Parent
(Context
),
19012 Obj_Ref
=> Obj_Ref
,
19013 Check_Actuals
=> Check_Actuals
);
19015 -- The volatile object appears on either side of an assignment
19017 elsif Nkind
(Context
) = N_Assignment_Statement
then
19020 -- The volatile object is part of the initialization expression of
19023 elsif Nkind
(Context
) = N_Object_Declaration
19024 and then Present
(Expression
(Context
))
19025 and then Expression
(Context
) = Obj_Ref
19026 and then Nkind
(Parent
(Context
)) /= N_Expression_With_Actions
19028 Obj_Id
:= Defining_Entity
(Context
);
19030 -- The volatile object acts as the initialization expression of an
19031 -- extended return statement. This is valid context as long as the
19032 -- function is volatile.
19034 if Is_Return_Object
(Obj_Id
) then
19035 return Within_Volatile_Function
(Scope
(Obj_Id
));
19037 -- Otherwise this is a normal object initialization
19043 -- The volatile object acts as the name of a renaming declaration
19045 elsif Nkind
(Context
) = N_Object_Renaming_Declaration
19046 and then Name
(Context
) = Obj_Ref
19050 -- The volatile object appears as an actual parameter in a call to an
19051 -- instance of Unchecked_Conversion whose result is renamed.
19053 elsif Nkind
(Context
) = N_Function_Call
19054 and then Is_Entity_Name
(Name
(Context
))
19055 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
19056 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
19060 -- The volatile object is actually the prefix in a protected entry,
19061 -- function, or procedure call.
19063 elsif Is_Protected_Operation_Call
(Context
) then
19066 -- The volatile object appears as the expression of a simple return
19067 -- statement that applies to a volatile function.
19069 elsif Nkind
(Context
) = N_Simple_Return_Statement
19070 and then Expression
(Context
) = Obj_Ref
19073 Within_Volatile_Function
(Return_Statement_Entity
(Context
));
19075 -- The volatile object appears as the prefix of a name occurring in a
19076 -- non-interfering context.
19078 elsif Nkind
(Context
) in
19079 N_Attribute_Reference |
19080 N_Explicit_Dereference |
19081 N_Indexed_Component |
19082 N_Selected_Component |
19084 and then Prefix
(Context
) = Obj_Ref
19085 and then Is_OK_Volatile_Context
19086 (Context
=> Parent
(Context
),
19087 Obj_Ref
=> Context
,
19088 Check_Actuals
=> Check_Actuals
)
19092 -- The volatile object appears as the prefix of attributes Address,
19093 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
19094 -- Position, Size, Storage_Size.
19096 elsif Nkind
(Context
) = N_Attribute_Reference
19097 and then Prefix
(Context
) = Obj_Ref
19098 and then Attribute_Name
(Context
) in Name_Address
19100 | Name_Component_Size
19108 | Name_Storage_Size
19112 -- The volatile object appears as the expression of a type conversion
19113 -- occurring in a non-interfering context.
19115 elsif Nkind
(Context
) in N_Qualified_Expression
19116 | N_Type_Conversion
19117 | N_Unchecked_Type_Conversion
19118 and then Expression
(Context
) = Obj_Ref
19119 and then Is_OK_Volatile_Context
19120 (Context
=> Parent
(Context
),
19121 Obj_Ref
=> Context
,
19122 Check_Actuals
=> Check_Actuals
)
19126 -- The volatile object appears as the expression in a delay statement
19128 elsif Nkind
(Context
) in N_Delay_Statement
then
19131 -- Allow references to volatile objects in various checks. This is not a
19132 -- direct SPARK 2014 requirement.
19134 elsif Within_Check
(Context
) then
19137 -- References to effectively volatile objects that appear as actual
19138 -- parameters in subprogram calls can be examined only after call itself
19139 -- has been resolved. Before that, assume such references to be legal.
19141 elsif Nkind
(Context
) in N_Subprogram_Call | N_Entry_Call_Statement
then
19142 if Check_Actuals
then
19145 Formal
: Entity_Id
;
19146 Subp
: constant Entity_Id
:= Get_Called_Entity
(Context
);
19148 Find_Actual
(Obj_Ref
, Formal
, Call
);
19149 pragma Assert
(Call
= Context
);
19151 -- An effectively volatile object may act as an actual when the
19152 -- corresponding formal is of a non-scalar effectively volatile
19153 -- type (SPARK RM 7.1.3(9)).
19155 if not Is_Scalar_Type
(Etype
(Formal
))
19156 and then Is_Effectively_Volatile_For_Reading
(Etype
(Formal
))
19160 -- An effectively volatile object may act as an actual in a
19161 -- call to an instance of Unchecked_Conversion. (SPARK RM
19164 elsif Is_Unchecked_Conversion_Instance
(Subp
) then
19177 end Is_OK_Volatile_Context
;
19179 ------------------------------------
19180 -- Is_Package_Contract_Annotation --
19181 ------------------------------------
19183 function Is_Package_Contract_Annotation
(Item
: Node_Id
) return Boolean is
19187 if Nkind
(Item
) = N_Aspect_Specification
then
19188 Nam
:= Chars
(Identifier
(Item
));
19190 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
19191 Nam
:= Pragma_Name
(Item
);
19194 return Nam
= Name_Abstract_State
19195 or else Nam
= Name_Initial_Condition
19196 or else Nam
= Name_Initializes
19197 or else Nam
= Name_Refined_State
;
19198 end Is_Package_Contract_Annotation
;
19200 -----------------------------------
19201 -- Is_Partially_Initialized_Type --
19202 -----------------------------------
19204 function Is_Partially_Initialized_Type
19206 Include_Implicit
: Boolean := True) return Boolean
19209 if Is_Scalar_Type
(Typ
) then
19210 return Has_Default_Aspect
(Base_Type
(Typ
));
19212 elsif Is_Access_Type
(Typ
) then
19213 return Include_Implicit
;
19215 elsif Is_Array_Type
(Typ
) then
19217 -- If component type is partially initialized, so is array type
19219 if Has_Default_Aspect
(Base_Type
(Typ
))
19220 or else Is_Partially_Initialized_Type
19221 (Component_Type
(Typ
), Include_Implicit
)
19225 -- Otherwise we are only partially initialized if we are fully
19226 -- initialized (this is the empty array case, no point in us
19227 -- duplicating that code here).
19230 return Is_Fully_Initialized_Type
(Typ
);
19233 elsif Is_Record_Type
(Typ
) then
19235 -- A discriminated type is always partially initialized if in
19238 if Has_Discriminants
(Typ
) and then Include_Implicit
then
19241 -- A tagged type is always partially initialized
19243 elsif Is_Tagged_Type
(Typ
) then
19246 -- Case of nondiscriminated record
19252 Component_Present
: Boolean := False;
19253 -- Set True if at least one component is present. If no
19254 -- components are present, then record type is fully
19255 -- initialized (another odd case, like the null array).
19258 -- Loop through components
19260 Comp
:= First_Component
(Typ
);
19261 while Present
(Comp
) loop
19262 Component_Present
:= True;
19264 -- If a component has an initialization expression then the
19265 -- enclosing record type is partially initialized
19267 if Present
(Parent
(Comp
))
19268 and then Present
(Expression
(Parent
(Comp
)))
19272 -- If a component is of a type which is itself partially
19273 -- initialized, then the enclosing record type is also.
19275 elsif Is_Partially_Initialized_Type
19276 (Etype
(Comp
), Include_Implicit
)
19281 Next_Component
(Comp
);
19284 -- No initialized components found. If we found any components
19285 -- they were all uninitialized so the result is false.
19287 if Component_Present
then
19290 -- But if we found no components, then all the components are
19291 -- initialized so we consider the type to be initialized.
19299 -- Concurrent types are always fully initialized
19301 elsif Is_Concurrent_Type
(Typ
) then
19304 -- For a private type, go to underlying type. If there is no underlying
19305 -- type then just assume this partially initialized. Not clear if this
19306 -- can happen in a non-error case, but no harm in testing for this.
19308 elsif Is_Private_Type
(Typ
) then
19310 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
19315 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
19319 -- For any other type (are there any?) assume partially initialized
19324 end Is_Partially_Initialized_Type
;
19326 ------------------------------------
19327 -- Is_Potentially_Persistent_Type --
19328 ------------------------------------
19330 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
19335 -- For private type, test corresponding full type
19337 if Is_Private_Type
(T
) then
19338 return Is_Potentially_Persistent_Type
(Full_View
(T
));
19340 -- Scalar types are potentially persistent
19342 elsif Is_Scalar_Type
(T
) then
19345 -- Record type is potentially persistent if not tagged and the types of
19346 -- all it components are potentially persistent, and no component has
19347 -- an initialization expression.
19349 elsif Is_Record_Type
(T
)
19350 and then not Is_Tagged_Type
(T
)
19351 and then not Is_Partially_Initialized_Type
(T
)
19353 Comp
:= First_Component
(T
);
19354 while Present
(Comp
) loop
19355 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
19358 Next_Entity
(Comp
);
19364 -- Array type is potentially persistent if its component type is
19365 -- potentially persistent and if all its constraints are static.
19367 elsif Is_Array_Type
(T
) then
19368 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
19372 Indx
:= First_Index
(T
);
19373 while Present
(Indx
) loop
19374 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
19383 -- All other types are not potentially persistent
19388 end Is_Potentially_Persistent_Type
;
19390 --------------------------------
19391 -- Is_Potentially_Unevaluated --
19392 --------------------------------
19394 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
19395 function Has_Null_Others_Choice
(Aggr
: Node_Id
) return Boolean;
19396 -- Aggr is an array aggregate with static bounds and an others clause;
19397 -- return True if the others choice of the given array aggregate does
19398 -- not cover any component (i.e. is null).
19400 function Immediate_Context_Implies_Is_Potentially_Unevaluated
19401 (Expr
: Node_Id
) return Boolean;
19402 -- Return True if the *immediate* context of this expression tells us
19403 -- that it is potentially unevaluated; return False if the *immediate*
19404 -- context doesn't provide an answer to this question and we need to
19407 function Non_Static_Or_Null_Range
(N
: Node_Id
) return Boolean;
19408 -- Return True if the given range is nonstatic or null
19410 ----------------------------
19411 -- Has_Null_Others_Choice --
19412 ----------------------------
19414 function Has_Null_Others_Choice
(Aggr
: Node_Id
) return Boolean is
19415 Idx
: constant Node_Id
:= First_Index
(Etype
(Aggr
));
19416 Hiv
: constant Uint
:= Expr_Value
(Type_High_Bound
(Etype
(Idx
)));
19417 Lov
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Etype
(Idx
)));
19421 Intervals
: constant Interval_Lists
.Discrete_Interval_List
:=
19422 Interval_Lists
.Aggregate_Intervals
(Aggr
);
19425 -- The others choice is null if, after normalization, we
19426 -- have a single interval covering the whole aggregate.
19428 return Intervals
'Length = 1
19430 Intervals
(Intervals
'First).Low
= Lov
19432 Intervals
(Intervals
'First).High
= Hiv
;
19435 -- If the aggregate is malformed (that is, indexes are not disjoint)
19436 -- then no action is needed at this stage; the error will be reported
19437 -- later by the frontend.
19440 when Interval_Lists
.Intervals_Error
=>
19442 end Has_Null_Others_Choice
;
19444 ----------------------------------------------------------
19445 -- Immediate_Context_Implies_Is_Potentially_Unevaluated --
19446 ----------------------------------------------------------
19448 function Immediate_Context_Implies_Is_Potentially_Unevaluated
19449 (Expr
: Node_Id
) return Boolean
19451 Par
: constant Node_Id
:= Parent
(Expr
);
19453 function Aggregate_Type
return Node_Id
is (Etype
(Parent
(Par
)));
19455 if Nkind
(Par
) = N_If_Expression
then
19456 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
19458 elsif Nkind
(Par
) = N_Case_Expression
then
19459 return Expr
/= Expression
(Par
);
19461 elsif Nkind
(Par
) in N_And_Then | N_Or_Else
then
19462 return Expr
= Right_Opnd
(Par
);
19464 elsif Nkind
(Par
) in N_In | N_Not_In
then
19466 -- If the membership includes several alternatives, only the first
19467 -- is definitely evaluated.
19469 if Present
(Alternatives
(Par
)) then
19470 return Expr
/= First
(Alternatives
(Par
));
19472 -- If this is a range membership both bounds are evaluated
19478 elsif Nkind
(Par
) = N_Quantified_Expression
then
19479 return Expr
= Condition
(Par
);
19481 elsif Nkind
(Par
) in N_Component_Association
19482 | N_Iterated_Component_Association
19483 and then Expr
= Expression
(Par
)
19484 and then Nkind
(Parent
(Par
))
19485 in N_Aggregate | N_Delta_Aggregate | N_Extension_Aggregate
19486 and then Present
(Aggregate_Type
)
19487 and then Aggregate_Type
/= Any_Composite
19489 if Is_Array_Type
(Aggregate_Type
) then
19490 if Ada_Version
>= Ada_2022
then
19491 -- For Ada 2022, this predicate returns True for
19492 -- any "repeatedly evaluated" expression.
19498 In_Others_Choice
: Boolean := False;
19499 Array_Agg
: constant Node_Id
:= Parent
(Par
);
19501 -- The expression of an array_component_association is
19502 -- potentially unevaluated if the associated choice is a
19503 -- subtype_indication or range that defines a nonstatic or
19506 Choice
:= First
(Choices
(Par
));
19507 while Present
(Choice
) loop
19508 if Nkind
(Choice
) = N_Range
19509 and then Non_Static_Or_Null_Range
(Choice
)
19513 elsif Nkind
(Choice
) = N_Identifier
19514 and then Present
(Scalar_Range
(Etype
(Choice
)))
19516 Non_Static_Or_Null_Range
19517 (Scalar_Range
(Etype
(Choice
)))
19521 elsif Nkind
(Choice
) = N_Others_Choice
then
19522 In_Others_Choice
:= True;
19528 -- It is also potentially unevaluated if the associated
19529 -- choice is an others choice and the applicable index
19530 -- constraint is nonstatic or null.
19532 if In_Others_Choice
then
19533 if not Compile_Time_Known_Bounds
(Aggregate_Type
) then
19536 return Has_Null_Others_Choice
(Array_Agg
);
19541 elsif Is_Container_Aggregate
(Parent
(Par
)) then
19542 -- a component of a container aggregate
19551 end Immediate_Context_Implies_Is_Potentially_Unevaluated
;
19553 ------------------------------
19554 -- Non_Static_Or_Null_Range --
19555 ------------------------------
19557 function Non_Static_Or_Null_Range
(N
: Node_Id
) return Boolean is
19558 Low
, High
: Node_Id
;
19561 Get_Index_Bounds
(N
, Low
, High
);
19563 -- Check static bounds
19565 if not Compile_Time_Known_Value
(Low
)
19566 or else not Compile_Time_Known_Value
(High
)
19570 -- Check null range
19572 elsif Expr_Value
(High
) < Expr_Value
(Low
) then
19577 end Non_Static_Or_Null_Range
;
19584 -- Start of processing for Is_Potentially_Unevaluated
19590 -- A postcondition whose expression is a short-circuit is broken down
19591 -- into individual aspects for better exception reporting. The original
19592 -- short-circuit expression is rewritten as the second operand, and an
19593 -- occurrence of 'Old in that operand is potentially unevaluated.
19594 -- See sem_ch13.adb for details of this transformation. The reference
19595 -- to 'Old may appear within an expression, so we must look for the
19596 -- enclosing pragma argument in the tree that contains the reference.
19598 while Present
(Par
)
19599 and then Nkind
(Par
) /= N_Pragma_Argument_Association
19601 if Is_Rewrite_Substitution
(Par
)
19602 and then Nkind
(Original_Node
(Par
)) = N_And_Then
19607 Par
:= Parent
(Par
);
19610 -- Other cases; 'Old appears within other expression (not the top-level
19611 -- conjunct in a postcondition) with a potentially unevaluated operand.
19613 Par
:= Parent
(Expr
);
19615 while Present
(Par
)
19616 and then Nkind
(Par
) /= N_Pragma_Argument_Association
19618 if Comes_From_Source
(Par
)
19620 Immediate_Context_Implies_Is_Potentially_Unevaluated
(Expr
)
19624 -- For component associations continue climbing; it may be part of an
19625 -- array aggregate. For iterated component association we know that
19626 -- it belongs to an array aggreate, but only its expression is
19627 -- potentially unevaluated, not discrete choice list or iterator
19630 elsif Nkind
(Par
) in N_Component_Association
19631 | N_Iterated_Component_Association
19635 -- If the context is not an expression, or if is the result of
19636 -- expansion of an enclosing construct (such as another attribute)
19637 -- the predicate does not apply.
19639 elsif Nkind
(Par
) = N_Case_Expression_Alternative
then
19642 elsif Nkind
(Par
) not in N_Subexpr
19643 or else not Comes_From_Source
(Par
)
19649 Par
:= Parent
(Par
);
19653 end Is_Potentially_Unevaluated
;
19655 -----------------------------------------
19656 -- Is_Predefined_Dispatching_Operation --
19657 -----------------------------------------
19659 function Is_Predefined_Dispatching_Operation
19660 (E
: Entity_Id
) return Boolean
19662 TSS_Name
: TSS_Name_Type
;
19665 if not Is_Dispatching_Operation
(E
) then
19669 Get_Name_String
(Chars
(E
));
19671 -- Most predefined primitives have internally generated names. Equality
19672 -- must be treated differently; the predefined operation is recognized
19673 -- as a homogeneous binary operator that returns Boolean.
19675 if Name_Len
> TSS_Name_Type
'Last then
19678 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
19680 if Chars
(E
) in Name_uAssign | Name_uSize
19682 (Chars
(E
) = Name_Op_Eq
19683 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
19684 or else TSS_Name
= TSS_Deep_Adjust
19685 or else TSS_Name
= TSS_Deep_Finalize
19686 or else TSS_Name
= TSS_Stream_Input
19687 or else TSS_Name
= TSS_Stream_Output
19688 or else TSS_Name
= TSS_Stream_Read
19689 or else TSS_Name
= TSS_Stream_Write
19690 or else TSS_Name
= TSS_Put_Image
19691 or else Is_Predefined_Interface_Primitive
(E
)
19698 end Is_Predefined_Dispatching_Operation
;
19700 ---------------------------------------
19701 -- Is_Predefined_Interface_Primitive --
19702 ---------------------------------------
19704 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
19706 -- In VM targets we don't restrict the functionality of this test to
19707 -- compiling in Ada 2005 mode since in VM targets any tagged type has
19708 -- these primitives.
19710 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
19711 and then Chars
(E
) in Name_uDisp_Asynchronous_Select
19712 | Name_uDisp_Conditional_Select
19713 | Name_uDisp_Get_Prim_Op_Kind
19714 | Name_uDisp_Get_Task_Id
19715 | Name_uDisp_Requeue
19716 | Name_uDisp_Timed_Select
;
19717 end Is_Predefined_Interface_Primitive
;
19719 ---------------------------------------
19720 -- Is_Predefined_Internal_Operation --
19721 ---------------------------------------
19723 function Is_Predefined_Internal_Operation
19724 (E
: Entity_Id
) return Boolean
19726 TSS_Name
: TSS_Name_Type
;
19729 if not Is_Dispatching_Operation
(E
) then
19733 Get_Name_String
(Chars
(E
));
19735 -- Most predefined primitives have internally generated names. Equality
19736 -- must be treated differently; the predefined operation is recognized
19737 -- as a homogeneous binary operator that returns Boolean.
19739 if Name_Len
> TSS_Name_Type
'Last then
19742 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
19744 if Chars
(E
) in Name_uSize | Name_uAssign
19746 (Chars
(E
) = Name_Op_Eq
19747 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
19748 or else TSS_Name
= TSS_Deep_Adjust
19749 or else TSS_Name
= TSS_Deep_Finalize
19750 or else Is_Predefined_Interface_Primitive
(E
)
19757 end Is_Predefined_Internal_Operation
;
19759 --------------------------------
19760 -- Is_Preelaborable_Aggregate --
19761 --------------------------------
19763 function Is_Preelaborable_Aggregate
(Aggr
: Node_Id
) return Boolean is
19764 Aggr_Typ
: constant Entity_Id
:= Etype
(Aggr
);
19765 Array_Aggr
: constant Boolean := Is_Array_Type
(Aggr_Typ
);
19767 Anc_Part
: Node_Id
;
19770 Comp_Typ
: Entity_Id
:= Empty
; -- init to avoid warning
19775 Comp_Typ
:= Component_Type
(Aggr_Typ
);
19778 -- Inspect the ancestor part
19780 if Nkind
(Aggr
) = N_Extension_Aggregate
then
19781 Anc_Part
:= Ancestor_Part
(Aggr
);
19783 -- The ancestor denotes a subtype mark
19785 if Is_Entity_Name
(Anc_Part
)
19786 and then Is_Type
(Entity
(Anc_Part
))
19788 if not Has_Preelaborable_Initialization
(Entity
(Anc_Part
)) then
19792 -- Otherwise the ancestor denotes an expression
19794 elsif not Is_Preelaborable_Construct
(Anc_Part
) then
19799 -- Inspect the positional associations
19801 Expr
:= First
(Expressions
(Aggr
));
19802 while Present
(Expr
) loop
19803 if not Is_Preelaborable_Construct
(Expr
) then
19810 -- Inspect the named associations
19812 Assoc
:= First
(Component_Associations
(Aggr
));
19813 while Present
(Assoc
) loop
19815 -- Inspect the choices of the current named association
19817 Choice
:= First
(Choices
(Assoc
));
19818 while Present
(Choice
) loop
19821 -- For a choice to be preelaborable, it must denote either a
19822 -- static range or a static expression.
19824 if Nkind
(Choice
) = N_Others_Choice
then
19827 elsif Nkind
(Choice
) = N_Range
then
19828 if not Is_OK_Static_Range
(Choice
) then
19832 elsif not Is_OK_Static_Expression
(Choice
) then
19837 Comp_Typ
:= Etype
(Choice
);
19843 -- The type of the choice must have preelaborable initialization if
19844 -- the association carries a <>.
19846 pragma Assert
(Present
(Comp_Typ
));
19847 if Box_Present
(Assoc
) then
19848 if not Has_Preelaborable_Initialization
(Comp_Typ
) then
19852 -- The type of the expression must have preelaborable initialization
19854 elsif not Is_Preelaborable_Construct
(Expression
(Assoc
)) then
19861 -- At this point the aggregate is preelaborable
19864 end Is_Preelaborable_Aggregate
;
19866 --------------------------------
19867 -- Is_Preelaborable_Construct --
19868 --------------------------------
19870 function Is_Preelaborable_Construct
(N
: Node_Id
) return Boolean is
19874 if Nkind
(N
) in N_Aggregate | N_Extension_Aggregate
then
19875 return Is_Preelaborable_Aggregate
(N
);
19877 -- Attributes are allowed in general, even if their prefix is a formal
19878 -- type. It seems that certain attributes known not to be static might
19879 -- not be allowed, but there are no rules to prevent them.
19881 elsif Nkind
(N
) = N_Attribute_Reference
then
19886 elsif Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
19889 elsif Nkind
(N
) = N_Qualified_Expression
then
19890 return Is_Preelaborable_Construct
(Expression
(N
));
19892 -- Names are preelaborable when they denote a discriminant of an
19893 -- enclosing type. Discriminals are also considered for this check.
19895 elsif Is_Entity_Name
(N
)
19896 and then Present
(Entity
(N
))
19898 (Ekind
(Entity
(N
)) = E_Discriminant
19899 or else (Ekind
(Entity
(N
)) in E_Constant | E_In_Parameter
19900 and then Present
(Discriminal_Link
(Entity
(N
)))))
19906 elsif Nkind
(N
) = N_Null
then
19909 -- Ada 2022 (AI12-0175): Calls to certain functions that are essentially
19910 -- unchecked conversions are preelaborable.
19912 elsif Ada_Version
>= Ada_2022
19913 and then Nkind
(N
) = N_Function_Call
19914 and then Is_Entity_Name
(Name
(N
))
19915 and then Is_Preelaborable_Function
(Entity
(Name
(N
)))
19920 A
:= First_Actual
(N
);
19922 while Present
(A
) loop
19923 if not Is_Preelaborable_Construct
(A
) then
19933 -- Otherwise the construct is not preelaborable
19938 end Is_Preelaborable_Construct
;
19940 -------------------------------
19941 -- Is_Preelaborable_Function --
19942 -------------------------------
19944 function Is_Preelaborable_Function
(Id
: Entity_Id
) return Boolean is
19945 SATAC
: constant Rtsfind
.RTU_Id
:= System_Address_To_Access_Conversions
;
19946 Scop
: constant Entity_Id
:= Scope
(Id
);
19949 -- Small optimization: every allowed function has convention Intrinsic
19950 -- (see Analyze_Subprogram_Instantiation for the subtlety in the test).
19952 if not Is_Intrinsic_Subprogram
(Id
)
19953 and then Convention
(Id
) /= Convention_Intrinsic
19958 -- An instance of Unchecked_Conversion
19960 if Is_Unchecked_Conversion_Instance
(Id
) then
19964 -- A function declared in System.Storage_Elements
19966 if Is_RTU
(Scop
, System_Storage_Elements
) then
19970 -- The functions To_Pointer and To_Address declared in an instance of
19971 -- System.Address_To_Access_Conversions (they are the only ones).
19973 if Ekind
(Scop
) = E_Package
19974 and then Nkind
(Parent
(Scop
)) = N_Package_Specification
19975 and then Present
(Generic_Parent
(Parent
(Scop
)))
19976 and then Is_RTU
(Generic_Parent
(Parent
(Scop
)), SATAC
)
19982 end Is_Preelaborable_Function
;
19984 -----------------------------
19985 -- Is_Private_Library_Unit --
19986 -----------------------------
19988 function Is_Private_Library_Unit
(Unit
: Entity_Id
) return Boolean is
19989 Comp_Unit
: constant Node_Id
:= Parent
(Unit_Declaration_Node
(Unit
));
19991 return Nkind
(Comp_Unit
) = N_Compilation_Unit
19992 and then Private_Present
(Comp_Unit
);
19993 end Is_Private_Library_Unit
;
19995 ---------------------------------
19996 -- Is_Protected_Self_Reference --
19997 ---------------------------------
19999 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
20001 function In_Access_Definition
(N
: Node_Id
) return Boolean;
20002 -- Returns true if N belongs to an access definition
20004 --------------------------
20005 -- In_Access_Definition --
20006 --------------------------
20008 function In_Access_Definition
(N
: Node_Id
) return Boolean is
20013 while Present
(P
) loop
20014 if Nkind
(P
) = N_Access_Definition
then
20022 end In_Access_Definition
;
20024 -- Start of processing for Is_Protected_Self_Reference
20027 -- Verify that prefix is analyzed and has the proper form. Note that
20028 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
20029 -- produce the address of an entity, do not analyze their prefix
20030 -- because they denote entities that are not necessarily visible.
20031 -- Neither of them can apply to a protected type.
20033 return Ada_Version
>= Ada_2005
20034 and then Is_Entity_Name
(N
)
20035 and then Present
(Entity
(N
))
20036 and then Is_Protected_Type
(Entity
(N
))
20037 and then In_Open_Scopes
(Entity
(N
))
20038 and then not In_Access_Definition
(N
);
20039 end Is_Protected_Self_Reference
;
20041 -----------------------------
20042 -- Is_RCI_Pkg_Spec_Or_Body --
20043 -----------------------------
20045 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
20047 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
20048 -- Return True if the unit of Cunit is an RCI package declaration
20050 ---------------------------
20051 -- Is_RCI_Pkg_Decl_Cunit --
20052 ---------------------------
20054 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
20055 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
20058 if Nkind
(The_Unit
) /= N_Package_Declaration
then
20062 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
20063 end Is_RCI_Pkg_Decl_Cunit
;
20065 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
20068 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
20070 (Nkind
(Unit
(Cunit
)) = N_Package_Body
20071 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
20072 end Is_RCI_Pkg_Spec_Or_Body
;
20074 -----------------------------------------
20075 -- Is_Remote_Access_To_Class_Wide_Type --
20076 -----------------------------------------
20078 function Is_Remote_Access_To_Class_Wide_Type
20079 (E
: Entity_Id
) return Boolean
20082 -- A remote access to class-wide type is a general access to object type
20083 -- declared in the visible part of a Remote_Types or Remote_Call_
20086 return Ekind
(E
) = E_General_Access_Type
20087 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
20088 end Is_Remote_Access_To_Class_Wide_Type
;
20090 -----------------------------------------
20091 -- Is_Remote_Access_To_Subprogram_Type --
20092 -----------------------------------------
20094 function Is_Remote_Access_To_Subprogram_Type
20095 (E
: Entity_Id
) return Boolean
20098 return (Ekind
(E
) = E_Access_Subprogram_Type
20099 or else (Ekind
(E
) = E_Record_Type
20100 and then Present
(Corresponding_Remote_Type
(E
))))
20101 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
20102 end Is_Remote_Access_To_Subprogram_Type
;
20104 --------------------
20105 -- Is_Remote_Call --
20106 --------------------
20108 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
20110 if Nkind
(N
) not in N_Subprogram_Call
then
20112 -- An entry call cannot be remote
20116 elsif Nkind
(Name
(N
)) in N_Has_Entity
20117 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
20119 -- A subprogram declared in the spec of a RCI package is remote
20123 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
20124 and then Is_Remote_Access_To_Subprogram_Type
20125 (Etype
(Prefix
(Name
(N
))))
20127 -- The dereference of a RAS is a remote call
20131 elsif Present
(Controlling_Argument
(N
))
20132 and then Is_Remote_Access_To_Class_Wide_Type
20133 (Etype
(Controlling_Argument
(N
)))
20135 -- Any primitive operation call with a controlling argument of
20136 -- a RACW type is a remote call.
20141 -- All other calls are local calls
20144 end Is_Remote_Call
;
20146 ----------------------
20147 -- Is_Renamed_Entry --
20148 ----------------------
20150 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
20151 Orig_Node
: Node_Id
:= Empty
;
20152 Subp_Decl
: Node_Id
:=
20153 (if No
(Parent
(Proc_Nam
)) then Empty
else Parent
(Parent
(Proc_Nam
)));
20155 function Is_Entry
(Nam
: Node_Id
) return Boolean;
20156 -- Determine whether Nam is an entry. Traverse selectors if there are
20157 -- nested selected components.
20163 function Is_Entry
(Nam
: Node_Id
) return Boolean is
20165 if Nkind
(Nam
) = N_Selected_Component
then
20166 return Is_Entry
(Selector_Name
(Nam
));
20169 return Ekind
(Entity
(Nam
)) = E_Entry
;
20172 -- Start of processing for Is_Renamed_Entry
20175 if Present
(Alias
(Proc_Nam
)) then
20176 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
20179 -- Look for a rewritten subprogram renaming declaration
20181 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
20182 and then Present
(Original_Node
(Subp_Decl
))
20184 Orig_Node
:= Original_Node
(Subp_Decl
);
20187 -- The rewritten subprogram is actually an entry
20189 if Present
(Orig_Node
)
20190 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
20191 and then Is_Entry
(Name
(Orig_Node
))
20197 end Is_Renamed_Entry
;
20199 ----------------------------
20200 -- Is_Reversible_Iterator --
20201 ----------------------------
20203 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
20204 Ifaces_List
: Elist_Id
;
20205 Iface_Elmt
: Elmt_Id
;
20209 if Is_Class_Wide_Type
(Typ
)
20210 and then Chars
(Root_Type
(Typ
)) = Name_Reversible_Iterator
20211 and then In_Predefined_Unit
(Root_Type
(Typ
))
20215 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
20219 Collect_Interfaces
(Typ
, Ifaces_List
);
20221 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
20222 while Present
(Iface_Elmt
) loop
20223 Iface
:= Node
(Iface_Elmt
);
20224 if Chars
(Iface
) = Name_Reversible_Iterator
20225 and then In_Predefined_Unit
(Iface
)
20230 Next_Elmt
(Iface_Elmt
);
20235 end Is_Reversible_Iterator
;
20237 ---------------------------------
20238 -- Is_Single_Concurrent_Object --
20239 ---------------------------------
20241 function Is_Single_Concurrent_Object
(Id
: Entity_Id
) return Boolean is
20244 Is_Single_Protected_Object
(Id
) or else Is_Single_Task_Object
(Id
);
20245 end Is_Single_Concurrent_Object
;
20247 -------------------------------
20248 -- Is_Single_Concurrent_Type --
20249 -------------------------------
20251 function Is_Single_Concurrent_Type
(Id
: Entity_Id
) return Boolean is
20254 Ekind
(Id
) in E_Protected_Type | E_Task_Type
20255 and then Is_Single_Concurrent_Type_Declaration
20256 (Declaration_Node
(Id
));
20257 end Is_Single_Concurrent_Type
;
20259 -------------------------------------------
20260 -- Is_Single_Concurrent_Type_Declaration --
20261 -------------------------------------------
20263 function Is_Single_Concurrent_Type_Declaration
20264 (N
: Node_Id
) return Boolean
20267 return Nkind
(Original_Node
(N
)) in
20268 N_Single_Protected_Declaration | N_Single_Task_Declaration
;
20269 end Is_Single_Concurrent_Type_Declaration
;
20271 ---------------------------------------------
20272 -- Is_Single_Precision_Floating_Point_Type --
20273 ---------------------------------------------
20275 function Is_Single_Precision_Floating_Point_Type
20276 (E
: Entity_Id
) return Boolean is
20278 return Is_Floating_Point_Type
(E
)
20279 and then Machine_Radix_Value
(E
) = Uint_2
20280 and then Machine_Mantissa_Value
(E
) = Uint_24
20281 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_7
20282 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_7
);
20283 end Is_Single_Precision_Floating_Point_Type
;
20285 --------------------------------
20286 -- Is_Single_Protected_Object --
20287 --------------------------------
20289 function Is_Single_Protected_Object
(Id
: Entity_Id
) return Boolean is
20292 Ekind
(Id
) = E_Variable
20293 and then Ekind
(Etype
(Id
)) = E_Protected_Type
20294 and then Is_Single_Concurrent_Type
(Etype
(Id
));
20295 end Is_Single_Protected_Object
;
20297 ---------------------------
20298 -- Is_Single_Task_Object --
20299 ---------------------------
20301 function Is_Single_Task_Object
(Id
: Entity_Id
) return Boolean is
20304 Ekind
(Id
) = E_Variable
20305 and then Ekind
(Etype
(Id
)) = E_Task_Type
20306 and then Is_Single_Concurrent_Type
(Etype
(Id
));
20307 end Is_Single_Task_Object
;
20309 -----------------------------
20310 -- Is_Specific_Tagged_Type --
20311 -----------------------------
20313 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
20314 Full_Typ
: Entity_Id
;
20317 -- Handle private types
20319 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
20320 Full_Typ
:= Full_View
(Typ
);
20325 -- A specific tagged type is a non-class-wide tagged type
20327 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
20328 end Is_Specific_Tagged_Type
;
20334 function Is_Statement
(N
: Node_Id
) return Boolean is
20337 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
20338 or else Nkind
(N
) = N_Procedure_Call_Statement
;
20341 --------------------------------------
20342 -- Is_Static_Discriminant_Component --
20343 --------------------------------------
20345 function Is_Static_Discriminant_Component
(N
: Node_Id
) return Boolean is
20347 return Nkind
(N
) = N_Selected_Component
20348 and then not Is_In_Discriminant_Check
(N
)
20349 and then Present
(Etype
(Prefix
(N
)))
20350 and then Ekind
(Etype
(Prefix
(N
))) = E_Record_Subtype
20351 and then Has_Static_Discriminants
(Etype
(Prefix
(N
)))
20352 and then Present
(Entity
(Selector_Name
(N
)))
20353 and then Ekind
(Entity
(Selector_Name
(N
))) = E_Discriminant
20354 and then not In_Check_Node
(N
);
20355 end Is_Static_Discriminant_Component
;
20357 ------------------------
20358 -- Is_Static_Function --
20359 ------------------------
20361 function Is_Static_Function
(Subp
: Entity_Id
) return Boolean is
20363 -- Always return False for pre Ada 2022 to e.g. ignore the Static
20364 -- aspect in package Interfaces for Ada_Version < 2022 and also
20367 return Ada_Version
>= Ada_2022
20368 and then Has_Aspect
(Subp
, Aspect_Static
)
20370 (No
(Find_Value_Of_Aspect
(Subp
, Aspect_Static
))
20371 or else Is_True
(Static_Boolean
20372 (Find_Value_Of_Aspect
(Subp
, Aspect_Static
))));
20373 end Is_Static_Function
;
20375 -----------------------------
20376 -- Is_Static_Function_Call --
20377 -----------------------------
20379 function Is_Static_Function_Call
(Call
: Node_Id
) return Boolean is
20380 function Has_All_Static_Actuals
(Call
: Node_Id
) return Boolean;
20381 -- Return whether all actual parameters of Call are static expressions
20383 ----------------------------
20384 -- Has_All_Static_Actuals --
20385 ----------------------------
20387 function Has_All_Static_Actuals
(Call
: Node_Id
) return Boolean is
20388 Actual
: Node_Id
:= First_Actual
(Call
);
20389 String_Result
: constant Boolean :=
20390 Is_String_Type
(Etype
(Entity
(Name
(Call
))));
20393 while Present
(Actual
) loop
20394 if not Is_Static_Expression
(Actual
) then
20396 -- ??? In the string-returning case we want to avoid a call
20397 -- being made to Establish_Transient_Scope in Resolve_Call,
20398 -- but at the point where that's tested for (which now includes
20399 -- a call to test Is_Static_Function_Call), the actuals of the
20400 -- call haven't been resolved, so expressions of the actuals
20401 -- may not have been marked Is_Static_Expression yet, so we
20402 -- force them to be resolved here, so we can tell if they're
20403 -- static. Calling Resolve here is admittedly a kludge, and we
20404 -- limit this call to string-returning cases.
20406 if String_Result
then
20410 -- Test flag again in case it's now True due to above Resolve
20412 if not Is_Static_Expression
(Actual
) then
20417 Next_Actual
(Actual
);
20421 end Has_All_Static_Actuals
;
20424 return Nkind
(Call
) = N_Function_Call
20425 and then Is_Entity_Name
(Name
(Call
))
20426 and then Is_Static_Function
(Entity
(Name
(Call
)))
20427 and then Has_All_Static_Actuals
(Call
);
20428 end Is_Static_Function_Call
;
20430 -------------------------------------------
20431 -- Is_Subcomponent_Of_Full_Access_Object --
20432 -------------------------------------------
20434 function Is_Subcomponent_Of_Full_Access_Object
(N
: Node_Id
) return Boolean
20439 R
:= Get_Referenced_Object
(N
);
20441 while Nkind
(R
) in N_Indexed_Component | N_Selected_Component | N_Slice
20443 R
:= Get_Referenced_Object
(Prefix
(R
));
20445 -- If the prefix is an access value, only the designated type matters
20447 if Is_Access_Type
(Etype
(R
)) then
20448 if Is_Full_Access
(Designated_Type
(Etype
(R
))) then
20453 if Is_Full_Access_Object
(R
) then
20460 end Is_Subcomponent_Of_Full_Access_Object
;
20462 ---------------------------------------
20463 -- Is_Subprogram_Contract_Annotation --
20464 ---------------------------------------
20466 function Is_Subprogram_Contract_Annotation
20467 (Item
: Node_Id
) return Boolean
20472 if Nkind
(Item
) = N_Aspect_Specification
then
20473 Nam
:= Chars
(Identifier
(Item
));
20475 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
20476 Nam
:= Pragma_Name
(Item
);
20479 return Nam
= Name_Always_Terminates
20480 or else Nam
= Name_Contract_Cases
20481 or else Nam
= Name_Depends
20482 or else Nam
= Name_Exceptional_Cases
20483 or else Nam
= Name_Extensions_Visible
20484 or else Nam
= Name_Global
20485 or else Nam
= Name_Post
20486 or else Nam
= Name_Post_Class
20487 or else Nam
= Name_Postcondition
20488 or else Nam
= Name_Pre
20489 or else Nam
= Name_Pre_Class
20490 or else Nam
= Name_Precondition
20491 or else Nam
= Name_Refined_Depends
20492 or else Nam
= Name_Refined_Global
20493 or else Nam
= Name_Refined_Post
20494 or else Nam
= Name_Subprogram_Variant
20495 or else Nam
= Name_Test_Case
;
20496 end Is_Subprogram_Contract_Annotation
;
20498 --------------------------------------------------
20499 -- Is_Subprogram_Stub_Without_Prior_Declaration --
20500 --------------------------------------------------
20502 function Is_Subprogram_Stub_Without_Prior_Declaration
20503 (N
: Node_Id
) return Boolean
20506 pragma Assert
(Nkind
(N
) = N_Subprogram_Body_Stub
);
20508 case Ekind
(Defining_Entity
(N
)) is
20510 -- A subprogram stub without prior declaration serves as declaration
20511 -- for the actual subprogram body. As such, it has an attached
20512 -- defining entity of E_Function or E_Procedure.
20519 -- Otherwise, it is completes a [generic] subprogram declaration
20521 when E_Generic_Function
20522 | E_Generic_Procedure
20523 | E_Subprogram_Body
20528 raise Program_Error
;
20530 end Is_Subprogram_Stub_Without_Prior_Declaration
;
20532 ---------------------------
20533 -- Is_Suitable_Primitive --
20534 ---------------------------
20536 function Is_Suitable_Primitive
(Subp_Id
: Entity_Id
) return Boolean is
20538 -- The Default_Initial_Condition and invariant procedures must not be
20539 -- treated as primitive operations even when they apply to a tagged
20540 -- type. These routines must not act as targets of dispatching calls
20541 -- because they already utilize class-wide-precondition semantics to
20542 -- handle inheritance and overriding.
20544 if Ekind
(Subp_Id
) = E_Procedure
20545 and then (Is_DIC_Procedure
(Subp_Id
)
20547 Is_Invariant_Procedure
(Subp_Id
))
20553 end Is_Suitable_Primitive
;
20555 ----------------------------
20556 -- Is_Synchronized_Object --
20557 ----------------------------
20559 function Is_Synchronized_Object
(Id
: Entity_Id
) return Boolean is
20563 if Is_Object
(Id
) then
20565 -- The object is synchronized if it is of a type that yields a
20566 -- synchronized object.
20568 if Yields_Synchronized_Object
(Etype
(Id
)) then
20571 -- The object is synchronized if it is atomic and Async_Writers is
20574 elsif Is_Atomic_Object_Entity
(Id
)
20575 and then Async_Writers_Enabled
(Id
)
20579 -- A constant is a synchronized object by default, unless its type is
20580 -- access-to-variable type.
20582 elsif Ekind
(Id
) = E_Constant
20583 and then not Is_Access_Variable
(Etype
(Id
))
20587 -- A variable is a synchronized object if it is subject to pragma
20588 -- Constant_After_Elaboration.
20590 elsif Ekind
(Id
) = E_Variable
then
20591 Prag
:= Get_Pragma
(Id
, Pragma_Constant_After_Elaboration
);
20593 return Present
(Prag
) and then Is_Enabled_Pragma
(Prag
);
20597 -- Otherwise the input is not an object or it does not qualify as a
20598 -- synchronized object.
20601 end Is_Synchronized_Object
;
20603 ---------------------------------
20604 -- Is_Synchronized_Tagged_Type --
20605 ---------------------------------
20607 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
20608 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
20611 -- A task or protected type derived from an interface is a tagged type.
20612 -- Such a tagged type is called a synchronized tagged type, as are
20613 -- synchronized interfaces and private extensions whose declaration
20614 -- includes the reserved word synchronized.
20616 return (Is_Tagged_Type
(E
)
20617 and then (Kind
= E_Task_Type
20619 Kind
= E_Protected_Type
))
20622 and then Is_Synchronized_Interface
(E
))
20624 (Ekind
(E
) = E_Record_Type_With_Private
20625 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
20626 and then (Synchronized_Present
(Parent
(E
))
20627 or else Is_Synchronized_Interface
(Etype
(E
))));
20628 end Is_Synchronized_Tagged_Type
;
20634 function Is_Transfer
(N
: Node_Id
) return Boolean is
20635 Kind
: constant Node_Kind
:= Nkind
(N
);
20638 if Kind
in N_Simple_Return_Statement
20639 | N_Extended_Return_Statement
20641 | N_Raise_Statement
20642 | N_Requeue_Statement
20646 elsif Kind
in N_Exit_Statement | N_Raise_xxx_Error
20647 and then No
(Condition
(N
))
20651 elsif Kind
= N_Procedure_Call_Statement
20652 and then Is_Entity_Name
(Name
(N
))
20653 and then Present
(Entity
(Name
(N
)))
20654 and then No_Return
(Entity
(Name
(N
)))
20658 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
20670 function Is_True
(U
: Opt_Ubool
) return Boolean is
20672 return No
(U
) or else U
= Uint_1
;
20675 ------------------------
20676 -- Is_Trivial_Boolean --
20677 ------------------------
20679 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
20681 return Comes_From_Source
(N
)
20682 and then Nkind
(N
) in N_Identifier | N_Expanded_Name
20683 and then Entity
(N
) in Standard_True | Standard_False
;
20684 end Is_Trivial_Boolean
;
20686 --------------------------------------
20687 -- Is_Unchecked_Conversion_Instance --
20688 --------------------------------------
20690 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
20694 -- Look for a function whose generic parent is the predefined intrinsic
20695 -- function Unchecked_Conversion, or for one that renames such an
20698 if Ekind
(Id
) = E_Function
then
20699 Par
:= Parent
(Id
);
20701 if Nkind
(Par
) = N_Function_Specification
then
20702 Par
:= Generic_Parent
(Par
);
20704 if Present
(Par
) then
20706 Chars
(Par
) = Name_Unchecked_Conversion
20707 and then Is_Intrinsic_Subprogram
(Par
)
20708 and then In_Predefined_Unit
(Par
);
20711 Present
(Alias
(Id
))
20712 and then Is_Unchecked_Conversion_Instance
(Alias
(Id
));
20718 end Is_Unchecked_Conversion_Instance
;
20720 -------------------------------
20721 -- Is_Universal_Numeric_Type --
20722 -------------------------------
20724 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
20726 return T
= Universal_Integer
or else T
= Universal_Real
;
20727 end Is_Universal_Numeric_Type
;
20729 ------------------------------
20730 -- Is_User_Defined_Equality --
20731 ------------------------------
20733 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean is
20734 F1
, F2
: Entity_Id
;
20737 -- An equality operator is a function that carries the name "=", returns
20738 -- Boolean, and has exactly two formal parameters of an identical type.
20740 if Ekind
(Id
) = E_Function
20741 and then Chars
(Id
) = Name_Op_Eq
20742 and then Base_Type
(Etype
(Id
)) = Standard_Boolean
20744 F1
:= First_Formal
(Id
);
20750 F2
:= Next_Formal
(F1
);
20752 return Present
(F2
)
20753 and then No
(Next_Formal
(F2
))
20754 and then Base_Type
(Etype
(F1
)) = Base_Type
(Etype
(F2
));
20759 end Is_User_Defined_Equality
;
20761 -----------------------------
20762 -- Is_User_Defined_Literal --
20763 -----------------------------
20765 function Is_User_Defined_Literal
20767 Typ
: Entity_Id
) return Boolean
20769 Literal_Aspect_Map
:
20770 constant array (N_Numeric_Or_String_Literal
) of Aspect_Id
:=
20771 (N_Integer_Literal
=> Aspect_Integer_Literal
,
20772 N_Interpolated_String_Literal
=> No_Aspect
,
20773 N_Real_Literal
=> Aspect_Real_Literal
,
20774 N_String_Literal
=> Aspect_String_Literal
);
20777 -- Return True when N is either a literal or a named number and the
20778 -- type has the appropriate user-defined literal aspect.
20780 return (Nkind
(N
) in N_Numeric_Or_String_Literal
20781 and then Has_Aspect
(Typ
, Literal_Aspect_Map
(Nkind
(N
))))
20783 (Is_Entity_Name
(N
)
20784 and then Present
(Entity
(N
))
20786 ((Ekind
(Entity
(N
)) = E_Named_Integer
20787 and then Has_Aspect
(Typ
, Aspect_Integer_Literal
))
20789 (Ekind
(Entity
(N
)) = E_Named_Real
20790 and then Has_Aspect
(Typ
, Aspect_Real_Literal
))));
20791 end Is_User_Defined_Literal
;
20793 --------------------------------------
20794 -- Is_Validation_Variable_Reference --
20795 --------------------------------------
20797 function Is_Validation_Variable_Reference
(N
: Node_Id
) return Boolean is
20798 Var
: constant Node_Id
:= Unqual_Conv
(N
);
20799 Var_Id
: Entity_Id
;
20804 if Is_Entity_Name
(Var
) then
20805 Var_Id
:= Entity
(Var
);
20810 and then Ekind
(Var_Id
) = E_Variable
20811 and then Present
(Validated_Object
(Var_Id
));
20812 end Is_Validation_Variable_Reference
;
20814 ----------------------------
20815 -- Is_Variable_Size_Array --
20816 ----------------------------
20818 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
20822 pragma Assert
(Is_Array_Type
(E
));
20824 -- Check if some index is initialized with a non-constant value
20826 Idx
:= First_Index
(E
);
20827 while Present
(Idx
) loop
20828 if Nkind
(Idx
) = N_Range
then
20829 if not Is_Constant_Bound
(Low_Bound
(Idx
))
20830 or else not Is_Constant_Bound
(High_Bound
(Idx
))
20840 end Is_Variable_Size_Array
;
20842 -----------------------------
20843 -- Is_Variable_Size_Record --
20844 -----------------------------
20846 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
20848 Comp_Typ
: Entity_Id
;
20851 pragma Assert
(Is_Record_Type
(E
));
20853 Comp
:= First_Component
(E
);
20854 while Present
(Comp
) loop
20855 Comp_Typ
:= Underlying_Type
(Etype
(Comp
));
20857 -- Recursive call if the record type has discriminants
20859 if Is_Record_Type
(Comp_Typ
)
20860 and then Has_Discriminants
(Comp_Typ
)
20861 and then Is_Variable_Size_Record
(Comp_Typ
)
20865 elsif Is_Array_Type
(Comp_Typ
)
20866 and then Is_Variable_Size_Array
(Comp_Typ
)
20871 Next_Component
(Comp
);
20875 end Is_Variable_Size_Record
;
20881 -- Should Is_Variable be refactored to better handle dereferences and
20882 -- technical debt ???
20884 function Is_Variable
20886 Use_Original_Node
: Boolean := True) return Boolean
20888 Orig_Node
: Node_Id
;
20890 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
20891 -- Within a protected function, the private components of the enclosing
20892 -- protected type are constants. A function nested within a (protected)
20893 -- procedure is not itself protected. Within the body of a protected
20894 -- function the current instance of the protected type is a constant.
20896 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
20897 -- Prefixes can involve implicit dereferences, in which case we must
20898 -- test for the case of a reference of a constant access type, which can
20899 -- can never be a variable.
20901 ---------------------------
20902 -- In_Protected_Function --
20903 ---------------------------
20905 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
20910 -- E is the current instance of a type
20912 if Is_Type
(E
) then
20921 if not Is_Protected_Type
(Prot
) then
20925 S
:= Current_Scope
;
20926 while Present
(S
) and then S
/= Prot
loop
20927 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
20936 end In_Protected_Function
;
20938 ------------------------
20939 -- Is_Variable_Prefix --
20940 ------------------------
20942 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
20944 if Is_Access_Type
(Etype
(P
)) then
20945 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
20947 -- For the case of an indexed component whose prefix has a packed
20948 -- array type, the prefix has been rewritten into a type conversion.
20949 -- Determine variable-ness from the converted expression.
20951 elsif Nkind
(P
) = N_Type_Conversion
20952 and then not Comes_From_Source
(P
)
20953 and then Is_Packed_Array
(Etype
(P
))
20955 return Is_Variable
(Expression
(P
));
20958 return Is_Variable
(P
);
20960 end Is_Variable_Prefix
;
20962 -- Start of processing for Is_Variable
20965 -- Special check, allow x'Deref(expr) as a variable
20967 if Nkind
(N
) = N_Attribute_Reference
20968 and then Attribute_Name
(N
) = Name_Deref
20973 -- Check if we perform the test on the original node since this may be a
20974 -- test of syntactic categories which must not be disturbed by whatever
20975 -- rewriting might have occurred. For example, an aggregate, which is
20976 -- certainly NOT a variable, could be turned into a variable by
20979 if Use_Original_Node
then
20980 Orig_Node
:= Original_Node
(N
);
20985 -- Definitely OK if Assignment_OK is set. Since this is something that
20986 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
20988 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
20991 -- Normally we go to the original node, but there is one exception where
20992 -- we use the rewritten node, namely when it is an explicit dereference.
20993 -- The generated code may rewrite a prefix which is an access type with
20994 -- an explicit dereference. The dereference is a variable, even though
20995 -- the original node may not be (since it could be a constant of the
20998 -- In Ada 2005 we have a further case to consider: the prefix may be a
20999 -- function call given in prefix notation. The original node appears to
21000 -- be a selected component, but we need to examine the call.
21002 elsif Nkind
(N
) = N_Explicit_Dereference
21003 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
21004 and then Present
(Etype
(Orig_Node
))
21005 and then Is_Access_Type
(Etype
(Orig_Node
))
21007 -- Note that if the prefix is an explicit dereference that does not
21008 -- come from source, we must check for a rewritten function call in
21009 -- prefixed notation before other forms of rewriting, to prevent a
21013 (Nkind
(Orig_Node
) = N_Function_Call
21014 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
21016 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
21018 -- Generalized indexing operations are rewritten as explicit
21019 -- dereferences, and it is only during resolution that we can
21020 -- check whether the context requires an access_to_variable type.
21022 elsif Nkind
(N
) = N_Explicit_Dereference
21023 and then Present
(Etype
(Orig_Node
))
21024 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
21025 and then Ada_Version
>= Ada_2012
21027 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
21029 -- A function call is never a variable
21031 elsif Nkind
(N
) = N_Function_Call
then
21034 -- All remaining checks use the original node
21036 elsif Is_Entity_Name
(Orig_Node
)
21037 and then Present
(Entity
(Orig_Node
))
21040 E
: constant Entity_Id
:= Entity
(Orig_Node
);
21041 K
: constant Entity_Kind
:= Ekind
(E
);
21044 if Is_Loop_Parameter
(E
) then
21048 return (K
= E_Variable
21049 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
21050 or else (K
= E_Component
21051 and then not In_Protected_Function
(E
))
21052 or else (Present
(Etype
(E
))
21053 and then Is_Access_Variable
(Etype
(E
))
21054 and then Is_Dereferenced
(N
))
21055 or else K
= E_Out_Parameter
21056 or else K
= E_In_Out_Parameter
21057 or else K
= E_Generic_In_Out_Parameter
21059 -- Current instance of type. If this is a protected type, check
21060 -- we are not within the body of one of its protected functions.
21062 or else (Is_Type
(E
)
21063 and then In_Open_Scopes
(E
)
21064 and then not In_Protected_Function
(E
))
21066 or else (Is_Incomplete_Or_Private_Type
(E
)
21067 and then In_Open_Scopes
(Full_View
(E
)));
21071 case Nkind
(Orig_Node
) is
21072 when N_Indexed_Component
21075 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
21077 when N_Selected_Component
=>
21078 return Is_Variable
(Selector_Name
(Orig_Node
))
21079 and then Is_Variable_Prefix
(Prefix
(Orig_Node
));
21081 -- For an explicit dereference, the type of the prefix cannot
21082 -- be an access to constant or an access to subprogram.
21084 when N_Explicit_Dereference
=>
21086 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
21088 return Is_Access_Type
(Typ
)
21089 and then not Is_Access_Constant
(Root_Type
(Typ
))
21090 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
21093 -- The type conversion is the case where we do not deal with the
21094 -- context dependent special case of an actual parameter. Thus
21095 -- the type conversion is only considered a variable for the
21096 -- purposes of this routine if the target type is tagged. However,
21097 -- a type conversion is considered to be a variable if it does not
21098 -- come from source (this deals for example with the conversions
21099 -- of expressions to their actual subtypes).
21101 when N_Type_Conversion
=>
21102 return Is_Variable
(Expression
(Orig_Node
))
21104 (not Comes_From_Source
(Orig_Node
)
21106 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
21108 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
21110 -- GNAT allows an unchecked type conversion as a variable. This
21111 -- only affects the generation of internal expanded code, since
21112 -- calls to instantiations of Unchecked_Conversion are never
21113 -- considered variables (since they are function calls).
21115 when N_Unchecked_Type_Conversion
=>
21116 return Is_Variable
(Expression
(Orig_Node
));
21124 ------------------------
21125 -- Is_View_Conversion --
21126 ------------------------
21128 function Is_View_Conversion
(N
: Node_Id
) return Boolean is
21130 if Nkind
(N
) = N_Type_Conversion
21131 and then Nkind
(Unqual_Conv
(N
)) in N_Has_Etype
21133 if Is_Tagged_Type
(Etype
(N
))
21134 and then Is_Tagged_Type
(Etype
(Unqual_Conv
(N
)))
21138 elsif Is_Actual_Parameter
(N
)
21139 and then (Is_Actual_Out_Parameter
(N
)
21140 or else Is_Actual_In_Out_Parameter
(N
))
21147 end Is_View_Conversion
;
21149 ---------------------------
21150 -- Is_Visibly_Controlled --
21151 ---------------------------
21153 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
21154 Root
: constant Entity_Id
:= Root_Type
(T
);
21156 return Chars
(Scope
(Root
)) = Name_Finalization
21157 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
21158 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
21159 end Is_Visibly_Controlled
;
21161 ----------------------------------------
21162 -- Is_Volatile_Full_Access_Object_Ref --
21163 ----------------------------------------
21165 function Is_Volatile_Full_Access_Object_Ref
(N
: Node_Id
) return Boolean is
21166 function Is_VFA_Object_Entity
(Id
: Entity_Id
) return Boolean;
21167 -- Determine whether arbitrary entity Id denotes an object that is
21168 -- Volatile_Full_Access.
21170 ----------------------------
21171 -- Is_VFA_Object_Entity --
21172 ----------------------------
21174 function Is_VFA_Object_Entity
(Id
: Entity_Id
) return Boolean is
21178 and then (Is_Volatile_Full_Access
(Id
)
21180 Is_Volatile_Full_Access
(Etype
(Id
)));
21181 end Is_VFA_Object_Entity
;
21183 -- Start of processing for Is_Volatile_Full_Access_Object_Ref
21186 if Is_Entity_Name
(N
) then
21187 return Is_VFA_Object_Entity
(Entity
(N
));
21189 elsif Is_Volatile_Full_Access
(Etype
(N
)) then
21192 elsif Nkind
(N
) = N_Selected_Component
then
21193 return Is_Volatile_Full_Access
(Entity
(Selector_Name
(N
)));
21198 end Is_Volatile_Full_Access_Object_Ref
;
21200 --------------------------
21201 -- Is_Volatile_Function --
21202 --------------------------
21204 function Is_Volatile_Function
(Func_Id
: Entity_Id
) return Boolean is
21206 pragma Assert
(Ekind
(Func_Id
) in E_Function | E_Generic_Function
);
21208 -- A protected function is volatile
21210 if Nkind
(Parent
(Unit_Declaration_Node
(Func_Id
))) =
21211 N_Protected_Definition
21215 -- An instance of Ada.Unchecked_Conversion is a volatile function if
21216 -- either the source or the target are effectively volatile.
21218 elsif Is_Unchecked_Conversion_Instance
(Func_Id
)
21219 and then Has_Effectively_Volatile_Profile
(Func_Id
)
21223 -- Otherwise the function is treated as volatile if it is subject to
21224 -- enabled pragma Volatile_Function.
21228 Is_Enabled_Pragma
(Get_Pragma
(Func_Id
, Pragma_Volatile_Function
));
21230 end Is_Volatile_Function
;
21232 ----------------------------
21233 -- Is_Volatile_Object_Ref --
21234 ----------------------------
21236 function Is_Volatile_Object_Ref
(N
: Node_Id
) return Boolean is
21237 function Is_Volatile_Object_Entity
(Id
: Entity_Id
) return Boolean;
21238 -- Determine whether arbitrary entity Id denotes an object that is
21241 function Prefix_Has_Volatile_Components
(P
: Node_Id
) return Boolean;
21242 -- Determine whether prefix P has volatile components. This requires
21243 -- the presence of a Volatile_Components aspect/pragma or that P be
21244 -- itself a volatile object as per RM C.6(8).
21246 ---------------------------------
21247 -- Is_Volatile_Object_Entity --
21248 ---------------------------------
21250 function Is_Volatile_Object_Entity
(Id
: Entity_Id
) return Boolean is
21254 and then (Is_Volatile
(Id
) or else Is_Volatile
(Etype
(Id
)));
21255 end Is_Volatile_Object_Entity
;
21257 ------------------------------------
21258 -- Prefix_Has_Volatile_Components --
21259 ------------------------------------
21261 function Prefix_Has_Volatile_Components
(P
: Node_Id
) return Boolean is
21262 Typ
: constant Entity_Id
:= Etype
(P
);
21265 if Is_Access_Type
(Typ
) then
21267 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
21270 return Has_Volatile_Components
(Dtyp
)
21271 or else Is_Volatile
(Dtyp
);
21274 elsif Has_Volatile_Components
(Typ
) then
21277 elsif Is_Entity_Name
(P
)
21278 and then Has_Volatile_Component
(Entity
(P
))
21282 elsif Is_Volatile_Object_Ref
(P
) then
21288 end Prefix_Has_Volatile_Components
;
21290 -- Start of processing for Is_Volatile_Object_Ref
21293 if Is_Entity_Name
(N
) then
21294 return Is_Volatile_Object_Entity
(Entity
(N
));
21296 elsif Is_Volatile
(Etype
(N
)) then
21299 elsif Nkind
(N
) = N_Indexed_Component
then
21300 return Prefix_Has_Volatile_Components
(Prefix
(N
));
21302 elsif Nkind
(N
) = N_Selected_Component
then
21303 return Prefix_Has_Volatile_Components
(Prefix
(N
))
21304 or else Is_Volatile
(Entity
(Selector_Name
(N
)));
21309 end Is_Volatile_Object_Ref
;
21311 -----------------------------
21312 -- Iterate_Call_Parameters --
21313 -----------------------------
21315 procedure Iterate_Call_Parameters
(Call
: Node_Id
) is
21316 Actual
: Node_Id
:= First_Actual
(Call
);
21317 Formal
: Entity_Id
:= First_Formal
(Get_Called_Entity
(Call
));
21320 while Present
(Formal
) and then Present
(Actual
) loop
21321 Handle_Parameter
(Formal
, Actual
);
21323 Next_Formal
(Formal
);
21324 Next_Actual
(Actual
);
21327 pragma Assert
(No
(Formal
));
21328 pragma Assert
(No
(Actual
));
21329 end Iterate_Call_Parameters
;
21331 --------------------------------
21332 -- Iterate_Interface_Ancestor --
21333 --------------------------------
21335 function Iterator_Interface_Ancestor
(Typ
: Entity_Id
) return Entity_Id
is
21337 if Has_Interfaces
(Typ
) then
21339 Iface_Elmt
: Elmt_Id
;
21341 Root_Iface
: Entity_Id
;
21344 Collect_Interfaces
(Typ
, Ifaces
);
21346 Iface_Elmt
:= First_Elmt
(Ifaces
);
21347 while Present
(Iface_Elmt
) loop
21348 Root_Iface
:= Root_Type
(Node
(Iface_Elmt
));
21350 if Chars
(Root_Iface
)
21351 in Name_Forward_Iterator | Name_Reversible_Iterator
21352 and then In_Predefined_Unit
(Root_Iface
)
21357 Next_Elmt
(Iface_Elmt
);
21363 end Iterator_Interface_Ancestor
;
21365 -------------------------
21366 -- Kill_Current_Values --
21367 -------------------------
21369 procedure Kill_Current_Values
21371 Last_Assignment_Only
: Boolean := False)
21374 if Is_Assignable
(Ent
) then
21375 Set_Last_Assignment
(Ent
, Empty
);
21378 if Is_Object
(Ent
) then
21379 if not Last_Assignment_Only
then
21381 Set_Current_Value
(Ent
, Empty
);
21383 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
21384 -- for a constant. Once the constant is elaborated, its value is
21385 -- not changed, therefore the associated flags that describe the
21386 -- value should not be modified either.
21388 if Ekind
(Ent
) = E_Constant
then
21391 -- Non-constant entities
21394 if not Can_Never_Be_Null
(Ent
) then
21395 Set_Is_Known_Non_Null
(Ent
, False);
21398 Set_Is_Known_Null
(Ent
, False);
21400 -- Reset the Is_Known_Valid flag unless the type is always
21401 -- valid. This does not apply to a loop parameter because its
21402 -- bounds are defined by the loop header and therefore always
21405 if not Is_Known_Valid
(Etype
(Ent
))
21406 and then Ekind
(Ent
) /= E_Loop_Parameter
21408 Set_Is_Known_Valid
(Ent
, False);
21413 end Kill_Current_Values
;
21415 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
21419 -- Kill all saved checks, a special case of killing saved values
21421 if not Last_Assignment_Only
then
21425 -- Loop through relevant scopes, which includes the current scope and
21426 -- any parent scopes if the current scope is a block or a package.
21428 S
:= Current_Scope
;
21431 -- Clear current values of all entities in current scope
21436 Ent
:= First_Entity
(S
);
21437 while Present
(Ent
) loop
21438 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
21443 -- If this is a not a subprogram, deal with parents
21445 if not Is_Subprogram
(S
) then
21447 exit Scope_Loop
when S
= Standard_Standard
;
21451 end loop Scope_Loop
;
21452 end Kill_Current_Values
;
21454 --------------------------
21455 -- Kill_Size_Check_Code --
21456 --------------------------
21458 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
21460 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
21461 and then Present
(Size_Check_Code
(E
))
21463 Remove
(Size_Check_Code
(E
));
21464 Set_Size_Check_Code
(E
, Empty
);
21466 end Kill_Size_Check_Code
;
21468 --------------------
21469 -- Known_Non_Null --
21470 --------------------
21472 function Known_Non_Null
(N
: Node_Id
) return Boolean is
21473 Status
: constant Null_Status_Kind
:= Null_Status
(N
);
21480 -- The expression yields a non-null value ignoring simple flow analysis
21482 if Status
= Is_Non_Null
then
21485 -- Otherwise check whether N is a reference to an entity that appears
21486 -- within a conditional construct.
21488 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
21490 -- First check if we are in decisive conditional
21492 Get_Current_Value_Condition
(N
, Op
, Val
);
21494 if Known_Null
(Val
) then
21495 if Op
= N_Op_Eq
then
21497 elsif Op
= N_Op_Ne
then
21502 -- If OK to do replacement, test Is_Known_Non_Null flag
21506 if OK_To_Do_Constant_Replacement
(Id
) then
21507 return Is_Known_Non_Null
(Id
);
21511 -- Otherwise it is not possible to determine whether N yields a non-null
21515 end Known_Non_Null
;
21521 function Known_Null
(N
: Node_Id
) return Boolean is
21522 Status
: constant Null_Status_Kind
:= Null_Status
(N
);
21529 -- The expression yields a null value ignoring simple flow analysis
21531 if Status
= Is_Null
then
21534 -- Otherwise check whether N is a reference to an entity that appears
21535 -- within a conditional construct.
21537 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
21539 -- First check if we are in decisive conditional
21541 Get_Current_Value_Condition
(N
, Op
, Val
);
21543 -- If Get_Current_Value_Condition were to return Val = N, then the
21544 -- recursion below could be infinite.
21547 raise Program_Error
;
21550 if Known_Null
(Val
) then
21551 if Op
= N_Op_Eq
then
21553 elsif Op
= N_Op_Ne
then
21558 -- If OK to do replacement, test Is_Known_Null flag
21562 if OK_To_Do_Constant_Replacement
(Id
) then
21563 return Is_Known_Null
(Id
);
21567 -- Otherwise it is not possible to determine whether N yields a null
21573 ---------------------------
21574 -- Last_Source_Statement --
21575 ---------------------------
21577 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
21581 N
:= Last
(Statements
(HSS
));
21582 while Present
(N
) loop
21583 exit when Comes_From_Source
(N
);
21588 end Last_Source_Statement
;
21590 -----------------------
21591 -- Mark_Coextensions --
21592 -----------------------
21594 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
21595 Is_Dynamic
: Boolean;
21596 -- Indicates whether the context causes nested coextensions to be
21597 -- dynamic or static
21599 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
21600 -- Recognize an allocator node and label it as a dynamic coextension
21602 --------------------
21603 -- Mark_Allocator --
21604 --------------------
21606 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
21608 if Nkind
(N
) = N_Allocator
then
21610 Set_Is_Static_Coextension
(N
, False);
21611 Set_Is_Dynamic_Coextension
(N
);
21613 -- If the allocator expression is potentially dynamic, it may
21614 -- be expanded out of order and require dynamic allocation
21615 -- anyway, so we treat the coextension itself as dynamic.
21616 -- Potential optimization ???
21618 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
21619 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
21621 Set_Is_Static_Coextension
(N
, False);
21622 Set_Is_Dynamic_Coextension
(N
);
21624 Set_Is_Dynamic_Coextension
(N
, False);
21625 Set_Is_Static_Coextension
(N
);
21630 end Mark_Allocator
;
21632 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
21634 -- Start of processing for Mark_Coextensions
21637 -- An allocator that appears on the right-hand side of an assignment is
21638 -- treated as a potentially dynamic coextension when the right-hand side
21639 -- is an allocator or a qualified expression.
21641 -- Obj := new ...'(new Coextension ...);
21643 if Nkind
(Context_Nod
) = N_Assignment_Statement
then
21644 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) in
21645 N_Allocator | N_Qualified_Expression
;
21647 -- An allocator that appears within the expression of a simple return
21648 -- statement is treated as a potentially dynamic coextension when the
21649 -- expression is either aggregate, allocator, or qualified expression.
21651 -- return (new Coextension ...);
21652 -- return new ...'(new Coextension ...);
21654 elsif Nkind
(Context_Nod
) = N_Simple_Return_Statement
then
21655 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) in
21656 N_Aggregate | N_Allocator | N_Qualified_Expression
;
21658 -- An alloctor that appears within the initialization expression of an
21659 -- object declaration is considered a potentially dynamic coextension
21660 -- when the initialization expression is an allocator or a qualified
21663 -- Obj : ... := new ...'(new Coextension ...);
21665 -- A similar case arises when the object declaration is part of an
21666 -- extended return statement.
21668 -- return Obj : ... := new ...'(new Coextension ...);
21669 -- return Obj : ... := (new Coextension ...);
21671 elsif Nkind
(Context_Nod
) = N_Object_Declaration
then
21672 Is_Dynamic
:= Nkind
(Root_Nod
) in N_Allocator | N_Qualified_Expression
21673 or else Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
21675 -- This routine should not be called with constructs that cannot contain
21679 raise Program_Error
;
21682 Mark_Allocators
(Root_Nod
);
21683 end Mark_Coextensions
;
21685 ---------------------------------
21686 -- Mark_Elaboration_Attributes --
21687 ---------------------------------
21689 procedure Mark_Elaboration_Attributes
21690 (N_Id
: Node_Or_Entity_Id
;
21691 Checks
: Boolean := False;
21692 Level
: Boolean := False;
21693 Modes
: Boolean := False;
21694 Warnings
: Boolean := False)
21696 function Elaboration_Checks_OK
21697 (Target_Id
: Entity_Id
;
21698 Context_Id
: Entity_Id
) return Boolean;
21699 -- Determine whether elaboration checks are enabled for target Target_Id
21700 -- which resides within context Context_Id.
21702 procedure Mark_Elaboration_Attributes_Id
(Id
: Entity_Id
);
21703 -- Preserve relevant attributes of the context in arbitrary entity Id
21705 procedure Mark_Elaboration_Attributes_Node
(N
: Node_Id
);
21706 -- Preserve relevant attributes of the context in arbitrary node N
21708 ---------------------------
21709 -- Elaboration_Checks_OK --
21710 ---------------------------
21712 function Elaboration_Checks_OK
21713 (Target_Id
: Entity_Id
;
21714 Context_Id
: Entity_Id
) return Boolean
21716 Encl_Scop
: Entity_Id
;
21719 -- Elaboration checks are suppressed for the target
21721 if Elaboration_Checks_Suppressed
(Target_Id
) then
21725 -- Otherwise elaboration checks are OK for the target, but may be
21726 -- suppressed for the context where the target is declared.
21728 Encl_Scop
:= Context_Id
;
21729 while Present
(Encl_Scop
) and then Encl_Scop
/= Standard_Standard
loop
21730 if Elaboration_Checks_Suppressed
(Encl_Scop
) then
21734 Encl_Scop
:= Scope
(Encl_Scop
);
21737 -- Neither the target nor its declarative context have elaboration
21738 -- checks suppressed.
21741 end Elaboration_Checks_OK
;
21743 ------------------------------------
21744 -- Mark_Elaboration_Attributes_Id --
21745 ------------------------------------
21747 procedure Mark_Elaboration_Attributes_Id
(Id
: Entity_Id
) is
21749 -- Mark the status of elaboration checks in effect. Do not reset the
21750 -- status in case the entity is reanalyzed with checks suppressed.
21752 if Checks
and then not Is_Elaboration_Checks_OK_Id
(Id
) then
21753 Set_Is_Elaboration_Checks_OK_Id
(Id
,
21754 Elaboration_Checks_OK
21756 Context_Id
=> Scope
(Id
)));
21759 -- Mark the status of elaboration warnings in effect. Do not reset
21760 -- the status in case the entity is reanalyzed with warnings off.
21762 if Warnings
and then not Is_Elaboration_Warnings_OK_Id
(Id
) then
21763 Set_Is_Elaboration_Warnings_OK_Id
(Id
, Elab_Warnings
);
21765 end Mark_Elaboration_Attributes_Id
;
21767 --------------------------------------
21768 -- Mark_Elaboration_Attributes_Node --
21769 --------------------------------------
21771 procedure Mark_Elaboration_Attributes_Node
(N
: Node_Id
) is
21772 function Extract_Name
(N
: Node_Id
) return Node_Id
;
21773 -- Obtain the Name attribute of call or instantiation N
21779 function Extract_Name
(N
: Node_Id
) return Node_Id
is
21785 -- A call to an entry family appears in indexed form
21787 if Nkind
(Nam
) = N_Indexed_Component
then
21788 Nam
:= Prefix
(Nam
);
21791 -- The name may also appear in qualified form
21793 if Nkind
(Nam
) = N_Selected_Component
then
21794 Nam
:= Selector_Name
(Nam
);
21802 Context_Id
: Entity_Id
;
21805 -- Start of processing for Mark_Elaboration_Attributes_Node
21808 -- Mark the status of elaboration checks in effect. Do not reset the
21809 -- status in case the node is reanalyzed with checks suppressed.
21811 if Checks
and then not Is_Elaboration_Checks_OK_Node
(N
) then
21813 -- Assignments, attribute references, and variable references do
21814 -- not have a "declarative" context.
21816 Context_Id
:= Empty
;
21818 -- The status of elaboration checks for calls and instantiations
21819 -- depends on the most recent pragma Suppress/Unsuppress, as well
21820 -- as the suppression status of the context where the target is
21824 -- function Func ...;
21828 -- procedure Main is
21829 -- pragma Suppress (Elaboration_Checks, Pack);
21830 -- X : ... := Pack.Func;
21833 -- In the example above, the call to Func has elaboration checks
21834 -- enabled because there is no active general purpose suppression
21835 -- pragma, however the elaboration checks of Pack are explicitly
21836 -- suppressed. As a result the elaboration checks of the call must
21837 -- be disabled in order to preserve this dependency.
21839 if Nkind
(N
) in N_Entry_Call_Statement
21841 | N_Function_Instantiation
21842 | N_Package_Instantiation
21843 | N_Procedure_Call_Statement
21844 | N_Procedure_Instantiation
21846 Nam
:= Extract_Name
(N
);
21848 if Is_Entity_Name
(Nam
) and then Present
(Entity
(Nam
)) then
21849 Context_Id
:= Scope
(Entity
(Nam
));
21853 Set_Is_Elaboration_Checks_OK_Node
(N
,
21854 Elaboration_Checks_OK
21855 (Target_Id
=> Empty
,
21856 Context_Id
=> Context_Id
));
21859 -- Mark the enclosing level of the node. Do not reset the status in
21860 -- case the node is relocated and reanalyzed.
21862 if Level
and then not Is_Declaration_Level_Node
(N
) then
21863 Set_Is_Declaration_Level_Node
(N
,
21864 Find_Enclosing_Level
(N
) = Declaration_Level
);
21867 -- Mark the Ghost and SPARK mode in effect
21870 if Ghost_Mode
= Ignore
then
21871 Set_Is_Ignored_Ghost_Node
(N
);
21874 if SPARK_Mode
= On
then
21875 Set_Is_SPARK_Mode_On_Node
(N
);
21879 -- Mark the status of elaboration warnings in effect. Do not reset
21880 -- the status in case the node is reanalyzed with warnings off.
21882 if Warnings
and then not Is_Elaboration_Warnings_OK_Node
(N
) then
21883 Set_Is_Elaboration_Warnings_OK_Node
(N
, Elab_Warnings
);
21885 end Mark_Elaboration_Attributes_Node
;
21887 -- Start of processing for Mark_Elaboration_Attributes
21890 -- Do not capture any elaboration-related attributes when switch -gnatH
21891 -- (legacy elaboration checking mode enabled) is in effect because the
21892 -- attributes are useless to the legacy model.
21894 if Legacy_Elaboration_Checks
then
21898 if Nkind
(N_Id
) in N_Entity
then
21899 Mark_Elaboration_Attributes_Id
(N_Id
);
21901 Mark_Elaboration_Attributes_Node
(N_Id
);
21903 end Mark_Elaboration_Attributes
;
21905 ----------------------------------------
21906 -- Mark_Save_Invocation_Graph_Of_Body --
21907 ----------------------------------------
21909 procedure Mark_Save_Invocation_Graph_Of_Body
is
21910 Main
: constant Node_Id
:= Cunit
(Main_Unit
);
21911 Main_Unit
: constant Node_Id
:= Unit
(Main
);
21912 Aux_Id
: Entity_Id
;
21915 Set_Save_Invocation_Graph_Of_Body
(Main
);
21917 -- Assume that the main unit does not have a complimentary unit
21921 -- Obtain the complimentary unit of the main unit
21923 if Nkind
(Main_Unit
) in N_Generic_Package_Declaration
21924 | N_Generic_Subprogram_Declaration
21925 | N_Package_Declaration
21926 | N_Subprogram_Declaration
21928 Aux_Id
:= Corresponding_Body
(Main_Unit
);
21930 elsif Nkind
(Main_Unit
) in N_Package_Body
21931 | N_Subprogram_Body
21932 | N_Subprogram_Renaming_Declaration
21934 Aux_Id
:= Corresponding_Spec
(Main_Unit
);
21937 if Present
(Aux_Id
) then
21938 Set_Save_Invocation_Graph_Of_Body
21939 (Parent
(Unit_Declaration_Node
(Aux_Id
)));
21941 end Mark_Save_Invocation_Graph_Of_Body
;
21943 ----------------------------------
21944 -- Matching_Static_Array_Bounds --
21945 ----------------------------------
21947 function Matching_Static_Array_Bounds
21949 R_Typ
: Node_Id
) return Boolean
21951 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
21952 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
21954 L_Index
: Node_Id
:= Empty
; -- init to ...
21955 R_Index
: Node_Id
:= Empty
; -- ...avoid warnings
21964 if L_Ndims
/= R_Ndims
then
21968 -- Unconstrained types do not have static bounds
21970 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
21974 -- First treat specially the first dimension, as the lower bound and
21975 -- length of string literals are not stored like those of arrays.
21977 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
21978 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
21979 L_Len
:= String_Literal_Length
(L_Typ
);
21981 L_Index
:= First_Index
(L_Typ
);
21982 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
21984 if Is_OK_Static_Expression
(L_Low
)
21986 Is_OK_Static_Expression
(L_High
)
21988 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
21991 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
21998 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
21999 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
22000 R_Len
:= String_Literal_Length
(R_Typ
);
22002 R_Index
:= First_Index
(R_Typ
);
22003 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
22005 if Is_OK_Static_Expression
(R_Low
)
22007 Is_OK_Static_Expression
(R_High
)
22009 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
22012 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
22019 if (Is_OK_Static_Expression
(L_Low
)
22021 Is_OK_Static_Expression
(R_Low
))
22022 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
22023 and then L_Len
= R_Len
22030 -- Then treat all other dimensions
22032 for Indx
in 2 .. L_Ndims
loop
22036 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
22037 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
22039 if (Is_OK_Static_Expression
(L_Low
) and then
22040 Is_OK_Static_Expression
(L_High
) and then
22041 Is_OK_Static_Expression
(R_Low
) and then
22042 Is_OK_Static_Expression
(R_High
))
22043 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
22045 Expr_Value
(L_High
) = Expr_Value
(R_High
))
22053 -- If we fall through the loop, all indexes matched
22056 end Matching_Static_Array_Bounds
;
22062 function Might_Raise
(N
: Node_Id
) return Boolean is
22063 Result
: Boolean := False;
22065 function Process
(N
: Node_Id
) return Traverse_Result
;
22066 -- Set Result to True if we find something that could raise an exception
22072 function Process
(N
: Node_Id
) return Traverse_Result
is
22074 if Nkind
(N
) in N_Procedure_Call_Statement
22076 | N_Raise_Statement
22077 | N_Raise_xxx_Error
22078 | N_Raise_Expression
22087 procedure Set_Result
is new Traverse_Proc
(Process
);
22089 -- Start of processing for Might_Raise
22092 -- False if exceptions can't be propagated
22094 if No_Exception_Handlers_Set
then
22098 -- If the checks handled by the back end are not disabled, we cannot
22099 -- ensure that no exception will be raised.
22101 if not Access_Checks_Suppressed
(Empty
)
22102 or else not Discriminant_Checks_Suppressed
(Empty
)
22103 or else not Range_Checks_Suppressed
(Empty
)
22104 or else not Index_Checks_Suppressed
(Empty
)
22105 or else Opt
.Stack_Checking_Enabled
22114 ----------------------------------------
22115 -- Nearest_Class_Condition_Subprogram --
22116 ----------------------------------------
22118 function Nearest_Class_Condition_Subprogram
22119 (Kind
: Condition_Kind
;
22120 Spec_Id
: Entity_Id
) return Entity_Id
22122 Subp_Id
: constant Entity_Id
:= Ultimate_Alias
(Spec_Id
);
22125 -- Prevent cascaded errors
22127 if not Is_Dispatching_Operation
(Subp_Id
) then
22130 -- No need to search if this subprogram has class-wide postconditions
22132 elsif Present
(Class_Condition
(Kind
, Subp_Id
)) then
22136 -- Process the contracts of inherited subprograms, looking for
22137 -- class-wide pre/postconditions.
22140 Subps
: constant Subprogram_List
:= Inherited_Subprograms
(Subp_Id
);
22141 Subp_Id
: Entity_Id
;
22144 for Index
in Subps
'Range loop
22145 Subp_Id
:= Subps
(Index
);
22147 if Present
(Alias
(Subp_Id
)) then
22148 Subp_Id
:= Ultimate_Alias
(Subp_Id
);
22151 -- Wrappers of class-wide pre/postconditions reference the
22152 -- parent primitive that has the inherited contract.
22154 if Is_Wrapper
(Subp_Id
)
22155 and then Present
(LSP_Subprogram
(Subp_Id
))
22157 Subp_Id
:= LSP_Subprogram
(Subp_Id
);
22160 if Present
(Class_Condition
(Kind
, Subp_Id
)) then
22167 end Nearest_Class_Condition_Subprogram
;
22169 --------------------------------
22170 -- Nearest_Enclosing_Instance --
22171 --------------------------------
22173 function Nearest_Enclosing_Instance
(E
: Entity_Id
) return Entity_Id
is
22178 while Present
(Inst
) and then Inst
/= Standard_Standard
loop
22179 if Is_Generic_Instance
(Inst
) then
22183 Inst
:= Scope
(Inst
);
22187 end Nearest_Enclosing_Instance
;
22189 ------------------------
22190 -- Needs_Finalization --
22191 ------------------------
22193 function Needs_Finalization
(Typ
: Entity_Id
) return Boolean is
22194 function Has_Some_Controlled_Component
22195 (Input_Typ
: Entity_Id
) return Boolean;
22196 -- Determine whether type Input_Typ has at least one controlled
22199 -----------------------------------
22200 -- Has_Some_Controlled_Component --
22201 -----------------------------------
22203 function Has_Some_Controlled_Component
22204 (Input_Typ
: Entity_Id
) return Boolean
22209 -- When a type is already frozen and has at least one controlled
22210 -- component, or is manually decorated, it is sufficient to inspect
22211 -- flag Has_Controlled_Component.
22213 if Has_Controlled_Component
(Input_Typ
) then
22216 -- Otherwise inspect the internals of the type
22218 elsif not Is_Frozen
(Input_Typ
) then
22219 if Is_Array_Type
(Input_Typ
) then
22220 return Needs_Finalization
(Component_Type
(Input_Typ
));
22222 elsif Is_Record_Type
(Input_Typ
) then
22223 Comp
:= First_Component
(Input_Typ
);
22224 while Present
(Comp
) loop
22225 if Needs_Finalization
(Etype
(Comp
)) then
22229 Next_Component
(Comp
);
22235 end Has_Some_Controlled_Component
;
22237 -- Start of processing for Needs_Finalization
22240 -- Certain run-time configurations and targets do not provide support
22241 -- for controlled types.
22243 if Restriction_Active
(No_Finalization
) then
22246 -- C++ types are not considered controlled. It is assumed that the non-
22247 -- Ada side will handle their clean up.
22249 elsif Convention
(Typ
) = Convention_CPP
then
22252 -- Class-wide types are treated as controlled because derivations from
22253 -- the root type may introduce controlled components.
22255 elsif Is_Class_Wide_Type
(Typ
) then
22258 -- Concurrent types are controlled as long as their corresponding record
22261 elsif Is_Concurrent_Type
(Typ
)
22262 and then Present
(Corresponding_Record_Type
(Typ
))
22263 and then Needs_Finalization
(Corresponding_Record_Type
(Typ
))
22267 -- Otherwise the type is controlled when it is either derived from type
22268 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
22269 -- contains at least one controlled component.
22273 Is_Controlled
(Typ
) or else Has_Some_Controlled_Component
(Typ
);
22275 end Needs_Finalization
;
22277 ----------------------
22278 -- Needs_One_Actual --
22279 ----------------------
22281 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
22282 Formal
: Entity_Id
;
22285 -- Ada 2005 or later, and formals present. The first formal must be
22286 -- of a type that supports prefix notation: a controlling argument,
22287 -- a class-wide type, or an access to such.
22289 if Ada_Version
>= Ada_2005
22290 and then Present
(First_Formal
(E
))
22291 and then No
(Default_Value
(First_Formal
(E
)))
22293 (Is_Controlling_Formal
(First_Formal
(E
))
22294 or else Is_Class_Wide_Type
(Etype
(First_Formal
(E
)))
22295 or else Is_Anonymous_Access_Type
(Etype
(First_Formal
(E
))))
22297 Formal
:= Next_Formal
(First_Formal
(E
));
22298 while Present
(Formal
) loop
22299 if No
(Default_Value
(Formal
)) then
22303 Next_Formal
(Formal
);
22308 -- Ada 83/95 or no formals
22313 end Needs_One_Actual
;
22315 ----------------------------
22316 -- Needs_Secondary_Stack --
22317 ----------------------------
22319 function Needs_Secondary_Stack
(Id
: Entity_Id
) return Boolean is
22320 pragma Assert
(if Present
(Id
) then Ekind
(Id
) in E_Void | Type_Kind
);
22322 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean;
22323 -- Called for untagged record and protected types. Return True if the
22324 -- size of function results is known in the caller for Typ.
22326 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean;
22327 -- Returns True if Typ is a nonlimited record with defaulted
22328 -- discriminants whose max size makes it unsuitable for allocating on
22329 -- the primary stack.
22331 ------------------------------
22332 -- Caller_Known_Size_Record --
22333 ------------------------------
22335 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean is
22336 pragma Assert
(if Present
(Typ
) then Typ
= Underlying_Type
(Typ
));
22338 function Depends_On_Discriminant
(Typ
: Entity_Id
) return Boolean;
22339 -- Called for untagged record and protected types. Return True if Typ
22340 -- depends on discriminants, either directly when it is unconstrained
22341 -- or indirectly when it is constrained by uplevel discriminants.
22343 -----------------------------
22344 -- Depends_On_Discriminant --
22345 -----------------------------
22347 function Depends_On_Discriminant
(Typ
: Entity_Id
) return Boolean is
22351 if Has_Discriminants
(Typ
) then
22352 if not Is_Constrained
(Typ
) then
22356 Cons
:= First_Elmt
(Discriminant_Constraint
(Typ
));
22357 while Present
(Cons
) loop
22358 if Nkind
(Node
(Cons
)) = N_Identifier
22359 and then Ekind
(Entity
(Node
(Cons
))) = E_Discriminant
22370 end Depends_On_Discriminant
;
22373 -- This is a protected type without Corresponding_Record_Type set,
22374 -- typically because expansion is disabled. The safe thing to do is
22375 -- to return True, so Needs_Secondary_Stack returns False.
22381 -- First see if we have a variant part and return False if it depends
22382 -- on discriminants.
22384 if Has_Variant_Part
(Typ
) and then Depends_On_Discriminant
(Typ
) then
22388 -- Then loop over components and return False if their subtype has a
22389 -- caller-unknown size, possibly recursively.
22391 -- ??? This is overly conservative, an array could be nested inside
22392 -- some other record that is constrained by nondiscriminants. That
22393 -- is, the recursive calls are too conservative.
22399 Comp
:= First_Component
(Typ
);
22400 while Present
(Comp
) loop
22402 Comp_Type
: constant Entity_Id
:=
22403 Underlying_Type
(Etype
(Comp
));
22406 if Is_Record_Type
(Comp_Type
) then
22407 if not Caller_Known_Size_Record
(Comp_Type
) then
22411 elsif Is_Protected_Type
(Comp_Type
) then
22412 if not Caller_Known_Size_Record
22413 (Corresponding_Record_Type
(Comp_Type
))
22418 elsif Is_Array_Type
(Comp_Type
) then
22419 if Size_Depends_On_Discriminant
(Comp_Type
) then
22425 Next_Component
(Comp
);
22430 end Caller_Known_Size_Record
;
22432 ------------------------------
22433 -- Large_Max_Size_Mutable --
22434 ------------------------------
22436 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean is
22437 pragma Assert
(Typ
= Underlying_Type
(Typ
));
22439 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean;
22440 -- Returns true if the discrete type T has a large range
22442 ----------------------------
22443 -- Is_Large_Discrete_Type --
22444 ----------------------------
22446 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean is
22447 Threshold
: constant Int
:= 16;
22448 -- Arbitrary threshold above which we consider it "large". We want
22449 -- a fairly large threshold, because these large types really
22450 -- shouldn't have default discriminants in the first place, in
22454 return UI_To_Int
(RM_Size
(T
)) > Threshold
;
22455 end Is_Large_Discrete_Type
;
22457 -- Start of processing for Large_Max_Size_Mutable
22460 if Is_Record_Type
(Typ
)
22461 and then not Is_Inherently_Limited_Type
(Typ
)
22462 and then Has_Defaulted_Discriminants
(Typ
)
22464 -- Loop through the components, looking for an array whose upper
22465 -- bound(s) depends on discriminants, where both the subtype of
22466 -- the discriminant and the index subtype are too large.
22472 Comp
:= First_Component
(Typ
);
22473 while Present
(Comp
) loop
22475 Comp_Type
: constant Entity_Id
:=
22476 Underlying_Type
(Etype
(Comp
));
22483 if Present
(Comp_Type
)
22484 and then Is_Array_Type
(Comp_Type
)
22486 Indx
:= First_Index
(Comp_Type
);
22488 while Present
(Indx
) loop
22489 Ityp
:= Etype
(Indx
);
22490 Hi
:= Type_High_Bound
(Ityp
);
22492 if Nkind
(Hi
) = N_Identifier
22493 and then Ekind
(Entity
(Hi
)) = E_Discriminant
22494 and then Is_Large_Discrete_Type
(Ityp
)
22495 and then Is_Large_Discrete_Type
22496 (Etype
(Entity
(Hi
)))
22506 Next_Component
(Comp
);
22512 end Large_Max_Size_Mutable
;
22514 -- Local declarations
22516 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
22518 -- Start of processing for Needs_Secondary_Stack
22521 -- This is a private type which is not completed yet. This can only
22522 -- happen in a default expression (of a formal parameter or of a
22523 -- record component). The safe thing to do is to return False.
22529 -- Do not expand transient scope for non-existent procedure return or
22530 -- string literal types.
22532 if Typ
= Standard_Void_Type
22533 or else Ekind
(Typ
) = E_String_Literal_Subtype
22537 -- If Typ is a generic formal incomplete type, then we want to look at
22538 -- the actual type.
22540 elsif Ekind
(Typ
) = E_Record_Subtype
22541 and then Present
(Cloned_Subtype
(Typ
))
22543 return Needs_Secondary_Stack
(Cloned_Subtype
(Typ
));
22545 -- Class-wide types obviously have an unknown size. For specific tagged
22546 -- types, if a call returning one of them is dispatching on result, and
22547 -- this type is not returned on the secondary stack, then the call goes
22548 -- through a thunk that only moves the result from the primary onto the
22549 -- secondary stack, because the computation of the size of the result is
22550 -- possible but complex from the outside.
22552 elsif Is_Class_Wide_Type
(Typ
) then
22555 -- If the return slot of the back end cannot be accessed, then there
22556 -- is no way to call Adjust at the right time for the return object if
22557 -- the type needs finalization, so the return object must be allocated
22558 -- on the secondary stack.
22560 elsif not Back_End_Return_Slot
and then Needs_Finalization
(Typ
) then
22563 -- Definite subtypes have a known size. This includes all elementary
22564 -- types. Tasks have a known size even if they have discriminants, so
22565 -- we return False here, with one exception:
22566 -- For a type like:
22567 -- type T (Last : Natural := 0) is
22568 -- X : String (1 .. Last);
22570 -- we return True. That's because for "P(F(...));", where F returns T,
22571 -- we don't know the size of the result at the call site, so if we
22572 -- allocated it on the primary stack, we would have to allocate the
22573 -- maximum size, which is way too big.
22575 elsif Is_Definite_Subtype
(Typ
) or else Is_Task_Type
(Typ
) then
22576 return Large_Max_Size_Mutable
(Typ
);
22578 -- Indefinite (discriminated) record type
22580 elsif Is_Record_Type
(Typ
) then
22581 return not Caller_Known_Size_Record
(Typ
);
22583 -- Indefinite (discriminated) protected type
22585 elsif Is_Protected_Type
(Typ
) then
22586 return not Caller_Known_Size_Record
(Corresponding_Record_Type
(Typ
));
22588 -- Unconstrained array type
22591 pragma Assert
(Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
));
22594 end Needs_Secondary_Stack
;
22596 ---------------------------------
22597 -- Needs_Simple_Initialization --
22598 ---------------------------------
22600 function Needs_Simple_Initialization
22602 Consider_IS
: Boolean := True) return Boolean
22604 Consider_IS_NS
: constant Boolean :=
22605 Normalize_Scalars
or (Initialize_Scalars
and Consider_IS
);
22608 -- Never need initialization if it is suppressed
22610 if Initialization_Suppressed
(Typ
) then
22614 -- Check for private type, in which case test applies to the underlying
22615 -- type of the private type.
22617 if Is_Private_Type
(Typ
) then
22619 RT
: constant Entity_Id
:= Underlying_Type
(Typ
);
22621 if Present
(RT
) then
22622 return Needs_Simple_Initialization
(RT
);
22628 -- Scalar type with Default_Value aspect requires initialization
22630 elsif Is_Scalar_Type
(Typ
) and then Has_Default_Aspect
(Typ
) then
22633 -- Cases needing simple initialization are access types, and, if pragma
22634 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
22637 elsif Is_Access_Type
(Typ
)
22638 or else (Consider_IS_NS
and then Is_Scalar_Type
(Typ
))
22642 -- If Initialize/Normalize_Scalars is in effect, string objects also
22643 -- need initialization, unless they are created in the course of
22644 -- expanding an aggregate (since in the latter case they will be
22645 -- filled with appropriate initializing values before they are used).
22647 elsif Consider_IS_NS
22648 and then Is_Standard_String_Type
(Typ
)
22650 (not Is_Itype
(Typ
)
22651 or else Nkind
(Associated_Node_For_Itype
(Typ
)) /= N_Aggregate
)
22658 end Needs_Simple_Initialization
;
22660 -------------------------------------
22661 -- Needs_Variable_Reference_Marker --
22662 -------------------------------------
22664 function Needs_Variable_Reference_Marker
22666 Calls_OK
: Boolean) return Boolean
22668 function Within_Suitable_Context
(Ref
: Node_Id
) return Boolean;
22669 -- Deteremine whether variable reference Ref appears within a suitable
22670 -- context that allows the creation of a marker.
22672 -----------------------------
22673 -- Within_Suitable_Context --
22674 -----------------------------
22676 function Within_Suitable_Context
(Ref
: Node_Id
) return Boolean is
22681 while Present
(Par
) loop
22683 -- The context is not suitable when the reference appears within
22684 -- the formal part of an instantiation which acts as compilation
22685 -- unit because there is no proper list for the insertion of the
22688 if Nkind
(Par
) = N_Generic_Association
22689 and then Nkind
(Parent
(Par
)) in N_Generic_Instantiation
22690 and then Nkind
(Parent
(Parent
(Par
))) = N_Compilation_Unit
22694 -- The context is not suitable when the reference appears within
22695 -- a pragma. If the pragma has run-time semantics, the reference
22696 -- will be reconsidered once the pragma is expanded.
22698 elsif Nkind
(Par
) = N_Pragma
then
22701 -- The context is not suitable when the reference appears within a
22702 -- subprogram call, and the caller requests this behavior.
22705 and then Nkind
(Par
) in N_Entry_Call_Statement
22707 | N_Procedure_Call_Statement
22711 -- Prevent the search from going too far
22713 elsif Is_Body_Or_Package_Declaration
(Par
) then
22717 Par
:= Parent
(Par
);
22721 end Within_Suitable_Context
;
22726 Var_Id
: Entity_Id
;
22728 -- Start of processing for Needs_Variable_Reference_Marker
22731 -- No marker needs to be created when switch -gnatH (legacy elaboration
22732 -- checking mode enabled) is in effect because the legacy ABE mechanism
22733 -- does not use markers.
22735 if Legacy_Elaboration_Checks
then
22738 -- No marker needs to be created when the reference is preanalyzed
22739 -- because the marker will be inserted in the wrong place.
22741 elsif Preanalysis_Active
then
22744 -- Only references warrant a marker
22746 elsif Nkind
(N
) not in N_Expanded_Name | N_Identifier
then
22749 -- Only source references warrant a marker
22751 elsif not Comes_From_Source
(N
) then
22754 -- No marker needs to be created when the reference is erroneous, left
22755 -- in a bad state, or does not denote a variable.
22757 elsif not (Present
(Entity
(N
))
22758 and then Ekind
(Entity
(N
)) = E_Variable
22759 and then Entity
(N
) /= Any_Id
)
22764 Var_Id
:= Entity
(N
);
22765 Prag
:= SPARK_Pragma
(Var_Id
);
22767 -- Both the variable and reference must appear in SPARK_Mode On regions
22768 -- because this elaboration scenario falls under the SPARK rules.
22770 if not (Comes_From_Source
(Var_Id
)
22771 and then Present
(Prag
)
22772 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
22773 and then Is_SPARK_Mode_On_Node
(N
))
22777 -- No marker needs to be created when the reference does not appear
22778 -- within a suitable context (see body for details).
22780 -- Performance note: parent traversal
22782 elsif not Within_Suitable_Context
(N
) then
22786 -- At this point it is known that the variable reference will play a
22787 -- role in ABE diagnostics and requires a marker.
22790 end Needs_Variable_Reference_Marker
;
22792 ------------------------
22793 -- New_Copy_List_Tree --
22794 ------------------------
22796 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
22801 if List
= No_List
then
22808 while Present
(E
) loop
22809 Append
(New_Copy_Tree
(E
), NL
);
22815 end New_Copy_List_Tree
;
22817 -------------------
22818 -- New_Copy_Tree --
22819 -------------------
22821 -- The following tables play a key role in replicating entities and Itypes.
22822 -- They are intentionally declared at the library level rather than within
22823 -- New_Copy_Tree to avoid elaborating them on each call. This performance
22824 -- optimization saves up to 2% of the entire compilation time spent in the
22825 -- front end. Care should be taken to reset the tables on each new call to
22828 NCT_Table_Max
: constant := 511;
22830 subtype NCT_Table_Index
is Nat
range 0 .. NCT_Table_Max
- 1;
22832 function NCT_Table_Hash
(Key
: Node_Or_Entity_Id
) return NCT_Table_Index
;
22833 -- Obtain the hash value of node or entity Key
22835 --------------------
22836 -- NCT_Table_Hash --
22837 --------------------
22839 function NCT_Table_Hash
(Key
: Node_Or_Entity_Id
) return NCT_Table_Index
is
22841 return NCT_Table_Index
(Key
mod NCT_Table_Max
);
22842 end NCT_Table_Hash
;
22844 ----------------------
22845 -- NCT_New_Entities --
22846 ----------------------
22848 -- The following table maps old entities and Itypes to their corresponding
22849 -- new entities and Itypes.
22853 package NCT_New_Entities
is new Simple_HTable
(
22854 Header_Num
=> NCT_Table_Index
,
22855 Element
=> Entity_Id
,
22856 No_Element
=> Empty
,
22858 Hash
=> NCT_Table_Hash
,
22861 ------------------------
22862 -- NCT_Pending_Itypes --
22863 ------------------------
22865 -- The following table maps old Associated_Node_For_Itype nodes to a set of
22866 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
22867 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
22868 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
22870 -- Ppp -> (Xxx, Yyy, Zzz)
22872 -- The set is expressed as an Elist
22874 package NCT_Pending_Itypes
is new Simple_HTable
(
22875 Header_Num
=> NCT_Table_Index
,
22876 Element
=> Elist_Id
,
22877 No_Element
=> No_Elist
,
22879 Hash
=> NCT_Table_Hash
,
22882 NCT_Tables_In_Use
: Boolean := False;
22883 -- This flag keeps track of whether the two tables NCT_New_Entities and
22884 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
22885 -- where certain operations are not performed if the tables are not in
22886 -- use. This saves up to 8% of the entire compilation time spent in the
22889 -------------------
22890 -- New_Copy_Tree --
22891 -------------------
22893 function New_Copy_Tree
22895 Map
: Elist_Id
:= No_Elist
;
22896 New_Sloc
: Source_Ptr
:= No_Location
;
22897 New_Scope
: Entity_Id
:= Empty
) return Node_Id
22899 -- This routine performs low-level tree manipulations and needs access
22900 -- to the internals of the tree.
22902 EWA_Level
: Nat
:= 0;
22903 -- This counter keeps track of how many N_Expression_With_Actions nodes
22904 -- are encountered during a depth-first traversal of the subtree. These
22905 -- nodes may define new entities in their Actions lists and thus require
22906 -- special processing.
22908 EWA_Inner_Scope_Level
: Nat
:= 0;
22909 -- This counter keeps track of how many scoping constructs appear within
22910 -- an N_Expression_With_Actions node.
22912 procedure Add_New_Entity
(Old_Id
: Entity_Id
; New_Id
: Entity_Id
);
22913 pragma Inline
(Add_New_Entity
);
22914 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
22915 -- value New_Id. Old_Id is an entity which appears within the Actions
22916 -- list of an N_Expression_With_Actions node, or within an entity map.
22917 -- New_Id is the corresponding new entity generated during Phase 1.
22919 procedure Add_Pending_Itype
(Assoc_Nod
: Node_Id
; Itype
: Entity_Id
);
22920 pragma Inline
(Add_Pending_Itype
);
22921 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
22922 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
22925 procedure Build_NCT_Tables
(Entity_Map
: Elist_Id
);
22926 pragma Inline
(Build_NCT_Tables
);
22927 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
22928 -- information supplied in entity map Entity_Map. The format of the
22929 -- entity map must be as follows:
22931 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
22933 function Copy_Any_Node_With_Replacement
22934 (N
: Node_Or_Entity_Id
) return Node_Or_Entity_Id
;
22935 pragma Inline
(Copy_Any_Node_With_Replacement
);
22936 -- Replicate entity or node N by invoking one of the following routines:
22938 -- Copy_Node_With_Replacement
22939 -- Corresponding_Entity
22941 function Copy_Elist_With_Replacement
(List
: Elist_Id
) return Elist_Id
;
22942 -- Replicate the elements of entity list List
22944 function Copy_Field_With_Replacement
22946 Old_Par
: Node_Id
:= Empty
;
22947 New_Par
: Node_Id
:= Empty
;
22948 Semantic
: Boolean := False) return Union_Id
;
22949 -- Replicate field Field by invoking one of the following routines:
22951 -- Copy_Elist_With_Replacement
22952 -- Copy_List_With_Replacement
22953 -- Copy_Node_With_Replacement
22954 -- Corresponding_Entity
22956 -- If the field is not an entity list, entity, itype, syntactic list,
22957 -- or node, then the field is returned unchanged. The routine always
22958 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
22959 -- the expected parent of a syntactic field. New_Par is the new parent
22960 -- associated with a replicated syntactic field. Flag Semantic should
22961 -- be set when the input is a semantic field.
22963 function Copy_List_With_Replacement
(List
: List_Id
) return List_Id
;
22964 -- Replicate the elements of syntactic list List
22966 function Copy_Node_With_Replacement
(N
: Node_Id
) return Node_Id
;
22967 -- Replicate node N
22969 function Corresponding_Entity
(Id
: Entity_Id
) return Entity_Id
;
22970 pragma Inline
(Corresponding_Entity
);
22971 -- Return the corresponding new entity of Id generated during Phase 1.
22972 -- If there is no such entity, return Id.
22974 function In_Entity_Map
22976 Entity_Map
: Elist_Id
) return Boolean;
22977 pragma Inline
(In_Entity_Map
);
22978 -- Determine whether entity Id is one of the old ids specified in entity
22979 -- map Entity_Map. The format of the entity map must be as follows:
22981 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
22983 procedure Update_CFS_Sloc
(N
: Node_Or_Entity_Id
);
22984 pragma Inline
(Update_CFS_Sloc
);
22985 -- Update the Comes_From_Source and Sloc attributes of node or entity N
22987 procedure Update_Controlling_Argument
22988 (Old_Call
: Node_Id
;
22989 New_Call
: Node_Id
);
22990 pragma Inline
(Update_Controlling_Argument
);
22991 -- Update Controlling_Argument of New_Call base on Old_Call to make it
22992 -- points to the corresponding newly copied actual parameter.
22994 procedure Update_Named_Associations
22995 (Old_Call
: Node_Id
;
22996 New_Call
: Node_Id
);
22997 pragma Inline
(Update_Named_Associations
);
22998 -- Update semantic chain First/Next_Named_Association of call New_call
22999 -- based on call Old_Call.
23001 procedure Update_New_Entities
(Entity_Map
: Elist_Id
);
23002 pragma Inline
(Update_New_Entities
);
23003 -- Update the semantic attributes of all new entities generated during
23004 -- Phase 1 that do not appear in entity map Entity_Map. The format of
23005 -- the entity map must be as follows:
23007 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
23009 procedure Update_Pending_Itypes
23010 (Old_Assoc
: Node_Id
;
23011 New_Assoc
: Node_Id
);
23012 pragma Inline
(Update_Pending_Itypes
);
23013 -- Update semantic attribute Associated_Node_For_Itype to refer to node
23014 -- New_Assoc for all itypes whose associated node is Old_Assoc.
23016 procedure Update_Semantic_Fields
(Id
: Entity_Id
);
23017 pragma Inline
(Update_Semantic_Fields
);
23018 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
23021 procedure Visit_Any_Node
(N
: Node_Or_Entity_Id
);
23022 pragma Inline
(Visit_Any_Node
);
23023 -- Visit entity of node N by invoking one of the following routines:
23029 procedure Visit_Elist
(List
: Elist_Id
);
23030 -- Visit the elements of entity list List
23032 procedure Visit_Entity
(Id
: Entity_Id
);
23033 -- Visit entity Id. This action may create a new entity of Id and save
23034 -- it in table NCT_New_Entities.
23036 procedure Visit_Field
23038 Par_Nod
: Node_Id
:= Empty
;
23039 Semantic
: Boolean := False);
23040 -- Visit field Field by invoking one of the following routines:
23048 -- If the field is not an entity list, entity, itype, syntactic list,
23049 -- or node, then the field is not visited. The routine always visits
23050 -- valid syntactic fields. Par_Nod is the expected parent of the
23051 -- syntactic field. Flag Semantic should be set when the input is a
23054 procedure Visit_Itype
(Itype
: Entity_Id
);
23055 -- Visit itype Itype. This action may create a new entity for Itype and
23056 -- save it in table NCT_New_Entities. In addition, the routine may map
23057 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
23059 procedure Visit_List
(List
: List_Id
);
23060 -- Visit the elements of syntactic list List
23062 procedure Visit_Node
(N
: Node_Id
);
23065 procedure Visit_Semantic_Fields
(Id
: Entity_Id
);
23066 pragma Inline
(Visit_Semantic_Fields
);
23067 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
23068 -- fields of entity or itype Id.
23070 --------------------
23071 -- Add_New_Entity --
23072 --------------------
23074 procedure Add_New_Entity
(Old_Id
: Entity_Id
; New_Id
: Entity_Id
) is
23076 pragma Assert
(Present
(Old_Id
));
23077 pragma Assert
(Present
(New_Id
));
23078 pragma Assert
(Nkind
(Old_Id
) in N_Entity
);
23079 pragma Assert
(Nkind
(New_Id
) in N_Entity
);
23081 NCT_Tables_In_Use
:= True;
23083 -- Sanity check the NCT_New_Entities table. No previous mapping with
23084 -- key Old_Id should exist.
23086 pragma Assert
(No
(NCT_New_Entities
.Get
(Old_Id
)));
23088 -- Establish the mapping
23090 -- Old_Id -> New_Id
23092 NCT_New_Entities
.Set
(Old_Id
, New_Id
);
23093 end Add_New_Entity
;
23095 -----------------------
23096 -- Add_Pending_Itype --
23097 -----------------------
23099 procedure Add_Pending_Itype
(Assoc_Nod
: Node_Id
; Itype
: Entity_Id
) is
23103 pragma Assert
(Present
(Assoc_Nod
));
23104 pragma Assert
(Present
(Itype
));
23105 pragma Assert
(Nkind
(Itype
) in N_Entity
);
23106 pragma Assert
(Is_Itype
(Itype
));
23108 NCT_Tables_In_Use
:= True;
23110 -- It is not possible to sanity check the NCT_Pendint_Itypes table
23111 -- directly because a single node may act as the associated node for
23112 -- multiple itypes.
23114 Itypes
:= NCT_Pending_Itypes
.Get
(Assoc_Nod
);
23116 if No
(Itypes
) then
23117 Itypes
:= New_Elmt_List
;
23118 NCT_Pending_Itypes
.Set
(Assoc_Nod
, Itypes
);
23121 -- Establish the mapping
23123 -- Assoc_Nod -> (Itype, ...)
23125 -- Avoid inserting the same itype multiple times. This involves a
23126 -- linear search, however the set of itypes with the same associated
23127 -- node is very small.
23129 Append_Unique_Elmt
(Itype
, Itypes
);
23130 end Add_Pending_Itype
;
23132 ----------------------
23133 -- Build_NCT_Tables --
23134 ----------------------
23136 procedure Build_NCT_Tables
(Entity_Map
: Elist_Id
) is
23138 Old_Id
: Entity_Id
;
23139 New_Id
: Entity_Id
;
23142 -- Nothing to do when there is no entity map
23144 if No
(Entity_Map
) then
23148 Elmt
:= First_Elmt
(Entity_Map
);
23149 while Present
(Elmt
) loop
23151 -- Extract the (Old_Id, New_Id) pair from the entity map
23153 Old_Id
:= Node
(Elmt
);
23156 New_Id
:= Node
(Elmt
);
23159 -- Establish the following mapping within table NCT_New_Entities
23161 -- Old_Id -> New_Id
23163 Add_New_Entity
(Old_Id
, New_Id
);
23165 -- Establish the following mapping within table NCT_Pending_Itypes
23166 -- when the new entity is an itype.
23168 -- Assoc_Nod -> (New_Id, ...)
23170 -- IMPORTANT: the associated node is that of the old itype because
23171 -- the node will be replicated in Phase 2.
23173 if Is_Itype
(Old_Id
) then
23175 (Assoc_Nod
=> Associated_Node_For_Itype
(Old_Id
),
23179 end Build_NCT_Tables
;
23181 ------------------------------------
23182 -- Copy_Any_Node_With_Replacement --
23183 ------------------------------------
23185 function Copy_Any_Node_With_Replacement
23186 (N
: Node_Or_Entity_Id
) return Node_Or_Entity_Id
23189 if Nkind
(N
) in N_Entity
then
23190 return Corresponding_Entity
(N
);
23192 return Copy_Node_With_Replacement
(N
);
23194 end Copy_Any_Node_With_Replacement
;
23196 ---------------------------------
23197 -- Copy_Elist_With_Replacement --
23198 ---------------------------------
23200 function Copy_Elist_With_Replacement
(List
: Elist_Id
) return Elist_Id
is
23205 -- Copy the contents of the old list. Note that the list itself may
23206 -- be empty, in which case the routine returns a new empty list. This
23207 -- avoids sharing lists between subtrees. The element of an entity
23208 -- list could be an entity or a node, hence the invocation of routine
23209 -- Copy_Any_Node_With_Replacement.
23211 if Present
(List
) then
23212 Result
:= New_Elmt_List
;
23214 Elmt
:= First_Elmt
(List
);
23215 while Present
(Elmt
) loop
23217 (Copy_Any_Node_With_Replacement
(Node
(Elmt
)), Result
);
23222 -- Otherwise the list does not exist
23225 Result
:= No_Elist
;
23229 end Copy_Elist_With_Replacement
;
23231 ---------------------------------
23232 -- Copy_Field_With_Replacement --
23233 ---------------------------------
23235 function Copy_Field_With_Replacement
23237 Old_Par
: Node_Id
:= Empty
;
23238 New_Par
: Node_Id
:= Empty
;
23239 Semantic
: Boolean := False) return Union_Id
23242 -- The field is empty
23244 if Field
= Union_Id
(Empty
) then
23247 -- The field is an entity/itype/node
23249 elsif Field
in Node_Range
then
23251 Old_N
: constant Node_Id
:= Node_Id
(Field
);
23252 Syntactic
: constant Boolean :=
23253 Is_Syntactic_Node
(Source
=> Old_Par
, Field
=> Old_N
);
23258 -- The field is an entity/itype
23260 if Nkind
(Old_N
) in N_Entity
then
23262 -- An entity/itype is always replicated
23264 New_N
:= Corresponding_Entity
(Old_N
);
23266 -- Update the parent pointer when the entity is a syntactic
23267 -- field. Note that itypes do not have parent pointers.
23269 if Syntactic
and then New_N
/= Old_N
then
23270 Set_Parent
(New_N
, New_Par
);
23273 -- The field is a node
23276 -- A node is replicated when it is either a syntactic field
23277 -- or when the caller treats it as a semantic attribute.
23279 if Syntactic
or else Semantic
then
23280 New_N
:= Copy_Node_With_Replacement
(Old_N
);
23282 -- Update the parent pointer when the node is a syntactic
23285 if Syntactic
and then New_N
/= Old_N
then
23286 Set_Parent
(New_N
, New_Par
);
23289 -- Otherwise the node is returned unchanged
23296 return Union_Id
(New_N
);
23299 -- The field is an entity list
23301 elsif Field
in Elist_Range
then
23302 return Union_Id
(Copy_Elist_With_Replacement
(Elist_Id
(Field
)));
23304 -- The field is a syntactic list
23306 elsif Field
in List_Range
then
23308 Old_List
: constant List_Id
:= List_Id
(Field
);
23309 Syntactic
: constant Boolean := Parent
(Old_List
) = Old_Par
;
23311 New_List
: List_Id
;
23314 -- A list is replicated when it is either a syntactic field or
23315 -- when the caller treats it as a semantic attribute.
23317 if Syntactic
or else Semantic
then
23318 New_List
:= Copy_List_With_Replacement
(Old_List
);
23320 -- Update the parent pointer when the list is a syntactic
23323 if Syntactic
and then New_List
/= Old_List
then
23324 Set_Parent
(New_List
, New_Par
);
23327 -- Otherwise the list is returned unchanged
23330 New_List
:= Old_List
;
23333 return Union_Id
(New_List
);
23336 -- Otherwise the field denotes an attribute that does not need to be
23337 -- replicated (Chars, literals, etc).
23342 end Copy_Field_With_Replacement
;
23344 --------------------------------
23345 -- Copy_List_With_Replacement --
23346 --------------------------------
23348 function Copy_List_With_Replacement
(List
: List_Id
) return List_Id
is
23353 -- Copy the contents of the old list. Note that the list itself may
23354 -- be empty, in which case the routine returns a new empty list. This
23355 -- avoids sharing lists between subtrees. The element of a syntactic
23356 -- list is always a node, never an entity or itype, hence the call to
23357 -- routine Copy_Node_With_Replacement.
23359 if Present
(List
) then
23360 Result
:= New_List
;
23362 Elmt
:= First
(List
);
23363 while Present
(Elmt
) loop
23364 Append
(Copy_Node_With_Replacement
(Elmt
), Result
);
23369 -- Otherwise the list does not exist
23376 end Copy_List_With_Replacement
;
23378 --------------------------------
23379 -- Copy_Node_With_Replacement --
23380 --------------------------------
23382 function Copy_Node_With_Replacement
(N
: Node_Id
) return Node_Id
is
23385 function Transform
(U
: Union_Id
) return Union_Id
;
23386 -- Copies one field, replacing N with Result
23392 function Transform
(U
: Union_Id
) return Union_Id
is
23394 return Copy_Field_With_Replacement
23397 New_Par
=> Result
);
23400 procedure Walk
is new Walk_Sinfo_Fields_Pairwise
(Transform
);
23402 -- Start of processing for Copy_Node_With_Replacement
23405 -- Assume that the node must be returned unchanged
23409 if N
> Empty_Or_Error
then
23410 pragma Assert
(Nkind
(N
) not in N_Entity
);
23412 Result
:= New_Copy
(N
);
23414 Walk
(Result
, Result
);
23416 -- Update the Comes_From_Source and Sloc attributes of the node
23417 -- in case the caller has supplied new values.
23419 Update_CFS_Sloc
(Result
);
23421 -- Update the Associated_Node_For_Itype attribute of all itypes
23422 -- created during Phase 1 whose associated node is N. As a result
23423 -- the Associated_Node_For_Itype refers to the replicated node.
23424 -- No action needs to be taken when the Associated_Node_For_Itype
23425 -- refers to an entity because this was already handled during
23426 -- Phase 1, in Visit_Itype.
23428 Update_Pending_Itypes
23430 New_Assoc
=> Result
);
23432 -- Update the First/Next_Named_Association chain and the
23433 -- Controlling_Argument for a replicated call.
23435 if Nkind
(N
) in N_Entry_Call_Statement
23436 | N_Subprogram_Call
23438 Update_Named_Associations
23440 New_Call
=> Result
);
23442 if Nkind
(N
) in N_Subprogram_Call
then
23443 Update_Controlling_Argument
23445 New_Call
=> Result
);
23448 -- Update the Renamed_Object attribute of a replicated object
23451 elsif Nkind
(N
) = N_Object_Renaming_Declaration
then
23452 Set_Renamed_Object_Of_Possibly_Void
23453 (Defining_Entity
(Result
), Name
(Result
));
23455 -- Update the Chars attribute of identifiers
23457 elsif Nkind
(N
) = N_Identifier
then
23459 -- The Entity field of identifiers that denote aspects is used
23460 -- to store arbitrary expressions (and hence we must check that
23461 -- they reference an actual entity before copying their Chars
23464 if Present
(Entity
(Result
))
23465 and then Nkind
(Entity
(Result
)) in N_Entity
23467 Set_Chars
(Result
, Chars
(Entity
(Result
)));
23473 end Copy_Node_With_Replacement
;
23475 --------------------------
23476 -- Corresponding_Entity --
23477 --------------------------
23479 function Corresponding_Entity
(Id
: Entity_Id
) return Entity_Id
is
23480 New_Id
: Entity_Id
;
23481 Result
: Entity_Id
;
23484 -- Assume that the entity must be returned unchanged
23488 if Id
> Empty_Or_Error
then
23489 pragma Assert
(Nkind
(Id
) in N_Entity
);
23491 -- Determine whether the entity has a corresponding new entity
23492 -- generated during Phase 1 and if it does, use it.
23494 if NCT_Tables_In_Use
then
23495 New_Id
:= NCT_New_Entities
.Get
(Id
);
23497 if Present
(New_Id
) then
23504 end Corresponding_Entity
;
23506 -------------------
23507 -- In_Entity_Map --
23508 -------------------
23510 function In_Entity_Map
23512 Entity_Map
: Elist_Id
) return Boolean
23515 Old_Id
: Entity_Id
;
23518 -- The entity map contains pairs (Old_Id, New_Id). The advancement
23519 -- step always skips the New_Id portion of the pair.
23521 if Present
(Entity_Map
) then
23522 Elmt
:= First_Elmt
(Entity_Map
);
23523 while Present
(Elmt
) loop
23524 Old_Id
:= Node
(Elmt
);
23526 if Old_Id
= Id
then
23538 ---------------------
23539 -- Update_CFS_Sloc --
23540 ---------------------
23542 procedure Update_CFS_Sloc
(N
: Node_Or_Entity_Id
) is
23544 -- A new source location defaults the Comes_From_Source attribute
23546 if New_Sloc
/= No_Location
then
23547 Set_Comes_From_Source
(N
, Get_Comes_From_Source_Default
);
23548 Set_Sloc
(N
, New_Sloc
);
23550 end Update_CFS_Sloc
;
23552 ---------------------------------
23553 -- Update_Controlling_Argument --
23554 ---------------------------------
23556 procedure Update_Controlling_Argument
23557 (Old_Call
: Node_Id
;
23558 New_Call
: Node_Id
)
23563 Old_Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Old_Call
);
23564 -- Controlling argument of the old call node
23566 Replaced
: Boolean := False;
23567 -- Flag to make sure that replacement works as expected
23570 if No
(Old_Ctrl_Arg
) then
23574 -- Recreate the Controlling_Argument of a call by traversing both the
23575 -- old and new actual parameters in parallel.
23577 New_Act
:= First
(Parameter_Associations
(New_Call
));
23578 Old_Act
:= First
(Parameter_Associations
(Old_Call
));
23579 while Present
(Old_Act
) loop
23581 -- Actual parameter appears either in a named parameter
23582 -- association or directly.
23584 if Nkind
(Old_Act
) = N_Parameter_Association
then
23585 if Explicit_Actual_Parameter
(Old_Act
) = Old_Ctrl_Arg
then
23586 Set_Controlling_Argument
23587 (New_Call
, Explicit_Actual_Parameter
(New_Act
));
23592 elsif Old_Act
= Old_Ctrl_Arg
then
23593 Set_Controlling_Argument
(New_Call
, New_Act
);
23602 pragma Assert
(Replaced
);
23603 end Update_Controlling_Argument
;
23605 -------------------------------
23606 -- Update_Named_Associations --
23607 -------------------------------
23609 procedure Update_Named_Associations
23610 (Old_Call
: Node_Id
;
23611 New_Call
: Node_Id
)
23614 New_Next
: Node_Id
;
23616 Old_Next
: Node_Id
;
23619 if No
(First_Named_Actual
(Old_Call
)) then
23623 -- Recreate the First/Next_Named_Actual chain of a call by traversing
23624 -- the chains of both the old and new calls in parallel.
23626 New_Act
:= First
(Parameter_Associations
(New_Call
));
23627 Old_Act
:= First
(Parameter_Associations
(Old_Call
));
23628 while Present
(Old_Act
) loop
23629 if Nkind
(Old_Act
) = N_Parameter_Association
23630 and then Explicit_Actual_Parameter
(Old_Act
)
23631 = First_Named_Actual
(Old_Call
)
23633 Set_First_Named_Actual
(New_Call
,
23634 Explicit_Actual_Parameter
(New_Act
));
23637 if Nkind
(Old_Act
) = N_Parameter_Association
23638 and then Present
(Next_Named_Actual
(Old_Act
))
23640 -- Scan the actual parameter list to find the next suitable
23641 -- named actual. Note that the list may be out of order.
23643 New_Next
:= First
(Parameter_Associations
(New_Call
));
23644 Old_Next
:= First
(Parameter_Associations
(Old_Call
));
23645 while Nkind
(Old_Next
) /= N_Parameter_Association
23646 or else Explicit_Actual_Parameter
(Old_Next
) /=
23647 Next_Named_Actual
(Old_Act
)
23653 Set_Next_Named_Actual
(New_Act
,
23654 Explicit_Actual_Parameter
(New_Next
));
23660 end Update_Named_Associations
;
23662 -------------------------
23663 -- Update_New_Entities --
23664 -------------------------
23666 procedure Update_New_Entities
(Entity_Map
: Elist_Id
) is
23667 New_Id
: Entity_Id
:= Empty
;
23668 Old_Id
: Entity_Id
:= Empty
;
23671 if NCT_Tables_In_Use
then
23672 NCT_New_Entities
.Get_First
(Old_Id
, New_Id
);
23674 -- Update the semantic fields of all new entities created during
23675 -- Phase 1 which were not supplied via an entity map.
23676 -- ??? Is there a better way of distinguishing those?
23678 while Present
(Old_Id
) and then Present
(New_Id
) loop
23679 if not In_Entity_Map
(Old_Id
, Entity_Map
) then
23680 Update_Semantic_Fields
(New_Id
);
23683 NCT_New_Entities
.Get_Next
(Old_Id
, New_Id
);
23686 end Update_New_Entities
;
23688 ---------------------------
23689 -- Update_Pending_Itypes --
23690 ---------------------------
23692 procedure Update_Pending_Itypes
23693 (Old_Assoc
: Node_Id
;
23694 New_Assoc
: Node_Id
)
23700 if NCT_Tables_In_Use
then
23701 Itypes
:= NCT_Pending_Itypes
.Get
(Old_Assoc
);
23703 -- Update the Associated_Node_For_Itype attribute for all itypes
23704 -- which originally refer to Old_Assoc to designate New_Assoc.
23706 if Present
(Itypes
) then
23707 Item
:= First_Elmt
(Itypes
);
23708 while Present
(Item
) loop
23709 Set_Associated_Node_For_Itype
(Node
(Item
), New_Assoc
);
23715 end Update_Pending_Itypes
;
23717 ----------------------------
23718 -- Update_Semantic_Fields --
23719 ----------------------------
23721 procedure Update_Semantic_Fields
(Id
: Entity_Id
) is
23723 -- Discriminant_Constraint
23725 if Is_Type
(Id
) and then Has_Discriminants
(Base_Type
(Id
)) then
23726 Set_Discriminant_Constraint
(Id
, Elist_Id
(
23727 Copy_Field_With_Replacement
23728 (Field
=> Union_Id
(Discriminant_Constraint
(Id
)),
23729 Semantic
=> True)));
23734 Set_Etype
(Id
, Node_Id
(
23735 Copy_Field_With_Replacement
23736 (Field
=> Union_Id
(Etype
(Id
)),
23737 Semantic
=> True)));
23740 -- Packed_Array_Impl_Type
23742 if Is_Array_Type
(Id
) then
23743 if Present
(First_Index
(Id
)) then
23744 Set_First_Index
(Id
, First
(List_Id
(
23745 Copy_Field_With_Replacement
23746 (Field
=> Union_Id
(List_Containing
(First_Index
(Id
))),
23747 Semantic
=> True))));
23750 if Is_Packed
(Id
) then
23751 Set_Packed_Array_Impl_Type
(Id
, Node_Id
(
23752 Copy_Field_With_Replacement
23753 (Field
=> Union_Id
(Packed_Array_Impl_Type
(Id
)),
23754 Semantic
=> True)));
23760 Set_Prev_Entity
(Id
, Node_Id
(
23761 Copy_Field_With_Replacement
23762 (Field
=> Union_Id
(Prev_Entity
(Id
)),
23763 Semantic
=> True)));
23767 Set_Next_Entity
(Id
, Node_Id
(
23768 Copy_Field_With_Replacement
23769 (Field
=> Union_Id
(Next_Entity
(Id
)),
23770 Semantic
=> True)));
23774 if Is_Discrete_Type
(Id
) then
23775 Set_Scalar_Range
(Id
, Node_Id
(
23776 Copy_Field_With_Replacement
23777 (Field
=> Union_Id
(Scalar_Range
(Id
)),
23778 Semantic
=> True)));
23783 -- Update the scope when the caller specified an explicit one
23785 if Present
(New_Scope
) then
23786 Set_Scope
(Id
, New_Scope
);
23788 Set_Scope
(Id
, Node_Id
(
23789 Copy_Field_With_Replacement
23790 (Field
=> Union_Id
(Scope
(Id
)),
23791 Semantic
=> True)));
23793 end Update_Semantic_Fields
;
23795 --------------------
23796 -- Visit_Any_Node --
23797 --------------------
23799 procedure Visit_Any_Node
(N
: Node_Or_Entity_Id
) is
23801 if Nkind
(N
) in N_Entity
then
23802 if Is_Itype
(N
) then
23810 end Visit_Any_Node
;
23816 procedure Visit_Elist
(List
: Elist_Id
) is
23820 -- The element of an entity list could be an entity, itype, or a
23821 -- node, hence the call to Visit_Any_Node.
23823 if Present
(List
) then
23824 Elmt
:= First_Elmt
(List
);
23825 while Present
(Elmt
) loop
23826 Visit_Any_Node
(Node
(Elmt
));
23837 procedure Visit_Entity
(Id
: Entity_Id
) is
23838 New_Id
: Entity_Id
;
23841 pragma Assert
(Nkind
(Id
) in N_Entity
);
23842 pragma Assert
(not Is_Itype
(Id
));
23844 -- Nothing to do when the entity is not defined in the Actions list
23845 -- of an N_Expression_With_Actions node.
23847 if EWA_Level
= 0 then
23850 -- Nothing to do when the entity is defined in a scoping construct
23851 -- within an N_Expression_With_Actions node.
23853 elsif EWA_Inner_Scope_Level
> 0 then
23856 -- Nothing to do when the entity does not denote a construct that
23857 -- may appear within an N_Expression_With_Actions node. Relaxing
23858 -- this restriction leads to a performance penalty.
23860 -- ??? this list is flaky, and may hide dormant bugs
23861 -- Should functions be included???
23863 -- Quantified expressions contain an entity declaration that must
23864 -- always be replaced when the expander is active, even if it has
23865 -- not been analyzed yet like e.g. in predicates.
23867 elsif Ekind
(Id
) not in E_Block
23872 and then not Is_Entity_Of_Quantified_Expression
(Id
)
23873 and then not Is_Type
(Id
)
23877 -- Nothing to do when the entity was already visited
23879 elsif NCT_Tables_In_Use
23880 and then Present
(NCT_New_Entities
.Get
(Id
))
23884 -- Nothing to do when the declaration node of the entity is not in
23885 -- the subtree being replicated.
23887 elsif not In_Subtree
23888 (N
=> Declaration_Node
(Id
),
23894 -- Create a new entity by directly copying the old entity. This
23895 -- action causes all attributes of the old entity to be inherited.
23897 New_Id
:= New_Copy
(Id
);
23899 -- Create a new name for the new entity because the back end needs
23900 -- distinct names for debugging purposes, provided that the entity
23901 -- has already been analyzed.
23903 if Ekind
(Id
) /= E_Void
then
23904 Set_Chars
(New_Id
, New_Internal_Name
('T'));
23907 -- Update the Comes_From_Source and Sloc attributes of the entity in
23908 -- case the caller has supplied new values.
23910 Update_CFS_Sloc
(New_Id
);
23912 -- Establish the following mapping within table NCT_New_Entities:
23916 Add_New_Entity
(Id
, New_Id
);
23918 -- Deal with the semantic fields of entities. The fields are visited
23919 -- because they may mention entities which reside within the subtree
23922 Visit_Semantic_Fields
(Id
);
23929 procedure Visit_Field
23931 Par_Nod
: Node_Id
:= Empty
;
23932 Semantic
: Boolean := False)
23935 -- The field is empty
23937 if Field
= Union_Id
(Empty
) then
23940 -- The field is an entity/itype/node
23942 elsif Field
in Node_Range
then
23944 N
: constant Node_Id
:= Node_Id
(Field
);
23947 -- The field is an entity/itype
23949 if Nkind
(N
) in N_Entity
then
23951 -- Itypes are always visited
23953 if Is_Itype
(N
) then
23956 -- An entity is visited when it is either a syntactic field
23957 -- or when the caller treats it as a semantic attribute.
23959 elsif Parent
(N
) = Par_Nod
or else Semantic
then
23963 -- The field is a node
23966 -- A node is visited when it is either a syntactic field or
23967 -- when the caller treats it as a semantic attribute.
23969 if Parent
(N
) = Par_Nod
or else Semantic
then
23975 -- The field is an entity list
23977 elsif Field
in Elist_Range
then
23978 Visit_Elist
(Elist_Id
(Field
));
23980 -- The field is a syntax list
23982 elsif Field
in List_Range
then
23984 List
: constant List_Id
:= List_Id
(Field
);
23987 -- A syntax list is visited when it is either a syntactic field
23988 -- or when the caller treats it as a semantic attribute.
23990 if Parent
(List
) = Par_Nod
or else Semantic
then
23995 -- Otherwise the field denotes information which does not need to be
23996 -- visited (chars, literals, etc.).
24007 procedure Visit_Itype
(Itype
: Entity_Id
) is
24008 New_Assoc
: Node_Id
;
24009 New_Itype
: Entity_Id
;
24010 Old_Assoc
: Node_Id
;
24013 pragma Assert
(Nkind
(Itype
) in N_Entity
);
24014 pragma Assert
(Is_Itype
(Itype
));
24016 -- Itypes that describe the designated type of access to subprograms
24017 -- have the structure of subprogram declarations, with signatures,
24018 -- etc. Either we duplicate the signatures completely, or choose to
24019 -- share such itypes, which is fine because their elaboration will
24020 -- have no side effects.
24022 if Ekind
(Itype
) = E_Subprogram_Type
then
24025 -- Nothing to do if the itype was already visited
24027 elsif NCT_Tables_In_Use
24028 and then Present
(NCT_New_Entities
.Get
(Itype
))
24032 -- Nothing to do if the associated node of the itype is not within
24033 -- the subtree being replicated.
24035 elsif not In_Subtree
24036 (N
=> Associated_Node_For_Itype
(Itype
),
24042 -- Create a new itype by directly copying the old itype. This action
24043 -- causes all attributes of the old itype to be inherited.
24045 New_Itype
:= New_Copy
(Itype
);
24047 -- Create a new name for the new itype because the back end requires
24048 -- distinct names for debugging purposes.
24050 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
24052 -- Update the Comes_From_Source and Sloc attributes of the itype in
24053 -- case the caller has supplied new values.
24055 Update_CFS_Sloc
(New_Itype
);
24057 -- Establish the following mapping within table NCT_New_Entities:
24059 -- Itype -> New_Itype
24061 Add_New_Entity
(Itype
, New_Itype
);
24063 -- The new itype must be unfrozen because the resulting subtree may
24064 -- be inserted anywhere and cause an earlier or later freezing.
24066 if Present
(Freeze_Node
(New_Itype
)) then
24067 Set_Freeze_Node
(New_Itype
, Empty
);
24068 Set_Is_Frozen
(New_Itype
, False);
24071 -- If a record subtype is simply copied, the entity list will be
24072 -- shared, so Cloned_Subtype must be set to indicate this.
24074 if Ekind
(Itype
) in E_Class_Wide_Subtype | E_Record_Subtype
then
24075 Set_Cloned_Subtype
(New_Itype
, Itype
);
24078 -- The associated node may denote an entity, in which case it may
24079 -- already have a new corresponding entity created during a prior
24080 -- call to Visit_Entity or Visit_Itype for the same subtree.
24083 -- Old_Assoc ---------> New_Assoc
24085 -- Created by Visit_Itype
24086 -- Itype -------------> New_Itype
24087 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
24089 -- In the example above, Old_Assoc is an arbitrary entity that was
24090 -- already visited for the same subtree and has a corresponding new
24091 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
24092 -- of copying entities, however it must be updated to New_Assoc.
24094 Old_Assoc
:= Associated_Node_For_Itype
(Itype
);
24096 if Nkind
(Old_Assoc
) in N_Entity
then
24097 if NCT_Tables_In_Use
then
24098 New_Assoc
:= NCT_New_Entities
.Get
(Old_Assoc
);
24100 if Present
(New_Assoc
) then
24101 Set_Associated_Node_For_Itype
(New_Itype
, New_Assoc
);
24105 -- Otherwise the associated node denotes a node. Postpone the update
24106 -- until Phase 2 when the node is replicated. Establish the following
24107 -- mapping within table NCT_Pending_Itypes:
24109 -- Old_Assoc -> (New_Type, ...)
24112 Add_Pending_Itype
(Old_Assoc
, New_Itype
);
24115 -- Deal with the semantic fields of itypes. The fields are visited
24116 -- because they may mention entities that reside within the subtree
24119 Visit_Semantic_Fields
(Itype
);
24126 procedure Visit_List
(List
: List_Id
) is
24130 -- Note that the element of a syntactic list is always a node, never
24131 -- an entity or itype, hence the call to Visit_Node.
24133 Elmt
:= First
(List
);
24134 while Present
(Elmt
) loop
24145 procedure Visit_Node
(N
: Node_Id
) is
24147 pragma Assert
(Nkind
(N
) not in N_Entity
);
24149 -- If the node is a quantified expression and expander is active,
24150 -- it contains an implicit declaration that may require a new entity
24151 -- when the condition has already been (pre)analyzed.
24153 if Nkind
(N
) = N_Expression_With_Actions
24155 (Nkind
(N
) = N_Quantified_Expression
and then Expander_Active
)
24157 EWA_Level
:= EWA_Level
+ 1;
24159 elsif EWA_Level
> 0
24160 and then Nkind
(N
) in N_Block_Statement
24161 | N_Subprogram_Body
24162 | N_Subprogram_Declaration
24164 EWA_Inner_Scope_Level
:= EWA_Inner_Scope_Level
+ 1;
24167 -- If the node is a block, we need to process all declarations
24168 -- in the block and make new entities for each.
24170 if Nkind
(N
) = N_Block_Statement
then
24172 Decl
: Node_Id
:= First
(Declarations
(N
));
24175 while Present
(Decl
) loop
24176 if Nkind
(Decl
) = N_Object_Declaration
then
24177 Add_New_Entity
(Defining_Identifier
(Decl
),
24178 New_Copy
(Defining_Identifier
(Decl
)));
24187 procedure Action
(U
: Union_Id
);
24188 procedure Action
(U
: Union_Id
) is
24190 Visit_Field
(Field
=> U
, Par_Nod
=> N
);
24193 procedure Walk
is new Walk_Sinfo_Fields
(Action
);
24199 and then Nkind
(N
) in N_Block_Statement
24200 | N_Subprogram_Body
24201 | N_Subprogram_Declaration
24203 EWA_Inner_Scope_Level
:= EWA_Inner_Scope_Level
- 1;
24205 elsif Nkind
(N
) = N_Expression_With_Actions
24207 (Nkind
(N
) = N_Quantified_Expression
and then Expander_Active
)
24209 EWA_Level
:= EWA_Level
- 1;
24213 ---------------------------
24214 -- Visit_Semantic_Fields --
24215 ---------------------------
24217 procedure Visit_Semantic_Fields
(Id
: Entity_Id
) is
24219 pragma Assert
(Nkind
(Id
) in N_Entity
);
24221 -- Discriminant_Constraint
24223 if Is_Type
(Id
) and then Has_Discriminants
(Base_Type
(Id
)) then
24225 (Field
=> Union_Id
(Discriminant_Constraint
(Id
)),
24232 (Field
=> Union_Id
(Etype
(Id
)),
24236 -- Packed_Array_Impl_Type
24238 if Is_Array_Type
(Id
) then
24239 if Present
(First_Index
(Id
)) then
24241 (Field
=> Union_Id
(List_Containing
(First_Index
(Id
))),
24245 if Is_Packed
(Id
) then
24247 (Field
=> Union_Id
(Packed_Array_Impl_Type
(Id
)),
24254 if Is_Discrete_Type
(Id
) then
24256 (Field
=> Union_Id
(Scalar_Range
(Id
)),
24259 end Visit_Semantic_Fields
;
24261 -- Start of processing for New_Copy_Tree
24264 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
24265 -- shallow copies for each node within, and then updating the child and
24266 -- parent pointers accordingly. This process is straightforward, however
24267 -- the routine must deal with the following complications:
24269 -- * Entities defined within N_Expression_With_Actions nodes must be
24270 -- replicated rather than shared to avoid introducing two identical
24271 -- symbols within the same scope. Note that no other expression can
24272 -- currently define entities.
24275 -- Source_Low : ...;
24276 -- Source_High : ...;
24278 -- <reference to Source_Low>
24279 -- <reference to Source_High>
24282 -- New_Copy_Tree handles this case by first creating new entities
24283 -- and then updating all existing references to point to these new
24290 -- <reference to New_Low>
24291 -- <reference to New_High>
24294 -- * Itypes defined within the subtree must be replicated to avoid any
24295 -- dependencies on invalid or inaccessible data.
24297 -- subtype Source_Itype is ... range Source_Low .. Source_High;
24299 -- New_Copy_Tree handles this case by first creating a new itype in
24300 -- the same fashion as entities, and then updating various relevant
24303 -- subtype New_Itype is ... range New_Low .. New_High;
24305 -- * The Associated_Node_For_Itype field of itypes must be updated to
24306 -- reference the proper replicated entity or node.
24308 -- * Semantic fields of entities such as Etype and Scope must be
24309 -- updated to reference the proper replicated entities.
24311 -- * Some semantic fields of nodes must be updated to reference
24312 -- the proper replicated nodes.
24314 -- Finally, quantified expressions contain an implicit declaration for
24315 -- the bound variable. Given that quantified expressions appearing
24316 -- in contracts are copied to create pragmas and eventually checking
24317 -- procedures, a new bound variable must be created for each copy, to
24318 -- prevent multiple declarations of the same symbol.
24320 -- To meet all these demands, routine New_Copy_Tree is split into two
24323 -- Phase 1 traverses the tree in order to locate entities and itypes
24324 -- defined within the subtree. New entities are generated and saved in
24325 -- table NCT_New_Entities. The semantic fields of all new entities and
24326 -- itypes are then updated accordingly.
24328 -- Phase 2 traverses the tree in order to replicate each node. Various
24329 -- semantic fields of nodes and entities are updated accordingly.
24331 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
24332 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
24335 if NCT_Tables_In_Use
then
24336 NCT_Tables_In_Use
:= False;
24338 NCT_New_Entities
.Reset
;
24339 NCT_Pending_Itypes
.Reset
;
24342 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
24343 -- supplied by a linear entity map. The tables offer faster access to
24346 Build_NCT_Tables
(Map
);
24348 -- Execute Phase 1. Traverse the subtree and generate new entities for
24349 -- the following cases:
24351 -- * An entity defined within an N_Expression_With_Actions node
24353 -- * An itype referenced within the subtree where the associated node
24354 -- is also in the subtree.
24356 -- All new entities are accessible via table NCT_New_Entities, which
24357 -- contains mappings of the form:
24359 -- Old_Entity -> New_Entity
24360 -- Old_Itype -> New_Itype
24362 -- In addition, the associated nodes of all new itypes are mapped in
24363 -- table NCT_Pending_Itypes:
24365 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
24367 Visit_Any_Node
(Source
);
24369 -- Update the semantic attributes of all new entities generated during
24370 -- Phase 1 before starting Phase 2. The updates could be performed in
24371 -- routine Corresponding_Entity, however this may cause the same entity
24372 -- to be updated multiple times, effectively generating useless nodes.
24373 -- Keeping the updates separates from Phase 2 ensures that only one set
24374 -- of attributes is generated for an entity at any one time.
24376 Update_New_Entities
(Map
);
24378 -- Execute Phase 2. Replicate the source subtree one node at a time.
24379 -- The following transformations take place:
24381 -- * References to entities and itypes are updated to refer to the
24382 -- new entities and itypes generated during Phase 1.
24384 -- * All Associated_Node_For_Itype attributes of itypes are updated
24385 -- to refer to the new replicated Associated_Node_For_Itype.
24387 return Copy_Node_With_Replacement
(Source
);
24390 -------------------------
24391 -- New_External_Entity --
24392 -------------------------
24394 function New_External_Entity
24395 (Kind
: Entity_Kind
;
24396 Scope_Id
: Entity_Id
;
24397 Sloc_Value
: Source_Ptr
;
24398 Related_Id
: Entity_Id
;
24399 Suffix
: Character;
24400 Suffix_Index
: Int
:= 0;
24401 Prefix
: Character := ' ') return Entity_Id
24403 N
: constant Entity_Id
:=
24404 Make_Defining_Identifier
(Sloc_Value
,
24406 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
24409 Mutate_Ekind
(N
, Kind
);
24410 Set_Is_Internal
(N
, True);
24411 Append_Entity
(N
, Scope_Id
);
24412 Set_Public_Status
(N
);
24414 if Kind
in Type_Kind
then
24415 Reinit_Size_Align
(N
);
24419 end New_External_Entity
;
24421 -------------------------
24422 -- New_Internal_Entity --
24423 -------------------------
24425 function New_Internal_Entity
24426 (Kind
: Entity_Kind
;
24427 Scope_Id
: Entity_Id
;
24428 Sloc_Value
: Source_Ptr
;
24429 Id_Char
: Character) return Entity_Id
24431 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
24434 Mutate_Ekind
(N
, Kind
);
24435 Set_Is_Internal
(N
, True);
24436 Append_Entity
(N
, Scope_Id
);
24438 if Kind
in Type_Kind
then
24439 Reinit_Size_Align
(N
);
24443 end New_Internal_Entity
;
24449 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
24450 Par
: constant Node_Id
:= Parent
(Actual_Id
);
24454 -- If we are pointing at a positional parameter, it is a member of a
24455 -- node list (the list of parameters), and the next parameter is the
24456 -- next node on the list, unless we hit a parameter association, then
24457 -- we shift to using the chain whose head is the First_Named_Actual in
24458 -- the parent, and then is threaded using the Next_Named_Actual of the
24459 -- Parameter_Association. All this fiddling is because the original node
24460 -- list is in the textual call order, and what we need is the
24461 -- declaration order.
24463 if Is_List_Member
(Actual_Id
) then
24464 N
:= Next
(Actual_Id
);
24466 if Nkind
(N
) = N_Parameter_Association
then
24468 -- In case of a build-in-place call, the call will no longer be a
24469 -- call; it will have been rewritten.
24471 if Nkind
(Par
) in N_Entry_Call_Statement
24473 | N_Procedure_Call_Statement
24475 return First_Named_Actual
(Par
);
24477 -- In case of a call rewritten in GNATprove mode while "inlining
24478 -- for proof" go to the original call.
24480 elsif Nkind
(Par
) = N_Null_Statement
then
24484 Nkind
(Original_Node
(Par
)) in N_Subprogram_Call
);
24486 return First_Named_Actual
(Original_Node
(Par
));
24495 return Next_Named_Actual
(Parent
(Actual_Id
));
24499 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
24501 Actual_Id
:= Next_Actual
(Actual_Id
);
24508 function Next_Global
(Node
: Node_Id
) return Node_Id
is
24510 -- The global item may either be in a list, or by itself, in which case
24511 -- there is no next global item with the same mode.
24513 if Is_List_Member
(Node
) then
24514 return Next
(Node
);
24520 procedure Next_Global
(Node
: in out Node_Id
) is
24522 Node
:= Next_Global
(Node
);
24525 ------------------------
24526 -- No_Caching_Enabled --
24527 ------------------------
24529 function No_Caching_Enabled
(Id
: Entity_Id
) return Boolean is
24530 Prag
: constant Node_Id
:= Get_Pragma
(Id
, Pragma_No_Caching
);
24534 if Present
(Prag
) then
24535 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
24537 -- The pragma has an optional Boolean expression, the related
24538 -- property is enabled only when the expression evaluates to True.
24540 if Present
(Arg1
) then
24541 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
)));
24543 -- Otherwise the lack of expression enables the property by
24550 -- The property was never set in the first place
24555 end No_Caching_Enabled
;
24557 --------------------------
24558 -- No_Heap_Finalization --
24559 --------------------------
24561 function No_Heap_Finalization
(Typ
: Entity_Id
) return Boolean is
24563 if Ekind
(Typ
) in E_Access_Type | E_General_Access_Type
24564 and then Is_Library_Level_Entity
(Typ
)
24566 -- A global No_Heap_Finalization pragma applies to all library-level
24567 -- named access-to-object types.
24569 if Present
(No_Heap_Finalization_Pragma
) then
24572 -- The library-level named access-to-object type itself is subject to
24573 -- pragma No_Heap_Finalization.
24575 elsif Present
(Get_Pragma
(Typ
, Pragma_No_Heap_Finalization
)) then
24581 end No_Heap_Finalization
;
24583 -----------------------
24584 -- Normalize_Actuals --
24585 -----------------------
24587 -- Chain actuals according to formals of subprogram. If there are no named
24588 -- associations, the chain is simply the list of Parameter Associations,
24589 -- since the order is the same as the declaration order. If there are named
24590 -- associations, then the First_Named_Actual field in the N_Function_Call
24591 -- or N_Procedure_Call_Statement node points to the Parameter_Association
24592 -- node for the parameter that comes first in declaration order. The
24593 -- remaining named parameters are then chained in declaration order using
24594 -- Next_Named_Actual.
24596 -- This routine also verifies that the number of actuals is compatible with
24597 -- the number and default values of formals, but performs no type checking
24598 -- (type checking is done by the caller).
24600 -- If the matching succeeds, Success is set to True and the caller proceeds
24601 -- with type-checking. If the match is unsuccessful, then Success is set to
24602 -- False, and the caller attempts a different interpretation, if there is
24605 -- If the flag Report is on, the call is not overloaded, and a failure to
24606 -- match can be reported here, rather than in the caller.
24608 procedure Normalize_Actuals
24612 Success
: out Boolean)
24614 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
24615 Actual
: Node_Id
:= Empty
;
24616 Formal
: Entity_Id
;
24617 Last
: Node_Id
:= Empty
;
24618 First_Named
: Node_Id
:= Empty
;
24621 Formals_To_Match
: Integer := 0;
24622 Actuals_To_Match
: Integer := 0;
24624 procedure Chain
(A
: Node_Id
);
24625 -- Add named actual at the proper place in the list, using the
24626 -- Next_Named_Actual link.
24628 function Reporting
return Boolean;
24629 -- Determines if an error is to be reported. To report an error, we
24630 -- need Report to be True, and also we do not report errors caused
24631 -- by calls to init procs that occur within other init procs. Such
24632 -- errors must always be cascaded errors, since if all the types are
24633 -- declared correctly, the compiler will certainly build decent calls.
24639 procedure Chain
(A
: Node_Id
) is
24643 -- Call node points to first actual in list
24645 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
24648 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
24652 Set_Next_Named_Actual
(Last
, Empty
);
24659 function Reporting
return Boolean is
24664 elsif not Within_Init_Proc
then
24667 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
24675 -- Start of processing for Normalize_Actuals
24678 if Is_Access_Type
(S
) then
24680 -- The name in the call is a function call that returns an access
24681 -- to subprogram. The designated type has the list of formals.
24683 Formal
:= First_Formal
(Designated_Type
(S
));
24685 Formal
:= First_Formal
(S
);
24688 while Present
(Formal
) loop
24689 Formals_To_Match
:= Formals_To_Match
+ 1;
24690 Next_Formal
(Formal
);
24693 -- Find if there is a named association, and verify that no positional
24694 -- associations appear after named ones.
24696 if Present
(Actuals
) then
24697 Actual
:= First
(Actuals
);
24700 while Present
(Actual
)
24701 and then Nkind
(Actual
) /= N_Parameter_Association
24703 Actuals_To_Match
:= Actuals_To_Match
+ 1;
24707 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
24709 -- Most common case: positional notation, no defaults
24714 elsif Actuals_To_Match
> Formals_To_Match
then
24716 -- Too many actuals: will not work
24719 if Is_Entity_Name
(Name
(N
)) then
24720 Error_Msg_N
("too many arguments in call to&", Name
(N
));
24722 Error_Msg_N
("too many arguments in call", N
);
24730 First_Named
:= Actual
;
24732 while Present
(Actual
) loop
24733 if Nkind
(Actual
) /= N_Parameter_Association
then
24735 ("positional parameters not allowed after named ones", Actual
);
24740 Actuals_To_Match
:= Actuals_To_Match
+ 1;
24746 if Present
(Actuals
) then
24747 Actual
:= First
(Actuals
);
24750 Formal
:= First_Formal
(S
);
24751 while Present
(Formal
) loop
24753 -- Match the formals in order. If the corresponding actual is
24754 -- positional, nothing to do. Else scan the list of named actuals
24755 -- to find the one with the right name.
24757 if Present
(Actual
)
24758 and then Nkind
(Actual
) /= N_Parameter_Association
24761 Actuals_To_Match
:= Actuals_To_Match
- 1;
24762 Formals_To_Match
:= Formals_To_Match
- 1;
24765 -- For named parameters, search the list of actuals to find
24766 -- one that matches the next formal name.
24768 Actual
:= First_Named
;
24770 while Present
(Actual
) loop
24771 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
24774 Actuals_To_Match
:= Actuals_To_Match
- 1;
24775 Formals_To_Match
:= Formals_To_Match
- 1;
24783 if Ekind
(Formal
) /= E_In_Parameter
24784 or else No
(Default_Value
(Formal
))
24787 if (Comes_From_Source
(S
)
24788 or else Sloc
(S
) = Standard_Location
)
24789 and then Is_Overloadable
(S
)
24793 Nkind
(Parent
(N
)) in N_Procedure_Call_Statement
24795 | N_Parameter_Association
24796 and then Ekind
(S
) /= E_Function
24798 Set_Etype
(N
, Etype
(S
));
24801 Error_Msg_Name_1
:= Chars
(S
);
24802 Error_Msg_Sloc
:= Sloc
(S
);
24804 ("missing argument for parameter & "
24805 & "in call to % declared #", N
, Formal
);
24808 elsif Is_Overloadable
(S
) then
24809 Error_Msg_Name_1
:= Chars
(S
);
24811 -- Point to type derivation that generated the
24814 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
24817 ("missing argument for parameter & "
24818 & "in call to % (inherited) #", N
, Formal
);
24822 ("missing argument for parameter &", N
, Formal
);
24830 Formals_To_Match
:= Formals_To_Match
- 1;
24835 Next_Formal
(Formal
);
24838 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
24845 -- Find some superfluous named actual that did not get
24846 -- attached to the list of associations.
24848 Actual
:= First
(Actuals
);
24849 while Present
(Actual
) loop
24850 if Nkind
(Actual
) = N_Parameter_Association
24851 and then Actual
/= Last
24852 and then No
(Next_Named_Actual
(Actual
))
24854 -- A validity check may introduce a copy of a call that
24855 -- includes an extra actual (for example for an unrelated
24856 -- accessibility check). Check that the extra actual matches
24857 -- some extra formal, which must exist already because
24858 -- subprogram must be frozen at this point.
24860 if Present
(Extra_Formals
(S
))
24861 and then not Comes_From_Source
(Actual
)
24862 and then Nkind
(Actual
) = N_Parameter_Association
24863 and then Chars
(Extra_Formals
(S
)) =
24864 Chars
(Selector_Name
(Actual
))
24869 ("unmatched actual & in call", Selector_Name
(Actual
));
24881 end Normalize_Actuals
;
24883 --------------------------------
24884 -- Note_Possible_Modification --
24885 --------------------------------
24887 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
24888 Modification_Comes_From_Source
: constant Boolean :=
24889 Comes_From_Source
(Parent
(N
));
24895 -- Loop to find referenced entity, if there is one
24901 if Is_Entity_Name
(Exp
) then
24902 Ent
:= Entity
(Exp
);
24904 -- If the entity is missing, it is an undeclared identifier,
24905 -- and there is nothing to annotate.
24911 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
24913 P
: constant Node_Id
:= Prefix
(Exp
);
24916 -- In formal verification mode, keep track of all reads and
24917 -- writes through explicit dereferences.
24919 if GNATprove_Mode
then
24920 SPARK_Specific
.Generate_Dereference
(N
, 'm');
24923 if Nkind
(P
) = N_Selected_Component
24924 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
24926 -- Case of a reference to an entry formal
24928 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
24930 elsif Nkind
(P
) = N_Identifier
24931 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
24932 and then Present
(Expression
(Parent
(Entity
(P
))))
24933 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
24936 -- Case of a reference to a value on which side effects have
24939 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
24947 elsif Nkind
(Exp
) in N_Type_Conversion | N_Unchecked_Type_Conversion
24949 Exp
:= Expression
(Exp
);
24952 elsif Nkind
(Exp
) in
24953 N_Slice | N_Indexed_Component | N_Selected_Component
24955 -- Special check, if the prefix is an access type, then return
24956 -- since we are modifying the thing pointed to, not the prefix.
24957 -- When we are expanding, most usually the prefix is replaced
24958 -- by an explicit dereference, and this test is not needed, but
24959 -- in some cases (notably -gnatc mode and generics) when we do
24960 -- not do full expansion, we need this special test.
24962 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
24965 -- Otherwise go to prefix and keep going
24968 Exp
:= Prefix
(Exp
);
24972 -- All other cases, not a modification
24978 -- Now look for entity being referenced
24980 if Present
(Ent
) then
24981 if Is_Object
(Ent
) then
24982 if Comes_From_Source
(Exp
)
24983 or else Modification_Comes_From_Source
24985 -- Give warning if pragma unmodified is given and we are
24986 -- sure this is a modification.
24988 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
24990 -- Note that the entity may be present only as a result
24991 -- of pragma Unused.
24993 if Has_Pragma_Unused
(Ent
) then
24995 ("??aspect Unused specified for &!", N
, Ent
);
24998 ("??aspect Unmodified specified for &!", N
, Ent
);
25002 Set_Never_Set_In_Source
(Ent
, False);
25005 Set_Is_True_Constant
(Ent
, False);
25006 Set_Current_Value
(Ent
, Empty
);
25007 Set_Is_Known_Null
(Ent
, False);
25009 if not Can_Never_Be_Null
(Ent
) then
25010 Set_Is_Known_Non_Null
(Ent
, False);
25013 -- Follow renaming chain
25015 if Ekind
(Ent
) in E_Variable | E_Constant
25016 and then Present
(Renamed_Object
(Ent
))
25018 Exp
:= Renamed_Object
(Ent
);
25020 -- If the entity is the loop variable in an iteration over
25021 -- a container, retrieve container expression to indicate
25022 -- possible modification.
25024 if Present
(Related_Expression
(Ent
))
25025 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
25026 N_Iterator_Specification
25028 Exp
:= Original_Node
(Related_Expression
(Ent
));
25033 -- The expression may be the renaming of a subcomponent of an
25034 -- array or container. The assignment to the subcomponent is
25035 -- a modification of the container.
25037 elsif Comes_From_Source
(Original_Node
(Exp
))
25038 and then Nkind
(Original_Node
(Exp
)) in
25039 N_Selected_Component | N_Indexed_Component
25041 Exp
:= Prefix
(Original_Node
(Exp
));
25045 -- Generate a reference only if the assignment comes from
25046 -- source. This excludes, for example, calls to a dispatching
25047 -- assignment operation when the left-hand side is tagged. In
25048 -- GNATprove mode, we need those references also on generated
25049 -- code, as these are used to compute the local effects of
25052 if Modification_Comes_From_Source
or GNATprove_Mode
then
25053 Generate_Reference
(Ent
, Exp
, 'm');
25055 -- If the target of the assignment is the bound variable
25056 -- in an iterator, indicate that the corresponding array
25057 -- or container is also modified.
25059 if Ada_Version
>= Ada_2012
25060 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
25063 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
25066 -- ??? In the full version of the construct, the
25067 -- domain of iteration can be given by an expression.
25069 if Is_Entity_Name
(Domain
) then
25070 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
25071 Set_Is_True_Constant
(Entity
(Domain
), False);
25072 Set_Never_Set_In_Source
(Entity
(Domain
), False);
25081 -- If we are sure this is a modification from source, and we know
25082 -- this modifies a constant, then give an appropriate warning.
25085 and then Modification_Comes_From_Source
25086 and then Overlays_Constant
(Ent
)
25087 and then Address_Clause_Overlay_Warnings
25090 Addr
: constant Node_Id
:= Address_Clause
(Ent
);
25095 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
25097 Error_Msg_Sloc
:= Sloc
(Addr
);
25099 ("?o?constant& may be modified via address clause#",
25110 end Note_Possible_Modification
;
25116 function Null_Status
(N
: Node_Id
) return Null_Status_Kind
is
25117 function Is_Null_Excluding_Def
(Def
: Node_Id
) return Boolean;
25118 -- Determine whether definition Def carries a null exclusion
25120 function Null_Status_Of_Entity
(Id
: Entity_Id
) return Null_Status_Kind
;
25121 -- Determine the null status of arbitrary entity Id
25123 function Null_Status_Of_Type
(Typ
: Entity_Id
) return Null_Status_Kind
;
25124 -- Determine the null status of type Typ
25126 ---------------------------
25127 -- Is_Null_Excluding_Def --
25128 ---------------------------
25130 function Is_Null_Excluding_Def
(Def
: Node_Id
) return Boolean is
25132 return Nkind
(Def
) in N_Access_Definition
25133 | N_Access_Function_Definition
25134 | N_Access_Procedure_Definition
25135 | N_Access_To_Object_Definition
25136 | N_Component_Definition
25137 | N_Derived_Type_Definition
25138 and then Null_Exclusion_Present
(Def
);
25139 end Is_Null_Excluding_Def
;
25141 ---------------------------
25142 -- Null_Status_Of_Entity --
25143 ---------------------------
25145 function Null_Status_Of_Entity
25146 (Id
: Entity_Id
) return Null_Status_Kind
25148 Decl
: constant Node_Id
:= Declaration_Node
(Id
);
25152 -- The value of an imported or exported entity may be set externally
25153 -- regardless of a null exclusion. As a result, the value cannot be
25154 -- determined statically.
25156 if Is_Imported
(Id
) or else Is_Exported
(Id
) then
25159 elsif Nkind
(Decl
) in N_Component_Declaration
25160 | N_Discriminant_Specification
25161 | N_Formal_Object_Declaration
25162 | N_Object_Declaration
25163 | N_Object_Renaming_Declaration
25164 | N_Parameter_Specification
25166 -- A component declaration yields a non-null value when either
25167 -- its component definition or access definition carries a null
25170 if Nkind
(Decl
) = N_Component_Declaration
then
25171 Def
:= Component_Definition
(Decl
);
25173 if Is_Null_Excluding_Def
(Def
) then
25174 return Is_Non_Null
;
25177 Def
:= Access_Definition
(Def
);
25179 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
25180 return Is_Non_Null
;
25183 -- A formal object declaration yields a non-null value if its
25184 -- access definition carries a null exclusion. If the object is
25185 -- default initialized, then the value depends on the expression.
25187 elsif Nkind
(Decl
) = N_Formal_Object_Declaration
then
25188 Def
:= Access_Definition
(Decl
);
25190 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
25191 return Is_Non_Null
;
25194 -- A constant may yield a null or non-null value depending on its
25195 -- initialization expression.
25197 elsif Ekind
(Id
) = E_Constant
then
25198 return Null_Status
(Constant_Value
(Id
));
25200 -- The construct yields a non-null value when it has a null
25203 elsif Null_Exclusion_Present
(Decl
) then
25204 return Is_Non_Null
;
25206 -- An object renaming declaration yields a non-null value if its
25207 -- access definition carries a null exclusion. Otherwise the value
25208 -- depends on the renamed name.
25210 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
25211 Def
:= Access_Definition
(Decl
);
25213 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
25214 return Is_Non_Null
;
25217 return Null_Status
(Name
(Decl
));
25222 -- At this point the declaration of the entity does not carry a null
25223 -- exclusion and lacks an initialization expression. Check the status
25226 return Null_Status_Of_Type
(Etype
(Id
));
25227 end Null_Status_Of_Entity
;
25229 -------------------------
25230 -- Null_Status_Of_Type --
25231 -------------------------
25233 function Null_Status_Of_Type
(Typ
: Entity_Id
) return Null_Status_Kind
is
25238 -- Traverse the type chain looking for types with null exclusion
25241 while Present
(Curr
) and then Etype
(Curr
) /= Curr
loop
25242 Decl
:= Parent
(Curr
);
25244 -- Guard against itypes which do not always have declarations. A
25245 -- type yields a non-null value if it carries a null exclusion.
25247 if Present
(Decl
) then
25248 if Nkind
(Decl
) = N_Full_Type_Declaration
25249 and then Is_Null_Excluding_Def
(Type_Definition
(Decl
))
25251 return Is_Non_Null
;
25253 elsif Nkind
(Decl
) = N_Subtype_Declaration
25254 and then Null_Exclusion_Present
(Decl
)
25256 return Is_Non_Null
;
25260 Curr
:= Etype
(Curr
);
25263 -- The type chain does not contain any null excluding types
25266 end Null_Status_Of_Type
;
25268 -- Start of processing for Null_Status
25271 -- Prevent cascaded errors or infinite loops when trying to determine
25272 -- the null status of an erroneous construct.
25274 if Error_Posted
(N
) then
25277 -- An allocator always creates a non-null value
25279 elsif Nkind
(N
) = N_Allocator
then
25280 return Is_Non_Null
;
25282 -- Taking the 'Access of something yields a non-null value
25284 elsif Nkind
(N
) = N_Attribute_Reference
25285 and then Attribute_Name
(N
) in Name_Access
25286 | Name_Unchecked_Access
25287 | Name_Unrestricted_Access
25289 return Is_Non_Null
;
25291 -- "null" yields null
25293 elsif Nkind
(N
) = N_Null
then
25296 -- Check the status of the operand of a type conversion
25298 elsif Nkind
(N
) in N_Type_Conversion | N_Unchecked_Type_Conversion
then
25299 return Null_Status
(Expression
(N
));
25301 -- The input denotes a reference to an entity. Determine whether the
25302 -- entity or its type yields a null or non-null value.
25304 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
25305 return Null_Status_Of_Entity
(Entity
(N
));
25308 -- Otherwise it is not possible to determine the null status of the
25309 -- subexpression at compile time without resorting to simple flow
25315 --------------------------------------
25316 -- Null_To_Null_Address_Convert_OK --
25317 --------------------------------------
25319 function Null_To_Null_Address_Convert_OK
25321 Typ
: Entity_Id
:= Empty
) return Boolean
25324 if not Relaxed_RM_Semantics
then
25328 if Nkind
(N
) = N_Null
then
25329 return Present
(Typ
) and then Is_Descendant_Of_Address
(Typ
);
25331 elsif Nkind
(N
) in N_Op_Compare
then
25333 L
: constant Node_Id
:= Left_Opnd
(N
);
25334 R
: constant Node_Id
:= Right_Opnd
(N
);
25337 -- We check the Etype of the complementary operand since the
25338 -- N_Null node is not decorated at this stage.
25341 ((Nkind
(L
) = N_Null
25342 and then Is_Descendant_Of_Address
(Etype
(R
)))
25344 (Nkind
(R
) = N_Null
25345 and then Is_Descendant_Of_Address
(Etype
(L
))));
25350 end Null_To_Null_Address_Convert_OK
;
25352 ---------------------------------
25353 -- Number_Of_Elements_In_Array --
25354 ---------------------------------
25356 function Number_Of_Elements_In_Array
(T
: Entity_Id
) return Int
is
25364 pragma Assert
(Is_Array_Type
(T
));
25366 Indx
:= First_Index
(T
);
25367 while Present
(Indx
) loop
25368 Typ
:= Underlying_Type
(Etype
(Indx
));
25370 -- Never look at junk bounds of a generic type
25372 if Is_Generic_Type
(Typ
) then
25376 -- Check the array bounds are known at compile time and return zero
25377 -- if they are not.
25379 Low
:= Type_Low_Bound
(Typ
);
25380 High
:= Type_High_Bound
(Typ
);
25382 if not Compile_Time_Known_Value
(Low
) then
25384 elsif not Compile_Time_Known_Value
(High
) then
25388 Num
* UI_To_Int
((Expr_Value
(High
) - Expr_Value
(Low
) + 1));
25395 end Number_Of_Elements_In_Array
;
25397 ---------------------------------
25398 -- Original_Aspect_Pragma_Name --
25399 ---------------------------------
25401 function Original_Aspect_Pragma_Name
(N
: Node_Id
) return Name_Id
is
25403 Item_Nam
: Name_Id
;
25406 pragma Assert
(Nkind
(N
) in N_Aspect_Specification | N_Pragma
);
25410 -- The pragma was generated to emulate an aspect, use the original
25411 -- aspect specification.
25413 if Nkind
(Item
) = N_Pragma
and then From_Aspect_Specification
(Item
) then
25414 Item
:= Corresponding_Aspect
(Item
);
25417 -- Retrieve the name of the aspect/pragma. As assertion pragmas from
25418 -- a generic instantiation might have been rewritten into pragma Check,
25419 -- we look at the original node for Item. Note also that Pre, Pre_Class,
25420 -- Post and Post_Class rewrite their pragma identifier to preserve the
25421 -- original name, so we look at the original node for the identifier.
25422 -- ??? this is kludgey
25424 if Nkind
(Item
) = N_Pragma
then
25426 Chars
(Original_Node
(Pragma_Identifier
(Original_Node
(Item
))));
25428 if Item_Nam
= Name_Check
then
25429 -- Pragma "Check" preserves the original pragma name as its first
25432 Chars
(Expression
(First
(Pragma_Argument_Associations
25433 (Original_Node
(Item
)))));
25437 pragma Assert
(Nkind
(Item
) = N_Aspect_Specification
);
25438 Item_Nam
:= Chars
(Identifier
(Item
));
25441 -- Deal with 'Class by converting the name to its _XXX form
25443 if Class_Present
(Item
) then
25444 if Item_Nam
= Name_Invariant
then
25445 Item_Nam
:= Name_uInvariant
;
25447 elsif Item_Nam
= Name_Post
then
25448 Item_Nam
:= Name_uPost
;
25450 elsif Item_Nam
= Name_Pre
then
25451 Item_Nam
:= Name_uPre
;
25453 elsif Item_Nam
in Name_Type_Invariant | Name_Type_Invariant_Class
25455 Item_Nam
:= Name_uType_Invariant
;
25457 -- Nothing to do for other cases (e.g. a Check that derived from
25458 -- Pre_Class and has the flag set). Also we do nothing if the name
25459 -- is already in special _xxx form.
25465 end Original_Aspect_Pragma_Name
;
25467 --------------------------------------
25468 -- Original_Corresponding_Operation --
25469 --------------------------------------
25471 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
25473 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
25476 -- If S is an inherited primitive S2 the original corresponding
25477 -- operation of S is the original corresponding operation of S2
25479 if Present
(Alias
(S
))
25480 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
25482 return Original_Corresponding_Operation
(Alias
(S
));
25484 -- If S overrides an inherited subprogram S2 the original corresponding
25485 -- operation of S is the original corresponding operation of S2
25487 elsif Present
(Overridden_Operation
(S
)) then
25488 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
25490 -- otherwise it is S itself
25495 end Original_Corresponding_Operation
;
25497 -----------------------------------
25498 -- Original_View_In_Visible_Part --
25499 -----------------------------------
25501 function Original_View_In_Visible_Part
25502 (Typ
: Entity_Id
) return Boolean
25504 Scop
: constant Entity_Id
:= Scope
(Typ
);
25507 -- The scope must be a package
25509 if not Is_Package_Or_Generic_Package
(Scop
) then
25513 -- A type with a private declaration has a private view declared in
25514 -- the visible part.
25516 if Has_Private_Declaration
(Typ
) then
25520 return List_Containing
(Parent
(Typ
)) =
25521 Visible_Declarations
(Package_Specification
(Scop
));
25522 end Original_View_In_Visible_Part
;
25524 -------------------
25525 -- Output_Entity --
25526 -------------------
25528 procedure Output_Entity
(Id
: Entity_Id
) is
25532 Scop
:= Scope
(Id
);
25534 -- The entity may lack a scope when it is in the process of being
25535 -- analyzed. Use the current scope as an approximation.
25538 Scop
:= Current_Scope
;
25541 Output_Name
(Chars
(Id
), Scop
);
25548 procedure Output_Name
(Nam
: Name_Id
; Scop
: Entity_Id
:= Current_Scope
) is
25552 (Get_Qualified_Name
25563 -- This would be trivial, simply a test for an identifier that was a
25564 -- reference to a formal, if it were not for the fact that a previous call
25565 -- to Expand_Entry_Parameter will have modified the reference to the
25566 -- identifier. A formal of a protected entity is rewritten as
25568 -- typ!(recobj).rec.all'Constrained
25570 -- where rec is a selector whose Entry_Formal link points to the formal
25572 -- If the type of the entry parameter has a representation clause, then an
25573 -- extra temp is involved (see below).
25575 -- For a formal of a task entity, the formal is rewritten as a local
25578 -- In addition, a formal that is marked volatile because it is aliased
25579 -- through an address clause is rewritten as dereference as well.
25581 function Param_Entity
(N
: Node_Id
) return Entity_Id
is
25582 Renamed_Obj
: Node_Id
;
25585 -- Simple reference case
25587 if Nkind
(N
) in N_Identifier | N_Expanded_Name
then
25588 if Is_Formal
(Entity
(N
)) then
25591 -- Handle renamings of formal parameters and formals of tasks that
25592 -- are rewritten as renamings.
25594 elsif Nkind
(Parent
(Entity
(N
))) = N_Object_Renaming_Declaration
then
25595 Renamed_Obj
:= Get_Referenced_Object
(Renamed_Object
(Entity
(N
)));
25597 if Is_Entity_Name
(Renamed_Obj
)
25598 and then Is_Formal
(Entity
(Renamed_Obj
))
25600 return Entity
(Renamed_Obj
);
25603 Nkind
(Parent
(Parent
(Entity
(N
)))) = N_Accept_Statement
25610 if Nkind
(N
) = N_Explicit_Dereference
then
25612 P
: Node_Id
:= Prefix
(N
);
25618 -- If the type of an entry parameter has a representation
25619 -- clause, then the prefix is not a selected component, but
25620 -- instead a reference to a temp pointing at the selected
25621 -- component. In this case, set P to be the initial value of
25624 if Nkind
(P
) = N_Identifier
then
25627 if Ekind
(E
) = E_Constant
then
25628 Decl
:= Parent
(E
);
25630 if Nkind
(Decl
) = N_Object_Declaration
then
25631 P
:= Expression
(Decl
);
25636 if Nkind
(P
) = N_Selected_Component
then
25637 S
:= Selector_Name
(P
);
25639 if Present
(Entry_Formal
(Entity
(S
))) then
25640 return Entry_Formal
(Entity
(S
));
25643 elsif Nkind
(Original_Node
(N
)) = N_Identifier
then
25644 return Param_Entity
(Original_Node
(N
));
25653 ----------------------
25654 -- Policy_In_Effect --
25655 ----------------------
25657 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
25658 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
25659 -- Determine the mode of a policy in a N_Pragma list
25661 --------------------
25662 -- Policy_In_List --
25663 --------------------
25665 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
25672 while Present
(Prag
) loop
25673 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
25674 Arg2
:= Next
(Arg1
);
25676 Arg1
:= Get_Pragma_Arg
(Arg1
);
25677 Arg2
:= Get_Pragma_Arg
(Arg2
);
25679 -- The current Check_Policy pragma matches the requested policy or
25680 -- appears in the single argument form (Assertion, policy_id).
25682 if Chars
(Arg1
) in Name_Assertion | Policy
then
25683 return Chars
(Arg2
);
25686 Prag
:= Next_Pragma
(Prag
);
25690 end Policy_In_List
;
25696 -- Start of processing for Policy_In_Effect
25699 if not Is_Valid_Assertion_Kind
(Policy
) then
25700 raise Program_Error
;
25703 -- Inspect all policy pragmas that appear within scopes (if any)
25705 Kind
:= Policy_In_List
(Check_Policy_List
);
25707 -- Inspect all configuration policy pragmas (if any)
25709 if Kind
= No_Name
then
25710 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
25713 -- The context lacks policy pragmas, determine the mode based on whether
25714 -- assertions are enabled at the configuration level. This ensures that
25715 -- the policy is preserved when analyzing generics.
25717 if Kind
= No_Name
then
25718 if Assertions_Enabled_Config
then
25719 Kind
:= Name_Check
;
25721 Kind
:= Name_Ignore
;
25725 -- In CodePeer mode and GNATprove mode, we need to consider all
25726 -- assertions, unless they are disabled. Force Name_Check on
25727 -- ignored assertions.
25729 if Kind
in Name_Ignore | Name_Off
25730 and then (CodePeer_Mode
or GNATprove_Mode
)
25732 Kind
:= Name_Check
;
25736 end Policy_In_Effect
;
25738 -------------------------------
25739 -- Preanalyze_Without_Errors --
25740 -------------------------------
25742 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
25743 Status
: constant Boolean := Get_Ignore_Errors
;
25745 Set_Ignore_Errors
(True);
25747 Set_Ignore_Errors
(Status
);
25748 end Preanalyze_Without_Errors
;
25750 -----------------------
25751 -- Predicate_Enabled --
25752 -----------------------
25754 function Predicate_Enabled
(Typ
: Entity_Id
) return Boolean is
25756 return Present
(Predicate_Function
(Typ
))
25757 and then not Predicates_Ignored
(Typ
)
25758 and then not Predicate_Checks_Suppressed
(Empty
);
25759 end Predicate_Enabled
;
25761 ----------------------------------
25762 -- Predicate_Failure_Expression --
25763 ----------------------------------
25765 function Predicate_Failure_Expression
25766 (Typ
: Entity_Id
; Inherited_OK
: Boolean) return Node_Id
25768 PF_Aspect
: constant Node_Id
:=
25769 Find_Aspect
(Typ
, Aspect_Predicate_Failure
);
25771 -- Check for Predicate_Failure aspect specification via an
25772 -- aspect_specification (as opposed to via a pragma).
25774 if Present
(PF_Aspect
) then
25775 if Inherited_OK
or else Entity
(PF_Aspect
) = Typ
then
25776 return Expression
(PF_Aspect
);
25782 -- Check for Predicate_Failure aspect specification via a pragma.
25785 Rep_Item
: Node_Id
:= First_Rep_Item
(Typ
);
25787 while Present
(Rep_Item
) loop
25788 if Nkind
(Rep_Item
) = N_Pragma
25789 and then Get_Pragma_Id
(Rep_Item
) = Pragma_Predicate_Failure
25792 Arg1
: constant Node_Id
:=
25794 (First
(Pragma_Argument_Associations
(Rep_Item
)));
25795 Arg2
: constant Node_Id
:=
25797 (Next
(First
(Pragma_Argument_Associations
(Rep_Item
))));
25799 if Inherited_OK
or else
25800 (Nkind
(Arg1
) in N_Has_Entity
25801 and then Entity
(Arg1
) = Typ
)
25808 Next_Rep_Item
(Rep_Item
);
25812 -- If we are interested in an inherited Predicate_Failure aspect
25813 -- and we have an ancestor to inherit from, then recursively check
25816 if Inherited_OK
and then Present
(Nearest_Ancestor
(Typ
)) then
25817 return Predicate_Failure_Expression
(Nearest_Ancestor
(Typ
),
25818 Inherited_OK
=> True);
25822 end Predicate_Failure_Expression
;
25824 ----------------------------------
25825 -- Predicate_Tests_On_Arguments --
25826 ----------------------------------
25828 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
25830 -- Always test predicates on indirect call
25832 if Ekind
(Subp
) = E_Subprogram_Type
then
25835 -- Do not test predicates on call to generated default Finalize, since
25836 -- we are not interested in whether something we are finalizing (and
25837 -- typically destroying) satisfies its predicates.
25839 elsif Chars
(Subp
) = Name_Finalize
25840 and then not Comes_From_Source
(Subp
)
25844 -- Do not test predicates on any internally generated routines
25846 elsif Is_Internal_Name
(Chars
(Subp
)) then
25849 -- Do not test predicates on call to Init_Proc, since if needed the
25850 -- predicate test will occur at some other point.
25852 elsif Is_Init_Proc
(Subp
) then
25855 -- Do not test predicates on call to predicate function, since this
25856 -- would cause infinite recursion.
25858 elsif Ekind
(Subp
) = E_Function
25859 and then Is_Predicate_Function
(Subp
)
25863 -- For now, no other exceptions
25868 end Predicate_Tests_On_Arguments
;
25870 -----------------------
25871 -- Private_Component --
25872 -----------------------
25874 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
25875 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
25877 function Trace_Components
25879 Check
: Boolean) return Entity_Id
;
25880 -- Recursive function that does the work, and checks against circular
25881 -- definition for each subcomponent type.
25883 ----------------------
25884 -- Trace_Components --
25885 ----------------------
25887 function Trace_Components
25889 Check
: Boolean) return Entity_Id
25891 Btype
: constant Entity_Id
:= Base_Type
(T
);
25892 Component
: Entity_Id
;
25894 Candidate
: Entity_Id
:= Empty
;
25897 if Check
and then Btype
= Ancestor
then
25898 Error_Msg_N
("circular type definition", Type_Id
);
25902 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
25903 if Present
(Full_View
(Btype
))
25904 and then Is_Record_Type
(Full_View
(Btype
))
25905 and then not Is_Frozen
(Btype
)
25907 -- To indicate that the ancestor depends on a private type, the
25908 -- current Btype is sufficient. However, to check for circular
25909 -- definition we must recurse on the full view.
25911 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
25913 if Candidate
= Any_Type
then
25923 elsif Is_Array_Type
(Btype
) then
25924 return Trace_Components
(Component_Type
(Btype
), True);
25926 elsif Is_Record_Type
(Btype
) then
25927 Component
:= First_Entity
(Btype
);
25928 while Present
(Component
)
25929 and then Comes_From_Source
(Component
)
25931 -- Skip anonymous types generated by constrained components
25933 if not Is_Type
(Component
) then
25934 P
:= Trace_Components
(Etype
(Component
), True);
25936 if Present
(P
) then
25937 if P
= Any_Type
then
25945 Next_Entity
(Component
);
25953 end Trace_Components
;
25955 -- Start of processing for Private_Component
25958 return Trace_Components
(Type_Id
, False);
25959 end Private_Component
;
25961 ---------------------------
25962 -- Primitive_Names_Match --
25963 ---------------------------
25965 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
25966 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
25967 -- Given an internal name, returns the corresponding non-internal name
25969 ------------------------
25970 -- Non_Internal_Name --
25971 ------------------------
25973 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
25975 Get_Name_String
(Chars
(E
));
25976 Name_Len
:= Name_Len
- 1;
25978 end Non_Internal_Name
;
25980 -- Start of processing for Primitive_Names_Match
25983 pragma Assert
(Present
(E1
) and then Present
(E2
));
25985 return Chars
(E1
) = Chars
(E2
)
25987 (not Is_Internal_Name
(Chars
(E1
))
25988 and then Is_Internal_Name
(Chars
(E2
))
25989 and then Non_Internal_Name
(E2
) = Chars
(E1
))
25991 (not Is_Internal_Name
(Chars
(E2
))
25992 and then Is_Internal_Name
(Chars
(E1
))
25993 and then Non_Internal_Name
(E1
) = Chars
(E2
))
25995 (Is_Predefined_Dispatching_Operation
(E1
)
25996 and then Is_Predefined_Dispatching_Operation
(E2
)
25997 and then Same_TSS
(E1
, E2
))
25999 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
26000 end Primitive_Names_Match
;
26002 -----------------------
26003 -- Process_End_Label --
26004 -----------------------
26006 procedure Process_End_Label
26015 Label_Ref
: Boolean;
26016 -- Set True if reference to end label itself is required
26019 -- Gets set to the operator symbol or identifier that references the
26020 -- entity Ent. For the child unit case, this is the identifier from the
26021 -- designator. For other cases, this is simply Endl.
26023 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
26024 -- N is an identifier node that appears as a parent unit reference in
26025 -- the case where Ent is a child unit. This procedure generates an
26026 -- appropriate cross-reference entry. E is the corresponding entity.
26028 -------------------------
26029 -- Generate_Parent_Ref --
26030 -------------------------
26032 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
26034 -- If names do not match, something weird, skip reference
26036 if Chars
(E
) = Chars
(N
) then
26038 -- Generate the reference. We do NOT consider this as a reference
26039 -- for unreferenced symbol purposes.
26041 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
26043 if Style_Check
then
26044 Style
.Check_Identifier
(N
, E
);
26047 end Generate_Parent_Ref
;
26049 -- Start of processing for Process_End_Label
26052 -- If no node, ignore. This happens in some error situations, and
26053 -- also for some internally generated structures where no end label
26054 -- references are required in any case.
26060 -- Nothing to do if no End_Label, happens for internally generated
26061 -- constructs where we don't want an end label reference anyway. Also
26062 -- nothing to do if Endl is a string literal, which means there was
26063 -- some prior error (bad operator symbol)
26065 Endl
:= End_Label
(N
);
26067 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
26071 -- Reference node is not in extended main source unit
26073 if not In_Extended_Main_Source_Unit
(N
) then
26075 -- Generally we do not collect references except for the extended
26076 -- main source unit. The one exception is the 'e' entry for a
26077 -- package spec, where it is useful for a client to have the
26078 -- ending information to define scopes.
26084 Label_Ref
:= False;
26086 -- For this case, we can ignore any parent references, but we
26087 -- need the package name itself for the 'e' entry.
26089 if Nkind
(Endl
) = N_Designator
then
26090 Endl
:= Identifier
(Endl
);
26094 -- Reference is in extended main source unit
26099 -- For designator, generate references for the parent entries
26101 if Nkind
(Endl
) = N_Designator
then
26103 -- Generate references for the prefix if the END line comes from
26104 -- source (otherwise we do not need these references) We climb the
26105 -- scope stack to find the expected entities.
26107 if Comes_From_Source
(Endl
) then
26108 Nam
:= Name
(Endl
);
26109 Scop
:= Current_Scope
;
26110 while Nkind
(Nam
) = N_Selected_Component
loop
26111 Scop
:= Scope
(Scop
);
26112 exit when No
(Scop
);
26113 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
26114 Nam
:= Prefix
(Nam
);
26117 if Present
(Scop
) then
26118 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
26122 Endl
:= Identifier
(Endl
);
26126 -- If the end label is not for the given entity, then either we have
26127 -- some previous error, or this is a generic instantiation for which
26128 -- we do not need to make a cross-reference in this case anyway. In
26129 -- either case we simply ignore the call.
26131 if Chars
(Ent
) /= Chars
(Endl
) then
26135 -- If label was really there, then generate a normal reference and then
26136 -- adjust the location in the end label to point past the name (which
26137 -- should almost always be the semicolon).
26139 Loc
:= Sloc
(Endl
);
26141 if Comes_From_Source
(Endl
) then
26143 -- If a label reference is required, then do the style check and
26144 -- generate an l-type cross-reference entry for the label
26147 if Style_Check
then
26148 Style
.Check_Identifier
(Endl
, Ent
);
26151 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
26154 -- Set the location to point past the label (normally this will
26155 -- mean the semicolon immediately following the label). This is
26156 -- done for the sake of the 'e' or 't' entry generated below.
26158 Get_Decoded_Name_String
(Chars
(Endl
));
26159 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
26162 -- Now generate the e/t reference
26164 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
26166 -- Restore Sloc, in case modified above, since we have an identifier
26167 -- and the normal Sloc should be left set in the tree.
26169 Set_Sloc
(Endl
, Loc
);
26170 end Process_End_Label
;
26172 --------------------------------
26173 -- Propagate_Concurrent_Flags --
26174 --------------------------------
26176 procedure Propagate_Concurrent_Flags
26178 Comp_Typ
: Entity_Id
)
26181 if Has_Task
(Comp_Typ
) then
26182 Set_Has_Task
(Typ
);
26185 if Has_Protected
(Comp_Typ
) then
26186 Set_Has_Protected
(Typ
);
26189 if Has_Timing_Event
(Comp_Typ
) then
26190 Set_Has_Timing_Event
(Typ
);
26192 end Propagate_Concurrent_Flags
;
26194 ------------------------------
26195 -- Propagate_DIC_Attributes --
26196 ------------------------------
26198 procedure Propagate_DIC_Attributes
26200 From_Typ
: Entity_Id
)
26202 DIC_Proc
: Entity_Id
;
26203 Partial_DIC_Proc
: Entity_Id
;
26206 if Present
(Typ
) and then Present
(From_Typ
) then
26207 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
26209 -- Nothing to do if both the source and the destination denote the
26212 if From_Typ
= Typ
then
26215 -- Nothing to do when the destination denotes an incomplete type
26216 -- because the DIC is associated with the current instance of a
26217 -- private type, thus it can never apply to an incomplete type.
26219 elsif Is_Incomplete_Type
(Typ
) then
26223 DIC_Proc
:= DIC_Procedure
(From_Typ
);
26224 Partial_DIC_Proc
:= Partial_DIC_Procedure
(From_Typ
);
26226 -- The setting of the attributes is intentionally conservative. This
26227 -- prevents accidental clobbering of enabled attributes. We need to
26228 -- call Base_Type twice, because it is sometimes not set to an actual
26231 if Has_Inherited_DIC
(From_Typ
) then
26232 Set_Has_Inherited_DIC
(Base_Type
(Base_Type
(Typ
)));
26235 if Has_Own_DIC
(From_Typ
) then
26236 Set_Has_Own_DIC
(Base_Type
(Base_Type
(Typ
)));
26239 if Present
(DIC_Proc
) and then No
(DIC_Procedure
(Typ
)) then
26240 Set_DIC_Procedure
(Typ
, DIC_Proc
);
26243 if Present
(Partial_DIC_Proc
)
26244 and then No
(Partial_DIC_Procedure
(Typ
))
26246 Set_Partial_DIC_Procedure
(Typ
, Partial_DIC_Proc
);
26249 end Propagate_DIC_Attributes
;
26251 ------------------------------------
26252 -- Propagate_Invariant_Attributes --
26253 ------------------------------------
26255 procedure Propagate_Invariant_Attributes
26257 From_Typ
: Entity_Id
)
26259 Full_IP
: Entity_Id
;
26260 Part_IP
: Entity_Id
;
26263 if Present
(Typ
) and then Present
(From_Typ
) then
26264 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
26266 -- Nothing to do if both the source and the destination denote the
26269 if From_Typ
= Typ
then
26273 Full_IP
:= Invariant_Procedure
(From_Typ
);
26274 Part_IP
:= Partial_Invariant_Procedure
(From_Typ
);
26276 -- The setting of the attributes is intentionally conservative. This
26277 -- prevents accidental clobbering of enabled attributes. We need to
26278 -- call Base_Type twice, because it is sometimes not set to an actual
26281 if Has_Inheritable_Invariants
(From_Typ
) then
26282 Set_Has_Inheritable_Invariants
(Base_Type
(Base_Type
(Typ
)));
26285 if Has_Inherited_Invariants
(From_Typ
) then
26286 Set_Has_Inherited_Invariants
(Base_Type
(Base_Type
(Typ
)));
26289 if Has_Own_Invariants
(From_Typ
) then
26290 Set_Has_Own_Invariants
(Base_Type
(Base_Type
(Typ
)));
26293 if Present
(Full_IP
) and then No
(Invariant_Procedure
(Typ
)) then
26294 Set_Invariant_Procedure
(Typ
, Full_IP
);
26297 if Present
(Part_IP
) and then No
(Partial_Invariant_Procedure
(Typ
))
26299 Set_Partial_Invariant_Procedure
(Typ
, Part_IP
);
26302 end Propagate_Invariant_Attributes
;
26304 ------------------------------------
26305 -- Propagate_Predicate_Attributes --
26306 ------------------------------------
26308 procedure Propagate_Predicate_Attributes
26310 From_Typ
: Entity_Id
)
26312 Pred_Func
: Entity_Id
;
26314 if Present
(Typ
) and then Present
(From_Typ
) then
26315 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
26317 -- Nothing to do if both the source and the destination denote the
26320 if From_Typ
= Typ
then
26324 Pred_Func
:= Predicate_Function
(From_Typ
);
26326 -- The setting of the attributes is intentionally conservative. This
26327 -- prevents accidental clobbering of enabled attributes.
26329 if Has_Predicates
(From_Typ
) then
26330 Set_Has_Predicates
(Typ
);
26333 if Present
(Pred_Func
) and then No
(Predicate_Function
(Typ
)) then
26334 Set_Predicate_Function
(Typ
, Pred_Func
);
26337 end Propagate_Predicate_Attributes
;
26339 ---------------------------------------
26340 -- Record_Possible_Part_Of_Reference --
26341 ---------------------------------------
26343 procedure Record_Possible_Part_Of_Reference
26344 (Var_Id
: Entity_Id
;
26347 Encap
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
26351 -- The variable is a constituent of a single protected/task type. Such
26352 -- a variable acts as a component of the type and must appear within a
26353 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
26354 -- verify its legality now.
26356 if Present
(Encap
) and then Is_Single_Concurrent_Object
(Encap
) then
26357 Check_Part_Of_Reference
(Var_Id
, Ref
);
26359 -- The variable is subject to pragma Part_Of and may eventually become a
26360 -- constituent of a single protected/task type. Record the reference to
26361 -- verify its placement when the contract of the variable is analyzed.
26363 elsif Present
(Get_Pragma
(Var_Id
, Pragma_Part_Of
)) then
26364 Refs
:= Part_Of_References
(Var_Id
);
26367 Refs
:= New_Elmt_List
;
26368 Set_Part_Of_References
(Var_Id
, Refs
);
26371 Append_Elmt
(Ref
, Refs
);
26373 end Record_Possible_Part_Of_Reference
;
26379 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
26380 Seen
: Boolean := False;
26382 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
26383 -- Determine whether node N denotes a reference to Id. If this is the
26384 -- case, set global flag Seen to True and stop the traversal.
26390 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
26392 if Is_Entity_Name
(N
)
26393 and then Present
(Entity
(N
))
26394 and then Entity
(N
) = Id
26403 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
26405 -- Start of processing for Referenced
26408 Inspect_Expression
(Expr
);
26412 ------------------------------------
26413 -- References_Generic_Formal_Type --
26414 ------------------------------------
26416 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
26418 function Process
(N
: Node_Id
) return Traverse_Result
;
26419 -- Process one node in search for generic formal type
26425 function Process
(N
: Node_Id
) return Traverse_Result
is
26427 if Nkind
(N
) in N_Has_Entity
then
26429 E
: constant Entity_Id
:= Entity
(N
);
26431 if Present
(E
) then
26432 if Is_Generic_Type
(E
) then
26434 elsif Present
(Etype
(E
))
26435 and then Is_Generic_Type
(Etype
(E
))
26446 function Traverse
is new Traverse_Func
(Process
);
26447 -- Traverse tree to look for generic type
26450 if Inside_A_Generic
then
26451 return Traverse
(N
) = Abandon
;
26455 end References_Generic_Formal_Type
;
26457 -------------------------------
26458 -- Remove_Entity_And_Homonym --
26459 -------------------------------
26461 procedure Remove_Entity_And_Homonym
(Id
: Entity_Id
) is
26463 Remove_Entity
(Id
);
26464 Remove_Homonym
(Id
);
26465 end Remove_Entity_And_Homonym
;
26467 --------------------
26468 -- Remove_Homonym --
26469 --------------------
26471 procedure Remove_Homonym
(Id
: Entity_Id
) is
26473 Prev
: Entity_Id
:= Empty
;
26476 if Id
= Current_Entity
(Id
) then
26477 if Present
(Homonym
(Id
)) then
26478 Set_Current_Entity
(Homonym
(Id
));
26480 Set_Name_Entity_Id
(Chars
(Id
), Empty
);
26484 Hom
:= Current_Entity
(Id
);
26485 while Present
(Hom
) and then Hom
/= Id
loop
26487 Hom
:= Homonym
(Hom
);
26490 -- If Id is not on the homonym chain, nothing to do
26492 if Present
(Hom
) then
26493 Set_Homonym
(Prev
, Homonym
(Id
));
26496 end Remove_Homonym
;
26498 ------------------------------
26499 -- Remove_Overloaded_Entity --
26500 ------------------------------
26502 procedure Remove_Overloaded_Entity
(Id
: Entity_Id
) is
26503 procedure Remove_Primitive_Of
(Typ
: Entity_Id
);
26504 -- Remove primitive subprogram Id from the list of primitives that
26505 -- belong to type Typ.
26507 -------------------------
26508 -- Remove_Primitive_Of --
26509 -------------------------
26511 procedure Remove_Primitive_Of
(Typ
: Entity_Id
) is
26515 if Is_Tagged_Type
(Typ
) then
26516 Prims
:= Direct_Primitive_Operations
(Typ
);
26518 if Present
(Prims
) then
26519 Remove
(Prims
, Id
);
26522 end Remove_Primitive_Of
;
26526 Formal
: Entity_Id
;
26528 -- Start of processing for Remove_Overloaded_Entity
26531 Remove_Entity_And_Homonym
(Id
);
26533 -- The entity denotes a primitive subprogram. Remove it from the list of
26534 -- primitives of the associated controlling type.
26536 if Ekind
(Id
) in E_Function | E_Procedure
and then Is_Primitive
(Id
) then
26537 Formal
:= First_Formal
(Id
);
26538 while Present
(Formal
) loop
26539 if Is_Controlling_Formal
(Formal
) then
26540 Remove_Primitive_Of
(Etype
(Formal
));
26544 Next_Formal
(Formal
);
26547 if Ekind
(Id
) = E_Function
and then Has_Controlling_Result
(Id
) then
26548 Remove_Primitive_Of
(Etype
(Id
));
26551 end Remove_Overloaded_Entity
;
26553 ---------------------
26554 -- Rep_To_Pos_Flag --
26555 ---------------------
26557 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
26559 return New_Occurrence_Of
26560 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
26561 end Rep_To_Pos_Flag
;
26563 --------------------
26564 -- Require_Entity --
26565 --------------------
26567 procedure Require_Entity
(N
: Node_Id
) is
26569 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
26570 if Total_Errors_Detected
/= 0 then
26571 Set_Entity
(N
, Any_Id
);
26573 raise Program_Error
;
26576 end Require_Entity
;
26578 ------------------------------
26579 -- Requires_Transient_Scope --
26580 ------------------------------
26582 function Requires_Transient_Scope
(Typ
: Entity_Id
) return Boolean is
26584 return Needs_Secondary_Stack
(Typ
) or else Needs_Finalization
(Typ
);
26585 end Requires_Transient_Scope
;
26587 --------------------------
26588 -- Reset_Analyzed_Flags --
26589 --------------------------
26591 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
26592 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
26593 -- Function used to reset Analyzed flags in tree. Note that we do
26594 -- not reset Analyzed flags in entities, since there is no need to
26595 -- reanalyze entities, and indeed, it is wrong to do so, since it
26596 -- can result in generating auxiliary stuff more than once.
26598 --------------------
26599 -- Clear_Analyzed --
26600 --------------------
26602 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
26604 if Nkind
(N
) not in N_Entity
then
26605 Set_Analyzed
(N
, False);
26609 end Clear_Analyzed
;
26611 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
26613 -- Start of processing for Reset_Analyzed_Flags
26616 Reset_Analyzed
(N
);
26617 end Reset_Analyzed_Flags
;
26619 ------------------------
26620 -- Restore_SPARK_Mode --
26621 ------------------------
26623 procedure Restore_SPARK_Mode
26624 (Mode
: SPARK_Mode_Type
;
26628 SPARK_Mode
:= Mode
;
26629 SPARK_Mode_Pragma
:= Prag
;
26630 end Restore_SPARK_Mode
;
26632 --------------------------------
26633 -- Returns_Unconstrained_Type --
26634 --------------------------------
26636 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
26638 return Ekind
(Subp
) = E_Function
26639 and then not Is_Scalar_Type
(Etype
(Subp
))
26640 and then not Is_Access_Type
(Etype
(Subp
))
26641 and then not Is_Constrained
(Etype
(Subp
));
26642 end Returns_Unconstrained_Type
;
26644 ----------------------------
26645 -- Root_Type_Of_Full_View --
26646 ----------------------------
26648 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
26649 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
26652 -- The root type of the full view may itself be a private type. Keep
26653 -- looking for the ultimate derivation parent.
26655 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
26656 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
26660 end Root_Type_Of_Full_View
;
26662 ---------------------------
26663 -- Safe_To_Capture_Value --
26664 ---------------------------
26666 function Safe_To_Capture_Value
26669 Cond
: Boolean := False) return Boolean
26672 -- The only entities for which we track constant values are variables
26673 -- that are not renamings, constants and formal parameters, so check
26674 -- if we have this case.
26676 -- Note: it may seem odd to track constant values for constants, but in
26677 -- fact this routine is used for other purposes than simply capturing
26678 -- the value. In particular, the setting of Known[_Non]_Null and
26681 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
26683 Ekind
(Ent
) = E_Constant
26689 -- For conditionals, we also allow loop parameters
26691 elsif Cond
and then Ekind
(Ent
) = E_Loop_Parameter
then
26694 -- For all other cases, not just unsafe, but impossible to capture
26695 -- Current_Value, since the above are the only entities which have
26696 -- Current_Value fields.
26702 -- Skip if volatile or aliased, since funny things might be going on in
26703 -- these cases which we cannot necessarily track. Also skip any variable
26704 -- for which an address clause is given, or whose address is taken. Also
26705 -- never capture value of library level variables (an attempt to do so
26706 -- can occur in the case of package elaboration code).
26708 if Treat_As_Volatile
(Ent
)
26709 or else Is_Aliased
(Ent
)
26710 or else Present
(Address_Clause
(Ent
))
26711 or else Address_Taken
(Ent
)
26712 or else (Is_Library_Level_Entity
(Ent
)
26713 and then Ekind
(Ent
) = E_Variable
)
26718 -- OK, all above conditions are met. We also require that the scope of
26719 -- the reference be the same as the scope of the entity, not counting
26720 -- packages and blocks and loops.
26723 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
26724 R_Scope
: Entity_Id
;
26727 R_Scope
:= Current_Scope
;
26728 while R_Scope
/= Standard_Standard
loop
26729 exit when R_Scope
= E_Scope
;
26731 if Ekind
(R_Scope
) not in E_Package | E_Block | E_Loop
then
26734 R_Scope
:= Scope
(R_Scope
);
26739 -- We also require that the reference does not appear in a context
26740 -- where it is not sure to be executed (i.e. a conditional context
26741 -- or an exception handler). We skip this if Cond is True, since the
26742 -- capturing of values from conditional tests handles this ok.
26744 if Cond
or else No
(N
) then
26755 -- Seems dubious that case expressions are not handled here ???
26758 while Present
(P
) loop
26759 if Is_Body
(P
) then
26762 elsif Nkind
(P
) = N_If_Statement
26763 or else Nkind
(P
) = N_Case_Statement
26764 or else (Nkind
(P
) in N_Short_Circuit
26765 and then Desc
= Right_Opnd
(P
))
26766 or else (Nkind
(P
) = N_If_Expression
26767 and then Desc
/= First
(Expressions
(P
)))
26768 or else Nkind
(P
) = N_Exception_Handler
26769 or else Nkind
(P
) = N_Selective_Accept
26770 or else Nkind
(P
) = N_Conditional_Entry_Call
26771 or else Nkind
(P
) = N_Timed_Entry_Call
26772 or else Nkind
(P
) = N_Asynchronous_Select
26780 -- A special Ada 2012 case: the original node may be part
26781 -- of the else_actions of a conditional expression, in which
26782 -- case it might not have been expanded yet, and appears in
26783 -- a non-syntactic list of actions. In that case it is clearly
26784 -- not safe to save a value.
26787 and then Is_List_Member
(Desc
)
26788 and then No
(Parent
(List_Containing
(Desc
)))
26796 -- OK, looks safe to set value
26799 end Safe_To_Capture_Value
;
26805 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
26806 K1
: constant Node_Kind
:= Nkind
(N1
);
26807 K2
: constant Node_Kind
:= Nkind
(N2
);
26810 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
26811 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
26813 return Chars
(N1
) = Chars
(N2
);
26815 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
26816 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
26818 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
26819 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
26830 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
26831 N1
: constant Node_Id
:= Original_Node
(Node1
);
26832 N2
: constant Node_Id
:= Original_Node
(Node2
);
26833 -- We do the tests on original nodes, since we are most interested
26834 -- in the original source, not any expansion that got in the way.
26836 K1
: constant Node_Kind
:= Nkind
(N1
);
26837 K2
: constant Node_Kind
:= Nkind
(N2
);
26840 -- First case, both are entities with same entity
26842 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
26844 EN1
: constant Entity_Id
:= Entity
(N1
);
26845 EN2
: constant Entity_Id
:= Entity
(N2
);
26847 if Present
(EN1
) and then Present
(EN2
)
26848 and then (Ekind
(EN1
) in E_Variable | E_Constant
26849 or else Is_Formal
(EN1
))
26857 -- Second case, selected component with same selector, same record
26859 if K1
= N_Selected_Component
26860 and then K2
= N_Selected_Component
26861 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
26863 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
26865 -- Third case, indexed component with same subscripts, same array
26867 elsif K1
= N_Indexed_Component
26868 and then K2
= N_Indexed_Component
26869 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
26874 E1
:= First
(Expressions
(N1
));
26875 E2
:= First
(Expressions
(N2
));
26876 while Present
(E1
) loop
26877 if not Same_Value
(E1
, E2
) then
26888 -- Fourth case, slice of same array with same bounds
26891 and then K2
= N_Slice
26892 and then Nkind
(Discrete_Range
(N1
)) = N_Range
26893 and then Nkind
(Discrete_Range
(N2
)) = N_Range
26894 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
26895 Low_Bound
(Discrete_Range
(N2
)))
26896 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
26897 High_Bound
(Discrete_Range
(N2
)))
26899 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
26901 -- All other cases, not clearly the same object
26908 ---------------------------------
26909 -- Same_Or_Aliased_Subprograms --
26910 ---------------------------------
26912 function Same_Or_Aliased_Subprograms
26914 E
: Entity_Id
) return Boolean
26916 Subp_Alias
: constant Entity_Id
:= Alias
(S
);
26917 Subp
: Entity_Id
:= E
;
26919 -- During expansion of subprograms with postconditions the original
26920 -- subprogram's declarations and statements get wrapped into a local
26921 -- _Wrapped_Statements subprogram.
26923 if Chars
(Subp
) = Name_uWrapped_Statements
then
26924 Subp
:= Enclosing_Subprogram
(Subp
);
26928 or else (Present
(Subp_Alias
) and then Subp_Alias
= Subp
);
26929 end Same_Or_Aliased_Subprograms
;
26935 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
26940 elsif not Is_Constrained
(T1
)
26941 and then not Is_Constrained
(T2
)
26942 and then Base_Type
(T1
) = Base_Type
(T2
)
26946 -- For now don't bother with case of identical constraints, to be
26947 -- fiddled with later on perhaps (this is only used for optimization
26948 -- purposes, so it is not critical to do a best possible job)
26959 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
26961 if Compile_Time_Known_Value
(Node1
)
26962 and then Compile_Time_Known_Value
(Node2
)
26964 -- Handle properly compile-time expressions that are not
26967 if Is_String_Type
(Etype
(Node1
)) then
26968 return Expr_Value_S
(Node1
) = Expr_Value_S
(Node2
);
26971 return Expr_Value
(Node1
) = Expr_Value
(Node2
);
26974 elsif Same_Object
(Node1
, Node2
) then
26981 --------------------
26982 -- Set_SPARK_Mode --
26983 --------------------
26985 procedure Set_SPARK_Mode
(Context
: Entity_Id
) is
26987 -- Do not consider illegal or partially decorated constructs
26989 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
26992 elsif Present
(SPARK_Pragma
(Context
)) then
26994 (Mode
=> Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Context
)),
26995 Prag
=> SPARK_Pragma
(Context
));
26997 end Set_SPARK_Mode
;
26999 -------------------------
27000 -- Scalar_Part_Present --
27001 -------------------------
27003 function Scalar_Part_Present
(Typ
: Entity_Id
) return Boolean is
27004 Val_Typ
: constant Entity_Id
:= Validated_View
(Typ
);
27008 if Is_Scalar_Type
(Val_Typ
) then
27011 elsif Is_Array_Type
(Val_Typ
) then
27012 return Scalar_Part_Present
(Component_Type
(Val_Typ
));
27014 elsif Is_Record_Type
(Val_Typ
) then
27015 Field
:= First_Component_Or_Discriminant
(Val_Typ
);
27016 while Present
(Field
) loop
27017 if Scalar_Part_Present
(Etype
(Field
)) then
27021 Next_Component_Or_Discriminant
(Field
);
27026 end Scalar_Part_Present
;
27028 ------------------------
27029 -- Scope_Is_Transient --
27030 ------------------------
27032 function Scope_Is_Transient
return Boolean is
27034 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
27035 end Scope_Is_Transient
;
27041 function Scope_Within
27042 (Inner
: Entity_Id
;
27043 Outer
: Entity_Id
) return Boolean
27049 while Present
(Curr
) and then Curr
/= Standard_Standard
loop
27050 Curr
:= Scope
(Curr
);
27052 if Curr
= Outer
then
27055 -- A selective accept body appears within a task type, but the
27056 -- enclosing subprogram is the procedure of the task body.
27058 elsif Ekind
(Implementation_Base_Type
(Curr
)) = E_Task_Type
27060 Outer
= Task_Body_Procedure
(Implementation_Base_Type
(Curr
))
27064 -- Ditto for the body of a protected operation
27066 elsif Is_Subprogram
(Curr
)
27067 and then Outer
= Protected_Body_Subprogram
(Curr
)
27071 -- The body of a protected operation is within the protected type
27073 elsif Is_Subprogram
(Curr
)
27074 and then Present
(Protected_Subprogram
(Curr
))
27075 and then Is_Protected_Type
(Outer
)
27076 and then Scope
(Protected_Subprogram
(Curr
)) = Outer
27080 -- Outside of its scope, a synchronized type may just be private
27082 elsif Is_Private_Type
(Curr
)
27083 and then Present
(Full_View
(Curr
))
27084 and then Is_Concurrent_Type
(Full_View
(Curr
))
27086 return Scope_Within
(Full_View
(Curr
), Outer
);
27093 --------------------------
27094 -- Scope_Within_Or_Same --
27095 --------------------------
27097 function Scope_Within_Or_Same
27098 (Inner
: Entity_Id
;
27099 Outer
: Entity_Id
) return Boolean
27101 Curr
: Entity_Id
:= Inner
;
27104 -- Similar to the above, but check for scope identity first
27106 while Present
(Curr
) and then Curr
/= Standard_Standard
loop
27107 if Curr
= Outer
then
27110 elsif Ekind
(Implementation_Base_Type
(Curr
)) = E_Task_Type
27112 Outer
= Task_Body_Procedure
(Implementation_Base_Type
(Curr
))
27116 elsif Is_Subprogram
(Curr
)
27117 and then Outer
= Protected_Body_Subprogram
(Curr
)
27121 elsif Is_Subprogram
(Curr
)
27122 and then Present
(Protected_Subprogram
(Curr
))
27123 and then Is_Protected_Type
(Outer
)
27124 and then Scope
(Protected_Subprogram
(Curr
)) = Outer
27128 elsif Is_Private_Type
(Curr
)
27129 and then Present
(Full_View
(Curr
))
27131 if Full_View
(Curr
) = Outer
then
27134 return Scope_Within
(Full_View
(Curr
), Outer
);
27138 Curr
:= Scope
(Curr
);
27142 end Scope_Within_Or_Same
;
27144 ------------------------
27145 -- Set_Current_Entity --
27146 ------------------------
27148 -- The given entity is to be set as the currently visible definition of its
27149 -- associated name (i.e. the Node_Id associated with its name). All we have
27150 -- to do is to get the name from the identifier, and then set the
27151 -- associated Node_Id to point to the given entity.
27153 procedure Set_Current_Entity
(E
: Entity_Id
) is
27155 Set_Name_Entity_Id
(Chars
(E
), E
);
27156 end Set_Current_Entity
;
27158 ---------------------------
27159 -- Set_Debug_Info_Needed --
27160 ---------------------------
27162 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
27164 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
27165 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
27166 -- Used to set debug info in a related node if not set already
27168 --------------------------------------
27169 -- Set_Debug_Info_Needed_If_Not_Set --
27170 --------------------------------------
27172 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
27174 if Present
(E
) and then not Needs_Debug_Info
(E
) then
27175 Set_Debug_Info_Needed
(E
);
27177 -- For a private type, indicate that the full view also needs
27178 -- debug information.
27181 and then Is_Private_Type
(E
)
27182 and then Present
(Full_View
(E
))
27184 Set_Debug_Info_Needed
(Full_View
(E
));
27187 end Set_Debug_Info_Needed_If_Not_Set
;
27189 -- Start of processing for Set_Debug_Info_Needed
27192 -- Nothing to do if there is no available entity
27197 -- Nothing to do for an entity with suppressed debug information
27199 elsif Debug_Info_Off
(T
) then
27202 -- Nothing to do for an ignored Ghost entity because the entity will be
27203 -- eliminated from the tree.
27205 elsif Is_Ignored_Ghost_Entity
(T
) then
27208 -- Nothing to do if entity comes from a predefined file. Library files
27209 -- are compiled without debug information, but inlined bodies of these
27210 -- routines may appear in user code, and debug information on them ends
27211 -- up complicating debugging the user code.
27213 elsif In_Inlined_Body
and then In_Predefined_Unit
(T
) then
27214 Set_Needs_Debug_Info
(T
, False);
27217 -- Set flag in entity itself. Note that we will go through the following
27218 -- circuitry even if the flag is already set on T. That's intentional,
27219 -- it makes sure that the flag will be set in subsidiary entities.
27221 Set_Needs_Debug_Info
(T
);
27223 -- Set flag on subsidiary entities if not set already
27225 if Is_Object
(T
) then
27226 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
27228 elsif Is_Type
(T
) then
27229 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
27231 if Is_Record_Type
(T
) then
27233 Ent
: Entity_Id
:= First_Entity
(T
);
27235 while Present
(Ent
) loop
27236 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
27241 -- For a class wide subtype, we also need debug information
27242 -- for the equivalent type.
27244 if Ekind
(T
) = E_Class_Wide_Subtype
then
27245 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
27248 elsif Is_Array_Type
(T
) then
27249 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
27252 Indx
: Node_Id
:= First_Index
(T
);
27254 while Present
(Indx
) loop
27255 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
27260 -- For a packed array type, we also need debug information for
27261 -- the type used to represent the packed array. Conversely, we
27262 -- also need it for the former if we need it for the latter.
27264 if Is_Packed
(T
) then
27265 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
27268 if Is_Packed_Array_Impl_Type
(T
) then
27269 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
27272 elsif Is_Access_Type
(T
) then
27273 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
27275 elsif Is_Private_Type
(T
) then
27277 FV
: constant Entity_Id
:= Full_View
(T
);
27280 Set_Debug_Info_Needed_If_Not_Set
(FV
);
27282 -- If the full view is itself a derived private type, we need
27283 -- debug information on its underlying type.
27286 and then Is_Private_Type
(FV
)
27287 and then Present
(Underlying_Full_View
(FV
))
27289 Set_Needs_Debug_Info
(Underlying_Full_View
(FV
));
27293 elsif Is_Protected_Type
(T
) then
27294 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
27296 elsif Is_Scalar_Type
(T
) then
27298 -- If the subrange bounds are materialized by dedicated constant
27299 -- objects, also include them in the debug info to make sure the
27300 -- debugger can properly use them.
27302 if Present
(Scalar_Range
(T
))
27303 and then Nkind
(Scalar_Range
(T
)) = N_Range
27306 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
27307 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
27310 if Is_Entity_Name
(Low_Bnd
) then
27311 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
27314 if Is_Entity_Name
(High_Bnd
) then
27315 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
27321 end Set_Debug_Info_Needed
;
27323 --------------------------------
27324 -- Set_Debug_Info_Defining_Id --
27325 --------------------------------
27327 procedure Set_Debug_Info_Defining_Id
(N
: Node_Id
) is
27329 if Comes_From_Source
(Defining_Identifier
(N
))
27330 or else Debug_Generated_Code
27332 Set_Debug_Info_Needed
(Defining_Identifier
(N
));
27334 end Set_Debug_Info_Defining_Id
;
27336 ----------------------------
27337 -- Set_Entity_With_Checks --
27338 ----------------------------
27340 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
27341 Val_Actual
: Entity_Id
;
27343 Post_Node
: Node_Id
;
27346 -- Unconditionally set the entity
27348 Set_Entity
(N
, Val
);
27350 -- The node to post on is the selector in the case of an expanded name,
27351 -- and otherwise the node itself.
27353 if Nkind
(N
) = N_Expanded_Name
then
27354 Post_Node
:= Selector_Name
(N
);
27359 -- Check for violation of No_Fixed_IO
27361 if Restriction_Check_Required
(No_Fixed_IO
)
27363 ((RTU_Loaded
(Ada_Text_IO
)
27364 and then (Is_RTE
(Val
, RE_Decimal_IO
)
27366 Is_RTE
(Val
, RE_Fixed_IO
)))
27369 (RTU_Loaded
(Ada_Wide_Text_IO
)
27370 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
27372 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
27375 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
27376 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
27378 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
27380 -- A special extra check, don't complain about a reference from within
27381 -- the Ada.Interrupts package itself!
27383 and then not In_Same_Extended_Unit
(N
, Val
)
27385 Check_Restriction
(No_Fixed_IO
, Post_Node
);
27388 -- Remaining checks are only done on source nodes. Note that we test
27389 -- for violation of No_Fixed_IO even on non-source nodes, because the
27390 -- cases for checking violations of this restriction are instantiations
27391 -- where the reference in the instance has Comes_From_Source False.
27393 if not Comes_From_Source
(N
) then
27397 -- Check for violation of No_Abort_Statements, which is triggered by
27398 -- call to Ada.Task_Identification.Abort_Task.
27400 if Restriction_Check_Required
(No_Abort_Statements
)
27401 and then Is_RTE
(Val
, RE_Abort_Task
)
27403 -- A special extra check, don't complain about a reference from within
27404 -- the Ada.Task_Identification package itself!
27406 and then not In_Same_Extended_Unit
(N
, Val
)
27408 Check_Restriction
(No_Abort_Statements
, Post_Node
);
27411 if Val
= Standard_Long_Long_Integer
then
27412 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
27415 -- Check for violation of No_Dynamic_Attachment
27417 if Restriction_Check_Required
(No_Dynamic_Attachment
)
27418 and then RTU_Loaded
(Ada_Interrupts
)
27419 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
27420 Is_RTE
(Val
, RE_Is_Attached
) or else
27421 Is_RTE
(Val
, RE_Current_Handler
) or else
27422 Is_RTE
(Val
, RE_Attach_Handler
) or else
27423 Is_RTE
(Val
, RE_Exchange_Handler
) or else
27424 Is_RTE
(Val
, RE_Detach_Handler
) or else
27425 Is_RTE
(Val
, RE_Reference
))
27427 -- A special extra check, don't complain about a reference from within
27428 -- the Ada.Interrupts package itself!
27430 and then not In_Same_Extended_Unit
(N
, Val
)
27432 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
27435 -- Check for No_Implementation_Identifiers
27437 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
27439 -- We have an implementation defined entity if it is marked as
27440 -- implementation defined, or is defined in a package marked as
27441 -- implementation defined. However, library packages themselves
27442 -- are excluded (we don't want to flag Interfaces itself, just
27443 -- the entities within it).
27445 if (Is_Implementation_Defined
(Val
)
27447 (Present
(Scope
(Val
))
27448 and then Is_Implementation_Defined
(Scope
(Val
))))
27449 and then not (Is_Package_Or_Generic_Package
(Val
)
27450 and then Is_Library_Level_Entity
(Val
))
27452 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
27456 -- Do the style check
27459 and then not Suppress_Style_Checks
(Val
)
27460 and then not In_Instance
27462 if Nkind
(N
) = N_Identifier
then
27464 elsif Nkind
(N
) = N_Expanded_Name
then
27465 Nod
:= Selector_Name
(N
);
27470 -- A special situation arises for derived operations, where we want
27471 -- to do the check against the parent (since the Sloc of the derived
27472 -- operation points to the derived type declaration itself).
27475 while not Comes_From_Source
(Val_Actual
)
27476 and then Nkind
(Val_Actual
) in N_Entity
27477 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
27478 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
27479 and then Present
(Alias
(Val_Actual
))
27481 Val_Actual
:= Alias
(Val_Actual
);
27484 -- Renaming declarations for generic actuals do not come from source,
27485 -- and have a different name from that of the entity they rename, so
27486 -- there is no style check to perform here.
27488 if Chars
(Nod
) = Chars
(Val_Actual
) then
27489 Style
.Check_Identifier
(Nod
, Val_Actual
);
27492 end Set_Entity_With_Checks
;
27494 ------------------------------
27495 -- Set_Invalid_Scalar_Value --
27496 ------------------------------
27498 procedure Set_Invalid_Scalar_Value
27499 (Scal_Typ
: Float_Scalar_Id
;
27502 Slot
: Ureal
renames Invalid_Floats
(Scal_Typ
);
27505 -- Detect an attempt to set a different value for the same scalar type
27507 pragma Assert
(Slot
= No_Ureal
);
27509 end Set_Invalid_Scalar_Value
;
27511 ------------------------------
27512 -- Set_Invalid_Scalar_Value --
27513 ------------------------------
27515 procedure Set_Invalid_Scalar_Value
27516 (Scal_Typ
: Integer_Scalar_Id
;
27519 Slot
: Uint
renames Invalid_Integers
(Scal_Typ
);
27522 -- Detect an attempt to set a different value for the same scalar type
27524 pragma Assert
(No
(Slot
));
27526 end Set_Invalid_Scalar_Value
;
27528 ------------------------
27529 -- Set_Name_Entity_Id --
27530 ------------------------
27532 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
27534 Set_Name_Table_Int
(Id
, Int
(Val
));
27535 end Set_Name_Entity_Id
;
27537 ---------------------
27538 -- Set_Next_Actual --
27539 ---------------------
27541 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
27543 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
27544 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
27546 end Set_Next_Actual
;
27548 ----------------------------------
27549 -- Set_Optimize_Alignment_Flags --
27550 ----------------------------------
27552 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
27554 if Optimize_Alignment
= 'S' then
27555 Set_Optimize_Alignment_Space
(E
);
27556 elsif Optimize_Alignment
= 'T' then
27557 Set_Optimize_Alignment_Time
(E
);
27559 end Set_Optimize_Alignment_Flags
;
27561 -----------------------
27562 -- Set_Public_Status --
27563 -----------------------
27565 procedure Set_Public_Status
(Id
: Entity_Id
) is
27566 S
: constant Entity_Id
:= Current_Scope
;
27568 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
27569 -- Determines if E is defined within handled statement sequence or
27570 -- an if statement, returns True if so, False otherwise.
27572 ----------------------
27573 -- Within_HSS_Or_If --
27574 ----------------------
27576 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
27579 N
:= Declaration_Node
(E
);
27587 N_Handled_Sequence_Of_Statements | N_If_Statement
27592 end Within_HSS_Or_If
;
27594 -- Start of processing for Set_Public_Status
27597 -- Everything in the scope of Standard is public
27599 if S
= Standard_Standard
then
27600 Set_Is_Public
(Id
);
27602 -- Entity is definitely not public if enclosing scope is not public
27604 elsif not Is_Public
(S
) then
27607 -- An object or function declaration that occurs in a handled sequence
27608 -- of statements or within an if statement is the declaration for a
27609 -- temporary object or local subprogram generated by the expander. It
27610 -- never needs to be made public and furthermore, making it public can
27611 -- cause back end problems.
27613 elsif Nkind
(Parent
(Id
)) in
27614 N_Object_Declaration | N_Function_Specification
27615 and then Within_HSS_Or_If
(Id
)
27619 -- Entities in public packages or records are public
27621 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
27622 Set_Is_Public
(Id
);
27624 -- The bounds of an entry family declaration can generate object
27625 -- declarations that are visible to the back-end, e.g. in the
27626 -- the declaration of a composite type that contains tasks.
27628 elsif Is_Concurrent_Type
(S
)
27629 and then not Has_Completion
(S
)
27630 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
27632 Set_Is_Public
(Id
);
27634 end Set_Public_Status
;
27636 -----------------------------
27637 -- Set_Referenced_Modified --
27638 -----------------------------
27640 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
27644 -- Deal with indexed or selected component where prefix is modified
27646 if Nkind
(N
) in N_Indexed_Component | N_Selected_Component
then
27647 Pref
:= Prefix
(N
);
27649 -- If prefix is access type, then it is the designated object that is
27650 -- being modified, which means we have no entity to set the flag on.
27652 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
27655 -- Otherwise chase the prefix
27658 Set_Referenced_Modified
(Pref
, Out_Param
);
27661 -- Otherwise see if we have an entity name (only other case to process)
27663 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
27664 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
27665 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
27667 end Set_Referenced_Modified
;
27673 procedure Set_Rep_Info
(T1
: Entity_Id
; T2
: Entity_Id
) is
27675 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
27676 Set_Is_Independent
(T1
, Is_Independent
(T2
));
27677 Set_Is_Volatile_Full_Access
(T1
, Is_Volatile_Full_Access
(T2
));
27679 if Is_Base_Type
(T1
) then
27680 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
27684 -------------------
27685 -- Set_Size_Info --
27686 -------------------
27688 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
27690 -- We copy Esize, but not RM_Size, since in general RM_Size is
27691 -- subtype specific and does not get inherited by all subtypes.
27693 Copy_Esize
(To
=> T1
, From
=> T2
);
27694 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
27696 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
27698 Is_Discrete_Or_Fixed_Point_Type
(T2
)
27700 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
27703 Copy_Alignment
(To
=> T1
, From
=> T2
);
27706 ------------------------------
27707 -- Should_Ignore_Pragma_Par --
27708 ------------------------------
27710 function Should_Ignore_Pragma_Par
(Prag_Name
: Name_Id
) return Boolean is
27711 pragma Assert
(Compiler_State
= Parsing
);
27712 -- This one can't work during semantic analysis, because we don't have a
27713 -- correct Current_Source_File.
27715 Result
: constant Boolean :=
27716 Get_Name_Table_Boolean3
(Prag_Name
)
27717 and then not Is_Internal_File_Name
27718 (File_Name
(Current_Source_File
));
27721 end Should_Ignore_Pragma_Par
;
27723 ------------------------------
27724 -- Should_Ignore_Pragma_Sem --
27725 ------------------------------
27727 function Should_Ignore_Pragma_Sem
(N
: Node_Id
) return Boolean is
27728 pragma Assert
(Compiler_State
= Analyzing
);
27729 Prag_Name
: constant Name_Id
:= Pragma_Name
(N
);
27730 Result
: constant Boolean :=
27731 Get_Name_Table_Boolean3
(Prag_Name
)
27732 and then not In_Internal_Unit
(N
);
27736 end Should_Ignore_Pragma_Sem
;
27738 --------------------
27739 -- Static_Boolean --
27740 --------------------
27742 function Static_Boolean
(N
: Node_Id
) return Opt_Ubool
is
27744 Analyze_And_Resolve
(N
, Standard_Boolean
);
27747 or else Error_Posted
(N
)
27748 or else Etype
(N
) = Any_Type
27753 if Is_OK_Static_Expression
(N
) then
27754 if not Raises_Constraint_Error
(N
) then
27755 return Expr_Value
(N
);
27760 elsif Etype
(N
) = Any_Type
then
27764 Flag_Non_Static_Expr
27765 ("static boolean expression required here", N
);
27768 end Static_Boolean
;
27770 --------------------
27771 -- Static_Integer --
27772 --------------------
27774 function Static_Integer
(N
: Node_Id
) return Uint
is
27776 Analyze_And_Resolve
(N
, Any_Integer
);
27779 or else Error_Posted
(N
)
27780 or else Etype
(N
) = Any_Type
27785 if Is_OK_Static_Expression
(N
) then
27786 if not Raises_Constraint_Error
(N
) then
27787 return Expr_Value
(N
);
27792 elsif Etype
(N
) = Any_Type
then
27796 Flag_Non_Static_Expr
27797 ("static integer expression required here", N
);
27800 end Static_Integer
;
27802 -------------------------------
27803 -- Statically_Denotes_Entity --
27804 -------------------------------
27806 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
27809 if not Is_Entity_Name
(N
) then
27816 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
27817 or else Is_Prival
(E
)
27818 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
27819 end Statically_Denotes_Entity
;
27821 -------------------------------
27822 -- Statically_Denotes_Object --
27823 -------------------------------
27825 function Statically_Denotes_Object
(N
: Node_Id
) return Boolean is
27827 return Statically_Denotes_Entity
(N
)
27828 and then Is_Object_Reference
(N
);
27829 end Statically_Denotes_Object
;
27831 --------------------------
27832 -- Statically_Different --
27833 --------------------------
27835 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
27836 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
27837 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
27839 return Is_Entity_Name
(R1
)
27840 and then Is_Entity_Name
(R2
)
27841 and then Entity
(R1
) /= Entity
(R2
)
27842 and then not Is_Formal
(Entity
(R1
))
27843 and then not Is_Formal
(Entity
(R2
));
27844 end Statically_Different
;
27846 -----------------------------
27847 -- Statically_Names_Object --
27848 -----------------------------
27850 function Statically_Names_Object
(N
: Node_Id
) return Boolean is
27852 if Statically_Denotes_Object
(N
) then
27854 elsif Is_Entity_Name
(N
) then
27856 E
: constant Entity_Id
:= Entity
(N
);
27858 return Nkind
(Parent
(E
)) = N_Object_Renaming_Declaration
27859 and then Statically_Names_Object
(Renamed_Object
(E
));
27864 when N_Indexed_Component
=>
27865 if Is_Access_Type
(Etype
(Prefix
(N
))) then
27866 -- treat implicit dereference same as explicit
27870 if not Is_Constrained
(Etype
(Prefix
(N
))) then
27875 Indx
: Node_Id
:= First_Index
(Etype
(Prefix
(N
)));
27876 Expr
: Node_Id
:= First
(Expressions
(N
));
27877 Index_Subtype
: Node_Id
;
27880 Index_Subtype
:= Etype
(Indx
);
27882 if not Is_Static_Subtype
(Index_Subtype
) then
27885 if not Is_OK_Static_Expression
(Expr
) then
27890 Index_Value
: constant Uint
:= Expr_Value
(Expr
);
27891 Low_Value
: constant Uint
:=
27892 Expr_Value
(Type_Low_Bound
(Index_Subtype
));
27893 High_Value
: constant Uint
:=
27894 Expr_Value
(Type_High_Bound
(Index_Subtype
));
27896 if Index_Value
< Low_Value
27897 or Index_Value
> High_Value
27904 Expr
:= Next
(Expr
);
27905 pragma Assert
(Present
(Indx
) = Present
(Expr
)
27906 or else Serious_Errors_Detected
> 0);
27907 exit when not (Present
(Indx
) and Present
(Expr
));
27911 when N_Selected_Component
=>
27912 if Is_Access_Type
(Etype
(Prefix
(N
))) then
27913 -- treat implicit dereference same as explicit
27917 if Ekind
(Entity
(Selector_Name
(N
))) not in
27918 E_Component | E_Discriminant
27924 Comp
: constant Entity_Id
:=
27925 Original_Record_Component
(Entity
(Selector_Name
(N
)));
27927 -- AI12-0373 confirms that we should not call
27928 -- Has_Discriminant_Dependent_Constraint here which would be
27931 if Is_Declared_Within_Variant
(Comp
) then
27936 when others => -- includes N_Slice, N_Explicit_Dereference
27940 pragma Assert
(Present
(Prefix
(N
)));
27942 return Statically_Names_Object
(Prefix
(N
));
27943 end Statically_Names_Object
;
27945 ---------------------------------
27946 -- String_From_Numeric_Literal --
27947 ---------------------------------
27949 function String_From_Numeric_Literal
(N
: Node_Id
) return String_Id
is
27950 Loc
: constant Source_Ptr
:= Sloc
(N
);
27951 Sbuffer
: constant Source_Buffer_Ptr
:=
27952 Source_Text
(Get_Source_File_Index
(Loc
));
27953 Src_Ptr
: Source_Ptr
:= Loc
;
27955 C
: Character := Sbuffer
(Src_Ptr
);
27956 -- Current source program character
27958 function Belongs_To_Numeric_Literal
(C
: Character) return Boolean;
27959 -- Return True if C belongs to the numeric literal
27961 --------------------------------
27962 -- Belongs_To_Numeric_Literal --
27963 --------------------------------
27965 function Belongs_To_Numeric_Literal
(C
: Character) return Boolean is
27968 when '0' .. '9' |
'_' |
'.' |
'e' |
'#' |
'A' .. 'F' =>
27971 -- Make sure '+' or '-' is part of an exponent
27975 Prev_C
: constant Character := Sbuffer
(Src_Ptr
- 1);
27977 return Prev_C
in 'e' |
'E';
27980 -- Other characters cannot belong to a numeric literal
27985 end Belongs_To_Numeric_Literal
;
27987 -- Start of processing for String_From_Numeric_Literal
27991 while Belongs_To_Numeric_Literal
(C
) loop
27992 Store_String_Char
(C
);
27993 Src_Ptr
:= Src_Ptr
+ 1;
27994 C
:= Sbuffer
(Src_Ptr
);
27998 end String_From_Numeric_Literal
;
28000 --------------------------------------
28001 -- Subject_To_Loop_Entry_Attributes --
28002 --------------------------------------
28004 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
28010 -- The expansion mechanism transform a loop subject to at least one
28011 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
28012 -- the conditional part.
28014 if Nkind
(Stmt
) in N_Block_Statement | N_If_Statement
28015 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
28017 Stmt
:= Original_Node
(N
);
28021 Nkind
(Stmt
) = N_Loop_Statement
28022 and then Present
(Identifier
(Stmt
))
28023 and then Present
(Entity
(Identifier
(Stmt
)))
28024 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
28025 end Subject_To_Loop_Entry_Attributes
;
28027 ---------------------
28028 -- Subprogram_Name --
28029 ---------------------
28031 function Subprogram_Name
(N
: Node_Id
) return String is
28032 Buf
: Bounded_String
;
28033 Ent
: Node_Id
:= N
;
28037 while Present
(Ent
) loop
28038 case Nkind
(Ent
) is
28039 when N_Subprogram_Body
=>
28040 Ent
:= Defining_Unit_Name
(Specification
(Ent
));
28043 when N_Subprogram_Declaration
=>
28044 Nod
:= Corresponding_Body
(Ent
);
28046 if Present
(Nod
) then
28049 Ent
:= Defining_Unit_Name
(Specification
(Ent
));
28054 when N_Subprogram_Instantiation
28056 | N_Package_Specification
28058 Ent
:= Defining_Unit_Name
(Ent
);
28061 when N_Protected_Type_Declaration
=>
28062 Ent
:= Corresponding_Body
(Ent
);
28065 when N_Protected_Body
28068 Ent
:= Defining_Identifier
(Ent
);
28078 Ent
:= Parent
(Ent
);
28082 return "unknown subprogram:unknown file:0:0";
28085 -- If the subprogram is a child unit, use its simple name to start the
28086 -- construction of the fully qualified name.
28088 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
28089 Ent
:= Defining_Identifier
(Ent
);
28092 Append_Entity_Name
(Buf
, Ent
);
28094 -- Append homonym number if needed
28096 if Nkind
(N
) in N_Entity
and then Has_Homonym
(N
) then
28098 H
: Entity_Id
:= Homonym
(N
);
28102 while Present
(H
) loop
28103 if Scope
(H
) = Scope
(N
) then
28117 -- Append source location of Ent to Buf so that the string will
28118 -- look like "subp:file:line:col".
28121 Loc
: constant Source_Ptr
:= Sloc
(Ent
);
28124 Append
(Buf
, Reference_Name
(Get_Source_File_Index
(Loc
)));
28126 Append
(Buf
, Nat
(Get_Logical_Line_Number
(Loc
)));
28128 Append
(Buf
, Nat
(Get_Column_Number
(Loc
)));
28132 end Subprogram_Name
;
28134 -------------------------------
28135 -- Support_Atomic_Primitives --
28136 -------------------------------
28138 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
28142 -- Verify the alignment of Typ is known
28144 if not Known_Alignment
(Typ
) then
28148 if Known_Static_Esize
(Typ
) then
28149 Size
:= UI_To_Int
(Esize
(Typ
));
28151 -- If the Esize (Object_Size) is unknown at compile time, look at the
28152 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
28154 elsif Known_Static_RM_Size
(Typ
) then
28155 Size
:= UI_To_Int
(RM_Size
(Typ
));
28157 -- Otherwise, the size is considered to be unknown.
28163 -- Check that the size of the component is 8, 16, 32, or 64 bits and
28164 -- that Typ is properly aligned.
28167 when 8 |
16 |
32 |
64 =>
28168 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
28173 end Support_Atomic_Primitives
;
28179 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
28181 if Debug_Flag_W
then
28182 for J
in 0 .. Scope_Stack
.Last
loop
28187 Write_Name
(Chars
(E
));
28188 Write_Str
(" from ");
28189 Write_Location
(Sloc
(N
));
28194 -----------------------
28195 -- Transfer_Entities --
28196 -----------------------
28198 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
28199 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
28200 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
28201 -- Set_Public_Status. If successful and Id denotes a record type, set
28202 -- the Is_Public attribute of its fields.
28204 --------------------------
28205 -- Set_Public_Status_Of --
28206 --------------------------
28208 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
28212 if not Is_Public
(Id
) then
28213 Set_Public_Status
(Id
);
28215 -- When the input entity is a public record type, ensure that all
28216 -- its internal fields are also exposed to the linker. The fields
28217 -- of a class-wide type are never made public.
28220 and then Is_Record_Type
(Id
)
28221 and then not Is_Class_Wide_Type
(Id
)
28223 Field
:= First_Entity
(Id
);
28224 while Present
(Field
) loop
28225 Set_Is_Public
(Field
);
28226 Next_Entity
(Field
);
28230 end Set_Public_Status_Of
;
28234 Full_Id
: Entity_Id
;
28237 -- Start of processing for Transfer_Entities
28240 Id
:= First_Entity
(From
);
28242 if Present
(Id
) then
28244 -- Merge the entity chain of the source scope with that of the
28245 -- destination scope.
28247 if Present
(Last_Entity
(To
)) then
28248 Link_Entities
(Last_Entity
(To
), Id
);
28250 Set_First_Entity
(To
, Id
);
28253 Set_Last_Entity
(To
, Last_Entity
(From
));
28255 -- Inspect the entities of the source scope and update their Scope
28258 while Present
(Id
) loop
28259 Set_Scope
(Id
, To
);
28260 Set_Public_Status_Of
(Id
);
28262 -- Handle an internally generated full view for a private type
28264 if Is_Private_Type
(Id
)
28265 and then Present
(Full_View
(Id
))
28266 and then Is_Itype
(Full_View
(Id
))
28268 Full_Id
:= Full_View
(Id
);
28270 Set_Scope
(Full_Id
, To
);
28271 Set_Public_Status_Of
(Full_Id
);
28277 Set_First_Entity
(From
, Empty
);
28278 Set_Last_Entity
(From
, Empty
);
28280 end Transfer_Entities
;
28282 ------------------------
28283 -- Traverse_More_Func --
28284 ------------------------
28286 function Traverse_More_Func
(Node
: Node_Id
) return Traverse_Final_Result
is
28288 Processing_Itype
: Boolean := False;
28289 -- Set to True while traversing the nodes under an Itype, to prevent
28290 -- looping on Itype handling during that traversal.
28292 function Process_More
(N
: Node_Id
) return Traverse_Result
;
28293 -- Wrapper over the Process callback to handle parts of the AST that
28294 -- are not normally traversed as syntactic children.
28296 function Traverse_Rec
(N
: Node_Id
) return Traverse_Final_Result
;
28297 -- Main recursive traversal implemented as an instantiation of
28298 -- Traverse_Func over a modified Process callback.
28304 function Process_More
(N
: Node_Id
) return Traverse_Result
is
28306 procedure Traverse_More
(N
: Node_Id
;
28307 Res
: in out Traverse_Result
);
28308 procedure Traverse_More
(L
: List_Id
;
28309 Res
: in out Traverse_Result
);
28310 -- Traverse a node or list and update the traversal result to value
28311 -- Abandon when needed.
28313 -------------------
28314 -- Traverse_More --
28315 -------------------
28317 procedure Traverse_More
(N
: Node_Id
;
28318 Res
: in out Traverse_Result
)
28321 -- Do not process any more nodes if Abandon was reached
28323 if Res
= Abandon
then
28327 if Traverse_Rec
(N
) = Abandon
then
28332 procedure Traverse_More
(L
: List_Id
;
28333 Res
: in out Traverse_Result
)
28335 N
: Node_Id
:= First
(L
);
28338 -- Do not process any more nodes if Abandon was reached
28340 if Res
= Abandon
then
28344 while Present
(N
) loop
28345 Traverse_More
(N
, Res
);
28353 Result
: Traverse_Result
;
28355 -- Start of processing for Process_More
28358 -- Initial callback to Process. Return immediately on Skip/Abandon.
28359 -- Otherwise update the value of Node for further processing of
28360 -- non-syntactic children.
28362 Result
:= Process
(N
);
28365 when OK
=> Node
:= N
;
28366 when OK_Orig
=> Node
:= Original_Node
(N
);
28367 when Skip
=> return Skip
;
28368 when Abandon
=> return Abandon
;
28371 -- Process the relevant semantic children which are a logical part of
28372 -- the AST under this node before returning for the processing of
28373 -- syntactic children.
28375 -- Start with all non-syntactic lists of action nodes
28377 case Nkind
(Node
) is
28378 when N_Component_Association
=>
28379 Traverse_More
(Loop_Actions
(Node
), Result
);
28381 when N_Elsif_Part
=>
28382 Traverse_More
(Condition_Actions
(Node
), Result
);
28384 when N_Short_Circuit
=>
28385 Traverse_More
(Actions
(Node
), Result
);
28387 when N_Case_Expression_Alternative
=>
28388 Traverse_More
(Actions
(Node
), Result
);
28390 when N_Iterated_Component_Association
=>
28391 Traverse_More
(Loop_Actions
(Node
), Result
);
28393 when N_Iterated_Element_Association
=>
28394 Traverse_More
(Loop_Actions
(Node
), Result
);
28396 when N_Iteration_Scheme
=>
28397 Traverse_More
(Condition_Actions
(Node
), Result
);
28399 when N_If_Expression
=>
28400 Traverse_More
(Then_Actions
(Node
), Result
);
28401 Traverse_More
(Else_Actions
(Node
), Result
);
28403 -- Various nodes have a field Actions as a syntactic node,
28404 -- so it will be traversed in the regular syntactic traversal.
28406 when N_Compilation_Unit_Aux
28407 | N_Compound_Statement
28408 | N_Expression_With_Actions
28417 -- If Process_Itypes is True, process unattached nodes which come
28418 -- from Itypes. This only concerns currently ranges of scalar
28419 -- (possibly as index) types. This traversal is protected against
28420 -- looping with Processing_Itype.
28423 and then not Processing_Itype
28424 and then Nkind
(Node
) in N_Has_Etype
28425 and then Present
(Etype
(Node
))
28426 and then Is_Itype
(Etype
(Node
))
28429 Typ
: constant Entity_Id
:= Etype
(Node
);
28431 Processing_Itype
:= True;
28433 case Ekind
(Typ
) is
28434 when Scalar_Kind
=>
28435 Traverse_More
(Scalar_Range
(Typ
), Result
);
28439 Index
: Node_Id
:= First_Index
(Typ
);
28442 while Present
(Index
) loop
28443 if Nkind
(Index
) in N_Has_Entity
then
28444 Rng
:= Scalar_Range
(Entity
(Index
));
28449 Traverse_More
(Rng
, Result
);
28450 Next_Index
(Index
);
28457 Processing_Itype
:= False;
28464 -- Define Traverse_Rec as a renaming of the instantiation, as an
28465 -- instantiation cannot complete a previous spec.
28467 function Traverse_Recursive
is new Traverse_Func
(Process_More
);
28468 function Traverse_Rec
(N
: Node_Id
) return Traverse_Final_Result
28469 renames Traverse_Recursive
;
28471 -- Start of processing for Traverse_More_Func
28474 return Traverse_Rec
(Node
);
28475 end Traverse_More_Func
;
28477 ------------------------
28478 -- Traverse_More_Proc --
28479 ------------------------
28481 procedure Traverse_More_Proc
(Node
: Node_Id
) is
28482 function Traverse
is new Traverse_More_Func
(Process
, Process_Itypes
);
28483 Discard
: Traverse_Final_Result
;
28484 pragma Warnings
(Off
, Discard
);
28486 Discard
:= Traverse
(Node
);
28487 end Traverse_More_Proc
;
28489 ------------------------------------
28490 -- Type_Without_Stream_Operation --
28491 ------------------------------------
28493 function Type_Without_Stream_Operation
28495 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
28497 BT
: constant Entity_Id
:= Base_Type
(T
);
28498 Op_Missing
: Boolean;
28501 if not Restriction_Active
(No_Default_Stream_Attributes
) then
28505 if Is_Elementary_Type
(T
) then
28506 if Op
= TSS_Null
then
28508 No
(TSS
(BT
, TSS_Stream_Read
))
28509 or else No
(TSS
(BT
, TSS_Stream_Write
));
28512 Op_Missing
:= No
(TSS
(BT
, Op
));
28521 elsif Is_Array_Type
(T
) then
28522 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
28524 elsif Is_Record_Type
(T
) then
28530 Comp
:= First_Component
(T
);
28531 while Present
(Comp
) loop
28532 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
28534 if Present
(C_Typ
) then
28538 Next_Component
(Comp
);
28544 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
28545 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
28549 end Type_Without_Stream_Operation
;
28551 ------------------------------
28552 -- Ultimate_Overlaid_Entity --
28553 ------------------------------
28555 function Ultimate_Overlaid_Entity
(E
: Entity_Id
) return Entity_Id
is
28557 Alias
: Entity_Id
:= E
;
28561 -- Currently this routine is only called for stand-alone objects that
28562 -- have been analysed, since the analysis of the Address aspect is often
28565 pragma Assert
(Ekind
(E
) in E_Constant | E_Variable
);
28568 Address
:= Address_Clause
(Alias
);
28569 if Present
(Address
) then
28570 Find_Overlaid_Entity
(Address
, Alias
, Offset
);
28571 if Present
(Alias
) then
28576 elsif Alias
= E
then
28582 end Ultimate_Overlaid_Entity
;
28584 ---------------------
28585 -- Ultimate_Prefix --
28586 ---------------------
28588 function Ultimate_Prefix
(N
: Node_Id
) return Node_Id
is
28593 while Nkind
(Pref
) in N_Explicit_Dereference
28594 | N_Indexed_Component
28595 | N_Selected_Component
28598 Pref
:= Prefix
(Pref
);
28602 end Ultimate_Prefix
;
28604 ----------------------------
28605 -- Unique_Defining_Entity --
28606 ----------------------------
28608 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
28610 return Unique_Entity
(Defining_Entity
(N
));
28611 end Unique_Defining_Entity
;
28613 -------------------
28614 -- Unique_Entity --
28615 -------------------
28617 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
28618 U
: Entity_Id
:= E
;
28624 if Present
(Full_View
(E
)) then
28625 U
:= Full_View
(E
);
28629 if Nkind
(Parent
(E
)) = N_Entry_Body
then
28631 Prot_Item
: Entity_Id
;
28632 Prot_Type
: Entity_Id
;
28635 if Ekind
(E
) = E_Entry
then
28636 Prot_Type
:= Scope
(E
);
28638 -- Bodies of entry families are nested within an extra scope
28639 -- that contains an entry index declaration.
28642 Prot_Type
:= Scope
(Scope
(E
));
28645 -- A protected type may be declared as a private type, in
28646 -- which case we need to get its full view.
28648 if Is_Private_Type
(Prot_Type
) then
28649 Prot_Type
:= Full_View
(Prot_Type
);
28652 -- Full view may not be present on error, in which case
28653 -- return E by default.
28655 if Present
(Prot_Type
) then
28656 pragma Assert
(Ekind
(Prot_Type
) = E_Protected_Type
);
28658 -- Traverse the entity list of the protected type and
28659 -- locate an entry declaration which matches the entry
28662 Prot_Item
:= First_Entity
(Prot_Type
);
28663 while Present
(Prot_Item
) loop
28664 if Ekind
(Prot_Item
) in Entry_Kind
28665 and then Corresponding_Body
(Parent
(Prot_Item
)) = E
28671 Next_Entity
(Prot_Item
);
28677 when Formal_Kind
=>
28678 if Present
(Spec_Entity
(E
)) then
28679 U
:= Spec_Entity
(E
);
28682 when E_Package_Body
=>
28685 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
28689 if Nkind
(P
) = N_Package_Body
28690 and then Present
(Corresponding_Spec
(P
))
28692 U
:= Corresponding_Spec
(P
);
28694 elsif Nkind
(P
) = N_Package_Body_Stub
28695 and then Present
(Corresponding_Spec_Of_Stub
(P
))
28697 U
:= Corresponding_Spec_Of_Stub
(P
);
28700 when E_Protected_Body
=>
28703 if Nkind
(P
) = N_Protected_Body
28704 and then Present
(Corresponding_Spec
(P
))
28706 U
:= Corresponding_Spec
(P
);
28708 elsif Nkind
(P
) = N_Protected_Body_Stub
28709 and then Present
(Corresponding_Spec_Of_Stub
(P
))
28711 U
:= Corresponding_Spec_Of_Stub
(P
);
28713 if Is_Single_Protected_Object
(U
) then
28718 if Is_Private_Type
(U
) then
28719 U
:= Full_View
(U
);
28722 when E_Subprogram_Body
=>
28725 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
28731 if Nkind
(P
) = N_Subprogram_Body
28732 and then Present
(Corresponding_Spec
(P
))
28734 U
:= Corresponding_Spec
(P
);
28736 elsif Nkind
(P
) = N_Subprogram_Body_Stub
28737 and then Present
(Corresponding_Spec_Of_Stub
(P
))
28739 U
:= Corresponding_Spec_Of_Stub
(P
);
28741 elsif Nkind
(P
) = N_Subprogram_Renaming_Declaration
then
28742 U
:= Corresponding_Spec
(P
);
28745 when E_Task_Body
=>
28748 if Nkind
(P
) = N_Task_Body
28749 and then Present
(Corresponding_Spec
(P
))
28751 U
:= Corresponding_Spec
(P
);
28753 elsif Nkind
(P
) = N_Task_Body_Stub
28754 and then Present
(Corresponding_Spec_Of_Stub
(P
))
28756 U
:= Corresponding_Spec_Of_Stub
(P
);
28758 if Is_Single_Task_Object
(U
) then
28763 if Is_Private_Type
(U
) then
28764 U
:= Full_View
(U
);
28768 if Present
(Full_View
(E
)) then
28769 U
:= Full_View
(E
);
28783 function Unique_Name
(E
: Entity_Id
) return String is
28785 -- Local subprograms
28787 function Add_Homonym_Suffix
(E
: Entity_Id
) return String;
28789 function This_Name
return String;
28791 ------------------------
28792 -- Add_Homonym_Suffix --
28793 ------------------------
28795 function Add_Homonym_Suffix
(E
: Entity_Id
) return String is
28797 -- Names in E_Subprogram_Body or E_Package_Body entities are not
28798 -- reliable, as they may not include the overloading suffix.
28799 -- Instead, when looking for the name of E or one of its enclosing
28800 -- scope, we get the name of the corresponding Unique_Entity.
28802 U
: constant Entity_Id
:= Unique_Entity
(E
);
28803 Nam
: constant String := Get_Name_String
(Chars
(U
));
28806 -- If E has homonyms but is not fully qualified, as done in
28807 -- GNATprove mode, append the homonym number on the fly. Strip the
28808 -- leading space character in the image of natural numbers. Also do
28809 -- not print the homonym value of 1.
28811 if Has_Homonym
(U
) then
28813 N
: constant Pos
:= Homonym_Number
(U
);
28814 S
: constant String := N
'Img;
28817 return Nam
& "__" & S
(2 .. S
'Last);
28823 end Add_Homonym_Suffix
;
28829 function This_Name
return String is
28831 return Add_Homonym_Suffix
(E
);
28836 U
: constant Entity_Id
:= Unique_Entity
(E
);
28838 -- Start of processing for Unique_Name
28841 if E
= Standard_Standard
28842 or else Has_Fully_Qualified_Name
(E
)
28846 elsif Ekind
(E
) = E_Enumeration_Literal
then
28847 return Unique_Name
(Etype
(E
)) & "__" & This_Name
;
28851 S
: constant Entity_Id
:= Scope
(U
);
28852 pragma Assert
(Present
(S
));
28855 -- Prefix names of predefined types with standard__, but leave
28856 -- names of user-defined packages and subprograms without prefix
28857 -- (even if technically they are nested in the Standard package).
28859 if S
= Standard_Standard
then
28860 if Ekind
(U
) = E_Package
or else Is_Subprogram
(U
) then
28863 return Unique_Name
(S
) & "__" & This_Name
;
28866 -- For intances of generic subprograms use the name of the related
28867 -- instance and skip the scope of its wrapper package.
28869 elsif Is_Wrapper_Package
(S
) then
28870 pragma Assert
(Scope
(S
) = Scope
(Related_Instance
(S
)));
28871 -- Wrapper package and the instantiation are in the same scope
28874 Related_Name
: constant String :=
28875 Add_Homonym_Suffix
(Related_Instance
(S
));
28876 Enclosing_Name
: constant String :=
28877 Unique_Name
(Scope
(S
)) & "__" & Related_Name
;
28880 if Is_Subprogram
(U
)
28881 and then not Is_Generic_Actual_Subprogram
(U
)
28883 return Enclosing_Name
;
28885 return Enclosing_Name
& "__" & This_Name
;
28889 elsif Is_Child_Unit
(U
) then
28890 return Child_Prefix
& Unique_Name
(S
) & "__" & This_Name
;
28892 return Unique_Name
(S
) & "__" & This_Name
;
28898 ---------------------
28899 -- Unit_Is_Visible --
28900 ---------------------
28902 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
28903 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
28904 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
28906 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
28907 -- For a child unit, check whether unit appears in a with_clause
28910 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
28911 -- Scan the context clause of one compilation unit looking for a
28912 -- with_clause for the unit in question.
28914 ----------------------------
28915 -- Unit_In_Parent_Context --
28916 ----------------------------
28918 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
28920 if Unit_In_Context
(Par_Unit
) then
28923 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
28924 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
28929 end Unit_In_Parent_Context
;
28931 ---------------------
28932 -- Unit_In_Context --
28933 ---------------------
28935 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
28939 Clause
:= First
(Context_Items
(Comp_Unit
));
28940 while Present
(Clause
) loop
28941 if Nkind
(Clause
) = N_With_Clause
then
28942 if Library_Unit
(Clause
) = U
then
28945 -- The with_clause may denote a renaming of the unit we are
28946 -- looking for, eg. Text_IO which renames Ada.Text_IO.
28949 Renamed_Entity
(Entity
(Name
(Clause
))) =
28950 Defining_Entity
(Unit
(U
))
28960 end Unit_In_Context
;
28962 -- Start of processing for Unit_Is_Visible
28965 -- The currrent unit is directly visible
28970 elsif Unit_In_Context
(Curr
) then
28973 -- If the current unit is a body, check the context of the spec
28975 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
28977 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
28978 and then not Acts_As_Spec
(Unit
(Curr
)))
28980 if Unit_In_Context
(Library_Unit
(Curr
)) then
28985 -- If the spec is a child unit, examine the parents
28987 if Is_Child_Unit
(Curr_Entity
) then
28988 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
28990 Unit_In_Parent_Context
28991 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
28993 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
28999 end Unit_Is_Visible
;
29001 ------------------------------
29002 -- Universal_Interpretation --
29003 ------------------------------
29005 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
29006 Index
: Interp_Index
;
29010 -- The argument may be a formal parameter of an operator or subprogram
29011 -- with multiple interpretations, or else an expression for an actual.
29013 if Nkind
(Opnd
) = N_Defining_Identifier
29014 or else not Is_Overloaded
(Opnd
)
29016 if Is_Universal_Numeric_Type
(Etype
(Opnd
)) then
29017 return Etype
(Opnd
);
29023 Get_First_Interp
(Opnd
, Index
, It
);
29024 while Present
(It
.Typ
) loop
29025 if Is_Universal_Numeric_Type
(It
.Typ
) then
29029 Get_Next_Interp
(Index
, It
);
29034 end Universal_Interpretation
;
29040 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
29042 -- Recurse to handle unlikely case of multiple levels of qualification
29044 if Nkind
(Expr
) = N_Qualified_Expression
then
29045 return Unqualify
(Expression
(Expr
));
29047 -- Normal case, not a qualified expression
29058 function Unqual_Conv
(Expr
: Node_Id
) return Node_Id
is
29060 -- Recurse to handle unlikely case of multiple levels of qualification
29061 -- and/or conversion.
29063 if Nkind
(Expr
) in N_Qualified_Expression
29064 | N_Type_Conversion
29065 | N_Unchecked_Type_Conversion
29067 return Unqual_Conv
(Expression
(Expr
));
29069 -- Normal case, not a qualified expression
29076 --------------------
29077 -- Validated_View --
29078 --------------------
29080 function Validated_View
(Typ
: Entity_Id
) return Entity_Id
is
29082 -- Scalar types can be always validated. In fast, switiching to the base
29083 -- type would drop the range constraints and force validation to use a
29084 -- larger type than necessary.
29086 if Is_Scalar_Type
(Typ
) then
29089 -- Array types can be validated even when they are derived, because
29090 -- validation only requires their bounds and component types to be
29091 -- accessible. In fact, switching to the parent type would pollute
29092 -- expansion of attribute Valid_Scalars with unnecessary conversion
29093 -- that might not be eliminated by the frontend.
29095 elsif Is_Array_Type
(Typ
) then
29098 -- For other types, in particular for record subtypes, we switch to the
29101 elsif not Is_Base_Type
(Typ
) then
29102 return Validated_View
(Base_Type
(Typ
));
29104 -- Obtain the full view of the input type by stripping away concurrency,
29105 -- derivations, and privacy.
29107 elsif Is_Concurrent_Type
(Typ
) then
29108 if Present
(Corresponding_Record_Type
(Typ
)) then
29109 return Corresponding_Record_Type
(Typ
);
29114 elsif Is_Derived_Type
(Typ
) then
29115 return Validated_View
(Etype
(Typ
));
29117 elsif Is_Private_Type
(Typ
) then
29118 if Present
(Underlying_Full_View
(Typ
)) then
29119 return Validated_View
(Underlying_Full_View
(Typ
));
29121 elsif Present
(Full_View
(Typ
)) then
29122 return Validated_View
(Full_View
(Typ
));
29127 elsif From_Limited_With
(Typ
) then
29128 if Has_Non_Limited_View
(Typ
) then
29129 return Validated_View
(Non_Limited_View
(Typ
));
29137 end Validated_View
;
29139 -----------------------
29140 -- Visible_Ancestors --
29141 -----------------------
29143 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
29149 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
29151 -- Collect all the parents and progenitors of Typ. If the full-view of
29152 -- private parents and progenitors is available then it is used to
29153 -- generate the list of visible ancestors; otherwise their partial
29154 -- view is added to the resulting list.
29159 Use_Full_View
=> True);
29163 Ifaces_List
=> List_2
,
29164 Exclude_Parents
=> True,
29165 Use_Full_View
=> True);
29167 -- Join the two lists. Avoid duplications because an interface may
29168 -- simultaneously be parent and progenitor of a type.
29170 Elmt
:= First_Elmt
(List_2
);
29171 while Present
(Elmt
) loop
29172 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
29177 end Visible_Ancestors
;
29179 ---------------------------
29180 -- Warn_On_Hiding_Entity --
29181 ---------------------------
29183 procedure Warn_On_Hiding_Entity
29185 Hidden
, Visible
: Entity_Id
;
29186 On_Use_Clause
: Boolean)
29189 -- Don't warn for record components since they always have a well
29190 -- defined scope which does not confuse other uses. Note that in
29191 -- some cases, Ekind has not been set yet.
29193 if Ekind
(Hidden
) /= E_Component
29194 and then Ekind
(Hidden
) /= E_Discriminant
29195 and then Nkind
(Parent
(Hidden
)) /= N_Component_Declaration
29196 and then Ekind
(Visible
) /= E_Component
29197 and then Ekind
(Visible
) /= E_Discriminant
29198 and then Nkind
(Parent
(Visible
)) /= N_Component_Declaration
29200 -- Don't warn for one character variables. It is too common to use
29201 -- such variables as locals and will just cause too many false hits.
29203 and then Length_Of_Name
(Chars
(Hidden
)) /= 1
29205 -- Don't warn for non-source entities
29207 and then Comes_From_Source
(Hidden
)
29208 and then Comes_From_Source
(Visible
)
29210 -- Don't warn within a generic instantiation
29212 and then not In_Instance
29214 -- Don't warn unless entity in question is in extended main source
29216 and then In_Extended_Main_Source_Unit
(Visible
)
29218 -- Finally, in the case of a declaration, the hidden entity must
29219 -- be either immediately visible or use visible (i.e. from a used
29220 -- package). In the case of a use clause, the visible entity must
29221 -- be immediately visible.
29224 (if On_Use_Clause
then
29225 Is_Immediately_Visible
(Visible
)
29227 (Is_Immediately_Visible
(Hidden
)
29229 Is_Potentially_Use_Visible
(Hidden
)))
29231 if On_Use_Clause
then
29232 Error_Msg_Sloc
:= Sloc
(Visible
);
29233 Error_Msg_NE
("visible declaration of&# hides homonym "
29234 & "from use clause?h?", N
, Hidden
);
29236 Error_Msg_Sloc
:= Sloc
(Hidden
);
29237 Error_Msg_NE
("declaration hides &#?h?", N
, Visible
);
29240 end Warn_On_Hiding_Entity
;
29242 ----------------------
29243 -- Within_Init_Proc --
29244 ----------------------
29246 function Within_Init_Proc
return Boolean is
29250 S
:= Current_Scope
;
29251 while not Is_Overloadable
(S
) loop
29252 if S
= Standard_Standard
then
29259 return Is_Init_Proc
(S
);
29260 end Within_Init_Proc
;
29262 ---------------------------
29263 -- Within_Protected_Type --
29264 ---------------------------
29266 function Within_Protected_Type
(E
: Entity_Id
) return Boolean is
29267 Scop
: Entity_Id
:= Scope
(E
);
29270 while Present
(Scop
) loop
29271 if Ekind
(Scop
) = E_Protected_Type
then
29275 Scop
:= Scope
(Scop
);
29279 end Within_Protected_Type
;
29285 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
29287 return Scope_Within_Or_Same
(Scope
(E
), S
);
29294 procedure Wrong_Type
29296 Expected_Type
: Entity_Id
;
29297 Multiple
: Boolean := False)
29299 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
29300 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
29302 Err_Msg_Exp_Typ
: Entity_Id
:= Expected_Type
;
29303 -- Type entity used when printing errors concerning the expected type
29305 Matching_Field
: Entity_Id
;
29306 -- Entity to give a more precise suggestion on how to write a one-
29307 -- element positional aggregate.
29309 function Has_One_Matching_Field
return Boolean;
29310 -- Determines if Expec_Type is a record type with a single component or
29311 -- discriminant whose type matches the found type or is one dimensional
29312 -- array whose component type matches the found type. In the case of
29313 -- one discriminant, we ignore the variant parts. That's not accurate,
29314 -- but good enough for the warning.
29316 ----------------------------
29317 -- Has_One_Matching_Field --
29318 ----------------------------
29320 function Has_One_Matching_Field
return Boolean is
29324 Matching_Field
:= Empty
;
29326 if Is_Array_Type
(Expec_Type
)
29327 and then Number_Dimensions
(Expec_Type
) = 1
29328 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
29330 -- Use type name if available. This excludes multidimensional
29331 -- arrays and anonymous arrays.
29333 if Comes_From_Source
(Expec_Type
) then
29334 Matching_Field
:= Expec_Type
;
29336 -- For an assignment, use name of target
29338 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
29339 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
29341 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
29346 elsif not Is_Record_Type
(Expec_Type
) then
29350 E
:= First_Entity
(Expec_Type
);
29355 elsif Ekind
(E
) not in E_Discriminant | E_Component
29356 or else Chars
(E
) in Name_uTag | Name_uParent
29365 if not Covers
(Etype
(E
), Found_Type
) then
29368 elsif Present
(Next_Entity
(E
))
29369 and then (Ekind
(E
) = E_Component
29370 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
29375 Matching_Field
:= E
;
29379 end Has_One_Matching_Field
;
29381 -- Start of processing for Wrong_Type
29384 -- Don't output message if either type is Any_Type, or if a message
29385 -- has already been posted for this node and we do not want multiple
29386 -- error messages. We need to do the latter check explicitly (it is
29387 -- ordinarily done in Errout) because we are using '!' to force the
29388 -- output of the error messages.
29390 if Expec_Type
= Any_Type
29391 or else Found_Type
= Any_Type
29392 or else (Error_Posted
(Expr
) and then not Multiple
)
29396 -- If one of the types is a Taft-Amendment type and the other it its
29397 -- completion, it must be an illegal use of a TAT in the spec, for
29398 -- which an error was already emitted. Avoid cascaded errors.
29400 elsif Is_Incomplete_Type
(Expec_Type
)
29401 and then Has_Completion_In_Body
(Expec_Type
)
29402 and then Full_View
(Expec_Type
) = Etype
(Expr
)
29406 elsif Is_Incomplete_Type
(Etype
(Expr
))
29407 and then Has_Completion_In_Body
(Etype
(Expr
))
29408 and then Full_View
(Etype
(Expr
)) = Expec_Type
29413 -- Avoid printing internally generated subtypes in error messages and
29414 -- instead use the corresponding first subtype in such cases.
29416 if not Comes_From_Source
(Err_Msg_Exp_Typ
)
29417 or else not Comes_From_Source
(Declaration_Node
(Err_Msg_Exp_Typ
))
29419 Err_Msg_Exp_Typ
:= First_Subtype
(Err_Msg_Exp_Typ
);
29422 -- An interesting special check. If the expression is parenthesized
29423 -- and its type corresponds to the type of the sole component of the
29424 -- expected record type, or to the component type of the expected one
29425 -- dimensional array type, then assume we have a bad aggregate attempt.
29427 if Nkind
(Expr
) in N_Subexpr
29428 and then Paren_Count
(Expr
) /= 0
29429 and then Has_One_Matching_Field
29431 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
29433 if Present
(Matching_Field
) then
29434 if Is_Array_Type
(Expec_Type
) then
29436 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
29439 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
29443 -- Another special check, if we are looking for a pool-specific access
29444 -- type and we found an E_Access_Attribute_Type, then we have the case
29445 -- of an Access attribute being used in a context which needs a pool-
29446 -- specific type, which is never allowed. The one extra check we make
29447 -- is that the expected designated type covers the Found_Type.
29449 elsif Is_Access_Type
(Expec_Type
)
29450 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
29451 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
29452 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
29454 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
29457 ("result must be general access type!", Expr
);
29458 Error_Msg_NE
-- CODEFIX
29459 ("\add ALL to }!", Expr
, Err_Msg_Exp_Typ
);
29461 -- Another special check, if the expected type is an integer type,
29462 -- but the expression is of type System.Address, and the parent is
29463 -- an addition or subtraction operation whose left operand is the
29464 -- expression in question and whose right operand is of an integral
29465 -- type, then this is an attempt at address arithmetic, so give
29466 -- appropriate message.
29468 elsif Is_Integer_Type
(Expec_Type
)
29469 and then Is_RTE
(Found_Type
, RE_Address
)
29470 and then Nkind
(Parent
(Expr
)) in N_Op_Add | N_Op_Subtract
29471 and then Expr
= Left_Opnd
(Parent
(Expr
))
29472 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
29475 ("address arithmetic not predefined in package System",
29478 ("\possible missing with/use of System.Storage_Elements",
29482 -- If the expected type is an anonymous access type, as for access
29483 -- parameters and discriminants, the error is on the designated types.
29485 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
29486 if Comes_From_Source
(Expec_Type
) then
29487 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
29490 ("expected an access type with designated}",
29491 Expr
, Designated_Type
(Expec_Type
));
29494 if Is_Access_Type
(Found_Type
)
29495 and then not Comes_From_Source
(Found_Type
)
29498 ("\\found an access type with designated}!",
29499 Expr
, Designated_Type
(Found_Type
));
29501 if From_Limited_With
(Found_Type
) then
29502 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
29503 Error_Msg_Qual_Level
:= 99;
29504 Error_Msg_NE
-- CODEFIX
29505 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
29506 Error_Msg_Qual_Level
:= 0;
29508 Error_Msg_NE
("found}!", Expr
, Found_Type
);
29512 -- Normal case of one type found, some other type expected
29515 -- If the names of the two types are the same, see if some number
29516 -- of levels of qualification will help. Don't try more than three
29517 -- levels, and if we get to standard, it's no use (and probably
29518 -- represents an error in the compiler) Also do not bother with
29519 -- internal scope names.
29522 Expec_Scope
: Entity_Id
;
29523 Found_Scope
: Entity_Id
;
29526 Expec_Scope
:= Expec_Type
;
29527 Found_Scope
:= Found_Type
;
29529 for Levels
in Nat
range 0 .. 3 loop
29530 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
29531 Error_Msg_Qual_Level
:= Levels
;
29535 Expec_Scope
:= Scope
(Expec_Scope
);
29536 Found_Scope
:= Scope
(Found_Scope
);
29538 exit when Expec_Scope
= Standard_Standard
29539 or else Found_Scope
= Standard_Standard
29540 or else not Comes_From_Source
(Expec_Scope
)
29541 or else not Comes_From_Source
(Found_Scope
);
29545 if Is_Record_Type
(Expec_Type
)
29546 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
29548 Error_Msg_NE
("expected}!", Expr
,
29549 Corresponding_Remote_Type
(Expec_Type
));
29551 Error_Msg_NE
("expected}!", Expr
, Err_Msg_Exp_Typ
);
29554 if Is_Entity_Name
(Expr
)
29555 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
29557 Error_Msg_N
("\\found package name!", Expr
);
29559 elsif Is_Entity_Name
(Expr
)
29560 and then Ekind
(Entity
(Expr
)) in E_Procedure | E_Generic_Procedure
29562 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
29564 ("found procedure name, possibly missing Access attribute!",
29568 ("\\found procedure name instead of function!", Expr
);
29571 elsif Nkind
(Expr
) = N_Function_Call
29572 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
29573 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
29574 and then No
(Parameter_Associations
(Expr
))
29577 ("found function name, possibly missing Access attribute!",
29580 -- Catch common error: a prefix or infix operator which is not
29581 -- directly visible because the type isn't.
29583 elsif Nkind
(Expr
) in N_Op
29584 and then Is_Overloaded
(Expr
)
29585 and then not Is_Immediately_Visible
(Expec_Type
)
29586 and then not Is_Potentially_Use_Visible
(Expec_Type
)
29587 and then not In_Use
(Expec_Type
)
29588 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
29591 ("operator of the type is not directly visible!", Expr
);
29593 elsif Ekind
(Found_Type
) = E_Void
29594 and then Present
(Parent
(Found_Type
))
29595 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
29597 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
29600 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
29603 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
29604 -- of the same modular type, and (M1 and M2) = 0 was intended.
29606 if Expec_Type
= Standard_Boolean
29607 and then Is_Modular_Integer_Type
(Found_Type
)
29608 and then Nkind
(Parent
(Expr
)) in N_Op_And | N_Op_Or | N_Op_Xor
29609 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
29612 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
29613 L
: constant Node_Id
:= Left_Opnd
(Op
);
29614 R
: constant Node_Id
:= Right_Opnd
(Op
);
29617 -- The case for the message is when the left operand of the
29618 -- comparison is the same modular type, or when it is an
29619 -- integer literal (or other universal integer expression),
29620 -- which would have been typed as the modular type if the
29621 -- parens had been there.
29623 if (Etype
(L
) = Found_Type
29625 Etype
(L
) = Universal_Integer
)
29626 and then Is_Integer_Type
(Etype
(R
))
29629 ("\\possible missing parens for modular operation", Expr
);
29634 -- Reset error message qualification indication
29636 Error_Msg_Qual_Level
:= 0;
29640 --------------------------------
29641 -- Yields_Synchronized_Object --
29642 --------------------------------
29644 function Yields_Synchronized_Object
(Typ
: Entity_Id
) return Boolean is
29645 Has_Sync_Comp
: Boolean := False;
29649 -- An array type yields a synchronized object if its component type
29650 -- yields a synchronized object.
29652 if Is_Array_Type
(Typ
) then
29653 return Yields_Synchronized_Object
(Component_Type
(Typ
));
29655 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
29656 -- yields a synchronized object by default.
29658 elsif Is_Descendant_Of_Suspension_Object
(Typ
) then
29661 -- A protected type yields a synchronized object by default
29663 elsif Is_Protected_Type
(Typ
) then
29666 -- A record type or type extension yields a synchronized object when its
29667 -- discriminants (if any) lack default values and all components are of
29668 -- a type that yields a synchronized object.
29670 elsif Is_Record_Type
(Typ
) then
29672 -- Inspect all entities defined in the scope of the type, looking for
29673 -- components of a type that does not yield a synchronized object or
29674 -- for discriminants with default values.
29676 Id
:= First_Entity
(Typ
);
29677 while Present
(Id
) loop
29678 if Comes_From_Source
(Id
) then
29679 if Ekind
(Id
) = E_Component
then
29680 if Yields_Synchronized_Object
(Etype
(Id
)) then
29681 Has_Sync_Comp
:= True;
29683 -- The component does not yield a synchronized object
29689 elsif Ekind
(Id
) = E_Discriminant
29690 and then Present
(Expression
(Parent
(Id
)))
29699 -- Ensure that the parent type of a type extension yields a
29700 -- synchronized object.
29702 if Etype
(Typ
) /= Typ
29703 and then not Is_Private_Type
(Etype
(Typ
))
29704 and then not Yields_Synchronized_Object
(Etype
(Typ
))
29709 -- If we get here, then all discriminants lack default values and all
29710 -- components are of a type that yields a synchronized object.
29712 return Has_Sync_Comp
;
29714 -- A synchronized interface type yields a synchronized object by default
29716 elsif Is_Synchronized_Interface
(Typ
) then
29719 -- A task type yields a synchronized object by default
29721 elsif Is_Task_Type
(Typ
) then
29724 -- A private type yields a synchronized object if its underlying type
29727 elsif Is_Private_Type
(Typ
)
29728 and then Present
(Underlying_Type
(Typ
))
29730 return Yields_Synchronized_Object
(Underlying_Type
(Typ
));
29732 -- Otherwise the type does not yield a synchronized object
29737 end Yields_Synchronized_Object
;
29739 ---------------------------
29740 -- Yields_Universal_Type --
29741 ---------------------------
29743 function Yields_Universal_Type
(N
: Node_Id
) return Boolean is
29745 -- Integer and real literals are of a universal type
29747 if Nkind
(N
) in N_Integer_Literal | N_Real_Literal
then
29750 -- The values of certain attributes are of a universal type
29752 elsif Nkind
(N
) = N_Attribute_Reference
then
29754 Universal_Type_Attribute
(Get_Attribute_Id
(Attribute_Name
(N
)));
29756 -- ??? There are possibly other cases to consider
29761 end Yields_Universal_Type
;
29763 package body Interval_Lists
is
29765 procedure Check_Consistency
(Intervals
: Discrete_Interval_List
);
29766 -- Check that list is sorted, lacks null intervals, and has gaps
29767 -- between intervals.
29769 function Chosen_Interval
(Choice
: Node_Id
) return Discrete_Interval
;
29770 -- Given an element of a Discrete_Choices list, a
29771 -- Static_Discrete_Predicate list, or an Others_Discrete_Choices
29772 -- list (but not an N_Others_Choice node) return the corresponding
29773 -- interval. If an element that does not represent a single
29774 -- contiguous interval due to a static predicate (or which
29775 -- represents a single contiguous interval whose bounds depend on
29776 -- a static predicate) is encountered, then that is an error on the
29777 -- part of whoever built the list in question.
29779 function In_Interval
29780 (Value
: Uint
; Interval
: Discrete_Interval
) return Boolean;
29781 -- Does the given value lie within the given interval?
29783 procedure Normalize_Interval_List
29784 (List
: in out Discrete_Interval_List
; Last
: out Nat
);
29785 -- Perform sorting and merging as required by Check_Consistency
29787 -------------------------
29788 -- Aggregate_Intervals --
29789 -------------------------
29791 function Aggregate_Intervals
(N
: Node_Id
) return Discrete_Interval_List
29793 pragma Assert
(Nkind
(N
) = N_Aggregate
29794 and then Is_Array_Type
(Etype
(N
)));
29796 function Unmerged_Intervals_Count
return Nat
;
29797 -- Count the number of intervals given in the aggregate N; the others
29798 -- choice (if present) is not taken into account.
29800 ------------------------------
29801 -- Unmerged_Intervals_Count --
29802 ------------------------------
29804 function Unmerged_Intervals_Count
return Nat
is
29809 Comp
:= First
(Component_Associations
(N
));
29810 while Present
(Comp
) loop
29811 Choice
:= First
(Choices
(Comp
));
29813 while Present
(Choice
) loop
29814 if Nkind
(Choice
) /= N_Others_Choice
then
29815 Count
:= Count
+ 1;
29825 end Unmerged_Intervals_Count
;
29830 Max_I
: constant Nat
:= Unmerged_Intervals_Count
;
29831 Intervals
: Discrete_Interval_List
(1 .. Max_I
);
29834 -- Start of processing for Aggregate_Intervals
29837 -- No action needed if there are no intervals
29843 -- Internally store all the unsorted intervals
29845 Comp
:= First
(Component_Associations
(N
));
29846 while Present
(Comp
) loop
29848 Choice_Intervals
: constant Discrete_Interval_List
29849 := Choice_List_Intervals
(Choices
(Comp
));
29851 for J
in Choice_Intervals
'Range loop
29852 Num_I
:= Num_I
+ 1;
29853 Intervals
(Num_I
) := Choice_Intervals
(J
);
29860 -- Normalize the lists sorting and merging the intervals
29863 Aggr_Intervals
: Discrete_Interval_List
(1 .. Num_I
)
29864 := Intervals
(1 .. Num_I
);
29866 Normalize_Interval_List
(Aggr_Intervals
, Num_I
);
29867 Check_Consistency
(Aggr_Intervals
(1 .. Num_I
));
29868 return Aggr_Intervals
(1 .. Num_I
);
29870 end Aggregate_Intervals
;
29872 ------------------------
29873 -- Check_Consistency --
29874 ------------------------
29876 procedure Check_Consistency
(Intervals
: Discrete_Interval_List
) is
29878 if Serious_Errors_Detected
> 0 then
29882 -- low bound is 1 and high bound equals length
29883 pragma Assert
(Intervals
'First = 1 and Intervals
'Last >= 0);
29884 for Idx
in Intervals
'Range loop
29885 -- each interval is non-null
29886 pragma Assert
(Intervals
(Idx
).Low
<= Intervals
(Idx
).High
);
29887 if Idx
/= Intervals
'First then
29888 -- intervals are sorted with non-empty gaps between them
29890 (Intervals
(Idx
- 1).High
< (Intervals
(Idx
).Low
- 1));
29894 end Check_Consistency
;
29896 ---------------------------
29897 -- Choice_List_Intervals --
29898 ---------------------------
29900 function Choice_List_Intervals
29901 (Discrete_Choices
: List_Id
) return Discrete_Interval_List
29903 function Unmerged_Choice_Count
return Nat
;
29904 -- The number of intervals before adjacent intervals are merged
29906 ---------------------------
29907 -- Unmerged_Choice_Count --
29908 ---------------------------
29910 function Unmerged_Choice_Count
return Nat
is
29911 Choice
: Node_Id
:= First
(Discrete_Choices
);
29914 while Present
(Choice
) loop
29915 -- Non-contiguous choices involving static predicates
29916 -- have already been normalized away.
29918 if Nkind
(Choice
) = N_Others_Choice
then
29920 Count
+ List_Length
(Others_Discrete_Choices
(Choice
));
29922 Count
:= Count
+ 1; -- an ordinary expression or range
29928 end Unmerged_Choice_Count
;
29932 Choice
: Node_Id
:= First
(Discrete_Choices
);
29933 Result
: Discrete_Interval_List
(1 .. Unmerged_Choice_Count
);
29936 -- Start of processing for Choice_List_Intervals
29939 while Present
(Choice
) loop
29940 if Nkind
(Choice
) = N_Others_Choice
then
29942 Others_Choice
: Node_Id
29943 := First
(Others_Discrete_Choices
(Choice
));
29945 while Present
(Others_Choice
) loop
29946 Count
:= Count
+ 1;
29947 Result
(Count
) := Chosen_Interval
(Others_Choice
);
29948 Next
(Others_Choice
);
29952 Count
:= Count
+ 1;
29953 Result
(Count
) := Chosen_Interval
(Choice
);
29959 pragma Assert
(Count
= Result
'Last);
29960 Normalize_Interval_List
(Result
, Count
);
29961 Check_Consistency
(Result
(1 .. Count
));
29962 return Result
(1 .. Count
);
29963 end Choice_List_Intervals
;
29965 ---------------------
29966 -- Chosen_Interval --
29967 ---------------------
29969 function Chosen_Interval
(Choice
: Node_Id
) return Discrete_Interval
is
29971 case Nkind
(Choice
) is
29973 return (Low
=> Expr_Value
(Low_Bound
(Choice
)),
29974 High
=> Expr_Value
(High_Bound
(Choice
)));
29976 when N_Subtype_Indication
=>
29978 Range_Exp
: constant Node_Id
29979 := Range_Expression
(Constraint
(Choice
));
29981 return (Low
=> Expr_Value
(Low_Bound
(Range_Exp
)),
29982 High
=> Expr_Value
(High_Bound
(Range_Exp
)));
29985 when N_Others_Choice
=>
29986 raise Program_Error
;
29989 if Is_Entity_Name
(Choice
) and then Is_Type
(Entity
(Choice
))
29992 (Low
=> Expr_Value
(Type_Low_Bound
(Entity
(Choice
))),
29993 High
=> Expr_Value
(Type_High_Bound
(Entity
(Choice
))));
29996 return (Low | High
=> Expr_Value
(Choice
));
29999 end Chosen_Interval
;
30005 function In_Interval
30006 (Value
: Uint
; Interval
: Discrete_Interval
) return Boolean is
30008 return Value
>= Interval
.Low
and then Value
<= Interval
.High
;
30016 (Subset
, Of_Set
: Discrete_Interval_List
) return Boolean
30018 -- Returns True iff for each interval of Subset we can find
30019 -- a single interval of Of_Set which contains the Subset interval.
30021 if Of_Set
'Length = 0 then
30022 return Subset
'Length = 0;
30026 Set_Index
: Pos
range Of_Set
'Range := Of_Set
'First;
30029 for Ss_Idx
in Subset
'Range loop
30030 while not In_Interval
30031 (Value
=> Subset
(Ss_Idx
).Low
,
30032 Interval
=> Of_Set
(Set_Index
))
30034 if Set_Index
= Of_Set
'Last then
30038 Set_Index
:= Set_Index
+ 1;
30042 (Value
=> Subset
(Ss_Idx
).High
,
30043 Interval
=> Of_Set
(Set_Index
))
30053 -----------------------------
30054 -- Normalize_Interval_List --
30055 -----------------------------
30057 procedure Normalize_Interval_List
30058 (List
: in out Discrete_Interval_List
; Last
: out Nat
)
30060 Temp_0
: Discrete_Interval
:= (others => Uint_0
);
30061 -- Cope with Heap_Sort_G idiosyncrasies.
30063 function Is_Null
(Idx
: Pos
) return Boolean;
30064 -- True iff List (Idx) defines a null range
30066 function Lt_Interval
(Idx1
, Idx2
: Natural) return Boolean;
30067 -- Compare two list elements
30069 procedure Merge_Intervals
(Null_Interval_Count
: out Nat
);
30070 -- Merge contiguous ranges by replacing one with merged range and
30071 -- the other with a null value. Return a count of the null intervals,
30072 -- both preexisting and those introduced by merging.
30074 procedure Move_Interval
(From
, To
: Natural);
30075 -- Copy interval from one location to another
30077 function Read_Interval
(From
: Natural) return Discrete_Interval
;
30078 -- Normal array indexing unless From = 0
30080 ----------------------
30081 -- Interval_Sorting --
30082 ----------------------
30084 package Interval_Sorting
is
30085 new Gnat
.Heap_Sort_G
(Move_Interval
, Lt_Interval
);
30091 function Is_Null
(Idx
: Pos
) return Boolean is
30093 return List
(Idx
).Low
> List
(Idx
).High
;
30100 function Lt_Interval
(Idx1
, Idx2
: Natural) return Boolean is
30101 Elem1
: constant Discrete_Interval
:= Read_Interval
(Idx1
);
30102 Elem2
: constant Discrete_Interval
:= Read_Interval
(Idx2
);
30103 Null_1
: constant Boolean := Elem1
.Low
> Elem1
.High
;
30104 Null_2
: constant Boolean := Elem2
.Low
> Elem2
.High
;
30106 if Null_1
/= Null_2
then
30107 -- So that sorting moves null intervals to high end
30110 elsif Elem1
.Low
/= Elem2
.Low
then
30111 return Elem1
.Low
< Elem2
.Low
;
30114 return Elem1
.High
< Elem2
.High
;
30118 ---------------------
30119 -- Merge_Intervals --
30120 ---------------------
30122 procedure Merge_Intervals
(Null_Interval_Count
: out Nat
) is
30123 Not_Null
: Pos
range List
'Range;
30124 -- Index of the most recently examined non-null interval
30126 Null_Interval
: constant Discrete_Interval
30127 := (Low
=> Uint_1
, High
=> Uint_0
); -- any null range ok here
30129 if List
'Length = 0 or else Is_Null
(List
'First) then
30130 Null_Interval_Count
:= List
'Length;
30131 -- no non-null elements, so no merge candidates
30135 Null_Interval_Count
:= 0;
30136 Not_Null
:= List
'First;
30138 for Idx
in List
'First + 1 .. List
'Last loop
30139 if Is_Null
(Idx
) then
30141 -- all remaining elements are null
30143 Null_Interval_Count
:=
30144 Null_Interval_Count
+ List
(Idx
.. List
'Last)'Length;
30147 elsif List
(Idx
).Low
= List
(Not_Null
).High
+ 1 then
30149 -- Merge the two intervals into one; discard the other
30151 List
(Not_Null
).High
:= List
(Idx
).High
;
30152 List
(Idx
) := Null_Interval
;
30153 Null_Interval_Count
:= Null_Interval_Count
+ 1;
30156 if List
(Idx
).Low
<= List
(Not_Null
).High
then
30157 raise Intervals_Error
;
30160 pragma Assert
(List
(Idx
).Low
> List
(Not_Null
).High
);
30164 end Merge_Intervals
;
30166 -------------------
30167 -- Move_Interval --
30168 -------------------
30170 procedure Move_Interval
(From
, To
: Natural) is
30171 Rhs
: constant Discrete_Interval
:= Read_Interval
(From
);
30176 List
(Pos
(To
)) := Rhs
;
30180 -------------------
30181 -- Read_Interval --
30182 -------------------
30184 function Read_Interval
(From
: Natural) return Discrete_Interval
is
30189 return List
(Pos
(From
));
30193 -- Start of processing for Normalize_Interval_Lists
30196 Interval_Sorting
.Sort
(Natural (List
'Last));
30199 Null_Interval_Count
: Nat
;
30202 Merge_Intervals
(Null_Interval_Count
);
30203 Last
:= List
'Last - Null_Interval_Count
;
30205 if Null_Interval_Count
/= 0 then
30206 -- Move null intervals introduced during merging to high end
30207 Interval_Sorting
.Sort
(Natural (List
'Last));
30210 end Normalize_Interval_List
;
30212 --------------------
30213 -- Type_Intervals --
30214 --------------------
30216 function Type_Intervals
(Typ
: Entity_Id
) return Discrete_Interval_List
30219 if Has_Static_Predicate
(Typ
) then
30221 -- No sorting or merging needed
30222 SDP_List
: constant List_Id
:= Static_Discrete_Predicate
(Typ
);
30223 Range_Or_Expr
: Node_Id
:= First
(SDP_List
);
30224 Result
: Discrete_Interval_List
(1 .. List_Length
(SDP_List
));
30227 for Idx
in Result
'Range loop
30228 Result
(Idx
) := Chosen_Interval
(Range_Or_Expr
);
30229 Next
(Range_Or_Expr
);
30232 pragma Assert
(No
(Range_Or_Expr
));
30233 Check_Consistency
(Result
);
30238 Low
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Typ
));
30239 High
: constant Uint
:= Expr_Value
(Type_High_Bound
(Typ
));
30243 Null_Array
: Discrete_Interval_List
(1 .. 0);
30248 return (1 => (Low
=> Low
, High
=> High
));
30252 end Type_Intervals
;
30254 end Interval_Lists
;
30256 package body Old_Attr_Util
is
30257 package body Conditional_Evaluation
is
30258 type Determining_Expr_Context
is
30259 (No_Context
, If_Expr
, Case_Expr
, Short_Circuit_Op
, Membership_Test
);
30261 -- Determining_Expr_Context enumeration elements (except for
30262 -- No_Context) correspond to the list items in RM 6.1.1 definition
30263 -- of "determining expression".
30265 type Determining_Expr
30266 (Context
: Determining_Expr_Context
:= No_Context
)
30268 Expr
: Node_Id
:= Empty
;
30270 when Short_Circuit_Op
=>
30271 Is_And_Then
: Boolean;
30273 Is_Then_Part
: Boolean;
30275 Alternatives
: Node_Id
;
30276 when Membership_Test
=>
30277 -- Given a subexpression of <exp4> in a membership test
30278 -- <exp1> in <exp2> | <exp3> | <exp4> | <exp5>
30279 -- the corresponding determining expression value would
30280 -- have First_Non_Preceding = <exp4> (See RM 6.1.1).
30281 First_Non_Preceding
: Node_Id
;
30287 type Determining_Expression_List
is
30288 array (Positive range <>) of Determining_Expr
;
30290 function Determining_Condition
(Det
: Determining_Expr
)
30292 -- Given a determining expression, build a Boolean-valued
30293 -- condition that incorporates that expression into condition
30294 -- suitable for deciding whether to initialize a 'Old constant.
30295 -- Polarity is "True => initialize the constant".
30297 function Determining_Expressions
30298 (Expr
: Node_Id
; Expr_Trailer
: Node_Id
:= Empty
)
30299 return Determining_Expression_List
;
30300 -- Given a conditionally evaluated expression, return its
30301 -- determining expressions.
30302 -- See RM 6.1.1 for definition of term "determining expressions".
30303 -- Tests should be performed in the order they occur in the
30304 -- array, with short circuiting.
30305 -- A determining expression need not be of a boolean type (e.g.,
30306 -- it might be the determining expression of a case expression).
30307 -- The Expr_Trailer parameter should be defaulted for nonrecursive
30310 function Is_Conditionally_Evaluated
(Expr
: Node_Id
) return Boolean;
30311 -- See RM 6.1.1 for definition of term "conditionally evaluated".
30313 function Is_Known_On_Entry
(Expr
: Node_Id
) return Boolean;
30314 -- See RM 6.1.1 for definition of term "known on entry".
30316 --------------------------------------
30317 -- Conditional_Evaluation_Condition --
30318 --------------------------------------
30320 function Conditional_Evaluation_Condition
30321 (Expr
: Node_Id
) return Node_Id
30323 Determiners
: constant Determining_Expression_List
:=
30324 Determining_Expressions
(Expr
);
30325 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
30326 Result
: Node_Id
:=
30327 New_Occurrence_Of
(Standard_True
, Loc
);
30329 pragma Assert
(Determiners
'Length > 0 or else
30330 Is_Anonymous_Access_Type
(Etype
(Expr
)));
30332 for I
in Determiners
'Range loop
30333 Result
:= Make_And_Then
30335 Left_Opnd
=> Result
,
30337 Determining_Condition
(Determiners
(I
)));
30340 end Conditional_Evaluation_Condition
;
30342 ---------------------------
30343 -- Determining_Condition --
30344 ---------------------------
30346 function Determining_Condition
(Det
: Determining_Expr
) return Node_Id
30348 Loc
: constant Source_Ptr
:= Sloc
(Det
.Expr
);
30350 case Det
.Context
is
30351 when Short_Circuit_Op
=>
30352 if Det
.Is_And_Then
then
30353 return New_Copy_Tree
(Det
.Expr
);
30355 return Make_Op_Not
(Loc
, New_Copy_Tree
(Det
.Expr
));
30359 if Det
.Is_Then_Part
then
30360 return New_Copy_Tree
(Det
.Expr
);
30362 return Make_Op_Not
(Loc
, New_Copy_Tree
(Det
.Expr
));
30367 Alts
: List_Id
:= Discrete_Choices
(Det
.Alternatives
);
30369 if Nkind
(First
(Alts
)) = N_Others_Choice
then
30370 Alts
:= Others_Discrete_Choices
(First
(Alts
));
30373 return Make_In
(Loc
,
30374 Left_Opnd
=> New_Copy_Tree
(Det
.Expr
),
30375 Right_Opnd
=> Empty
,
30376 Alternatives
=> New_Copy_List
(Alts
));
30379 when Membership_Test
=>
30381 function Copy_Prefix
30382 (List
: List_Id
; Suffix_Start
: Node_Id
)
30384 -- Given a list and a member of that list, returns
30385 -- a copy (similar to Nlists.New_Copy_List) of the
30386 -- prefix of the list up to but not including
30393 function Copy_Prefix
30394 (List
: List_Id
; Suffix_Start
: Node_Id
)
30397 Result
: constant List_Id
:= New_List
;
30398 Elem
: Node_Id
:= First
(List
);
30400 while Elem
/= Suffix_Start
loop
30401 Append
(New_Copy
(Elem
), Result
);
30403 pragma Assert
(Present
(Elem
));
30409 return Make_In
(Loc
,
30410 Left_Opnd
=> New_Copy_Tree
(Left_Opnd
(Det
.Expr
)),
30411 Right_Opnd
=> Empty
,
30412 Alternatives
=> Copy_Prefix
30413 (Alternatives
(Det
.Expr
),
30414 Det
.First_Non_Preceding
));
30418 raise Program_Error
;
30420 end Determining_Condition
;
30422 -----------------------------
30423 -- Determining_Expressions --
30424 -----------------------------
30426 function Determining_Expressions
30427 (Expr
: Node_Id
; Expr_Trailer
: Node_Id
:= Empty
)
30428 return Determining_Expression_List
30430 Par
: Node_Id
:= Expr
;
30431 Trailer
: Node_Id
:= Expr_Trailer
;
30432 Next_Element
: Determining_Expr
;
30434 -- We want to stop climbing up the tree when we reach the
30435 -- postcondition expression. An aspect_specification is
30436 -- transformed into a pragma, so reaching a pragma is our
30437 -- termination condition. This relies on the fact that
30438 -- pragmas are not allowed in declare expressions (or any
30439 -- other kind of expression).
30442 Next_Element
.Expr
:= Empty
;
30444 case Nkind
(Par
) is
30445 when N_Short_Circuit
=>
30446 if Trailer
= Right_Opnd
(Par
) then
30448 (Expr
=> Left_Opnd
(Par
),
30449 Context
=> Short_Circuit_Op
,
30450 Is_And_Then
=> Nkind
(Par
) = N_And_Then
);
30453 when N_If_Expression
=>
30454 -- For an expression like
30455 -- (if C1 then ... elsif C2 then ... else Foo'Old)
30456 -- the RM says are two determining expressions,
30457 -- C1 and C2. Our treatment here (where we only add
30458 -- one determining expression to the list) is ok because
30459 -- we will see two if-expressions, one within the other.
30461 if Trailer
/= First
(Expressions
(Par
)) then
30463 (Expr
=> First
(Expressions
(Par
)),
30464 Context
=> If_Expr
,
30466 Trailer
= Next
(First
(Expressions
(Par
))));
30469 when N_Case_Expression_Alternative
=>
30470 pragma Assert
(Nkind
(Parent
(Par
)) = N_Case_Expression
);
30473 (Expr
=> Expression
(Parent
(Par
)),
30474 Context
=> Case_Expr
,
30475 Alternatives
=> Par
);
30477 when N_Membership_Test
=>
30478 if Trailer
/= Left_Opnd
(Par
)
30479 and then Is_Non_Empty_List
(Alternatives
(Par
))
30480 and then Trailer
/= First
(Alternatives
(Par
))
30482 pragma Assert
(No
(Right_Opnd
(Par
)));
30484 (Is_List_Member
(Trailer
)
30485 and then List_Containing
(Trailer
)
30486 = Alternatives
(Par
));
30488 -- This one is different than the others
30489 -- because one element in the array result
30490 -- may represent multiple determining
30491 -- expressions (i.e. every member of the list
30492 -- Alternatives (Par)
30493 -- up to but not including Trailer).
30497 Context
=> Membership_Test
,
30498 First_Non_Preceding
=> Trailer
);
30503 Previous
: constant Node_Id
:= Prev
(Par
);
30504 Prev_Expr
: Node_Id
;
30506 if Nkind
(Previous
) = N_Pragma
and then
30507 Split_PPC
(Previous
)
30509 -- A source-level postcondition of
30510 -- A and then B and then C
30512 -- pragma Postcondition (A);
30513 -- pragma Postcondition (B);
30514 -- pragma Postcondition (C);
30515 -- with Split_PPC set to True on all but the
30516 -- last pragma. We account for that here.
30520 (Pragma_Argument_Associations
(Previous
)));
30522 -- This Analyze call is needed in the case when
30523 -- Sem_Attr.Analyze_Attribute calls
30524 -- Eligible_For_Conditional_Evaluation. Without
30525 -- it, we end up passing an unanalyzed expression
30526 -- to Is_Known_On_Entry and that doesn't work.
30528 Analyze
(Prev_Expr
);
30531 (Expr
=> Prev_Expr
,
30532 Context
=> Short_Circuit_Op
,
30533 Is_And_Then
=> True);
30535 return Determining_Expressions
(Prev_Expr
)
30539 (Get_Pragma_Id
(Pragma_Name
(Par
)) in
30541 | Pragma_Contract_Cases
30542 | Pragma_Exceptional_Cases
30544 | Pragma_Postcondition
30545 | Pragma_Post_Class
30546 | Pragma_Refined_Post
);
30548 return (1 .. 0 => <>); -- recursion terminates here
30553 -- This case should be impossible, but if it does
30554 -- happen somehow then we don't want an infinite loop.
30555 raise Program_Error
;
30562 Par
:= Parent
(Par
);
30564 if Present
(Next_Element
.Expr
) then
30565 return Determining_Expressions
30566 (Expr
=> Par
, Expr_Trailer
=> Trailer
)
30570 end Determining_Expressions
;
30572 -----------------------------------------
30573 -- Eligible_For_Conditional_Evaluation --
30574 -----------------------------------------
30576 function Eligible_For_Conditional_Evaluation
30577 (Expr
: Node_Id
) return Boolean
30580 if Is_Anonymous_Access_Type
(Etype
(Expr
)) then
30581 -- The code in exp_attr.adb that also builds declarations
30582 -- for 'Old constants doesn't handle the anonymous access
30583 -- type case correctly, so we avoid that problem by
30584 -- returning True here.
30587 elsif Ada_Version
< Ada_2022
then
30590 elsif Inside_Class_Condition_Preanalysis
then
30591 -- No need to evaluate it during preanalysis of a class-wide
30592 -- pre/postcondition since the expression is not installed yet
30593 -- on its definite context.
30596 elsif not Is_Conditionally_Evaluated
(Expr
) then
30600 Determiners
: constant Determining_Expression_List
:=
30601 Determining_Expressions
(Expr
);
30603 pragma Assert
(Determiners
'Length > 0);
30605 for Idx
in Determiners
'Range loop
30606 if not Is_Known_On_Entry
(Determiners
(Idx
).Expr
) then
30613 end Eligible_For_Conditional_Evaluation
;
30615 --------------------------------
30616 -- Is_Conditionally_Evaluated --
30617 --------------------------------
30619 function Is_Conditionally_Evaluated
(Expr
: Node_Id
) return Boolean
30621 -- There are three possibilities - the expression is
30622 -- unconditionally evaluated, repeatedly evaluated, or
30623 -- conditionally evaluated (see RM 6.1.1). So we implement
30624 -- this test by testing for the other two.
30626 function Is_Repeatedly_Evaluated
(Expr
: Node_Id
) return Boolean;
30627 -- See RM 6.1.1 for definition of "repeatedly evaluated".
30629 -----------------------------
30630 -- Is_Repeatedly_Evaluated --
30631 -----------------------------
30633 function Is_Repeatedly_Evaluated
(Expr
: Node_Id
) return Boolean is
30634 Par
: Node_Id
:= Expr
;
30635 Trailer
: Node_Id
:= Empty
;
30637 -- There are three ways that an expression can be repeatedly
30640 -- An aspect_specification is transformed into a pragma, so
30641 -- reaching a pragma is our termination condition. We want to
30642 -- stop when we reach the postcondition expression.
30644 while Nkind
(Par
) /= N_Pragma
loop
30645 pragma Assert
(Present
(Par
));
30647 -- test for case 1:
30648 -- A subexpression of a predicate of a
30649 -- quantified_expression.
30651 if Nkind
(Par
) = N_Quantified_Expression
30652 and then Trailer
= Condition
(Par
)
30655 elsif Nkind
(Par
) = N_Expression_With_Actions
30657 Nkind
(Original_Node
(Par
)) = N_Quantified_Expression
30662 -- test for cases 2 and 3:
30663 -- A subexpression of the expression of an
30664 -- array_component_association or of
30665 -- a container_element_associatiation.
30667 if Nkind
(Par
) in N_Component_Association
30668 | N_Iterated_Component_Association
30669 and then Trailer
= Expression
(Par
)
30671 -- determine whether Par is part of an array aggregate
30672 -- or a container aggregate
30674 Rover
: Node_Id
:= Par
;
30676 while Nkind
(Rover
) not in N_Has_Etype
loop
30677 pragma Assert
(Present
(Rover
));
30678 Rover
:= Parent
(Rover
);
30680 if Present
(Etype
(Rover
)) then
30681 if Is_Array_Type
(Etype
(Rover
))
30682 or else Is_Container_Aggregate
(Rover
)
30691 Par
:= Parent
(Par
);
30695 end Is_Repeatedly_Evaluated
;
30698 if not Is_Potentially_Unevaluated
(Expr
) then
30699 -- the expression is unconditionally evaluated
30701 elsif Is_Repeatedly_Evaluated
(Expr
) then
30706 end Is_Conditionally_Evaluated
;
30708 -----------------------
30709 -- Is_Known_On_Entry --
30710 -----------------------
30712 function Is_Known_On_Entry
(Expr
: Node_Id
) return Boolean is
30713 -- ??? This implementation is incomplete. See RM 6.1.1
30714 -- for details. In particular, this function *should* return
30715 -- True for a function call (or a user-defined literal, which
30716 -- is equivalent to a function call) if all actual parameters
30717 -- (including defaulted params) are known on entry and the
30718 -- function has "Globals => null" specified; the current
30719 -- implementation will incorrectly return False in this case.
30721 function All_Exps_Known_On_Entry
30722 (Expr_List
: List_Id
) return Boolean;
30723 -- Given a list of expressions, returns False iff
30724 -- Is_Known_On_Entry is False for at least one list element.
30726 -----------------------------
30727 -- All_Exps_Known_On_Entry --
30728 -----------------------------
30730 function All_Exps_Known_On_Entry
30731 (Expr_List
: List_Id
) return Boolean
30733 Expr
: Node_Id
:= First
(Expr_List
);
30735 while Present
(Expr
) loop
30736 if not Is_Known_On_Entry
(Expr
) then
30742 end All_Exps_Known_On_Entry
;
30745 if Is_Static_Expression
(Expr
) then
30749 if Is_Attribute_Old
(Expr
) then
30754 Pref
: Node_Id
:= Expr
;
30757 case Nkind
(Pref
) is
30758 when N_Selected_Component
=>
30761 when N_Indexed_Component
=>
30762 if not All_Exps_Known_On_Entry
(Expressions
(Pref
))
30768 return False; -- just to be clear about this case
30774 Pref
:= Prefix
(Pref
);
30777 if Is_Entity_Name
(Pref
)
30778 and then Is_Constant_Object
(Entity
(Pref
))
30781 Obj
: constant Entity_Id
:= Entity
(Pref
);
30782 Obj_Typ
: constant Entity_Id
:= Etype
(Obj
);
30784 case Ekind
(Obj
) is
30785 when E_In_Parameter
=>
30786 if not Is_Elementary_Type
(Obj_Typ
) then
30788 elsif Is_Aliased
(Obj
) then
30793 -- return False for a deferred constant
30794 if Present
(Full_View
(Obj
)) then
30798 -- return False if not "all views are constant".
30799 if Is_Immutably_Limited_Type
(Obj_Typ
)
30800 or Needs_Finalization
(Obj_Typ
)
30813 -- ??? Cope with a malformed tree. Code to cope with a
30814 -- nonstatic use of an enumeration literal should not be
30816 if Is_Entity_Name
(Pref
)
30817 and then Ekind
(Entity
(Pref
)) = E_Enumeration_Literal
30823 case Nkind
(Expr
) is
30825 return Is_Known_On_Entry
(Right_Opnd
(Expr
));
30827 when N_Binary_Op
=>
30828 return Is_Known_On_Entry
(Left_Opnd
(Expr
))
30829 and then Is_Known_On_Entry
(Right_Opnd
(Expr
));
30831 when N_Type_Conversion | N_Qualified_Expression
=>
30832 return Is_Known_On_Entry
(Expression
(Expr
));
30834 when N_If_Expression
=>
30835 if not All_Exps_Known_On_Entry
(Expressions
(Expr
)) then
30839 when N_Case_Expression
=>
30840 if not Is_Known_On_Entry
(Expression
(Expr
)) then
30845 Alt
: Node_Id
:= First
(Alternatives
(Expr
));
30847 while Present
(Alt
) loop
30848 if not Is_Known_On_Entry
(Expression
(Alt
)) then
30862 end Is_Known_On_Entry
;
30864 end Conditional_Evaluation
;
30866 package body Indirect_Temps
is
30868 Indirect_Temp_Access_Type_Char
: constant Character := 'K';
30869 -- The character passed to Make_Temporary when declaring
30870 -- the access type that is used in the implementation of an
30871 -- indirect temporary.
30873 --------------------------
30874 -- Indirect_Temp_Needed --
30875 --------------------------
30877 function Indirect_Temp_Needed
(Typ
: Entity_Id
) return Boolean is
30879 -- There should be no correctness issues if the only cases where
30880 -- this function returns False are cases where Typ is an
30881 -- anonymous access type and we need to generate a saooaaat (a
30882 -- stand-alone object of an anonymous access type) in order get
30883 -- accessibility right. In other cases where this function
30884 -- returns False, there would be no correctness problems with
30885 -- returning True instead; however, returning False when we can
30886 -- generally results in simpler code.
30890 -- If Typ is not definite, then we cannot generate
30893 or else not Is_Definite_Subtype
(Typ
)
30895 -- If Typ is tagged, then generating
30897 -- might generate an object with the wrong tag. If we had
30898 -- a predicate that indicated whether the nominal tag is
30899 -- trustworthy, we could use that predicate here.
30901 or else Is_Tagged_Type
(Typ
)
30903 -- If Typ needs finalization, then generating an implicit
30905 -- declaration could have user-visible side effects.
30907 or else Needs_Finalization
(Typ
)
30909 -- In the anonymous access type case, we need to
30910 -- generate a saooaaat. We don't want the code in
30911 -- in exp_attr.adb that deals with the case where this
30912 -- function returns False to have to deal with that case
30913 -- (just to avoid code duplication). So we cheat a little
30914 -- bit and return True here for an anonymous access type.
30916 or else Is_Anonymous_Access_Type
(Typ
);
30918 -- ??? Unimplemented - spec description says:
30919 -- For an unconstrained-but-definite discriminated subtype,
30920 -- returns True if the potential difference in size between an
30921 -- unconstrained object and a constrained object is large.
30924 -- type Typ (Len : Natural := 0) is
30925 -- record F : String (1 .. Len); end record;
30927 -- See Large_Max_Size_Mutable function elsewhere in this file,
30928 -- currently declared inside of Needs_Secondary_Stack, so it
30929 -- would have to be moved if we want it to be callable from here.
30931 end Indirect_Temp_Needed
;
30933 ---------------------------
30934 -- Declare_Indirect_Temp --
30935 ---------------------------
30937 procedure Declare_Indirect_Temp
30938 (Attr_Prefix
: Node_Id
; Indirect_Temp
: out Entity_Id
)
30940 Loc
: constant Source_Ptr
:= Sloc
(Attr_Prefix
);
30941 Prefix_Type
: constant Entity_Id
:= Etype
(Attr_Prefix
);
30942 Temp_Id
: constant Entity_Id
:=
30943 Make_Temporary
(Loc
, 'P', Attr_Prefix
);
30945 procedure Declare_Indirect_Temp_Via_Allocation
;
30946 -- Handle the usual case.
30948 -------------------------------------------
30949 -- Declare_Indirect_Temp_Via_Allocation --
30950 -------------------------------------------
30952 procedure Declare_Indirect_Temp_Via_Allocation
is
30953 Access_Type_Id
: constant Entity_Id
30955 (Loc
, Indirect_Temp_Access_Type_Char
, Attr_Prefix
);
30957 Temp_Decl
: constant Node_Id
:=
30958 Make_Object_Declaration
(Loc
,
30959 Defining_Identifier
=> Temp_Id
,
30960 Object_Definition
=>
30961 New_Occurrence_Of
(Access_Type_Id
, Loc
));
30963 Allocate_Class_Wide
: constant Boolean :=
30964 Is_Specific_Tagged_Type
(Prefix_Type
);
30965 -- If True then access type designates the class-wide type in
30966 -- order to preserve (at run time) the value of the underlying
30968 -- ??? We could do better here (in the case where Prefix_Type
30969 -- is tagged and specific) if we had a predicate which takes an
30970 -- expression and returns True iff the expression is of
30971 -- a specific tagged type and the underlying tag (at run time)
30972 -- is statically known to match that of the specific type.
30973 -- In that case, Allocate_Class_Wide could safely be False.
30975 function Designated_Subtype_Mark
return Node_Id
;
30976 -- Usually, a subtype mark indicating the subtype of the
30977 -- attribute prefix. If that subtype is a specific tagged
30978 -- type, then returns the corresponding class-wide type.
30979 -- If the prefix is of an anonymous access type, then returns
30980 -- the designated type of that type.
30982 -----------------------------
30983 -- Designated_Subtype_Mark --
30984 -----------------------------
30986 function Designated_Subtype_Mark
return Node_Id
is
30987 Typ
: Entity_Id
:= Prefix_Type
;
30989 if Allocate_Class_Wide
then
30990 if Is_Private_Type
(Typ
)
30991 and then Present
(Full_View
(Typ
))
30993 Typ
:= Full_View
(Typ
);
30995 Typ
:= Class_Wide_Type
(Typ
);
30998 return New_Occurrence_Of
(Typ
, Loc
);
30999 end Designated_Subtype_Mark
;
31001 Access_Type_Def
: constant Node_Id
31002 := Make_Access_To_Object_Definition
31003 (Loc
, Subtype_Indication
=> Designated_Subtype_Mark
);
31005 Access_Type_Decl
: constant Node_Id
31006 := Make_Full_Type_Declaration
31007 (Loc
, Access_Type_Id
,
31008 Type_Definition
=> Access_Type_Def
);
31010 Mutate_Ekind
(Temp_Id
, E_Variable
);
31011 Set_Etype
(Temp_Id
, Access_Type_Id
);
31012 Mutate_Ekind
(Access_Type_Id
, E_Access_Type
);
31014 if Append_Decls_In_Reverse_Order
then
31015 Append_Item
(Temp_Decl
, Is_Eval_Stmt
=> False);
31016 Append_Item
(Access_Type_Decl
, Is_Eval_Stmt
=> False);
31018 Append_Item
(Access_Type_Decl
, Is_Eval_Stmt
=> False);
31019 Append_Item
(Temp_Decl
, Is_Eval_Stmt
=> False);
31022 -- When a type associated with an indirect temporary gets
31023 -- created for a 'Old attribute reference we need to mark
31024 -- the type as such. This allows, for example, finalization
31025 -- masters associated with them to be finalized in the correct
31026 -- order after postcondition checks.
31028 if Attribute_Name
(Parent
(Attr_Prefix
)) = Name_Old
then
31029 Set_Stores_Attribute_Old_Prefix
(Access_Type_Id
);
31032 Analyze
(Access_Type_Decl
);
31033 Analyze
(Temp_Decl
);
31036 (Is_Access_Type_For_Indirect_Temp
(Access_Type_Id
));
31039 Expression
: Node_Id
:= Attr_Prefix
;
31040 Allocator
: Node_Id
;
31042 if Allocate_Class_Wide
then
31043 -- generate T'Class'(T'Class (<prefix>))
31045 Make_Type_Conversion
(Loc
,
31046 Subtype_Mark
=> Designated_Subtype_Mark
,
31047 Expression
=> Expression
);
31051 Make_Allocator
(Loc
,
31052 Make_Qualified_Expression
31054 Subtype_Mark
=> Designated_Subtype_Mark
,
31055 Expression
=> Expression
));
31057 -- Allocate saved prefix value on the secondary stack
31058 -- in order to avoid introducing a storage leak. This
31059 -- allocated object is never explicitly reclaimed.
31061 -- ??? Emit storage leak warning if RE_SS_Pool
31064 if RTE_Available
(RE_SS_Pool
) then
31065 Set_Storage_Pool
(Allocator
, RTE
(RE_SS_Pool
));
31066 Set_Procedure_To_Call
31067 (Allocator
, RTE
(RE_SS_Allocate
));
31068 Set_Uses_Sec_Stack
(Current_Scope
);
31072 (Make_Assignment_Statement
(Loc
,
31073 Name
=> New_Occurrence_Of
(Temp_Id
, Loc
),
31074 Expression
=> Allocator
),
31075 Is_Eval_Stmt
=> True);
31077 end Declare_Indirect_Temp_Via_Allocation
;
31080 Indirect_Temp
:= Temp_Id
;
31082 if Is_Anonymous_Access_Type
(Prefix_Type
) then
31083 -- In the anonymous access type case, we do not want a level
31084 -- indirection (which would result in declaring an
31085 -- access-to-access type); that would result in correctness
31086 -- problems - the accessibility level of the type of the
31087 -- 'Old constant would be wrong (See 6.1.1.). So in that case,
31088 -- we do not generate an allocator. Instead we generate
31089 -- Temp : access Designated := null;
31090 -- which is unconditionally elaborated and then
31091 -- Temp := <attribute prefix>;
31092 -- which is conditionally executed.
31095 Temp_Decl
: constant Node_Id
:=
31096 Make_Object_Declaration
(Loc
,
31097 Defining_Identifier
=> Temp_Id
,
31098 Object_Definition
=>
31099 Make_Access_Definition
31101 Constant_Present
=>
31102 Is_Access_Constant
(Prefix_Type
),
31105 (Designated_Type
(Prefix_Type
), Loc
)));
31107 Append_Item
(Temp_Decl
, Is_Eval_Stmt
=> False);
31108 Analyze
(Temp_Decl
);
31110 (Make_Assignment_Statement
(Loc
,
31111 Name
=> New_Occurrence_Of
(Temp_Id
, Loc
),
31112 Expression
=> Attr_Prefix
),
31113 Is_Eval_Stmt
=> True);
31117 Declare_Indirect_Temp_Via_Allocation
;
31119 end Declare_Indirect_Temp
;
31121 -------------------------
31122 -- Indirect_Temp_Value --
31123 -------------------------
31125 function Indirect_Temp_Value
31128 Loc
: Source_Ptr
) return Node_Id
31132 if Is_Anonymous_Access_Type
(Typ
) then
31133 -- No indirection in this case; just evaluate the temp.
31134 Result
:= New_Occurrence_Of
(Temp
, Loc
);
31135 Set_Etype
(Result
, Etype
(Temp
));
31138 Result
:= Make_Explicit_Dereference
(Loc
,
31139 New_Occurrence_Of
(Temp
, Loc
));
31141 Set_Etype
(Result
, Designated_Type
(Etype
(Temp
)));
31143 if Is_Specific_Tagged_Type
(Typ
) then
31144 -- The designated type of the access type is class-wide, so
31145 -- convert to the specific type.
31148 Make_Type_Conversion
(Loc
,
31149 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
31150 Expression
=> Result
);
31152 Set_Etype
(Result
, Typ
);
31157 end Indirect_Temp_Value
;
31159 function Is_Access_Type_For_Indirect_Temp
31160 (T
: Entity_Id
) return Boolean is
31162 if Is_Access_Type
(T
)
31163 and then not Comes_From_Source
(T
)
31164 and then Is_Internal_Name
(Chars
(T
))
31165 and then Nkind
(Scope
(T
)) in N_Entity
31166 and then Ekind
(Scope
(T
))
31167 in E_Entry | E_Entry_Family | E_Function | E_Procedure
31169 (Present
(Wrapped_Statements
(Scope
(T
)))
31170 or else Present
(Contract
(Scope
(T
))))
31172 -- ??? Should define a flag for this. We could incorrectly
31173 -- return True if other clients of Make_Temporary happen to
31174 -- pass in the same character.
31176 Name
: constant String := Get_Name_String
(Chars
(T
));
31178 if Name
(Name
'First) = Indirect_Temp_Access_Type_Char
then
31185 end Is_Access_Type_For_Indirect_Temp
;
31187 end Indirect_Temps
;
31190 package body Storage_Model_Support
is
31192 -----------------------------------------
31193 -- Has_Designated_Storage_Model_Aspect --
31194 -----------------------------------------
31196 function Has_Designated_Storage_Model_Aspect
31197 (Typ
: Entity_Id
) return Boolean
31200 return Has_Aspect
(Typ
, Aspect_Designated_Storage_Model
);
31201 end Has_Designated_Storage_Model_Aspect
;
31203 -----------------------------------
31204 -- Has_Storage_Model_Type_Aspect --
31205 -----------------------------------
31207 function Has_Storage_Model_Type_Aspect
(Typ
: Entity_Id
) return Boolean
31210 return Has_Aspect
(Typ
, Aspect_Storage_Model_Type
);
31211 end Has_Storage_Model_Type_Aspect
;
31213 --------------------------
31214 -- Storage_Model_Object --
31215 --------------------------
31217 function Storage_Model_Object
(Typ
: Entity_Id
) return Entity_Id
is
31219 pragma Assert
(Has_Designated_Storage_Model_Aspect
(Typ
));
31223 (Find_Value_Of_Aspect
(Typ
, Aspect_Designated_Storage_Model
));
31224 end Storage_Model_Object
;
31226 ------------------------
31227 -- Storage_Model_Type --
31228 ------------------------
31230 function Storage_Model_Type
(Obj
: Entity_Id
) return Entity_Id
is
31232 pragma Assert
(Has_Storage_Model_Type_Aspect
(Etype
(Obj
)));
31234 return Etype
(Obj
);
31235 end Storage_Model_Type
;
31237 -----------------------------------
31238 -- Get_Storage_Model_Type_Entity --
31239 -----------------------------------
31241 function Get_Storage_Model_Type_Entity
31242 (SM_Obj_Or_Type
: Entity_Id
;
31243 Nam
: Name_Id
) return Entity_Id
31245 Typ
: constant Entity_Id
:= (if Is_Object
(SM_Obj_Or_Type
) then
31246 Storage_Model_Type
(SM_Obj_Or_Type
)
31252 Nam
in Name_Address_Type
31253 | Name_Null_Address
31258 | Name_Storage_Size
);
31261 SMT_Aspect_Value
: constant Node_Id
:=
31262 Find_Value_Of_Aspect
(Typ
, Aspect_Storage_Model_Type
);
31265 -- When the aspect has an aggregate expression, search through it
31266 -- to locate a match for the name of the given "subaspect" and return
31267 -- the entity of the aggregate association's expression.
31269 if Present
(SMT_Aspect_Value
) then
31270 Assoc
:= First
(Component_Associations
(SMT_Aspect_Value
));
31271 while Present
(Assoc
) loop
31272 if Chars
(First
(Choices
(Assoc
))) = Nam
then
31273 return Entity
(Expression
(Assoc
));
31280 -- The aggregate argument of Storage_Model_Type is optional, and when
31281 -- not present the aspect defaults to the native storage model, where
31282 -- the address type is System.Address. In that case, we return
31283 -- System.Address for Name_Address_Type and System.Null_Address for
31284 -- Name_Null_Address, but return Empty for other cases, and leave it
31285 -- to the back end to map those to the appropriate native operations.
31287 if Nam
= Name_Address_Type
then
31288 return RTE
(RE_Address
);
31290 elsif Nam
= Name_Null_Address
then
31291 return RTE
(RE_Null_Address
);
31296 end Get_Storage_Model_Type_Entity
;
31298 --------------------------------
31299 -- Storage_Model_Address_Type --
31300 --------------------------------
31302 function Storage_Model_Address_Type
31303 (SM_Obj_Or_Type
: Entity_Id
) return Entity_Id
31307 Get_Storage_Model_Type_Entity
(SM_Obj_Or_Type
, Name_Address_Type
);
31308 end Storage_Model_Address_Type
;
31310 --------------------------------
31311 -- Storage_Model_Null_Address --
31312 --------------------------------
31314 function Storage_Model_Null_Address
31315 (SM_Obj_Or_Type
: Entity_Id
) return Entity_Id
31319 Get_Storage_Model_Type_Entity
(SM_Obj_Or_Type
, Name_Null_Address
);
31320 end Storage_Model_Null_Address
;
31322 ----------------------------
31323 -- Storage_Model_Allocate --
31324 ----------------------------
31326 function Storage_Model_Allocate
31327 (SM_Obj_Or_Type
: Entity_Id
) return Entity_Id
31330 return Get_Storage_Model_Type_Entity
(SM_Obj_Or_Type
, Name_Allocate
);
31331 end Storage_Model_Allocate
;
31333 ------------------------------
31334 -- Storage_Model_Deallocate --
31335 ------------------------------
31337 function Storage_Model_Deallocate
31338 (SM_Obj_Or_Type
: Entity_Id
) return Entity_Id
31342 Get_Storage_Model_Type_Entity
(SM_Obj_Or_Type
, Name_Deallocate
);
31343 end Storage_Model_Deallocate
;
31345 -----------------------------
31346 -- Storage_Model_Copy_From --
31347 -----------------------------
31349 function Storage_Model_Copy_From
31350 (SM_Obj_Or_Type
: Entity_Id
) return Entity_Id
31353 return Get_Storage_Model_Type_Entity
(SM_Obj_Or_Type
, Name_Copy_From
);
31354 end Storage_Model_Copy_From
;
31356 ---------------------------
31357 -- Storage_Model_Copy_To --
31358 ---------------------------
31360 function Storage_Model_Copy_To
31361 (SM_Obj_Or_Type
: Entity_Id
) return Entity_Id
31364 return Get_Storage_Model_Type_Entity
(SM_Obj_Or_Type
, Name_Copy_To
);
31365 end Storage_Model_Copy_To
;
31367 --------------------------------
31368 -- Storage_Model_Storage_Size --
31369 --------------------------------
31371 function Storage_Model_Storage_Size
31372 (SM_Obj_Or_Type
: Entity_Id
) return Entity_Id
31376 Get_Storage_Model_Type_Entity
(SM_Obj_Or_Type
, Name_Storage_Size
);
31377 end Storage_Model_Storage_Size
;
31379 end Storage_Model_Support
;
31382 Erroutc
.Subprogram_Name_Ptr
:= Subprogram_Name
'Access;