1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Accessibility
; use Accessibility
;
27 with 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 Namet
; use Namet
;
51 with Nmake
; use Nmake
;
52 with Nlists
; use Nlists
;
54 with Output
; use Output
;
55 with Par_SCO
; use Par_SCO
;
56 with Restrict
; use Restrict
;
57 with Rident
; use Rident
;
58 with Rtsfind
; use Rtsfind
;
60 with Sem_Aggr
; use Sem_Aggr
;
61 with Sem_Attr
; use Sem_Attr
;
62 with Sem_Aux
; use Sem_Aux
;
63 with Sem_Case
; use Sem_Case
;
64 with Sem_Cat
; use Sem_Cat
;
65 with Sem_Ch3
; use Sem_Ch3
;
66 with Sem_Ch4
; use Sem_Ch4
;
67 with Sem_Ch5
; use Sem_Ch5
;
68 with Sem_Ch6
; use Sem_Ch6
;
69 with Sem_Ch8
; use Sem_Ch8
;
70 with Sem_Ch13
; use Sem_Ch13
;
71 with Sem_Dim
; use Sem_Dim
;
72 with Sem_Disp
; use Sem_Disp
;
73 with Sem_Dist
; use Sem_Dist
;
74 with Sem_Elab
; use Sem_Elab
;
75 with Sem_Elim
; use Sem_Elim
;
76 with Sem_Eval
; use Sem_Eval
;
77 with Sem_Intr
; use Sem_Intr
;
78 with Sem_Mech
; use Sem_Mech
;
79 with Sem_Type
; use Sem_Type
;
80 with Sem_Util
; use Sem_Util
;
81 with Sem_Warn
; use Sem_Warn
;
82 with Sinfo
; use Sinfo
;
83 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
84 with Sinfo
.Utils
; use Sinfo
.Utils
;
85 with Sinfo
.CN
; use Sinfo
.CN
;
86 with Snames
; use Snames
;
87 with Stand
; use Stand
;
88 with Stringt
; use Stringt
;
89 with Strub
; use Strub
;
90 with Style
; use Style
;
91 with Targparm
; use Targparm
;
92 with Tbuild
; use Tbuild
;
93 with Uintp
; use Uintp
;
94 with Urealp
; use Urealp
;
95 with Warnsw
; use Warnsw
;
97 package body Sem_Res
is
99 -----------------------
100 -- Local Subprograms --
101 -----------------------
103 -- Second pass (top-down) type checking and overload resolution procedures
104 -- Typ is the type required by context. These procedures propagate the
105 -- type information recursively to the descendants of N. If the node is not
106 -- overloaded, its Etype is established in the first pass. If overloaded,
107 -- the Resolve routines set the correct type. For arithmetic operators, the
108 -- Etype is the base type of the context.
110 -- Note that Resolve_Attribute is separated off in Sem_Attr
112 function Has_Applicable_User_Defined_Literal
114 Typ
: Entity_Id
) return Boolean;
115 -- Check whether N is a literal or a named number, and whether Typ has a
116 -- user-defined literal aspect that may apply to N. In this case, replace
117 -- N with a call to the corresponding function and return True.
119 procedure Check_Discriminant_Use
(N
: Node_Id
);
120 -- Enforce the restrictions on the use of discriminants when constraining
121 -- a component of a discriminated type (record or concurrent type).
123 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
);
124 -- Given a node for an operator associated with type T, check that the
125 -- operator is visible. Operators all of whose operands are universal must
126 -- be checked for visibility during resolution because their type is not
127 -- determinable based on their operands.
129 procedure Check_Fully_Declared_Prefix
132 -- Check that the type of the prefix of a dereference is not incomplete
134 function Check_Infinite_Recursion
(Call
: Node_Id
) return Boolean;
135 -- Given a call node, Call, which is known to occur immediately within the
136 -- subprogram being called, determines whether it is a detectable case of
137 -- an infinite recursion, and if so, outputs appropriate messages. Returns
138 -- True if an infinite recursion is detected, and False otherwise.
140 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
);
141 -- N is the node for a logical operator. If the operator is predefined, and
142 -- the root type of the operands is Standard.Boolean, then a check is made
143 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
144 -- the style check for Style_Check_Boolean_And_Or.
146 function Is_Atomic_Ref_With_Address
(N
: Node_Id
) return Boolean;
147 -- N is either an indexed component or a selected component. This function
148 -- returns true if the prefix denotes an atomic object that has an address
149 -- clause (the case in which we may want to issue a warning).
151 function Is_Definite_Access_Type
(E
: N_Entity_Id
) return Boolean;
152 -- Determine whether E is an access type declared by an access declaration,
153 -- and not an (anonymous) allocator type.
155 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean;
156 -- Utility to check whether the entity for an operator is a predefined
157 -- operator, in which case the expression is left as an operator in the
158 -- tree (else it is rewritten into a call). An instance of an intrinsic
159 -- conversion operation may be given an operator name, but is not treated
160 -- like an operator. Note that an operator that is an imported back-end
161 -- builtin has convention Intrinsic, but is expected to be rewritten into
162 -- a call, so such an operator is not treated as predefined by this
165 procedure Preanalyze_And_Resolve
168 With_Freezing
: Boolean);
169 -- Subsidiary of public versions of Preanalyze_And_Resolve.
171 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
);
172 -- If a default expression in entry call N depends on the discriminants
173 -- of the task, it must be replaced with a reference to the discriminant
174 -- of the task being called.
176 procedure Resolve_Dependent_Expression
180 -- Internal procedure to resolve the dependent expression Expr of the
181 -- conditional expression N with type Typ.
183 procedure Resolve_Op_Concat_Arg
188 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
189 -- concatenation operator. The operand is either of the array type or of
190 -- the component type. If the operand is an aggregate, and the component
191 -- type is composite, this is ambiguous if component type has aggregates.
193 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
);
194 -- Does the first part of the work of Resolve_Op_Concat
196 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
);
197 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
198 -- has been resolved. See Resolve_Op_Concat for details.
200 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
);
201 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
);
202 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
);
203 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
204 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
205 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
);
206 procedure Resolve_Declare_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
207 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
);
208 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
);
209 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
);
210 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
);
211 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
212 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
);
213 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
);
214 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
215 procedure Resolve_Interpolated_String_Literal
218 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
);
219 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
);
220 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
);
221 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
);
222 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
);
223 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
);
224 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
);
225 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
226 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
227 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
);
228 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
229 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
);
230 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
);
231 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
);
232 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
);
233 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
);
234 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
235 procedure Resolve_Target_Name
(N
: Node_Id
; Typ
: Entity_Id
);
236 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
237 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
);
238 procedure Resolve_Unchecked_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
239 procedure Resolve_Unchecked_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
241 function Operator_Kind
243 Is_Binary
: Boolean) return Node_Kind
;
244 -- Utility to map the name of an operator into the corresponding Node. Used
245 -- by other node rewriting procedures.
247 procedure Resolve_Actuals
(N
: Node_Id
; Nam
: Entity_Id
);
248 -- Resolve actuals of call, and add default expressions for missing ones.
249 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
250 -- called subprogram.
252 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
);
253 -- Called from Resolve_Call, when the prefix denotes an entry or element
254 -- of entry family. Actuals are resolved as for subprograms, and the node
255 -- is rebuilt as an entry call. Also called for protected operations. Typ
256 -- is the context type, which is used when the operation is a protected
257 -- function with no arguments, and the return value is indexed.
259 procedure Resolve_Implicit_Dereference
(P
: Node_Id
);
260 -- Called when P is the prefix of an indexed component, or of a selected
261 -- component, or of a slice. If P is of an access type, we unconditionally
262 -- rewrite it as an explicit dereference. This ensures that the expander
263 -- and the code generator have a fully explicit tree to work with.
265 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
266 -- A call to a user-defined intrinsic operator is rewritten as a call to
267 -- the corresponding predefined operator, with suitable conversions. Note
268 -- that this applies only for intrinsic operators that denote predefined
269 -- operators, not ones that are intrinsic imports of back-end builtins.
271 procedure Resolve_Intrinsic_Unary_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
272 -- Ditto, for arithmetic unary operators
274 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
);
275 -- If an operator node resolves to a call to a user-defined operator,
276 -- rewrite the node as a function call.
278 procedure Make_Call_Into_Operator
282 -- Inverse transformation: if an operator is given in functional notation,
283 -- then after resolving the node, transform into an operator node, so that
284 -- operands are resolved properly. Recall that predefined operators do not
285 -- have a full signature and special resolution rules apply.
287 procedure Rewrite_Renamed_Operator
291 -- An operator can rename another, e.g. in an instantiation. In that
292 -- case, the proper operator node must be constructed and resolved.
294 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
);
295 -- The String_Literal_Subtype is built for all strings that are not
296 -- operands of a static concatenation operation. If the argument is not
297 -- a N_String_Literal node, then the call has no effect.
299 procedure Set_Slice_Subtype
(N
: Node_Id
);
300 -- Build subtype of array type, with the range specified by the slice
302 procedure Simplify_Type_Conversion
(N
: Node_Id
);
303 -- Called after N has been resolved and evaluated, but before range checks
304 -- have been applied. This rewrites the conversion into a simpler form.
306 function Try_User_Defined_Literal
308 Typ
: Entity_Id
) return Boolean;
309 -- If the node is a literal or a named number or a conditional expression
310 -- whose dependent expressions are all literals or named numbers, and the
311 -- context type has a user-defined literal aspect, then rewrite the node
312 -- or its leaf nodes as calls to the corresponding function, which plays
313 -- the role of an implicit conversion.
315 function Try_User_Defined_Literal_For_Operator
317 Typ
: Entity_Id
) return Boolean;
318 -- If an operator node has a literal operand, check whether the type of the
319 -- context, or that of the other operand has a user-defined literal aspect
320 -- that can be applied to the literal to resolve the node. If such aspect
321 -- exists, replace literal with a call to the corresponding function and
322 -- return True, return false otherwise.
324 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
;
325 -- A universal_fixed expression in an universal context is unambiguous if
326 -- there is only one applicable fixed point type. Determining whether there
327 -- is only one requires a search over all visible entities, and happens
328 -- only in very pathological cases (see 6115-006).
330 -------------------------
331 -- Ambiguous_Character --
332 -------------------------
334 procedure Ambiguous_Character
(C
: Node_Id
) is
338 if Nkind
(C
) = N_Character_Literal
then
339 Error_Msg_N
("ambiguous character literal", C
);
341 -- First the ones in Standard
343 Error_Msg_N
("\\possible interpretation: Character!", C
);
344 Error_Msg_N
("\\possible interpretation: Wide_Character!", C
);
346 -- Include Wide_Wide_Character in Ada 2005 mode
348 if Ada_Version
>= Ada_2005
then
349 Error_Msg_N
("\\possible interpretation: Wide_Wide_Character!", C
);
352 -- Now any other types that match
354 E
:= Current_Entity
(C
);
355 while Present
(E
) loop
356 Error_Msg_NE
("\\possible interpretation:}!", C
, Etype
(E
));
360 end Ambiguous_Character
;
362 -------------------------
363 -- Analyze_And_Resolve --
364 -------------------------
366 procedure Analyze_And_Resolve
(N
: Node_Id
) is
370 end Analyze_And_Resolve
;
372 procedure Analyze_And_Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
376 end Analyze_And_Resolve
;
378 -- Versions with check(s) suppressed
380 procedure Analyze_And_Resolve
385 Scop
: constant Entity_Id
:= Current_Scope
;
388 if Suppress
= All_Checks
then
390 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
392 Scope_Suppress
.Suppress
:= (others => True);
393 Analyze_And_Resolve
(N
, Typ
);
394 Scope_Suppress
.Suppress
:= Sva
;
399 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
401 Scope_Suppress
.Suppress
(Suppress
) := True;
402 Analyze_And_Resolve
(N
, Typ
);
403 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
407 if Current_Scope
/= Scop
408 and then Scope_Is_Transient
410 -- This can only happen if a transient scope was created for an inner
411 -- expression, which will be removed upon completion of the analysis
412 -- of an enclosing construct. The transient scope must have the
413 -- suppress status of the enclosing environment, not of this Analyze
416 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
419 end Analyze_And_Resolve
;
421 procedure Analyze_And_Resolve
425 Scop
: constant Entity_Id
:= Current_Scope
;
428 if Suppress
= All_Checks
then
430 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
432 Scope_Suppress
.Suppress
:= (others => True);
433 Analyze_And_Resolve
(N
);
434 Scope_Suppress
.Suppress
:= Sva
;
439 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
441 Scope_Suppress
.Suppress
(Suppress
) := True;
442 Analyze_And_Resolve
(N
);
443 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
447 if Current_Scope
/= Scop
and then Scope_Is_Transient
then
448 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
451 end Analyze_And_Resolve
;
453 -------------------------------------
454 -- Has_Applicable_User_Defined_Literal --
455 -------------------------------------
457 function Has_Applicable_User_Defined_Literal
459 Typ
: Entity_Id
) return Boolean
461 Loc
: constant Source_Ptr
:= Sloc
(N
);
463 constant array (N_Numeric_Or_String_Literal
) of Aspect_Id
:=
464 (N_Integer_Literal
=> Aspect_Integer_Literal
,
465 N_Interpolated_String_Literal
=> No_Aspect
,
466 N_Real_Literal
=> Aspect_Real_Literal
,
467 N_String_Literal
=> Aspect_String_Literal
);
469 Named_Number_Aspect_Map
: constant array (Named_Kind
) of Aspect_Id
:=
470 (E_Named_Integer
=> Aspect_Integer_Literal
,
471 E_Named_Real
=> Aspect_Real_Literal
);
473 Lit_Aspect
: Aspect_Id
;
484 if (Nkind
(N
) in N_Numeric_Or_String_Literal
486 (Find_Aspect
(Typ
, Literal_Aspect_Map
(Nkind
(N
)))))
488 (Nkind
(N
) = N_Identifier
489 and then Is_Named_Number
(Entity
(N
))
493 (Typ
, Named_Number_Aspect_Map
(Ekind
(Entity
(N
))))))
496 (if Nkind
(N
) = N_Identifier
497 then Named_Number_Aspect_Map
(Ekind
(Entity
(N
)))
498 else Literal_Aspect_Map
(Nkind
(N
)));
500 Entity
(Expression
(Find_Aspect
(Typ
, Lit_Aspect
)));
501 Name
:= Make_Identifier
(Loc
, Chars
(Callee
));
503 if Is_Derived_Type
(Typ
)
504 and then Base_Type
(Etype
(Callee
)) /= Base_Type
(Typ
)
507 Corresponding_Primitive_Op
508 (Ancestor_Op
=> Callee
,
509 Descendant_Type
=> Base_Type
(Typ
));
512 -- Handle an identifier that denotes a named number.
514 if Nkind
(N
) = N_Identifier
then
515 Expr
:= Expression
(Declaration_Node
(Entity
(N
)));
517 if Ekind
(Entity
(N
)) = E_Named_Integer
then
518 UI_Image
(Expr_Value
(Expr
), Decimal
);
521 (UI_Image_Buffer
(1 .. UI_Image_Length
));
522 Param1
:= Make_String_Literal
(Loc
, End_String
);
523 Params
:= New_List
(Param1
);
526 UI_Image
(Norm_Num
(Expr_Value_R
(Expr
)), Decimal
);
529 if UR_Is_Negative
(Expr_Value_R
(Expr
)) then
530 Store_String_Chars
("-");
534 (UI_Image_Buffer
(1 .. UI_Image_Length
));
535 Param1
:= Make_String_Literal
(Loc
, End_String
);
537 -- Note: Set_Etype is called below on Param1
539 UI_Image
(Norm_Den
(Expr_Value_R
(Expr
)), Decimal
);
542 (UI_Image_Buffer
(1 .. UI_Image_Length
));
543 Param2
:= Make_String_Literal
(Loc
, End_String
);
544 Set_Etype
(Param2
, Standard_String
);
546 Params
:= New_List
(Param1
, Param2
);
548 if Present
(Related_Expression
(Callee
)) then
549 Callee
:= Related_Expression
(Callee
);
552 ("cannot resolve & for a named real", N
, Callee
);
557 elsif Nkind
(N
) = N_String_Literal
then
558 Param1
:= Make_String_Literal
(Loc
, Strval
(N
));
559 Params
:= New_List
(Param1
);
564 (Loc
, String_From_Numeric_Literal
(N
));
565 Params
:= New_List
(Param1
);
572 Parameter_Associations
=> Params
);
574 Set_Entity
(Name
, Callee
);
575 Set_Is_Overloaded
(Name
, False);
577 if Lit_Aspect
= Aspect_String_Literal
then
578 Set_Etype
(Param1
, Standard_Wide_Wide_String
);
580 Set_Etype
(Param1
, Standard_String
);
583 Set_Etype
(Call
, Etype
(Callee
));
585 -- Conversion not needed if the result type of the call is class-wide
586 -- or if the result type matches the context type.
588 if not Is_Class_Wide_Type
(Typ
)
589 and then Base_Type
(Etype
(Call
)) /= Base_Type
(Typ
)
591 -- Conversion may be needed in case of an inherited
592 -- aspect of a derived type. For a null extension, we
593 -- use a null extension aggregate instead because the
594 -- downward type conversion would be illegal.
596 if Is_Null_Extension_Of
598 Ancestor
=> Etype
(Call
))
600 Call
:= Make_Extension_Aggregate
(Loc
,
601 Ancestor_Part
=> Call
,
602 Null_Record_Present
=> True);
604 Call
:= Convert_To
(Typ
, Call
);
610 Analyze_And_Resolve
(N
, Typ
);
616 end Has_Applicable_User_Defined_Literal
;
618 ----------------------------
619 -- Check_Discriminant_Use --
620 ----------------------------
622 procedure Check_Discriminant_Use
(N
: Node_Id
) is
623 PN
: constant Node_Id
:= Parent
(N
);
624 Disc
: constant Entity_Id
:= Entity
(N
);
629 -- Any use in a spec-expression is legal
631 if In_Spec_Expression
then
634 elsif Nkind
(PN
) = N_Range
then
636 -- Discriminant cannot be used to constrain a scalar type
640 if Nkind
(P
) = N_Range_Constraint
641 and then Nkind
(Parent
(P
)) = N_Subtype_Indication
642 and then Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
644 Error_Msg_N
("discriminant cannot constrain scalar type", N
);
646 elsif Nkind
(P
) = N_Index_Or_Discriminant_Constraint
then
648 -- The following check catches the unusual case where a
649 -- discriminant appears within an index constraint that is part
650 -- of a larger expression within a constraint on a component,
651 -- e.g. "C : Int range 1 .. F (new A(1 .. D))". For now we only
652 -- check case of record components, and note that a similar check
653 -- should also apply in the case of discriminant constraints
656 -- Note that the check for N_Subtype_Declaration below is to
657 -- detect the valid use of discriminants in the constraints of a
658 -- subtype declaration when this subtype declaration appears
659 -- inside the scope of a record type (which is syntactically
660 -- illegal, but which may be created as part of derived type
661 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
664 if Ekind
(Current_Scope
) = E_Record_Type
665 and then Scope
(Disc
) = Current_Scope
667 (Nkind
(Parent
(P
)) = N_Subtype_Indication
669 Nkind
(Parent
(Parent
(P
))) in N_Component_Definition
670 | N_Subtype_Declaration
671 and then Paren_Count
(N
) = 0)
674 ("discriminant must appear alone in component constraint", N
);
678 -- Detect a common error:
680 -- type R (D : Positive := 100) is record
681 -- Name : String (1 .. D);
684 -- The default value causes an object of type R to be allocated
685 -- with room for Positive'Last characters. The RM does not mandate
686 -- the allocation of the maximum size, but that is what GNAT does
687 -- so we should warn the programmer that there is a problem.
689 Check_Large
: declare
695 function Large_Storage_Type
(T
: Entity_Id
) return Boolean;
696 -- Return True if type T has a large enough range that any
697 -- array whose index type covered the whole range of the type
698 -- would likely raise Storage_Error.
700 ------------------------
701 -- Large_Storage_Type --
702 ------------------------
704 function Large_Storage_Type
(T
: Entity_Id
) return Boolean is
706 -- The type is considered large if its bounds are known at
707 -- compile time and if it requires at least as many bits as
708 -- a Positive to store the possible values.
710 return Compile_Time_Known_Value
(Type_Low_Bound
(T
))
711 and then Compile_Time_Known_Value
(Type_High_Bound
(T
))
713 Minimum_Size
(T
, Biased
=> True) >=
714 RM_Size
(Standard_Positive
);
715 end Large_Storage_Type
;
717 -- Start of processing for Check_Large
720 -- Check that the Disc has a large range
722 if not Large_Storage_Type
(Etype
(Disc
)) then
726 -- If the enclosing type is limited, we allocate only the
727 -- default value, not the maximum, and there is no need for
730 if Is_Limited_Type
(Scope
(Disc
)) then
734 -- Check that it is the high bound
736 if N
/= High_Bound
(PN
)
737 or else No
(Discriminant_Default_Value
(Disc
))
742 -- Check the array allows a large range at this bound. First
747 if Nkind
(SI
) /= N_Subtype_Indication
then
751 T
:= Entity
(Subtype_Mark
(SI
));
753 if not Is_Array_Type
(T
) then
757 -- Next, find the dimension
759 TB
:= First_Index
(T
);
760 CB
:= First
(Constraints
(P
));
762 and then Present
(TB
)
763 and then Present
(CB
)
774 -- Now, check the dimension has a large range
776 if not Large_Storage_Type
(Etype
(TB
)) then
780 -- Warn about the danger
783 ("??creation of & object may raise Storage_Error!",
792 -- Legal case is in index or discriminant constraint
794 elsif Nkind
(PN
) in N_Index_Or_Discriminant_Constraint
795 | N_Discriminant_Association
797 if Paren_Count
(N
) > 0 then
799 ("discriminant in constraint must appear alone", N
);
801 elsif Nkind
(N
) = N_Expanded_Name
802 and then Comes_From_Source
(N
)
805 ("discriminant must appear alone as a direct name", N
);
810 -- Otherwise, context is an expression. It should not be within (i.e. a
811 -- subexpression of) a constraint for a component.
816 while Nkind
(P
) not in
817 N_Component_Declaration | N_Subtype_Indication | N_Entry_Declaration
824 -- If the discriminant is used in an expression that is a bound of a
825 -- scalar type, an Itype is created and the bounds are attached to
826 -- its range, not to the original subtype indication. Such use is of
827 -- course a double fault.
829 if (Nkind
(P
) = N_Subtype_Indication
830 and then Nkind
(Parent
(P
)) in N_Component_Definition
831 | N_Derived_Type_Definition
832 and then D
= Constraint
(P
))
834 -- The constraint itself may be given by a subtype indication,
835 -- rather than by a more common discrete range.
837 or else (Nkind
(P
) = N_Subtype_Indication
839 Nkind
(Parent
(P
)) = N_Index_Or_Discriminant_Constraint
)
840 or else Nkind
(P
) = N_Entry_Declaration
841 or else Nkind
(D
) = N_Defining_Identifier
844 ("discriminant in constraint must appear alone", N
);
847 end Check_Discriminant_Use
;
849 --------------------------------
850 -- Check_For_Visible_Operator --
851 --------------------------------
853 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
) is
855 if Comes_From_Source
(N
)
856 and then not Is_Visible_Operator
(Original_Node
(N
), T
)
857 and then not Error_Posted
(N
)
859 Error_Msg_NE
-- CODEFIX
860 ("operator for} is not directly visible!", N
, First_Subtype
(T
));
861 Error_Msg_N
-- CODEFIX
862 ("use clause would make operation legal!", N
);
864 end Check_For_Visible_Operator
;
866 ---------------------------------
867 -- Check_Fully_Declared_Prefix --
868 ---------------------------------
870 procedure Check_Fully_Declared_Prefix
875 -- Check that the designated type of the prefix of a dereference is
876 -- not an incomplete type. This cannot be done unconditionally, because
877 -- dereferences of private types are legal in default expressions. This
878 -- case is taken care of in Check_Fully_Declared, called below. There
879 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
881 -- This consideration also applies to similar checks for allocators,
882 -- qualified expressions, and type conversions.
884 -- An additional exception concerns other per-object expressions that
885 -- are not directly related to component declarations, in particular
886 -- representation pragmas for tasks. These will be per-object
887 -- expressions if they depend on discriminants or some global entity.
888 -- If the task has access discriminants, the designated type may be
889 -- incomplete at the point the expression is resolved. This resolution
890 -- takes place within the body of the initialization procedure, where
891 -- the discriminant is replaced by its discriminal.
893 if Is_Entity_Name
(Pref
)
894 and then Ekind
(Entity
(Pref
)) = E_In_Parameter
898 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
899 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
900 -- Analyze_Object_Renaming, and Freeze_Entity.
902 elsif Ada_Version
>= Ada_2005
903 and then Is_Entity_Name
(Pref
)
904 and then Is_Access_Type
(Etype
(Pref
))
905 and then Ekind
(Directly_Designated_Type
(Etype
(Pref
))) =
907 and then Is_Tagged_Type
(Directly_Designated_Type
(Etype
(Pref
)))
911 Check_Fully_Declared
(Typ
, Parent
(Pref
));
913 end Check_Fully_Declared_Prefix
;
915 ------------------------------
916 -- Check_Infinite_Recursion --
917 ------------------------------
919 function Check_Infinite_Recursion
(Call
: Node_Id
) return Boolean is
920 function Invoked_With_Different_Arguments
(N
: Node_Id
) return Boolean;
921 -- Determine whether call N invokes the related enclosing subprogram
922 -- with actuals that differ from the subprogram's formals.
924 function Is_Conditional_Statement
(N
: Node_Id
) return Boolean;
925 -- Determine whether arbitrary node N denotes a conditional construct
927 function Is_Control_Flow_Statement
(N
: Node_Id
) return Boolean;
928 -- Determine whether arbitrary node N denotes a control flow statement
929 -- or a construct that may contains such a statement.
931 function Is_Immediately_Within_Body
(N
: Node_Id
) return Boolean;
932 -- Determine whether arbitrary node N appears immediately within the
933 -- statements of an entry or subprogram body.
935 function Is_Raise_Idiom
(N
: Node_Id
) return Boolean;
936 -- Determine whether arbitrary node N appears immediately within the
937 -- body of an entry or subprogram, and is preceded by a single raise
940 function Is_Raise_Statement
(N
: Node_Id
) return Boolean;
941 -- Determine whether arbitrary node N denotes a raise statement
943 function Is_Sole_Statement
(N
: Node_Id
) return Boolean;
944 -- Determine whether arbitrary node N is the sole source statement in
945 -- the body of the enclosing subprogram.
947 function Preceded_By_Control_Flow_Statement
(N
: Node_Id
) return Boolean;
948 -- Determine whether arbitrary node N is preceded by a control flow
951 function Within_Conditional_Statement
(N
: Node_Id
) return Boolean;
952 -- Determine whether arbitrary node N appears within a conditional
955 --------------------------------------
956 -- Invoked_With_Different_Arguments --
957 --------------------------------------
959 function Invoked_With_Different_Arguments
(N
: Node_Id
) return Boolean is
960 Subp
: constant Entity_Id
:= Get_Called_Entity
(N
);
966 -- Determine whether the formals of the invoked subprogram are not
967 -- used as actuals in the call.
969 Actual
:= First_Actual
(N
);
970 Formal
:= First_Formal
(Subp
);
971 while Present
(Actual
) and then Present
(Formal
) loop
973 -- The current actual does not match the current formal
975 if not (Is_Entity_Name
(Actual
)
976 and then Entity
(Actual
) = Formal
)
981 Next_Actual
(Actual
);
982 Next_Formal
(Formal
);
986 end Invoked_With_Different_Arguments
;
988 ------------------------------
989 -- Is_Conditional_Statement --
990 ------------------------------
992 function Is_Conditional_Statement
(N
: Node_Id
) return Boolean is
995 Nkind
(N
) in N_And_Then
1001 end Is_Conditional_Statement
;
1003 -------------------------------
1004 -- Is_Control_Flow_Statement --
1005 -------------------------------
1007 function Is_Control_Flow_Statement
(N
: Node_Id
) return Boolean is
1009 -- It is assumed that all statements may affect the control flow in
1010 -- some way. A raise statement may be expanded into a non-statement
1013 return Is_Statement
(N
) or else Is_Raise_Statement
(N
);
1014 end Is_Control_Flow_Statement
;
1016 --------------------------------
1017 -- Is_Immediately_Within_Body --
1018 --------------------------------
1020 function Is_Immediately_Within_Body
(N
: Node_Id
) return Boolean is
1021 HSS
: constant Node_Id
:= Parent
(N
);
1025 Nkind
(HSS
) = N_Handled_Sequence_Of_Statements
1026 and then Nkind
(Parent
(HSS
)) in N_Entry_Body | N_Subprogram_Body
1027 and then Is_List_Member
(N
)
1028 and then List_Containing
(N
) = Statements
(HSS
);
1029 end Is_Immediately_Within_Body
;
1031 --------------------
1032 -- Is_Raise_Idiom --
1033 --------------------
1035 function Is_Raise_Idiom
(N
: Node_Id
) return Boolean is
1036 Raise_Stmt
: Node_Id
;
1040 if Is_Immediately_Within_Body
(N
) then
1042 -- Assume that no raise statement has been seen yet
1044 Raise_Stmt
:= Empty
;
1046 -- Examine the statements preceding the input node, skipping
1047 -- internally-generated constructs.
1050 while Present
(Stmt
) loop
1052 -- Multiple raise statements violate the idiom
1054 if Is_Raise_Statement
(Stmt
) then
1055 if Present
(Raise_Stmt
) then
1061 elsif Comes_From_Source
(Stmt
) then
1065 Stmt
:= Prev
(Stmt
);
1068 -- At this point the node must be preceded by a raise statement,
1069 -- and the raise statement has to be the sole statement within
1070 -- the enclosing entry or subprogram body.
1073 Present
(Raise_Stmt
) and then Is_Sole_Statement
(Raise_Stmt
);
1079 ------------------------
1080 -- Is_Raise_Statement --
1081 ------------------------
1083 function Is_Raise_Statement
(N
: Node_Id
) return Boolean is
1085 -- A raise statement may be transfomed into a Raise_xxx_Error node
1088 Nkind
(N
) = N_Raise_Statement
1089 or else Nkind
(N
) in N_Raise_xxx_Error
;
1090 end Is_Raise_Statement
;
1092 -----------------------
1093 -- Is_Sole_Statement --
1094 -----------------------
1096 function Is_Sole_Statement
(N
: Node_Id
) return Boolean is
1100 -- The input node appears within the statements of an entry or
1101 -- subprogram body. Examine the statements preceding the node.
1103 if Is_Immediately_Within_Body
(N
) then
1106 while Present
(Stmt
) loop
1108 -- The statement is preceded by another statement or a source
1109 -- construct. This indicates that the node does not appear by
1112 if Is_Control_Flow_Statement
(Stmt
)
1113 or else Comes_From_Source
(Stmt
)
1118 Stmt
:= Prev
(Stmt
);
1124 -- The input node is within a construct nested inside the entry or
1128 end Is_Sole_Statement
;
1130 ----------------------------------------
1131 -- Preceded_By_Control_Flow_Statement --
1132 ----------------------------------------
1134 function Preceded_By_Control_Flow_Statement
1135 (N
: Node_Id
) return Boolean
1140 if Is_List_Member
(N
) then
1143 -- Examine the statements preceding the input node
1145 while Present
(Stmt
) loop
1146 if Is_Control_Flow_Statement
(Stmt
) then
1150 Stmt
:= Prev
(Stmt
);
1156 -- Assume that the node is part of some control flow statement
1159 end Preceded_By_Control_Flow_Statement
;
1161 ----------------------------------
1162 -- Within_Conditional_Statement --
1163 ----------------------------------
1165 function Within_Conditional_Statement
(N
: Node_Id
) return Boolean is
1170 while Present
(Stmt
) loop
1171 if Is_Conditional_Statement
(Stmt
) then
1174 -- Prevent the search from going too far
1176 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
1180 Stmt
:= Parent
(Stmt
);
1184 end Within_Conditional_Statement
;
1188 Call_Context
: constant Node_Id
:=
1189 Enclosing_Declaration_Or_Statement
(Call
);
1191 -- Start of processing for Check_Infinite_Recursion
1194 -- The call is assumed to be safe when the enclosing subprogram is
1195 -- invoked with actuals other than its formals.
1197 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1200 -- Proc (A1, A2, ..., AN);
1204 if Invoked_With_Different_Arguments
(Call
) then
1207 -- The call is assumed to be safe when the invocation of the enclosing
1208 -- subprogram depends on a conditional statement.
1210 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1213 -- if Some_Condition then
1214 -- Proc (F1, F2, ..., FN);
1219 elsif Within_Conditional_Statement
(Call
) then
1222 -- The context of the call is assumed to be safe when the invocation of
1223 -- the enclosing subprogram is preceded by some control flow statement.
1225 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1228 -- if Some_Condition then
1232 -- Proc (F1, F2, ..., FN);
1236 elsif Preceded_By_Control_Flow_Statement
(Call_Context
) then
1239 -- Detect an idiom where the context of the call is preceded by a single
1242 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1245 -- Proc (F1, F2, ..., FN);
1248 elsif Is_Raise_Idiom
(Call_Context
) then
1252 -- At this point it is certain that infinite recursion will take place
1253 -- as long as the call is executed. Detect a case where the context of
1254 -- the call is the sole source statement within the subprogram body.
1256 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1258 -- Proc (F1, F2, ..., FN);
1261 -- Install an explicit raise to prevent the infinite recursion.
1263 if Is_Sole_Statement
(Call_Context
) then
1264 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1265 Error_Msg_N
("!infinite recursion<<", Call
);
1266 Error_Msg_N
("\!Storage_Error [<<", Call
);
1268 Insert_Action
(Call
,
1269 Make_Raise_Storage_Error
(Sloc
(Call
),
1270 Reason
=> SE_Infinite_Recursion
));
1272 -- Otherwise infinite recursion could take place, considering other flow
1273 -- control constructs such as gotos, exit statements, etc.
1276 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1277 Error_Msg_N
("!possible infinite recursion<<", Call
);
1278 Error_Msg_N
("\!??Storage_Error ]<<", Call
);
1282 end Check_Infinite_Recursion
;
1284 ---------------------------------------
1285 -- Check_No_Direct_Boolean_Operators --
1286 ---------------------------------------
1288 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
) is
1290 if Scope
(Entity
(N
)) = Standard_Standard
1291 and then Root_Type
(Etype
(Left_Opnd
(N
))) = Standard_Boolean
1293 -- Restriction only applies to original source code
1295 if Comes_From_Source
(N
) then
1296 Check_Restriction
(No_Direct_Boolean_Operators
, N
);
1300 -- Do style check (but skip if in instance, error is on template)
1303 if not In_Instance
then
1304 Check_Boolean_Operator
(N
);
1307 end Check_No_Direct_Boolean_Operators
;
1309 ------------------------------
1310 -- Check_Parameterless_Call --
1311 ------------------------------
1313 procedure Check_Parameterless_Call
(N
: Node_Id
) is
1316 function Prefix_Is_Access_Subp
return Boolean;
1317 -- If the prefix is of an access_to_subprogram type, the node must be
1318 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1319 -- interpretations are access to subprograms.
1321 ---------------------------
1322 -- Prefix_Is_Access_Subp --
1323 ---------------------------
1325 function Prefix_Is_Access_Subp
return Boolean is
1330 -- If the context is an attribute reference that can apply to
1331 -- functions, this is never a parameterless call (RM 4.1.4(6)).
1333 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1334 and then Attribute_Name
(Parent
(N
))
1335 in Name_Address | Name_Code_Address | Name_Access
1340 if not Is_Overloaded
(N
) then
1342 Ekind
(Etype
(N
)) = E_Subprogram_Type
1343 and then Base_Type
(Etype
(Etype
(N
))) /= Standard_Void_Type
;
1345 Get_First_Interp
(N
, I
, It
);
1346 while Present
(It
.Typ
) loop
1347 if Ekind
(It
.Typ
) /= E_Subprogram_Type
1348 or else Base_Type
(Etype
(It
.Typ
)) = Standard_Void_Type
1353 Get_Next_Interp
(I
, It
);
1358 end Prefix_Is_Access_Subp
;
1360 -- Start of processing for Check_Parameterless_Call
1363 -- Defend against junk stuff if errors already detected
1365 if Total_Errors_Detected
/= 0 then
1366 if Nkind
(N
) in N_Has_Etype
and then Etype
(N
) = Any_Type
then
1368 elsif Nkind
(N
) in N_Has_Chars
1369 and then not Is_Valid_Name
(Chars
(N
))
1377 -- If the context expects a value, and the name is a procedure, this is
1378 -- most likely a missing 'Access. Don't try to resolve the parameterless
1379 -- call, error will be caught when the outer call is analyzed.
1381 if Is_Entity_Name
(N
)
1382 and then Ekind
(Entity
(N
)) = E_Procedure
1383 and then not Is_Overloaded
(N
)
1385 Nkind
(Parent
(N
)) in N_Parameter_Association
1387 | N_Procedure_Call_Statement
1392 -- Rewrite as call if overloadable entity that is (or could be, in the
1393 -- overloaded case) a function call. If we know for sure that the entity
1394 -- is an enumeration literal, we do not rewrite it.
1396 -- If the entity is the name of an operator, it cannot be a call because
1397 -- operators cannot have default parameters. In this case, this must be
1398 -- a string whose contents coincide with an operator name. Set the kind
1399 -- of the node appropriately.
1401 if (Is_Entity_Name
(N
)
1402 and then Nkind
(N
) /= N_Operator_Symbol
1403 and then Is_Overloadable
(Entity
(N
))
1404 and then (Ekind
(Entity
(N
)) /= E_Enumeration_Literal
1405 or else Is_Overloaded
(N
)))
1407 -- Rewrite as call if it is an explicit dereference of an expression of
1408 -- a subprogram access type, and the subprogram type is not that of a
1409 -- procedure or entry.
1412 (Nkind
(N
) = N_Explicit_Dereference
and then Prefix_Is_Access_Subp
)
1414 -- Rewrite as call if it is a selected component which is a function,
1415 -- this is the case of a call to a protected function (which may be
1416 -- overloaded with other protected operations).
1419 (Nkind
(N
) = N_Selected_Component
1420 and then (Ekind
(Entity
(Selector_Name
(N
))) = E_Function
1422 (Ekind
(Entity
(Selector_Name
(N
))) in
1423 E_Entry | E_Procedure
1424 and then Is_Overloaded
(Selector_Name
(N
)))))
1426 -- If one of the above three conditions is met, rewrite as call. Apply
1427 -- the rewriting only once.
1430 if Nkind
(Parent
(N
)) /= N_Function_Call
1431 or else N
/= Name
(Parent
(N
))
1434 -- This may be a prefixed call that was not fully analyzed, e.g.
1435 -- an actual in an instance.
1437 if Ada_Version
>= Ada_2005
1438 and then Nkind
(N
) = N_Selected_Component
1439 and then Is_Dispatching_Operation
(Entity
(Selector_Name
(N
)))
1441 Analyze_Selected_Component
(N
);
1443 if Nkind
(N
) /= N_Selected_Component
then
1448 -- The node is the name of the parameterless call. Preserve its
1449 -- descendants, which may be complex expressions.
1451 Nam
:= Relocate_Node
(N
);
1453 -- If overloaded, overload set belongs to new copy
1455 Save_Interps
(N
, Nam
);
1457 -- Change node to parameterless function call (note that the
1458 -- Parameter_Associations associations field is left set to Empty,
1459 -- its normal default value since there are no parameters)
1461 Change_Node
(N
, N_Function_Call
);
1463 Set_Sloc
(N
, Sloc
(Nam
));
1467 elsif Nkind
(N
) = N_Parameter_Association
then
1468 Check_Parameterless_Call
(Explicit_Actual_Parameter
(N
));
1470 elsif Nkind
(N
) = N_Operator_Symbol
then
1471 Set_Etype
(N
, Empty
);
1472 Set_Entity
(N
, Empty
);
1473 Set_Is_Overloaded
(N
, False);
1474 Change_Operator_Symbol_To_String_Literal
(N
);
1475 Set_Etype
(N
, Any_String
);
1477 end Check_Parameterless_Call
;
1479 --------------------------------
1480 -- Is_Atomic_Ref_With_Address --
1481 --------------------------------
1483 function Is_Atomic_Ref_With_Address
(N
: Node_Id
) return Boolean is
1484 Pref
: constant Node_Id
:= Prefix
(N
);
1487 if not Is_Entity_Name
(Pref
) then
1492 Pent
: constant Entity_Id
:= Entity
(Pref
);
1493 Ptyp
: constant Entity_Id
:= Etype
(Pent
);
1495 return not Is_Access_Type
(Ptyp
)
1496 and then (Is_Atomic
(Ptyp
) or else Is_Atomic
(Pent
))
1497 and then Present
(Address_Clause
(Pent
));
1500 end Is_Atomic_Ref_With_Address
;
1502 -----------------------------
1503 -- Is_Definite_Access_Type --
1504 -----------------------------
1506 function Is_Definite_Access_Type
(E
: N_Entity_Id
) return Boolean is
1507 Btyp
: constant Entity_Id
:= Base_Type
(E
);
1509 return Ekind
(Btyp
) = E_Access_Type
1510 or else (Ekind
(Btyp
) = E_Access_Subprogram_Type
1511 and then Comes_From_Source
(Btyp
));
1512 end Is_Definite_Access_Type
;
1514 ----------------------
1515 -- Is_Predefined_Op --
1516 ----------------------
1518 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean is
1520 -- Predefined operators are intrinsic subprograms
1522 if not Is_Intrinsic_Subprogram
(Nam
) then
1526 -- A call to a back-end builtin is never a predefined operator
1528 if Is_Imported
(Nam
) and then Present
(Interface_Name
(Nam
)) then
1532 return not Is_Generic_Instance
(Nam
)
1533 and then Chars
(Nam
) in Any_Operator_Name
1534 and then (No
(Alias
(Nam
)) or else Is_Predefined_Op
(Alias
(Nam
)));
1535 end Is_Predefined_Op
;
1537 -----------------------------
1538 -- Make_Call_Into_Operator --
1539 -----------------------------
1541 procedure Make_Call_Into_Operator
1546 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
1547 Act1
: Node_Id
:= First_Actual
(N
);
1548 Act2
: Node_Id
:= Next_Actual
(Act1
);
1549 Error
: Boolean := False;
1550 Func
: constant Entity_Id
:= Entity
(Name
(N
));
1551 Is_Binary
: constant Boolean := Present
(Act2
);
1553 Opnd_Type
: Entity_Id
:= Empty
;
1554 Orig_Type
: Entity_Id
:= Empty
;
1557 type Kind_Test
is access function (E
: N_Entity_Id
) return Boolean;
1559 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean;
1560 -- If the operand is not universal, and the operator is given by an
1561 -- expanded name, verify that the operand has an interpretation with a
1562 -- type defined in the given scope of the operator.
1564 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
;
1565 -- Find a type of the given class in package Pack that contains the
1568 ---------------------------
1569 -- Operand_Type_In_Scope --
1570 ---------------------------
1572 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean is
1573 Nod
: constant Node_Id
:= Right_Opnd
(Op_Node
);
1578 if not Is_Overloaded
(Nod
) then
1579 return Scope
(Base_Type
(Etype
(Nod
))) = S
;
1582 Get_First_Interp
(Nod
, I
, It
);
1583 while Present
(It
.Typ
) loop
1584 if Scope
(Base_Type
(It
.Typ
)) = S
then
1588 Get_Next_Interp
(I
, It
);
1593 end Operand_Type_In_Scope
;
1599 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
is
1602 function In_Decl
return Boolean;
1603 -- Verify that node is not part of the type declaration for the
1604 -- candidate type, which would otherwise be invisible.
1610 function In_Decl
return Boolean is
1611 Decl_Node
: constant Node_Id
:= Parent
(E
);
1617 if Etype
(E
) = Any_Type
then
1620 elsif No
(Decl_Node
) then
1625 and then Nkind
(N2
) /= N_Compilation_Unit
1627 if N2
= Decl_Node
then
1638 -- Start of processing for Type_In_P
1641 -- If the context type is declared in the prefix package, this is the
1642 -- desired base type.
1644 if Scope
(Base_Type
(Typ
)) = Pack
and then Test
(Typ
) then
1645 return Base_Type
(Typ
);
1648 E
:= First_Entity
(Pack
);
1649 while Present
(E
) loop
1650 if Test
(E
) and then not In_Decl
then
1661 -- Start of processing for Make_Call_Into_Operator
1664 Op_Node
:= New_Node
(Operator_Kind
(Op_Name
, Is_Binary
), Sloc
(N
));
1666 -- Preserve the Comes_From_Source flag on the result if the original
1667 -- call came from source. Although it is not strictly the case that the
1668 -- operator as such comes from the source, logically it corresponds
1669 -- exactly to the function call in the source, so it should be marked
1670 -- this way (e.g. to make sure that validity checks work fine).
1672 Preserve_Comes_From_Source
(Op_Node
, N
);
1674 -- Ensure that the corresponding operator has the same parent as the
1675 -- original call. This guarantees that parent traversals performed by
1676 -- the ABE mechanism succeed.
1678 Set_Parent
(Op_Node
, Parent
(N
));
1683 Set_Left_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1684 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act2
));
1685 Save_Interps
(Act1
, Left_Opnd
(Op_Node
));
1686 Save_Interps
(Act2
, Right_Opnd
(Op_Node
));
1687 Act1
:= Left_Opnd
(Op_Node
);
1688 Act2
:= Right_Opnd
(Op_Node
);
1693 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1694 Save_Interps
(Act1
, Right_Opnd
(Op_Node
));
1695 Act1
:= Right_Opnd
(Op_Node
);
1698 -- If the operator is denoted by an expanded name, and the prefix is
1699 -- not Standard, but the operator is a predefined one whose scope is
1700 -- Standard, then this is an implicit_operator, inserted as an
1701 -- interpretation by the procedure of the same name. This procedure
1702 -- overestimates the presence of implicit operators, because it does
1703 -- not examine the type of the operands. Verify now that the operand
1704 -- type appears in the given scope. If right operand is universal,
1705 -- check the other operand. In the case of concatenation, either
1706 -- argument can be the component type, so check the type of the result.
1707 -- If both arguments are literals, look for a type of the right kind
1708 -- defined in the given scope. This elaborate nonsense is brought to
1709 -- you courtesy of b33302a. The type itself must be frozen, so we must
1710 -- find the type of the proper class in the given scope.
1712 -- A final wrinkle is the multiplication operator for fixed point types,
1713 -- which is defined in Standard only, and not in the scope of the
1714 -- fixed point type itself.
1716 if Nkind
(Name
(N
)) = N_Expanded_Name
then
1717 Pack
:= Entity
(Prefix
(Name
(N
)));
1719 -- If this is a package renaming, get renamed entity, which will be
1720 -- the scope of the operands if operaton is type-correct.
1722 if Present
(Renamed_Entity
(Pack
)) then
1723 Pack
:= Renamed_Entity
(Pack
);
1726 -- If the entity being called is defined in the given package, it is
1727 -- a renaming of a predefined operator, and known to be legal.
1729 if Scope
(Entity
(Name
(N
))) = Pack
1730 and then Pack
/= Standard_Standard
1734 -- Visibility does not need to be checked in an instance: if the
1735 -- operator was not visible in the generic it has been diagnosed
1736 -- already, else there is an implicit copy of it in the instance.
1738 elsif In_Instance
then
1741 elsif Op_Name
in Name_Op_Multiply | Name_Op_Divide
1742 and then Is_Fixed_Point_Type
(Etype
(Act1
))
1743 and then Is_Fixed_Point_Type
(Etype
(Act2
))
1745 if Pack
/= Standard_Standard
then
1749 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1752 elsif Ada_Version
>= Ada_2005
1753 and then Op_Name
in Name_Op_Eq | Name_Op_Ne
1754 and then (Is_Anonymous_Access_Type
(Etype
(Act1
))
1755 or else Is_Anonymous_Access_Type
(Etype
(Act2
)))
1760 Opnd_Type
:= Base_Type
(Etype
(Right_Opnd
(Op_Node
)));
1762 if Op_Name
= Name_Op_Concat
then
1763 Opnd_Type
:= Base_Type
(Typ
);
1765 elsif (Scope
(Opnd_Type
) = Standard_Standard
1767 or else (Nkind
(Right_Opnd
(Op_Node
)) = N_Attribute_Reference
1769 and then not Comes_From_Source
(Opnd_Type
))
1771 Opnd_Type
:= Base_Type
(Etype
(Left_Opnd
(Op_Node
)));
1774 if Scope
(Opnd_Type
) = Standard_Standard
then
1776 -- Verify that the scope contains a type that corresponds to
1777 -- the given literal. Optimize the case where Pack is Standard.
1779 if Pack
/= Standard_Standard
then
1780 if Opnd_Type
= Universal_Integer
then
1781 Orig_Type
:= Type_In_P
(Is_Integer_Type
'Access);
1783 elsif Opnd_Type
= Universal_Real
then
1784 Orig_Type
:= Type_In_P
(Is_Real_Type
'Access);
1786 elsif Opnd_Type
= Universal_Access
then
1787 Orig_Type
:= Type_In_P
(Is_Definite_Access_Type
'Access);
1789 elsif Opnd_Type
= Any_String
then
1790 Orig_Type
:= Type_In_P
(Is_String_Type
'Access);
1792 elsif Opnd_Type
= Any_Composite
then
1793 Orig_Type
:= Type_In_P
(Is_Composite_Type
'Access);
1795 if Present
(Orig_Type
) then
1796 if Has_Private_Component
(Orig_Type
) then
1799 Set_Etype
(Act1
, Orig_Type
);
1802 Set_Etype
(Act2
, Orig_Type
);
1811 Error
:= No
(Orig_Type
);
1814 elsif Ekind
(Opnd_Type
) = E_Allocator_Type
1815 and then No
(Type_In_P
(Is_Definite_Access_Type
'Access))
1819 -- If the type is defined elsewhere, and the operator is not
1820 -- defined in the given scope (by a renaming declaration, e.g.)
1821 -- then this is an error as well. If an extension of System is
1822 -- present, and the type may be defined there, Pack must be
1825 elsif Scope
(Opnd_Type
) /= Pack
1826 and then Scope
(Op_Id
) /= Pack
1827 and then (No
(System_Aux_Id
)
1828 or else Scope
(Opnd_Type
) /= System_Aux_Id
1829 or else Pack
/= Scope
(System_Aux_Id
))
1831 if not Is_Overloaded
(Right_Opnd
(Op_Node
)) then
1834 Error
:= not Operand_Type_In_Scope
(Pack
);
1837 elsif Pack
= Standard_Standard
1838 and then not Operand_Type_In_Scope
(Standard_Standard
)
1845 Error_Msg_Node_2
:= Pack
;
1847 ("& not declared in&", N
, Selector_Name
(Name
(N
)));
1848 Set_Etype
(N
, Any_Type
);
1851 -- Detect a mismatch between the context type and the result type
1852 -- in the named package, which is otherwise not detected if the
1853 -- operands are universal. Check is only needed if source entity is
1854 -- an operator, not a function that renames an operator.
1856 elsif Nkind
(Parent
(N
)) /= N_Type_Conversion
1857 and then Ekind
(Entity
(Name
(N
))) = E_Operator
1858 and then Is_Numeric_Type
(Typ
)
1859 and then not Is_Universal_Numeric_Type
(Typ
)
1860 and then Scope
(Base_Type
(Typ
)) /= Pack
1861 and then not In_Instance
1863 if Is_Fixed_Point_Type
(Typ
)
1864 and then Op_Name
in Name_Op_Multiply | Name_Op_Divide
1866 -- Already checked above
1870 -- Operator may be defined in an extension of System
1872 elsif Present
(System_Aux_Id
)
1873 and then Present
(Opnd_Type
)
1874 and then Scope
(Opnd_Type
) = System_Aux_Id
1879 -- Could we use Wrong_Type here??? (this would require setting
1880 -- Etype (N) to the actual type found where Typ was expected).
1882 Error_Msg_NE
("expect }", N
, Typ
);
1887 Set_Chars
(Op_Node
, Op_Name
);
1889 if not Is_Private_Type
(Etype
(N
)) then
1890 Set_Etype
(Op_Node
, Base_Type
(Etype
(N
)));
1892 Set_Etype
(Op_Node
, Etype
(N
));
1895 -- If this is a call to a function that renames a predefined equality,
1896 -- the renaming declaration provides a type that must be used to
1897 -- resolve the operands. This must be done now because resolution of
1898 -- the equality node will not resolve any remaining ambiguity, and it
1899 -- assumes that the first operand is not overloaded.
1901 if Op_Name
in Name_Op_Eq | Name_Op_Ne
1902 and then Ekind
(Func
) = E_Function
1903 and then Is_Overloaded
(Act1
)
1905 Resolve
(Act1
, Base_Type
(Etype
(First_Formal
(Func
))));
1906 Resolve
(Act2
, Base_Type
(Etype
(First_Formal
(Func
))));
1909 Set_Entity
(Op_Node
, Op_Id
);
1910 Generate_Reference
(Op_Id
, N
, ' ');
1912 Rewrite
(N
, Op_Node
);
1914 -- If this is an arithmetic operator and the result type is private,
1915 -- the operands and the result must be wrapped in conversion to
1916 -- expose the underlying numeric type and expand the proper checks,
1917 -- e.g. on division.
1919 if Is_Private_Type
(Typ
) then
1929 Resolve_Intrinsic_Operator
(N
, Typ
);
1935 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
1943 end Make_Call_Into_Operator
;
1949 function Operator_Kind
1951 Is_Binary
: Boolean) return Node_Kind
1956 -- Use CASE statement or array???
1959 if Op_Name
= Name_Op_And
then
1961 elsif Op_Name
= Name_Op_Or
then
1963 elsif Op_Name
= Name_Op_Xor
then
1965 elsif Op_Name
= Name_Op_Eq
then
1967 elsif Op_Name
= Name_Op_Ne
then
1969 elsif Op_Name
= Name_Op_Lt
then
1971 elsif Op_Name
= Name_Op_Le
then
1973 elsif Op_Name
= Name_Op_Gt
then
1975 elsif Op_Name
= Name_Op_Ge
then
1977 elsif Op_Name
= Name_Op_Add
then
1979 elsif Op_Name
= Name_Op_Subtract
then
1980 Kind
:= N_Op_Subtract
;
1981 elsif Op_Name
= Name_Op_Concat
then
1982 Kind
:= N_Op_Concat
;
1983 elsif Op_Name
= Name_Op_Multiply
then
1984 Kind
:= N_Op_Multiply
;
1985 elsif Op_Name
= Name_Op_Divide
then
1986 Kind
:= N_Op_Divide
;
1987 elsif Op_Name
= Name_Op_Mod
then
1989 elsif Op_Name
= Name_Op_Rem
then
1991 elsif Op_Name
= Name_Op_Expon
then
1994 raise Program_Error
;
2000 if Op_Name
= Name_Op_Add
then
2002 elsif Op_Name
= Name_Op_Subtract
then
2004 elsif Op_Name
= Name_Op_Abs
then
2006 elsif Op_Name
= Name_Op_Not
then
2009 raise Program_Error
;
2016 ----------------------------
2017 -- Preanalyze_And_Resolve --
2018 ----------------------------
2020 procedure Preanalyze_And_Resolve
2023 With_Freezing
: Boolean)
2025 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
2026 Save_Must_Not_Freeze
: constant Boolean := Must_Not_Freeze
(N
);
2027 Save_Preanalysis_Count
: constant Nat
:=
2028 Inside_Preanalysis_Without_Freezing
;
2030 pragma Assert
(Nkind
(N
) in N_Subexpr
);
2032 if not With_Freezing
then
2033 Set_Must_Not_Freeze
(N
);
2034 Inside_Preanalysis_Without_Freezing
:=
2035 Inside_Preanalysis_Without_Freezing
+ 1;
2038 Full_Analysis
:= False;
2039 Expander_Mode_Save_And_Set
(False);
2041 -- See also Preanalyze_And_Resolve in sem.adb for similar handling
2043 -- Normally, we suppress all checks for this preanalysis. There is no
2044 -- point in processing them now, since they will be applied properly
2045 -- and in the proper location when the default expressions reanalyzed
2046 -- and reexpanded later on. We will also have more information at that
2047 -- point for possible suppression of individual checks.
2049 -- However, in GNATprove mode, most expansion is suppressed, and this
2050 -- later reanalysis and reexpansion may not occur. GNATprove mode does
2051 -- require the setting of checking flags for proof purposes, so we
2052 -- do the GNATprove preanalysis without suppressing checks.
2054 -- This special handling for SPARK mode is required for example in the
2055 -- case of Ada 2012 constructs such as quantified expressions, which are
2056 -- expanded in two separate steps.
2058 -- We also do not want to suppress checks if we are not dealing
2059 -- with a default expression. One such case that is known to reach
2060 -- this point is the expression of an expression function.
2062 if GNATprove_Mode
or Nkind
(Parent
(N
)) = N_Simple_Return_Statement
then
2063 Analyze_And_Resolve
(N
, T
);
2065 Analyze_And_Resolve
(N
, T
, Suppress
=> All_Checks
);
2068 Expander_Mode_Restore
;
2069 Full_Analysis
:= Save_Full_Analysis
;
2071 if not With_Freezing
then
2072 Set_Must_Not_Freeze
(N
, Save_Must_Not_Freeze
);
2073 Inside_Preanalysis_Without_Freezing
:=
2074 Inside_Preanalysis_Without_Freezing
- 1;
2078 (Inside_Preanalysis_Without_Freezing
= Save_Preanalysis_Count
);
2079 end Preanalyze_And_Resolve
;
2081 ----------------------------
2082 -- Preanalyze_And_Resolve --
2083 ----------------------------
2085 procedure Preanalyze_And_Resolve
(N
: Node_Id
; T
: Entity_Id
) is
2087 Preanalyze_And_Resolve
(N
, T
, With_Freezing
=> False);
2088 end Preanalyze_And_Resolve
;
2090 -- Version without context type
2092 procedure Preanalyze_And_Resolve
(N
: Node_Id
) is
2093 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
2096 Full_Analysis
:= False;
2097 Expander_Mode_Save_And_Set
(False);
2100 Resolve
(N
, Etype
(N
), Suppress
=> All_Checks
);
2102 Expander_Mode_Restore
;
2103 Full_Analysis
:= Save_Full_Analysis
;
2104 end Preanalyze_And_Resolve
;
2106 ------------------------------------------
2107 -- Preanalyze_With_Freezing_And_Resolve --
2108 ------------------------------------------
2110 procedure Preanalyze_With_Freezing_And_Resolve
2115 Preanalyze_And_Resolve
(N
, T
, With_Freezing
=> True);
2116 end Preanalyze_With_Freezing_And_Resolve
;
2118 ----------------------------------
2119 -- Replace_Actual_Discriminants --
2120 ----------------------------------
2122 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
) is
2123 Loc
: constant Source_Ptr
:= Sloc
(N
);
2124 Tsk
: Node_Id
:= Empty
;
2126 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
;
2127 -- Comment needed???
2133 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
is
2137 if Nkind
(Nod
) = N_Identifier
then
2138 Ent
:= Entity
(Nod
);
2141 and then Ekind
(Ent
) = E_Discriminant
2144 Make_Selected_Component
(Loc
,
2145 Prefix
=> New_Copy_Tree
(Tsk
, New_Sloc
=> Loc
),
2146 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Ent
))));
2148 Set_Etype
(Nod
, Etype
(Ent
));
2156 procedure Replace_Discrs
is new Traverse_Proc
(Process_Discr
);
2158 -- Start of processing for Replace_Actual_Discriminants
2161 if Expander_Active
then
2164 -- Allow the replacement of concurrent discriminants in GNATprove even
2165 -- though this is a light expansion activity. Note that generic units
2166 -- are not modified.
2168 elsif GNATprove_Mode
and not Inside_A_Generic
then
2175 if Nkind
(Name
(N
)) = N_Selected_Component
then
2176 Tsk
:= Prefix
(Name
(N
));
2178 elsif Nkind
(Name
(N
)) = N_Indexed_Component
then
2179 Tsk
:= Prefix
(Prefix
(Name
(N
)));
2182 if Present
(Tsk
) then
2183 Replace_Discrs
(Default
);
2185 end Replace_Actual_Discriminants
;
2191 procedure Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
2192 Ambiguous
: Boolean := False;
2193 Ctx_Type
: Entity_Id
:= Typ
;
2194 Expr_Type
: Entity_Id
:= Empty
; -- prevent junk warning
2195 Err_Type
: Entity_Id
:= Empty
;
2196 Found
: Boolean := False;
2199 I1
: Interp_Index
:= 0; -- prevent junk warning
2202 Seen
: Entity_Id
:= Empty
; -- prevent junk warning
2204 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean;
2205 -- Determine whether a node comes from a predefined library unit or
2208 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
);
2209 -- Try and fix up a literal so that it matches its expected type. New
2210 -- literals are manufactured if necessary to avoid cascaded errors.
2212 procedure Report_Ambiguous_Argument
;
2213 -- Additional diagnostics when an ambiguous call has an ambiguous
2214 -- argument (typically a controlling actual).
2216 procedure Resolution_Failed
;
2217 -- Called when attempt at resolving current expression fails
2219 ------------------------------------
2220 -- Comes_From_Predefined_Lib_Unit --
2221 -------------------------------------
2223 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean is
2226 Sloc
(Nod
) = Standard_Location
or else In_Predefined_Unit
(Nod
);
2227 end Comes_From_Predefined_Lib_Unit
;
2229 --------------------
2230 -- Patch_Up_Value --
2231 --------------------
2233 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
) is
2235 if Nkind
(N
) = N_Integer_Literal
and then Is_Real_Type
(Typ
) then
2237 Make_Real_Literal
(Sloc
(N
),
2238 Realval
=> UR_From_Uint
(Intval
(N
))));
2239 Set_Etype
(N
, Universal_Real
);
2240 Set_Is_Static_Expression
(N
);
2242 elsif Nkind
(N
) = N_Real_Literal
and then Is_Integer_Type
(Typ
) then
2244 Make_Integer_Literal
(Sloc
(N
),
2245 Intval
=> UR_To_Uint
(Realval
(N
))));
2246 Set_Etype
(N
, Universal_Integer
);
2247 Set_Is_Static_Expression
(N
);
2249 elsif Nkind
(N
) = N_String_Literal
2250 and then Is_Character_Type
(Typ
)
2252 Set_Character_Literal_Name
(Get_Char_Code
('A'));
2254 Make_Character_Literal
(Sloc
(N
),
2256 Char_Literal_Value
=>
2257 UI_From_CC
(Get_Char_Code
('A'))));
2258 Set_Etype
(N
, Any_Character
);
2259 Set_Is_Static_Expression
(N
);
2261 elsif Nkind
(N
) /= N_String_Literal
and then Is_String_Type
(Typ
) then
2263 Make_String_Literal
(Sloc
(N
),
2264 Strval
=> End_String
));
2266 elsif Nkind
(N
) = N_Range
then
2267 Patch_Up_Value
(Low_Bound
(N
), Typ
);
2268 Patch_Up_Value
(High_Bound
(N
), Typ
);
2272 -------------------------------
2273 -- Report_Ambiguous_Argument --
2274 -------------------------------
2276 procedure Report_Ambiguous_Argument
is
2277 Arg
: constant Node_Id
:= First
(Parameter_Associations
(N
));
2282 if Nkind
(Arg
) = N_Function_Call
2283 and then Is_Entity_Name
(Name
(Arg
))
2284 and then Is_Overloaded
(Name
(Arg
))
2286 Error_Msg_NE
("ambiguous call to&", Arg
, Name
(Arg
));
2288 -- Examine possible interpretations, and adapt the message
2289 -- for inherited subprograms declared by a type derivation.
2291 Get_First_Interp
(Name
(Arg
), I
, It
);
2292 while Present
(It
.Nam
) loop
2293 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2295 if Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
then
2296 Error_Msg_N
("interpretation (inherited) #!", Arg
);
2298 Error_Msg_N
("interpretation #!", Arg
);
2301 Get_Next_Interp
(I
, It
);
2305 -- Additional message and hint if the ambiguity involves an Ada 2022
2306 -- container aggregate.
2308 Check_Ambiguous_Aggregate
(N
);
2309 end Report_Ambiguous_Argument
;
2311 -----------------------
2312 -- Resolution_Failed --
2313 -----------------------
2315 procedure Resolution_Failed
is
2317 Patch_Up_Value
(N
, Typ
);
2319 -- Set the type to the desired one to minimize cascaded errors. Note
2320 -- that this is an approximation and does not work in all cases.
2324 Debug_A_Exit
("resolving ", N
, " (done, resolution failed)");
2325 Set_Is_Overloaded
(N
, False);
2327 -- The caller will return without calling the expander, so we need
2328 -- to set the analyzed flag. Note that it is fine to set Analyzed
2329 -- to True even if we are in the middle of a shallow analysis,
2330 -- (see the spec of sem for more details) since this is an error
2331 -- situation anyway, and there is no point in repeating the
2332 -- analysis later (indeed it won't work to repeat it later, since
2333 -- we haven't got a clear resolution of which entity is being
2336 Set_Analyzed
(N
, True);
2338 end Resolution_Failed
;
2340 -- Start of processing for Resolve
2347 -- Access attribute on remote subprogram cannot be used for a non-remote
2348 -- access-to-subprogram type.
2350 if Nkind
(N
) = N_Attribute_Reference
2351 and then Attribute_Name
(N
) in Name_Access
2352 | Name_Unrestricted_Access
2353 | Name_Unchecked_Access
2354 and then Comes_From_Source
(N
)
2355 and then Is_Entity_Name
(Prefix
(N
))
2356 and then Is_Subprogram
(Entity
(Prefix
(N
)))
2357 and then Is_Remote_Call_Interface
(Entity
(Prefix
(N
)))
2358 and then not Is_Remote_Access_To_Subprogram_Type
(Typ
)
2361 ("prefix must statically denote a non-remote subprogram", N
);
2364 -- If the context is a Remote_Access_To_Subprogram, access attributes
2365 -- must be resolved with the corresponding fat pointer. There is no need
2366 -- to check for the attribute name since the return type of an
2367 -- attribute is never a remote type.
2369 if Nkind
(N
) = N_Attribute_Reference
2370 and then Comes_From_Source
(N
)
2371 and then (Is_Remote_Call_Interface
(Typ
) or else Is_Remote_Types
(Typ
))
2374 Attr
: constant Attribute_Id
:=
2375 Get_Attribute_Id
(Attribute_Name
(N
));
2376 Pref
: constant Node_Id
:= Prefix
(N
);
2379 Is_Remote
: Boolean := True;
2382 -- Check that Typ is a remote access-to-subprogram type
2384 if Is_Remote_Access_To_Subprogram_Type
(Typ
) then
2386 -- Prefix (N) must statically denote a remote subprogram
2387 -- declared in a package specification.
2389 if Attr
= Attribute_Access
or else
2390 Attr
= Attribute_Unchecked_Access
or else
2391 Attr
= Attribute_Unrestricted_Access
2393 Decl
:= Unit_Declaration_Node
(Entity
(Pref
));
2395 if Nkind
(Decl
) = N_Subprogram_Body
then
2396 Spec
:= Corresponding_Spec
(Decl
);
2398 if Present
(Spec
) then
2399 Decl
:= Unit_Declaration_Node
(Spec
);
2403 Spec
:= Parent
(Decl
);
2405 if not Is_Entity_Name
(Prefix
(N
))
2406 or else Nkind
(Spec
) /= N_Package_Specification
2408 not Is_Remote_Call_Interface
(Defining_Entity
(Spec
))
2412 ("prefix must statically denote a remote subprogram",
2416 -- If we are generating code in distributed mode, perform
2417 -- semantic checks against corresponding remote entities.
2420 and then Get_PCS_Name
/= Name_No_DSA
2422 Check_Subtype_Conformant
2423 (New_Id
=> Entity
(Prefix
(N
)),
2424 Old_Id
=> Designated_Type
2425 (Corresponding_Remote_Type
(Typ
)),
2429 Process_Remote_AST_Attribute
(N
, Typ
);
2437 Debug_A_Entry
("resolving ", N
);
2439 if Debug_Flag_V
then
2440 Write_Overloads
(N
);
2443 if Comes_From_Source
(N
) then
2444 if Is_Fixed_Point_Type
(Typ
) then
2445 Check_Restriction
(No_Fixed_Point
, N
);
2447 elsif Is_Floating_Point_Type
(Typ
)
2448 and then Typ
/= Universal_Real
2449 and then Typ
/= Any_Real
2451 Check_Restriction
(No_Floating_Point
, N
);
2455 -- Return if already analyzed
2457 if Analyzed
(N
) then
2458 Debug_A_Exit
("resolving ", N
, " (done, already analyzed)");
2459 Analyze_Dimension
(N
);
2462 -- Any case of Any_Type as the Etype value means that we had a
2465 elsif Etype
(N
) = Any_Type
then
2466 Debug_A_Exit
("resolving ", N
, " (done, Etype = Any_Type)");
2470 Check_Parameterless_Call
(N
);
2472 -- The resolution of an Expression_With_Actions is determined by
2473 -- its Expression, but if the node comes from source it is a
2474 -- Declare_Expression and requires scope management.
2476 if Nkind
(N
) = N_Expression_With_Actions
then
2477 if Comes_From_Source
(N
) and then not Is_Rewrite_Substitution
(N
) then
2478 Resolve_Declare_Expression
(N
, Typ
);
2480 Resolve
(Expression
(N
), Typ
);
2484 Expr_Type
:= Etype
(Expression
(N
));
2486 -- The resolution of a conditional expression that is the operand of a
2487 -- type conversion is determined by the conversion (RM 4.5.7(10/3)).
2489 elsif Nkind
(N
) in N_Case_Expression | N_If_Expression
2490 and then Nkind
(Parent
(N
)) = N_Type_Conversion
2493 Expr_Type
:= Etype
(Parent
(N
));
2495 -- If not overloaded, then we know the type, and all that needs doing
2496 -- is to check that this type is compatible with the context. But note
2497 -- that we may have an operator with no interpretation in Ada 2022 for
2498 -- the case of possible user-defined literals as operands.
2500 elsif not Is_Overloaded
(N
) then
2501 if Nkind
(N
) in N_Op
and then No
(Entity
(N
)) then
2502 pragma Assert
(Ada_Version
>= Ada_2022
);
2505 Found
:= Covers
(Typ
, Etype
(N
));
2507 Expr_Type
:= Etype
(N
);
2509 -- In the overloaded case, we must select the interpretation that
2510 -- is compatible with the context (i.e. the type passed to Resolve)
2513 From_Lib
:= Comes_From_Predefined_Lib_Unit
(N
);
2515 -- Loop through possible interpretations
2517 Get_First_Interp
(N
, I
, It
);
2518 Interp_Loop
: while Present
(It
.Typ
) loop
2519 if Debug_Flag_V
then
2520 Write_Str
("Interp: ");
2524 -- We are only interested in interpretations that are compatible
2525 -- with the expected type, any other interpretations are ignored.
2527 if not Covers
(Typ
, It
.Typ
) then
2528 if Debug_Flag_V
then
2529 Write_Str
(" interpretation incompatible with context");
2534 -- Skip the current interpretation if it is disabled by an
2535 -- abstract operator. This action is performed only when the
2536 -- type against which we are resolving is the same as the
2537 -- type of the interpretation.
2539 if Ada_Version
>= Ada_2005
2540 and then It
.Typ
= Typ
2541 and then not Is_Universal_Numeric_Type
(Typ
)
2542 and then Present
(It
.Abstract_Op
)
2544 if Debug_Flag_V
then
2545 Write_Line
("Skip.");
2551 -- First matching interpretation
2557 Expr_Type
:= It
.Typ
;
2559 -- Matching interpretation that is not the first, maybe an
2560 -- error, but there are some cases where preference rules are
2561 -- used to choose between the two possibilities. These and
2562 -- some more obscure cases are handled in Disambiguate.
2565 -- If the current statement is part of a predefined library
2566 -- unit, then all interpretations which come from user level
2567 -- packages should not be considered. Check previous and
2571 if not Comes_From_Predefined_Lib_Unit
(It
.Nam
) then
2574 elsif not Comes_From_Predefined_Lib_Unit
(Seen
) then
2576 -- Previous interpretation must be discarded
2580 Expr_Type
:= It
.Typ
;
2581 Set_Entity
(N
, Seen
);
2586 -- Otherwise apply further disambiguation steps
2588 Error_Msg_Sloc
:= Sloc
(Seen
);
2589 It1
:= Disambiguate
(N
, I1
, I
, Typ
);
2591 -- Disambiguation has succeeded. Skip the remaining
2594 if It1
/= No_Interp
then
2596 Expr_Type
:= It1
.Typ
;
2598 while Present
(It
.Typ
) loop
2599 Get_Next_Interp
(I
, It
);
2603 -- Before we issue an ambiguity complaint, check for the
2604 -- case of a subprogram call where at least one of the
2605 -- arguments is Any_Type, and if so suppress the message,
2606 -- since it is a cascaded error. This can also happen for
2607 -- a generalized indexing operation.
2609 if Nkind
(N
) in N_Subprogram_Call
2610 or else (Nkind
(N
) = N_Indexed_Component
2611 and then Present
(Generalized_Indexing
(N
)))
2618 if Nkind
(N
) = N_Indexed_Component
then
2619 Rewrite
(N
, Generalized_Indexing
(N
));
2622 A
:= First_Actual
(N
);
2623 while Present
(A
) loop
2626 if Nkind
(E
) = N_Parameter_Association
then
2627 E
:= Explicit_Actual_Parameter
(E
);
2630 if Etype
(E
) = Any_Type
then
2631 if Debug_Flag_V
then
2632 Write_Str
("Any_Type in call");
2643 elsif Nkind
(N
) in N_Binary_Op
2644 and then (Etype
(Left_Opnd
(N
)) = Any_Type
2645 or else Etype
(Right_Opnd
(N
)) = Any_Type
)
2649 elsif Nkind
(N
) in N_Unary_Op
2650 and then Etype
(Right_Opnd
(N
)) = Any_Type
2655 -- Not that special case, so issue message using the flag
2656 -- Ambiguous to control printing of the header message
2657 -- only at the start of an ambiguous set.
2659 if not Ambiguous
then
2660 if Nkind
(N
) = N_Function_Call
2661 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2664 ("ambiguous expression (cannot resolve indirect "
2667 Error_Msg_NE
-- CODEFIX
2668 ("ambiguous expression (cannot resolve&)!",
2674 if Nkind
(Parent
(Seen
)) = N_Full_Type_Declaration
then
2676 ("\\possible interpretation (inherited)#!", N
);
2678 Error_Msg_N
-- CODEFIX
2679 ("\\possible interpretation#!", N
);
2682 if Nkind
(N
) in N_Subprogram_Call
2683 and then Present
(Parameter_Associations
(N
))
2685 Report_Ambiguous_Argument
;
2689 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2691 -- By default, the error message refers to the candidate
2692 -- interpretation. But if it is a predefined operator, it
2693 -- is implicitly declared at the declaration of the type
2694 -- of the operand. Recover the sloc of that declaration
2695 -- for the error message.
2697 if Nkind
(N
) in N_Op
2698 and then Scope
(It
.Nam
) = Standard_Standard
2699 and then not Is_Overloaded
(Right_Opnd
(N
))
2700 and then Scope
(Base_Type
(Etype
(Right_Opnd
(N
)))) /=
2703 Err_Type
:= First_Subtype
(Etype
(Right_Opnd
(N
)));
2705 if Comes_From_Source
(Err_Type
)
2706 and then Present
(Parent
(Err_Type
))
2708 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2711 elsif Nkind
(N
) in N_Binary_Op
2712 and then Scope
(It
.Nam
) = Standard_Standard
2713 and then not Is_Overloaded
(Left_Opnd
(N
))
2714 and then Scope
(Base_Type
(Etype
(Left_Opnd
(N
)))) /=
2717 Err_Type
:= First_Subtype
(Etype
(Left_Opnd
(N
)));
2719 if Comes_From_Source
(Err_Type
)
2720 and then Present
(Parent
(Err_Type
))
2722 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2725 -- If this is an indirect call, use the subprogram_type
2726 -- in the message, to have a meaningful location. Also
2727 -- indicate if this is an inherited operation, created
2728 -- by a type declaration.
2730 elsif Nkind
(N
) = N_Function_Call
2731 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2732 and then Is_Type
(It
.Nam
)
2736 Sloc
(Associated_Node_For_Itype
(Err_Type
));
2741 if Nkind
(N
) in N_Op
2742 and then Scope
(It
.Nam
) = Standard_Standard
2743 and then Present
(Err_Type
)
2745 -- Special-case the message for universal_fixed
2746 -- operators, which are not declared with the type
2747 -- of the operand, but appear forever in Standard.
2749 if It
.Typ
= Universal_Fixed
2750 and then Scope
(It
.Nam
) = Standard_Standard
2753 ("\\possible interpretation as universal_fixed "
2754 & "operation (RM 4.5.5 (19))", N
);
2757 ("\\possible interpretation (predefined)#!", N
);
2761 Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
2764 ("\\possible interpretation (inherited)#!", N
);
2766 Error_Msg_N
-- CODEFIX
2767 ("\\possible interpretation#!", N
);
2773 -- We have a matching interpretation, Expr_Type is the type
2774 -- from this interpretation, and Seen is the entity.
2776 -- For an operator, just set the entity name. The type will be
2777 -- set by the specific operator resolution routine.
2779 if Nkind
(N
) in N_Op
then
2780 Set_Entity
(N
, Seen
);
2781 Generate_Reference
(Seen
, N
);
2783 elsif Nkind
(N
) in N_Case_Expression
2784 | N_Character_Literal
2788 Set_Etype
(N
, Expr_Type
);
2790 -- AI05-0139-2: Expression is overloaded because type has
2791 -- implicit dereference. The context may be the one that
2792 -- requires implicit dereferemce.
2794 elsif Has_Implicit_Dereference
(Expr_Type
) then
2795 Set_Etype
(N
, Expr_Type
);
2796 Set_Is_Overloaded
(N
, False);
2798 -- If the expression is an entity, generate a reference
2799 -- to it, as this is not done for an overloaded construct
2802 if Is_Entity_Name
(N
)
2803 and then Comes_From_Source
(N
)
2805 Generate_Reference
(Entity
(N
), N
);
2807 -- Examine access discriminants of entity type,
2808 -- to check whether one of them yields the
2813 First_Discriminant
(Etype
(Entity
(N
)));
2816 while Present
(Disc
) loop
2817 exit when Is_Access_Type
(Etype
(Disc
))
2818 and then Has_Implicit_Dereference
(Disc
)
2819 and then Designated_Type
(Etype
(Disc
)) = Typ
;
2821 Next_Discriminant
(Disc
);
2824 if Present
(Disc
) then
2825 Build_Explicit_Dereference
(N
, Disc
);
2832 elsif Is_Overloaded
(N
)
2833 and then Present
(It
.Nam
)
2834 and then Ekind
(It
.Nam
) = E_Discriminant
2835 and then Has_Implicit_Dereference
(It
.Nam
)
2837 -- If the node is a general indexing, the dereference is
2838 -- is inserted when resolving the rewritten form, else
2841 if Nkind
(N
) /= N_Indexed_Component
2842 or else No
(Generalized_Indexing
(N
))
2844 Build_Explicit_Dereference
(N
, It
.Nam
);
2847 -- For an explicit dereference, attribute reference, range,
2848 -- short-circuit form (which is not an operator node), or call
2849 -- with a name that is an explicit dereference, there is
2850 -- nothing to be done at this point.
2852 elsif Nkind
(N
) in N_Attribute_Reference
2854 | N_Explicit_Dereference
2856 | N_Indexed_Component
2859 | N_Selected_Component
2861 or else Nkind
(Name
(N
)) = N_Explicit_Dereference
2865 -- For procedure or function calls, set the type of the name,
2866 -- and also the entity pointer for the prefix.
2868 elsif Nkind
(N
) in N_Subprogram_Call
2869 and then Is_Entity_Name
(Name
(N
))
2871 Set_Etype
(Name
(N
), Expr_Type
);
2872 Set_Entity
(Name
(N
), Seen
);
2873 Generate_Reference
(Seen
, Name
(N
));
2875 elsif Nkind
(N
) = N_Function_Call
2876 and then Nkind
(Name
(N
)) = N_Selected_Component
2878 Set_Etype
(Name
(N
), Expr_Type
);
2879 Set_Entity
(Selector_Name
(Name
(N
)), Seen
);
2880 Generate_Reference
(Seen
, Selector_Name
(Name
(N
)));
2882 -- For all other cases, just set the type of the Name
2885 Set_Etype
(Name
(N
), Expr_Type
);
2892 -- Move to next interpretation
2894 exit Interp_Loop
when No
(It
.Typ
);
2896 Get_Next_Interp
(I
, It
);
2897 end loop Interp_Loop
;
2900 -- At this stage Found indicates whether or not an acceptable
2901 -- interpretation exists. If not, then we have an error, except that if
2902 -- the context is Any_Type as a result of some other error, then we
2903 -- suppress the error report.
2906 if Typ
/= Any_Type
then
2908 -- If type we are looking for is Void, then this is the procedure
2909 -- call case, and the error is simply that what we gave is not a
2910 -- procedure name (we think of procedure calls as expressions with
2911 -- types internally, but the user doesn't think of them this way).
2913 if Typ
= Standard_Void_Type
then
2915 -- Special case message if function used as a procedure
2917 if Nkind
(N
) = N_Procedure_Call_Statement
2918 and then Is_Entity_Name
(Name
(N
))
2919 and then Ekind
(Entity
(Name
(N
))) = E_Function
2922 ("cannot use call to function & as a statement",
2923 Name
(N
), Entity
(Name
(N
)));
2925 ("\return value of a function call cannot be ignored",
2928 -- Otherwise give general message (not clear what cases this
2929 -- covers, but no harm in providing for them).
2932 Error_Msg_N
("expect procedure name in procedure call", N
);
2937 -- Otherwise we do have a subexpression with the wrong type
2939 -- Check for the case of an allocator which uses an access type
2940 -- instead of the designated type. This is a common error and we
2941 -- specialize the message, posting an error on the operand of the
2942 -- allocator, complaining that we expected the designated type of
2945 elsif Nkind
(N
) = N_Allocator
2946 and then Is_Access_Type
(Typ
)
2947 and then Is_Access_Type
(Etype
(N
))
2948 and then Designated_Type
(Etype
(N
)) = Typ
2950 Wrong_Type
(Expression
(N
), Designated_Type
(Typ
));
2953 -- Check for view mismatch on Null in instances, for which the
2954 -- view-swapping mechanism has no identifier.
2956 elsif (In_Instance
or else In_Inlined_Body
)
2957 and then Nkind
(N
) = N_Null
2958 and then Is_Private_Type
(Typ
)
2959 and then Is_Access_Type
(Full_View
(Typ
))
2961 Resolve
(N
, Full_View
(Typ
));
2965 -- Check for an aggregate. Sometimes we can get bogus aggregates
2966 -- from misuse of parentheses, and we are about to complain about
2967 -- the aggregate without even looking inside it.
2969 -- Instead, if we have an aggregate of type Any_Composite, then
2970 -- analyze and resolve the component fields, and then only issue
2971 -- another message if we get no errors doing this (otherwise
2972 -- assume that the errors in the aggregate caused the problem).
2974 elsif Nkind
(N
) = N_Aggregate
2975 and then Etype
(N
) = Any_Composite
2977 if Ada_Version
>= Ada_2022
2978 and then Has_Aspect
(Typ
, Aspect_Aggregate
)
2980 Resolve_Container_Aggregate
(N
, Typ
);
2982 if Expander_Active
then
2988 -- Disable expansion in any case. If there is a type mismatch
2989 -- it may be fatal to try to expand the aggregate. The flag
2990 -- would otherwise be set to false when the error is posted.
2992 Expander_Active
:= False;
2995 procedure Check_Aggr
(Aggr
: Node_Id
);
2996 -- Check one aggregate, and set Found to True if we have a
2997 -- definite error in any of its elements
2999 procedure Check_Elmt
(Aelmt
: Node_Id
);
3000 -- Check one element of aggregate and set Found to True if
3001 -- we definitely have an error in the element.
3007 procedure Check_Aggr
(Aggr
: Node_Id
) is
3011 if Present
(Expressions
(Aggr
)) then
3012 Elmt
:= First
(Expressions
(Aggr
));
3013 while Present
(Elmt
) loop
3019 if Present
(Component_Associations
(Aggr
)) then
3020 Elmt
:= First
(Component_Associations
(Aggr
));
3021 while Present
(Elmt
) loop
3023 -- If this is a default-initialized component, then
3024 -- there is nothing to check. The box will be
3025 -- replaced by the appropriate call during late
3028 if Nkind
(Elmt
) /= N_Iterated_Component_Association
3029 and then not Box_Present
(Elmt
)
3031 Check_Elmt
(Expression
(Elmt
));
3043 procedure Check_Elmt
(Aelmt
: Node_Id
) is
3045 -- If we have a nested aggregate, go inside it (to
3046 -- attempt a naked analyze-resolve of the aggregate can
3047 -- cause undesirable cascaded errors). Do not resolve
3048 -- expression if it needs a type from context, as for
3049 -- integer * fixed expression.
3051 if Nkind
(Aelmt
) = N_Aggregate
then
3057 if not Is_Overloaded
(Aelmt
)
3058 and then Etype
(Aelmt
) /= Any_Fixed
3063 if Etype
(Aelmt
) = Any_Type
then
3074 -- Check whether the node is a literal or a named number or a
3075 -- conditional expression whose dependent expressions are all
3076 -- literals or named numbers.
3078 if Try_User_Defined_Literal
(N
, Typ
) then
3082 -- Looks like we have a type error, but check for special case
3083 -- of Address wanted, integer found, with the configuration pragma
3084 -- Allow_Integer_Address active. If we have this case, introduce
3085 -- an unchecked conversion to allow the integer expression to be
3086 -- treated as an Address. The reverse case of integer wanted,
3087 -- Address found, is treated in an analogous manner.
3089 if Address_Integer_Convert_OK
(Typ
, Etype
(N
)) then
3090 Rewrite
(N
, Unchecked_Convert_To
(Typ
, Relocate_Node
(N
)));
3091 Analyze_And_Resolve
(N
, Typ
);
3094 -- Under relaxed RM semantics silently replace occurrences of null
3095 -- by System.Null_Address.
3097 elsif Null_To_Null_Address_Convert_OK
(N
, Typ
) then
3098 Replace_Null_By_Null_Address
(N
);
3099 Analyze_And_Resolve
(N
, Typ
);
3103 -- That special Allow_Integer_Address check did not apply, so we
3104 -- have a real type error. If an error message was issued already,
3105 -- Found got reset to True, so if it's still False, issue standard
3106 -- Wrong_Type message.
3109 if Is_Overloaded
(N
) and then Nkind
(N
) = N_Function_Call
then
3111 Subp_Name
: Node_Id
;
3114 if Is_Entity_Name
(Name
(N
)) then
3115 Subp_Name
:= Name
(N
);
3117 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
3119 -- Protected operation: retrieve operation name
3121 Subp_Name
:= Selector_Name
(Name
(N
));
3124 raise Program_Error
;
3127 Error_Msg_Node_2
:= Typ
;
3129 ("no visible interpretation of& matches expected type&",
3133 if All_Errors_Mode
then
3135 Index
: Interp_Index
;
3139 Error_Msg_N
("\\possible interpretations:", N
);
3141 Get_First_Interp
(Name
(N
), Index
, It
);
3142 while Present
(It
.Nam
) loop
3143 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
3144 Error_Msg_Node_2
:= It
.Nam
;
3146 ("\\ type& for & declared#", N
, It
.Typ
);
3147 Get_Next_Interp
(Index
, It
);
3152 Error_Msg_N
("\use -gnatf for details", N
);
3155 -- Recognize the case of a quantified expression being mistaken
3156 -- for an iterated component association because the user
3157 -- forgot the "all" or "some" keyword after "for". Because the
3158 -- error message starts with "missing ALL", we automatically
3159 -- benefit from the associated CODEFIX, which requires that
3160 -- the message is located on the identifier following "for"
3161 -- in order for the CODEFIX to insert "all" in the right place.
3163 elsif Nkind
(N
) = N_Aggregate
3164 and then List_Length
(Component_Associations
(N
)) = 1
3165 and then Nkind
(First
(Component_Associations
(N
)))
3166 = N_Iterated_Component_Association
3167 and then Is_Boolean_Type
(Typ
)
3170 (Iterator_Specification
3171 (First
(Component_Associations
(N
))))
3173 Error_Msg_N
-- CODEFIX
3174 ("missing ALL or SOME in quantified expression",
3176 (Iterator_Specification
3177 (First
(Component_Associations
(N
)))));
3179 Error_Msg_N
-- CODEFIX
3180 ("missing ALL or SOME in quantified expression",
3182 (First
(Component_Associations
(N
))));
3185 -- For an operator with no interpretation, check whether one of
3186 -- its operands may be a user-defined literal.
3188 elsif Nkind
(N
) in N_Op
and then No
(Entity
(N
)) then
3189 if Try_User_Defined_Literal_For_Operator
(N
, Typ
) then
3192 Unresolved_Operator
(N
);
3196 Wrong_Type
(N
, Typ
);
3204 -- Test if we have more than one interpretation for the context
3206 elsif Ambiguous
then
3210 -- Only one interpretation
3213 -- Prevent implicit conversions between access-to-subprogram types
3214 -- with different strub modes. Explicit conversions are acceptable in
3215 -- some circumstances. We don't have to be concerned about data or
3216 -- access-to-data types. Conversions between data types can safely
3217 -- drop or add strub attributes from types, because strub effects are
3218 -- associated with the locations rather than values. E.g., converting
3219 -- a hypothetical Strub_Integer variable to Integer would load the
3220 -- value from the variable, enabling stack scrabbing for the
3221 -- enclosing subprogram, and then convert the value to Integer. As
3222 -- for conversions between access-to-data types, that's no different
3223 -- from any other case of type punning.
3225 if Is_Access_Type
(Typ
)
3226 and then Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
3227 and then Is_Access_Type
(Expr_Type
)
3228 and then Ekind
(Designated_Type
(Expr_Type
)) = E_Subprogram_Type
3230 Check_Same_Strub_Mode
3231 (Designated_Type
(Typ
), Designated_Type
(Expr_Type
));
3234 -- In Ada 2005, if we have something like "X : T := 2 + 2;", where
3235 -- the "+" on T is abstract, and the operands are of universal type,
3236 -- the above code will have (incorrectly) resolved the "+" to the
3237 -- universal one in Standard. Therefore check for this case and give
3238 -- an error. We can't do this earlier, because it would cause legal
3239 -- cases to get errors (when some other type has an abstract "+").
3241 if Ada_Version
>= Ada_2005
3242 and then Nkind
(N
) in N_Op
3243 and then Is_Overloaded
(N
)
3244 and then Is_Universal_Numeric_Type
(Etype
(Entity
(N
)))
3246 Get_First_Interp
(N
, I
, It
);
3247 while Present
(It
.Typ
) loop
3248 if Present
(It
.Abstract_Op
)
3249 and then Etype
(It
.Abstract_Op
) = Typ
3251 Nondispatching_Call_To_Abstract_Operation
3252 (N
, It
.Abstract_Op
);
3256 Get_Next_Interp
(I
, It
);
3260 -- Here we have an acceptable interpretation for the context
3262 -- Propagate type information and normalize tree for various
3263 -- predefined operations. If the context only imposes a class of
3264 -- types, rather than a specific type, propagate the actual type
3267 if Typ
= Any_Integer
or else
3268 Typ
= Any_Boolean
or else
3269 Typ
= Any_Modular
or else
3270 Typ
= Any_Real
or else
3273 Ctx_Type
:= Expr_Type
;
3275 -- Any_Fixed is legal in a real context only if a specific fixed-
3276 -- point type is imposed. If Norman Cohen can be confused by this,
3277 -- it deserves a separate message.
3280 and then Expr_Type
= Any_Fixed
3282 Error_Msg_N
("illegal context for mixed mode operation", N
);
3283 Set_Etype
(N
, Universal_Real
);
3284 Ctx_Type
:= Universal_Real
;
3288 -- A user-defined operator is transformed into a function call at
3289 -- this point, so that further processing knows that operators are
3290 -- really operators (i.e. are predefined operators). User-defined
3291 -- operators that are intrinsic are just renamings of the predefined
3292 -- ones, and need not be turned into calls either, but if they rename
3293 -- a different operator, we must transform the node accordingly.
3294 -- Instantiations of Unchecked_Conversion are intrinsic but are
3295 -- treated as functions, even if given an operator designator.
3297 if Nkind
(N
) in N_Op
3298 and then Present
(Entity
(N
))
3299 and then Ekind
(Entity
(N
)) /= E_Operator
3301 if not Is_Predefined_Op
(Entity
(N
)) then
3302 Rewrite_Operator_As_Call
(N
, Entity
(N
));
3304 elsif Present
(Alias
(Entity
(N
)))
3306 Nkind
(Parent
(Parent
(Entity
(N
)))) =
3307 N_Subprogram_Renaming_Declaration
3309 Rewrite_Renamed_Operator
(N
, Alias
(Entity
(N
)), Typ
);
3311 -- If the node is rewritten, it will be fully resolved in
3312 -- Rewrite_Renamed_Operator.
3314 if Analyzed
(N
) then
3320 case N_Subexpr
'(Nkind (N)) is
3322 Resolve_Aggregate (N, Ctx_Type);
3325 Resolve_Allocator (N, Ctx_Type);
3327 when N_Short_Circuit =>
3328 Resolve_Short_Circuit (N, Ctx_Type);
3330 when N_Attribute_Reference =>
3331 Resolve_Attribute (N, Ctx_Type);
3333 when N_Case_Expression =>
3334 Resolve_Case_Expression (N, Ctx_Type);
3336 when N_Character_Literal =>
3337 Resolve_Character_Literal (N, Ctx_Type);
3339 when N_Delta_Aggregate =>
3340 Resolve_Delta_Aggregate (N, Ctx_Type);
3342 when N_Expanded_Name =>
3343 Resolve_Entity_Name (N, Ctx_Type);
3345 when N_Explicit_Dereference =>
3346 Resolve_Explicit_Dereference (N, Ctx_Type);
3348 when N_Expression_With_Actions =>
3349 Resolve_Expression_With_Actions (N, Ctx_Type);
3351 when N_Extension_Aggregate =>
3352 Resolve_Extension_Aggregate (N, Ctx_Type);
3354 when N_Function_Call =>
3355 Resolve_Call (N, Ctx_Type);
3357 when N_Identifier =>
3358 Resolve_Entity_Name (N, Ctx_Type);
3360 when N_If_Expression =>
3361 Resolve_If_Expression (N, Ctx_Type);
3363 when N_Indexed_Component =>
3364 Resolve_Indexed_Component (N, Ctx_Type);
3366 when N_Integer_Literal =>
3367 Resolve_Integer_Literal (N, Ctx_Type);
3369 when N_Membership_Test =>
3370 Resolve_Membership_Op (N, Ctx_Type);
3373 Resolve_Null (N, Ctx_Type);
3379 Resolve_Logical_Op (N, Ctx_Type);
3384 Resolve_Equality_Op (N, Ctx_Type);
3391 Resolve_Comparison_Op (N, Ctx_Type);
3394 Resolve_Op_Not (N, Ctx_Type);
3403 Resolve_Arithmetic_Op (N, Ctx_Type);
3406 Resolve_Op_Concat (N, Ctx_Type);
3409 Resolve_Op_Expon (N, Ctx_Type);
3415 Resolve_Unary_Op (N, Ctx_Type);
3418 Resolve_Shift (N, Ctx_Type);
3420 when N_Procedure_Call_Statement =>
3421 Resolve_Call (N, Ctx_Type);
3423 when N_Operator_Symbol =>
3424 Resolve_Operator_Symbol (N, Ctx_Type);
3426 when N_Qualified_Expression =>
3427 Resolve_Qualified_Expression (N, Ctx_Type);
3429 -- Why is the following null, needs a comment ???
3431 when N_Quantified_Expression =>
3434 when N_Raise_Expression =>
3435 Resolve_Raise_Expression (N, Ctx_Type);
3437 when N_Raise_xxx_Error =>
3438 Set_Etype (N, Ctx_Type);
3441 Resolve_Range (N, Ctx_Type);
3443 when N_Real_Literal =>
3444 Resolve_Real_Literal (N, Ctx_Type);
3447 Resolve_Reference (N, Ctx_Type);
3449 when N_Selected_Component =>
3450 Resolve_Selected_Component (N, Ctx_Type);
3453 Resolve_Slice (N, Ctx_Type);
3455 when N_String_Literal =>
3456 Resolve_String_Literal (N, Ctx_Type);
3458 when N_Interpolated_String_Literal =>
3459 Resolve_Interpolated_String_Literal (N, Ctx_Type);
3461 when N_Target_Name =>
3462 Resolve_Target_Name (N, Ctx_Type);
3464 when N_Type_Conversion =>
3465 Resolve_Type_Conversion (N, Ctx_Type);
3467 when N_Unchecked_Expression =>
3468 Resolve_Unchecked_Expression (N, Ctx_Type);
3470 when N_Unchecked_Type_Conversion =>
3471 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
3474 -- Mark relevant use-type and use-package clauses as effective using
3475 -- the original node because constant folding may have occurred and
3476 -- removed references that need to be examined.
3478 if Nkind (Original_Node (N)) in N_Op then
3479 Mark_Use_Clauses (Original_Node (N));
3482 -- Ada 2012 (AI05-0149): Apply an (implicit) conversion to an
3483 -- expression of an anonymous access type that occurs in the context
3484 -- of a named general access type, except when the expression is that
3485 -- of a membership test. This ensures proper legality checking in
3486 -- terms of allowed conversions (expressions that would be illegal to
3487 -- convert implicitly are allowed in membership tests).
3489 if Ada_Version >= Ada_2012
3490 and then Ekind (Base_Type (Ctx_Type)) = E_General_Access_Type
3491 and then Ekind (Etype (N)) = E_Anonymous_Access_Type
3492 and then Nkind (Parent (N)) not in N_Membership_Test
3494 Rewrite (N, Convert_To (Ctx_Type, Relocate_Node (N)));
3495 Analyze_And_Resolve (N, Ctx_Type);
3498 -- If the subexpression was replaced by a non-subexpression, then
3499 -- all we do is to expand it. The only legitimate case we know of
3500 -- is converting procedure call statement to entry call statements,
3501 -- but there may be others, so we are making this test general.
3503 if Nkind (N) not in N_Subexpr then
3504 Debug_A_Exit ("resolving ", N, " (done)");
3509 -- The expression is definitely NOT overloaded at this point, so
3510 -- we reset the Is_Overloaded flag to avoid any confusion when
3511 -- reanalyzing the node.
3513 Set_Is_Overloaded (N, False);
3515 -- Freeze expression type, entity if it is a name, and designated
3516 -- type if it is an allocator (RM 13.14(10,11,13)).
3518 -- Now that the resolution of the type of the node is complete, and
3519 -- we did not detect an error, we can expand this node. We skip the
3520 -- expand call if we are in a default expression, see section
3521 -- "Handling of Default Expressions" in Sem spec.
3523 Debug_A_Exit ("resolving ", N, " (done)");
3525 -- We unconditionally freeze the expression, even if we are in
3526 -- default expression mode (the Freeze_Expression routine tests this
3527 -- flag and only freezes static types if it is set).
3529 -- Ada 2012 (AI05-177): The declaration of an expression function
3530 -- does not cause freezing, but we never reach here in that case.
3531 -- Here we are resolving the corresponding expanded body, so we do
3532 -- need to perform normal freezing.
3534 -- As elsewhere we do not emit freeze node within a generic.
3536 if not Inside_A_Generic then
3537 Freeze_Expression (N);
3540 -- Now we can do the expansion
3550 -- Version with check(s) suppressed
3552 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
3554 if Suppress = All_Checks then
3556 Sva : constant Suppress_Array := Scope_Suppress.Suppress;
3558 Scope_Suppress.Suppress := (others => True);
3560 Scope_Suppress.Suppress := Sva;
3565 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
3567 Scope_Suppress.Suppress (Suppress) := True;
3569 Scope_Suppress.Suppress (Suppress) := Svg;
3578 -- Version with implicit type
3580 procedure Resolve (N : Node_Id) is
3582 Resolve (N, Etype (N));
3585 ---------------------
3586 -- Resolve_Actuals --
3587 ---------------------
3589 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
3590 Loc : constant Source_Ptr := Sloc (N);
3592 A_Typ : Entity_Id := Empty; -- init to avoid warning
3595 Prev : Node_Id := Empty;
3597 Real_F : Entity_Id := Empty; -- init to avoid warning
3599 Real_Subp : Entity_Id;
3600 -- If the subprogram being called is an inherited operation for
3601 -- a formal derived type in an instance, Real_Subp is the subprogram
3602 -- that will be called. It may have different formal names than the
3603 -- operation of the formal in the generic, so after actual is resolved
3604 -- the name of the actual in a named association must carry the name
3605 -- of the actual of the subprogram being called.
3607 procedure Check_Aliased_Parameter;
3608 -- Check rules on aliased parameters and related accessibility rules
3609 -- in (RM 3.10.2 (10.2-10.4)).
3611 procedure Check_Argument_Order;
3612 -- Performs a check for the case where the actuals are all simple
3613 -- identifiers that correspond to the formal names, but in the wrong
3614 -- order, which is considered suspicious and cause for a warning.
3616 procedure Check_Prefixed_Call;
3617 -- If the original node is an overloaded call in prefix notation,
3618 -- insert an 'Access or a dereference as needed over the first actual
.
3619 -- Try_Object_Operation has already verified that there is a valid
3620 -- interpretation, but the form of the actual can only be determined
3621 -- once the primitive operation is identified.
3623 procedure Insert_Default
;
3624 -- If the actual is missing in a call, insert in the actuals list
3625 -- an instance of the default expression. The insertion is always
3626 -- a named association.
3628 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean;
3629 -- Check whether T1 and T2, or their full views, are derived from a
3630 -- common type. Used to enforce the restrictions on array conversions
3633 function Static_Concatenation
(N
: Node_Id
) return Boolean;
3634 -- Predicate to determine whether an actual that is a concatenation
3635 -- will be evaluated statically and does not need a transient scope.
3636 -- This must be determined before the actual is resolved and expanded
3637 -- because if needed the transient scope must be introduced earlier.
3639 -----------------------------
3640 -- Check_Aliased_Parameter --
3641 -----------------------------
3643 procedure Check_Aliased_Parameter
is
3644 Nominal_Subt
: Entity_Id
;
3647 if Is_Aliased
(F
) then
3648 if Is_Tagged_Type
(A_Typ
) then
3651 elsif Is_Aliased_View
(A
) then
3652 if Is_Constr_Subt_For_U_Nominal
(A_Typ
) then
3653 Nominal_Subt
:= Base_Type
(A_Typ
);
3655 Nominal_Subt
:= A_Typ
;
3658 if Subtypes_Statically_Match
(F_Typ
, Nominal_Subt
) then
3661 -- In a generic body assume the worst for generic formals:
3662 -- they can have a constrained partial view (AI05-041).
3664 elsif Has_Discriminants
(F_Typ
)
3665 and then not Is_Constrained
(F_Typ
)
3666 and then not Object_Type_Has_Constrained_Partial_View
3667 (Typ
=> F_Typ
, Scop
=> Current_Scope
)
3672 Error_Msg_NE
("untagged actual does not statically match "
3673 & "aliased formal&", A
, F
);
3677 Error_Msg_NE
("actual for aliased formal& must be "
3678 & "aliased object", A
, F
);
3681 if Ekind
(Nam
) = E_Procedure
then
3684 elsif Ekind
(Etype
(Nam
)) = E_Anonymous_Access_Type
then
3685 if Nkind
(Parent
(N
)) = N_Type_Conversion
3686 and then Type_Access_Level
(Etype
(Parent
(N
)))
3687 < Static_Accessibility_Level
(A
, Object_Decl_Level
)
3689 Error_Msg_N
("aliased actual has wrong accessibility", A
);
3692 elsif Nkind
(Parent
(N
)) = N_Qualified_Expression
3693 and then Nkind
(Parent
(Parent
(N
))) = N_Allocator
3694 and then Type_Access_Level
(Etype
(Parent
(Parent
(N
))))
3695 < Static_Accessibility_Level
(A
, Object_Decl_Level
)
3698 ("aliased actual in allocator has wrong accessibility", A
);
3701 end Check_Aliased_Parameter
;
3703 --------------------------
3704 -- Check_Argument_Order --
3705 --------------------------
3707 procedure Check_Argument_Order
is
3709 -- Nothing to do if no parameters, or original node is neither a
3710 -- function call nor a procedure call statement (happens in the
3711 -- operator-transformed-to-function call case), or the call is to an
3712 -- operator symbol (which is usually in infix form), or the call does
3713 -- not come from source, or this warning is off.
3715 if not Warn_On_Parameter_Order
3716 or else No
(Parameter_Associations
(N
))
3717 or else Nkind
(Original_Node
(N
)) not in N_Subprogram_Call
3718 or else (Nkind
(Name
(N
)) = N_Identifier
3719 and then Present
(Entity
(Name
(N
)))
3720 and then Nkind
(Entity
(Name
(N
))) =
3721 N_Defining_Operator_Symbol
)
3722 or else not Comes_From_Source
(N
)
3728 Nargs
: constant Nat
:= List_Length
(Parameter_Associations
(N
));
3731 -- Nothing to do if only one parameter
3737 -- Here if at least two arguments
3740 Actuals
: array (1 .. Nargs
) of Node_Id
;
3744 Wrong_Order
: Boolean := False;
3745 -- Set True if an out of order case is found
3748 -- Collect identifier names of actuals, fail if any actual is
3749 -- not a simple identifier, and record max length of name.
3751 Actual
:= First
(Parameter_Associations
(N
));
3752 for J
in Actuals
'Range loop
3753 if Nkind
(Actual
) /= N_Identifier
then
3756 Actuals
(J
) := Actual
;
3761 -- If we got this far, all actuals are identifiers and the list
3762 -- of their names is stored in the Actuals array.
3764 Formal
:= First_Formal
(Nam
);
3765 for J
in Actuals
'Range loop
3767 -- If we ran out of formals, that's odd, probably an error
3768 -- which will be detected elsewhere, but abandon the search.
3774 -- If name matches and is in order OK
3776 if Chars
(Formal
) = Chars
(Actuals
(J
)) then
3780 -- If no match, see if it is elsewhere in list and if so
3781 -- flag potential wrong order if type is compatible.
3783 for K
in Actuals
'Range loop
3784 if Chars
(Formal
) = Chars
(Actuals
(K
))
3786 Has_Compatible_Type
(Actuals
(K
), Etype
(Formal
))
3788 Wrong_Order
:= True;
3798 <<Continue
>> Next_Formal
(Formal
);
3801 -- If Formals left over, also probably an error, skip warning
3803 if Present
(Formal
) then
3807 -- Here we give the warning if something was out of order
3811 ("?.p?actuals for this call may be in wrong order", N
);
3815 end Check_Argument_Order
;
3817 -------------------------
3818 -- Check_Prefixed_Call --
3819 -------------------------
3821 procedure Check_Prefixed_Call
is
3822 Act
: constant Node_Id
:= First_Actual
(N
);
3823 A_Type
: constant Entity_Id
:= Etype
(Act
);
3824 F_Type
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
3825 Orig
: constant Node_Id
:= Original_Node
(N
);
3829 -- Check whether the call is a prefixed call, with or without
3830 -- additional actuals.
3832 if Nkind
(Orig
) = N_Selected_Component
3834 (Nkind
(Orig
) = N_Indexed_Component
3835 and then Nkind
(Prefix
(Orig
)) = N_Selected_Component
3836 and then Is_Entity_Name
(Prefix
(Prefix
(Orig
)))
3837 and then Is_Entity_Name
(Act
)
3838 and then Chars
(Act
) = Chars
(Prefix
(Prefix
(Orig
))))
3840 if Is_Access_Type
(A_Type
)
3841 and then not Is_Access_Type
(F_Type
)
3843 -- Introduce dereference on object in prefix
3846 Make_Explicit_Dereference
(Sloc
(Act
),
3847 Prefix
=> Relocate_Node
(Act
));
3848 Rewrite
(Act
, New_A
);
3851 elsif Is_Access_Type
(F_Type
)
3852 and then not Is_Access_Type
(A_Type
)
3854 -- Introduce an implicit 'Access in prefix
3856 if not Is_Aliased_View
(Act
) then
3858 ("object in prefixed call to& must be aliased "
3859 & "(RM 4.1.3 (13 1/2))",
3864 Make_Attribute_Reference
(Loc
,
3865 Attribute_Name
=> Name_Access
,
3866 Prefix
=> Relocate_Node
(Act
)));
3871 end Check_Prefixed_Call
;
3873 --------------------
3874 -- Insert_Default --
3875 --------------------
3877 procedure Insert_Default
is
3882 -- Missing argument in call, nothing to insert
3884 if No
(Default_Value
(F
)) then
3888 -- Note that we do a full New_Copy_Tree, so that any associated
3889 -- Itypes are properly copied. This may not be needed any more,
3890 -- but it does no harm as a safety measure. Defaults of a generic
3891 -- formal may be out of bounds of the corresponding actual (see
3892 -- cc1311b) and an additional check may be required.
3897 New_Scope
=> Current_Scope
,
3900 -- Propagate dimension information, if any.
3902 Copy_Dimensions
(Default_Value
(F
), Actval
);
3904 if Is_Concurrent_Type
(Scope
(Nam
))
3905 and then Has_Discriminants
(Scope
(Nam
))
3907 Replace_Actual_Discriminants
(N
, Actval
);
3910 if Is_Overloadable
(Nam
)
3911 and then Present
(Alias
(Nam
))
3913 if Base_Type
(Etype
(F
)) /= Base_Type
(Etype
(Actval
))
3914 and then not Is_Tagged_Type
(Etype
(F
))
3916 -- If default is a real literal, do not introduce a
3917 -- conversion whose effect may depend on the run-time
3918 -- size of universal real.
3920 if Nkind
(Actval
) = N_Real_Literal
then
3921 Set_Etype
(Actval
, Base_Type
(Etype
(F
)));
3923 Actval
:= Unchecked_Convert_To
(Etype
(F
), Actval
);
3927 if Is_Scalar_Type
(Etype
(F
)) then
3928 Enable_Range_Check
(Actval
);
3931 Set_Parent
(Actval
, N
);
3933 -- Resolve aggregates with their base type, to avoid scope
3934 -- anomalies: the subtype was first built in the subprogram
3935 -- declaration, and the current call may be nested.
3937 if Nkind
(Actval
) = N_Aggregate
then
3938 Analyze_And_Resolve
(Actval
, Etype
(F
));
3940 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3944 Set_Parent
(Actval
, N
);
3946 -- See note above concerning aggregates
3948 if Nkind
(Actval
) = N_Aggregate
3949 and then Has_Discriminants
(Etype
(Actval
))
3951 Analyze_And_Resolve
(Actval
, Base_Type
(Etype
(Actval
)));
3953 -- Resolve entities with their own type, which may differ from
3954 -- the type of a reference in a generic context because of the
3955 -- trick used in Save_Global_References.Set_Global_Type to set
3956 -- full views forcefully, which did not anticipate the need to
3957 -- re-analyze default values in calls.
3959 elsif Is_Entity_Name
(Actval
) then
3960 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Actval
)));
3962 -- Ditto for calls whose name is an entity, for the same reason
3964 elsif Nkind
(Actval
) = N_Function_Call
3965 and then Is_Entity_Name
(Name
(Actval
))
3967 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Name
(Actval
))));
3970 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3974 -- If default is a tag indeterminate function call, propagate tag
3975 -- to obtain proper dispatching.
3977 if Is_Controlling_Formal
(F
)
3978 and then Nkind
(Default_Value
(F
)) = N_Function_Call
3980 Set_Is_Controlling_Actual
(Actval
);
3984 -- If the default expression raises constraint error, then just
3985 -- silently replace it with an N_Raise_Constraint_Error node, since
3986 -- we already gave the warning on the subprogram spec. If node is
3987 -- already a Raise_Constraint_Error leave as is, to prevent loops in
3988 -- the warnings removal machinery.
3990 if Raises_Constraint_Error
(Actval
)
3991 and then Nkind
(Actval
) /= N_Raise_Constraint_Error
3994 Make_Raise_Constraint_Error
(Loc
,
3995 Reason
=> CE_Range_Check_Failed
));
3997 Set_Raises_Constraint_Error
(Actval
);
3998 Set_Etype
(Actval
, Etype
(F
));
4002 Make_Parameter_Association
(Loc
,
4003 Explicit_Actual_Parameter
=> Actval
,
4004 Selector_Name
=> Make_Identifier
(Loc
, Chars
(F
)));
4006 -- Case of insertion is first named actual
4009 or else Nkind
(Parent
(Prev
)) /= N_Parameter_Association
4011 Set_Next_Named_Actual
(Assoc
, First_Named_Actual
(N
));
4012 Set_First_Named_Actual
(N
, Actval
);
4015 if No
(Parameter_Associations
(N
)) then
4016 Set_Parameter_Associations
(N
, New_List
(Assoc
));
4018 Append
(Assoc
, Parameter_Associations
(N
));
4022 Insert_After
(Prev
, Assoc
);
4025 -- Case of insertion is not first named actual
4028 Set_Next_Named_Actual
4029 (Assoc
, Next_Named_Actual
(Parent
(Prev
)));
4030 Set_Next_Named_Actual
(Parent
(Prev
), Actval
);
4031 Append
(Assoc
, Parameter_Associations
(N
));
4034 Mark_Rewrite_Insertion
(Assoc
);
4035 Mark_Rewrite_Insertion
(Actval
);
4044 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean is
4045 FT1
: Entity_Id
:= T1
;
4046 FT2
: Entity_Id
:= T2
;
4049 if Is_Private_Type
(T1
)
4050 and then Present
(Full_View
(T1
))
4052 FT1
:= Full_View
(T1
);
4055 if Is_Private_Type
(T2
)
4056 and then Present
(Full_View
(T2
))
4058 FT2
:= Full_View
(T2
);
4061 return Root_Type
(Base_Type
(FT1
)) = Root_Type
(Base_Type
(FT2
));
4064 --------------------------
4065 -- Static_Concatenation --
4066 --------------------------
4068 function Static_Concatenation
(N
: Node_Id
) return Boolean is
4071 when N_String_Literal
=>
4076 -- Concatenation is static when both operands are static and
4077 -- the concatenation operator is a predefined one.
4079 return Scope
(Entity
(N
)) = Standard_Standard
4081 Static_Concatenation
(Left_Opnd
(N
))
4083 Static_Concatenation
(Right_Opnd
(N
));
4086 if Is_Entity_Name
(N
) then
4088 Ent
: constant Entity_Id
:= Entity
(N
);
4090 return Ekind
(Ent
) = E_Constant
4091 and then Present
(Constant_Value
(Ent
))
4093 Is_OK_Static_Expression
(Constant_Value
(Ent
));
4100 end Static_Concatenation
;
4102 -- Start of processing for Resolve_Actuals
4105 Check_Argument_Order
;
4107 if Is_Overloadable
(Nam
)
4108 and then Is_Inherited_Operation
(Nam
)
4109 and then In_Instance
4110 and then Present
(Alias
(Nam
))
4111 and then Present
(Overridden_Operation
(Alias
(Nam
)))
4113 Real_Subp
:= Alias
(Nam
);
4118 if Present
(First_Actual
(N
)) then
4119 Check_Prefixed_Call
;
4122 A
:= First_Actual
(N
);
4123 F
:= First_Formal
(Nam
);
4125 if Present
(Real_Subp
) then
4126 Real_F
:= First_Formal
(Real_Subp
);
4129 while Present
(F
) loop
4130 if No
(A
) and then Needs_No_Actuals
(Nam
) then
4133 -- If we have an error in any formal or actual, indicated by a type
4134 -- of Any_Type, then abandon resolution attempt, and set result type
4137 elsif Etype
(F
) = Any_Type
then
4138 Set_Etype
(N
, Any_Type
);
4141 elsif Present
(A
) and then Etype
(A
) = Any_Type
then
4142 -- For the peculiar case of a user-defined comparison or equality
4143 -- operator that does not return a boolean type, the operands may
4144 -- have been ambiguous for the predefined operator and, therefore,
4145 -- marked with Any_Type. Since the operation has been resolved to
4146 -- the user-defined operator, that is irrelevant, so reset Etype.
4148 if Nkind
(Original_Node
(N
)) in N_Op_Compare
4149 and then not Is_Boolean_Type
(Etype
(N
))
4151 Set_Etype
(A
, Etype
(F
));
4153 -- Also skip this if the actual is a Raise_Expression, whose type
4154 -- is imposed from context.
4156 elsif Nkind
(A
) = N_Raise_Expression
then
4160 Set_Etype
(N
, Any_Type
);
4165 -- Case where actual is present
4167 -- If the actual is an entity, generate a reference to it now. We
4168 -- do this before the actual is resolved, because a formal of some
4169 -- protected subprogram, or a task discriminant, will be rewritten
4170 -- during expansion, and the source entity reference may be lost.
4173 and then Is_Entity_Name
(A
)
4174 and then Comes_From_Source
(A
)
4176 -- Annotate the tree by creating a variable reference marker when
4177 -- the actual denotes a variable reference, in case the reference
4178 -- is folded or optimized away. The variable reference marker is
4179 -- automatically saved for later examination by the ABE Processing
4180 -- phase. The status of the reference is set as follows:
4184 -- write IN OUT, OUT
4186 if Needs_Variable_Reference_Marker
4190 Build_Variable_Reference_Marker
4192 Read
=> Ekind
(F
) /= E_Out_Parameter
,
4193 Write
=> Ekind
(F
) /= E_In_Parameter
);
4196 Orig_A
:= Entity
(A
);
4198 if Present
(Orig_A
) then
4199 if Is_Formal
(Orig_A
)
4200 and then Ekind
(F
) /= E_In_Parameter
4202 Generate_Reference
(Orig_A
, A
, 'm');
4204 elsif not Is_Overloaded
(A
) then
4205 if Ekind
(F
) /= E_Out_Parameter
then
4206 Generate_Reference
(Orig_A
, A
);
4208 -- RM 6.4.1(12): For an out parameter that is passed by
4209 -- copy, the formal parameter object is created, and:
4211 -- * For an access type, the formal parameter is initialized
4212 -- from the value of the actual, without checking that the
4213 -- value satisfies any constraint, any predicate, or any
4214 -- exclusion of the null value.
4216 -- * For a scalar type that has the Default_Value aspect
4217 -- specified, the formal parameter is initialized from the
4218 -- value of the actual, without checking that the value
4219 -- satisfies any constraint or any predicate.
4220 -- I do not understand why this case is included??? this is
4221 -- not a case where an OUT parameter is treated as IN OUT.
4223 -- * For a composite type with discriminants or that has
4224 -- implicit initial values for any subcomponents, the
4225 -- behavior is as for an in out parameter passed by copy.
4227 -- Hence for these cases we generate the read reference now
4228 -- (the write reference will be generated later by
4229 -- Note_Possible_Modification).
4231 elsif Is_By_Copy_Type
(Etype
(F
))
4233 (Is_Access_Type
(Etype
(F
))
4235 (Is_Scalar_Type
(Etype
(F
))
4237 Present
(Default_Aspect_Value
(Etype
(F
))))
4239 (Is_Composite_Type
(Etype
(F
))
4240 and then (Has_Discriminants
(Etype
(F
))
4241 or else Is_Partially_Initialized_Type
4244 Generate_Reference
(Orig_A
, A
);
4251 and then (Nkind
(Parent
(A
)) /= N_Parameter_Association
4252 or else Chars
(Selector_Name
(Parent
(A
))) = Chars
(F
))
4254 -- If style checking mode on, check match of formal name
4257 if Nkind
(Parent
(A
)) = N_Parameter_Association
then
4258 Check_Identifier
(Selector_Name
(Parent
(A
)), F
);
4262 -- If the formal is Out or In_Out, do not resolve and expand the
4263 -- conversion, because it is subsequently expanded into explicit
4264 -- temporaries and assignments. However, the object of the
4265 -- conversion can be resolved. An exception is the case of tagged
4266 -- type conversion with a class-wide actual. In that case we want
4267 -- the tag check to occur and no temporary will be needed (no
4268 -- representation change can occur) and the parameter is passed by
4269 -- reference, so we go ahead and resolve the type conversion.
4270 -- Another exception is the case of reference to component or
4271 -- subcomponent of a bit-packed array, in which case we want to
4272 -- defer expansion to the point the in and out assignments are
4275 if Ekind
(F
) /= E_In_Parameter
4276 and then Nkind
(A
) = N_Type_Conversion
4277 and then not Is_Class_Wide_Type
(Etype
(Expression
(A
)))
4278 and then not Is_Interface
(Etype
(A
))
4281 Expr_Typ
: constant Entity_Id
:= Etype
(Expression
(A
));
4284 -- Check RM 4.6 (24.2/2)
4286 if Is_Array_Type
(Etype
(F
))
4287 and then Is_View_Conversion
(A
)
4289 -- In a view conversion, the conversion must be legal in
4290 -- both directions, and thus both component types must be
4291 -- aliased, or neither (4.6 (8)).
4293 -- Check RM 4.6 (24.8/2)
4295 if Has_Aliased_Components
(Expr_Typ
) /=
4296 Has_Aliased_Components
(Etype
(F
))
4298 -- This normally illegal conversion is legal in an
4299 -- expanded instance body because of RM 12.3(11).
4300 -- At runtime, conversion must create a new object.
4302 if not In_Instance
then
4304 ("both component types in a view conversion must"
4305 & " be aliased, or neither", A
);
4308 -- Check RM 4.6 (24/3)
4310 elsif not Same_Ancestor
(Etype
(F
), Expr_Typ
) then
4311 -- Check view conv between unrelated by ref array
4314 if Is_By_Reference_Type
(Etype
(F
))
4315 or else Is_By_Reference_Type
(Expr_Typ
)
4318 ("view conversion between unrelated by reference "
4319 & "array types not allowed ('A'I-00246)", A
);
4321 -- In Ada 2005 mode, check view conversion component
4322 -- type cannot be private, tagged, or volatile. Note
4323 -- that we only apply this to source conversions. The
4324 -- generated code can contain conversions which are
4325 -- not subject to this test, and we cannot extract the
4326 -- component type in such cases since it is not
4329 elsif Comes_From_Source
(A
)
4330 and then Ada_Version
>= Ada_2005
4333 Comp_Type
: constant Entity_Id
:=
4334 Component_Type
(Expr_Typ
);
4336 if (Is_Private_Type
(Comp_Type
)
4337 and then not Is_Generic_Type
(Comp_Type
))
4338 or else Is_Tagged_Type
(Comp_Type
)
4339 or else Is_Volatile
(Comp_Type
)
4342 ("component type of a view conversion " &
4343 "cannot be private, tagged, or volatile" &
4351 -- AI12-0074 & AI12-0377
4352 -- Check 6.4.1: If the mode is out, the actual parameter is
4353 -- a view conversion, and the type of the formal parameter
4354 -- is a scalar type, then either:
4355 -- - the target and operand type both do not have the
4356 -- Default_Value aspect specified; or
4357 -- - the target and operand type both have the
4358 -- Default_Value aspect specified, and there shall exist
4359 -- a type (other than a root numeric type) that is an
4360 -- ancestor of both the target type and the operand
4363 elsif Ekind
(F
) = E_Out_Parameter
4364 and then Is_Scalar_Type
(Etype
(F
))
4366 if Has_Default_Aspect
(Etype
(F
)) /=
4367 Has_Default_Aspect
(Expr_Typ
)
4370 ("view conversion requires Default_Value on both " &
4371 "types (RM 6.4.1)", A
);
4372 elsif Has_Default_Aspect
(Expr_Typ
)
4373 and then not Same_Ancestor
(Etype
(F
), Expr_Typ
)
4376 ("view conversion between unrelated types with "
4377 & "Default_Value not allowed (RM 6.4.1)", A
);
4382 -- Resolve expression if conversion is all OK
4384 if (Conversion_OK
(A
)
4385 or else Valid_Conversion
(A
, Etype
(A
), Expression
(A
)))
4386 and then not Is_Ref_To_Bit_Packed_Array
(Expression
(A
))
4388 Resolve
(Expression
(A
));
4391 -- If the actual is a function call that returns a limited
4392 -- unconstrained object that needs finalization, create a
4393 -- transient scope for it, so that it can receive the proper
4394 -- finalization list.
4396 elsif Expander_Active
4397 and then Nkind
(A
) = N_Function_Call
4398 and then Is_Limited_Record
(Etype
(F
))
4399 and then not Is_Constrained
(Etype
(F
))
4400 and then (Needs_Finalization
(Etype
(F
))
4401 or else Has_Task
(Etype
(F
)))
4403 Establish_Transient_Scope
(A
, Manage_Sec_Stack
=> False);
4404 Resolve
(A
, Etype
(F
));
4406 -- A small optimization: if one of the actuals is a concatenation
4407 -- create a block around a procedure call to recover stack space.
4408 -- This alleviates stack usage when several procedure calls in
4409 -- the same statement list use concatenation. We do not perform
4410 -- this wrapping for code statements, where the argument is a
4411 -- static string, and we want to preserve warnings involving
4412 -- sequences of such statements.
4414 elsif Expander_Active
4415 and then Nkind
(A
) = N_Op_Concat
4416 and then Nkind
(N
) = N_Procedure_Call_Statement
4417 and then not (Is_Intrinsic_Subprogram
(Nam
)
4418 and then Chars
(Nam
) = Name_Asm
)
4419 and then not Static_Concatenation
(A
)
4421 Establish_Transient_Scope
(A
, Manage_Sec_Stack
=> False);
4422 Resolve
(A
, Etype
(F
));
4425 if Nkind
(A
) = N_Type_Conversion
4426 and then Is_Array_Type
(Etype
(F
))
4427 and then not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
4429 (Is_Limited_Type
(Etype
(F
))
4430 or else Is_Limited_Type
(Etype
(Expression
(A
))))
4433 ("conversion between unrelated limited array types not "
4434 & "allowed ('A'I-00246)", A
);
4436 if Is_Limited_Type
(Etype
(F
)) then
4437 Explain_Limited_Type
(Etype
(F
), A
);
4440 if Is_Limited_Type
(Etype
(Expression
(A
))) then
4441 Explain_Limited_Type
(Etype
(Expression
(A
)), A
);
4445 -- (Ada 2005: AI-251): If the actual is an allocator whose
4446 -- directly designated type is a class-wide interface, we build
4447 -- an anonymous access type to use it as the type of the
4448 -- allocator. Later, when the subprogram call is expanded, if
4449 -- the interface has a secondary dispatch table the expander
4450 -- will add a type conversion to force the correct displacement
4453 if Nkind
(A
) = N_Allocator
then
4455 DDT
: constant Entity_Id
:=
4456 Directly_Designated_Type
(Base_Type
(Etype
(F
)));
4459 -- Displace the pointer to the object to reference its
4460 -- secondary dispatch table.
4462 if Is_Class_Wide_Type
(DDT
)
4463 and then Is_Interface
(DDT
)
4465 Rewrite
(A
, Convert_To
(Etype
(F
), Relocate_Node
(A
)));
4466 Analyze_And_Resolve
(A
, Etype
(F
),
4467 Suppress
=> Access_Check
);
4470 -- Ada 2005, AI-162:If the actual is an allocator, the
4471 -- innermost enclosing statement is the master of the
4472 -- created object. This needs to be done with expansion
4473 -- enabled only, otherwise the transient scope will not
4474 -- be removed in the expansion of the wrapped construct.
4477 and then (Needs_Finalization
(DDT
)
4478 or else Has_Task
(DDT
))
4480 Establish_Transient_Scope
4481 (A
, Manage_Sec_Stack
=> False);
4485 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
4486 Check_Restriction
(No_Access_Parameter_Allocators
, A
);
4490 -- (Ada 2005): The call may be to a primitive operation of a
4491 -- tagged synchronized type, declared outside of the type. In
4492 -- this case the controlling actual must be converted to its
4493 -- corresponding record type, which is the formal type. The
4494 -- actual may be a subtype, either because of a constraint or
4495 -- because it is a generic actual, so use base type to locate
4498 F_Typ
:= Base_Type
(Etype
(F
));
4500 if Is_Tagged_Type
(F_Typ
)
4501 and then (Is_Concurrent_Type
(F_Typ
)
4502 or else Is_Concurrent_Record_Type
(F_Typ
))
4504 -- If the actual is overloaded, look for an interpretation
4505 -- that has a synchronized type.
4507 if not Is_Overloaded
(A
) then
4508 A_Typ
:= Base_Type
(Etype
(A
));
4512 Index
: Interp_Index
;
4516 Get_First_Interp
(A
, Index
, It
);
4517 while Present
(It
.Typ
) loop
4518 if Is_Concurrent_Type
(It
.Typ
)
4519 or else Is_Concurrent_Record_Type
(It
.Typ
)
4521 A_Typ
:= Base_Type
(It
.Typ
);
4525 Get_Next_Interp
(Index
, It
);
4531 Full_A_Typ
: Entity_Id
;
4534 if Present
(Full_View
(A_Typ
)) then
4535 Full_A_Typ
:= Base_Type
(Full_View
(A_Typ
));
4537 Full_A_Typ
:= A_Typ
;
4540 -- Tagged synchronized type (case 1): the actual is a
4543 if Is_Concurrent_Type
(A_Typ
)
4544 and then Corresponding_Record_Type
(A_Typ
) = F_Typ
4547 Unchecked_Convert_To
4548 (Corresponding_Record_Type
(A_Typ
), A
));
4549 Resolve
(A
, Etype
(F
));
4551 -- Tagged synchronized type (case 2): the formal is a
4554 elsif Ekind
(Full_A_Typ
) = E_Record_Type
4556 (Corresponding_Concurrent_Type
(Full_A_Typ
))
4557 and then Is_Concurrent_Type
(F_Typ
)
4558 and then Present
(Corresponding_Record_Type
(F_Typ
))
4559 and then Full_A_Typ
= Corresponding_Record_Type
(F_Typ
)
4561 Resolve
(A
, Corresponding_Record_Type
(F_Typ
));
4566 Resolve
(A
, Etype
(F
));
4570 -- Not a synchronized operation
4573 Resolve
(A
, Etype
(F
));
4580 -- An actual cannot be an untagged formal incomplete type
4582 if Ekind
(A_Typ
) = E_Incomplete_Type
4583 and then not Is_Tagged_Type
(A_Typ
)
4584 and then Is_Generic_Type
(A_Typ
)
4587 ("invalid use of untagged formal incomplete type", A
);
4590 -- For mode IN, if actual is an entity, and the type of the formal
4591 -- has warnings suppressed, then we reset Never_Set_In_Source for
4592 -- the calling entity. The reason for this is to catch cases like
4593 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
4594 -- uses trickery to modify an IN parameter.
4596 if Ekind
(F
) = E_In_Parameter
4597 and then Is_Entity_Name
(A
)
4598 and then Present
(Entity
(A
))
4599 and then Ekind
(Entity
(A
)) = E_Variable
4600 and then Has_Warnings_Off
(F_Typ
)
4602 Set_Never_Set_In_Source
(Entity
(A
), False);
4605 -- Perform error checks for IN and IN OUT parameters
4607 if Ekind
(F
) /= E_Out_Parameter
then
4609 -- Check unset reference. For scalar parameters, it is clearly
4610 -- wrong to pass an uninitialized value as either an IN or
4611 -- IN-OUT parameter. For composites, it is also clearly an
4612 -- error to pass a completely uninitialized value as an IN
4613 -- parameter, but the case of IN OUT is trickier. We prefer
4614 -- not to give a warning here. For example, suppose there is
4615 -- a routine that sets some component of a record to False.
4616 -- It is perfectly reasonable to make this IN-OUT and allow
4617 -- either initialized or uninitialized records to be passed
4620 -- For partially initialized composite values, we also avoid
4621 -- warnings, since it is quite likely that we are passing a
4622 -- partially initialized value and only the initialized fields
4623 -- will in fact be read in the subprogram.
4625 if Is_Scalar_Type
(A_Typ
)
4626 or else (Ekind
(F
) = E_In_Parameter
4627 and then not Is_Partially_Initialized_Type
(A_Typ
))
4629 Check_Unset_Reference
(A
);
4632 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
4633 -- actual to a nested call, since this constitutes a reading of
4634 -- the parameter, which is not allowed.
4636 if Ada_Version
= Ada_83
4637 and then Is_Entity_Name
(A
)
4638 and then Ekind
(Entity
(A
)) = E_Out_Parameter
4640 Error_Msg_N
("(Ada 83) illegal reading of out parameter", A
);
4644 -- In -gnatd.q mode, forget that a given array is constant when
4645 -- it is passed as an IN parameter to a foreign-convention
4646 -- subprogram. This is in case the subprogram evilly modifies the
4647 -- object. Of course, correct code would use IN OUT.
4650 and then Ekind
(F
) = E_In_Parameter
4651 and then Has_Foreign_Convention
(Nam
)
4652 and then Is_Array_Type
(F_Typ
)
4653 and then Nkind
(A
) in N_Has_Entity
4654 and then Present
(Entity
(A
))
4656 Set_Is_True_Constant
(Entity
(A
), False);
4659 -- Case of OUT or IN OUT parameter
4661 if Ekind
(F
) /= E_In_Parameter
then
4663 -- For an Out parameter, check for useless assignment. Note
4664 -- that we can't set Last_Assignment this early, because we may
4665 -- kill current values in Resolve_Call, and that call would
4666 -- clobber the Last_Assignment field.
4668 -- Note: call Warn_On_Useless_Assignment before doing the check
4669 -- below for Is_OK_Variable_For_Out_Formal so that the setting
4670 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
4671 -- reflects the last assignment, not this one.
4673 if Ekind
(F
) = E_Out_Parameter
then
4674 if Warn_On_Modified_As_Out_Parameter
(F
)
4675 and then Is_Entity_Name
(A
)
4676 and then Present
(Entity
(A
))
4677 and then Comes_From_Source
(N
)
4679 Warn_On_Useless_Assignment
(Entity
(A
), A
);
4683 -- Validate the form of the actual. Note that the call to
4684 -- Is_OK_Variable_For_Out_Formal generates the required
4685 -- reference in this case.
4687 -- A call to an initialization procedure for an aggregate
4688 -- component may initialize a nested component of a constant
4689 -- designated object. In this context the object is variable.
4691 if not Is_OK_Variable_For_Out_Formal
(A
)
4692 and then not Is_Init_Proc
(Nam
)
4694 Error_Msg_NE
("actual for& must be a variable", A
, F
);
4696 if Is_Subprogram
(Current_Scope
) then
4697 if Is_Invariant_Procedure
(Current_Scope
)
4698 or else Is_Partial_Invariant_Procedure
(Current_Scope
)
4701 ("function used in invariant cannot modify its "
4704 elsif Is_Predicate_Function
(Current_Scope
) then
4706 ("function used in predicate cannot modify its "
4712 -- What's the following about???
4714 if Is_Entity_Name
(A
) then
4715 Kill_Checks
(Entity
(A
));
4721 if A_Typ
= Any_Type
then
4722 Set_Etype
(N
, Any_Type
);
4726 -- Apply appropriate constraint/predicate checks for IN [OUT] case
4728 if Ekind
(F
) in E_In_Parameter | E_In_Out_Parameter
then
4730 -- Apply predicate tests except in certain special cases. Note
4731 -- that it might be more consistent to apply these only when
4732 -- expansion is active (in Exp_Ch6.Expand_Actuals), as we do
4733 -- for the outbound predicate tests ??? In any case indicate
4734 -- the function being called, for better warnings if the call
4735 -- leads to an infinite recursion.
4737 if Predicate_Tests_On_Arguments
(Nam
) then
4738 Apply_Predicate_Check
(A
, F_Typ
, Fun
=> Nam
);
4741 -- Apply required constraint checks
4743 if Is_Scalar_Type
(A_Typ
) then
4744 Apply_Scalar_Range_Check
(A
, F_Typ
);
4746 elsif Is_Array_Type
(A_Typ
) then
4747 Apply_Length_Check
(A
, F_Typ
);
4749 elsif Is_Record_Type
(F_Typ
)
4750 and then Has_Discriminants
(F_Typ
)
4751 and then Is_Constrained
(F_Typ
)
4752 and then (not Is_Derived_Type
(F_Typ
)
4753 or else Comes_From_Source
(Nam
))
4755 Apply_Discriminant_Check
(A
, F_Typ
);
4757 -- For view conversions of a discriminated object, apply
4758 -- check to object itself, the conversion alreay has the
4761 if Nkind
(A
) = N_Type_Conversion
4762 and then Is_Constrained
(Etype
(Expression
(A
)))
4764 Apply_Discriminant_Check
(Expression
(A
), F_Typ
);
4767 elsif Is_Access_Type
(F_Typ
)
4768 and then Is_Array_Type
(Designated_Type
(F_Typ
))
4769 and then Is_Constrained
(Designated_Type
(F_Typ
))
4771 Apply_Length_Check
(A
, F_Typ
);
4773 elsif Is_Access_Type
(F_Typ
)
4774 and then Has_Discriminants
(Designated_Type
(F_Typ
))
4775 and then Is_Constrained
(Designated_Type
(F_Typ
))
4777 Apply_Discriminant_Check
(A
, F_Typ
);
4780 Apply_Range_Check
(A
, F_Typ
);
4783 -- Ada 2005 (AI-231): Note that the controlling parameter case
4784 -- already existed in Ada 95, which is partially checked
4785 -- elsewhere (see Checks), and we don't want the warning
4786 -- message to differ.
4788 if Is_Access_Type
(F_Typ
)
4789 and then Can_Never_Be_Null
(F_Typ
)
4790 and then Known_Null
(A
)
4792 if Is_Controlling_Formal
(F
) then
4793 Apply_Compile_Time_Constraint_Error
4795 Msg
=> "null value not allowed here??",
4796 Reason
=> CE_Access_Check_Failed
);
4798 elsif Ada_Version
>= Ada_2005
then
4799 Apply_Compile_Time_Constraint_Error
4801 Msg
=> "(Ada 2005) NULL not allowed in "
4802 & "null-excluding formal??",
4803 Reason
=> CE_Null_Not_Allowed
);
4808 -- Checks for OUT parameters and IN OUT parameters
4810 if Ekind
(F
) in E_Out_Parameter | E_In_Out_Parameter
then
4812 -- If there is a type conversion, make sure the return value
4813 -- meets the constraints of the variable before the conversion.
4815 if Nkind
(A
) = N_Type_Conversion
then
4816 if Is_Scalar_Type
(A_Typ
) then
4818 -- Special case here tailored to Exp_Ch6.Is_Legal_Copy,
4819 -- which would prevent the check from being generated.
4820 -- This is for Starlet only though, so long obsolete.
4822 if Mechanism
(F
) = By_Reference
4823 and then Ekind
(Nam
) = E_Procedure
4824 and then Is_Valued_Procedure
(Nam
)
4828 Apply_Scalar_Range_Check
4829 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4832 -- In addition the return value must meet the constraints
4833 -- of the object type (see the comment below).
4835 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
4839 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4842 -- If no conversion, apply scalar range checks and length check
4843 -- based on the subtype of the actual (NOT that of the formal).
4844 -- This indicates that the check takes place on return from the
4845 -- call. During expansion the required constraint checks are
4846 -- inserted. In GNATprove mode, in the absence of expansion,
4847 -- the flag indicates that the returned value is valid.
4850 if Is_Scalar_Type
(F_Typ
) then
4851 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
4853 elsif Is_Array_Type
(F_Typ
)
4854 and then Ekind
(F
) = E_Out_Parameter
4856 Apply_Length_Check
(A
, F_Typ
);
4859 Apply_Range_Check
(A
, A_Typ
, F_Typ
);
4863 -- Note: we do not apply the predicate checks for the case of
4864 -- OUT and IN OUT parameters. They are instead applied in the
4865 -- Expand_Actuals routine in Exp_Ch6.
4868 -- If the formal is of an unconstrained array subtype with fixed
4869 -- lower bound, then sliding to that bound may be needed.
4871 if Is_Fixed_Lower_Bound_Array_Subtype
(F_Typ
) then
4872 Expand_Sliding_Conversion
(A
, F_Typ
);
4875 -- An actual associated with an access parameter is implicitly
4876 -- converted to the anonymous access type of the formal and must
4877 -- satisfy the legality checks for access conversions.
4879 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
4880 if not Valid_Conversion
(A
, F_Typ
, A
) then
4882 ("invalid implicit conversion for access parameter", A
);
4885 -- If the actual is an access selected component of a variable,
4886 -- the call may modify its designated object. It is reasonable
4887 -- to treat this as a potential modification of the enclosing
4888 -- record, to prevent spurious warnings that it should be
4889 -- declared as a constant, because intuitively programmers
4890 -- regard the designated subcomponent as part of the record.
4892 if Nkind
(A
) = N_Selected_Component
4893 and then Is_Entity_Name
(Prefix
(A
))
4894 and then not Is_Constant_Object
(Entity
(Prefix
(A
)))
4896 Note_Possible_Modification
(A
, Sure
=> False);
4900 -- Check illegal cases of atomic/volatile/VFA actual (RM C.6(12))
4902 if (Is_By_Reference_Type
(F_Typ
) or else Is_Aliased
(F
))
4903 and then Comes_From_Source
(N
)
4905 if Is_Atomic_Object
(A
)
4906 and then not Is_Atomic
(F_Typ
)
4909 ("cannot pass atomic object to nonatomic formal&",
4912 ("\which is passed by reference (RM C.6(12))", A
);
4914 elsif Is_Volatile_Object_Ref
(A
)
4915 and then not Is_Volatile
(F_Typ
)
4918 ("cannot pass volatile object to nonvolatile formal&",
4921 ("\which is passed by reference (RM C.6(12))", A
);
4923 elsif Is_Volatile_Full_Access_Object_Ref
(A
)
4924 and then not Is_Volatile_Full_Access
(F_Typ
)
4927 ("cannot pass full access object to nonfull access "
4930 ("\which is passed by reference (RM C.6(12))", A
);
4933 -- Check for nonatomic subcomponent of a full access object
4934 -- in Ada 2022 (RM C.6 (12)).
4936 if Ada_Version
>= Ada_2022
4937 and then Is_Subcomponent_Of_Full_Access_Object
(A
)
4938 and then not Is_Atomic_Object
(A
)
4941 ("cannot pass nonatomic subcomponent of full access "
4944 ("\to formal & which is passed by reference (RM C.6(12))",
4949 -- Check that subprograms don't have improper controlling
4950 -- arguments (RM 3.9.2 (9)).
4952 -- A primitive operation may have an access parameter of an
4953 -- incomplete tagged type, but a dispatching call is illegal
4954 -- if the type is still incomplete.
4956 if Is_Controlling_Formal
(F
) then
4957 Set_Is_Controlling_Actual
(A
);
4959 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
4961 Desig
: constant Entity_Id
:= Designated_Type
(F_Typ
);
4963 if Ekind
(Desig
) = E_Incomplete_Type
4964 and then No
(Full_View
(Desig
))
4965 and then No
(Non_Limited_View
(Desig
))
4968 ("premature use of incomplete type& "
4969 & "in dispatching call", A
, Desig
);
4974 elsif Nkind
(A
) = N_Explicit_Dereference
then
4975 Validate_Remote_Access_To_Class_Wide_Type
(A
);
4978 -- Apply legality rule 3.9.2 (9/1)
4980 -- Skip this check on helpers and indirect-call wrappers built to
4981 -- support class-wide preconditions.
4983 if (Is_Class_Wide_Type
(A_Typ
) or else Is_Dynamically_Tagged
(A
))
4984 and then not Is_Class_Wide_Type
(F_Typ
)
4985 and then not Is_Controlling_Formal
(F
)
4986 and then not In_Instance
4987 and then (not Is_Subprogram
(Nam
)
4988 or else No
(Class_Preconditions_Subprogram
(Nam
)))
4990 Error_Msg_N
("class-wide argument not allowed here!", A
);
4992 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
4993 Error_Msg_Node_2
:= F_Typ
;
4995 ("& is not a dispatching operation of &!", A
, Nam
);
4998 -- Apply the checks described in 3.10.2(27): if the context is a
4999 -- specific access-to-object, the actual cannot be class-wide.
5000 -- Use base type to exclude access_to_subprogram cases.
5002 elsif Is_Access_Type
(A_Typ
)
5003 and then Is_Access_Type
(F_Typ
)
5004 and then not Is_Access_Subprogram_Type
(Base_Type
(F_Typ
))
5005 and then (Is_Class_Wide_Type
(Designated_Type
(A_Typ
))
5006 or else (Nkind
(A
) = N_Attribute_Reference
5008 Is_Class_Wide_Type
(Etype
(Prefix
(A
)))))
5009 and then not Is_Class_Wide_Type
(Designated_Type
(F_Typ
))
5010 and then not Is_Controlling_Formal
(F
)
5012 -- Disable these checks for call to imported C++ subprograms
5015 (Is_Entity_Name
(Name
(N
))
5016 and then Is_Imported
(Entity
(Name
(N
)))
5017 and then Convention
(Entity
(Name
(N
))) = Convention_CPP
)
5020 ("access to class-wide argument not allowed here!", A
);
5022 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
5023 Error_Msg_Node_2
:= Designated_Type
(F_Typ
);
5025 ("& is not a dispatching operation of &!", A
, Nam
);
5029 Check_Aliased_Parameter
;
5033 -- If it is a named association, treat the selector_name as a
5034 -- proper identifier, and mark the corresponding entity.
5036 if Nkind
(Parent
(A
)) = N_Parameter_Association
5038 -- Ignore reference in SPARK mode, as it refers to an entity not
5039 -- in scope at the point of reference, so the reference should
5040 -- be ignored for computing effects of subprograms.
5042 and then not GNATprove_Mode
5044 -- If subprogram is overridden, use name of formal that
5047 if Present
(Real_Subp
) then
5048 Set_Entity
(Selector_Name
(Parent
(A
)), Real_F
);
5049 Set_Etype
(Selector_Name
(Parent
(A
)), Etype
(Real_F
));
5052 Set_Entity
(Selector_Name
(Parent
(A
)), F
);
5053 Generate_Reference
(F
, Selector_Name
(Parent
(A
)));
5054 Set_Etype
(Selector_Name
(Parent
(A
)), F_Typ
);
5055 Generate_Reference
(F_Typ
, N
, ' ');
5061 if Ekind
(F
) /= E_Out_Parameter
then
5062 Check_Unset_Reference
(A
);
5065 -- A formal parameter of a specific tagged type whose related
5066 -- subprogram is subject to pragma Extensions_Visible with value
5067 -- "False" cannot act as an actual in a subprogram with value
5068 -- "True" (SPARK RM 6.1.7(3)).
5070 -- No check needed for helpers and indirect-call wrappers built to
5071 -- support class-wide preconditions.
5073 if Is_EVF_Expression
(A
)
5074 and then Extensions_Visible_Status
(Nam
) =
5075 Extensions_Visible_True
5077 (Is_Subprogram
(Current_Scope
)
5079 Present
(Class_Preconditions_Subprogram
(Current_Scope
)))
5082 ("formal parameter cannot act as actual parameter when "
5083 & "Extensions_Visible is False", A
);
5085 ("\subprogram & has Extensions_Visible True", A
, Nam
);
5088 -- The actual parameter of a Ghost subprogram whose formal is of
5089 -- mode IN OUT or OUT must be a Ghost variable (SPARK RM 6.9(12)).
5091 if Comes_From_Source
(Nam
)
5092 and then Is_Ghost_Entity
(Nam
)
5093 and then Ekind
(F
) in E_In_Out_Parameter | E_Out_Parameter
5094 and then Is_Entity_Name
(A
)
5095 and then Present
(Entity
(A
))
5096 and then not Is_Ghost_Entity
(Entity
(A
))
5099 ("non-ghost variable & cannot appear as actual in call to "
5100 & "ghost procedure", A
, Entity
(A
));
5102 if Ekind
(F
) = E_In_Out_Parameter
then
5103 Error_Msg_N
("\corresponding formal has mode `IN OUT`", A
);
5105 Error_Msg_N
("\corresponding formal has mode OUT", A
);
5109 -- (AI12-0397): The target of a subprogram call that occurs within
5110 -- the expression of an Default_Initial_Condition aspect and has
5111 -- an actual that is the current instance of the type must be
5112 -- either a primitive of the type or a class-wide subprogram,
5113 -- because the type of the current instance in such an aspect is
5114 -- considered to be a notional formal derived type whose only
5115 -- operations correspond to the primitives of the enclosing type.
5116 -- Nonprimitives can be called, but the current instance must be
5117 -- converted rather than passed directly. Note that a current
5118 -- instance of a type with DIC will occur as a reference to an
5119 -- in-mode formal of an enclosing DIC procedure or partial DIC
5120 -- procedure. (It seems that this check should perhaps also apply
5121 -- to calls within Type_Invariant'Class, but not Type_Invariant,
5124 if Nkind
(A
) = N_Identifier
5125 and then Ekind
(Entity
(A
)) = E_In_Parameter
5127 and then Is_Subprogram
(Scope
(Entity
(A
)))
5128 and then Is_DIC_Procedure
(Scope
(Entity
(A
)))
5130 -- We check Comes_From_Source to exclude inherited primitives
5131 -- from being flagged, because such subprograms turn out to not
5132 -- always have the Is_Primitive flag set. ???
5134 and then Comes_From_Source
(Nam
)
5136 and then not Is_Primitive
(Nam
)
5137 and then not Is_Class_Wide_Type
(F_Typ
)
5140 ("call to nonprimitive & with current instance not allowed " &
5141 "for aspect", A
, Nam
);
5146 -- Case where actual is not present
5154 if Present
(Real_Subp
) then
5155 Next_Formal
(Real_F
);
5158 end Resolve_Actuals
;
5160 -----------------------
5161 -- Resolve_Allocator --
5162 -----------------------
5164 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
) is
5165 Desig_T
: constant Entity_Id
:= Designated_Type
(Typ
);
5166 E
: constant Node_Id
:= Expression
(N
);
5168 Discrim
: Entity_Id
;
5171 Assoc
: Node_Id
:= Empty
;
5174 procedure Check_Allocator_Discrim_Accessibility
5175 (Disc_Exp
: Node_Id
;
5176 Alloc_Typ
: Entity_Id
);
5177 -- Check that accessibility level associated with an access discriminant
5178 -- initialized in an allocator by the expression Disc_Exp is not deeper
5179 -- than the level of the allocator type Alloc_Typ. An error message is
5180 -- issued if this condition is violated. Specialized checks are done for
5181 -- the cases of a constraint expression which is an access attribute or
5182 -- an access discriminant.
5184 procedure Check_Allocator_Discrim_Accessibility_Exprs
5185 (Curr_Exp
: Node_Id
;
5186 Alloc_Typ
: Entity_Id
);
5187 -- Dispatch checks performed by Check_Allocator_Discrim_Accessibility
5188 -- across all expressions within a given conditional expression.
5190 function In_Dispatching_Context
return Boolean;
5191 -- If the allocator is an actual in a call, it is allowed to be class-
5192 -- wide when the context is not because it is a controlling actual.
5194 -------------------------------------------
5195 -- Check_Allocator_Discrim_Accessibility --
5196 -------------------------------------------
5198 procedure Check_Allocator_Discrim_Accessibility
5199 (Disc_Exp
: Node_Id
;
5200 Alloc_Typ
: Entity_Id
)
5203 if Type_Access_Level
(Etype
(Disc_Exp
)) >
5204 Deepest_Type_Access_Level
(Alloc_Typ
)
5207 ("operand type has deeper level than allocator type", Disc_Exp
);
5209 -- When the expression is an Access attribute the level of the prefix
5210 -- object must not be deeper than that of the allocator's type.
5212 elsif Nkind
(Disc_Exp
) = N_Attribute_Reference
5213 and then Get_Attribute_Id
(Attribute_Name
(Disc_Exp
)) =
5215 and then Static_Accessibility_Level
5216 (Disc_Exp
, Zero_On_Dynamic_Level
)
5217 > Deepest_Type_Access_Level
(Alloc_Typ
)
5220 ("prefix of attribute has deeper level than allocator type",
5223 -- When the expression is an access discriminant the check is against
5224 -- the level of the prefix object.
5226 elsif Ekind
(Etype
(Disc_Exp
)) = E_Anonymous_Access_Type
5227 and then Nkind
(Disc_Exp
) = N_Selected_Component
5228 and then Static_Accessibility_Level
5229 (Disc_Exp
, Zero_On_Dynamic_Level
)
5230 > Deepest_Type_Access_Level
(Alloc_Typ
)
5233 ("access discriminant has deeper level than allocator type",
5236 -- All other cases are legal
5241 end Check_Allocator_Discrim_Accessibility
;
5243 -------------------------------------------------
5244 -- Check_Allocator_Discrim_Accessibility_Exprs --
5245 -------------------------------------------------
5247 procedure Check_Allocator_Discrim_Accessibility_Exprs
5248 (Curr_Exp
: Node_Id
;
5249 Alloc_Typ
: Entity_Id
)
5253 Disc_Exp
: constant Node_Id
:= Original_Node
(Curr_Exp
);
5255 -- When conditional expressions are constant folded we know at
5256 -- compile time which expression to check - so don't bother with
5257 -- the rest of the cases.
5259 if Nkind
(Curr_Exp
) = N_Attribute_Reference
then
5260 Check_Allocator_Discrim_Accessibility
(Curr_Exp
, Alloc_Typ
);
5262 -- Non-constant-folded if expressions
5264 elsif Nkind
(Disc_Exp
) = N_If_Expression
then
5265 -- Check both expressions if they are still present in the face
5268 Expr
:= Next
(First
(Expressions
(Disc_Exp
)));
5269 if Present
(Expr
) then
5270 Check_Allocator_Discrim_Accessibility_Exprs
(Expr
, Alloc_Typ
);
5272 if Present
(Expr
) then
5273 Check_Allocator_Discrim_Accessibility_Exprs
5278 -- Non-constant-folded case expressions
5280 elsif Nkind
(Disc_Exp
) = N_Case_Expression
then
5281 -- Check all alternatives
5283 Alt
:= First
(Alternatives
(Disc_Exp
));
5284 while Present
(Alt
) loop
5285 Check_Allocator_Discrim_Accessibility_Exprs
5286 (Expression
(Alt
), Alloc_Typ
);
5291 -- Base case, check the accessibility of the original node of the
5295 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Alloc_Typ
);
5297 end Check_Allocator_Discrim_Accessibility_Exprs
;
5299 ----------------------------
5300 -- In_Dispatching_Context --
5301 ----------------------------
5303 function In_Dispatching_Context
return Boolean is
5304 Par
: constant Node_Id
:= Parent
(N
);
5307 return Nkind
(Par
) in N_Subprogram_Call
5308 and then Is_Entity_Name
(Name
(Par
))
5309 and then Is_Dispatching_Operation
(Entity
(Name
(Par
)));
5310 end In_Dispatching_Context
;
5312 -- Start of processing for Resolve_Allocator
5315 -- Replace general access with specific type
5317 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
5318 Set_Etype
(N
, Base_Type
(Typ
));
5321 if Is_Abstract_Type
(Typ
) then
5322 Error_Msg_N
("type of allocator cannot be abstract", N
);
5325 -- For qualified expression, resolve the expression using the given
5326 -- subtype (nothing to do for type mark, subtype indication)
5328 if Nkind
(E
) = N_Qualified_Expression
then
5329 if Is_Class_Wide_Type
(Etype
(E
))
5330 and then not Is_Class_Wide_Type
(Desig_T
)
5331 and then not In_Dispatching_Context
5334 ("class-wide allocator not allowed for this access type", N
);
5337 -- Do a full resolution to apply constraint and predicate checks
5339 Resolve_Qualified_Expression
(E
, Etype
(E
));
5340 Check_Unset_Reference
(Expression
(E
));
5342 -- Allocators generated by the build-in-place expansion mechanism
5343 -- are explicitly marked as coming from source but do not need to be
5344 -- checked for limited initialization. To exclude this case, ensure
5345 -- that the parent of the allocator is a source node.
5346 -- The return statement constructed for an Expression_Function does
5347 -- not come from source but requires a limited check.
5349 if Is_Limited_Type
(Etype
(E
))
5350 and then Comes_From_Source
(N
)
5352 (Comes_From_Source
(Parent
(N
))
5354 (Ekind
(Current_Scope
) = E_Function
5355 and then Nkind
(Original_Node
(Unit_Declaration_Node
5356 (Current_Scope
))) = N_Expression_Function
))
5357 and then not In_Instance_Body
5359 if not OK_For_Limited_Init
(Etype
(E
), Expression
(E
)) then
5360 if Nkind
(Parent
(N
)) = N_Assignment_Statement
then
5362 ("illegal expression for initialized allocator of a "
5363 & "limited type (RM 7.5 (2.7/2))", N
);
5366 ("initialization not allowed for limited types", N
);
5369 Explain_Limited_Type
(Etype
(E
), N
);
5373 -- Calls to build-in-place functions are not currently supported in
5374 -- allocators for access types associated with a simple storage pool.
5375 -- Supporting such allocators may require passing additional implicit
5376 -- parameters to build-in-place functions (or a significant revision
5377 -- of the current b-i-p implementation to unify the handling for
5378 -- multiple kinds of storage pools). ???
5380 if Is_Inherently_Limited_Type
(Desig_T
)
5381 and then Nkind
(Expression
(E
)) = N_Function_Call
5384 Pool
: constant Entity_Id
:=
5385 Associated_Storage_Pool
(Root_Type
(Typ
));
5389 Present
(Get_Rep_Pragma
5390 (Etype
(Pool
), Name_Simple_Storage_Pool_Type
))
5393 ("limited function calls not yet supported in simple "
5394 & "storage pool allocators", Expression
(E
));
5399 -- A special accessibility check is needed for allocators that
5400 -- constrain access discriminants. The level of the type of the
5401 -- expression used to constrain an access discriminant cannot be
5402 -- deeper than the type of the allocator (in contrast to access
5403 -- parameters, where the level of the actual can be arbitrary).
5405 -- We can't use Valid_Conversion to perform this check because in
5406 -- general the type of the allocator is unrelated to the type of
5407 -- the access discriminant.
5409 if Ekind
(Typ
) /= E_Anonymous_Access_Type
5410 or else Is_Local_Anonymous_Access
(Typ
)
5412 Subtyp
:= Entity
(Subtype_Mark
(E
));
5414 Aggr
:= Original_Node
(Expression
(E
));
5416 if Has_Discriminants
(Subtyp
)
5417 and then Nkind
(Aggr
) in N_Aggregate | N_Extension_Aggregate
5419 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
5421 -- Get the first component expression of the aggregate
5423 if Present
(Expressions
(Aggr
)) then
5424 Disc_Exp
:= First
(Expressions
(Aggr
));
5426 elsif Present
(Component_Associations
(Aggr
)) then
5427 Assoc
:= First
(Component_Associations
(Aggr
));
5429 if Present
(Assoc
) then
5430 Disc_Exp
:= Expression
(Assoc
);
5439 while Present
(Discrim
) and then Present
(Disc_Exp
) loop
5440 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
5441 Check_Allocator_Discrim_Accessibility_Exprs
5445 Next_Discriminant
(Discrim
);
5447 if Present
(Discrim
) then
5448 if Present
(Assoc
) then
5450 Disc_Exp
:= Expression
(Assoc
);
5452 elsif Present
(Next
(Disc_Exp
)) then
5456 Assoc
:= First
(Component_Associations
(Aggr
));
5458 if Present
(Assoc
) then
5459 Disc_Exp
:= Expression
(Assoc
);
5469 -- For a subtype mark or subtype indication, freeze the subtype
5472 Freeze_Expression
(E
);
5474 if Is_Access_Constant
(Typ
) and then not No_Initialization
(N
) then
5476 ("initialization required for access-to-constant allocator", N
);
5479 -- A special accessibility check is needed for allocators that
5480 -- constrain access discriminants. The level of the type of the
5481 -- expression used to constrain an access discriminant cannot be
5482 -- deeper than the type of the allocator (in contrast to access
5483 -- parameters, where the level of the actual can be arbitrary).
5484 -- We can't use Valid_Conversion to perform this check because
5485 -- in general the type of the allocator is unrelated to the type
5486 -- of the access discriminant.
5488 if Nkind
(Original_Node
(E
)) = N_Subtype_Indication
5489 and then (Ekind
(Typ
) /= E_Anonymous_Access_Type
5490 or else Is_Local_Anonymous_Access
(Typ
))
5492 Subtyp
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
5494 if Has_Discriminants
(Subtyp
) then
5495 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
5496 Constr
:= First
(Constraints
(Constraint
(Original_Node
(E
))));
5497 while Present
(Discrim
) and then Present
(Constr
) loop
5498 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
5499 if Nkind
(Constr
) = N_Discriminant_Association
then
5500 Disc_Exp
:= Expression
(Constr
);
5505 Check_Allocator_Discrim_Accessibility_Exprs
5509 Next_Discriminant
(Discrim
);
5516 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
5517 -- check that the level of the type of the created object is not deeper
5518 -- than the level of the allocator's access type, since extensions can
5519 -- now occur at deeper levels than their ancestor types. This is a
5520 -- static accessibility level check; a run-time check is also needed in
5521 -- the case of an initialized allocator with a class-wide argument (see
5522 -- Expand_Allocator_Expression).
5524 if Ada_Version
>= Ada_2005
5525 and then Is_Class_Wide_Type
(Desig_T
)
5528 Exp_Typ
: Entity_Id
;
5531 if Nkind
(E
) = N_Qualified_Expression
then
5532 Exp_Typ
:= Etype
(E
);
5533 elsif Nkind
(E
) = N_Subtype_Indication
then
5534 Exp_Typ
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
5536 Exp_Typ
:= Entity
(E
);
5539 if Type_Access_Level
(Exp_Typ
) >
5540 Deepest_Type_Access_Level
(Typ
)
5542 if In_Instance_Body
then
5543 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5545 ("type in allocator has deeper level than designated "
5546 & "class-wide type<<", E
);
5547 Error_Msg_N
("\Program_Error [<<", E
);
5550 Make_Raise_Program_Error
(Sloc
(N
),
5551 Reason
=> PE_Accessibility_Check_Failed
));
5554 -- Do not apply Ada 2005 accessibility checks on a class-wide
5555 -- allocator if the type given in the allocator is a formal
5556 -- type or within a formal package. A run-time check will be
5557 -- performed in the instance.
5559 elsif not Is_Generic_Type
(Exp_Typ
)
5560 and then not In_Generic_Formal_Package
(Exp_Typ
)
5563 ("type in allocator has deeper level than designated "
5564 & "class-wide type", E
);
5570 -- Check for allocation from an empty storage pool. But do not complain
5571 -- if it's a return statement for a build-in-place function, because the
5572 -- allocator is there just in case the caller uses an allocator. If the
5573 -- caller does use an allocator, it will be caught at the call site.
5575 if No_Pool_Assigned
(Typ
)
5576 and then not For_Special_Return_Object
(N
)
5578 Error_Msg_N
("allocation from empty storage pool!", N
);
5580 -- If the context is an unchecked conversion, as may happen within an
5581 -- inlined subprogram, the allocator is being resolved with its own
5582 -- anonymous type. In that case, if the target type has a specific
5583 -- storage pool, it must be inherited explicitly by the allocator type.
5585 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
5586 and then No
(Associated_Storage_Pool
(Typ
))
5588 Set_Associated_Storage_Pool
5589 (Typ
, Associated_Storage_Pool
(Etype
(Parent
(N
))));
5592 if Ekind
(Etype
(N
)) = E_Anonymous_Access_Type
then
5593 Check_Restriction
(No_Anonymous_Allocators
, N
);
5596 -- Check that an allocator with task parts isn't for a nested access
5597 -- type when restriction No_Task_Hierarchy applies.
5599 if not Is_Library_Level_Entity
(Base_Type
(Typ
))
5600 and then Has_Task
(Base_Type
(Desig_T
))
5602 Check_Restriction
(No_Task_Hierarchy
, N
);
5605 -- An illegal allocator may be rewritten as a raise Program_Error
5608 if Nkind
(N
) = N_Allocator
then
5610 -- Avoid coextension processing for an allocator that is the
5611 -- expansion of a build-in-place function call.
5613 if Nkind
(Original_Node
(N
)) = N_Allocator
5614 and then Nkind
(Expression
(Original_Node
(N
))) =
5615 N_Qualified_Expression
5616 and then Nkind
(Expression
(Expression
(Original_Node
(N
)))) =
5618 and then Is_Expanded_Build_In_Place_Call
5619 (Expression
(Expression
(Original_Node
(N
))))
5621 null; -- b-i-p function call case
5624 -- An anonymous access discriminant is the definition of a
5627 if Ekind
(Typ
) = E_Anonymous_Access_Type
5628 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
5629 N_Discriminant_Specification
5632 Discr
: constant Entity_Id
:=
5633 Defining_Identifier
(Associated_Node_For_Itype
(Typ
));
5636 Check_Restriction
(No_Coextensions
, N
);
5638 -- Ada 2012 AI05-0052: If the designated type of the
5639 -- allocator is limited, then the allocator shall not
5640 -- be used to define the value of an access discriminant
5641 -- unless the discriminated type is immutably limited.
5643 if Ada_Version
>= Ada_2012
5644 and then Is_Limited_Type
(Desig_T
)
5645 and then not Is_Inherently_Limited_Type
(Scope
(Discr
))
5648 ("only immutably limited types can have anonymous "
5649 & "access discriminants designating a limited type",
5654 -- Avoid marking an allocator as a dynamic coextension if it is
5655 -- within a static construct.
5657 if not Is_Static_Coextension
(N
) then
5658 Set_Is_Dynamic_Coextension
(N
);
5660 -- Finalization and deallocation of coextensions utilizes an
5661 -- approximate implementation which does not directly adhere
5662 -- to the semantic rules. Warn on potential issues involving
5665 if Is_Controlled
(Desig_T
) then
5667 ("??coextension will not be finalized when its "
5668 & "associated owner is deallocated or finalized", N
);
5671 ("??coextension will not be deallocated when its "
5672 & "associated owner is deallocated", N
);
5676 -- Cleanup for potential static coextensions
5679 Set_Is_Dynamic_Coextension
(N
, False);
5680 Set_Is_Static_Coextension
(N
, False);
5682 -- Anonymous access-to-controlled objects are not finalized on
5683 -- time because this involves run-time ownership and currently
5684 -- this property is not available. In rare cases the object may
5685 -- not be finalized at all. Warn on potential issues involving
5686 -- anonymous access-to-controlled objects.
5688 if Ekind
(Typ
) = E_Anonymous_Access_Type
5689 and then Is_Controlled_Active
(Desig_T
)
5692 ("??object designated by anonymous access object might "
5693 & "not be finalized until its enclosing library unit "
5694 & "goes out of scope", N
);
5695 Error_Msg_N
("\use named access type instead", N
);
5701 -- Report a simple error: if the designated object is a local task,
5702 -- its body has not been seen yet, and its activation will fail an
5703 -- elaboration check.
5705 if Is_Task_Type
(Desig_T
)
5706 and then Scope
(Base_Type
(Desig_T
)) = Current_Scope
5707 and then Is_Compilation_Unit
(Current_Scope
)
5708 and then Ekind
(Current_Scope
) = E_Package
5709 and then not In_Package_Body
(Current_Scope
)
5711 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5712 Error_Msg_N
("cannot activate task before body seen<<", N
);
5713 Error_Msg_N
("\Program_Error [<<", N
);
5716 -- Ada 2012 (AI05-0111-3): Detect an attempt to allocate a task or a
5717 -- type with a task component on a subpool. This action must raise
5718 -- Program_Error at runtime.
5720 if Ada_Version
>= Ada_2012
5721 and then Nkind
(N
) = N_Allocator
5722 and then Present
(Subpool_Handle_Name
(N
))
5723 and then Has_Task
(Desig_T
)
5725 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5726 Error_Msg_N
("cannot allocate task on subpool<<", N
);
5727 Error_Msg_N
("\Program_Error [<<", N
);
5730 Make_Raise_Program_Error
(Sloc
(N
),
5731 Reason
=> PE_Explicit_Raise
));
5734 end Resolve_Allocator
;
5736 ---------------------------
5737 -- Resolve_Arithmetic_Op --
5738 ---------------------------
5740 -- Used for resolving all arithmetic operators except exponentiation
5742 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
5743 L
: constant Node_Id
:= Left_Opnd
(N
);
5744 R
: constant Node_Id
:= Right_Opnd
(N
);
5745 TL
: constant Entity_Id
:= Base_Type
(Etype
(L
));
5746 TR
: constant Entity_Id
:= Base_Type
(Etype
(R
));
5750 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
5751 -- We do the resolution using the base type, because intermediate values
5752 -- in expressions always are of the base type, not a subtype of it.
5754 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean;
5755 -- Returns True if N is in a context that expects "any real type"
5757 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean;
5758 -- Return True iff given type is Integer or universal real/integer
5760 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
);
5761 -- Choose type of integer literal in fixed-point operation to conform
5762 -- to available fixed-point type. T is the type of the other operand,
5763 -- which is needed to determine the expected type of N.
5765 procedure Set_Operand_Type
(N
: Node_Id
);
5766 -- Set operand type to T if universal
5768 -------------------------------
5769 -- Expected_Type_Is_Any_Real --
5770 -------------------------------
5772 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean is
5774 -- N is the expression after "delta" in a fixed_point_definition;
5777 return Nkind
(Parent
(N
)) in N_Ordinary_Fixed_Point_Definition
5778 | N_Decimal_Fixed_Point_Definition
5780 -- N is one of the bounds in a real_range_specification;
5783 | N_Real_Range_Specification
5785 -- N is the expression of a delta_constraint;
5788 | N_Delta_Constraint
;
5789 end Expected_Type_Is_Any_Real
;
5791 -----------------------------
5792 -- Is_Integer_Or_Universal --
5793 -----------------------------
5795 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean is
5797 Index
: Interp_Index
;
5801 if not Is_Overloaded
(N
) then
5803 return Base_Type
(T
) = Base_Type
(Standard_Integer
)
5804 or else Is_Universal_Numeric_Type
(T
);
5806 Get_First_Interp
(N
, Index
, It
);
5807 while Present
(It
.Typ
) loop
5808 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
)
5809 or else Is_Universal_Numeric_Type
(It
.Typ
)
5814 Get_Next_Interp
(Index
, It
);
5819 end Is_Integer_Or_Universal
;
5821 ----------------------------
5822 -- Set_Mixed_Mode_Operand --
5823 ----------------------------
5825 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
) is
5826 Index
: Interp_Index
;
5830 if Universal_Interpretation
(N
) = Universal_Integer
then
5832 -- A universal integer literal is resolved as standard integer
5833 -- except in the case of a fixed-point result, where we leave it
5834 -- as universal (to be handled by Exp_Fixd later on)
5836 if Is_Fixed_Point_Type
(T
) then
5837 Resolve
(N
, Universal_Integer
);
5839 Resolve
(N
, Standard_Integer
);
5842 elsif Universal_Interpretation
(N
) = Universal_Real
5843 and then (T
= Base_Type
(Standard_Integer
)
5844 or else Is_Universal_Numeric_Type
(T
))
5846 -- A universal real can appear in a fixed-type context. We resolve
5847 -- the literal with that context, even though this might raise an
5848 -- exception prematurely (the other operand may be zero).
5852 elsif Etype
(N
) = Base_Type
(Standard_Integer
)
5853 and then T
= Universal_Real
5854 and then Is_Overloaded
(N
)
5856 -- Integer arg in mixed-mode operation. Resolve with universal
5857 -- type, in case preference rule must be applied.
5859 Resolve
(N
, Universal_Integer
);
5861 elsif Etype
(N
) = T
and then B_Typ
/= Universal_Fixed
then
5863 -- If the operand is part of a fixed multiplication operation,
5864 -- a conversion will be applied to each operand, so resolve it
5865 -- with its own type.
5867 if Nkind
(Parent
(N
)) in N_Op_Divide | N_Op_Multiply
then
5871 -- Not a mixed-mode operation, resolve with context
5876 elsif Etype
(N
) = Any_Fixed
then
5878 -- N may itself be a mixed-mode operation, so use context type
5882 elsif Is_Fixed_Point_Type
(T
)
5883 and then B_Typ
= Universal_Fixed
5884 and then Is_Overloaded
(N
)
5886 -- Must be (fixed * fixed) operation, operand must have one
5887 -- compatible interpretation.
5889 Resolve
(N
, Any_Fixed
);
5891 elsif Is_Fixed_Point_Type
(B_Typ
)
5892 and then (T
= Universal_Real
or else Is_Fixed_Point_Type
(T
))
5893 and then Is_Overloaded
(N
)
5895 -- C * F(X) in a fixed context, where C is a real literal or a
5896 -- fixed-point expression. F must have either a fixed type
5897 -- interpretation or an integer interpretation, but not both.
5899 Get_First_Interp
(N
, Index
, It
);
5900 while Present
(It
.Typ
) loop
5901 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
) then
5902 if Analyzed
(N
) then
5903 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5905 Resolve
(N
, Standard_Integer
);
5908 elsif Is_Fixed_Point_Type
(It
.Typ
) then
5909 if Analyzed
(N
) then
5910 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5912 Resolve
(N
, It
.Typ
);
5916 Get_Next_Interp
(Index
, It
);
5919 -- Reanalyze the literal with the fixed type of the context. If
5920 -- context is Universal_Fixed, we are within a conversion, leave
5921 -- the literal as a universal real because there is no usable
5922 -- fixed type, and the target of the conversion plays no role in
5936 if B_Typ
= Universal_Fixed
5937 and then Nkind
(Op2
) = N_Real_Literal
5939 T2
:= Universal_Real
;
5944 Set_Analyzed
(Op2
, False);
5948 -- A universal real conditional expression can appear in a fixed-type
5949 -- context and must be resolved with that context to facilitate the
5950 -- code generation in the back end. However, If the context is
5951 -- Universal_fixed (i.e. as an operand of a multiplication/division
5952 -- involving a fixed-point operand) the conditional expression must
5953 -- resolve to a unique visible fixed_point type, normally Duration.
5955 elsif Nkind
(N
) in N_Case_Expression | N_If_Expression
5956 and then Etype
(N
) = Universal_Real
5957 and then Is_Fixed_Point_Type
(B_Typ
)
5959 if B_Typ
= Universal_Fixed
then
5960 Resolve
(N
, Unique_Fixed_Point_Type
(N
));
5969 end Set_Mixed_Mode_Operand
;
5971 ----------------------
5972 -- Set_Operand_Type --
5973 ----------------------
5975 procedure Set_Operand_Type
(N
: Node_Id
) is
5977 if Is_Universal_Numeric_Type
(Etype
(N
)) then
5980 end Set_Operand_Type
;
5982 -- Start of processing for Resolve_Arithmetic_Op
5985 if Ekind
(Entity
(N
)) = E_Function
5986 and then Is_Imported
(Entity
(N
))
5987 and then Is_Intrinsic_Subprogram
(Entity
(N
))
5989 Generate_Reference
(Entity
(N
), N
);
5990 Resolve_Intrinsic_Operator
(N
, Typ
);
5993 -- Special-case for mixed-mode universal expressions or fixed point type
5994 -- operation: each argument is resolved separately. The same treatment
5995 -- is required if one of the operands of a fixed point operation is
5996 -- universal real, since in this case we don't do a conversion to a
5997 -- specific fixed-point type (instead the expander handles the case).
5999 -- Set the type of the node to its universal interpretation because
6000 -- legality checks on an exponentiation operand need the context.
6002 elsif Is_Universal_Numeric_Type
(B_Typ
)
6003 and then Present
(Universal_Interpretation
(L
))
6004 and then Present
(Universal_Interpretation
(R
))
6006 Set_Etype
(N
, B_Typ
);
6007 Resolve
(L
, Universal_Interpretation
(L
));
6008 Resolve
(R
, Universal_Interpretation
(R
));
6010 elsif (B_Typ
= Universal_Real
6011 or else Etype
(N
) = Universal_Fixed
6012 or else (Etype
(N
) = Any_Fixed
6013 and then Is_Fixed_Point_Type
(B_Typ
))
6014 or else (Is_Fixed_Point_Type
(B_Typ
)
6015 and then (Is_Integer_Or_Universal
(L
)
6017 Is_Integer_Or_Universal
(R
))))
6018 and then Nkind
(N
) in N_Op_Multiply | N_Op_Divide
6020 if TL
= Universal_Integer
or else TR
= Universal_Integer
then
6021 Check_For_Visible_Operator
(N
, B_Typ
);
6024 -- If context is a fixed type and one operand is integer, the other
6025 -- is resolved with the type of the context.
6027 if Is_Fixed_Point_Type
(B_Typ
)
6028 and then (Base_Type
(TL
) = Base_Type
(Standard_Integer
)
6029 or else TL
= Universal_Integer
)
6034 elsif Is_Fixed_Point_Type
(B_Typ
)
6035 and then (Base_Type
(TR
) = Base_Type
(Standard_Integer
)
6036 or else TR
= Universal_Integer
)
6041 -- If both operands are universal and the context is a floating
6042 -- point type, the operands are resolved to the type of the context.
6044 elsif Is_Floating_Point_Type
(B_Typ
) then
6049 Set_Mixed_Mode_Operand
(L
, TR
);
6050 Set_Mixed_Mode_Operand
(R
, TL
);
6053 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
6054 -- multiplying operators from being used when the expected type is
6055 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
6056 -- some cases where the expected type is actually Any_Real;
6057 -- Expected_Type_Is_Any_Real takes care of that case.
6059 if Etype
(N
) = Universal_Fixed
6060 or else Etype
(N
) = Any_Fixed
6062 if B_Typ
= Universal_Fixed
6063 and then not Expected_Type_Is_Any_Real
(N
)
6064 and then Nkind
(Parent
(N
)) not in
6065 N_Type_Conversion | N_Unchecked_Type_Conversion
6067 Error_Msg_N
("type cannot be determined from context!", N
);
6068 Error_Msg_N
("\explicit conversion to result type required", N
);
6070 Set_Etype
(L
, Any_Type
);
6071 Set_Etype
(R
, Any_Type
);
6074 if Ada_Version
= Ada_83
6075 and then Etype
(N
) = Universal_Fixed
6076 and then Nkind
(Parent
(N
)) not in
6077 N_Type_Conversion | N_Unchecked_Type_Conversion
6080 ("(Ada 83) fixed-point operation needs explicit "
6084 -- The expected type is "any real type" in contexts like
6086 -- type T is delta <universal_fixed-expression> ...
6088 -- in which case we need to set the type to Universal_Real
6089 -- so that static expression evaluation will work properly.
6091 if Expected_Type_Is_Any_Real
(N
) then
6092 Set_Etype
(N
, Universal_Real
);
6094 Set_Etype
(N
, B_Typ
);
6098 elsif Is_Fixed_Point_Type
(B_Typ
)
6099 and then (Is_Integer_Or_Universal
(L
)
6100 or else Nkind
(L
) = N_Real_Literal
6101 or else Nkind
(R
) = N_Real_Literal
6102 or else Is_Integer_Or_Universal
(R
))
6104 Set_Etype
(N
, B_Typ
);
6106 elsif Etype
(N
) = Any_Fixed
then
6108 -- If no previous errors, this is only possible if one operand is
6109 -- overloaded and the context is universal. Resolve as such.
6111 Set_Etype
(N
, B_Typ
);
6115 if Is_Universal_Numeric_Type
(TL
)
6117 Is_Universal_Numeric_Type
(TR
)
6119 Check_For_Visible_Operator
(N
, B_Typ
);
6122 -- If the context is Universal_Fixed and the operands are also
6123 -- universal fixed, this is an error, unless there is only one
6124 -- applicable fixed_point type (usually Duration).
6126 if B_Typ
= Universal_Fixed
and then Etype
(L
) = Universal_Fixed
then
6127 T
:= Unique_Fixed_Point_Type
(N
);
6129 if T
= Any_Type
then
6142 -- If one of the arguments was resolved to a non-universal type.
6143 -- label the result of the operation itself with the same type.
6144 -- Do the same for the universal argument, if any.
6146 T
:= Intersect_Types
(L
, R
);
6147 Set_Etype
(N
, Base_Type
(T
));
6148 Set_Operand_Type
(L
);
6149 Set_Operand_Type
(R
);
6152 Generate_Operator_Reference
(N
, Typ
);
6153 Analyze_Dimension
(N
);
6154 Eval_Arithmetic_Op
(N
);
6156 -- Set overflow and division checking bit
6158 if Nkind
(N
) in N_Op
then
6159 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
6160 Enable_Overflow_Check
(N
);
6163 -- Give warning if explicit division by zero
6165 if Nkind
(N
) in N_Op_Divide | N_Op_Rem | N_Op_Mod
6166 and then not Division_Checks_Suppressed
(Etype
(N
))
6168 Rop
:= Right_Opnd
(N
);
6170 if Compile_Time_Known_Value
(Rop
)
6171 and then ((Is_Integer_Type
(Etype
(Rop
))
6172 and then Expr_Value
(Rop
) = Uint_0
)
6174 (Is_Real_Type
(Etype
(Rop
))
6175 and then Expr_Value_R
(Rop
) = Ureal_0
))
6177 -- Specialize the warning message according to the operation.
6178 -- When SPARK_Mode is On, force a warning instead of an error
6179 -- in that case, as this likely corresponds to deactivated
6180 -- code. The following warnings are for the case
6185 -- For division, we have two cases, for float division
6186 -- of an unconstrained float type, on a machine where
6187 -- Machine_Overflows is false, we don't get an exception
6188 -- at run-time, but rather an infinity or Nan. The Nan
6189 -- case is pretty obscure, so just warn about infinities.
6191 if Is_Floating_Point_Type
(Typ
)
6192 and then not Is_Constrained
(Typ
)
6193 and then not Machine_Overflows_On_Target
6196 ("float division by zero, may generate "
6197 & "'+'/'- infinity??", Right_Opnd
(N
));
6199 -- For all other cases, we get a Constraint_Error
6202 Apply_Compile_Time_Constraint_Error
6203 (N
, "division by zero??", CE_Divide_By_Zero
,
6204 Loc
=> Sloc
(Right_Opnd
(N
)),
6205 Warn
=> SPARK_Mode
= On
);
6209 Apply_Compile_Time_Constraint_Error
6210 (N
, "rem with zero divisor??", CE_Divide_By_Zero
,
6211 Loc
=> Sloc
(Right_Opnd
(N
)),
6212 Warn
=> SPARK_Mode
= On
);
6215 Apply_Compile_Time_Constraint_Error
6216 (N
, "mod with zero divisor??", CE_Divide_By_Zero
,
6217 Loc
=> Sloc
(Right_Opnd
(N
)),
6218 Warn
=> SPARK_Mode
= On
);
6220 -- Division by zero can only happen with division, rem,
6221 -- and mod operations.
6224 raise Program_Error
;
6227 -- Otherwise just set the flag to check at run time
6230 Activate_Division_Check
(N
);
6234 -- If Restriction No_Implicit_Conditionals is active, then it is
6235 -- violated if either operand can be negative for mod, or for rem
6236 -- if both operands can be negative.
6238 if Restriction_Check_Required
(No_Implicit_Conditionals
)
6239 and then Nkind
(N
) in N_Op_Rem | N_Op_Mod
6248 -- Set if corresponding operand might be negative
6252 (Left_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
6253 LNeg
:= not OK
or else Lo
< 0;
6256 (Right_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
6257 RNeg
:= not OK
or else Lo
< 0;
6259 -- Check if we will be generating conditionals. There are two
6260 -- cases where that can happen, first for REM, the only case
6261 -- is largest negative integer mod -1, where the division can
6262 -- overflow, but we still have to give the right result. The
6263 -- front end generates a test for this annoying case. Here we
6264 -- just test if both operands can be negative (that's what the
6265 -- expander does, so we match its logic here).
6267 -- The second case is mod where either operand can be negative.
6268 -- In this case, the back end has to generate additional tests.
6270 if (Nkind
(N
) = N_Op_Rem
and then (LNeg
and RNeg
))
6272 (Nkind
(N
) = N_Op_Mod
and then (LNeg
or RNeg
))
6274 Check_Restriction
(No_Implicit_Conditionals
, N
);
6280 Check_Unset_Reference
(L
);
6281 Check_Unset_Reference
(R
);
6282 end Resolve_Arithmetic_Op
;
6288 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
6289 Loc
: constant Source_Ptr
:= Sloc
(N
);
6290 Subp
: constant Node_Id
:= Name
(N
);
6291 Body_Id
: Entity_Id
;
6302 -- Preserve relevant elaboration-related attributes of the context which
6303 -- are no longer available or very expensive to recompute once analysis,
6304 -- resolution, and expansion are over.
6306 Mark_Elaboration_Attributes
6312 -- The context imposes a unique interpretation with type Typ on a
6313 -- procedure or function call. Find the entity of the subprogram that
6314 -- yields the expected type, and propagate the corresponding formal
6315 -- constraints on the actuals. The caller has established that an
6316 -- interpretation exists, and emitted an error if not unique.
6318 -- First deal with the case of a call to an access-to-subprogram,
6319 -- dereference made explicit in Analyze_Call.
6321 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
6322 if not Is_Overloaded
(Subp
) then
6323 Nam
:= Etype
(Subp
);
6326 -- Find the interpretation whose type (a subprogram type) has a
6327 -- return type that is compatible with the context. Analysis of
6328 -- the node has established that one exists.
6332 Get_First_Interp
(Subp
, I
, It
);
6333 while Present
(It
.Typ
) loop
6334 if Covers
(Typ
, Etype
(It
.Typ
)) then
6339 Get_Next_Interp
(I
, It
);
6343 raise Program_Error
;
6347 -- If the prefix is not an entity, then resolve it
6349 if not Is_Entity_Name
(Subp
) then
6350 Resolve
(Subp
, Nam
);
6353 -- For an indirect call, we always invalidate checks, since we do not
6354 -- know whether the subprogram is local or global. Yes we could do
6355 -- better here, e.g. by knowing that there are no local subprograms,
6356 -- but it does not seem worth the effort. Similarly, we kill all
6357 -- knowledge of current constant values.
6359 Kill_Current_Values
;
6361 -- If this is a procedure call which is really an entry call, do
6362 -- the conversion of the procedure call to an entry call. Protected
6363 -- operations use the same circuitry because the name in the call
6364 -- can be an arbitrary expression with special resolution rules.
6366 elsif Nkind
(Subp
) in N_Selected_Component | N_Indexed_Component
6367 or else (Is_Entity_Name
(Subp
) and then Is_Entry
(Entity
(Subp
)))
6369 Resolve_Entry_Call
(N
, Typ
);
6371 if Legacy_Elaboration_Checks
then
6372 Check_Elab_Call
(N
);
6375 -- Annotate the tree by creating a call marker in case the original
6376 -- call is transformed by expansion. The call marker is automatically
6377 -- saved for later examination by the ABE Processing phase.
6379 Build_Call_Marker
(N
);
6381 -- Kill checks and constant values, as above for indirect case
6382 -- Who knows what happens when another task is activated?
6384 Kill_Current_Values
;
6387 -- Normal subprogram call with name established in Resolve
6389 elsif not Is_Type
(Entity
(Subp
)) then
6390 Nam
:= Entity
(Subp
);
6391 Set_Entity_With_Checks
(Subp
, Nam
);
6393 -- Otherwise we must have the case of an overloaded call
6396 pragma Assert
(Is_Overloaded
(Subp
));
6398 -- Initialize Nam to prevent warning (we know it will be assigned
6399 -- in the loop below, but the compiler does not know that).
6403 Get_First_Interp
(Subp
, I
, It
);
6404 while Present
(It
.Typ
) loop
6405 if Covers
(Typ
, It
.Typ
) then
6407 Set_Entity_With_Checks
(Subp
, Nam
);
6411 Get_Next_Interp
(I
, It
);
6415 -- Check that a call to Current_Task does not occur in an entry body
6417 if Is_RTE
(Nam
, RE_Current_Task
) then
6426 -- Exclude calls that occur within the default of a formal
6427 -- parameter of the entry, since those are evaluated outside
6430 exit when No
(P
) or else Nkind
(P
) = N_Parameter_Specification
;
6432 if Nkind
(P
) = N_Entry_Body
6433 or else (Nkind
(P
) = N_Subprogram_Body
6434 and then Is_Entry_Barrier_Function
(P
))
6437 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6439 ("& should not be used in entry body (RM C.7(17))<<",
6441 Error_Msg_NE
("\Program_Error [<<", N
, Nam
);
6443 Make_Raise_Program_Error
(Loc
,
6444 Reason
=> PE_Current_Task_In_Entry_Body
));
6445 Set_Etype
(N
, Rtype
);
6452 -- Check that a procedure call does not occur in the context of the
6453 -- entry call statement of a conditional or timed entry call. Note that
6454 -- the case of a call to a subprogram renaming of an entry will also be
6455 -- rejected. The test for N not being an N_Entry_Call_Statement is
6456 -- defensive, covering the possibility that the processing of entry
6457 -- calls might reach this point due to later modifications of the code
6460 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
6461 and then Nkind
(N
) /= N_Entry_Call_Statement
6462 and then Entry_Call_Statement
(Parent
(N
)) = N
6464 if Ada_Version
< Ada_2005
then
6465 Error_Msg_N
("entry call required in select statement", N
);
6467 -- Ada 2005 (AI-345): If a procedure_call_statement is used
6468 -- for a procedure_or_entry_call, the procedure_name or
6469 -- procedure_prefix of the procedure_call_statement shall denote
6470 -- an entry renamed by a procedure, or (a view of) a primitive
6471 -- subprogram of a limited interface whose first parameter is
6472 -- a controlling parameter.
6474 elsif Nkind
(N
) = N_Procedure_Call_Statement
6475 and then not Is_Renamed_Entry
(Nam
)
6476 and then not Is_Controlling_Limited_Procedure
(Nam
)
6479 ("entry call or dispatching primitive of interface required", N
);
6483 -- Check that this is not a call to a protected procedure or entry from
6484 -- within a protected function.
6486 Check_Internal_Protected_Use
(N
, Nam
);
6488 -- Freeze the subprogram name if not in a spec-expression. Note that
6489 -- we freeze procedure calls as well as function calls. Procedure calls
6490 -- are not frozen according to the rules (RM 13.14(14)) because it is
6491 -- impossible to have a procedure call to a non-frozen procedure in
6492 -- pure Ada, but in the code that we generate in the expander, this
6493 -- rule needs extending because we can generate procedure calls that
6496 -- In Ada 2012, expression functions may be called within pre/post
6497 -- conditions of subsequent functions or expression functions. Such
6498 -- calls do not freeze when they appear within generated bodies,
6499 -- (including the body of another expression function) which would
6500 -- place the freeze node in the wrong scope. An expression function
6501 -- is frozen in the usual fashion, by the appearance of a real body,
6502 -- or at the end of a declarative part. However an implicit call to
6503 -- an expression function may appear when it is part of a default
6504 -- expression in a call to an initialization procedure, and must be
6505 -- frozen now, even if the body is inserted at a later point.
6506 -- Otherwise, the call freezes the expression if expander is active,
6507 -- for example as part of an object declaration.
6509 if Is_Entity_Name
(Subp
)
6510 and then not In_Spec_Expression
6511 and then not Is_Expression_Function_Or_Completion
(Current_Scope
)
6512 and then not (Chars
(Current_Scope
) = Name_uWrapped_Statements
6513 and then Is_Expression_Function_Or_Completion
6514 (Scope
(Current_Scope
)))
6516 (not Is_Expression_Function_Or_Completion
(Entity
(Subp
))
6517 or else Expander_Active
)
6519 if Is_Expression_Function
(Entity
(Subp
)) then
6521 -- Force freeze of expression function in call
6523 Set_Comes_From_Source
(Subp
, True);
6524 Set_Must_Not_Freeze
(Subp
, False);
6527 Freeze_Expression
(Subp
);
6530 -- For a predefined operator, the type of the result is the type imposed
6531 -- by context, except for a predefined operation on universal fixed.
6532 -- Otherwise the type of the call is the type returned by the subprogram
6535 if Is_Predefined_Op
(Nam
) then
6536 if Etype
(N
) /= Universal_Fixed
then
6540 -- If the subprogram returns an array type, and the context requires the
6541 -- component type of that array type, the node is really an indexing of
6542 -- the parameterless call. Resolve as such. A pathological case occurs
6543 -- when the type of the component is an access to the array type. In
6544 -- this case the call is truly ambiguous. If the call is to an intrinsic
6545 -- subprogram, it can't be an indexed component. This check is necessary
6546 -- because if it's Unchecked_Conversion, and we have "type T_Ptr is
6547 -- access T;" and "type T is array (...) of T_Ptr;" (i.e. an array of
6548 -- pointers to the same array), the compiler gets confused and does an
6549 -- infinite recursion.
6551 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
6553 ((Is_Array_Type
(Etype
(Nam
))
6554 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
6556 (Is_Access_Type
(Etype
(Nam
))
6557 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
6559 Covers
(Typ
, Component_Type
(Designated_Type
(Etype
(Nam
))))
6560 and then not Is_Intrinsic_Subprogram
(Entity
(Subp
))))
6563 Index_Node
: Node_Id
;
6565 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
6568 -- If this is a parameterless call there is no ambiguity and the
6569 -- call has the type of the function.
6571 if No
(First_Actual
(N
)) then
6572 Set_Etype
(N
, Etype
(Nam
));
6574 if Present
(First_Formal
(Nam
)) then
6575 Resolve_Actuals
(N
, Nam
);
6578 -- Annotate the tree by creating a call marker in case the
6579 -- original call is transformed by expansion. The call marker
6580 -- is automatically saved for later examination by the ABE
6581 -- Processing phase.
6583 Build_Call_Marker
(N
);
6585 elsif Is_Access_Type
(Ret_Type
)
6587 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
6590 ("cannot disambiguate function call and indexing", N
);
6592 New_Subp
:= Relocate_Node
(Subp
);
6594 -- The called entity may be an explicit dereference, in which
6595 -- case there is no entity to set.
6597 if Nkind
(New_Subp
) /= N_Explicit_Dereference
then
6598 Set_Entity
(Subp
, Nam
);
6601 if (Is_Array_Type
(Ret_Type
)
6602 and then Component_Type
(Ret_Type
) /= Any_Type
)
6604 (Is_Access_Type
(Ret_Type
)
6606 Component_Type
(Designated_Type
(Ret_Type
)) /= Any_Type
)
6608 if Needs_No_Actuals
(Nam
) then
6610 -- Indexed call to a parameterless function
6613 Make_Indexed_Component
(Loc
,
6615 Make_Function_Call
(Loc
, Name
=> New_Subp
),
6616 Expressions
=> Parameter_Associations
(N
));
6618 -- An Ada 2005 prefixed call to a primitive operation
6619 -- whose first parameter is the prefix. This prefix was
6620 -- prepended to the parameter list, which is actually a
6621 -- list of indexes. Remove the prefix in order to build
6622 -- the proper indexed component.
6625 Make_Indexed_Component
(Loc
,
6627 Make_Function_Call
(Loc
,
6629 Parameter_Associations
=>
6631 (Remove_Head
(Parameter_Associations
(N
)))),
6632 Expressions
=> Parameter_Associations
(N
));
6635 -- Preserve the parenthesis count of the node
6637 Set_Paren_Count
(Index_Node
, Paren_Count
(N
));
6639 -- Since we are correcting a node classification error made
6640 -- by the parser, we call Replace rather than Rewrite.
6642 Replace
(N
, Index_Node
);
6644 Set_Etype
(Prefix
(N
), Ret_Type
);
6647 if Legacy_Elaboration_Checks
then
6648 Check_Elab_Call
(Prefix
(N
));
6651 -- Annotate the tree by creating a call marker in case
6652 -- the original call is transformed by expansion. The call
6653 -- marker is automatically saved for later examination by
6654 -- the ABE Processing phase.
6656 Build_Call_Marker
(Prefix
(N
));
6658 Resolve_Indexed_Component
(N
, Typ
);
6666 -- If the called function is not declared in the main unit and it
6667 -- returns the limited view of type then use the available view (as
6668 -- is done in Try_Object_Operation) to prevent back-end confusion;
6669 -- for the function entity itself. The call must appear in a context
6670 -- where the nonlimited view is available. If the function entity is
6671 -- in the extended main unit then no action is needed, because the
6672 -- back end handles this case. In either case the type of the call
6673 -- is the nonlimited view.
6675 if From_Limited_With
(Etype
(Nam
))
6676 and then Present
(Available_View
(Etype
(Nam
)))
6678 Set_Etype
(N
, Available_View
(Etype
(Nam
)));
6680 if not In_Extended_Main_Code_Unit
(Nam
) then
6681 Set_Etype
(Nam
, Available_View
(Etype
(Nam
)));
6685 Set_Etype
(N
, Etype
(Nam
));
6689 -- In the case where the call is to an overloaded subprogram, Analyze
6690 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
6691 -- such a case Normalize_Actuals needs to be called once more to order
6692 -- the actuals correctly. Otherwise the call will have the ordering
6693 -- given by the last overloaded subprogram whether this is the correct
6694 -- one being called or not.
6696 if Is_Overloaded
(Subp
) then
6697 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
6698 pragma Assert
(Norm_OK
);
6701 -- In any case, call is fully resolved now. Reset Overload flag, to
6702 -- prevent subsequent overload resolution if node is analyzed again
6704 Set_Is_Overloaded
(Subp
, False);
6705 Set_Is_Overloaded
(N
, False);
6707 -- A Ghost entity must appear in a specific context
6709 if Is_Ghost_Entity
(Nam
) and then Comes_From_Source
(N
) then
6710 Check_Ghost_Context
(Nam
, N
);
6713 if Is_Entity_Name
(Subp
) then
6714 Local_Restrict
.Check_Call
6715 (Call
=> N
, Callee
=> Ultimate_Alias
(Nam
));
6717 Local_Restrict
.Check_Call
(Call
=> N
);
6720 -- If we are calling the current subprogram from immediately within its
6721 -- body, then that is the case where we can sometimes detect cases of
6722 -- infinite recursion statically. Do not try this in case restriction
6723 -- No_Recursion is in effect anyway, and do it only for source calls.
6725 if Comes_From_Source
(N
) then
6726 Scop
:= Current_Scope
;
6728 -- Issue warning for possible infinite recursion in the absence
6729 -- of the No_Recursion restriction.
6731 if Same_Or_Aliased_Subprograms
(Nam
, Scop
)
6732 and then not Restriction_Active
(No_Recursion
)
6733 and then not Is_Static_Function
(Scop
)
6734 and then Check_Infinite_Recursion
(N
)
6736 -- Here we detected and flagged an infinite recursion, so we do
6737 -- not need to test the case below for further warnings. Also we
6738 -- are all done if we now have a raise SE node.
6740 if Nkind
(N
) = N_Raise_Storage_Error
then
6744 -- If call is to immediately containing subprogram, then check for
6745 -- the case of a possible run-time detectable infinite recursion.
6748 Scope_Loop
: while Scop
/= Standard_Standard
loop
6749 if Same_Or_Aliased_Subprograms
(Nam
, Scop
) then
6751 -- Ada 2022 (AI12-0075): Static functions are never allowed
6752 -- to make a recursive call, as specified by 6.8(5.4/5).
6754 if Is_Static_Function
(Scop
) then
6756 ("recursive call not allowed in static expression "
6759 Set_Error_Posted
(Scop
);
6764 -- Although in general case, recursion is not statically
6765 -- checkable, the case of calling an immediately containing
6766 -- subprogram is easy to catch.
6768 if not Is_Ignored_Ghost_Entity
(Nam
) then
6769 Check_Restriction
(No_Recursion
, N
);
6772 -- If the recursive call is to a parameterless subprogram,
6773 -- then even if we can't statically detect infinite
6774 -- recursion, this is pretty suspicious, and we output a
6775 -- warning. Furthermore, we will try later to detect some
6776 -- cases here at run time by expanding checking code (see
6777 -- Detect_Infinite_Recursion in package Exp_Ch6).
6779 -- If the recursive call is within a handler, do not emit a
6780 -- warning, because this is a common idiom: loop until input
6781 -- is correct, catch illegal input in handler and restart.
6783 if No
(First_Formal
(Nam
))
6784 and then Etype
(Nam
) = Standard_Void_Type
6785 and then not Error_Posted
(N
)
6786 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
6788 -- For the case of a procedure call. We give the message
6789 -- only if the call is the first statement in a sequence
6790 -- of statements, or if all previous statements are
6791 -- simple assignments. This is simply a heuristic to
6792 -- decrease false positives, without losing too many good
6793 -- warnings. The idea is that these previous statements
6794 -- may affect global variables the procedure depends on.
6795 -- We also exclude raise statements, that may arise from
6796 -- constraint checks and are probably unrelated to the
6797 -- intended control flow.
6799 if Nkind
(N
) = N_Procedure_Call_Statement
6800 and then Is_List_Member
(N
)
6806 while Present
(P
) loop
6807 if Nkind
(P
) not in N_Assignment_Statement
6808 | N_Raise_Constraint_Error
6818 -- Do not give warning if we are in a conditional context
6821 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
6823 if (K
= N_Loop_Statement
6824 and then Present
(Iteration_Scheme
(Parent
(N
))))
6825 or else K
= N_If_Statement
6826 or else K
= N_Elsif_Part
6827 or else K
= N_Case_Statement_Alternative
6833 -- Here warning is to be issued
6835 Set_Has_Recursive_Call
(Nam
);
6836 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6837 Error_Msg_N
("possible infinite recursion<<!", N
);
6838 Error_Msg_N
("\Storage_Error ]<<!", N
);
6844 Scop
:= Scope
(Scop
);
6845 end loop Scope_Loop
;
6849 -- Check obsolescent reference to Ada.Characters.Handling subprogram
6851 Check_Obsolescent_2005_Entity
(Nam
, Subp
);
6853 -- If subprogram name is a predefined operator, it was given in
6854 -- functional notation. Replace call node with operator node, so
6855 -- that actuals can be resolved appropriately.
6857 if Ekind
(Nam
) = E_Operator
or else Is_Predefined_Op
(Nam
) then
6858 Make_Call_Into_Operator
(N
, Typ
, Nam
);
6861 elsif Present
(Alias
(Nam
)) and then Is_Predefined_Op
(Alias
(Nam
)) then
6862 Resolve_Actuals
(N
, Nam
);
6863 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
6867 -- Create a transient scope if the expander is active and the resulting
6868 -- type requires it.
6870 -- There are several notable exceptions:
6872 -- a) Intrinsic subprograms (Unchecked_Conversion and source info
6873 -- functions) do not use the secondary stack even though the return
6874 -- type may be unconstrained.
6876 -- b) Subprograms that are ignored ghost entities do not return anything
6878 -- c) Calls to a build-in-place function, since such functions may
6879 -- allocate their result directly in a target object, and cases where
6880 -- the result does get allocated in the secondary stack are checked for
6881 -- within the specialized Exp_Ch6 procedures for expanding those
6882 -- build-in-place calls.
6884 -- d) Calls to inlinable expression functions do not use the secondary
6885 -- stack (since the call will be replaced by its returned object).
6887 -- e) If the subprogram is marked Inline, then even if it returns
6888 -- an unconstrained type the call does not require use of the secondary
6889 -- stack. However, inlining will only take place if the body to inline
6890 -- is already present. It may not be available if e.g. the subprogram is
6891 -- declared in a child instance.
6893 -- f) If the subprogram is a static expression function and the call is
6894 -- a static call (the actuals are all static expressions), then we never
6895 -- want to create a transient scope (this could occur in the case of a
6896 -- static string-returning call).
6898 -- g) If the call is the expression of a simple return statement that
6899 -- returns on the same stack, since it will be handled as a tail call
6900 -- by Expand_Simple_Function_Return.
6903 and then Ekind
(Nam
) in E_Function | E_Subprogram_Type
6904 and then Requires_Transient_Scope
(Etype
(Nam
))
6905 and then not Is_Intrinsic_Subprogram
(Nam
)
6906 and then not Is_Ignored_Ghost_Entity
(Nam
)
6907 and then not Is_Build_In_Place_Function
(Nam
)
6908 and then not Is_Inlinable_Expression_Function
(Nam
)
6909 and then not (Is_Inlined
(Nam
)
6910 and then Has_Pragma_Inline
(Nam
)
6911 and then Nkind
(Unit_Declaration_Node
(Nam
)) =
6912 N_Subprogram_Declaration
6914 Present
(Body_To_Inline
(Unit_Declaration_Node
(Nam
))))
6915 and then not Is_Static_Function_Call
(N
)
6916 and then not (Nkind
(Parent
(N
)) = N_Simple_Return_Statement
6918 Needs_Secondary_Stack
6921 (Return_Statement_Entity
(Parent
(N
))))) =
6922 Needs_Secondary_Stack
(Etype
(Nam
)))
6924 Establish_Transient_Scope
(N
, Needs_Secondary_Stack
(Etype
(Nam
)));
6926 -- If the call appears within the bounds of a loop, it will be
6927 -- rewritten and reanalyzed, nothing left to do here.
6929 if Nkind
(N
) /= N_Function_Call
then
6934 -- A protected function cannot be called within the definition of the
6935 -- enclosing protected type, unless it is part of a pre/postcondition
6936 -- on another protected operation. This may appear in the entry wrapper
6937 -- created for an entry with preconditions.
6939 if Is_Protected_Type
(Scope
(Nam
))
6940 and then In_Open_Scopes
(Scope
(Nam
))
6941 and then not Has_Completion
(Scope
(Nam
))
6942 and then not In_Spec_Expression
6943 and then not Is_Entry_Wrapper
(Current_Scope
)
6946 ("& cannot be called before end of protected definition", N
, Nam
);
6949 -- Propagate interpretation to actuals, and add default expressions
6952 if Present
(First_Formal
(Nam
)) then
6953 Resolve_Actuals
(N
, Nam
);
6955 -- Overloaded literals are rewritten as function calls, for purpose of
6956 -- resolution. After resolution, we can replace the call with the
6959 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
6960 Copy_Node
(Subp
, N
);
6961 Resolve_Entity_Name
(N
, Typ
);
6963 -- Avoid validation, since it is a static function call
6965 Generate_Reference
(Nam
, Subp
);
6969 -- If the subprogram is not global, then kill all saved values and
6970 -- checks. This is a bit conservative, since in many cases we could do
6971 -- better, but it is not worth the effort. Similarly, we kill constant
6972 -- values. However we do not need to do this for internal entities
6973 -- (unless they are inherited user-defined subprograms), since they
6974 -- are not in the business of molesting local values.
6976 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
6977 -- kill all checks and values for calls to global subprograms. This
6978 -- takes care of the case where an access to a local subprogram is
6979 -- taken, and could be passed directly or indirectly and then called
6980 -- from almost any context.
6982 -- Note: we do not do this step till after resolving the actuals. That
6983 -- way we still take advantage of the current value information while
6984 -- scanning the actuals.
6986 -- We suppress killing values if we are processing the nodes associated
6987 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
6988 -- type kills all the values as part of analyzing the code that
6989 -- initializes the dispatch tables.
6991 if Inside_Freezing_Actions
= 0
6992 and then (not Is_Library_Level_Entity
(Nam
)
6993 or else Suppress_Value_Tracking_On_Call
6994 (Nearest_Dynamic_Scope
(Current_Scope
)))
6995 and then (Comes_From_Source
(Nam
)
6996 or else (Present
(Alias
(Nam
))
6997 and then Comes_From_Source
(Alias
(Nam
))))
6999 Kill_Current_Values
;
7002 -- If we are warning about unread OUT parameters, this is the place to
7003 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
7004 -- after the above call to Kill_Current_Values (since that call clears
7005 -- the Last_Assignment field of all local variables).
7007 if (Warn_On_Modified_Unread
or Warn_On_All_Unread_Out_Parameters
)
7008 and then Comes_From_Source
(N
)
7009 and then In_Extended_Main_Source_Unit
(N
)
7016 F
:= First_Formal
(Nam
);
7017 A
:= First_Actual
(N
);
7018 while Present
(F
) and then Present
(A
) loop
7019 if Ekind
(F
) in E_Out_Parameter | E_In_Out_Parameter
7020 and then Warn_On_Modified_As_Out_Parameter
(F
)
7021 and then Is_Entity_Name
(A
)
7022 and then Present
(Entity
(A
))
7023 and then Comes_From_Source
(N
)
7024 and then Safe_To_Capture_Value
(N
, Entity
(A
))
7026 Set_Last_Assignment
(Entity
(A
), A
);
7035 -- If the subprogram is a primitive operation, check whether or not
7036 -- it is a correct dispatching call.
7038 if Is_Overloadable
(Nam
) and then Is_Dispatching_Operation
(Nam
) then
7039 Check_Dispatching_Call
(N
);
7041 -- If the subprogram is an abstract operation, then flag an error
7043 elsif Is_Overloadable
(Nam
) and then Is_Abstract_Subprogram
(Nam
) then
7044 Nondispatching_Call_To_Abstract_Operation
(N
, Nam
);
7047 -- If this is a dispatching call, generate the appropriate reference,
7048 -- for better source navigation in GNAT Studio.
7050 if Is_Overloadable
(Nam
) and then Present
(Controlling_Argument
(N
)) then
7051 Generate_Reference
(Nam
, Subp
, 'R');
7053 -- Normal case, not a dispatching call: generate a call reference
7056 Generate_Reference
(Nam
, Subp
, 's');
7059 if Is_Intrinsic_Subprogram
(Nam
) then
7060 Check_Intrinsic_Call
(N
);
7063 -- Check for violation of restriction No_Specific_Termination_Handlers
7064 -- and warn on a potentially blocking call to Abort_Task.
7066 if Restriction_Check_Required
(No_Specific_Termination_Handlers
)
7067 and then (Is_RTE
(Nam
, RE_Set_Specific_Handler
)
7069 Is_RTE
(Nam
, RE_Specific_Handler
))
7071 Check_Restriction
(No_Specific_Termination_Handlers
, N
);
7073 elsif Is_RTE
(Nam
, RE_Abort_Task
) then
7074 Check_Potentially_Blocking_Operation
(N
);
7077 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
7078 -- timing event violates restriction No_Relative_Delay (AI-0211). We
7079 -- need to check the second argument to determine whether it is an
7080 -- absolute or relative timing event.
7082 if Restriction_Check_Required
(No_Relative_Delay
)
7083 and then Is_RTE
(Nam
, RE_Set_Handler
)
7084 and then Is_RTE
(Etype
(Next_Actual
(First_Actual
(N
))), RE_Time_Span
)
7086 Check_Restriction
(No_Relative_Delay
, N
);
7089 -- Issue an error for a call to an eliminated subprogram. This routine
7090 -- will not perform the check if the call appears within a default
7093 Check_For_Eliminated_Subprogram
(Subp
, Nam
);
7095 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
7096 -- class-wide and the call dispatches on result in a context that does
7097 -- not provide a tag, the call raises Program_Error.
7099 if Nkind
(N
) = N_Function_Call
7100 and then In_Instance
7101 and then Is_Generic_Actual_Type
(Typ
)
7102 and then Is_Class_Wide_Type
(Typ
)
7103 and then Has_Controlling_Result
(Nam
)
7104 and then Nkind
(Parent
(N
)) = N_Object_Declaration
7106 -- Verify that none of the formals are controlling
7109 Call_OK
: Boolean := False;
7113 F
:= First_Formal
(Nam
);
7114 while Present
(F
) loop
7115 if Is_Controlling_Formal
(F
) then
7124 Error_Msg_Warn
:= SPARK_Mode
/= On
;
7125 Error_Msg_N
("!cannot determine tag of result<<", N
);
7126 Error_Msg_N
("\Program_Error [<<!", N
);
7128 Make_Raise_Program_Error
(Sloc
(N
),
7129 Reason
=> PE_Explicit_Raise
));
7134 -- Check for calling a function with OUT or IN OUT parameter when the
7135 -- calling context (us right now) is not Ada 2012, so does not allow
7136 -- OUT or IN OUT parameters in function calls. Functions declared in
7137 -- a predefined unit are OK, as they may be called indirectly from a
7138 -- user-declared instantiation.
7140 if Ada_Version
< Ada_2012
7141 and then Ekind
(Nam
) = E_Function
7142 and then Has_Out_Or_In_Out_Parameter
(Nam
)
7143 and then not In_Predefined_Unit
(Nam
)
7145 Error_Msg_NE
("& has at least one OUT or `IN OUT` parameter", N
, Nam
);
7146 Error_Msg_N
("\call to this function only allowed in Ada 2012", N
);
7149 -- Check the dimensions of the actuals in the call. For function calls,
7150 -- propagate the dimensions from the returned type to N.
7152 Analyze_Dimension_Call
(N
, Nam
);
7154 -- Check unreachable code after calls to procedures with No_Return
7156 if Ekind
(Nam
) = E_Procedure
and then No_Return
(Nam
) then
7157 Check_Unreachable_Code
(N
);
7160 -- All done, evaluate call and deal with elaboration issues
7164 if Legacy_Elaboration_Checks
then
7165 Check_Elab_Call
(N
);
7168 -- Annotate the tree by creating a call marker in case the original call
7169 -- is transformed by expansion. The call marker is automatically saved
7170 -- for later examination by the ABE Processing phase.
7172 Build_Call_Marker
(N
);
7174 Mark_Use_Clauses
(Subp
);
7176 Warn_On_Overlapping_Actuals
(Nam
, N
);
7178 -- Ada 2022 (AI12-0075): If the call is a static call to a static
7179 -- expression function, then we want to "inline" the call, replacing
7180 -- it with the folded static result. This is not done if the checking
7181 -- for a potentially static expression is enabled or if an error has
7182 -- been posted on the call (which may be due to the check for recursive
7183 -- calls, in which case we don't want to fall into infinite recursion
7184 -- when doing the inlining).
7186 if not Checking_Potentially_Static_Expression
7187 and then Is_Static_Function_Call
(N
)
7188 and then not Is_Intrinsic_Subprogram
(Ultimate_Alias
(Nam
))
7189 and then not Error_Posted
(Ultimate_Alias
(Nam
))
7191 Inline_Static_Function_Call
(N
, Ultimate_Alias
(Nam
));
7193 -- In GNATprove mode, expansion is disabled, but we want to inline some
7194 -- subprograms to facilitate formal verification. Indirect calls through
7195 -- a subprogram type or within a generic cannot be inlined. Inlining is
7196 -- performed only for calls subject to SPARK_Mode on.
7198 elsif GNATprove_Mode
7199 and then SPARK_Mode
= On
7200 and then Is_Overloadable
(Nam
)
7201 and then not Inside_A_Generic
7203 Nam_UA
:= Ultimate_Alias
(Nam
);
7204 Nam_Decl
:= Unit_Declaration_Node
(Nam_UA
);
7206 if Nkind
(Nam_Decl
) = N_Subprogram_Declaration
then
7207 Body_Id
:= Corresponding_Body
(Nam_Decl
);
7209 -- Nothing to do if the subprogram is not eligible for inlining in
7210 -- GNATprove mode, or inlining is disabled with switch -gnatdm
7212 if not Is_Inlined_Always
(Nam_UA
)
7213 or else not Can_Be_Inlined_In_GNATprove_Mode
(Nam_UA
, Body_Id
)
7214 or else Debug_Flag_M
7218 -- Calls cannot be inlined inside assertions, as GNATprove treats
7219 -- assertions as logic expressions. Only issue a message when the
7220 -- body has been seen, otherwise this leads to spurious messages
7221 -- on expression functions.
7223 elsif In_Assertion_Expr
/= 0 then
7225 ("cannot inline & (in assertion expression)?", N
, Nam_UA
,
7226 Suppress_Info
=> No
(Body_Id
));
7228 -- Calls cannot be inlined inside default expressions
7230 elsif In_Default_Expr
then
7232 ("cannot inline & (in default expression)?", N
, Nam_UA
);
7234 -- Calls cannot be inlined inside potentially unevaluated
7235 -- expressions, as this would create complex actions inside
7236 -- expressions, that are not handled by GNATprove.
7238 elsif Is_Potentially_Unevaluated
(N
) then
7240 ("cannot inline & (in potentially unevaluated context)?",
7243 -- Calls are not inlined inside the loop_parameter_specification
7244 -- or iterator_specification of the quantified expression, as they
7245 -- are only preanalyzed. Calls in the predicate part are handled
7246 -- by the previous test on potentially unevaluated expressions.
7248 elsif In_Quantified_Expression
(N
) then
7250 ("cannot inline & (in quantified expression)?", N
, Nam_UA
);
7252 -- Inlining should not be performed during preanalysis
7254 elsif Full_Analysis
then
7256 -- Do not inline calls inside expression functions or functions
7257 -- generated by the front end for subtype predicates, as this
7258 -- would prevent interpreting them as logical formulas in
7259 -- GNATprove. Only issue a message when the body has been seen,
7260 -- otherwise this leads to spurious messages on callees that
7261 -- are themselves expression functions.
7263 if Present
(Current_Subprogram
)
7265 (Is_Expression_Function_Or_Completion
(Current_Subprogram
)
7266 or else Is_Predicate_Function
(Current_Subprogram
)
7267 or else Is_Invariant_Procedure
(Current_Subprogram
)
7268 or else Is_DIC_Procedure
(Current_Subprogram
))
7271 Issue_Msg
: constant Boolean :=
7273 and then Present
(Body_To_Inline
(Nam_Decl
));
7275 if Is_Predicate_Function
(Current_Subprogram
) then
7277 ("cannot inline & (inside predicate)?",
7278 N
, Nam_UA
, Suppress_Info
=> not Issue_Msg
);
7280 elsif Is_Invariant_Procedure
(Current_Subprogram
) then
7282 ("cannot inline & (inside invariant)?",
7283 N
, Nam_UA
, Suppress_Info
=> not Issue_Msg
);
7285 elsif Is_DIC_Procedure
(Current_Subprogram
) then
7287 ("cannot inline & (inside Default_Initial_Condition)?",
7288 N
, Nam_UA
, Suppress_Info
=> not Issue_Msg
);
7292 ("cannot inline & (inside expression function)?",
7293 N
, Nam_UA
, Suppress_Info
=> not Issue_Msg
);
7297 -- Cannot inline a call inside the definition of a record type,
7298 -- typically inside the constraints of the type. Calls in
7299 -- default expressions are also not inlined, but this is
7300 -- filtered out above when testing In_Default_Expr.
7302 elsif Is_Record_Type
(Current_Scope
) then
7304 ("cannot inline & (inside record type)?", N
, Nam_UA
);
7306 -- With the one-pass inlining technique, a call cannot be
7307 -- inlined if the corresponding body has not been seen yet.
7309 elsif No
(Body_Id
) then
7311 ("cannot inline & (body not seen yet)?", N
, Nam_UA
);
7313 -- Nothing to do if there is no body to inline, indicating that
7314 -- the subprogram is not suitable for inlining in GNATprove
7317 elsif No
(Body_To_Inline
(Nam_Decl
)) then
7320 -- Calls cannot be inlined inside the conditions of while
7321 -- loops, as this would create complex actions inside
7322 -- the condition, that are not handled by GNATprove.
7324 elsif In_Statement_Condition_With_Actions
(N
) then
7326 ("cannot inline & (in while loop condition)?", N
, Nam_UA
);
7328 -- Do not inline calls which would possibly lead to missing a
7329 -- type conversion check on an input parameter.
7331 elsif not Call_Can_Be_Inlined_In_GNATprove_Mode
(N
, Nam
) then
7333 ("cannot inline & (possible check on input parameters)?",
7336 -- Otherwise, inline the call, issuing an info message when
7340 if Debug_Flag_Underscore_F
then
7342 ("info: analyzing call to & in context?", N
, Nam_UA
);
7345 Expand_Inlined_Call
(N
, Nam_UA
, Nam
);
7352 -----------------------------
7353 -- Resolve_Case_Expression --
7354 -----------------------------
7356 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7359 Alt_Typ
: Entity_Id
;
7363 Alt
:= First
(Alternatives
(N
));
7364 while Present
(Alt
) loop
7365 Alt_Expr
:= Expression
(Alt
);
7367 if Error_Posted
(Alt_Expr
) then
7371 Resolve_Dependent_Expression
(N
, Alt_Expr
, Typ
);
7373 Check_Unset_Reference
(Alt_Expr
);
7374 Alt_Typ
:= Etype
(Alt_Expr
);
7376 -- When the expression is of a scalar subtype different from the
7377 -- result subtype, then insert a conversion to ensure the generation
7378 -- of a constraint check.
7380 if Is_Scalar_Type
(Alt_Typ
) and then Alt_Typ
/= Typ
then
7381 Rewrite
(Alt_Expr
, Convert_To
(Typ
, Alt_Expr
));
7382 Analyze_And_Resolve
(Alt_Expr
, Typ
);
7388 -- Apply RM 4.5.7 (17/3): whether the expression is statically or
7389 -- dynamically tagged must be known statically.
7391 if Is_Tagged_Type
(Typ
) and then not Is_Class_Wide_Type
(Typ
) then
7392 Alt
:= First
(Alternatives
(N
));
7393 Is_Dyn
:= Is_Dynamically_Tagged
(Expression
(Alt
));
7395 while Present
(Alt
) loop
7396 if Is_Dynamically_Tagged
(Expression
(Alt
)) /= Is_Dyn
then
7398 ("all or none of the dependent expressions can be "
7399 & "dynamically tagged", N
);
7407 Eval_Case_Expression
(N
);
7408 Analyze_Dimension
(N
);
7409 end Resolve_Case_Expression
;
7411 -------------------------------
7412 -- Resolve_Character_Literal --
7413 -------------------------------
7415 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
7416 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7420 -- Verify that the character does belong to the type of the context
7422 Set_Etype
(N
, B_Typ
);
7423 Eval_Character_Literal
(N
);
7425 -- Wide_Wide_Character literals must always be defined, since the set
7426 -- of wide wide character literals is complete, i.e. if a character
7427 -- literal is accepted by the parser, then it is OK for wide wide
7428 -- character (out of range character literals are rejected).
7430 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
7433 -- Always accept character literal for type Any_Character, which
7434 -- occurs in error situations and in comparisons of literals, both
7435 -- of which should accept all literals.
7437 elsif B_Typ
= Any_Character
then
7440 -- For Standard.Character or a type derived from it, check that the
7441 -- literal is in range.
7443 elsif Root_Type
(B_Typ
) = Standard_Character
then
7444 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
7448 -- For Standard.Wide_Character or a type derived from it, check that the
7449 -- literal is in range.
7451 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
7452 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
7456 -- If the entity is already set, this has already been resolved in a
7457 -- generic context, or comes from expansion. Nothing else to do.
7459 elsif Present
(Entity
(N
)) then
7462 -- Otherwise we have a user defined character type, and we can use the
7463 -- standard visibility mechanisms to locate the referenced entity.
7466 C
:= Current_Entity
(N
);
7467 while Present
(C
) loop
7468 if Etype
(C
) = B_Typ
then
7469 Set_Entity_With_Checks
(N
, C
);
7470 Generate_Reference
(C
, N
);
7478 -- If we fall through, then the literal does not match any of the
7479 -- entries of the enumeration type. This isn't just a constraint error
7480 -- situation, it is an illegality (see RM 4.2).
7483 ("character not defined for }", N
, First_Subtype
(B_Typ
));
7484 end Resolve_Character_Literal
;
7486 ---------------------------
7487 -- Resolve_Comparison_Op --
7488 ---------------------------
7490 -- The operands must have compatible types and the boolean context does not
7491 -- participate in the resolution. The first pass verifies that the operands
7492 -- are not ambiguous and sets their type correctly, or to Any_Type in case
7493 -- of ambiguity. If both operands are strings or aggregates, then they are
7494 -- ambiguous even if they carry a single (universal) type.
7496 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7497 L
: constant Node_Id
:= Left_Opnd
(N
);
7498 R
: constant Node_Id
:= Right_Opnd
(N
);
7500 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
7503 if T
= Any_Fixed
then
7504 T
:= Unique_Fixed_Point_Type
(L
);
7507 Set_Etype
(N
, Base_Type
(Typ
));
7508 Generate_Reference
(T
, N
, ' ');
7510 if T
= Any_Type
then
7511 -- Deal with explicit ambiguity of operands
7513 if Is_Overloaded
(L
) or else Is_Overloaded
(R
) then
7514 Ambiguous_Operands
(N
);
7520 -- Deal with other error cases
7522 if T
= Any_String
or else
7523 T
= Any_Composite
or else
7526 if T
= Any_Character
then
7527 Ambiguous_Character
(L
);
7529 Error_Msg_N
("ambiguous operands for comparison", N
);
7532 Set_Etype
(N
, Any_Type
);
7536 -- Resolve the operands if types OK
7540 Set_Compare_Type
(N
, T
);
7541 Check_Unset_Reference
(L
);
7542 Check_Unset_Reference
(R
);
7543 Generate_Operator_Reference
(N
, T
);
7544 Check_Low_Bound_Tested
(N
);
7546 -- Check comparison on unordered enumeration
7548 if Bad_Unordered_Enumeration_Reference
(N
, Etype
(L
)) then
7549 Error_Msg_Sloc
:= Sloc
(Etype
(L
));
7551 ("comparison on unordered enumeration type& declared#?.u?",
7555 Analyze_Dimension
(N
);
7557 Eval_Relational_Op
(N
);
7558 end Resolve_Comparison_Op
;
7560 --------------------------------
7561 -- Resolve_Declare_Expression --
7562 --------------------------------
7564 procedure Resolve_Declare_Expression
7568 Expr
: constant Node_Id
:= Expression
(N
);
7571 Local
: Entity_Id
:= Empty
;
7573 function Replace_Local
(N
: Node_Id
) return Traverse_Result
;
7574 -- Use a tree traversal to replace each occurrence of the name of
7575 -- a local object declared in the construct, with the corresponding
7576 -- entity. This replaces the usual way to perform name capture by
7577 -- visibility, because it is not possible to place on the scope
7578 -- stack the fake scope created for the analysis of the local
7579 -- declarations; such a scope conflicts with the transient scopes
7580 -- that may be generated if the expression includes function calls
7581 -- requiring finalization.
7587 function Replace_Local
(N
: Node_Id
) return Traverse_Result
is
7589 -- The identifier may be the prefix of a selected component,
7590 -- but not a selector name, because the local entities do not
7591 -- have a scope that can be named: a selected component whose
7592 -- selector is a homonym of a local entity must denote some
7595 if Nkind
(N
) = N_Identifier
7596 and then Chars
(N
) = Chars
(Local
)
7597 and then No
(Entity
(N
))
7599 (Nkind
(Parent
(N
)) /= N_Selected_Component
7600 or else N
= Prefix
(Parent
(N
)))
7602 Set_Entity
(N
, Local
);
7603 Set_Etype
(N
, Etype
(Local
));
7609 procedure Replace_Local_Ref
is new Traverse_Proc
(Replace_Local
);
7611 -- Start of processing for Resolve_Declare_Expression
7615 Decl
:= First
(Actions
(N
));
7617 while Present
(Decl
) loop
7619 N_Object_Declaration | N_Object_Renaming_Declaration
7620 and then Comes_From_Source
(Defining_Identifier
(Decl
))
7622 Local
:= Defining_Identifier
(Decl
);
7623 Replace_Local_Ref
(Expr
);
7625 -- Traverse the expression to replace references to local
7626 -- variables that occur within declarations of the
7627 -- declare_expression.
7630 D
: Node_Id
:= Next
(Decl
);
7632 while Present
(D
) loop
7633 Replace_Local_Ref
(D
);
7642 -- The end of the declarative list is a freeze point for the
7643 -- local declarations.
7645 if Present
(Local
) then
7646 Decl
:= Parent
(Local
);
7647 Freeze_All
(First_Entity
(Scope
(Local
)), Decl
);
7650 Resolve
(Expr
, Typ
);
7651 Check_Unset_Reference
(Expr
);
7652 end Resolve_Declare_Expression
;
7654 -----------------------------------
7655 -- Resolve_Dependent_Expression --
7656 -----------------------------------
7658 procedure Resolve_Dependent_Expression
7664 -- RM 4.5.7(8/3) says that the expected type of dependent expressions is
7665 -- that of the conditional expression but RM 4.5.7(10/3) forces the type
7666 -- of the conditional expression without changing the expected type (the
7667 -- expected type of the operand of a type conversion is any type), so we
7668 -- may have a gap between these two types that is bridged by the dynamic
7669 -- semantics specified by RM 4.5.7(20/3) with the associated legality
7670 -- rule RM 4.5.7(16/3) that will be automatically enforced.
7672 if Nkind
(Parent
(N
)) = N_Type_Conversion
7673 and then Nkind
(Expr
) /= N_Raise_Expression
7675 Convert_To_And_Rewrite
(Typ
, Expr
);
7676 Analyze_And_Resolve
(Expr
);
7678 Resolve
(Expr
, Typ
);
7680 end Resolve_Dependent_Expression
;
7682 -----------------------------------------
7683 -- Resolve_Discrete_Subtype_Indication --
7684 -----------------------------------------
7686 procedure Resolve_Discrete_Subtype_Indication
7694 Analyze
(Subtype_Mark
(N
));
7695 S
:= Entity
(Subtype_Mark
(N
));
7697 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
7698 Error_Msg_N
("expect range constraint for discrete type", N
);
7699 Set_Etype
(N
, Any_Type
);
7702 R
:= Range_Expression
(Constraint
(N
));
7710 if Base_Type
(S
) /= Base_Type
(Typ
) then
7712 ("expect subtype of }", N
, First_Subtype
(Typ
));
7714 -- Rewrite the constraint as a range of Typ
7715 -- to allow compilation to proceed further.
7718 Rewrite
(Low_Bound
(R
),
7719 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
7720 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
7721 Attribute_Name
=> Name_First
));
7722 Rewrite
(High_Bound
(R
),
7723 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
7724 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
7725 Attribute_Name
=> Name_First
));
7729 Set_Etype
(N
, Etype
(R
));
7731 -- Additionally, we must check that the bounds are compatible
7732 -- with the given subtype, which might be different from the
7733 -- type of the context.
7735 Apply_Range_Check
(R
, S
);
7737 -- ??? If the above check statically detects a Constraint_Error
7738 -- it replaces the offending bound(s) of the range R with a
7739 -- Constraint_Error node. When the itype which uses these bounds
7740 -- is frozen the resulting call to Duplicate_Subexpr generates
7741 -- a new temporary for the bounds.
7743 -- Unfortunately there are other itypes that are also made depend
7744 -- on these bounds, so when Duplicate_Subexpr is called they get
7745 -- a forward reference to the newly created temporaries and Gigi
7746 -- aborts on such forward references. This is probably sign of a
7747 -- more fundamental problem somewhere else in either the order of
7748 -- itype freezing or the way certain itypes are constructed.
7750 -- To get around this problem we call Remove_Side_Effects right
7751 -- away if either bounds of R are a Constraint_Error.
7754 L
: constant Node_Id
:= Low_Bound
(R
);
7755 H
: constant Node_Id
:= High_Bound
(R
);
7758 if Nkind
(L
) = N_Raise_Constraint_Error
then
7759 Remove_Side_Effects
(L
);
7762 if Nkind
(H
) = N_Raise_Constraint_Error
then
7763 Remove_Side_Effects
(H
);
7767 Check_Unset_Reference
(Low_Bound
(R
));
7768 Check_Unset_Reference
(High_Bound
(R
));
7771 end Resolve_Discrete_Subtype_Indication
;
7773 -------------------------
7774 -- Resolve_Entity_Name --
7775 -------------------------
7777 -- Used to resolve identifiers and expanded names
7779 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
7780 function Is_Assignment_Or_Object_Expression
7782 Expr
: Node_Id
) return Boolean;
7783 -- Determine whether node Context denotes an assignment statement or an
7784 -- object declaration whose expression is node Expr.
7786 function Is_Attribute_Expression
(Expr
: Node_Id
) return Boolean;
7787 -- Determine whether Expr is part of an N_Attribute_Reference
7790 ----------------------------------------
7791 -- Is_Assignment_Or_Object_Expression --
7792 ----------------------------------------
7794 function Is_Assignment_Or_Object_Expression
7796 Expr
: Node_Id
) return Boolean
7799 if Nkind
(Context
) in N_Assignment_Statement | N_Object_Declaration
7800 and then Expression
(Context
) = Expr
7804 -- Check whether a construct that yields a name is the expression of
7805 -- an assignment statement or an object declaration.
7807 elsif (Nkind
(Context
) in N_Attribute_Reference
7808 | N_Explicit_Dereference
7809 | N_Indexed_Component
7810 | N_Selected_Component
7812 and then Prefix
(Context
) = Expr
)
7814 (Nkind
(Context
) in N_Type_Conversion
7815 | N_Unchecked_Type_Conversion
7816 and then Expression
(Context
) = Expr
)
7819 Is_Assignment_Or_Object_Expression
7820 (Context
=> Parent
(Context
),
7823 -- Otherwise the context is not an assignment statement or an object
7829 end Is_Assignment_Or_Object_Expression
;
7831 -----------------------------
7832 -- Is_Attribute_Expression --
7833 -----------------------------
7835 function Is_Attribute_Expression
(Expr
: Node_Id
) return Boolean is
7836 N
: Node_Id
:= Expr
;
7838 while Present
(N
) loop
7839 if Nkind
(N
) = N_Attribute_Reference
then
7842 -- Prevent the search from going too far
7844 elsif Is_Body_Or_Package_Declaration
(N
) then
7852 end Is_Attribute_Expression
;
7856 E
: constant Entity_Id
:= Entity
(N
);
7859 -- Start of processing for Resolve_Entity_Name
7862 -- If garbage from errors, set to Any_Type and return
7864 if No
(E
) and then Total_Errors_Detected
/= 0 then
7865 Set_Etype
(N
, Any_Type
);
7869 -- Replace named numbers by corresponding literals. Note that this is
7870 -- the one case where Resolve_Entity_Name must reset the Etype, since
7871 -- it is currently marked as universal.
7873 if Ekind
(E
) = E_Named_Integer
then
7875 Eval_Named_Integer
(N
);
7877 elsif Ekind
(E
) = E_Named_Real
then
7879 Eval_Named_Real
(N
);
7881 -- For enumeration literals, we need to make sure that a proper style
7882 -- check is done, since such literals are overloaded, and thus we did
7883 -- not do a style check during the first phase of analysis.
7885 elsif Ekind
(E
) = E_Enumeration_Literal
then
7886 Set_Entity_With_Checks
(N
, E
);
7887 Eval_Entity_Name
(N
);
7889 -- Case of (sub)type name appearing in a context where an expression
7890 -- is expected. This is legal if occurrence is a current instance.
7891 -- See RM 8.6 (17/3). It is also legal if the expression is
7892 -- part of a choice pattern for a case stmt/expr having a
7893 -- non-discrete selecting expression.
7895 elsif Is_Type
(E
) then
7896 if Is_Current_Instance
(N
) or else Is_Case_Choice_Pattern
(N
) then
7899 -- Any other use is an error
7903 ("invalid use of subtype mark in expression or call", N
);
7906 -- Check discriminant use if entity is discriminant in current scope,
7907 -- i.e. discriminant of record or concurrent type currently being
7908 -- analyzed. Uses in corresponding body are unrestricted.
7910 elsif Ekind
(E
) = E_Discriminant
7911 and then Scope
(E
) = Current_Scope
7912 and then not Has_Completion
(Current_Scope
)
7914 Check_Discriminant_Use
(N
);
7916 -- A parameterless generic function cannot appear in a context that
7917 -- requires resolution.
7919 elsif Ekind
(E
) = E_Generic_Function
then
7920 Error_Msg_N
("illegal use of generic function", N
);
7922 -- In Ada 83 an OUT parameter cannot be read, but attributes of
7923 -- array types (i.e. bounds and length) are legal.
7925 elsif Ekind
(E
) = E_Out_Parameter
7926 and then (Is_Scalar_Type
(Etype
(E
))
7927 or else not Is_Attribute_Expression
(Parent
(N
)))
7929 and then (Nkind
(Parent
(N
)) in N_Op
7930 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
7931 or else Is_Assignment_Or_Object_Expression
7932 (Context
=> Parent
(N
),
7935 if Ada_Version
= Ada_83
then
7936 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
7939 -- In all other cases, just do the possible static evaluation
7942 -- A deferred constant that appears in an expression must have a
7943 -- completion, unless it has been removed by in-place expansion of
7944 -- an aggregate. A constant that is a renaming does not need
7947 if Ekind
(E
) = E_Constant
7948 and then Comes_From_Source
(E
)
7949 and then No
(Constant_Value
(E
))
7950 and then Is_Frozen
(Etype
(E
))
7951 and then not In_Spec_Expression
7952 and then not Is_Imported
(E
)
7953 and then Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
7955 if No_Initialization
(Parent
(E
))
7956 or else (Present
(Full_View
(E
))
7957 and then No_Initialization
(Parent
(Full_View
(E
))))
7962 ("deferred constant is frozen before completion", N
);
7966 Eval_Entity_Name
(N
);
7971 -- When the entity appears in a parameter association, retrieve the
7972 -- related subprogram call.
7974 if Nkind
(Par
) = N_Parameter_Association
then
7975 Par
:= Parent
(Par
);
7978 if Comes_From_Source
(N
) then
7980 -- The following checks are only relevant when SPARK_Mode is On as
7981 -- they are not standard Ada legality rules.
7983 if SPARK_Mode
= On
then
7985 -- Check for possible elaboration issues with respect to reads of
7986 -- variables. The act of renaming the variable is not considered a
7987 -- read as it simply establishes an alias.
7989 if Legacy_Elaboration_Checks
7990 and then Ekind
(E
) = E_Variable
7991 and then Dynamic_Elaboration_Checks
7992 and then Nkind
(Par
) /= N_Object_Renaming_Declaration
7994 Check_Elab_Call
(N
);
7998 -- The variable may eventually become a constituent of a single
7999 -- protected/task type. Record the reference now and verify its
8000 -- legality when analyzing the contract of the variable
8003 if Ekind
(E
) = E_Variable
then
8004 Record_Possible_Part_Of_Reference
(E
, N
);
8007 -- A Ghost entity must appear in a specific context
8009 if Is_Ghost_Entity
(E
) then
8010 Check_Ghost_Context
(E
, N
);
8013 -- We may be resolving an entity within expanded code, so a reference
8014 -- to an entity should be ignored when calculating effective use
8015 -- clauses to avoid inappropriate marking.
8017 Mark_Use_Clauses
(E
);
8019 end Resolve_Entity_Name
;
8025 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
8026 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
8034 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
8035 -- If the bounds of the entry family being called depend on task
8036 -- discriminants, build a new index subtype where a discriminant is
8037 -- replaced with the value of the discriminant of the target task.
8038 -- The target task is the prefix of the entry name in the call.
8040 -----------------------
8041 -- Actual_Index_Type --
8042 -----------------------
8044 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
8045 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
8046 Tsk
: constant Entity_Id
:= Scope
(E
);
8047 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
8048 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
8051 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
8052 -- If the bound is given by a discriminant, replace with a reference
8053 -- to the discriminant of the same name in the target task. If the
8054 -- entry name is the target of a requeue statement and the entry is
8055 -- in the current protected object, the bound to be used is the
8056 -- discriminal of the object (see Apply_Range_Check for details of
8057 -- the transformation).
8059 -----------------------------
8060 -- Actual_Discriminant_Ref --
8061 -----------------------------
8063 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
8064 Typ
: constant Entity_Id
:= Etype
(Bound
);
8068 Remove_Side_Effects
(Bound
);
8070 if not Is_Entity_Name
(Bound
)
8071 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
8075 elsif Is_Protected_Type
(Tsk
)
8076 and then In_Open_Scopes
(Tsk
)
8077 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
8079 -- Note: here Bound denotes a discriminant of the corresponding
8080 -- record type tskV, whose discriminal is a formal of the
8081 -- init-proc tskVIP. What we want is the body discriminal,
8082 -- which is associated to the discriminant of the original
8083 -- concurrent type tsk.
8085 return New_Occurrence_Of
8086 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
8090 Make_Selected_Component
(Loc
,
8091 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
8092 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
8097 end Actual_Discriminant_Ref
;
8099 -- Start of processing for Actual_Index_Type
8102 if not Has_Discriminants
(Tsk
)
8103 or else (not Is_Entity_Name
(Lo
) and then not Is_Entity_Name
(Hi
))
8105 return Entry_Index_Type
(E
);
8108 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
8109 Set_Etype
(New_T
, Base_Type
(Typ
));
8110 Set_Size_Info
(New_T
, Typ
);
8111 Set_RM_Size
(New_T
, RM_Size
(Typ
));
8112 Set_Scalar_Range
(New_T
,
8113 Make_Range
(Sloc
(Entry_Name
),
8114 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
8115 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
8119 end Actual_Index_Type
;
8121 -- Start of processing for Resolve_Entry
8124 -- Find name of entry being called, and resolve prefix of name with its
8125 -- own type. The prefix can be overloaded, and the name and signature of
8126 -- the entry must be taken into account.
8128 if Nkind
(Entry_Name
) = N_Indexed_Component
then
8130 -- Case of dealing with entry family within the current tasks
8132 E_Name
:= Prefix
(Entry_Name
);
8135 E_Name
:= Entry_Name
;
8138 if Is_Entity_Name
(E_Name
) then
8140 -- Entry call to an entry (or entry family) in the current task. This
8141 -- is legal even though the task will deadlock. Rewrite as call to
8144 -- This can also be a call to an entry in an enclosing task. If this
8145 -- is a single task, we have to retrieve its name, because the scope
8146 -- of the entry is the task type, not the object. If the enclosing
8147 -- task is a task type, the identity of the task is given by its own
8150 -- Finally this can be a requeue on an entry of the same task or
8151 -- protected object.
8153 S
:= Scope
(Entity
(E_Name
));
8155 for J
in reverse 0 .. Scope_Stack
.Last
loop
8156 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
8157 and then not Comes_From_Source
(S
)
8159 -- S is an enclosing task or protected object. The concurrent
8160 -- declaration has been converted into a type declaration, and
8161 -- the object itself has an object declaration that follows
8162 -- the type in the same declarative part.
8164 Tsk
:= Next_Entity
(S
);
8165 while Etype
(Tsk
) /= S
loop
8172 elsif S
= Scope_Stack
.Table
(J
).Entity
then
8174 -- Call to current task. Will be transformed into call to Self
8182 Make_Selected_Component
(Loc
,
8183 Prefix
=> New_Occurrence_Of
(S
, Loc
),
8185 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
8186 Rewrite
(E_Name
, New_N
);
8189 elsif Nkind
(Entry_Name
) = N_Selected_Component
8190 and then Is_Overloaded
(Prefix
(Entry_Name
))
8192 -- Use the entry name (which must be unique at this point) to find
8193 -- the prefix that returns the corresponding task/protected type.
8196 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
8197 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
8202 Get_First_Interp
(Pref
, I
, It
);
8203 while Present
(It
.Typ
) loop
8204 if Scope
(Ent
) = It
.Typ
then
8205 Set_Etype
(Pref
, It
.Typ
);
8209 Get_Next_Interp
(I
, It
);
8214 if Nkind
(Entry_Name
) = N_Selected_Component
then
8215 Resolve
(Prefix
(Entry_Name
));
8216 Resolve_Implicit_Dereference
(Prefix
(Entry_Name
));
8218 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8219 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
8220 Resolve
(Prefix
(Prefix
(Entry_Name
)));
8221 Resolve_Implicit_Dereference
(Prefix
(Prefix
(Entry_Name
)));
8223 -- We do not resolve the prefix because an Entry_Family has no type,
8224 -- although it has the semantics of an array since it can be indexed.
8225 -- In order to perform the associated range check, we would need to
8226 -- build an array type on the fly and set it on the prefix, but this
8227 -- would be wasteful since only the index type matters. Therefore we
8228 -- attach this index type directly, so that Actual_Index_Expression
8229 -- can pick it up later in order to generate the range check.
8231 Set_Etype
(Prefix
(Entry_Name
), Actual_Index_Type
(Nam
));
8233 Index
:= First
(Expressions
(Entry_Name
));
8234 Resolve
(Index
, Entry_Index_Type
(Nam
));
8236 -- Generate a reference for the index when it denotes an entity
8238 if Is_Entity_Name
(Index
) then
8239 Generate_Reference
(Entity
(Index
), Nam
);
8242 -- Up to this point the expression could have been the actual in a
8243 -- simple entry call, and be given by a named association.
8245 if Nkind
(Index
) = N_Parameter_Association
then
8246 Error_Msg_N
("expect expression for entry index", Index
);
8248 Apply_Scalar_Range_Check
(Index
, Etype
(Prefix
(Entry_Name
)));
8253 ------------------------
8254 -- Resolve_Entry_Call --
8255 ------------------------
8257 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
8258 Entry_Name
: constant Node_Id
:= Name
(N
);
8259 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
8267 -- We kill all checks here, because it does not seem worth the effort to
8268 -- do anything better, an entry call is a big operation.
8272 -- Processing of the name is similar for entry calls and protected
8273 -- operation calls. Once the entity is determined, we can complete
8274 -- the resolution of the actuals.
8276 -- The selector may be overloaded, in the case of a protected object
8277 -- with overloaded functions. The type of the context is used for
8280 if Nkind
(Entry_Name
) = N_Selected_Component
8281 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
8282 and then Typ
/= Standard_Void_Type
8289 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
8290 while Present
(It
.Typ
) loop
8291 if Covers
(Typ
, It
.Typ
) then
8292 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
8293 Set_Etype
(Entry_Name
, It
.Typ
);
8295 Generate_Reference
(It
.Typ
, N
, ' ');
8298 Get_Next_Interp
(I
, It
);
8303 Resolve_Entry
(Entry_Name
);
8305 if Nkind
(Entry_Name
) = N_Selected_Component
then
8307 -- Simple entry or protected operation call
8309 Nam
:= Entity
(Selector_Name
(Entry_Name
));
8310 Obj
:= Prefix
(Entry_Name
);
8312 if Is_Subprogram
(Nam
) then
8313 Check_For_Eliminated_Subprogram
(Entry_Name
, Nam
);
8316 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
8318 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8320 -- Call to member of entry family
8322 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
8323 Obj
:= Prefix
(Prefix
(Entry_Name
));
8324 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
8327 -- We cannot in general check the maximum depth of protected entry calls
8328 -- at compile time. But we can tell that any protected entry call at all
8329 -- violates a specified nesting depth of zero.
8331 if Is_Protected_Type
(Scope
(Nam
)) then
8332 Check_Restriction
(Max_Entry_Queue_Length
, N
);
8335 -- Use context type to disambiguate a protected function that can be
8336 -- called without actuals and that returns an array type, and where the
8337 -- argument list may be an indexing of the returned value.
8339 if Ekind
(Nam
) = E_Function
8340 and then Needs_No_Actuals
(Nam
)
8341 and then Present
(Parameter_Associations
(N
))
8343 ((Is_Array_Type
(Etype
(Nam
))
8344 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
8346 or else (Is_Access_Type
(Etype
(Nam
))
8347 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
8351 Component_Type
(Designated_Type
(Etype
(Nam
))))))
8354 Index_Node
: Node_Id
;
8358 Make_Indexed_Component
(Loc
,
8360 Make_Function_Call
(Loc
, Name
=> Relocate_Node
(Entry_Name
)),
8361 Expressions
=> Parameter_Associations
(N
));
8363 -- Since we are correcting a node classification error made by the
8364 -- parser, we call Replace rather than Rewrite.
8366 Replace
(N
, Index_Node
);
8367 Set_Etype
(Prefix
(N
), Etype
(Nam
));
8369 Resolve_Indexed_Component
(N
, Typ
);
8375 and then Present
(Contract_Wrapper
(Nam
))
8376 and then Current_Scope
/= Contract_Wrapper
(Nam
)
8377 and then Current_Scope
/= Wrapped_Statements
(Contract_Wrapper
(Nam
))
8379 -- Note the entity being called before rewriting the call, so that
8380 -- it appears used at this point.
8382 Generate_Reference
(Nam
, Entry_Name
, 'r');
8384 -- Rewrite as call to the precondition wrapper, adding the task
8385 -- object to the list of actuals. If the call is to a member of an
8386 -- entry family, include the index as well.
8390 New_Actuals
: List_Id
;
8393 New_Actuals
:= New_List
(Obj
);
8395 if Nkind
(Entry_Name
) = N_Indexed_Component
then
8396 Append_To
(New_Actuals
,
8397 New_Copy_Tree
(First
(Expressions
(Entry_Name
))));
8400 Append_List
(Parameter_Associations
(N
), New_Actuals
);
8402 Make_Procedure_Call_Statement
(Loc
,
8404 New_Occurrence_Of
(Contract_Wrapper
(Nam
), Loc
),
8405 Parameter_Associations
=> New_Actuals
);
8406 Rewrite
(N
, New_Call
);
8408 -- Preanalyze and resolve new call. Current procedure is called
8409 -- from Resolve_Call, after which expansion will take place.
8411 Preanalyze_And_Resolve
(N
);
8416 -- The operation name may have been overloaded. Order the actuals
8417 -- according to the formals of the resolved entity, and set the return
8418 -- type to that of the operation.
8421 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
8422 pragma Assert
(Norm_OK
);
8423 Set_Etype
(N
, Etype
(Nam
));
8425 -- Reset the Is_Overloaded flag, since resolution is now completed
8427 -- Simple entry call
8429 if Nkind
(Entry_Name
) = N_Selected_Component
then
8430 Set_Is_Overloaded
(Selector_Name
(Entry_Name
), False);
8432 -- Call to a member of an entry family
8434 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8435 Set_Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)), False);
8439 Resolve_Actuals
(N
, Nam
);
8440 Check_Internal_Protected_Use
(N
, Nam
);
8442 -- Create a call reference to the entry
8444 Generate_Reference
(Nam
, Entry_Name
, 's');
8446 if Is_Entry
(Nam
) then
8447 Check_Potentially_Blocking_Operation
(N
);
8450 -- Verify that a procedure call cannot masquerade as an entry
8451 -- call where an entry call is expected.
8453 if Ekind
(Nam
) = E_Procedure
then
8454 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
8455 and then N
= Entry_Call_Statement
(Parent
(N
))
8457 Error_Msg_N
("entry call required in select statement", N
);
8459 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
8460 and then N
= Triggering_Statement
(Parent
(N
))
8462 Error_Msg_N
("triggering statement cannot be procedure call", N
);
8464 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
8465 and then not In_Open_Scopes
(Scope
(Nam
))
8467 Error_Msg_N
("task has no entry with this name", Entry_Name
);
8471 -- After resolution, entry calls and protected procedure calls are
8472 -- changed into entry calls, for expansion. The structure of the node
8473 -- does not change, so it can safely be done in place. Protected
8474 -- function calls must keep their structure because they are
8477 if Ekind
(Nam
) /= E_Function
then
8479 -- A protected operation that is not a function may modify the
8480 -- corresponding object, and cannot apply to a constant. If this
8481 -- is an internal call, the prefix is the type itself.
8483 if Is_Protected_Type
(Scope
(Nam
))
8484 and then not Is_Variable
(Obj
)
8485 and then (not Is_Entity_Name
(Obj
)
8486 or else not Is_Type
(Entity
(Obj
)))
8489 ("prefix of protected procedure or entry call must be variable",
8494 Entry_Call
: Node_Id
;
8498 Make_Entry_Call_Statement
(Loc
,
8500 Parameter_Associations
=> Parameter_Associations
(N
));
8502 -- Inherit relevant attributes from the original call
8504 Set_First_Named_Actual
8505 (Entry_Call
, First_Named_Actual
(N
));
8507 Set_Is_Elaboration_Checks_OK_Node
8508 (Entry_Call
, Is_Elaboration_Checks_OK_Node
(N
));
8510 Set_Is_Elaboration_Warnings_OK_Node
8511 (Entry_Call
, Is_Elaboration_Warnings_OK_Node
(N
));
8513 Set_Is_SPARK_Mode_On_Node
8514 (Entry_Call
, Is_SPARK_Mode_On_Node
(N
));
8516 Rewrite
(N
, Entry_Call
);
8517 Set_Analyzed
(N
, True);
8520 -- Protected functions can return on the secondary stack, in which case
8521 -- we must trigger the transient scope mechanism.
8523 elsif Expander_Active
8524 and then Requires_Transient_Scope
(Etype
(Nam
))
8526 Establish_Transient_Scope
(N
, Needs_Secondary_Stack
(Etype
(Nam
)));
8529 -- Now we know that this is not a call to a function that returns an
8530 -- array type; moreover, we know the name of the called entry. Detect
8531 -- overlapping actuals, just like for a subprogram call.
8533 Warn_On_Overlapping_Actuals
(Nam
, N
);
8534 end Resolve_Entry_Call
;
8536 -------------------------
8537 -- Resolve_Equality_Op --
8538 -------------------------
8540 -- The operands must have compatible types and the boolean context does not
8541 -- participate in the resolution. The first pass verifies that the operands
8542 -- are not ambiguous and sets their type correctly, or to Any_Type in case
8543 -- of ambiguity. If both operands are strings, aggregates, allocators, or
8544 -- null, they are ambiguous even if they carry a single (universal) type.
8546 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8547 L
: constant Node_Id
:= Left_Opnd
(N
);
8548 R
: constant Node_Id
:= Right_Opnd
(N
);
8550 Implicit_NE_For_User_Defined_Operator
: constant Boolean :=
8552 and then Ekind
(Entity
(N
)) = E_Function
8553 and then not Comes_From_Source
(Entity
(N
))
8555 Is_Intrinsic_Subprogram
(Corresponding_Equality
(Entity
(N
)));
8556 -- Whether this is a call to the implicit inequality operator created
8557 -- for a user-defined operator that is not an intrinsic subprogram, in
8558 -- which case we need to skip some processing.
8560 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
8562 procedure Check_Access_Attribute
(N
: Node_Id
);
8563 -- For any object, '[Unchecked_]Access of such object can never be
8564 -- passed as an operand to the Universal_Access equality operators.
8565 -- This is so because the expected type for Obj'Access in a call to
8566 -- these operators, whose formals are of type Universal_Access, is
8567 -- Universal_Access, and Universal_Access does not have a designated
8568 -- type. For more details, see RM 3.10.2(2/2) and 6.4.1(3).
8570 procedure Check_Designated_Object_Types
(T1
, T2
: Entity_Id
);
8571 -- Check RM 4.5.2(9.6/2) on the given designated object types
8573 procedure Check_Designated_Subprogram_Types
(T1
, T2
: Entity_Id
);
8574 -- Check RM 4.5.2(9.7/2) on the given designated subprogram types
8576 procedure Check_If_Expression
(Cond
: Node_Id
);
8577 -- The resolution rule for if expressions requires that each such must
8578 -- have a unique type. This means that if several dependent expressions
8579 -- are of a non-null anonymous access type, and the context does not
8580 -- impose an expected type (as can be the case in an equality operation)
8581 -- the expression must be rejected.
8583 procedure Explain_Redundancy
(N
: Node_Id
);
8584 -- Attempt to explain the nature of a redundant comparison with True. If
8585 -- the expression N is too complex, this routine issues a general error
8588 function Find_Unique_Access_Type
return Entity_Id
;
8589 -- In the case of allocators and access attributes, the context must
8590 -- provide an indication of the specific access type to be used. If
8591 -- one operand is of such a "generic" access type, check whether there
8592 -- is a specific visible access type that has the same designated type.
8593 -- This is semantically dubious, and of no interest to any real code,
8594 -- but c48008a makes it all worthwhile.
8596 function Suspicious_Prio_For_Equality
return Boolean;
8597 -- Returns True iff the parent node is a and/or/xor operation that
8598 -- could be the cause of confused priorities. Note that if the not is
8599 -- in parens, then False is returned.
8601 ----------------------------
8602 -- Check_Access_Attribute --
8603 ----------------------------
8605 procedure Check_Access_Attribute
(N
: Node_Id
) is
8607 if Nkind
(N
) = N_Attribute_Reference
8608 and then Attribute_Name
(N
) in Name_Access | Name_Unchecked_Access
8611 ("access attribute cannot be used as actual for "
8612 & "universal_access equality", N
);
8614 end Check_Access_Attribute
;
8616 -----------------------------------
8617 -- Check_Designated_Object_Types --
8618 -----------------------------------
8620 procedure Check_Designated_Object_Types
(T1
, T2
: Entity_Id
) is
8622 if (Is_Elementary_Type
(T1
) or else Is_Array_Type
(T1
))
8623 and then (Base_Type
(T1
) /= Base_Type
(T2
)
8624 or else not Subtypes_Statically_Match
(T1
, T2
))
8627 ("designated subtypes for universal_access equality "
8628 & "do not statically match (RM 4.5.2(9.6/2)", N
);
8629 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
8630 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
8632 end Check_Designated_Object_Types
;
8634 ---------------------------------------
8635 -- Check_Designated_Subprogram_Types --
8636 ---------------------------------------
8638 procedure Check_Designated_Subprogram_Types
(T1
, T2
: Entity_Id
) is
8640 if not Subtype_Conformant
(T1
, T2
) then
8642 ("designated subtypes for universal_access equality "
8643 & "not subtype conformant (RM 4.5.2(9.7/2)", N
);
8644 Error_Msg_NE
("\left operand has}!", N
, Etype
(L
));
8645 Error_Msg_NE
("\right operand has}!", N
, Etype
(R
));
8647 end Check_Designated_Subprogram_Types
;
8649 -------------------------
8650 -- Check_If_Expression --
8651 -------------------------
8653 procedure Check_If_Expression
(Cond
: Node_Id
) is
8654 Then_Expr
: Node_Id
;
8655 Else_Expr
: Node_Id
;
8658 if Nkind
(Cond
) = N_If_Expression
then
8659 Then_Expr
:= Next
(First
(Expressions
(Cond
)));
8660 Else_Expr
:= Next
(Then_Expr
);
8662 if Nkind
(Then_Expr
) /= N_Null
8663 and then Nkind
(Else_Expr
) /= N_Null
8665 Error_Msg_N
("cannot determine type of if expression", Cond
);
8668 end Check_If_Expression
;
8670 ------------------------
8671 -- Explain_Redundancy --
8672 ------------------------
8674 procedure Explain_Redundancy
(N
: Node_Id
) is
8682 -- Strip the operand down to an entity
8685 if Nkind
(Val
) = N_Selected_Component
then
8686 Val
:= Selector_Name
(Val
);
8692 -- The construct denotes an entity
8694 if Is_Entity_Name
(Val
) and then Present
(Entity
(Val
)) then
8695 Val_Id
:= Entity
(Val
);
8697 -- Do not generate an error message when the comparison is done
8698 -- against the enumeration literal Standard.True.
8700 if Ekind
(Val_Id
) /= E_Enumeration_Literal
then
8702 -- Build a customized error message
8705 Add_Str_To_Name_Buffer
("?r?");
8707 if Ekind
(Val_Id
) = E_Component
then
8708 Add_Str_To_Name_Buffer
("component ");
8710 elsif Ekind
(Val_Id
) = E_Constant
then
8711 Add_Str_To_Name_Buffer
("constant ");
8713 elsif Ekind
(Val_Id
) = E_Discriminant
then
8714 Add_Str_To_Name_Buffer
("discriminant ");
8716 elsif Is_Formal
(Val_Id
) then
8717 Add_Str_To_Name_Buffer
("parameter ");
8719 elsif Ekind
(Val_Id
) = E_Variable
then
8720 Add_Str_To_Name_Buffer
("variable ");
8723 Add_Str_To_Name_Buffer
("& is always True!");
8726 Error_Msg_NE
(Get_Name_String
(Error
), Val
, Val_Id
);
8729 -- The construct is too complex to disect, issue a general message
8732 Error_Msg_N
("?r?expression is always True!", Val
);
8734 end Explain_Redundancy
;
8736 -----------------------------
8737 -- Find_Unique_Access_Type --
8738 -----------------------------
8740 function Find_Unique_Access_Type
return Entity_Id
is
8746 if Ekind
(Etype
(R
)) in E_Allocator_Type | E_Access_Attribute_Type
8748 Acc
:= Designated_Type
(Etype
(R
));
8750 elsif Ekind
(Etype
(L
)) in E_Allocator_Type | E_Access_Attribute_Type
8752 Acc
:= Designated_Type
(Etype
(L
));
8758 while S
/= Standard_Standard
loop
8759 E
:= First_Entity
(S
);
8760 while Present
(E
) loop
8762 and then Is_Access_Type
(E
)
8763 and then Ekind
(E
) /= E_Allocator_Type
8764 and then Designated_Type
(E
) = Base_Type
(Acc
)
8776 end Find_Unique_Access_Type
;
8778 ----------------------------------
8779 -- Suspicious_Prio_For_Equality --
8780 ----------------------------------
8782 function Suspicious_Prio_For_Equality
return Boolean is
8783 Par
: constant Node_Id
:= Parent
(N
);
8786 -- Check if parent node is one of and/or/xor, not parenthesized
8787 -- explicitly, and its own parent is not of this kind. Otherwise,
8788 -- it's a case of chained Boolean conditions which is likely well
8791 if Nkind
(Par
) in N_Op_And | N_Op_Or | N_Op_Xor
8792 and then Paren_Count
(N
) = 0
8793 and then Nkind
(Parent
(Par
)) not in N_Op_And | N_Op_Or | N_Op_Xor
8797 (if Left_Opnd
(Par
) = N
then
8802 -- Compar may have been rewritten, for example from (a /= b)
8803 -- into not (a = b). Use the Original_Node instead.
8805 Compar
:= Original_Node
(Compar
);
8807 -- If the other argument of the and/or/xor is also a
8808 -- comparison, or another and/or/xor then most likely
8809 -- the priorities are correctly set.
8811 return Nkind
(Compar
) not in N_Op_Boolean
;
8817 end Suspicious_Prio_For_Equality
;
8819 -- Start of processing for Resolve_Equality_Op
8822 if T
= Any_Fixed
then
8823 T
:= Unique_Fixed_Point_Type
(L
);
8826 Set_Etype
(N
, Base_Type
(Typ
));
8827 Generate_Reference
(T
, N
, ' ');
8829 if T
= Any_Type
then
8830 -- Deal with explicit ambiguity of operands, unless this is a call
8831 -- to the implicit inequality operator created for a user-defined
8832 -- operator that is not an intrinsic subprogram, since the common
8833 -- resolution of operands done here does not apply to it.
8835 if not Implicit_NE_For_User_Defined_Operator
8836 and then (Is_Overloaded
(L
) or else Is_Overloaded
(R
))
8838 Ambiguous_Operands
(N
);
8843 -- For Ada 2022, check for user-defined literals when the type has
8844 -- the appropriate aspect.
8846 if Has_Applicable_User_Defined_Literal
(L
, Etype
(R
)) then
8847 Resolve
(L
, Etype
(R
));
8848 Set_Etype
(N
, Standard_Boolean
);
8851 if Has_Applicable_User_Defined_Literal
(R
, Etype
(L
)) then
8852 Resolve
(R
, Etype
(L
));
8853 Set_Etype
(N
, Standard_Boolean
);
8856 -- Deal with other error cases
8858 if T
= Any_String
or else
8859 T
= Any_Composite
or else
8862 if T
= Any_Character
then
8863 Ambiguous_Character
(L
);
8865 Error_Msg_N
("ambiguous operands for equality", N
);
8868 Set_Etype
(N
, Any_Type
);
8871 elsif T
= Universal_Access
8872 or else Ekind
(T
) in E_Allocator_Type | E_Access_Attribute_Type
8874 T
:= Find_Unique_Access_Type
;
8877 Error_Msg_N
("ambiguous operands for equality", N
);
8878 Set_Etype
(N
, Any_Type
);
8882 -- If expressions must have a single type, and if the context does
8883 -- not impose one the dependent expressions cannot be anonymous
8886 -- Why no similar processing for case expressions???
8888 elsif Ada_Version
>= Ada_2012
8889 and then Is_Anonymous_Access_Type
(Etype
(L
))
8890 and then Is_Anonymous_Access_Type
(Etype
(R
))
8892 Check_If_Expression
(L
);
8893 Check_If_Expression
(R
);
8896 -- RM 4.5.2(9.5/2): At least one of the operands of the equality
8897 -- operators for universal_access shall be of type universal_access,
8898 -- or both shall be of access-to-object types, or both shall be of
8899 -- access-to-subprogram types (RM 4.5.2(9.5/2)).
8901 if Is_Anonymous_Access_Type
(T
)
8902 and then Etype
(L
) /= Universal_Access
8903 and then Etype
(R
) /= Universal_Access
8905 -- RM 4.5.2(9.6/2): When both are of access-to-object types, the
8906 -- designated types shall be the same or one shall cover the other
8907 -- and if the designated types are elementary or array types, then
8908 -- the designated subtypes shall statically match.
8910 if Is_Access_Object_Type
(Etype
(L
))
8911 and then Is_Access_Object_Type
(Etype
(R
))
8913 Check_Designated_Object_Types
8914 (Designated_Type
(Etype
(L
)), Designated_Type
(Etype
(R
)));
8916 -- RM 4.5.2(9.7/2): When both are of access-to-subprogram types,
8917 -- the designated profiles shall be subtype conformant.
8919 elsif Is_Access_Subprogram_Type
(Etype
(L
))
8920 and then Is_Access_Subprogram_Type
(Etype
(R
))
8922 Check_Designated_Subprogram_Types
8923 (Designated_Type
(Etype
(L
)), Designated_Type
(Etype
(R
)));
8927 -- Check another case of equality operators for universal_access
8929 if Is_Anonymous_Access_Type
(T
) and then Comes_From_Source
(N
) then
8930 Check_Access_Attribute
(L
);
8931 Check_Access_Attribute
(R
);
8936 Set_Compare_Type
(N
, T
);
8938 -- AI12-0413: user-defined primitive equality of an untagged record
8939 -- type hides the predefined equality operator, including within a
8940 -- generic, and if it is declared abstract, results in an illegal
8941 -- instance if the operator is used in the spec, or in the raising
8942 -- of Program_Error if used in the body of an instance.
8944 if Nkind
(N
) = N_Op_Eq
8945 and then In_Instance
8946 and then Ada_Version
>= Ada_2012
8949 U
: constant Entity_Id
:= Underlying_Type
(T
);
8955 and then Is_Record_Type
(U
)
8956 and then not Is_Tagged_Type
(U
)
8958 Eq
:= Get_User_Defined_Equality
(T
);
8960 if Present
(Eq
) then
8961 if Is_Abstract_Subprogram
(Eq
) then
8962 Nondispatching_Call_To_Abstract_Operation
(N
, Eq
);
8964 Rewrite_Operator_As_Call
(N
, Eq
);
8973 -- If the unique type is a class-wide type then it will be expanded
8974 -- into a dispatching call to the predefined primitive. Therefore we
8975 -- check here for potential violation of such restriction.
8977 if Is_Class_Wide_Type
(T
) then
8978 Check_Restriction
(No_Dispatching_Calls
, N
);
8981 -- Only warn for redundant equality comparison to True for objects
8982 -- (e.g. "X = True") and operations (e.g. "(X < Y) = True"). For
8983 -- other expressions, it may be a matter of preference to write
8984 -- "Expr = True" or "Expr".
8986 if Warn_On_Redundant_Constructs
8987 and then Comes_From_Source
(N
)
8988 and then Comes_From_Source
(R
)
8989 and then Is_Entity_Name
(R
)
8990 and then Entity
(R
) = Standard_True
8992 ((Is_Entity_Name
(L
) and then Is_Object
(Entity
(L
)))
8996 Error_Msg_N
-- CODEFIX
8997 ("?r?comparison with True is redundant!", N
);
8998 Explain_Redundancy
(Original_Node
(R
));
9001 -- Warn on a (in)equality between boolean values which is not
9002 -- parenthesized when the parent expression is one of and/or/xor, as
9003 -- this is interpreted as (a = b) op c where most likely a = (b op c)
9004 -- was intended. Do not generate a warning in generic instances, as
9005 -- the problematic expression may be implicitly parenthesized in
9006 -- the generic itself if one of the operators is a generic formal.
9007 -- Also do not generate a warning for generated equality, for
9008 -- example from rewritting a membership test.
9010 if Warn_On_Questionable_Missing_Parens
9011 and then not In_Instance
9012 and then Comes_From_Source
(N
)
9013 and then Is_Boolean_Type
(T
)
9014 and then Suspicious_Prio_For_Equality
9016 Error_Msg_N
("?q?equality should be parenthesized here!", N
);
9019 Check_Unset_Reference
(L
);
9020 Check_Unset_Reference
(R
);
9021 Generate_Operator_Reference
(N
, T
);
9022 Check_Low_Bound_Tested
(N
);
9024 -- Unless this is a call to the implicit inequality operator created
9025 -- for a user-defined operator that is not an intrinsic subprogram,
9026 -- try to fold the operation.
9028 if not Implicit_NE_For_User_Defined_Operator
then
9029 Analyze_Dimension
(N
);
9030 Eval_Relational_Op
(N
);
9032 elsif Nkind
(N
) = N_Op_Ne
9033 and then Is_Abstract_Subprogram
(Entity
(N
))
9035 Nondispatching_Call_To_Abstract_Operation
(N
, Entity
(N
));
9038 end Resolve_Equality_Op
;
9040 ----------------------------------
9041 -- Resolve_Explicit_Dereference --
9042 ----------------------------------
9044 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
9045 Loc
: constant Source_Ptr
:= Sloc
(N
);
9047 P
: constant Node_Id
:= Prefix
(N
);
9050 -- The candidate prefix type, if overloaded
9056 Check_Fully_Declared_Prefix
(Typ
, P
);
9059 -- A useful optimization: check whether the dereference denotes an
9060 -- element of a container, and if so rewrite it as a call to the
9061 -- corresponding Element function.
9063 -- Disabled for now, on advice of ARG. A more restricted form of the
9064 -- predicate might be acceptable ???
9066 -- if Is_Container_Element (N) then
9070 if Is_Overloaded
(P
) then
9072 -- Use the context type to select the prefix that has the correct
9073 -- designated type. Keep the first match, which will be the inner-
9076 Get_First_Interp
(P
, I
, It
);
9078 while Present
(It
.Typ
) loop
9079 if Is_Access_Type
(It
.Typ
)
9080 and then Covers
(Typ
, Designated_Type
(It
.Typ
))
9086 -- Remove access types that do not match, but preserve access
9087 -- to subprogram interpretations, in case a further dereference
9088 -- is needed (see below).
9090 elsif Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
9094 Get_Next_Interp
(I
, It
);
9097 if Present
(P_Typ
) then
9099 Set_Etype
(N
, Designated_Type
(P_Typ
));
9102 -- If no interpretation covers the designated type of the prefix,
9103 -- this is the pathological case where not all implementations of
9104 -- the prefix allow the interpretation of the node as a call. Now
9105 -- that the expected type is known, Remove other interpretations
9106 -- from prefix, rewrite it as a call, and resolve again, so that
9107 -- the proper call node is generated.
9109 Get_First_Interp
(P
, I
, It
);
9110 while Present
(It
.Typ
) loop
9111 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
9115 Get_Next_Interp
(I
, It
);
9119 Make_Function_Call
(Loc
,
9121 Make_Explicit_Dereference
(Loc
,
9123 Parameter_Associations
=> New_List
);
9125 Save_Interps
(N
, New_N
);
9127 Analyze_And_Resolve
(N
, Typ
);
9131 -- If not overloaded, resolve P with its own type
9137 -- If the prefix might be null, add an access check
9139 if Is_Access_Type
(Etype
(P
))
9140 and then not Can_Never_Be_Null
(Etype
(P
))
9142 Apply_Access_Check
(N
);
9145 -- If the designated type is a packed unconstrained array type, and the
9146 -- explicit dereference is not in the context of an attribute reference,
9147 -- then we must compute and set the actual subtype, since it is needed
9148 -- by Gigi. The reason we exclude the attribute case is that this is
9149 -- handled fine by Gigi, and in fact we use such attributes to build the
9150 -- actual subtype. We also exclude generated code (which builds actual
9151 -- subtypes directly if they are needed).
9153 if Is_Packed_Array
(Etype
(N
))
9154 and then not Is_Constrained
(Etype
(N
))
9155 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
9156 and then Comes_From_Source
(N
)
9158 Set_Etype
(N
, Get_Actual_Subtype
(N
));
9161 Analyze_Dimension
(N
);
9163 -- Note: No Eval processing is required for an explicit dereference,
9164 -- because such a name can never be static.
9166 end Resolve_Explicit_Dereference
;
9168 -------------------------------------
9169 -- Resolve_Expression_With_Actions --
9170 -------------------------------------
9172 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
9174 function OK_For_Static
(Act
: Node_Id
) return Boolean;
9175 -- True if Act is an action of a declare_expression that is allowed in a
9176 -- static declare_expression.
9178 function All_OK_For_Static
return Boolean;
9179 -- True if all actions of N are allowed in a static declare_expression.
9181 function Get_Literal
(Expr
: Node_Id
) return Node_Id
;
9182 -- Expr is an expression with compile-time-known value. This returns the
9183 -- literal node that reprsents that value.
9189 function OK_For_Static
(Act
: Node_Id
) return Boolean is
9192 when N_Object_Declaration
=>
9193 if Constant_Present
(Act
)
9194 and then Is_Static_Expression
(Expression
(Act
))
9199 when N_Object_Renaming_Declaration
=>
9200 if Statically_Names_Object
(Name
(Act
)) then
9205 -- No other declarations, nor even pragmas, are allowed in a
9206 -- declare expression, so if we see something else, it must be
9207 -- an internally generated expression_with_actions.
9214 -----------------------
9215 -- All_OK_For_Static --
9216 -----------------------
9218 function All_OK_For_Static
return Boolean is
9219 Act
: Node_Id
:= First
(Actions
(N
));
9221 while Present
(Act
) loop
9222 if not OK_For_Static
(Act
) then
9230 end All_OK_For_Static
;
9236 function Get_Literal
(Expr
: Node_Id
) return Node_Id
is
9237 pragma Assert
(Compile_Time_Known_Value
(Expr
));
9240 case Nkind
(Expr
) is
9241 when N_Has_Entity
=>
9242 if Ekind
(Entity
(Expr
)) = E_Enumeration_Literal
then
9245 Result
:= Constant_Value
(Entity
(Expr
));
9247 when N_Numeric_Or_String_Literal
=>
9250 raise Program_Error
;
9254 (Nkind
(Result
) in N_Numeric_Or_String_Literal
9255 or else Ekind
(Entity
(Result
)) = E_Enumeration_Literal
);
9261 Loc
: constant Source_Ptr
:= Sloc
(N
);
9263 -- Start of processing for Resolve_Expression_With_Actions
9268 if Is_Empty_List
(Actions
(N
)) then
9269 pragma Assert
(All_OK_For_Static
); null;
9272 -- If the value of the expression is known at compile time, and all
9273 -- of the actions (if any) are suitable, then replace the declare
9274 -- expression with its expression. This allows the declare expression
9275 -- as a whole to be static if appropriate. See AI12-0368.
9277 if Compile_Time_Known_Value
(Expression
(N
)) then
9278 if Is_Empty_List
(Actions
(N
)) then
9279 Rewrite
(N
, Expression
(N
));
9280 elsif All_OK_For_Static
then
9283 (Get_Literal
(Expression
(N
)), New_Sloc
=> Loc
));
9286 end Resolve_Expression_With_Actions
;
9288 ----------------------------------
9289 -- Resolve_Generalized_Indexing --
9290 ----------------------------------
9292 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
) is
9293 Indexing
: constant Node_Id
:= Generalized_Indexing
(N
);
9295 Rewrite
(N
, Indexing
);
9297 end Resolve_Generalized_Indexing
;
9299 ---------------------------
9300 -- Resolve_If_Expression --
9301 ---------------------------
9303 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9304 Condition
: constant Node_Id
:= First
(Expressions
(N
));
9306 procedure Apply_Check
(Expr
: Node_Id
; Result_Type
: Entity_Id
);
9307 -- When a dependent expression is of a subtype different from
9308 -- the context subtype, then insert a qualification to ensure
9309 -- the generation of a constraint check. This was previously
9310 -- for scalar types. For array types apply a length check, given
9311 -- that the context in general allows sliding, while a qualified
9312 -- expression forces equality of bounds.
9318 procedure Apply_Check
(Expr
: Node_Id
; Result_Type
: Entity_Id
) is
9319 Expr_Typ
: constant Entity_Id
:= Etype
(Expr
);
9320 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
9324 or else Is_Tagged_Type
(Typ
)
9325 or else Is_Access_Type
(Typ
)
9326 or else not Is_Constrained
(Typ
)
9327 or else Inside_A_Generic
9331 elsif Is_Array_Type
(Typ
) then
9332 Apply_Length_Check
(Expr
, Typ
);
9336 Make_Qualified_Expression
(Loc
,
9337 Subtype_Mark
=> New_Occurrence_Of
(Result_Type
, Loc
),
9338 Expression
=> Relocate_Node
(Expr
)));
9340 Analyze_And_Resolve
(Expr
, Result_Type
);
9346 Else_Expr
: Node_Id
;
9347 Then_Expr
: Node_Id
;
9349 Result_Type
: Entity_Id
;
9350 -- So in most cases the type of the if_expression and of its
9351 -- dependent expressions is that of the context. However, if
9352 -- the expression is the index of an Indexed_Component, we must
9353 -- ensure that a proper index check is applied, rather than a
9354 -- range check on the index type (which might be discriminant
9355 -- dependent). In this case we resolve with the base type of the
9356 -- index type, and the index check is generated in the resolution
9357 -- of the indexed_component above.
9359 -- Start of processing for Resolve_If_Expression
9362 -- Defend against malformed expressions
9364 if No
(Condition
) then
9368 if Present
(Parent
(N
))
9369 and then (Nkind
(Parent
(N
)) = N_Indexed_Component
9370 or else Nkind
(Parent
(Parent
(N
))) = N_Indexed_Component
)
9372 Result_Type
:= Base_Type
(Typ
);
9378 Then_Expr
:= Next
(Condition
);
9380 if No
(Then_Expr
) then
9384 Resolve
(Condition
, Any_Boolean
);
9385 Check_Unset_Reference
(Condition
);
9387 Resolve_Dependent_Expression
(N
, Then_Expr
, Result_Type
);
9389 Check_Unset_Reference
(Then_Expr
);
9390 Apply_Check
(Then_Expr
, Result_Type
);
9392 Else_Expr
:= Next
(Then_Expr
);
9394 -- If ELSE expression present, just resolve using the determined type
9396 if Present
(Else_Expr
) then
9397 Resolve_Dependent_Expression
(N
, Else_Expr
, Result_Type
);
9399 Check_Unset_Reference
(Else_Expr
);
9400 Apply_Check
(Else_Expr
, Result_Type
);
9402 -- Apply RM 4.5.7 (17/3): whether the expression is statically or
9403 -- dynamically tagged must be known statically.
9405 if Is_Tagged_Type
(Typ
) and then not Is_Class_Wide_Type
(Typ
) then
9406 if Is_Dynamically_Tagged
(Then_Expr
) /=
9407 Is_Dynamically_Tagged
(Else_Expr
)
9409 Error_Msg_N
("all or none of the dependent expressions "
9410 & "can be dynamically tagged", N
);
9414 -- If no ELSE expression is present, root type must be Standard.Boolean
9415 -- and we provide a Standard.True result converted to the appropriate
9416 -- Boolean type (in case it is a derived boolean type).
9418 elsif Root_Type
(Typ
) = Standard_Boolean
then
9420 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
9421 Analyze_And_Resolve
(Else_Expr
, Result_Type
);
9422 Append_To
(Expressions
(N
), Else_Expr
);
9425 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
9426 Append_To
(Expressions
(N
), Error
);
9429 Set_Etype
(N
, Result_Type
);
9431 if not Error_Posted
(N
) then
9432 Eval_If_Expression
(N
);
9435 Analyze_Dimension
(N
);
9436 end Resolve_If_Expression
;
9438 ----------------------------------
9439 -- Resolve_Implicit_Dereference --
9440 ----------------------------------
9442 procedure Resolve_Implicit_Dereference
(P
: Node_Id
) is
9443 Desig_Typ
: Entity_Id
;
9446 if Is_Access_Type
(Etype
(P
)) then
9447 Desig_Typ
:= Implicitly_Designated_Type
(Etype
(P
));
9448 Insert_Explicit_Dereference
(P
);
9449 Analyze_And_Resolve
(P
, Desig_Typ
);
9451 end Resolve_Implicit_Dereference
;
9453 -------------------------------
9454 -- Resolve_Indexed_Component --
9455 -------------------------------
9457 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
9458 Pref
: constant Node_Id
:= Prefix
(N
);
9460 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
9464 if Present
(Generalized_Indexing
(N
)) then
9465 Resolve_Generalized_Indexing
(N
, Typ
);
9469 if Is_Overloaded
(Pref
) then
9471 -- Use the context type to select the prefix that yields the correct
9477 I1
: Interp_Index
:= 0;
9478 Found
: Boolean := False;
9481 Get_First_Interp
(Pref
, I
, It
);
9482 while Present
(It
.Typ
) loop
9483 if (Is_Array_Type
(It
.Typ
)
9484 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
9485 or else (Is_Access_Type
(It
.Typ
)
9486 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
9490 Component_Type
(Designated_Type
(It
.Typ
))))
9493 It
:= Disambiguate
(Pref
, I1
, I
, Any_Type
);
9495 if It
= No_Interp
then
9496 Error_Msg_N
("ambiguous prefix for indexing", N
);
9502 Array_Type
:= It
.Typ
;
9508 Array_Type
:= It
.Typ
;
9513 Get_Next_Interp
(I
, It
);
9518 Array_Type
:= Etype
(Pref
);
9521 Resolve
(Pref
, Array_Type
);
9522 Array_Type
:= Get_Actual_Subtype_If_Available
(Pref
);
9524 -- If the prefix's type is an access type, get to the real array type.
9525 -- Note: we do not apply an access check because an explicit dereference
9526 -- will be introduced later, and the check will happen there.
9528 if Is_Access_Type
(Array_Type
) then
9529 Array_Type
:= Implicitly_Designated_Type
(Array_Type
);
9532 -- If name was overloaded, set component type correctly now.
9533 -- If a misplaced call to an entry family (which has no index types)
9534 -- return. Error will be diagnosed from calling context.
9536 if Is_Array_Type
(Array_Type
) then
9537 Set_Etype
(N
, Component_Type
(Array_Type
));
9542 Index
:= First_Index
(Array_Type
);
9543 Expr
:= First
(Expressions
(N
));
9545 -- The prefix may have resolved to a string literal, in which case its
9546 -- etype has a special representation. This is only possible currently
9547 -- if the prefix is a static concatenation, written in functional
9550 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
9551 Resolve
(Expr
, Standard_Positive
);
9554 while Present
(Index
) and then Present
(Expr
) loop
9555 Resolve
(Expr
, Etype
(Index
));
9556 Check_Unset_Reference
(Expr
);
9558 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
9565 Resolve_Implicit_Dereference
(Pref
);
9566 Analyze_Dimension
(N
);
9568 -- Do not generate the warning on suspicious index if we are analyzing
9569 -- package Ada.Tags; otherwise we will report the warning with the
9570 -- Prims_Ptr field of the dispatch table.
9572 if Scope
(Etype
(Pref
)) = Standard_Standard
9574 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Pref
))), Ada_Tags
)
9576 Warn_On_Suspicious_Index
(Pref
, First
(Expressions
(N
)));
9577 Eval_Indexed_Component
(N
);
9580 -- If the array type is atomic and the component is not, then this is
9581 -- worth a warning before Ada 2022, since we have a situation where the
9582 -- access to the component may cause extra read/writes of the atomic
9583 -- object, or partial word accesses, both of which may be unexpected.
9585 if Nkind
(N
) = N_Indexed_Component
9586 and then Is_Atomic_Ref_With_Address
(N
)
9587 and then not (Has_Atomic_Components
(Array_Type
)
9588 or else (Is_Entity_Name
(Pref
)
9589 and then Has_Atomic_Components
9591 and then not Is_Atomic
(Component_Type
(Array_Type
))
9592 and then Ada_Version
< Ada_2022
9595 ("??access to non-atomic component of atomic array", Pref
);
9597 ("??\may cause unexpected accesses to atomic object", Pref
);
9599 end Resolve_Indexed_Component
;
9601 -----------------------------
9602 -- Resolve_Integer_Literal --
9603 -----------------------------
9605 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9608 Eval_Integer_Literal
(N
);
9609 end Resolve_Integer_Literal
;
9611 -----------------------------------------
9612 -- Resolve_Interpolated_String_Literal --
9613 -----------------------------------------
9615 procedure Resolve_Interpolated_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
)
9620 Str_Elem
:= First
(Expressions
(N
));
9621 pragma Assert
(Nkind
(Str_Elem
) = N_String_Literal
);
9623 while Present
(Str_Elem
) loop
9625 -- Resolve string elements using the context type; for interpolated
9626 -- expressions there is no need to check if their type has a suitable
9627 -- image function because under Ada 2022 all the types have such
9628 -- function available.
9630 if Etype
(Str_Elem
) = Any_String
then
9631 Resolve
(Str_Elem
, Typ
);
9638 end Resolve_Interpolated_String_Literal
;
9640 --------------------------------
9641 -- Resolve_Intrinsic_Operator --
9642 --------------------------------
9644 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
9645 Is_Stoele_Mod
: constant Boolean :=
9646 Nkind
(N
) = N_Op_Mod
9647 and then Is_RTE
(First_Subtype
(Typ
), RE_Storage_Offset
)
9648 and then Is_RTE
(Etype
(Left_Opnd
(N
)), RE_Address
);
9649 -- True if this is the special mod operator of System.Storage_Elements,
9650 -- which needs to be resolved to the type of the left operand in order
9651 -- to implement the correct semantics.
9653 Btyp
: constant Entity_Id
:=
9655 then Implementation_Base_Type
(Etype
(Left_Opnd
(N
)))
9656 else Implementation_Base_Type
(Typ
));
9657 -- The base type to be used for the operator
9659 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
;
9660 -- If the operand is a literal, it cannot be the expression in a
9661 -- conversion. Use a qualified expression instead.
9663 ---------------------
9664 -- Convert_Operand --
9665 ---------------------
9667 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
is
9668 Loc
: constant Source_Ptr
:= Sloc
(Opnd
);
9672 if Nkind
(Opnd
) in N_Integer_Literal | N_Real_Literal
then
9674 Make_Qualified_Expression
(Loc
,
9675 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
9676 Expression
=> Relocate_Node
(Opnd
));
9680 Res
:= Unchecked_Convert_To
(Btyp
, Opnd
);
9684 end Convert_Operand
;
9692 -- Start of processing for Resolve_Intrinsic_Operator
9695 -- We must preserve the original entity in a generic setting, so that
9696 -- the legality of the operation can be verified in an instance.
9698 if not Expander_Active
then
9703 while Scope
(Op
) /= Standard_Standard
loop
9705 pragma Assert
(Present
(Op
));
9709 Set_Is_Overloaded
(N
, False);
9711 -- If the result or operand types are private, rewrite with unchecked
9712 -- conversions on the operands and the result, to expose the proper
9713 -- underlying numeric type. Likewise for the special mod operator of
9714 -- System.Storage_Elements, to expose the modified base type.
9716 if Is_Private_Type
(Typ
)
9717 or else Is_Private_Type
(Etype
(Left_Opnd
(N
)))
9718 or else Is_Private_Type
(Etype
(Right_Opnd
(N
)))
9719 or else Is_Stoele_Mod
9721 Arg1
:= Convert_Operand
(Left_Opnd
(N
));
9723 if Nkind
(N
) = N_Op_Expon
then
9724 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
9726 Arg2
:= Convert_Operand
(Right_Opnd
(N
));
9729 if Nkind
(Arg1
) = N_Type_Conversion
then
9730 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
9733 if Nkind
(Arg2
) = N_Type_Conversion
then
9734 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
9737 Set_Left_Opnd
(N
, Arg1
);
9738 Set_Right_Opnd
(N
, Arg2
);
9740 Set_Etype
(N
, Btyp
);
9741 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
9744 elsif Typ
/= Etype
(Left_Opnd
(N
))
9745 or else Typ
/= Etype
(Right_Opnd
(N
))
9747 -- Add explicit conversion where needed, and save interpretations in
9748 -- case operands are overloaded.
9750 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
9751 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
9753 if Nkind
(Arg1
) = N_Type_Conversion
then
9754 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
9756 Save_Interps
(Left_Opnd
(N
), Arg1
);
9759 if Nkind
(Arg2
) = N_Type_Conversion
then
9760 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
9762 Save_Interps
(Right_Opnd
(N
), Arg2
);
9765 Rewrite
(Left_Opnd
(N
), Arg1
);
9766 Rewrite
(Right_Opnd
(N
), Arg2
);
9769 Resolve_Arithmetic_Op
(N
, Typ
);
9772 Resolve_Arithmetic_Op
(N
, Typ
);
9774 end Resolve_Intrinsic_Operator
;
9776 --------------------------------------
9777 -- Resolve_Intrinsic_Unary_Operator --
9778 --------------------------------------
9780 procedure Resolve_Intrinsic_Unary_Operator
9784 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
9790 while Scope
(Op
) /= Standard_Standard
loop
9792 pragma Assert
(Present
(Op
));
9797 if Is_Private_Type
(Typ
) then
9798 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
9799 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
9801 Set_Right_Opnd
(N
, Arg2
);
9803 Set_Etype
(N
, Btyp
);
9804 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
9808 Resolve_Unary_Op
(N
, Typ
);
9810 end Resolve_Intrinsic_Unary_Operator
;
9812 ------------------------
9813 -- Resolve_Logical_Op --
9814 ------------------------
9816 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
9820 Check_No_Direct_Boolean_Operators
(N
);
9822 -- Predefined operations on scalar types yield the base type. On the
9823 -- other hand, logical operations on arrays yield the type of the
9824 -- arguments (and the context).
9826 if Is_Array_Type
(Typ
) then
9829 B_Typ
:= Base_Type
(Typ
);
9832 -- The following test is required because the operands of the operation
9833 -- may be literals, in which case the resulting type appears to be
9834 -- compatible with a signed integer type, when in fact it is compatible
9835 -- only with modular types. If the context itself is universal, the
9836 -- operation is illegal.
9838 if not Valid_Boolean_Arg
(Typ
) then
9839 Error_Msg_N
("invalid context for logical operation", N
);
9840 Set_Etype
(N
, Any_Type
);
9843 elsif Typ
= Any_Modular
then
9845 ("no modular type available in this context", N
);
9846 Set_Etype
(N
, Any_Type
);
9849 elsif Is_Modular_Integer_Type
(Typ
)
9850 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
9851 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
9853 Check_For_Visible_Operator
(N
, B_Typ
);
9856 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
9857 -- is active and the result type is standard Boolean (do not mess with
9858 -- ops that return a nonstandard Boolean type, because something strange
9861 -- Note: you might expect this replacement to be done during expansion,
9862 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
9863 -- is used, no part of the right operand of an "and" or "or" operator
9864 -- should be executed if the left operand would short-circuit the
9865 -- evaluation of the corresponding "and then" or "or else". If we left
9866 -- the replacement to expansion time, then run-time checks associated
9867 -- with such operands would be evaluated unconditionally, due to being
9868 -- before the condition prior to the rewriting as short-circuit forms
9869 -- during expansion.
9871 if Short_Circuit_And_Or
9872 and then B_Typ
= Standard_Boolean
9873 and then Nkind
(N
) in N_Op_And | N_Op_Or
9875 -- Mark the corresponding putative SCO operator as truly a logical
9876 -- (and short-circuit) operator.
9878 if Generate_SCO
and then Comes_From_Source
(N
) then
9879 Set_SCO_Logical_Operator
(N
);
9882 if Nkind
(N
) = N_Op_And
then
9884 Make_And_Then
(Sloc
(N
),
9885 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
9886 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
9887 Analyze_And_Resolve
(N
, B_Typ
);
9889 -- Case of OR changed to OR ELSE
9893 Make_Or_Else
(Sloc
(N
),
9894 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
9895 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
9896 Analyze_And_Resolve
(N
, B_Typ
);
9899 -- Return now, since analysis of the rewritten ops will take care of
9900 -- other reference bookkeeping and expression folding.
9905 Resolve
(Left_Opnd
(N
), B_Typ
);
9906 Resolve
(Right_Opnd
(N
), B_Typ
);
9908 Check_Unset_Reference
(Left_Opnd
(N
));
9909 Check_Unset_Reference
(Right_Opnd
(N
));
9911 Set_Etype
(N
, B_Typ
);
9912 Generate_Operator_Reference
(N
, B_Typ
);
9913 Eval_Logical_Op
(N
);
9914 end Resolve_Logical_Op
;
9916 ---------------------------------
9917 -- Resolve_Membership_Equality --
9918 ---------------------------------
9920 procedure Resolve_Membership_Equality
(N
: Node_Id
; Typ
: Entity_Id
) is
9921 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
9924 -- RM 4.5.2(4.1/3): if the type is limited, then it shall have a visible
9925 -- primitive equality operator. This means that we can use the regular
9926 -- visibility-based resolution and reset Entity in order to trigger it.
9928 if Is_Limited_Type
(Typ
) then
9929 Set_Entity
(N
, Empty
);
9931 -- RM 4.5.2(28.1/3): if the type is a record, then the membership test
9932 -- uses the primitive equality for the type [even if it is not visible].
9933 -- We only deal with the untagged case here, because the tagged case is
9934 -- handled uniformly in the expander.
9936 elsif Is_Record_Type
(Utyp
) and then not Is_Tagged_Type
(Utyp
) then
9938 Eq_Id
: constant Entity_Id
:= Get_User_Defined_Equality
(Typ
);
9941 if Present
(Eq_Id
) then
9942 Rewrite_Operator_As_Call
(N
, Eq_Id
);
9946 end Resolve_Membership_Equality
;
9948 ---------------------------
9949 -- Resolve_Membership_Op --
9950 ---------------------------
9952 -- The context can only be a boolean type, and does not determine the
9953 -- arguments. Arguments should be unambiguous, but the preference rule for
9954 -- universal types applies.
9956 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
9957 pragma Assert
(Is_Boolean_Type
(Typ
));
9959 L
: constant Node_Id
:= Left_Opnd
(N
);
9960 R
: constant Node_Id
:= Right_Opnd
(N
);
9963 procedure Resolve_Set_Membership
;
9964 -- Analysis has determined a unique type for the left operand. Use it as
9965 -- the basis to resolve the disjuncts.
9967 ----------------------------
9968 -- Resolve_Set_Membership --
9969 ----------------------------
9971 procedure Resolve_Set_Membership
is
9975 -- If the left operand is overloaded, find type compatible with not
9976 -- overloaded alternative of the right operand.
9978 Alt
:= First
(Alternatives
(N
));
9979 if Is_Overloaded
(L
) then
9981 while Present
(Alt
) loop
9982 if not Is_Overloaded
(Alt
) then
9983 T
:= Intersect_Types
(L
, Alt
);
9990 -- Unclear how to resolve expression if all alternatives are also
9994 Error_Msg_N
("ambiguous expression", N
);
9998 T
:= Intersect_Types
(L
, Alt
);
10003 Alt
:= First
(Alternatives
(N
));
10004 while Present
(Alt
) loop
10006 -- Alternative is an expression, a range
10007 -- or a subtype mark.
10009 if not Is_Entity_Name
(Alt
)
10010 or else not Is_Type
(Entity
(Alt
))
10018 -- Check for duplicates for discrete case
10020 if Is_Discrete_Type
(T
) then
10027 Alts
: array (0 .. List_Length
(Alternatives
(N
))) of Ent
;
10031 -- Loop checking duplicates. This is quadratic, but giant sets
10032 -- are unlikely in this context so it's a reasonable choice.
10035 Alt
:= First
(Alternatives
(N
));
10036 while Present
(Alt
) loop
10037 if Is_OK_Static_Expression
(Alt
)
10038 and then Nkind
(Alt
) in N_Integer_Literal
10039 | N_Character_Literal
10042 Nalts
:= Nalts
+ 1;
10043 Alts
(Nalts
) := (Alt
, Expr_Value
(Alt
));
10045 for J
in 1 .. Nalts
- 1 loop
10046 if Alts
(J
).Val
= Alts
(Nalts
).Val
then
10047 Error_Msg_Sloc
:= Sloc
(Alts
(J
).Alt
);
10048 Error_Msg_N
("duplicate of value given#??", Alt
);
10058 -- RM 4.5.2 (28.1/3) specifies that for types other than records or
10059 -- limited types, evaluation of a membership test uses the predefined
10060 -- equality for the type. This may be confusing to users, and the
10061 -- following warning appears useful for the most common case.
10063 if Is_Scalar_Type
(Etype
(L
))
10064 and then Present
(Get_User_Defined_Equality
(Etype
(L
)))
10067 ("membership test on& uses predefined equality?", N
, Etype
(L
));
10069 ("\even if user-defined equality exists (RM 4.5.2 (28.1/3)?", N
);
10071 end Resolve_Set_Membership
;
10073 -- Start of processing for Resolve_Membership_Op
10076 if L
= Error
or else R
= Error
then
10080 if Present
(Alternatives
(N
)) then
10081 Resolve_Set_Membership
;
10084 elsif not Is_Overloaded
(R
)
10085 and then Is_Universal_Numeric_Type
(Etype
(R
))
10086 and then Is_Overloaded
(L
)
10090 -- If the left operand is of a universal numeric type and the right
10091 -- operand is not, we do not resolve the operands to the tested type
10092 -- but to the universal type instead. If not conforming to the letter,
10093 -- it's conforming to the spirit of the specification of membership
10094 -- tests, which are typically used to guard a specific operation and
10095 -- ought not to fail a check in doing so. Without this, in the case of
10097 -- type Small_Length is range 1 .. 16;
10099 -- function Is_Small_String (S : String) return Boolean is
10101 -- return S'Length in Small_Length;
10104 -- the function Is_Small_String would fail a range check for strings
10105 -- larger than 127 characters.
10107 -- The test on the size is required in GNAT because universal_integer
10108 -- does not cover all the values of all the supported integer types,
10109 -- for example the large values of Long_Long_Long_Unsigned.
10111 elsif not Is_Overloaded
(L
)
10112 and then Is_Universal_Numeric_Type
(Etype
(L
))
10113 and then (Is_Overloaded
(R
)
10115 (not Is_Universal_Numeric_Type
(Etype
(R
))
10117 (not Is_Integer_Type
(Etype
(R
))
10119 RM_Size
(Etype
(R
)) < RM_Size
(Universal_Integer
))))
10123 -- If the right operand is 'Range, we first need to resolve it (to
10124 -- the tested type) so that it is rewritten as an N_Range, before
10125 -- converting its bounds and resolving it again below.
10127 if Nkind
(R
) = N_Attribute_Reference
10128 and then Attribute_Name
(R
) = Name_Range
10133 -- If the right operand is an N_Range, we convert its bounds to the
10134 -- universal type before resolving it.
10136 if Nkind
(R
) = N_Range
then
10138 Make_Range
(Sloc
(R
),
10139 Low_Bound
=> Convert_To
(T
, Low_Bound
(R
)),
10140 High_Bound
=> Convert_To
(T
, High_Bound
(R
))));
10144 -- Ada 2005 (AI-251): Support the following case:
10146 -- type I is interface;
10147 -- type T is tagged ...
10149 -- function Test (O : I'Class) is
10151 -- return O in T'Class.
10154 -- In this case we have nothing else to do. The membership test will be
10155 -- done at run time.
10157 elsif Ada_Version
>= Ada_2005
10158 and then Is_Class_Wide_Type
(Etype
(L
))
10159 and then Is_Interface
(Etype
(L
))
10160 and then not Is_Interface
(Etype
(R
))
10165 T
:= Intersect_Types
(L
, R
);
10168 -- If mixed-mode operations are present and operands are all literal,
10169 -- the only interpretation involves Duration, which is probably not
10170 -- the intention of the programmer.
10172 if T
= Any_Fixed
then
10173 T
:= Unique_Fixed_Point_Type
(N
);
10175 if T
= Any_Type
then
10181 Check_Unset_Reference
(L
);
10183 if Nkind
(R
) = N_Range
10184 and then not Is_Scalar_Type
(T
)
10186 Error_Msg_N
("scalar type required for range", R
);
10189 if Is_Entity_Name
(R
) then
10190 Freeze_Expression
(R
);
10193 Check_Unset_Reference
(R
);
10196 -- Here after resolving membership operation
10200 Eval_Membership_Op
(N
);
10201 end Resolve_Membership_Op
;
10207 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
10208 Loc
: constant Source_Ptr
:= Sloc
(N
);
10211 -- Handle restriction against anonymous null access values This
10212 -- restriction can be turned off using -gnatdj.
10214 -- Ada 2005 (AI-231): Remove restriction
10216 if Ada_Version
< Ada_2005
10217 and then not Debug_Flag_J
10218 and then Ekind
(Typ
) = E_Anonymous_Access_Type
10219 and then Comes_From_Source
(N
)
10221 -- In the common case of a call which uses an explicitly null value
10222 -- for an access parameter, give specialized error message.
10224 if Nkind
(Parent
(N
)) in N_Subprogram_Call
then
10226 ("NULL is not allowed as argument for an access parameter", N
);
10228 -- Standard message for all other cases (are there any?)
10232 ("NULL cannot be of an anonymous access type", N
);
10236 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
10237 -- assignment to a null-excluding object.
10239 if Ada_Version
>= Ada_2005
10240 and then Can_Never_Be_Null
(Typ
)
10241 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
10243 if Inside_Init_Proc
then
10245 -- Decide whether to generate an if_statement around our
10246 -- null-excluding check to avoid them on certain internal object
10247 -- declarations by looking at the type the current Init_Proc
10251 -- if T1b_skip_null_excluding_check then
10252 -- [constraint_error "access check failed"]
10255 if Needs_Conditional_Null_Excluding_Check
10256 (Etype
(First_Formal
(Enclosing_Init_Proc
)))
10259 Make_If_Statement
(Loc
,
10261 Make_Identifier
(Loc
,
10263 (Chars
(Typ
), "_skip_null_excluding_check")),
10266 Make_Raise_Constraint_Error
(Loc
,
10267 Reason
=> CE_Access_Check_Failed
))));
10269 -- Otherwise, simply create the check
10273 Make_Raise_Constraint_Error
(Loc
,
10274 Reason
=> CE_Access_Check_Failed
));
10278 (Compile_Time_Constraint_Error
(N
,
10279 "(Ada 2005) NULL not allowed in null-excluding objects??"),
10280 Make_Raise_Constraint_Error
(Loc
,
10281 Reason
=> CE_Access_Check_Failed
));
10285 -- In a distributed context, null for a remote access to subprogram may
10286 -- need to be replaced with a special record aggregate. In this case,
10287 -- return after having done the transformation.
10289 if (Ekind
(Typ
) = E_Record_Type
10290 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
10291 and then Remote_AST_Null_Value
(N
, Typ
)
10296 -- The null literal takes its type from the context
10298 Set_Etype
(N
, Typ
);
10301 -----------------------
10302 -- Resolve_Op_Concat --
10303 -----------------------
10305 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
10307 -- We wish to avoid deep recursion, because concatenations are often
10308 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
10309 -- operands nonrecursively until we find something that is not a simple
10310 -- concatenation (A in this case). We resolve that, and then walk back
10311 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
10312 -- to do the rest of the work at each level. The Parent pointers allow
10313 -- us to avoid recursion, and thus avoid running out of memory. See also
10314 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
10320 -- The following code is equivalent to:
10322 -- Resolve_Op_Concat_First (NN, Typ);
10323 -- Resolve_Op_Concat_Arg (N, ...);
10324 -- Resolve_Op_Concat_Rest (N, Typ);
10326 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
10327 -- operand is a concatenation.
10329 -- Walk down left operands
10332 Resolve_Op_Concat_First
(NN
, Typ
);
10333 Op1
:= Left_Opnd
(NN
);
10334 exit when not (Nkind
(Op1
) = N_Op_Concat
10335 and then not Is_Array_Type
(Component_Type
(Typ
))
10336 and then Entity
(Op1
) = Entity
(NN
));
10340 -- Now (given the above example) NN is A&B and Op1 is A
10342 -- First resolve Op1 ...
10344 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
10346 -- ... then walk NN back up until we reach N (where we started), calling
10347 -- Resolve_Op_Concat_Rest along the way.
10350 Resolve_Op_Concat_Rest
(NN
, Typ
);
10354 end Resolve_Op_Concat
;
10356 ---------------------------
10357 -- Resolve_Op_Concat_Arg --
10358 ---------------------------
10360 procedure Resolve_Op_Concat_Arg
10366 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10367 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
10370 if In_Instance
then
10372 or else (not Is_Overloaded
(Arg
)
10373 and then Etype
(Arg
) /= Any_Composite
10374 and then Covers
(Ctyp
, Etype
(Arg
)))
10376 Resolve
(Arg
, Ctyp
);
10378 Resolve
(Arg
, Btyp
);
10381 -- If both Array & Array and Array & Component are visible, there is a
10382 -- potential ambiguity that must be reported.
10384 elsif Has_Compatible_Type
(Arg
, Ctyp
) then
10385 if Nkind
(Arg
) = N_Aggregate
10386 and then Is_Composite_Type
(Ctyp
)
10388 if Is_Private_Type
(Ctyp
) then
10389 Resolve
(Arg
, Btyp
);
10391 -- If the operation is user-defined and not overloaded use its
10392 -- profile. The operation may be a renaming, in which case it has
10393 -- been rewritten, and we want the original profile.
10395 elsif not Is_Overloaded
(N
)
10396 and then Comes_From_Source
(Entity
(Original_Node
(N
)))
10397 and then Ekind
(Entity
(Original_Node
(N
))) = E_Function
10401 (Next_Formal
(First_Formal
(Entity
(Original_Node
(N
))))));
10404 -- Otherwise an aggregate may match both the array type and the
10408 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
10409 Set_Etype
(Arg
, Any_Type
);
10413 if Is_Overloaded
(Arg
)
10414 and then Has_Compatible_Type
(Arg
, Typ
)
10415 and then Etype
(Arg
) /= Any_Type
10423 Get_First_Interp
(Arg
, I
, It
);
10425 Get_Next_Interp
(I
, It
);
10427 -- Special-case the error message when the overloading is
10428 -- caused by a function that yields an array and can be
10429 -- called without parameters.
10431 if It
.Nam
= Func
then
10432 Error_Msg_Sloc
:= Sloc
(Func
);
10433 Error_Msg_N
("ambiguous call to function#", Arg
);
10435 ("\\interpretation as call yields&", Arg
, Typ
);
10437 ("\\interpretation as indexing of call yields&",
10441 Error_Msg_N
("ambiguous operand for concatenation!", Arg
);
10443 Get_First_Interp
(Arg
, I
, It
);
10444 while Present
(It
.Nam
) loop
10445 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
10447 if Base_Type
(It
.Typ
) = Btyp
10449 Base_Type
(It
.Typ
) = Base_Type
(Ctyp
)
10451 Error_Msg_N
-- CODEFIX
10452 ("\\possible interpretation#", Arg
);
10455 Get_Next_Interp
(I
, It
);
10461 Resolve
(Arg
, Ctyp
);
10463 if Nkind
(Arg
) = N_String_Literal
then
10464 Set_Etype
(Arg
, Ctyp
);
10466 elsif Is_Scalar_Type
(Etype
(Arg
))
10467 and then Compile_Time_Known_Value
(Arg
)
10469 -- Determine if the out-of-range violation constitutes a
10470 -- warning or an error according to the expression base type,
10471 -- according to Ada 2022 RM 4.9 (35/2).
10473 if Is_Out_Of_Range
(Arg
, Base_Type
(Ctyp
)) then
10474 Apply_Compile_Time_Constraint_Error
10475 (Arg
, "value not in range of}", CE_Range_Check_Failed
,
10476 Ent
=> Base_Type
(Ctyp
),
10477 Typ
=> Base_Type
(Ctyp
));
10479 elsif Is_Out_Of_Range
(Arg
, Ctyp
) then
10480 Apply_Compile_Time_Constraint_Error
10481 (Arg
, "value not in range of}??", CE_Range_Check_Failed
,
10487 if Arg
= Left_Opnd
(N
) then
10488 Set_Is_Component_Left_Opnd
(N
);
10490 Set_Is_Component_Right_Opnd
(N
);
10495 Resolve
(Arg
, Btyp
);
10498 Check_Unset_Reference
(Arg
);
10499 end Resolve_Op_Concat_Arg
;
10501 -----------------------------
10502 -- Resolve_Op_Concat_First --
10503 -----------------------------
10505 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
10506 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10507 Op1
: constant Node_Id
:= Left_Opnd
(N
);
10508 Op2
: constant Node_Id
:= Right_Opnd
(N
);
10511 -- The parser folds an enormous sequence of concatenations of string
10512 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
10513 -- in the right operand. If the expression resolves to a predefined "&"
10514 -- operator, all is well. Otherwise, the parser's folding is wrong, so
10515 -- we give an error. See P_Simple_Expression in Par.Ch4.
10517 if Nkind
(Op2
) = N_String_Literal
10518 and then Is_Folded_In_Parser
(Op2
)
10519 and then Ekind
(Entity
(N
)) = E_Function
10521 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
10522 and then String_Length
(Strval
(Op1
)) = 0);
10523 Error_Msg_N
("too many user-defined concatenations", N
);
10527 Set_Etype
(N
, Btyp
);
10529 if Is_Limited_Composite
(Btyp
) then
10530 Error_Msg_N
("concatenation not available for limited array", N
);
10531 Explain_Limited_Type
(Btyp
, N
);
10533 end Resolve_Op_Concat_First
;
10535 ----------------------------
10536 -- Resolve_Op_Concat_Rest --
10537 ----------------------------
10539 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
10540 Op1
: constant Node_Id
:= Left_Opnd
(N
);
10541 Op2
: constant Node_Id
:= Right_Opnd
(N
);
10544 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
10546 Generate_Operator_Reference
(N
, Typ
);
10548 if Is_String_Type
(Typ
) then
10549 Eval_Concatenation
(N
);
10552 -- If this is not a static concatenation, but the result is a string
10553 -- type (and not an array of strings) ensure that static string operands
10554 -- have their subtypes properly constructed.
10556 if Nkind
(N
) /= N_String_Literal
10557 and then Is_Character_Type
(Component_Type
(Typ
))
10559 Set_String_Literal_Subtype
(Op1
, Typ
);
10560 Set_String_Literal_Subtype
(Op2
, Typ
);
10562 end Resolve_Op_Concat_Rest
;
10564 ----------------------
10565 -- Resolve_Op_Expon --
10566 ----------------------
10568 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
10569 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10572 -- Catch attempts to do fixed-point exponentiation with universal
10573 -- operands, which is a case where the illegality is not caught during
10574 -- normal operator analysis. This is not done in preanalysis mode
10575 -- since the tree is not fully decorated during preanalysis.
10577 if Full_Analysis
then
10578 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
10579 Error_Msg_N
("exponentiation not available for fixed point", N
);
10582 elsif Nkind
(Parent
(N
)) in N_Op
10583 and then Present
(Etype
(Parent
(N
)))
10584 and then Is_Fixed_Point_Type
(Etype
(Parent
(N
)))
10585 and then Etype
(N
) = Universal_Real
10586 and then Comes_From_Source
(N
)
10588 Error_Msg_N
("exponentiation not available for fixed point", N
);
10593 if Ekind
(Entity
(N
)) = E_Function
10594 and then Is_Imported
(Entity
(N
))
10595 and then Is_Intrinsic_Subprogram
(Entity
(N
))
10597 Generate_Reference
(Entity
(N
), N
);
10598 Resolve_Intrinsic_Operator
(N
, Typ
);
10602 if Is_Universal_Numeric_Type
(Etype
(Left_Opnd
(N
))) then
10603 Check_For_Visible_Operator
(N
, B_Typ
);
10606 -- We do the resolution using the base type, because intermediate values
10607 -- in expressions are always of the base type, not a subtype of it.
10609 Resolve
(Left_Opnd
(N
), B_Typ
);
10610 Resolve
(Right_Opnd
(N
), Standard_Integer
);
10612 -- For integer types, right argument must be in Natural range
10614 if Is_Integer_Type
(Typ
) then
10615 Apply_Scalar_Range_Check
(Right_Opnd
(N
), Standard_Natural
);
10618 Check_Unset_Reference
(Left_Opnd
(N
));
10619 Check_Unset_Reference
(Right_Opnd
(N
));
10621 Set_Etype
(N
, B_Typ
);
10622 Generate_Operator_Reference
(N
, B_Typ
);
10624 Analyze_Dimension
(N
);
10626 if Ada_Version
>= Ada_2012
and then Has_Dimension_System
(B_Typ
) then
10627 -- Evaluate the exponentiation operator for dimensioned type
10629 Eval_Op_Expon_For_Dimensioned_Type
(N
, B_Typ
);
10634 -- Set overflow checking bit. Much cleverer code needed here eventually
10635 -- and perhaps the Resolve routines should be separated for the various
10636 -- arithmetic operations, since they will need different processing. ???
10638 if Nkind
(N
) in N_Op
then
10639 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
10640 Enable_Overflow_Check
(N
);
10643 end Resolve_Op_Expon
;
10645 --------------------
10646 -- Resolve_Op_Not --
10647 --------------------
10649 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
10650 function Parent_Is_Boolean
return Boolean;
10651 -- This function determines if the parent node is a boolean operator or
10652 -- operation (comparison op, membership test, or short circuit form) and
10653 -- the not in question is the left operand of this operation. Note that
10654 -- if the not is in parens, then false is returned.
10656 -----------------------
10657 -- Parent_Is_Boolean --
10658 -----------------------
10660 function Parent_Is_Boolean
return Boolean is
10662 return Paren_Count
(N
) = 0
10663 and then Nkind
(Parent
(N
)) in N_Membership_Test
10666 and then Left_Opnd
(Parent
(N
)) = N
;
10667 end Parent_Is_Boolean
;
10673 -- Start of processing for Resolve_Op_Not
10676 -- Predefined operations on scalar types yield the base type. On the
10677 -- other hand, logical operations on arrays yield the type of the
10678 -- arguments (and the context).
10680 if Is_Array_Type
(Typ
) then
10683 B_Typ
:= Base_Type
(Typ
);
10686 -- Straightforward case of incorrect arguments
10688 if not Valid_Boolean_Arg
(Typ
) then
10689 Error_Msg_N
("invalid operand type for operator&", N
);
10690 Set_Etype
(N
, Any_Type
);
10693 -- Special case of probable missing parens
10695 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
10696 if Parent_Is_Boolean
then
10698 ("operand of NOT must be enclosed in parentheses",
10702 ("no modular type available in this context", N
);
10705 Set_Etype
(N
, Any_Type
);
10708 -- OK resolution of NOT
10711 -- Warn if non-boolean types involved. This is a case like not a < b
10712 -- where a and b are modular, where we will get (not a) < b and most
10713 -- likely not (a < b) was intended.
10715 if Warn_On_Questionable_Missing_Parens
10716 and then not Is_Boolean_Type
(Typ
)
10717 and then Parent_Is_Boolean
10719 Error_Msg_N
("?q?not expression should be parenthesized here!", N
);
10722 -- Warn on double negation if checking redundant constructs
10724 if Warn_On_Redundant_Constructs
10725 and then Comes_From_Source
(N
)
10726 and then Comes_From_Source
(Right_Opnd
(N
))
10727 and then Root_Type
(Typ
) = Standard_Boolean
10728 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
10730 Error_Msg_N
("redundant double negation?r?", N
);
10733 -- Complete resolution and evaluation of NOT
10735 Resolve
(Right_Opnd
(N
), B_Typ
);
10736 Check_Unset_Reference
(Right_Opnd
(N
));
10737 Set_Etype
(N
, B_Typ
);
10738 Generate_Operator_Reference
(N
, B_Typ
);
10741 end Resolve_Op_Not
;
10743 -----------------------------
10744 -- Resolve_Operator_Symbol --
10745 -----------------------------
10747 -- Nothing to be done, all resolved already
10749 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
10750 pragma Warnings
(Off
, N
);
10751 pragma Warnings
(Off
, Typ
);
10755 end Resolve_Operator_Symbol
;
10757 ----------------------------------
10758 -- Resolve_Qualified_Expression --
10759 ----------------------------------
10761 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
10762 pragma Warnings
(Off
, Typ
);
10764 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
10765 Expr
: constant Node_Id
:= Expression
(N
);
10768 Resolve
(Expr
, Target_Typ
);
10769 Check_Unset_Reference
(Expr
);
10771 -- A qualified expression requires an exact match of the type, class-
10772 -- wide matching is not allowed. However, if the qualifying type is
10773 -- specific and the expression has a class-wide type, it may still be
10774 -- okay, since it can be the result of the expansion of a call to a
10775 -- dispatching function, so we also have to check class-wideness of the
10776 -- type of the expression's original node.
10778 if (Is_Class_Wide_Type
(Target_Typ
)
10780 (Is_Class_Wide_Type
(Etype
(Expr
))
10781 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
10782 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
10784 Wrong_Type
(Expr
, Target_Typ
);
10787 -- If the target type is unconstrained, then we reset the type of the
10788 -- result from the type of the expression. For other cases, the actual
10789 -- subtype of the expression is the target type. But we avoid doing it
10790 -- for an allocator since this is not needed and might be problematic.
10792 if Is_Composite_Type
(Target_Typ
)
10793 and then not Is_Constrained
(Target_Typ
)
10794 and then Nkind
(Parent
(N
)) /= N_Allocator
10796 Set_Etype
(N
, Etype
(Expr
));
10799 Analyze_Dimension
(N
);
10800 Eval_Qualified_Expression
(N
);
10802 -- If we still have a qualified expression after the static evaluation,
10803 -- then apply a scalar range check if needed. The reason that we do this
10804 -- after the Eval call is that otherwise, the application of the range
10805 -- check may convert an illegal static expression and result in warning
10806 -- rather than giving an error (e.g Integer'(Integer'Last + 1)).
10808 if Nkind
(N
) = N_Qualified_Expression
10809 and then Is_Scalar_Type
(Target_Typ
)
10811 Apply_Scalar_Range_Check
(Expr
, Target_Typ
);
10814 -- AI12-0100: Once the qualified expression is resolved, check whether
10815 -- operand satisfies a static predicate of the target subtype, if any.
10816 -- In the static expression case, a predicate check failure is an error.
10818 if Has_Predicates
(Target_Typ
) then
10819 Check_Expression_Against_Static_Predicate
10820 (Expr
, Target_Typ
, Static_Failure_Is_Error
=> True);
10822 end Resolve_Qualified_Expression
;
10824 ------------------------------
10825 -- Resolve_Raise_Expression --
10826 ------------------------------
10828 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
10830 if Typ
= Raise_Type
then
10831 Error_Msg_N
("cannot find unique type for raise expression", N
);
10832 Set_Etype
(N
, Any_Type
);
10835 Set_Etype
(N
, Typ
);
10837 -- Apply check for required parentheses in the enclosing
10838 -- context of raise_expressions (RM 11.3 (2)), including default
10839 -- expressions in contexts that can include aspect specifications,
10840 -- and ancestor parts of extension aggregates.
10843 Par
: Node_Id
:= Parent
(N
);
10844 Parentheses_Found
: Boolean := Paren_Count
(N
) > 0;
10847 while Present
(Par
)
10848 and then Nkind
(Par
) in N_Has_Etype
10850 if Paren_Count
(Par
) > 0 then
10851 Parentheses_Found
:= True;
10854 if Nkind
(Par
) = N_Extension_Aggregate
10855 and then N
= Ancestor_Part
(Par
)
10860 Par
:= Parent
(Par
);
10863 if not Parentheses_Found
10864 and then Comes_From_Source
(Par
)
10866 (Nkind
(Par
) in N_Modular_Type_Definition
10867 | N_Floating_Point_Definition
10868 | N_Ordinary_Fixed_Point_Definition
10869 | N_Decimal_Fixed_Point_Definition
10870 | N_Extension_Aggregate
10871 | N_Discriminant_Specification
10872 | N_Parameter_Specification
10873 | N_Formal_Object_Declaration
10875 or else (Nkind
(Par
) = N_Object_Declaration
10877 Nkind
(Parent
(Par
)) /= N_Extended_Return_Statement
))
10880 ("raise_expression must be parenthesized in this context",
10885 end Resolve_Raise_Expression
;
10887 -------------------
10888 -- Resolve_Range --
10889 -------------------
10891 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
10892 L
: constant Node_Id
:= Low_Bound
(N
);
10893 H
: constant Node_Id
:= High_Bound
(N
);
10895 function First_Last_Ref
return Boolean;
10896 -- Returns True if N is of the form X'First .. X'Last where X is the
10897 -- same entity for both attributes.
10899 --------------------
10900 -- First_Last_Ref --
10901 --------------------
10903 function First_Last_Ref
return Boolean is
10904 Lorig
: constant Node_Id
:= Original_Node
(L
);
10905 Horig
: constant Node_Id
:= Original_Node
(H
);
10908 if Nkind
(Lorig
) = N_Attribute_Reference
10909 and then Nkind
(Horig
) = N_Attribute_Reference
10910 and then Attribute_Name
(Lorig
) = Name_First
10911 and then Attribute_Name
(Horig
) = Name_Last
10914 PL
: constant Node_Id
:= Prefix
(Lorig
);
10915 PH
: constant Node_Id
:= Prefix
(Horig
);
10917 return Is_Entity_Name
(PL
)
10918 and then Is_Entity_Name
(PH
)
10919 and then Entity
(PL
) = Entity
(PH
);
10924 end First_Last_Ref
;
10926 -- Start of processing for Resolve_Range
10929 Set_Etype
(N
, Typ
);
10934 -- Reanalyze the lower bound after both bounds have been analyzed, so
10935 -- that the range is known to be static or not by now. This may trigger
10936 -- more compile-time evaluation, which is useful for static analysis
10937 -- with GNATprove. This is not needed for compilation or static analysis
10938 -- with CodePeer, as full expansion does that evaluation then.
10940 if GNATprove_Mode
then
10941 Set_Analyzed
(L
, False);
10945 -- Check for inappropriate range on unordered enumeration type
10947 if Bad_Unordered_Enumeration_Reference
(N
, Typ
)
10949 -- Exclude X'First .. X'Last if X is the same entity for both
10951 and then not First_Last_Ref
10953 Error_Msg_Sloc
:= Sloc
(Typ
);
10955 ("subrange of unordered enumeration type& declared#?.u?", N
, Typ
);
10958 Check_Unset_Reference
(L
);
10959 Check_Unset_Reference
(H
);
10961 -- We have to check the bounds for being within the base range as
10962 -- required for a non-static context. Normally this is automatic and
10963 -- done as part of evaluating expressions, but the N_Range node is an
10964 -- exception, since in GNAT we consider this node to be a subexpression,
10965 -- even though in Ada it is not. The circuit in Sem_Eval could check for
10966 -- this, but that would put the test on the main evaluation path for
10969 Check_Non_Static_Context
(L
);
10970 Check_Non_Static_Context
(H
);
10972 -- Check for an ambiguous range over character literals. This will
10973 -- happen with a membership test involving only literals.
10975 if Typ
= Any_Character
then
10976 Ambiguous_Character
(L
);
10977 Set_Etype
(N
, Any_Type
);
10981 -- If bounds are static, constant-fold them, so size computations are
10982 -- identical between front-end and back-end. Do not perform this
10983 -- transformation while analyzing generic units, as type information
10984 -- would be lost when reanalyzing the constant node in the instance.
10986 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
10987 if Is_OK_Static_Expression
(L
) then
10988 Fold_Uint
(L
, Expr_Value
(L
), Static
=> True);
10991 if Is_OK_Static_Expression
(H
) then
10992 Fold_Uint
(H
, Expr_Value
(H
), Static
=> True);
10996 -- If we have a compile-time-known null range, we warn, because that is
10997 -- likely to be a mistake. (Dynamic null ranges make sense, but often
10998 -- compile-time-known ones do not.) Warn only if this is in a subtype
10999 -- declaration. We do this here, rather than while analyzing a subtype
11000 -- declaration, in case we decide to expand the cases. We do not want to
11001 -- warn in all cases, because some are idiomatic, such as an empty
11002 -- aggregate (1 .. 0 => <>).
11004 -- We don't warn in generics or their instances, because there might be
11005 -- some instances where the range is null, and some where it is not,
11006 -- which would lead to false alarms.
11008 if not (Inside_A_Generic
or In_Instance
)
11009 and then Comes_From_Source
(N
)
11010 and then Compile_Time_Compare
11011 (Low_Bound
(N
), High_Bound
(N
), Assume_Valid
=> True) = GT
11012 and then Nkind
(Parent
(N
)) = N_Range_Constraint
11013 and then Nkind
(Parent
(Parent
(N
))) = N_Subtype_Indication
11014 and then Nkind
(Parent
(Parent
(Parent
(N
)))) = N_Subtype_Declaration
11015 and then Is_OK_Static_Range
(N
)
11017 Error_Msg_N
("null range??", N
);
11021 --------------------------
11022 -- Resolve_Real_Literal --
11023 --------------------------
11025 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
11026 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
11029 -- Special processing for fixed-point literals to make sure that the
11030 -- value is an exact multiple of the small where this is required. We
11031 -- skip this for the universal real case, and also for generic types.
11033 if Is_Fixed_Point_Type
(Typ
)
11034 and then Typ
/= Universal_Fixed
11035 and then Typ
/= Any_Fixed
11036 and then not Is_Generic_Type
(Typ
)
11038 -- We must freeze the base type to get the proper value of the small
11040 if not Is_Frozen
(Base_Type
(Typ
)) then
11041 Freeze_Fixed_Point_Type
(Base_Type
(Typ
));
11045 Val
: constant Ureal
:= Realval
(N
);
11046 Cintr
: constant Ureal
:= Val
/ Small_Value
(Base_Type
(Typ
));
11047 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
11048 Den
: constant Uint
:= Norm_Den
(Cintr
);
11052 -- Case of literal is not an exact multiple of the Small
11056 -- For a source program literal for a decimal fixed-point type,
11057 -- this is statically illegal (RM 4.9(36)).
11059 if Is_Decimal_Fixed_Point_Type
(Typ
)
11060 and then Actual_Typ
= Universal_Real
11061 and then Comes_From_Source
(N
)
11063 Error_Msg_N
("value has extraneous low order digits", N
);
11066 -- Generate a warning if literal from source
11068 if Is_OK_Static_Expression
(N
)
11069 and then Warn_On_Bad_Fixed_Value
11072 ("?b?static fixed-point value is not a multiple of Small!",
11076 -- Replace literal by a value that is the exact representation
11077 -- of a value of the type, i.e. a multiple of the small value,
11078 -- by truncation, since Machine_Rounds is false for all GNAT
11079 -- fixed-point types (RM 4.9(38)).
11081 Stat
:= Is_OK_Static_Expression
(N
);
11083 Make_Real_Literal
(Sloc
(N
),
11084 Realval
=> Small_Value
(Typ
) * Cint
));
11086 Set_Is_Static_Expression
(N
, Stat
);
11089 -- In all cases, set the corresponding integer field
11091 Set_Corresponding_Integer_Value
(N
, Cint
);
11095 -- Now replace the actual type by the expected type as usual
11097 Set_Etype
(N
, Typ
);
11098 Eval_Real_Literal
(N
);
11099 end Resolve_Real_Literal
;
11101 -----------------------
11102 -- Resolve_Reference --
11103 -----------------------
11105 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
11106 P
: constant Node_Id
:= Prefix
(N
);
11109 -- Replace general access with specific type
11111 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
11112 Set_Etype
(N
, Base_Type
(Typ
));
11115 Resolve
(P
, Designated_Type
(Etype
(N
)));
11117 -- If we are taking the reference of a volatile entity, then treat it as
11118 -- a potential modification of this entity. This is too conservative,
11119 -- but necessary because remove side effects can cause transformations
11120 -- of normal assignments into reference sequences that otherwise fail to
11121 -- notice the modification.
11123 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
11124 Note_Possible_Modification
(P
, Sure
=> False);
11126 end Resolve_Reference
;
11128 --------------------------------
11129 -- Resolve_Selected_Component --
11130 --------------------------------
11132 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
11134 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
11135 P
: constant Node_Id
:= Prefix
(N
);
11136 S
: constant Node_Id
:= Selector_Name
(N
);
11137 T
: Entity_Id
:= Etype
(P
);
11139 I1
: Interp_Index
:= 0; -- prevent junk warning
11144 function Init_Component
return Boolean;
11145 -- Check whether this is the initialization of a component within an
11146 -- init proc (by assignment or call to another init proc). If true,
11147 -- there is no need for a discriminant check.
11149 --------------------
11150 -- Init_Component --
11151 --------------------
11153 function Init_Component
return Boolean is
11155 return Inside_Init_Proc
11156 and then Nkind
(Prefix
(N
)) = N_Identifier
11157 and then Chars
(Prefix
(N
)) = Name_uInit
11158 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
11159 end Init_Component
;
11161 -- Start of processing for Resolve_Selected_Component
11164 if Is_Overloaded
(P
) then
11166 -- Use the context type to select the prefix that has a selector
11167 -- of the correct name and type.
11170 Get_First_Interp
(P
, I
, It
);
11172 Search
: while Present
(It
.Typ
) loop
11173 if Is_Access_Type
(It
.Typ
) then
11174 T
:= Designated_Type
(It
.Typ
);
11179 -- Locate selected component. For a private prefix the selector
11180 -- can denote a discriminant.
11182 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
11184 -- The visible components of a class-wide type are those of
11187 if Is_Class_Wide_Type
(T
) then
11191 Comp
:= First_Entity
(T
);
11192 while Present
(Comp
) loop
11193 if Chars
(Comp
) = Chars
(S
)
11194 and then Covers
(Typ
, Etype
(Comp
))
11203 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
11205 if It
= No_Interp
then
11207 ("ambiguous prefix for selected component", N
);
11208 Set_Etype
(N
, Typ
);
11214 -- There may be an implicit dereference. Retrieve
11215 -- designated record type.
11217 if Is_Access_Type
(It1
.Typ
) then
11218 T
:= Designated_Type
(It1
.Typ
);
11223 if Scope
(Comp1
) /= T
then
11225 -- Resolution chooses the new interpretation.
11226 -- Find the component with the right name.
11228 Comp1
:= First_Entity
(T
);
11229 while Present
(Comp1
)
11230 and then Chars
(Comp1
) /= Chars
(S
)
11232 Next_Entity
(Comp1
);
11241 Next_Entity
(Comp
);
11245 Get_Next_Interp
(I
, It
);
11248 -- There must be a legal interpretation at this point
11250 pragma Assert
(Found
);
11251 Resolve
(P
, It1
.Typ
);
11253 -- In general the expected type is the type of the context, not the
11254 -- type of the candidate selected component.
11256 Set_Etype
(N
, Typ
);
11257 Set_Entity_With_Checks
(S
, Comp1
);
11259 -- The type of the context and that of the component are
11260 -- compatible and in general identical, but if they are anonymous
11261 -- access-to-subprogram types, the relevant type is that of the
11262 -- component. This matters in Unnest_Subprograms mode, where the
11263 -- relevant context is the one in which the type is declared, not
11264 -- the point of use. This determines what activation record to use.
11266 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
11267 Set_Etype
(N
, Etype
(Comp1
));
11269 -- When the type of the component is an access to a class-wide type
11270 -- the relevant type is that of the component (since in such case we
11271 -- may need to generate implicit type conversions or dispatching
11274 elsif Is_Access_Type
(Typ
)
11275 and then not Is_Class_Wide_Type
(Designated_Type
(Typ
))
11276 and then Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp1
)))
11278 Set_Etype
(N
, Etype
(Comp1
));
11282 -- Resolve prefix with its type
11287 -- Generate cross-reference. We needed to wait until full overloading
11288 -- resolution was complete to do this, since otherwise we can't tell if
11289 -- we are an lvalue or not.
11291 if Known_To_Be_Assigned
(N
) then
11292 Generate_Reference
(Entity
(S
), S
, 'm');
11294 Generate_Reference
(Entity
(S
), S
, 'r');
11297 -- If the prefix's type is an access type, get to the real record type.
11298 -- Note: we do not apply an access check because an explicit dereference
11299 -- will be introduced later, and the check will happen there.
11301 if Is_Access_Type
(Etype
(P
)) then
11302 T
:= Implicitly_Designated_Type
(Etype
(P
));
11303 Check_Fully_Declared_Prefix
(T
, P
);
11309 -- Set flag for expander if discriminant check required on a component
11310 -- appearing within a variant.
11312 if Has_Discriminants
(T
)
11313 and then Ekind
(Entity
(S
)) = E_Component
11314 and then Present
(Original_Record_Component
(Entity
(S
)))
11315 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
11317 Is_Declared_Within_Variant
(Original_Record_Component
(Entity
(S
)))
11318 and then not Discriminant_Checks_Suppressed
(T
)
11319 and then not Init_Component
11321 Set_Do_Discriminant_Check
(N
);
11324 if Ekind
(Entity
(S
)) = E_Void
then
11325 Error_Msg_N
("premature use of component", S
);
11328 -- If the prefix is a record conversion, this may be a renamed
11329 -- discriminant whose bounds differ from those of the original
11330 -- one, so we must ensure that a range check is performed.
11332 if Nkind
(P
) = N_Type_Conversion
11333 and then Ekind
(Entity
(S
)) = E_Discriminant
11334 and then Is_Discrete_Type
(Typ
)
11336 Set_Etype
(N
, Base_Type
(Typ
));
11339 -- Eval_Selected_Component may e.g. fold statically known discriminants.
11341 Eval_Selected_Component
(N
);
11343 if Nkind
(N
) = N_Selected_Component
then
11345 -- If the record type is atomic and the component is not, then this
11346 -- is worth a warning before Ada 2022, since we have a situation
11347 -- where the access to the component may cause extra read/writes of
11348 -- the atomic object, or partial word accesses, both of which may be
11351 if Is_Atomic_Ref_With_Address
(N
)
11352 and then not Is_Atomic
(Entity
(S
))
11353 and then not Is_Atomic
(Etype
(Entity
(S
)))
11354 and then Ada_Version
< Ada_2022
11357 ("??access to non-atomic component of atomic record",
11360 ("\??may cause unexpected accesses to atomic object",
11364 Resolve_Implicit_Dereference
(Prefix
(N
));
11365 Analyze_Dimension
(N
);
11367 end Resolve_Selected_Component
;
11369 -------------------
11370 -- Resolve_Shift --
11371 -------------------
11373 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
11374 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11375 L
: constant Node_Id
:= Left_Opnd
(N
);
11376 R
: constant Node_Id
:= Right_Opnd
(N
);
11379 -- We do the resolution using the base type, because intermediate values
11380 -- in expressions always are of the base type, not a subtype of it.
11382 Resolve
(L
, B_Typ
);
11383 Resolve
(R
, Standard_Natural
);
11385 Check_Unset_Reference
(L
);
11386 Check_Unset_Reference
(R
);
11388 Set_Etype
(N
, B_Typ
);
11389 Generate_Operator_Reference
(N
, B_Typ
);
11393 ---------------------------
11394 -- Resolve_Short_Circuit --
11395 ---------------------------
11397 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
11398 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11399 L
: constant Node_Id
:= Left_Opnd
(N
);
11400 R
: constant Node_Id
:= Right_Opnd
(N
);
11403 -- Ensure all actions associated with the left operand (e.g.
11404 -- finalization of transient objects) are fully evaluated locally within
11405 -- an expression with actions. This is particularly helpful for coverage
11406 -- analysis. However this should not happen in generics or if option
11407 -- Minimize_Expression_With_Actions is set.
11409 if Expander_Active
and not Minimize_Expression_With_Actions
then
11411 Reloc_L
: constant Node_Id
:= Relocate_Node
(L
);
11413 Save_Interps
(Old_N
=> L
, New_N
=> Reloc_L
);
11416 Make_Expression_With_Actions
(Sloc
(L
),
11417 Actions
=> New_List
,
11418 Expression
=> Reloc_L
));
11420 -- Set Comes_From_Source on L to preserve warnings for unset
11423 Preserve_Comes_From_Source
(L
, Reloc_L
);
11427 Resolve
(L
, B_Typ
);
11428 Resolve
(R
, B_Typ
);
11430 -- Check for issuing warning for always False assert/check, this happens
11431 -- when assertions are turned off, in which case the pragma Assert/Check
11432 -- was transformed into:
11434 -- if False and then <condition> then ...
11436 -- and we detect this pattern
11438 if Warn_On_Assertion_Failure
11439 and then Is_Entity_Name
(R
)
11440 and then Entity
(R
) = Standard_False
11441 and then Nkind
(Parent
(N
)) = N_If_Statement
11442 and then Nkind
(N
) = N_And_Then
11443 and then Is_Entity_Name
(L
)
11444 and then Entity
(L
) = Standard_False
11447 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
11450 -- Special handling of Asssert pragma
11452 if Nkind
(Orig
) = N_Pragma
11453 and then Pragma_Name
(Orig
) = Name_Assert
11456 Expr
: constant Node_Id
:=
11459 (First
(Pragma_Argument_Associations
(Orig
))));
11462 -- Don't warn if original condition is explicit False,
11463 -- since obviously the failure is expected in this case.
11465 if Is_Entity_Name
(Expr
)
11466 and then Entity
(Expr
) = Standard_False
11470 -- Issue warning. We do not want the deletion of the
11471 -- IF/AND-THEN to take this message with it. We achieve this
11472 -- by making sure that the expanded code points to the Sloc
11473 -- of the expression, not the original pragma.
11476 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
11477 -- The source location of the expression is not usually
11478 -- the best choice here. For example, it gets located on
11479 -- the last AND keyword in a chain of boolean expressiond
11480 -- AND'ed together. It is best to put the message on the
11481 -- first character of the assertion, which is the effect
11482 -- of the First_Node call here.
11485 ("?.a?assertion would fail at run time!",
11487 (First
(Pragma_Argument_Associations
(Orig
))));
11491 -- Similar processing for Check pragma
11493 elsif Nkind
(Orig
) = N_Pragma
11494 and then Pragma_Name
(Orig
) = Name_Check
11496 -- Don't want to warn if original condition is explicit False
11499 Expr
: constant Node_Id
:=
11502 (Next
(First
(Pragma_Argument_Associations
(Orig
)))));
11504 if Is_Entity_Name
(Expr
)
11505 and then Entity
(Expr
) = Standard_False
11512 -- Again use Error_Msg_F rather than Error_Msg_N, see
11513 -- comment above for an explanation of why we do this.
11516 ("?.a?check would fail at run time!",
11518 (Last
(Pragma_Argument_Associations
(Orig
))));
11525 -- Continue with processing of short circuit
11527 Check_Unset_Reference
(L
);
11528 Check_Unset_Reference
(R
);
11530 Set_Etype
(N
, B_Typ
);
11531 Eval_Short_Circuit
(N
);
11532 end Resolve_Short_Circuit
;
11534 -------------------
11535 -- Resolve_Slice --
11536 -------------------
11538 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
11539 Drange
: constant Node_Id
:= Discrete_Range
(N
);
11540 Pref
: constant Node_Id
:= Prefix
(N
);
11541 Array_Type
: Entity_Id
:= Empty
;
11542 Dexpr
: Node_Id
:= Empty
;
11543 Index_Type
: Entity_Id
;
11546 if Is_Overloaded
(Pref
) then
11548 -- Use the context type to select the prefix that yields the correct
11553 I1
: Interp_Index
:= 0;
11555 Found
: Boolean := False;
11558 Get_First_Interp
(Pref
, I
, It
);
11559 while Present
(It
.Typ
) loop
11560 if (Is_Array_Type
(It
.Typ
)
11561 and then Covers
(Typ
, It
.Typ
))
11562 or else (Is_Access_Type
(It
.Typ
)
11563 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
11564 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
11567 It
:= Disambiguate
(Pref
, I1
, I
, Any_Type
);
11569 if It
= No_Interp
then
11570 Error_Msg_N
("ambiguous prefix for slicing", N
);
11571 Set_Etype
(N
, Typ
);
11575 Array_Type
:= It
.Typ
;
11580 Array_Type
:= It
.Typ
;
11585 Get_Next_Interp
(I
, It
);
11590 Array_Type
:= Etype
(Pref
);
11593 Resolve
(Pref
, Array_Type
);
11595 -- If the prefix's type is an access type, get to the real array type.
11596 -- Note: we do not apply an access check because an explicit dereference
11597 -- will be introduced later, and the check will happen there.
11599 if Is_Access_Type
(Array_Type
) then
11600 Array_Type
:= Implicitly_Designated_Type
(Array_Type
);
11602 -- If the prefix is an access to an unconstrained array, we must use
11603 -- the actual subtype of the object to perform the index checks. The
11604 -- object denoted by the prefix is implicit in the node, so we build
11605 -- an explicit representation for it in order to compute the actual
11608 if not Is_Constrained
(Array_Type
) then
11609 Remove_Side_Effects
(Pref
);
11612 Obj
: constant Node_Id
:=
11613 Make_Explicit_Dereference
(Sloc
(N
),
11614 Prefix
=> New_Copy_Tree
(Pref
));
11616 Set_Etype
(Obj
, Array_Type
);
11617 Set_Parent
(Obj
, Parent
(N
));
11618 Array_Type
:= Get_Actual_Subtype
(Obj
);
11622 -- In CodePeer mode the attribute Image is not expanded, so when it
11623 -- acts as a prefix of a slice, we handle it like a call to function
11624 -- returning an unconstrained string. Same for the Wide variants of
11625 -- attribute Image.
11627 elsif Is_Entity_Name
(Pref
)
11628 or else Nkind
(Pref
) = N_Explicit_Dereference
11629 or else (Nkind
(Pref
) = N_Function_Call
11630 and then not Is_Constrained
(Etype
(Pref
)))
11631 or else (CodePeer_Mode
11632 and then Nkind
(Pref
) = N_Attribute_Reference
11633 and then Attribute_Name
(Pref
) in Name_Image
11635 | Name_Wide_Wide_Image
)
11637 Array_Type
:= Get_Actual_Subtype
(Pref
);
11639 -- If the name is a selected component that depends on discriminants,
11640 -- build an actual subtype for it. This can happen only when the name
11641 -- itself is overloaded; otherwise the actual subtype is created when
11642 -- the selected component is analyzed.
11644 elsif Nkind
(Pref
) = N_Selected_Component
11645 and then Full_Analysis
11646 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
11649 Act_Decl
: constant Node_Id
:=
11650 Build_Actual_Subtype_Of_Component
(Array_Type
, Pref
);
11652 Insert_Action
(N
, Act_Decl
);
11653 Array_Type
:= Defining_Identifier
(Act_Decl
);
11656 -- Maybe this should just be "else", instead of checking for the
11657 -- specific case of slice??? This is needed for the case where the
11658 -- prefix is an Image attribute, which gets expanded to a slice, and so
11659 -- has a constrained subtype which we want to use for the slice range
11660 -- check applied below (the range check won't get done if the
11661 -- unconstrained subtype of the 'Image is used).
11663 elsif Nkind
(Pref
) = N_Slice
then
11664 Array_Type
:= Etype
(Pref
);
11667 -- Obtain the type of the array index
11669 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
11670 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
11672 Index_Type
:= Etype
(First_Index
(Array_Type
));
11675 -- If name was overloaded, set slice type correctly now
11677 Set_Etype
(N
, Array_Type
);
11679 -- Handle the generation of a range check that compares the array index
11680 -- against the discrete_range. The check is not applied to internally
11681 -- built nodes associated with the expansion of dispatch tables. Check
11682 -- that Ada.Tags has already been loaded to avoid extra dependencies on
11685 if Tagged_Type_Expansion
11686 and then RTU_Loaded
(Ada_Tags
)
11687 and then Nkind
(Pref
) = N_Selected_Component
11688 and then Present
(Entity
(Selector_Name
(Pref
)))
11689 and then Entity
(Selector_Name
(Pref
)) =
11690 RTE_Record_Component
(RE_Prims_Ptr
)
11694 -- The discrete_range is specified by a subtype name. Create an
11695 -- equivalent range attribute, apply checks to this attribute, but
11696 -- insert them into the range expression of the slice itself.
11698 elsif Is_Entity_Name
(Drange
) then
11700 Make_Attribute_Reference
11703 New_Occurrence_Of
(Entity
(Drange
), Sloc
(Drange
)),
11704 Attribute_Name
=> Name_Range
);
11706 Analyze_And_Resolve
(Dexpr
, Etype
(Drange
));
11708 elsif Nkind
(Drange
) = N_Subtype_Indication
then
11709 Dexpr
:= Range_Expression
(Constraint
(Drange
));
11711 -- The discrete_range is a regular range (or a range attribute, which
11712 -- will be resolved into a regular range). Resolve the bounds and remove
11713 -- their side effects.
11716 Resolve
(Drange
, Base_Type
(Index_Type
));
11718 if Nkind
(Drange
) = N_Range
then
11719 Force_Evaluation
(Low_Bound
(Drange
));
11720 Force_Evaluation
(High_Bound
(Drange
));
11726 if Present
(Dexpr
) then
11727 Apply_Range_Check
(Dexpr
, Index_Type
, Insert_Node
=> Drange
);
11730 Set_Slice_Subtype
(N
);
11732 -- Check bad use of type with predicates
11738 if Nkind
(Drange
) = N_Subtype_Indication
11739 and then Has_Predicates
(Entity
(Subtype_Mark
(Drange
)))
11741 Subt
:= Entity
(Subtype_Mark
(Drange
));
11743 Subt
:= Etype
(Drange
);
11746 if Has_Predicates
(Subt
) then
11747 Bad_Predicated_Subtype_Use
11748 ("subtype& has predicate, not allowed in slice", Drange
, Subt
);
11752 -- Otherwise here is where we check suspicious indexes
11754 if Nkind
(Drange
) = N_Range
then
11755 Warn_On_Suspicious_Index
(Pref
, Low_Bound
(Drange
));
11756 Warn_On_Suspicious_Index
(Pref
, High_Bound
(Drange
));
11759 Resolve_Implicit_Dereference
(Pref
);
11760 Analyze_Dimension
(N
);
11764 ----------------------------
11765 -- Resolve_String_Literal --
11766 ----------------------------
11768 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
11769 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
11770 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
11771 Loc
: constant Source_Ptr
:= Sloc
(N
);
11772 Str
: constant String_Id
:= Strval
(N
);
11773 Strlen
: constant Nat
:= String_Length
(Str
);
11774 Subtype_Id
: Entity_Id
;
11775 Need_Check
: Boolean;
11778 -- For a string appearing in a concatenation, defer creation of the
11779 -- string_literal_subtype until the end of the resolution of the
11780 -- concatenation, because the literal may be constant-folded away. This
11781 -- is a useful optimization for long concatenation expressions.
11783 -- If the string is an aggregate built for a single character (which
11784 -- happens in a non-static context) or a is null string to which special
11785 -- checks may apply, we build the subtype. Wide strings must also get a
11786 -- string subtype if they come from a one character aggregate. Strings
11787 -- generated by attributes might be static, but it is often hard to
11788 -- determine whether the enclosing context is static, so we generate
11789 -- subtypes for them as well, thus losing some rarer optimizations ???
11790 -- Same for strings that come from a static conversion.
11793 (Strlen
= 0 and then Typ
/= Standard_String
)
11794 or else Nkind
(Parent
(N
)) /= N_Op_Concat
11795 or else (N
/= Left_Opnd
(Parent
(N
))
11796 and then N
/= Right_Opnd
(Parent
(N
)))
11797 or else ((Typ
= Standard_Wide_String
11798 or else Typ
= Standard_Wide_Wide_String
)
11799 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
11801 -- If the resolving type is itself a string literal subtype, we can just
11802 -- reuse it, since there is no point in creating another.
11804 if Ekind
(Typ
) = E_String_Literal_Subtype
then
11807 elsif Nkind
(Parent
(N
)) = N_Op_Concat
11808 and then not Need_Check
11809 and then Nkind
(Original_Node
(N
)) not in N_Character_Literal
11810 | N_Attribute_Reference
11811 | N_Qualified_Expression
11812 | N_Type_Conversion
11816 -- Do not generate a string literal subtype for the default expression
11817 -- of a formal parameter in GNATprove mode. This is because the string
11818 -- subtype is associated with the freezing actions of the subprogram,
11819 -- however freezing is disabled in GNATprove mode and as a result the
11820 -- subtype is unavailable.
11822 elsif GNATprove_Mode
11823 and then Nkind
(Parent
(N
)) = N_Parameter_Specification
11827 -- Otherwise we must create a string literal subtype. Note that the
11828 -- whole idea of string literal subtypes is simply to avoid the need
11829 -- for building a full fledged array subtype for each literal.
11832 Set_String_Literal_Subtype
(N
, Typ
);
11833 Subtype_Id
:= Etype
(N
);
11836 if Nkind
(Parent
(N
)) /= N_Op_Concat
11839 Set_Etype
(N
, Subtype_Id
);
11840 Eval_String_Literal
(N
);
11843 if Is_Limited_Composite
(Typ
)
11844 or else Is_Private_Composite
(Typ
)
11846 Error_Msg_N
("string literal not available for private array", N
);
11847 Set_Etype
(N
, Any_Type
);
11851 -- The validity of a null string has been checked in the call to
11852 -- Eval_String_Literal.
11857 -- Always accept string literal with component type Any_Character, which
11858 -- occurs in error situations and in comparisons of literals, both of
11859 -- which should accept all literals.
11861 elsif R_Typ
= Any_Character
then
11864 -- If the type is bit-packed, then we always transform the string
11865 -- literal into a full fledged aggregate.
11867 elsif Is_Bit_Packed_Array
(Typ
) then
11870 -- Deal with cases of Wide_Wide_String, Wide_String, and String
11873 -- For Standard.Wide_Wide_String, or any other type whose component
11874 -- type is Standard.Wide_Wide_Character, we know that all the
11875 -- characters in the string must be acceptable, since the parser
11876 -- accepted the characters as valid character literals.
11878 if R_Typ
= Standard_Wide_Wide_Character
then
11881 -- For the case of Standard.String, or any other type whose component
11882 -- type is Standard.Character, we must make sure that there are no
11883 -- wide characters in the string, i.e. that it is entirely composed
11884 -- of characters in range of type Character.
11886 -- If the string literal is the result of a static concatenation, the
11887 -- test has already been performed on the components, and need not be
11890 elsif R_Typ
= Standard_Character
11891 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
11893 for J
in 1 .. Strlen
loop
11894 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
11896 -- If we are out of range, post error. This is one of the
11897 -- very few places that we place the flag in the middle of
11898 -- a token, right under the offending wide character. Not
11899 -- quite clear if this is right wrt wide character encoding
11900 -- sequences, but it's only an error message.
11903 ("literal out of range of type Standard.Character",
11904 Loc
+ Source_Ptr
(J
));
11909 -- For the case of Standard.Wide_String, or any other type whose
11910 -- component type is Standard.Wide_Character, we must make sure that
11911 -- there are no wide characters in the string, i.e. that it is
11912 -- entirely composed of characters in range of type Wide_Character.
11914 -- If the string literal is the result of a static concatenation,
11915 -- the test has already been performed on the components, and need
11916 -- not be repeated.
11918 elsif R_Typ
= Standard_Wide_Character
11919 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
11921 for J
in 1 .. Strlen
loop
11922 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
11924 -- If we are out of range, post error. This is one of the
11925 -- very few places that we place the flag in the middle of
11926 -- a token, right under the offending wide character.
11928 -- This is not quite right, because characters in general
11929 -- will take more than one character position ???
11932 ("literal out of range of type Standard.Wide_Character",
11933 Loc
+ Source_Ptr
(J
));
11938 -- If the root type is not a standard character, then we will convert
11939 -- the string into an aggregate and will let the aggregate code do
11940 -- the checking. Standard Wide_Wide_Character is also OK here.
11946 -- See if the component type of the array corresponding to the string
11947 -- has compile time known bounds. If yes we can directly check
11948 -- whether the evaluation of the string will raise constraint error.
11949 -- Otherwise we need to transform the string literal into the
11950 -- corresponding character aggregate and let the aggregate code do
11951 -- the checking. We use the same transformation if the component
11952 -- type has a static predicate, which will be applied to each
11953 -- character when the aggregate is resolved.
11955 if Is_Standard_Character_Type
(R_Typ
) then
11957 -- Check for the case of full range, where we are definitely OK
11959 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
11963 -- Here the range is not the complete base type range, so check
11966 Comp_Typ_Lo
: constant Node_Id
:=
11967 Type_Low_Bound
(Component_Type
(Typ
));
11968 Comp_Typ_Hi
: constant Node_Id
:=
11969 Type_High_Bound
(Component_Type
(Typ
));
11974 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
11975 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
11977 for J
in 1 .. Strlen
loop
11978 Char_Val
:= UI_From_CC
(Get_String_Char
(Str
, J
));
11980 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
11981 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
11983 Apply_Compile_Time_Constraint_Error
11984 (N
, "character out of range??",
11985 CE_Range_Check_Failed
,
11986 Loc
=> Loc
+ Source_Ptr
(J
));
11990 if not Has_Static_Predicate
(C_Typ
) then
11998 -- If we got here we meed to transform the string literal into the
11999 -- equivalent qualified positional array aggregate. This is rather
12000 -- heavy artillery for this situation, but it is hard work to avoid.
12003 Lits
: constant List_Id
:= New_List
;
12004 P
: Source_Ptr
:= Loc
+ 1;
12008 -- Build the character literals, we give them source locations that
12009 -- correspond to the string positions, which is a bit tricky given
12010 -- the possible presence of wide character escape sequences.
12012 for J
in 1 .. Strlen
loop
12013 C
:= Get_String_Char
(Str
, J
);
12014 Set_Character_Literal_Name
(C
);
12017 Make_Character_Literal
(P
,
12018 Chars
=> Name_Find
,
12019 Char_Literal_Value
=> UI_From_CC
(C
)));
12021 if In_Character_Range
(C
) then
12024 -- Should we have a call to Skip_Wide here ???
12033 Make_Qualified_Expression
(Loc
,
12034 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
12036 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
12038 Analyze_And_Resolve
(N
, Typ
);
12040 end Resolve_String_Literal
;
12042 -------------------------
12043 -- Resolve_Target_Name --
12044 -------------------------
12046 procedure Resolve_Target_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
12048 Set_Etype
(N
, Typ
);
12049 end Resolve_Target_Name
;
12051 -----------------------------
12052 -- Resolve_Type_Conversion --
12053 -----------------------------
12055 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
12056 Conv_OK
: constant Boolean := Conversion_OK
(N
);
12057 Operand
: constant Node_Id
:= Expression
(N
);
12058 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
12059 Target_Typ
: constant Entity_Id
:= Etype
(N
);
12064 Test_Redundant
: Boolean := Warn_On_Redundant_Constructs
;
12065 -- Set to False to suppress cases where we want to suppress the test
12066 -- for redundancy to avoid possible false positives on this warning.
12070 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
12075 -- If the Operand Etype is Universal_Fixed, then the conversion is
12076 -- never redundant. We need this check because by the time we have
12077 -- finished the rather complex transformation, the conversion looks
12078 -- redundant when it is not.
12080 if Operand_Typ
= Universal_Fixed
then
12081 Test_Redundant
:= False;
12083 -- If the operand is marked as Any_Fixed, then special processing is
12084 -- required. This is also a case where we suppress the test for a
12085 -- redundant conversion, since most certainly it is not redundant.
12087 elsif Operand_Typ
= Any_Fixed
then
12088 Test_Redundant
:= False;
12090 -- Mixed-mode operation involving a literal. Context must be a fixed
12091 -- type which is applied to the literal subsequently.
12093 -- Multiplication and division involving two fixed type operands must
12094 -- yield a universal real because the result is computed in arbitrary
12097 if Is_Fixed_Point_Type
(Typ
)
12098 and then Nkind
(Operand
) in N_Op_Divide | N_Op_Multiply
12099 and then Etype
(Left_Opnd
(Operand
)) = Any_Fixed
12100 and then Etype
(Right_Opnd
(Operand
)) = Any_Fixed
12102 Set_Etype
(Operand
, Universal_Real
);
12104 elsif Is_Numeric_Type
(Typ
)
12105 and then Nkind
(Operand
) in N_Op_Multiply | N_Op_Divide
12106 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
12108 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
12110 -- Return if expression is ambiguous
12112 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
12115 -- If nothing else, the available fixed type is Duration
12118 Set_Etype
(Operand
, Standard_Duration
);
12121 -- Resolve the real operand with largest available precision
12123 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
12124 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
12126 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
12129 Resolve
(Rop
, Universal_Real
);
12131 -- If the operand is a literal (it could be a non-static and
12132 -- illegal exponentiation) check whether the use of Duration
12133 -- is potentially inaccurate.
12135 if Nkind
(Rop
) = N_Real_Literal
12136 and then Realval
(Rop
) /= Ureal_0
12137 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
12140 ("??universal real operand can only "
12141 & "be interpreted as Duration!", Rop
);
12143 ("\??precision will be lost in the conversion!", Rop
);
12146 elsif Is_Numeric_Type
(Typ
)
12147 and then Nkind
(Operand
) in N_Op
12148 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
12150 Set_Etype
(Operand
, Standard_Duration
);
12153 Error_Msg_N
("invalid context for mixed mode operation", N
);
12154 Set_Etype
(Operand
, Any_Type
);
12161 Analyze_Dimension
(N
);
12163 -- Note: we do the Eval_Type_Conversion call before applying the
12164 -- required checks for a subtype conversion. This is important, since
12165 -- both are prepared under certain circumstances to change the type
12166 -- conversion to a constraint error node, but in the case of
12167 -- Eval_Type_Conversion this may reflect an illegality in the static
12168 -- case, and we would miss the illegality (getting only a warning
12169 -- message), if we applied the type conversion checks first.
12171 Eval_Type_Conversion
(N
);
12173 -- Even when evaluation is not possible, we may be able to simplify the
12174 -- conversion or its expression. This needs to be done before applying
12175 -- checks, since otherwise the checks may use the original expression
12176 -- and defeat the simplifications. This is specifically the case for
12177 -- elimination of the floating-point Truncation attribute in
12178 -- float-to-int conversions.
12180 Simplify_Type_Conversion
(N
);
12182 -- If after evaluation we still have a type conversion, then we may need
12183 -- to apply checks required for a subtype conversion. But skip them if
12184 -- universal fixed operands are involved, since range checks are handled
12185 -- separately for these cases, after the expansion done by Exp_Fixd.
12187 if Nkind
(N
) = N_Type_Conversion
12188 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
12189 and then Target_Typ
/= Universal_Fixed
12190 and then Etype
(Operand
) /= Universal_Fixed
12192 Apply_Type_Conversion_Checks
(N
);
12195 -- Issue warning for conversion of simple object to its own type. We
12196 -- have to test the original nodes, since they may have been rewritten
12197 -- by various optimizations.
12199 Orig_N
:= Original_Node
(N
);
12201 -- Here we test for a redundant conversion if the warning mode is
12202 -- active (and was not locally reset), and we have a type conversion
12203 -- from source not appearing in a generic instance.
12206 and then Nkind
(Orig_N
) = N_Type_Conversion
12207 and then Comes_From_Source
(Orig_N
)
12208 and then not In_Instance
12210 Orig_N
:= Original_Node
(Expression
(Orig_N
));
12211 Orig_T
:= Target_Typ
;
12213 -- If the node is part of a larger expression, the Target_Type
12214 -- may not be the original type of the node if the context is a
12215 -- condition. Recover original type to see if conversion is needed.
12217 if Is_Boolean_Type
(Orig_T
)
12218 and then Nkind
(Parent
(N
)) in N_Op
12220 Orig_T
:= Etype
(Parent
(N
));
12223 -- If we have an entity name, then give the warning if the entity
12224 -- is the right type, or if it is a loop parameter covered by the
12225 -- original type (that's needed because loop parameters have an
12226 -- odd subtype coming from the bounds).
12228 if (Is_Entity_Name
(Orig_N
)
12229 and then Present
(Entity
(Orig_N
))
12231 (Etype
(Entity
(Orig_N
)) = Orig_T
12233 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
12234 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
))))))
12236 -- If not an entity, then type of expression must match
12238 or else Etype
(Orig_N
) = Orig_T
12240 -- One more check, do not give warning if the analyzed conversion
12241 -- has an expression with non-static bounds, and the bounds of the
12242 -- target are static. This avoids junk warnings in cases where the
12243 -- conversion is necessary to establish staticness, for example in
12244 -- a case statement.
12246 if not Is_OK_Static_Subtype
(Operand_Typ
)
12247 and then Is_OK_Static_Subtype
(Target_Typ
)
12251 -- Never give a warning if the operand is a conditional expression
12252 -- because RM 4.5.7(10/3) forces its type to be the target type.
12254 elsif Nkind
(Orig_N
) in N_Case_Expression | N_If_Expression
then
12257 -- Finally, if this type conversion occurs in a context requiring
12258 -- a prefix, and the expression is a qualified expression then the
12259 -- type conversion is not redundant, since a qualified expression
12260 -- is not a prefix, whereas a type conversion is. For example, "X
12261 -- := T'(Funx(...)).Y;" is illegal because a selected component
12262 -- requires a prefix, but a type conversion makes it legal: "X :=
12263 -- T(T'(Funx(...))).Y;"
12265 -- In Ada 2012, a qualified expression is a name, so this idiom is
12266 -- no longer needed, but we still suppress the warning because it
12267 -- seems unfriendly for warnings to pop up when you switch to the
12268 -- newer language version.
12270 elsif Nkind
(Orig_N
) = N_Qualified_Expression
12271 and then Nkind
(Parent
(N
)) in N_Attribute_Reference
12272 | N_Indexed_Component
12273 | N_Selected_Component
12275 | N_Explicit_Dereference
12279 -- Never warn on conversion to Long_Long_Integer'Base since
12280 -- that is most likely an artifact of the extended overflow
12281 -- checking and comes from complex expanded code.
12283 elsif Orig_T
= Base_Type
(Standard_Long_Long_Integer
) then
12286 -- Do not warn on conversion to class-wide type on helpers of
12287 -- class-wide preconditions because in this context the warning
12288 -- would be spurious (since the class-wide precondition has been
12289 -- installed in the return statement of the helper, which has a
12290 -- class-wide formal type instead of a regular tagged type).
12292 elsif Is_Class_Wide_Type
(Orig_T
)
12293 and then Is_Subprogram_Or_Generic_Subprogram
(Current_Scope
)
12294 and then Present
(Class_Preconditions_Subprogram
(Current_Scope
))
12298 -- Here we give the redundant conversion warning. If it is an
12299 -- entity, give the name of the entity in the message. If not,
12300 -- just mention the expression.
12303 if Is_Entity_Name
(Orig_N
) then
12304 Error_Msg_Node_2
:= Orig_T
;
12305 Error_Msg_NE
-- CODEFIX
12306 ("?r?redundant conversion, & is of type &!",
12307 N
, Entity
(Orig_N
));
12310 ("?r?redundant conversion, expression is of type&!",
12317 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
12318 -- No need to perform any interface conversion if the type of the
12319 -- expression coincides with the target type.
12321 if Ada_Version
>= Ada_2005
12322 and then Expander_Active
12323 and then Operand_Typ
/= Target_Typ
12326 Opnd
: Entity_Id
:= Operand_Typ
;
12327 Target
: Entity_Id
:= Target_Typ
;
12330 -- If the type of the operand is a limited view, use nonlimited
12331 -- view when available. If it is a class-wide type, recover the
12332 -- class-wide type of the nonlimited view.
12334 if From_Limited_With
(Opnd
)
12335 and then Has_Non_Limited_View
(Opnd
)
12337 Opnd
:= Non_Limited_View
(Opnd
);
12338 Set_Etype
(Expression
(N
), Opnd
);
12341 -- It seems that Non_Limited_View should also be applied for
12342 -- Target when it has a limited view, but that leads to missing
12343 -- error checks on interface conversions further below. ???
12345 if Is_Access_Type
(Opnd
) then
12346 Opnd
:= Designated_Type
(Opnd
);
12348 -- If the type of the operand is a limited view, use nonlimited
12349 -- view when available. If it is a class-wide type, recover the
12350 -- class-wide type of the nonlimited view.
12352 if From_Limited_With
(Opnd
)
12353 and then Has_Non_Limited_View
(Opnd
)
12355 Opnd
:= Non_Limited_View
(Opnd
);
12359 if Is_Access_Type
(Target_Typ
) then
12360 Target
:= Designated_Type
(Target
);
12362 -- If the target type is a limited view, use nonlimited view
12365 if From_Limited_With
(Target
)
12366 and then Has_Non_Limited_View
(Target
)
12368 Target
:= Non_Limited_View
(Target
);
12372 if Opnd
= Target
then
12375 -- Conversion from interface type
12377 -- It seems that it would be better for the error checks below
12378 -- to be performed as part of Validate_Conversion (and maybe some
12379 -- of the error checks above could be moved as well?). ???
12381 elsif Is_Interface
(Opnd
) then
12383 -- Ada 2005 (AI-217): Handle entities from limited views
12385 if From_Limited_With
(Opnd
) then
12386 Error_Msg_Qual_Level
:= 99;
12387 Error_Msg_NE
-- CODEFIX
12388 ("missing WITH clause on package &", N
,
12389 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
12391 ("type conversions require visibility of the full view",
12394 elsif From_Limited_With
(Target
)
12396 (Is_Access_Type
(Target_Typ
)
12397 and then Present
(Non_Limited_View
(Etype
(Target
))))
12399 Error_Msg_Qual_Level
:= 99;
12400 Error_Msg_NE
-- CODEFIX
12401 ("missing WITH clause on package &", N
,
12402 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
12404 ("type conversions require visibility of the full view",
12408 Expand_Interface_Conversion
(N
);
12411 -- Conversion to interface type
12413 elsif Is_Interface
(Target
) then
12414 Expand_Interface_Conversion
(N
);
12419 -- Ada 2012: Once the type conversion is resolved, check whether the
12420 -- operand satisfies a static predicate of the target subtype, if any.
12421 -- In the static expression case, a predicate check failure is an error.
12423 if Has_Predicates
(Target_Typ
) then
12424 Check_Expression_Against_Static_Predicate
12425 (N
, Target_Typ
, Static_Failure_Is_Error
=> True);
12428 -- If at this stage we have a fixed to integer conversion, make sure the
12429 -- Do_Range_Check flag is set, because such conversions in general need
12430 -- a range check. We only need this if expansion is off, see above why.
12432 if Nkind
(N
) = N_Type_Conversion
12433 and then not Expander_Active
12434 and then Is_Integer_Type
(Target_Typ
)
12435 and then Is_Fixed_Point_Type
(Operand_Typ
)
12436 and then not Range_Checks_Suppressed
(Target_Typ
)
12437 and then not Range_Checks_Suppressed
(Operand_Typ
)
12439 Set_Do_Range_Check
(Operand
);
12442 -- Generating C code a type conversion of an access to constrained
12443 -- array type to access to unconstrained array type involves building
12444 -- a fat pointer which in general cannot be generated on the fly. We
12445 -- remove side effects in order to store the result of the conversion
12446 -- into a temporary.
12448 if Modify_Tree_For_C
12449 and then Nkind
(N
) = N_Type_Conversion
12450 and then Nkind
(Parent
(N
)) /= N_Object_Declaration
12451 and then Is_Access_Type
(Etype
(N
))
12452 and then Is_Array_Type
(Designated_Type
(Etype
(N
)))
12453 and then not Is_Constrained
(Designated_Type
(Etype
(N
)))
12454 and then Is_Constrained
(Designated_Type
(Etype
(Expression
(N
))))
12456 Remove_Side_Effects
(N
);
12458 end Resolve_Type_Conversion
;
12460 ----------------------
12461 -- Resolve_Unary_Op --
12462 ----------------------
12464 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
12465 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
12466 R
: constant Node_Id
:= Right_Opnd
(N
);
12472 -- Deal with intrinsic unary operators
12474 if Comes_From_Source
(N
)
12475 and then Ekind
(Entity
(N
)) = E_Function
12476 and then Is_Imported
(Entity
(N
))
12477 and then Is_Intrinsic_Subprogram
(Entity
(N
))
12479 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
12483 -- Deal with universal cases
12485 if Is_Universal_Numeric_Type
(Etype
(R
)) then
12486 Check_For_Visible_Operator
(N
, B_Typ
);
12489 Set_Etype
(N
, B_Typ
);
12490 Resolve
(R
, B_Typ
);
12492 -- Generate warning for negative literal of a modular type, unless it is
12493 -- enclosed directly in a type qualification or a type conversion, as it
12494 -- is likely not what the user intended. We don't issue the warning for
12495 -- the common use of -1 to denote OxFFFF_FFFF...
12497 if Warn_On_Suspicious_Modulus_Value
12498 and then Nkind
(N
) = N_Op_Minus
12499 and then Nkind
(R
) = N_Integer_Literal
12500 and then Comes_From_Source
(R
)
12501 and then Is_Modular_Integer_Type
(B_Typ
)
12502 and then Nkind
(Parent
(N
)) not in N_Qualified_Expression
12503 | N_Type_Conversion
12504 and then Expr_Value
(R
) > Uint_1
12507 ("?.m?negative literal of modular type is in fact positive", N
);
12508 Error_Msg_Uint_1
:= (-Expr_Value
(R
)) mod Modulus
(B_Typ
);
12509 Error_Msg_Uint_2
:= Expr_Value
(R
);
12510 Error_Msg_N
("\do you really mean^ when writing -^ '?", N
);
12512 ("\if you do, use qualification to avoid this warning", N
);
12515 -- Generate warning for expressions like abs (x mod 2)
12517 if Warn_On_Redundant_Constructs
12518 and then Nkind
(N
) = N_Op_Abs
12520 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
12522 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
12523 Error_Msg_N
-- CODEFIX
12524 ("?r?abs applied to known non-negative value has no effect", N
);
12528 -- Deal with reference generation
12530 Check_Unset_Reference
(R
);
12531 Generate_Operator_Reference
(N
, B_Typ
);
12532 Analyze_Dimension
(N
);
12535 -- Set overflow checking bit. Much cleverer code needed here eventually
12536 -- and perhaps the Resolve routines should be separated for the various
12537 -- arithmetic operations, since they will need different processing ???
12539 if Nkind
(N
) in N_Op
then
12540 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
12541 Enable_Overflow_Check
(N
);
12545 -- Generate warning for expressions like -5 mod 3 for integers. No need
12546 -- to worry in the floating-point case, since parens do not affect the
12547 -- result so there is no point in giving in a warning.
12550 Norig
: constant Node_Id
:= Original_Node
(N
);
12559 if Warn_On_Questionable_Missing_Parens
12560 and then Comes_From_Source
(Norig
)
12561 and then Is_Integer_Type
(Typ
)
12562 and then Nkind
(Norig
) = N_Op_Minus
12564 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
12566 -- We are looking for cases where the right operand is not
12567 -- parenthesized, and is a binary operator, multiply, divide, or
12568 -- mod. These are the cases where the grouping can affect results.
12570 if Paren_Count
(Rorig
) = 0
12571 and then Nkind
(Rorig
) in N_Op_Mod | N_Op_Multiply | N_Op_Divide
12573 -- For mod, we always give the warning, since the value is
12574 -- affected by the parenthesization (e.g. (-5) mod 315 /=
12575 -- -(5 mod 315)). But for the other cases, the only concern is
12576 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
12577 -- overflows, but (-2) * 64 does not). So we try to give the
12578 -- message only when overflow is possible.
12580 if Nkind
(Rorig
) /= N_Op_Mod
12581 and then Compile_Time_Known_Value
(R
)
12583 Val
:= Expr_Value
(R
);
12585 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
12586 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
12588 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
12591 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
12592 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
12594 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
12597 -- Note that the test below is deliberately excluding the
12598 -- largest negative number, since that is a potentially
12599 -- troublesome case (e.g. -2 * x, where the result is the
12600 -- largest negative integer has an overflow with 2 * x).
12602 if Val
> LB
and then Val
<= HB
then
12607 -- For the multiplication case, the only case we have to worry
12608 -- about is when (-a)*b is exactly the largest negative number
12609 -- so that -(a*b) can cause overflow. This can only happen if
12610 -- a is a power of 2, and more generally if any operand is a
12611 -- constant that is not a power of 2, then the parentheses
12612 -- cannot affect whether overflow occurs. We only bother to
12613 -- test the left most operand
12615 -- Loop looking at left operands for one that has known value
12618 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
12619 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
12620 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
12622 -- Operand value of 0 or 1 skips warning
12627 -- Otherwise check power of 2, if power of 2, warn, if
12628 -- anything else, skip warning.
12631 while Lval
/= 2 loop
12632 if Lval
mod 2 = 1 then
12643 -- Keep looking at left operands
12645 Opnd
:= Left_Opnd
(Opnd
);
12646 end loop Opnd_Loop
;
12648 -- For rem or "/" we can only have a problematic situation
12649 -- if the divisor has a value of minus one or one. Otherwise
12650 -- overflow is impossible (divisor > 1) or we have a case of
12651 -- division by zero in any case.
12653 if Nkind
(Rorig
) in N_Op_Divide | N_Op_Rem
12654 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
12655 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
12660 -- If we fall through warning should be issued
12662 -- Shouldn't we test Warn_On_Questionable_Missing_Parens ???
12665 ("??unary minus expression should be parenthesized here!", N
);
12669 end Resolve_Unary_Op
;
12671 ----------------------------------
12672 -- Resolve_Unchecked_Expression --
12673 ----------------------------------
12675 procedure Resolve_Unchecked_Expression
12680 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
12681 Set_Etype
(N
, Typ
);
12682 end Resolve_Unchecked_Expression
;
12684 ---------------------------------------
12685 -- Resolve_Unchecked_Type_Conversion --
12686 ---------------------------------------
12688 procedure Resolve_Unchecked_Type_Conversion
12692 pragma Warnings
(Off
, Typ
);
12694 Operand
: constant Node_Id
:= Expression
(N
);
12695 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
12698 -- Resolve operand using its own type
12700 Resolve
(Operand
, Opnd_Type
);
12702 -- If the expression is a conversion to universal integer of an
12703 -- an expression with an integer type, then we can eliminate the
12704 -- intermediate conversion to universal integer.
12706 if Nkind
(Operand
) = N_Type_Conversion
12707 and then Entity
(Subtype_Mark
(Operand
)) = Universal_Integer
12708 and then Is_Integer_Type
(Etype
(Expression
(Operand
)))
12710 Rewrite
(Operand
, Relocate_Node
(Expression
(Operand
)));
12711 Analyze_And_Resolve
(Operand
);
12714 -- In an inlined context, the unchecked conversion may be applied
12715 -- to a literal, in which case its type is the type of the context.
12716 -- (In other contexts conversions cannot apply to literals).
12719 and then (Opnd_Type
= Any_Character
or else
12720 Opnd_Type
= Any_Integer
or else
12721 Opnd_Type
= Any_Real
)
12723 Set_Etype
(Operand
, Typ
);
12726 Analyze_Dimension
(N
);
12727 Eval_Unchecked_Conversion
(N
);
12728 end Resolve_Unchecked_Type_Conversion
;
12730 ------------------------------
12731 -- Rewrite_Operator_As_Call --
12732 ------------------------------
12734 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
12735 Loc
: constant Source_Ptr
:= Sloc
(N
);
12736 Actuals
: constant List_Id
:= New_List
;
12740 if Nkind
(N
) in N_Binary_Op
then
12741 Append
(Left_Opnd
(N
), Actuals
);
12744 Append
(Right_Opnd
(N
), Actuals
);
12747 Make_Function_Call
(Sloc
=> Loc
,
12748 Name
=> New_Occurrence_Of
(Nam
, Loc
),
12749 Parameter_Associations
=> Actuals
);
12751 Preserve_Comes_From_Source
(New_N
, N
);
12752 Preserve_Comes_From_Source
(Name
(New_N
), N
);
12753 Rewrite
(N
, New_N
);
12754 Set_Etype
(N
, Etype
(Nam
));
12755 end Rewrite_Operator_As_Call
;
12757 ------------------------------
12758 -- Rewrite_Renamed_Operator --
12759 ------------------------------
12761 procedure Rewrite_Renamed_Operator
12766 Nam
: constant Name_Id
:= Chars
(Op
);
12767 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
12771 -- Do not perform this transformation within a pre/postcondition,
12772 -- because the expression will be reanalyzed, and the transformation
12773 -- might affect the visibility of the operator, e.g. in an instance.
12774 -- Note that fully analyzed and expanded pre/postconditions appear as
12775 -- pragma Check equivalents.
12777 if In_Pre_Post_Condition
(N
) then
12781 -- Likewise when an expression function is being preanalyzed, since the
12782 -- expression will be reanalyzed as part of the generated body.
12784 if In_Spec_Expression
then
12786 S
: constant Entity_Id
:= Current_Scope_No_Loops
;
12788 if Ekind
(S
) = E_Function
12789 and then Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
12790 N_Expression_Function
12797 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
12798 Set_Chars
(Op_Node
, Nam
);
12799 Set_Etype
(Op_Node
, Etype
(N
));
12800 Set_Entity
(Op_Node
, Op
);
12801 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
12804 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
12807 -- Indicate that both the original entity and its renaming are
12808 -- referenced at this point.
12810 Generate_Reference
(Entity
(N
), N
);
12811 Generate_Reference
(Op
, N
);
12813 Rewrite
(N
, Op_Node
);
12815 -- If the context type is private, add the appropriate conversions so
12816 -- that the operator is applied to the full view. This is done in the
12817 -- routines that resolve intrinsic operators.
12819 if Is_Intrinsic_Subprogram
(Op
) and then Is_Private_Type
(Typ
) then
12829 Resolve_Intrinsic_Operator
(N
, Typ
);
12835 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
12841 end Rewrite_Renamed_Operator
;
12843 -----------------------
12844 -- Set_Slice_Subtype --
12845 -----------------------
12847 -- Build an implicit subtype declaration to represent the type delivered by
12848 -- the slice. This is an abbreviated version of an array subtype. We define
12849 -- an index subtype for the slice, using either the subtype name or the
12850 -- discrete range of the slice. To be consistent with index usage elsewhere
12851 -- we create a list header to hold the single index. This list is not
12852 -- otherwise attached to the syntax tree.
12854 procedure Set_Slice_Subtype
(N
: Node_Id
) is
12855 Loc
: constant Source_Ptr
:= Sloc
(N
);
12856 Index_List
: constant List_Id
:= New_List
;
12858 Index_Subtype
: Entity_Id
;
12859 Index_Type
: Entity_Id
;
12860 Slice_Subtype
: Entity_Id
;
12861 Drange
: constant Node_Id
:= Discrete_Range
(N
);
12864 Index_Type
:= Base_Type
(Etype
(Drange
));
12866 if Is_Entity_Name
(Drange
) then
12867 Index_Subtype
:= Entity
(Drange
);
12870 -- We force the evaluation of a range. This is definitely needed in
12871 -- the renamed case, and seems safer to do unconditionally. Note in
12872 -- any case that since we will create and insert an Itype referring
12873 -- to this range, we must make sure any side effect removal actions
12874 -- are inserted before the Itype definition.
12876 if Nkind
(Drange
) = N_Range
then
12877 Force_Evaluation
(Low_Bound
(Drange
));
12878 Force_Evaluation
(High_Bound
(Drange
));
12880 -- If the discrete range is given by a subtype indication, the
12881 -- type of the slice is the base of the subtype mark.
12883 elsif Nkind
(Drange
) = N_Subtype_Indication
then
12885 R
: constant Node_Id
:= Range_Expression
(Constraint
(Drange
));
12887 Index_Type
:= Base_Type
(Entity
(Subtype_Mark
(Drange
)));
12888 Force_Evaluation
(Low_Bound
(R
));
12889 Force_Evaluation
(High_Bound
(R
));
12893 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
12895 -- Take a new copy of Drange (where bounds have been rewritten to
12896 -- reference side-effect-free names). Using a separate tree ensures
12897 -- that further expansion (e.g. while rewriting a slice assignment
12898 -- into a FOR loop) does not attempt to remove side effects on the
12899 -- bounds again (which would cause the bounds in the index subtype
12900 -- definition to refer to temporaries before they are defined) (the
12901 -- reason is that some names are considered side effect free here
12902 -- for the subtype, but not in the context of a loop iteration
12905 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
12906 Set_Parent
(Scalar_Range
(Index_Subtype
), Index_Subtype
);
12907 Set_Etype
(Index_Subtype
, Index_Type
);
12908 Set_Size_Info
(Index_Subtype
, Index_Type
);
12909 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
12910 Set_Is_Constrained
(Index_Subtype
);
12913 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
12915 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
12916 Set_Etype
(Index
, Index_Subtype
);
12917 Append
(Index
, Index_List
);
12919 Set_First_Index
(Slice_Subtype
, Index
);
12920 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
12921 Set_Is_Constrained
(Slice_Subtype
, True);
12923 Check_Compile_Time_Size
(Slice_Subtype
);
12925 -- The Etype of the existing Slice node is reset to this slice subtype.
12926 -- Its bounds are obtained from its first index.
12928 Set_Etype
(N
, Slice_Subtype
);
12930 -- For bit-packed slice subtypes, freeze immediately (except in the case
12931 -- of being in a "spec expression" where we never freeze when we first
12932 -- see the expression).
12934 if Is_Bit_Packed_Array
(Slice_Subtype
) and not In_Spec_Expression
then
12935 Freeze_Itype
(Slice_Subtype
, N
);
12937 -- For all other cases insert an itype reference in the slice's actions
12938 -- so that the itype is frozen at the proper place in the tree (i.e. at
12939 -- the point where actions for the slice are analyzed). Note that this
12940 -- is different from freezing the itype immediately, which might be
12941 -- premature (e.g. if the slice is within a transient scope). This needs
12942 -- to be done only if expansion is enabled.
12944 elsif Expander_Active
then
12945 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
12947 end Set_Slice_Subtype
;
12949 --------------------------------
12950 -- Set_String_Literal_Subtype --
12951 --------------------------------
12953 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
12954 Loc
: constant Source_Ptr
:= Sloc
(N
);
12955 Low_Bound
: constant Node_Id
:=
12956 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
12957 Subtype_Id
: Entity_Id
;
12960 if Nkind
(N
) /= N_String_Literal
then
12964 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
12965 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
12966 (String_Length
(Strval
(N
))));
12967 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
12968 Set_Is_Constrained
(Subtype_Id
);
12969 Set_Etype
(N
, Subtype_Id
);
12971 -- The low bound is set from the low bound of the corresponding index
12972 -- type. Note that we do not store the high bound in the string literal
12973 -- subtype, but it can be deduced if necessary from the length and the
12976 if Is_OK_Static_Expression
(Low_Bound
) then
12977 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
12979 -- If the lower bound is not static we create a range for the string
12980 -- literal, using the index type and the known length of the literal.
12981 -- If the length is 1, then the upper bound is set to a mere copy of
12982 -- the lower bound; or else, if the index type is a signed integer,
12983 -- then the upper bound is computed as Low_Bound + L - 1; otherwise,
12984 -- the upper bound is computed as T'Val (T'Pos (Low_Bound) + L - 1).
12988 Length
: constant Nat
:= String_Length
(Strval
(N
));
12989 Index_List
: constant List_Id
:= New_List
;
12990 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
12991 Array_Subtype
: Entity_Id
;
12993 High_Bound
: Node_Id
;
12995 Index_Subtype
: Entity_Id
;
12999 High_Bound
:= New_Copy_Tree
(Low_Bound
);
13001 elsif Is_Signed_Integer_Type
(Index_Type
) then
13004 Left_Opnd
=> New_Copy_Tree
(Low_Bound
),
13005 Right_Opnd
=> Make_Integer_Literal
(Loc
, Length
- 1));
13009 Make_Attribute_Reference
(Loc
,
13010 Attribute_Name
=> Name_Val
,
13012 New_Occurrence_Of
(Index_Type
, Loc
),
13013 Expressions
=> New_List
(
13016 Make_Attribute_Reference
(Loc
,
13017 Attribute_Name
=> Name_Pos
,
13019 New_Occurrence_Of
(Index_Type
, Loc
),
13021 New_List
(New_Copy_Tree
(Low_Bound
))),
13023 Make_Integer_Literal
(Loc
, Length
- 1))));
13026 if Is_Integer_Type
(Index_Type
) then
13027 Set_String_Literal_Low_Bound
13028 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
13031 -- If the index type is an enumeration type, build bounds
13032 -- expression with attributes.
13034 Set_String_Literal_Low_Bound
13036 Make_Attribute_Reference
(Loc
,
13037 Attribute_Name
=> Name_First
,
13039 New_Occurrence_Of
(Base_Type
(Index_Type
), Loc
)));
13042 Analyze_And_Resolve
13043 (String_Literal_Low_Bound
(Subtype_Id
), Base_Type
(Index_Type
));
13045 -- Build bona fide subtype for the string, and wrap it in an
13046 -- unchecked conversion, because the back end expects the
13047 -- String_Literal_Subtype to have a static lower bound.
13050 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
13051 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
13052 Set_Scalar_Range
(Index_Subtype
, Drange
);
13053 Set_Parent
(Drange
, N
);
13054 Analyze_And_Resolve
(Drange
, Index_Type
);
13056 -- In this context, the Index_Type may already have a constraint,
13057 -- so use common base type on string subtype. The base type may
13058 -- be used when generating attributes of the string, for example
13059 -- in the context of a slice assignment.
13061 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
13062 Set_Size_Info
(Index_Subtype
, Index_Type
);
13063 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
13065 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
13067 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
13068 Set_Etype
(Index
, Index_Subtype
);
13069 Append
(Index
, Index_List
);
13071 Set_First_Index
(Array_Subtype
, Index
);
13072 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
13073 Set_Is_Constrained
(Array_Subtype
, True);
13075 Rewrite
(N
, Unchecked_Convert_To
(Array_Subtype
, N
));
13076 Set_Etype
(N
, Array_Subtype
);
13079 end Set_String_Literal_Subtype
;
13081 ------------------------------
13082 -- Simplify_Type_Conversion --
13083 ------------------------------
13085 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
13087 if Nkind
(N
) = N_Type_Conversion
then
13089 Operand
: constant Node_Id
:= Expression
(N
);
13090 Target_Typ
: constant Entity_Id
:= Etype
(N
);
13091 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
13094 -- Special processing if the conversion is the expression of a
13095 -- Rounding or Truncation attribute reference. In this case we
13098 -- ityp (ftyp'Rounding (x)) or ityp (ftyp'Truncation (x))
13104 -- with the Float_Truncate flag set to False or True respectively,
13105 -- which is more efficient. We reuse Rounding for Machine_Rounding
13106 -- as System.Fat_Gen, which is a permissible behavior.
13108 if Is_Floating_Point_Type
(Opnd_Typ
)
13110 (Is_Integer_Type
(Target_Typ
)
13111 or else (Is_Fixed_Point_Type
(Target_Typ
)
13112 and then Conversion_OK
(N
)))
13113 and then Nkind
(Operand
) = N_Attribute_Reference
13114 and then Attribute_Name
(Operand
) in Name_Rounding
13115 | Name_Machine_Rounding
13119 Truncate
: constant Boolean :=
13120 Attribute_Name
(Operand
) = Name_Truncation
;
13123 Relocate_Node
(First
(Expressions
(Operand
))));
13124 Set_Float_Truncate
(N
, Truncate
);
13127 -- Special processing for the conversion of an integer literal to
13128 -- a dynamic type: we first convert the literal to the root type
13129 -- and then convert the result to the target type, the goal being
13130 -- to avoid doing range checks in universal integer.
13132 elsif Is_Integer_Type
(Target_Typ
)
13133 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
13134 and then Nkind
(Operand
) = N_Integer_Literal
13135 and then Opnd_Typ
= Universal_Integer
13137 Convert_To_And_Rewrite
(Root_Type
(Target_Typ
), Operand
);
13138 Analyze_And_Resolve
(Operand
);
13140 -- If the expression is a conversion to universal integer of an
13141 -- an expression with an integer type, then we can eliminate the
13142 -- intermediate conversion to universal integer.
13144 elsif Nkind
(Operand
) = N_Type_Conversion
13145 and then Entity
(Subtype_Mark
(Operand
)) = Universal_Integer
13146 and then Is_Integer_Type
(Etype
(Expression
(Operand
)))
13148 Rewrite
(Operand
, Relocate_Node
(Expression
(Operand
)));
13149 Analyze_And_Resolve
(Operand
);
13153 end Simplify_Type_Conversion
;
13155 ------------------------------
13156 -- Try_User_Defined_Literal --
13157 ------------------------------
13159 function Try_User_Defined_Literal
13161 Typ
: Entity_Id
) return Boolean
13164 if Has_Applicable_User_Defined_Literal
(N
, Typ
) then
13167 elsif Nkind
(N
) = N_If_Expression
then
13168 -- Both dependent expressions must have the same type as the context
13171 Condition
: constant Node_Id
:= First
(Expressions
(N
));
13172 Then_Expr
: constant Node_Id
:= Next
(Condition
);
13173 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
13176 if Has_Applicable_User_Defined_Literal
(Then_Expr
, Typ
) then
13177 Resolve
(Else_Expr
, Typ
);
13178 Analyze_And_Resolve
(N
, Typ
);
13181 elsif Has_Applicable_User_Defined_Literal
(Else_Expr
, Typ
) then
13182 Resolve
(Then_Expr
, Typ
);
13183 Analyze_And_Resolve
(N
, Typ
);
13188 elsif Nkind
(N
) = N_Case_Expression
then
13189 -- All dependent expressions must have the same type as the context
13195 Alt
:= First
(Alternatives
(N
));
13197 while Present
(Alt
) loop
13198 if Has_Applicable_User_Defined_Literal
(Expression
(Alt
), Typ
)
13201 Other_Alt
: Node_Id
;
13204 Other_Alt
:= First
(Alternatives
(N
));
13206 while Present
(Other_Alt
) loop
13207 if Other_Alt
/= Alt
then
13208 Resolve
(Expression
(Other_Alt
), Typ
);
13214 Analyze_And_Resolve
(N
, Typ
);
13225 end Try_User_Defined_Literal
;
13227 -------------------------------------------
13228 -- Try_User_Defined_Literal_For_Operator --
13229 -------------------------------------------
13231 function Try_User_Defined_Literal_For_Operator
13233 Typ
: Entity_Id
) return Boolean
13236 if Nkind
(N
) in N_Op_Add
13243 -- Both operands must have the same type as the context
13244 -- (ignoring for now fixed-point and exponentiation ops).
13246 if Has_Applicable_User_Defined_Literal
(Right_Opnd
(N
), Typ
)
13247 or else (Nkind
(Left_Opnd
(N
)) in N_Op
13248 and then Covers
(Typ
, Etype
(Right_Opnd
(N
))))
13250 Resolve
(Left_Opnd
(N
), Typ
);
13251 Analyze_And_Resolve
(N
, Typ
);
13254 elsif Has_Applicable_User_Defined_Literal
(Left_Opnd
(N
), Typ
)
13255 or else (Nkind
(Right_Opnd
(N
)) in N_Op
13256 and then Covers
(Typ
, Etype
(Left_Opnd
(N
))))
13258 Resolve
(Right_Opnd
(N
), Typ
);
13259 Analyze_And_Resolve
(N
, Typ
);
13263 elsif Nkind
(N
) in N_Binary_Op
then
13264 -- For other binary operators the context does not impose a type on
13265 -- the operands, but their types must match.
13267 if Nkind
(Left_Opnd
(N
))
13268 not in N_Integer_Literal | N_String_Literal | N_Real_Literal
13270 Has_Applicable_User_Defined_Literal
13271 (Right_Opnd
(N
), Etype
(Left_Opnd
(N
)))
13273 Analyze_And_Resolve
(N
, Typ
);
13276 elsif Nkind
(Right_Opnd
(N
))
13277 not in N_Integer_Literal | N_String_Literal | N_Real_Literal
13279 Has_Applicable_User_Defined_Literal
13280 (Left_Opnd
(N
), Etype
(Right_Opnd
(N
)))
13282 Analyze_And_Resolve
(N
, Typ
);
13286 elsif Nkind
(N
) in N_Unary_Op
13287 and then Has_Applicable_User_Defined_Literal
(Right_Opnd
(N
), Typ
)
13289 Analyze_And_Resolve
(N
, Typ
);
13294 end Try_User_Defined_Literal_For_Operator
;
13296 -----------------------------
13297 -- Unique_Fixed_Point_Type --
13298 -----------------------------
13300 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
13301 procedure Fixed_Point_Error
(T1
: Entity_Id
; T2
: Entity_Id
);
13302 -- Give error messages for true ambiguity. Messages are posted on node
13303 -- N, and entities T1, T2 are the possible interpretations.
13305 -----------------------
13306 -- Fixed_Point_Error --
13307 -----------------------
13309 procedure Fixed_Point_Error
(T1
: Entity_Id
; T2
: Entity_Id
) is
13311 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
13312 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
13313 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
13314 end Fixed_Point_Error
;
13324 -- Start of processing for Unique_Fixed_Point_Type
13327 -- The operations on Duration are visible, so Duration is always a
13328 -- possible interpretation.
13330 T1
:= Standard_Duration
;
13332 -- Look for fixed-point types in enclosing scopes
13334 Scop
:= Current_Scope
;
13335 while Scop
/= Standard_Standard
loop
13336 T2
:= First_Entity
(Scop
);
13337 while Present
(T2
) loop
13338 if Is_Fixed_Point_Type
(T2
)
13339 and then Current_Entity
(T2
) = T2
13340 and then Scope
(Base_Type
(T2
)) = Scop
13342 if Present
(T1
) then
13343 Fixed_Point_Error
(T1
, T2
);
13353 Scop
:= Scope
(Scop
);
13356 -- Look for visible fixed type declarations in the context
13358 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
13359 while Present
(Item
) loop
13360 if Nkind
(Item
) = N_With_Clause
then
13361 Scop
:= Entity
(Name
(Item
));
13362 T2
:= First_Entity
(Scop
);
13363 while Present
(T2
) loop
13364 if Is_Fixed_Point_Type
(T2
)
13365 and then Scope
(Base_Type
(T2
)) = Scop
13366 and then (Is_Potentially_Use_Visible
(T2
) or else In_Use
(T2
))
13368 if Present
(T1
) then
13369 Fixed_Point_Error
(T1
, T2
);
13383 if Nkind
(N
) = N_Real_Literal
then
13384 Error_Msg_NE
("??real literal interpreted as }!", N
, T1
);
13387 -- When the context is a type conversion, issue the warning on the
13388 -- expression of the conversion because it is the actual operation.
13390 if Nkind
(N
) in N_Type_Conversion | N_Unchecked_Type_Conversion
then
13391 ErrN
:= Expression
(N
);
13397 ("??universal_fixed expression interpreted as }!", ErrN
, T1
);
13401 end Unique_Fixed_Point_Type
;
13403 ----------------------
13404 -- Valid_Conversion --
13405 ----------------------
13407 function Valid_Conversion
13409 Target
: Entity_Id
;
13411 Report_Errs
: Boolean := True) return Boolean
13413 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
13414 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
13415 Inc_Ancestor
: Entity_Id
;
13417 function Conversion_Check
13419 Msg
: String) return Boolean;
13420 -- Little routine to post Msg if Valid is False, returns Valid value
13422 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
);
13423 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
13425 procedure Conversion_Error_NE
13427 N
: Node_Or_Entity_Id
;
13428 E
: Node_Or_Entity_Id
);
13429 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
13431 function In_Instance_Code
return Boolean;
13432 -- Return True if expression is within an instance but is not in one of
13433 -- the actuals of the instantiation. Type conversions within an instance
13434 -- are not rechecked because type visibility may lead to spurious errors
13435 -- but conversions in an actual for a formal object must be checked.
13437 function Is_Discrim_Of_Bad_Access_Conversion_Argument
13438 (Expr
: Node_Id
) return Boolean;
13439 -- Implicit anonymous-to-named access type conversions are not allowed
13440 -- if the "statically deeper than" relationship does not apply to the
13441 -- type of the conversion operand. See RM 8.6(28.1) and AARM 8.6(28.d).
13442 -- We deal with most such cases elsewhere so that we can emit more
13443 -- specific error messages (e.g., if the operand is an access parameter
13444 -- or a saooaaat (stand-alone object of an anonymous access type)), but
13445 -- here is where we catch the case where the operand is an access
13446 -- discriminant selected from a dereference of another such "bad"
13447 -- conversion argument.
13449 function Valid_Tagged_Conversion
13450 (Target_Type
: Entity_Id
;
13451 Opnd_Type
: Entity_Id
) return Boolean;
13452 -- Specifically test for validity of tagged conversions
13454 function Valid_Array_Conversion
return Boolean;
13455 -- Check index and component conformance, and accessibility levels if
13456 -- the component types are anonymous access types (Ada 2005).
13458 ----------------------
13459 -- Conversion_Check --
13460 ----------------------
13462 function Conversion_Check
13464 Msg
: String) return Boolean
13469 -- A generic unit has already been analyzed and we have verified
13470 -- that a particular conversion is OK in that context. Since the
13471 -- instance is reanalyzed without relying on the relationships
13472 -- established during the analysis of the generic, it is possible
13473 -- to end up with inconsistent views of private types. Do not emit
13474 -- the error message in such cases. The rest of the machinery in
13475 -- Valid_Conversion still ensures the proper compatibility of
13476 -- target and operand types.
13478 and then not In_Instance_Code
13480 Conversion_Error_N
(Msg
, Operand
);
13484 end Conversion_Check
;
13486 ------------------------
13487 -- Conversion_Error_N --
13488 ------------------------
13490 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
13492 if Report_Errs
then
13493 Error_Msg_N
(Msg
, N
);
13495 end Conversion_Error_N
;
13497 -------------------------
13498 -- Conversion_Error_NE --
13499 -------------------------
13501 procedure Conversion_Error_NE
13503 N
: Node_Or_Entity_Id
;
13504 E
: Node_Or_Entity_Id
)
13507 if Report_Errs
then
13508 Error_Msg_NE
(Msg
, N
, E
);
13510 end Conversion_Error_NE
;
13512 ----------------------
13513 -- In_Instance_Code --
13514 ----------------------
13516 function In_Instance_Code
return Boolean is
13520 if not In_Instance
then
13525 while Present
(Par
) loop
13527 -- The expression is part of an actual object if it appears in
13528 -- the generated object declaration in the instance.
13530 if Nkind
(Par
) = N_Object_Declaration
13531 and then Present
(Corresponding_Generic_Association
(Par
))
13537 Nkind
(Par
) in N_Statement_Other_Than_Procedure_Call
13538 or else Nkind
(Par
) in N_Subprogram_Call
13539 or else Nkind
(Par
) in N_Declaration
;
13542 Par
:= Parent
(Par
);
13545 -- Otherwise the expression appears within the instantiated unit
13549 end In_Instance_Code
;
13551 --------------------------------------------------
13552 -- Is_Discrim_Of_Bad_Access_Conversion_Argument --
13553 --------------------------------------------------
13555 function Is_Discrim_Of_Bad_Access_Conversion_Argument
13556 (Expr
: Node_Id
) return Boolean
13558 Exp_Type
: Entity_Id
:= Base_Type
(Etype
(Expr
));
13559 pragma Assert
(Is_Access_Type
(Exp_Type
));
13561 Associated_Node
: Node_Id
;
13562 Deref_Prefix
: Node_Id
;
13564 if not Is_Anonymous_Access_Type
(Exp_Type
) then
13568 pragma Assert
(Is_Itype
(Exp_Type
));
13569 Associated_Node
:= Associated_Node_For_Itype
(Exp_Type
);
13571 if Nkind
(Associated_Node
) /= N_Discriminant_Specification
then
13572 return False; -- not the type of an access discriminant
13575 -- return False if Expr not of form <prefix>.all.Some_Component
13577 if Nkind
(Expr
) /= N_Selected_Component
13578 or else Nkind
(Prefix
(Expr
)) /= N_Explicit_Dereference
13580 -- conditional expressions, declare expressions ???
13584 Deref_Prefix
:= Prefix
(Prefix
(Expr
));
13585 Exp_Type
:= Base_Type
(Etype
(Deref_Prefix
));
13587 -- The "statically deeper relationship" does not apply
13588 -- to generic formal access types, so a prefix of such
13589 -- a type is a "bad" prefix.
13591 if Is_Generic_Formal
(Exp_Type
) then
13594 -- The "statically deeper relationship" does apply to
13595 -- any other named access type.
13597 elsif not Is_Anonymous_Access_Type
(Exp_Type
) then
13601 pragma Assert
(Is_Itype
(Exp_Type
));
13602 Associated_Node
:= Associated_Node_For_Itype
(Exp_Type
);
13604 -- The "statically deeper relationship" applies to some
13605 -- anonymous access types and not to others. Return
13606 -- True for the cases where it does not apply. Also check
13607 -- recursively for the
13608 -- <prefix>.all.Access_Discrim.all.Access_Discrim case,
13609 -- where the correct result depends on <prefix>.
13611 return Nkind
(Associated_Node
) in
13612 N_Procedure_Specification |
-- access parameter
13613 N_Function_Specification |
-- access parameter
13614 N_Object_Declaration
-- saooaaat
13615 or else Is_Discrim_Of_Bad_Access_Conversion_Argument
(Deref_Prefix
);
13616 end Is_Discrim_Of_Bad_Access_Conversion_Argument
;
13618 ----------------------------
13619 -- Valid_Array_Conversion --
13620 ----------------------------
13622 function Valid_Array_Conversion
return Boolean is
13623 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
13624 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
13626 Opnd_Index
: Node_Id
;
13627 Opnd_Index_Type
: Entity_Id
;
13629 Target_Comp_Type
: constant Entity_Id
:=
13630 Component_Type
(Target_Type
);
13631 Target_Comp_Base
: constant Entity_Id
:=
13632 Base_Type
(Target_Comp_Type
);
13634 Target_Index
: Node_Id
;
13635 Target_Index_Type
: Entity_Id
;
13638 -- Error if wrong number of dimensions
13641 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
13644 ("incompatible number of dimensions for conversion", Operand
);
13647 -- Number of dimensions matches
13650 -- Loop through indexes of the two arrays
13652 Target_Index
:= First_Index
(Target_Type
);
13653 Opnd_Index
:= First_Index
(Opnd_Type
);
13654 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
13655 Target_Index_Type
:= Etype
(Target_Index
);
13656 Opnd_Index_Type
:= Etype
(Opnd_Index
);
13658 -- Error if index types are incompatible
13660 if not (Is_Integer_Type
(Target_Index_Type
)
13661 and then Is_Integer_Type
(Opnd_Index_Type
))
13662 and then Root_Type
(Target_Index_Type
)
13663 /= Root_Type
(Opnd_Index_Type
)
13666 ("incompatible index types for array conversion",
13671 Next_Index
(Target_Index
);
13672 Next_Index
(Opnd_Index
);
13675 -- If component types have same base type, all set
13677 if Target_Comp_Base
= Opnd_Comp_Base
then
13680 -- Here if base types of components are not the same. The only
13681 -- time this is allowed is if we have anonymous access types.
13683 -- The conversion of arrays of anonymous access types can lead
13684 -- to dangling pointers. AI-392 formalizes the accessibility
13685 -- checks that must be applied to such conversions to prevent
13686 -- out-of-scope references.
13688 elsif Ekind
(Target_Comp_Base
) in
13689 E_Anonymous_Access_Type
13690 | E_Anonymous_Access_Subprogram_Type
13691 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
13693 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
13695 if Type_Access_Level
(Target_Type
) <
13696 Deepest_Type_Access_Level
(Opnd_Type
)
13698 if In_Instance_Body
then
13699 Error_Msg_Warn
:= SPARK_Mode
/= On
;
13701 ("source array type has deeper accessibility "
13702 & "level than target<<", Operand
);
13703 Conversion_Error_N
("\Program_Error [<<", Operand
);
13705 Make_Raise_Program_Error
(Sloc
(N
),
13706 Reason
=> PE_Accessibility_Check_Failed
));
13707 Set_Etype
(N
, Target_Type
);
13710 -- Conversion not allowed because of accessibility levels
13714 ("source array type has deeper accessibility "
13715 & "level than target", Operand
);
13723 -- All other cases where component base types do not match
13727 ("incompatible component types for array conversion",
13732 -- Check that component subtypes statically match. For numeric
13733 -- types this means that both must be either constrained or
13734 -- unconstrained. For enumeration types the bounds must match.
13735 -- All of this is checked in Subtypes_Statically_Match.
13737 if not Subtypes_Statically_Match
13738 (Target_Comp_Type
, Opnd_Comp_Type
)
13741 ("component subtypes must statically match", Operand
);
13747 end Valid_Array_Conversion
;
13749 -----------------------------
13750 -- Valid_Tagged_Conversion --
13751 -----------------------------
13753 function Valid_Tagged_Conversion
13754 (Target_Type
: Entity_Id
;
13755 Opnd_Type
: Entity_Id
) return Boolean
13758 -- Upward conversions are allowed (RM 4.6(22))
13760 if Covers
(Target_Type
, Opnd_Type
)
13761 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
13765 -- Downward conversion are allowed if the operand is class-wide
13768 elsif Is_Class_Wide_Type
(Opnd_Type
)
13769 and then Covers
(Opnd_Type
, Target_Type
)
13773 elsif Covers
(Opnd_Type
, Target_Type
)
13774 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
13777 Conversion_Check
(False,
13778 "downward conversion of tagged objects not allowed");
13780 -- Ada 2005 (AI-251): A conversion is valid if the operand and target
13781 -- types are both class-wide types and the specific type associated
13782 -- with at least one of them is an interface type (RM 4.6 (23.1/2));
13783 -- at run-time a check will verify the validity of this interface
13784 -- type conversion.
13786 elsif Is_Class_Wide_Type
(Target_Type
)
13787 and then Is_Class_Wide_Type
(Opnd_Type
)
13788 and then (Is_Interface
(Target_Type
)
13789 or else Is_Interface
(Opnd_Type
))
13795 elsif Is_Class_Wide_Type
(Target_Type
)
13796 and then Is_Interface
(Target_Type
)
13797 and then not Is_Interface
(Opnd_Type
)
13798 and then not Interface_Present_In_Ancestor
13800 Iface
=> Target_Type
)
13802 Error_Msg_Name_1
:= Chars
(Etype
(Target_Type
));
13803 Error_Msg_Name_2
:= Chars
(Opnd_Type
);
13805 ("wrong interface conversion (% is not a progenitor "
13809 elsif Is_Class_Wide_Type
(Opnd_Type
)
13810 and then Is_Interface
(Opnd_Type
)
13811 and then not Is_Interface
(Target_Type
)
13812 and then not Interface_Present_In_Ancestor
13813 (Typ
=> Target_Type
,
13814 Iface
=> Opnd_Type
)
13816 Error_Msg_Name_1
:= Chars
(Etype
(Opnd_Type
));
13817 Error_Msg_Name_2
:= Chars
(Target_Type
);
13819 ("wrong interface conversion (% is not a progenitor "
13822 -- Search for interface types shared between the target type and
13823 -- the operand interface type to complete the text of the error
13824 -- since the source of this error is a missing type conversion
13825 -- to such interface type.
13827 if Has_Interfaces
(Target_Type
) then
13829 Operand_Ifaces_List
: Elist_Id
;
13830 Operand_Iface_Elmt
: Elmt_Id
;
13831 Target_Ifaces_List
: Elist_Id
;
13832 Target_Iface_Elmt
: Elmt_Id
;
13833 First_Candidate
: Boolean := True;
13836 Collect_Interfaces
(Base_Type
(Target_Type
),
13837 Target_Ifaces_List
);
13838 Collect_Interfaces
(Root_Type
(Base_Type
(Opnd_Type
)),
13839 Operand_Ifaces_List
);
13841 Operand_Iface_Elmt
:= First_Elmt
(Operand_Ifaces_List
);
13842 while Present
(Operand_Iface_Elmt
) loop
13843 Target_Iface_Elmt
:= First_Elmt
(Target_Ifaces_List
);
13844 while Present
(Target_Iface_Elmt
) loop
13845 if Node
(Operand_Iface_Elmt
)
13846 = Node
(Target_Iface_Elmt
)
13848 Error_Msg_Name_1
:=
13849 Chars
(Node
(Target_Iface_Elmt
));
13851 if First_Candidate
then
13852 First_Candidate
:= False;
13854 ("\must convert to `%''Class` before downward "
13855 & "conversion", Operand
);
13858 ("\or must convert to `%''Class` before "
13859 & "downward conversion", Operand
);
13863 Next_Elmt
(Target_Iface_Elmt
);
13866 Next_Elmt
(Operand_Iface_Elmt
);
13873 elsif not Is_Class_Wide_Type
(Target_Type
)
13874 and then Is_Interface
(Target_Type
)
13877 ("wrong use of interface type in tagged conversion", N
);
13879 ("\add ''Class to the target interface type", N
);
13882 elsif not Is_Class_Wide_Type
(Opnd_Type
)
13883 and then Is_Interface
(Opnd_Type
)
13886 ("must convert to class-wide interface type before downward "
13887 & "conversion", Operand
);
13891 Conversion_Error_NE
13892 ("invalid tagged conversion, not compatible with}",
13893 N
, First_Subtype
(Opnd_Type
));
13896 end Valid_Tagged_Conversion
;
13898 -- Start of processing for Valid_Conversion
13901 Check_Parameterless_Call
(Operand
);
13903 if Is_Overloaded
(Operand
) then
13913 -- Remove procedure calls, which syntactically cannot appear in
13914 -- this context, but which cannot be removed by type checking,
13915 -- because the context does not impose a type.
13917 -- The node may be labelled overloaded, but still contain only one
13918 -- interpretation because others were discarded earlier. If this
13919 -- is the case, retain the single interpretation if legal.
13921 Get_First_Interp
(Operand
, I
, It
);
13922 Opnd_Type
:= It
.Typ
;
13923 Get_Next_Interp
(I
, It
);
13925 if Present
(It
.Typ
)
13926 and then Opnd_Type
/= Standard_Void_Type
13928 -- More than one candidate interpretation is available
13930 Get_First_Interp
(Operand
, I
, It
);
13931 while Present
(It
.Typ
) loop
13932 if It
.Typ
= Standard_Void_Type
then
13936 -- When compiling for a system where Address is of a visible
13937 -- integer type, spurious ambiguities can be produced when
13938 -- arithmetic operations have a literal operand and return
13939 -- System.Address or a descendant of it. These ambiguities
13940 -- are usually resolved by the context, but for conversions
13941 -- there is no context type and the removal of the spurious
13942 -- operations must be done explicitly here.
13944 if not Address_Is_Private
13945 and then Is_Descendant_Of_Address
(It
.Typ
)
13950 Get_Next_Interp
(I
, It
);
13954 Get_First_Interp
(Operand
, I
, It
);
13958 if No
(It
.Typ
) then
13959 Conversion_Error_N
("illegal operand in conversion", Operand
);
13963 Get_Next_Interp
(I
, It
);
13965 if Present
(It
.Typ
) then
13968 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
13970 if It1
= No_Interp
then
13972 ("ambiguous operand in conversion", Operand
);
13974 -- If the interpretation involves a standard operator, use
13975 -- the location of the type, which may be user-defined.
13977 if Sloc
(It
.Nam
) = Standard_Location
then
13978 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
13980 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
13983 Conversion_Error_N
-- CODEFIX
13984 ("\\possible interpretation#!", Operand
);
13986 if Sloc
(N1
) = Standard_Location
then
13987 Error_Msg_Sloc
:= Sloc
(T1
);
13989 Error_Msg_Sloc
:= Sloc
(N1
);
13992 Conversion_Error_N
-- CODEFIX
13993 ("\\possible interpretation#!", Operand
);
13999 Set_Etype
(Operand
, It1
.Typ
);
14000 Opnd_Type
:= It1
.Typ
;
14004 -- Deal with conversion of integer type to address if the pragma
14005 -- Allow_Integer_Address is in effect. We convert the conversion to
14006 -- an unchecked conversion in this case and we are all done.
14008 if Address_Integer_Convert_OK
(Opnd_Type
, Target_Type
) then
14009 Rewrite
(N
, Unchecked_Convert_To
(Target_Type
, Expression
(N
)));
14010 Analyze_And_Resolve
(N
, Target_Type
);
14014 -- If we are within a child unit, check whether the type of the
14015 -- expression has an ancestor in a parent unit, in which case it
14016 -- belongs to its derivation class even if the ancestor is private.
14017 -- See RM 7.3.1 (5.2/3).
14019 Inc_Ancestor
:= Get_Incomplete_View_Of_Ancestor
(Opnd_Type
);
14023 if Is_Numeric_Type
(Target_Type
) then
14025 -- A universal fixed expression can be converted to any numeric type
14027 if Opnd_Type
= Universal_Fixed
then
14030 -- Also no need to check when in an instance or inlined body, because
14031 -- the legality has been established when the template was analyzed.
14032 -- Furthermore, numeric conversions may occur where only a private
14033 -- view of the operand type is visible at the instantiation point.
14034 -- This results in a spurious error if we check that the operand type
14035 -- is a numeric type.
14037 -- Note: in a previous version of this unit, the following tests were
14038 -- applied only for generated code (Comes_From_Source set to False),
14039 -- but in fact the test is required for source code as well, since
14040 -- this situation can arise in source code.
14042 elsif In_Instance_Code
or else In_Inlined_Body
then
14045 -- Otherwise we need the conversion check
14048 return Conversion_Check
14049 (Is_Numeric_Type
(Opnd_Type
)
14051 (Present
(Inc_Ancestor
)
14052 and then Is_Numeric_Type
(Inc_Ancestor
)),
14053 "illegal operand for numeric conversion");
14058 elsif Is_Array_Type
(Target_Type
) then
14059 if not Is_Array_Type
(Opnd_Type
)
14060 or else Opnd_Type
= Any_Composite
14061 or else Opnd_Type
= Any_String
14064 ("illegal operand for array conversion", Operand
);
14068 return Valid_Array_Conversion
;
14071 -- Ada 2005 (AI-251): Internally generated conversions of access to
14072 -- interface types added to force the displacement of the pointer to
14073 -- reference the corresponding dispatch table.
14075 elsif not Comes_From_Source
(N
)
14076 and then Is_Access_Type
(Target_Type
)
14077 and then Is_Interface
(Designated_Type
(Target_Type
))
14081 -- Ada 2005 (AI-251): Anonymous access types where target references an
14084 elsif Is_Access_Type
(Opnd_Type
)
14085 and then Ekind
(Target_Type
) in
14086 E_General_Access_Type | E_Anonymous_Access_Type
14087 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
14089 -- Check the static accessibility rule of 4.6(17). Note that the
14090 -- check is not enforced when within an instance body, since the
14091 -- RM requires such cases to be caught at run time.
14093 -- If the operand is a rewriting of an allocator no check is needed
14094 -- because there are no accessibility issues.
14096 if Nkind
(Original_Node
(N
)) = N_Allocator
then
14099 elsif Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
14100 if Type_Access_Level
(Opnd_Type
) >
14101 Deepest_Type_Access_Level
(Target_Type
)
14103 -- In an instance, this is a run-time check, but one we know
14104 -- will fail, so generate an appropriate warning. The raise
14105 -- will be generated by Expand_N_Type_Conversion.
14107 if In_Instance_Body
then
14108 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14110 ("cannot convert local pointer to non-local access type<<",
14112 Conversion_Error_N
("\Program_Error [<<", Operand
);
14116 ("cannot convert local pointer to non-local access type",
14121 -- Special accessibility checks are needed in the case of access
14122 -- discriminants declared for a limited type.
14124 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
14125 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
14127 -- When the operand is a selected access discriminant the check
14128 -- needs to be made against the level of the object denoted by
14129 -- the prefix of the selected name (Accessibility_Level handles
14130 -- checking the prefix of the operand for this case).
14132 if Nkind
(Operand
) = N_Selected_Component
14133 and then Static_Accessibility_Level
14134 (Operand
, Zero_On_Dynamic_Level
)
14135 > Deepest_Type_Access_Level
(Target_Type
)
14137 -- In an instance, this is a run-time check, but one we know
14138 -- will fail, so generate an appropriate warning. The raise
14139 -- will be generated by Expand_N_Type_Conversion.
14141 if In_Instance_Body
then
14142 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14144 ("cannot convert access discriminant to non-local "
14145 & "access type<<", Operand
);
14146 Conversion_Error_N
("\Program_Error [<<", Operand
);
14148 -- Real error if not in instance body
14152 ("cannot convert access discriminant to non-local "
14153 & "access type", Operand
);
14158 -- The case of a reference to an access discriminant from
14159 -- within a limited type declaration (which will appear as
14160 -- a discriminal) is always illegal because the level of the
14161 -- discriminant is considered to be deeper than any (nameable)
14164 if Is_Entity_Name
(Operand
)
14165 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
14167 Ekind
(Entity
(Operand
)) in E_In_Parameter | E_Constant
14168 and then Present
(Discriminal_Link
(Entity
(Operand
)))
14171 ("discriminant has deeper accessibility level than target",
14180 -- General and anonymous access types
14182 elsif Ekind
(Target_Type
) in
14183 E_General_Access_Type | E_Anonymous_Access_Type
14186 (Is_Access_Type
(Opnd_Type
)
14188 Ekind
(Opnd_Type
) not in
14189 E_Access_Subprogram_Type |
14190 E_Access_Protected_Subprogram_Type
,
14191 "must be an access-to-object type")
14193 if Is_Access_Constant
(Opnd_Type
)
14194 and then not Is_Access_Constant
(Target_Type
)
14197 ("access-to-constant operand type not allowed", Operand
);
14201 -- Check the static accessibility rule of 4.6(17). Note that the
14202 -- check is not enforced when within an instance body, since the RM
14203 -- requires such cases to be caught at run time.
14205 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
14206 or else Is_Local_Anonymous_Access
(Target_Type
)
14207 or else Nkind
(Associated_Node_For_Itype
(Target_Type
)) =
14208 N_Object_Declaration
14210 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
14211 -- conversions from an anonymous access type to a named general
14212 -- access type. Such conversions are not allowed in the case of
14213 -- access parameters and stand-alone objects of an anonymous
14214 -- access type. The implicit conversion case is recognized by
14215 -- testing that Comes_From_Source is False and that it's been
14216 -- rewritten. The Comes_From_Source test isn't sufficient because
14217 -- nodes in inlined calls to predefined library routines can have
14218 -- Comes_From_Source set to False. (Is there a better way to test
14219 -- for implicit conversions???).
14221 -- Do not treat a rewritten 'Old attribute reference like other
14222 -- rewrite substitutions. This makes a difference, for example,
14223 -- in the case where we are generating the expansion of a
14224 -- membership test of the form
14225 -- Saooaaat'Old in Named_Access_Type
14226 -- because in this case Valid_Conversion needs to return True
14227 -- (otherwise the expansion will be False - see the call site
14228 -- in exp_ch4.adb).
14230 if Ada_Version
>= Ada_2012
14231 and then not Comes_From_Source
(N
)
14232 and then Is_Rewrite_Substitution
(N
)
14233 and then not Is_Attribute_Old
(Original_Node
(N
))
14234 and then Ekind
(Base_Type
(Target_Type
)) = E_General_Access_Type
14235 and then Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
14237 if Is_Itype
(Opnd_Type
) then
14239 -- When applying restriction No_Dynamic_Accessibility_Check,
14240 -- implicit conversions are allowed when the operand type is
14241 -- not deeper than the target type.
14243 if No_Dynamic_Accessibility_Checks_Enabled
(N
) then
14244 if Type_Access_Level
(Opnd_Type
)
14245 > Deepest_Type_Access_Level
(Target_Type
)
14248 ("operand has deeper level than target", Operand
);
14251 -- Implicit conversions aren't allowed for objects of an
14252 -- anonymous access type, since such objects have nonstatic
14253 -- levels in Ada 2012.
14255 elsif Nkind
(Associated_Node_For_Itype
(Opnd_Type
))
14256 = N_Object_Declaration
14259 ("implicit conversion of stand-alone anonymous "
14260 & "access object not allowed", Operand
);
14263 -- Implicit conversions aren't allowed for anonymous access
14264 -- parameters. We exclude anonymous access results as well
14265 -- as universal_access "=".
14267 elsif not Is_Local_Anonymous_Access
(Opnd_Type
)
14268 and then Nkind
(Associated_Node_For_Itype
(Opnd_Type
)) in
14269 N_Function_Specification |
14270 N_Procedure_Specification
14271 and then Nkind
(Parent
(N
)) not in N_Op_Eq | N_Op_Ne
14274 ("implicit conversion of anonymous access parameter "
14275 & "not allowed", Operand
);
14278 -- Detect access discriminant values that are illegal
14279 -- implicit anonymous-to-named access conversion operands.
14281 elsif Is_Discrim_Of_Bad_Access_Conversion_Argument
(Operand
)
14284 ("implicit conversion of anonymous access value "
14285 & "not allowed", Operand
);
14288 -- In other cases, the level of the operand's type must be
14289 -- statically less deep than that of the target type, else
14290 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
14292 elsif Type_Access_Level
(Opnd_Type
) >
14293 Deepest_Type_Access_Level
(Target_Type
)
14296 ("implicit conversion of anonymous access value "
14297 & "violates accessibility", Operand
);
14302 -- Check if the operand is deeper than the target type, taking
14303 -- care to avoid the case where we are converting a result of a
14304 -- function returning an anonymous access type since the "master
14305 -- of the call" would be target type of the conversion unless
14306 -- the target type is anonymous access as well - see RM 3.10.2
14309 -- Note that when the restriction No_Dynamic_Accessibility_Checks
14310 -- is in effect wei also want to proceed with the conversion check
14311 -- described above.
14313 elsif Type_Access_Level
(Opnd_Type
, Assoc_Ent
=> Operand
)
14314 > Deepest_Type_Access_Level
(Target_Type
)
14315 and then (Nkind
(Associated_Node_For_Itype
(Opnd_Type
))
14316 /= N_Function_Specification
14317 or else Ekind
(Target_Type
) in Anonymous_Access_Kind
14318 or else No_Dynamic_Accessibility_Checks_Enabled
(N
))
14320 -- Check we are not in a return value ???
14322 and then (not In_Return_Value
(N
)
14324 Nkind
(Associated_Node_For_Itype
(Target_Type
))
14325 = N_Component_Declaration
)
14327 -- In an instance, this is a run-time check, but one we know
14328 -- will fail, so generate an appropriate warning. The raise
14329 -- will be generated by Expand_N_Type_Conversion.
14331 if In_Instance_Body
then
14332 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14334 ("cannot convert local pointer to non-local access type<<",
14336 Conversion_Error_N
("\Program_Error [<<", Operand
);
14338 -- If not in an instance body, this is a real error
14341 -- Avoid generation of spurious error message
14343 if not Error_Posted
(N
) then
14345 ("cannot convert local pointer to non-local access type",
14352 -- Special accessibility checks are needed in the case of access
14353 -- discriminants declared for a limited type.
14355 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
14356 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
14358 -- When the operand is a selected access discriminant the check
14359 -- needs to be made against the level of the object denoted by
14360 -- the prefix of the selected name (Accessibility_Level handles
14361 -- checking the prefix of the operand for this case).
14363 if Nkind
(Operand
) = N_Selected_Component
14364 and then Static_Accessibility_Level
14365 (Operand
, Zero_On_Dynamic_Level
)
14366 > Deepest_Type_Access_Level
(Target_Type
)
14368 -- In an instance, this is a run-time check, but one we know
14369 -- will fail, so generate an appropriate warning. The raise
14370 -- will be generated by Expand_N_Type_Conversion.
14372 if In_Instance_Body
then
14373 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14375 ("cannot convert access discriminant to non-local "
14376 & "access type<<", Operand
);
14377 Conversion_Error_N
("\Program_Error [<<", Operand
);
14379 -- If not in an instance body, this is a real error
14383 ("cannot convert access discriminant to non-local "
14384 & "access type", Operand
);
14389 -- The case of a reference to an access discriminant from
14390 -- within a limited type declaration (which will appear as
14391 -- a discriminal) is always illegal because the level of the
14392 -- discriminant is considered to be deeper than any (nameable)
14395 if Is_Entity_Name
(Operand
)
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",
14408 -- In the presence of limited_with clauses we have to use nonlimited
14409 -- views, if available.
14411 Check_Limited
: declare
14412 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
14413 -- Helper function to handle limited views
14415 --------------------------
14416 -- Full_Designated_Type --
14417 --------------------------
14419 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
14420 Desig
: constant Entity_Id
:= Designated_Type
(T
);
14423 -- Handle the limited view of a type
14425 if From_Limited_With
(Desig
)
14426 and then Has_Non_Limited_View
(Desig
)
14428 return Available_View
(Desig
);
14432 end Full_Designated_Type
;
14434 -- Local Declarations
14436 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
14437 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
14439 Same_Base
: constant Boolean :=
14440 Base_Type
(Target
) = Base_Type
(Opnd
);
14442 -- Start of processing for Check_Limited
14445 if Is_Tagged_Type
(Target
) then
14446 return Valid_Tagged_Conversion
(Target
, Opnd
);
14449 if not Same_Base
then
14450 Conversion_Error_NE
14451 ("target designated type not compatible with }",
14452 N
, Base_Type
(Opnd
));
14455 -- Ada 2005 AI-384: legality rule is symmetric in both
14456 -- designated types. The conversion is legal (with possible
14457 -- constraint check) if either designated type is
14460 elsif Subtypes_Statically_Match
(Target
, Opnd
)
14462 (Has_Discriminants
(Target
)
14464 (not Is_Constrained
(Opnd
)
14465 or else not Is_Constrained
(Target
)))
14467 -- Special case, if Value_Size has been used to make the
14468 -- sizes different, the conversion is not allowed even
14469 -- though the subtypes statically match.
14471 if Known_Static_RM_Size
(Target
)
14472 and then Known_Static_RM_Size
(Opnd
)
14473 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
14475 Conversion_Error_NE
14476 ("target designated subtype not compatible with }",
14478 Conversion_Error_NE
14479 ("\because sizes of the two designated subtypes differ",
14483 -- Normal case where conversion is allowed
14491 ("target designated subtype not compatible with }",
14498 -- Access to subprogram types. If the operand is an access parameter,
14499 -- the type has a deeper accessibility that any master, and cannot be
14500 -- assigned. We must make an exception if the conversion is part of an
14501 -- assignment and the target is the return object of an extended return
14502 -- statement, because in that case the accessibility check takes place
14503 -- after the return.
14505 elsif Is_Access_Subprogram_Type
(Target_Type
)
14507 -- Note: this test of Opnd_Type is there to prevent entering this
14508 -- branch in the case of a remote access to subprogram type, which
14509 -- is internally represented as an E_Record_Type.
14511 and then Is_Access_Type
(Opnd_Type
)
14513 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
14514 and then Is_Entity_Name
(Operand
)
14515 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
14517 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
14518 or else not Is_Entity_Name
(Name
(Parent
(N
)))
14519 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
14522 ("illegal attempt to store anonymous access to subprogram",
14525 ("\value has deeper accessibility than any master "
14526 & "(RM 3.10.2 (13))",
14530 ("\use named access type for& instead of access parameter",
14531 Operand
, Entity
(Operand
));
14534 -- Check that the designated types are subtype conformant
14536 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
14537 Old_Id
=> Designated_Type
(Opnd_Type
),
14540 -- Check the static accessibility rule of 4.6(20)
14542 if Type_Access_Level
(Opnd_Type
) >
14543 Deepest_Type_Access_Level
(Target_Type
)
14546 ("operand type has deeper accessibility level than target",
14549 -- Check that if the operand type is declared in a generic body,
14550 -- then the target type must be declared within that same body
14551 -- (enforces last sentence of 4.6(20)).
14553 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
14555 O_Gen
: constant Node_Id
:=
14556 Enclosing_Generic_Body
(Opnd_Type
);
14561 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
14562 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
14563 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
14566 if T_Gen
/= O_Gen
then
14568 ("target type must be declared in same generic body "
14569 & "as operand type", N
);
14574 -- Check that the strub modes are compatible.
14575 -- We wish to reject explicit conversions only for
14576 -- incompatible modes.
14578 return Conversion_Check
14579 (Compatible_Strub_Modes
14580 (Designated_Type
(Target_Type
),
14581 Designated_Type
(Opnd_Type
)),
14582 "incompatible `strub` modes");
14584 -- Remote access to subprogram types
14586 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
14587 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
14589 -- It is valid to convert from one RAS type to another provided
14590 -- that their specification statically match.
14592 -- Note: at this point, remote access to subprogram types have been
14593 -- expanded to their E_Record_Type representation, and we need to
14594 -- go back to the original access type definition using the
14595 -- Corresponding_Remote_Type attribute in order to check that the
14596 -- designated profiles match.
14598 pragma Assert
(Ekind
(Target_Type
) = E_Record_Type
);
14599 pragma Assert
(Ekind
(Opnd_Type
) = E_Record_Type
);
14601 Check_Subtype_Conformant
14603 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
14605 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
14609 -- Check that the strub modes are compatible.
14610 -- We wish to reject explicit conversions only for
14611 -- incompatible modes.
14613 return Conversion_Check
14614 (Compatible_Strub_Modes
14615 (Designated_Type
(Target_Type
),
14616 Designated_Type
(Opnd_Type
)),
14617 "incompatible `strub` modes");
14619 -- If it was legal in the generic, it's legal in the instance
14621 elsif In_Instance_Body
then
14624 -- If both are tagged types, check legality of view conversions
14626 elsif Is_Tagged_Type
(Target_Type
)
14628 Is_Tagged_Type
(Opnd_Type
)
14630 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
14632 -- Types derived from the same root type are convertible
14634 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
14637 -- In an instance or an inlined body, there may be inconsistent views of
14638 -- the same type, or of types derived from a common root.
14640 elsif (In_Instance
or In_Inlined_Body
)
14642 Root_Type
(Underlying_Type
(Target_Type
)) =
14643 Root_Type
(Underlying_Type
(Opnd_Type
))
14647 -- Special check for common access type error case
14649 elsif Ekind
(Target_Type
) = E_Access_Type
14650 and then Is_Access_Type
(Opnd_Type
)
14652 Conversion_Error_N
("target type must be general access type!", N
);
14653 Conversion_Error_NE
-- CODEFIX
14654 ("\add ALL to }!", N
, Target_Type
);
14657 -- Here we have a real conversion error
14660 -- Check for missing regular with_clause when only a limited view of
14661 -- target is available.
14663 if From_Limited_With
(Opnd_Type
) and then In_Package_Body
then
14664 Conversion_Error_NE
14665 ("invalid conversion, not compatible with limited view of }",
14667 Conversion_Error_NE
14668 ("\add with_clause for& to current unit!", N
, Scope
(Opnd_Type
));
14670 elsif Is_Access_Type
(Opnd_Type
)
14671 and then From_Limited_With
(Designated_Type
(Opnd_Type
))
14672 and then In_Package_Body
14674 Conversion_Error_NE
14675 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
14676 Conversion_Error_NE
14677 ("\add with_clause for& to current unit!",
14678 N
, Scope
(Designated_Type
(Opnd_Type
)));
14681 Conversion_Error_NE
14682 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
14687 end Valid_Conversion
;