1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Debug
; use Debug
;
29 with Debug_A
; use Debug_A
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Expander
; use Expander
;
33 with Exp_Disp
; use Exp_Disp
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Ch7
; use Exp_Ch7
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Exp_Util
; use Exp_Util
;
38 with Fname
; use Fname
;
39 with Freeze
; use Freeze
;
40 with Inline
; use Inline
;
41 with Itypes
; use Itypes
;
43 with Lib
.Xref
; use Lib
.Xref
;
44 with Namet
; use Namet
;
45 with Nmake
; use Nmake
;
46 with Nlists
; use Nlists
;
48 with Output
; use Output
;
49 with Restrict
; use Restrict
;
50 with Rident
; use Rident
;
51 with Rtsfind
; use Rtsfind
;
53 with Sem_Aux
; use Sem_Aux
;
54 with Sem_Aggr
; use Sem_Aggr
;
55 with Sem_Attr
; use Sem_Attr
;
56 with Sem_Cat
; use Sem_Cat
;
57 with Sem_Ch4
; use Sem_Ch4
;
58 with Sem_Ch6
; use Sem_Ch6
;
59 with Sem_Ch8
; use Sem_Ch8
;
60 with Sem_Ch13
; use Sem_Ch13
;
61 with Sem_Dim
; use Sem_Dim
;
62 with Sem_Disp
; use Sem_Disp
;
63 with Sem_Dist
; use Sem_Dist
;
64 with Sem_Elim
; use Sem_Elim
;
65 with Sem_Elab
; use Sem_Elab
;
66 with Sem_Eval
; use Sem_Eval
;
67 with Sem_Intr
; use Sem_Intr
;
68 with Sem_Util
; use Sem_Util
;
69 with Targparm
; use Targparm
;
70 with Sem_Type
; use Sem_Type
;
71 with Sem_Warn
; use Sem_Warn
;
72 with Sinfo
; use Sinfo
;
73 with Sinfo
.CN
; use Sinfo
.CN
;
74 with Snames
; use Snames
;
75 with Stand
; use Stand
;
76 with Stringt
; use Stringt
;
77 with Style
; use Style
;
78 with Tbuild
; use Tbuild
;
79 with Uintp
; use Uintp
;
80 with Urealp
; use Urealp
;
82 package body Sem_Res
is
84 -----------------------
85 -- Local Subprograms --
86 -----------------------
88 -- Second pass (top-down) type checking and overload resolution procedures
89 -- Typ is the type required by context. These procedures propagate the type
90 -- information recursively to the descendants of N. If the node is not
91 -- overloaded, its Etype is established in the first pass. If overloaded,
92 -- the Resolve routines set the correct type. For arith. operators, the
93 -- Etype is the base type of the context.
95 -- Note that Resolve_Attribute is separated off in Sem_Attr
97 procedure Check_Discriminant_Use
(N
: Node_Id
);
98 -- Enforce the restrictions on the use of discriminants when constraining
99 -- a component of a discriminated type (record or concurrent type).
101 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
);
102 -- Given a node for an operator associated with type T, check that
103 -- the operator is visible. Operators all of whose operands are
104 -- universal must be checked for visibility during resolution
105 -- because their type is not determinable based on their operands.
107 procedure Check_Fully_Declared_Prefix
110 -- Check that the type of the prefix of a dereference is not incomplete
112 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean;
113 -- Given a call node, N, which is known to occur immediately within the
114 -- subprogram being called, determines whether it is a detectable case of
115 -- an infinite recursion, and if so, outputs appropriate messages. Returns
116 -- True if an infinite recursion is detected, and False otherwise.
118 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
);
119 -- If the type of the object being initialized uses the secondary stack
120 -- directly or indirectly, create a transient scope for the call to the
121 -- init proc. This is because we do not create transient scopes for the
122 -- initialization of individual components within the init proc itself.
123 -- Could be optimized away perhaps?
125 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
);
126 -- N is the node for a logical operator. If the operator is predefined, and
127 -- the root type of the operands is Standard.Boolean, then a check is made
128 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
129 -- the style check for Style_Check_Boolean_And_Or.
131 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean;
132 -- Determine whether E is an access type declared by an access declaration,
133 -- and not an (anonymous) allocator type.
135 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean;
136 -- Utility to check whether the entity for an operator is a predefined
137 -- operator, in which case the expression is left as an operator in the
138 -- tree (else it is rewritten into a call). An instance of an intrinsic
139 -- conversion operation may be given an operator name, but is not treated
140 -- like an operator. Note that an operator that is an imported back-end
141 -- builtin has convention Intrinsic, but is expected to be rewritten into
142 -- a call, so such an operator is not treated as predefined by this
145 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
);
146 -- If a default expression in entry call N depends on the discriminants
147 -- of the task, it must be replaced with a reference to the discriminant
148 -- of the task being called.
150 procedure Resolve_Op_Concat_Arg
155 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
156 -- concatenation operator. The operand is either of the array type or of
157 -- the component type. If the operand is an aggregate, and the component
158 -- type is composite, this is ambiguous if component type has aggregates.
160 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
);
161 -- Does the first part of the work of Resolve_Op_Concat
163 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
);
164 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
165 -- has been resolved. See Resolve_Op_Concat for details.
167 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
);
168 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
);
169 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
);
170 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
171 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
172 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
);
173 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
);
174 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
);
175 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
);
176 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
);
177 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
178 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
);
179 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
);
180 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
181 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
);
182 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
);
183 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
);
184 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
);
185 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
);
186 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
);
187 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
);
188 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
189 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
190 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
);
191 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
192 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
);
193 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
);
194 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
);
195 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
);
196 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
);
197 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
198 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
199 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
);
200 procedure Resolve_Unchecked_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
201 procedure Resolve_Unchecked_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
203 function Operator_Kind
205 Is_Binary
: Boolean) return Node_Kind
;
206 -- Utility to map the name of an operator into the corresponding Node. Used
207 -- by other node rewriting procedures.
209 procedure Resolve_Actuals
(N
: Node_Id
; Nam
: Entity_Id
);
210 -- Resolve actuals of call, and add default expressions for missing ones.
211 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
212 -- called subprogram.
214 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
);
215 -- Called from Resolve_Call, when the prefix denotes an entry or element
216 -- of entry family. Actuals are resolved as for subprograms, and the node
217 -- is rebuilt as an entry call. Also called for protected operations. Typ
218 -- is the context type, which is used when the operation is a protected
219 -- function with no arguments, and the return value is indexed.
221 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
222 -- A call to a user-defined intrinsic operator is rewritten as a call to
223 -- the corresponding predefined operator, with suitable conversions. Note
224 -- that this applies only for intrinsic operators that denote predefined
225 -- operators, not ones that are intrinsic imports of back-end builtins.
227 procedure Resolve_Intrinsic_Unary_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
228 -- Ditto, for arithmetic unary operators
230 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
);
231 -- If an operator node resolves to a call to a user-defined operator,
232 -- rewrite the node as a function call.
234 procedure Make_Call_Into_Operator
238 -- Inverse transformation: if an operator is given in functional notation,
239 -- then after resolving the node, transform into an operator node, so
240 -- that operands are resolved properly. Recall that predefined operators
241 -- do not have a full signature and special resolution rules apply.
243 procedure Rewrite_Renamed_Operator
247 -- An operator can rename another, e.g. in an instantiation. In that
248 -- case, the proper operator node must be constructed and resolved.
250 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
);
251 -- The String_Literal_Subtype is built for all strings that are not
252 -- operands of a static concatenation operation. If the argument is
253 -- not a N_String_Literal node, then the call has no effect.
255 procedure Set_Slice_Subtype
(N
: Node_Id
);
256 -- Build subtype of array type, with the range specified by the slice
258 procedure Simplify_Type_Conversion
(N
: Node_Id
);
259 -- Called after N has been resolved and evaluated, but before range checks
260 -- have been applied. Currently simplifies a combination of floating-point
261 -- to integer conversion and Rounding or Truncation attribute.
263 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
;
264 -- A universal_fixed expression in an universal context is unambiguous if
265 -- there is only one applicable fixed point type. Determining whether there
266 -- is only one requires a search over all visible entities, and happens
267 -- only in very pathological cases (see 6115-006).
269 -------------------------
270 -- Ambiguous_Character --
271 -------------------------
273 procedure Ambiguous_Character
(C
: Node_Id
) is
277 if Nkind
(C
) = N_Character_Literal
then
278 Error_Msg_N
("ambiguous character literal", C
);
280 -- First the ones in Standard
282 Error_Msg_N
("\\possible interpretation: Character!", C
);
283 Error_Msg_N
("\\possible interpretation: Wide_Character!", C
);
285 -- Include Wide_Wide_Character in Ada 2005 mode
287 if Ada_Version
>= Ada_2005
then
288 Error_Msg_N
("\\possible interpretation: Wide_Wide_Character!", C
);
291 -- Now any other types that match
293 E
:= Current_Entity
(C
);
294 while Present
(E
) loop
295 Error_Msg_NE
("\\possible interpretation:}!", C
, Etype
(E
));
299 end Ambiguous_Character
;
301 -------------------------
302 -- Analyze_And_Resolve --
303 -------------------------
305 procedure Analyze_And_Resolve
(N
: Node_Id
) is
309 end Analyze_And_Resolve
;
311 procedure Analyze_And_Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
315 end Analyze_And_Resolve
;
317 -- Versions with check(s) suppressed
319 procedure Analyze_And_Resolve
324 Scop
: constant Entity_Id
:= Current_Scope
;
327 if Suppress
= All_Checks
then
329 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
331 Scope_Suppress
.Suppress
:= (others => True);
332 Analyze_And_Resolve
(N
, Typ
);
333 Scope_Suppress
.Suppress
:= Sva
;
338 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
340 Scope_Suppress
.Suppress
(Suppress
) := True;
341 Analyze_And_Resolve
(N
, Typ
);
342 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
346 if Current_Scope
/= Scop
347 and then Scope_Is_Transient
349 -- This can only happen if a transient scope was created for an inner
350 -- expression, which will be removed upon completion of the analysis
351 -- of an enclosing construct. The transient scope must have the
352 -- suppress status of the enclosing environment, not of this Analyze
355 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
358 end Analyze_And_Resolve
;
360 procedure Analyze_And_Resolve
364 Scop
: constant Entity_Id
:= Current_Scope
;
367 if Suppress
= All_Checks
then
369 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
371 Scope_Suppress
.Suppress
:= (others => True);
372 Analyze_And_Resolve
(N
);
373 Scope_Suppress
.Suppress
:= Sva
;
378 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
380 Scope_Suppress
.Suppress
(Suppress
) := True;
381 Analyze_And_Resolve
(N
);
382 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
386 if Current_Scope
/= Scop
and then Scope_Is_Transient
then
387 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
390 end Analyze_And_Resolve
;
392 ----------------------------
393 -- Check_Discriminant_Use --
394 ----------------------------
396 procedure Check_Discriminant_Use
(N
: Node_Id
) is
397 PN
: constant Node_Id
:= Parent
(N
);
398 Disc
: constant Entity_Id
:= Entity
(N
);
403 -- Any use in a spec-expression is legal
405 if In_Spec_Expression
then
408 elsif Nkind
(PN
) = N_Range
then
410 -- Discriminant cannot be used to constrain a scalar type
414 if Nkind
(P
) = N_Range_Constraint
415 and then Nkind
(Parent
(P
)) = N_Subtype_Indication
416 and then Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
418 Error_Msg_N
("discriminant cannot constrain scalar type", N
);
420 elsif Nkind
(P
) = N_Index_Or_Discriminant_Constraint
then
422 -- The following check catches the unusual case where a
423 -- discriminant appears within an index constraint that is part of
424 -- a larger expression within a constraint on a component, e.g. "C
425 -- : Int range 1 .. F (new A(1 .. D))". For now we only check case
426 -- of record components, and note that a similar check should also
427 -- apply in the case of discriminant constraints below. ???
429 -- Note that the check for N_Subtype_Declaration below is to
430 -- detect the valid use of discriminants in the constraints of a
431 -- subtype declaration when this subtype declaration appears
432 -- inside the scope of a record type (which is syntactically
433 -- illegal, but which may be created as part of derived type
434 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
437 if Ekind
(Current_Scope
) = E_Record_Type
438 and then Scope
(Disc
) = Current_Scope
440 (Nkind
(Parent
(P
)) = N_Subtype_Indication
442 Nkind_In
(Parent
(Parent
(P
)), N_Component_Definition
,
443 N_Subtype_Declaration
)
444 and then Paren_Count
(N
) = 0)
447 ("discriminant must appear alone in component constraint", N
);
451 -- Detect a common error:
453 -- type R (D : Positive := 100) is record
454 -- Name : String (1 .. D);
457 -- The default value causes an object of type R to be allocated
458 -- with room for Positive'Last characters. The RM does not mandate
459 -- the allocation of the maximum size, but that is what GNAT does
460 -- so we should warn the programmer that there is a problem.
462 Check_Large
: declare
468 function Large_Storage_Type
(T
: Entity_Id
) return Boolean;
469 -- Return True if type T has a large enough range that any
470 -- array whose index type covered the whole range of the type
471 -- would likely raise Storage_Error.
473 ------------------------
474 -- Large_Storage_Type --
475 ------------------------
477 function Large_Storage_Type
(T
: Entity_Id
) return Boolean is
479 -- The type is considered large if its bounds are known at
480 -- compile time and if it requires at least as many bits as
481 -- a Positive to store the possible values.
483 return Compile_Time_Known_Value
(Type_Low_Bound
(T
))
484 and then Compile_Time_Known_Value
(Type_High_Bound
(T
))
486 Minimum_Size
(T
, Biased
=> True) >=
487 RM_Size
(Standard_Positive
);
488 end Large_Storage_Type
;
490 -- Start of processing for Check_Large
493 -- Check that the Disc has a large range
495 if not Large_Storage_Type
(Etype
(Disc
)) then
499 -- If the enclosing type is limited, we allocate only the
500 -- default value, not the maximum, and there is no need for
503 if Is_Limited_Type
(Scope
(Disc
)) then
507 -- Check that it is the high bound
509 if N
/= High_Bound
(PN
)
510 or else No
(Discriminant_Default_Value
(Disc
))
515 -- Check the array allows a large range at this bound. First
520 if Nkind
(SI
) /= N_Subtype_Indication
then
524 T
:= Entity
(Subtype_Mark
(SI
));
526 if not Is_Array_Type
(T
) then
530 -- Next, find the dimension
532 TB
:= First_Index
(T
);
533 CB
:= First
(Constraints
(P
));
535 and then Present
(TB
)
536 and then Present
(CB
)
547 -- Now, check the dimension has a large range
549 if not Large_Storage_Type
(Etype
(TB
)) then
553 -- Warn about the danger
556 ("??creation of & object may raise Storage_Error!",
565 -- Legal case is in index or discriminant constraint
567 elsif Nkind_In
(PN
, N_Index_Or_Discriminant_Constraint
,
568 N_Discriminant_Association
)
570 if Paren_Count
(N
) > 0 then
572 ("discriminant in constraint must appear alone", N
);
574 elsif Nkind
(N
) = N_Expanded_Name
575 and then Comes_From_Source
(N
)
578 ("discriminant must appear alone as a direct name", N
);
583 -- Otherwise, context is an expression. It should not be within (i.e. a
584 -- subexpression of) a constraint for a component.
589 while not Nkind_In
(P
, N_Component_Declaration
,
590 N_Subtype_Indication
,
598 -- If the discriminant is used in an expression that is a bound of a
599 -- scalar type, an Itype is created and the bounds are attached to
600 -- its range, not to the original subtype indication. Such use is of
601 -- course a double fault.
603 if (Nkind
(P
) = N_Subtype_Indication
604 and then Nkind_In
(Parent
(P
), N_Component_Definition
,
605 N_Derived_Type_Definition
)
606 and then D
= Constraint
(P
))
608 -- The constraint itself may be given by a subtype indication,
609 -- rather than by a more common discrete range.
611 or else (Nkind
(P
) = N_Subtype_Indication
613 Nkind
(Parent
(P
)) = N_Index_Or_Discriminant_Constraint
)
614 or else Nkind
(P
) = N_Entry_Declaration
615 or else Nkind
(D
) = N_Defining_Identifier
618 ("discriminant in constraint must appear alone", N
);
621 end Check_Discriminant_Use
;
623 --------------------------------
624 -- Check_For_Visible_Operator --
625 --------------------------------
627 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
) is
629 if Is_Invisible_Operator
(N
, T
) then
630 Error_Msg_NE
-- CODEFIX
631 ("operator for} is not directly visible!", N
, First_Subtype
(T
));
632 Error_Msg_N
-- CODEFIX
633 ("use clause would make operation legal!", N
);
635 end Check_For_Visible_Operator
;
637 ----------------------------------
638 -- Check_Fully_Declared_Prefix --
639 ----------------------------------
641 procedure Check_Fully_Declared_Prefix
646 -- Check that the designated type of the prefix of a dereference is
647 -- not an incomplete type. This cannot be done unconditionally, because
648 -- dereferences of private types are legal in default expressions. This
649 -- case is taken care of in Check_Fully_Declared, called below. There
650 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
652 -- This consideration also applies to similar checks for allocators,
653 -- qualified expressions, and type conversions.
655 -- An additional exception concerns other per-object expressions that
656 -- are not directly related to component declarations, in particular
657 -- representation pragmas for tasks. These will be per-object
658 -- expressions if they depend on discriminants or some global entity.
659 -- If the task has access discriminants, the designated type may be
660 -- incomplete at the point the expression is resolved. This resolution
661 -- takes place within the body of the initialization procedure, where
662 -- the discriminant is replaced by its discriminal.
664 if Is_Entity_Name
(Pref
)
665 and then Ekind
(Entity
(Pref
)) = E_In_Parameter
669 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
670 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
671 -- Analyze_Object_Renaming, and Freeze_Entity.
673 elsif Ada_Version
>= Ada_2005
674 and then Is_Entity_Name
(Pref
)
675 and then Is_Access_Type
(Etype
(Pref
))
676 and then Ekind
(Directly_Designated_Type
(Etype
(Pref
))) =
678 and then Is_Tagged_Type
(Directly_Designated_Type
(Etype
(Pref
)))
682 Check_Fully_Declared
(Typ
, Parent
(Pref
));
684 end Check_Fully_Declared_Prefix
;
686 ------------------------------
687 -- Check_Infinite_Recursion --
688 ------------------------------
690 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean is
694 function Same_Argument_List
return Boolean;
695 -- Check whether list of actuals is identical to list of formals of
696 -- called function (which is also the enclosing scope).
698 ------------------------
699 -- Same_Argument_List --
700 ------------------------
702 function Same_Argument_List
return Boolean is
708 if not Is_Entity_Name
(Name
(N
)) then
711 Subp
:= Entity
(Name
(N
));
714 F
:= First_Formal
(Subp
);
715 A
:= First_Actual
(N
);
716 while Present
(F
) and then Present
(A
) loop
717 if not Is_Entity_Name
(A
)
718 or else Entity
(A
) /= F
728 end Same_Argument_List
;
730 -- Start of processing for Check_Infinite_Recursion
733 -- Special case, if this is a procedure call and is a call to the
734 -- current procedure with the same argument list, then this is for
735 -- sure an infinite recursion and we insert a call to raise SE.
737 if Is_List_Member
(N
)
738 and then List_Length
(List_Containing
(N
)) = 1
739 and then Same_Argument_List
742 P
: constant Node_Id
:= Parent
(N
);
744 if Nkind
(P
) = N_Handled_Sequence_Of_Statements
745 and then Nkind
(Parent
(P
)) = N_Subprogram_Body
746 and then Is_Empty_List
(Declarations
(Parent
(P
)))
748 Error_Msg_Warn
:= SPARK_Mode
/= On
;
749 Error_Msg_N
("!infinite recursion<<", N
);
750 Error_Msg_N
("\!Storage_Error [<<", N
);
752 Make_Raise_Storage_Error
(Sloc
(N
),
753 Reason
=> SE_Infinite_Recursion
));
759 -- If not that special case, search up tree, quitting if we reach a
760 -- construct (e.g. a conditional) that tells us that this is not a
761 -- case for an infinite recursion warning.
767 -- If no parent, then we were not inside a subprogram, this can for
768 -- example happen when processing certain pragmas in a spec. Just
769 -- return False in this case.
775 -- Done if we get to subprogram body, this is definitely an infinite
776 -- recursion case if we did not find anything to stop us.
778 exit when Nkind
(P
) = N_Subprogram_Body
;
780 -- If appearing in conditional, result is false
782 if Nkind_In
(P
, N_Or_Else
,
791 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
792 and then C
/= First
(Statements
(P
))
794 -- If the call is the expression of a return statement and the
795 -- actuals are identical to the formals, it's worth a warning.
796 -- However, we skip this if there is an immediately preceding
797 -- raise statement, since the call is never executed.
799 -- Furthermore, this corresponds to a common idiom:
801 -- function F (L : Thing) return Boolean is
803 -- raise Program_Error;
807 -- for generating a stub function
809 if Nkind
(Parent
(N
)) = N_Simple_Return_Statement
810 and then Same_Argument_List
812 exit when not Is_List_Member
(Parent
(N
));
814 -- OK, return statement is in a statement list, look for raise
820 -- Skip past N_Freeze_Entity nodes generated by expansion
822 Nod
:= Prev
(Parent
(N
));
824 and then Nkind
(Nod
) = N_Freeze_Entity
829 -- If no raise statement, give warning. We look at the
830 -- original node, because in the case of "raise ... with
831 -- ...", the node has been transformed into a call.
833 exit when Nkind
(Original_Node
(Nod
)) /= N_Raise_Statement
835 (Nkind
(Nod
) not in N_Raise_xxx_Error
836 or else Present
(Condition
(Nod
)));
847 Error_Msg_Warn
:= SPARK_Mode
/= On
;
848 Error_Msg_N
("!possible infinite recursion<<", N
);
849 Error_Msg_N
("\!??Storage_Error ]<<", N
);
852 end Check_Infinite_Recursion
;
854 -------------------------------
855 -- Check_Initialization_Call --
856 -------------------------------
858 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
) is
859 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
861 function Uses_SS
(T
: Entity_Id
) return Boolean;
862 -- Check whether the creation of an object of the type will involve
863 -- use of the secondary stack. If T is a record type, this is true
864 -- if the expression for some component uses the secondary stack, e.g.
865 -- through a call to a function that returns an unconstrained value.
866 -- False if T is controlled, because cleanups occur elsewhere.
872 function Uses_SS
(T
: Entity_Id
) return Boolean is
875 Full_Type
: Entity_Id
:= Underlying_Type
(T
);
878 -- Normally we want to use the underlying type, but if it's not set
879 -- then continue with T.
881 if not Present
(Full_Type
) then
885 if Is_Controlled
(Full_Type
) then
888 elsif Is_Array_Type
(Full_Type
) then
889 return Uses_SS
(Component_Type
(Full_Type
));
891 elsif Is_Record_Type
(Full_Type
) then
892 Comp
:= First_Component
(Full_Type
);
893 while Present
(Comp
) loop
894 if Ekind
(Comp
) = E_Component
895 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
897 -- The expression for a dynamic component may be rewritten
898 -- as a dereference, so retrieve original node.
900 Expr
:= Original_Node
(Expression
(Parent
(Comp
)));
902 -- Return True if the expression is a call to a function
903 -- (including an attribute function such as Image, or a
904 -- user-defined operator) with a result that requires a
907 if (Nkind
(Expr
) = N_Function_Call
908 or else Nkind
(Expr
) in N_Op
909 or else (Nkind
(Expr
) = N_Attribute_Reference
910 and then Present
(Expressions
(Expr
))))
911 and then Requires_Transient_Scope
(Etype
(Expr
))
915 elsif Uses_SS
(Etype
(Comp
)) then
920 Next_Component
(Comp
);
930 -- Start of processing for Check_Initialization_Call
933 -- Establish a transient scope if the type needs it
935 if Uses_SS
(Typ
) then
936 Establish_Transient_Scope
(First_Actual
(N
), Sec_Stack
=> True);
938 end Check_Initialization_Call
;
940 ---------------------------------------
941 -- Check_No_Direct_Boolean_Operators --
942 ---------------------------------------
944 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
) is
946 if Scope
(Entity
(N
)) = Standard_Standard
947 and then Root_Type
(Etype
(Left_Opnd
(N
))) = Standard_Boolean
949 -- Restriction only applies to original source code
951 if Comes_From_Source
(N
) then
952 Check_Restriction
(No_Direct_Boolean_Operators
, N
);
956 -- Do style check (but skip if in instance, error is on template)
959 if not In_Instance
then
960 Check_Boolean_Operator
(N
);
963 end Check_No_Direct_Boolean_Operators
;
965 ------------------------------
966 -- Check_Parameterless_Call --
967 ------------------------------
969 procedure Check_Parameterless_Call
(N
: Node_Id
) is
972 function Prefix_Is_Access_Subp
return Boolean;
973 -- If the prefix is of an access_to_subprogram type, the node must be
974 -- rewritten as a call. Ditto if the prefix is overloaded and all its
975 -- interpretations are access to subprograms.
977 ---------------------------
978 -- Prefix_Is_Access_Subp --
979 ---------------------------
981 function Prefix_Is_Access_Subp
return Boolean is
986 -- If the context is an attribute reference that can apply to
987 -- functions, this is never a parameterless call (RM 4.1.4(6)).
989 if Nkind
(Parent
(N
)) = N_Attribute_Reference
990 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
997 if not Is_Overloaded
(N
) then
999 Ekind
(Etype
(N
)) = E_Subprogram_Type
1000 and then Base_Type
(Etype
(Etype
(N
))) /= Standard_Void_Type
;
1002 Get_First_Interp
(N
, I
, It
);
1003 while Present
(It
.Typ
) loop
1004 if Ekind
(It
.Typ
) /= E_Subprogram_Type
1005 or else Base_Type
(Etype
(It
.Typ
)) = Standard_Void_Type
1010 Get_Next_Interp
(I
, It
);
1015 end Prefix_Is_Access_Subp
;
1017 -- Start of processing for Check_Parameterless_Call
1020 -- Defend against junk stuff if errors already detected
1022 if Total_Errors_Detected
/= 0 then
1023 if Nkind
(N
) in N_Has_Etype
and then Etype
(N
) = Any_Type
then
1025 elsif Nkind
(N
) in N_Has_Chars
1026 and then Chars
(N
) in Error_Name_Or_No_Name
1034 -- If the context expects a value, and the name is a procedure, this is
1035 -- most likely a missing 'Access. Don't try to resolve the parameterless
1036 -- call, error will be caught when the outer call is analyzed.
1038 if Is_Entity_Name
(N
)
1039 and then Ekind
(Entity
(N
)) = E_Procedure
1040 and then not Is_Overloaded
(N
)
1042 Nkind_In
(Parent
(N
), N_Parameter_Association
,
1044 N_Procedure_Call_Statement
)
1049 -- Rewrite as call if overloadable entity that is (or could be, in the
1050 -- overloaded case) a function call. If we know for sure that the entity
1051 -- is an enumeration literal, we do not rewrite it.
1053 -- If the entity is the name of an operator, it cannot be a call because
1054 -- operators cannot have default parameters. In this case, this must be
1055 -- a string whose contents coincide with an operator name. Set the kind
1056 -- of the node appropriately.
1058 if (Is_Entity_Name
(N
)
1059 and then Nkind
(N
) /= N_Operator_Symbol
1060 and then Is_Overloadable
(Entity
(N
))
1061 and then (Ekind
(Entity
(N
)) /= E_Enumeration_Literal
1062 or else Is_Overloaded
(N
)))
1064 -- Rewrite as call if it is an explicit dereference of an expression of
1065 -- a subprogram access type, and the subprogram type is not that of a
1066 -- procedure or entry.
1069 (Nkind
(N
) = N_Explicit_Dereference
and then Prefix_Is_Access_Subp
)
1071 -- Rewrite as call if it is a selected component which is a function,
1072 -- this is the case of a call to a protected function (which may be
1073 -- overloaded with other protected operations).
1076 (Nkind
(N
) = N_Selected_Component
1077 and then (Ekind
(Entity
(Selector_Name
(N
))) = E_Function
1079 (Ekind_In
(Entity
(Selector_Name
(N
)), E_Entry
,
1081 and then Is_Overloaded
(Selector_Name
(N
)))))
1083 -- If one of the above three conditions is met, rewrite as call. Apply
1084 -- the rewriting only once.
1087 if Nkind
(Parent
(N
)) /= N_Function_Call
1088 or else N
/= Name
(Parent
(N
))
1091 -- This may be a prefixed call that was not fully analyzed, e.g.
1092 -- an actual in an instance.
1094 if Ada_Version
>= Ada_2005
1095 and then Nkind
(N
) = N_Selected_Component
1096 and then Is_Dispatching_Operation
(Entity
(Selector_Name
(N
)))
1098 Analyze_Selected_Component
(N
);
1100 if Nkind
(N
) /= N_Selected_Component
then
1105 -- The node is the name of the parameterless call. Preserve its
1106 -- descendants, which may be complex expressions.
1108 Nam
:= Relocate_Node
(N
);
1110 -- If overloaded, overload set belongs to new copy
1112 Save_Interps
(N
, Nam
);
1114 -- Change node to parameterless function call (note that the
1115 -- Parameter_Associations associations field is left set to Empty,
1116 -- its normal default value since there are no parameters)
1118 Change_Node
(N
, N_Function_Call
);
1120 Set_Sloc
(N
, Sloc
(Nam
));
1124 elsif Nkind
(N
) = N_Parameter_Association
then
1125 Check_Parameterless_Call
(Explicit_Actual_Parameter
(N
));
1127 elsif Nkind
(N
) = N_Operator_Symbol
then
1128 Change_Operator_Symbol_To_String_Literal
(N
);
1129 Set_Is_Overloaded
(N
, False);
1130 Set_Etype
(N
, Any_String
);
1132 end Check_Parameterless_Call
;
1134 -----------------------------
1135 -- Is_Definite_Access_Type --
1136 -----------------------------
1138 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean is
1139 Btyp
: constant Entity_Id
:= Base_Type
(E
);
1141 return Ekind
(Btyp
) = E_Access_Type
1142 or else (Ekind
(Btyp
) = E_Access_Subprogram_Type
1143 and then Comes_From_Source
(Btyp
));
1144 end Is_Definite_Access_Type
;
1146 ----------------------
1147 -- Is_Predefined_Op --
1148 ----------------------
1150 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean is
1152 -- Predefined operators are intrinsic subprograms
1154 if not Is_Intrinsic_Subprogram
(Nam
) then
1158 -- A call to a back-end builtin is never a predefined operator
1160 if Is_Imported
(Nam
) and then Present
(Interface_Name
(Nam
)) then
1164 return not Is_Generic_Instance
(Nam
)
1165 and then Chars
(Nam
) in Any_Operator_Name
1166 and then (No
(Alias
(Nam
)) or else Is_Predefined_Op
(Alias
(Nam
)));
1167 end Is_Predefined_Op
;
1169 -----------------------------
1170 -- Make_Call_Into_Operator --
1171 -----------------------------
1173 procedure Make_Call_Into_Operator
1178 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
1179 Act1
: Node_Id
:= First_Actual
(N
);
1180 Act2
: Node_Id
:= Next_Actual
(Act1
);
1181 Error
: Boolean := False;
1182 Func
: constant Entity_Id
:= Entity
(Name
(N
));
1183 Is_Binary
: constant Boolean := Present
(Act2
);
1185 Opnd_Type
: Entity_Id
;
1186 Orig_Type
: Entity_Id
:= Empty
;
1189 type Kind_Test
is access function (E
: Entity_Id
) return Boolean;
1191 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean;
1192 -- If the operand is not universal, and the operator is given by an
1193 -- expanded name, verify that the operand has an interpretation with a
1194 -- type defined in the given scope of the operator.
1196 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
;
1197 -- Find a type of the given class in package Pack that contains the
1200 ---------------------------
1201 -- Operand_Type_In_Scope --
1202 ---------------------------
1204 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean is
1205 Nod
: constant Node_Id
:= Right_Opnd
(Op_Node
);
1210 if not Is_Overloaded
(Nod
) then
1211 return Scope
(Base_Type
(Etype
(Nod
))) = S
;
1214 Get_First_Interp
(Nod
, I
, It
);
1215 while Present
(It
.Typ
) loop
1216 if Scope
(Base_Type
(It
.Typ
)) = S
then
1220 Get_Next_Interp
(I
, It
);
1225 end Operand_Type_In_Scope
;
1231 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
is
1234 function In_Decl
return Boolean;
1235 -- Verify that node is not part of the type declaration for the
1236 -- candidate type, which would otherwise be invisible.
1242 function In_Decl
return Boolean is
1243 Decl_Node
: constant Node_Id
:= Parent
(E
);
1249 if Etype
(E
) = Any_Type
then
1252 elsif No
(Decl_Node
) then
1257 and then Nkind
(N2
) /= N_Compilation_Unit
1259 if N2
= Decl_Node
then
1270 -- Start of processing for Type_In_P
1273 -- If the context type is declared in the prefix package, this is the
1274 -- desired base type.
1276 if Scope
(Base_Type
(Typ
)) = Pack
and then Test
(Typ
) then
1277 return Base_Type
(Typ
);
1280 E
:= First_Entity
(Pack
);
1281 while Present
(E
) loop
1283 and then not In_Decl
1295 -- Start of processing for Make_Call_Into_Operator
1298 Op_Node
:= New_Node
(Operator_Kind
(Op_Name
, Is_Binary
), Sloc
(N
));
1303 Set_Left_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1304 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act2
));
1305 Save_Interps
(Act1
, Left_Opnd
(Op_Node
));
1306 Save_Interps
(Act2
, Right_Opnd
(Op_Node
));
1307 Act1
:= Left_Opnd
(Op_Node
);
1308 Act2
:= Right_Opnd
(Op_Node
);
1313 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1314 Save_Interps
(Act1
, Right_Opnd
(Op_Node
));
1315 Act1
:= Right_Opnd
(Op_Node
);
1318 -- If the operator is denoted by an expanded name, and the prefix is
1319 -- not Standard, but the operator is a predefined one whose scope is
1320 -- Standard, then this is an implicit_operator, inserted as an
1321 -- interpretation by the procedure of the same name. This procedure
1322 -- overestimates the presence of implicit operators, because it does
1323 -- not examine the type of the operands. Verify now that the operand
1324 -- type appears in the given scope. If right operand is universal,
1325 -- check the other operand. In the case of concatenation, either
1326 -- argument can be the component type, so check the type of the result.
1327 -- If both arguments are literals, look for a type of the right kind
1328 -- defined in the given scope. This elaborate nonsense is brought to
1329 -- you courtesy of b33302a. The type itself must be frozen, so we must
1330 -- find the type of the proper class in the given scope.
1332 -- A final wrinkle is the multiplication operator for fixed point types,
1333 -- which is defined in Standard only, and not in the scope of the
1334 -- fixed point type itself.
1336 if Nkind
(Name
(N
)) = N_Expanded_Name
then
1337 Pack
:= Entity
(Prefix
(Name
(N
)));
1339 -- If this is a package renaming, get renamed entity, which will be
1340 -- the scope of the operands if operaton is type-correct.
1342 if Present
(Renamed_Entity
(Pack
)) then
1343 Pack
:= Renamed_Entity
(Pack
);
1346 -- If the entity being called is defined in the given package, it is
1347 -- a renaming of a predefined operator, and known to be legal.
1349 if Scope
(Entity
(Name
(N
))) = Pack
1350 and then Pack
/= Standard_Standard
1354 -- Visibility does not need to be checked in an instance: if the
1355 -- operator was not visible in the generic it has been diagnosed
1356 -- already, else there is an implicit copy of it in the instance.
1358 elsif In_Instance
then
1361 elsif Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
)
1362 and then Is_Fixed_Point_Type
(Etype
(Left_Opnd
(Op_Node
)))
1363 and then Is_Fixed_Point_Type
(Etype
(Right_Opnd
(Op_Node
)))
1365 if Pack
/= Standard_Standard
then
1369 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1372 elsif Ada_Version
>= Ada_2005
1373 and then Nam_In
(Op_Name
, Name_Op_Eq
, Name_Op_Ne
)
1374 and then Ekind
(Etype
(Act1
)) = E_Anonymous_Access_Type
1379 Opnd_Type
:= Base_Type
(Etype
(Right_Opnd
(Op_Node
)));
1381 if Op_Name
= Name_Op_Concat
then
1382 Opnd_Type
:= Base_Type
(Typ
);
1384 elsif (Scope
(Opnd_Type
) = Standard_Standard
1386 or else (Nkind
(Right_Opnd
(Op_Node
)) = N_Attribute_Reference
1388 and then not Comes_From_Source
(Opnd_Type
))
1390 Opnd_Type
:= Base_Type
(Etype
(Left_Opnd
(Op_Node
)));
1393 if Scope
(Opnd_Type
) = Standard_Standard
then
1395 -- Verify that the scope contains a type that corresponds to
1396 -- the given literal. Optimize the case where Pack is Standard.
1398 if Pack
/= Standard_Standard
then
1400 if Opnd_Type
= Universal_Integer
then
1401 Orig_Type
:= Type_In_P
(Is_Integer_Type
'Access);
1403 elsif Opnd_Type
= Universal_Real
then
1404 Orig_Type
:= Type_In_P
(Is_Real_Type
'Access);
1406 elsif Opnd_Type
= Any_String
then
1407 Orig_Type
:= Type_In_P
(Is_String_Type
'Access);
1409 elsif Opnd_Type
= Any_Access
then
1410 Orig_Type
:= Type_In_P
(Is_Definite_Access_Type
'Access);
1412 elsif Opnd_Type
= Any_Composite
then
1413 Orig_Type
:= Type_In_P
(Is_Composite_Type
'Access);
1415 if Present
(Orig_Type
) then
1416 if Has_Private_Component
(Orig_Type
) then
1419 Set_Etype
(Act1
, Orig_Type
);
1422 Set_Etype
(Act2
, Orig_Type
);
1431 Error
:= No
(Orig_Type
);
1434 elsif Ekind
(Opnd_Type
) = E_Allocator_Type
1435 and then No
(Type_In_P
(Is_Definite_Access_Type
'Access))
1439 -- If the type is defined elsewhere, and the operator is not
1440 -- defined in the given scope (by a renaming declaration, e.g.)
1441 -- then this is an error as well. If an extension of System is
1442 -- present, and the type may be defined there, Pack must be
1445 elsif Scope
(Opnd_Type
) /= Pack
1446 and then Scope
(Op_Id
) /= Pack
1447 and then (No
(System_Aux_Id
)
1448 or else Scope
(Opnd_Type
) /= System_Aux_Id
1449 or else Pack
/= Scope
(System_Aux_Id
))
1451 if not Is_Overloaded
(Right_Opnd
(Op_Node
)) then
1454 Error
:= not Operand_Type_In_Scope
(Pack
);
1457 elsif Pack
= Standard_Standard
1458 and then not Operand_Type_In_Scope
(Standard_Standard
)
1465 Error_Msg_Node_2
:= Pack
;
1467 ("& not declared in&", N
, Selector_Name
(Name
(N
)));
1468 Set_Etype
(N
, Any_Type
);
1471 -- Detect a mismatch between the context type and the result type
1472 -- in the named package, which is otherwise not detected if the
1473 -- operands are universal. Check is only needed if source entity is
1474 -- an operator, not a function that renames an operator.
1476 elsif Nkind
(Parent
(N
)) /= N_Type_Conversion
1477 and then Ekind
(Entity
(Name
(N
))) = E_Operator
1478 and then Is_Numeric_Type
(Typ
)
1479 and then not Is_Universal_Numeric_Type
(Typ
)
1480 and then Scope
(Base_Type
(Typ
)) /= Pack
1481 and then not In_Instance
1483 if Is_Fixed_Point_Type
(Typ
)
1484 and then Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
)
1486 -- Already checked above
1490 -- Operator may be defined in an extension of System
1492 elsif Present
(System_Aux_Id
)
1493 and then Scope
(Opnd_Type
) = System_Aux_Id
1498 -- Could we use Wrong_Type here??? (this would require setting
1499 -- Etype (N) to the actual type found where Typ was expected).
1501 Error_Msg_NE
("expect }", N
, Typ
);
1506 Set_Chars
(Op_Node
, Op_Name
);
1508 if not Is_Private_Type
(Etype
(N
)) then
1509 Set_Etype
(Op_Node
, Base_Type
(Etype
(N
)));
1511 Set_Etype
(Op_Node
, Etype
(N
));
1514 -- If this is a call to a function that renames a predefined equality,
1515 -- the renaming declaration provides a type that must be used to
1516 -- resolve the operands. This must be done now because resolution of
1517 -- the equality node will not resolve any remaining ambiguity, and it
1518 -- assumes that the first operand is not overloaded.
1520 if Nam_In
(Op_Name
, Name_Op_Eq
, Name_Op_Ne
)
1521 and then Ekind
(Func
) = E_Function
1522 and then Is_Overloaded
(Act1
)
1524 Resolve
(Act1
, Base_Type
(Etype
(First_Formal
(Func
))));
1525 Resolve
(Act2
, Base_Type
(Etype
(First_Formal
(Func
))));
1528 Set_Entity
(Op_Node
, Op_Id
);
1529 Generate_Reference
(Op_Id
, N
, ' ');
1531 -- Do rewrite setting Comes_From_Source on the result if the original
1532 -- call came from source. Although it is not strictly the case that the
1533 -- operator as such comes from the source, logically it corresponds
1534 -- exactly to the function call in the source, so it should be marked
1535 -- this way (e.g. to make sure that validity checks work fine).
1538 CS
: constant Boolean := Comes_From_Source
(N
);
1540 Rewrite
(N
, Op_Node
);
1541 Set_Comes_From_Source
(N
, CS
);
1544 -- If this is an arithmetic operator and the result type is private,
1545 -- the operands and the result must be wrapped in conversion to
1546 -- expose the underlying numeric type and expand the proper checks,
1547 -- e.g. on division.
1549 if Is_Private_Type
(Typ
) then
1551 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1552 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
1553 Resolve_Intrinsic_Operator
(N
, Typ
);
1555 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
1556 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
1565 -- If in ASIS_Mode, propagate operand types to original actuals of
1566 -- function call, which would otherwise not be fully resolved. If
1567 -- the call has already been constant-folded, nothing to do. We
1568 -- relocate the operand nodes rather than copy them, to preserve
1569 -- original_node pointers, given that the operands themselves may
1570 -- have been rewritten. If the call was itself a rewriting of an
1571 -- operator node, nothing to do.
1574 and then Nkind
(N
) in N_Op
1575 and then Nkind
(Original_Node
(N
)) = N_Function_Call
1578 Rewrite
(First
(Parameter_Associations
(Original_Node
(N
))),
1579 Relocate_Node
(Left_Opnd
(N
)));
1580 Rewrite
(Next
(First
(Parameter_Associations
(Original_Node
(N
)))),
1581 Relocate_Node
(Right_Opnd
(N
)));
1583 Rewrite
(First
(Parameter_Associations
(Original_Node
(N
))),
1584 Relocate_Node
(Right_Opnd
(N
)));
1587 Set_Parent
(Original_Node
(N
), Parent
(N
));
1589 end Make_Call_Into_Operator
;
1595 function Operator_Kind
1597 Is_Binary
: Boolean) return Node_Kind
1602 -- Use CASE statement or array???
1605 if Op_Name
= Name_Op_And
then
1607 elsif Op_Name
= Name_Op_Or
then
1609 elsif Op_Name
= Name_Op_Xor
then
1611 elsif Op_Name
= Name_Op_Eq
then
1613 elsif Op_Name
= Name_Op_Ne
then
1615 elsif Op_Name
= Name_Op_Lt
then
1617 elsif Op_Name
= Name_Op_Le
then
1619 elsif Op_Name
= Name_Op_Gt
then
1621 elsif Op_Name
= Name_Op_Ge
then
1623 elsif Op_Name
= Name_Op_Add
then
1625 elsif Op_Name
= Name_Op_Subtract
then
1626 Kind
:= N_Op_Subtract
;
1627 elsif Op_Name
= Name_Op_Concat
then
1628 Kind
:= N_Op_Concat
;
1629 elsif Op_Name
= Name_Op_Multiply
then
1630 Kind
:= N_Op_Multiply
;
1631 elsif Op_Name
= Name_Op_Divide
then
1632 Kind
:= N_Op_Divide
;
1633 elsif Op_Name
= Name_Op_Mod
then
1635 elsif Op_Name
= Name_Op_Rem
then
1637 elsif Op_Name
= Name_Op_Expon
then
1640 raise Program_Error
;
1646 if Op_Name
= Name_Op_Add
then
1648 elsif Op_Name
= Name_Op_Subtract
then
1650 elsif Op_Name
= Name_Op_Abs
then
1652 elsif Op_Name
= Name_Op_Not
then
1655 raise Program_Error
;
1662 ----------------------------
1663 -- Preanalyze_And_Resolve --
1664 ----------------------------
1666 procedure Preanalyze_And_Resolve
(N
: Node_Id
; T
: Entity_Id
) is
1667 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1670 Full_Analysis
:= False;
1671 Expander_Mode_Save_And_Set
(False);
1673 -- Normally, we suppress all checks for this preanalysis. There is no
1674 -- point in processing them now, since they will be applied properly
1675 -- and in the proper location when the default expressions reanalyzed
1676 -- and reexpanded later on. We will also have more information at that
1677 -- point for possible suppression of individual checks.
1679 -- However, in SPARK mode, most expansion is suppressed, and this
1680 -- later reanalysis and reexpansion may not occur. SPARK mode does
1681 -- require the setting of checking flags for proof purposes, so we
1682 -- do the SPARK preanalysis without suppressing checks.
1684 -- This special handling for SPARK mode is required for example in the
1685 -- case of Ada 2012 constructs such as quantified expressions, which are
1686 -- expanded in two separate steps.
1688 if GNATprove_Mode
then
1689 Analyze_And_Resolve
(N
, T
);
1691 Analyze_And_Resolve
(N
, T
, Suppress
=> All_Checks
);
1694 Expander_Mode_Restore
;
1695 Full_Analysis
:= Save_Full_Analysis
;
1696 end Preanalyze_And_Resolve
;
1698 -- Version without context type
1700 procedure Preanalyze_And_Resolve
(N
: Node_Id
) is
1701 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1704 Full_Analysis
:= False;
1705 Expander_Mode_Save_And_Set
(False);
1708 Resolve
(N
, Etype
(N
), Suppress
=> All_Checks
);
1710 Expander_Mode_Restore
;
1711 Full_Analysis
:= Save_Full_Analysis
;
1712 end Preanalyze_And_Resolve
;
1714 ----------------------------------
1715 -- Replace_Actual_Discriminants --
1716 ----------------------------------
1718 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
) is
1719 Loc
: constant Source_Ptr
:= Sloc
(N
);
1720 Tsk
: Node_Id
:= Empty
;
1722 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
;
1723 -- Comment needed???
1729 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
is
1733 if Nkind
(Nod
) = N_Identifier
then
1734 Ent
:= Entity
(Nod
);
1737 and then Ekind
(Ent
) = E_Discriminant
1740 Make_Selected_Component
(Loc
,
1741 Prefix
=> New_Copy_Tree
(Tsk
, New_Sloc
=> Loc
),
1742 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Ent
))));
1744 Set_Etype
(Nod
, Etype
(Ent
));
1752 procedure Replace_Discrs
is new Traverse_Proc
(Process_Discr
);
1754 -- Start of processing for Replace_Actual_Discriminants
1757 if not Expander_Active
then
1761 if Nkind
(Name
(N
)) = N_Selected_Component
then
1762 Tsk
:= Prefix
(Name
(N
));
1764 elsif Nkind
(Name
(N
)) = N_Indexed_Component
then
1765 Tsk
:= Prefix
(Prefix
(Name
(N
)));
1771 Replace_Discrs
(Default
);
1773 end Replace_Actual_Discriminants
;
1779 procedure Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
1780 Ambiguous
: Boolean := False;
1781 Ctx_Type
: Entity_Id
:= Typ
;
1782 Expr_Type
: Entity_Id
:= Empty
; -- prevent junk warning
1783 Err_Type
: Entity_Id
:= Empty
;
1784 Found
: Boolean := False;
1787 I1
: Interp_Index
:= 0; -- prevent junk warning
1790 Seen
: Entity_Id
:= Empty
; -- prevent junk warning
1792 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean;
1793 -- Determine whether a node comes from a predefined library unit or
1796 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
);
1797 -- Try and fix up a literal so that it matches its expected type. New
1798 -- literals are manufactured if necessary to avoid cascaded errors.
1800 procedure Report_Ambiguous_Argument
;
1801 -- Additional diagnostics when an ambiguous call has an ambiguous
1802 -- argument (typically a controlling actual).
1804 procedure Resolution_Failed
;
1805 -- Called when attempt at resolving current expression fails
1807 ------------------------------------
1808 -- Comes_From_Predefined_Lib_Unit --
1809 -------------------------------------
1811 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean is
1814 Sloc
(Nod
) = Standard_Location
1815 or else Is_Predefined_File_Name
1816 (Unit_File_Name
(Get_Source_Unit
(Sloc
(Nod
))));
1817 end Comes_From_Predefined_Lib_Unit
;
1819 --------------------
1820 -- Patch_Up_Value --
1821 --------------------
1823 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
) is
1825 if Nkind
(N
) = N_Integer_Literal
and then Is_Real_Type
(Typ
) then
1827 Make_Real_Literal
(Sloc
(N
),
1828 Realval
=> UR_From_Uint
(Intval
(N
))));
1829 Set_Etype
(N
, Universal_Real
);
1830 Set_Is_Static_Expression
(N
);
1832 elsif Nkind
(N
) = N_Real_Literal
and then Is_Integer_Type
(Typ
) then
1834 Make_Integer_Literal
(Sloc
(N
),
1835 Intval
=> UR_To_Uint
(Realval
(N
))));
1836 Set_Etype
(N
, Universal_Integer
);
1837 Set_Is_Static_Expression
(N
);
1839 elsif Nkind
(N
) = N_String_Literal
1840 and then Is_Character_Type
(Typ
)
1842 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('A')));
1844 Make_Character_Literal
(Sloc
(N
),
1846 Char_Literal_Value
=>
1847 UI_From_Int
(Character'Pos ('A'))));
1848 Set_Etype
(N
, Any_Character
);
1849 Set_Is_Static_Expression
(N
);
1851 elsif Nkind
(N
) /= N_String_Literal
and then Is_String_Type
(Typ
) then
1853 Make_String_Literal
(Sloc
(N
),
1854 Strval
=> End_String
));
1856 elsif Nkind
(N
) = N_Range
then
1857 Patch_Up_Value
(Low_Bound
(N
), Typ
);
1858 Patch_Up_Value
(High_Bound
(N
), Typ
);
1862 -------------------------------
1863 -- Report_Ambiguous_Argument --
1864 -------------------------------
1866 procedure Report_Ambiguous_Argument
is
1867 Arg
: constant Node_Id
:= First
(Parameter_Associations
(N
));
1872 if Nkind
(Arg
) = N_Function_Call
1873 and then Is_Entity_Name
(Name
(Arg
))
1874 and then Is_Overloaded
(Name
(Arg
))
1876 Error_Msg_NE
("ambiguous call to&", Arg
, Name
(Arg
));
1878 -- Could use comments on what is going on here???
1880 Get_First_Interp
(Name
(Arg
), I
, It
);
1881 while Present
(It
.Nam
) loop
1882 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
1884 if Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
then
1885 Error_Msg_N
("interpretation (inherited) #!", Arg
);
1887 Error_Msg_N
("interpretation #!", Arg
);
1890 Get_Next_Interp
(I
, It
);
1893 end Report_Ambiguous_Argument
;
1895 -----------------------
1896 -- Resolution_Failed --
1897 -----------------------
1899 procedure Resolution_Failed
is
1901 Patch_Up_Value
(N
, Typ
);
1903 Debug_A_Exit
("resolving ", N
, " (done, resolution failed)");
1904 Set_Is_Overloaded
(N
, False);
1906 -- The caller will return without calling the expander, so we need
1907 -- to set the analyzed flag. Note that it is fine to set Analyzed
1908 -- to True even if we are in the middle of a shallow analysis,
1909 -- (see the spec of sem for more details) since this is an error
1910 -- situation anyway, and there is no point in repeating the
1911 -- analysis later (indeed it won't work to repeat it later, since
1912 -- we haven't got a clear resolution of which entity is being
1915 Set_Analyzed
(N
, True);
1917 end Resolution_Failed
;
1919 -- Start of processing for Resolve
1926 -- Access attribute on remote subprogram cannot be used for a non-remote
1927 -- access-to-subprogram type.
1929 if Nkind
(N
) = N_Attribute_Reference
1930 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
1931 Name_Unrestricted_Access
,
1932 Name_Unchecked_Access
)
1933 and then Comes_From_Source
(N
)
1934 and then Is_Entity_Name
(Prefix
(N
))
1935 and then Is_Subprogram
(Entity
(Prefix
(N
)))
1936 and then Is_Remote_Call_Interface
(Entity
(Prefix
(N
)))
1937 and then not Is_Remote_Access_To_Subprogram_Type
(Typ
)
1940 ("prefix must statically denote a non-remote subprogram", N
);
1943 From_Lib
:= Comes_From_Predefined_Lib_Unit
(N
);
1945 -- If the context is a Remote_Access_To_Subprogram, access attributes
1946 -- must be resolved with the corresponding fat pointer. There is no need
1947 -- to check for the attribute name since the return type of an
1948 -- attribute is never a remote type.
1950 if Nkind
(N
) = N_Attribute_Reference
1951 and then Comes_From_Source
(N
)
1952 and then (Is_Remote_Call_Interface
(Typ
) or else Is_Remote_Types
(Typ
))
1955 Attr
: constant Attribute_Id
:=
1956 Get_Attribute_Id
(Attribute_Name
(N
));
1957 Pref
: constant Node_Id
:= Prefix
(N
);
1960 Is_Remote
: Boolean := True;
1963 -- Check that Typ is a remote access-to-subprogram type
1965 if Is_Remote_Access_To_Subprogram_Type
(Typ
) then
1967 -- Prefix (N) must statically denote a remote subprogram
1968 -- declared in a package specification.
1970 if Attr
= Attribute_Access
or else
1971 Attr
= Attribute_Unchecked_Access
or else
1972 Attr
= Attribute_Unrestricted_Access
1974 Decl
:= Unit_Declaration_Node
(Entity
(Pref
));
1976 if Nkind
(Decl
) = N_Subprogram_Body
then
1977 Spec
:= Corresponding_Spec
(Decl
);
1979 if Present
(Spec
) then
1980 Decl
:= Unit_Declaration_Node
(Spec
);
1984 Spec
:= Parent
(Decl
);
1986 if not Is_Entity_Name
(Prefix
(N
))
1987 or else Nkind
(Spec
) /= N_Package_Specification
1989 not Is_Remote_Call_Interface
(Defining_Entity
(Spec
))
1993 ("prefix must statically denote a remote subprogram ",
1997 -- If we are generating code in distributed mode, perform
1998 -- semantic checks against corresponding remote entities.
2001 and then Get_PCS_Name
/= Name_No_DSA
2003 Check_Subtype_Conformant
2004 (New_Id
=> Entity
(Prefix
(N
)),
2005 Old_Id
=> Designated_Type
2006 (Corresponding_Remote_Type
(Typ
)),
2010 Process_Remote_AST_Attribute
(N
, Typ
);
2018 Debug_A_Entry
("resolving ", N
);
2020 if Debug_Flag_V
then
2021 Write_Overloads
(N
);
2024 if Comes_From_Source
(N
) then
2025 if Is_Fixed_Point_Type
(Typ
) then
2026 Check_Restriction
(No_Fixed_Point
, N
);
2028 elsif Is_Floating_Point_Type
(Typ
)
2029 and then Typ
/= Universal_Real
2030 and then Typ
/= Any_Real
2032 Check_Restriction
(No_Floating_Point
, N
);
2036 -- Return if already analyzed
2038 if Analyzed
(N
) then
2039 Debug_A_Exit
("resolving ", N
, " (done, already analyzed)");
2040 Analyze_Dimension
(N
);
2043 -- Any case of Any_Type as the Etype value means that we had a
2046 elsif Etype
(N
) = Any_Type
then
2047 Debug_A_Exit
("resolving ", N
, " (done, Etype = Any_Type)");
2051 Check_Parameterless_Call
(N
);
2053 -- The resolution of an Expression_With_Actions is determined by
2056 if Nkind
(N
) = N_Expression_With_Actions
then
2057 Resolve
(Expression
(N
), Typ
);
2060 Expr_Type
:= Etype
(Expression
(N
));
2062 -- If not overloaded, then we know the type, and all that needs doing
2063 -- is to check that this type is compatible with the context.
2065 elsif not Is_Overloaded
(N
) then
2066 Found
:= Covers
(Typ
, Etype
(N
));
2067 Expr_Type
:= Etype
(N
);
2069 -- In the overloaded case, we must select the interpretation that
2070 -- is compatible with the context (i.e. the type passed to Resolve)
2073 -- Loop through possible interpretations
2075 Get_First_Interp
(N
, I
, It
);
2076 Interp_Loop
: while Present
(It
.Typ
) loop
2078 if Debug_Flag_V
then
2079 Write_Str
("Interp: ");
2083 -- We are only interested in interpretations that are compatible
2084 -- with the expected type, any other interpretations are ignored.
2086 if not Covers
(Typ
, It
.Typ
) then
2087 if Debug_Flag_V
then
2088 Write_Str
(" interpretation incompatible with context");
2093 -- Skip the current interpretation if it is disabled by an
2094 -- abstract operator. This action is performed only when the
2095 -- type against which we are resolving is the same as the
2096 -- type of the interpretation.
2098 if Ada_Version
>= Ada_2005
2099 and then It
.Typ
= Typ
2100 and then Typ
/= Universal_Integer
2101 and then Typ
/= Universal_Real
2102 and then Present
(It
.Abstract_Op
)
2104 if Debug_Flag_V
then
2105 Write_Line
("Skip.");
2111 -- First matching interpretation
2117 Expr_Type
:= It
.Typ
;
2119 -- Matching interpretation that is not the first, maybe an
2120 -- error, but there are some cases where preference rules are
2121 -- used to choose between the two possibilities. These and
2122 -- some more obscure cases are handled in Disambiguate.
2125 -- If the current statement is part of a predefined library
2126 -- unit, then all interpretations which come from user level
2127 -- packages should not be considered. Check previous and
2131 if not Comes_From_Predefined_Lib_Unit
(It
.Nam
) then
2134 elsif not Comes_From_Predefined_Lib_Unit
(Seen
) then
2136 -- Previous interpretation must be discarded
2140 Expr_Type
:= It
.Typ
;
2141 Set_Entity
(N
, Seen
);
2146 -- Otherwise apply further disambiguation steps
2148 Error_Msg_Sloc
:= Sloc
(Seen
);
2149 It1
:= Disambiguate
(N
, I1
, I
, Typ
);
2151 -- Disambiguation has succeeded. Skip the remaining
2154 if It1
/= No_Interp
then
2156 Expr_Type
:= It1
.Typ
;
2158 while Present
(It
.Typ
) loop
2159 Get_Next_Interp
(I
, It
);
2163 -- Before we issue an ambiguity complaint, check for
2164 -- the case of a subprogram call where at least one
2165 -- of the arguments is Any_Type, and if so, suppress
2166 -- the message, since it is a cascaded error.
2168 if Nkind
(N
) in N_Subprogram_Call
then
2174 A
:= First_Actual
(N
);
2175 while Present
(A
) loop
2178 if Nkind
(E
) = N_Parameter_Association
then
2179 E
:= Explicit_Actual_Parameter
(E
);
2182 if Etype
(E
) = Any_Type
then
2183 if Debug_Flag_V
then
2184 Write_Str
("Any_Type in call");
2195 elsif Nkind
(N
) in N_Binary_Op
2196 and then (Etype
(Left_Opnd
(N
)) = Any_Type
2197 or else Etype
(Right_Opnd
(N
)) = Any_Type
)
2201 elsif Nkind
(N
) in N_Unary_Op
2202 and then Etype
(Right_Opnd
(N
)) = Any_Type
2207 -- Not that special case, so issue message using the
2208 -- flag Ambiguous to control printing of the header
2209 -- message only at the start of an ambiguous set.
2211 if not Ambiguous
then
2212 if Nkind
(N
) = N_Function_Call
2213 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2216 ("ambiguous expression "
2217 & "(cannot resolve indirect call)!", N
);
2219 Error_Msg_NE
-- CODEFIX
2220 ("ambiguous expression (cannot resolve&)!",
2226 if Nkind
(Parent
(Seen
)) = N_Full_Type_Declaration
then
2228 ("\\possible interpretation (inherited)#!", N
);
2230 Error_Msg_N
-- CODEFIX
2231 ("\\possible interpretation#!", N
);
2234 if Nkind
(N
) in N_Subprogram_Call
2235 and then Present
(Parameter_Associations
(N
))
2237 Report_Ambiguous_Argument
;
2241 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2243 -- By default, the error message refers to the candidate
2244 -- interpretation. But if it is a predefined operator, it
2245 -- is implicitly declared at the declaration of the type
2246 -- of the operand. Recover the sloc of that declaration
2247 -- for the error message.
2249 if Nkind
(N
) in N_Op
2250 and then Scope
(It
.Nam
) = Standard_Standard
2251 and then not Is_Overloaded
(Right_Opnd
(N
))
2252 and then Scope
(Base_Type
(Etype
(Right_Opnd
(N
)))) /=
2255 Err_Type
:= First_Subtype
(Etype
(Right_Opnd
(N
)));
2257 if Comes_From_Source
(Err_Type
)
2258 and then Present
(Parent
(Err_Type
))
2260 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2263 elsif Nkind
(N
) in N_Binary_Op
2264 and then Scope
(It
.Nam
) = Standard_Standard
2265 and then not Is_Overloaded
(Left_Opnd
(N
))
2266 and then Scope
(Base_Type
(Etype
(Left_Opnd
(N
)))) /=
2269 Err_Type
:= First_Subtype
(Etype
(Left_Opnd
(N
)));
2271 if Comes_From_Source
(Err_Type
)
2272 and then Present
(Parent
(Err_Type
))
2274 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2277 -- If this is an indirect call, use the subprogram_type
2278 -- in the message, to have a meaningful location. Also
2279 -- indicate if this is an inherited operation, created
2280 -- by a type declaration.
2282 elsif Nkind
(N
) = N_Function_Call
2283 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2284 and then Is_Type
(It
.Nam
)
2288 Sloc
(Associated_Node_For_Itype
(Err_Type
));
2293 if Nkind
(N
) in N_Op
2294 and then Scope
(It
.Nam
) = Standard_Standard
2295 and then Present
(Err_Type
)
2297 -- Special-case the message for universal_fixed
2298 -- operators, which are not declared with the type
2299 -- of the operand, but appear forever in Standard.
2301 if It
.Typ
= Universal_Fixed
2302 and then Scope
(It
.Nam
) = Standard_Standard
2305 ("\\possible interpretation as universal_fixed "
2306 & "operation (RM 4.5.5 (19))", N
);
2309 ("\\possible interpretation (predefined)#!", N
);
2313 Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
2316 ("\\possible interpretation (inherited)#!", N
);
2318 Error_Msg_N
-- CODEFIX
2319 ("\\possible interpretation#!", N
);
2325 -- We have a matching interpretation, Expr_Type is the type
2326 -- from this interpretation, and Seen is the entity.
2328 -- For an operator, just set the entity name. The type will be
2329 -- set by the specific operator resolution routine.
2331 if Nkind
(N
) in N_Op
then
2332 Set_Entity
(N
, Seen
);
2333 Generate_Reference
(Seen
, N
);
2335 elsif Nkind
(N
) = N_Case_Expression
then
2336 Set_Etype
(N
, Expr_Type
);
2338 elsif Nkind
(N
) = N_Character_Literal
then
2339 Set_Etype
(N
, Expr_Type
);
2341 elsif Nkind
(N
) = N_If_Expression
then
2342 Set_Etype
(N
, Expr_Type
);
2344 -- AI05-0139-2: Expression is overloaded because type has
2345 -- implicit dereference. If type matches context, no implicit
2346 -- dereference is involved.
2348 elsif Has_Implicit_Dereference
(Expr_Type
) then
2349 Set_Etype
(N
, Expr_Type
);
2350 Set_Is_Overloaded
(N
, False);
2353 elsif Is_Overloaded
(N
)
2354 and then Present
(It
.Nam
)
2355 and then Ekind
(It
.Nam
) = E_Discriminant
2356 and then Has_Implicit_Dereference
(It
.Nam
)
2358 -- If the node is a general indexing, the dereference is
2359 -- is inserted when resolving the rewritten form, else
2362 if Nkind
(N
) /= N_Indexed_Component
2363 or else No
(Generalized_Indexing
(N
))
2365 Build_Explicit_Dereference
(N
, It
.Nam
);
2368 -- For an explicit dereference, attribute reference, range,
2369 -- short-circuit form (which is not an operator node), or call
2370 -- with a name that is an explicit dereference, there is
2371 -- nothing to be done at this point.
2373 elsif Nkind_In
(N
, N_Explicit_Dereference
,
2374 N_Attribute_Reference
,
2376 N_Indexed_Component
,
2379 N_Selected_Component
,
2381 or else Nkind
(Name
(N
)) = N_Explicit_Dereference
2385 -- For procedure or function calls, set the type of the name,
2386 -- and also the entity pointer for the prefix.
2388 elsif Nkind
(N
) in N_Subprogram_Call
2389 and then Is_Entity_Name
(Name
(N
))
2391 Set_Etype
(Name
(N
), Expr_Type
);
2392 Set_Entity
(Name
(N
), Seen
);
2393 Generate_Reference
(Seen
, Name
(N
));
2395 elsif Nkind
(N
) = N_Function_Call
2396 and then Nkind
(Name
(N
)) = N_Selected_Component
2398 Set_Etype
(Name
(N
), Expr_Type
);
2399 Set_Entity
(Selector_Name
(Name
(N
)), Seen
);
2400 Generate_Reference
(Seen
, Selector_Name
(Name
(N
)));
2402 -- For all other cases, just set the type of the Name
2405 Set_Etype
(Name
(N
), Expr_Type
);
2412 -- Move to next interpretation
2414 exit Interp_Loop
when No
(It
.Typ
);
2416 Get_Next_Interp
(I
, It
);
2417 end loop Interp_Loop
;
2420 -- At this stage Found indicates whether or not an acceptable
2421 -- interpretation exists. If not, then we have an error, except that if
2422 -- the context is Any_Type as a result of some other error, then we
2423 -- suppress the error report.
2426 if Typ
/= Any_Type
then
2428 -- If type we are looking for is Void, then this is the procedure
2429 -- call case, and the error is simply that what we gave is not a
2430 -- procedure name (we think of procedure calls as expressions with
2431 -- types internally, but the user doesn't think of them this way).
2433 if Typ
= Standard_Void_Type
then
2435 -- Special case message if function used as a procedure
2437 if Nkind
(N
) = N_Procedure_Call_Statement
2438 and then Is_Entity_Name
(Name
(N
))
2439 and then Ekind
(Entity
(Name
(N
))) = E_Function
2442 ("cannot use function & in a procedure call",
2443 Name
(N
), Entity
(Name
(N
)));
2445 -- Otherwise give general message (not clear what cases this
2446 -- covers, but no harm in providing for them).
2449 Error_Msg_N
("expect procedure name in procedure call", N
);
2454 -- Otherwise we do have a subexpression with the wrong type
2456 -- Check for the case of an allocator which uses an access type
2457 -- instead of the designated type. This is a common error and we
2458 -- specialize the message, posting an error on the operand of the
2459 -- allocator, complaining that we expected the designated type of
2462 elsif Nkind
(N
) = N_Allocator
2463 and then Is_Access_Type
(Typ
)
2464 and then Is_Access_Type
(Etype
(N
))
2465 and then Designated_Type
(Etype
(N
)) = Typ
2467 Wrong_Type
(Expression
(N
), Designated_Type
(Typ
));
2470 -- Check for view mismatch on Null in instances, for which the
2471 -- view-swapping mechanism has no identifier.
2473 elsif (In_Instance
or else In_Inlined_Body
)
2474 and then (Nkind
(N
) = N_Null
)
2475 and then Is_Private_Type
(Typ
)
2476 and then Is_Access_Type
(Full_View
(Typ
))
2478 Resolve
(N
, Full_View
(Typ
));
2482 -- Check for an aggregate. Sometimes we can get bogus aggregates
2483 -- from misuse of parentheses, and we are about to complain about
2484 -- the aggregate without even looking inside it.
2486 -- Instead, if we have an aggregate of type Any_Composite, then
2487 -- analyze and resolve the component fields, and then only issue
2488 -- another message if we get no errors doing this (otherwise
2489 -- assume that the errors in the aggregate caused the problem).
2491 elsif Nkind
(N
) = N_Aggregate
2492 and then Etype
(N
) = Any_Composite
2494 -- Disable expansion in any case. If there is a type mismatch
2495 -- it may be fatal to try to expand the aggregate. The flag
2496 -- would otherwise be set to false when the error is posted.
2498 Expander_Active
:= False;
2501 procedure Check_Aggr
(Aggr
: Node_Id
);
2502 -- Check one aggregate, and set Found to True if we have a
2503 -- definite error in any of its elements
2505 procedure Check_Elmt
(Aelmt
: Node_Id
);
2506 -- Check one element of aggregate and set Found to True if
2507 -- we definitely have an error in the element.
2513 procedure Check_Aggr
(Aggr
: Node_Id
) is
2517 if Present
(Expressions
(Aggr
)) then
2518 Elmt
:= First
(Expressions
(Aggr
));
2519 while Present
(Elmt
) loop
2525 if Present
(Component_Associations
(Aggr
)) then
2526 Elmt
:= First
(Component_Associations
(Aggr
));
2527 while Present
(Elmt
) loop
2529 -- If this is a default-initialized component, then
2530 -- there is nothing to check. The box will be
2531 -- replaced by the appropriate call during late
2534 if not Box_Present
(Elmt
) then
2535 Check_Elmt
(Expression
(Elmt
));
2547 procedure Check_Elmt
(Aelmt
: Node_Id
) is
2549 -- If we have a nested aggregate, go inside it (to
2550 -- attempt a naked analyze-resolve of the aggregate can
2551 -- cause undesirable cascaded errors). Do not resolve
2552 -- expression if it needs a type from context, as for
2553 -- integer * fixed expression.
2555 if Nkind
(Aelmt
) = N_Aggregate
then
2561 if not Is_Overloaded
(Aelmt
)
2562 and then Etype
(Aelmt
) /= Any_Fixed
2567 if Etype
(Aelmt
) = Any_Type
then
2578 -- Looks like we have a type error, but check for special case
2579 -- of Address wanted, integer found, with the configuration pragma
2580 -- Allow_Integer_Address active. If we have this case, introduce
2581 -- an unchecked conversion to allow the integer expression to be
2582 -- treated as an Address. The reverse case of integer wanted,
2583 -- Address found, is treated in an analogous manner.
2585 if Address_Integer_Convert_OK
(Typ
, Etype
(N
)) then
2586 Rewrite
(N
, Unchecked_Convert_To
(Typ
, Relocate_Node
(N
)));
2587 Analyze_And_Resolve
(N
, Typ
);
2591 -- That special Allow_Integer_Address check did not appply, so we
2592 -- have a real type error. If an error message was issued already,
2593 -- Found got reset to True, so if it's still False, issue standard
2594 -- Wrong_Type message.
2597 if Is_Overloaded
(N
) and then Nkind
(N
) = N_Function_Call
then
2599 Subp_Name
: Node_Id
;
2602 if Is_Entity_Name
(Name
(N
)) then
2603 Subp_Name
:= Name
(N
);
2605 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2607 -- Protected operation: retrieve operation name
2609 Subp_Name
:= Selector_Name
(Name
(N
));
2612 raise Program_Error
;
2615 Error_Msg_Node_2
:= Typ
;
2617 ("no visible interpretation of& "
2618 & "matches expected type&", N
, Subp_Name
);
2621 if All_Errors_Mode
then
2623 Index
: Interp_Index
;
2627 Error_Msg_N
("\\possible interpretations:", N
);
2629 Get_First_Interp
(Name
(N
), Index
, It
);
2630 while Present
(It
.Nam
) loop
2631 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2632 Error_Msg_Node_2
:= It
.Nam
;
2634 ("\\ type& for & declared#", N
, It
.Typ
);
2635 Get_Next_Interp
(Index
, It
);
2640 Error_Msg_N
("\use -gnatf for details", N
);
2644 Wrong_Type
(N
, Typ
);
2652 -- Test if we have more than one interpretation for the context
2654 elsif Ambiguous
then
2658 -- Only one intepretation
2661 -- In Ada 2005, if we have something like "X : T := 2 + 2;", where
2662 -- the "+" on T is abstract, and the operands are of universal type,
2663 -- the above code will have (incorrectly) resolved the "+" to the
2664 -- universal one in Standard. Therefore check for this case and give
2665 -- an error. We can't do this earlier, because it would cause legal
2666 -- cases to get errors (when some other type has an abstract "+").
2668 if Ada_Version
>= Ada_2005
2669 and then Nkind
(N
) in N_Op
2670 and then Is_Overloaded
(N
)
2671 and then Is_Universal_Numeric_Type
(Etype
(Entity
(N
)))
2673 Get_First_Interp
(N
, I
, It
);
2674 while Present
(It
.Typ
) loop
2675 if Present
(It
.Abstract_Op
) and then
2676 Etype
(It
.Abstract_Op
) = Typ
2679 ("cannot call abstract subprogram &!", N
, It
.Abstract_Op
);
2683 Get_Next_Interp
(I
, It
);
2687 -- Here we have an acceptable interpretation for the context
2689 -- Propagate type information and normalize tree for various
2690 -- predefined operations. If the context only imposes a class of
2691 -- types, rather than a specific type, propagate the actual type
2694 if Typ
= Any_Integer
or else
2695 Typ
= Any_Boolean
or else
2696 Typ
= Any_Modular
or else
2697 Typ
= Any_Real
or else
2700 Ctx_Type
:= Expr_Type
;
2702 -- Any_Fixed is legal in a real context only if a specific fixed-
2703 -- point type is imposed. If Norman Cohen can be confused by this,
2704 -- it deserves a separate message.
2707 and then Expr_Type
= Any_Fixed
2709 Error_Msg_N
("illegal context for mixed mode operation", N
);
2710 Set_Etype
(N
, Universal_Real
);
2711 Ctx_Type
:= Universal_Real
;
2715 -- A user-defined operator is transformed into a function call at
2716 -- this point, so that further processing knows that operators are
2717 -- really operators (i.e. are predefined operators). User-defined
2718 -- operators that are intrinsic are just renamings of the predefined
2719 -- ones, and need not be turned into calls either, but if they rename
2720 -- a different operator, we must transform the node accordingly.
2721 -- Instantiations of Unchecked_Conversion are intrinsic but are
2722 -- treated as functions, even if given an operator designator.
2724 if Nkind
(N
) in N_Op
2725 and then Present
(Entity
(N
))
2726 and then Ekind
(Entity
(N
)) /= E_Operator
2729 if not Is_Predefined_Op
(Entity
(N
)) then
2730 Rewrite_Operator_As_Call
(N
, Entity
(N
));
2732 elsif Present
(Alias
(Entity
(N
)))
2734 Nkind
(Parent
(Parent
(Entity
(N
)))) =
2735 N_Subprogram_Renaming_Declaration
2737 Rewrite_Renamed_Operator
(N
, Alias
(Entity
(N
)), Typ
);
2739 -- If the node is rewritten, it will be fully resolved in
2740 -- Rewrite_Renamed_Operator.
2742 if Analyzed
(N
) then
2748 case N_Subexpr
'(Nkind (N)) is
2750 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2752 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2754 when N_Short_Circuit
2755 => Resolve_Short_Circuit (N, Ctx_Type);
2757 when N_Attribute_Reference
2758 => Resolve_Attribute (N, Ctx_Type);
2760 when N_Case_Expression
2761 => Resolve_Case_Expression (N, Ctx_Type);
2763 when N_Character_Literal
2764 => Resolve_Character_Literal (N, Ctx_Type);
2766 when N_Expanded_Name
2767 => Resolve_Entity_Name (N, Ctx_Type);
2769 when N_Explicit_Dereference
2770 => Resolve_Explicit_Dereference (N, Ctx_Type);
2772 when N_Expression_With_Actions
2773 => Resolve_Expression_With_Actions (N, Ctx_Type);
2775 when N_Extension_Aggregate
2776 => Resolve_Extension_Aggregate (N, Ctx_Type);
2778 when N_Function_Call
2779 => Resolve_Call (N, Ctx_Type);
2782 => Resolve_Entity_Name (N, Ctx_Type);
2784 when N_If_Expression
2785 => Resolve_If_Expression (N, Ctx_Type);
2787 when N_Indexed_Component
2788 => Resolve_Indexed_Component (N, Ctx_Type);
2790 when N_Integer_Literal
2791 => Resolve_Integer_Literal (N, Ctx_Type);
2793 when N_Membership_Test
2794 => Resolve_Membership_Op (N, Ctx_Type);
2796 when N_Null => Resolve_Null (N, Ctx_Type);
2798 when N_Op_And | N_Op_Or | N_Op_Xor
2799 => Resolve_Logical_Op (N, Ctx_Type);
2801 when N_Op_Eq | N_Op_Ne
2802 => Resolve_Equality_Op (N, Ctx_Type);
2804 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2805 => Resolve_Comparison_Op (N, Ctx_Type);
2807 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2809 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2810 N_Op_Divide | N_Op_Mod | N_Op_Rem
2812 => Resolve_Arithmetic_Op (N, Ctx_Type);
2814 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2816 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2818 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2819 => Resolve_Unary_Op (N, Ctx_Type);
2821 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2823 when N_Procedure_Call_Statement
2824 => Resolve_Call (N, Ctx_Type);
2826 when N_Operator_Symbol
2827 => Resolve_Operator_Symbol (N, Ctx_Type);
2829 when N_Qualified_Expression
2830 => Resolve_Qualified_Expression (N, Ctx_Type);
2832 -- Why is the following null, needs a comment ???
2834 when N_Quantified_Expression
2837 when N_Raise_Expression
2838 => Resolve_Raise_Expression (N, Ctx_Type);
2840 when N_Raise_xxx_Error
2841 => Set_Etype (N, Ctx_Type);
2843 when N_Range => Resolve_Range (N, Ctx_Type);
2846 => Resolve_Real_Literal (N, Ctx_Type);
2848 when N_Reference => Resolve_Reference (N, Ctx_Type);
2850 when N_Selected_Component
2851 => Resolve_Selected_Component (N, Ctx_Type);
2853 when N_Slice => Resolve_Slice (N, Ctx_Type);
2855 when N_String_Literal
2856 => Resolve_String_Literal (N, Ctx_Type);
2858 when N_Type_Conversion
2859 => Resolve_Type_Conversion (N, Ctx_Type);
2861 when N_Unchecked_Expression =>
2862 Resolve_Unchecked_Expression (N, Ctx_Type);
2864 when N_Unchecked_Type_Conversion =>
2865 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2868 -- Ada 2012 (AI05-0149): Apply an (implicit) conversion to an
2869 -- expression of an anonymous access type that occurs in the context
2870 -- of a named general access type, except when the expression is that
2871 -- of a membership test. This ensures proper legality checking in
2872 -- terms of allowed conversions (expressions that would be illegal to
2873 -- convert implicitly are allowed in membership tests).
2875 if Ada_Version >= Ada_2012
2876 and then Ekind (Ctx_Type) = E_General_Access_Type
2877 and then Ekind (Etype (N)) = E_Anonymous_Access_Type
2878 and then Nkind (Parent (N)) not in N_Membership_Test
2880 Rewrite (N, Convert_To (Ctx_Type, Relocate_Node (N)));
2881 Analyze_And_Resolve (N, Ctx_Type);
2884 -- If the subexpression was replaced by a non-subexpression, then
2885 -- all we do is to expand it. The only legitimate case we know of
2886 -- is converting procedure call statement to entry call statements,
2887 -- but there may be others, so we are making this test general.
2889 if Nkind (N) not in N_Subexpr then
2890 Debug_A_Exit ("resolving ", N, " (done)");
2895 -- The expression is definitely NOT overloaded at this point, so
2896 -- we reset the Is_Overloaded flag to avoid any confusion when
2897 -- reanalyzing the node.
2899 Set_Is_Overloaded (N, False);
2901 -- Freeze expression type, entity if it is a name, and designated
2902 -- type if it is an allocator (RM 13.14(10,11,13)).
2904 -- Now that the resolution of the type of the node is complete, and
2905 -- we did not detect an error, we can expand this node. We skip the
2906 -- expand call if we are in a default expression, see section
2907 -- "Handling of Default Expressions" in Sem spec.
2909 Debug_A_Exit ("resolving ", N, " (done)");
2911 -- We unconditionally freeze the expression, even if we are in
2912 -- default expression mode (the Freeze_Expression routine tests this
2913 -- flag and only freezes static types if it is set).
2915 -- Ada 2012 (AI05-177): The declaration of an expression function
2916 -- does not cause freezing, but we never reach here in that case.
2917 -- Here we are resolving the corresponding expanded body, so we do
2918 -- need to perform normal freezing.
2920 Freeze_Expression (N);
2922 -- Now we can do the expansion
2932 -- Version with check(s) suppressed
2934 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2936 if Suppress = All_Checks then
2938 Sva : constant Suppress_Array := Scope_Suppress.Suppress;
2940 Scope_Suppress.Suppress := (others => True);
2942 Scope_Suppress.Suppress := Sva;
2947 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
2949 Scope_Suppress.Suppress (Suppress) := True;
2951 Scope_Suppress.Suppress (Suppress) := Svg;
2960 -- Version with implicit type
2962 procedure Resolve (N : Node_Id) is
2964 Resolve (N, Etype (N));
2967 ---------------------
2968 -- Resolve_Actuals --
2969 ---------------------
2971 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2972 Loc : constant Source_Ptr := Sloc (N);
2978 Prev : Node_Id := Empty;
2981 procedure Check_Aliased_Parameter;
2982 -- Check rules on aliased parameters and related accessibility rules
2983 -- in (RM 3.10.2 (10.2-10.4)).
2985 procedure Check_Argument_Order;
2986 -- Performs a check for the case where the actuals are all simple
2987 -- identifiers that correspond to the formal names, but in the wrong
2988 -- order, which is considered suspicious and cause for a warning.
2990 procedure Check_Prefixed_Call;
2991 -- If the original node is an overloaded call in prefix notation,
2992 -- insert an 'Access or a dereference as needed over the first actual
.
2993 -- Try_Object_Operation has already verified that there is a valid
2994 -- interpretation, but the form of the actual can only be determined
2995 -- once the primitive operation is identified.
2997 procedure Insert_Default
;
2998 -- If the actual is missing in a call, insert in the actuals list
2999 -- an instance of the default expression. The insertion is always
3000 -- a named association.
3002 procedure Property_Error
3005 Prop_Nam
: Name_Id
);
3006 -- Emit an error concerning variable Var with entity Var_Id that has
3007 -- enabled property Prop_Nam when it acts as an actual parameter in a
3008 -- call and the corresponding formal parameter is of mode IN.
3010 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean;
3011 -- Check whether T1 and T2, or their full views, are derived from a
3012 -- common type. Used to enforce the restrictions on array conversions
3015 function Static_Concatenation
(N
: Node_Id
) return Boolean;
3016 -- Predicate to determine whether an actual that is a concatenation
3017 -- will be evaluated statically and does not need a transient scope.
3018 -- This must be determined before the actual is resolved and expanded
3019 -- because if needed the transient scope must be introduced earlier.
3021 ------------------------------
3022 -- Check_Aliased_Parameter --
3023 ------------------------------
3025 procedure Check_Aliased_Parameter
is
3026 Nominal_Subt
: Entity_Id
;
3029 if Is_Aliased
(F
) then
3030 if Is_Tagged_Type
(A_Typ
) then
3033 elsif Is_Aliased_View
(A
) then
3034 if Is_Constr_Subt_For_U_Nominal
(A_Typ
) then
3035 Nominal_Subt
:= Base_Type
(A_Typ
);
3037 Nominal_Subt
:= A_Typ
;
3040 if Subtypes_Statically_Match
(F_Typ
, Nominal_Subt
) then
3043 -- In a generic body assume the worst for generic formals:
3044 -- they can have a constrained partial view (AI05-041).
3046 elsif Has_Discriminants
(F_Typ
)
3047 and then not Is_Constrained
(F_Typ
)
3048 and then not Has_Constrained_Partial_View
(F_Typ
)
3049 and then not Is_Generic_Type
(F_Typ
)
3054 Error_Msg_NE
("untagged actual does not match "
3055 & "aliased formal&", A
, F
);
3059 Error_Msg_NE
("actual for aliased formal& must be "
3060 & "aliased object", A
, F
);
3063 if Ekind
(Nam
) = E_Procedure
then
3066 elsif Ekind
(Etype
(Nam
)) = E_Anonymous_Access_Type
then
3067 if Nkind
(Parent
(N
)) = N_Type_Conversion
3068 and then Type_Access_Level
(Etype
(Parent
(N
))) <
3069 Object_Access_Level
(A
)
3071 Error_Msg_N
("aliased actual has wrong accessibility", A
);
3074 elsif Nkind
(Parent
(N
)) = N_Qualified_Expression
3075 and then Nkind
(Parent
(Parent
(N
))) = N_Allocator
3076 and then Type_Access_Level
(Etype
(Parent
(Parent
(N
)))) <
3077 Object_Access_Level
(A
)
3080 ("aliased actual in allocator has wrong accessibility", A
);
3083 end Check_Aliased_Parameter
;
3085 --------------------------
3086 -- Check_Argument_Order --
3087 --------------------------
3089 procedure Check_Argument_Order
is
3091 -- Nothing to do if no parameters, or original node is neither a
3092 -- function call nor a procedure call statement (happens in the
3093 -- operator-transformed-to-function call case), or the call does
3094 -- not come from source, or this warning is off.
3096 if not Warn_On_Parameter_Order
3097 or else No
(Parameter_Associations
(N
))
3098 or else Nkind
(Original_Node
(N
)) not in N_Subprogram_Call
3099 or else not Comes_From_Source
(N
)
3105 Nargs
: constant Nat
:= List_Length
(Parameter_Associations
(N
));
3108 -- Nothing to do if only one parameter
3114 -- Here if at least two arguments
3117 Actuals
: array (1 .. Nargs
) of Node_Id
;
3121 Wrong_Order
: Boolean := False;
3122 -- Set True if an out of order case is found
3125 -- Collect identifier names of actuals, fail if any actual is
3126 -- not a simple identifier, and record max length of name.
3128 Actual
:= First
(Parameter_Associations
(N
));
3129 for J
in Actuals
'Range loop
3130 if Nkind
(Actual
) /= N_Identifier
then
3133 Actuals
(J
) := Actual
;
3138 -- If we got this far, all actuals are identifiers and the list
3139 -- of their names is stored in the Actuals array.
3141 Formal
:= First_Formal
(Nam
);
3142 for J
in Actuals
'Range loop
3144 -- If we ran out of formals, that's odd, probably an error
3145 -- which will be detected elsewhere, but abandon the search.
3151 -- If name matches and is in order OK
3153 if Chars
(Formal
) = Chars
(Actuals
(J
)) then
3157 -- If no match, see if it is elsewhere in list and if so
3158 -- flag potential wrong order if type is compatible.
3160 for K
in Actuals
'Range loop
3161 if Chars
(Formal
) = Chars
(Actuals
(K
))
3163 Has_Compatible_Type
(Actuals
(K
), Etype
(Formal
))
3165 Wrong_Order
:= True;
3175 <<Continue
>> Next_Formal
(Formal
);
3178 -- If Formals left over, also probably an error, skip warning
3180 if Present
(Formal
) then
3184 -- Here we give the warning if something was out of order
3188 ("?P?actuals for this call may be in wrong order", N
);
3192 end Check_Argument_Order
;
3194 -------------------------
3195 -- Check_Prefixed_Call --
3196 -------------------------
3198 procedure Check_Prefixed_Call
is
3199 Act
: constant Node_Id
:= First_Actual
(N
);
3200 A_Type
: constant Entity_Id
:= Etype
(Act
);
3201 F_Type
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
3202 Orig
: constant Node_Id
:= Original_Node
(N
);
3206 -- Check whether the call is a prefixed call, with or without
3207 -- additional actuals.
3209 if Nkind
(Orig
) = N_Selected_Component
3211 (Nkind
(Orig
) = N_Indexed_Component
3212 and then Nkind
(Prefix
(Orig
)) = N_Selected_Component
3213 and then Is_Entity_Name
(Prefix
(Prefix
(Orig
)))
3214 and then Is_Entity_Name
(Act
)
3215 and then Chars
(Act
) = Chars
(Prefix
(Prefix
(Orig
))))
3217 if Is_Access_Type
(A_Type
)
3218 and then not Is_Access_Type
(F_Type
)
3220 -- Introduce dereference on object in prefix
3223 Make_Explicit_Dereference
(Sloc
(Act
),
3224 Prefix
=> Relocate_Node
(Act
));
3225 Rewrite
(Act
, New_A
);
3228 elsif Is_Access_Type
(F_Type
)
3229 and then not Is_Access_Type
(A_Type
)
3231 -- Introduce an implicit 'Access in prefix
3233 if not Is_Aliased_View
(Act
) then
3235 ("object in prefixed call to& must be aliased"
3236 & " (RM-2005 4.3.1 (13))",
3241 Make_Attribute_Reference
(Loc
,
3242 Attribute_Name
=> Name_Access
,
3243 Prefix
=> Relocate_Node
(Act
)));
3248 end Check_Prefixed_Call
;
3250 --------------------
3251 -- Insert_Default --
3252 --------------------
3254 procedure Insert_Default
is
3259 -- Missing argument in call, nothing to insert
3261 if No
(Default_Value
(F
)) then
3265 -- Note that we do a full New_Copy_Tree, so that any associated
3266 -- Itypes are properly copied. This may not be needed any more,
3267 -- but it does no harm as a safety measure. Defaults of a generic
3268 -- formal may be out of bounds of the corresponding actual (see
3269 -- cc1311b) and an additional check may be required.
3274 New_Scope
=> Current_Scope
,
3277 if Is_Concurrent_Type
(Scope
(Nam
))
3278 and then Has_Discriminants
(Scope
(Nam
))
3280 Replace_Actual_Discriminants
(N
, Actval
);
3283 if Is_Overloadable
(Nam
)
3284 and then Present
(Alias
(Nam
))
3286 if Base_Type
(Etype
(F
)) /= Base_Type
(Etype
(Actval
))
3287 and then not Is_Tagged_Type
(Etype
(F
))
3289 -- If default is a real literal, do not introduce a
3290 -- conversion whose effect may depend on the run-time
3291 -- size of universal real.
3293 if Nkind
(Actval
) = N_Real_Literal
then
3294 Set_Etype
(Actval
, Base_Type
(Etype
(F
)));
3296 Actval
:= Unchecked_Convert_To
(Etype
(F
), Actval
);
3300 if Is_Scalar_Type
(Etype
(F
)) then
3301 Enable_Range_Check
(Actval
);
3304 Set_Parent
(Actval
, N
);
3306 -- Resolve aggregates with their base type, to avoid scope
3307 -- anomalies: the subtype was first built in the subprogram
3308 -- declaration, and the current call may be nested.
3310 if Nkind
(Actval
) = N_Aggregate
then
3311 Analyze_And_Resolve
(Actval
, Etype
(F
));
3313 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3317 Set_Parent
(Actval
, N
);
3319 -- See note above concerning aggregates
3321 if Nkind
(Actval
) = N_Aggregate
3322 and then Has_Discriminants
(Etype
(Actval
))
3324 Analyze_And_Resolve
(Actval
, Base_Type
(Etype
(Actval
)));
3326 -- Resolve entities with their own type, which may differ from
3327 -- the type of a reference in a generic context (the view
3328 -- swapping mechanism did not anticipate the re-analysis of
3329 -- default values in calls).
3331 elsif Is_Entity_Name
(Actval
) then
3332 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Actval
)));
3335 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3339 -- If default is a tag indeterminate function call, propagate tag
3340 -- to obtain proper dispatching.
3342 if Is_Controlling_Formal
(F
)
3343 and then Nkind
(Default_Value
(F
)) = N_Function_Call
3345 Set_Is_Controlling_Actual
(Actval
);
3350 -- If the default expression raises constraint error, then just
3351 -- silently replace it with an N_Raise_Constraint_Error node, since
3352 -- we already gave the warning on the subprogram spec. If node is
3353 -- already a Raise_Constraint_Error leave as is, to prevent loops in
3354 -- the warnings removal machinery.
3356 if Raises_Constraint_Error
(Actval
)
3357 and then Nkind
(Actval
) /= N_Raise_Constraint_Error
3360 Make_Raise_Constraint_Error
(Loc
,
3361 Reason
=> CE_Range_Check_Failed
));
3362 Set_Raises_Constraint_Error
(Actval
);
3363 Set_Etype
(Actval
, Etype
(F
));
3367 Make_Parameter_Association
(Loc
,
3368 Explicit_Actual_Parameter
=> Actval
,
3369 Selector_Name
=> Make_Identifier
(Loc
, Chars
(F
)));
3371 -- Case of insertion is first named actual
3373 if No
(Prev
) or else
3374 Nkind
(Parent
(Prev
)) /= N_Parameter_Association
3376 Set_Next_Named_Actual
(Assoc
, First_Named_Actual
(N
));
3377 Set_First_Named_Actual
(N
, Actval
);
3380 if No
(Parameter_Associations
(N
)) then
3381 Set_Parameter_Associations
(N
, New_List
(Assoc
));
3383 Append
(Assoc
, Parameter_Associations
(N
));
3387 Insert_After
(Prev
, Assoc
);
3390 -- Case of insertion is not first named actual
3393 Set_Next_Named_Actual
3394 (Assoc
, Next_Named_Actual
(Parent
(Prev
)));
3395 Set_Next_Named_Actual
(Parent
(Prev
), Actval
);
3396 Append
(Assoc
, Parameter_Associations
(N
));
3399 Mark_Rewrite_Insertion
(Assoc
);
3400 Mark_Rewrite_Insertion
(Actval
);
3405 --------------------
3406 -- Property_Error --
3407 --------------------
3409 procedure Property_Error
3415 Error_Msg_Name_1
:= Prop_Nam
;
3417 ("external variable & with enabled property % cannot appear as "
3418 & "actual in procedure call (SPARK RM 7.1.3(11))", Var
, Var_Id
);
3419 Error_Msg_N
("\\corresponding formal parameter has mode In", Var
);
3426 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean is
3427 FT1
: Entity_Id
:= T1
;
3428 FT2
: Entity_Id
:= T2
;
3431 if Is_Private_Type
(T1
)
3432 and then Present
(Full_View
(T1
))
3434 FT1
:= Full_View
(T1
);
3437 if Is_Private_Type
(T2
)
3438 and then Present
(Full_View
(T2
))
3440 FT2
:= Full_View
(T2
);
3443 return Root_Type
(Base_Type
(FT1
)) = Root_Type
(Base_Type
(FT2
));
3446 --------------------------
3447 -- Static_Concatenation --
3448 --------------------------
3450 function Static_Concatenation
(N
: Node_Id
) return Boolean is
3453 when N_String_Literal
=>
3458 -- Concatenation is static when both operands are static and
3459 -- the concatenation operator is a predefined one.
3461 return Scope
(Entity
(N
)) = Standard_Standard
3463 Static_Concatenation
(Left_Opnd
(N
))
3465 Static_Concatenation
(Right_Opnd
(N
));
3468 if Is_Entity_Name
(N
) then
3470 Ent
: constant Entity_Id
:= Entity
(N
);
3472 return Ekind
(Ent
) = E_Constant
3473 and then Present
(Constant_Value
(Ent
))
3475 Is_OK_Static_Expression
(Constant_Value
(Ent
));
3482 end Static_Concatenation
;
3484 -- Start of processing for Resolve_Actuals
3487 Check_Argument_Order
;
3488 Check_Function_Writable_Actuals
(N
);
3490 if Present
(First_Actual
(N
)) then
3491 Check_Prefixed_Call
;
3494 A
:= First_Actual
(N
);
3495 F
:= First_Formal
(Nam
);
3496 while Present
(F
) loop
3497 if No
(A
) and then Needs_No_Actuals
(Nam
) then
3500 -- If we have an error in any actual or formal, indicated by a type
3501 -- of Any_Type, then abandon resolution attempt, and set result type
3502 -- to Any_Type. Skip this if the actual is a Raise_Expression, whose
3503 -- type is imposed from context.
3505 elsif (Present
(A
) and then Etype
(A
) = Any_Type
)
3506 or else Etype
(F
) = Any_Type
3508 if Nkind
(A
) /= N_Raise_Expression
then
3509 Set_Etype
(N
, Any_Type
);
3514 -- Case where actual is present
3516 -- If the actual is an entity, generate a reference to it now. We
3517 -- do this before the actual is resolved, because a formal of some
3518 -- protected subprogram, or a task discriminant, will be rewritten
3519 -- during expansion, and the source entity reference may be lost.
3522 and then Is_Entity_Name
(A
)
3523 and then Comes_From_Source
(N
)
3525 Orig_A
:= Entity
(A
);
3527 if Present
(Orig_A
) then
3528 if Is_Formal
(Orig_A
)
3529 and then Ekind
(F
) /= E_In_Parameter
3531 Generate_Reference
(Orig_A
, A
, 'm');
3533 elsif not Is_Overloaded
(A
) then
3534 if Ekind
(F
) /= E_Out_Parameter
then
3535 Generate_Reference
(Orig_A
, A
);
3537 -- RM 6.4.1(12): For an out parameter that is passed by
3538 -- copy, the formal parameter object is created, and:
3540 -- * For an access type, the formal parameter is initialized
3541 -- from the value of the actual, without checking that the
3542 -- value satisfies any constraint, any predicate, or any
3543 -- exclusion of the null value.
3545 -- * For a scalar type that has the Default_Value aspect
3546 -- specified, the formal parameter is initialized from the
3547 -- value of the actual, without checking that the value
3548 -- satisfies any constraint or any predicate.
3549 -- I do not understand why this case is included??? this is
3550 -- not a case where an OUT parameter is treated as IN OUT.
3552 -- * For a composite type with discriminants or that has
3553 -- implicit initial values for any subcomponents, the
3554 -- behavior is as for an in out parameter passed by copy.
3556 -- Hence for these cases we generate the read reference now
3557 -- (the write reference will be generated later by
3558 -- Note_Possible_Modification).
3560 elsif Is_By_Copy_Type
(Etype
(F
))
3562 (Is_Access_Type
(Etype
(F
))
3564 (Is_Scalar_Type
(Etype
(F
))
3566 Present
(Default_Aspect_Value
(Etype
(F
))))
3568 (Is_Composite_Type
(Etype
(F
))
3569 and then (Has_Discriminants
(Etype
(F
))
3570 or else Is_Partially_Initialized_Type
3573 Generate_Reference
(Orig_A
, A
);
3580 and then (Nkind
(Parent
(A
)) /= N_Parameter_Association
3581 or else Chars
(Selector_Name
(Parent
(A
))) = Chars
(F
))
3583 -- If style checking mode on, check match of formal name
3586 if Nkind
(Parent
(A
)) = N_Parameter_Association
then
3587 Check_Identifier
(Selector_Name
(Parent
(A
)), F
);
3591 -- If the formal is Out or In_Out, do not resolve and expand the
3592 -- conversion, because it is subsequently expanded into explicit
3593 -- temporaries and assignments. However, the object of the
3594 -- conversion can be resolved. An exception is the case of tagged
3595 -- type conversion with a class-wide actual. In that case we want
3596 -- the tag check to occur and no temporary will be needed (no
3597 -- representation change can occur) and the parameter is passed by
3598 -- reference, so we go ahead and resolve the type conversion.
3599 -- Another exception is the case of reference to component or
3600 -- subcomponent of a bit-packed array, in which case we want to
3601 -- defer expansion to the point the in and out assignments are
3604 if Ekind
(F
) /= E_In_Parameter
3605 and then Nkind
(A
) = N_Type_Conversion
3606 and then not Is_Class_Wide_Type
(Etype
(Expression
(A
)))
3608 if Ekind
(F
) = E_In_Out_Parameter
3609 and then Is_Array_Type
(Etype
(F
))
3611 -- In a view conversion, the conversion must be legal in
3612 -- both directions, and thus both component types must be
3613 -- aliased, or neither (4.6 (8)).
3615 -- The extra rule in 4.6 (24.9.2) seems unduly restrictive:
3616 -- the privacy requirement should not apply to generic
3617 -- types, and should be checked in an instance. ARG query
3620 if Has_Aliased_Components
(Etype
(Expression
(A
))) /=
3621 Has_Aliased_Components
(Etype
(F
))
3624 ("both component types in a view conversion must be"
3625 & " aliased, or neither", A
);
3627 -- Comment here??? what set of cases???
3630 not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
3632 -- Check view conv between unrelated by ref array types
3634 if Is_By_Reference_Type
(Etype
(F
))
3635 or else Is_By_Reference_Type
(Etype
(Expression
(A
)))
3638 ("view conversion between unrelated by reference "
3639 & "array types not allowed (\'A'I-00246)", A
);
3641 -- In Ada 2005 mode, check view conversion component
3642 -- type cannot be private, tagged, or volatile. Note
3643 -- that we only apply this to source conversions. The
3644 -- generated code can contain conversions which are
3645 -- not subject to this test, and we cannot extract the
3646 -- component type in such cases since it is not present.
3648 elsif Comes_From_Source
(A
)
3649 and then Ada_Version
>= Ada_2005
3652 Comp_Type
: constant Entity_Id
:=
3654 (Etype
(Expression
(A
)));
3656 if (Is_Private_Type
(Comp_Type
)
3657 and then not Is_Generic_Type
(Comp_Type
))
3658 or else Is_Tagged_Type
(Comp_Type
)
3659 or else Is_Volatile
(Comp_Type
)
3662 ("component type of a view conversion cannot"
3663 & " be private, tagged, or volatile"
3672 -- Resolve expression if conversion is all OK
3674 if (Conversion_OK
(A
)
3675 or else Valid_Conversion
(A
, Etype
(A
), Expression
(A
)))
3676 and then not Is_Ref_To_Bit_Packed_Array
(Expression
(A
))
3678 Resolve
(Expression
(A
));
3681 -- If the actual is a function call that returns a limited
3682 -- unconstrained object that needs finalization, create a
3683 -- transient scope for it, so that it can receive the proper
3684 -- finalization list.
3686 elsif Nkind
(A
) = N_Function_Call
3687 and then Is_Limited_Record
(Etype
(F
))
3688 and then not Is_Constrained
(Etype
(F
))
3689 and then Expander_Active
3690 and then (Is_Controlled
(Etype
(F
)) or else Has_Task
(Etype
(F
)))
3692 Establish_Transient_Scope
(A
, Sec_Stack
=> False);
3693 Resolve
(A
, Etype
(F
));
3695 -- A small optimization: if one of the actuals is a concatenation
3696 -- create a block around a procedure call to recover stack space.
3697 -- This alleviates stack usage when several procedure calls in
3698 -- the same statement list use concatenation. We do not perform
3699 -- this wrapping for code statements, where the argument is a
3700 -- static string, and we want to preserve warnings involving
3701 -- sequences of such statements.
3703 elsif Nkind
(A
) = N_Op_Concat
3704 and then Nkind
(N
) = N_Procedure_Call_Statement
3705 and then Expander_Active
3707 not (Is_Intrinsic_Subprogram
(Nam
)
3708 and then Chars
(Nam
) = Name_Asm
)
3709 and then not Static_Concatenation
(A
)
3711 Establish_Transient_Scope
(A
, Sec_Stack
=> False);
3712 Resolve
(A
, Etype
(F
));
3715 if Nkind
(A
) = N_Type_Conversion
3716 and then Is_Array_Type
(Etype
(F
))
3717 and then not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
3719 (Is_Limited_Type
(Etype
(F
))
3720 or else Is_Limited_Type
(Etype
(Expression
(A
))))
3723 ("conversion between unrelated limited array types "
3724 & "not allowed ('A'I-00246)", A
);
3726 if Is_Limited_Type
(Etype
(F
)) then
3727 Explain_Limited_Type
(Etype
(F
), A
);
3730 if Is_Limited_Type
(Etype
(Expression
(A
))) then
3731 Explain_Limited_Type
(Etype
(Expression
(A
)), A
);
3735 -- (Ada 2005: AI-251): If the actual is an allocator whose
3736 -- directly designated type is a class-wide interface, we build
3737 -- an anonymous access type to use it as the type of the
3738 -- allocator. Later, when the subprogram call is expanded, if
3739 -- the interface has a secondary dispatch table the expander
3740 -- will add a type conversion to force the correct displacement
3743 if Nkind
(A
) = N_Allocator
then
3745 DDT
: constant Entity_Id
:=
3746 Directly_Designated_Type
(Base_Type
(Etype
(F
)));
3748 New_Itype
: Entity_Id
;
3751 if Is_Class_Wide_Type
(DDT
)
3752 and then Is_Interface
(DDT
)
3754 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, A
);
3755 Set_Etype
(New_Itype
, Etype
(A
));
3756 Set_Directly_Designated_Type
3757 (New_Itype
, Directly_Designated_Type
(Etype
(A
)));
3758 Set_Etype
(A
, New_Itype
);
3761 -- Ada 2005, AI-162:If the actual is an allocator, the
3762 -- innermost enclosing statement is the master of the
3763 -- created object. This needs to be done with expansion
3764 -- enabled only, otherwise the transient scope will not
3765 -- be removed in the expansion of the wrapped construct.
3767 if (Is_Controlled
(DDT
) or else Has_Task
(DDT
))
3768 and then Expander_Active
3770 Establish_Transient_Scope
(A
, Sec_Stack
=> False);
3774 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
3775 Check_Restriction
(No_Access_Parameter_Allocators
, A
);
3779 -- (Ada 2005): The call may be to a primitive operation of a
3780 -- tagged synchronized type, declared outside of the type. In
3781 -- this case the controlling actual must be converted to its
3782 -- corresponding record type, which is the formal type. The
3783 -- actual may be a subtype, either because of a constraint or
3784 -- because it is a generic actual, so use base type to locate
3787 F_Typ
:= Base_Type
(Etype
(F
));
3789 if Is_Tagged_Type
(F_Typ
)
3790 and then (Is_Concurrent_Type
(F_Typ
)
3791 or else Is_Concurrent_Record_Type
(F_Typ
))
3793 -- If the actual is overloaded, look for an interpretation
3794 -- that has a synchronized type.
3796 if not Is_Overloaded
(A
) then
3797 A_Typ
:= Base_Type
(Etype
(A
));
3801 Index
: Interp_Index
;
3805 Get_First_Interp
(A
, Index
, It
);
3806 while Present
(It
.Typ
) loop
3807 if Is_Concurrent_Type
(It
.Typ
)
3808 or else Is_Concurrent_Record_Type
(It
.Typ
)
3810 A_Typ
:= Base_Type
(It
.Typ
);
3814 Get_Next_Interp
(Index
, It
);
3820 Full_A_Typ
: Entity_Id
;
3823 if Present
(Full_View
(A_Typ
)) then
3824 Full_A_Typ
:= Base_Type
(Full_View
(A_Typ
));
3826 Full_A_Typ
:= A_Typ
;
3829 -- Tagged synchronized type (case 1): the actual is a
3832 if Is_Concurrent_Type
(A_Typ
)
3833 and then Corresponding_Record_Type
(A_Typ
) = F_Typ
3836 Unchecked_Convert_To
3837 (Corresponding_Record_Type
(A_Typ
), A
));
3838 Resolve
(A
, Etype
(F
));
3840 -- Tagged synchronized type (case 2): the formal is a
3843 elsif Ekind
(Full_A_Typ
) = E_Record_Type
3845 (Corresponding_Concurrent_Type
(Full_A_Typ
))
3846 and then Is_Concurrent_Type
(F_Typ
)
3847 and then Present
(Corresponding_Record_Type
(F_Typ
))
3848 and then Full_A_Typ
= Corresponding_Record_Type
(F_Typ
)
3850 Resolve
(A
, Corresponding_Record_Type
(F_Typ
));
3855 Resolve
(A
, Etype
(F
));
3859 -- Not a synchronized operation
3862 Resolve
(A
, Etype
(F
));
3869 -- An actual cannot be an untagged formal incomplete type
3871 if Ekind
(A_Typ
) = E_Incomplete_Type
3872 and then not Is_Tagged_Type
(A_Typ
)
3873 and then Is_Generic_Type
(A_Typ
)
3876 ("invalid use of untagged formal incomplete type", A
);
3879 if Comes_From_Source
(Original_Node
(N
))
3880 and then Nkind_In
(Original_Node
(N
), N_Function_Call
,
3881 N_Procedure_Call_Statement
)
3883 -- In formal mode, check that actual parameters matching
3884 -- formals of tagged types are objects (or ancestor type
3885 -- conversions of objects), not general expressions.
3887 if Is_Actual_Tagged_Parameter
(A
) then
3888 if Is_SPARK_Object_Reference
(A
) then
3891 elsif Nkind
(A
) = N_Type_Conversion
then
3893 Operand
: constant Node_Id
:= Expression
(A
);
3894 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
3895 Target_Typ
: constant Entity_Id
:= A_Typ
;
3898 if not Is_SPARK_Object_Reference
(Operand
) then
3899 Check_SPARK_Restriction
3900 ("object required", Operand
);
3902 -- In formal mode, the only view conversions are those
3903 -- involving ancestor conversion of an extended type.
3906 (Is_Tagged_Type
(Target_Typ
)
3907 and then not Is_Class_Wide_Type
(Target_Typ
)
3908 and then Is_Tagged_Type
(Operand_Typ
)
3909 and then not Is_Class_Wide_Type
(Operand_Typ
)
3910 and then Is_Ancestor
(Target_Typ
, Operand_Typ
))
3913 (F
, E_Out_Parameter
, E_In_Out_Parameter
)
3915 Check_SPARK_Restriction
3916 ("ancestor conversion is the only permitted "
3917 & "view conversion", A
);
3919 Check_SPARK_Restriction
3920 ("ancestor conversion required", A
);
3929 Check_SPARK_Restriction
("object required", A
);
3932 -- In formal mode, the only view conversions are those
3933 -- involving ancestor conversion of an extended type.
3935 elsif Nkind
(A
) = N_Type_Conversion
3936 and then Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
)
3938 Check_SPARK_Restriction
3939 ("ancestor conversion is the only permitted view "
3944 -- has warnings suppressed, then we reset Never_Set_In_Source for
3945 -- the calling entity. The reason for this is to catch cases like
3946 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3947 -- uses trickery to modify an IN parameter.
3949 if Ekind
(F
) = E_In_Parameter
3950 and then Is_Entity_Name
(A
)
3951 and then Present
(Entity
(A
))
3952 and then Ekind
(Entity
(A
)) = E_Variable
3953 and then Has_Warnings_Off
(F_Typ
)
3955 Set_Never_Set_In_Source
(Entity
(A
), False);
3958 -- Perform error checks for IN and IN OUT parameters
3960 if Ekind
(F
) /= E_Out_Parameter
then
3962 -- Check unset reference. For scalar parameters, it is clearly
3963 -- wrong to pass an uninitialized value as either an IN or
3964 -- IN-OUT parameter. For composites, it is also clearly an
3965 -- error to pass a completely uninitialized value as an IN
3966 -- parameter, but the case of IN OUT is trickier. We prefer
3967 -- not to give a warning here. For example, suppose there is
3968 -- a routine that sets some component of a record to False.
3969 -- It is perfectly reasonable to make this IN-OUT and allow
3970 -- either initialized or uninitialized records to be passed
3973 -- For partially initialized composite values, we also avoid
3974 -- warnings, since it is quite likely that we are passing a
3975 -- partially initialized value and only the initialized fields
3976 -- will in fact be read in the subprogram.
3978 if Is_Scalar_Type
(A_Typ
)
3979 or else (Ekind
(F
) = E_In_Parameter
3980 and then not Is_Partially_Initialized_Type
(A_Typ
))
3982 Check_Unset_Reference
(A
);
3985 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3986 -- actual to a nested call, since this is case of reading an
3987 -- out parameter, which is not allowed.
3989 if Ada_Version
= Ada_83
3990 and then Is_Entity_Name
(A
)
3991 and then Ekind
(Entity
(A
)) = E_Out_Parameter
3993 Error_Msg_N
("(Ada 83) illegal reading of out parameter", A
);
3997 -- Case of OUT or IN OUT parameter
3999 if Ekind
(F
) /= E_In_Parameter
then
4001 -- For an Out parameter, check for useless assignment. Note
4002 -- that we can't set Last_Assignment this early, because we may
4003 -- kill current values in Resolve_Call, and that call would
4004 -- clobber the Last_Assignment field.
4006 -- Note: call Warn_On_Useless_Assignment before doing the check
4007 -- below for Is_OK_Variable_For_Out_Formal so that the setting
4008 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
4009 -- reflects the last assignment, not this one.
4011 if Ekind
(F
) = E_Out_Parameter
then
4012 if Warn_On_Modified_As_Out_Parameter
(F
)
4013 and then Is_Entity_Name
(A
)
4014 and then Present
(Entity
(A
))
4015 and then Comes_From_Source
(N
)
4017 Warn_On_Useless_Assignment
(Entity
(A
), A
);
4021 -- Validate the form of the actual. Note that the call to
4022 -- Is_OK_Variable_For_Out_Formal generates the required
4023 -- reference in this case.
4025 -- A call to an initialization procedure for an aggregate
4026 -- component may initialize a nested component of a constant
4027 -- designated object. In this context the object is variable.
4029 if not Is_OK_Variable_For_Out_Formal
(A
)
4030 and then not Is_Init_Proc
(Nam
)
4032 Error_Msg_NE
("actual for& must be a variable", A
, F
);
4034 if Is_Subprogram
(Current_Scope
)
4036 (Is_Invariant_Procedure
(Current_Scope
)
4037 or else Is_Predicate_Function
(Current_Scope
))
4040 ("function used in predicate cannot "
4041 & "modify its argument", F
);
4045 -- What's the following about???
4047 if Is_Entity_Name
(A
) then
4048 Kill_Checks
(Entity
(A
));
4054 if Etype
(A
) = Any_Type
then
4055 Set_Etype
(N
, Any_Type
);
4059 -- Apply appropriate constraint/predicate checks for IN [OUT] case
4061 if Ekind_In
(F
, E_In_Parameter
, E_In_Out_Parameter
) then
4063 -- Apply predicate tests except in certain special cases. Note
4064 -- that it might be more consistent to apply these only when
4065 -- expansion is active (in Exp_Ch6.Expand_Actuals), as we do
4066 -- for the outbound predicate tests ???
4068 if Predicate_Tests_On_Arguments
(Nam
) then
4069 Apply_Predicate_Check
(A
, F_Typ
);
4072 -- Apply required constraint checks
4074 -- Gigi looks at the check flag and uses the appropriate types.
4075 -- For now since one flag is used there is an optimization
4076 -- which might not be done in the IN OUT case since Gigi does
4077 -- not do any analysis. More thought required about this ???
4079 -- In fact is this comment obsolete??? doesn't the expander now
4080 -- generate all these tests anyway???
4082 if Is_Scalar_Type
(Etype
(A
)) then
4083 Apply_Scalar_Range_Check
(A
, F_Typ
);
4085 elsif Is_Array_Type
(Etype
(A
)) then
4086 Apply_Length_Check
(A
, F_Typ
);
4088 elsif Is_Record_Type
(F_Typ
)
4089 and then Has_Discriminants
(F_Typ
)
4090 and then Is_Constrained
(F_Typ
)
4091 and then (not Is_Derived_Type
(F_Typ
)
4092 or else Comes_From_Source
(Nam
))
4094 Apply_Discriminant_Check
(A
, F_Typ
);
4096 -- For view conversions of a discriminated object, apply
4097 -- check to object itself, the conversion alreay has the
4100 if Nkind
(A
) = N_Type_Conversion
4101 and then Is_Constrained
(Etype
(Expression
(A
)))
4103 Apply_Discriminant_Check
(Expression
(A
), F_Typ
);
4106 elsif Is_Access_Type
(F_Typ
)
4107 and then Is_Array_Type
(Designated_Type
(F_Typ
))
4108 and then Is_Constrained
(Designated_Type
(F_Typ
))
4110 Apply_Length_Check
(A
, F_Typ
);
4112 elsif Is_Access_Type
(F_Typ
)
4113 and then Has_Discriminants
(Designated_Type
(F_Typ
))
4114 and then Is_Constrained
(Designated_Type
(F_Typ
))
4116 Apply_Discriminant_Check
(A
, F_Typ
);
4119 Apply_Range_Check
(A
, F_Typ
);
4122 -- Ada 2005 (AI-231): Note that the controlling parameter case
4123 -- already existed in Ada 95, which is partially checked
4124 -- elsewhere (see Checks), and we don't want the warning
4125 -- message to differ.
4127 if Is_Access_Type
(F_Typ
)
4128 and then Can_Never_Be_Null
(F_Typ
)
4129 and then Known_Null
(A
)
4131 if Is_Controlling_Formal
(F
) then
4132 Apply_Compile_Time_Constraint_Error
4134 Msg
=> "null value not allowed here??",
4135 Reason
=> CE_Access_Check_Failed
);
4137 elsif Ada_Version
>= Ada_2005
then
4138 Apply_Compile_Time_Constraint_Error
4140 Msg
=> "(Ada 2005) null not allowed in "
4141 & "null-excluding formal??",
4142 Reason
=> CE_Null_Not_Allowed
);
4147 -- Checks for OUT parameters and IN OUT parameters
4149 if Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
) then
4151 -- If there is a type conversion, to make sure the return value
4152 -- meets the constraints of the variable before the conversion.
4154 if Nkind
(A
) = N_Type_Conversion
then
4155 if Is_Scalar_Type
(A_Typ
) then
4156 Apply_Scalar_Range_Check
4157 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4160 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4163 -- If no conversion apply scalar range checks and length checks
4164 -- base on the subtype of the actual (NOT that of the formal).
4167 if Is_Scalar_Type
(F_Typ
) then
4168 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
4169 elsif Is_Array_Type
(F_Typ
)
4170 and then Ekind
(F
) = E_Out_Parameter
4172 Apply_Length_Check
(A
, F_Typ
);
4174 Apply_Range_Check
(A
, A_Typ
, F_Typ
);
4178 -- Note: we do not apply the predicate checks for the case of
4179 -- OUT and IN OUT parameters. They are instead applied in the
4180 -- Expand_Actuals routine in Exp_Ch6.
4183 -- An actual associated with an access parameter is implicitly
4184 -- converted to the anonymous access type of the formal and must
4185 -- satisfy the legality checks for access conversions.
4187 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
4188 if not Valid_Conversion
(A
, F_Typ
, A
) then
4190 ("invalid implicit conversion for access parameter", A
);
4193 -- If the actual is an access selected component of a variable,
4194 -- the call may modify its designated object. It is reasonable
4195 -- to treat this as a potential modification of the enclosing
4196 -- record, to prevent spurious warnings that it should be
4197 -- declared as a constant, because intuitively programmers
4198 -- regard the designated subcomponent as part of the record.
4200 if Nkind
(A
) = N_Selected_Component
4201 and then Is_Entity_Name
(Prefix
(A
))
4202 and then not Is_Constant_Object
(Entity
(Prefix
(A
)))
4204 Note_Possible_Modification
(A
, Sure
=> False);
4208 -- Check bad case of atomic/volatile argument (RM C.6(12))
4210 if Is_By_Reference_Type
(Etype
(F
))
4211 and then Comes_From_Source
(N
)
4213 if Is_Atomic_Object
(A
)
4214 and then not Is_Atomic
(Etype
(F
))
4217 ("cannot pass atomic argument to non-atomic formal&",
4220 elsif Is_Volatile_Object
(A
)
4221 and then not Is_Volatile
(Etype
(F
))
4224 ("cannot pass volatile argument to non-volatile formal&",
4229 -- Check that subprograms don't have improper controlling
4230 -- arguments (RM 3.9.2 (9)).
4232 -- A primitive operation may have an access parameter of an
4233 -- incomplete tagged type, but a dispatching call is illegal
4234 -- if the type is still incomplete.
4236 if Is_Controlling_Formal
(F
) then
4237 Set_Is_Controlling_Actual
(A
);
4239 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
4241 Desig
: constant Entity_Id
:= Designated_Type
(Etype
(F
));
4243 if Ekind
(Desig
) = E_Incomplete_Type
4244 and then No
(Full_View
(Desig
))
4245 and then No
(Non_Limited_View
(Desig
))
4248 ("premature use of incomplete type& "
4249 & "in dispatching call", A
, Desig
);
4254 elsif Nkind
(A
) = N_Explicit_Dereference
then
4255 Validate_Remote_Access_To_Class_Wide_Type
(A
);
4258 if (Is_Class_Wide_Type
(A_Typ
) or else Is_Dynamically_Tagged
(A
))
4259 and then not Is_Class_Wide_Type
(F_Typ
)
4260 and then not Is_Controlling_Formal
(F
)
4262 Error_Msg_N
("class-wide argument not allowed here!", A
);
4264 if Is_Subprogram
(Nam
)
4265 and then Comes_From_Source
(Nam
)
4267 Error_Msg_Node_2
:= F_Typ
;
4269 ("& is not a dispatching operation of &!", A
, Nam
);
4272 -- Apply the checks described in 3.10.2(27): if the context is a
4273 -- specific access-to-object, the actual cannot be class-wide.
4274 -- Use base type to exclude access_to_subprogram cases.
4276 elsif Is_Access_Type
(A_Typ
)
4277 and then Is_Access_Type
(F_Typ
)
4278 and then not Is_Access_Subprogram_Type
(Base_Type
(F_Typ
))
4279 and then (Is_Class_Wide_Type
(Designated_Type
(A_Typ
))
4280 or else (Nkind
(A
) = N_Attribute_Reference
4282 Is_Class_Wide_Type
(Etype
(Prefix
(A
)))))
4283 and then not Is_Class_Wide_Type
(Designated_Type
(F_Typ
))
4284 and then not Is_Controlling_Formal
(F
)
4286 -- Disable these checks for call to imported C++ subprograms
4289 (Is_Entity_Name
(Name
(N
))
4290 and then Is_Imported
(Entity
(Name
(N
)))
4291 and then Convention
(Entity
(Name
(N
))) = Convention_CPP
)
4294 ("access to class-wide argument not allowed here!", A
);
4296 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
4297 Error_Msg_Node_2
:= Designated_Type
(F_Typ
);
4299 ("& is not a dispatching operation of &!", A
, Nam
);
4303 Check_Aliased_Parameter
;
4307 -- If it is a named association, treat the selector_name as a
4308 -- proper identifier, and mark the corresponding entity.
4310 if Nkind
(Parent
(A
)) = N_Parameter_Association
4312 -- Ignore reference in SPARK mode, as it refers to an entity not
4313 -- in scope at the point of reference, so the reference should
4314 -- be ignored for computing effects of subprograms.
4316 and then not GNATprove_Mode
4318 Set_Entity
(Selector_Name
(Parent
(A
)), F
);
4319 Generate_Reference
(F
, Selector_Name
(Parent
(A
)));
4320 Set_Etype
(Selector_Name
(Parent
(A
)), F_Typ
);
4321 Generate_Reference
(F_Typ
, N
, ' ');
4326 if Ekind
(F
) /= E_Out_Parameter
then
4327 Check_Unset_Reference
(A
);
4330 -- The following checks are only relevant when SPARK_Mode is on as
4331 -- they are not standard Ada legality rule. Internally generated
4332 -- temporaries are ignored.
4335 and then Is_Effectively_Volatile_Object
(A
)
4336 and then Comes_From_Source
(A
)
4338 -- An effectively volatile object may act as an actual
4339 -- parameter when the corresponding formal is of a non-scalar
4342 if Is_Volatile
(Etype
(F
))
4343 and then not Is_Scalar_Type
(Etype
(F
))
4347 -- An effectively volatile object may act as an actual
4348 -- parameter in a call to an instance of Unchecked_Conversion.
4350 elsif Is_Unchecked_Conversion_Instance
(Nam
) then
4355 ("volatile object cannot act as actual in a call (SPARK "
4356 & "RM 7.1.3(12))", A
);
4359 -- Detect an external variable with an enabled property that
4360 -- does not match the mode of the corresponding formal in a
4361 -- procedure call. Functions are not considered because they
4362 -- cannot have effectively volatile formal parameters in the
4365 if Ekind
(Nam
) = E_Procedure
4366 and then Is_Entity_Name
(A
)
4367 and then Present
(Entity
(A
))
4368 and then Ekind
(Entity
(A
)) = E_Variable
4372 if Ekind
(F
) = E_In_Parameter
then
4373 if Async_Readers_Enabled
(A_Id
) then
4374 Property_Error
(A
, A_Id
, Name_Async_Readers
);
4375 elsif Effective_Reads_Enabled
(A_Id
) then
4376 Property_Error
(A
, A_Id
, Name_Effective_Reads
);
4377 elsif Effective_Writes_Enabled
(A_Id
) then
4378 Property_Error
(A
, A_Id
, Name_Effective_Writes
);
4381 elsif Ekind
(F
) = E_Out_Parameter
4382 and then Async_Writers_Enabled
(A_Id
)
4384 Error_Msg_Name_1
:= Name_Async_Writers
;
4386 ("external variable & with enabled property % cannot "
4387 & "appear as actual in procedure call "
4388 & "(SPARK RM 7.1.3(11))", A
, A_Id
);
4390 ("\\corresponding formal parameter has mode Out", A
);
4397 -- Case where actual is not present
4405 end Resolve_Actuals
;
4407 -----------------------
4408 -- Resolve_Allocator --
4409 -----------------------
4411 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
) is
4412 Desig_T
: constant Entity_Id
:= Designated_Type
(Typ
);
4413 E
: constant Node_Id
:= Expression
(N
);
4415 Discrim
: Entity_Id
;
4418 Assoc
: Node_Id
:= Empty
;
4421 procedure Check_Allocator_Discrim_Accessibility
4422 (Disc_Exp
: Node_Id
;
4423 Alloc_Typ
: Entity_Id
);
4424 -- Check that accessibility level associated with an access discriminant
4425 -- initialized in an allocator by the expression Disc_Exp is not deeper
4426 -- than the level of the allocator type Alloc_Typ. An error message is
4427 -- issued if this condition is violated. Specialized checks are done for
4428 -- the cases of a constraint expression which is an access attribute or
4429 -- an access discriminant.
4431 function In_Dispatching_Context
return Boolean;
4432 -- If the allocator is an actual in a call, it is allowed to be class-
4433 -- wide when the context is not because it is a controlling actual.
4435 -------------------------------------------
4436 -- Check_Allocator_Discrim_Accessibility --
4437 -------------------------------------------
4439 procedure Check_Allocator_Discrim_Accessibility
4440 (Disc_Exp
: Node_Id
;
4441 Alloc_Typ
: Entity_Id
)
4444 if Type_Access_Level
(Etype
(Disc_Exp
)) >
4445 Deepest_Type_Access_Level
(Alloc_Typ
)
4448 ("operand type has deeper level than allocator type", Disc_Exp
);
4450 -- When the expression is an Access attribute the level of the prefix
4451 -- object must not be deeper than that of the allocator's type.
4453 elsif Nkind
(Disc_Exp
) = N_Attribute_Reference
4454 and then Get_Attribute_Id
(Attribute_Name
(Disc_Exp
)) =
4456 and then Object_Access_Level
(Prefix
(Disc_Exp
)) >
4457 Deepest_Type_Access_Level
(Alloc_Typ
)
4460 ("prefix of attribute has deeper level than allocator type",
4463 -- When the expression is an access discriminant the check is against
4464 -- the level of the prefix object.
4466 elsif Ekind
(Etype
(Disc_Exp
)) = E_Anonymous_Access_Type
4467 and then Nkind
(Disc_Exp
) = N_Selected_Component
4468 and then Object_Access_Level
(Prefix
(Disc_Exp
)) >
4469 Deepest_Type_Access_Level
(Alloc_Typ
)
4472 ("access discriminant has deeper level than allocator type",
4475 -- All other cases are legal
4480 end Check_Allocator_Discrim_Accessibility
;
4482 ----------------------------
4483 -- In_Dispatching_Context --
4484 ----------------------------
4486 function In_Dispatching_Context
return Boolean is
4487 Par
: constant Node_Id
:= Parent
(N
);
4490 return Nkind
(Par
) in N_Subprogram_Call
4491 and then Is_Entity_Name
(Name
(Par
))
4492 and then Is_Dispatching_Operation
(Entity
(Name
(Par
)));
4493 end In_Dispatching_Context
;
4495 -- Start of processing for Resolve_Allocator
4498 -- Replace general access with specific type
4500 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
4501 Set_Etype
(N
, Base_Type
(Typ
));
4504 if Is_Abstract_Type
(Typ
) then
4505 Error_Msg_N
("type of allocator cannot be abstract", N
);
4508 -- For qualified expression, resolve the expression using the given
4509 -- subtype (nothing to do for type mark, subtype indication)
4511 if Nkind
(E
) = N_Qualified_Expression
then
4512 if Is_Class_Wide_Type
(Etype
(E
))
4513 and then not Is_Class_Wide_Type
(Desig_T
)
4514 and then not In_Dispatching_Context
4517 ("class-wide allocator not allowed for this access type", N
);
4520 Resolve
(Expression
(E
), Etype
(E
));
4521 Check_Non_Static_Context
(Expression
(E
));
4522 Check_Unset_Reference
(Expression
(E
));
4524 -- A qualified expression requires an exact match of the type.
4525 -- Class-wide matching is not allowed.
4527 if (Is_Class_Wide_Type
(Etype
(Expression
(E
)))
4528 or else Is_Class_Wide_Type
(Etype
(E
)))
4529 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Etype
(E
))
4531 Wrong_Type
(Expression
(E
), Etype
(E
));
4534 -- Calls to build-in-place functions are not currently supported in
4535 -- allocators for access types associated with a simple storage pool.
4536 -- Supporting such allocators may require passing additional implicit
4537 -- parameters to build-in-place functions (or a significant revision
4538 -- of the current b-i-p implementation to unify the handling for
4539 -- multiple kinds of storage pools). ???
4541 if Is_Limited_View
(Desig_T
)
4542 and then Nkind
(Expression
(E
)) = N_Function_Call
4545 Pool
: constant Entity_Id
:=
4546 Associated_Storage_Pool
(Root_Type
(Typ
));
4550 Present
(Get_Rep_Pragma
4551 (Etype
(Pool
), Name_Simple_Storage_Pool_Type
))
4554 ("limited function calls not yet supported in simple "
4555 & "storage pool allocators", Expression
(E
));
4560 -- A special accessibility check is needed for allocators that
4561 -- constrain access discriminants. The level of the type of the
4562 -- expression used to constrain an access discriminant cannot be
4563 -- deeper than the type of the allocator (in contrast to access
4564 -- parameters, where the level of the actual can be arbitrary).
4566 -- We can't use Valid_Conversion to perform this check because in
4567 -- general the type of the allocator is unrelated to the type of
4568 -- the access discriminant.
4570 if Ekind
(Typ
) /= E_Anonymous_Access_Type
4571 or else Is_Local_Anonymous_Access
(Typ
)
4573 Subtyp
:= Entity
(Subtype_Mark
(E
));
4575 Aggr
:= Original_Node
(Expression
(E
));
4577 if Has_Discriminants
(Subtyp
)
4578 and then Nkind_In
(Aggr
, N_Aggregate
, N_Extension_Aggregate
)
4580 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
4582 -- Get the first component expression of the aggregate
4584 if Present
(Expressions
(Aggr
)) then
4585 Disc_Exp
:= First
(Expressions
(Aggr
));
4587 elsif Present
(Component_Associations
(Aggr
)) then
4588 Assoc
:= First
(Component_Associations
(Aggr
));
4590 if Present
(Assoc
) then
4591 Disc_Exp
:= Expression
(Assoc
);
4600 while Present
(Discrim
) and then Present
(Disc_Exp
) loop
4601 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
4602 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
4605 Next_Discriminant
(Discrim
);
4607 if Present
(Discrim
) then
4608 if Present
(Assoc
) then
4610 Disc_Exp
:= Expression
(Assoc
);
4612 elsif Present
(Next
(Disc_Exp
)) then
4616 Assoc
:= First
(Component_Associations
(Aggr
));
4618 if Present
(Assoc
) then
4619 Disc_Exp
:= Expression
(Assoc
);
4629 -- For a subtype mark or subtype indication, freeze the subtype
4632 Freeze_Expression
(E
);
4634 if Is_Access_Constant
(Typ
) and then not No_Initialization
(N
) then
4636 ("initialization required for access-to-constant allocator", N
);
4639 -- A special accessibility check is needed for allocators that
4640 -- constrain access discriminants. The level of the type of the
4641 -- expression used to constrain an access discriminant cannot be
4642 -- deeper than the type of the allocator (in contrast to access
4643 -- parameters, where the level of the actual can be arbitrary).
4644 -- We can't use Valid_Conversion to perform this check because
4645 -- in general the type of the allocator is unrelated to the type
4646 -- of the access discriminant.
4648 if Nkind
(Original_Node
(E
)) = N_Subtype_Indication
4649 and then (Ekind
(Typ
) /= E_Anonymous_Access_Type
4650 or else Is_Local_Anonymous_Access
(Typ
))
4652 Subtyp
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
4654 if Has_Discriminants
(Subtyp
) then
4655 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
4656 Constr
:= First
(Constraints
(Constraint
(Original_Node
(E
))));
4657 while Present
(Discrim
) and then Present
(Constr
) loop
4658 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
4659 if Nkind
(Constr
) = N_Discriminant_Association
then
4660 Disc_Exp
:= Original_Node
(Expression
(Constr
));
4662 Disc_Exp
:= Original_Node
(Constr
);
4665 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
4668 Next_Discriminant
(Discrim
);
4675 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4676 -- check that the level of the type of the created object is not deeper
4677 -- than the level of the allocator's access type, since extensions can
4678 -- now occur at deeper levels than their ancestor types. This is a
4679 -- static accessibility level check; a run-time check is also needed in
4680 -- the case of an initialized allocator with a class-wide argument (see
4681 -- Expand_Allocator_Expression).
4683 if Ada_Version
>= Ada_2005
4684 and then Is_Class_Wide_Type
(Desig_T
)
4687 Exp_Typ
: Entity_Id
;
4690 if Nkind
(E
) = N_Qualified_Expression
then
4691 Exp_Typ
:= Etype
(E
);
4692 elsif Nkind
(E
) = N_Subtype_Indication
then
4693 Exp_Typ
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
4695 Exp_Typ
:= Entity
(E
);
4698 if Type_Access_Level
(Exp_Typ
) >
4699 Deepest_Type_Access_Level
(Typ
)
4701 if In_Instance_Body
then
4702 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4704 ("type in allocator has deeper level than "
4705 & "designated class-wide type<<", E
);
4706 Error_Msg_N
("\Program_Error [<<", E
);
4708 Make_Raise_Program_Error
(Sloc
(N
),
4709 Reason
=> PE_Accessibility_Check_Failed
));
4712 -- Do not apply Ada 2005 accessibility checks on a class-wide
4713 -- allocator if the type given in the allocator is a formal
4714 -- type. A run-time check will be performed in the instance.
4716 elsif not Is_Generic_Type
(Exp_Typ
) then
4717 Error_Msg_N
("type in allocator has deeper level than "
4718 & "designated class-wide type", E
);
4724 -- Check for allocation from an empty storage pool
4726 if No_Pool_Assigned
(Typ
) then
4727 Error_Msg_N
("allocation from empty storage pool!", N
);
4729 -- If the context is an unchecked conversion, as may happen within an
4730 -- inlined subprogram, the allocator is being resolved with its own
4731 -- anonymous type. In that case, if the target type has a specific
4732 -- storage pool, it must be inherited explicitly by the allocator type.
4734 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
4735 and then No
(Associated_Storage_Pool
(Typ
))
4737 Set_Associated_Storage_Pool
4738 (Typ
, Associated_Storage_Pool
(Etype
(Parent
(N
))));
4741 if Ekind
(Etype
(N
)) = E_Anonymous_Access_Type
then
4742 Check_Restriction
(No_Anonymous_Allocators
, N
);
4745 -- Check that an allocator with task parts isn't for a nested access
4746 -- type when restriction No_Task_Hierarchy applies.
4748 if not Is_Library_Level_Entity
(Base_Type
(Typ
))
4749 and then Has_Task
(Base_Type
(Desig_T
))
4751 Check_Restriction
(No_Task_Hierarchy
, N
);
4754 -- An illegal allocator may be rewritten as a raise Program_Error
4757 if Nkind
(N
) = N_Allocator
then
4759 -- An anonymous access discriminant is the definition of a
4762 if Ekind
(Typ
) = E_Anonymous_Access_Type
4763 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
4764 N_Discriminant_Specification
4767 Discr
: constant Entity_Id
:=
4768 Defining_Identifier
(Associated_Node_For_Itype
(Typ
));
4771 Check_Restriction
(No_Coextensions
, N
);
4773 -- Ada 2012 AI05-0052: If the designated type of the allocator
4774 -- is limited, then the allocator shall not be used to define
4775 -- the value of an access discriminant unless the discriminated
4776 -- type is immutably limited.
4778 if Ada_Version
>= Ada_2012
4779 and then Is_Limited_Type
(Desig_T
)
4780 and then not Is_Limited_View
(Scope
(Discr
))
4783 ("only immutably limited types can have anonymous "
4784 & "access discriminants designating a limited type", N
);
4788 -- Avoid marking an allocator as a dynamic coextension if it is
4789 -- within a static construct.
4791 if not Is_Static_Coextension
(N
) then
4792 Set_Is_Dynamic_Coextension
(N
);
4795 -- Cleanup for potential static coextensions
4798 Set_Is_Dynamic_Coextension
(N
, False);
4799 Set_Is_Static_Coextension
(N
, False);
4803 -- Report a simple error: if the designated object is a local task,
4804 -- its body has not been seen yet, and its activation will fail an
4805 -- elaboration check.
4807 if Is_Task_Type
(Desig_T
)
4808 and then Scope
(Base_Type
(Desig_T
)) = Current_Scope
4809 and then Is_Compilation_Unit
(Current_Scope
)
4810 and then Ekind
(Current_Scope
) = E_Package
4811 and then not In_Package_Body
(Current_Scope
)
4813 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4814 Error_Msg_N
("cannot activate task before body seen<<", N
);
4815 Error_Msg_N
("\Program_Error [<<", N
);
4818 -- Ada 2012 (AI05-0111-3): Detect an attempt to allocate a task or a
4819 -- type with a task component on a subpool. This action must raise
4820 -- Program_Error at runtime.
4822 if Ada_Version
>= Ada_2012
4823 and then Nkind
(N
) = N_Allocator
4824 and then Present
(Subpool_Handle_Name
(N
))
4825 and then Has_Task
(Desig_T
)
4827 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4828 Error_Msg_N
("cannot allocate task on subpool<<", N
);
4829 Error_Msg_N
("\Program_Error [<<", N
);
4832 Make_Raise_Program_Error
(Sloc
(N
),
4833 Reason
=> PE_Explicit_Raise
));
4836 end Resolve_Allocator
;
4838 ---------------------------
4839 -- Resolve_Arithmetic_Op --
4840 ---------------------------
4842 -- Used for resolving all arithmetic operators except exponentiation
4844 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
4845 L
: constant Node_Id
:= Left_Opnd
(N
);
4846 R
: constant Node_Id
:= Right_Opnd
(N
);
4847 TL
: constant Entity_Id
:= Base_Type
(Etype
(L
));
4848 TR
: constant Entity_Id
:= Base_Type
(Etype
(R
));
4852 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
4853 -- We do the resolution using the base type, because intermediate values
4854 -- in expressions always are of the base type, not a subtype of it.
4856 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean;
4857 -- Returns True if N is in a context that expects "any real type"
4859 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean;
4860 -- Return True iff given type is Integer or universal real/integer
4862 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
);
4863 -- Choose type of integer literal in fixed-point operation to conform
4864 -- to available fixed-point type. T is the type of the other operand,
4865 -- which is needed to determine the expected type of N.
4867 procedure Set_Operand_Type
(N
: Node_Id
);
4868 -- Set operand type to T if universal
4870 -------------------------------
4871 -- Expected_Type_Is_Any_Real --
4872 -------------------------------
4874 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean is
4876 -- N is the expression after "delta" in a fixed_point_definition;
4879 return Nkind_In
(Parent
(N
), N_Ordinary_Fixed_Point_Definition
,
4880 N_Decimal_Fixed_Point_Definition
,
4882 -- N is one of the bounds in a real_range_specification;
4885 N_Real_Range_Specification
,
4887 -- N is the expression of a delta_constraint;
4890 N_Delta_Constraint
);
4891 end Expected_Type_Is_Any_Real
;
4893 -----------------------------
4894 -- Is_Integer_Or_Universal --
4895 -----------------------------
4897 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean is
4899 Index
: Interp_Index
;
4903 if not Is_Overloaded
(N
) then
4905 return Base_Type
(T
) = Base_Type
(Standard_Integer
)
4906 or else T
= Universal_Integer
4907 or else T
= Universal_Real
;
4909 Get_First_Interp
(N
, Index
, It
);
4910 while Present
(It
.Typ
) loop
4911 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
)
4912 or else It
.Typ
= Universal_Integer
4913 or else It
.Typ
= Universal_Real
4918 Get_Next_Interp
(Index
, It
);
4923 end Is_Integer_Or_Universal
;
4925 ----------------------------
4926 -- Set_Mixed_Mode_Operand --
4927 ----------------------------
4929 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
) is
4930 Index
: Interp_Index
;
4934 if Universal_Interpretation
(N
) = Universal_Integer
then
4936 -- A universal integer literal is resolved as standard integer
4937 -- except in the case of a fixed-point result, where we leave it
4938 -- as universal (to be handled by Exp_Fixd later on)
4940 if Is_Fixed_Point_Type
(T
) then
4941 Resolve
(N
, Universal_Integer
);
4943 Resolve
(N
, Standard_Integer
);
4946 elsif Universal_Interpretation
(N
) = Universal_Real
4947 and then (T
= Base_Type
(Standard_Integer
)
4948 or else T
= Universal_Integer
4949 or else T
= Universal_Real
)
4951 -- A universal real can appear in a fixed-type context. We resolve
4952 -- the literal with that context, even though this might raise an
4953 -- exception prematurely (the other operand may be zero).
4957 elsif Etype
(N
) = Base_Type
(Standard_Integer
)
4958 and then T
= Universal_Real
4959 and then Is_Overloaded
(N
)
4961 -- Integer arg in mixed-mode operation. Resolve with universal
4962 -- type, in case preference rule must be applied.
4964 Resolve
(N
, Universal_Integer
);
4967 and then B_Typ
/= Universal_Fixed
4969 -- Not a mixed-mode operation, resolve with context
4973 elsif Etype
(N
) = Any_Fixed
then
4975 -- N may itself be a mixed-mode operation, so use context type
4979 elsif Is_Fixed_Point_Type
(T
)
4980 and then B_Typ
= Universal_Fixed
4981 and then Is_Overloaded
(N
)
4983 -- Must be (fixed * fixed) operation, operand must have one
4984 -- compatible interpretation.
4986 Resolve
(N
, Any_Fixed
);
4988 elsif Is_Fixed_Point_Type
(B_Typ
)
4989 and then (T
= Universal_Real
or else Is_Fixed_Point_Type
(T
))
4990 and then Is_Overloaded
(N
)
4992 -- C * F(X) in a fixed context, where C is a real literal or a
4993 -- fixed-point expression. F must have either a fixed type
4994 -- interpretation or an integer interpretation, but not both.
4996 Get_First_Interp
(N
, Index
, It
);
4997 while Present
(It
.Typ
) loop
4998 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
) then
4999 if Analyzed
(N
) then
5000 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5002 Resolve
(N
, Standard_Integer
);
5005 elsif Is_Fixed_Point_Type
(It
.Typ
) then
5006 if Analyzed
(N
) then
5007 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5009 Resolve
(N
, It
.Typ
);
5013 Get_Next_Interp
(Index
, It
);
5016 -- Reanalyze the literal with the fixed type of the context. If
5017 -- context is Universal_Fixed, we are within a conversion, leave
5018 -- the literal as a universal real because there is no usable
5019 -- fixed type, and the target of the conversion plays no role in
5033 if B_Typ
= Universal_Fixed
5034 and then Nkind
(Op2
) = N_Real_Literal
5036 T2
:= Universal_Real
;
5041 Set_Analyzed
(Op2
, False);
5048 end Set_Mixed_Mode_Operand
;
5050 ----------------------
5051 -- Set_Operand_Type --
5052 ----------------------
5054 procedure Set_Operand_Type
(N
: Node_Id
) is
5056 if Etype
(N
) = Universal_Integer
5057 or else Etype
(N
) = Universal_Real
5061 end Set_Operand_Type
;
5063 -- Start of processing for Resolve_Arithmetic_Op
5066 if Comes_From_Source
(N
)
5067 and then Ekind
(Entity
(N
)) = E_Function
5068 and then Is_Imported
(Entity
(N
))
5069 and then Is_Intrinsic_Subprogram
(Entity
(N
))
5071 Resolve_Intrinsic_Operator
(N
, Typ
);
5074 -- Special-case for mixed-mode universal expressions or fixed point type
5075 -- operation: each argument is resolved separately. The same treatment
5076 -- is required if one of the operands of a fixed point operation is
5077 -- universal real, since in this case we don't do a conversion to a
5078 -- specific fixed-point type (instead the expander handles the case).
5080 -- Set the type of the node to its universal interpretation because
5081 -- legality checks on an exponentiation operand need the context.
5083 elsif (B_Typ
= Universal_Integer
or else B_Typ
= Universal_Real
)
5084 and then Present
(Universal_Interpretation
(L
))
5085 and then Present
(Universal_Interpretation
(R
))
5087 Set_Etype
(N
, B_Typ
);
5088 Resolve
(L
, Universal_Interpretation
(L
));
5089 Resolve
(R
, Universal_Interpretation
(R
));
5091 elsif (B_Typ
= Universal_Real
5092 or else Etype
(N
) = Universal_Fixed
5093 or else (Etype
(N
) = Any_Fixed
5094 and then Is_Fixed_Point_Type
(B_Typ
))
5095 or else (Is_Fixed_Point_Type
(B_Typ
)
5096 and then (Is_Integer_Or_Universal
(L
)
5098 Is_Integer_Or_Universal
(R
))))
5099 and then Nkind_In
(N
, N_Op_Multiply
, N_Op_Divide
)
5101 if TL
= Universal_Integer
or else TR
= Universal_Integer
then
5102 Check_For_Visible_Operator
(N
, B_Typ
);
5105 -- If context is a fixed type and one operand is integer, the other
5106 -- is resolved with the type of the context.
5108 if Is_Fixed_Point_Type
(B_Typ
)
5109 and then (Base_Type
(TL
) = Base_Type
(Standard_Integer
)
5110 or else TL
= Universal_Integer
)
5115 elsif Is_Fixed_Point_Type
(B_Typ
)
5116 and then (Base_Type
(TR
) = Base_Type
(Standard_Integer
)
5117 or else TR
= Universal_Integer
)
5123 Set_Mixed_Mode_Operand
(L
, TR
);
5124 Set_Mixed_Mode_Operand
(R
, TL
);
5127 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
5128 -- multiplying operators from being used when the expected type is
5129 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
5130 -- some cases where the expected type is actually Any_Real;
5131 -- Expected_Type_Is_Any_Real takes care of that case.
5133 if Etype
(N
) = Universal_Fixed
5134 or else Etype
(N
) = Any_Fixed
5136 if B_Typ
= Universal_Fixed
5137 and then not Expected_Type_Is_Any_Real
(N
)
5138 and then not Nkind_In
(Parent
(N
), N_Type_Conversion
,
5139 N_Unchecked_Type_Conversion
)
5141 Error_Msg_N
("type cannot be determined from context!", N
);
5142 Error_Msg_N
("\explicit conversion to result type required", N
);
5144 Set_Etype
(L
, Any_Type
);
5145 Set_Etype
(R
, Any_Type
);
5148 if Ada_Version
= Ada_83
5149 and then Etype
(N
) = Universal_Fixed
5151 Nkind_In
(Parent
(N
), N_Type_Conversion
,
5152 N_Unchecked_Type_Conversion
)
5155 ("(Ada 83) fixed-point operation "
5156 & "needs explicit conversion", N
);
5159 -- The expected type is "any real type" in contexts like
5161 -- type T is delta <universal_fixed-expression> ...
5163 -- in which case we need to set the type to Universal_Real
5164 -- so that static expression evaluation will work properly.
5166 if Expected_Type_Is_Any_Real
(N
) then
5167 Set_Etype
(N
, Universal_Real
);
5169 Set_Etype
(N
, B_Typ
);
5173 elsif Is_Fixed_Point_Type
(B_Typ
)
5174 and then (Is_Integer_Or_Universal
(L
)
5175 or else Nkind
(L
) = N_Real_Literal
5176 or else Nkind
(R
) = N_Real_Literal
5177 or else Is_Integer_Or_Universal
(R
))
5179 Set_Etype
(N
, B_Typ
);
5181 elsif Etype
(N
) = Any_Fixed
then
5183 -- If no previous errors, this is only possible if one operand is
5184 -- overloaded and the context is universal. Resolve as such.
5186 Set_Etype
(N
, B_Typ
);
5190 if (TL
= Universal_Integer
or else TL
= Universal_Real
)
5192 (TR
= Universal_Integer
or else TR
= Universal_Real
)
5194 Check_For_Visible_Operator
(N
, B_Typ
);
5197 -- If the context is Universal_Fixed and the operands are also
5198 -- universal fixed, this is an error, unless there is only one
5199 -- applicable fixed_point type (usually Duration).
5201 if B_Typ
= Universal_Fixed
and then Etype
(L
) = Universal_Fixed
then
5202 T
:= Unique_Fixed_Point_Type
(N
);
5204 if T
= Any_Type
then
5217 -- If one of the arguments was resolved to a non-universal type.
5218 -- label the result of the operation itself with the same type.
5219 -- Do the same for the universal argument, if any.
5221 T
:= Intersect_Types
(L
, R
);
5222 Set_Etype
(N
, Base_Type
(T
));
5223 Set_Operand_Type
(L
);
5224 Set_Operand_Type
(R
);
5227 Generate_Operator_Reference
(N
, Typ
);
5228 Analyze_Dimension
(N
);
5229 Eval_Arithmetic_Op
(N
);
5231 -- In SPARK, a multiplication or division with operands of fixed point
5232 -- types must be qualified or explicitly converted to identify the
5235 if (Is_Fixed_Point_Type
(Etype
(L
))
5236 or else Is_Fixed_Point_Type
(Etype
(R
)))
5237 and then Nkind_In
(N
, N_Op_Multiply
, N_Op_Divide
)
5239 not Nkind_In
(Parent
(N
), N_Qualified_Expression
, N_Type_Conversion
)
5241 Check_SPARK_Restriction
5242 ("operation should be qualified or explicitly converted", N
);
5245 -- Set overflow and division checking bit
5247 if Nkind
(N
) in N_Op
then
5248 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
5249 Enable_Overflow_Check
(N
);
5252 -- Give warning if explicit division by zero
5254 if Nkind_In
(N
, N_Op_Divide
, N_Op_Rem
, N_Op_Mod
)
5255 and then not Division_Checks_Suppressed
(Etype
(N
))
5257 Rop
:= Right_Opnd
(N
);
5259 if Compile_Time_Known_Value
(Rop
)
5260 and then ((Is_Integer_Type
(Etype
(Rop
))
5261 and then Expr_Value
(Rop
) = Uint_0
)
5263 (Is_Real_Type
(Etype
(Rop
))
5264 and then Expr_Value_R
(Rop
) = Ureal_0
))
5266 -- Specialize the warning message according to the operation.
5267 -- The following warnings are for the case
5272 -- For division, we have two cases, for float division
5273 -- of an unconstrained float type, on a machine where
5274 -- Machine_Overflows is false, we don't get an exception
5275 -- at run-time, but rather an infinity or Nan. The Nan
5276 -- case is pretty obscure, so just warn about infinities.
5278 if Is_Floating_Point_Type
(Typ
)
5279 and then not Is_Constrained
(Typ
)
5280 and then not Machine_Overflows_On_Target
5283 ("float division by zero, may generate "
5284 & "'+'/'- infinity??", Right_Opnd
(N
));
5286 -- For all other cases, we get a Constraint_Error
5289 Apply_Compile_Time_Constraint_Error
5290 (N
, "division by zero??", CE_Divide_By_Zero
,
5291 Loc
=> Sloc
(Right_Opnd
(N
)));
5295 Apply_Compile_Time_Constraint_Error
5296 (N
, "rem with zero divisor??", CE_Divide_By_Zero
,
5297 Loc
=> Sloc
(Right_Opnd
(N
)));
5300 Apply_Compile_Time_Constraint_Error
5301 (N
, "mod with zero divisor??", CE_Divide_By_Zero
,
5302 Loc
=> Sloc
(Right_Opnd
(N
)));
5304 -- Division by zero can only happen with division, rem,
5305 -- and mod operations.
5308 raise Program_Error
;
5311 -- Otherwise just set the flag to check at run time
5314 Activate_Division_Check
(N
);
5318 -- If Restriction No_Implicit_Conditionals is active, then it is
5319 -- violated if either operand can be negative for mod, or for rem
5320 -- if both operands can be negative.
5322 if Restriction_Check_Required
(No_Implicit_Conditionals
)
5323 and then Nkind_In
(N
, N_Op_Rem
, N_Op_Mod
)
5332 -- Set if corresponding operand might be negative
5336 (Left_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
5337 LNeg
:= (not OK
) or else Lo
< 0;
5340 (Right_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
5341 RNeg
:= (not OK
) or else Lo
< 0;
5343 -- Check if we will be generating conditionals. There are two
5344 -- cases where that can happen, first for REM, the only case
5345 -- is largest negative integer mod -1, where the division can
5346 -- overflow, but we still have to give the right result. The
5347 -- front end generates a test for this annoying case. Here we
5348 -- just test if both operands can be negative (that's what the
5349 -- expander does, so we match its logic here).
5351 -- The second case is mod where either operand can be negative.
5352 -- In this case, the back end has to generate additional tests.
5354 if (Nkind
(N
) = N_Op_Rem
and then (LNeg
and RNeg
))
5356 (Nkind
(N
) = N_Op_Mod
and then (LNeg
or RNeg
))
5358 Check_Restriction
(No_Implicit_Conditionals
, N
);
5364 Check_Unset_Reference
(L
);
5365 Check_Unset_Reference
(R
);
5366 Check_Function_Writable_Actuals
(N
);
5367 end Resolve_Arithmetic_Op
;
5373 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
5374 function Same_Or_Aliased_Subprograms
5376 E
: Entity_Id
) return Boolean;
5377 -- Returns True if the subprogram entity S is the same as E or else
5378 -- S is an alias of E.
5380 ---------------------------------
5381 -- Same_Or_Aliased_Subprograms --
5382 ---------------------------------
5384 function Same_Or_Aliased_Subprograms
5386 E
: Entity_Id
) return Boolean
5388 Subp_Alias
: constant Entity_Id
:= Alias
(S
);
5390 return S
= E
or else (Present
(Subp_Alias
) and then Subp_Alias
= E
);
5391 end Same_Or_Aliased_Subprograms
;
5395 Loc
: constant Source_Ptr
:= Sloc
(N
);
5396 Subp
: constant Node_Id
:= Name
(N
);
5397 Body_Id
: Entity_Id
;
5407 -- Start of processing for Resolve_Call
5410 -- The context imposes a unique interpretation with type Typ on a
5411 -- procedure or function call. Find the entity of the subprogram that
5412 -- yields the expected type, and propagate the corresponding formal
5413 -- constraints on the actuals. The caller has established that an
5414 -- interpretation exists, and emitted an error if not unique.
5416 -- First deal with the case of a call to an access-to-subprogram,
5417 -- dereference made explicit in Analyze_Call.
5419 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
5420 if not Is_Overloaded
(Subp
) then
5421 Nam
:= Etype
(Subp
);
5424 -- Find the interpretation whose type (a subprogram type) has a
5425 -- return type that is compatible with the context. Analysis of
5426 -- the node has established that one exists.
5430 Get_First_Interp
(Subp
, I
, It
);
5431 while Present
(It
.Typ
) loop
5432 if Covers
(Typ
, Etype
(It
.Typ
)) then
5437 Get_Next_Interp
(I
, It
);
5441 raise Program_Error
;
5445 -- If the prefix is not an entity, then resolve it
5447 if not Is_Entity_Name
(Subp
) then
5448 Resolve
(Subp
, Nam
);
5451 -- For an indirect call, we always invalidate checks, since we do not
5452 -- know whether the subprogram is local or global. Yes we could do
5453 -- better here, e.g. by knowing that there are no local subprograms,
5454 -- but it does not seem worth the effort. Similarly, we kill all
5455 -- knowledge of current constant values.
5457 Kill_Current_Values
;
5459 -- If this is a procedure call which is really an entry call, do
5460 -- the conversion of the procedure call to an entry call. Protected
5461 -- operations use the same circuitry because the name in the call
5462 -- can be an arbitrary expression with special resolution rules.
5464 elsif Nkind_In
(Subp
, N_Selected_Component
, N_Indexed_Component
)
5465 or else (Is_Entity_Name
(Subp
)
5466 and then Ekind
(Entity
(Subp
)) = E_Entry
)
5468 Resolve_Entry_Call
(N
, Typ
);
5469 Check_Elab_Call
(N
);
5471 -- Kill checks and constant values, as above for indirect case
5472 -- Who knows what happens when another task is activated?
5474 Kill_Current_Values
;
5477 -- Normal subprogram call with name established in Resolve
5479 elsif not (Is_Type
(Entity
(Subp
))) then
5480 Nam
:= Entity
(Subp
);
5481 Set_Entity_With_Checks
(Subp
, Nam
);
5483 -- Otherwise we must have the case of an overloaded call
5486 pragma Assert
(Is_Overloaded
(Subp
));
5488 -- Initialize Nam to prevent warning (we know it will be assigned
5489 -- in the loop below, but the compiler does not know that).
5493 Get_First_Interp
(Subp
, I
, It
);
5494 while Present
(It
.Typ
) loop
5495 if Covers
(Typ
, It
.Typ
) then
5497 Set_Entity_With_Checks
(Subp
, Nam
);
5501 Get_Next_Interp
(I
, It
);
5505 if Is_Access_Subprogram_Type
(Base_Type
(Etype
(Nam
)))
5506 and then not Is_Access_Subprogram_Type
(Base_Type
(Typ
))
5507 and then Nkind
(Subp
) /= N_Explicit_Dereference
5508 and then Present
(Parameter_Associations
(N
))
5510 -- The prefix is a parameterless function call that returns an access
5511 -- to subprogram. If parameters are present in the current call, add
5512 -- add an explicit dereference. We use the base type here because
5513 -- within an instance these may be subtypes.
5515 -- The dereference is added either in Analyze_Call or here. Should
5516 -- be consolidated ???
5518 Set_Is_Overloaded
(Subp
, False);
5519 Set_Etype
(Subp
, Etype
(Nam
));
5520 Insert_Explicit_Dereference
(Subp
);
5521 Nam
:= Designated_Type
(Etype
(Nam
));
5522 Resolve
(Subp
, Nam
);
5525 -- Check that a call to Current_Task does not occur in an entry body
5527 if Is_RTE
(Nam
, RE_Current_Task
) then
5536 -- Exclude calls that occur within the default of a formal
5537 -- parameter of the entry, since those are evaluated outside
5540 exit when No
(P
) or else Nkind
(P
) = N_Parameter_Specification
;
5542 if Nkind
(P
) = N_Entry_Body
5543 or else (Nkind
(P
) = N_Subprogram_Body
5544 and then Is_Entry_Barrier_Function
(P
))
5547 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5549 ("& should not be used in entry body (RM C.7(17))<<",
5551 Error_Msg_NE
("\Program_Error [<<", N
, Nam
);
5553 Make_Raise_Program_Error
(Loc
,
5554 Reason
=> PE_Current_Task_In_Entry_Body
));
5555 Set_Etype
(N
, Rtype
);
5562 -- Check that a procedure call does not occur in the context of the
5563 -- entry call statement of a conditional or timed entry call. Note that
5564 -- the case of a call to a subprogram renaming of an entry will also be
5565 -- rejected. The test for N not being an N_Entry_Call_Statement is
5566 -- defensive, covering the possibility that the processing of entry
5567 -- calls might reach this point due to later modifications of the code
5570 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
5571 and then Nkind
(N
) /= N_Entry_Call_Statement
5572 and then Entry_Call_Statement
(Parent
(N
)) = N
5574 if Ada_Version
< Ada_2005
then
5575 Error_Msg_N
("entry call required in select statement", N
);
5577 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5578 -- for a procedure_or_entry_call, the procedure_name or
5579 -- procedure_prefix of the procedure_call_statement shall denote
5580 -- an entry renamed by a procedure, or (a view of) a primitive
5581 -- subprogram of a limited interface whose first parameter is
5582 -- a controlling parameter.
5584 elsif Nkind
(N
) = N_Procedure_Call_Statement
5585 and then not Is_Renamed_Entry
(Nam
)
5586 and then not Is_Controlling_Limited_Procedure
(Nam
)
5589 ("entry call or dispatching primitive of interface required", N
);
5593 -- If the SPARK_05 restriction is active, we are not allowed
5594 -- to have a call to a subprogram before we see its completion.
5596 if not Has_Completion
(Nam
)
5597 and then Restriction_Check_Required
(SPARK_05
)
5599 -- Don't flag strange internal calls
5601 and then Comes_From_Source
(N
)
5602 and then Comes_From_Source
(Nam
)
5604 -- Only flag calls in extended main source
5606 and then In_Extended_Main_Source_Unit
(Nam
)
5607 and then In_Extended_Main_Source_Unit
(N
)
5609 -- Exclude enumeration literals from this processing
5611 and then Ekind
(Nam
) /= E_Enumeration_Literal
5613 Check_SPARK_Restriction
5614 ("call to subprogram cannot appear before its body", N
);
5617 -- Check that this is not a call to a protected procedure or entry from
5618 -- within a protected function.
5620 Check_Internal_Protected_Use
(N
, Nam
);
5622 -- Freeze the subprogram name if not in a spec-expression. Note that
5623 -- we freeze procedure calls as well as function calls. Procedure calls
5624 -- are not frozen according to the rules (RM 13.14(14)) because it is
5625 -- impossible to have a procedure call to a non-frozen procedure in
5626 -- pure Ada, but in the code that we generate in the expander, this
5627 -- rule needs extending because we can generate procedure calls that
5630 -- In Ada 2012, expression functions may be called within pre/post
5631 -- conditions of subsequent functions or expression functions. Such
5632 -- calls do not freeze when they appear within generated bodies,
5633 -- (including the body of another expression function) which would
5634 -- place the freeze node in the wrong scope. An expression function
5635 -- is frozen in the usual fashion, by the appearance of a real body,
5636 -- or at the end of a declarative part.
5638 if Is_Entity_Name
(Subp
) and then not In_Spec_Expression
5639 and then not Is_Expression_Function
(Current_Scope
)
5641 (not Is_Expression_Function
(Entity
(Subp
))
5642 or else Scope
(Entity
(Subp
)) = Current_Scope
)
5644 Freeze_Expression
(Subp
);
5647 -- For a predefined operator, the type of the result is the type imposed
5648 -- by context, except for a predefined operation on universal fixed.
5649 -- Otherwise The type of the call is the type returned by the subprogram
5652 if Is_Predefined_Op
(Nam
) then
5653 if Etype
(N
) /= Universal_Fixed
then
5657 -- If the subprogram returns an array type, and the context requires the
5658 -- component type of that array type, the node is really an indexing of
5659 -- the parameterless call. Resolve as such. A pathological case occurs
5660 -- when the type of the component is an access to the array type. In
5661 -- this case the call is truly ambiguous.
5663 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
5665 ((Is_Array_Type
(Etype
(Nam
))
5666 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
5668 (Is_Access_Type
(Etype
(Nam
))
5669 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
5671 Covers
(Typ
, Component_Type
(Designated_Type
(Etype
(Nam
))))))
5674 Index_Node
: Node_Id
;
5676 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
5679 if Is_Access_Type
(Ret_Type
)
5680 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
5683 ("cannot disambiguate function call and indexing", N
);
5685 New_Subp
:= Relocate_Node
(Subp
);
5687 -- The called entity may be an explicit dereference, in which
5688 -- case there is no entity to set.
5690 if Nkind
(New_Subp
) /= N_Explicit_Dereference
then
5691 Set_Entity
(Subp
, Nam
);
5694 if (Is_Array_Type
(Ret_Type
)
5695 and then Component_Type
(Ret_Type
) /= Any_Type
)
5697 (Is_Access_Type
(Ret_Type
)
5699 Component_Type
(Designated_Type
(Ret_Type
)) /= Any_Type
)
5701 if Needs_No_Actuals
(Nam
) then
5703 -- Indexed call to a parameterless function
5706 Make_Indexed_Component
(Loc
,
5708 Make_Function_Call
(Loc
, Name
=> New_Subp
),
5709 Expressions
=> Parameter_Associations
(N
));
5711 -- An Ada 2005 prefixed call to a primitive operation
5712 -- whose first parameter is the prefix. This prefix was
5713 -- prepended to the parameter list, which is actually a
5714 -- list of indexes. Remove the prefix in order to build
5715 -- the proper indexed component.
5718 Make_Indexed_Component
(Loc
,
5720 Make_Function_Call
(Loc
,
5722 Parameter_Associations
=>
5724 (Remove_Head
(Parameter_Associations
(N
)))),
5725 Expressions
=> Parameter_Associations
(N
));
5728 -- Preserve the parenthesis count of the node
5730 Set_Paren_Count
(Index_Node
, Paren_Count
(N
));
5732 -- Since we are correcting a node classification error made
5733 -- by the parser, we call Replace rather than Rewrite.
5735 Replace
(N
, Index_Node
);
5737 Set_Etype
(Prefix
(N
), Ret_Type
);
5739 Resolve_Indexed_Component
(N
, Typ
);
5740 Check_Elab_Call
(Prefix
(N
));
5748 Set_Etype
(N
, Etype
(Nam
));
5751 -- In the case where the call is to an overloaded subprogram, Analyze
5752 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5753 -- such a case Normalize_Actuals needs to be called once more to order
5754 -- the actuals correctly. Otherwise the call will have the ordering
5755 -- given by the last overloaded subprogram whether this is the correct
5756 -- one being called or not.
5758 if Is_Overloaded
(Subp
) then
5759 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
5760 pragma Assert
(Norm_OK
);
5763 -- In any case, call is fully resolved now. Reset Overload flag, to
5764 -- prevent subsequent overload resolution if node is analyzed again
5766 Set_Is_Overloaded
(Subp
, False);
5767 Set_Is_Overloaded
(N
, False);
5769 -- If we are calling the current subprogram from immediately within its
5770 -- body, then that is the case where we can sometimes detect cases of
5771 -- infinite recursion statically. Do not try this in case restriction
5772 -- No_Recursion is in effect anyway, and do it only for source calls.
5774 if Comes_From_Source
(N
) then
5775 Scop
:= Current_Scope
;
5777 -- Check violation of SPARK_05 restriction which does not permit
5778 -- a subprogram body to contain a call to the subprogram directly.
5780 if Restriction_Check_Required
(SPARK_05
)
5781 and then Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5783 Check_SPARK_Restriction
5784 ("subprogram may not contain direct call to itself", N
);
5787 -- Issue warning for possible infinite recursion in the absence
5788 -- of the No_Recursion restriction.
5790 if Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5791 and then not Restriction_Active
(No_Recursion
)
5792 and then Check_Infinite_Recursion
(N
)
5794 -- Here we detected and flagged an infinite recursion, so we do
5795 -- not need to test the case below for further warnings. Also we
5796 -- are all done if we now have a raise SE node.
5798 if Nkind
(N
) = N_Raise_Storage_Error
then
5802 -- If call is to immediately containing subprogram, then check for
5803 -- the case of a possible run-time detectable infinite recursion.
5806 Scope_Loop
: while Scop
/= Standard_Standard
loop
5807 if Same_Or_Aliased_Subprograms
(Nam
, Scop
) then
5809 -- Although in general case, recursion is not statically
5810 -- checkable, the case of calling an immediately containing
5811 -- subprogram is easy to catch.
5813 Check_Restriction
(No_Recursion
, N
);
5815 -- If the recursive call is to a parameterless subprogram,
5816 -- then even if we can't statically detect infinite
5817 -- recursion, this is pretty suspicious, and we output a
5818 -- warning. Furthermore, we will try later to detect some
5819 -- cases here at run time by expanding checking code (see
5820 -- Detect_Infinite_Recursion in package Exp_Ch6).
5822 -- If the recursive call is within a handler, do not emit a
5823 -- warning, because this is a common idiom: loop until input
5824 -- is correct, catch illegal input in handler and restart.
5826 if No
(First_Formal
(Nam
))
5827 and then Etype
(Nam
) = Standard_Void_Type
5828 and then not Error_Posted
(N
)
5829 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
5831 -- For the case of a procedure call. We give the message
5832 -- only if the call is the first statement in a sequence
5833 -- of statements, or if all previous statements are
5834 -- simple assignments. This is simply a heuristic to
5835 -- decrease false positives, without losing too many good
5836 -- warnings. The idea is that these previous statements
5837 -- may affect global variables the procedure depends on.
5838 -- We also exclude raise statements, that may arise from
5839 -- constraint checks and are probably unrelated to the
5840 -- intended control flow.
5842 if Nkind
(N
) = N_Procedure_Call_Statement
5843 and then Is_List_Member
(N
)
5849 while Present
(P
) loop
5850 if not Nkind_In
(P
, N_Assignment_Statement
,
5851 N_Raise_Constraint_Error
)
5861 -- Do not give warning if we are in a conditional context
5864 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
5866 if (K
= N_Loop_Statement
5867 and then Present
(Iteration_Scheme
(Parent
(N
))))
5868 or else K
= N_If_Statement
5869 or else K
= N_Elsif_Part
5870 or else K
= N_Case_Statement_Alternative
5876 -- Here warning is to be issued
5878 Set_Has_Recursive_Call
(Nam
);
5879 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5880 Error_Msg_N
("possible infinite recursion<<!", N
);
5881 Error_Msg_N
("\Storage_Error ]<<!", N
);
5887 Scop
:= Scope
(Scop
);
5888 end loop Scope_Loop
;
5892 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5894 Check_Obsolescent_2005_Entity
(Nam
, Subp
);
5896 -- If subprogram name is a predefined operator, it was given in
5897 -- functional notation. Replace call node with operator node, so
5898 -- that actuals can be resolved appropriately.
5900 if Is_Predefined_Op
(Nam
) or else Ekind
(Nam
) = E_Operator
then
5901 Make_Call_Into_Operator
(N
, Typ
, Entity
(Name
(N
)));
5904 elsif Present
(Alias
(Nam
))
5905 and then Is_Predefined_Op
(Alias
(Nam
))
5907 Resolve_Actuals
(N
, Nam
);
5908 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
5912 -- Create a transient scope if the resulting type requires it
5914 -- There are several notable exceptions:
5916 -- a) In init procs, the transient scope overhead is not needed, and is
5917 -- even incorrect when the call is a nested initialization call for a
5918 -- component whose expansion may generate adjust calls. However, if the
5919 -- call is some other procedure call within an initialization procedure
5920 -- (for example a call to Create_Task in the init_proc of the task
5921 -- run-time record) a transient scope must be created around this call.
5923 -- b) Enumeration literal pseudo-calls need no transient scope
5925 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5926 -- functions) do not use the secondary stack even though the return
5927 -- type may be unconstrained.
5929 -- d) Calls to a build-in-place function, since such functions may
5930 -- allocate their result directly in a target object, and cases where
5931 -- the result does get allocated in the secondary stack are checked for
5932 -- within the specialized Exp_Ch6 procedures for expanding those
5933 -- build-in-place calls.
5935 -- e) If the subprogram is marked Inline_Always, then even if it returns
5936 -- an unconstrained type the call does not require use of the secondary
5937 -- stack. However, inlining will only take place if the body to inline
5938 -- is already present. It may not be available if e.g. the subprogram is
5939 -- declared in a child instance.
5941 -- If this is an initialization call for a type whose construction
5942 -- uses the secondary stack, and it is not a nested call to initialize
5943 -- a component, we do need to create a transient scope for it. We
5944 -- check for this by traversing the type in Check_Initialization_Call.
5947 and then Has_Pragma_Inline
(Nam
)
5948 and then Nkind
(Unit_Declaration_Node
(Nam
)) = N_Subprogram_Declaration
5949 and then Present
(Body_To_Inline
(Unit_Declaration_Node
(Nam
)))
5953 elsif Ekind
(Nam
) = E_Enumeration_Literal
5954 or else Is_Build_In_Place_Function
(Nam
)
5955 or else Is_Intrinsic_Subprogram
(Nam
)
5959 elsif Expander_Active
5960 and then Is_Type
(Etype
(Nam
))
5961 and then Requires_Transient_Scope
(Etype
(Nam
))
5963 (not Within_Init_Proc
5965 (not Is_Init_Proc
(Nam
) and then Ekind
(Nam
) /= E_Function
))
5967 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
5969 -- If the call appears within the bounds of a loop, it will
5970 -- be rewritten and reanalyzed, nothing left to do here.
5972 if Nkind
(N
) /= N_Function_Call
then
5976 elsif Is_Init_Proc
(Nam
)
5977 and then not Within_Init_Proc
5979 Check_Initialization_Call
(N
, Nam
);
5982 -- A protected function cannot be called within the definition of the
5983 -- enclosing protected type.
5985 if Is_Protected_Type
(Scope
(Nam
))
5986 and then In_Open_Scopes
(Scope
(Nam
))
5987 and then not Has_Completion
(Scope
(Nam
))
5990 ("& cannot be called before end of protected definition", N
, Nam
);
5993 -- Propagate interpretation to actuals, and add default expressions
5996 if Present
(First_Formal
(Nam
)) then
5997 Resolve_Actuals
(N
, Nam
);
5999 -- Overloaded literals are rewritten as function calls, for purpose of
6000 -- resolution. After resolution, we can replace the call with the
6003 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
6004 Copy_Node
(Subp
, N
);
6005 Resolve_Entity_Name
(N
, Typ
);
6007 -- Avoid validation, since it is a static function call
6009 Generate_Reference
(Nam
, Subp
);
6013 -- If the subprogram is not global, then kill all saved values and
6014 -- checks. This is a bit conservative, since in many cases we could do
6015 -- better, but it is not worth the effort. Similarly, we kill constant
6016 -- values. However we do not need to do this for internal entities
6017 -- (unless they are inherited user-defined subprograms), since they
6018 -- are not in the business of molesting local values.
6020 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
6021 -- kill all checks and values for calls to global subprograms. This
6022 -- takes care of the case where an access to a local subprogram is
6023 -- taken, and could be passed directly or indirectly and then called
6024 -- from almost any context.
6026 -- Note: we do not do this step till after resolving the actuals. That
6027 -- way we still take advantage of the current value information while
6028 -- scanning the actuals.
6030 -- We suppress killing values if we are processing the nodes associated
6031 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
6032 -- type kills all the values as part of analyzing the code that
6033 -- initializes the dispatch tables.
6035 if Inside_Freezing_Actions
= 0
6036 and then (not Is_Library_Level_Entity
(Nam
)
6037 or else Suppress_Value_Tracking_On_Call
6038 (Nearest_Dynamic_Scope
(Current_Scope
)))
6039 and then (Comes_From_Source
(Nam
)
6040 or else (Present
(Alias
(Nam
))
6041 and then Comes_From_Source
(Alias
(Nam
))))
6043 Kill_Current_Values
;
6046 -- If we are warning about unread OUT parameters, this is the place to
6047 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
6048 -- after the above call to Kill_Current_Values (since that call clears
6049 -- the Last_Assignment field of all local variables).
6051 if (Warn_On_Modified_Unread
or Warn_On_All_Unread_Out_Parameters
)
6052 and then Comes_From_Source
(N
)
6053 and then In_Extended_Main_Source_Unit
(N
)
6060 F
:= First_Formal
(Nam
);
6061 A
:= First_Actual
(N
);
6062 while Present
(F
) and then Present
(A
) loop
6063 if Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
)
6064 and then Warn_On_Modified_As_Out_Parameter
(F
)
6065 and then Is_Entity_Name
(A
)
6066 and then Present
(Entity
(A
))
6067 and then Comes_From_Source
(N
)
6068 and then Safe_To_Capture_Value
(N
, Entity
(A
))
6070 Set_Last_Assignment
(Entity
(A
), A
);
6079 -- If the subprogram is a primitive operation, check whether or not
6080 -- it is a correct dispatching call.
6082 if Is_Overloadable
(Nam
)
6083 and then Is_Dispatching_Operation
(Nam
)
6085 Check_Dispatching_Call
(N
);
6087 elsif Ekind
(Nam
) /= E_Subprogram_Type
6088 and then Is_Abstract_Subprogram
(Nam
)
6089 and then not In_Instance
6091 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Nam
);
6094 -- If this is a dispatching call, generate the appropriate reference,
6095 -- for better source navigation in GPS.
6097 if Is_Overloadable
(Nam
)
6098 and then Present
(Controlling_Argument
(N
))
6100 Generate_Reference
(Nam
, Subp
, 'R');
6102 -- Normal case, not a dispatching call: generate a call reference
6105 Generate_Reference
(Nam
, Subp
, 's');
6108 if Is_Intrinsic_Subprogram
(Nam
) then
6109 Check_Intrinsic_Call
(N
);
6112 -- Check for violation of restriction No_Specific_Termination_Handlers
6113 -- and warn on a potentially blocking call to Abort_Task.
6115 if Restriction_Check_Required
(No_Specific_Termination_Handlers
)
6116 and then (Is_RTE
(Nam
, RE_Set_Specific_Handler
)
6118 Is_RTE
(Nam
, RE_Specific_Handler
))
6120 Check_Restriction
(No_Specific_Termination_Handlers
, N
);
6122 elsif Is_RTE
(Nam
, RE_Abort_Task
) then
6123 Check_Potentially_Blocking_Operation
(N
);
6126 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
6127 -- timing event violates restriction No_Relative_Delay (AI-0211). We
6128 -- need to check the second argument to determine whether it is an
6129 -- absolute or relative timing event.
6131 if Restriction_Check_Required
(No_Relative_Delay
)
6132 and then Is_RTE
(Nam
, RE_Set_Handler
)
6133 and then Is_RTE
(Etype
(Next_Actual
(First_Actual
(N
))), RE_Time_Span
)
6135 Check_Restriction
(No_Relative_Delay
, N
);
6138 -- Issue an error for a call to an eliminated subprogram. This routine
6139 -- will not perform the check if the call appears within a default
6142 Check_For_Eliminated_Subprogram
(Subp
, Nam
);
6144 -- In formal mode, the primitive operations of a tagged type or type
6145 -- extension do not include functions that return the tagged type.
6147 if Nkind
(N
) = N_Function_Call
6148 and then Is_Tagged_Type
(Etype
(N
))
6149 and then Is_Entity_Name
(Name
(N
))
6150 and then Is_Inherited_Operation_For_Type
(Entity
(Name
(N
)), Etype
(N
))
6152 Check_SPARK_Restriction
("function not inherited", N
);
6155 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
6156 -- class-wide and the call dispatches on result in a context that does
6157 -- not provide a tag, the call raises Program_Error.
6159 if Nkind
(N
) = N_Function_Call
6160 and then In_Instance
6161 and then Is_Generic_Actual_Type
(Typ
)
6162 and then Is_Class_Wide_Type
(Typ
)
6163 and then Has_Controlling_Result
(Nam
)
6164 and then Nkind
(Parent
(N
)) = N_Object_Declaration
6166 -- Verify that none of the formals are controlling
6169 Call_OK
: Boolean := False;
6173 F
:= First_Formal
(Nam
);
6174 while Present
(F
) loop
6175 if Is_Controlling_Formal
(F
) then
6184 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6185 Error_Msg_N
("!cannot determine tag of result<<", N
);
6186 Error_Msg_N
("\Program_Error [<<!", N
);
6188 Make_Raise_Program_Error
(Sloc
(N
),
6189 Reason
=> PE_Explicit_Raise
));
6194 -- Check for calling a function with OUT or IN OUT parameter when the
6195 -- calling context (us right now) is not Ada 2012, so does not allow
6196 -- OUT or IN OUT parameters in function calls.
6198 if Ada_Version
< Ada_2012
6199 and then Ekind
(Nam
) = E_Function
6200 and then Has_Out_Or_In_Out_Parameter
(Nam
)
6202 Error_Msg_NE
("& has at least one OUT or `IN OUT` parameter", N
, Nam
);
6203 Error_Msg_N
("\call to this function only allowed in Ada 2012", N
);
6206 -- Check the dimensions of the actuals in the call. For function calls,
6207 -- propagate the dimensions from the returned type to N.
6209 Analyze_Dimension_Call
(N
, Nam
);
6211 -- All done, evaluate call and deal with elaboration issues
6214 Check_Elab_Call
(N
);
6216 -- In GNATprove mode, expansion is disabled, but we want to inline some
6217 -- subprograms to facilitate formal verification. Indirect calls through
6218 -- a subprogram type or within a generic cannot be inlined. Inlining is
6219 -- performed only for calls subject to SPARK_Mode on.
6222 and then SPARK_Mode
= On
6223 and then Is_Overloadable
(Nam
)
6224 and then not Inside_A_Generic
6226 Nam_UA
:= Ultimate_Alias
(Nam
);
6227 Nam_Decl
:= Unit_Declaration_Node
(Nam_UA
);
6229 if Nkind
(Nam_Decl
) = N_Subprogram_Declaration
then
6230 Body_Id
:= Corresponding_Body
(Nam_Decl
);
6232 -- Nothing to do if the subprogram is not eligible for inlining in
6235 if not Is_Inlined_Always
(Nam_UA
)
6236 or else not Can_Be_Inlined_In_GNATprove_Mode
(Nam_UA
, Body_Id
)
6240 -- Calls cannot be inlined inside assertions, as GNATprove treats
6241 -- assertions as logic expressions.
6243 elsif In_Assertion_Expr
/= 0 then
6244 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6245 Error_Msg_N
("\call appears in assertion expression", N
);
6246 Set_Is_Inlined_Always
(Nam_UA
, False);
6248 -- Calls cannot be inlined inside default expressions
6250 elsif In_Default_Expr
then
6251 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6252 Error_Msg_N
("\call appears in default expression", N
);
6253 Set_Is_Inlined_Always
(Nam_UA
, False);
6255 -- Inlining should not be performed during pre-analysis
6257 elsif Full_Analysis
then
6259 -- With the one-pass inlining technique, a call cannot be
6260 -- inlined if the corresponding body has not been seen yet.
6262 if No
(Body_Id
) then
6264 ("?no contextual analysis of & (body not seen yet)",
6266 Set_Is_Inlined_Always
(Nam_UA
, False);
6268 -- Nothing to do if there is no body to inline, indicating that
6269 -- the subprogram is not suitable for inlining in GNATprove
6272 elsif No
(Body_To_Inline
(Nam_Decl
)) then
6275 -- Calls cannot be inlined inside potentially unevaluated
6276 -- expressions, as this would create complex actions inside
6277 -- expressions, that are not handled by GNATprove.
6279 elsif Is_Potentially_Unevaluated
(N
) then
6280 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6282 ("\call appears in potentially unevaluated context", N
);
6283 Set_Is_Inlined_Always
(Nam_UA
, False);
6285 -- Otherwise, inline the call
6288 Expand_Inlined_Call
(N
, Nam_UA
, Nam
);
6294 Warn_On_Overlapping_Actuals
(Nam
, N
);
6297 -----------------------------
6298 -- Resolve_Case_Expression --
6299 -----------------------------
6301 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
6305 Alt
:= First
(Alternatives
(N
));
6306 while Present
(Alt
) loop
6307 Resolve
(Expression
(Alt
), Typ
);
6312 Eval_Case_Expression
(N
);
6313 end Resolve_Case_Expression
;
6315 -------------------------------
6316 -- Resolve_Character_Literal --
6317 -------------------------------
6319 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
6320 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
6324 -- Verify that the character does belong to the type of the context
6326 Set_Etype
(N
, B_Typ
);
6327 Eval_Character_Literal
(N
);
6329 -- Wide_Wide_Character literals must always be defined, since the set
6330 -- of wide wide character literals is complete, i.e. if a character
6331 -- literal is accepted by the parser, then it is OK for wide wide
6332 -- character (out of range character literals are rejected).
6334 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
6337 -- Always accept character literal for type Any_Character, which
6338 -- occurs in error situations and in comparisons of literals, both
6339 -- of which should accept all literals.
6341 elsif B_Typ
= Any_Character
then
6344 -- For Standard.Character or a type derived from it, check that the
6345 -- literal is in range.
6347 elsif Root_Type
(B_Typ
) = Standard_Character
then
6348 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
6352 -- For Standard.Wide_Character or a type derived from it, check that the
6353 -- literal is in range.
6355 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
6356 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
6360 -- For Standard.Wide_Wide_Character or a type derived from it, we
6361 -- know the literal is in range, since the parser checked.
6363 elsif Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
6366 -- If the entity is already set, this has already been resolved in a
6367 -- generic context, or comes from expansion. Nothing else to do.
6369 elsif Present
(Entity
(N
)) then
6372 -- Otherwise we have a user defined character type, and we can use the
6373 -- standard visibility mechanisms to locate the referenced entity.
6376 C
:= Current_Entity
(N
);
6377 while Present
(C
) loop
6378 if Etype
(C
) = B_Typ
then
6379 Set_Entity_With_Checks
(N
, C
);
6380 Generate_Reference
(C
, N
);
6388 -- If we fall through, then the literal does not match any of the
6389 -- entries of the enumeration type. This isn't just a constraint error
6390 -- situation, it is an illegality (see RM 4.2).
6393 ("character not defined for }", N
, First_Subtype
(B_Typ
));
6394 end Resolve_Character_Literal
;
6396 ---------------------------
6397 -- Resolve_Comparison_Op --
6398 ---------------------------
6400 -- Context requires a boolean type, and plays no role in resolution.
6401 -- Processing identical to that for equality operators. The result type is
6402 -- the base type, which matters when pathological subtypes of booleans with
6403 -- limited ranges are used.
6405 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6406 L
: constant Node_Id
:= Left_Opnd
(N
);
6407 R
: constant Node_Id
:= Right_Opnd
(N
);
6411 -- If this is an intrinsic operation which is not predefined, use the
6412 -- types of its declared arguments to resolve the possibly overloaded
6413 -- operands. Otherwise the operands are unambiguous and specify the
6416 if Scope
(Entity
(N
)) /= Standard_Standard
then
6417 T
:= Etype
(First_Entity
(Entity
(N
)));
6420 T
:= Find_Unique_Type
(L
, R
);
6422 if T
= Any_Fixed
then
6423 T
:= Unique_Fixed_Point_Type
(L
);
6427 Set_Etype
(N
, Base_Type
(Typ
));
6428 Generate_Reference
(T
, N
, ' ');
6430 -- Skip remaining processing if already set to Any_Type
6432 if T
= Any_Type
then
6436 -- Deal with other error cases
6438 if T
= Any_String
or else
6439 T
= Any_Composite
or else
6442 if T
= Any_Character
then
6443 Ambiguous_Character
(L
);
6445 Error_Msg_N
("ambiguous operands for comparison", N
);
6448 Set_Etype
(N
, Any_Type
);
6452 -- Resolve the operands if types OK
6456 Check_Unset_Reference
(L
);
6457 Check_Unset_Reference
(R
);
6458 Generate_Operator_Reference
(N
, T
);
6459 Check_Low_Bound_Tested
(N
);
6461 -- In SPARK, ordering operators <, <=, >, >= are not defined for Boolean
6462 -- types or array types except String.
6464 if Is_Boolean_Type
(T
) then
6465 Check_SPARK_Restriction
6466 ("comparison is not defined on Boolean type", N
);
6468 elsif Is_Array_Type
(T
)
6469 and then Base_Type
(T
) /= Standard_String
6471 Check_SPARK_Restriction
6472 ("comparison is not defined on array types other than String", N
);
6475 -- Check comparison on unordered enumeration
6477 if Bad_Unordered_Enumeration_Reference
(N
, Etype
(L
)) then
6478 Error_Msg_Sloc
:= Sloc
(Etype
(L
));
6480 ("comparison on unordered enumeration type& declared#?U?",
6484 -- Evaluate the relation (note we do this after the above check since
6485 -- this Eval call may change N to True/False.
6487 Analyze_Dimension
(N
);
6488 Eval_Relational_Op
(N
);
6489 end Resolve_Comparison_Op
;
6491 -----------------------------------------
6492 -- Resolve_Discrete_Subtype_Indication --
6493 -----------------------------------------
6495 procedure Resolve_Discrete_Subtype_Indication
6503 Analyze
(Subtype_Mark
(N
));
6504 S
:= Entity
(Subtype_Mark
(N
));
6506 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
6507 Error_Msg_N
("expect range constraint for discrete type", N
);
6508 Set_Etype
(N
, Any_Type
);
6511 R
:= Range_Expression
(Constraint
(N
));
6519 if Base_Type
(S
) /= Base_Type
(Typ
) then
6521 ("expect subtype of }", N
, First_Subtype
(Typ
));
6523 -- Rewrite the constraint as a range of Typ
6524 -- to allow compilation to proceed further.
6527 Rewrite
(Low_Bound
(R
),
6528 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
6529 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
6530 Attribute_Name
=> Name_First
));
6531 Rewrite
(High_Bound
(R
),
6532 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
6533 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
6534 Attribute_Name
=> Name_First
));
6538 Set_Etype
(N
, Etype
(R
));
6540 -- Additionally, we must check that the bounds are compatible
6541 -- with the given subtype, which might be different from the
6542 -- type of the context.
6544 Apply_Range_Check
(R
, S
);
6546 -- ??? If the above check statically detects a Constraint_Error
6547 -- it replaces the offending bound(s) of the range R with a
6548 -- Constraint_Error node. When the itype which uses these bounds
6549 -- is frozen the resulting call to Duplicate_Subexpr generates
6550 -- a new temporary for the bounds.
6552 -- Unfortunately there are other itypes that are also made depend
6553 -- on these bounds, so when Duplicate_Subexpr is called they get
6554 -- a forward reference to the newly created temporaries and Gigi
6555 -- aborts on such forward references. This is probably sign of a
6556 -- more fundamental problem somewhere else in either the order of
6557 -- itype freezing or the way certain itypes are constructed.
6559 -- To get around this problem we call Remove_Side_Effects right
6560 -- away if either bounds of R are a Constraint_Error.
6563 L
: constant Node_Id
:= Low_Bound
(R
);
6564 H
: constant Node_Id
:= High_Bound
(R
);
6567 if Nkind
(L
) = N_Raise_Constraint_Error
then
6568 Remove_Side_Effects
(L
);
6571 if Nkind
(H
) = N_Raise_Constraint_Error
then
6572 Remove_Side_Effects
(H
);
6576 Check_Unset_Reference
(Low_Bound
(R
));
6577 Check_Unset_Reference
(High_Bound
(R
));
6580 end Resolve_Discrete_Subtype_Indication
;
6582 -------------------------
6583 -- Resolve_Entity_Name --
6584 -------------------------
6586 -- Used to resolve identifiers and expanded names
6588 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
6589 function Appears_In_Check
(Nod
: Node_Id
) return Boolean;
6590 -- Denote whether an arbitrary node Nod appears in a check node
6592 function Is_OK_Volatile_Context
6594 Obj_Ref
: Node_Id
) return Boolean;
6595 -- Determine whether node Context denotes a "non-interfering context"
6596 -- (as defined in SPARK RM 7.1.3(13)) where volatile reference Obj_Ref
6597 -- can safely reside.
6599 ----------------------
6600 -- Appears_In_Check --
6601 ----------------------
6603 function Appears_In_Check
(Nod
: Node_Id
) return Boolean is
6607 -- Climb the parent chain looking for a check node
6610 while Present
(Par
) loop
6611 if Nkind
(Par
) in N_Raise_xxx_Error
then
6614 -- Prevent the search from going too far
6616 elsif Is_Body_Or_Package_Declaration
(Par
) then
6620 Par
:= Parent
(Par
);
6624 end Appears_In_Check
;
6626 ----------------------------
6627 -- Is_OK_Volatile_Context --
6628 ----------------------------
6630 function Is_OK_Volatile_Context
6632 Obj_Ref
: Node_Id
) return Boolean
6635 -- The volatile object appears on either side of an assignment
6637 if Nkind
(Context
) = N_Assignment_Statement
then
6640 -- The volatile object is part of the initialization expression of
6641 -- another object. Ensure that the climb of the parent chain came
6642 -- from the expression side and not from the name side.
6644 elsif Nkind
(Context
) = N_Object_Declaration
6645 and then Present
(Expression
(Context
))
6646 and then Expression
(Context
) = Obj_Ref
6650 -- The volatile object appears as an actual parameter in a call to an
6651 -- instance of Unchecked_Conversion whose result is renamed.
6653 elsif Nkind
(Context
) = N_Function_Call
6654 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
6655 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
6659 -- The volatile object appears as the prefix of a name occurring
6660 -- in a non-interfering context.
6662 elsif Nkind_In
(Context
, N_Attribute_Reference
,
6663 N_Indexed_Component
,
6664 N_Selected_Component
,
6666 and then Prefix
(Context
) = Obj_Ref
6667 and then Is_OK_Volatile_Context
6668 (Context
=> Parent
(Context
),
6673 -- Allow references to volatile objects in various checks. This is
6674 -- not a direct SPARK 2014 requirement.
6676 elsif Appears_In_Check
(Context
) then
6682 end Is_OK_Volatile_Context
;
6686 E
: constant Entity_Id
:= Entity
(N
);
6687 Par
: constant Node_Id
:= Parent
(N
);
6689 -- Start of processing for Resolve_Entity_Name
6692 -- If garbage from errors, set to Any_Type and return
6694 if No
(E
) and then Total_Errors_Detected
/= 0 then
6695 Set_Etype
(N
, Any_Type
);
6699 -- Replace named numbers by corresponding literals. Note that this is
6700 -- the one case where Resolve_Entity_Name must reset the Etype, since
6701 -- it is currently marked as universal.
6703 if Ekind
(E
) = E_Named_Integer
then
6705 Eval_Named_Integer
(N
);
6707 elsif Ekind
(E
) = E_Named_Real
then
6709 Eval_Named_Real
(N
);
6711 -- For enumeration literals, we need to make sure that a proper style
6712 -- check is done, since such literals are overloaded, and thus we did
6713 -- not do a style check during the first phase of analysis.
6715 elsif Ekind
(E
) = E_Enumeration_Literal
then
6716 Set_Entity_With_Checks
(N
, E
);
6717 Eval_Entity_Name
(N
);
6719 -- Case of subtype name appearing as an operand in expression
6721 elsif Is_Type
(E
) then
6723 -- Allow use of subtype if it is a concurrent type where we are
6724 -- currently inside the body. This will eventually be expanded into a
6725 -- call to Self (for tasks) or _object (for protected objects). Any
6726 -- other use of a subtype is invalid.
6728 if Is_Concurrent_Type
(E
)
6729 and then In_Open_Scopes
(E
)
6733 -- Any other use is an error
6737 ("invalid use of subtype mark in expression or call", N
);
6740 -- Check discriminant use if entity is discriminant in current scope,
6741 -- i.e. discriminant of record or concurrent type currently being
6742 -- analyzed. Uses in corresponding body are unrestricted.
6744 elsif Ekind
(E
) = E_Discriminant
6745 and then Scope
(E
) = Current_Scope
6746 and then not Has_Completion
(Current_Scope
)
6748 Check_Discriminant_Use
(N
);
6750 -- A parameterless generic function cannot appear in a context that
6751 -- requires resolution.
6753 elsif Ekind
(E
) = E_Generic_Function
then
6754 Error_Msg_N
("illegal use of generic function", N
);
6756 elsif Ekind
(E
) = E_Out_Parameter
6757 and then Ada_Version
= Ada_83
6758 and then (Nkind
(Parent
(N
)) in N_Op
6759 or else (Nkind
(Parent
(N
)) = N_Assignment_Statement
6760 and then N
= Expression
(Parent
(N
)))
6761 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
)
6763 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
6765 -- In all other cases, just do the possible static evaluation
6768 -- A deferred constant that appears in an expression must have a
6769 -- completion, unless it has been removed by in-place expansion of
6772 if Ekind
(E
) = E_Constant
6773 and then Comes_From_Source
(E
)
6774 and then No
(Constant_Value
(E
))
6775 and then Is_Frozen
(Etype
(E
))
6776 and then not In_Spec_Expression
6777 and then not Is_Imported
(E
)
6779 if No_Initialization
(Parent
(E
))
6780 or else (Present
(Full_View
(E
))
6781 and then No_Initialization
(Parent
(Full_View
(E
))))
6786 "deferred constant is frozen before completion", N
);
6790 Eval_Entity_Name
(N
);
6793 -- An effectively volatile object subject to enabled properties
6794 -- Async_Writers or Effective_Reads must appear in a specific context.
6795 -- The following checks are only relevant when SPARK_Mode is on as they
6796 -- are not standard Ada legality rules.
6799 and then Is_Object
(E
)
6800 and then Is_Effectively_Volatile
(E
)
6801 and then Comes_From_Source
(E
)
6803 (Async_Writers_Enabled
(E
) or else Effective_Reads_Enabled
(E
))
6805 -- The effectively volatile objects appears in a "non-interfering
6806 -- context" as defined in SPARK RM 7.1.3(13).
6808 if Is_OK_Volatile_Context
(Par
, N
) then
6811 -- Assume that references to effectively volatile objects that appear
6812 -- as actual parameters in a procedure call are always legal. The
6813 -- full legality check is done when the actuals are resolved.
6815 elsif Nkind
(Par
) = N_Procedure_Call_Statement
then
6818 -- Otherwise the context causes a side effect with respect to the
6819 -- effectively volatile object.
6823 ("volatile object cannot appear in this context "
6824 & "(SPARK RM 7.1.3(13))", N
);
6827 end Resolve_Entity_Name
;
6833 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
6834 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
6842 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
6843 -- If the bounds of the entry family being called depend on task
6844 -- discriminants, build a new index subtype where a discriminant is
6845 -- replaced with the value of the discriminant of the target task.
6846 -- The target task is the prefix of the entry name in the call.
6848 -----------------------
6849 -- Actual_Index_Type --
6850 -----------------------
6852 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
6853 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
6854 Tsk
: constant Entity_Id
:= Scope
(E
);
6855 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
6856 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
6859 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
6860 -- If the bound is given by a discriminant, replace with a reference
6861 -- to the discriminant of the same name in the target task. If the
6862 -- entry name is the target of a requeue statement and the entry is
6863 -- in the current protected object, the bound to be used is the
6864 -- discriminal of the object (see Apply_Range_Checks for details of
6865 -- the transformation).
6867 -----------------------------
6868 -- Actual_Discriminant_Ref --
6869 -----------------------------
6871 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
6872 Typ
: constant Entity_Id
:= Etype
(Bound
);
6876 Remove_Side_Effects
(Bound
);
6878 if not Is_Entity_Name
(Bound
)
6879 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
6883 elsif Is_Protected_Type
(Tsk
)
6884 and then In_Open_Scopes
(Tsk
)
6885 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
6887 -- Note: here Bound denotes a discriminant of the corresponding
6888 -- record type tskV, whose discriminal is a formal of the
6889 -- init-proc tskVIP. What we want is the body discriminal,
6890 -- which is associated to the discriminant of the original
6891 -- concurrent type tsk.
6893 return New_Occurrence_Of
6894 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
6898 Make_Selected_Component
(Loc
,
6899 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
6900 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
6905 end Actual_Discriminant_Ref
;
6907 -- Start of processing for Actual_Index_Type
6910 if not Has_Discriminants
(Tsk
)
6911 or else (not Is_Entity_Name
(Lo
) and then not Is_Entity_Name
(Hi
))
6913 return Entry_Index_Type
(E
);
6916 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
6917 Set_Etype
(New_T
, Base_Type
(Typ
));
6918 Set_Size_Info
(New_T
, Typ
);
6919 Set_RM_Size
(New_T
, RM_Size
(Typ
));
6920 Set_Scalar_Range
(New_T
,
6921 Make_Range
(Sloc
(Entry_Name
),
6922 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
6923 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
6927 end Actual_Index_Type
;
6929 -- Start of processing of Resolve_Entry
6932 -- Find name of entry being called, and resolve prefix of name with its
6933 -- own type. The prefix can be overloaded, and the name and signature of
6934 -- the entry must be taken into account.
6936 if Nkind
(Entry_Name
) = N_Indexed_Component
then
6938 -- Case of dealing with entry family within the current tasks
6940 E_Name
:= Prefix
(Entry_Name
);
6943 E_Name
:= Entry_Name
;
6946 if Is_Entity_Name
(E_Name
) then
6948 -- Entry call to an entry (or entry family) in the current task. This
6949 -- is legal even though the task will deadlock. Rewrite as call to
6952 -- This can also be a call to an entry in an enclosing task. If this
6953 -- is a single task, we have to retrieve its name, because the scope
6954 -- of the entry is the task type, not the object. If the enclosing
6955 -- task is a task type, the identity of the task is given by its own
6958 -- Finally this can be a requeue on an entry of the same task or
6959 -- protected object.
6961 S
:= Scope
(Entity
(E_Name
));
6963 for J
in reverse 0 .. Scope_Stack
.Last
loop
6964 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
6965 and then not Comes_From_Source
(S
)
6967 -- S is an enclosing task or protected object. The concurrent
6968 -- declaration has been converted into a type declaration, and
6969 -- the object itself has an object declaration that follows
6970 -- the type in the same declarative part.
6972 Tsk
:= Next_Entity
(S
);
6973 while Etype
(Tsk
) /= S
loop
6980 elsif S
= Scope_Stack
.Table
(J
).Entity
then
6982 -- Call to current task. Will be transformed into call to Self
6990 Make_Selected_Component
(Loc
,
6991 Prefix
=> New_Occurrence_Of
(S
, Loc
),
6993 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
6994 Rewrite
(E_Name
, New_N
);
6997 elsif Nkind
(Entry_Name
) = N_Selected_Component
6998 and then Is_Overloaded
(Prefix
(Entry_Name
))
7000 -- Use the entry name (which must be unique at this point) to find
7001 -- the prefix that returns the corresponding task/protected type.
7004 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
7005 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
7010 Get_First_Interp
(Pref
, I
, It
);
7011 while Present
(It
.Typ
) loop
7012 if Scope
(Ent
) = It
.Typ
then
7013 Set_Etype
(Pref
, It
.Typ
);
7017 Get_Next_Interp
(I
, It
);
7022 if Nkind
(Entry_Name
) = N_Selected_Component
then
7023 Resolve
(Prefix
(Entry_Name
));
7025 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7026 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7027 Resolve
(Prefix
(Prefix
(Entry_Name
)));
7028 Index
:= First
(Expressions
(Entry_Name
));
7029 Resolve
(Index
, Entry_Index_Type
(Nam
));
7031 -- Up to this point the expression could have been the actual in a
7032 -- simple entry call, and be given by a named association.
7034 if Nkind
(Index
) = N_Parameter_Association
then
7035 Error_Msg_N
("expect expression for entry index", Index
);
7037 Apply_Range_Check
(Index
, Actual_Index_Type
(Nam
));
7042 ------------------------
7043 -- Resolve_Entry_Call --
7044 ------------------------
7046 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
7047 Entry_Name
: constant Node_Id
:= Name
(N
);
7048 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
7050 First_Named
: Node_Id
;
7057 -- We kill all checks here, because it does not seem worth the effort to
7058 -- do anything better, an entry call is a big operation.
7062 -- Processing of the name is similar for entry calls and protected
7063 -- operation calls. Once the entity is determined, we can complete
7064 -- the resolution of the actuals.
7066 -- The selector may be overloaded, in the case of a protected object
7067 -- with overloaded functions. The type of the context is used for
7070 if Nkind
(Entry_Name
) = N_Selected_Component
7071 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
7072 and then Typ
/= Standard_Void_Type
7079 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
7080 while Present
(It
.Typ
) loop
7081 if Covers
(Typ
, It
.Typ
) then
7082 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
7083 Set_Etype
(Entry_Name
, It
.Typ
);
7085 Generate_Reference
(It
.Typ
, N
, ' ');
7088 Get_Next_Interp
(I
, It
);
7093 Resolve_Entry
(Entry_Name
);
7095 if Nkind
(Entry_Name
) = N_Selected_Component
then
7097 -- Simple entry call
7099 Nam
:= Entity
(Selector_Name
(Entry_Name
));
7100 Obj
:= Prefix
(Entry_Name
);
7101 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
7103 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7105 -- Call to member of entry family
7107 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7108 Obj
:= Prefix
(Prefix
(Entry_Name
));
7109 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
7112 -- We cannot in general check the maximum depth of protected entry calls
7113 -- at compile time. But we can tell that any protected entry call at all
7114 -- violates a specified nesting depth of zero.
7116 if Is_Protected_Type
(Scope
(Nam
)) then
7117 Check_Restriction
(Max_Entry_Queue_Length
, N
);
7120 -- Use context type to disambiguate a protected function that can be
7121 -- called without actuals and that returns an array type, and where the
7122 -- argument list may be an indexing of the returned value.
7124 if Ekind
(Nam
) = E_Function
7125 and then Needs_No_Actuals
(Nam
)
7126 and then Present
(Parameter_Associations
(N
))
7128 ((Is_Array_Type
(Etype
(Nam
))
7129 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
7131 or else (Is_Access_Type
(Etype
(Nam
))
7132 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
7136 Component_Type
(Designated_Type
(Etype
(Nam
))))))
7139 Index_Node
: Node_Id
;
7143 Make_Indexed_Component
(Loc
,
7145 Make_Function_Call
(Loc
, Name
=> Relocate_Node
(Entry_Name
)),
7146 Expressions
=> Parameter_Associations
(N
));
7148 -- Since we are correcting a node classification error made by the
7149 -- parser, we call Replace rather than Rewrite.
7151 Replace
(N
, Index_Node
);
7152 Set_Etype
(Prefix
(N
), Etype
(Nam
));
7154 Resolve_Indexed_Component
(N
, Typ
);
7159 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
)
7160 and then Present
(PPC_Wrapper
(Nam
))
7161 and then Current_Scope
/= PPC_Wrapper
(Nam
)
7163 -- Rewrite as call to the precondition wrapper, adding the task
7164 -- object to the list of actuals. If the call is to a member of an
7165 -- entry family, include the index as well.
7169 New_Actuals
: List_Id
;
7172 New_Actuals
:= New_List
(Obj
);
7174 if Nkind
(Entry_Name
) = N_Indexed_Component
then
7175 Append_To
(New_Actuals
,
7176 New_Copy_Tree
(First
(Expressions
(Entry_Name
))));
7179 Append_List
(Parameter_Associations
(N
), New_Actuals
);
7181 Make_Procedure_Call_Statement
(Loc
,
7183 New_Occurrence_Of
(PPC_Wrapper
(Nam
), Loc
),
7184 Parameter_Associations
=> New_Actuals
);
7185 Rewrite
(N
, New_Call
);
7187 -- Preanalyze and resolve new call. Current procedure is called
7188 -- from Resolve_Call, after which expansion will take place.
7190 Preanalyze_And_Resolve
(N
);
7195 -- The operation name may have been overloaded. Order the actuals
7196 -- according to the formals of the resolved entity, and set the return
7197 -- type to that of the operation.
7200 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
7201 pragma Assert
(Norm_OK
);
7202 Set_Etype
(N
, Etype
(Nam
));
7205 Resolve_Actuals
(N
, Nam
);
7206 Check_Internal_Protected_Use
(N
, Nam
);
7208 -- Create a call reference to the entry
7210 Generate_Reference
(Nam
, Entry_Name
, 's');
7212 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
) then
7213 Check_Potentially_Blocking_Operation
(N
);
7216 -- Verify that a procedure call cannot masquerade as an entry
7217 -- call where an entry call is expected.
7219 if Ekind
(Nam
) = E_Procedure
then
7220 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
7221 and then N
= Entry_Call_Statement
(Parent
(N
))
7223 Error_Msg_N
("entry call required in select statement", N
);
7225 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
7226 and then N
= Triggering_Statement
(Parent
(N
))
7228 Error_Msg_N
("triggering statement cannot be procedure call", N
);
7230 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
7231 and then not In_Open_Scopes
(Scope
(Nam
))
7233 Error_Msg_N
("task has no entry with this name", Entry_Name
);
7237 -- After resolution, entry calls and protected procedure calls are
7238 -- changed into entry calls, for expansion. The structure of the node
7239 -- does not change, so it can safely be done in place. Protected
7240 -- function calls must keep their structure because they are
7243 if Ekind
(Nam
) /= E_Function
then
7245 -- A protected operation that is not a function may modify the
7246 -- corresponding object, and cannot apply to a constant. If this
7247 -- is an internal call, the prefix is the type itself.
7249 if Is_Protected_Type
(Scope
(Nam
))
7250 and then not Is_Variable
(Obj
)
7251 and then (not Is_Entity_Name
(Obj
)
7252 or else not Is_Type
(Entity
(Obj
)))
7255 ("prefix of protected procedure or entry call must be variable",
7259 Actuals
:= Parameter_Associations
(N
);
7260 First_Named
:= First_Named_Actual
(N
);
7263 Make_Entry_Call_Statement
(Loc
,
7265 Parameter_Associations
=> Actuals
));
7267 Set_First_Named_Actual
(N
, First_Named
);
7268 Set_Analyzed
(N
, True);
7270 -- Protected functions can return on the secondary stack, in which
7271 -- case we must trigger the transient scope mechanism.
7273 elsif Expander_Active
7274 and then Requires_Transient_Scope
(Etype
(Nam
))
7276 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
7278 end Resolve_Entry_Call
;
7280 -------------------------
7281 -- Resolve_Equality_Op --
7282 -------------------------
7284 -- Both arguments must have the same type, and the boolean context does
7285 -- not participate in the resolution. The first pass verifies that the
7286 -- interpretation is not ambiguous, and the type of the left argument is
7287 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
7288 -- are strings or aggregates, allocators, or Null, they are ambiguous even
7289 -- though they carry a single (universal) type. Diagnose this case here.
7291 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7292 L
: constant Node_Id
:= Left_Opnd
(N
);
7293 R
: constant Node_Id
:= Right_Opnd
(N
);
7294 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
7296 procedure Check_If_Expression
(Cond
: Node_Id
);
7297 -- The resolution rule for if expressions requires that each such must
7298 -- have a unique type. This means that if several dependent expressions
7299 -- are of a non-null anonymous access type, and the context does not
7300 -- impose an expected type (as can be the case in an equality operation)
7301 -- the expression must be rejected.
7303 procedure Explain_Redundancy
(N
: Node_Id
);
7304 -- Attempt to explain the nature of a redundant comparison with True. If
7305 -- the expression N is too complex, this routine issues a general error
7308 function Find_Unique_Access_Type
return Entity_Id
;
7309 -- In the case of allocators and access attributes, the context must
7310 -- provide an indication of the specific access type to be used. If
7311 -- one operand is of such a "generic" access type, check whether there
7312 -- is a specific visible access type that has the same designated type.
7313 -- This is semantically dubious, and of no interest to any real code,
7314 -- but c48008a makes it all worthwhile.
7316 -------------------------
7317 -- Check_If_Expression --
7318 -------------------------
7320 procedure Check_If_Expression
(Cond
: Node_Id
) is
7321 Then_Expr
: Node_Id
;
7322 Else_Expr
: Node_Id
;
7325 if Nkind
(Cond
) = N_If_Expression
then
7326 Then_Expr
:= Next
(First
(Expressions
(Cond
)));
7327 Else_Expr
:= Next
(Then_Expr
);
7329 if Nkind
(Then_Expr
) /= N_Null
7330 and then Nkind
(Else_Expr
) /= N_Null
7332 Error_Msg_N
("cannot determine type of if expression", Cond
);
7335 end Check_If_Expression
;
7337 ------------------------
7338 -- Explain_Redundancy --
7339 ------------------------
7341 procedure Explain_Redundancy
(N
: Node_Id
) is
7349 -- Strip the operand down to an entity
7352 if Nkind
(Val
) = N_Selected_Component
then
7353 Val
:= Selector_Name
(Val
);
7359 -- The construct denotes an entity
7361 if Is_Entity_Name
(Val
) and then Present
(Entity
(Val
)) then
7362 Val_Id
:= Entity
(Val
);
7364 -- Do not generate an error message when the comparison is done
7365 -- against the enumeration literal Standard.True.
7367 if Ekind
(Val_Id
) /= E_Enumeration_Literal
then
7369 -- Build a customized error message
7372 Add_Str_To_Name_Buffer
("?r?");
7374 if Ekind
(Val_Id
) = E_Component
then
7375 Add_Str_To_Name_Buffer
("component ");
7377 elsif Ekind
(Val_Id
) = E_Constant
then
7378 Add_Str_To_Name_Buffer
("constant ");
7380 elsif Ekind
(Val_Id
) = E_Discriminant
then
7381 Add_Str_To_Name_Buffer
("discriminant ");
7383 elsif Is_Formal
(Val_Id
) then
7384 Add_Str_To_Name_Buffer
("parameter ");
7386 elsif Ekind
(Val_Id
) = E_Variable
then
7387 Add_Str_To_Name_Buffer
("variable ");
7390 Add_Str_To_Name_Buffer
("& is always True!");
7393 Error_Msg_NE
(Get_Name_String
(Error
), Val
, Val_Id
);
7396 -- The construct is too complex to disect, issue a general message
7399 Error_Msg_N
("?r?expression is always True!", Val
);
7401 end Explain_Redundancy
;
7403 -----------------------------
7404 -- Find_Unique_Access_Type --
7405 -----------------------------
7407 function Find_Unique_Access_Type
return Entity_Id
is
7413 if Ekind_In
(Etype
(R
), E_Allocator_Type
,
7414 E_Access_Attribute_Type
)
7416 Acc
:= Designated_Type
(Etype
(R
));
7418 elsif Ekind_In
(Etype
(L
), E_Allocator_Type
,
7419 E_Access_Attribute_Type
)
7421 Acc
:= Designated_Type
(Etype
(L
));
7427 while S
/= Standard_Standard
loop
7428 E
:= First_Entity
(S
);
7429 while Present
(E
) loop
7431 and then Is_Access_Type
(E
)
7432 and then Ekind
(E
) /= E_Allocator_Type
7433 and then Designated_Type
(E
) = Base_Type
(Acc
)
7445 end Find_Unique_Access_Type
;
7447 -- Start of processing for Resolve_Equality_Op
7450 Set_Etype
(N
, Base_Type
(Typ
));
7451 Generate_Reference
(T
, N
, ' ');
7453 if T
= Any_Fixed
then
7454 T
:= Unique_Fixed_Point_Type
(L
);
7457 if T
/= Any_Type
then
7458 if T
= Any_String
or else
7459 T
= Any_Composite
or else
7462 if T
= Any_Character
then
7463 Ambiguous_Character
(L
);
7465 Error_Msg_N
("ambiguous operands for equality", N
);
7468 Set_Etype
(N
, Any_Type
);
7471 elsif T
= Any_Access
7472 or else Ekind_In
(T
, E_Allocator_Type
, E_Access_Attribute_Type
)
7474 T
:= Find_Unique_Access_Type
;
7477 Error_Msg_N
("ambiguous operands for equality", N
);
7478 Set_Etype
(N
, Any_Type
);
7482 -- If expressions must have a single type, and if the context does
7483 -- not impose one the dependent expressions cannot be anonymous
7486 -- Why no similar processing for case expressions???
7488 elsif Ada_Version
>= Ada_2012
7489 and then Ekind_In
(Etype
(L
), E_Anonymous_Access_Type
,
7490 E_Anonymous_Access_Subprogram_Type
)
7491 and then Ekind_In
(Etype
(R
), E_Anonymous_Access_Type
,
7492 E_Anonymous_Access_Subprogram_Type
)
7494 Check_If_Expression
(L
);
7495 Check_If_Expression
(R
);
7501 -- In SPARK, equality operators = and /= for array types other than
7502 -- String are only defined when, for each index position, the
7503 -- operands have equal static bounds.
7505 if Is_Array_Type
(T
) then
7507 -- Protect call to Matching_Static_Array_Bounds to avoid costly
7508 -- operation if not needed.
7510 if Restriction_Check_Required
(SPARK_05
)
7511 and then Base_Type
(T
) /= Standard_String
7512 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
7513 and then Etype
(L
) /= Any_Composite
-- or else L in error
7514 and then Etype
(R
) /= Any_Composite
-- or else R in error
7515 and then not Matching_Static_Array_Bounds
(Etype
(L
), Etype
(R
))
7517 Check_SPARK_Restriction
7518 ("array types should have matching static bounds", N
);
7522 -- If the unique type is a class-wide type then it will be expanded
7523 -- into a dispatching call to the predefined primitive. Therefore we
7524 -- check here for potential violation of such restriction.
7526 if Is_Class_Wide_Type
(T
) then
7527 Check_Restriction
(No_Dispatching_Calls
, N
);
7530 if Warn_On_Redundant_Constructs
7531 and then Comes_From_Source
(N
)
7532 and then Comes_From_Source
(R
)
7533 and then Is_Entity_Name
(R
)
7534 and then Entity
(R
) = Standard_True
7536 Error_Msg_N
-- CODEFIX
7537 ("?r?comparison with True is redundant!", N
);
7538 Explain_Redundancy
(Original_Node
(R
));
7541 Check_Unset_Reference
(L
);
7542 Check_Unset_Reference
(R
);
7543 Generate_Operator_Reference
(N
, T
);
7544 Check_Low_Bound_Tested
(N
);
7546 -- If this is an inequality, it may be the implicit inequality
7547 -- created for a user-defined operation, in which case the corres-
7548 -- ponding equality operation is not intrinsic, and the operation
7549 -- cannot be constant-folded. Else fold.
7551 if Nkind
(N
) = N_Op_Eq
7552 or else Comes_From_Source
(Entity
(N
))
7553 or else Ekind
(Entity
(N
)) = E_Operator
7554 or else Is_Intrinsic_Subprogram
7555 (Corresponding_Equality
(Entity
(N
)))
7557 Analyze_Dimension
(N
);
7558 Eval_Relational_Op
(N
);
7560 elsif Nkind
(N
) = N_Op_Ne
7561 and then Is_Abstract_Subprogram
(Entity
(N
))
7563 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Entity
(N
));
7566 -- Ada 2005: If one operand is an anonymous access type, convert the
7567 -- other operand to it, to ensure that the underlying types match in
7568 -- the back-end. Same for access_to_subprogram, and the conversion
7569 -- verifies that the types are subtype conformant.
7571 -- We apply the same conversion in the case one of the operands is a
7572 -- private subtype of the type of the other.
7574 -- Why the Expander_Active test here ???
7578 (Ekind_In
(T
, E_Anonymous_Access_Type
,
7579 E_Anonymous_Access_Subprogram_Type
)
7580 or else Is_Private_Type
(T
))
7582 if Etype
(L
) /= T
then
7584 Make_Unchecked_Type_Conversion
(Sloc
(L
),
7585 Subtype_Mark
=> New_Occurrence_Of
(T
, Sloc
(L
)),
7586 Expression
=> Relocate_Node
(L
)));
7587 Analyze_And_Resolve
(L
, T
);
7590 if (Etype
(R
)) /= T
then
7592 Make_Unchecked_Type_Conversion
(Sloc
(R
),
7593 Subtype_Mark
=> New_Occurrence_Of
(Etype
(L
), Sloc
(R
)),
7594 Expression
=> Relocate_Node
(R
)));
7595 Analyze_And_Resolve
(R
, T
);
7599 end Resolve_Equality_Op
;
7601 ----------------------------------
7602 -- Resolve_Explicit_Dereference --
7603 ----------------------------------
7605 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
7606 Loc
: constant Source_Ptr
:= Sloc
(N
);
7608 P
: constant Node_Id
:= Prefix
(N
);
7611 -- The candidate prefix type, if overloaded
7617 Check_Fully_Declared_Prefix
(Typ
, P
);
7620 -- A useful optimization: check whether the dereference denotes an
7621 -- element of a container, and if so rewrite it as a call to the
7622 -- corresponding Element function.
7624 -- Disabled for now, on advice of ARG. A more restricted form of the
7625 -- predicate might be acceptable ???
7627 -- if Is_Container_Element (N) then
7631 if Is_Overloaded
(P
) then
7633 -- Use the context type to select the prefix that has the correct
7634 -- designated type. Keep the first match, which will be the inner-
7637 Get_First_Interp
(P
, I
, It
);
7639 while Present
(It
.Typ
) loop
7640 if Is_Access_Type
(It
.Typ
)
7641 and then Covers
(Typ
, Designated_Type
(It
.Typ
))
7647 -- Remove access types that do not match, but preserve access
7648 -- to subprogram interpretations, in case a further dereference
7649 -- is needed (see below).
7651 elsif Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7655 Get_Next_Interp
(I
, It
);
7658 if Present
(P_Typ
) then
7660 Set_Etype
(N
, Designated_Type
(P_Typ
));
7663 -- If no interpretation covers the designated type of the prefix,
7664 -- this is the pathological case where not all implementations of
7665 -- the prefix allow the interpretation of the node as a call. Now
7666 -- that the expected type is known, Remove other interpretations
7667 -- from prefix, rewrite it as a call, and resolve again, so that
7668 -- the proper call node is generated.
7670 Get_First_Interp
(P
, I
, It
);
7671 while Present
(It
.Typ
) loop
7672 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7676 Get_Next_Interp
(I
, It
);
7680 Make_Function_Call
(Loc
,
7682 Make_Explicit_Dereference
(Loc
,
7684 Parameter_Associations
=> New_List
);
7686 Save_Interps
(N
, New_N
);
7688 Analyze_And_Resolve
(N
, Typ
);
7692 -- If not overloaded, resolve P with its own type
7698 if Is_Access_Type
(Etype
(P
)) then
7699 Apply_Access_Check
(N
);
7702 -- If the designated type is a packed unconstrained array type, and the
7703 -- explicit dereference is not in the context of an attribute reference,
7704 -- then we must compute and set the actual subtype, since it is needed
7705 -- by Gigi. The reason we exclude the attribute case is that this is
7706 -- handled fine by Gigi, and in fact we use such attributes to build the
7707 -- actual subtype. We also exclude generated code (which builds actual
7708 -- subtypes directly if they are needed).
7710 if Is_Array_Type
(Etype
(N
))
7711 and then Is_Packed
(Etype
(N
))
7712 and then not Is_Constrained
(Etype
(N
))
7713 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
7714 and then Comes_From_Source
(N
)
7716 Set_Etype
(N
, Get_Actual_Subtype
(N
));
7719 -- Note: No Eval processing is required for an explicit dereference,
7720 -- because such a name can never be static.
7722 end Resolve_Explicit_Dereference
;
7724 -------------------------------------
7725 -- Resolve_Expression_With_Actions --
7726 -------------------------------------
7728 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
7732 -- If N has no actions, and its expression has been constant folded,
7733 -- then rewrite N as just its expression. Note, we can't do this in
7734 -- the general case of Is_Empty_List (Actions (N)) as this would cause
7735 -- Expression (N) to be expanded again.
7737 if Is_Empty_List
(Actions
(N
))
7738 and then Compile_Time_Known_Value
(Expression
(N
))
7740 Rewrite
(N
, Expression
(N
));
7742 end Resolve_Expression_With_Actions
;
7744 ----------------------------------
7745 -- Resolve_Generalized_Indexing --
7746 ----------------------------------
7748 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
) is
7749 Indexing
: constant Node_Id
:= Generalized_Indexing
(N
);
7755 -- In ASIS mode, propagate the information about the indices back to
7756 -- to the original indexing node. The generalized indexing is either
7757 -- a function call, or a dereference of one. The actuals include the
7758 -- prefix of the original node, which is the container expression.
7761 Resolve
(Indexing
, Typ
);
7762 Set_Etype
(N
, Etype
(Indexing
));
7763 Set_Is_Overloaded
(N
, False);
7766 while Nkind_In
(Call
, N_Explicit_Dereference
, N_Selected_Component
)
7768 Call
:= Prefix
(Call
);
7771 if Nkind
(Call
) = N_Function_Call
then
7772 Indices
:= Parameter_Associations
(Call
);
7773 Pref
:= Remove_Head
(Indices
);
7774 Set_Expressions
(N
, Indices
);
7775 Set_Prefix
(N
, Pref
);
7779 Rewrite
(N
, Indexing
);
7782 end Resolve_Generalized_Indexing
;
7784 ---------------------------
7785 -- Resolve_If_Expression --
7786 ---------------------------
7788 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7789 Condition
: constant Node_Id
:= First
(Expressions
(N
));
7790 Then_Expr
: constant Node_Id
:= Next
(Condition
);
7791 Else_Expr
: Node_Id
:= Next
(Then_Expr
);
7792 Else_Typ
: Entity_Id
;
7793 Then_Typ
: Entity_Id
;
7796 Resolve
(Condition
, Any_Boolean
);
7797 Resolve
(Then_Expr
, Typ
);
7798 Then_Typ
:= Etype
(Then_Expr
);
7800 -- When the "then" expression is of a scalar subtype different from the
7801 -- result subtype, then insert a conversion to ensure the generation of
7802 -- a constraint check. The same is done for the else part below, again
7803 -- comparing subtypes rather than base types.
7805 if Is_Scalar_Type
(Then_Typ
)
7806 and then Then_Typ
/= Typ
7808 Rewrite
(Then_Expr
, Convert_To
(Typ
, Then_Expr
));
7809 Analyze_And_Resolve
(Then_Expr
, Typ
);
7812 -- If ELSE expression present, just resolve using the determined type
7814 if Present
(Else_Expr
) then
7815 Resolve
(Else_Expr
, Typ
);
7816 Else_Typ
:= Etype
(Else_Expr
);
7818 if Is_Scalar_Type
(Else_Typ
)
7819 and then Else_Typ
/= Typ
7821 Rewrite
(Else_Expr
, Convert_To
(Typ
, Else_Expr
));
7822 Analyze_And_Resolve
(Else_Expr
, Typ
);
7825 -- If no ELSE expression is present, root type must be Standard.Boolean
7826 -- and we provide a Standard.True result converted to the appropriate
7827 -- Boolean type (in case it is a derived boolean type).
7829 elsif Root_Type
(Typ
) = Standard_Boolean
then
7831 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
7832 Analyze_And_Resolve
(Else_Expr
, Typ
);
7833 Append_To
(Expressions
(N
), Else_Expr
);
7836 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
7837 Append_To
(Expressions
(N
), Error
);
7841 Eval_If_Expression
(N
);
7842 end Resolve_If_Expression
;
7844 -------------------------------
7845 -- Resolve_Indexed_Component --
7846 -------------------------------
7848 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
7849 Name
: constant Node_Id
:= Prefix
(N
);
7851 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
7855 if Present
(Generalized_Indexing
(N
)) then
7856 Resolve_Generalized_Indexing
(N
, Typ
);
7860 if Is_Overloaded
(Name
) then
7862 -- Use the context type to select the prefix that yields the correct
7868 I1
: Interp_Index
:= 0;
7869 P
: constant Node_Id
:= Prefix
(N
);
7870 Found
: Boolean := False;
7873 Get_First_Interp
(P
, I
, It
);
7874 while Present
(It
.Typ
) loop
7875 if (Is_Array_Type
(It
.Typ
)
7876 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
7877 or else (Is_Access_Type
(It
.Typ
)
7878 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
7882 Component_Type
(Designated_Type
(It
.Typ
))))
7885 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
7887 if It
= No_Interp
then
7888 Error_Msg_N
("ambiguous prefix for indexing", N
);
7894 Array_Type
:= It
.Typ
;
7900 Array_Type
:= It
.Typ
;
7905 Get_Next_Interp
(I
, It
);
7910 Array_Type
:= Etype
(Name
);
7913 Resolve
(Name
, Array_Type
);
7914 Array_Type
:= Get_Actual_Subtype_If_Available
(Name
);
7916 -- If prefix is access type, dereference to get real array type.
7917 -- Note: we do not apply an access check because the expander always
7918 -- introduces an explicit dereference, and the check will happen there.
7920 if Is_Access_Type
(Array_Type
) then
7921 Array_Type
:= Designated_Type
(Array_Type
);
7924 -- If name was overloaded, set component type correctly now
7925 -- If a misplaced call to an entry family (which has no index types)
7926 -- return. Error will be diagnosed from calling context.
7928 if Is_Array_Type
(Array_Type
) then
7929 Set_Etype
(N
, Component_Type
(Array_Type
));
7934 Index
:= First_Index
(Array_Type
);
7935 Expr
:= First
(Expressions
(N
));
7937 -- The prefix may have resolved to a string literal, in which case its
7938 -- etype has a special representation. This is only possible currently
7939 -- if the prefix is a static concatenation, written in functional
7942 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
7943 Resolve
(Expr
, Standard_Positive
);
7946 while Present
(Index
) and Present
(Expr
) loop
7947 Resolve
(Expr
, Etype
(Index
));
7948 Check_Unset_Reference
(Expr
);
7950 if Is_Scalar_Type
(Etype
(Expr
)) then
7951 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
7953 Apply_Range_Check
(Expr
, Get_Actual_Subtype
(Index
));
7961 Analyze_Dimension
(N
);
7963 -- Do not generate the warning on suspicious index if we are analyzing
7964 -- package Ada.Tags; otherwise we will report the warning with the
7965 -- Prims_Ptr field of the dispatch table.
7967 if Scope
(Etype
(Prefix
(N
))) = Standard_Standard
7969 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Prefix
(N
)))),
7972 Warn_On_Suspicious_Index
(Name
, First
(Expressions
(N
)));
7973 Eval_Indexed_Component
(N
);
7976 -- If the array type is atomic, and is packed, and we are in a left side
7977 -- context, then this is worth a warning, since we have a situation
7978 -- where the access to the component may cause extra read/writes of
7979 -- the atomic array object, which could be considered unexpected.
7981 if Nkind
(N
) = N_Indexed_Component
7982 and then (Is_Atomic
(Array_Type
)
7983 or else (Is_Entity_Name
(Prefix
(N
))
7984 and then Is_Atomic
(Entity
(Prefix
(N
)))))
7985 and then Is_Bit_Packed_Array
(Array_Type
)
7986 and then Is_LHS
(N
) = Yes
7988 Error_Msg_N
("??assignment to component of packed atomic array",
7990 Error_Msg_N
("??\may cause unexpected accesses to atomic object",
7993 end Resolve_Indexed_Component
;
7995 -----------------------------
7996 -- Resolve_Integer_Literal --
7997 -----------------------------
7999 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
8002 Eval_Integer_Literal
(N
);
8003 end Resolve_Integer_Literal
;
8005 --------------------------------
8006 -- Resolve_Intrinsic_Operator --
8007 --------------------------------
8009 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
8010 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8015 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
;
8016 -- If the operand is a literal, it cannot be the expression in a
8017 -- conversion. Use a qualified expression instead.
8019 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
is
8020 Loc
: constant Source_Ptr
:= Sloc
(Opnd
);
8023 if Nkind_In
(Opnd
, N_Integer_Literal
, N_Real_Literal
) then
8025 Make_Qualified_Expression
(Loc
,
8026 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
8027 Expression
=> Relocate_Node
(Opnd
));
8031 Res
:= Unchecked_Convert_To
(Btyp
, Opnd
);
8035 end Convert_Operand
;
8037 -- Start of processing for Resolve_Intrinsic_Operator
8040 -- We must preserve the original entity in a generic setting, so that
8041 -- the legality of the operation can be verified in an instance.
8043 if not Expander_Active
then
8048 while Scope
(Op
) /= Standard_Standard
loop
8050 pragma Assert
(Present
(Op
));
8054 Set_Is_Overloaded
(N
, False);
8056 -- If the result or operand types are private, rewrite with unchecked
8057 -- conversions on the operands and the result, to expose the proper
8058 -- underlying numeric type.
8060 if Is_Private_Type
(Typ
)
8061 or else Is_Private_Type
(Etype
(Left_Opnd
(N
)))
8062 or else Is_Private_Type
(Etype
(Right_Opnd
(N
)))
8064 Arg1
:= Convert_Operand
(Left_Opnd
(N
));
8065 -- Unchecked_Convert_To (Btyp, Left_Opnd (N));
8066 -- What on earth is this commented out fragment of code???
8068 if Nkind
(N
) = N_Op_Expon
then
8069 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
8071 Arg2
:= Convert_Operand
(Right_Opnd
(N
));
8074 if Nkind
(Arg1
) = N_Type_Conversion
then
8075 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8078 if Nkind
(Arg2
) = N_Type_Conversion
then
8079 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8082 Set_Left_Opnd
(N
, Arg1
);
8083 Set_Right_Opnd
(N
, Arg2
);
8085 Set_Etype
(N
, Btyp
);
8086 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8089 elsif Typ
/= Etype
(Left_Opnd
(N
))
8090 or else Typ
/= Etype
(Right_Opnd
(N
))
8092 -- Add explicit conversion where needed, and save interpretations in
8093 -- case operands are overloaded.
8095 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
8096 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
8098 if Nkind
(Arg1
) = N_Type_Conversion
then
8099 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8101 Save_Interps
(Left_Opnd
(N
), Arg1
);
8104 if Nkind
(Arg2
) = N_Type_Conversion
then
8105 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8107 Save_Interps
(Right_Opnd
(N
), Arg2
);
8110 Rewrite
(Left_Opnd
(N
), Arg1
);
8111 Rewrite
(Right_Opnd
(N
), Arg2
);
8114 Resolve_Arithmetic_Op
(N
, Typ
);
8117 Resolve_Arithmetic_Op
(N
, Typ
);
8119 end Resolve_Intrinsic_Operator
;
8121 --------------------------------------
8122 -- Resolve_Intrinsic_Unary_Operator --
8123 --------------------------------------
8125 procedure Resolve_Intrinsic_Unary_Operator
8129 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8135 while Scope
(Op
) /= Standard_Standard
loop
8137 pragma Assert
(Present
(Op
));
8142 if Is_Private_Type
(Typ
) then
8143 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
8144 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8146 Set_Right_Opnd
(N
, Arg2
);
8148 Set_Etype
(N
, Btyp
);
8149 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8153 Resolve_Unary_Op
(N
, Typ
);
8155 end Resolve_Intrinsic_Unary_Operator
;
8157 ------------------------
8158 -- Resolve_Logical_Op --
8159 ------------------------
8161 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8165 Check_No_Direct_Boolean_Operators
(N
);
8167 -- Predefined operations on scalar types yield the base type. On the
8168 -- other hand, logical operations on arrays yield the type of the
8169 -- arguments (and the context).
8171 if Is_Array_Type
(Typ
) then
8174 B_Typ
:= Base_Type
(Typ
);
8177 -- The following test is required because the operands of the operation
8178 -- may be literals, in which case the resulting type appears to be
8179 -- compatible with a signed integer type, when in fact it is compatible
8180 -- only with modular types. If the context itself is universal, the
8181 -- operation is illegal.
8183 if not Valid_Boolean_Arg
(Typ
) then
8184 Error_Msg_N
("invalid context for logical operation", N
);
8185 Set_Etype
(N
, Any_Type
);
8188 elsif Typ
= Any_Modular
then
8190 ("no modular type available in this context", N
);
8191 Set_Etype
(N
, Any_Type
);
8194 elsif Is_Modular_Integer_Type
(Typ
)
8195 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
8196 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
8198 Check_For_Visible_Operator
(N
, B_Typ
);
8201 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
8202 -- is active and the result type is standard Boolean (do not mess with
8203 -- ops that return a nonstandard Boolean type, because something strange
8206 -- Note: you might expect this replacement to be done during expansion,
8207 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
8208 -- is used, no part of the right operand of an "and" or "or" operator
8209 -- should be executed if the left operand would short-circuit the
8210 -- evaluation of the corresponding "and then" or "or else". If we left
8211 -- the replacement to expansion time, then run-time checks associated
8212 -- with such operands would be evaluated unconditionally, due to being
8213 -- before the condition prior to the rewriting as short-circuit forms
8214 -- during expansion.
8216 if Short_Circuit_And_Or
8217 and then B_Typ
= Standard_Boolean
8218 and then Nkind_In
(N
, N_Op_And
, N_Op_Or
)
8220 if Nkind
(N
) = N_Op_And
then
8222 Make_And_Then
(Sloc
(N
),
8223 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8224 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8225 Analyze_And_Resolve
(N
, B_Typ
);
8227 -- Case of OR changed to OR ELSE
8231 Make_Or_Else
(Sloc
(N
),
8232 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8233 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8234 Analyze_And_Resolve
(N
, B_Typ
);
8237 -- Return now, since analysis of the rewritten ops will take care of
8238 -- other reference bookkeeping and expression folding.
8243 Resolve
(Left_Opnd
(N
), B_Typ
);
8244 Resolve
(Right_Opnd
(N
), B_Typ
);
8246 Check_Unset_Reference
(Left_Opnd
(N
));
8247 Check_Unset_Reference
(Right_Opnd
(N
));
8249 Set_Etype
(N
, B_Typ
);
8250 Generate_Operator_Reference
(N
, B_Typ
);
8251 Eval_Logical_Op
(N
);
8253 -- In SPARK, logical operations AND, OR and XOR for arrays are defined
8254 -- only when both operands have same static lower and higher bounds. Of
8255 -- course the types have to match, so only check if operands are
8256 -- compatible and the node itself has no errors.
8258 if Is_Array_Type
(B_Typ
)
8259 and then Nkind
(N
) in N_Binary_Op
8262 Left_Typ
: constant Node_Id
:= Etype
(Left_Opnd
(N
));
8263 Right_Typ
: constant Node_Id
:= Etype
(Right_Opnd
(N
));
8266 -- Protect call to Matching_Static_Array_Bounds to avoid costly
8267 -- operation if not needed.
8269 if Restriction_Check_Required
(SPARK_05
)
8270 and then Base_Type
(Left_Typ
) = Base_Type
(Right_Typ
)
8271 and then Left_Typ
/= Any_Composite
-- or Left_Opnd in error
8272 and then Right_Typ
/= Any_Composite
-- or Right_Opnd in error
8273 and then not Matching_Static_Array_Bounds
(Left_Typ
, Right_Typ
)
8275 Check_SPARK_Restriction
8276 ("array types should have matching static bounds", N
);
8281 Check_Function_Writable_Actuals
(N
);
8282 end Resolve_Logical_Op
;
8284 ---------------------------
8285 -- Resolve_Membership_Op --
8286 ---------------------------
8288 -- The context can only be a boolean type, and does not determine the
8289 -- arguments. Arguments should be unambiguous, but the preference rule for
8290 -- universal types applies.
8292 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8293 pragma Warnings
(Off
, Typ
);
8295 L
: constant Node_Id
:= Left_Opnd
(N
);
8296 R
: constant Node_Id
:= Right_Opnd
(N
);
8299 procedure Resolve_Set_Membership
;
8300 -- Analysis has determined a unique type for the left operand. Use it to
8301 -- resolve the disjuncts.
8303 ----------------------------
8304 -- Resolve_Set_Membership --
8305 ----------------------------
8307 procedure Resolve_Set_Membership
is
8309 Ltyp
: constant Entity_Id
:= Etype
(L
);
8314 Alt
:= First
(Alternatives
(N
));
8315 while Present
(Alt
) loop
8317 -- Alternative is an expression, a range
8318 -- or a subtype mark.
8320 if not Is_Entity_Name
(Alt
)
8321 or else not Is_Type
(Entity
(Alt
))
8323 Resolve
(Alt
, Ltyp
);
8329 -- Check for duplicates for discrete case
8331 if Is_Discrete_Type
(Ltyp
) then
8338 Alts
: array (0 .. List_Length
(Alternatives
(N
))) of Ent
;
8342 -- Loop checking duplicates. This is quadratic, but giant sets
8343 -- are unlikely in this context so it's a reasonable choice.
8346 Alt
:= First
(Alternatives
(N
));
8347 while Present
(Alt
) loop
8348 if Is_OK_Static_Expression
(Alt
)
8349 and then (Nkind_In
(Alt
, N_Integer_Literal
,
8350 N_Character_Literal
)
8351 or else Nkind
(Alt
) in N_Has_Entity
)
8354 Alts
(Nalts
) := (Alt
, Expr_Value
(Alt
));
8356 for J
in 1 .. Nalts
- 1 loop
8357 if Alts
(J
).Val
= Alts
(Nalts
).Val
then
8358 Error_Msg_Sloc
:= Sloc
(Alts
(J
).Alt
);
8359 Error_Msg_N
("duplicate of value given#??", Alt
);
8368 end Resolve_Set_Membership
;
8370 -- Start of processing for Resolve_Membership_Op
8373 if L
= Error
or else R
= Error
then
8377 if Present
(Alternatives
(N
)) then
8378 Resolve_Set_Membership
;
8381 elsif not Is_Overloaded
(R
)
8383 (Etype
(R
) = Universal_Integer
8385 Etype
(R
) = Universal_Real
)
8386 and then Is_Overloaded
(L
)
8390 -- Ada 2005 (AI-251): Support the following case:
8392 -- type I is interface;
8393 -- type T is tagged ...
8395 -- function Test (O : I'Class) is
8397 -- return O in T'Class.
8400 -- In this case we have nothing else to do. The membership test will be
8401 -- done at run time.
8403 elsif Ada_Version
>= Ada_2005
8404 and then Is_Class_Wide_Type
(Etype
(L
))
8405 and then Is_Interface
(Etype
(L
))
8406 and then Is_Class_Wide_Type
(Etype
(R
))
8407 and then not Is_Interface
(Etype
(R
))
8411 T
:= Intersect_Types
(L
, R
);
8414 -- If mixed-mode operations are present and operands are all literal,
8415 -- the only interpretation involves Duration, which is probably not
8416 -- the intention of the programmer.
8418 if T
= Any_Fixed
then
8419 T
:= Unique_Fixed_Point_Type
(N
);
8421 if T
= Any_Type
then
8427 Check_Unset_Reference
(L
);
8429 if Nkind
(R
) = N_Range
8430 and then not Is_Scalar_Type
(T
)
8432 Error_Msg_N
("scalar type required for range", R
);
8435 if Is_Entity_Name
(R
) then
8436 Freeze_Expression
(R
);
8439 Check_Unset_Reference
(R
);
8442 -- Here after resolving membership operation
8446 Eval_Membership_Op
(N
);
8447 Check_Function_Writable_Actuals
(N
);
8448 end Resolve_Membership_Op
;
8454 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
8455 Loc
: constant Source_Ptr
:= Sloc
(N
);
8458 -- Handle restriction against anonymous null access values This
8459 -- restriction can be turned off using -gnatdj.
8461 -- Ada 2005 (AI-231): Remove restriction
8463 if Ada_Version
< Ada_2005
8464 and then not Debug_Flag_J
8465 and then Ekind
(Typ
) = E_Anonymous_Access_Type
8466 and then Comes_From_Source
(N
)
8468 -- In the common case of a call which uses an explicitly null value
8469 -- for an access parameter, give specialized error message.
8471 if Nkind
(Parent
(N
)) in N_Subprogram_Call
then
8473 ("null is not allowed as argument for an access parameter", N
);
8475 -- Standard message for all other cases (are there any?)
8479 ("null cannot be of an anonymous access type", N
);
8483 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
8484 -- assignment to a null-excluding object
8486 if Ada_Version
>= Ada_2005
8487 and then Can_Never_Be_Null
(Typ
)
8488 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
8490 if not Inside_Init_Proc
then
8492 (Compile_Time_Constraint_Error
(N
,
8493 "(Ada 2005) null not allowed in null-excluding objects??"),
8494 Make_Raise_Constraint_Error
(Loc
,
8495 Reason
=> CE_Access_Check_Failed
));
8498 Make_Raise_Constraint_Error
(Loc
,
8499 Reason
=> CE_Access_Check_Failed
));
8503 -- In a distributed context, null for a remote access to subprogram may
8504 -- need to be replaced with a special record aggregate. In this case,
8505 -- return after having done the transformation.
8507 if (Ekind
(Typ
) = E_Record_Type
8508 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
8509 and then Remote_AST_Null_Value
(N
, Typ
)
8514 -- The null literal takes its type from the context
8519 -----------------------
8520 -- Resolve_Op_Concat --
8521 -----------------------
8523 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
8525 -- We wish to avoid deep recursion, because concatenations are often
8526 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
8527 -- operands nonrecursively until we find something that is not a simple
8528 -- concatenation (A in this case). We resolve that, and then walk back
8529 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
8530 -- to do the rest of the work at each level. The Parent pointers allow
8531 -- us to avoid recursion, and thus avoid running out of memory. See also
8532 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
8538 -- The following code is equivalent to:
8540 -- Resolve_Op_Concat_First (NN, Typ);
8541 -- Resolve_Op_Concat_Arg (N, ...);
8542 -- Resolve_Op_Concat_Rest (N, Typ);
8544 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
8545 -- operand is a concatenation.
8547 -- Walk down left operands
8550 Resolve_Op_Concat_First
(NN
, Typ
);
8551 Op1
:= Left_Opnd
(NN
);
8552 exit when not (Nkind
(Op1
) = N_Op_Concat
8553 and then not Is_Array_Type
(Component_Type
(Typ
))
8554 and then Entity
(Op1
) = Entity
(NN
));
8558 -- Now (given the above example) NN is A&B and Op1 is A
8560 -- First resolve Op1 ...
8562 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
8564 -- ... then walk NN back up until we reach N (where we started), calling
8565 -- Resolve_Op_Concat_Rest along the way.
8568 Resolve_Op_Concat_Rest
(NN
, Typ
);
8573 if Base_Type
(Etype
(N
)) /= Standard_String
then
8574 Check_SPARK_Restriction
8575 ("result of concatenation should have type String", N
);
8577 end Resolve_Op_Concat
;
8579 ---------------------------
8580 -- Resolve_Op_Concat_Arg --
8581 ---------------------------
8583 procedure Resolve_Op_Concat_Arg
8589 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8590 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
8595 or else (not Is_Overloaded
(Arg
)
8596 and then Etype
(Arg
) /= Any_Composite
8597 and then Covers
(Ctyp
, Etype
(Arg
)))
8599 Resolve
(Arg
, Ctyp
);
8601 Resolve
(Arg
, Btyp
);
8604 -- If both Array & Array and Array & Component are visible, there is a
8605 -- potential ambiguity that must be reported.
8607 elsif Has_Compatible_Type
(Arg
, Ctyp
) then
8608 if Nkind
(Arg
) = N_Aggregate
8609 and then Is_Composite_Type
(Ctyp
)
8611 if Is_Private_Type
(Ctyp
) then
8612 Resolve
(Arg
, Btyp
);
8614 -- If the operation is user-defined and not overloaded use its
8615 -- profile. The operation may be a renaming, in which case it has
8616 -- been rewritten, and we want the original profile.
8618 elsif not Is_Overloaded
(N
)
8619 and then Comes_From_Source
(Entity
(Original_Node
(N
)))
8620 and then Ekind
(Entity
(Original_Node
(N
))) = E_Function
8624 (Next_Formal
(First_Formal
(Entity
(Original_Node
(N
))))));
8627 -- Otherwise an aggregate may match both the array type and the
8631 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
8632 Set_Etype
(Arg
, Any_Type
);
8636 if Is_Overloaded
(Arg
)
8637 and then Has_Compatible_Type
(Arg
, Typ
)
8638 and then Etype
(Arg
) /= Any_Type
8646 Get_First_Interp
(Arg
, I
, It
);
8648 Get_Next_Interp
(I
, It
);
8650 -- Special-case the error message when the overloading is
8651 -- caused by a function that yields an array and can be
8652 -- called without parameters.
8654 if It
.Nam
= Func
then
8655 Error_Msg_Sloc
:= Sloc
(Func
);
8656 Error_Msg_N
("ambiguous call to function#", Arg
);
8658 ("\\interpretation as call yields&", Arg
, Typ
);
8660 ("\\interpretation as indexing of call yields&",
8661 Arg
, Component_Type
(Typ
));
8664 Error_Msg_N
("ambiguous operand for concatenation!", Arg
);
8666 Get_First_Interp
(Arg
, I
, It
);
8667 while Present
(It
.Nam
) loop
8668 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
8670 if Base_Type
(It
.Typ
) = Btyp
8672 Base_Type
(It
.Typ
) = Base_Type
(Ctyp
)
8674 Error_Msg_N
-- CODEFIX
8675 ("\\possible interpretation#", Arg
);
8678 Get_Next_Interp
(I
, It
);
8684 Resolve
(Arg
, Component_Type
(Typ
));
8686 if Nkind
(Arg
) = N_String_Literal
then
8687 Set_Etype
(Arg
, Component_Type
(Typ
));
8690 if Arg
= Left_Opnd
(N
) then
8691 Set_Is_Component_Left_Opnd
(N
);
8693 Set_Is_Component_Right_Opnd
(N
);
8698 Resolve
(Arg
, Btyp
);
8701 -- Concatenation is restricted in SPARK: each operand must be either a
8702 -- string literal, the name of a string constant, a static character or
8703 -- string expression, or another concatenation. Arg cannot be a
8704 -- concatenation here as callers of Resolve_Op_Concat_Arg call it
8705 -- separately on each final operand, past concatenation operations.
8707 if Is_Character_Type
(Etype
(Arg
)) then
8708 if not Is_OK_Static_Expression
(Arg
) then
8709 Check_SPARK_Restriction
8710 ("character operand for concatenation should be static", Arg
);
8713 elsif Is_String_Type
(Etype
(Arg
)) then
8714 if not (Nkind_In
(Arg
, N_Identifier
, N_Expanded_Name
)
8715 and then Is_Constant_Object
(Entity
(Arg
)))
8716 and then not Is_OK_Static_Expression
(Arg
)
8718 Check_SPARK_Restriction
8719 ("string operand for concatenation should be static", Arg
);
8722 -- Do not issue error on an operand that is neither a character nor a
8723 -- string, as the error is issued in Resolve_Op_Concat.
8729 Check_Unset_Reference
(Arg
);
8730 end Resolve_Op_Concat_Arg
;
8732 -----------------------------
8733 -- Resolve_Op_Concat_First --
8734 -----------------------------
8736 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
8737 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8738 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8739 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8742 -- The parser folds an enormous sequence of concatenations of string
8743 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
8744 -- in the right operand. If the expression resolves to a predefined "&"
8745 -- operator, all is well. Otherwise, the parser's folding is wrong, so
8746 -- we give an error. See P_Simple_Expression in Par.Ch4.
8748 if Nkind
(Op2
) = N_String_Literal
8749 and then Is_Folded_In_Parser
(Op2
)
8750 and then Ekind
(Entity
(N
)) = E_Function
8752 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
8753 and then String_Length
(Strval
(Op1
)) = 0);
8754 Error_Msg_N
("too many user-defined concatenations", N
);
8758 Set_Etype
(N
, Btyp
);
8760 if Is_Limited_Composite
(Btyp
) then
8761 Error_Msg_N
("concatenation not available for limited array", N
);
8762 Explain_Limited_Type
(Btyp
, N
);
8764 end Resolve_Op_Concat_First
;
8766 ----------------------------
8767 -- Resolve_Op_Concat_Rest --
8768 ----------------------------
8770 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
8771 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8772 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8775 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
8777 Generate_Operator_Reference
(N
, Typ
);
8779 if Is_String_Type
(Typ
) then
8780 Eval_Concatenation
(N
);
8783 -- If this is not a static concatenation, but the result is a string
8784 -- type (and not an array of strings) ensure that static string operands
8785 -- have their subtypes properly constructed.
8787 if Nkind
(N
) /= N_String_Literal
8788 and then Is_Character_Type
(Component_Type
(Typ
))
8790 Set_String_Literal_Subtype
(Op1
, Typ
);
8791 Set_String_Literal_Subtype
(Op2
, Typ
);
8793 end Resolve_Op_Concat_Rest
;
8795 ----------------------
8796 -- Resolve_Op_Expon --
8797 ----------------------
8799 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
8800 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
8803 -- Catch attempts to do fixed-point exponentiation with universal
8804 -- operands, which is a case where the illegality is not caught during
8805 -- normal operator analysis. This is not done in preanalysis mode
8806 -- since the tree is not fully decorated during preanalysis.
8808 if Full_Analysis
then
8809 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
8810 Error_Msg_N
("exponentiation not available for fixed point", N
);
8813 elsif Nkind
(Parent
(N
)) in N_Op
8814 and then Is_Fixed_Point_Type
(Etype
(Parent
(N
)))
8815 and then Etype
(N
) = Universal_Real
8816 and then Comes_From_Source
(N
)
8818 Error_Msg_N
("exponentiation not available for fixed point", N
);
8823 if Comes_From_Source
(N
)
8824 and then Ekind
(Entity
(N
)) = E_Function
8825 and then Is_Imported
(Entity
(N
))
8826 and then Is_Intrinsic_Subprogram
(Entity
(N
))
8828 Resolve_Intrinsic_Operator
(N
, Typ
);
8832 if Etype
(Left_Opnd
(N
)) = Universal_Integer
8833 or else Etype
(Left_Opnd
(N
)) = Universal_Real
8835 Check_For_Visible_Operator
(N
, B_Typ
);
8838 -- We do the resolution using the base type, because intermediate values
8839 -- in expressions are always of the base type, not a subtype of it.
8841 Resolve
(Left_Opnd
(N
), B_Typ
);
8842 Resolve
(Right_Opnd
(N
), Standard_Integer
);
8844 -- For integer types, right argument must be in Natural range
8846 if Is_Integer_Type
(Typ
) then
8847 Apply_Scalar_Range_Check
(Right_Opnd
(N
), Standard_Natural
);
8850 Check_Unset_Reference
(Left_Opnd
(N
));
8851 Check_Unset_Reference
(Right_Opnd
(N
));
8853 Set_Etype
(N
, B_Typ
);
8854 Generate_Operator_Reference
(N
, B_Typ
);
8856 Analyze_Dimension
(N
);
8858 if Ada_Version
>= Ada_2012
and then Has_Dimension_System
(B_Typ
) then
8859 -- Evaluate the exponentiation operator for dimensioned type
8861 Eval_Op_Expon_For_Dimensioned_Type
(N
, B_Typ
);
8866 -- Set overflow checking bit. Much cleverer code needed here eventually
8867 -- and perhaps the Resolve routines should be separated for the various
8868 -- arithmetic operations, since they will need different processing. ???
8870 if Nkind
(N
) in N_Op
then
8871 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
8872 Enable_Overflow_Check
(N
);
8875 end Resolve_Op_Expon
;
8877 --------------------
8878 -- Resolve_Op_Not --
8879 --------------------
8881 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
8884 function Parent_Is_Boolean
return Boolean;
8885 -- This function determines if the parent node is a boolean operator or
8886 -- operation (comparison op, membership test, or short circuit form) and
8887 -- the not in question is the left operand of this operation. Note that
8888 -- if the not is in parens, then false is returned.
8890 -----------------------
8891 -- Parent_Is_Boolean --
8892 -----------------------
8894 function Parent_Is_Boolean
return Boolean is
8896 if Paren_Count
(N
) /= 0 then
8900 case Nkind
(Parent
(N
)) is
8915 return Left_Opnd
(Parent
(N
)) = N
;
8921 end Parent_Is_Boolean
;
8923 -- Start of processing for Resolve_Op_Not
8926 -- Predefined operations on scalar types yield the base type. On the
8927 -- other hand, logical operations on arrays yield the type of the
8928 -- arguments (and the context).
8930 if Is_Array_Type
(Typ
) then
8933 B_Typ
:= Base_Type
(Typ
);
8936 -- Straightforward case of incorrect arguments
8938 if not Valid_Boolean_Arg
(Typ
) then
8939 Error_Msg_N
("invalid operand type for operator&", N
);
8940 Set_Etype
(N
, Any_Type
);
8943 -- Special case of probable missing parens
8945 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
8946 if Parent_Is_Boolean
then
8948 ("operand of not must be enclosed in parentheses",
8952 ("no modular type available in this context", N
);
8955 Set_Etype
(N
, Any_Type
);
8958 -- OK resolution of NOT
8961 -- Warn if non-boolean types involved. This is a case like not a < b
8962 -- where a and b are modular, where we will get (not a) < b and most
8963 -- likely not (a < b) was intended.
8965 if Warn_On_Questionable_Missing_Parens
8966 and then not Is_Boolean_Type
(Typ
)
8967 and then Parent_Is_Boolean
8969 Error_Msg_N
("?q?not expression should be parenthesized here!", N
);
8972 -- Warn on double negation if checking redundant constructs
8974 if Warn_On_Redundant_Constructs
8975 and then Comes_From_Source
(N
)
8976 and then Comes_From_Source
(Right_Opnd
(N
))
8977 and then Root_Type
(Typ
) = Standard_Boolean
8978 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
8980 Error_Msg_N
("redundant double negation?r?", N
);
8983 -- Complete resolution and evaluation of NOT
8985 Resolve
(Right_Opnd
(N
), B_Typ
);
8986 Check_Unset_Reference
(Right_Opnd
(N
));
8987 Set_Etype
(N
, B_Typ
);
8988 Generate_Operator_Reference
(N
, B_Typ
);
8993 -----------------------------
8994 -- Resolve_Operator_Symbol --
8995 -----------------------------
8997 -- Nothing to be done, all resolved already
8999 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
9000 pragma Warnings
(Off
, N
);
9001 pragma Warnings
(Off
, Typ
);
9005 end Resolve_Operator_Symbol
;
9007 ----------------------------------
9008 -- Resolve_Qualified_Expression --
9009 ----------------------------------
9011 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9012 pragma Warnings
(Off
, Typ
);
9014 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
9015 Expr
: constant Node_Id
:= Expression
(N
);
9018 Resolve
(Expr
, Target_Typ
);
9020 -- Protect call to Matching_Static_Array_Bounds to avoid costly
9021 -- operation if not needed.
9023 if Restriction_Check_Required
(SPARK_05
)
9024 and then Is_Array_Type
(Target_Typ
)
9025 and then Is_Array_Type
(Etype
(Expr
))
9026 and then Etype
(Expr
) /= Any_Composite
-- or else Expr in error
9027 and then not Matching_Static_Array_Bounds
(Target_Typ
, Etype
(Expr
))
9029 Check_SPARK_Restriction
9030 ("array types should have matching static bounds", N
);
9033 -- A qualified expression requires an exact match of the type, class-
9034 -- wide matching is not allowed. However, if the qualifying type is
9035 -- specific and the expression has a class-wide type, it may still be
9036 -- okay, since it can be the result of the expansion of a call to a
9037 -- dispatching function, so we also have to check class-wideness of the
9038 -- type of the expression's original node.
9040 if (Is_Class_Wide_Type
(Target_Typ
)
9042 (Is_Class_Wide_Type
(Etype
(Expr
))
9043 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
9044 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
9046 Wrong_Type
(Expr
, Target_Typ
);
9049 -- If the target type is unconstrained, then we reset the type of the
9050 -- result from the type of the expression. For other cases, the actual
9051 -- subtype of the expression is the target type.
9053 if Is_Composite_Type
(Target_Typ
)
9054 and then not Is_Constrained
(Target_Typ
)
9056 Set_Etype
(N
, Etype
(Expr
));
9059 Analyze_Dimension
(N
);
9060 Eval_Qualified_Expression
(N
);
9061 end Resolve_Qualified_Expression
;
9063 ------------------------------
9064 -- Resolve_Raise_Expression --
9065 ------------------------------
9067 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9069 if Typ
= Raise_Type
then
9070 Error_Msg_N
("cannot find unique type for raise expression", N
);
9071 Set_Etype
(N
, Any_Type
);
9075 end Resolve_Raise_Expression
;
9081 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
9082 L
: constant Node_Id
:= Low_Bound
(N
);
9083 H
: constant Node_Id
:= High_Bound
(N
);
9085 function First_Last_Ref
return Boolean;
9086 -- Returns True if N is of the form X'First .. X'Last where X is the
9087 -- same entity for both attributes.
9089 --------------------
9090 -- First_Last_Ref --
9091 --------------------
9093 function First_Last_Ref
return Boolean is
9094 Lorig
: constant Node_Id
:= Original_Node
(L
);
9095 Horig
: constant Node_Id
:= Original_Node
(H
);
9098 if Nkind
(Lorig
) = N_Attribute_Reference
9099 and then Nkind
(Horig
) = N_Attribute_Reference
9100 and then Attribute_Name
(Lorig
) = Name_First
9101 and then Attribute_Name
(Horig
) = Name_Last
9104 PL
: constant Node_Id
:= Prefix
(Lorig
);
9105 PH
: constant Node_Id
:= Prefix
(Horig
);
9107 if Is_Entity_Name
(PL
)
9108 and then Is_Entity_Name
(PH
)
9109 and then Entity
(PL
) = Entity
(PH
)
9119 -- Start of processing for Resolve_Range
9126 -- Check for inappropriate range on unordered enumeration type
9128 if Bad_Unordered_Enumeration_Reference
(N
, Typ
)
9130 -- Exclude X'First .. X'Last if X is the same entity for both
9132 and then not First_Last_Ref
9134 Error_Msg_Sloc
:= Sloc
(Typ
);
9136 ("subrange of unordered enumeration type& declared#?U?", N
, Typ
);
9139 Check_Unset_Reference
(L
);
9140 Check_Unset_Reference
(H
);
9142 -- We have to check the bounds for being within the base range as
9143 -- required for a non-static context. Normally this is automatic and
9144 -- done as part of evaluating expressions, but the N_Range node is an
9145 -- exception, since in GNAT we consider this node to be a subexpression,
9146 -- even though in Ada it is not. The circuit in Sem_Eval could check for
9147 -- this, but that would put the test on the main evaluation path for
9150 Check_Non_Static_Context
(L
);
9151 Check_Non_Static_Context
(H
);
9153 -- Check for an ambiguous range over character literals. This will
9154 -- happen with a membership test involving only literals.
9156 if Typ
= Any_Character
then
9157 Ambiguous_Character
(L
);
9158 Set_Etype
(N
, Any_Type
);
9162 -- If bounds are static, constant-fold them, so size computations are
9163 -- identical between front-end and back-end. Do not perform this
9164 -- transformation while analyzing generic units, as type information
9165 -- would be lost when reanalyzing the constant node in the instance.
9167 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
9168 if Is_OK_Static_Expression
(L
) then
9169 Fold_Uint
(L
, Expr_Value
(L
), Is_OK_Static_Expression
(L
));
9172 if Is_OK_Static_Expression
(H
) then
9173 Fold_Uint
(H
, Expr_Value
(H
), Is_OK_Static_Expression
(H
));
9178 --------------------------
9179 -- Resolve_Real_Literal --
9180 --------------------------
9182 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9183 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
9186 -- Special processing for fixed-point literals to make sure that the
9187 -- value is an exact multiple of small where this is required. We skip
9188 -- this for the universal real case, and also for generic types.
9190 if Is_Fixed_Point_Type
(Typ
)
9191 and then Typ
/= Universal_Fixed
9192 and then Typ
/= Any_Fixed
9193 and then not Is_Generic_Type
(Typ
)
9196 Val
: constant Ureal
:= Realval
(N
);
9197 Cintr
: constant Ureal
:= Val
/ Small_Value
(Typ
);
9198 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
9199 Den
: constant Uint
:= Norm_Den
(Cintr
);
9203 -- Case of literal is not an exact multiple of the Small
9207 -- For a source program literal for a decimal fixed-point type,
9208 -- this is statically illegal (RM 4.9(36)).
9210 if Is_Decimal_Fixed_Point_Type
(Typ
)
9211 and then Actual_Typ
= Universal_Real
9212 and then Comes_From_Source
(N
)
9214 Error_Msg_N
("value has extraneous low order digits", N
);
9217 -- Generate a warning if literal from source
9219 if Is_OK_Static_Expression
(N
)
9220 and then Warn_On_Bad_Fixed_Value
9223 ("?b?static fixed-point value is not a multiple of Small!",
9227 -- Replace literal by a value that is the exact representation
9228 -- of a value of the type, i.e. a multiple of the small value,
9229 -- by truncation, since Machine_Rounds is false for all GNAT
9230 -- fixed-point types (RM 4.9(38)).
9232 Stat
:= Is_OK_Static_Expression
(N
);
9234 Make_Real_Literal
(Sloc
(N
),
9235 Realval
=> Small_Value
(Typ
) * Cint
));
9237 Set_Is_Static_Expression
(N
, Stat
);
9240 -- In all cases, set the corresponding integer field
9242 Set_Corresponding_Integer_Value
(N
, Cint
);
9246 -- Now replace the actual type by the expected type as usual
9249 Eval_Real_Literal
(N
);
9250 end Resolve_Real_Literal
;
9252 -----------------------
9253 -- Resolve_Reference --
9254 -----------------------
9256 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
9257 P
: constant Node_Id
:= Prefix
(N
);
9260 -- Replace general access with specific type
9262 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
9263 Set_Etype
(N
, Base_Type
(Typ
));
9266 Resolve
(P
, Designated_Type
(Etype
(N
)));
9268 -- If we are taking the reference of a volatile entity, then treat it as
9269 -- a potential modification of this entity. This is too conservative,
9270 -- but necessary because remove side effects can cause transformations
9271 -- of normal assignments into reference sequences that otherwise fail to
9272 -- notice the modification.
9274 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
9275 Note_Possible_Modification
(P
, Sure
=> False);
9277 end Resolve_Reference
;
9279 --------------------------------
9280 -- Resolve_Selected_Component --
9281 --------------------------------
9283 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
9285 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
9286 P
: constant Node_Id
:= Prefix
(N
);
9287 S
: constant Node_Id
:= Selector_Name
(N
);
9288 T
: Entity_Id
:= Etype
(P
);
9290 I1
: Interp_Index
:= 0; -- prevent junk warning
9295 function Init_Component
return Boolean;
9296 -- Check whether this is the initialization of a component within an
9297 -- init proc (by assignment or call to another init proc). If true,
9298 -- there is no need for a discriminant check.
9300 --------------------
9301 -- Init_Component --
9302 --------------------
9304 function Init_Component
return Boolean is
9306 return Inside_Init_Proc
9307 and then Nkind
(Prefix
(N
)) = N_Identifier
9308 and then Chars
(Prefix
(N
)) = Name_uInit
9309 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
9312 -- Start of processing for Resolve_Selected_Component
9315 if Is_Overloaded
(P
) then
9317 -- Use the context type to select the prefix that has a selector
9318 -- of the correct name and type.
9321 Get_First_Interp
(P
, I
, It
);
9323 Search
: while Present
(It
.Typ
) loop
9324 if Is_Access_Type
(It
.Typ
) then
9325 T
:= Designated_Type
(It
.Typ
);
9330 -- Locate selected component. For a private prefix the selector
9331 -- can denote a discriminant.
9333 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
9335 -- The visible components of a class-wide type are those of
9338 if Is_Class_Wide_Type
(T
) then
9342 Comp
:= First_Entity
(T
);
9343 while Present
(Comp
) loop
9344 if Chars
(Comp
) = Chars
(S
)
9345 and then Covers
(Typ
, Etype
(Comp
))
9354 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9356 if It
= No_Interp
then
9358 ("ambiguous prefix for selected component", N
);
9365 -- There may be an implicit dereference. Retrieve
9366 -- designated record type.
9368 if Is_Access_Type
(It1
.Typ
) then
9369 T
:= Designated_Type
(It1
.Typ
);
9374 if Scope
(Comp1
) /= T
then
9376 -- Resolution chooses the new interpretation.
9377 -- Find the component with the right name.
9379 Comp1
:= First_Entity
(T
);
9380 while Present
(Comp1
)
9381 and then Chars
(Comp1
) /= Chars
(S
)
9383 Comp1
:= Next_Entity
(Comp1
);
9392 Comp
:= Next_Entity
(Comp
);
9396 Get_Next_Interp
(I
, It
);
9399 -- There must be a legal interpretation at this point
9401 pragma Assert
(Found
);
9402 Resolve
(P
, It1
.Typ
);
9404 Set_Entity_With_Checks
(S
, Comp1
);
9407 -- Resolve prefix with its type
9412 -- Generate cross-reference. We needed to wait until full overloading
9413 -- resolution was complete to do this, since otherwise we can't tell if
9414 -- we are an lvalue or not.
9416 if May_Be_Lvalue
(N
) then
9417 Generate_Reference
(Entity
(S
), S
, 'm');
9419 Generate_Reference
(Entity
(S
), S
, 'r');
9422 -- If prefix is an access type, the node will be transformed into an
9423 -- explicit dereference during expansion. The type of the node is the
9424 -- designated type of that of the prefix.
9426 if Is_Access_Type
(Etype
(P
)) then
9427 T
:= Designated_Type
(Etype
(P
));
9428 Check_Fully_Declared_Prefix
(T
, P
);
9433 -- Set flag for expander if discriminant check required
9435 if Has_Discriminants
(T
)
9436 and then Ekind_In
(Entity
(S
), E_Component
, E_Discriminant
)
9437 and then Present
(Original_Record_Component
(Entity
(S
)))
9438 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
9439 and then not Discriminant_Checks_Suppressed
(T
)
9440 and then not Init_Component
9442 Set_Do_Discriminant_Check
(N
);
9445 if Ekind
(Entity
(S
)) = E_Void
then
9446 Error_Msg_N
("premature use of component", S
);
9449 -- If the prefix is a record conversion, this may be a renamed
9450 -- discriminant whose bounds differ from those of the original
9451 -- one, so we must ensure that a range check is performed.
9453 if Nkind
(P
) = N_Type_Conversion
9454 and then Ekind
(Entity
(S
)) = E_Discriminant
9455 and then Is_Discrete_Type
(Typ
)
9457 Set_Etype
(N
, Base_Type
(Typ
));
9460 -- Note: No Eval processing is required, because the prefix is of a
9461 -- record type, or protected type, and neither can possibly be static.
9463 -- If the array type is atomic, and is packed, and we are in a left side
9464 -- context, then this is worth a warning, since we have a situation
9465 -- where the access to the component may cause extra read/writes of the
9466 -- atomic array object, which could be considered unexpected.
9468 if Nkind
(N
) = N_Selected_Component
9469 and then (Is_Atomic
(T
)
9470 or else (Is_Entity_Name
(Prefix
(N
))
9471 and then Is_Atomic
(Entity
(Prefix
(N
)))))
9472 and then Is_Packed
(T
)
9473 and then Is_LHS
(N
) = Yes
9476 ("??assignment to component of packed atomic record", Prefix
(N
));
9478 ("\??may cause unexpected accesses to atomic object", Prefix
(N
));
9481 Analyze_Dimension
(N
);
9482 end Resolve_Selected_Component
;
9488 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
9489 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9490 L
: constant Node_Id
:= Left_Opnd
(N
);
9491 R
: constant Node_Id
:= Right_Opnd
(N
);
9494 -- We do the resolution using the base type, because intermediate values
9495 -- in expressions always are of the base type, not a subtype of it.
9498 Resolve
(R
, Standard_Natural
);
9500 Check_Unset_Reference
(L
);
9501 Check_Unset_Reference
(R
);
9503 Set_Etype
(N
, B_Typ
);
9504 Generate_Operator_Reference
(N
, B_Typ
);
9508 ---------------------------
9509 -- Resolve_Short_Circuit --
9510 ---------------------------
9512 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
9513 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9514 L
: constant Node_Id
:= Left_Opnd
(N
);
9515 R
: constant Node_Id
:= Right_Opnd
(N
);
9518 -- Ensure all actions associated with the left operand (e.g.
9519 -- finalization of transient controlled objects) are fully evaluated
9520 -- locally within an expression with actions. This is particularly
9521 -- helpful for coverage analysis. However this should not happen in
9524 if Expander_Active
then
9526 Reloc_L
: constant Node_Id
:= Relocate_Node
(L
);
9528 Save_Interps
(Old_N
=> L
, New_N
=> Reloc_L
);
9531 Make_Expression_With_Actions
(Sloc
(L
),
9532 Actions
=> New_List
,
9533 Expression
=> Reloc_L
));
9535 -- Set Comes_From_Source on L to preserve warnings for unset
9538 Set_Comes_From_Source
(L
, Comes_From_Source
(Reloc_L
));
9545 -- Check for issuing warning for always False assert/check, this happens
9546 -- when assertions are turned off, in which case the pragma Assert/Check
9547 -- was transformed into:
9549 -- if False and then <condition> then ...
9551 -- and we detect this pattern
9553 if Warn_On_Assertion_Failure
9554 and then Is_Entity_Name
(R
)
9555 and then Entity
(R
) = Standard_False
9556 and then Nkind
(Parent
(N
)) = N_If_Statement
9557 and then Nkind
(N
) = N_And_Then
9558 and then Is_Entity_Name
(L
)
9559 and then Entity
(L
) = Standard_False
9562 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
9565 -- Special handling of Asssert pragma
9567 if Nkind
(Orig
) = N_Pragma
9568 and then Pragma_Name
(Orig
) = Name_Assert
9571 Expr
: constant Node_Id
:=
9574 (First
(Pragma_Argument_Associations
(Orig
))));
9577 -- Don't warn if original condition is explicit False,
9578 -- since obviously the failure is expected in this case.
9580 if Is_Entity_Name
(Expr
)
9581 and then Entity
(Expr
) = Standard_False
9585 -- Issue warning. We do not want the deletion of the
9586 -- IF/AND-THEN to take this message with it. We achieve this
9587 -- by making sure that the expanded code points to the Sloc
9588 -- of the expression, not the original pragma.
9591 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
9592 -- The source location of the expression is not usually
9593 -- the best choice here. For example, it gets located on
9594 -- the last AND keyword in a chain of boolean expressiond
9595 -- AND'ed together. It is best to put the message on the
9596 -- first character of the assertion, which is the effect
9597 -- of the First_Node call here.
9600 ("?A?assertion would fail at run time!",
9602 (First
(Pragma_Argument_Associations
(Orig
))));
9606 -- Similar processing for Check pragma
9608 elsif Nkind
(Orig
) = N_Pragma
9609 and then Pragma_Name
(Orig
) = Name_Check
9611 -- Don't want to warn if original condition is explicit False
9614 Expr
: constant Node_Id
:=
9617 (Next
(First
(Pragma_Argument_Associations
(Orig
)))));
9619 if Is_Entity_Name
(Expr
)
9620 and then Entity
(Expr
) = Standard_False
9627 -- Again use Error_Msg_F rather than Error_Msg_N, see
9628 -- comment above for an explanation of why we do this.
9631 ("?A?check would fail at run time!",
9633 (Last
(Pragma_Argument_Associations
(Orig
))));
9640 -- Continue with processing of short circuit
9642 Check_Unset_Reference
(L
);
9643 Check_Unset_Reference
(R
);
9645 Set_Etype
(N
, B_Typ
);
9646 Eval_Short_Circuit
(N
);
9647 end Resolve_Short_Circuit
;
9653 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
9654 Drange
: constant Node_Id
:= Discrete_Range
(N
);
9655 Name
: constant Node_Id
:= Prefix
(N
);
9656 Array_Type
: Entity_Id
:= Empty
;
9657 Dexpr
: Node_Id
:= Empty
;
9658 Index_Type
: Entity_Id
;
9661 if Is_Overloaded
(Name
) then
9663 -- Use the context type to select the prefix that yields the correct
9668 I1
: Interp_Index
:= 0;
9670 P
: constant Node_Id
:= Prefix
(N
);
9671 Found
: Boolean := False;
9674 Get_First_Interp
(P
, I
, It
);
9675 while Present
(It
.Typ
) loop
9676 if (Is_Array_Type
(It
.Typ
)
9677 and then Covers
(Typ
, It
.Typ
))
9678 or else (Is_Access_Type
(It
.Typ
)
9679 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
9680 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
9683 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9685 if It
= No_Interp
then
9686 Error_Msg_N
("ambiguous prefix for slicing", N
);
9691 Array_Type
:= It
.Typ
;
9696 Array_Type
:= It
.Typ
;
9701 Get_Next_Interp
(I
, It
);
9706 Array_Type
:= Etype
(Name
);
9709 Resolve
(Name
, Array_Type
);
9711 if Is_Access_Type
(Array_Type
) then
9712 Apply_Access_Check
(N
);
9713 Array_Type
:= Designated_Type
(Array_Type
);
9715 -- If the prefix is an access to an unconstrained array, we must use
9716 -- the actual subtype of the object to perform the index checks. The
9717 -- object denoted by the prefix is implicit in the node, so we build
9718 -- an explicit representation for it in order to compute the actual
9721 if not Is_Constrained
(Array_Type
) then
9722 Remove_Side_Effects
(Prefix
(N
));
9725 Obj
: constant Node_Id
:=
9726 Make_Explicit_Dereference
(Sloc
(N
),
9727 Prefix
=> New_Copy_Tree
(Prefix
(N
)));
9729 Set_Etype
(Obj
, Array_Type
);
9730 Set_Parent
(Obj
, Parent
(N
));
9731 Array_Type
:= Get_Actual_Subtype
(Obj
);
9735 elsif Is_Entity_Name
(Name
)
9736 or else Nkind
(Name
) = N_Explicit_Dereference
9737 or else (Nkind
(Name
) = N_Function_Call
9738 and then not Is_Constrained
(Etype
(Name
)))
9740 Array_Type
:= Get_Actual_Subtype
(Name
);
9742 -- If the name is a selected component that depends on discriminants,
9743 -- build an actual subtype for it. This can happen only when the name
9744 -- itself is overloaded; otherwise the actual subtype is created when
9745 -- the selected component is analyzed.
9747 elsif Nkind
(Name
) = N_Selected_Component
9748 and then Full_Analysis
9749 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
9752 Act_Decl
: constant Node_Id
:=
9753 Build_Actual_Subtype_Of_Component
(Array_Type
, Name
);
9755 Insert_Action
(N
, Act_Decl
);
9756 Array_Type
:= Defining_Identifier
(Act_Decl
);
9759 -- Maybe this should just be "else", instead of checking for the
9760 -- specific case of slice??? This is needed for the case where the
9761 -- prefix is an Image attribute, which gets expanded to a slice, and so
9762 -- has a constrained subtype which we want to use for the slice range
9763 -- check applied below (the range check won't get done if the
9764 -- unconstrained subtype of the 'Image is used).
9766 elsif Nkind
(Name
) = N_Slice
then
9767 Array_Type
:= Etype
(Name
);
9770 -- Obtain the type of the array index
9772 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
9773 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
9775 Index_Type
:= Etype
(First_Index
(Array_Type
));
9778 -- If name was overloaded, set slice type correctly now
9780 Set_Etype
(N
, Array_Type
);
9782 -- Handle the generation of a range check that compares the array index
9783 -- against the discrete_range. The check is not applied to internally
9784 -- built nodes associated with the expansion of dispatch tables. Check
9785 -- that Ada.Tags has already been loaded to avoid extra dependencies on
9788 if Tagged_Type_Expansion
9789 and then RTU_Loaded
(Ada_Tags
)
9790 and then Nkind
(Prefix
(N
)) = N_Selected_Component
9791 and then Present
(Entity
(Selector_Name
(Prefix
(N
))))
9792 and then Entity
(Selector_Name
(Prefix
(N
))) =
9793 RTE_Record_Component
(RE_Prims_Ptr
)
9797 -- The discrete_range is specified by a subtype indication. Create a
9798 -- shallow copy and inherit the type, parent and source location from
9799 -- the discrete_range. This ensures that the range check is inserted
9800 -- relative to the slice and that the runtime exception points to the
9801 -- proper construct.
9803 elsif Is_Entity_Name
(Drange
) then
9804 Dexpr
:= New_Copy
(Scalar_Range
(Entity
(Drange
)));
9806 Set_Etype
(Dexpr
, Etype
(Drange
));
9807 Set_Parent
(Dexpr
, Parent
(Drange
));
9808 Set_Sloc
(Dexpr
, Sloc
(Drange
));
9810 -- The discrete_range is a regular range. Resolve the bounds and remove
9811 -- their side effects.
9814 Resolve
(Drange
, Base_Type
(Index_Type
));
9816 if Nkind
(Drange
) = N_Range
then
9817 Force_Evaluation
(Low_Bound
(Drange
));
9818 Force_Evaluation
(High_Bound
(Drange
));
9824 if Present
(Dexpr
) then
9825 Apply_Range_Check
(Dexpr
, Index_Type
);
9828 Set_Slice_Subtype
(N
);
9830 -- Check bad use of type with predicates
9836 if Nkind
(Drange
) = N_Subtype_Indication
9837 and then Has_Predicates
(Entity
(Subtype_Mark
(Drange
)))
9839 Subt
:= Entity
(Subtype_Mark
(Drange
));
9841 Subt
:= Etype
(Drange
);
9844 if Has_Predicates
(Subt
) then
9845 Bad_Predicated_Subtype_Use
9846 ("subtype& has predicate, not allowed in slice", Drange
, Subt
);
9850 -- Otherwise here is where we check suspicious indexes
9852 if Nkind
(Drange
) = N_Range
then
9853 Warn_On_Suspicious_Index
(Name
, Low_Bound
(Drange
));
9854 Warn_On_Suspicious_Index
(Name
, High_Bound
(Drange
));
9857 Analyze_Dimension
(N
);
9861 ----------------------------
9862 -- Resolve_String_Literal --
9863 ----------------------------
9865 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9866 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
9867 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
9868 Loc
: constant Source_Ptr
:= Sloc
(N
);
9869 Str
: constant String_Id
:= Strval
(N
);
9870 Strlen
: constant Nat
:= String_Length
(Str
);
9871 Subtype_Id
: Entity_Id
;
9872 Need_Check
: Boolean;
9875 -- For a string appearing in a concatenation, defer creation of the
9876 -- string_literal_subtype until the end of the resolution of the
9877 -- concatenation, because the literal may be constant-folded away. This
9878 -- is a useful optimization for long concatenation expressions.
9880 -- If the string is an aggregate built for a single character (which
9881 -- happens in a non-static context) or a is null string to which special
9882 -- checks may apply, we build the subtype. Wide strings must also get a
9883 -- string subtype if they come from a one character aggregate. Strings
9884 -- generated by attributes might be static, but it is often hard to
9885 -- determine whether the enclosing context is static, so we generate
9886 -- subtypes for them as well, thus losing some rarer optimizations ???
9887 -- Same for strings that come from a static conversion.
9890 (Strlen
= 0 and then Typ
/= Standard_String
)
9891 or else Nkind
(Parent
(N
)) /= N_Op_Concat
9892 or else (N
/= Left_Opnd
(Parent
(N
))
9893 and then N
/= Right_Opnd
(Parent
(N
)))
9894 or else ((Typ
= Standard_Wide_String
9895 or else Typ
= Standard_Wide_Wide_String
)
9896 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
9898 -- If the resolving type is itself a string literal subtype, we can just
9899 -- reuse it, since there is no point in creating another.
9901 if Ekind
(Typ
) = E_String_Literal_Subtype
then
9904 elsif Nkind
(Parent
(N
)) = N_Op_Concat
9905 and then not Need_Check
9906 and then not Nkind_In
(Original_Node
(N
), N_Character_Literal
,
9907 N_Attribute_Reference
,
9908 N_Qualified_Expression
,
9913 -- Otherwise we must create a string literal subtype. Note that the
9914 -- whole idea of string literal subtypes is simply to avoid the need
9915 -- for building a full fledged array subtype for each literal.
9918 Set_String_Literal_Subtype
(N
, Typ
);
9919 Subtype_Id
:= Etype
(N
);
9922 if Nkind
(Parent
(N
)) /= N_Op_Concat
9925 Set_Etype
(N
, Subtype_Id
);
9926 Eval_String_Literal
(N
);
9929 if Is_Limited_Composite
(Typ
)
9930 or else Is_Private_Composite
(Typ
)
9932 Error_Msg_N
("string literal not available for private array", N
);
9933 Set_Etype
(N
, Any_Type
);
9937 -- The validity of a null string has been checked in the call to
9938 -- Eval_String_Literal.
9943 -- Always accept string literal with component type Any_Character, which
9944 -- occurs in error situations and in comparisons of literals, both of
9945 -- which should accept all literals.
9947 elsif R_Typ
= Any_Character
then
9950 -- If the type is bit-packed, then we always transform the string
9951 -- literal into a full fledged aggregate.
9953 elsif Is_Bit_Packed_Array
(Typ
) then
9956 -- Deal with cases of Wide_Wide_String, Wide_String, and String
9959 -- For Standard.Wide_Wide_String, or any other type whose component
9960 -- type is Standard.Wide_Wide_Character, we know that all the
9961 -- characters in the string must be acceptable, since the parser
9962 -- accepted the characters as valid character literals.
9964 if R_Typ
= Standard_Wide_Wide_Character
then
9967 -- For the case of Standard.String, or any other type whose component
9968 -- type is Standard.Character, we must make sure that there are no
9969 -- wide characters in the string, i.e. that it is entirely composed
9970 -- of characters in range of type Character.
9972 -- If the string literal is the result of a static concatenation, the
9973 -- test has already been performed on the components, and need not be
9976 elsif R_Typ
= Standard_Character
9977 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
9979 for J
in 1 .. Strlen
loop
9980 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
9982 -- If we are out of range, post error. This is one of the
9983 -- very few places that we place the flag in the middle of
9984 -- a token, right under the offending wide character. Not
9985 -- quite clear if this is right wrt wide character encoding
9986 -- sequences, but it's only an error message.
9989 ("literal out of range of type Standard.Character",
9990 Source_Ptr
(Int
(Loc
) + J
));
9995 -- For the case of Standard.Wide_String, or any other type whose
9996 -- component type is Standard.Wide_Character, we must make sure that
9997 -- there are no wide characters in the string, i.e. that it is
9998 -- entirely composed of characters in range of type Wide_Character.
10000 -- If the string literal is the result of a static concatenation,
10001 -- the test has already been performed on the components, and need
10002 -- not be repeated.
10004 elsif R_Typ
= Standard_Wide_Character
10005 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
10007 for J
in 1 .. Strlen
loop
10008 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
10010 -- If we are out of range, post error. This is one of the
10011 -- very few places that we place the flag in the middle of
10012 -- a token, right under the offending wide character.
10014 -- This is not quite right, because characters in general
10015 -- will take more than one character position ???
10018 ("literal out of range of type Standard.Wide_Character",
10019 Source_Ptr
(Int
(Loc
) + J
));
10024 -- If the root type is not a standard character, then we will convert
10025 -- the string into an aggregate and will let the aggregate code do
10026 -- the checking. Standard Wide_Wide_Character is also OK here.
10032 -- See if the component type of the array corresponding to the string
10033 -- has compile time known bounds. If yes we can directly check
10034 -- whether the evaluation of the string will raise constraint error.
10035 -- Otherwise we need to transform the string literal into the
10036 -- corresponding character aggregate and let the aggregate code do
10039 if Is_Standard_Character_Type
(R_Typ
) then
10041 -- Check for the case of full range, where we are definitely OK
10043 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
10047 -- Here the range is not the complete base type range, so check
10050 Comp_Typ_Lo
: constant Node_Id
:=
10051 Type_Low_Bound
(Component_Type
(Typ
));
10052 Comp_Typ_Hi
: constant Node_Id
:=
10053 Type_High_Bound
(Component_Type
(Typ
));
10058 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
10059 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
10061 for J
in 1 .. Strlen
loop
10062 Char_Val
:= UI_From_Int
(Int
(Get_String_Char
(Str
, J
)));
10064 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
10065 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
10067 Apply_Compile_Time_Constraint_Error
10068 (N
, "character out of range??",
10069 CE_Range_Check_Failed
,
10070 Loc
=> Source_Ptr
(Int
(Loc
) + J
));
10080 -- If we got here we meed to transform the string literal into the
10081 -- equivalent qualified positional array aggregate. This is rather
10082 -- heavy artillery for this situation, but it is hard work to avoid.
10085 Lits
: constant List_Id
:= New_List
;
10086 P
: Source_Ptr
:= Loc
+ 1;
10090 -- Build the character literals, we give them source locations that
10091 -- correspond to the string positions, which is a bit tricky given
10092 -- the possible presence of wide character escape sequences.
10094 for J
in 1 .. Strlen
loop
10095 C
:= Get_String_Char
(Str
, J
);
10096 Set_Character_Literal_Name
(C
);
10099 Make_Character_Literal
(P
,
10100 Chars
=> Name_Find
,
10101 Char_Literal_Value
=> UI_From_CC
(C
)));
10103 if In_Character_Range
(C
) then
10106 -- Should we have a call to Skip_Wide here ???
10115 Make_Qualified_Expression
(Loc
,
10116 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
10118 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
10120 Analyze_And_Resolve
(N
, Typ
);
10122 end Resolve_String_Literal
;
10124 -----------------------------
10125 -- Resolve_Type_Conversion --
10126 -----------------------------
10128 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
10129 Conv_OK
: constant Boolean := Conversion_OK
(N
);
10130 Operand
: constant Node_Id
:= Expression
(N
);
10131 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
10132 Target_Typ
: constant Entity_Id
:= Etype
(N
);
10137 Test_Redundant
: Boolean := Warn_On_Redundant_Constructs
;
10138 -- Set to False to suppress cases where we want to suppress the test
10139 -- for redundancy to avoid possible false positives on this warning.
10143 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
10148 -- If the Operand Etype is Universal_Fixed, then the conversion is
10149 -- never redundant. We need this check because by the time we have
10150 -- finished the rather complex transformation, the conversion looks
10151 -- redundant when it is not.
10153 if Operand_Typ
= Universal_Fixed
then
10154 Test_Redundant
:= False;
10156 -- If the operand is marked as Any_Fixed, then special processing is
10157 -- required. This is also a case where we suppress the test for a
10158 -- redundant conversion, since most certainly it is not redundant.
10160 elsif Operand_Typ
= Any_Fixed
then
10161 Test_Redundant
:= False;
10163 -- Mixed-mode operation involving a literal. Context must be a fixed
10164 -- type which is applied to the literal subsequently.
10166 if Is_Fixed_Point_Type
(Typ
) then
10167 Set_Etype
(Operand
, Universal_Real
);
10169 elsif Is_Numeric_Type
(Typ
)
10170 and then Nkind_In
(Operand
, N_Op_Multiply
, N_Op_Divide
)
10171 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
10173 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
10175 -- Return if expression is ambiguous
10177 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
10180 -- If nothing else, the available fixed type is Duration
10183 Set_Etype
(Operand
, Standard_Duration
);
10186 -- Resolve the real operand with largest available precision
10188 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
10189 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
10191 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
10194 Resolve
(Rop
, Universal_Real
);
10196 -- If the operand is a literal (it could be a non-static and
10197 -- illegal exponentiation) check whether the use of Duration
10198 -- is potentially inaccurate.
10200 if Nkind
(Rop
) = N_Real_Literal
10201 and then Realval
(Rop
) /= Ureal_0
10202 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
10205 ("??universal real operand can only "
10206 & "be interpreted as Duration!", Rop
);
10208 ("\??precision will be lost in the conversion!", Rop
);
10211 elsif Is_Numeric_Type
(Typ
)
10212 and then Nkind
(Operand
) in N_Op
10213 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
10215 Set_Etype
(Operand
, Standard_Duration
);
10218 Error_Msg_N
("invalid context for mixed mode operation", N
);
10219 Set_Etype
(Operand
, Any_Type
);
10226 -- In SPARK, a type conversion between array types should be restricted
10227 -- to types which have matching static bounds.
10229 -- Protect call to Matching_Static_Array_Bounds to avoid costly
10230 -- operation if not needed.
10232 if Restriction_Check_Required
(SPARK_05
)
10233 and then Is_Array_Type
(Target_Typ
)
10234 and then Is_Array_Type
(Operand_Typ
)
10235 and then Operand_Typ
/= Any_Composite
-- or else Operand in error
10236 and then not Matching_Static_Array_Bounds
(Target_Typ
, Operand_Typ
)
10238 Check_SPARK_Restriction
10239 ("array types should have matching static bounds", N
);
10242 -- In formal mode, the operand of an ancestor type conversion must be an
10243 -- object (not an expression).
10245 if Is_Tagged_Type
(Target_Typ
)
10246 and then not Is_Class_Wide_Type
(Target_Typ
)
10247 and then Is_Tagged_Type
(Operand_Typ
)
10248 and then not Is_Class_Wide_Type
(Operand_Typ
)
10249 and then Is_Ancestor
(Target_Typ
, Operand_Typ
)
10250 and then not Is_SPARK_Object_Reference
(Operand
)
10252 Check_SPARK_Restriction
("object required", Operand
);
10255 Analyze_Dimension
(N
);
10257 -- Note: we do the Eval_Type_Conversion call before applying the
10258 -- required checks for a subtype conversion. This is important, since
10259 -- both are prepared under certain circumstances to change the type
10260 -- conversion to a constraint error node, but in the case of
10261 -- Eval_Type_Conversion this may reflect an illegality in the static
10262 -- case, and we would miss the illegality (getting only a warning
10263 -- message), if we applied the type conversion checks first.
10265 Eval_Type_Conversion
(N
);
10267 -- Even when evaluation is not possible, we may be able to simplify the
10268 -- conversion or its expression. This needs to be done before applying
10269 -- checks, since otherwise the checks may use the original expression
10270 -- and defeat the simplifications. This is specifically the case for
10271 -- elimination of the floating-point Truncation attribute in
10272 -- float-to-int conversions.
10274 Simplify_Type_Conversion
(N
);
10276 -- If after evaluation we still have a type conversion, then we may need
10277 -- to apply checks required for a subtype conversion.
10279 -- Skip these type conversion checks if universal fixed operands
10280 -- operands involved, since range checks are handled separately for
10281 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
10283 if Nkind
(N
) = N_Type_Conversion
10284 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
10285 and then Target_Typ
/= Universal_Fixed
10286 and then Operand_Typ
/= Universal_Fixed
10288 Apply_Type_Conversion_Checks
(N
);
10291 -- Issue warning for conversion of simple object to its own type. We
10292 -- have to test the original nodes, since they may have been rewritten
10293 -- by various optimizations.
10295 Orig_N
:= Original_Node
(N
);
10297 -- Here we test for a redundant conversion if the warning mode is
10298 -- active (and was not locally reset), and we have a type conversion
10299 -- from source not appearing in a generic instance.
10302 and then Nkind
(Orig_N
) = N_Type_Conversion
10303 and then Comes_From_Source
(Orig_N
)
10304 and then not In_Instance
10306 Orig_N
:= Original_Node
(Expression
(Orig_N
));
10307 Orig_T
:= Target_Typ
;
10309 -- If the node is part of a larger expression, the Target_Type
10310 -- may not be the original type of the node if the context is a
10311 -- condition. Recover original type to see if conversion is needed.
10313 if Is_Boolean_Type
(Orig_T
)
10314 and then Nkind
(Parent
(N
)) in N_Op
10316 Orig_T
:= Etype
(Parent
(N
));
10319 -- If we have an entity name, then give the warning if the entity
10320 -- is the right type, or if it is a loop parameter covered by the
10321 -- original type (that's needed because loop parameters have an
10322 -- odd subtype coming from the bounds).
10324 if (Is_Entity_Name
(Orig_N
)
10326 (Etype
(Entity
(Orig_N
)) = Orig_T
10328 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
10329 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
))))))
10331 -- If not an entity, then type of expression must match
10333 or else Etype
(Orig_N
) = Orig_T
10335 -- One more check, do not give warning if the analyzed conversion
10336 -- has an expression with non-static bounds, and the bounds of the
10337 -- target are static. This avoids junk warnings in cases where the
10338 -- conversion is necessary to establish staticness, for example in
10339 -- a case statement.
10341 if not Is_OK_Static_Subtype
(Operand_Typ
)
10342 and then Is_OK_Static_Subtype
(Target_Typ
)
10346 -- Finally, if this type conversion occurs in a context requiring
10347 -- a prefix, and the expression is a qualified expression then the
10348 -- type conversion is not redundant, since a qualified expression
10349 -- is not a prefix, whereas a type conversion is. For example, "X
10350 -- := T'(Funx(...)).Y;" is illegal because a selected component
10351 -- requires a prefix, but a type conversion makes it legal: "X :=
10352 -- T(T'(Funx(...))).Y;"
10354 -- In Ada 2012, a qualified expression is a name, so this idiom is
10355 -- no longer needed, but we still suppress the warning because it
10356 -- seems unfriendly for warnings to pop up when you switch to the
10357 -- newer language version.
10359 elsif Nkind
(Orig_N
) = N_Qualified_Expression
10360 and then Nkind_In
(Parent
(N
), N_Attribute_Reference
,
10361 N_Indexed_Component
,
10362 N_Selected_Component
,
10364 N_Explicit_Dereference
)
10368 -- Never warn on conversion to Long_Long_Integer'Base since
10369 -- that is most likely an artifact of the extended overflow
10370 -- checking and comes from complex expanded code.
10372 elsif Orig_T
= Base_Type
(Standard_Long_Long_Integer
) then
10375 -- Here we give the redundant conversion warning. If it is an
10376 -- entity, give the name of the entity in the message. If not,
10377 -- just mention the expression.
10379 -- Shoudn't we test Warn_On_Redundant_Constructs here ???
10382 if Is_Entity_Name
(Orig_N
) then
10383 Error_Msg_Node_2
:= Orig_T
;
10384 Error_Msg_NE
-- CODEFIX
10385 ("??redundant conversion, & is of type &!",
10386 N
, Entity
(Orig_N
));
10389 ("??redundant conversion, expression is of type&!",
10396 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
10397 -- No need to perform any interface conversion if the type of the
10398 -- expression coincides with the target type.
10400 if Ada_Version
>= Ada_2005
10401 and then Expander_Active
10402 and then Operand_Typ
/= Target_Typ
10405 Opnd
: Entity_Id
:= Operand_Typ
;
10406 Target
: Entity_Id
:= Target_Typ
;
10409 -- If the type of the operand is a limited view, use the non-
10410 -- limited view when available.
10412 if From_Limited_With
(Opnd
)
10413 and then Ekind
(Opnd
) in Incomplete_Kind
10414 and then Present
(Non_Limited_View
(Opnd
))
10416 Opnd
:= Non_Limited_View
(Opnd
);
10417 Set_Etype
(Expression
(N
), Opnd
);
10420 if Is_Access_Type
(Opnd
) then
10421 Opnd
:= Designated_Type
(Opnd
);
10424 if Is_Access_Type
(Target_Typ
) then
10425 Target
:= Designated_Type
(Target
);
10428 if Opnd
= Target
then
10431 -- Conversion from interface type
10433 elsif Is_Interface
(Opnd
) then
10435 -- Ada 2005 (AI-217): Handle entities from limited views
10437 if From_Limited_With
(Opnd
) then
10438 Error_Msg_Qual_Level
:= 99;
10439 Error_Msg_NE
-- CODEFIX
10440 ("missing WITH clause on package &", N
,
10441 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
10443 ("type conversions require visibility of the full view",
10446 elsif From_Limited_With
(Target
)
10448 (Is_Access_Type
(Target_Typ
)
10449 and then Present
(Non_Limited_View
(Etype
(Target
))))
10451 Error_Msg_Qual_Level
:= 99;
10452 Error_Msg_NE
-- CODEFIX
10453 ("missing WITH clause on package &", N
,
10454 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
10456 ("type conversions require visibility of the full view",
10460 Expand_Interface_Conversion
(N
);
10463 -- Conversion to interface type
10465 elsif Is_Interface
(Target
) then
10469 if Ekind_In
(Opnd
, E_Protected_Subtype
, E_Task_Subtype
) then
10470 Opnd
:= Etype
(Opnd
);
10473 if Is_Class_Wide_Type
(Opnd
)
10474 or else Interface_Present_In_Ancestor
10478 Expand_Interface_Conversion
(N
);
10480 Error_Msg_Name_1
:= Chars
(Etype
(Target
));
10481 Error_Msg_Name_2
:= Chars
(Opnd
);
10483 ("wrong interface conversion (% is not a progenitor "
10490 -- Ada 2012: if target type has predicates, the result requires a
10491 -- predicate check. If the context is a call to another predicate
10492 -- check we must prevent infinite recursion.
10494 if Has_Predicates
(Target_Typ
) then
10495 if Nkind
(Parent
(N
)) = N_Function_Call
10496 and then Present
(Name
(Parent
(N
)))
10497 and then (Is_Predicate_Function
(Entity
(Name
(Parent
(N
))))
10499 Is_Predicate_Function_M
(Entity
(Name
(Parent
(N
)))))
10504 Apply_Predicate_Check
(N
, Target_Typ
);
10507 end Resolve_Type_Conversion
;
10509 ----------------------
10510 -- Resolve_Unary_Op --
10511 ----------------------
10513 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
10514 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10515 R
: constant Node_Id
:= Right_Opnd
(N
);
10521 if Is_Modular_Integer_Type
(Typ
) and then Nkind
(N
) /= N_Op_Not
then
10522 Error_Msg_Name_1
:= Chars
(Typ
);
10523 Check_SPARK_Restriction
10524 ("unary operator not defined for modular type%", N
);
10527 -- Deal with intrinsic unary operators
10529 if Comes_From_Source
(N
)
10530 and then Ekind
(Entity
(N
)) = E_Function
10531 and then Is_Imported
(Entity
(N
))
10532 and then Is_Intrinsic_Subprogram
(Entity
(N
))
10534 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10538 -- Deal with universal cases
10540 if Etype
(R
) = Universal_Integer
10542 Etype
(R
) = Universal_Real
10544 Check_For_Visible_Operator
(N
, B_Typ
);
10547 Set_Etype
(N
, B_Typ
);
10548 Resolve
(R
, B_Typ
);
10550 -- Generate warning for expressions like abs (x mod 2)
10552 if Warn_On_Redundant_Constructs
10553 and then Nkind
(N
) = N_Op_Abs
10555 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
10557 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
10558 Error_Msg_N
-- CODEFIX
10559 ("?r?abs applied to known non-negative value has no effect", N
);
10563 -- Deal with reference generation
10565 Check_Unset_Reference
(R
);
10566 Generate_Operator_Reference
(N
, B_Typ
);
10567 Analyze_Dimension
(N
);
10570 -- Set overflow checking bit. Much cleverer code needed here eventually
10571 -- and perhaps the Resolve routines should be separated for the various
10572 -- arithmetic operations, since they will need different processing ???
10574 if Nkind
(N
) in N_Op
then
10575 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
10576 Enable_Overflow_Check
(N
);
10580 -- Generate warning for expressions like -5 mod 3 for integers. No need
10581 -- to worry in the floating-point case, since parens do not affect the
10582 -- result so there is no point in giving in a warning.
10585 Norig
: constant Node_Id
:= Original_Node
(N
);
10594 if Warn_On_Questionable_Missing_Parens
10595 and then Comes_From_Source
(Norig
)
10596 and then Is_Integer_Type
(Typ
)
10597 and then Nkind
(Norig
) = N_Op_Minus
10599 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
10601 -- We are looking for cases where the right operand is not
10602 -- parenthesized, and is a binary operator, multiply, divide, or
10603 -- mod. These are the cases where the grouping can affect results.
10605 if Paren_Count
(Rorig
) = 0
10606 and then Nkind_In
(Rorig
, N_Op_Mod
, N_Op_Multiply
, N_Op_Divide
)
10608 -- For mod, we always give the warning, since the value is
10609 -- affected by the parenthesization (e.g. (-5) mod 315 /=
10610 -- -(5 mod 315)). But for the other cases, the only concern is
10611 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
10612 -- overflows, but (-2) * 64 does not). So we try to give the
10613 -- message only when overflow is possible.
10615 if Nkind
(Rorig
) /= N_Op_Mod
10616 and then Compile_Time_Known_Value
(R
)
10618 Val
:= Expr_Value
(R
);
10620 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
10621 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
10623 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
10626 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
10627 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
10629 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
10632 -- Note that the test below is deliberately excluding the
10633 -- largest negative number, since that is a potentially
10634 -- troublesome case (e.g. -2 * x, where the result is the
10635 -- largest negative integer has an overflow with 2 * x).
10637 if Val
> LB
and then Val
<= HB
then
10642 -- For the multiplication case, the only case we have to worry
10643 -- about is when (-a)*b is exactly the largest negative number
10644 -- so that -(a*b) can cause overflow. This can only happen if
10645 -- a is a power of 2, and more generally if any operand is a
10646 -- constant that is not a power of 2, then the parentheses
10647 -- cannot affect whether overflow occurs. We only bother to
10648 -- test the left most operand
10650 -- Loop looking at left operands for one that has known value
10653 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
10654 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
10655 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
10657 -- Operand value of 0 or 1 skips warning
10662 -- Otherwise check power of 2, if power of 2, warn, if
10663 -- anything else, skip warning.
10666 while Lval
/= 2 loop
10667 if Lval
mod 2 = 1 then
10678 -- Keep looking at left operands
10680 Opnd
:= Left_Opnd
(Opnd
);
10681 end loop Opnd_Loop
;
10683 -- For rem or "/" we can only have a problematic situation
10684 -- if the divisor has a value of minus one or one. Otherwise
10685 -- overflow is impossible (divisor > 1) or we have a case of
10686 -- division by zero in any case.
10688 if Nkind_In
(Rorig
, N_Op_Divide
, N_Op_Rem
)
10689 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
10690 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
10695 -- If we fall through warning should be issued
10697 -- Shouldn't we test Warn_On_Questionable_Missing_Parens ???
10700 ("??unary minus expression should be parenthesized here!", N
);
10704 end Resolve_Unary_Op
;
10706 ----------------------------------
10707 -- Resolve_Unchecked_Expression --
10708 ----------------------------------
10710 procedure Resolve_Unchecked_Expression
10715 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
10716 Set_Etype
(N
, Typ
);
10717 end Resolve_Unchecked_Expression
;
10719 ---------------------------------------
10720 -- Resolve_Unchecked_Type_Conversion --
10721 ---------------------------------------
10723 procedure Resolve_Unchecked_Type_Conversion
10727 pragma Warnings
(Off
, Typ
);
10729 Operand
: constant Node_Id
:= Expression
(N
);
10730 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
10733 -- Resolve operand using its own type
10735 Resolve
(Operand
, Opnd_Type
);
10737 -- In an inlined context, the unchecked conversion may be applied
10738 -- to a literal, in which case its type is the type of the context.
10739 -- (In other contexts conversions cannot apply to literals).
10742 and then (Opnd_Type
= Any_Character
or else
10743 Opnd_Type
= Any_Integer
or else
10744 Opnd_Type
= Any_Real
)
10746 Set_Etype
(Operand
, Typ
);
10749 Analyze_Dimension
(N
);
10750 Eval_Unchecked_Conversion
(N
);
10751 end Resolve_Unchecked_Type_Conversion
;
10753 ------------------------------
10754 -- Rewrite_Operator_As_Call --
10755 ------------------------------
10757 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
10758 Loc
: constant Source_Ptr
:= Sloc
(N
);
10759 Actuals
: constant List_Id
:= New_List
;
10763 if Nkind
(N
) in N_Binary_Op
then
10764 Append
(Left_Opnd
(N
), Actuals
);
10767 Append
(Right_Opnd
(N
), Actuals
);
10770 Make_Function_Call
(Sloc
=> Loc
,
10771 Name
=> New_Occurrence_Of
(Nam
, Loc
),
10772 Parameter_Associations
=> Actuals
);
10774 Preserve_Comes_From_Source
(New_N
, N
);
10775 Preserve_Comes_From_Source
(Name
(New_N
), N
);
10776 Rewrite
(N
, New_N
);
10777 Set_Etype
(N
, Etype
(Nam
));
10778 end Rewrite_Operator_As_Call
;
10780 ------------------------------
10781 -- Rewrite_Renamed_Operator --
10782 ------------------------------
10784 procedure Rewrite_Renamed_Operator
10789 Nam
: constant Name_Id
:= Chars
(Op
);
10790 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
10794 -- Do not perform this transformation within a pre/postcondition,
10795 -- because the expression will be re-analyzed, and the transformation
10796 -- might affect the visibility of the operator, e.g. in an instance.
10798 if In_Assertion_Expr
> 0 then
10802 -- Rewrite the operator node using the real operator, not its renaming.
10803 -- Exclude user-defined intrinsic operations of the same name, which are
10804 -- treated separately and rewritten as calls.
10806 if Ekind
(Op
) /= E_Function
or else Chars
(N
) /= Nam
then
10807 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
10808 Set_Chars
(Op_Node
, Nam
);
10809 Set_Etype
(Op_Node
, Etype
(N
));
10810 Set_Entity
(Op_Node
, Op
);
10811 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
10813 -- Indicate that both the original entity and its renaming are
10814 -- referenced at this point.
10816 Generate_Reference
(Entity
(N
), N
);
10817 Generate_Reference
(Op
, N
);
10820 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
10823 Rewrite
(N
, Op_Node
);
10825 -- If the context type is private, add the appropriate conversions so
10826 -- that the operator is applied to the full view. This is done in the
10827 -- routines that resolve intrinsic operators.
10829 if Is_Intrinsic_Subprogram
(Op
)
10830 and then Is_Private_Type
(Typ
)
10833 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
10834 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
10835 Resolve_Intrinsic_Operator
(N
, Typ
);
10837 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
10838 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10845 elsif Ekind
(Op
) = E_Function
and then Is_Intrinsic_Subprogram
(Op
) then
10847 -- Operator renames a user-defined operator of the same name. Use the
10848 -- original operator in the node, which is the one Gigi knows about.
10850 Set_Entity
(N
, Op
);
10851 Set_Is_Overloaded
(N
, False);
10853 end Rewrite_Renamed_Operator
;
10855 -----------------------
10856 -- Set_Slice_Subtype --
10857 -----------------------
10859 -- Build an implicit subtype declaration to represent the type delivered by
10860 -- the slice. This is an abbreviated version of an array subtype. We define
10861 -- an index subtype for the slice, using either the subtype name or the
10862 -- discrete range of the slice. To be consistent with index usage elsewhere
10863 -- we create a list header to hold the single index. This list is not
10864 -- otherwise attached to the syntax tree.
10866 procedure Set_Slice_Subtype
(N
: Node_Id
) is
10867 Loc
: constant Source_Ptr
:= Sloc
(N
);
10868 Index_List
: constant List_Id
:= New_List
;
10870 Index_Subtype
: Entity_Id
;
10871 Index_Type
: Entity_Id
;
10872 Slice_Subtype
: Entity_Id
;
10873 Drange
: constant Node_Id
:= Discrete_Range
(N
);
10876 Index_Type
:= Base_Type
(Etype
(Drange
));
10878 if Is_Entity_Name
(Drange
) then
10879 Index_Subtype
:= Entity
(Drange
);
10882 -- We force the evaluation of a range. This is definitely needed in
10883 -- the renamed case, and seems safer to do unconditionally. Note in
10884 -- any case that since we will create and insert an Itype referring
10885 -- to this range, we must make sure any side effect removal actions
10886 -- are inserted before the Itype definition.
10888 if Nkind
(Drange
) = N_Range
then
10889 Force_Evaluation
(Low_Bound
(Drange
));
10890 Force_Evaluation
(High_Bound
(Drange
));
10892 -- If the discrete range is given by a subtype indication, the
10893 -- type of the slice is the base of the subtype mark.
10895 elsif Nkind
(Drange
) = N_Subtype_Indication
then
10897 R
: constant Node_Id
:= Range_Expression
(Constraint
(Drange
));
10899 Index_Type
:= Base_Type
(Entity
(Subtype_Mark
(Drange
)));
10900 Force_Evaluation
(Low_Bound
(R
));
10901 Force_Evaluation
(High_Bound
(R
));
10905 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
10907 -- Take a new copy of Drange (where bounds have been rewritten to
10908 -- reference side-effect-free names). Using a separate tree ensures
10909 -- that further expansion (e.g. while rewriting a slice assignment
10910 -- into a FOR loop) does not attempt to remove side effects on the
10911 -- bounds again (which would cause the bounds in the index subtype
10912 -- definition to refer to temporaries before they are defined) (the
10913 -- reason is that some names are considered side effect free here
10914 -- for the subtype, but not in the context of a loop iteration
10917 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
10918 Set_Parent
(Scalar_Range
(Index_Subtype
), Index_Subtype
);
10919 Set_Etype
(Index_Subtype
, Index_Type
);
10920 Set_Size_Info
(Index_Subtype
, Index_Type
);
10921 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
10924 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
10926 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
10927 Set_Etype
(Index
, Index_Subtype
);
10928 Append
(Index
, Index_List
);
10930 Set_First_Index
(Slice_Subtype
, Index
);
10931 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
10932 Set_Is_Constrained
(Slice_Subtype
, True);
10934 Check_Compile_Time_Size
(Slice_Subtype
);
10936 -- The Etype of the existing Slice node is reset to this slice subtype.
10937 -- Its bounds are obtained from its first index.
10939 Set_Etype
(N
, Slice_Subtype
);
10941 -- For packed slice subtypes, freeze immediately (except in the case of
10942 -- being in a "spec expression" where we never freeze when we first see
10943 -- the expression).
10945 if Is_Packed
(Slice_Subtype
) and not In_Spec_Expression
then
10946 Freeze_Itype
(Slice_Subtype
, N
);
10948 -- For all other cases insert an itype reference in the slice's actions
10949 -- so that the itype is frozen at the proper place in the tree (i.e. at
10950 -- the point where actions for the slice are analyzed). Note that this
10951 -- is different from freezing the itype immediately, which might be
10952 -- premature (e.g. if the slice is within a transient scope). This needs
10953 -- to be done only if expansion is enabled.
10955 elsif Expander_Active
then
10956 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
10958 end Set_Slice_Subtype
;
10960 --------------------------------
10961 -- Set_String_Literal_Subtype --
10962 --------------------------------
10964 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
10965 Loc
: constant Source_Ptr
:= Sloc
(N
);
10966 Low_Bound
: constant Node_Id
:=
10967 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
10968 Subtype_Id
: Entity_Id
;
10971 if Nkind
(N
) /= N_String_Literal
then
10975 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
10976 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
10977 (String_Length
(Strval
(N
))));
10978 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
10979 Set_Is_Constrained
(Subtype_Id
);
10980 Set_Etype
(N
, Subtype_Id
);
10982 -- The low bound is set from the low bound of the corresponding index
10983 -- type. Note that we do not store the high bound in the string literal
10984 -- subtype, but it can be deduced if necessary from the length and the
10987 if Is_OK_Static_Expression
(Low_Bound
) then
10988 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
10990 -- If the lower bound is not static we create a range for the string
10991 -- literal, using the index type and the known length of the literal.
10992 -- The index type is not necessarily Positive, so the upper bound is
10993 -- computed as T'Val (T'Pos (Low_Bound) + L - 1).
10997 Index_List
: constant List_Id
:= New_List
;
10998 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
10999 High_Bound
: constant Node_Id
:=
11000 Make_Attribute_Reference
(Loc
,
11001 Attribute_Name
=> Name_Val
,
11003 New_Occurrence_Of
(Index_Type
, Loc
),
11004 Expressions
=> New_List
(
11007 Make_Attribute_Reference
(Loc
,
11008 Attribute_Name
=> Name_Pos
,
11010 New_Occurrence_Of
(Index_Type
, Loc
),
11012 New_List
(New_Copy_Tree
(Low_Bound
))),
11014 Make_Integer_Literal
(Loc
,
11015 String_Length
(Strval
(N
)) - 1))));
11017 Array_Subtype
: Entity_Id
;
11020 Index_Subtype
: Entity_Id
;
11023 if Is_Integer_Type
(Index_Type
) then
11024 Set_String_Literal_Low_Bound
11025 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
11028 -- If the index type is an enumeration type, build bounds
11029 -- expression with attributes.
11031 Set_String_Literal_Low_Bound
11033 Make_Attribute_Reference
(Loc
,
11034 Attribute_Name
=> Name_First
,
11036 New_Occurrence_Of
(Base_Type
(Index_Type
), Loc
)));
11037 Set_Etype
(String_Literal_Low_Bound
(Subtype_Id
), Index_Type
);
11040 Analyze_And_Resolve
(String_Literal_Low_Bound
(Subtype_Id
));
11042 -- Build bona fide subtype for the string, and wrap it in an
11043 -- unchecked conversion, because the backend expects the
11044 -- String_Literal_Subtype to have a static lower bound.
11047 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
11048 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
11049 Set_Scalar_Range
(Index_Subtype
, Drange
);
11050 Set_Parent
(Drange
, N
);
11051 Analyze_And_Resolve
(Drange
, Index_Type
);
11053 -- In the context, the Index_Type may already have a constraint,
11054 -- so use common base type on string subtype. The base type may
11055 -- be used when generating attributes of the string, for example
11056 -- in the context of a slice assignment.
11058 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
11059 Set_Size_Info
(Index_Subtype
, Index_Type
);
11060 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
11062 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
11064 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
11065 Set_Etype
(Index
, Index_Subtype
);
11066 Append
(Index
, Index_List
);
11068 Set_First_Index
(Array_Subtype
, Index
);
11069 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
11070 Set_Is_Constrained
(Array_Subtype
, True);
11073 Make_Unchecked_Type_Conversion
(Loc
,
11074 Subtype_Mark
=> New_Occurrence_Of
(Array_Subtype
, Loc
),
11075 Expression
=> Relocate_Node
(N
)));
11076 Set_Etype
(N
, Array_Subtype
);
11079 end Set_String_Literal_Subtype
;
11081 ------------------------------
11082 -- Simplify_Type_Conversion --
11083 ------------------------------
11085 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
11087 if Nkind
(N
) = N_Type_Conversion
then
11089 Operand
: constant Node_Id
:= Expression
(N
);
11090 Target_Typ
: constant Entity_Id
:= Etype
(N
);
11091 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
11094 -- Special processing if the conversion is the expression of a
11095 -- Rounding or Truncation attribute reference. In this case we
11098 -- ityp (ftyp'Rounding (x)) or ityp (ftyp'Truncation (x))
11104 -- with the Float_Truncate flag set to False or True respectively,
11105 -- which is more efficient.
11107 if Is_Floating_Point_Type
(Opnd_Typ
)
11109 (Is_Integer_Type
(Target_Typ
)
11110 or else (Is_Fixed_Point_Type
(Target_Typ
)
11111 and then Conversion_OK
(N
)))
11112 and then Nkind
(Operand
) = N_Attribute_Reference
11113 and then Nam_In
(Attribute_Name
(Operand
), Name_Rounding
,
11117 Truncate
: constant Boolean :=
11118 Attribute_Name
(Operand
) = Name_Truncation
;
11121 Relocate_Node
(First
(Expressions
(Operand
))));
11122 Set_Float_Truncate
(N
, Truncate
);
11127 end Simplify_Type_Conversion
;
11129 -----------------------------
11130 -- Unique_Fixed_Point_Type --
11131 -----------------------------
11133 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
11134 T1
: Entity_Id
:= Empty
;
11139 procedure Fixed_Point_Error
;
11140 -- Give error messages for true ambiguity. Messages are posted on node
11141 -- N, and entities T1, T2 are the possible interpretations.
11143 -----------------------
11144 -- Fixed_Point_Error --
11145 -----------------------
11147 procedure Fixed_Point_Error
is
11149 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
11150 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
11151 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
11152 end Fixed_Point_Error
;
11154 -- Start of processing for Unique_Fixed_Point_Type
11157 -- The operations on Duration are visible, so Duration is always a
11158 -- possible interpretation.
11160 T1
:= Standard_Duration
;
11162 -- Look for fixed-point types in enclosing scopes
11164 Scop
:= Current_Scope
;
11165 while Scop
/= Standard_Standard
loop
11166 T2
:= First_Entity
(Scop
);
11167 while Present
(T2
) loop
11168 if Is_Fixed_Point_Type
(T2
)
11169 and then Current_Entity
(T2
) = T2
11170 and then Scope
(Base_Type
(T2
)) = Scop
11172 if Present
(T1
) then
11183 Scop
:= Scope
(Scop
);
11186 -- Look for visible fixed type declarations in the context
11188 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
11189 while Present
(Item
) loop
11190 if Nkind
(Item
) = N_With_Clause
then
11191 Scop
:= Entity
(Name
(Item
));
11192 T2
:= First_Entity
(Scop
);
11193 while Present
(T2
) loop
11194 if Is_Fixed_Point_Type
(T2
)
11195 and then Scope
(Base_Type
(T2
)) = Scop
11196 and then (Is_Potentially_Use_Visible
(T2
) or else In_Use
(T2
))
11198 if Present
(T1
) then
11213 if Nkind
(N
) = N_Real_Literal
then
11215 ("??real literal interpreted as }!", N
, T1
);
11218 ("??universal_fixed expression interpreted as }!", N
, T1
);
11222 end Unique_Fixed_Point_Type
;
11224 ----------------------
11225 -- Valid_Conversion --
11226 ----------------------
11228 function Valid_Conversion
11230 Target
: Entity_Id
;
11232 Report_Errs
: Boolean := True) return Boolean
11234 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
11235 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
11236 Inc_Ancestor
: Entity_Id
;
11238 function Conversion_Check
11240 Msg
: String) return Boolean;
11241 -- Little routine to post Msg if Valid is False, returns Valid value
11243 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
);
11244 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
11246 procedure Conversion_Error_NE
11248 N
: Node_Or_Entity_Id
;
11249 E
: Node_Or_Entity_Id
);
11250 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
11252 function Valid_Tagged_Conversion
11253 (Target_Type
: Entity_Id
;
11254 Opnd_Type
: Entity_Id
) return Boolean;
11255 -- Specifically test for validity of tagged conversions
11257 function Valid_Array_Conversion
return Boolean;
11258 -- Check index and component conformance, and accessibility levels if
11259 -- the component types are anonymous access types (Ada 2005).
11261 ----------------------
11262 -- Conversion_Check --
11263 ----------------------
11265 function Conversion_Check
11267 Msg
: String) return Boolean
11272 -- A generic unit has already been analyzed and we have verified
11273 -- that a particular conversion is OK in that context. Since the
11274 -- instance is reanalyzed without relying on the relationships
11275 -- established during the analysis of the generic, it is possible
11276 -- to end up with inconsistent views of private types. Do not emit
11277 -- the error message in such cases. The rest of the machinery in
11278 -- Valid_Conversion still ensures the proper compatibility of
11279 -- target and operand types.
11281 and then not In_Instance
11283 Conversion_Error_N
(Msg
, Operand
);
11287 end Conversion_Check
;
11289 ------------------------
11290 -- Conversion_Error_N --
11291 ------------------------
11293 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
11295 if Report_Errs
then
11296 Error_Msg_N
(Msg
, N
);
11298 end Conversion_Error_N
;
11300 -------------------------
11301 -- Conversion_Error_NE --
11302 -------------------------
11304 procedure Conversion_Error_NE
11306 N
: Node_Or_Entity_Id
;
11307 E
: Node_Or_Entity_Id
)
11310 if Report_Errs
then
11311 Error_Msg_NE
(Msg
, N
, E
);
11313 end Conversion_Error_NE
;
11315 ----------------------------
11316 -- Valid_Array_Conversion --
11317 ----------------------------
11319 function Valid_Array_Conversion
return Boolean
11321 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
11322 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
11324 Opnd_Index
: Node_Id
;
11325 Opnd_Index_Type
: Entity_Id
;
11327 Target_Comp_Type
: constant Entity_Id
:=
11328 Component_Type
(Target_Type
);
11329 Target_Comp_Base
: constant Entity_Id
:=
11330 Base_Type
(Target_Comp_Type
);
11332 Target_Index
: Node_Id
;
11333 Target_Index_Type
: Entity_Id
;
11336 -- Error if wrong number of dimensions
11339 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
11342 ("incompatible number of dimensions for conversion", Operand
);
11345 -- Number of dimensions matches
11348 -- Loop through indexes of the two arrays
11350 Target_Index
:= First_Index
(Target_Type
);
11351 Opnd_Index
:= First_Index
(Opnd_Type
);
11352 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
11353 Target_Index_Type
:= Etype
(Target_Index
);
11354 Opnd_Index_Type
:= Etype
(Opnd_Index
);
11356 -- Error if index types are incompatible
11358 if not (Is_Integer_Type
(Target_Index_Type
)
11359 and then Is_Integer_Type
(Opnd_Index_Type
))
11360 and then (Root_Type
(Target_Index_Type
)
11361 /= Root_Type
(Opnd_Index_Type
))
11364 ("incompatible index types for array conversion",
11369 Next_Index
(Target_Index
);
11370 Next_Index
(Opnd_Index
);
11373 -- If component types have same base type, all set
11375 if Target_Comp_Base
= Opnd_Comp_Base
then
11378 -- Here if base types of components are not the same. The only
11379 -- time this is allowed is if we have anonymous access types.
11381 -- The conversion of arrays of anonymous access types can lead
11382 -- to dangling pointers. AI-392 formalizes the accessibility
11383 -- checks that must be applied to such conversions to prevent
11384 -- out-of-scope references.
11387 (Target_Comp_Base
, E_Anonymous_Access_Type
,
11388 E_Anonymous_Access_Subprogram_Type
)
11389 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
11391 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
11393 if Type_Access_Level
(Target_Type
) <
11394 Deepest_Type_Access_Level
(Opnd_Type
)
11396 if In_Instance_Body
then
11397 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11399 ("source array type has deeper accessibility "
11400 & "level than target<<", Operand
);
11401 Conversion_Error_N
("\Program_Error [<<", Operand
);
11403 Make_Raise_Program_Error
(Sloc
(N
),
11404 Reason
=> PE_Accessibility_Check_Failed
));
11405 Set_Etype
(N
, Target_Type
);
11408 -- Conversion not allowed because of accessibility levels
11412 ("source array type has deeper accessibility "
11413 & "level than target", Operand
);
11421 -- All other cases where component base types do not match
11425 ("incompatible component types for array conversion",
11430 -- Check that component subtypes statically match. For numeric
11431 -- types this means that both must be either constrained or
11432 -- unconstrained. For enumeration types the bounds must match.
11433 -- All of this is checked in Subtypes_Statically_Match.
11435 if not Subtypes_Statically_Match
11436 (Target_Comp_Type
, Opnd_Comp_Type
)
11439 ("component subtypes must statically match", Operand
);
11445 end Valid_Array_Conversion
;
11447 -----------------------------
11448 -- Valid_Tagged_Conversion --
11449 -----------------------------
11451 function Valid_Tagged_Conversion
11452 (Target_Type
: Entity_Id
;
11453 Opnd_Type
: Entity_Id
) return Boolean
11456 -- Upward conversions are allowed (RM 4.6(22))
11458 if Covers
(Target_Type
, Opnd_Type
)
11459 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
11463 -- Downward conversion are allowed if the operand is class-wide
11466 elsif Is_Class_Wide_Type
(Opnd_Type
)
11467 and then Covers
(Opnd_Type
, Target_Type
)
11471 elsif Covers
(Opnd_Type
, Target_Type
)
11472 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
11475 Conversion_Check
(False,
11476 "downward conversion of tagged objects not allowed");
11478 -- Ada 2005 (AI-251): The conversion to/from interface types is
11481 elsif Is_Interface
(Target_Type
) or else Is_Interface
(Opnd_Type
) then
11484 -- If the operand is a class-wide type obtained through a limited_
11485 -- with clause, and the context includes the non-limited view, use
11486 -- it to determine whether the conversion is legal.
11488 elsif Is_Class_Wide_Type
(Opnd_Type
)
11489 and then From_Limited_With
(Opnd_Type
)
11490 and then Present
(Non_Limited_View
(Etype
(Opnd_Type
)))
11491 and then Is_Interface
(Non_Limited_View
(Etype
(Opnd_Type
)))
11495 elsif Is_Access_Type
(Opnd_Type
)
11496 and then Is_Interface
(Directly_Designated_Type
(Opnd_Type
))
11501 Conversion_Error_NE
11502 ("invalid tagged conversion, not compatible with}",
11503 N
, First_Subtype
(Opnd_Type
));
11506 end Valid_Tagged_Conversion
;
11508 -- Start of processing for Valid_Conversion
11511 Check_Parameterless_Call
(Operand
);
11513 if Is_Overloaded
(Operand
) then
11523 -- Remove procedure calls, which syntactically cannot appear in
11524 -- this context, but which cannot be removed by type checking,
11525 -- because the context does not impose a type.
11527 -- The node may be labelled overloaded, but still contain only one
11528 -- interpretation because others were discarded earlier. If this
11529 -- is the case, retain the single interpretation if legal.
11531 Get_First_Interp
(Operand
, I
, It
);
11532 Opnd_Type
:= It
.Typ
;
11533 Get_Next_Interp
(I
, It
);
11535 if Present
(It
.Typ
)
11536 and then Opnd_Type
/= Standard_Void_Type
11538 -- More than one candidate interpretation is available
11540 Get_First_Interp
(Operand
, I
, It
);
11541 while Present
(It
.Typ
) loop
11542 if It
.Typ
= Standard_Void_Type
then
11546 -- When compiling for a system where Address is of a visible
11547 -- integer type, spurious ambiguities can be produced when
11548 -- arithmetic operations have a literal operand and return
11549 -- System.Address or a descendant of it. These ambiguities
11550 -- are usually resolved by the context, but for conversions
11551 -- there is no context type and the removal of the spurious
11552 -- operations must be done explicitly here.
11554 if not Address_Is_Private
11555 and then Is_Descendent_Of_Address
(It
.Typ
)
11560 Get_Next_Interp
(I
, It
);
11564 Get_First_Interp
(Operand
, I
, It
);
11568 if No
(It
.Typ
) then
11569 Conversion_Error_N
("illegal operand in conversion", Operand
);
11573 Get_Next_Interp
(I
, It
);
11575 if Present
(It
.Typ
) then
11578 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
11580 if It1
= No_Interp
then
11582 ("ambiguous operand in conversion", Operand
);
11584 -- If the interpretation involves a standard operator, use
11585 -- the location of the type, which may be user-defined.
11587 if Sloc
(It
.Nam
) = Standard_Location
then
11588 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
11590 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
11593 Conversion_Error_N
-- CODEFIX
11594 ("\\possible interpretation#!", Operand
);
11596 if Sloc
(N1
) = Standard_Location
then
11597 Error_Msg_Sloc
:= Sloc
(T1
);
11599 Error_Msg_Sloc
:= Sloc
(N1
);
11602 Conversion_Error_N
-- CODEFIX
11603 ("\\possible interpretation#!", Operand
);
11609 Set_Etype
(Operand
, It1
.Typ
);
11610 Opnd_Type
:= It1
.Typ
;
11614 -- Deal with conversion of integer type to address if the pragma
11615 -- Allow_Integer_Address is in effect. We convert the conversion to
11616 -- an unchecked conversion in this case and we are all done.
11618 if Address_Integer_Convert_OK
(Opnd_Type
, Target_Type
) then
11619 Rewrite
(N
, Unchecked_Convert_To
(Target_Type
, Expression
(N
)));
11620 Analyze_And_Resolve
(N
, Target_Type
);
11624 -- If we are within a child unit, check whether the type of the
11625 -- expression has an ancestor in a parent unit, in which case it
11626 -- belongs to its derivation class even if the ancestor is private.
11627 -- See RM 7.3.1 (5.2/3).
11629 Inc_Ancestor
:= Get_Incomplete_View_Of_Ancestor
(Opnd_Type
);
11633 if Is_Numeric_Type
(Target_Type
) then
11635 -- A universal fixed expression can be converted to any numeric type
11637 if Opnd_Type
= Universal_Fixed
then
11640 -- Also no need to check when in an instance or inlined body, because
11641 -- the legality has been established when the template was analyzed.
11642 -- Furthermore, numeric conversions may occur where only a private
11643 -- view of the operand type is visible at the instantiation point.
11644 -- This results in a spurious error if we check that the operand type
11645 -- is a numeric type.
11647 -- Note: in a previous version of this unit, the following tests were
11648 -- applied only for generated code (Comes_From_Source set to False),
11649 -- but in fact the test is required for source code as well, since
11650 -- this situation can arise in source code.
11652 elsif In_Instance
or else In_Inlined_Body
then
11655 -- Otherwise we need the conversion check
11658 return Conversion_Check
11659 (Is_Numeric_Type
(Opnd_Type
)
11661 (Present
(Inc_Ancestor
)
11662 and then Is_Numeric_Type
(Inc_Ancestor
)),
11663 "illegal operand for numeric conversion");
11668 elsif Is_Array_Type
(Target_Type
) then
11669 if not Is_Array_Type
(Opnd_Type
)
11670 or else Opnd_Type
= Any_Composite
11671 or else Opnd_Type
= Any_String
11674 ("illegal operand for array conversion", Operand
);
11678 return Valid_Array_Conversion
;
11681 -- Ada 2005 (AI-251): Anonymous access types where target references an
11684 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11685 E_Anonymous_Access_Type
)
11686 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
11688 -- Check the static accessibility rule of 4.6(17). Note that the
11689 -- check is not enforced when within an instance body, since the
11690 -- RM requires such cases to be caught at run time.
11692 -- If the operand is a rewriting of an allocator no check is needed
11693 -- because there are no accessibility issues.
11695 if Nkind
(Original_Node
(N
)) = N_Allocator
then
11698 elsif Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
11699 if Type_Access_Level
(Opnd_Type
) >
11700 Deepest_Type_Access_Level
(Target_Type
)
11702 -- In an instance, this is a run-time check, but one we know
11703 -- will fail, so generate an appropriate warning. The raise
11704 -- will be generated by Expand_N_Type_Conversion.
11706 if In_Instance_Body
then
11707 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11709 ("cannot convert local pointer to non-local access type<<",
11711 Conversion_Error_N
("\Program_Error [<<", Operand
);
11715 ("cannot convert local pointer to non-local access type",
11720 -- Special accessibility checks are needed in the case of access
11721 -- discriminants declared for a limited type.
11723 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11724 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11726 -- When the operand is a selected access discriminant the check
11727 -- needs to be made against the level of the object denoted by
11728 -- the prefix of the selected name (Object_Access_Level handles
11729 -- checking the prefix of the operand for this case).
11731 if Nkind
(Operand
) = N_Selected_Component
11732 and then Object_Access_Level
(Operand
) >
11733 Deepest_Type_Access_Level
(Target_Type
)
11735 -- In an instance, this is a run-time check, but one we know
11736 -- will fail, so generate an appropriate warning. The raise
11737 -- will be generated by Expand_N_Type_Conversion.
11739 if In_Instance_Body
then
11740 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11742 ("cannot convert access discriminant to non-local "
11743 & "access type<<", Operand
);
11744 Conversion_Error_N
("\Program_Error [<<", Operand
);
11746 -- Real error if not in instance body
11750 ("cannot convert access discriminant to non-local "
11751 & "access type", Operand
);
11756 -- The case of a reference to an access discriminant from
11757 -- within a limited type declaration (which will appear as
11758 -- a discriminal) is always illegal because the level of the
11759 -- discriminant is considered to be deeper than any (nameable)
11762 if Is_Entity_Name
(Operand
)
11763 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11765 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
11766 and then Present
(Discriminal_Link
(Entity
(Operand
)))
11769 ("discriminant has deeper accessibility level than target",
11778 -- General and anonymous access types
11780 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11781 E_Anonymous_Access_Type
)
11784 (Is_Access_Type
(Opnd_Type
)
11786 Ekind_In
(Opnd_Type
, E_Access_Subprogram_Type
,
11787 E_Access_Protected_Subprogram_Type
),
11788 "must be an access-to-object type")
11790 if Is_Access_Constant
(Opnd_Type
)
11791 and then not Is_Access_Constant
(Target_Type
)
11794 ("access-to-constant operand type not allowed", Operand
);
11798 -- Check the static accessibility rule of 4.6(17). Note that the
11799 -- check is not enforced when within an instance body, since the RM
11800 -- requires such cases to be caught at run time.
11802 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
11803 or else Is_Local_Anonymous_Access
(Target_Type
)
11804 or else Nkind
(Associated_Node_For_Itype
(Target_Type
)) =
11805 N_Object_Declaration
11807 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
11808 -- conversions from an anonymous access type to a named general
11809 -- access type. Such conversions are not allowed in the case of
11810 -- access parameters and stand-alone objects of an anonymous
11811 -- access type. The implicit conversion case is recognized by
11812 -- testing that Comes_From_Source is False and that it's been
11813 -- rewritten. The Comes_From_Source test isn't sufficient because
11814 -- nodes in inlined calls to predefined library routines can have
11815 -- Comes_From_Source set to False. (Is there a better way to test
11816 -- for implicit conversions???)
11818 if Ada_Version
>= Ada_2012
11819 and then not Comes_From_Source
(N
)
11820 and then N
/= Original_Node
(N
)
11821 and then Ekind
(Target_Type
) = E_General_Access_Type
11822 and then Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11824 if Is_Itype
(Opnd_Type
) then
11826 -- Implicit conversions aren't allowed for objects of an
11827 -- anonymous access type, since such objects have nonstatic
11828 -- levels in Ada 2012.
11830 if Nkind
(Associated_Node_For_Itype
(Opnd_Type
)) =
11831 N_Object_Declaration
11834 ("implicit conversion of stand-alone anonymous "
11835 & "access object not allowed", Operand
);
11838 -- Implicit conversions aren't allowed for anonymous access
11839 -- parameters. The "not Is_Local_Anonymous_Access_Type" test
11840 -- is done to exclude anonymous access results.
11842 elsif not Is_Local_Anonymous_Access
(Opnd_Type
)
11843 and then Nkind_In
(Associated_Node_For_Itype
(Opnd_Type
),
11844 N_Function_Specification
,
11845 N_Procedure_Specification
)
11848 ("implicit conversion of anonymous access formal "
11849 & "not allowed", Operand
);
11852 -- This is a case where there's an enclosing object whose
11853 -- to which the "statically deeper than" relationship does
11854 -- not apply (such as an access discriminant selected from
11855 -- a dereference of an access parameter).
11857 elsif Object_Access_Level
(Operand
)
11858 = Scope_Depth
(Standard_Standard
)
11861 ("implicit conversion of anonymous access value "
11862 & "not allowed", Operand
);
11865 -- In other cases, the level of the operand's type must be
11866 -- statically less deep than that of the target type, else
11867 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
11869 elsif Type_Access_Level
(Opnd_Type
) >
11870 Deepest_Type_Access_Level
(Target_Type
)
11873 ("implicit conversion of anonymous access value "
11874 & "violates accessibility", Operand
);
11879 elsif Type_Access_Level
(Opnd_Type
) >
11880 Deepest_Type_Access_Level
(Target_Type
)
11882 -- In an instance, this is a run-time check, but one we know
11883 -- will fail, so generate an appropriate warning. The raise
11884 -- will be generated by Expand_N_Type_Conversion.
11886 if In_Instance_Body
then
11887 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11889 ("cannot convert local pointer to non-local access type<<",
11891 Conversion_Error_N
("\Program_Error [<<", Operand
);
11893 -- If not in an instance body, this is a real error
11896 -- Avoid generation of spurious error message
11898 if not Error_Posted
(N
) then
11900 ("cannot convert local pointer to non-local access type",
11907 -- Special accessibility checks are needed in the case of access
11908 -- discriminants declared for a limited type.
11910 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11911 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11913 -- When the operand is a selected access discriminant the check
11914 -- needs to be made against the level of the object denoted by
11915 -- the prefix of the selected name (Object_Access_Level handles
11916 -- checking the prefix of the operand for this case).
11918 if Nkind
(Operand
) = N_Selected_Component
11919 and then Object_Access_Level
(Operand
) >
11920 Deepest_Type_Access_Level
(Target_Type
)
11922 -- In an instance, this is a run-time check, but one we know
11923 -- will fail, so generate an appropriate warning. The raise
11924 -- will be generated by Expand_N_Type_Conversion.
11926 if In_Instance_Body
then
11927 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11929 ("cannot convert access discriminant to non-local "
11930 & "access type<<", Operand
);
11931 Conversion_Error_N
("\Program_Error [<<", Operand
);
11933 -- If not in an instance body, this is a real error
11937 ("cannot convert access discriminant to non-local "
11938 & "access type", Operand
);
11943 -- The case of a reference to an access discriminant from
11944 -- within a limited type declaration (which will appear as
11945 -- a discriminal) is always illegal because the level of the
11946 -- discriminant is considered to be deeper than any (nameable)
11949 if Is_Entity_Name
(Operand
)
11951 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
11952 and then Present
(Discriminal_Link
(Entity
(Operand
)))
11955 ("discriminant has deeper accessibility level than target",
11962 -- In the presence of limited_with clauses we have to use non-limited
11963 -- views, if available.
11965 Check_Limited
: declare
11966 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
11967 -- Helper function to handle limited views
11969 --------------------------
11970 -- Full_Designated_Type --
11971 --------------------------
11973 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
11974 Desig
: constant Entity_Id
:= Designated_Type
(T
);
11977 -- Handle the limited view of a type
11979 if Is_Incomplete_Type
(Desig
)
11980 and then From_Limited_With
(Desig
)
11981 and then Present
(Non_Limited_View
(Desig
))
11983 return Available_View
(Desig
);
11987 end Full_Designated_Type
;
11989 -- Local Declarations
11991 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
11992 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
11994 Same_Base
: constant Boolean :=
11995 Base_Type
(Target
) = Base_Type
(Opnd
);
11997 -- Start of processing for Check_Limited
12000 if Is_Tagged_Type
(Target
) then
12001 return Valid_Tagged_Conversion
(Target
, Opnd
);
12004 if not Same_Base
then
12005 Conversion_Error_NE
12006 ("target designated type not compatible with }",
12007 N
, Base_Type
(Opnd
));
12010 -- Ada 2005 AI-384: legality rule is symmetric in both
12011 -- designated types. The conversion is legal (with possible
12012 -- constraint check) if either designated type is
12015 elsif Subtypes_Statically_Match
(Target
, Opnd
)
12017 (Has_Discriminants
(Target
)
12019 (not Is_Constrained
(Opnd
)
12020 or else not Is_Constrained
(Target
)))
12022 -- Special case, if Value_Size has been used to make the
12023 -- sizes different, the conversion is not allowed even
12024 -- though the subtypes statically match.
12026 if Known_Static_RM_Size
(Target
)
12027 and then Known_Static_RM_Size
(Opnd
)
12028 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
12030 Conversion_Error_NE
12031 ("target designated subtype not compatible with }",
12033 Conversion_Error_NE
12034 ("\because sizes of the two designated subtypes differ",
12038 -- Normal case where conversion is allowed
12046 ("target designated subtype not compatible with }",
12053 -- Access to subprogram types. If the operand is an access parameter,
12054 -- the type has a deeper accessibility that any master, and cannot be
12055 -- assigned. We must make an exception if the conversion is part of an
12056 -- assignment and the target is the return object of an extended return
12057 -- statement, because in that case the accessibility check takes place
12058 -- after the return.
12060 elsif Is_Access_Subprogram_Type
(Target_Type
)
12062 -- Note: this test of Opnd_Type is there to prevent entering this
12063 -- branch in the case of a remote access to subprogram type, which
12064 -- is internally represented as an E_Record_Type.
12066 and then Is_Access_Type
(Opnd_Type
)
12068 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
12069 and then Is_Entity_Name
(Operand
)
12070 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
12072 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
12073 or else not Is_Entity_Name
(Name
(Parent
(N
)))
12074 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
12077 ("illegal attempt to store anonymous access to subprogram",
12080 ("\value has deeper accessibility than any master "
12081 & "(RM 3.10.2 (13))",
12085 ("\use named access type for& instead of access parameter",
12086 Operand
, Entity
(Operand
));
12089 -- Check that the designated types are subtype conformant
12091 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
12092 Old_Id
=> Designated_Type
(Opnd_Type
),
12095 -- Check the static accessibility rule of 4.6(20)
12097 if Type_Access_Level
(Opnd_Type
) >
12098 Deepest_Type_Access_Level
(Target_Type
)
12101 ("operand type has deeper accessibility level than target",
12104 -- Check that if the operand type is declared in a generic body,
12105 -- then the target type must be declared within that same body
12106 -- (enforces last sentence of 4.6(20)).
12108 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
12110 O_Gen
: constant Node_Id
:=
12111 Enclosing_Generic_Body
(Opnd_Type
);
12116 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
12117 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
12118 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
12121 if T_Gen
/= O_Gen
then
12123 ("target type must be declared in same generic body "
12124 & "as operand type", N
);
12131 -- Remote access to subprogram types
12133 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
12134 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
12136 -- It is valid to convert from one RAS type to another provided
12137 -- that their specification statically match.
12139 -- Note: at this point, remote access to subprogram types have been
12140 -- expanded to their E_Record_Type representation, and we need to
12141 -- go back to the original access type definition using the
12142 -- Corresponding_Remote_Type attribute in order to check that the
12143 -- designated profiles match.
12145 pragma Assert
(Ekind
(Target_Type
) = E_Record_Type
);
12146 pragma Assert
(Ekind
(Opnd_Type
) = E_Record_Type
);
12148 Check_Subtype_Conformant
12150 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
12152 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
12157 -- If it was legal in the generic, it's legal in the instance
12159 elsif In_Instance_Body
then
12162 -- If both are tagged types, check legality of view conversions
12164 elsif Is_Tagged_Type
(Target_Type
)
12166 Is_Tagged_Type
(Opnd_Type
)
12168 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
12170 -- Types derived from the same root type are convertible
12172 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
12175 -- In an instance or an inlined body, there may be inconsistent views of
12176 -- the same type, or of types derived from a common root.
12178 elsif (In_Instance
or In_Inlined_Body
)
12180 Root_Type
(Underlying_Type
(Target_Type
)) =
12181 Root_Type
(Underlying_Type
(Opnd_Type
))
12185 -- Special check for common access type error case
12187 elsif Ekind
(Target_Type
) = E_Access_Type
12188 and then Is_Access_Type
(Opnd_Type
)
12190 Conversion_Error_N
("target type must be general access type!", N
);
12191 Conversion_Error_NE
-- CODEFIX
12192 ("add ALL to }!", N
, Target_Type
);
12195 -- Here we have a real conversion error
12198 Conversion_Error_NE
12199 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
12202 end Valid_Conversion
;