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_Atomic_Ref_With_Address
(N
: Node_Id
) return Boolean;
132 -- N is either an indexed component or a selected component. This function
133 -- returns true if the prefix refers to an object that has an address
134 -- clause (the case in which we may want to issue a warning).
136 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean;
137 -- Determine whether E is an access type declared by an access declaration,
138 -- and not an (anonymous) allocator type.
140 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean;
141 -- Utility to check whether the entity for an operator is a predefined
142 -- operator, in which case the expression is left as an operator in the
143 -- tree (else it is rewritten into a call). An instance of an intrinsic
144 -- conversion operation may be given an operator name, but is not treated
145 -- like an operator. Note that an operator that is an imported back-end
146 -- builtin has convention Intrinsic, but is expected to be rewritten into
147 -- a call, so such an operator is not treated as predefined by this
150 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
);
151 -- If a default expression in entry call N depends on the discriminants
152 -- of the task, it must be replaced with a reference to the discriminant
153 -- of the task being called.
155 procedure Resolve_Op_Concat_Arg
160 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
161 -- concatenation operator. The operand is either of the array type or of
162 -- the component type. If the operand is an aggregate, and the component
163 -- type is composite, this is ambiguous if component type has aggregates.
165 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
);
166 -- Does the first part of the work of Resolve_Op_Concat
168 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
);
169 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
170 -- has been resolved. See Resolve_Op_Concat for details.
172 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
);
173 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
);
174 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
);
175 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
176 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
177 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
);
178 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
);
179 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
);
180 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
);
181 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
);
182 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
183 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
);
184 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
);
185 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
186 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
);
187 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
);
188 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
);
189 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
);
190 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
);
191 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
);
192 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
);
193 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
194 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
195 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
);
196 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
197 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
);
198 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
);
199 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
);
200 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
);
201 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
);
202 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
203 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
204 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
);
205 procedure Resolve_Unchecked_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
206 procedure Resolve_Unchecked_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
208 function Operator_Kind
210 Is_Binary
: Boolean) return Node_Kind
;
211 -- Utility to map the name of an operator into the corresponding Node. Used
212 -- by other node rewriting procedures.
214 procedure Resolve_Actuals
(N
: Node_Id
; Nam
: Entity_Id
);
215 -- Resolve actuals of call, and add default expressions for missing ones.
216 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
217 -- called subprogram.
219 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
);
220 -- Called from Resolve_Call, when the prefix denotes an entry or element
221 -- of entry family. Actuals are resolved as for subprograms, and the node
222 -- is rebuilt as an entry call. Also called for protected operations. Typ
223 -- is the context type, which is used when the operation is a protected
224 -- function with no arguments, and the return value is indexed.
226 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
227 -- A call to a user-defined intrinsic operator is rewritten as a call to
228 -- the corresponding predefined operator, with suitable conversions. Note
229 -- that this applies only for intrinsic operators that denote predefined
230 -- operators, not ones that are intrinsic imports of back-end builtins.
232 procedure Resolve_Intrinsic_Unary_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
233 -- Ditto, for arithmetic unary operators
235 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
);
236 -- If an operator node resolves to a call to a user-defined operator,
237 -- rewrite the node as a function call.
239 procedure Make_Call_Into_Operator
243 -- Inverse transformation: if an operator is given in functional notation,
244 -- then after resolving the node, transform into an operator node, so
245 -- that operands are resolved properly. Recall that predefined operators
246 -- do not have a full signature and special resolution rules apply.
248 procedure Rewrite_Renamed_Operator
252 -- An operator can rename another, e.g. in an instantiation. In that
253 -- case, the proper operator node must be constructed and resolved.
255 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
);
256 -- The String_Literal_Subtype is built for all strings that are not
257 -- operands of a static concatenation operation. If the argument is
258 -- not a N_String_Literal node, then the call has no effect.
260 procedure Set_Slice_Subtype
(N
: Node_Id
);
261 -- Build subtype of array type, with the range specified by the slice
263 procedure Simplify_Type_Conversion
(N
: Node_Id
);
264 -- Called after N has been resolved and evaluated, but before range checks
265 -- have been applied. Currently simplifies a combination of floating-point
266 -- to integer conversion and Rounding or Truncation attribute.
268 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
;
269 -- A universal_fixed expression in an universal context is unambiguous if
270 -- there is only one applicable fixed point type. Determining whether there
271 -- is only one requires a search over all visible entities, and happens
272 -- only in very pathological cases (see 6115-006).
274 -------------------------
275 -- Ambiguous_Character --
276 -------------------------
278 procedure Ambiguous_Character
(C
: Node_Id
) is
282 if Nkind
(C
) = N_Character_Literal
then
283 Error_Msg_N
("ambiguous character literal", C
);
285 -- First the ones in Standard
287 Error_Msg_N
("\\possible interpretation: Character!", C
);
288 Error_Msg_N
("\\possible interpretation: Wide_Character!", C
);
290 -- Include Wide_Wide_Character in Ada 2005 mode
292 if Ada_Version
>= Ada_2005
then
293 Error_Msg_N
("\\possible interpretation: Wide_Wide_Character!", C
);
296 -- Now any other types that match
298 E
:= Current_Entity
(C
);
299 while Present
(E
) loop
300 Error_Msg_NE
("\\possible interpretation:}!", C
, Etype
(E
));
304 end Ambiguous_Character
;
306 -------------------------
307 -- Analyze_And_Resolve --
308 -------------------------
310 procedure Analyze_And_Resolve
(N
: Node_Id
) is
314 end Analyze_And_Resolve
;
316 procedure Analyze_And_Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
320 end Analyze_And_Resolve
;
322 -- Versions with check(s) suppressed
324 procedure Analyze_And_Resolve
329 Scop
: constant Entity_Id
:= Current_Scope
;
332 if Suppress
= All_Checks
then
334 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
336 Scope_Suppress
.Suppress
:= (others => True);
337 Analyze_And_Resolve
(N
, Typ
);
338 Scope_Suppress
.Suppress
:= Sva
;
343 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
345 Scope_Suppress
.Suppress
(Suppress
) := True;
346 Analyze_And_Resolve
(N
, Typ
);
347 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
351 if Current_Scope
/= Scop
352 and then Scope_Is_Transient
354 -- This can only happen if a transient scope was created for an inner
355 -- expression, which will be removed upon completion of the analysis
356 -- of an enclosing construct. The transient scope must have the
357 -- suppress status of the enclosing environment, not of this Analyze
360 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
363 end Analyze_And_Resolve
;
365 procedure Analyze_And_Resolve
369 Scop
: constant Entity_Id
:= Current_Scope
;
372 if Suppress
= All_Checks
then
374 Sva
: constant Suppress_Array
:= Scope_Suppress
.Suppress
;
376 Scope_Suppress
.Suppress
:= (others => True);
377 Analyze_And_Resolve
(N
);
378 Scope_Suppress
.Suppress
:= Sva
;
383 Svg
: constant Boolean := Scope_Suppress
.Suppress
(Suppress
);
385 Scope_Suppress
.Suppress
(Suppress
) := True;
386 Analyze_And_Resolve
(N
);
387 Scope_Suppress
.Suppress
(Suppress
) := Svg
;
391 if Current_Scope
/= Scop
and then Scope_Is_Transient
then
392 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
395 end Analyze_And_Resolve
;
397 ----------------------------
398 -- Check_Discriminant_Use --
399 ----------------------------
401 procedure Check_Discriminant_Use
(N
: Node_Id
) is
402 PN
: constant Node_Id
:= Parent
(N
);
403 Disc
: constant Entity_Id
:= Entity
(N
);
408 -- Any use in a spec-expression is legal
410 if In_Spec_Expression
then
413 elsif Nkind
(PN
) = N_Range
then
415 -- Discriminant cannot be used to constrain a scalar type
419 if Nkind
(P
) = N_Range_Constraint
420 and then Nkind
(Parent
(P
)) = N_Subtype_Indication
421 and then Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
423 Error_Msg_N
("discriminant cannot constrain scalar type", N
);
425 elsif Nkind
(P
) = N_Index_Or_Discriminant_Constraint
then
427 -- The following check catches the unusual case where a
428 -- discriminant appears within an index constraint that is part of
429 -- a larger expression within a constraint on a component, e.g. "C
430 -- : Int range 1 .. F (new A(1 .. D))". For now we only check case
431 -- of record components, and note that a similar check should also
432 -- apply in the case of discriminant constraints below. ???
434 -- Note that the check for N_Subtype_Declaration below is to
435 -- detect the valid use of discriminants in the constraints of a
436 -- subtype declaration when this subtype declaration appears
437 -- inside the scope of a record type (which is syntactically
438 -- illegal, but which may be created as part of derived type
439 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
442 if Ekind
(Current_Scope
) = E_Record_Type
443 and then Scope
(Disc
) = Current_Scope
445 (Nkind
(Parent
(P
)) = N_Subtype_Indication
447 Nkind_In
(Parent
(Parent
(P
)), N_Component_Definition
,
448 N_Subtype_Declaration
)
449 and then Paren_Count
(N
) = 0)
452 ("discriminant must appear alone in component constraint", N
);
456 -- Detect a common error:
458 -- type R (D : Positive := 100) is record
459 -- Name : String (1 .. D);
462 -- The default value causes an object of type R to be allocated
463 -- with room for Positive'Last characters. The RM does not mandate
464 -- the allocation of the maximum size, but that is what GNAT does
465 -- so we should warn the programmer that there is a problem.
467 Check_Large
: declare
473 function Large_Storage_Type
(T
: Entity_Id
) return Boolean;
474 -- Return True if type T has a large enough range that any
475 -- array whose index type covered the whole range of the type
476 -- would likely raise Storage_Error.
478 ------------------------
479 -- Large_Storage_Type --
480 ------------------------
482 function Large_Storage_Type
(T
: Entity_Id
) return Boolean is
484 -- The type is considered large if its bounds are known at
485 -- compile time and if it requires at least as many bits as
486 -- a Positive to store the possible values.
488 return Compile_Time_Known_Value
(Type_Low_Bound
(T
))
489 and then Compile_Time_Known_Value
(Type_High_Bound
(T
))
491 Minimum_Size
(T
, Biased
=> True) >=
492 RM_Size
(Standard_Positive
);
493 end Large_Storage_Type
;
495 -- Start of processing for Check_Large
498 -- Check that the Disc has a large range
500 if not Large_Storage_Type
(Etype
(Disc
)) then
504 -- If the enclosing type is limited, we allocate only the
505 -- default value, not the maximum, and there is no need for
508 if Is_Limited_Type
(Scope
(Disc
)) then
512 -- Check that it is the high bound
514 if N
/= High_Bound
(PN
)
515 or else No
(Discriminant_Default_Value
(Disc
))
520 -- Check the array allows a large range at this bound. First
525 if Nkind
(SI
) /= N_Subtype_Indication
then
529 T
:= Entity
(Subtype_Mark
(SI
));
531 if not Is_Array_Type
(T
) then
535 -- Next, find the dimension
537 TB
:= First_Index
(T
);
538 CB
:= First
(Constraints
(P
));
540 and then Present
(TB
)
541 and then Present
(CB
)
552 -- Now, check the dimension has a large range
554 if not Large_Storage_Type
(Etype
(TB
)) then
558 -- Warn about the danger
561 ("??creation of & object may raise Storage_Error!",
570 -- Legal case is in index or discriminant constraint
572 elsif Nkind_In
(PN
, N_Index_Or_Discriminant_Constraint
,
573 N_Discriminant_Association
)
575 if Paren_Count
(N
) > 0 then
577 ("discriminant in constraint must appear alone", N
);
579 elsif Nkind
(N
) = N_Expanded_Name
580 and then Comes_From_Source
(N
)
583 ("discriminant must appear alone as a direct name", N
);
588 -- Otherwise, context is an expression. It should not be within (i.e. a
589 -- subexpression of) a constraint for a component.
594 while not Nkind_In
(P
, N_Component_Declaration
,
595 N_Subtype_Indication
,
603 -- If the discriminant is used in an expression that is a bound of a
604 -- scalar type, an Itype is created and the bounds are attached to
605 -- its range, not to the original subtype indication. Such use is of
606 -- course a double fault.
608 if (Nkind
(P
) = N_Subtype_Indication
609 and then Nkind_In
(Parent
(P
), N_Component_Definition
,
610 N_Derived_Type_Definition
)
611 and then D
= Constraint
(P
))
613 -- The constraint itself may be given by a subtype indication,
614 -- rather than by a more common discrete range.
616 or else (Nkind
(P
) = N_Subtype_Indication
618 Nkind
(Parent
(P
)) = N_Index_Or_Discriminant_Constraint
)
619 or else Nkind
(P
) = N_Entry_Declaration
620 or else Nkind
(D
) = N_Defining_Identifier
623 ("discriminant in constraint must appear alone", N
);
626 end Check_Discriminant_Use
;
628 --------------------------------
629 -- Check_For_Visible_Operator --
630 --------------------------------
632 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
) is
634 if Is_Invisible_Operator
(N
, T
) then
635 Error_Msg_NE
-- CODEFIX
636 ("operator for} is not directly visible!", N
, First_Subtype
(T
));
637 Error_Msg_N
-- CODEFIX
638 ("use clause would make operation legal!", N
);
640 end Check_For_Visible_Operator
;
642 ----------------------------------
643 -- Check_Fully_Declared_Prefix --
644 ----------------------------------
646 procedure Check_Fully_Declared_Prefix
651 -- Check that the designated type of the prefix of a dereference is
652 -- not an incomplete type. This cannot be done unconditionally, because
653 -- dereferences of private types are legal in default expressions. This
654 -- case is taken care of in Check_Fully_Declared, called below. There
655 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
657 -- This consideration also applies to similar checks for allocators,
658 -- qualified expressions, and type conversions.
660 -- An additional exception concerns other per-object expressions that
661 -- are not directly related to component declarations, in particular
662 -- representation pragmas for tasks. These will be per-object
663 -- expressions if they depend on discriminants or some global entity.
664 -- If the task has access discriminants, the designated type may be
665 -- incomplete at the point the expression is resolved. This resolution
666 -- takes place within the body of the initialization procedure, where
667 -- the discriminant is replaced by its discriminal.
669 if Is_Entity_Name
(Pref
)
670 and then Ekind
(Entity
(Pref
)) = E_In_Parameter
674 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
675 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
676 -- Analyze_Object_Renaming, and Freeze_Entity.
678 elsif Ada_Version
>= Ada_2005
679 and then Is_Entity_Name
(Pref
)
680 and then Is_Access_Type
(Etype
(Pref
))
681 and then Ekind
(Directly_Designated_Type
(Etype
(Pref
))) =
683 and then Is_Tagged_Type
(Directly_Designated_Type
(Etype
(Pref
)))
687 Check_Fully_Declared
(Typ
, Parent
(Pref
));
689 end Check_Fully_Declared_Prefix
;
691 ------------------------------
692 -- Check_Infinite_Recursion --
693 ------------------------------
695 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean is
699 function Same_Argument_List
return Boolean;
700 -- Check whether list of actuals is identical to list of formals of
701 -- called function (which is also the enclosing scope).
703 ------------------------
704 -- Same_Argument_List --
705 ------------------------
707 function Same_Argument_List
return Boolean is
713 if not Is_Entity_Name
(Name
(N
)) then
716 Subp
:= Entity
(Name
(N
));
719 F
:= First_Formal
(Subp
);
720 A
:= First_Actual
(N
);
721 while Present
(F
) and then Present
(A
) loop
722 if not Is_Entity_Name
(A
)
723 or else Entity
(A
) /= F
733 end Same_Argument_List
;
735 -- Start of processing for Check_Infinite_Recursion
738 -- Special case, if this is a procedure call and is a call to the
739 -- current procedure with the same argument list, then this is for
740 -- sure an infinite recursion and we insert a call to raise SE.
742 if Is_List_Member
(N
)
743 and then List_Length
(List_Containing
(N
)) = 1
744 and then Same_Argument_List
747 P
: constant Node_Id
:= Parent
(N
);
749 if Nkind
(P
) = N_Handled_Sequence_Of_Statements
750 and then Nkind
(Parent
(P
)) = N_Subprogram_Body
751 and then Is_Empty_List
(Declarations
(Parent
(P
)))
753 Error_Msg_Warn
:= SPARK_Mode
/= On
;
754 Error_Msg_N
("!infinite recursion<<", N
);
755 Error_Msg_N
("\!Storage_Error [<<", N
);
757 Make_Raise_Storage_Error
(Sloc
(N
),
758 Reason
=> SE_Infinite_Recursion
));
764 -- If not that special case, search up tree, quitting if we reach a
765 -- construct (e.g. a conditional) that tells us that this is not a
766 -- case for an infinite recursion warning.
772 -- If no parent, then we were not inside a subprogram, this can for
773 -- example happen when processing certain pragmas in a spec. Just
774 -- return False in this case.
780 -- Done if we get to subprogram body, this is definitely an infinite
781 -- recursion case if we did not find anything to stop us.
783 exit when Nkind
(P
) = N_Subprogram_Body
;
785 -- If appearing in conditional, result is false
787 if Nkind_In
(P
, N_Or_Else
,
796 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
797 and then C
/= First
(Statements
(P
))
799 -- If the call is the expression of a return statement and the
800 -- actuals are identical to the formals, it's worth a warning.
801 -- However, we skip this if there is an immediately preceding
802 -- raise statement, since the call is never executed.
804 -- Furthermore, this corresponds to a common idiom:
806 -- function F (L : Thing) return Boolean is
808 -- raise Program_Error;
812 -- for generating a stub function
814 if Nkind
(Parent
(N
)) = N_Simple_Return_Statement
815 and then Same_Argument_List
817 exit when not Is_List_Member
(Parent
(N
));
819 -- OK, return statement is in a statement list, look for raise
825 -- Skip past N_Freeze_Entity nodes generated by expansion
827 Nod
:= Prev
(Parent
(N
));
829 and then Nkind
(Nod
) = N_Freeze_Entity
834 -- If no raise statement, give warning. We look at the
835 -- original node, because in the case of "raise ... with
836 -- ...", the node has been transformed into a call.
838 exit when Nkind
(Original_Node
(Nod
)) /= N_Raise_Statement
840 (Nkind
(Nod
) not in N_Raise_xxx_Error
841 or else Present
(Condition
(Nod
)));
852 Error_Msg_Warn
:= SPARK_Mode
/= On
;
853 Error_Msg_N
("!possible infinite recursion<<", N
);
854 Error_Msg_N
("\!??Storage_Error ]<<", N
);
857 end Check_Infinite_Recursion
;
859 -------------------------------
860 -- Check_Initialization_Call --
861 -------------------------------
863 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
) is
864 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
866 function Uses_SS
(T
: Entity_Id
) return Boolean;
867 -- Check whether the creation of an object of the type will involve
868 -- use of the secondary stack. If T is a record type, this is true
869 -- if the expression for some component uses the secondary stack, e.g.
870 -- through a call to a function that returns an unconstrained value.
871 -- False if T is controlled, because cleanups occur elsewhere.
877 function Uses_SS
(T
: Entity_Id
) return Boolean is
880 Full_Type
: Entity_Id
:= Underlying_Type
(T
);
883 -- Normally we want to use the underlying type, but if it's not set
884 -- then continue with T.
886 if not Present
(Full_Type
) then
890 if Is_Controlled
(Full_Type
) then
893 elsif Is_Array_Type
(Full_Type
) then
894 return Uses_SS
(Component_Type
(Full_Type
));
896 elsif Is_Record_Type
(Full_Type
) then
897 Comp
:= First_Component
(Full_Type
);
898 while Present
(Comp
) loop
899 if Ekind
(Comp
) = E_Component
900 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
902 -- The expression for a dynamic component may be rewritten
903 -- as a dereference, so retrieve original node.
905 Expr
:= Original_Node
(Expression
(Parent
(Comp
)));
907 -- Return True if the expression is a call to a function
908 -- (including an attribute function such as Image, or a
909 -- user-defined operator) with a result that requires a
912 if (Nkind
(Expr
) = N_Function_Call
913 or else Nkind
(Expr
) in N_Op
914 or else (Nkind
(Expr
) = N_Attribute_Reference
915 and then Present
(Expressions
(Expr
))))
916 and then Requires_Transient_Scope
(Etype
(Expr
))
920 elsif Uses_SS
(Etype
(Comp
)) then
925 Next_Component
(Comp
);
935 -- Start of processing for Check_Initialization_Call
938 -- Establish a transient scope if the type needs it
940 if Uses_SS
(Typ
) then
941 Establish_Transient_Scope
(First_Actual
(N
), Sec_Stack
=> True);
943 end Check_Initialization_Call
;
945 ---------------------------------------
946 -- Check_No_Direct_Boolean_Operators --
947 ---------------------------------------
949 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
) is
951 if Scope
(Entity
(N
)) = Standard_Standard
952 and then Root_Type
(Etype
(Left_Opnd
(N
))) = Standard_Boolean
954 -- Restriction only applies to original source code
956 if Comes_From_Source
(N
) then
957 Check_Restriction
(No_Direct_Boolean_Operators
, N
);
961 -- Do style check (but skip if in instance, error is on template)
964 if not In_Instance
then
965 Check_Boolean_Operator
(N
);
968 end Check_No_Direct_Boolean_Operators
;
970 ------------------------------
971 -- Check_Parameterless_Call --
972 ------------------------------
974 procedure Check_Parameterless_Call
(N
: Node_Id
) is
977 function Prefix_Is_Access_Subp
return Boolean;
978 -- If the prefix is of an access_to_subprogram type, the node must be
979 -- rewritten as a call. Ditto if the prefix is overloaded and all its
980 -- interpretations are access to subprograms.
982 ---------------------------
983 -- Prefix_Is_Access_Subp --
984 ---------------------------
986 function Prefix_Is_Access_Subp
return Boolean is
991 -- If the context is an attribute reference that can apply to
992 -- functions, this is never a parameterless call (RM 4.1.4(6)).
994 if Nkind
(Parent
(N
)) = N_Attribute_Reference
995 and then Nam_In
(Attribute_Name
(Parent
(N
)), Name_Address
,
1002 if not Is_Overloaded
(N
) then
1004 Ekind
(Etype
(N
)) = E_Subprogram_Type
1005 and then Base_Type
(Etype
(Etype
(N
))) /= Standard_Void_Type
;
1007 Get_First_Interp
(N
, I
, It
);
1008 while Present
(It
.Typ
) loop
1009 if Ekind
(It
.Typ
) /= E_Subprogram_Type
1010 or else Base_Type
(Etype
(It
.Typ
)) = Standard_Void_Type
1015 Get_Next_Interp
(I
, It
);
1020 end Prefix_Is_Access_Subp
;
1022 -- Start of processing for Check_Parameterless_Call
1025 -- Defend against junk stuff if errors already detected
1027 if Total_Errors_Detected
/= 0 then
1028 if Nkind
(N
) in N_Has_Etype
and then Etype
(N
) = Any_Type
then
1030 elsif Nkind
(N
) in N_Has_Chars
1031 and then Chars
(N
) in Error_Name_Or_No_Name
1039 -- If the context expects a value, and the name is a procedure, this is
1040 -- most likely a missing 'Access. Don't try to resolve the parameterless
1041 -- call, error will be caught when the outer call is analyzed.
1043 if Is_Entity_Name
(N
)
1044 and then Ekind
(Entity
(N
)) = E_Procedure
1045 and then not Is_Overloaded
(N
)
1047 Nkind_In
(Parent
(N
), N_Parameter_Association
,
1049 N_Procedure_Call_Statement
)
1054 -- Rewrite as call if overloadable entity that is (or could be, in the
1055 -- overloaded case) a function call. If we know for sure that the entity
1056 -- is an enumeration literal, we do not rewrite it.
1058 -- If the entity is the name of an operator, it cannot be a call because
1059 -- operators cannot have default parameters. In this case, this must be
1060 -- a string whose contents coincide with an operator name. Set the kind
1061 -- of the node appropriately.
1063 if (Is_Entity_Name
(N
)
1064 and then Nkind
(N
) /= N_Operator_Symbol
1065 and then Is_Overloadable
(Entity
(N
))
1066 and then (Ekind
(Entity
(N
)) /= E_Enumeration_Literal
1067 or else Is_Overloaded
(N
)))
1069 -- Rewrite as call if it is an explicit dereference of an expression of
1070 -- a subprogram access type, and the subprogram type is not that of a
1071 -- procedure or entry.
1074 (Nkind
(N
) = N_Explicit_Dereference
and then Prefix_Is_Access_Subp
)
1076 -- Rewrite as call if it is a selected component which is a function,
1077 -- this is the case of a call to a protected function (which may be
1078 -- overloaded with other protected operations).
1081 (Nkind
(N
) = N_Selected_Component
1082 and then (Ekind
(Entity
(Selector_Name
(N
))) = E_Function
1084 (Ekind_In
(Entity
(Selector_Name
(N
)), E_Entry
,
1086 and then Is_Overloaded
(Selector_Name
(N
)))))
1088 -- If one of the above three conditions is met, rewrite as call. Apply
1089 -- the rewriting only once.
1092 if Nkind
(Parent
(N
)) /= N_Function_Call
1093 or else N
/= Name
(Parent
(N
))
1096 -- This may be a prefixed call that was not fully analyzed, e.g.
1097 -- an actual in an instance.
1099 if Ada_Version
>= Ada_2005
1100 and then Nkind
(N
) = N_Selected_Component
1101 and then Is_Dispatching_Operation
(Entity
(Selector_Name
(N
)))
1103 Analyze_Selected_Component
(N
);
1105 if Nkind
(N
) /= N_Selected_Component
then
1110 -- The node is the name of the parameterless call. Preserve its
1111 -- descendants, which may be complex expressions.
1113 Nam
:= Relocate_Node
(N
);
1115 -- If overloaded, overload set belongs to new copy
1117 Save_Interps
(N
, Nam
);
1119 -- Change node to parameterless function call (note that the
1120 -- Parameter_Associations associations field is left set to Empty,
1121 -- its normal default value since there are no parameters)
1123 Change_Node
(N
, N_Function_Call
);
1125 Set_Sloc
(N
, Sloc
(Nam
));
1129 elsif Nkind
(N
) = N_Parameter_Association
then
1130 Check_Parameterless_Call
(Explicit_Actual_Parameter
(N
));
1132 elsif Nkind
(N
) = N_Operator_Symbol
then
1133 Change_Operator_Symbol_To_String_Literal
(N
);
1134 Set_Is_Overloaded
(N
, False);
1135 Set_Etype
(N
, Any_String
);
1137 end Check_Parameterless_Call
;
1139 --------------------------------
1140 -- Is_Atomic_Ref_With_Address --
1141 --------------------------------
1143 function Is_Atomic_Ref_With_Address
(N
: Node_Id
) return Boolean is
1144 Pref
: constant Node_Id
:= Prefix
(N
);
1147 if not Is_Entity_Name
(Pref
) then
1152 Pent
: constant Entity_Id
:= Entity
(Pref
);
1153 Ptyp
: constant Entity_Id
:= Etype
(Pent
);
1155 return not Is_Access_Type
(Ptyp
)
1156 and then (Is_Atomic
(Ptyp
) or else Is_Atomic
(Pent
))
1157 and then Present
(Address_Clause
(Pent
));
1160 end Is_Atomic_Ref_With_Address
;
1162 -----------------------------
1163 -- Is_Definite_Access_Type --
1164 -----------------------------
1166 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean is
1167 Btyp
: constant Entity_Id
:= Base_Type
(E
);
1169 return Ekind
(Btyp
) = E_Access_Type
1170 or else (Ekind
(Btyp
) = E_Access_Subprogram_Type
1171 and then Comes_From_Source
(Btyp
));
1172 end Is_Definite_Access_Type
;
1174 ----------------------
1175 -- Is_Predefined_Op --
1176 ----------------------
1178 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean is
1180 -- Predefined operators are intrinsic subprograms
1182 if not Is_Intrinsic_Subprogram
(Nam
) then
1186 -- A call to a back-end builtin is never a predefined operator
1188 if Is_Imported
(Nam
) and then Present
(Interface_Name
(Nam
)) then
1192 return not Is_Generic_Instance
(Nam
)
1193 and then Chars
(Nam
) in Any_Operator_Name
1194 and then (No
(Alias
(Nam
)) or else Is_Predefined_Op
(Alias
(Nam
)));
1195 end Is_Predefined_Op
;
1197 -----------------------------
1198 -- Make_Call_Into_Operator --
1199 -----------------------------
1201 procedure Make_Call_Into_Operator
1206 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
1207 Act1
: Node_Id
:= First_Actual
(N
);
1208 Act2
: Node_Id
:= Next_Actual
(Act1
);
1209 Error
: Boolean := False;
1210 Func
: constant Entity_Id
:= Entity
(Name
(N
));
1211 Is_Binary
: constant Boolean := Present
(Act2
);
1213 Opnd_Type
: Entity_Id
;
1214 Orig_Type
: Entity_Id
:= Empty
;
1217 type Kind_Test
is access function (E
: Entity_Id
) return Boolean;
1219 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean;
1220 -- If the operand is not universal, and the operator is given by an
1221 -- expanded name, verify that the operand has an interpretation with a
1222 -- type defined in the given scope of the operator.
1224 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
;
1225 -- Find a type of the given class in package Pack that contains the
1228 ---------------------------
1229 -- Operand_Type_In_Scope --
1230 ---------------------------
1232 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean is
1233 Nod
: constant Node_Id
:= Right_Opnd
(Op_Node
);
1238 if not Is_Overloaded
(Nod
) then
1239 return Scope
(Base_Type
(Etype
(Nod
))) = S
;
1242 Get_First_Interp
(Nod
, I
, It
);
1243 while Present
(It
.Typ
) loop
1244 if Scope
(Base_Type
(It
.Typ
)) = S
then
1248 Get_Next_Interp
(I
, It
);
1253 end Operand_Type_In_Scope
;
1259 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
is
1262 function In_Decl
return Boolean;
1263 -- Verify that node is not part of the type declaration for the
1264 -- candidate type, which would otherwise be invisible.
1270 function In_Decl
return Boolean is
1271 Decl_Node
: constant Node_Id
:= Parent
(E
);
1277 if Etype
(E
) = Any_Type
then
1280 elsif No
(Decl_Node
) then
1285 and then Nkind
(N2
) /= N_Compilation_Unit
1287 if N2
= Decl_Node
then
1298 -- Start of processing for Type_In_P
1301 -- If the context type is declared in the prefix package, this is the
1302 -- desired base type.
1304 if Scope
(Base_Type
(Typ
)) = Pack
and then Test
(Typ
) then
1305 return Base_Type
(Typ
);
1308 E
:= First_Entity
(Pack
);
1309 while Present
(E
) loop
1311 and then not In_Decl
1323 -- Start of processing for Make_Call_Into_Operator
1326 Op_Node
:= New_Node
(Operator_Kind
(Op_Name
, Is_Binary
), Sloc
(N
));
1331 Set_Left_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1332 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act2
));
1333 Save_Interps
(Act1
, Left_Opnd
(Op_Node
));
1334 Save_Interps
(Act2
, Right_Opnd
(Op_Node
));
1335 Act1
:= Left_Opnd
(Op_Node
);
1336 Act2
:= Right_Opnd
(Op_Node
);
1341 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1342 Save_Interps
(Act1
, Right_Opnd
(Op_Node
));
1343 Act1
:= Right_Opnd
(Op_Node
);
1346 -- If the operator is denoted by an expanded name, and the prefix is
1347 -- not Standard, but the operator is a predefined one whose scope is
1348 -- Standard, then this is an implicit_operator, inserted as an
1349 -- interpretation by the procedure of the same name. This procedure
1350 -- overestimates the presence of implicit operators, because it does
1351 -- not examine the type of the operands. Verify now that the operand
1352 -- type appears in the given scope. If right operand is universal,
1353 -- check the other operand. In the case of concatenation, either
1354 -- argument can be the component type, so check the type of the result.
1355 -- If both arguments are literals, look for a type of the right kind
1356 -- defined in the given scope. This elaborate nonsense is brought to
1357 -- you courtesy of b33302a. The type itself must be frozen, so we must
1358 -- find the type of the proper class in the given scope.
1360 -- A final wrinkle is the multiplication operator for fixed point types,
1361 -- which is defined in Standard only, and not in the scope of the
1362 -- fixed point type itself.
1364 if Nkind
(Name
(N
)) = N_Expanded_Name
then
1365 Pack
:= Entity
(Prefix
(Name
(N
)));
1367 -- If this is a package renaming, get renamed entity, which will be
1368 -- the scope of the operands if operaton is type-correct.
1370 if Present
(Renamed_Entity
(Pack
)) then
1371 Pack
:= Renamed_Entity
(Pack
);
1374 -- If the entity being called is defined in the given package, it is
1375 -- a renaming of a predefined operator, and known to be legal.
1377 if Scope
(Entity
(Name
(N
))) = Pack
1378 and then Pack
/= Standard_Standard
1382 -- Visibility does not need to be checked in an instance: if the
1383 -- operator was not visible in the generic it has been diagnosed
1384 -- already, else there is an implicit copy of it in the instance.
1386 elsif In_Instance
then
1389 elsif Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
)
1390 and then Is_Fixed_Point_Type
(Etype
(Left_Opnd
(Op_Node
)))
1391 and then Is_Fixed_Point_Type
(Etype
(Right_Opnd
(Op_Node
)))
1393 if Pack
/= Standard_Standard
then
1397 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1400 elsif Ada_Version
>= Ada_2005
1401 and then Nam_In
(Op_Name
, Name_Op_Eq
, Name_Op_Ne
)
1402 and then Ekind
(Etype
(Act1
)) = E_Anonymous_Access_Type
1407 Opnd_Type
:= Base_Type
(Etype
(Right_Opnd
(Op_Node
)));
1409 if Op_Name
= Name_Op_Concat
then
1410 Opnd_Type
:= Base_Type
(Typ
);
1412 elsif (Scope
(Opnd_Type
) = Standard_Standard
1414 or else (Nkind
(Right_Opnd
(Op_Node
)) = N_Attribute_Reference
1416 and then not Comes_From_Source
(Opnd_Type
))
1418 Opnd_Type
:= Base_Type
(Etype
(Left_Opnd
(Op_Node
)));
1421 if Scope
(Opnd_Type
) = Standard_Standard
then
1423 -- Verify that the scope contains a type that corresponds to
1424 -- the given literal. Optimize the case where Pack is Standard.
1426 if Pack
/= Standard_Standard
then
1428 if Opnd_Type
= Universal_Integer
then
1429 Orig_Type
:= Type_In_P
(Is_Integer_Type
'Access);
1431 elsif Opnd_Type
= Universal_Real
then
1432 Orig_Type
:= Type_In_P
(Is_Real_Type
'Access);
1434 elsif Opnd_Type
= Any_String
then
1435 Orig_Type
:= Type_In_P
(Is_String_Type
'Access);
1437 elsif Opnd_Type
= Any_Access
then
1438 Orig_Type
:= Type_In_P
(Is_Definite_Access_Type
'Access);
1440 elsif Opnd_Type
= Any_Composite
then
1441 Orig_Type
:= Type_In_P
(Is_Composite_Type
'Access);
1443 if Present
(Orig_Type
) then
1444 if Has_Private_Component
(Orig_Type
) then
1447 Set_Etype
(Act1
, Orig_Type
);
1450 Set_Etype
(Act2
, Orig_Type
);
1459 Error
:= No
(Orig_Type
);
1462 elsif Ekind
(Opnd_Type
) = E_Allocator_Type
1463 and then No
(Type_In_P
(Is_Definite_Access_Type
'Access))
1467 -- If the type is defined elsewhere, and the operator is not
1468 -- defined in the given scope (by a renaming declaration, e.g.)
1469 -- then this is an error as well. If an extension of System is
1470 -- present, and the type may be defined there, Pack must be
1473 elsif Scope
(Opnd_Type
) /= Pack
1474 and then Scope
(Op_Id
) /= Pack
1475 and then (No
(System_Aux_Id
)
1476 or else Scope
(Opnd_Type
) /= System_Aux_Id
1477 or else Pack
/= Scope
(System_Aux_Id
))
1479 if not Is_Overloaded
(Right_Opnd
(Op_Node
)) then
1482 Error
:= not Operand_Type_In_Scope
(Pack
);
1485 elsif Pack
= Standard_Standard
1486 and then not Operand_Type_In_Scope
(Standard_Standard
)
1493 Error_Msg_Node_2
:= Pack
;
1495 ("& not declared in&", N
, Selector_Name
(Name
(N
)));
1496 Set_Etype
(N
, Any_Type
);
1499 -- Detect a mismatch between the context type and the result type
1500 -- in the named package, which is otherwise not detected if the
1501 -- operands are universal. Check is only needed if source entity is
1502 -- an operator, not a function that renames an operator.
1504 elsif Nkind
(Parent
(N
)) /= N_Type_Conversion
1505 and then Ekind
(Entity
(Name
(N
))) = E_Operator
1506 and then Is_Numeric_Type
(Typ
)
1507 and then not Is_Universal_Numeric_Type
(Typ
)
1508 and then Scope
(Base_Type
(Typ
)) /= Pack
1509 and then not In_Instance
1511 if Is_Fixed_Point_Type
(Typ
)
1512 and then Nam_In
(Op_Name
, Name_Op_Multiply
, Name_Op_Divide
)
1514 -- Already checked above
1518 -- Operator may be defined in an extension of System
1520 elsif Present
(System_Aux_Id
)
1521 and then Scope
(Opnd_Type
) = System_Aux_Id
1526 -- Could we use Wrong_Type here??? (this would require setting
1527 -- Etype (N) to the actual type found where Typ was expected).
1529 Error_Msg_NE
("expect }", N
, Typ
);
1534 Set_Chars
(Op_Node
, Op_Name
);
1536 if not Is_Private_Type
(Etype
(N
)) then
1537 Set_Etype
(Op_Node
, Base_Type
(Etype
(N
)));
1539 Set_Etype
(Op_Node
, Etype
(N
));
1542 -- If this is a call to a function that renames a predefined equality,
1543 -- the renaming declaration provides a type that must be used to
1544 -- resolve the operands. This must be done now because resolution of
1545 -- the equality node will not resolve any remaining ambiguity, and it
1546 -- assumes that the first operand is not overloaded.
1548 if Nam_In
(Op_Name
, Name_Op_Eq
, Name_Op_Ne
)
1549 and then Ekind
(Func
) = E_Function
1550 and then Is_Overloaded
(Act1
)
1552 Resolve
(Act1
, Base_Type
(Etype
(First_Formal
(Func
))));
1553 Resolve
(Act2
, Base_Type
(Etype
(First_Formal
(Func
))));
1556 Set_Entity
(Op_Node
, Op_Id
);
1557 Generate_Reference
(Op_Id
, N
, ' ');
1559 -- Do rewrite setting Comes_From_Source on the result if the original
1560 -- call came from source. Although it is not strictly the case that the
1561 -- operator as such comes from the source, logically it corresponds
1562 -- exactly to the function call in the source, so it should be marked
1563 -- this way (e.g. to make sure that validity checks work fine).
1566 CS
: constant Boolean := Comes_From_Source
(N
);
1568 Rewrite
(N
, Op_Node
);
1569 Set_Comes_From_Source
(N
, CS
);
1572 -- If this is an arithmetic operator and the result type is private,
1573 -- the operands and the result must be wrapped in conversion to
1574 -- expose the underlying numeric type and expand the proper checks,
1575 -- e.g. on division.
1577 if Is_Private_Type
(Typ
) then
1579 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1580 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
1581 Resolve_Intrinsic_Operator
(N
, Typ
);
1583 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
1584 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
1593 -- If in ASIS_Mode, propagate operand types to original actuals of
1594 -- function call, which would otherwise not be fully resolved. If
1595 -- the call has already been constant-folded, nothing to do. We
1596 -- relocate the operand nodes rather than copy them, to preserve
1597 -- original_node pointers, given that the operands themselves may
1598 -- have been rewritten. If the call was itself a rewriting of an
1599 -- operator node, nothing to do.
1602 and then Nkind
(N
) in N_Op
1603 and then Nkind
(Original_Node
(N
)) = N_Function_Call
1606 Rewrite
(First
(Parameter_Associations
(Original_Node
(N
))),
1607 Relocate_Node
(Left_Opnd
(N
)));
1608 Rewrite
(Next
(First
(Parameter_Associations
(Original_Node
(N
)))),
1609 Relocate_Node
(Right_Opnd
(N
)));
1611 Rewrite
(First
(Parameter_Associations
(Original_Node
(N
))),
1612 Relocate_Node
(Right_Opnd
(N
)));
1615 Set_Parent
(Original_Node
(N
), Parent
(N
));
1617 end Make_Call_Into_Operator
;
1623 function Operator_Kind
1625 Is_Binary
: Boolean) return Node_Kind
1630 -- Use CASE statement or array???
1633 if Op_Name
= Name_Op_And
then
1635 elsif Op_Name
= Name_Op_Or
then
1637 elsif Op_Name
= Name_Op_Xor
then
1639 elsif Op_Name
= Name_Op_Eq
then
1641 elsif Op_Name
= Name_Op_Ne
then
1643 elsif Op_Name
= Name_Op_Lt
then
1645 elsif Op_Name
= Name_Op_Le
then
1647 elsif Op_Name
= Name_Op_Gt
then
1649 elsif Op_Name
= Name_Op_Ge
then
1651 elsif Op_Name
= Name_Op_Add
then
1653 elsif Op_Name
= Name_Op_Subtract
then
1654 Kind
:= N_Op_Subtract
;
1655 elsif Op_Name
= Name_Op_Concat
then
1656 Kind
:= N_Op_Concat
;
1657 elsif Op_Name
= Name_Op_Multiply
then
1658 Kind
:= N_Op_Multiply
;
1659 elsif Op_Name
= Name_Op_Divide
then
1660 Kind
:= N_Op_Divide
;
1661 elsif Op_Name
= Name_Op_Mod
then
1663 elsif Op_Name
= Name_Op_Rem
then
1665 elsif Op_Name
= Name_Op_Expon
then
1668 raise Program_Error
;
1674 if Op_Name
= Name_Op_Add
then
1676 elsif Op_Name
= Name_Op_Subtract
then
1678 elsif Op_Name
= Name_Op_Abs
then
1680 elsif Op_Name
= Name_Op_Not
then
1683 raise Program_Error
;
1690 ----------------------------
1691 -- Preanalyze_And_Resolve --
1692 ----------------------------
1694 procedure Preanalyze_And_Resolve
(N
: Node_Id
; T
: Entity_Id
) is
1695 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1698 Full_Analysis
:= False;
1699 Expander_Mode_Save_And_Set
(False);
1701 -- Normally, we suppress all checks for this preanalysis. There is no
1702 -- point in processing them now, since they will be applied properly
1703 -- and in the proper location when the default expressions reanalyzed
1704 -- and reexpanded later on. We will also have more information at that
1705 -- point for possible suppression of individual checks.
1707 -- However, in SPARK mode, most expansion is suppressed, and this
1708 -- later reanalysis and reexpansion may not occur. SPARK mode does
1709 -- require the setting of checking flags for proof purposes, so we
1710 -- do the SPARK preanalysis without suppressing checks.
1712 -- This special handling for SPARK mode is required for example in the
1713 -- case of Ada 2012 constructs such as quantified expressions, which are
1714 -- expanded in two separate steps.
1716 if GNATprove_Mode
then
1717 Analyze_And_Resolve
(N
, T
);
1719 Analyze_And_Resolve
(N
, T
, Suppress
=> All_Checks
);
1722 Expander_Mode_Restore
;
1723 Full_Analysis
:= Save_Full_Analysis
;
1724 end Preanalyze_And_Resolve
;
1726 -- Version without context type
1728 procedure Preanalyze_And_Resolve
(N
: Node_Id
) is
1729 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1732 Full_Analysis
:= False;
1733 Expander_Mode_Save_And_Set
(False);
1736 Resolve
(N
, Etype
(N
), Suppress
=> All_Checks
);
1738 Expander_Mode_Restore
;
1739 Full_Analysis
:= Save_Full_Analysis
;
1740 end Preanalyze_And_Resolve
;
1742 ----------------------------------
1743 -- Replace_Actual_Discriminants --
1744 ----------------------------------
1746 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
) is
1747 Loc
: constant Source_Ptr
:= Sloc
(N
);
1748 Tsk
: Node_Id
:= Empty
;
1750 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
;
1751 -- Comment needed???
1757 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
is
1761 if Nkind
(Nod
) = N_Identifier
then
1762 Ent
:= Entity
(Nod
);
1765 and then Ekind
(Ent
) = E_Discriminant
1768 Make_Selected_Component
(Loc
,
1769 Prefix
=> New_Copy_Tree
(Tsk
, New_Sloc
=> Loc
),
1770 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Ent
))));
1772 Set_Etype
(Nod
, Etype
(Ent
));
1780 procedure Replace_Discrs
is new Traverse_Proc
(Process_Discr
);
1782 -- Start of processing for Replace_Actual_Discriminants
1785 if not Expander_Active
then
1789 if Nkind
(Name
(N
)) = N_Selected_Component
then
1790 Tsk
:= Prefix
(Name
(N
));
1792 elsif Nkind
(Name
(N
)) = N_Indexed_Component
then
1793 Tsk
:= Prefix
(Prefix
(Name
(N
)));
1799 Replace_Discrs
(Default
);
1801 end Replace_Actual_Discriminants
;
1807 procedure Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
1808 Ambiguous
: Boolean := False;
1809 Ctx_Type
: Entity_Id
:= Typ
;
1810 Expr_Type
: Entity_Id
:= Empty
; -- prevent junk warning
1811 Err_Type
: Entity_Id
:= Empty
;
1812 Found
: Boolean := False;
1815 I1
: Interp_Index
:= 0; -- prevent junk warning
1818 Seen
: Entity_Id
:= Empty
; -- prevent junk warning
1820 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean;
1821 -- Determine whether a node comes from a predefined library unit or
1824 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
);
1825 -- Try and fix up a literal so that it matches its expected type. New
1826 -- literals are manufactured if necessary to avoid cascaded errors.
1828 procedure Report_Ambiguous_Argument
;
1829 -- Additional diagnostics when an ambiguous call has an ambiguous
1830 -- argument (typically a controlling actual).
1832 procedure Resolution_Failed
;
1833 -- Called when attempt at resolving current expression fails
1835 ------------------------------------
1836 -- Comes_From_Predefined_Lib_Unit --
1837 -------------------------------------
1839 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean is
1842 Sloc
(Nod
) = Standard_Location
1843 or else Is_Predefined_File_Name
1844 (Unit_File_Name
(Get_Source_Unit
(Sloc
(Nod
))));
1845 end Comes_From_Predefined_Lib_Unit
;
1847 --------------------
1848 -- Patch_Up_Value --
1849 --------------------
1851 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
) is
1853 if Nkind
(N
) = N_Integer_Literal
and then Is_Real_Type
(Typ
) then
1855 Make_Real_Literal
(Sloc
(N
),
1856 Realval
=> UR_From_Uint
(Intval
(N
))));
1857 Set_Etype
(N
, Universal_Real
);
1858 Set_Is_Static_Expression
(N
);
1860 elsif Nkind
(N
) = N_Real_Literal
and then Is_Integer_Type
(Typ
) then
1862 Make_Integer_Literal
(Sloc
(N
),
1863 Intval
=> UR_To_Uint
(Realval
(N
))));
1864 Set_Etype
(N
, Universal_Integer
);
1865 Set_Is_Static_Expression
(N
);
1867 elsif Nkind
(N
) = N_String_Literal
1868 and then Is_Character_Type
(Typ
)
1870 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('A')));
1872 Make_Character_Literal
(Sloc
(N
),
1874 Char_Literal_Value
=>
1875 UI_From_Int
(Character'Pos ('A'))));
1876 Set_Etype
(N
, Any_Character
);
1877 Set_Is_Static_Expression
(N
);
1879 elsif Nkind
(N
) /= N_String_Literal
and then Is_String_Type
(Typ
) then
1881 Make_String_Literal
(Sloc
(N
),
1882 Strval
=> End_String
));
1884 elsif Nkind
(N
) = N_Range
then
1885 Patch_Up_Value
(Low_Bound
(N
), Typ
);
1886 Patch_Up_Value
(High_Bound
(N
), Typ
);
1890 -------------------------------
1891 -- Report_Ambiguous_Argument --
1892 -------------------------------
1894 procedure Report_Ambiguous_Argument
is
1895 Arg
: constant Node_Id
:= First
(Parameter_Associations
(N
));
1900 if Nkind
(Arg
) = N_Function_Call
1901 and then Is_Entity_Name
(Name
(Arg
))
1902 and then Is_Overloaded
(Name
(Arg
))
1904 Error_Msg_NE
("ambiguous call to&", Arg
, Name
(Arg
));
1906 -- Could use comments on what is going on here???
1908 Get_First_Interp
(Name
(Arg
), I
, It
);
1909 while Present
(It
.Nam
) loop
1910 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
1912 if Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
then
1913 Error_Msg_N
("interpretation (inherited) #!", Arg
);
1915 Error_Msg_N
("interpretation #!", Arg
);
1918 Get_Next_Interp
(I
, It
);
1921 end Report_Ambiguous_Argument
;
1923 -----------------------
1924 -- Resolution_Failed --
1925 -----------------------
1927 procedure Resolution_Failed
is
1929 Patch_Up_Value
(N
, Typ
);
1931 Debug_A_Exit
("resolving ", N
, " (done, resolution failed)");
1932 Set_Is_Overloaded
(N
, False);
1934 -- The caller will return without calling the expander, so we need
1935 -- to set the analyzed flag. Note that it is fine to set Analyzed
1936 -- to True even if we are in the middle of a shallow analysis,
1937 -- (see the spec of sem for more details) since this is an error
1938 -- situation anyway, and there is no point in repeating the
1939 -- analysis later (indeed it won't work to repeat it later, since
1940 -- we haven't got a clear resolution of which entity is being
1943 Set_Analyzed
(N
, True);
1945 end Resolution_Failed
;
1947 -- Start of processing for Resolve
1954 -- Access attribute on remote subprogram cannot be used for a non-remote
1955 -- access-to-subprogram type.
1957 if Nkind
(N
) = N_Attribute_Reference
1958 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
1959 Name_Unrestricted_Access
,
1960 Name_Unchecked_Access
)
1961 and then Comes_From_Source
(N
)
1962 and then Is_Entity_Name
(Prefix
(N
))
1963 and then Is_Subprogram
(Entity
(Prefix
(N
)))
1964 and then Is_Remote_Call_Interface
(Entity
(Prefix
(N
)))
1965 and then not Is_Remote_Access_To_Subprogram_Type
(Typ
)
1968 ("prefix must statically denote a non-remote subprogram", N
);
1971 From_Lib
:= Comes_From_Predefined_Lib_Unit
(N
);
1973 -- If the context is a Remote_Access_To_Subprogram, access attributes
1974 -- must be resolved with the corresponding fat pointer. There is no need
1975 -- to check for the attribute name since the return type of an
1976 -- attribute is never a remote type.
1978 if Nkind
(N
) = N_Attribute_Reference
1979 and then Comes_From_Source
(N
)
1980 and then (Is_Remote_Call_Interface
(Typ
) or else Is_Remote_Types
(Typ
))
1983 Attr
: constant Attribute_Id
:=
1984 Get_Attribute_Id
(Attribute_Name
(N
));
1985 Pref
: constant Node_Id
:= Prefix
(N
);
1988 Is_Remote
: Boolean := True;
1991 -- Check that Typ is a remote access-to-subprogram type
1993 if Is_Remote_Access_To_Subprogram_Type
(Typ
) then
1995 -- Prefix (N) must statically denote a remote subprogram
1996 -- declared in a package specification.
1998 if Attr
= Attribute_Access
or else
1999 Attr
= Attribute_Unchecked_Access
or else
2000 Attr
= Attribute_Unrestricted_Access
2002 Decl
:= Unit_Declaration_Node
(Entity
(Pref
));
2004 if Nkind
(Decl
) = N_Subprogram_Body
then
2005 Spec
:= Corresponding_Spec
(Decl
);
2007 if Present
(Spec
) then
2008 Decl
:= Unit_Declaration_Node
(Spec
);
2012 Spec
:= Parent
(Decl
);
2014 if not Is_Entity_Name
(Prefix
(N
))
2015 or else Nkind
(Spec
) /= N_Package_Specification
2017 not Is_Remote_Call_Interface
(Defining_Entity
(Spec
))
2021 ("prefix must statically denote a remote subprogram ",
2025 -- If we are generating code in distributed mode, perform
2026 -- semantic checks against corresponding remote entities.
2029 and then Get_PCS_Name
/= Name_No_DSA
2031 Check_Subtype_Conformant
2032 (New_Id
=> Entity
(Prefix
(N
)),
2033 Old_Id
=> Designated_Type
2034 (Corresponding_Remote_Type
(Typ
)),
2038 Process_Remote_AST_Attribute
(N
, Typ
);
2046 Debug_A_Entry
("resolving ", N
);
2048 if Debug_Flag_V
then
2049 Write_Overloads
(N
);
2052 if Comes_From_Source
(N
) then
2053 if Is_Fixed_Point_Type
(Typ
) then
2054 Check_Restriction
(No_Fixed_Point
, N
);
2056 elsif Is_Floating_Point_Type
(Typ
)
2057 and then Typ
/= Universal_Real
2058 and then Typ
/= Any_Real
2060 Check_Restriction
(No_Floating_Point
, N
);
2064 -- Return if already analyzed
2066 if Analyzed
(N
) then
2067 Debug_A_Exit
("resolving ", N
, " (done, already analyzed)");
2068 Analyze_Dimension
(N
);
2071 -- Any case of Any_Type as the Etype value means that we had a
2074 elsif Etype
(N
) = Any_Type
then
2075 Debug_A_Exit
("resolving ", N
, " (done, Etype = Any_Type)");
2079 Check_Parameterless_Call
(N
);
2081 -- The resolution of an Expression_With_Actions is determined by
2084 if Nkind
(N
) = N_Expression_With_Actions
then
2085 Resolve
(Expression
(N
), Typ
);
2088 Expr_Type
:= Etype
(Expression
(N
));
2090 -- If not overloaded, then we know the type, and all that needs doing
2091 -- is to check that this type is compatible with the context.
2093 elsif not Is_Overloaded
(N
) then
2094 Found
:= Covers
(Typ
, Etype
(N
));
2095 Expr_Type
:= Etype
(N
);
2097 -- In the overloaded case, we must select the interpretation that
2098 -- is compatible with the context (i.e. the type passed to Resolve)
2101 -- Loop through possible interpretations
2103 Get_First_Interp
(N
, I
, It
);
2104 Interp_Loop
: while Present
(It
.Typ
) loop
2106 if Debug_Flag_V
then
2107 Write_Str
("Interp: ");
2111 -- We are only interested in interpretations that are compatible
2112 -- with the expected type, any other interpretations are ignored.
2114 if not Covers
(Typ
, It
.Typ
) then
2115 if Debug_Flag_V
then
2116 Write_Str
(" interpretation incompatible with context");
2121 -- Skip the current interpretation if it is disabled by an
2122 -- abstract operator. This action is performed only when the
2123 -- type against which we are resolving is the same as the
2124 -- type of the interpretation.
2126 if Ada_Version
>= Ada_2005
2127 and then It
.Typ
= Typ
2128 and then Typ
/= Universal_Integer
2129 and then Typ
/= Universal_Real
2130 and then Present
(It
.Abstract_Op
)
2132 if Debug_Flag_V
then
2133 Write_Line
("Skip.");
2139 -- First matching interpretation
2145 Expr_Type
:= It
.Typ
;
2147 -- Matching interpretation that is not the first, maybe an
2148 -- error, but there are some cases where preference rules are
2149 -- used to choose between the two possibilities. These and
2150 -- some more obscure cases are handled in Disambiguate.
2153 -- If the current statement is part of a predefined library
2154 -- unit, then all interpretations which come from user level
2155 -- packages should not be considered. Check previous and
2159 if not Comes_From_Predefined_Lib_Unit
(It
.Nam
) then
2162 elsif not Comes_From_Predefined_Lib_Unit
(Seen
) then
2164 -- Previous interpretation must be discarded
2168 Expr_Type
:= It
.Typ
;
2169 Set_Entity
(N
, Seen
);
2174 -- Otherwise apply further disambiguation steps
2176 Error_Msg_Sloc
:= Sloc
(Seen
);
2177 It1
:= Disambiguate
(N
, I1
, I
, Typ
);
2179 -- Disambiguation has succeeded. Skip the remaining
2182 if It1
/= No_Interp
then
2184 Expr_Type
:= It1
.Typ
;
2186 while Present
(It
.Typ
) loop
2187 Get_Next_Interp
(I
, It
);
2191 -- Before we issue an ambiguity complaint, check for
2192 -- the case of a subprogram call where at least one
2193 -- of the arguments is Any_Type, and if so, suppress
2194 -- the message, since it is a cascaded error.
2196 if Nkind
(N
) in N_Subprogram_Call
then
2202 A
:= First_Actual
(N
);
2203 while Present
(A
) loop
2206 if Nkind
(E
) = N_Parameter_Association
then
2207 E
:= Explicit_Actual_Parameter
(E
);
2210 if Etype
(E
) = Any_Type
then
2211 if Debug_Flag_V
then
2212 Write_Str
("Any_Type in call");
2223 elsif Nkind
(N
) in N_Binary_Op
2224 and then (Etype
(Left_Opnd
(N
)) = Any_Type
2225 or else Etype
(Right_Opnd
(N
)) = Any_Type
)
2229 elsif Nkind
(N
) in N_Unary_Op
2230 and then Etype
(Right_Opnd
(N
)) = Any_Type
2235 -- Not that special case, so issue message using the
2236 -- flag Ambiguous to control printing of the header
2237 -- message only at the start of an ambiguous set.
2239 if not Ambiguous
then
2240 if Nkind
(N
) = N_Function_Call
2241 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2244 ("ambiguous expression "
2245 & "(cannot resolve indirect call)!", N
);
2247 Error_Msg_NE
-- CODEFIX
2248 ("ambiguous expression (cannot resolve&)!",
2254 if Nkind
(Parent
(Seen
)) = N_Full_Type_Declaration
then
2256 ("\\possible interpretation (inherited)#!", N
);
2258 Error_Msg_N
-- CODEFIX
2259 ("\\possible interpretation#!", N
);
2262 if Nkind
(N
) in N_Subprogram_Call
2263 and then Present
(Parameter_Associations
(N
))
2265 Report_Ambiguous_Argument
;
2269 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2271 -- By default, the error message refers to the candidate
2272 -- interpretation. But if it is a predefined operator, it
2273 -- is implicitly declared at the declaration of the type
2274 -- of the operand. Recover the sloc of that declaration
2275 -- for the error message.
2277 if Nkind
(N
) in N_Op
2278 and then Scope
(It
.Nam
) = Standard_Standard
2279 and then not Is_Overloaded
(Right_Opnd
(N
))
2280 and then Scope
(Base_Type
(Etype
(Right_Opnd
(N
)))) /=
2283 Err_Type
:= First_Subtype
(Etype
(Right_Opnd
(N
)));
2285 if Comes_From_Source
(Err_Type
)
2286 and then Present
(Parent
(Err_Type
))
2288 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2291 elsif Nkind
(N
) in N_Binary_Op
2292 and then Scope
(It
.Nam
) = Standard_Standard
2293 and then not Is_Overloaded
(Left_Opnd
(N
))
2294 and then Scope
(Base_Type
(Etype
(Left_Opnd
(N
)))) /=
2297 Err_Type
:= First_Subtype
(Etype
(Left_Opnd
(N
)));
2299 if Comes_From_Source
(Err_Type
)
2300 and then Present
(Parent
(Err_Type
))
2302 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2305 -- If this is an indirect call, use the subprogram_type
2306 -- in the message, to have a meaningful location. Also
2307 -- indicate if this is an inherited operation, created
2308 -- by a type declaration.
2310 elsif Nkind
(N
) = N_Function_Call
2311 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2312 and then Is_Type
(It
.Nam
)
2316 Sloc
(Associated_Node_For_Itype
(Err_Type
));
2321 if Nkind
(N
) in N_Op
2322 and then Scope
(It
.Nam
) = Standard_Standard
2323 and then Present
(Err_Type
)
2325 -- Special-case the message for universal_fixed
2326 -- operators, which are not declared with the type
2327 -- of the operand, but appear forever in Standard.
2329 if It
.Typ
= Universal_Fixed
2330 and then Scope
(It
.Nam
) = Standard_Standard
2333 ("\\possible interpretation as universal_fixed "
2334 & "operation (RM 4.5.5 (19))", N
);
2337 ("\\possible interpretation (predefined)#!", N
);
2341 Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
2344 ("\\possible interpretation (inherited)#!", N
);
2346 Error_Msg_N
-- CODEFIX
2347 ("\\possible interpretation#!", N
);
2353 -- We have a matching interpretation, Expr_Type is the type
2354 -- from this interpretation, and Seen is the entity.
2356 -- For an operator, just set the entity name. The type will be
2357 -- set by the specific operator resolution routine.
2359 if Nkind
(N
) in N_Op
then
2360 Set_Entity
(N
, Seen
);
2361 Generate_Reference
(Seen
, N
);
2363 elsif Nkind
(N
) = N_Case_Expression
then
2364 Set_Etype
(N
, Expr_Type
);
2366 elsif Nkind
(N
) = N_Character_Literal
then
2367 Set_Etype
(N
, Expr_Type
);
2369 elsif Nkind
(N
) = N_If_Expression
then
2370 Set_Etype
(N
, Expr_Type
);
2372 -- AI05-0139-2: Expression is overloaded because type has
2373 -- implicit dereference. If type matches context, no implicit
2374 -- dereference is involved.
2376 elsif Has_Implicit_Dereference
(Expr_Type
) then
2377 Set_Etype
(N
, Expr_Type
);
2378 Set_Is_Overloaded
(N
, False);
2381 elsif Is_Overloaded
(N
)
2382 and then Present
(It
.Nam
)
2383 and then Ekind
(It
.Nam
) = E_Discriminant
2384 and then Has_Implicit_Dereference
(It
.Nam
)
2386 -- If the node is a general indexing, the dereference is
2387 -- is inserted when resolving the rewritten form, else
2390 if Nkind
(N
) /= N_Indexed_Component
2391 or else No
(Generalized_Indexing
(N
))
2393 Build_Explicit_Dereference
(N
, It
.Nam
);
2396 -- For an explicit dereference, attribute reference, range,
2397 -- short-circuit form (which is not an operator node), or call
2398 -- with a name that is an explicit dereference, there is
2399 -- nothing to be done at this point.
2401 elsif Nkind_In
(N
, N_Explicit_Dereference
,
2402 N_Attribute_Reference
,
2404 N_Indexed_Component
,
2407 N_Selected_Component
,
2409 or else Nkind
(Name
(N
)) = N_Explicit_Dereference
2413 -- For procedure or function calls, set the type of the name,
2414 -- and also the entity pointer for the prefix.
2416 elsif Nkind
(N
) in N_Subprogram_Call
2417 and then Is_Entity_Name
(Name
(N
))
2419 Set_Etype
(Name
(N
), Expr_Type
);
2420 Set_Entity
(Name
(N
), Seen
);
2421 Generate_Reference
(Seen
, Name
(N
));
2423 elsif Nkind
(N
) = N_Function_Call
2424 and then Nkind
(Name
(N
)) = N_Selected_Component
2426 Set_Etype
(Name
(N
), Expr_Type
);
2427 Set_Entity
(Selector_Name
(Name
(N
)), Seen
);
2428 Generate_Reference
(Seen
, Selector_Name
(Name
(N
)));
2430 -- For all other cases, just set the type of the Name
2433 Set_Etype
(Name
(N
), Expr_Type
);
2440 -- Move to next interpretation
2442 exit Interp_Loop
when No
(It
.Typ
);
2444 Get_Next_Interp
(I
, It
);
2445 end loop Interp_Loop
;
2448 -- At this stage Found indicates whether or not an acceptable
2449 -- interpretation exists. If not, then we have an error, except that if
2450 -- the context is Any_Type as a result of some other error, then we
2451 -- suppress the error report.
2454 if Typ
/= Any_Type
then
2456 -- If type we are looking for is Void, then this is the procedure
2457 -- call case, and the error is simply that what we gave is not a
2458 -- procedure name (we think of procedure calls as expressions with
2459 -- types internally, but the user doesn't think of them this way).
2461 if Typ
= Standard_Void_Type
then
2463 -- Special case message if function used as a procedure
2465 if Nkind
(N
) = N_Procedure_Call_Statement
2466 and then Is_Entity_Name
(Name
(N
))
2467 and then Ekind
(Entity
(Name
(N
))) = E_Function
2470 ("cannot use function & in a procedure call",
2471 Name
(N
), Entity
(Name
(N
)));
2473 -- Otherwise give general message (not clear what cases this
2474 -- covers, but no harm in providing for them).
2477 Error_Msg_N
("expect procedure name in procedure call", N
);
2482 -- Otherwise we do have a subexpression with the wrong type
2484 -- Check for the case of an allocator which uses an access type
2485 -- instead of the designated type. This is a common error and we
2486 -- specialize the message, posting an error on the operand of the
2487 -- allocator, complaining that we expected the designated type of
2490 elsif Nkind
(N
) = N_Allocator
2491 and then Is_Access_Type
(Typ
)
2492 and then Is_Access_Type
(Etype
(N
))
2493 and then Designated_Type
(Etype
(N
)) = Typ
2495 Wrong_Type
(Expression
(N
), Designated_Type
(Typ
));
2498 -- Check for view mismatch on Null in instances, for which the
2499 -- view-swapping mechanism has no identifier.
2501 elsif (In_Instance
or else In_Inlined_Body
)
2502 and then (Nkind
(N
) = N_Null
)
2503 and then Is_Private_Type
(Typ
)
2504 and then Is_Access_Type
(Full_View
(Typ
))
2506 Resolve
(N
, Full_View
(Typ
));
2510 -- Check for an aggregate. Sometimes we can get bogus aggregates
2511 -- from misuse of parentheses, and we are about to complain about
2512 -- the aggregate without even looking inside it.
2514 -- Instead, if we have an aggregate of type Any_Composite, then
2515 -- analyze and resolve the component fields, and then only issue
2516 -- another message if we get no errors doing this (otherwise
2517 -- assume that the errors in the aggregate caused the problem).
2519 elsif Nkind
(N
) = N_Aggregate
2520 and then Etype
(N
) = Any_Composite
2522 -- Disable expansion in any case. If there is a type mismatch
2523 -- it may be fatal to try to expand the aggregate. The flag
2524 -- would otherwise be set to false when the error is posted.
2526 Expander_Active
:= False;
2529 procedure Check_Aggr
(Aggr
: Node_Id
);
2530 -- Check one aggregate, and set Found to True if we have a
2531 -- definite error in any of its elements
2533 procedure Check_Elmt
(Aelmt
: Node_Id
);
2534 -- Check one element of aggregate and set Found to True if
2535 -- we definitely have an error in the element.
2541 procedure Check_Aggr
(Aggr
: Node_Id
) is
2545 if Present
(Expressions
(Aggr
)) then
2546 Elmt
:= First
(Expressions
(Aggr
));
2547 while Present
(Elmt
) loop
2553 if Present
(Component_Associations
(Aggr
)) then
2554 Elmt
:= First
(Component_Associations
(Aggr
));
2555 while Present
(Elmt
) loop
2557 -- If this is a default-initialized component, then
2558 -- there is nothing to check. The box will be
2559 -- replaced by the appropriate call during late
2562 if not Box_Present
(Elmt
) then
2563 Check_Elmt
(Expression
(Elmt
));
2575 procedure Check_Elmt
(Aelmt
: Node_Id
) is
2577 -- If we have a nested aggregate, go inside it (to
2578 -- attempt a naked analyze-resolve of the aggregate can
2579 -- cause undesirable cascaded errors). Do not resolve
2580 -- expression if it needs a type from context, as for
2581 -- integer * fixed expression.
2583 if Nkind
(Aelmt
) = N_Aggregate
then
2589 if not Is_Overloaded
(Aelmt
)
2590 and then Etype
(Aelmt
) /= Any_Fixed
2595 if Etype
(Aelmt
) = Any_Type
then
2606 -- Looks like we have a type error, but check for special case
2607 -- of Address wanted, integer found, with the configuration pragma
2608 -- Allow_Integer_Address active. If we have this case, introduce
2609 -- an unchecked conversion to allow the integer expression to be
2610 -- treated as an Address. The reverse case of integer wanted,
2611 -- Address found, is treated in an analogous manner.
2613 if Address_Integer_Convert_OK
(Typ
, Etype
(N
)) then
2614 Rewrite
(N
, Unchecked_Convert_To
(Typ
, Relocate_Node
(N
)));
2615 Analyze_And_Resolve
(N
, Typ
);
2619 -- That special Allow_Integer_Address check did not appply, so we
2620 -- have a real type error. If an error message was issued already,
2621 -- Found got reset to True, so if it's still False, issue standard
2622 -- Wrong_Type message.
2625 if Is_Overloaded
(N
) and then Nkind
(N
) = N_Function_Call
then
2627 Subp_Name
: Node_Id
;
2630 if Is_Entity_Name
(Name
(N
)) then
2631 Subp_Name
:= Name
(N
);
2633 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2635 -- Protected operation: retrieve operation name
2637 Subp_Name
:= Selector_Name
(Name
(N
));
2640 raise Program_Error
;
2643 Error_Msg_Node_2
:= Typ
;
2645 ("no visible interpretation of& "
2646 & "matches expected type&", N
, Subp_Name
);
2649 if All_Errors_Mode
then
2651 Index
: Interp_Index
;
2655 Error_Msg_N
("\\possible interpretations:", N
);
2657 Get_First_Interp
(Name
(N
), Index
, It
);
2658 while Present
(It
.Nam
) loop
2659 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2660 Error_Msg_Node_2
:= It
.Nam
;
2662 ("\\ type& for & declared#", N
, It
.Typ
);
2663 Get_Next_Interp
(Index
, It
);
2668 Error_Msg_N
("\use -gnatf for details", N
);
2672 Wrong_Type
(N
, Typ
);
2680 -- Test if we have more than one interpretation for the context
2682 elsif Ambiguous
then
2686 -- Only one intepretation
2689 -- In Ada 2005, if we have something like "X : T := 2 + 2;", where
2690 -- the "+" on T is abstract, and the operands are of universal type,
2691 -- the above code will have (incorrectly) resolved the "+" to the
2692 -- universal one in Standard. Therefore check for this case and give
2693 -- an error. We can't do this earlier, because it would cause legal
2694 -- cases to get errors (when some other type has an abstract "+").
2696 if Ada_Version
>= Ada_2005
2697 and then Nkind
(N
) in N_Op
2698 and then Is_Overloaded
(N
)
2699 and then Is_Universal_Numeric_Type
(Etype
(Entity
(N
)))
2701 Get_First_Interp
(N
, I
, It
);
2702 while Present
(It
.Typ
) loop
2703 if Present
(It
.Abstract_Op
) and then
2704 Etype
(It
.Abstract_Op
) = Typ
2707 ("cannot call abstract subprogram &!", N
, It
.Abstract_Op
);
2711 Get_Next_Interp
(I
, It
);
2715 -- Here we have an acceptable interpretation for the context
2717 -- Propagate type information and normalize tree for various
2718 -- predefined operations. If the context only imposes a class of
2719 -- types, rather than a specific type, propagate the actual type
2722 if Typ
= Any_Integer
or else
2723 Typ
= Any_Boolean
or else
2724 Typ
= Any_Modular
or else
2725 Typ
= Any_Real
or else
2728 Ctx_Type
:= Expr_Type
;
2730 -- Any_Fixed is legal in a real context only if a specific fixed-
2731 -- point type is imposed. If Norman Cohen can be confused by this,
2732 -- it deserves a separate message.
2735 and then Expr_Type
= Any_Fixed
2737 Error_Msg_N
("illegal context for mixed mode operation", N
);
2738 Set_Etype
(N
, Universal_Real
);
2739 Ctx_Type
:= Universal_Real
;
2743 -- A user-defined operator is transformed into a function call at
2744 -- this point, so that further processing knows that operators are
2745 -- really operators (i.e. are predefined operators). User-defined
2746 -- operators that are intrinsic are just renamings of the predefined
2747 -- ones, and need not be turned into calls either, but if they rename
2748 -- a different operator, we must transform the node accordingly.
2749 -- Instantiations of Unchecked_Conversion are intrinsic but are
2750 -- treated as functions, even if given an operator designator.
2752 if Nkind
(N
) in N_Op
2753 and then Present
(Entity
(N
))
2754 and then Ekind
(Entity
(N
)) /= E_Operator
2757 if not Is_Predefined_Op
(Entity
(N
)) then
2758 Rewrite_Operator_As_Call
(N
, Entity
(N
));
2760 elsif Present
(Alias
(Entity
(N
)))
2762 Nkind
(Parent
(Parent
(Entity
(N
)))) =
2763 N_Subprogram_Renaming_Declaration
2765 Rewrite_Renamed_Operator
(N
, Alias
(Entity
(N
)), Typ
);
2767 -- If the node is rewritten, it will be fully resolved in
2768 -- Rewrite_Renamed_Operator.
2770 if Analyzed
(N
) then
2776 case N_Subexpr
'(Nkind (N)) is
2778 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2780 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2782 when N_Short_Circuit
2783 => Resolve_Short_Circuit (N, Ctx_Type);
2785 when N_Attribute_Reference
2786 => Resolve_Attribute (N, Ctx_Type);
2788 when N_Case_Expression
2789 => Resolve_Case_Expression (N, Ctx_Type);
2791 when N_Character_Literal
2792 => Resolve_Character_Literal (N, Ctx_Type);
2794 when N_Expanded_Name
2795 => Resolve_Entity_Name (N, Ctx_Type);
2797 when N_Explicit_Dereference
2798 => Resolve_Explicit_Dereference (N, Ctx_Type);
2800 when N_Expression_With_Actions
2801 => Resolve_Expression_With_Actions (N, Ctx_Type);
2803 when N_Extension_Aggregate
2804 => Resolve_Extension_Aggregate (N, Ctx_Type);
2806 when N_Function_Call
2807 => Resolve_Call (N, Ctx_Type);
2810 => Resolve_Entity_Name (N, Ctx_Type);
2812 when N_If_Expression
2813 => Resolve_If_Expression (N, Ctx_Type);
2815 when N_Indexed_Component
2816 => Resolve_Indexed_Component (N, Ctx_Type);
2818 when N_Integer_Literal
2819 => Resolve_Integer_Literal (N, Ctx_Type);
2821 when N_Membership_Test
2822 => Resolve_Membership_Op (N, Ctx_Type);
2824 when N_Null => Resolve_Null (N, Ctx_Type);
2826 when N_Op_And | N_Op_Or | N_Op_Xor
2827 => Resolve_Logical_Op (N, Ctx_Type);
2829 when N_Op_Eq | N_Op_Ne
2830 => Resolve_Equality_Op (N, Ctx_Type);
2832 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2833 => Resolve_Comparison_Op (N, Ctx_Type);
2835 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2837 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2838 N_Op_Divide | N_Op_Mod | N_Op_Rem
2840 => Resolve_Arithmetic_Op (N, Ctx_Type);
2842 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2844 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2846 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2847 => Resolve_Unary_Op (N, Ctx_Type);
2849 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2851 when N_Procedure_Call_Statement
2852 => Resolve_Call (N, Ctx_Type);
2854 when N_Operator_Symbol
2855 => Resolve_Operator_Symbol (N, Ctx_Type);
2857 when N_Qualified_Expression
2858 => Resolve_Qualified_Expression (N, Ctx_Type);
2860 -- Why is the following null, needs a comment ???
2862 when N_Quantified_Expression
2865 when N_Raise_Expression
2866 => Resolve_Raise_Expression (N, Ctx_Type);
2868 when N_Raise_xxx_Error
2869 => Set_Etype (N, Ctx_Type);
2871 when N_Range => Resolve_Range (N, Ctx_Type);
2874 => Resolve_Real_Literal (N, Ctx_Type);
2876 when N_Reference => Resolve_Reference (N, Ctx_Type);
2878 when N_Selected_Component
2879 => Resolve_Selected_Component (N, Ctx_Type);
2881 when N_Slice => Resolve_Slice (N, Ctx_Type);
2883 when N_String_Literal
2884 => Resolve_String_Literal (N, Ctx_Type);
2886 when N_Type_Conversion
2887 => Resolve_Type_Conversion (N, Ctx_Type);
2889 when N_Unchecked_Expression =>
2890 Resolve_Unchecked_Expression (N, Ctx_Type);
2892 when N_Unchecked_Type_Conversion =>
2893 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2896 -- Ada 2012 (AI05-0149): Apply an (implicit) conversion to an
2897 -- expression of an anonymous access type that occurs in the context
2898 -- of a named general access type, except when the expression is that
2899 -- of a membership test. This ensures proper legality checking in
2900 -- terms of allowed conversions (expressions that would be illegal to
2901 -- convert implicitly are allowed in membership tests).
2903 if Ada_Version >= Ada_2012
2904 and then Ekind (Ctx_Type) = E_General_Access_Type
2905 and then Ekind (Etype (N)) = E_Anonymous_Access_Type
2906 and then Nkind (Parent (N)) not in N_Membership_Test
2908 Rewrite (N, Convert_To (Ctx_Type, Relocate_Node (N)));
2909 Analyze_And_Resolve (N, Ctx_Type);
2912 -- If the subexpression was replaced by a non-subexpression, then
2913 -- all we do is to expand it. The only legitimate case we know of
2914 -- is converting procedure call statement to entry call statements,
2915 -- but there may be others, so we are making this test general.
2917 if Nkind (N) not in N_Subexpr then
2918 Debug_A_Exit ("resolving ", N, " (done)");
2923 -- The expression is definitely NOT overloaded at this point, so
2924 -- we reset the Is_Overloaded flag to avoid any confusion when
2925 -- reanalyzing the node.
2927 Set_Is_Overloaded (N, False);
2929 -- Freeze expression type, entity if it is a name, and designated
2930 -- type if it is an allocator (RM 13.14(10,11,13)).
2932 -- Now that the resolution of the type of the node is complete, and
2933 -- we did not detect an error, we can expand this node. We skip the
2934 -- expand call if we are in a default expression, see section
2935 -- "Handling of Default Expressions" in Sem spec.
2937 Debug_A_Exit ("resolving ", N, " (done)");
2939 -- We unconditionally freeze the expression, even if we are in
2940 -- default expression mode (the Freeze_Expression routine tests this
2941 -- flag and only freezes static types if it is set).
2943 -- Ada 2012 (AI05-177): The declaration of an expression function
2944 -- does not cause freezing, but we never reach here in that case.
2945 -- Here we are resolving the corresponding expanded body, so we do
2946 -- need to perform normal freezing.
2948 Freeze_Expression (N);
2950 -- Now we can do the expansion
2960 -- Version with check(s) suppressed
2962 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2964 if Suppress = All_Checks then
2966 Sva : constant Suppress_Array := Scope_Suppress.Suppress;
2968 Scope_Suppress.Suppress := (others => True);
2970 Scope_Suppress.Suppress := Sva;
2975 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
2977 Scope_Suppress.Suppress (Suppress) := True;
2979 Scope_Suppress.Suppress (Suppress) := Svg;
2988 -- Version with implicit type
2990 procedure Resolve (N : Node_Id) is
2992 Resolve (N, Etype (N));
2995 ---------------------
2996 -- Resolve_Actuals --
2997 ---------------------
2999 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
3000 Loc : constant Source_Ptr := Sloc (N);
3006 Prev : Node_Id := Empty;
3009 procedure Check_Aliased_Parameter;
3010 -- Check rules on aliased parameters and related accessibility rules
3011 -- in (RM 3.10.2 (10.2-10.4)).
3013 procedure Check_Argument_Order;
3014 -- Performs a check for the case where the actuals are all simple
3015 -- identifiers that correspond to the formal names, but in the wrong
3016 -- order, which is considered suspicious and cause for a warning.
3018 procedure Check_Prefixed_Call;
3019 -- If the original node is an overloaded call in prefix notation,
3020 -- insert an 'Access or a dereference as needed over the first actual
.
3021 -- Try_Object_Operation has already verified that there is a valid
3022 -- interpretation, but the form of the actual can only be determined
3023 -- once the primitive operation is identified.
3025 procedure Insert_Default
;
3026 -- If the actual is missing in a call, insert in the actuals list
3027 -- an instance of the default expression. The insertion is always
3028 -- a named association.
3030 procedure Property_Error
3033 Prop_Nam
: Name_Id
);
3034 -- Emit an error concerning variable Var with entity Var_Id that has
3035 -- enabled property Prop_Nam when it acts as an actual parameter in a
3036 -- call and the corresponding formal parameter is of mode IN.
3038 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean;
3039 -- Check whether T1 and T2, or their full views, are derived from a
3040 -- common type. Used to enforce the restrictions on array conversions
3043 function Static_Concatenation
(N
: Node_Id
) return Boolean;
3044 -- Predicate to determine whether an actual that is a concatenation
3045 -- will be evaluated statically and does not need a transient scope.
3046 -- This must be determined before the actual is resolved and expanded
3047 -- because if needed the transient scope must be introduced earlier.
3049 ------------------------------
3050 -- Check_Aliased_Parameter --
3051 ------------------------------
3053 procedure Check_Aliased_Parameter
is
3054 Nominal_Subt
: Entity_Id
;
3057 if Is_Aliased
(F
) then
3058 if Is_Tagged_Type
(A_Typ
) then
3061 elsif Is_Aliased_View
(A
) then
3062 if Is_Constr_Subt_For_U_Nominal
(A_Typ
) then
3063 Nominal_Subt
:= Base_Type
(A_Typ
);
3065 Nominal_Subt
:= A_Typ
;
3068 if Subtypes_Statically_Match
(F_Typ
, Nominal_Subt
) then
3071 -- In a generic body assume the worst for generic formals:
3072 -- they can have a constrained partial view (AI05-041).
3074 elsif Has_Discriminants
(F_Typ
)
3075 and then not Is_Constrained
(F_Typ
)
3076 and then not Has_Constrained_Partial_View
(F_Typ
)
3077 and then not Is_Generic_Type
(F_Typ
)
3082 Error_Msg_NE
("untagged actual does not match "
3083 & "aliased formal&", A
, F
);
3087 Error_Msg_NE
("actual for aliased formal& must be "
3088 & "aliased object", A
, F
);
3091 if Ekind
(Nam
) = E_Procedure
then
3094 elsif Ekind
(Etype
(Nam
)) = E_Anonymous_Access_Type
then
3095 if Nkind
(Parent
(N
)) = N_Type_Conversion
3096 and then Type_Access_Level
(Etype
(Parent
(N
))) <
3097 Object_Access_Level
(A
)
3099 Error_Msg_N
("aliased actual has wrong accessibility", A
);
3102 elsif Nkind
(Parent
(N
)) = N_Qualified_Expression
3103 and then Nkind
(Parent
(Parent
(N
))) = N_Allocator
3104 and then Type_Access_Level
(Etype
(Parent
(Parent
(N
)))) <
3105 Object_Access_Level
(A
)
3108 ("aliased actual in allocator has wrong accessibility", A
);
3111 end Check_Aliased_Parameter
;
3113 --------------------------
3114 -- Check_Argument_Order --
3115 --------------------------
3117 procedure Check_Argument_Order
is
3119 -- Nothing to do if no parameters, or original node is neither a
3120 -- function call nor a procedure call statement (happens in the
3121 -- operator-transformed-to-function call case), or the call does
3122 -- not come from source, or this warning is off.
3124 if not Warn_On_Parameter_Order
3125 or else No
(Parameter_Associations
(N
))
3126 or else Nkind
(Original_Node
(N
)) not in N_Subprogram_Call
3127 or else not Comes_From_Source
(N
)
3133 Nargs
: constant Nat
:= List_Length
(Parameter_Associations
(N
));
3136 -- Nothing to do if only one parameter
3142 -- Here if at least two arguments
3145 Actuals
: array (1 .. Nargs
) of Node_Id
;
3149 Wrong_Order
: Boolean := False;
3150 -- Set True if an out of order case is found
3153 -- Collect identifier names of actuals, fail if any actual is
3154 -- not a simple identifier, and record max length of name.
3156 Actual
:= First
(Parameter_Associations
(N
));
3157 for J
in Actuals
'Range loop
3158 if Nkind
(Actual
) /= N_Identifier
then
3161 Actuals
(J
) := Actual
;
3166 -- If we got this far, all actuals are identifiers and the list
3167 -- of their names is stored in the Actuals array.
3169 Formal
:= First_Formal
(Nam
);
3170 for J
in Actuals
'Range loop
3172 -- If we ran out of formals, that's odd, probably an error
3173 -- which will be detected elsewhere, but abandon the search.
3179 -- If name matches and is in order OK
3181 if Chars
(Formal
) = Chars
(Actuals
(J
)) then
3185 -- If no match, see if it is elsewhere in list and if so
3186 -- flag potential wrong order if type is compatible.
3188 for K
in Actuals
'Range loop
3189 if Chars
(Formal
) = Chars
(Actuals
(K
))
3191 Has_Compatible_Type
(Actuals
(K
), Etype
(Formal
))
3193 Wrong_Order
:= True;
3203 <<Continue
>> Next_Formal
(Formal
);
3206 -- If Formals left over, also probably an error, skip warning
3208 if Present
(Formal
) then
3212 -- Here we give the warning if something was out of order
3216 ("?P?actuals for this call may be in wrong order", N
);
3220 end Check_Argument_Order
;
3222 -------------------------
3223 -- Check_Prefixed_Call --
3224 -------------------------
3226 procedure Check_Prefixed_Call
is
3227 Act
: constant Node_Id
:= First_Actual
(N
);
3228 A_Type
: constant Entity_Id
:= Etype
(Act
);
3229 F_Type
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
3230 Orig
: constant Node_Id
:= Original_Node
(N
);
3234 -- Check whether the call is a prefixed call, with or without
3235 -- additional actuals.
3237 if Nkind
(Orig
) = N_Selected_Component
3239 (Nkind
(Orig
) = N_Indexed_Component
3240 and then Nkind
(Prefix
(Orig
)) = N_Selected_Component
3241 and then Is_Entity_Name
(Prefix
(Prefix
(Orig
)))
3242 and then Is_Entity_Name
(Act
)
3243 and then Chars
(Act
) = Chars
(Prefix
(Prefix
(Orig
))))
3245 if Is_Access_Type
(A_Type
)
3246 and then not Is_Access_Type
(F_Type
)
3248 -- Introduce dereference on object in prefix
3251 Make_Explicit_Dereference
(Sloc
(Act
),
3252 Prefix
=> Relocate_Node
(Act
));
3253 Rewrite
(Act
, New_A
);
3256 elsif Is_Access_Type
(F_Type
)
3257 and then not Is_Access_Type
(A_Type
)
3259 -- Introduce an implicit 'Access in prefix
3261 if not Is_Aliased_View
(Act
) then
3263 ("object in prefixed call to& must be aliased "
3264 & "(RM 4.1.3 (13 1/2))",
3269 Make_Attribute_Reference
(Loc
,
3270 Attribute_Name
=> Name_Access
,
3271 Prefix
=> Relocate_Node
(Act
)));
3276 end Check_Prefixed_Call
;
3278 --------------------
3279 -- Insert_Default --
3280 --------------------
3282 procedure Insert_Default
is
3287 -- Missing argument in call, nothing to insert
3289 if No
(Default_Value
(F
)) then
3293 -- Note that we do a full New_Copy_Tree, so that any associated
3294 -- Itypes are properly copied. This may not be needed any more,
3295 -- but it does no harm as a safety measure. Defaults of a generic
3296 -- formal may be out of bounds of the corresponding actual (see
3297 -- cc1311b) and an additional check may be required.
3302 New_Scope
=> Current_Scope
,
3305 if Is_Concurrent_Type
(Scope
(Nam
))
3306 and then Has_Discriminants
(Scope
(Nam
))
3308 Replace_Actual_Discriminants
(N
, Actval
);
3311 if Is_Overloadable
(Nam
)
3312 and then Present
(Alias
(Nam
))
3314 if Base_Type
(Etype
(F
)) /= Base_Type
(Etype
(Actval
))
3315 and then not Is_Tagged_Type
(Etype
(F
))
3317 -- If default is a real literal, do not introduce a
3318 -- conversion whose effect may depend on the run-time
3319 -- size of universal real.
3321 if Nkind
(Actval
) = N_Real_Literal
then
3322 Set_Etype
(Actval
, Base_Type
(Etype
(F
)));
3324 Actval
:= Unchecked_Convert_To
(Etype
(F
), Actval
);
3328 if Is_Scalar_Type
(Etype
(F
)) then
3329 Enable_Range_Check
(Actval
);
3332 Set_Parent
(Actval
, N
);
3334 -- Resolve aggregates with their base type, to avoid scope
3335 -- anomalies: the subtype was first built in the subprogram
3336 -- declaration, and the current call may be nested.
3338 if Nkind
(Actval
) = N_Aggregate
then
3339 Analyze_And_Resolve
(Actval
, Etype
(F
));
3341 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3345 Set_Parent
(Actval
, N
);
3347 -- See note above concerning aggregates
3349 if Nkind
(Actval
) = N_Aggregate
3350 and then Has_Discriminants
(Etype
(Actval
))
3352 Analyze_And_Resolve
(Actval
, Base_Type
(Etype
(Actval
)));
3354 -- Resolve entities with their own type, which may differ from
3355 -- the type of a reference in a generic context (the view
3356 -- swapping mechanism did not anticipate the re-analysis of
3357 -- default values in calls).
3359 elsif Is_Entity_Name
(Actval
) then
3360 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Actval
)));
3363 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3367 -- If default is a tag indeterminate function call, propagate tag
3368 -- to obtain proper dispatching.
3370 if Is_Controlling_Formal
(F
)
3371 and then Nkind
(Default_Value
(F
)) = N_Function_Call
3373 Set_Is_Controlling_Actual
(Actval
);
3378 -- If the default expression raises constraint error, then just
3379 -- silently replace it with an N_Raise_Constraint_Error node, since
3380 -- we already gave the warning on the subprogram spec. If node is
3381 -- already a Raise_Constraint_Error leave as is, to prevent loops in
3382 -- the warnings removal machinery.
3384 if Raises_Constraint_Error
(Actval
)
3385 and then Nkind
(Actval
) /= N_Raise_Constraint_Error
3388 Make_Raise_Constraint_Error
(Loc
,
3389 Reason
=> CE_Range_Check_Failed
));
3390 Set_Raises_Constraint_Error
(Actval
);
3391 Set_Etype
(Actval
, Etype
(F
));
3395 Make_Parameter_Association
(Loc
,
3396 Explicit_Actual_Parameter
=> Actval
,
3397 Selector_Name
=> Make_Identifier
(Loc
, Chars
(F
)));
3399 -- Case of insertion is first named actual
3401 if No
(Prev
) or else
3402 Nkind
(Parent
(Prev
)) /= N_Parameter_Association
3404 Set_Next_Named_Actual
(Assoc
, First_Named_Actual
(N
));
3405 Set_First_Named_Actual
(N
, Actval
);
3408 if No
(Parameter_Associations
(N
)) then
3409 Set_Parameter_Associations
(N
, New_List
(Assoc
));
3411 Append
(Assoc
, Parameter_Associations
(N
));
3415 Insert_After
(Prev
, Assoc
);
3418 -- Case of insertion is not first named actual
3421 Set_Next_Named_Actual
3422 (Assoc
, Next_Named_Actual
(Parent
(Prev
)));
3423 Set_Next_Named_Actual
(Parent
(Prev
), Actval
);
3424 Append
(Assoc
, Parameter_Associations
(N
));
3427 Mark_Rewrite_Insertion
(Assoc
);
3428 Mark_Rewrite_Insertion
(Actval
);
3433 --------------------
3434 -- Property_Error --
3435 --------------------
3437 procedure Property_Error
3443 Error_Msg_Name_1
:= Prop_Nam
;
3445 ("external variable & with enabled property % cannot appear as "
3446 & "actual in procedure call (SPARK RM 7.1.3(11))", Var
, Var_Id
);
3447 Error_Msg_N
("\\corresponding formal parameter has mode In", Var
);
3454 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean is
3455 FT1
: Entity_Id
:= T1
;
3456 FT2
: Entity_Id
:= T2
;
3459 if Is_Private_Type
(T1
)
3460 and then Present
(Full_View
(T1
))
3462 FT1
:= Full_View
(T1
);
3465 if Is_Private_Type
(T2
)
3466 and then Present
(Full_View
(T2
))
3468 FT2
:= Full_View
(T2
);
3471 return Root_Type
(Base_Type
(FT1
)) = Root_Type
(Base_Type
(FT2
));
3474 --------------------------
3475 -- Static_Concatenation --
3476 --------------------------
3478 function Static_Concatenation
(N
: Node_Id
) return Boolean is
3481 when N_String_Literal
=>
3486 -- Concatenation is static when both operands are static and
3487 -- the concatenation operator is a predefined one.
3489 return Scope
(Entity
(N
)) = Standard_Standard
3491 Static_Concatenation
(Left_Opnd
(N
))
3493 Static_Concatenation
(Right_Opnd
(N
));
3496 if Is_Entity_Name
(N
) then
3498 Ent
: constant Entity_Id
:= Entity
(N
);
3500 return Ekind
(Ent
) = E_Constant
3501 and then Present
(Constant_Value
(Ent
))
3503 Is_OK_Static_Expression
(Constant_Value
(Ent
));
3510 end Static_Concatenation
;
3512 -- Start of processing for Resolve_Actuals
3515 Check_Argument_Order
;
3516 Check_Function_Writable_Actuals
(N
);
3518 if Present
(First_Actual
(N
)) then
3519 Check_Prefixed_Call
;
3522 A
:= First_Actual
(N
);
3523 F
:= First_Formal
(Nam
);
3524 while Present
(F
) loop
3525 if No
(A
) and then Needs_No_Actuals
(Nam
) then
3528 -- If we have an error in any actual or formal, indicated by a type
3529 -- of Any_Type, then abandon resolution attempt, and set result type
3530 -- to Any_Type. Skip this if the actual is a Raise_Expression, whose
3531 -- type is imposed from context.
3533 elsif (Present
(A
) and then Etype
(A
) = Any_Type
)
3534 or else Etype
(F
) = Any_Type
3536 if Nkind
(A
) /= N_Raise_Expression
then
3537 Set_Etype
(N
, Any_Type
);
3542 -- Case where actual is present
3544 -- If the actual is an entity, generate a reference to it now. We
3545 -- do this before the actual is resolved, because a formal of some
3546 -- protected subprogram, or a task discriminant, will be rewritten
3547 -- during expansion, and the source entity reference may be lost.
3550 and then Is_Entity_Name
(A
)
3551 and then Comes_From_Source
(N
)
3553 Orig_A
:= Entity
(A
);
3555 if Present
(Orig_A
) then
3556 if Is_Formal
(Orig_A
)
3557 and then Ekind
(F
) /= E_In_Parameter
3559 Generate_Reference
(Orig_A
, A
, 'm');
3561 elsif not Is_Overloaded
(A
) then
3562 if Ekind
(F
) /= E_Out_Parameter
then
3563 Generate_Reference
(Orig_A
, A
);
3565 -- RM 6.4.1(12): For an out parameter that is passed by
3566 -- copy, the formal parameter object is created, and:
3568 -- * For an access type, the formal parameter is initialized
3569 -- from the value of the actual, without checking that the
3570 -- value satisfies any constraint, any predicate, or any
3571 -- exclusion of the null value.
3573 -- * For a scalar type that has the Default_Value aspect
3574 -- specified, the formal parameter is initialized from the
3575 -- value of the actual, without checking that the value
3576 -- satisfies any constraint or any predicate.
3577 -- I do not understand why this case is included??? this is
3578 -- not a case where an OUT parameter is treated as IN OUT.
3580 -- * For a composite type with discriminants or that has
3581 -- implicit initial values for any subcomponents, the
3582 -- behavior is as for an in out parameter passed by copy.
3584 -- Hence for these cases we generate the read reference now
3585 -- (the write reference will be generated later by
3586 -- Note_Possible_Modification).
3588 elsif Is_By_Copy_Type
(Etype
(F
))
3590 (Is_Access_Type
(Etype
(F
))
3592 (Is_Scalar_Type
(Etype
(F
))
3594 Present
(Default_Aspect_Value
(Etype
(F
))))
3596 (Is_Composite_Type
(Etype
(F
))
3597 and then (Has_Discriminants
(Etype
(F
))
3598 or else Is_Partially_Initialized_Type
3601 Generate_Reference
(Orig_A
, A
);
3608 and then (Nkind
(Parent
(A
)) /= N_Parameter_Association
3609 or else Chars
(Selector_Name
(Parent
(A
))) = Chars
(F
))
3611 -- If style checking mode on, check match of formal name
3614 if Nkind
(Parent
(A
)) = N_Parameter_Association
then
3615 Check_Identifier
(Selector_Name
(Parent
(A
)), F
);
3619 -- If the formal is Out or In_Out, do not resolve and expand the
3620 -- conversion, because it is subsequently expanded into explicit
3621 -- temporaries and assignments. However, the object of the
3622 -- conversion can be resolved. An exception is the case of tagged
3623 -- type conversion with a class-wide actual. In that case we want
3624 -- the tag check to occur and no temporary will be needed (no
3625 -- representation change can occur) and the parameter is passed by
3626 -- reference, so we go ahead and resolve the type conversion.
3627 -- Another exception is the case of reference to component or
3628 -- subcomponent of a bit-packed array, in which case we want to
3629 -- defer expansion to the point the in and out assignments are
3632 if Ekind
(F
) /= E_In_Parameter
3633 and then Nkind
(A
) = N_Type_Conversion
3634 and then not Is_Class_Wide_Type
(Etype
(Expression
(A
)))
3636 if Ekind
(F
) = E_In_Out_Parameter
3637 and then Is_Array_Type
(Etype
(F
))
3639 -- In a view conversion, the conversion must be legal in
3640 -- both directions, and thus both component types must be
3641 -- aliased, or neither (4.6 (8)).
3643 -- The extra rule in 4.6 (24.9.2) seems unduly restrictive:
3644 -- the privacy requirement should not apply to generic
3645 -- types, and should be checked in an instance. ARG query
3648 if Has_Aliased_Components
(Etype
(Expression
(A
))) /=
3649 Has_Aliased_Components
(Etype
(F
))
3652 ("both component types in a view conversion must be"
3653 & " aliased, or neither", A
);
3655 -- Comment here??? what set of cases???
3658 not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
3660 -- Check view conv between unrelated by ref array types
3662 if Is_By_Reference_Type
(Etype
(F
))
3663 or else Is_By_Reference_Type
(Etype
(Expression
(A
)))
3666 ("view conversion between unrelated by reference "
3667 & "array types not allowed (\'A'I-00246)", A
);
3669 -- In Ada 2005 mode, check view conversion component
3670 -- type cannot be private, tagged, or volatile. Note
3671 -- that we only apply this to source conversions. The
3672 -- generated code can contain conversions which are
3673 -- not subject to this test, and we cannot extract the
3674 -- component type in such cases since it is not present.
3676 elsif Comes_From_Source
(A
)
3677 and then Ada_Version
>= Ada_2005
3680 Comp_Type
: constant Entity_Id
:=
3682 (Etype
(Expression
(A
)));
3684 if (Is_Private_Type
(Comp_Type
)
3685 and then not Is_Generic_Type
(Comp_Type
))
3686 or else Is_Tagged_Type
(Comp_Type
)
3687 or else Is_Volatile
(Comp_Type
)
3690 ("component type of a view conversion cannot"
3691 & " be private, tagged, or volatile"
3700 -- Resolve expression if conversion is all OK
3702 if (Conversion_OK
(A
)
3703 or else Valid_Conversion
(A
, Etype
(A
), Expression
(A
)))
3704 and then not Is_Ref_To_Bit_Packed_Array
(Expression
(A
))
3706 Resolve
(Expression
(A
));
3709 -- If the actual is a function call that returns a limited
3710 -- unconstrained object that needs finalization, create a
3711 -- transient scope for it, so that it can receive the proper
3712 -- finalization list.
3714 elsif Nkind
(A
) = N_Function_Call
3715 and then Is_Limited_Record
(Etype
(F
))
3716 and then not Is_Constrained
(Etype
(F
))
3717 and then Expander_Active
3718 and then (Is_Controlled
(Etype
(F
)) or else Has_Task
(Etype
(F
)))
3720 Establish_Transient_Scope
(A
, Sec_Stack
=> False);
3721 Resolve
(A
, Etype
(F
));
3723 -- A small optimization: if one of the actuals is a concatenation
3724 -- create a block around a procedure call to recover stack space.
3725 -- This alleviates stack usage when several procedure calls in
3726 -- the same statement list use concatenation. We do not perform
3727 -- this wrapping for code statements, where the argument is a
3728 -- static string, and we want to preserve warnings involving
3729 -- sequences of such statements.
3731 elsif Nkind
(A
) = N_Op_Concat
3732 and then Nkind
(N
) = N_Procedure_Call_Statement
3733 and then Expander_Active
3735 not (Is_Intrinsic_Subprogram
(Nam
)
3736 and then Chars
(Nam
) = Name_Asm
)
3737 and then not Static_Concatenation
(A
)
3739 Establish_Transient_Scope
(A
, Sec_Stack
=> False);
3740 Resolve
(A
, Etype
(F
));
3743 if Nkind
(A
) = N_Type_Conversion
3744 and then Is_Array_Type
(Etype
(F
))
3745 and then not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
3747 (Is_Limited_Type
(Etype
(F
))
3748 or else Is_Limited_Type
(Etype
(Expression
(A
))))
3751 ("conversion between unrelated limited array types "
3752 & "not allowed ('A'I-00246)", A
);
3754 if Is_Limited_Type
(Etype
(F
)) then
3755 Explain_Limited_Type
(Etype
(F
), A
);
3758 if Is_Limited_Type
(Etype
(Expression
(A
))) then
3759 Explain_Limited_Type
(Etype
(Expression
(A
)), A
);
3763 -- (Ada 2005: AI-251): If the actual is an allocator whose
3764 -- directly designated type is a class-wide interface, we build
3765 -- an anonymous access type to use it as the type of the
3766 -- allocator. Later, when the subprogram call is expanded, if
3767 -- the interface has a secondary dispatch table the expander
3768 -- will add a type conversion to force the correct displacement
3771 if Nkind
(A
) = N_Allocator
then
3773 DDT
: constant Entity_Id
:=
3774 Directly_Designated_Type
(Base_Type
(Etype
(F
)));
3776 New_Itype
: Entity_Id
;
3779 if Is_Class_Wide_Type
(DDT
)
3780 and then Is_Interface
(DDT
)
3782 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, A
);
3783 Set_Etype
(New_Itype
, Etype
(A
));
3784 Set_Directly_Designated_Type
3785 (New_Itype
, Directly_Designated_Type
(Etype
(A
)));
3786 Set_Etype
(A
, New_Itype
);
3789 -- Ada 2005, AI-162:If the actual is an allocator, the
3790 -- innermost enclosing statement is the master of the
3791 -- created object. This needs to be done with expansion
3792 -- enabled only, otherwise the transient scope will not
3793 -- be removed in the expansion of the wrapped construct.
3795 if (Is_Controlled
(DDT
) or else Has_Task
(DDT
))
3796 and then Expander_Active
3798 Establish_Transient_Scope
(A
, Sec_Stack
=> False);
3802 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
3803 Check_Restriction
(No_Access_Parameter_Allocators
, A
);
3807 -- (Ada 2005): The call may be to a primitive operation of a
3808 -- tagged synchronized type, declared outside of the type. In
3809 -- this case the controlling actual must be converted to its
3810 -- corresponding record type, which is the formal type. The
3811 -- actual may be a subtype, either because of a constraint or
3812 -- because it is a generic actual, so use base type to locate
3815 F_Typ
:= Base_Type
(Etype
(F
));
3817 if Is_Tagged_Type
(F_Typ
)
3818 and then (Is_Concurrent_Type
(F_Typ
)
3819 or else Is_Concurrent_Record_Type
(F_Typ
))
3821 -- If the actual is overloaded, look for an interpretation
3822 -- that has a synchronized type.
3824 if not Is_Overloaded
(A
) then
3825 A_Typ
:= Base_Type
(Etype
(A
));
3829 Index
: Interp_Index
;
3833 Get_First_Interp
(A
, Index
, It
);
3834 while Present
(It
.Typ
) loop
3835 if Is_Concurrent_Type
(It
.Typ
)
3836 or else Is_Concurrent_Record_Type
(It
.Typ
)
3838 A_Typ
:= Base_Type
(It
.Typ
);
3842 Get_Next_Interp
(Index
, It
);
3848 Full_A_Typ
: Entity_Id
;
3851 if Present
(Full_View
(A_Typ
)) then
3852 Full_A_Typ
:= Base_Type
(Full_View
(A_Typ
));
3854 Full_A_Typ
:= A_Typ
;
3857 -- Tagged synchronized type (case 1): the actual is a
3860 if Is_Concurrent_Type
(A_Typ
)
3861 and then Corresponding_Record_Type
(A_Typ
) = F_Typ
3864 Unchecked_Convert_To
3865 (Corresponding_Record_Type
(A_Typ
), A
));
3866 Resolve
(A
, Etype
(F
));
3868 -- Tagged synchronized type (case 2): the formal is a
3871 elsif Ekind
(Full_A_Typ
) = E_Record_Type
3873 (Corresponding_Concurrent_Type
(Full_A_Typ
))
3874 and then Is_Concurrent_Type
(F_Typ
)
3875 and then Present
(Corresponding_Record_Type
(F_Typ
))
3876 and then Full_A_Typ
= Corresponding_Record_Type
(F_Typ
)
3878 Resolve
(A
, Corresponding_Record_Type
(F_Typ
));
3883 Resolve
(A
, Etype
(F
));
3887 -- Not a synchronized operation
3890 Resolve
(A
, Etype
(F
));
3897 -- An actual cannot be an untagged formal incomplete type
3899 if Ekind
(A_Typ
) = E_Incomplete_Type
3900 and then not Is_Tagged_Type
(A_Typ
)
3901 and then Is_Generic_Type
(A_Typ
)
3904 ("invalid use of untagged formal incomplete type", A
);
3907 if Comes_From_Source
(Original_Node
(N
))
3908 and then Nkind_In
(Original_Node
(N
), N_Function_Call
,
3909 N_Procedure_Call_Statement
)
3911 -- In formal mode, check that actual parameters matching
3912 -- formals of tagged types are objects (or ancestor type
3913 -- conversions of objects), not general expressions.
3915 if Is_Actual_Tagged_Parameter
(A
) then
3916 if Is_SPARK_05_Object_Reference
(A
) then
3919 elsif Nkind
(A
) = N_Type_Conversion
then
3921 Operand
: constant Node_Id
:= Expression
(A
);
3922 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
3923 Target_Typ
: constant Entity_Id
:= A_Typ
;
3926 if not Is_SPARK_05_Object_Reference
(Operand
) then
3927 Check_SPARK_05_Restriction
3928 ("object required", Operand
);
3930 -- In formal mode, the only view conversions are those
3931 -- involving ancestor conversion of an extended type.
3934 (Is_Tagged_Type
(Target_Typ
)
3935 and then not Is_Class_Wide_Type
(Target_Typ
)
3936 and then Is_Tagged_Type
(Operand_Typ
)
3937 and then not Is_Class_Wide_Type
(Operand_Typ
)
3938 and then Is_Ancestor
(Target_Typ
, Operand_Typ
))
3941 (F
, E_Out_Parameter
, E_In_Out_Parameter
)
3943 Check_SPARK_05_Restriction
3944 ("ancestor conversion is the only permitted "
3945 & "view conversion", A
);
3947 Check_SPARK_05_Restriction
3948 ("ancestor conversion required", A
);
3957 Check_SPARK_05_Restriction
("object required", A
);
3960 -- In formal mode, the only view conversions are those
3961 -- involving ancestor conversion of an extended type.
3963 elsif Nkind
(A
) = N_Type_Conversion
3964 and then Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
)
3966 Check_SPARK_05_Restriction
3967 ("ancestor conversion is the only permitted view "
3972 -- has warnings suppressed, then we reset Never_Set_In_Source for
3973 -- the calling entity. The reason for this is to catch cases like
3974 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3975 -- uses trickery to modify an IN parameter.
3977 if Ekind
(F
) = E_In_Parameter
3978 and then Is_Entity_Name
(A
)
3979 and then Present
(Entity
(A
))
3980 and then Ekind
(Entity
(A
)) = E_Variable
3981 and then Has_Warnings_Off
(F_Typ
)
3983 Set_Never_Set_In_Source
(Entity
(A
), False);
3986 -- Perform error checks for IN and IN OUT parameters
3988 if Ekind
(F
) /= E_Out_Parameter
then
3990 -- Check unset reference. For scalar parameters, it is clearly
3991 -- wrong to pass an uninitialized value as either an IN or
3992 -- IN-OUT parameter. For composites, it is also clearly an
3993 -- error to pass a completely uninitialized value as an IN
3994 -- parameter, but the case of IN OUT is trickier. We prefer
3995 -- not to give a warning here. For example, suppose there is
3996 -- a routine that sets some component of a record to False.
3997 -- It is perfectly reasonable to make this IN-OUT and allow
3998 -- either initialized or uninitialized records to be passed
4001 -- For partially initialized composite values, we also avoid
4002 -- warnings, since it is quite likely that we are passing a
4003 -- partially initialized value and only the initialized fields
4004 -- will in fact be read in the subprogram.
4006 if Is_Scalar_Type
(A_Typ
)
4007 or else (Ekind
(F
) = E_In_Parameter
4008 and then not Is_Partially_Initialized_Type
(A_Typ
))
4010 Check_Unset_Reference
(A
);
4013 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
4014 -- actual to a nested call, since this is case of reading an
4015 -- out parameter, which is not allowed.
4017 if Ada_Version
= Ada_83
4018 and then Is_Entity_Name
(A
)
4019 and then Ekind
(Entity
(A
)) = E_Out_Parameter
4021 Error_Msg_N
("(Ada 83) illegal reading of out parameter", A
);
4025 -- Case of OUT or IN OUT parameter
4027 if Ekind
(F
) /= E_In_Parameter
then
4029 -- For an Out parameter, check for useless assignment. Note
4030 -- that we can't set Last_Assignment this early, because we may
4031 -- kill current values in Resolve_Call, and that call would
4032 -- clobber the Last_Assignment field.
4034 -- Note: call Warn_On_Useless_Assignment before doing the check
4035 -- below for Is_OK_Variable_For_Out_Formal so that the setting
4036 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
4037 -- reflects the last assignment, not this one.
4039 if Ekind
(F
) = E_Out_Parameter
then
4040 if Warn_On_Modified_As_Out_Parameter
(F
)
4041 and then Is_Entity_Name
(A
)
4042 and then Present
(Entity
(A
))
4043 and then Comes_From_Source
(N
)
4045 Warn_On_Useless_Assignment
(Entity
(A
), A
);
4049 -- Validate the form of the actual. Note that the call to
4050 -- Is_OK_Variable_For_Out_Formal generates the required
4051 -- reference in this case.
4053 -- A call to an initialization procedure for an aggregate
4054 -- component may initialize a nested component of a constant
4055 -- designated object. In this context the object is variable.
4057 if not Is_OK_Variable_For_Out_Formal
(A
)
4058 and then not Is_Init_Proc
(Nam
)
4060 Error_Msg_NE
("actual for& must be a variable", A
, F
);
4062 if Is_Subprogram
(Current_Scope
)
4064 (Is_Invariant_Procedure
(Current_Scope
)
4065 or else Is_Predicate_Function
(Current_Scope
))
4068 ("function used in predicate cannot "
4069 & "modify its argument", F
);
4073 -- What's the following about???
4075 if Is_Entity_Name
(A
) then
4076 Kill_Checks
(Entity
(A
));
4082 if Etype
(A
) = Any_Type
then
4083 Set_Etype
(N
, Any_Type
);
4087 -- Apply appropriate constraint/predicate checks for IN [OUT] case
4089 if Ekind_In
(F
, E_In_Parameter
, E_In_Out_Parameter
) then
4091 -- Apply predicate tests except in certain special cases. Note
4092 -- that it might be more consistent to apply these only when
4093 -- expansion is active (in Exp_Ch6.Expand_Actuals), as we do
4094 -- for the outbound predicate tests ???
4096 if Predicate_Tests_On_Arguments
(Nam
) then
4097 Apply_Predicate_Check
(A
, F_Typ
);
4100 -- Apply required constraint checks
4102 -- Gigi looks at the check flag and uses the appropriate types.
4103 -- For now since one flag is used there is an optimization
4104 -- which might not be done in the IN OUT case since Gigi does
4105 -- not do any analysis. More thought required about this ???
4107 -- In fact is this comment obsolete??? doesn't the expander now
4108 -- generate all these tests anyway???
4110 if Is_Scalar_Type
(Etype
(A
)) then
4111 Apply_Scalar_Range_Check
(A
, F_Typ
);
4113 elsif Is_Array_Type
(Etype
(A
)) then
4114 Apply_Length_Check
(A
, F_Typ
);
4116 elsif Is_Record_Type
(F_Typ
)
4117 and then Has_Discriminants
(F_Typ
)
4118 and then Is_Constrained
(F_Typ
)
4119 and then (not Is_Derived_Type
(F_Typ
)
4120 or else Comes_From_Source
(Nam
))
4122 Apply_Discriminant_Check
(A
, F_Typ
);
4124 -- For view conversions of a discriminated object, apply
4125 -- check to object itself, the conversion alreay has the
4128 if Nkind
(A
) = N_Type_Conversion
4129 and then Is_Constrained
(Etype
(Expression
(A
)))
4131 Apply_Discriminant_Check
(Expression
(A
), F_Typ
);
4134 elsif Is_Access_Type
(F_Typ
)
4135 and then Is_Array_Type
(Designated_Type
(F_Typ
))
4136 and then Is_Constrained
(Designated_Type
(F_Typ
))
4138 Apply_Length_Check
(A
, F_Typ
);
4140 elsif Is_Access_Type
(F_Typ
)
4141 and then Has_Discriminants
(Designated_Type
(F_Typ
))
4142 and then Is_Constrained
(Designated_Type
(F_Typ
))
4144 Apply_Discriminant_Check
(A
, F_Typ
);
4147 Apply_Range_Check
(A
, F_Typ
);
4150 -- Ada 2005 (AI-231): Note that the controlling parameter case
4151 -- already existed in Ada 95, which is partially checked
4152 -- elsewhere (see Checks), and we don't want the warning
4153 -- message to differ.
4155 if Is_Access_Type
(F_Typ
)
4156 and then Can_Never_Be_Null
(F_Typ
)
4157 and then Known_Null
(A
)
4159 if Is_Controlling_Formal
(F
) then
4160 Apply_Compile_Time_Constraint_Error
4162 Msg
=> "null value not allowed here??",
4163 Reason
=> CE_Access_Check_Failed
);
4165 elsif Ada_Version
>= Ada_2005
then
4166 Apply_Compile_Time_Constraint_Error
4168 Msg
=> "(Ada 2005) null not allowed in "
4169 & "null-excluding formal??",
4170 Reason
=> CE_Null_Not_Allowed
);
4175 -- Checks for OUT parameters and IN OUT parameters
4177 if Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
) then
4179 -- If there is a type conversion, to make sure the return value
4180 -- meets the constraints of the variable before the conversion.
4182 if Nkind
(A
) = N_Type_Conversion
then
4183 if Is_Scalar_Type
(A_Typ
) then
4184 Apply_Scalar_Range_Check
4185 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4188 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
4191 -- If no conversion apply scalar range checks and length checks
4192 -- base on the subtype of the actual (NOT that of the formal).
4195 if Is_Scalar_Type
(F_Typ
) then
4196 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
4197 elsif Is_Array_Type
(F_Typ
)
4198 and then Ekind
(F
) = E_Out_Parameter
4200 Apply_Length_Check
(A
, F_Typ
);
4202 Apply_Range_Check
(A
, A_Typ
, F_Typ
);
4206 -- Note: we do not apply the predicate checks for the case of
4207 -- OUT and IN OUT parameters. They are instead applied in the
4208 -- Expand_Actuals routine in Exp_Ch6.
4211 -- An actual associated with an access parameter is implicitly
4212 -- converted to the anonymous access type of the formal and must
4213 -- satisfy the legality checks for access conversions.
4215 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
4216 if not Valid_Conversion
(A
, F_Typ
, A
) then
4218 ("invalid implicit conversion for access parameter", A
);
4221 -- If the actual is an access selected component of a variable,
4222 -- the call may modify its designated object. It is reasonable
4223 -- to treat this as a potential modification of the enclosing
4224 -- record, to prevent spurious warnings that it should be
4225 -- declared as a constant, because intuitively programmers
4226 -- regard the designated subcomponent as part of the record.
4228 if Nkind
(A
) = N_Selected_Component
4229 and then Is_Entity_Name
(Prefix
(A
))
4230 and then not Is_Constant_Object
(Entity
(Prefix
(A
)))
4232 Note_Possible_Modification
(A
, Sure
=> False);
4236 -- Check bad case of atomic/volatile argument (RM C.6(12))
4238 if Is_By_Reference_Type
(Etype
(F
))
4239 and then Comes_From_Source
(N
)
4241 if Is_Atomic_Object
(A
)
4242 and then not Is_Atomic
(Etype
(F
))
4245 ("cannot pass atomic argument to non-atomic formal&",
4248 elsif Is_Volatile_Object
(A
)
4249 and then not Is_Volatile
(Etype
(F
))
4252 ("cannot pass volatile argument to non-volatile formal&",
4257 -- Check that subprograms don't have improper controlling
4258 -- arguments (RM 3.9.2 (9)).
4260 -- A primitive operation may have an access parameter of an
4261 -- incomplete tagged type, but a dispatching call is illegal
4262 -- if the type is still incomplete.
4264 if Is_Controlling_Formal
(F
) then
4265 Set_Is_Controlling_Actual
(A
);
4267 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
4269 Desig
: constant Entity_Id
:= Designated_Type
(Etype
(F
));
4271 if Ekind
(Desig
) = E_Incomplete_Type
4272 and then No
(Full_View
(Desig
))
4273 and then No
(Non_Limited_View
(Desig
))
4276 ("premature use of incomplete type& "
4277 & "in dispatching call", A
, Desig
);
4282 elsif Nkind
(A
) = N_Explicit_Dereference
then
4283 Validate_Remote_Access_To_Class_Wide_Type
(A
);
4286 if (Is_Class_Wide_Type
(A_Typ
) or else Is_Dynamically_Tagged
(A
))
4287 and then not Is_Class_Wide_Type
(F_Typ
)
4288 and then not Is_Controlling_Formal
(F
)
4290 Error_Msg_N
("class-wide argument not allowed here!", A
);
4292 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
4293 Error_Msg_Node_2
:= F_Typ
;
4295 ("& is not a dispatching operation of &!", A
, Nam
);
4298 -- Apply the checks described in 3.10.2(27): if the context is a
4299 -- specific access-to-object, the actual cannot be class-wide.
4300 -- Use base type to exclude access_to_subprogram cases.
4302 elsif Is_Access_Type
(A_Typ
)
4303 and then Is_Access_Type
(F_Typ
)
4304 and then not Is_Access_Subprogram_Type
(Base_Type
(F_Typ
))
4305 and then (Is_Class_Wide_Type
(Designated_Type
(A_Typ
))
4306 or else (Nkind
(A
) = N_Attribute_Reference
4308 Is_Class_Wide_Type
(Etype
(Prefix
(A
)))))
4309 and then not Is_Class_Wide_Type
(Designated_Type
(F_Typ
))
4310 and then not Is_Controlling_Formal
(F
)
4312 -- Disable these checks for call to imported C++ subprograms
4315 (Is_Entity_Name
(Name
(N
))
4316 and then Is_Imported
(Entity
(Name
(N
)))
4317 and then Convention
(Entity
(Name
(N
))) = Convention_CPP
)
4320 ("access to class-wide argument not allowed here!", A
);
4322 if Is_Subprogram
(Nam
) and then Comes_From_Source
(Nam
) then
4323 Error_Msg_Node_2
:= Designated_Type
(F_Typ
);
4325 ("& is not a dispatching operation of &!", A
, Nam
);
4329 Check_Aliased_Parameter
;
4333 -- If it is a named association, treat the selector_name as a
4334 -- proper identifier, and mark the corresponding entity.
4336 if Nkind
(Parent
(A
)) = N_Parameter_Association
4338 -- Ignore reference in SPARK mode, as it refers to an entity not
4339 -- in scope at the point of reference, so the reference should
4340 -- be ignored for computing effects of subprograms.
4342 and then not GNATprove_Mode
4344 Set_Entity
(Selector_Name
(Parent
(A
)), F
);
4345 Generate_Reference
(F
, Selector_Name
(Parent
(A
)));
4346 Set_Etype
(Selector_Name
(Parent
(A
)), F_Typ
);
4347 Generate_Reference
(F_Typ
, N
, ' ');
4352 if Ekind
(F
) /= E_Out_Parameter
then
4353 Check_Unset_Reference
(A
);
4356 -- The following checks are only relevant when SPARK_Mode is on as
4357 -- they are not standard Ada legality rule. Internally generated
4358 -- temporaries are ignored.
4361 and then Is_Effectively_Volatile_Object
(A
)
4362 and then Comes_From_Source
(A
)
4364 -- An effectively volatile object may act as an actual
4365 -- parameter when the corresponding formal is of a non-scalar
4368 if Is_Volatile
(Etype
(F
))
4369 and then not Is_Scalar_Type
(Etype
(F
))
4373 -- An effectively volatile object may act as an actual
4374 -- parameter in a call to an instance of Unchecked_Conversion.
4376 elsif Is_Unchecked_Conversion_Instance
(Nam
) then
4381 ("volatile object cannot act as actual in a call (SPARK "
4382 & "RM 7.1.3(12))", A
);
4385 -- Detect an external variable with an enabled property that
4386 -- does not match the mode of the corresponding formal in a
4387 -- procedure call. Functions are not considered because they
4388 -- cannot have effectively volatile formal parameters in the
4391 if Ekind
(Nam
) = E_Procedure
4392 and then Is_Entity_Name
(A
)
4393 and then Present
(Entity
(A
))
4394 and then Ekind
(Entity
(A
)) = E_Variable
4398 if Ekind
(F
) = E_In_Parameter
then
4399 if Async_Readers_Enabled
(A_Id
) then
4400 Property_Error
(A
, A_Id
, Name_Async_Readers
);
4401 elsif Effective_Reads_Enabled
(A_Id
) then
4402 Property_Error
(A
, A_Id
, Name_Effective_Reads
);
4403 elsif Effective_Writes_Enabled
(A_Id
) then
4404 Property_Error
(A
, A_Id
, Name_Effective_Writes
);
4407 elsif Ekind
(F
) = E_Out_Parameter
4408 and then Async_Writers_Enabled
(A_Id
)
4410 Error_Msg_Name_1
:= Name_Async_Writers
;
4412 ("external variable & with enabled property % cannot "
4413 & "appear as actual in procedure call "
4414 & "(SPARK RM 7.1.3(11))", A
, A_Id
);
4416 ("\\corresponding formal parameter has mode Out", A
);
4421 -- A formal parameter of a specific tagged type whose related
4422 -- subprogram is subject to pragma Extensions_Visible with value
4423 -- "False" cannot act as an actual in a subprogram with value
4424 -- "True" (SPARK RM 6.1.7(3)).
4426 if Is_EVF_Expression
(A
)
4427 and then Extensions_Visible_Status
(Nam
) =
4428 Extensions_Visible_True
4431 ("formal parameter with Extensions_Visible False cannot act "
4432 & "as actual parameter", A
);
4434 ("\subprogram & has Extensions_Visible True", A
, Nam
);
4439 -- Case where actual is not present
4447 end Resolve_Actuals
;
4449 -----------------------
4450 -- Resolve_Allocator --
4451 -----------------------
4453 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
) is
4454 Desig_T
: constant Entity_Id
:= Designated_Type
(Typ
);
4455 E
: constant Node_Id
:= Expression
(N
);
4457 Discrim
: Entity_Id
;
4460 Assoc
: Node_Id
:= Empty
;
4463 procedure Check_Allocator_Discrim_Accessibility
4464 (Disc_Exp
: Node_Id
;
4465 Alloc_Typ
: Entity_Id
);
4466 -- Check that accessibility level associated with an access discriminant
4467 -- initialized in an allocator by the expression Disc_Exp is not deeper
4468 -- than the level of the allocator type Alloc_Typ. An error message is
4469 -- issued if this condition is violated. Specialized checks are done for
4470 -- the cases of a constraint expression which is an access attribute or
4471 -- an access discriminant.
4473 function In_Dispatching_Context
return Boolean;
4474 -- If the allocator is an actual in a call, it is allowed to be class-
4475 -- wide when the context is not because it is a controlling actual.
4477 -------------------------------------------
4478 -- Check_Allocator_Discrim_Accessibility --
4479 -------------------------------------------
4481 procedure Check_Allocator_Discrim_Accessibility
4482 (Disc_Exp
: Node_Id
;
4483 Alloc_Typ
: Entity_Id
)
4486 if Type_Access_Level
(Etype
(Disc_Exp
)) >
4487 Deepest_Type_Access_Level
(Alloc_Typ
)
4490 ("operand type has deeper level than allocator type", Disc_Exp
);
4492 -- When the expression is an Access attribute the level of the prefix
4493 -- object must not be deeper than that of the allocator's type.
4495 elsif Nkind
(Disc_Exp
) = N_Attribute_Reference
4496 and then Get_Attribute_Id
(Attribute_Name
(Disc_Exp
)) =
4498 and then Object_Access_Level
(Prefix
(Disc_Exp
)) >
4499 Deepest_Type_Access_Level
(Alloc_Typ
)
4502 ("prefix of attribute has deeper level than allocator type",
4505 -- When the expression is an access discriminant the check is against
4506 -- the level of the prefix object.
4508 elsif Ekind
(Etype
(Disc_Exp
)) = E_Anonymous_Access_Type
4509 and then Nkind
(Disc_Exp
) = N_Selected_Component
4510 and then Object_Access_Level
(Prefix
(Disc_Exp
)) >
4511 Deepest_Type_Access_Level
(Alloc_Typ
)
4514 ("access discriminant has deeper level than allocator type",
4517 -- All other cases are legal
4522 end Check_Allocator_Discrim_Accessibility
;
4524 ----------------------------
4525 -- In_Dispatching_Context --
4526 ----------------------------
4528 function In_Dispatching_Context
return Boolean is
4529 Par
: constant Node_Id
:= Parent
(N
);
4532 return Nkind
(Par
) in N_Subprogram_Call
4533 and then Is_Entity_Name
(Name
(Par
))
4534 and then Is_Dispatching_Operation
(Entity
(Name
(Par
)));
4535 end In_Dispatching_Context
;
4537 -- Start of processing for Resolve_Allocator
4540 -- Replace general access with specific type
4542 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
4543 Set_Etype
(N
, Base_Type
(Typ
));
4546 if Is_Abstract_Type
(Typ
) then
4547 Error_Msg_N
("type of allocator cannot be abstract", N
);
4550 -- For qualified expression, resolve the expression using the given
4551 -- subtype (nothing to do for type mark, subtype indication)
4553 if Nkind
(E
) = N_Qualified_Expression
then
4554 if Is_Class_Wide_Type
(Etype
(E
))
4555 and then not Is_Class_Wide_Type
(Desig_T
)
4556 and then not In_Dispatching_Context
4559 ("class-wide allocator not allowed for this access type", N
);
4562 Resolve
(Expression
(E
), Etype
(E
));
4563 Check_Non_Static_Context
(Expression
(E
));
4564 Check_Unset_Reference
(Expression
(E
));
4566 -- A qualified expression requires an exact match of the type.
4567 -- Class-wide matching is not allowed.
4569 if (Is_Class_Wide_Type
(Etype
(Expression
(E
)))
4570 or else Is_Class_Wide_Type
(Etype
(E
)))
4571 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Etype
(E
))
4573 Wrong_Type
(Expression
(E
), Etype
(E
));
4576 -- Calls to build-in-place functions are not currently supported in
4577 -- allocators for access types associated with a simple storage pool.
4578 -- Supporting such allocators may require passing additional implicit
4579 -- parameters to build-in-place functions (or a significant revision
4580 -- of the current b-i-p implementation to unify the handling for
4581 -- multiple kinds of storage pools). ???
4583 if Is_Limited_View
(Desig_T
)
4584 and then Nkind
(Expression
(E
)) = N_Function_Call
4587 Pool
: constant Entity_Id
:=
4588 Associated_Storage_Pool
(Root_Type
(Typ
));
4592 Present
(Get_Rep_Pragma
4593 (Etype
(Pool
), Name_Simple_Storage_Pool_Type
))
4596 ("limited function calls not yet supported in simple "
4597 & "storage pool allocators", Expression
(E
));
4602 -- A special accessibility check is needed for allocators that
4603 -- constrain access discriminants. The level of the type of the
4604 -- expression used to constrain an access discriminant cannot be
4605 -- deeper than the type of the allocator (in contrast to access
4606 -- parameters, where the level of the actual can be arbitrary).
4608 -- We can't use Valid_Conversion to perform this check because in
4609 -- general the type of the allocator is unrelated to the type of
4610 -- the access discriminant.
4612 if Ekind
(Typ
) /= E_Anonymous_Access_Type
4613 or else Is_Local_Anonymous_Access
(Typ
)
4615 Subtyp
:= Entity
(Subtype_Mark
(E
));
4617 Aggr
:= Original_Node
(Expression
(E
));
4619 if Has_Discriminants
(Subtyp
)
4620 and then Nkind_In
(Aggr
, N_Aggregate
, N_Extension_Aggregate
)
4622 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
4624 -- Get the first component expression of the aggregate
4626 if Present
(Expressions
(Aggr
)) then
4627 Disc_Exp
:= First
(Expressions
(Aggr
));
4629 elsif Present
(Component_Associations
(Aggr
)) then
4630 Assoc
:= First
(Component_Associations
(Aggr
));
4632 if Present
(Assoc
) then
4633 Disc_Exp
:= Expression
(Assoc
);
4642 while Present
(Discrim
) and then Present
(Disc_Exp
) loop
4643 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
4644 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
4647 Next_Discriminant
(Discrim
);
4649 if Present
(Discrim
) then
4650 if Present
(Assoc
) then
4652 Disc_Exp
:= Expression
(Assoc
);
4654 elsif Present
(Next
(Disc_Exp
)) then
4658 Assoc
:= First
(Component_Associations
(Aggr
));
4660 if Present
(Assoc
) then
4661 Disc_Exp
:= Expression
(Assoc
);
4671 -- For a subtype mark or subtype indication, freeze the subtype
4674 Freeze_Expression
(E
);
4676 if Is_Access_Constant
(Typ
) and then not No_Initialization
(N
) then
4678 ("initialization required for access-to-constant allocator", N
);
4681 -- A special accessibility check is needed for allocators that
4682 -- constrain access discriminants. The level of the type of the
4683 -- expression used to constrain an access discriminant cannot be
4684 -- deeper than the type of the allocator (in contrast to access
4685 -- parameters, where the level of the actual can be arbitrary).
4686 -- We can't use Valid_Conversion to perform this check because
4687 -- in general the type of the allocator is unrelated to the type
4688 -- of the access discriminant.
4690 if Nkind
(Original_Node
(E
)) = N_Subtype_Indication
4691 and then (Ekind
(Typ
) /= E_Anonymous_Access_Type
4692 or else Is_Local_Anonymous_Access
(Typ
))
4694 Subtyp
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
4696 if Has_Discriminants
(Subtyp
) then
4697 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
4698 Constr
:= First
(Constraints
(Constraint
(Original_Node
(E
))));
4699 while Present
(Discrim
) and then Present
(Constr
) loop
4700 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
4701 if Nkind
(Constr
) = N_Discriminant_Association
then
4702 Disc_Exp
:= Original_Node
(Expression
(Constr
));
4704 Disc_Exp
:= Original_Node
(Constr
);
4707 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
4710 Next_Discriminant
(Discrim
);
4717 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4718 -- check that the level of the type of the created object is not deeper
4719 -- than the level of the allocator's access type, since extensions can
4720 -- now occur at deeper levels than their ancestor types. This is a
4721 -- static accessibility level check; a run-time check is also needed in
4722 -- the case of an initialized allocator with a class-wide argument (see
4723 -- Expand_Allocator_Expression).
4725 if Ada_Version
>= Ada_2005
4726 and then Is_Class_Wide_Type
(Desig_T
)
4729 Exp_Typ
: Entity_Id
;
4732 if Nkind
(E
) = N_Qualified_Expression
then
4733 Exp_Typ
:= Etype
(E
);
4734 elsif Nkind
(E
) = N_Subtype_Indication
then
4735 Exp_Typ
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
4737 Exp_Typ
:= Entity
(E
);
4740 if Type_Access_Level
(Exp_Typ
) >
4741 Deepest_Type_Access_Level
(Typ
)
4743 if In_Instance_Body
then
4744 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4746 ("type in allocator has deeper level than "
4747 & "designated class-wide type<<", E
);
4748 Error_Msg_N
("\Program_Error [<<", E
);
4750 Make_Raise_Program_Error
(Sloc
(N
),
4751 Reason
=> PE_Accessibility_Check_Failed
));
4754 -- Do not apply Ada 2005 accessibility checks on a class-wide
4755 -- allocator if the type given in the allocator is a formal
4756 -- type. A run-time check will be performed in the instance.
4758 elsif not Is_Generic_Type
(Exp_Typ
) then
4759 Error_Msg_N
("type in allocator has deeper level than "
4760 & "designated class-wide type", E
);
4766 -- Check for allocation from an empty storage pool
4768 if No_Pool_Assigned
(Typ
) then
4769 Error_Msg_N
("allocation from empty storage pool!", N
);
4771 -- If the context is an unchecked conversion, as may happen within an
4772 -- inlined subprogram, the allocator is being resolved with its own
4773 -- anonymous type. In that case, if the target type has a specific
4774 -- storage pool, it must be inherited explicitly by the allocator type.
4776 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
4777 and then No
(Associated_Storage_Pool
(Typ
))
4779 Set_Associated_Storage_Pool
4780 (Typ
, Associated_Storage_Pool
(Etype
(Parent
(N
))));
4783 if Ekind
(Etype
(N
)) = E_Anonymous_Access_Type
then
4784 Check_Restriction
(No_Anonymous_Allocators
, N
);
4787 -- Check that an allocator with task parts isn't for a nested access
4788 -- type when restriction No_Task_Hierarchy applies.
4790 if not Is_Library_Level_Entity
(Base_Type
(Typ
))
4791 and then Has_Task
(Base_Type
(Desig_T
))
4793 Check_Restriction
(No_Task_Hierarchy
, N
);
4796 -- An illegal allocator may be rewritten as a raise Program_Error
4799 if Nkind
(N
) = N_Allocator
then
4801 -- An anonymous access discriminant is the definition of a
4804 if Ekind
(Typ
) = E_Anonymous_Access_Type
4805 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
4806 N_Discriminant_Specification
4809 Discr
: constant Entity_Id
:=
4810 Defining_Identifier
(Associated_Node_For_Itype
(Typ
));
4813 Check_Restriction
(No_Coextensions
, N
);
4815 -- Ada 2012 AI05-0052: If the designated type of the allocator
4816 -- is limited, then the allocator shall not be used to define
4817 -- the value of an access discriminant unless the discriminated
4818 -- type is immutably limited.
4820 if Ada_Version
>= Ada_2012
4821 and then Is_Limited_Type
(Desig_T
)
4822 and then not Is_Limited_View
(Scope
(Discr
))
4825 ("only immutably limited types can have anonymous "
4826 & "access discriminants designating a limited type", N
);
4830 -- Avoid marking an allocator as a dynamic coextension if it is
4831 -- within a static construct.
4833 if not Is_Static_Coextension
(N
) then
4834 Set_Is_Dynamic_Coextension
(N
);
4837 -- Cleanup for potential static coextensions
4840 Set_Is_Dynamic_Coextension
(N
, False);
4841 Set_Is_Static_Coextension
(N
, False);
4845 -- Report a simple error: if the designated object is a local task,
4846 -- its body has not been seen yet, and its activation will fail an
4847 -- elaboration check.
4849 if Is_Task_Type
(Desig_T
)
4850 and then Scope
(Base_Type
(Desig_T
)) = Current_Scope
4851 and then Is_Compilation_Unit
(Current_Scope
)
4852 and then Ekind
(Current_Scope
) = E_Package
4853 and then not In_Package_Body
(Current_Scope
)
4855 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4856 Error_Msg_N
("cannot activate task before body seen<<", N
);
4857 Error_Msg_N
("\Program_Error [<<", N
);
4860 -- Ada 2012 (AI05-0111-3): Detect an attempt to allocate a task or a
4861 -- type with a task component on a subpool. This action must raise
4862 -- Program_Error at runtime.
4864 if Ada_Version
>= Ada_2012
4865 and then Nkind
(N
) = N_Allocator
4866 and then Present
(Subpool_Handle_Name
(N
))
4867 and then Has_Task
(Desig_T
)
4869 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4870 Error_Msg_N
("cannot allocate task on subpool<<", N
);
4871 Error_Msg_N
("\Program_Error [<<", N
);
4874 Make_Raise_Program_Error
(Sloc
(N
),
4875 Reason
=> PE_Explicit_Raise
));
4878 end Resolve_Allocator
;
4880 ---------------------------
4881 -- Resolve_Arithmetic_Op --
4882 ---------------------------
4884 -- Used for resolving all arithmetic operators except exponentiation
4886 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
4887 L
: constant Node_Id
:= Left_Opnd
(N
);
4888 R
: constant Node_Id
:= Right_Opnd
(N
);
4889 TL
: constant Entity_Id
:= Base_Type
(Etype
(L
));
4890 TR
: constant Entity_Id
:= Base_Type
(Etype
(R
));
4894 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
4895 -- We do the resolution using the base type, because intermediate values
4896 -- in expressions always are of the base type, not a subtype of it.
4898 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean;
4899 -- Returns True if N is in a context that expects "any real type"
4901 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean;
4902 -- Return True iff given type is Integer or universal real/integer
4904 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
);
4905 -- Choose type of integer literal in fixed-point operation to conform
4906 -- to available fixed-point type. T is the type of the other operand,
4907 -- which is needed to determine the expected type of N.
4909 procedure Set_Operand_Type
(N
: Node_Id
);
4910 -- Set operand type to T if universal
4912 -------------------------------
4913 -- Expected_Type_Is_Any_Real --
4914 -------------------------------
4916 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean is
4918 -- N is the expression after "delta" in a fixed_point_definition;
4921 return Nkind_In
(Parent
(N
), N_Ordinary_Fixed_Point_Definition
,
4922 N_Decimal_Fixed_Point_Definition
,
4924 -- N is one of the bounds in a real_range_specification;
4927 N_Real_Range_Specification
,
4929 -- N is the expression of a delta_constraint;
4932 N_Delta_Constraint
);
4933 end Expected_Type_Is_Any_Real
;
4935 -----------------------------
4936 -- Is_Integer_Or_Universal --
4937 -----------------------------
4939 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean is
4941 Index
: Interp_Index
;
4945 if not Is_Overloaded
(N
) then
4947 return Base_Type
(T
) = Base_Type
(Standard_Integer
)
4948 or else T
= Universal_Integer
4949 or else T
= Universal_Real
;
4951 Get_First_Interp
(N
, Index
, It
);
4952 while Present
(It
.Typ
) loop
4953 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
)
4954 or else It
.Typ
= Universal_Integer
4955 or else It
.Typ
= Universal_Real
4960 Get_Next_Interp
(Index
, It
);
4965 end Is_Integer_Or_Universal
;
4967 ----------------------------
4968 -- Set_Mixed_Mode_Operand --
4969 ----------------------------
4971 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
) is
4972 Index
: Interp_Index
;
4976 if Universal_Interpretation
(N
) = Universal_Integer
then
4978 -- A universal integer literal is resolved as standard integer
4979 -- except in the case of a fixed-point result, where we leave it
4980 -- as universal (to be handled by Exp_Fixd later on)
4982 if Is_Fixed_Point_Type
(T
) then
4983 Resolve
(N
, Universal_Integer
);
4985 Resolve
(N
, Standard_Integer
);
4988 elsif Universal_Interpretation
(N
) = Universal_Real
4989 and then (T
= Base_Type
(Standard_Integer
)
4990 or else T
= Universal_Integer
4991 or else T
= Universal_Real
)
4993 -- A universal real can appear in a fixed-type context. We resolve
4994 -- the literal with that context, even though this might raise an
4995 -- exception prematurely (the other operand may be zero).
4999 elsif Etype
(N
) = Base_Type
(Standard_Integer
)
5000 and then T
= Universal_Real
5001 and then Is_Overloaded
(N
)
5003 -- Integer arg in mixed-mode operation. Resolve with universal
5004 -- type, in case preference rule must be applied.
5006 Resolve
(N
, Universal_Integer
);
5009 and then B_Typ
/= Universal_Fixed
5011 -- Not a mixed-mode operation, resolve with context
5015 elsif Etype
(N
) = Any_Fixed
then
5017 -- N may itself be a mixed-mode operation, so use context type
5021 elsif Is_Fixed_Point_Type
(T
)
5022 and then B_Typ
= Universal_Fixed
5023 and then Is_Overloaded
(N
)
5025 -- Must be (fixed * fixed) operation, operand must have one
5026 -- compatible interpretation.
5028 Resolve
(N
, Any_Fixed
);
5030 elsif Is_Fixed_Point_Type
(B_Typ
)
5031 and then (T
= Universal_Real
or else Is_Fixed_Point_Type
(T
))
5032 and then Is_Overloaded
(N
)
5034 -- C * F(X) in a fixed context, where C is a real literal or a
5035 -- fixed-point expression. F must have either a fixed type
5036 -- interpretation or an integer interpretation, but not both.
5038 Get_First_Interp
(N
, Index
, It
);
5039 while Present
(It
.Typ
) loop
5040 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
) then
5041 if Analyzed
(N
) then
5042 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5044 Resolve
(N
, Standard_Integer
);
5047 elsif Is_Fixed_Point_Type
(It
.Typ
) then
5048 if Analyzed
(N
) then
5049 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5051 Resolve
(N
, It
.Typ
);
5055 Get_Next_Interp
(Index
, It
);
5058 -- Reanalyze the literal with the fixed type of the context. If
5059 -- context is Universal_Fixed, we are within a conversion, leave
5060 -- the literal as a universal real because there is no usable
5061 -- fixed type, and the target of the conversion plays no role in
5075 if B_Typ
= Universal_Fixed
5076 and then Nkind
(Op2
) = N_Real_Literal
5078 T2
:= Universal_Real
;
5083 Set_Analyzed
(Op2
, False);
5090 end Set_Mixed_Mode_Operand
;
5092 ----------------------
5093 -- Set_Operand_Type --
5094 ----------------------
5096 procedure Set_Operand_Type
(N
: Node_Id
) is
5098 if Etype
(N
) = Universal_Integer
5099 or else Etype
(N
) = Universal_Real
5103 end Set_Operand_Type
;
5105 -- Start of processing for Resolve_Arithmetic_Op
5108 if Comes_From_Source
(N
)
5109 and then Ekind
(Entity
(N
)) = E_Function
5110 and then Is_Imported
(Entity
(N
))
5111 and then Is_Intrinsic_Subprogram
(Entity
(N
))
5113 Resolve_Intrinsic_Operator
(N
, Typ
);
5116 -- Special-case for mixed-mode universal expressions or fixed point type
5117 -- operation: each argument is resolved separately. The same treatment
5118 -- is required if one of the operands of a fixed point operation is
5119 -- universal real, since in this case we don't do a conversion to a
5120 -- specific fixed-point type (instead the expander handles the case).
5122 -- Set the type of the node to its universal interpretation because
5123 -- legality checks on an exponentiation operand need the context.
5125 elsif (B_Typ
= Universal_Integer
or else B_Typ
= Universal_Real
)
5126 and then Present
(Universal_Interpretation
(L
))
5127 and then Present
(Universal_Interpretation
(R
))
5129 Set_Etype
(N
, B_Typ
);
5130 Resolve
(L
, Universal_Interpretation
(L
));
5131 Resolve
(R
, Universal_Interpretation
(R
));
5133 elsif (B_Typ
= Universal_Real
5134 or else Etype
(N
) = Universal_Fixed
5135 or else (Etype
(N
) = Any_Fixed
5136 and then Is_Fixed_Point_Type
(B_Typ
))
5137 or else (Is_Fixed_Point_Type
(B_Typ
)
5138 and then (Is_Integer_Or_Universal
(L
)
5140 Is_Integer_Or_Universal
(R
))))
5141 and then Nkind_In
(N
, N_Op_Multiply
, N_Op_Divide
)
5143 if TL
= Universal_Integer
or else TR
= Universal_Integer
then
5144 Check_For_Visible_Operator
(N
, B_Typ
);
5147 -- If context is a fixed type and one operand is integer, the other
5148 -- is resolved with the type of the context.
5150 if Is_Fixed_Point_Type
(B_Typ
)
5151 and then (Base_Type
(TL
) = Base_Type
(Standard_Integer
)
5152 or else TL
= Universal_Integer
)
5157 elsif Is_Fixed_Point_Type
(B_Typ
)
5158 and then (Base_Type
(TR
) = Base_Type
(Standard_Integer
)
5159 or else TR
= Universal_Integer
)
5165 Set_Mixed_Mode_Operand
(L
, TR
);
5166 Set_Mixed_Mode_Operand
(R
, TL
);
5169 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
5170 -- multiplying operators from being used when the expected type is
5171 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
5172 -- some cases where the expected type is actually Any_Real;
5173 -- Expected_Type_Is_Any_Real takes care of that case.
5175 if Etype
(N
) = Universal_Fixed
5176 or else Etype
(N
) = Any_Fixed
5178 if B_Typ
= Universal_Fixed
5179 and then not Expected_Type_Is_Any_Real
(N
)
5180 and then not Nkind_In
(Parent
(N
), N_Type_Conversion
,
5181 N_Unchecked_Type_Conversion
)
5183 Error_Msg_N
("type cannot be determined from context!", N
);
5184 Error_Msg_N
("\explicit conversion to result type required", N
);
5186 Set_Etype
(L
, Any_Type
);
5187 Set_Etype
(R
, Any_Type
);
5190 if Ada_Version
= Ada_83
5191 and then Etype
(N
) = Universal_Fixed
5193 Nkind_In
(Parent
(N
), N_Type_Conversion
,
5194 N_Unchecked_Type_Conversion
)
5197 ("(Ada 83) fixed-point operation "
5198 & "needs explicit conversion", N
);
5201 -- The expected type is "any real type" in contexts like
5203 -- type T is delta <universal_fixed-expression> ...
5205 -- in which case we need to set the type to Universal_Real
5206 -- so that static expression evaluation will work properly.
5208 if Expected_Type_Is_Any_Real
(N
) then
5209 Set_Etype
(N
, Universal_Real
);
5211 Set_Etype
(N
, B_Typ
);
5215 elsif Is_Fixed_Point_Type
(B_Typ
)
5216 and then (Is_Integer_Or_Universal
(L
)
5217 or else Nkind
(L
) = N_Real_Literal
5218 or else Nkind
(R
) = N_Real_Literal
5219 or else Is_Integer_Or_Universal
(R
))
5221 Set_Etype
(N
, B_Typ
);
5223 elsif Etype
(N
) = Any_Fixed
then
5225 -- If no previous errors, this is only possible if one operand is
5226 -- overloaded and the context is universal. Resolve as such.
5228 Set_Etype
(N
, B_Typ
);
5232 if (TL
= Universal_Integer
or else TL
= Universal_Real
)
5234 (TR
= Universal_Integer
or else TR
= Universal_Real
)
5236 Check_For_Visible_Operator
(N
, B_Typ
);
5239 -- If the context is Universal_Fixed and the operands are also
5240 -- universal fixed, this is an error, unless there is only one
5241 -- applicable fixed_point type (usually Duration).
5243 if B_Typ
= Universal_Fixed
and then Etype
(L
) = Universal_Fixed
then
5244 T
:= Unique_Fixed_Point_Type
(N
);
5246 if T
= Any_Type
then
5259 -- If one of the arguments was resolved to a non-universal type.
5260 -- label the result of the operation itself with the same type.
5261 -- Do the same for the universal argument, if any.
5263 T
:= Intersect_Types
(L
, R
);
5264 Set_Etype
(N
, Base_Type
(T
));
5265 Set_Operand_Type
(L
);
5266 Set_Operand_Type
(R
);
5269 Generate_Operator_Reference
(N
, Typ
);
5270 Analyze_Dimension
(N
);
5271 Eval_Arithmetic_Op
(N
);
5273 -- In SPARK, a multiplication or division with operands of fixed point
5274 -- types must be qualified or explicitly converted to identify the
5277 if (Is_Fixed_Point_Type
(Etype
(L
))
5278 or else Is_Fixed_Point_Type
(Etype
(R
)))
5279 and then Nkind_In
(N
, N_Op_Multiply
, N_Op_Divide
)
5281 not Nkind_In
(Parent
(N
), N_Qualified_Expression
, N_Type_Conversion
)
5283 Check_SPARK_05_Restriction
5284 ("operation should be qualified or explicitly converted", N
);
5287 -- Set overflow and division checking bit
5289 if Nkind
(N
) in N_Op
then
5290 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
5291 Enable_Overflow_Check
(N
);
5294 -- Give warning if explicit division by zero
5296 if Nkind_In
(N
, N_Op_Divide
, N_Op_Rem
, N_Op_Mod
)
5297 and then not Division_Checks_Suppressed
(Etype
(N
))
5299 Rop
:= Right_Opnd
(N
);
5301 if Compile_Time_Known_Value
(Rop
)
5302 and then ((Is_Integer_Type
(Etype
(Rop
))
5303 and then Expr_Value
(Rop
) = Uint_0
)
5305 (Is_Real_Type
(Etype
(Rop
))
5306 and then Expr_Value_R
(Rop
) = Ureal_0
))
5308 -- Specialize the warning message according to the operation.
5309 -- The following warnings are for the case
5314 -- For division, we have two cases, for float division
5315 -- of an unconstrained float type, on a machine where
5316 -- Machine_Overflows is false, we don't get an exception
5317 -- at run-time, but rather an infinity or Nan. The Nan
5318 -- case is pretty obscure, so just warn about infinities.
5320 if Is_Floating_Point_Type
(Typ
)
5321 and then not Is_Constrained
(Typ
)
5322 and then not Machine_Overflows_On_Target
5325 ("float division by zero, may generate "
5326 & "'+'/'- infinity??", Right_Opnd
(N
));
5328 -- For all other cases, we get a Constraint_Error
5331 Apply_Compile_Time_Constraint_Error
5332 (N
, "division by zero??", CE_Divide_By_Zero
,
5333 Loc
=> Sloc
(Right_Opnd
(N
)));
5337 Apply_Compile_Time_Constraint_Error
5338 (N
, "rem with zero divisor??", CE_Divide_By_Zero
,
5339 Loc
=> Sloc
(Right_Opnd
(N
)));
5342 Apply_Compile_Time_Constraint_Error
5343 (N
, "mod with zero divisor??", CE_Divide_By_Zero
,
5344 Loc
=> Sloc
(Right_Opnd
(N
)));
5346 -- Division by zero can only happen with division, rem,
5347 -- and mod operations.
5350 raise Program_Error
;
5353 -- Otherwise just set the flag to check at run time
5356 Activate_Division_Check
(N
);
5360 -- If Restriction No_Implicit_Conditionals is active, then it is
5361 -- violated if either operand can be negative for mod, or for rem
5362 -- if both operands can be negative.
5364 if Restriction_Check_Required
(No_Implicit_Conditionals
)
5365 and then Nkind_In
(N
, N_Op_Rem
, N_Op_Mod
)
5374 -- Set if corresponding operand might be negative
5378 (Left_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
5379 LNeg
:= (not OK
) or else Lo
< 0;
5382 (Right_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
5383 RNeg
:= (not OK
) or else Lo
< 0;
5385 -- Check if we will be generating conditionals. There are two
5386 -- cases where that can happen, first for REM, the only case
5387 -- is largest negative integer mod -1, where the division can
5388 -- overflow, but we still have to give the right result. The
5389 -- front end generates a test for this annoying case. Here we
5390 -- just test if both operands can be negative (that's what the
5391 -- expander does, so we match its logic here).
5393 -- The second case is mod where either operand can be negative.
5394 -- In this case, the back end has to generate additional tests.
5396 if (Nkind
(N
) = N_Op_Rem
and then (LNeg
and RNeg
))
5398 (Nkind
(N
) = N_Op_Mod
and then (LNeg
or RNeg
))
5400 Check_Restriction
(No_Implicit_Conditionals
, N
);
5406 Check_Unset_Reference
(L
);
5407 Check_Unset_Reference
(R
);
5408 Check_Function_Writable_Actuals
(N
);
5409 end Resolve_Arithmetic_Op
;
5415 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
5416 function Same_Or_Aliased_Subprograms
5418 E
: Entity_Id
) return Boolean;
5419 -- Returns True if the subprogram entity S is the same as E or else
5420 -- S is an alias of E.
5422 ---------------------------------
5423 -- Same_Or_Aliased_Subprograms --
5424 ---------------------------------
5426 function Same_Or_Aliased_Subprograms
5428 E
: Entity_Id
) return Boolean
5430 Subp_Alias
: constant Entity_Id
:= Alias
(S
);
5432 return S
= E
or else (Present
(Subp_Alias
) and then Subp_Alias
= E
);
5433 end Same_Or_Aliased_Subprograms
;
5437 Loc
: constant Source_Ptr
:= Sloc
(N
);
5438 Subp
: constant Node_Id
:= Name
(N
);
5439 Body_Id
: Entity_Id
;
5449 -- Start of processing for Resolve_Call
5452 -- The context imposes a unique interpretation with type Typ on a
5453 -- procedure or function call. Find the entity of the subprogram that
5454 -- yields the expected type, and propagate the corresponding formal
5455 -- constraints on the actuals. The caller has established that an
5456 -- interpretation exists, and emitted an error if not unique.
5458 -- First deal with the case of a call to an access-to-subprogram,
5459 -- dereference made explicit in Analyze_Call.
5461 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
5462 if not Is_Overloaded
(Subp
) then
5463 Nam
:= Etype
(Subp
);
5466 -- Find the interpretation whose type (a subprogram type) has a
5467 -- return type that is compatible with the context. Analysis of
5468 -- the node has established that one exists.
5472 Get_First_Interp
(Subp
, I
, It
);
5473 while Present
(It
.Typ
) loop
5474 if Covers
(Typ
, Etype
(It
.Typ
)) then
5479 Get_Next_Interp
(I
, It
);
5483 raise Program_Error
;
5487 -- If the prefix is not an entity, then resolve it
5489 if not Is_Entity_Name
(Subp
) then
5490 Resolve
(Subp
, Nam
);
5493 -- For an indirect call, we always invalidate checks, since we do not
5494 -- know whether the subprogram is local or global. Yes we could do
5495 -- better here, e.g. by knowing that there are no local subprograms,
5496 -- but it does not seem worth the effort. Similarly, we kill all
5497 -- knowledge of current constant values.
5499 Kill_Current_Values
;
5501 -- If this is a procedure call which is really an entry call, do
5502 -- the conversion of the procedure call to an entry call. Protected
5503 -- operations use the same circuitry because the name in the call
5504 -- can be an arbitrary expression with special resolution rules.
5506 elsif Nkind_In
(Subp
, N_Selected_Component
, N_Indexed_Component
)
5507 or else (Is_Entity_Name
(Subp
)
5508 and then Ekind
(Entity
(Subp
)) = E_Entry
)
5510 Resolve_Entry_Call
(N
, Typ
);
5511 Check_Elab_Call
(N
);
5513 -- Kill checks and constant values, as above for indirect case
5514 -- Who knows what happens when another task is activated?
5516 Kill_Current_Values
;
5519 -- Normal subprogram call with name established in Resolve
5521 elsif not (Is_Type
(Entity
(Subp
))) then
5522 Nam
:= Entity
(Subp
);
5523 Set_Entity_With_Checks
(Subp
, Nam
);
5525 -- Otherwise we must have the case of an overloaded call
5528 pragma Assert
(Is_Overloaded
(Subp
));
5530 -- Initialize Nam to prevent warning (we know it will be assigned
5531 -- in the loop below, but the compiler does not know that).
5535 Get_First_Interp
(Subp
, I
, It
);
5536 while Present
(It
.Typ
) loop
5537 if Covers
(Typ
, It
.Typ
) then
5539 Set_Entity_With_Checks
(Subp
, Nam
);
5543 Get_Next_Interp
(I
, It
);
5547 if Is_Access_Subprogram_Type
(Base_Type
(Etype
(Nam
)))
5548 and then not Is_Access_Subprogram_Type
(Base_Type
(Typ
))
5549 and then Nkind
(Subp
) /= N_Explicit_Dereference
5550 and then Present
(Parameter_Associations
(N
))
5552 -- The prefix is a parameterless function call that returns an access
5553 -- to subprogram. If parameters are present in the current call, add
5554 -- add an explicit dereference. We use the base type here because
5555 -- within an instance these may be subtypes.
5557 -- The dereference is added either in Analyze_Call or here. Should
5558 -- be consolidated ???
5560 Set_Is_Overloaded
(Subp
, False);
5561 Set_Etype
(Subp
, Etype
(Nam
));
5562 Insert_Explicit_Dereference
(Subp
);
5563 Nam
:= Designated_Type
(Etype
(Nam
));
5564 Resolve
(Subp
, Nam
);
5567 -- Check that a call to Current_Task does not occur in an entry body
5569 if Is_RTE
(Nam
, RE_Current_Task
) then
5578 -- Exclude calls that occur within the default of a formal
5579 -- parameter of the entry, since those are evaluated outside
5582 exit when No
(P
) or else Nkind
(P
) = N_Parameter_Specification
;
5584 if Nkind
(P
) = N_Entry_Body
5585 or else (Nkind
(P
) = N_Subprogram_Body
5586 and then Is_Entry_Barrier_Function
(P
))
5589 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5591 ("& should not be used in entry body (RM C.7(17))<<",
5593 Error_Msg_NE
("\Program_Error [<<", N
, Nam
);
5595 Make_Raise_Program_Error
(Loc
,
5596 Reason
=> PE_Current_Task_In_Entry_Body
));
5597 Set_Etype
(N
, Rtype
);
5604 -- Check that a procedure call does not occur in the context of the
5605 -- entry call statement of a conditional or timed entry call. Note that
5606 -- the case of a call to a subprogram renaming of an entry will also be
5607 -- rejected. The test for N not being an N_Entry_Call_Statement is
5608 -- defensive, covering the possibility that the processing of entry
5609 -- calls might reach this point due to later modifications of the code
5612 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
5613 and then Nkind
(N
) /= N_Entry_Call_Statement
5614 and then Entry_Call_Statement
(Parent
(N
)) = N
5616 if Ada_Version
< Ada_2005
then
5617 Error_Msg_N
("entry call required in select statement", N
);
5619 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5620 -- for a procedure_or_entry_call, the procedure_name or
5621 -- procedure_prefix of the procedure_call_statement shall denote
5622 -- an entry renamed by a procedure, or (a view of) a primitive
5623 -- subprogram of a limited interface whose first parameter is
5624 -- a controlling parameter.
5626 elsif Nkind
(N
) = N_Procedure_Call_Statement
5627 and then not Is_Renamed_Entry
(Nam
)
5628 and then not Is_Controlling_Limited_Procedure
(Nam
)
5631 ("entry call or dispatching primitive of interface required", N
);
5635 -- If the SPARK_05 restriction is active, we are not allowed
5636 -- to have a call to a subprogram before we see its completion.
5638 if not Has_Completion
(Nam
)
5639 and then Restriction_Check_Required
(SPARK_05
)
5641 -- Don't flag strange internal calls
5643 and then Comes_From_Source
(N
)
5644 and then Comes_From_Source
(Nam
)
5646 -- Only flag calls in extended main source
5648 and then In_Extended_Main_Source_Unit
(Nam
)
5649 and then In_Extended_Main_Source_Unit
(N
)
5651 -- Exclude enumeration literals from this processing
5653 and then Ekind
(Nam
) /= E_Enumeration_Literal
5655 Check_SPARK_05_Restriction
5656 ("call to subprogram cannot appear before its body", N
);
5659 -- Check that this is not a call to a protected procedure or entry from
5660 -- within a protected function.
5662 Check_Internal_Protected_Use
(N
, Nam
);
5664 -- Freeze the subprogram name if not in a spec-expression. Note that
5665 -- we freeze procedure calls as well as function calls. Procedure calls
5666 -- are not frozen according to the rules (RM 13.14(14)) because it is
5667 -- impossible to have a procedure call to a non-frozen procedure in
5668 -- pure Ada, but in the code that we generate in the expander, this
5669 -- rule needs extending because we can generate procedure calls that
5672 -- In Ada 2012, expression functions may be called within pre/post
5673 -- conditions of subsequent functions or expression functions. Such
5674 -- calls do not freeze when they appear within generated bodies,
5675 -- (including the body of another expression function) which would
5676 -- place the freeze node in the wrong scope. An expression function
5677 -- is frozen in the usual fashion, by the appearance of a real body,
5678 -- or at the end of a declarative part.
5680 if Is_Entity_Name
(Subp
) and then not In_Spec_Expression
5681 and then not Is_Expression_Function
(Current_Scope
)
5683 (not Is_Expression_Function
(Entity
(Subp
))
5684 or else Scope
(Entity
(Subp
)) = Current_Scope
)
5686 Freeze_Expression
(Subp
);
5689 -- For a predefined operator, the type of the result is the type imposed
5690 -- by context, except for a predefined operation on universal fixed.
5691 -- Otherwise The type of the call is the type returned by the subprogram
5694 if Is_Predefined_Op
(Nam
) then
5695 if Etype
(N
) /= Universal_Fixed
then
5699 -- If the subprogram returns an array type, and the context requires the
5700 -- component type of that array type, the node is really an indexing of
5701 -- the parameterless call. Resolve as such. A pathological case occurs
5702 -- when the type of the component is an access to the array type. In
5703 -- this case the call is truly ambiguous.
5705 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
5707 ((Is_Array_Type
(Etype
(Nam
))
5708 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
5710 (Is_Access_Type
(Etype
(Nam
))
5711 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
5713 Covers
(Typ
, Component_Type
(Designated_Type
(Etype
(Nam
))))))
5716 Index_Node
: Node_Id
;
5718 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
5721 if Is_Access_Type
(Ret_Type
)
5722 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
5725 ("cannot disambiguate function call and indexing", N
);
5727 New_Subp
:= Relocate_Node
(Subp
);
5729 -- The called entity may be an explicit dereference, in which
5730 -- case there is no entity to set.
5732 if Nkind
(New_Subp
) /= N_Explicit_Dereference
then
5733 Set_Entity
(Subp
, Nam
);
5736 if (Is_Array_Type
(Ret_Type
)
5737 and then Component_Type
(Ret_Type
) /= Any_Type
)
5739 (Is_Access_Type
(Ret_Type
)
5741 Component_Type
(Designated_Type
(Ret_Type
)) /= Any_Type
)
5743 if Needs_No_Actuals
(Nam
) then
5745 -- Indexed call to a parameterless function
5748 Make_Indexed_Component
(Loc
,
5750 Make_Function_Call
(Loc
, Name
=> New_Subp
),
5751 Expressions
=> Parameter_Associations
(N
));
5753 -- An Ada 2005 prefixed call to a primitive operation
5754 -- whose first parameter is the prefix. This prefix was
5755 -- prepended to the parameter list, which is actually a
5756 -- list of indexes. Remove the prefix in order to build
5757 -- the proper indexed component.
5760 Make_Indexed_Component
(Loc
,
5762 Make_Function_Call
(Loc
,
5764 Parameter_Associations
=>
5766 (Remove_Head
(Parameter_Associations
(N
)))),
5767 Expressions
=> Parameter_Associations
(N
));
5770 -- Preserve the parenthesis count of the node
5772 Set_Paren_Count
(Index_Node
, Paren_Count
(N
));
5774 -- Since we are correcting a node classification error made
5775 -- by the parser, we call Replace rather than Rewrite.
5777 Replace
(N
, Index_Node
);
5779 Set_Etype
(Prefix
(N
), Ret_Type
);
5781 Resolve_Indexed_Component
(N
, Typ
);
5782 Check_Elab_Call
(Prefix
(N
));
5790 Set_Etype
(N
, Etype
(Nam
));
5793 -- In the case where the call is to an overloaded subprogram, Analyze
5794 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5795 -- such a case Normalize_Actuals needs to be called once more to order
5796 -- the actuals correctly. Otherwise the call will have the ordering
5797 -- given by the last overloaded subprogram whether this is the correct
5798 -- one being called or not.
5800 if Is_Overloaded
(Subp
) then
5801 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
5802 pragma Assert
(Norm_OK
);
5805 -- In any case, call is fully resolved now. Reset Overload flag, to
5806 -- prevent subsequent overload resolution if node is analyzed again
5808 Set_Is_Overloaded
(Subp
, False);
5809 Set_Is_Overloaded
(N
, False);
5811 -- If we are calling the current subprogram from immediately within its
5812 -- body, then that is the case where we can sometimes detect cases of
5813 -- infinite recursion statically. Do not try this in case restriction
5814 -- No_Recursion is in effect anyway, and do it only for source calls.
5816 if Comes_From_Source
(N
) then
5817 Scop
:= Current_Scope
;
5819 -- Check violation of SPARK_05 restriction which does not permit
5820 -- a subprogram body to contain a call to the subprogram directly.
5822 if Restriction_Check_Required
(SPARK_05
)
5823 and then Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5825 Check_SPARK_05_Restriction
5826 ("subprogram may not contain direct call to itself", N
);
5829 -- Issue warning for possible infinite recursion in the absence
5830 -- of the No_Recursion restriction.
5832 if Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5833 and then not Restriction_Active
(No_Recursion
)
5834 and then Check_Infinite_Recursion
(N
)
5836 -- Here we detected and flagged an infinite recursion, so we do
5837 -- not need to test the case below for further warnings. Also we
5838 -- are all done if we now have a raise SE node.
5840 if Nkind
(N
) = N_Raise_Storage_Error
then
5844 -- If call is to immediately containing subprogram, then check for
5845 -- the case of a possible run-time detectable infinite recursion.
5848 Scope_Loop
: while Scop
/= Standard_Standard
loop
5849 if Same_Or_Aliased_Subprograms
(Nam
, Scop
) then
5851 -- Although in general case, recursion is not statically
5852 -- checkable, the case of calling an immediately containing
5853 -- subprogram is easy to catch.
5855 Check_Restriction
(No_Recursion
, N
);
5857 -- If the recursive call is to a parameterless subprogram,
5858 -- then even if we can't statically detect infinite
5859 -- recursion, this is pretty suspicious, and we output a
5860 -- warning. Furthermore, we will try later to detect some
5861 -- cases here at run time by expanding checking code (see
5862 -- Detect_Infinite_Recursion in package Exp_Ch6).
5864 -- If the recursive call is within a handler, do not emit a
5865 -- warning, because this is a common idiom: loop until input
5866 -- is correct, catch illegal input in handler and restart.
5868 if No
(First_Formal
(Nam
))
5869 and then Etype
(Nam
) = Standard_Void_Type
5870 and then not Error_Posted
(N
)
5871 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
5873 -- For the case of a procedure call. We give the message
5874 -- only if the call is the first statement in a sequence
5875 -- of statements, or if all previous statements are
5876 -- simple assignments. This is simply a heuristic to
5877 -- decrease false positives, without losing too many good
5878 -- warnings. The idea is that these previous statements
5879 -- may affect global variables the procedure depends on.
5880 -- We also exclude raise statements, that may arise from
5881 -- constraint checks and are probably unrelated to the
5882 -- intended control flow.
5884 if Nkind
(N
) = N_Procedure_Call_Statement
5885 and then Is_List_Member
(N
)
5891 while Present
(P
) loop
5892 if not Nkind_In
(P
, N_Assignment_Statement
,
5893 N_Raise_Constraint_Error
)
5903 -- Do not give warning if we are in a conditional context
5906 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
5908 if (K
= N_Loop_Statement
5909 and then Present
(Iteration_Scheme
(Parent
(N
))))
5910 or else K
= N_If_Statement
5911 or else K
= N_Elsif_Part
5912 or else K
= N_Case_Statement_Alternative
5918 -- Here warning is to be issued
5920 Set_Has_Recursive_Call
(Nam
);
5921 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5922 Error_Msg_N
("possible infinite recursion<<!", N
);
5923 Error_Msg_N
("\Storage_Error ]<<!", N
);
5929 Scop
:= Scope
(Scop
);
5930 end loop Scope_Loop
;
5934 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5936 Check_Obsolescent_2005_Entity
(Nam
, Subp
);
5938 -- If subprogram name is a predefined operator, it was given in
5939 -- functional notation. Replace call node with operator node, so
5940 -- that actuals can be resolved appropriately.
5942 if Is_Predefined_Op
(Nam
) or else Ekind
(Nam
) = E_Operator
then
5943 Make_Call_Into_Operator
(N
, Typ
, Entity
(Name
(N
)));
5946 elsif Present
(Alias
(Nam
))
5947 and then Is_Predefined_Op
(Alias
(Nam
))
5949 Resolve_Actuals
(N
, Nam
);
5950 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
5954 -- Create a transient scope if the resulting type requires it
5956 -- There are several notable exceptions:
5958 -- a) In init procs, the transient scope overhead is not needed, and is
5959 -- even incorrect when the call is a nested initialization call for a
5960 -- component whose expansion may generate adjust calls. However, if the
5961 -- call is some other procedure call within an initialization procedure
5962 -- (for example a call to Create_Task in the init_proc of the task
5963 -- run-time record) a transient scope must be created around this call.
5965 -- b) Enumeration literal pseudo-calls need no transient scope
5967 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5968 -- functions) do not use the secondary stack even though the return
5969 -- type may be unconstrained.
5971 -- d) Calls to a build-in-place function, since such functions may
5972 -- allocate their result directly in a target object, and cases where
5973 -- the result does get allocated in the secondary stack are checked for
5974 -- within the specialized Exp_Ch6 procedures for expanding those
5975 -- build-in-place calls.
5977 -- e) If the subprogram is marked Inline_Always, then even if it returns
5978 -- an unconstrained type the call does not require use of the secondary
5979 -- stack. However, inlining will only take place if the body to inline
5980 -- is already present. It may not be available if e.g. the subprogram is
5981 -- declared in a child instance.
5983 -- If this is an initialization call for a type whose construction
5984 -- uses the secondary stack, and it is not a nested call to initialize
5985 -- a component, we do need to create a transient scope for it. We
5986 -- check for this by traversing the type in Check_Initialization_Call.
5989 and then Has_Pragma_Inline
(Nam
)
5990 and then Nkind
(Unit_Declaration_Node
(Nam
)) = N_Subprogram_Declaration
5991 and then Present
(Body_To_Inline
(Unit_Declaration_Node
(Nam
)))
5995 elsif Ekind
(Nam
) = E_Enumeration_Literal
5996 or else Is_Build_In_Place_Function
(Nam
)
5997 or else Is_Intrinsic_Subprogram
(Nam
)
6001 elsif Expander_Active
6002 and then Is_Type
(Etype
(Nam
))
6003 and then Requires_Transient_Scope
(Etype
(Nam
))
6005 (not Within_Init_Proc
6007 (not Is_Init_Proc
(Nam
) and then Ekind
(Nam
) /= E_Function
))
6009 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
6011 -- If the call appears within the bounds of a loop, it will
6012 -- be rewritten and reanalyzed, nothing left to do here.
6014 if Nkind
(N
) /= N_Function_Call
then
6018 elsif Is_Init_Proc
(Nam
)
6019 and then not Within_Init_Proc
6021 Check_Initialization_Call
(N
, Nam
);
6024 -- A protected function cannot be called within the definition of the
6025 -- enclosing protected type, unless it is part of a pre/postcondition
6026 -- on another protected operation.
6028 if Is_Protected_Type
(Scope
(Nam
))
6029 and then In_Open_Scopes
(Scope
(Nam
))
6030 and then not Has_Completion
(Scope
(Nam
))
6031 and then not In_Spec_Expression
6034 ("& cannot be called before end of protected definition", N
, Nam
);
6037 -- Propagate interpretation to actuals, and add default expressions
6040 if Present
(First_Formal
(Nam
)) then
6041 Resolve_Actuals
(N
, Nam
);
6043 -- Overloaded literals are rewritten as function calls, for purpose of
6044 -- resolution. After resolution, we can replace the call with the
6047 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
6048 Copy_Node
(Subp
, N
);
6049 Resolve_Entity_Name
(N
, Typ
);
6051 -- Avoid validation, since it is a static function call
6053 Generate_Reference
(Nam
, Subp
);
6057 -- If the subprogram is not global, then kill all saved values and
6058 -- checks. This is a bit conservative, since in many cases we could do
6059 -- better, but it is not worth the effort. Similarly, we kill constant
6060 -- values. However we do not need to do this for internal entities
6061 -- (unless they are inherited user-defined subprograms), since they
6062 -- are not in the business of molesting local values.
6064 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
6065 -- kill all checks and values for calls to global subprograms. This
6066 -- takes care of the case where an access to a local subprogram is
6067 -- taken, and could be passed directly or indirectly and then called
6068 -- from almost any context.
6070 -- Note: we do not do this step till after resolving the actuals. That
6071 -- way we still take advantage of the current value information while
6072 -- scanning the actuals.
6074 -- We suppress killing values if we are processing the nodes associated
6075 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
6076 -- type kills all the values as part of analyzing the code that
6077 -- initializes the dispatch tables.
6079 if Inside_Freezing_Actions
= 0
6080 and then (not Is_Library_Level_Entity
(Nam
)
6081 or else Suppress_Value_Tracking_On_Call
6082 (Nearest_Dynamic_Scope
(Current_Scope
)))
6083 and then (Comes_From_Source
(Nam
)
6084 or else (Present
(Alias
(Nam
))
6085 and then Comes_From_Source
(Alias
(Nam
))))
6087 Kill_Current_Values
;
6090 -- If we are warning about unread OUT parameters, this is the place to
6091 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
6092 -- after the above call to Kill_Current_Values (since that call clears
6093 -- the Last_Assignment field of all local variables).
6095 if (Warn_On_Modified_Unread
or Warn_On_All_Unread_Out_Parameters
)
6096 and then Comes_From_Source
(N
)
6097 and then In_Extended_Main_Source_Unit
(N
)
6104 F
:= First_Formal
(Nam
);
6105 A
:= First_Actual
(N
);
6106 while Present
(F
) and then Present
(A
) loop
6107 if Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
)
6108 and then Warn_On_Modified_As_Out_Parameter
(F
)
6109 and then Is_Entity_Name
(A
)
6110 and then Present
(Entity
(A
))
6111 and then Comes_From_Source
(N
)
6112 and then Safe_To_Capture_Value
(N
, Entity
(A
))
6114 Set_Last_Assignment
(Entity
(A
), A
);
6123 -- If the subprogram is a primitive operation, check whether or not
6124 -- it is a correct dispatching call.
6126 if Is_Overloadable
(Nam
)
6127 and then Is_Dispatching_Operation
(Nam
)
6129 Check_Dispatching_Call
(N
);
6131 elsif Ekind
(Nam
) /= E_Subprogram_Type
6132 and then Is_Abstract_Subprogram
(Nam
)
6133 and then not In_Instance
6135 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Nam
);
6138 -- If this is a dispatching call, generate the appropriate reference,
6139 -- for better source navigation in GPS.
6141 if Is_Overloadable
(Nam
)
6142 and then Present
(Controlling_Argument
(N
))
6144 Generate_Reference
(Nam
, Subp
, 'R');
6146 -- Normal case, not a dispatching call: generate a call reference
6149 Generate_Reference
(Nam
, Subp
, 's');
6152 if Is_Intrinsic_Subprogram
(Nam
) then
6153 Check_Intrinsic_Call
(N
);
6156 -- Check for violation of restriction No_Specific_Termination_Handlers
6157 -- and warn on a potentially blocking call to Abort_Task.
6159 if Restriction_Check_Required
(No_Specific_Termination_Handlers
)
6160 and then (Is_RTE
(Nam
, RE_Set_Specific_Handler
)
6162 Is_RTE
(Nam
, RE_Specific_Handler
))
6164 Check_Restriction
(No_Specific_Termination_Handlers
, N
);
6166 elsif Is_RTE
(Nam
, RE_Abort_Task
) then
6167 Check_Potentially_Blocking_Operation
(N
);
6170 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
6171 -- timing event violates restriction No_Relative_Delay (AI-0211). We
6172 -- need to check the second argument to determine whether it is an
6173 -- absolute or relative timing event.
6175 if Restriction_Check_Required
(No_Relative_Delay
)
6176 and then Is_RTE
(Nam
, RE_Set_Handler
)
6177 and then Is_RTE
(Etype
(Next_Actual
(First_Actual
(N
))), RE_Time_Span
)
6179 Check_Restriction
(No_Relative_Delay
, N
);
6182 -- Issue an error for a call to an eliminated subprogram. This routine
6183 -- will not perform the check if the call appears within a default
6186 Check_For_Eliminated_Subprogram
(Subp
, Nam
);
6188 -- In formal mode, the primitive operations of a tagged type or type
6189 -- extension do not include functions that return the tagged type.
6191 if Nkind
(N
) = N_Function_Call
6192 and then Is_Tagged_Type
(Etype
(N
))
6193 and then Is_Entity_Name
(Name
(N
))
6194 and then Is_Inherited_Operation_For_Type
(Entity
(Name
(N
)), Etype
(N
))
6196 Check_SPARK_05_Restriction
("function not inherited", N
);
6199 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
6200 -- class-wide and the call dispatches on result in a context that does
6201 -- not provide a tag, the call raises Program_Error.
6203 if Nkind
(N
) = N_Function_Call
6204 and then In_Instance
6205 and then Is_Generic_Actual_Type
(Typ
)
6206 and then Is_Class_Wide_Type
(Typ
)
6207 and then Has_Controlling_Result
(Nam
)
6208 and then Nkind
(Parent
(N
)) = N_Object_Declaration
6210 -- Verify that none of the formals are controlling
6213 Call_OK
: Boolean := False;
6217 F
:= First_Formal
(Nam
);
6218 while Present
(F
) loop
6219 if Is_Controlling_Formal
(F
) then
6228 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6229 Error_Msg_N
("!cannot determine tag of result<<", N
);
6230 Error_Msg_N
("\Program_Error [<<!", N
);
6232 Make_Raise_Program_Error
(Sloc
(N
),
6233 Reason
=> PE_Explicit_Raise
));
6238 -- Check for calling a function with OUT or IN OUT parameter when the
6239 -- calling context (us right now) is not Ada 2012, so does not allow
6240 -- OUT or IN OUT parameters in function calls.
6242 if Ada_Version
< Ada_2012
6243 and then Ekind
(Nam
) = E_Function
6244 and then Has_Out_Or_In_Out_Parameter
(Nam
)
6246 Error_Msg_NE
("& has at least one OUT or `IN OUT` parameter", N
, Nam
);
6247 Error_Msg_N
("\call to this function only allowed in Ada 2012", N
);
6250 -- Check the dimensions of the actuals in the call. For function calls,
6251 -- propagate the dimensions from the returned type to N.
6253 Analyze_Dimension_Call
(N
, Nam
);
6255 -- All done, evaluate call and deal with elaboration issues
6258 Check_Elab_Call
(N
);
6260 -- In GNATprove mode, expansion is disabled, but we want to inline some
6261 -- subprograms to facilitate formal verification. Indirect calls through
6262 -- a subprogram type or within a generic cannot be inlined. Inlining is
6263 -- performed only for calls subject to SPARK_Mode on.
6266 and then SPARK_Mode
= On
6267 and then Is_Overloadable
(Nam
)
6268 and then not Inside_A_Generic
6270 Nam_UA
:= Ultimate_Alias
(Nam
);
6271 Nam_Decl
:= Unit_Declaration_Node
(Nam_UA
);
6273 if Nkind
(Nam_Decl
) = N_Subprogram_Declaration
then
6274 Body_Id
:= Corresponding_Body
(Nam_Decl
);
6276 -- Nothing to do if the subprogram is not eligible for inlining in
6279 if not Is_Inlined_Always
(Nam_UA
)
6280 or else not Can_Be_Inlined_In_GNATprove_Mode
(Nam_UA
, Body_Id
)
6284 -- Calls cannot be inlined inside assertions, as GNATprove treats
6285 -- assertions as logic expressions.
6287 elsif In_Assertion_Expr
/= 0 then
6288 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6289 Error_Msg_N
("\call appears in assertion expression", N
);
6290 Set_Is_Inlined_Always
(Nam_UA
, False);
6292 -- Calls cannot be inlined inside default expressions
6294 elsif In_Default_Expr
then
6295 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6296 Error_Msg_N
("\call appears in default expression", N
);
6297 Set_Is_Inlined_Always
(Nam_UA
, False);
6299 -- Inlining should not be performed during pre-analysis
6301 elsif Full_Analysis
then
6303 -- With the one-pass inlining technique, a call cannot be
6304 -- inlined if the corresponding body has not been seen yet.
6306 if No
(Body_Id
) then
6308 ("?no contextual analysis of & (body not seen yet)",
6310 Set_Is_Inlined_Always
(Nam_UA
, False);
6312 -- Nothing to do if there is no body to inline, indicating that
6313 -- the subprogram is not suitable for inlining in GNATprove
6316 elsif No
(Body_To_Inline
(Nam_Decl
)) then
6319 -- Calls cannot be inlined inside potentially unevaluated
6320 -- expressions, as this would create complex actions inside
6321 -- expressions, that are not handled by GNATprove.
6323 elsif Is_Potentially_Unevaluated
(N
) then
6324 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6326 ("\call appears in potentially unevaluated context", N
);
6327 Set_Is_Inlined_Always
(Nam_UA
, False);
6329 -- Otherwise, inline the call
6332 Expand_Inlined_Call
(N
, Nam_UA
, Nam
);
6338 Warn_On_Overlapping_Actuals
(Nam
, N
);
6341 -----------------------------
6342 -- Resolve_Case_Expression --
6343 -----------------------------
6345 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
6349 Alt
:= First
(Alternatives
(N
));
6350 while Present
(Alt
) loop
6351 Resolve
(Expression
(Alt
), Typ
);
6356 Eval_Case_Expression
(N
);
6357 end Resolve_Case_Expression
;
6359 -------------------------------
6360 -- Resolve_Character_Literal --
6361 -------------------------------
6363 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
6364 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
6368 -- Verify that the character does belong to the type of the context
6370 Set_Etype
(N
, B_Typ
);
6371 Eval_Character_Literal
(N
);
6373 -- Wide_Wide_Character literals must always be defined, since the set
6374 -- of wide wide character literals is complete, i.e. if a character
6375 -- literal is accepted by the parser, then it is OK for wide wide
6376 -- character (out of range character literals are rejected).
6378 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
6381 -- Always accept character literal for type Any_Character, which
6382 -- occurs in error situations and in comparisons of literals, both
6383 -- of which should accept all literals.
6385 elsif B_Typ
= Any_Character
then
6388 -- For Standard.Character or a type derived from it, check that the
6389 -- literal is in range.
6391 elsif Root_Type
(B_Typ
) = Standard_Character
then
6392 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
6396 -- For Standard.Wide_Character or a type derived from it, check that the
6397 -- literal is in range.
6399 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
6400 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
6404 -- For Standard.Wide_Wide_Character or a type derived from it, we
6405 -- know the literal is in range, since the parser checked.
6407 elsif Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
6410 -- If the entity is already set, this has already been resolved in a
6411 -- generic context, or comes from expansion. Nothing else to do.
6413 elsif Present
(Entity
(N
)) then
6416 -- Otherwise we have a user defined character type, and we can use the
6417 -- standard visibility mechanisms to locate the referenced entity.
6420 C
:= Current_Entity
(N
);
6421 while Present
(C
) loop
6422 if Etype
(C
) = B_Typ
then
6423 Set_Entity_With_Checks
(N
, C
);
6424 Generate_Reference
(C
, N
);
6432 -- If we fall through, then the literal does not match any of the
6433 -- entries of the enumeration type. This isn't just a constraint error
6434 -- situation, it is an illegality (see RM 4.2).
6437 ("character not defined for }", N
, First_Subtype
(B_Typ
));
6438 end Resolve_Character_Literal
;
6440 ---------------------------
6441 -- Resolve_Comparison_Op --
6442 ---------------------------
6444 -- Context requires a boolean type, and plays no role in resolution.
6445 -- Processing identical to that for equality operators. The result type is
6446 -- the base type, which matters when pathological subtypes of booleans with
6447 -- limited ranges are used.
6449 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6450 L
: constant Node_Id
:= Left_Opnd
(N
);
6451 R
: constant Node_Id
:= Right_Opnd
(N
);
6455 -- If this is an intrinsic operation which is not predefined, use the
6456 -- types of its declared arguments to resolve the possibly overloaded
6457 -- operands. Otherwise the operands are unambiguous and specify the
6460 if Scope
(Entity
(N
)) /= Standard_Standard
then
6461 T
:= Etype
(First_Entity
(Entity
(N
)));
6464 T
:= Find_Unique_Type
(L
, R
);
6466 if T
= Any_Fixed
then
6467 T
:= Unique_Fixed_Point_Type
(L
);
6471 Set_Etype
(N
, Base_Type
(Typ
));
6472 Generate_Reference
(T
, N
, ' ');
6474 -- Skip remaining processing if already set to Any_Type
6476 if T
= Any_Type
then
6480 -- Deal with other error cases
6482 if T
= Any_String
or else
6483 T
= Any_Composite
or else
6486 if T
= Any_Character
then
6487 Ambiguous_Character
(L
);
6489 Error_Msg_N
("ambiguous operands for comparison", N
);
6492 Set_Etype
(N
, Any_Type
);
6496 -- Resolve the operands if types OK
6500 Check_Unset_Reference
(L
);
6501 Check_Unset_Reference
(R
);
6502 Generate_Operator_Reference
(N
, T
);
6503 Check_Low_Bound_Tested
(N
);
6505 -- In SPARK, ordering operators <, <=, >, >= are not defined for Boolean
6506 -- types or array types except String.
6508 if Is_Boolean_Type
(T
) then
6509 Check_SPARK_05_Restriction
6510 ("comparison is not defined on Boolean type", N
);
6512 elsif Is_Array_Type
(T
)
6513 and then Base_Type
(T
) /= Standard_String
6515 Check_SPARK_05_Restriction
6516 ("comparison is not defined on array types other than String", N
);
6519 -- Check comparison on unordered enumeration
6521 if Bad_Unordered_Enumeration_Reference
(N
, Etype
(L
)) then
6522 Error_Msg_Sloc
:= Sloc
(Etype
(L
));
6524 ("comparison on unordered enumeration type& declared#?U?",
6528 -- Evaluate the relation (note we do this after the above check since
6529 -- this Eval call may change N to True/False.
6531 Analyze_Dimension
(N
);
6532 Eval_Relational_Op
(N
);
6533 end Resolve_Comparison_Op
;
6535 -----------------------------------------
6536 -- Resolve_Discrete_Subtype_Indication --
6537 -----------------------------------------
6539 procedure Resolve_Discrete_Subtype_Indication
6547 Analyze
(Subtype_Mark
(N
));
6548 S
:= Entity
(Subtype_Mark
(N
));
6550 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
6551 Error_Msg_N
("expect range constraint for discrete type", N
);
6552 Set_Etype
(N
, Any_Type
);
6555 R
:= Range_Expression
(Constraint
(N
));
6563 if Base_Type
(S
) /= Base_Type
(Typ
) then
6565 ("expect subtype of }", N
, First_Subtype
(Typ
));
6567 -- Rewrite the constraint as a range of Typ
6568 -- to allow compilation to proceed further.
6571 Rewrite
(Low_Bound
(R
),
6572 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
6573 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
6574 Attribute_Name
=> Name_First
));
6575 Rewrite
(High_Bound
(R
),
6576 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
6577 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
6578 Attribute_Name
=> Name_First
));
6582 Set_Etype
(N
, Etype
(R
));
6584 -- Additionally, we must check that the bounds are compatible
6585 -- with the given subtype, which might be different from the
6586 -- type of the context.
6588 Apply_Range_Check
(R
, S
);
6590 -- ??? If the above check statically detects a Constraint_Error
6591 -- it replaces the offending bound(s) of the range R with a
6592 -- Constraint_Error node. When the itype which uses these bounds
6593 -- is frozen the resulting call to Duplicate_Subexpr generates
6594 -- a new temporary for the bounds.
6596 -- Unfortunately there are other itypes that are also made depend
6597 -- on these bounds, so when Duplicate_Subexpr is called they get
6598 -- a forward reference to the newly created temporaries and Gigi
6599 -- aborts on such forward references. This is probably sign of a
6600 -- more fundamental problem somewhere else in either the order of
6601 -- itype freezing or the way certain itypes are constructed.
6603 -- To get around this problem we call Remove_Side_Effects right
6604 -- away if either bounds of R are a Constraint_Error.
6607 L
: constant Node_Id
:= Low_Bound
(R
);
6608 H
: constant Node_Id
:= High_Bound
(R
);
6611 if Nkind
(L
) = N_Raise_Constraint_Error
then
6612 Remove_Side_Effects
(L
);
6615 if Nkind
(H
) = N_Raise_Constraint_Error
then
6616 Remove_Side_Effects
(H
);
6620 Check_Unset_Reference
(Low_Bound
(R
));
6621 Check_Unset_Reference
(High_Bound
(R
));
6624 end Resolve_Discrete_Subtype_Indication
;
6626 -------------------------
6627 -- Resolve_Entity_Name --
6628 -------------------------
6630 -- Used to resolve identifiers and expanded names
6632 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
6633 function Appears_In_Check
(Nod
: Node_Id
) return Boolean;
6634 -- Denote whether an arbitrary node Nod appears in a check node
6636 function Is_OK_Volatile_Context
6638 Obj_Ref
: Node_Id
) return Boolean;
6639 -- Determine whether node Context denotes a "non-interfering context"
6640 -- (as defined in SPARK RM 7.1.3(13)) where volatile reference Obj_Ref
6641 -- can safely reside.
6643 ----------------------
6644 -- Appears_In_Check --
6645 ----------------------
6647 function Appears_In_Check
(Nod
: Node_Id
) return Boolean is
6651 -- Climb the parent chain looking for a check node
6654 while Present
(Par
) loop
6655 if Nkind
(Par
) in N_Raise_xxx_Error
then
6658 -- Prevent the search from going too far
6660 elsif Is_Body_Or_Package_Declaration
(Par
) then
6664 Par
:= Parent
(Par
);
6668 end Appears_In_Check
;
6670 ----------------------------
6671 -- Is_OK_Volatile_Context --
6672 ----------------------------
6674 function Is_OK_Volatile_Context
6676 Obj_Ref
: Node_Id
) return Boolean
6679 -- The volatile object appears on either side of an assignment
6681 if Nkind
(Context
) = N_Assignment_Statement
then
6684 -- The volatile object is part of the initialization expression of
6685 -- another object. Ensure that the climb of the parent chain came
6686 -- from the expression side and not from the name side.
6688 elsif Nkind
(Context
) = N_Object_Declaration
6689 and then Present
(Expression
(Context
))
6690 and then Expression
(Context
) = Obj_Ref
6694 -- The volatile object appears as an actual parameter in a call to an
6695 -- instance of Unchecked_Conversion whose result is renamed.
6697 elsif Nkind
(Context
) = N_Function_Call
6698 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
6699 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
6703 -- The volatile object appears as the prefix of a name occurring
6704 -- in a non-interfering context.
6706 elsif Nkind_In
(Context
, N_Attribute_Reference
,
6707 N_Indexed_Component
,
6708 N_Selected_Component
,
6710 and then Prefix
(Context
) = Obj_Ref
6711 and then Is_OK_Volatile_Context
6712 (Context
=> Parent
(Context
),
6717 -- The volatile object appears as the expression of a type conversion
6718 -- occurring in a non-interfering context.
6720 elsif Nkind_In
(Context
, N_Type_Conversion
,
6721 N_Unchecked_Type_Conversion
)
6722 and then Expression
(Context
) = Obj_Ref
6723 and then Is_OK_Volatile_Context
6724 (Context
=> Parent
(Context
),
6729 -- Allow references to volatile objects in various checks. This is
6730 -- not a direct SPARK 2014 requirement.
6732 elsif Appears_In_Check
(Context
) then
6738 end Is_OK_Volatile_Context
;
6742 E
: constant Entity_Id
:= Entity
(N
);
6745 -- Start of processing for Resolve_Entity_Name
6748 -- If garbage from errors, set to Any_Type and return
6750 if No
(E
) and then Total_Errors_Detected
/= 0 then
6751 Set_Etype
(N
, Any_Type
);
6755 -- Replace named numbers by corresponding literals. Note that this is
6756 -- the one case where Resolve_Entity_Name must reset the Etype, since
6757 -- it is currently marked as universal.
6759 if Ekind
(E
) = E_Named_Integer
then
6761 Eval_Named_Integer
(N
);
6763 elsif Ekind
(E
) = E_Named_Real
then
6765 Eval_Named_Real
(N
);
6767 -- For enumeration literals, we need to make sure that a proper style
6768 -- check is done, since such literals are overloaded, and thus we did
6769 -- not do a style check during the first phase of analysis.
6771 elsif Ekind
(E
) = E_Enumeration_Literal
then
6772 Set_Entity_With_Checks
(N
, E
);
6773 Eval_Entity_Name
(N
);
6775 -- Case of subtype name appearing as an operand in expression
6777 elsif Is_Type
(E
) then
6779 -- Allow use of subtype if it is a concurrent type where we are
6780 -- currently inside the body. This will eventually be expanded into a
6781 -- call to Self (for tasks) or _object (for protected objects). Any
6782 -- other use of a subtype is invalid.
6784 if Is_Concurrent_Type
(E
)
6785 and then In_Open_Scopes
(E
)
6789 -- Any other use is an error
6793 ("invalid use of subtype mark in expression or call", N
);
6796 -- Check discriminant use if entity is discriminant in current scope,
6797 -- i.e. discriminant of record or concurrent type currently being
6798 -- analyzed. Uses in corresponding body are unrestricted.
6800 elsif Ekind
(E
) = E_Discriminant
6801 and then Scope
(E
) = Current_Scope
6802 and then not Has_Completion
(Current_Scope
)
6804 Check_Discriminant_Use
(N
);
6806 -- A parameterless generic function cannot appear in a context that
6807 -- requires resolution.
6809 elsif Ekind
(E
) = E_Generic_Function
then
6810 Error_Msg_N
("illegal use of generic function", N
);
6812 elsif Ekind
(E
) = E_Out_Parameter
6813 and then Ada_Version
= Ada_83
6814 and then (Nkind
(Parent
(N
)) in N_Op
6815 or else (Nkind
(Parent
(N
)) = N_Assignment_Statement
6816 and then N
= Expression
(Parent
(N
)))
6817 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
)
6819 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
6821 -- In all other cases, just do the possible static evaluation
6824 -- A deferred constant that appears in an expression must have a
6825 -- completion, unless it has been removed by in-place expansion of
6828 if Ekind
(E
) = E_Constant
6829 and then Comes_From_Source
(E
)
6830 and then No
(Constant_Value
(E
))
6831 and then Is_Frozen
(Etype
(E
))
6832 and then not In_Spec_Expression
6833 and then not Is_Imported
(E
)
6835 if No_Initialization
(Parent
(E
))
6836 or else (Present
(Full_View
(E
))
6837 and then No_Initialization
(Parent
(Full_View
(E
))))
6842 "deferred constant is frozen before completion", N
);
6846 Eval_Entity_Name
(N
);
6851 -- When the entity appears in a parameter association, retrieve the
6852 -- related subprogram call.
6854 if Nkind
(Par
) = N_Parameter_Association
then
6855 Par
:= Parent
(Par
);
6858 -- An effectively volatile object subject to enabled properties
6859 -- Async_Writers or Effective_Reads must appear in a specific context.
6860 -- The following checks are only relevant when SPARK_Mode is on as they
6861 -- are not standard Ada legality rules.
6864 and then Is_Object
(E
)
6865 and then Is_Effectively_Volatile
(E
)
6866 and then Comes_From_Source
(E
)
6868 (Async_Writers_Enabled
(E
) or else Effective_Reads_Enabled
(E
))
6870 -- The effectively volatile objects appears in a "non-interfering
6871 -- context" as defined in SPARK RM 7.1.3(13).
6873 if Is_OK_Volatile_Context
(Par
, N
) then
6876 -- Assume that references to effectively volatile objects that appear
6877 -- as actual parameters in a procedure call are always legal. A full
6878 -- legality check is done when the actuals are resolved.
6880 elsif Nkind
(Par
) = N_Procedure_Call_Statement
then
6883 -- Otherwise the context causes a side effect with respect to the
6884 -- effectively volatile object.
6888 ("volatile object cannot appear in this context "
6889 & "(SPARK RM 7.1.3(13))", N
);
6892 end Resolve_Entity_Name
;
6898 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
6899 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
6907 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
6908 -- If the bounds of the entry family being called depend on task
6909 -- discriminants, build a new index subtype where a discriminant is
6910 -- replaced with the value of the discriminant of the target task.
6911 -- The target task is the prefix of the entry name in the call.
6913 -----------------------
6914 -- Actual_Index_Type --
6915 -----------------------
6917 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
6918 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
6919 Tsk
: constant Entity_Id
:= Scope
(E
);
6920 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
6921 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
6924 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
6925 -- If the bound is given by a discriminant, replace with a reference
6926 -- to the discriminant of the same name in the target task. If the
6927 -- entry name is the target of a requeue statement and the entry is
6928 -- in the current protected object, the bound to be used is the
6929 -- discriminal of the object (see Apply_Range_Checks for details of
6930 -- the transformation).
6932 -----------------------------
6933 -- Actual_Discriminant_Ref --
6934 -----------------------------
6936 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
6937 Typ
: constant Entity_Id
:= Etype
(Bound
);
6941 Remove_Side_Effects
(Bound
);
6943 if not Is_Entity_Name
(Bound
)
6944 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
6948 elsif Is_Protected_Type
(Tsk
)
6949 and then In_Open_Scopes
(Tsk
)
6950 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
6952 -- Note: here Bound denotes a discriminant of the corresponding
6953 -- record type tskV, whose discriminal is a formal of the
6954 -- init-proc tskVIP. What we want is the body discriminal,
6955 -- which is associated to the discriminant of the original
6956 -- concurrent type tsk.
6958 return New_Occurrence_Of
6959 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
6963 Make_Selected_Component
(Loc
,
6964 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
6965 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
6970 end Actual_Discriminant_Ref
;
6972 -- Start of processing for Actual_Index_Type
6975 if not Has_Discriminants
(Tsk
)
6976 or else (not Is_Entity_Name
(Lo
) and then not Is_Entity_Name
(Hi
))
6978 return Entry_Index_Type
(E
);
6981 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
6982 Set_Etype
(New_T
, Base_Type
(Typ
));
6983 Set_Size_Info
(New_T
, Typ
);
6984 Set_RM_Size
(New_T
, RM_Size
(Typ
));
6985 Set_Scalar_Range
(New_T
,
6986 Make_Range
(Sloc
(Entry_Name
),
6987 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
6988 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
6992 end Actual_Index_Type
;
6994 -- Start of processing of Resolve_Entry
6997 -- Find name of entry being called, and resolve prefix of name with its
6998 -- own type. The prefix can be overloaded, and the name and signature of
6999 -- the entry must be taken into account.
7001 if Nkind
(Entry_Name
) = N_Indexed_Component
then
7003 -- Case of dealing with entry family within the current tasks
7005 E_Name
:= Prefix
(Entry_Name
);
7008 E_Name
:= Entry_Name
;
7011 if Is_Entity_Name
(E_Name
) then
7013 -- Entry call to an entry (or entry family) in the current task. This
7014 -- is legal even though the task will deadlock. Rewrite as call to
7017 -- This can also be a call to an entry in an enclosing task. If this
7018 -- is a single task, we have to retrieve its name, because the scope
7019 -- of the entry is the task type, not the object. If the enclosing
7020 -- task is a task type, the identity of the task is given by its own
7023 -- Finally this can be a requeue on an entry of the same task or
7024 -- protected object.
7026 S
:= Scope
(Entity
(E_Name
));
7028 for J
in reverse 0 .. Scope_Stack
.Last
loop
7029 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
7030 and then not Comes_From_Source
(S
)
7032 -- S is an enclosing task or protected object. The concurrent
7033 -- declaration has been converted into a type declaration, and
7034 -- the object itself has an object declaration that follows
7035 -- the type in the same declarative part.
7037 Tsk
:= Next_Entity
(S
);
7038 while Etype
(Tsk
) /= S
loop
7045 elsif S
= Scope_Stack
.Table
(J
).Entity
then
7047 -- Call to current task. Will be transformed into call to Self
7055 Make_Selected_Component
(Loc
,
7056 Prefix
=> New_Occurrence_Of
(S
, Loc
),
7058 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
7059 Rewrite
(E_Name
, New_N
);
7062 elsif Nkind
(Entry_Name
) = N_Selected_Component
7063 and then Is_Overloaded
(Prefix
(Entry_Name
))
7065 -- Use the entry name (which must be unique at this point) to find
7066 -- the prefix that returns the corresponding task/protected type.
7069 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
7070 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
7075 Get_First_Interp
(Pref
, I
, It
);
7076 while Present
(It
.Typ
) loop
7077 if Scope
(Ent
) = It
.Typ
then
7078 Set_Etype
(Pref
, It
.Typ
);
7082 Get_Next_Interp
(I
, It
);
7087 if Nkind
(Entry_Name
) = N_Selected_Component
then
7088 Resolve
(Prefix
(Entry_Name
));
7090 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7091 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7092 Resolve
(Prefix
(Prefix
(Entry_Name
)));
7093 Index
:= First
(Expressions
(Entry_Name
));
7094 Resolve
(Index
, Entry_Index_Type
(Nam
));
7096 -- Up to this point the expression could have been the actual in a
7097 -- simple entry call, and be given by a named association.
7099 if Nkind
(Index
) = N_Parameter_Association
then
7100 Error_Msg_N
("expect expression for entry index", Index
);
7102 Apply_Range_Check
(Index
, Actual_Index_Type
(Nam
));
7107 ------------------------
7108 -- Resolve_Entry_Call --
7109 ------------------------
7111 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
7112 Entry_Name
: constant Node_Id
:= Name
(N
);
7113 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
7115 First_Named
: Node_Id
;
7122 -- We kill all checks here, because it does not seem worth the effort to
7123 -- do anything better, an entry call is a big operation.
7127 -- Processing of the name is similar for entry calls and protected
7128 -- operation calls. Once the entity is determined, we can complete
7129 -- the resolution of the actuals.
7131 -- The selector may be overloaded, in the case of a protected object
7132 -- with overloaded functions. The type of the context is used for
7135 if Nkind
(Entry_Name
) = N_Selected_Component
7136 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
7137 and then Typ
/= Standard_Void_Type
7144 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
7145 while Present
(It
.Typ
) loop
7146 if Covers
(Typ
, It
.Typ
) then
7147 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
7148 Set_Etype
(Entry_Name
, It
.Typ
);
7150 Generate_Reference
(It
.Typ
, N
, ' ');
7153 Get_Next_Interp
(I
, It
);
7158 Resolve_Entry
(Entry_Name
);
7160 if Nkind
(Entry_Name
) = N_Selected_Component
then
7162 -- Simple entry call
7164 Nam
:= Entity
(Selector_Name
(Entry_Name
));
7165 Obj
:= Prefix
(Entry_Name
);
7166 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
7168 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7170 -- Call to member of entry family
7172 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7173 Obj
:= Prefix
(Prefix
(Entry_Name
));
7174 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
7177 -- We cannot in general check the maximum depth of protected entry calls
7178 -- at compile time. But we can tell that any protected entry call at all
7179 -- violates a specified nesting depth of zero.
7181 if Is_Protected_Type
(Scope
(Nam
)) then
7182 Check_Restriction
(Max_Entry_Queue_Length
, N
);
7185 -- Use context type to disambiguate a protected function that can be
7186 -- called without actuals and that returns an array type, and where the
7187 -- argument list may be an indexing of the returned value.
7189 if Ekind
(Nam
) = E_Function
7190 and then Needs_No_Actuals
(Nam
)
7191 and then Present
(Parameter_Associations
(N
))
7193 ((Is_Array_Type
(Etype
(Nam
))
7194 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
7196 or else (Is_Access_Type
(Etype
(Nam
))
7197 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
7201 Component_Type
(Designated_Type
(Etype
(Nam
))))))
7204 Index_Node
: Node_Id
;
7208 Make_Indexed_Component
(Loc
,
7210 Make_Function_Call
(Loc
, Name
=> Relocate_Node
(Entry_Name
)),
7211 Expressions
=> Parameter_Associations
(N
));
7213 -- Since we are correcting a node classification error made by the
7214 -- parser, we call Replace rather than Rewrite.
7216 Replace
(N
, Index_Node
);
7217 Set_Etype
(Prefix
(N
), Etype
(Nam
));
7219 Resolve_Indexed_Component
(N
, Typ
);
7224 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
)
7225 and then Present
(PPC_Wrapper
(Nam
))
7226 and then Current_Scope
/= PPC_Wrapper
(Nam
)
7228 -- Rewrite as call to the precondition wrapper, adding the task
7229 -- object to the list of actuals. If the call is to a member of an
7230 -- entry family, include the index as well.
7234 New_Actuals
: List_Id
;
7237 New_Actuals
:= New_List
(Obj
);
7239 if Nkind
(Entry_Name
) = N_Indexed_Component
then
7240 Append_To
(New_Actuals
,
7241 New_Copy_Tree
(First
(Expressions
(Entry_Name
))));
7244 Append_List
(Parameter_Associations
(N
), New_Actuals
);
7246 Make_Procedure_Call_Statement
(Loc
,
7248 New_Occurrence_Of
(PPC_Wrapper
(Nam
), Loc
),
7249 Parameter_Associations
=> New_Actuals
);
7250 Rewrite
(N
, New_Call
);
7252 -- Preanalyze and resolve new call. Current procedure is called
7253 -- from Resolve_Call, after which expansion will take place.
7255 Preanalyze_And_Resolve
(N
);
7260 -- The operation name may have been overloaded. Order the actuals
7261 -- according to the formals of the resolved entity, and set the return
7262 -- type to that of the operation.
7265 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
7266 pragma Assert
(Norm_OK
);
7267 Set_Etype
(N
, Etype
(Nam
));
7270 Resolve_Actuals
(N
, Nam
);
7271 Check_Internal_Protected_Use
(N
, Nam
);
7273 -- Create a call reference to the entry
7275 Generate_Reference
(Nam
, Entry_Name
, 's');
7277 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
) then
7278 Check_Potentially_Blocking_Operation
(N
);
7281 -- Verify that a procedure call cannot masquerade as an entry
7282 -- call where an entry call is expected.
7284 if Ekind
(Nam
) = E_Procedure
then
7285 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
7286 and then N
= Entry_Call_Statement
(Parent
(N
))
7288 Error_Msg_N
("entry call required in select statement", N
);
7290 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
7291 and then N
= Triggering_Statement
(Parent
(N
))
7293 Error_Msg_N
("triggering statement cannot be procedure call", N
);
7295 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
7296 and then not In_Open_Scopes
(Scope
(Nam
))
7298 Error_Msg_N
("task has no entry with this name", Entry_Name
);
7302 -- After resolution, entry calls and protected procedure calls are
7303 -- changed into entry calls, for expansion. The structure of the node
7304 -- does not change, so it can safely be done in place. Protected
7305 -- function calls must keep their structure because they are
7308 if Ekind
(Nam
) /= E_Function
then
7310 -- A protected operation that is not a function may modify the
7311 -- corresponding object, and cannot apply to a constant. If this
7312 -- is an internal call, the prefix is the type itself.
7314 if Is_Protected_Type
(Scope
(Nam
))
7315 and then not Is_Variable
(Obj
)
7316 and then (not Is_Entity_Name
(Obj
)
7317 or else not Is_Type
(Entity
(Obj
)))
7320 ("prefix of protected procedure or entry call must be variable",
7324 Actuals
:= Parameter_Associations
(N
);
7325 First_Named
:= First_Named_Actual
(N
);
7328 Make_Entry_Call_Statement
(Loc
,
7330 Parameter_Associations
=> Actuals
));
7332 Set_First_Named_Actual
(N
, First_Named
);
7333 Set_Analyzed
(N
, True);
7335 -- Protected functions can return on the secondary stack, in which
7336 -- case we must trigger the transient scope mechanism.
7338 elsif Expander_Active
7339 and then Requires_Transient_Scope
(Etype
(Nam
))
7341 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
7343 end Resolve_Entry_Call
;
7345 -------------------------
7346 -- Resolve_Equality_Op --
7347 -------------------------
7349 -- Both arguments must have the same type, and the boolean context does
7350 -- not participate in the resolution. The first pass verifies that the
7351 -- interpretation is not ambiguous, and the type of the left argument is
7352 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
7353 -- are strings or aggregates, allocators, or Null, they are ambiguous even
7354 -- though they carry a single (universal) type. Diagnose this case here.
7356 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7357 L
: constant Node_Id
:= Left_Opnd
(N
);
7358 R
: constant Node_Id
:= Right_Opnd
(N
);
7359 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
7361 procedure Check_If_Expression
(Cond
: Node_Id
);
7362 -- The resolution rule for if expressions requires that each such must
7363 -- have a unique type. This means that if several dependent expressions
7364 -- are of a non-null anonymous access type, and the context does not
7365 -- impose an expected type (as can be the case in an equality operation)
7366 -- the expression must be rejected.
7368 procedure Explain_Redundancy
(N
: Node_Id
);
7369 -- Attempt to explain the nature of a redundant comparison with True. If
7370 -- the expression N is too complex, this routine issues a general error
7373 function Find_Unique_Access_Type
return Entity_Id
;
7374 -- In the case of allocators and access attributes, the context must
7375 -- provide an indication of the specific access type to be used. If
7376 -- one operand is of such a "generic" access type, check whether there
7377 -- is a specific visible access type that has the same designated type.
7378 -- This is semantically dubious, and of no interest to any real code,
7379 -- but c48008a makes it all worthwhile.
7381 -------------------------
7382 -- Check_If_Expression --
7383 -------------------------
7385 procedure Check_If_Expression
(Cond
: Node_Id
) is
7386 Then_Expr
: Node_Id
;
7387 Else_Expr
: Node_Id
;
7390 if Nkind
(Cond
) = N_If_Expression
then
7391 Then_Expr
:= Next
(First
(Expressions
(Cond
)));
7392 Else_Expr
:= Next
(Then_Expr
);
7394 if Nkind
(Then_Expr
) /= N_Null
7395 and then Nkind
(Else_Expr
) /= N_Null
7397 Error_Msg_N
("cannot determine type of if expression", Cond
);
7400 end Check_If_Expression
;
7402 ------------------------
7403 -- Explain_Redundancy --
7404 ------------------------
7406 procedure Explain_Redundancy
(N
: Node_Id
) is
7414 -- Strip the operand down to an entity
7417 if Nkind
(Val
) = N_Selected_Component
then
7418 Val
:= Selector_Name
(Val
);
7424 -- The construct denotes an entity
7426 if Is_Entity_Name
(Val
) and then Present
(Entity
(Val
)) then
7427 Val_Id
:= Entity
(Val
);
7429 -- Do not generate an error message when the comparison is done
7430 -- against the enumeration literal Standard.True.
7432 if Ekind
(Val_Id
) /= E_Enumeration_Literal
then
7434 -- Build a customized error message
7437 Add_Str_To_Name_Buffer
("?r?");
7439 if Ekind
(Val_Id
) = E_Component
then
7440 Add_Str_To_Name_Buffer
("component ");
7442 elsif Ekind
(Val_Id
) = E_Constant
then
7443 Add_Str_To_Name_Buffer
("constant ");
7445 elsif Ekind
(Val_Id
) = E_Discriminant
then
7446 Add_Str_To_Name_Buffer
("discriminant ");
7448 elsif Is_Formal
(Val_Id
) then
7449 Add_Str_To_Name_Buffer
("parameter ");
7451 elsif Ekind
(Val_Id
) = E_Variable
then
7452 Add_Str_To_Name_Buffer
("variable ");
7455 Add_Str_To_Name_Buffer
("& is always True!");
7458 Error_Msg_NE
(Get_Name_String
(Error
), Val
, Val_Id
);
7461 -- The construct is too complex to disect, issue a general message
7464 Error_Msg_N
("?r?expression is always True!", Val
);
7466 end Explain_Redundancy
;
7468 -----------------------------
7469 -- Find_Unique_Access_Type --
7470 -----------------------------
7472 function Find_Unique_Access_Type
return Entity_Id
is
7478 if Ekind_In
(Etype
(R
), E_Allocator_Type
,
7479 E_Access_Attribute_Type
)
7481 Acc
:= Designated_Type
(Etype
(R
));
7483 elsif Ekind_In
(Etype
(L
), E_Allocator_Type
,
7484 E_Access_Attribute_Type
)
7486 Acc
:= Designated_Type
(Etype
(L
));
7492 while S
/= Standard_Standard
loop
7493 E
:= First_Entity
(S
);
7494 while Present
(E
) loop
7496 and then Is_Access_Type
(E
)
7497 and then Ekind
(E
) /= E_Allocator_Type
7498 and then Designated_Type
(E
) = Base_Type
(Acc
)
7510 end Find_Unique_Access_Type
;
7512 -- Start of processing for Resolve_Equality_Op
7515 Set_Etype
(N
, Base_Type
(Typ
));
7516 Generate_Reference
(T
, N
, ' ');
7518 if T
= Any_Fixed
then
7519 T
:= Unique_Fixed_Point_Type
(L
);
7522 if T
/= Any_Type
then
7523 if T
= Any_String
or else
7524 T
= Any_Composite
or else
7527 if T
= Any_Character
then
7528 Ambiguous_Character
(L
);
7530 Error_Msg_N
("ambiguous operands for equality", N
);
7533 Set_Etype
(N
, Any_Type
);
7536 elsif T
= Any_Access
7537 or else Ekind_In
(T
, E_Allocator_Type
, E_Access_Attribute_Type
)
7539 T
:= Find_Unique_Access_Type
;
7542 Error_Msg_N
("ambiguous operands for equality", N
);
7543 Set_Etype
(N
, Any_Type
);
7547 -- If expressions must have a single type, and if the context does
7548 -- not impose one the dependent expressions cannot be anonymous
7551 -- Why no similar processing for case expressions???
7553 elsif Ada_Version
>= Ada_2012
7554 and then Ekind_In
(Etype
(L
), E_Anonymous_Access_Type
,
7555 E_Anonymous_Access_Subprogram_Type
)
7556 and then Ekind_In
(Etype
(R
), E_Anonymous_Access_Type
,
7557 E_Anonymous_Access_Subprogram_Type
)
7559 Check_If_Expression
(L
);
7560 Check_If_Expression
(R
);
7566 -- In SPARK, equality operators = and /= for array types other than
7567 -- String are only defined when, for each index position, the
7568 -- operands have equal static bounds.
7570 if Is_Array_Type
(T
) then
7572 -- Protect call to Matching_Static_Array_Bounds to avoid costly
7573 -- operation if not needed.
7575 if Restriction_Check_Required
(SPARK_05
)
7576 and then Base_Type
(T
) /= Standard_String
7577 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
7578 and then Etype
(L
) /= Any_Composite
-- or else L in error
7579 and then Etype
(R
) /= Any_Composite
-- or else R in error
7580 and then not Matching_Static_Array_Bounds
(Etype
(L
), Etype
(R
))
7582 Check_SPARK_05_Restriction
7583 ("array types should have matching static bounds", N
);
7587 -- If the unique type is a class-wide type then it will be expanded
7588 -- into a dispatching call to the predefined primitive. Therefore we
7589 -- check here for potential violation of such restriction.
7591 if Is_Class_Wide_Type
(T
) then
7592 Check_Restriction
(No_Dispatching_Calls
, N
);
7595 if Warn_On_Redundant_Constructs
7596 and then Comes_From_Source
(N
)
7597 and then Comes_From_Source
(R
)
7598 and then Is_Entity_Name
(R
)
7599 and then Entity
(R
) = Standard_True
7601 Error_Msg_N
-- CODEFIX
7602 ("?r?comparison with True is redundant!", N
);
7603 Explain_Redundancy
(Original_Node
(R
));
7606 Check_Unset_Reference
(L
);
7607 Check_Unset_Reference
(R
);
7608 Generate_Operator_Reference
(N
, T
);
7609 Check_Low_Bound_Tested
(N
);
7611 -- If this is an inequality, it may be the implicit inequality
7612 -- created for a user-defined operation, in which case the corres-
7613 -- ponding equality operation is not intrinsic, and the operation
7614 -- cannot be constant-folded. Else fold.
7616 if Nkind
(N
) = N_Op_Eq
7617 or else Comes_From_Source
(Entity
(N
))
7618 or else Ekind
(Entity
(N
)) = E_Operator
7619 or else Is_Intrinsic_Subprogram
7620 (Corresponding_Equality
(Entity
(N
)))
7622 Analyze_Dimension
(N
);
7623 Eval_Relational_Op
(N
);
7625 elsif Nkind
(N
) = N_Op_Ne
7626 and then Is_Abstract_Subprogram
(Entity
(N
))
7628 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Entity
(N
));
7631 -- Ada 2005: If one operand is an anonymous access type, convert the
7632 -- other operand to it, to ensure that the underlying types match in
7633 -- the back-end. Same for access_to_subprogram, and the conversion
7634 -- verifies that the types are subtype conformant.
7636 -- We apply the same conversion in the case one of the operands is a
7637 -- private subtype of the type of the other.
7639 -- Why the Expander_Active test here ???
7643 (Ekind_In
(T
, E_Anonymous_Access_Type
,
7644 E_Anonymous_Access_Subprogram_Type
)
7645 or else Is_Private_Type
(T
))
7647 if Etype
(L
) /= T
then
7649 Make_Unchecked_Type_Conversion
(Sloc
(L
),
7650 Subtype_Mark
=> New_Occurrence_Of
(T
, Sloc
(L
)),
7651 Expression
=> Relocate_Node
(L
)));
7652 Analyze_And_Resolve
(L
, T
);
7655 if (Etype
(R
)) /= T
then
7657 Make_Unchecked_Type_Conversion
(Sloc
(R
),
7658 Subtype_Mark
=> New_Occurrence_Of
(Etype
(L
), Sloc
(R
)),
7659 Expression
=> Relocate_Node
(R
)));
7660 Analyze_And_Resolve
(R
, T
);
7664 end Resolve_Equality_Op
;
7666 ----------------------------------
7667 -- Resolve_Explicit_Dereference --
7668 ----------------------------------
7670 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
7671 Loc
: constant Source_Ptr
:= Sloc
(N
);
7673 P
: constant Node_Id
:= Prefix
(N
);
7676 -- The candidate prefix type, if overloaded
7682 Check_Fully_Declared_Prefix
(Typ
, P
);
7685 -- A useful optimization: check whether the dereference denotes an
7686 -- element of a container, and if so rewrite it as a call to the
7687 -- corresponding Element function.
7689 -- Disabled for now, on advice of ARG. A more restricted form of the
7690 -- predicate might be acceptable ???
7692 -- if Is_Container_Element (N) then
7696 if Is_Overloaded
(P
) then
7698 -- Use the context type to select the prefix that has the correct
7699 -- designated type. Keep the first match, which will be the inner-
7702 Get_First_Interp
(P
, I
, It
);
7704 while Present
(It
.Typ
) loop
7705 if Is_Access_Type
(It
.Typ
)
7706 and then Covers
(Typ
, Designated_Type
(It
.Typ
))
7712 -- Remove access types that do not match, but preserve access
7713 -- to subprogram interpretations, in case a further dereference
7714 -- is needed (see below).
7716 elsif Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7720 Get_Next_Interp
(I
, It
);
7723 if Present
(P_Typ
) then
7725 Set_Etype
(N
, Designated_Type
(P_Typ
));
7728 -- If no interpretation covers the designated type of the prefix,
7729 -- this is the pathological case where not all implementations of
7730 -- the prefix allow the interpretation of the node as a call. Now
7731 -- that the expected type is known, Remove other interpretations
7732 -- from prefix, rewrite it as a call, and resolve again, so that
7733 -- the proper call node is generated.
7735 Get_First_Interp
(P
, I
, It
);
7736 while Present
(It
.Typ
) loop
7737 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7741 Get_Next_Interp
(I
, It
);
7745 Make_Function_Call
(Loc
,
7747 Make_Explicit_Dereference
(Loc
,
7749 Parameter_Associations
=> New_List
);
7751 Save_Interps
(N
, New_N
);
7753 Analyze_And_Resolve
(N
, Typ
);
7757 -- If not overloaded, resolve P with its own type
7763 if Is_Access_Type
(Etype
(P
)) then
7764 Apply_Access_Check
(N
);
7767 -- If the designated type is a packed unconstrained array type, and the
7768 -- explicit dereference is not in the context of an attribute reference,
7769 -- then we must compute and set the actual subtype, since it is needed
7770 -- by Gigi. The reason we exclude the attribute case is that this is
7771 -- handled fine by Gigi, and in fact we use such attributes to build the
7772 -- actual subtype. We also exclude generated code (which builds actual
7773 -- subtypes directly if they are needed).
7775 if Is_Array_Type
(Etype
(N
))
7776 and then Is_Packed
(Etype
(N
))
7777 and then not Is_Constrained
(Etype
(N
))
7778 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
7779 and then Comes_From_Source
(N
)
7781 Set_Etype
(N
, Get_Actual_Subtype
(N
));
7784 -- Note: No Eval processing is required for an explicit dereference,
7785 -- because such a name can never be static.
7787 end Resolve_Explicit_Dereference
;
7789 -------------------------------------
7790 -- Resolve_Expression_With_Actions --
7791 -------------------------------------
7793 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
7797 -- If N has no actions, and its expression has been constant folded,
7798 -- then rewrite N as just its expression. Note, we can't do this in
7799 -- the general case of Is_Empty_List (Actions (N)) as this would cause
7800 -- Expression (N) to be expanded again.
7802 if Is_Empty_List
(Actions
(N
))
7803 and then Compile_Time_Known_Value
(Expression
(N
))
7805 Rewrite
(N
, Expression
(N
));
7807 end Resolve_Expression_With_Actions
;
7809 ----------------------------------
7810 -- Resolve_Generalized_Indexing --
7811 ----------------------------------
7813 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
) is
7814 Indexing
: constant Node_Id
:= Generalized_Indexing
(N
);
7820 -- In ASIS mode, propagate the information about the indices back to
7821 -- to the original indexing node. The generalized indexing is either
7822 -- a function call, or a dereference of one. The actuals include the
7823 -- prefix of the original node, which is the container expression.
7826 Resolve
(Indexing
, Typ
);
7827 Set_Etype
(N
, Etype
(Indexing
));
7828 Set_Is_Overloaded
(N
, False);
7831 while Nkind_In
(Call
, N_Explicit_Dereference
, N_Selected_Component
)
7833 Call
:= Prefix
(Call
);
7836 if Nkind
(Call
) = N_Function_Call
then
7837 Indices
:= Parameter_Associations
(Call
);
7838 Pref
:= Remove_Head
(Indices
);
7839 Set_Expressions
(N
, Indices
);
7840 Set_Prefix
(N
, Pref
);
7844 Rewrite
(N
, Indexing
);
7847 end Resolve_Generalized_Indexing
;
7849 ---------------------------
7850 -- Resolve_If_Expression --
7851 ---------------------------
7853 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7854 Condition
: constant Node_Id
:= First
(Expressions
(N
));
7855 Then_Expr
: constant Node_Id
:= Next
(Condition
);
7856 Else_Expr
: Node_Id
:= Next
(Then_Expr
);
7857 Else_Typ
: Entity_Id
;
7858 Then_Typ
: Entity_Id
;
7861 Resolve
(Condition
, Any_Boolean
);
7862 Resolve
(Then_Expr
, Typ
);
7863 Then_Typ
:= Etype
(Then_Expr
);
7865 -- When the "then" expression is of a scalar subtype different from the
7866 -- result subtype, then insert a conversion to ensure the generation of
7867 -- a constraint check. The same is done for the else part below, again
7868 -- comparing subtypes rather than base types.
7870 if Is_Scalar_Type
(Then_Typ
)
7871 and then Then_Typ
/= Typ
7873 Rewrite
(Then_Expr
, Convert_To
(Typ
, Then_Expr
));
7874 Analyze_And_Resolve
(Then_Expr
, Typ
);
7877 -- If ELSE expression present, just resolve using the determined type
7879 if Present
(Else_Expr
) then
7880 Resolve
(Else_Expr
, Typ
);
7881 Else_Typ
:= Etype
(Else_Expr
);
7883 if Is_Scalar_Type
(Else_Typ
)
7884 and then Else_Typ
/= Typ
7886 Rewrite
(Else_Expr
, Convert_To
(Typ
, Else_Expr
));
7887 Analyze_And_Resolve
(Else_Expr
, Typ
);
7890 -- If no ELSE expression is present, root type must be Standard.Boolean
7891 -- and we provide a Standard.True result converted to the appropriate
7892 -- Boolean type (in case it is a derived boolean type).
7894 elsif Root_Type
(Typ
) = Standard_Boolean
then
7896 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
7897 Analyze_And_Resolve
(Else_Expr
, Typ
);
7898 Append_To
(Expressions
(N
), Else_Expr
);
7901 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
7902 Append_To
(Expressions
(N
), Error
);
7906 Eval_If_Expression
(N
);
7907 end Resolve_If_Expression
;
7909 -------------------------------
7910 -- Resolve_Indexed_Component --
7911 -------------------------------
7913 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
7914 Name
: constant Node_Id
:= Prefix
(N
);
7916 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
7920 if Present
(Generalized_Indexing
(N
)) then
7921 Resolve_Generalized_Indexing
(N
, Typ
);
7925 if Is_Overloaded
(Name
) then
7927 -- Use the context type to select the prefix that yields the correct
7933 I1
: Interp_Index
:= 0;
7934 P
: constant Node_Id
:= Prefix
(N
);
7935 Found
: Boolean := False;
7938 Get_First_Interp
(P
, I
, It
);
7939 while Present
(It
.Typ
) loop
7940 if (Is_Array_Type
(It
.Typ
)
7941 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
7942 or else (Is_Access_Type
(It
.Typ
)
7943 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
7947 Component_Type
(Designated_Type
(It
.Typ
))))
7950 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
7952 if It
= No_Interp
then
7953 Error_Msg_N
("ambiguous prefix for indexing", N
);
7959 Array_Type
:= It
.Typ
;
7965 Array_Type
:= It
.Typ
;
7970 Get_Next_Interp
(I
, It
);
7975 Array_Type
:= Etype
(Name
);
7978 Resolve
(Name
, Array_Type
);
7979 Array_Type
:= Get_Actual_Subtype_If_Available
(Name
);
7981 -- If prefix is access type, dereference to get real array type.
7982 -- Note: we do not apply an access check because the expander always
7983 -- introduces an explicit dereference, and the check will happen there.
7985 if Is_Access_Type
(Array_Type
) then
7986 Array_Type
:= Designated_Type
(Array_Type
);
7989 -- If name was overloaded, set component type correctly now
7990 -- If a misplaced call to an entry family (which has no index types)
7991 -- return. Error will be diagnosed from calling context.
7993 if Is_Array_Type
(Array_Type
) then
7994 Set_Etype
(N
, Component_Type
(Array_Type
));
7999 Index
:= First_Index
(Array_Type
);
8000 Expr
:= First
(Expressions
(N
));
8002 -- The prefix may have resolved to a string literal, in which case its
8003 -- etype has a special representation. This is only possible currently
8004 -- if the prefix is a static concatenation, written in functional
8007 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
8008 Resolve
(Expr
, Standard_Positive
);
8011 while Present
(Index
) and Present
(Expr
) loop
8012 Resolve
(Expr
, Etype
(Index
));
8013 Check_Unset_Reference
(Expr
);
8015 if Is_Scalar_Type
(Etype
(Expr
)) then
8016 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
8018 Apply_Range_Check
(Expr
, Get_Actual_Subtype
(Index
));
8026 Analyze_Dimension
(N
);
8028 -- Do not generate the warning on suspicious index if we are analyzing
8029 -- package Ada.Tags; otherwise we will report the warning with the
8030 -- Prims_Ptr field of the dispatch table.
8032 if Scope
(Etype
(Prefix
(N
))) = Standard_Standard
8034 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Prefix
(N
)))),
8037 Warn_On_Suspicious_Index
(Name
, First
(Expressions
(N
)));
8038 Eval_Indexed_Component
(N
);
8041 -- If the array type is atomic, and the component is not atomic, then
8042 -- this is worth a warning, since we have a situation where the access
8043 -- to the component may cause extra read/writes of the atomic array
8044 -- object, or partial word accesses, which could be unexpected.
8046 if Nkind
(N
) = N_Indexed_Component
8047 and then Is_Atomic_Ref_With_Address
(N
)
8048 and then not (Has_Atomic_Components
(Array_Type
)
8049 or else (Is_Entity_Name
(Prefix
(N
))
8050 and then Has_Atomic_Components
8051 (Entity
(Prefix
(N
)))))
8052 and then not Is_Atomic
(Component_Type
(Array_Type
))
8054 Error_Msg_N
("??access to non-atomic component of atomic array",
8056 Error_Msg_N
("??\may cause unexpected accesses to atomic object",
8059 end Resolve_Indexed_Component
;
8061 -----------------------------
8062 -- Resolve_Integer_Literal --
8063 -----------------------------
8065 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
8068 Eval_Integer_Literal
(N
);
8069 end Resolve_Integer_Literal
;
8071 --------------------------------
8072 -- Resolve_Intrinsic_Operator --
8073 --------------------------------
8075 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
8076 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8081 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
;
8082 -- If the operand is a literal, it cannot be the expression in a
8083 -- conversion. Use a qualified expression instead.
8085 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
is
8086 Loc
: constant Source_Ptr
:= Sloc
(Opnd
);
8089 if Nkind_In
(Opnd
, N_Integer_Literal
, N_Real_Literal
) then
8091 Make_Qualified_Expression
(Loc
,
8092 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
8093 Expression
=> Relocate_Node
(Opnd
));
8097 Res
:= Unchecked_Convert_To
(Btyp
, Opnd
);
8101 end Convert_Operand
;
8103 -- Start of processing for Resolve_Intrinsic_Operator
8106 -- We must preserve the original entity in a generic setting, so that
8107 -- the legality of the operation can be verified in an instance.
8109 if not Expander_Active
then
8114 while Scope
(Op
) /= Standard_Standard
loop
8116 pragma Assert
(Present
(Op
));
8120 Set_Is_Overloaded
(N
, False);
8122 -- If the result or operand types are private, rewrite with unchecked
8123 -- conversions on the operands and the result, to expose the proper
8124 -- underlying numeric type.
8126 if Is_Private_Type
(Typ
)
8127 or else Is_Private_Type
(Etype
(Left_Opnd
(N
)))
8128 or else Is_Private_Type
(Etype
(Right_Opnd
(N
)))
8130 Arg1
:= Convert_Operand
(Left_Opnd
(N
));
8131 -- Unchecked_Convert_To (Btyp, Left_Opnd (N));
8132 -- What on earth is this commented out fragment of code???
8134 if Nkind
(N
) = N_Op_Expon
then
8135 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
8137 Arg2
:= Convert_Operand
(Right_Opnd
(N
));
8140 if Nkind
(Arg1
) = N_Type_Conversion
then
8141 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8144 if Nkind
(Arg2
) = N_Type_Conversion
then
8145 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8148 Set_Left_Opnd
(N
, Arg1
);
8149 Set_Right_Opnd
(N
, Arg2
);
8151 Set_Etype
(N
, Btyp
);
8152 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8155 elsif Typ
/= Etype
(Left_Opnd
(N
))
8156 or else Typ
/= Etype
(Right_Opnd
(N
))
8158 -- Add explicit conversion where needed, and save interpretations in
8159 -- case operands are overloaded.
8161 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
8162 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
8164 if Nkind
(Arg1
) = N_Type_Conversion
then
8165 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8167 Save_Interps
(Left_Opnd
(N
), Arg1
);
8170 if Nkind
(Arg2
) = N_Type_Conversion
then
8171 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8173 Save_Interps
(Right_Opnd
(N
), Arg2
);
8176 Rewrite
(Left_Opnd
(N
), Arg1
);
8177 Rewrite
(Right_Opnd
(N
), Arg2
);
8180 Resolve_Arithmetic_Op
(N
, Typ
);
8183 Resolve_Arithmetic_Op
(N
, Typ
);
8185 end Resolve_Intrinsic_Operator
;
8187 --------------------------------------
8188 -- Resolve_Intrinsic_Unary_Operator --
8189 --------------------------------------
8191 procedure Resolve_Intrinsic_Unary_Operator
8195 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8201 while Scope
(Op
) /= Standard_Standard
loop
8203 pragma Assert
(Present
(Op
));
8208 if Is_Private_Type
(Typ
) then
8209 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
8210 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8212 Set_Right_Opnd
(N
, Arg2
);
8214 Set_Etype
(N
, Btyp
);
8215 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8219 Resolve_Unary_Op
(N
, Typ
);
8221 end Resolve_Intrinsic_Unary_Operator
;
8223 ------------------------
8224 -- Resolve_Logical_Op --
8225 ------------------------
8227 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8231 Check_No_Direct_Boolean_Operators
(N
);
8233 -- Predefined operations on scalar types yield the base type. On the
8234 -- other hand, logical operations on arrays yield the type of the
8235 -- arguments (and the context).
8237 if Is_Array_Type
(Typ
) then
8240 B_Typ
:= Base_Type
(Typ
);
8243 -- The following test is required because the operands of the operation
8244 -- may be literals, in which case the resulting type appears to be
8245 -- compatible with a signed integer type, when in fact it is compatible
8246 -- only with modular types. If the context itself is universal, the
8247 -- operation is illegal.
8249 if not Valid_Boolean_Arg
(Typ
) then
8250 Error_Msg_N
("invalid context for logical operation", N
);
8251 Set_Etype
(N
, Any_Type
);
8254 elsif Typ
= Any_Modular
then
8256 ("no modular type available in this context", N
);
8257 Set_Etype
(N
, Any_Type
);
8260 elsif Is_Modular_Integer_Type
(Typ
)
8261 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
8262 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
8264 Check_For_Visible_Operator
(N
, B_Typ
);
8267 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
8268 -- is active and the result type is standard Boolean (do not mess with
8269 -- ops that return a nonstandard Boolean type, because something strange
8272 -- Note: you might expect this replacement to be done during expansion,
8273 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
8274 -- is used, no part of the right operand of an "and" or "or" operator
8275 -- should be executed if the left operand would short-circuit the
8276 -- evaluation of the corresponding "and then" or "or else". If we left
8277 -- the replacement to expansion time, then run-time checks associated
8278 -- with such operands would be evaluated unconditionally, due to being
8279 -- before the condition prior to the rewriting as short-circuit forms
8280 -- during expansion.
8282 if Short_Circuit_And_Or
8283 and then B_Typ
= Standard_Boolean
8284 and then Nkind_In
(N
, N_Op_And
, N_Op_Or
)
8286 if Nkind
(N
) = N_Op_And
then
8288 Make_And_Then
(Sloc
(N
),
8289 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8290 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8291 Analyze_And_Resolve
(N
, B_Typ
);
8293 -- Case of OR changed to OR ELSE
8297 Make_Or_Else
(Sloc
(N
),
8298 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8299 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8300 Analyze_And_Resolve
(N
, B_Typ
);
8303 -- Return now, since analysis of the rewritten ops will take care of
8304 -- other reference bookkeeping and expression folding.
8309 Resolve
(Left_Opnd
(N
), B_Typ
);
8310 Resolve
(Right_Opnd
(N
), B_Typ
);
8312 Check_Unset_Reference
(Left_Opnd
(N
));
8313 Check_Unset_Reference
(Right_Opnd
(N
));
8315 Set_Etype
(N
, B_Typ
);
8316 Generate_Operator_Reference
(N
, B_Typ
);
8317 Eval_Logical_Op
(N
);
8319 -- In SPARK, logical operations AND, OR and XOR for arrays are defined
8320 -- only when both operands have same static lower and higher bounds. Of
8321 -- course the types have to match, so only check if operands are
8322 -- compatible and the node itself has no errors.
8324 if Is_Array_Type
(B_Typ
)
8325 and then Nkind
(N
) in N_Binary_Op
8328 Left_Typ
: constant Node_Id
:= Etype
(Left_Opnd
(N
));
8329 Right_Typ
: constant Node_Id
:= Etype
(Right_Opnd
(N
));
8332 -- Protect call to Matching_Static_Array_Bounds to avoid costly
8333 -- operation if not needed.
8335 if Restriction_Check_Required
(SPARK_05
)
8336 and then Base_Type
(Left_Typ
) = Base_Type
(Right_Typ
)
8337 and then Left_Typ
/= Any_Composite
-- or Left_Opnd in error
8338 and then Right_Typ
/= Any_Composite
-- or Right_Opnd in error
8339 and then not Matching_Static_Array_Bounds
(Left_Typ
, Right_Typ
)
8341 Check_SPARK_05_Restriction
8342 ("array types should have matching static bounds", N
);
8347 Check_Function_Writable_Actuals
(N
);
8348 end Resolve_Logical_Op
;
8350 ---------------------------
8351 -- Resolve_Membership_Op --
8352 ---------------------------
8354 -- The context can only be a boolean type, and does not determine the
8355 -- arguments. Arguments should be unambiguous, but the preference rule for
8356 -- universal types applies.
8358 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8359 pragma Warnings
(Off
, Typ
);
8361 L
: constant Node_Id
:= Left_Opnd
(N
);
8362 R
: constant Node_Id
:= Right_Opnd
(N
);
8365 procedure Resolve_Set_Membership
;
8366 -- Analysis has determined a unique type for the left operand. Use it to
8367 -- resolve the disjuncts.
8369 ----------------------------
8370 -- Resolve_Set_Membership --
8371 ----------------------------
8373 procedure Resolve_Set_Membership
is
8375 Ltyp
: constant Entity_Id
:= Etype
(L
);
8380 Alt
:= First
(Alternatives
(N
));
8381 while Present
(Alt
) loop
8383 -- Alternative is an expression, a range
8384 -- or a subtype mark.
8386 if not Is_Entity_Name
(Alt
)
8387 or else not Is_Type
(Entity
(Alt
))
8389 Resolve
(Alt
, Ltyp
);
8395 -- Check for duplicates for discrete case
8397 if Is_Discrete_Type
(Ltyp
) then
8404 Alts
: array (0 .. List_Length
(Alternatives
(N
))) of Ent
;
8408 -- Loop checking duplicates. This is quadratic, but giant sets
8409 -- are unlikely in this context so it's a reasonable choice.
8412 Alt
:= First
(Alternatives
(N
));
8413 while Present
(Alt
) loop
8414 if Is_OK_Static_Expression
(Alt
)
8415 and then (Nkind_In
(Alt
, N_Integer_Literal
,
8416 N_Character_Literal
)
8417 or else Nkind
(Alt
) in N_Has_Entity
)
8420 Alts
(Nalts
) := (Alt
, Expr_Value
(Alt
));
8422 for J
in 1 .. Nalts
- 1 loop
8423 if Alts
(J
).Val
= Alts
(Nalts
).Val
then
8424 Error_Msg_Sloc
:= Sloc
(Alts
(J
).Alt
);
8425 Error_Msg_N
("duplicate of value given#??", Alt
);
8434 end Resolve_Set_Membership
;
8436 -- Start of processing for Resolve_Membership_Op
8439 if L
= Error
or else R
= Error
then
8443 if Present
(Alternatives
(N
)) then
8444 Resolve_Set_Membership
;
8447 elsif not Is_Overloaded
(R
)
8449 (Etype
(R
) = Universal_Integer
8451 Etype
(R
) = Universal_Real
)
8452 and then Is_Overloaded
(L
)
8456 -- Ada 2005 (AI-251): Support the following case:
8458 -- type I is interface;
8459 -- type T is tagged ...
8461 -- function Test (O : I'Class) is
8463 -- return O in T'Class.
8466 -- In this case we have nothing else to do. The membership test will be
8467 -- done at run time.
8469 elsif Ada_Version
>= Ada_2005
8470 and then Is_Class_Wide_Type
(Etype
(L
))
8471 and then Is_Interface
(Etype
(L
))
8472 and then Is_Class_Wide_Type
(Etype
(R
))
8473 and then not Is_Interface
(Etype
(R
))
8477 T
:= Intersect_Types
(L
, R
);
8480 -- If mixed-mode operations are present and operands are all literal,
8481 -- the only interpretation involves Duration, which is probably not
8482 -- the intention of the programmer.
8484 if T
= Any_Fixed
then
8485 T
:= Unique_Fixed_Point_Type
(N
);
8487 if T
= Any_Type
then
8493 Check_Unset_Reference
(L
);
8495 if Nkind
(R
) = N_Range
8496 and then not Is_Scalar_Type
(T
)
8498 Error_Msg_N
("scalar type required for range", R
);
8501 if Is_Entity_Name
(R
) then
8502 Freeze_Expression
(R
);
8505 Check_Unset_Reference
(R
);
8508 -- Here after resolving membership operation
8512 Eval_Membership_Op
(N
);
8513 Check_Function_Writable_Actuals
(N
);
8514 end Resolve_Membership_Op
;
8520 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
8521 Loc
: constant Source_Ptr
:= Sloc
(N
);
8524 -- Handle restriction against anonymous null access values This
8525 -- restriction can be turned off using -gnatdj.
8527 -- Ada 2005 (AI-231): Remove restriction
8529 if Ada_Version
< Ada_2005
8530 and then not Debug_Flag_J
8531 and then Ekind
(Typ
) = E_Anonymous_Access_Type
8532 and then Comes_From_Source
(N
)
8534 -- In the common case of a call which uses an explicitly null value
8535 -- for an access parameter, give specialized error message.
8537 if Nkind
(Parent
(N
)) in N_Subprogram_Call
then
8539 ("null is not allowed as argument for an access parameter", N
);
8541 -- Standard message for all other cases (are there any?)
8545 ("null cannot be of an anonymous access type", N
);
8549 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
8550 -- assignment to a null-excluding object
8552 if Ada_Version
>= Ada_2005
8553 and then Can_Never_Be_Null
(Typ
)
8554 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
8556 if not Inside_Init_Proc
then
8558 (Compile_Time_Constraint_Error
(N
,
8559 "(Ada 2005) null not allowed in null-excluding objects??"),
8560 Make_Raise_Constraint_Error
(Loc
,
8561 Reason
=> CE_Access_Check_Failed
));
8564 Make_Raise_Constraint_Error
(Loc
,
8565 Reason
=> CE_Access_Check_Failed
));
8569 -- In a distributed context, null for a remote access to subprogram may
8570 -- need to be replaced with a special record aggregate. In this case,
8571 -- return after having done the transformation.
8573 if (Ekind
(Typ
) = E_Record_Type
8574 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
8575 and then Remote_AST_Null_Value
(N
, Typ
)
8580 -- The null literal takes its type from the context
8585 -----------------------
8586 -- Resolve_Op_Concat --
8587 -----------------------
8589 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
8591 -- We wish to avoid deep recursion, because concatenations are often
8592 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
8593 -- operands nonrecursively until we find something that is not a simple
8594 -- concatenation (A in this case). We resolve that, and then walk back
8595 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
8596 -- to do the rest of the work at each level. The Parent pointers allow
8597 -- us to avoid recursion, and thus avoid running out of memory. See also
8598 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
8604 -- The following code is equivalent to:
8606 -- Resolve_Op_Concat_First (NN, Typ);
8607 -- Resolve_Op_Concat_Arg (N, ...);
8608 -- Resolve_Op_Concat_Rest (N, Typ);
8610 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
8611 -- operand is a concatenation.
8613 -- Walk down left operands
8616 Resolve_Op_Concat_First
(NN
, Typ
);
8617 Op1
:= Left_Opnd
(NN
);
8618 exit when not (Nkind
(Op1
) = N_Op_Concat
8619 and then not Is_Array_Type
(Component_Type
(Typ
))
8620 and then Entity
(Op1
) = Entity
(NN
));
8624 -- Now (given the above example) NN is A&B and Op1 is A
8626 -- First resolve Op1 ...
8628 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
8630 -- ... then walk NN back up until we reach N (where we started), calling
8631 -- Resolve_Op_Concat_Rest along the way.
8634 Resolve_Op_Concat_Rest
(NN
, Typ
);
8639 if Base_Type
(Etype
(N
)) /= Standard_String
then
8640 Check_SPARK_05_Restriction
8641 ("result of concatenation should have type String", N
);
8643 end Resolve_Op_Concat
;
8645 ---------------------------
8646 -- Resolve_Op_Concat_Arg --
8647 ---------------------------
8649 procedure Resolve_Op_Concat_Arg
8655 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8656 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
8661 or else (not Is_Overloaded
(Arg
)
8662 and then Etype
(Arg
) /= Any_Composite
8663 and then Covers
(Ctyp
, Etype
(Arg
)))
8665 Resolve
(Arg
, Ctyp
);
8667 Resolve
(Arg
, Btyp
);
8670 -- If both Array & Array and Array & Component are visible, there is a
8671 -- potential ambiguity that must be reported.
8673 elsif Has_Compatible_Type
(Arg
, Ctyp
) then
8674 if Nkind
(Arg
) = N_Aggregate
8675 and then Is_Composite_Type
(Ctyp
)
8677 if Is_Private_Type
(Ctyp
) then
8678 Resolve
(Arg
, Btyp
);
8680 -- If the operation is user-defined and not overloaded use its
8681 -- profile. The operation may be a renaming, in which case it has
8682 -- been rewritten, and we want the original profile.
8684 elsif not Is_Overloaded
(N
)
8685 and then Comes_From_Source
(Entity
(Original_Node
(N
)))
8686 and then Ekind
(Entity
(Original_Node
(N
))) = E_Function
8690 (Next_Formal
(First_Formal
(Entity
(Original_Node
(N
))))));
8693 -- Otherwise an aggregate may match both the array type and the
8697 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
8698 Set_Etype
(Arg
, Any_Type
);
8702 if Is_Overloaded
(Arg
)
8703 and then Has_Compatible_Type
(Arg
, Typ
)
8704 and then Etype
(Arg
) /= Any_Type
8712 Get_First_Interp
(Arg
, I
, It
);
8714 Get_Next_Interp
(I
, It
);
8716 -- Special-case the error message when the overloading is
8717 -- caused by a function that yields an array and can be
8718 -- called without parameters.
8720 if It
.Nam
= Func
then
8721 Error_Msg_Sloc
:= Sloc
(Func
);
8722 Error_Msg_N
("ambiguous call to function#", Arg
);
8724 ("\\interpretation as call yields&", Arg
, Typ
);
8726 ("\\interpretation as indexing of call yields&",
8727 Arg
, Component_Type
(Typ
));
8730 Error_Msg_N
("ambiguous operand for concatenation!", Arg
);
8732 Get_First_Interp
(Arg
, I
, It
);
8733 while Present
(It
.Nam
) loop
8734 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
8736 if Base_Type
(It
.Typ
) = Btyp
8738 Base_Type
(It
.Typ
) = Base_Type
(Ctyp
)
8740 Error_Msg_N
-- CODEFIX
8741 ("\\possible interpretation#", Arg
);
8744 Get_Next_Interp
(I
, It
);
8750 Resolve
(Arg
, Component_Type
(Typ
));
8752 if Nkind
(Arg
) = N_String_Literal
then
8753 Set_Etype
(Arg
, Component_Type
(Typ
));
8756 if Arg
= Left_Opnd
(N
) then
8757 Set_Is_Component_Left_Opnd
(N
);
8759 Set_Is_Component_Right_Opnd
(N
);
8764 Resolve
(Arg
, Btyp
);
8767 -- Concatenation is restricted in SPARK: each operand must be either a
8768 -- string literal, the name of a string constant, a static character or
8769 -- string expression, or another concatenation. Arg cannot be a
8770 -- concatenation here as callers of Resolve_Op_Concat_Arg call it
8771 -- separately on each final operand, past concatenation operations.
8773 if Is_Character_Type
(Etype
(Arg
)) then
8774 if not Is_OK_Static_Expression
(Arg
) then
8775 Check_SPARK_05_Restriction
8776 ("character operand for concatenation should be static", Arg
);
8779 elsif Is_String_Type
(Etype
(Arg
)) then
8780 if not (Nkind_In
(Arg
, N_Identifier
, N_Expanded_Name
)
8781 and then Is_Constant_Object
(Entity
(Arg
)))
8782 and then not Is_OK_Static_Expression
(Arg
)
8784 Check_SPARK_05_Restriction
8785 ("string operand for concatenation should be static", Arg
);
8788 -- Do not issue error on an operand that is neither a character nor a
8789 -- string, as the error is issued in Resolve_Op_Concat.
8795 Check_Unset_Reference
(Arg
);
8796 end Resolve_Op_Concat_Arg
;
8798 -----------------------------
8799 -- Resolve_Op_Concat_First --
8800 -----------------------------
8802 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
8803 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8804 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8805 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8808 -- The parser folds an enormous sequence of concatenations of string
8809 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
8810 -- in the right operand. If the expression resolves to a predefined "&"
8811 -- operator, all is well. Otherwise, the parser's folding is wrong, so
8812 -- we give an error. See P_Simple_Expression in Par.Ch4.
8814 if Nkind
(Op2
) = N_String_Literal
8815 and then Is_Folded_In_Parser
(Op2
)
8816 and then Ekind
(Entity
(N
)) = E_Function
8818 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
8819 and then String_Length
(Strval
(Op1
)) = 0);
8820 Error_Msg_N
("too many user-defined concatenations", N
);
8824 Set_Etype
(N
, Btyp
);
8826 if Is_Limited_Composite
(Btyp
) then
8827 Error_Msg_N
("concatenation not available for limited array", N
);
8828 Explain_Limited_Type
(Btyp
, N
);
8830 end Resolve_Op_Concat_First
;
8832 ----------------------------
8833 -- Resolve_Op_Concat_Rest --
8834 ----------------------------
8836 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
8837 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8838 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8841 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
8843 Generate_Operator_Reference
(N
, Typ
);
8845 if Is_String_Type
(Typ
) then
8846 Eval_Concatenation
(N
);
8849 -- If this is not a static concatenation, but the result is a string
8850 -- type (and not an array of strings) ensure that static string operands
8851 -- have their subtypes properly constructed.
8853 if Nkind
(N
) /= N_String_Literal
8854 and then Is_Character_Type
(Component_Type
(Typ
))
8856 Set_String_Literal_Subtype
(Op1
, Typ
);
8857 Set_String_Literal_Subtype
(Op2
, Typ
);
8859 end Resolve_Op_Concat_Rest
;
8861 ----------------------
8862 -- Resolve_Op_Expon --
8863 ----------------------
8865 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
8866 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
8869 -- Catch attempts to do fixed-point exponentiation with universal
8870 -- operands, which is a case where the illegality is not caught during
8871 -- normal operator analysis. This is not done in preanalysis mode
8872 -- since the tree is not fully decorated during preanalysis.
8874 if Full_Analysis
then
8875 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
8876 Error_Msg_N
("exponentiation not available for fixed point", N
);
8879 elsif Nkind
(Parent
(N
)) in N_Op
8880 and then Is_Fixed_Point_Type
(Etype
(Parent
(N
)))
8881 and then Etype
(N
) = Universal_Real
8882 and then Comes_From_Source
(N
)
8884 Error_Msg_N
("exponentiation not available for fixed point", N
);
8889 if Comes_From_Source
(N
)
8890 and then Ekind
(Entity
(N
)) = E_Function
8891 and then Is_Imported
(Entity
(N
))
8892 and then Is_Intrinsic_Subprogram
(Entity
(N
))
8894 Resolve_Intrinsic_Operator
(N
, Typ
);
8898 if Etype
(Left_Opnd
(N
)) = Universal_Integer
8899 or else Etype
(Left_Opnd
(N
)) = Universal_Real
8901 Check_For_Visible_Operator
(N
, B_Typ
);
8904 -- We do the resolution using the base type, because intermediate values
8905 -- in expressions are always of the base type, not a subtype of it.
8907 Resolve
(Left_Opnd
(N
), B_Typ
);
8908 Resolve
(Right_Opnd
(N
), Standard_Integer
);
8910 -- For integer types, right argument must be in Natural range
8912 if Is_Integer_Type
(Typ
) then
8913 Apply_Scalar_Range_Check
(Right_Opnd
(N
), Standard_Natural
);
8916 Check_Unset_Reference
(Left_Opnd
(N
));
8917 Check_Unset_Reference
(Right_Opnd
(N
));
8919 Set_Etype
(N
, B_Typ
);
8920 Generate_Operator_Reference
(N
, B_Typ
);
8922 Analyze_Dimension
(N
);
8924 if Ada_Version
>= Ada_2012
and then Has_Dimension_System
(B_Typ
) then
8925 -- Evaluate the exponentiation operator for dimensioned type
8927 Eval_Op_Expon_For_Dimensioned_Type
(N
, B_Typ
);
8932 -- Set overflow checking bit. Much cleverer code needed here eventually
8933 -- and perhaps the Resolve routines should be separated for the various
8934 -- arithmetic operations, since they will need different processing. ???
8936 if Nkind
(N
) in N_Op
then
8937 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
8938 Enable_Overflow_Check
(N
);
8941 end Resolve_Op_Expon
;
8943 --------------------
8944 -- Resolve_Op_Not --
8945 --------------------
8947 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
8950 function Parent_Is_Boolean
return Boolean;
8951 -- This function determines if the parent node is a boolean operator or
8952 -- operation (comparison op, membership test, or short circuit form) and
8953 -- the not in question is the left operand of this operation. Note that
8954 -- if the not is in parens, then false is returned.
8956 -----------------------
8957 -- Parent_Is_Boolean --
8958 -----------------------
8960 function Parent_Is_Boolean
return Boolean is
8962 if Paren_Count
(N
) /= 0 then
8966 case Nkind
(Parent
(N
)) is
8981 return Left_Opnd
(Parent
(N
)) = N
;
8987 end Parent_Is_Boolean
;
8989 -- Start of processing for Resolve_Op_Not
8992 -- Predefined operations on scalar types yield the base type. On the
8993 -- other hand, logical operations on arrays yield the type of the
8994 -- arguments (and the context).
8996 if Is_Array_Type
(Typ
) then
8999 B_Typ
:= Base_Type
(Typ
);
9002 -- Straightforward case of incorrect arguments
9004 if not Valid_Boolean_Arg
(Typ
) then
9005 Error_Msg_N
("invalid operand type for operator&", N
);
9006 Set_Etype
(N
, Any_Type
);
9009 -- Special case of probable missing parens
9011 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
9012 if Parent_Is_Boolean
then
9014 ("operand of not must be enclosed in parentheses",
9018 ("no modular type available in this context", N
);
9021 Set_Etype
(N
, Any_Type
);
9024 -- OK resolution of NOT
9027 -- Warn if non-boolean types involved. This is a case like not a < b
9028 -- where a and b are modular, where we will get (not a) < b and most
9029 -- likely not (a < b) was intended.
9031 if Warn_On_Questionable_Missing_Parens
9032 and then not Is_Boolean_Type
(Typ
)
9033 and then Parent_Is_Boolean
9035 Error_Msg_N
("?q?not expression should be parenthesized here!", N
);
9038 -- Warn on double negation if checking redundant constructs
9040 if Warn_On_Redundant_Constructs
9041 and then Comes_From_Source
(N
)
9042 and then Comes_From_Source
(Right_Opnd
(N
))
9043 and then Root_Type
(Typ
) = Standard_Boolean
9044 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
9046 Error_Msg_N
("redundant double negation?r?", N
);
9049 -- Complete resolution and evaluation of NOT
9051 Resolve
(Right_Opnd
(N
), B_Typ
);
9052 Check_Unset_Reference
(Right_Opnd
(N
));
9053 Set_Etype
(N
, B_Typ
);
9054 Generate_Operator_Reference
(N
, B_Typ
);
9059 -----------------------------
9060 -- Resolve_Operator_Symbol --
9061 -----------------------------
9063 -- Nothing to be done, all resolved already
9065 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
9066 pragma Warnings
(Off
, N
);
9067 pragma Warnings
(Off
, Typ
);
9071 end Resolve_Operator_Symbol
;
9073 ----------------------------------
9074 -- Resolve_Qualified_Expression --
9075 ----------------------------------
9077 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9078 pragma Warnings
(Off
, Typ
);
9080 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
9081 Expr
: constant Node_Id
:= Expression
(N
);
9084 Resolve
(Expr
, Target_Typ
);
9086 -- Protect call to Matching_Static_Array_Bounds to avoid costly
9087 -- operation if not needed.
9089 if Restriction_Check_Required
(SPARK_05
)
9090 and then Is_Array_Type
(Target_Typ
)
9091 and then Is_Array_Type
(Etype
(Expr
))
9092 and then Etype
(Expr
) /= Any_Composite
-- or else Expr in error
9093 and then not Matching_Static_Array_Bounds
(Target_Typ
, Etype
(Expr
))
9095 Check_SPARK_05_Restriction
9096 ("array types should have matching static bounds", N
);
9099 -- A qualified expression requires an exact match of the type, class-
9100 -- wide matching is not allowed. However, if the qualifying type is
9101 -- specific and the expression has a class-wide type, it may still be
9102 -- okay, since it can be the result of the expansion of a call to a
9103 -- dispatching function, so we also have to check class-wideness of the
9104 -- type of the expression's original node.
9106 if (Is_Class_Wide_Type
(Target_Typ
)
9108 (Is_Class_Wide_Type
(Etype
(Expr
))
9109 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
9110 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
9112 Wrong_Type
(Expr
, Target_Typ
);
9115 -- If the target type is unconstrained, then we reset the type of the
9116 -- result from the type of the expression. For other cases, the actual
9117 -- subtype of the expression is the target type.
9119 if Is_Composite_Type
(Target_Typ
)
9120 and then not Is_Constrained
(Target_Typ
)
9122 Set_Etype
(N
, Etype
(Expr
));
9125 Analyze_Dimension
(N
);
9126 Eval_Qualified_Expression
(N
);
9128 -- If we still have a qualified expression after the static evaluation,
9129 -- then apply a scalar range check if needed. The reason that we do this
9130 -- after the Eval call is that otherwise, the application of the range
9131 -- check may convert an illegal static expression and result in warning
9132 -- rather than giving an error (e.g Integer'(Integer'Last + 1)).
9134 if Nkind
(N
) = N_Qualified_Expression
and then Is_Scalar_Type
(Typ
) then
9135 Apply_Scalar_Range_Check
(Expr
, Typ
);
9137 end Resolve_Qualified_Expression
;
9139 ------------------------------
9140 -- Resolve_Raise_Expression --
9141 ------------------------------
9143 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9145 if Typ
= Raise_Type
then
9146 Error_Msg_N
("cannot find unique type for raise expression", N
);
9147 Set_Etype
(N
, Any_Type
);
9151 end Resolve_Raise_Expression
;
9157 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
9158 L
: constant Node_Id
:= Low_Bound
(N
);
9159 H
: constant Node_Id
:= High_Bound
(N
);
9161 function First_Last_Ref
return Boolean;
9162 -- Returns True if N is of the form X'First .. X'Last where X is the
9163 -- same entity for both attributes.
9165 --------------------
9166 -- First_Last_Ref --
9167 --------------------
9169 function First_Last_Ref
return Boolean is
9170 Lorig
: constant Node_Id
:= Original_Node
(L
);
9171 Horig
: constant Node_Id
:= Original_Node
(H
);
9174 if Nkind
(Lorig
) = N_Attribute_Reference
9175 and then Nkind
(Horig
) = N_Attribute_Reference
9176 and then Attribute_Name
(Lorig
) = Name_First
9177 and then Attribute_Name
(Horig
) = Name_Last
9180 PL
: constant Node_Id
:= Prefix
(Lorig
);
9181 PH
: constant Node_Id
:= Prefix
(Horig
);
9183 if Is_Entity_Name
(PL
)
9184 and then Is_Entity_Name
(PH
)
9185 and then Entity
(PL
) = Entity
(PH
)
9195 -- Start of processing for Resolve_Range
9202 -- Check for inappropriate range on unordered enumeration type
9204 if Bad_Unordered_Enumeration_Reference
(N
, Typ
)
9206 -- Exclude X'First .. X'Last if X is the same entity for both
9208 and then not First_Last_Ref
9210 Error_Msg_Sloc
:= Sloc
(Typ
);
9212 ("subrange of unordered enumeration type& declared#?U?", N
, Typ
);
9215 Check_Unset_Reference
(L
);
9216 Check_Unset_Reference
(H
);
9218 -- We have to check the bounds for being within the base range as
9219 -- required for a non-static context. Normally this is automatic and
9220 -- done as part of evaluating expressions, but the N_Range node is an
9221 -- exception, since in GNAT we consider this node to be a subexpression,
9222 -- even though in Ada it is not. The circuit in Sem_Eval could check for
9223 -- this, but that would put the test on the main evaluation path for
9226 Check_Non_Static_Context
(L
);
9227 Check_Non_Static_Context
(H
);
9229 -- Check for an ambiguous range over character literals. This will
9230 -- happen with a membership test involving only literals.
9232 if Typ
= Any_Character
then
9233 Ambiguous_Character
(L
);
9234 Set_Etype
(N
, Any_Type
);
9238 -- If bounds are static, constant-fold them, so size computations are
9239 -- identical between front-end and back-end. Do not perform this
9240 -- transformation while analyzing generic units, as type information
9241 -- would be lost when reanalyzing the constant node in the instance.
9243 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
9244 if Is_OK_Static_Expression
(L
) then
9245 Fold_Uint
(L
, Expr_Value
(L
), Is_OK_Static_Expression
(L
));
9248 if Is_OK_Static_Expression
(H
) then
9249 Fold_Uint
(H
, Expr_Value
(H
), Is_OK_Static_Expression
(H
));
9254 --------------------------
9255 -- Resolve_Real_Literal --
9256 --------------------------
9258 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9259 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
9262 -- Special processing for fixed-point literals to make sure that the
9263 -- value is an exact multiple of small where this is required. We skip
9264 -- this for the universal real case, and also for generic types.
9266 if Is_Fixed_Point_Type
(Typ
)
9267 and then Typ
/= Universal_Fixed
9268 and then Typ
/= Any_Fixed
9269 and then not Is_Generic_Type
(Typ
)
9272 Val
: constant Ureal
:= Realval
(N
);
9273 Cintr
: constant Ureal
:= Val
/ Small_Value
(Typ
);
9274 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
9275 Den
: constant Uint
:= Norm_Den
(Cintr
);
9279 -- Case of literal is not an exact multiple of the Small
9283 -- For a source program literal for a decimal fixed-point type,
9284 -- this is statically illegal (RM 4.9(36)).
9286 if Is_Decimal_Fixed_Point_Type
(Typ
)
9287 and then Actual_Typ
= Universal_Real
9288 and then Comes_From_Source
(N
)
9290 Error_Msg_N
("value has extraneous low order digits", N
);
9293 -- Generate a warning if literal from source
9295 if Is_OK_Static_Expression
(N
)
9296 and then Warn_On_Bad_Fixed_Value
9299 ("?b?static fixed-point value is not a multiple of Small!",
9303 -- Replace literal by a value that is the exact representation
9304 -- of a value of the type, i.e. a multiple of the small value,
9305 -- by truncation, since Machine_Rounds is false for all GNAT
9306 -- fixed-point types (RM 4.9(38)).
9308 Stat
:= Is_OK_Static_Expression
(N
);
9310 Make_Real_Literal
(Sloc
(N
),
9311 Realval
=> Small_Value
(Typ
) * Cint
));
9313 Set_Is_Static_Expression
(N
, Stat
);
9316 -- In all cases, set the corresponding integer field
9318 Set_Corresponding_Integer_Value
(N
, Cint
);
9322 -- Now replace the actual type by the expected type as usual
9325 Eval_Real_Literal
(N
);
9326 end Resolve_Real_Literal
;
9328 -----------------------
9329 -- Resolve_Reference --
9330 -----------------------
9332 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
9333 P
: constant Node_Id
:= Prefix
(N
);
9336 -- Replace general access with specific type
9338 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
9339 Set_Etype
(N
, Base_Type
(Typ
));
9342 Resolve
(P
, Designated_Type
(Etype
(N
)));
9344 -- If we are taking the reference of a volatile entity, then treat it as
9345 -- a potential modification of this entity. This is too conservative,
9346 -- but necessary because remove side effects can cause transformations
9347 -- of normal assignments into reference sequences that otherwise fail to
9348 -- notice the modification.
9350 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
9351 Note_Possible_Modification
(P
, Sure
=> False);
9353 end Resolve_Reference
;
9355 --------------------------------
9356 -- Resolve_Selected_Component --
9357 --------------------------------
9359 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
9361 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
9362 P
: constant Node_Id
:= Prefix
(N
);
9363 S
: constant Node_Id
:= Selector_Name
(N
);
9364 T
: Entity_Id
:= Etype
(P
);
9366 I1
: Interp_Index
:= 0; -- prevent junk warning
9371 function Init_Component
return Boolean;
9372 -- Check whether this is the initialization of a component within an
9373 -- init proc (by assignment or call to another init proc). If true,
9374 -- there is no need for a discriminant check.
9376 --------------------
9377 -- Init_Component --
9378 --------------------
9380 function Init_Component
return Boolean is
9382 return Inside_Init_Proc
9383 and then Nkind
(Prefix
(N
)) = N_Identifier
9384 and then Chars
(Prefix
(N
)) = Name_uInit
9385 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
9388 -- Start of processing for Resolve_Selected_Component
9391 if Is_Overloaded
(P
) then
9393 -- Use the context type to select the prefix that has a selector
9394 -- of the correct name and type.
9397 Get_First_Interp
(P
, I
, It
);
9399 Search
: while Present
(It
.Typ
) loop
9400 if Is_Access_Type
(It
.Typ
) then
9401 T
:= Designated_Type
(It
.Typ
);
9406 -- Locate selected component. For a private prefix the selector
9407 -- can denote a discriminant.
9409 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
9411 -- The visible components of a class-wide type are those of
9414 if Is_Class_Wide_Type
(T
) then
9418 Comp
:= First_Entity
(T
);
9419 while Present
(Comp
) loop
9420 if Chars
(Comp
) = Chars
(S
)
9421 and then Covers
(Typ
, Etype
(Comp
))
9430 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9432 if It
= No_Interp
then
9434 ("ambiguous prefix for selected component", N
);
9441 -- There may be an implicit dereference. Retrieve
9442 -- designated record type.
9444 if Is_Access_Type
(It1
.Typ
) then
9445 T
:= Designated_Type
(It1
.Typ
);
9450 if Scope
(Comp1
) /= T
then
9452 -- Resolution chooses the new interpretation.
9453 -- Find the component with the right name.
9455 Comp1
:= First_Entity
(T
);
9456 while Present
(Comp1
)
9457 and then Chars
(Comp1
) /= Chars
(S
)
9459 Comp1
:= Next_Entity
(Comp1
);
9468 Comp
:= Next_Entity
(Comp
);
9472 Get_Next_Interp
(I
, It
);
9475 -- There must be a legal interpretation at this point
9477 pragma Assert
(Found
);
9478 Resolve
(P
, It1
.Typ
);
9480 Set_Entity_With_Checks
(S
, Comp1
);
9483 -- Resolve prefix with its type
9488 -- Generate cross-reference. We needed to wait until full overloading
9489 -- resolution was complete to do this, since otherwise we can't tell if
9490 -- we are an lvalue or not.
9492 if May_Be_Lvalue
(N
) then
9493 Generate_Reference
(Entity
(S
), S
, 'm');
9495 Generate_Reference
(Entity
(S
), S
, 'r');
9498 -- If prefix is an access type, the node will be transformed into an
9499 -- explicit dereference during expansion. The type of the node is the
9500 -- designated type of that of the prefix.
9502 if Is_Access_Type
(Etype
(P
)) then
9503 T
:= Designated_Type
(Etype
(P
));
9504 Check_Fully_Declared_Prefix
(T
, P
);
9509 -- Set flag for expander if discriminant check required
9511 if Has_Discriminants
(T
)
9512 and then Ekind_In
(Entity
(S
), E_Component
, E_Discriminant
)
9513 and then Present
(Original_Record_Component
(Entity
(S
)))
9514 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
9515 and then not Discriminant_Checks_Suppressed
(T
)
9516 and then not Init_Component
9518 Set_Do_Discriminant_Check
(N
);
9521 if Ekind
(Entity
(S
)) = E_Void
then
9522 Error_Msg_N
("premature use of component", S
);
9525 -- If the prefix is a record conversion, this may be a renamed
9526 -- discriminant whose bounds differ from those of the original
9527 -- one, so we must ensure that a range check is performed.
9529 if Nkind
(P
) = N_Type_Conversion
9530 and then Ekind
(Entity
(S
)) = E_Discriminant
9531 and then Is_Discrete_Type
(Typ
)
9533 Set_Etype
(N
, Base_Type
(Typ
));
9536 -- Note: No Eval processing is required, because the prefix is of a
9537 -- record type, or protected type, and neither can possibly be static.
9539 -- If the record type is atomic, and the component is non-atomic, then
9540 -- this is worth a warning, since we have a situation where the access
9541 -- to the component may cause extra read/writes of the atomic array
9542 -- object, or partial word accesses, both of which may be unexpected.
9544 if Nkind
(N
) = N_Selected_Component
9545 and then Is_Atomic_Ref_With_Address
(N
)
9546 and then not Is_Atomic
(Entity
(S
))
9547 and then not Is_Atomic
(Etype
(Entity
(S
)))
9550 ("??access to non-atomic component of atomic record",
9553 ("\??may cause unexpected accesses to atomic object",
9557 Analyze_Dimension
(N
);
9558 end Resolve_Selected_Component
;
9564 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
9565 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9566 L
: constant Node_Id
:= Left_Opnd
(N
);
9567 R
: constant Node_Id
:= Right_Opnd
(N
);
9570 -- We do the resolution using the base type, because intermediate values
9571 -- in expressions always are of the base type, not a subtype of it.
9574 Resolve
(R
, Standard_Natural
);
9576 Check_Unset_Reference
(L
);
9577 Check_Unset_Reference
(R
);
9579 Set_Etype
(N
, B_Typ
);
9580 Generate_Operator_Reference
(N
, B_Typ
);
9584 ---------------------------
9585 -- Resolve_Short_Circuit --
9586 ---------------------------
9588 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
9589 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9590 L
: constant Node_Id
:= Left_Opnd
(N
);
9591 R
: constant Node_Id
:= Right_Opnd
(N
);
9594 -- Ensure all actions associated with the left operand (e.g.
9595 -- finalization of transient controlled objects) are fully evaluated
9596 -- locally within an expression with actions. This is particularly
9597 -- helpful for coverage analysis. However this should not happen in
9600 if Expander_Active
then
9602 Reloc_L
: constant Node_Id
:= Relocate_Node
(L
);
9604 Save_Interps
(Old_N
=> L
, New_N
=> Reloc_L
);
9607 Make_Expression_With_Actions
(Sloc
(L
),
9608 Actions
=> New_List
,
9609 Expression
=> Reloc_L
));
9611 -- Set Comes_From_Source on L to preserve warnings for unset
9614 Set_Comes_From_Source
(L
, Comes_From_Source
(Reloc_L
));
9621 -- Check for issuing warning for always False assert/check, this happens
9622 -- when assertions are turned off, in which case the pragma Assert/Check
9623 -- was transformed into:
9625 -- if False and then <condition> then ...
9627 -- and we detect this pattern
9629 if Warn_On_Assertion_Failure
9630 and then Is_Entity_Name
(R
)
9631 and then Entity
(R
) = Standard_False
9632 and then Nkind
(Parent
(N
)) = N_If_Statement
9633 and then Nkind
(N
) = N_And_Then
9634 and then Is_Entity_Name
(L
)
9635 and then Entity
(L
) = Standard_False
9638 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
9641 -- Special handling of Asssert pragma
9643 if Nkind
(Orig
) = N_Pragma
9644 and then Pragma_Name
(Orig
) = Name_Assert
9647 Expr
: constant Node_Id
:=
9650 (First
(Pragma_Argument_Associations
(Orig
))));
9653 -- Don't warn if original condition is explicit False,
9654 -- since obviously the failure is expected in this case.
9656 if Is_Entity_Name
(Expr
)
9657 and then Entity
(Expr
) = Standard_False
9661 -- Issue warning. We do not want the deletion of the
9662 -- IF/AND-THEN to take this message with it. We achieve this
9663 -- by making sure that the expanded code points to the Sloc
9664 -- of the expression, not the original pragma.
9667 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
9668 -- The source location of the expression is not usually
9669 -- the best choice here. For example, it gets located on
9670 -- the last AND keyword in a chain of boolean expressiond
9671 -- AND'ed together. It is best to put the message on the
9672 -- first character of the assertion, which is the effect
9673 -- of the First_Node call here.
9676 ("?A?assertion would fail at run time!",
9678 (First
(Pragma_Argument_Associations
(Orig
))));
9682 -- Similar processing for Check pragma
9684 elsif Nkind
(Orig
) = N_Pragma
9685 and then Pragma_Name
(Orig
) = Name_Check
9687 -- Don't want to warn if original condition is explicit False
9690 Expr
: constant Node_Id
:=
9693 (Next
(First
(Pragma_Argument_Associations
(Orig
)))));
9695 if Is_Entity_Name
(Expr
)
9696 and then Entity
(Expr
) = Standard_False
9703 -- Again use Error_Msg_F rather than Error_Msg_N, see
9704 -- comment above for an explanation of why we do this.
9707 ("?A?check would fail at run time!",
9709 (Last
(Pragma_Argument_Associations
(Orig
))));
9716 -- Continue with processing of short circuit
9718 Check_Unset_Reference
(L
);
9719 Check_Unset_Reference
(R
);
9721 Set_Etype
(N
, B_Typ
);
9722 Eval_Short_Circuit
(N
);
9723 end Resolve_Short_Circuit
;
9729 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
9730 Drange
: constant Node_Id
:= Discrete_Range
(N
);
9731 Name
: constant Node_Id
:= Prefix
(N
);
9732 Array_Type
: Entity_Id
:= Empty
;
9733 Dexpr
: Node_Id
:= Empty
;
9734 Index_Type
: Entity_Id
;
9737 if Is_Overloaded
(Name
) then
9739 -- Use the context type to select the prefix that yields the correct
9744 I1
: Interp_Index
:= 0;
9746 P
: constant Node_Id
:= Prefix
(N
);
9747 Found
: Boolean := False;
9750 Get_First_Interp
(P
, I
, It
);
9751 while Present
(It
.Typ
) loop
9752 if (Is_Array_Type
(It
.Typ
)
9753 and then Covers
(Typ
, It
.Typ
))
9754 or else (Is_Access_Type
(It
.Typ
)
9755 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
9756 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
9759 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9761 if It
= No_Interp
then
9762 Error_Msg_N
("ambiguous prefix for slicing", N
);
9767 Array_Type
:= It
.Typ
;
9772 Array_Type
:= It
.Typ
;
9777 Get_Next_Interp
(I
, It
);
9782 Array_Type
:= Etype
(Name
);
9785 Resolve
(Name
, Array_Type
);
9787 if Is_Access_Type
(Array_Type
) then
9788 Apply_Access_Check
(N
);
9789 Array_Type
:= Designated_Type
(Array_Type
);
9791 -- If the prefix is an access to an unconstrained array, we must use
9792 -- the actual subtype of the object to perform the index checks. The
9793 -- object denoted by the prefix is implicit in the node, so we build
9794 -- an explicit representation for it in order to compute the actual
9797 if not Is_Constrained
(Array_Type
) then
9798 Remove_Side_Effects
(Prefix
(N
));
9801 Obj
: constant Node_Id
:=
9802 Make_Explicit_Dereference
(Sloc
(N
),
9803 Prefix
=> New_Copy_Tree
(Prefix
(N
)));
9805 Set_Etype
(Obj
, Array_Type
);
9806 Set_Parent
(Obj
, Parent
(N
));
9807 Array_Type
:= Get_Actual_Subtype
(Obj
);
9811 elsif Is_Entity_Name
(Name
)
9812 or else Nkind
(Name
) = N_Explicit_Dereference
9813 or else (Nkind
(Name
) = N_Function_Call
9814 and then not Is_Constrained
(Etype
(Name
)))
9816 Array_Type
:= Get_Actual_Subtype
(Name
);
9818 -- If the name is a selected component that depends on discriminants,
9819 -- build an actual subtype for it. This can happen only when the name
9820 -- itself is overloaded; otherwise the actual subtype is created when
9821 -- the selected component is analyzed.
9823 elsif Nkind
(Name
) = N_Selected_Component
9824 and then Full_Analysis
9825 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
9828 Act_Decl
: constant Node_Id
:=
9829 Build_Actual_Subtype_Of_Component
(Array_Type
, Name
);
9831 Insert_Action
(N
, Act_Decl
);
9832 Array_Type
:= Defining_Identifier
(Act_Decl
);
9835 -- Maybe this should just be "else", instead of checking for the
9836 -- specific case of slice??? This is needed for the case where the
9837 -- prefix is an Image attribute, which gets expanded to a slice, and so
9838 -- has a constrained subtype which we want to use for the slice range
9839 -- check applied below (the range check won't get done if the
9840 -- unconstrained subtype of the 'Image is used).
9842 elsif Nkind
(Name
) = N_Slice
then
9843 Array_Type
:= Etype
(Name
);
9846 -- Obtain the type of the array index
9848 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
9849 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
9851 Index_Type
:= Etype
(First_Index
(Array_Type
));
9854 -- If name was overloaded, set slice type correctly now
9856 Set_Etype
(N
, Array_Type
);
9858 -- Handle the generation of a range check that compares the array index
9859 -- against the discrete_range. The check is not applied to internally
9860 -- built nodes associated with the expansion of dispatch tables. Check
9861 -- that Ada.Tags has already been loaded to avoid extra dependencies on
9864 if Tagged_Type_Expansion
9865 and then RTU_Loaded
(Ada_Tags
)
9866 and then Nkind
(Prefix
(N
)) = N_Selected_Component
9867 and then Present
(Entity
(Selector_Name
(Prefix
(N
))))
9868 and then Entity
(Selector_Name
(Prefix
(N
))) =
9869 RTE_Record_Component
(RE_Prims_Ptr
)
9873 -- The discrete_range is specified by a subtype indication. Create a
9874 -- shallow copy and inherit the type, parent and source location from
9875 -- the discrete_range. This ensures that the range check is inserted
9876 -- relative to the slice and that the runtime exception points to the
9877 -- proper construct.
9879 elsif Is_Entity_Name
(Drange
) then
9880 Dexpr
:= New_Copy
(Scalar_Range
(Entity
(Drange
)));
9882 Set_Etype
(Dexpr
, Etype
(Drange
));
9883 Set_Parent
(Dexpr
, Parent
(Drange
));
9884 Set_Sloc
(Dexpr
, Sloc
(Drange
));
9886 -- The discrete_range is a regular range. Resolve the bounds and remove
9887 -- their side effects.
9890 Resolve
(Drange
, Base_Type
(Index_Type
));
9892 if Nkind
(Drange
) = N_Range
then
9893 Force_Evaluation
(Low_Bound
(Drange
));
9894 Force_Evaluation
(High_Bound
(Drange
));
9900 if Present
(Dexpr
) then
9901 Apply_Range_Check
(Dexpr
, Index_Type
);
9904 Set_Slice_Subtype
(N
);
9906 -- Check bad use of type with predicates
9912 if Nkind
(Drange
) = N_Subtype_Indication
9913 and then Has_Predicates
(Entity
(Subtype_Mark
(Drange
)))
9915 Subt
:= Entity
(Subtype_Mark
(Drange
));
9917 Subt
:= Etype
(Drange
);
9920 if Has_Predicates
(Subt
) then
9921 Bad_Predicated_Subtype_Use
9922 ("subtype& has predicate, not allowed in slice", Drange
, Subt
);
9926 -- Otherwise here is where we check suspicious indexes
9928 if Nkind
(Drange
) = N_Range
then
9929 Warn_On_Suspicious_Index
(Name
, Low_Bound
(Drange
));
9930 Warn_On_Suspicious_Index
(Name
, High_Bound
(Drange
));
9933 Analyze_Dimension
(N
);
9937 ----------------------------
9938 -- Resolve_String_Literal --
9939 ----------------------------
9941 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9942 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
9943 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
9944 Loc
: constant Source_Ptr
:= Sloc
(N
);
9945 Str
: constant String_Id
:= Strval
(N
);
9946 Strlen
: constant Nat
:= String_Length
(Str
);
9947 Subtype_Id
: Entity_Id
;
9948 Need_Check
: Boolean;
9951 -- For a string appearing in a concatenation, defer creation of the
9952 -- string_literal_subtype until the end of the resolution of the
9953 -- concatenation, because the literal may be constant-folded away. This
9954 -- is a useful optimization for long concatenation expressions.
9956 -- If the string is an aggregate built for a single character (which
9957 -- happens in a non-static context) or a is null string to which special
9958 -- checks may apply, we build the subtype. Wide strings must also get a
9959 -- string subtype if they come from a one character aggregate. Strings
9960 -- generated by attributes might be static, but it is often hard to
9961 -- determine whether the enclosing context is static, so we generate
9962 -- subtypes for them as well, thus losing some rarer optimizations ???
9963 -- Same for strings that come from a static conversion.
9966 (Strlen
= 0 and then Typ
/= Standard_String
)
9967 or else Nkind
(Parent
(N
)) /= N_Op_Concat
9968 or else (N
/= Left_Opnd
(Parent
(N
))
9969 and then N
/= Right_Opnd
(Parent
(N
)))
9970 or else ((Typ
= Standard_Wide_String
9971 or else Typ
= Standard_Wide_Wide_String
)
9972 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
9974 -- If the resolving type is itself a string literal subtype, we can just
9975 -- reuse it, since there is no point in creating another.
9977 if Ekind
(Typ
) = E_String_Literal_Subtype
then
9980 elsif Nkind
(Parent
(N
)) = N_Op_Concat
9981 and then not Need_Check
9982 and then not Nkind_In
(Original_Node
(N
), N_Character_Literal
,
9983 N_Attribute_Reference
,
9984 N_Qualified_Expression
,
9989 -- Do not generate a string literal subtype for the default expression
9990 -- of a formal parameter in GNATprove mode. This is because the string
9991 -- subtype is associated with the freezing actions of the subprogram,
9992 -- however freezing is disabled in GNATprove mode and as a result the
9993 -- subtype is unavailable.
9995 elsif GNATprove_Mode
9996 and then Nkind
(Parent
(N
)) = N_Parameter_Specification
10000 -- Otherwise we must create a string literal subtype. Note that the
10001 -- whole idea of string literal subtypes is simply to avoid the need
10002 -- for building a full fledged array subtype for each literal.
10005 Set_String_Literal_Subtype
(N
, Typ
);
10006 Subtype_Id
:= Etype
(N
);
10009 if Nkind
(Parent
(N
)) /= N_Op_Concat
10012 Set_Etype
(N
, Subtype_Id
);
10013 Eval_String_Literal
(N
);
10016 if Is_Limited_Composite
(Typ
)
10017 or else Is_Private_Composite
(Typ
)
10019 Error_Msg_N
("string literal not available for private array", N
);
10020 Set_Etype
(N
, Any_Type
);
10024 -- The validity of a null string has been checked in the call to
10025 -- Eval_String_Literal.
10030 -- Always accept string literal with component type Any_Character, which
10031 -- occurs in error situations and in comparisons of literals, both of
10032 -- which should accept all literals.
10034 elsif R_Typ
= Any_Character
then
10037 -- If the type is bit-packed, then we always transform the string
10038 -- literal into a full fledged aggregate.
10040 elsif Is_Bit_Packed_Array
(Typ
) then
10043 -- Deal with cases of Wide_Wide_String, Wide_String, and String
10046 -- For Standard.Wide_Wide_String, or any other type whose component
10047 -- type is Standard.Wide_Wide_Character, we know that all the
10048 -- characters in the string must be acceptable, since the parser
10049 -- accepted the characters as valid character literals.
10051 if R_Typ
= Standard_Wide_Wide_Character
then
10054 -- For the case of Standard.String, or any other type whose component
10055 -- type is Standard.Character, we must make sure that there are no
10056 -- wide characters in the string, i.e. that it is entirely composed
10057 -- of characters in range of type Character.
10059 -- If the string literal is the result of a static concatenation, the
10060 -- test has already been performed on the components, and need not be
10063 elsif R_Typ
= Standard_Character
10064 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
10066 for J
in 1 .. Strlen
loop
10067 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
10069 -- If we are out of range, post error. This is one of the
10070 -- very few places that we place the flag in the middle of
10071 -- a token, right under the offending wide character. Not
10072 -- quite clear if this is right wrt wide character encoding
10073 -- sequences, but it's only an error message.
10076 ("literal out of range of type Standard.Character",
10077 Source_Ptr
(Int
(Loc
) + J
));
10082 -- For the case of Standard.Wide_String, or any other type whose
10083 -- component type is Standard.Wide_Character, we must make sure that
10084 -- there are no wide characters in the string, i.e. that it is
10085 -- entirely composed of characters in range of type Wide_Character.
10087 -- If the string literal is the result of a static concatenation,
10088 -- the test has already been performed on the components, and need
10089 -- not be repeated.
10091 elsif R_Typ
= Standard_Wide_Character
10092 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
10094 for J
in 1 .. Strlen
loop
10095 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
10097 -- If we are out of range, post error. This is one of the
10098 -- very few places that we place the flag in the middle of
10099 -- a token, right under the offending wide character.
10101 -- This is not quite right, because characters in general
10102 -- will take more than one character position ???
10105 ("literal out of range of type Standard.Wide_Character",
10106 Source_Ptr
(Int
(Loc
) + J
));
10111 -- If the root type is not a standard character, then we will convert
10112 -- the string into an aggregate and will let the aggregate code do
10113 -- the checking. Standard Wide_Wide_Character is also OK here.
10119 -- See if the component type of the array corresponding to the string
10120 -- has compile time known bounds. If yes we can directly check
10121 -- whether the evaluation of the string will raise constraint error.
10122 -- Otherwise we need to transform the string literal into the
10123 -- corresponding character aggregate and let the aggregate code do
10126 if Is_Standard_Character_Type
(R_Typ
) then
10128 -- Check for the case of full range, where we are definitely OK
10130 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
10134 -- Here the range is not the complete base type range, so check
10137 Comp_Typ_Lo
: constant Node_Id
:=
10138 Type_Low_Bound
(Component_Type
(Typ
));
10139 Comp_Typ_Hi
: constant Node_Id
:=
10140 Type_High_Bound
(Component_Type
(Typ
));
10145 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
10146 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
10148 for J
in 1 .. Strlen
loop
10149 Char_Val
:= UI_From_Int
(Int
(Get_String_Char
(Str
, J
)));
10151 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
10152 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
10154 Apply_Compile_Time_Constraint_Error
10155 (N
, "character out of range??",
10156 CE_Range_Check_Failed
,
10157 Loc
=> Source_Ptr
(Int
(Loc
) + J
));
10167 -- If we got here we meed to transform the string literal into the
10168 -- equivalent qualified positional array aggregate. This is rather
10169 -- heavy artillery for this situation, but it is hard work to avoid.
10172 Lits
: constant List_Id
:= New_List
;
10173 P
: Source_Ptr
:= Loc
+ 1;
10177 -- Build the character literals, we give them source locations that
10178 -- correspond to the string positions, which is a bit tricky given
10179 -- the possible presence of wide character escape sequences.
10181 for J
in 1 .. Strlen
loop
10182 C
:= Get_String_Char
(Str
, J
);
10183 Set_Character_Literal_Name
(C
);
10186 Make_Character_Literal
(P
,
10187 Chars
=> Name_Find
,
10188 Char_Literal_Value
=> UI_From_CC
(C
)));
10190 if In_Character_Range
(C
) then
10193 -- Should we have a call to Skip_Wide here ???
10202 Make_Qualified_Expression
(Loc
,
10203 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
10205 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
10207 Analyze_And_Resolve
(N
, Typ
);
10209 end Resolve_String_Literal
;
10211 -----------------------------
10212 -- Resolve_Type_Conversion --
10213 -----------------------------
10215 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
10216 Conv_OK
: constant Boolean := Conversion_OK
(N
);
10217 Operand
: constant Node_Id
:= Expression
(N
);
10218 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
10219 Target_Typ
: constant Entity_Id
:= Etype
(N
);
10224 Test_Redundant
: Boolean := Warn_On_Redundant_Constructs
;
10225 -- Set to False to suppress cases where we want to suppress the test
10226 -- for redundancy to avoid possible false positives on this warning.
10230 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
10235 -- If the Operand Etype is Universal_Fixed, then the conversion is
10236 -- never redundant. We need this check because by the time we have
10237 -- finished the rather complex transformation, the conversion looks
10238 -- redundant when it is not.
10240 if Operand_Typ
= Universal_Fixed
then
10241 Test_Redundant
:= False;
10243 -- If the operand is marked as Any_Fixed, then special processing is
10244 -- required. This is also a case where we suppress the test for a
10245 -- redundant conversion, since most certainly it is not redundant.
10247 elsif Operand_Typ
= Any_Fixed
then
10248 Test_Redundant
:= False;
10250 -- Mixed-mode operation involving a literal. Context must be a fixed
10251 -- type which is applied to the literal subsequently.
10253 if Is_Fixed_Point_Type
(Typ
) then
10254 Set_Etype
(Operand
, Universal_Real
);
10256 elsif Is_Numeric_Type
(Typ
)
10257 and then Nkind_In
(Operand
, N_Op_Multiply
, N_Op_Divide
)
10258 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
10260 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
10262 -- Return if expression is ambiguous
10264 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
10267 -- If nothing else, the available fixed type is Duration
10270 Set_Etype
(Operand
, Standard_Duration
);
10273 -- Resolve the real operand with largest available precision
10275 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
10276 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
10278 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
10281 Resolve
(Rop
, Universal_Real
);
10283 -- If the operand is a literal (it could be a non-static and
10284 -- illegal exponentiation) check whether the use of Duration
10285 -- is potentially inaccurate.
10287 if Nkind
(Rop
) = N_Real_Literal
10288 and then Realval
(Rop
) /= Ureal_0
10289 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
10292 ("??universal real operand can only "
10293 & "be interpreted as Duration!", Rop
);
10295 ("\??precision will be lost in the conversion!", Rop
);
10298 elsif Is_Numeric_Type
(Typ
)
10299 and then Nkind
(Operand
) in N_Op
10300 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
10302 Set_Etype
(Operand
, Standard_Duration
);
10305 Error_Msg_N
("invalid context for mixed mode operation", N
);
10306 Set_Etype
(Operand
, Any_Type
);
10313 -- In SPARK, a type conversion between array types should be restricted
10314 -- to types which have matching static bounds.
10316 -- Protect call to Matching_Static_Array_Bounds to avoid costly
10317 -- operation if not needed.
10319 if Restriction_Check_Required
(SPARK_05
)
10320 and then Is_Array_Type
(Target_Typ
)
10321 and then Is_Array_Type
(Operand_Typ
)
10322 and then Operand_Typ
/= Any_Composite
-- or else Operand in error
10323 and then not Matching_Static_Array_Bounds
(Target_Typ
, Operand_Typ
)
10325 Check_SPARK_05_Restriction
10326 ("array types should have matching static bounds", N
);
10329 -- In formal mode, the operand of an ancestor type conversion must be an
10330 -- object (not an expression).
10332 if Is_Tagged_Type
(Target_Typ
)
10333 and then not Is_Class_Wide_Type
(Target_Typ
)
10334 and then Is_Tagged_Type
(Operand_Typ
)
10335 and then not Is_Class_Wide_Type
(Operand_Typ
)
10336 and then Is_Ancestor
(Target_Typ
, Operand_Typ
)
10337 and then not Is_SPARK_05_Object_Reference
(Operand
)
10339 Check_SPARK_05_Restriction
("object required", Operand
);
10342 Analyze_Dimension
(N
);
10344 -- Note: we do the Eval_Type_Conversion call before applying the
10345 -- required checks for a subtype conversion. This is important, since
10346 -- both are prepared under certain circumstances to change the type
10347 -- conversion to a constraint error node, but in the case of
10348 -- Eval_Type_Conversion this may reflect an illegality in the static
10349 -- case, and we would miss the illegality (getting only a warning
10350 -- message), if we applied the type conversion checks first.
10352 Eval_Type_Conversion
(N
);
10354 -- Even when evaluation is not possible, we may be able to simplify the
10355 -- conversion or its expression. This needs to be done before applying
10356 -- checks, since otherwise the checks may use the original expression
10357 -- and defeat the simplifications. This is specifically the case for
10358 -- elimination of the floating-point Truncation attribute in
10359 -- float-to-int conversions.
10361 Simplify_Type_Conversion
(N
);
10363 -- If after evaluation we still have a type conversion, then we may need
10364 -- to apply checks required for a subtype conversion.
10366 -- Skip these type conversion checks if universal fixed operands
10367 -- operands involved, since range checks are handled separately for
10368 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
10370 if Nkind
(N
) = N_Type_Conversion
10371 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
10372 and then Target_Typ
/= Universal_Fixed
10373 and then Operand_Typ
/= Universal_Fixed
10375 Apply_Type_Conversion_Checks
(N
);
10378 -- Issue warning for conversion of simple object to its own type. We
10379 -- have to test the original nodes, since they may have been rewritten
10380 -- by various optimizations.
10382 Orig_N
:= Original_Node
(N
);
10384 -- Here we test for a redundant conversion if the warning mode is
10385 -- active (and was not locally reset), and we have a type conversion
10386 -- from source not appearing in a generic instance.
10389 and then Nkind
(Orig_N
) = N_Type_Conversion
10390 and then Comes_From_Source
(Orig_N
)
10391 and then not In_Instance
10393 Orig_N
:= Original_Node
(Expression
(Orig_N
));
10394 Orig_T
:= Target_Typ
;
10396 -- If the node is part of a larger expression, the Target_Type
10397 -- may not be the original type of the node if the context is a
10398 -- condition. Recover original type to see if conversion is needed.
10400 if Is_Boolean_Type
(Orig_T
)
10401 and then Nkind
(Parent
(N
)) in N_Op
10403 Orig_T
:= Etype
(Parent
(N
));
10406 -- If we have an entity name, then give the warning if the entity
10407 -- is the right type, or if it is a loop parameter covered by the
10408 -- original type (that's needed because loop parameters have an
10409 -- odd subtype coming from the bounds).
10411 if (Is_Entity_Name
(Orig_N
)
10413 (Etype
(Entity
(Orig_N
)) = Orig_T
10415 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
10416 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
))))))
10418 -- If not an entity, then type of expression must match
10420 or else Etype
(Orig_N
) = Orig_T
10422 -- One more check, do not give warning if the analyzed conversion
10423 -- has an expression with non-static bounds, and the bounds of the
10424 -- target are static. This avoids junk warnings in cases where the
10425 -- conversion is necessary to establish staticness, for example in
10426 -- a case statement.
10428 if not Is_OK_Static_Subtype
(Operand_Typ
)
10429 and then Is_OK_Static_Subtype
(Target_Typ
)
10433 -- Finally, if this type conversion occurs in a context requiring
10434 -- a prefix, and the expression is a qualified expression then the
10435 -- type conversion is not redundant, since a qualified expression
10436 -- is not a prefix, whereas a type conversion is. For example, "X
10437 -- := T'(Funx(...)).Y;" is illegal because a selected component
10438 -- requires a prefix, but a type conversion makes it legal: "X :=
10439 -- T(T'(Funx(...))).Y;"
10441 -- In Ada 2012, a qualified expression is a name, so this idiom is
10442 -- no longer needed, but we still suppress the warning because it
10443 -- seems unfriendly for warnings to pop up when you switch to the
10444 -- newer language version.
10446 elsif Nkind
(Orig_N
) = N_Qualified_Expression
10447 and then Nkind_In
(Parent
(N
), N_Attribute_Reference
,
10448 N_Indexed_Component
,
10449 N_Selected_Component
,
10451 N_Explicit_Dereference
)
10455 -- Never warn on conversion to Long_Long_Integer'Base since
10456 -- that is most likely an artifact of the extended overflow
10457 -- checking and comes from complex expanded code.
10459 elsif Orig_T
= Base_Type
(Standard_Long_Long_Integer
) then
10462 -- Here we give the redundant conversion warning. If it is an
10463 -- entity, give the name of the entity in the message. If not,
10464 -- just mention the expression.
10466 -- Shoudn't we test Warn_On_Redundant_Constructs here ???
10469 if Is_Entity_Name
(Orig_N
) then
10470 Error_Msg_Node_2
:= Orig_T
;
10471 Error_Msg_NE
-- CODEFIX
10472 ("??redundant conversion, & is of type &!",
10473 N
, Entity
(Orig_N
));
10476 ("??redundant conversion, expression is of type&!",
10483 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
10484 -- No need to perform any interface conversion if the type of the
10485 -- expression coincides with the target type.
10487 if Ada_Version
>= Ada_2005
10488 and then Expander_Active
10489 and then Operand_Typ
/= Target_Typ
10492 Opnd
: Entity_Id
:= Operand_Typ
;
10493 Target
: Entity_Id
:= Target_Typ
;
10496 -- If the type of the operand is a limited view, use the non-
10497 -- limited view when available.
10499 if From_Limited_With
(Opnd
)
10500 and then Ekind
(Opnd
) in Incomplete_Kind
10501 and then Present
(Non_Limited_View
(Opnd
))
10503 Opnd
:= Non_Limited_View
(Opnd
);
10504 Set_Etype
(Expression
(N
), Opnd
);
10507 if Is_Access_Type
(Opnd
) then
10508 Opnd
:= Designated_Type
(Opnd
);
10511 if Is_Access_Type
(Target_Typ
) then
10512 Target
:= Designated_Type
(Target
);
10515 if Opnd
= Target
then
10518 -- Conversion from interface type
10520 elsif Is_Interface
(Opnd
) then
10522 -- Ada 2005 (AI-217): Handle entities from limited views
10524 if From_Limited_With
(Opnd
) then
10525 Error_Msg_Qual_Level
:= 99;
10526 Error_Msg_NE
-- CODEFIX
10527 ("missing WITH clause on package &", N
,
10528 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
10530 ("type conversions require visibility of the full view",
10533 elsif From_Limited_With
(Target
)
10535 (Is_Access_Type
(Target_Typ
)
10536 and then Present
(Non_Limited_View
(Etype
(Target
))))
10538 Error_Msg_Qual_Level
:= 99;
10539 Error_Msg_NE
-- CODEFIX
10540 ("missing WITH clause on package &", N
,
10541 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
10543 ("type conversions require visibility of the full view",
10547 Expand_Interface_Conversion
(N
);
10550 -- Conversion to interface type
10552 elsif Is_Interface
(Target
) then
10556 if Ekind_In
(Opnd
, E_Protected_Subtype
, E_Task_Subtype
) then
10557 Opnd
:= Etype
(Opnd
);
10560 if Is_Class_Wide_Type
(Opnd
)
10561 or else Interface_Present_In_Ancestor
10565 Expand_Interface_Conversion
(N
);
10567 Error_Msg_Name_1
:= Chars
(Etype
(Target
));
10568 Error_Msg_Name_2
:= Chars
(Opnd
);
10570 ("wrong interface conversion (% is not a progenitor "
10577 -- Ada 2012: if target type has predicates, the result requires a
10578 -- predicate check. If the context is a call to another predicate
10579 -- check we must prevent infinite recursion.
10581 if Has_Predicates
(Target_Typ
) then
10582 if Nkind
(Parent
(N
)) = N_Function_Call
10583 and then Present
(Name
(Parent
(N
)))
10584 and then (Is_Predicate_Function
(Entity
(Name
(Parent
(N
))))
10586 Is_Predicate_Function_M
(Entity
(Name
(Parent
(N
)))))
10591 Apply_Predicate_Check
(N
, Target_Typ
);
10595 -- If at this stage we have a real to integer conversion, make sure
10596 -- that the Do_Range_Check flag is set, because such conversions in
10597 -- general need a range check. We only need this if expansion is off
10598 -- or we are in GNATProve mode.
10600 if Nkind
(N
) = N_Type_Conversion
10601 and then (GNATprove_Mode
or not Expander_Active
)
10602 and then Is_Integer_Type
(Target_Typ
)
10603 and then Is_Real_Type
(Operand_Typ
)
10605 Set_Do_Range_Check
(Operand
);
10607 end Resolve_Type_Conversion
;
10609 ----------------------
10610 -- Resolve_Unary_Op --
10611 ----------------------
10613 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
10614 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10615 R
: constant Node_Id
:= Right_Opnd
(N
);
10621 if Is_Modular_Integer_Type
(Typ
) and then Nkind
(N
) /= N_Op_Not
then
10622 Error_Msg_Name_1
:= Chars
(Typ
);
10623 Check_SPARK_05_Restriction
10624 ("unary operator not defined for modular type%", N
);
10627 -- Deal with intrinsic unary operators
10629 if Comes_From_Source
(N
)
10630 and then Ekind
(Entity
(N
)) = E_Function
10631 and then Is_Imported
(Entity
(N
))
10632 and then Is_Intrinsic_Subprogram
(Entity
(N
))
10634 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10638 -- Deal with universal cases
10640 if Etype
(R
) = Universal_Integer
10642 Etype
(R
) = Universal_Real
10644 Check_For_Visible_Operator
(N
, B_Typ
);
10647 Set_Etype
(N
, B_Typ
);
10648 Resolve
(R
, B_Typ
);
10650 -- Generate warning for expressions like abs (x mod 2)
10652 if Warn_On_Redundant_Constructs
10653 and then Nkind
(N
) = N_Op_Abs
10655 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
10657 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
10658 Error_Msg_N
-- CODEFIX
10659 ("?r?abs applied to known non-negative value has no effect", N
);
10663 -- Deal with reference generation
10665 Check_Unset_Reference
(R
);
10666 Generate_Operator_Reference
(N
, B_Typ
);
10667 Analyze_Dimension
(N
);
10670 -- Set overflow checking bit. Much cleverer code needed here eventually
10671 -- and perhaps the Resolve routines should be separated for the various
10672 -- arithmetic operations, since they will need different processing ???
10674 if Nkind
(N
) in N_Op
then
10675 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
10676 Enable_Overflow_Check
(N
);
10680 -- Generate warning for expressions like -5 mod 3 for integers. No need
10681 -- to worry in the floating-point case, since parens do not affect the
10682 -- result so there is no point in giving in a warning.
10685 Norig
: constant Node_Id
:= Original_Node
(N
);
10694 if Warn_On_Questionable_Missing_Parens
10695 and then Comes_From_Source
(Norig
)
10696 and then Is_Integer_Type
(Typ
)
10697 and then Nkind
(Norig
) = N_Op_Minus
10699 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
10701 -- We are looking for cases where the right operand is not
10702 -- parenthesized, and is a binary operator, multiply, divide, or
10703 -- mod. These are the cases where the grouping can affect results.
10705 if Paren_Count
(Rorig
) = 0
10706 and then Nkind_In
(Rorig
, N_Op_Mod
, N_Op_Multiply
, N_Op_Divide
)
10708 -- For mod, we always give the warning, since the value is
10709 -- affected by the parenthesization (e.g. (-5) mod 315 /=
10710 -- -(5 mod 315)). But for the other cases, the only concern is
10711 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
10712 -- overflows, but (-2) * 64 does not). So we try to give the
10713 -- message only when overflow is possible.
10715 if Nkind
(Rorig
) /= N_Op_Mod
10716 and then Compile_Time_Known_Value
(R
)
10718 Val
:= Expr_Value
(R
);
10720 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
10721 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
10723 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
10726 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
10727 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
10729 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
10732 -- Note that the test below is deliberately excluding the
10733 -- largest negative number, since that is a potentially
10734 -- troublesome case (e.g. -2 * x, where the result is the
10735 -- largest negative integer has an overflow with 2 * x).
10737 if Val
> LB
and then Val
<= HB
then
10742 -- For the multiplication case, the only case we have to worry
10743 -- about is when (-a)*b is exactly the largest negative number
10744 -- so that -(a*b) can cause overflow. This can only happen if
10745 -- a is a power of 2, and more generally if any operand is a
10746 -- constant that is not a power of 2, then the parentheses
10747 -- cannot affect whether overflow occurs. We only bother to
10748 -- test the left most operand
10750 -- Loop looking at left operands for one that has known value
10753 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
10754 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
10755 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
10757 -- Operand value of 0 or 1 skips warning
10762 -- Otherwise check power of 2, if power of 2, warn, if
10763 -- anything else, skip warning.
10766 while Lval
/= 2 loop
10767 if Lval
mod 2 = 1 then
10778 -- Keep looking at left operands
10780 Opnd
:= Left_Opnd
(Opnd
);
10781 end loop Opnd_Loop
;
10783 -- For rem or "/" we can only have a problematic situation
10784 -- if the divisor has a value of minus one or one. Otherwise
10785 -- overflow is impossible (divisor > 1) or we have a case of
10786 -- division by zero in any case.
10788 if Nkind_In
(Rorig
, N_Op_Divide
, N_Op_Rem
)
10789 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
10790 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
10795 -- If we fall through warning should be issued
10797 -- Shouldn't we test Warn_On_Questionable_Missing_Parens ???
10800 ("??unary minus expression should be parenthesized here!", N
);
10804 end Resolve_Unary_Op
;
10806 ----------------------------------
10807 -- Resolve_Unchecked_Expression --
10808 ----------------------------------
10810 procedure Resolve_Unchecked_Expression
10815 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
10816 Set_Etype
(N
, Typ
);
10817 end Resolve_Unchecked_Expression
;
10819 ---------------------------------------
10820 -- Resolve_Unchecked_Type_Conversion --
10821 ---------------------------------------
10823 procedure Resolve_Unchecked_Type_Conversion
10827 pragma Warnings
(Off
, Typ
);
10829 Operand
: constant Node_Id
:= Expression
(N
);
10830 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
10833 -- Resolve operand using its own type
10835 Resolve
(Operand
, Opnd_Type
);
10837 -- In an inlined context, the unchecked conversion may be applied
10838 -- to a literal, in which case its type is the type of the context.
10839 -- (In other contexts conversions cannot apply to literals).
10842 and then (Opnd_Type
= Any_Character
or else
10843 Opnd_Type
= Any_Integer
or else
10844 Opnd_Type
= Any_Real
)
10846 Set_Etype
(Operand
, Typ
);
10849 Analyze_Dimension
(N
);
10850 Eval_Unchecked_Conversion
(N
);
10851 end Resolve_Unchecked_Type_Conversion
;
10853 ------------------------------
10854 -- Rewrite_Operator_As_Call --
10855 ------------------------------
10857 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
10858 Loc
: constant Source_Ptr
:= Sloc
(N
);
10859 Actuals
: constant List_Id
:= New_List
;
10863 if Nkind
(N
) in N_Binary_Op
then
10864 Append
(Left_Opnd
(N
), Actuals
);
10867 Append
(Right_Opnd
(N
), Actuals
);
10870 Make_Function_Call
(Sloc
=> Loc
,
10871 Name
=> New_Occurrence_Of
(Nam
, Loc
),
10872 Parameter_Associations
=> Actuals
);
10874 Preserve_Comes_From_Source
(New_N
, N
);
10875 Preserve_Comes_From_Source
(Name
(New_N
), N
);
10876 Rewrite
(N
, New_N
);
10877 Set_Etype
(N
, Etype
(Nam
));
10878 end Rewrite_Operator_As_Call
;
10880 ------------------------------
10881 -- Rewrite_Renamed_Operator --
10882 ------------------------------
10884 procedure Rewrite_Renamed_Operator
10889 Nam
: constant Name_Id
:= Chars
(Op
);
10890 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
10894 -- Do not perform this transformation within a pre/postcondition,
10895 -- because the expression will be re-analyzed, and the transformation
10896 -- might affect the visibility of the operator, e.g. in an instance.
10898 if In_Assertion_Expr
> 0 then
10902 -- Rewrite the operator node using the real operator, not its renaming.
10903 -- Exclude user-defined intrinsic operations of the same name, which are
10904 -- treated separately and rewritten as calls.
10906 if Ekind
(Op
) /= E_Function
or else Chars
(N
) /= Nam
then
10907 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
10908 Set_Chars
(Op_Node
, Nam
);
10909 Set_Etype
(Op_Node
, Etype
(N
));
10910 Set_Entity
(Op_Node
, Op
);
10911 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
10913 -- Indicate that both the original entity and its renaming are
10914 -- referenced at this point.
10916 Generate_Reference
(Entity
(N
), N
);
10917 Generate_Reference
(Op
, N
);
10920 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
10923 Rewrite
(N
, Op_Node
);
10925 -- If the context type is private, add the appropriate conversions so
10926 -- that the operator is applied to the full view. This is done in the
10927 -- routines that resolve intrinsic operators.
10929 if Is_Intrinsic_Subprogram
(Op
)
10930 and then Is_Private_Type
(Typ
)
10933 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
10934 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
10935 Resolve_Intrinsic_Operator
(N
, Typ
);
10937 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
10938 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10945 elsif Ekind
(Op
) = E_Function
and then Is_Intrinsic_Subprogram
(Op
) then
10947 -- Operator renames a user-defined operator of the same name. Use the
10948 -- original operator in the node, which is the one Gigi knows about.
10950 Set_Entity
(N
, Op
);
10951 Set_Is_Overloaded
(N
, False);
10953 end Rewrite_Renamed_Operator
;
10955 -----------------------
10956 -- Set_Slice_Subtype --
10957 -----------------------
10959 -- Build an implicit subtype declaration to represent the type delivered by
10960 -- the slice. This is an abbreviated version of an array subtype. We define
10961 -- an index subtype for the slice, using either the subtype name or the
10962 -- discrete range of the slice. To be consistent with index usage elsewhere
10963 -- we create a list header to hold the single index. This list is not
10964 -- otherwise attached to the syntax tree.
10966 procedure Set_Slice_Subtype
(N
: Node_Id
) is
10967 Loc
: constant Source_Ptr
:= Sloc
(N
);
10968 Index_List
: constant List_Id
:= New_List
;
10970 Index_Subtype
: Entity_Id
;
10971 Index_Type
: Entity_Id
;
10972 Slice_Subtype
: Entity_Id
;
10973 Drange
: constant Node_Id
:= Discrete_Range
(N
);
10976 Index_Type
:= Base_Type
(Etype
(Drange
));
10978 if Is_Entity_Name
(Drange
) then
10979 Index_Subtype
:= Entity
(Drange
);
10982 -- We force the evaluation of a range. This is definitely needed in
10983 -- the renamed case, and seems safer to do unconditionally. Note in
10984 -- any case that since we will create and insert an Itype referring
10985 -- to this range, we must make sure any side effect removal actions
10986 -- are inserted before the Itype definition.
10988 if Nkind
(Drange
) = N_Range
then
10989 Force_Evaluation
(Low_Bound
(Drange
));
10990 Force_Evaluation
(High_Bound
(Drange
));
10992 -- If the discrete range is given by a subtype indication, the
10993 -- type of the slice is the base of the subtype mark.
10995 elsif Nkind
(Drange
) = N_Subtype_Indication
then
10997 R
: constant Node_Id
:= Range_Expression
(Constraint
(Drange
));
10999 Index_Type
:= Base_Type
(Entity
(Subtype_Mark
(Drange
)));
11000 Force_Evaluation
(Low_Bound
(R
));
11001 Force_Evaluation
(High_Bound
(R
));
11005 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
11007 -- Take a new copy of Drange (where bounds have been rewritten to
11008 -- reference side-effect-free names). Using a separate tree ensures
11009 -- that further expansion (e.g. while rewriting a slice assignment
11010 -- into a FOR loop) does not attempt to remove side effects on the
11011 -- bounds again (which would cause the bounds in the index subtype
11012 -- definition to refer to temporaries before they are defined) (the
11013 -- reason is that some names are considered side effect free here
11014 -- for the subtype, but not in the context of a loop iteration
11017 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
11018 Set_Parent
(Scalar_Range
(Index_Subtype
), Index_Subtype
);
11019 Set_Etype
(Index_Subtype
, Index_Type
);
11020 Set_Size_Info
(Index_Subtype
, Index_Type
);
11021 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
11024 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
11026 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
11027 Set_Etype
(Index
, Index_Subtype
);
11028 Append
(Index
, Index_List
);
11030 Set_First_Index
(Slice_Subtype
, Index
);
11031 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
11032 Set_Is_Constrained
(Slice_Subtype
, True);
11034 Check_Compile_Time_Size
(Slice_Subtype
);
11036 -- The Etype of the existing Slice node is reset to this slice subtype.
11037 -- Its bounds are obtained from its first index.
11039 Set_Etype
(N
, Slice_Subtype
);
11041 -- For packed slice subtypes, freeze immediately (except in the case of
11042 -- being in a "spec expression" where we never freeze when we first see
11043 -- the expression).
11045 if Is_Packed
(Slice_Subtype
) and not In_Spec_Expression
then
11046 Freeze_Itype
(Slice_Subtype
, N
);
11048 -- For all other cases insert an itype reference in the slice's actions
11049 -- so that the itype is frozen at the proper place in the tree (i.e. at
11050 -- the point where actions for the slice are analyzed). Note that this
11051 -- is different from freezing the itype immediately, which might be
11052 -- premature (e.g. if the slice is within a transient scope). This needs
11053 -- to be done only if expansion is enabled.
11055 elsif Expander_Active
then
11056 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
11058 end Set_Slice_Subtype
;
11060 --------------------------------
11061 -- Set_String_Literal_Subtype --
11062 --------------------------------
11064 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
11065 Loc
: constant Source_Ptr
:= Sloc
(N
);
11066 Low_Bound
: constant Node_Id
:=
11067 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
11068 Subtype_Id
: Entity_Id
;
11071 if Nkind
(N
) /= N_String_Literal
then
11075 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
11076 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
11077 (String_Length
(Strval
(N
))));
11078 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
11079 Set_Is_Constrained
(Subtype_Id
);
11080 Set_Etype
(N
, Subtype_Id
);
11082 -- The low bound is set from the low bound of the corresponding index
11083 -- type. Note that we do not store the high bound in the string literal
11084 -- subtype, but it can be deduced if necessary from the length and the
11087 if Is_OK_Static_Expression
(Low_Bound
) then
11088 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
11090 -- If the lower bound is not static we create a range for the string
11091 -- literal, using the index type and the known length of the literal.
11092 -- The index type is not necessarily Positive, so the upper bound is
11093 -- computed as T'Val (T'Pos (Low_Bound) + L - 1).
11097 Index_List
: constant List_Id
:= New_List
;
11098 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
11099 High_Bound
: constant Node_Id
:=
11100 Make_Attribute_Reference
(Loc
,
11101 Attribute_Name
=> Name_Val
,
11103 New_Occurrence_Of
(Index_Type
, Loc
),
11104 Expressions
=> New_List
(
11107 Make_Attribute_Reference
(Loc
,
11108 Attribute_Name
=> Name_Pos
,
11110 New_Occurrence_Of
(Index_Type
, Loc
),
11112 New_List
(New_Copy_Tree
(Low_Bound
))),
11114 Make_Integer_Literal
(Loc
,
11115 String_Length
(Strval
(N
)) - 1))));
11117 Array_Subtype
: Entity_Id
;
11120 Index_Subtype
: Entity_Id
;
11123 if Is_Integer_Type
(Index_Type
) then
11124 Set_String_Literal_Low_Bound
11125 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
11128 -- If the index type is an enumeration type, build bounds
11129 -- expression with attributes.
11131 Set_String_Literal_Low_Bound
11133 Make_Attribute_Reference
(Loc
,
11134 Attribute_Name
=> Name_First
,
11136 New_Occurrence_Of
(Base_Type
(Index_Type
), Loc
)));
11137 Set_Etype
(String_Literal_Low_Bound
(Subtype_Id
), Index_Type
);
11140 Analyze_And_Resolve
(String_Literal_Low_Bound
(Subtype_Id
));
11142 -- Build bona fide subtype for the string, and wrap it in an
11143 -- unchecked conversion, because the backend expects the
11144 -- String_Literal_Subtype to have a static lower bound.
11147 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
11148 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
11149 Set_Scalar_Range
(Index_Subtype
, Drange
);
11150 Set_Parent
(Drange
, N
);
11151 Analyze_And_Resolve
(Drange
, Index_Type
);
11153 -- In the context, the Index_Type may already have a constraint,
11154 -- so use common base type on string subtype. The base type may
11155 -- be used when generating attributes of the string, for example
11156 -- in the context of a slice assignment.
11158 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
11159 Set_Size_Info
(Index_Subtype
, Index_Type
);
11160 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
11162 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
11164 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
11165 Set_Etype
(Index
, Index_Subtype
);
11166 Append
(Index
, Index_List
);
11168 Set_First_Index
(Array_Subtype
, Index
);
11169 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
11170 Set_Is_Constrained
(Array_Subtype
, True);
11173 Make_Unchecked_Type_Conversion
(Loc
,
11174 Subtype_Mark
=> New_Occurrence_Of
(Array_Subtype
, Loc
),
11175 Expression
=> Relocate_Node
(N
)));
11176 Set_Etype
(N
, Array_Subtype
);
11179 end Set_String_Literal_Subtype
;
11181 ------------------------------
11182 -- Simplify_Type_Conversion --
11183 ------------------------------
11185 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
11187 if Nkind
(N
) = N_Type_Conversion
then
11189 Operand
: constant Node_Id
:= Expression
(N
);
11190 Target_Typ
: constant Entity_Id
:= Etype
(N
);
11191 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
11194 -- Special processing if the conversion is the expression of a
11195 -- Rounding or Truncation attribute reference. In this case we
11198 -- ityp (ftyp'Rounding (x)) or ityp (ftyp'Truncation (x))
11204 -- with the Float_Truncate flag set to False or True respectively,
11205 -- which is more efficient.
11207 if Is_Floating_Point_Type
(Opnd_Typ
)
11209 (Is_Integer_Type
(Target_Typ
)
11210 or else (Is_Fixed_Point_Type
(Target_Typ
)
11211 and then Conversion_OK
(N
)))
11212 and then Nkind
(Operand
) = N_Attribute_Reference
11213 and then Nam_In
(Attribute_Name
(Operand
), Name_Rounding
,
11217 Truncate
: constant Boolean :=
11218 Attribute_Name
(Operand
) = Name_Truncation
;
11221 Relocate_Node
(First
(Expressions
(Operand
))));
11222 Set_Float_Truncate
(N
, Truncate
);
11227 end Simplify_Type_Conversion
;
11229 -----------------------------
11230 -- Unique_Fixed_Point_Type --
11231 -----------------------------
11233 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
11234 T1
: Entity_Id
:= Empty
;
11239 procedure Fixed_Point_Error
;
11240 -- Give error messages for true ambiguity. Messages are posted on node
11241 -- N, and entities T1, T2 are the possible interpretations.
11243 -----------------------
11244 -- Fixed_Point_Error --
11245 -----------------------
11247 procedure Fixed_Point_Error
is
11249 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
11250 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
11251 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
11252 end Fixed_Point_Error
;
11254 -- Start of processing for Unique_Fixed_Point_Type
11257 -- The operations on Duration are visible, so Duration is always a
11258 -- possible interpretation.
11260 T1
:= Standard_Duration
;
11262 -- Look for fixed-point types in enclosing scopes
11264 Scop
:= Current_Scope
;
11265 while Scop
/= Standard_Standard
loop
11266 T2
:= First_Entity
(Scop
);
11267 while Present
(T2
) loop
11268 if Is_Fixed_Point_Type
(T2
)
11269 and then Current_Entity
(T2
) = T2
11270 and then Scope
(Base_Type
(T2
)) = Scop
11272 if Present
(T1
) then
11283 Scop
:= Scope
(Scop
);
11286 -- Look for visible fixed type declarations in the context
11288 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
11289 while Present
(Item
) loop
11290 if Nkind
(Item
) = N_With_Clause
then
11291 Scop
:= Entity
(Name
(Item
));
11292 T2
:= First_Entity
(Scop
);
11293 while Present
(T2
) loop
11294 if Is_Fixed_Point_Type
(T2
)
11295 and then Scope
(Base_Type
(T2
)) = Scop
11296 and then (Is_Potentially_Use_Visible
(T2
) or else In_Use
(T2
))
11298 if Present
(T1
) then
11313 if Nkind
(N
) = N_Real_Literal
then
11315 ("??real literal interpreted as }!", N
, T1
);
11318 ("??universal_fixed expression interpreted as }!", N
, T1
);
11322 end Unique_Fixed_Point_Type
;
11324 ----------------------
11325 -- Valid_Conversion --
11326 ----------------------
11328 function Valid_Conversion
11330 Target
: Entity_Id
;
11332 Report_Errs
: Boolean := True) return Boolean
11334 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
11335 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
11336 Inc_Ancestor
: Entity_Id
;
11338 function Conversion_Check
11340 Msg
: String) return Boolean;
11341 -- Little routine to post Msg if Valid is False, returns Valid value
11343 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
);
11344 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
11346 procedure Conversion_Error_NE
11348 N
: Node_Or_Entity_Id
;
11349 E
: Node_Or_Entity_Id
);
11350 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
11352 function Valid_Tagged_Conversion
11353 (Target_Type
: Entity_Id
;
11354 Opnd_Type
: Entity_Id
) return Boolean;
11355 -- Specifically test for validity of tagged conversions
11357 function Valid_Array_Conversion
return Boolean;
11358 -- Check index and component conformance, and accessibility levels if
11359 -- the component types are anonymous access types (Ada 2005).
11361 ----------------------
11362 -- Conversion_Check --
11363 ----------------------
11365 function Conversion_Check
11367 Msg
: String) return Boolean
11372 -- A generic unit has already been analyzed and we have verified
11373 -- that a particular conversion is OK in that context. Since the
11374 -- instance is reanalyzed without relying on the relationships
11375 -- established during the analysis of the generic, it is possible
11376 -- to end up with inconsistent views of private types. Do not emit
11377 -- the error message in such cases. The rest of the machinery in
11378 -- Valid_Conversion still ensures the proper compatibility of
11379 -- target and operand types.
11381 and then not In_Instance
11383 Conversion_Error_N
(Msg
, Operand
);
11387 end Conversion_Check
;
11389 ------------------------
11390 -- Conversion_Error_N --
11391 ------------------------
11393 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
11395 if Report_Errs
then
11396 Error_Msg_N
(Msg
, N
);
11398 end Conversion_Error_N
;
11400 -------------------------
11401 -- Conversion_Error_NE --
11402 -------------------------
11404 procedure Conversion_Error_NE
11406 N
: Node_Or_Entity_Id
;
11407 E
: Node_Or_Entity_Id
)
11410 if Report_Errs
then
11411 Error_Msg_NE
(Msg
, N
, E
);
11413 end Conversion_Error_NE
;
11415 ----------------------------
11416 -- Valid_Array_Conversion --
11417 ----------------------------
11419 function Valid_Array_Conversion
return Boolean
11421 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
11422 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
11424 Opnd_Index
: Node_Id
;
11425 Opnd_Index_Type
: Entity_Id
;
11427 Target_Comp_Type
: constant Entity_Id
:=
11428 Component_Type
(Target_Type
);
11429 Target_Comp_Base
: constant Entity_Id
:=
11430 Base_Type
(Target_Comp_Type
);
11432 Target_Index
: Node_Id
;
11433 Target_Index_Type
: Entity_Id
;
11436 -- Error if wrong number of dimensions
11439 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
11442 ("incompatible number of dimensions for conversion", Operand
);
11445 -- Number of dimensions matches
11448 -- Loop through indexes of the two arrays
11450 Target_Index
:= First_Index
(Target_Type
);
11451 Opnd_Index
:= First_Index
(Opnd_Type
);
11452 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
11453 Target_Index_Type
:= Etype
(Target_Index
);
11454 Opnd_Index_Type
:= Etype
(Opnd_Index
);
11456 -- Error if index types are incompatible
11458 if not (Is_Integer_Type
(Target_Index_Type
)
11459 and then Is_Integer_Type
(Opnd_Index_Type
))
11460 and then (Root_Type
(Target_Index_Type
)
11461 /= Root_Type
(Opnd_Index_Type
))
11464 ("incompatible index types for array conversion",
11469 Next_Index
(Target_Index
);
11470 Next_Index
(Opnd_Index
);
11473 -- If component types have same base type, all set
11475 if Target_Comp_Base
= Opnd_Comp_Base
then
11478 -- Here if base types of components are not the same. The only
11479 -- time this is allowed is if we have anonymous access types.
11481 -- The conversion of arrays of anonymous access types can lead
11482 -- to dangling pointers. AI-392 formalizes the accessibility
11483 -- checks that must be applied to such conversions to prevent
11484 -- out-of-scope references.
11487 (Target_Comp_Base
, E_Anonymous_Access_Type
,
11488 E_Anonymous_Access_Subprogram_Type
)
11489 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
11491 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
11493 if Type_Access_Level
(Target_Type
) <
11494 Deepest_Type_Access_Level
(Opnd_Type
)
11496 if In_Instance_Body
then
11497 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11499 ("source array type has deeper accessibility "
11500 & "level than target<<", Operand
);
11501 Conversion_Error_N
("\Program_Error [<<", Operand
);
11503 Make_Raise_Program_Error
(Sloc
(N
),
11504 Reason
=> PE_Accessibility_Check_Failed
));
11505 Set_Etype
(N
, Target_Type
);
11508 -- Conversion not allowed because of accessibility levels
11512 ("source array type has deeper accessibility "
11513 & "level than target", Operand
);
11521 -- All other cases where component base types do not match
11525 ("incompatible component types for array conversion",
11530 -- Check that component subtypes statically match. For numeric
11531 -- types this means that both must be either constrained or
11532 -- unconstrained. For enumeration types the bounds must match.
11533 -- All of this is checked in Subtypes_Statically_Match.
11535 if not Subtypes_Statically_Match
11536 (Target_Comp_Type
, Opnd_Comp_Type
)
11539 ("component subtypes must statically match", Operand
);
11545 end Valid_Array_Conversion
;
11547 -----------------------------
11548 -- Valid_Tagged_Conversion --
11549 -----------------------------
11551 function Valid_Tagged_Conversion
11552 (Target_Type
: Entity_Id
;
11553 Opnd_Type
: Entity_Id
) return Boolean
11556 -- Upward conversions are allowed (RM 4.6(22))
11558 if Covers
(Target_Type
, Opnd_Type
)
11559 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
11563 -- Downward conversion are allowed if the operand is class-wide
11566 elsif Is_Class_Wide_Type
(Opnd_Type
)
11567 and then Covers
(Opnd_Type
, Target_Type
)
11571 elsif Covers
(Opnd_Type
, Target_Type
)
11572 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
11575 Conversion_Check
(False,
11576 "downward conversion of tagged objects not allowed");
11578 -- Ada 2005 (AI-251): The conversion to/from interface types is
11581 elsif Is_Interface
(Target_Type
) or else Is_Interface
(Opnd_Type
) then
11584 -- If the operand is a class-wide type obtained through a limited_
11585 -- with clause, and the context includes the non-limited view, use
11586 -- it to determine whether the conversion is legal.
11588 elsif Is_Class_Wide_Type
(Opnd_Type
)
11589 and then From_Limited_With
(Opnd_Type
)
11590 and then Present
(Non_Limited_View
(Etype
(Opnd_Type
)))
11591 and then Is_Interface
(Non_Limited_View
(Etype
(Opnd_Type
)))
11595 elsif Is_Access_Type
(Opnd_Type
)
11596 and then Is_Interface
(Directly_Designated_Type
(Opnd_Type
))
11601 Conversion_Error_NE
11602 ("invalid tagged conversion, not compatible with}",
11603 N
, First_Subtype
(Opnd_Type
));
11606 end Valid_Tagged_Conversion
;
11608 -- Start of processing for Valid_Conversion
11611 Check_Parameterless_Call
(Operand
);
11613 if Is_Overloaded
(Operand
) then
11623 -- Remove procedure calls, which syntactically cannot appear in
11624 -- this context, but which cannot be removed by type checking,
11625 -- because the context does not impose a type.
11627 -- The node may be labelled overloaded, but still contain only one
11628 -- interpretation because others were discarded earlier. If this
11629 -- is the case, retain the single interpretation if legal.
11631 Get_First_Interp
(Operand
, I
, It
);
11632 Opnd_Type
:= It
.Typ
;
11633 Get_Next_Interp
(I
, It
);
11635 if Present
(It
.Typ
)
11636 and then Opnd_Type
/= Standard_Void_Type
11638 -- More than one candidate interpretation is available
11640 Get_First_Interp
(Operand
, I
, It
);
11641 while Present
(It
.Typ
) loop
11642 if It
.Typ
= Standard_Void_Type
then
11646 -- When compiling for a system where Address is of a visible
11647 -- integer type, spurious ambiguities can be produced when
11648 -- arithmetic operations have a literal operand and return
11649 -- System.Address or a descendant of it. These ambiguities
11650 -- are usually resolved by the context, but for conversions
11651 -- there is no context type and the removal of the spurious
11652 -- operations must be done explicitly here.
11654 if not Address_Is_Private
11655 and then Is_Descendent_Of_Address
(It
.Typ
)
11660 Get_Next_Interp
(I
, It
);
11664 Get_First_Interp
(Operand
, I
, It
);
11668 if No
(It
.Typ
) then
11669 Conversion_Error_N
("illegal operand in conversion", Operand
);
11673 Get_Next_Interp
(I
, It
);
11675 if Present
(It
.Typ
) then
11678 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
11680 if It1
= No_Interp
then
11682 ("ambiguous operand in conversion", Operand
);
11684 -- If the interpretation involves a standard operator, use
11685 -- the location of the type, which may be user-defined.
11687 if Sloc
(It
.Nam
) = Standard_Location
then
11688 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
11690 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
11693 Conversion_Error_N
-- CODEFIX
11694 ("\\possible interpretation#!", Operand
);
11696 if Sloc
(N1
) = Standard_Location
then
11697 Error_Msg_Sloc
:= Sloc
(T1
);
11699 Error_Msg_Sloc
:= Sloc
(N1
);
11702 Conversion_Error_N
-- CODEFIX
11703 ("\\possible interpretation#!", Operand
);
11709 Set_Etype
(Operand
, It1
.Typ
);
11710 Opnd_Type
:= It1
.Typ
;
11714 -- Deal with conversion of integer type to address if the pragma
11715 -- Allow_Integer_Address is in effect. We convert the conversion to
11716 -- an unchecked conversion in this case and we are all done.
11718 if Address_Integer_Convert_OK
(Opnd_Type
, Target_Type
) then
11719 Rewrite
(N
, Unchecked_Convert_To
(Target_Type
, Expression
(N
)));
11720 Analyze_And_Resolve
(N
, Target_Type
);
11724 -- If we are within a child unit, check whether the type of the
11725 -- expression has an ancestor in a parent unit, in which case it
11726 -- belongs to its derivation class even if the ancestor is private.
11727 -- See RM 7.3.1 (5.2/3).
11729 Inc_Ancestor
:= Get_Incomplete_View_Of_Ancestor
(Opnd_Type
);
11733 if Is_Numeric_Type
(Target_Type
) then
11735 -- A universal fixed expression can be converted to any numeric type
11737 if Opnd_Type
= Universal_Fixed
then
11740 -- Also no need to check when in an instance or inlined body, because
11741 -- the legality has been established when the template was analyzed.
11742 -- Furthermore, numeric conversions may occur where only a private
11743 -- view of the operand type is visible at the instantiation point.
11744 -- This results in a spurious error if we check that the operand type
11745 -- is a numeric type.
11747 -- Note: in a previous version of this unit, the following tests were
11748 -- applied only for generated code (Comes_From_Source set to False),
11749 -- but in fact the test is required for source code as well, since
11750 -- this situation can arise in source code.
11752 elsif In_Instance
or else In_Inlined_Body
then
11755 -- Otherwise we need the conversion check
11758 return Conversion_Check
11759 (Is_Numeric_Type
(Opnd_Type
)
11761 (Present
(Inc_Ancestor
)
11762 and then Is_Numeric_Type
(Inc_Ancestor
)),
11763 "illegal operand for numeric conversion");
11768 elsif Is_Array_Type
(Target_Type
) then
11769 if not Is_Array_Type
(Opnd_Type
)
11770 or else Opnd_Type
= Any_Composite
11771 or else Opnd_Type
= Any_String
11774 ("illegal operand for array conversion", Operand
);
11778 return Valid_Array_Conversion
;
11781 -- Ada 2005 (AI-251): Anonymous access types where target references an
11784 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11785 E_Anonymous_Access_Type
)
11786 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
11788 -- Check the static accessibility rule of 4.6(17). Note that the
11789 -- check is not enforced when within an instance body, since the
11790 -- RM requires such cases to be caught at run time.
11792 -- If the operand is a rewriting of an allocator no check is needed
11793 -- because there are no accessibility issues.
11795 if Nkind
(Original_Node
(N
)) = N_Allocator
then
11798 elsif Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
11799 if Type_Access_Level
(Opnd_Type
) >
11800 Deepest_Type_Access_Level
(Target_Type
)
11802 -- In an instance, this is a run-time check, but one we know
11803 -- will fail, so generate an appropriate warning. The raise
11804 -- will be generated by Expand_N_Type_Conversion.
11806 if In_Instance_Body
then
11807 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11809 ("cannot convert local pointer to non-local access type<<",
11811 Conversion_Error_N
("\Program_Error [<<", Operand
);
11815 ("cannot convert local pointer to non-local access type",
11820 -- Special accessibility checks are needed in the case of access
11821 -- discriminants declared for a limited type.
11823 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11824 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11826 -- When the operand is a selected access discriminant the check
11827 -- needs to be made against the level of the object denoted by
11828 -- the prefix of the selected name (Object_Access_Level handles
11829 -- checking the prefix of the operand for this case).
11831 if Nkind
(Operand
) = N_Selected_Component
11832 and then Object_Access_Level
(Operand
) >
11833 Deepest_Type_Access_Level
(Target_Type
)
11835 -- In an instance, this is a run-time check, but one we know
11836 -- will fail, so generate an appropriate warning. The raise
11837 -- will be generated by Expand_N_Type_Conversion.
11839 if In_Instance_Body
then
11840 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11842 ("cannot convert access discriminant to non-local "
11843 & "access type<<", Operand
);
11844 Conversion_Error_N
("\Program_Error [<<", Operand
);
11846 -- Real error if not in instance body
11850 ("cannot convert access discriminant to non-local "
11851 & "access type", Operand
);
11856 -- The case of a reference to an access discriminant from
11857 -- within a limited type declaration (which will appear as
11858 -- a discriminal) is always illegal because the level of the
11859 -- discriminant is considered to be deeper than any (nameable)
11862 if Is_Entity_Name
(Operand
)
11863 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11865 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
11866 and then Present
(Discriminal_Link
(Entity
(Operand
)))
11869 ("discriminant has deeper accessibility level than target",
11878 -- General and anonymous access types
11880 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11881 E_Anonymous_Access_Type
)
11884 (Is_Access_Type
(Opnd_Type
)
11886 Ekind_In
(Opnd_Type
, E_Access_Subprogram_Type
,
11887 E_Access_Protected_Subprogram_Type
),
11888 "must be an access-to-object type")
11890 if Is_Access_Constant
(Opnd_Type
)
11891 and then not Is_Access_Constant
(Target_Type
)
11894 ("access-to-constant operand type not allowed", Operand
);
11898 -- Check the static accessibility rule of 4.6(17). Note that the
11899 -- check is not enforced when within an instance body, since the RM
11900 -- requires such cases to be caught at run time.
11902 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
11903 or else Is_Local_Anonymous_Access
(Target_Type
)
11904 or else Nkind
(Associated_Node_For_Itype
(Target_Type
)) =
11905 N_Object_Declaration
11907 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
11908 -- conversions from an anonymous access type to a named general
11909 -- access type. Such conversions are not allowed in the case of
11910 -- access parameters and stand-alone objects of an anonymous
11911 -- access type. The implicit conversion case is recognized by
11912 -- testing that Comes_From_Source is False and that it's been
11913 -- rewritten. The Comes_From_Source test isn't sufficient because
11914 -- nodes in inlined calls to predefined library routines can have
11915 -- Comes_From_Source set to False. (Is there a better way to test
11916 -- for implicit conversions???)
11918 if Ada_Version
>= Ada_2012
11919 and then not Comes_From_Source
(N
)
11920 and then N
/= Original_Node
(N
)
11921 and then Ekind
(Target_Type
) = E_General_Access_Type
11922 and then Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11924 if Is_Itype
(Opnd_Type
) then
11926 -- Implicit conversions aren't allowed for objects of an
11927 -- anonymous access type, since such objects have nonstatic
11928 -- levels in Ada 2012.
11930 if Nkind
(Associated_Node_For_Itype
(Opnd_Type
)) =
11931 N_Object_Declaration
11934 ("implicit conversion of stand-alone anonymous "
11935 & "access object not allowed", Operand
);
11938 -- Implicit conversions aren't allowed for anonymous access
11939 -- parameters. The "not Is_Local_Anonymous_Access_Type" test
11940 -- is done to exclude anonymous access results.
11942 elsif not Is_Local_Anonymous_Access
(Opnd_Type
)
11943 and then Nkind_In
(Associated_Node_For_Itype
(Opnd_Type
),
11944 N_Function_Specification
,
11945 N_Procedure_Specification
)
11948 ("implicit conversion of anonymous access formal "
11949 & "not allowed", Operand
);
11952 -- This is a case where there's an enclosing object whose
11953 -- to which the "statically deeper than" relationship does
11954 -- not apply (such as an access discriminant selected from
11955 -- a dereference of an access parameter).
11957 elsif Object_Access_Level
(Operand
)
11958 = Scope_Depth
(Standard_Standard
)
11961 ("implicit conversion of anonymous access value "
11962 & "not allowed", Operand
);
11965 -- In other cases, the level of the operand's type must be
11966 -- statically less deep than that of the target type, else
11967 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
11969 elsif Type_Access_Level
(Opnd_Type
) >
11970 Deepest_Type_Access_Level
(Target_Type
)
11973 ("implicit conversion of anonymous access value "
11974 & "violates accessibility", Operand
);
11979 elsif Type_Access_Level
(Opnd_Type
) >
11980 Deepest_Type_Access_Level
(Target_Type
)
11982 -- In an instance, this is a run-time check, but one we know
11983 -- will fail, so generate an appropriate warning. The raise
11984 -- will be generated by Expand_N_Type_Conversion.
11986 if In_Instance_Body
then
11987 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11989 ("cannot convert local pointer to non-local access type<<",
11991 Conversion_Error_N
("\Program_Error [<<", Operand
);
11993 -- If not in an instance body, this is a real error
11996 -- Avoid generation of spurious error message
11998 if not Error_Posted
(N
) then
12000 ("cannot convert local pointer to non-local access type",
12007 -- Special accessibility checks are needed in the case of access
12008 -- discriminants declared for a limited type.
12010 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
12011 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
12013 -- When the operand is a selected access discriminant the check
12014 -- needs to be made against the level of the object denoted by
12015 -- the prefix of the selected name (Object_Access_Level handles
12016 -- checking the prefix of the operand for this case).
12018 if Nkind
(Operand
) = N_Selected_Component
12019 and then Object_Access_Level
(Operand
) >
12020 Deepest_Type_Access_Level
(Target_Type
)
12022 -- In an instance, this is a run-time check, but one we know
12023 -- will fail, so generate an appropriate warning. The raise
12024 -- will be generated by Expand_N_Type_Conversion.
12026 if In_Instance_Body
then
12027 Error_Msg_Warn
:= SPARK_Mode
/= On
;
12029 ("cannot convert access discriminant to non-local "
12030 & "access type<<", Operand
);
12031 Conversion_Error_N
("\Program_Error [<<", Operand
);
12033 -- If not in an instance body, this is a real error
12037 ("cannot convert access discriminant to non-local "
12038 & "access type", Operand
);
12043 -- The case of a reference to an access discriminant from
12044 -- within a limited type declaration (which will appear as
12045 -- a discriminal) is always illegal because the level of the
12046 -- discriminant is considered to be deeper than any (nameable)
12049 if Is_Entity_Name
(Operand
)
12051 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
12052 and then Present
(Discriminal_Link
(Entity
(Operand
)))
12055 ("discriminant has deeper accessibility level than target",
12062 -- In the presence of limited_with clauses we have to use non-limited
12063 -- views, if available.
12065 Check_Limited
: declare
12066 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
12067 -- Helper function to handle limited views
12069 --------------------------
12070 -- Full_Designated_Type --
12071 --------------------------
12073 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
12074 Desig
: constant Entity_Id
:= Designated_Type
(T
);
12077 -- Handle the limited view of a type
12079 if Is_Incomplete_Type
(Desig
)
12080 and then From_Limited_With
(Desig
)
12081 and then Present
(Non_Limited_View
(Desig
))
12083 return Available_View
(Desig
);
12087 end Full_Designated_Type
;
12089 -- Local Declarations
12091 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
12092 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
12094 Same_Base
: constant Boolean :=
12095 Base_Type
(Target
) = Base_Type
(Opnd
);
12097 -- Start of processing for Check_Limited
12100 if Is_Tagged_Type
(Target
) then
12101 return Valid_Tagged_Conversion
(Target
, Opnd
);
12104 if not Same_Base
then
12105 Conversion_Error_NE
12106 ("target designated type not compatible with }",
12107 N
, Base_Type
(Opnd
));
12110 -- Ada 2005 AI-384: legality rule is symmetric in both
12111 -- designated types. The conversion is legal (with possible
12112 -- constraint check) if either designated type is
12115 elsif Subtypes_Statically_Match
(Target
, Opnd
)
12117 (Has_Discriminants
(Target
)
12119 (not Is_Constrained
(Opnd
)
12120 or else not Is_Constrained
(Target
)))
12122 -- Special case, if Value_Size has been used to make the
12123 -- sizes different, the conversion is not allowed even
12124 -- though the subtypes statically match.
12126 if Known_Static_RM_Size
(Target
)
12127 and then Known_Static_RM_Size
(Opnd
)
12128 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
12130 Conversion_Error_NE
12131 ("target designated subtype not compatible with }",
12133 Conversion_Error_NE
12134 ("\because sizes of the two designated subtypes differ",
12138 -- Normal case where conversion is allowed
12146 ("target designated subtype not compatible with }",
12153 -- Access to subprogram types. If the operand is an access parameter,
12154 -- the type has a deeper accessibility that any master, and cannot be
12155 -- assigned. We must make an exception if the conversion is part of an
12156 -- assignment and the target is the return object of an extended return
12157 -- statement, because in that case the accessibility check takes place
12158 -- after the return.
12160 elsif Is_Access_Subprogram_Type
(Target_Type
)
12162 -- Note: this test of Opnd_Type is there to prevent entering this
12163 -- branch in the case of a remote access to subprogram type, which
12164 -- is internally represented as an E_Record_Type.
12166 and then Is_Access_Type
(Opnd_Type
)
12168 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
12169 and then Is_Entity_Name
(Operand
)
12170 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
12172 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
12173 or else not Is_Entity_Name
(Name
(Parent
(N
)))
12174 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
12177 ("illegal attempt to store anonymous access to subprogram",
12180 ("\value has deeper accessibility than any master "
12181 & "(RM 3.10.2 (13))",
12185 ("\use named access type for& instead of access parameter",
12186 Operand
, Entity
(Operand
));
12189 -- Check that the designated types are subtype conformant
12191 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
12192 Old_Id
=> Designated_Type
(Opnd_Type
),
12195 -- Check the static accessibility rule of 4.6(20)
12197 if Type_Access_Level
(Opnd_Type
) >
12198 Deepest_Type_Access_Level
(Target_Type
)
12201 ("operand type has deeper accessibility level than target",
12204 -- Check that if the operand type is declared in a generic body,
12205 -- then the target type must be declared within that same body
12206 -- (enforces last sentence of 4.6(20)).
12208 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
12210 O_Gen
: constant Node_Id
:=
12211 Enclosing_Generic_Body
(Opnd_Type
);
12216 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
12217 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
12218 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
12221 if T_Gen
/= O_Gen
then
12223 ("target type must be declared in same generic body "
12224 & "as operand type", N
);
12231 -- Remote access to subprogram types
12233 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
12234 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
12236 -- It is valid to convert from one RAS type to another provided
12237 -- that their specification statically match.
12239 -- Note: at this point, remote access to subprogram types have been
12240 -- expanded to their E_Record_Type representation, and we need to
12241 -- go back to the original access type definition using the
12242 -- Corresponding_Remote_Type attribute in order to check that the
12243 -- designated profiles match.
12245 pragma Assert
(Ekind
(Target_Type
) = E_Record_Type
);
12246 pragma Assert
(Ekind
(Opnd_Type
) = E_Record_Type
);
12248 Check_Subtype_Conformant
12250 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
12252 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
12257 -- If it was legal in the generic, it's legal in the instance
12259 elsif In_Instance_Body
then
12262 -- If both are tagged types, check legality of view conversions
12264 elsif Is_Tagged_Type
(Target_Type
)
12266 Is_Tagged_Type
(Opnd_Type
)
12268 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
12270 -- Types derived from the same root type are convertible
12272 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
12275 -- In an instance or an inlined body, there may be inconsistent views of
12276 -- the same type, or of types derived from a common root.
12278 elsif (In_Instance
or In_Inlined_Body
)
12280 Root_Type
(Underlying_Type
(Target_Type
)) =
12281 Root_Type
(Underlying_Type
(Opnd_Type
))
12285 -- Special check for common access type error case
12287 elsif Ekind
(Target_Type
) = E_Access_Type
12288 and then Is_Access_Type
(Opnd_Type
)
12290 Conversion_Error_N
("target type must be general access type!", N
);
12291 Conversion_Error_NE
-- CODEFIX
12292 ("add ALL to }!", N
, Target_Type
);
12295 -- Here we have a real conversion error
12298 Conversion_Error_NE
12299 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
12302 end Valid_Conversion
;