1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, 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 Aspects
; use Aspects
;
28 with Atree
; use Atree
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Debug_A
; use Debug_A
;
32 with Einfo
; use Einfo
;
33 with Einfo
.Entities
; use Einfo
.Entities
;
34 with Einfo
.Utils
; use Einfo
.Utils
;
35 with Elists
; use Elists
;
36 with Errout
; use Errout
;
37 with Expander
; use Expander
;
38 with Exp_Ch6
; use Exp_Ch6
;
39 with Exp_Ch7
; use Exp_Ch7
;
40 with Exp_Disp
; use Exp_Disp
;
41 with Exp_Tss
; use Exp_Tss
;
42 with Exp_Util
; use Exp_Util
;
43 with Freeze
; use Freeze
;
44 with Ghost
; use Ghost
;
45 with Inline
; use Inline
;
46 with Itypes
; use Itypes
;
48 with Lib
.Xref
; use Lib
.Xref
;
50 with Mutably_Tagged
; use Mutably_Tagged
;
51 with Namet
; use Namet
;
52 with Nmake
; use Nmake
;
53 with Nlists
; use Nlists
;
55 with Output
; use Output
;
56 with Par_SCO
; use Par_SCO
;
57 with Restrict
; use Restrict
;
58 with Rident
; use Rident
;
59 with Rtsfind
; use Rtsfind
;
61 with Sem_Aggr
; use Sem_Aggr
;
62 with Sem_Attr
; use Sem_Attr
;
63 with Sem_Aux
; use Sem_Aux
;
64 with Sem_Case
; use Sem_Case
;
65 with Sem_Cat
; use Sem_Cat
;
66 with Sem_Ch3
; use Sem_Ch3
;
67 with Sem_Ch4
; use Sem_Ch4
;
68 with Sem_Ch5
; use Sem_Ch5
;
69 with Sem_Ch6
; use Sem_Ch6
;
70 with Sem_Ch8
; use Sem_Ch8
;
71 with Sem_Ch13
; use Sem_Ch13
;
72 with Sem_Dim
; use Sem_Dim
;
73 with Sem_Disp
; use Sem_Disp
;
74 with Sem_Dist
; use Sem_Dist
;
75 with Sem_Elab
; use Sem_Elab
;
76 with Sem_Elim
; use Sem_Elim
;
77 with Sem_Eval
; use Sem_Eval
;
78 with Sem_Intr
; use Sem_Intr
;
79 with Sem_Mech
; use Sem_Mech
;
80 with Sem_Type
; use Sem_Type
;
81 with Sem_Util
; use Sem_Util
;
82 with Sem_Warn
; use Sem_Warn
;
83 with Sinfo
; use Sinfo
;
84 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
85 with Sinfo
.Utils
; use Sinfo
.Utils
;
86 with Sinfo
.CN
; use Sinfo
.CN
;
87 with Sinput
; use Sinput
;
88 with Snames
; use Snames
;
89 with Stand
; use Stand
;
90 with Stringt
; use Stringt
;
91 with Strub
; use Strub
;
92 with Style
; use Style
;
93 with Targparm
; use Targparm
;
94 with Tbuild
; use Tbuild
;
95 with Uintp
; use Uintp
;
96 with Urealp
; use Urealp
;
97 with Warnsw
; use Warnsw
;
99 package body Sem_Res
is
101 -----------------------
102 -- Local Subprograms --
103 -----------------------
105 -- Second pass (top-down) type checking and overload resolution procedures
106 -- Typ is the type required by context. These procedures propagate the
107 -- type information recursively to the descendants of N. If the node is not
108 -- overloaded, its Etype is established in the first pass. If overloaded,
109 -- the Resolve routines set the correct type. For arithmetic operators, the
110 -- Etype is the base type of the context.
112 -- Note that Resolve_Attribute is separated off in Sem_Attr
114 function Has_Applicable_User_Defined_Literal
116 Typ
: Entity_Id
) return Boolean;
117 -- Check whether N is a literal or a named number, and whether Typ has a
118 -- user-defined literal aspect that may apply to N. In this case, replace
119 -- N with a call to the corresponding function and return True.
121 procedure Check_Discriminant_Use
(N
: Node_Id
);
122 -- Enforce the restrictions on the use of discriminants when constraining
123 -- a component of a discriminated type (record or concurrent type).
125 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
);
126 -- Given a node for an operator associated with type T, check that the
127 -- operator is visible. Operators all of whose operands are universal must
128 -- be checked for visibility during resolution because their type is not
129 -- determinable based on their operands.
131 procedure Check_Fully_Declared_Prefix
134 -- Check that the type of the prefix of a dereference is not incomplete
136 function Check_Infinite_Recursion
(Call
: Node_Id
) return Boolean;
137 -- Given a call node, Call, which is known to occur immediately within the
138 -- subprogram being called, determines whether it is a detectable case of
139 -- an infinite recursion, and if so, outputs appropriate messages. Returns
140 -- True if an infinite recursion is detected, and False otherwise.
142 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
);
143 -- N is the node for a logical operator. If the operator is predefined, and
144 -- the root type of the operands is Standard.Boolean, then a check is made
145 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
146 -- the style check for Style_Check_Boolean_And_Or.
148 function Is_Atomic_Non_VFA_Ref_With_Address
(N
: Node_Id
) return Boolean;
149 -- N is either an indexed component or a selected component. Return true
150 -- if the prefix denotes an Atomic but not Volatile_Full_Access object that
151 -- has an address clause (the case in which we may want to give a warning).
153 function Is_Definite_Access_Type
(E
: N_Entity_Id
) return Boolean;
154 -- Determine whether E is an access type declared by an access declaration,
155 -- and not an (anonymous) allocator type.
157 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean;
158 -- Utility to check whether the entity for an operator is a predefined
159 -- operator, in which case the expression is left as an operator in the
160 -- tree (else it is rewritten into a call). An instance of an intrinsic
161 -- conversion operation may be given an operator name, but is not treated
162 -- like an operator. Note that an operator that is an imported back-end
163 -- builtin has convention Intrinsic, but is expected to be rewritten into
164 -- a call, so such an operator is not treated as predefined by this
167 function Original_Implementation_Base_Type
168 (Id
: Entity_Id
) return Entity_Id
;
169 -- Like Implementation_Base_Type, but looks at Original_Node.
171 procedure Preanalyze_And_Resolve
174 With_Freezing
: Boolean);
175 -- Subsidiary of public versions of Preanalyze_And_Resolve.
177 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
);
178 -- If a default expression in entry call N depends on the discriminants
179 -- of the task, it must be replaced with a reference to the discriminant
180 -- of the task being called.
182 procedure Resolve_Dependent_Expression
186 -- Internal procedure to resolve the dependent expression Expr of the
187 -- conditional expression N with type Typ.
189 procedure Resolve_Op_Concat_Arg
194 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
195 -- concatenation operator. The operand is either of the array type or of
196 -- the component type. If the operand is an aggregate, and the component
197 -- type is composite, this is ambiguous if component type has aggregates.
199 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
);
200 -- Does the first part of the work of Resolve_Op_Concat
202 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
);
203 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
204 -- has been resolved. See Resolve_Op_Concat for details.
206 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
);
207 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
);
208 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
);
209 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
210 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
211 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
);
212 procedure Resolve_Declare_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
213 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
);
214 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
);
215 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
);
216 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
);
217 procedure Resolve_External_Initializer
(N
: Node_Id
; Typ
: Entity_Id
);
218 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
219 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
);
220 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
);
221 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
222 procedure Resolve_Interpolated_String_Literal
225 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
);
226 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
);
227 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
);
228 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
);
229 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
);
230 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
);
231 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
);
232 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
233 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
234 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
);
235 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
236 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
);
237 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
);
238 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
);
239 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
);
240 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
);
241 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
242 procedure Resolve_Target_Name
(N
: Node_Id
; Typ
: Entity_Id
);
243 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
244 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
);
245 procedure Resolve_Unchecked_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
246 procedure Resolve_Unchecked_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
248 function Operator_Kind
250 Is_Binary
: Boolean) return Node_Kind
;
251 -- Utility to map the name of an operator into the corresponding Node. Used
252 -- by other node rewriting procedures.
254 procedure Resolve_Actuals
(N
: Node_Id
; Nam
: Entity_Id
);
255 -- Resolve actuals of call, and add default expressions for missing ones.
256 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
257 -- called subprogram.
259 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
);
260 -- Called from Resolve_Call, when the prefix denotes an entry or element
261 -- of entry family. Actuals are resolved as for subprograms, and the node
262 -- is rebuilt as an entry call. Also called for protected operations. Typ
263 -- is the context type, which is used when the operation is a protected
264 -- function with no arguments, and the return value is indexed.
266 procedure Resolve_Implicit_Dereference
(P
: Node_Id
);
267 -- Called when P is the prefix of an indexed component, or of a selected
268 -- component, or of a slice. If P is of an access type, we unconditionally
269 -- rewrite it as an explicit dereference. This ensures that the expander
270 -- and the code generator have a fully explicit tree to work with.
272 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
273 -- A call to a user-defined intrinsic operator is rewritten as a call to
274 -- the corresponding predefined operator, with suitable conversions. Note
275 -- that this applies only for intrinsic operators that denote predefined
276 -- operators, not ones that are intrinsic imports of back-end builtins.
278 procedure Resolve_Intrinsic_Unary_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
279 -- Ditto, for arithmetic unary operators
281 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
);
282 -- If an operator node resolves to a call to a user-defined operator,
283 -- rewrite the node as a function call.
285 procedure Make_Call_Into_Operator
289 -- Inverse transformation: if an operator is given in functional notation,
290 -- then after resolving the node, transform into an operator node, so that
291 -- operands are resolved properly. Recall that predefined operators do not
292 -- have a full signature and special resolution rules apply.
294 procedure Rewrite_Renamed_Operator
298 -- An operator can rename another, e.g. in an instantiation. In that
299 -- case, the proper operator node must be constructed and resolved.
301 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
);
302 -- The String_Literal_Subtype is built for all strings that are not
303 -- operands of a static concatenation operation. It is also built for
304 -- expressions generated by the expansion of the External_Initialization
305 -- aspect. If the argument is not an N_String_Literal node or an
306 -- N_External_Initializer node, then the call has no effect.
308 procedure Set_Slice_Subtype
(N
: Node_Id
);
309 -- Build subtype of array type, with the range specified by the slice
311 procedure Simplify_Type_Conversion
(N
: Node_Id
);
312 -- Called after N has been resolved and evaluated, but before range checks
313 -- have been applied. This rewrites the conversion into a simpler form.
315 function Try_User_Defined_Literal
317 Typ
: Entity_Id
) return Boolean;
318 -- If the node is a literal or a named number or a conditional expression
319 -- whose dependent expressions are all literals or named numbers, and the
320 -- context type has a user-defined literal aspect, then rewrite the node
321 -- or its leaf nodes as calls to the corresponding function, which plays
322 -- the role of an implicit conversion.
324 function Try_User_Defined_Literal_For_Operator
326 Typ
: Entity_Id
) return Boolean;
327 -- If an operator node has a literal operand, check whether the type of the
328 -- context, or that of the other operand has a user-defined literal aspect
329 -- that can be applied to the literal to resolve the node. If such aspect
330 -- exists, replace literal with a call to the corresponding function and
331 -- return True, return false otherwise.
333 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
;
334 -- A universal_fixed expression in an universal context is unambiguous if
335 -- there is only one applicable fixed point type. Determining whether there
336 -- is only one requires a search over all visible entities, and happens
337 -- only in very pathological cases (see 6115-006).
339 -------------------------
340 -- Ambiguous_Character --
341 -------------------------
343 procedure Ambiguous_Character
(C
: Node_Id
) is
347 if Nkind
(C
) = N_Character_Literal
then
348 Error_Msg_N
("ambiguous character literal", C
);
350 -- First the ones in Standard
352 Error_Msg_N
("\\possible interpretation: Character!", C
);
353 Error_Msg_N
("\\possible interpretation: Wide_Character!", C
);
355 -- Include Wide_Wide_Character in Ada 2005 mode
357 if Ada_Version
>= Ada_2005
then
358 Error_Msg_N
("\\possible interpretation: Wide_Wide_Character!", C
);
361 -- Now any other types that match
363 E
:= Current_Entity
(C
);
364 while Present
(E
) loop
365 Error_Msg_NE
("\\possible interpretation:}!", C
, Etype
(E
));
369 end Ambiguous_Character
;
371 -------------------------
372 -- Analyze_And_Resolve --
373 -------------------------
375 procedure Analyze_And_Resolve
(N
: Node_Id
) is
379 end Analyze_And_Resolve
;
381 procedure Analyze_And_Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
385 end Analyze_And_Resolve
;
387 -- Versions with check(s) suppressed
389 procedure Analyze_And_Resolve
394 Scop
: constant Entity_Id
:= Current_Scope
;
397 if Suppress
= All_Checks
then
399 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
401 Scope_Suppress
.Suppress
:= (others => True);
402 Analyze_And_Resolve
(N
, Typ
);
403 Scope_Suppress
.Suppress
:= Sva
;
408 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
410 Scope_Suppress
.Suppress
(Suppress
) := True;
411 Analyze_And_Resolve
(N
, Typ
);
412 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
416 if Current_Scope
/= Scop
417 and then Scope_Is_Transient
419 -- This can only happen if a transient scope was created for an inner
420 -- expression, which will be removed upon completion of the analysis
421 -- of an enclosing construct. The transient scope must have the
422 -- suppress status of the enclosing environment, not of this Analyze
425 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
428 end Analyze_And_Resolve
;
430 procedure Analyze_And_Resolve
434 Scop
: constant Entity_Id
:= Current_Scope
;
437 if Suppress
= All_Checks
then
439 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
441 Scope_Suppress
.Suppress
:= (others => True);
442 Analyze_And_Resolve
(N
);
443 Scope_Suppress
.Suppress
:= Sva
;
448 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
450 Scope_Suppress
.Suppress
(Suppress
) := True;
451 Analyze_And_Resolve
(N
);
452 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
456 if Current_Scope
/= Scop
and then Scope_Is_Transient
then
457 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
460 end Analyze_And_Resolve
;
462 -------------------------------------
463 -- Has_Applicable_User_Defined_Literal --
464 -------------------------------------
466 function Has_Applicable_User_Defined_Literal
468 Typ
: Entity_Id
) return Boolean
470 Loc
: constant Source_Ptr
:= Sloc
(N
);
472 constant array (N_Numeric_Or_String_Literal
) of Aspect_Id
:=
473 (N_Integer_Literal
=> Aspect_Integer_Literal
,
474 N_Interpolated_String_Literal
=> Aspect_String_Literal
,
475 N_Real_Literal
=> Aspect_Real_Literal
,
476 N_String_Literal
=> Aspect_String_Literal
);
478 Named_Number_Aspect_Map
: constant array (Named_Kind
) of Aspect_Id
:=
479 (E_Named_Integer
=> Aspect_Integer_Literal
,
480 E_Named_Real
=> Aspect_Real_Literal
);
482 Lit_Aspect
: Aspect_Id
;
493 if (Nkind
(N
) in N_Numeric_Or_String_Literal
494 | N_Interpolated_String_Literal
496 (Find_Aspect
(Typ
, Literal_Aspect_Map
(Nkind
(N
)))))
498 (Nkind
(N
) = N_Identifier
499 and then Is_Named_Number
(Entity
(N
))
503 (Typ
, Named_Number_Aspect_Map
(Ekind
(Entity
(N
))))))
506 (if Nkind
(N
) = N_Identifier
507 then Named_Number_Aspect_Map
(Ekind
(Entity
(N
)))
508 else Literal_Aspect_Map
(Nkind
(N
)));
510 Entity
(Expression
(Find_Aspect
(Typ
, Lit_Aspect
)));
511 Name
:= Make_Identifier
(Loc
, Chars
(Callee
));
513 if Is_Derived_Type
(Typ
)
514 and then Base_Type
(Etype
(Callee
)) /= Base_Type
(Typ
)
517 Corresponding_Primitive_Op
518 (Ancestor_Op
=> Callee
,
519 Descendant_Type
=> Base_Type
(Typ
));
522 -- Handle an identifier that denotes a named number.
524 if Nkind
(N
) = N_Identifier
then
525 Expr
:= Expression
(Declaration_Node
(Entity
(N
)));
527 if Ekind
(Entity
(N
)) = E_Named_Integer
then
528 UI_Image
(Expr_Value
(Expr
), Decimal
);
531 (UI_Image_Buffer
(1 .. UI_Image_Length
));
532 Param1
:= Make_String_Literal
(Loc
, End_String
);
533 Params
:= New_List
(Param1
);
536 UI_Image
(Norm_Num
(Expr_Value_R
(Expr
)), Decimal
);
539 if UR_Is_Negative
(Expr_Value_R
(Expr
)) then
540 Store_String_Chars
("-");
544 (UI_Image_Buffer
(1 .. UI_Image_Length
));
545 Param1
:= Make_String_Literal
(Loc
, End_String
);
547 -- Note: Set_Etype is called below on Param1
549 UI_Image
(Norm_Den
(Expr_Value_R
(Expr
)), Decimal
);
552 (UI_Image_Buffer
(1 .. UI_Image_Length
));
553 Param2
:= Make_String_Literal
(Loc
, End_String
);
554 Set_Etype
(Param2
, Standard_String
);
556 Params
:= New_List
(Param1
, Param2
);
558 if Present
(Related_Expression
(Callee
)) then
559 Callee
:= Related_Expression
(Callee
);
562 ("cannot resolve & for a named real", N
, Callee
);
567 elsif Nkind
(N
) = N_String_Literal
then
568 Param1
:= Make_String_Literal
(Loc
, Strval
(N
));
569 Params
:= New_List
(Param1
);
571 elsif Nkind
(N
) = N_Interpolated_String_Literal
then
572 Param1
:= New_Copy_Tree
(N
);
573 Params
:= New_List
(Param1
);
578 (Loc
, String_From_Numeric_Literal
(N
));
579 Params
:= New_List
(Param1
);
586 Parameter_Associations
=> Params
);
588 Set_Entity
(Name
, Callee
);
589 Set_Is_Overloaded
(Name
, False);
591 if Lit_Aspect
= Aspect_String_Literal
then
592 Set_Etype
(Param1
, Standard_Wide_Wide_String
);
594 Set_Etype
(Param1
, Standard_String
);
597 Set_Etype
(Call
, Etype
(Callee
));
599 -- Conversion not needed if the result type of the call is class-wide
600 -- or if the result type matches the context type.
602 if not Is_Class_Wide_Type
(Typ
)
603 and then Base_Type
(Etype
(Call
)) /= Base_Type
(Typ
)
605 -- Conversion may be needed in case of an inherited
606 -- aspect of a derived type. For a null extension, we
607 -- use a null extension aggregate instead because the
608 -- downward type conversion would be illegal.
610 if Is_Null_Extension_Of
612 Ancestor
=> Etype
(Call
))
614 Call
:= Make_Extension_Aggregate
(Loc
,
615 Ancestor_Part
=> Call
,
616 Null_Record_Present
=> True);
618 Call
:= Convert_To
(Typ
, Call
);
624 Analyze_And_Resolve
(N
, Typ
);
630 end Has_Applicable_User_Defined_Literal
;
632 ----------------------------
633 -- Check_Discriminant_Use --
634 ----------------------------
636 procedure Check_Discriminant_Use
(N
: Node_Id
) is
637 PN
: constant Node_Id
:= Parent
(N
);
638 Disc
: constant Entity_Id
:= Entity
(N
);
643 -- Any use in a spec-expression is legal
645 if In_Spec_Expression
then
648 elsif Nkind
(PN
) = N_Range
then
650 -- Discriminant cannot be used to constrain a scalar type
654 if Nkind
(P
) = N_Range_Constraint
655 and then Nkind
(Parent
(P
)) = N_Subtype_Indication
656 and then Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
658 Error_Msg_N
("discriminant cannot constrain scalar type", N
);
660 elsif Nkind
(P
) = N_Index_Or_Discriminant_Constraint
then
662 -- The following check catches the unusual case where a
663 -- discriminant appears within an index constraint that is part
664 -- of a larger expression within a constraint on a component,
665 -- e.g. "C : Int range 1 .. F (new A(1 .. D))". For now we only
666 -- check case of record components, and note that a similar check
667 -- should also apply in the case of discriminant constraints
670 -- Note that the check for N_Subtype_Declaration below is to
671 -- detect the valid use of discriminants in the constraints of a
672 -- subtype declaration when this subtype declaration appears
673 -- inside the scope of a record type (which is syntactically
674 -- illegal, but which may be created as part of derived type
675 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
678 if Ekind
(Current_Scope
) = E_Record_Type
679 and then Scope
(Disc
) = Current_Scope
681 (Nkind
(Parent
(P
)) = N_Subtype_Indication
683 Nkind
(Parent
(Parent
(P
))) in N_Component_Definition
684 | N_Subtype_Declaration
685 and then Paren_Count
(N
) = 0)
688 ("discriminant must appear alone in component constraint", N
);
692 -- Detect a common error:
694 -- type R (D : Positive := 100) is record
695 -- Name : String (1 .. D);
698 -- The default value causes an object of type R to be allocated
699 -- with room for Positive'Last characters. The RM does not mandate
700 -- the allocation of the maximum size, but that is what GNAT does
701 -- so we should warn the programmer that there is a problem.
703 Check_Large
: declare
709 function Large_Storage_Type
(T
: Entity_Id
) return Boolean;
710 -- Return True if type T has a large enough range that any
711 -- array whose index type covered the whole range of the type
712 -- would likely raise Storage_Error.
714 ------------------------
715 -- Large_Storage_Type --
716 ------------------------
718 function Large_Storage_Type
(T
: Entity_Id
) return Boolean is
720 -- The type is considered large if its bounds are known at
721 -- compile time and if it requires at least as many bits as
722 -- a Positive to store the possible values.
724 return Compile_Time_Known_Value
(Type_Low_Bound
(T
))
725 and then Compile_Time_Known_Value
(Type_High_Bound
(T
))
727 Minimum_Size
(T
, Biased
=> True) >=
728 RM_Size
(Standard_Positive
);
729 end Large_Storage_Type
;
731 -- Start of processing for Check_Large
734 -- Check that the Disc has a large range
736 if not Large_Storage_Type
(Etype
(Disc
)) then
740 -- If the enclosing type is limited, we allocate only the
741 -- default value, not the maximum, and there is no need for
744 if Is_Limited_Type
(Scope
(Disc
)) then
748 -- Check that it is the high bound
750 if N
/= High_Bound
(PN
)
751 or else No
(Discriminant_Default_Value
(Disc
))
756 -- Check the array allows a large range at this bound. First
761 if Nkind
(SI
) /= N_Subtype_Indication
then
765 T
:= Entity
(Subtype_Mark
(SI
));
767 if not Is_Array_Type
(T
) then
771 -- Next, find the dimension
773 TB
:= First_Index
(T
);
774 CB
:= First
(Constraints
(P
));
776 and then Present
(TB
)
777 and then Present
(CB
)
788 -- Now, check the dimension has a large range
790 if not Large_Storage_Type
(Etype
(TB
)) then
794 -- Warn about the danger
797 ("??creation of & object may raise Storage_Error!",
806 -- Legal case is in index or discriminant constraint
808 elsif Nkind
(PN
) in N_Index_Or_Discriminant_Constraint
809 | N_Discriminant_Association
811 if Paren_Count
(N
) > 0 then
813 ("discriminant in constraint must appear alone", N
);
815 elsif Nkind
(N
) = N_Expanded_Name
816 and then Comes_From_Source
(N
)
819 ("discriminant must appear alone as a direct name", N
);
824 -- Otherwise, context is an expression. It should not be within (i.e. a
825 -- subexpression of) a constraint for a component.
830 while Nkind
(P
) not in
831 N_Component_Declaration | N_Subtype_Indication | N_Entry_Declaration
838 -- If the discriminant is used in an expression that is a bound of a
839 -- scalar type, an Itype is created and the bounds are attached to
840 -- its range, not to the original subtype indication. Such use is of
841 -- course a double fault.
843 if (Nkind
(P
) = N_Subtype_Indication
844 and then Nkind
(Parent
(P
)) in N_Component_Definition
845 | N_Derived_Type_Definition
846 and then D
= Constraint
(P
))
848 -- The constraint itself may be given by a subtype indication,
849 -- rather than by a more common discrete range.
851 or else (Nkind
(P
) = N_Subtype_Indication
853 Nkind
(Parent
(P
)) = N_Index_Or_Discriminant_Constraint
)
854 or else Nkind
(P
) = N_Entry_Declaration
855 or else Nkind
(D
) = N_Defining_Identifier
858 ("discriminant in constraint must appear alone", N
);
861 end Check_Discriminant_Use
;
863 --------------------------------
864 -- Check_For_Visible_Operator --
865 --------------------------------
867 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
) is
869 if Comes_From_Source
(N
)
870 and then not Is_Visible_Operator
(Original_Node
(N
), T
)
871 and then not Error_Posted
(N
)
873 Error_Msg_NE
-- CODEFIX
874 ("operator for} is not directly visible!", N
, First_Subtype
(T
));
875 Error_Msg_N
-- CODEFIX
876 ("use clause would make operation legal!", N
);
878 end Check_For_Visible_Operator
;
880 ---------------------------------
881 -- Check_Fully_Declared_Prefix --
882 ---------------------------------
884 procedure Check_Fully_Declared_Prefix
889 -- Check that the designated type of the prefix of a dereference is
890 -- not an incomplete type. This cannot be done unconditionally, because
891 -- dereferences of private types are legal in default expressions. This
892 -- case is taken care of in Check_Fully_Declared, called below. There
893 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
895 -- This consideration also applies to similar checks for allocators,
896 -- qualified expressions, and type conversions.
898 -- An additional exception concerns other per-object expressions that
899 -- are not directly related to component declarations, in particular
900 -- representation pragmas for tasks. These will be per-object
901 -- expressions if they depend on discriminants or some global entity.
902 -- If the task has access discriminants, the designated type may be
903 -- incomplete at the point the expression is resolved. This resolution
904 -- takes place within the body of the initialization procedure, where
905 -- the discriminant is replaced by its discriminal.
907 if Is_Entity_Name
(Pref
)
908 and then Ekind
(Entity
(Pref
)) = E_In_Parameter
912 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
913 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
914 -- Analyze_Object_Renaming, and Freeze_Entity.
916 elsif Ada_Version
>= Ada_2005
917 and then Is_Entity_Name
(Pref
)
918 and then Is_Access_Type
(Etype
(Pref
))
919 and then Ekind
(Directly_Designated_Type
(Etype
(Pref
))) =
921 and then Is_Tagged_Type
(Directly_Designated_Type
(Etype
(Pref
)))
925 Check_Fully_Declared
(Typ
, Parent
(Pref
));
927 end Check_Fully_Declared_Prefix
;
929 ------------------------------
930 -- Check_Infinite_Recursion --
931 ------------------------------
933 function Check_Infinite_Recursion
(Call
: Node_Id
) return Boolean is
934 function Invoked_With_Different_Arguments
(N
: Node_Id
) return Boolean;
935 -- Determine whether call N invokes the related enclosing subprogram
936 -- with actuals that differ from the subprogram's formals.
938 function Is_Conditional_Statement
(N
: Node_Id
) return Boolean;
939 -- Determine whether arbitrary node N denotes a conditional construct
941 function Is_Control_Flow_Statement
(N
: Node_Id
) return Boolean;
942 -- Determine whether arbitrary node N denotes a control flow statement
943 -- or a construct that may contains such a statement.
945 function Is_Immediately_Within_Body
(N
: Node_Id
) return Boolean;
946 -- Determine whether arbitrary node N appears immediately within the
947 -- statements of an entry or subprogram body.
949 function Is_Raise_Idiom
(N
: Node_Id
) return Boolean;
950 -- Determine whether arbitrary node N appears immediately within the
951 -- body of an entry or subprogram, and is preceded by a single raise
954 function Is_Raise_Statement
(N
: Node_Id
) return Boolean;
955 -- Determine whether arbitrary node N denotes a raise statement
957 function Is_Sole_Statement
(N
: Node_Id
) return Boolean;
958 -- Determine whether arbitrary node N is the sole source statement in
959 -- the body of the enclosing subprogram.
961 function Preceded_By_Control_Flow_Statement
(N
: Node_Id
) return Boolean;
962 -- Determine whether arbitrary node N is preceded by a control flow
965 function Within_Conditional_Statement
(N
: Node_Id
) return Boolean;
966 -- Determine whether arbitrary node N appears within a conditional
969 --------------------------------------
970 -- Invoked_With_Different_Arguments --
971 --------------------------------------
973 function Invoked_With_Different_Arguments
(N
: Node_Id
) return Boolean is
974 Subp
: constant Entity_Id
:= Get_Called_Entity
(N
);
980 -- Determine whether the formals of the invoked subprogram are not
981 -- used as actuals in the call.
983 Actual
:= First_Actual
(N
);
984 Formal
:= First_Formal
(Subp
);
985 while Present
(Actual
) and then Present
(Formal
) loop
987 -- The current actual does not match the current formal
989 if not (Is_Entity_Name
(Actual
)
990 and then Entity
(Actual
) = Formal
)
995 Next_Actual
(Actual
);
996 Next_Formal
(Formal
);
1000 end Invoked_With_Different_Arguments
;
1002 ------------------------------
1003 -- Is_Conditional_Statement --
1004 ------------------------------
1006 function Is_Conditional_Statement
(N
: Node_Id
) return Boolean is
1009 Nkind
(N
) in N_And_Then
1015 end Is_Conditional_Statement
;
1017 -------------------------------
1018 -- Is_Control_Flow_Statement --
1019 -------------------------------
1021 function Is_Control_Flow_Statement
(N
: Node_Id
) return Boolean is
1023 -- It is assumed that all statements may affect the control flow in
1024 -- some way. A raise statement may be expanded into a non-statement
1027 return Is_Statement
(N
) or else Is_Raise_Statement
(N
);
1028 end Is_Control_Flow_Statement
;
1030 --------------------------------
1031 -- Is_Immediately_Within_Body --
1032 --------------------------------
1034 function Is_Immediately_Within_Body
(N
: Node_Id
) return Boolean is
1035 HSS
: constant Node_Id
:= Parent
(N
);
1039 Nkind
(HSS
) = N_Handled_Sequence_Of_Statements
1040 and then Nkind
(Parent
(HSS
)) in N_Entry_Body | N_Subprogram_Body
1041 and then Is_List_Member
(N
)
1042 and then List_Containing
(N
) = Statements
(HSS
);
1043 end Is_Immediately_Within_Body
;
1045 --------------------
1046 -- Is_Raise_Idiom --
1047 --------------------
1049 function Is_Raise_Idiom
(N
: Node_Id
) return Boolean is
1050 Raise_Stmt
: Node_Id
;
1054 if Is_Immediately_Within_Body
(N
) then
1056 -- Assume that no raise statement has been seen yet
1058 Raise_Stmt
:= Empty
;
1060 -- Examine the statements preceding the input node, skipping
1061 -- internally-generated constructs.
1064 while Present
(Stmt
) loop
1066 -- Multiple raise statements violate the idiom
1068 if Is_Raise_Statement
(Stmt
) then
1069 if Present
(Raise_Stmt
) then
1075 elsif Comes_From_Source
(Stmt
) then
1079 Stmt
:= Prev
(Stmt
);
1082 -- At this point the node must be preceded by a raise statement,
1083 -- and the raise statement has to be the sole statement within
1084 -- the enclosing entry or subprogram body.
1087 Present
(Raise_Stmt
) and then Is_Sole_Statement
(Raise_Stmt
);
1093 ------------------------
1094 -- Is_Raise_Statement --
1095 ------------------------
1097 function Is_Raise_Statement
(N
: Node_Id
) return Boolean is
1099 -- A raise statement may be transfomed into a Raise_xxx_Error node
1102 Nkind
(N
) = N_Raise_Statement
1103 or else Nkind
(N
) in N_Raise_xxx_Error
;
1104 end Is_Raise_Statement
;
1106 -----------------------
1107 -- Is_Sole_Statement --
1108 -----------------------
1110 function Is_Sole_Statement
(N
: Node_Id
) return Boolean is
1114 -- The input node appears within the statements of an entry or
1115 -- subprogram body. Examine the statements preceding the node.
1117 if Is_Immediately_Within_Body
(N
) then
1120 while Present
(Stmt
) loop
1122 -- The statement is preceded by another statement or a source
1123 -- construct. This indicates that the node does not appear by
1126 if Is_Control_Flow_Statement
(Stmt
)
1127 or else Comes_From_Source
(Stmt
)
1132 Stmt
:= Prev
(Stmt
);
1138 -- The input node is within a construct nested inside the entry or
1142 end Is_Sole_Statement
;
1144 ----------------------------------------
1145 -- Preceded_By_Control_Flow_Statement --
1146 ----------------------------------------
1148 function Preceded_By_Control_Flow_Statement
1149 (N
: Node_Id
) return Boolean
1154 if Is_List_Member
(N
) then
1157 -- Examine the statements preceding the input node
1159 while Present
(Stmt
) loop
1160 if Is_Control_Flow_Statement
(Stmt
) then
1164 Stmt
:= Prev
(Stmt
);
1170 -- Assume that the node is part of some control flow statement
1173 end Preceded_By_Control_Flow_Statement
;
1175 ----------------------------------
1176 -- Within_Conditional_Statement --
1177 ----------------------------------
1179 function Within_Conditional_Statement
(N
: Node_Id
) return Boolean is
1184 while Present
(Stmt
) loop
1185 if Is_Conditional_Statement
(Stmt
) then
1188 -- Prevent the search from going too far
1190 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
1194 Stmt
:= Parent
(Stmt
);
1198 end Within_Conditional_Statement
;
1202 Call_Context
: constant Node_Id
:=
1203 Enclosing_Declaration_Or_Statement
(Call
);
1205 -- Start of processing for Check_Infinite_Recursion
1208 -- The call is assumed to be safe when the enclosing subprogram is
1209 -- invoked with actuals other than its formals.
1211 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1214 -- Proc (A1, A2, ..., AN);
1218 if Invoked_With_Different_Arguments
(Call
) then
1221 -- The call is assumed to be safe when the invocation of the enclosing
1222 -- subprogram depends on a conditional statement.
1224 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1227 -- if Some_Condition then
1228 -- Proc (F1, F2, ..., FN);
1233 elsif Within_Conditional_Statement
(Call
) then
1236 -- The context of the call is assumed to be safe when the invocation of
1237 -- the enclosing subprogram is preceded by some control flow statement.
1239 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1242 -- if Some_Condition then
1246 -- Proc (F1, F2, ..., FN);
1250 elsif Preceded_By_Control_Flow_Statement
(Call_Context
) then
1253 -- Detect an idiom where the context of the call is preceded by a single
1256 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1259 -- Proc (F1, F2, ..., FN);
1262 elsif Is_Raise_Idiom
(Call_Context
) then
1266 -- At this point it is certain that infinite recursion will take place
1267 -- as long as the call is executed. Detect a case where the context of
1268 -- the call is the sole source statement within the subprogram body.
1270 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1272 -- Proc (F1, F2, ..., FN);
1275 -- Install an explicit raise to prevent the infinite recursion.
1277 if Is_Sole_Statement
(Call_Context
) then
1278 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1279 Error_Msg_N
("!infinite recursion<<", Call
);
1280 Error_Msg_N
("\!Storage_Error [<<", Call
);
1282 Insert_Action
(Call
,
1283 Make_Raise_Storage_Error
(Sloc
(Call
),
1284 Reason
=> SE_Infinite_Recursion
));
1286 -- Otherwise infinite recursion could take place, considering other flow
1287 -- control constructs such as gotos, exit statements, etc.
1290 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1291 Error_Msg_N
("!possible infinite recursion<<", Call
);
1292 Error_Msg_N
("\!??Storage_Error ]<<", Call
);
1296 end Check_Infinite_Recursion
;
1298 ---------------------------------------
1299 -- Check_No_Direct_Boolean_Operators --
1300 ---------------------------------------
1302 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
) is
1304 if Scope
(Entity
(N
)) = Standard_Standard
1305 and then Root_Type
(Etype
(Left_Opnd
(N
))) = Standard_Boolean
1307 -- Restriction only applies to original source code
1309 if Comes_From_Source
(N
) then
1310 Check_Restriction
(No_Direct_Boolean_Operators
, N
);
1314 -- Do style check (but skip if in instance, error is on template)
1317 if not In_Instance
then
1318 Check_Boolean_Operator
(N
);
1321 end Check_No_Direct_Boolean_Operators
;
1323 ------------------------------
1324 -- Check_Parameterless_Call --
1325 ------------------------------
1327 procedure Check_Parameterless_Call
(N
: Node_Id
) is
1330 function Prefix_Is_Access_Subp
return Boolean;
1331 -- If the prefix is of an access_to_subprogram type, the node must be
1332 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1333 -- interpretations are access to subprograms.
1335 ---------------------------
1336 -- Prefix_Is_Access_Subp --
1337 ---------------------------
1339 function Prefix_Is_Access_Subp
return Boolean is
1344 -- If the context is an attribute reference that can apply to
1345 -- functions, this is never a parameterless call (RM 4.1.4(6)).
1347 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1348 and then Attribute_Name
(Parent
(N
))
1349 in Name_Address | Name_Code_Address | Name_Access
1354 if not Is_Overloaded
(N
) then
1356 Ekind
(Etype
(N
)) = E_Subprogram_Type
1357 and then Base_Type
(Etype
(Etype
(N
))) /= Standard_Void_Type
;
1359 Get_First_Interp
(N
, I
, It
);
1360 while Present
(It
.Typ
) loop
1361 if Ekind
(It
.Typ
) /= E_Subprogram_Type
1362 or else Base_Type
(Etype
(It
.Typ
)) = Standard_Void_Type
1367 Get_Next_Interp
(I
, It
);
1372 end Prefix_Is_Access_Subp
;
1374 -- Start of processing for Check_Parameterless_Call
1377 -- Defend against junk stuff if errors already detected
1379 if Total_Errors_Detected
/= 0 then
1380 if Nkind
(N
) in N_Has_Etype
and then Etype
(N
) = Any_Type
then
1382 elsif Nkind
(N
) in N_Has_Chars
1383 and then not Is_Valid_Name
(Chars
(N
))
1391 -- If the context expects a value, and the name is a procedure, this is
1392 -- most likely a missing 'Access. Don't try to resolve the parameterless
1393 -- call, error will be caught when the outer call is analyzed.
1395 if Is_Entity_Name
(N
)
1396 and then Ekind
(Entity
(N
)) = E_Procedure
1397 and then not Is_Overloaded
(N
)
1399 Nkind
(Parent
(N
)) in N_Parameter_Association
1401 | N_Procedure_Call_Statement
1406 -- Rewrite as call if overloadable entity that is (or could be, in the
1407 -- overloaded case) a function call. If we know for sure that the entity
1408 -- is an enumeration literal, we do not rewrite it.
1410 -- If the entity is the name of an operator, it cannot be a call because
1411 -- operators cannot have default parameters. In this case, this must be
1412 -- a string whose contents coincide with an operator name. Set the kind
1413 -- of the node appropriately.
1415 if (Is_Entity_Name
(N
)
1416 and then Nkind
(N
) /= N_Operator_Symbol
1417 and then Is_Overloadable
(Entity
(N
))
1418 and then (Ekind
(Entity
(N
)) /= E_Enumeration_Literal
1419 or else Is_Overloaded
(N
)))
1421 -- Rewrite as call if it is an explicit dereference of an expression of
1422 -- a subprogram access type, and the subprogram type is not that of a
1423 -- procedure or entry.
1426 (Nkind
(N
) = N_Explicit_Dereference
and then Prefix_Is_Access_Subp
)
1428 -- Rewrite as call if it is a selected component which is a function,
1429 -- this is the case of a call to a protected function (which may be
1430 -- overloaded with other protected operations).
1433 (Nkind
(N
) = N_Selected_Component
1434 and then (Ekind
(Entity
(Selector_Name
(N
))) = E_Function
1436 (Ekind
(Entity
(Selector_Name
(N
))) in
1437 E_Entry | E_Procedure
1438 and then Is_Overloaded
(Selector_Name
(N
)))))
1440 -- If one of the above three conditions is met, rewrite as call. Apply
1441 -- the rewriting only once.
1444 if Nkind
(Parent
(N
)) /= N_Function_Call
1445 or else N
/= Name
(Parent
(N
))
1448 -- This may be a prefixed call that was not fully analyzed, e.g.
1449 -- an actual in an instance.
1451 if Ada_Version
>= Ada_2005
1452 and then Nkind
(N
) = N_Selected_Component
1453 and then Is_Dispatching_Operation
(Entity
(Selector_Name
(N
)))
1455 Analyze_Selected_Component
(N
);
1457 if Nkind
(N
) /= N_Selected_Component
then
1462 -- The node is the name of the parameterless call. Preserve its
1463 -- descendants, which may be complex expressions.
1465 Nam
:= Relocate_Node
(N
);
1467 -- If overloaded, overload set belongs to new copy
1469 Save_Interps
(N
, Nam
);
1471 -- Change node to parameterless function call (note that the
1472 -- Parameter_Associations associations field is left set to Empty,
1473 -- its normal default value since there are no parameters)
1475 Change_Node
(N
, N_Function_Call
);
1477 Set_Sloc
(N
, Sloc
(Nam
));
1481 elsif Nkind
(N
) = N_Parameter_Association
then
1482 Check_Parameterless_Call
(Explicit_Actual_Parameter
(N
));
1484 elsif Nkind
(N
) = N_Operator_Symbol
then
1485 Set_Etype
(N
, Empty
);
1486 Set_Entity
(N
, Empty
);
1487 Set_Is_Overloaded
(N
, False);
1488 Change_Operator_Symbol_To_String_Literal
(N
);
1489 Set_Etype
(N
, Any_String
);
1491 end Check_Parameterless_Call
;
1493 ----------------------------------------
1494 -- Is_Atomic_Non_VFA_Ref_With_Address --
1495 ----------------------------------------
1497 function Is_Atomic_Non_VFA_Ref_With_Address
(N
: Node_Id
) return Boolean is
1498 Pref
: constant Node_Id
:= Prefix
(N
);
1500 function Is_Atomic_Non_VFA
(E
: Entity_Id
) return Boolean;
1501 -- Return true if E is Atomic but not Volatile_Full_Access
1503 -----------------------
1504 -- Is_Atomic_Non_VFA --
1505 -----------------------
1507 function Is_Atomic_Non_VFA
(E
: Entity_Id
) return Boolean is
1509 return Is_Atomic
(E
) and then not Is_Volatile_Full_Access
(E
);
1510 end Is_Atomic_Non_VFA
;
1513 if Is_Entity_Name
(Pref
) then
1515 Pent
: constant Entity_Id
:= Entity
(Pref
);
1516 Ptyp
: constant Entity_Id
:= Etype
(Pent
);
1519 return not Is_Access_Type
(Ptyp
)
1520 and then (Is_Atomic_Non_VFA
(Ptyp
)
1521 or else Is_Atomic_Non_VFA
(Pent
))
1522 and then Present
(Address_Clause
(Pent
));
1528 end Is_Atomic_Non_VFA_Ref_With_Address
;
1530 -----------------------------
1531 -- Is_Definite_Access_Type --
1532 -----------------------------
1534 function Is_Definite_Access_Type
(E
: N_Entity_Id
) return Boolean is
1535 Btyp
: constant Entity_Id
:= Base_Type
(E
);
1537 return Ekind
(Btyp
) = E_Access_Type
1538 or else (Ekind
(Btyp
) = E_Access_Subprogram_Type
1539 and then Comes_From_Source
(Btyp
));
1540 end Is_Definite_Access_Type
;
1542 ----------------------
1543 -- Is_Predefined_Op --
1544 ----------------------
1546 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean is
1548 -- Predefined operators are intrinsic subprograms
1550 if not Is_Intrinsic_Subprogram
(Nam
) then
1554 -- A call to a back-end builtin is never a predefined operator
1556 if Is_Imported
(Nam
) and then Present
(Interface_Name
(Nam
)) then
1560 return not Is_Generic_Instance
(Nam
)
1561 and then Chars
(Nam
) in Any_Operator_Name
1562 and then (No
(Alias
(Nam
)) or else Is_Predefined_Op
(Alias
(Nam
)));
1563 end Is_Predefined_Op
;
1565 -----------------------------
1566 -- Make_Call_Into_Operator --
1567 -----------------------------
1569 procedure Make_Call_Into_Operator
1574 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
1575 Act1
: Node_Id
:= First_Actual
(N
);
1576 Act2
: Node_Id
:= Next_Actual
(Act1
);
1577 Error
: Boolean := False;
1578 Func
: constant Entity_Id
:= Entity
(Name
(N
));
1579 Is_Binary
: constant Boolean := Present
(Act2
);
1581 Opnd_Type
: Entity_Id
:= Empty
;
1582 Orig_Type
: Entity_Id
:= Empty
;
1585 type Kind_Test
is access function (E
: N_Entity_Id
) return Boolean;
1587 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean;
1588 -- If the operand is not universal, and the operator is given by an
1589 -- expanded name, verify that the operand has an interpretation with a
1590 -- type defined in the given scope of the operator.
1592 function Type_In_P
(Test
: not null Kind_Test
) return Entity_Id
;
1593 -- Find a type of the given class in package Pack that contains the
1596 ---------------------------
1597 -- Operand_Type_In_Scope --
1598 ---------------------------
1600 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean is
1601 Nod
: constant Node_Id
:= Right_Opnd
(Op_Node
);
1606 if not Is_Overloaded
(Nod
) then
1607 return Scope
(Base_Type
(Etype
(Nod
))) = S
;
1610 Get_First_Interp
(Nod
, I
, It
);
1611 while Present
(It
.Typ
) loop
1612 if Scope
(Base_Type
(It
.Typ
)) = S
then
1616 Get_Next_Interp
(I
, It
);
1621 end Operand_Type_In_Scope
;
1627 function Type_In_P
(Test
: not null Kind_Test
) return Entity_Id
is
1630 function In_Decl
return Boolean;
1631 -- Verify that node is not part of the type declaration for the
1632 -- candidate type, which would otherwise be invisible.
1638 function In_Decl
return Boolean is
1639 Decl_Node
: constant Node_Id
:= Parent
(E
);
1643 if Etype
(E
) = Any_Type
then
1646 elsif No
(Decl_Node
) then
1652 while Present
(Context
)
1653 and then Nkind
(Context
) /= N_Compilation_Unit
1655 if Context
= Decl_Node
then
1658 Context
:= Parent
(Context
);
1666 -- Start of processing for Type_In_P
1669 -- If the context type is declared in the prefix package, this is the
1670 -- desired base type.
1672 if Scope
(Base_Type
(Typ
)) = Pack
and then Test
(Typ
) then
1673 return Base_Type
(Typ
);
1676 E
:= First_Entity
(Pack
);
1677 while Present
(E
) loop
1678 if Test
(E
) and then not In_Decl
then
1689 -- Start of processing for Make_Call_Into_Operator
1692 Op_Node
:= New_Node
(Operator_Kind
(Op_Name
, Is_Binary
), Sloc
(N
));
1694 -- Preserve the Comes_From_Source flag on the result if the original
1695 -- call came from source. Although it is not strictly the case that the
1696 -- operator as such comes from the source, logically it corresponds
1697 -- exactly to the function call in the source, so it should be marked
1698 -- this way (e.g. to make sure that validity checks work fine).
1700 Preserve_Comes_From_Source
(Op_Node
, N
);
1702 -- Ensure that the corresponding operator has the same parent as the
1703 -- original call. This guarantees that parent traversals performed by
1704 -- the ABE mechanism succeed.
1706 Set_Parent
(Op_Node
, Parent
(N
));
1711 Set_Left_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1712 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act2
));
1713 Save_Interps
(Act1
, Left_Opnd
(Op_Node
));
1714 Save_Interps
(Act2
, Right_Opnd
(Op_Node
));
1715 Act1
:= Left_Opnd
(Op_Node
);
1716 Act2
:= Right_Opnd
(Op_Node
);
1721 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1722 Save_Interps
(Act1
, Right_Opnd
(Op_Node
));
1723 Act1
:= Right_Opnd
(Op_Node
);
1726 -- If the operator is denoted by an expanded name, and the prefix is
1727 -- not Standard, but the operator is a predefined one whose scope is
1728 -- Standard, then this is an implicit_operator, inserted as an
1729 -- interpretation by the procedure of the same name. This procedure
1730 -- overestimates the presence of implicit operators, because it does
1731 -- not examine the type of the operands. Verify now that the operand
1732 -- type appears in the given scope. If right operand is universal,
1733 -- check the other operand. In the case of concatenation, either
1734 -- argument can be the component type, so check the type of the result.
1735 -- If both arguments are literals, look for a type of the right kind
1736 -- defined in the given scope. This elaborate nonsense is brought to
1737 -- you courtesy of b33302a. The type itself must be frozen, so we must
1738 -- find the type of the proper class in the given scope.
1740 -- A final wrinkle is the multiplication operator for fixed point types,
1741 -- which is defined in Standard only, and not in the scope of the
1742 -- fixed point type itself.
1744 if Nkind
(Name
(N
)) = N_Expanded_Name
then
1745 Pack
:= Entity
(Prefix
(Name
(N
)));
1747 -- If this is a package renaming, get renamed entity, which will be
1748 -- the scope of the operands if operaton is type-correct.
1750 if Present
(Renamed_Entity
(Pack
)) then
1751 Pack
:= Renamed_Entity
(Pack
);
1754 -- If the entity being called is defined in the given package, it is
1755 -- a renaming of a predefined operator, and known to be legal.
1757 if Scope
(Entity
(Name
(N
))) = Pack
1758 and then Pack
/= Standard_Standard
1762 -- Visibility does not need to be checked in an instance: if the
1763 -- operator was not visible in the generic it has been diagnosed
1764 -- already, else there is an implicit copy of it in the instance.
1766 elsif In_Instance
then
1769 elsif Op_Name
in Name_Op_Multiply | Name_Op_Divide
1770 and then Is_Fixed_Point_Type
(Etype
(Act1
))
1771 and then Is_Fixed_Point_Type
(Etype
(Act2
))
1773 if Pack
/= Standard_Standard
then
1777 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1780 elsif Ada_Version
>= Ada_2005
1781 and then Op_Name
in Name_Op_Eq | Name_Op_Ne
1782 and then (Is_Anonymous_Access_Type
(Etype
(Act1
))
1783 or else Is_Anonymous_Access_Type
(Etype
(Act2
)))
1788 Opnd_Type
:= Base_Type
(Etype
(Right_Opnd
(Op_Node
)));
1790 if Op_Name
= Name_Op_Concat
then
1791 Opnd_Type
:= Base_Type
(Typ
);
1793 elsif (Scope
(Opnd_Type
) = Standard_Standard
1795 or else (Nkind
(Right_Opnd
(Op_Node
)) = N_Attribute_Reference
1797 and then not Comes_From_Source
(Opnd_Type
))
1799 Opnd_Type
:= Base_Type
(Etype
(Left_Opnd
(Op_Node
)));
1802 if Scope
(Opnd_Type
) = Standard_Standard
then
1804 -- Verify that the scope contains a type that corresponds to
1805 -- the given literal. Optimize the case where Pack is Standard.
1807 if Pack
/= Standard_Standard
then
1808 if Opnd_Type
= Universal_Integer
then
1809 Orig_Type
:= Type_In_P
(Is_Integer_Type
'Access);
1811 elsif Opnd_Type
= Universal_Real
then
1812 Orig_Type
:= Type_In_P
(Is_Real_Type
'Access);
1814 elsif Opnd_Type
= Universal_Access
then
1815 Orig_Type
:= Type_In_P
(Is_Definite_Access_Type
'Access);
1817 elsif Opnd_Type
= Any_String
then
1818 Orig_Type
:= Type_In_P
(Is_String_Type
'Access);
1820 elsif Opnd_Type
= Any_Composite
then
1821 Orig_Type
:= Type_In_P
(Is_Composite_Type
'Access);
1823 if Present
(Orig_Type
) then
1824 if Has_Private_Component
(Orig_Type
) then
1827 Set_Etype
(Act1
, Orig_Type
);
1830 Set_Etype
(Act2
, Orig_Type
);
1839 Error
:= No
(Orig_Type
);
1842 elsif Ekind
(Opnd_Type
) = E_Allocator_Type
1843 and then No
(Type_In_P
(Is_Definite_Access_Type
'Access))
1847 -- If the type is defined elsewhere, and the operator is not
1848 -- defined in the given scope (by a renaming declaration, e.g.)
1849 -- then this is an error as well. If an extension of System is
1850 -- present, and the type may be defined there, Pack must be
1853 elsif Scope
(Opnd_Type
) /= Pack
1854 and then Scope
(Op_Id
) /= Pack
1855 and then (No
(System_Aux_Id
)
1856 or else Scope
(Opnd_Type
) /= System_Aux_Id
1857 or else Pack
/= Scope
(System_Aux_Id
))
1859 if not Is_Overloaded
(Right_Opnd
(Op_Node
)) then
1862 Error
:= not Operand_Type_In_Scope
(Pack
);
1865 elsif Pack
= Standard_Standard
1866 and then not Operand_Type_In_Scope
(Standard_Standard
)
1873 Error_Msg_Node_2
:= Pack
;
1875 ("& not declared in&", N
, Selector_Name
(Name
(N
)));
1876 Set_Etype
(N
, Any_Type
);
1879 -- Detect a mismatch between the context type and the result type
1880 -- in the named package, which is otherwise not detected if the
1881 -- operands are universal. Check is only needed if source entity is
1882 -- an operator, not a function that renames an operator.
1884 elsif Nkind
(Parent
(N
)) /= N_Type_Conversion
1885 and then Ekind
(Entity
(Name
(N
))) = E_Operator
1886 and then Is_Numeric_Type
(Typ
)
1887 and then not Is_Universal_Numeric_Type
(Typ
)
1888 and then Scope
(Base_Type
(Typ
)) /= Pack
1889 and then not In_Instance
1891 if Is_Fixed_Point_Type
(Typ
)
1892 and then Op_Name
in Name_Op_Multiply | Name_Op_Divide
1894 -- Already checked above
1898 -- Operator may be defined in an extension of System
1900 elsif Present
(System_Aux_Id
)
1901 and then Present
(Opnd_Type
)
1902 and then Scope
(Opnd_Type
) = System_Aux_Id
1907 -- Could we use Wrong_Type here??? (this would require setting
1908 -- Etype (N) to the actual type found where Typ was expected).
1910 Error_Msg_NE
("expect }", N
, Typ
);
1915 Set_Chars
(Op_Node
, Op_Name
);
1917 if not Is_Private_Type
(Etype
(N
)) then
1918 Set_Etype
(Op_Node
, Base_Type
(Etype
(N
)));
1920 Set_Etype
(Op_Node
, Etype
(N
));
1923 -- If this is a call to a function that renames a predefined equality,
1924 -- the renaming declaration provides a type that must be used to
1925 -- resolve the operands. This must be done now because resolution of
1926 -- the equality node will not resolve any remaining ambiguity, and it
1927 -- assumes that the first operand is not overloaded.
1929 if Op_Name
in Name_Op_Eq | Name_Op_Ne
1930 and then Ekind
(Func
) = E_Function
1931 and then Is_Overloaded
(Act1
)
1933 Resolve
(Act1
, Base_Type
(Etype
(First_Formal
(Func
))));
1934 Resolve
(Act2
, Base_Type
(Etype
(First_Formal
(Func
))));
1937 Set_Entity
(Op_Node
, Op_Id
);
1938 Generate_Reference
(Op_Id
, N
, ' ');
1940 Rewrite
(N
, Op_Node
);
1942 -- If this is an arithmetic operator and the result type is private,
1943 -- the operands and the result must be wrapped in conversion to
1944 -- expose the underlying numeric type and expand the proper checks,
1945 -- e.g. on division.
1947 if Is_Private_Type
(Typ
) then
1957 Resolve_Intrinsic_Operator
(N
, Typ
);
1963 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
1971 end Make_Call_Into_Operator
;
1977 function Operator_Kind
1979 Is_Binary
: Boolean) return Node_Kind
1984 -- Use CASE statement or array???
1987 if Op_Name
= Name_Op_And
then
1989 elsif Op_Name
= Name_Op_Or
then
1991 elsif Op_Name
= Name_Op_Xor
then
1993 elsif Op_Name
= Name_Op_Eq
then
1995 elsif Op_Name
= Name_Op_Ne
then
1997 elsif Op_Name
= Name_Op_Lt
then
1999 elsif Op_Name
= Name_Op_Le
then
2001 elsif Op_Name
= Name_Op_Gt
then
2003 elsif Op_Name
= Name_Op_Ge
then
2005 elsif Op_Name
= Name_Op_Add
then
2007 elsif Op_Name
= Name_Op_Subtract
then
2008 Kind
:= N_Op_Subtract
;
2009 elsif Op_Name
= Name_Op_Concat
then
2010 Kind
:= N_Op_Concat
;
2011 elsif Op_Name
= Name_Op_Multiply
then
2012 Kind
:= N_Op_Multiply
;
2013 elsif Op_Name
= Name_Op_Divide
then
2014 Kind
:= N_Op_Divide
;
2015 elsif Op_Name
= Name_Op_Mod
then
2017 elsif Op_Name
= Name_Op_Rem
then
2019 elsif Op_Name
= Name_Op_Expon
then
2022 raise Program_Error
;
2028 if Op_Name
= Name_Op_Add
then
2030 elsif Op_Name
= Name_Op_Subtract
then
2032 elsif Op_Name
= Name_Op_Abs
then
2034 elsif Op_Name
= Name_Op_Not
then
2037 raise Program_Error
;
2044 ---------------------------------------
2045 -- Original_Implementation_Base_Type --
2046 ---------------------------------------
2048 function Original_Implementation_Base_Type
2049 (Id
: Entity_Id
) return Entity_Id
2051 IBT
: constant Entity_Id
:= Implementation_Base_Type
(Id
);
2052 IBT_Decl
: constant Node_Id
:= Parent
(IBT
);
2053 Parent_Id
: Node_Id
;
2055 if Nkind
(IBT_Decl
) = N_Full_Type_Declaration
2056 and then Original_Node
(IBT_Decl
) /= IBT_Decl
2057 and then Nkind
(Original_Node
(IBT_Decl
)) =
2058 N_Full_Type_Declaration
2059 and then Nkind
(Type_Definition
(Original_Node
(IBT_Decl
)))
2060 = N_Derived_Type_Definition
2062 Parent_Id
:= Subtype_Indication
(Type_Definition
2063 (Original_Node
(IBT_Decl
)));
2065 if Nkind
(Parent_Id
) = N_Subtype_Indication
then
2066 Parent_Id
:= Subtype_Mark
(Parent_Id
);
2069 return Original_Implementation_Base_Type
2070 (Etype
(Parent_Id
));
2074 end Original_Implementation_Base_Type
;
2076 ----------------------------
2077 -- Preanalyze_And_Resolve --
2078 ----------------------------
2080 procedure Preanalyze_And_Resolve
2083 With_Freezing
: Boolean)
2085 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
2086 Save_Must_Not_Freeze
: constant Boolean := Must_Not_Freeze
(N
);
2087 Save_Preanalysis_Count
: constant Nat
:=
2088 Inside_Preanalysis_Without_Freezing
;
2090 pragma Assert
(Nkind
(N
) in N_Subexpr
);
2092 if not With_Freezing
then
2093 Set_Must_Not_Freeze
(N
);
2094 Inside_Preanalysis_Without_Freezing
:=
2095 Inside_Preanalysis_Without_Freezing
+ 1;
2098 Full_Analysis
:= False;
2099 Expander_Mode_Save_And_Set
(False);
2101 -- See also Preanalyze_And_Resolve in sem.adb for similar handling
2103 -- Normally, we suppress all checks for this preanalysis. There is no
2104 -- point in processing them now, since they will be applied properly
2105 -- and in the proper location when the default expressions reanalyzed
2106 -- and reexpanded later on. We will also have more information at that
2107 -- point for possible suppression of individual checks.
2109 -- However, in GNATprove mode, most expansion is suppressed, and this
2110 -- later reanalysis and reexpansion may not occur. GNATprove mode does
2111 -- require the setting of checking flags for proof purposes, so we
2112 -- do the GNATprove preanalysis without suppressing checks.
2114 -- This special handling for SPARK mode is required for example in the
2115 -- case of Ada 2012 constructs such as quantified expressions, which are
2116 -- expanded in two separate steps.
2118 -- We also do not want to suppress checks if we are not dealing
2119 -- with a default expression. One such case that is known to reach
2120 -- this point is the expression of an expression function.
2122 if GNATprove_Mode
or Nkind
(Parent
(N
)) = N_Simple_Return_Statement
then
2123 Analyze_And_Resolve
(N
, T
);
2125 Analyze_And_Resolve
(N
, T
, Suppress
=> All_Checks
);
2128 Expander_Mode_Restore
;
2129 Full_Analysis
:= Save_Full_Analysis
;
2131 if not With_Freezing
then
2132 Set_Must_Not_Freeze
(N
, Save_Must_Not_Freeze
);
2133 Inside_Preanalysis_Without_Freezing
:=
2134 Inside_Preanalysis_Without_Freezing
- 1;
2138 (Inside_Preanalysis_Without_Freezing
= Save_Preanalysis_Count
);
2139 end Preanalyze_And_Resolve
;
2141 ----------------------------
2142 -- Preanalyze_And_Resolve --
2143 ----------------------------
2145 procedure Preanalyze_And_Resolve
(N
: Node_Id
; T
: Entity_Id
) is
2147 Preanalyze_And_Resolve
(N
, T
, With_Freezing
=> False);
2148 end Preanalyze_And_Resolve
;
2150 -- Version without context type
2152 procedure Preanalyze_And_Resolve
(N
: Node_Id
) is
2153 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
2156 Full_Analysis
:= False;
2157 Expander_Mode_Save_And_Set
(False);
2160 Resolve
(N
, Etype
(N
), Suppress
=> All_Checks
);
2162 Expander_Mode_Restore
;
2163 Full_Analysis
:= Save_Full_Analysis
;
2164 end Preanalyze_And_Resolve
;
2166 ------------------------------------------
2167 -- Preanalyze_With_Freezing_And_Resolve --
2168 ------------------------------------------
2170 procedure Preanalyze_With_Freezing_And_Resolve
2175 Preanalyze_And_Resolve
(N
, T
, With_Freezing
=> True);
2176 end Preanalyze_With_Freezing_And_Resolve
;
2178 ----------------------------------
2179 -- Replace_Actual_Discriminants --
2180 ----------------------------------
2182 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
) is
2183 Loc
: constant Source_Ptr
:= Sloc
(N
);
2184 Tsk
: Node_Id
:= Empty
;
2186 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
;
2187 -- Comment needed???
2193 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
is
2197 if Nkind
(Nod
) = N_Identifier
then
2198 Ent
:= Entity
(Nod
);
2201 and then Ekind
(Ent
) = E_Discriminant
2204 Make_Selected_Component
(Loc
,
2205 Prefix
=> New_Copy_Tree
(Tsk
, New_Sloc
=> Loc
),
2206 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Ent
))));
2208 Set_Etype
(Nod
, Etype
(Ent
));
2216 procedure Replace_Discrs
is new Traverse_Proc
(Process_Discr
);
2218 -- Start of processing for Replace_Actual_Discriminants
2221 if Expander_Active
then
2224 -- Allow the replacement of concurrent discriminants in GNATprove even
2225 -- though this is a light expansion activity. Note that generic units
2226 -- are not modified.
2228 elsif GNATprove_Mode
and not Inside_A_Generic
then
2235 if Nkind
(Name
(N
)) = N_Selected_Component
then
2236 Tsk
:= Prefix
(Name
(N
));
2238 elsif Nkind
(Name
(N
)) = N_Indexed_Component
then
2239 Tsk
:= Prefix
(Prefix
(Name
(N
)));
2242 if Present
(Tsk
) then
2243 Replace_Discrs
(Default
);
2245 end Replace_Actual_Discriminants
;
2251 procedure Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
2252 Ambiguous
: Boolean := False;
2253 Ctx_Type
: Entity_Id
:= Typ
;
2254 Expr_Type
: Entity_Id
:= Empty
; -- prevent junk warning
2255 Err_Type
: Entity_Id
:= Empty
;
2256 Found
: Boolean := False;
2259 I1
: Interp_Index
:= 0; -- prevent junk warning
2262 Seen
: Entity_Id
:= Empty
; -- prevent junk warning
2264 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean;
2265 -- Determine whether a node comes from a predefined library unit or
2268 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
);
2269 -- Try and fix up a literal so that it matches its expected type. New
2270 -- literals are manufactured if necessary to avoid cascaded errors.
2272 procedure Report_Ambiguous_Argument
;
2273 -- Additional diagnostics when an ambiguous call has an ambiguous
2274 -- argument (typically a controlling actual).
2276 procedure Resolution_Failed
;
2277 -- Called when attempt at resolving current expression fails
2279 ------------------------------------
2280 -- Comes_From_Predefined_Lib_Unit --
2281 -------------------------------------
2283 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean is
2286 Sloc
(Nod
) = Standard_Location
or else In_Predefined_Unit
(Nod
);
2287 end Comes_From_Predefined_Lib_Unit
;
2289 --------------------
2290 -- Patch_Up_Value --
2291 --------------------
2293 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
) is
2295 if Nkind
(N
) = N_Integer_Literal
and then Is_Real_Type
(Typ
) then
2297 Make_Real_Literal
(Sloc
(N
),
2298 Realval
=> UR_From_Uint
(Intval
(N
))));
2299 Set_Etype
(N
, Universal_Real
);
2300 Set_Is_Static_Expression
(N
);
2302 elsif Nkind
(N
) = N_Real_Literal
and then Is_Integer_Type
(Typ
) then
2304 Make_Integer_Literal
(Sloc
(N
),
2305 Intval
=> UR_To_Uint
(Realval
(N
))));
2306 Set_Etype
(N
, Universal_Integer
);
2307 Set_Is_Static_Expression
(N
);
2309 elsif Nkind
(N
) = N_String_Literal
2310 and then Is_Character_Type
(Typ
)
2312 Set_Character_Literal_Name
(Get_Char_Code
('A'));
2314 Make_Character_Literal
(Sloc
(N
),
2316 Char_Literal_Value
=>
2317 UI_From_CC
(Get_Char_Code
('A'))));
2318 Set_Etype
(N
, Any_Character
);
2319 Set_Is_Static_Expression
(N
);
2321 elsif Nkind
(N
) /= N_String_Literal
and then Is_String_Type
(Typ
) then
2323 Make_String_Literal
(Sloc
(N
),
2324 Strval
=> End_String
));
2326 elsif Nkind
(N
) = N_Range
then
2327 Patch_Up_Value
(Low_Bound
(N
), Typ
);
2328 Patch_Up_Value
(High_Bound
(N
), Typ
);
2332 -------------------------------
2333 -- Report_Ambiguous_Argument --
2334 -------------------------------
2336 procedure Report_Ambiguous_Argument
is
2337 Arg
: constant Node_Id
:= First
(Parameter_Associations
(N
));
2342 if Nkind
(Arg
) = N_Function_Call
2343 and then Is_Entity_Name
(Name
(Arg
))
2344 and then Is_Overloaded
(Name
(Arg
))
2346 Error_Msg_NE
("ambiguous call to&", Arg
, Name
(Arg
));
2348 -- Examine possible interpretations, and adapt the message
2349 -- for inherited subprograms declared by a type derivation.
2351 Get_First_Interp
(Name
(Arg
), I
, It
);
2352 while Present
(It
.Nam
) loop
2353 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2355 if Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
then
2356 Error_Msg_N
("interpretation (inherited) #!", Arg
);
2358 Error_Msg_N
("interpretation #!", Arg
);
2361 Get_Next_Interp
(I
, It
);
2365 -- Additional message and hint if the ambiguity involves an Ada 2022
2366 -- container aggregate.
2368 Check_Ambiguous_Aggregate
(N
);
2369 end Report_Ambiguous_Argument
;
2371 -----------------------
2372 -- Resolution_Failed --
2373 -----------------------
2375 procedure Resolution_Failed
is
2377 Patch_Up_Value
(N
, Typ
);
2379 -- Set the type to the desired one to minimize cascaded errors. Note
2380 -- that this is an approximation and does not work in all cases.
2384 Debug_A_Exit
("resolving ", N
, " (done, resolution failed)");
2385 Set_Is_Overloaded
(N
, False);
2387 -- The caller will return without calling the expander, so we need
2388 -- to set the analyzed flag. Note that it is fine to set Analyzed
2389 -- to True even if we are in the middle of a shallow analysis,
2390 -- (see the spec of sem for more details) since this is an error
2391 -- situation anyway, and there is no point in repeating the
2392 -- analysis later (indeed it won't work to repeat it later, since
2393 -- we haven't got a clear resolution of which entity is being
2396 Set_Analyzed
(N
, True);
2398 end Resolution_Failed
;
2400 -- Start of processing for Resolve
2407 -- Access attribute on remote subprogram cannot be used for a non-remote
2408 -- access-to-subprogram type.
2410 if Nkind
(N
) = N_Attribute_Reference
2411 and then Attribute_Name
(N
) in Name_Access
2412 | Name_Unrestricted_Access
2413 | Name_Unchecked_Access
2414 and then Comes_From_Source
(N
)
2415 and then Is_Entity_Name
(Prefix
(N
))
2416 and then Is_Subprogram
(Entity
(Prefix
(N
)))
2417 and then Is_Remote_Call_Interface
(Entity
(Prefix
(N
)))
2418 and then not Is_Remote_Access_To_Subprogram_Type
(Typ
)
2421 ("prefix must statically denote a non-remote subprogram", N
);
2424 -- If the context is a Remote_Access_To_Subprogram, access attributes
2425 -- must be resolved with the corresponding fat pointer. There is no need
2426 -- to check for the attribute name since the return type of an
2427 -- attribute is never a remote type.
2429 if Nkind
(N
) = N_Attribute_Reference
2430 and then Comes_From_Source
(N
)
2431 and then (Is_Remote_Call_Interface
(Typ
) or else Is_Remote_Types
(Typ
))
2434 Attr
: constant Attribute_Id
:=
2435 Get_Attribute_Id
(Attribute_Name
(N
));
2436 Pref
: constant Node_Id
:= Prefix
(N
);
2439 Is_Remote
: Boolean := True;
2442 -- Check that Typ is a remote access-to-subprogram type
2444 if Is_Remote_Access_To_Subprogram_Type
(Typ
) then
2446 -- Prefix (N) must statically denote a remote subprogram
2447 -- declared in a package specification.
2449 if Attr
= Attribute_Access
or else
2450 Attr
= Attribute_Unchecked_Access
or else
2451 Attr
= Attribute_Unrestricted_Access
2453 Decl
:= Unit_Declaration_Node
(Entity
(Pref
));
2455 if Nkind
(Decl
) = N_Subprogram_Body
then
2456 Spec
:= Corresponding_Spec
(Decl
);
2458 if Present
(Spec
) then
2459 Decl
:= Unit_Declaration_Node
(Spec
);
2463 Spec
:= Parent
(Decl
);
2465 if not Is_Entity_Name
(Prefix
(N
))
2466 or else Nkind
(Spec
) /= N_Package_Specification
2468 not Is_Remote_Call_Interface
(Defining_Entity
(Spec
))
2472 ("prefix must statically denote a remote subprogram",
2476 -- If we are generating code in distributed mode, perform
2477 -- semantic checks against corresponding remote entities.
2480 and then Get_PCS_Name
/= Name_No_DSA
2482 Check_Subtype_Conformant
2483 (New_Id
=> Entity
(Prefix
(N
)),
2484 Old_Id
=> Designated_Type
2485 (Corresponding_Remote_Type
(Typ
)),
2489 Process_Remote_AST_Attribute
(N
, Typ
);
2497 Debug_A_Entry
("resolving ", N
);
2499 if Debug_Flag_V
then
2500 Write_Overloads
(N
);
2503 if Comes_From_Source
(N
) then
2504 if Is_Fixed_Point_Type
(Typ
) then
2505 Check_Restriction
(No_Fixed_Point
, N
);
2507 elsif Is_Floating_Point_Type
(Typ
)
2508 and then Typ
/= Universal_Real
2509 and then Typ
/= Any_Real
2511 Check_Restriction
(No_Floating_Point
, N
);
2515 -- Return if already analyzed
2517 if Analyzed
(N
) then
2518 Debug_A_Exit
("resolving ", N
, " (done, already analyzed)");
2519 Analyze_Dimension
(N
);
2522 -- Any case of Any_Type as the Etype value means that we had a
2525 elsif Etype
(N
) = Any_Type
then
2526 Debug_A_Exit
("resolving ", N
, " (done, Etype = Any_Type)");
2530 Check_Parameterless_Call
(N
);
2532 -- The resolution of an Expression_With_Actions is determined by
2533 -- its Expression, but if the node comes from source it is a
2534 -- Declare_Expression and requires scope management.
2536 if Nkind
(N
) = N_Expression_With_Actions
then
2537 if Comes_From_Source
(N
) and then not Is_Rewrite_Substitution
(N
) then
2538 Resolve_Declare_Expression
(N
, Typ
);
2540 Resolve
(Expression
(N
), Typ
);
2544 Expr_Type
:= Etype
(Expression
(N
));
2546 -- The resolution of a conditional expression that is the operand of a
2547 -- type conversion is determined by the conversion (RM 4.5.7(10/3)).
2549 elsif Nkind
(N
) in N_Case_Expression | N_If_Expression
2550 and then Nkind
(Parent
(N
)) = N_Type_Conversion
2553 Expr_Type
:= Etype
(Parent
(N
));
2555 -- If not overloaded, then we know the type, and all that needs doing
2556 -- is to check that this type is compatible with the context. But note
2557 -- that we may have an operator with no interpretation in Ada 2022 for
2558 -- the case of possible user-defined literals as operands.
2560 elsif not Is_Overloaded
(N
) then
2561 if Nkind
(N
) in N_Op
and then No
(Entity
(N
)) then
2562 pragma Assert
(Ada_Version
>= Ada_2022
);
2564 elsif not Comes_From_Source
(N
) and then
2565 Original_Implementation_Base_Type
(Typ
) =
2566 Original_Implementation_Base_Type
(Etype
(N
))
2568 -- Ignore privacy for streaming or Put_Image routines
2571 Found
:= Covers
(Typ
, Etype
(N
));
2574 Expr_Type
:= Etype
(N
);
2576 -- In the overloaded case, we must select the interpretation that
2577 -- is compatible with the context (i.e. the type passed to Resolve)
2580 From_Lib
:= Comes_From_Predefined_Lib_Unit
(N
);
2582 -- Loop through possible interpretations
2584 Get_First_Interp
(N
, I
, It
);
2585 Interp_Loop
: while Present
(It
.Typ
) loop
2586 if Debug_Flag_V
then
2587 Write_Str
("Interp: ");
2591 -- We are only interested in interpretations that are compatible
2592 -- with the expected type, any other interpretations are ignored.
2594 if not Covers
(Typ
, It
.Typ
) then
2595 if Debug_Flag_V
then
2596 Write_Str
(" interpretation incompatible with context");
2601 -- Skip the current interpretation if it is disabled by an
2602 -- abstract operator. This action is performed only when the
2603 -- type against which we are resolving is the same as the
2604 -- type of the interpretation.
2606 if Ada_Version
>= Ada_2005
2607 and then It
.Typ
= Typ
2608 and then not Is_Universal_Numeric_Type
(Typ
)
2609 and then Present
(It
.Abstract_Op
)
2611 if Debug_Flag_V
then
2612 Write_Line
("Skip.");
2618 -- First matching interpretation
2624 Expr_Type
:= It
.Typ
;
2626 -- Matching interpretation that is not the first, maybe an
2627 -- error, but there are some cases where preference rules are
2628 -- used to choose between the two possibilities. These and
2629 -- some more obscure cases are handled in Disambiguate.
2632 -- If the current statement is part of a predefined library
2633 -- unit, then all interpretations which come from user level
2634 -- packages should not be considered. Check previous and
2638 if not Comes_From_Predefined_Lib_Unit
(It
.Nam
) then
2641 elsif not Comes_From_Predefined_Lib_Unit
(Seen
) then
2643 -- Previous interpretation must be discarded
2647 Expr_Type
:= It
.Typ
;
2648 Set_Entity
(N
, Seen
);
2653 -- Otherwise apply further disambiguation steps
2655 Error_Msg_Sloc
:= Sloc
(Seen
);
2656 It1
:= Disambiguate
(N
, I1
, I
, Typ
);
2658 -- Disambiguation has succeeded. Skip the remaining
2661 if It1
/= No_Interp
then
2663 Expr_Type
:= It1
.Typ
;
2665 while Present
(It
.Typ
) loop
2666 Get_Next_Interp
(I
, It
);
2670 -- Before we issue an ambiguity complaint, check for the
2671 -- case of a subprogram call where at least one of the
2672 -- arguments is Any_Type, and if so suppress the message,
2673 -- since it is a cascaded error. This can also happen for
2674 -- a generalized indexing operation.
2676 if Nkind
(N
) in N_Subprogram_Call
2677 or else (Nkind
(N
) = N_Indexed_Component
2678 and then Present
(Generalized_Indexing
(N
)))
2685 if Nkind
(N
) = N_Indexed_Component
then
2686 Rewrite
(N
, Generalized_Indexing
(N
));
2689 A
:= First_Actual
(N
);
2690 while Present
(A
) loop
2693 if Nkind
(E
) = N_Parameter_Association
then
2694 E
:= Explicit_Actual_Parameter
(E
);
2697 if Etype
(E
) = Any_Type
then
2698 if Debug_Flag_V
then
2699 Write_Str
("Any_Type in call");
2710 elsif Nkind
(N
) in N_Binary_Op
2711 and then (Etype
(Left_Opnd
(N
)) = Any_Type
2712 or else Etype
(Right_Opnd
(N
)) = Any_Type
)
2716 elsif Nkind
(N
) in N_Unary_Op
2717 and then Etype
(Right_Opnd
(N
)) = Any_Type
2722 -- Not that special case, so issue message using the flag
2723 -- Ambiguous to control printing of the header message
2724 -- only at the start of an ambiguous set.
2726 if not Ambiguous
then
2727 if Nkind
(N
) = N_Function_Call
2728 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2731 ("ambiguous expression (cannot resolve indirect "
2734 Error_Msg_NE
-- CODEFIX
2735 ("ambiguous expression (cannot resolve&)!",
2741 if Nkind
(Parent
(Seen
)) = N_Full_Type_Declaration
then
2743 ("\\possible interpretation (inherited)#!", N
);
2745 Error_Msg_N
-- CODEFIX
2746 ("\\possible interpretation#!", N
);
2749 if Nkind
(N
) in N_Subprogram_Call
2750 and then Present
(Parameter_Associations
(N
))
2752 Report_Ambiguous_Argument
;
2756 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2758 -- By default, the error message refers to the candidate
2759 -- interpretation. But if it is a predefined operator, it
2760 -- is implicitly declared at the declaration of the type
2761 -- of the operand. Recover the sloc of that declaration
2762 -- for the error message.
2764 if Nkind
(N
) in N_Op
2765 and then Scope
(It
.Nam
) = Standard_Standard
2766 and then not Is_Overloaded
(Right_Opnd
(N
))
2767 and then Scope
(Base_Type
(Etype
(Right_Opnd
(N
)))) /=
2770 Err_Type
:= First_Subtype
(Etype
(Right_Opnd
(N
)));
2772 if Comes_From_Source
(Err_Type
)
2773 and then Present
(Parent
(Err_Type
))
2775 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2778 elsif Nkind
(N
) in N_Binary_Op
2779 and then Scope
(It
.Nam
) = Standard_Standard
2780 and then not Is_Overloaded
(Left_Opnd
(N
))
2781 and then Scope
(Base_Type
(Etype
(Left_Opnd
(N
)))) /=
2784 Err_Type
:= First_Subtype
(Etype
(Left_Opnd
(N
)));
2786 if Comes_From_Source
(Err_Type
)
2787 and then Present
(Parent
(Err_Type
))
2789 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2792 -- If this is an indirect call, use the subprogram_type
2793 -- in the message, to have a meaningful location. Also
2794 -- indicate if this is an inherited operation, created
2795 -- by a type declaration.
2797 elsif Nkind
(N
) = N_Function_Call
2798 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2799 and then Is_Type
(It
.Nam
)
2803 Sloc
(Associated_Node_For_Itype
(Err_Type
));
2808 if Nkind
(N
) in N_Op
2809 and then Scope
(It
.Nam
) = Standard_Standard
2810 and then Present
(Err_Type
)
2812 -- Special-case the message for universal_fixed
2813 -- operators, which are not declared with the type
2814 -- of the operand, but appear forever in Standard.
2816 if It
.Typ
= Universal_Fixed
2817 and then Scope
(It
.Nam
) = Standard_Standard
2820 ("\\possible interpretation as universal_fixed "
2821 & "operation (RM 4.5.5 (19))", N
);
2824 ("\\possible interpretation (predefined)#!", N
);
2828 Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
2831 ("\\possible interpretation (inherited)#!", N
);
2833 Error_Msg_N
-- CODEFIX
2834 ("\\possible interpretation#!", N
);
2840 -- We have a matching interpretation, Expr_Type is the type
2841 -- from this interpretation, and Seen is the entity.
2843 -- For an operator, just set the entity name. The type will be
2844 -- set by the specific operator resolution routine.
2846 if Nkind
(N
) in N_Op
then
2847 Set_Entity
(N
, Seen
);
2848 Generate_Reference
(Seen
, N
);
2850 elsif Nkind
(N
) in N_Case_Expression
2851 | N_Character_Literal
2855 Set_Etype
(N
, Expr_Type
);
2857 -- AI05-0139-2: Expression is overloaded because type has
2858 -- implicit dereference. The context may be the one that
2859 -- requires implicit dereferemce.
2861 elsif Has_Implicit_Dereference
(Expr_Type
) then
2862 Set_Etype
(N
, Expr_Type
);
2863 Set_Is_Overloaded
(N
, False);
2865 -- If the expression is an entity, generate a reference
2866 -- to it, as this is not done for an overloaded construct
2869 if Is_Entity_Name
(N
)
2870 and then Comes_From_Source
(N
)
2872 Generate_Reference
(Entity
(N
), N
);
2874 -- Examine access discriminants of entity type,
2875 -- to check whether one of them yields the
2880 First_Discriminant
(Etype
(Entity
(N
)));
2883 while Present
(Disc
) loop
2884 exit when Is_Access_Type
(Etype
(Disc
))
2885 and then Has_Implicit_Dereference
(Disc
)
2886 and then Designated_Type
(Etype
(Disc
)) = Typ
;
2888 Next_Discriminant
(Disc
);
2891 if Present
(Disc
) then
2892 Build_Explicit_Dereference
(N
, Disc
);
2899 elsif Is_Overloaded
(N
)
2900 and then Present
(It
.Nam
)
2901 and then Ekind
(It
.Nam
) = E_Discriminant
2902 and then Has_Implicit_Dereference
(It
.Nam
)
2904 -- If the node is a general indexing, the dereference is
2905 -- is inserted when resolving the rewritten form, else
2908 if Nkind
(N
) /= N_Indexed_Component
2909 or else No
(Generalized_Indexing
(N
))
2911 Build_Explicit_Dereference
(N
, It
.Nam
);
2914 -- For an explicit dereference, attribute reference, range,
2915 -- short-circuit form (which is not an operator node), or call
2916 -- with a name that is an explicit dereference, there is
2917 -- nothing to be done at this point.
2919 elsif Nkind
(N
) in N_Attribute_Reference
2921 | N_Explicit_Dereference
2923 | N_Indexed_Component
2926 | N_Selected_Component
2928 or else Nkind
(Name
(N
)) = N_Explicit_Dereference
2932 -- For procedure or function calls, set the type of the name,
2933 -- and also the entity pointer for the prefix.
2935 elsif Nkind
(N
) in N_Subprogram_Call
2936 and then Is_Entity_Name
(Name
(N
))
2938 Set_Etype
(Name
(N
), Expr_Type
);
2939 Set_Entity
(Name
(N
), Seen
);
2940 Generate_Reference
(Seen
, Name
(N
));
2942 elsif Nkind
(N
) = N_Function_Call
2943 and then Nkind
(Name
(N
)) = N_Selected_Component
2945 Set_Etype
(Name
(N
), Expr_Type
);
2946 Set_Entity
(Selector_Name
(Name
(N
)), Seen
);
2947 Generate_Reference
(Seen
, Selector_Name
(Name
(N
)));
2949 -- For all other cases, just set the type of the Name
2952 Set_Etype
(Name
(N
), Expr_Type
);
2959 -- Move to next interpretation
2961 exit Interp_Loop
when No
(It
.Typ
);
2963 Get_Next_Interp
(I
, It
);
2964 end loop Interp_Loop
;
2967 -- At this stage Found indicates whether or not an acceptable
2968 -- interpretation exists. If not, then we have an error, except that if
2969 -- the context is Any_Type as a result of some other error, then we
2970 -- suppress the error report.
2973 if Typ
/= Any_Type
then
2975 -- If type we are looking for is Void, then this is the procedure
2976 -- call case, and the error is simply that what we gave is not a
2977 -- procedure name (we think of procedure calls as expressions with
2978 -- types internally, but the user doesn't think of them this way).
2980 if Typ
= Standard_Void_Type
then
2982 -- Special case message if function used as a procedure
2984 if Nkind
(N
) = N_Procedure_Call_Statement
2985 and then Is_Entity_Name
(Name
(N
))
2986 and then Ekind
(Entity
(Name
(N
))) = E_Function
2989 ("cannot use call to function & as a statement",
2990 Name
(N
), Entity
(Name
(N
)));
2992 ("\return value of a function call cannot be ignored",
2995 -- Otherwise give general message (not clear what cases this
2996 -- covers, but no harm in providing for them).
2999 Error_Msg_N
("expect procedure name in procedure call", N
);
3004 -- Otherwise we do have a subexpression with the wrong type
3006 -- Check for the case of an allocator which uses an access type
3007 -- instead of the designated type. This is a common error and we
3008 -- specialize the message, posting an error on the operand of the
3009 -- allocator, complaining that we expected the designated type of
3012 elsif Nkind
(N
) = N_Allocator
3013 and then Is_Access_Type
(Typ
)
3014 and then Is_Access_Type
(Etype
(N
))
3015 and then Designated_Type
(Etype
(N
)) = Typ
3017 Wrong_Type
(Expression
(N
), Designated_Type
(Typ
));
3020 -- Check for view mismatch on Null in instances, for which the
3021 -- view-swapping mechanism has no identifier.
3023 elsif (In_Instance
or else In_Inlined_Body
)
3024 and then Nkind
(N
) = N_Null
3025 and then Is_Private_Type
(Typ
)
3026 and then Is_Access_Type
(Full_View
(Typ
))
3028 Resolve
(N
, Full_View
(Typ
));
3032 -- Check for an aggregate. Sometimes we can get bogus aggregates
3033 -- from misuse of parentheses, and we are about to complain about
3034 -- the aggregate without even looking inside it.
3036 -- Instead, if we have an aggregate of type Any_Composite, then
3037 -- analyze and resolve the component fields, and then only issue
3038 -- another message if we get no errors doing this (otherwise
3039 -- assume that the errors in the aggregate caused the problem).
3041 elsif Nkind
(N
) = N_Aggregate
3042 and then Etype
(N
) = Any_Composite
3044 if Ada_Version
>= Ada_2022
3045 and then Has_Aspect
(Typ
, Aspect_Aggregate
)
3047 Resolve_Container_Aggregate
(N
, Typ
);
3049 if Expander_Active
then
3055 -- Disable expansion in any case. If there is a type mismatch
3056 -- it may be fatal to try to expand the aggregate. The flag
3057 -- would otherwise be set to false when the error is posted.
3059 Expander_Active
:= False;
3062 procedure Check_Aggr
(Aggr
: Node_Id
);
3063 -- Check one aggregate, and set Found to True if we have a
3064 -- definite error in any of its elements
3066 procedure Check_Elmt
(Aelmt
: Node_Id
);
3067 -- Check one element of aggregate and set Found to True if
3068 -- we definitely have an error in the element.
3074 procedure Check_Aggr
(Aggr
: Node_Id
) is
3078 if Present
(Expressions
(Aggr
)) then
3079 Elmt
:= First
(Expressions
(Aggr
));
3080 while Present
(Elmt
) loop
3086 if Present
(Component_Associations
(Aggr
)) then
3087 Elmt
:= First
(Component_Associations
(Aggr
));
3088 while Present
(Elmt
) loop
3090 -- If this is a default-initialized component, then
3091 -- there is nothing to check. The box will be
3092 -- replaced by the appropriate call during late
3095 if Nkind
(Elmt
) /= N_Iterated_Component_Association
3096 and then not Box_Present
(Elmt
)
3098 Check_Elmt
(Expression
(Elmt
));
3110 procedure Check_Elmt
(Aelmt
: Node_Id
) is
3112 -- If we have a nested aggregate, go inside it (to
3113 -- attempt a naked analyze-resolve of the aggregate can
3114 -- cause undesirable cascaded errors). Do not resolve
3115 -- expression if it needs a type from context, as for
3116 -- integer * fixed expression.
3118 if Nkind
(Aelmt
) = N_Aggregate
then
3124 if not Is_Overloaded
(Aelmt
)
3125 and then Etype
(Aelmt
) /= Any_Fixed
3130 if Etype
(Aelmt
) = Any_Type
then
3141 -- Check whether the node is a literal or a named number or a
3142 -- conditional expression whose dependent expressions are all
3143 -- literals or named numbers.
3145 if Try_User_Defined_Literal
(N
, Typ
) then
3149 -- Looks like we have a type error, but check for special case
3150 -- of Address wanted, integer found, with the configuration pragma
3151 -- Allow_Integer_Address active. If we have this case, introduce
3152 -- an unchecked conversion to allow the integer expression to be
3153 -- treated as an Address. The reverse case of integer wanted,
3154 -- Address found, is treated in an analogous manner.
3156 if Address_Integer_Convert_OK
(Typ
, Etype
(N
)) then
3157 Rewrite
(N
, Unchecked_Convert_To
(Typ
, Relocate_Node
(N
)));
3158 Analyze_And_Resolve
(N
, Typ
);
3161 -- Under relaxed RM semantics silently replace occurrences of null
3162 -- by System.Null_Address.
3164 elsif Null_To_Null_Address_Convert_OK
(N
, Typ
) then
3165 Replace_Null_By_Null_Address
(N
);
3166 Analyze_And_Resolve
(N
, Typ
);
3170 -- That special Allow_Integer_Address check did not apply, so we
3171 -- have a real type error. If an error message was issued already,
3172 -- Found got reset to True, so if it's still False, issue standard
3173 -- Wrong_Type message.
3176 if Is_Overloaded
(N
) and then Nkind
(N
) = N_Function_Call
then
3178 Subp_Name
: Node_Id
;
3181 if Is_Entity_Name
(Name
(N
)) then
3182 Subp_Name
:= Name
(N
);
3184 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
3186 -- Protected operation: retrieve operation name
3188 Subp_Name
:= Selector_Name
(Name
(N
));
3191 raise Program_Error
;
3194 Error_Msg_Node_2
:= Typ
;
3196 ("no visible interpretation of& matches expected type&",
3200 if All_Errors_Mode
then
3202 Index
: Interp_Index
;
3206 Error_Msg_N
("\\possible interpretations:", N
);
3208 Get_First_Interp
(Name
(N
), Index
, It
);
3209 while Present
(It
.Nam
) loop
3210 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
3211 Error_Msg_Node_2
:= It
.Nam
;
3213 ("\\ type& for & declared#", N
, It
.Typ
);
3214 Get_Next_Interp
(Index
, It
);
3219 Error_Msg_N
("\use -gnatf for details", N
);
3222 -- Recognize the case of a quantified expression being mistaken
3223 -- for an iterated component association because the user
3224 -- forgot the "all" or "some" keyword after "for". Because the
3225 -- error message starts with "missing ALL", we automatically
3226 -- benefit from the associated CODEFIX, which requires that
3227 -- the message is located on the identifier following "for"
3228 -- in order for the CODEFIX to insert "all" in the right place.
3230 elsif Nkind
(N
) = N_Aggregate
3231 and then List_Length
(Component_Associations
(N
)) = 1
3232 and then Nkind
(First
(Component_Associations
(N
)))
3233 = N_Iterated_Component_Association
3234 and then Is_Boolean_Type
(Typ
)
3237 (Iterator_Specification
3238 (First
(Component_Associations
(N
))))
3240 Error_Msg_N
-- CODEFIX
3241 ("missing ALL or SOME in quantified expression",
3243 (Iterator_Specification
3244 (First
(Component_Associations
(N
)))));
3246 Error_Msg_N
-- CODEFIX
3247 ("missing ALL or SOME in quantified expression",
3249 (First
(Component_Associations
(N
))));
3252 -- For an operator with no interpretation, check whether one of
3253 -- its operands may be a user-defined literal.
3255 elsif Nkind
(N
) in N_Op
and then No
(Entity
(N
)) then
3256 if Try_User_Defined_Literal_For_Operator
(N
, Typ
) then
3259 Unresolved_Operator
(N
);
3263 Wrong_Type
(N
, Typ
);
3271 -- Test if we have more than one interpretation for the context
3273 elsif Ambiguous
then
3277 -- Only one interpretation
3280 -- Prevent implicit conversions between access-to-subprogram types
3281 -- with different strub modes. Explicit conversions are acceptable in
3282 -- some circumstances. We don't have to be concerned about data or
3283 -- access-to-data types. Conversions between data types can safely
3284 -- drop or add strub attributes from types, because strub effects are
3285 -- associated with the locations rather than values. E.g., converting
3286 -- a hypothetical Strub_Integer variable to Integer would load the
3287 -- value from the variable, enabling stack scrabbing for the
3288 -- enclosing subprogram, and then convert the value to Integer. As
3289 -- for conversions between access-to-data types, that's no different
3290 -- from any other case of type punning.
3292 if Is_Access_Type
(Typ
)
3293 and then Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
3294 and then Is_Access_Type
(Expr_Type
)
3295 and then Ekind
(Designated_Type
(Expr_Type
)) = E_Subprogram_Type
3297 Check_Same_Strub_Mode
3298 (Designated_Type
(Typ
), Designated_Type
(Expr_Type
));
3301 -- In Ada 2005, if we have something like "X : T := 2 + 2;", where
3302 -- the "+" on T is abstract, and the operands are of universal type,
3303 -- the above code will have (incorrectly) resolved the "+" to the
3304 -- universal one in Standard. Therefore check for this case and give
3305 -- an error. We can't do this earlier, because it would cause legal
3306 -- cases to get errors (when some other type has an abstract "+").
3308 if Ada_Version
>= Ada_2005
3309 and then Nkind
(N
) in N_Op
3310 and then Is_Overloaded
(N
)
3311 and then Is_Universal_Numeric_Type
(Etype
(Entity
(N
)))
3313 Get_First_Interp
(N
, I
, It
);
3314 while Present
(It
.Typ
) loop
3315 if Present
(It
.Abstract_Op
)
3316 and then Etype
(It
.Abstract_Op
) = Typ
3318 Nondispatching_Call_To_Abstract_Operation
3319 (N
, It
.Abstract_Op
);
3323 Get_Next_Interp
(I
, It
);
3327 -- Here we have an acceptable interpretation for the context
3329 -- Propagate type information and normalize tree for various
3330 -- predefined operations. If the context only imposes a class of
3331 -- types, rather than a specific type, propagate the actual type
3334 if Typ
= Any_Integer
or else
3335 Typ
= Any_Boolean
or else
3336 Typ
= Any_Modular
or else
3337 Typ
= Any_Real
or else
3340 Ctx_Type
:= Expr_Type
;
3342 -- Any_Fixed is legal in a real context only if a specific fixed-
3343 -- point type is imposed. If Norman Cohen can be confused by this,
3344 -- it deserves a separate message.
3347 and then Expr_Type
= Any_Fixed
3349 Error_Msg_N
("illegal context for mixed mode operation", N
);
3350 Set_Etype
(N
, Universal_Real
);
3351 Ctx_Type
:= Universal_Real
;
3355 -- A user-defined operator is transformed into a function call at
3356 -- this point, so that further processing knows that operators are
3357 -- really operators (i.e. are predefined operators). User-defined
3358 -- operators that are intrinsic are just renamings of the predefined
3359 -- ones, and need not be turned into calls either, but if they rename
3360 -- a different operator, we must transform the node accordingly.
3361 -- Instantiations of Unchecked_Conversion are intrinsic but are
3362 -- treated as functions, even if given an operator designator.
3364 if Nkind
(N
) in N_Op
3365 and then Present
(Entity
(N
))
3366 and then Ekind
(Entity
(N
)) /= E_Operator
3368 if not Is_Predefined_Op
(Entity
(N
)) then
3369 Rewrite_Operator_As_Call
(N
, Entity
(N
));
3371 elsif Present
(Alias
(Entity
(N
)))
3373 Nkind
(Parent
(Parent
(Entity
(N
)))) =
3374 N_Subprogram_Renaming_Declaration
3376 Rewrite_Renamed_Operator
(N
, Alias
(Entity
(N
)), Typ
);
3378 -- If the node is rewritten, it will be fully resolved in
3379 -- Rewrite_Renamed_Operator.
3381 if Analyzed
(N
) then
3387 case N_Subexpr
'(Nkind (N)) is
3389 Resolve_Aggregate (N, Ctx_Type);
3392 Resolve_Allocator (N, Ctx_Type);
3394 when N_Short_Circuit =>
3395 Resolve_Short_Circuit (N, Ctx_Type);
3397 when N_Attribute_Reference =>
3398 Resolve_Attribute (N, Ctx_Type);
3400 when N_Case_Expression =>
3401 Resolve_Case_Expression (N, Ctx_Type);
3403 when N_Character_Literal =>
3404 Resolve_Character_Literal (N, Ctx_Type);
3406 when N_Delta_Aggregate =>
3407 Resolve_Delta_Aggregate (N, Ctx_Type);
3409 when N_Expanded_Name =>
3410 Resolve_Entity_Name (N, Ctx_Type);
3412 when N_Explicit_Dereference =>
3413 Resolve_Explicit_Dereference (N, Ctx_Type);
3415 when N_Expression_With_Actions =>
3416 Resolve_Expression_With_Actions (N, Ctx_Type);
3418 when N_Extension_Aggregate =>
3419 Resolve_Extension_Aggregate (N, Ctx_Type);
3421 when N_External_Initializer =>
3422 Resolve_External_Initializer (N, Ctx_Type);
3424 when N_Function_Call =>
3425 Resolve_Call (N, Ctx_Type);
3427 when N_Identifier =>
3428 Resolve_Entity_Name (N, Ctx_Type);
3430 when N_If_Expression =>
3431 Resolve_If_Expression (N, Ctx_Type);
3433 when N_Indexed_Component =>
3434 Resolve_Indexed_Component (N, Ctx_Type);
3436 when N_Integer_Literal =>
3437 Resolve_Integer_Literal (N, Ctx_Type);
3439 when N_Membership_Test =>
3440 Resolve_Membership_Op (N, Ctx_Type);
3443 Resolve_Null (N, Ctx_Type);
3449 Resolve_Logical_Op (N, Ctx_Type);
3454 Resolve_Equality_Op (N, Ctx_Type);
3461 Resolve_Comparison_Op (N, Ctx_Type);
3464 Resolve_Op_Not (N, Ctx_Type);
3473 Resolve_Arithmetic_Op (N, Ctx_Type);
3476 Resolve_Op_Concat (N, Ctx_Type);
3479 Resolve_Op_Expon (N, Ctx_Type);
3485 Resolve_Unary_Op (N, Ctx_Type);
3488 Resolve_Shift (N, Ctx_Type);
3490 when N_Procedure_Call_Statement =>
3491 Resolve_Call (N, Ctx_Type);
3493 when N_Operator_Symbol =>
3494 Resolve_Operator_Symbol (N, Ctx_Type);
3496 when N_Qualified_Expression =>
3497 Resolve_Qualified_Expression (N, Ctx_Type);
3499 -- Why is the following null, needs a comment ???
3501 when N_Quantified_Expression =>
3504 when N_Raise_Expression =>
3505 Resolve_Raise_Expression (N, Ctx_Type);
3507 when N_Raise_xxx_Error =>
3508 Set_Etype (N, Ctx_Type);
3511 Resolve_Range (N, Ctx_Type);
3513 when N_Real_Literal =>
3514 Resolve_Real_Literal (N, Ctx_Type);
3517 Resolve_Reference (N, Ctx_Type);
3519 when N_Selected_Component =>
3520 Resolve_Selected_Component (N, Ctx_Type);
3523 Resolve_Slice (N, Ctx_Type);
3525 when N_String_Literal =>
3526 Resolve_String_Literal (N, Ctx_Type);
3528 when N_Interpolated_String_Literal =>
3529 Resolve_Interpolated_String_Literal (N, Ctx_Type);
3531 when N_Target_Name =>
3532 Resolve_Target_Name (N, Ctx_Type);
3534 when N_Type_Conversion =>
3535 Resolve_Type_Conversion (N, Ctx_Type);
3537 when N_Unchecked_Expression =>
3538 Resolve_Unchecked_Expression (N, Ctx_Type);
3540 when N_Unchecked_Type_Conversion =>
3541 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
3544 -- Mark relevant use-type and use-package clauses as effective using
3545 -- the original node because constant folding may have occurred and
3546 -- removed references that need to be examined.
3548 if Nkind (Original_Node (N)) in N_Op then
3549 Mark_Use_Clauses (Original_Node (N));
3552 -- Ada 2012 (AI05-0149): Apply an (implicit) conversion to an
3553 -- expression of an anonymous access type that occurs in the context
3554 -- of a named general access type, except when the expression is that
3555 -- of a membership test. This ensures proper legality checking in
3556 -- terms of allowed conversions (expressions that would be illegal to
3557 -- convert implicitly are allowed in membership tests).
3559 if Ada_Version >= Ada_2012
3560 and then Ekind (Base_Type (Ctx_Type)) = E_General_Access_Type
3561 and then Ekind (Etype (N)) = E_Anonymous_Access_Type
3562 and then Nkind (Parent (N)) not in N_Membership_Test
3564 Rewrite (N, Convert_To (Ctx_Type, Relocate_Node (N)));
3565 Analyze_And_Resolve (N, Ctx_Type);
3568 -- If the subexpression was replaced by a non-subexpression, then
3569 -- all we do is to expand it. The only legitimate case we know of
3570 -- is converting procedure call statement to entry call statements,
3571 -- but there may be others, so we are making this test general.
3573 if Nkind (N) not in N_Subexpr then
3574 Debug_A_Exit ("resolving ", N, " (done)");
3579 -- The expression is definitely NOT overloaded at this point, so
3580 -- we reset the Is_Overloaded flag to avoid any confusion when
3581 -- reanalyzing the node.
3583 Set_Is_Overloaded (N, False);
3585 -- Freeze expression type, entity if it is a name, and designated
3586 -- type if it is an allocator (RM 13.14(10,11,13)).
3588 -- Now that the resolution of the type of the node is complete, and
3589 -- we did not detect an error, we can expand this node. We skip the
3590 -- expand call if we are in a default expression, see section
3591 -- "Handling of Default Expressions" in Sem spec.
3593 Debug_A_Exit ("resolving ", N, " (done)");
3595 -- We unconditionally freeze the expression, even if we are in
3596 -- default expression mode (the Freeze_Expression routine tests this
3597 -- flag and only freezes static types if it is set).
3599 -- Ada 2012 (AI05-177): The declaration of an expression function
3600 -- does not cause freezing, but we never reach here in that case.
3601 -- Here we are resolving the corresponding expanded body, so we do
3602 -- need to perform normal freezing.
3604 -- As elsewhere we do not emit freeze node within a generic.
3606 if not Inside_A_Generic then
3607 Freeze_Expression (N);
3610 -- Now we can do the expansion
3620 -- Version with check(s) suppressed
3622 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
3624 if Suppress = All_Checks then
3626 Sva : constant Suppress_Array := Scope_Suppress.Suppress;
3628 Scope_Suppress.Suppress := (others => True);
3630 Scope_Suppress.Suppress := Sva;
3635 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
3637 Scope_Suppress.Suppress (Suppress) := True;
3639 Scope_Suppress.Suppress (Suppress) := Svg;
3648 -- Version with implicit type
3650 procedure Resolve (N : Node_Id) is
3652 Resolve (N, Etype (N));
3655 ---------------------
3656 -- Resolve_Actuals --
3657 ---------------------
3659 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
3660 Loc : constant Source_Ptr := Sloc (N);
3662 A_Typ : Entity_Id := Empty; -- init to avoid warning
3665 Prev : Node_Id := Empty;
3667 Real_F : Entity_Id := Empty; -- init to avoid warning
3669 Real_Subp : Entity_Id;
3670 -- If the subprogram being called is an inherited operation for
3671 -- a formal derived type in an instance, Real_Subp is the subprogram
3672 -- that will be called. It may have different formal names than the
3673 -- operation of the formal in the generic, so after actual is resolved
3674 -- the name of the actual in a named association must carry the name
3675 -- of the actual of the subprogram being called.
3677 procedure Check_Aliased_Parameter;
3678 -- Check rules on aliased parameters and related accessibility rules
3679 -- in (RM 3.10.2 (10.2-10.4)).
3681 procedure Check_Argument_Order;
3682 -- Performs a check for the case where the actuals are all simple
3683 -- identifiers that correspond to the formal names, but in the wrong
3684 -- order, which is considered suspicious and cause for a warning.
3686 procedure Check_Prefixed_Call;
3687 -- If the original node is an overloaded call in prefix notation,
3688 -- insert an 'Access or a dereference as needed over the first actual
.
3689 -- Try_Object_Operation has already verified that there is a valid
3690 -- interpretation, but the form of the actual can only be determined
3691 -- once the primitive operation is identified.
3693 procedure Insert_Default
;
3694 -- If the actual is missing in a call, insert in the actuals list
3695 -- an instance of the default expression. The insertion is always
3696 -- a named association.
3698 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean;
3699 -- Check whether T1 and T2, or their full views, are derived from a
3700 -- common type. Used to enforce the restrictions on array conversions
3703 function Static_Concatenation
(N
: Node_Id
) return Boolean;
3704 -- Predicate to determine whether an actual that is a concatenation
3705 -- will be evaluated statically and does not need a transient scope.
3706 -- This must be determined before the actual is resolved and expanded
3707 -- because if needed the transient scope must be introduced earlier.
3709 -----------------------------
3710 -- Check_Aliased_Parameter --
3711 -----------------------------
3713 procedure Check_Aliased_Parameter
is
3714 Nominal_Subt
: Entity_Id
;
3717 if Is_Aliased
(F
) then
3718 if Is_Tagged_Type
(A_Typ
) then
3721 elsif Is_Aliased_View
(A
) then
3722 if Is_Constr_Subt_For_U_Nominal
(A_Typ
) then
3723 Nominal_Subt
:= Base_Type
(A_Typ
);
3725 Nominal_Subt
:= A_Typ
;
3728 if Subtypes_Statically_Match
(F_Typ
, Nominal_Subt
) then
3731 -- In a generic body assume the worst for generic formals:
3732 -- they can have a constrained partial view (AI05-041).
3734 elsif Has_Discriminants
(F_Typ
)
3735 and then not Is_Constrained
(F_Typ
)
3736 and then not Object_Type_Has_Constrained_Partial_View
3737 (Typ
=> F_Typ
, Scop
=> Current_Scope
)
3742 Error_Msg_NE
("untagged actual does not statically match "
3743 & "aliased formal&", A
, F
);
3747 Error_Msg_NE
("actual for aliased formal& must be "
3748 & "aliased object", A
, F
);
3751 if Ekind
(Nam
) = E_Procedure
then
3754 elsif Ekind
(Etype
(Nam
)) = E_Anonymous_Access_Type
then
3755 if Nkind
(Parent
(N
)) = N_Type_Conversion
3756 and then Type_Access_Level
(Etype
(Parent
(N
)))
3757 < Static_Accessibility_Level
(A
, Object_Decl_Level
)
3759 Error_Msg_N
("aliased actual has wrong accessibility", A
);
3762 elsif Nkind
(Parent
(N
)) = N_Qualified_Expression
3763 and then Nkind
(Parent
(Parent
(N
))) = N_Allocator
3764 and then Type_Access_Level
(Etype
(Parent
(Parent
(N
))))
3765 < Static_Accessibility_Level
(A
, Object_Decl_Level
)
3768 ("aliased actual in allocator has wrong accessibility", A
);
3771 end Check_Aliased_Parameter
;
3773 --------------------------
3774 -- Check_Argument_Order --
3775 --------------------------
3777 procedure Check_Argument_Order
is
3779 -- Nothing to do if no parameters, or original node is neither a
3780 -- function call nor a procedure call statement (happens in the
3781 -- operator-transformed-to-function call case), or the call is to an
3782 -- operator symbol (which is usually in infix form), or the call does
3783 -- not come from source, or this warning is off.
3785 if not Warn_On_Parameter_Order
3786 or else No
(Parameter_Associations
(N
))
3787 or else Nkind
(Original_Node
(N
)) not in N_Subprogram_Call
3788 or else (Nkind
(Name
(N
)) = N_Identifier
3789 and then Present
(Entity
(Name
(N
)))
3790 and then Nkind
(Entity
(Name
(N
))) =
3791 N_Defining_Operator_Symbol
)
3792 or else not Comes_From_Source
(N
)
3798 Nargs
: constant Nat
:= List_Length
(Parameter_Associations
(N
));
3801 -- Nothing to do if only one parameter
3807 -- Here if at least two arguments
3810 Actuals
: array (1 .. Nargs
) of Node_Id
;
3814 Wrong_Order
: Boolean := False;
3815 -- Set True if an out of order case is found
3818 -- Collect identifier names of actuals, fail if any actual is
3819 -- not a simple identifier, and record max length of name.
3821 Actual
:= First
(Parameter_Associations
(N
));
3822 for J
in Actuals
'Range loop
3823 if Nkind
(Actual
) /= N_Identifier
then
3826 Actuals
(J
) := Actual
;
3831 -- If we got this far, all actuals are identifiers and the list
3832 -- of their names is stored in the Actuals array.
3834 Formal
:= First_Formal
(Nam
);
3835 for J
in Actuals
'Range loop
3837 -- If we ran out of formals, that's odd, probably an error
3838 -- which will be detected elsewhere, but abandon the search.
3844 -- If name matches and is in order OK
3846 if Chars
(Formal
) = Chars
(Actuals
(J
)) then
3850 -- If no match, see if it is elsewhere in list and if so
3851 -- flag potential wrong order if type is compatible.
3853 for K
in Actuals
'Range loop
3854 if Chars
(Formal
) = Chars
(Actuals
(K
))
3856 Has_Compatible_Type
(Actuals
(K
), Etype
(Formal
))
3858 Wrong_Order
:= True;
3868 <<Continue
>> Next_Formal
(Formal
);
3871 -- If Formals left over, also probably an error, skip warning
3873 if Present
(Formal
) then
3877 -- Here we give the warning if something was out of order
3881 ("?.p?actuals for this call may be in wrong order", N
);
3885 end Check_Argument_Order
;
3887 -------------------------
3888 -- Check_Prefixed_Call --
3889 -------------------------
3891 procedure Check_Prefixed_Call
is
3892 Actual
: constant Node_Id
:= First_Actual
(N
);
3893 Actual_Type
: constant Entity_Id
:= Etype
(Actual
);
3894 Formal_Type
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
3895 New_Actual
: Node_Id
;
3898 -- Check whether the call is a prefixed call, with or without
3899 -- additional actuals.
3901 if Is_Expanded_Prefixed_Call
(N
) then
3903 -- Introduce dereference on object in prefix
3905 if Is_Access_Type
(Actual_Type
)
3906 and then not Is_Access_Type
(Formal_Type
)
3909 Make_Explicit_Dereference
(Sloc
(Actual
),
3910 Prefix
=> Relocate_Node
(Actual
));
3911 Rewrite
(Actual
, New_Actual
);
3914 -- Conversely, if the formal is an access parameter and the object
3915 -- is not an access type or a reference type (i.e. a type with the
3916 -- Implicit_Dereference aspect specified), add an implicit 'Access
3917 -- to the prefix. Its analysis will check that the object is
3920 elsif Is_Access_Type
(Formal_Type
)
3921 and then not Is_Access_Type
(Actual_Type
)
3922 and then (not Has_Implicit_Dereference
(Actual_Type
)
3926 (Etype
(Get_Reference_Discriminant
(Actual_Type
)))))
3929 Make_Attribute_Reference
(Loc
,
3930 Attribute_Name
=> Name_Access
,
3931 Prefix
=> Relocate_Node
(Actual
)));
3935 end Check_Prefixed_Call
;
3937 --------------------
3938 -- Insert_Default --
3939 --------------------
3941 procedure Insert_Default
is
3946 -- Missing argument in call, nothing to insert
3948 if No
(Default_Value
(F
)) then
3952 -- Note that we do a full New_Copy_Tree, so that any associated
3953 -- Itypes are properly copied. This may not be needed any more,
3954 -- but it does no harm as a safety measure. Defaults of a generic
3955 -- formal may be out of bounds of the corresponding actual (see
3956 -- cc1311b) and an additional check may be required.
3961 New_Scope
=> Current_Scope
,
3964 -- Propagate dimension information, if any.
3966 Copy_Dimensions
(Default_Value
(F
), Actval
);
3968 if Is_Concurrent_Type
(Scope
(Nam
))
3969 and then Has_Discriminants
(Scope
(Nam
))
3971 Replace_Actual_Discriminants
(N
, Actval
);
3974 if Is_Overloadable
(Nam
)
3975 and then Present
(Alias
(Nam
))
3977 if Base_Type
(Etype
(F
)) /= Base_Type
(Etype
(Actval
))
3978 and then not Is_Tagged_Type
(Etype
(F
))
3980 -- If default is a real literal, do not introduce a
3981 -- conversion whose effect may depend on the run-time
3982 -- size of universal real.
3984 if Nkind
(Actval
) = N_Real_Literal
then
3985 Set_Etype
(Actval
, Base_Type
(Etype
(F
)));
3987 Actval
:= Unchecked_Convert_To
(Etype
(F
), Actval
);
3991 if Is_Scalar_Type
(Etype
(F
)) then
3992 Enable_Range_Check
(Actval
);
3995 Set_Parent
(Actval
, N
);
3997 -- Resolve aggregates with their base type, to avoid scope
3998 -- anomalies: the subtype was first built in the subprogram
3999 -- declaration, and the current call may be nested.
4001 if Nkind
(Actval
) = N_Aggregate
then
4002 Analyze_And_Resolve
(Actval
, Etype
(F
));
4004 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
4008 Set_Parent
(Actval
, N
);
4010 -- See note above concerning aggregates
4012 if Nkind
(Actval
) = N_Aggregate
4013 and then Has_Discriminants
(Etype
(Actval
))
4015 Analyze_And_Resolve
(Actval
, Base_Type
(Etype
(Actval
)));
4017 -- Resolve entities with their own type, which may differ from
4018 -- the type of a reference in a generic context because of the
4019 -- trick used in Save_Global_References.Set_Global_Type to set
4020 -- full views forcefully, which did not anticipate the need to
4021 -- re-analyze default values in calls.
4023 elsif Is_Entity_Name
(Actval
) then
4024 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Actval
)));
4026 -- Ditto for calls whose name is an entity, for the same reason
4028 elsif Nkind
(Actval
) = N_Function_Call
4029 and then Is_Entity_Name
(Name
(Actval
))
4031 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Name
(Actval
))));
4034 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
4038 -- If default is a tag indeterminate function call, propagate tag
4039 -- to obtain proper dispatching.
4041 if Is_Controlling_Formal
(F
)
4042 and then Nkind
(Default_Value
(F
)) = N_Function_Call
4044 Set_Is_Controlling_Actual
(Actval
);
4048 -- If the default expression raises constraint error, then just
4049 -- silently replace it with an N_Raise_Constraint_Error node, since
4050 -- we already gave the warning on the subprogram spec. If node is
4051 -- already a Raise_Constraint_Error leave as is, to prevent loops in
4052 -- the warnings removal machinery.
4054 if Raises_Constraint_Error
(Actval
)
4055 and then Nkind
(Actval
) /= N_Raise_Constraint_Error
4058 Make_Raise_Constraint_Error
(Loc
,
4059 Reason
=> CE_Range_Check_Failed
));
4061 Set_Raises_Constraint_Error
(Actval
);
4062 Set_Etype
(Actval
, Etype
(F
));
4066 Make_Parameter_Association
(Loc
,
4067 Explicit_Actual_Parameter
=> Actval
,
4068 Selector_Name
=> Make_Identifier
(Loc
, Chars
(F
)));
4070 -- Case of insertion is first named actual
4073 or else Nkind
(Parent
(Prev
)) /= N_Parameter_Association
4075 Set_Next_Named_Actual
(Assoc
, First_Named_Actual
(N
));
4076 Set_First_Named_Actual
(N
, Actval
);
4079 if No
(Parameter_Associations
(N
)) then
4080 Set_Parameter_Associations
(N
, New_List
(Assoc
));
4082 Append
(Assoc
, Parameter_Associations
(N
));
4086 Insert_After
(Prev
, Assoc
);
4089 -- Case of insertion is not first named actual
4092 Set_Next_Named_Actual
4093 (Assoc
, Next_Named_Actual
(Parent
(Prev
)));
4094 Set_Next_Named_Actual
(Parent
(Prev
), Actval
);
4095 Append
(Assoc
, Parameter_Associations
(N
));
4098 Mark_Rewrite_Insertion
(Assoc
);
4099 Mark_Rewrite_Insertion
(Actval
);
4108 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean is
4109 FT1
: Entity_Id
:= T1
;
4110 FT2
: Entity_Id
:= T2
;
4113 if Is_Private_Type
(T1
)
4114 and then Present
(Full_View
(T1
))
4116 FT1
:= Full_View
(T1
);
4119 if Is_Private_Type
(T2
)
4120 and then Present
(Full_View
(T2
))
4122 FT2
:= Full_View
(T2
);
4125 return Root_Type
(Base_Type
(FT1
)) = Root_Type
(Base_Type
(FT2
));
4128 --------------------------
4129 -- Static_Concatenation --
4130 --------------------------
4132 function Static_Concatenation
(N
: Node_Id
) return Boolean is
4135 when N_String_Literal
=>
4140 -- Concatenation is static when both operands are static and
4141 -- the concatenation operator is a predefined one.
4143 return Scope
(Entity
(N
)) = Standard_Standard
4145 Static_Concatenation
(Left_Opnd
(N
))
4147 Static_Concatenation
(Right_Opnd
(N
));
4150 if Is_Entity_Name
(N
) then
4152 Ent
: constant Entity_Id
:= Entity
(N
);
4154 return Ekind
(Ent
) = E_Constant
4155 and then Present
(Constant_Value
(Ent
))
4157 Is_OK_Static_Expression
(Constant_Value
(Ent
));
4164 end Static_Concatenation
;
4166 -- Start of processing for Resolve_Actuals
4169 Check_Argument_Order
;
4171 if Is_Overloadable
(Nam
)
4172 and then Is_Inherited_Operation
(Nam
)
4173 and then In_Instance
4174 and then Present
(Alias
(Nam
))
4175 and then Present
(Overridden_Operation
(Alias
(Nam
)))
4177 Real_Subp
:= Alias
(Nam
);
4182 if Present
(First_Actual
(N
)) then
4183 Check_Prefixed_Call
;
4186 A
:= First_Actual
(N
);
4187 F
:= First_Formal
(Nam
);
4189 if Present
(Real_Subp
) then
4190 Real_F
:= First_Formal
(Real_Subp
);
4193 while Present
(F
) loop
4194 if No
(A
) and then Needs_No_Actuals
(Nam
) then
4197 -- If we have an error in any formal or actual, indicated by a type
4198 -- of Any_Type, then abandon resolution attempt, and set result type
4201 elsif Etype
(F
) = Any_Type
then
4202 Set_Etype
(N
, Any_Type
);
4205 elsif Present
(A
) and then Etype
(A
) = Any_Type
then
4206 -- For the peculiar case of a user-defined comparison or equality
4207 -- operator that does not return a boolean type, the operands may
4208 -- have been ambiguous for the predefined operator and, therefore,
4209 -- marked with Any_Type. Since the operation has been resolved to
4210 -- the user-defined operator, that is irrelevant, so reset Etype.
4212 if Nkind
(Original_Node
(N
)) in N_Op_Compare
4213 and then not Is_Boolean_Type
(Etype
(N
))
4215 Set_Etype
(A
, Etype
(F
));
4217 -- Also skip this if the actual is a Raise_Expression, whose type
4218 -- is imposed from context.
4220 elsif Nkind
(A
) = N_Raise_Expression
then
4224 Set_Etype
(N
, Any_Type
);
4229 -- Case where actual is present
4231 -- If the actual is an entity, generate a reference to it now. We
4232 -- do this before the actual is resolved, because a formal of some
4233 -- protected subprogram, or a task discriminant, will be rewritten
4234 -- during expansion, and the source entity reference may be lost.
4237 and then Is_Entity_Name
(A
)
4238 and then Comes_From_Source
(A
)
4240 -- Annotate the tree by creating a variable reference marker when
4241 -- the actual denotes a variable reference, in case the reference
4242 -- is folded or optimized away. The variable reference marker is
4243 -- automatically saved for later examination by the ABE Processing
4244 -- phase. The status of the reference is set as follows:
4248 -- write IN OUT, OUT
4250 if Needs_Variable_Reference_Marker
4254 Build_Variable_Reference_Marker
4256 Read
=> Ekind
(F
) /= E_Out_Parameter
,
4257 Write
=> Ekind
(F
) /= E_In_Parameter
);
4260 Orig_A
:= Entity
(A
);
4262 if Present
(Orig_A
) then
4263 if Is_Formal
(Orig_A
)
4264 and then Ekind
(F
) /= E_In_Parameter
4266 Generate_Reference
(Orig_A
, A
, 'm');
4268 elsif not Is_Overloaded
(A
) then
4269 if Ekind
(F
) /= E_Out_Parameter
then
4270 Generate_Reference
(Orig_A
, A
);
4272 -- RM 6.4.1(12): For an out parameter that is passed by
4273 -- copy, the formal parameter object is created, and:
4275 -- * For an access type, the formal parameter is initialized
4276 -- from the value of the actual, without checking that the
4277 -- value satisfies any constraint, any predicate, or any
4278 -- exclusion of the null value.
4280 -- * For a scalar type that has the Default_Value aspect
4281 -- specified, the formal parameter is initialized from the
4282 -- value of the actual, without checking that the value
4283 -- satisfies any constraint or any predicate.
4284 -- I do not understand why this case is included??? this is
4285 -- not a case where an OUT parameter is treated as IN OUT.
4287 -- * For a composite type with discriminants or that has
4288 -- implicit initial values for any subcomponents, the
4289 -- behavior is as for an in out parameter passed by copy.
4291 -- Hence for these cases we generate the read reference now
4292 -- (the write reference will be generated later by
4293 -- Note_Possible_Modification).
4295 elsif Is_By_Copy_Type
(Etype
(F
))
4297 (Is_Access_Type
(Etype
(F
))
4299 (Is_Scalar_Type
(Etype
(F
))
4301 Present
(Default_Aspect_Value
(Etype
(F
))))
4303 (Is_Composite_Type
(Etype
(F
))
4304 and then (Has_Discriminants
(Etype
(F
))
4305 or else Is_Partially_Initialized_Type
4308 Generate_Reference
(Orig_A
, A
);
4315 and then (Nkind
(Parent
(A
)) /= N_Parameter_Association
4316 or else Chars
(Selector_Name
(Parent
(A
))) = Chars
(F
))
4318 -- If style checking mode on, check match of formal name
4321 if Nkind
(Parent
(A
)) = N_Parameter_Association
then
4322 Check_Identifier
(Selector_Name
(Parent
(A
)), F
);
4326 -- If the formal is Out or In_Out, do not resolve and expand the
4327 -- conversion, because it is subsequently expanded into explicit
4328 -- temporaries and assignments. However, the object of the
4329 -- conversion can be resolved. An exception is the case of tagged
4330 -- type conversion with a class-wide actual. In that case we want
4331 -- the tag check to occur and no temporary will be needed (no
4332 -- representation change can occur) and the parameter is passed by
4333 -- reference, so we go ahead and resolve the type conversion.
4334 -- Another exception is the case of reference to component or
4335 -- subcomponent of a bit-packed array, in which case we want to
4336 -- defer expansion to the point the in and out assignments are
4339 if Ekind
(F
) /= E_In_Parameter
4340 and then Nkind
(A
) = N_Type_Conversion
4341 and then not Is_Class_Wide_Type
(Etype
(Expression
(A
)))
4342 and then not Is_Interface
(Etype
(A
))
4345 Expr_Typ
: constant Entity_Id
:= Etype
(Expression
(A
));
4348 -- Check RM 4.6 (24.2/2)
4350 if Is_Array_Type
(Etype
(F
))
4351 and then Is_View_Conversion
(A
)
4353 -- In a view conversion, the conversion must be legal in
4354 -- both directions, and thus both component types must be
4355 -- aliased, or neither (4.6 (8)).
4357 -- Check RM 4.6 (24.8/2)
4359 if Has_Aliased_Components
(Expr_Typ
) /=
4360 Has_Aliased_Components
(Etype
(F
))
4362 -- This normally illegal conversion is legal in an
4363 -- expanded instance body because of RM 12.3(11).
4364 -- At runtime, conversion must create a new object.
4366 if not In_Instance
then
4368 ("both component types in a view conversion must"
4369 & " be aliased, or neither", A
);
4372 -- Check RM 4.6 (24/3)
4374 elsif not Same_Ancestor
(Etype
(F
), Expr_Typ
) then
4375 -- Check view conv between unrelated by ref array
4378 if Is_By_Reference_Type
(Etype
(F
))
4379 or else Is_By_Reference_Type
(Expr_Typ
)
4382 ("view conversion between unrelated by reference "
4383 & "array types not allowed ('A'I-00246)", A
);
4385 -- In Ada 2005 mode, check view conversion component
4386 -- type cannot be private, tagged, or volatile. Note
4387 -- that we only apply this to source conversions. The
4388 -- generated code can contain conversions which are
4389 -- not subject to this test, and we cannot extract the
4390 -- component type in such cases since it is not
4393 elsif Comes_From_Source
(A
)
4394 and then Ada_Version
>= Ada_2005
4397 Comp_Type
: constant Entity_Id
:=
4398 Component_Type
(Expr_Typ
);
4400 if (Is_Private_Type
(Comp_Type
)
4401 and then not Is_Generic_Type
(Comp_Type
))
4402 or else Is_Tagged_Type
(Comp_Type
)
4403 or else Is_Volatile
(Comp_Type
)
4406 ("component type of a view conversion " &
4407 "cannot be private, tagged, or volatile" &
4415 -- AI12-0074 & AI12-0377
4416 -- Check 6.4.1: If the mode is out, the actual parameter is
4417 -- a view conversion, and the type of the formal parameter
4418 -- is a scalar type, then either:
4419 -- - the target and operand type both do not have the
4420 -- Default_Value aspect specified; or
4421 -- - the target and operand type both have the
4422 -- Default_Value aspect specified, and there shall exist
4423 -- a type (other than a root numeric type) that is an
4424 -- ancestor of both the target type and the operand
4427 elsif Ekind
(F
) = E_Out_Parameter
4428 and then Is_Scalar_Type
(Etype
(F
))
4430 if Has_Default_Aspect
(Etype
(F
)) /=
4431 Has_Default_Aspect
(Expr_Typ
)
4434 ("view conversion requires Default_Value on both " &
4435 "types (RM 6.4.1)", A
);
4436 elsif Has_Default_Aspect
(Expr_Typ
)
4437 and then not Same_Ancestor
(Etype
(F
), Expr_Typ
)
4440 ("view conversion between unrelated types with "
4441 & "Default_Value not allowed (RM 6.4.1)", A
);
4446 -- Resolve expression if conversion is all OK
4448 if (Conversion_OK
(A
)
4449 or else Valid_Conversion
(A
, Etype
(A
), Expression
(A
)))
4450 and then not Is_Ref_To_Bit_Packed_Array
(Expression
(A
))
4452 Resolve
(Expression
(A
));
4455 -- In GNATprove mode, add a range check flag on scalar
4456 -- conversions for IN OUT parameters. The check may be
4457 -- needed on entry from the call.
4460 and then Ekind
(F
) = E_In_Out_Parameter
4461 and then Is_Scalar_Type
(Etype
(F
))
4463 Set_Do_Range_Check
(Expression
(A
));
4466 -- If the actual is a function call that returns a limited
4467 -- unconstrained object that needs finalization, create a
4468 -- transient scope for it, so that it can receive the proper
4469 -- finalization list.
4471 elsif Expander_Active
4472 and then Nkind
(A
) = N_Function_Call
4473 and then Is_Limited_Record
(Etype
(F
))
4474 and then not Is_Constrained
(Etype
(F
))
4475 and then (Needs_Finalization
(Etype
(F
))
4476 or else Has_Task
(Etype
(F
)))
4478 Establish_Transient_Scope
(A
, Manage_Sec_Stack
=> False);
4479 Resolve
(A
, Etype
(F
));
4481 -- A small optimization: if one of the actuals is a concatenation
4482 -- create a block around a procedure call to recover stack space.
4483 -- This alleviates stack usage when several procedure calls in
4484 -- the same statement list use concatenation. We do not perform
4485 -- this wrapping for code statements, where the argument is a
4486 -- static string, and we want to preserve warnings involving
4487 -- sequences of such statements.
4489 elsif Expander_Active
4490 and then Nkind
(A
) = N_Op_Concat
4491 and then Nkind
(N
) = N_Procedure_Call_Statement
4492 and then not (Is_Intrinsic_Subprogram
(Nam
)
4493 and then Chars
(Nam
) = Name_Asm
)
4494 and then not Static_Concatenation
(A
)
4496 Establish_Transient_Scope
(A
, Manage_Sec_Stack
=> False);
4497 Resolve
(A
, Etype
(F
));
4500 if Nkind
(A
) = N_Type_Conversion
4501 and then Is_Array_Type
(Etype
(F
))
4502 and then not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
4504 (Is_Limited_Type
(Etype
(F
))
4505 or else Is_Limited_Type
(Etype
(Expression
(A
))))
4508 ("conversion between unrelated limited array types not "
4509 & "allowed ('A'I-00246)", A
);
4511 if Is_Limited_Type
(Etype
(F
)) then
4512 Explain_Limited_Type
(Etype
(F
), A
);
4515 if Is_Limited_Type
(Etype
(Expression
(A
))) then
4516 Explain_Limited_Type
(Etype
(Expression
(A
)), A
);
4520 -- (Ada 2005: AI-251): If the actual is an allocator whose
4521 -- directly designated type is a class-wide interface, we build
4522 -- an anonymous access type to use it as the type of the
4523 -- allocator. Later, when the subprogram call is expanded, if
4524 -- the interface has a secondary dispatch table the expander
4525 -- will add a type conversion to force the correct displacement
4528 if Nkind
(A
) = N_Allocator
then
4530 DDT
: constant Entity_Id
:=
4531 Directly_Designated_Type
(Base_Type
(Etype
(F
)));
4534 -- Displace the pointer to the object to reference its
4535 -- secondary dispatch table.
4537 if Is_Class_Wide_Type
(DDT
)
4538 and then Is_Interface
(DDT
)
4540 Rewrite
(A
, Convert_To
(Etype
(F
), Relocate_Node
(A
)));
4541 Analyze_And_Resolve
(A
, Etype
(F
),
4542 Suppress
=> Access_Check
);
4545 -- Ada 2005, AI-162:If the actual is an allocator, the
4546 -- innermost enclosing statement is the master of the
4547 -- created object. This needs to be done with expansion
4548 -- enabled only, otherwise the transient scope will not
4549 -- be removed in the expansion of the wrapped construct.
4552 and then (Needs_Finalization
(DDT
)
4553 or else Has_Task
(DDT
))
4555 Establish_Transient_Scope
4556 (A
, Manage_Sec_Stack
=> False);
4560 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
4561 Check_Restriction
(No_Access_Parameter_Allocators
, A
);
4565 -- (Ada 2005): The call may be to a primitive operation of a
4566 -- tagged synchronized type, declared outside of the type. In
4567 -- this case the controlling actual must be converted to its
4568 -- corresponding record type, which is the formal type. The
4569 -- actual may be a subtype, either because of a constraint or
4570 -- because it is a generic actual, so use base type to locate
4573 F_Typ
:= Base_Type
(Etype
(F
));
4575 if Is_Tagged_Type
(F_Typ
)
4576 and then (Is_Concurrent_Type
(F_Typ
)
4577 or else Is_Concurrent_Record_Type
(F_Typ
))
4579 -- If the actual is overloaded, look for an interpretation
4580 -- that has a synchronized type.
4582 if not Is_Overloaded
(A
) then
4583 A_Typ
:= Base_Type
(Etype
(A
));
4587 Index
: Interp_Index
;
4591 Get_First_Interp
(A
, Index
, It
);
4592 while Present
(It
.Typ
) loop
4593 if Is_Concurrent_Type
(It
.Typ
)
4594 or else Is_Concurrent_Record_Type
(It
.Typ
)
4596 A_Typ
:= Base_Type
(It
.Typ
);
4600 Get_Next_Interp
(Index
, It
);
4606 Full_A_Typ
: Entity_Id
;
4609 if Present
(Full_View
(A_Typ
)) then
4610 Full_A_Typ
:= Base_Type
(Full_View
(A_Typ
));
4612 Full_A_Typ
:= A_Typ
;
4615 -- Tagged synchronized type (case 1): the actual is a
4618 if Is_Concurrent_Type
(A_Typ
)
4619 and then Corresponding_Record_Type
(A_Typ
) = F_Typ
4622 Unchecked_Convert_To
4623 (Corresponding_Record_Type
(A_Typ
), A
));
4624 Resolve
(A
, Etype
(F
));
4626 -- Tagged synchronized type (case 2): the formal is a
4629 elsif Ekind
(Full_A_Typ
) = E_Record_Type
4631 (Corresponding_Concurrent_Type
(Full_A_Typ
))
4632 and then Is_Concurrent_Type
(F_Typ
)
4633 and then Present
(Corresponding_Record_Type
(F_Typ
))
4634 and then Full_A_Typ
= Corresponding_Record_Type
(F_Typ
)
4636 Resolve
(A
, Corresponding_Record_Type
(F_Typ
));
4641 Resolve
(A
, Etype
(F
));
4645 -- Not a synchronized operation
4648 Resolve
(A
, Etype
(F
));
4655 -- If A_Typ is complete and F_Typ is not, then adjust F_Typ
4657 if Ekind
(F_Typ
) = E_Incomplete_Type
4658 and then Present
(Full_View
(F_Typ
))
4659 and then not Is_Incomplete_Type
(A_Typ
)
4661 F_Typ
:= Full_View
(F_Typ
);
4664 -- An actual cannot be of an untagged incomplete view; the result
4665 -- object of a function call cannot be of an incomplete view
4668 if Ekind
(A_Typ
) = E_Incomplete_Type
4669 and then (Nkind
(A
) = N_Function_Call
4670 or else not Is_Tagged_Type
(A_Typ
))
4672 -- No error if the call is placed in the initializing
4673 -- expression of a component of the full-view of the
4674 -- incomplete type. For example:
4677 -- function F (Obj : T) return Integer;
4680 -- Data : Integer := F (T);
4683 if Present
(Full_View
(A_Typ
))
4684 and then Full_View
(A_Typ
) = Current_Scope
4685 and then In_Spec_Expression
4686 and then In_Default_Expr
4690 -- No error if the call is performed in pre/postconditions, and
4691 -- it is an incomplete type of a limited-with clause.
4693 elsif From_Limited_With
(A_Typ
)
4694 and then Present
(Non_Limited_View
(A_Typ
))
4695 and then Is_Subprogram
(Current_Scope
)
4699 Present
(Class_Preconditions_Subprogram
(Current_Scope
)))
4703 elsif Is_Generic_Type
(A_Typ
) then
4704 if Is_Tagged_Type
(A_Typ
) then
4706 ("invalid use of tagged formal incomplete type", A
);
4709 ("invalid use of untagged formal incomplete type", A
);
4712 Check_Fully_Declared
(A_Typ
, A
);
4716 -- For mode IN, if actual is an entity, and the type of the formal
4717 -- has warnings suppressed, then we reset Never_Set_In_Source for
4718 -- the calling entity. The reason for this is to catch cases like
4719 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
4720 -- uses trickery to modify an IN parameter.
4722 if Ekind
(F
) = E_In_Parameter
4723 and then Is_Entity_Name
(A
)
4724 and then Present
(Entity
(A
))
4725 and then Ekind
(Entity
(A
)) = E_Variable
4726 and then Has_Warnings_Off
(F_Typ
)
4728 Set_Never_Set_In_Source
(Entity
(A
), False);
4731 -- Perform error checks for IN and IN OUT parameters
4733 if Ekind
(F
) /= E_Out_Parameter
then
4735 -- Check unset reference. For scalar parameters, it is clearly
4736 -- wrong to pass an uninitialized value as either an IN or
4737 -- IN-OUT parameter. For composites, it is also clearly an
4738 -- error to pass a completely uninitialized value as an IN
4739 -- parameter, but the case of IN OUT is trickier. We prefer
4740 -- not to give a warning here. For example, suppose there is
4741 -- a routine that sets some component of a record to False.
4742 -- It is perfectly reasonable to make this IN-OUT and allow
4743 -- either initialized or uninitialized records to be passed
4746 -- For partially initialized composite values, we also avoid
4747 -- warnings, since it is quite likely that we are passing a
4748 -- partially initialized value and only the initialized fields
4749 -- will in fact be read in the subprogram.
4751 if Is_Scalar_Type
(A_Typ
)
4752 or else (Ekind
(F
) = E_In_Parameter
4753 and then not Is_Partially_Initialized_Type
(A_Typ
))
4755 Check_Unset_Reference
(A
);
4758 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
4759 -- actual to a nested call, since this constitutes a reading of
4760 -- the parameter, which is not allowed.
4762 if Ada_Version
= Ada_83
4763 and then Is_Entity_Name
(A
)
4764 and then Ekind
(Entity
(A
)) = E_Out_Parameter
4766 Error_Msg_N
("(Ada 83) illegal reading of out parameter", A
);
4770 -- In -gnatd.q mode, forget that a given array is constant when
4771 -- it is passed as an IN parameter to a foreign-convention
4772 -- subprogram. This is in case the subprogram evilly modifies the
4773 -- object. Of course, correct code would use IN OUT.
4776 and then Ekind
(F
) = E_In_Parameter
4777 and then Has_Foreign_Convention
(Nam
)
4778 and then Is_Array_Type
(F_Typ
)
4779 and then Nkind
(A
) in N_Has_Entity
4780 and then Present
(Entity
(A
))
4782 Set_Is_True_Constant
(Entity
(A
), False);
4785 -- Case of OUT or IN OUT parameter
4787 if Ekind
(F
) /= E_In_Parameter
then
4789 -- For an Out parameter, check for useless assignment. Note
4790 -- that we can't set Last_Assignment this early, because we may
4791 -- kill current values in Resolve_Call, and that call would
4792 -- clobber the Last_Assignment field.
4794 -- Note: call Warn_On_Useless_Assignment before doing the check
4795 -- below for Is_OK_Variable_For_Out_Formal so that the setting
4796 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
4797 -- reflects the last assignment, not this one.
4799 if Ekind
(F
) = E_Out_Parameter
then
4800 if Warn_On_Modified_As_Out_Parameter
(F
)
4801 and then Is_Entity_Name
(A
)
4802 and then Present
(Entity
(A
))
4803 and then Comes_From_Source
(N
)
4805 Warn_On_Useless_Assignment
(Entity
(A
), A
);
4809 -- Validate the form of the actual. Note that the call to
4810 -- Is_OK_Variable_For_Out_Formal generates the required
4811 -- reference in this case.
4813 -- A call to an initialization procedure for an aggregate
4814 -- component may initialize a nested component of a constant
4815 -- designated object. In this context the object is variable.
4817 if not Is_OK_Variable_For_Out_Formal
(A
)
4818 and then not Is_Init_Proc
(Nam
)
4820 Error_Msg_NE
("actual for& must be a variable", A
, F
);
4822 if Is_Subprogram
(Current_Scope
) then
4823 if Is_Invariant_Procedure
(Current_Scope
)
4824 or else Is_Partial_Invariant_Procedure
(Current_Scope
)
4827 ("function used in invariant cannot modify its "
4830 elsif Is_Predicate_Function
(Current_Scope
) then
4832 ("function used in predicate cannot modify its "
4838 -- What's the following about???
4840 if Is_Entity_Name
(A
) then
4841 Kill_Checks
(Entity
(A
));
4847 if A_Typ
= Any_Type
then
4848 Set_Etype
(N
, Any_Type
);
4852 -- Apply appropriate constraint/predicate checks for IN [OUT] case
4854 if Ekind
(F
) in E_In_Parameter | E_In_Out_Parameter
then
4856 -- Apply predicate tests except in certain special cases. Note
4857 -- that it might be more consistent to apply these only when
4858 -- expansion is active (in Exp_Ch6.Expand_Actuals), as we do
4859 -- for the outbound predicate tests ??? In any case indicate
4860 -- the function being called, for better warnings if the call
4861 -- leads to an infinite recursion.
4863 if Predicate_Tests_On_Arguments
(Nam
) then
4864 Apply_Predicate_Check
(A
, F_Typ
, Fun
=> Nam
);
4867 -- Apply required constraint checks
4869 if Is_Scalar_Type
(A_Typ
) then
4870 Apply_Scalar_Range_Check
(A
, F_Typ
);
4872 elsif Is_Array_Type
(A_Typ
) then
4873 Apply_Length_Check
(A
, F_Typ
);
4875 elsif Is_Record_Type
(F_Typ
)
4876 and then Has_Discriminants
(F_Typ
)
4877 and then Is_Constrained
(F_Typ
)
4878 and then (not Is_Derived_Type
(F_Typ
)
4879 or else Comes_From_Source
(Nam
))
4881 Apply_Discriminant_Check
(A
, F_Typ
);
4883 -- For view conversions of a discriminated object, apply
4884 -- check to object itself, the conversion alreay has the
4887 if Nkind
(A
) = N_Type_Conversion
4888 and then Is_Constrained
(Etype
(Expression
(A
)))
4890 Apply_Discriminant_Check
(Expression
(A
), F_Typ
);
4893 elsif Is_Access_Type
(F_Typ
)
4894 and then Is_Array_Type
(Designated_Type
(F_Typ
))
4895 and then Is_Constrained
(Designated_Type
(F_Typ
))
4897 Apply_Length_Check
(A
, F_Typ
);
4899 elsif Is_Access_Type
(F_Typ
)
4900 and then Has_Discriminants
(Designated_Type
(F_Typ
))
4901 and then Is_Constrained
(Designated_Type
(F_Typ
))
4903 Apply_Discriminant_Check
(A
, F_Typ
);
4906 Apply_Range_Check
(A
, F_Typ
);
4909 -- Ada 2005 (AI-231): Note that the controlling parameter case
4910 -- already existed in Ada 95, which is partially checked
4911 -- elsewhere (see Checks), and we don't want the warning
4912 -- message to differ.
4914 if Is_Access_Type
(F_Typ
)
4915 and then Can_Never_Be_Null
(F_Typ
)
4916 and then Known_Null
(A
)
4918 if Is_Controlling_Formal
(F
) then
4919 Apply_Compile_Time_Constraint_Error
4921 Msg
=> "null value not allowed here??",
4922 Reason
=> CE_Access_Check_Failed
);
4924 elsif Ada_Version
>= Ada_2005
then
4925 Apply_Compile_Time_Constraint_Error
4927 Msg
=> "(Ada 2005) NULL not allowed in "
4928 & "null-excluding formal??",
4929 Reason
=> CE_Null_Not_Allowed
);
4933 -- In a prefixed call, if the prefix is an access type
4934 -- it cannot be null.
4936 if Is_Access_Type
(F_Typ
)
4937 and then A
= First_Actual
(N
)
4938 and then Is_Expanded_Prefixed_Call
(N
)
4940 if not Is_Access_Type
(A_Typ
)
4941 and then not Is_Aliased_View
(A
)
4944 ("object in prefixed call to& must be aliased "
4945 & "(RM 4.1.3 (13 1/2))",
4949 if Debug_Flag_Underscore_PP
4951 (Is_Controlling_Formal
(F
)
4952 or else Is_Class_Wide_Type
(Designated_Type
(F_Typ
)))
4954 Install_Null_Excluding_Check
(A
);
4959 -- Checks for OUT parameters and IN OUT parameters
4961 if Ekind
(F
) in E_Out_Parameter | E_In_Out_Parameter
then
4963 -- If there is a type conversion, make sure the return value
4964 -- meets the constraints of the variable before the conversion.
4966 if Nkind
(A
) = N_Type_Conversion
then
4967 if Is_Scalar_Type
(A_Typ
) then
4969 -- Special case here tailored to Exp_Ch6.Is_Legal_Copy,
4970 -- which would prevent the check from being generated.
4971 -- This is for Starlet only though, so long obsolete.
4973 if Mechanism
(F
) = By_Reference
4974 and then Ekind
(Nam
) = E_Procedure
4975 and then Is_Valued_Procedure
(Nam
)
4979 Apply_Scalar_Range_Check
4980 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4983 -- In addition the return value must meet the constraints
4984 -- of the object type (see the comment below).
4986 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
4990 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4993 -- If no conversion, apply scalar range checks and length check
4994 -- based on the subtype of the actual (NOT that of the formal).
4995 -- This indicates that the check takes place on return from the
4996 -- call. During expansion the required constraint checks are
4997 -- inserted. In GNATprove mode, in the absence of expansion,
4998 -- the flag indicates that the returned value is valid.
5001 if Is_Scalar_Type
(F_Typ
) then
5002 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
5004 elsif Is_Array_Type
(F_Typ
)
5005 and then Ekind
(F
) = E_Out_Parameter
5007 Apply_Length_Check
(A
, F_Typ
);
5010 Apply_Range_Check
(A
, A_Typ
, F_Typ
);
5014 -- Note: we do not apply the predicate checks for the case of
5015 -- OUT and IN OUT parameters. They are instead applied in the
5016 -- Expand_Actuals routine in Exp_Ch6.
5019 -- If the formal is of an unconstrained array subtype with fixed
5020 -- lower bound, then sliding to that bound may be needed.
5022 if Is_Fixed_Lower_Bound_Array_Subtype
(F_Typ
) then
5023 Expand_Sliding_Conversion
(A
, F_Typ
);
5026 -- An actual associated with an access parameter is implicitly
5027 -- converted to the anonymous access type of the formal and must
5028 -- satisfy the legality checks for access conversions.
5030 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
5031 if not Valid_Conversion
(A
, F_Typ
, A
) then
5033 ("invalid implicit conversion for access parameter", A
);
5036 -- If the actual is an access selected component of a variable,
5037 -- the call may modify its designated object. It is reasonable
5038 -- to treat this as a potential modification of the enclosing
5039 -- record, to prevent spurious warnings that it should be
5040 -- declared as a constant, because intuitively programmers
5041 -- regard the designated subcomponent as part of the record.
5043 if Nkind
(A
) = N_Selected_Component
5044 and then Is_Entity_Name
(Prefix
(A
))
5045 and then not Is_Constant_Object
(Entity
(Prefix
(A
)))
5047 Note_Possible_Modification
(A
, Sure
=> False);
5051 -- Check illegal cases of atomic/volatile/VFA actual (RM C.6(12))
5053 if (Is_By_Reference_Type
(F_Typ
) or else Is_Aliased
(F
))
5054 and then Comes_From_Source
(N
)
5056 if Is_Atomic_Object
(A
)
5057 and then not Is_Atomic
(F_Typ
)
5060 ("cannot pass atomic object to nonatomic formal&",
5063 ("\which is passed by reference (RM C.6(12))", A
);
5065 elsif Is_Volatile_Object_Ref
(A
)
5066 and then not Is_Volatile
(F_Typ
)
5069 ("cannot pass volatile object to nonvolatile formal&",
5072 ("\which is passed by reference (RM C.6(12))", A
);
5074 elsif Is_Volatile_Full_Access_Object_Ref
(A
)
5075 and then not Is_Volatile_Full_Access
(F_Typ
)
5078 ("cannot pass full access object to nonfull access "
5081 ("\which is passed by reference (RM C.6(12))", A
);
5084 -- Check for nonatomic subcomponent of a full access object
5085 -- in Ada 2022 (RM C.6 (12)).
5087 if Ada_Version
>= Ada_2022
5088 and then Is_Subcomponent_Of_Full_Access_Object
(A
)
5089 and then not Is_Atomic_Object
(A
)
5092 ("cannot pass nonatomic subcomponent of full access "
5095 ("\to formal & which is passed by reference (RM C.6(12))",
5100 -- Check that subprograms don't have improper controlling
5101 -- arguments (RM 3.9.2 (9)).
5103 -- A primitive operation may have an access parameter of an
5104 -- incomplete tagged type, but a dispatching call is illegal
5105 -- if the type is still incomplete.
5107 if Is_Controlling_Formal
(F
) then
5108 Set_Is_Controlling_Actual
(A
);
5110 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
5112 Desig
: constant Entity_Id
:= Designated_Type
(F_Typ
);
5114 if Ekind
(Desig
) = E_Incomplete_Type
5115 and then No
(Full_View
(Desig
))
5116 and then No
(Non_Limited_View
(Desig
))
5119 ("premature use of incomplete type& "
5120 & "in dispatching call", A
, Desig
);
5125 elsif Nkind
(A
) = N_Explicit_Dereference
then
5126 Validate_Remote_Access_To_Class_Wide_Type
(A
);
5129 -- Apply legality rule 3.9.2 (9/1)
5131 -- Skip this check on helpers and indirect-call wrappers built to
5132 -- support class-wide preconditions.
5134 -- We make special exception here for mutably tagged types and
5135 -- related calls to their initialization procedures.
5137 if (Is_Class_Wide_Type
(A_Typ
) or else Is_Dynamically_Tagged
(A
))
5138 and then not Is_Class_Wide_Type
(F_Typ
)
5139 and then not Is_Controlling_Formal
(F
)
5140 and then not In_Instance
5141 and then (not Is_Subprogram
(Nam
)
5142 or else No
(Class_Preconditions_Subprogram
(Nam
)))
5144 -- Ignore mutably tagged types and their use in calls to init
5147 and then not Is_Mutably_Tagged_CW_Equivalent_Type
(A_Typ
)
5148 and then not Is_Init_Proc
(Nam
)
5150 Error_Msg_N
("class-wide argument not allowed here!", A
);
5152 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
5153 Error_Msg_Node_2
:= F_Typ
;
5155 ("& is not a dispatching operation of &!", A
, Nam
);
5158 -- Apply the checks described in 3.10.2(27): if the context is a
5159 -- specific access-to-object, the actual cannot be class-wide.
5160 -- Use base type to exclude access_to_subprogram cases.
5162 elsif Is_Access_Type
(A_Typ
)
5163 and then Is_Access_Type
(F_Typ
)
5164 and then not Is_Access_Subprogram_Type
(Base_Type
(F_Typ
))
5165 and then (Is_Class_Wide_Type
(Designated_Type
(A_Typ
))
5166 or else (Nkind
(A
) = N_Attribute_Reference
5168 Is_Class_Wide_Type
(Etype
(Prefix
(A
)))))
5169 and then not Is_Class_Wide_Type
(Designated_Type
(F_Typ
))
5170 and then not Is_Controlling_Formal
(F
)
5172 -- Disable these checks for call to imported C++ subprograms
5175 (Is_Entity_Name
(Name
(N
))
5176 and then Is_Imported
(Entity
(Name
(N
)))
5177 and then Convention
(Entity
(Name
(N
))) = Convention_CPP
)
5180 ("access to class-wide argument not allowed here!", A
);
5182 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
5183 Error_Msg_Node_2
:= Designated_Type
(F_Typ
);
5185 ("& is not a dispatching operation of &!", A
, Nam
);
5189 Check_Aliased_Parameter
;
5193 -- If it is a named association, treat the selector_name as a
5194 -- proper identifier, and mark the corresponding entity.
5196 if Nkind
(Parent
(A
)) = N_Parameter_Association
5198 -- Ignore reference in SPARK mode, as it refers to an entity not
5199 -- in scope at the point of reference, so the reference should
5200 -- be ignored for computing effects of subprograms.
5202 and then not GNATprove_Mode
5204 -- If subprogram is overridden, use name of formal that
5207 if Present
(Real_Subp
) then
5208 Set_Entity
(Selector_Name
(Parent
(A
)), Real_F
);
5209 Set_Etype
(Selector_Name
(Parent
(A
)), Etype
(Real_F
));
5212 Set_Entity
(Selector_Name
(Parent
(A
)), F
);
5213 Generate_Reference
(F
, Selector_Name
(Parent
(A
)));
5214 Set_Etype
(Selector_Name
(Parent
(A
)), F_Typ
);
5215 Generate_Reference
(F_Typ
, N
, ' ');
5221 if Ekind
(F
) /= E_Out_Parameter
then
5222 Check_Unset_Reference
(A
);
5225 -- A formal parameter of a specific tagged type whose related
5226 -- subprogram is subject to pragma Extensions_Visible with value
5227 -- "False" cannot act as an actual in a subprogram with value
5228 -- "True" (SPARK RM 6.1.7(3)).
5230 -- No check needed for helpers and indirect-call wrappers built to
5231 -- support class-wide preconditions.
5233 if Is_EVF_Expression
(A
)
5234 and then Extensions_Visible_Status
(Nam
) =
5235 Extensions_Visible_True
5237 (Is_Subprogram
(Current_Scope
)
5239 Present
(Class_Preconditions_Subprogram
(Current_Scope
)))
5242 ("formal parameter cannot act as actual parameter when "
5243 & "Extensions_Visible is False", A
);
5245 ("\subprogram & has Extensions_Visible True", A
, Nam
);
5248 -- The actual parameter of a Ghost subprogram whose formal is of
5249 -- mode IN OUT or OUT must be a Ghost variable (SPARK RM 6.9(12)).
5251 if Comes_From_Source
(Nam
)
5252 and then Is_Ghost_Entity
(Nam
)
5253 and then Ekind
(F
) in E_In_Out_Parameter | E_Out_Parameter
5254 and then Is_Entity_Name
(A
)
5255 and then Present
(Entity
(A
))
5256 and then not Is_Ghost_Entity
(Entity
(A
))
5259 ("non-ghost variable & cannot appear as actual in call to "
5260 & "ghost procedure", A
, Entity
(A
));
5262 if Ekind
(F
) = E_In_Out_Parameter
then
5263 Error_Msg_N
("\corresponding formal has mode `IN OUT`", A
);
5265 Error_Msg_N
("\corresponding formal has mode OUT", A
);
5269 -- (AI12-0397): The target of a subprogram call that occurs within
5270 -- the expression of an Default_Initial_Condition aspect and has
5271 -- an actual that is the current instance of the type must be
5272 -- either a primitive of the type or a class-wide subprogram,
5273 -- because the type of the current instance in such an aspect is
5274 -- considered to be a notional formal derived type whose only
5275 -- operations correspond to the primitives of the enclosing type.
5276 -- Nonprimitives can be called, but the current instance must be
5277 -- converted rather than passed directly. Note that a current
5278 -- instance of a type with DIC will occur as a reference to an
5279 -- in-mode formal of an enclosing DIC procedure or partial DIC
5280 -- procedure. (It seems that this check should perhaps also apply
5281 -- to calls within Type_Invariant'Class, but not Type_Invariant,
5284 if Nkind
(A
) = N_Identifier
5285 and then Ekind
(Entity
(A
)) = E_In_Parameter
5287 and then Is_Subprogram
(Scope
(Entity
(A
)))
5288 and then Is_DIC_Procedure
(Scope
(Entity
(A
)))
5290 -- We check Comes_From_Source to exclude inherited primitives
5291 -- from being flagged, because such subprograms turn out to not
5292 -- always have the Is_Primitive flag set. ???
5294 and then Comes_From_Source
(Nam
)
5296 and then not Is_Primitive
(Nam
)
5297 and then not Is_Class_Wide_Type
(F_Typ
)
5300 ("call to nonprimitive & with current instance not allowed " &
5301 "for aspect", A
, Nam
);
5306 -- Case where actual is not present
5314 if Present
(Real_Subp
) then
5315 Next_Formal
(Real_F
);
5318 end Resolve_Actuals
;
5320 -----------------------
5321 -- Resolve_Allocator --
5322 -----------------------
5324 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
) is
5325 Desig_T
: constant Entity_Id
:= Designated_Type
(Typ
);
5326 E
: constant Node_Id
:= Expression
(N
);
5328 Discrim
: Entity_Id
;
5331 Assoc
: Node_Id
:= Empty
;
5334 procedure Check_Allocator_Discrim_Accessibility
5335 (Disc_Exp
: Node_Id
;
5336 Alloc_Typ
: Entity_Id
);
5337 -- Check that accessibility level associated with an access discriminant
5338 -- initialized in an allocator by the expression Disc_Exp is not deeper
5339 -- than the level of the allocator type Alloc_Typ. An error message is
5340 -- issued if this condition is violated. Specialized checks are done for
5341 -- the cases of a constraint expression which is an access attribute or
5342 -- an access discriminant.
5344 procedure Check_Allocator_Discrim_Accessibility_Exprs
5345 (Curr_Exp
: Node_Id
;
5346 Alloc_Typ
: Entity_Id
);
5347 -- Dispatch checks performed by Check_Allocator_Discrim_Accessibility
5348 -- across all expressions within a given conditional expression.
5350 function In_Dispatching_Context
return Boolean;
5351 -- If the allocator is an actual in a call, it is allowed to be class-
5352 -- wide when the context is not because it is a controlling actual.
5354 -------------------------------------------
5355 -- Check_Allocator_Discrim_Accessibility --
5356 -------------------------------------------
5358 procedure Check_Allocator_Discrim_Accessibility
5359 (Disc_Exp
: Node_Id
;
5360 Alloc_Typ
: Entity_Id
)
5363 if Type_Access_Level
(Etype
(Disc_Exp
)) >
5364 Deepest_Type_Access_Level
(Alloc_Typ
)
5367 ("operand type has deeper level than allocator type", Disc_Exp
);
5369 -- When the expression is an Access attribute the level of the prefix
5370 -- object must not be deeper than that of the allocator's type.
5372 elsif Nkind
(Disc_Exp
) = N_Attribute_Reference
5373 and then Get_Attribute_Id
(Attribute_Name
(Disc_Exp
)) =
5375 and then Static_Accessibility_Level
5376 (Disc_Exp
, Zero_On_Dynamic_Level
)
5377 > Deepest_Type_Access_Level
(Alloc_Typ
)
5380 ("prefix of attribute has deeper level than allocator type",
5383 -- When the expression is an access discriminant the check is against
5384 -- the level of the prefix object.
5386 elsif Ekind
(Etype
(Disc_Exp
)) = E_Anonymous_Access_Type
5387 and then Nkind
(Disc_Exp
) = N_Selected_Component
5388 and then Static_Accessibility_Level
5389 (Disc_Exp
, Zero_On_Dynamic_Level
)
5390 > Deepest_Type_Access_Level
(Alloc_Typ
)
5393 ("access discriminant has deeper level than allocator type",
5396 -- All other cases are legal
5401 end Check_Allocator_Discrim_Accessibility
;
5403 -------------------------------------------------
5404 -- Check_Allocator_Discrim_Accessibility_Exprs --
5405 -------------------------------------------------
5407 procedure Check_Allocator_Discrim_Accessibility_Exprs
5408 (Curr_Exp
: Node_Id
;
5409 Alloc_Typ
: Entity_Id
)
5413 Disc_Exp
: constant Node_Id
:= Original_Node
(Curr_Exp
);
5415 -- When conditional expressions are constant folded we know at
5416 -- compile time which expression to check - so don't bother with
5417 -- the rest of the cases.
5419 if Nkind
(Curr_Exp
) = N_Attribute_Reference
then
5420 Check_Allocator_Discrim_Accessibility
(Curr_Exp
, Alloc_Typ
);
5422 -- Non-constant-folded if expressions
5424 elsif Nkind
(Disc_Exp
) = N_If_Expression
then
5425 -- Check both expressions if they are still present in the face
5428 Expr
:= Next
(First
(Expressions
(Disc_Exp
)));
5429 if Present
(Expr
) then
5430 Check_Allocator_Discrim_Accessibility_Exprs
(Expr
, Alloc_Typ
);
5432 if Present
(Expr
) then
5433 Check_Allocator_Discrim_Accessibility_Exprs
5438 -- Non-constant-folded case expressions
5440 elsif Nkind
(Disc_Exp
) = N_Case_Expression
then
5441 -- Check all alternatives
5443 Alt
:= First
(Alternatives
(Disc_Exp
));
5444 while Present
(Alt
) loop
5445 Check_Allocator_Discrim_Accessibility_Exprs
5446 (Expression
(Alt
), Alloc_Typ
);
5451 -- Base case, check the accessibility of the original node of the
5455 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Alloc_Typ
);
5457 end Check_Allocator_Discrim_Accessibility_Exprs
;
5459 ----------------------------
5460 -- In_Dispatching_Context --
5461 ----------------------------
5463 function In_Dispatching_Context
return Boolean is
5464 Par
: constant Node_Id
:= Parent
(N
);
5467 return Nkind
(Par
) in N_Subprogram_Call
5468 and then Is_Entity_Name
(Name
(Par
))
5469 and then Is_Dispatching_Operation
(Entity
(Name
(Par
)));
5470 end In_Dispatching_Context
;
5472 -- Start of processing for Resolve_Allocator
5475 -- Replace general access with specific type
5477 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
5478 Set_Etype
(N
, Base_Type
(Typ
));
5481 if Is_Abstract_Type
(Typ
) then
5482 Error_Msg_N
("type of allocator cannot be abstract", N
);
5485 -- For qualified expression, resolve the expression using the given
5486 -- subtype (nothing to do for type mark, subtype indication)
5488 if Nkind
(E
) = N_Qualified_Expression
then
5489 if Is_Class_Wide_Type
(Etype
(E
))
5490 and then not Is_Class_Wide_Type
(Desig_T
)
5491 and then not In_Dispatching_Context
5494 ("class-wide allocator not allowed for this access type", N
);
5497 -- Do a full resolution to apply constraint and predicate checks
5499 Resolve_Qualified_Expression
(E
, Etype
(E
));
5500 Check_Unset_Reference
(Expression
(E
));
5502 -- Allocators generated by the build-in-place expansion mechanism
5503 -- are explicitly marked as coming from source but do not need to be
5504 -- checked for limited initialization. To exclude this case, ensure
5505 -- that the parent of the allocator is a source node.
5506 -- The return statement constructed for an Expression_Function does
5507 -- not come from source but requires a limited check.
5509 if Is_Limited_Type
(Etype
(E
))
5510 and then Comes_From_Source
(N
)
5512 (Comes_From_Source
(Parent
(N
))
5514 (Ekind
(Current_Scope
) = E_Function
5515 and then Nkind
(Original_Node
(Unit_Declaration_Node
5516 (Current_Scope
))) = N_Expression_Function
))
5517 and then not In_Instance_Body
5519 if not OK_For_Limited_Init
(Etype
(E
), Expression
(E
)) then
5520 if Nkind
(Parent
(N
)) = N_Assignment_Statement
then
5522 ("illegal expression for initialized allocator of a "
5523 & "limited type (RM 7.5 (2.7/2))", N
);
5526 ("initialization not allowed for limited types", N
);
5529 Explain_Limited_Type
(Etype
(E
), N
);
5533 -- Calls to build-in-place functions are not currently supported in
5534 -- allocators for access types associated with a simple storage pool.
5535 -- Supporting such allocators may require passing additional implicit
5536 -- parameters to build-in-place functions (or a significant revision
5537 -- of the current b-i-p implementation to unify the handling for
5538 -- multiple kinds of storage pools). ???
5540 if Is_Inherently_Limited_Type
(Desig_T
)
5541 and then Nkind
(Expression
(E
)) = N_Function_Call
5544 Pool
: constant Entity_Id
:=
5545 Associated_Storage_Pool
(Root_Type
(Typ
));
5549 Present
(Get_Rep_Pragma
5550 (Etype
(Pool
), Name_Simple_Storage_Pool_Type
))
5553 ("limited function calls not yet supported in simple "
5554 & "storage pool allocators", Expression
(E
));
5559 -- A special accessibility check is needed for allocators that
5560 -- constrain access discriminants. The level of the type of the
5561 -- expression used to constrain an access discriminant cannot be
5562 -- deeper than the type of the allocator (in contrast to access
5563 -- parameters, where the level of the actual can be arbitrary).
5565 -- We can't use Valid_Conversion to perform this check because in
5566 -- general the type of the allocator is unrelated to the type of
5567 -- the access discriminant.
5569 if Ekind
(Typ
) /= E_Anonymous_Access_Type
5570 or else Is_Local_Anonymous_Access
(Typ
)
5572 Subtyp
:= Entity
(Subtype_Mark
(E
));
5574 Aggr
:= Original_Node
(Expression
(E
));
5576 if Has_Discriminants
(Subtyp
)
5577 and then Nkind
(Aggr
) in N_Aggregate | N_Extension_Aggregate
5579 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
5581 -- Get the first component expression of the aggregate
5583 if Present
(Expressions
(Aggr
)) then
5584 Disc_Exp
:= First
(Expressions
(Aggr
));
5586 elsif Present
(Component_Associations
(Aggr
)) then
5587 Assoc
:= First
(Component_Associations
(Aggr
));
5589 if Present
(Assoc
) then
5590 Disc_Exp
:= Expression
(Assoc
);
5599 while Present
(Discrim
) and then Present
(Disc_Exp
) loop
5600 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
5601 Check_Allocator_Discrim_Accessibility_Exprs
5605 Next_Discriminant
(Discrim
);
5607 if Present
(Discrim
) then
5608 if Present
(Assoc
) then
5610 Disc_Exp
:= Expression
(Assoc
);
5612 elsif Present
(Next
(Disc_Exp
)) then
5616 Assoc
:= First
(Component_Associations
(Aggr
));
5618 if Present
(Assoc
) then
5619 Disc_Exp
:= Expression
(Assoc
);
5629 -- For a subtype mark or subtype indication, freeze the subtype
5632 Freeze_Expression
(E
);
5634 if Is_Access_Constant
(Typ
) and then not No_Initialization
(N
) then
5636 ("initialization required for access-to-constant allocator", N
);
5639 -- A special accessibility check is needed for allocators that
5640 -- constrain access discriminants. The level of the type of the
5641 -- expression used to constrain an access discriminant cannot be
5642 -- deeper than the type of the allocator (in contrast to access
5643 -- parameters, where the level of the actual can be arbitrary).
5644 -- We can't use Valid_Conversion to perform this check because
5645 -- in general the type of the allocator is unrelated to the type
5646 -- of the access discriminant.
5648 if Nkind
(Original_Node
(E
)) = N_Subtype_Indication
5649 and then (Ekind
(Typ
) /= E_Anonymous_Access_Type
5650 or else Is_Local_Anonymous_Access
(Typ
))
5652 Subtyp
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
5654 if Has_Discriminants
(Subtyp
) then
5655 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
5656 Constr
:= First
(Constraints
(Constraint
(Original_Node
(E
))));
5657 while Present
(Discrim
) and then Present
(Constr
) loop
5658 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
5659 if Nkind
(Constr
) = N_Discriminant_Association
then
5660 Disc_Exp
:= Expression
(Constr
);
5665 Check_Allocator_Discrim_Accessibility_Exprs
5669 Next_Discriminant
(Discrim
);
5676 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
5677 -- check that the level of the type of the created object is not deeper
5678 -- than the level of the allocator's access type, since extensions can
5679 -- now occur at deeper levels than their ancestor types. This is a
5680 -- static accessibility level check; a run-time check is also needed in
5681 -- the case of an initialized allocator with a class-wide argument (see
5682 -- Expand_Allocator_Expression).
5684 if Ada_Version
>= Ada_2005
5685 and then Is_Class_Wide_Type
(Desig_T
)
5688 Exp_Typ
: Entity_Id
;
5691 if Nkind
(E
) = N_Qualified_Expression
then
5692 Exp_Typ
:= Etype
(E
);
5693 elsif Nkind
(E
) = N_Subtype_Indication
then
5694 Exp_Typ
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
5696 Exp_Typ
:= Entity
(E
);
5699 if Type_Access_Level
(Exp_Typ
) >
5700 Deepest_Type_Access_Level
(Typ
)
5702 if In_Instance_Body
then
5703 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5705 ("type in allocator has deeper level than designated "
5706 & "class-wide type<<", E
);
5707 Error_Msg_N
("\Program_Error [<<", E
);
5710 Make_Raise_Program_Error
(Sloc
(N
),
5711 Reason
=> PE_Accessibility_Check_Failed
));
5714 -- Do not apply Ada 2005 accessibility checks on a class-wide
5715 -- allocator if the type given in the allocator is a formal
5716 -- type or within a formal package. A run-time check will be
5717 -- performed in the instance.
5719 elsif not Is_Generic_Type
(Exp_Typ
)
5720 and then not In_Generic_Formal_Package
(Exp_Typ
)
5723 ("type in allocator has deeper level than designated "
5724 & "class-wide type", E
);
5730 -- Check for allocation from an empty storage pool. But do not complain
5731 -- if it's a return statement for a build-in-place function, because the
5732 -- allocator is there just in case the caller uses an allocator. If the
5733 -- caller does use an allocator, it will be caught at the call site.
5735 if No_Pool_Assigned
(Typ
)
5736 and then not For_Special_Return_Object
(N
)
5738 Error_Msg_N
("allocation from empty storage pool!", N
);
5740 -- If the context is an unchecked conversion, as may happen within an
5741 -- inlined subprogram, the allocator is being resolved with its own
5742 -- anonymous type. In that case, if the target type has a specific
5743 -- storage pool, it must be inherited explicitly by the allocator type.
5745 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
5746 and then No
(Associated_Storage_Pool
(Typ
))
5748 Set_Associated_Storage_Pool
5749 (Typ
, Associated_Storage_Pool
(Etype
(Parent
(N
))));
5752 if Ekind
(Etype
(N
)) = E_Anonymous_Access_Type
then
5753 Check_Restriction
(No_Anonymous_Allocators
, N
);
5756 -- Check that an allocator with task parts isn't for a nested access
5757 -- type when restriction No_Task_Hierarchy applies.
5759 if not Is_Library_Level_Entity
(Base_Type
(Typ
))
5760 and then Has_Task
(Base_Type
(Desig_T
))
5762 Check_Restriction
(No_Task_Hierarchy
, N
);
5765 -- An illegal allocator may be rewritten as a raise Program_Error
5768 if Nkind
(N
) = N_Allocator
then
5770 -- Avoid coextension processing for an allocator that is the
5771 -- expansion of a build-in-place function call.
5773 if Nkind
(Original_Node
(N
)) = N_Allocator
5774 and then Nkind
(Expression
(Original_Node
(N
))) =
5775 N_Qualified_Expression
5776 and then Nkind
(Expression
(Expression
(Original_Node
(N
)))) =
5778 and then Is_Expanded_Build_In_Place_Call
5779 (Expression
(Expression
(Original_Node
(N
))))
5781 null; -- b-i-p function call case
5784 -- An anonymous access discriminant is the definition of a
5787 if Ekind
(Typ
) = E_Anonymous_Access_Type
5788 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
5789 N_Discriminant_Specification
5792 Discr
: constant Entity_Id
:=
5793 Defining_Identifier
(Associated_Node_For_Itype
(Typ
));
5796 Check_Restriction
(No_Coextensions
, N
);
5798 -- Ada 2012 AI05-0052: If the designated type of the
5799 -- allocator is limited, then the allocator shall not
5800 -- be used to define the value of an access discriminant
5801 -- unless the discriminated type is immutably limited.
5803 if Ada_Version
>= Ada_2012
5804 and then Is_Limited_Type
(Desig_T
)
5805 and then not Is_Inherently_Limited_Type
(Scope
(Discr
))
5808 ("only immutably limited types can have anonymous "
5809 & "access discriminants designating a limited type",
5814 -- Avoid marking an allocator as a dynamic coextension if it is
5815 -- within a static construct.
5817 if not Is_Static_Coextension
(N
) then
5818 Set_Is_Dynamic_Coextension
(N
);
5820 -- Finalization and deallocation of coextensions utilizes an
5821 -- approximate implementation which does not directly adhere
5822 -- to the semantic rules. Warn on potential issues involving
5825 if Is_Controlled
(Desig_T
) then
5827 ("??coextension will not be finalized when its "
5828 & "associated owner is deallocated or finalized", N
);
5831 ("??coextension will not be deallocated when its "
5832 & "associated owner is deallocated", N
);
5836 -- Cleanup for potential static coextensions
5839 Set_Is_Dynamic_Coextension
(N
, False);
5840 Set_Is_Static_Coextension
(N
, False);
5842 -- Objects allocated through anonymous access types are not
5843 -- finalized on time because this involves run-time ownership
5844 -- and currently this property is not available. In rare cases
5845 -- the object might not be finalized at all. Warn on potential
5846 -- issues involving anonymous access-to-controlled types.
5848 if Ekind
(Typ
) = E_Anonymous_Access_Type
5849 and then Is_Controlled_Active
(Desig_T
)
5852 ("??object designated by anonymous access value might "
5853 & "not be finalized until its enclosing library unit "
5854 & "goes out of scope, or not be finalized at all", N
);
5855 Error_Msg_N
("\use named access type instead", N
);
5861 -- Report a simple error: if the designated object is a local task,
5862 -- its body has not been seen yet, and its activation will fail an
5863 -- elaboration check.
5865 if Is_Task_Type
(Desig_T
)
5866 and then Scope
(Base_Type
(Desig_T
)) = Current_Scope
5867 and then Is_Compilation_Unit
(Current_Scope
)
5868 and then Ekind
(Current_Scope
) = E_Package
5869 and then not In_Package_Body
(Current_Scope
)
5871 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5872 Error_Msg_N
("cannot activate task before body seen<<", N
);
5873 Error_Msg_N
("\Program_Error [<<", N
);
5876 -- Ada 2012 (AI05-0111-3): Detect an attempt to allocate a task or a
5877 -- type with a task component on a subpool. This action must raise
5878 -- Program_Error at runtime.
5880 if Ada_Version
>= Ada_2012
5881 and then Nkind
(N
) = N_Allocator
5882 and then Present
(Subpool_Handle_Name
(N
))
5883 and then Has_Task
(Desig_T
)
5885 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5886 Error_Msg_N
("cannot allocate task on subpool<<", N
);
5887 Error_Msg_N
("\Program_Error [<<", N
);
5890 Make_Raise_Program_Error
(Sloc
(N
),
5891 Reason
=> PE_Explicit_Raise
));
5894 end Resolve_Allocator
;
5896 ---------------------------
5897 -- Resolve_Arithmetic_Op --
5898 ---------------------------
5900 -- Used for resolving all arithmetic operators except exponentiation
5902 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
5903 L
: constant Node_Id
:= Left_Opnd
(N
);
5904 R
: constant Node_Id
:= Right_Opnd
(N
);
5905 TL
: constant Entity_Id
:= Base_Type
(Etype
(L
));
5906 TR
: constant Entity_Id
:= Base_Type
(Etype
(R
));
5910 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
5911 -- We do the resolution using the base type, because intermediate values
5912 -- in expressions always are of the base type, not a subtype of it.
5914 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean;
5915 -- Returns True if N is in a context that expects "any real type"
5917 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean;
5918 -- Return True iff given type is Integer or universal real/integer
5920 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
);
5921 -- Choose type of integer literal in fixed-point operation to conform
5922 -- to available fixed-point type. T is the type of the other operand,
5923 -- which is needed to determine the expected type of N.
5925 procedure Set_Operand_Type
(N
: Node_Id
);
5926 -- Set operand type to T if universal
5928 -------------------------------
5929 -- Expected_Type_Is_Any_Real --
5930 -------------------------------
5932 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean is
5934 -- N is the expression after "delta" in a fixed_point_definition;
5937 return Nkind
(Parent
(N
)) in N_Ordinary_Fixed_Point_Definition
5938 | N_Decimal_Fixed_Point_Definition
5940 -- N is one of the bounds in a real_range_specification;
5943 | N_Real_Range_Specification
5945 -- N is the expression of a delta_constraint;
5948 | N_Delta_Constraint
;
5949 end Expected_Type_Is_Any_Real
;
5951 -----------------------------
5952 -- Is_Integer_Or_Universal --
5953 -----------------------------
5955 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean is
5957 Index
: Interp_Index
;
5961 if not Is_Overloaded
(N
) then
5963 return Base_Type
(T
) = Base_Type
(Standard_Integer
)
5964 or else Is_Universal_Numeric_Type
(T
);
5966 Get_First_Interp
(N
, Index
, It
);
5967 while Present
(It
.Typ
) loop
5968 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
)
5969 or else Is_Universal_Numeric_Type
(It
.Typ
)
5974 Get_Next_Interp
(Index
, It
);
5979 end Is_Integer_Or_Universal
;
5981 ----------------------------
5982 -- Set_Mixed_Mode_Operand --
5983 ----------------------------
5985 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
) is
5986 Index
: Interp_Index
;
5990 if Universal_Interpretation
(N
) = Universal_Integer
then
5992 -- A universal integer literal is resolved as standard integer
5993 -- except in the case of a fixed-point result, where we leave it
5994 -- as universal (to be handled by Exp_Fixd later on)
5996 if Is_Fixed_Point_Type
(T
) then
5997 Resolve
(N
, Universal_Integer
);
5999 Resolve
(N
, Standard_Integer
);
6002 elsif Universal_Interpretation
(N
) = Universal_Real
6003 and then (T
= Base_Type
(Standard_Integer
)
6004 or else Is_Universal_Numeric_Type
(T
))
6006 -- A universal real can appear in a fixed-type context. We resolve
6007 -- the literal with that context, even though this might raise an
6008 -- exception prematurely (the other operand may be zero).
6012 elsif Etype
(N
) = Base_Type
(Standard_Integer
)
6013 and then T
= Universal_Real
6014 and then Is_Overloaded
(N
)
6016 -- Integer arg in mixed-mode operation. Resolve with universal
6017 -- type, in case preference rule must be applied.
6019 Resolve
(N
, Universal_Integer
);
6021 elsif Etype
(N
) = T
and then B_Typ
/= Universal_Fixed
then
6023 -- If the operand is part of a fixed multiplication operation,
6024 -- a conversion will be applied to each operand, so resolve it
6025 -- with its own type.
6027 if Nkind
(Parent
(N
)) in N_Op_Divide | N_Op_Multiply
then
6031 -- Not a mixed-mode operation, resolve with context
6036 elsif Etype
(N
) = Any_Fixed
then
6038 -- N may itself be a mixed-mode operation, so use context type
6042 elsif Is_Fixed_Point_Type
(T
)
6043 and then B_Typ
= Universal_Fixed
6044 and then Is_Overloaded
(N
)
6046 -- Must be (fixed * fixed) operation, operand must have one
6047 -- compatible interpretation.
6049 Resolve
(N
, Any_Fixed
);
6051 elsif Is_Fixed_Point_Type
(B_Typ
)
6052 and then (T
= Universal_Real
or else Is_Fixed_Point_Type
(T
))
6053 and then Is_Overloaded
(N
)
6055 -- C * F(X) in a fixed context, where C is a real literal or a
6056 -- fixed-point expression. F must have either a fixed type
6057 -- interpretation or an integer interpretation, but not both.
6059 Get_First_Interp
(N
, Index
, It
);
6060 while Present
(It
.Typ
) loop
6061 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
) then
6062 if Analyzed
(N
) then
6063 Error_Msg_N
("ambiguous operand in fixed operation", N
);
6065 Resolve
(N
, Standard_Integer
);
6068 elsif Is_Fixed_Point_Type
(It
.Typ
) then
6069 if Analyzed
(N
) then
6070 Error_Msg_N
("ambiguous operand in fixed operation", N
);
6072 Resolve
(N
, It
.Typ
);
6076 Get_Next_Interp
(Index
, It
);
6079 -- Reanalyze the literal with the fixed type of the context. If
6080 -- context is Universal_Fixed, we are within a conversion, leave
6081 -- the literal as a universal real because there is no usable
6082 -- fixed type, and the target of the conversion plays no role in
6096 if B_Typ
= Universal_Fixed
6097 and then Nkind
(Op2
) = N_Real_Literal
6099 T2
:= Universal_Real
;
6104 Set_Analyzed
(Op2
, False);
6108 -- A universal real conditional expression can appear in a fixed-type
6109 -- context and must be resolved with that context to facilitate the
6110 -- code generation in the back end. However, If the context is
6111 -- Universal_fixed (i.e. as an operand of a multiplication/division
6112 -- involving a fixed-point operand) the conditional expression must
6113 -- resolve to a unique visible fixed_point type, normally Duration.
6115 elsif Nkind
(N
) in N_Case_Expression | N_If_Expression
6116 and then Etype
(N
) = Universal_Real
6117 and then Is_Fixed_Point_Type
(B_Typ
)
6119 if B_Typ
= Universal_Fixed
then
6120 Resolve
(N
, Unique_Fixed_Point_Type
(N
));
6129 end Set_Mixed_Mode_Operand
;
6131 ----------------------
6132 -- Set_Operand_Type --
6133 ----------------------
6135 procedure Set_Operand_Type
(N
: Node_Id
) is
6137 if Is_Universal_Numeric_Type
(Etype
(N
)) then
6140 end Set_Operand_Type
;
6142 -- Start of processing for Resolve_Arithmetic_Op
6145 if Ekind
(Entity
(N
)) = E_Function
6146 and then Is_Imported
(Entity
(N
))
6147 and then Is_Intrinsic_Subprogram
(Entity
(N
))
6149 Generate_Reference
(Entity
(N
), N
);
6150 Resolve_Intrinsic_Operator
(N
, Typ
);
6153 -- Special-case for mixed-mode universal expressions or fixed point type
6154 -- operation: each argument is resolved separately. The same treatment
6155 -- is required if one of the operands of a fixed point operation is
6156 -- universal real, since in this case we don't do a conversion to a
6157 -- specific fixed-point type (instead the expander handles the case).
6159 -- Set the type of the node to its universal interpretation because
6160 -- legality checks on an exponentiation operand need the context.
6162 elsif Is_Universal_Numeric_Type
(B_Typ
)
6163 and then Present
(Universal_Interpretation
(L
))
6164 and then Present
(Universal_Interpretation
(R
))
6166 Set_Etype
(N
, B_Typ
);
6167 Resolve
(L
, Universal_Interpretation
(L
));
6168 Resolve
(R
, Universal_Interpretation
(R
));
6170 elsif (B_Typ
= Universal_Real
6171 or else Etype
(N
) = Universal_Fixed
6172 or else (Etype
(N
) = Any_Fixed
6173 and then Is_Fixed_Point_Type
(B_Typ
))
6174 or else (Is_Fixed_Point_Type
(B_Typ
)
6175 and then (Is_Integer_Or_Universal
(L
)
6177 Is_Integer_Or_Universal
(R
))))
6178 and then Nkind
(N
) in N_Op_Multiply | N_Op_Divide
6180 if TL
= Universal_Integer
or else TR
= Universal_Integer
then
6181 Check_For_Visible_Operator
(N
, B_Typ
);
6184 -- If context is a fixed type and one operand is integer, the other
6185 -- is resolved with the type of the context.
6187 if Is_Fixed_Point_Type
(B_Typ
)
6188 and then (Base_Type
(TL
) = Base_Type
(Standard_Integer
)
6189 or else TL
= Universal_Integer
)
6194 elsif Is_Fixed_Point_Type
(B_Typ
)
6195 and then (Base_Type
(TR
) = Base_Type
(Standard_Integer
)
6196 or else TR
= Universal_Integer
)
6201 -- If both operands are universal and the context is a floating
6202 -- point type, the operands are resolved to the type of the context.
6204 elsif Is_Floating_Point_Type
(B_Typ
) then
6209 Set_Mixed_Mode_Operand
(L
, TR
);
6210 Set_Mixed_Mode_Operand
(R
, TL
);
6213 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
6214 -- multiplying operators from being used when the expected type is
6215 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
6216 -- some cases where the expected type is actually Any_Real;
6217 -- Expected_Type_Is_Any_Real takes care of that case.
6219 if Etype
(N
) = Universal_Fixed
6220 or else Etype
(N
) = Any_Fixed
6222 if B_Typ
= Universal_Fixed
6223 and then not Expected_Type_Is_Any_Real
(N
)
6224 and then Nkind
(Parent
(N
)) not in
6225 N_Type_Conversion | N_Unchecked_Type_Conversion
6227 Error_Msg_N
("type cannot be determined from context!", N
);
6228 Error_Msg_N
("\explicit conversion to result type required", N
);
6230 Set_Etype
(L
, Any_Type
);
6231 Set_Etype
(R
, Any_Type
);
6234 if Ada_Version
= Ada_83
6235 and then Etype
(N
) = Universal_Fixed
6236 and then Nkind
(Parent
(N
)) not in
6237 N_Type_Conversion | N_Unchecked_Type_Conversion
6240 ("(Ada 83) fixed-point operation needs explicit "
6244 -- The expected type is "any real type" in contexts like
6246 -- type T is delta <universal_fixed-expression> ...
6248 -- in which case we need to set the type to Universal_Real
6249 -- so that static expression evaluation will work properly.
6251 if Expected_Type_Is_Any_Real
(N
) then
6252 Set_Etype
(N
, Universal_Real
);
6254 Set_Etype
(N
, B_Typ
);
6258 elsif Is_Fixed_Point_Type
(B_Typ
)
6259 and then (Is_Integer_Or_Universal
(L
)
6260 or else Nkind
(L
) = N_Real_Literal
6261 or else Nkind
(R
) = N_Real_Literal
6262 or else Is_Integer_Or_Universal
(R
))
6264 Set_Etype
(N
, B_Typ
);
6266 elsif Etype
(N
) = Any_Fixed
then
6268 -- If no previous errors, this is only possible if one operand is
6269 -- overloaded and the context is universal. Resolve as such.
6271 Set_Etype
(N
, B_Typ
);
6275 if Is_Universal_Numeric_Type
(TL
)
6277 Is_Universal_Numeric_Type
(TR
)
6279 Check_For_Visible_Operator
(N
, B_Typ
);
6282 -- If the context is Universal_Fixed and the operands are also
6283 -- universal fixed, this is an error, unless there is only one
6284 -- applicable fixed_point type (usually Duration).
6286 if B_Typ
= Universal_Fixed
and then Etype
(L
) = Universal_Fixed
then
6287 T
:= Unique_Fixed_Point_Type
(N
);
6289 if T
= Any_Type
then
6302 -- If one of the arguments was resolved to a non-universal type.
6303 -- label the result of the operation itself with the same type.
6304 -- Do the same for the universal argument, if any.
6306 T
:= Intersect_Types
(L
, R
);
6307 Set_Etype
(N
, Base_Type
(T
));
6308 Set_Operand_Type
(L
);
6309 Set_Operand_Type
(R
);
6312 Generate_Operator_Reference
(N
, Typ
);
6313 Analyze_Dimension
(N
);
6314 Eval_Arithmetic_Op
(N
);
6316 -- Set overflow and division checking bit
6318 if Nkind
(N
) in N_Op
then
6319 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
6320 Enable_Overflow_Check
(N
);
6323 -- Give warning if explicit division by zero
6325 if Nkind
(N
) in N_Op_Divide | N_Op_Rem | N_Op_Mod
6326 and then not Division_Checks_Suppressed
(Etype
(N
))
6328 Rop
:= Right_Opnd
(N
);
6330 if Compile_Time_Known_Value
(Rop
)
6331 and then ((Is_Integer_Type
(Etype
(Rop
))
6332 and then Expr_Value
(Rop
) = Uint_0
)
6334 (Is_Real_Type
(Etype
(Rop
))
6335 and then Expr_Value_R
(Rop
) = Ureal_0
))
6337 -- Specialize the warning message according to the operation.
6338 -- When SPARK_Mode is On, force a warning instead of an error
6339 -- in that case, as this likely corresponds to deactivated
6340 -- code. The following warnings are for the case
6345 -- For division, we have two cases, for float division
6346 -- of an unconstrained float type, on a machine where
6347 -- Machine_Overflows is false, we don't get an exception
6348 -- at run-time, but rather an infinity or Nan. The Nan
6349 -- case is pretty obscure, so just warn about infinities.
6351 if Is_Floating_Point_Type
(Typ
)
6352 and then not Is_Constrained
(Typ
)
6353 and then not Machine_Overflows_On_Target
6356 ("float division by zero, may generate "
6357 & "'+'/'- infinity??", Right_Opnd
(N
));
6359 -- For all other cases, we get a Constraint_Error
6362 Apply_Compile_Time_Constraint_Error
6363 (N
, "division by zero??", CE_Divide_By_Zero
,
6364 Loc
=> Sloc
(Right_Opnd
(N
)),
6365 Warn
=> SPARK_Mode
= On
);
6369 Apply_Compile_Time_Constraint_Error
6370 (N
, "rem with zero divisor??", CE_Divide_By_Zero
,
6371 Loc
=> Sloc
(Right_Opnd
(N
)),
6372 Warn
=> SPARK_Mode
= On
);
6375 Apply_Compile_Time_Constraint_Error
6376 (N
, "mod with zero divisor??", CE_Divide_By_Zero
,
6377 Loc
=> Sloc
(Right_Opnd
(N
)),
6378 Warn
=> SPARK_Mode
= On
);
6380 -- Division by zero can only happen with division, rem,
6381 -- and mod operations.
6384 raise Program_Error
;
6387 -- Otherwise just set the flag to check at run time
6390 Activate_Division_Check
(N
);
6394 -- If Restriction No_Implicit_Conditionals is active, then it is
6395 -- violated if either operand can be negative for mod, or for rem
6396 -- if both operands can be negative.
6398 if Restriction_Check_Required
(No_Implicit_Conditionals
)
6399 and then Nkind
(N
) in N_Op_Rem | N_Op_Mod
6408 -- Set if corresponding operand might be negative
6412 (Left_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
6413 LNeg
:= not OK
or else Lo
< 0;
6416 (Right_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
6417 RNeg
:= not OK
or else Lo
< 0;
6419 -- Check if we will be generating conditionals. There are two
6420 -- cases where that can happen, first for REM, the only case
6421 -- is largest negative integer mod -1, where the division can
6422 -- overflow, but we still have to give the right result. The
6423 -- front end generates a test for this annoying case. Here we
6424 -- just test if both operands can be negative (that's what the
6425 -- expander does, so we match its logic here).
6427 -- The second case is mod where either operand can be negative.
6428 -- In this case, the back end has to generate additional tests.
6430 if (Nkind
(N
) = N_Op_Rem
and then (LNeg
and RNeg
))
6432 (Nkind
(N
) = N_Op_Mod
and then (LNeg
or RNeg
))
6434 Check_Restriction
(No_Implicit_Conditionals
, N
);
6440 Check_Unset_Reference
(L
);
6441 Check_Unset_Reference
(R
);
6442 end Resolve_Arithmetic_Op
;
6448 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
6449 Loc
: constant Source_Ptr
:= Sloc
(N
);
6450 Subp
: constant Node_Id
:= Name
(N
);
6451 Body_Id
: Entity_Id
;
6462 -- Preserve relevant elaboration-related attributes of the context which
6463 -- are no longer available or very expensive to recompute once analysis,
6464 -- resolution, and expansion are over.
6466 Mark_Elaboration_Attributes
6472 -- The context imposes a unique interpretation with type Typ on a
6473 -- procedure or function call. Find the entity of the subprogram that
6474 -- yields the expected type, and propagate the corresponding formal
6475 -- constraints on the actuals. The caller has established that an
6476 -- interpretation exists, and emitted an error if not unique.
6478 -- First deal with the case of a call to an access-to-subprogram,
6479 -- dereference made explicit in Analyze_Call.
6481 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
6482 if not Is_Overloaded
(Subp
) then
6483 Nam
:= Etype
(Subp
);
6486 -- Find the interpretation whose type (a subprogram type) has a
6487 -- return type that is compatible with the context. Analysis of
6488 -- the node has established that one exists.
6492 Get_First_Interp
(Subp
, I
, It
);
6493 while Present
(It
.Typ
) loop
6494 if Covers
(Typ
, Etype
(It
.Typ
)) then
6499 Get_Next_Interp
(I
, It
);
6503 raise Program_Error
;
6507 -- If the prefix is not an entity, then resolve it
6509 if not Is_Entity_Name
(Subp
) then
6510 Resolve
(Subp
, Nam
);
6513 -- For an indirect call, we always invalidate checks, since we do not
6514 -- know whether the subprogram is local or global. Yes we could do
6515 -- better here, e.g. by knowing that there are no local subprograms,
6516 -- but it does not seem worth the effort. Similarly, we kill all
6517 -- knowledge of current constant values.
6519 Kill_Current_Values
;
6521 -- If this is a procedure call which is really an entry call, do
6522 -- the conversion of the procedure call to an entry call. Protected
6523 -- operations use the same circuitry because the name in the call
6524 -- can be an arbitrary expression with special resolution rules.
6526 elsif Nkind
(Subp
) in N_Selected_Component | N_Indexed_Component
6527 or else (Is_Entity_Name
(Subp
) and then Is_Entry
(Entity
(Subp
)))
6529 Resolve_Entry_Call
(N
, Typ
);
6531 if Legacy_Elaboration_Checks
then
6532 Check_Elab_Call
(N
);
6535 -- Annotate the tree by creating a call marker in case the original
6536 -- call is transformed by expansion. The call marker is automatically
6537 -- saved for later examination by the ABE Processing phase.
6539 Build_Call_Marker
(N
);
6541 -- Kill checks and constant values, as above for indirect case
6542 -- Who knows what happens when another task is activated?
6544 Kill_Current_Values
;
6547 -- Normal subprogram call with name established in Resolve
6549 elsif not Is_Type
(Entity
(Subp
)) then
6550 Nam
:= Entity
(Subp
);
6551 Set_Entity_With_Checks
(Subp
, Nam
);
6553 -- Otherwise we must have the case of an overloaded call
6556 pragma Assert
(Is_Overloaded
(Subp
));
6558 -- Initialize Nam to prevent warning (we know it will be assigned
6559 -- in the loop below, but the compiler does not know that).
6563 Get_First_Interp
(Subp
, I
, It
);
6564 while Present
(It
.Typ
) loop
6565 if Covers
(Typ
, It
.Typ
) then
6567 Set_Entity_With_Checks
(Subp
, Nam
);
6571 Get_Next_Interp
(I
, It
);
6575 -- Check that a call to Current_Task does not occur in an entry body
6577 if Is_RTE
(Nam
, RE_Current_Task
) then
6586 -- Exclude calls that occur within the default of a formal
6587 -- parameter of the entry, since those are evaluated outside
6590 exit when No
(P
) or else Nkind
(P
) = N_Parameter_Specification
;
6592 if Nkind
(P
) = N_Entry_Body
6593 or else (Nkind
(P
) = N_Subprogram_Body
6594 and then Is_Entry_Barrier_Function
(P
))
6597 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6599 ("& should not be used in entry body (RM C.7(17))<<",
6601 Error_Msg_NE
("\Program_Error [<<", N
, Nam
);
6603 Make_Raise_Program_Error
(Loc
,
6604 Reason
=> PE_Current_Task_In_Entry_Body
));
6605 Set_Etype
(N
, Rtype
);
6612 -- Check that a procedure call does not occur in the context of the
6613 -- entry call statement of a conditional or timed entry call. Note that
6614 -- the case of a call to a subprogram renaming of an entry will also be
6615 -- rejected. The test for N not being an N_Entry_Call_Statement is
6616 -- defensive, covering the possibility that the processing of entry
6617 -- calls might reach this point due to later modifications of the code
6620 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
6621 and then Nkind
(N
) /= N_Entry_Call_Statement
6622 and then Entry_Call_Statement
(Parent
(N
)) = N
6624 if Ada_Version
< Ada_2005
then
6625 Error_Msg_N
("entry call required in select statement", N
);
6627 -- Ada 2005 (AI-345): If a procedure_call_statement is used
6628 -- for a procedure_or_entry_call, the procedure_name or
6629 -- procedure_prefix of the procedure_call_statement shall denote
6630 -- an entry renamed by a procedure, or (a view of) a primitive
6631 -- subprogram of a limited interface whose first parameter is
6632 -- a controlling parameter.
6634 elsif Nkind
(N
) = N_Procedure_Call_Statement
6635 and then not Is_Renamed_Entry
(Nam
)
6636 and then not Is_Controlling_Limited_Procedure
(Nam
)
6639 ("entry call or dispatching primitive of interface required", N
);
6643 -- Check that this is not a call to a protected procedure or entry from
6644 -- within a protected function.
6646 Check_Internal_Protected_Use
(N
, Nam
);
6648 -- Freeze the subprogram name if not in a spec-expression. Note that
6649 -- we freeze procedure calls as well as function calls. Procedure calls
6650 -- are not frozen according to the rules (RM 13.14(14)) because it is
6651 -- impossible to have a procedure call to a non-frozen procedure in
6652 -- pure Ada, but in the code that we generate in the expander, this
6653 -- rule needs extending because we can generate procedure calls that
6656 -- In Ada 2012, expression functions may be called within pre/post
6657 -- conditions of subsequent functions or expression functions. Such
6658 -- calls do not freeze when they appear within generated bodies,
6659 -- (including the body of another expression function) which would
6660 -- place the freeze node in the wrong scope. An expression function
6661 -- is frozen in the usual fashion, by the appearance of a real body,
6662 -- or at the end of a declarative part. However an implicit call to
6663 -- an expression function may appear when it is part of a default
6664 -- expression in a call to an initialization procedure, and must be
6665 -- frozen now, even if the body is inserted at a later point.
6666 -- Otherwise, the call freezes the expression if expander is active,
6667 -- for example as part of an object declaration.
6669 if Is_Entity_Name
(Subp
)
6670 and then not In_Spec_Expression
6671 and then not Is_Expression_Function_Or_Completion
(Current_Scope
)
6672 and then not (Chars
(Current_Scope
) = Name_uWrapped_Statements
6673 and then Is_Expression_Function_Or_Completion
6674 (Scope
(Current_Scope
)))
6676 (not Is_Expression_Function_Or_Completion
(Entity
(Subp
))
6677 or else Expander_Active
)
6679 if Is_Expression_Function
(Entity
(Subp
)) then
6681 -- Force freeze of expression function in call
6683 Set_Comes_From_Source
(Subp
, True);
6684 Set_Must_Not_Freeze
(Subp
, False);
6687 Freeze_Expression
(Subp
);
6690 -- For a predefined operator, the type of the result is the type imposed
6691 -- by context, except for a predefined operation on universal fixed.
6692 -- Otherwise the type of the call is the type returned by the subprogram
6695 if Is_Predefined_Op
(Nam
) then
6696 if Etype
(N
) /= Universal_Fixed
then
6700 -- If the subprogram returns an array type, and the context requires the
6701 -- component type of that array type, the node is really an indexing of
6702 -- the parameterless call. Resolve as such. A pathological case occurs
6703 -- when the type of the component is an access to the array type. In
6704 -- this case the call is truly ambiguous. If the call is to an intrinsic
6705 -- subprogram, it can't be an indexed component. This check is necessary
6706 -- because if it's Unchecked_Conversion, and we have "type T_Ptr is
6707 -- access T;" and "type T is array (...) of T_Ptr;" (i.e. an array of
6708 -- pointers to the same array), the compiler gets confused and does an
6709 -- infinite recursion.
6711 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
6713 ((Is_Array_Type
(Etype
(Nam
))
6714 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
6716 (Is_Access_Type
(Etype
(Nam
))
6717 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
6719 Covers
(Typ
, Component_Type
(Designated_Type
(Etype
(Nam
))))
6720 and then not Is_Intrinsic_Subprogram
(Entity
(Subp
))))
6723 Index_Node
: Node_Id
;
6725 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
6728 -- If this is a parameterless call there is no ambiguity and the
6729 -- call has the type of the function.
6731 if No
(First_Actual
(N
)) then
6732 Set_Etype
(N
, Etype
(Nam
));
6734 if Present
(First_Formal
(Nam
)) then
6735 Resolve_Actuals
(N
, Nam
);
6738 -- Annotate the tree by creating a call marker in case the
6739 -- original call is transformed by expansion. The call marker
6740 -- is automatically saved for later examination by the ABE
6741 -- Processing phase.
6743 Build_Call_Marker
(N
);
6745 elsif Is_Access_Type
(Ret_Type
)
6747 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
6750 ("cannot disambiguate function call and indexing", N
);
6752 New_Subp
:= Relocate_Node
(Subp
);
6754 -- The called entity may be an explicit dereference, in which
6755 -- case there is no entity to set.
6757 if Nkind
(New_Subp
) /= N_Explicit_Dereference
then
6758 Set_Entity
(Subp
, Nam
);
6761 if (Is_Array_Type
(Ret_Type
)
6762 and then Component_Type
(Ret_Type
) /= Any_Type
)
6764 (Is_Access_Type
(Ret_Type
)
6766 Component_Type
(Designated_Type
(Ret_Type
)) /= Any_Type
)
6768 if Needs_No_Actuals
(Nam
) then
6770 -- Indexed call to a parameterless function
6773 Make_Indexed_Component
(Loc
,
6775 Make_Function_Call
(Loc
, Name
=> New_Subp
),
6776 Expressions
=> Parameter_Associations
(N
));
6778 -- An Ada 2005 prefixed call to a primitive operation
6779 -- whose first parameter is the prefix. This prefix was
6780 -- prepended to the parameter list, which is actually a
6781 -- list of indexes. Remove the prefix in order to build
6782 -- the proper indexed component.
6785 Make_Indexed_Component
(Loc
,
6787 Make_Function_Call
(Loc
,
6789 Parameter_Associations
=>
6791 (Remove_Head
(Parameter_Associations
(N
)))),
6792 Expressions
=> Parameter_Associations
(N
));
6795 -- Preserve the parenthesis count of the node
6797 Set_Paren_Count
(Index_Node
, Paren_Count
(N
));
6799 -- Since we are correcting a node classification error made
6800 -- by the parser, we call Replace rather than Rewrite.
6802 Replace
(N
, Index_Node
);
6804 Set_Etype
(Prefix
(N
), Ret_Type
);
6807 if Legacy_Elaboration_Checks
then
6808 Check_Elab_Call
(Prefix
(N
));
6811 -- Annotate the tree by creating a call marker in case
6812 -- the original call is transformed by expansion. The call
6813 -- marker is automatically saved for later examination by
6814 -- the ABE Processing phase.
6816 Build_Call_Marker
(Prefix
(N
));
6818 Resolve_Indexed_Component
(N
, Typ
);
6826 -- If the called function is not declared in the main unit and it
6827 -- returns the limited view of type then use the available view (as
6828 -- is done in Try_Object_Operation) to prevent back-end confusion;
6829 -- for the function entity itself. The call must appear in a context
6830 -- where the nonlimited view is available. If the function entity is
6831 -- in the extended main unit then no action is needed, because the
6832 -- back end handles this case. In either case the type of the call
6833 -- is the nonlimited view.
6835 if From_Limited_With
(Etype
(Nam
))
6836 and then Present
(Available_View
(Etype
(Nam
)))
6838 Set_Etype
(N
, Available_View
(Etype
(Nam
)));
6840 if not In_Extended_Main_Code_Unit
(Nam
) then
6841 Set_Etype
(Nam
, Available_View
(Etype
(Nam
)));
6845 Set_Etype
(N
, Etype
(Nam
));
6849 -- In the case where the call is to an overloaded subprogram, Analyze
6850 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
6851 -- such a case Normalize_Actuals needs to be called once more to order
6852 -- the actuals correctly. Otherwise the call will have the ordering
6853 -- given by the last overloaded subprogram whether this is the correct
6854 -- one being called or not.
6856 if Is_Overloaded
(Subp
) then
6857 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
6858 pragma Assert
(Norm_OK
);
6861 -- In any case, call is fully resolved now. Reset Overload flag, to
6862 -- prevent subsequent overload resolution if node is analyzed again
6864 Set_Is_Overloaded
(Subp
, False);
6865 Set_Is_Overloaded
(N
, False);
6867 -- A Ghost entity must appear in a specific context
6869 if Is_Ghost_Entity
(Nam
) and then Comes_From_Source
(N
) then
6870 Check_Ghost_Context
(Nam
, N
);
6873 if Is_Entity_Name
(Subp
) then
6874 Local_Restrict
.Check_Call
6875 (Call
=> N
, Callee
=> Ultimate_Alias
(Nam
));
6877 Local_Restrict
.Check_Call
(Call
=> N
);
6880 -- If we are calling the current subprogram from immediately within its
6881 -- body, then that is the case where we can sometimes detect cases of
6882 -- infinite recursion statically. Do not try this in case restriction
6883 -- No_Recursion is in effect anyway, and do it only for source calls.
6885 if Comes_From_Source
(N
) then
6886 Scop
:= Current_Scope
;
6888 -- Issue warning for possible infinite recursion in the absence
6889 -- of the No_Recursion restriction.
6891 if Same_Or_Aliased_Subprograms
(Nam
, Scop
)
6892 and then not Restriction_Active
(No_Recursion
)
6893 and then not Is_Static_Function
(Scop
)
6894 and then Check_Infinite_Recursion
(N
)
6896 -- Here we detected and flagged an infinite recursion, so we do
6897 -- not need to test the case below for further warnings. Also we
6898 -- are all done if we now have a raise SE node.
6900 if Nkind
(N
) = N_Raise_Storage_Error
then
6904 -- If call is to immediately containing subprogram, then check for
6905 -- the case of a possible run-time detectable infinite recursion.
6908 Scope_Loop
: while Scop
/= Standard_Standard
loop
6909 if Same_Or_Aliased_Subprograms
(Nam
, Scop
) then
6911 -- Ada 2022 (AI12-0075): Static functions are never allowed
6912 -- to make a recursive call, as specified by 6.8(5.4/5).
6914 if Is_Static_Function
(Scop
) then
6916 ("recursive call not allowed in static expression "
6919 Set_Error_Posted
(Scop
);
6924 -- Although in general case, recursion is not statically
6925 -- checkable, the case of calling an immediately containing
6926 -- subprogram is easy to catch.
6928 if not Is_Ignored_Ghost_Entity
(Nam
) then
6929 Check_Restriction
(No_Recursion
, N
);
6932 -- If the recursive call is to a parameterless subprogram,
6933 -- then even if we can't statically detect infinite
6934 -- recursion, this is pretty suspicious, and we output a
6935 -- warning. Furthermore, we will try later to detect some
6936 -- cases here at run time by expanding checking code (see
6937 -- Detect_Infinite_Recursion in package Exp_Ch6).
6939 -- If the recursive call is within a handler, do not emit a
6940 -- warning, because this is a common idiom: loop until input
6941 -- is correct, catch illegal input in handler and restart.
6943 if No
(First_Formal
(Nam
))
6944 and then Etype
(Nam
) = Standard_Void_Type
6945 and then not Error_Posted
(N
)
6946 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
6948 -- For the case of a procedure call. We give the message
6949 -- only if the call is the first statement in a sequence
6950 -- of statements, or if all previous statements are
6951 -- simple assignments. This is simply a heuristic to
6952 -- decrease false positives, without losing too many good
6953 -- warnings. The idea is that these previous statements
6954 -- may affect global variables the procedure depends on.
6955 -- We also exclude raise statements, that may arise from
6956 -- constraint checks and are probably unrelated to the
6957 -- intended control flow.
6959 if Nkind
(N
) = N_Procedure_Call_Statement
6960 and then Is_List_Member
(N
)
6966 while Present
(P
) loop
6967 if Nkind
(P
) not in N_Assignment_Statement
6968 | N_Raise_Constraint_Error
6978 -- Do not give warning if we are in a conditional context
6981 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
6983 if (K
= N_Loop_Statement
6984 and then Present
(Iteration_Scheme
(Parent
(N
))))
6985 or else K
= N_If_Statement
6986 or else K
= N_Elsif_Part
6987 or else K
= N_Case_Statement_Alternative
6993 -- Here warning is to be issued
6995 Set_Has_Recursive_Call
(Nam
);
6996 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6997 Error_Msg_N
("possible infinite recursion<<!", N
);
6998 Error_Msg_N
("\Storage_Error ]<<!", N
);
7004 Scop
:= Scope
(Scop
);
7005 end loop Scope_Loop
;
7009 -- Check obsolescent reference to Ada.Characters.Handling subprogram
7011 Check_Obsolescent_2005_Entity
(Nam
, Subp
);
7013 -- If subprogram name is a predefined operator, it was given in
7014 -- functional notation. Replace call node with operator node, so
7015 -- that actuals can be resolved appropriately.
7017 if Ekind
(Nam
) = E_Operator
or else Is_Predefined_Op
(Nam
) then
7018 Make_Call_Into_Operator
(N
, Typ
, Nam
);
7021 elsif Present
(Alias
(Nam
)) and then Is_Predefined_Op
(Alias
(Nam
)) then
7022 Resolve_Actuals
(N
, Nam
);
7023 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
7027 -- Create a transient scope if the expander is active and the resulting
7028 -- type requires it.
7030 -- There are several notable exceptions:
7032 -- a) Intrinsic subprograms (Unchecked_Conversion and source info
7033 -- functions) do not use the secondary stack even though the return
7034 -- type may be unconstrained.
7036 -- b) Subprograms that are ignored ghost entities do not return anything
7038 -- c) Calls to a build-in-place function, since such functions may
7039 -- allocate their result directly in a target object, and cases where
7040 -- the result does get allocated in the secondary stack are checked for
7041 -- within the specialized Exp_Ch6 procedures for expanding those
7042 -- build-in-place calls.
7044 -- d) Calls to inlinable expression functions do not use the secondary
7045 -- stack (since the call will be replaced by its returned object).
7047 -- e) If the subprogram is marked Inline, then even if it returns
7048 -- an unconstrained type the call does not require use of the secondary
7049 -- stack. However, inlining will only take place if the body to inline
7050 -- is already present. It may not be available if e.g. the subprogram is
7051 -- declared in a child instance.
7053 -- f) If the subprogram is a static expression function and the call is
7054 -- a static call (the actuals are all static expressions), then we never
7055 -- want to create a transient scope (this could occur in the case of a
7056 -- static string-returning call).
7058 -- g) If the call is the expression of a simple return statement that
7059 -- returns on the same stack, since it will be handled as a tail call
7060 -- by Expand_Simple_Function_Return.
7063 and then Ekind
(Nam
) in E_Function | E_Subprogram_Type
7064 and then Requires_Transient_Scope
(Etype
(Nam
))
7065 and then not Is_Intrinsic_Subprogram
(Nam
)
7066 and then not Is_Ignored_Ghost_Entity
(Nam
)
7067 and then not Is_Build_In_Place_Function
(Nam
)
7068 and then not Is_Inlinable_Expression_Function
(Nam
)
7069 and then not (Is_Inlined
(Nam
)
7070 and then Has_Pragma_Inline
(Nam
)
7071 and then Nkind
(Unit_Declaration_Node
(Nam
)) =
7072 N_Subprogram_Declaration
7074 Present
(Body_To_Inline
(Unit_Declaration_Node
(Nam
))))
7075 and then not Is_Static_Function_Call
(N
)
7076 and then not (Nkind
(Parent
(N
)) = N_Simple_Return_Statement
7078 Needs_Secondary_Stack
7081 (Return_Statement_Entity
(Parent
(N
))))) =
7082 Needs_Secondary_Stack
(Etype
(Nam
)))
7084 Establish_Transient_Scope
(N
, Needs_Secondary_Stack
(Etype
(Nam
)));
7086 -- If the call appears within the bounds of a loop, it will be
7087 -- rewritten and reanalyzed, nothing left to do here.
7089 if Nkind
(N
) /= N_Function_Call
then
7094 -- A protected function cannot be called within the definition of the
7095 -- enclosing protected type, unless it is part of a pre/postcondition
7096 -- on another protected operation. This may appear in the entry wrapper
7097 -- created for an entry with preconditions.
7099 if Is_Protected_Type
(Scope
(Nam
))
7100 and then In_Open_Scopes
(Scope
(Nam
))
7101 and then not Has_Completion
(Scope
(Nam
))
7102 and then not In_Spec_Expression
7103 and then not Is_Entry_Wrapper
(Current_Scope
)
7106 ("& cannot be called before end of protected definition", N
, Nam
);
7109 -- Propagate interpretation to actuals, and add default expressions
7112 if Present
(First_Formal
(Nam
)) then
7113 Resolve_Actuals
(N
, Nam
);
7115 -- Overloaded literals are rewritten as function calls, for purpose of
7116 -- resolution. After resolution, we can replace the call with the
7119 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
7120 Copy_Node
(Subp
, N
);
7121 Resolve_Entity_Name
(N
, Typ
);
7123 -- Avoid validation, since it is a static function call
7125 Generate_Reference
(Nam
, Subp
);
7129 -- If the subprogram is not global, then kill all saved values and
7130 -- checks. This is a bit conservative, since in many cases we could do
7131 -- better, but it is not worth the effort. Similarly, we kill constant
7132 -- values. However we do not need to do this for internal entities
7133 -- (unless they are inherited user-defined subprograms), since they
7134 -- are not in the business of molesting local values.
7136 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
7137 -- kill all checks and values for calls to global subprograms. This
7138 -- takes care of the case where an access to a local subprogram is
7139 -- taken, and could be passed directly or indirectly and then called
7140 -- from almost any context.
7142 -- Note: we do not do this step till after resolving the actuals. That
7143 -- way we still take advantage of the current value information while
7144 -- scanning the actuals.
7146 -- We suppress killing values if we are processing the nodes associated
7147 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
7148 -- type kills all the values as part of analyzing the code that
7149 -- initializes the dispatch tables.
7151 if Inside_Freezing_Actions
= 0
7152 and then (not Is_Library_Level_Entity
(Nam
)
7153 or else Suppress_Value_Tracking_On_Call
7154 (Nearest_Dynamic_Scope
(Current_Scope
)))
7155 and then (Comes_From_Source
(Nam
)
7156 or else (Present
(Alias
(Nam
))
7157 and then Comes_From_Source
(Alias
(Nam
))))
7159 Kill_Current_Values
;
7162 -- If we are warning about unread OUT parameters, this is the place to
7163 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
7164 -- after the above call to Kill_Current_Values (since that call clears
7165 -- the Last_Assignment field of all local variables).
7167 if (Warn_On_Modified_Unread
or Warn_On_All_Unread_Out_Parameters
)
7168 and then Comes_From_Source
(N
)
7169 and then In_Extended_Main_Source_Unit
(N
)
7176 F
:= First_Formal
(Nam
);
7177 A
:= First_Actual
(N
);
7178 while Present
(F
) and then Present
(A
) loop
7179 if Ekind
(F
) in E_Out_Parameter | E_In_Out_Parameter
7180 and then Warn_On_Modified_As_Out_Parameter
(F
)
7181 and then Is_Entity_Name
(A
)
7182 and then Present
(Entity
(A
))
7183 and then Comes_From_Source
(N
)
7184 and then Safe_To_Capture_Value
(N
, Entity
(A
))
7186 Set_Last_Assignment
(Entity
(A
), A
);
7195 -- If the subprogram is a primitive operation, check whether or not
7196 -- it is a correct dispatching call.
7198 if Is_Overloadable
(Nam
) and then Is_Dispatching_Operation
(Nam
) then
7199 Check_Dispatching_Call
(N
);
7201 -- If the subprogram is an abstract operation, then flag an error
7203 elsif Is_Overloadable
(Nam
) and then Is_Abstract_Subprogram
(Nam
) then
7204 Nondispatching_Call_To_Abstract_Operation
(N
, Nam
);
7207 -- If this is a dispatching call, generate the appropriate reference,
7208 -- for better source navigation in GNAT Studio.
7210 if Is_Overloadable
(Nam
) and then Present
(Controlling_Argument
(N
)) then
7211 Generate_Reference
(Nam
, Subp
, 'R');
7213 -- Normal case, not a dispatching call: generate a call reference
7216 Generate_Reference
(Nam
, Subp
, 's');
7219 if Is_Intrinsic_Subprogram
(Nam
) then
7220 Check_Intrinsic_Call
(N
);
7223 -- Check for violation of restriction No_Specific_Termination_Handlers
7224 -- and warn on a potentially blocking call to Abort_Task.
7226 if Restriction_Check_Required
(No_Specific_Termination_Handlers
)
7227 and then (Is_RTE
(Nam
, RE_Set_Specific_Handler
)
7229 Is_RTE
(Nam
, RE_Specific_Handler
))
7231 Check_Restriction
(No_Specific_Termination_Handlers
, N
);
7233 elsif Is_RTE
(Nam
, RE_Abort_Task
) then
7234 Check_Potentially_Blocking_Operation
(N
);
7237 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
7238 -- timing event violates restriction No_Relative_Delay (AI-0211). We
7239 -- need to check the second argument to determine whether it is an
7240 -- absolute or relative timing event.
7242 if Restriction_Check_Required
(No_Relative_Delay
)
7243 and then Is_RTE
(Nam
, RE_Set_Handler
)
7244 and then Is_RTE
(Etype
(Next_Actual
(First_Actual
(N
))), RE_Time_Span
)
7246 Check_Restriction
(No_Relative_Delay
, N
);
7249 -- Issue an error for a call to an eliminated subprogram. This routine
7250 -- will not perform the check if the call appears within a default
7253 Check_For_Eliminated_Subprogram
(Subp
, Nam
);
7255 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
7256 -- class-wide and the call dispatches on result in a context that does
7257 -- not provide a tag, the call raises Program_Error.
7259 if Nkind
(N
) = N_Function_Call
7260 and then In_Instance
7261 and then Is_Generic_Actual_Type
(Typ
)
7262 and then Is_Class_Wide_Type
(Typ
)
7263 and then Has_Controlling_Result
(Nam
)
7264 and then Nkind
(Parent
(N
)) = N_Object_Declaration
7266 -- Verify that none of the formals are controlling
7269 Call_OK
: Boolean := False;
7273 F
:= First_Formal
(Nam
);
7274 while Present
(F
) loop
7275 if Is_Controlling_Formal
(F
) then
7284 Error_Msg_Warn
:= SPARK_Mode
/= On
;
7285 Error_Msg_N
("!cannot determine tag of result<<", N
);
7286 Error_Msg_N
("\Program_Error [<<!", N
);
7288 Make_Raise_Program_Error
(Sloc
(N
),
7289 Reason
=> PE_Explicit_Raise
));
7294 -- Check for calling a function with OUT or IN OUT parameter when the
7295 -- calling context (us right now) is not Ada 2012, so does not allow
7296 -- OUT or IN OUT parameters in function calls. Functions declared in
7297 -- a predefined unit are OK, as they may be called indirectly from a
7298 -- user-declared instantiation.
7300 if Ada_Version
< Ada_2012
7301 and then Ekind
(Nam
) = E_Function
7302 and then Has_Out_Or_In_Out_Parameter
(Nam
)
7303 and then not In_Predefined_Unit
(Nam
)
7305 Error_Msg_NE
("& has at least one OUT or `IN OUT` parameter", N
, Nam
);
7306 Error_Msg_N
("\call to this function only allowed in Ada 2012", N
);
7309 -- Check the dimensions of the actuals in the call. For function calls,
7310 -- propagate the dimensions from the returned type to N.
7312 Analyze_Dimension_Call
(N
, Nam
);
7314 -- Check unreachable code after calls to procedures with No_Return
7316 if Ekind
(Nam
) = E_Procedure
and then No_Return
(Nam
) then
7317 Check_Unreachable_Code
(N
);
7320 -- All done, evaluate call and deal with elaboration issues
7324 if Legacy_Elaboration_Checks
then
7325 Check_Elab_Call
(N
);
7328 -- Annotate the tree by creating a call marker in case the original call
7329 -- is transformed by expansion. The call marker is automatically saved
7330 -- for later examination by the ABE Processing phase.
7332 Build_Call_Marker
(N
);
7334 Mark_Use_Clauses
(Subp
);
7336 Warn_On_Overlapping_Actuals
(Nam
, N
);
7338 -- Ada 2022 (AI12-0075): If the call is a static call to a static
7339 -- expression function, then we want to "inline" the call, replacing
7340 -- it with the folded static result. This is not done if the checking
7341 -- for a potentially static expression is enabled or if an error has
7342 -- been posted on the call (which may be due to the check for recursive
7343 -- calls, in which case we don't want to fall into infinite recursion
7344 -- when doing the inlining).
7346 if not Checking_Potentially_Static_Expression
7347 and then Is_Static_Function_Call
(N
)
7348 and then not Is_Intrinsic_Subprogram
(Ultimate_Alias
(Nam
))
7349 and then not Error_Posted
(Ultimate_Alias
(Nam
))
7351 Inline_Static_Function_Call
(N
, Ultimate_Alias
(Nam
));
7353 -- In GNATprove mode, expansion is disabled, but we want to inline some
7354 -- subprograms to facilitate formal verification. Indirect calls through
7355 -- a subprogram type or within a generic cannot be inlined. Inlining is
7356 -- performed only for calls subject to SPARK_Mode => On.
7358 elsif GNATprove_Mode
7359 and then SPARK_Mode
= On
7360 and then Is_Overloadable
(Nam
)
7361 and then not Inside_A_Generic
7363 Nam_UA
:= Ultimate_Alias
(Nam
);
7364 Nam_Decl
:= Unit_Declaration_Node
(Nam_UA
);
7366 if Nkind
(Nam_Decl
) = N_Subprogram_Declaration
then
7367 Body_Id
:= Corresponding_Body
(Nam_Decl
);
7369 -- Nothing to do if the subprogram is not inlined (because it is
7370 -- recursive, directly or indirectly), or is not eligible for
7371 -- inlining GNATprove mode (because of properties of the
7372 -- subprogram itself), or inlining has been disabled with switch
7375 if not Is_Inlined
(Nam_UA
)
7376 or else not Can_Be_Inlined_In_GNATprove_Mode
(Nam_UA
, Body_Id
)
7377 or else Debug_Flag_M
7381 -- Calls cannot be inlined inside assertions, as GNATprove treats
7382 -- assertions as logic expressions. Only issue a message when the
7383 -- body has been seen, otherwise this leads to spurious messages
7384 -- on expression functions.
7386 elsif In_Assertion_Expr
/= 0 then
7388 ("cannot inline & (in assertion expression)?", N
, Nam_UA
,
7389 Suppress_Info
=> No
(Body_Id
));
7391 -- Calls cannot be inlined inside default expressions
7393 elsif In_Default_Expr
then
7395 ("cannot inline & (in default expression)?", N
, Nam_UA
);
7397 -- Calls cannot be inlined inside potentially unevaluated
7398 -- expressions, as this would create complex actions inside
7399 -- expressions, that are not handled by GNATprove.
7401 elsif Is_Potentially_Unevaluated
(N
) then
7403 ("cannot inline & (in potentially unevaluated context)?",
7406 -- Calls are not inlined inside the loop_parameter_specification
7407 -- or iterator_specification of the quantified expression, as they
7408 -- are only preanalyzed. Calls in the predicate part are handled
7409 -- by the previous test on potentially unevaluated expressions.
7411 elsif In_Quantified_Expression
(N
) then
7413 ("cannot inline & (in quantified expression)?", N
, Nam_UA
);
7415 -- Inlining should not be performed during preanalysis
7417 elsif Full_Analysis
then
7419 -- Do not inline calls inside expression functions or functions
7420 -- generated by the front end for subtype predicates, as this
7421 -- would prevent interpreting them as logical formulas in
7422 -- GNATprove. Only issue a message when the body has been seen,
7423 -- otherwise this leads to spurious messages on callees that
7424 -- are themselves expression functions.
7426 if Present
(Current_Subprogram
)
7428 (Is_Expression_Function_Or_Completion
(Current_Subprogram
)
7429 or else Is_Predicate_Function
(Current_Subprogram
)
7430 or else Is_Invariant_Procedure
(Current_Subprogram
)
7431 or else Is_DIC_Procedure
(Current_Subprogram
))
7434 Issue_Msg
: constant Boolean :=
7436 and then Present
(Body_To_Inline
(Nam_Decl
));
7438 if Is_Predicate_Function
(Current_Subprogram
) then
7440 ("cannot inline & (inside predicate)?",
7441 N
, Nam_UA
, Suppress_Info
=> not Issue_Msg
);
7443 elsif Is_Invariant_Procedure
(Current_Subprogram
) then
7445 ("cannot inline & (inside invariant)?",
7446 N
, Nam_UA
, Suppress_Info
=> not Issue_Msg
);
7448 elsif Is_DIC_Procedure
(Current_Subprogram
) then
7450 ("cannot inline & (inside Default_Initial_Condition)?",
7451 N
, Nam_UA
, Suppress_Info
=> not Issue_Msg
);
7455 ("cannot inline & (inside expression function)?",
7456 N
, Nam_UA
, Suppress_Info
=> not Issue_Msg
);
7460 -- Cannot inline a call inside the definition of a record type,
7461 -- typically inside the constraints of the type. Calls in
7462 -- default expressions are also not inlined, but this is
7463 -- filtered out above when testing In_Default_Expr.
7465 elsif Is_Record_Type
(Current_Scope
) then
7467 ("cannot inline & (inside record type)?", N
, Nam_UA
);
7469 -- With the one-pass inlining technique, a call cannot be
7470 -- inlined if the corresponding body has not been seen yet.
7472 elsif No
(Body_Id
) then
7474 ("cannot inline & (body not seen yet)?", N
, Nam_UA
);
7476 -- Nothing to do if there is no body to inline, indicating that
7477 -- the subprogram is not suitable for inlining in GNATprove
7480 elsif No
(Body_To_Inline
(Nam_Decl
)) then
7483 -- Calls cannot be inlined inside the conditions of while
7484 -- loops, as this would create complex actions inside
7485 -- the condition, that are not handled by GNATprove.
7487 elsif In_Statement_Condition_With_Actions
(N
) then
7489 ("cannot inline & (in while loop condition)?", N
, Nam_UA
);
7491 -- Do not inline calls which would possibly lead to missing a
7492 -- type conversion check on an input parameter or a memory leak
7493 -- on an output parameter.
7495 elsif not Call_Can_Be_Inlined_In_GNATprove_Mode
(N
, Nam
) then
7497 ("cannot inline & (possible check on parameters)?",
7500 -- Otherwise, inline the call, issuing an info message when
7504 if Debug_Flag_Underscore_F
then
7506 ("info: analyzing call to & in context?", N
, Nam_UA
);
7509 Expand_Inlined_Call
(N
, Nam_UA
, Nam
);
7516 -----------------------------
7517 -- Resolve_Case_Expression --
7518 -----------------------------
7520 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7523 Alt_Typ
: Entity_Id
;
7527 Alt
:= First
(Alternatives
(N
));
7528 while Present
(Alt
) loop
7529 Alt_Expr
:= Expression
(Alt
);
7531 if Error_Posted
(Alt_Expr
) then
7535 Resolve_Dependent_Expression
(N
, Alt_Expr
, Typ
);
7537 Check_Unset_Reference
(Alt_Expr
);
7538 Alt_Typ
:= Etype
(Alt_Expr
);
7540 -- When the expression is of a scalar subtype different from the
7541 -- result subtype, then insert a conversion to ensure the generation
7542 -- of a constraint check.
7544 if Is_Scalar_Type
(Alt_Typ
) and then Alt_Typ
/= Typ
then
7545 Rewrite
(Alt_Expr
, Convert_To
(Typ
, Alt_Expr
));
7546 Analyze_And_Resolve
(Alt_Expr
, Typ
);
7548 elsif Is_Array_Type
(Typ
) then
7549 Apply_Length_Check
(Alt_Expr
, Typ
);
7555 -- Apply RM 4.5.7 (17/3): whether the expression is statically or
7556 -- dynamically tagged must be known statically.
7558 if Is_Tagged_Type
(Typ
) and then not Is_Class_Wide_Type
(Typ
) then
7559 Alt
:= First
(Alternatives
(N
));
7560 Is_Dyn
:= Is_Dynamically_Tagged
(Expression
(Alt
));
7562 while Present
(Alt
) loop
7563 if Is_Dynamically_Tagged
(Expression
(Alt
)) /= Is_Dyn
then
7565 ("all or none of the dependent expressions can be "
7566 & "dynamically tagged", N
);
7574 Eval_Case_Expression
(N
);
7575 Analyze_Dimension
(N
);
7576 end Resolve_Case_Expression
;
7578 -------------------------------
7579 -- Resolve_Character_Literal --
7580 -------------------------------
7582 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
7583 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7587 -- Verify that the character does belong to the type of the context
7589 Set_Etype
(N
, B_Typ
);
7590 Eval_Character_Literal
(N
);
7592 -- Wide_Wide_Character literals must always be defined, since the set
7593 -- of wide wide character literals is complete, i.e. if a character
7594 -- literal is accepted by the parser, then it is OK for wide wide
7595 -- character (out of range character literals are rejected).
7597 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
7600 -- Always accept character literal for type Any_Character, which
7601 -- occurs in error situations and in comparisons of literals, both
7602 -- of which should accept all literals.
7604 elsif B_Typ
= Any_Character
then
7607 -- For Standard.Character or a type derived from it, check that the
7608 -- literal is in range.
7610 elsif Root_Type
(B_Typ
) = Standard_Character
then
7611 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
7615 -- For Standard.Wide_Character or a type derived from it, check that the
7616 -- literal is in range.
7618 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
7619 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
7623 -- If the entity is already set, this has already been resolved in a
7624 -- generic context, or comes from expansion. Nothing else to do.
7626 elsif Present
(Entity
(N
)) then
7629 -- Otherwise we have a user defined character type, and we can use the
7630 -- standard visibility mechanisms to locate the referenced entity.
7633 C
:= Current_Entity
(N
);
7634 while Present
(C
) loop
7635 if Etype
(C
) = B_Typ
then
7636 Set_Entity_With_Checks
(N
, C
);
7637 Generate_Reference
(C
, N
);
7645 -- If we fall through, then the literal does not match any of the
7646 -- entries of the enumeration type. This isn't just a constraint error
7647 -- situation, it is an illegality (see RM 4.2).
7650 ("character not defined for }", N
, First_Subtype
(B_Typ
));
7651 end Resolve_Character_Literal
;
7653 ---------------------------
7654 -- Resolve_Comparison_Op --
7655 ---------------------------
7657 -- The operands must have compatible types and the boolean context does not
7658 -- participate in the resolution. The first pass verifies that the operands
7659 -- are not ambiguous and sets their type correctly, or to Any_Type in case
7660 -- of ambiguity. If both operands are strings or aggregates, then they are
7661 -- ambiguous even if they carry a single (universal) type.
7663 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7664 L
: constant Node_Id
:= Left_Opnd
(N
);
7665 R
: constant Node_Id
:= Right_Opnd
(N
);
7667 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
7670 if T
= Any_Fixed
then
7671 T
:= Unique_Fixed_Point_Type
(L
);
7674 Set_Etype
(N
, Base_Type
(Typ
));
7675 Generate_Reference
(T
, N
, ' ');
7677 if T
= Any_Type
then
7678 -- Deal with explicit ambiguity of operands
7680 if Is_Overloaded
(L
) or else Is_Overloaded
(R
) then
7681 Ambiguous_Operands
(N
);
7687 -- Deal with other error cases
7689 if T
= Any_String
or else
7690 T
= Any_Composite
or else
7693 if T
= Any_Character
then
7694 Ambiguous_Character
(L
);
7696 Error_Msg_N
("ambiguous operands for comparison", N
);
7699 Set_Etype
(N
, Any_Type
);
7703 -- Resolve the operands if types OK
7707 Set_Compare_Type
(N
, T
);
7708 Check_Unset_Reference
(L
);
7709 Check_Unset_Reference
(R
);
7710 Generate_Operator_Reference
(N
, T
);
7711 Check_Low_Bound_Tested
(N
);
7713 -- Check comparison on unordered enumeration
7715 if Bad_Unordered_Enumeration_Reference
(N
, Etype
(L
)) then
7716 Error_Msg_Sloc
:= Sloc
(Etype
(L
));
7718 ("comparison on unordered enumeration type& declared#?.u?",
7722 Analyze_Dimension
(N
);
7724 Eval_Relational_Op
(N
);
7725 end Resolve_Comparison_Op
;
7727 --------------------------------
7728 -- Resolve_Declare_Expression --
7729 --------------------------------
7731 procedure Resolve_Declare_Expression
7735 Expr
: constant Node_Id
:= Expression
(N
);
7738 Local
: Entity_Id
:= Empty
;
7740 function Replace_Local
(N
: Node_Id
) return Traverse_Result
;
7741 -- Use a tree traversal to replace each occurrence of the name of
7742 -- a local object declared in the construct, with the corresponding
7743 -- entity. This replaces the usual way to perform name capture by
7744 -- visibility, because it is not possible to place on the scope
7745 -- stack the fake scope created for the analysis of the local
7746 -- declarations; such a scope conflicts with the transient scopes
7747 -- that may be generated if the expression includes function calls
7748 -- requiring finalization.
7754 function Replace_Local
(N
: Node_Id
) return Traverse_Result
is
7756 -- The identifier may be the prefix of a selected component,
7757 -- but not a selector name, because the local entities do not
7758 -- have a scope that can be named: a selected component whose
7759 -- selector is a homonym of a local entity must denote some
7762 if Nkind
(N
) = N_Identifier
7763 and then Chars
(N
) = Chars
(Local
)
7764 and then No
(Entity
(N
))
7766 (Nkind
(Parent
(N
)) /= N_Selected_Component
7767 or else N
= Prefix
(Parent
(N
)))
7769 Set_Entity
(N
, Local
);
7770 Set_Etype
(N
, Etype
(Local
));
7776 procedure Replace_Local_Ref
is new Traverse_Proc
(Replace_Local
);
7778 -- Start of processing for Resolve_Declare_Expression
7781 Decl
:= First
(Actions
(N
));
7783 while Present
(Decl
) loop
7785 N_Object_Declaration | N_Object_Renaming_Declaration
7786 and then Comes_From_Source
(Defining_Identifier
(Decl
))
7788 Local
:= Defining_Identifier
(Decl
);
7789 Replace_Local_Ref
(Expr
);
7791 -- Traverse the expression to replace references to local
7792 -- variables that occur within declarations of the
7793 -- declare_expression.
7796 D
: Node_Id
:= Next
(Decl
);
7798 while Present
(D
) loop
7799 Replace_Local_Ref
(D
);
7808 -- The end of the declarative list is a freeze point for the
7809 -- local declarations.
7811 if Present
(Local
) then
7812 Decl
:= Parent
(Local
);
7813 Freeze_All
(First_Entity
(Scope
(Local
)), Decl
);
7816 Resolve
(Expr
, Typ
);
7817 Check_Unset_Reference
(Expr
);
7818 end Resolve_Declare_Expression
;
7820 -----------------------------------
7821 -- Resolve_Dependent_Expression --
7822 -----------------------------------
7824 procedure Resolve_Dependent_Expression
7830 -- RM 4.5.7(8/3) says that the expected type of dependent expressions is
7831 -- that of the conditional expression but RM 4.5.7(10/3) forces the type
7832 -- of the conditional expression without changing the expected type (the
7833 -- expected type of the operand of a type conversion is any type), so we
7834 -- may have a gap between these two types that is bridged by the dynamic
7835 -- semantics specified by RM 4.5.7(20/3) with the associated legality
7836 -- rule RM 4.5.7(16/3) that will be automatically enforced.
7838 if Nkind
(Parent
(N
)) = N_Type_Conversion
7839 and then Nkind
(Expr
) /= N_Raise_Expression
7841 Convert_To_And_Rewrite
(Typ
, Expr
);
7842 Analyze_And_Resolve
(Expr
);
7844 Resolve
(Expr
, Typ
);
7846 end Resolve_Dependent_Expression
;
7848 -----------------------------------------
7849 -- Resolve_Discrete_Subtype_Indication --
7850 -----------------------------------------
7852 procedure Resolve_Discrete_Subtype_Indication
7860 Analyze
(Subtype_Mark
(N
));
7861 S
:= Entity
(Subtype_Mark
(N
));
7863 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
7864 Error_Msg_N
("expect range constraint for discrete type", N
);
7865 Set_Etype
(N
, Any_Type
);
7868 R
:= Range_Expression
(Constraint
(N
));
7876 if Base_Type
(S
) /= Base_Type
(Typ
) then
7878 ("expect subtype of }", N
, First_Subtype
(Typ
));
7880 -- Rewrite the constraint as a range of Typ
7881 -- to allow compilation to proceed further.
7884 Rewrite
(Low_Bound
(R
),
7885 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
7886 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
7887 Attribute_Name
=> Name_First
));
7888 Rewrite
(High_Bound
(R
),
7889 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
7890 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
7891 Attribute_Name
=> Name_First
));
7895 Set_Etype
(N
, Etype
(R
));
7897 -- Additionally, we must check that the bounds are compatible
7898 -- with the given subtype, which might be different from the
7899 -- type of the context.
7901 Apply_Range_Check
(R
, S
);
7903 -- ??? If the above check statically detects a Constraint_Error
7904 -- it replaces the offending bound(s) of the range R with a
7905 -- Constraint_Error node. When the itype which uses these bounds
7906 -- is frozen the resulting call to Duplicate_Subexpr generates
7907 -- a new temporary for the bounds.
7909 -- Unfortunately there are other itypes that are also made depend
7910 -- on these bounds, so when Duplicate_Subexpr is called they get
7911 -- a forward reference to the newly created temporaries and Gigi
7912 -- aborts on such forward references. This is probably sign of a
7913 -- more fundamental problem somewhere else in either the order of
7914 -- itype freezing or the way certain itypes are constructed.
7916 -- To get around this problem we call Remove_Side_Effects right
7917 -- away if either bounds of R are a Constraint_Error.
7920 L
: constant Node_Id
:= Low_Bound
(R
);
7921 H
: constant Node_Id
:= High_Bound
(R
);
7924 if Nkind
(L
) = N_Raise_Constraint_Error
then
7925 Remove_Side_Effects
(L
);
7928 if Nkind
(H
) = N_Raise_Constraint_Error
then
7929 Remove_Side_Effects
(H
);
7933 Check_Unset_Reference
(Low_Bound
(R
));
7934 Check_Unset_Reference
(High_Bound
(R
));
7937 end Resolve_Discrete_Subtype_Indication
;
7939 -------------------------
7940 -- Resolve_Entity_Name --
7941 -------------------------
7943 -- Used to resolve identifiers and expanded names
7945 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
7946 function Is_Assignment_Or_Object_Expression
7948 Expr
: Node_Id
) return Boolean;
7949 -- Determine whether node Context denotes an assignment statement or an
7950 -- object declaration whose expression is node Expr.
7952 function Is_Attribute_Expression
(Expr
: Node_Id
) return Boolean;
7953 -- Determine whether Expr is part of an N_Attribute_Reference
7956 ----------------------------------------
7957 -- Is_Assignment_Or_Object_Expression --
7958 ----------------------------------------
7960 function Is_Assignment_Or_Object_Expression
7962 Expr
: Node_Id
) return Boolean
7965 if Nkind
(Context
) in N_Assignment_Statement | N_Object_Declaration
7966 and then Expression
(Context
) = Expr
7970 -- Check whether a construct that yields a name is the expression of
7971 -- an assignment statement or an object declaration.
7973 elsif (Nkind
(Context
) in N_Attribute_Reference
7974 | N_Explicit_Dereference
7975 | N_Indexed_Component
7976 | N_Selected_Component
7978 and then Prefix
(Context
) = Expr
)
7980 (Nkind
(Context
) in N_Type_Conversion
7981 | N_Unchecked_Type_Conversion
7982 and then Expression
(Context
) = Expr
)
7985 Is_Assignment_Or_Object_Expression
7986 (Context
=> Parent
(Context
),
7989 -- Otherwise the context is not an assignment statement or an object
7995 end Is_Assignment_Or_Object_Expression
;
7997 -----------------------------
7998 -- Is_Attribute_Expression --
7999 -----------------------------
8001 function Is_Attribute_Expression
(Expr
: Node_Id
) return Boolean is
8002 N
: Node_Id
:= Expr
;
8004 while Present
(N
) loop
8005 if Nkind
(N
) = N_Attribute_Reference
then
8008 -- Prevent the search from going too far
8010 elsif Is_Body_Or_Package_Declaration
(N
) then
8018 end Is_Attribute_Expression
;
8022 E
: constant Entity_Id
:= Entity
(N
);
8025 -- Start of processing for Resolve_Entity_Name
8028 -- If garbage from errors, set to Any_Type and return
8030 if No
(E
) and then Total_Errors_Detected
/= 0 then
8031 Set_Etype
(N
, Any_Type
);
8035 -- Replace named numbers by corresponding literals. Note that this is
8036 -- the one case where Resolve_Entity_Name must reset the Etype, since
8037 -- it is currently marked as universal.
8039 if Ekind
(E
) = E_Named_Integer
then
8041 Eval_Named_Integer
(N
);
8043 elsif Ekind
(E
) = E_Named_Real
then
8045 Eval_Named_Real
(N
);
8047 -- For enumeration literals, we need to make sure that a proper style
8048 -- check is done, since such literals are overloaded, and thus we did
8049 -- not do a style check during the first phase of analysis.
8051 elsif Ekind
(E
) = E_Enumeration_Literal
then
8052 Set_Entity_With_Checks
(N
, E
);
8053 Eval_Entity_Name
(N
);
8055 -- Case of (sub)type name appearing in a context where an expression
8056 -- is expected. This is legal if occurrence is a current instance.
8057 -- See RM 8.6 (17/3). It is also legal if the expression is
8058 -- part of a choice pattern for a case stmt/expr having a
8059 -- non-discrete selecting expression.
8061 elsif Is_Type
(E
) then
8062 if Is_Current_Instance
(N
) or else Is_Case_Choice_Pattern
(N
) then
8065 -- Any other use is an error
8069 ("invalid use of subtype mark in expression or call", N
);
8072 -- Check discriminant use if entity is discriminant in current scope,
8073 -- i.e. discriminant of record or concurrent type currently being
8074 -- analyzed. Uses in corresponding body are unrestricted.
8076 elsif Ekind
(E
) = E_Discriminant
8077 and then Scope
(E
) = Current_Scope
8078 and then not Has_Completion
(Current_Scope
)
8080 Check_Discriminant_Use
(N
);
8082 -- A parameterless generic function cannot appear in a context that
8083 -- requires resolution.
8085 elsif Ekind
(E
) = E_Generic_Function
then
8086 Error_Msg_N
("illegal use of generic function", N
);
8088 -- In Ada 83 an OUT parameter cannot be read, but attributes of
8089 -- array types (i.e. bounds and length) are legal.
8091 elsif Ekind
(E
) = E_Out_Parameter
8092 and then (Is_Scalar_Type
(Etype
(E
))
8093 or else not Is_Attribute_Expression
(Parent
(N
)))
8095 and then (Nkind
(Parent
(N
)) in N_Op
8096 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
8097 or else Is_Assignment_Or_Object_Expression
8098 (Context
=> Parent
(N
),
8101 if Ada_Version
= Ada_83
then
8102 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
8105 -- In all other cases, just do the possible static evaluation
8108 -- A deferred constant that appears in an expression must have a
8109 -- completion, unless it has been removed by in-place expansion of
8110 -- an aggregate. A constant that is a renaming does not need
8113 if Ekind
(E
) = E_Constant
8114 and then Comes_From_Source
(E
)
8115 and then No
(Constant_Value
(E
))
8116 and then Is_Frozen
(Etype
(E
))
8117 and then not In_Spec_Expression
8118 and then not Is_Imported
(E
)
8119 and then Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
8121 if No_Initialization
(Parent
(E
))
8122 or else (Present
(Full_View
(E
))
8123 and then No_Initialization
(Parent
(Full_View
(E
))))
8128 ("deferred constant is frozen before completion", N
);
8132 Eval_Entity_Name
(N
);
8137 -- When the entity appears in a parameter association, retrieve the
8138 -- related subprogram call.
8140 if Nkind
(Par
) = N_Parameter_Association
then
8141 Par
:= Parent
(Par
);
8144 if Comes_From_Source
(N
) then
8146 -- The following checks are only relevant when SPARK_Mode is On as
8147 -- they are not standard Ada legality rules.
8149 if SPARK_Mode
= On
then
8151 -- Check for possible elaboration issues with respect to reads of
8152 -- variables. The act of renaming the variable is not considered a
8153 -- read as it simply establishes an alias.
8155 if Legacy_Elaboration_Checks
8156 and then Ekind
(E
) = E_Variable
8157 and then Dynamic_Elaboration_Checks
8158 and then Nkind
(Par
) /= N_Object_Renaming_Declaration
8160 Check_Elab_Call
(N
);
8164 -- The variable may eventually become a constituent of a single
8165 -- protected/task type. Record the reference now and verify its
8166 -- legality when analyzing the contract of the variable
8169 if Ekind
(E
) = E_Variable
then
8170 Record_Possible_Part_Of_Reference
(E
, N
);
8173 -- A Ghost entity must appear in a specific context
8175 if Is_Ghost_Entity
(E
) then
8176 Check_Ghost_Context
(E
, N
);
8179 -- We may be resolving an entity within expanded code, so a reference
8180 -- to an entity should be ignored when calculating effective use
8181 -- clauses to avoid inappropriate marking.
8183 Mark_Use_Clauses
(E
);
8185 end Resolve_Entity_Name
;
8191 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
8192 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
8200 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
8201 -- If the bounds of the entry family being called depend on task
8202 -- discriminants, build a new index subtype where a discriminant is
8203 -- replaced with the value of the discriminant of the target task.
8204 -- The target task is the prefix of the entry name in the call.
8206 -----------------------
8207 -- Actual_Index_Type --
8208 -----------------------
8210 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
8211 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
8212 Tsk
: constant Entity_Id
:= Scope
(E
);
8213 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
8214 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
8217 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
8218 -- If the bound is given by a discriminant, replace with a reference
8219 -- to the discriminant of the same name in the target task. If the
8220 -- entry name is the target of a requeue statement and the entry is
8221 -- in the current protected object, the bound to be used is the
8222 -- discriminal of the object (see Apply_Range_Check for details of
8223 -- the transformation).
8225 -----------------------------
8226 -- Actual_Discriminant_Ref --
8227 -----------------------------
8229 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
8230 Typ
: constant Entity_Id
:= Etype
(Bound
);
8234 Remove_Side_Effects
(Bound
);
8236 if not Is_Entity_Name
(Bound
)
8237 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
8241 elsif Is_Protected_Type
(Tsk
)
8242 and then In_Open_Scopes
(Tsk
)
8243 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
8245 -- Note: here Bound denotes a discriminant of the corresponding
8246 -- record type tskV, whose discriminal is a formal of the
8247 -- init-proc tskVIP. What we want is the body discriminal,
8248 -- which is associated to the discriminant of the original
8249 -- concurrent type tsk.
8251 return New_Occurrence_Of
8252 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
8256 Make_Selected_Component
(Loc
,
8257 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
8258 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
8263 end Actual_Discriminant_Ref
;
8265 -- Start of processing for Actual_Index_Type
8268 if not Has_Discriminants
(Tsk
)
8269 or else (not Is_Entity_Name
(Lo
) and then not Is_Entity_Name
(Hi
))
8271 return Entry_Index_Type
(E
);
8274 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
8275 Set_Etype
(New_T
, Base_Type
(Typ
));
8276 Set_Size_Info
(New_T
, Typ
);
8277 Set_RM_Size
(New_T
, RM_Size
(Typ
));
8278 Set_Scalar_Range
(New_T
,
8279 Make_Range
(Sloc
(Entry_Name
),
8280 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
8281 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
8285 end Actual_Index_Type
;
8287 -- Start of processing for Resolve_Entry
8290 -- Find name of entry being called, and resolve prefix of name with its
8291 -- own type. The prefix can be overloaded, and the name and signature of
8292 -- the entry must be taken into account.
8294 if Nkind
(Entry_Name
) = N_Indexed_Component
then
8296 -- Case of dealing with entry family within the current tasks
8298 E_Name
:= Prefix
(Entry_Name
);
8301 E_Name
:= Entry_Name
;
8304 if Is_Entity_Name
(E_Name
) then
8306 -- Entry call to an entry (or entry family) in the current task. This
8307 -- is legal even though the task will deadlock. Rewrite as call to
8310 -- This can also be a call to an entry in an enclosing task. If this
8311 -- is a single task, we have to retrieve its name, because the scope
8312 -- of the entry is the task type, not the object. If the enclosing
8313 -- task is a task type, the identity of the task is given by its own
8316 -- Finally this can be a requeue on an entry of the same task or
8317 -- protected object.
8319 S
:= Scope
(Entity
(E_Name
));
8321 for J
in reverse 0 .. Scope_Stack
.Last
loop
8322 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
8323 and then not Comes_From_Source
(S
)
8325 -- S is an enclosing task or protected object. The concurrent
8326 -- declaration has been converted into a type declaration, and
8327 -- the object itself has an object declaration that follows
8328 -- the type in the same declarative part.
8330 Tsk
:= Next_Entity
(S
);
8331 while Etype
(Tsk
) /= S
loop
8338 elsif S
= Scope_Stack
.Table
(J
).Entity
then
8340 -- Call to current task. Will be transformed into call to Self
8348 Make_Selected_Component
(Loc
,
8349 Prefix
=> New_Occurrence_Of
(S
, Loc
),
8351 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
8352 Rewrite
(E_Name
, New_N
);
8355 elsif Nkind
(Entry_Name
) = N_Selected_Component
8356 and then Is_Overloaded
(Prefix
(Entry_Name
))
8358 -- Use the entry name (which must be unique at this point) to find
8359 -- the prefix that returns the corresponding task/protected type.
8362 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
8363 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
8368 Get_First_Interp
(Pref
, I
, It
);
8369 while Present
(It
.Typ
) loop
8370 if Scope
(Ent
) = It
.Typ
then
8371 Set_Etype
(Pref
, It
.Typ
);
8375 Get_Next_Interp
(I
, It
);
8380 if Nkind
(Entry_Name
) = N_Selected_Component
then
8381 Resolve
(Prefix
(Entry_Name
));
8382 Resolve_Implicit_Dereference
(Prefix
(Entry_Name
));
8384 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8385 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
8386 Resolve
(Prefix
(Prefix
(Entry_Name
)));
8387 Resolve_Implicit_Dereference
(Prefix
(Prefix
(Entry_Name
)));
8389 -- We do not resolve the prefix because an Entry_Family has no type,
8390 -- although it has the semantics of an array since it can be indexed.
8391 -- In order to perform the associated range check, we would need to
8392 -- build an array type on the fly and set it on the prefix, but this
8393 -- would be wasteful since only the index type matters. Therefore we
8394 -- attach this index type directly, so that Actual_Index_Expression
8395 -- can pick it up later in order to generate the range check.
8397 Set_Etype
(Prefix
(Entry_Name
), Actual_Index_Type
(Nam
));
8399 Index
:= First
(Expressions
(Entry_Name
));
8400 Resolve
(Index
, Entry_Index_Type
(Nam
));
8402 -- Generate a reference for the index when it denotes an entity
8404 if Is_Entity_Name
(Index
) then
8405 Generate_Reference
(Entity
(Index
), Nam
);
8408 -- Up to this point the expression could have been the actual in a
8409 -- simple entry call, and be given by a named association.
8411 if Nkind
(Index
) = N_Parameter_Association
then
8412 Error_Msg_N
("expect expression for entry index", Index
);
8414 Apply_Scalar_Range_Check
(Index
, Etype
(Prefix
(Entry_Name
)));
8419 ------------------------
8420 -- Resolve_Entry_Call --
8421 ------------------------
8423 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
8424 Entry_Name
: constant Node_Id
:= Name
(N
);
8425 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
8433 -- We kill all checks here, because it does not seem worth the effort to
8434 -- do anything better, an entry call is a big operation.
8438 -- Processing of the name is similar for entry calls and protected
8439 -- operation calls. Once the entity is determined, we can complete
8440 -- the resolution of the actuals.
8442 -- The selector may be overloaded, in the case of a protected object
8443 -- with overloaded functions. The type of the context is used for
8446 if Nkind
(Entry_Name
) = N_Selected_Component
8447 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
8448 and then Typ
/= Standard_Void_Type
8455 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
8456 while Present
(It
.Typ
) loop
8457 if Covers
(Typ
, It
.Typ
) then
8458 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
8459 Set_Etype
(Entry_Name
, It
.Typ
);
8461 Generate_Reference
(It
.Typ
, N
, ' ');
8464 Get_Next_Interp
(I
, It
);
8469 Resolve_Entry
(Entry_Name
);
8471 if Nkind
(Entry_Name
) = N_Selected_Component
then
8473 -- Simple entry or protected operation call
8475 Nam
:= Entity
(Selector_Name
(Entry_Name
));
8476 Obj
:= Prefix
(Entry_Name
);
8478 if Is_Subprogram
(Nam
) then
8479 Check_For_Eliminated_Subprogram
(Entry_Name
, Nam
);
8482 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
8484 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8486 -- Call to member of entry family
8488 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
8489 Obj
:= Prefix
(Prefix
(Entry_Name
));
8490 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
8493 -- We cannot in general check the maximum depth of protected entry calls
8494 -- at compile time. But we can tell that any protected entry call at all
8495 -- violates a specified nesting depth of zero.
8497 if Is_Protected_Type
(Scope
(Nam
)) then
8498 Check_Restriction
(Max_Entry_Queue_Length
, N
);
8501 -- Use context type to disambiguate a protected function that can be
8502 -- called without actuals and that returns an array type, and where the
8503 -- argument list may be an indexing of the returned value.
8505 if Ekind
(Nam
) = E_Function
8506 and then Needs_No_Actuals
(Nam
)
8507 and then Present
(Parameter_Associations
(N
))
8509 ((Is_Array_Type
(Etype
(Nam
))
8510 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
8512 or else (Is_Access_Type
(Etype
(Nam
))
8513 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
8517 Component_Type
(Designated_Type
(Etype
(Nam
))))))
8520 Index_Node
: Node_Id
;
8524 Make_Indexed_Component
(Loc
,
8526 Make_Function_Call
(Loc
, Name
=> Relocate_Node
(Entry_Name
)),
8527 Expressions
=> Parameter_Associations
(N
));
8529 -- Since we are correcting a node classification error made by the
8530 -- parser, we call Replace rather than Rewrite.
8532 Replace
(N
, Index_Node
);
8533 Set_Etype
(Prefix
(N
), Etype
(Nam
));
8535 Resolve_Indexed_Component
(N
, Typ
);
8541 and then Present
(Contract_Wrapper
(Nam
))
8542 and then Current_Scope
/= Contract_Wrapper
(Nam
)
8543 and then Current_Scope
/= Wrapped_Statements
(Contract_Wrapper
(Nam
))
8545 -- Note the entity being called before rewriting the call, so that
8546 -- it appears used at this point.
8548 Generate_Reference
(Nam
, Entry_Name
, 'r');
8550 -- Rewrite as call to the precondition wrapper, adding the task
8551 -- object to the list of actuals. If the call is to a member of an
8552 -- entry family, include the index as well.
8556 New_Actuals
: List_Id
;
8559 New_Actuals
:= New_List
(Obj
);
8561 if Nkind
(Entry_Name
) = N_Indexed_Component
then
8562 Append_To
(New_Actuals
,
8563 New_Copy_Tree
(First
(Expressions
(Entry_Name
))));
8566 Append_List
(Parameter_Associations
(N
), New_Actuals
);
8568 Make_Procedure_Call_Statement
(Loc
,
8570 New_Occurrence_Of
(Contract_Wrapper
(Nam
), Loc
),
8571 Parameter_Associations
=> New_Actuals
);
8572 Rewrite
(N
, New_Call
);
8574 -- Preanalyze and resolve new call. Current procedure is called
8575 -- from Resolve_Call, after which expansion will take place.
8577 Preanalyze_And_Resolve
(N
);
8582 -- The operation name may have been overloaded. Order the actuals
8583 -- according to the formals of the resolved entity, and set the return
8584 -- type to that of the operation.
8587 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
8588 pragma Assert
(Norm_OK
);
8589 Set_Etype
(N
, Etype
(Nam
));
8591 -- Reset the Is_Overloaded flag, since resolution is now completed
8593 -- Simple entry call
8595 if Nkind
(Entry_Name
) = N_Selected_Component
then
8596 Set_Is_Overloaded
(Selector_Name
(Entry_Name
), False);
8598 -- Call to a member of an entry family
8600 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8601 Set_Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)), False);
8605 Resolve_Actuals
(N
, Nam
);
8606 Check_Internal_Protected_Use
(N
, Nam
);
8608 -- Create a call reference to the entry
8610 Generate_Reference
(Nam
, Entry_Name
, 's');
8612 if Is_Entry
(Nam
) then
8613 Check_Potentially_Blocking_Operation
(N
);
8616 -- Verify that a procedure call cannot masquerade as an entry
8617 -- call where an entry call is expected.
8619 if Ekind
(Nam
) = E_Procedure
then
8620 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
8621 and then N
= Entry_Call_Statement
(Parent
(N
))
8623 Error_Msg_N
("entry call required in select statement", N
);
8625 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
8626 and then N
= Triggering_Statement
(Parent
(N
))
8628 Error_Msg_N
("triggering statement cannot be procedure call", N
);
8630 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
8631 and then not In_Open_Scopes
(Scope
(Nam
))
8633 Error_Msg_N
("task has no entry with this name", Entry_Name
);
8637 -- After resolution, entry calls and protected procedure calls are
8638 -- changed into entry calls, for expansion. The structure of the node
8639 -- does not change, so it can safely be done in place. Protected
8640 -- function calls must keep their structure because they are
8643 if Ekind
(Nam
) /= E_Function
then
8645 -- A protected operation that is not a function may modify the
8646 -- corresponding object, and cannot apply to a constant. If this
8647 -- is an internal call, the prefix is the type itself.
8649 if Is_Protected_Type
(Scope
(Nam
))
8650 and then not Is_Variable
(Obj
)
8651 and then (not Is_Entity_Name
(Obj
)
8652 or else not Is_Type
(Entity
(Obj
)))
8655 ("prefix of protected procedure or entry call must be variable",
8660 Entry_Call
: Node_Id
;
8664 Make_Entry_Call_Statement
(Loc
,
8666 Parameter_Associations
=> Parameter_Associations
(N
));
8668 -- Inherit relevant attributes from the original call
8670 Set_First_Named_Actual
8671 (Entry_Call
, First_Named_Actual
(N
));
8673 Set_Is_Elaboration_Checks_OK_Node
8674 (Entry_Call
, Is_Elaboration_Checks_OK_Node
(N
));
8676 Set_Is_Elaboration_Warnings_OK_Node
8677 (Entry_Call
, Is_Elaboration_Warnings_OK_Node
(N
));
8679 Set_Is_SPARK_Mode_On_Node
8680 (Entry_Call
, Is_SPARK_Mode_On_Node
(N
));
8682 Rewrite
(N
, Entry_Call
);
8683 Set_Analyzed
(N
, True);
8686 -- Protected functions can return on the secondary stack, in which case
8687 -- we must trigger the transient scope mechanism.
8689 elsif Expander_Active
8690 and then Requires_Transient_Scope
(Etype
(Nam
))
8692 Establish_Transient_Scope
(N
, Needs_Secondary_Stack
(Etype
(Nam
)));
8695 -- Now we know that this is not a call to a function that returns an
8696 -- array type; moreover, we know the name of the called entry. Detect
8697 -- overlapping actuals, just like for a subprogram call.
8699 Warn_On_Overlapping_Actuals
(Nam
, N
);
8700 end Resolve_Entry_Call
;
8702 -------------------------
8703 -- Resolve_Equality_Op --
8704 -------------------------
8706 -- The operands must have compatible types and the boolean context does not
8707 -- participate in the resolution. The first pass verifies that the operands
8708 -- are not ambiguous and sets their type correctly, or to Any_Type in case
8709 -- of ambiguity. If both operands are strings, aggregates, allocators, or
8710 -- null, they are ambiguous even if they carry a single (universal) type.
8712 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8713 L
: constant Node_Id
:= Left_Opnd
(N
);
8714 R
: constant Node_Id
:= Right_Opnd
(N
);
8716 Implicit_NE_For_User_Defined_Operator
: constant Boolean :=
8718 and then Ekind
(Entity
(N
)) = E_Function
8719 and then not Comes_From_Source
(Entity
(N
))
8721 Is_Intrinsic_Subprogram
(Corresponding_Equality
(Entity
(N
)));
8722 -- Whether this is a call to the implicit inequality operator created
8723 -- for a user-defined operator that is not an intrinsic subprogram, in
8724 -- which case we need to skip some processing.
8726 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
8728 procedure Check_Access_Attribute
(N
: Node_Id
);
8729 -- For any object, '[Unchecked_]Access of such object can never be
8730 -- passed as an operand to the Universal_Access equality operators.
8731 -- This is so because the expected type for Obj'Access in a call to
8732 -- these operators, whose formals are of type Universal_Access, is
8733 -- Universal_Access, and Universal_Access does not have a designated
8734 -- type. For more details, see RM 3.10.2(2/2) and 6.4.1(3).
8736 procedure Check_Designated_Object_Types
(T1
, T2
: Entity_Id
);
8737 -- Check RM 4.5.2(9.6/2) on the given designated object types
8739 procedure Check_Designated_Subprogram_Types
(T1
, T2
: Entity_Id
);
8740 -- Check RM 4.5.2(9.7/2) on the given designated subprogram types
8742 procedure Check_If_Expression
(Cond
: Node_Id
);
8743 -- The resolution rule for if expressions requires that each such must
8744 -- have a unique type. This means that if several dependent expressions
8745 -- are of a non-null anonymous access type, and the context does not
8746 -- impose an expected type (as can be the case in an equality operation)
8747 -- the expression must be rejected.
8749 procedure Explain_Redundancy
(N
: Node_Id
);
8750 -- Attempt to explain the nature of a redundant comparison with True. If
8751 -- the expression N is too complex, this routine issues a general error
8754 function Find_Unique_Access_Type
return Entity_Id
;
8755 -- In the case of allocators and access attributes, the context must
8756 -- provide an indication of the specific access type to be used. If
8757 -- one operand is of such a "generic" access type, check whether there
8758 -- is a specific visible access type that has the same designated type.
8759 -- This is semantically dubious, and of no interest to any real code,
8760 -- but c48008a makes it all worthwhile.
8762 function Suspicious_Prio_For_Equality
return Boolean;
8763 -- Returns True iff the parent node is a and/or/xor operation that
8764 -- could be the cause of confused priorities. Note that if the not is
8765 -- in parens, then False is returned.
8767 ----------------------------
8768 -- Check_Access_Attribute --
8769 ----------------------------
8771 procedure Check_Access_Attribute
(N
: Node_Id
) is
8773 if Nkind
(N
) = N_Attribute_Reference
8774 and then Attribute_Name
(N
) in Name_Access | Name_Unchecked_Access
8777 ("access attribute cannot be used as actual for "
8778 & "universal_access equality", N
);
8780 end Check_Access_Attribute
;
8782 -----------------------------------
8783 -- Check_Designated_Object_Types --
8784 -----------------------------------
8786 procedure Check_Designated_Object_Types
(T1
, T2
: Entity_Id
) is
8788 if (Is_Elementary_Type
(T1
) or else Is_Array_Type
(T1
))
8789 and then (Base_Type
(T1
) /= Base_Type
(T2
)
8790 or else not Subtypes_Statically_Match
(T1
, T2
))
8793 ("designated subtypes for universal_access equality "
8794 & "do not statically match (RM 4.5.2(9.6/2)", N
);
8795 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
8796 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
8798 end Check_Designated_Object_Types
;
8800 ---------------------------------------
8801 -- Check_Designated_Subprogram_Types --
8802 ---------------------------------------
8804 procedure Check_Designated_Subprogram_Types
(T1
, T2
: Entity_Id
) is
8806 if not Subtype_Conformant
(T1
, T2
) then
8808 ("designated subtypes for universal_access equality "
8809 & "not subtype conformant (RM 4.5.2(9.7/2)", N
);
8810 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
8811 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
8813 end Check_Designated_Subprogram_Types
;
8815 -------------------------
8816 -- Check_If_Expression --
8817 -------------------------
8819 procedure Check_If_Expression
(Cond
: Node_Id
) is
8820 Then_Expr
: Node_Id
;
8821 Else_Expr
: Node_Id
;
8824 if Nkind
(Cond
) = N_If_Expression
then
8825 Then_Expr
:= Next
(First
(Expressions
(Cond
)));
8826 Else_Expr
:= Next
(Then_Expr
);
8828 if Nkind
(Then_Expr
) /= N_Null
8829 and then Nkind
(Else_Expr
) /= N_Null
8831 Error_Msg_N
("cannot determine type of if expression", Cond
);
8834 end Check_If_Expression
;
8836 ------------------------
8837 -- Explain_Redundancy --
8838 ------------------------
8840 procedure Explain_Redundancy
(N
: Node_Id
) is
8848 -- Strip the operand down to an entity
8851 if Nkind
(Val
) = N_Selected_Component
then
8852 Val
:= Selector_Name
(Val
);
8858 -- The construct denotes an entity
8860 if Is_Entity_Name
(Val
) and then Present
(Entity
(Val
)) then
8861 Val_Id
:= Entity
(Val
);
8863 -- Do not generate an error message when the comparison is done
8864 -- against the enumeration literal Standard.True.
8866 if Ekind
(Val_Id
) /= E_Enumeration_Literal
then
8868 -- Build a customized error message
8871 Add_Str_To_Name_Buffer
("?r?");
8873 if Ekind
(Val_Id
) = E_Component
then
8874 Add_Str_To_Name_Buffer
("component ");
8876 elsif Ekind
(Val_Id
) = E_Constant
then
8877 Add_Str_To_Name_Buffer
("constant ");
8879 elsif Ekind
(Val_Id
) = E_Discriminant
then
8880 Add_Str_To_Name_Buffer
("discriminant ");
8882 elsif Is_Formal
(Val_Id
) then
8883 Add_Str_To_Name_Buffer
("parameter ");
8885 elsif Ekind
(Val_Id
) = E_Variable
then
8886 Add_Str_To_Name_Buffer
("variable ");
8889 Add_Str_To_Name_Buffer
("& is always True!");
8892 Error_Msg_NE
(Get_Name_String
(Error
), Val
, Val_Id
);
8895 -- The construct is too complex to disect, issue a general message
8898 Error_Msg_N
("?r?expression is always True!", Val
);
8900 end Explain_Redundancy
;
8902 -----------------------------
8903 -- Find_Unique_Access_Type --
8904 -----------------------------
8906 function Find_Unique_Access_Type
return Entity_Id
is
8912 if Ekind
(Etype
(R
)) in E_Allocator_Type | E_Access_Attribute_Type
8914 Acc
:= Designated_Type
(Etype
(R
));
8916 elsif Ekind
(Etype
(L
)) in E_Allocator_Type | E_Access_Attribute_Type
8918 Acc
:= Designated_Type
(Etype
(L
));
8924 while S
/= Standard_Standard
loop
8925 E
:= First_Entity
(S
);
8926 while Present
(E
) loop
8928 and then Is_Access_Type
(E
)
8929 and then Ekind
(E
) /= E_Allocator_Type
8930 and then Designated_Type
(E
) = Base_Type
(Acc
)
8942 end Find_Unique_Access_Type
;
8944 ----------------------------------
8945 -- Suspicious_Prio_For_Equality --
8946 ----------------------------------
8948 function Suspicious_Prio_For_Equality
return Boolean is
8949 Par
: constant Node_Id
:= Parent
(N
);
8952 -- Check if parent node is one of and/or/xor, not parenthesized
8953 -- explicitly, and its own parent is not of this kind. Otherwise,
8954 -- it's a case of chained Boolean conditions which is likely well
8957 if Nkind
(Par
) in N_Op_And | N_Op_Or | N_Op_Xor
8958 and then Paren_Count
(N
) = 0
8959 and then Nkind
(Parent
(Par
)) not in N_Op_And | N_Op_Or | N_Op_Xor
8963 (if Left_Opnd
(Par
) = N
then
8968 -- Compar may have been rewritten, for example from (a /= b)
8969 -- into not (a = b). Use the Original_Node instead.
8971 Compar
:= Original_Node
(Compar
);
8973 -- If the other argument of the and/or/xor is also a
8974 -- comparison, or another and/or/xor then most likely
8975 -- the priorities are correctly set.
8977 return Nkind
(Compar
) not in N_Op_Boolean
;
8983 end Suspicious_Prio_For_Equality
;
8985 -- Start of processing for Resolve_Equality_Op
8988 if T
= Any_Fixed
then
8989 T
:= Unique_Fixed_Point_Type
(L
);
8992 Set_Etype
(N
, Base_Type
(Typ
));
8993 Generate_Reference
(T
, N
, ' ');
8995 if T
= Any_Type
then
8996 -- Deal with explicit ambiguity of operands, unless this is a call
8997 -- to the implicit inequality operator created for a user-defined
8998 -- operator that is not an intrinsic subprogram, since the common
8999 -- resolution of operands done here does not apply to it.
9001 if not Implicit_NE_For_User_Defined_Operator
9002 and then (Is_Overloaded
(L
) or else Is_Overloaded
(R
))
9004 Ambiguous_Operands
(N
);
9009 -- For Ada 2022, check for user-defined literals when the type has
9010 -- the appropriate aspect.
9012 if Has_Applicable_User_Defined_Literal
(L
, Etype
(R
)) then
9013 Resolve
(L
, Etype
(R
));
9014 Set_Etype
(N
, Standard_Boolean
);
9017 if Has_Applicable_User_Defined_Literal
(R
, Etype
(L
)) then
9018 Resolve
(R
, Etype
(L
));
9019 Set_Etype
(N
, Standard_Boolean
);
9022 -- Deal with other error cases
9024 if T
= Any_String
or else
9025 T
= Any_Composite
or else
9028 if T
= Any_Character
then
9029 Ambiguous_Character
(L
);
9031 Error_Msg_N
("ambiguous operands for equality", N
);
9034 Set_Etype
(N
, Any_Type
);
9037 elsif T
= Universal_Access
9038 or else Ekind
(T
) in E_Allocator_Type | E_Access_Attribute_Type
9040 T
:= Find_Unique_Access_Type
;
9043 Error_Msg_N
("ambiguous operands for equality", N
);
9044 Set_Etype
(N
, Any_Type
);
9048 -- If expressions must have a single type, and if the context does
9049 -- not impose one the dependent expressions cannot be anonymous
9052 -- Why no similar processing for case expressions???
9054 elsif Ada_Version
>= Ada_2012
9055 and then Is_Anonymous_Access_Type
(Etype
(L
))
9056 and then Is_Anonymous_Access_Type
(Etype
(R
))
9058 Check_If_Expression
(L
);
9059 Check_If_Expression
(R
);
9062 -- RM 4.5.2(9.5/2): At least one of the operands of the equality
9063 -- operators for universal_access shall be of type universal_access,
9064 -- or both shall be of access-to-object types, or both shall be of
9065 -- access-to-subprogram types (RM 4.5.2(9.5/2)).
9067 if Is_Anonymous_Access_Type
(T
)
9068 and then Etype
(L
) /= Universal_Access
9069 and then Etype
(R
) /= Universal_Access
9071 -- RM 4.5.2(9.6/2): When both are of access-to-object types, the
9072 -- designated types shall be the same or one shall cover the other
9073 -- and if the designated types are elementary or array types, then
9074 -- the designated subtypes shall statically match.
9076 if Is_Access_Object_Type
(Etype
(L
))
9077 and then Is_Access_Object_Type
(Etype
(R
))
9079 Check_Designated_Object_Types
9080 (Designated_Type
(Etype
(L
)), Designated_Type
(Etype
(R
)));
9082 -- RM 4.5.2(9.7/2): When both are of access-to-subprogram types,
9083 -- the designated profiles shall be subtype conformant.
9085 elsif Is_Access_Subprogram_Type
(Etype
(L
))
9086 and then Is_Access_Subprogram_Type
(Etype
(R
))
9088 Check_Designated_Subprogram_Types
9089 (Designated_Type
(Etype
(L
)), Designated_Type
(Etype
(R
)));
9093 -- Check another case of equality operators for universal_access
9095 if Is_Anonymous_Access_Type
(T
) and then Comes_From_Source
(N
) then
9096 Check_Access_Attribute
(L
);
9097 Check_Access_Attribute
(R
);
9102 Set_Compare_Type
(N
, T
);
9104 -- AI12-0413: user-defined primitive equality of an untagged record
9105 -- type hides the predefined equality operator, including within a
9106 -- generic, and if it is declared abstract, results in an illegal
9107 -- instance if the operator is used in the spec, or in the raising
9108 -- of Program_Error if used in the body of an instance.
9110 if Nkind
(N
) = N_Op_Eq
9111 and then In_Instance
9112 and then Ada_Version
>= Ada_2012
9115 U
: constant Entity_Id
:= Underlying_Type
(T
);
9121 and then Is_Record_Type
(U
)
9122 and then not Is_Tagged_Type
(U
)
9124 Eq
:= Get_User_Defined_Equality
(T
);
9126 if Present
(Eq
) then
9127 if Is_Abstract_Subprogram
(Eq
) then
9128 Nondispatching_Call_To_Abstract_Operation
(N
, Eq
);
9130 Rewrite_Operator_As_Call
(N
, Eq
);
9139 -- If the unique type is a class-wide type then it will be expanded
9140 -- into a dispatching call to the predefined primitive. Therefore we
9141 -- check here for potential violation of such restriction.
9143 if Is_Class_Wide_Type
(T
) then
9144 Check_Restriction
(No_Dispatching_Calls
, N
);
9147 -- Only warn for redundant equality comparison to True for objects
9148 -- (e.g. "X = True") and operations (e.g. "(X < Y) = True"). For
9149 -- other expressions, it may be a matter of preference to write
9150 -- "Expr = True" or "Expr".
9152 if Warn_On_Redundant_Constructs
9153 and then Comes_From_Source
(N
)
9154 and then Comes_From_Source
(R
)
9155 and then Is_Entity_Name
(R
)
9156 and then Entity
(R
) = Standard_True
9158 ((Is_Entity_Name
(L
) and then Is_Object
(Entity
(L
)))
9162 Error_Msg_N
-- CODEFIX
9163 ("?r?comparison with True is redundant!", N
);
9164 Explain_Redundancy
(Original_Node
(R
));
9167 -- Warn on a (in)equality between boolean values which is not
9168 -- parenthesized when the parent expression is one of and/or/xor, as
9169 -- this is interpreted as (a = b) op c where most likely a = (b op c)
9170 -- was intended. Do not generate a warning in generic instances, as
9171 -- the problematic expression may be implicitly parenthesized in
9172 -- the generic itself if one of the operators is a generic formal.
9173 -- Also do not generate a warning for generated equality, for
9174 -- example from rewritting a membership test.
9176 if Warn_On_Questionable_Missing_Parens
9177 and then not In_Instance
9178 and then Comes_From_Source
(N
)
9179 and then Is_Boolean_Type
(T
)
9180 and then Suspicious_Prio_For_Equality
9182 Error_Msg_N
("?q?equality should be parenthesized here!", N
);
9185 Check_Unset_Reference
(L
);
9186 Check_Unset_Reference
(R
);
9187 Generate_Operator_Reference
(N
, T
);
9188 Check_Low_Bound_Tested
(N
);
9190 -- Unless this is a call to the implicit inequality operator created
9191 -- for a user-defined operator that is not an intrinsic subprogram,
9192 -- try to fold the operation.
9194 if not Implicit_NE_For_User_Defined_Operator
then
9195 Analyze_Dimension
(N
);
9196 Eval_Relational_Op
(N
);
9198 elsif Nkind
(N
) = N_Op_Ne
9199 and then Is_Abstract_Subprogram
(Entity
(N
))
9201 Nondispatching_Call_To_Abstract_Operation
(N
, Entity
(N
));
9204 end Resolve_Equality_Op
;
9206 ----------------------------------
9207 -- Resolve_Explicit_Dereference --
9208 ----------------------------------
9210 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
9211 Loc
: constant Source_Ptr
:= Sloc
(N
);
9213 P
: constant Node_Id
:= Prefix
(N
);
9216 -- The candidate prefix type, if overloaded
9222 Check_Fully_Declared_Prefix
(Typ
, P
);
9225 -- A useful optimization: check whether the dereference denotes an
9226 -- element of a container, and if so rewrite it as a call to the
9227 -- corresponding Element function.
9229 -- Disabled for now, on advice of ARG. A more restricted form of the
9230 -- predicate might be acceptable ???
9232 -- if Is_Container_Element (N) then
9236 if Is_Overloaded
(P
) then
9238 -- Use the context type to select the prefix that has the correct
9239 -- designated type. Keep the first match, which will be the inner-
9242 Get_First_Interp
(P
, I
, It
);
9244 while Present
(It
.Typ
) loop
9245 if Is_Access_Type
(It
.Typ
)
9246 and then Covers
(Typ
, Designated_Type
(It
.Typ
))
9252 -- Remove access types that do not match, but preserve access
9253 -- to subprogram interpretations, in case a further dereference
9254 -- is needed (see below).
9256 elsif Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
9260 Get_Next_Interp
(I
, It
);
9263 if Present
(P_Typ
) then
9265 Set_Etype
(N
, Designated_Type
(P_Typ
));
9268 -- If no interpretation covers the designated type of the prefix,
9269 -- this is the pathological case where not all implementations of
9270 -- the prefix allow the interpretation of the node as a call. Now
9271 -- that the expected type is known, Remove other interpretations
9272 -- from prefix, rewrite it as a call, and resolve again, so that
9273 -- the proper call node is generated.
9275 Get_First_Interp
(P
, I
, It
);
9276 while Present
(It
.Typ
) loop
9277 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
9281 Get_Next_Interp
(I
, It
);
9285 Make_Function_Call
(Loc
,
9287 Make_Explicit_Dereference
(Loc
,
9289 Parameter_Associations
=> New_List
);
9291 Save_Interps
(N
, New_N
);
9293 Analyze_And_Resolve
(N
, Typ
);
9297 -- If not overloaded, resolve P with its own type
9303 -- If the prefix might be null, add an access check
9305 if Is_Access_Type
(Etype
(P
))
9306 and then not Can_Never_Be_Null
(Etype
(P
))
9308 Apply_Access_Check
(N
);
9311 -- If the designated type is a packed unconstrained array type, and the
9312 -- explicit dereference is not in the context of an attribute reference,
9313 -- then we must compute and set the actual subtype, since it is needed
9314 -- by Gigi. The reason we exclude the attribute case is that this is
9315 -- handled fine by Gigi, and in fact we use such attributes to build the
9316 -- actual subtype. We also exclude generated code (which builds actual
9317 -- subtypes directly if they are needed).
9319 if Is_Packed_Array
(Etype
(N
))
9320 and then not Is_Constrained
(Etype
(N
))
9321 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
9322 and then Comes_From_Source
(N
)
9324 Set_Etype
(N
, Get_Actual_Subtype
(N
));
9327 Analyze_Dimension
(N
);
9329 -- Note: No Eval processing is required for an explicit dereference,
9330 -- because such a name can never be static.
9332 end Resolve_Explicit_Dereference
;
9334 -------------------------------------
9335 -- Resolve_Expression_With_Actions --
9336 -------------------------------------
9338 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
9340 function OK_For_Static
(Act
: Node_Id
) return Boolean;
9341 -- True if Act is an action of a declare_expression that is allowed in a
9342 -- static declare_expression.
9344 function All_OK_For_Static
return Boolean;
9345 -- True if all actions of N are allowed in a static declare_expression.
9347 function Get_Literal
(Expr
: Node_Id
) return Node_Id
;
9348 -- Expr is an expression with compile-time-known value. This returns the
9349 -- literal node that reprsents that value.
9355 function OK_For_Static
(Act
: Node_Id
) return Boolean is
9358 when N_Object_Declaration
=>
9359 if Constant_Present
(Act
)
9360 and then Is_Static_Expression
(Expression
(Act
))
9365 when N_Object_Renaming_Declaration
=>
9366 if Statically_Names_Object
(Name
(Act
)) then
9371 -- No other declarations, nor even pragmas, are allowed in a
9372 -- declare expression, so if we see something else, it must be
9373 -- an internally generated expression_with_actions.
9380 -----------------------
9381 -- All_OK_For_Static --
9382 -----------------------
9384 function All_OK_For_Static
return Boolean is
9385 Act
: Node_Id
:= First
(Actions
(N
));
9387 while Present
(Act
) loop
9388 if not OK_For_Static
(Act
) then
9396 end All_OK_For_Static
;
9402 function Get_Literal
(Expr
: Node_Id
) return Node_Id
is
9403 pragma Assert
(Compile_Time_Known_Value
(Expr
));
9406 case Nkind
(Expr
) is
9407 when N_Has_Entity
=>
9408 if Ekind
(Entity
(Expr
)) = E_Enumeration_Literal
then
9411 Result
:= Constant_Value
(Entity
(Expr
));
9413 when N_Numeric_Or_String_Literal
=>
9416 raise Program_Error
;
9420 (Nkind
(Result
) in N_Numeric_Or_String_Literal
9421 or else Ekind
(Entity
(Result
)) = E_Enumeration_Literal
);
9427 Loc
: constant Source_Ptr
:= Sloc
(N
);
9429 -- Start of processing for Resolve_Expression_With_Actions
9434 if Is_Empty_List
(Actions
(N
)) then
9435 pragma Assert
(All_OK_For_Static
); null;
9438 -- If the value of the expression is known at compile time, and all
9439 -- of the actions (if any) are suitable, then replace the declare
9440 -- expression with its expression. This allows the declare expression
9441 -- as a whole to be static if appropriate. See AI12-0368.
9443 if Compile_Time_Known_Value
(Expression
(N
)) then
9444 if Is_Empty_List
(Actions
(N
)) then
9445 Rewrite
(N
, Expression
(N
));
9446 elsif All_OK_For_Static
then
9449 (Get_Literal
(Expression
(N
)), New_Sloc
=> Loc
));
9452 end Resolve_Expression_With_Actions
;
9454 ----------------------------------
9455 -- Resolve_External_Initializer --
9456 ----------------------------------
9458 procedure Resolve_External_Initializer
(N
: Node_Id
; Typ
: Entity_Id
) is
9460 Set_String_Literal_Subtype
(N
, Typ
);
9461 end Resolve_External_Initializer
;
9463 ----------------------------------
9464 -- Resolve_Generalized_Indexing --
9465 ----------------------------------
9467 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
) is
9468 Indexing
: constant Node_Id
:= Generalized_Indexing
(N
);
9470 Rewrite
(N
, Indexing
);
9472 end Resolve_Generalized_Indexing
;
9474 ---------------------------
9475 -- Resolve_If_Expression --
9476 ---------------------------
9478 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9479 Condition
: constant Node_Id
:= First
(Expressions
(N
));
9481 procedure Apply_Check
(Expr
: Node_Id
; Result_Type
: Entity_Id
);
9482 -- When a dependent expression is of a subtype different from
9483 -- the context subtype, then insert a qualification to ensure
9484 -- the generation of a constraint check. This was previously
9485 -- for scalar types. For array types apply a length check, given
9486 -- that the context in general allows sliding, while a qualified
9487 -- expression forces equality of bounds.
9493 procedure Apply_Check
(Expr
: Node_Id
; Result_Type
: Entity_Id
) is
9494 Expr_Typ
: constant Entity_Id
:= Etype
(Expr
);
9495 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
9499 or else Is_Tagged_Type
(Typ
)
9500 or else Is_Access_Type
(Typ
)
9501 or else not Is_Constrained
(Typ
)
9502 or else Inside_A_Generic
9506 elsif Is_Array_Type
(Typ
) then
9507 Apply_Length_Check
(Expr
, Typ
);
9511 Make_Qualified_Expression
(Loc
,
9512 Subtype_Mark
=> New_Occurrence_Of
(Result_Type
, Loc
),
9513 Expression
=> Relocate_Node
(Expr
)));
9515 Analyze_And_Resolve
(Expr
, Result_Type
);
9521 Else_Expr
: Node_Id
;
9522 Then_Expr
: Node_Id
;
9524 Result_Type
: Entity_Id
;
9525 -- So in most cases the type of the if_expression and of its
9526 -- dependent expressions is that of the context. However, if
9527 -- the expression is the index of an Indexed_Component, we must
9528 -- ensure that a proper index check is applied, rather than a
9529 -- range check on the index type (which might be discriminant
9530 -- dependent). In this case we resolve with the base type of the
9531 -- index type, and the index check is generated in the resolution
9532 -- of the indexed_component above.
9534 -- Start of processing for Resolve_If_Expression
9537 -- Defend against malformed expressions
9539 if No
(Condition
) then
9543 if Present
(Parent
(N
))
9544 and then (Nkind
(Parent
(N
)) = N_Indexed_Component
9545 or else Nkind
(Parent
(Parent
(N
))) = N_Indexed_Component
)
9547 Result_Type
:= Base_Type
(Typ
);
9553 Then_Expr
:= Next
(Condition
);
9555 if No
(Then_Expr
) then
9559 Resolve
(Condition
, Any_Boolean
);
9560 Check_Unset_Reference
(Condition
);
9562 Resolve_Dependent_Expression
(N
, Then_Expr
, Result_Type
);
9564 Check_Unset_Reference
(Then_Expr
);
9565 Apply_Check
(Then_Expr
, Result_Type
);
9567 Else_Expr
:= Next
(Then_Expr
);
9569 -- If ELSE expression present, just resolve using the determined type
9571 if Present
(Else_Expr
) then
9572 Resolve_Dependent_Expression
(N
, Else_Expr
, Result_Type
);
9574 Check_Unset_Reference
(Else_Expr
);
9575 Apply_Check
(Else_Expr
, Result_Type
);
9577 -- Apply RM 4.5.7 (17/3): whether the expression is statically or
9578 -- dynamically tagged must be known statically.
9580 if Is_Tagged_Type
(Typ
) and then not Is_Class_Wide_Type
(Typ
) then
9581 if Is_Dynamically_Tagged
(Then_Expr
) /=
9582 Is_Dynamically_Tagged
(Else_Expr
)
9584 Error_Msg_N
("all or none of the dependent expressions "
9585 & "can be dynamically tagged", N
);
9589 -- If no ELSE expression is present, root type must be Standard.Boolean
9590 -- and we provide a Standard.True result converted to the appropriate
9591 -- Boolean type (in case it is a derived boolean type).
9593 elsif Root_Type
(Typ
) = Standard_Boolean
then
9595 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
9596 Analyze_And_Resolve
(Else_Expr
, Result_Type
);
9597 Append_To
(Expressions
(N
), Else_Expr
);
9600 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
9601 Append_To
(Expressions
(N
), Error
);
9604 Set_Etype
(N
, Result_Type
);
9606 if not Error_Posted
(N
) then
9607 Eval_If_Expression
(N
);
9610 Analyze_Dimension
(N
);
9611 end Resolve_If_Expression
;
9613 ----------------------------------
9614 -- Resolve_Implicit_Dereference --
9615 ----------------------------------
9617 procedure Resolve_Implicit_Dereference
(P
: Node_Id
) is
9618 Desig_Typ
: Entity_Id
;
9621 if Is_Access_Type
(Etype
(P
)) then
9622 Desig_Typ
:= Implicitly_Designated_Type
(Etype
(P
));
9623 Insert_Explicit_Dereference
(P
);
9624 Analyze_And_Resolve
(P
, Desig_Typ
);
9626 end Resolve_Implicit_Dereference
;
9628 -------------------------------
9629 -- Resolve_Indexed_Component --
9630 -------------------------------
9632 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
9633 Pref
: constant Node_Id
:= Prefix
(N
);
9635 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
9639 if Present
(Generalized_Indexing
(N
)) then
9640 Resolve_Generalized_Indexing
(N
, Typ
);
9644 if Is_Overloaded
(Pref
) then
9646 -- Use the context type to select the prefix that yields the correct
9652 I1
: Interp_Index
:= 0;
9653 Found
: Boolean := False;
9656 Get_First_Interp
(Pref
, I
, It
);
9657 while Present
(It
.Typ
) loop
9658 if (Is_Array_Type
(It
.Typ
)
9659 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
9660 or else (Is_Access_Type
(It
.Typ
)
9661 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
9665 Component_Type
(Designated_Type
(It
.Typ
))))
9668 It
:= Disambiguate
(Pref
, I1
, I
, Any_Type
);
9670 if It
= No_Interp
then
9671 Error_Msg_N
("ambiguous prefix for indexing", N
);
9677 Array_Type
:= It
.Typ
;
9683 Array_Type
:= It
.Typ
;
9688 Get_Next_Interp
(I
, It
);
9693 Array_Type
:= Etype
(Pref
);
9696 Resolve
(Pref
, Array_Type
);
9697 Array_Type
:= Get_Actual_Subtype_If_Available
(Pref
);
9699 -- If the prefix's type is an access type, get to the real array type.
9700 -- Note: we do not apply an access check because an explicit dereference
9701 -- will be introduced later, and the check will happen there.
9703 if Is_Access_Type
(Array_Type
) then
9704 Array_Type
:= Implicitly_Designated_Type
(Array_Type
);
9707 -- If name was overloaded, set component type correctly now.
9708 -- If a misplaced call to an entry family (which has no index types)
9709 -- return. Error will be diagnosed from calling context.
9711 if Is_Array_Type
(Array_Type
) then
9712 Set_Etype
(N
, Component_Type
(Array_Type
));
9717 Index
:= First_Index
(Array_Type
);
9718 Expr
:= First
(Expressions
(N
));
9720 -- The prefix may have resolved to a string literal, in which case its
9721 -- etype has a special representation. This is only possible currently
9722 -- if the prefix is a static concatenation, written in functional
9725 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
9726 Resolve
(Expr
, Standard_Positive
);
9729 while Present
(Index
) and then Present
(Expr
) loop
9730 Resolve
(Expr
, Etype
(Index
));
9731 Check_Unset_Reference
(Expr
);
9733 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
9740 Resolve_Implicit_Dereference
(Pref
);
9741 Analyze_Dimension
(N
);
9743 -- Do not generate the warning on suspicious index if we are analyzing
9744 -- package Ada.Tags; otherwise we will report the warning with the
9745 -- Prims_Ptr field of the dispatch table.
9747 if Scope
(Etype
(Pref
)) = Standard_Standard
9749 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Pref
))), Ada_Tags
)
9751 Warn_On_Suspicious_Index
(Pref
, First
(Expressions
(N
)));
9752 Eval_Indexed_Component
(N
);
9755 -- If the array type is atomic and the component is not, then this is
9756 -- worth a warning before Ada 2022, since we have a situation where the
9757 -- access to the component may cause extra read/writes of the atomic
9758 -- object, or partial word accesses, both of which may be unexpected.
9760 if Nkind
(N
) = N_Indexed_Component
9761 and then Is_Atomic_Non_VFA_Ref_With_Address
(N
)
9762 and then not (Has_Atomic_Components
(Array_Type
)
9763 or else (Is_Entity_Name
(Pref
)
9764 and then Has_Atomic_Components
9766 and then not Is_Atomic
(Component_Type
(Array_Type
))
9767 and then Ada_Version
< Ada_2022
9770 ("??access to non-atomic component of atomic array", Pref
);
9772 ("??\may cause unexpected accesses to atomic object", Pref
);
9774 end Resolve_Indexed_Component
;
9776 -----------------------------
9777 -- Resolve_Integer_Literal --
9778 -----------------------------
9780 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9783 Eval_Integer_Literal
(N
);
9784 end Resolve_Integer_Literal
;
9786 -----------------------------------------
9787 -- Resolve_Interpolated_String_Literal --
9788 -----------------------------------------
9790 procedure Resolve_Interpolated_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
)
9795 Str_Elem
:= First
(Expressions
(N
));
9796 pragma Assert
(Nkind
(Str_Elem
) = N_String_Literal
);
9798 while Present
(Str_Elem
) loop
9800 -- Resolve string elements using the context type; for interpolated
9801 -- expressions there is no need to check if their type has a suitable
9802 -- image function because under Ada 2022 all the types have such
9803 -- function available.
9805 if Nkind
(Str_Elem
) = N_String_Literal
9806 and then Is_Interpolated_String_Literal
(Str_Elem
)
9808 Resolve
(Str_Elem
, Typ
);
9810 -- Must have been rejected during analysis
9812 elsif Nkind
(Str_Elem
) in N_Character_Literal
9817 pragma Assert
(Error_Posted
(Str_Elem
));
9824 end Resolve_Interpolated_String_Literal
;
9826 --------------------------------
9827 -- Resolve_Intrinsic_Operator --
9828 --------------------------------
9830 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
9831 Is_Stoele_Mod
: constant Boolean :=
9832 Nkind
(N
) = N_Op_Mod
9833 and then Is_RTE
(First_Subtype
(Typ
), RE_Storage_Offset
)
9834 and then Is_RTE
(Etype
(Left_Opnd
(N
)), RE_Address
);
9835 -- True if this is the special mod operator of System.Storage_Elements,
9836 -- which needs to be resolved to the type of the left operand in order
9837 -- to implement the correct semantics.
9839 Btyp
: constant Entity_Id
:=
9841 then Implementation_Base_Type
(Etype
(Left_Opnd
(N
)))
9842 else Implementation_Base_Type
(Typ
));
9843 -- The base type to be used for the operator
9845 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
;
9846 -- If the operand is a literal, it cannot be the expression in a
9847 -- conversion. Use a qualified expression instead.
9849 ---------------------
9850 -- Convert_Operand --
9851 ---------------------
9853 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
is
9854 Loc
: constant Source_Ptr
:= Sloc
(Opnd
);
9858 if Nkind
(Opnd
) in N_Integer_Literal | N_Real_Literal
then
9860 Make_Qualified_Expression
(Loc
,
9861 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
9862 Expression
=> Relocate_Node
(Opnd
));
9866 Res
:= Unchecked_Convert_To
(Btyp
, Opnd
);
9870 end Convert_Operand
;
9878 -- Start of processing for Resolve_Intrinsic_Operator
9881 -- We must preserve the original entity in a generic setting, so that
9882 -- the legality of the operation can be verified in an instance.
9884 if not Expander_Active
then
9888 case N_Binary_Op
'(Nkind (N)) is
9890 Op := Standard_Op_Add;
9892 Op := Standard_Op_Expon;
9893 when N_Op_Subtract =>
9894 Op := Standard_Op_Subtract;
9896 Op := Standard_Op_Divide;
9898 Op := Standard_Op_Mod;
9899 when N_Op_Multiply =>
9900 Op := Standard_Op_Multiply;
9902 Op := Standard_Op_Rem;
9904 -- Non-arithmetic operators are handled elsewhere
9910 raise Program_Error;
9914 Set_Is_Overloaded (N, False);
9916 -- If the result or operand types are private, rewrite with unchecked
9917 -- conversions on the operands and the result, to expose the proper
9918 -- underlying numeric type. Likewise for the special mod operator of
9919 -- System.Storage_Elements, to expose the modified base type.
9921 if Is_Private_Type (Typ)
9922 or else Is_Private_Type (Etype (Left_Opnd (N)))
9923 or else Is_Private_Type (Etype (Right_Opnd (N)))
9924 or else Is_Stoele_Mod
9926 Arg1 := Convert_Operand (Left_Opnd (N));
9928 if Nkind (N) = N_Op_Expon then
9929 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
9931 Arg2 := Convert_Operand (Right_Opnd (N));
9934 if Nkind (Arg1) = N_Type_Conversion then
9935 Save_Interps (Left_Opnd (N), Expression (Arg1));
9938 if Nkind (Arg2) = N_Type_Conversion then
9939 Save_Interps (Right_Opnd (N), Expression (Arg2));
9942 Set_Left_Opnd (N, Arg1);
9943 Set_Right_Opnd (N, Arg2);
9945 Set_Etype (N, Btyp);
9946 Rewrite (N, Unchecked_Convert_To (Typ, N));
9949 elsif Typ /= Etype (Left_Opnd (N))
9950 or else Typ /= Etype (Right_Opnd (N))
9952 -- Add explicit conversion where needed, and save interpretations in
9953 -- case operands are overloaded.
9955 Arg1 := Convert_To (Typ, Left_Opnd (N));
9956 Arg2 := Convert_To (Typ, Right_Opnd (N));
9958 if Nkind (Arg1) = N_Type_Conversion then
9959 Save_Interps (Left_Opnd (N), Expression (Arg1));
9961 Save_Interps (Left_Opnd (N), Arg1);
9964 if Nkind (Arg2) = N_Type_Conversion then
9965 Save_Interps (Right_Opnd (N), Expression (Arg2));
9967 Save_Interps (Right_Opnd (N), Arg2);
9970 Rewrite (Left_Opnd (N), Arg1);
9971 Rewrite (Right_Opnd (N), Arg2);
9974 Resolve_Arithmetic_Op (N, Typ);
9977 Resolve_Arithmetic_Op (N, Typ);
9979 end Resolve_Intrinsic_Operator;
9981 --------------------------------------
9982 -- Resolve_Intrinsic_Unary_Operator --
9983 --------------------------------------
9985 procedure Resolve_Intrinsic_Unary_Operator
9989 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
9994 -- We must preserve the original entity in a generic setting, so that
9995 -- the legality of the operation can be verified in an instance.
9997 if not Expander_Active then
10001 case N_Unary_Op'(Nkind
(N
)) is
10003 Op
:= Standard_Op_Abs
;
10005 Op
:= Standard_Op_Minus
;
10007 Op
:= Standard_Op_Plus
;
10009 -- Non-arithmetic operators are handled elsewhere
10012 raise Program_Error
;
10015 Set_Entity
(N
, Op
);
10017 if Is_Private_Type
(Typ
) then
10018 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
10019 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
10021 Set_Right_Opnd
(N
, Arg2
);
10023 Set_Etype
(N
, Btyp
);
10024 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
10028 Resolve_Unary_Op
(N
, Typ
);
10030 end Resolve_Intrinsic_Unary_Operator
;
10032 ------------------------
10033 -- Resolve_Logical_Op --
10034 ------------------------
10036 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
10040 Check_No_Direct_Boolean_Operators
(N
);
10042 -- Predefined operations on scalar types yield the base type. On the
10043 -- other hand, logical operations on arrays yield the type of the
10044 -- arguments (and the context).
10046 if Is_Array_Type
(Typ
) then
10049 B_Typ
:= Base_Type
(Typ
);
10052 -- The following test is required because the operands of the operation
10053 -- may be literals, in which case the resulting type appears to be
10054 -- compatible with a signed integer type, when in fact it is compatible
10055 -- only with modular types. If the context itself is universal, the
10056 -- operation is illegal.
10058 if not Valid_Boolean_Arg
(Typ
) then
10059 Error_Msg_N
("invalid context for logical operation", N
);
10060 Set_Etype
(N
, Any_Type
);
10063 elsif Typ
= Any_Modular
then
10065 ("no modular type available in this context", N
);
10066 Set_Etype
(N
, Any_Type
);
10069 elsif Is_Modular_Integer_Type
(Typ
)
10070 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
10071 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
10073 Check_For_Visible_Operator
(N
, B_Typ
);
10076 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
10077 -- is active and the result type is standard Boolean (do not mess with
10078 -- ops that return a nonstandard Boolean type, because something strange
10081 -- Note: you might expect this replacement to be done during expansion,
10082 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
10083 -- is used, no part of the right operand of an "and" or "or" operator
10084 -- should be executed if the left operand would short-circuit the
10085 -- evaluation of the corresponding "and then" or "or else". If we left
10086 -- the replacement to expansion time, then run-time checks associated
10087 -- with such operands would be evaluated unconditionally, due to being
10088 -- before the condition prior to the rewriting as short-circuit forms
10089 -- during expansion.
10091 if Short_Circuit_And_Or
10092 and then B_Typ
= Standard_Boolean
10093 and then Nkind
(N
) in N_Op_And | N_Op_Or
10095 -- Mark the corresponding putative SCO operator as truly a logical
10096 -- (and short-circuit) operator.
10098 if Generate_SCO
and then Comes_From_Source
(N
) then
10099 Set_SCO_Logical_Operator
(N
);
10102 if Nkind
(N
) = N_Op_And
then
10104 Make_And_Then
(Sloc
(N
),
10105 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
10106 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
10107 Analyze_And_Resolve
(N
, B_Typ
);
10109 -- Case of OR changed to OR ELSE
10113 Make_Or_Else
(Sloc
(N
),
10114 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
10115 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
10116 Analyze_And_Resolve
(N
, B_Typ
);
10119 -- Return now, since analysis of the rewritten ops will take care of
10120 -- other reference bookkeeping and expression folding.
10125 Resolve
(Left_Opnd
(N
), B_Typ
);
10126 Resolve
(Right_Opnd
(N
), B_Typ
);
10128 Check_Unset_Reference
(Left_Opnd
(N
));
10129 Check_Unset_Reference
(Right_Opnd
(N
));
10131 Set_Etype
(N
, B_Typ
);
10132 Generate_Operator_Reference
(N
, B_Typ
);
10133 Eval_Logical_Op
(N
);
10134 end Resolve_Logical_Op
;
10136 ---------------------------------
10137 -- Resolve_Membership_Equality --
10138 ---------------------------------
10140 procedure Resolve_Membership_Equality
(N
: Node_Id
; Typ
: Entity_Id
) is
10141 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
10144 -- RM 4.5.2(4.1/3): if the type is limited, then it shall have a visible
10145 -- primitive equality operator. This means that we can use the regular
10146 -- visibility-based resolution and reset Entity in order to trigger it.
10148 if Is_Limited_Type
(Typ
) then
10149 Set_Entity
(N
, Empty
);
10151 -- RM 4.5.2(28.1/3): if the type is a record, then the membership test
10152 -- uses the primitive equality for the type [even if it is not visible].
10153 -- We only deal with the untagged case here, because the tagged case is
10154 -- handled uniformly in the expander.
10156 elsif Is_Record_Type
(Utyp
) and then not Is_Tagged_Type
(Utyp
) then
10158 Eq_Id
: constant Entity_Id
:= Get_User_Defined_Equality
(Typ
);
10161 if Present
(Eq_Id
) then
10162 Rewrite_Operator_As_Call
(N
, Eq_Id
);
10166 end Resolve_Membership_Equality
;
10168 ---------------------------
10169 -- Resolve_Membership_Op --
10170 ---------------------------
10172 -- The context can only be a boolean type, and does not determine the
10173 -- arguments. Arguments should be unambiguous, but the preference rule for
10174 -- universal types applies.
10176 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
10177 pragma Assert
(Is_Boolean_Type
(Typ
));
10179 L
: constant Node_Id
:= Left_Opnd
(N
);
10180 R
: constant Node_Id
:= Right_Opnd
(N
);
10183 procedure Resolve_Set_Membership
;
10184 -- Analysis has determined a unique type for the left operand. Use it as
10185 -- the basis to resolve the disjuncts.
10187 ----------------------------
10188 -- Resolve_Set_Membership --
10189 ----------------------------
10191 procedure Resolve_Set_Membership
is
10195 -- If the left operand is overloaded, find type compatible with not
10196 -- overloaded alternative of the right operand.
10198 Alt
:= First
(Alternatives
(N
));
10199 if Is_Overloaded
(L
) then
10201 while Present
(Alt
) loop
10202 if not Is_Overloaded
(Alt
) then
10203 T
:= Intersect_Types
(L
, Alt
);
10210 -- Unclear how to resolve expression if all alternatives are also
10214 Error_Msg_N
("ambiguous expression", N
);
10218 T
:= Intersect_Types
(L
, Alt
);
10223 Alt
:= First
(Alternatives
(N
));
10224 while Present
(Alt
) loop
10226 -- Alternative is an expression, a range
10227 -- or a subtype mark.
10229 if not Is_Entity_Name
(Alt
)
10230 or else not Is_Type
(Entity
(Alt
))
10238 -- Check for duplicates for discrete case
10240 if Is_Discrete_Type
(T
) then
10247 Alts
: array (0 .. List_Length
(Alternatives
(N
))) of Ent
;
10251 -- Loop checking duplicates. This is quadratic, but giant sets
10252 -- are unlikely in this context so it's a reasonable choice.
10255 Alt
:= First
(Alternatives
(N
));
10256 while Present
(Alt
) loop
10257 if Is_OK_Static_Expression
(Alt
)
10258 and then Nkind
(Alt
) in N_Integer_Literal
10259 | N_Character_Literal
10262 Nalts
:= Nalts
+ 1;
10263 Alts
(Nalts
) := (Alt
, Expr_Value
(Alt
));
10265 for J
in 1 .. Nalts
- 1 loop
10266 if Alts
(J
).Val
= Alts
(Nalts
).Val
then
10267 Error_Msg_Sloc
:= Sloc
(Alts
(J
).Alt
);
10268 Error_Msg_N
("duplicate of value given#??", Alt
);
10278 -- RM 4.5.2 (28.1/3) specifies that for types other than records or
10279 -- limited types, evaluation of a membership test uses the predefined
10280 -- equality for the type. This may be confusing to users, and the
10281 -- following warning appears useful for the most common case.
10283 if Is_Scalar_Type
(Etype
(L
))
10284 and then Present
(Get_User_Defined_Equality
(Etype
(L
)))
10287 ("membership test on& uses predefined equality?", N
, Etype
(L
));
10289 ("\even if user-defined equality exists (RM 4.5.2 (28.1/3)?", N
);
10291 end Resolve_Set_Membership
;
10293 -- Start of processing for Resolve_Membership_Op
10296 if L
= Error
or else R
= Error
then
10300 if Present
(Alternatives
(N
)) then
10301 Resolve_Set_Membership
;
10304 elsif not Is_Overloaded
(R
)
10305 and then Is_Universal_Numeric_Type
(Etype
(R
))
10306 and then Is_Overloaded
(L
)
10310 -- If the left operand is of a universal numeric type and the right
10311 -- operand is not, we do not resolve the operands to the tested type
10312 -- but to the universal type instead. If not conforming to the letter,
10313 -- it's conforming to the spirit of the specification of membership
10314 -- tests, which are typically used to guard a specific operation and
10315 -- ought not to fail a check in doing so. Without this, in the case of
10317 -- type Small_Length is range 1 .. 16;
10319 -- function Is_Small_String (S : String) return Boolean is
10321 -- return S'Length in Small_Length;
10324 -- the function Is_Small_String would fail a range check for strings
10325 -- larger than 127 characters.
10327 -- The test on the size is required in GNAT because universal_integer
10328 -- does not cover all the values of all the supported integer types,
10329 -- for example the large values of Long_Long_Long_Unsigned.
10331 elsif not Is_Overloaded
(L
)
10332 and then Is_Universal_Numeric_Type
(Etype
(L
))
10333 and then (Is_Overloaded
(R
)
10335 (not Is_Universal_Numeric_Type
(Etype
(R
))
10337 (not Is_Integer_Type
(Etype
(R
))
10339 RM_Size
(Etype
(R
)) < RM_Size
(Universal_Integer
))))
10343 -- If the right operand is 'Range, we first need to resolve it (to
10344 -- the tested type) so that it is rewritten as an N_Range, before
10345 -- converting its bounds and resolving it again below.
10347 if Nkind
(R
) = N_Attribute_Reference
10348 and then Attribute_Name
(R
) = Name_Range
10353 -- If the right operand is an N_Range, we convert its bounds to the
10354 -- universal type before resolving it.
10356 if Nkind
(R
) = N_Range
then
10358 Make_Range
(Sloc
(R
),
10359 Low_Bound
=> Convert_To
(T
, Low_Bound
(R
)),
10360 High_Bound
=> Convert_To
(T
, High_Bound
(R
))));
10364 -- Ada 2005 (AI-251): Support the following case:
10366 -- type I is interface;
10367 -- type T is tagged ...
10369 -- function Test (O : I'Class) is
10371 -- return O in T'Class.
10374 -- In this case we have nothing else to do. The membership test will be
10375 -- done at run time.
10377 elsif Ada_Version
>= Ada_2005
10378 and then Is_Class_Wide_Type
(Etype
(L
))
10379 and then Is_Interface
(Etype
(L
))
10380 and then not Is_Interface
(Etype
(R
))
10385 T
:= Intersect_Types
(L
, R
);
10388 -- If mixed-mode operations are present and operands are all literal,
10389 -- the only interpretation involves Duration, which is probably not
10390 -- the intention of the programmer.
10392 if T
= Any_Fixed
then
10393 T
:= Unique_Fixed_Point_Type
(N
);
10395 if T
= Any_Type
then
10401 Check_Unset_Reference
(L
);
10403 if Nkind
(R
) = N_Range
10404 and then not Is_Scalar_Type
(T
)
10406 Error_Msg_N
("scalar type required for range", R
);
10409 if Is_Entity_Name
(R
) then
10410 Freeze_Expression
(R
);
10413 Check_Unset_Reference
(R
);
10416 -- Here after resolving membership operation
10420 Eval_Membership_Op
(N
);
10421 end Resolve_Membership_Op
;
10427 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
10428 Loc
: constant Source_Ptr
:= Sloc
(N
);
10431 -- Handle restriction against anonymous null access values This
10432 -- restriction can be turned off using -gnatdj.
10434 -- Ada 2005 (AI-231): Remove restriction
10436 if Ada_Version
< Ada_2005
10437 and then not Debug_Flag_J
10438 and then Ekind
(Typ
) = E_Anonymous_Access_Type
10439 and then Comes_From_Source
(N
)
10441 -- In the common case of a call which uses an explicitly null value
10442 -- for an access parameter, give specialized error message.
10444 if Nkind
(Parent
(N
)) in N_Subprogram_Call
then
10446 ("NULL is not allowed as argument for an access parameter", N
);
10448 -- Standard message for all other cases (are there any?)
10452 ("NULL cannot be of an anonymous access type", N
);
10456 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
10457 -- assignment to a null-excluding object.
10459 if Ada_Version
>= Ada_2005
10460 and then Can_Never_Be_Null
(Typ
)
10461 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
10463 if Inside_Init_Proc
then
10465 -- Decide whether to generate an if_statement around our
10466 -- null-excluding check to avoid them on certain internal object
10467 -- declarations by looking at the type the current Init_Proc
10471 -- if T1b_skip_null_excluding_check then
10472 -- [constraint_error "access check failed"]
10475 if Needs_Conditional_Null_Excluding_Check
10476 (Etype
(First_Formal
(Enclosing_Init_Proc
)))
10479 Make_If_Statement
(Loc
,
10481 Make_Identifier
(Loc
,
10483 (Chars
(Typ
), "_skip_null_excluding_check")),
10486 Make_Raise_Constraint_Error
(Loc
,
10487 Reason
=> CE_Access_Check_Failed
))));
10489 -- Otherwise, simply create the check
10493 Make_Raise_Constraint_Error
(Loc
,
10494 Reason
=> CE_Access_Check_Failed
));
10498 (Compile_Time_Constraint_Error
(N
,
10499 "(Ada 2005) NULL not allowed in null-excluding objects??"),
10500 Make_Raise_Constraint_Error
(Loc
,
10501 Reason
=> CE_Access_Check_Failed
));
10505 -- In a distributed context, null for a remote access to subprogram may
10506 -- need to be replaced with a special record aggregate. In this case,
10507 -- return after having done the transformation.
10509 if (Ekind
(Typ
) = E_Record_Type
10510 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
10511 and then Remote_AST_Null_Value
(N
, Typ
)
10516 -- The null literal takes its type from the context
10518 Set_Etype
(N
, Typ
);
10521 -----------------------
10522 -- Resolve_Op_Concat --
10523 -----------------------
10525 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
10527 -- We wish to avoid deep recursion, because concatenations are often
10528 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
10529 -- operands nonrecursively until we find something that is not a simple
10530 -- concatenation (A in this case). We resolve that, and then walk back
10531 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
10532 -- to do the rest of the work at each level. The Parent pointers allow
10533 -- us to avoid recursion, and thus avoid running out of memory. See also
10534 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
10540 -- The following code is equivalent to:
10542 -- Resolve_Op_Concat_First (NN, Typ);
10543 -- Resolve_Op_Concat_Arg (N, ...);
10544 -- Resolve_Op_Concat_Rest (N, Typ);
10546 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
10547 -- operand is a concatenation.
10549 -- Walk down left operands
10552 Resolve_Op_Concat_First
(NN
, Typ
);
10553 Op1
:= Left_Opnd
(NN
);
10554 exit when not (Nkind
(Op1
) = N_Op_Concat
10555 and then not Is_Array_Type
(Component_Type
(Typ
))
10556 and then Entity
(Op1
) = Entity
(NN
));
10560 -- Now (given the above example) NN is A&B and Op1 is A
10562 -- First resolve Op1 ...
10564 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
10566 -- ... then walk NN back up until we reach N (where we started), calling
10567 -- Resolve_Op_Concat_Rest along the way.
10570 Resolve_Op_Concat_Rest
(NN
, Typ
);
10574 end Resolve_Op_Concat
;
10576 ---------------------------
10577 -- Resolve_Op_Concat_Arg --
10578 ---------------------------
10580 procedure Resolve_Op_Concat_Arg
10586 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10587 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
10590 if In_Instance
then
10592 or else (not Is_Overloaded
(Arg
)
10593 and then Etype
(Arg
) /= Any_Composite
10594 and then Covers
(Ctyp
, Etype
(Arg
)))
10596 Resolve
(Arg
, Ctyp
);
10598 Resolve
(Arg
, Btyp
);
10601 -- If both Array & Array and Array & Component are visible, there is a
10602 -- potential ambiguity that must be reported.
10604 elsif Has_Compatible_Type
(Arg
, Ctyp
) then
10605 if Nkind
(Arg
) = N_Aggregate
10606 and then Is_Composite_Type
(Ctyp
)
10608 if Is_Private_Type
(Ctyp
) then
10609 Resolve
(Arg
, Btyp
);
10611 -- If the operation is user-defined and not overloaded use its
10612 -- profile. The operation may be a renaming, in which case it has
10613 -- been rewritten, and we want the original profile.
10615 elsif not Is_Overloaded
(N
)
10616 and then Comes_From_Source
(Entity
(Original_Node
(N
)))
10617 and then Ekind
(Entity
(Original_Node
(N
))) = E_Function
10621 (Next_Formal
(First_Formal
(Entity
(Original_Node
(N
))))));
10624 -- Otherwise an aggregate may match both the array type and the
10628 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
10629 Set_Etype
(Arg
, Any_Type
);
10633 if Is_Overloaded
(Arg
)
10634 and then Has_Compatible_Type
(Arg
, Typ
)
10635 and then Etype
(Arg
) /= Any_Type
10643 Get_First_Interp
(Arg
, I
, It
);
10645 Get_Next_Interp
(I
, It
);
10647 -- Special-case the error message when the overloading is
10648 -- caused by a function that yields an array and can be
10649 -- called without parameters.
10651 if It
.Nam
= Func
then
10652 Error_Msg_Sloc
:= Sloc
(Func
);
10653 Error_Msg_N
("ambiguous call to function#", Arg
);
10655 ("\\interpretation as call yields&", Arg
, Typ
);
10657 ("\\interpretation as indexing of call yields&",
10661 Error_Msg_N
("ambiguous operand for concatenation!", Arg
);
10663 Get_First_Interp
(Arg
, I
, It
);
10664 while Present
(It
.Nam
) loop
10665 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
10667 if Base_Type
(It
.Typ
) = Btyp
10669 Base_Type
(It
.Typ
) = Base_Type
(Ctyp
)
10671 Error_Msg_N
-- CODEFIX
10672 ("\\possible interpretation#", Arg
);
10675 Get_Next_Interp
(I
, It
);
10681 Resolve
(Arg
, Ctyp
);
10683 if Nkind
(Arg
) = N_String_Literal
then
10684 Set_Etype
(Arg
, Ctyp
);
10686 elsif Is_Scalar_Type
(Etype
(Arg
))
10687 and then Compile_Time_Known_Value
(Arg
)
10689 -- Determine if the out-of-range violation constitutes a
10690 -- warning or an error according to the expression base type,
10691 -- according to Ada 2022 RM 4.9 (35/2).
10693 if Is_Out_Of_Range
(Arg
, Base_Type
(Ctyp
)) then
10694 Apply_Compile_Time_Constraint_Error
10695 (Arg
, "value not in range of}", CE_Range_Check_Failed
,
10696 Ent
=> Base_Type
(Ctyp
),
10697 Typ
=> Base_Type
(Ctyp
));
10699 elsif Is_Out_Of_Range
(Arg
, Ctyp
) then
10700 Apply_Compile_Time_Constraint_Error
10701 (Arg
, "value not in range of}??", CE_Range_Check_Failed
,
10707 if Arg
= Left_Opnd
(N
) then
10708 Set_Is_Component_Left_Opnd
(N
);
10710 Set_Is_Component_Right_Opnd
(N
);
10715 Resolve
(Arg
, Btyp
);
10718 Check_Unset_Reference
(Arg
);
10719 end Resolve_Op_Concat_Arg
;
10721 -----------------------------
10722 -- Resolve_Op_Concat_First --
10723 -----------------------------
10725 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
10726 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10727 Op1
: constant Node_Id
:= Left_Opnd
(N
);
10728 Op2
: constant Node_Id
:= Right_Opnd
(N
);
10731 -- The parser folds an enormous sequence of concatenations of string
10732 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
10733 -- in the right operand. If the expression resolves to a predefined "&"
10734 -- operator, all is well. Otherwise, the parser's folding is wrong, so
10735 -- we give an error. See P_Simple_Expression in Par.Ch4.
10737 if Nkind
(Op2
) = N_String_Literal
10738 and then Is_Folded_In_Parser
(Op2
)
10739 and then Ekind
(Entity
(N
)) = E_Function
10741 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
10742 and then String_Length
(Strval
(Op1
)) = 0);
10743 Error_Msg_N
("too many user-defined concatenations", N
);
10747 Set_Etype
(N
, Btyp
);
10749 if Is_Limited_Composite
(Btyp
) then
10750 Error_Msg_N
("concatenation not available for limited array", N
);
10751 Explain_Limited_Type
(Btyp
, N
);
10753 end Resolve_Op_Concat_First
;
10755 ----------------------------
10756 -- Resolve_Op_Concat_Rest --
10757 ----------------------------
10759 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
10760 Op1
: constant Node_Id
:= Left_Opnd
(N
);
10761 Op2
: constant Node_Id
:= Right_Opnd
(N
);
10764 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
10766 Generate_Operator_Reference
(N
, Typ
);
10768 if Is_String_Type
(Typ
) then
10769 Eval_Concatenation
(N
);
10772 -- If this is not a static concatenation, but the result is a string
10773 -- type (and not an array of strings) ensure that static string operands
10774 -- have their subtypes properly constructed.
10776 if Nkind
(N
) /= N_String_Literal
10777 and then Is_Character_Type
(Component_Type
(Typ
))
10779 Set_String_Literal_Subtype
(Op1
, Typ
);
10780 Set_String_Literal_Subtype
(Op2
, Typ
);
10782 end Resolve_Op_Concat_Rest
;
10784 ----------------------
10785 -- Resolve_Op_Expon --
10786 ----------------------
10788 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
10789 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10792 -- Catch attempts to do fixed-point exponentiation with universal
10793 -- operands, which is a case where the illegality is not caught during
10794 -- normal operator analysis. This is not done in preanalysis mode
10795 -- since the tree is not fully decorated during preanalysis.
10797 if Full_Analysis
then
10798 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
10799 Error_Msg_N
("exponentiation not available for fixed point", N
);
10802 elsif Nkind
(Parent
(N
)) in N_Op
10803 and then Present
(Etype
(Parent
(N
)))
10804 and then Is_Fixed_Point_Type
(Etype
(Parent
(N
)))
10805 and then Etype
(N
) = Universal_Real
10806 and then Comes_From_Source
(N
)
10808 Error_Msg_N
("exponentiation not available for fixed point", N
);
10813 if Ekind
(Entity
(N
)) = E_Function
10814 and then Is_Imported
(Entity
(N
))
10815 and then Is_Intrinsic_Subprogram
(Entity
(N
))
10817 Generate_Reference
(Entity
(N
), N
);
10818 Resolve_Intrinsic_Operator
(N
, Typ
);
10822 if Is_Universal_Numeric_Type
(Etype
(Left_Opnd
(N
))) then
10823 Check_For_Visible_Operator
(N
, B_Typ
);
10826 -- We do the resolution using the base type, because intermediate values
10827 -- in expressions are always of the base type, not a subtype of it.
10829 Resolve
(Left_Opnd
(N
), B_Typ
);
10830 Resolve
(Right_Opnd
(N
), Standard_Integer
);
10832 -- For integer types, right argument must be in Natural range
10834 if Is_Integer_Type
(Typ
) then
10835 Apply_Scalar_Range_Check
(Right_Opnd
(N
), Standard_Natural
);
10838 Check_Unset_Reference
(Left_Opnd
(N
));
10839 Check_Unset_Reference
(Right_Opnd
(N
));
10841 Set_Etype
(N
, B_Typ
);
10842 Generate_Operator_Reference
(N
, B_Typ
);
10844 Analyze_Dimension
(N
);
10846 if Ada_Version
>= Ada_2012
and then Has_Dimension_System
(B_Typ
) then
10847 -- Evaluate the exponentiation operator for dimensioned type
10849 Eval_Op_Expon_For_Dimensioned_Type
(N
, B_Typ
);
10854 -- Set overflow checking bit. Much cleverer code needed here eventually
10855 -- and perhaps the Resolve routines should be separated for the various
10856 -- arithmetic operations, since they will need different processing. ???
10858 if Nkind
(N
) in N_Op
then
10859 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
10860 Enable_Overflow_Check
(N
);
10863 end Resolve_Op_Expon
;
10865 --------------------
10866 -- Resolve_Op_Not --
10867 --------------------
10869 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
10870 function Parent_Is_Boolean
return Boolean;
10871 -- This function determines if the parent node is a boolean operator or
10872 -- operation (comparison op, membership test, or short circuit form) and
10873 -- the not in question is the left operand of this operation. Note that
10874 -- if the not is in parens, then false is returned.
10876 -----------------------
10877 -- Parent_Is_Boolean --
10878 -----------------------
10880 function Parent_Is_Boolean
return Boolean is
10882 return Paren_Count
(N
) = 0
10883 and then Nkind
(Parent
(N
)) in N_Membership_Test
10886 and then Left_Opnd
(Parent
(N
)) = N
;
10887 end Parent_Is_Boolean
;
10893 -- Start of processing for Resolve_Op_Not
10896 -- Predefined operations on scalar types yield the base type. On the
10897 -- other hand, logical operations on arrays yield the type of the
10898 -- arguments (and the context).
10900 if Is_Array_Type
(Typ
) then
10903 B_Typ
:= Base_Type
(Typ
);
10906 -- Straightforward case of incorrect arguments
10908 if not Valid_Boolean_Arg
(Typ
) then
10909 Error_Msg_N
("invalid operand type for operator&", N
);
10910 Set_Etype
(N
, Any_Type
);
10913 -- Special case of probable missing parens
10915 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
10916 if Parent_Is_Boolean
then
10918 ("operand of NOT must be enclosed in parentheses",
10922 ("no modular type available in this context", N
);
10925 Set_Etype
(N
, Any_Type
);
10928 -- OK resolution of NOT
10931 -- Warn if non-boolean types involved. This is a case like not a < b
10932 -- where a and b are modular, where we will get (not a) < b and most
10933 -- likely not (a < b) was intended.
10935 if Warn_On_Questionable_Missing_Parens
10936 and then not Is_Boolean_Type
(Typ
)
10937 and then Parent_Is_Boolean
10939 Error_Msg_N
("?q?not expression should be parenthesized here!", N
);
10942 -- Warn on double negation if checking redundant constructs
10944 if Warn_On_Redundant_Constructs
10945 and then Comes_From_Source
(N
)
10946 and then Comes_From_Source
(Right_Opnd
(N
))
10947 and then Root_Type
(Typ
) = Standard_Boolean
10948 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
10950 Error_Msg_N
("redundant double negation?r?", N
);
10953 -- Complete resolution and evaluation of NOT
10955 Resolve
(Right_Opnd
(N
), B_Typ
);
10956 Check_Unset_Reference
(Right_Opnd
(N
));
10957 Set_Etype
(N
, B_Typ
);
10958 Generate_Operator_Reference
(N
, B_Typ
);
10961 end Resolve_Op_Not
;
10963 -----------------------------
10964 -- Resolve_Operator_Symbol --
10965 -----------------------------
10967 -- Nothing to be done, all resolved already
10969 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
10970 pragma Warnings
(Off
, N
);
10971 pragma Warnings
(Off
, Typ
);
10975 end Resolve_Operator_Symbol
;
10977 ----------------------------------
10978 -- Resolve_Qualified_Expression --
10979 ----------------------------------
10981 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
10982 pragma Warnings
(Off
, Typ
);
10984 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
10985 Expr
: constant Node_Id
:= Expression
(N
);
10988 Resolve
(Expr
, Target_Typ
);
10989 Check_Unset_Reference
(Expr
);
10991 -- A qualified expression requires an exact match of the type, class-
10992 -- wide matching is not allowed. However, if the qualifying type is
10993 -- specific and the expression has a class-wide type, it may still be
10994 -- okay, since it can be the result of the expansion of a call to a
10995 -- dispatching function, so we also have to check class-wideness of the
10996 -- type of the expression's original node.
10998 if (Is_Class_Wide_Type
(Target_Typ
)
11000 (Is_Class_Wide_Type
(Etype
(Expr
))
11001 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
11002 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
11004 Wrong_Type
(Expr
, Target_Typ
);
11007 -- If the target type is unconstrained, then we reset the type of the
11008 -- result from the type of the expression. For other cases, the actual
11009 -- subtype of the expression is the target type. But we avoid doing it
11010 -- for an allocator since this is not needed and might be problematic.
11012 if Is_Composite_Type
(Target_Typ
)
11013 and then not Is_Constrained
(Target_Typ
)
11014 and then Nkind
(Parent
(N
)) /= N_Allocator
11016 Set_Etype
(N
, Etype
(Expr
));
11019 Analyze_Dimension
(N
);
11020 Eval_Qualified_Expression
(N
);
11022 -- If we still have a qualified expression after the static evaluation,
11023 -- then apply a scalar range check if needed. The reason that we do this
11024 -- after the Eval call is that otherwise, the application of the range
11025 -- check may convert an illegal static expression and result in warning
11026 -- rather than giving an error (e.g Integer'(Integer'Last + 1)).
11028 if Nkind
(N
) = N_Qualified_Expression
11029 and then Is_Scalar_Type
(Target_Typ
)
11031 Apply_Scalar_Range_Check
(Expr
, Target_Typ
);
11034 -- AI12-0100: Once the qualified expression is resolved, check whether
11035 -- operand satisfies a static predicate of the target subtype, if any.
11036 -- In the static expression case, a predicate check failure is an error.
11038 if Has_Predicates
(Target_Typ
) then
11039 Check_Expression_Against_Static_Predicate
11040 (Expr
, Target_Typ
, Static_Failure_Is_Error
=> True);
11042 end Resolve_Qualified_Expression
;
11044 ------------------------------
11045 -- Resolve_Raise_Expression --
11046 ------------------------------
11048 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
11050 if Typ
= Raise_Type
then
11051 Error_Msg_N
("cannot find unique type for raise expression", N
);
11052 Set_Etype
(N
, Any_Type
);
11055 Set_Etype
(N
, Typ
);
11057 -- Apply check for required parentheses in the enclosing
11058 -- context of raise_expressions (RM 11.3 (2)), including default
11059 -- expressions in contexts that can include aspect specifications,
11060 -- and ancestor parts of extension aggregates.
11063 Par
: Node_Id
:= Parent
(N
);
11064 Parentheses_Found
: Boolean := Paren_Count
(N
) > 0;
11067 while Present
(Par
)
11068 and then Nkind
(Par
) in N_Has_Etype
11070 if Paren_Count
(Par
) > 0 then
11071 Parentheses_Found
:= True;
11074 if Nkind
(Par
) = N_Extension_Aggregate
11075 and then N
= Ancestor_Part
(Par
)
11080 Par
:= Parent
(Par
);
11083 if not Parentheses_Found
11084 and then Comes_From_Source
(Par
)
11086 (Nkind
(Par
) in N_Modular_Type_Definition
11087 | N_Floating_Point_Definition
11088 | N_Ordinary_Fixed_Point_Definition
11089 | N_Decimal_Fixed_Point_Definition
11090 | N_Extension_Aggregate
11091 | N_Discriminant_Specification
11092 | N_Parameter_Specification
11093 | N_Formal_Object_Declaration
11095 or else (Nkind
(Par
) = N_Object_Declaration
11097 Nkind
(Parent
(Par
)) /= N_Extended_Return_Statement
))
11100 ("raise_expression must be parenthesized in this context",
11105 end Resolve_Raise_Expression
;
11107 -------------------
11108 -- Resolve_Range --
11109 -------------------
11111 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
11112 L
: constant Node_Id
:= Low_Bound
(N
);
11113 H
: constant Node_Id
:= High_Bound
(N
);
11115 function First_Last_Ref
return Boolean;
11116 -- Returns True if N is of the form X'First .. X'Last where X is the
11117 -- same entity for both attributes.
11119 --------------------
11120 -- First_Last_Ref --
11121 --------------------
11123 function First_Last_Ref
return Boolean is
11124 Lorig
: constant Node_Id
:= Original_Node
(L
);
11125 Horig
: constant Node_Id
:= Original_Node
(H
);
11128 if Nkind
(Lorig
) = N_Attribute_Reference
11129 and then Nkind
(Horig
) = N_Attribute_Reference
11130 and then Attribute_Name
(Lorig
) = Name_First
11131 and then Attribute_Name
(Horig
) = Name_Last
11134 PL
: constant Node_Id
:= Prefix
(Lorig
);
11135 PH
: constant Node_Id
:= Prefix
(Horig
);
11137 return Is_Entity_Name
(PL
)
11138 and then Is_Entity_Name
(PH
)
11139 and then Entity
(PL
) = Entity
(PH
);
11144 end First_Last_Ref
;
11146 -- Start of processing for Resolve_Range
11149 Set_Etype
(N
, Typ
);
11154 -- Reanalyze the lower bound after both bounds have been analyzed, so
11155 -- that the range is known to be static or not by now. This may trigger
11156 -- more compile-time evaluation, which is useful for static analysis
11157 -- with GNATprove. This is not needed for compilation or static analysis
11158 -- with CodePeer, as full expansion does that evaluation then.
11160 if GNATprove_Mode
then
11161 Set_Analyzed
(L
, False);
11165 -- Check for inappropriate range on unordered enumeration type
11167 if Bad_Unordered_Enumeration_Reference
(N
, Typ
)
11169 -- Exclude X'First .. X'Last if X is the same entity for both
11171 and then not First_Last_Ref
11173 Error_Msg_Sloc
:= Sloc
(Typ
);
11175 ("subrange of unordered enumeration type& declared#?.u?", N
, Typ
);
11178 Check_Unset_Reference
(L
);
11179 Check_Unset_Reference
(H
);
11181 -- We have to check the bounds for being within the base range as
11182 -- required for a non-static context. Normally this is automatic and
11183 -- done as part of evaluating expressions, but the N_Range node is an
11184 -- exception, since in GNAT we consider this node to be a subexpression,
11185 -- even though in Ada it is not. The circuit in Sem_Eval could check for
11186 -- this, but that would put the test on the main evaluation path for
11189 Check_Non_Static_Context
(L
);
11190 Check_Non_Static_Context
(H
);
11192 -- Check for an ambiguous range over character literals. This will
11193 -- happen with a membership test involving only literals.
11195 if Typ
= Any_Character
then
11196 Ambiguous_Character
(L
);
11197 Set_Etype
(N
, Any_Type
);
11201 -- If bounds are static, constant-fold them, so size computations are
11202 -- identical between front-end and back-end. Do not perform this
11203 -- transformation while analyzing generic units, as type information
11204 -- would be lost when reanalyzing the constant node in the instance.
11206 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
11207 if Is_OK_Static_Expression
(L
) then
11208 Fold_Uint
(L
, Expr_Value
(L
), Static
=> True);
11211 if Is_OK_Static_Expression
(H
) then
11212 Fold_Uint
(H
, Expr_Value
(H
), Static
=> True);
11216 -- If we have a compile-time-known null range, we warn, because that is
11217 -- likely to be a mistake. (Dynamic null ranges make sense, but often
11218 -- compile-time-known ones do not.) Warn only if this is in a subtype
11219 -- declaration. We do this here, rather than while analyzing a subtype
11220 -- declaration, in case we decide to expand the cases. We do not want to
11221 -- warn in all cases, because some are idiomatic, such as an empty
11222 -- aggregate (1 .. 0 => <>).
11224 -- We don't warn in generics or their instances, because there might be
11225 -- some instances where the range is null, and some where it is not,
11226 -- which would lead to false alarms.
11228 if not (Inside_A_Generic
or In_Instance
)
11229 and then Comes_From_Source
(N
)
11230 and then Compile_Time_Compare
11231 (Low_Bound
(N
), High_Bound
(N
), Assume_Valid
=> True) = GT
11232 and then Nkind
(Parent
(N
)) = N_Range_Constraint
11233 and then Nkind
(Parent
(Parent
(N
))) = N_Subtype_Indication
11234 and then Nkind
(Parent
(Parent
(Parent
(N
)))) = N_Subtype_Declaration
11235 and then Is_OK_Static_Range
(N
)
11237 Error_Msg_N
("null range??", N
);
11241 --------------------------
11242 -- Resolve_Real_Literal --
11243 --------------------------
11245 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
11246 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
11249 -- Special processing for fixed-point literals to make sure that the
11250 -- value is an exact multiple of the small where this is required. We
11251 -- skip this for the universal real case, and also for generic types.
11253 if Is_Fixed_Point_Type
(Typ
)
11254 and then Typ
/= Universal_Fixed
11255 and then Typ
/= Any_Fixed
11256 and then not Is_Generic_Type
(Typ
)
11258 -- We must freeze the base type to get the proper value of the small
11260 if not Is_Frozen
(Base_Type
(Typ
)) then
11261 Freeze_Fixed_Point_Type
(Base_Type
(Typ
));
11265 Val
: constant Ureal
:= Realval
(N
);
11266 Cintr
: constant Ureal
:= Val
/ Small_Value
(Base_Type
(Typ
));
11267 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
11268 Den
: constant Uint
:= Norm_Den
(Cintr
);
11272 -- Case of literal is not an exact multiple of the Small
11276 -- For a source program literal for a decimal fixed-point type,
11277 -- this is statically illegal (RM 4.9(36)).
11279 if Is_Decimal_Fixed_Point_Type
(Typ
)
11280 and then Actual_Typ
= Universal_Real
11281 and then Comes_From_Source
(N
)
11283 Error_Msg_N
("value has extraneous low order digits", N
);
11286 -- Generate a warning if literal from source
11288 if Is_OK_Static_Expression
(N
)
11289 and then Warn_On_Bad_Fixed_Value
11292 ("?b?static fixed-point value is not a multiple of Small!",
11296 -- Replace literal by a value that is the exact representation
11297 -- of a value of the type, i.e. a multiple of the small value,
11298 -- by truncation, since Machine_Rounds is false for all GNAT
11299 -- fixed-point types (RM 4.9(38)).
11301 Stat
:= Is_OK_Static_Expression
(N
);
11303 Make_Real_Literal
(Sloc
(N
),
11304 Realval
=> Small_Value
(Typ
) * Cint
));
11306 Set_Is_Static_Expression
(N
, Stat
);
11309 -- In all cases, set the corresponding integer field
11311 Set_Corresponding_Integer_Value
(N
, Cint
);
11315 -- Now replace the actual type by the expected type as usual
11317 Set_Etype
(N
, Typ
);
11318 Eval_Real_Literal
(N
);
11319 end Resolve_Real_Literal
;
11321 -----------------------
11322 -- Resolve_Reference --
11323 -----------------------
11325 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
11326 P
: constant Node_Id
:= Prefix
(N
);
11329 -- Replace general access with specific type
11331 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
11332 Set_Etype
(N
, Base_Type
(Typ
));
11335 Resolve
(P
, Designated_Type
(Etype
(N
)));
11337 -- If we are taking the reference of a volatile entity, then treat it as
11338 -- a potential modification of this entity. This is too conservative,
11339 -- but necessary because remove side effects can cause transformations
11340 -- of normal assignments into reference sequences that otherwise fail to
11341 -- notice the modification.
11343 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
11344 Note_Possible_Modification
(P
, Sure
=> False);
11346 end Resolve_Reference
;
11348 --------------------------------
11349 -- Resolve_Selected_Component --
11350 --------------------------------
11352 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
11354 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
11355 P
: constant Node_Id
:= Prefix
(N
);
11356 S
: constant Node_Id
:= Selector_Name
(N
);
11357 T
: Entity_Id
:= Etype
(P
);
11359 I1
: Interp_Index
:= 0; -- prevent junk warning
11364 function Init_Component
return Boolean;
11365 -- Check whether this is the initialization of a component within an
11366 -- init proc (by assignment or call to another init proc). If true,
11367 -- there is no need for a discriminant check.
11369 --------------------
11370 -- Init_Component --
11371 --------------------
11373 function Init_Component
return Boolean is
11375 return Inside_Init_Proc
11376 and then Nkind
(Prefix
(N
)) = N_Identifier
11377 and then Chars
(Prefix
(N
)) = Name_uInit
11378 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
11379 end Init_Component
;
11381 -- Start of processing for Resolve_Selected_Component
11384 if Is_Overloaded
(P
) then
11386 -- Use the context type to select the prefix that has a selector
11387 -- of the correct name and type.
11390 Get_First_Interp
(P
, I
, It
);
11392 Search
: while Present
(It
.Typ
) loop
11393 if Is_Access_Type
(It
.Typ
) then
11394 T
:= Designated_Type
(It
.Typ
);
11399 -- Locate selected component. For a private prefix the selector
11400 -- can denote a discriminant.
11402 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
11404 -- The visible components of a class-wide type are those of
11407 if Is_Class_Wide_Type
(T
) then
11411 Comp
:= First_Entity
(T
);
11412 while Present
(Comp
) loop
11413 if Chars
(Comp
) = Chars
(S
)
11414 and then Covers
(Typ
, Etype
(Comp
))
11423 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
11425 if It
= No_Interp
then
11427 ("ambiguous prefix for selected component", N
);
11428 Set_Etype
(N
, Typ
);
11434 -- There may be an implicit dereference. Retrieve
11435 -- designated record type.
11437 if Is_Access_Type
(It1
.Typ
) then
11438 T
:= Designated_Type
(It1
.Typ
);
11443 if Scope
(Comp1
) /= T
then
11445 -- Resolution chooses the new interpretation.
11446 -- Find the component with the right name.
11448 Comp1
:= First_Entity
(T
);
11449 while Present
(Comp1
)
11450 and then Chars
(Comp1
) /= Chars
(S
)
11452 Next_Entity
(Comp1
);
11461 Next_Entity
(Comp
);
11465 Get_Next_Interp
(I
, It
);
11468 -- There must be a legal interpretation at this point
11470 pragma Assert
(Found
);
11471 Resolve
(P
, It1
.Typ
);
11473 -- In general the expected type is the type of the context, not the
11474 -- type of the candidate selected component.
11476 Set_Etype
(N
, Typ
);
11477 Set_Entity_With_Checks
(S
, Comp1
);
11479 -- The type of the context and that of the component are
11480 -- compatible and in general identical, but if they are anonymous
11481 -- access-to-subprogram types, the relevant type is that of the
11482 -- component. This matters in Unnest_Subprograms mode, where the
11483 -- relevant context is the one in which the type is declared, not
11484 -- the point of use. This determines what activation record to use.
11486 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
11487 Set_Etype
(N
, Etype
(Comp1
));
11489 -- When the type of the component is an access to a class-wide type
11490 -- the relevant type is that of the component (since in such case we
11491 -- may need to generate implicit type conversions or dispatching
11494 elsif Is_Access_Type
(Typ
)
11495 and then not Is_Class_Wide_Type
(Designated_Type
(Typ
))
11496 and then Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp1
)))
11498 Set_Etype
(N
, Etype
(Comp1
));
11502 -- Resolve prefix with its type
11507 -- Generate cross-reference. We needed to wait until full overloading
11508 -- resolution was complete to do this, since otherwise we can't tell if
11509 -- we are an lvalue or not.
11511 if Known_To_Be_Assigned
(N
) then
11512 Generate_Reference
(Entity
(S
), S
, 'm');
11514 Generate_Reference
(Entity
(S
), S
, 'r');
11517 -- If the prefix's type is an access type, get to the real record type.
11518 -- Note: we do not apply an access check because an explicit dereference
11519 -- will be introduced later, and the check will happen there.
11521 if Is_Access_Type
(Etype
(P
)) then
11522 T
:= Implicitly_Designated_Type
(Etype
(P
));
11523 Check_Fully_Declared_Prefix
(T
, P
);
11529 -- Set flag for expander if discriminant check required on a component
11530 -- appearing within a variant.
11532 if Has_Discriminants
(T
)
11533 and then Ekind
(Entity
(S
)) = E_Component
11534 and then Present
(Original_Record_Component
(Entity
(S
)))
11535 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
11537 Is_Declared_Within_Variant
(Original_Record_Component
(Entity
(S
)))
11538 and then not Discriminant_Checks_Suppressed
(T
)
11539 and then not Init_Component
11541 Set_Do_Discriminant_Check
(N
);
11544 if Ekind
(Entity
(S
)) = E_Void
then
11545 Error_Msg_N
("premature use of component", S
);
11548 -- If the prefix is a record conversion, this may be a renamed
11549 -- discriminant whose bounds differ from those of the original
11550 -- one, so we must ensure that a range check is performed.
11552 if Nkind
(P
) = N_Type_Conversion
11553 and then Ekind
(Entity
(S
)) = E_Discriminant
11554 and then Is_Discrete_Type
(Typ
)
11556 Set_Etype
(N
, Base_Type
(Typ
));
11559 -- Eval_Selected_Component may e.g. fold statically known discriminants.
11561 Eval_Selected_Component
(N
);
11563 if Nkind
(N
) = N_Selected_Component
then
11565 -- If the record type is atomic and the component is not, then this
11566 -- is worth a warning before Ada 2022, since we have a situation
11567 -- where the access to the component may cause extra read/writes of
11568 -- the atomic object, or partial word accesses, both of which may be
11571 if Is_Atomic_Non_VFA_Ref_With_Address
(N
)
11572 and then not Is_Atomic
(Entity
(S
))
11573 and then not Is_Atomic
(Etype
(Entity
(S
)))
11574 and then Ada_Version
< Ada_2022
11577 ("??access to non-atomic component of atomic record",
11580 ("\??may cause unexpected accesses to atomic object",
11584 Resolve_Implicit_Dereference
(Prefix
(N
));
11585 Analyze_Dimension
(N
);
11587 end Resolve_Selected_Component
;
11589 -------------------
11590 -- Resolve_Shift --
11591 -------------------
11593 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
11594 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11595 L
: constant Node_Id
:= Left_Opnd
(N
);
11596 R
: constant Node_Id
:= Right_Opnd
(N
);
11599 -- We do the resolution using the base type, because intermediate values
11600 -- in expressions always are of the base type, not a subtype of it.
11602 Resolve
(L
, B_Typ
);
11603 Resolve
(R
, Standard_Natural
);
11605 Check_Unset_Reference
(L
);
11606 Check_Unset_Reference
(R
);
11608 Set_Etype
(N
, B_Typ
);
11609 Generate_Operator_Reference
(N
, B_Typ
);
11613 ---------------------------
11614 -- Resolve_Short_Circuit --
11615 ---------------------------
11617 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
11618 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11619 L
: constant Node_Id
:= Left_Opnd
(N
);
11620 R
: constant Node_Id
:= Right_Opnd
(N
);
11623 -- Ensure all actions associated with the left operand (e.g.
11624 -- finalization of transient objects) are fully evaluated locally within
11625 -- an expression with actions. This is particularly helpful for coverage
11626 -- analysis at the object level. However this should not happen in
11629 if Expander_Active
then
11631 Reloc_L
: constant Node_Id
:= Relocate_Node
(L
);
11633 Save_Interps
(Old_N
=> L
, New_N
=> Reloc_L
);
11636 Make_Expression_With_Actions
(Sloc
(L
),
11637 Actions
=> New_List
,
11638 Expression
=> Reloc_L
));
11640 -- Set Comes_From_Source on L to preserve warnings for unset
11643 Preserve_Comes_From_Source
(L
, Reloc_L
);
11647 Resolve
(L
, B_Typ
);
11648 Resolve
(R
, B_Typ
);
11650 -- Check for issuing warning for always False assert/check, this happens
11651 -- when assertions are turned off, in which case the pragma Assert/Check
11652 -- was transformed into:
11654 -- if False and then <condition> then ...
11656 -- and we detect this pattern
11658 if Warn_On_Assertion_Failure
11659 and then Is_Entity_Name
(R
)
11660 and then Entity
(R
) = Standard_False
11661 and then Nkind
(Parent
(N
)) = N_If_Statement
11662 and then Nkind
(N
) = N_And_Then
11663 and then Is_Entity_Name
(L
)
11664 and then Entity
(L
) = Standard_False
11667 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
11670 -- Special handling of Asssert pragma
11672 if Nkind
(Orig
) = N_Pragma
11673 and then Pragma_Name
(Orig
) = Name_Assert
11676 Expr
: constant Node_Id
:=
11679 (First
(Pragma_Argument_Associations
(Orig
))));
11682 -- Don't warn if original condition is explicit False,
11683 -- since obviously the failure is expected in this case.
11685 if Is_Entity_Name
(Expr
)
11686 and then Entity
(Expr
) = Standard_False
11690 -- Issue warning. We do not want the deletion of the
11691 -- IF/AND-THEN to take this message with it. We achieve this
11692 -- by making sure that the expanded code points to the Sloc
11693 -- of the expression, not the original pragma.
11696 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
11697 -- The source location of the expression is not usually
11698 -- the best choice here. For example, it gets located on
11699 -- the last AND keyword in a chain of boolean expressiond
11700 -- AND'ed together. It is best to put the message on the
11701 -- first character of the assertion, which is the effect
11702 -- of the First_Node call here.
11705 ("?.a?assertion would fail at run time!",
11707 (First
(Pragma_Argument_Associations
(Orig
))));
11711 -- Similar processing for Check pragma
11713 elsif Nkind
(Orig
) = N_Pragma
11714 and then Pragma_Name
(Orig
) = Name_Check
11716 -- Don't want to warn if original condition is explicit False
11719 Expr
: constant Node_Id
:=
11722 (Next
(First
(Pragma_Argument_Associations
(Orig
)))));
11724 if Is_Entity_Name
(Expr
)
11725 and then Entity
(Expr
) = Standard_False
11732 -- Again use Error_Msg_F rather than Error_Msg_N, see
11733 -- comment above for an explanation of why we do this.
11736 ("?.a?check would fail at run time!",
11738 (Last
(Pragma_Argument_Associations
(Orig
))));
11745 -- Continue with processing of short circuit
11747 Check_Unset_Reference
(L
);
11748 Check_Unset_Reference
(R
);
11750 Set_Etype
(N
, B_Typ
);
11751 Eval_Short_Circuit
(N
);
11752 end Resolve_Short_Circuit
;
11754 -------------------
11755 -- Resolve_Slice --
11756 -------------------
11758 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
11759 Drange
: constant Node_Id
:= Discrete_Range
(N
);
11760 Pref
: constant Node_Id
:= Prefix
(N
);
11761 Array_Type
: Entity_Id
:= Empty
;
11762 Dexpr
: Node_Id
:= Empty
;
11763 Index_Type
: Entity_Id
;
11766 if Is_Overloaded
(Pref
) then
11768 -- Use the context type to select the prefix that yields the correct
11773 I1
: Interp_Index
:= 0;
11775 Found
: Boolean := False;
11778 Get_First_Interp
(Pref
, I
, It
);
11779 while Present
(It
.Typ
) loop
11780 if (Is_Array_Type
(It
.Typ
)
11781 and then Covers
(Typ
, It
.Typ
))
11782 or else (Is_Access_Type
(It
.Typ
)
11783 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
11784 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
11787 It
:= Disambiguate
(Pref
, I1
, I
, Any_Type
);
11789 if It
= No_Interp
then
11790 Error_Msg_N
("ambiguous prefix for slicing", N
);
11791 Set_Etype
(N
, Typ
);
11795 Array_Type
:= It
.Typ
;
11800 Array_Type
:= It
.Typ
;
11805 Get_Next_Interp
(I
, It
);
11810 Array_Type
:= Etype
(Pref
);
11813 Resolve
(Pref
, Array_Type
);
11815 -- If the prefix's type is an access type, get to the real array type.
11816 -- Note: we do not apply an access check because an explicit dereference
11817 -- will be introduced later, and the check will happen there.
11819 if Is_Access_Type
(Array_Type
) then
11820 Array_Type
:= Implicitly_Designated_Type
(Array_Type
);
11822 -- If the prefix is an access to an unconstrained array, we must use
11823 -- the actual subtype of the object to perform the index checks. The
11824 -- object denoted by the prefix is implicit in the node, so we build
11825 -- an explicit representation for it in order to compute the actual
11828 if not Is_Constrained
(Array_Type
) then
11829 Remove_Side_Effects
(Pref
);
11832 Obj
: constant Node_Id
:=
11833 Make_Explicit_Dereference
(Sloc
(N
),
11834 Prefix
=> New_Copy_Tree
(Pref
));
11836 Set_Etype
(Obj
, Array_Type
);
11837 Set_Parent
(Obj
, Parent
(N
));
11838 Array_Type
:= Get_Actual_Subtype
(Obj
);
11842 -- In CodePeer mode the attribute Image is not expanded, so when it
11843 -- acts as a prefix of a slice, we handle it like a call to function
11844 -- returning an unconstrained string. Same for the Wide variants of
11845 -- attribute Image.
11847 elsif Is_Entity_Name
(Pref
)
11848 or else Nkind
(Pref
) = N_Explicit_Dereference
11849 or else (Nkind
(Pref
) = N_Function_Call
11850 and then not Is_Constrained
(Etype
(Pref
)))
11851 or else (CodePeer_Mode
11852 and then Nkind
(Pref
) = N_Attribute_Reference
11853 and then Attribute_Name
(Pref
) in Name_Image
11855 | Name_Wide_Wide_Image
)
11857 Array_Type
:= Get_Actual_Subtype
(Pref
);
11859 -- If the name is a selected component that depends on discriminants,
11860 -- build an actual subtype for it. This can happen only when the name
11861 -- itself is overloaded; otherwise the actual subtype is created when
11862 -- the selected component is analyzed.
11864 elsif Nkind
(Pref
) = N_Selected_Component
11865 and then Full_Analysis
11866 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
11869 Act_Decl
: constant Node_Id
:=
11870 Build_Actual_Subtype_Of_Component
(Array_Type
, Pref
);
11872 Insert_Action
(N
, Act_Decl
);
11873 Array_Type
:= Defining_Identifier
(Act_Decl
);
11876 -- Maybe this should just be "else", instead of checking for the
11877 -- specific case of slice??? This is needed for the case where the
11878 -- prefix is an Image attribute, which gets expanded to a slice, and so
11879 -- has a constrained subtype which we want to use for the slice range
11880 -- check applied below (the range check won't get done if the
11881 -- unconstrained subtype of the 'Image is used).
11883 elsif Nkind
(Pref
) = N_Slice
then
11884 Array_Type
:= Etype
(Pref
);
11887 -- Obtain the type of the array index
11889 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
11890 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
11892 Index_Type
:= Etype
(First_Index
(Array_Type
));
11895 -- If name was overloaded, set slice type correctly now
11897 Set_Etype
(N
, Array_Type
);
11899 -- Handle the generation of a range check that compares the array index
11900 -- against the discrete_range. The check is not applied to internally
11901 -- built nodes associated with the expansion of dispatch tables. Check
11902 -- that Ada.Tags has already been loaded to avoid extra dependencies on
11905 if Tagged_Type_Expansion
11906 and then RTU_Loaded
(Ada_Tags
)
11907 and then Nkind
(Pref
) = N_Selected_Component
11908 and then Present
(Entity
(Selector_Name
(Pref
)))
11909 and then Entity
(Selector_Name
(Pref
)) =
11910 RTE_Record_Component
(RE_Prims_Ptr
)
11914 -- The discrete_range is specified by a subtype name. Create an
11915 -- equivalent range attribute, apply checks to this attribute, but
11916 -- insert them into the range expression of the slice itself.
11918 elsif Is_Entity_Name
(Drange
) then
11920 Make_Attribute_Reference
11923 New_Occurrence_Of
(Entity
(Drange
), Sloc
(Drange
)),
11924 Attribute_Name
=> Name_Range
);
11926 Analyze_And_Resolve
(Dexpr
, Etype
(Drange
));
11928 elsif Nkind
(Drange
) = N_Subtype_Indication
then
11929 Dexpr
:= Range_Expression
(Constraint
(Drange
));
11931 -- The discrete_range is a regular range (or a range attribute, which
11932 -- will be resolved into a regular range). Resolve the bounds and remove
11933 -- their side effects.
11936 Resolve
(Drange
, Base_Type
(Index_Type
));
11938 if Nkind
(Drange
) = N_Range
then
11939 Force_Evaluation
(Low_Bound
(Drange
));
11940 Force_Evaluation
(High_Bound
(Drange
));
11946 if Present
(Dexpr
) then
11947 Apply_Range_Check
(Dexpr
, Index_Type
, Insert_Node
=> Drange
);
11950 Set_Slice_Subtype
(N
);
11952 -- Check bad use of type with predicates
11958 if Nkind
(Drange
) = N_Subtype_Indication
11959 and then Has_Predicates
(Entity
(Subtype_Mark
(Drange
)))
11961 Subt
:= Entity
(Subtype_Mark
(Drange
));
11963 Subt
:= Etype
(Drange
);
11966 if Has_Predicates
(Subt
) then
11967 Bad_Predicated_Subtype_Use
11968 ("subtype& has predicate, not allowed in slice", Drange
, Subt
);
11972 -- Otherwise here is where we check suspicious indexes
11974 if Nkind
(Drange
) = N_Range
then
11975 Warn_On_Suspicious_Index
(Pref
, Low_Bound
(Drange
));
11976 Warn_On_Suspicious_Index
(Pref
, High_Bound
(Drange
));
11979 Resolve_Implicit_Dereference
(Pref
);
11980 Analyze_Dimension
(N
);
11984 ----------------------------
11985 -- Resolve_String_Literal --
11986 ----------------------------
11988 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
11989 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
11990 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
11991 Loc
: constant Source_Ptr
:= Sloc
(N
);
11992 Str
: constant String_Id
:= Strval
(N
);
11993 Strlen
: constant Nat
:= String_Length
(Str
);
11994 Subtype_Id
: Entity_Id
;
11995 Need_Check
: Boolean;
11998 -- For a string appearing in a concatenation, defer creation of the
11999 -- string_literal_subtype until the end of the resolution of the
12000 -- concatenation, because the literal may be constant-folded away. This
12001 -- is a useful optimization for long concatenation expressions.
12003 -- If the string is an aggregate built for a single character (which
12004 -- happens in a non-static context) or a is null string to which special
12005 -- checks may apply, we build the subtype. Wide strings must also get a
12006 -- string subtype if they come from a one character aggregate. Strings
12007 -- generated by attributes might be static, but it is often hard to
12008 -- determine whether the enclosing context is static, so we generate
12009 -- subtypes for them as well, thus losing some rarer optimizations ???
12010 -- Same for strings that come from a static conversion.
12013 (Strlen
= 0 and then Typ
/= Standard_String
)
12014 or else Nkind
(Parent
(N
)) /= N_Op_Concat
12015 or else (N
/= Left_Opnd
(Parent
(N
))
12016 and then N
/= Right_Opnd
(Parent
(N
)))
12017 or else ((Typ
= Standard_Wide_String
12018 or else Typ
= Standard_Wide_Wide_String
)
12019 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
12021 -- If the resolving type is itself a string literal subtype, we can just
12022 -- reuse it, since there is no point in creating another.
12024 if Ekind
(Typ
) = E_String_Literal_Subtype
then
12027 elsif Nkind
(Parent
(N
)) = N_Op_Concat
12028 and then not Need_Check
12029 and then Nkind
(Original_Node
(N
)) not in N_Character_Literal
12030 | N_Attribute_Reference
12031 | N_Qualified_Expression
12032 | N_Type_Conversion
12036 -- Do not generate a string literal subtype for the default expression
12037 -- of a formal parameter in GNATprove mode. This is because the string
12038 -- subtype is associated with the freezing actions of the subprogram,
12039 -- however freezing is disabled in GNATprove mode and as a result the
12040 -- subtype is unavailable.
12042 elsif GNATprove_Mode
12043 and then Nkind
(Parent
(N
)) = N_Parameter_Specification
12047 -- Otherwise we must create a string literal subtype. Note that the
12048 -- whole idea of string literal subtypes is simply to avoid the need
12049 -- for building a full fledged array subtype for each literal.
12052 Set_String_Literal_Subtype
(N
, Typ
);
12053 Subtype_Id
:= Etype
(N
);
12056 if Nkind
(Parent
(N
)) /= N_Op_Concat
12059 Set_Etype
(N
, Subtype_Id
);
12060 Eval_String_Literal
(N
);
12063 if Is_Limited_Composite
(Typ
)
12064 or else Is_Private_Composite
(Typ
)
12066 Error_Msg_N
("string literal not available for private array", N
);
12067 Set_Etype
(N
, Any_Type
);
12071 -- The validity of a null string has been checked in the call to
12072 -- Eval_String_Literal.
12077 -- Always accept string literal with component type Any_Character, which
12078 -- occurs in error situations and in comparisons of literals, both of
12079 -- which should accept all literals.
12081 elsif R_Typ
= Any_Character
then
12084 -- If the type is bit-packed, then we always transform the string
12085 -- literal into a full fledged aggregate.
12087 elsif Is_Bit_Packed_Array
(Typ
) then
12090 -- Deal with cases of Wide_Wide_String, Wide_String, and String
12093 -- For Standard.Wide_Wide_String, or any other type whose component
12094 -- type is Standard.Wide_Wide_Character, we know that all the
12095 -- characters in the string must be acceptable, since the parser
12096 -- accepted the characters as valid character literals.
12098 if R_Typ
= Standard_Wide_Wide_Character
then
12101 -- For the case of Standard.String, or any other type whose component
12102 -- type is Standard.Character, we must make sure that there are no
12103 -- wide characters in the string, i.e. that it is entirely composed
12104 -- of characters in range of type Character.
12106 -- If the string literal is the result of a static concatenation, the
12107 -- test has already been performed on the components, and need not be
12110 elsif R_Typ
= Standard_Character
12111 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
12113 for J
in 1 .. Strlen
loop
12114 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
12116 -- If we are out of range, post error. This is one of the
12117 -- very few places that we place the flag in the middle of
12118 -- a token, right under the offending wide character. Not
12119 -- quite clear if this is right wrt wide character encoding
12120 -- sequences, but it's only an error message.
12123 ("literal out of range of type Standard.Character",
12124 Loc
+ Source_Ptr
(J
));
12129 -- For the case of Standard.Wide_String, or any other type whose
12130 -- component type is Standard.Wide_Character, we must make sure that
12131 -- there are no wide characters in the string, i.e. that it is
12132 -- entirely composed of characters in range of type Wide_Character.
12134 -- If the string literal is the result of a static concatenation,
12135 -- the test has already been performed on the components, and need
12136 -- not be repeated.
12138 elsif R_Typ
= Standard_Wide_Character
12139 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
12141 for J
in 1 .. Strlen
loop
12142 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
12144 -- If we are out of range, post error. This is one of the
12145 -- very few places that we place the flag in the middle of
12146 -- a token, right under the offending wide character.
12148 -- This is not quite right, because characters in general
12149 -- will take more than one character position ???
12152 ("literal out of range of type Standard.Wide_Character",
12153 Loc
+ Source_Ptr
(J
));
12158 -- If the root type is not a standard character, then we will convert
12159 -- the string into an aggregate and will let the aggregate code do
12160 -- the checking. Standard Wide_Wide_Character is also OK here.
12166 -- See if the component type of the array corresponding to the string
12167 -- has compile time known bounds. If yes we can directly check
12168 -- whether the evaluation of the string will raise constraint error.
12169 -- Otherwise we need to transform the string literal into the
12170 -- corresponding character aggregate and let the aggregate code do
12171 -- the checking. We use the same transformation if the component
12172 -- type has a static predicate, which will be applied to each
12173 -- character when the aggregate is resolved.
12175 if Is_Standard_Character_Type
(R_Typ
) then
12177 -- Check for the case of full range, where we are definitely OK
12179 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
12183 -- Here the range is not the complete base type range, so check
12186 Comp_Typ_Lo
: constant Node_Id
:=
12187 Type_Low_Bound
(Component_Type
(Typ
));
12188 Comp_Typ_Hi
: constant Node_Id
:=
12189 Type_High_Bound
(Component_Type
(Typ
));
12194 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
12195 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
12197 for J
in 1 .. Strlen
loop
12198 Char_Val
:= UI_From_CC
(Get_String_Char
(Str
, J
));
12200 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
12201 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
12203 Apply_Compile_Time_Constraint_Error
12204 (N
, "character out of range??",
12205 CE_Range_Check_Failed
,
12206 Loc
=> Loc
+ Source_Ptr
(J
));
12210 if not Has_Static_Predicate
(C_Typ
) then
12218 -- If we got here we meed to transform the string literal into the
12219 -- equivalent qualified positional array aggregate. This is rather
12220 -- heavy artillery for this situation, but it is hard work to avoid.
12223 Lits
: constant List_Id
:= New_List
;
12224 P
: Source_Ptr
:= Loc
+ 1;
12228 -- Build the character literals, we give them source locations that
12229 -- correspond to the string positions, which is a bit tricky given
12230 -- the possible presence of wide character escape sequences.
12232 for J
in 1 .. Strlen
loop
12233 C
:= Get_String_Char
(Str
, J
);
12234 Set_Character_Literal_Name
(C
);
12237 Make_Character_Literal
(P
,
12238 Chars
=> Name_Find
,
12239 Char_Literal_Value
=> UI_From_CC
(C
)));
12241 if In_Character_Range
(C
) then
12244 -- Should we have a call to Skip_Wide here ???
12253 Make_Qualified_Expression
(Loc
,
12254 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
12256 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
12258 Analyze_And_Resolve
(N
, Typ
);
12260 end Resolve_String_Literal
;
12262 -------------------------
12263 -- Resolve_Target_Name --
12264 -------------------------
12266 procedure Resolve_Target_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
12268 Set_Etype
(N
, Typ
);
12269 end Resolve_Target_Name
;
12271 -----------------------------
12272 -- Resolve_Type_Conversion --
12273 -----------------------------
12275 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
12276 Conv_OK
: constant Boolean := Conversion_OK
(N
);
12277 Operand
: constant Node_Id
:= Expression
(N
);
12278 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
12279 Target_Typ
: constant Entity_Id
:= Etype
(N
);
12284 Test_Redundant
: Boolean := Warn_On_Redundant_Constructs
;
12285 -- Set to False to suppress cases where we want to suppress the test
12286 -- for redundancy to avoid possible false positives on this warning.
12290 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
12295 -- If the Operand Etype is Universal_Fixed, then the conversion is
12296 -- never redundant. We need this check because by the time we have
12297 -- finished the rather complex transformation, the conversion looks
12298 -- redundant when it is not.
12300 if Operand_Typ
= Universal_Fixed
then
12301 Test_Redundant
:= False;
12303 -- If the operand is marked as Any_Fixed, then special processing is
12304 -- required. This is also a case where we suppress the test for a
12305 -- redundant conversion, since most certainly it is not redundant.
12307 elsif Operand_Typ
= Any_Fixed
then
12308 Test_Redundant
:= False;
12310 -- Mixed-mode operation involving a literal. Context must be a fixed
12311 -- type which is applied to the literal subsequently.
12313 -- Multiplication and division involving two fixed type operands must
12314 -- yield a universal real because the result is computed in arbitrary
12317 if Is_Fixed_Point_Type
(Typ
)
12318 and then Nkind
(Operand
) in N_Op_Divide | N_Op_Multiply
12319 and then Etype
(Left_Opnd
(Operand
)) = Any_Fixed
12320 and then Etype
(Right_Opnd
(Operand
)) = Any_Fixed
12322 Set_Etype
(Operand
, Universal_Real
);
12324 elsif Is_Numeric_Type
(Typ
)
12325 and then Nkind
(Operand
) in N_Op_Multiply | N_Op_Divide
12326 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
12328 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
12330 -- Return if expression is ambiguous
12332 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
12335 -- If nothing else, the available fixed type is Duration
12338 Set_Etype
(Operand
, Standard_Duration
);
12341 -- Resolve the real operand with largest available precision
12343 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
12344 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
12346 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
12349 Resolve
(Rop
, Universal_Real
);
12351 -- If the operand is a literal (it could be a non-static and
12352 -- illegal exponentiation) check whether the use of Duration
12353 -- is potentially inaccurate.
12355 if Nkind
(Rop
) = N_Real_Literal
12356 and then Realval
(Rop
) /= Ureal_0
12357 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
12360 ("??universal real operand can only "
12361 & "be interpreted as Duration!", Rop
);
12363 ("\??precision will be lost in the conversion!", Rop
);
12366 elsif Is_Numeric_Type
(Typ
)
12367 and then Nkind
(Operand
) in N_Op
12368 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
12370 Set_Etype
(Operand
, Standard_Duration
);
12373 Error_Msg_N
("invalid context for mixed mode operation", N
);
12374 Set_Etype
(Operand
, Any_Type
);
12381 Analyze_Dimension
(N
);
12383 -- Note: we do the Eval_Type_Conversion call before applying the
12384 -- required checks for a subtype conversion. This is important, since
12385 -- both are prepared under certain circumstances to change the type
12386 -- conversion to a constraint error node, but in the case of
12387 -- Eval_Type_Conversion this may reflect an illegality in the static
12388 -- case, and we would miss the illegality (getting only a warning
12389 -- message), if we applied the type conversion checks first.
12391 Eval_Type_Conversion
(N
);
12393 -- Even when evaluation is not possible, we may be able to simplify the
12394 -- conversion or its expression. This needs to be done before applying
12395 -- checks, since otherwise the checks may use the original expression
12396 -- and defeat the simplifications. This is specifically the case for
12397 -- elimination of the floating-point Truncation attribute in
12398 -- float-to-int conversions.
12400 Simplify_Type_Conversion
(N
);
12402 -- If after evaluation we still have a type conversion, then we may need
12403 -- to apply checks required for a subtype conversion. But skip them if
12404 -- universal fixed operands are involved, since range checks are handled
12405 -- separately for these cases, after the expansion done by Exp_Fixd.
12407 if Nkind
(N
) = N_Type_Conversion
12408 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
12409 and then Target_Typ
/= Universal_Fixed
12410 and then Etype
(Operand
) /= Universal_Fixed
12412 Apply_Type_Conversion_Checks
(N
);
12415 -- Issue warning for conversion of simple object to its own type. We
12416 -- have to test the original nodes, since they may have been rewritten
12417 -- by various optimizations.
12419 Orig_N
:= Original_Node
(N
);
12421 -- Here we test for a redundant conversion if the warning mode is
12422 -- active (and was not locally reset), and we have a type conversion
12423 -- from source not appearing in a generic instance.
12426 and then Nkind
(Orig_N
) = N_Type_Conversion
12427 and then Comes_From_Source
(Orig_N
)
12428 and then not In_Instance
12430 Orig_N
:= Original_Node
(Expression
(Orig_N
));
12431 Orig_T
:= Target_Typ
;
12433 -- If the node is part of a larger expression, the Target_Type
12434 -- may not be the original type of the node if the context is a
12435 -- condition. Recover original type to see if conversion is needed.
12437 if Is_Boolean_Type
(Orig_T
)
12438 and then Nkind
(Parent
(N
)) in N_Op
12440 Orig_T
:= Etype
(Parent
(N
));
12443 -- If we have an entity name, then give the warning if the entity
12444 -- is the right type, or if it is a loop parameter covered by the
12445 -- original type (that's needed because loop parameters have an
12446 -- odd subtype coming from the bounds).
12448 if (Is_Entity_Name
(Orig_N
)
12449 and then Present
(Entity
(Orig_N
))
12451 (Etype
(Entity
(Orig_N
)) = Orig_T
12453 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
12454 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
))))))
12456 -- If not an entity, then type of expression must match
12458 or else Etype
(Orig_N
) = Orig_T
12460 -- One more check, do not give warning if the analyzed conversion
12461 -- has an expression with non-static bounds, and the bounds of the
12462 -- target are static. This avoids junk warnings in cases where the
12463 -- conversion is necessary to establish staticness, for example in
12464 -- a case statement.
12466 if not Is_OK_Static_Subtype
(Operand_Typ
)
12467 and then Is_OK_Static_Subtype
(Target_Typ
)
12471 -- Never give a warning if the operand is a conditional expression
12472 -- because RM 4.5.7(10/3) forces its type to be the target type.
12474 elsif Nkind
(Orig_N
) in N_Case_Expression | N_If_Expression
then
12477 -- Finally, if this type conversion occurs in a context requiring
12478 -- a prefix, and the expression is a qualified expression then the
12479 -- type conversion is not redundant, since a qualified expression
12480 -- is not a prefix, whereas a type conversion is. For example, "X
12481 -- := T'(Funx(...)).Y;" is illegal because a selected component
12482 -- requires a prefix, but a type conversion makes it legal: "X :=
12483 -- T(T'(Funx(...))).Y;"
12485 -- In Ada 2012, a qualified expression is a name, so this idiom is
12486 -- no longer needed, but we still suppress the warning because it
12487 -- seems unfriendly for warnings to pop up when you switch to the
12488 -- newer language version.
12490 elsif Nkind
(Orig_N
) = N_Qualified_Expression
12491 and then Nkind
(Parent
(N
)) in N_Attribute_Reference
12492 | N_Indexed_Component
12493 | N_Selected_Component
12495 | N_Explicit_Dereference
12499 -- Never warn on conversion to Long_Long_Integer'Base since
12500 -- that is most likely an artifact of the extended overflow
12501 -- checking and comes from complex expanded code.
12503 elsif Orig_T
= Base_Type
(Standard_Long_Long_Integer
) then
12506 -- Do not warn on conversion to class-wide type on helpers of
12507 -- class-wide preconditions because in this context the warning
12508 -- would be spurious (since the class-wide precondition has been
12509 -- installed in the return statement of the helper, which has a
12510 -- class-wide formal type instead of a regular tagged type).
12512 elsif Is_Class_Wide_Type
(Orig_T
)
12513 and then Is_Subprogram_Or_Generic_Subprogram
(Current_Scope
)
12514 and then Present
(Class_Preconditions_Subprogram
(Current_Scope
))
12518 -- Here we give the redundant conversion warning. If it is an
12519 -- entity, give the name of the entity in the message. If not,
12520 -- just mention the expression.
12523 if Is_Entity_Name
(Orig_N
) then
12524 Error_Msg_Node_2
:= Orig_T
;
12525 Error_Msg_NE
-- CODEFIX
12526 ("?r?redundant conversion, & is of type &!",
12527 N
, Entity
(Orig_N
));
12530 ("?r?redundant conversion, expression is of type&!",
12537 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
12538 -- No need to perform any interface conversion if the type of the
12539 -- expression coincides with the target type.
12541 if Ada_Version
>= Ada_2005
12542 and then Expander_Active
12543 and then Operand_Typ
/= Target_Typ
12546 Opnd
: Entity_Id
:= Operand_Typ
;
12547 Target
: Entity_Id
:= Target_Typ
;
12550 -- If the type of the operand is a limited view, use nonlimited
12551 -- view when available. If it is a class-wide type, recover the
12552 -- class-wide type of the nonlimited view.
12554 if From_Limited_With
(Opnd
)
12555 and then Has_Non_Limited_View
(Opnd
)
12557 Opnd
:= Non_Limited_View
(Opnd
);
12558 Set_Etype
(Expression
(N
), Opnd
);
12561 -- It seems that Non_Limited_View should also be applied for
12562 -- Target when it has a limited view, but that leads to missing
12563 -- error checks on interface conversions further below. ???
12565 if Is_Access_Type
(Opnd
) then
12566 Opnd
:= Designated_Type
(Opnd
);
12568 -- If the type of the operand is a limited view, use nonlimited
12569 -- view when available. If it is a class-wide type, recover the
12570 -- class-wide type of the nonlimited view.
12572 if From_Limited_With
(Opnd
)
12573 and then Has_Non_Limited_View
(Opnd
)
12575 Opnd
:= Non_Limited_View
(Opnd
);
12579 if Is_Access_Type
(Target_Typ
) then
12580 Target
:= Designated_Type
(Target
);
12582 -- If the target type is a limited view, use nonlimited view
12585 if From_Limited_With
(Target
)
12586 and then Has_Non_Limited_View
(Target
)
12588 Target
:= Non_Limited_View
(Target
);
12592 if Opnd
= Target
then
12595 -- Conversion from interface type
12597 -- It seems that it would be better for the error checks below
12598 -- to be performed as part of Validate_Conversion (and maybe some
12599 -- of the error checks above could be moved as well?). ???
12601 elsif Is_Interface
(Opnd
) then
12603 -- Ada 2005 (AI-217): Handle entities from limited views
12605 if From_Limited_With
(Opnd
) then
12606 Error_Msg_Qual_Level
:= 99;
12607 Error_Msg_NE
-- CODEFIX
12608 ("missing WITH clause on package &", N
,
12609 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
12611 ("type conversions require visibility of the full view",
12614 elsif From_Limited_With
(Target
)
12616 (Is_Access_Type
(Target_Typ
)
12617 and then Present
(Non_Limited_View
(Etype
(Target
))))
12619 Error_Msg_Qual_Level
:= 99;
12620 Error_Msg_NE
-- CODEFIX
12621 ("missing WITH clause on package &", N
,
12622 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
12624 ("type conversions require visibility of the full view",
12628 Expand_Interface_Conversion
(N
);
12631 -- Conversion to interface type
12633 elsif Is_Interface
(Target
) then
12634 Expand_Interface_Conversion
(N
);
12639 -- Ada 2012: Once the type conversion is resolved, check whether the
12640 -- operand satisfies a static predicate of the target subtype, if any.
12641 -- In the static expression case, a predicate check failure is an error.
12643 if Has_Predicates
(Target_Typ
) then
12644 Check_Expression_Against_Static_Predicate
12645 (N
, Target_Typ
, Static_Failure_Is_Error
=> True);
12648 -- If at this stage we have a fixed to integer conversion, make sure the
12649 -- Do_Range_Check flag is set, because such conversions in general need
12650 -- a range check. We only need this if expansion is off, see above why.
12652 if Nkind
(N
) = N_Type_Conversion
12653 and then not Expander_Active
12654 and then Is_Integer_Type
(Target_Typ
)
12655 and then Is_Fixed_Point_Type
(Operand_Typ
)
12656 and then not Range_Checks_Suppressed
(Target_Typ
)
12657 and then not Range_Checks_Suppressed
(Operand_Typ
)
12659 Set_Do_Range_Check
(Operand
);
12661 end Resolve_Type_Conversion
;
12663 ----------------------
12664 -- Resolve_Unary_Op --
12665 ----------------------
12667 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
12668 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
12669 R
: constant Node_Id
:= Right_Opnd
(N
);
12675 -- Deal with intrinsic unary operators
12677 if Comes_From_Source
(N
)
12678 and then Ekind
(Entity
(N
)) = E_Function
12679 and then Is_Imported
(Entity
(N
))
12680 and then Is_Intrinsic_Subprogram
(Entity
(N
))
12682 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
12686 -- Deal with universal cases
12688 if Is_Universal_Numeric_Type
(Etype
(R
)) then
12689 Check_For_Visible_Operator
(N
, B_Typ
);
12692 Set_Etype
(N
, B_Typ
);
12693 Resolve
(R
, B_Typ
);
12695 -- Generate warning for negative literal of a modular type, unless it is
12696 -- enclosed directly in a type qualification or a type conversion, as it
12697 -- is likely not what the user intended. We don't issue the warning for
12698 -- the common use of -1 to denote OxFFFF_FFFF...
12700 if Warn_On_Suspicious_Modulus_Value
12701 and then Nkind
(N
) = N_Op_Minus
12702 and then Nkind
(R
) = N_Integer_Literal
12703 and then Comes_From_Source
(R
)
12704 and then Is_Modular_Integer_Type
(B_Typ
)
12705 and then Nkind
(Parent
(N
)) not in N_Qualified_Expression
12706 | N_Type_Conversion
12707 and then Expr_Value
(R
) > Uint_1
12710 ("?.m?negative literal of modular type is in fact positive", N
);
12711 Error_Msg_Uint_1
:= (-Expr_Value
(R
)) mod Modulus
(B_Typ
);
12712 Error_Msg_Uint_2
:= Expr_Value
(R
);
12713 Error_Msg_N
("\do you really mean^ when writing -^ '?", N
);
12715 ("\if you do, use qualification to avoid this warning", N
);
12718 -- Generate warning for expressions like abs (x mod 2)
12720 if Warn_On_Redundant_Constructs
12721 and then Nkind
(N
) = N_Op_Abs
12723 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
12725 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
12726 Error_Msg_N
-- CODEFIX
12727 ("?r?abs applied to known non-negative value has no effect", N
);
12731 -- Deal with reference generation
12733 Check_Unset_Reference
(R
);
12734 Generate_Operator_Reference
(N
, B_Typ
);
12735 Analyze_Dimension
(N
);
12738 -- Set overflow checking bit. Much cleverer code needed here eventually
12739 -- and perhaps the Resolve routines should be separated for the various
12740 -- arithmetic operations, since they will need different processing ???
12742 if Nkind
(N
) in N_Op
then
12743 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
12744 Enable_Overflow_Check
(N
);
12748 -- Generate warning for expressions like -5 mod 3 for integers. No need
12749 -- to worry in the floating-point case, since parens do not affect the
12750 -- result so there is no point in giving in a warning.
12753 Norig
: constant Node_Id
:= Original_Node
(N
);
12762 if Warn_On_Questionable_Missing_Parens
12763 and then Comes_From_Source
(Norig
)
12764 and then Is_Integer_Type
(Typ
)
12765 and then Nkind
(Norig
) = N_Op_Minus
12767 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
12769 -- We are looking for cases where the right operand is not
12770 -- parenthesized, and is a binary operator, multiply, divide, or
12771 -- mod. These are the cases where the grouping can affect results.
12773 if Paren_Count
(Rorig
) = 0
12774 and then Nkind
(Rorig
) in N_Op_Mod | N_Op_Multiply | N_Op_Divide
12776 -- For mod, we always give the warning, since the value is
12777 -- affected by the parenthesization (e.g. (-5) mod 315 /=
12778 -- -(5 mod 315)). But for the other cases, the only concern is
12779 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
12780 -- overflows, but (-2) * 64 does not). So we try to give the
12781 -- message only when overflow is possible.
12783 if Nkind
(Rorig
) /= N_Op_Mod
12784 and then Compile_Time_Known_Value
(R
)
12786 Val
:= Expr_Value
(R
);
12788 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
12789 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
12791 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
12794 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
12795 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
12797 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
12800 -- Note that the test below is deliberately excluding the
12801 -- largest negative number, since that is a potentially
12802 -- troublesome case (e.g. -2 * x, where the result is the
12803 -- largest negative integer has an overflow with 2 * x).
12805 if Val
> LB
and then Val
<= HB
then
12810 -- For the multiplication case, the only case we have to worry
12811 -- about is when (-a)*b is exactly the largest negative number
12812 -- so that -(a*b) can cause overflow. This can only happen if
12813 -- a is a power of 2, and more generally if any operand is a
12814 -- constant that is not a power of 2, then the parentheses
12815 -- cannot affect whether overflow occurs. We only bother to
12816 -- test the left most operand
12818 -- Loop looking at left operands for one that has known value
12821 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
12822 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
12823 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
12825 -- Operand value of 0 or 1 skips warning
12830 -- Otherwise check power of 2, if power of 2, warn, if
12831 -- anything else, skip warning.
12834 while Lval
/= 2 loop
12835 if Lval
mod 2 = 1 then
12846 -- Keep looking at left operands
12848 Opnd
:= Left_Opnd
(Opnd
);
12849 end loop Opnd_Loop
;
12851 -- For rem or "/" we can only have a problematic situation
12852 -- if the divisor has a value of minus one or one. Otherwise
12853 -- overflow is impossible (divisor > 1) or we have a case of
12854 -- division by zero in any case.
12856 if Nkind
(Rorig
) in N_Op_Divide | N_Op_Rem
12857 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
12858 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
12863 -- If we fall through warning should be issued
12865 -- Shouldn't we test Warn_On_Questionable_Missing_Parens ???
12868 ("??unary minus expression should be parenthesized here!", N
);
12872 end Resolve_Unary_Op
;
12874 ----------------------------------
12875 -- Resolve_Unchecked_Expression --
12876 ----------------------------------
12878 procedure Resolve_Unchecked_Expression
12883 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
12884 Set_Etype
(N
, Typ
);
12885 end Resolve_Unchecked_Expression
;
12887 ---------------------------------------
12888 -- Resolve_Unchecked_Type_Conversion --
12889 ---------------------------------------
12891 procedure Resolve_Unchecked_Type_Conversion
12895 pragma Warnings
(Off
, Typ
);
12897 Operand
: constant Node_Id
:= Expression
(N
);
12898 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
12901 -- Resolve operand using its own type
12903 Resolve
(Operand
, Opnd_Type
);
12905 -- If the expression is a conversion to universal integer of an
12906 -- an expression with an integer type, then we can eliminate the
12907 -- intermediate conversion to universal integer.
12909 if Nkind
(Operand
) = N_Type_Conversion
12910 and then Entity
(Subtype_Mark
(Operand
)) = Universal_Integer
12911 and then Is_Integer_Type
(Etype
(Expression
(Operand
)))
12913 Rewrite
(Operand
, Relocate_Node
(Expression
(Operand
)));
12914 Analyze_And_Resolve
(Operand
);
12917 -- In an inlined context, the unchecked conversion may be applied
12918 -- to a literal, in which case its type is the type of the context.
12919 -- (In other contexts conversions cannot apply to literals).
12922 and then (Opnd_Type
= Any_Character
or else
12923 Opnd_Type
= Any_Integer
or else
12924 Opnd_Type
= Any_Real
)
12926 Set_Etype
(Operand
, Typ
);
12929 Analyze_Dimension
(N
);
12930 Eval_Unchecked_Conversion
(N
);
12931 end Resolve_Unchecked_Type_Conversion
;
12933 ------------------------------
12934 -- Rewrite_Operator_As_Call --
12935 ------------------------------
12937 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
12938 Loc
: constant Source_Ptr
:= Sloc
(N
);
12939 Actuals
: constant List_Id
:= New_List
;
12943 if Nkind
(N
) in N_Binary_Op
then
12944 Append
(Left_Opnd
(N
), Actuals
);
12947 Append
(Right_Opnd
(N
), Actuals
);
12950 Make_Function_Call
(Sloc
=> Loc
,
12951 Name
=> New_Occurrence_Of
(Nam
, Loc
),
12952 Parameter_Associations
=> Actuals
);
12954 Preserve_Comes_From_Source
(New_N
, N
);
12955 Preserve_Comes_From_Source
(Name
(New_N
), N
);
12956 Rewrite
(N
, New_N
);
12957 Set_Etype
(N
, Etype
(Nam
));
12958 end Rewrite_Operator_As_Call
;
12960 ------------------------------
12961 -- Rewrite_Renamed_Operator --
12962 ------------------------------
12964 procedure Rewrite_Renamed_Operator
12969 Nam
: constant Name_Id
:= Chars
(Op
);
12970 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
12974 -- Do not perform this transformation within a pre/postcondition,
12975 -- because the expression will be reanalyzed, and the transformation
12976 -- might affect the visibility of the operator, e.g. in an instance.
12977 -- Note that fully analyzed and expanded pre/postconditions appear as
12978 -- pragma Check equivalents.
12980 if In_Pre_Post_Condition
(N
) then
12984 -- Likewise when an expression function is being preanalyzed, since the
12985 -- expression will be reanalyzed as part of the generated body.
12987 if In_Spec_Expression
then
12989 S
: constant Entity_Id
:= Current_Scope_No_Loops
;
12991 if Ekind
(S
) = E_Function
12992 and then Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
12993 N_Expression_Function
13000 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
13001 Set_Chars
(Op_Node
, Nam
);
13002 Set_Etype
(Op_Node
, Etype
(N
));
13003 Set_Entity
(Op_Node
, Op
);
13004 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
13007 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
13010 -- Indicate that both the original entity and its renaming are
13011 -- referenced at this point.
13013 Generate_Reference
(Entity
(N
), N
);
13014 Generate_Reference
(Op
, N
);
13016 Rewrite
(N
, Op_Node
);
13018 -- If the context type is private, add the appropriate conversions so
13019 -- that the operator is applied to the full view. This is done in the
13020 -- routines that resolve intrinsic operators.
13022 if Is_Intrinsic_Subprogram
(Op
) and then Is_Private_Type
(Typ
) then
13032 Resolve_Intrinsic_Operator
(N
, Typ
);
13038 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
13044 end Rewrite_Renamed_Operator
;
13046 -----------------------
13047 -- Set_Slice_Subtype --
13048 -----------------------
13050 -- Build an implicit subtype declaration to represent the type delivered by
13051 -- the slice. This is an abbreviated version of an array subtype. We define
13052 -- an index subtype for the slice, using either the subtype name or the
13053 -- discrete range of the slice. To be consistent with index usage elsewhere
13054 -- we create a list header to hold the single index. This list is not
13055 -- otherwise attached to the syntax tree.
13057 procedure Set_Slice_Subtype
(N
: Node_Id
) is
13058 Loc
: constant Source_Ptr
:= Sloc
(N
);
13059 Index_List
: constant List_Id
:= New_List
;
13061 Index_Subtype
: Entity_Id
;
13062 Index_Type
: Entity_Id
;
13063 Slice_Subtype
: Entity_Id
;
13064 Drange
: constant Node_Id
:= Discrete_Range
(N
);
13067 Index_Type
:= Base_Type
(Etype
(Drange
));
13069 if Is_Entity_Name
(Drange
) then
13070 Index_Subtype
:= Entity
(Drange
);
13073 -- We force the evaluation of a range. This is definitely needed in
13074 -- the renamed case, and seems safer to do unconditionally. Note in
13075 -- any case that since we will create and insert an Itype referring
13076 -- to this range, we must make sure any side effect removal actions
13077 -- are inserted before the Itype definition.
13079 if Nkind
(Drange
) = N_Range
then
13080 Force_Evaluation
(Low_Bound
(Drange
));
13081 Force_Evaluation
(High_Bound
(Drange
));
13083 -- If the discrete range is given by a subtype indication, the
13084 -- type of the slice is the base of the subtype mark.
13086 elsif Nkind
(Drange
) = N_Subtype_Indication
then
13088 R
: constant Node_Id
:= Range_Expression
(Constraint
(Drange
));
13090 Index_Type
:= Base_Type
(Entity
(Subtype_Mark
(Drange
)));
13091 Force_Evaluation
(Low_Bound
(R
));
13092 Force_Evaluation
(High_Bound
(R
));
13096 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
13098 -- Take a new copy of Drange (where bounds have been rewritten to
13099 -- reference side-effect-free names). Using a separate tree ensures
13100 -- that further expansion (e.g. while rewriting a slice assignment
13101 -- into a FOR loop) does not attempt to remove side effects on the
13102 -- bounds again (which would cause the bounds in the index subtype
13103 -- definition to refer to temporaries before they are defined) (the
13104 -- reason is that some names are considered side effect free here
13105 -- for the subtype, but not in the context of a loop iteration
13108 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
13109 Set_Parent
(Scalar_Range
(Index_Subtype
), Index_Subtype
);
13110 Set_Etype
(Index_Subtype
, Index_Type
);
13111 Set_Size_Info
(Index_Subtype
, Index_Type
);
13112 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
13113 Set_Is_Constrained
(Index_Subtype
);
13116 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
13118 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
13119 Set_Etype
(Index
, Index_Subtype
);
13120 Append
(Index
, Index_List
);
13122 Set_First_Index
(Slice_Subtype
, Index
);
13123 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
13124 Set_Is_Constrained
(Slice_Subtype
, True);
13126 Check_Compile_Time_Size
(Slice_Subtype
);
13128 -- The Etype of the existing Slice node is reset to this slice subtype.
13129 -- Its bounds are obtained from its first index.
13131 Set_Etype
(N
, Slice_Subtype
);
13133 -- For bit-packed slice subtypes, freeze immediately (except in the case
13134 -- of being in a "spec expression" where we never freeze when we first
13135 -- see the expression).
13137 if Is_Bit_Packed_Array
(Slice_Subtype
) and not In_Spec_Expression
then
13138 Freeze_Itype
(Slice_Subtype
, N
);
13140 -- For all other cases insert an itype reference in the slice's actions
13141 -- so that the itype is frozen at the proper place in the tree (i.e. at
13142 -- the point where actions for the slice are analyzed). Note that this
13143 -- is different from freezing the itype immediately, which might be
13144 -- premature (e.g. if the slice is within a transient scope). This needs
13145 -- to be done only if expansion is enabled.
13147 elsif Expander_Active
then
13148 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
13150 end Set_Slice_Subtype
;
13152 --------------------------------
13153 -- Set_String_Literal_Subtype --
13154 --------------------------------
13156 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
13157 Loc
: constant Source_Ptr
:= Sloc
(N
);
13158 Low_Bound
: constant Node_Id
:=
13159 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
13160 Length
: constant Nat
:=
13162 when N_String_Literal
=> String_Length
(Strval
(N
)),
13163 -- Sinput.Source_Last points to an EOF character that's not in the
13164 -- original file and we do not include that character.
13165 when N_External_Initializer
=> Nat
(
13166 Source_Last
(File_Index
(N
)) - Source_First
(File_Index
(N
))),
13168 Subtype_Id
: Entity_Id
;
13171 if Nkind
(N
) not in N_String_Literal | N_External_Initializer
then
13175 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
13176 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
(Length
));
13177 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
13178 Set_Is_Constrained
(Subtype_Id
);
13179 Set_Etype
(N
, Subtype_Id
);
13181 -- The low bound is set from the low bound of the corresponding index
13182 -- type. Note that we do not store the high bound in the string literal
13183 -- subtype, but it can be deduced if necessary from the length and the
13186 if Is_OK_Static_Expression
(Low_Bound
) then
13187 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
13189 -- If the lower bound is not static we create a range for the string
13190 -- literal, using the index type and the known length of the literal.
13191 -- If the length is 1, then the upper bound is set to a mere copy of
13192 -- the lower bound; or else, if the index type is a signed integer,
13193 -- then the upper bound is computed as Low_Bound + L - 1; otherwise,
13194 -- the upper bound is computed as T'Val (T'Pos (Low_Bound) + L - 1).
13198 Index_List
: constant List_Id
:= New_List
;
13199 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
13200 Array_Subtype
: Entity_Id
;
13202 High_Bound
: Node_Id
;
13204 Index_Subtype
: Entity_Id
;
13208 High_Bound
:= New_Copy_Tree
(Low_Bound
);
13210 elsif Is_Signed_Integer_Type
(Index_Type
) then
13213 Left_Opnd
=> New_Copy_Tree
(Low_Bound
),
13214 Right_Opnd
=> Make_Integer_Literal
(Loc
, Length
- 1));
13218 Make_Attribute_Reference
(Loc
,
13219 Attribute_Name
=> Name_Val
,
13221 New_Occurrence_Of
(Index_Type
, Loc
),
13222 Expressions
=> New_List
(
13225 Make_Attribute_Reference
(Loc
,
13226 Attribute_Name
=> Name_Pos
,
13228 New_Occurrence_Of
(Index_Type
, Loc
),
13230 New_List
(New_Copy_Tree
(Low_Bound
))),
13232 Make_Integer_Literal
(Loc
, Length
- 1))));
13235 if Is_Integer_Type
(Index_Type
) then
13236 Set_String_Literal_Low_Bound
13237 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
13240 -- If the index type is an enumeration type, build bounds
13241 -- expression with attributes.
13243 Set_String_Literal_Low_Bound
13245 Make_Attribute_Reference
(Loc
,
13246 Attribute_Name
=> Name_First
,
13248 New_Occurrence_Of
(Base_Type
(Index_Type
), Loc
)));
13251 Analyze_And_Resolve
13252 (String_Literal_Low_Bound
(Subtype_Id
), Base_Type
(Index_Type
));
13254 -- Build bona fide subtype for the string, and wrap it in an
13255 -- unchecked conversion, because the back end expects the
13256 -- String_Literal_Subtype to have a static lower bound.
13259 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
13260 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
13261 Set_Scalar_Range
(Index_Subtype
, Drange
);
13262 Set_Parent
(Drange
, N
);
13263 Analyze_And_Resolve
(Drange
, Index_Type
);
13265 -- In this context, the Index_Type may already have a constraint,
13266 -- so use common base type on string subtype. The base type may
13267 -- be used when generating attributes of the string, for example
13268 -- in the context of a slice assignment.
13270 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
13271 Set_Size_Info
(Index_Subtype
, Index_Type
);
13272 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
13274 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
13276 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
13277 Set_Etype
(Index
, Index_Subtype
);
13278 Append
(Index
, Index_List
);
13280 Set_First_Index
(Array_Subtype
, Index
);
13281 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
13282 Set_Is_Constrained
(Array_Subtype
, True);
13284 Rewrite
(N
, Unchecked_Convert_To
(Array_Subtype
, N
));
13285 Set_Etype
(N
, Array_Subtype
);
13288 end Set_String_Literal_Subtype
;
13290 ------------------------------
13291 -- Simplify_Type_Conversion --
13292 ------------------------------
13294 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
13296 if Nkind
(N
) = N_Type_Conversion
then
13298 Operand
: constant Node_Id
:= Expression
(N
);
13299 Target_Typ
: constant Entity_Id
:= Etype
(N
);
13300 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
13303 -- Special processing if the conversion is the expression of a
13304 -- Rounding or Truncation attribute reference. In this case we
13307 -- ityp (ftyp'Rounding (x)) or ityp (ftyp'Truncation (x))
13313 -- with the Float_Truncate flag set to False or True respectively,
13314 -- which is more efficient. We reuse Rounding for Machine_Rounding
13315 -- as System.Fat_Gen, which is a permissible behavior.
13317 if Is_Floating_Point_Type
(Opnd_Typ
)
13319 (Is_Integer_Type
(Target_Typ
)
13320 or else (Is_Fixed_Point_Type
(Target_Typ
)
13321 and then Conversion_OK
(N
)))
13322 and then Nkind
(Operand
) = N_Attribute_Reference
13323 and then Attribute_Name
(Operand
) in Name_Rounding
13324 | Name_Machine_Rounding
13328 Truncate
: constant Boolean :=
13329 Attribute_Name
(Operand
) = Name_Truncation
;
13332 Relocate_Node
(First
(Expressions
(Operand
))));
13333 Set_Float_Truncate
(N
, Truncate
);
13336 -- Special processing for the conversion of an integer literal to
13337 -- a dynamic type: we first convert the literal to the root type
13338 -- and then convert the result to the target type, the goal being
13339 -- to avoid doing range checks in universal integer.
13341 elsif Is_Integer_Type
(Target_Typ
)
13342 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
13343 and then Nkind
(Operand
) = N_Integer_Literal
13344 and then Opnd_Typ
= Universal_Integer
13346 Convert_To_And_Rewrite
(Root_Type
(Target_Typ
), Operand
);
13347 Analyze_And_Resolve
(Operand
);
13349 -- If the expression is a conversion to universal integer of an
13350 -- an expression with an integer type, then we can eliminate the
13351 -- intermediate conversion to universal integer.
13353 elsif Nkind
(Operand
) = N_Type_Conversion
13354 and then Entity
(Subtype_Mark
(Operand
)) = Universal_Integer
13355 and then Is_Integer_Type
(Etype
(Expression
(Operand
)))
13357 Rewrite
(Operand
, Relocate_Node
(Expression
(Operand
)));
13358 Analyze_And_Resolve
(Operand
);
13362 end Simplify_Type_Conversion
;
13364 ------------------------------
13365 -- Try_User_Defined_Literal --
13366 ------------------------------
13368 function Try_User_Defined_Literal
13370 Typ
: Entity_Id
) return Boolean
13373 if Has_Applicable_User_Defined_Literal
(N
, Typ
) then
13376 elsif Nkind
(N
) = N_If_Expression
then
13377 -- Both dependent expressions must have the same type as the context
13380 Condition
: constant Node_Id
:= First
(Expressions
(N
));
13381 Then_Expr
: constant Node_Id
:= Next
(Condition
);
13382 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
13385 if Has_Applicable_User_Defined_Literal
(Then_Expr
, Typ
) then
13386 Resolve
(Else_Expr
, Typ
);
13387 Analyze_And_Resolve
(N
, Typ
);
13390 elsif Has_Applicable_User_Defined_Literal
(Else_Expr
, Typ
) then
13391 Resolve
(Then_Expr
, Typ
);
13392 Analyze_And_Resolve
(N
, Typ
);
13397 elsif Nkind
(N
) = N_Case_Expression
then
13398 -- All dependent expressions must have the same type as the context
13404 Alt
:= First
(Alternatives
(N
));
13406 while Present
(Alt
) loop
13407 if Has_Applicable_User_Defined_Literal
(Expression
(Alt
), Typ
)
13410 Other_Alt
: Node_Id
;
13413 Other_Alt
:= First
(Alternatives
(N
));
13415 while Present
(Other_Alt
) loop
13416 if Other_Alt
/= Alt
then
13417 Resolve
(Expression
(Other_Alt
), Typ
);
13423 Analyze_And_Resolve
(N
, Typ
);
13434 end Try_User_Defined_Literal
;
13436 -------------------------------------------
13437 -- Try_User_Defined_Literal_For_Operator --
13438 -------------------------------------------
13440 function Try_User_Defined_Literal_For_Operator
13442 Typ
: Entity_Id
) return Boolean
13445 if Nkind
(N
) in N_Op_Add
13452 -- Both operands must have the same type as the context
13453 -- (ignoring for now fixed-point and exponentiation ops).
13455 if Has_Applicable_User_Defined_Literal
(Right_Opnd
(N
), Typ
)
13456 or else (Nkind
(Left_Opnd
(N
)) in N_Op
13457 and then Covers
(Typ
, Etype
(Right_Opnd
(N
))))
13459 Resolve
(Left_Opnd
(N
), Typ
);
13460 Analyze_And_Resolve
(N
, Typ
);
13463 elsif Has_Applicable_User_Defined_Literal
(Left_Opnd
(N
), Typ
)
13464 or else (Nkind
(Right_Opnd
(N
)) in N_Op
13465 and then Covers
(Typ
, Etype
(Left_Opnd
(N
))))
13467 Resolve
(Right_Opnd
(N
), Typ
);
13468 Analyze_And_Resolve
(N
, Typ
);
13472 elsif Nkind
(N
) in N_Binary_Op
then
13473 -- For other binary operators the context does not impose a type on
13474 -- the operands, but their types must match.
13476 if Nkind
(Left_Opnd
(N
))
13477 not in N_Integer_Literal | N_String_Literal | N_Real_Literal
13479 Has_Applicable_User_Defined_Literal
13480 (Right_Opnd
(N
), Etype
(Left_Opnd
(N
)))
13482 Analyze_And_Resolve
(N
, Typ
);
13485 elsif Nkind
(Right_Opnd
(N
))
13486 not in N_Integer_Literal | N_String_Literal | N_Real_Literal
13488 Has_Applicable_User_Defined_Literal
13489 (Left_Opnd
(N
), Etype
(Right_Opnd
(N
)))
13491 Analyze_And_Resolve
(N
, Typ
);
13495 elsif Nkind
(N
) in N_Unary_Op
13496 and then Has_Applicable_User_Defined_Literal
(Right_Opnd
(N
), Typ
)
13498 Analyze_And_Resolve
(N
, Typ
);
13503 end Try_User_Defined_Literal_For_Operator
;
13505 -----------------------------
13506 -- Unique_Fixed_Point_Type --
13507 -----------------------------
13509 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
13510 procedure Fixed_Point_Error
(T1
: Entity_Id
; T2
: Entity_Id
);
13511 -- Give error messages for true ambiguity. Messages are posted on node
13512 -- N, and entities T1, T2 are the possible interpretations.
13514 -----------------------
13515 -- Fixed_Point_Error --
13516 -----------------------
13518 procedure Fixed_Point_Error
(T1
: Entity_Id
; T2
: Entity_Id
) is
13520 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
13521 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
13522 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
13523 end Fixed_Point_Error
;
13533 -- Start of processing for Unique_Fixed_Point_Type
13536 -- The operations on Duration are visible, so Duration is always a
13537 -- possible interpretation.
13539 T1
:= Standard_Duration
;
13541 -- Look for fixed-point types in enclosing scopes
13543 Scop
:= Current_Scope
;
13544 while Scop
/= Standard_Standard
loop
13545 T2
:= First_Entity
(Scop
);
13546 while Present
(T2
) loop
13547 if Is_Fixed_Point_Type
(T2
)
13548 and then Current_Entity
(T2
) = T2
13549 and then Scope
(Base_Type
(T2
)) = Scop
13551 if Present
(T1
) then
13552 Fixed_Point_Error
(T1
, T2
);
13562 Scop
:= Scope
(Scop
);
13565 -- Look for visible fixed type declarations in the context
13567 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
13568 while Present
(Item
) loop
13569 if Nkind
(Item
) = N_With_Clause
then
13570 Scop
:= Entity
(Name
(Item
));
13571 T2
:= First_Entity
(Scop
);
13572 while Present
(T2
) loop
13573 if Is_Fixed_Point_Type
(T2
)
13574 and then Scope
(Base_Type
(T2
)) = Scop
13575 and then (Is_Potentially_Use_Visible
(T2
) or else In_Use
(T2
))
13577 if Present
(T1
) then
13578 Fixed_Point_Error
(T1
, T2
);
13592 if Nkind
(N
) = N_Real_Literal
then
13593 Error_Msg_NE
("??real literal interpreted as }!", N
, T1
);
13596 -- When the context is a type conversion, issue the warning on the
13597 -- expression of the conversion because it is the actual operation.
13599 if Nkind
(N
) in N_Type_Conversion | N_Unchecked_Type_Conversion
then
13600 ErrN
:= Expression
(N
);
13606 ("??universal_fixed expression interpreted as }!", ErrN
, T1
);
13610 end Unique_Fixed_Point_Type
;
13612 ----------------------
13613 -- Valid_Conversion --
13614 ----------------------
13616 function Valid_Conversion
13618 Target
: Entity_Id
;
13620 Report_Errs
: Boolean := True) return Boolean
13622 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
13623 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
13624 Inc_Ancestor
: Entity_Id
;
13626 function Conversion_Check
13628 Msg
: String) return Boolean;
13629 -- Little routine to post Msg if Valid is False, returns Valid value
13631 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
);
13632 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
13634 procedure Conversion_Error_NE
13636 N
: Node_Or_Entity_Id
;
13637 E
: Node_Or_Entity_Id
);
13638 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
13640 function In_Instance_Code
return Boolean;
13641 -- Return True if expression is within an instance but is not in one of
13642 -- the actuals of the instantiation. Type conversions within an instance
13643 -- are not rechecked because type visibility may lead to spurious errors
13644 -- but conversions in an actual for a formal object must be checked.
13646 function Is_Discrim_Of_Bad_Access_Conversion_Argument
13647 (Expr
: Node_Id
) return Boolean;
13648 -- Implicit anonymous-to-named access type conversions are not allowed
13649 -- if the "statically deeper than" relationship does not apply to the
13650 -- type of the conversion operand. See RM 8.6(28.1) and AARM 8.6(28.d).
13651 -- We deal with most such cases elsewhere so that we can emit more
13652 -- specific error messages (e.g., if the operand is an access parameter
13653 -- or a saooaaat (stand-alone object of an anonymous access type)), but
13654 -- here is where we catch the case where the operand is an access
13655 -- discriminant selected from a dereference of another such "bad"
13656 -- conversion argument.
13658 function Valid_Tagged_Conversion
13659 (Target_Type
: Entity_Id
;
13660 Opnd_Type
: Entity_Id
) return Boolean;
13661 -- Specifically test for validity of tagged conversions
13663 function Valid_Array_Conversion
return Boolean;
13664 -- Check index and component conformance, and accessibility levels if
13665 -- the component types are anonymous access types (Ada 2005).
13667 ----------------------
13668 -- Conversion_Check --
13669 ----------------------
13671 function Conversion_Check
13673 Msg
: String) return Boolean
13678 -- A generic unit has already been analyzed and we have verified
13679 -- that a particular conversion is OK in that context. Since the
13680 -- instance is reanalyzed without relying on the relationships
13681 -- established during the analysis of the generic, it is possible
13682 -- to end up with inconsistent views of private types. Do not emit
13683 -- the error message in such cases. The rest of the machinery in
13684 -- Valid_Conversion still ensures the proper compatibility of
13685 -- target and operand types.
13687 and then not In_Instance_Code
13689 Conversion_Error_N
(Msg
, Operand
);
13693 end Conversion_Check
;
13695 ------------------------
13696 -- Conversion_Error_N --
13697 ------------------------
13699 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
13701 if Report_Errs
then
13702 Error_Msg_N
(Msg
, N
);
13704 end Conversion_Error_N
;
13706 -------------------------
13707 -- Conversion_Error_NE --
13708 -------------------------
13710 procedure Conversion_Error_NE
13712 N
: Node_Or_Entity_Id
;
13713 E
: Node_Or_Entity_Id
)
13716 if Report_Errs
then
13717 Error_Msg_NE
(Msg
, N
, E
);
13719 end Conversion_Error_NE
;
13721 ----------------------
13722 -- In_Instance_Code --
13723 ----------------------
13725 function In_Instance_Code
return Boolean is
13729 if not In_Instance
then
13734 while Present
(Par
) loop
13736 -- The expression is part of an actual object if it appears in
13737 -- the generated object declaration in the instance.
13739 if Nkind
(Par
) = N_Object_Declaration
13740 and then Present
(Corresponding_Generic_Association
(Par
))
13746 Nkind
(Par
) in N_Statement_Other_Than_Procedure_Call
13747 or else Nkind
(Par
) in N_Subprogram_Call
13748 or else Nkind
(Par
) in N_Declaration
;
13751 Par
:= Parent
(Par
);
13754 -- Otherwise the expression appears within the instantiated unit
13758 end In_Instance_Code
;
13760 --------------------------------------------------
13761 -- Is_Discrim_Of_Bad_Access_Conversion_Argument --
13762 --------------------------------------------------
13764 function Is_Discrim_Of_Bad_Access_Conversion_Argument
13765 (Expr
: Node_Id
) return Boolean
13767 Exp_Type
: Entity_Id
:= Base_Type
(Etype
(Expr
));
13768 pragma Assert
(Is_Access_Type
(Exp_Type
));
13770 Associated_Node
: Node_Id
;
13771 Deref_Prefix
: Node_Id
;
13773 if not Is_Anonymous_Access_Type
(Exp_Type
) then
13777 pragma Assert
(Is_Itype
(Exp_Type
));
13778 Associated_Node
:= Associated_Node_For_Itype
(Exp_Type
);
13780 if Nkind
(Associated_Node
) /= N_Discriminant_Specification
then
13781 return False; -- not the type of an access discriminant
13784 -- return False if Expr not of form <prefix>.all.Some_Component
13786 if Nkind
(Expr
) /= N_Selected_Component
13787 or else Nkind
(Prefix
(Expr
)) /= N_Explicit_Dereference
13789 -- conditional expressions, declare expressions ???
13793 Deref_Prefix
:= Prefix
(Prefix
(Expr
));
13794 Exp_Type
:= Base_Type
(Etype
(Deref_Prefix
));
13796 -- The "statically deeper relationship" does not apply
13797 -- to generic formal access types, so a prefix of such
13798 -- a type is a "bad" prefix.
13800 if Is_Generic_Formal
(Exp_Type
) then
13803 -- The "statically deeper relationship" does apply to
13804 -- any other named access type.
13806 elsif not Is_Anonymous_Access_Type
(Exp_Type
) then
13810 pragma Assert
(Is_Itype
(Exp_Type
));
13811 Associated_Node
:= Associated_Node_For_Itype
(Exp_Type
);
13813 -- The "statically deeper relationship" applies to some
13814 -- anonymous access types and not to others. Return
13815 -- True for the cases where it does not apply. Also check
13816 -- recursively for the
13817 -- <prefix>.all.Access_Discrim.all.Access_Discrim case,
13818 -- where the correct result depends on <prefix>.
13820 return Nkind
(Associated_Node
) in
13821 N_Procedure_Specification |
-- access parameter
13822 N_Function_Specification |
-- access parameter
13823 N_Object_Declaration
-- saooaaat
13824 or else Is_Discrim_Of_Bad_Access_Conversion_Argument
(Deref_Prefix
);
13825 end Is_Discrim_Of_Bad_Access_Conversion_Argument
;
13827 ----------------------------
13828 -- Valid_Array_Conversion --
13829 ----------------------------
13831 function Valid_Array_Conversion
return Boolean is
13832 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
13833 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
13835 Opnd_Index
: Node_Id
;
13836 Opnd_Index_Type
: Entity_Id
;
13838 Target_Comp_Type
: constant Entity_Id
:=
13839 Component_Type
(Target_Type
);
13840 Target_Comp_Base
: constant Entity_Id
:=
13841 Base_Type
(Target_Comp_Type
);
13843 Target_Index
: Node_Id
;
13844 Target_Index_Type
: Entity_Id
;
13847 -- Error if wrong number of dimensions
13850 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
13853 ("incompatible number of dimensions for conversion", Operand
);
13856 -- Number of dimensions matches
13859 -- Loop through indexes of the two arrays
13861 Target_Index
:= First_Index
(Target_Type
);
13862 Opnd_Index
:= First_Index
(Opnd_Type
);
13863 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
13864 Target_Index_Type
:= Etype
(Target_Index
);
13865 Opnd_Index_Type
:= Etype
(Opnd_Index
);
13867 -- Error if index types are incompatible
13869 if not (Is_Integer_Type
(Target_Index_Type
)
13870 and then Is_Integer_Type
(Opnd_Index_Type
))
13871 and then Root_Type
(Target_Index_Type
)
13872 /= Root_Type
(Opnd_Index_Type
)
13875 ("incompatible index types for array conversion",
13880 Next_Index
(Target_Index
);
13881 Next_Index
(Opnd_Index
);
13884 -- If component types have same base type, all set
13886 if Target_Comp_Base
= Opnd_Comp_Base
then
13889 -- Here if base types of components are not the same. The only
13890 -- time this is allowed is if we have anonymous access types.
13892 -- The conversion of arrays of anonymous access types can lead
13893 -- to dangling pointers. AI-392 formalizes the accessibility
13894 -- checks that must be applied to such conversions to prevent
13895 -- out-of-scope references.
13897 elsif Ekind
(Target_Comp_Base
) in
13898 E_Anonymous_Access_Type
13899 | E_Anonymous_Access_Subprogram_Type
13900 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
13902 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
13904 if Type_Access_Level
(Target_Type
) <
13905 Deepest_Type_Access_Level
(Opnd_Type
)
13907 if In_Instance_Body
then
13908 Error_Msg_Warn
:= SPARK_Mode
/= On
;
13910 ("source array type has deeper accessibility "
13911 & "level than target<<", Operand
);
13912 Conversion_Error_N
("\Program_Error [<<", Operand
);
13914 Make_Raise_Program_Error
(Sloc
(N
),
13915 Reason
=> PE_Accessibility_Check_Failed
));
13916 Set_Etype
(N
, Target_Type
);
13919 -- Conversion not allowed because of accessibility levels
13923 ("source array type has deeper accessibility "
13924 & "level than target", Operand
);
13932 -- All other cases where component base types do not match
13936 ("incompatible component types for array conversion",
13941 -- Check that component subtypes statically match. For numeric
13942 -- types this means that both must be either constrained or
13943 -- unconstrained. For enumeration types the bounds must match.
13944 -- All of this is checked in Subtypes_Statically_Match.
13946 if not Subtypes_Statically_Match
13947 (Target_Comp_Type
, Opnd_Comp_Type
)
13950 ("component subtypes must statically match", Operand
);
13956 end Valid_Array_Conversion
;
13958 -----------------------------
13959 -- Valid_Tagged_Conversion --
13960 -----------------------------
13962 function Valid_Tagged_Conversion
13963 (Target_Type
: Entity_Id
;
13964 Opnd_Type
: Entity_Id
) return Boolean
13967 -- Upward conversions are allowed (RM 4.6(22))
13969 if Covers
(Target_Type
, Opnd_Type
)
13970 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
13974 -- Downward conversion are allowed if the operand is class-wide
13977 elsif Is_Class_Wide_Type
(Opnd_Type
)
13978 and then Covers
(Opnd_Type
, Target_Type
)
13982 elsif Covers
(Opnd_Type
, Target_Type
)
13983 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
13985 -- Deal with non-extension derivation involving an
13986 -- untagged view of a tagged type.
13988 if not Is_Tagged_Type
(Target_Type
) then
13993 Conversion_Check
(False,
13994 "downward conversion of tagged objects not allowed");
13996 -- Ada 2005 (AI-251): A conversion is valid if the operand and target
13997 -- types are both class-wide types and the specific type associated
13998 -- with at least one of them is an interface type (RM 4.6 (23.1/2));
13999 -- at run-time a check will verify the validity of this interface
14000 -- type conversion.
14002 elsif Is_Class_Wide_Type
(Target_Type
)
14003 and then Is_Class_Wide_Type
(Opnd_Type
)
14004 and then (Is_Interface
(Target_Type
)
14005 or else Is_Interface
(Opnd_Type
))
14011 elsif Is_Class_Wide_Type
(Target_Type
)
14012 and then Is_Interface
(Target_Type
)
14013 and then not Is_Interface
(Opnd_Type
)
14014 and then not Interface_Present_In_Ancestor
14016 Iface
=> Target_Type
)
14018 Error_Msg_Name_1
:= Chars
(Etype
(Target_Type
));
14019 Error_Msg_Name_2
:= Chars
(Opnd_Type
);
14021 ("wrong interface conversion (% is not a progenitor "
14025 elsif Is_Class_Wide_Type
(Opnd_Type
)
14026 and then Is_Interface
(Opnd_Type
)
14027 and then not Is_Interface
(Target_Type
)
14028 and then not Interface_Present_In_Ancestor
14029 (Typ
=> Target_Type
,
14030 Iface
=> Opnd_Type
)
14032 Error_Msg_Name_1
:= Chars
(Etype
(Opnd_Type
));
14033 Error_Msg_Name_2
:= Chars
(Target_Type
);
14035 ("wrong interface conversion (% is not a progenitor "
14038 -- Search for interface types shared between the target type and
14039 -- the operand interface type to complete the text of the error
14040 -- since the source of this error is a missing type conversion
14041 -- to such interface type.
14043 if Has_Interfaces
(Target_Type
) then
14045 Operand_Ifaces_List
: Elist_Id
;
14046 Operand_Iface_Elmt
: Elmt_Id
;
14047 Target_Ifaces_List
: Elist_Id
;
14048 Target_Iface_Elmt
: Elmt_Id
;
14049 First_Candidate
: Boolean := True;
14052 Collect_Interfaces
(Base_Type
(Target_Type
),
14053 Target_Ifaces_List
);
14054 Collect_Interfaces
(Root_Type
(Base_Type
(Opnd_Type
)),
14055 Operand_Ifaces_List
);
14057 Operand_Iface_Elmt
:= First_Elmt
(Operand_Ifaces_List
);
14058 while Present
(Operand_Iface_Elmt
) loop
14059 Target_Iface_Elmt
:= First_Elmt
(Target_Ifaces_List
);
14060 while Present
(Target_Iface_Elmt
) loop
14061 if Node
(Operand_Iface_Elmt
)
14062 = Node
(Target_Iface_Elmt
)
14064 Error_Msg_Name_1
:=
14065 Chars
(Node
(Target_Iface_Elmt
));
14067 if First_Candidate
then
14068 First_Candidate
:= False;
14070 ("\must convert to `%''Class` before downward "
14071 & "conversion", Operand
);
14074 ("\or must convert to `%''Class` before "
14075 & "downward conversion", Operand
);
14079 Next_Elmt
(Target_Iface_Elmt
);
14082 Next_Elmt
(Operand_Iface_Elmt
);
14089 elsif not Is_Class_Wide_Type
(Target_Type
)
14090 and then Is_Interface
(Target_Type
)
14093 ("wrong use of interface type in tagged conversion", N
);
14095 ("\add ''Class to the target interface type", N
);
14098 elsif not Is_Class_Wide_Type
(Opnd_Type
)
14099 and then Is_Interface
(Opnd_Type
)
14102 ("must convert to class-wide interface type before downward "
14103 & "conversion", Operand
);
14107 Conversion_Error_NE
14108 ("invalid tagged conversion, not compatible with}",
14109 N
, First_Subtype
(Opnd_Type
));
14112 end Valid_Tagged_Conversion
;
14114 -- Start of processing for Valid_Conversion
14117 Check_Parameterless_Call
(Operand
);
14119 if Is_Overloaded
(Operand
) then
14129 -- Remove procedure calls, which syntactically cannot appear in
14130 -- this context, but which cannot be removed by type checking,
14131 -- because the context does not impose a type.
14133 -- The node may be labelled overloaded, but still contain only one
14134 -- interpretation because others were discarded earlier. If this
14135 -- is the case, retain the single interpretation if legal.
14137 Get_First_Interp
(Operand
, I
, It
);
14138 Opnd_Type
:= It
.Typ
;
14139 Get_Next_Interp
(I
, It
);
14141 if Present
(It
.Typ
)
14142 and then Opnd_Type
/= Standard_Void_Type
14144 -- More than one candidate interpretation is available
14146 Get_First_Interp
(Operand
, I
, It
);
14147 while Present
(It
.Typ
) loop
14148 if It
.Typ
= Standard_Void_Type
then
14152 -- When compiling for a system where Address is of a visible
14153 -- integer type, spurious ambiguities can be produced when
14154 -- arithmetic operations have a literal operand and return
14155 -- System.Address or a descendant of it. These ambiguities
14156 -- are usually resolved by the context, but for conversions
14157 -- there is no context type and the removal of the spurious
14158 -- operations must be done explicitly here.
14160 if not Address_Is_Private
14161 and then Is_Descendant_Of_Address
(It
.Typ
)
14166 Get_Next_Interp
(I
, It
);
14170 Get_First_Interp
(Operand
, I
, It
);
14174 if No
(It
.Typ
) then
14175 Conversion_Error_N
("illegal operand in conversion", Operand
);
14179 Get_Next_Interp
(I
, It
);
14181 if Present
(It
.Typ
) then
14184 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
14186 if It1
= No_Interp
then
14188 ("ambiguous operand in conversion", Operand
);
14190 -- If the interpretation involves a standard operator, use
14191 -- the location of the type, which may be user-defined.
14193 if Sloc
(It
.Nam
) = Standard_Location
then
14194 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
14196 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
14199 Conversion_Error_N
-- CODEFIX
14200 ("\\possible interpretation#!", Operand
);
14202 if Sloc
(N1
) = Standard_Location
then
14203 Error_Msg_Sloc
:= Sloc
(T1
);
14205 Error_Msg_Sloc
:= Sloc
(N1
);
14208 Conversion_Error_N
-- CODEFIX
14209 ("\\possible interpretation#!", Operand
);
14215 Set_Etype
(Operand
, It1
.Typ
);
14216 Opnd_Type
:= It1
.Typ
;
14220 -- When we encounter a class-wide equivalent type used to represent
14221 -- a fully sized mutably tagged type, pretend we are actually looking
14222 -- at the class-wide mutably tagged type instead.
14225 Get_Corresponding_Mutably_Tagged_Type_If_Present
(Opnd_Type
);
14227 -- Deal with conversion of integer type to address if the pragma
14228 -- Allow_Integer_Address is in effect. We convert the conversion to
14229 -- an unchecked conversion in this case and we are all done.
14231 if Address_Integer_Convert_OK
(Opnd_Type
, Target_Type
) then
14232 Rewrite
(N
, Unchecked_Convert_To
(Target_Type
, Expression
(N
)));
14233 Analyze_And_Resolve
(N
, Target_Type
);
14237 -- If we are within a child unit, check whether the type of the
14238 -- expression has an ancestor in a parent unit, in which case it
14239 -- belongs to its derivation class even if the ancestor is private.
14240 -- See RM 7.3.1 (5.2/3).
14242 Inc_Ancestor
:= Get_Incomplete_View_Of_Ancestor
(Opnd_Type
);
14246 if Is_Numeric_Type
(Target_Type
) then
14248 -- A universal fixed expression can be converted to any numeric type
14250 if Opnd_Type
= Universal_Fixed
then
14253 -- Also no need to check when in an instance or inlined body, because
14254 -- the legality has been established when the template was analyzed.
14255 -- Furthermore, numeric conversions may occur where only a private
14256 -- view of the operand type is visible at the instantiation point.
14257 -- This results in a spurious error if we check that the operand type
14258 -- is a numeric type.
14260 -- Note: in a previous version of this unit, the following tests were
14261 -- applied only for generated code (Comes_From_Source set to False),
14262 -- but in fact the test is required for source code as well, since
14263 -- this situation can arise in source code.
14265 elsif In_Instance_Code
or else In_Inlined_Body
then
14268 -- Otherwise we need the conversion check
14271 return Conversion_Check
14272 (Is_Numeric_Type
(Opnd_Type
)
14274 (Present
(Inc_Ancestor
)
14275 and then Is_Numeric_Type
(Inc_Ancestor
)),
14276 "illegal operand for numeric conversion");
14281 elsif Is_Array_Type
(Target_Type
) then
14282 if not Is_Array_Type
(Opnd_Type
)
14283 or else Opnd_Type
= Any_Composite
14284 or else Opnd_Type
= Any_String
14286 if not Comes_From_Source
(N
)
14287 and then Implementation_Base_Type
(Target_Type
) =
14288 Implementation_Base_Type
(Opnd_Type
)
14294 ("illegal operand for array conversion", Operand
);
14298 return Valid_Array_Conversion
;
14301 -- Ada 2005 (AI-251): Internally generated conversions of access to
14302 -- interface types added to force the displacement of the pointer to
14303 -- reference the corresponding dispatch table.
14305 elsif not Comes_From_Source
(N
)
14306 and then Is_Access_Type
(Target_Type
)
14307 and then Is_Interface
(Designated_Type
(Target_Type
))
14311 -- Ada 2005 (AI-251): Anonymous access types where target references an
14314 elsif Is_Access_Type
(Opnd_Type
)
14315 and then Ekind
(Target_Type
) in
14316 E_General_Access_Type | E_Anonymous_Access_Type
14317 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
14319 -- Check the static accessibility rule of 4.6(17). Note that the
14320 -- check is not enforced when within an instance body, since the
14321 -- RM requires such cases to be caught at run time.
14323 -- If the operand is a rewriting of an allocator no check is needed
14324 -- because there are no accessibility issues.
14326 if Nkind
(Original_Node
(N
)) = N_Allocator
then
14329 elsif Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
14330 if Type_Access_Level
(Opnd_Type
) >
14331 Deepest_Type_Access_Level
(Target_Type
)
14333 -- In an instance, this is a run-time check, but one we know
14334 -- will fail, so generate an appropriate warning. The raise
14335 -- will be generated by Expand_N_Type_Conversion.
14337 if In_Instance_Body
then
14338 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14340 ("cannot convert local pointer to non-local access type<<",
14342 Conversion_Error_N
("\Program_Error [<<", Operand
);
14346 ("cannot convert local pointer to non-local access type",
14351 -- Special accessibility checks are needed in the case of access
14352 -- discriminants declared for a limited type.
14354 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
14355 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
14357 -- When the operand is a selected access discriminant the check
14358 -- needs to be made against the level of the object denoted by
14359 -- the prefix of the selected name (Accessibility_Level handles
14360 -- checking the prefix of the operand for this case).
14362 if Nkind
(Operand
) = N_Selected_Component
14363 and then Static_Accessibility_Level
14364 (Operand
, Zero_On_Dynamic_Level
)
14365 > Deepest_Type_Access_Level
(Target_Type
)
14367 -- In an instance, this is a run-time check, but one we know
14368 -- will fail, so generate an appropriate warning. The raise
14369 -- will be generated by Expand_N_Type_Conversion.
14371 if In_Instance_Body
then
14372 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14374 ("cannot convert access discriminant to non-local "
14375 & "access type<<", Operand
);
14376 Conversion_Error_N
("\Program_Error [<<", Operand
);
14378 -- Real error if not in instance body
14382 ("cannot convert access discriminant to non-local "
14383 & "access type", Operand
);
14388 -- The case of a reference to an access discriminant from
14389 -- within a limited type declaration (which will appear as
14390 -- a discriminal) is always illegal because the level of the
14391 -- discriminant is considered to be deeper than any (nameable)
14394 if Is_Entity_Name
(Operand
)
14395 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
14397 Ekind
(Entity
(Operand
)) in E_In_Parameter | E_Constant
14398 and then Present
(Discriminal_Link
(Entity
(Operand
)))
14401 ("discriminant has deeper accessibility level than target",
14410 -- General and anonymous access types
14412 elsif Ekind
(Target_Type
) in
14413 E_General_Access_Type | E_Anonymous_Access_Type
14416 (Is_Access_Type
(Opnd_Type
)
14418 Ekind
(Opnd_Type
) not in
14419 E_Access_Subprogram_Type |
14420 E_Access_Protected_Subprogram_Type
,
14421 "must be an access-to-object type")
14423 if Is_Access_Constant
(Opnd_Type
)
14424 and then not Is_Access_Constant
(Target_Type
)
14427 ("access-to-constant operand type not allowed", Operand
);
14432 Extended_Opnd
: constant Boolean :=
14433 Is_Extended_Access_Type
(Opnd_Type
);
14434 Extended_Target
: constant Boolean :=
14435 Is_Extended_Access_Type
(Target_Type
);
14437 -- An extended access value may designate objects that are
14438 -- impossible to reference using a non-extended type, so
14439 -- prohibit conversions that would require being able to
14440 -- do the impossible.
14442 if Extended_Opnd
then
14443 if not Extended_Target
then
14445 ("cannot convert extended access value"
14446 & " to non-extended access type",
14451 -- Detect bad conversion on copy back for a view conversion
14453 elsif Extended_Target
and then Is_View_Conversion
(N
) then
14455 ("cannot convert non-extended value"
14456 & " to extended access type in view conversion",
14462 -- Check the static accessibility rule of 4.6(17). Note that the
14463 -- check is not enforced when within an instance body, since the RM
14464 -- requires such cases to be caught at run time.
14466 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
14467 or else Is_Local_Anonymous_Access
(Target_Type
)
14468 or else Nkind
(Associated_Node_For_Itype
(Target_Type
)) =
14469 N_Object_Declaration
14471 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
14472 -- conversions from an anonymous access type to a named general
14473 -- access type. Such conversions are not allowed in the case of
14474 -- access parameters and stand-alone objects of an anonymous
14475 -- access type. The implicit conversion case is recognized by
14476 -- testing that Comes_From_Source is False and that it's been
14477 -- rewritten. The Comes_From_Source test isn't sufficient because
14478 -- nodes in inlined calls to predefined library routines can have
14479 -- Comes_From_Source set to False. (Is there a better way to test
14480 -- for implicit conversions???).
14482 -- Do not treat a rewritten 'Old attribute reference like other
14483 -- rewrite substitutions. This makes a difference, for example,
14484 -- in the case where we are generating the expansion of a
14485 -- membership test of the form
14486 -- Saooaaat'Old in Named_Access_Type
14487 -- because in this case Valid_Conversion needs to return True
14488 -- (otherwise the expansion will be False - see the call site
14489 -- in exp_ch4.adb).
14491 if Ada_Version
>= Ada_2012
14492 and then not Comes_From_Source
(N
)
14493 and then Is_Rewrite_Substitution
(N
)
14494 and then not Is_Attribute_Old
(Original_Node
(N
))
14495 and then Ekind
(Base_Type
(Target_Type
)) = E_General_Access_Type
14496 and then Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
14498 if Is_Itype
(Opnd_Type
) then
14500 -- When applying restriction No_Dynamic_Accessibility_Check,
14501 -- implicit conversions are allowed when the operand type is
14502 -- not deeper than the target type.
14504 if No_Dynamic_Accessibility_Checks_Enabled
(N
) then
14505 if Type_Access_Level
(Opnd_Type
)
14506 > Deepest_Type_Access_Level
(Target_Type
)
14509 ("operand has deeper level than target", Operand
);
14513 -- Implicit conversions aren't allowed for objects of an
14514 -- anonymous access type, since such objects have nonstatic
14515 -- levels in Ada 2012.
14517 elsif Nkind
(Associated_Node_For_Itype
(Opnd_Type
))
14518 = N_Object_Declaration
14521 ("implicit conversion of stand-alone anonymous "
14522 & "access object not allowed", Operand
);
14525 -- Implicit conversions aren't allowed for anonymous access
14526 -- parameters. We exclude anonymous access results as well
14527 -- as universal_access "=".
14529 elsif not Is_Local_Anonymous_Access
(Opnd_Type
)
14530 and then Nkind
(Associated_Node_For_Itype
(Opnd_Type
)) in
14531 N_Function_Specification |
14532 N_Procedure_Specification
14533 and then Nkind
(Parent
(N
)) not in N_Op_Eq | N_Op_Ne
14536 ("implicit conversion of anonymous access parameter "
14537 & "not allowed", Operand
);
14540 -- Detect access discriminant values that are illegal
14541 -- implicit anonymous-to-named access conversion operands.
14543 elsif Is_Discrim_Of_Bad_Access_Conversion_Argument
(Operand
)
14546 ("implicit conversion of anonymous access value "
14547 & "not allowed", Operand
);
14550 -- In other cases, the level of the operand's type must be
14551 -- statically less deep than that of the target type, else
14552 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
14554 elsif Type_Access_Level
(Opnd_Type
) >
14555 Deepest_Type_Access_Level
(Target_Type
)
14558 ("implicit conversion of anonymous access value "
14559 & "violates accessibility", Operand
);
14564 -- Check if the operand is deeper than the target type, taking
14565 -- care to avoid the case where we are converting a result of a
14566 -- function returning an anonymous access type since the "master
14567 -- of the call" would be target type of the conversion unless
14568 -- the target type is anonymous access as well - see RM 3.10.2
14571 -- Note that when the restriction No_Dynamic_Accessibility_Checks
14572 -- is in effect wei also want to proceed with the conversion check
14573 -- described above.
14575 elsif Type_Access_Level
(Opnd_Type
, Assoc_Ent
=> Operand
)
14576 > Deepest_Type_Access_Level
(Target_Type
)
14577 and then (Nkind
(Associated_Node_For_Itype
(Opnd_Type
))
14578 /= N_Function_Specification
14579 or else Ekind
(Target_Type
) in Anonymous_Access_Kind
14580 or else No_Dynamic_Accessibility_Checks_Enabled
(N
))
14582 -- Check we are not in a return value ???
14584 and then (not In_Return_Value
(N
)
14586 Nkind
(Associated_Node_For_Itype
(Target_Type
))
14587 = N_Component_Declaration
)
14589 -- In an instance, this is a run-time check, but one we know
14590 -- will fail, so generate an appropriate warning. The raise
14591 -- will be generated by Expand_N_Type_Conversion.
14593 if In_Instance_Body
then
14594 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14596 ("cannot convert local pointer to non-local access type<<",
14598 Conversion_Error_N
("\Program_Error [<<", Operand
);
14600 -- If not in an instance body, this is a real error
14603 -- Avoid generation of spurious error message
14605 if not Error_Posted
(N
) then
14607 ("cannot convert local pointer to non-local access type",
14614 -- Special accessibility checks are needed in the case of access
14615 -- discriminants declared for a limited type.
14617 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
14618 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
14620 -- When the operand is a selected access discriminant the check
14621 -- needs to be made against the level of the object denoted by
14622 -- the prefix of the selected name (Accessibility_Level handles
14623 -- checking the prefix of the operand for this case).
14625 if Nkind
(Operand
) = N_Selected_Component
14626 and then Static_Accessibility_Level
14627 (Operand
, Zero_On_Dynamic_Level
)
14628 > Deepest_Type_Access_Level
(Target_Type
)
14630 -- In an instance, this is a run-time check, but one we know
14631 -- will fail, so generate an appropriate warning. The raise
14632 -- will be generated by Expand_N_Type_Conversion.
14634 if In_Instance_Body
then
14635 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14637 ("cannot convert access discriminant to non-local "
14638 & "access type<<", Operand
);
14639 Conversion_Error_N
("\Program_Error [<<", Operand
);
14641 -- If not in an instance body, this is a real error
14645 ("cannot convert access discriminant to non-local "
14646 & "access type", Operand
);
14651 -- The case of a reference to an access discriminant from
14652 -- within a limited type declaration (which will appear as
14653 -- a discriminal) is always illegal because the level of the
14654 -- discriminant is considered to be deeper than any (nameable)
14657 if Is_Entity_Name
(Operand
)
14659 Ekind
(Entity
(Operand
)) in E_In_Parameter | E_Constant
14660 and then Present
(Discriminal_Link
(Entity
(Operand
)))
14663 ("discriminant has deeper accessibility level than target",
14670 -- In the presence of limited_with clauses we have to use nonlimited
14671 -- views, if available.
14673 Check_Limited
: declare
14674 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
14675 -- Helper function to handle limited views
14677 --------------------------
14678 -- Full_Designated_Type --
14679 --------------------------
14681 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
14682 Desig
: constant Entity_Id
:= Designated_Type
(T
);
14685 -- Handle the limited view of a type
14687 if From_Limited_With
(Desig
)
14688 and then Has_Non_Limited_View
(Desig
)
14690 return Available_View
(Desig
);
14694 end Full_Designated_Type
;
14696 -- Local Declarations
14698 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
14699 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
14701 Same_Base
: constant Boolean :=
14702 Base_Type
(Target
) = Base_Type
(Opnd
);
14704 -- Start of processing for Check_Limited
14707 if Is_Tagged_Type
(Target
) then
14708 return Valid_Tagged_Conversion
(Target
, Opnd
);
14711 if not Same_Base
then
14712 Conversion_Error_NE
14713 ("target designated type not compatible with }",
14714 N
, Base_Type
(Opnd
));
14717 -- Ada 2005 AI-384: legality rule is symmetric in both
14718 -- designated types. The conversion is legal (with possible
14719 -- constraint check) if either designated type is
14722 elsif Subtypes_Statically_Match
(Target
, Opnd
)
14724 (Has_Discriminants
(Target
)
14726 (not Is_Constrained
(Opnd
)
14727 or else not Is_Constrained
(Target
)))
14729 -- Special case, if Value_Size has been used to make the
14730 -- sizes different, the conversion is not allowed even
14731 -- though the subtypes statically match.
14733 if Known_Static_RM_Size
(Target
)
14734 and then Known_Static_RM_Size
(Opnd
)
14735 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
14737 Conversion_Error_NE
14738 ("target designated subtype not compatible with }",
14740 Conversion_Error_NE
14741 ("\because sizes of the two designated subtypes differ",
14745 -- Normal case where conversion is allowed
14753 ("target designated subtype not compatible with }",
14760 -- Access to subprogram types. If the operand is an access parameter,
14761 -- the type has a deeper accessibility that any master, and cannot be
14762 -- assigned. We must make an exception if the conversion is part of an
14763 -- assignment and the target is the return object of an extended return
14764 -- statement, because in that case the accessibility check takes place
14765 -- after the return.
14767 elsif Is_Access_Subprogram_Type
(Target_Type
)
14769 -- Note: this test of Opnd_Type is there to prevent entering this
14770 -- branch in the case of a remote access to subprogram type, which
14771 -- is internally represented as an E_Record_Type.
14773 and then Is_Access_Type
(Opnd_Type
)
14775 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
14776 and then Is_Entity_Name
(Operand
)
14777 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
14779 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
14780 or else not Is_Entity_Name
(Name
(Parent
(N
)))
14781 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
14784 ("illegal attempt to store anonymous access to subprogram",
14787 ("\value has deeper accessibility than any master "
14788 & "(RM 3.10.2 (13))",
14792 ("\use named access type for& instead of access parameter",
14793 Operand
, Entity
(Operand
));
14796 -- Check that the designated types are subtype conformant
14798 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
14799 Old_Id
=> Designated_Type
(Opnd_Type
),
14802 -- Check the static accessibility rule of 4.6(20)
14804 if Type_Access_Level
(Opnd_Type
) >
14805 Deepest_Type_Access_Level
(Target_Type
)
14808 ("operand type has deeper accessibility level than target",
14811 -- Check that if the operand type is declared in a generic body,
14812 -- then the target type must be declared within that same body
14813 -- (enforces last sentence of 4.6(20)).
14815 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
14817 O_Gen
: constant Node_Id
:=
14818 Enclosing_Generic_Body
(Opnd_Type
);
14823 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
14824 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
14825 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
14828 if T_Gen
/= O_Gen
then
14830 ("target type must be declared in same generic body "
14831 & "as operand type", N
);
14836 -- Check that the strub modes are compatible.
14837 -- We wish to reject explicit conversions only for
14838 -- incompatible modes.
14840 return Conversion_Check
14841 (Compatible_Strub_Modes
14842 (Designated_Type
(Target_Type
),
14843 Designated_Type
(Opnd_Type
)),
14844 "incompatible `strub` modes");
14846 -- Remote access to subprogram types
14848 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
14849 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
14851 -- It is valid to convert from one RAS type to another provided
14852 -- that their specification statically match.
14854 -- Note: at this point, remote access to subprogram types have been
14855 -- expanded to their E_Record_Type representation, and we need to
14856 -- go back to the original access type definition using the
14857 -- Corresponding_Remote_Type attribute in order to check that the
14858 -- designated profiles match.
14860 pragma Assert
(Ekind
(Target_Type
) = E_Record_Type
);
14861 pragma Assert
(Ekind
(Opnd_Type
) = E_Record_Type
);
14863 Check_Subtype_Conformant
14865 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
14867 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
14871 -- Check that the strub modes are compatible.
14872 -- We wish to reject explicit conversions only for
14873 -- incompatible modes.
14875 return Conversion_Check
14876 (Compatible_Strub_Modes
14877 (Designated_Type
(Target_Type
),
14878 Designated_Type
(Opnd_Type
)),
14879 "incompatible `strub` modes");
14881 -- If it was legal in the generic, it's legal in the instance
14883 elsif In_Instance
then
14886 -- Ignore privacy for streaming or Put_Image routines
14888 elsif not Comes_From_Source
(N
)
14889 and then Original_Implementation_Base_Type
(Target_Type
) =
14890 Original_Implementation_Base_Type
(Opnd_Type
)
14894 -- If both are tagged types, check legality of view conversions
14896 elsif (Is_Tagged_Type
(Target_Type
) and then Is_Tagged_Type
(Opnd_Type
))
14897 or else (not Comes_From_Source
(N
)
14899 Is_Tagged_Type
(Implementation_Base_Type
(Target_Type
))
14901 Is_Tagged_Type
(Implementation_Base_Type
(Opnd_Type
)))
14903 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
14905 -- Types derived from the same root type are convertible
14907 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
14910 -- In an instance or an inlined body, there may be inconsistent views of
14911 -- the same type, or of types derived from a common root. Similarly
14912 -- for compiler-generated streaming or Put_Image subprograms.
14914 elsif (In_Instance
or In_Inlined_Body
or not Comes_From_Source
(N
))
14916 Root_Type
(Underlying_Type
(Target_Type
)) =
14917 Root_Type
(Underlying_Type
(Opnd_Type
))
14921 -- Special check for common access type error case
14923 elsif Ekind
(Target_Type
) = E_Access_Type
14924 and then Is_Access_Type
(Opnd_Type
)
14926 Conversion_Error_N
("target type must be general access type!", N
);
14927 Conversion_Error_NE
-- CODEFIX
14928 ("\add ALL to }!", N
, Target_Type
);
14931 -- Here we have a real conversion error
14934 -- Check for missing regular with_clause when only a limited view of
14935 -- target is available.
14937 if From_Limited_With
(Opnd_Type
) and then In_Package_Body
then
14938 Conversion_Error_NE
14939 ("invalid conversion, not compatible with limited view of }",
14941 Conversion_Error_NE
14942 ("\add with_clause for& to current unit!", N
, Scope
(Opnd_Type
));
14944 elsif Is_Access_Type
(Opnd_Type
)
14945 and then From_Limited_With
(Designated_Type
(Opnd_Type
))
14946 and then In_Package_Body
14948 Conversion_Error_NE
14949 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
14950 Conversion_Error_NE
14951 ("\add with_clause for& to current unit!",
14952 N
, Scope
(Designated_Type
(Opnd_Type
)));
14955 Conversion_Error_NE
14956 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
14961 end Valid_Conversion
;