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 Loc
: constant Source_Ptr
:= Sloc
(N
);
5375 Subp
: constant Node_Id
:= Name
(N
);
5383 function Same_Or_Aliased_Subprograms
5385 E
: Entity_Id
) return Boolean;
5386 -- Returns True if the subprogram entity S is the same as E or else
5387 -- S is an alias of E.
5389 ---------------------------------
5390 -- Same_Or_Aliased_Subprograms --
5391 ---------------------------------
5393 function Same_Or_Aliased_Subprograms
5395 E
: Entity_Id
) return Boolean
5397 Subp_Alias
: constant Entity_Id
:= Alias
(S
);
5399 return S
= E
or else (Present
(Subp_Alias
) and then Subp_Alias
= E
);
5400 end Same_Or_Aliased_Subprograms
;
5402 -- Start of processing for Resolve_Call
5405 -- The context imposes a unique interpretation with type Typ on a
5406 -- procedure or function call. Find the entity of the subprogram that
5407 -- yields the expected type, and propagate the corresponding formal
5408 -- constraints on the actuals. The caller has established that an
5409 -- interpretation exists, and emitted an error if not unique.
5411 -- First deal with the case of a call to an access-to-subprogram,
5412 -- dereference made explicit in Analyze_Call.
5414 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
5415 if not Is_Overloaded
(Subp
) then
5416 Nam
:= Etype
(Subp
);
5419 -- Find the interpretation whose type (a subprogram type) has a
5420 -- return type that is compatible with the context. Analysis of
5421 -- the node has established that one exists.
5425 Get_First_Interp
(Subp
, I
, It
);
5426 while Present
(It
.Typ
) loop
5427 if Covers
(Typ
, Etype
(It
.Typ
)) then
5432 Get_Next_Interp
(I
, It
);
5436 raise Program_Error
;
5440 -- If the prefix is not an entity, then resolve it
5442 if not Is_Entity_Name
(Subp
) then
5443 Resolve
(Subp
, Nam
);
5446 -- For an indirect call, we always invalidate checks, since we do not
5447 -- know whether the subprogram is local or global. Yes we could do
5448 -- better here, e.g. by knowing that there are no local subprograms,
5449 -- but it does not seem worth the effort. Similarly, we kill all
5450 -- knowledge of current constant values.
5452 Kill_Current_Values
;
5454 -- If this is a procedure call which is really an entry call, do
5455 -- the conversion of the procedure call to an entry call. Protected
5456 -- operations use the same circuitry because the name in the call
5457 -- can be an arbitrary expression with special resolution rules.
5459 elsif Nkind_In
(Subp
, N_Selected_Component
, N_Indexed_Component
)
5460 or else (Is_Entity_Name
(Subp
)
5461 and then Ekind
(Entity
(Subp
)) = E_Entry
)
5463 Resolve_Entry_Call
(N
, Typ
);
5464 Check_Elab_Call
(N
);
5466 -- Kill checks and constant values, as above for indirect case
5467 -- Who knows what happens when another task is activated?
5469 Kill_Current_Values
;
5472 -- Normal subprogram call with name established in Resolve
5474 elsif not (Is_Type
(Entity
(Subp
))) then
5475 Nam
:= Entity
(Subp
);
5476 Set_Entity_With_Checks
(Subp
, Nam
);
5478 -- Otherwise we must have the case of an overloaded call
5481 pragma Assert
(Is_Overloaded
(Subp
));
5483 -- Initialize Nam to prevent warning (we know it will be assigned
5484 -- in the loop below, but the compiler does not know that).
5488 Get_First_Interp
(Subp
, I
, It
);
5489 while Present
(It
.Typ
) loop
5490 if Covers
(Typ
, It
.Typ
) then
5492 Set_Entity_With_Checks
(Subp
, Nam
);
5496 Get_Next_Interp
(I
, It
);
5500 if Is_Access_Subprogram_Type
(Base_Type
(Etype
(Nam
)))
5501 and then not Is_Access_Subprogram_Type
(Base_Type
(Typ
))
5502 and then Nkind
(Subp
) /= N_Explicit_Dereference
5503 and then Present
(Parameter_Associations
(N
))
5505 -- The prefix is a parameterless function call that returns an access
5506 -- to subprogram. If parameters are present in the current call, add
5507 -- add an explicit dereference. We use the base type here because
5508 -- within an instance these may be subtypes.
5510 -- The dereference is added either in Analyze_Call or here. Should
5511 -- be consolidated ???
5513 Set_Is_Overloaded
(Subp
, False);
5514 Set_Etype
(Subp
, Etype
(Nam
));
5515 Insert_Explicit_Dereference
(Subp
);
5516 Nam
:= Designated_Type
(Etype
(Nam
));
5517 Resolve
(Subp
, Nam
);
5520 -- Check that a call to Current_Task does not occur in an entry body
5522 if Is_RTE
(Nam
, RE_Current_Task
) then
5531 -- Exclude calls that occur within the default of a formal
5532 -- parameter of the entry, since those are evaluated outside
5535 exit when No
(P
) or else Nkind
(P
) = N_Parameter_Specification
;
5537 if Nkind
(P
) = N_Entry_Body
5538 or else (Nkind
(P
) = N_Subprogram_Body
5539 and then Is_Entry_Barrier_Function
(P
))
5542 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5544 ("& should not be used in entry body (RM C.7(17))<<",
5546 Error_Msg_NE
("\Program_Error [<<", N
, Nam
);
5548 Make_Raise_Program_Error
(Loc
,
5549 Reason
=> PE_Current_Task_In_Entry_Body
));
5550 Set_Etype
(N
, Rtype
);
5557 -- Check that a procedure call does not occur in the context of the
5558 -- entry call statement of a conditional or timed entry call. Note that
5559 -- the case of a call to a subprogram renaming of an entry will also be
5560 -- rejected. The test for N not being an N_Entry_Call_Statement is
5561 -- defensive, covering the possibility that the processing of entry
5562 -- calls might reach this point due to later modifications of the code
5565 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
5566 and then Nkind
(N
) /= N_Entry_Call_Statement
5567 and then Entry_Call_Statement
(Parent
(N
)) = N
5569 if Ada_Version
< Ada_2005
then
5570 Error_Msg_N
("entry call required in select statement", N
);
5572 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5573 -- for a procedure_or_entry_call, the procedure_name or
5574 -- procedure_prefix of the procedure_call_statement shall denote
5575 -- an entry renamed by a procedure, or (a view of) a primitive
5576 -- subprogram of a limited interface whose first parameter is
5577 -- a controlling parameter.
5579 elsif Nkind
(N
) = N_Procedure_Call_Statement
5580 and then not Is_Renamed_Entry
(Nam
)
5581 and then not Is_Controlling_Limited_Procedure
(Nam
)
5584 ("entry call or dispatching primitive of interface required", N
);
5588 -- If the SPARK_05 restriction is active, we are not allowed
5589 -- to have a call to a subprogram before we see its completion.
5591 if not Has_Completion
(Nam
)
5592 and then Restriction_Check_Required
(SPARK_05
)
5594 -- Don't flag strange internal calls
5596 and then Comes_From_Source
(N
)
5597 and then Comes_From_Source
(Nam
)
5599 -- Only flag calls in extended main source
5601 and then In_Extended_Main_Source_Unit
(Nam
)
5602 and then In_Extended_Main_Source_Unit
(N
)
5604 -- Exclude enumeration literals from this processing
5606 and then Ekind
(Nam
) /= E_Enumeration_Literal
5608 Check_SPARK_Restriction
5609 ("call to subprogram cannot appear before its body", N
);
5612 -- Check that this is not a call to a protected procedure or entry from
5613 -- within a protected function.
5615 Check_Internal_Protected_Use
(N
, Nam
);
5617 -- Freeze the subprogram name if not in a spec-expression. Note that
5618 -- we freeze procedure calls as well as function calls. Procedure calls
5619 -- are not frozen according to the rules (RM 13.14(14)) because it is
5620 -- impossible to have a procedure call to a non-frozen procedure in
5621 -- pure Ada, but in the code that we generate in the expander, this
5622 -- rule needs extending because we can generate procedure calls that
5625 -- In Ada 2012, expression functions may be called within pre/post
5626 -- conditions of subsequent functions or expression functions. Such
5627 -- calls do not freeze when they appear within generated bodies,
5628 -- (including the body of another expression function) which would
5629 -- place the freeze node in the wrong scope. An expression function
5630 -- is frozen in the usual fashion, by the appearance of a real body,
5631 -- or at the end of a declarative part.
5633 if Is_Entity_Name
(Subp
) and then not In_Spec_Expression
5634 and then not Is_Expression_Function
(Current_Scope
)
5636 (not Is_Expression_Function
(Entity
(Subp
))
5637 or else Scope
(Entity
(Subp
)) = Current_Scope
)
5639 Freeze_Expression
(Subp
);
5642 -- For a predefined operator, the type of the result is the type imposed
5643 -- by context, except for a predefined operation on universal fixed.
5644 -- Otherwise The type of the call is the type returned by the subprogram
5647 if Is_Predefined_Op
(Nam
) then
5648 if Etype
(N
) /= Universal_Fixed
then
5652 -- If the subprogram returns an array type, and the context requires the
5653 -- component type of that array type, the node is really an indexing of
5654 -- the parameterless call. Resolve as such. A pathological case occurs
5655 -- when the type of the component is an access to the array type. In
5656 -- this case the call is truly ambiguous.
5658 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
5660 ((Is_Array_Type
(Etype
(Nam
))
5661 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
5663 (Is_Access_Type
(Etype
(Nam
))
5664 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
5666 Covers
(Typ
, Component_Type
(Designated_Type
(Etype
(Nam
))))))
5669 Index_Node
: Node_Id
;
5671 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
5674 if Is_Access_Type
(Ret_Type
)
5675 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
5678 ("cannot disambiguate function call and indexing", N
);
5680 New_Subp
:= Relocate_Node
(Subp
);
5682 -- The called entity may be an explicit dereference, in which
5683 -- case there is no entity to set.
5685 if Nkind
(New_Subp
) /= N_Explicit_Dereference
then
5686 Set_Entity
(Subp
, Nam
);
5689 if (Is_Array_Type
(Ret_Type
)
5690 and then Component_Type
(Ret_Type
) /= Any_Type
)
5692 (Is_Access_Type
(Ret_Type
)
5694 Component_Type
(Designated_Type
(Ret_Type
)) /= Any_Type
)
5696 if Needs_No_Actuals
(Nam
) then
5698 -- Indexed call to a parameterless function
5701 Make_Indexed_Component
(Loc
,
5703 Make_Function_Call
(Loc
, Name
=> New_Subp
),
5704 Expressions
=> Parameter_Associations
(N
));
5706 -- An Ada 2005 prefixed call to a primitive operation
5707 -- whose first parameter is the prefix. This prefix was
5708 -- prepended to the parameter list, which is actually a
5709 -- list of indexes. Remove the prefix in order to build
5710 -- the proper indexed component.
5713 Make_Indexed_Component
(Loc
,
5715 Make_Function_Call
(Loc
,
5717 Parameter_Associations
=>
5719 (Remove_Head
(Parameter_Associations
(N
)))),
5720 Expressions
=> Parameter_Associations
(N
));
5723 -- Preserve the parenthesis count of the node
5725 Set_Paren_Count
(Index_Node
, Paren_Count
(N
));
5727 -- Since we are correcting a node classification error made
5728 -- by the parser, we call Replace rather than Rewrite.
5730 Replace
(N
, Index_Node
);
5732 Set_Etype
(Prefix
(N
), Ret_Type
);
5734 Resolve_Indexed_Component
(N
, Typ
);
5735 Check_Elab_Call
(Prefix
(N
));
5743 Set_Etype
(N
, Etype
(Nam
));
5746 -- In the case where the call is to an overloaded subprogram, Analyze
5747 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5748 -- such a case Normalize_Actuals needs to be called once more to order
5749 -- the actuals correctly. Otherwise the call will have the ordering
5750 -- given by the last overloaded subprogram whether this is the correct
5751 -- one being called or not.
5753 if Is_Overloaded
(Subp
) then
5754 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
5755 pragma Assert
(Norm_OK
);
5758 -- In any case, call is fully resolved now. Reset Overload flag, to
5759 -- prevent subsequent overload resolution if node is analyzed again
5761 Set_Is_Overloaded
(Subp
, False);
5762 Set_Is_Overloaded
(N
, False);
5764 -- If we are calling the current subprogram from immediately within its
5765 -- body, then that is the case where we can sometimes detect cases of
5766 -- infinite recursion statically. Do not try this in case restriction
5767 -- No_Recursion is in effect anyway, and do it only for source calls.
5769 if Comes_From_Source
(N
) then
5770 Scop
:= Current_Scope
;
5772 -- Check violation of SPARK_05 restriction which does not permit
5773 -- a subprogram body to contain a call to the subprogram directly.
5775 if Restriction_Check_Required
(SPARK_05
)
5776 and then Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5778 Check_SPARK_Restriction
5779 ("subprogram may not contain direct call to itself", N
);
5782 -- Issue warning for possible infinite recursion in the absence
5783 -- of the No_Recursion restriction.
5785 if Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5786 and then not Restriction_Active
(No_Recursion
)
5787 and then Check_Infinite_Recursion
(N
)
5789 -- Here we detected and flagged an infinite recursion, so we do
5790 -- not need to test the case below for further warnings. Also we
5791 -- are all done if we now have a raise SE node.
5793 if Nkind
(N
) = N_Raise_Storage_Error
then
5797 -- If call is to immediately containing subprogram, then check for
5798 -- the case of a possible run-time detectable infinite recursion.
5801 Scope_Loop
: while Scop
/= Standard_Standard
loop
5802 if Same_Or_Aliased_Subprograms
(Nam
, Scop
) then
5804 -- Although in general case, recursion is not statically
5805 -- checkable, the case of calling an immediately containing
5806 -- subprogram is easy to catch.
5808 Check_Restriction
(No_Recursion
, N
);
5810 -- If the recursive call is to a parameterless subprogram,
5811 -- then even if we can't statically detect infinite
5812 -- recursion, this is pretty suspicious, and we output a
5813 -- warning. Furthermore, we will try later to detect some
5814 -- cases here at run time by expanding checking code (see
5815 -- Detect_Infinite_Recursion in package Exp_Ch6).
5817 -- If the recursive call is within a handler, do not emit a
5818 -- warning, because this is a common idiom: loop until input
5819 -- is correct, catch illegal input in handler and restart.
5821 if No
(First_Formal
(Nam
))
5822 and then Etype
(Nam
) = Standard_Void_Type
5823 and then not Error_Posted
(N
)
5824 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
5826 -- For the case of a procedure call. We give the message
5827 -- only if the call is the first statement in a sequence
5828 -- of statements, or if all previous statements are
5829 -- simple assignments. This is simply a heuristic to
5830 -- decrease false positives, without losing too many good
5831 -- warnings. The idea is that these previous statements
5832 -- may affect global variables the procedure depends on.
5833 -- We also exclude raise statements, that may arise from
5834 -- constraint checks and are probably unrelated to the
5835 -- intended control flow.
5837 if Nkind
(N
) = N_Procedure_Call_Statement
5838 and then Is_List_Member
(N
)
5844 while Present
(P
) loop
5845 if not Nkind_In
(P
, N_Assignment_Statement
,
5846 N_Raise_Constraint_Error
)
5856 -- Do not give warning if we are in a conditional context
5859 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
5861 if (K
= N_Loop_Statement
5862 and then Present
(Iteration_Scheme
(Parent
(N
))))
5863 or else K
= N_If_Statement
5864 or else K
= N_Elsif_Part
5865 or else K
= N_Case_Statement_Alternative
5871 -- Here warning is to be issued
5873 Set_Has_Recursive_Call
(Nam
);
5874 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5875 Error_Msg_N
("possible infinite recursion<<!", N
);
5876 Error_Msg_N
("\Storage_Error ]<<!", N
);
5882 Scop
:= Scope
(Scop
);
5883 end loop Scope_Loop
;
5887 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5889 Check_Obsolescent_2005_Entity
(Nam
, Subp
);
5891 -- If subprogram name is a predefined operator, it was given in
5892 -- functional notation. Replace call node with operator node, so
5893 -- that actuals can be resolved appropriately.
5895 if Is_Predefined_Op
(Nam
) or else Ekind
(Nam
) = E_Operator
then
5896 Make_Call_Into_Operator
(N
, Typ
, Entity
(Name
(N
)));
5899 elsif Present
(Alias
(Nam
))
5900 and then Is_Predefined_Op
(Alias
(Nam
))
5902 Resolve_Actuals
(N
, Nam
);
5903 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
5907 -- Create a transient scope if the resulting type requires it
5909 -- There are several notable exceptions:
5911 -- a) In init procs, the transient scope overhead is not needed, and is
5912 -- even incorrect when the call is a nested initialization call for a
5913 -- component whose expansion may generate adjust calls. However, if the
5914 -- call is some other procedure call within an initialization procedure
5915 -- (for example a call to Create_Task in the init_proc of the task
5916 -- run-time record) a transient scope must be created around this call.
5918 -- b) Enumeration literal pseudo-calls need no transient scope
5920 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5921 -- functions) do not use the secondary stack even though the return
5922 -- type may be unconstrained.
5924 -- d) Calls to a build-in-place function, since such functions may
5925 -- allocate their result directly in a target object, and cases where
5926 -- the result does get allocated in the secondary stack are checked for
5927 -- within the specialized Exp_Ch6 procedures for expanding those
5928 -- build-in-place calls.
5930 -- e) If the subprogram is marked Inline_Always, then even if it returns
5931 -- an unconstrained type the call does not require use of the secondary
5932 -- stack. However, inlining will only take place if the body to inline
5933 -- is already present. It may not be available if e.g. the subprogram is
5934 -- declared in a child instance.
5936 -- If this is an initialization call for a type whose construction
5937 -- uses the secondary stack, and it is not a nested call to initialize
5938 -- a component, we do need to create a transient scope for it. We
5939 -- check for this by traversing the type in Check_Initialization_Call.
5942 and then Has_Pragma_Inline
(Nam
)
5943 and then Nkind
(Unit_Declaration_Node
(Nam
)) = N_Subprogram_Declaration
5944 and then Present
(Body_To_Inline
(Unit_Declaration_Node
(Nam
)))
5948 elsif Ekind
(Nam
) = E_Enumeration_Literal
5949 or else Is_Build_In_Place_Function
(Nam
)
5950 or else Is_Intrinsic_Subprogram
(Nam
)
5954 elsif Expander_Active
5955 and then Is_Type
(Etype
(Nam
))
5956 and then Requires_Transient_Scope
(Etype
(Nam
))
5958 (not Within_Init_Proc
5960 (not Is_Init_Proc
(Nam
) and then Ekind
(Nam
) /= E_Function
))
5962 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
5964 -- If the call appears within the bounds of a loop, it will
5965 -- be rewritten and reanalyzed, nothing left to do here.
5967 if Nkind
(N
) /= N_Function_Call
then
5971 elsif Is_Init_Proc
(Nam
)
5972 and then not Within_Init_Proc
5974 Check_Initialization_Call
(N
, Nam
);
5977 -- A protected function cannot be called within the definition of the
5978 -- enclosing protected type.
5980 if Is_Protected_Type
(Scope
(Nam
))
5981 and then In_Open_Scopes
(Scope
(Nam
))
5982 and then not Has_Completion
(Scope
(Nam
))
5985 ("& cannot be called before end of protected definition", N
, Nam
);
5988 -- Propagate interpretation to actuals, and add default expressions
5991 if Present
(First_Formal
(Nam
)) then
5992 Resolve_Actuals
(N
, Nam
);
5994 -- Overloaded literals are rewritten as function calls, for purpose of
5995 -- resolution. After resolution, we can replace the call with the
5998 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
5999 Copy_Node
(Subp
, N
);
6000 Resolve_Entity_Name
(N
, Typ
);
6002 -- Avoid validation, since it is a static function call
6004 Generate_Reference
(Nam
, Subp
);
6008 -- If the subprogram is not global, then kill all saved values and
6009 -- checks. This is a bit conservative, since in many cases we could do
6010 -- better, but it is not worth the effort. Similarly, we kill constant
6011 -- values. However we do not need to do this for internal entities
6012 -- (unless they are inherited user-defined subprograms), since they
6013 -- are not in the business of molesting local values.
6015 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
6016 -- kill all checks and values for calls to global subprograms. This
6017 -- takes care of the case where an access to a local subprogram is
6018 -- taken, and could be passed directly or indirectly and then called
6019 -- from almost any context.
6021 -- Note: we do not do this step till after resolving the actuals. That
6022 -- way we still take advantage of the current value information while
6023 -- scanning the actuals.
6025 -- We suppress killing values if we are processing the nodes associated
6026 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
6027 -- type kills all the values as part of analyzing the code that
6028 -- initializes the dispatch tables.
6030 if Inside_Freezing_Actions
= 0
6031 and then (not Is_Library_Level_Entity
(Nam
)
6032 or else Suppress_Value_Tracking_On_Call
6033 (Nearest_Dynamic_Scope
(Current_Scope
)))
6034 and then (Comes_From_Source
(Nam
)
6035 or else (Present
(Alias
(Nam
))
6036 and then Comes_From_Source
(Alias
(Nam
))))
6038 Kill_Current_Values
;
6041 -- If we are warning about unread OUT parameters, this is the place to
6042 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
6043 -- after the above call to Kill_Current_Values (since that call clears
6044 -- the Last_Assignment field of all local variables).
6046 if (Warn_On_Modified_Unread
or Warn_On_All_Unread_Out_Parameters
)
6047 and then Comes_From_Source
(N
)
6048 and then In_Extended_Main_Source_Unit
(N
)
6055 F
:= First_Formal
(Nam
);
6056 A
:= First_Actual
(N
);
6057 while Present
(F
) and then Present
(A
) loop
6058 if Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
)
6059 and then Warn_On_Modified_As_Out_Parameter
(F
)
6060 and then Is_Entity_Name
(A
)
6061 and then Present
(Entity
(A
))
6062 and then Comes_From_Source
(N
)
6063 and then Safe_To_Capture_Value
(N
, Entity
(A
))
6065 Set_Last_Assignment
(Entity
(A
), A
);
6074 -- If the subprogram is a primitive operation, check whether or not
6075 -- it is a correct dispatching call.
6077 if Is_Overloadable
(Nam
)
6078 and then Is_Dispatching_Operation
(Nam
)
6080 Check_Dispatching_Call
(N
);
6082 elsif Ekind
(Nam
) /= E_Subprogram_Type
6083 and then Is_Abstract_Subprogram
(Nam
)
6084 and then not In_Instance
6086 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Nam
);
6089 -- If this is a dispatching call, generate the appropriate reference,
6090 -- for better source navigation in GPS.
6092 if Is_Overloadable
(Nam
)
6093 and then Present
(Controlling_Argument
(N
))
6095 Generate_Reference
(Nam
, Subp
, 'R');
6097 -- Normal case, not a dispatching call: generate a call reference
6100 Generate_Reference
(Nam
, Subp
, 's');
6103 if Is_Intrinsic_Subprogram
(Nam
) then
6104 Check_Intrinsic_Call
(N
);
6107 -- Check for violation of restriction No_Specific_Termination_Handlers
6108 -- and warn on a potentially blocking call to Abort_Task.
6110 if Restriction_Check_Required
(No_Specific_Termination_Handlers
)
6111 and then (Is_RTE
(Nam
, RE_Set_Specific_Handler
)
6113 Is_RTE
(Nam
, RE_Specific_Handler
))
6115 Check_Restriction
(No_Specific_Termination_Handlers
, N
);
6117 elsif Is_RTE
(Nam
, RE_Abort_Task
) then
6118 Check_Potentially_Blocking_Operation
(N
);
6121 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
6122 -- timing event violates restriction No_Relative_Delay (AI-0211). We
6123 -- need to check the second argument to determine whether it is an
6124 -- absolute or relative timing event.
6126 if Restriction_Check_Required
(No_Relative_Delay
)
6127 and then Is_RTE
(Nam
, RE_Set_Handler
)
6128 and then Is_RTE
(Etype
(Next_Actual
(First_Actual
(N
))), RE_Time_Span
)
6130 Check_Restriction
(No_Relative_Delay
, N
);
6133 -- Issue an error for a call to an eliminated subprogram. This routine
6134 -- will not perform the check if the call appears within a default
6137 Check_For_Eliminated_Subprogram
(Subp
, Nam
);
6139 -- In formal mode, the primitive operations of a tagged type or type
6140 -- extension do not include functions that return the tagged type.
6142 if Nkind
(N
) = N_Function_Call
6143 and then Is_Tagged_Type
(Etype
(N
))
6144 and then Is_Entity_Name
(Name
(N
))
6145 and then Is_Inherited_Operation_For_Type
(Entity
(Name
(N
)), Etype
(N
))
6147 Check_SPARK_Restriction
("function not inherited", N
);
6150 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
6151 -- class-wide and the call dispatches on result in a context that does
6152 -- not provide a tag, the call raises Program_Error.
6154 if Nkind
(N
) = N_Function_Call
6155 and then In_Instance
6156 and then Is_Generic_Actual_Type
(Typ
)
6157 and then Is_Class_Wide_Type
(Typ
)
6158 and then Has_Controlling_Result
(Nam
)
6159 and then Nkind
(Parent
(N
)) = N_Object_Declaration
6161 -- Verify that none of the formals are controlling
6164 Call_OK
: Boolean := False;
6168 F
:= First_Formal
(Nam
);
6169 while Present
(F
) loop
6170 if Is_Controlling_Formal
(F
) then
6179 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6180 Error_Msg_N
("!cannot determine tag of result<<", N
);
6181 Error_Msg_N
("\Program_Error [<<!", N
);
6183 Make_Raise_Program_Error
(Sloc
(N
),
6184 Reason
=> PE_Explicit_Raise
));
6189 -- Check for calling a function with OUT or IN OUT parameter when the
6190 -- calling context (us right now) is not Ada 2012, so does not allow
6191 -- OUT or IN OUT parameters in function calls.
6193 if Ada_Version
< Ada_2012
6194 and then Ekind
(Nam
) = E_Function
6195 and then Has_Out_Or_In_Out_Parameter
(Nam
)
6197 Error_Msg_NE
("& has at least one OUT or `IN OUT` parameter", N
, Nam
);
6198 Error_Msg_N
("\call to this function only allowed in Ada 2012", N
);
6201 -- Check the dimensions of the actuals in the call. For function calls,
6202 -- propagate the dimensions from the returned type to N.
6204 Analyze_Dimension_Call
(N
, Nam
);
6206 -- All done, evaluate call and deal with elaboration issues
6209 Check_Elab_Call
(N
);
6211 -- In GNATprove mode, expansion is disabled, but we want to inline some
6212 -- subprograms to facilitate formal verification. Indirect calls through
6213 -- a subprogram type or within a generic cannot be inlined. Inlining is
6214 -- performed only for calls subject to SPARK_Mode on.
6217 and then SPARK_Mode
= On
6218 and then Is_Overloadable
(Nam
)
6219 and then not Inside_A_Generic
6221 -- Retrieve the body to inline from the ultimate alias of Nam, if
6222 -- there is one, otherwise calls that should be inlined end up not
6226 Nam_UA
: constant Entity_Id
:= Ultimate_Alias
(Nam
);
6227 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Nam_UA
);
6228 Body_Id
: constant Entity_Id
:= Corresponding_Body
(Decl
);
6231 -- If the subprogram is not eligible for inlining in GNATprove
6232 -- mode, do nothing.
6234 if Nkind
(Decl
) /= N_Subprogram_Declaration
6235 or else 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 -- Inlining should not be performed during pre-analysis
6250 elsif Full_Analysis
then
6252 -- With the one-pass inlining technique, a call cannot be
6253 -- inlined if the corresponding body has not been seen yet.
6255 if No
(Body_Id
) then
6257 ("?no contextual analysis of & (body not seen yet)",
6259 Set_Is_Inlined_Always
(Nam_UA
, False);
6261 -- Nothing to do if there is no body to inline, indicating that
6262 -- the subprogram is not suitable for inlining in GNATprove
6265 elsif No
(Body_To_Inline
(Decl
)) then
6268 -- Calls cannot be inlined inside potentially unevaluated
6269 -- expressions, as this would create complex actions inside
6270 -- expressions, that are not handled by GNATprove.
6272 elsif Is_Potentially_Unevaluated
(N
) then
6273 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6275 ("\call appears in potentially unevaluated context", N
);
6276 Set_Is_Inlined_Always
(Nam_UA
, False);
6278 -- Otherwise, inline the call
6281 Expand_Inlined_Call
(N
, Nam_UA
, Nam
);
6287 Warn_On_Overlapping_Actuals
(Nam
, N
);
6290 -----------------------------
6291 -- Resolve_Case_Expression --
6292 -----------------------------
6294 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
6298 Alt
:= First
(Alternatives
(N
));
6299 while Present
(Alt
) loop
6300 Resolve
(Expression
(Alt
), Typ
);
6305 Eval_Case_Expression
(N
);
6306 end Resolve_Case_Expression
;
6308 -------------------------------
6309 -- Resolve_Character_Literal --
6310 -------------------------------
6312 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
6313 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
6317 -- Verify that the character does belong to the type of the context
6319 Set_Etype
(N
, B_Typ
);
6320 Eval_Character_Literal
(N
);
6322 -- Wide_Wide_Character literals must always be defined, since the set
6323 -- of wide wide character literals is complete, i.e. if a character
6324 -- literal is accepted by the parser, then it is OK for wide wide
6325 -- character (out of range character literals are rejected).
6327 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
6330 -- Always accept character literal for type Any_Character, which
6331 -- occurs in error situations and in comparisons of literals, both
6332 -- of which should accept all literals.
6334 elsif B_Typ
= Any_Character
then
6337 -- For Standard.Character or a type derived from it, check that the
6338 -- literal is in range.
6340 elsif Root_Type
(B_Typ
) = Standard_Character
then
6341 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
6345 -- For Standard.Wide_Character or a type derived from it, check that the
6346 -- literal is in range.
6348 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
6349 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
6353 -- For Standard.Wide_Wide_Character or a type derived from it, we
6354 -- know the literal is in range, since the parser checked.
6356 elsif Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
6359 -- If the entity is already set, this has already been resolved in a
6360 -- generic context, or comes from expansion. Nothing else to do.
6362 elsif Present
(Entity
(N
)) then
6365 -- Otherwise we have a user defined character type, and we can use the
6366 -- standard visibility mechanisms to locate the referenced entity.
6369 C
:= Current_Entity
(N
);
6370 while Present
(C
) loop
6371 if Etype
(C
) = B_Typ
then
6372 Set_Entity_With_Checks
(N
, C
);
6373 Generate_Reference
(C
, N
);
6381 -- If we fall through, then the literal does not match any of the
6382 -- entries of the enumeration type. This isn't just a constraint error
6383 -- situation, it is an illegality (see RM 4.2).
6386 ("character not defined for }", N
, First_Subtype
(B_Typ
));
6387 end Resolve_Character_Literal
;
6389 ---------------------------
6390 -- Resolve_Comparison_Op --
6391 ---------------------------
6393 -- Context requires a boolean type, and plays no role in resolution.
6394 -- Processing identical to that for equality operators. The result type is
6395 -- the base type, which matters when pathological subtypes of booleans with
6396 -- limited ranges are used.
6398 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6399 L
: constant Node_Id
:= Left_Opnd
(N
);
6400 R
: constant Node_Id
:= Right_Opnd
(N
);
6404 -- If this is an intrinsic operation which is not predefined, use the
6405 -- types of its declared arguments to resolve the possibly overloaded
6406 -- operands. Otherwise the operands are unambiguous and specify the
6409 if Scope
(Entity
(N
)) /= Standard_Standard
then
6410 T
:= Etype
(First_Entity
(Entity
(N
)));
6413 T
:= Find_Unique_Type
(L
, R
);
6415 if T
= Any_Fixed
then
6416 T
:= Unique_Fixed_Point_Type
(L
);
6420 Set_Etype
(N
, Base_Type
(Typ
));
6421 Generate_Reference
(T
, N
, ' ');
6423 -- Skip remaining processing if already set to Any_Type
6425 if T
= Any_Type
then
6429 -- Deal with other error cases
6431 if T
= Any_String
or else
6432 T
= Any_Composite
or else
6435 if T
= Any_Character
then
6436 Ambiguous_Character
(L
);
6438 Error_Msg_N
("ambiguous operands for comparison", N
);
6441 Set_Etype
(N
, Any_Type
);
6445 -- Resolve the operands if types OK
6449 Check_Unset_Reference
(L
);
6450 Check_Unset_Reference
(R
);
6451 Generate_Operator_Reference
(N
, T
);
6452 Check_Low_Bound_Tested
(N
);
6454 -- In SPARK, ordering operators <, <=, >, >= are not defined for Boolean
6455 -- types or array types except String.
6457 if Is_Boolean_Type
(T
) then
6458 Check_SPARK_Restriction
6459 ("comparison is not defined on Boolean type", N
);
6461 elsif Is_Array_Type
(T
)
6462 and then Base_Type
(T
) /= Standard_String
6464 Check_SPARK_Restriction
6465 ("comparison is not defined on array types other than String", N
);
6468 -- Check comparison on unordered enumeration
6470 if Bad_Unordered_Enumeration_Reference
(N
, Etype
(L
)) then
6471 Error_Msg_Sloc
:= Sloc
(Etype
(L
));
6473 ("comparison on unordered enumeration type& declared#?U?",
6477 -- Evaluate the relation (note we do this after the above check since
6478 -- this Eval call may change N to True/False.
6480 Analyze_Dimension
(N
);
6481 Eval_Relational_Op
(N
);
6482 end Resolve_Comparison_Op
;
6484 -----------------------------------------
6485 -- Resolve_Discrete_Subtype_Indication --
6486 -----------------------------------------
6488 procedure Resolve_Discrete_Subtype_Indication
6496 Analyze
(Subtype_Mark
(N
));
6497 S
:= Entity
(Subtype_Mark
(N
));
6499 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
6500 Error_Msg_N
("expect range constraint for discrete type", N
);
6501 Set_Etype
(N
, Any_Type
);
6504 R
:= Range_Expression
(Constraint
(N
));
6512 if Base_Type
(S
) /= Base_Type
(Typ
) then
6514 ("expect subtype of }", N
, First_Subtype
(Typ
));
6516 -- Rewrite the constraint as a range of Typ
6517 -- to allow compilation to proceed further.
6520 Rewrite
(Low_Bound
(R
),
6521 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
6522 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
6523 Attribute_Name
=> Name_First
));
6524 Rewrite
(High_Bound
(R
),
6525 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
6526 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
6527 Attribute_Name
=> Name_First
));
6531 Set_Etype
(N
, Etype
(R
));
6533 -- Additionally, we must check that the bounds are compatible
6534 -- with the given subtype, which might be different from the
6535 -- type of the context.
6537 Apply_Range_Check
(R
, S
);
6539 -- ??? If the above check statically detects a Constraint_Error
6540 -- it replaces the offending bound(s) of the range R with a
6541 -- Constraint_Error node. When the itype which uses these bounds
6542 -- is frozen the resulting call to Duplicate_Subexpr generates
6543 -- a new temporary for the bounds.
6545 -- Unfortunately there are other itypes that are also made depend
6546 -- on these bounds, so when Duplicate_Subexpr is called they get
6547 -- a forward reference to the newly created temporaries and Gigi
6548 -- aborts on such forward references. This is probably sign of a
6549 -- more fundamental problem somewhere else in either the order of
6550 -- itype freezing or the way certain itypes are constructed.
6552 -- To get around this problem we call Remove_Side_Effects right
6553 -- away if either bounds of R are a Constraint_Error.
6556 L
: constant Node_Id
:= Low_Bound
(R
);
6557 H
: constant Node_Id
:= High_Bound
(R
);
6560 if Nkind
(L
) = N_Raise_Constraint_Error
then
6561 Remove_Side_Effects
(L
);
6564 if Nkind
(H
) = N_Raise_Constraint_Error
then
6565 Remove_Side_Effects
(H
);
6569 Check_Unset_Reference
(Low_Bound
(R
));
6570 Check_Unset_Reference
(High_Bound
(R
));
6573 end Resolve_Discrete_Subtype_Indication
;
6575 -------------------------
6576 -- Resolve_Entity_Name --
6577 -------------------------
6579 -- Used to resolve identifiers and expanded names
6581 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
6582 function Appears_In_Check
(Nod
: Node_Id
) return Boolean;
6583 -- Denote whether an arbitrary node Nod appears in a check node
6585 function Is_OK_Volatile_Context
6587 Obj_Ref
: Node_Id
) return Boolean;
6588 -- Determine whether node Context denotes a "non-interfering context"
6589 -- (as defined in SPARK RM 7.1.3(13)) where volatile reference Obj_Ref
6590 -- can safely reside.
6592 ----------------------
6593 -- Appears_In_Check --
6594 ----------------------
6596 function Appears_In_Check
(Nod
: Node_Id
) return Boolean is
6600 -- Climb the parent chain looking for a check node
6603 while Present
(Par
) loop
6604 if Nkind
(Par
) in N_Raise_xxx_Error
then
6607 -- Prevent the search from going too far
6609 elsif Is_Body_Or_Package_Declaration
(Par
) then
6613 Par
:= Parent
(Par
);
6617 end Appears_In_Check
;
6619 ----------------------------
6620 -- Is_OK_Volatile_Context --
6621 ----------------------------
6623 function Is_OK_Volatile_Context
6625 Obj_Ref
: Node_Id
) return Boolean
6628 -- The volatile object appears on either side of an assignment
6630 if Nkind
(Context
) = N_Assignment_Statement
then
6633 -- The volatile object is part of the initialization expression of
6634 -- another object. Ensure that the climb of the parent chain came
6635 -- from the expression side and not from the name side.
6637 elsif Nkind
(Context
) = N_Object_Declaration
6638 and then Present
(Expression
(Context
))
6639 and then Expression
(Context
) = Obj_Ref
6643 -- The volatile object appears as an actual parameter in a call to an
6644 -- instance of Unchecked_Conversion whose result is renamed.
6646 elsif Nkind
(Context
) = N_Function_Call
6647 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
6648 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
6652 -- The volatile object appears as the prefix of a name occurring
6653 -- in a non-interfering context.
6655 elsif Nkind_In
(Context
, N_Attribute_Reference
,
6656 N_Indexed_Component
,
6657 N_Selected_Component
,
6659 and then Prefix
(Context
) = Obj_Ref
6660 and then Is_OK_Volatile_Context
6661 (Context
=> Parent
(Context
),
6666 -- Allow references to volatile objects in various checks. This is
6667 -- not a direct SPARK 2014 requirement.
6669 elsif Appears_In_Check
(Context
) then
6675 end Is_OK_Volatile_Context
;
6679 E
: constant Entity_Id
:= Entity
(N
);
6680 Par
: constant Node_Id
:= Parent
(N
);
6682 -- Start of processing for Resolve_Entity_Name
6685 -- If garbage from errors, set to Any_Type and return
6687 if No
(E
) and then Total_Errors_Detected
/= 0 then
6688 Set_Etype
(N
, Any_Type
);
6692 -- Replace named numbers by corresponding literals. Note that this is
6693 -- the one case where Resolve_Entity_Name must reset the Etype, since
6694 -- it is currently marked as universal.
6696 if Ekind
(E
) = E_Named_Integer
then
6698 Eval_Named_Integer
(N
);
6700 elsif Ekind
(E
) = E_Named_Real
then
6702 Eval_Named_Real
(N
);
6704 -- For enumeration literals, we need to make sure that a proper style
6705 -- check is done, since such literals are overloaded, and thus we did
6706 -- not do a style check during the first phase of analysis.
6708 elsif Ekind
(E
) = E_Enumeration_Literal
then
6709 Set_Entity_With_Checks
(N
, E
);
6710 Eval_Entity_Name
(N
);
6712 -- Case of subtype name appearing as an operand in expression
6714 elsif Is_Type
(E
) then
6716 -- Allow use of subtype if it is a concurrent type where we are
6717 -- currently inside the body. This will eventually be expanded into a
6718 -- call to Self (for tasks) or _object (for protected objects). Any
6719 -- other use of a subtype is invalid.
6721 if Is_Concurrent_Type
(E
)
6722 and then In_Open_Scopes
(E
)
6726 -- Any other use is an error
6730 ("invalid use of subtype mark in expression or call", N
);
6733 -- Check discriminant use if entity is discriminant in current scope,
6734 -- i.e. discriminant of record or concurrent type currently being
6735 -- analyzed. Uses in corresponding body are unrestricted.
6737 elsif Ekind
(E
) = E_Discriminant
6738 and then Scope
(E
) = Current_Scope
6739 and then not Has_Completion
(Current_Scope
)
6741 Check_Discriminant_Use
(N
);
6743 -- A parameterless generic function cannot appear in a context that
6744 -- requires resolution.
6746 elsif Ekind
(E
) = E_Generic_Function
then
6747 Error_Msg_N
("illegal use of generic function", N
);
6749 elsif Ekind
(E
) = E_Out_Parameter
6750 and then Ada_Version
= Ada_83
6751 and then (Nkind
(Parent
(N
)) in N_Op
6752 or else (Nkind
(Parent
(N
)) = N_Assignment_Statement
6753 and then N
= Expression
(Parent
(N
)))
6754 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
)
6756 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
6758 -- In all other cases, just do the possible static evaluation
6761 -- A deferred constant that appears in an expression must have a
6762 -- completion, unless it has been removed by in-place expansion of
6765 if Ekind
(E
) = E_Constant
6766 and then Comes_From_Source
(E
)
6767 and then No
(Constant_Value
(E
))
6768 and then Is_Frozen
(Etype
(E
))
6769 and then not In_Spec_Expression
6770 and then not Is_Imported
(E
)
6772 if No_Initialization
(Parent
(E
))
6773 or else (Present
(Full_View
(E
))
6774 and then No_Initialization
(Parent
(Full_View
(E
))))
6779 "deferred constant is frozen before completion", N
);
6783 Eval_Entity_Name
(N
);
6786 -- An effectively volatile object subject to enabled properties
6787 -- Async_Writers or Effective_Reads must appear in a specific context.
6788 -- The following checks are only relevant when SPARK_Mode is on as they
6789 -- are not standard Ada legality rules.
6792 and then Is_Object
(E
)
6793 and then Is_Effectively_Volatile
(E
)
6794 and then Comes_From_Source
(E
)
6796 (Async_Writers_Enabled
(E
) or else Effective_Reads_Enabled
(E
))
6798 -- The effectively volatile objects appears in a "non-interfering
6799 -- context" as defined in SPARK RM 7.1.3(13).
6801 if Is_OK_Volatile_Context
(Par
, N
) then
6804 -- Assume that references to effectively volatile objects that appear
6805 -- as actual parameters in a procedure call are always legal. The
6806 -- full legality check is done when the actuals are resolved.
6808 elsif Nkind
(Par
) = N_Procedure_Call_Statement
then
6811 -- Otherwise the context causes a side effect with respect to the
6812 -- effectively volatile object.
6816 ("volatile object cannot appear in this context "
6817 & "(SPARK RM 7.1.3(13))", N
);
6820 end Resolve_Entity_Name
;
6826 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
6827 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
6835 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
6836 -- If the bounds of the entry family being called depend on task
6837 -- discriminants, build a new index subtype where a discriminant is
6838 -- replaced with the value of the discriminant of the target task.
6839 -- The target task is the prefix of the entry name in the call.
6841 -----------------------
6842 -- Actual_Index_Type --
6843 -----------------------
6845 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
6846 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
6847 Tsk
: constant Entity_Id
:= Scope
(E
);
6848 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
6849 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
6852 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
6853 -- If the bound is given by a discriminant, replace with a reference
6854 -- to the discriminant of the same name in the target task. If the
6855 -- entry name is the target of a requeue statement and the entry is
6856 -- in the current protected object, the bound to be used is the
6857 -- discriminal of the object (see Apply_Range_Checks for details of
6858 -- the transformation).
6860 -----------------------------
6861 -- Actual_Discriminant_Ref --
6862 -----------------------------
6864 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
6865 Typ
: constant Entity_Id
:= Etype
(Bound
);
6869 Remove_Side_Effects
(Bound
);
6871 if not Is_Entity_Name
(Bound
)
6872 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
6876 elsif Is_Protected_Type
(Tsk
)
6877 and then In_Open_Scopes
(Tsk
)
6878 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
6880 -- Note: here Bound denotes a discriminant of the corresponding
6881 -- record type tskV, whose discriminal is a formal of the
6882 -- init-proc tskVIP. What we want is the body discriminal,
6883 -- which is associated to the discriminant of the original
6884 -- concurrent type tsk.
6886 return New_Occurrence_Of
6887 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
6891 Make_Selected_Component
(Loc
,
6892 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
6893 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
6898 end Actual_Discriminant_Ref
;
6900 -- Start of processing for Actual_Index_Type
6903 if not Has_Discriminants
(Tsk
)
6904 or else (not Is_Entity_Name
(Lo
) and then not Is_Entity_Name
(Hi
))
6906 return Entry_Index_Type
(E
);
6909 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
6910 Set_Etype
(New_T
, Base_Type
(Typ
));
6911 Set_Size_Info
(New_T
, Typ
);
6912 Set_RM_Size
(New_T
, RM_Size
(Typ
));
6913 Set_Scalar_Range
(New_T
,
6914 Make_Range
(Sloc
(Entry_Name
),
6915 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
6916 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
6920 end Actual_Index_Type
;
6922 -- Start of processing of Resolve_Entry
6925 -- Find name of entry being called, and resolve prefix of name with its
6926 -- own type. The prefix can be overloaded, and the name and signature of
6927 -- the entry must be taken into account.
6929 if Nkind
(Entry_Name
) = N_Indexed_Component
then
6931 -- Case of dealing with entry family within the current tasks
6933 E_Name
:= Prefix
(Entry_Name
);
6936 E_Name
:= Entry_Name
;
6939 if Is_Entity_Name
(E_Name
) then
6941 -- Entry call to an entry (or entry family) in the current task. This
6942 -- is legal even though the task will deadlock. Rewrite as call to
6945 -- This can also be a call to an entry in an enclosing task. If this
6946 -- is a single task, we have to retrieve its name, because the scope
6947 -- of the entry is the task type, not the object. If the enclosing
6948 -- task is a task type, the identity of the task is given by its own
6951 -- Finally this can be a requeue on an entry of the same task or
6952 -- protected object.
6954 S
:= Scope
(Entity
(E_Name
));
6956 for J
in reverse 0 .. Scope_Stack
.Last
loop
6957 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
6958 and then not Comes_From_Source
(S
)
6960 -- S is an enclosing task or protected object. The concurrent
6961 -- declaration has been converted into a type declaration, and
6962 -- the object itself has an object declaration that follows
6963 -- the type in the same declarative part.
6965 Tsk
:= Next_Entity
(S
);
6966 while Etype
(Tsk
) /= S
loop
6973 elsif S
= Scope_Stack
.Table
(J
).Entity
then
6975 -- Call to current task. Will be transformed into call to Self
6983 Make_Selected_Component
(Loc
,
6984 Prefix
=> New_Occurrence_Of
(S
, Loc
),
6986 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
6987 Rewrite
(E_Name
, New_N
);
6990 elsif Nkind
(Entry_Name
) = N_Selected_Component
6991 and then Is_Overloaded
(Prefix
(Entry_Name
))
6993 -- Use the entry name (which must be unique at this point) to find
6994 -- the prefix that returns the corresponding task/protected type.
6997 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
6998 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
7003 Get_First_Interp
(Pref
, I
, It
);
7004 while Present
(It
.Typ
) loop
7005 if Scope
(Ent
) = It
.Typ
then
7006 Set_Etype
(Pref
, It
.Typ
);
7010 Get_Next_Interp
(I
, It
);
7015 if Nkind
(Entry_Name
) = N_Selected_Component
then
7016 Resolve
(Prefix
(Entry_Name
));
7018 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7019 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7020 Resolve
(Prefix
(Prefix
(Entry_Name
)));
7021 Index
:= First
(Expressions
(Entry_Name
));
7022 Resolve
(Index
, Entry_Index_Type
(Nam
));
7024 -- Up to this point the expression could have been the actual in a
7025 -- simple entry call, and be given by a named association.
7027 if Nkind
(Index
) = N_Parameter_Association
then
7028 Error_Msg_N
("expect expression for entry index", Index
);
7030 Apply_Range_Check
(Index
, Actual_Index_Type
(Nam
));
7035 ------------------------
7036 -- Resolve_Entry_Call --
7037 ------------------------
7039 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
7040 Entry_Name
: constant Node_Id
:= Name
(N
);
7041 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
7043 First_Named
: Node_Id
;
7050 -- We kill all checks here, because it does not seem worth the effort to
7051 -- do anything better, an entry call is a big operation.
7055 -- Processing of the name is similar for entry calls and protected
7056 -- operation calls. Once the entity is determined, we can complete
7057 -- the resolution of the actuals.
7059 -- The selector may be overloaded, in the case of a protected object
7060 -- with overloaded functions. The type of the context is used for
7063 if Nkind
(Entry_Name
) = N_Selected_Component
7064 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
7065 and then Typ
/= Standard_Void_Type
7072 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
7073 while Present
(It
.Typ
) loop
7074 if Covers
(Typ
, It
.Typ
) then
7075 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
7076 Set_Etype
(Entry_Name
, It
.Typ
);
7078 Generate_Reference
(It
.Typ
, N
, ' ');
7081 Get_Next_Interp
(I
, It
);
7086 Resolve_Entry
(Entry_Name
);
7088 if Nkind
(Entry_Name
) = N_Selected_Component
then
7090 -- Simple entry call
7092 Nam
:= Entity
(Selector_Name
(Entry_Name
));
7093 Obj
:= Prefix
(Entry_Name
);
7094 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
7096 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7098 -- Call to member of entry family
7100 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7101 Obj
:= Prefix
(Prefix
(Entry_Name
));
7102 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
7105 -- We cannot in general check the maximum depth of protected entry calls
7106 -- at compile time. But we can tell that any protected entry call at all
7107 -- violates a specified nesting depth of zero.
7109 if Is_Protected_Type
(Scope
(Nam
)) then
7110 Check_Restriction
(Max_Entry_Queue_Length
, N
);
7113 -- Use context type to disambiguate a protected function that can be
7114 -- called without actuals and that returns an array type, and where the
7115 -- argument list may be an indexing of the returned value.
7117 if Ekind
(Nam
) = E_Function
7118 and then Needs_No_Actuals
(Nam
)
7119 and then Present
(Parameter_Associations
(N
))
7121 ((Is_Array_Type
(Etype
(Nam
))
7122 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
7124 or else (Is_Access_Type
(Etype
(Nam
))
7125 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
7129 Component_Type
(Designated_Type
(Etype
(Nam
))))))
7132 Index_Node
: Node_Id
;
7136 Make_Indexed_Component
(Loc
,
7138 Make_Function_Call
(Loc
, Name
=> Relocate_Node
(Entry_Name
)),
7139 Expressions
=> Parameter_Associations
(N
));
7141 -- Since we are correcting a node classification error made by the
7142 -- parser, we call Replace rather than Rewrite.
7144 Replace
(N
, Index_Node
);
7145 Set_Etype
(Prefix
(N
), Etype
(Nam
));
7147 Resolve_Indexed_Component
(N
, Typ
);
7152 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
)
7153 and then Present
(PPC_Wrapper
(Nam
))
7154 and then Current_Scope
/= PPC_Wrapper
(Nam
)
7156 -- Rewrite as call to the precondition wrapper, adding the task
7157 -- object to the list of actuals. If the call is to a member of an
7158 -- entry family, include the index as well.
7162 New_Actuals
: List_Id
;
7165 New_Actuals
:= New_List
(Obj
);
7167 if Nkind
(Entry_Name
) = N_Indexed_Component
then
7168 Append_To
(New_Actuals
,
7169 New_Copy_Tree
(First
(Expressions
(Entry_Name
))));
7172 Append_List
(Parameter_Associations
(N
), New_Actuals
);
7174 Make_Procedure_Call_Statement
(Loc
,
7176 New_Occurrence_Of
(PPC_Wrapper
(Nam
), Loc
),
7177 Parameter_Associations
=> New_Actuals
);
7178 Rewrite
(N
, New_Call
);
7180 -- Preanalyze and resolve new call. Current procedure is called
7181 -- from Resolve_Call, after which expansion will take place.
7183 Preanalyze_And_Resolve
(N
);
7188 -- The operation name may have been overloaded. Order the actuals
7189 -- according to the formals of the resolved entity, and set the return
7190 -- type to that of the operation.
7193 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
7194 pragma Assert
(Norm_OK
);
7195 Set_Etype
(N
, Etype
(Nam
));
7198 Resolve_Actuals
(N
, Nam
);
7199 Check_Internal_Protected_Use
(N
, Nam
);
7201 -- Create a call reference to the entry
7203 Generate_Reference
(Nam
, Entry_Name
, 's');
7205 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
) then
7206 Check_Potentially_Blocking_Operation
(N
);
7209 -- Verify that a procedure call cannot masquerade as an entry
7210 -- call where an entry call is expected.
7212 if Ekind
(Nam
) = E_Procedure
then
7213 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
7214 and then N
= Entry_Call_Statement
(Parent
(N
))
7216 Error_Msg_N
("entry call required in select statement", N
);
7218 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
7219 and then N
= Triggering_Statement
(Parent
(N
))
7221 Error_Msg_N
("triggering statement cannot be procedure call", N
);
7223 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
7224 and then not In_Open_Scopes
(Scope
(Nam
))
7226 Error_Msg_N
("task has no entry with this name", Entry_Name
);
7230 -- After resolution, entry calls and protected procedure calls are
7231 -- changed into entry calls, for expansion. The structure of the node
7232 -- does not change, so it can safely be done in place. Protected
7233 -- function calls must keep their structure because they are
7236 if Ekind
(Nam
) /= E_Function
then
7238 -- A protected operation that is not a function may modify the
7239 -- corresponding object, and cannot apply to a constant. If this
7240 -- is an internal call, the prefix is the type itself.
7242 if Is_Protected_Type
(Scope
(Nam
))
7243 and then not Is_Variable
(Obj
)
7244 and then (not Is_Entity_Name
(Obj
)
7245 or else not Is_Type
(Entity
(Obj
)))
7248 ("prefix of protected procedure or entry call must be variable",
7252 Actuals
:= Parameter_Associations
(N
);
7253 First_Named
:= First_Named_Actual
(N
);
7256 Make_Entry_Call_Statement
(Loc
,
7258 Parameter_Associations
=> Actuals
));
7260 Set_First_Named_Actual
(N
, First_Named
);
7261 Set_Analyzed
(N
, True);
7263 -- Protected functions can return on the secondary stack, in which
7264 -- case we must trigger the transient scope mechanism.
7266 elsif Expander_Active
7267 and then Requires_Transient_Scope
(Etype
(Nam
))
7269 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
7271 end Resolve_Entry_Call
;
7273 -------------------------
7274 -- Resolve_Equality_Op --
7275 -------------------------
7277 -- Both arguments must have the same type, and the boolean context does
7278 -- not participate in the resolution. The first pass verifies that the
7279 -- interpretation is not ambiguous, and the type of the left argument is
7280 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
7281 -- are strings or aggregates, allocators, or Null, they are ambiguous even
7282 -- though they carry a single (universal) type. Diagnose this case here.
7284 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7285 L
: constant Node_Id
:= Left_Opnd
(N
);
7286 R
: constant Node_Id
:= Right_Opnd
(N
);
7287 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
7289 procedure Check_If_Expression
(Cond
: Node_Id
);
7290 -- The resolution rule for if expressions requires that each such must
7291 -- have a unique type. This means that if several dependent expressions
7292 -- are of a non-null anonymous access type, and the context does not
7293 -- impose an expected type (as can be the case in an equality operation)
7294 -- the expression must be rejected.
7296 procedure Explain_Redundancy
(N
: Node_Id
);
7297 -- Attempt to explain the nature of a redundant comparison with True. If
7298 -- the expression N is too complex, this routine issues a general error
7301 function Find_Unique_Access_Type
return Entity_Id
;
7302 -- In the case of allocators and access attributes, the context must
7303 -- provide an indication of the specific access type to be used. If
7304 -- one operand is of such a "generic" access type, check whether there
7305 -- is a specific visible access type that has the same designated type.
7306 -- This is semantically dubious, and of no interest to any real code,
7307 -- but c48008a makes it all worthwhile.
7309 -------------------------
7310 -- Check_If_Expression --
7311 -------------------------
7313 procedure Check_If_Expression
(Cond
: Node_Id
) is
7314 Then_Expr
: Node_Id
;
7315 Else_Expr
: Node_Id
;
7318 if Nkind
(Cond
) = N_If_Expression
then
7319 Then_Expr
:= Next
(First
(Expressions
(Cond
)));
7320 Else_Expr
:= Next
(Then_Expr
);
7322 if Nkind
(Then_Expr
) /= N_Null
7323 and then Nkind
(Else_Expr
) /= N_Null
7325 Error_Msg_N
("cannot determine type of if expression", Cond
);
7328 end Check_If_Expression
;
7330 ------------------------
7331 -- Explain_Redundancy --
7332 ------------------------
7334 procedure Explain_Redundancy
(N
: Node_Id
) is
7342 -- Strip the operand down to an entity
7345 if Nkind
(Val
) = N_Selected_Component
then
7346 Val
:= Selector_Name
(Val
);
7352 -- The construct denotes an entity
7354 if Is_Entity_Name
(Val
) and then Present
(Entity
(Val
)) then
7355 Val_Id
:= Entity
(Val
);
7357 -- Do not generate an error message when the comparison is done
7358 -- against the enumeration literal Standard.True.
7360 if Ekind
(Val_Id
) /= E_Enumeration_Literal
then
7362 -- Build a customized error message
7365 Add_Str_To_Name_Buffer
("?r?");
7367 if Ekind
(Val_Id
) = E_Component
then
7368 Add_Str_To_Name_Buffer
("component ");
7370 elsif Ekind
(Val_Id
) = E_Constant
then
7371 Add_Str_To_Name_Buffer
("constant ");
7373 elsif Ekind
(Val_Id
) = E_Discriminant
then
7374 Add_Str_To_Name_Buffer
("discriminant ");
7376 elsif Is_Formal
(Val_Id
) then
7377 Add_Str_To_Name_Buffer
("parameter ");
7379 elsif Ekind
(Val_Id
) = E_Variable
then
7380 Add_Str_To_Name_Buffer
("variable ");
7383 Add_Str_To_Name_Buffer
("& is always True!");
7386 Error_Msg_NE
(Get_Name_String
(Error
), Val
, Val_Id
);
7389 -- The construct is too complex to disect, issue a general message
7392 Error_Msg_N
("?r?expression is always True!", Val
);
7394 end Explain_Redundancy
;
7396 -----------------------------
7397 -- Find_Unique_Access_Type --
7398 -----------------------------
7400 function Find_Unique_Access_Type
return Entity_Id
is
7406 if Ekind_In
(Etype
(R
), E_Allocator_Type
,
7407 E_Access_Attribute_Type
)
7409 Acc
:= Designated_Type
(Etype
(R
));
7411 elsif Ekind_In
(Etype
(L
), E_Allocator_Type
,
7412 E_Access_Attribute_Type
)
7414 Acc
:= Designated_Type
(Etype
(L
));
7420 while S
/= Standard_Standard
loop
7421 E
:= First_Entity
(S
);
7422 while Present
(E
) loop
7424 and then Is_Access_Type
(E
)
7425 and then Ekind
(E
) /= E_Allocator_Type
7426 and then Designated_Type
(E
) = Base_Type
(Acc
)
7438 end Find_Unique_Access_Type
;
7440 -- Start of processing for Resolve_Equality_Op
7443 Set_Etype
(N
, Base_Type
(Typ
));
7444 Generate_Reference
(T
, N
, ' ');
7446 if T
= Any_Fixed
then
7447 T
:= Unique_Fixed_Point_Type
(L
);
7450 if T
/= Any_Type
then
7451 if T
= Any_String
or else
7452 T
= Any_Composite
or else
7455 if T
= Any_Character
then
7456 Ambiguous_Character
(L
);
7458 Error_Msg_N
("ambiguous operands for equality", N
);
7461 Set_Etype
(N
, Any_Type
);
7464 elsif T
= Any_Access
7465 or else Ekind_In
(T
, E_Allocator_Type
, E_Access_Attribute_Type
)
7467 T
:= Find_Unique_Access_Type
;
7470 Error_Msg_N
("ambiguous operands for equality", N
);
7471 Set_Etype
(N
, Any_Type
);
7475 -- If expressions must have a single type, and if the context does
7476 -- not impose one the dependent expressions cannot be anonymous
7479 -- Why no similar processing for case expressions???
7481 elsif Ada_Version
>= Ada_2012
7482 and then Ekind_In
(Etype
(L
), E_Anonymous_Access_Type
,
7483 E_Anonymous_Access_Subprogram_Type
)
7484 and then Ekind_In
(Etype
(R
), E_Anonymous_Access_Type
,
7485 E_Anonymous_Access_Subprogram_Type
)
7487 Check_If_Expression
(L
);
7488 Check_If_Expression
(R
);
7494 -- In SPARK, equality operators = and /= for array types other than
7495 -- String are only defined when, for each index position, the
7496 -- operands have equal static bounds.
7498 if Is_Array_Type
(T
) then
7500 -- Protect call to Matching_Static_Array_Bounds to avoid costly
7501 -- operation if not needed.
7503 if Restriction_Check_Required
(SPARK_05
)
7504 and then Base_Type
(T
) /= Standard_String
7505 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
7506 and then Etype
(L
) /= Any_Composite
-- or else L in error
7507 and then Etype
(R
) /= Any_Composite
-- or else R in error
7508 and then not Matching_Static_Array_Bounds
(Etype
(L
), Etype
(R
))
7510 Check_SPARK_Restriction
7511 ("array types should have matching static bounds", N
);
7515 -- If the unique type is a class-wide type then it will be expanded
7516 -- into a dispatching call to the predefined primitive. Therefore we
7517 -- check here for potential violation of such restriction.
7519 if Is_Class_Wide_Type
(T
) then
7520 Check_Restriction
(No_Dispatching_Calls
, N
);
7523 if Warn_On_Redundant_Constructs
7524 and then Comes_From_Source
(N
)
7525 and then Comes_From_Source
(R
)
7526 and then Is_Entity_Name
(R
)
7527 and then Entity
(R
) = Standard_True
7529 Error_Msg_N
-- CODEFIX
7530 ("?r?comparison with True is redundant!", N
);
7531 Explain_Redundancy
(Original_Node
(R
));
7534 Check_Unset_Reference
(L
);
7535 Check_Unset_Reference
(R
);
7536 Generate_Operator_Reference
(N
, T
);
7537 Check_Low_Bound_Tested
(N
);
7539 -- If this is an inequality, it may be the implicit inequality
7540 -- created for a user-defined operation, in which case the corres-
7541 -- ponding equality operation is not intrinsic, and the operation
7542 -- cannot be constant-folded. Else fold.
7544 if Nkind
(N
) = N_Op_Eq
7545 or else Comes_From_Source
(Entity
(N
))
7546 or else Ekind
(Entity
(N
)) = E_Operator
7547 or else Is_Intrinsic_Subprogram
7548 (Corresponding_Equality
(Entity
(N
)))
7550 Analyze_Dimension
(N
);
7551 Eval_Relational_Op
(N
);
7553 elsif Nkind
(N
) = N_Op_Ne
7554 and then Is_Abstract_Subprogram
(Entity
(N
))
7556 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Entity
(N
));
7559 -- Ada 2005: If one operand is an anonymous access type, convert the
7560 -- other operand to it, to ensure that the underlying types match in
7561 -- the back-end. Same for access_to_subprogram, and the conversion
7562 -- verifies that the types are subtype conformant.
7564 -- We apply the same conversion in the case one of the operands is a
7565 -- private subtype of the type of the other.
7567 -- Why the Expander_Active test here ???
7571 (Ekind_In
(T
, E_Anonymous_Access_Type
,
7572 E_Anonymous_Access_Subprogram_Type
)
7573 or else Is_Private_Type
(T
))
7575 if Etype
(L
) /= T
then
7577 Make_Unchecked_Type_Conversion
(Sloc
(L
),
7578 Subtype_Mark
=> New_Occurrence_Of
(T
, Sloc
(L
)),
7579 Expression
=> Relocate_Node
(L
)));
7580 Analyze_And_Resolve
(L
, T
);
7583 if (Etype
(R
)) /= T
then
7585 Make_Unchecked_Type_Conversion
(Sloc
(R
),
7586 Subtype_Mark
=> New_Occurrence_Of
(Etype
(L
), Sloc
(R
)),
7587 Expression
=> Relocate_Node
(R
)));
7588 Analyze_And_Resolve
(R
, T
);
7592 end Resolve_Equality_Op
;
7594 ----------------------------------
7595 -- Resolve_Explicit_Dereference --
7596 ----------------------------------
7598 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
7599 Loc
: constant Source_Ptr
:= Sloc
(N
);
7601 P
: constant Node_Id
:= Prefix
(N
);
7604 -- The candidate prefix type, if overloaded
7610 Check_Fully_Declared_Prefix
(Typ
, P
);
7613 -- A useful optimization: check whether the dereference denotes an
7614 -- element of a container, and if so rewrite it as a call to the
7615 -- corresponding Element function.
7617 -- Disabled for now, on advice of ARG. A more restricted form of the
7618 -- predicate might be acceptable ???
7620 -- if Is_Container_Element (N) then
7624 if Is_Overloaded
(P
) then
7626 -- Use the context type to select the prefix that has the correct
7627 -- designated type. Keep the first match, which will be the inner-
7630 Get_First_Interp
(P
, I
, It
);
7632 while Present
(It
.Typ
) loop
7633 if Is_Access_Type
(It
.Typ
)
7634 and then Covers
(Typ
, Designated_Type
(It
.Typ
))
7640 -- Remove access types that do not match, but preserve access
7641 -- to subprogram interpretations, in case a further dereference
7642 -- is needed (see below).
7644 elsif Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7648 Get_Next_Interp
(I
, It
);
7651 if Present
(P_Typ
) then
7653 Set_Etype
(N
, Designated_Type
(P_Typ
));
7656 -- If no interpretation covers the designated type of the prefix,
7657 -- this is the pathological case where not all implementations of
7658 -- the prefix allow the interpretation of the node as a call. Now
7659 -- that the expected type is known, Remove other interpretations
7660 -- from prefix, rewrite it as a call, and resolve again, so that
7661 -- the proper call node is generated.
7663 Get_First_Interp
(P
, I
, It
);
7664 while Present
(It
.Typ
) loop
7665 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7669 Get_Next_Interp
(I
, It
);
7673 Make_Function_Call
(Loc
,
7675 Make_Explicit_Dereference
(Loc
,
7677 Parameter_Associations
=> New_List
);
7679 Save_Interps
(N
, New_N
);
7681 Analyze_And_Resolve
(N
, Typ
);
7685 -- If not overloaded, resolve P with its own type
7691 if Is_Access_Type
(Etype
(P
)) then
7692 Apply_Access_Check
(N
);
7695 -- If the designated type is a packed unconstrained array type, and the
7696 -- explicit dereference is not in the context of an attribute reference,
7697 -- then we must compute and set the actual subtype, since it is needed
7698 -- by Gigi. The reason we exclude the attribute case is that this is
7699 -- handled fine by Gigi, and in fact we use such attributes to build the
7700 -- actual subtype. We also exclude generated code (which builds actual
7701 -- subtypes directly if they are needed).
7703 if Is_Array_Type
(Etype
(N
))
7704 and then Is_Packed
(Etype
(N
))
7705 and then not Is_Constrained
(Etype
(N
))
7706 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
7707 and then Comes_From_Source
(N
)
7709 Set_Etype
(N
, Get_Actual_Subtype
(N
));
7712 -- Note: No Eval processing is required for an explicit dereference,
7713 -- because such a name can never be static.
7715 end Resolve_Explicit_Dereference
;
7717 -------------------------------------
7718 -- Resolve_Expression_With_Actions --
7719 -------------------------------------
7721 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
7725 -- If N has no actions, and its expression has been constant folded,
7726 -- then rewrite N as just its expression. Note, we can't do this in
7727 -- the general case of Is_Empty_List (Actions (N)) as this would cause
7728 -- Expression (N) to be expanded again.
7730 if Is_Empty_List
(Actions
(N
))
7731 and then Compile_Time_Known_Value
(Expression
(N
))
7733 Rewrite
(N
, Expression
(N
));
7735 end Resolve_Expression_With_Actions
;
7737 ----------------------------------
7738 -- Resolve_Generalized_Indexing --
7739 ----------------------------------
7741 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
) is
7742 Indexing
: constant Node_Id
:= Generalized_Indexing
(N
);
7748 -- In ASIS mode, propagate the information about the indices back to
7749 -- to the original indexing node. The generalized indexing is either
7750 -- a function call, or a dereference of one. The actuals include the
7751 -- prefix of the original node, which is the container expression.
7754 Resolve
(Indexing
, Typ
);
7755 Set_Etype
(N
, Etype
(Indexing
));
7756 Set_Is_Overloaded
(N
, False);
7759 while Nkind_In
(Call
, N_Explicit_Dereference
, N_Selected_Component
)
7761 Call
:= Prefix
(Call
);
7764 if Nkind
(Call
) = N_Function_Call
then
7765 Indices
:= Parameter_Associations
(Call
);
7766 Pref
:= Remove_Head
(Indices
);
7767 Set_Expressions
(N
, Indices
);
7768 Set_Prefix
(N
, Pref
);
7772 Rewrite
(N
, Indexing
);
7775 end Resolve_Generalized_Indexing
;
7777 ---------------------------
7778 -- Resolve_If_Expression --
7779 ---------------------------
7781 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7782 Condition
: constant Node_Id
:= First
(Expressions
(N
));
7783 Then_Expr
: constant Node_Id
:= Next
(Condition
);
7784 Else_Expr
: Node_Id
:= Next
(Then_Expr
);
7785 Else_Typ
: Entity_Id
;
7786 Then_Typ
: Entity_Id
;
7789 Resolve
(Condition
, Any_Boolean
);
7790 Resolve
(Then_Expr
, Typ
);
7791 Then_Typ
:= Etype
(Then_Expr
);
7793 -- When the "then" expression is of a scalar subtype different from the
7794 -- result subtype, then insert a conversion to ensure the generation of
7795 -- a constraint check. The same is done for the else part below, again
7796 -- comparing subtypes rather than base types.
7798 if Is_Scalar_Type
(Then_Typ
)
7799 and then Then_Typ
/= Typ
7801 Rewrite
(Then_Expr
, Convert_To
(Typ
, Then_Expr
));
7802 Analyze_And_Resolve
(Then_Expr
, Typ
);
7805 -- If ELSE expression present, just resolve using the determined type
7807 if Present
(Else_Expr
) then
7808 Resolve
(Else_Expr
, Typ
);
7809 Else_Typ
:= Etype
(Else_Expr
);
7811 if Is_Scalar_Type
(Else_Typ
)
7812 and then Else_Typ
/= Typ
7814 Rewrite
(Else_Expr
, Convert_To
(Typ
, Else_Expr
));
7815 Analyze_And_Resolve
(Else_Expr
, Typ
);
7818 -- If no ELSE expression is present, root type must be Standard.Boolean
7819 -- and we provide a Standard.True result converted to the appropriate
7820 -- Boolean type (in case it is a derived boolean type).
7822 elsif Root_Type
(Typ
) = Standard_Boolean
then
7824 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
7825 Analyze_And_Resolve
(Else_Expr
, Typ
);
7826 Append_To
(Expressions
(N
), Else_Expr
);
7829 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
7830 Append_To
(Expressions
(N
), Error
);
7834 Eval_If_Expression
(N
);
7835 end Resolve_If_Expression
;
7837 -------------------------------
7838 -- Resolve_Indexed_Component --
7839 -------------------------------
7841 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
7842 Name
: constant Node_Id
:= Prefix
(N
);
7844 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
7848 if Present
(Generalized_Indexing
(N
)) then
7849 Resolve_Generalized_Indexing
(N
, Typ
);
7853 if Is_Overloaded
(Name
) then
7855 -- Use the context type to select the prefix that yields the correct
7861 I1
: Interp_Index
:= 0;
7862 P
: constant Node_Id
:= Prefix
(N
);
7863 Found
: Boolean := False;
7866 Get_First_Interp
(P
, I
, It
);
7867 while Present
(It
.Typ
) loop
7868 if (Is_Array_Type
(It
.Typ
)
7869 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
7870 or else (Is_Access_Type
(It
.Typ
)
7871 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
7875 Component_Type
(Designated_Type
(It
.Typ
))))
7878 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
7880 if It
= No_Interp
then
7881 Error_Msg_N
("ambiguous prefix for indexing", N
);
7887 Array_Type
:= It
.Typ
;
7893 Array_Type
:= It
.Typ
;
7898 Get_Next_Interp
(I
, It
);
7903 Array_Type
:= Etype
(Name
);
7906 Resolve
(Name
, Array_Type
);
7907 Array_Type
:= Get_Actual_Subtype_If_Available
(Name
);
7909 -- If prefix is access type, dereference to get real array type.
7910 -- Note: we do not apply an access check because the expander always
7911 -- introduces an explicit dereference, and the check will happen there.
7913 if Is_Access_Type
(Array_Type
) then
7914 Array_Type
:= Designated_Type
(Array_Type
);
7917 -- If name was overloaded, set component type correctly now
7918 -- If a misplaced call to an entry family (which has no index types)
7919 -- return. Error will be diagnosed from calling context.
7921 if Is_Array_Type
(Array_Type
) then
7922 Set_Etype
(N
, Component_Type
(Array_Type
));
7927 Index
:= First_Index
(Array_Type
);
7928 Expr
:= First
(Expressions
(N
));
7930 -- The prefix may have resolved to a string literal, in which case its
7931 -- etype has a special representation. This is only possible currently
7932 -- if the prefix is a static concatenation, written in functional
7935 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
7936 Resolve
(Expr
, Standard_Positive
);
7939 while Present
(Index
) and Present
(Expr
) loop
7940 Resolve
(Expr
, Etype
(Index
));
7941 Check_Unset_Reference
(Expr
);
7943 if Is_Scalar_Type
(Etype
(Expr
)) then
7944 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
7946 Apply_Range_Check
(Expr
, Get_Actual_Subtype
(Index
));
7954 Analyze_Dimension
(N
);
7956 -- Do not generate the warning on suspicious index if we are analyzing
7957 -- package Ada.Tags; otherwise we will report the warning with the
7958 -- Prims_Ptr field of the dispatch table.
7960 if Scope
(Etype
(Prefix
(N
))) = Standard_Standard
7962 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Prefix
(N
)))),
7965 Warn_On_Suspicious_Index
(Name
, First
(Expressions
(N
)));
7966 Eval_Indexed_Component
(N
);
7969 -- If the array type is atomic, and is packed, and we are in a left side
7970 -- context, then this is worth a warning, since we have a situation
7971 -- where the access to the component may cause extra read/writes of
7972 -- the atomic array object, which could be considered unexpected.
7974 if Nkind
(N
) = N_Indexed_Component
7975 and then (Is_Atomic
(Array_Type
)
7976 or else (Is_Entity_Name
(Prefix
(N
))
7977 and then Is_Atomic
(Entity
(Prefix
(N
)))))
7978 and then Is_Bit_Packed_Array
(Array_Type
)
7979 and then Is_LHS
(N
) = Yes
7981 Error_Msg_N
("??assignment to component of packed atomic array",
7983 Error_Msg_N
("??\may cause unexpected accesses to atomic object",
7986 end Resolve_Indexed_Component
;
7988 -----------------------------
7989 -- Resolve_Integer_Literal --
7990 -----------------------------
7992 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
7995 Eval_Integer_Literal
(N
);
7996 end Resolve_Integer_Literal
;
7998 --------------------------------
7999 -- Resolve_Intrinsic_Operator --
8000 --------------------------------
8002 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
8003 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8008 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
;
8009 -- If the operand is a literal, it cannot be the expression in a
8010 -- conversion. Use a qualified expression instead.
8012 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
is
8013 Loc
: constant Source_Ptr
:= Sloc
(Opnd
);
8016 if Nkind_In
(Opnd
, N_Integer_Literal
, N_Real_Literal
) then
8018 Make_Qualified_Expression
(Loc
,
8019 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
8020 Expression
=> Relocate_Node
(Opnd
));
8024 Res
:= Unchecked_Convert_To
(Btyp
, Opnd
);
8028 end Convert_Operand
;
8030 -- Start of processing for Resolve_Intrinsic_Operator
8033 -- We must preserve the original entity in a generic setting, so that
8034 -- the legality of the operation can be verified in an instance.
8036 if not Expander_Active
then
8041 while Scope
(Op
) /= Standard_Standard
loop
8043 pragma Assert
(Present
(Op
));
8047 Set_Is_Overloaded
(N
, False);
8049 -- If the result or operand types are private, rewrite with unchecked
8050 -- conversions on the operands and the result, to expose the proper
8051 -- underlying numeric type.
8053 if Is_Private_Type
(Typ
)
8054 or else Is_Private_Type
(Etype
(Left_Opnd
(N
)))
8055 or else Is_Private_Type
(Etype
(Right_Opnd
(N
)))
8057 Arg1
:= Convert_Operand
(Left_Opnd
(N
));
8058 -- Unchecked_Convert_To (Btyp, Left_Opnd (N));
8059 -- What on earth is this commented out fragment of code???
8061 if Nkind
(N
) = N_Op_Expon
then
8062 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
8064 Arg2
:= Convert_Operand
(Right_Opnd
(N
));
8067 if Nkind
(Arg1
) = N_Type_Conversion
then
8068 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8071 if Nkind
(Arg2
) = N_Type_Conversion
then
8072 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8075 Set_Left_Opnd
(N
, Arg1
);
8076 Set_Right_Opnd
(N
, Arg2
);
8078 Set_Etype
(N
, Btyp
);
8079 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8082 elsif Typ
/= Etype
(Left_Opnd
(N
))
8083 or else Typ
/= Etype
(Right_Opnd
(N
))
8085 -- Add explicit conversion where needed, and save interpretations in
8086 -- case operands are overloaded.
8088 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
8089 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
8091 if Nkind
(Arg1
) = N_Type_Conversion
then
8092 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8094 Save_Interps
(Left_Opnd
(N
), Arg1
);
8097 if Nkind
(Arg2
) = N_Type_Conversion
then
8098 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8100 Save_Interps
(Right_Opnd
(N
), Arg2
);
8103 Rewrite
(Left_Opnd
(N
), Arg1
);
8104 Rewrite
(Right_Opnd
(N
), Arg2
);
8107 Resolve_Arithmetic_Op
(N
, Typ
);
8110 Resolve_Arithmetic_Op
(N
, Typ
);
8112 end Resolve_Intrinsic_Operator
;
8114 --------------------------------------
8115 -- Resolve_Intrinsic_Unary_Operator --
8116 --------------------------------------
8118 procedure Resolve_Intrinsic_Unary_Operator
8122 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8128 while Scope
(Op
) /= Standard_Standard
loop
8130 pragma Assert
(Present
(Op
));
8135 if Is_Private_Type
(Typ
) then
8136 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
8137 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8139 Set_Right_Opnd
(N
, Arg2
);
8141 Set_Etype
(N
, Btyp
);
8142 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8146 Resolve_Unary_Op
(N
, Typ
);
8148 end Resolve_Intrinsic_Unary_Operator
;
8150 ------------------------
8151 -- Resolve_Logical_Op --
8152 ------------------------
8154 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8158 Check_No_Direct_Boolean_Operators
(N
);
8160 -- Predefined operations on scalar types yield the base type. On the
8161 -- other hand, logical operations on arrays yield the type of the
8162 -- arguments (and the context).
8164 if Is_Array_Type
(Typ
) then
8167 B_Typ
:= Base_Type
(Typ
);
8170 -- The following test is required because the operands of the operation
8171 -- may be literals, in which case the resulting type appears to be
8172 -- compatible with a signed integer type, when in fact it is compatible
8173 -- only with modular types. If the context itself is universal, the
8174 -- operation is illegal.
8176 if not Valid_Boolean_Arg
(Typ
) then
8177 Error_Msg_N
("invalid context for logical operation", N
);
8178 Set_Etype
(N
, Any_Type
);
8181 elsif Typ
= Any_Modular
then
8183 ("no modular type available in this context", N
);
8184 Set_Etype
(N
, Any_Type
);
8187 elsif Is_Modular_Integer_Type
(Typ
)
8188 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
8189 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
8191 Check_For_Visible_Operator
(N
, B_Typ
);
8194 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
8195 -- is active and the result type is standard Boolean (do not mess with
8196 -- ops that return a nonstandard Boolean type, because something strange
8199 -- Note: you might expect this replacement to be done during expansion,
8200 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
8201 -- is used, no part of the right operand of an "and" or "or" operator
8202 -- should be executed if the left operand would short-circuit the
8203 -- evaluation of the corresponding "and then" or "or else". If we left
8204 -- the replacement to expansion time, then run-time checks associated
8205 -- with such operands would be evaluated unconditionally, due to being
8206 -- before the condition prior to the rewriting as short-circuit forms
8207 -- during expansion.
8209 if Short_Circuit_And_Or
8210 and then B_Typ
= Standard_Boolean
8211 and then Nkind_In
(N
, N_Op_And
, N_Op_Or
)
8213 if Nkind
(N
) = N_Op_And
then
8215 Make_And_Then
(Sloc
(N
),
8216 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8217 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8218 Analyze_And_Resolve
(N
, B_Typ
);
8220 -- Case of OR changed to OR ELSE
8224 Make_Or_Else
(Sloc
(N
),
8225 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8226 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8227 Analyze_And_Resolve
(N
, B_Typ
);
8230 -- Return now, since analysis of the rewritten ops will take care of
8231 -- other reference bookkeeping and expression folding.
8236 Resolve
(Left_Opnd
(N
), B_Typ
);
8237 Resolve
(Right_Opnd
(N
), B_Typ
);
8239 Check_Unset_Reference
(Left_Opnd
(N
));
8240 Check_Unset_Reference
(Right_Opnd
(N
));
8242 Set_Etype
(N
, B_Typ
);
8243 Generate_Operator_Reference
(N
, B_Typ
);
8244 Eval_Logical_Op
(N
);
8246 -- In SPARK, logical operations AND, OR and XOR for arrays are defined
8247 -- only when both operands have same static lower and higher bounds. Of
8248 -- course the types have to match, so only check if operands are
8249 -- compatible and the node itself has no errors.
8251 if Is_Array_Type
(B_Typ
)
8252 and then Nkind
(N
) in N_Binary_Op
8255 Left_Typ
: constant Node_Id
:= Etype
(Left_Opnd
(N
));
8256 Right_Typ
: constant Node_Id
:= Etype
(Right_Opnd
(N
));
8259 -- Protect call to Matching_Static_Array_Bounds to avoid costly
8260 -- operation if not needed.
8262 if Restriction_Check_Required
(SPARK_05
)
8263 and then Base_Type
(Left_Typ
) = Base_Type
(Right_Typ
)
8264 and then Left_Typ
/= Any_Composite
-- or Left_Opnd in error
8265 and then Right_Typ
/= Any_Composite
-- or Right_Opnd in error
8266 and then not Matching_Static_Array_Bounds
(Left_Typ
, Right_Typ
)
8268 Check_SPARK_Restriction
8269 ("array types should have matching static bounds", N
);
8274 Check_Function_Writable_Actuals
(N
);
8275 end Resolve_Logical_Op
;
8277 ---------------------------
8278 -- Resolve_Membership_Op --
8279 ---------------------------
8281 -- The context can only be a boolean type, and does not determine the
8282 -- arguments. Arguments should be unambiguous, but the preference rule for
8283 -- universal types applies.
8285 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8286 pragma Warnings
(Off
, Typ
);
8288 L
: constant Node_Id
:= Left_Opnd
(N
);
8289 R
: constant Node_Id
:= Right_Opnd
(N
);
8292 procedure Resolve_Set_Membership
;
8293 -- Analysis has determined a unique type for the left operand. Use it to
8294 -- resolve the disjuncts.
8296 ----------------------------
8297 -- Resolve_Set_Membership --
8298 ----------------------------
8300 procedure Resolve_Set_Membership
is
8302 Ltyp
: constant Entity_Id
:= Etype
(L
);
8307 Alt
:= First
(Alternatives
(N
));
8308 while Present
(Alt
) loop
8310 -- Alternative is an expression, a range
8311 -- or a subtype mark.
8313 if not Is_Entity_Name
(Alt
)
8314 or else not Is_Type
(Entity
(Alt
))
8316 Resolve
(Alt
, Ltyp
);
8322 -- Check for duplicates for discrete case
8324 if Is_Discrete_Type
(Ltyp
) then
8331 Alts
: array (0 .. List_Length
(Alternatives
(N
))) of Ent
;
8335 -- Loop checking duplicates. This is quadratic, but giant sets
8336 -- are unlikely in this context so it's a reasonable choice.
8339 Alt
:= First
(Alternatives
(N
));
8340 while Present
(Alt
) loop
8341 if Is_OK_Static_Expression
(Alt
)
8342 and then (Nkind_In
(Alt
, N_Integer_Literal
,
8343 N_Character_Literal
)
8344 or else Nkind
(Alt
) in N_Has_Entity
)
8347 Alts
(Nalts
) := (Alt
, Expr_Value
(Alt
));
8349 for J
in 1 .. Nalts
- 1 loop
8350 if Alts
(J
).Val
= Alts
(Nalts
).Val
then
8351 Error_Msg_Sloc
:= Sloc
(Alts
(J
).Alt
);
8352 Error_Msg_N
("duplicate of value given#??", Alt
);
8361 end Resolve_Set_Membership
;
8363 -- Start of processing for Resolve_Membership_Op
8366 if L
= Error
or else R
= Error
then
8370 if Present
(Alternatives
(N
)) then
8371 Resolve_Set_Membership
;
8374 elsif not Is_Overloaded
(R
)
8376 (Etype
(R
) = Universal_Integer
8378 Etype
(R
) = Universal_Real
)
8379 and then Is_Overloaded
(L
)
8383 -- Ada 2005 (AI-251): Support the following case:
8385 -- type I is interface;
8386 -- type T is tagged ...
8388 -- function Test (O : I'Class) is
8390 -- return O in T'Class.
8393 -- In this case we have nothing else to do. The membership test will be
8394 -- done at run time.
8396 elsif Ada_Version
>= Ada_2005
8397 and then Is_Class_Wide_Type
(Etype
(L
))
8398 and then Is_Interface
(Etype
(L
))
8399 and then Is_Class_Wide_Type
(Etype
(R
))
8400 and then not Is_Interface
(Etype
(R
))
8404 T
:= Intersect_Types
(L
, R
);
8407 -- If mixed-mode operations are present and operands are all literal,
8408 -- the only interpretation involves Duration, which is probably not
8409 -- the intention of the programmer.
8411 if T
= Any_Fixed
then
8412 T
:= Unique_Fixed_Point_Type
(N
);
8414 if T
= Any_Type
then
8420 Check_Unset_Reference
(L
);
8422 if Nkind
(R
) = N_Range
8423 and then not Is_Scalar_Type
(T
)
8425 Error_Msg_N
("scalar type required for range", R
);
8428 if Is_Entity_Name
(R
) then
8429 Freeze_Expression
(R
);
8432 Check_Unset_Reference
(R
);
8435 -- Here after resolving membership operation
8439 Eval_Membership_Op
(N
);
8440 Check_Function_Writable_Actuals
(N
);
8441 end Resolve_Membership_Op
;
8447 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
8448 Loc
: constant Source_Ptr
:= Sloc
(N
);
8451 -- Handle restriction against anonymous null access values This
8452 -- restriction can be turned off using -gnatdj.
8454 -- Ada 2005 (AI-231): Remove restriction
8456 if Ada_Version
< Ada_2005
8457 and then not Debug_Flag_J
8458 and then Ekind
(Typ
) = E_Anonymous_Access_Type
8459 and then Comes_From_Source
(N
)
8461 -- In the common case of a call which uses an explicitly null value
8462 -- for an access parameter, give specialized error message.
8464 if Nkind
(Parent
(N
)) in N_Subprogram_Call
then
8466 ("null is not allowed as argument for an access parameter", N
);
8468 -- Standard message for all other cases (are there any?)
8472 ("null cannot be of an anonymous access type", N
);
8476 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
8477 -- assignment to a null-excluding object
8479 if Ada_Version
>= Ada_2005
8480 and then Can_Never_Be_Null
(Typ
)
8481 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
8483 if not Inside_Init_Proc
then
8485 (Compile_Time_Constraint_Error
(N
,
8486 "(Ada 2005) null not allowed in null-excluding objects??"),
8487 Make_Raise_Constraint_Error
(Loc
,
8488 Reason
=> CE_Access_Check_Failed
));
8491 Make_Raise_Constraint_Error
(Loc
,
8492 Reason
=> CE_Access_Check_Failed
));
8496 -- In a distributed context, null for a remote access to subprogram may
8497 -- need to be replaced with a special record aggregate. In this case,
8498 -- return after having done the transformation.
8500 if (Ekind
(Typ
) = E_Record_Type
8501 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
8502 and then Remote_AST_Null_Value
(N
, Typ
)
8507 -- The null literal takes its type from the context
8512 -----------------------
8513 -- Resolve_Op_Concat --
8514 -----------------------
8516 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
8518 -- We wish to avoid deep recursion, because concatenations are often
8519 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
8520 -- operands nonrecursively until we find something that is not a simple
8521 -- concatenation (A in this case). We resolve that, and then walk back
8522 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
8523 -- to do the rest of the work at each level. The Parent pointers allow
8524 -- us to avoid recursion, and thus avoid running out of memory. See also
8525 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
8531 -- The following code is equivalent to:
8533 -- Resolve_Op_Concat_First (NN, Typ);
8534 -- Resolve_Op_Concat_Arg (N, ...);
8535 -- Resolve_Op_Concat_Rest (N, Typ);
8537 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
8538 -- operand is a concatenation.
8540 -- Walk down left operands
8543 Resolve_Op_Concat_First
(NN
, Typ
);
8544 Op1
:= Left_Opnd
(NN
);
8545 exit when not (Nkind
(Op1
) = N_Op_Concat
8546 and then not Is_Array_Type
(Component_Type
(Typ
))
8547 and then Entity
(Op1
) = Entity
(NN
));
8551 -- Now (given the above example) NN is A&B and Op1 is A
8553 -- First resolve Op1 ...
8555 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
8557 -- ... then walk NN back up until we reach N (where we started), calling
8558 -- Resolve_Op_Concat_Rest along the way.
8561 Resolve_Op_Concat_Rest
(NN
, Typ
);
8566 if Base_Type
(Etype
(N
)) /= Standard_String
then
8567 Check_SPARK_Restriction
8568 ("result of concatenation should have type String", N
);
8570 end Resolve_Op_Concat
;
8572 ---------------------------
8573 -- Resolve_Op_Concat_Arg --
8574 ---------------------------
8576 procedure Resolve_Op_Concat_Arg
8582 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8583 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
8588 or else (not Is_Overloaded
(Arg
)
8589 and then Etype
(Arg
) /= Any_Composite
8590 and then Covers
(Ctyp
, Etype
(Arg
)))
8592 Resolve
(Arg
, Ctyp
);
8594 Resolve
(Arg
, Btyp
);
8597 -- If both Array & Array and Array & Component are visible, there is a
8598 -- potential ambiguity that must be reported.
8600 elsif Has_Compatible_Type
(Arg
, Ctyp
) then
8601 if Nkind
(Arg
) = N_Aggregate
8602 and then Is_Composite_Type
(Ctyp
)
8604 if Is_Private_Type
(Ctyp
) then
8605 Resolve
(Arg
, Btyp
);
8607 -- If the operation is user-defined and not overloaded use its
8608 -- profile. The operation may be a renaming, in which case it has
8609 -- been rewritten, and we want the original profile.
8611 elsif not Is_Overloaded
(N
)
8612 and then Comes_From_Source
(Entity
(Original_Node
(N
)))
8613 and then Ekind
(Entity
(Original_Node
(N
))) = E_Function
8617 (Next_Formal
(First_Formal
(Entity
(Original_Node
(N
))))));
8620 -- Otherwise an aggregate may match both the array type and the
8624 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
8625 Set_Etype
(Arg
, Any_Type
);
8629 if Is_Overloaded
(Arg
)
8630 and then Has_Compatible_Type
(Arg
, Typ
)
8631 and then Etype
(Arg
) /= Any_Type
8639 Get_First_Interp
(Arg
, I
, It
);
8641 Get_Next_Interp
(I
, It
);
8643 -- Special-case the error message when the overloading is
8644 -- caused by a function that yields an array and can be
8645 -- called without parameters.
8647 if It
.Nam
= Func
then
8648 Error_Msg_Sloc
:= Sloc
(Func
);
8649 Error_Msg_N
("ambiguous call to function#", Arg
);
8651 ("\\interpretation as call yields&", Arg
, Typ
);
8653 ("\\interpretation as indexing of call yields&",
8654 Arg
, Component_Type
(Typ
));
8657 Error_Msg_N
("ambiguous operand for concatenation!", Arg
);
8659 Get_First_Interp
(Arg
, I
, It
);
8660 while Present
(It
.Nam
) loop
8661 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
8663 if Base_Type
(It
.Typ
) = Btyp
8665 Base_Type
(It
.Typ
) = Base_Type
(Ctyp
)
8667 Error_Msg_N
-- CODEFIX
8668 ("\\possible interpretation#", Arg
);
8671 Get_Next_Interp
(I
, It
);
8677 Resolve
(Arg
, Component_Type
(Typ
));
8679 if Nkind
(Arg
) = N_String_Literal
then
8680 Set_Etype
(Arg
, Component_Type
(Typ
));
8683 if Arg
= Left_Opnd
(N
) then
8684 Set_Is_Component_Left_Opnd
(N
);
8686 Set_Is_Component_Right_Opnd
(N
);
8691 Resolve
(Arg
, Btyp
);
8694 -- Concatenation is restricted in SPARK: each operand must be either a
8695 -- string literal, the name of a string constant, a static character or
8696 -- string expression, or another concatenation. Arg cannot be a
8697 -- concatenation here as callers of Resolve_Op_Concat_Arg call it
8698 -- separately on each final operand, past concatenation operations.
8700 if Is_Character_Type
(Etype
(Arg
)) then
8701 if not Is_OK_Static_Expression
(Arg
) then
8702 Check_SPARK_Restriction
8703 ("character operand for concatenation should be static", Arg
);
8706 elsif Is_String_Type
(Etype
(Arg
)) then
8707 if not (Nkind_In
(Arg
, N_Identifier
, N_Expanded_Name
)
8708 and then Is_Constant_Object
(Entity
(Arg
)))
8709 and then not Is_OK_Static_Expression
(Arg
)
8711 Check_SPARK_Restriction
8712 ("string operand for concatenation should be static", Arg
);
8715 -- Do not issue error on an operand that is neither a character nor a
8716 -- string, as the error is issued in Resolve_Op_Concat.
8722 Check_Unset_Reference
(Arg
);
8723 end Resolve_Op_Concat_Arg
;
8725 -----------------------------
8726 -- Resolve_Op_Concat_First --
8727 -----------------------------
8729 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
8730 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8731 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8732 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8735 -- The parser folds an enormous sequence of concatenations of string
8736 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
8737 -- in the right operand. If the expression resolves to a predefined "&"
8738 -- operator, all is well. Otherwise, the parser's folding is wrong, so
8739 -- we give an error. See P_Simple_Expression in Par.Ch4.
8741 if Nkind
(Op2
) = N_String_Literal
8742 and then Is_Folded_In_Parser
(Op2
)
8743 and then Ekind
(Entity
(N
)) = E_Function
8745 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
8746 and then String_Length
(Strval
(Op1
)) = 0);
8747 Error_Msg_N
("too many user-defined concatenations", N
);
8751 Set_Etype
(N
, Btyp
);
8753 if Is_Limited_Composite
(Btyp
) then
8754 Error_Msg_N
("concatenation not available for limited array", N
);
8755 Explain_Limited_Type
(Btyp
, N
);
8757 end Resolve_Op_Concat_First
;
8759 ----------------------------
8760 -- Resolve_Op_Concat_Rest --
8761 ----------------------------
8763 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
8764 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8765 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8768 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
8770 Generate_Operator_Reference
(N
, Typ
);
8772 if Is_String_Type
(Typ
) then
8773 Eval_Concatenation
(N
);
8776 -- If this is not a static concatenation, but the result is a string
8777 -- type (and not an array of strings) ensure that static string operands
8778 -- have their subtypes properly constructed.
8780 if Nkind
(N
) /= N_String_Literal
8781 and then Is_Character_Type
(Component_Type
(Typ
))
8783 Set_String_Literal_Subtype
(Op1
, Typ
);
8784 Set_String_Literal_Subtype
(Op2
, Typ
);
8786 end Resolve_Op_Concat_Rest
;
8788 ----------------------
8789 -- Resolve_Op_Expon --
8790 ----------------------
8792 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
8793 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
8796 -- Catch attempts to do fixed-point exponentiation with universal
8797 -- operands, which is a case where the illegality is not caught during
8798 -- normal operator analysis. This is not done in preanalysis mode
8799 -- since the tree is not fully decorated during preanalysis.
8801 if Full_Analysis
then
8802 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
8803 Error_Msg_N
("exponentiation not available for fixed point", N
);
8806 elsif Nkind
(Parent
(N
)) in N_Op
8807 and then Is_Fixed_Point_Type
(Etype
(Parent
(N
)))
8808 and then Etype
(N
) = Universal_Real
8809 and then Comes_From_Source
(N
)
8811 Error_Msg_N
("exponentiation not available for fixed point", N
);
8816 if Comes_From_Source
(N
)
8817 and then Ekind
(Entity
(N
)) = E_Function
8818 and then Is_Imported
(Entity
(N
))
8819 and then Is_Intrinsic_Subprogram
(Entity
(N
))
8821 Resolve_Intrinsic_Operator
(N
, Typ
);
8825 if Etype
(Left_Opnd
(N
)) = Universal_Integer
8826 or else Etype
(Left_Opnd
(N
)) = Universal_Real
8828 Check_For_Visible_Operator
(N
, B_Typ
);
8831 -- We do the resolution using the base type, because intermediate values
8832 -- in expressions are always of the base type, not a subtype of it.
8834 Resolve
(Left_Opnd
(N
), B_Typ
);
8835 Resolve
(Right_Opnd
(N
), Standard_Integer
);
8837 -- For integer types, right argument must be in Natural range
8839 if Is_Integer_Type
(Typ
) then
8840 Apply_Scalar_Range_Check
(Right_Opnd
(N
), Standard_Natural
);
8843 Check_Unset_Reference
(Left_Opnd
(N
));
8844 Check_Unset_Reference
(Right_Opnd
(N
));
8846 Set_Etype
(N
, B_Typ
);
8847 Generate_Operator_Reference
(N
, B_Typ
);
8849 Analyze_Dimension
(N
);
8851 if Ada_Version
>= Ada_2012
and then Has_Dimension_System
(B_Typ
) then
8852 -- Evaluate the exponentiation operator for dimensioned type
8854 Eval_Op_Expon_For_Dimensioned_Type
(N
, B_Typ
);
8859 -- Set overflow checking bit. Much cleverer code needed here eventually
8860 -- and perhaps the Resolve routines should be separated for the various
8861 -- arithmetic operations, since they will need different processing. ???
8863 if Nkind
(N
) in N_Op
then
8864 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
8865 Enable_Overflow_Check
(N
);
8868 end Resolve_Op_Expon
;
8870 --------------------
8871 -- Resolve_Op_Not --
8872 --------------------
8874 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
8877 function Parent_Is_Boolean
return Boolean;
8878 -- This function determines if the parent node is a boolean operator or
8879 -- operation (comparison op, membership test, or short circuit form) and
8880 -- the not in question is the left operand of this operation. Note that
8881 -- if the not is in parens, then false is returned.
8883 -----------------------
8884 -- Parent_Is_Boolean --
8885 -----------------------
8887 function Parent_Is_Boolean
return Boolean is
8889 if Paren_Count
(N
) /= 0 then
8893 case Nkind
(Parent
(N
)) is
8908 return Left_Opnd
(Parent
(N
)) = N
;
8914 end Parent_Is_Boolean
;
8916 -- Start of processing for Resolve_Op_Not
8919 -- Predefined operations on scalar types yield the base type. On the
8920 -- other hand, logical operations on arrays yield the type of the
8921 -- arguments (and the context).
8923 if Is_Array_Type
(Typ
) then
8926 B_Typ
:= Base_Type
(Typ
);
8929 -- Straightforward case of incorrect arguments
8931 if not Valid_Boolean_Arg
(Typ
) then
8932 Error_Msg_N
("invalid operand type for operator&", N
);
8933 Set_Etype
(N
, Any_Type
);
8936 -- Special case of probable missing parens
8938 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
8939 if Parent_Is_Boolean
then
8941 ("operand of not must be enclosed in parentheses",
8945 ("no modular type available in this context", N
);
8948 Set_Etype
(N
, Any_Type
);
8951 -- OK resolution of NOT
8954 -- Warn if non-boolean types involved. This is a case like not a < b
8955 -- where a and b are modular, where we will get (not a) < b and most
8956 -- likely not (a < b) was intended.
8958 if Warn_On_Questionable_Missing_Parens
8959 and then not Is_Boolean_Type
(Typ
)
8960 and then Parent_Is_Boolean
8962 Error_Msg_N
("?q?not expression should be parenthesized here!", N
);
8965 -- Warn on double negation if checking redundant constructs
8967 if Warn_On_Redundant_Constructs
8968 and then Comes_From_Source
(N
)
8969 and then Comes_From_Source
(Right_Opnd
(N
))
8970 and then Root_Type
(Typ
) = Standard_Boolean
8971 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
8973 Error_Msg_N
("redundant double negation?r?", N
);
8976 -- Complete resolution and evaluation of NOT
8978 Resolve
(Right_Opnd
(N
), B_Typ
);
8979 Check_Unset_Reference
(Right_Opnd
(N
));
8980 Set_Etype
(N
, B_Typ
);
8981 Generate_Operator_Reference
(N
, B_Typ
);
8986 -----------------------------
8987 -- Resolve_Operator_Symbol --
8988 -----------------------------
8990 -- Nothing to be done, all resolved already
8992 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
8993 pragma Warnings
(Off
, N
);
8994 pragma Warnings
(Off
, Typ
);
8998 end Resolve_Operator_Symbol
;
9000 ----------------------------------
9001 -- Resolve_Qualified_Expression --
9002 ----------------------------------
9004 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9005 pragma Warnings
(Off
, Typ
);
9007 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
9008 Expr
: constant Node_Id
:= Expression
(N
);
9011 Resolve
(Expr
, Target_Typ
);
9013 -- Protect call to Matching_Static_Array_Bounds to avoid costly
9014 -- operation if not needed.
9016 if Restriction_Check_Required
(SPARK_05
)
9017 and then Is_Array_Type
(Target_Typ
)
9018 and then Is_Array_Type
(Etype
(Expr
))
9019 and then Etype
(Expr
) /= Any_Composite
-- or else Expr in error
9020 and then not Matching_Static_Array_Bounds
(Target_Typ
, Etype
(Expr
))
9022 Check_SPARK_Restriction
9023 ("array types should have matching static bounds", N
);
9026 -- A qualified expression requires an exact match of the type, class-
9027 -- wide matching is not allowed. However, if the qualifying type is
9028 -- specific and the expression has a class-wide type, it may still be
9029 -- okay, since it can be the result of the expansion of a call to a
9030 -- dispatching function, so we also have to check class-wideness of the
9031 -- type of the expression's original node.
9033 if (Is_Class_Wide_Type
(Target_Typ
)
9035 (Is_Class_Wide_Type
(Etype
(Expr
))
9036 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
9037 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
9039 Wrong_Type
(Expr
, Target_Typ
);
9042 -- If the target type is unconstrained, then we reset the type of the
9043 -- result from the type of the expression. For other cases, the actual
9044 -- subtype of the expression is the target type.
9046 if Is_Composite_Type
(Target_Typ
)
9047 and then not Is_Constrained
(Target_Typ
)
9049 Set_Etype
(N
, Etype
(Expr
));
9052 Analyze_Dimension
(N
);
9053 Eval_Qualified_Expression
(N
);
9054 end Resolve_Qualified_Expression
;
9056 ------------------------------
9057 -- Resolve_Raise_Expression --
9058 ------------------------------
9060 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9062 if Typ
= Raise_Type
then
9063 Error_Msg_N
("cannot find unique type for raise expression", N
);
9064 Set_Etype
(N
, Any_Type
);
9068 end Resolve_Raise_Expression
;
9074 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
9075 L
: constant Node_Id
:= Low_Bound
(N
);
9076 H
: constant Node_Id
:= High_Bound
(N
);
9078 function First_Last_Ref
return Boolean;
9079 -- Returns True if N is of the form X'First .. X'Last where X is the
9080 -- same entity for both attributes.
9082 --------------------
9083 -- First_Last_Ref --
9084 --------------------
9086 function First_Last_Ref
return Boolean is
9087 Lorig
: constant Node_Id
:= Original_Node
(L
);
9088 Horig
: constant Node_Id
:= Original_Node
(H
);
9091 if Nkind
(Lorig
) = N_Attribute_Reference
9092 and then Nkind
(Horig
) = N_Attribute_Reference
9093 and then Attribute_Name
(Lorig
) = Name_First
9094 and then Attribute_Name
(Horig
) = Name_Last
9097 PL
: constant Node_Id
:= Prefix
(Lorig
);
9098 PH
: constant Node_Id
:= Prefix
(Horig
);
9100 if Is_Entity_Name
(PL
)
9101 and then Is_Entity_Name
(PH
)
9102 and then Entity
(PL
) = Entity
(PH
)
9112 -- Start of processing for Resolve_Range
9119 -- Check for inappropriate range on unordered enumeration type
9121 if Bad_Unordered_Enumeration_Reference
(N
, Typ
)
9123 -- Exclude X'First .. X'Last if X is the same entity for both
9125 and then not First_Last_Ref
9127 Error_Msg_Sloc
:= Sloc
(Typ
);
9129 ("subrange of unordered enumeration type& declared#?U?", N
, Typ
);
9132 Check_Unset_Reference
(L
);
9133 Check_Unset_Reference
(H
);
9135 -- We have to check the bounds for being within the base range as
9136 -- required for a non-static context. Normally this is automatic and
9137 -- done as part of evaluating expressions, but the N_Range node is an
9138 -- exception, since in GNAT we consider this node to be a subexpression,
9139 -- even though in Ada it is not. The circuit in Sem_Eval could check for
9140 -- this, but that would put the test on the main evaluation path for
9143 Check_Non_Static_Context
(L
);
9144 Check_Non_Static_Context
(H
);
9146 -- Check for an ambiguous range over character literals. This will
9147 -- happen with a membership test involving only literals.
9149 if Typ
= Any_Character
then
9150 Ambiguous_Character
(L
);
9151 Set_Etype
(N
, Any_Type
);
9155 -- If bounds are static, constant-fold them, so size computations are
9156 -- identical between front-end and back-end. Do not perform this
9157 -- transformation while analyzing generic units, as type information
9158 -- would be lost when reanalyzing the constant node in the instance.
9160 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
9161 if Is_OK_Static_Expression
(L
) then
9162 Fold_Uint
(L
, Expr_Value
(L
), Is_OK_Static_Expression
(L
));
9165 if Is_OK_Static_Expression
(H
) then
9166 Fold_Uint
(H
, Expr_Value
(H
), Is_OK_Static_Expression
(H
));
9171 --------------------------
9172 -- Resolve_Real_Literal --
9173 --------------------------
9175 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9176 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
9179 -- Special processing for fixed-point literals to make sure that the
9180 -- value is an exact multiple of small where this is required. We skip
9181 -- this for the universal real case, and also for generic types.
9183 if Is_Fixed_Point_Type
(Typ
)
9184 and then Typ
/= Universal_Fixed
9185 and then Typ
/= Any_Fixed
9186 and then not Is_Generic_Type
(Typ
)
9189 Val
: constant Ureal
:= Realval
(N
);
9190 Cintr
: constant Ureal
:= Val
/ Small_Value
(Typ
);
9191 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
9192 Den
: constant Uint
:= Norm_Den
(Cintr
);
9196 -- Case of literal is not an exact multiple of the Small
9200 -- For a source program literal for a decimal fixed-point type,
9201 -- this is statically illegal (RM 4.9(36)).
9203 if Is_Decimal_Fixed_Point_Type
(Typ
)
9204 and then Actual_Typ
= Universal_Real
9205 and then Comes_From_Source
(N
)
9207 Error_Msg_N
("value has extraneous low order digits", N
);
9210 -- Generate a warning if literal from source
9212 if Is_OK_Static_Expression
(N
)
9213 and then Warn_On_Bad_Fixed_Value
9216 ("?b?static fixed-point value is not a multiple of Small!",
9220 -- Replace literal by a value that is the exact representation
9221 -- of a value of the type, i.e. a multiple of the small value,
9222 -- by truncation, since Machine_Rounds is false for all GNAT
9223 -- fixed-point types (RM 4.9(38)).
9225 Stat
:= Is_OK_Static_Expression
(N
);
9227 Make_Real_Literal
(Sloc
(N
),
9228 Realval
=> Small_Value
(Typ
) * Cint
));
9230 Set_Is_Static_Expression
(N
, Stat
);
9233 -- In all cases, set the corresponding integer field
9235 Set_Corresponding_Integer_Value
(N
, Cint
);
9239 -- Now replace the actual type by the expected type as usual
9242 Eval_Real_Literal
(N
);
9243 end Resolve_Real_Literal
;
9245 -----------------------
9246 -- Resolve_Reference --
9247 -----------------------
9249 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
9250 P
: constant Node_Id
:= Prefix
(N
);
9253 -- Replace general access with specific type
9255 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
9256 Set_Etype
(N
, Base_Type
(Typ
));
9259 Resolve
(P
, Designated_Type
(Etype
(N
)));
9261 -- If we are taking the reference of a volatile entity, then treat it as
9262 -- a potential modification of this entity. This is too conservative,
9263 -- but necessary because remove side effects can cause transformations
9264 -- of normal assignments into reference sequences that otherwise fail to
9265 -- notice the modification.
9267 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
9268 Note_Possible_Modification
(P
, Sure
=> False);
9270 end Resolve_Reference
;
9272 --------------------------------
9273 -- Resolve_Selected_Component --
9274 --------------------------------
9276 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
9278 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
9279 P
: constant Node_Id
:= Prefix
(N
);
9280 S
: constant Node_Id
:= Selector_Name
(N
);
9281 T
: Entity_Id
:= Etype
(P
);
9283 I1
: Interp_Index
:= 0; -- prevent junk warning
9288 function Init_Component
return Boolean;
9289 -- Check whether this is the initialization of a component within an
9290 -- init proc (by assignment or call to another init proc). If true,
9291 -- there is no need for a discriminant check.
9293 --------------------
9294 -- Init_Component --
9295 --------------------
9297 function Init_Component
return Boolean is
9299 return Inside_Init_Proc
9300 and then Nkind
(Prefix
(N
)) = N_Identifier
9301 and then Chars
(Prefix
(N
)) = Name_uInit
9302 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
9305 -- Start of processing for Resolve_Selected_Component
9308 if Is_Overloaded
(P
) then
9310 -- Use the context type to select the prefix that has a selector
9311 -- of the correct name and type.
9314 Get_First_Interp
(P
, I
, It
);
9316 Search
: while Present
(It
.Typ
) loop
9317 if Is_Access_Type
(It
.Typ
) then
9318 T
:= Designated_Type
(It
.Typ
);
9323 -- Locate selected component. For a private prefix the selector
9324 -- can denote a discriminant.
9326 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
9328 -- The visible components of a class-wide type are those of
9331 if Is_Class_Wide_Type
(T
) then
9335 Comp
:= First_Entity
(T
);
9336 while Present
(Comp
) loop
9337 if Chars
(Comp
) = Chars
(S
)
9338 and then Covers
(Typ
, Etype
(Comp
))
9347 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9349 if It
= No_Interp
then
9351 ("ambiguous prefix for selected component", N
);
9358 -- There may be an implicit dereference. Retrieve
9359 -- designated record type.
9361 if Is_Access_Type
(It1
.Typ
) then
9362 T
:= Designated_Type
(It1
.Typ
);
9367 if Scope
(Comp1
) /= T
then
9369 -- Resolution chooses the new interpretation.
9370 -- Find the component with the right name.
9372 Comp1
:= First_Entity
(T
);
9373 while Present
(Comp1
)
9374 and then Chars
(Comp1
) /= Chars
(S
)
9376 Comp1
:= Next_Entity
(Comp1
);
9385 Comp
:= Next_Entity
(Comp
);
9389 Get_Next_Interp
(I
, It
);
9392 -- There must be a legal interpretation at this point
9394 pragma Assert
(Found
);
9395 Resolve
(P
, It1
.Typ
);
9397 Set_Entity_With_Checks
(S
, Comp1
);
9400 -- Resolve prefix with its type
9405 -- Generate cross-reference. We needed to wait until full overloading
9406 -- resolution was complete to do this, since otherwise we can't tell if
9407 -- we are an lvalue or not.
9409 if May_Be_Lvalue
(N
) then
9410 Generate_Reference
(Entity
(S
), S
, 'm');
9412 Generate_Reference
(Entity
(S
), S
, 'r');
9415 -- If prefix is an access type, the node will be transformed into an
9416 -- explicit dereference during expansion. The type of the node is the
9417 -- designated type of that of the prefix.
9419 if Is_Access_Type
(Etype
(P
)) then
9420 T
:= Designated_Type
(Etype
(P
));
9421 Check_Fully_Declared_Prefix
(T
, P
);
9426 -- Set flag for expander if discriminant check required
9428 if Has_Discriminants
(T
)
9429 and then Ekind_In
(Entity
(S
), E_Component
, E_Discriminant
)
9430 and then Present
(Original_Record_Component
(Entity
(S
)))
9431 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
9432 and then not Discriminant_Checks_Suppressed
(T
)
9433 and then not Init_Component
9435 Set_Do_Discriminant_Check
(N
);
9438 if Ekind
(Entity
(S
)) = E_Void
then
9439 Error_Msg_N
("premature use of component", S
);
9442 -- If the prefix is a record conversion, this may be a renamed
9443 -- discriminant whose bounds differ from those of the original
9444 -- one, so we must ensure that a range check is performed.
9446 if Nkind
(P
) = N_Type_Conversion
9447 and then Ekind
(Entity
(S
)) = E_Discriminant
9448 and then Is_Discrete_Type
(Typ
)
9450 Set_Etype
(N
, Base_Type
(Typ
));
9453 -- Note: No Eval processing is required, because the prefix is of a
9454 -- record type, or protected type, and neither can possibly be static.
9456 -- If the array type is atomic, and is packed, and we are in a left side
9457 -- context, then this is worth a warning, since we have a situation
9458 -- where the access to the component may cause extra read/writes of the
9459 -- atomic array object, which could be considered unexpected.
9461 if Nkind
(N
) = N_Selected_Component
9462 and then (Is_Atomic
(T
)
9463 or else (Is_Entity_Name
(Prefix
(N
))
9464 and then Is_Atomic
(Entity
(Prefix
(N
)))))
9465 and then Is_Packed
(T
)
9466 and then Is_LHS
(N
) = Yes
9469 ("??assignment to component of packed atomic record", Prefix
(N
));
9471 ("\??may cause unexpected accesses to atomic object", Prefix
(N
));
9474 Analyze_Dimension
(N
);
9475 end Resolve_Selected_Component
;
9481 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
9482 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9483 L
: constant Node_Id
:= Left_Opnd
(N
);
9484 R
: constant Node_Id
:= Right_Opnd
(N
);
9487 -- We do the resolution using the base type, because intermediate values
9488 -- in expressions always are of the base type, not a subtype of it.
9491 Resolve
(R
, Standard_Natural
);
9493 Check_Unset_Reference
(L
);
9494 Check_Unset_Reference
(R
);
9496 Set_Etype
(N
, B_Typ
);
9497 Generate_Operator_Reference
(N
, B_Typ
);
9501 ---------------------------
9502 -- Resolve_Short_Circuit --
9503 ---------------------------
9505 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
9506 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9507 L
: constant Node_Id
:= Left_Opnd
(N
);
9508 R
: constant Node_Id
:= Right_Opnd
(N
);
9511 -- Ensure all actions associated with the left operand (e.g.
9512 -- finalization of transient controlled objects) are fully evaluated
9513 -- locally within an expression with actions. This is particularly
9514 -- helpful for coverage analysis. However this should not happen in
9517 if Expander_Active
then
9519 Reloc_L
: constant Node_Id
:= Relocate_Node
(L
);
9521 Save_Interps
(Old_N
=> L
, New_N
=> Reloc_L
);
9524 Make_Expression_With_Actions
(Sloc
(L
),
9525 Actions
=> New_List
,
9526 Expression
=> Reloc_L
));
9528 -- Set Comes_From_Source on L to preserve warnings for unset
9531 Set_Comes_From_Source
(L
, Comes_From_Source
(Reloc_L
));
9538 -- Check for issuing warning for always False assert/check, this happens
9539 -- when assertions are turned off, in which case the pragma Assert/Check
9540 -- was transformed into:
9542 -- if False and then <condition> then ...
9544 -- and we detect this pattern
9546 if Warn_On_Assertion_Failure
9547 and then Is_Entity_Name
(R
)
9548 and then Entity
(R
) = Standard_False
9549 and then Nkind
(Parent
(N
)) = N_If_Statement
9550 and then Nkind
(N
) = N_And_Then
9551 and then Is_Entity_Name
(L
)
9552 and then Entity
(L
) = Standard_False
9555 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
9558 -- Special handling of Asssert pragma
9560 if Nkind
(Orig
) = N_Pragma
9561 and then Pragma_Name
(Orig
) = Name_Assert
9564 Expr
: constant Node_Id
:=
9567 (First
(Pragma_Argument_Associations
(Orig
))));
9570 -- Don't warn if original condition is explicit False,
9571 -- since obviously the failure is expected in this case.
9573 if Is_Entity_Name
(Expr
)
9574 and then Entity
(Expr
) = Standard_False
9578 -- Issue warning. We do not want the deletion of the
9579 -- IF/AND-THEN to take this message with it. We achieve this
9580 -- by making sure that the expanded code points to the Sloc
9581 -- of the expression, not the original pragma.
9584 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
9585 -- The source location of the expression is not usually
9586 -- the best choice here. For example, it gets located on
9587 -- the last AND keyword in a chain of boolean expressiond
9588 -- AND'ed together. It is best to put the message on the
9589 -- first character of the assertion, which is the effect
9590 -- of the First_Node call here.
9593 ("?A?assertion would fail at run time!",
9595 (First
(Pragma_Argument_Associations
(Orig
))));
9599 -- Similar processing for Check pragma
9601 elsif Nkind
(Orig
) = N_Pragma
9602 and then Pragma_Name
(Orig
) = Name_Check
9604 -- Don't want to warn if original condition is explicit False
9607 Expr
: constant Node_Id
:=
9610 (Next
(First
(Pragma_Argument_Associations
(Orig
)))));
9612 if Is_Entity_Name
(Expr
)
9613 and then Entity
(Expr
) = Standard_False
9620 -- Again use Error_Msg_F rather than Error_Msg_N, see
9621 -- comment above for an explanation of why we do this.
9624 ("?A?check would fail at run time!",
9626 (Last
(Pragma_Argument_Associations
(Orig
))));
9633 -- Continue with processing of short circuit
9635 Check_Unset_Reference
(L
);
9636 Check_Unset_Reference
(R
);
9638 Set_Etype
(N
, B_Typ
);
9639 Eval_Short_Circuit
(N
);
9640 end Resolve_Short_Circuit
;
9646 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
9647 Drange
: constant Node_Id
:= Discrete_Range
(N
);
9648 Name
: constant Node_Id
:= Prefix
(N
);
9649 Array_Type
: Entity_Id
:= Empty
;
9650 Dexpr
: Node_Id
:= Empty
;
9651 Index_Type
: Entity_Id
;
9654 if Is_Overloaded
(Name
) then
9656 -- Use the context type to select the prefix that yields the correct
9661 I1
: Interp_Index
:= 0;
9663 P
: constant Node_Id
:= Prefix
(N
);
9664 Found
: Boolean := False;
9667 Get_First_Interp
(P
, I
, It
);
9668 while Present
(It
.Typ
) loop
9669 if (Is_Array_Type
(It
.Typ
)
9670 and then Covers
(Typ
, It
.Typ
))
9671 or else (Is_Access_Type
(It
.Typ
)
9672 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
9673 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
9676 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9678 if It
= No_Interp
then
9679 Error_Msg_N
("ambiguous prefix for slicing", N
);
9684 Array_Type
:= It
.Typ
;
9689 Array_Type
:= It
.Typ
;
9694 Get_Next_Interp
(I
, It
);
9699 Array_Type
:= Etype
(Name
);
9702 Resolve
(Name
, Array_Type
);
9704 if Is_Access_Type
(Array_Type
) then
9705 Apply_Access_Check
(N
);
9706 Array_Type
:= Designated_Type
(Array_Type
);
9708 -- If the prefix is an access to an unconstrained array, we must use
9709 -- the actual subtype of the object to perform the index checks. The
9710 -- object denoted by the prefix is implicit in the node, so we build
9711 -- an explicit representation for it in order to compute the actual
9714 if not Is_Constrained
(Array_Type
) then
9715 Remove_Side_Effects
(Prefix
(N
));
9718 Obj
: constant Node_Id
:=
9719 Make_Explicit_Dereference
(Sloc
(N
),
9720 Prefix
=> New_Copy_Tree
(Prefix
(N
)));
9722 Set_Etype
(Obj
, Array_Type
);
9723 Set_Parent
(Obj
, Parent
(N
));
9724 Array_Type
:= Get_Actual_Subtype
(Obj
);
9728 elsif Is_Entity_Name
(Name
)
9729 or else Nkind
(Name
) = N_Explicit_Dereference
9730 or else (Nkind
(Name
) = N_Function_Call
9731 and then not Is_Constrained
(Etype
(Name
)))
9733 Array_Type
:= Get_Actual_Subtype
(Name
);
9735 -- If the name is a selected component that depends on discriminants,
9736 -- build an actual subtype for it. This can happen only when the name
9737 -- itself is overloaded; otherwise the actual subtype is created when
9738 -- the selected component is analyzed.
9740 elsif Nkind
(Name
) = N_Selected_Component
9741 and then Full_Analysis
9742 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
9745 Act_Decl
: constant Node_Id
:=
9746 Build_Actual_Subtype_Of_Component
(Array_Type
, Name
);
9748 Insert_Action
(N
, Act_Decl
);
9749 Array_Type
:= Defining_Identifier
(Act_Decl
);
9752 -- Maybe this should just be "else", instead of checking for the
9753 -- specific case of slice??? This is needed for the case where the
9754 -- prefix is an Image attribute, which gets expanded to a slice, and so
9755 -- has a constrained subtype which we want to use for the slice range
9756 -- check applied below (the range check won't get done if the
9757 -- unconstrained subtype of the 'Image is used).
9759 elsif Nkind
(Name
) = N_Slice
then
9760 Array_Type
:= Etype
(Name
);
9763 -- Obtain the type of the array index
9765 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
9766 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
9768 Index_Type
:= Etype
(First_Index
(Array_Type
));
9771 -- If name was overloaded, set slice type correctly now
9773 Set_Etype
(N
, Array_Type
);
9775 -- Handle the generation of a range check that compares the array index
9776 -- against the discrete_range. The check is not applied to internally
9777 -- built nodes associated with the expansion of dispatch tables. Check
9778 -- that Ada.Tags has already been loaded to avoid extra dependencies on
9781 if Tagged_Type_Expansion
9782 and then RTU_Loaded
(Ada_Tags
)
9783 and then Nkind
(Prefix
(N
)) = N_Selected_Component
9784 and then Present
(Entity
(Selector_Name
(Prefix
(N
))))
9785 and then Entity
(Selector_Name
(Prefix
(N
))) =
9786 RTE_Record_Component
(RE_Prims_Ptr
)
9790 -- The discrete_range is specified by a subtype indication. Create a
9791 -- shallow copy and inherit the type, parent and source location from
9792 -- the discrete_range. This ensures that the range check is inserted
9793 -- relative to the slice and that the runtime exception points to the
9794 -- proper construct.
9796 elsif Is_Entity_Name
(Drange
) then
9797 Dexpr
:= New_Copy
(Scalar_Range
(Entity
(Drange
)));
9799 Set_Etype
(Dexpr
, Etype
(Drange
));
9800 Set_Parent
(Dexpr
, Parent
(Drange
));
9801 Set_Sloc
(Dexpr
, Sloc
(Drange
));
9803 -- The discrete_range is a regular range. Resolve the bounds and remove
9804 -- their side effects.
9807 Resolve
(Drange
, Base_Type
(Index_Type
));
9809 if Nkind
(Drange
) = N_Range
then
9810 Force_Evaluation
(Low_Bound
(Drange
));
9811 Force_Evaluation
(High_Bound
(Drange
));
9817 if Present
(Dexpr
) then
9818 Apply_Range_Check
(Dexpr
, Index_Type
);
9821 Set_Slice_Subtype
(N
);
9823 -- Check bad use of type with predicates
9829 if Nkind
(Drange
) = N_Subtype_Indication
9830 and then Has_Predicates
(Entity
(Subtype_Mark
(Drange
)))
9832 Subt
:= Entity
(Subtype_Mark
(Drange
));
9834 Subt
:= Etype
(Drange
);
9837 if Has_Predicates
(Subt
) then
9838 Bad_Predicated_Subtype_Use
9839 ("subtype& has predicate, not allowed in slice", Drange
, Subt
);
9843 -- Otherwise here is where we check suspicious indexes
9845 if Nkind
(Drange
) = N_Range
then
9846 Warn_On_Suspicious_Index
(Name
, Low_Bound
(Drange
));
9847 Warn_On_Suspicious_Index
(Name
, High_Bound
(Drange
));
9850 Analyze_Dimension
(N
);
9854 ----------------------------
9855 -- Resolve_String_Literal --
9856 ----------------------------
9858 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9859 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
9860 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
9861 Loc
: constant Source_Ptr
:= Sloc
(N
);
9862 Str
: constant String_Id
:= Strval
(N
);
9863 Strlen
: constant Nat
:= String_Length
(Str
);
9864 Subtype_Id
: Entity_Id
;
9865 Need_Check
: Boolean;
9868 -- For a string appearing in a concatenation, defer creation of the
9869 -- string_literal_subtype until the end of the resolution of the
9870 -- concatenation, because the literal may be constant-folded away. This
9871 -- is a useful optimization for long concatenation expressions.
9873 -- If the string is an aggregate built for a single character (which
9874 -- happens in a non-static context) or a is null string to which special
9875 -- checks may apply, we build the subtype. Wide strings must also get a
9876 -- string subtype if they come from a one character aggregate. Strings
9877 -- generated by attributes might be static, but it is often hard to
9878 -- determine whether the enclosing context is static, so we generate
9879 -- subtypes for them as well, thus losing some rarer optimizations ???
9880 -- Same for strings that come from a static conversion.
9883 (Strlen
= 0 and then Typ
/= Standard_String
)
9884 or else Nkind
(Parent
(N
)) /= N_Op_Concat
9885 or else (N
/= Left_Opnd
(Parent
(N
))
9886 and then N
/= Right_Opnd
(Parent
(N
)))
9887 or else ((Typ
= Standard_Wide_String
9888 or else Typ
= Standard_Wide_Wide_String
)
9889 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
9891 -- If the resolving type is itself a string literal subtype, we can just
9892 -- reuse it, since there is no point in creating another.
9894 if Ekind
(Typ
) = E_String_Literal_Subtype
then
9897 elsif Nkind
(Parent
(N
)) = N_Op_Concat
9898 and then not Need_Check
9899 and then not Nkind_In
(Original_Node
(N
), N_Character_Literal
,
9900 N_Attribute_Reference
,
9901 N_Qualified_Expression
,
9906 -- Otherwise we must create a string literal subtype. Note that the
9907 -- whole idea of string literal subtypes is simply to avoid the need
9908 -- for building a full fledged array subtype for each literal.
9911 Set_String_Literal_Subtype
(N
, Typ
);
9912 Subtype_Id
:= Etype
(N
);
9915 if Nkind
(Parent
(N
)) /= N_Op_Concat
9918 Set_Etype
(N
, Subtype_Id
);
9919 Eval_String_Literal
(N
);
9922 if Is_Limited_Composite
(Typ
)
9923 or else Is_Private_Composite
(Typ
)
9925 Error_Msg_N
("string literal not available for private array", N
);
9926 Set_Etype
(N
, Any_Type
);
9930 -- The validity of a null string has been checked in the call to
9931 -- Eval_String_Literal.
9936 -- Always accept string literal with component type Any_Character, which
9937 -- occurs in error situations and in comparisons of literals, both of
9938 -- which should accept all literals.
9940 elsif R_Typ
= Any_Character
then
9943 -- If the type is bit-packed, then we always transform the string
9944 -- literal into a full fledged aggregate.
9946 elsif Is_Bit_Packed_Array
(Typ
) then
9949 -- Deal with cases of Wide_Wide_String, Wide_String, and String
9952 -- For Standard.Wide_Wide_String, or any other type whose component
9953 -- type is Standard.Wide_Wide_Character, we know that all the
9954 -- characters in the string must be acceptable, since the parser
9955 -- accepted the characters as valid character literals.
9957 if R_Typ
= Standard_Wide_Wide_Character
then
9960 -- For the case of Standard.String, or any other type whose component
9961 -- type is Standard.Character, we must make sure that there are no
9962 -- wide characters in the string, i.e. that it is entirely composed
9963 -- of characters in range of type Character.
9965 -- If the string literal is the result of a static concatenation, the
9966 -- test has already been performed on the components, and need not be
9969 elsif R_Typ
= Standard_Character
9970 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
9972 for J
in 1 .. Strlen
loop
9973 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
9975 -- If we are out of range, post error. This is one of the
9976 -- very few places that we place the flag in the middle of
9977 -- a token, right under the offending wide character. Not
9978 -- quite clear if this is right wrt wide character encoding
9979 -- sequences, but it's only an error message.
9982 ("literal out of range of type Standard.Character",
9983 Source_Ptr
(Int
(Loc
) + J
));
9988 -- For the case of Standard.Wide_String, or any other type whose
9989 -- component type is Standard.Wide_Character, we must make sure that
9990 -- there are no wide characters in the string, i.e. that it is
9991 -- entirely composed of characters in range of type Wide_Character.
9993 -- If the string literal is the result of a static concatenation,
9994 -- the test has already been performed on the components, and need
9997 elsif R_Typ
= Standard_Wide_Character
9998 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
10000 for J
in 1 .. Strlen
loop
10001 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
10003 -- If we are out of range, post error. This is one of the
10004 -- very few places that we place the flag in the middle of
10005 -- a token, right under the offending wide character.
10007 -- This is not quite right, because characters in general
10008 -- will take more than one character position ???
10011 ("literal out of range of type Standard.Wide_Character",
10012 Source_Ptr
(Int
(Loc
) + J
));
10017 -- If the root type is not a standard character, then we will convert
10018 -- the string into an aggregate and will let the aggregate code do
10019 -- the checking. Standard Wide_Wide_Character is also OK here.
10025 -- See if the component type of the array corresponding to the string
10026 -- has compile time known bounds. If yes we can directly check
10027 -- whether the evaluation of the string will raise constraint error.
10028 -- Otherwise we need to transform the string literal into the
10029 -- corresponding character aggregate and let the aggregate code do
10032 if Is_Standard_Character_Type
(R_Typ
) then
10034 -- Check for the case of full range, where we are definitely OK
10036 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
10040 -- Here the range is not the complete base type range, so check
10043 Comp_Typ_Lo
: constant Node_Id
:=
10044 Type_Low_Bound
(Component_Type
(Typ
));
10045 Comp_Typ_Hi
: constant Node_Id
:=
10046 Type_High_Bound
(Component_Type
(Typ
));
10051 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
10052 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
10054 for J
in 1 .. Strlen
loop
10055 Char_Val
:= UI_From_Int
(Int
(Get_String_Char
(Str
, J
)));
10057 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
10058 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
10060 Apply_Compile_Time_Constraint_Error
10061 (N
, "character out of range??",
10062 CE_Range_Check_Failed
,
10063 Loc
=> Source_Ptr
(Int
(Loc
) + J
));
10073 -- If we got here we meed to transform the string literal into the
10074 -- equivalent qualified positional array aggregate. This is rather
10075 -- heavy artillery for this situation, but it is hard work to avoid.
10078 Lits
: constant List_Id
:= New_List
;
10079 P
: Source_Ptr
:= Loc
+ 1;
10083 -- Build the character literals, we give them source locations that
10084 -- correspond to the string positions, which is a bit tricky given
10085 -- the possible presence of wide character escape sequences.
10087 for J
in 1 .. Strlen
loop
10088 C
:= Get_String_Char
(Str
, J
);
10089 Set_Character_Literal_Name
(C
);
10092 Make_Character_Literal
(P
,
10093 Chars
=> Name_Find
,
10094 Char_Literal_Value
=> UI_From_CC
(C
)));
10096 if In_Character_Range
(C
) then
10099 -- Should we have a call to Skip_Wide here ???
10108 Make_Qualified_Expression
(Loc
,
10109 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
10111 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
10113 Analyze_And_Resolve
(N
, Typ
);
10115 end Resolve_String_Literal
;
10117 -----------------------------
10118 -- Resolve_Type_Conversion --
10119 -----------------------------
10121 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
10122 Conv_OK
: constant Boolean := Conversion_OK
(N
);
10123 Operand
: constant Node_Id
:= Expression
(N
);
10124 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
10125 Target_Typ
: constant Entity_Id
:= Etype
(N
);
10130 Test_Redundant
: Boolean := Warn_On_Redundant_Constructs
;
10131 -- Set to False to suppress cases where we want to suppress the test
10132 -- for redundancy to avoid possible false positives on this warning.
10136 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
10141 -- If the Operand Etype is Universal_Fixed, then the conversion is
10142 -- never redundant. We need this check because by the time we have
10143 -- finished the rather complex transformation, the conversion looks
10144 -- redundant when it is not.
10146 if Operand_Typ
= Universal_Fixed
then
10147 Test_Redundant
:= False;
10149 -- If the operand is marked as Any_Fixed, then special processing is
10150 -- required. This is also a case where we suppress the test for a
10151 -- redundant conversion, since most certainly it is not redundant.
10153 elsif Operand_Typ
= Any_Fixed
then
10154 Test_Redundant
:= False;
10156 -- Mixed-mode operation involving a literal. Context must be a fixed
10157 -- type which is applied to the literal subsequently.
10159 if Is_Fixed_Point_Type
(Typ
) then
10160 Set_Etype
(Operand
, Universal_Real
);
10162 elsif Is_Numeric_Type
(Typ
)
10163 and then Nkind_In
(Operand
, N_Op_Multiply
, N_Op_Divide
)
10164 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
10166 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
10168 -- Return if expression is ambiguous
10170 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
10173 -- If nothing else, the available fixed type is Duration
10176 Set_Etype
(Operand
, Standard_Duration
);
10179 -- Resolve the real operand with largest available precision
10181 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
10182 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
10184 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
10187 Resolve
(Rop
, Universal_Real
);
10189 -- If the operand is a literal (it could be a non-static and
10190 -- illegal exponentiation) check whether the use of Duration
10191 -- is potentially inaccurate.
10193 if Nkind
(Rop
) = N_Real_Literal
10194 and then Realval
(Rop
) /= Ureal_0
10195 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
10198 ("??universal real operand can only "
10199 & "be interpreted as Duration!", Rop
);
10201 ("\??precision will be lost in the conversion!", Rop
);
10204 elsif Is_Numeric_Type
(Typ
)
10205 and then Nkind
(Operand
) in N_Op
10206 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
10208 Set_Etype
(Operand
, Standard_Duration
);
10211 Error_Msg_N
("invalid context for mixed mode operation", N
);
10212 Set_Etype
(Operand
, Any_Type
);
10219 -- In SPARK, a type conversion between array types should be restricted
10220 -- to types which have matching static bounds.
10222 -- Protect call to Matching_Static_Array_Bounds to avoid costly
10223 -- operation if not needed.
10225 if Restriction_Check_Required
(SPARK_05
)
10226 and then Is_Array_Type
(Target_Typ
)
10227 and then Is_Array_Type
(Operand_Typ
)
10228 and then Operand_Typ
/= Any_Composite
-- or else Operand in error
10229 and then not Matching_Static_Array_Bounds
(Target_Typ
, Operand_Typ
)
10231 Check_SPARK_Restriction
10232 ("array types should have matching static bounds", N
);
10235 -- In formal mode, the operand of an ancestor type conversion must be an
10236 -- object (not an expression).
10238 if Is_Tagged_Type
(Target_Typ
)
10239 and then not Is_Class_Wide_Type
(Target_Typ
)
10240 and then Is_Tagged_Type
(Operand_Typ
)
10241 and then not Is_Class_Wide_Type
(Operand_Typ
)
10242 and then Is_Ancestor
(Target_Typ
, Operand_Typ
)
10243 and then not Is_SPARK_Object_Reference
(Operand
)
10245 Check_SPARK_Restriction
("object required", Operand
);
10248 Analyze_Dimension
(N
);
10250 -- Note: we do the Eval_Type_Conversion call before applying the
10251 -- required checks for a subtype conversion. This is important, since
10252 -- both are prepared under certain circumstances to change the type
10253 -- conversion to a constraint error node, but in the case of
10254 -- Eval_Type_Conversion this may reflect an illegality in the static
10255 -- case, and we would miss the illegality (getting only a warning
10256 -- message), if we applied the type conversion checks first.
10258 Eval_Type_Conversion
(N
);
10260 -- Even when evaluation is not possible, we may be able to simplify the
10261 -- conversion or its expression. This needs to be done before applying
10262 -- checks, since otherwise the checks may use the original expression
10263 -- and defeat the simplifications. This is specifically the case for
10264 -- elimination of the floating-point Truncation attribute in
10265 -- float-to-int conversions.
10267 Simplify_Type_Conversion
(N
);
10269 -- If after evaluation we still have a type conversion, then we may need
10270 -- to apply checks required for a subtype conversion.
10272 -- Skip these type conversion checks if universal fixed operands
10273 -- operands involved, since range checks are handled separately for
10274 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
10276 if Nkind
(N
) = N_Type_Conversion
10277 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
10278 and then Target_Typ
/= Universal_Fixed
10279 and then Operand_Typ
/= Universal_Fixed
10281 Apply_Type_Conversion_Checks
(N
);
10284 -- Issue warning for conversion of simple object to its own type. We
10285 -- have to test the original nodes, since they may have been rewritten
10286 -- by various optimizations.
10288 Orig_N
:= Original_Node
(N
);
10290 -- Here we test for a redundant conversion if the warning mode is
10291 -- active (and was not locally reset), and we have a type conversion
10292 -- from source not appearing in a generic instance.
10295 and then Nkind
(Orig_N
) = N_Type_Conversion
10296 and then Comes_From_Source
(Orig_N
)
10297 and then not In_Instance
10299 Orig_N
:= Original_Node
(Expression
(Orig_N
));
10300 Orig_T
:= Target_Typ
;
10302 -- If the node is part of a larger expression, the Target_Type
10303 -- may not be the original type of the node if the context is a
10304 -- condition. Recover original type to see if conversion is needed.
10306 if Is_Boolean_Type
(Orig_T
)
10307 and then Nkind
(Parent
(N
)) in N_Op
10309 Orig_T
:= Etype
(Parent
(N
));
10312 -- If we have an entity name, then give the warning if the entity
10313 -- is the right type, or if it is a loop parameter covered by the
10314 -- original type (that's needed because loop parameters have an
10315 -- odd subtype coming from the bounds).
10317 if (Is_Entity_Name
(Orig_N
)
10319 (Etype
(Entity
(Orig_N
)) = Orig_T
10321 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
10322 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
))))))
10324 -- If not an entity, then type of expression must match
10326 or else Etype
(Orig_N
) = Orig_T
10328 -- One more check, do not give warning if the analyzed conversion
10329 -- has an expression with non-static bounds, and the bounds of the
10330 -- target are static. This avoids junk warnings in cases where the
10331 -- conversion is necessary to establish staticness, for example in
10332 -- a case statement.
10334 if not Is_OK_Static_Subtype
(Operand_Typ
)
10335 and then Is_OK_Static_Subtype
(Target_Typ
)
10339 -- Finally, if this type conversion occurs in a context requiring
10340 -- a prefix, and the expression is a qualified expression then the
10341 -- type conversion is not redundant, since a qualified expression
10342 -- is not a prefix, whereas a type conversion is. For example, "X
10343 -- := T'(Funx(...)).Y;" is illegal because a selected component
10344 -- requires a prefix, but a type conversion makes it legal: "X :=
10345 -- T(T'(Funx(...))).Y;"
10347 -- In Ada 2012, a qualified expression is a name, so this idiom is
10348 -- no longer needed, but we still suppress the warning because it
10349 -- seems unfriendly for warnings to pop up when you switch to the
10350 -- newer language version.
10352 elsif Nkind
(Orig_N
) = N_Qualified_Expression
10353 and then Nkind_In
(Parent
(N
), N_Attribute_Reference
,
10354 N_Indexed_Component
,
10355 N_Selected_Component
,
10357 N_Explicit_Dereference
)
10361 -- Never warn on conversion to Long_Long_Integer'Base since
10362 -- that is most likely an artifact of the extended overflow
10363 -- checking and comes from complex expanded code.
10365 elsif Orig_T
= Base_Type
(Standard_Long_Long_Integer
) then
10368 -- Here we give the redundant conversion warning. If it is an
10369 -- entity, give the name of the entity in the message. If not,
10370 -- just mention the expression.
10372 -- Shoudn't we test Warn_On_Redundant_Constructs here ???
10375 if Is_Entity_Name
(Orig_N
) then
10376 Error_Msg_Node_2
:= Orig_T
;
10377 Error_Msg_NE
-- CODEFIX
10378 ("??redundant conversion, & is of type &!",
10379 N
, Entity
(Orig_N
));
10382 ("??redundant conversion, expression is of type&!",
10389 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
10390 -- No need to perform any interface conversion if the type of the
10391 -- expression coincides with the target type.
10393 if Ada_Version
>= Ada_2005
10394 and then Expander_Active
10395 and then Operand_Typ
/= Target_Typ
10398 Opnd
: Entity_Id
:= Operand_Typ
;
10399 Target
: Entity_Id
:= Target_Typ
;
10402 -- If the type of the operand is a limited view, use the non-
10403 -- limited view when available.
10405 if From_Limited_With
(Opnd
)
10406 and then Ekind
(Opnd
) in Incomplete_Kind
10407 and then Present
(Non_Limited_View
(Opnd
))
10409 Opnd
:= Non_Limited_View
(Opnd
);
10410 Set_Etype
(Expression
(N
), Opnd
);
10413 if Is_Access_Type
(Opnd
) then
10414 Opnd
:= Designated_Type
(Opnd
);
10417 if Is_Access_Type
(Target_Typ
) then
10418 Target
:= Designated_Type
(Target
);
10421 if Opnd
= Target
then
10424 -- Conversion from interface type
10426 elsif Is_Interface
(Opnd
) then
10428 -- Ada 2005 (AI-217): Handle entities from limited views
10430 if From_Limited_With
(Opnd
) then
10431 Error_Msg_Qual_Level
:= 99;
10432 Error_Msg_NE
-- CODEFIX
10433 ("missing WITH clause on package &", N
,
10434 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
10436 ("type conversions require visibility of the full view",
10439 elsif From_Limited_With
(Target
)
10441 (Is_Access_Type
(Target_Typ
)
10442 and then Present
(Non_Limited_View
(Etype
(Target
))))
10444 Error_Msg_Qual_Level
:= 99;
10445 Error_Msg_NE
-- CODEFIX
10446 ("missing WITH clause on package &", N
,
10447 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
10449 ("type conversions require visibility of the full view",
10453 Expand_Interface_Conversion
(N
);
10456 -- Conversion to interface type
10458 elsif Is_Interface
(Target
) then
10462 if Ekind_In
(Opnd
, E_Protected_Subtype
, E_Task_Subtype
) then
10463 Opnd
:= Etype
(Opnd
);
10466 if Is_Class_Wide_Type
(Opnd
)
10467 or else Interface_Present_In_Ancestor
10471 Expand_Interface_Conversion
(N
);
10473 Error_Msg_Name_1
:= Chars
(Etype
(Target
));
10474 Error_Msg_Name_2
:= Chars
(Opnd
);
10476 ("wrong interface conversion (% is not a progenitor "
10483 -- Ada 2012: if target type has predicates, the result requires a
10484 -- predicate check. If the context is a call to another predicate
10485 -- check we must prevent infinite recursion.
10487 if Has_Predicates
(Target_Typ
) then
10488 if Nkind
(Parent
(N
)) = N_Function_Call
10489 and then Present
(Name
(Parent
(N
)))
10490 and then (Is_Predicate_Function
(Entity
(Name
(Parent
(N
))))
10492 Is_Predicate_Function_M
(Entity
(Name
(Parent
(N
)))))
10497 Apply_Predicate_Check
(N
, Target_Typ
);
10500 end Resolve_Type_Conversion
;
10502 ----------------------
10503 -- Resolve_Unary_Op --
10504 ----------------------
10506 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
10507 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10508 R
: constant Node_Id
:= Right_Opnd
(N
);
10514 if Is_Modular_Integer_Type
(Typ
) and then Nkind
(N
) /= N_Op_Not
then
10515 Error_Msg_Name_1
:= Chars
(Typ
);
10516 Check_SPARK_Restriction
10517 ("unary operator not defined for modular type%", N
);
10520 -- Deal with intrinsic unary operators
10522 if Comes_From_Source
(N
)
10523 and then Ekind
(Entity
(N
)) = E_Function
10524 and then Is_Imported
(Entity
(N
))
10525 and then Is_Intrinsic_Subprogram
(Entity
(N
))
10527 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10531 -- Deal with universal cases
10533 if Etype
(R
) = Universal_Integer
10535 Etype
(R
) = Universal_Real
10537 Check_For_Visible_Operator
(N
, B_Typ
);
10540 Set_Etype
(N
, B_Typ
);
10541 Resolve
(R
, B_Typ
);
10543 -- Generate warning for expressions like abs (x mod 2)
10545 if Warn_On_Redundant_Constructs
10546 and then Nkind
(N
) = N_Op_Abs
10548 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
10550 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
10551 Error_Msg_N
-- CODEFIX
10552 ("?r?abs applied to known non-negative value has no effect", N
);
10556 -- Deal with reference generation
10558 Check_Unset_Reference
(R
);
10559 Generate_Operator_Reference
(N
, B_Typ
);
10560 Analyze_Dimension
(N
);
10563 -- Set overflow checking bit. Much cleverer code needed here eventually
10564 -- and perhaps the Resolve routines should be separated for the various
10565 -- arithmetic operations, since they will need different processing ???
10567 if Nkind
(N
) in N_Op
then
10568 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
10569 Enable_Overflow_Check
(N
);
10573 -- Generate warning for expressions like -5 mod 3 for integers. No need
10574 -- to worry in the floating-point case, since parens do not affect the
10575 -- result so there is no point in giving in a warning.
10578 Norig
: constant Node_Id
:= Original_Node
(N
);
10587 if Warn_On_Questionable_Missing_Parens
10588 and then Comes_From_Source
(Norig
)
10589 and then Is_Integer_Type
(Typ
)
10590 and then Nkind
(Norig
) = N_Op_Minus
10592 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
10594 -- We are looking for cases where the right operand is not
10595 -- parenthesized, and is a binary operator, multiply, divide, or
10596 -- mod. These are the cases where the grouping can affect results.
10598 if Paren_Count
(Rorig
) = 0
10599 and then Nkind_In
(Rorig
, N_Op_Mod
, N_Op_Multiply
, N_Op_Divide
)
10601 -- For mod, we always give the warning, since the value is
10602 -- affected by the parenthesization (e.g. (-5) mod 315 /=
10603 -- -(5 mod 315)). But for the other cases, the only concern is
10604 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
10605 -- overflows, but (-2) * 64 does not). So we try to give the
10606 -- message only when overflow is possible.
10608 if Nkind
(Rorig
) /= N_Op_Mod
10609 and then Compile_Time_Known_Value
(R
)
10611 Val
:= Expr_Value
(R
);
10613 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
10614 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
10616 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
10619 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
10620 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
10622 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
10625 -- Note that the test below is deliberately excluding the
10626 -- largest negative number, since that is a potentially
10627 -- troublesome case (e.g. -2 * x, where the result is the
10628 -- largest negative integer has an overflow with 2 * x).
10630 if Val
> LB
and then Val
<= HB
then
10635 -- For the multiplication case, the only case we have to worry
10636 -- about is when (-a)*b is exactly the largest negative number
10637 -- so that -(a*b) can cause overflow. This can only happen if
10638 -- a is a power of 2, and more generally if any operand is a
10639 -- constant that is not a power of 2, then the parentheses
10640 -- cannot affect whether overflow occurs. We only bother to
10641 -- test the left most operand
10643 -- Loop looking at left operands for one that has known value
10646 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
10647 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
10648 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
10650 -- Operand value of 0 or 1 skips warning
10655 -- Otherwise check power of 2, if power of 2, warn, if
10656 -- anything else, skip warning.
10659 while Lval
/= 2 loop
10660 if Lval
mod 2 = 1 then
10671 -- Keep looking at left operands
10673 Opnd
:= Left_Opnd
(Opnd
);
10674 end loop Opnd_Loop
;
10676 -- For rem or "/" we can only have a problematic situation
10677 -- if the divisor has a value of minus one or one. Otherwise
10678 -- overflow is impossible (divisor > 1) or we have a case of
10679 -- division by zero in any case.
10681 if Nkind_In
(Rorig
, N_Op_Divide
, N_Op_Rem
)
10682 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
10683 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
10688 -- If we fall through warning should be issued
10690 -- Shouldn't we test Warn_On_Questionable_Missing_Parens ???
10693 ("??unary minus expression should be parenthesized here!", N
);
10697 end Resolve_Unary_Op
;
10699 ----------------------------------
10700 -- Resolve_Unchecked_Expression --
10701 ----------------------------------
10703 procedure Resolve_Unchecked_Expression
10708 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
10709 Set_Etype
(N
, Typ
);
10710 end Resolve_Unchecked_Expression
;
10712 ---------------------------------------
10713 -- Resolve_Unchecked_Type_Conversion --
10714 ---------------------------------------
10716 procedure Resolve_Unchecked_Type_Conversion
10720 pragma Warnings
(Off
, Typ
);
10722 Operand
: constant Node_Id
:= Expression
(N
);
10723 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
10726 -- Resolve operand using its own type
10728 Resolve
(Operand
, Opnd_Type
);
10730 -- In an inlined context, the unchecked conversion may be applied
10731 -- to a literal, in which case its type is the type of the context.
10732 -- (In other contexts conversions cannot apply to literals).
10735 and then (Opnd_Type
= Any_Character
or else
10736 Opnd_Type
= Any_Integer
or else
10737 Opnd_Type
= Any_Real
)
10739 Set_Etype
(Operand
, Typ
);
10742 Analyze_Dimension
(N
);
10743 Eval_Unchecked_Conversion
(N
);
10744 end Resolve_Unchecked_Type_Conversion
;
10746 ------------------------------
10747 -- Rewrite_Operator_As_Call --
10748 ------------------------------
10750 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
10751 Loc
: constant Source_Ptr
:= Sloc
(N
);
10752 Actuals
: constant List_Id
:= New_List
;
10756 if Nkind
(N
) in N_Binary_Op
then
10757 Append
(Left_Opnd
(N
), Actuals
);
10760 Append
(Right_Opnd
(N
), Actuals
);
10763 Make_Function_Call
(Sloc
=> Loc
,
10764 Name
=> New_Occurrence_Of
(Nam
, Loc
),
10765 Parameter_Associations
=> Actuals
);
10767 Preserve_Comes_From_Source
(New_N
, N
);
10768 Preserve_Comes_From_Source
(Name
(New_N
), N
);
10769 Rewrite
(N
, New_N
);
10770 Set_Etype
(N
, Etype
(Nam
));
10771 end Rewrite_Operator_As_Call
;
10773 ------------------------------
10774 -- Rewrite_Renamed_Operator --
10775 ------------------------------
10777 procedure Rewrite_Renamed_Operator
10782 Nam
: constant Name_Id
:= Chars
(Op
);
10783 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
10787 -- Do not perform this transformation within a pre/postcondition,
10788 -- because the expression will be re-analyzed, and the transformation
10789 -- might affect the visibility of the operator, e.g. in an instance.
10791 if In_Assertion_Expr
> 0 then
10795 -- Rewrite the operator node using the real operator, not its renaming.
10796 -- Exclude user-defined intrinsic operations of the same name, which are
10797 -- treated separately and rewritten as calls.
10799 if Ekind
(Op
) /= E_Function
or else Chars
(N
) /= Nam
then
10800 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
10801 Set_Chars
(Op_Node
, Nam
);
10802 Set_Etype
(Op_Node
, Etype
(N
));
10803 Set_Entity
(Op_Node
, Op
);
10804 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
10806 -- Indicate that both the original entity and its renaming are
10807 -- referenced at this point.
10809 Generate_Reference
(Entity
(N
), N
);
10810 Generate_Reference
(Op
, N
);
10813 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
10816 Rewrite
(N
, Op_Node
);
10818 -- If the context type is private, add the appropriate conversions so
10819 -- that the operator is applied to the full view. This is done in the
10820 -- routines that resolve intrinsic operators.
10822 if Is_Intrinsic_Subprogram
(Op
)
10823 and then Is_Private_Type
(Typ
)
10826 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
10827 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
10828 Resolve_Intrinsic_Operator
(N
, Typ
);
10830 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
10831 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10838 elsif Ekind
(Op
) = E_Function
and then Is_Intrinsic_Subprogram
(Op
) then
10840 -- Operator renames a user-defined operator of the same name. Use the
10841 -- original operator in the node, which is the one Gigi knows about.
10843 Set_Entity
(N
, Op
);
10844 Set_Is_Overloaded
(N
, False);
10846 end Rewrite_Renamed_Operator
;
10848 -----------------------
10849 -- Set_Slice_Subtype --
10850 -----------------------
10852 -- Build an implicit subtype declaration to represent the type delivered by
10853 -- the slice. This is an abbreviated version of an array subtype. We define
10854 -- an index subtype for the slice, using either the subtype name or the
10855 -- discrete range of the slice. To be consistent with index usage elsewhere
10856 -- we create a list header to hold the single index. This list is not
10857 -- otherwise attached to the syntax tree.
10859 procedure Set_Slice_Subtype
(N
: Node_Id
) is
10860 Loc
: constant Source_Ptr
:= Sloc
(N
);
10861 Index_List
: constant List_Id
:= New_List
;
10863 Index_Subtype
: Entity_Id
;
10864 Index_Type
: Entity_Id
;
10865 Slice_Subtype
: Entity_Id
;
10866 Drange
: constant Node_Id
:= Discrete_Range
(N
);
10869 Index_Type
:= Base_Type
(Etype
(Drange
));
10871 if Is_Entity_Name
(Drange
) then
10872 Index_Subtype
:= Entity
(Drange
);
10875 -- We force the evaluation of a range. This is definitely needed in
10876 -- the renamed case, and seems safer to do unconditionally. Note in
10877 -- any case that since we will create and insert an Itype referring
10878 -- to this range, we must make sure any side effect removal actions
10879 -- are inserted before the Itype definition.
10881 if Nkind
(Drange
) = N_Range
then
10882 Force_Evaluation
(Low_Bound
(Drange
));
10883 Force_Evaluation
(High_Bound
(Drange
));
10885 -- If the discrete range is given by a subtype indication, the
10886 -- type of the slice is the base of the subtype mark.
10888 elsif Nkind
(Drange
) = N_Subtype_Indication
then
10890 R
: constant Node_Id
:= Range_Expression
(Constraint
(Drange
));
10892 Index_Type
:= Base_Type
(Entity
(Subtype_Mark
(Drange
)));
10893 Force_Evaluation
(Low_Bound
(R
));
10894 Force_Evaluation
(High_Bound
(R
));
10898 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
10900 -- Take a new copy of Drange (where bounds have been rewritten to
10901 -- reference side-effect-free names). Using a separate tree ensures
10902 -- that further expansion (e.g. while rewriting a slice assignment
10903 -- into a FOR loop) does not attempt to remove side effects on the
10904 -- bounds again (which would cause the bounds in the index subtype
10905 -- definition to refer to temporaries before they are defined) (the
10906 -- reason is that some names are considered side effect free here
10907 -- for the subtype, but not in the context of a loop iteration
10910 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
10911 Set_Parent
(Scalar_Range
(Index_Subtype
), Index_Subtype
);
10912 Set_Etype
(Index_Subtype
, Index_Type
);
10913 Set_Size_Info
(Index_Subtype
, Index_Type
);
10914 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
10917 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
10919 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
10920 Set_Etype
(Index
, Index_Subtype
);
10921 Append
(Index
, Index_List
);
10923 Set_First_Index
(Slice_Subtype
, Index
);
10924 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
10925 Set_Is_Constrained
(Slice_Subtype
, True);
10927 Check_Compile_Time_Size
(Slice_Subtype
);
10929 -- The Etype of the existing Slice node is reset to this slice subtype.
10930 -- Its bounds are obtained from its first index.
10932 Set_Etype
(N
, Slice_Subtype
);
10934 -- For packed slice subtypes, freeze immediately (except in the case of
10935 -- being in a "spec expression" where we never freeze when we first see
10936 -- the expression).
10938 if Is_Packed
(Slice_Subtype
) and not In_Spec_Expression
then
10939 Freeze_Itype
(Slice_Subtype
, N
);
10941 -- For all other cases insert an itype reference in the slice's actions
10942 -- so that the itype is frozen at the proper place in the tree (i.e. at
10943 -- the point where actions for the slice are analyzed). Note that this
10944 -- is different from freezing the itype immediately, which might be
10945 -- premature (e.g. if the slice is within a transient scope). This needs
10946 -- to be done only if expansion is enabled.
10948 elsif Expander_Active
then
10949 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
10951 end Set_Slice_Subtype
;
10953 --------------------------------
10954 -- Set_String_Literal_Subtype --
10955 --------------------------------
10957 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
10958 Loc
: constant Source_Ptr
:= Sloc
(N
);
10959 Low_Bound
: constant Node_Id
:=
10960 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
10961 Subtype_Id
: Entity_Id
;
10964 if Nkind
(N
) /= N_String_Literal
then
10968 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
10969 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
10970 (String_Length
(Strval
(N
))));
10971 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
10972 Set_Is_Constrained
(Subtype_Id
);
10973 Set_Etype
(N
, Subtype_Id
);
10975 -- The low bound is set from the low bound of the corresponding index
10976 -- type. Note that we do not store the high bound in the string literal
10977 -- subtype, but it can be deduced if necessary from the length and the
10980 if Is_OK_Static_Expression
(Low_Bound
) then
10981 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
10983 -- If the lower bound is not static we create a range for the string
10984 -- literal, using the index type and the known length of the literal.
10985 -- The index type is not necessarily Positive, so the upper bound is
10986 -- computed as T'Val (T'Pos (Low_Bound) + L - 1).
10990 Index_List
: constant List_Id
:= New_List
;
10991 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
10992 High_Bound
: constant Node_Id
:=
10993 Make_Attribute_Reference
(Loc
,
10994 Attribute_Name
=> Name_Val
,
10996 New_Occurrence_Of
(Index_Type
, Loc
),
10997 Expressions
=> New_List
(
11000 Make_Attribute_Reference
(Loc
,
11001 Attribute_Name
=> Name_Pos
,
11003 New_Occurrence_Of
(Index_Type
, Loc
),
11005 New_List
(New_Copy_Tree
(Low_Bound
))),
11007 Make_Integer_Literal
(Loc
,
11008 String_Length
(Strval
(N
)) - 1))));
11010 Array_Subtype
: Entity_Id
;
11013 Index_Subtype
: Entity_Id
;
11016 if Is_Integer_Type
(Index_Type
) then
11017 Set_String_Literal_Low_Bound
11018 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
11021 -- If the index type is an enumeration type, build bounds
11022 -- expression with attributes.
11024 Set_String_Literal_Low_Bound
11026 Make_Attribute_Reference
(Loc
,
11027 Attribute_Name
=> Name_First
,
11029 New_Occurrence_Of
(Base_Type
(Index_Type
), Loc
)));
11030 Set_Etype
(String_Literal_Low_Bound
(Subtype_Id
), Index_Type
);
11033 Analyze_And_Resolve
(String_Literal_Low_Bound
(Subtype_Id
));
11035 -- Build bona fide subtype for the string, and wrap it in an
11036 -- unchecked conversion, because the backend expects the
11037 -- String_Literal_Subtype to have a static lower bound.
11040 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
11041 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
11042 Set_Scalar_Range
(Index_Subtype
, Drange
);
11043 Set_Parent
(Drange
, N
);
11044 Analyze_And_Resolve
(Drange
, Index_Type
);
11046 -- In the context, the Index_Type may already have a constraint,
11047 -- so use common base type on string subtype. The base type may
11048 -- be used when generating attributes of the string, for example
11049 -- in the context of a slice assignment.
11051 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
11052 Set_Size_Info
(Index_Subtype
, Index_Type
);
11053 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
11055 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
11057 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
11058 Set_Etype
(Index
, Index_Subtype
);
11059 Append
(Index
, Index_List
);
11061 Set_First_Index
(Array_Subtype
, Index
);
11062 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
11063 Set_Is_Constrained
(Array_Subtype
, True);
11066 Make_Unchecked_Type_Conversion
(Loc
,
11067 Subtype_Mark
=> New_Occurrence_Of
(Array_Subtype
, Loc
),
11068 Expression
=> Relocate_Node
(N
)));
11069 Set_Etype
(N
, Array_Subtype
);
11072 end Set_String_Literal_Subtype
;
11074 ------------------------------
11075 -- Simplify_Type_Conversion --
11076 ------------------------------
11078 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
11080 if Nkind
(N
) = N_Type_Conversion
then
11082 Operand
: constant Node_Id
:= Expression
(N
);
11083 Target_Typ
: constant Entity_Id
:= Etype
(N
);
11084 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
11087 -- Special processing if the conversion is the expression of a
11088 -- Rounding or Truncation attribute reference. In this case we
11091 -- ityp (ftyp'Rounding (x)) or ityp (ftyp'Truncation (x))
11097 -- with the Float_Truncate flag set to False or True respectively,
11098 -- which is more efficient.
11100 if Is_Floating_Point_Type
(Opnd_Typ
)
11102 (Is_Integer_Type
(Target_Typ
)
11103 or else (Is_Fixed_Point_Type
(Target_Typ
)
11104 and then Conversion_OK
(N
)))
11105 and then Nkind
(Operand
) = N_Attribute_Reference
11106 and then Nam_In
(Attribute_Name
(Operand
), Name_Rounding
,
11110 Truncate
: constant Boolean :=
11111 Attribute_Name
(Operand
) = Name_Truncation
;
11114 Relocate_Node
(First
(Expressions
(Operand
))));
11115 Set_Float_Truncate
(N
, Truncate
);
11120 end Simplify_Type_Conversion
;
11122 -----------------------------
11123 -- Unique_Fixed_Point_Type --
11124 -----------------------------
11126 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
11127 T1
: Entity_Id
:= Empty
;
11132 procedure Fixed_Point_Error
;
11133 -- Give error messages for true ambiguity. Messages are posted on node
11134 -- N, and entities T1, T2 are the possible interpretations.
11136 -----------------------
11137 -- Fixed_Point_Error --
11138 -----------------------
11140 procedure Fixed_Point_Error
is
11142 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
11143 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
11144 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
11145 end Fixed_Point_Error
;
11147 -- Start of processing for Unique_Fixed_Point_Type
11150 -- The operations on Duration are visible, so Duration is always a
11151 -- possible interpretation.
11153 T1
:= Standard_Duration
;
11155 -- Look for fixed-point types in enclosing scopes
11157 Scop
:= Current_Scope
;
11158 while Scop
/= Standard_Standard
loop
11159 T2
:= First_Entity
(Scop
);
11160 while Present
(T2
) loop
11161 if Is_Fixed_Point_Type
(T2
)
11162 and then Current_Entity
(T2
) = T2
11163 and then Scope
(Base_Type
(T2
)) = Scop
11165 if Present
(T1
) then
11176 Scop
:= Scope
(Scop
);
11179 -- Look for visible fixed type declarations in the context
11181 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
11182 while Present
(Item
) loop
11183 if Nkind
(Item
) = N_With_Clause
then
11184 Scop
:= Entity
(Name
(Item
));
11185 T2
:= First_Entity
(Scop
);
11186 while Present
(T2
) loop
11187 if Is_Fixed_Point_Type
(T2
)
11188 and then Scope
(Base_Type
(T2
)) = Scop
11189 and then (Is_Potentially_Use_Visible
(T2
) or else In_Use
(T2
))
11191 if Present
(T1
) then
11206 if Nkind
(N
) = N_Real_Literal
then
11208 ("??real literal interpreted as }!", N
, T1
);
11211 ("??universal_fixed expression interpreted as }!", N
, T1
);
11215 end Unique_Fixed_Point_Type
;
11217 ----------------------
11218 -- Valid_Conversion --
11219 ----------------------
11221 function Valid_Conversion
11223 Target
: Entity_Id
;
11225 Report_Errs
: Boolean := True) return Boolean
11227 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
11228 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
11229 Inc_Ancestor
: Entity_Id
;
11231 function Conversion_Check
11233 Msg
: String) return Boolean;
11234 -- Little routine to post Msg if Valid is False, returns Valid value
11236 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
);
11237 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
11239 procedure Conversion_Error_NE
11241 N
: Node_Or_Entity_Id
;
11242 E
: Node_Or_Entity_Id
);
11243 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
11245 function Valid_Tagged_Conversion
11246 (Target_Type
: Entity_Id
;
11247 Opnd_Type
: Entity_Id
) return Boolean;
11248 -- Specifically test for validity of tagged conversions
11250 function Valid_Array_Conversion
return Boolean;
11251 -- Check index and component conformance, and accessibility levels if
11252 -- the component types are anonymous access types (Ada 2005).
11254 ----------------------
11255 -- Conversion_Check --
11256 ----------------------
11258 function Conversion_Check
11260 Msg
: String) return Boolean
11265 -- A generic unit has already been analyzed and we have verified
11266 -- that a particular conversion is OK in that context. Since the
11267 -- instance is reanalyzed without relying on the relationships
11268 -- established during the analysis of the generic, it is possible
11269 -- to end up with inconsistent views of private types. Do not emit
11270 -- the error message in such cases. The rest of the machinery in
11271 -- Valid_Conversion still ensures the proper compatibility of
11272 -- target and operand types.
11274 and then not In_Instance
11276 Conversion_Error_N
(Msg
, Operand
);
11280 end Conversion_Check
;
11282 ------------------------
11283 -- Conversion_Error_N --
11284 ------------------------
11286 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
11288 if Report_Errs
then
11289 Error_Msg_N
(Msg
, N
);
11291 end Conversion_Error_N
;
11293 -------------------------
11294 -- Conversion_Error_NE --
11295 -------------------------
11297 procedure Conversion_Error_NE
11299 N
: Node_Or_Entity_Id
;
11300 E
: Node_Or_Entity_Id
)
11303 if Report_Errs
then
11304 Error_Msg_NE
(Msg
, N
, E
);
11306 end Conversion_Error_NE
;
11308 ----------------------------
11309 -- Valid_Array_Conversion --
11310 ----------------------------
11312 function Valid_Array_Conversion
return Boolean
11314 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
11315 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
11317 Opnd_Index
: Node_Id
;
11318 Opnd_Index_Type
: Entity_Id
;
11320 Target_Comp_Type
: constant Entity_Id
:=
11321 Component_Type
(Target_Type
);
11322 Target_Comp_Base
: constant Entity_Id
:=
11323 Base_Type
(Target_Comp_Type
);
11325 Target_Index
: Node_Id
;
11326 Target_Index_Type
: Entity_Id
;
11329 -- Error if wrong number of dimensions
11332 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
11335 ("incompatible number of dimensions for conversion", Operand
);
11338 -- Number of dimensions matches
11341 -- Loop through indexes of the two arrays
11343 Target_Index
:= First_Index
(Target_Type
);
11344 Opnd_Index
:= First_Index
(Opnd_Type
);
11345 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
11346 Target_Index_Type
:= Etype
(Target_Index
);
11347 Opnd_Index_Type
:= Etype
(Opnd_Index
);
11349 -- Error if index types are incompatible
11351 if not (Is_Integer_Type
(Target_Index_Type
)
11352 and then Is_Integer_Type
(Opnd_Index_Type
))
11353 and then (Root_Type
(Target_Index_Type
)
11354 /= Root_Type
(Opnd_Index_Type
))
11357 ("incompatible index types for array conversion",
11362 Next_Index
(Target_Index
);
11363 Next_Index
(Opnd_Index
);
11366 -- If component types have same base type, all set
11368 if Target_Comp_Base
= Opnd_Comp_Base
then
11371 -- Here if base types of components are not the same. The only
11372 -- time this is allowed is if we have anonymous access types.
11374 -- The conversion of arrays of anonymous access types can lead
11375 -- to dangling pointers. AI-392 formalizes the accessibility
11376 -- checks that must be applied to such conversions to prevent
11377 -- out-of-scope references.
11380 (Target_Comp_Base
, E_Anonymous_Access_Type
,
11381 E_Anonymous_Access_Subprogram_Type
)
11382 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
11384 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
11386 if Type_Access_Level
(Target_Type
) <
11387 Deepest_Type_Access_Level
(Opnd_Type
)
11389 if In_Instance_Body
then
11390 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11392 ("source array type has deeper accessibility "
11393 & "level than target<<", Operand
);
11394 Conversion_Error_N
("\Program_Error [<<", Operand
);
11396 Make_Raise_Program_Error
(Sloc
(N
),
11397 Reason
=> PE_Accessibility_Check_Failed
));
11398 Set_Etype
(N
, Target_Type
);
11401 -- Conversion not allowed because of accessibility levels
11405 ("source array type has deeper accessibility "
11406 & "level than target", Operand
);
11414 -- All other cases where component base types do not match
11418 ("incompatible component types for array conversion",
11423 -- Check that component subtypes statically match. For numeric
11424 -- types this means that both must be either constrained or
11425 -- unconstrained. For enumeration types the bounds must match.
11426 -- All of this is checked in Subtypes_Statically_Match.
11428 if not Subtypes_Statically_Match
11429 (Target_Comp_Type
, Opnd_Comp_Type
)
11432 ("component subtypes must statically match", Operand
);
11438 end Valid_Array_Conversion
;
11440 -----------------------------
11441 -- Valid_Tagged_Conversion --
11442 -----------------------------
11444 function Valid_Tagged_Conversion
11445 (Target_Type
: Entity_Id
;
11446 Opnd_Type
: Entity_Id
) return Boolean
11449 -- Upward conversions are allowed (RM 4.6(22))
11451 if Covers
(Target_Type
, Opnd_Type
)
11452 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
11456 -- Downward conversion are allowed if the operand is class-wide
11459 elsif Is_Class_Wide_Type
(Opnd_Type
)
11460 and then Covers
(Opnd_Type
, Target_Type
)
11464 elsif Covers
(Opnd_Type
, Target_Type
)
11465 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
11468 Conversion_Check
(False,
11469 "downward conversion of tagged objects not allowed");
11471 -- Ada 2005 (AI-251): The conversion to/from interface types is
11474 elsif Is_Interface
(Target_Type
) or else Is_Interface
(Opnd_Type
) then
11477 -- If the operand is a class-wide type obtained through a limited_
11478 -- with clause, and the context includes the non-limited view, use
11479 -- it to determine whether the conversion is legal.
11481 elsif Is_Class_Wide_Type
(Opnd_Type
)
11482 and then From_Limited_With
(Opnd_Type
)
11483 and then Present
(Non_Limited_View
(Etype
(Opnd_Type
)))
11484 and then Is_Interface
(Non_Limited_View
(Etype
(Opnd_Type
)))
11488 elsif Is_Access_Type
(Opnd_Type
)
11489 and then Is_Interface
(Directly_Designated_Type
(Opnd_Type
))
11494 Conversion_Error_NE
11495 ("invalid tagged conversion, not compatible with}",
11496 N
, First_Subtype
(Opnd_Type
));
11499 end Valid_Tagged_Conversion
;
11501 -- Start of processing for Valid_Conversion
11504 Check_Parameterless_Call
(Operand
);
11506 if Is_Overloaded
(Operand
) then
11516 -- Remove procedure calls, which syntactically cannot appear in
11517 -- this context, but which cannot be removed by type checking,
11518 -- because the context does not impose a type.
11520 -- The node may be labelled overloaded, but still contain only one
11521 -- interpretation because others were discarded earlier. If this
11522 -- is the case, retain the single interpretation if legal.
11524 Get_First_Interp
(Operand
, I
, It
);
11525 Opnd_Type
:= It
.Typ
;
11526 Get_Next_Interp
(I
, It
);
11528 if Present
(It
.Typ
)
11529 and then Opnd_Type
/= Standard_Void_Type
11531 -- More than one candidate interpretation is available
11533 Get_First_Interp
(Operand
, I
, It
);
11534 while Present
(It
.Typ
) loop
11535 if It
.Typ
= Standard_Void_Type
then
11539 -- When compiling for a system where Address is of a visible
11540 -- integer type, spurious ambiguities can be produced when
11541 -- arithmetic operations have a literal operand and return
11542 -- System.Address or a descendant of it. These ambiguities
11543 -- are usually resolved by the context, but for conversions
11544 -- there is no context type and the removal of the spurious
11545 -- operations must be done explicitly here.
11547 if not Address_Is_Private
11548 and then Is_Descendent_Of_Address
(It
.Typ
)
11553 Get_Next_Interp
(I
, It
);
11557 Get_First_Interp
(Operand
, I
, It
);
11561 if No
(It
.Typ
) then
11562 Conversion_Error_N
("illegal operand in conversion", Operand
);
11566 Get_Next_Interp
(I
, It
);
11568 if Present
(It
.Typ
) then
11571 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
11573 if It1
= No_Interp
then
11575 ("ambiguous operand in conversion", Operand
);
11577 -- If the interpretation involves a standard operator, use
11578 -- the location of the type, which may be user-defined.
11580 if Sloc
(It
.Nam
) = Standard_Location
then
11581 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
11583 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
11586 Conversion_Error_N
-- CODEFIX
11587 ("\\possible interpretation#!", Operand
);
11589 if Sloc
(N1
) = Standard_Location
then
11590 Error_Msg_Sloc
:= Sloc
(T1
);
11592 Error_Msg_Sloc
:= Sloc
(N1
);
11595 Conversion_Error_N
-- CODEFIX
11596 ("\\possible interpretation#!", Operand
);
11602 Set_Etype
(Operand
, It1
.Typ
);
11603 Opnd_Type
:= It1
.Typ
;
11607 -- Deal with conversion of integer type to address if the pragma
11608 -- Allow_Integer_Address is in effect. We convert the conversion to
11609 -- an unchecked conversion in this case and we are all done.
11611 if Address_Integer_Convert_OK
(Opnd_Type
, Target_Type
) then
11612 Rewrite
(N
, Unchecked_Convert_To
(Target_Type
, Expression
(N
)));
11613 Analyze_And_Resolve
(N
, Target_Type
);
11617 -- If we are within a child unit, check whether the type of the
11618 -- expression has an ancestor in a parent unit, in which case it
11619 -- belongs to its derivation class even if the ancestor is private.
11620 -- See RM 7.3.1 (5.2/3).
11622 Inc_Ancestor
:= Get_Incomplete_View_Of_Ancestor
(Opnd_Type
);
11626 if Is_Numeric_Type
(Target_Type
) then
11628 -- A universal fixed expression can be converted to any numeric type
11630 if Opnd_Type
= Universal_Fixed
then
11633 -- Also no need to check when in an instance or inlined body, because
11634 -- the legality has been established when the template was analyzed.
11635 -- Furthermore, numeric conversions may occur where only a private
11636 -- view of the operand type is visible at the instantiation point.
11637 -- This results in a spurious error if we check that the operand type
11638 -- is a numeric type.
11640 -- Note: in a previous version of this unit, the following tests were
11641 -- applied only for generated code (Comes_From_Source set to False),
11642 -- but in fact the test is required for source code as well, since
11643 -- this situation can arise in source code.
11645 elsif In_Instance
or else In_Inlined_Body
then
11648 -- Otherwise we need the conversion check
11651 return Conversion_Check
11652 (Is_Numeric_Type
(Opnd_Type
)
11654 (Present
(Inc_Ancestor
)
11655 and then Is_Numeric_Type
(Inc_Ancestor
)),
11656 "illegal operand for numeric conversion");
11661 elsif Is_Array_Type
(Target_Type
) then
11662 if not Is_Array_Type
(Opnd_Type
)
11663 or else Opnd_Type
= Any_Composite
11664 or else Opnd_Type
= Any_String
11667 ("illegal operand for array conversion", Operand
);
11671 return Valid_Array_Conversion
;
11674 -- Ada 2005 (AI-251): Anonymous access types where target references an
11677 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11678 E_Anonymous_Access_Type
)
11679 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
11681 -- Check the static accessibility rule of 4.6(17). Note that the
11682 -- check is not enforced when within an instance body, since the
11683 -- RM requires such cases to be caught at run time.
11685 -- If the operand is a rewriting of an allocator no check is needed
11686 -- because there are no accessibility issues.
11688 if Nkind
(Original_Node
(N
)) = N_Allocator
then
11691 elsif Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
11692 if Type_Access_Level
(Opnd_Type
) >
11693 Deepest_Type_Access_Level
(Target_Type
)
11695 -- In an instance, this is a run-time check, but one we know
11696 -- will fail, so generate an appropriate warning. The raise
11697 -- will be generated by Expand_N_Type_Conversion.
11699 if In_Instance_Body
then
11700 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11702 ("cannot convert local pointer to non-local access type<<",
11704 Conversion_Error_N
("\Program_Error [<<", Operand
);
11708 ("cannot convert local pointer to non-local access type",
11713 -- Special accessibility checks are needed in the case of access
11714 -- discriminants declared for a limited type.
11716 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11717 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11719 -- When the operand is a selected access discriminant the check
11720 -- needs to be made against the level of the object denoted by
11721 -- the prefix of the selected name (Object_Access_Level handles
11722 -- checking the prefix of the operand for this case).
11724 if Nkind
(Operand
) = N_Selected_Component
11725 and then Object_Access_Level
(Operand
) >
11726 Deepest_Type_Access_Level
(Target_Type
)
11728 -- In an instance, this is a run-time check, but one we know
11729 -- will fail, so generate an appropriate warning. The raise
11730 -- will be generated by Expand_N_Type_Conversion.
11732 if In_Instance_Body
then
11733 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11735 ("cannot convert access discriminant to non-local "
11736 & "access type<<", Operand
);
11737 Conversion_Error_N
("\Program_Error [<<", Operand
);
11739 -- Real error if not in instance body
11743 ("cannot convert access discriminant to non-local "
11744 & "access type", Operand
);
11749 -- The case of a reference to an access discriminant from
11750 -- within a limited type declaration (which will appear as
11751 -- a discriminal) is always illegal because the level of the
11752 -- discriminant is considered to be deeper than any (nameable)
11755 if Is_Entity_Name
(Operand
)
11756 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11758 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
11759 and then Present
(Discriminal_Link
(Entity
(Operand
)))
11762 ("discriminant has deeper accessibility level than target",
11771 -- General and anonymous access types
11773 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11774 E_Anonymous_Access_Type
)
11777 (Is_Access_Type
(Opnd_Type
)
11779 Ekind_In
(Opnd_Type
, E_Access_Subprogram_Type
,
11780 E_Access_Protected_Subprogram_Type
),
11781 "must be an access-to-object type")
11783 if Is_Access_Constant
(Opnd_Type
)
11784 and then not Is_Access_Constant
(Target_Type
)
11787 ("access-to-constant operand type not allowed", Operand
);
11791 -- Check the static accessibility rule of 4.6(17). Note that the
11792 -- check is not enforced when within an instance body, since the RM
11793 -- requires such cases to be caught at run time.
11795 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
11796 or else Is_Local_Anonymous_Access
(Target_Type
)
11797 or else Nkind
(Associated_Node_For_Itype
(Target_Type
)) =
11798 N_Object_Declaration
11800 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
11801 -- conversions from an anonymous access type to a named general
11802 -- access type. Such conversions are not allowed in the case of
11803 -- access parameters and stand-alone objects of an anonymous
11804 -- access type. The implicit conversion case is recognized by
11805 -- testing that Comes_From_Source is False and that it's been
11806 -- rewritten. The Comes_From_Source test isn't sufficient because
11807 -- nodes in inlined calls to predefined library routines can have
11808 -- Comes_From_Source set to False. (Is there a better way to test
11809 -- for implicit conversions???)
11811 if Ada_Version
>= Ada_2012
11812 and then not Comes_From_Source
(N
)
11813 and then N
/= Original_Node
(N
)
11814 and then Ekind
(Target_Type
) = E_General_Access_Type
11815 and then Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11817 if Is_Itype
(Opnd_Type
) then
11819 -- Implicit conversions aren't allowed for objects of an
11820 -- anonymous access type, since such objects have nonstatic
11821 -- levels in Ada 2012.
11823 if Nkind
(Associated_Node_For_Itype
(Opnd_Type
)) =
11824 N_Object_Declaration
11827 ("implicit conversion of stand-alone anonymous "
11828 & "access object not allowed", Operand
);
11831 -- Implicit conversions aren't allowed for anonymous access
11832 -- parameters. The "not Is_Local_Anonymous_Access_Type" test
11833 -- is done to exclude anonymous access results.
11835 elsif not Is_Local_Anonymous_Access
(Opnd_Type
)
11836 and then Nkind_In
(Associated_Node_For_Itype
(Opnd_Type
),
11837 N_Function_Specification
,
11838 N_Procedure_Specification
)
11841 ("implicit conversion of anonymous access formal "
11842 & "not allowed", Operand
);
11845 -- This is a case where there's an enclosing object whose
11846 -- to which the "statically deeper than" relationship does
11847 -- not apply (such as an access discriminant selected from
11848 -- a dereference of an access parameter).
11850 elsif Object_Access_Level
(Operand
)
11851 = Scope_Depth
(Standard_Standard
)
11854 ("implicit conversion of anonymous access value "
11855 & "not allowed", Operand
);
11858 -- In other cases, the level of the operand's type must be
11859 -- statically less deep than that of the target type, else
11860 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
11862 elsif Type_Access_Level
(Opnd_Type
) >
11863 Deepest_Type_Access_Level
(Target_Type
)
11866 ("implicit conversion of anonymous access value "
11867 & "violates accessibility", Operand
);
11872 elsif Type_Access_Level
(Opnd_Type
) >
11873 Deepest_Type_Access_Level
(Target_Type
)
11875 -- In an instance, this is a run-time check, but one we know
11876 -- will fail, so generate an appropriate warning. The raise
11877 -- will be generated by Expand_N_Type_Conversion.
11879 if In_Instance_Body
then
11880 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11882 ("cannot convert local pointer to non-local access type<<",
11884 Conversion_Error_N
("\Program_Error [<<", Operand
);
11886 -- If not in an instance body, this is a real error
11889 -- Avoid generation of spurious error message
11891 if not Error_Posted
(N
) then
11893 ("cannot convert local pointer to non-local access type",
11900 -- Special accessibility checks are needed in the case of access
11901 -- discriminants declared for a limited type.
11903 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11904 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11906 -- When the operand is a selected access discriminant the check
11907 -- needs to be made against the level of the object denoted by
11908 -- the prefix of the selected name (Object_Access_Level handles
11909 -- checking the prefix of the operand for this case).
11911 if Nkind
(Operand
) = N_Selected_Component
11912 and then Object_Access_Level
(Operand
) >
11913 Deepest_Type_Access_Level
(Target_Type
)
11915 -- In an instance, this is a run-time check, but one we know
11916 -- will fail, so generate an appropriate warning. The raise
11917 -- will be generated by Expand_N_Type_Conversion.
11919 if In_Instance_Body
then
11920 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11922 ("cannot convert access discriminant to non-local "
11923 & "access type<<", Operand
);
11924 Conversion_Error_N
("\Program_Error [<<", Operand
);
11926 -- If not in an instance body, this is a real error
11930 ("cannot convert access discriminant to non-local "
11931 & "access type", Operand
);
11936 -- The case of a reference to an access discriminant from
11937 -- within a limited type declaration (which will appear as
11938 -- a discriminal) is always illegal because the level of the
11939 -- discriminant is considered to be deeper than any (nameable)
11942 if Is_Entity_Name
(Operand
)
11944 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
11945 and then Present
(Discriminal_Link
(Entity
(Operand
)))
11948 ("discriminant has deeper accessibility level than target",
11955 -- In the presence of limited_with clauses we have to use non-limited
11956 -- views, if available.
11958 Check_Limited
: declare
11959 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
11960 -- Helper function to handle limited views
11962 --------------------------
11963 -- Full_Designated_Type --
11964 --------------------------
11966 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
11967 Desig
: constant Entity_Id
:= Designated_Type
(T
);
11970 -- Handle the limited view of a type
11972 if Is_Incomplete_Type
(Desig
)
11973 and then From_Limited_With
(Desig
)
11974 and then Present
(Non_Limited_View
(Desig
))
11976 return Available_View
(Desig
);
11980 end Full_Designated_Type
;
11982 -- Local Declarations
11984 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
11985 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
11987 Same_Base
: constant Boolean :=
11988 Base_Type
(Target
) = Base_Type
(Opnd
);
11990 -- Start of processing for Check_Limited
11993 if Is_Tagged_Type
(Target
) then
11994 return Valid_Tagged_Conversion
(Target
, Opnd
);
11997 if not Same_Base
then
11998 Conversion_Error_NE
11999 ("target designated type not compatible with }",
12000 N
, Base_Type
(Opnd
));
12003 -- Ada 2005 AI-384: legality rule is symmetric in both
12004 -- designated types. The conversion is legal (with possible
12005 -- constraint check) if either designated type is
12008 elsif Subtypes_Statically_Match
(Target
, Opnd
)
12010 (Has_Discriminants
(Target
)
12012 (not Is_Constrained
(Opnd
)
12013 or else not Is_Constrained
(Target
)))
12015 -- Special case, if Value_Size has been used to make the
12016 -- sizes different, the conversion is not allowed even
12017 -- though the subtypes statically match.
12019 if Known_Static_RM_Size
(Target
)
12020 and then Known_Static_RM_Size
(Opnd
)
12021 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
12023 Conversion_Error_NE
12024 ("target designated subtype not compatible with }",
12026 Conversion_Error_NE
12027 ("\because sizes of the two designated subtypes differ",
12031 -- Normal case where conversion is allowed
12039 ("target designated subtype not compatible with }",
12046 -- Access to subprogram types. If the operand is an access parameter,
12047 -- the type has a deeper accessibility that any master, and cannot be
12048 -- assigned. We must make an exception if the conversion is part of an
12049 -- assignment and the target is the return object of an extended return
12050 -- statement, because in that case the accessibility check takes place
12051 -- after the return.
12053 elsif Is_Access_Subprogram_Type
(Target_Type
)
12055 -- Note: this test of Opnd_Type is there to prevent entering this
12056 -- branch in the case of a remote access to subprogram type, which
12057 -- is internally represented as an E_Record_Type.
12059 and then Is_Access_Type
(Opnd_Type
)
12061 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
12062 and then Is_Entity_Name
(Operand
)
12063 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
12065 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
12066 or else not Is_Entity_Name
(Name
(Parent
(N
)))
12067 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
12070 ("illegal attempt to store anonymous access to subprogram",
12073 ("\value has deeper accessibility than any master "
12074 & "(RM 3.10.2 (13))",
12078 ("\use named access type for& instead of access parameter",
12079 Operand
, Entity
(Operand
));
12082 -- Check that the designated types are subtype conformant
12084 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
12085 Old_Id
=> Designated_Type
(Opnd_Type
),
12088 -- Check the static accessibility rule of 4.6(20)
12090 if Type_Access_Level
(Opnd_Type
) >
12091 Deepest_Type_Access_Level
(Target_Type
)
12094 ("operand type has deeper accessibility level than target",
12097 -- Check that if the operand type is declared in a generic body,
12098 -- then the target type must be declared within that same body
12099 -- (enforces last sentence of 4.6(20)).
12101 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
12103 O_Gen
: constant Node_Id
:=
12104 Enclosing_Generic_Body
(Opnd_Type
);
12109 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
12110 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
12111 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
12114 if T_Gen
/= O_Gen
then
12116 ("target type must be declared in same generic body "
12117 & "as operand type", N
);
12124 -- Remote access to subprogram types
12126 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
12127 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
12129 -- It is valid to convert from one RAS type to another provided
12130 -- that their specification statically match.
12132 -- Note: at this point, remote access to subprogram types have been
12133 -- expanded to their E_Record_Type representation, and we need to
12134 -- go back to the original access type definition using the
12135 -- Corresponding_Remote_Type attribute in order to check that the
12136 -- designated profiles match.
12138 pragma Assert
(Ekind
(Target_Type
) = E_Record_Type
);
12139 pragma Assert
(Ekind
(Opnd_Type
) = E_Record_Type
);
12141 Check_Subtype_Conformant
12143 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
12145 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
12150 -- If it was legal in the generic, it's legal in the instance
12152 elsif In_Instance_Body
then
12155 -- If both are tagged types, check legality of view conversions
12157 elsif Is_Tagged_Type
(Target_Type
)
12159 Is_Tagged_Type
(Opnd_Type
)
12161 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
12163 -- Types derived from the same root type are convertible
12165 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
12168 -- In an instance or an inlined body, there may be inconsistent views of
12169 -- the same type, or of types derived from a common root.
12171 elsif (In_Instance
or In_Inlined_Body
)
12173 Root_Type
(Underlying_Type
(Target_Type
)) =
12174 Root_Type
(Underlying_Type
(Opnd_Type
))
12178 -- Special check for common access type error case
12180 elsif Ekind
(Target_Type
) = E_Access_Type
12181 and then Is_Access_Type
(Opnd_Type
)
12183 Conversion_Error_N
("target type must be general access type!", N
);
12184 Conversion_Error_NE
-- CODEFIX
12185 ("add ALL to }!", N
, Target_Type
);
12188 -- Here we have a real conversion error
12191 Conversion_Error_NE
12192 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
12195 end Valid_Conversion
;