1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2022, 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 Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Debug_A
; use Debug_A
;
31 with Einfo
; use Einfo
;
32 with Einfo
.Entities
; use Einfo
.Entities
;
33 with Einfo
.Utils
; use Einfo
.Utils
;
34 with Errout
; use Errout
;
35 with Expander
; use Expander
;
36 with Exp_Ch6
; use Exp_Ch6
;
37 with Exp_Ch7
; use Exp_Ch7
;
38 with Exp_Disp
; use Exp_Disp
;
39 with Exp_Tss
; use Exp_Tss
;
40 with Exp_Util
; use Exp_Util
;
41 with Freeze
; use Freeze
;
42 with Ghost
; use Ghost
;
43 with Inline
; use Inline
;
44 with Itypes
; use Itypes
;
46 with Lib
.Xref
; use Lib
.Xref
;
47 with Namet
; use Namet
;
48 with Nmake
; use Nmake
;
49 with Nlists
; use Nlists
;
51 with Output
; use Output
;
52 with Par_SCO
; use Par_SCO
;
53 with Restrict
; use Restrict
;
54 with Rident
; use Rident
;
55 with Rtsfind
; use Rtsfind
;
57 with Sem_Aggr
; use Sem_Aggr
;
58 with Sem_Attr
; use Sem_Attr
;
59 with Sem_Aux
; use Sem_Aux
;
60 with Sem_Case
; use Sem_Case
;
61 with Sem_Cat
; use Sem_Cat
;
62 with Sem_Ch3
; use Sem_Ch3
;
63 with Sem_Ch4
; use Sem_Ch4
;
64 with Sem_Ch6
; use Sem_Ch6
;
65 with Sem_Ch8
; use Sem_Ch8
;
66 with Sem_Ch13
; use Sem_Ch13
;
67 with Sem_Dim
; use Sem_Dim
;
68 with Sem_Disp
; use Sem_Disp
;
69 with Sem_Dist
; use Sem_Dist
;
70 with Sem_Elab
; use Sem_Elab
;
71 with Sem_Elim
; use Sem_Elim
;
72 with Sem_Eval
; use Sem_Eval
;
73 with Sem_Intr
; use Sem_Intr
;
74 with Sem_Mech
; use Sem_Mech
;
75 with Sem_Type
; use Sem_Type
;
76 with Sem_Util
; use Sem_Util
;
77 with Sem_Warn
; use Sem_Warn
;
78 with Sinfo
; use Sinfo
;
79 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
80 with Sinfo
.Utils
; use Sinfo
.Utils
;
81 with Sinfo
.CN
; use Sinfo
.CN
;
82 with Snames
; use Snames
;
83 with Stand
; use Stand
;
84 with Stringt
; use Stringt
;
85 with Strub
; use Strub
;
86 with Style
; use Style
;
87 with Targparm
; use Targparm
;
88 with Tbuild
; use Tbuild
;
89 with Uintp
; use Uintp
;
90 with Urealp
; use Urealp
;
92 package body Sem_Res
is
94 -----------------------
95 -- Local Subprograms --
96 -----------------------
98 -- Second pass (top-down) type checking and overload resolution procedures
99 -- Typ is the type required by context. These procedures propagate the
100 -- type information recursively to the descendants of N. If the node is not
101 -- overloaded, its Etype is established in the first pass. If overloaded,
102 -- the Resolve routines set the correct type. For arithmetic operators, the
103 -- Etype is the base type of the context.
105 -- Note that Resolve_Attribute is separated off in Sem_Attr
107 function Has_Applicable_User_Defined_Literal
109 Typ
: Entity_Id
) return Boolean;
110 -- If N is a literal or a named number, check whether Typ
111 -- has a user-defined literal aspect that can apply to N.
112 -- If present, replace N with a call to the corresponding
113 -- function and return True.
115 procedure Check_Discriminant_Use
(N
: Node_Id
);
116 -- Enforce the restrictions on the use of discriminants when constraining
117 -- a component of a discriminated type (record or concurrent type).
119 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
);
120 -- Given a node for an operator associated with type T, check that the
121 -- operator is visible. Operators all of whose operands are universal must
122 -- be checked for visibility during resolution because their type is not
123 -- determinable based on their operands.
125 procedure Check_Fully_Declared_Prefix
128 -- Check that the type of the prefix of a dereference is not incomplete
130 function Check_Infinite_Recursion
(Call
: Node_Id
) return Boolean;
131 -- Given a call node, Call, which is known to occur immediately within the
132 -- subprogram being called, determines whether it is a detectable case of
133 -- an infinite recursion, and if so, outputs appropriate messages. Returns
134 -- True if an infinite recursion is detected, and False otherwise.
136 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
);
137 -- N is the node for a logical operator. If the operator is predefined, and
138 -- the root type of the operands is Standard.Boolean, then a check is made
139 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
140 -- the style check for Style_Check_Boolean_And_Or.
142 function Is_Atomic_Ref_With_Address
(N
: Node_Id
) return Boolean;
143 -- N is either an indexed component or a selected component. This function
144 -- returns true if the prefix denotes an atomic object that has an address
145 -- clause (the case in which we may want to issue a warning).
147 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean;
148 -- Determine whether E is an access type declared by an access declaration,
149 -- and not an (anonymous) allocator type.
151 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean;
152 -- Utility to check whether the entity for an operator is a predefined
153 -- operator, in which case the expression is left as an operator in the
154 -- tree (else it is rewritten into a call). An instance of an intrinsic
155 -- conversion operation may be given an operator name, but is not treated
156 -- like an operator. Note that an operator that is an imported back-end
157 -- builtin has convention Intrinsic, but is expected to be rewritten into
158 -- a call, so such an operator is not treated as predefined by this
161 procedure Preanalyze_And_Resolve
164 With_Freezing
: Boolean);
165 -- Subsidiary of public versions of Preanalyze_And_Resolve.
167 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
);
168 -- If a default expression in entry call N depends on the discriminants
169 -- of the task, it must be replaced with a reference to the discriminant
170 -- of the task being called.
172 procedure Resolve_Op_Concat_Arg
177 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
178 -- concatenation operator. The operand is either of the array type or of
179 -- the component type. If the operand is an aggregate, and the component
180 -- type is composite, this is ambiguous if component type has aggregates.
182 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
);
183 -- Does the first part of the work of Resolve_Op_Concat
185 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
);
186 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
187 -- has been resolved. See Resolve_Op_Concat for details.
189 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
);
190 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
);
191 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
);
192 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
193 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
194 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
);
195 procedure Resolve_Declare_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
196 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
);
197 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
);
198 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
);
199 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
);
200 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
201 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
);
202 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
);
203 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
204 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
);
205 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
);
206 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
);
207 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
);
208 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
);
209 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
);
210 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
);
211 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
212 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
213 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
);
214 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
215 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
);
216 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
);
217 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
);
218 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
);
219 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
);
220 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
221 procedure Resolve_Target_Name
(N
: Node_Id
; Typ
: Entity_Id
);
222 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
223 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
);
224 procedure Resolve_Unchecked_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
225 procedure Resolve_Unchecked_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
227 function Operator_Kind
229 Is_Binary
: Boolean) return Node_Kind
;
230 -- Utility to map the name of an operator into the corresponding Node. Used
231 -- by other node rewriting procedures.
233 procedure Resolve_Actuals
(N
: Node_Id
; Nam
: Entity_Id
);
234 -- Resolve actuals of call, and add default expressions for missing ones.
235 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
236 -- called subprogram.
238 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
);
239 -- Called from Resolve_Call, when the prefix denotes an entry or element
240 -- of entry family. Actuals are resolved as for subprograms, and the node
241 -- is rebuilt as an entry call. Also called for protected operations. Typ
242 -- is the context type, which is used when the operation is a protected
243 -- function with no arguments, and the return value is indexed.
245 procedure Resolve_Implicit_Dereference
(P
: Node_Id
);
246 -- Called when P is the prefix of an indexed component, or of a selected
247 -- component, or of a slice. If P is of an access type, we unconditionally
248 -- rewrite it as an explicit dereference. This ensures that the expander
249 -- and the code generator have a fully explicit tree to work with.
251 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
252 -- A call to a user-defined intrinsic operator is rewritten as a call to
253 -- the corresponding predefined operator, with suitable conversions. Note
254 -- that this applies only for intrinsic operators that denote predefined
255 -- operators, not ones that are intrinsic imports of back-end builtins.
257 procedure Resolve_Intrinsic_Unary_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
258 -- Ditto, for arithmetic unary operators
260 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
);
261 -- If an operator node resolves to a call to a user-defined operator,
262 -- rewrite the node as a function call.
264 procedure Make_Call_Into_Operator
268 -- Inverse transformation: if an operator is given in functional notation,
269 -- then after resolving the node, transform into an operator node, so that
270 -- operands are resolved properly. Recall that predefined operators do not
271 -- have a full signature and special resolution rules apply.
273 procedure Rewrite_Renamed_Operator
277 -- An operator can rename another, e.g. in an instantiation. In that
278 -- case, the proper operator node must be constructed and resolved.
280 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
);
281 -- The String_Literal_Subtype is built for all strings that are not
282 -- operands of a static concatenation operation. If the argument is not
283 -- a N_String_Literal node, then the call has no effect.
285 procedure Set_Slice_Subtype
(N
: Node_Id
);
286 -- Build subtype of array type, with the range specified by the slice
288 procedure Simplify_Type_Conversion
(N
: Node_Id
);
289 -- Called after N has been resolved and evaluated, but before range checks
290 -- have been applied. This rewrites the conversion into a simpler form.
292 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
;
293 -- A universal_fixed expression in an universal context is unambiguous if
294 -- there is only one applicable fixed point type. Determining whether there
295 -- is only one requires a search over all visible entities, and happens
296 -- only in very pathological cases (see 6115-006).
298 function Try_User_Defined_Literal
300 Typ
: Entity_Id
) return Boolean;
301 -- If an operator node has a literal operand, check whether the type
302 -- of the context, or the type of the other operand has a user-defined
303 -- literal aspect that can be applied to the literal to resolve the node.
304 -- If such aspect exists, replace literal with a call to the
305 -- corresponding function and return True, return false otherwise.
307 -------------------------
308 -- Ambiguous_Character --
309 -------------------------
311 procedure Ambiguous_Character
(C
: Node_Id
) is
315 if Nkind
(C
) = N_Character_Literal
then
316 Error_Msg_N
("ambiguous character literal", C
);
318 -- First the ones in Standard
320 Error_Msg_N
("\\possible interpretation: Character!", C
);
321 Error_Msg_N
("\\possible interpretation: Wide_Character!", C
);
323 -- Include Wide_Wide_Character in Ada 2005 mode
325 if Ada_Version
>= Ada_2005
then
326 Error_Msg_N
("\\possible interpretation: Wide_Wide_Character!", C
);
329 -- Now any other types that match
331 E
:= Current_Entity
(C
);
332 while Present
(E
) loop
333 Error_Msg_NE
("\\possible interpretation:}!", C
, Etype
(E
));
337 end Ambiguous_Character
;
339 -------------------------
340 -- Analyze_And_Resolve --
341 -------------------------
343 procedure Analyze_And_Resolve
(N
: Node_Id
) is
347 end Analyze_And_Resolve
;
349 procedure Analyze_And_Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
353 end Analyze_And_Resolve
;
355 -- Versions with check(s) suppressed
357 procedure Analyze_And_Resolve
362 Scop
: constant Entity_Id
:= Current_Scope
;
365 if Suppress
= All_Checks
then
367 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
369 Scope_Suppress
.Suppress
:= (others => True);
370 Analyze_And_Resolve
(N
, Typ
);
371 Scope_Suppress
.Suppress
:= Sva
;
376 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
378 Scope_Suppress
.Suppress
(Suppress
) := True;
379 Analyze_And_Resolve
(N
, Typ
);
380 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
384 if Current_Scope
/= Scop
385 and then Scope_Is_Transient
387 -- This can only happen if a transient scope was created for an inner
388 -- expression, which will be removed upon completion of the analysis
389 -- of an enclosing construct. The transient scope must have the
390 -- suppress status of the enclosing environment, not of this Analyze
393 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
396 end Analyze_And_Resolve
;
398 procedure Analyze_And_Resolve
402 Scop
: constant Entity_Id
:= Current_Scope
;
405 if Suppress
= All_Checks
then
407 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
409 Scope_Suppress
.Suppress
:= (others => True);
410 Analyze_And_Resolve
(N
);
411 Scope_Suppress
.Suppress
:= Sva
;
416 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
418 Scope_Suppress
.Suppress
(Suppress
) := True;
419 Analyze_And_Resolve
(N
);
420 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
424 if Current_Scope
/= Scop
and then Scope_Is_Transient
then
425 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
428 end Analyze_And_Resolve
;
430 -------------------------------------
431 -- Has_Applicable_User_Defined_Literal --
432 -------------------------------------
434 function Has_Applicable_User_Defined_Literal
436 Typ
: Entity_Id
) return Boolean
438 Loc
: constant Source_Ptr
:= Sloc
(N
);
440 constant array (N_Numeric_Or_String_Literal
) of Aspect_Id
:=
441 (N_Integer_Literal
=> Aspect_Integer_Literal
,
442 N_Real_Literal
=> Aspect_Real_Literal
,
443 N_String_Literal
=> Aspect_String_Literal
);
445 Named_Number_Aspect_Map
: constant array (Named_Kind
) of Aspect_Id
:=
446 (E_Named_Integer
=> Aspect_Integer_Literal
,
447 E_Named_Real
=> Aspect_Real_Literal
);
449 Lit_Aspect
: Aspect_Id
;
460 if (Nkind
(N
) in N_Numeric_Or_String_Literal
462 (Find_Aspect
(Typ
, Literal_Aspect_Map
(Nkind
(N
)))))
464 (Nkind
(N
) = N_Identifier
465 and then Is_Named_Number
(Entity
(N
))
469 (Typ
, Named_Number_Aspect_Map
(Ekind
(Entity
(N
))))))
472 (if Nkind
(N
) = N_Identifier
473 then Named_Number_Aspect_Map
(Ekind
(Entity
(N
)))
474 else Literal_Aspect_Map
(Nkind
(N
)));
476 Entity
(Expression
(Find_Aspect
(Typ
, Lit_Aspect
)));
477 Name
:= Make_Identifier
(Loc
, Chars
(Callee
));
479 if Is_Derived_Type
(Typ
)
480 and then Is_Tagged_Type
(Typ
)
481 and then Base_Type
(Etype
(Callee
)) /= Base_Type
(Typ
)
484 Corresponding_Primitive_Op
485 (Ancestor_Op
=> Callee
,
486 Descendant_Type
=> Base_Type
(Typ
));
489 -- Handle an identifier that denotes a named number.
491 if Nkind
(N
) = N_Identifier
then
492 Expr
:= Expression
(Declaration_Node
(Entity
(N
)));
494 if Ekind
(Entity
(N
)) = E_Named_Integer
then
495 UI_Image
(Expr_Value
(Expr
), Decimal
);
498 (UI_Image_Buffer
(1 .. UI_Image_Length
));
499 Param1
:= Make_String_Literal
(Loc
, End_String
);
500 Params
:= New_List
(Param1
);
503 UI_Image
(Norm_Num
(Expr_Value_R
(Expr
)), Decimal
);
506 if UR_Is_Negative
(Expr_Value_R
(Expr
)) then
507 Store_String_Chars
("-");
511 (UI_Image_Buffer
(1 .. UI_Image_Length
));
512 Param1
:= Make_String_Literal
(Loc
, End_String
);
514 -- Note: Set_Etype is called below on Param1
516 UI_Image
(Norm_Den
(Expr_Value_R
(Expr
)), Decimal
);
519 (UI_Image_Buffer
(1 .. UI_Image_Length
));
520 Param2
:= Make_String_Literal
(Loc
, End_String
);
521 Set_Etype
(Param2
, Standard_String
);
523 Params
:= New_List
(Param1
, Param2
);
525 if Present
(Related_Expression
(Callee
)) then
526 Callee
:= Related_Expression
(Callee
);
529 ("cannot resolve & for a named real", N
, Callee
);
534 elsif Nkind
(N
) = N_String_Literal
then
535 Param1
:= Make_String_Literal
(Loc
, Strval
(N
));
536 Params
:= New_List
(Param1
);
541 (Loc
, String_From_Numeric_Literal
(N
));
542 Params
:= New_List
(Param1
);
549 Parameter_Associations
=> Params
);
551 Set_Entity
(Name
, Callee
);
552 Set_Is_Overloaded
(Name
, False);
554 if Lit_Aspect
= Aspect_String_Literal
then
555 Set_Etype
(Param1
, Standard_Wide_Wide_String
);
557 Set_Etype
(Param1
, Standard_String
);
560 Set_Etype
(Call
, Etype
(Callee
));
562 if Base_Type
(Etype
(Call
)) /= Base_Type
(Typ
) then
563 -- Conversion may be needed in case of an inherited
564 -- aspect of a derived type. For a null extension, we
565 -- use a null extension aggregate instead because the
566 -- downward type conversion would be illegal.
568 if Is_Null_Extension_Of
570 Ancestor
=> Etype
(Call
))
572 Call
:= Make_Extension_Aggregate
(Loc
,
573 Ancestor_Part
=> Call
,
574 Null_Record_Present
=> True);
576 Call
:= Convert_To
(Typ
, Call
);
582 Analyze_And_Resolve
(N
, Typ
);
587 end Has_Applicable_User_Defined_Literal
;
589 ----------------------------
590 -- Check_Discriminant_Use --
591 ----------------------------
593 procedure Check_Discriminant_Use
(N
: Node_Id
) is
594 PN
: constant Node_Id
:= Parent
(N
);
595 Disc
: constant Entity_Id
:= Entity
(N
);
600 -- Any use in a spec-expression is legal
602 if In_Spec_Expression
then
605 elsif Nkind
(PN
) = N_Range
then
607 -- Discriminant cannot be used to constrain a scalar type
611 if Nkind
(P
) = N_Range_Constraint
612 and then Nkind
(Parent
(P
)) = N_Subtype_Indication
613 and then Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
615 Error_Msg_N
("discriminant cannot constrain scalar type", N
);
617 elsif Nkind
(P
) = N_Index_Or_Discriminant_Constraint
then
619 -- The following check catches the unusual case where a
620 -- discriminant appears within an index constraint that is part
621 -- of a larger expression within a constraint on a component,
622 -- e.g. "C : Int range 1 .. F (new A(1 .. D))". For now we only
623 -- check case of record components, and note that a similar check
624 -- should also apply in the case of discriminant constraints
627 -- Note that the check for N_Subtype_Declaration below is to
628 -- detect the valid use of discriminants in the constraints of a
629 -- subtype declaration when this subtype declaration appears
630 -- inside the scope of a record type (which is syntactically
631 -- illegal, but which may be created as part of derived type
632 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
635 if Ekind
(Current_Scope
) = E_Record_Type
636 and then Scope
(Disc
) = Current_Scope
638 (Nkind
(Parent
(P
)) = N_Subtype_Indication
640 Nkind
(Parent
(Parent
(P
))) in N_Component_Definition
641 | N_Subtype_Declaration
642 and then Paren_Count
(N
) = 0)
645 ("discriminant must appear alone in component constraint", N
);
649 -- Detect a common error:
651 -- type R (D : Positive := 100) is record
652 -- Name : String (1 .. D);
655 -- The default value causes an object of type R to be allocated
656 -- with room for Positive'Last characters. The RM does not mandate
657 -- the allocation of the maximum size, but that is what GNAT does
658 -- so we should warn the programmer that there is a problem.
660 Check_Large
: declare
666 function Large_Storage_Type
(T
: Entity_Id
) return Boolean;
667 -- Return True if type T has a large enough range that any
668 -- array whose index type covered the whole range of the type
669 -- would likely raise Storage_Error.
671 ------------------------
672 -- Large_Storage_Type --
673 ------------------------
675 function Large_Storage_Type
(T
: Entity_Id
) return Boolean is
677 -- The type is considered large if its bounds are known at
678 -- compile time and if it requires at least as many bits as
679 -- a Positive to store the possible values.
681 return Compile_Time_Known_Value
(Type_Low_Bound
(T
))
682 and then Compile_Time_Known_Value
(Type_High_Bound
(T
))
684 Minimum_Size
(T
, Biased
=> True) >=
685 RM_Size
(Standard_Positive
);
686 end Large_Storage_Type
;
688 -- Start of processing for Check_Large
691 -- Check that the Disc has a large range
693 if not Large_Storage_Type
(Etype
(Disc
)) then
697 -- If the enclosing type is limited, we allocate only the
698 -- default value, not the maximum, and there is no need for
701 if Is_Limited_Type
(Scope
(Disc
)) then
705 -- Check that it is the high bound
707 if N
/= High_Bound
(PN
)
708 or else No
(Discriminant_Default_Value
(Disc
))
713 -- Check the array allows a large range at this bound. First
718 if Nkind
(SI
) /= N_Subtype_Indication
then
722 T
:= Entity
(Subtype_Mark
(SI
));
724 if not Is_Array_Type
(T
) then
728 -- Next, find the dimension
730 TB
:= First_Index
(T
);
731 CB
:= First
(Constraints
(P
));
733 and then Present
(TB
)
734 and then Present
(CB
)
745 -- Now, check the dimension has a large range
747 if not Large_Storage_Type
(Etype
(TB
)) then
751 -- Warn about the danger
754 ("??creation of & object may raise Storage_Error!",
763 -- Legal case is in index or discriminant constraint
765 elsif Nkind
(PN
) in N_Index_Or_Discriminant_Constraint
766 | N_Discriminant_Association
768 if Paren_Count
(N
) > 0 then
770 ("discriminant in constraint must appear alone", N
);
772 elsif Nkind
(N
) = N_Expanded_Name
773 and then Comes_From_Source
(N
)
776 ("discriminant must appear alone as a direct name", N
);
781 -- Otherwise, context is an expression. It should not be within (i.e. a
782 -- subexpression of) a constraint for a component.
787 while Nkind
(P
) not in
788 N_Component_Declaration | N_Subtype_Indication | N_Entry_Declaration
795 -- If the discriminant is used in an expression that is a bound of a
796 -- scalar type, an Itype is created and the bounds are attached to
797 -- its range, not to the original subtype indication. Such use is of
798 -- course a double fault.
800 if (Nkind
(P
) = N_Subtype_Indication
801 and then Nkind
(Parent
(P
)) in N_Component_Definition
802 | N_Derived_Type_Definition
803 and then D
= Constraint
(P
))
805 -- The constraint itself may be given by a subtype indication,
806 -- rather than by a more common discrete range.
808 or else (Nkind
(P
) = N_Subtype_Indication
810 Nkind
(Parent
(P
)) = N_Index_Or_Discriminant_Constraint
)
811 or else Nkind
(P
) = N_Entry_Declaration
812 or else Nkind
(D
) = N_Defining_Identifier
815 ("discriminant in constraint must appear alone", N
);
818 end Check_Discriminant_Use
;
820 --------------------------------
821 -- Check_For_Visible_Operator --
822 --------------------------------
824 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
) is
826 if Comes_From_Source
(N
)
827 and then not Is_Visible_Operator
(Original_Node
(N
), T
)
828 and then not Error_Posted
(N
)
830 Error_Msg_NE
-- CODEFIX
831 ("operator for} is not directly visible!", N
, First_Subtype
(T
));
832 Error_Msg_N
-- CODEFIX
833 ("use clause would make operation legal!", N
);
835 end Check_For_Visible_Operator
;
837 ---------------------------------
838 -- Check_Fully_Declared_Prefix --
839 ---------------------------------
841 procedure Check_Fully_Declared_Prefix
846 -- Check that the designated type of the prefix of a dereference is
847 -- not an incomplete type. This cannot be done unconditionally, because
848 -- dereferences of private types are legal in default expressions. This
849 -- case is taken care of in Check_Fully_Declared, called below. There
850 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
852 -- This consideration also applies to similar checks for allocators,
853 -- qualified expressions, and type conversions.
855 -- An additional exception concerns other per-object expressions that
856 -- are not directly related to component declarations, in particular
857 -- representation pragmas for tasks. These will be per-object
858 -- expressions if they depend on discriminants or some global entity.
859 -- If the task has access discriminants, the designated type may be
860 -- incomplete at the point the expression is resolved. This resolution
861 -- takes place within the body of the initialization procedure, where
862 -- the discriminant is replaced by its discriminal.
864 if Is_Entity_Name
(Pref
)
865 and then Ekind
(Entity
(Pref
)) = E_In_Parameter
869 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
870 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
871 -- Analyze_Object_Renaming, and Freeze_Entity.
873 elsif Ada_Version
>= Ada_2005
874 and then Is_Entity_Name
(Pref
)
875 and then Is_Access_Type
(Etype
(Pref
))
876 and then Ekind
(Directly_Designated_Type
(Etype
(Pref
))) =
878 and then Is_Tagged_Type
(Directly_Designated_Type
(Etype
(Pref
)))
882 Check_Fully_Declared
(Typ
, Parent
(Pref
));
884 end Check_Fully_Declared_Prefix
;
886 ------------------------------
887 -- Check_Infinite_Recursion --
888 ------------------------------
890 function Check_Infinite_Recursion
(Call
: Node_Id
) return Boolean is
891 function Enclosing_Declaration_Or_Statement
(N
: Node_Id
) return Node_Id
;
892 -- Return the nearest enclosing declaration or statement that houses
895 function Invoked_With_Different_Arguments
(N
: Node_Id
) return Boolean;
896 -- Determine whether call N invokes the related enclosing subprogram
897 -- with actuals that differ from the subprogram's formals.
899 function Is_Conditional_Statement
(N
: Node_Id
) return Boolean;
900 -- Determine whether arbitrary node N denotes a conditional construct
902 function Is_Control_Flow_Statement
(N
: Node_Id
) return Boolean;
903 -- Determine whether arbitrary node N denotes a control flow statement
904 -- or a construct that may contains such a statement.
906 function Is_Immediately_Within_Body
(N
: Node_Id
) return Boolean;
907 -- Determine whether arbitrary node N appears immediately within the
908 -- statements of an entry or subprogram body.
910 function Is_Raise_Idiom
(N
: Node_Id
) return Boolean;
911 -- Determine whether arbitrary node N appears immediately within the
912 -- body of an entry or subprogram, and is preceded by a single raise
915 function Is_Raise_Statement
(N
: Node_Id
) return Boolean;
916 -- Determine whether arbitrary node N denotes a raise statement
918 function Is_Sole_Statement
(N
: Node_Id
) return Boolean;
919 -- Determine whether arbitrary node N is the sole source statement in
920 -- the body of the enclosing subprogram.
922 function Preceded_By_Control_Flow_Statement
(N
: Node_Id
) return Boolean;
923 -- Determine whether arbitrary node N is preceded by a control flow
926 function Within_Conditional_Statement
(N
: Node_Id
) return Boolean;
927 -- Determine whether arbitrary node N appears within a conditional
930 ----------------------------------------
931 -- Enclosing_Declaration_Or_Statement --
932 ----------------------------------------
934 function Enclosing_Declaration_Or_Statement
935 (N
: Node_Id
) return Node_Id
941 while Present
(Par
) loop
942 if Is_Declaration
(Par
) or else Is_Statement
(Par
) then
945 -- Prevent the search from going too far
947 elsif Is_Body_Or_Package_Declaration
(Par
) then
955 end Enclosing_Declaration_Or_Statement
;
957 --------------------------------------
958 -- Invoked_With_Different_Arguments --
959 --------------------------------------
961 function Invoked_With_Different_Arguments
(N
: Node_Id
) return Boolean is
962 Subp
: constant Entity_Id
:= Entity
(Name
(N
));
968 -- Determine whether the formals of the invoked subprogram are not
969 -- used as actuals in the call.
971 Actual
:= First_Actual
(Call
);
972 Formal
:= First_Formal
(Subp
);
973 while Present
(Actual
) and then Present
(Formal
) loop
975 -- The current actual does not match the current formal
977 if not (Is_Entity_Name
(Actual
)
978 and then Entity
(Actual
) = Formal
)
983 Next_Actual
(Actual
);
984 Next_Formal
(Formal
);
988 end Invoked_With_Different_Arguments
;
990 ------------------------------
991 -- Is_Conditional_Statement --
992 ------------------------------
994 function Is_Conditional_Statement
(N
: Node_Id
) return Boolean is
997 Nkind
(N
) in N_And_Then
1003 end Is_Conditional_Statement
;
1005 -------------------------------
1006 -- Is_Control_Flow_Statement --
1007 -------------------------------
1009 function Is_Control_Flow_Statement
(N
: Node_Id
) return Boolean is
1011 -- It is assumed that all statements may affect the control flow in
1012 -- some way. A raise statement may be expanded into a non-statement
1015 return Is_Statement
(N
) or else Is_Raise_Statement
(N
);
1016 end Is_Control_Flow_Statement
;
1018 --------------------------------
1019 -- Is_Immediately_Within_Body --
1020 --------------------------------
1022 function Is_Immediately_Within_Body
(N
: Node_Id
) return Boolean is
1023 HSS
: constant Node_Id
:= Parent
(N
);
1027 Nkind
(HSS
) = N_Handled_Sequence_Of_Statements
1028 and then Nkind
(Parent
(HSS
)) in N_Entry_Body | N_Subprogram_Body
1029 and then Is_List_Member
(N
)
1030 and then List_Containing
(N
) = Statements
(HSS
);
1031 end Is_Immediately_Within_Body
;
1033 --------------------
1034 -- Is_Raise_Idiom --
1035 --------------------
1037 function Is_Raise_Idiom
(N
: Node_Id
) return Boolean is
1038 Raise_Stmt
: Node_Id
;
1042 if Is_Immediately_Within_Body
(N
) then
1044 -- Assume that no raise statement has been seen yet
1046 Raise_Stmt
:= Empty
;
1048 -- Examine the statements preceding the input node, skipping
1049 -- internally-generated constructs.
1052 while Present
(Stmt
) loop
1054 -- Multiple raise statements violate the idiom
1056 if Is_Raise_Statement
(Stmt
) then
1057 if Present
(Raise_Stmt
) then
1063 elsif Comes_From_Source
(Stmt
) then
1067 Stmt
:= Prev
(Stmt
);
1070 -- At this point the node must be preceded by a raise statement,
1071 -- and the raise statement has to be the sole statement within
1072 -- the enclosing entry or subprogram body.
1075 Present
(Raise_Stmt
) and then Is_Sole_Statement
(Raise_Stmt
);
1081 ------------------------
1082 -- Is_Raise_Statement --
1083 ------------------------
1085 function Is_Raise_Statement
(N
: Node_Id
) return Boolean is
1087 -- A raise statement may be transfomed into a Raise_xxx_Error node
1090 Nkind
(N
) = N_Raise_Statement
1091 or else Nkind
(N
) in N_Raise_xxx_Error
;
1092 end Is_Raise_Statement
;
1094 -----------------------
1095 -- Is_Sole_Statement --
1096 -----------------------
1098 function Is_Sole_Statement
(N
: Node_Id
) return Boolean is
1102 -- The input node appears within the statements of an entry or
1103 -- subprogram body. Examine the statements preceding the node.
1105 if Is_Immediately_Within_Body
(N
) then
1108 while Present
(Stmt
) loop
1110 -- The statement is preceded by another statement or a source
1111 -- construct. This indicates that the node does not appear by
1114 if Is_Control_Flow_Statement
(Stmt
)
1115 or else Comes_From_Source
(Stmt
)
1120 Stmt
:= Prev
(Stmt
);
1126 -- The input node is within a construct nested inside the entry or
1130 end Is_Sole_Statement
;
1132 ----------------------------------------
1133 -- Preceded_By_Control_Flow_Statement --
1134 ----------------------------------------
1136 function Preceded_By_Control_Flow_Statement
1137 (N
: Node_Id
) return Boolean
1142 if Is_List_Member
(N
) then
1145 -- Examine the statements preceding the input node
1147 while Present
(Stmt
) loop
1148 if Is_Control_Flow_Statement
(Stmt
) then
1152 Stmt
:= Prev
(Stmt
);
1158 -- Assume that the node is part of some control flow statement
1161 end Preceded_By_Control_Flow_Statement
;
1163 ----------------------------------
1164 -- Within_Conditional_Statement --
1165 ----------------------------------
1167 function Within_Conditional_Statement
(N
: Node_Id
) return Boolean is
1172 while Present
(Stmt
) loop
1173 if Is_Conditional_Statement
(Stmt
) then
1176 -- Prevent the search from going too far
1178 elsif Is_Body_Or_Package_Declaration
(Stmt
) then
1182 Stmt
:= Parent
(Stmt
);
1186 end Within_Conditional_Statement
;
1190 Call_Context
: constant Node_Id
:=
1191 Enclosing_Declaration_Or_Statement
(Call
);
1193 -- Start of processing for Check_Infinite_Recursion
1196 -- The call is assumed to be safe when the enclosing subprogram is
1197 -- invoked with actuals other than its formals.
1199 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1202 -- Proc (A1, A2, ..., AN);
1206 if Invoked_With_Different_Arguments
(Call
) then
1209 -- The call is assumed to be safe when the invocation of the enclosing
1210 -- subprogram depends on a conditional statement.
1212 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1215 -- if Some_Condition then
1216 -- Proc (F1, F2, ..., FN);
1221 elsif Within_Conditional_Statement
(Call
) then
1224 -- The context of the call is assumed to be safe when the invocation of
1225 -- the enclosing subprogram is preceded by some control flow statement.
1227 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1230 -- if Some_Condition then
1234 -- Proc (F1, F2, ..., FN);
1238 elsif Preceded_By_Control_Flow_Statement
(Call_Context
) then
1241 -- Detect an idiom where the context of the call is preceded by a single
1244 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1247 -- Proc (F1, F2, ..., FN);
1250 elsif Is_Raise_Idiom
(Call_Context
) then
1254 -- At this point it is certain that infinite recursion will take place
1255 -- as long as the call is executed. Detect a case where the context of
1256 -- the call is the sole source statement within the subprogram body.
1258 -- procedure Proc (F1 : ...; F2 : ...; ...; FN : ...) is
1260 -- Proc (F1, F2, ..., FN);
1263 -- Install an explicit raise to prevent the infinite recursion.
1265 if Is_Sole_Statement
(Call_Context
) then
1266 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1267 Error_Msg_N
("!infinite recursion<<", Call
);
1268 Error_Msg_N
("\!Storage_Error [<<", Call
);
1270 Insert_Action
(Call
,
1271 Make_Raise_Storage_Error
(Sloc
(Call
),
1272 Reason
=> SE_Infinite_Recursion
));
1274 -- Otherwise infinite recursion could take place, considering other flow
1275 -- control constructs such as gotos, exit statements, etc.
1278 Error_Msg_Warn
:= SPARK_Mode
/= On
;
1279 Error_Msg_N
("!possible infinite recursion<<", Call
);
1280 Error_Msg_N
("\!??Storage_Error ]<<", Call
);
1284 end Check_Infinite_Recursion
;
1286 ---------------------------------------
1287 -- Check_No_Direct_Boolean_Operators --
1288 ---------------------------------------
1290 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
) is
1292 if Scope
(Entity
(N
)) = Standard_Standard
1293 and then Root_Type
(Etype
(Left_Opnd
(N
))) = Standard_Boolean
1295 -- Restriction only applies to original source code
1297 if Comes_From_Source
(N
) then
1298 Check_Restriction
(No_Direct_Boolean_Operators
, N
);
1302 -- Do style check (but skip if in instance, error is on template)
1305 if not In_Instance
then
1306 Check_Boolean_Operator
(N
);
1309 end Check_No_Direct_Boolean_Operators
;
1311 ------------------------------
1312 -- Check_Parameterless_Call --
1313 ------------------------------
1315 procedure Check_Parameterless_Call
(N
: Node_Id
) is
1318 function Prefix_Is_Access_Subp
return Boolean;
1319 -- If the prefix is of an access_to_subprogram type, the node must be
1320 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1321 -- interpretations are access to subprograms.
1323 ---------------------------
1324 -- Prefix_Is_Access_Subp --
1325 ---------------------------
1327 function Prefix_Is_Access_Subp
return Boolean is
1332 -- If the context is an attribute reference that can apply to
1333 -- functions, this is never a parameterless call (RM 4.1.4(6)).
1335 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1336 and then Attribute_Name
(Parent
(N
))
1337 in Name_Address | Name_Code_Address | Name_Access
1342 if not Is_Overloaded
(N
) then
1344 Ekind
(Etype
(N
)) = E_Subprogram_Type
1345 and then Base_Type
(Etype
(Etype
(N
))) /= Standard_Void_Type
;
1347 Get_First_Interp
(N
, I
, It
);
1348 while Present
(It
.Typ
) loop
1349 if Ekind
(It
.Typ
) /= E_Subprogram_Type
1350 or else Base_Type
(Etype
(It
.Typ
)) = Standard_Void_Type
1355 Get_Next_Interp
(I
, It
);
1360 end Prefix_Is_Access_Subp
;
1362 -- Start of processing for Check_Parameterless_Call
1365 -- Defend against junk stuff if errors already detected
1367 if Total_Errors_Detected
/= 0 then
1368 if Nkind
(N
) in N_Has_Etype
and then Etype
(N
) = Any_Type
then
1370 elsif Nkind
(N
) in N_Has_Chars
1371 and then not Is_Valid_Name
(Chars
(N
))
1379 -- If the context expects a value, and the name is a procedure, this is
1380 -- most likely a missing 'Access. Don't try to resolve the parameterless
1381 -- call, error will be caught when the outer call is analyzed.
1383 if Is_Entity_Name
(N
)
1384 and then Ekind
(Entity
(N
)) = E_Procedure
1385 and then not Is_Overloaded
(N
)
1387 Nkind
(Parent
(N
)) in N_Parameter_Association
1389 | N_Procedure_Call_Statement
1394 -- Rewrite as call if overloadable entity that is (or could be, in the
1395 -- overloaded case) a function call. If we know for sure that the entity
1396 -- is an enumeration literal, we do not rewrite it.
1398 -- If the entity is the name of an operator, it cannot be a call because
1399 -- operators cannot have default parameters. In this case, this must be
1400 -- a string whose contents coincide with an operator name. Set the kind
1401 -- of the node appropriately.
1403 if (Is_Entity_Name
(N
)
1404 and then Nkind
(N
) /= N_Operator_Symbol
1405 and then Is_Overloadable
(Entity
(N
))
1406 and then (Ekind
(Entity
(N
)) /= E_Enumeration_Literal
1407 or else Is_Overloaded
(N
)))
1409 -- Rewrite as call if it is an explicit dereference of an expression of
1410 -- a subprogram access type, and the subprogram type is not that of a
1411 -- procedure or entry.
1414 (Nkind
(N
) = N_Explicit_Dereference
and then Prefix_Is_Access_Subp
)
1416 -- Rewrite as call if it is a selected component which is a function,
1417 -- this is the case of a call to a protected function (which may be
1418 -- overloaded with other protected operations).
1421 (Nkind
(N
) = N_Selected_Component
1422 and then (Ekind
(Entity
(Selector_Name
(N
))) = E_Function
1424 (Ekind
(Entity
(Selector_Name
(N
))) in
1425 E_Entry | E_Procedure
1426 and then Is_Overloaded
(Selector_Name
(N
)))))
1428 -- If one of the above three conditions is met, rewrite as call. Apply
1429 -- the rewriting only once.
1432 if Nkind
(Parent
(N
)) /= N_Function_Call
1433 or else N
/= Name
(Parent
(N
))
1436 -- This may be a prefixed call that was not fully analyzed, e.g.
1437 -- an actual in an instance.
1439 if Ada_Version
>= Ada_2005
1440 and then Nkind
(N
) = N_Selected_Component
1441 and then Is_Dispatching_Operation
(Entity
(Selector_Name
(N
)))
1443 Analyze_Selected_Component
(N
);
1445 if Nkind
(N
) /= N_Selected_Component
then
1450 -- The node is the name of the parameterless call. Preserve its
1451 -- descendants, which may be complex expressions.
1453 Nam
:= Relocate_Node
(N
);
1455 -- If overloaded, overload set belongs to new copy
1457 Save_Interps
(N
, Nam
);
1459 -- Change node to parameterless function call (note that the
1460 -- Parameter_Associations associations field is left set to Empty,
1461 -- its normal default value since there are no parameters)
1463 Change_Node
(N
, N_Function_Call
);
1465 Set_Sloc
(N
, Sloc
(Nam
));
1469 elsif Nkind
(N
) = N_Parameter_Association
then
1470 Check_Parameterless_Call
(Explicit_Actual_Parameter
(N
));
1472 elsif Nkind
(N
) = N_Operator_Symbol
then
1473 Set_Etype
(N
, Empty
);
1474 Set_Entity
(N
, Empty
);
1475 Set_Is_Overloaded
(N
, False);
1476 Change_Operator_Symbol_To_String_Literal
(N
);
1477 Set_Etype
(N
, Any_String
);
1479 end Check_Parameterless_Call
;
1481 --------------------------------
1482 -- Is_Atomic_Ref_With_Address --
1483 --------------------------------
1485 function Is_Atomic_Ref_With_Address
(N
: Node_Id
) return Boolean is
1486 Pref
: constant Node_Id
:= Prefix
(N
);
1489 if not Is_Entity_Name
(Pref
) then
1494 Pent
: constant Entity_Id
:= Entity
(Pref
);
1495 Ptyp
: constant Entity_Id
:= Etype
(Pent
);
1497 return not Is_Access_Type
(Ptyp
)
1498 and then (Is_Atomic
(Ptyp
) or else Is_Atomic
(Pent
))
1499 and then Present
(Address_Clause
(Pent
));
1502 end Is_Atomic_Ref_With_Address
;
1504 -----------------------------
1505 -- Is_Definite_Access_Type --
1506 -----------------------------
1508 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean is
1509 Btyp
: constant Entity_Id
:= Base_Type
(E
);
1511 return Ekind
(Btyp
) = E_Access_Type
1512 or else (Ekind
(Btyp
) = E_Access_Subprogram_Type
1513 and then Comes_From_Source
(Btyp
));
1514 end Is_Definite_Access_Type
;
1516 ----------------------
1517 -- Is_Predefined_Op --
1518 ----------------------
1520 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean is
1522 -- Predefined operators are intrinsic subprograms
1524 if not Is_Intrinsic_Subprogram
(Nam
) then
1528 -- A call to a back-end builtin is never a predefined operator
1530 if Is_Imported
(Nam
) and then Present
(Interface_Name
(Nam
)) then
1534 return not Is_Generic_Instance
(Nam
)
1535 and then Chars
(Nam
) in Any_Operator_Name
1536 and then (No
(Alias
(Nam
)) or else Is_Predefined_Op
(Alias
(Nam
)));
1537 end Is_Predefined_Op
;
1539 -----------------------------
1540 -- Make_Call_Into_Operator --
1541 -----------------------------
1543 procedure Make_Call_Into_Operator
1548 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
1549 Act1
: Node_Id
:= First_Actual
(N
);
1550 Act2
: Node_Id
:= Next_Actual
(Act1
);
1551 Error
: Boolean := False;
1552 Func
: constant Entity_Id
:= Entity
(Name
(N
));
1553 Is_Binary
: constant Boolean := Present
(Act2
);
1555 Opnd_Type
: Entity_Id
:= Empty
;
1556 Orig_Type
: Entity_Id
:= Empty
;
1559 type Kind_Test
is access function (E
: Entity_Id
) return Boolean;
1561 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean;
1562 -- If the operand is not universal, and the operator is given by an
1563 -- expanded name, verify that the operand has an interpretation with a
1564 -- type defined in the given scope of the operator.
1566 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
;
1567 -- Find a type of the given class in package Pack that contains the
1570 ---------------------------
1571 -- Operand_Type_In_Scope --
1572 ---------------------------
1574 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean is
1575 Nod
: constant Node_Id
:= Right_Opnd
(Op_Node
);
1580 if not Is_Overloaded
(Nod
) then
1581 return Scope
(Base_Type
(Etype
(Nod
))) = S
;
1584 Get_First_Interp
(Nod
, I
, It
);
1585 while Present
(It
.Typ
) loop
1586 if Scope
(Base_Type
(It
.Typ
)) = S
then
1590 Get_Next_Interp
(I
, It
);
1595 end Operand_Type_In_Scope
;
1601 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
is
1604 function In_Decl
return Boolean;
1605 -- Verify that node is not part of the type declaration for the
1606 -- candidate type, which would otherwise be invisible.
1612 function In_Decl
return Boolean is
1613 Decl_Node
: constant Node_Id
:= Parent
(E
);
1619 if Etype
(E
) = Any_Type
then
1622 elsif No
(Decl_Node
) then
1627 and then Nkind
(N2
) /= N_Compilation_Unit
1629 if N2
= Decl_Node
then
1640 -- Start of processing for Type_In_P
1643 -- If the context type is declared in the prefix package, this is the
1644 -- desired base type.
1646 if Scope
(Base_Type
(Typ
)) = Pack
and then Test
(Typ
) then
1647 return Base_Type
(Typ
);
1650 E
:= First_Entity
(Pack
);
1651 while Present
(E
) loop
1652 if Test
(E
) and then not In_Decl
then
1663 -- Start of processing for Make_Call_Into_Operator
1666 Op_Node
:= New_Node
(Operator_Kind
(Op_Name
, Is_Binary
), Sloc
(N
));
1668 -- Preserve the Comes_From_Source flag on the result if the original
1669 -- call came from source. Although it is not strictly the case that the
1670 -- operator as such comes from the source, logically it corresponds
1671 -- exactly to the function call in the source, so it should be marked
1672 -- this way (e.g. to make sure that validity checks work fine).
1674 Preserve_Comes_From_Source
(Op_Node
, N
);
1676 -- Ensure that the corresponding operator has the same parent as the
1677 -- original call. This guarantees that parent traversals performed by
1678 -- the ABE mechanism succeed.
1680 Set_Parent
(Op_Node
, Parent
(N
));
1685 Set_Left_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1686 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act2
));
1687 Save_Interps
(Act1
, Left_Opnd
(Op_Node
));
1688 Save_Interps
(Act2
, Right_Opnd
(Op_Node
));
1689 Act1
:= Left_Opnd
(Op_Node
);
1690 Act2
:= Right_Opnd
(Op_Node
);
1695 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1696 Save_Interps
(Act1
, Right_Opnd
(Op_Node
));
1697 Act1
:= Right_Opnd
(Op_Node
);
1700 -- If the operator is denoted by an expanded name, and the prefix is
1701 -- not Standard, but the operator is a predefined one whose scope is
1702 -- Standard, then this is an implicit_operator, inserted as an
1703 -- interpretation by the procedure of the same name. This procedure
1704 -- overestimates the presence of implicit operators, because it does
1705 -- not examine the type of the operands. Verify now that the operand
1706 -- type appears in the given scope. If right operand is universal,
1707 -- check the other operand. In the case of concatenation, either
1708 -- argument can be the component type, so check the type of the result.
1709 -- If both arguments are literals, look for a type of the right kind
1710 -- defined in the given scope. This elaborate nonsense is brought to
1711 -- you courtesy of b33302a. The type itself must be frozen, so we must
1712 -- find the type of the proper class in the given scope.
1714 -- A final wrinkle is the multiplication operator for fixed point types,
1715 -- which is defined in Standard only, and not in the scope of the
1716 -- fixed point type itself.
1718 if Nkind
(Name
(N
)) = N_Expanded_Name
then
1719 Pack
:= Entity
(Prefix
(Name
(N
)));
1721 -- If this is a package renaming, get renamed entity, which will be
1722 -- the scope of the operands if operaton is type-correct.
1724 if Present
(Renamed_Entity
(Pack
)) then
1725 Pack
:= Renamed_Entity
(Pack
);
1728 -- If the entity being called is defined in the given package, it is
1729 -- a renaming of a predefined operator, and known to be legal.
1731 if Scope
(Entity
(Name
(N
))) = Pack
1732 and then Pack
/= Standard_Standard
1736 -- Visibility does not need to be checked in an instance: if the
1737 -- operator was not visible in the generic it has been diagnosed
1738 -- already, else there is an implicit copy of it in the instance.
1740 elsif In_Instance
then
1743 elsif Op_Name
in Name_Op_Multiply | Name_Op_Divide
1744 and then Is_Fixed_Point_Type
(Etype
(Act1
))
1745 and then Is_Fixed_Point_Type
(Etype
(Act2
))
1747 if Pack
/= Standard_Standard
then
1751 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1754 elsif Ada_Version
>= Ada_2005
1755 and then Op_Name
in Name_Op_Eq | Name_Op_Ne
1756 and then (Is_Anonymous_Access_Type
(Etype
(Act1
))
1757 or else Is_Anonymous_Access_Type
(Etype
(Act2
)))
1762 Opnd_Type
:= Base_Type
(Etype
(Right_Opnd
(Op_Node
)));
1764 if Op_Name
= Name_Op_Concat
then
1765 Opnd_Type
:= Base_Type
(Typ
);
1767 elsif (Scope
(Opnd_Type
) = Standard_Standard
1769 or else (Nkind
(Right_Opnd
(Op_Node
)) = N_Attribute_Reference
1771 and then not Comes_From_Source
(Opnd_Type
))
1773 Opnd_Type
:= Base_Type
(Etype
(Left_Opnd
(Op_Node
)));
1776 if Scope
(Opnd_Type
) = Standard_Standard
then
1778 -- Verify that the scope contains a type that corresponds to
1779 -- the given literal. Optimize the case where Pack is Standard.
1781 if Pack
/= Standard_Standard
then
1782 if Opnd_Type
= Universal_Integer
then
1783 Orig_Type
:= Type_In_P
(Is_Integer_Type
'Access);
1785 elsif Opnd_Type
= Universal_Real
then
1786 Orig_Type
:= Type_In_P
(Is_Real_Type
'Access);
1788 elsif Opnd_Type
= Universal_Access
then
1789 Orig_Type
:= Type_In_P
(Is_Definite_Access_Type
'Access);
1791 elsif Opnd_Type
= Any_String
then
1792 Orig_Type
:= Type_In_P
(Is_String_Type
'Access);
1794 elsif Opnd_Type
= Any_Composite
then
1795 Orig_Type
:= Type_In_P
(Is_Composite_Type
'Access);
1797 if Present
(Orig_Type
) then
1798 if Has_Private_Component
(Orig_Type
) then
1801 Set_Etype
(Act1
, Orig_Type
);
1804 Set_Etype
(Act2
, Orig_Type
);
1813 Error
:= No
(Orig_Type
);
1816 elsif Ekind
(Opnd_Type
) = E_Allocator_Type
1817 and then No
(Type_In_P
(Is_Definite_Access_Type
'Access))
1821 -- If the type is defined elsewhere, and the operator is not
1822 -- defined in the given scope (by a renaming declaration, e.g.)
1823 -- then this is an error as well. If an extension of System is
1824 -- present, and the type may be defined there, Pack must be
1827 elsif Scope
(Opnd_Type
) /= Pack
1828 and then Scope
(Op_Id
) /= Pack
1829 and then (No
(System_Aux_Id
)
1830 or else Scope
(Opnd_Type
) /= System_Aux_Id
1831 or else Pack
/= Scope
(System_Aux_Id
))
1833 if not Is_Overloaded
(Right_Opnd
(Op_Node
)) then
1836 Error
:= not Operand_Type_In_Scope
(Pack
);
1839 elsif Pack
= Standard_Standard
1840 and then not Operand_Type_In_Scope
(Standard_Standard
)
1847 Error_Msg_Node_2
:= Pack
;
1849 ("& not declared in&", N
, Selector_Name
(Name
(N
)));
1850 Set_Etype
(N
, Any_Type
);
1853 -- Detect a mismatch between the context type and the result type
1854 -- in the named package, which is otherwise not detected if the
1855 -- operands are universal. Check is only needed if source entity is
1856 -- an operator, not a function that renames an operator.
1858 elsif Nkind
(Parent
(N
)) /= N_Type_Conversion
1859 and then Ekind
(Entity
(Name
(N
))) = E_Operator
1860 and then Is_Numeric_Type
(Typ
)
1861 and then not Is_Universal_Numeric_Type
(Typ
)
1862 and then Scope
(Base_Type
(Typ
)) /= Pack
1863 and then not In_Instance
1865 if Is_Fixed_Point_Type
(Typ
)
1866 and then Op_Name
in Name_Op_Multiply | Name_Op_Divide
1868 -- Already checked above
1872 -- Operator may be defined in an extension of System
1874 elsif Present
(System_Aux_Id
)
1875 and then Present
(Opnd_Type
)
1876 and then Scope
(Opnd_Type
) = System_Aux_Id
1881 -- Could we use Wrong_Type here??? (this would require setting
1882 -- Etype (N) to the actual type found where Typ was expected).
1884 Error_Msg_NE
("expect }", N
, Typ
);
1889 Set_Chars
(Op_Node
, Op_Name
);
1891 if not Is_Private_Type
(Etype
(N
)) then
1892 Set_Etype
(Op_Node
, Base_Type
(Etype
(N
)));
1894 Set_Etype
(Op_Node
, Etype
(N
));
1897 -- If this is a call to a function that renames a predefined equality,
1898 -- the renaming declaration provides a type that must be used to
1899 -- resolve the operands. This must be done now because resolution of
1900 -- the equality node will not resolve any remaining ambiguity, and it
1901 -- assumes that the first operand is not overloaded.
1903 if Op_Name
in Name_Op_Eq | Name_Op_Ne
1904 and then Ekind
(Func
) = E_Function
1905 and then Is_Overloaded
(Act1
)
1907 Resolve
(Act1
, Base_Type
(Etype
(First_Formal
(Func
))));
1908 Resolve
(Act2
, Base_Type
(Etype
(First_Formal
(Func
))));
1911 Set_Entity
(Op_Node
, Op_Id
);
1912 Generate_Reference
(Op_Id
, N
, ' ');
1914 Rewrite
(N
, Op_Node
);
1916 -- If this is an arithmetic operator and the result type is private,
1917 -- the operands and the result must be wrapped in conversion to
1918 -- expose the underlying numeric type and expand the proper checks,
1919 -- e.g. on division.
1921 if Is_Private_Type
(Typ
) then
1931 Resolve_Intrinsic_Operator
(N
, Typ
);
1937 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
1945 end Make_Call_Into_Operator
;
1951 function Operator_Kind
1953 Is_Binary
: Boolean) return Node_Kind
1958 -- Use CASE statement or array???
1961 if Op_Name
= Name_Op_And
then
1963 elsif Op_Name
= Name_Op_Or
then
1965 elsif Op_Name
= Name_Op_Xor
then
1967 elsif Op_Name
= Name_Op_Eq
then
1969 elsif Op_Name
= Name_Op_Ne
then
1971 elsif Op_Name
= Name_Op_Lt
then
1973 elsif Op_Name
= Name_Op_Le
then
1975 elsif Op_Name
= Name_Op_Gt
then
1977 elsif Op_Name
= Name_Op_Ge
then
1979 elsif Op_Name
= Name_Op_Add
then
1981 elsif Op_Name
= Name_Op_Subtract
then
1982 Kind
:= N_Op_Subtract
;
1983 elsif Op_Name
= Name_Op_Concat
then
1984 Kind
:= N_Op_Concat
;
1985 elsif Op_Name
= Name_Op_Multiply
then
1986 Kind
:= N_Op_Multiply
;
1987 elsif Op_Name
= Name_Op_Divide
then
1988 Kind
:= N_Op_Divide
;
1989 elsif Op_Name
= Name_Op_Mod
then
1991 elsif Op_Name
= Name_Op_Rem
then
1993 elsif Op_Name
= Name_Op_Expon
then
1996 raise Program_Error
;
2002 if Op_Name
= Name_Op_Add
then
2004 elsif Op_Name
= Name_Op_Subtract
then
2006 elsif Op_Name
= Name_Op_Abs
then
2008 elsif Op_Name
= Name_Op_Not
then
2011 raise Program_Error
;
2018 ----------------------------
2019 -- Preanalyze_And_Resolve --
2020 ----------------------------
2022 procedure Preanalyze_And_Resolve
2025 With_Freezing
: Boolean)
2027 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
2028 Save_Must_Not_Freeze
: constant Boolean := Must_Not_Freeze
(N
);
2029 Save_Preanalysis_Count
: constant Nat
:=
2030 Inside_Preanalysis_Without_Freezing
;
2032 pragma Assert
(Nkind
(N
) in N_Subexpr
);
2034 if not With_Freezing
then
2035 Set_Must_Not_Freeze
(N
);
2036 Inside_Preanalysis_Without_Freezing
:=
2037 Inside_Preanalysis_Without_Freezing
+ 1;
2040 Full_Analysis
:= False;
2041 Expander_Mode_Save_And_Set
(False);
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 SPARK mode, most expansion is suppressed, and this
2050 -- later reanalysis and reexpansion may not occur. SPARK mode does
2051 -- require the setting of checking flags for proof purposes, so we
2052 -- do the SPARK 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 if GNATprove_Mode
then
2059 Analyze_And_Resolve
(N
, T
);
2061 Analyze_And_Resolve
(N
, T
, Suppress
=> All_Checks
);
2064 Expander_Mode_Restore
;
2065 Full_Analysis
:= Save_Full_Analysis
;
2067 if not With_Freezing
then
2068 Set_Must_Not_Freeze
(N
, Save_Must_Not_Freeze
);
2069 Inside_Preanalysis_Without_Freezing
:=
2070 Inside_Preanalysis_Without_Freezing
- 1;
2074 (Inside_Preanalysis_Without_Freezing
= Save_Preanalysis_Count
);
2075 end Preanalyze_And_Resolve
;
2077 ----------------------------
2078 -- Preanalyze_And_Resolve --
2079 ----------------------------
2081 procedure Preanalyze_And_Resolve
(N
: Node_Id
; T
: Entity_Id
) is
2083 Preanalyze_And_Resolve
(N
, T
, With_Freezing
=> False);
2084 end Preanalyze_And_Resolve
;
2086 -- Version without context type
2088 procedure Preanalyze_And_Resolve
(N
: Node_Id
) is
2089 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
2092 Full_Analysis
:= False;
2093 Expander_Mode_Save_And_Set
(False);
2096 Resolve
(N
, Etype
(N
), Suppress
=> All_Checks
);
2098 Expander_Mode_Restore
;
2099 Full_Analysis
:= Save_Full_Analysis
;
2100 end Preanalyze_And_Resolve
;
2102 ------------------------------------------
2103 -- Preanalyze_With_Freezing_And_Resolve --
2104 ------------------------------------------
2106 procedure Preanalyze_With_Freezing_And_Resolve
2111 Preanalyze_And_Resolve
(N
, T
, With_Freezing
=> True);
2112 end Preanalyze_With_Freezing_And_Resolve
;
2114 ----------------------------------
2115 -- Replace_Actual_Discriminants --
2116 ----------------------------------
2118 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
) is
2119 Loc
: constant Source_Ptr
:= Sloc
(N
);
2120 Tsk
: Node_Id
:= Empty
;
2122 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
;
2123 -- Comment needed???
2129 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
is
2133 if Nkind
(Nod
) = N_Identifier
then
2134 Ent
:= Entity
(Nod
);
2137 and then Ekind
(Ent
) = E_Discriminant
2140 Make_Selected_Component
(Loc
,
2141 Prefix
=> New_Copy_Tree
(Tsk
, New_Sloc
=> Loc
),
2142 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Ent
))));
2144 Set_Etype
(Nod
, Etype
(Ent
));
2152 procedure Replace_Discrs
is new Traverse_Proc
(Process_Discr
);
2154 -- Start of processing for Replace_Actual_Discriminants
2157 if Expander_Active
then
2160 -- Allow the replacement of concurrent discriminants in GNATprove even
2161 -- though this is a light expansion activity. Note that generic units
2162 -- are not modified.
2164 elsif GNATprove_Mode
and not Inside_A_Generic
then
2171 if Nkind
(Name
(N
)) = N_Selected_Component
then
2172 Tsk
:= Prefix
(Name
(N
));
2174 elsif Nkind
(Name
(N
)) = N_Indexed_Component
then
2175 Tsk
:= Prefix
(Prefix
(Name
(N
)));
2178 if Present
(Tsk
) then
2179 Replace_Discrs
(Default
);
2181 end Replace_Actual_Discriminants
;
2187 procedure Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
2188 Ambiguous
: Boolean := False;
2189 Ctx_Type
: Entity_Id
:= Typ
;
2190 Expr_Type
: Entity_Id
:= Empty
; -- prevent junk warning
2191 Err_Type
: Entity_Id
:= Empty
;
2192 Found
: Boolean := False;
2195 I1
: Interp_Index
:= 0; -- prevent junk warning
2198 Seen
: Entity_Id
:= Empty
; -- prevent junk warning
2200 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean;
2201 -- Determine whether a node comes from a predefined library unit or
2204 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
);
2205 -- Try and fix up a literal so that it matches its expected type. New
2206 -- literals are manufactured if necessary to avoid cascaded errors.
2208 procedure Report_Ambiguous_Argument
;
2209 -- Additional diagnostics when an ambiguous call has an ambiguous
2210 -- argument (typically a controlling actual).
2212 procedure Resolution_Failed
;
2213 -- Called when attempt at resolving current expression fails
2215 ------------------------------------
2216 -- Comes_From_Predefined_Lib_Unit --
2217 -------------------------------------
2219 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean is
2222 Sloc
(Nod
) = Standard_Location
or else In_Predefined_Unit
(Nod
);
2223 end Comes_From_Predefined_Lib_Unit
;
2225 --------------------
2226 -- Patch_Up_Value --
2227 --------------------
2229 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
) is
2231 if Nkind
(N
) = N_Integer_Literal
and then Is_Real_Type
(Typ
) then
2233 Make_Real_Literal
(Sloc
(N
),
2234 Realval
=> UR_From_Uint
(Intval
(N
))));
2235 Set_Etype
(N
, Universal_Real
);
2236 Set_Is_Static_Expression
(N
);
2238 elsif Nkind
(N
) = N_Real_Literal
and then Is_Integer_Type
(Typ
) then
2240 Make_Integer_Literal
(Sloc
(N
),
2241 Intval
=> UR_To_Uint
(Realval
(N
))));
2242 Set_Etype
(N
, Universal_Integer
);
2243 Set_Is_Static_Expression
(N
);
2245 elsif Nkind
(N
) = N_String_Literal
2246 and then Is_Character_Type
(Typ
)
2248 Set_Character_Literal_Name
(Get_Char_Code
('A'));
2250 Make_Character_Literal
(Sloc
(N
),
2252 Char_Literal_Value
=>
2253 UI_From_CC
(Get_Char_Code
('A'))));
2254 Set_Etype
(N
, Any_Character
);
2255 Set_Is_Static_Expression
(N
);
2257 elsif Nkind
(N
) /= N_String_Literal
and then Is_String_Type
(Typ
) then
2259 Make_String_Literal
(Sloc
(N
),
2260 Strval
=> End_String
));
2262 elsif Nkind
(N
) = N_Range
then
2263 Patch_Up_Value
(Low_Bound
(N
), Typ
);
2264 Patch_Up_Value
(High_Bound
(N
), Typ
);
2268 -------------------------------
2269 -- Report_Ambiguous_Argument --
2270 -------------------------------
2272 procedure Report_Ambiguous_Argument
is
2273 Arg
: constant Node_Id
:= First
(Parameter_Associations
(N
));
2278 if Nkind
(Arg
) = N_Function_Call
2279 and then Is_Entity_Name
(Name
(Arg
))
2280 and then Is_Overloaded
(Name
(Arg
))
2282 Error_Msg_NE
("ambiguous call to&", Arg
, Name
(Arg
));
2284 -- Examine possible interpretations, and adapt the message
2285 -- for inherited subprograms declared by a type derivation.
2287 Get_First_Interp
(Name
(Arg
), I
, It
);
2288 while Present
(It
.Nam
) loop
2289 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2291 if Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
then
2292 Error_Msg_N
("interpretation (inherited) #!", Arg
);
2294 Error_Msg_N
("interpretation #!", Arg
);
2297 Get_Next_Interp
(I
, It
);
2301 -- Additional message and hint if the ambiguity involves an Ada 2022
2302 -- container aggregate.
2304 Check_Ambiguous_Aggregate
(N
);
2305 end Report_Ambiguous_Argument
;
2307 -----------------------
2308 -- Resolution_Failed --
2309 -----------------------
2311 procedure Resolution_Failed
is
2313 Patch_Up_Value
(N
, Typ
);
2315 -- Set the type to the desired one to minimize cascaded errors. Note
2316 -- that this is an approximation and does not work in all cases.
2320 Debug_A_Exit
("resolving ", N
, " (done, resolution failed)");
2321 Set_Is_Overloaded
(N
, False);
2323 -- The caller will return without calling the expander, so we need
2324 -- to set the analyzed flag. Note that it is fine to set Analyzed
2325 -- to True even if we are in the middle of a shallow analysis,
2326 -- (see the spec of sem for more details) since this is an error
2327 -- situation anyway, and there is no point in repeating the
2328 -- analysis later (indeed it won't work to repeat it later, since
2329 -- we haven't got a clear resolution of which entity is being
2332 Set_Analyzed
(N
, True);
2334 end Resolution_Failed
;
2336 -- Start of processing for Resolve
2343 -- Access attribute on remote subprogram cannot be used for a non-remote
2344 -- access-to-subprogram type.
2346 if Nkind
(N
) = N_Attribute_Reference
2347 and then Attribute_Name
(N
) in Name_Access
2348 | Name_Unrestricted_Access
2349 | Name_Unchecked_Access
2350 and then Comes_From_Source
(N
)
2351 and then Is_Entity_Name
(Prefix
(N
))
2352 and then Is_Subprogram
(Entity
(Prefix
(N
)))
2353 and then Is_Remote_Call_Interface
(Entity
(Prefix
(N
)))
2354 and then not Is_Remote_Access_To_Subprogram_Type
(Typ
)
2357 ("prefix must statically denote a non-remote subprogram", N
);
2360 From_Lib
:= Comes_From_Predefined_Lib_Unit
(N
);
2362 -- If the context is a Remote_Access_To_Subprogram, access attributes
2363 -- must be resolved with the corresponding fat pointer. There is no need
2364 -- to check for the attribute name since the return type of an
2365 -- attribute is never a remote type.
2367 if Nkind
(N
) = N_Attribute_Reference
2368 and then Comes_From_Source
(N
)
2369 and then (Is_Remote_Call_Interface
(Typ
) or else Is_Remote_Types
(Typ
))
2372 Attr
: constant Attribute_Id
:=
2373 Get_Attribute_Id
(Attribute_Name
(N
));
2374 Pref
: constant Node_Id
:= Prefix
(N
);
2377 Is_Remote
: Boolean := True;
2380 -- Check that Typ is a remote access-to-subprogram type
2382 if Is_Remote_Access_To_Subprogram_Type
(Typ
) then
2384 -- Prefix (N) must statically denote a remote subprogram
2385 -- declared in a package specification.
2387 if Attr
= Attribute_Access
or else
2388 Attr
= Attribute_Unchecked_Access
or else
2389 Attr
= Attribute_Unrestricted_Access
2391 Decl
:= Unit_Declaration_Node
(Entity
(Pref
));
2393 if Nkind
(Decl
) = N_Subprogram_Body
then
2394 Spec
:= Corresponding_Spec
(Decl
);
2396 if Present
(Spec
) then
2397 Decl
:= Unit_Declaration_Node
(Spec
);
2401 Spec
:= Parent
(Decl
);
2403 if not Is_Entity_Name
(Prefix
(N
))
2404 or else Nkind
(Spec
) /= N_Package_Specification
2406 not Is_Remote_Call_Interface
(Defining_Entity
(Spec
))
2410 ("prefix must statically denote a remote subprogram",
2414 -- If we are generating code in distributed mode, perform
2415 -- semantic checks against corresponding remote entities.
2418 and then Get_PCS_Name
/= Name_No_DSA
2420 Check_Subtype_Conformant
2421 (New_Id
=> Entity
(Prefix
(N
)),
2422 Old_Id
=> Designated_Type
2423 (Corresponding_Remote_Type
(Typ
)),
2427 Process_Remote_AST_Attribute
(N
, Typ
);
2435 Debug_A_Entry
("resolving ", N
);
2437 if Debug_Flag_V
then
2438 Write_Overloads
(N
);
2441 if Comes_From_Source
(N
) then
2442 if Is_Fixed_Point_Type
(Typ
) then
2443 Check_Restriction
(No_Fixed_Point
, N
);
2445 elsif Is_Floating_Point_Type
(Typ
)
2446 and then Typ
/= Universal_Real
2447 and then Typ
/= Any_Real
2449 Check_Restriction
(No_Floating_Point
, N
);
2453 -- Return if already analyzed
2455 if Analyzed
(N
) then
2456 Debug_A_Exit
("resolving ", N
, " (done, already analyzed)");
2457 Analyze_Dimension
(N
);
2460 -- Any case of Any_Type as the Etype value means that we had a
2463 elsif Etype
(N
) = Any_Type
then
2464 Debug_A_Exit
("resolving ", N
, " (done, Etype = Any_Type)");
2468 Check_Parameterless_Call
(N
);
2470 -- The resolution of an Expression_With_Actions is determined by
2471 -- its Expression, but if the node comes from source it is a
2472 -- Declare_Expression and requires scope management.
2474 if Nkind
(N
) = N_Expression_With_Actions
then
2475 if Comes_From_Source
(N
) and then N
= Original_Node
(N
) then
2476 Resolve_Declare_Expression
(N
, Typ
);
2478 Resolve
(Expression
(N
), Typ
);
2482 Expr_Type
:= Etype
(Expression
(N
));
2484 -- If not overloaded, then we know the type, and all that needs doing
2485 -- is to check that this type is compatible with the context.
2487 elsif not Is_Overloaded
(N
) then
2488 Found
:= Covers
(Typ
, Etype
(N
));
2489 Expr_Type
:= Etype
(N
);
2491 -- In the overloaded case, we must select the interpretation that
2492 -- is compatible with the context (i.e. the type passed to Resolve)
2495 -- Loop through possible interpretations
2497 Get_First_Interp
(N
, I
, It
);
2498 Interp_Loop
: while Present
(It
.Typ
) loop
2499 if Debug_Flag_V
then
2500 Write_Str
("Interp: ");
2504 -- We are only interested in interpretations that are compatible
2505 -- with the expected type, any other interpretations are ignored.
2507 if not Covers
(Typ
, It
.Typ
) then
2508 if Debug_Flag_V
then
2509 Write_Str
(" interpretation incompatible with context");
2514 -- Skip the current interpretation if it is disabled by an
2515 -- abstract operator. This action is performed only when the
2516 -- type against which we are resolving is the same as the
2517 -- type of the interpretation.
2519 if Ada_Version
>= Ada_2005
2520 and then It
.Typ
= Typ
2521 and then not Is_Universal_Numeric_Type
(Typ
)
2522 and then Present
(It
.Abstract_Op
)
2524 if Debug_Flag_V
then
2525 Write_Line
("Skip.");
2531 -- First matching interpretation
2537 Expr_Type
:= It
.Typ
;
2539 -- Matching interpretation that is not the first, maybe an
2540 -- error, but there are some cases where preference rules are
2541 -- used to choose between the two possibilities. These and
2542 -- some more obscure cases are handled in Disambiguate.
2545 -- If the current statement is part of a predefined library
2546 -- unit, then all interpretations which come from user level
2547 -- packages should not be considered. Check previous and
2551 if not Comes_From_Predefined_Lib_Unit
(It
.Nam
) then
2554 elsif not Comes_From_Predefined_Lib_Unit
(Seen
) then
2556 -- Previous interpretation must be discarded
2560 Expr_Type
:= It
.Typ
;
2561 Set_Entity
(N
, Seen
);
2566 -- Otherwise apply further disambiguation steps
2568 Error_Msg_Sloc
:= Sloc
(Seen
);
2569 It1
:= Disambiguate
(N
, I1
, I
, Typ
);
2571 -- Disambiguation has succeeded. Skip the remaining
2574 if It1
/= No_Interp
then
2576 Expr_Type
:= It1
.Typ
;
2578 while Present
(It
.Typ
) loop
2579 Get_Next_Interp
(I
, It
);
2583 -- Before we issue an ambiguity complaint, check for the
2584 -- case of a subprogram call where at least one of the
2585 -- arguments is Any_Type, and if so suppress the message,
2586 -- since it is a cascaded error. This can also happen for
2587 -- a generalized indexing operation.
2589 if Nkind
(N
) in N_Subprogram_Call
2590 or else (Nkind
(N
) = N_Indexed_Component
2591 and then Present
(Generalized_Indexing
(N
)))
2598 if Nkind
(N
) = N_Indexed_Component
then
2599 Rewrite
(N
, Generalized_Indexing
(N
));
2602 A
:= First_Actual
(N
);
2603 while Present
(A
) loop
2606 if Nkind
(E
) = N_Parameter_Association
then
2607 E
:= Explicit_Actual_Parameter
(E
);
2610 if Etype
(E
) = Any_Type
then
2611 if Debug_Flag_V
then
2612 Write_Str
("Any_Type in call");
2623 elsif Nkind
(N
) in N_Binary_Op
2624 and then (Etype
(Left_Opnd
(N
)) = Any_Type
2625 or else Etype
(Right_Opnd
(N
)) = Any_Type
)
2629 elsif Nkind
(N
) in N_Unary_Op
2630 and then Etype
(Right_Opnd
(N
)) = Any_Type
2635 -- Not that special case, so issue message using the flag
2636 -- Ambiguous to control printing of the header message
2637 -- only at the start of an ambiguous set.
2639 if not Ambiguous
then
2640 if Nkind
(N
) = N_Function_Call
2641 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2644 ("ambiguous expression (cannot resolve indirect "
2647 Error_Msg_NE
-- CODEFIX
2648 ("ambiguous expression (cannot resolve&)!",
2654 if Nkind
(Parent
(Seen
)) = N_Full_Type_Declaration
then
2656 ("\\possible interpretation (inherited)#!", N
);
2658 Error_Msg_N
-- CODEFIX
2659 ("\\possible interpretation#!", N
);
2662 if Nkind
(N
) in N_Subprogram_Call
2663 and then Present
(Parameter_Associations
(N
))
2665 Report_Ambiguous_Argument
;
2669 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2671 -- By default, the error message refers to the candidate
2672 -- interpretation. But if it is a predefined operator, it
2673 -- is implicitly declared at the declaration of the type
2674 -- of the operand. Recover the sloc of that declaration
2675 -- for the error message.
2677 if Nkind
(N
) in N_Op
2678 and then Scope
(It
.Nam
) = Standard_Standard
2679 and then not Is_Overloaded
(Right_Opnd
(N
))
2680 and then Scope
(Base_Type
(Etype
(Right_Opnd
(N
)))) /=
2683 Err_Type
:= First_Subtype
(Etype
(Right_Opnd
(N
)));
2685 if Comes_From_Source
(Err_Type
)
2686 and then Present
(Parent
(Err_Type
))
2688 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2691 elsif Nkind
(N
) in N_Binary_Op
2692 and then Scope
(It
.Nam
) = Standard_Standard
2693 and then not Is_Overloaded
(Left_Opnd
(N
))
2694 and then Scope
(Base_Type
(Etype
(Left_Opnd
(N
)))) /=
2697 Err_Type
:= First_Subtype
(Etype
(Left_Opnd
(N
)));
2699 if Comes_From_Source
(Err_Type
)
2700 and then Present
(Parent
(Err_Type
))
2702 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2705 -- If this is an indirect call, use the subprogram_type
2706 -- in the message, to have a meaningful location. Also
2707 -- indicate if this is an inherited operation, created
2708 -- by a type declaration.
2710 elsif Nkind
(N
) = N_Function_Call
2711 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2712 and then Is_Type
(It
.Nam
)
2716 Sloc
(Associated_Node_For_Itype
(Err_Type
));
2721 if Nkind
(N
) in N_Op
2722 and then Scope
(It
.Nam
) = Standard_Standard
2723 and then Present
(Err_Type
)
2725 -- Special-case the message for universal_fixed
2726 -- operators, which are not declared with the type
2727 -- of the operand, but appear forever in Standard.
2729 if It
.Typ
= Universal_Fixed
2730 and then Scope
(It
.Nam
) = Standard_Standard
2733 ("\\possible interpretation as universal_fixed "
2734 & "operation (RM 4.5.5 (19))", N
);
2737 ("\\possible interpretation (predefined)#!", N
);
2741 Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
2744 ("\\possible interpretation (inherited)#!", N
);
2746 Error_Msg_N
-- CODEFIX
2747 ("\\possible interpretation#!", N
);
2753 -- We have a matching interpretation, Expr_Type is the type
2754 -- from this interpretation, and Seen is the entity.
2756 -- For an operator, just set the entity name. The type will be
2757 -- set by the specific operator resolution routine.
2759 if Nkind
(N
) in N_Op
then
2760 Set_Entity
(N
, Seen
);
2761 Generate_Reference
(Seen
, N
);
2763 elsif Nkind
(N
) in N_Case_Expression
2764 | N_Character_Literal
2768 Set_Etype
(N
, Expr_Type
);
2770 -- AI05-0139-2: Expression is overloaded because type has
2771 -- implicit dereference. The context may be the one that
2772 -- requires implicit dereferemce.
2774 elsif Has_Implicit_Dereference
(Expr_Type
) then
2775 Set_Etype
(N
, Expr_Type
);
2776 Set_Is_Overloaded
(N
, False);
2778 -- If the expression is an entity, generate a reference
2779 -- to it, as this is not done for an overloaded construct
2782 if Is_Entity_Name
(N
)
2783 and then Comes_From_Source
(N
)
2785 Generate_Reference
(Entity
(N
), N
);
2787 -- Examine access discriminants of entity type,
2788 -- to check whether one of them yields the
2793 First_Discriminant
(Etype
(Entity
(N
)));
2796 while Present
(Disc
) loop
2797 exit when Is_Access_Type
(Etype
(Disc
))
2798 and then Has_Implicit_Dereference
(Disc
)
2799 and then Designated_Type
(Etype
(Disc
)) = Typ
;
2801 Next_Discriminant
(Disc
);
2804 if Present
(Disc
) then
2805 Build_Explicit_Dereference
(N
, Disc
);
2812 elsif Is_Overloaded
(N
)
2813 and then Present
(It
.Nam
)
2814 and then Ekind
(It
.Nam
) = E_Discriminant
2815 and then Has_Implicit_Dereference
(It
.Nam
)
2817 -- If the node is a general indexing, the dereference is
2818 -- is inserted when resolving the rewritten form, else
2821 if Nkind
(N
) /= N_Indexed_Component
2822 or else No
(Generalized_Indexing
(N
))
2824 Build_Explicit_Dereference
(N
, It
.Nam
);
2827 -- For an explicit dereference, attribute reference, range,
2828 -- short-circuit form (which is not an operator node), or call
2829 -- with a name that is an explicit dereference, there is
2830 -- nothing to be done at this point.
2832 elsif Nkind
(N
) in N_Attribute_Reference
2834 | N_Explicit_Dereference
2836 | N_Indexed_Component
2839 | N_Selected_Component
2841 or else Nkind
(Name
(N
)) = N_Explicit_Dereference
2845 -- For procedure or function calls, set the type of the name,
2846 -- and also the entity pointer for the prefix.
2848 elsif Nkind
(N
) in N_Subprogram_Call
2849 and then Is_Entity_Name
(Name
(N
))
2851 Set_Etype
(Name
(N
), Expr_Type
);
2852 Set_Entity
(Name
(N
), Seen
);
2853 Generate_Reference
(Seen
, Name
(N
));
2855 elsif Nkind
(N
) = N_Function_Call
2856 and then Nkind
(Name
(N
)) = N_Selected_Component
2858 Set_Etype
(Name
(N
), Expr_Type
);
2859 Set_Entity
(Selector_Name
(Name
(N
)), Seen
);
2860 Generate_Reference
(Seen
, Selector_Name
(Name
(N
)));
2862 -- For all other cases, just set the type of the Name
2865 Set_Etype
(Name
(N
), Expr_Type
);
2872 -- Move to next interpretation
2874 exit Interp_Loop
when No
(It
.Typ
);
2876 Get_Next_Interp
(I
, It
);
2877 end loop Interp_Loop
;
2880 -- At this stage Found indicates whether or not an acceptable
2881 -- interpretation exists. If not, then we have an error, except that if
2882 -- the context is Any_Type as a result of some other error, then we
2883 -- suppress the error report.
2886 if Typ
/= Any_Type
then
2888 -- If type we are looking for is Void, then this is the procedure
2889 -- call case, and the error is simply that what we gave is not a
2890 -- procedure name (we think of procedure calls as expressions with
2891 -- types internally, but the user doesn't think of them this way).
2893 if Typ
= Standard_Void_Type
then
2895 -- Special case message if function used as a procedure
2897 if Nkind
(N
) = N_Procedure_Call_Statement
2898 and then Is_Entity_Name
(Name
(N
))
2899 and then Ekind
(Entity
(Name
(N
))) = E_Function
2902 ("cannot use call to function & as a statement",
2903 Name
(N
), Entity
(Name
(N
)));
2905 ("\return value of a function call cannot be ignored",
2908 -- Otherwise give general message (not clear what cases this
2909 -- covers, but no harm in providing for them).
2912 Error_Msg_N
("expect procedure name in procedure call", N
);
2917 -- Otherwise we do have a subexpression with the wrong type
2919 -- Check for the case of an allocator which uses an access type
2920 -- instead of the designated type. This is a common error and we
2921 -- specialize the message, posting an error on the operand of the
2922 -- allocator, complaining that we expected the designated type of
2925 elsif Nkind
(N
) = N_Allocator
2926 and then Is_Access_Type
(Typ
)
2927 and then Is_Access_Type
(Etype
(N
))
2928 and then Designated_Type
(Etype
(N
)) = Typ
2930 Wrong_Type
(Expression
(N
), Designated_Type
(Typ
));
2933 -- Check for view mismatch on Null in instances, for which the
2934 -- view-swapping mechanism has no identifier.
2936 elsif (In_Instance
or else In_Inlined_Body
)
2937 and then (Nkind
(N
) = N_Null
)
2938 and then Is_Private_Type
(Typ
)
2939 and then Is_Access_Type
(Full_View
(Typ
))
2941 Resolve
(N
, Full_View
(Typ
));
2945 -- Check for an aggregate. Sometimes we can get bogus aggregates
2946 -- from misuse of parentheses, and we are about to complain about
2947 -- the aggregate without even looking inside it.
2949 -- Instead, if we have an aggregate of type Any_Composite, then
2950 -- analyze and resolve the component fields, and then only issue
2951 -- another message if we get no errors doing this (otherwise
2952 -- assume that the errors in the aggregate caused the problem).
2954 elsif Nkind
(N
) = N_Aggregate
2955 and then Etype
(N
) = Any_Composite
2957 if Ada_Version
>= Ada_2022
2958 and then Has_Aspect
(Typ
, Aspect_Aggregate
)
2960 Resolve_Container_Aggregate
(N
, Typ
);
2962 if Expander_Active
then
2968 -- Disable expansion in any case. If there is a type mismatch
2969 -- it may be fatal to try to expand the aggregate. The flag
2970 -- would otherwise be set to false when the error is posted.
2972 Expander_Active
:= False;
2975 procedure Check_Aggr
(Aggr
: Node_Id
);
2976 -- Check one aggregate, and set Found to True if we have a
2977 -- definite error in any of its elements
2979 procedure Check_Elmt
(Aelmt
: Node_Id
);
2980 -- Check one element of aggregate and set Found to True if
2981 -- we definitely have an error in the element.
2987 procedure Check_Aggr
(Aggr
: Node_Id
) is
2991 if Present
(Expressions
(Aggr
)) then
2992 Elmt
:= First
(Expressions
(Aggr
));
2993 while Present
(Elmt
) loop
2999 if Present
(Component_Associations
(Aggr
)) then
3000 Elmt
:= First
(Component_Associations
(Aggr
));
3001 while Present
(Elmt
) loop
3003 -- If this is a default-initialized component, then
3004 -- there is nothing to check. The box will be
3005 -- replaced by the appropriate call during late
3008 if Nkind
(Elmt
) /= N_Iterated_Component_Association
3009 and then not Box_Present
(Elmt
)
3011 Check_Elmt
(Expression
(Elmt
));
3023 procedure Check_Elmt
(Aelmt
: Node_Id
) is
3025 -- If we have a nested aggregate, go inside it (to
3026 -- attempt a naked analyze-resolve of the aggregate can
3027 -- cause undesirable cascaded errors). Do not resolve
3028 -- expression if it needs a type from context, as for
3029 -- integer * fixed expression.
3031 if Nkind
(Aelmt
) = N_Aggregate
then
3037 if not Is_Overloaded
(Aelmt
)
3038 and then Etype
(Aelmt
) /= Any_Fixed
3043 if Etype
(Aelmt
) = Any_Type
then
3054 -- If node is a literal and context type has a user-defined
3055 -- literal aspect, rewrite node as a call to the corresponding
3056 -- function, which plays the role of an implicit conversion.
3059 N_Numeric_Or_String_Literal | N_Identifier
3060 and then Has_Applicable_User_Defined_Literal
(N
, Typ
)
3062 Analyze_And_Resolve
(N
, Typ
);
3066 -- Looks like we have a type error, but check for special case
3067 -- of Address wanted, integer found, with the configuration pragma
3068 -- Allow_Integer_Address active. If we have this case, introduce
3069 -- an unchecked conversion to allow the integer expression to be
3070 -- treated as an Address. The reverse case of integer wanted,
3071 -- Address found, is treated in an analogous manner.
3073 if Address_Integer_Convert_OK
(Typ
, Etype
(N
)) then
3074 Rewrite
(N
, Unchecked_Convert_To
(Typ
, Relocate_Node
(N
)));
3075 Analyze_And_Resolve
(N
, Typ
);
3078 -- Under relaxed RM semantics silently replace occurrences of null
3079 -- by System.Null_Address.
3081 elsif Null_To_Null_Address_Convert_OK
(N
, Typ
) then
3082 Replace_Null_By_Null_Address
(N
);
3083 Analyze_And_Resolve
(N
, Typ
);
3087 -- That special Allow_Integer_Address check did not apply, so we
3088 -- have a real type error. If an error message was issued already,
3089 -- Found got reset to True, so if it's still False, issue standard
3090 -- Wrong_Type message.
3093 if Is_Overloaded
(N
) and then Nkind
(N
) = N_Function_Call
then
3095 Subp_Name
: Node_Id
;
3098 if Is_Entity_Name
(Name
(N
)) then
3099 Subp_Name
:= Name
(N
);
3101 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
3103 -- Protected operation: retrieve operation name
3105 Subp_Name
:= Selector_Name
(Name
(N
));
3108 raise Program_Error
;
3111 Error_Msg_Node_2
:= Typ
;
3113 ("no visible interpretation of& matches expected type&",
3117 if All_Errors_Mode
then
3119 Index
: Interp_Index
;
3123 Error_Msg_N
("\\possible interpretations:", N
);
3125 Get_First_Interp
(Name
(N
), Index
, It
);
3126 while Present
(It
.Nam
) loop
3127 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
3128 Error_Msg_Node_2
:= It
.Nam
;
3130 ("\\ type& for & declared#", N
, It
.Typ
);
3131 Get_Next_Interp
(Index
, It
);
3136 Error_Msg_N
("\use -gnatf for details", N
);
3139 -- Recognize the case of a quantified expression being mistaken
3140 -- for an iterated component association because the user
3141 -- forgot the "all" or "some" keyword after "for". Because the
3142 -- error message starts with "missing ALL", we automatically
3143 -- benefit from the associated CODEFIX, which requires that
3144 -- the message is located on the identifier following "for"
3145 -- in order for the CODEFIX to insert "all" in the right place.
3147 elsif Nkind
(N
) = N_Aggregate
3148 and then List_Length
(Component_Associations
(N
)) = 1
3149 and then Nkind
(First
(Component_Associations
(N
)))
3150 = N_Iterated_Component_Association
3151 and then Is_Boolean_Type
(Typ
)
3153 Error_Msg_N
-- CODEFIX
3154 ("missing ALL or SOME in quantified expression",
3155 Defining_Identifier
(First
(Component_Associations
(N
))));
3157 -- For an operator with no interpretation, check whether
3158 -- one of its operands may be a user-defined literal.
3160 elsif Nkind
(N
) in N_Op
3161 and then Try_User_Defined_Literal
(N
, Typ
)
3166 Wrong_Type
(N
, Typ
);
3174 -- Test if we have more than one interpretation for the context
3176 elsif Ambiguous
then
3180 -- Only one interpretation
3183 -- Prevent implicit conversions between access-to-subprogram types
3184 -- with different strub modes. Explicit conversions are acceptable in
3185 -- some circumstances. We don't have to be concerned about data or
3186 -- access-to-data types. Conversions between data types can safely
3187 -- drop or add strub attributes from types, because strub effects are
3188 -- associated with the locations rather than values. E.g., converting
3189 -- a hypothetical Strub_Integer variable to Integer would load the
3190 -- value from the variable, enabling stack scrabbing for the
3191 -- enclosing subprogram, and then convert the value to Integer. As
3192 -- for conversions between access-to-data types, that's no different
3193 -- from any other case of type punning.
3195 if Is_Access_Type
(Typ
)
3196 and then Ekind
(Designated_Type
(Typ
)) = E_Subprogram_Type
3197 and then Is_Access_Type
(Expr_Type
)
3198 and then Ekind
(Designated_Type
(Expr_Type
)) = E_Subprogram_Type
3200 Check_Same_Strub_Mode
3201 (Designated_Type
(Typ
), Designated_Type
(Expr_Type
));
3204 -- In Ada 2005, if we have something like "X : T := 2 + 2;", where
3205 -- the "+" on T is abstract, and the operands are of universal type,
3206 -- the above code will have (incorrectly) resolved the "+" to the
3207 -- universal one in Standard. Therefore check for this case and give
3208 -- an error. We can't do this earlier, because it would cause legal
3209 -- cases to get errors (when some other type has an abstract "+").
3211 if Ada_Version
>= Ada_2005
3212 and then Nkind
(N
) in N_Op
3213 and then Is_Overloaded
(N
)
3214 and then Is_Universal_Numeric_Type
(Etype
(Entity
(N
)))
3216 Get_First_Interp
(N
, I
, It
);
3217 while Present
(It
.Typ
) loop
3218 if Present
(It
.Abstract_Op
) and then
3219 Etype
(It
.Abstract_Op
) = Typ
3222 ("cannot call abstract subprogram &!", N
, It
.Abstract_Op
);
3226 Get_Next_Interp
(I
, It
);
3230 -- Here we have an acceptable interpretation for the context
3232 -- Propagate type information and normalize tree for various
3233 -- predefined operations. If the context only imposes a class of
3234 -- types, rather than a specific type, propagate the actual type
3237 if Typ
= Any_Integer
or else
3238 Typ
= Any_Boolean
or else
3239 Typ
= Any_Modular
or else
3240 Typ
= Any_Real
or else
3243 Ctx_Type
:= Expr_Type
;
3245 -- Any_Fixed is legal in a real context only if a specific fixed-
3246 -- point type is imposed. If Norman Cohen can be confused by this,
3247 -- it deserves a separate message.
3250 and then Expr_Type
= Any_Fixed
3252 Error_Msg_N
("illegal context for mixed mode operation", N
);
3253 Set_Etype
(N
, Universal_Real
);
3254 Ctx_Type
:= Universal_Real
;
3258 -- A user-defined operator is transformed into a function call at
3259 -- this point, so that further processing knows that operators are
3260 -- really operators (i.e. are predefined operators). User-defined
3261 -- operators that are intrinsic are just renamings of the predefined
3262 -- ones, and need not be turned into calls either, but if they rename
3263 -- a different operator, we must transform the node accordingly.
3264 -- Instantiations of Unchecked_Conversion are intrinsic but are
3265 -- treated as functions, even if given an operator designator.
3267 if Nkind
(N
) in N_Op
3268 and then Present
(Entity
(N
))
3269 and then Ekind
(Entity
(N
)) /= E_Operator
3271 if not Is_Predefined_Op
(Entity
(N
)) then
3272 Rewrite_Operator_As_Call
(N
, Entity
(N
));
3274 elsif Present
(Alias
(Entity
(N
)))
3276 Nkind
(Parent
(Parent
(Entity
(N
)))) =
3277 N_Subprogram_Renaming_Declaration
3279 Rewrite_Renamed_Operator
(N
, Alias
(Entity
(N
)), Typ
);
3281 -- If the node is rewritten, it will be fully resolved in
3282 -- Rewrite_Renamed_Operator.
3284 if Analyzed
(N
) then
3290 case N_Subexpr
'(Nkind (N)) is
3292 Resolve_Aggregate (N, Ctx_Type);
3295 Resolve_Allocator (N, Ctx_Type);
3297 when N_Short_Circuit =>
3298 Resolve_Short_Circuit (N, Ctx_Type);
3300 when N_Attribute_Reference =>
3301 Resolve_Attribute (N, Ctx_Type);
3303 when N_Case_Expression =>
3304 Resolve_Case_Expression (N, Ctx_Type);
3306 when N_Character_Literal =>
3307 Resolve_Character_Literal (N, Ctx_Type);
3309 when N_Delta_Aggregate =>
3310 Resolve_Delta_Aggregate (N, Ctx_Type);
3312 when N_Expanded_Name =>
3313 Resolve_Entity_Name (N, Ctx_Type);
3315 when N_Explicit_Dereference =>
3316 Resolve_Explicit_Dereference (N, Ctx_Type);
3318 when N_Expression_With_Actions =>
3319 Resolve_Expression_With_Actions (N, Ctx_Type);
3321 when N_Extension_Aggregate =>
3322 Resolve_Extension_Aggregate (N, Ctx_Type);
3324 when N_Function_Call =>
3325 Resolve_Call (N, Ctx_Type);
3327 when N_Identifier =>
3328 Resolve_Entity_Name (N, Ctx_Type);
3330 when N_If_Expression =>
3331 Resolve_If_Expression (N, Ctx_Type);
3333 when N_Indexed_Component =>
3334 Resolve_Indexed_Component (N, Ctx_Type);
3336 when N_Integer_Literal =>
3337 Resolve_Integer_Literal (N, Ctx_Type);
3339 when N_Membership_Test =>
3340 Resolve_Membership_Op (N, Ctx_Type);
3343 Resolve_Null (N, Ctx_Type);
3349 Resolve_Logical_Op (N, Ctx_Type);
3354 Resolve_Equality_Op (N, Ctx_Type);
3361 Resolve_Comparison_Op (N, Ctx_Type);
3364 Resolve_Op_Not (N, Ctx_Type);
3373 Resolve_Arithmetic_Op (N, Ctx_Type);
3376 Resolve_Op_Concat (N, Ctx_Type);
3379 Resolve_Op_Expon (N, Ctx_Type);
3385 Resolve_Unary_Op (N, Ctx_Type);
3388 Resolve_Shift (N, Ctx_Type);
3390 when N_Procedure_Call_Statement =>
3391 Resolve_Call (N, Ctx_Type);
3393 when N_Operator_Symbol =>
3394 Resolve_Operator_Symbol (N, Ctx_Type);
3396 when N_Qualified_Expression =>
3397 Resolve_Qualified_Expression (N, Ctx_Type);
3399 -- Why is the following null, needs a comment ???
3401 when N_Quantified_Expression =>
3404 when N_Raise_Expression =>
3405 Resolve_Raise_Expression (N, Ctx_Type);
3407 when N_Raise_xxx_Error =>
3408 Set_Etype (N, Ctx_Type);
3411 Resolve_Range (N, Ctx_Type);
3413 when N_Real_Literal =>
3414 Resolve_Real_Literal (N, Ctx_Type);
3417 Resolve_Reference (N, Ctx_Type);
3419 when N_Selected_Component =>
3420 Resolve_Selected_Component (N, Ctx_Type);
3423 Resolve_Slice (N, Ctx_Type);
3425 when N_String_Literal =>
3426 Resolve_String_Literal (N, Ctx_Type);
3428 when N_Target_Name =>
3429 Resolve_Target_Name (N, Ctx_Type);
3431 when N_Type_Conversion =>
3432 Resolve_Type_Conversion (N, Ctx_Type);
3434 when N_Unchecked_Expression =>
3435 Resolve_Unchecked_Expression (N, Ctx_Type);
3437 when N_Unchecked_Type_Conversion =>
3438 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
3441 -- Mark relevant use-type and use-package clauses as effective using
3442 -- the original node because constant folding may have occurred and
3443 -- removed references that need to be examined.
3445 if Nkind (Original_Node (N)) in N_Op then
3446 Mark_Use_Clauses (Original_Node (N));
3449 -- Ada 2012 (AI05-0149): Apply an (implicit) conversion to an
3450 -- expression of an anonymous access type that occurs in the context
3451 -- of a named general access type, except when the expression is that
3452 -- of a membership test. This ensures proper legality checking in
3453 -- terms of allowed conversions (expressions that would be illegal to
3454 -- convert implicitly are allowed in membership tests).
3456 if Ada_Version >= Ada_2012
3457 and then Ekind (Base_Type (Ctx_Type)) = E_General_Access_Type
3458 and then Ekind (Etype (N)) = E_Anonymous_Access_Type
3459 and then Nkind (Parent (N)) not in N_Membership_Test
3461 Rewrite (N, Convert_To (Ctx_Type, Relocate_Node (N)));
3462 Analyze_And_Resolve (N, Ctx_Type);
3465 -- If the subexpression was replaced by a non-subexpression, then
3466 -- all we do is to expand it. The only legitimate case we know of
3467 -- is converting procedure call statement to entry call statements,
3468 -- but there may be others, so we are making this test general.
3470 if Nkind (N) not in N_Subexpr then
3471 Debug_A_Exit ("resolving ", N, " (done)");
3476 -- The expression is definitely NOT overloaded at this point, so
3477 -- we reset the Is_Overloaded flag to avoid any confusion when
3478 -- reanalyzing the node.
3480 Set_Is_Overloaded (N, False);
3482 -- Freeze expression type, entity if it is a name, and designated
3483 -- type if it is an allocator (RM 13.14(10,11,13)).
3485 -- Now that the resolution of the type of the node is complete, and
3486 -- we did not detect an error, we can expand this node. We skip the
3487 -- expand call if we are in a default expression, see section
3488 -- "Handling of Default Expressions" in Sem spec.
3490 Debug_A_Exit ("resolving ", N, " (done)");
3492 -- We unconditionally freeze the expression, even if we are in
3493 -- default expression mode (the Freeze_Expression routine tests this
3494 -- flag and only freezes static types if it is set).
3496 -- Ada 2012 (AI05-177): The declaration of an expression function
3497 -- does not cause freezing, but we never reach here in that case.
3498 -- Here we are resolving the corresponding expanded body, so we do
3499 -- need to perform normal freezing.
3501 -- As elsewhere we do not emit freeze node within a generic.
3503 if not Inside_A_Generic then
3504 Freeze_Expression (N);
3507 -- Now we can do the expansion
3517 -- Version with check(s) suppressed
3519 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
3521 if Suppress = All_Checks then
3523 Sva : constant Suppress_Array := Scope_Suppress.Suppress;
3525 Scope_Suppress.Suppress := (others => True);
3527 Scope_Suppress.Suppress := Sva;
3532 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
3534 Scope_Suppress.Suppress (Suppress) := True;
3536 Scope_Suppress.Suppress (Suppress) := Svg;
3545 -- Version with implicit type
3547 procedure Resolve (N : Node_Id) is
3549 Resolve (N, Etype (N));
3552 ---------------------
3553 -- Resolve_Actuals --
3554 ---------------------
3556 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
3557 Loc : constant Source_Ptr := Sloc (N);
3559 A_Typ : Entity_Id := Empty; -- init to avoid warning
3562 Prev : Node_Id := Empty;
3564 Real_F : Entity_Id := Empty; -- init to avoid warning
3566 Real_Subp : Entity_Id;
3567 -- If the subprogram being called is an inherited operation for
3568 -- a formal derived type in an instance, Real_Subp is the subprogram
3569 -- that will be called. It may have different formal names than the
3570 -- operation of the formal in the generic, so after actual is resolved
3571 -- the name of the actual in a named association must carry the name
3572 -- of the actual of the subprogram being called.
3574 procedure Check_Aliased_Parameter;
3575 -- Check rules on aliased parameters and related accessibility rules
3576 -- in (RM 3.10.2 (10.2-10.4)).
3578 procedure Check_Argument_Order;
3579 -- Performs a check for the case where the actuals are all simple
3580 -- identifiers that correspond to the formal names, but in the wrong
3581 -- order, which is considered suspicious and cause for a warning.
3583 procedure Check_Prefixed_Call;
3584 -- If the original node is an overloaded call in prefix notation,
3585 -- insert an 'Access or a dereference as needed over the first actual
.
3586 -- Try_Object_Operation has already verified that there is a valid
3587 -- interpretation, but the form of the actual can only be determined
3588 -- once the primitive operation is identified.
3590 procedure Flag_Effectively_Volatile_Objects
(Expr
: Node_Id
);
3591 -- Emit an error concerning the illegal usage of an effectively volatile
3592 -- object for reading in interfering context (SPARK RM 7.1.3(10)).
3594 procedure Insert_Default
;
3595 -- If the actual is missing in a call, insert in the actuals list
3596 -- an instance of the default expression. The insertion is always
3597 -- a named association.
3599 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean;
3600 -- Check whether T1 and T2, or their full views, are derived from a
3601 -- common type. Used to enforce the restrictions on array conversions
3604 function Static_Concatenation
(N
: Node_Id
) return Boolean;
3605 -- Predicate to determine whether an actual that is a concatenation
3606 -- will be evaluated statically and does not need a transient scope.
3607 -- This must be determined before the actual is resolved and expanded
3608 -- because if needed the transient scope must be introduced earlier.
3610 -----------------------------
3611 -- Check_Aliased_Parameter --
3612 -----------------------------
3614 procedure Check_Aliased_Parameter
is
3615 Nominal_Subt
: Entity_Id
;
3618 if Is_Aliased
(F
) then
3619 if Is_Tagged_Type
(A_Typ
) then
3622 elsif Is_Aliased_View
(A
) then
3623 if Is_Constr_Subt_For_U_Nominal
(A_Typ
) then
3624 Nominal_Subt
:= Base_Type
(A_Typ
);
3626 Nominal_Subt
:= A_Typ
;
3629 if Subtypes_Statically_Match
(F_Typ
, Nominal_Subt
) then
3632 -- In a generic body assume the worst for generic formals:
3633 -- they can have a constrained partial view (AI05-041).
3635 elsif Has_Discriminants
(F_Typ
)
3636 and then not Is_Constrained
(F_Typ
)
3637 and then not Object_Type_Has_Constrained_Partial_View
3638 (Typ
=> F_Typ
, Scop
=> Current_Scope
)
3643 Error_Msg_NE
("untagged actual does not statically match "
3644 & "aliased formal&", A
, F
);
3648 Error_Msg_NE
("actual for aliased formal& must be "
3649 & "aliased object", A
, F
);
3652 if Ekind
(Nam
) = E_Procedure
then
3655 elsif Ekind
(Etype
(Nam
)) = E_Anonymous_Access_Type
then
3656 if Nkind
(Parent
(N
)) = N_Type_Conversion
3657 and then Type_Access_Level
(Etype
(Parent
(N
)))
3658 < Static_Accessibility_Level
(A
, Object_Decl_Level
)
3660 Error_Msg_N
("aliased actual has wrong accessibility", A
);
3663 elsif Nkind
(Parent
(N
)) = N_Qualified_Expression
3664 and then Nkind
(Parent
(Parent
(N
))) = N_Allocator
3665 and then Type_Access_Level
(Etype
(Parent
(Parent
(N
))))
3666 < Static_Accessibility_Level
(A
, Object_Decl_Level
)
3669 ("aliased actual in allocator has wrong accessibility", A
);
3672 end Check_Aliased_Parameter
;
3674 --------------------------
3675 -- Check_Argument_Order --
3676 --------------------------
3678 procedure Check_Argument_Order
is
3680 -- Nothing to do if no parameters, or original node is neither a
3681 -- function call nor a procedure call statement (happens in the
3682 -- operator-transformed-to-function call case), or the call is to an
3683 -- operator symbol (which is usually in infix form), or the call does
3684 -- not come from source, or this warning is off.
3686 if not Warn_On_Parameter_Order
3687 or else No
(Parameter_Associations
(N
))
3688 or else Nkind
(Original_Node
(N
)) not in N_Subprogram_Call
3689 or else (Nkind
(Name
(N
)) = N_Identifier
3690 and then Present
(Entity
(Name
(N
)))
3691 and then Nkind
(Entity
(Name
(N
))) =
3692 N_Defining_Operator_Symbol
)
3693 or else not Comes_From_Source
(N
)
3699 Nargs
: constant Nat
:= List_Length
(Parameter_Associations
(N
));
3702 -- Nothing to do if only one parameter
3708 -- Here if at least two arguments
3711 Actuals
: array (1 .. Nargs
) of Node_Id
;
3715 Wrong_Order
: Boolean := False;
3716 -- Set True if an out of order case is found
3719 -- Collect identifier names of actuals, fail if any actual is
3720 -- not a simple identifier, and record max length of name.
3722 Actual
:= First
(Parameter_Associations
(N
));
3723 for J
in Actuals
'Range loop
3724 if Nkind
(Actual
) /= N_Identifier
then
3727 Actuals
(J
) := Actual
;
3732 -- If we got this far, all actuals are identifiers and the list
3733 -- of their names is stored in the Actuals array.
3735 Formal
:= First_Formal
(Nam
);
3736 for J
in Actuals
'Range loop
3738 -- If we ran out of formals, that's odd, probably an error
3739 -- which will be detected elsewhere, but abandon the search.
3745 -- If name matches and is in order OK
3747 if Chars
(Formal
) = Chars
(Actuals
(J
)) then
3751 -- If no match, see if it is elsewhere in list and if so
3752 -- flag potential wrong order if type is compatible.
3754 for K
in Actuals
'Range loop
3755 if Chars
(Formal
) = Chars
(Actuals
(K
))
3757 Has_Compatible_Type
(Actuals
(K
), Etype
(Formal
))
3759 Wrong_Order
:= True;
3769 <<Continue
>> Next_Formal
(Formal
);
3772 -- If Formals left over, also probably an error, skip warning
3774 if Present
(Formal
) then
3778 -- Here we give the warning if something was out of order
3782 ("?.p?actuals for this call may be in wrong order", N
);
3786 end Check_Argument_Order
;
3788 -------------------------
3789 -- Check_Prefixed_Call --
3790 -------------------------
3792 procedure Check_Prefixed_Call
is
3793 Act
: constant Node_Id
:= First_Actual
(N
);
3794 A_Type
: constant Entity_Id
:= Etype
(Act
);
3795 F_Type
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
3796 Orig
: constant Node_Id
:= Original_Node
(N
);
3800 -- Check whether the call is a prefixed call, with or without
3801 -- additional actuals.
3803 if Nkind
(Orig
) = N_Selected_Component
3805 (Nkind
(Orig
) = N_Indexed_Component
3806 and then Nkind
(Prefix
(Orig
)) = N_Selected_Component
3807 and then Is_Entity_Name
(Prefix
(Prefix
(Orig
)))
3808 and then Is_Entity_Name
(Act
)
3809 and then Chars
(Act
) = Chars
(Prefix
(Prefix
(Orig
))))
3811 if Is_Access_Type
(A_Type
)
3812 and then not Is_Access_Type
(F_Type
)
3814 -- Introduce dereference on object in prefix
3817 Make_Explicit_Dereference
(Sloc
(Act
),
3818 Prefix
=> Relocate_Node
(Act
));
3819 Rewrite
(Act
, New_A
);
3822 elsif Is_Access_Type
(F_Type
)
3823 and then not Is_Access_Type
(A_Type
)
3825 -- Introduce an implicit 'Access in prefix
3827 if not Is_Aliased_View
(Act
) then
3829 ("object in prefixed call to& must be aliased "
3830 & "(RM 4.1.3 (13 1/2))",
3835 Make_Attribute_Reference
(Loc
,
3836 Attribute_Name
=> Name_Access
,
3837 Prefix
=> Relocate_Node
(Act
)));
3842 end Check_Prefixed_Call
;
3844 ---------------------------------------
3845 -- Flag_Effectively_Volatile_Objects --
3846 ---------------------------------------
3848 procedure Flag_Effectively_Volatile_Objects
(Expr
: Node_Id
) is
3849 function Flag_Object
(N
: Node_Id
) return Traverse_Result
;
3850 -- Determine whether arbitrary node N denotes an effectively volatile
3851 -- object for reading and if it does, emit an error.
3857 function Flag_Object
(N
: Node_Id
) return Traverse_Result
is
3862 -- Do not consider nested function calls because they have
3863 -- already been processed during their own resolution.
3865 when N_Function_Call
=>
3868 when N_Identifier | N_Expanded_Name
=>
3872 and then Is_Object
(Id
)
3873 and then Is_Effectively_Volatile_For_Reading
(Id
)
3875 not Is_OK_Volatile_Context
(Context
=> Parent
(N
),
3877 Check_Actuals
=> True)
3880 ("volatile object cannot appear in this context"
3881 & " (SPARK RM 7.1.3(10))", N
);
3891 procedure Flag_Objects
is new Traverse_Proc
(Flag_Object
);
3893 -- Start of processing for Flag_Effectively_Volatile_Objects
3896 Flag_Objects
(Expr
);
3897 end Flag_Effectively_Volatile_Objects
;
3899 --------------------
3900 -- Insert_Default --
3901 --------------------
3903 procedure Insert_Default
is
3908 -- Missing argument in call, nothing to insert
3910 if No
(Default_Value
(F
)) then
3914 -- Note that we do a full New_Copy_Tree, so that any associated
3915 -- Itypes are properly copied. This may not be needed any more,
3916 -- but it does no harm as a safety measure. Defaults of a generic
3917 -- formal may be out of bounds of the corresponding actual (see
3918 -- cc1311b) and an additional check may be required.
3923 New_Scope
=> Current_Scope
,
3926 -- Propagate dimension information, if any.
3928 Copy_Dimensions
(Default_Value
(F
), Actval
);
3930 if Is_Concurrent_Type
(Scope
(Nam
))
3931 and then Has_Discriminants
(Scope
(Nam
))
3933 Replace_Actual_Discriminants
(N
, Actval
);
3936 if Is_Overloadable
(Nam
)
3937 and then Present
(Alias
(Nam
))
3939 if Base_Type
(Etype
(F
)) /= Base_Type
(Etype
(Actval
))
3940 and then not Is_Tagged_Type
(Etype
(F
))
3942 -- If default is a real literal, do not introduce a
3943 -- conversion whose effect may depend on the run-time
3944 -- size of universal real.
3946 if Nkind
(Actval
) = N_Real_Literal
then
3947 Set_Etype
(Actval
, Base_Type
(Etype
(F
)));
3949 Actval
:= Unchecked_Convert_To
(Etype
(F
), Actval
);
3953 if Is_Scalar_Type
(Etype
(F
)) then
3954 Enable_Range_Check
(Actval
);
3957 Set_Parent
(Actval
, N
);
3959 -- Resolve aggregates with their base type, to avoid scope
3960 -- anomalies: the subtype was first built in the subprogram
3961 -- declaration, and the current call may be nested.
3963 if Nkind
(Actval
) = N_Aggregate
then
3964 Analyze_And_Resolve
(Actval
, Etype
(F
));
3966 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3970 Set_Parent
(Actval
, N
);
3972 -- See note above concerning aggregates
3974 if Nkind
(Actval
) = N_Aggregate
3975 and then Has_Discriminants
(Etype
(Actval
))
3977 Analyze_And_Resolve
(Actval
, Base_Type
(Etype
(Actval
)));
3979 -- Resolve entities with their own type, which may differ from
3980 -- the type of a reference in a generic context (the view
3981 -- swapping mechanism did not anticipate the re-analysis of
3982 -- default values in calls).
3984 elsif Is_Entity_Name
(Actval
) then
3985 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Actval
)));
3988 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3992 -- If default is a tag indeterminate function call, propagate tag
3993 -- to obtain proper dispatching.
3995 if Is_Controlling_Formal
(F
)
3996 and then Nkind
(Default_Value
(F
)) = N_Function_Call
3998 Set_Is_Controlling_Actual
(Actval
);
4002 -- If the default expression raises constraint error, then just
4003 -- silently replace it with an N_Raise_Constraint_Error node, since
4004 -- we already gave the warning on the subprogram spec. If node is
4005 -- already a Raise_Constraint_Error leave as is, to prevent loops in
4006 -- the warnings removal machinery.
4008 if Raises_Constraint_Error
(Actval
)
4009 and then Nkind
(Actval
) /= N_Raise_Constraint_Error
4012 Make_Raise_Constraint_Error
(Loc
,
4013 Reason
=> CE_Range_Check_Failed
));
4015 Set_Raises_Constraint_Error
(Actval
);
4016 Set_Etype
(Actval
, Etype
(F
));
4020 Make_Parameter_Association
(Loc
,
4021 Explicit_Actual_Parameter
=> Actval
,
4022 Selector_Name
=> Make_Identifier
(Loc
, Chars
(F
)));
4024 -- Case of insertion is first named actual
4027 or else Nkind
(Parent
(Prev
)) /= N_Parameter_Association
4029 Set_Next_Named_Actual
(Assoc
, First_Named_Actual
(N
));
4030 Set_First_Named_Actual
(N
, Actval
);
4033 if No
(Parameter_Associations
(N
)) then
4034 Set_Parameter_Associations
(N
, New_List
(Assoc
));
4036 Append
(Assoc
, Parameter_Associations
(N
));
4040 Insert_After
(Prev
, Assoc
);
4043 -- Case of insertion is not first named actual
4046 Set_Next_Named_Actual
4047 (Assoc
, Next_Named_Actual
(Parent
(Prev
)));
4048 Set_Next_Named_Actual
(Parent
(Prev
), Actval
);
4049 Append
(Assoc
, Parameter_Associations
(N
));
4052 Mark_Rewrite_Insertion
(Assoc
);
4053 Mark_Rewrite_Insertion
(Actval
);
4062 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean is
4063 FT1
: Entity_Id
:= T1
;
4064 FT2
: Entity_Id
:= T2
;
4067 if Is_Private_Type
(T1
)
4068 and then Present
(Full_View
(T1
))
4070 FT1
:= Full_View
(T1
);
4073 if Is_Private_Type
(T2
)
4074 and then Present
(Full_View
(T2
))
4076 FT2
:= Full_View
(T2
);
4079 return Root_Type
(Base_Type
(FT1
)) = Root_Type
(Base_Type
(FT2
));
4082 --------------------------
4083 -- Static_Concatenation --
4084 --------------------------
4086 function Static_Concatenation
(N
: Node_Id
) return Boolean is
4089 when N_String_Literal
=>
4094 -- Concatenation is static when both operands are static and
4095 -- the concatenation operator is a predefined one.
4097 return Scope
(Entity
(N
)) = Standard_Standard
4099 Static_Concatenation
(Left_Opnd
(N
))
4101 Static_Concatenation
(Right_Opnd
(N
));
4104 if Is_Entity_Name
(N
) then
4106 Ent
: constant Entity_Id
:= Entity
(N
);
4108 return Ekind
(Ent
) = E_Constant
4109 and then Present
(Constant_Value
(Ent
))
4111 Is_OK_Static_Expression
(Constant_Value
(Ent
));
4118 end Static_Concatenation
;
4120 -- Start of processing for Resolve_Actuals
4123 Check_Argument_Order
;
4125 if Is_Overloadable
(Nam
)
4126 and then Is_Inherited_Operation
(Nam
)
4127 and then In_Instance
4128 and then Present
(Alias
(Nam
))
4129 and then Present
(Overridden_Operation
(Alias
(Nam
)))
4131 Real_Subp
:= Alias
(Nam
);
4136 if Present
(First_Actual
(N
)) then
4137 Check_Prefixed_Call
;
4140 A
:= First_Actual
(N
);
4141 F
:= First_Formal
(Nam
);
4143 if Present
(Real_Subp
) then
4144 Real_F
:= First_Formal
(Real_Subp
);
4147 while Present
(F
) loop
4148 if No
(A
) and then Needs_No_Actuals
(Nam
) then
4151 -- If we have an error in any formal or actual, indicated by a type
4152 -- of Any_Type, then abandon resolution attempt, and set result type
4155 elsif Etype
(F
) = Any_Type
then
4156 Set_Etype
(N
, Any_Type
);
4159 elsif Present
(A
) and then Etype
(A
) = Any_Type
then
4160 -- For the peculiar case of a user-defined comparison or equality
4161 -- operator that does not return a boolean type, the operands may
4162 -- have been ambiguous for the predefined operator and, therefore,
4163 -- marked with Any_Type. Since the operation has been resolved to
4164 -- the user-defined operator, that is irrelevant, so reset Etype.
4166 if Nkind
(Original_Node
(N
)) in N_Op_Eq
4172 and then not Is_Boolean_Type
(Etype
(N
))
4174 Set_Etype
(A
, Etype
(F
));
4176 -- Also skip this if the actual is a Raise_Expression, whose type
4177 -- is imposed from context.
4179 elsif Nkind
(A
) = N_Raise_Expression
then
4183 Set_Etype
(N
, Any_Type
);
4188 -- Case where actual is present
4190 -- If the actual is an entity, generate a reference to it now. We
4191 -- do this before the actual is resolved, because a formal of some
4192 -- protected subprogram, or a task discriminant, will be rewritten
4193 -- during expansion, and the source entity reference may be lost.
4196 and then Is_Entity_Name
(A
)
4197 and then Comes_From_Source
(A
)
4199 -- Annotate the tree by creating a variable reference marker when
4200 -- the actual denotes a variable reference, in case the reference
4201 -- is folded or optimized away. The variable reference marker is
4202 -- automatically saved for later examination by the ABE Processing
4203 -- phase. The status of the reference is set as follows:
4207 -- write IN OUT, OUT
4209 if Needs_Variable_Reference_Marker
4213 Build_Variable_Reference_Marker
4215 Read
=> Ekind
(F
) /= E_Out_Parameter
,
4216 Write
=> Ekind
(F
) /= E_In_Parameter
);
4219 Orig_A
:= Entity
(A
);
4221 if Present
(Orig_A
) then
4222 if Is_Formal
(Orig_A
)
4223 and then Ekind
(F
) /= E_In_Parameter
4225 Generate_Reference
(Orig_A
, A
, 'm');
4227 elsif not Is_Overloaded
(A
) then
4228 if Ekind
(F
) /= E_Out_Parameter
then
4229 Generate_Reference
(Orig_A
, A
);
4231 -- RM 6.4.1(12): For an out parameter that is passed by
4232 -- copy, the formal parameter object is created, and:
4234 -- * For an access type, the formal parameter is initialized
4235 -- from the value of the actual, without checking that the
4236 -- value satisfies any constraint, any predicate, or any
4237 -- exclusion of the null value.
4239 -- * For a scalar type that has the Default_Value aspect
4240 -- specified, the formal parameter is initialized from the
4241 -- value of the actual, without checking that the value
4242 -- satisfies any constraint or any predicate.
4243 -- I do not understand why this case is included??? this is
4244 -- not a case where an OUT parameter is treated as IN OUT.
4246 -- * For a composite type with discriminants or that has
4247 -- implicit initial values for any subcomponents, the
4248 -- behavior is as for an in out parameter passed by copy.
4250 -- Hence for these cases we generate the read reference now
4251 -- (the write reference will be generated later by
4252 -- Note_Possible_Modification).
4254 elsif Is_By_Copy_Type
(Etype
(F
))
4256 (Is_Access_Type
(Etype
(F
))
4258 (Is_Scalar_Type
(Etype
(F
))
4260 Present
(Default_Aspect_Value
(Etype
(F
))))
4262 (Is_Composite_Type
(Etype
(F
))
4263 and then (Has_Discriminants
(Etype
(F
))
4264 or else Is_Partially_Initialized_Type
4267 Generate_Reference
(Orig_A
, A
);
4274 and then (Nkind
(Parent
(A
)) /= N_Parameter_Association
4275 or else Chars
(Selector_Name
(Parent
(A
))) = Chars
(F
))
4277 -- If style checking mode on, check match of formal name
4280 if Nkind
(Parent
(A
)) = N_Parameter_Association
then
4281 Check_Identifier
(Selector_Name
(Parent
(A
)), F
);
4285 -- If the formal is Out or In_Out, do not resolve and expand the
4286 -- conversion, because it is subsequently expanded into explicit
4287 -- temporaries and assignments. However, the object of the
4288 -- conversion can be resolved. An exception is the case of tagged
4289 -- type conversion with a class-wide actual. In that case we want
4290 -- the tag check to occur and no temporary will be needed (no
4291 -- representation change can occur) and the parameter is passed by
4292 -- reference, so we go ahead and resolve the type conversion.
4293 -- Another exception is the case of reference to component or
4294 -- subcomponent of a bit-packed array, in which case we want to
4295 -- defer expansion to the point the in and out assignments are
4298 if Ekind
(F
) /= E_In_Parameter
4299 and then Nkind
(A
) = N_Type_Conversion
4300 and then not Is_Class_Wide_Type
(Etype
(Expression
(A
)))
4301 and then not Is_Interface
(Etype
(A
))
4304 Expr_Typ
: constant Entity_Id
:= Etype
(Expression
(A
));
4307 -- Check RM 4.6 (24.2/2)
4309 if Is_Array_Type
(Etype
(F
))
4310 and then Is_View_Conversion
(A
)
4312 -- In a view conversion, the conversion must be legal in
4313 -- both directions, and thus both component types must be
4314 -- aliased, or neither (4.6 (8)).
4316 -- Check RM 4.6 (24.8/2)
4318 if Has_Aliased_Components
(Expr_Typ
) /=
4319 Has_Aliased_Components
(Etype
(F
))
4321 -- This normally illegal conversion is legal in an
4322 -- expanded instance body because of RM 12.3(11).
4323 -- At runtime, conversion must create a new object.
4325 if not In_Instance
then
4327 ("both component types in a view conversion must"
4328 & " be aliased, or neither", A
);
4331 -- Check RM 4.6 (24/3)
4333 elsif not Same_Ancestor
(Etype
(F
), Expr_Typ
) then
4334 -- Check view conv between unrelated by ref array
4337 if Is_By_Reference_Type
(Etype
(F
))
4338 or else Is_By_Reference_Type
(Expr_Typ
)
4341 ("view conversion between unrelated by reference "
4342 & "array types not allowed ('A'I-00246)", A
);
4344 -- In Ada 2005 mode, check view conversion component
4345 -- type cannot be private, tagged, or volatile. Note
4346 -- that we only apply this to source conversions. The
4347 -- generated code can contain conversions which are
4348 -- not subject to this test, and we cannot extract the
4349 -- component type in such cases since it is not
4352 elsif Comes_From_Source
(A
)
4353 and then Ada_Version
>= Ada_2005
4356 Comp_Type
: constant Entity_Id
:=
4357 Component_Type
(Expr_Typ
);
4359 if (Is_Private_Type
(Comp_Type
)
4360 and then not Is_Generic_Type
(Comp_Type
))
4361 or else Is_Tagged_Type
(Comp_Type
)
4362 or else Is_Volatile
(Comp_Type
)
4365 ("component type of a view conversion " &
4366 "cannot be private, tagged, or volatile" &
4374 -- AI12-0074 & AI12-0377
4375 -- Check 6.4.1: If the mode is out, the actual parameter is
4376 -- a view conversion, and the type of the formal parameter
4377 -- is a scalar type, then either:
4378 -- - the target and operand type both do not have the
4379 -- Default_Value aspect specified; or
4380 -- - the target and operand type both have the
4381 -- Default_Value aspect specified, and there shall exist
4382 -- a type (other than a root numeric type) that is an
4383 -- ancestor of both the target type and the operand
4386 elsif Ekind
(F
) = E_Out_Parameter
4387 and then Is_Scalar_Type
(Etype
(F
))
4389 if Has_Default_Aspect
(Etype
(F
)) /=
4390 Has_Default_Aspect
(Expr_Typ
)
4393 ("view conversion requires Default_Value on both " &
4394 "types (RM 6.4.1)", A
);
4395 elsif Has_Default_Aspect
(Expr_Typ
)
4396 and then not Same_Ancestor
(Etype
(F
), Expr_Typ
)
4399 ("view conversion between unrelated types with "
4400 & "Default_Value not allowed (RM 6.4.1)", A
);
4405 -- Resolve expression if conversion is all OK
4407 if (Conversion_OK
(A
)
4408 or else Valid_Conversion
(A
, Etype
(A
), Expression
(A
)))
4409 and then not Is_Ref_To_Bit_Packed_Array
(Expression
(A
))
4411 Resolve
(Expression
(A
));
4414 -- If the actual is a function call that returns a limited
4415 -- unconstrained object that needs finalization, create a
4416 -- transient scope for it, so that it can receive the proper
4417 -- finalization list.
4419 elsif Expander_Active
4420 and then Nkind
(A
) = N_Function_Call
4421 and then Is_Limited_Record
(Etype
(F
))
4422 and then not Is_Constrained
(Etype
(F
))
4423 and then (Needs_Finalization
(Etype
(F
))
4424 or else Has_Task
(Etype
(F
)))
4426 Establish_Transient_Scope
(A
, Manage_Sec_Stack
=> False);
4427 Resolve
(A
, Etype
(F
));
4429 -- A small optimization: if one of the actuals is a concatenation
4430 -- create a block around a procedure call to recover stack space.
4431 -- This alleviates stack usage when several procedure calls in
4432 -- the same statement list use concatenation. We do not perform
4433 -- this wrapping for code statements, where the argument is a
4434 -- static string, and we want to preserve warnings involving
4435 -- sequences of such statements.
4437 elsif Expander_Active
4438 and then Nkind
(A
) = N_Op_Concat
4439 and then Nkind
(N
) = N_Procedure_Call_Statement
4440 and then not (Is_Intrinsic_Subprogram
(Nam
)
4441 and then Chars
(Nam
) = Name_Asm
)
4442 and then not Static_Concatenation
(A
)
4444 Establish_Transient_Scope
(A
, Manage_Sec_Stack
=> False);
4445 Resolve
(A
, Etype
(F
));
4448 if Nkind
(A
) = N_Type_Conversion
4449 and then Is_Array_Type
(Etype
(F
))
4450 and then not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
4452 (Is_Limited_Type
(Etype
(F
))
4453 or else Is_Limited_Type
(Etype
(Expression
(A
))))
4456 ("conversion between unrelated limited array types not "
4457 & "allowed ('A'I-00246)", A
);
4459 if Is_Limited_Type
(Etype
(F
)) then
4460 Explain_Limited_Type
(Etype
(F
), A
);
4463 if Is_Limited_Type
(Etype
(Expression
(A
))) then
4464 Explain_Limited_Type
(Etype
(Expression
(A
)), A
);
4468 -- (Ada 2005: AI-251): If the actual is an allocator whose
4469 -- directly designated type is a class-wide interface, we build
4470 -- an anonymous access type to use it as the type of the
4471 -- allocator. Later, when the subprogram call is expanded, if
4472 -- the interface has a secondary dispatch table the expander
4473 -- will add a type conversion to force the correct displacement
4476 if Nkind
(A
) = N_Allocator
then
4478 DDT
: constant Entity_Id
:=
4479 Directly_Designated_Type
(Base_Type
(Etype
(F
)));
4482 -- Displace the pointer to the object to reference its
4483 -- secondary dispatch table.
4485 if Is_Class_Wide_Type
(DDT
)
4486 and then Is_Interface
(DDT
)
4488 Rewrite
(A
, Convert_To
(Etype
(F
), Relocate_Node
(A
)));
4489 Analyze_And_Resolve
(A
, Etype
(F
),
4490 Suppress
=> Access_Check
);
4493 -- Ada 2005, AI-162:If the actual is an allocator, the
4494 -- innermost enclosing statement is the master of the
4495 -- created object. This needs to be done with expansion
4496 -- enabled only, otherwise the transient scope will not
4497 -- be removed in the expansion of the wrapped construct.
4500 and then (Needs_Finalization
(DDT
)
4501 or else Has_Task
(DDT
))
4503 Establish_Transient_Scope
4504 (A
, Manage_Sec_Stack
=> False);
4508 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
4509 Check_Restriction
(No_Access_Parameter_Allocators
, A
);
4513 -- (Ada 2005): The call may be to a primitive operation of a
4514 -- tagged synchronized type, declared outside of the type. In
4515 -- this case the controlling actual must be converted to its
4516 -- corresponding record type, which is the formal type. The
4517 -- actual may be a subtype, either because of a constraint or
4518 -- because it is a generic actual, so use base type to locate
4521 F_Typ
:= Base_Type
(Etype
(F
));
4523 if Is_Tagged_Type
(F_Typ
)
4524 and then (Is_Concurrent_Type
(F_Typ
)
4525 or else Is_Concurrent_Record_Type
(F_Typ
))
4527 -- If the actual is overloaded, look for an interpretation
4528 -- that has a synchronized type.
4530 if not Is_Overloaded
(A
) then
4531 A_Typ
:= Base_Type
(Etype
(A
));
4535 Index
: Interp_Index
;
4539 Get_First_Interp
(A
, Index
, It
);
4540 while Present
(It
.Typ
) loop
4541 if Is_Concurrent_Type
(It
.Typ
)
4542 or else Is_Concurrent_Record_Type
(It
.Typ
)
4544 A_Typ
:= Base_Type
(It
.Typ
);
4548 Get_Next_Interp
(Index
, It
);
4554 Full_A_Typ
: Entity_Id
;
4557 if Present
(Full_View
(A_Typ
)) then
4558 Full_A_Typ
:= Base_Type
(Full_View
(A_Typ
));
4560 Full_A_Typ
:= A_Typ
;
4563 -- Tagged synchronized type (case 1): the actual is a
4566 if Is_Concurrent_Type
(A_Typ
)
4567 and then Corresponding_Record_Type
(A_Typ
) = F_Typ
4570 Unchecked_Convert_To
4571 (Corresponding_Record_Type
(A_Typ
), A
));
4572 Resolve
(A
, Etype
(F
));
4574 -- Tagged synchronized type (case 2): the formal is a
4577 elsif Ekind
(Full_A_Typ
) = E_Record_Type
4579 (Corresponding_Concurrent_Type
(Full_A_Typ
))
4580 and then Is_Concurrent_Type
(F_Typ
)
4581 and then Present
(Corresponding_Record_Type
(F_Typ
))
4582 and then Full_A_Typ
= Corresponding_Record_Type
(F_Typ
)
4584 Resolve
(A
, Corresponding_Record_Type
(F_Typ
));
4589 Resolve
(A
, Etype
(F
));
4593 -- Not a synchronized operation
4596 Resolve
(A
, Etype
(F
));
4603 -- An actual cannot be an untagged formal incomplete type
4605 if Ekind
(A_Typ
) = E_Incomplete_Type
4606 and then not Is_Tagged_Type
(A_Typ
)
4607 and then Is_Generic_Type
(A_Typ
)
4610 ("invalid use of untagged formal incomplete type", A
);
4613 -- has warnings suppressed, then we reset Never_Set_In_Source for
4614 -- the calling entity. The reason for this is to catch cases like
4615 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
4616 -- uses trickery to modify an IN parameter.
4618 if Ekind
(F
) = E_In_Parameter
4619 and then Is_Entity_Name
(A
)
4620 and then Present
(Entity
(A
))
4621 and then Ekind
(Entity
(A
)) = E_Variable
4622 and then Has_Warnings_Off
(F_Typ
)
4624 Set_Never_Set_In_Source
(Entity
(A
), False);
4627 -- Perform error checks for IN and IN OUT parameters
4629 if Ekind
(F
) /= E_Out_Parameter
then
4631 -- Check unset reference. For scalar parameters, it is clearly
4632 -- wrong to pass an uninitialized value as either an IN or
4633 -- IN-OUT parameter. For composites, it is also clearly an
4634 -- error to pass a completely uninitialized value as an IN
4635 -- parameter, but the case of IN OUT is trickier. We prefer
4636 -- not to give a warning here. For example, suppose there is
4637 -- a routine that sets some component of a record to False.
4638 -- It is perfectly reasonable to make this IN-OUT and allow
4639 -- either initialized or uninitialized records to be passed
4642 -- For partially initialized composite values, we also avoid
4643 -- warnings, since it is quite likely that we are passing a
4644 -- partially initialized value and only the initialized fields
4645 -- will in fact be read in the subprogram.
4647 if Is_Scalar_Type
(A_Typ
)
4648 or else (Ekind
(F
) = E_In_Parameter
4649 and then not Is_Partially_Initialized_Type
(A_Typ
))
4651 Check_Unset_Reference
(A
);
4654 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
4655 -- actual to a nested call, since this constitutes a reading of
4656 -- the parameter, which is not allowed.
4658 if Ada_Version
= Ada_83
4659 and then Is_Entity_Name
(A
)
4660 and then Ekind
(Entity
(A
)) = E_Out_Parameter
4662 Error_Msg_N
("(Ada 83) illegal reading of out parameter", A
);
4666 -- In -gnatd.q mode, forget that a given array is constant when
4667 -- it is passed as an IN parameter to a foreign-convention
4668 -- subprogram. This is in case the subprogram evilly modifies the
4669 -- object. Of course, correct code would use IN OUT.
4672 and then Ekind
(F
) = E_In_Parameter
4673 and then Has_Foreign_Convention
(Nam
)
4674 and then Is_Array_Type
(F_Typ
)
4675 and then Nkind
(A
) in N_Has_Entity
4676 and then Present
(Entity
(A
))
4678 Set_Is_True_Constant
(Entity
(A
), False);
4681 -- Case of OUT or IN OUT parameter
4683 if Ekind
(F
) /= E_In_Parameter
then
4685 -- For an Out parameter, check for useless assignment. Note
4686 -- that we can't set Last_Assignment this early, because we may
4687 -- kill current values in Resolve_Call, and that call would
4688 -- clobber the Last_Assignment field.
4690 -- Note: call Warn_On_Useless_Assignment before doing the check
4691 -- below for Is_OK_Variable_For_Out_Formal so that the setting
4692 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
4693 -- reflects the last assignment, not this one.
4695 if Ekind
(F
) = E_Out_Parameter
then
4696 if Warn_On_Modified_As_Out_Parameter
(F
)
4697 and then Is_Entity_Name
(A
)
4698 and then Present
(Entity
(A
))
4699 and then Comes_From_Source
(N
)
4701 Warn_On_Useless_Assignment
(Entity
(A
), A
);
4705 -- Validate the form of the actual. Note that the call to
4706 -- Is_OK_Variable_For_Out_Formal generates the required
4707 -- reference in this case.
4709 -- A call to an initialization procedure for an aggregate
4710 -- component may initialize a nested component of a constant
4711 -- designated object. In this context the object is variable.
4713 if not Is_OK_Variable_For_Out_Formal
(A
)
4714 and then not Is_Init_Proc
(Nam
)
4716 Error_Msg_NE
("actual for& must be a variable", A
, F
);
4718 if Is_Subprogram
(Current_Scope
) then
4719 if Is_Invariant_Procedure
(Current_Scope
)
4720 or else Is_Partial_Invariant_Procedure
(Current_Scope
)
4723 ("function used in invariant cannot modify its "
4726 elsif Is_Predicate_Function
(Current_Scope
) then
4728 ("function used in predicate cannot modify its "
4734 -- What's the following about???
4736 if Is_Entity_Name
(A
) then
4737 Kill_Checks
(Entity
(A
));
4743 if A_Typ
= Any_Type
then
4744 Set_Etype
(N
, Any_Type
);
4748 -- Apply appropriate constraint/predicate checks for IN [OUT] case
4750 if Ekind
(F
) in E_In_Parameter | E_In_Out_Parameter
then
4752 -- Apply predicate tests except in certain special cases. Note
4753 -- that it might be more consistent to apply these only when
4754 -- expansion is active (in Exp_Ch6.Expand_Actuals), as we do
4755 -- for the outbound predicate tests ??? In any case indicate
4756 -- the function being called, for better warnings if the call
4757 -- leads to an infinite recursion.
4759 if Predicate_Tests_On_Arguments
(Nam
) then
4760 Apply_Predicate_Check
(A
, F_Typ
, Nam
);
4763 -- Apply required constraint checks
4765 if Is_Scalar_Type
(A_Typ
) then
4766 Apply_Scalar_Range_Check
(A
, F_Typ
);
4768 elsif Is_Array_Type
(A_Typ
) then
4769 Apply_Length_Check
(A
, F_Typ
);
4771 elsif Is_Record_Type
(F_Typ
)
4772 and then Has_Discriminants
(F_Typ
)
4773 and then Is_Constrained
(F_Typ
)
4774 and then (not Is_Derived_Type
(F_Typ
)
4775 or else Comes_From_Source
(Nam
))
4777 Apply_Discriminant_Check
(A
, F_Typ
);
4779 -- For view conversions of a discriminated object, apply
4780 -- check to object itself, the conversion alreay has the
4783 if Nkind
(A
) = N_Type_Conversion
4784 and then Is_Constrained
(Etype
(Expression
(A
)))
4786 Apply_Discriminant_Check
(Expression
(A
), F_Typ
);
4789 elsif Is_Access_Type
(F_Typ
)
4790 and then Is_Array_Type
(Designated_Type
(F_Typ
))
4791 and then Is_Constrained
(Designated_Type
(F_Typ
))
4793 Apply_Length_Check
(A
, F_Typ
);
4795 elsif Is_Access_Type
(F_Typ
)
4796 and then Has_Discriminants
(Designated_Type
(F_Typ
))
4797 and then Is_Constrained
(Designated_Type
(F_Typ
))
4799 Apply_Discriminant_Check
(A
, F_Typ
);
4802 Apply_Range_Check
(A
, F_Typ
);
4805 -- Ada 2005 (AI-231): Note that the controlling parameter case
4806 -- already existed in Ada 95, which is partially checked
4807 -- elsewhere (see Checks), and we don't want the warning
4808 -- message to differ.
4810 if Is_Access_Type
(F_Typ
)
4811 and then Can_Never_Be_Null
(F_Typ
)
4812 and then Known_Null
(A
)
4814 if Is_Controlling_Formal
(F
) then
4815 Apply_Compile_Time_Constraint_Error
4817 Msg
=> "null value not allowed here??",
4818 Reason
=> CE_Access_Check_Failed
);
4820 elsif Ada_Version
>= Ada_2005
then
4821 Apply_Compile_Time_Constraint_Error
4823 Msg
=> "(Ada 2005) NULL not allowed in "
4824 & "null-excluding formal??",
4825 Reason
=> CE_Null_Not_Allowed
);
4830 -- Checks for OUT parameters and IN OUT parameters
4832 if Ekind
(F
) in E_Out_Parameter | E_In_Out_Parameter
then
4834 -- If there is a type conversion, make sure the return value
4835 -- meets the constraints of the variable before the conversion.
4837 if Nkind
(A
) = N_Type_Conversion
then
4838 if Is_Scalar_Type
(A_Typ
) then
4840 -- Special case here tailored to Exp_Ch6.Is_Legal_Copy,
4841 -- which would prevent the check from being generated.
4842 -- This is for Starlet only though, so long obsolete.
4844 if Mechanism
(F
) = By_Reference
4845 and then Ekind
(Nam
) = E_Procedure
4846 and then Is_Valued_Procedure
(Nam
)
4850 Apply_Scalar_Range_Check
4851 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4854 -- In addition the return value must meet the constraints
4855 -- of the object type (see the comment below).
4857 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
4861 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4864 -- If no conversion, apply scalar range checks and length check
4865 -- based on the subtype of the actual (NOT that of the formal).
4866 -- This indicates that the check takes place on return from the
4867 -- call. During expansion the required constraint checks are
4868 -- inserted. In GNATprove mode, in the absence of expansion,
4869 -- the flag indicates that the returned value is valid.
4872 if Is_Scalar_Type
(F_Typ
) then
4873 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
4875 elsif Is_Array_Type
(F_Typ
)
4876 and then Ekind
(F
) = E_Out_Parameter
4878 Apply_Length_Check
(A
, F_Typ
);
4881 Apply_Range_Check
(A
, A_Typ
, F_Typ
);
4885 -- Note: we do not apply the predicate checks for the case of
4886 -- OUT and IN OUT parameters. They are instead applied in the
4887 -- Expand_Actuals routine in Exp_Ch6.
4890 -- If the formal is of an unconstrained array subtype with fixed
4891 -- lower bound, then sliding to that bound may be needed.
4893 if Is_Fixed_Lower_Bound_Array_Subtype
(F_Typ
) then
4894 Expand_Sliding_Conversion
(A
, F_Typ
);
4897 -- An actual associated with an access parameter is implicitly
4898 -- converted to the anonymous access type of the formal and must
4899 -- satisfy the legality checks for access conversions.
4901 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
4902 if not Valid_Conversion
(A
, F_Typ
, A
) then
4904 ("invalid implicit conversion for access parameter", A
);
4907 -- If the actual is an access selected component of a variable,
4908 -- the call may modify its designated object. It is reasonable
4909 -- to treat this as a potential modification of the enclosing
4910 -- record, to prevent spurious warnings that it should be
4911 -- declared as a constant, because intuitively programmers
4912 -- regard the designated subcomponent as part of the record.
4914 if Nkind
(A
) = N_Selected_Component
4915 and then Is_Entity_Name
(Prefix
(A
))
4916 and then not Is_Constant_Object
(Entity
(Prefix
(A
)))
4918 Note_Possible_Modification
(A
, Sure
=> False);
4922 -- Check illegal cases of atomic/volatile/VFA actual (RM C.6(12))
4924 if (Is_By_Reference_Type
(F_Typ
) or else Is_Aliased
(F
))
4925 and then Comes_From_Source
(N
)
4927 if Is_Atomic_Object
(A
)
4928 and then not Is_Atomic
(F_Typ
)
4931 ("cannot pass atomic object to nonatomic formal&",
4934 ("\which is passed by reference (RM C.6(12))", A
);
4936 elsif Is_Volatile_Object_Ref
(A
)
4937 and then not Is_Volatile
(F_Typ
)
4940 ("cannot pass volatile object to nonvolatile formal&",
4943 ("\which is passed by reference (RM C.6(12))", A
);
4945 elsif Is_Volatile_Full_Access_Object_Ref
(A
)
4946 and then not Is_Volatile_Full_Access
(F_Typ
)
4949 ("cannot pass full access object to nonfull access "
4952 ("\which is passed by reference (RM C.6(12))", A
);
4955 -- Check for nonatomic subcomponent of a full access object
4956 -- in Ada 2022 (RM C.6 (12)).
4958 if Ada_Version
>= Ada_2022
4959 and then Is_Subcomponent_Of_Full_Access_Object
(A
)
4960 and then not Is_Atomic_Object
(A
)
4963 ("cannot pass nonatomic subcomponent of full access "
4966 ("\to formal & which is passed by reference (RM C.6(12))",
4971 -- Check that subprograms don't have improper controlling
4972 -- arguments (RM 3.9.2 (9)).
4974 -- A primitive operation may have an access parameter of an
4975 -- incomplete tagged type, but a dispatching call is illegal
4976 -- if the type is still incomplete.
4978 if Is_Controlling_Formal
(F
) then
4979 Set_Is_Controlling_Actual
(A
);
4981 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
4983 Desig
: constant Entity_Id
:= Designated_Type
(F_Typ
);
4985 if Ekind
(Desig
) = E_Incomplete_Type
4986 and then No
(Full_View
(Desig
))
4987 and then No
(Non_Limited_View
(Desig
))
4990 ("premature use of incomplete type& "
4991 & "in dispatching call", A
, Desig
);
4996 elsif Nkind
(A
) = N_Explicit_Dereference
then
4997 Validate_Remote_Access_To_Class_Wide_Type
(A
);
5000 -- Apply legality rule 3.9.2 (9/1)
5002 -- Skip this check on helpers and indirect-call wrappers built to
5003 -- support class-wide preconditions.
5005 if (Is_Class_Wide_Type
(A_Typ
) or else Is_Dynamically_Tagged
(A
))
5006 and then not Is_Class_Wide_Type
(F_Typ
)
5007 and then not Is_Controlling_Formal
(F
)
5008 and then not In_Instance
5009 and then (not Is_Subprogram
(Nam
)
5010 or else No
(Class_Preconditions_Subprogram
(Nam
)))
5012 Error_Msg_N
("class-wide argument not allowed here!", A
);
5014 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
5015 Error_Msg_Node_2
:= F_Typ
;
5017 ("& is not a dispatching operation of &!", A
, Nam
);
5020 -- Apply the checks described in 3.10.2(27): if the context is a
5021 -- specific access-to-object, the actual cannot be class-wide.
5022 -- Use base type to exclude access_to_subprogram cases.
5024 elsif Is_Access_Type
(A_Typ
)
5025 and then Is_Access_Type
(F_Typ
)
5026 and then not Is_Access_Subprogram_Type
(Base_Type
(F_Typ
))
5027 and then (Is_Class_Wide_Type
(Designated_Type
(A_Typ
))
5028 or else (Nkind
(A
) = N_Attribute_Reference
5030 Is_Class_Wide_Type
(Etype
(Prefix
(A
)))))
5031 and then not Is_Class_Wide_Type
(Designated_Type
(F_Typ
))
5032 and then not Is_Controlling_Formal
(F
)
5034 -- Disable these checks for call to imported C++ subprograms
5037 (Is_Entity_Name
(Name
(N
))
5038 and then Is_Imported
(Entity
(Name
(N
)))
5039 and then Convention
(Entity
(Name
(N
))) = Convention_CPP
)
5042 ("access to class-wide argument not allowed here!", A
);
5044 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
5045 Error_Msg_Node_2
:= Designated_Type
(F_Typ
);
5047 ("& is not a dispatching operation of &!", A
, Nam
);
5051 Check_Aliased_Parameter
;
5055 -- If it is a named association, treat the selector_name as a
5056 -- proper identifier, and mark the corresponding entity.
5058 if Nkind
(Parent
(A
)) = N_Parameter_Association
5060 -- Ignore reference in SPARK mode, as it refers to an entity not
5061 -- in scope at the point of reference, so the reference should
5062 -- be ignored for computing effects of subprograms.
5064 and then not GNATprove_Mode
5066 -- If subprogram is overridden, use name of formal that
5069 if Present
(Real_Subp
) then
5070 Set_Entity
(Selector_Name
(Parent
(A
)), Real_F
);
5071 Set_Etype
(Selector_Name
(Parent
(A
)), Etype
(Real_F
));
5074 Set_Entity
(Selector_Name
(Parent
(A
)), F
);
5075 Generate_Reference
(F
, Selector_Name
(Parent
(A
)));
5076 Set_Etype
(Selector_Name
(Parent
(A
)), F_Typ
);
5077 Generate_Reference
(F_Typ
, N
, ' ');
5083 if Ekind
(F
) /= E_Out_Parameter
then
5084 Check_Unset_Reference
(A
);
5087 -- The following checks are only relevant when SPARK_Mode is on as
5088 -- they are not standard Ada legality rule. Internally generated
5089 -- temporaries are ignored.
5091 if SPARK_Mode
= On
and then Comes_From_Source
(A
) then
5093 -- Inspect the expression and flag each effectively volatile
5094 -- object for reading as illegal because it appears within
5095 -- an interfering context. Note that this is usually done
5096 -- in Resolve_Entity_Name, but when the effectively volatile
5097 -- object for reading appears as an actual in a call, the call
5098 -- must be resolved first.
5100 Flag_Effectively_Volatile_Objects
(A
);
5103 -- A formal parameter of a specific tagged type whose related
5104 -- subprogram is subject to pragma Extensions_Visible with value
5105 -- "False" cannot act as an actual in a subprogram with value
5106 -- "True" (SPARK RM 6.1.7(3)).
5108 -- No check needed for helpers and indirect-call wrappers built to
5109 -- support class-wide preconditions.
5111 if Is_EVF_Expression
(A
)
5112 and then Extensions_Visible_Status
(Nam
) =
5113 Extensions_Visible_True
5114 and then No
(Class_Preconditions_Subprogram
(Current_Scope
))
5117 ("formal parameter cannot act as actual parameter when "
5118 & "Extensions_Visible is False", A
);
5120 ("\subprogram & has Extensions_Visible True", A
, Nam
);
5123 -- The actual parameter of a Ghost subprogram whose formal is of
5124 -- mode IN OUT or OUT must be a Ghost variable (SPARK RM 6.9(12)).
5126 if Comes_From_Source
(Nam
)
5127 and then Is_Ghost_Entity
(Nam
)
5128 and then Ekind
(F
) in E_In_Out_Parameter | E_Out_Parameter
5129 and then Is_Entity_Name
(A
)
5130 and then Present
(Entity
(A
))
5131 and then not Is_Ghost_Entity
(Entity
(A
))
5134 ("non-ghost variable & cannot appear as actual in call to "
5135 & "ghost procedure", A
, Entity
(A
));
5137 if Ekind
(F
) = E_In_Out_Parameter
then
5138 Error_Msg_N
("\corresponding formal has mode `IN OUT`", A
);
5140 Error_Msg_N
("\corresponding formal has mode OUT", A
);
5144 -- (AI12-0397): The target of a subprogram call that occurs within
5145 -- the expression of an Default_Initial_Condition aspect and has
5146 -- an actual that is the current instance of the type must be
5147 -- either a primitive of the type or a class-wide subprogram,
5148 -- because the type of the current instance in such an aspect is
5149 -- considered to be a notional formal derived type whose only
5150 -- operations correspond to the primitives of the enclosing type.
5151 -- Nonprimitives can be called, but the current instance must be
5152 -- converted rather than passed directly. Note that a current
5153 -- instance of a type with DIC will occur as a reference to an
5154 -- in-mode formal of an enclosing DIC procedure or partial DIC
5155 -- procedure. (It seems that this check should perhaps also apply
5156 -- to calls within Type_Invariant'Class, but not Type_Invariant,
5159 if Nkind
(A
) = N_Identifier
5160 and then Ekind
(Entity
(A
)) = E_In_Parameter
5162 and then Is_Subprogram
(Scope
(Entity
(A
)))
5163 and then Is_DIC_Procedure
(Scope
(Entity
(A
)))
5165 -- We check Comes_From_Source to exclude inherited primitives
5166 -- from being flagged, because such subprograms turn out to not
5167 -- always have the Is_Primitive flag set. ???
5169 and then Comes_From_Source
(Nam
)
5171 and then not Is_Primitive
(Nam
)
5172 and then not Is_Class_Wide_Type
(F_Typ
)
5175 ("call to nonprimitive & with current instance not allowed " &
5176 "for aspect", A
, Nam
);
5181 -- Case where actual is not present
5189 if Present
(Real_Subp
) then
5190 Next_Formal
(Real_F
);
5193 end Resolve_Actuals
;
5195 -----------------------
5196 -- Resolve_Allocator --
5197 -----------------------
5199 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
) is
5200 Desig_T
: constant Entity_Id
:= Designated_Type
(Typ
);
5201 E
: constant Node_Id
:= Expression
(N
);
5203 Discrim
: Entity_Id
;
5206 Assoc
: Node_Id
:= Empty
;
5209 procedure Check_Allocator_Discrim_Accessibility
5210 (Disc_Exp
: Node_Id
;
5211 Alloc_Typ
: Entity_Id
);
5212 -- Check that accessibility level associated with an access discriminant
5213 -- initialized in an allocator by the expression Disc_Exp is not deeper
5214 -- than the level of the allocator type Alloc_Typ. An error message is
5215 -- issued if this condition is violated. Specialized checks are done for
5216 -- the cases of a constraint expression which is an access attribute or
5217 -- an access discriminant.
5219 procedure Check_Allocator_Discrim_Accessibility_Exprs
5220 (Curr_Exp
: Node_Id
;
5221 Alloc_Typ
: Entity_Id
);
5222 -- Dispatch checks performed by Check_Allocator_Discrim_Accessibility
5223 -- across all expressions within a given conditional expression.
5225 function In_Dispatching_Context
return Boolean;
5226 -- If the allocator is an actual in a call, it is allowed to be class-
5227 -- wide when the context is not because it is a controlling actual.
5229 -------------------------------------------
5230 -- Check_Allocator_Discrim_Accessibility --
5231 -------------------------------------------
5233 procedure Check_Allocator_Discrim_Accessibility
5234 (Disc_Exp
: Node_Id
;
5235 Alloc_Typ
: Entity_Id
)
5238 if Type_Access_Level
(Etype
(Disc_Exp
)) >
5239 Deepest_Type_Access_Level
(Alloc_Typ
)
5242 ("operand type has deeper level than allocator type", Disc_Exp
);
5244 -- When the expression is an Access attribute the level of the prefix
5245 -- object must not be deeper than that of the allocator's type.
5247 elsif Nkind
(Disc_Exp
) = N_Attribute_Reference
5248 and then Get_Attribute_Id
(Attribute_Name
(Disc_Exp
)) =
5250 and then Static_Accessibility_Level
5251 (Disc_Exp
, Zero_On_Dynamic_Level
)
5252 > Deepest_Type_Access_Level
(Alloc_Typ
)
5255 ("prefix of attribute has deeper level than allocator type",
5258 -- When the expression is an access discriminant the check is against
5259 -- the level of the prefix object.
5261 elsif Ekind
(Etype
(Disc_Exp
)) = E_Anonymous_Access_Type
5262 and then Nkind
(Disc_Exp
) = N_Selected_Component
5263 and then Static_Accessibility_Level
5264 (Disc_Exp
, Zero_On_Dynamic_Level
)
5265 > Deepest_Type_Access_Level
(Alloc_Typ
)
5268 ("access discriminant has deeper level than allocator type",
5271 -- All other cases are legal
5276 end Check_Allocator_Discrim_Accessibility
;
5278 -------------------------------------------------
5279 -- Check_Allocator_Discrim_Accessibility_Exprs --
5280 -------------------------------------------------
5282 procedure Check_Allocator_Discrim_Accessibility_Exprs
5283 (Curr_Exp
: Node_Id
;
5284 Alloc_Typ
: Entity_Id
)
5288 Disc_Exp
: constant Node_Id
:= Original_Node
(Curr_Exp
);
5290 -- When conditional expressions are constant folded we know at
5291 -- compile time which expression to check - so don't bother with
5292 -- the rest of the cases.
5294 if Nkind
(Curr_Exp
) = N_Attribute_Reference
then
5295 Check_Allocator_Discrim_Accessibility
(Curr_Exp
, Alloc_Typ
);
5297 -- Non-constant-folded if expressions
5299 elsif Nkind
(Disc_Exp
) = N_If_Expression
then
5300 -- Check both expressions if they are still present in the face
5303 Expr
:= Next
(First
(Expressions
(Disc_Exp
)));
5304 if Present
(Expr
) then
5305 Check_Allocator_Discrim_Accessibility_Exprs
(Expr
, Alloc_Typ
);
5307 if Present
(Expr
) then
5308 Check_Allocator_Discrim_Accessibility_Exprs
5313 -- Non-constant-folded case expressions
5315 elsif Nkind
(Disc_Exp
) = N_Case_Expression
then
5316 -- Check all alternatives
5318 Alt
:= First
(Alternatives
(Disc_Exp
));
5319 while Present
(Alt
) loop
5320 Check_Allocator_Discrim_Accessibility_Exprs
5321 (Expression
(Alt
), Alloc_Typ
);
5326 -- Base case, check the accessibility of the original node of the
5330 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Alloc_Typ
);
5332 end Check_Allocator_Discrim_Accessibility_Exprs
;
5334 ----------------------------
5335 -- In_Dispatching_Context --
5336 ----------------------------
5338 function In_Dispatching_Context
return Boolean is
5339 Par
: constant Node_Id
:= Parent
(N
);
5342 return Nkind
(Par
) in N_Subprogram_Call
5343 and then Is_Entity_Name
(Name
(Par
))
5344 and then Is_Dispatching_Operation
(Entity
(Name
(Par
)));
5345 end In_Dispatching_Context
;
5347 -- Start of processing for Resolve_Allocator
5350 -- Replace general access with specific type
5352 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
5353 Set_Etype
(N
, Base_Type
(Typ
));
5356 if Is_Abstract_Type
(Typ
) then
5357 Error_Msg_N
("type of allocator cannot be abstract", N
);
5360 -- For qualified expression, resolve the expression using the given
5361 -- subtype (nothing to do for type mark, subtype indication)
5363 if Nkind
(E
) = N_Qualified_Expression
then
5364 if Is_Class_Wide_Type
(Etype
(E
))
5365 and then not Is_Class_Wide_Type
(Desig_T
)
5366 and then not In_Dispatching_Context
5369 ("class-wide allocator not allowed for this access type", N
);
5372 -- Do a full resolution to apply constraint and predicate checks
5374 Resolve_Qualified_Expression
(E
, Etype
(E
));
5375 Check_Unset_Reference
(Expression
(E
));
5377 -- Allocators generated by the build-in-place expansion mechanism
5378 -- are explicitly marked as coming from source but do not need to be
5379 -- checked for limited initialization. To exclude this case, ensure
5380 -- that the parent of the allocator is a source node.
5381 -- The return statement constructed for an Expression_Function does
5382 -- not come from source but requires a limited check.
5384 if Is_Limited_Type
(Etype
(E
))
5385 and then Comes_From_Source
(N
)
5387 (Comes_From_Source
(Parent
(N
))
5389 (Ekind
(Current_Scope
) = E_Function
5390 and then Nkind
(Original_Node
(Unit_Declaration_Node
5391 (Current_Scope
))) = N_Expression_Function
))
5392 and then not In_Instance_Body
5394 if not OK_For_Limited_Init
(Etype
(E
), Expression
(E
)) then
5395 if Nkind
(Parent
(N
)) = N_Assignment_Statement
then
5397 ("illegal expression for initialized allocator of a "
5398 & "limited type (RM 7.5 (2.7/2))", N
);
5401 ("initialization not allowed for limited types", N
);
5404 Explain_Limited_Type
(Etype
(E
), N
);
5408 -- Calls to build-in-place functions are not currently supported in
5409 -- allocators for access types associated with a simple storage pool.
5410 -- Supporting such allocators may require passing additional implicit
5411 -- parameters to build-in-place functions (or a significant revision
5412 -- of the current b-i-p implementation to unify the handling for
5413 -- multiple kinds of storage pools). ???
5415 if Is_Limited_View
(Desig_T
)
5416 and then Nkind
(Expression
(E
)) = N_Function_Call
5419 Pool
: constant Entity_Id
:=
5420 Associated_Storage_Pool
(Root_Type
(Typ
));
5424 Present
(Get_Rep_Pragma
5425 (Etype
(Pool
), Name_Simple_Storage_Pool_Type
))
5428 ("limited function calls not yet supported in simple "
5429 & "storage pool allocators", Expression
(E
));
5434 -- A special accessibility check is needed for allocators that
5435 -- constrain access discriminants. The level of the type of the
5436 -- expression used to constrain an access discriminant cannot be
5437 -- deeper than the type of the allocator (in contrast to access
5438 -- parameters, where the level of the actual can be arbitrary).
5440 -- We can't use Valid_Conversion to perform this check because in
5441 -- general the type of the allocator is unrelated to the type of
5442 -- the access discriminant.
5444 if Ekind
(Typ
) /= E_Anonymous_Access_Type
5445 or else Is_Local_Anonymous_Access
(Typ
)
5447 Subtyp
:= Entity
(Subtype_Mark
(E
));
5449 Aggr
:= Original_Node
(Expression
(E
));
5451 if Has_Discriminants
(Subtyp
)
5452 and then Nkind
(Aggr
) in N_Aggregate | N_Extension_Aggregate
5454 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
5456 -- Get the first component expression of the aggregate
5458 if Present
(Expressions
(Aggr
)) then
5459 Disc_Exp
:= First
(Expressions
(Aggr
));
5461 elsif Present
(Component_Associations
(Aggr
)) then
5462 Assoc
:= First
(Component_Associations
(Aggr
));
5464 if Present
(Assoc
) then
5465 Disc_Exp
:= Expression
(Assoc
);
5474 while Present
(Discrim
) and then Present
(Disc_Exp
) loop
5475 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
5476 Check_Allocator_Discrim_Accessibility_Exprs
5480 Next_Discriminant
(Discrim
);
5482 if Present
(Discrim
) then
5483 if Present
(Assoc
) then
5485 Disc_Exp
:= Expression
(Assoc
);
5487 elsif Present
(Next
(Disc_Exp
)) then
5491 Assoc
:= First
(Component_Associations
(Aggr
));
5493 if Present
(Assoc
) then
5494 Disc_Exp
:= Expression
(Assoc
);
5504 -- For a subtype mark or subtype indication, freeze the subtype
5507 Freeze_Expression
(E
);
5509 if Is_Access_Constant
(Typ
) and then not No_Initialization
(N
) then
5511 ("initialization required for access-to-constant allocator", N
);
5514 -- A special accessibility check is needed for allocators that
5515 -- constrain access discriminants. The level of the type of the
5516 -- expression used to constrain an access discriminant cannot be
5517 -- deeper than the type of the allocator (in contrast to access
5518 -- parameters, where the level of the actual can be arbitrary).
5519 -- We can't use Valid_Conversion to perform this check because
5520 -- in general the type of the allocator is unrelated to the type
5521 -- of the access discriminant.
5523 if Nkind
(Original_Node
(E
)) = N_Subtype_Indication
5524 and then (Ekind
(Typ
) /= E_Anonymous_Access_Type
5525 or else Is_Local_Anonymous_Access
(Typ
))
5527 Subtyp
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
5529 if Has_Discriminants
(Subtyp
) then
5530 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
5531 Constr
:= First
(Constraints
(Constraint
(Original_Node
(E
))));
5532 while Present
(Discrim
) and then Present
(Constr
) loop
5533 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
5534 if Nkind
(Constr
) = N_Discriminant_Association
then
5535 Disc_Exp
:= Expression
(Constr
);
5540 Check_Allocator_Discrim_Accessibility_Exprs
5544 Next_Discriminant
(Discrim
);
5551 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
5552 -- check that the level of the type of the created object is not deeper
5553 -- than the level of the allocator's access type, since extensions can
5554 -- now occur at deeper levels than their ancestor types. This is a
5555 -- static accessibility level check; a run-time check is also needed in
5556 -- the case of an initialized allocator with a class-wide argument (see
5557 -- Expand_Allocator_Expression).
5559 if Ada_Version
>= Ada_2005
5560 and then Is_Class_Wide_Type
(Desig_T
)
5563 Exp_Typ
: Entity_Id
;
5566 if Nkind
(E
) = N_Qualified_Expression
then
5567 Exp_Typ
:= Etype
(E
);
5568 elsif Nkind
(E
) = N_Subtype_Indication
then
5569 Exp_Typ
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
5571 Exp_Typ
:= Entity
(E
);
5574 if Type_Access_Level
(Exp_Typ
) >
5575 Deepest_Type_Access_Level
(Typ
)
5577 if In_Instance_Body
then
5578 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5580 ("type in allocator has deeper level than designated "
5581 & "class-wide type<<", E
);
5582 Error_Msg_N
("\Program_Error [<<", E
);
5585 Make_Raise_Program_Error
(Sloc
(N
),
5586 Reason
=> PE_Accessibility_Check_Failed
));
5589 -- Do not apply Ada 2005 accessibility checks on a class-wide
5590 -- allocator if the type given in the allocator is a formal
5591 -- type or within a formal package. A run-time check will be
5592 -- performed in the instance.
5594 elsif not Is_Generic_Type
(Exp_Typ
)
5595 and then not In_Generic_Formal_Package
(Exp_Typ
)
5598 ("type in allocator has deeper level than designated "
5599 & "class-wide type", E
);
5605 -- Check for allocation from an empty storage pool. But do not complain
5606 -- if it's a return statement for a build-in-place function, because the
5607 -- allocator is there just in case the caller uses an allocator. If the
5608 -- caller does use an allocator, it will be caught at the call site.
5610 if No_Pool_Assigned
(Typ
)
5611 and then not Alloc_For_BIP_Return
(N
)
5613 Error_Msg_N
("allocation from empty storage pool!", N
);
5615 -- If the context is an unchecked conversion, as may happen within an
5616 -- inlined subprogram, the allocator is being resolved with its own
5617 -- anonymous type. In that case, if the target type has a specific
5618 -- storage pool, it must be inherited explicitly by the allocator type.
5620 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
5621 and then No
(Associated_Storage_Pool
(Typ
))
5623 Set_Associated_Storage_Pool
5624 (Typ
, Associated_Storage_Pool
(Etype
(Parent
(N
))));
5627 if Ekind
(Etype
(N
)) = E_Anonymous_Access_Type
then
5628 Check_Restriction
(No_Anonymous_Allocators
, N
);
5631 -- Check that an allocator with task parts isn't for a nested access
5632 -- type when restriction No_Task_Hierarchy applies.
5634 if not Is_Library_Level_Entity
(Base_Type
(Typ
))
5635 and then Has_Task
(Base_Type
(Desig_T
))
5637 Check_Restriction
(No_Task_Hierarchy
, N
);
5640 -- An illegal allocator may be rewritten as a raise Program_Error
5643 if Nkind
(N
) = N_Allocator
then
5645 -- Avoid coextension processing for an allocator that is the
5646 -- expansion of a build-in-place function call.
5648 if Nkind
(Original_Node
(N
)) = N_Allocator
5649 and then Nkind
(Expression
(Original_Node
(N
))) =
5650 N_Qualified_Expression
5651 and then Nkind
(Expression
(Expression
(Original_Node
(N
)))) =
5653 and then Is_Expanded_Build_In_Place_Call
5654 (Expression
(Expression
(Original_Node
(N
))))
5656 null; -- b-i-p function call case
5659 -- An anonymous access discriminant is the definition of a
5662 if Ekind
(Typ
) = E_Anonymous_Access_Type
5663 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
5664 N_Discriminant_Specification
5667 Discr
: constant Entity_Id
:=
5668 Defining_Identifier
(Associated_Node_For_Itype
(Typ
));
5671 Check_Restriction
(No_Coextensions
, N
);
5673 -- Ada 2012 AI05-0052: If the designated type of the
5674 -- allocator is limited, then the allocator shall not
5675 -- be used to define the value of an access discriminant
5676 -- unless the discriminated type is immutably limited.
5678 if Ada_Version
>= Ada_2012
5679 and then Is_Limited_Type
(Desig_T
)
5680 and then not Is_Limited_View
(Scope
(Discr
))
5683 ("only immutably limited types can have anonymous "
5684 & "access discriminants designating a limited type",
5689 -- Avoid marking an allocator as a dynamic coextension if it is
5690 -- within a static construct.
5692 if not Is_Static_Coextension
(N
) then
5693 Set_Is_Dynamic_Coextension
(N
);
5695 -- Finalization and deallocation of coextensions utilizes an
5696 -- approximate implementation which does not directly adhere
5697 -- to the semantic rules. Warn on potential issues involving
5700 if Is_Controlled
(Desig_T
) then
5702 ("??coextension will not be finalized when its "
5703 & "associated owner is deallocated or finalized", N
);
5706 ("??coextension will not be deallocated when its "
5707 & "associated owner is deallocated", N
);
5711 -- Cleanup for potential static coextensions
5714 Set_Is_Dynamic_Coextension
(N
, False);
5715 Set_Is_Static_Coextension
(N
, False);
5717 -- Anonymous access-to-controlled objects are not finalized on
5718 -- time because this involves run-time ownership and currently
5719 -- this property is not available. In rare cases the object may
5720 -- not be finalized at all. Warn on potential issues involving
5721 -- anonymous access-to-controlled objects.
5723 if Ekind
(Typ
) = E_Anonymous_Access_Type
5724 and then Is_Controlled_Active
(Desig_T
)
5727 ("??object designated by anonymous access object might "
5728 & "not be finalized until its enclosing library unit "
5729 & "goes out of scope", N
);
5730 Error_Msg_N
("\use named access type instead", N
);
5736 -- Report a simple error: if the designated object is a local task,
5737 -- its body has not been seen yet, and its activation will fail an
5738 -- elaboration check.
5740 if Is_Task_Type
(Desig_T
)
5741 and then Scope
(Base_Type
(Desig_T
)) = Current_Scope
5742 and then Is_Compilation_Unit
(Current_Scope
)
5743 and then Ekind
(Current_Scope
) = E_Package
5744 and then not In_Package_Body
(Current_Scope
)
5746 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5747 Error_Msg_N
("cannot activate task before body seen<<", N
);
5748 Error_Msg_N
("\Program_Error [<<", N
);
5751 -- Ada 2012 (AI05-0111-3): Detect an attempt to allocate a task or a
5752 -- type with a task component on a subpool. This action must raise
5753 -- Program_Error at runtime.
5755 if Ada_Version
>= Ada_2012
5756 and then Nkind
(N
) = N_Allocator
5757 and then Present
(Subpool_Handle_Name
(N
))
5758 and then Has_Task
(Desig_T
)
5760 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5761 Error_Msg_N
("cannot allocate task on subpool<<", N
);
5762 Error_Msg_N
("\Program_Error [<<", N
);
5765 Make_Raise_Program_Error
(Sloc
(N
),
5766 Reason
=> PE_Explicit_Raise
));
5769 end Resolve_Allocator
;
5771 ---------------------------
5772 -- Resolve_Arithmetic_Op --
5773 ---------------------------
5775 -- Used for resolving all arithmetic operators except exponentiation
5777 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
5778 L
: constant Node_Id
:= Left_Opnd
(N
);
5779 R
: constant Node_Id
:= Right_Opnd
(N
);
5780 TL
: constant Entity_Id
:= Base_Type
(Etype
(L
));
5781 TR
: constant Entity_Id
:= Base_Type
(Etype
(R
));
5785 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
5786 -- We do the resolution using the base type, because intermediate values
5787 -- in expressions always are of the base type, not a subtype of it.
5789 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean;
5790 -- Returns True if N is in a context that expects "any real type"
5792 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean;
5793 -- Return True iff given type is Integer or universal real/integer
5795 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
);
5796 -- Choose type of integer literal in fixed-point operation to conform
5797 -- to available fixed-point type. T is the type of the other operand,
5798 -- which is needed to determine the expected type of N.
5800 procedure Set_Operand_Type
(N
: Node_Id
);
5801 -- Set operand type to T if universal
5803 -------------------------------
5804 -- Expected_Type_Is_Any_Real --
5805 -------------------------------
5807 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean is
5809 -- N is the expression after "delta" in a fixed_point_definition;
5812 return Nkind
(Parent
(N
)) in N_Ordinary_Fixed_Point_Definition
5813 | N_Decimal_Fixed_Point_Definition
5815 -- N is one of the bounds in a real_range_specification;
5818 | N_Real_Range_Specification
5820 -- N is the expression of a delta_constraint;
5823 | N_Delta_Constraint
;
5824 end Expected_Type_Is_Any_Real
;
5826 -----------------------------
5827 -- Is_Integer_Or_Universal --
5828 -----------------------------
5830 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean is
5832 Index
: Interp_Index
;
5836 if not Is_Overloaded
(N
) then
5838 return Base_Type
(T
) = Base_Type
(Standard_Integer
)
5839 or else Is_Universal_Numeric_Type
(T
);
5841 Get_First_Interp
(N
, Index
, It
);
5842 while Present
(It
.Typ
) loop
5843 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
)
5844 or else Is_Universal_Numeric_Type
(It
.Typ
)
5849 Get_Next_Interp
(Index
, It
);
5854 end Is_Integer_Or_Universal
;
5856 ----------------------------
5857 -- Set_Mixed_Mode_Operand --
5858 ----------------------------
5860 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
) is
5861 Index
: Interp_Index
;
5865 if Universal_Interpretation
(N
) = Universal_Integer
then
5867 -- A universal integer literal is resolved as standard integer
5868 -- except in the case of a fixed-point result, where we leave it
5869 -- as universal (to be handled by Exp_Fixd later on)
5871 if Is_Fixed_Point_Type
(T
) then
5872 Resolve
(N
, Universal_Integer
);
5874 Resolve
(N
, Standard_Integer
);
5877 elsif Universal_Interpretation
(N
) = Universal_Real
5878 and then (T
= Base_Type
(Standard_Integer
)
5879 or else Is_Universal_Numeric_Type
(T
))
5881 -- A universal real can appear in a fixed-type context. We resolve
5882 -- the literal with that context, even though this might raise an
5883 -- exception prematurely (the other operand may be zero).
5887 elsif Etype
(N
) = Base_Type
(Standard_Integer
)
5888 and then T
= Universal_Real
5889 and then Is_Overloaded
(N
)
5891 -- Integer arg in mixed-mode operation. Resolve with universal
5892 -- type, in case preference rule must be applied.
5894 Resolve
(N
, Universal_Integer
);
5896 elsif Etype
(N
) = T
and then B_Typ
/= Universal_Fixed
then
5898 -- If the operand is part of a fixed multiplication operation,
5899 -- a conversion will be applied to each operand, so resolve it
5900 -- with its own type.
5902 if Nkind
(Parent
(N
)) in N_Op_Divide | N_Op_Multiply
then
5906 -- Not a mixed-mode operation, resolve with context
5911 elsif Etype
(N
) = Any_Fixed
then
5913 -- N may itself be a mixed-mode operation, so use context type
5917 elsif Is_Fixed_Point_Type
(T
)
5918 and then B_Typ
= Universal_Fixed
5919 and then Is_Overloaded
(N
)
5921 -- Must be (fixed * fixed) operation, operand must have one
5922 -- compatible interpretation.
5924 Resolve
(N
, Any_Fixed
);
5926 elsif Is_Fixed_Point_Type
(B_Typ
)
5927 and then (T
= Universal_Real
or else Is_Fixed_Point_Type
(T
))
5928 and then Is_Overloaded
(N
)
5930 -- C * F(X) in a fixed context, where C is a real literal or a
5931 -- fixed-point expression. F must have either a fixed type
5932 -- interpretation or an integer interpretation, but not both.
5934 Get_First_Interp
(N
, Index
, It
);
5935 while Present
(It
.Typ
) loop
5936 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
) then
5937 if Analyzed
(N
) then
5938 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5940 Resolve
(N
, Standard_Integer
);
5943 elsif Is_Fixed_Point_Type
(It
.Typ
) then
5944 if Analyzed
(N
) then
5945 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5947 Resolve
(N
, It
.Typ
);
5951 Get_Next_Interp
(Index
, It
);
5954 -- Reanalyze the literal with the fixed type of the context. If
5955 -- context is Universal_Fixed, we are within a conversion, leave
5956 -- the literal as a universal real because there is no usable
5957 -- fixed type, and the target of the conversion plays no role in
5971 if B_Typ
= Universal_Fixed
5972 and then Nkind
(Op2
) = N_Real_Literal
5974 T2
:= Universal_Real
;
5979 Set_Analyzed
(Op2
, False);
5983 -- A universal real conditional expression can appear in a fixed-type
5984 -- context and must be resolved with that context to facilitate the
5985 -- code generation in the back end. However, If the context is
5986 -- Universal_fixed (i.e. as an operand of a multiplication/division
5987 -- involving a fixed-point operand) the conditional expression must
5988 -- resolve to a unique visible fixed_point type, normally Duration.
5990 elsif Nkind
(N
) in N_Case_Expression | N_If_Expression
5991 and then Etype
(N
) = Universal_Real
5992 and then Is_Fixed_Point_Type
(B_Typ
)
5994 if B_Typ
= Universal_Fixed
then
5995 Resolve
(N
, Unique_Fixed_Point_Type
(N
));
6004 end Set_Mixed_Mode_Operand
;
6006 ----------------------
6007 -- Set_Operand_Type --
6008 ----------------------
6010 procedure Set_Operand_Type
(N
: Node_Id
) is
6012 if Is_Universal_Numeric_Type
(Etype
(N
)) then
6015 end Set_Operand_Type
;
6017 -- Start of processing for Resolve_Arithmetic_Op
6020 if Comes_From_Source
(N
)
6021 and then Ekind
(Entity
(N
)) = E_Function
6022 and then Is_Imported
(Entity
(N
))
6023 and then Is_Intrinsic_Subprogram
(Entity
(N
))
6025 Resolve_Intrinsic_Operator
(N
, Typ
);
6028 -- Special-case for mixed-mode universal expressions or fixed point type
6029 -- operation: each argument is resolved separately. The same treatment
6030 -- is required if one of the operands of a fixed point operation is
6031 -- universal real, since in this case we don't do a conversion to a
6032 -- specific fixed-point type (instead the expander handles the case).
6034 -- Set the type of the node to its universal interpretation because
6035 -- legality checks on an exponentiation operand need the context.
6037 elsif Is_Universal_Numeric_Type
(B_Typ
)
6038 and then Present
(Universal_Interpretation
(L
))
6039 and then Present
(Universal_Interpretation
(R
))
6041 Set_Etype
(N
, B_Typ
);
6042 Resolve
(L
, Universal_Interpretation
(L
));
6043 Resolve
(R
, Universal_Interpretation
(R
));
6045 elsif (B_Typ
= Universal_Real
6046 or else Etype
(N
) = Universal_Fixed
6047 or else (Etype
(N
) = Any_Fixed
6048 and then Is_Fixed_Point_Type
(B_Typ
))
6049 or else (Is_Fixed_Point_Type
(B_Typ
)
6050 and then (Is_Integer_Or_Universal
(L
)
6052 Is_Integer_Or_Universal
(R
))))
6053 and then Nkind
(N
) in N_Op_Multiply | N_Op_Divide
6055 if TL
= Universal_Integer
or else TR
= Universal_Integer
then
6056 Check_For_Visible_Operator
(N
, B_Typ
);
6059 -- If context is a fixed type and one operand is integer, the other
6060 -- is resolved with the type of the context.
6062 if Is_Fixed_Point_Type
(B_Typ
)
6063 and then (Base_Type
(TL
) = Base_Type
(Standard_Integer
)
6064 or else TL
= Universal_Integer
)
6069 elsif Is_Fixed_Point_Type
(B_Typ
)
6070 and then (Base_Type
(TR
) = Base_Type
(Standard_Integer
)
6071 or else TR
= Universal_Integer
)
6076 -- If both operands are universal and the context is a floating
6077 -- point type, the operands are resolved to the type of the context.
6079 elsif Is_Floating_Point_Type
(B_Typ
) then
6084 Set_Mixed_Mode_Operand
(L
, TR
);
6085 Set_Mixed_Mode_Operand
(R
, TL
);
6088 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
6089 -- multiplying operators from being used when the expected type is
6090 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
6091 -- some cases where the expected type is actually Any_Real;
6092 -- Expected_Type_Is_Any_Real takes care of that case.
6094 if Etype
(N
) = Universal_Fixed
6095 or else Etype
(N
) = Any_Fixed
6097 if B_Typ
= Universal_Fixed
6098 and then not Expected_Type_Is_Any_Real
(N
)
6099 and then Nkind
(Parent
(N
)) not in
6100 N_Type_Conversion | N_Unchecked_Type_Conversion
6102 Error_Msg_N
("type cannot be determined from context!", N
);
6103 Error_Msg_N
("\explicit conversion to result type required", N
);
6105 Set_Etype
(L
, Any_Type
);
6106 Set_Etype
(R
, Any_Type
);
6109 if Ada_Version
= Ada_83
6110 and then Etype
(N
) = Universal_Fixed
6111 and then Nkind
(Parent
(N
)) not in
6112 N_Type_Conversion | N_Unchecked_Type_Conversion
6115 ("(Ada 83) fixed-point operation needs explicit "
6119 -- The expected type is "any real type" in contexts like
6121 -- type T is delta <universal_fixed-expression> ...
6123 -- in which case we need to set the type to Universal_Real
6124 -- so that static expression evaluation will work properly.
6126 if Expected_Type_Is_Any_Real
(N
) then
6127 Set_Etype
(N
, Universal_Real
);
6129 Set_Etype
(N
, B_Typ
);
6133 elsif Is_Fixed_Point_Type
(B_Typ
)
6134 and then (Is_Integer_Or_Universal
(L
)
6135 or else Nkind
(L
) = N_Real_Literal
6136 or else Nkind
(R
) = N_Real_Literal
6137 or else Is_Integer_Or_Universal
(R
))
6139 Set_Etype
(N
, B_Typ
);
6141 elsif Etype
(N
) = Any_Fixed
then
6143 -- If no previous errors, this is only possible if one operand is
6144 -- overloaded and the context is universal. Resolve as such.
6146 Set_Etype
(N
, B_Typ
);
6150 if Is_Universal_Numeric_Type
(TL
)
6152 Is_Universal_Numeric_Type
(TR
)
6154 Check_For_Visible_Operator
(N
, B_Typ
);
6157 -- If the context is Universal_Fixed and the operands are also
6158 -- universal fixed, this is an error, unless there is only one
6159 -- applicable fixed_point type (usually Duration).
6161 if B_Typ
= Universal_Fixed
and then Etype
(L
) = Universal_Fixed
then
6162 T
:= Unique_Fixed_Point_Type
(N
);
6164 if T
= Any_Type
then
6177 -- If one of the arguments was resolved to a non-universal type.
6178 -- label the result of the operation itself with the same type.
6179 -- Do the same for the universal argument, if any.
6181 T
:= Intersect_Types
(L
, R
);
6182 Set_Etype
(N
, Base_Type
(T
));
6183 Set_Operand_Type
(L
);
6184 Set_Operand_Type
(R
);
6187 Generate_Operator_Reference
(N
, Typ
);
6188 Analyze_Dimension
(N
);
6189 Eval_Arithmetic_Op
(N
);
6191 -- Set overflow and division checking bit
6193 if Nkind
(N
) in N_Op
then
6194 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
6195 Enable_Overflow_Check
(N
);
6198 -- Give warning if explicit division by zero
6200 if Nkind
(N
) in N_Op_Divide | N_Op_Rem | N_Op_Mod
6201 and then not Division_Checks_Suppressed
(Etype
(N
))
6203 Rop
:= Right_Opnd
(N
);
6205 if Compile_Time_Known_Value
(Rop
)
6206 and then ((Is_Integer_Type
(Etype
(Rop
))
6207 and then Expr_Value
(Rop
) = Uint_0
)
6209 (Is_Real_Type
(Etype
(Rop
))
6210 and then Expr_Value_R
(Rop
) = Ureal_0
))
6212 -- Specialize the warning message according to the operation.
6213 -- When SPARK_Mode is On, force a warning instead of an error
6214 -- in that case, as this likely corresponds to deactivated
6215 -- code. The following warnings are for the case
6220 -- For division, we have two cases, for float division
6221 -- of an unconstrained float type, on a machine where
6222 -- Machine_Overflows is false, we don't get an exception
6223 -- at run-time, but rather an infinity or Nan. The Nan
6224 -- case is pretty obscure, so just warn about infinities.
6226 if Is_Floating_Point_Type
(Typ
)
6227 and then not Is_Constrained
(Typ
)
6228 and then not Machine_Overflows_On_Target
6231 ("float division by zero, may generate "
6232 & "'+'/'- infinity??", Right_Opnd
(N
));
6234 -- For all other cases, we get a Constraint_Error
6237 Apply_Compile_Time_Constraint_Error
6238 (N
, "division by zero??", CE_Divide_By_Zero
,
6239 Loc
=> Sloc
(Right_Opnd
(N
)),
6240 Warn
=> SPARK_Mode
= On
);
6244 Apply_Compile_Time_Constraint_Error
6245 (N
, "rem with zero divisor??", CE_Divide_By_Zero
,
6246 Loc
=> Sloc
(Right_Opnd
(N
)),
6247 Warn
=> SPARK_Mode
= On
);
6250 Apply_Compile_Time_Constraint_Error
6251 (N
, "mod with zero divisor??", CE_Divide_By_Zero
,
6252 Loc
=> Sloc
(Right_Opnd
(N
)),
6253 Warn
=> SPARK_Mode
= On
);
6255 -- Division by zero can only happen with division, rem,
6256 -- and mod operations.
6259 raise Program_Error
;
6262 -- Otherwise just set the flag to check at run time
6265 Activate_Division_Check
(N
);
6269 -- If Restriction No_Implicit_Conditionals is active, then it is
6270 -- violated if either operand can be negative for mod, or for rem
6271 -- if both operands can be negative.
6273 if Restriction_Check_Required
(No_Implicit_Conditionals
)
6274 and then Nkind
(N
) in N_Op_Rem | N_Op_Mod
6283 -- Set if corresponding operand might be negative
6287 (Left_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
6288 LNeg
:= (not OK
) or else Lo
< 0;
6291 (Right_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
6292 RNeg
:= (not OK
) or else Lo
< 0;
6294 -- Check if we will be generating conditionals. There are two
6295 -- cases where that can happen, first for REM, the only case
6296 -- is largest negative integer mod -1, where the division can
6297 -- overflow, but we still have to give the right result. The
6298 -- front end generates a test for this annoying case. Here we
6299 -- just test if both operands can be negative (that's what the
6300 -- expander does, so we match its logic here).
6302 -- The second case is mod where either operand can be negative.
6303 -- In this case, the back end has to generate additional tests.
6305 if (Nkind
(N
) = N_Op_Rem
and then (LNeg
and RNeg
))
6307 (Nkind
(N
) = N_Op_Mod
and then (LNeg
or RNeg
))
6309 Check_Restriction
(No_Implicit_Conditionals
, N
);
6315 Check_Unset_Reference
(L
);
6316 Check_Unset_Reference
(R
);
6317 end Resolve_Arithmetic_Op
;
6323 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
6324 Loc
: constant Source_Ptr
:= Sloc
(N
);
6325 Subp
: constant Node_Id
:= Name
(N
);
6326 Body_Id
: Entity_Id
;
6337 -- Preserve relevant elaboration-related attributes of the context which
6338 -- are no longer available or very expensive to recompute once analysis,
6339 -- resolution, and expansion are over.
6341 Mark_Elaboration_Attributes
6347 -- The context imposes a unique interpretation with type Typ on a
6348 -- procedure or function call. Find the entity of the subprogram that
6349 -- yields the expected type, and propagate the corresponding formal
6350 -- constraints on the actuals. The caller has established that an
6351 -- interpretation exists, and emitted an error if not unique.
6353 -- First deal with the case of a call to an access-to-subprogram,
6354 -- dereference made explicit in Analyze_Call.
6356 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
6357 if not Is_Overloaded
(Subp
) then
6358 Nam
:= Etype
(Subp
);
6361 -- Find the interpretation whose type (a subprogram type) has a
6362 -- return type that is compatible with the context. Analysis of
6363 -- the node has established that one exists.
6367 Get_First_Interp
(Subp
, I
, It
);
6368 while Present
(It
.Typ
) loop
6369 if Covers
(Typ
, Etype
(It
.Typ
)) then
6374 Get_Next_Interp
(I
, It
);
6378 raise Program_Error
;
6382 -- If the prefix is not an entity, then resolve it
6384 if not Is_Entity_Name
(Subp
) then
6385 Resolve
(Subp
, Nam
);
6388 -- For an indirect call, we always invalidate checks, since we do not
6389 -- know whether the subprogram is local or global. Yes we could do
6390 -- better here, e.g. by knowing that there are no local subprograms,
6391 -- but it does not seem worth the effort. Similarly, we kill all
6392 -- knowledge of current constant values.
6394 Kill_Current_Values
;
6396 -- If this is a procedure call which is really an entry call, do
6397 -- the conversion of the procedure call to an entry call. Protected
6398 -- operations use the same circuitry because the name in the call
6399 -- can be an arbitrary expression with special resolution rules.
6401 elsif Nkind
(Subp
) in N_Selected_Component | N_Indexed_Component
6402 or else (Is_Entity_Name
(Subp
) and then Is_Entry
(Entity
(Subp
)))
6404 Resolve_Entry_Call
(N
, Typ
);
6406 if Legacy_Elaboration_Checks
then
6407 Check_Elab_Call
(N
);
6410 -- Annotate the tree by creating a call marker in case the original
6411 -- call is transformed by expansion. The call marker is automatically
6412 -- saved for later examination by the ABE Processing phase.
6414 Build_Call_Marker
(N
);
6416 -- Kill checks and constant values, as above for indirect case
6417 -- Who knows what happens when another task is activated?
6419 Kill_Current_Values
;
6422 -- Normal subprogram call with name established in Resolve
6424 elsif not Is_Type
(Entity
(Subp
)) then
6425 Nam
:= Entity
(Subp
);
6426 Set_Entity_With_Checks
(Subp
, Nam
);
6428 -- Otherwise we must have the case of an overloaded call
6431 pragma Assert
(Is_Overloaded
(Subp
));
6433 -- Initialize Nam to prevent warning (we know it will be assigned
6434 -- in the loop below, but the compiler does not know that).
6438 Get_First_Interp
(Subp
, I
, It
);
6439 while Present
(It
.Typ
) loop
6440 if Covers
(Typ
, It
.Typ
) then
6442 Set_Entity_With_Checks
(Subp
, Nam
);
6446 Get_Next_Interp
(I
, It
);
6450 -- Check that a call to Current_Task does not occur in an entry body
6452 if Is_RTE
(Nam
, RE_Current_Task
) then
6461 -- Exclude calls that occur within the default of a formal
6462 -- parameter of the entry, since those are evaluated outside
6465 exit when No
(P
) or else Nkind
(P
) = N_Parameter_Specification
;
6467 if Nkind
(P
) = N_Entry_Body
6468 or else (Nkind
(P
) = N_Subprogram_Body
6469 and then Is_Entry_Barrier_Function
(P
))
6472 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6474 ("& should not be used in entry body (RM C.7(17))<<",
6476 Error_Msg_NE
("\Program_Error [<<", N
, Nam
);
6478 Make_Raise_Program_Error
(Loc
,
6479 Reason
=> PE_Current_Task_In_Entry_Body
));
6480 Set_Etype
(N
, Rtype
);
6487 -- Check that a procedure call does not occur in the context of the
6488 -- entry call statement of a conditional or timed entry call. Note that
6489 -- the case of a call to a subprogram renaming of an entry will also be
6490 -- rejected. The test for N not being an N_Entry_Call_Statement is
6491 -- defensive, covering the possibility that the processing of entry
6492 -- calls might reach this point due to later modifications of the code
6495 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
6496 and then Nkind
(N
) /= N_Entry_Call_Statement
6497 and then Entry_Call_Statement
(Parent
(N
)) = N
6499 if Ada_Version
< Ada_2005
then
6500 Error_Msg_N
("entry call required in select statement", N
);
6502 -- Ada 2005 (AI-345): If a procedure_call_statement is used
6503 -- for a procedure_or_entry_call, the procedure_name or
6504 -- procedure_prefix of the procedure_call_statement shall denote
6505 -- an entry renamed by a procedure, or (a view of) a primitive
6506 -- subprogram of a limited interface whose first parameter is
6507 -- a controlling parameter.
6509 elsif Nkind
(N
) = N_Procedure_Call_Statement
6510 and then not Is_Renamed_Entry
(Nam
)
6511 and then not Is_Controlling_Limited_Procedure
(Nam
)
6514 ("entry call or dispatching primitive of interface required", N
);
6518 -- Check that this is not a call to a protected procedure or entry from
6519 -- within a protected function.
6521 Check_Internal_Protected_Use
(N
, Nam
);
6523 -- Freeze the subprogram name if not in a spec-expression. Note that
6524 -- we freeze procedure calls as well as function calls. Procedure calls
6525 -- are not frozen according to the rules (RM 13.14(14)) because it is
6526 -- impossible to have a procedure call to a non-frozen procedure in
6527 -- pure Ada, but in the code that we generate in the expander, this
6528 -- rule needs extending because we can generate procedure calls that
6531 -- In Ada 2012, expression functions may be called within pre/post
6532 -- conditions of subsequent functions or expression functions. Such
6533 -- calls do not freeze when they appear within generated bodies,
6534 -- (including the body of another expression function) which would
6535 -- place the freeze node in the wrong scope. An expression function
6536 -- is frozen in the usual fashion, by the appearance of a real body,
6537 -- or at the end of a declarative part. However an implicit call to
6538 -- an expression function may appear when it is part of a default
6539 -- expression in a call to an initialization procedure, and must be
6540 -- frozen now, even if the body is inserted at a later point.
6541 -- Otherwise, the call freezes the expression if expander is active,
6542 -- for example as part of an object declaration.
6544 if Is_Entity_Name
(Subp
)
6545 and then not In_Spec_Expression
6546 and then not Is_Expression_Function_Or_Completion
(Current_Scope
)
6548 (not Is_Expression_Function_Or_Completion
(Entity
(Subp
))
6549 or else Expander_Active
)
6551 if Is_Expression_Function
(Entity
(Subp
)) then
6553 -- Force freeze of expression function in call
6555 Set_Comes_From_Source
(Subp
, True);
6556 Set_Must_Not_Freeze
(Subp
, False);
6559 Freeze_Expression
(Subp
);
6562 -- For a predefined operator, the type of the result is the type imposed
6563 -- by context, except for a predefined operation on universal fixed.
6564 -- Otherwise the type of the call is the type returned by the subprogram
6567 if Is_Predefined_Op
(Nam
) then
6568 if Etype
(N
) /= Universal_Fixed
then
6572 -- If the subprogram returns an array type, and the context requires the
6573 -- component type of that array type, the node is really an indexing of
6574 -- the parameterless call. Resolve as such. A pathological case occurs
6575 -- when the type of the component is an access to the array type. In
6576 -- this case the call is truly ambiguous. If the call is to an intrinsic
6577 -- subprogram, it can't be an indexed component. This check is necessary
6578 -- because if it's Unchecked_Conversion, and we have "type T_Ptr is
6579 -- access T;" and "type T is array (...) of T_Ptr;" (i.e. an array of
6580 -- pointers to the same array), the compiler gets confused and does an
6581 -- infinite recursion.
6583 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
6585 ((Is_Array_Type
(Etype
(Nam
))
6586 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
6588 (Is_Access_Type
(Etype
(Nam
))
6589 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
6591 Covers
(Typ
, Component_Type
(Designated_Type
(Etype
(Nam
))))
6592 and then not Is_Intrinsic_Subprogram
(Entity
(Subp
))))
6595 Index_Node
: Node_Id
;
6597 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
6600 -- If this is a parameterless call there is no ambiguity and the
6601 -- call has the type of the function.
6603 if No
(First_Actual
(N
)) then
6604 Set_Etype
(N
, Etype
(Nam
));
6606 if Present
(First_Formal
(Nam
)) then
6607 Resolve_Actuals
(N
, Nam
);
6610 -- Annotate the tree by creating a call marker in case the
6611 -- original call is transformed by expansion. The call marker
6612 -- is automatically saved for later examination by the ABE
6613 -- Processing phase.
6615 Build_Call_Marker
(N
);
6617 elsif Is_Access_Type
(Ret_Type
)
6619 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
6622 ("cannot disambiguate function call and indexing", N
);
6624 New_Subp
:= Relocate_Node
(Subp
);
6626 -- The called entity may be an explicit dereference, in which
6627 -- case there is no entity to set.
6629 if Nkind
(New_Subp
) /= N_Explicit_Dereference
then
6630 Set_Entity
(Subp
, Nam
);
6633 if (Is_Array_Type
(Ret_Type
)
6634 and then Component_Type
(Ret_Type
) /= Any_Type
)
6636 (Is_Access_Type
(Ret_Type
)
6638 Component_Type
(Designated_Type
(Ret_Type
)) /= Any_Type
)
6640 if Needs_No_Actuals
(Nam
) then
6642 -- Indexed call to a parameterless function
6645 Make_Indexed_Component
(Loc
,
6647 Make_Function_Call
(Loc
, Name
=> New_Subp
),
6648 Expressions
=> Parameter_Associations
(N
));
6650 -- An Ada 2005 prefixed call to a primitive operation
6651 -- whose first parameter is the prefix. This prefix was
6652 -- prepended to the parameter list, which is actually a
6653 -- list of indexes. Remove the prefix in order to build
6654 -- the proper indexed component.
6657 Make_Indexed_Component
(Loc
,
6659 Make_Function_Call
(Loc
,
6661 Parameter_Associations
=>
6663 (Remove_Head
(Parameter_Associations
(N
)))),
6664 Expressions
=> Parameter_Associations
(N
));
6667 -- Preserve the parenthesis count of the node
6669 Set_Paren_Count
(Index_Node
, Paren_Count
(N
));
6671 -- Since we are correcting a node classification error made
6672 -- by the parser, we call Replace rather than Rewrite.
6674 Replace
(N
, Index_Node
);
6676 Set_Etype
(Prefix
(N
), Ret_Type
);
6679 if Legacy_Elaboration_Checks
then
6680 Check_Elab_Call
(Prefix
(N
));
6683 -- Annotate the tree by creating a call marker in case
6684 -- the original call is transformed by expansion. The call
6685 -- marker is automatically saved for later examination by
6686 -- the ABE Processing phase.
6688 Build_Call_Marker
(Prefix
(N
));
6690 Resolve_Indexed_Component
(N
, Typ
);
6698 -- If the called function is not declared in the main unit and it
6699 -- returns the limited view of type then use the available view (as
6700 -- is done in Try_Object_Operation) to prevent back-end confusion;
6701 -- for the function entity itself. The call must appear in a context
6702 -- where the nonlimited view is available. If the function entity is
6703 -- in the extended main unit then no action is needed, because the
6704 -- back end handles this case. In either case the type of the call
6705 -- is the nonlimited view.
6707 if From_Limited_With
(Etype
(Nam
))
6708 and then Present
(Available_View
(Etype
(Nam
)))
6710 Set_Etype
(N
, Available_View
(Etype
(Nam
)));
6712 if not In_Extended_Main_Code_Unit
(Nam
) then
6713 Set_Etype
(Nam
, Available_View
(Etype
(Nam
)));
6717 Set_Etype
(N
, Etype
(Nam
));
6721 -- In the case where the call is to an overloaded subprogram, Analyze
6722 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
6723 -- such a case Normalize_Actuals needs to be called once more to order
6724 -- the actuals correctly. Otherwise the call will have the ordering
6725 -- given by the last overloaded subprogram whether this is the correct
6726 -- one being called or not.
6728 if Is_Overloaded
(Subp
) then
6729 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
6730 pragma Assert
(Norm_OK
);
6733 -- In any case, call is fully resolved now. Reset Overload flag, to
6734 -- prevent subsequent overload resolution if node is analyzed again
6736 Set_Is_Overloaded
(Subp
, False);
6737 Set_Is_Overloaded
(N
, False);
6739 -- A Ghost entity must appear in a specific context
6741 if Is_Ghost_Entity
(Nam
) and then Comes_From_Source
(N
) then
6742 Check_Ghost_Context
(Nam
, N
);
6745 -- If we are calling the current subprogram from immediately within its
6746 -- body, then that is the case where we can sometimes detect cases of
6747 -- infinite recursion statically. Do not try this in case restriction
6748 -- No_Recursion is in effect anyway, and do it only for source calls.
6750 if Comes_From_Source
(N
) then
6751 Scop
:= Current_Scope
;
6753 -- Issue warning for possible infinite recursion in the absence
6754 -- of the No_Recursion restriction.
6756 if Same_Or_Aliased_Subprograms
(Nam
, Scop
)
6757 and then not Restriction_Active
(No_Recursion
)
6758 and then not Is_Static_Function
(Scop
)
6759 and then Check_Infinite_Recursion
(N
)
6761 -- Here we detected and flagged an infinite recursion, so we do
6762 -- not need to test the case below for further warnings. Also we
6763 -- are all done if we now have a raise SE node.
6765 if Nkind
(N
) = N_Raise_Storage_Error
then
6769 -- If call is to immediately containing subprogram, then check for
6770 -- the case of a possible run-time detectable infinite recursion.
6773 Scope_Loop
: while Scop
/= Standard_Standard
loop
6774 if Same_Or_Aliased_Subprograms
(Nam
, Scop
) then
6776 -- Ada 2022 (AI12-0075): Static functions are never allowed
6777 -- to make a recursive call, as specified by 6.8(5.4/5).
6779 if Is_Static_Function
(Scop
) then
6781 ("recursive call not allowed in static expression "
6784 Set_Error_Posted
(Scop
);
6789 -- Although in general case, recursion is not statically
6790 -- checkable, the case of calling an immediately containing
6791 -- subprogram is easy to catch.
6793 if not Is_Ignored_Ghost_Entity
(Nam
) then
6794 Check_Restriction
(No_Recursion
, N
);
6797 -- If the recursive call is to a parameterless subprogram,
6798 -- then even if we can't statically detect infinite
6799 -- recursion, this is pretty suspicious, and we output a
6800 -- warning. Furthermore, we will try later to detect some
6801 -- cases here at run time by expanding checking code (see
6802 -- Detect_Infinite_Recursion in package Exp_Ch6).
6804 -- If the recursive call is within a handler, do not emit a
6805 -- warning, because this is a common idiom: loop until input
6806 -- is correct, catch illegal input in handler and restart.
6808 if No
(First_Formal
(Nam
))
6809 and then Etype
(Nam
) = Standard_Void_Type
6810 and then not Error_Posted
(N
)
6811 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
6813 -- For the case of a procedure call. We give the message
6814 -- only if the call is the first statement in a sequence
6815 -- of statements, or if all previous statements are
6816 -- simple assignments. This is simply a heuristic to
6817 -- decrease false positives, without losing too many good
6818 -- warnings. The idea is that these previous statements
6819 -- may affect global variables the procedure depends on.
6820 -- We also exclude raise statements, that may arise from
6821 -- constraint checks and are probably unrelated to the
6822 -- intended control flow.
6824 if Nkind
(N
) = N_Procedure_Call_Statement
6825 and then Is_List_Member
(N
)
6831 while Present
(P
) loop
6832 if Nkind
(P
) not in N_Assignment_Statement
6833 | N_Raise_Constraint_Error
6843 -- Do not give warning if we are in a conditional context
6846 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
6848 if (K
= N_Loop_Statement
6849 and then Present
(Iteration_Scheme
(Parent
(N
))))
6850 or else K
= N_If_Statement
6851 or else K
= N_Elsif_Part
6852 or else K
= N_Case_Statement_Alternative
6858 -- Here warning is to be issued
6860 Set_Has_Recursive_Call
(Nam
);
6861 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6862 Error_Msg_N
("possible infinite recursion<<!", N
);
6863 Error_Msg_N
("\Storage_Error ]<<!", N
);
6869 Scop
:= Scope
(Scop
);
6870 end loop Scope_Loop
;
6874 -- Check obsolescent reference to Ada.Characters.Handling subprogram
6876 Check_Obsolescent_2005_Entity
(Nam
, Subp
);
6878 -- If subprogram name is a predefined operator, it was given in
6879 -- functional notation. Replace call node with operator node, so
6880 -- that actuals can be resolved appropriately.
6882 if Ekind
(Nam
) = E_Operator
or else Is_Predefined_Op
(Nam
) then
6883 Make_Call_Into_Operator
(N
, Typ
, Nam
);
6886 elsif Present
(Alias
(Nam
)) and then Is_Predefined_Op
(Alias
(Nam
)) then
6887 Resolve_Actuals
(N
, Nam
);
6888 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
6892 -- Create a transient scope if the resulting type requires it
6894 -- There are several notable exceptions:
6896 -- a) In init procs, the transient scope overhead is not needed, and is
6897 -- even incorrect when the call is a nested initialization call for a
6898 -- component whose expansion may generate adjust calls. However, if the
6899 -- call is some other procedure call within an initialization procedure
6900 -- (for example a call to Create_Task in the init_proc of the task
6901 -- run-time record) a transient scope must be created around this call.
6903 -- b) Enumeration literal pseudo-calls need no transient scope
6905 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
6906 -- functions) do not use the secondary stack even though the return
6907 -- type may be unconstrained.
6909 -- d) Calls to a build-in-place function, since such functions may
6910 -- allocate their result directly in a target object, and cases where
6911 -- the result does get allocated in the secondary stack are checked for
6912 -- within the specialized Exp_Ch6 procedures for expanding those
6913 -- build-in-place calls.
6915 -- e) Calls to inlinable expression functions do not use the secondary
6916 -- stack (since the call will be replaced by its returned object).
6918 -- f) If the subprogram is marked Inline_Always, then even if it returns
6919 -- an unconstrained type the call does not require use of the secondary
6920 -- stack. However, inlining will only take place if the body to inline
6921 -- is already present. It may not be available if e.g. the subprogram is
6922 -- declared in a child instance.
6924 -- g) If the subprogram is a static expression function and the call is
6925 -- a static call (the actuals are all static expressions), then we never
6926 -- want to create a transient scope (this could occur in the case of a
6927 -- static string-returning call).
6930 and then Has_Pragma_Inline
(Nam
)
6931 and then Nkind
(Unit_Declaration_Node
(Nam
)) = N_Subprogram_Declaration
6932 and then Present
(Body_To_Inline
(Unit_Declaration_Node
(Nam
)))
6936 elsif Ekind
(Nam
) = E_Enumeration_Literal
6937 or else Is_Build_In_Place_Function
(Nam
)
6938 or else Is_Intrinsic_Subprogram
(Nam
)
6939 or else Is_Inlinable_Expression_Function
(Nam
)
6940 or else Is_Static_Function_Call
(N
)
6944 -- A return statement from an ignored Ghost function does not use the
6945 -- secondary stack (or any other one).
6947 elsif Expander_Active
6948 and then Ekind
(Nam
) in E_Function | E_Subprogram_Type
6949 and then Requires_Transient_Scope
(Etype
(Nam
))
6950 and then not Is_Ignored_Ghost_Entity
(Nam
)
6952 Establish_Transient_Scope
(N
, Manage_Sec_Stack
=> True);
6954 -- If the call appears within the bounds of a loop, it will be
6955 -- rewritten and reanalyzed, nothing left to do here.
6957 if Nkind
(N
) /= N_Function_Call
then
6962 -- A protected function cannot be called within the definition of the
6963 -- enclosing protected type, unless it is part of a pre/postcondition
6964 -- on another protected operation. This may appear in the entry wrapper
6965 -- created for an entry with preconditions.
6967 if Is_Protected_Type
(Scope
(Nam
))
6968 and then In_Open_Scopes
(Scope
(Nam
))
6969 and then not Has_Completion
(Scope
(Nam
))
6970 and then not In_Spec_Expression
6971 and then not Is_Entry_Wrapper
(Current_Scope
)
6974 ("& cannot be called before end of protected definition", N
, Nam
);
6977 -- Propagate interpretation to actuals, and add default expressions
6980 if Present
(First_Formal
(Nam
)) then
6981 Resolve_Actuals
(N
, Nam
);
6983 -- Overloaded literals are rewritten as function calls, for purpose of
6984 -- resolution. After resolution, we can replace the call with the
6987 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
6988 Copy_Node
(Subp
, N
);
6989 Resolve_Entity_Name
(N
, Typ
);
6991 -- Avoid validation, since it is a static function call
6993 Generate_Reference
(Nam
, Subp
);
6997 -- If the subprogram is not global, then kill all saved values and
6998 -- checks. This is a bit conservative, since in many cases we could do
6999 -- better, but it is not worth the effort. Similarly, we kill constant
7000 -- values. However we do not need to do this for internal entities
7001 -- (unless they are inherited user-defined subprograms), since they
7002 -- are not in the business of molesting local values.
7004 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
7005 -- kill all checks and values for calls to global subprograms. This
7006 -- takes care of the case where an access to a local subprogram is
7007 -- taken, and could be passed directly or indirectly and then called
7008 -- from almost any context.
7010 -- Note: we do not do this step till after resolving the actuals. That
7011 -- way we still take advantage of the current value information while
7012 -- scanning the actuals.
7014 -- We suppress killing values if we are processing the nodes associated
7015 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
7016 -- type kills all the values as part of analyzing the code that
7017 -- initializes the dispatch tables.
7019 if Inside_Freezing_Actions
= 0
7020 and then (not Is_Library_Level_Entity
(Nam
)
7021 or else Suppress_Value_Tracking_On_Call
7022 (Nearest_Dynamic_Scope
(Current_Scope
)))
7023 and then (Comes_From_Source
(Nam
)
7024 or else (Present
(Alias
(Nam
))
7025 and then Comes_From_Source
(Alias
(Nam
))))
7027 Kill_Current_Values
;
7030 -- If we are warning about unread OUT parameters, this is the place to
7031 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
7032 -- after the above call to Kill_Current_Values (since that call clears
7033 -- the Last_Assignment field of all local variables).
7035 if (Warn_On_Modified_Unread
or Warn_On_All_Unread_Out_Parameters
)
7036 and then Comes_From_Source
(N
)
7037 and then In_Extended_Main_Source_Unit
(N
)
7044 F
:= First_Formal
(Nam
);
7045 A
:= First_Actual
(N
);
7046 while Present
(F
) and then Present
(A
) loop
7047 if Ekind
(F
) in E_Out_Parameter | E_In_Out_Parameter
7048 and then Warn_On_Modified_As_Out_Parameter
(F
)
7049 and then Is_Entity_Name
(A
)
7050 and then Present
(Entity
(A
))
7051 and then Comes_From_Source
(N
)
7052 and then Safe_To_Capture_Value
(N
, Entity
(A
))
7054 Set_Last_Assignment
(Entity
(A
), A
);
7063 -- If the subprogram is a primitive operation, check whether or not
7064 -- it is a correct dispatching call.
7066 if Is_Overloadable
(Nam
)
7067 and then Is_Dispatching_Operation
(Nam
)
7069 Check_Dispatching_Call
(N
);
7071 elsif Ekind
(Nam
) /= E_Subprogram_Type
7072 and then Is_Abstract_Subprogram
(Nam
)
7073 and then not In_Instance
7075 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Nam
);
7078 -- If this is a dispatching call, generate the appropriate reference,
7079 -- for better source navigation in GNAT Studio.
7081 if Is_Overloadable
(Nam
)
7082 and then Present
(Controlling_Argument
(N
))
7084 Generate_Reference
(Nam
, Subp
, 'R');
7086 -- Normal case, not a dispatching call: generate a call reference
7089 Generate_Reference
(Nam
, Subp
, 's');
7092 if Is_Intrinsic_Subprogram
(Nam
) then
7093 Check_Intrinsic_Call
(N
);
7096 -- Check for violation of restriction No_Specific_Termination_Handlers
7097 -- and warn on a potentially blocking call to Abort_Task.
7099 if Restriction_Check_Required
(No_Specific_Termination_Handlers
)
7100 and then (Is_RTE
(Nam
, RE_Set_Specific_Handler
)
7102 Is_RTE
(Nam
, RE_Specific_Handler
))
7104 Check_Restriction
(No_Specific_Termination_Handlers
, N
);
7106 elsif Is_RTE
(Nam
, RE_Abort_Task
) then
7107 Check_Potentially_Blocking_Operation
(N
);
7110 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
7111 -- timing event violates restriction No_Relative_Delay (AI-0211). We
7112 -- need to check the second argument to determine whether it is an
7113 -- absolute or relative timing event.
7115 if Restriction_Check_Required
(No_Relative_Delay
)
7116 and then Is_RTE
(Nam
, RE_Set_Handler
)
7117 and then Is_RTE
(Etype
(Next_Actual
(First_Actual
(N
))), RE_Time_Span
)
7119 Check_Restriction
(No_Relative_Delay
, N
);
7122 -- Issue an error for a call to an eliminated subprogram. This routine
7123 -- will not perform the check if the call appears within a default
7126 Check_For_Eliminated_Subprogram
(Subp
, Nam
);
7128 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
7129 -- class-wide and the call dispatches on result in a context that does
7130 -- not provide a tag, the call raises Program_Error.
7132 if Nkind
(N
) = N_Function_Call
7133 and then In_Instance
7134 and then Is_Generic_Actual_Type
(Typ
)
7135 and then Is_Class_Wide_Type
(Typ
)
7136 and then Has_Controlling_Result
(Nam
)
7137 and then Nkind
(Parent
(N
)) = N_Object_Declaration
7139 -- Verify that none of the formals are controlling
7142 Call_OK
: Boolean := False;
7146 F
:= First_Formal
(Nam
);
7147 while Present
(F
) loop
7148 if Is_Controlling_Formal
(F
) then
7157 Error_Msg_Warn
:= SPARK_Mode
/= On
;
7158 Error_Msg_N
("!cannot determine tag of result<<", N
);
7159 Error_Msg_N
("\Program_Error [<<!", N
);
7161 Make_Raise_Program_Error
(Sloc
(N
),
7162 Reason
=> PE_Explicit_Raise
));
7167 -- Check for calling a function with OUT or IN OUT parameter when the
7168 -- calling context (us right now) is not Ada 2012, so does not allow
7169 -- OUT or IN OUT parameters in function calls. Functions declared in
7170 -- a predefined unit are OK, as they may be called indirectly from a
7171 -- user-declared instantiation.
7173 if Ada_Version
< Ada_2012
7174 and then Ekind
(Nam
) = E_Function
7175 and then Has_Out_Or_In_Out_Parameter
(Nam
)
7176 and then not In_Predefined_Unit
(Nam
)
7178 Error_Msg_NE
("& has at least one OUT or `IN OUT` parameter", N
, Nam
);
7179 Error_Msg_N
("\call to this function only allowed in Ada 2012", N
);
7182 -- Check the dimensions of the actuals in the call. For function calls,
7183 -- propagate the dimensions from the returned type to N.
7185 Analyze_Dimension_Call
(N
, Nam
);
7187 -- All done, evaluate call and deal with elaboration issues
7191 if Legacy_Elaboration_Checks
then
7192 Check_Elab_Call
(N
);
7195 -- Annotate the tree by creating a call marker in case the original call
7196 -- is transformed by expansion. The call marker is automatically saved
7197 -- for later examination by the ABE Processing phase.
7199 Build_Call_Marker
(N
);
7201 Mark_Use_Clauses
(Subp
);
7203 Warn_On_Overlapping_Actuals
(Nam
, N
);
7205 -- Ada 2022 (AI12-0075): If the call is a static call to a static
7206 -- expression function, then we want to "inline" the call, replacing
7207 -- it with the folded static result. This is not done if the checking
7208 -- for a potentially static expression is enabled or if an error has
7209 -- been posted on the call (which may be due to the check for recursive
7210 -- calls, in which case we don't want to fall into infinite recursion
7211 -- when doing the inlining).
7213 if not Checking_Potentially_Static_Expression
7214 and then Is_Static_Function_Call
(N
)
7215 and then not Is_Intrinsic_Subprogram
(Ultimate_Alias
(Nam
))
7216 and then not Error_Posted
(Ultimate_Alias
(Nam
))
7218 Inline_Static_Function_Call
(N
, Ultimate_Alias
(Nam
));
7220 -- In GNATprove mode, expansion is disabled, but we want to inline some
7221 -- subprograms to facilitate formal verification. Indirect calls through
7222 -- a subprogram type or within a generic cannot be inlined. Inlining is
7223 -- performed only for calls subject to SPARK_Mode on.
7225 elsif GNATprove_Mode
7226 and then SPARK_Mode
= On
7227 and then Is_Overloadable
(Nam
)
7228 and then not Inside_A_Generic
7230 Nam_UA
:= Ultimate_Alias
(Nam
);
7231 Nam_Decl
:= Unit_Declaration_Node
(Nam_UA
);
7233 if Nkind
(Nam_Decl
) = N_Subprogram_Declaration
then
7234 Body_Id
:= Corresponding_Body
(Nam_Decl
);
7236 -- Nothing to do if the subprogram is not eligible for inlining in
7237 -- GNATprove mode, or inlining is disabled with switch -gnatdm
7239 if not Is_Inlined_Always
(Nam_UA
)
7240 or else not Can_Be_Inlined_In_GNATprove_Mode
(Nam_UA
, Body_Id
)
7241 or else Debug_Flag_M
7245 -- Calls cannot be inlined inside assertions, as GNATprove treats
7246 -- assertions as logic expressions. Only issue a message when the
7247 -- body has been seen, otherwise this leads to spurious messages
7248 -- on expression functions.
7250 elsif In_Assertion_Expr
/= 0 then
7252 ("cannot inline & (in assertion expression)?", N
, Nam_UA
,
7253 Suppress_Info
=> No
(Body_Id
));
7255 -- Calls cannot be inlined inside default expressions
7257 elsif In_Default_Expr
then
7259 ("cannot inline & (in default expression)?", N
, Nam_UA
);
7261 -- Calls cannot be inlined inside quantified expressions, which
7262 -- are left in expression form for GNATprove. Since these
7263 -- expressions are only preanalyzed, we need to detect the failure
7264 -- to inline outside of the case for Full_Analysis below.
7266 elsif In_Quantified_Expression
(N
) then
7268 ("cannot inline & (in quantified expression)?", N
, Nam_UA
);
7270 -- Inlining should not be performed during preanalysis
7272 elsif Full_Analysis
then
7274 -- Do not inline calls inside expression functions or functions
7275 -- generated by the front end for subtype predicates, as this
7276 -- would prevent interpreting them as logical formulas in
7277 -- GNATprove. Only issue a message when the body has been seen,
7278 -- otherwise this leads to spurious messages on callees that
7279 -- are themselves expression functions.
7281 if Present
(Current_Subprogram
)
7283 (Is_Expression_Function_Or_Completion
(Current_Subprogram
)
7284 or else Is_Predicate_Function
(Current_Subprogram
)
7285 or else Is_Invariant_Procedure
(Current_Subprogram
)
7286 or else Is_DIC_Procedure
(Current_Subprogram
))
7288 if Present
(Body_Id
)
7289 and then Present
(Body_To_Inline
(Nam_Decl
))
7291 if Is_Predicate_Function
(Current_Subprogram
) then
7293 ("cannot inline & (inside predicate)?",
7296 elsif Is_Invariant_Procedure
(Current_Subprogram
) then
7298 ("cannot inline & (inside invariant)?",
7301 elsif Is_DIC_Procedure
(Current_Subprogram
) then
7303 ("cannot inline & (inside Default_Initial_Condition)?",
7308 ("cannot inline & (inside expression function)?",
7313 -- Cannot inline a call inside the definition of a record type,
7314 -- typically inside the constraints of the type. Calls in
7315 -- default expressions are also not inlined, but this is
7316 -- filtered out above when testing In_Default_Expr.
7318 elsif Is_Record_Type
(Current_Scope
) then
7320 ("cannot inline & (inside record type)?", N
, Nam_UA
);
7322 -- With the one-pass inlining technique, a call cannot be
7323 -- inlined if the corresponding body has not been seen yet.
7325 elsif No
(Body_Id
) then
7327 ("cannot inline & (body not seen yet)?", N
, Nam_UA
);
7329 -- Nothing to do if there is no body to inline, indicating that
7330 -- the subprogram is not suitable for inlining in GNATprove
7333 elsif No
(Body_To_Inline
(Nam_Decl
)) then
7336 -- Calls cannot be inlined inside potentially unevaluated
7337 -- expressions, as this would create complex actions inside
7338 -- expressions, that are not handled by GNATprove.
7340 elsif Is_Potentially_Unevaluated
(N
) then
7342 ("cannot inline & (in potentially unevaluated context)?",
7345 -- Calls cannot be inlined inside the conditions of while
7346 -- loops, as this would create complex actions inside
7347 -- the condition, that are not handled by GNATprove.
7349 elsif In_Statement_Condition_With_Actions
(N
) then
7351 ("cannot inline & (in while loop condition)?", N
, Nam_UA
);
7353 -- Do not inline calls which would possibly lead to missing a
7354 -- type conversion check on an input parameter.
7356 elsif not Call_Can_Be_Inlined_In_GNATprove_Mode
(N
, Nam
) then
7358 ("cannot inline & (possible check on input parameters)?",
7361 -- Otherwise, inline the call, issuing an info message when
7365 if Debug_Flag_Underscore_F
then
7367 ("info: analyzing call to & in context?", N
, Nam_UA
);
7370 Expand_Inlined_Call
(N
, Nam_UA
, Nam
);
7377 -----------------------------
7378 -- Resolve_Case_Expression --
7379 -----------------------------
7381 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7384 Alt_Typ
: Entity_Id
;
7388 Alt
:= First
(Alternatives
(N
));
7389 while Present
(Alt
) loop
7390 Alt_Expr
:= Expression
(Alt
);
7392 if Error_Posted
(Alt_Expr
) then
7396 Resolve
(Alt_Expr
, Typ
);
7397 Check_Unset_Reference
(Alt_Expr
);
7398 Alt_Typ
:= Etype
(Alt_Expr
);
7400 -- When the expression is of a scalar subtype different from the
7401 -- result subtype, then insert a conversion to ensure the generation
7402 -- of a constraint check.
7404 if Is_Scalar_Type
(Alt_Typ
) and then Alt_Typ
/= Typ
then
7405 Rewrite
(Alt_Expr
, Convert_To
(Typ
, Alt_Expr
));
7406 Analyze_And_Resolve
(Alt_Expr
, Typ
);
7412 -- Apply RM 4.5.7 (17/3): whether the expression is statically or
7413 -- dynamically tagged must be known statically.
7415 if Is_Tagged_Type
(Typ
) and then not Is_Class_Wide_Type
(Typ
) then
7416 Alt
:= First
(Alternatives
(N
));
7417 Is_Dyn
:= Is_Dynamically_Tagged
(Expression
(Alt
));
7419 while Present
(Alt
) loop
7420 if Is_Dynamically_Tagged
(Expression
(Alt
)) /= Is_Dyn
then
7422 ("all or none of the dependent expressions can be "
7423 & "dynamically tagged", N
);
7431 Eval_Case_Expression
(N
);
7432 Analyze_Dimension
(N
);
7433 end Resolve_Case_Expression
;
7435 -------------------------------
7436 -- Resolve_Character_Literal --
7437 -------------------------------
7439 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
7440 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7444 -- Verify that the character does belong to the type of the context
7446 Set_Etype
(N
, B_Typ
);
7447 Eval_Character_Literal
(N
);
7449 -- Wide_Wide_Character literals must always be defined, since the set
7450 -- of wide wide character literals is complete, i.e. if a character
7451 -- literal is accepted by the parser, then it is OK for wide wide
7452 -- character (out of range character literals are rejected).
7454 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
7457 -- Always accept character literal for type Any_Character, which
7458 -- occurs in error situations and in comparisons of literals, both
7459 -- of which should accept all literals.
7461 elsif B_Typ
= Any_Character
then
7464 -- For Standard.Character or a type derived from it, check that the
7465 -- literal is in range.
7467 elsif Root_Type
(B_Typ
) = Standard_Character
then
7468 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
7472 -- For Standard.Wide_Character or a type derived from it, check that the
7473 -- literal is in range.
7475 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
7476 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
7480 -- If the entity is already set, this has already been resolved in a
7481 -- generic context, or comes from expansion. Nothing else to do.
7483 elsif Present
(Entity
(N
)) then
7486 -- Otherwise we have a user defined character type, and we can use the
7487 -- standard visibility mechanisms to locate the referenced entity.
7490 C
:= Current_Entity
(N
);
7491 while Present
(C
) loop
7492 if Etype
(C
) = B_Typ
then
7493 Set_Entity_With_Checks
(N
, C
);
7494 Generate_Reference
(C
, N
);
7502 -- If we fall through, then the literal does not match any of the
7503 -- entries of the enumeration type. This isn't just a constraint error
7504 -- situation, it is an illegality (see RM 4.2).
7507 ("character not defined for }", N
, First_Subtype
(B_Typ
));
7508 end Resolve_Character_Literal
;
7510 ---------------------------
7511 -- Resolve_Comparison_Op --
7512 ---------------------------
7514 -- The operands must have compatible types and the boolean context does not
7515 -- participate in the resolution. The first pass verifies that the operands
7516 -- are not ambiguous and sets their type correctly, or to Any_Type in case
7517 -- of ambiguity. If both operands are strings or aggregates, then they are
7518 -- ambiguous even if they carry a single (universal) type.
7520 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7521 L
: constant Node_Id
:= Left_Opnd
(N
);
7522 R
: constant Node_Id
:= Right_Opnd
(N
);
7524 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
7527 if T
= Any_Fixed
then
7528 T
:= Unique_Fixed_Point_Type
(L
);
7531 Set_Etype
(N
, Base_Type
(Typ
));
7532 Generate_Reference
(T
, N
, ' ');
7534 if T
= Any_Type
then
7535 -- Deal with explicit ambiguity of operands
7537 if Ekind
(Entity
(N
)) = E_Operator
7538 and then (Is_Overloaded
(L
) or else Is_Overloaded
(R
))
7540 Ambiguous_Operands
(N
);
7546 -- Deal with other error cases
7548 if T
= Any_String
or else
7549 T
= Any_Composite
or else
7552 if T
= Any_Character
then
7553 Ambiguous_Character
(L
);
7555 Error_Msg_N
("ambiguous operands for comparison", N
);
7558 Set_Etype
(N
, Any_Type
);
7562 -- Resolve the operands if types OK
7566 Check_Unset_Reference
(L
);
7567 Check_Unset_Reference
(R
);
7568 Generate_Operator_Reference
(N
, T
);
7569 Check_Low_Bound_Tested
(N
);
7571 -- Check comparison on unordered enumeration
7573 if Bad_Unordered_Enumeration_Reference
(N
, Etype
(L
)) then
7574 Error_Msg_Sloc
:= Sloc
(Etype
(L
));
7576 ("comparison on unordered enumeration type& declared#?.u?",
7580 Analyze_Dimension
(N
);
7582 Eval_Relational_Op
(N
);
7583 end Resolve_Comparison_Op
;
7585 --------------------------------
7586 -- Resolve_Declare_Expression --
7587 --------------------------------
7589 procedure Resolve_Declare_Expression
7593 Expr
: constant Node_Id
:= Expression
(N
);
7596 Local
: Entity_Id
:= Empty
;
7598 function Replace_Local
(N
: Node_Id
) return Traverse_Result
;
7599 -- Use a tree traversal to replace each occurrence of the name of
7600 -- a local object declared in the construct, with the corresponding
7601 -- entity. This replaces the usual way to perform name capture by
7602 -- visibility, because it is not possible to place on the scope
7603 -- stack the fake scope created for the analysis of the local
7604 -- declarations; such a scope conflicts with the transient scopes
7605 -- that may be generated if the expression includes function calls
7606 -- requiring finalization.
7612 function Replace_Local
(N
: Node_Id
) return Traverse_Result
is
7614 -- The identifier may be the prefix of a selected component,
7615 -- but not a selector name, because the local entities do not
7616 -- have a scope that can be named: a selected component whose
7617 -- selector is a homonym of a local entity must denote some
7620 if Nkind
(N
) = N_Identifier
7621 and then Chars
(N
) = Chars
(Local
)
7622 and then No
(Entity
(N
))
7624 (Nkind
(Parent
(N
)) /= N_Selected_Component
7625 or else N
= Prefix
(Parent
(N
)))
7627 Set_Entity
(N
, Local
);
7628 Set_Etype
(N
, Etype
(Local
));
7634 procedure Replace_Local_Ref
is new Traverse_Proc
(Replace_Local
);
7636 -- Start of processing for Resolve_Declare_Expression
7640 Decl
:= First
(Actions
(N
));
7642 while Present
(Decl
) loop
7644 N_Object_Declaration | N_Object_Renaming_Declaration
7645 and then Comes_From_Source
(Defining_Identifier
(Decl
))
7647 Local
:= Defining_Identifier
(Decl
);
7648 Replace_Local_Ref
(Expr
);
7650 -- Traverse the expression to replace references to local
7651 -- variables that occur within declarations of the
7652 -- declare_expression.
7655 D
: Node_Id
:= Next
(Decl
);
7657 while Present
(D
) loop
7658 Replace_Local_Ref
(D
);
7667 -- The end of the declarative list is a freeze point for the
7668 -- local declarations.
7670 if Present
(Local
) then
7671 Decl
:= Parent
(Local
);
7672 Freeze_All
(First_Entity
(Scope
(Local
)), Decl
);
7675 Resolve
(Expr
, Typ
);
7676 end Resolve_Declare_Expression
;
7678 -----------------------------------------
7679 -- Resolve_Discrete_Subtype_Indication --
7680 -----------------------------------------
7682 procedure Resolve_Discrete_Subtype_Indication
7690 Analyze
(Subtype_Mark
(N
));
7691 S
:= Entity
(Subtype_Mark
(N
));
7693 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
7694 Error_Msg_N
("expect range constraint for discrete type", N
);
7695 Set_Etype
(N
, Any_Type
);
7698 R
:= Range_Expression
(Constraint
(N
));
7706 if Base_Type
(S
) /= Base_Type
(Typ
) then
7708 ("expect subtype of }", N
, First_Subtype
(Typ
));
7710 -- Rewrite the constraint as a range of Typ
7711 -- to allow compilation to proceed further.
7714 Rewrite
(Low_Bound
(R
),
7715 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
7716 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
7717 Attribute_Name
=> Name_First
));
7718 Rewrite
(High_Bound
(R
),
7719 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
7720 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
7721 Attribute_Name
=> Name_First
));
7725 Set_Etype
(N
, Etype
(R
));
7727 -- Additionally, we must check that the bounds are compatible
7728 -- with the given subtype, which might be different from the
7729 -- type of the context.
7731 Apply_Range_Check
(R
, S
);
7733 -- ??? If the above check statically detects a Constraint_Error
7734 -- it replaces the offending bound(s) of the range R with a
7735 -- Constraint_Error node. When the itype which uses these bounds
7736 -- is frozen the resulting call to Duplicate_Subexpr generates
7737 -- a new temporary for the bounds.
7739 -- Unfortunately there are other itypes that are also made depend
7740 -- on these bounds, so when Duplicate_Subexpr is called they get
7741 -- a forward reference to the newly created temporaries and Gigi
7742 -- aborts on such forward references. This is probably sign of a
7743 -- more fundamental problem somewhere else in either the order of
7744 -- itype freezing or the way certain itypes are constructed.
7746 -- To get around this problem we call Remove_Side_Effects right
7747 -- away if either bounds of R are a Constraint_Error.
7750 L
: constant Node_Id
:= Low_Bound
(R
);
7751 H
: constant Node_Id
:= High_Bound
(R
);
7754 if Nkind
(L
) = N_Raise_Constraint_Error
then
7755 Remove_Side_Effects
(L
);
7758 if Nkind
(H
) = N_Raise_Constraint_Error
then
7759 Remove_Side_Effects
(H
);
7763 Check_Unset_Reference
(Low_Bound
(R
));
7764 Check_Unset_Reference
(High_Bound
(R
));
7767 end Resolve_Discrete_Subtype_Indication
;
7769 -------------------------
7770 -- Resolve_Entity_Name --
7771 -------------------------
7773 -- Used to resolve identifiers and expanded names
7775 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
7776 function Is_Assignment_Or_Object_Expression
7778 Expr
: Node_Id
) return Boolean;
7779 -- Determine whether node Context denotes an assignment statement or an
7780 -- object declaration whose expression is node Expr.
7782 function Is_Attribute_Expression
(Expr
: Node_Id
) return Boolean;
7783 -- Determine whether Expr is part of an N_Attribute_Reference
7786 ----------------------------------------
7787 -- Is_Assignment_Or_Object_Expression --
7788 ----------------------------------------
7790 function Is_Assignment_Or_Object_Expression
7792 Expr
: Node_Id
) return Boolean
7795 if Nkind
(Context
) in N_Assignment_Statement | N_Object_Declaration
7796 and then Expression
(Context
) = Expr
7800 -- Check whether a construct that yields a name is the expression of
7801 -- an assignment statement or an object declaration.
7803 elsif (Nkind
(Context
) in N_Attribute_Reference
7804 | N_Explicit_Dereference
7805 | N_Indexed_Component
7806 | N_Selected_Component
7808 and then Prefix
(Context
) = Expr
)
7810 (Nkind
(Context
) in N_Type_Conversion
7811 | N_Unchecked_Type_Conversion
7812 and then Expression
(Context
) = Expr
)
7815 Is_Assignment_Or_Object_Expression
7816 (Context
=> Parent
(Context
),
7819 -- Otherwise the context is not an assignment statement or an object
7825 end Is_Assignment_Or_Object_Expression
;
7827 -----------------------------
7828 -- Is_Attribute_Expression --
7829 -----------------------------
7831 function Is_Attribute_Expression
(Expr
: Node_Id
) return Boolean is
7832 N
: Node_Id
:= Expr
;
7834 while Present
(N
) loop
7835 if Nkind
(N
) = N_Attribute_Reference
then
7838 -- Prevent the search from going too far
7840 elsif Is_Body_Or_Package_Declaration
(N
) then
7848 end Is_Attribute_Expression
;
7852 E
: constant Entity_Id
:= Entity
(N
);
7855 -- Start of processing for Resolve_Entity_Name
7858 -- If garbage from errors, set to Any_Type and return
7860 if No
(E
) and then Total_Errors_Detected
/= 0 then
7861 Set_Etype
(N
, Any_Type
);
7865 -- Replace named numbers by corresponding literals. Note that this is
7866 -- the one case where Resolve_Entity_Name must reset the Etype, since
7867 -- it is currently marked as universal.
7869 if Ekind
(E
) = E_Named_Integer
then
7871 Eval_Named_Integer
(N
);
7873 elsif Ekind
(E
) = E_Named_Real
then
7875 Eval_Named_Real
(N
);
7877 -- For enumeration literals, we need to make sure that a proper style
7878 -- check is done, since such literals are overloaded, and thus we did
7879 -- not do a style check during the first phase of analysis.
7881 elsif Ekind
(E
) = E_Enumeration_Literal
then
7882 Set_Entity_With_Checks
(N
, E
);
7883 Eval_Entity_Name
(N
);
7885 -- Case of (sub)type name appearing in a context where an expression
7886 -- is expected. This is legal if occurrence is a current instance.
7887 -- See RM 8.6 (17/3). It is also legal if the expression is
7888 -- part of a choice pattern for a case stmt/expr having a
7889 -- non-discrete selecting expression.
7891 elsif Is_Type
(E
) then
7892 if Is_Current_Instance
(N
) or else Is_Case_Choice_Pattern
(N
) then
7895 -- Any other use is an error
7899 ("invalid use of subtype mark in expression or call", N
);
7902 -- Check discriminant use if entity is discriminant in current scope,
7903 -- i.e. discriminant of record or concurrent type currently being
7904 -- analyzed. Uses in corresponding body are unrestricted.
7906 elsif Ekind
(E
) = E_Discriminant
7907 and then Scope
(E
) = Current_Scope
7908 and then not Has_Completion
(Current_Scope
)
7910 Check_Discriminant_Use
(N
);
7912 -- A parameterless generic function cannot appear in a context that
7913 -- requires resolution.
7915 elsif Ekind
(E
) = E_Generic_Function
then
7916 Error_Msg_N
("illegal use of generic function", N
);
7918 -- In Ada 83 an OUT parameter cannot be read, but attributes of
7919 -- array types (i.e. bounds and length) are legal.
7921 elsif Ekind
(E
) = E_Out_Parameter
7922 and then (Is_Scalar_Type
(Etype
(E
))
7923 or else not Is_Attribute_Expression
(Parent
(N
)))
7925 and then (Nkind
(Parent
(N
)) in N_Op
7926 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
7927 or else Is_Assignment_Or_Object_Expression
7928 (Context
=> Parent
(N
),
7931 if Ada_Version
= Ada_83
then
7932 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
7935 -- In all other cases, just do the possible static evaluation
7938 -- A deferred constant that appears in an expression must have a
7939 -- completion, unless it has been removed by in-place expansion of
7940 -- an aggregate. A constant that is a renaming does not need
7943 if Ekind
(E
) = E_Constant
7944 and then Comes_From_Source
(E
)
7945 and then No
(Constant_Value
(E
))
7946 and then Is_Frozen
(Etype
(E
))
7947 and then not In_Spec_Expression
7948 and then not Is_Imported
(E
)
7949 and then Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
7951 if No_Initialization
(Parent
(E
))
7952 or else (Present
(Full_View
(E
))
7953 and then No_Initialization
(Parent
(Full_View
(E
))))
7958 ("deferred constant is frozen before completion", N
);
7962 Eval_Entity_Name
(N
);
7967 -- When the entity appears in a parameter association, retrieve the
7968 -- related subprogram call.
7970 if Nkind
(Par
) = N_Parameter_Association
then
7971 Par
:= Parent
(Par
);
7974 if Comes_From_Source
(N
) then
7976 -- The following checks are only relevant when SPARK_Mode is on as
7977 -- they are not standard Ada legality rules.
7979 if SPARK_Mode
= On
then
7981 -- An effectively volatile object for reading must appear in
7982 -- non-interfering context (SPARK RM 7.1.3(10)).
7985 and then Is_Effectively_Volatile_For_Reading
(E
)
7987 not Is_OK_Volatile_Context
(Par
, N
, Check_Actuals
=> False)
7990 ("volatile object cannot appear in this context "
7991 & "(SPARK RM 7.1.3(10))", N
);
7994 -- Check for possible elaboration issues with respect to reads of
7995 -- variables. The act of renaming the variable is not considered a
7996 -- read as it simply establishes an alias.
7998 if Legacy_Elaboration_Checks
7999 and then Ekind
(E
) = E_Variable
8000 and then Dynamic_Elaboration_Checks
8001 and then Nkind
(Par
) /= N_Object_Renaming_Declaration
8003 Check_Elab_Call
(N
);
8007 -- The variable may eventually become a constituent of a single
8008 -- protected/task type. Record the reference now and verify its
8009 -- legality when analyzing the contract of the variable
8012 if Ekind
(E
) = E_Variable
then
8013 Record_Possible_Part_Of_Reference
(E
, N
);
8016 -- A Ghost entity must appear in a specific context
8018 if Is_Ghost_Entity
(E
) then
8019 Check_Ghost_Context
(E
, N
);
8023 -- We may be resolving an entity within expanded code, so a reference to
8024 -- an entity should be ignored when calculating effective use clauses to
8025 -- avoid inappropriate marking.
8027 if Comes_From_Source
(N
) then
8028 Mark_Use_Clauses
(E
);
8030 end Resolve_Entity_Name
;
8036 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
8037 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
8045 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
8046 -- If the bounds of the entry family being called depend on task
8047 -- discriminants, build a new index subtype where a discriminant is
8048 -- replaced with the value of the discriminant of the target task.
8049 -- The target task is the prefix of the entry name in the call.
8051 -----------------------
8052 -- Actual_Index_Type --
8053 -----------------------
8055 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
8056 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
8057 Tsk
: constant Entity_Id
:= Scope
(E
);
8058 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
8059 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
8062 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
8063 -- If the bound is given by a discriminant, replace with a reference
8064 -- to the discriminant of the same name in the target task. If the
8065 -- entry name is the target of a requeue statement and the entry is
8066 -- in the current protected object, the bound to be used is the
8067 -- discriminal of the object (see Apply_Range_Check for details of
8068 -- the transformation).
8070 -----------------------------
8071 -- Actual_Discriminant_Ref --
8072 -----------------------------
8074 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
8075 Typ
: constant Entity_Id
:= Etype
(Bound
);
8079 Remove_Side_Effects
(Bound
);
8081 if not Is_Entity_Name
(Bound
)
8082 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
8086 elsif Is_Protected_Type
(Tsk
)
8087 and then In_Open_Scopes
(Tsk
)
8088 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
8090 -- Note: here Bound denotes a discriminant of the corresponding
8091 -- record type tskV, whose discriminal is a formal of the
8092 -- init-proc tskVIP. What we want is the body discriminal,
8093 -- which is associated to the discriminant of the original
8094 -- concurrent type tsk.
8096 return New_Occurrence_Of
8097 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
8101 Make_Selected_Component
(Loc
,
8102 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
8103 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
8108 end Actual_Discriminant_Ref
;
8110 -- Start of processing for Actual_Index_Type
8113 if not Has_Discriminants
(Tsk
)
8114 or else (not Is_Entity_Name
(Lo
) and then not Is_Entity_Name
(Hi
))
8116 return Entry_Index_Type
(E
);
8119 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
8120 Set_Etype
(New_T
, Base_Type
(Typ
));
8121 Set_Size_Info
(New_T
, Typ
);
8122 Set_RM_Size
(New_T
, RM_Size
(Typ
));
8123 Set_Scalar_Range
(New_T
,
8124 Make_Range
(Sloc
(Entry_Name
),
8125 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
8126 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
8130 end Actual_Index_Type
;
8132 -- Start of processing for Resolve_Entry
8135 -- Find name of entry being called, and resolve prefix of name with its
8136 -- own type. The prefix can be overloaded, and the name and signature of
8137 -- the entry must be taken into account.
8139 if Nkind
(Entry_Name
) = N_Indexed_Component
then
8141 -- Case of dealing with entry family within the current tasks
8143 E_Name
:= Prefix
(Entry_Name
);
8146 E_Name
:= Entry_Name
;
8149 if Is_Entity_Name
(E_Name
) then
8151 -- Entry call to an entry (or entry family) in the current task. This
8152 -- is legal even though the task will deadlock. Rewrite as call to
8155 -- This can also be a call to an entry in an enclosing task. If this
8156 -- is a single task, we have to retrieve its name, because the scope
8157 -- of the entry is the task type, not the object. If the enclosing
8158 -- task is a task type, the identity of the task is given by its own
8161 -- Finally this can be a requeue on an entry of the same task or
8162 -- protected object.
8164 S
:= Scope
(Entity
(E_Name
));
8166 for J
in reverse 0 .. Scope_Stack
.Last
loop
8167 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
8168 and then not Comes_From_Source
(S
)
8170 -- S is an enclosing task or protected object. The concurrent
8171 -- declaration has been converted into a type declaration, and
8172 -- the object itself has an object declaration that follows
8173 -- the type in the same declarative part.
8175 Tsk
:= Next_Entity
(S
);
8176 while Etype
(Tsk
) /= S
loop
8183 elsif S
= Scope_Stack
.Table
(J
).Entity
then
8185 -- Call to current task. Will be transformed into call to Self
8193 Make_Selected_Component
(Loc
,
8194 Prefix
=> New_Occurrence_Of
(S
, Loc
),
8196 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
8197 Rewrite
(E_Name
, New_N
);
8200 elsif Nkind
(Entry_Name
) = N_Selected_Component
8201 and then Is_Overloaded
(Prefix
(Entry_Name
))
8203 -- Use the entry name (which must be unique at this point) to find
8204 -- the prefix that returns the corresponding task/protected type.
8207 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
8208 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
8213 Get_First_Interp
(Pref
, I
, It
);
8214 while Present
(It
.Typ
) loop
8215 if Scope
(Ent
) = It
.Typ
then
8216 Set_Etype
(Pref
, It
.Typ
);
8220 Get_Next_Interp
(I
, It
);
8225 if Nkind
(Entry_Name
) = N_Selected_Component
then
8226 Resolve
(Prefix
(Entry_Name
));
8227 Resolve_Implicit_Dereference
(Prefix
(Entry_Name
));
8229 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8230 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
8231 Resolve
(Prefix
(Prefix
(Entry_Name
)));
8232 Resolve_Implicit_Dereference
(Prefix
(Prefix
(Entry_Name
)));
8234 -- We do not resolve the prefix because an Entry_Family has no type,
8235 -- although it has the semantics of an array since it can be indexed.
8236 -- In order to perform the associated range check, we would need to
8237 -- build an array type on the fly and set it on the prefix, but this
8238 -- would be wasteful since only the index type matters. Therefore we
8239 -- attach this index type directly, so that Actual_Index_Expression
8240 -- can pick it up later in order to generate the range check.
8242 Set_Etype
(Prefix
(Entry_Name
), Actual_Index_Type
(Nam
));
8244 Index
:= First
(Expressions
(Entry_Name
));
8245 Resolve
(Index
, Entry_Index_Type
(Nam
));
8247 -- Generate a reference for the index when it denotes an entity
8249 if Is_Entity_Name
(Index
) then
8250 Generate_Reference
(Entity
(Index
), Nam
);
8253 -- Up to this point the expression could have been the actual in a
8254 -- simple entry call, and be given by a named association.
8256 if Nkind
(Index
) = N_Parameter_Association
then
8257 Error_Msg_N
("expect expression for entry index", Index
);
8259 Apply_Scalar_Range_Check
(Index
, Etype
(Prefix
(Entry_Name
)));
8264 ------------------------
8265 -- Resolve_Entry_Call --
8266 ------------------------
8268 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
8269 Entry_Name
: constant Node_Id
:= Name
(N
);
8270 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
8278 -- We kill all checks here, because it does not seem worth the effort to
8279 -- do anything better, an entry call is a big operation.
8283 -- Processing of the name is similar for entry calls and protected
8284 -- operation calls. Once the entity is determined, we can complete
8285 -- the resolution of the actuals.
8287 -- The selector may be overloaded, in the case of a protected object
8288 -- with overloaded functions. The type of the context is used for
8291 if Nkind
(Entry_Name
) = N_Selected_Component
8292 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
8293 and then Typ
/= Standard_Void_Type
8300 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
8301 while Present
(It
.Typ
) loop
8302 if Covers
(Typ
, It
.Typ
) then
8303 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
8304 Set_Etype
(Entry_Name
, It
.Typ
);
8306 Generate_Reference
(It
.Typ
, N
, ' ');
8309 Get_Next_Interp
(I
, It
);
8314 Resolve_Entry
(Entry_Name
);
8316 if Nkind
(Entry_Name
) = N_Selected_Component
then
8318 -- Simple entry or protected operation call
8320 Nam
:= Entity
(Selector_Name
(Entry_Name
));
8321 Obj
:= Prefix
(Entry_Name
);
8323 if Is_Subprogram
(Nam
) then
8324 Check_For_Eliminated_Subprogram
(Entry_Name
, Nam
);
8327 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
8329 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8331 -- Call to member of entry family
8333 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
8334 Obj
:= Prefix
(Prefix
(Entry_Name
));
8335 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
8338 -- We cannot in general check the maximum depth of protected entry calls
8339 -- at compile time. But we can tell that any protected entry call at all
8340 -- violates a specified nesting depth of zero.
8342 if Is_Protected_Type
(Scope
(Nam
)) then
8343 Check_Restriction
(Max_Entry_Queue_Length
, N
);
8346 -- Use context type to disambiguate a protected function that can be
8347 -- called without actuals and that returns an array type, and where the
8348 -- argument list may be an indexing of the returned value.
8350 if Ekind
(Nam
) = E_Function
8351 and then Needs_No_Actuals
(Nam
)
8352 and then Present
(Parameter_Associations
(N
))
8354 ((Is_Array_Type
(Etype
(Nam
))
8355 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
8357 or else (Is_Access_Type
(Etype
(Nam
))
8358 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
8362 Component_Type
(Designated_Type
(Etype
(Nam
))))))
8365 Index_Node
: Node_Id
;
8369 Make_Indexed_Component
(Loc
,
8371 Make_Function_Call
(Loc
, Name
=> Relocate_Node
(Entry_Name
)),
8372 Expressions
=> Parameter_Associations
(N
));
8374 -- Since we are correcting a node classification error made by the
8375 -- parser, we call Replace rather than Rewrite.
8377 Replace
(N
, Index_Node
);
8378 Set_Etype
(Prefix
(N
), Etype
(Nam
));
8380 Resolve_Indexed_Component
(N
, Typ
);
8386 and then Present
(Contract_Wrapper
(Nam
))
8387 and then Current_Scope
/= Contract_Wrapper
(Nam
)
8389 -- Note the entity being called before rewriting the call, so that
8390 -- it appears used at this point.
8392 Generate_Reference
(Nam
, Entry_Name
, 'r');
8394 -- Rewrite as call to the precondition wrapper, adding the task
8395 -- object to the list of actuals. If the call is to a member of an
8396 -- entry family, include the index as well.
8400 New_Actuals
: List_Id
;
8403 New_Actuals
:= New_List
(Obj
);
8405 if Nkind
(Entry_Name
) = N_Indexed_Component
then
8406 Append_To
(New_Actuals
,
8407 New_Copy_Tree
(First
(Expressions
(Entry_Name
))));
8410 Append_List
(Parameter_Associations
(N
), New_Actuals
);
8412 Make_Procedure_Call_Statement
(Loc
,
8414 New_Occurrence_Of
(Contract_Wrapper
(Nam
), Loc
),
8415 Parameter_Associations
=> New_Actuals
);
8416 Rewrite
(N
, New_Call
);
8418 -- Preanalyze and resolve new call. Current procedure is called
8419 -- from Resolve_Call, after which expansion will take place.
8421 Preanalyze_And_Resolve
(N
);
8426 -- The operation name may have been overloaded. Order the actuals
8427 -- according to the formals of the resolved entity, and set the return
8428 -- type to that of the operation.
8431 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
8432 pragma Assert
(Norm_OK
);
8433 Set_Etype
(N
, Etype
(Nam
));
8435 -- Reset the Is_Overloaded flag, since resolution is now completed
8437 -- Simple entry call
8439 if Nkind
(Entry_Name
) = N_Selected_Component
then
8440 Set_Is_Overloaded
(Selector_Name
(Entry_Name
), False);
8442 -- Call to a member of an entry family
8444 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
8445 Set_Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)), False);
8449 Resolve_Actuals
(N
, Nam
);
8450 Check_Internal_Protected_Use
(N
, Nam
);
8452 -- Create a call reference to the entry
8454 Generate_Reference
(Nam
, Entry_Name
, 's');
8456 if Is_Entry
(Nam
) then
8457 Check_Potentially_Blocking_Operation
(N
);
8460 -- Verify that a procedure call cannot masquerade as an entry
8461 -- call where an entry call is expected.
8463 if Ekind
(Nam
) = E_Procedure
then
8464 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
8465 and then N
= Entry_Call_Statement
(Parent
(N
))
8467 Error_Msg_N
("entry call required in select statement", N
);
8469 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
8470 and then N
= Triggering_Statement
(Parent
(N
))
8472 Error_Msg_N
("triggering statement cannot be procedure call", N
);
8474 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
8475 and then not In_Open_Scopes
(Scope
(Nam
))
8477 Error_Msg_N
("task has no entry with this name", Entry_Name
);
8481 -- After resolution, entry calls and protected procedure calls are
8482 -- changed into entry calls, for expansion. The structure of the node
8483 -- does not change, so it can safely be done in place. Protected
8484 -- function calls must keep their structure because they are
8487 if Ekind
(Nam
) /= E_Function
then
8489 -- A protected operation that is not a function may modify the
8490 -- corresponding object, and cannot apply to a constant. If this
8491 -- is an internal call, the prefix is the type itself.
8493 if Is_Protected_Type
(Scope
(Nam
))
8494 and then not Is_Variable
(Obj
)
8495 and then (not Is_Entity_Name
(Obj
)
8496 or else not Is_Type
(Entity
(Obj
)))
8499 ("prefix of protected procedure or entry call must be variable",
8504 Entry_Call
: Node_Id
;
8508 Make_Entry_Call_Statement
(Loc
,
8510 Parameter_Associations
=> Parameter_Associations
(N
));
8512 -- Inherit relevant attributes from the original call
8514 Set_First_Named_Actual
8515 (Entry_Call
, First_Named_Actual
(N
));
8517 Set_Is_Elaboration_Checks_OK_Node
8518 (Entry_Call
, Is_Elaboration_Checks_OK_Node
(N
));
8520 Set_Is_Elaboration_Warnings_OK_Node
8521 (Entry_Call
, Is_Elaboration_Warnings_OK_Node
(N
));
8523 Set_Is_SPARK_Mode_On_Node
8524 (Entry_Call
, Is_SPARK_Mode_On_Node
(N
));
8526 Rewrite
(N
, Entry_Call
);
8527 Set_Analyzed
(N
, True);
8530 -- Protected functions can return on the secondary stack, in which case
8531 -- we must trigger the transient scope mechanism.
8533 elsif Expander_Active
8534 and then Requires_Transient_Scope
(Etype
(Nam
))
8536 Establish_Transient_Scope
(N
, Manage_Sec_Stack
=> True);
8539 -- Now we know that this is not a call to a function that returns an
8540 -- array type; moreover, we know the name of the called entry. Detect
8541 -- overlapping actuals, just like for a subprogram call.
8543 Warn_On_Overlapping_Actuals
(Nam
, N
);
8544 end Resolve_Entry_Call
;
8546 -------------------------
8547 -- Resolve_Equality_Op --
8548 -------------------------
8550 -- The operands must have compatible types and the boolean context does not
8551 -- participate in the resolution. The first pass verifies that the operands
8552 -- are not ambiguous and sets their type correctly, or to Any_Type in case
8553 -- of ambiguity. If both operands are strings, aggregates, allocators, or
8554 -- null, they are ambiguous even if they carry a single (universal) type.
8556 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8557 L
: constant Node_Id
:= Left_Opnd
(N
);
8558 R
: constant Node_Id
:= Right_Opnd
(N
);
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
8832 if Ekind
(Entity
(N
)) = E_Operator
8833 and then (Is_Overloaded
(L
) or else Is_Overloaded
(R
))
8835 Ambiguous_Operands
(N
);
8839 -- Deal with other error cases
8841 if T
= Any_String
or else
8842 T
= Any_Composite
or else
8845 if T
= Any_Character
then
8846 Ambiguous_Character
(L
);
8848 Error_Msg_N
("ambiguous operands for equality", N
);
8851 Set_Etype
(N
, Any_Type
);
8854 elsif T
= Universal_Access
8855 or else Ekind
(T
) in E_Allocator_Type | E_Access_Attribute_Type
8857 T
:= Find_Unique_Access_Type
;
8860 Error_Msg_N
("ambiguous operands for equality", N
);
8861 Set_Etype
(N
, Any_Type
);
8865 -- If expressions must have a single type, and if the context does
8866 -- not impose one the dependent expressions cannot be anonymous
8869 -- Why no similar processing for case expressions???
8871 elsif Ada_Version
>= Ada_2012
8872 and then Is_Anonymous_Access_Type
(Etype
(L
))
8873 and then Is_Anonymous_Access_Type
(Etype
(R
))
8875 Check_If_Expression
(L
);
8876 Check_If_Expression
(R
);
8879 -- RM 4.5.2(9.5/2): At least one of the operands of the equality
8880 -- operators for universal_access shall be of type universal_access,
8881 -- or both shall be of access-to-object types, or both shall be of
8882 -- access-to-subprogram types (RM 4.5.2(9.5/2)).
8884 if Is_Anonymous_Access_Type
(T
)
8885 and then Etype
(L
) /= Universal_Access
8886 and then Etype
(R
) /= Universal_Access
8888 -- RM 4.5.2(9.6/2): When both are of access-to-object types, the
8889 -- designated types shall be the same or one shall cover the other
8890 -- and if the designated types are elementary or array types, then
8891 -- the designated subtypes shall statically match.
8893 if Is_Access_Object_Type
(Etype
(L
))
8894 and then Is_Access_Object_Type
(Etype
(R
))
8896 Check_Designated_Object_Types
8897 (Designated_Type
(Etype
(L
)), Designated_Type
(Etype
(R
)));
8899 -- RM 4.5.2(9.7/2): When both are of access-to-subprogram types,
8900 -- the designated profiles shall be subtype conformant.
8902 elsif Is_Access_Subprogram_Type
(Etype
(L
))
8903 and then Is_Access_Subprogram_Type
(Etype
(R
))
8905 Check_Designated_Subprogram_Types
8906 (Designated_Type
(Etype
(L
)), Designated_Type
(Etype
(R
)));
8910 -- Check another case of equality operators for universal_access
8912 if Is_Anonymous_Access_Type
(T
) and then Comes_From_Source
(N
) then
8913 Check_Access_Attribute
(L
);
8914 Check_Access_Attribute
(R
);
8920 -- If the unique type is a class-wide type then it will be expanded
8921 -- into a dispatching call to the predefined primitive. Therefore we
8922 -- check here for potential violation of such restriction.
8924 if Is_Class_Wide_Type
(T
) then
8925 Check_Restriction
(No_Dispatching_Calls
, N
);
8928 -- Only warn for redundant equality comparison to True for objects
8929 -- (e.g. "X = True") and operations (e.g. "(X < Y) = True"). For
8930 -- other expressions, it may be a matter of preference to write
8931 -- "Expr = True" or "Expr".
8933 if Warn_On_Redundant_Constructs
8934 and then Comes_From_Source
(N
)
8935 and then Comes_From_Source
(R
)
8936 and then Is_Entity_Name
(R
)
8937 and then Entity
(R
) = Standard_True
8939 ((Is_Entity_Name
(L
) and then Is_Object
(Entity
(L
)))
8943 Error_Msg_N
-- CODEFIX
8944 ("?r?comparison with True is redundant!", N
);
8945 Explain_Redundancy
(Original_Node
(R
));
8948 -- Warn on a (in)equality between boolean values which is not
8949 -- parenthesized when the parent expression is one of and/or/xor, as
8950 -- this is interpreted as (a = b) op c where most likely a = (b op c)
8951 -- was intended. Do not generate a warning in generic instances, as
8952 -- the problematic expression may be implicitly parenthesized in
8953 -- the generic itself if one of the operators is a generic formal.
8954 -- Also do not generate a warning for generated equality, for
8955 -- example from rewritting a membership test.
8957 if Warn_On_Questionable_Missing_Parens
8958 and then not In_Instance
8959 and then Comes_From_Source
(N
)
8960 and then Is_Boolean_Type
(T
)
8961 and then Suspicious_Prio_For_Equality
8963 Error_Msg_N
("?q?equality should be parenthesized here!", N
);
8966 Check_Unset_Reference
(L
);
8967 Check_Unset_Reference
(R
);
8968 Generate_Operator_Reference
(N
, T
);
8969 Check_Low_Bound_Tested
(N
);
8971 -- If this is an inequality, it may be the implicit inequality
8972 -- created for a user-defined operation, in which case the corres-
8973 -- ponding equality operation is not intrinsic, and the operation
8974 -- cannot be constant-folded. Else fold.
8976 if Nkind
(N
) = N_Op_Eq
8977 or else Comes_From_Source
(Entity
(N
))
8978 or else Ekind
(Entity
(N
)) = E_Operator
8979 or else Is_Intrinsic_Subprogram
8980 (Corresponding_Equality
(Entity
(N
)))
8982 Analyze_Dimension
(N
);
8983 Eval_Relational_Op
(N
);
8985 elsif Nkind
(N
) = N_Op_Ne
8986 and then Is_Abstract_Subprogram
(Entity
(N
))
8988 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Entity
(N
));
8991 end Resolve_Equality_Op
;
8993 ----------------------------------
8994 -- Resolve_Explicit_Dereference --
8995 ----------------------------------
8997 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
8998 Loc
: constant Source_Ptr
:= Sloc
(N
);
9000 P
: constant Node_Id
:= Prefix
(N
);
9003 -- The candidate prefix type, if overloaded
9009 Check_Fully_Declared_Prefix
(Typ
, P
);
9012 -- A useful optimization: check whether the dereference denotes an
9013 -- element of a container, and if so rewrite it as a call to the
9014 -- corresponding Element function.
9016 -- Disabled for now, on advice of ARG. A more restricted form of the
9017 -- predicate might be acceptable ???
9019 -- if Is_Container_Element (N) then
9023 if Is_Overloaded
(P
) then
9025 -- Use the context type to select the prefix that has the correct
9026 -- designated type. Keep the first match, which will be the inner-
9029 Get_First_Interp
(P
, I
, It
);
9031 while Present
(It
.Typ
) loop
9032 if Is_Access_Type
(It
.Typ
)
9033 and then Covers
(Typ
, Designated_Type
(It
.Typ
))
9039 -- Remove access types that do not match, but preserve access
9040 -- to subprogram interpretations, in case a further dereference
9041 -- is needed (see below).
9043 elsif Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
9047 Get_Next_Interp
(I
, It
);
9050 if Present
(P_Typ
) then
9052 Set_Etype
(N
, Designated_Type
(P_Typ
));
9055 -- If no interpretation covers the designated type of the prefix,
9056 -- this is the pathological case where not all implementations of
9057 -- the prefix allow the interpretation of the node as a call. Now
9058 -- that the expected type is known, Remove other interpretations
9059 -- from prefix, rewrite it as a call, and resolve again, so that
9060 -- the proper call node is generated.
9062 Get_First_Interp
(P
, I
, It
);
9063 while Present
(It
.Typ
) loop
9064 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
9068 Get_Next_Interp
(I
, It
);
9072 Make_Function_Call
(Loc
,
9074 Make_Explicit_Dereference
(Loc
,
9076 Parameter_Associations
=> New_List
);
9078 Save_Interps
(N
, New_N
);
9080 Analyze_And_Resolve
(N
, Typ
);
9084 -- If not overloaded, resolve P with its own type
9090 -- If the prefix might be null, add an access check
9092 if Is_Access_Type
(Etype
(P
))
9093 and then not Can_Never_Be_Null
(Etype
(P
))
9095 Apply_Access_Check
(N
);
9098 -- If the designated type is a packed unconstrained array type, and the
9099 -- explicit dereference is not in the context of an attribute reference,
9100 -- then we must compute and set the actual subtype, since it is needed
9101 -- by Gigi. The reason we exclude the attribute case is that this is
9102 -- handled fine by Gigi, and in fact we use such attributes to build the
9103 -- actual subtype. We also exclude generated code (which builds actual
9104 -- subtypes directly if they are needed).
9106 if Is_Packed_Array
(Etype
(N
))
9107 and then not Is_Constrained
(Etype
(N
))
9108 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
9109 and then Comes_From_Source
(N
)
9111 Set_Etype
(N
, Get_Actual_Subtype
(N
));
9114 Analyze_Dimension
(N
);
9116 -- Note: No Eval processing is required for an explicit dereference,
9117 -- because such a name can never be static.
9119 end Resolve_Explicit_Dereference
;
9121 -------------------------------------
9122 -- Resolve_Expression_With_Actions --
9123 -------------------------------------
9125 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
9127 function OK_For_Static
(Act
: Node_Id
) return Boolean;
9128 -- True if Act is an action of a declare_expression that is allowed in a
9129 -- static declare_expression.
9131 function All_OK_For_Static
return Boolean;
9132 -- True if all actions of N are allowed in a static declare_expression.
9134 function Get_Literal
(Expr
: Node_Id
) return Node_Id
;
9135 -- Expr is an expression with compile-time-known value. This returns the
9136 -- literal node that reprsents that value.
9138 function OK_For_Static
(Act
: Node_Id
) return Boolean is
9141 when N_Object_Declaration
=>
9142 if Constant_Present
(Act
)
9143 and then Is_Static_Expression
(Expression
(Act
))
9148 when N_Object_Renaming_Declaration
=>
9149 if Statically_Names_Object
(Name
(Act
)) then
9154 -- No other declarations, nor even pragmas, are allowed in a
9155 -- declare expression, so if we see something else, it must be
9156 -- an internally generated expression_with_actions.
9163 function All_OK_For_Static
return Boolean is
9164 Act
: Node_Id
:= First
(Actions
(N
));
9166 while Present
(Act
) loop
9167 if not OK_For_Static
(Act
) then
9175 end All_OK_For_Static
;
9177 function Get_Literal
(Expr
: Node_Id
) return Node_Id
is
9178 pragma Assert
(Compile_Time_Known_Value
(Expr
));
9181 case Nkind
(Expr
) is
9182 when N_Has_Entity
=>
9183 if Ekind
(Entity
(Expr
)) = E_Enumeration_Literal
then
9186 Result
:= Constant_Value
(Entity
(Expr
));
9188 when N_Numeric_Or_String_Literal
=>
9191 raise Program_Error
;
9195 (Nkind
(Result
) in N_Numeric_Or_String_Literal
9196 or else Ekind
(Entity
(Result
)) = E_Enumeration_Literal
);
9200 Loc
: constant Source_Ptr
:= Sloc
(N
);
9205 if Is_Empty_List
(Actions
(N
)) then
9206 pragma Assert
(All_OK_For_Static
); null;
9209 -- If the value of the expression is known at compile time, and all
9210 -- of the actions (if any) are suitable, then replace the declare
9211 -- expression with its expression. This allows the declare expression
9212 -- as a whole to be static if appropriate. See AI12-0368.
9214 if Compile_Time_Known_Value
(Expression
(N
)) then
9215 if Is_Empty_List
(Actions
(N
)) then
9216 Rewrite
(N
, Expression
(N
));
9217 elsif All_OK_For_Static
then
9220 (Get_Literal
(Expression
(N
)), New_Sloc
=> Loc
));
9223 end Resolve_Expression_With_Actions
;
9225 ----------------------------------
9226 -- Resolve_Generalized_Indexing --
9227 ----------------------------------
9229 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
) is
9230 Indexing
: constant Node_Id
:= Generalized_Indexing
(N
);
9232 Rewrite
(N
, Indexing
);
9234 end Resolve_Generalized_Indexing
;
9236 ---------------------------
9237 -- Resolve_If_Expression --
9238 ---------------------------
9240 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9241 procedure Apply_Check
(Expr
: Node_Id
);
9242 -- When a dependent expression is of a subtype different from
9243 -- the context subtype, then insert a qualification to ensure
9244 -- the generation of a constraint check. This was previously
9245 -- for scalar types. For array types apply a length check, given
9246 -- that the context in general allows sliding, while a qualified
9247 -- expression forces equality of bounds.
9249 Result_Type
: Entity_Id
:= Typ
;
9250 -- So in most cases the type of the If_Expression and of its
9251 -- dependent expressions is that of the context. However, if
9252 -- the expression is the index of an Indexed_Component, we must
9253 -- ensure that a proper index check is applied, rather than a
9254 -- range check on the index type (which might be discriminant
9255 -- dependent). In this case we resolve with the base type of the
9256 -- index type, and the index check is generated in the resolution
9257 -- of the indexed_component above.
9263 procedure Apply_Check
(Expr
: Node_Id
) is
9264 Expr_Typ
: constant Entity_Id
:= Etype
(Expr
);
9265 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
9269 or else Is_Tagged_Type
(Typ
)
9270 or else Is_Access_Type
(Typ
)
9271 or else not Is_Constrained
(Typ
)
9272 or else Inside_A_Generic
9276 elsif Is_Array_Type
(Typ
) then
9277 Apply_Length_Check
(Expr
, Typ
);
9281 Make_Qualified_Expression
(Loc
,
9282 Subtype_Mark
=> New_Occurrence_Of
(Result_Type
, Loc
),
9283 Expression
=> Relocate_Node
(Expr
)));
9285 Analyze_And_Resolve
(Expr
, Result_Type
);
9291 Condition
: constant Node_Id
:= First
(Expressions
(N
));
9292 Else_Expr
: Node_Id
;
9293 Then_Expr
: Node_Id
;
9295 -- Start of processing for Resolve_If_Expression
9298 -- Defend against malformed expressions
9300 if No
(Condition
) then
9304 if Present
(Parent
(N
))
9305 and then (Nkind
(Parent
(N
)) = N_Indexed_Component
9306 or else Nkind
(Parent
(Parent
(N
))) = N_Indexed_Component
)
9308 Result_Type
:= Base_Type
(Typ
);
9311 Then_Expr
:= Next
(Condition
);
9313 if No
(Then_Expr
) then
9317 Else_Expr
:= Next
(Then_Expr
);
9319 Resolve
(Condition
, Any_Boolean
);
9320 Resolve
(Then_Expr
, Result_Type
);
9321 Check_Unset_Reference
(Condition
);
9322 Check_Unset_Reference
(Then_Expr
);
9324 Apply_Check
(Then_Expr
);
9326 -- If ELSE expression present, just resolve using the determined type
9327 -- If type is universal, resolve to any member of the class.
9329 if Present
(Else_Expr
) then
9330 if Typ
= Universal_Integer
then
9331 Resolve
(Else_Expr
, Any_Integer
);
9333 elsif Typ
= Universal_Real
then
9334 Resolve
(Else_Expr
, Any_Real
);
9337 Resolve
(Else_Expr
, Result_Type
);
9340 Check_Unset_Reference
(Else_Expr
);
9342 Apply_Check
(Else_Expr
);
9344 -- Apply RM 4.5.7 (17/3): whether the expression is statically or
9345 -- dynamically tagged must be known statically.
9347 if Is_Tagged_Type
(Typ
) and then not Is_Class_Wide_Type
(Typ
) then
9348 if Is_Dynamically_Tagged
(Then_Expr
) /=
9349 Is_Dynamically_Tagged
(Else_Expr
)
9351 Error_Msg_N
("all or none of the dependent expressions "
9352 & "can be dynamically tagged", N
);
9356 -- If no ELSE expression is present, root type must be Standard.Boolean
9357 -- and we provide a Standard.True result converted to the appropriate
9358 -- Boolean type (in case it is a derived boolean type).
9360 elsif Root_Type
(Typ
) = Standard_Boolean
then
9362 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
9363 Analyze_And_Resolve
(Else_Expr
, Result_Type
);
9364 Append_To
(Expressions
(N
), Else_Expr
);
9367 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
9368 Append_To
(Expressions
(N
), Error
);
9371 Set_Etype
(N
, Result_Type
);
9373 if not Error_Posted
(N
) then
9374 Eval_If_Expression
(N
);
9377 Analyze_Dimension
(N
);
9378 end Resolve_If_Expression
;
9380 ----------------------------------
9381 -- Resolve_Implicit_Dereference --
9382 ----------------------------------
9384 procedure Resolve_Implicit_Dereference
(P
: Node_Id
) is
9385 Desig_Typ
: Entity_Id
;
9388 -- In an instance the proper view may not always be correct for
9389 -- private types, see e.g. Sem_Type.Covers for similar handling.
9391 if Is_Private_Type
(Etype
(P
))
9392 and then Present
(Full_View
(Etype
(P
)))
9393 and then Is_Access_Type
(Full_View
(Etype
(P
)))
9394 and then In_Instance
9396 Set_Etype
(P
, Full_View
(Etype
(P
)));
9399 if Is_Access_Type
(Etype
(P
)) then
9400 Desig_Typ
:= Implicitly_Designated_Type
(Etype
(P
));
9401 Insert_Explicit_Dereference
(P
);
9402 Analyze_And_Resolve
(P
, Desig_Typ
);
9404 end Resolve_Implicit_Dereference
;
9406 -------------------------------
9407 -- Resolve_Indexed_Component --
9408 -------------------------------
9410 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
9411 Pref
: constant Node_Id
:= Prefix
(N
);
9413 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
9417 if Present
(Generalized_Indexing
(N
)) then
9418 Resolve_Generalized_Indexing
(N
, Typ
);
9422 if Is_Overloaded
(Pref
) then
9424 -- Use the context type to select the prefix that yields the correct
9430 I1
: Interp_Index
:= 0;
9431 Found
: Boolean := False;
9434 Get_First_Interp
(Pref
, I
, It
);
9435 while Present
(It
.Typ
) loop
9436 if (Is_Array_Type
(It
.Typ
)
9437 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
9438 or else (Is_Access_Type
(It
.Typ
)
9439 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
9443 Component_Type
(Designated_Type
(It
.Typ
))))
9446 It
:= Disambiguate
(Pref
, I1
, I
, Any_Type
);
9448 if It
= No_Interp
then
9449 Error_Msg_N
("ambiguous prefix for indexing", N
);
9455 Array_Type
:= It
.Typ
;
9461 Array_Type
:= It
.Typ
;
9466 Get_Next_Interp
(I
, It
);
9471 Array_Type
:= Etype
(Pref
);
9474 Resolve
(Pref
, Array_Type
);
9475 Array_Type
:= Get_Actual_Subtype_If_Available
(Pref
);
9477 -- If the prefix's type is an access type, get to the real array type.
9478 -- Note: we do not apply an access check because an explicit dereference
9479 -- will be introduced later, and the check will happen there.
9481 if Is_Access_Type
(Array_Type
) then
9482 Array_Type
:= Implicitly_Designated_Type
(Array_Type
);
9485 -- If name was overloaded, set component type correctly now.
9486 -- If a misplaced call to an entry family (which has no index types)
9487 -- return. Error will be diagnosed from calling context.
9489 if Is_Array_Type
(Array_Type
) then
9490 Set_Etype
(N
, Component_Type
(Array_Type
));
9495 Index
:= First_Index
(Array_Type
);
9496 Expr
:= First
(Expressions
(N
));
9498 -- The prefix may have resolved to a string literal, in which case its
9499 -- etype has a special representation. This is only possible currently
9500 -- if the prefix is a static concatenation, written in functional
9503 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
9504 Resolve
(Expr
, Standard_Positive
);
9507 while Present
(Index
) and then Present
(Expr
) loop
9508 Resolve
(Expr
, Etype
(Index
));
9509 Check_Unset_Reference
(Expr
);
9511 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
9518 Resolve_Implicit_Dereference
(Pref
);
9519 Analyze_Dimension
(N
);
9521 -- Do not generate the warning on suspicious index if we are analyzing
9522 -- package Ada.Tags; otherwise we will report the warning with the
9523 -- Prims_Ptr field of the dispatch table.
9525 if Scope
(Etype
(Pref
)) = Standard_Standard
9527 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Pref
))), Ada_Tags
)
9529 Warn_On_Suspicious_Index
(Pref
, First
(Expressions
(N
)));
9530 Eval_Indexed_Component
(N
);
9533 -- If the array type is atomic and the component is not, then this is
9534 -- worth a warning before Ada 2022, since we have a situation where the
9535 -- access to the component may cause extra read/writes of the atomic
9536 -- object, or partial word accesses, both of which may be unexpected.
9538 if Nkind
(N
) = N_Indexed_Component
9539 and then Is_Atomic_Ref_With_Address
(N
)
9540 and then not (Has_Atomic_Components
(Array_Type
)
9541 or else (Is_Entity_Name
(Pref
)
9542 and then Has_Atomic_Components
9544 and then not Is_Atomic
(Component_Type
(Array_Type
))
9545 and then Ada_Version
< Ada_2022
9548 ("??access to non-atomic component of atomic array", Pref
);
9550 ("??\may cause unexpected accesses to atomic object", Pref
);
9552 end Resolve_Indexed_Component
;
9554 -----------------------------
9555 -- Resolve_Integer_Literal --
9556 -----------------------------
9558 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9561 Eval_Integer_Literal
(N
);
9562 end Resolve_Integer_Literal
;
9564 --------------------------------
9565 -- Resolve_Intrinsic_Operator --
9566 --------------------------------
9568 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
9569 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
9574 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
;
9575 -- If the operand is a literal, it cannot be the expression in a
9576 -- conversion. Use a qualified expression instead.
9578 ---------------------
9579 -- Convert_Operand --
9580 ---------------------
9582 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
is
9583 Loc
: constant Source_Ptr
:= Sloc
(Opnd
);
9587 if Nkind
(Opnd
) in N_Integer_Literal | N_Real_Literal
then
9589 Make_Qualified_Expression
(Loc
,
9590 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
9591 Expression
=> Relocate_Node
(Opnd
));
9595 Res
:= Unchecked_Convert_To
(Btyp
, Opnd
);
9599 end Convert_Operand
;
9601 -- Start of processing for Resolve_Intrinsic_Operator
9604 -- We must preserve the original entity in a generic setting, so that
9605 -- the legality of the operation can be verified in an instance.
9607 if not Expander_Active
then
9612 while Scope
(Op
) /= Standard_Standard
loop
9614 pragma Assert
(Present
(Op
));
9618 Set_Is_Overloaded
(N
, False);
9620 -- If the result or operand types are private, rewrite with unchecked
9621 -- conversions on the operands and the result, to expose the proper
9622 -- underlying numeric type.
9624 if Is_Private_Type
(Typ
)
9625 or else Is_Private_Type
(Etype
(Left_Opnd
(N
)))
9626 or else Is_Private_Type
(Etype
(Right_Opnd
(N
)))
9628 Arg1
:= Convert_Operand
(Left_Opnd
(N
));
9630 if Nkind
(N
) = N_Op_Expon
then
9631 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
9633 Arg2
:= Convert_Operand
(Right_Opnd
(N
));
9636 if Nkind
(Arg1
) = N_Type_Conversion
then
9637 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
9640 if Nkind
(Arg2
) = N_Type_Conversion
then
9641 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
9644 Set_Left_Opnd
(N
, Arg1
);
9645 Set_Right_Opnd
(N
, Arg2
);
9647 Set_Etype
(N
, Btyp
);
9648 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
9651 elsif Typ
/= Etype
(Left_Opnd
(N
))
9652 or else Typ
/= Etype
(Right_Opnd
(N
))
9654 -- Add explicit conversion where needed, and save interpretations in
9655 -- case operands are overloaded.
9657 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
9658 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
9660 if Nkind
(Arg1
) = N_Type_Conversion
then
9661 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
9663 Save_Interps
(Left_Opnd
(N
), Arg1
);
9666 if Nkind
(Arg2
) = N_Type_Conversion
then
9667 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
9669 Save_Interps
(Right_Opnd
(N
), Arg2
);
9672 Rewrite
(Left_Opnd
(N
), Arg1
);
9673 Rewrite
(Right_Opnd
(N
), Arg2
);
9676 Resolve_Arithmetic_Op
(N
, Typ
);
9679 Resolve_Arithmetic_Op
(N
, Typ
);
9681 end Resolve_Intrinsic_Operator
;
9683 --------------------------------------
9684 -- Resolve_Intrinsic_Unary_Operator --
9685 --------------------------------------
9687 procedure Resolve_Intrinsic_Unary_Operator
9691 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
9697 while Scope
(Op
) /= Standard_Standard
loop
9699 pragma Assert
(Present
(Op
));
9704 if Is_Private_Type
(Typ
) then
9705 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
9706 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
9708 Set_Right_Opnd
(N
, Arg2
);
9710 Set_Etype
(N
, Btyp
);
9711 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
9715 Resolve_Unary_Op
(N
, Typ
);
9717 end Resolve_Intrinsic_Unary_Operator
;
9719 ------------------------
9720 -- Resolve_Logical_Op --
9721 ------------------------
9723 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
9727 Check_No_Direct_Boolean_Operators
(N
);
9729 -- Predefined operations on scalar types yield the base type. On the
9730 -- other hand, logical operations on arrays yield the type of the
9731 -- arguments (and the context).
9733 if Is_Array_Type
(Typ
) then
9736 B_Typ
:= Base_Type
(Typ
);
9739 -- The following test is required because the operands of the operation
9740 -- may be literals, in which case the resulting type appears to be
9741 -- compatible with a signed integer type, when in fact it is compatible
9742 -- only with modular types. If the context itself is universal, the
9743 -- operation is illegal.
9745 if not Valid_Boolean_Arg
(Typ
) then
9746 Error_Msg_N
("invalid context for logical operation", N
);
9747 Set_Etype
(N
, Any_Type
);
9750 elsif Typ
= Any_Modular
then
9752 ("no modular type available in this context", N
);
9753 Set_Etype
(N
, Any_Type
);
9756 elsif Is_Modular_Integer_Type
(Typ
)
9757 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
9758 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
9760 Check_For_Visible_Operator
(N
, B_Typ
);
9763 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
9764 -- is active and the result type is standard Boolean (do not mess with
9765 -- ops that return a nonstandard Boolean type, because something strange
9768 -- Note: you might expect this replacement to be done during expansion,
9769 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
9770 -- is used, no part of the right operand of an "and" or "or" operator
9771 -- should be executed if the left operand would short-circuit the
9772 -- evaluation of the corresponding "and then" or "or else". If we left
9773 -- the replacement to expansion time, then run-time checks associated
9774 -- with such operands would be evaluated unconditionally, due to being
9775 -- before the condition prior to the rewriting as short-circuit forms
9776 -- during expansion.
9778 if Short_Circuit_And_Or
9779 and then B_Typ
= Standard_Boolean
9780 and then Nkind
(N
) in N_Op_And | N_Op_Or
9782 -- Mark the corresponding putative SCO operator as truly a logical
9783 -- (and short-circuit) operator.
9785 if Generate_SCO
and then Comes_From_Source
(N
) then
9786 Set_SCO_Logical_Operator
(N
);
9789 if Nkind
(N
) = N_Op_And
then
9791 Make_And_Then
(Sloc
(N
),
9792 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
9793 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
9794 Analyze_And_Resolve
(N
, B_Typ
);
9796 -- Case of OR changed to OR ELSE
9800 Make_Or_Else
(Sloc
(N
),
9801 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
9802 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
9803 Analyze_And_Resolve
(N
, B_Typ
);
9806 -- Return now, since analysis of the rewritten ops will take care of
9807 -- other reference bookkeeping and expression folding.
9812 Resolve
(Left_Opnd
(N
), B_Typ
);
9813 Resolve
(Right_Opnd
(N
), B_Typ
);
9815 Check_Unset_Reference
(Left_Opnd
(N
));
9816 Check_Unset_Reference
(Right_Opnd
(N
));
9818 Set_Etype
(N
, B_Typ
);
9819 Generate_Operator_Reference
(N
, B_Typ
);
9820 Eval_Logical_Op
(N
);
9821 end Resolve_Logical_Op
;
9823 ---------------------------
9824 -- Resolve_Membership_Op --
9825 ---------------------------
9827 -- The context can only be a boolean type, and does not determine the
9828 -- arguments. Arguments should be unambiguous, but the preference rule for
9829 -- universal types applies.
9831 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
9832 pragma Assert
(Is_Boolean_Type
(Typ
));
9834 L
: constant Node_Id
:= Left_Opnd
(N
);
9835 R
: constant Node_Id
:= Right_Opnd
(N
);
9838 procedure Resolve_Set_Membership
;
9839 -- Analysis has determined a unique type for the left operand. Use it as
9840 -- the basis to resolve the disjuncts.
9842 ----------------------------
9843 -- Resolve_Set_Membership --
9844 ----------------------------
9846 procedure Resolve_Set_Membership
is
9850 -- If the left operand is overloaded, find type compatible with not
9851 -- overloaded alternative of the right operand.
9853 Alt
:= First
(Alternatives
(N
));
9854 if Is_Overloaded
(L
) then
9856 while Present
(Alt
) loop
9857 if not Is_Overloaded
(Alt
) then
9858 T
:= Intersect_Types
(L
, Alt
);
9865 -- Unclear how to resolve expression if all alternatives are also
9869 Error_Msg_N
("ambiguous expression", N
);
9873 T
:= Intersect_Types
(L
, Alt
);
9878 Alt
:= First
(Alternatives
(N
));
9879 while Present
(Alt
) loop
9881 -- Alternative is an expression, a range
9882 -- or a subtype mark.
9884 if not Is_Entity_Name
(Alt
)
9885 or else not Is_Type
(Entity
(Alt
))
9893 -- Check for duplicates for discrete case
9895 if Is_Discrete_Type
(T
) then
9902 Alts
: array (0 .. List_Length
(Alternatives
(N
))) of Ent
;
9906 -- Loop checking duplicates. This is quadratic, but giant sets
9907 -- are unlikely in this context so it's a reasonable choice.
9910 Alt
:= First
(Alternatives
(N
));
9911 while Present
(Alt
) loop
9912 if Is_OK_Static_Expression
(Alt
)
9913 and then Nkind
(Alt
) in N_Integer_Literal
9914 | N_Character_Literal
9918 Alts
(Nalts
) := (Alt
, Expr_Value
(Alt
));
9920 for J
in 1 .. Nalts
- 1 loop
9921 if Alts
(J
).Val
= Alts
(Nalts
).Val
then
9922 Error_Msg_Sloc
:= Sloc
(Alts
(J
).Alt
);
9923 Error_Msg_N
("duplicate of value given#??", Alt
);
9933 -- RM 4.5.2 (28.1/3) specifies that for types other than records or
9934 -- limited types, evaluation of a membership test uses the predefined
9935 -- equality for the type. This may be confusing to users, and the
9936 -- following warning appears useful for the most common case.
9938 if Is_Scalar_Type
(Etype
(L
))
9939 and then Present
(Get_User_Defined_Eq
(Etype
(L
)))
9942 ("membership test on& uses predefined equality?", N
, Etype
(L
));
9944 ("\even if user-defined equality exists (RM 4.5.2 (28.1/3)?", N
);
9946 end Resolve_Set_Membership
;
9948 -- Start of processing for Resolve_Membership_Op
9951 if L
= Error
or else R
= Error
then
9955 if Present
(Alternatives
(N
)) then
9956 Resolve_Set_Membership
;
9959 elsif not Is_Overloaded
(R
)
9960 and then Is_Universal_Numeric_Type
(Etype
(R
))
9961 and then Is_Overloaded
(L
)
9965 -- Ada 2005 (AI-251): Support the following case:
9967 -- type I is interface;
9968 -- type T is tagged ...
9970 -- function Test (O : I'Class) is
9972 -- return O in T'Class.
9975 -- In this case we have nothing else to do. The membership test will be
9976 -- done at run time.
9978 elsif Ada_Version
>= Ada_2005
9979 and then Is_Class_Wide_Type
(Etype
(L
))
9980 and then Is_Interface
(Etype
(L
))
9981 and then not Is_Interface
(Etype
(R
))
9985 T
:= Intersect_Types
(L
, R
);
9988 -- If mixed-mode operations are present and operands are all literal,
9989 -- the only interpretation involves Duration, which is probably not
9990 -- the intention of the programmer.
9992 if T
= Any_Fixed
then
9993 T
:= Unique_Fixed_Point_Type
(N
);
9995 if T
= Any_Type
then
10001 Check_Unset_Reference
(L
);
10003 if Nkind
(R
) = N_Range
10004 and then not Is_Scalar_Type
(T
)
10006 Error_Msg_N
("scalar type required for range", R
);
10009 if Is_Entity_Name
(R
) then
10010 Freeze_Expression
(R
);
10013 Check_Unset_Reference
(R
);
10016 -- Here after resolving membership operation
10020 Eval_Membership_Op
(N
);
10021 end Resolve_Membership_Op
;
10027 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
10028 Loc
: constant Source_Ptr
:= Sloc
(N
);
10031 -- Handle restriction against anonymous null access values This
10032 -- restriction can be turned off using -gnatdj.
10034 -- Ada 2005 (AI-231): Remove restriction
10036 if Ada_Version
< Ada_2005
10037 and then not Debug_Flag_J
10038 and then Ekind
(Typ
) = E_Anonymous_Access_Type
10039 and then Comes_From_Source
(N
)
10041 -- In the common case of a call which uses an explicitly null value
10042 -- for an access parameter, give specialized error message.
10044 if Nkind
(Parent
(N
)) in N_Subprogram_Call
then
10046 ("NULL is not allowed as argument for an access parameter", N
);
10048 -- Standard message for all other cases (are there any?)
10052 ("NULL cannot be of an anonymous access type", N
);
10056 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
10057 -- assignment to a null-excluding object.
10059 if Ada_Version
>= Ada_2005
10060 and then Can_Never_Be_Null
(Typ
)
10061 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
10063 if Inside_Init_Proc
then
10065 -- Decide whether to generate an if_statement around our
10066 -- null-excluding check to avoid them on certain internal object
10067 -- declarations by looking at the type the current Init_Proc
10071 -- if T1b_skip_null_excluding_check then
10072 -- [constraint_error "access check failed"]
10075 if Needs_Conditional_Null_Excluding_Check
10076 (Etype
(First_Formal
(Enclosing_Init_Proc
)))
10079 Make_If_Statement
(Loc
,
10081 Make_Identifier
(Loc
,
10083 (Chars
(Typ
), "_skip_null_excluding_check")),
10086 Make_Raise_Constraint_Error
(Loc
,
10087 Reason
=> CE_Access_Check_Failed
))));
10089 -- Otherwise, simply create the check
10093 Make_Raise_Constraint_Error
(Loc
,
10094 Reason
=> CE_Access_Check_Failed
));
10098 (Compile_Time_Constraint_Error
(N
,
10099 "(Ada 2005) NULL not allowed in null-excluding objects??"),
10100 Make_Raise_Constraint_Error
(Loc
,
10101 Reason
=> CE_Access_Check_Failed
));
10105 -- In a distributed context, null for a remote access to subprogram may
10106 -- need to be replaced with a special record aggregate. In this case,
10107 -- return after having done the transformation.
10109 if (Ekind
(Typ
) = E_Record_Type
10110 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
10111 and then Remote_AST_Null_Value
(N
, Typ
)
10116 -- The null literal takes its type from the context
10118 Set_Etype
(N
, Typ
);
10121 -----------------------
10122 -- Resolve_Op_Concat --
10123 -----------------------
10125 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
10127 -- We wish to avoid deep recursion, because concatenations are often
10128 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
10129 -- operands nonrecursively until we find something that is not a simple
10130 -- concatenation (A in this case). We resolve that, and then walk back
10131 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
10132 -- to do the rest of the work at each level. The Parent pointers allow
10133 -- us to avoid recursion, and thus avoid running out of memory. See also
10134 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
10140 -- The following code is equivalent to:
10142 -- Resolve_Op_Concat_First (NN, Typ);
10143 -- Resolve_Op_Concat_Arg (N, ...);
10144 -- Resolve_Op_Concat_Rest (N, Typ);
10146 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
10147 -- operand is a concatenation.
10149 -- Walk down left operands
10152 Resolve_Op_Concat_First
(NN
, Typ
);
10153 Op1
:= Left_Opnd
(NN
);
10154 exit when not (Nkind
(Op1
) = N_Op_Concat
10155 and then not Is_Array_Type
(Component_Type
(Typ
))
10156 and then Entity
(Op1
) = Entity
(NN
));
10160 -- Now (given the above example) NN is A&B and Op1 is A
10162 -- First resolve Op1 ...
10164 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
10166 -- ... then walk NN back up until we reach N (where we started), calling
10167 -- Resolve_Op_Concat_Rest along the way.
10170 Resolve_Op_Concat_Rest
(NN
, Typ
);
10174 end Resolve_Op_Concat
;
10176 ---------------------------
10177 -- Resolve_Op_Concat_Arg --
10178 ---------------------------
10180 procedure Resolve_Op_Concat_Arg
10186 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10187 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
10190 if In_Instance
then
10192 or else (not Is_Overloaded
(Arg
)
10193 and then Etype
(Arg
) /= Any_Composite
10194 and then Covers
(Ctyp
, Etype
(Arg
)))
10196 Resolve
(Arg
, Ctyp
);
10198 Resolve
(Arg
, Btyp
);
10201 -- If both Array & Array and Array & Component are visible, there is a
10202 -- potential ambiguity that must be reported.
10204 elsif Has_Compatible_Type
(Arg
, Ctyp
) then
10205 if Nkind
(Arg
) = N_Aggregate
10206 and then Is_Composite_Type
(Ctyp
)
10208 if Is_Private_Type
(Ctyp
) then
10209 Resolve
(Arg
, Btyp
);
10211 -- If the operation is user-defined and not overloaded use its
10212 -- profile. The operation may be a renaming, in which case it has
10213 -- been rewritten, and we want the original profile.
10215 elsif not Is_Overloaded
(N
)
10216 and then Comes_From_Source
(Entity
(Original_Node
(N
)))
10217 and then Ekind
(Entity
(Original_Node
(N
))) = E_Function
10221 (Next_Formal
(First_Formal
(Entity
(Original_Node
(N
))))));
10224 -- Otherwise an aggregate may match both the array type and the
10228 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
10229 Set_Etype
(Arg
, Any_Type
);
10233 if Is_Overloaded
(Arg
)
10234 and then Has_Compatible_Type
(Arg
, Typ
)
10235 and then Etype
(Arg
) /= Any_Type
10243 Get_First_Interp
(Arg
, I
, It
);
10245 Get_Next_Interp
(I
, It
);
10247 -- Special-case the error message when the overloading is
10248 -- caused by a function that yields an array and can be
10249 -- called without parameters.
10251 if It
.Nam
= Func
then
10252 Error_Msg_Sloc
:= Sloc
(Func
);
10253 Error_Msg_N
("ambiguous call to function#", Arg
);
10255 ("\\interpretation as call yields&", Arg
, Typ
);
10257 ("\\interpretation as indexing of call yields&",
10261 Error_Msg_N
("ambiguous operand for concatenation!", Arg
);
10263 Get_First_Interp
(Arg
, I
, It
);
10264 while Present
(It
.Nam
) loop
10265 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
10267 if Base_Type
(It
.Typ
) = Btyp
10269 Base_Type
(It
.Typ
) = Base_Type
(Ctyp
)
10271 Error_Msg_N
-- CODEFIX
10272 ("\\possible interpretation#", Arg
);
10275 Get_Next_Interp
(I
, It
);
10281 Resolve
(Arg
, Ctyp
);
10283 if Nkind
(Arg
) = N_String_Literal
then
10284 Set_Etype
(Arg
, Ctyp
);
10286 elsif Is_Scalar_Type
(Etype
(Arg
))
10287 and then Compile_Time_Known_Value
(Arg
)
10289 -- Determine if the out-of-range violation constitutes a
10290 -- warning or an error according to the expression base type,
10291 -- according to Ada 2022 RM 4.9 (35/2).
10293 if Is_Out_Of_Range
(Arg
, Base_Type
(Ctyp
)) then
10294 Apply_Compile_Time_Constraint_Error
10295 (Arg
, "value not in range of}", CE_Range_Check_Failed
,
10296 Ent
=> Base_Type
(Ctyp
),
10297 Typ
=> Base_Type
(Ctyp
));
10299 elsif Is_Out_Of_Range
(Arg
, Ctyp
) then
10300 Apply_Compile_Time_Constraint_Error
10301 (Arg
, "value not in range of}??", CE_Range_Check_Failed
,
10307 if Arg
= Left_Opnd
(N
) then
10308 Set_Is_Component_Left_Opnd
(N
);
10310 Set_Is_Component_Right_Opnd
(N
);
10315 Resolve
(Arg
, Btyp
);
10318 Check_Unset_Reference
(Arg
);
10319 end Resolve_Op_Concat_Arg
;
10321 -----------------------------
10322 -- Resolve_Op_Concat_First --
10323 -----------------------------
10325 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
10326 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
10327 Op1
: constant Node_Id
:= Left_Opnd
(N
);
10328 Op2
: constant Node_Id
:= Right_Opnd
(N
);
10331 -- The parser folds an enormous sequence of concatenations of string
10332 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
10333 -- in the right operand. If the expression resolves to a predefined "&"
10334 -- operator, all is well. Otherwise, the parser's folding is wrong, so
10335 -- we give an error. See P_Simple_Expression in Par.Ch4.
10337 if Nkind
(Op2
) = N_String_Literal
10338 and then Is_Folded_In_Parser
(Op2
)
10339 and then Ekind
(Entity
(N
)) = E_Function
10341 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
10342 and then String_Length
(Strval
(Op1
)) = 0);
10343 Error_Msg_N
("too many user-defined concatenations", N
);
10347 Set_Etype
(N
, Btyp
);
10349 if Is_Limited_Composite
(Btyp
) then
10350 Error_Msg_N
("concatenation not available for limited array", N
);
10351 Explain_Limited_Type
(Btyp
, N
);
10353 end Resolve_Op_Concat_First
;
10355 ----------------------------
10356 -- Resolve_Op_Concat_Rest --
10357 ----------------------------
10359 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
10360 Op1
: constant Node_Id
:= Left_Opnd
(N
);
10361 Op2
: constant Node_Id
:= Right_Opnd
(N
);
10364 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
10366 Generate_Operator_Reference
(N
, Typ
);
10368 if Is_String_Type
(Typ
) then
10369 Eval_Concatenation
(N
);
10372 -- If this is not a static concatenation, but the result is a string
10373 -- type (and not an array of strings) ensure that static string operands
10374 -- have their subtypes properly constructed.
10376 if Nkind
(N
) /= N_String_Literal
10377 and then Is_Character_Type
(Component_Type
(Typ
))
10379 Set_String_Literal_Subtype
(Op1
, Typ
);
10380 Set_String_Literal_Subtype
(Op2
, Typ
);
10382 end Resolve_Op_Concat_Rest
;
10384 ----------------------
10385 -- Resolve_Op_Expon --
10386 ----------------------
10388 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
10389 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10392 -- Catch attempts to do fixed-point exponentiation with universal
10393 -- operands, which is a case where the illegality is not caught during
10394 -- normal operator analysis. This is not done in preanalysis mode
10395 -- since the tree is not fully decorated during preanalysis.
10397 if Full_Analysis
then
10398 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
10399 Error_Msg_N
("exponentiation not available for fixed point", N
);
10402 elsif Nkind
(Parent
(N
)) in N_Op
10403 and then Present
(Etype
(Parent
(N
)))
10404 and then Is_Fixed_Point_Type
(Etype
(Parent
(N
)))
10405 and then Etype
(N
) = Universal_Real
10406 and then Comes_From_Source
(N
)
10408 Error_Msg_N
("exponentiation not available for fixed point", N
);
10413 if Comes_From_Source
(N
)
10414 and then Ekind
(Entity
(N
)) = E_Function
10415 and then Is_Imported
(Entity
(N
))
10416 and then Is_Intrinsic_Subprogram
(Entity
(N
))
10418 Resolve_Intrinsic_Operator
(N
, Typ
);
10422 if Is_Universal_Numeric_Type
(Etype
(Left_Opnd
(N
))) then
10423 Check_For_Visible_Operator
(N
, B_Typ
);
10426 -- We do the resolution using the base type, because intermediate values
10427 -- in expressions are always of the base type, not a subtype of it.
10429 Resolve
(Left_Opnd
(N
), B_Typ
);
10430 Resolve
(Right_Opnd
(N
), Standard_Integer
);
10432 -- For integer types, right argument must be in Natural range
10434 if Is_Integer_Type
(Typ
) then
10435 Apply_Scalar_Range_Check
(Right_Opnd
(N
), Standard_Natural
);
10438 Check_Unset_Reference
(Left_Opnd
(N
));
10439 Check_Unset_Reference
(Right_Opnd
(N
));
10441 Set_Etype
(N
, B_Typ
);
10442 Generate_Operator_Reference
(N
, B_Typ
);
10444 Analyze_Dimension
(N
);
10446 if Ada_Version
>= Ada_2012
and then Has_Dimension_System
(B_Typ
) then
10447 -- Evaluate the exponentiation operator for dimensioned type
10449 Eval_Op_Expon_For_Dimensioned_Type
(N
, B_Typ
);
10454 -- Set overflow checking bit. Much cleverer code needed here eventually
10455 -- and perhaps the Resolve routines should be separated for the various
10456 -- arithmetic operations, since they will need different processing. ???
10458 if Nkind
(N
) in N_Op
then
10459 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
10460 Enable_Overflow_Check
(N
);
10463 end Resolve_Op_Expon
;
10465 --------------------
10466 -- Resolve_Op_Not --
10467 --------------------
10469 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
10470 function Parent_Is_Boolean
return Boolean;
10471 -- This function determines if the parent node is a boolean operator or
10472 -- operation (comparison op, membership test, or short circuit form) and
10473 -- the not in question is the left operand of this operation. Note that
10474 -- if the not is in parens, then false is returned.
10476 -----------------------
10477 -- Parent_Is_Boolean --
10478 -----------------------
10480 function Parent_Is_Boolean
return Boolean is
10482 return Paren_Count
(N
) = 0
10483 and then Nkind
(Parent
(N
)) in N_Membership_Test
10486 and then Left_Opnd
(Parent
(N
)) = N
;
10487 end Parent_Is_Boolean
;
10493 -- Start of processing for Resolve_Op_Not
10496 -- Predefined operations on scalar types yield the base type. On the
10497 -- other hand, logical operations on arrays yield the type of the
10498 -- arguments (and the context).
10500 if Is_Array_Type
(Typ
) then
10503 B_Typ
:= Base_Type
(Typ
);
10506 -- Straightforward case of incorrect arguments
10508 if not Valid_Boolean_Arg
(Typ
) then
10509 Error_Msg_N
("invalid operand type for operator&", N
);
10510 Set_Etype
(N
, Any_Type
);
10513 -- Special case of probable missing parens
10515 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
10516 if Parent_Is_Boolean
then
10518 ("operand of NOT must be enclosed in parentheses",
10522 ("no modular type available in this context", N
);
10525 Set_Etype
(N
, Any_Type
);
10528 -- OK resolution of NOT
10531 -- Warn if non-boolean types involved. This is a case like not a < b
10532 -- where a and b are modular, where we will get (not a) < b and most
10533 -- likely not (a < b) was intended.
10535 if Warn_On_Questionable_Missing_Parens
10536 and then not Is_Boolean_Type
(Typ
)
10537 and then Parent_Is_Boolean
10539 Error_Msg_N
("?q?not expression should be parenthesized here!", N
);
10542 -- Warn on double negation if checking redundant constructs
10544 if Warn_On_Redundant_Constructs
10545 and then Comes_From_Source
(N
)
10546 and then Comes_From_Source
(Right_Opnd
(N
))
10547 and then Root_Type
(Typ
) = Standard_Boolean
10548 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
10550 Error_Msg_N
("redundant double negation?r?", N
);
10553 -- Complete resolution and evaluation of NOT
10555 Resolve
(Right_Opnd
(N
), B_Typ
);
10556 Check_Unset_Reference
(Right_Opnd
(N
));
10557 Set_Etype
(N
, B_Typ
);
10558 Generate_Operator_Reference
(N
, B_Typ
);
10561 end Resolve_Op_Not
;
10563 -----------------------------
10564 -- Resolve_Operator_Symbol --
10565 -----------------------------
10567 -- Nothing to be done, all resolved already
10569 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
10570 pragma Warnings
(Off
, N
);
10571 pragma Warnings
(Off
, Typ
);
10575 end Resolve_Operator_Symbol
;
10577 ----------------------------------
10578 -- Resolve_Qualified_Expression --
10579 ----------------------------------
10581 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
10582 pragma Warnings
(Off
, Typ
);
10584 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
10585 Expr
: constant Node_Id
:= Expression
(N
);
10588 Resolve
(Expr
, Target_Typ
);
10590 -- A qualified expression requires an exact match of the type, class-
10591 -- wide matching is not allowed. However, if the qualifying type is
10592 -- specific and the expression has a class-wide type, it may still be
10593 -- okay, since it can be the result of the expansion of a call to a
10594 -- dispatching function, so we also have to check class-wideness of the
10595 -- type of the expression's original node.
10597 if (Is_Class_Wide_Type
(Target_Typ
)
10599 (Is_Class_Wide_Type
(Etype
(Expr
))
10600 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
10601 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
10603 Wrong_Type
(Expr
, Target_Typ
);
10606 -- If the target type is unconstrained, then we reset the type of the
10607 -- result from the type of the expression. For other cases, the actual
10608 -- subtype of the expression is the target type. But we avoid doing it
10609 -- for an allocator since this is not needed and might be problematic.
10611 if Is_Composite_Type
(Target_Typ
)
10612 and then not Is_Constrained
(Target_Typ
)
10613 and then Nkind
(Parent
(N
)) /= N_Allocator
10615 Set_Etype
(N
, Etype
(Expr
));
10618 Analyze_Dimension
(N
);
10619 Eval_Qualified_Expression
(N
);
10621 -- If we still have a qualified expression after the static evaluation,
10622 -- then apply a scalar range check if needed. The reason that we do this
10623 -- after the Eval call is that otherwise, the application of the range
10624 -- check may convert an illegal static expression and result in warning
10625 -- rather than giving an error (e.g Integer'(Integer'Last + 1)).
10627 if Nkind
(N
) = N_Qualified_Expression
10628 and then Is_Scalar_Type
(Target_Typ
)
10630 Apply_Scalar_Range_Check
(Expr
, Target_Typ
);
10633 -- AI12-0100: Once the qualified expression is resolved, check whether
10634 -- operand satisfies a static predicate of the target subtype, if any.
10635 -- In the static expression case, a predicate check failure is an error.
10637 if Has_Predicates
(Target_Typ
) then
10638 Check_Expression_Against_Static_Predicate
10639 (Expr
, Target_Typ
, Static_Failure_Is_Error
=> True);
10641 end Resolve_Qualified_Expression
;
10643 ------------------------------
10644 -- Resolve_Raise_Expression --
10645 ------------------------------
10647 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
10649 if Typ
= Raise_Type
then
10650 Error_Msg_N
("cannot find unique type for raise expression", N
);
10651 Set_Etype
(N
, Any_Type
);
10654 Set_Etype
(N
, Typ
);
10656 -- Apply check for required parentheses in the enclosing
10657 -- context of raise_expressions (RM 11.3 (2)), including default
10658 -- expressions in contexts that can include aspect specifications,
10659 -- and ancestor parts of extension aggregates.
10662 Par
: Node_Id
:= Parent
(N
);
10663 Parentheses_Found
: Boolean := Paren_Count
(N
) > 0;
10666 while Present
(Par
)
10667 and then Nkind
(Par
) in N_Has_Etype
10669 if Paren_Count
(Par
) > 0 then
10670 Parentheses_Found
:= True;
10673 if Nkind
(Par
) = N_Extension_Aggregate
10674 and then N
= Ancestor_Part
(Par
)
10679 Par
:= Parent
(Par
);
10682 if not Parentheses_Found
10683 and then Comes_From_Source
(Par
)
10685 ((Nkind
(Par
) in N_Modular_Type_Definition
10686 | N_Floating_Point_Definition
10687 | N_Ordinary_Fixed_Point_Definition
10688 | N_Decimal_Fixed_Point_Definition
10689 | N_Extension_Aggregate
10690 | N_Discriminant_Specification
10691 | N_Parameter_Specification
10692 | N_Formal_Object_Declaration
)
10694 or else (Nkind
(Par
) = N_Object_Declaration
10696 Nkind
(Parent
(Par
)) /= N_Extended_Return_Statement
))
10699 ("raise_expression must be parenthesized in this context",
10704 end Resolve_Raise_Expression
;
10706 -------------------
10707 -- Resolve_Range --
10708 -------------------
10710 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
10711 L
: constant Node_Id
:= Low_Bound
(N
);
10712 H
: constant Node_Id
:= High_Bound
(N
);
10714 function First_Last_Ref
return Boolean;
10715 -- Returns True if N is of the form X'First .. X'Last where X is the
10716 -- same entity for both attributes.
10718 --------------------
10719 -- First_Last_Ref --
10720 --------------------
10722 function First_Last_Ref
return Boolean is
10723 Lorig
: constant Node_Id
:= Original_Node
(L
);
10724 Horig
: constant Node_Id
:= Original_Node
(H
);
10727 if Nkind
(Lorig
) = N_Attribute_Reference
10728 and then Nkind
(Horig
) = N_Attribute_Reference
10729 and then Attribute_Name
(Lorig
) = Name_First
10730 and then Attribute_Name
(Horig
) = Name_Last
10733 PL
: constant Node_Id
:= Prefix
(Lorig
);
10734 PH
: constant Node_Id
:= Prefix
(Horig
);
10736 return Is_Entity_Name
(PL
)
10737 and then Is_Entity_Name
(PH
)
10738 and then Entity
(PL
) = Entity
(PH
);
10743 end First_Last_Ref
;
10745 -- Start of processing for Resolve_Range
10748 Set_Etype
(N
, Typ
);
10753 -- Reanalyze the lower bound after both bounds have been analyzed, so
10754 -- that the range is known to be static or not by now. This may trigger
10755 -- more compile-time evaluation, which is useful for static analysis
10756 -- with GNATprove. This is not needed for compilation or static analysis
10757 -- with CodePeer, as full expansion does that evaluation then.
10759 if GNATprove_Mode
then
10760 Set_Analyzed
(L
, False);
10764 -- Check for inappropriate range on unordered enumeration type
10766 if Bad_Unordered_Enumeration_Reference
(N
, Typ
)
10768 -- Exclude X'First .. X'Last if X is the same entity for both
10770 and then not First_Last_Ref
10772 Error_Msg_Sloc
:= Sloc
(Typ
);
10774 ("subrange of unordered enumeration type& declared#?.u?", N
, Typ
);
10777 Check_Unset_Reference
(L
);
10778 Check_Unset_Reference
(H
);
10780 -- We have to check the bounds for being within the base range as
10781 -- required for a non-static context. Normally this is automatic and
10782 -- done as part of evaluating expressions, but the N_Range node is an
10783 -- exception, since in GNAT we consider this node to be a subexpression,
10784 -- even though in Ada it is not. The circuit in Sem_Eval could check for
10785 -- this, but that would put the test on the main evaluation path for
10788 Check_Non_Static_Context
(L
);
10789 Check_Non_Static_Context
(H
);
10791 -- Check for an ambiguous range over character literals. This will
10792 -- happen with a membership test involving only literals.
10794 if Typ
= Any_Character
then
10795 Ambiguous_Character
(L
);
10796 Set_Etype
(N
, Any_Type
);
10800 -- If bounds are static, constant-fold them, so size computations are
10801 -- identical between front-end and back-end. Do not perform this
10802 -- transformation while analyzing generic units, as type information
10803 -- would be lost when reanalyzing the constant node in the instance.
10805 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
10806 if Is_OK_Static_Expression
(L
) then
10807 Fold_Uint
(L
, Expr_Value
(L
), Static
=> True);
10810 if Is_OK_Static_Expression
(H
) then
10811 Fold_Uint
(H
, Expr_Value
(H
), Static
=> True);
10815 -- If we have a compile-time-known null range, we warn, because that is
10816 -- likely to be a mistake. (Dynamic null ranges make sense, but often
10817 -- compile-time-known ones do not.) Warn only if this is in a subtype
10818 -- declaration. We do this here, rather than while analyzing a subtype
10819 -- declaration, in case we decide to expand the cases. We do not want to
10820 -- warn in all cases, because some are idiomatic, such as an empty
10821 -- aggregate (1 .. 0 => <>).
10823 -- We don't warn in generics or their instances, because there might be
10824 -- some instances where the range is null, and some where it is not,
10825 -- which would lead to false alarms.
10827 if not (Inside_A_Generic
or In_Instance
)
10828 and then Comes_From_Source
(N
)
10829 and then Compile_Time_Compare
10830 (Low_Bound
(N
), High_Bound
(N
), Assume_Valid
=> True) = GT
10831 and then Nkind
(Parent
(N
)) = N_Range_Constraint
10832 and then Nkind
(Parent
(Parent
(N
))) = N_Subtype_Indication
10833 and then Nkind
(Parent
(Parent
(Parent
(N
)))) = N_Subtype_Declaration
10834 and then Is_OK_Static_Range
(N
)
10836 Error_Msg_N
("null range??", N
);
10840 --------------------------
10841 -- Resolve_Real_Literal --
10842 --------------------------
10844 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
10845 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
10848 -- Special processing for fixed-point literals to make sure that the
10849 -- value is an exact multiple of the small where this is required. We
10850 -- skip this for the universal real case, and also for generic types.
10852 if Is_Fixed_Point_Type
(Typ
)
10853 and then Typ
/= Universal_Fixed
10854 and then Typ
/= Any_Fixed
10855 and then not Is_Generic_Type
(Typ
)
10857 -- We must freeze the base type to get the proper value of the small
10859 if not Is_Frozen
(Base_Type
(Typ
)) then
10860 Freeze_Fixed_Point_Type
(Base_Type
(Typ
));
10864 Val
: constant Ureal
:= Realval
(N
);
10865 Cintr
: constant Ureal
:= Val
/ Small_Value
(Base_Type
(Typ
));
10866 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
10867 Den
: constant Uint
:= Norm_Den
(Cintr
);
10871 -- Case of literal is not an exact multiple of the Small
10875 -- For a source program literal for a decimal fixed-point type,
10876 -- this is statically illegal (RM 4.9(36)).
10878 if Is_Decimal_Fixed_Point_Type
(Typ
)
10879 and then Actual_Typ
= Universal_Real
10880 and then Comes_From_Source
(N
)
10882 Error_Msg_N
("value has extraneous low order digits", N
);
10885 -- Generate a warning if literal from source
10887 if Is_OK_Static_Expression
(N
)
10888 and then Warn_On_Bad_Fixed_Value
10891 ("?b?static fixed-point value is not a multiple of Small!",
10895 -- Replace literal by a value that is the exact representation
10896 -- of a value of the type, i.e. a multiple of the small value,
10897 -- by truncation, since Machine_Rounds is false for all GNAT
10898 -- fixed-point types (RM 4.9(38)).
10900 Stat
:= Is_OK_Static_Expression
(N
);
10902 Make_Real_Literal
(Sloc
(N
),
10903 Realval
=> Small_Value
(Typ
) * Cint
));
10905 Set_Is_Static_Expression
(N
, Stat
);
10908 -- In all cases, set the corresponding integer field
10910 Set_Corresponding_Integer_Value
(N
, Cint
);
10914 -- Now replace the actual type by the expected type as usual
10916 Set_Etype
(N
, Typ
);
10917 Eval_Real_Literal
(N
);
10918 end Resolve_Real_Literal
;
10920 -----------------------
10921 -- Resolve_Reference --
10922 -----------------------
10924 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
10925 P
: constant Node_Id
:= Prefix
(N
);
10928 -- Replace general access with specific type
10930 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
10931 Set_Etype
(N
, Base_Type
(Typ
));
10934 Resolve
(P
, Designated_Type
(Etype
(N
)));
10936 -- If we are taking the reference of a volatile entity, then treat it as
10937 -- a potential modification of this entity. This is too conservative,
10938 -- but necessary because remove side effects can cause transformations
10939 -- of normal assignments into reference sequences that otherwise fail to
10940 -- notice the modification.
10942 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
10943 Note_Possible_Modification
(P
, Sure
=> False);
10945 end Resolve_Reference
;
10947 --------------------------------
10948 -- Resolve_Selected_Component --
10949 --------------------------------
10951 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
10953 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
10954 P
: constant Node_Id
:= Prefix
(N
);
10955 S
: constant Node_Id
:= Selector_Name
(N
);
10956 T
: Entity_Id
:= Etype
(P
);
10958 I1
: Interp_Index
:= 0; -- prevent junk warning
10963 function Init_Component
return Boolean;
10964 -- Check whether this is the initialization of a component within an
10965 -- init proc (by assignment or call to another init proc). If true,
10966 -- there is no need for a discriminant check.
10968 --------------------
10969 -- Init_Component --
10970 --------------------
10972 function Init_Component
return Boolean is
10974 return Inside_Init_Proc
10975 and then Nkind
(Prefix
(N
)) = N_Identifier
10976 and then Chars
(Prefix
(N
)) = Name_uInit
10977 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
10978 end Init_Component
;
10980 -- Start of processing for Resolve_Selected_Component
10983 if Is_Overloaded
(P
) then
10985 -- Use the context type to select the prefix that has a selector
10986 -- of the correct name and type.
10989 Get_First_Interp
(P
, I
, It
);
10991 Search
: while Present
(It
.Typ
) loop
10992 if Is_Access_Type
(It
.Typ
) then
10993 T
:= Designated_Type
(It
.Typ
);
10998 -- Locate selected component. For a private prefix the selector
10999 -- can denote a discriminant.
11001 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
11003 -- The visible components of a class-wide type are those of
11006 if Is_Class_Wide_Type
(T
) then
11010 Comp
:= First_Entity
(T
);
11011 while Present
(Comp
) loop
11012 if Chars
(Comp
) = Chars
(S
)
11013 and then Covers
(Typ
, Etype
(Comp
))
11022 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
11024 if It
= No_Interp
then
11026 ("ambiguous prefix for selected component", N
);
11027 Set_Etype
(N
, Typ
);
11033 -- There may be an implicit dereference. Retrieve
11034 -- designated record type.
11036 if Is_Access_Type
(It1
.Typ
) then
11037 T
:= Designated_Type
(It1
.Typ
);
11042 if Scope
(Comp1
) /= T
then
11044 -- Resolution chooses the new interpretation.
11045 -- Find the component with the right name.
11047 Comp1
:= First_Entity
(T
);
11048 while Present
(Comp1
)
11049 and then Chars
(Comp1
) /= Chars
(S
)
11051 Next_Entity
(Comp1
);
11060 Next_Entity
(Comp
);
11064 Get_Next_Interp
(I
, It
);
11067 -- There must be a legal interpretation at this point
11069 pragma Assert
(Found
);
11070 Resolve
(P
, It1
.Typ
);
11072 -- In general the expected type is the type of the context, not the
11073 -- type of the candidate selected component.
11075 Set_Etype
(N
, Typ
);
11076 Set_Entity_With_Checks
(S
, Comp1
);
11078 -- The type of the context and that of the component are
11079 -- compatible and in general identical, but if they are anonymous
11080 -- access-to-subprogram types, the relevant type is that of the
11081 -- component. This matters in Unnest_Subprograms mode, where the
11082 -- relevant context is the one in which the type is declared, not
11083 -- the point of use. This determines what activation record to use.
11085 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
11086 Set_Etype
(N
, Etype
(Comp1
));
11088 -- When the type of the component is an access to a class-wide type
11089 -- the relevant type is that of the component (since in such case we
11090 -- may need to generate implicit type conversions or dispatching
11093 elsif Is_Access_Type
(Typ
)
11094 and then not Is_Class_Wide_Type
(Designated_Type
(Typ
))
11095 and then Is_Class_Wide_Type
(Designated_Type
(Etype
(Comp1
)))
11097 Set_Etype
(N
, Etype
(Comp1
));
11101 -- Resolve prefix with its type
11106 -- Generate cross-reference. We needed to wait until full overloading
11107 -- resolution was complete to do this, since otherwise we can't tell if
11108 -- we are an lvalue or not.
11110 if Known_To_Be_Assigned
(N
) then
11111 Generate_Reference
(Entity
(S
), S
, 'm');
11113 Generate_Reference
(Entity
(S
), S
, 'r');
11116 -- If the prefix's type is an access type, get to the real record type.
11117 -- Note: we do not apply an access check because an explicit dereference
11118 -- will be introduced later, and the check will happen there.
11120 if Is_Access_Type
(Etype
(P
)) then
11121 T
:= Implicitly_Designated_Type
(Etype
(P
));
11122 Check_Fully_Declared_Prefix
(T
, P
);
11127 -- If the prefix is an entity it may have a deferred reference set
11128 -- during analysis of the selected component. After resolution we
11129 -- can transform it into a proper reference. This prevents spurious
11130 -- warnings on useless assignments when the same selected component
11131 -- is the actual for an out parameter in a subsequent call.
11133 if Is_Entity_Name
(P
)
11134 and then Has_Deferred_Reference
(Entity
(P
))
11136 if Known_To_Be_Assigned
(N
) then
11137 Generate_Reference
(Entity
(P
), P
, 'm');
11139 Generate_Reference
(Entity
(P
), P
, 'r');
11144 -- Set flag for expander if discriminant check required on a component
11145 -- appearing within a variant.
11147 if Has_Discriminants
(T
)
11148 and then Ekind
(Entity
(S
)) = E_Component
11149 and then Present
(Original_Record_Component
(Entity
(S
)))
11150 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
11152 Is_Declared_Within_Variant
(Original_Record_Component
(Entity
(S
)))
11153 and then not Discriminant_Checks_Suppressed
(T
)
11154 and then not Init_Component
11156 Set_Do_Discriminant_Check
(N
);
11159 if Ekind
(Entity
(S
)) = E_Void
then
11160 Error_Msg_N
("premature use of component", S
);
11163 -- If the prefix is a record conversion, this may be a renamed
11164 -- discriminant whose bounds differ from those of the original
11165 -- one, so we must ensure that a range check is performed.
11167 if Nkind
(P
) = N_Type_Conversion
11168 and then Ekind
(Entity
(S
)) = E_Discriminant
11169 and then Is_Discrete_Type
(Typ
)
11171 Set_Etype
(N
, Base_Type
(Typ
));
11174 -- Eval_Selected_Component may e.g. fold statically known discriminants.
11176 Eval_Selected_Component
(N
);
11178 if Nkind
(N
) = N_Selected_Component
then
11180 -- If the record type is atomic and the component is not, then this
11181 -- is worth a warning before Ada 2022, since we have a situation
11182 -- where the access to the component may cause extra read/writes of
11183 -- the atomic object, or partial word accesses, both of which may be
11186 if Is_Atomic_Ref_With_Address
(N
)
11187 and then not Is_Atomic
(Entity
(S
))
11188 and then not Is_Atomic
(Etype
(Entity
(S
)))
11189 and then Ada_Version
< Ada_2022
11192 ("??access to non-atomic component of atomic record",
11195 ("\??may cause unexpected accesses to atomic object",
11199 Resolve_Implicit_Dereference
(Prefix
(N
));
11200 Analyze_Dimension
(N
);
11202 end Resolve_Selected_Component
;
11204 -------------------
11205 -- Resolve_Shift --
11206 -------------------
11208 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
11209 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11210 L
: constant Node_Id
:= Left_Opnd
(N
);
11211 R
: constant Node_Id
:= Right_Opnd
(N
);
11214 -- We do the resolution using the base type, because intermediate values
11215 -- in expressions always are of the base type, not a subtype of it.
11217 Resolve
(L
, B_Typ
);
11218 Resolve
(R
, Standard_Natural
);
11220 Check_Unset_Reference
(L
);
11221 Check_Unset_Reference
(R
);
11223 Set_Etype
(N
, B_Typ
);
11224 Generate_Operator_Reference
(N
, B_Typ
);
11228 ---------------------------
11229 -- Resolve_Short_Circuit --
11230 ---------------------------
11232 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
11233 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
11234 L
: constant Node_Id
:= Left_Opnd
(N
);
11235 R
: constant Node_Id
:= Right_Opnd
(N
);
11238 -- Ensure all actions associated with the left operand (e.g.
11239 -- finalization of transient objects) are fully evaluated locally within
11240 -- an expression with actions. This is particularly helpful for coverage
11241 -- analysis. However this should not happen in generics or if option
11242 -- Minimize_Expression_With_Actions is set.
11244 if Expander_Active
and not Minimize_Expression_With_Actions
then
11246 Reloc_L
: constant Node_Id
:= Relocate_Node
(L
);
11248 Save_Interps
(Old_N
=> L
, New_N
=> Reloc_L
);
11251 Make_Expression_With_Actions
(Sloc
(L
),
11252 Actions
=> New_List
,
11253 Expression
=> Reloc_L
));
11255 -- Set Comes_From_Source on L to preserve warnings for unset
11258 Preserve_Comes_From_Source
(L
, Reloc_L
);
11262 Resolve
(L
, B_Typ
);
11263 Resolve
(R
, B_Typ
);
11265 -- Check for issuing warning for always False assert/check, this happens
11266 -- when assertions are turned off, in which case the pragma Assert/Check
11267 -- was transformed into:
11269 -- if False and then <condition> then ...
11271 -- and we detect this pattern
11273 if Warn_On_Assertion_Failure
11274 and then Is_Entity_Name
(R
)
11275 and then Entity
(R
) = Standard_False
11276 and then Nkind
(Parent
(N
)) = N_If_Statement
11277 and then Nkind
(N
) = N_And_Then
11278 and then Is_Entity_Name
(L
)
11279 and then Entity
(L
) = Standard_False
11282 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
11285 -- Special handling of Asssert pragma
11287 if Nkind
(Orig
) = N_Pragma
11288 and then Pragma_Name
(Orig
) = Name_Assert
11291 Expr
: constant Node_Id
:=
11294 (First
(Pragma_Argument_Associations
(Orig
))));
11297 -- Don't warn if original condition is explicit False,
11298 -- since obviously the failure is expected in this case.
11300 if Is_Entity_Name
(Expr
)
11301 and then Entity
(Expr
) = Standard_False
11305 -- Issue warning. We do not want the deletion of the
11306 -- IF/AND-THEN to take this message with it. We achieve this
11307 -- by making sure that the expanded code points to the Sloc
11308 -- of the expression, not the original pragma.
11311 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
11312 -- The source location of the expression is not usually
11313 -- the best choice here. For example, it gets located on
11314 -- the last AND keyword in a chain of boolean expressiond
11315 -- AND'ed together. It is best to put the message on the
11316 -- first character of the assertion, which is the effect
11317 -- of the First_Node call here.
11320 ("?.a?assertion would fail at run time!",
11322 (First
(Pragma_Argument_Associations
(Orig
))));
11326 -- Similar processing for Check pragma
11328 elsif Nkind
(Orig
) = N_Pragma
11329 and then Pragma_Name
(Orig
) = Name_Check
11331 -- Don't want to warn if original condition is explicit False
11334 Expr
: constant Node_Id
:=
11337 (Next
(First
(Pragma_Argument_Associations
(Orig
)))));
11339 if Is_Entity_Name
(Expr
)
11340 and then Entity
(Expr
) = Standard_False
11347 -- Again use Error_Msg_F rather than Error_Msg_N, see
11348 -- comment above for an explanation of why we do this.
11351 ("?.a?check would fail at run time!",
11353 (Last
(Pragma_Argument_Associations
(Orig
))));
11360 -- Continue with processing of short circuit
11362 Check_Unset_Reference
(L
);
11363 Check_Unset_Reference
(R
);
11365 Set_Etype
(N
, B_Typ
);
11366 Eval_Short_Circuit
(N
);
11367 end Resolve_Short_Circuit
;
11369 -------------------
11370 -- Resolve_Slice --
11371 -------------------
11373 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
11374 Drange
: constant Node_Id
:= Discrete_Range
(N
);
11375 Pref
: constant Node_Id
:= Prefix
(N
);
11376 Array_Type
: Entity_Id
:= Empty
;
11377 Dexpr
: Node_Id
:= Empty
;
11378 Index_Type
: Entity_Id
;
11381 if Is_Overloaded
(Pref
) then
11383 -- Use the context type to select the prefix that yields the correct
11388 I1
: Interp_Index
:= 0;
11390 Found
: Boolean := False;
11393 Get_First_Interp
(Pref
, I
, It
);
11394 while Present
(It
.Typ
) loop
11395 if (Is_Array_Type
(It
.Typ
)
11396 and then Covers
(Typ
, It
.Typ
))
11397 or else (Is_Access_Type
(It
.Typ
)
11398 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
11399 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
11402 It
:= Disambiguate
(Pref
, I1
, I
, Any_Type
);
11404 if It
= No_Interp
then
11405 Error_Msg_N
("ambiguous prefix for slicing", N
);
11406 Set_Etype
(N
, Typ
);
11410 Array_Type
:= It
.Typ
;
11415 Array_Type
:= It
.Typ
;
11420 Get_Next_Interp
(I
, It
);
11425 Array_Type
:= Etype
(Pref
);
11428 Resolve
(Pref
, Array_Type
);
11430 -- If the prefix's type is an access type, get to the real array type.
11431 -- Note: we do not apply an access check because an explicit dereference
11432 -- will be introduced later, and the check will happen there.
11434 if Is_Access_Type
(Array_Type
) then
11435 Array_Type
:= Implicitly_Designated_Type
(Array_Type
);
11437 -- If the prefix is an access to an unconstrained array, we must use
11438 -- the actual subtype of the object to perform the index checks. The
11439 -- object denoted by the prefix is implicit in the node, so we build
11440 -- an explicit representation for it in order to compute the actual
11443 if not Is_Constrained
(Array_Type
) then
11444 Remove_Side_Effects
(Pref
);
11447 Obj
: constant Node_Id
:=
11448 Make_Explicit_Dereference
(Sloc
(N
),
11449 Prefix
=> New_Copy_Tree
(Pref
));
11451 Set_Etype
(Obj
, Array_Type
);
11452 Set_Parent
(Obj
, Parent
(N
));
11453 Array_Type
:= Get_Actual_Subtype
(Obj
);
11457 -- In CodePeer mode the attribute Image is not expanded, so when it
11458 -- acts as a prefix of a slice, we handle it like a call to function
11459 -- returning an unconstrained string. Same for the Wide variants of
11460 -- attribute Image.
11462 elsif Is_Entity_Name
(Pref
)
11463 or else Nkind
(Pref
) = N_Explicit_Dereference
11464 or else (Nkind
(Pref
) = N_Function_Call
11465 and then not Is_Constrained
(Etype
(Pref
)))
11466 or else (CodePeer_Mode
11467 and then Nkind
(Pref
) = N_Attribute_Reference
11468 and then Attribute_Name
(Pref
) in Name_Image
11470 | Name_Wide_Wide_Image
)
11472 Array_Type
:= Get_Actual_Subtype
(Pref
);
11474 -- If the name is a selected component that depends on discriminants,
11475 -- build an actual subtype for it. This can happen only when the name
11476 -- itself is overloaded; otherwise the actual subtype is created when
11477 -- the selected component is analyzed.
11479 elsif Nkind
(Pref
) = N_Selected_Component
11480 and then Full_Analysis
11481 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
11484 Act_Decl
: constant Node_Id
:=
11485 Build_Actual_Subtype_Of_Component
(Array_Type
, Pref
);
11487 Insert_Action
(N
, Act_Decl
);
11488 Array_Type
:= Defining_Identifier
(Act_Decl
);
11491 -- Maybe this should just be "else", instead of checking for the
11492 -- specific case of slice??? This is needed for the case where the
11493 -- prefix is an Image attribute, which gets expanded to a slice, and so
11494 -- has a constrained subtype which we want to use for the slice range
11495 -- check applied below (the range check won't get done if the
11496 -- unconstrained subtype of the 'Image is used).
11498 elsif Nkind
(Pref
) = N_Slice
then
11499 Array_Type
:= Etype
(Pref
);
11502 -- Obtain the type of the array index
11504 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
11505 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
11507 Index_Type
:= Etype
(First_Index
(Array_Type
));
11510 -- If name was overloaded, set slice type correctly now
11512 Set_Etype
(N
, Array_Type
);
11514 -- Handle the generation of a range check that compares the array index
11515 -- against the discrete_range. The check is not applied to internally
11516 -- built nodes associated with the expansion of dispatch tables. Check
11517 -- that Ada.Tags has already been loaded to avoid extra dependencies on
11520 if Tagged_Type_Expansion
11521 and then RTU_Loaded
(Ada_Tags
)
11522 and then Nkind
(Pref
) = N_Selected_Component
11523 and then Present
(Entity
(Selector_Name
(Pref
)))
11524 and then Entity
(Selector_Name
(Pref
)) =
11525 RTE_Record_Component
(RE_Prims_Ptr
)
11529 -- The discrete_range is specified by a subtype name. Create an
11530 -- equivalent range attribute, apply checks to this attribute, but
11531 -- insert them into the range expression of the slice itself.
11533 elsif Is_Entity_Name
(Drange
) then
11535 Make_Attribute_Reference
11538 New_Occurrence_Of
(Entity
(Drange
), Sloc
(Drange
)),
11539 Attribute_Name
=> Name_Range
);
11541 Analyze_And_Resolve
(Dexpr
, Etype
(Drange
));
11543 elsif Nkind
(Drange
) = N_Subtype_Indication
then
11544 Dexpr
:= Range_Expression
(Constraint
(Drange
));
11546 -- The discrete_range is a regular range (or a range attribute, which
11547 -- will be resolved into a regular range). Resolve the bounds and remove
11548 -- their side effects.
11551 Resolve
(Drange
, Base_Type
(Index_Type
));
11553 if Nkind
(Drange
) = N_Range
then
11554 Force_Evaluation
(Low_Bound
(Drange
));
11555 Force_Evaluation
(High_Bound
(Drange
));
11561 if Present
(Dexpr
) then
11562 Apply_Range_Check
(Dexpr
, Index_Type
, Insert_Node
=> Drange
);
11565 Set_Slice_Subtype
(N
);
11567 -- Check bad use of type with predicates
11573 if Nkind
(Drange
) = N_Subtype_Indication
11574 and then Has_Predicates
(Entity
(Subtype_Mark
(Drange
)))
11576 Subt
:= Entity
(Subtype_Mark
(Drange
));
11578 Subt
:= Etype
(Drange
);
11581 if Has_Predicates
(Subt
) then
11582 Bad_Predicated_Subtype_Use
11583 ("subtype& has predicate, not allowed in slice", Drange
, Subt
);
11587 -- Otherwise here is where we check suspicious indexes
11589 if Nkind
(Drange
) = N_Range
then
11590 Warn_On_Suspicious_Index
(Pref
, Low_Bound
(Drange
));
11591 Warn_On_Suspicious_Index
(Pref
, High_Bound
(Drange
));
11594 Resolve_Implicit_Dereference
(Pref
);
11595 Analyze_Dimension
(N
);
11599 ----------------------------
11600 -- Resolve_String_Literal --
11601 ----------------------------
11603 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
11604 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
11605 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
11606 Loc
: constant Source_Ptr
:= Sloc
(N
);
11607 Str
: constant String_Id
:= Strval
(N
);
11608 Strlen
: constant Nat
:= String_Length
(Str
);
11609 Subtype_Id
: Entity_Id
;
11610 Need_Check
: Boolean;
11613 -- For a string appearing in a concatenation, defer creation of the
11614 -- string_literal_subtype until the end of the resolution of the
11615 -- concatenation, because the literal may be constant-folded away. This
11616 -- is a useful optimization for long concatenation expressions.
11618 -- If the string is an aggregate built for a single character (which
11619 -- happens in a non-static context) or a is null string to which special
11620 -- checks may apply, we build the subtype. Wide strings must also get a
11621 -- string subtype if they come from a one character aggregate. Strings
11622 -- generated by attributes might be static, but it is often hard to
11623 -- determine whether the enclosing context is static, so we generate
11624 -- subtypes for them as well, thus losing some rarer optimizations ???
11625 -- Same for strings that come from a static conversion.
11628 (Strlen
= 0 and then Typ
/= Standard_String
)
11629 or else Nkind
(Parent
(N
)) /= N_Op_Concat
11630 or else (N
/= Left_Opnd
(Parent
(N
))
11631 and then N
/= Right_Opnd
(Parent
(N
)))
11632 or else ((Typ
= Standard_Wide_String
11633 or else Typ
= Standard_Wide_Wide_String
)
11634 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
11636 -- If the resolving type is itself a string literal subtype, we can just
11637 -- reuse it, since there is no point in creating another.
11639 if Ekind
(Typ
) = E_String_Literal_Subtype
then
11642 elsif Nkind
(Parent
(N
)) = N_Op_Concat
11643 and then not Need_Check
11644 and then Nkind
(Original_Node
(N
)) not in N_Character_Literal
11645 | N_Attribute_Reference
11646 | N_Qualified_Expression
11647 | N_Type_Conversion
11651 -- Do not generate a string literal subtype for the default expression
11652 -- of a formal parameter in GNATprove mode. This is because the string
11653 -- subtype is associated with the freezing actions of the subprogram,
11654 -- however freezing is disabled in GNATprove mode and as a result the
11655 -- subtype is unavailable.
11657 elsif GNATprove_Mode
11658 and then Nkind
(Parent
(N
)) = N_Parameter_Specification
11662 -- Otherwise we must create a string literal subtype. Note that the
11663 -- whole idea of string literal subtypes is simply to avoid the need
11664 -- for building a full fledged array subtype for each literal.
11667 Set_String_Literal_Subtype
(N
, Typ
);
11668 Subtype_Id
:= Etype
(N
);
11671 if Nkind
(Parent
(N
)) /= N_Op_Concat
11674 Set_Etype
(N
, Subtype_Id
);
11675 Eval_String_Literal
(N
);
11678 if Is_Limited_Composite
(Typ
)
11679 or else Is_Private_Composite
(Typ
)
11681 Error_Msg_N
("string literal not available for private array", N
);
11682 Set_Etype
(N
, Any_Type
);
11686 -- The validity of a null string has been checked in the call to
11687 -- Eval_String_Literal.
11692 -- Always accept string literal with component type Any_Character, which
11693 -- occurs in error situations and in comparisons of literals, both of
11694 -- which should accept all literals.
11696 elsif R_Typ
= Any_Character
then
11699 -- If the type is bit-packed, then we always transform the string
11700 -- literal into a full fledged aggregate.
11702 elsif Is_Bit_Packed_Array
(Typ
) then
11705 -- Deal with cases of Wide_Wide_String, Wide_String, and String
11708 -- For Standard.Wide_Wide_String, or any other type whose component
11709 -- type is Standard.Wide_Wide_Character, we know that all the
11710 -- characters in the string must be acceptable, since the parser
11711 -- accepted the characters as valid character literals.
11713 if R_Typ
= Standard_Wide_Wide_Character
then
11716 -- For the case of Standard.String, or any other type whose component
11717 -- type is Standard.Character, we must make sure that there are no
11718 -- wide characters in the string, i.e. that it is entirely composed
11719 -- of characters in range of type Character.
11721 -- If the string literal is the result of a static concatenation, the
11722 -- test has already been performed on the components, and need not be
11725 elsif R_Typ
= Standard_Character
11726 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
11728 for J
in 1 .. Strlen
loop
11729 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
11731 -- If we are out of range, post error. This is one of the
11732 -- very few places that we place the flag in the middle of
11733 -- a token, right under the offending wide character. Not
11734 -- quite clear if this is right wrt wide character encoding
11735 -- sequences, but it's only an error message.
11738 ("literal out of range of type Standard.Character",
11739 Source_Ptr
(Int
(Loc
) + J
));
11744 -- For the case of Standard.Wide_String, or any other type whose
11745 -- component type is Standard.Wide_Character, we must make sure that
11746 -- there are no wide characters in the string, i.e. that it is
11747 -- entirely composed of characters in range of type Wide_Character.
11749 -- If the string literal is the result of a static concatenation,
11750 -- the test has already been performed on the components, and need
11751 -- not be repeated.
11753 elsif R_Typ
= Standard_Wide_Character
11754 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
11756 for J
in 1 .. Strlen
loop
11757 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
11759 -- If we are out of range, post error. This is one of the
11760 -- very few places that we place the flag in the middle of
11761 -- a token, right under the offending wide character.
11763 -- This is not quite right, because characters in general
11764 -- will take more than one character position ???
11767 ("literal out of range of type Standard.Wide_Character",
11768 Source_Ptr
(Int
(Loc
) + J
));
11773 -- If the root type is not a standard character, then we will convert
11774 -- the string into an aggregate and will let the aggregate code do
11775 -- the checking. Standard Wide_Wide_Character is also OK here.
11781 -- See if the component type of the array corresponding to the string
11782 -- has compile time known bounds. If yes we can directly check
11783 -- whether the evaluation of the string will raise constraint error.
11784 -- Otherwise we need to transform the string literal into the
11785 -- corresponding character aggregate and let the aggregate code do
11786 -- the checking. We use the same transformation if the component
11787 -- type has a static predicate, which will be applied to each
11788 -- character when the aggregate is resolved.
11790 if Is_Standard_Character_Type
(R_Typ
) then
11792 -- Check for the case of full range, where we are definitely OK
11794 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
11798 -- Here the range is not the complete base type range, so check
11801 Comp_Typ_Lo
: constant Node_Id
:=
11802 Type_Low_Bound
(Component_Type
(Typ
));
11803 Comp_Typ_Hi
: constant Node_Id
:=
11804 Type_High_Bound
(Component_Type
(Typ
));
11809 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
11810 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
11812 for J
in 1 .. Strlen
loop
11813 Char_Val
:= UI_From_CC
(Get_String_Char
(Str
, J
));
11815 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
11816 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
11818 Apply_Compile_Time_Constraint_Error
11819 (N
, "character out of range??",
11820 CE_Range_Check_Failed
,
11821 Loc
=> Loc
+ Source_Ptr
(J
));
11825 if not Has_Static_Predicate
(C_Typ
) then
11833 -- If we got here we meed to transform the string literal into the
11834 -- equivalent qualified positional array aggregate. This is rather
11835 -- heavy artillery for this situation, but it is hard work to avoid.
11838 Lits
: constant List_Id
:= New_List
;
11839 P
: Source_Ptr
:= Loc
+ 1;
11843 -- Build the character literals, we give them source locations that
11844 -- correspond to the string positions, which is a bit tricky given
11845 -- the possible presence of wide character escape sequences.
11847 for J
in 1 .. Strlen
loop
11848 C
:= Get_String_Char
(Str
, J
);
11849 Set_Character_Literal_Name
(C
);
11852 Make_Character_Literal
(P
,
11853 Chars
=> Name_Find
,
11854 Char_Literal_Value
=> UI_From_CC
(C
)));
11856 if In_Character_Range
(C
) then
11859 -- Should we have a call to Skip_Wide here ???
11868 Make_Qualified_Expression
(Loc
,
11869 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
11871 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
11873 Analyze_And_Resolve
(N
, Typ
);
11875 end Resolve_String_Literal
;
11877 -------------------------
11878 -- Resolve_Target_Name --
11879 -------------------------
11881 procedure Resolve_Target_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
11883 Set_Etype
(N
, Typ
);
11884 end Resolve_Target_Name
;
11886 -----------------------------
11887 -- Resolve_Type_Conversion --
11888 -----------------------------
11890 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
11891 Conv_OK
: constant Boolean := Conversion_OK
(N
);
11892 Operand
: constant Node_Id
:= Expression
(N
);
11893 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
11894 Target_Typ
: constant Entity_Id
:= Etype
(N
);
11899 Test_Redundant
: Boolean := Warn_On_Redundant_Constructs
;
11900 -- Set to False to suppress cases where we want to suppress the test
11901 -- for redundancy to avoid possible false positives on this warning.
11905 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
11910 -- If the Operand Etype is Universal_Fixed, then the conversion is
11911 -- never redundant. We need this check because by the time we have
11912 -- finished the rather complex transformation, the conversion looks
11913 -- redundant when it is not.
11915 if Operand_Typ
= Universal_Fixed
then
11916 Test_Redundant
:= False;
11918 -- If the operand is marked as Any_Fixed, then special processing is
11919 -- required. This is also a case where we suppress the test for a
11920 -- redundant conversion, since most certainly it is not redundant.
11922 elsif Operand_Typ
= Any_Fixed
then
11923 Test_Redundant
:= False;
11925 -- Mixed-mode operation involving a literal. Context must be a fixed
11926 -- type which is applied to the literal subsequently.
11928 -- Multiplication and division involving two fixed type operands must
11929 -- yield a universal real because the result is computed in arbitrary
11932 if Is_Fixed_Point_Type
(Typ
)
11933 and then Nkind
(Operand
) in N_Op_Divide | N_Op_Multiply
11934 and then Etype
(Left_Opnd
(Operand
)) = Any_Fixed
11935 and then Etype
(Right_Opnd
(Operand
)) = Any_Fixed
11937 Set_Etype
(Operand
, Universal_Real
);
11939 elsif Is_Numeric_Type
(Typ
)
11940 and then Nkind
(Operand
) in N_Op_Multiply | N_Op_Divide
11941 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
11943 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
11945 -- Return if expression is ambiguous
11947 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
11950 -- If nothing else, the available fixed type is Duration
11953 Set_Etype
(Operand
, Standard_Duration
);
11956 -- Resolve the real operand with largest available precision
11958 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
11959 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
11961 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
11964 Resolve
(Rop
, Universal_Real
);
11966 -- If the operand is a literal (it could be a non-static and
11967 -- illegal exponentiation) check whether the use of Duration
11968 -- is potentially inaccurate.
11970 if Nkind
(Rop
) = N_Real_Literal
11971 and then Realval
(Rop
) /= Ureal_0
11972 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
11975 ("??universal real operand can only "
11976 & "be interpreted as Duration!", Rop
);
11978 ("\??precision will be lost in the conversion!", Rop
);
11981 elsif Is_Numeric_Type
(Typ
)
11982 and then Nkind
(Operand
) in N_Op
11983 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
11985 Set_Etype
(Operand
, Standard_Duration
);
11988 Error_Msg_N
("invalid context for mixed mode operation", N
);
11989 Set_Etype
(Operand
, Any_Type
);
11996 Analyze_Dimension
(N
);
11998 -- Note: we do the Eval_Type_Conversion call before applying the
11999 -- required checks for a subtype conversion. This is important, since
12000 -- both are prepared under certain circumstances to change the type
12001 -- conversion to a constraint error node, but in the case of
12002 -- Eval_Type_Conversion this may reflect an illegality in the static
12003 -- case, and we would miss the illegality (getting only a warning
12004 -- message), if we applied the type conversion checks first.
12006 Eval_Type_Conversion
(N
);
12008 -- Even when evaluation is not possible, we may be able to simplify the
12009 -- conversion or its expression. This needs to be done before applying
12010 -- checks, since otherwise the checks may use the original expression
12011 -- and defeat the simplifications. This is specifically the case for
12012 -- elimination of the floating-point Truncation attribute in
12013 -- float-to-int conversions.
12015 Simplify_Type_Conversion
(N
);
12017 -- If after evaluation we still have a type conversion, then we may need
12018 -- to apply checks required for a subtype conversion. But skip them if
12019 -- universal fixed operands are involved, since range checks are handled
12020 -- separately for these cases, after the expansion done by Exp_Fixd.
12022 if Nkind
(N
) = N_Type_Conversion
12023 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
12024 and then Target_Typ
/= Universal_Fixed
12025 and then Etype
(Operand
) /= Universal_Fixed
12027 Apply_Type_Conversion_Checks
(N
);
12030 -- Issue warning for conversion of simple object to its own type. We
12031 -- have to test the original nodes, since they may have been rewritten
12032 -- by various optimizations.
12034 Orig_N
:= Original_Node
(N
);
12036 -- Here we test for a redundant conversion if the warning mode is
12037 -- active (and was not locally reset), and we have a type conversion
12038 -- from source not appearing in a generic instance.
12041 and then Nkind
(Orig_N
) = N_Type_Conversion
12042 and then Comes_From_Source
(Orig_N
)
12043 and then not In_Instance
12045 Orig_N
:= Original_Node
(Expression
(Orig_N
));
12046 Orig_T
:= Target_Typ
;
12048 -- If the node is part of a larger expression, the Target_Type
12049 -- may not be the original type of the node if the context is a
12050 -- condition. Recover original type to see if conversion is needed.
12052 if Is_Boolean_Type
(Orig_T
)
12053 and then Nkind
(Parent
(N
)) in N_Op
12055 Orig_T
:= Etype
(Parent
(N
));
12058 -- If we have an entity name, then give the warning if the entity
12059 -- is the right type, or if it is a loop parameter covered by the
12060 -- original type (that's needed because loop parameters have an
12061 -- odd subtype coming from the bounds).
12063 if (Is_Entity_Name
(Orig_N
)
12064 and then Present
(Entity
(Orig_N
))
12066 (Etype
(Entity
(Orig_N
)) = Orig_T
12068 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
12069 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
))))))
12071 -- If not an entity, then type of expression must match
12073 or else Etype
(Orig_N
) = Orig_T
12075 -- One more check, do not give warning if the analyzed conversion
12076 -- has an expression with non-static bounds, and the bounds of the
12077 -- target are static. This avoids junk warnings in cases where the
12078 -- conversion is necessary to establish staticness, for example in
12079 -- a case statement.
12081 if not Is_OK_Static_Subtype
(Operand_Typ
)
12082 and then Is_OK_Static_Subtype
(Target_Typ
)
12086 -- Finally, if this type conversion occurs in a context requiring
12087 -- a prefix, and the expression is a qualified expression then the
12088 -- type conversion is not redundant, since a qualified expression
12089 -- is not a prefix, whereas a type conversion is. For example, "X
12090 -- := T'(Funx(...)).Y;" is illegal because a selected component
12091 -- requires a prefix, but a type conversion makes it legal: "X :=
12092 -- T(T'(Funx(...))).Y;"
12094 -- In Ada 2012, a qualified expression is a name, so this idiom is
12095 -- no longer needed, but we still suppress the warning because it
12096 -- seems unfriendly for warnings to pop up when you switch to the
12097 -- newer language version.
12099 elsif Nkind
(Orig_N
) = N_Qualified_Expression
12100 and then Nkind
(Parent
(N
)) in N_Attribute_Reference
12101 | N_Indexed_Component
12102 | N_Selected_Component
12104 | N_Explicit_Dereference
12108 -- Never warn on conversion to Long_Long_Integer'Base since
12109 -- that is most likely an artifact of the extended overflow
12110 -- checking and comes from complex expanded code.
12112 elsif Orig_T
= Base_Type
(Standard_Long_Long_Integer
) then
12115 -- Here we give the redundant conversion warning. If it is an
12116 -- entity, give the name of the entity in the message. If not,
12117 -- just mention the expression.
12120 if Is_Entity_Name
(Orig_N
) then
12121 Error_Msg_Node_2
:= Orig_T
;
12122 Error_Msg_NE
-- CODEFIX
12123 ("?r?redundant conversion, & is of type &!",
12124 N
, Entity
(Orig_N
));
12127 ("?r?redundant conversion, expression is of type&!",
12134 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
12135 -- No need to perform any interface conversion if the type of the
12136 -- expression coincides with the target type.
12138 if Ada_Version
>= Ada_2005
12139 and then Expander_Active
12140 and then Operand_Typ
/= Target_Typ
12143 Opnd
: Entity_Id
:= Operand_Typ
;
12144 Target
: Entity_Id
:= Target_Typ
;
12147 -- If the type of the operand is a limited view, use nonlimited
12148 -- view when available. If it is a class-wide type, recover the
12149 -- class-wide type of the nonlimited view.
12151 if From_Limited_With
(Opnd
)
12152 and then Has_Non_Limited_View
(Opnd
)
12154 Opnd
:= Non_Limited_View
(Opnd
);
12155 Set_Etype
(Expression
(N
), Opnd
);
12158 -- It seems that Non_Limited_View should also be applied for
12159 -- Target when it has a limited view, but that leads to missing
12160 -- error checks on interface conversions further below. ???
12162 if Is_Access_Type
(Opnd
) then
12163 Opnd
:= Designated_Type
(Opnd
);
12165 -- If the type of the operand is a limited view, use nonlimited
12166 -- view when available. If it is a class-wide type, recover the
12167 -- class-wide type of the nonlimited view.
12169 if From_Limited_With
(Opnd
)
12170 and then Has_Non_Limited_View
(Opnd
)
12172 Opnd
:= Non_Limited_View
(Opnd
);
12176 if Is_Access_Type
(Target_Typ
) then
12177 Target
:= Designated_Type
(Target
);
12179 -- If the target type is a limited view, use nonlimited view
12182 if From_Limited_With
(Target
)
12183 and then Has_Non_Limited_View
(Target
)
12185 Target
:= Non_Limited_View
(Target
);
12189 if Opnd
= Target
then
12192 -- Conversion from interface type
12194 -- It seems that it would be better for the error checks below
12195 -- to be performed as part of Validate_Conversion (and maybe some
12196 -- of the error checks above could be moved as well?). ???
12198 elsif Is_Interface
(Opnd
) then
12200 -- Ada 2005 (AI-217): Handle entities from limited views
12202 if From_Limited_With
(Opnd
) then
12203 Error_Msg_Qual_Level
:= 99;
12204 Error_Msg_NE
-- CODEFIX
12205 ("missing WITH clause on package &", N
,
12206 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
12208 ("type conversions require visibility of the full view",
12211 elsif From_Limited_With
(Target
)
12213 (Is_Access_Type
(Target_Typ
)
12214 and then Present
(Non_Limited_View
(Etype
(Target
))))
12216 Error_Msg_Qual_Level
:= 99;
12217 Error_Msg_NE
-- CODEFIX
12218 ("missing WITH clause on package &", N
,
12219 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
12221 ("type conversions require visibility of the full view",
12225 Expand_Interface_Conversion
(N
);
12228 -- Conversion to interface type
12230 elsif Is_Interface
(Target
) then
12234 if Ekind
(Opnd
) in E_Protected_Subtype | E_Task_Subtype
then
12235 Opnd
:= Etype
(Opnd
);
12238 if Is_Class_Wide_Type
(Opnd
)
12239 or else Interface_Present_In_Ancestor
12243 Expand_Interface_Conversion
(N
);
12245 Error_Msg_Name_1
:= Chars
(Etype
(Target
));
12246 Error_Msg_Name_2
:= Chars
(Opnd
);
12248 ("wrong interface conversion (% is not a progenitor "
12255 -- Ada 2012: Once the type conversion is resolved, check whether the
12256 -- operand satisfies a static predicate of the target subtype, if any.
12257 -- In the static expression case, a predicate check failure is an error.
12259 if Has_Predicates
(Target_Typ
) then
12260 Check_Expression_Against_Static_Predicate
12261 (N
, Target_Typ
, Static_Failure_Is_Error
=> True);
12264 -- If at this stage we have a fixed to integer conversion, make sure the
12265 -- Do_Range_Check flag is set, because such conversions in general need
12266 -- a range check. We only need this if expansion is off, see above why.
12268 if Nkind
(N
) = N_Type_Conversion
12269 and then not Expander_Active
12270 and then Is_Integer_Type
(Target_Typ
)
12271 and then Is_Fixed_Point_Type
(Operand_Typ
)
12272 and then not Range_Checks_Suppressed
(Target_Typ
)
12273 and then not Range_Checks_Suppressed
(Operand_Typ
)
12275 Set_Do_Range_Check
(Operand
);
12278 -- Generating C code a type conversion of an access to constrained
12279 -- array type to access to unconstrained array type involves building
12280 -- a fat pointer which in general cannot be generated on the fly. We
12281 -- remove side effects in order to store the result of the conversion
12282 -- into a temporary.
12284 if Modify_Tree_For_C
12285 and then Nkind
(N
) = N_Type_Conversion
12286 and then Nkind
(Parent
(N
)) /= N_Object_Declaration
12287 and then Is_Access_Type
(Etype
(N
))
12288 and then Is_Array_Type
(Designated_Type
(Etype
(N
)))
12289 and then not Is_Constrained
(Designated_Type
(Etype
(N
)))
12290 and then Is_Constrained
(Designated_Type
(Etype
(Expression
(N
))))
12292 Remove_Side_Effects
(N
);
12294 end Resolve_Type_Conversion
;
12296 ----------------------
12297 -- Resolve_Unary_Op --
12298 ----------------------
12300 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
12301 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
12302 R
: constant Node_Id
:= Right_Opnd
(N
);
12308 -- Deal with intrinsic unary operators
12310 if Comes_From_Source
(N
)
12311 and then Ekind
(Entity
(N
)) = E_Function
12312 and then Is_Imported
(Entity
(N
))
12313 and then Is_Intrinsic_Subprogram
(Entity
(N
))
12315 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
12319 -- Deal with universal cases
12321 if Is_Universal_Numeric_Type
(Etype
(R
)) then
12322 Check_For_Visible_Operator
(N
, B_Typ
);
12325 Set_Etype
(N
, B_Typ
);
12326 Resolve
(R
, B_Typ
);
12328 -- Generate warning for negative literal of a modular type, unless it is
12329 -- enclosed directly in a type qualification or a type conversion, as it
12330 -- is likely not what the user intended. We don't issue the warning for
12331 -- the common use of -1 to denote OxFFFF_FFFF...
12333 if Warn_On_Suspicious_Modulus_Value
12334 and then Nkind
(N
) = N_Op_Minus
12335 and then Nkind
(R
) = N_Integer_Literal
12336 and then Is_Modular_Integer_Type
(B_Typ
)
12337 and then Nkind
(Parent
(N
)) not in N_Qualified_Expression
12338 | N_Type_Conversion
12339 and then Expr_Value
(R
) > Uint_1
12342 ("?.m?negative literal of modular type is in fact positive", N
);
12343 Error_Msg_Uint_1
:= (-Expr_Value
(R
)) mod Modulus
(B_Typ
);
12344 Error_Msg_Uint_2
:= Expr_Value
(R
);
12345 Error_Msg_N
("\do you really mean^ when writing -^ '?", N
);
12347 ("\if you do, use qualification to avoid this warning", N
);
12350 -- Generate warning for expressions like abs (x mod 2)
12352 if Warn_On_Redundant_Constructs
12353 and then Nkind
(N
) = N_Op_Abs
12355 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
12357 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
12358 Error_Msg_N
-- CODEFIX
12359 ("?r?abs applied to known non-negative value has no effect", N
);
12363 -- Deal with reference generation
12365 Check_Unset_Reference
(R
);
12366 Generate_Operator_Reference
(N
, B_Typ
);
12367 Analyze_Dimension
(N
);
12370 -- Set overflow checking bit. Much cleverer code needed here eventually
12371 -- and perhaps the Resolve routines should be separated for the various
12372 -- arithmetic operations, since they will need different processing ???
12374 if Nkind
(N
) in N_Op
then
12375 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
12376 Enable_Overflow_Check
(N
);
12380 -- Generate warning for expressions like -5 mod 3 for integers. No need
12381 -- to worry in the floating-point case, since parens do not affect the
12382 -- result so there is no point in giving in a warning.
12385 Norig
: constant Node_Id
:= Original_Node
(N
);
12394 if Warn_On_Questionable_Missing_Parens
12395 and then Comes_From_Source
(Norig
)
12396 and then Is_Integer_Type
(Typ
)
12397 and then Nkind
(Norig
) = N_Op_Minus
12399 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
12401 -- We are looking for cases where the right operand is not
12402 -- parenthesized, and is a binary operator, multiply, divide, or
12403 -- mod. These are the cases where the grouping can affect results.
12405 if Paren_Count
(Rorig
) = 0
12406 and then Nkind
(Rorig
) in N_Op_Mod | N_Op_Multiply | N_Op_Divide
12408 -- For mod, we always give the warning, since the value is
12409 -- affected by the parenthesization (e.g. (-5) mod 315 /=
12410 -- -(5 mod 315)). But for the other cases, the only concern is
12411 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
12412 -- overflows, but (-2) * 64 does not). So we try to give the
12413 -- message only when overflow is possible.
12415 if Nkind
(Rorig
) /= N_Op_Mod
12416 and then Compile_Time_Known_Value
(R
)
12418 Val
:= Expr_Value
(R
);
12420 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
12421 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
12423 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
12426 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
12427 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
12429 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
12432 -- Note that the test below is deliberately excluding the
12433 -- largest negative number, since that is a potentially
12434 -- troublesome case (e.g. -2 * x, where the result is the
12435 -- largest negative integer has an overflow with 2 * x).
12437 if Val
> LB
and then Val
<= HB
then
12442 -- For the multiplication case, the only case we have to worry
12443 -- about is when (-a)*b is exactly the largest negative number
12444 -- so that -(a*b) can cause overflow. This can only happen if
12445 -- a is a power of 2, and more generally if any operand is a
12446 -- constant that is not a power of 2, then the parentheses
12447 -- cannot affect whether overflow occurs. We only bother to
12448 -- test the left most operand
12450 -- Loop looking at left operands for one that has known value
12453 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
12454 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
12455 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
12457 -- Operand value of 0 or 1 skips warning
12462 -- Otherwise check power of 2, if power of 2, warn, if
12463 -- anything else, skip warning.
12466 while Lval
/= 2 loop
12467 if Lval
mod 2 = 1 then
12478 -- Keep looking at left operands
12480 Opnd
:= Left_Opnd
(Opnd
);
12481 end loop Opnd_Loop
;
12483 -- For rem or "/" we can only have a problematic situation
12484 -- if the divisor has a value of minus one or one. Otherwise
12485 -- overflow is impossible (divisor > 1) or we have a case of
12486 -- division by zero in any case.
12488 if Nkind
(Rorig
) in N_Op_Divide | N_Op_Rem
12489 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
12490 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
12495 -- If we fall through warning should be issued
12497 -- Shouldn't we test Warn_On_Questionable_Missing_Parens ???
12500 ("??unary minus expression should be parenthesized here!", N
);
12504 end Resolve_Unary_Op
;
12506 ----------------------------------
12507 -- Resolve_Unchecked_Expression --
12508 ----------------------------------
12510 procedure Resolve_Unchecked_Expression
12515 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
12516 Set_Etype
(N
, Typ
);
12517 end Resolve_Unchecked_Expression
;
12519 ---------------------------------------
12520 -- Resolve_Unchecked_Type_Conversion --
12521 ---------------------------------------
12523 procedure Resolve_Unchecked_Type_Conversion
12527 pragma Warnings
(Off
, Typ
);
12529 Operand
: constant Node_Id
:= Expression
(N
);
12530 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
12533 -- Resolve operand using its own type
12535 Resolve
(Operand
, Opnd_Type
);
12537 -- If the expression is a conversion to universal integer of an
12538 -- an expression with an integer type, then we can eliminate the
12539 -- intermediate conversion to universal integer.
12541 if Nkind
(Operand
) = N_Type_Conversion
12542 and then Entity
(Subtype_Mark
(Operand
)) = Universal_Integer
12543 and then Is_Integer_Type
(Etype
(Expression
(Operand
)))
12545 Rewrite
(Operand
, Relocate_Node
(Expression
(Operand
)));
12546 Analyze_And_Resolve
(Operand
);
12549 -- In an inlined context, the unchecked conversion may be applied
12550 -- to a literal, in which case its type is the type of the context.
12551 -- (In other contexts conversions cannot apply to literals).
12554 and then (Opnd_Type
= Any_Character
or else
12555 Opnd_Type
= Any_Integer
or else
12556 Opnd_Type
= Any_Real
)
12558 Set_Etype
(Operand
, Typ
);
12561 Analyze_Dimension
(N
);
12562 Eval_Unchecked_Conversion
(N
);
12563 end Resolve_Unchecked_Type_Conversion
;
12565 ------------------------------
12566 -- Rewrite_Operator_As_Call --
12567 ------------------------------
12569 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
12570 Loc
: constant Source_Ptr
:= Sloc
(N
);
12571 Actuals
: constant List_Id
:= New_List
;
12575 if Nkind
(N
) in N_Binary_Op
then
12576 Append
(Left_Opnd
(N
), Actuals
);
12579 Append
(Right_Opnd
(N
), Actuals
);
12582 Make_Function_Call
(Sloc
=> Loc
,
12583 Name
=> New_Occurrence_Of
(Nam
, Loc
),
12584 Parameter_Associations
=> Actuals
);
12586 Preserve_Comes_From_Source
(New_N
, N
);
12587 Preserve_Comes_From_Source
(Name
(New_N
), N
);
12588 Rewrite
(N
, New_N
);
12589 Set_Etype
(N
, Etype
(Nam
));
12590 end Rewrite_Operator_As_Call
;
12592 ------------------------------
12593 -- Rewrite_Renamed_Operator --
12594 ------------------------------
12596 procedure Rewrite_Renamed_Operator
12601 Nam
: constant Name_Id
:= Chars
(Op
);
12602 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
12606 -- Do not perform this transformation within a pre/postcondition,
12607 -- because the expression will be reanalyzed, and the transformation
12608 -- might affect the visibility of the operator, e.g. in an instance.
12609 -- Note that fully analyzed and expanded pre/postconditions appear as
12610 -- pragma Check equivalents.
12612 if In_Pre_Post_Condition
(N
) then
12616 -- Likewise when an expression function is being preanalyzed, since the
12617 -- expression will be reanalyzed as part of the generated body.
12619 if In_Spec_Expression
then
12621 S
: constant Entity_Id
:= Current_Scope_No_Loops
;
12623 if Ekind
(S
) = E_Function
12624 and then Nkind
(Original_Node
(Unit_Declaration_Node
(S
))) =
12625 N_Expression_Function
12632 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
12633 Set_Chars
(Op_Node
, Nam
);
12634 Set_Etype
(Op_Node
, Etype
(N
));
12635 Set_Entity
(Op_Node
, Op
);
12636 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
12639 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
12642 -- Indicate that both the original entity and its renaming are
12643 -- referenced at this point.
12645 Generate_Reference
(Entity
(N
), N
);
12646 Generate_Reference
(Op
, N
);
12648 Rewrite
(N
, Op_Node
);
12650 -- If the context type is private, add the appropriate conversions so
12651 -- that the operator is applied to the full view. This is done in the
12652 -- routines that resolve intrinsic operators.
12654 if Is_Intrinsic_Subprogram
(Op
) and then Is_Private_Type
(Typ
) then
12664 Resolve_Intrinsic_Operator
(N
, Typ
);
12670 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
12676 end Rewrite_Renamed_Operator
;
12678 -----------------------
12679 -- Set_Slice_Subtype --
12680 -----------------------
12682 -- Build an implicit subtype declaration to represent the type delivered by
12683 -- the slice. This is an abbreviated version of an array subtype. We define
12684 -- an index subtype for the slice, using either the subtype name or the
12685 -- discrete range of the slice. To be consistent with index usage elsewhere
12686 -- we create a list header to hold the single index. This list is not
12687 -- otherwise attached to the syntax tree.
12689 procedure Set_Slice_Subtype
(N
: Node_Id
) is
12690 Loc
: constant Source_Ptr
:= Sloc
(N
);
12691 Index_List
: constant List_Id
:= New_List
;
12693 Index_Subtype
: Entity_Id
;
12694 Index_Type
: Entity_Id
;
12695 Slice_Subtype
: Entity_Id
;
12696 Drange
: constant Node_Id
:= Discrete_Range
(N
);
12699 Index_Type
:= Base_Type
(Etype
(Drange
));
12701 if Is_Entity_Name
(Drange
) then
12702 Index_Subtype
:= Entity
(Drange
);
12705 -- We force the evaluation of a range. This is definitely needed in
12706 -- the renamed case, and seems safer to do unconditionally. Note in
12707 -- any case that since we will create and insert an Itype referring
12708 -- to this range, we must make sure any side effect removal actions
12709 -- are inserted before the Itype definition.
12711 if Nkind
(Drange
) = N_Range
then
12712 Force_Evaluation
(Low_Bound
(Drange
));
12713 Force_Evaluation
(High_Bound
(Drange
));
12715 -- If the discrete range is given by a subtype indication, the
12716 -- type of the slice is the base of the subtype mark.
12718 elsif Nkind
(Drange
) = N_Subtype_Indication
then
12720 R
: constant Node_Id
:= Range_Expression
(Constraint
(Drange
));
12722 Index_Type
:= Base_Type
(Entity
(Subtype_Mark
(Drange
)));
12723 Force_Evaluation
(Low_Bound
(R
));
12724 Force_Evaluation
(High_Bound
(R
));
12728 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
12730 -- Take a new copy of Drange (where bounds have been rewritten to
12731 -- reference side-effect-free names). Using a separate tree ensures
12732 -- that further expansion (e.g. while rewriting a slice assignment
12733 -- into a FOR loop) does not attempt to remove side effects on the
12734 -- bounds again (which would cause the bounds in the index subtype
12735 -- definition to refer to temporaries before they are defined) (the
12736 -- reason is that some names are considered side effect free here
12737 -- for the subtype, but not in the context of a loop iteration
12740 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
12741 Set_Parent
(Scalar_Range
(Index_Subtype
), Index_Subtype
);
12742 Set_Etype
(Index_Subtype
, Index_Type
);
12743 Set_Size_Info
(Index_Subtype
, Index_Type
);
12744 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
12745 Set_Is_Constrained
(Index_Subtype
);
12748 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
12750 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
12751 Set_Etype
(Index
, Index_Subtype
);
12752 Append
(Index
, Index_List
);
12754 Set_First_Index
(Slice_Subtype
, Index
);
12755 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
12756 Set_Is_Constrained
(Slice_Subtype
, True);
12758 Check_Compile_Time_Size
(Slice_Subtype
);
12760 -- The Etype of the existing Slice node is reset to this slice subtype.
12761 -- Its bounds are obtained from its first index.
12763 Set_Etype
(N
, Slice_Subtype
);
12765 -- For bit-packed slice subtypes, freeze immediately (except in the case
12766 -- of being in a "spec expression" where we never freeze when we first
12767 -- see the expression).
12769 if Is_Bit_Packed_Array
(Slice_Subtype
) and not In_Spec_Expression
then
12770 Freeze_Itype
(Slice_Subtype
, N
);
12772 -- For all other cases insert an itype reference in the slice's actions
12773 -- so that the itype is frozen at the proper place in the tree (i.e. at
12774 -- the point where actions for the slice are analyzed). Note that this
12775 -- is different from freezing the itype immediately, which might be
12776 -- premature (e.g. if the slice is within a transient scope). This needs
12777 -- to be done only if expansion is enabled.
12779 elsif Expander_Active
then
12780 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
12782 end Set_Slice_Subtype
;
12784 --------------------------------
12785 -- Set_String_Literal_Subtype --
12786 --------------------------------
12788 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
12789 Loc
: constant Source_Ptr
:= Sloc
(N
);
12790 Low_Bound
: constant Node_Id
:=
12791 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
12792 Subtype_Id
: Entity_Id
;
12795 if Nkind
(N
) /= N_String_Literal
then
12799 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
12800 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
12801 (String_Length
(Strval
(N
))));
12802 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
12803 Set_Is_Constrained
(Subtype_Id
);
12804 Set_Etype
(N
, Subtype_Id
);
12806 -- The low bound is set from the low bound of the corresponding index
12807 -- type. Note that we do not store the high bound in the string literal
12808 -- subtype, but it can be deduced if necessary from the length and the
12811 if Is_OK_Static_Expression
(Low_Bound
) then
12812 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
12814 -- If the lower bound is not static we create a range for the string
12815 -- literal, using the index type and the known length of the literal.
12816 -- If the length is 1, then the upper bound is set to a mere copy of
12817 -- the lower bound; or else, if the index type is a signed integer,
12818 -- then the upper bound is computed as Low_Bound + L - 1; otherwise,
12819 -- the upper bound is computed as T'Val (T'Pos (Low_Bound) + L - 1).
12823 Length
: constant Nat
:= String_Length
(Strval
(N
));
12824 Index_List
: constant List_Id
:= New_List
;
12825 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
12826 Array_Subtype
: Entity_Id
;
12828 High_Bound
: Node_Id
;
12830 Index_Subtype
: Entity_Id
;
12834 High_Bound
:= New_Copy_Tree
(Low_Bound
);
12836 elsif Is_Signed_Integer_Type
(Index_Type
) then
12839 Left_Opnd
=> New_Copy_Tree
(Low_Bound
),
12840 Right_Opnd
=> Make_Integer_Literal
(Loc
, Length
- 1));
12844 Make_Attribute_Reference
(Loc
,
12845 Attribute_Name
=> Name_Val
,
12847 New_Occurrence_Of
(Index_Type
, Loc
),
12848 Expressions
=> New_List
(
12851 Make_Attribute_Reference
(Loc
,
12852 Attribute_Name
=> Name_Pos
,
12854 New_Occurrence_Of
(Index_Type
, Loc
),
12856 New_List
(New_Copy_Tree
(Low_Bound
))),
12858 Make_Integer_Literal
(Loc
, Length
- 1))));
12861 if Is_Integer_Type
(Index_Type
) then
12862 Set_String_Literal_Low_Bound
12863 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
12866 -- If the index type is an enumeration type, build bounds
12867 -- expression with attributes.
12869 Set_String_Literal_Low_Bound
12871 Make_Attribute_Reference
(Loc
,
12872 Attribute_Name
=> Name_First
,
12874 New_Occurrence_Of
(Base_Type
(Index_Type
), Loc
)));
12877 Analyze_And_Resolve
12878 (String_Literal_Low_Bound
(Subtype_Id
), Base_Type
(Index_Type
));
12880 -- Build bona fide subtype for the string, and wrap it in an
12881 -- unchecked conversion, because the back end expects the
12882 -- String_Literal_Subtype to have a static lower bound.
12885 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
12886 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
12887 Set_Scalar_Range
(Index_Subtype
, Drange
);
12888 Set_Parent
(Drange
, N
);
12889 Analyze_And_Resolve
(Drange
, Index_Type
);
12891 -- In this context, the Index_Type may already have a constraint,
12892 -- so use common base type on string subtype. The base type may
12893 -- be used when generating attributes of the string, for example
12894 -- in the context of a slice assignment.
12896 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
12897 Set_Size_Info
(Index_Subtype
, Index_Type
);
12898 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
12900 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
12902 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
12903 Set_Etype
(Index
, Index_Subtype
);
12904 Append
(Index
, Index_List
);
12906 Set_First_Index
(Array_Subtype
, Index
);
12907 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
12908 Set_Is_Constrained
(Array_Subtype
, True);
12910 Rewrite
(N
, Unchecked_Convert_To
(Array_Subtype
, N
));
12911 Set_Etype
(N
, Array_Subtype
);
12914 end Set_String_Literal_Subtype
;
12916 ------------------------------
12917 -- Simplify_Type_Conversion --
12918 ------------------------------
12920 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
12922 if Nkind
(N
) = N_Type_Conversion
then
12924 Operand
: constant Node_Id
:= Expression
(N
);
12925 Target_Typ
: constant Entity_Id
:= Etype
(N
);
12926 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
12929 -- Special processing if the conversion is the expression of a
12930 -- Rounding or Truncation attribute reference. In this case we
12933 -- ityp (ftyp'Rounding (x)) or ityp (ftyp'Truncation (x))
12939 -- with the Float_Truncate flag set to False or True respectively,
12940 -- which is more efficient. We reuse Rounding for Machine_Rounding
12941 -- as System.Fat_Gen, which is a permissible behavior.
12943 if Is_Floating_Point_Type
(Opnd_Typ
)
12945 (Is_Integer_Type
(Target_Typ
)
12946 or else (Is_Fixed_Point_Type
(Target_Typ
)
12947 and then Conversion_OK
(N
)))
12948 and then Nkind
(Operand
) = N_Attribute_Reference
12949 and then Attribute_Name
(Operand
) in Name_Rounding
12950 | Name_Machine_Rounding
12954 Truncate
: constant Boolean :=
12955 Attribute_Name
(Operand
) = Name_Truncation
;
12958 Relocate_Node
(First
(Expressions
(Operand
))));
12959 Set_Float_Truncate
(N
, Truncate
);
12962 -- Special processing for the conversion of an integer literal to
12963 -- a dynamic type: we first convert the literal to the root type
12964 -- and then convert the result to the target type, the goal being
12965 -- to avoid doing range checks in universal integer.
12967 elsif Is_Integer_Type
(Target_Typ
)
12968 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
12969 and then Nkind
(Operand
) = N_Integer_Literal
12970 and then Opnd_Typ
= Universal_Integer
12972 Convert_To_And_Rewrite
(Root_Type
(Target_Typ
), Operand
);
12973 Analyze_And_Resolve
(Operand
);
12975 -- If the expression is a conversion to universal integer of an
12976 -- an expression with an integer type, then we can eliminate the
12977 -- intermediate conversion to universal integer.
12979 elsif Nkind
(Operand
) = N_Type_Conversion
12980 and then Entity
(Subtype_Mark
(Operand
)) = Universal_Integer
12981 and then Is_Integer_Type
(Etype
(Expression
(Operand
)))
12983 Rewrite
(Operand
, Relocate_Node
(Expression
(Operand
)));
12984 Analyze_And_Resolve
(Operand
);
12988 end Simplify_Type_Conversion
;
12990 ------------------------------
12991 -- Try_User_Defined_Literal --
12992 ------------------------------
12994 function Try_User_Defined_Literal
12996 Typ
: Entity_Id
) return Boolean
12999 if Nkind
(N
) in N_Op_Add | N_Op_Divide | N_Op_Mod | N_Op_Multiply
13000 | N_Op_Rem | N_Op_Subtract
13003 -- Both operands must have the same type as the context.
13004 -- (ignoring for now fixed-point and exponentiation ops).
13006 if Has_Applicable_User_Defined_Literal
(Right_Opnd
(N
), Typ
) then
13007 Resolve
(Left_Opnd
(N
), Typ
);
13008 Analyze_And_Resolve
(N
, Typ
);
13013 Has_Applicable_User_Defined_Literal
(Left_Opnd
(N
), Typ
)
13015 Resolve
(Right_Opnd
(N
), Typ
);
13016 Analyze_And_Resolve
(N
, Typ
);
13023 elsif Nkind
(N
) in N_Binary_Op
then
13024 -- For other operators the context does not impose a type on
13025 -- the operands, but their types must match.
13027 if (Nkind
(Left_Opnd
(N
))
13028 not in N_Integer_Literal | N_String_Literal | N_Real_Literal
)
13030 Has_Applicable_User_Defined_Literal
13031 (Right_Opnd
(N
), Etype
(Left_Opnd
(N
)))
13033 Analyze_And_Resolve
(N
, Typ
);
13036 elsif (Nkind
(Right_Opnd
(N
))
13037 not in N_Integer_Literal | N_String_Literal | N_Real_Literal
)
13039 Has_Applicable_User_Defined_Literal
13040 (Left_Opnd
(N
), Etype
(Right_Opnd
(N
)))
13042 Analyze_And_Resolve
(N
, Typ
);
13048 elsif Nkind
(N
) in N_Unary_Op
13050 Has_Applicable_User_Defined_Literal
(Right_Opnd
(N
), Typ
)
13052 Analyze_And_Resolve
(N
, Typ
);
13055 else -- Other operators
13058 end Try_User_Defined_Literal
;
13060 -----------------------------
13061 -- Unique_Fixed_Point_Type --
13062 -----------------------------
13064 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
13065 procedure Fixed_Point_Error
(T1
: Entity_Id
; T2
: Entity_Id
);
13066 -- Give error messages for true ambiguity. Messages are posted on node
13067 -- N, and entities T1, T2 are the possible interpretations.
13069 -----------------------
13070 -- Fixed_Point_Error --
13071 -----------------------
13073 procedure Fixed_Point_Error
(T1
: Entity_Id
; T2
: Entity_Id
) is
13075 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
13076 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
13077 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
13078 end Fixed_Point_Error
;
13088 -- Start of processing for Unique_Fixed_Point_Type
13091 -- The operations on Duration are visible, so Duration is always a
13092 -- possible interpretation.
13094 T1
:= Standard_Duration
;
13096 -- Look for fixed-point types in enclosing scopes
13098 Scop
:= Current_Scope
;
13099 while Scop
/= Standard_Standard
loop
13100 T2
:= First_Entity
(Scop
);
13101 while Present
(T2
) loop
13102 if Is_Fixed_Point_Type
(T2
)
13103 and then Current_Entity
(T2
) = T2
13104 and then Scope
(Base_Type
(T2
)) = Scop
13106 if Present
(T1
) then
13107 Fixed_Point_Error
(T1
, T2
);
13117 Scop
:= Scope
(Scop
);
13120 -- Look for visible fixed type declarations in the context
13122 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
13123 while Present
(Item
) loop
13124 if Nkind
(Item
) = N_With_Clause
then
13125 Scop
:= Entity
(Name
(Item
));
13126 T2
:= First_Entity
(Scop
);
13127 while Present
(T2
) loop
13128 if Is_Fixed_Point_Type
(T2
)
13129 and then Scope
(Base_Type
(T2
)) = Scop
13130 and then (Is_Potentially_Use_Visible
(T2
) or else In_Use
(T2
))
13132 if Present
(T1
) then
13133 Fixed_Point_Error
(T1
, T2
);
13147 if Nkind
(N
) = N_Real_Literal
then
13148 Error_Msg_NE
("??real literal interpreted as }!", N
, T1
);
13151 -- When the context is a type conversion, issue the warning on the
13152 -- expression of the conversion because it is the actual operation.
13154 if Nkind
(N
) in N_Type_Conversion | N_Unchecked_Type_Conversion
then
13155 ErrN
:= Expression
(N
);
13161 ("??universal_fixed expression interpreted as }!", ErrN
, T1
);
13165 end Unique_Fixed_Point_Type
;
13167 ----------------------
13168 -- Valid_Conversion --
13169 ----------------------
13171 function Valid_Conversion
13173 Target
: Entity_Id
;
13175 Report_Errs
: Boolean := True) return Boolean
13177 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
13178 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
13179 Inc_Ancestor
: Entity_Id
;
13181 function Conversion_Check
13183 Msg
: String) return Boolean;
13184 -- Little routine to post Msg if Valid is False, returns Valid value
13186 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
);
13187 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
13189 procedure Conversion_Error_NE
13191 N
: Node_Or_Entity_Id
;
13192 E
: Node_Or_Entity_Id
);
13193 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
13195 function In_Instance_Code
return Boolean;
13196 -- Return True if expression is within an instance but is not in one of
13197 -- the actuals of the instantiation. Type conversions within an instance
13198 -- are not rechecked because type visibility may lead to spurious errors
13199 -- but conversions in an actual for a formal object must be checked.
13201 function Is_Discrim_Of_Bad_Access_Conversion_Argument
13202 (Expr
: Node_Id
) return Boolean;
13203 -- Implicit anonymous-to-named access type conversions are not allowed
13204 -- if the "statically deeper than" relationship does not apply to the
13205 -- type of the conversion operand. See RM 8.6(28.1) and AARM 8.6(28.d).
13206 -- We deal with most such cases elsewhere so that we can emit more
13207 -- specific error messages (e.g., if the operand is an access parameter
13208 -- or a saooaaat (stand-alone object of an anonymous access type)), but
13209 -- here is where we catch the case where the operand is an access
13210 -- discriminant selected from a dereference of another such "bad"
13211 -- conversion argument.
13213 function Valid_Tagged_Conversion
13214 (Target_Type
: Entity_Id
;
13215 Opnd_Type
: Entity_Id
) return Boolean;
13216 -- Specifically test for validity of tagged conversions
13218 function Valid_Array_Conversion
return Boolean;
13219 -- Check index and component conformance, and accessibility levels if
13220 -- the component types are anonymous access types (Ada 2005).
13222 ----------------------
13223 -- Conversion_Check --
13224 ----------------------
13226 function Conversion_Check
13228 Msg
: String) return Boolean
13233 -- A generic unit has already been analyzed and we have verified
13234 -- that a particular conversion is OK in that context. Since the
13235 -- instance is reanalyzed without relying on the relationships
13236 -- established during the analysis of the generic, it is possible
13237 -- to end up with inconsistent views of private types. Do not emit
13238 -- the error message in such cases. The rest of the machinery in
13239 -- Valid_Conversion still ensures the proper compatibility of
13240 -- target and operand types.
13242 and then not In_Instance_Code
13244 Conversion_Error_N
(Msg
, Operand
);
13248 end Conversion_Check
;
13250 ------------------------
13251 -- Conversion_Error_N --
13252 ------------------------
13254 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
13256 if Report_Errs
then
13257 Error_Msg_N
(Msg
, N
);
13259 end Conversion_Error_N
;
13261 -------------------------
13262 -- Conversion_Error_NE --
13263 -------------------------
13265 procedure Conversion_Error_NE
13267 N
: Node_Or_Entity_Id
;
13268 E
: Node_Or_Entity_Id
)
13271 if Report_Errs
then
13272 Error_Msg_NE
(Msg
, N
, E
);
13274 end Conversion_Error_NE
;
13276 ----------------------
13277 -- In_Instance_Code --
13278 ----------------------
13280 function In_Instance_Code
return Boolean is
13284 if not In_Instance
then
13289 while Present
(Par
) loop
13291 -- The expression is part of an actual object if it appears in
13292 -- the generated object declaration in the instance.
13294 if Nkind
(Par
) = N_Object_Declaration
13295 and then Present
(Corresponding_Generic_Association
(Par
))
13301 Nkind
(Par
) in N_Statement_Other_Than_Procedure_Call
13302 or else Nkind
(Par
) in N_Subprogram_Call
13303 or else Nkind
(Par
) in N_Declaration
;
13306 Par
:= Parent
(Par
);
13309 -- Otherwise the expression appears within the instantiated unit
13313 end In_Instance_Code
;
13315 --------------------------------------------------
13316 -- Is_Discrim_Of_Bad_Access_Conversion_Argument --
13317 --------------------------------------------------
13319 function Is_Discrim_Of_Bad_Access_Conversion_Argument
13320 (Expr
: Node_Id
) return Boolean
13322 Exp_Type
: Entity_Id
:= Base_Type
(Etype
(Expr
));
13323 pragma Assert
(Is_Access_Type
(Exp_Type
));
13325 Associated_Node
: Node_Id
;
13326 Deref_Prefix
: Node_Id
;
13328 if not Is_Anonymous_Access_Type
(Exp_Type
) then
13332 pragma Assert
(Is_Itype
(Exp_Type
));
13333 Associated_Node
:= Associated_Node_For_Itype
(Exp_Type
);
13335 if Nkind
(Associated_Node
) /= N_Discriminant_Specification
then
13336 return False; -- not the type of an access discriminant
13339 -- return False if Expr not of form <prefix>.all.Some_Component
13341 if (Nkind
(Expr
) /= N_Selected_Component
)
13342 or else (Nkind
(Prefix
(Expr
)) /= N_Explicit_Dereference
)
13344 -- conditional expressions, declare expressions ???
13348 Deref_Prefix
:= Prefix
(Prefix
(Expr
));
13349 Exp_Type
:= Base_Type
(Etype
(Deref_Prefix
));
13351 -- The "statically deeper relationship" does not apply
13352 -- to generic formal access types, so a prefix of such
13353 -- a type is a "bad" prefix.
13355 if Is_Generic_Formal
(Exp_Type
) then
13358 -- The "statically deeper relationship" does apply to
13359 -- any other named access type.
13361 elsif not Is_Anonymous_Access_Type
(Exp_Type
) then
13365 pragma Assert
(Is_Itype
(Exp_Type
));
13366 Associated_Node
:= Associated_Node_For_Itype
(Exp_Type
);
13368 -- The "statically deeper relationship" applies to some
13369 -- anonymous access types and not to others. Return
13370 -- True for the cases where it does not apply. Also check
13371 -- recursively for the
13372 -- <prefix>.all.Access_Discrim.all.Access_Discrim case,
13373 -- where the correct result depends on <prefix>.
13375 return Nkind
(Associated_Node
) in
13376 N_Procedure_Specification |
-- access parameter
13377 N_Function_Specification |
-- access parameter
13378 N_Object_Declaration
-- saooaaat
13379 or else Is_Discrim_Of_Bad_Access_Conversion_Argument
(Deref_Prefix
);
13380 end Is_Discrim_Of_Bad_Access_Conversion_Argument
;
13382 ----------------------------
13383 -- Valid_Array_Conversion --
13384 ----------------------------
13386 function Valid_Array_Conversion
return Boolean is
13387 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
13388 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
13390 Opnd_Index
: Node_Id
;
13391 Opnd_Index_Type
: Entity_Id
;
13393 Target_Comp_Type
: constant Entity_Id
:=
13394 Component_Type
(Target_Type
);
13395 Target_Comp_Base
: constant Entity_Id
:=
13396 Base_Type
(Target_Comp_Type
);
13398 Target_Index
: Node_Id
;
13399 Target_Index_Type
: Entity_Id
;
13402 -- Error if wrong number of dimensions
13405 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
13408 ("incompatible number of dimensions for conversion", Operand
);
13411 -- Number of dimensions matches
13414 -- Loop through indexes of the two arrays
13416 Target_Index
:= First_Index
(Target_Type
);
13417 Opnd_Index
:= First_Index
(Opnd_Type
);
13418 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
13419 Target_Index_Type
:= Etype
(Target_Index
);
13420 Opnd_Index_Type
:= Etype
(Opnd_Index
);
13422 -- Error if index types are incompatible
13424 if not (Is_Integer_Type
(Target_Index_Type
)
13425 and then Is_Integer_Type
(Opnd_Index_Type
))
13426 and then (Root_Type
(Target_Index_Type
)
13427 /= Root_Type
(Opnd_Index_Type
))
13430 ("incompatible index types for array conversion",
13435 Next_Index
(Target_Index
);
13436 Next_Index
(Opnd_Index
);
13439 -- If component types have same base type, all set
13441 if Target_Comp_Base
= Opnd_Comp_Base
then
13444 -- Here if base types of components are not the same. The only
13445 -- time this is allowed is if we have anonymous access types.
13447 -- The conversion of arrays of anonymous access types can lead
13448 -- to dangling pointers. AI-392 formalizes the accessibility
13449 -- checks that must be applied to such conversions to prevent
13450 -- out-of-scope references.
13452 elsif Ekind
(Target_Comp_Base
) in
13453 E_Anonymous_Access_Type
13454 | E_Anonymous_Access_Subprogram_Type
13455 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
13457 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
13459 if Type_Access_Level
(Target_Type
) <
13460 Deepest_Type_Access_Level
(Opnd_Type
)
13462 if In_Instance_Body
then
13463 Error_Msg_Warn
:= SPARK_Mode
/= On
;
13465 ("source array type has deeper accessibility "
13466 & "level than target<<", Operand
);
13467 Conversion_Error_N
("\Program_Error [<<", Operand
);
13469 Make_Raise_Program_Error
(Sloc
(N
),
13470 Reason
=> PE_Accessibility_Check_Failed
));
13471 Set_Etype
(N
, Target_Type
);
13474 -- Conversion not allowed because of accessibility levels
13478 ("source array type has deeper accessibility "
13479 & "level than target", Operand
);
13487 -- All other cases where component base types do not match
13491 ("incompatible component types for array conversion",
13496 -- Check that component subtypes statically match. For numeric
13497 -- types this means that both must be either constrained or
13498 -- unconstrained. For enumeration types the bounds must match.
13499 -- All of this is checked in Subtypes_Statically_Match.
13501 if not Subtypes_Statically_Match
13502 (Target_Comp_Type
, Opnd_Comp_Type
)
13505 ("component subtypes must statically match", Operand
);
13511 end Valid_Array_Conversion
;
13513 -----------------------------
13514 -- Valid_Tagged_Conversion --
13515 -----------------------------
13517 function Valid_Tagged_Conversion
13518 (Target_Type
: Entity_Id
;
13519 Opnd_Type
: Entity_Id
) return Boolean
13522 -- Upward conversions are allowed (RM 4.6(22))
13524 if Covers
(Target_Type
, Opnd_Type
)
13525 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
13529 -- Downward conversion are allowed if the operand is class-wide
13532 elsif Is_Class_Wide_Type
(Opnd_Type
)
13533 and then Covers
(Opnd_Type
, Target_Type
)
13537 elsif Covers
(Opnd_Type
, Target_Type
)
13538 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
13541 Conversion_Check
(False,
13542 "downward conversion of tagged objects not allowed");
13544 -- Ada 2005 (AI-251): The conversion to/from interface types is
13545 -- always valid. The types involved may be class-wide (sub)types.
13547 elsif Is_Interface
(Etype
(Base_Type
(Target_Type
)))
13548 or else Is_Interface
(Etype
(Base_Type
(Opnd_Type
)))
13552 -- If the operand is a class-wide type obtained through a limited_
13553 -- with clause, and the context includes the nonlimited view, use
13554 -- it to determine whether the conversion is legal.
13556 elsif Is_Class_Wide_Type
(Opnd_Type
)
13557 and then From_Limited_With
(Opnd_Type
)
13558 and then Present
(Non_Limited_View
(Etype
(Opnd_Type
)))
13559 and then Is_Interface
(Non_Limited_View
(Etype
(Opnd_Type
)))
13563 elsif Is_Access_Type
(Opnd_Type
)
13564 and then Is_Interface
(Directly_Designated_Type
(Opnd_Type
))
13569 Conversion_Error_NE
13570 ("invalid tagged conversion, not compatible with}",
13571 N
, First_Subtype
(Opnd_Type
));
13574 end Valid_Tagged_Conversion
;
13576 -- Start of processing for Valid_Conversion
13579 Check_Parameterless_Call
(Operand
);
13581 if Is_Overloaded
(Operand
) then
13591 -- Remove procedure calls, which syntactically cannot appear in
13592 -- this context, but which cannot be removed by type checking,
13593 -- because the context does not impose a type.
13595 -- The node may be labelled overloaded, but still contain only one
13596 -- interpretation because others were discarded earlier. If this
13597 -- is the case, retain the single interpretation if legal.
13599 Get_First_Interp
(Operand
, I
, It
);
13600 Opnd_Type
:= It
.Typ
;
13601 Get_Next_Interp
(I
, It
);
13603 if Present
(It
.Typ
)
13604 and then Opnd_Type
/= Standard_Void_Type
13606 -- More than one candidate interpretation is available
13608 Get_First_Interp
(Operand
, I
, It
);
13609 while Present
(It
.Typ
) loop
13610 if It
.Typ
= Standard_Void_Type
then
13614 -- When compiling for a system where Address is of a visible
13615 -- integer type, spurious ambiguities can be produced when
13616 -- arithmetic operations have a literal operand and return
13617 -- System.Address or a descendant of it. These ambiguities
13618 -- are usually resolved by the context, but for conversions
13619 -- there is no context type and the removal of the spurious
13620 -- operations must be done explicitly here.
13622 if not Address_Is_Private
13623 and then Is_Descendant_Of_Address
(It
.Typ
)
13628 Get_Next_Interp
(I
, It
);
13632 Get_First_Interp
(Operand
, I
, It
);
13636 if No
(It
.Typ
) then
13637 Conversion_Error_N
("illegal operand in conversion", Operand
);
13641 Get_Next_Interp
(I
, It
);
13643 if Present
(It
.Typ
) then
13646 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
13648 if It1
= No_Interp
then
13650 ("ambiguous operand in conversion", Operand
);
13652 -- If the interpretation involves a standard operator, use
13653 -- the location of the type, which may be user-defined.
13655 if Sloc
(It
.Nam
) = Standard_Location
then
13656 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
13658 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
13661 Conversion_Error_N
-- CODEFIX
13662 ("\\possible interpretation#!", Operand
);
13664 if Sloc
(N1
) = Standard_Location
then
13665 Error_Msg_Sloc
:= Sloc
(T1
);
13667 Error_Msg_Sloc
:= Sloc
(N1
);
13670 Conversion_Error_N
-- CODEFIX
13671 ("\\possible interpretation#!", Operand
);
13677 Set_Etype
(Operand
, It1
.Typ
);
13678 Opnd_Type
:= It1
.Typ
;
13682 -- Deal with conversion of integer type to address if the pragma
13683 -- Allow_Integer_Address is in effect. We convert the conversion to
13684 -- an unchecked conversion in this case and we are all done.
13686 if Address_Integer_Convert_OK
(Opnd_Type
, Target_Type
) then
13687 Rewrite
(N
, Unchecked_Convert_To
(Target_Type
, Expression
(N
)));
13688 Analyze_And_Resolve
(N
, Target_Type
);
13692 -- If we are within a child unit, check whether the type of the
13693 -- expression has an ancestor in a parent unit, in which case it
13694 -- belongs to its derivation class even if the ancestor is private.
13695 -- See RM 7.3.1 (5.2/3).
13697 Inc_Ancestor
:= Get_Incomplete_View_Of_Ancestor
(Opnd_Type
);
13701 if Is_Numeric_Type
(Target_Type
) then
13703 -- A universal fixed expression can be converted to any numeric type
13705 if Opnd_Type
= Universal_Fixed
then
13708 -- Also no need to check when in an instance or inlined body, because
13709 -- the legality has been established when the template was analyzed.
13710 -- Furthermore, numeric conversions may occur where only a private
13711 -- view of the operand type is visible at the instantiation point.
13712 -- This results in a spurious error if we check that the operand type
13713 -- is a numeric type.
13715 -- Note: in a previous version of this unit, the following tests were
13716 -- applied only for generated code (Comes_From_Source set to False),
13717 -- but in fact the test is required for source code as well, since
13718 -- this situation can arise in source code.
13720 elsif In_Instance_Code
or else In_Inlined_Body
then
13723 -- Otherwise we need the conversion check
13726 return Conversion_Check
13727 (Is_Numeric_Type
(Opnd_Type
)
13729 (Present
(Inc_Ancestor
)
13730 and then Is_Numeric_Type
(Inc_Ancestor
)),
13731 "illegal operand for numeric conversion");
13736 elsif Is_Array_Type
(Target_Type
) then
13737 if not Is_Array_Type
(Opnd_Type
)
13738 or else Opnd_Type
= Any_Composite
13739 or else Opnd_Type
= Any_String
13742 ("illegal operand for array conversion", Operand
);
13746 return Valid_Array_Conversion
;
13749 -- Ada 2005 (AI-251): Internally generated conversions of access to
13750 -- interface types added to force the displacement of the pointer to
13751 -- reference the corresponding dispatch table.
13753 elsif not Comes_From_Source
(N
)
13754 and then Is_Access_Type
(Target_Type
)
13755 and then Is_Interface
(Designated_Type
(Target_Type
))
13759 -- Ada 2005 (AI-251): Anonymous access types where target references an
13762 elsif Is_Access_Type
(Opnd_Type
)
13763 and then Ekind
(Target_Type
) in
13764 E_General_Access_Type | E_Anonymous_Access_Type
13765 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
13767 -- Check the static accessibility rule of 4.6(17). Note that the
13768 -- check is not enforced when within an instance body, since the
13769 -- RM requires such cases to be caught at run time.
13771 -- If the operand is a rewriting of an allocator no check is needed
13772 -- because there are no accessibility issues.
13774 if Nkind
(Original_Node
(N
)) = N_Allocator
then
13777 elsif Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
13778 if Type_Access_Level
(Opnd_Type
) >
13779 Deepest_Type_Access_Level
(Target_Type
)
13781 -- In an instance, this is a run-time check, but one we know
13782 -- will fail, so generate an appropriate warning. The raise
13783 -- will be generated by Expand_N_Type_Conversion.
13785 if In_Instance_Body
then
13786 Error_Msg_Warn
:= SPARK_Mode
/= On
;
13788 ("cannot convert local pointer to non-local access type<<",
13790 Conversion_Error_N
("\Program_Error [<<", Operand
);
13794 ("cannot convert local pointer to non-local access type",
13799 -- Special accessibility checks are needed in the case of access
13800 -- discriminants declared for a limited type.
13802 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
13803 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
13805 -- When the operand is a selected access discriminant the check
13806 -- needs to be made against the level of the object denoted by
13807 -- the prefix of the selected name (Accessibility_Level handles
13808 -- checking the prefix of the operand for this case).
13810 if Nkind
(Operand
) = N_Selected_Component
13811 and then Static_Accessibility_Level
13812 (Operand
, Zero_On_Dynamic_Level
)
13813 > Deepest_Type_Access_Level
(Target_Type
)
13815 -- In an instance, this is a run-time check, but one we know
13816 -- will fail, so generate an appropriate warning. The raise
13817 -- will be generated by Expand_N_Type_Conversion.
13819 if In_Instance_Body
then
13820 Error_Msg_Warn
:= SPARK_Mode
/= On
;
13822 ("cannot convert access discriminant to non-local "
13823 & "access type<<", Operand
);
13824 Conversion_Error_N
("\Program_Error [<<", Operand
);
13826 -- Real error if not in instance body
13830 ("cannot convert access discriminant to non-local "
13831 & "access type", Operand
);
13836 -- The case of a reference to an access discriminant from
13837 -- within a limited type declaration (which will appear as
13838 -- a discriminal) is always illegal because the level of the
13839 -- discriminant is considered to be deeper than any (nameable)
13842 if Is_Entity_Name
(Operand
)
13843 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
13845 Ekind
(Entity
(Operand
)) in E_In_Parameter | E_Constant
13846 and then Present
(Discriminal_Link
(Entity
(Operand
)))
13849 ("discriminant has deeper accessibility level than target",
13858 -- General and anonymous access types
13860 elsif Ekind
(Target_Type
) in
13861 E_General_Access_Type | E_Anonymous_Access_Type
13864 (Is_Access_Type
(Opnd_Type
)
13866 Ekind
(Opnd_Type
) not in
13867 E_Access_Subprogram_Type |
13868 E_Access_Protected_Subprogram_Type
,
13869 "must be an access-to-object type")
13871 if Is_Access_Constant
(Opnd_Type
)
13872 and then not Is_Access_Constant
(Target_Type
)
13875 ("access-to-constant operand type not allowed", Operand
);
13879 -- Check the static accessibility rule of 4.6(17). Note that the
13880 -- check is not enforced when within an instance body, since the RM
13881 -- requires such cases to be caught at run time.
13883 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
13884 or else Is_Local_Anonymous_Access
(Target_Type
)
13885 or else Nkind
(Associated_Node_For_Itype
(Target_Type
)) =
13886 N_Object_Declaration
13888 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
13889 -- conversions from an anonymous access type to a named general
13890 -- access type. Such conversions are not allowed in the case of
13891 -- access parameters and stand-alone objects of an anonymous
13892 -- access type. The implicit conversion case is recognized by
13893 -- testing that Comes_From_Source is False and that it's been
13894 -- rewritten. The Comes_From_Source test isn't sufficient because
13895 -- nodes in inlined calls to predefined library routines can have
13896 -- Comes_From_Source set to False. (Is there a better way to test
13897 -- for implicit conversions???).
13899 -- Do not treat a rewritten 'Old attribute reference like other
13900 -- rewrite substitutions. This makes a difference, for example,
13901 -- in the case where we are generating the expansion of a
13902 -- membership test of the form
13903 -- Saooaaat'Old in Named_Access_Type
13904 -- because in this case Valid_Conversion needs to return True
13905 -- (otherwise the expansion will be False - see the call site
13906 -- in exp_ch4.adb).
13908 if Ada_Version
>= Ada_2012
13909 and then not Comes_From_Source
(N
)
13910 and then Is_Rewrite_Substitution
(N
)
13911 and then not Is_Attribute_Old
(Original_Node
(N
))
13912 and then Ekind
(Base_Type
(Target_Type
)) = E_General_Access_Type
13913 and then Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
13915 if Is_Itype
(Opnd_Type
) then
13917 -- When applying restriction No_Dynamic_Accessibility_Check,
13918 -- implicit conversions are allowed when the operand type is
13919 -- not deeper than the target type.
13921 if No_Dynamic_Accessibility_Checks_Enabled
(N
) then
13922 if Type_Access_Level
(Opnd_Type
)
13923 > Deepest_Type_Access_Level
(Target_Type
)
13926 ("operand has deeper level than target", Operand
);
13929 -- Implicit conversions aren't allowed for objects of an
13930 -- anonymous access type, since such objects have nonstatic
13931 -- levels in Ada 2012.
13933 elsif Nkind
(Associated_Node_For_Itype
(Opnd_Type
))
13934 = N_Object_Declaration
13937 ("implicit conversion of stand-alone anonymous "
13938 & "access object not allowed", Operand
);
13941 -- Implicit conversions aren't allowed for anonymous access
13942 -- parameters. We exclude anonymous access results as well
13943 -- as universal_access "=".
13945 elsif not Is_Local_Anonymous_Access
(Opnd_Type
)
13946 and then Nkind
(Associated_Node_For_Itype
(Opnd_Type
)) in
13947 N_Function_Specification |
13948 N_Procedure_Specification
13949 and then Nkind
(Parent
(N
)) not in N_Op_Eq | N_Op_Ne
13952 ("implicit conversion of anonymous access parameter "
13953 & "not allowed", Operand
);
13956 -- Detect access discriminant values that are illegal
13957 -- implicit anonymous-to-named access conversion operands.
13959 elsif Is_Discrim_Of_Bad_Access_Conversion_Argument
(Operand
)
13962 ("implicit conversion of anonymous access value "
13963 & "not allowed", Operand
);
13966 -- In other cases, the level of the operand's type must be
13967 -- statically less deep than that of the target type, else
13968 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
13970 elsif Type_Access_Level
(Opnd_Type
) >
13971 Deepest_Type_Access_Level
(Target_Type
)
13974 ("implicit conversion of anonymous access value "
13975 & "violates accessibility", Operand
);
13980 -- Check if the operand is deeper than the target type, taking
13981 -- care to avoid the case where we are converting a result of a
13982 -- function returning an anonymous access type since the "master
13983 -- of the call" would be target type of the conversion unless
13984 -- the target type is anonymous access as well - see RM 3.10.2
13987 -- Note that when the restriction No_Dynamic_Accessibility_Checks
13988 -- is in effect wei also want to proceed with the conversion check
13989 -- described above.
13991 elsif Type_Access_Level
(Opnd_Type
, Assoc_Ent
=> Operand
)
13992 > Deepest_Type_Access_Level
(Target_Type
)
13993 and then (Nkind
(Associated_Node_For_Itype
(Opnd_Type
))
13994 /= N_Function_Specification
13995 or else Ekind
(Target_Type
) in Anonymous_Access_Kind
13996 or else No_Dynamic_Accessibility_Checks_Enabled
(N
))
13998 -- Check we are not in a return value ???
14000 and then (not In_Return_Value
(N
)
14002 Nkind
(Associated_Node_For_Itype
(Target_Type
))
14003 = N_Component_Declaration
)
14005 -- In an instance, this is a run-time check, but one we know
14006 -- will fail, so generate an appropriate warning. The raise
14007 -- will be generated by Expand_N_Type_Conversion.
14009 if In_Instance_Body
then
14010 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14012 ("cannot convert local pointer to non-local access type<<",
14014 Conversion_Error_N
("\Program_Error [<<", Operand
);
14016 -- If not in an instance body, this is a real error
14019 -- Avoid generation of spurious error message
14021 if not Error_Posted
(N
) then
14023 ("cannot convert local pointer to non-local access type",
14030 -- Special accessibility checks are needed in the case of access
14031 -- discriminants declared for a limited type.
14033 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
14034 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
14036 -- When the operand is a selected access discriminant the check
14037 -- needs to be made against the level of the object denoted by
14038 -- the prefix of the selected name (Accessibility_Level handles
14039 -- checking the prefix of the operand for this case).
14041 if Nkind
(Operand
) = N_Selected_Component
14042 and then Static_Accessibility_Level
14043 (Operand
, Zero_On_Dynamic_Level
)
14044 > Deepest_Type_Access_Level
(Target_Type
)
14046 -- In an instance, this is a run-time check, but one we know
14047 -- will fail, so generate an appropriate warning. The raise
14048 -- will be generated by Expand_N_Type_Conversion.
14050 if In_Instance_Body
then
14051 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14053 ("cannot convert access discriminant to non-local "
14054 & "access type<<", Operand
);
14055 Conversion_Error_N
("\Program_Error [<<", Operand
);
14057 -- If not in an instance body, this is a real error
14061 ("cannot convert access discriminant to non-local "
14062 & "access type", Operand
);
14067 -- The case of a reference to an access discriminant from
14068 -- within a limited type declaration (which will appear as
14069 -- a discriminal) is always illegal because the level of the
14070 -- discriminant is considered to be deeper than any (nameable)
14073 if Is_Entity_Name
(Operand
)
14075 Ekind
(Entity
(Operand
)) in E_In_Parameter | E_Constant
14076 and then Present
(Discriminal_Link
(Entity
(Operand
)))
14079 ("discriminant has deeper accessibility level than target",
14086 -- In the presence of limited_with clauses we have to use nonlimited
14087 -- views, if available.
14089 Check_Limited
: declare
14090 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
14091 -- Helper function to handle limited views
14093 --------------------------
14094 -- Full_Designated_Type --
14095 --------------------------
14097 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
14098 Desig
: constant Entity_Id
:= Designated_Type
(T
);
14101 -- Handle the limited view of a type
14103 if From_Limited_With
(Desig
)
14104 and then Has_Non_Limited_View
(Desig
)
14106 return Available_View
(Desig
);
14110 end Full_Designated_Type
;
14112 -- Local Declarations
14114 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
14115 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
14117 Same_Base
: constant Boolean :=
14118 Base_Type
(Target
) = Base_Type
(Opnd
);
14120 -- Start of processing for Check_Limited
14123 if Is_Tagged_Type
(Target
) then
14124 return Valid_Tagged_Conversion
(Target
, Opnd
);
14127 if not Same_Base
then
14128 Conversion_Error_NE
14129 ("target designated type not compatible with }",
14130 N
, Base_Type
(Opnd
));
14133 -- Ada 2005 AI-384: legality rule is symmetric in both
14134 -- designated types. The conversion is legal (with possible
14135 -- constraint check) if either designated type is
14138 elsif Subtypes_Statically_Match
(Target
, Opnd
)
14140 (Has_Discriminants
(Target
)
14142 (not Is_Constrained
(Opnd
)
14143 or else not Is_Constrained
(Target
)))
14145 -- Special case, if Value_Size has been used to make the
14146 -- sizes different, the conversion is not allowed even
14147 -- though the subtypes statically match.
14149 if Known_Static_RM_Size
(Target
)
14150 and then Known_Static_RM_Size
(Opnd
)
14151 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
14153 Conversion_Error_NE
14154 ("target designated subtype not compatible with }",
14156 Conversion_Error_NE
14157 ("\because sizes of the two designated subtypes differ",
14161 -- Normal case where conversion is allowed
14169 ("target designated subtype not compatible with }",
14176 -- Access to subprogram types. If the operand is an access parameter,
14177 -- the type has a deeper accessibility that any master, and cannot be
14178 -- assigned. We must make an exception if the conversion is part of an
14179 -- assignment and the target is the return object of an extended return
14180 -- statement, because in that case the accessibility check takes place
14181 -- after the return.
14183 elsif Is_Access_Subprogram_Type
(Target_Type
)
14185 -- Note: this test of Opnd_Type is there to prevent entering this
14186 -- branch in the case of a remote access to subprogram type, which
14187 -- is internally represented as an E_Record_Type.
14189 and then Is_Access_Type
(Opnd_Type
)
14191 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
14192 and then Is_Entity_Name
(Operand
)
14193 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
14195 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
14196 or else not Is_Entity_Name
(Name
(Parent
(N
)))
14197 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
14200 ("illegal attempt to store anonymous access to subprogram",
14203 ("\value has deeper accessibility than any master "
14204 & "(RM 3.10.2 (13))",
14208 ("\use named access type for& instead of access parameter",
14209 Operand
, Entity
(Operand
));
14212 -- Check that the designated types are subtype conformant
14214 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
14215 Old_Id
=> Designated_Type
(Opnd_Type
),
14218 -- Check the static accessibility rule of 4.6(20)
14220 if Type_Access_Level
(Opnd_Type
) >
14221 Deepest_Type_Access_Level
(Target_Type
)
14224 ("operand type has deeper accessibility level than target",
14227 -- Check that if the operand type is declared in a generic body,
14228 -- then the target type must be declared within that same body
14229 -- (enforces last sentence of 4.6(20)).
14231 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
14233 O_Gen
: constant Node_Id
:=
14234 Enclosing_Generic_Body
(Opnd_Type
);
14239 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
14240 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
14241 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
14244 if T_Gen
/= O_Gen
then
14246 ("target type must be declared in same generic body "
14247 & "as operand type", N
);
14252 -- Check that the strub modes are compatible.
14253 -- We wish to reject explicit conversions only for
14254 -- incompatible modes.
14256 return Conversion_Check
14257 (Compatible_Strub_Modes
14258 (Designated_Type
(Target_Type
),
14259 Designated_Type
(Opnd_Type
)),
14260 "incompatible `strub` modes");
14262 -- Remote access to subprogram types
14264 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
14265 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
14267 -- It is valid to convert from one RAS type to another provided
14268 -- that their specification statically match.
14270 -- Note: at this point, remote access to subprogram types have been
14271 -- expanded to their E_Record_Type representation, and we need to
14272 -- go back to the original access type definition using the
14273 -- Corresponding_Remote_Type attribute in order to check that the
14274 -- designated profiles match.
14276 pragma Assert
(Ekind
(Target_Type
) = E_Record_Type
);
14277 pragma Assert
(Ekind
(Opnd_Type
) = E_Record_Type
);
14279 Check_Subtype_Conformant
14281 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
14283 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
14287 -- Check that the strub modes are compatible.
14288 -- We wish to reject explicit conversions only for
14289 -- incompatible modes.
14291 return Conversion_Check
14292 (Compatible_Strub_Modes
14293 (Designated_Type
(Target_Type
),
14294 Designated_Type
(Opnd_Type
)),
14295 "incompatible `strub` modes");
14297 -- If it was legal in the generic, it's legal in the instance
14299 elsif In_Instance_Body
then
14302 -- If both are tagged types, check legality of view conversions
14304 elsif Is_Tagged_Type
(Target_Type
)
14306 Is_Tagged_Type
(Opnd_Type
)
14308 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
14310 -- Types derived from the same root type are convertible
14312 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
14315 -- In an instance or an inlined body, there may be inconsistent views of
14316 -- the same type, or of types derived from a common root.
14318 elsif (In_Instance
or In_Inlined_Body
)
14320 Root_Type
(Underlying_Type
(Target_Type
)) =
14321 Root_Type
(Underlying_Type
(Opnd_Type
))
14325 -- Special check for common access type error case
14327 elsif Ekind
(Target_Type
) = E_Access_Type
14328 and then Is_Access_Type
(Opnd_Type
)
14330 Conversion_Error_N
("target type must be general access type!", N
);
14331 Conversion_Error_NE
-- CODEFIX
14332 ("\add ALL to }!", N
, Target_Type
);
14335 -- Here we have a real conversion error
14338 -- Check for missing regular with_clause when only a limited view of
14339 -- target is available.
14341 if From_Limited_With
(Opnd_Type
) and then In_Package_Body
then
14342 Conversion_Error_NE
14343 ("invalid conversion, not compatible with limited view of }",
14345 Conversion_Error_NE
14346 ("\add with_clause for& to current unit!", N
, Scope
(Opnd_Type
));
14348 elsif Is_Access_Type
(Opnd_Type
)
14349 and then From_Limited_With
(Designated_Type
(Opnd_Type
))
14350 and then In_Package_Body
14352 Conversion_Error_NE
14353 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
14354 Conversion_Error_NE
14355 ("\add with_clause for& to current unit!",
14356 N
, Scope
(Designated_Type
(Opnd_Type
)));
14359 Conversion_Error_NE
14360 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
14365 end Valid_Conversion
;