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-2005 4.3.1 (13))",
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
);
4423 -- Case where actual is not present
4431 end Resolve_Actuals
;
4433 -----------------------
4434 -- Resolve_Allocator --
4435 -----------------------
4437 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
) is
4438 Desig_T
: constant Entity_Id
:= Designated_Type
(Typ
);
4439 E
: constant Node_Id
:= Expression
(N
);
4441 Discrim
: Entity_Id
;
4444 Assoc
: Node_Id
:= Empty
;
4447 procedure Check_Allocator_Discrim_Accessibility
4448 (Disc_Exp
: Node_Id
;
4449 Alloc_Typ
: Entity_Id
);
4450 -- Check that accessibility level associated with an access discriminant
4451 -- initialized in an allocator by the expression Disc_Exp is not deeper
4452 -- than the level of the allocator type Alloc_Typ. An error message is
4453 -- issued if this condition is violated. Specialized checks are done for
4454 -- the cases of a constraint expression which is an access attribute or
4455 -- an access discriminant.
4457 function In_Dispatching_Context
return Boolean;
4458 -- If the allocator is an actual in a call, it is allowed to be class-
4459 -- wide when the context is not because it is a controlling actual.
4461 -------------------------------------------
4462 -- Check_Allocator_Discrim_Accessibility --
4463 -------------------------------------------
4465 procedure Check_Allocator_Discrim_Accessibility
4466 (Disc_Exp
: Node_Id
;
4467 Alloc_Typ
: Entity_Id
)
4470 if Type_Access_Level
(Etype
(Disc_Exp
)) >
4471 Deepest_Type_Access_Level
(Alloc_Typ
)
4474 ("operand type has deeper level than allocator type", Disc_Exp
);
4476 -- When the expression is an Access attribute the level of the prefix
4477 -- object must not be deeper than that of the allocator's type.
4479 elsif Nkind
(Disc_Exp
) = N_Attribute_Reference
4480 and then Get_Attribute_Id
(Attribute_Name
(Disc_Exp
)) =
4482 and then Object_Access_Level
(Prefix
(Disc_Exp
)) >
4483 Deepest_Type_Access_Level
(Alloc_Typ
)
4486 ("prefix of attribute has deeper level than allocator type",
4489 -- When the expression is an access discriminant the check is against
4490 -- the level of the prefix object.
4492 elsif Ekind
(Etype
(Disc_Exp
)) = E_Anonymous_Access_Type
4493 and then Nkind
(Disc_Exp
) = N_Selected_Component
4494 and then Object_Access_Level
(Prefix
(Disc_Exp
)) >
4495 Deepest_Type_Access_Level
(Alloc_Typ
)
4498 ("access discriminant has deeper level than allocator type",
4501 -- All other cases are legal
4506 end Check_Allocator_Discrim_Accessibility
;
4508 ----------------------------
4509 -- In_Dispatching_Context --
4510 ----------------------------
4512 function In_Dispatching_Context
return Boolean is
4513 Par
: constant Node_Id
:= Parent
(N
);
4516 return Nkind
(Par
) in N_Subprogram_Call
4517 and then Is_Entity_Name
(Name
(Par
))
4518 and then Is_Dispatching_Operation
(Entity
(Name
(Par
)));
4519 end In_Dispatching_Context
;
4521 -- Start of processing for Resolve_Allocator
4524 -- Replace general access with specific type
4526 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
4527 Set_Etype
(N
, Base_Type
(Typ
));
4530 if Is_Abstract_Type
(Typ
) then
4531 Error_Msg_N
("type of allocator cannot be abstract", N
);
4534 -- For qualified expression, resolve the expression using the given
4535 -- subtype (nothing to do for type mark, subtype indication)
4537 if Nkind
(E
) = N_Qualified_Expression
then
4538 if Is_Class_Wide_Type
(Etype
(E
))
4539 and then not Is_Class_Wide_Type
(Desig_T
)
4540 and then not In_Dispatching_Context
4543 ("class-wide allocator not allowed for this access type", N
);
4546 Resolve
(Expression
(E
), Etype
(E
));
4547 Check_Non_Static_Context
(Expression
(E
));
4548 Check_Unset_Reference
(Expression
(E
));
4550 -- A qualified expression requires an exact match of the type.
4551 -- Class-wide matching is not allowed.
4553 if (Is_Class_Wide_Type
(Etype
(Expression
(E
)))
4554 or else Is_Class_Wide_Type
(Etype
(E
)))
4555 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Etype
(E
))
4557 Wrong_Type
(Expression
(E
), Etype
(E
));
4560 -- Calls to build-in-place functions are not currently supported in
4561 -- allocators for access types associated with a simple storage pool.
4562 -- Supporting such allocators may require passing additional implicit
4563 -- parameters to build-in-place functions (or a significant revision
4564 -- of the current b-i-p implementation to unify the handling for
4565 -- multiple kinds of storage pools). ???
4567 if Is_Limited_View
(Desig_T
)
4568 and then Nkind
(Expression
(E
)) = N_Function_Call
4571 Pool
: constant Entity_Id
:=
4572 Associated_Storage_Pool
(Root_Type
(Typ
));
4576 Present
(Get_Rep_Pragma
4577 (Etype
(Pool
), Name_Simple_Storage_Pool_Type
))
4580 ("limited function calls not yet supported in simple "
4581 & "storage pool allocators", Expression
(E
));
4586 -- A special accessibility check is needed for allocators that
4587 -- constrain access discriminants. The level of the type of the
4588 -- expression used to constrain an access discriminant cannot be
4589 -- deeper than the type of the allocator (in contrast to access
4590 -- parameters, where the level of the actual can be arbitrary).
4592 -- We can't use Valid_Conversion to perform this check because in
4593 -- general the type of the allocator is unrelated to the type of
4594 -- the access discriminant.
4596 if Ekind
(Typ
) /= E_Anonymous_Access_Type
4597 or else Is_Local_Anonymous_Access
(Typ
)
4599 Subtyp
:= Entity
(Subtype_Mark
(E
));
4601 Aggr
:= Original_Node
(Expression
(E
));
4603 if Has_Discriminants
(Subtyp
)
4604 and then Nkind_In
(Aggr
, N_Aggregate
, N_Extension_Aggregate
)
4606 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
4608 -- Get the first component expression of the aggregate
4610 if Present
(Expressions
(Aggr
)) then
4611 Disc_Exp
:= First
(Expressions
(Aggr
));
4613 elsif Present
(Component_Associations
(Aggr
)) then
4614 Assoc
:= First
(Component_Associations
(Aggr
));
4616 if Present
(Assoc
) then
4617 Disc_Exp
:= Expression
(Assoc
);
4626 while Present
(Discrim
) and then Present
(Disc_Exp
) loop
4627 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
4628 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
4631 Next_Discriminant
(Discrim
);
4633 if Present
(Discrim
) then
4634 if Present
(Assoc
) then
4636 Disc_Exp
:= Expression
(Assoc
);
4638 elsif Present
(Next
(Disc_Exp
)) then
4642 Assoc
:= First
(Component_Associations
(Aggr
));
4644 if Present
(Assoc
) then
4645 Disc_Exp
:= Expression
(Assoc
);
4655 -- For a subtype mark or subtype indication, freeze the subtype
4658 Freeze_Expression
(E
);
4660 if Is_Access_Constant
(Typ
) and then not No_Initialization
(N
) then
4662 ("initialization required for access-to-constant allocator", N
);
4665 -- A special accessibility check is needed for allocators that
4666 -- constrain access discriminants. The level of the type of the
4667 -- expression used to constrain an access discriminant cannot be
4668 -- deeper than the type of the allocator (in contrast to access
4669 -- parameters, where the level of the actual can be arbitrary).
4670 -- We can't use Valid_Conversion to perform this check because
4671 -- in general the type of the allocator is unrelated to the type
4672 -- of the access discriminant.
4674 if Nkind
(Original_Node
(E
)) = N_Subtype_Indication
4675 and then (Ekind
(Typ
) /= E_Anonymous_Access_Type
4676 or else Is_Local_Anonymous_Access
(Typ
))
4678 Subtyp
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
4680 if Has_Discriminants
(Subtyp
) then
4681 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
4682 Constr
:= First
(Constraints
(Constraint
(Original_Node
(E
))));
4683 while Present
(Discrim
) and then Present
(Constr
) loop
4684 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
4685 if Nkind
(Constr
) = N_Discriminant_Association
then
4686 Disc_Exp
:= Original_Node
(Expression
(Constr
));
4688 Disc_Exp
:= Original_Node
(Constr
);
4691 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
4694 Next_Discriminant
(Discrim
);
4701 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4702 -- check that the level of the type of the created object is not deeper
4703 -- than the level of the allocator's access type, since extensions can
4704 -- now occur at deeper levels than their ancestor types. This is a
4705 -- static accessibility level check; a run-time check is also needed in
4706 -- the case of an initialized allocator with a class-wide argument (see
4707 -- Expand_Allocator_Expression).
4709 if Ada_Version
>= Ada_2005
4710 and then Is_Class_Wide_Type
(Desig_T
)
4713 Exp_Typ
: Entity_Id
;
4716 if Nkind
(E
) = N_Qualified_Expression
then
4717 Exp_Typ
:= Etype
(E
);
4718 elsif Nkind
(E
) = N_Subtype_Indication
then
4719 Exp_Typ
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
4721 Exp_Typ
:= Entity
(E
);
4724 if Type_Access_Level
(Exp_Typ
) >
4725 Deepest_Type_Access_Level
(Typ
)
4727 if In_Instance_Body
then
4728 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4730 ("type in allocator has deeper level than "
4731 & "designated class-wide type<<", E
);
4732 Error_Msg_N
("\Program_Error [<<", E
);
4734 Make_Raise_Program_Error
(Sloc
(N
),
4735 Reason
=> PE_Accessibility_Check_Failed
));
4738 -- Do not apply Ada 2005 accessibility checks on a class-wide
4739 -- allocator if the type given in the allocator is a formal
4740 -- type. A run-time check will be performed in the instance.
4742 elsif not Is_Generic_Type
(Exp_Typ
) then
4743 Error_Msg_N
("type in allocator has deeper level than "
4744 & "designated class-wide type", E
);
4750 -- Check for allocation from an empty storage pool
4752 if No_Pool_Assigned
(Typ
) then
4753 Error_Msg_N
("allocation from empty storage pool!", N
);
4755 -- If the context is an unchecked conversion, as may happen within an
4756 -- inlined subprogram, the allocator is being resolved with its own
4757 -- anonymous type. In that case, if the target type has a specific
4758 -- storage pool, it must be inherited explicitly by the allocator type.
4760 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
4761 and then No
(Associated_Storage_Pool
(Typ
))
4763 Set_Associated_Storage_Pool
4764 (Typ
, Associated_Storage_Pool
(Etype
(Parent
(N
))));
4767 if Ekind
(Etype
(N
)) = E_Anonymous_Access_Type
then
4768 Check_Restriction
(No_Anonymous_Allocators
, N
);
4771 -- Check that an allocator with task parts isn't for a nested access
4772 -- type when restriction No_Task_Hierarchy applies.
4774 if not Is_Library_Level_Entity
(Base_Type
(Typ
))
4775 and then Has_Task
(Base_Type
(Desig_T
))
4777 Check_Restriction
(No_Task_Hierarchy
, N
);
4780 -- An illegal allocator may be rewritten as a raise Program_Error
4783 if Nkind
(N
) = N_Allocator
then
4785 -- An anonymous access discriminant is the definition of a
4788 if Ekind
(Typ
) = E_Anonymous_Access_Type
4789 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
4790 N_Discriminant_Specification
4793 Discr
: constant Entity_Id
:=
4794 Defining_Identifier
(Associated_Node_For_Itype
(Typ
));
4797 Check_Restriction
(No_Coextensions
, N
);
4799 -- Ada 2012 AI05-0052: If the designated type of the allocator
4800 -- is limited, then the allocator shall not be used to define
4801 -- the value of an access discriminant unless the discriminated
4802 -- type is immutably limited.
4804 if Ada_Version
>= Ada_2012
4805 and then Is_Limited_Type
(Desig_T
)
4806 and then not Is_Limited_View
(Scope
(Discr
))
4809 ("only immutably limited types can have anonymous "
4810 & "access discriminants designating a limited type", N
);
4814 -- Avoid marking an allocator as a dynamic coextension if it is
4815 -- within a static construct.
4817 if not Is_Static_Coextension
(N
) then
4818 Set_Is_Dynamic_Coextension
(N
);
4821 -- Cleanup for potential static coextensions
4824 Set_Is_Dynamic_Coextension
(N
, False);
4825 Set_Is_Static_Coextension
(N
, False);
4829 -- Report a simple error: if the designated object is a local task,
4830 -- its body has not been seen yet, and its activation will fail an
4831 -- elaboration check.
4833 if Is_Task_Type
(Desig_T
)
4834 and then Scope
(Base_Type
(Desig_T
)) = Current_Scope
4835 and then Is_Compilation_Unit
(Current_Scope
)
4836 and then Ekind
(Current_Scope
) = E_Package
4837 and then not In_Package_Body
(Current_Scope
)
4839 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4840 Error_Msg_N
("cannot activate task before body seen<<", N
);
4841 Error_Msg_N
("\Program_Error [<<", N
);
4844 -- Ada 2012 (AI05-0111-3): Detect an attempt to allocate a task or a
4845 -- type with a task component on a subpool. This action must raise
4846 -- Program_Error at runtime.
4848 if Ada_Version
>= Ada_2012
4849 and then Nkind
(N
) = N_Allocator
4850 and then Present
(Subpool_Handle_Name
(N
))
4851 and then Has_Task
(Desig_T
)
4853 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4854 Error_Msg_N
("cannot allocate task on subpool<<", N
);
4855 Error_Msg_N
("\Program_Error [<<", N
);
4858 Make_Raise_Program_Error
(Sloc
(N
),
4859 Reason
=> PE_Explicit_Raise
));
4862 end Resolve_Allocator
;
4864 ---------------------------
4865 -- Resolve_Arithmetic_Op --
4866 ---------------------------
4868 -- Used for resolving all arithmetic operators except exponentiation
4870 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
4871 L
: constant Node_Id
:= Left_Opnd
(N
);
4872 R
: constant Node_Id
:= Right_Opnd
(N
);
4873 TL
: constant Entity_Id
:= Base_Type
(Etype
(L
));
4874 TR
: constant Entity_Id
:= Base_Type
(Etype
(R
));
4878 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
4879 -- We do the resolution using the base type, because intermediate values
4880 -- in expressions always are of the base type, not a subtype of it.
4882 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean;
4883 -- Returns True if N is in a context that expects "any real type"
4885 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean;
4886 -- Return True iff given type is Integer or universal real/integer
4888 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
);
4889 -- Choose type of integer literal in fixed-point operation to conform
4890 -- to available fixed-point type. T is the type of the other operand,
4891 -- which is needed to determine the expected type of N.
4893 procedure Set_Operand_Type
(N
: Node_Id
);
4894 -- Set operand type to T if universal
4896 -------------------------------
4897 -- Expected_Type_Is_Any_Real --
4898 -------------------------------
4900 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean is
4902 -- N is the expression after "delta" in a fixed_point_definition;
4905 return Nkind_In
(Parent
(N
), N_Ordinary_Fixed_Point_Definition
,
4906 N_Decimal_Fixed_Point_Definition
,
4908 -- N is one of the bounds in a real_range_specification;
4911 N_Real_Range_Specification
,
4913 -- N is the expression of a delta_constraint;
4916 N_Delta_Constraint
);
4917 end Expected_Type_Is_Any_Real
;
4919 -----------------------------
4920 -- Is_Integer_Or_Universal --
4921 -----------------------------
4923 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean is
4925 Index
: Interp_Index
;
4929 if not Is_Overloaded
(N
) then
4931 return Base_Type
(T
) = Base_Type
(Standard_Integer
)
4932 or else T
= Universal_Integer
4933 or else T
= Universal_Real
;
4935 Get_First_Interp
(N
, Index
, It
);
4936 while Present
(It
.Typ
) loop
4937 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
)
4938 or else It
.Typ
= Universal_Integer
4939 or else It
.Typ
= Universal_Real
4944 Get_Next_Interp
(Index
, It
);
4949 end Is_Integer_Or_Universal
;
4951 ----------------------------
4952 -- Set_Mixed_Mode_Operand --
4953 ----------------------------
4955 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
) is
4956 Index
: Interp_Index
;
4960 if Universal_Interpretation
(N
) = Universal_Integer
then
4962 -- A universal integer literal is resolved as standard integer
4963 -- except in the case of a fixed-point result, where we leave it
4964 -- as universal (to be handled by Exp_Fixd later on)
4966 if Is_Fixed_Point_Type
(T
) then
4967 Resolve
(N
, Universal_Integer
);
4969 Resolve
(N
, Standard_Integer
);
4972 elsif Universal_Interpretation
(N
) = Universal_Real
4973 and then (T
= Base_Type
(Standard_Integer
)
4974 or else T
= Universal_Integer
4975 or else T
= Universal_Real
)
4977 -- A universal real can appear in a fixed-type context. We resolve
4978 -- the literal with that context, even though this might raise an
4979 -- exception prematurely (the other operand may be zero).
4983 elsif Etype
(N
) = Base_Type
(Standard_Integer
)
4984 and then T
= Universal_Real
4985 and then Is_Overloaded
(N
)
4987 -- Integer arg in mixed-mode operation. Resolve with universal
4988 -- type, in case preference rule must be applied.
4990 Resolve
(N
, Universal_Integer
);
4993 and then B_Typ
/= Universal_Fixed
4995 -- Not a mixed-mode operation, resolve with context
4999 elsif Etype
(N
) = Any_Fixed
then
5001 -- N may itself be a mixed-mode operation, so use context type
5005 elsif Is_Fixed_Point_Type
(T
)
5006 and then B_Typ
= Universal_Fixed
5007 and then Is_Overloaded
(N
)
5009 -- Must be (fixed * fixed) operation, operand must have one
5010 -- compatible interpretation.
5012 Resolve
(N
, Any_Fixed
);
5014 elsif Is_Fixed_Point_Type
(B_Typ
)
5015 and then (T
= Universal_Real
or else Is_Fixed_Point_Type
(T
))
5016 and then Is_Overloaded
(N
)
5018 -- C * F(X) in a fixed context, where C is a real literal or a
5019 -- fixed-point expression. F must have either a fixed type
5020 -- interpretation or an integer interpretation, but not both.
5022 Get_First_Interp
(N
, Index
, It
);
5023 while Present
(It
.Typ
) loop
5024 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
) then
5025 if Analyzed
(N
) then
5026 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5028 Resolve
(N
, Standard_Integer
);
5031 elsif Is_Fixed_Point_Type
(It
.Typ
) then
5032 if Analyzed
(N
) then
5033 Error_Msg_N
("ambiguous operand in fixed operation", N
);
5035 Resolve
(N
, It
.Typ
);
5039 Get_Next_Interp
(Index
, It
);
5042 -- Reanalyze the literal with the fixed type of the context. If
5043 -- context is Universal_Fixed, we are within a conversion, leave
5044 -- the literal as a universal real because there is no usable
5045 -- fixed type, and the target of the conversion plays no role in
5059 if B_Typ
= Universal_Fixed
5060 and then Nkind
(Op2
) = N_Real_Literal
5062 T2
:= Universal_Real
;
5067 Set_Analyzed
(Op2
, False);
5074 end Set_Mixed_Mode_Operand
;
5076 ----------------------
5077 -- Set_Operand_Type --
5078 ----------------------
5080 procedure Set_Operand_Type
(N
: Node_Id
) is
5082 if Etype
(N
) = Universal_Integer
5083 or else Etype
(N
) = Universal_Real
5087 end Set_Operand_Type
;
5089 -- Start of processing for Resolve_Arithmetic_Op
5092 if Comes_From_Source
(N
)
5093 and then Ekind
(Entity
(N
)) = E_Function
5094 and then Is_Imported
(Entity
(N
))
5095 and then Is_Intrinsic_Subprogram
(Entity
(N
))
5097 Resolve_Intrinsic_Operator
(N
, Typ
);
5100 -- Special-case for mixed-mode universal expressions or fixed point type
5101 -- operation: each argument is resolved separately. The same treatment
5102 -- is required if one of the operands of a fixed point operation is
5103 -- universal real, since in this case we don't do a conversion to a
5104 -- specific fixed-point type (instead the expander handles the case).
5106 -- Set the type of the node to its universal interpretation because
5107 -- legality checks on an exponentiation operand need the context.
5109 elsif (B_Typ
= Universal_Integer
or else B_Typ
= Universal_Real
)
5110 and then Present
(Universal_Interpretation
(L
))
5111 and then Present
(Universal_Interpretation
(R
))
5113 Set_Etype
(N
, B_Typ
);
5114 Resolve
(L
, Universal_Interpretation
(L
));
5115 Resolve
(R
, Universal_Interpretation
(R
));
5117 elsif (B_Typ
= Universal_Real
5118 or else Etype
(N
) = Universal_Fixed
5119 or else (Etype
(N
) = Any_Fixed
5120 and then Is_Fixed_Point_Type
(B_Typ
))
5121 or else (Is_Fixed_Point_Type
(B_Typ
)
5122 and then (Is_Integer_Or_Universal
(L
)
5124 Is_Integer_Or_Universal
(R
))))
5125 and then Nkind_In
(N
, N_Op_Multiply
, N_Op_Divide
)
5127 if TL
= Universal_Integer
or else TR
= Universal_Integer
then
5128 Check_For_Visible_Operator
(N
, B_Typ
);
5131 -- If context is a fixed type and one operand is integer, the other
5132 -- is resolved with the type of the context.
5134 if Is_Fixed_Point_Type
(B_Typ
)
5135 and then (Base_Type
(TL
) = Base_Type
(Standard_Integer
)
5136 or else TL
= Universal_Integer
)
5141 elsif Is_Fixed_Point_Type
(B_Typ
)
5142 and then (Base_Type
(TR
) = Base_Type
(Standard_Integer
)
5143 or else TR
= Universal_Integer
)
5149 Set_Mixed_Mode_Operand
(L
, TR
);
5150 Set_Mixed_Mode_Operand
(R
, TL
);
5153 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
5154 -- multiplying operators from being used when the expected type is
5155 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
5156 -- some cases where the expected type is actually Any_Real;
5157 -- Expected_Type_Is_Any_Real takes care of that case.
5159 if Etype
(N
) = Universal_Fixed
5160 or else Etype
(N
) = Any_Fixed
5162 if B_Typ
= Universal_Fixed
5163 and then not Expected_Type_Is_Any_Real
(N
)
5164 and then not Nkind_In
(Parent
(N
), N_Type_Conversion
,
5165 N_Unchecked_Type_Conversion
)
5167 Error_Msg_N
("type cannot be determined from context!", N
);
5168 Error_Msg_N
("\explicit conversion to result type required", N
);
5170 Set_Etype
(L
, Any_Type
);
5171 Set_Etype
(R
, Any_Type
);
5174 if Ada_Version
= Ada_83
5175 and then Etype
(N
) = Universal_Fixed
5177 Nkind_In
(Parent
(N
), N_Type_Conversion
,
5178 N_Unchecked_Type_Conversion
)
5181 ("(Ada 83) fixed-point operation "
5182 & "needs explicit conversion", N
);
5185 -- The expected type is "any real type" in contexts like
5187 -- type T is delta <universal_fixed-expression> ...
5189 -- in which case we need to set the type to Universal_Real
5190 -- so that static expression evaluation will work properly.
5192 if Expected_Type_Is_Any_Real
(N
) then
5193 Set_Etype
(N
, Universal_Real
);
5195 Set_Etype
(N
, B_Typ
);
5199 elsif Is_Fixed_Point_Type
(B_Typ
)
5200 and then (Is_Integer_Or_Universal
(L
)
5201 or else Nkind
(L
) = N_Real_Literal
5202 or else Nkind
(R
) = N_Real_Literal
5203 or else Is_Integer_Or_Universal
(R
))
5205 Set_Etype
(N
, B_Typ
);
5207 elsif Etype
(N
) = Any_Fixed
then
5209 -- If no previous errors, this is only possible if one operand is
5210 -- overloaded and the context is universal. Resolve as such.
5212 Set_Etype
(N
, B_Typ
);
5216 if (TL
= Universal_Integer
or else TL
= Universal_Real
)
5218 (TR
= Universal_Integer
or else TR
= Universal_Real
)
5220 Check_For_Visible_Operator
(N
, B_Typ
);
5223 -- If the context is Universal_Fixed and the operands are also
5224 -- universal fixed, this is an error, unless there is only one
5225 -- applicable fixed_point type (usually Duration).
5227 if B_Typ
= Universal_Fixed
and then Etype
(L
) = Universal_Fixed
then
5228 T
:= Unique_Fixed_Point_Type
(N
);
5230 if T
= Any_Type
then
5243 -- If one of the arguments was resolved to a non-universal type.
5244 -- label the result of the operation itself with the same type.
5245 -- Do the same for the universal argument, if any.
5247 T
:= Intersect_Types
(L
, R
);
5248 Set_Etype
(N
, Base_Type
(T
));
5249 Set_Operand_Type
(L
);
5250 Set_Operand_Type
(R
);
5253 Generate_Operator_Reference
(N
, Typ
);
5254 Analyze_Dimension
(N
);
5255 Eval_Arithmetic_Op
(N
);
5257 -- In SPARK, a multiplication or division with operands of fixed point
5258 -- types must be qualified or explicitly converted to identify the
5261 if (Is_Fixed_Point_Type
(Etype
(L
))
5262 or else Is_Fixed_Point_Type
(Etype
(R
)))
5263 and then Nkind_In
(N
, N_Op_Multiply
, N_Op_Divide
)
5265 not Nkind_In
(Parent
(N
), N_Qualified_Expression
, N_Type_Conversion
)
5267 Check_SPARK_05_Restriction
5268 ("operation should be qualified or explicitly converted", N
);
5271 -- Set overflow and division checking bit
5273 if Nkind
(N
) in N_Op
then
5274 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
5275 Enable_Overflow_Check
(N
);
5278 -- Give warning if explicit division by zero
5280 if Nkind_In
(N
, N_Op_Divide
, N_Op_Rem
, N_Op_Mod
)
5281 and then not Division_Checks_Suppressed
(Etype
(N
))
5283 Rop
:= Right_Opnd
(N
);
5285 if Compile_Time_Known_Value
(Rop
)
5286 and then ((Is_Integer_Type
(Etype
(Rop
))
5287 and then Expr_Value
(Rop
) = Uint_0
)
5289 (Is_Real_Type
(Etype
(Rop
))
5290 and then Expr_Value_R
(Rop
) = Ureal_0
))
5292 -- Specialize the warning message according to the operation.
5293 -- The following warnings are for the case
5298 -- For division, we have two cases, for float division
5299 -- of an unconstrained float type, on a machine where
5300 -- Machine_Overflows is false, we don't get an exception
5301 -- at run-time, but rather an infinity or Nan. The Nan
5302 -- case is pretty obscure, so just warn about infinities.
5304 if Is_Floating_Point_Type
(Typ
)
5305 and then not Is_Constrained
(Typ
)
5306 and then not Machine_Overflows_On_Target
5309 ("float division by zero, may generate "
5310 & "'+'/'- infinity??", Right_Opnd
(N
));
5312 -- For all other cases, we get a Constraint_Error
5315 Apply_Compile_Time_Constraint_Error
5316 (N
, "division by zero??", CE_Divide_By_Zero
,
5317 Loc
=> Sloc
(Right_Opnd
(N
)));
5321 Apply_Compile_Time_Constraint_Error
5322 (N
, "rem with zero divisor??", CE_Divide_By_Zero
,
5323 Loc
=> Sloc
(Right_Opnd
(N
)));
5326 Apply_Compile_Time_Constraint_Error
5327 (N
, "mod with zero divisor??", CE_Divide_By_Zero
,
5328 Loc
=> Sloc
(Right_Opnd
(N
)));
5330 -- Division by zero can only happen with division, rem,
5331 -- and mod operations.
5334 raise Program_Error
;
5337 -- Otherwise just set the flag to check at run time
5340 Activate_Division_Check
(N
);
5344 -- If Restriction No_Implicit_Conditionals is active, then it is
5345 -- violated if either operand can be negative for mod, or for rem
5346 -- if both operands can be negative.
5348 if Restriction_Check_Required
(No_Implicit_Conditionals
)
5349 and then Nkind_In
(N
, N_Op_Rem
, N_Op_Mod
)
5358 -- Set if corresponding operand might be negative
5362 (Left_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
5363 LNeg
:= (not OK
) or else Lo
< 0;
5366 (Right_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
5367 RNeg
:= (not OK
) or else Lo
< 0;
5369 -- Check if we will be generating conditionals. There are two
5370 -- cases where that can happen, first for REM, the only case
5371 -- is largest negative integer mod -1, where the division can
5372 -- overflow, but we still have to give the right result. The
5373 -- front end generates a test for this annoying case. Here we
5374 -- just test if both operands can be negative (that's what the
5375 -- expander does, so we match its logic here).
5377 -- The second case is mod where either operand can be negative.
5378 -- In this case, the back end has to generate additional tests.
5380 if (Nkind
(N
) = N_Op_Rem
and then (LNeg
and RNeg
))
5382 (Nkind
(N
) = N_Op_Mod
and then (LNeg
or RNeg
))
5384 Check_Restriction
(No_Implicit_Conditionals
, N
);
5390 Check_Unset_Reference
(L
);
5391 Check_Unset_Reference
(R
);
5392 Check_Function_Writable_Actuals
(N
);
5393 end Resolve_Arithmetic_Op
;
5399 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
5400 function Same_Or_Aliased_Subprograms
5402 E
: Entity_Id
) return Boolean;
5403 -- Returns True if the subprogram entity S is the same as E or else
5404 -- S is an alias of E.
5406 ---------------------------------
5407 -- Same_Or_Aliased_Subprograms --
5408 ---------------------------------
5410 function Same_Or_Aliased_Subprograms
5412 E
: Entity_Id
) return Boolean
5414 Subp_Alias
: constant Entity_Id
:= Alias
(S
);
5416 return S
= E
or else (Present
(Subp_Alias
) and then Subp_Alias
= E
);
5417 end Same_Or_Aliased_Subprograms
;
5421 Loc
: constant Source_Ptr
:= Sloc
(N
);
5422 Subp
: constant Node_Id
:= Name
(N
);
5423 Body_Id
: Entity_Id
;
5433 -- Start of processing for Resolve_Call
5436 -- The context imposes a unique interpretation with type Typ on a
5437 -- procedure or function call. Find the entity of the subprogram that
5438 -- yields the expected type, and propagate the corresponding formal
5439 -- constraints on the actuals. The caller has established that an
5440 -- interpretation exists, and emitted an error if not unique.
5442 -- First deal with the case of a call to an access-to-subprogram,
5443 -- dereference made explicit in Analyze_Call.
5445 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
5446 if not Is_Overloaded
(Subp
) then
5447 Nam
:= Etype
(Subp
);
5450 -- Find the interpretation whose type (a subprogram type) has a
5451 -- return type that is compatible with the context. Analysis of
5452 -- the node has established that one exists.
5456 Get_First_Interp
(Subp
, I
, It
);
5457 while Present
(It
.Typ
) loop
5458 if Covers
(Typ
, Etype
(It
.Typ
)) then
5463 Get_Next_Interp
(I
, It
);
5467 raise Program_Error
;
5471 -- If the prefix is not an entity, then resolve it
5473 if not Is_Entity_Name
(Subp
) then
5474 Resolve
(Subp
, Nam
);
5477 -- For an indirect call, we always invalidate checks, since we do not
5478 -- know whether the subprogram is local or global. Yes we could do
5479 -- better here, e.g. by knowing that there are no local subprograms,
5480 -- but it does not seem worth the effort. Similarly, we kill all
5481 -- knowledge of current constant values.
5483 Kill_Current_Values
;
5485 -- If this is a procedure call which is really an entry call, do
5486 -- the conversion of the procedure call to an entry call. Protected
5487 -- operations use the same circuitry because the name in the call
5488 -- can be an arbitrary expression with special resolution rules.
5490 elsif Nkind_In
(Subp
, N_Selected_Component
, N_Indexed_Component
)
5491 or else (Is_Entity_Name
(Subp
)
5492 and then Ekind
(Entity
(Subp
)) = E_Entry
)
5494 Resolve_Entry_Call
(N
, Typ
);
5495 Check_Elab_Call
(N
);
5497 -- Kill checks and constant values, as above for indirect case
5498 -- Who knows what happens when another task is activated?
5500 Kill_Current_Values
;
5503 -- Normal subprogram call with name established in Resolve
5505 elsif not (Is_Type
(Entity
(Subp
))) then
5506 Nam
:= Entity
(Subp
);
5507 Set_Entity_With_Checks
(Subp
, Nam
);
5509 -- Otherwise we must have the case of an overloaded call
5512 pragma Assert
(Is_Overloaded
(Subp
));
5514 -- Initialize Nam to prevent warning (we know it will be assigned
5515 -- in the loop below, but the compiler does not know that).
5519 Get_First_Interp
(Subp
, I
, It
);
5520 while Present
(It
.Typ
) loop
5521 if Covers
(Typ
, It
.Typ
) then
5523 Set_Entity_With_Checks
(Subp
, Nam
);
5527 Get_Next_Interp
(I
, It
);
5531 if Is_Access_Subprogram_Type
(Base_Type
(Etype
(Nam
)))
5532 and then not Is_Access_Subprogram_Type
(Base_Type
(Typ
))
5533 and then Nkind
(Subp
) /= N_Explicit_Dereference
5534 and then Present
(Parameter_Associations
(N
))
5536 -- The prefix is a parameterless function call that returns an access
5537 -- to subprogram. If parameters are present in the current call, add
5538 -- add an explicit dereference. We use the base type here because
5539 -- within an instance these may be subtypes.
5541 -- The dereference is added either in Analyze_Call or here. Should
5542 -- be consolidated ???
5544 Set_Is_Overloaded
(Subp
, False);
5545 Set_Etype
(Subp
, Etype
(Nam
));
5546 Insert_Explicit_Dereference
(Subp
);
5547 Nam
:= Designated_Type
(Etype
(Nam
));
5548 Resolve
(Subp
, Nam
);
5551 -- Check that a call to Current_Task does not occur in an entry body
5553 if Is_RTE
(Nam
, RE_Current_Task
) then
5562 -- Exclude calls that occur within the default of a formal
5563 -- parameter of the entry, since those are evaluated outside
5566 exit when No
(P
) or else Nkind
(P
) = N_Parameter_Specification
;
5568 if Nkind
(P
) = N_Entry_Body
5569 or else (Nkind
(P
) = N_Subprogram_Body
5570 and then Is_Entry_Barrier_Function
(P
))
5573 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5575 ("& should not be used in entry body (RM C.7(17))<<",
5577 Error_Msg_NE
("\Program_Error [<<", N
, Nam
);
5579 Make_Raise_Program_Error
(Loc
,
5580 Reason
=> PE_Current_Task_In_Entry_Body
));
5581 Set_Etype
(N
, Rtype
);
5588 -- Check that a procedure call does not occur in the context of the
5589 -- entry call statement of a conditional or timed entry call. Note that
5590 -- the case of a call to a subprogram renaming of an entry will also be
5591 -- rejected. The test for N not being an N_Entry_Call_Statement is
5592 -- defensive, covering the possibility that the processing of entry
5593 -- calls might reach this point due to later modifications of the code
5596 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
5597 and then Nkind
(N
) /= N_Entry_Call_Statement
5598 and then Entry_Call_Statement
(Parent
(N
)) = N
5600 if Ada_Version
< Ada_2005
then
5601 Error_Msg_N
("entry call required in select statement", N
);
5603 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5604 -- for a procedure_or_entry_call, the procedure_name or
5605 -- procedure_prefix of the procedure_call_statement shall denote
5606 -- an entry renamed by a procedure, or (a view of) a primitive
5607 -- subprogram of a limited interface whose first parameter is
5608 -- a controlling parameter.
5610 elsif Nkind
(N
) = N_Procedure_Call_Statement
5611 and then not Is_Renamed_Entry
(Nam
)
5612 and then not Is_Controlling_Limited_Procedure
(Nam
)
5615 ("entry call or dispatching primitive of interface required", N
);
5619 -- If the SPARK_05 restriction is active, we are not allowed
5620 -- to have a call to a subprogram before we see its completion.
5622 if not Has_Completion
(Nam
)
5623 and then Restriction_Check_Required
(SPARK_05
)
5625 -- Don't flag strange internal calls
5627 and then Comes_From_Source
(N
)
5628 and then Comes_From_Source
(Nam
)
5630 -- Only flag calls in extended main source
5632 and then In_Extended_Main_Source_Unit
(Nam
)
5633 and then In_Extended_Main_Source_Unit
(N
)
5635 -- Exclude enumeration literals from this processing
5637 and then Ekind
(Nam
) /= E_Enumeration_Literal
5639 Check_SPARK_05_Restriction
5640 ("call to subprogram cannot appear before its body", N
);
5643 -- Check that this is not a call to a protected procedure or entry from
5644 -- within a protected function.
5646 Check_Internal_Protected_Use
(N
, Nam
);
5648 -- Freeze the subprogram name if not in a spec-expression. Note that
5649 -- we freeze procedure calls as well as function calls. Procedure calls
5650 -- are not frozen according to the rules (RM 13.14(14)) because it is
5651 -- impossible to have a procedure call to a non-frozen procedure in
5652 -- pure Ada, but in the code that we generate in the expander, this
5653 -- rule needs extending because we can generate procedure calls that
5656 -- In Ada 2012, expression functions may be called within pre/post
5657 -- conditions of subsequent functions or expression functions. Such
5658 -- calls do not freeze when they appear within generated bodies,
5659 -- (including the body of another expression function) which would
5660 -- place the freeze node in the wrong scope. An expression function
5661 -- is frozen in the usual fashion, by the appearance of a real body,
5662 -- or at the end of a declarative part.
5664 if Is_Entity_Name
(Subp
) and then not In_Spec_Expression
5665 and then not Is_Expression_Function
(Current_Scope
)
5667 (not Is_Expression_Function
(Entity
(Subp
))
5668 or else Scope
(Entity
(Subp
)) = Current_Scope
)
5670 Freeze_Expression
(Subp
);
5673 -- For a predefined operator, the type of the result is the type imposed
5674 -- by context, except for a predefined operation on universal fixed.
5675 -- Otherwise The type of the call is the type returned by the subprogram
5678 if Is_Predefined_Op
(Nam
) then
5679 if Etype
(N
) /= Universal_Fixed
then
5683 -- If the subprogram returns an array type, and the context requires the
5684 -- component type of that array type, the node is really an indexing of
5685 -- the parameterless call. Resolve as such. A pathological case occurs
5686 -- when the type of the component is an access to the array type. In
5687 -- this case the call is truly ambiguous.
5689 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
5691 ((Is_Array_Type
(Etype
(Nam
))
5692 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
5694 (Is_Access_Type
(Etype
(Nam
))
5695 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
5697 Covers
(Typ
, Component_Type
(Designated_Type
(Etype
(Nam
))))))
5700 Index_Node
: Node_Id
;
5702 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
5705 if Is_Access_Type
(Ret_Type
)
5706 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
5709 ("cannot disambiguate function call and indexing", N
);
5711 New_Subp
:= Relocate_Node
(Subp
);
5713 -- The called entity may be an explicit dereference, in which
5714 -- case there is no entity to set.
5716 if Nkind
(New_Subp
) /= N_Explicit_Dereference
then
5717 Set_Entity
(Subp
, Nam
);
5720 if (Is_Array_Type
(Ret_Type
)
5721 and then Component_Type
(Ret_Type
) /= Any_Type
)
5723 (Is_Access_Type
(Ret_Type
)
5725 Component_Type
(Designated_Type
(Ret_Type
)) /= Any_Type
)
5727 if Needs_No_Actuals
(Nam
) then
5729 -- Indexed call to a parameterless function
5732 Make_Indexed_Component
(Loc
,
5734 Make_Function_Call
(Loc
, Name
=> New_Subp
),
5735 Expressions
=> Parameter_Associations
(N
));
5737 -- An Ada 2005 prefixed call to a primitive operation
5738 -- whose first parameter is the prefix. This prefix was
5739 -- prepended to the parameter list, which is actually a
5740 -- list of indexes. Remove the prefix in order to build
5741 -- the proper indexed component.
5744 Make_Indexed_Component
(Loc
,
5746 Make_Function_Call
(Loc
,
5748 Parameter_Associations
=>
5750 (Remove_Head
(Parameter_Associations
(N
)))),
5751 Expressions
=> Parameter_Associations
(N
));
5754 -- Preserve the parenthesis count of the node
5756 Set_Paren_Count
(Index_Node
, Paren_Count
(N
));
5758 -- Since we are correcting a node classification error made
5759 -- by the parser, we call Replace rather than Rewrite.
5761 Replace
(N
, Index_Node
);
5763 Set_Etype
(Prefix
(N
), Ret_Type
);
5765 Resolve_Indexed_Component
(N
, Typ
);
5766 Check_Elab_Call
(Prefix
(N
));
5774 Set_Etype
(N
, Etype
(Nam
));
5777 -- In the case where the call is to an overloaded subprogram, Analyze
5778 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5779 -- such a case Normalize_Actuals needs to be called once more to order
5780 -- the actuals correctly. Otherwise the call will have the ordering
5781 -- given by the last overloaded subprogram whether this is the correct
5782 -- one being called or not.
5784 if Is_Overloaded
(Subp
) then
5785 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
5786 pragma Assert
(Norm_OK
);
5789 -- In any case, call is fully resolved now. Reset Overload flag, to
5790 -- prevent subsequent overload resolution if node is analyzed again
5792 Set_Is_Overloaded
(Subp
, False);
5793 Set_Is_Overloaded
(N
, False);
5795 -- If we are calling the current subprogram from immediately within its
5796 -- body, then that is the case where we can sometimes detect cases of
5797 -- infinite recursion statically. Do not try this in case restriction
5798 -- No_Recursion is in effect anyway, and do it only for source calls.
5800 if Comes_From_Source
(N
) then
5801 Scop
:= Current_Scope
;
5803 -- Check violation of SPARK_05 restriction which does not permit
5804 -- a subprogram body to contain a call to the subprogram directly.
5806 if Restriction_Check_Required
(SPARK_05
)
5807 and then Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5809 Check_SPARK_05_Restriction
5810 ("subprogram may not contain direct call to itself", N
);
5813 -- Issue warning for possible infinite recursion in the absence
5814 -- of the No_Recursion restriction.
5816 if Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5817 and then not Restriction_Active
(No_Recursion
)
5818 and then Check_Infinite_Recursion
(N
)
5820 -- Here we detected and flagged an infinite recursion, so we do
5821 -- not need to test the case below for further warnings. Also we
5822 -- are all done if we now have a raise SE node.
5824 if Nkind
(N
) = N_Raise_Storage_Error
then
5828 -- If call is to immediately containing subprogram, then check for
5829 -- the case of a possible run-time detectable infinite recursion.
5832 Scope_Loop
: while Scop
/= Standard_Standard
loop
5833 if Same_Or_Aliased_Subprograms
(Nam
, Scop
) then
5835 -- Although in general case, recursion is not statically
5836 -- checkable, the case of calling an immediately containing
5837 -- subprogram is easy to catch.
5839 Check_Restriction
(No_Recursion
, N
);
5841 -- If the recursive call is to a parameterless subprogram,
5842 -- then even if we can't statically detect infinite
5843 -- recursion, this is pretty suspicious, and we output a
5844 -- warning. Furthermore, we will try later to detect some
5845 -- cases here at run time by expanding checking code (see
5846 -- Detect_Infinite_Recursion in package Exp_Ch6).
5848 -- If the recursive call is within a handler, do not emit a
5849 -- warning, because this is a common idiom: loop until input
5850 -- is correct, catch illegal input in handler and restart.
5852 if No
(First_Formal
(Nam
))
5853 and then Etype
(Nam
) = Standard_Void_Type
5854 and then not Error_Posted
(N
)
5855 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
5857 -- For the case of a procedure call. We give the message
5858 -- only if the call is the first statement in a sequence
5859 -- of statements, or if all previous statements are
5860 -- simple assignments. This is simply a heuristic to
5861 -- decrease false positives, without losing too many good
5862 -- warnings. The idea is that these previous statements
5863 -- may affect global variables the procedure depends on.
5864 -- We also exclude raise statements, that may arise from
5865 -- constraint checks and are probably unrelated to the
5866 -- intended control flow.
5868 if Nkind
(N
) = N_Procedure_Call_Statement
5869 and then Is_List_Member
(N
)
5875 while Present
(P
) loop
5876 if not Nkind_In
(P
, N_Assignment_Statement
,
5877 N_Raise_Constraint_Error
)
5887 -- Do not give warning if we are in a conditional context
5890 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
5892 if (K
= N_Loop_Statement
5893 and then Present
(Iteration_Scheme
(Parent
(N
))))
5894 or else K
= N_If_Statement
5895 or else K
= N_Elsif_Part
5896 or else K
= N_Case_Statement_Alternative
5902 -- Here warning is to be issued
5904 Set_Has_Recursive_Call
(Nam
);
5905 Error_Msg_Warn
:= SPARK_Mode
/= On
;
5906 Error_Msg_N
("possible infinite recursion<<!", N
);
5907 Error_Msg_N
("\Storage_Error ]<<!", N
);
5913 Scop
:= Scope
(Scop
);
5914 end loop Scope_Loop
;
5918 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5920 Check_Obsolescent_2005_Entity
(Nam
, Subp
);
5922 -- If subprogram name is a predefined operator, it was given in
5923 -- functional notation. Replace call node with operator node, so
5924 -- that actuals can be resolved appropriately.
5926 if Is_Predefined_Op
(Nam
) or else Ekind
(Nam
) = E_Operator
then
5927 Make_Call_Into_Operator
(N
, Typ
, Entity
(Name
(N
)));
5930 elsif Present
(Alias
(Nam
))
5931 and then Is_Predefined_Op
(Alias
(Nam
))
5933 Resolve_Actuals
(N
, Nam
);
5934 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
5938 -- Create a transient scope if the resulting type requires it
5940 -- There are several notable exceptions:
5942 -- a) In init procs, the transient scope overhead is not needed, and is
5943 -- even incorrect when the call is a nested initialization call for a
5944 -- component whose expansion may generate adjust calls. However, if the
5945 -- call is some other procedure call within an initialization procedure
5946 -- (for example a call to Create_Task in the init_proc of the task
5947 -- run-time record) a transient scope must be created around this call.
5949 -- b) Enumeration literal pseudo-calls need no transient scope
5951 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5952 -- functions) do not use the secondary stack even though the return
5953 -- type may be unconstrained.
5955 -- d) Calls to a build-in-place function, since such functions may
5956 -- allocate their result directly in a target object, and cases where
5957 -- the result does get allocated in the secondary stack are checked for
5958 -- within the specialized Exp_Ch6 procedures for expanding those
5959 -- build-in-place calls.
5961 -- e) If the subprogram is marked Inline_Always, then even if it returns
5962 -- an unconstrained type the call does not require use of the secondary
5963 -- stack. However, inlining will only take place if the body to inline
5964 -- is already present. It may not be available if e.g. the subprogram is
5965 -- declared in a child instance.
5967 -- If this is an initialization call for a type whose construction
5968 -- uses the secondary stack, and it is not a nested call to initialize
5969 -- a component, we do need to create a transient scope for it. We
5970 -- check for this by traversing the type in Check_Initialization_Call.
5973 and then Has_Pragma_Inline
(Nam
)
5974 and then Nkind
(Unit_Declaration_Node
(Nam
)) = N_Subprogram_Declaration
5975 and then Present
(Body_To_Inline
(Unit_Declaration_Node
(Nam
)))
5979 elsif Ekind
(Nam
) = E_Enumeration_Literal
5980 or else Is_Build_In_Place_Function
(Nam
)
5981 or else Is_Intrinsic_Subprogram
(Nam
)
5985 elsif Expander_Active
5986 and then Is_Type
(Etype
(Nam
))
5987 and then Requires_Transient_Scope
(Etype
(Nam
))
5989 (not Within_Init_Proc
5991 (not Is_Init_Proc
(Nam
) and then Ekind
(Nam
) /= E_Function
))
5993 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
5995 -- If the call appears within the bounds of a loop, it will
5996 -- be rewritten and reanalyzed, nothing left to do here.
5998 if Nkind
(N
) /= N_Function_Call
then
6002 elsif Is_Init_Proc
(Nam
)
6003 and then not Within_Init_Proc
6005 Check_Initialization_Call
(N
, Nam
);
6008 -- A protected function cannot be called within the definition of the
6009 -- enclosing protected type.
6011 if Is_Protected_Type
(Scope
(Nam
))
6012 and then In_Open_Scopes
(Scope
(Nam
))
6013 and then not Has_Completion
(Scope
(Nam
))
6016 ("& cannot be called before end of protected definition", N
, Nam
);
6019 -- Propagate interpretation to actuals, and add default expressions
6022 if Present
(First_Formal
(Nam
)) then
6023 Resolve_Actuals
(N
, Nam
);
6025 -- Overloaded literals are rewritten as function calls, for purpose of
6026 -- resolution. After resolution, we can replace the call with the
6029 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
6030 Copy_Node
(Subp
, N
);
6031 Resolve_Entity_Name
(N
, Typ
);
6033 -- Avoid validation, since it is a static function call
6035 Generate_Reference
(Nam
, Subp
);
6039 -- If the subprogram is not global, then kill all saved values and
6040 -- checks. This is a bit conservative, since in many cases we could do
6041 -- better, but it is not worth the effort. Similarly, we kill constant
6042 -- values. However we do not need to do this for internal entities
6043 -- (unless they are inherited user-defined subprograms), since they
6044 -- are not in the business of molesting local values.
6046 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
6047 -- kill all checks and values for calls to global subprograms. This
6048 -- takes care of the case where an access to a local subprogram is
6049 -- taken, and could be passed directly or indirectly and then called
6050 -- from almost any context.
6052 -- Note: we do not do this step till after resolving the actuals. That
6053 -- way we still take advantage of the current value information while
6054 -- scanning the actuals.
6056 -- We suppress killing values if we are processing the nodes associated
6057 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
6058 -- type kills all the values as part of analyzing the code that
6059 -- initializes the dispatch tables.
6061 if Inside_Freezing_Actions
= 0
6062 and then (not Is_Library_Level_Entity
(Nam
)
6063 or else Suppress_Value_Tracking_On_Call
6064 (Nearest_Dynamic_Scope
(Current_Scope
)))
6065 and then (Comes_From_Source
(Nam
)
6066 or else (Present
(Alias
(Nam
))
6067 and then Comes_From_Source
(Alias
(Nam
))))
6069 Kill_Current_Values
;
6072 -- If we are warning about unread OUT parameters, this is the place to
6073 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
6074 -- after the above call to Kill_Current_Values (since that call clears
6075 -- the Last_Assignment field of all local variables).
6077 if (Warn_On_Modified_Unread
or Warn_On_All_Unread_Out_Parameters
)
6078 and then Comes_From_Source
(N
)
6079 and then In_Extended_Main_Source_Unit
(N
)
6086 F
:= First_Formal
(Nam
);
6087 A
:= First_Actual
(N
);
6088 while Present
(F
) and then Present
(A
) loop
6089 if Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
)
6090 and then Warn_On_Modified_As_Out_Parameter
(F
)
6091 and then Is_Entity_Name
(A
)
6092 and then Present
(Entity
(A
))
6093 and then Comes_From_Source
(N
)
6094 and then Safe_To_Capture_Value
(N
, Entity
(A
))
6096 Set_Last_Assignment
(Entity
(A
), A
);
6105 -- If the subprogram is a primitive operation, check whether or not
6106 -- it is a correct dispatching call.
6108 if Is_Overloadable
(Nam
)
6109 and then Is_Dispatching_Operation
(Nam
)
6111 Check_Dispatching_Call
(N
);
6113 elsif Ekind
(Nam
) /= E_Subprogram_Type
6114 and then Is_Abstract_Subprogram
(Nam
)
6115 and then not In_Instance
6117 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Nam
);
6120 -- If this is a dispatching call, generate the appropriate reference,
6121 -- for better source navigation in GPS.
6123 if Is_Overloadable
(Nam
)
6124 and then Present
(Controlling_Argument
(N
))
6126 Generate_Reference
(Nam
, Subp
, 'R');
6128 -- Normal case, not a dispatching call: generate a call reference
6131 Generate_Reference
(Nam
, Subp
, 's');
6134 if Is_Intrinsic_Subprogram
(Nam
) then
6135 Check_Intrinsic_Call
(N
);
6138 -- Check for violation of restriction No_Specific_Termination_Handlers
6139 -- and warn on a potentially blocking call to Abort_Task.
6141 if Restriction_Check_Required
(No_Specific_Termination_Handlers
)
6142 and then (Is_RTE
(Nam
, RE_Set_Specific_Handler
)
6144 Is_RTE
(Nam
, RE_Specific_Handler
))
6146 Check_Restriction
(No_Specific_Termination_Handlers
, N
);
6148 elsif Is_RTE
(Nam
, RE_Abort_Task
) then
6149 Check_Potentially_Blocking_Operation
(N
);
6152 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
6153 -- timing event violates restriction No_Relative_Delay (AI-0211). We
6154 -- need to check the second argument to determine whether it is an
6155 -- absolute or relative timing event.
6157 if Restriction_Check_Required
(No_Relative_Delay
)
6158 and then Is_RTE
(Nam
, RE_Set_Handler
)
6159 and then Is_RTE
(Etype
(Next_Actual
(First_Actual
(N
))), RE_Time_Span
)
6161 Check_Restriction
(No_Relative_Delay
, N
);
6164 -- Issue an error for a call to an eliminated subprogram. This routine
6165 -- will not perform the check if the call appears within a default
6168 Check_For_Eliminated_Subprogram
(Subp
, Nam
);
6170 -- In formal mode, the primitive operations of a tagged type or type
6171 -- extension do not include functions that return the tagged type.
6173 if Nkind
(N
) = N_Function_Call
6174 and then Is_Tagged_Type
(Etype
(N
))
6175 and then Is_Entity_Name
(Name
(N
))
6176 and then Is_Inherited_Operation_For_Type
(Entity
(Name
(N
)), Etype
(N
))
6178 Check_SPARK_05_Restriction
("function not inherited", N
);
6181 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
6182 -- class-wide and the call dispatches on result in a context that does
6183 -- not provide a tag, the call raises Program_Error.
6185 if Nkind
(N
) = N_Function_Call
6186 and then In_Instance
6187 and then Is_Generic_Actual_Type
(Typ
)
6188 and then Is_Class_Wide_Type
(Typ
)
6189 and then Has_Controlling_Result
(Nam
)
6190 and then Nkind
(Parent
(N
)) = N_Object_Declaration
6192 -- Verify that none of the formals are controlling
6195 Call_OK
: Boolean := False;
6199 F
:= First_Formal
(Nam
);
6200 while Present
(F
) loop
6201 if Is_Controlling_Formal
(F
) then
6210 Error_Msg_Warn
:= SPARK_Mode
/= On
;
6211 Error_Msg_N
("!cannot determine tag of result<<", N
);
6212 Error_Msg_N
("\Program_Error [<<!", N
);
6214 Make_Raise_Program_Error
(Sloc
(N
),
6215 Reason
=> PE_Explicit_Raise
));
6220 -- Check for calling a function with OUT or IN OUT parameter when the
6221 -- calling context (us right now) is not Ada 2012, so does not allow
6222 -- OUT or IN OUT parameters in function calls.
6224 if Ada_Version
< Ada_2012
6225 and then Ekind
(Nam
) = E_Function
6226 and then Has_Out_Or_In_Out_Parameter
(Nam
)
6228 Error_Msg_NE
("& has at least one OUT or `IN OUT` parameter", N
, Nam
);
6229 Error_Msg_N
("\call to this function only allowed in Ada 2012", N
);
6232 -- Check the dimensions of the actuals in the call. For function calls,
6233 -- propagate the dimensions from the returned type to N.
6235 Analyze_Dimension_Call
(N
, Nam
);
6237 -- All done, evaluate call and deal with elaboration issues
6240 Check_Elab_Call
(N
);
6242 -- In GNATprove mode, expansion is disabled, but we want to inline some
6243 -- subprograms to facilitate formal verification. Indirect calls through
6244 -- a subprogram type or within a generic cannot be inlined. Inlining is
6245 -- performed only for calls subject to SPARK_Mode on.
6248 and then SPARK_Mode
= On
6249 and then Is_Overloadable
(Nam
)
6250 and then not Inside_A_Generic
6252 Nam_UA
:= Ultimate_Alias
(Nam
);
6253 Nam_Decl
:= Unit_Declaration_Node
(Nam_UA
);
6255 if Nkind
(Nam_Decl
) = N_Subprogram_Declaration
then
6256 Body_Id
:= Corresponding_Body
(Nam_Decl
);
6258 -- Nothing to do if the subprogram is not eligible for inlining in
6261 if not Is_Inlined_Always
(Nam_UA
)
6262 or else not Can_Be_Inlined_In_GNATprove_Mode
(Nam_UA
, Body_Id
)
6266 -- Calls cannot be inlined inside assertions, as GNATprove treats
6267 -- assertions as logic expressions.
6269 elsif In_Assertion_Expr
/= 0 then
6270 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6271 Error_Msg_N
("\call appears in assertion expression", N
);
6272 Set_Is_Inlined_Always
(Nam_UA
, False);
6274 -- Calls cannot be inlined inside default expressions
6276 elsif In_Default_Expr
then
6277 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6278 Error_Msg_N
("\call appears in default expression", N
);
6279 Set_Is_Inlined_Always
(Nam_UA
, False);
6281 -- Inlining should not be performed during pre-analysis
6283 elsif Full_Analysis
then
6285 -- With the one-pass inlining technique, a call cannot be
6286 -- inlined if the corresponding body has not been seen yet.
6288 if No
(Body_Id
) then
6290 ("?no contextual analysis of & (body not seen yet)",
6292 Set_Is_Inlined_Always
(Nam_UA
, False);
6294 -- Nothing to do if there is no body to inline, indicating that
6295 -- the subprogram is not suitable for inlining in GNATprove
6298 elsif No
(Body_To_Inline
(Nam_Decl
)) then
6301 -- Calls cannot be inlined inside potentially unevaluated
6302 -- expressions, as this would create complex actions inside
6303 -- expressions, that are not handled by GNATprove.
6305 elsif Is_Potentially_Unevaluated
(N
) then
6306 Error_Msg_NE
("?no contextual analysis of &", N
, Nam
);
6308 ("\call appears in potentially unevaluated context", N
);
6309 Set_Is_Inlined_Always
(Nam_UA
, False);
6311 -- Otherwise, inline the call
6314 Expand_Inlined_Call
(N
, Nam_UA
, Nam
);
6320 Warn_On_Overlapping_Actuals
(Nam
, N
);
6323 -----------------------------
6324 -- Resolve_Case_Expression --
6325 -----------------------------
6327 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
6331 Alt
:= First
(Alternatives
(N
));
6332 while Present
(Alt
) loop
6333 Resolve
(Expression
(Alt
), Typ
);
6338 Eval_Case_Expression
(N
);
6339 end Resolve_Case_Expression
;
6341 -------------------------------
6342 -- Resolve_Character_Literal --
6343 -------------------------------
6345 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
6346 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
6350 -- Verify that the character does belong to the type of the context
6352 Set_Etype
(N
, B_Typ
);
6353 Eval_Character_Literal
(N
);
6355 -- Wide_Wide_Character literals must always be defined, since the set
6356 -- of wide wide character literals is complete, i.e. if a character
6357 -- literal is accepted by the parser, then it is OK for wide wide
6358 -- character (out of range character literals are rejected).
6360 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
6363 -- Always accept character literal for type Any_Character, which
6364 -- occurs in error situations and in comparisons of literals, both
6365 -- of which should accept all literals.
6367 elsif B_Typ
= Any_Character
then
6370 -- For Standard.Character or a type derived from it, check that the
6371 -- literal is in range.
6373 elsif Root_Type
(B_Typ
) = Standard_Character
then
6374 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
6378 -- For Standard.Wide_Character or a type derived from it, check that the
6379 -- literal is in range.
6381 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
6382 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
6386 -- For Standard.Wide_Wide_Character or a type derived from it, we
6387 -- know the literal is in range, since the parser checked.
6389 elsif Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
6392 -- If the entity is already set, this has already been resolved in a
6393 -- generic context, or comes from expansion. Nothing else to do.
6395 elsif Present
(Entity
(N
)) then
6398 -- Otherwise we have a user defined character type, and we can use the
6399 -- standard visibility mechanisms to locate the referenced entity.
6402 C
:= Current_Entity
(N
);
6403 while Present
(C
) loop
6404 if Etype
(C
) = B_Typ
then
6405 Set_Entity_With_Checks
(N
, C
);
6406 Generate_Reference
(C
, N
);
6414 -- If we fall through, then the literal does not match any of the
6415 -- entries of the enumeration type. This isn't just a constraint error
6416 -- situation, it is an illegality (see RM 4.2).
6419 ("character not defined for }", N
, First_Subtype
(B_Typ
));
6420 end Resolve_Character_Literal
;
6422 ---------------------------
6423 -- Resolve_Comparison_Op --
6424 ---------------------------
6426 -- Context requires a boolean type, and plays no role in resolution.
6427 -- Processing identical to that for equality operators. The result type is
6428 -- the base type, which matters when pathological subtypes of booleans with
6429 -- limited ranges are used.
6431 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6432 L
: constant Node_Id
:= Left_Opnd
(N
);
6433 R
: constant Node_Id
:= Right_Opnd
(N
);
6437 -- If this is an intrinsic operation which is not predefined, use the
6438 -- types of its declared arguments to resolve the possibly overloaded
6439 -- operands. Otherwise the operands are unambiguous and specify the
6442 if Scope
(Entity
(N
)) /= Standard_Standard
then
6443 T
:= Etype
(First_Entity
(Entity
(N
)));
6446 T
:= Find_Unique_Type
(L
, R
);
6448 if T
= Any_Fixed
then
6449 T
:= Unique_Fixed_Point_Type
(L
);
6453 Set_Etype
(N
, Base_Type
(Typ
));
6454 Generate_Reference
(T
, N
, ' ');
6456 -- Skip remaining processing if already set to Any_Type
6458 if T
= Any_Type
then
6462 -- Deal with other error cases
6464 if T
= Any_String
or else
6465 T
= Any_Composite
or else
6468 if T
= Any_Character
then
6469 Ambiguous_Character
(L
);
6471 Error_Msg_N
("ambiguous operands for comparison", N
);
6474 Set_Etype
(N
, Any_Type
);
6478 -- Resolve the operands if types OK
6482 Check_Unset_Reference
(L
);
6483 Check_Unset_Reference
(R
);
6484 Generate_Operator_Reference
(N
, T
);
6485 Check_Low_Bound_Tested
(N
);
6487 -- In SPARK, ordering operators <, <=, >, >= are not defined for Boolean
6488 -- types or array types except String.
6490 if Is_Boolean_Type
(T
) then
6491 Check_SPARK_05_Restriction
6492 ("comparison is not defined on Boolean type", N
);
6494 elsif Is_Array_Type
(T
)
6495 and then Base_Type
(T
) /= Standard_String
6497 Check_SPARK_05_Restriction
6498 ("comparison is not defined on array types other than String", N
);
6501 -- Check comparison on unordered enumeration
6503 if Bad_Unordered_Enumeration_Reference
(N
, Etype
(L
)) then
6504 Error_Msg_Sloc
:= Sloc
(Etype
(L
));
6506 ("comparison on unordered enumeration type& declared#?U?",
6510 -- Evaluate the relation (note we do this after the above check since
6511 -- this Eval call may change N to True/False.
6513 Analyze_Dimension
(N
);
6514 Eval_Relational_Op
(N
);
6515 end Resolve_Comparison_Op
;
6517 -----------------------------------------
6518 -- Resolve_Discrete_Subtype_Indication --
6519 -----------------------------------------
6521 procedure Resolve_Discrete_Subtype_Indication
6529 Analyze
(Subtype_Mark
(N
));
6530 S
:= Entity
(Subtype_Mark
(N
));
6532 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
6533 Error_Msg_N
("expect range constraint for discrete type", N
);
6534 Set_Etype
(N
, Any_Type
);
6537 R
:= Range_Expression
(Constraint
(N
));
6545 if Base_Type
(S
) /= Base_Type
(Typ
) then
6547 ("expect subtype of }", N
, First_Subtype
(Typ
));
6549 -- Rewrite the constraint as a range of Typ
6550 -- to allow compilation to proceed further.
6553 Rewrite
(Low_Bound
(R
),
6554 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
6555 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
6556 Attribute_Name
=> Name_First
));
6557 Rewrite
(High_Bound
(R
),
6558 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
6559 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
6560 Attribute_Name
=> Name_First
));
6564 Set_Etype
(N
, Etype
(R
));
6566 -- Additionally, we must check that the bounds are compatible
6567 -- with the given subtype, which might be different from the
6568 -- type of the context.
6570 Apply_Range_Check
(R
, S
);
6572 -- ??? If the above check statically detects a Constraint_Error
6573 -- it replaces the offending bound(s) of the range R with a
6574 -- Constraint_Error node. When the itype which uses these bounds
6575 -- is frozen the resulting call to Duplicate_Subexpr generates
6576 -- a new temporary for the bounds.
6578 -- Unfortunately there are other itypes that are also made depend
6579 -- on these bounds, so when Duplicate_Subexpr is called they get
6580 -- a forward reference to the newly created temporaries and Gigi
6581 -- aborts on such forward references. This is probably sign of a
6582 -- more fundamental problem somewhere else in either the order of
6583 -- itype freezing or the way certain itypes are constructed.
6585 -- To get around this problem we call Remove_Side_Effects right
6586 -- away if either bounds of R are a Constraint_Error.
6589 L
: constant Node_Id
:= Low_Bound
(R
);
6590 H
: constant Node_Id
:= High_Bound
(R
);
6593 if Nkind
(L
) = N_Raise_Constraint_Error
then
6594 Remove_Side_Effects
(L
);
6597 if Nkind
(H
) = N_Raise_Constraint_Error
then
6598 Remove_Side_Effects
(H
);
6602 Check_Unset_Reference
(Low_Bound
(R
));
6603 Check_Unset_Reference
(High_Bound
(R
));
6606 end Resolve_Discrete_Subtype_Indication
;
6608 -------------------------
6609 -- Resolve_Entity_Name --
6610 -------------------------
6612 -- Used to resolve identifiers and expanded names
6614 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
6615 function Appears_In_Check
(Nod
: Node_Id
) return Boolean;
6616 -- Denote whether an arbitrary node Nod appears in a check node
6618 function Is_OK_Volatile_Context
6620 Obj_Ref
: Node_Id
) return Boolean;
6621 -- Determine whether node Context denotes a "non-interfering context"
6622 -- (as defined in SPARK RM 7.1.3(13)) where volatile reference Obj_Ref
6623 -- can safely reside.
6625 ----------------------
6626 -- Appears_In_Check --
6627 ----------------------
6629 function Appears_In_Check
(Nod
: Node_Id
) return Boolean is
6633 -- Climb the parent chain looking for a check node
6636 while Present
(Par
) loop
6637 if Nkind
(Par
) in N_Raise_xxx_Error
then
6640 -- Prevent the search from going too far
6642 elsif Is_Body_Or_Package_Declaration
(Par
) then
6646 Par
:= Parent
(Par
);
6650 end Appears_In_Check
;
6652 ----------------------------
6653 -- Is_OK_Volatile_Context --
6654 ----------------------------
6656 function Is_OK_Volatile_Context
6658 Obj_Ref
: Node_Id
) return Boolean
6661 -- The volatile object appears on either side of an assignment
6663 if Nkind
(Context
) = N_Assignment_Statement
then
6666 -- The volatile object is part of the initialization expression of
6667 -- another object. Ensure that the climb of the parent chain came
6668 -- from the expression side and not from the name side.
6670 elsif Nkind
(Context
) = N_Object_Declaration
6671 and then Present
(Expression
(Context
))
6672 and then Expression
(Context
) = Obj_Ref
6676 -- The volatile object appears as an actual parameter in a call to an
6677 -- instance of Unchecked_Conversion whose result is renamed.
6679 elsif Nkind
(Context
) = N_Function_Call
6680 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
6681 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
6685 -- The volatile object appears as the prefix of a name occurring
6686 -- in a non-interfering context.
6688 elsif Nkind_In
(Context
, N_Attribute_Reference
,
6689 N_Indexed_Component
,
6690 N_Selected_Component
,
6692 and then Prefix
(Context
) = Obj_Ref
6693 and then Is_OK_Volatile_Context
6694 (Context
=> Parent
(Context
),
6699 -- Allow references to volatile objects in various checks. This is
6700 -- not a direct SPARK 2014 requirement.
6702 elsif Appears_In_Check
(Context
) then
6708 end Is_OK_Volatile_Context
;
6712 E
: constant Entity_Id
:= Entity
(N
);
6713 Par
: constant Node_Id
:= Parent
(N
);
6715 -- Start of processing for Resolve_Entity_Name
6718 -- If garbage from errors, set to Any_Type and return
6720 if No
(E
) and then Total_Errors_Detected
/= 0 then
6721 Set_Etype
(N
, Any_Type
);
6725 -- Replace named numbers by corresponding literals. Note that this is
6726 -- the one case where Resolve_Entity_Name must reset the Etype, since
6727 -- it is currently marked as universal.
6729 if Ekind
(E
) = E_Named_Integer
then
6731 Eval_Named_Integer
(N
);
6733 elsif Ekind
(E
) = E_Named_Real
then
6735 Eval_Named_Real
(N
);
6737 -- For enumeration literals, we need to make sure that a proper style
6738 -- check is done, since such literals are overloaded, and thus we did
6739 -- not do a style check during the first phase of analysis.
6741 elsif Ekind
(E
) = E_Enumeration_Literal
then
6742 Set_Entity_With_Checks
(N
, E
);
6743 Eval_Entity_Name
(N
);
6745 -- Case of subtype name appearing as an operand in expression
6747 elsif Is_Type
(E
) then
6749 -- Allow use of subtype if it is a concurrent type where we are
6750 -- currently inside the body. This will eventually be expanded into a
6751 -- call to Self (for tasks) or _object (for protected objects). Any
6752 -- other use of a subtype is invalid.
6754 if Is_Concurrent_Type
(E
)
6755 and then In_Open_Scopes
(E
)
6759 -- Any other use is an error
6763 ("invalid use of subtype mark in expression or call", N
);
6766 -- Check discriminant use if entity is discriminant in current scope,
6767 -- i.e. discriminant of record or concurrent type currently being
6768 -- analyzed. Uses in corresponding body are unrestricted.
6770 elsif Ekind
(E
) = E_Discriminant
6771 and then Scope
(E
) = Current_Scope
6772 and then not Has_Completion
(Current_Scope
)
6774 Check_Discriminant_Use
(N
);
6776 -- A parameterless generic function cannot appear in a context that
6777 -- requires resolution.
6779 elsif Ekind
(E
) = E_Generic_Function
then
6780 Error_Msg_N
("illegal use of generic function", N
);
6782 elsif Ekind
(E
) = E_Out_Parameter
6783 and then Ada_Version
= Ada_83
6784 and then (Nkind
(Parent
(N
)) in N_Op
6785 or else (Nkind
(Parent
(N
)) = N_Assignment_Statement
6786 and then N
= Expression
(Parent
(N
)))
6787 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
)
6789 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
6791 -- In all other cases, just do the possible static evaluation
6794 -- A deferred constant that appears in an expression must have a
6795 -- completion, unless it has been removed by in-place expansion of
6798 if Ekind
(E
) = E_Constant
6799 and then Comes_From_Source
(E
)
6800 and then No
(Constant_Value
(E
))
6801 and then Is_Frozen
(Etype
(E
))
6802 and then not In_Spec_Expression
6803 and then not Is_Imported
(E
)
6805 if No_Initialization
(Parent
(E
))
6806 or else (Present
(Full_View
(E
))
6807 and then No_Initialization
(Parent
(Full_View
(E
))))
6812 "deferred constant is frozen before completion", N
);
6816 Eval_Entity_Name
(N
);
6819 -- An effectively volatile object subject to enabled properties
6820 -- Async_Writers or Effective_Reads must appear in a specific context.
6821 -- The following checks are only relevant when SPARK_Mode is on as they
6822 -- are not standard Ada legality rules.
6825 and then Is_Object
(E
)
6826 and then Is_Effectively_Volatile
(E
)
6827 and then Comes_From_Source
(E
)
6829 (Async_Writers_Enabled
(E
) or else Effective_Reads_Enabled
(E
))
6831 -- The effectively volatile objects appears in a "non-interfering
6832 -- context" as defined in SPARK RM 7.1.3(13).
6834 if Is_OK_Volatile_Context
(Par
, N
) then
6837 -- Assume that references to effectively volatile objects that appear
6838 -- as actual parameters in a procedure call are always legal. The
6839 -- full legality check is done when the actuals are resolved.
6841 elsif Nkind
(Par
) = N_Procedure_Call_Statement
then
6844 -- Otherwise the context causes a side effect with respect to the
6845 -- effectively volatile object.
6849 ("volatile object cannot appear in this context "
6850 & "(SPARK RM 7.1.3(13))", N
);
6853 end Resolve_Entity_Name
;
6859 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
6860 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
6868 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
6869 -- If the bounds of the entry family being called depend on task
6870 -- discriminants, build a new index subtype where a discriminant is
6871 -- replaced with the value of the discriminant of the target task.
6872 -- The target task is the prefix of the entry name in the call.
6874 -----------------------
6875 -- Actual_Index_Type --
6876 -----------------------
6878 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
6879 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
6880 Tsk
: constant Entity_Id
:= Scope
(E
);
6881 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
6882 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
6885 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
6886 -- If the bound is given by a discriminant, replace with a reference
6887 -- to the discriminant of the same name in the target task. If the
6888 -- entry name is the target of a requeue statement and the entry is
6889 -- in the current protected object, the bound to be used is the
6890 -- discriminal of the object (see Apply_Range_Checks for details of
6891 -- the transformation).
6893 -----------------------------
6894 -- Actual_Discriminant_Ref --
6895 -----------------------------
6897 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
6898 Typ
: constant Entity_Id
:= Etype
(Bound
);
6902 Remove_Side_Effects
(Bound
);
6904 if not Is_Entity_Name
(Bound
)
6905 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
6909 elsif Is_Protected_Type
(Tsk
)
6910 and then In_Open_Scopes
(Tsk
)
6911 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
6913 -- Note: here Bound denotes a discriminant of the corresponding
6914 -- record type tskV, whose discriminal is a formal of the
6915 -- init-proc tskVIP. What we want is the body discriminal,
6916 -- which is associated to the discriminant of the original
6917 -- concurrent type tsk.
6919 return New_Occurrence_Of
6920 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
6924 Make_Selected_Component
(Loc
,
6925 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
6926 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
6931 end Actual_Discriminant_Ref
;
6933 -- Start of processing for Actual_Index_Type
6936 if not Has_Discriminants
(Tsk
)
6937 or else (not Is_Entity_Name
(Lo
) and then not Is_Entity_Name
(Hi
))
6939 return Entry_Index_Type
(E
);
6942 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
6943 Set_Etype
(New_T
, Base_Type
(Typ
));
6944 Set_Size_Info
(New_T
, Typ
);
6945 Set_RM_Size
(New_T
, RM_Size
(Typ
));
6946 Set_Scalar_Range
(New_T
,
6947 Make_Range
(Sloc
(Entry_Name
),
6948 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
6949 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
6953 end Actual_Index_Type
;
6955 -- Start of processing of Resolve_Entry
6958 -- Find name of entry being called, and resolve prefix of name with its
6959 -- own type. The prefix can be overloaded, and the name and signature of
6960 -- the entry must be taken into account.
6962 if Nkind
(Entry_Name
) = N_Indexed_Component
then
6964 -- Case of dealing with entry family within the current tasks
6966 E_Name
:= Prefix
(Entry_Name
);
6969 E_Name
:= Entry_Name
;
6972 if Is_Entity_Name
(E_Name
) then
6974 -- Entry call to an entry (or entry family) in the current task. This
6975 -- is legal even though the task will deadlock. Rewrite as call to
6978 -- This can also be a call to an entry in an enclosing task. If this
6979 -- is a single task, we have to retrieve its name, because the scope
6980 -- of the entry is the task type, not the object. If the enclosing
6981 -- task is a task type, the identity of the task is given by its own
6984 -- Finally this can be a requeue on an entry of the same task or
6985 -- protected object.
6987 S
:= Scope
(Entity
(E_Name
));
6989 for J
in reverse 0 .. Scope_Stack
.Last
loop
6990 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
6991 and then not Comes_From_Source
(S
)
6993 -- S is an enclosing task or protected object. The concurrent
6994 -- declaration has been converted into a type declaration, and
6995 -- the object itself has an object declaration that follows
6996 -- the type in the same declarative part.
6998 Tsk
:= Next_Entity
(S
);
6999 while Etype
(Tsk
) /= S
loop
7006 elsif S
= Scope_Stack
.Table
(J
).Entity
then
7008 -- Call to current task. Will be transformed into call to Self
7016 Make_Selected_Component
(Loc
,
7017 Prefix
=> New_Occurrence_Of
(S
, Loc
),
7019 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
7020 Rewrite
(E_Name
, New_N
);
7023 elsif Nkind
(Entry_Name
) = N_Selected_Component
7024 and then Is_Overloaded
(Prefix
(Entry_Name
))
7026 -- Use the entry name (which must be unique at this point) to find
7027 -- the prefix that returns the corresponding task/protected type.
7030 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
7031 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
7036 Get_First_Interp
(Pref
, I
, It
);
7037 while Present
(It
.Typ
) loop
7038 if Scope
(Ent
) = It
.Typ
then
7039 Set_Etype
(Pref
, It
.Typ
);
7043 Get_Next_Interp
(I
, It
);
7048 if Nkind
(Entry_Name
) = N_Selected_Component
then
7049 Resolve
(Prefix
(Entry_Name
));
7051 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7052 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7053 Resolve
(Prefix
(Prefix
(Entry_Name
)));
7054 Index
:= First
(Expressions
(Entry_Name
));
7055 Resolve
(Index
, Entry_Index_Type
(Nam
));
7057 -- Up to this point the expression could have been the actual in a
7058 -- simple entry call, and be given by a named association.
7060 if Nkind
(Index
) = N_Parameter_Association
then
7061 Error_Msg_N
("expect expression for entry index", Index
);
7063 Apply_Range_Check
(Index
, Actual_Index_Type
(Nam
));
7068 ------------------------
7069 -- Resolve_Entry_Call --
7070 ------------------------
7072 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
7073 Entry_Name
: constant Node_Id
:= Name
(N
);
7074 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
7076 First_Named
: Node_Id
;
7083 -- We kill all checks here, because it does not seem worth the effort to
7084 -- do anything better, an entry call is a big operation.
7088 -- Processing of the name is similar for entry calls and protected
7089 -- operation calls. Once the entity is determined, we can complete
7090 -- the resolution of the actuals.
7092 -- The selector may be overloaded, in the case of a protected object
7093 -- with overloaded functions. The type of the context is used for
7096 if Nkind
(Entry_Name
) = N_Selected_Component
7097 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
7098 and then Typ
/= Standard_Void_Type
7105 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
7106 while Present
(It
.Typ
) loop
7107 if Covers
(Typ
, It
.Typ
) then
7108 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
7109 Set_Etype
(Entry_Name
, It
.Typ
);
7111 Generate_Reference
(It
.Typ
, N
, ' ');
7114 Get_Next_Interp
(I
, It
);
7119 Resolve_Entry
(Entry_Name
);
7121 if Nkind
(Entry_Name
) = N_Selected_Component
then
7123 -- Simple entry call
7125 Nam
:= Entity
(Selector_Name
(Entry_Name
));
7126 Obj
:= Prefix
(Entry_Name
);
7127 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
7129 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7131 -- Call to member of entry family
7133 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7134 Obj
:= Prefix
(Prefix
(Entry_Name
));
7135 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
7138 -- We cannot in general check the maximum depth of protected entry calls
7139 -- at compile time. But we can tell that any protected entry call at all
7140 -- violates a specified nesting depth of zero.
7142 if Is_Protected_Type
(Scope
(Nam
)) then
7143 Check_Restriction
(Max_Entry_Queue_Length
, N
);
7146 -- Use context type to disambiguate a protected function that can be
7147 -- called without actuals and that returns an array type, and where the
7148 -- argument list may be an indexing of the returned value.
7150 if Ekind
(Nam
) = E_Function
7151 and then Needs_No_Actuals
(Nam
)
7152 and then Present
(Parameter_Associations
(N
))
7154 ((Is_Array_Type
(Etype
(Nam
))
7155 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
7157 or else (Is_Access_Type
(Etype
(Nam
))
7158 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
7162 Component_Type
(Designated_Type
(Etype
(Nam
))))))
7165 Index_Node
: Node_Id
;
7169 Make_Indexed_Component
(Loc
,
7171 Make_Function_Call
(Loc
, Name
=> Relocate_Node
(Entry_Name
)),
7172 Expressions
=> Parameter_Associations
(N
));
7174 -- Since we are correcting a node classification error made by the
7175 -- parser, we call Replace rather than Rewrite.
7177 Replace
(N
, Index_Node
);
7178 Set_Etype
(Prefix
(N
), Etype
(Nam
));
7180 Resolve_Indexed_Component
(N
, Typ
);
7185 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
)
7186 and then Present
(PPC_Wrapper
(Nam
))
7187 and then Current_Scope
/= PPC_Wrapper
(Nam
)
7189 -- Rewrite as call to the precondition wrapper, adding the task
7190 -- object to the list of actuals. If the call is to a member of an
7191 -- entry family, include the index as well.
7195 New_Actuals
: List_Id
;
7198 New_Actuals
:= New_List
(Obj
);
7200 if Nkind
(Entry_Name
) = N_Indexed_Component
then
7201 Append_To
(New_Actuals
,
7202 New_Copy_Tree
(First
(Expressions
(Entry_Name
))));
7205 Append_List
(Parameter_Associations
(N
), New_Actuals
);
7207 Make_Procedure_Call_Statement
(Loc
,
7209 New_Occurrence_Of
(PPC_Wrapper
(Nam
), Loc
),
7210 Parameter_Associations
=> New_Actuals
);
7211 Rewrite
(N
, New_Call
);
7213 -- Preanalyze and resolve new call. Current procedure is called
7214 -- from Resolve_Call, after which expansion will take place.
7216 Preanalyze_And_Resolve
(N
);
7221 -- The operation name may have been overloaded. Order the actuals
7222 -- according to the formals of the resolved entity, and set the return
7223 -- type to that of the operation.
7226 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
7227 pragma Assert
(Norm_OK
);
7228 Set_Etype
(N
, Etype
(Nam
));
7231 Resolve_Actuals
(N
, Nam
);
7232 Check_Internal_Protected_Use
(N
, Nam
);
7234 -- Create a call reference to the entry
7236 Generate_Reference
(Nam
, Entry_Name
, 's');
7238 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
) then
7239 Check_Potentially_Blocking_Operation
(N
);
7242 -- Verify that a procedure call cannot masquerade as an entry
7243 -- call where an entry call is expected.
7245 if Ekind
(Nam
) = E_Procedure
then
7246 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
7247 and then N
= Entry_Call_Statement
(Parent
(N
))
7249 Error_Msg_N
("entry call required in select statement", N
);
7251 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
7252 and then N
= Triggering_Statement
(Parent
(N
))
7254 Error_Msg_N
("triggering statement cannot be procedure call", N
);
7256 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
7257 and then not In_Open_Scopes
(Scope
(Nam
))
7259 Error_Msg_N
("task has no entry with this name", Entry_Name
);
7263 -- After resolution, entry calls and protected procedure calls are
7264 -- changed into entry calls, for expansion. The structure of the node
7265 -- does not change, so it can safely be done in place. Protected
7266 -- function calls must keep their structure because they are
7269 if Ekind
(Nam
) /= E_Function
then
7271 -- A protected operation that is not a function may modify the
7272 -- corresponding object, and cannot apply to a constant. If this
7273 -- is an internal call, the prefix is the type itself.
7275 if Is_Protected_Type
(Scope
(Nam
))
7276 and then not Is_Variable
(Obj
)
7277 and then (not Is_Entity_Name
(Obj
)
7278 or else not Is_Type
(Entity
(Obj
)))
7281 ("prefix of protected procedure or entry call must be variable",
7285 Actuals
:= Parameter_Associations
(N
);
7286 First_Named
:= First_Named_Actual
(N
);
7289 Make_Entry_Call_Statement
(Loc
,
7291 Parameter_Associations
=> Actuals
));
7293 Set_First_Named_Actual
(N
, First_Named
);
7294 Set_Analyzed
(N
, True);
7296 -- Protected functions can return on the secondary stack, in which
7297 -- case we must trigger the transient scope mechanism.
7299 elsif Expander_Active
7300 and then Requires_Transient_Scope
(Etype
(Nam
))
7302 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
7304 end Resolve_Entry_Call
;
7306 -------------------------
7307 -- Resolve_Equality_Op --
7308 -------------------------
7310 -- Both arguments must have the same type, and the boolean context does
7311 -- not participate in the resolution. The first pass verifies that the
7312 -- interpretation is not ambiguous, and the type of the left argument is
7313 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
7314 -- are strings or aggregates, allocators, or Null, they are ambiguous even
7315 -- though they carry a single (universal) type. Diagnose this case here.
7317 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7318 L
: constant Node_Id
:= Left_Opnd
(N
);
7319 R
: constant Node_Id
:= Right_Opnd
(N
);
7320 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
7322 procedure Check_If_Expression
(Cond
: Node_Id
);
7323 -- The resolution rule for if expressions requires that each such must
7324 -- have a unique type. This means that if several dependent expressions
7325 -- are of a non-null anonymous access type, and the context does not
7326 -- impose an expected type (as can be the case in an equality operation)
7327 -- the expression must be rejected.
7329 procedure Explain_Redundancy
(N
: Node_Id
);
7330 -- Attempt to explain the nature of a redundant comparison with True. If
7331 -- the expression N is too complex, this routine issues a general error
7334 function Find_Unique_Access_Type
return Entity_Id
;
7335 -- In the case of allocators and access attributes, the context must
7336 -- provide an indication of the specific access type to be used. If
7337 -- one operand is of such a "generic" access type, check whether there
7338 -- is a specific visible access type that has the same designated type.
7339 -- This is semantically dubious, and of no interest to any real code,
7340 -- but c48008a makes it all worthwhile.
7342 -------------------------
7343 -- Check_If_Expression --
7344 -------------------------
7346 procedure Check_If_Expression
(Cond
: Node_Id
) is
7347 Then_Expr
: Node_Id
;
7348 Else_Expr
: Node_Id
;
7351 if Nkind
(Cond
) = N_If_Expression
then
7352 Then_Expr
:= Next
(First
(Expressions
(Cond
)));
7353 Else_Expr
:= Next
(Then_Expr
);
7355 if Nkind
(Then_Expr
) /= N_Null
7356 and then Nkind
(Else_Expr
) /= N_Null
7358 Error_Msg_N
("cannot determine type of if expression", Cond
);
7361 end Check_If_Expression
;
7363 ------------------------
7364 -- Explain_Redundancy --
7365 ------------------------
7367 procedure Explain_Redundancy
(N
: Node_Id
) is
7375 -- Strip the operand down to an entity
7378 if Nkind
(Val
) = N_Selected_Component
then
7379 Val
:= Selector_Name
(Val
);
7385 -- The construct denotes an entity
7387 if Is_Entity_Name
(Val
) and then Present
(Entity
(Val
)) then
7388 Val_Id
:= Entity
(Val
);
7390 -- Do not generate an error message when the comparison is done
7391 -- against the enumeration literal Standard.True.
7393 if Ekind
(Val_Id
) /= E_Enumeration_Literal
then
7395 -- Build a customized error message
7398 Add_Str_To_Name_Buffer
("?r?");
7400 if Ekind
(Val_Id
) = E_Component
then
7401 Add_Str_To_Name_Buffer
("component ");
7403 elsif Ekind
(Val_Id
) = E_Constant
then
7404 Add_Str_To_Name_Buffer
("constant ");
7406 elsif Ekind
(Val_Id
) = E_Discriminant
then
7407 Add_Str_To_Name_Buffer
("discriminant ");
7409 elsif Is_Formal
(Val_Id
) then
7410 Add_Str_To_Name_Buffer
("parameter ");
7412 elsif Ekind
(Val_Id
) = E_Variable
then
7413 Add_Str_To_Name_Buffer
("variable ");
7416 Add_Str_To_Name_Buffer
("& is always True!");
7419 Error_Msg_NE
(Get_Name_String
(Error
), Val
, Val_Id
);
7422 -- The construct is too complex to disect, issue a general message
7425 Error_Msg_N
("?r?expression is always True!", Val
);
7427 end Explain_Redundancy
;
7429 -----------------------------
7430 -- Find_Unique_Access_Type --
7431 -----------------------------
7433 function Find_Unique_Access_Type
return Entity_Id
is
7439 if Ekind_In
(Etype
(R
), E_Allocator_Type
,
7440 E_Access_Attribute_Type
)
7442 Acc
:= Designated_Type
(Etype
(R
));
7444 elsif Ekind_In
(Etype
(L
), E_Allocator_Type
,
7445 E_Access_Attribute_Type
)
7447 Acc
:= Designated_Type
(Etype
(L
));
7453 while S
/= Standard_Standard
loop
7454 E
:= First_Entity
(S
);
7455 while Present
(E
) loop
7457 and then Is_Access_Type
(E
)
7458 and then Ekind
(E
) /= E_Allocator_Type
7459 and then Designated_Type
(E
) = Base_Type
(Acc
)
7471 end Find_Unique_Access_Type
;
7473 -- Start of processing for Resolve_Equality_Op
7476 Set_Etype
(N
, Base_Type
(Typ
));
7477 Generate_Reference
(T
, N
, ' ');
7479 if T
= Any_Fixed
then
7480 T
:= Unique_Fixed_Point_Type
(L
);
7483 if T
/= Any_Type
then
7484 if T
= Any_String
or else
7485 T
= Any_Composite
or else
7488 if T
= Any_Character
then
7489 Ambiguous_Character
(L
);
7491 Error_Msg_N
("ambiguous operands for equality", N
);
7494 Set_Etype
(N
, Any_Type
);
7497 elsif T
= Any_Access
7498 or else Ekind_In
(T
, E_Allocator_Type
, E_Access_Attribute_Type
)
7500 T
:= Find_Unique_Access_Type
;
7503 Error_Msg_N
("ambiguous operands for equality", N
);
7504 Set_Etype
(N
, Any_Type
);
7508 -- If expressions must have a single type, and if the context does
7509 -- not impose one the dependent expressions cannot be anonymous
7512 -- Why no similar processing for case expressions???
7514 elsif Ada_Version
>= Ada_2012
7515 and then Ekind_In
(Etype
(L
), E_Anonymous_Access_Type
,
7516 E_Anonymous_Access_Subprogram_Type
)
7517 and then Ekind_In
(Etype
(R
), E_Anonymous_Access_Type
,
7518 E_Anonymous_Access_Subprogram_Type
)
7520 Check_If_Expression
(L
);
7521 Check_If_Expression
(R
);
7527 -- In SPARK, equality operators = and /= for array types other than
7528 -- String are only defined when, for each index position, the
7529 -- operands have equal static bounds.
7531 if Is_Array_Type
(T
) then
7533 -- Protect call to Matching_Static_Array_Bounds to avoid costly
7534 -- operation if not needed.
7536 if Restriction_Check_Required
(SPARK_05
)
7537 and then Base_Type
(T
) /= Standard_String
7538 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
7539 and then Etype
(L
) /= Any_Composite
-- or else L in error
7540 and then Etype
(R
) /= Any_Composite
-- or else R in error
7541 and then not Matching_Static_Array_Bounds
(Etype
(L
), Etype
(R
))
7543 Check_SPARK_05_Restriction
7544 ("array types should have matching static bounds", N
);
7548 -- If the unique type is a class-wide type then it will be expanded
7549 -- into a dispatching call to the predefined primitive. Therefore we
7550 -- check here for potential violation of such restriction.
7552 if Is_Class_Wide_Type
(T
) then
7553 Check_Restriction
(No_Dispatching_Calls
, N
);
7556 if Warn_On_Redundant_Constructs
7557 and then Comes_From_Source
(N
)
7558 and then Comes_From_Source
(R
)
7559 and then Is_Entity_Name
(R
)
7560 and then Entity
(R
) = Standard_True
7562 Error_Msg_N
-- CODEFIX
7563 ("?r?comparison with True is redundant!", N
);
7564 Explain_Redundancy
(Original_Node
(R
));
7567 Check_Unset_Reference
(L
);
7568 Check_Unset_Reference
(R
);
7569 Generate_Operator_Reference
(N
, T
);
7570 Check_Low_Bound_Tested
(N
);
7572 -- If this is an inequality, it may be the implicit inequality
7573 -- created for a user-defined operation, in which case the corres-
7574 -- ponding equality operation is not intrinsic, and the operation
7575 -- cannot be constant-folded. Else fold.
7577 if Nkind
(N
) = N_Op_Eq
7578 or else Comes_From_Source
(Entity
(N
))
7579 or else Ekind
(Entity
(N
)) = E_Operator
7580 or else Is_Intrinsic_Subprogram
7581 (Corresponding_Equality
(Entity
(N
)))
7583 Analyze_Dimension
(N
);
7584 Eval_Relational_Op
(N
);
7586 elsif Nkind
(N
) = N_Op_Ne
7587 and then Is_Abstract_Subprogram
(Entity
(N
))
7589 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Entity
(N
));
7592 -- Ada 2005: If one operand is an anonymous access type, convert the
7593 -- other operand to it, to ensure that the underlying types match in
7594 -- the back-end. Same for access_to_subprogram, and the conversion
7595 -- verifies that the types are subtype conformant.
7597 -- We apply the same conversion in the case one of the operands is a
7598 -- private subtype of the type of the other.
7600 -- Why the Expander_Active test here ???
7604 (Ekind_In
(T
, E_Anonymous_Access_Type
,
7605 E_Anonymous_Access_Subprogram_Type
)
7606 or else Is_Private_Type
(T
))
7608 if Etype
(L
) /= T
then
7610 Make_Unchecked_Type_Conversion
(Sloc
(L
),
7611 Subtype_Mark
=> New_Occurrence_Of
(T
, Sloc
(L
)),
7612 Expression
=> Relocate_Node
(L
)));
7613 Analyze_And_Resolve
(L
, T
);
7616 if (Etype
(R
)) /= T
then
7618 Make_Unchecked_Type_Conversion
(Sloc
(R
),
7619 Subtype_Mark
=> New_Occurrence_Of
(Etype
(L
), Sloc
(R
)),
7620 Expression
=> Relocate_Node
(R
)));
7621 Analyze_And_Resolve
(R
, T
);
7625 end Resolve_Equality_Op
;
7627 ----------------------------------
7628 -- Resolve_Explicit_Dereference --
7629 ----------------------------------
7631 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
7632 Loc
: constant Source_Ptr
:= Sloc
(N
);
7634 P
: constant Node_Id
:= Prefix
(N
);
7637 -- The candidate prefix type, if overloaded
7643 Check_Fully_Declared_Prefix
(Typ
, P
);
7646 -- A useful optimization: check whether the dereference denotes an
7647 -- element of a container, and if so rewrite it as a call to the
7648 -- corresponding Element function.
7650 -- Disabled for now, on advice of ARG. A more restricted form of the
7651 -- predicate might be acceptable ???
7653 -- if Is_Container_Element (N) then
7657 if Is_Overloaded
(P
) then
7659 -- Use the context type to select the prefix that has the correct
7660 -- designated type. Keep the first match, which will be the inner-
7663 Get_First_Interp
(P
, I
, It
);
7665 while Present
(It
.Typ
) loop
7666 if Is_Access_Type
(It
.Typ
)
7667 and then Covers
(Typ
, Designated_Type
(It
.Typ
))
7673 -- Remove access types that do not match, but preserve access
7674 -- to subprogram interpretations, in case a further dereference
7675 -- is needed (see below).
7677 elsif Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7681 Get_Next_Interp
(I
, It
);
7684 if Present
(P_Typ
) then
7686 Set_Etype
(N
, Designated_Type
(P_Typ
));
7689 -- If no interpretation covers the designated type of the prefix,
7690 -- this is the pathological case where not all implementations of
7691 -- the prefix allow the interpretation of the node as a call. Now
7692 -- that the expected type is known, Remove other interpretations
7693 -- from prefix, rewrite it as a call, and resolve again, so that
7694 -- the proper call node is generated.
7696 Get_First_Interp
(P
, I
, It
);
7697 while Present
(It
.Typ
) loop
7698 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7702 Get_Next_Interp
(I
, It
);
7706 Make_Function_Call
(Loc
,
7708 Make_Explicit_Dereference
(Loc
,
7710 Parameter_Associations
=> New_List
);
7712 Save_Interps
(N
, New_N
);
7714 Analyze_And_Resolve
(N
, Typ
);
7718 -- If not overloaded, resolve P with its own type
7724 if Is_Access_Type
(Etype
(P
)) then
7725 Apply_Access_Check
(N
);
7728 -- If the designated type is a packed unconstrained array type, and the
7729 -- explicit dereference is not in the context of an attribute reference,
7730 -- then we must compute and set the actual subtype, since it is needed
7731 -- by Gigi. The reason we exclude the attribute case is that this is
7732 -- handled fine by Gigi, and in fact we use such attributes to build the
7733 -- actual subtype. We also exclude generated code (which builds actual
7734 -- subtypes directly if they are needed).
7736 if Is_Array_Type
(Etype
(N
))
7737 and then Is_Packed
(Etype
(N
))
7738 and then not Is_Constrained
(Etype
(N
))
7739 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
7740 and then Comes_From_Source
(N
)
7742 Set_Etype
(N
, Get_Actual_Subtype
(N
));
7745 -- Note: No Eval processing is required for an explicit dereference,
7746 -- because such a name can never be static.
7748 end Resolve_Explicit_Dereference
;
7750 -------------------------------------
7751 -- Resolve_Expression_With_Actions --
7752 -------------------------------------
7754 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
7758 -- If N has no actions, and its expression has been constant folded,
7759 -- then rewrite N as just its expression. Note, we can't do this in
7760 -- the general case of Is_Empty_List (Actions (N)) as this would cause
7761 -- Expression (N) to be expanded again.
7763 if Is_Empty_List
(Actions
(N
))
7764 and then Compile_Time_Known_Value
(Expression
(N
))
7766 Rewrite
(N
, Expression
(N
));
7768 end Resolve_Expression_With_Actions
;
7770 ----------------------------------
7771 -- Resolve_Generalized_Indexing --
7772 ----------------------------------
7774 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
) is
7775 Indexing
: constant Node_Id
:= Generalized_Indexing
(N
);
7781 -- In ASIS mode, propagate the information about the indices back to
7782 -- to the original indexing node. The generalized indexing is either
7783 -- a function call, or a dereference of one. The actuals include the
7784 -- prefix of the original node, which is the container expression.
7787 Resolve
(Indexing
, Typ
);
7788 Set_Etype
(N
, Etype
(Indexing
));
7789 Set_Is_Overloaded
(N
, False);
7792 while Nkind_In
(Call
, N_Explicit_Dereference
, N_Selected_Component
)
7794 Call
:= Prefix
(Call
);
7797 if Nkind
(Call
) = N_Function_Call
then
7798 Indices
:= Parameter_Associations
(Call
);
7799 Pref
:= Remove_Head
(Indices
);
7800 Set_Expressions
(N
, Indices
);
7801 Set_Prefix
(N
, Pref
);
7805 Rewrite
(N
, Indexing
);
7808 end Resolve_Generalized_Indexing
;
7810 ---------------------------
7811 -- Resolve_If_Expression --
7812 ---------------------------
7814 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7815 Condition
: constant Node_Id
:= First
(Expressions
(N
));
7816 Then_Expr
: constant Node_Id
:= Next
(Condition
);
7817 Else_Expr
: Node_Id
:= Next
(Then_Expr
);
7818 Else_Typ
: Entity_Id
;
7819 Then_Typ
: Entity_Id
;
7822 Resolve
(Condition
, Any_Boolean
);
7823 Resolve
(Then_Expr
, Typ
);
7824 Then_Typ
:= Etype
(Then_Expr
);
7826 -- When the "then" expression is of a scalar subtype different from the
7827 -- result subtype, then insert a conversion to ensure the generation of
7828 -- a constraint check. The same is done for the else part below, again
7829 -- comparing subtypes rather than base types.
7831 if Is_Scalar_Type
(Then_Typ
)
7832 and then Then_Typ
/= Typ
7834 Rewrite
(Then_Expr
, Convert_To
(Typ
, Then_Expr
));
7835 Analyze_And_Resolve
(Then_Expr
, Typ
);
7838 -- If ELSE expression present, just resolve using the determined type
7840 if Present
(Else_Expr
) then
7841 Resolve
(Else_Expr
, Typ
);
7842 Else_Typ
:= Etype
(Else_Expr
);
7844 if Is_Scalar_Type
(Else_Typ
)
7845 and then Else_Typ
/= Typ
7847 Rewrite
(Else_Expr
, Convert_To
(Typ
, Else_Expr
));
7848 Analyze_And_Resolve
(Else_Expr
, Typ
);
7851 -- If no ELSE expression is present, root type must be Standard.Boolean
7852 -- and we provide a Standard.True result converted to the appropriate
7853 -- Boolean type (in case it is a derived boolean type).
7855 elsif Root_Type
(Typ
) = Standard_Boolean
then
7857 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
7858 Analyze_And_Resolve
(Else_Expr
, Typ
);
7859 Append_To
(Expressions
(N
), Else_Expr
);
7862 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
7863 Append_To
(Expressions
(N
), Error
);
7867 Eval_If_Expression
(N
);
7868 end Resolve_If_Expression
;
7870 -------------------------------
7871 -- Resolve_Indexed_Component --
7872 -------------------------------
7874 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
7875 Name
: constant Node_Id
:= Prefix
(N
);
7877 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
7881 if Present
(Generalized_Indexing
(N
)) then
7882 Resolve_Generalized_Indexing
(N
, Typ
);
7886 if Is_Overloaded
(Name
) then
7888 -- Use the context type to select the prefix that yields the correct
7894 I1
: Interp_Index
:= 0;
7895 P
: constant Node_Id
:= Prefix
(N
);
7896 Found
: Boolean := False;
7899 Get_First_Interp
(P
, I
, It
);
7900 while Present
(It
.Typ
) loop
7901 if (Is_Array_Type
(It
.Typ
)
7902 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
7903 or else (Is_Access_Type
(It
.Typ
)
7904 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
7908 Component_Type
(Designated_Type
(It
.Typ
))))
7911 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
7913 if It
= No_Interp
then
7914 Error_Msg_N
("ambiguous prefix for indexing", N
);
7920 Array_Type
:= It
.Typ
;
7926 Array_Type
:= It
.Typ
;
7931 Get_Next_Interp
(I
, It
);
7936 Array_Type
:= Etype
(Name
);
7939 Resolve
(Name
, Array_Type
);
7940 Array_Type
:= Get_Actual_Subtype_If_Available
(Name
);
7942 -- If prefix is access type, dereference to get real array type.
7943 -- Note: we do not apply an access check because the expander always
7944 -- introduces an explicit dereference, and the check will happen there.
7946 if Is_Access_Type
(Array_Type
) then
7947 Array_Type
:= Designated_Type
(Array_Type
);
7950 -- If name was overloaded, set component type correctly now
7951 -- If a misplaced call to an entry family (which has no index types)
7952 -- return. Error will be diagnosed from calling context.
7954 if Is_Array_Type
(Array_Type
) then
7955 Set_Etype
(N
, Component_Type
(Array_Type
));
7960 Index
:= First_Index
(Array_Type
);
7961 Expr
:= First
(Expressions
(N
));
7963 -- The prefix may have resolved to a string literal, in which case its
7964 -- etype has a special representation. This is only possible currently
7965 -- if the prefix is a static concatenation, written in functional
7968 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
7969 Resolve
(Expr
, Standard_Positive
);
7972 while Present
(Index
) and Present
(Expr
) loop
7973 Resolve
(Expr
, Etype
(Index
));
7974 Check_Unset_Reference
(Expr
);
7976 if Is_Scalar_Type
(Etype
(Expr
)) then
7977 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
7979 Apply_Range_Check
(Expr
, Get_Actual_Subtype
(Index
));
7987 Analyze_Dimension
(N
);
7989 -- Do not generate the warning on suspicious index if we are analyzing
7990 -- package Ada.Tags; otherwise we will report the warning with the
7991 -- Prims_Ptr field of the dispatch table.
7993 if Scope
(Etype
(Prefix
(N
))) = Standard_Standard
7995 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Prefix
(N
)))),
7998 Warn_On_Suspicious_Index
(Name
, First
(Expressions
(N
)));
7999 Eval_Indexed_Component
(N
);
8002 -- If the array type is atomic, and the component is not atomic, then
8003 -- this is worth a warning, since we have a situation where the access
8004 -- to the component may cause extra read/writes of the atomic array
8005 -- object, or partial word accesses, which could be unexpected.
8007 if Nkind
(N
) = N_Indexed_Component
8008 and then Is_Atomic_Ref_With_Address
(N
)
8009 and then not (Has_Atomic_Components
(Array_Type
)
8010 or else (Is_Entity_Name
(Prefix
(N
))
8011 and then Has_Atomic_Components
8012 (Entity
(Prefix
(N
)))))
8013 and then not Is_Atomic
(Component_Type
(Array_Type
))
8015 Error_Msg_N
("??access to non-atomic component of atomic array",
8017 Error_Msg_N
("??\may cause unexpected accesses to atomic object",
8020 end Resolve_Indexed_Component
;
8022 -----------------------------
8023 -- Resolve_Integer_Literal --
8024 -----------------------------
8026 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
8029 Eval_Integer_Literal
(N
);
8030 end Resolve_Integer_Literal
;
8032 --------------------------------
8033 -- Resolve_Intrinsic_Operator --
8034 --------------------------------
8036 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
8037 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8042 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
;
8043 -- If the operand is a literal, it cannot be the expression in a
8044 -- conversion. Use a qualified expression instead.
8046 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
is
8047 Loc
: constant Source_Ptr
:= Sloc
(Opnd
);
8050 if Nkind_In
(Opnd
, N_Integer_Literal
, N_Real_Literal
) then
8052 Make_Qualified_Expression
(Loc
,
8053 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
8054 Expression
=> Relocate_Node
(Opnd
));
8058 Res
:= Unchecked_Convert_To
(Btyp
, Opnd
);
8062 end Convert_Operand
;
8064 -- Start of processing for Resolve_Intrinsic_Operator
8067 -- We must preserve the original entity in a generic setting, so that
8068 -- the legality of the operation can be verified in an instance.
8070 if not Expander_Active
then
8075 while Scope
(Op
) /= Standard_Standard
loop
8077 pragma Assert
(Present
(Op
));
8081 Set_Is_Overloaded
(N
, False);
8083 -- If the result or operand types are private, rewrite with unchecked
8084 -- conversions on the operands and the result, to expose the proper
8085 -- underlying numeric type.
8087 if Is_Private_Type
(Typ
)
8088 or else Is_Private_Type
(Etype
(Left_Opnd
(N
)))
8089 or else Is_Private_Type
(Etype
(Right_Opnd
(N
)))
8091 Arg1
:= Convert_Operand
(Left_Opnd
(N
));
8092 -- Unchecked_Convert_To (Btyp, Left_Opnd (N));
8093 -- What on earth is this commented out fragment of code???
8095 if Nkind
(N
) = N_Op_Expon
then
8096 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
8098 Arg2
:= Convert_Operand
(Right_Opnd
(N
));
8101 if Nkind
(Arg1
) = N_Type_Conversion
then
8102 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8105 if Nkind
(Arg2
) = N_Type_Conversion
then
8106 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8109 Set_Left_Opnd
(N
, Arg1
);
8110 Set_Right_Opnd
(N
, Arg2
);
8112 Set_Etype
(N
, Btyp
);
8113 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8116 elsif Typ
/= Etype
(Left_Opnd
(N
))
8117 or else Typ
/= Etype
(Right_Opnd
(N
))
8119 -- Add explicit conversion where needed, and save interpretations in
8120 -- case operands are overloaded.
8122 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
8123 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
8125 if Nkind
(Arg1
) = N_Type_Conversion
then
8126 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8128 Save_Interps
(Left_Opnd
(N
), Arg1
);
8131 if Nkind
(Arg2
) = N_Type_Conversion
then
8132 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8134 Save_Interps
(Right_Opnd
(N
), Arg2
);
8137 Rewrite
(Left_Opnd
(N
), Arg1
);
8138 Rewrite
(Right_Opnd
(N
), Arg2
);
8141 Resolve_Arithmetic_Op
(N
, Typ
);
8144 Resolve_Arithmetic_Op
(N
, Typ
);
8146 end Resolve_Intrinsic_Operator
;
8148 --------------------------------------
8149 -- Resolve_Intrinsic_Unary_Operator --
8150 --------------------------------------
8152 procedure Resolve_Intrinsic_Unary_Operator
8156 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8162 while Scope
(Op
) /= Standard_Standard
loop
8164 pragma Assert
(Present
(Op
));
8169 if Is_Private_Type
(Typ
) then
8170 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
8171 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8173 Set_Right_Opnd
(N
, Arg2
);
8175 Set_Etype
(N
, Btyp
);
8176 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8180 Resolve_Unary_Op
(N
, Typ
);
8182 end Resolve_Intrinsic_Unary_Operator
;
8184 ------------------------
8185 -- Resolve_Logical_Op --
8186 ------------------------
8188 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8192 Check_No_Direct_Boolean_Operators
(N
);
8194 -- Predefined operations on scalar types yield the base type. On the
8195 -- other hand, logical operations on arrays yield the type of the
8196 -- arguments (and the context).
8198 if Is_Array_Type
(Typ
) then
8201 B_Typ
:= Base_Type
(Typ
);
8204 -- The following test is required because the operands of the operation
8205 -- may be literals, in which case the resulting type appears to be
8206 -- compatible with a signed integer type, when in fact it is compatible
8207 -- only with modular types. If the context itself is universal, the
8208 -- operation is illegal.
8210 if not Valid_Boolean_Arg
(Typ
) then
8211 Error_Msg_N
("invalid context for logical operation", N
);
8212 Set_Etype
(N
, Any_Type
);
8215 elsif Typ
= Any_Modular
then
8217 ("no modular type available in this context", N
);
8218 Set_Etype
(N
, Any_Type
);
8221 elsif Is_Modular_Integer_Type
(Typ
)
8222 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
8223 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
8225 Check_For_Visible_Operator
(N
, B_Typ
);
8228 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
8229 -- is active and the result type is standard Boolean (do not mess with
8230 -- ops that return a nonstandard Boolean type, because something strange
8233 -- Note: you might expect this replacement to be done during expansion,
8234 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
8235 -- is used, no part of the right operand of an "and" or "or" operator
8236 -- should be executed if the left operand would short-circuit the
8237 -- evaluation of the corresponding "and then" or "or else". If we left
8238 -- the replacement to expansion time, then run-time checks associated
8239 -- with such operands would be evaluated unconditionally, due to being
8240 -- before the condition prior to the rewriting as short-circuit forms
8241 -- during expansion.
8243 if Short_Circuit_And_Or
8244 and then B_Typ
= Standard_Boolean
8245 and then Nkind_In
(N
, N_Op_And
, N_Op_Or
)
8247 if Nkind
(N
) = N_Op_And
then
8249 Make_And_Then
(Sloc
(N
),
8250 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8251 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8252 Analyze_And_Resolve
(N
, B_Typ
);
8254 -- Case of OR changed to OR ELSE
8258 Make_Or_Else
(Sloc
(N
),
8259 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8260 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8261 Analyze_And_Resolve
(N
, B_Typ
);
8264 -- Return now, since analysis of the rewritten ops will take care of
8265 -- other reference bookkeeping and expression folding.
8270 Resolve
(Left_Opnd
(N
), B_Typ
);
8271 Resolve
(Right_Opnd
(N
), B_Typ
);
8273 Check_Unset_Reference
(Left_Opnd
(N
));
8274 Check_Unset_Reference
(Right_Opnd
(N
));
8276 Set_Etype
(N
, B_Typ
);
8277 Generate_Operator_Reference
(N
, B_Typ
);
8278 Eval_Logical_Op
(N
);
8280 -- In SPARK, logical operations AND, OR and XOR for arrays are defined
8281 -- only when both operands have same static lower and higher bounds. Of
8282 -- course the types have to match, so only check if operands are
8283 -- compatible and the node itself has no errors.
8285 if Is_Array_Type
(B_Typ
)
8286 and then Nkind
(N
) in N_Binary_Op
8289 Left_Typ
: constant Node_Id
:= Etype
(Left_Opnd
(N
));
8290 Right_Typ
: constant Node_Id
:= Etype
(Right_Opnd
(N
));
8293 -- Protect call to Matching_Static_Array_Bounds to avoid costly
8294 -- operation if not needed.
8296 if Restriction_Check_Required
(SPARK_05
)
8297 and then Base_Type
(Left_Typ
) = Base_Type
(Right_Typ
)
8298 and then Left_Typ
/= Any_Composite
-- or Left_Opnd in error
8299 and then Right_Typ
/= Any_Composite
-- or Right_Opnd in error
8300 and then not Matching_Static_Array_Bounds
(Left_Typ
, Right_Typ
)
8302 Check_SPARK_05_Restriction
8303 ("array types should have matching static bounds", N
);
8308 Check_Function_Writable_Actuals
(N
);
8309 end Resolve_Logical_Op
;
8311 ---------------------------
8312 -- Resolve_Membership_Op --
8313 ---------------------------
8315 -- The context can only be a boolean type, and does not determine the
8316 -- arguments. Arguments should be unambiguous, but the preference rule for
8317 -- universal types applies.
8319 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8320 pragma Warnings
(Off
, Typ
);
8322 L
: constant Node_Id
:= Left_Opnd
(N
);
8323 R
: constant Node_Id
:= Right_Opnd
(N
);
8326 procedure Resolve_Set_Membership
;
8327 -- Analysis has determined a unique type for the left operand. Use it to
8328 -- resolve the disjuncts.
8330 ----------------------------
8331 -- Resolve_Set_Membership --
8332 ----------------------------
8334 procedure Resolve_Set_Membership
is
8336 Ltyp
: constant Entity_Id
:= Etype
(L
);
8341 Alt
:= First
(Alternatives
(N
));
8342 while Present
(Alt
) loop
8344 -- Alternative is an expression, a range
8345 -- or a subtype mark.
8347 if not Is_Entity_Name
(Alt
)
8348 or else not Is_Type
(Entity
(Alt
))
8350 Resolve
(Alt
, Ltyp
);
8356 -- Check for duplicates for discrete case
8358 if Is_Discrete_Type
(Ltyp
) then
8365 Alts
: array (0 .. List_Length
(Alternatives
(N
))) of Ent
;
8369 -- Loop checking duplicates. This is quadratic, but giant sets
8370 -- are unlikely in this context so it's a reasonable choice.
8373 Alt
:= First
(Alternatives
(N
));
8374 while Present
(Alt
) loop
8375 if Is_OK_Static_Expression
(Alt
)
8376 and then (Nkind_In
(Alt
, N_Integer_Literal
,
8377 N_Character_Literal
)
8378 or else Nkind
(Alt
) in N_Has_Entity
)
8381 Alts
(Nalts
) := (Alt
, Expr_Value
(Alt
));
8383 for J
in 1 .. Nalts
- 1 loop
8384 if Alts
(J
).Val
= Alts
(Nalts
).Val
then
8385 Error_Msg_Sloc
:= Sloc
(Alts
(J
).Alt
);
8386 Error_Msg_N
("duplicate of value given#??", Alt
);
8395 end Resolve_Set_Membership
;
8397 -- Start of processing for Resolve_Membership_Op
8400 if L
= Error
or else R
= Error
then
8404 if Present
(Alternatives
(N
)) then
8405 Resolve_Set_Membership
;
8408 elsif not Is_Overloaded
(R
)
8410 (Etype
(R
) = Universal_Integer
8412 Etype
(R
) = Universal_Real
)
8413 and then Is_Overloaded
(L
)
8417 -- Ada 2005 (AI-251): Support the following case:
8419 -- type I is interface;
8420 -- type T is tagged ...
8422 -- function Test (O : I'Class) is
8424 -- return O in T'Class.
8427 -- In this case we have nothing else to do. The membership test will be
8428 -- done at run time.
8430 elsif Ada_Version
>= Ada_2005
8431 and then Is_Class_Wide_Type
(Etype
(L
))
8432 and then Is_Interface
(Etype
(L
))
8433 and then Is_Class_Wide_Type
(Etype
(R
))
8434 and then not Is_Interface
(Etype
(R
))
8438 T
:= Intersect_Types
(L
, R
);
8441 -- If mixed-mode operations are present and operands are all literal,
8442 -- the only interpretation involves Duration, which is probably not
8443 -- the intention of the programmer.
8445 if T
= Any_Fixed
then
8446 T
:= Unique_Fixed_Point_Type
(N
);
8448 if T
= Any_Type
then
8454 Check_Unset_Reference
(L
);
8456 if Nkind
(R
) = N_Range
8457 and then not Is_Scalar_Type
(T
)
8459 Error_Msg_N
("scalar type required for range", R
);
8462 if Is_Entity_Name
(R
) then
8463 Freeze_Expression
(R
);
8466 Check_Unset_Reference
(R
);
8469 -- Here after resolving membership operation
8473 Eval_Membership_Op
(N
);
8474 Check_Function_Writable_Actuals
(N
);
8475 end Resolve_Membership_Op
;
8481 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
8482 Loc
: constant Source_Ptr
:= Sloc
(N
);
8485 -- Handle restriction against anonymous null access values This
8486 -- restriction can be turned off using -gnatdj.
8488 -- Ada 2005 (AI-231): Remove restriction
8490 if Ada_Version
< Ada_2005
8491 and then not Debug_Flag_J
8492 and then Ekind
(Typ
) = E_Anonymous_Access_Type
8493 and then Comes_From_Source
(N
)
8495 -- In the common case of a call which uses an explicitly null value
8496 -- for an access parameter, give specialized error message.
8498 if Nkind
(Parent
(N
)) in N_Subprogram_Call
then
8500 ("null is not allowed as argument for an access parameter", N
);
8502 -- Standard message for all other cases (are there any?)
8506 ("null cannot be of an anonymous access type", N
);
8510 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
8511 -- assignment to a null-excluding object
8513 if Ada_Version
>= Ada_2005
8514 and then Can_Never_Be_Null
(Typ
)
8515 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
8517 if not Inside_Init_Proc
then
8519 (Compile_Time_Constraint_Error
(N
,
8520 "(Ada 2005) null not allowed in null-excluding objects??"),
8521 Make_Raise_Constraint_Error
(Loc
,
8522 Reason
=> CE_Access_Check_Failed
));
8525 Make_Raise_Constraint_Error
(Loc
,
8526 Reason
=> CE_Access_Check_Failed
));
8530 -- In a distributed context, null for a remote access to subprogram may
8531 -- need to be replaced with a special record aggregate. In this case,
8532 -- return after having done the transformation.
8534 if (Ekind
(Typ
) = E_Record_Type
8535 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
8536 and then Remote_AST_Null_Value
(N
, Typ
)
8541 -- The null literal takes its type from the context
8546 -----------------------
8547 -- Resolve_Op_Concat --
8548 -----------------------
8550 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
8552 -- We wish to avoid deep recursion, because concatenations are often
8553 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
8554 -- operands nonrecursively until we find something that is not a simple
8555 -- concatenation (A in this case). We resolve that, and then walk back
8556 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
8557 -- to do the rest of the work at each level. The Parent pointers allow
8558 -- us to avoid recursion, and thus avoid running out of memory. See also
8559 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
8565 -- The following code is equivalent to:
8567 -- Resolve_Op_Concat_First (NN, Typ);
8568 -- Resolve_Op_Concat_Arg (N, ...);
8569 -- Resolve_Op_Concat_Rest (N, Typ);
8571 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
8572 -- operand is a concatenation.
8574 -- Walk down left operands
8577 Resolve_Op_Concat_First
(NN
, Typ
);
8578 Op1
:= Left_Opnd
(NN
);
8579 exit when not (Nkind
(Op1
) = N_Op_Concat
8580 and then not Is_Array_Type
(Component_Type
(Typ
))
8581 and then Entity
(Op1
) = Entity
(NN
));
8585 -- Now (given the above example) NN is A&B and Op1 is A
8587 -- First resolve Op1 ...
8589 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
8591 -- ... then walk NN back up until we reach N (where we started), calling
8592 -- Resolve_Op_Concat_Rest along the way.
8595 Resolve_Op_Concat_Rest
(NN
, Typ
);
8600 if Base_Type
(Etype
(N
)) /= Standard_String
then
8601 Check_SPARK_05_Restriction
8602 ("result of concatenation should have type String", N
);
8604 end Resolve_Op_Concat
;
8606 ---------------------------
8607 -- Resolve_Op_Concat_Arg --
8608 ---------------------------
8610 procedure Resolve_Op_Concat_Arg
8616 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8617 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
8622 or else (not Is_Overloaded
(Arg
)
8623 and then Etype
(Arg
) /= Any_Composite
8624 and then Covers
(Ctyp
, Etype
(Arg
)))
8626 Resolve
(Arg
, Ctyp
);
8628 Resolve
(Arg
, Btyp
);
8631 -- If both Array & Array and Array & Component are visible, there is a
8632 -- potential ambiguity that must be reported.
8634 elsif Has_Compatible_Type
(Arg
, Ctyp
) then
8635 if Nkind
(Arg
) = N_Aggregate
8636 and then Is_Composite_Type
(Ctyp
)
8638 if Is_Private_Type
(Ctyp
) then
8639 Resolve
(Arg
, Btyp
);
8641 -- If the operation is user-defined and not overloaded use its
8642 -- profile. The operation may be a renaming, in which case it has
8643 -- been rewritten, and we want the original profile.
8645 elsif not Is_Overloaded
(N
)
8646 and then Comes_From_Source
(Entity
(Original_Node
(N
)))
8647 and then Ekind
(Entity
(Original_Node
(N
))) = E_Function
8651 (Next_Formal
(First_Formal
(Entity
(Original_Node
(N
))))));
8654 -- Otherwise an aggregate may match both the array type and the
8658 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
8659 Set_Etype
(Arg
, Any_Type
);
8663 if Is_Overloaded
(Arg
)
8664 and then Has_Compatible_Type
(Arg
, Typ
)
8665 and then Etype
(Arg
) /= Any_Type
8673 Get_First_Interp
(Arg
, I
, It
);
8675 Get_Next_Interp
(I
, It
);
8677 -- Special-case the error message when the overloading is
8678 -- caused by a function that yields an array and can be
8679 -- called without parameters.
8681 if It
.Nam
= Func
then
8682 Error_Msg_Sloc
:= Sloc
(Func
);
8683 Error_Msg_N
("ambiguous call to function#", Arg
);
8685 ("\\interpretation as call yields&", Arg
, Typ
);
8687 ("\\interpretation as indexing of call yields&",
8688 Arg
, Component_Type
(Typ
));
8691 Error_Msg_N
("ambiguous operand for concatenation!", Arg
);
8693 Get_First_Interp
(Arg
, I
, It
);
8694 while Present
(It
.Nam
) loop
8695 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
8697 if Base_Type
(It
.Typ
) = Btyp
8699 Base_Type
(It
.Typ
) = Base_Type
(Ctyp
)
8701 Error_Msg_N
-- CODEFIX
8702 ("\\possible interpretation#", Arg
);
8705 Get_Next_Interp
(I
, It
);
8711 Resolve
(Arg
, Component_Type
(Typ
));
8713 if Nkind
(Arg
) = N_String_Literal
then
8714 Set_Etype
(Arg
, Component_Type
(Typ
));
8717 if Arg
= Left_Opnd
(N
) then
8718 Set_Is_Component_Left_Opnd
(N
);
8720 Set_Is_Component_Right_Opnd
(N
);
8725 Resolve
(Arg
, Btyp
);
8728 -- Concatenation is restricted in SPARK: each operand must be either a
8729 -- string literal, the name of a string constant, a static character or
8730 -- string expression, or another concatenation. Arg cannot be a
8731 -- concatenation here as callers of Resolve_Op_Concat_Arg call it
8732 -- separately on each final operand, past concatenation operations.
8734 if Is_Character_Type
(Etype
(Arg
)) then
8735 if not Is_OK_Static_Expression
(Arg
) then
8736 Check_SPARK_05_Restriction
8737 ("character operand for concatenation should be static", Arg
);
8740 elsif Is_String_Type
(Etype
(Arg
)) then
8741 if not (Nkind_In
(Arg
, N_Identifier
, N_Expanded_Name
)
8742 and then Is_Constant_Object
(Entity
(Arg
)))
8743 and then not Is_OK_Static_Expression
(Arg
)
8745 Check_SPARK_05_Restriction
8746 ("string operand for concatenation should be static", Arg
);
8749 -- Do not issue error on an operand that is neither a character nor a
8750 -- string, as the error is issued in Resolve_Op_Concat.
8756 Check_Unset_Reference
(Arg
);
8757 end Resolve_Op_Concat_Arg
;
8759 -----------------------------
8760 -- Resolve_Op_Concat_First --
8761 -----------------------------
8763 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
8764 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8765 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8766 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8769 -- The parser folds an enormous sequence of concatenations of string
8770 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
8771 -- in the right operand. If the expression resolves to a predefined "&"
8772 -- operator, all is well. Otherwise, the parser's folding is wrong, so
8773 -- we give an error. See P_Simple_Expression in Par.Ch4.
8775 if Nkind
(Op2
) = N_String_Literal
8776 and then Is_Folded_In_Parser
(Op2
)
8777 and then Ekind
(Entity
(N
)) = E_Function
8779 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
8780 and then String_Length
(Strval
(Op1
)) = 0);
8781 Error_Msg_N
("too many user-defined concatenations", N
);
8785 Set_Etype
(N
, Btyp
);
8787 if Is_Limited_Composite
(Btyp
) then
8788 Error_Msg_N
("concatenation not available for limited array", N
);
8789 Explain_Limited_Type
(Btyp
, N
);
8791 end Resolve_Op_Concat_First
;
8793 ----------------------------
8794 -- Resolve_Op_Concat_Rest --
8795 ----------------------------
8797 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
8798 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8799 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8802 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
8804 Generate_Operator_Reference
(N
, Typ
);
8806 if Is_String_Type
(Typ
) then
8807 Eval_Concatenation
(N
);
8810 -- If this is not a static concatenation, but the result is a string
8811 -- type (and not an array of strings) ensure that static string operands
8812 -- have their subtypes properly constructed.
8814 if Nkind
(N
) /= N_String_Literal
8815 and then Is_Character_Type
(Component_Type
(Typ
))
8817 Set_String_Literal_Subtype
(Op1
, Typ
);
8818 Set_String_Literal_Subtype
(Op2
, Typ
);
8820 end Resolve_Op_Concat_Rest
;
8822 ----------------------
8823 -- Resolve_Op_Expon --
8824 ----------------------
8826 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
8827 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
8830 -- Catch attempts to do fixed-point exponentiation with universal
8831 -- operands, which is a case where the illegality is not caught during
8832 -- normal operator analysis. This is not done in preanalysis mode
8833 -- since the tree is not fully decorated during preanalysis.
8835 if Full_Analysis
then
8836 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
8837 Error_Msg_N
("exponentiation not available for fixed point", N
);
8840 elsif Nkind
(Parent
(N
)) in N_Op
8841 and then Is_Fixed_Point_Type
(Etype
(Parent
(N
)))
8842 and then Etype
(N
) = Universal_Real
8843 and then Comes_From_Source
(N
)
8845 Error_Msg_N
("exponentiation not available for fixed point", N
);
8850 if Comes_From_Source
(N
)
8851 and then Ekind
(Entity
(N
)) = E_Function
8852 and then Is_Imported
(Entity
(N
))
8853 and then Is_Intrinsic_Subprogram
(Entity
(N
))
8855 Resolve_Intrinsic_Operator
(N
, Typ
);
8859 if Etype
(Left_Opnd
(N
)) = Universal_Integer
8860 or else Etype
(Left_Opnd
(N
)) = Universal_Real
8862 Check_For_Visible_Operator
(N
, B_Typ
);
8865 -- We do the resolution using the base type, because intermediate values
8866 -- in expressions are always of the base type, not a subtype of it.
8868 Resolve
(Left_Opnd
(N
), B_Typ
);
8869 Resolve
(Right_Opnd
(N
), Standard_Integer
);
8871 -- For integer types, right argument must be in Natural range
8873 if Is_Integer_Type
(Typ
) then
8874 Apply_Scalar_Range_Check
(Right_Opnd
(N
), Standard_Natural
);
8877 Check_Unset_Reference
(Left_Opnd
(N
));
8878 Check_Unset_Reference
(Right_Opnd
(N
));
8880 Set_Etype
(N
, B_Typ
);
8881 Generate_Operator_Reference
(N
, B_Typ
);
8883 Analyze_Dimension
(N
);
8885 if Ada_Version
>= Ada_2012
and then Has_Dimension_System
(B_Typ
) then
8886 -- Evaluate the exponentiation operator for dimensioned type
8888 Eval_Op_Expon_For_Dimensioned_Type
(N
, B_Typ
);
8893 -- Set overflow checking bit. Much cleverer code needed here eventually
8894 -- and perhaps the Resolve routines should be separated for the various
8895 -- arithmetic operations, since they will need different processing. ???
8897 if Nkind
(N
) in N_Op
then
8898 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
8899 Enable_Overflow_Check
(N
);
8902 end Resolve_Op_Expon
;
8904 --------------------
8905 -- Resolve_Op_Not --
8906 --------------------
8908 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
8911 function Parent_Is_Boolean
return Boolean;
8912 -- This function determines if the parent node is a boolean operator or
8913 -- operation (comparison op, membership test, or short circuit form) and
8914 -- the not in question is the left operand of this operation. Note that
8915 -- if the not is in parens, then false is returned.
8917 -----------------------
8918 -- Parent_Is_Boolean --
8919 -----------------------
8921 function Parent_Is_Boolean
return Boolean is
8923 if Paren_Count
(N
) /= 0 then
8927 case Nkind
(Parent
(N
)) is
8942 return Left_Opnd
(Parent
(N
)) = N
;
8948 end Parent_Is_Boolean
;
8950 -- Start of processing for Resolve_Op_Not
8953 -- Predefined operations on scalar types yield the base type. On the
8954 -- other hand, logical operations on arrays yield the type of the
8955 -- arguments (and the context).
8957 if Is_Array_Type
(Typ
) then
8960 B_Typ
:= Base_Type
(Typ
);
8963 -- Straightforward case of incorrect arguments
8965 if not Valid_Boolean_Arg
(Typ
) then
8966 Error_Msg_N
("invalid operand type for operator&", N
);
8967 Set_Etype
(N
, Any_Type
);
8970 -- Special case of probable missing parens
8972 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
8973 if Parent_Is_Boolean
then
8975 ("operand of not must be enclosed in parentheses",
8979 ("no modular type available in this context", N
);
8982 Set_Etype
(N
, Any_Type
);
8985 -- OK resolution of NOT
8988 -- Warn if non-boolean types involved. This is a case like not a < b
8989 -- where a and b are modular, where we will get (not a) < b and most
8990 -- likely not (a < b) was intended.
8992 if Warn_On_Questionable_Missing_Parens
8993 and then not Is_Boolean_Type
(Typ
)
8994 and then Parent_Is_Boolean
8996 Error_Msg_N
("?q?not expression should be parenthesized here!", N
);
8999 -- Warn on double negation if checking redundant constructs
9001 if Warn_On_Redundant_Constructs
9002 and then Comes_From_Source
(N
)
9003 and then Comes_From_Source
(Right_Opnd
(N
))
9004 and then Root_Type
(Typ
) = Standard_Boolean
9005 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
9007 Error_Msg_N
("redundant double negation?r?", N
);
9010 -- Complete resolution and evaluation of NOT
9012 Resolve
(Right_Opnd
(N
), B_Typ
);
9013 Check_Unset_Reference
(Right_Opnd
(N
));
9014 Set_Etype
(N
, B_Typ
);
9015 Generate_Operator_Reference
(N
, B_Typ
);
9020 -----------------------------
9021 -- Resolve_Operator_Symbol --
9022 -----------------------------
9024 -- Nothing to be done, all resolved already
9026 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
9027 pragma Warnings
(Off
, N
);
9028 pragma Warnings
(Off
, Typ
);
9032 end Resolve_Operator_Symbol
;
9034 ----------------------------------
9035 -- Resolve_Qualified_Expression --
9036 ----------------------------------
9038 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9039 pragma Warnings
(Off
, Typ
);
9041 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
9042 Expr
: constant Node_Id
:= Expression
(N
);
9045 Resolve
(Expr
, Target_Typ
);
9047 -- Protect call to Matching_Static_Array_Bounds to avoid costly
9048 -- operation if not needed.
9050 if Restriction_Check_Required
(SPARK_05
)
9051 and then Is_Array_Type
(Target_Typ
)
9052 and then Is_Array_Type
(Etype
(Expr
))
9053 and then Etype
(Expr
) /= Any_Composite
-- or else Expr in error
9054 and then not Matching_Static_Array_Bounds
(Target_Typ
, Etype
(Expr
))
9056 Check_SPARK_05_Restriction
9057 ("array types should have matching static bounds", N
);
9060 -- A qualified expression requires an exact match of the type, class-
9061 -- wide matching is not allowed. However, if the qualifying type is
9062 -- specific and the expression has a class-wide type, it may still be
9063 -- okay, since it can be the result of the expansion of a call to a
9064 -- dispatching function, so we also have to check class-wideness of the
9065 -- type of the expression's original node.
9067 if (Is_Class_Wide_Type
(Target_Typ
)
9069 (Is_Class_Wide_Type
(Etype
(Expr
))
9070 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
9071 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
9073 Wrong_Type
(Expr
, Target_Typ
);
9076 -- If the target type is unconstrained, then we reset the type of the
9077 -- result from the type of the expression. For other cases, the actual
9078 -- subtype of the expression is the target type.
9080 if Is_Composite_Type
(Target_Typ
)
9081 and then not Is_Constrained
(Target_Typ
)
9083 Set_Etype
(N
, Etype
(Expr
));
9086 Analyze_Dimension
(N
);
9087 Eval_Qualified_Expression
(N
);
9089 -- If we still have a qualified expression after the static evaluation,
9090 -- then apply a scalar range check if needed. The reason that we do this
9091 -- after the Eval call is that otherwise, the application of the range
9092 -- check may convert an illegal static expression and result in warning
9093 -- rather than giving an error (e.g Integer'(Integer'Last + 1)).
9095 if Nkind
(N
) = N_Qualified_Expression
and then Is_Scalar_Type
(Typ
) then
9096 Apply_Scalar_Range_Check
(Expr
, Typ
);
9098 end Resolve_Qualified_Expression
;
9100 ------------------------------
9101 -- Resolve_Raise_Expression --
9102 ------------------------------
9104 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9106 if Typ
= Raise_Type
then
9107 Error_Msg_N
("cannot find unique type for raise expression", N
);
9108 Set_Etype
(N
, Any_Type
);
9112 end Resolve_Raise_Expression
;
9118 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
9119 L
: constant Node_Id
:= Low_Bound
(N
);
9120 H
: constant Node_Id
:= High_Bound
(N
);
9122 function First_Last_Ref
return Boolean;
9123 -- Returns True if N is of the form X'First .. X'Last where X is the
9124 -- same entity for both attributes.
9126 --------------------
9127 -- First_Last_Ref --
9128 --------------------
9130 function First_Last_Ref
return Boolean is
9131 Lorig
: constant Node_Id
:= Original_Node
(L
);
9132 Horig
: constant Node_Id
:= Original_Node
(H
);
9135 if Nkind
(Lorig
) = N_Attribute_Reference
9136 and then Nkind
(Horig
) = N_Attribute_Reference
9137 and then Attribute_Name
(Lorig
) = Name_First
9138 and then Attribute_Name
(Horig
) = Name_Last
9141 PL
: constant Node_Id
:= Prefix
(Lorig
);
9142 PH
: constant Node_Id
:= Prefix
(Horig
);
9144 if Is_Entity_Name
(PL
)
9145 and then Is_Entity_Name
(PH
)
9146 and then Entity
(PL
) = Entity
(PH
)
9156 -- Start of processing for Resolve_Range
9163 -- Check for inappropriate range on unordered enumeration type
9165 if Bad_Unordered_Enumeration_Reference
(N
, Typ
)
9167 -- Exclude X'First .. X'Last if X is the same entity for both
9169 and then not First_Last_Ref
9171 Error_Msg_Sloc
:= Sloc
(Typ
);
9173 ("subrange of unordered enumeration type& declared#?U?", N
, Typ
);
9176 Check_Unset_Reference
(L
);
9177 Check_Unset_Reference
(H
);
9179 -- We have to check the bounds for being within the base range as
9180 -- required for a non-static context. Normally this is automatic and
9181 -- done as part of evaluating expressions, but the N_Range node is an
9182 -- exception, since in GNAT we consider this node to be a subexpression,
9183 -- even though in Ada it is not. The circuit in Sem_Eval could check for
9184 -- this, but that would put the test on the main evaluation path for
9187 Check_Non_Static_Context
(L
);
9188 Check_Non_Static_Context
(H
);
9190 -- Check for an ambiguous range over character literals. This will
9191 -- happen with a membership test involving only literals.
9193 if Typ
= Any_Character
then
9194 Ambiguous_Character
(L
);
9195 Set_Etype
(N
, Any_Type
);
9199 -- If bounds are static, constant-fold them, so size computations are
9200 -- identical between front-end and back-end. Do not perform this
9201 -- transformation while analyzing generic units, as type information
9202 -- would be lost when reanalyzing the constant node in the instance.
9204 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
9205 if Is_OK_Static_Expression
(L
) then
9206 Fold_Uint
(L
, Expr_Value
(L
), Is_OK_Static_Expression
(L
));
9209 if Is_OK_Static_Expression
(H
) then
9210 Fold_Uint
(H
, Expr_Value
(H
), Is_OK_Static_Expression
(H
));
9215 --------------------------
9216 -- Resolve_Real_Literal --
9217 --------------------------
9219 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9220 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
9223 -- Special processing for fixed-point literals to make sure that the
9224 -- value is an exact multiple of small where this is required. We skip
9225 -- this for the universal real case, and also for generic types.
9227 if Is_Fixed_Point_Type
(Typ
)
9228 and then Typ
/= Universal_Fixed
9229 and then Typ
/= Any_Fixed
9230 and then not Is_Generic_Type
(Typ
)
9233 Val
: constant Ureal
:= Realval
(N
);
9234 Cintr
: constant Ureal
:= Val
/ Small_Value
(Typ
);
9235 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
9236 Den
: constant Uint
:= Norm_Den
(Cintr
);
9240 -- Case of literal is not an exact multiple of the Small
9244 -- For a source program literal for a decimal fixed-point type,
9245 -- this is statically illegal (RM 4.9(36)).
9247 if Is_Decimal_Fixed_Point_Type
(Typ
)
9248 and then Actual_Typ
= Universal_Real
9249 and then Comes_From_Source
(N
)
9251 Error_Msg_N
("value has extraneous low order digits", N
);
9254 -- Generate a warning if literal from source
9256 if Is_OK_Static_Expression
(N
)
9257 and then Warn_On_Bad_Fixed_Value
9260 ("?b?static fixed-point value is not a multiple of Small!",
9264 -- Replace literal by a value that is the exact representation
9265 -- of a value of the type, i.e. a multiple of the small value,
9266 -- by truncation, since Machine_Rounds is false for all GNAT
9267 -- fixed-point types (RM 4.9(38)).
9269 Stat
:= Is_OK_Static_Expression
(N
);
9271 Make_Real_Literal
(Sloc
(N
),
9272 Realval
=> Small_Value
(Typ
) * Cint
));
9274 Set_Is_Static_Expression
(N
, Stat
);
9277 -- In all cases, set the corresponding integer field
9279 Set_Corresponding_Integer_Value
(N
, Cint
);
9283 -- Now replace the actual type by the expected type as usual
9286 Eval_Real_Literal
(N
);
9287 end Resolve_Real_Literal
;
9289 -----------------------
9290 -- Resolve_Reference --
9291 -----------------------
9293 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
9294 P
: constant Node_Id
:= Prefix
(N
);
9297 -- Replace general access with specific type
9299 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
9300 Set_Etype
(N
, Base_Type
(Typ
));
9303 Resolve
(P
, Designated_Type
(Etype
(N
)));
9305 -- If we are taking the reference of a volatile entity, then treat it as
9306 -- a potential modification of this entity. This is too conservative,
9307 -- but necessary because remove side effects can cause transformations
9308 -- of normal assignments into reference sequences that otherwise fail to
9309 -- notice the modification.
9311 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
9312 Note_Possible_Modification
(P
, Sure
=> False);
9314 end Resolve_Reference
;
9316 --------------------------------
9317 -- Resolve_Selected_Component --
9318 --------------------------------
9320 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
9322 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
9323 P
: constant Node_Id
:= Prefix
(N
);
9324 S
: constant Node_Id
:= Selector_Name
(N
);
9325 T
: Entity_Id
:= Etype
(P
);
9327 I1
: Interp_Index
:= 0; -- prevent junk warning
9332 function Init_Component
return Boolean;
9333 -- Check whether this is the initialization of a component within an
9334 -- init proc (by assignment or call to another init proc). If true,
9335 -- there is no need for a discriminant check.
9337 --------------------
9338 -- Init_Component --
9339 --------------------
9341 function Init_Component
return Boolean is
9343 return Inside_Init_Proc
9344 and then Nkind
(Prefix
(N
)) = N_Identifier
9345 and then Chars
(Prefix
(N
)) = Name_uInit
9346 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
9349 -- Start of processing for Resolve_Selected_Component
9352 if Is_Overloaded
(P
) then
9354 -- Use the context type to select the prefix that has a selector
9355 -- of the correct name and type.
9358 Get_First_Interp
(P
, I
, It
);
9360 Search
: while Present
(It
.Typ
) loop
9361 if Is_Access_Type
(It
.Typ
) then
9362 T
:= Designated_Type
(It
.Typ
);
9367 -- Locate selected component. For a private prefix the selector
9368 -- can denote a discriminant.
9370 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
9372 -- The visible components of a class-wide type are those of
9375 if Is_Class_Wide_Type
(T
) then
9379 Comp
:= First_Entity
(T
);
9380 while Present
(Comp
) loop
9381 if Chars
(Comp
) = Chars
(S
)
9382 and then Covers
(Typ
, Etype
(Comp
))
9391 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9393 if It
= No_Interp
then
9395 ("ambiguous prefix for selected component", N
);
9402 -- There may be an implicit dereference. Retrieve
9403 -- designated record type.
9405 if Is_Access_Type
(It1
.Typ
) then
9406 T
:= Designated_Type
(It1
.Typ
);
9411 if Scope
(Comp1
) /= T
then
9413 -- Resolution chooses the new interpretation.
9414 -- Find the component with the right name.
9416 Comp1
:= First_Entity
(T
);
9417 while Present
(Comp1
)
9418 and then Chars
(Comp1
) /= Chars
(S
)
9420 Comp1
:= Next_Entity
(Comp1
);
9429 Comp
:= Next_Entity
(Comp
);
9433 Get_Next_Interp
(I
, It
);
9436 -- There must be a legal interpretation at this point
9438 pragma Assert
(Found
);
9439 Resolve
(P
, It1
.Typ
);
9441 Set_Entity_With_Checks
(S
, Comp1
);
9444 -- Resolve prefix with its type
9449 -- Generate cross-reference. We needed to wait until full overloading
9450 -- resolution was complete to do this, since otherwise we can't tell if
9451 -- we are an lvalue or not.
9453 if May_Be_Lvalue
(N
) then
9454 Generate_Reference
(Entity
(S
), S
, 'm');
9456 Generate_Reference
(Entity
(S
), S
, 'r');
9459 -- If prefix is an access type, the node will be transformed into an
9460 -- explicit dereference during expansion. The type of the node is the
9461 -- designated type of that of the prefix.
9463 if Is_Access_Type
(Etype
(P
)) then
9464 T
:= Designated_Type
(Etype
(P
));
9465 Check_Fully_Declared_Prefix
(T
, P
);
9470 -- Set flag for expander if discriminant check required
9472 if Has_Discriminants
(T
)
9473 and then Ekind_In
(Entity
(S
), E_Component
, E_Discriminant
)
9474 and then Present
(Original_Record_Component
(Entity
(S
)))
9475 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
9476 and then not Discriminant_Checks_Suppressed
(T
)
9477 and then not Init_Component
9479 Set_Do_Discriminant_Check
(N
);
9482 if Ekind
(Entity
(S
)) = E_Void
then
9483 Error_Msg_N
("premature use of component", S
);
9486 -- If the prefix is a record conversion, this may be a renamed
9487 -- discriminant whose bounds differ from those of the original
9488 -- one, so we must ensure that a range check is performed.
9490 if Nkind
(P
) = N_Type_Conversion
9491 and then Ekind
(Entity
(S
)) = E_Discriminant
9492 and then Is_Discrete_Type
(Typ
)
9494 Set_Etype
(N
, Base_Type
(Typ
));
9497 -- Note: No Eval processing is required, because the prefix is of a
9498 -- record type, or protected type, and neither can possibly be static.
9500 -- If the record type is atomic, and the component is non-atomic, then
9501 -- this is worth a warning, since we have a situation where the access
9502 -- to the component may cause extra read/writes of the atomic array
9503 -- object, or partial word accesses, both of which may be unexpected.
9505 if Nkind
(N
) = N_Selected_Component
9506 and then Is_Atomic_Ref_With_Address
(N
)
9507 and then not Is_Atomic
(Entity
(S
))
9508 and then not Is_Atomic
(Etype
(Entity
(S
)))
9511 ("??access to non-atomic component of atomic record",
9514 ("\??may cause unexpected accesses to atomic object",
9518 Analyze_Dimension
(N
);
9519 end Resolve_Selected_Component
;
9525 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
9526 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9527 L
: constant Node_Id
:= Left_Opnd
(N
);
9528 R
: constant Node_Id
:= Right_Opnd
(N
);
9531 -- We do the resolution using the base type, because intermediate values
9532 -- in expressions always are of the base type, not a subtype of it.
9535 Resolve
(R
, Standard_Natural
);
9537 Check_Unset_Reference
(L
);
9538 Check_Unset_Reference
(R
);
9540 Set_Etype
(N
, B_Typ
);
9541 Generate_Operator_Reference
(N
, B_Typ
);
9545 ---------------------------
9546 -- Resolve_Short_Circuit --
9547 ---------------------------
9549 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
9550 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9551 L
: constant Node_Id
:= Left_Opnd
(N
);
9552 R
: constant Node_Id
:= Right_Opnd
(N
);
9555 -- Ensure all actions associated with the left operand (e.g.
9556 -- finalization of transient controlled objects) are fully evaluated
9557 -- locally within an expression with actions. This is particularly
9558 -- helpful for coverage analysis. However this should not happen in
9561 if Expander_Active
then
9563 Reloc_L
: constant Node_Id
:= Relocate_Node
(L
);
9565 Save_Interps
(Old_N
=> L
, New_N
=> Reloc_L
);
9568 Make_Expression_With_Actions
(Sloc
(L
),
9569 Actions
=> New_List
,
9570 Expression
=> Reloc_L
));
9572 -- Set Comes_From_Source on L to preserve warnings for unset
9575 Set_Comes_From_Source
(L
, Comes_From_Source
(Reloc_L
));
9582 -- Check for issuing warning for always False assert/check, this happens
9583 -- when assertions are turned off, in which case the pragma Assert/Check
9584 -- was transformed into:
9586 -- if False and then <condition> then ...
9588 -- and we detect this pattern
9590 if Warn_On_Assertion_Failure
9591 and then Is_Entity_Name
(R
)
9592 and then Entity
(R
) = Standard_False
9593 and then Nkind
(Parent
(N
)) = N_If_Statement
9594 and then Nkind
(N
) = N_And_Then
9595 and then Is_Entity_Name
(L
)
9596 and then Entity
(L
) = Standard_False
9599 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
9602 -- Special handling of Asssert pragma
9604 if Nkind
(Orig
) = N_Pragma
9605 and then Pragma_Name
(Orig
) = Name_Assert
9608 Expr
: constant Node_Id
:=
9611 (First
(Pragma_Argument_Associations
(Orig
))));
9614 -- Don't warn if original condition is explicit False,
9615 -- since obviously the failure is expected in this case.
9617 if Is_Entity_Name
(Expr
)
9618 and then Entity
(Expr
) = Standard_False
9622 -- Issue warning. We do not want the deletion of the
9623 -- IF/AND-THEN to take this message with it. We achieve this
9624 -- by making sure that the expanded code points to the Sloc
9625 -- of the expression, not the original pragma.
9628 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
9629 -- The source location of the expression is not usually
9630 -- the best choice here. For example, it gets located on
9631 -- the last AND keyword in a chain of boolean expressiond
9632 -- AND'ed together. It is best to put the message on the
9633 -- first character of the assertion, which is the effect
9634 -- of the First_Node call here.
9637 ("?A?assertion would fail at run time!",
9639 (First
(Pragma_Argument_Associations
(Orig
))));
9643 -- Similar processing for Check pragma
9645 elsif Nkind
(Orig
) = N_Pragma
9646 and then Pragma_Name
(Orig
) = Name_Check
9648 -- Don't want to warn if original condition is explicit False
9651 Expr
: constant Node_Id
:=
9654 (Next
(First
(Pragma_Argument_Associations
(Orig
)))));
9656 if Is_Entity_Name
(Expr
)
9657 and then Entity
(Expr
) = Standard_False
9664 -- Again use Error_Msg_F rather than Error_Msg_N, see
9665 -- comment above for an explanation of why we do this.
9668 ("?A?check would fail at run time!",
9670 (Last
(Pragma_Argument_Associations
(Orig
))));
9677 -- Continue with processing of short circuit
9679 Check_Unset_Reference
(L
);
9680 Check_Unset_Reference
(R
);
9682 Set_Etype
(N
, B_Typ
);
9683 Eval_Short_Circuit
(N
);
9684 end Resolve_Short_Circuit
;
9690 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
9691 Drange
: constant Node_Id
:= Discrete_Range
(N
);
9692 Name
: constant Node_Id
:= Prefix
(N
);
9693 Array_Type
: Entity_Id
:= Empty
;
9694 Dexpr
: Node_Id
:= Empty
;
9695 Index_Type
: Entity_Id
;
9698 if Is_Overloaded
(Name
) then
9700 -- Use the context type to select the prefix that yields the correct
9705 I1
: Interp_Index
:= 0;
9707 P
: constant Node_Id
:= Prefix
(N
);
9708 Found
: Boolean := False;
9711 Get_First_Interp
(P
, I
, It
);
9712 while Present
(It
.Typ
) loop
9713 if (Is_Array_Type
(It
.Typ
)
9714 and then Covers
(Typ
, It
.Typ
))
9715 or else (Is_Access_Type
(It
.Typ
)
9716 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
9717 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
9720 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9722 if It
= No_Interp
then
9723 Error_Msg_N
("ambiguous prefix for slicing", N
);
9728 Array_Type
:= It
.Typ
;
9733 Array_Type
:= It
.Typ
;
9738 Get_Next_Interp
(I
, It
);
9743 Array_Type
:= Etype
(Name
);
9746 Resolve
(Name
, Array_Type
);
9748 if Is_Access_Type
(Array_Type
) then
9749 Apply_Access_Check
(N
);
9750 Array_Type
:= Designated_Type
(Array_Type
);
9752 -- If the prefix is an access to an unconstrained array, we must use
9753 -- the actual subtype of the object to perform the index checks. The
9754 -- object denoted by the prefix is implicit in the node, so we build
9755 -- an explicit representation for it in order to compute the actual
9758 if not Is_Constrained
(Array_Type
) then
9759 Remove_Side_Effects
(Prefix
(N
));
9762 Obj
: constant Node_Id
:=
9763 Make_Explicit_Dereference
(Sloc
(N
),
9764 Prefix
=> New_Copy_Tree
(Prefix
(N
)));
9766 Set_Etype
(Obj
, Array_Type
);
9767 Set_Parent
(Obj
, Parent
(N
));
9768 Array_Type
:= Get_Actual_Subtype
(Obj
);
9772 elsif Is_Entity_Name
(Name
)
9773 or else Nkind
(Name
) = N_Explicit_Dereference
9774 or else (Nkind
(Name
) = N_Function_Call
9775 and then not Is_Constrained
(Etype
(Name
)))
9777 Array_Type
:= Get_Actual_Subtype
(Name
);
9779 -- If the name is a selected component that depends on discriminants,
9780 -- build an actual subtype for it. This can happen only when the name
9781 -- itself is overloaded; otherwise the actual subtype is created when
9782 -- the selected component is analyzed.
9784 elsif Nkind
(Name
) = N_Selected_Component
9785 and then Full_Analysis
9786 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
9789 Act_Decl
: constant Node_Id
:=
9790 Build_Actual_Subtype_Of_Component
(Array_Type
, Name
);
9792 Insert_Action
(N
, Act_Decl
);
9793 Array_Type
:= Defining_Identifier
(Act_Decl
);
9796 -- Maybe this should just be "else", instead of checking for the
9797 -- specific case of slice??? This is needed for the case where the
9798 -- prefix is an Image attribute, which gets expanded to a slice, and so
9799 -- has a constrained subtype which we want to use for the slice range
9800 -- check applied below (the range check won't get done if the
9801 -- unconstrained subtype of the 'Image is used).
9803 elsif Nkind
(Name
) = N_Slice
then
9804 Array_Type
:= Etype
(Name
);
9807 -- Obtain the type of the array index
9809 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
9810 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
9812 Index_Type
:= Etype
(First_Index
(Array_Type
));
9815 -- If name was overloaded, set slice type correctly now
9817 Set_Etype
(N
, Array_Type
);
9819 -- Handle the generation of a range check that compares the array index
9820 -- against the discrete_range. The check is not applied to internally
9821 -- built nodes associated with the expansion of dispatch tables. Check
9822 -- that Ada.Tags has already been loaded to avoid extra dependencies on
9825 if Tagged_Type_Expansion
9826 and then RTU_Loaded
(Ada_Tags
)
9827 and then Nkind
(Prefix
(N
)) = N_Selected_Component
9828 and then Present
(Entity
(Selector_Name
(Prefix
(N
))))
9829 and then Entity
(Selector_Name
(Prefix
(N
))) =
9830 RTE_Record_Component
(RE_Prims_Ptr
)
9834 -- The discrete_range is specified by a subtype indication. Create a
9835 -- shallow copy and inherit the type, parent and source location from
9836 -- the discrete_range. This ensures that the range check is inserted
9837 -- relative to the slice and that the runtime exception points to the
9838 -- proper construct.
9840 elsif Is_Entity_Name
(Drange
) then
9841 Dexpr
:= New_Copy
(Scalar_Range
(Entity
(Drange
)));
9843 Set_Etype
(Dexpr
, Etype
(Drange
));
9844 Set_Parent
(Dexpr
, Parent
(Drange
));
9845 Set_Sloc
(Dexpr
, Sloc
(Drange
));
9847 -- The discrete_range is a regular range. Resolve the bounds and remove
9848 -- their side effects.
9851 Resolve
(Drange
, Base_Type
(Index_Type
));
9853 if Nkind
(Drange
) = N_Range
then
9854 Force_Evaluation
(Low_Bound
(Drange
));
9855 Force_Evaluation
(High_Bound
(Drange
));
9861 if Present
(Dexpr
) then
9862 Apply_Range_Check
(Dexpr
, Index_Type
);
9865 Set_Slice_Subtype
(N
);
9867 -- Check bad use of type with predicates
9873 if Nkind
(Drange
) = N_Subtype_Indication
9874 and then Has_Predicates
(Entity
(Subtype_Mark
(Drange
)))
9876 Subt
:= Entity
(Subtype_Mark
(Drange
));
9878 Subt
:= Etype
(Drange
);
9881 if Has_Predicates
(Subt
) then
9882 Bad_Predicated_Subtype_Use
9883 ("subtype& has predicate, not allowed in slice", Drange
, Subt
);
9887 -- Otherwise here is where we check suspicious indexes
9889 if Nkind
(Drange
) = N_Range
then
9890 Warn_On_Suspicious_Index
(Name
, Low_Bound
(Drange
));
9891 Warn_On_Suspicious_Index
(Name
, High_Bound
(Drange
));
9894 Analyze_Dimension
(N
);
9898 ----------------------------
9899 -- Resolve_String_Literal --
9900 ----------------------------
9902 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9903 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
9904 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
9905 Loc
: constant Source_Ptr
:= Sloc
(N
);
9906 Str
: constant String_Id
:= Strval
(N
);
9907 Strlen
: constant Nat
:= String_Length
(Str
);
9908 Subtype_Id
: Entity_Id
;
9909 Need_Check
: Boolean;
9912 -- For a string appearing in a concatenation, defer creation of the
9913 -- string_literal_subtype until the end of the resolution of the
9914 -- concatenation, because the literal may be constant-folded away. This
9915 -- is a useful optimization for long concatenation expressions.
9917 -- If the string is an aggregate built for a single character (which
9918 -- happens in a non-static context) or a is null string to which special
9919 -- checks may apply, we build the subtype. Wide strings must also get a
9920 -- string subtype if they come from a one character aggregate. Strings
9921 -- generated by attributes might be static, but it is often hard to
9922 -- determine whether the enclosing context is static, so we generate
9923 -- subtypes for them as well, thus losing some rarer optimizations ???
9924 -- Same for strings that come from a static conversion.
9927 (Strlen
= 0 and then Typ
/= Standard_String
)
9928 or else Nkind
(Parent
(N
)) /= N_Op_Concat
9929 or else (N
/= Left_Opnd
(Parent
(N
))
9930 and then N
/= Right_Opnd
(Parent
(N
)))
9931 or else ((Typ
= Standard_Wide_String
9932 or else Typ
= Standard_Wide_Wide_String
)
9933 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
9935 -- If the resolving type is itself a string literal subtype, we can just
9936 -- reuse it, since there is no point in creating another.
9938 if Ekind
(Typ
) = E_String_Literal_Subtype
then
9941 elsif Nkind
(Parent
(N
)) = N_Op_Concat
9942 and then not Need_Check
9943 and then not Nkind_In
(Original_Node
(N
), N_Character_Literal
,
9944 N_Attribute_Reference
,
9945 N_Qualified_Expression
,
9950 -- Otherwise we must create a string literal subtype. Note that the
9951 -- whole idea of string literal subtypes is simply to avoid the need
9952 -- for building a full fledged array subtype for each literal.
9955 Set_String_Literal_Subtype
(N
, Typ
);
9956 Subtype_Id
:= Etype
(N
);
9959 if Nkind
(Parent
(N
)) /= N_Op_Concat
9962 Set_Etype
(N
, Subtype_Id
);
9963 Eval_String_Literal
(N
);
9966 if Is_Limited_Composite
(Typ
)
9967 or else Is_Private_Composite
(Typ
)
9969 Error_Msg_N
("string literal not available for private array", N
);
9970 Set_Etype
(N
, Any_Type
);
9974 -- The validity of a null string has been checked in the call to
9975 -- Eval_String_Literal.
9980 -- Always accept string literal with component type Any_Character, which
9981 -- occurs in error situations and in comparisons of literals, both of
9982 -- which should accept all literals.
9984 elsif R_Typ
= Any_Character
then
9987 -- If the type is bit-packed, then we always transform the string
9988 -- literal into a full fledged aggregate.
9990 elsif Is_Bit_Packed_Array
(Typ
) then
9993 -- Deal with cases of Wide_Wide_String, Wide_String, and String
9996 -- For Standard.Wide_Wide_String, or any other type whose component
9997 -- type is Standard.Wide_Wide_Character, we know that all the
9998 -- characters in the string must be acceptable, since the parser
9999 -- accepted the characters as valid character literals.
10001 if R_Typ
= Standard_Wide_Wide_Character
then
10004 -- For the case of Standard.String, or any other type whose component
10005 -- type is Standard.Character, we must make sure that there are no
10006 -- wide characters in the string, i.e. that it is entirely composed
10007 -- of characters in range of type Character.
10009 -- If the string literal is the result of a static concatenation, the
10010 -- test has already been performed on the components, and need not be
10013 elsif R_Typ
= Standard_Character
10014 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
10016 for J
in 1 .. Strlen
loop
10017 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
10019 -- If we are out of range, post error. This is one of the
10020 -- very few places that we place the flag in the middle of
10021 -- a token, right under the offending wide character. Not
10022 -- quite clear if this is right wrt wide character encoding
10023 -- sequences, but it's only an error message.
10026 ("literal out of range of type Standard.Character",
10027 Source_Ptr
(Int
(Loc
) + J
));
10032 -- For the case of Standard.Wide_String, or any other type whose
10033 -- component type is Standard.Wide_Character, we must make sure that
10034 -- there are no wide characters in the string, i.e. that it is
10035 -- entirely composed of characters in range of type Wide_Character.
10037 -- If the string literal is the result of a static concatenation,
10038 -- the test has already been performed on the components, and need
10039 -- not be repeated.
10041 elsif R_Typ
= Standard_Wide_Character
10042 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
10044 for J
in 1 .. Strlen
loop
10045 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
10047 -- If we are out of range, post error. This is one of the
10048 -- very few places that we place the flag in the middle of
10049 -- a token, right under the offending wide character.
10051 -- This is not quite right, because characters in general
10052 -- will take more than one character position ???
10055 ("literal out of range of type Standard.Wide_Character",
10056 Source_Ptr
(Int
(Loc
) + J
));
10061 -- If the root type is not a standard character, then we will convert
10062 -- the string into an aggregate and will let the aggregate code do
10063 -- the checking. Standard Wide_Wide_Character is also OK here.
10069 -- See if the component type of the array corresponding to the string
10070 -- has compile time known bounds. If yes we can directly check
10071 -- whether the evaluation of the string will raise constraint error.
10072 -- Otherwise we need to transform the string literal into the
10073 -- corresponding character aggregate and let the aggregate code do
10076 if Is_Standard_Character_Type
(R_Typ
) then
10078 -- Check for the case of full range, where we are definitely OK
10080 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
10084 -- Here the range is not the complete base type range, so check
10087 Comp_Typ_Lo
: constant Node_Id
:=
10088 Type_Low_Bound
(Component_Type
(Typ
));
10089 Comp_Typ_Hi
: constant Node_Id
:=
10090 Type_High_Bound
(Component_Type
(Typ
));
10095 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
10096 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
10098 for J
in 1 .. Strlen
loop
10099 Char_Val
:= UI_From_Int
(Int
(Get_String_Char
(Str
, J
)));
10101 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
10102 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
10104 Apply_Compile_Time_Constraint_Error
10105 (N
, "character out of range??",
10106 CE_Range_Check_Failed
,
10107 Loc
=> Source_Ptr
(Int
(Loc
) + J
));
10117 -- If we got here we meed to transform the string literal into the
10118 -- equivalent qualified positional array aggregate. This is rather
10119 -- heavy artillery for this situation, but it is hard work to avoid.
10122 Lits
: constant List_Id
:= New_List
;
10123 P
: Source_Ptr
:= Loc
+ 1;
10127 -- Build the character literals, we give them source locations that
10128 -- correspond to the string positions, which is a bit tricky given
10129 -- the possible presence of wide character escape sequences.
10131 for J
in 1 .. Strlen
loop
10132 C
:= Get_String_Char
(Str
, J
);
10133 Set_Character_Literal_Name
(C
);
10136 Make_Character_Literal
(P
,
10137 Chars
=> Name_Find
,
10138 Char_Literal_Value
=> UI_From_CC
(C
)));
10140 if In_Character_Range
(C
) then
10143 -- Should we have a call to Skip_Wide here ???
10152 Make_Qualified_Expression
(Loc
,
10153 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
10155 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
10157 Analyze_And_Resolve
(N
, Typ
);
10159 end Resolve_String_Literal
;
10161 -----------------------------
10162 -- Resolve_Type_Conversion --
10163 -----------------------------
10165 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
10166 Conv_OK
: constant Boolean := Conversion_OK
(N
);
10167 Operand
: constant Node_Id
:= Expression
(N
);
10168 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
10169 Target_Typ
: constant Entity_Id
:= Etype
(N
);
10174 Test_Redundant
: Boolean := Warn_On_Redundant_Constructs
;
10175 -- Set to False to suppress cases where we want to suppress the test
10176 -- for redundancy to avoid possible false positives on this warning.
10180 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
10185 -- If the Operand Etype is Universal_Fixed, then the conversion is
10186 -- never redundant. We need this check because by the time we have
10187 -- finished the rather complex transformation, the conversion looks
10188 -- redundant when it is not.
10190 if Operand_Typ
= Universal_Fixed
then
10191 Test_Redundant
:= False;
10193 -- If the operand is marked as Any_Fixed, then special processing is
10194 -- required. This is also a case where we suppress the test for a
10195 -- redundant conversion, since most certainly it is not redundant.
10197 elsif Operand_Typ
= Any_Fixed
then
10198 Test_Redundant
:= False;
10200 -- Mixed-mode operation involving a literal. Context must be a fixed
10201 -- type which is applied to the literal subsequently.
10203 if Is_Fixed_Point_Type
(Typ
) then
10204 Set_Etype
(Operand
, Universal_Real
);
10206 elsif Is_Numeric_Type
(Typ
)
10207 and then Nkind_In
(Operand
, N_Op_Multiply
, N_Op_Divide
)
10208 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
10210 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
10212 -- Return if expression is ambiguous
10214 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
10217 -- If nothing else, the available fixed type is Duration
10220 Set_Etype
(Operand
, Standard_Duration
);
10223 -- Resolve the real operand with largest available precision
10225 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
10226 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
10228 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
10231 Resolve
(Rop
, Universal_Real
);
10233 -- If the operand is a literal (it could be a non-static and
10234 -- illegal exponentiation) check whether the use of Duration
10235 -- is potentially inaccurate.
10237 if Nkind
(Rop
) = N_Real_Literal
10238 and then Realval
(Rop
) /= Ureal_0
10239 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
10242 ("??universal real operand can only "
10243 & "be interpreted as Duration!", Rop
);
10245 ("\??precision will be lost in the conversion!", Rop
);
10248 elsif Is_Numeric_Type
(Typ
)
10249 and then Nkind
(Operand
) in N_Op
10250 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
10252 Set_Etype
(Operand
, Standard_Duration
);
10255 Error_Msg_N
("invalid context for mixed mode operation", N
);
10256 Set_Etype
(Operand
, Any_Type
);
10263 -- In SPARK, a type conversion between array types should be restricted
10264 -- to types which have matching static bounds.
10266 -- Protect call to Matching_Static_Array_Bounds to avoid costly
10267 -- operation if not needed.
10269 if Restriction_Check_Required
(SPARK_05
)
10270 and then Is_Array_Type
(Target_Typ
)
10271 and then Is_Array_Type
(Operand_Typ
)
10272 and then Operand_Typ
/= Any_Composite
-- or else Operand in error
10273 and then not Matching_Static_Array_Bounds
(Target_Typ
, Operand_Typ
)
10275 Check_SPARK_05_Restriction
10276 ("array types should have matching static bounds", N
);
10279 -- In formal mode, the operand of an ancestor type conversion must be an
10280 -- object (not an expression).
10282 if Is_Tagged_Type
(Target_Typ
)
10283 and then not Is_Class_Wide_Type
(Target_Typ
)
10284 and then Is_Tagged_Type
(Operand_Typ
)
10285 and then not Is_Class_Wide_Type
(Operand_Typ
)
10286 and then Is_Ancestor
(Target_Typ
, Operand_Typ
)
10287 and then not Is_SPARK_05_Object_Reference
(Operand
)
10289 Check_SPARK_05_Restriction
("object required", Operand
);
10292 Analyze_Dimension
(N
);
10294 -- Note: we do the Eval_Type_Conversion call before applying the
10295 -- required checks for a subtype conversion. This is important, since
10296 -- both are prepared under certain circumstances to change the type
10297 -- conversion to a constraint error node, but in the case of
10298 -- Eval_Type_Conversion this may reflect an illegality in the static
10299 -- case, and we would miss the illegality (getting only a warning
10300 -- message), if we applied the type conversion checks first.
10302 Eval_Type_Conversion
(N
);
10304 -- Even when evaluation is not possible, we may be able to simplify the
10305 -- conversion or its expression. This needs to be done before applying
10306 -- checks, since otherwise the checks may use the original expression
10307 -- and defeat the simplifications. This is specifically the case for
10308 -- elimination of the floating-point Truncation attribute in
10309 -- float-to-int conversions.
10311 Simplify_Type_Conversion
(N
);
10313 -- If after evaluation we still have a type conversion, then we may need
10314 -- to apply checks required for a subtype conversion.
10316 -- Skip these type conversion checks if universal fixed operands
10317 -- operands involved, since range checks are handled separately for
10318 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
10320 if Nkind
(N
) = N_Type_Conversion
10321 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
10322 and then Target_Typ
/= Universal_Fixed
10323 and then Operand_Typ
/= Universal_Fixed
10325 Apply_Type_Conversion_Checks
(N
);
10328 -- Issue warning for conversion of simple object to its own type. We
10329 -- have to test the original nodes, since they may have been rewritten
10330 -- by various optimizations.
10332 Orig_N
:= Original_Node
(N
);
10334 -- Here we test for a redundant conversion if the warning mode is
10335 -- active (and was not locally reset), and we have a type conversion
10336 -- from source not appearing in a generic instance.
10339 and then Nkind
(Orig_N
) = N_Type_Conversion
10340 and then Comes_From_Source
(Orig_N
)
10341 and then not In_Instance
10343 Orig_N
:= Original_Node
(Expression
(Orig_N
));
10344 Orig_T
:= Target_Typ
;
10346 -- If the node is part of a larger expression, the Target_Type
10347 -- may not be the original type of the node if the context is a
10348 -- condition. Recover original type to see if conversion is needed.
10350 if Is_Boolean_Type
(Orig_T
)
10351 and then Nkind
(Parent
(N
)) in N_Op
10353 Orig_T
:= Etype
(Parent
(N
));
10356 -- If we have an entity name, then give the warning if the entity
10357 -- is the right type, or if it is a loop parameter covered by the
10358 -- original type (that's needed because loop parameters have an
10359 -- odd subtype coming from the bounds).
10361 if (Is_Entity_Name
(Orig_N
)
10363 (Etype
(Entity
(Orig_N
)) = Orig_T
10365 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
10366 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
))))))
10368 -- If not an entity, then type of expression must match
10370 or else Etype
(Orig_N
) = Orig_T
10372 -- One more check, do not give warning if the analyzed conversion
10373 -- has an expression with non-static bounds, and the bounds of the
10374 -- target are static. This avoids junk warnings in cases where the
10375 -- conversion is necessary to establish staticness, for example in
10376 -- a case statement.
10378 if not Is_OK_Static_Subtype
(Operand_Typ
)
10379 and then Is_OK_Static_Subtype
(Target_Typ
)
10383 -- Finally, if this type conversion occurs in a context requiring
10384 -- a prefix, and the expression is a qualified expression then the
10385 -- type conversion is not redundant, since a qualified expression
10386 -- is not a prefix, whereas a type conversion is. For example, "X
10387 -- := T'(Funx(...)).Y;" is illegal because a selected component
10388 -- requires a prefix, but a type conversion makes it legal: "X :=
10389 -- T(T'(Funx(...))).Y;"
10391 -- In Ada 2012, a qualified expression is a name, so this idiom is
10392 -- no longer needed, but we still suppress the warning because it
10393 -- seems unfriendly for warnings to pop up when you switch to the
10394 -- newer language version.
10396 elsif Nkind
(Orig_N
) = N_Qualified_Expression
10397 and then Nkind_In
(Parent
(N
), N_Attribute_Reference
,
10398 N_Indexed_Component
,
10399 N_Selected_Component
,
10401 N_Explicit_Dereference
)
10405 -- Never warn on conversion to Long_Long_Integer'Base since
10406 -- that is most likely an artifact of the extended overflow
10407 -- checking and comes from complex expanded code.
10409 elsif Orig_T
= Base_Type
(Standard_Long_Long_Integer
) then
10412 -- Here we give the redundant conversion warning. If it is an
10413 -- entity, give the name of the entity in the message. If not,
10414 -- just mention the expression.
10416 -- Shoudn't we test Warn_On_Redundant_Constructs here ???
10419 if Is_Entity_Name
(Orig_N
) then
10420 Error_Msg_Node_2
:= Orig_T
;
10421 Error_Msg_NE
-- CODEFIX
10422 ("??redundant conversion, & is of type &!",
10423 N
, Entity
(Orig_N
));
10426 ("??redundant conversion, expression is of type&!",
10433 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
10434 -- No need to perform any interface conversion if the type of the
10435 -- expression coincides with the target type.
10437 if Ada_Version
>= Ada_2005
10438 and then Expander_Active
10439 and then Operand_Typ
/= Target_Typ
10442 Opnd
: Entity_Id
:= Operand_Typ
;
10443 Target
: Entity_Id
:= Target_Typ
;
10446 -- If the type of the operand is a limited view, use the non-
10447 -- limited view when available.
10449 if From_Limited_With
(Opnd
)
10450 and then Ekind
(Opnd
) in Incomplete_Kind
10451 and then Present
(Non_Limited_View
(Opnd
))
10453 Opnd
:= Non_Limited_View
(Opnd
);
10454 Set_Etype
(Expression
(N
), Opnd
);
10457 if Is_Access_Type
(Opnd
) then
10458 Opnd
:= Designated_Type
(Opnd
);
10461 if Is_Access_Type
(Target_Typ
) then
10462 Target
:= Designated_Type
(Target
);
10465 if Opnd
= Target
then
10468 -- Conversion from interface type
10470 elsif Is_Interface
(Opnd
) then
10472 -- Ada 2005 (AI-217): Handle entities from limited views
10474 if From_Limited_With
(Opnd
) then
10475 Error_Msg_Qual_Level
:= 99;
10476 Error_Msg_NE
-- CODEFIX
10477 ("missing WITH clause on package &", N
,
10478 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
10480 ("type conversions require visibility of the full view",
10483 elsif From_Limited_With
(Target
)
10485 (Is_Access_Type
(Target_Typ
)
10486 and then Present
(Non_Limited_View
(Etype
(Target
))))
10488 Error_Msg_Qual_Level
:= 99;
10489 Error_Msg_NE
-- CODEFIX
10490 ("missing WITH clause on package &", N
,
10491 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
10493 ("type conversions require visibility of the full view",
10497 Expand_Interface_Conversion
(N
);
10500 -- Conversion to interface type
10502 elsif Is_Interface
(Target
) then
10506 if Ekind_In
(Opnd
, E_Protected_Subtype
, E_Task_Subtype
) then
10507 Opnd
:= Etype
(Opnd
);
10510 if Is_Class_Wide_Type
(Opnd
)
10511 or else Interface_Present_In_Ancestor
10515 Expand_Interface_Conversion
(N
);
10517 Error_Msg_Name_1
:= Chars
(Etype
(Target
));
10518 Error_Msg_Name_2
:= Chars
(Opnd
);
10520 ("wrong interface conversion (% is not a progenitor "
10527 -- Ada 2012: if target type has predicates, the result requires a
10528 -- predicate check. If the context is a call to another predicate
10529 -- check we must prevent infinite recursion.
10531 if Has_Predicates
(Target_Typ
) then
10532 if Nkind
(Parent
(N
)) = N_Function_Call
10533 and then Present
(Name
(Parent
(N
)))
10534 and then (Is_Predicate_Function
(Entity
(Name
(Parent
(N
))))
10536 Is_Predicate_Function_M
(Entity
(Name
(Parent
(N
)))))
10541 Apply_Predicate_Check
(N
, Target_Typ
);
10545 -- If at this stage we have a real to integer conversion, make sure
10546 -- that the Do_Range_Check flag is set, because such conversions in
10547 -- general need a range check. We only need this if expansion is off
10548 -- or we are in GNATProve mode.
10550 if Nkind
(N
) = N_Type_Conversion
10551 and then (GNATprove_Mode
or not Expander_Active
)
10552 and then Is_Integer_Type
(Target_Typ
)
10553 and then Is_Real_Type
(Operand_Typ
)
10555 Set_Do_Range_Check
(Operand
);
10557 end Resolve_Type_Conversion
;
10559 ----------------------
10560 -- Resolve_Unary_Op --
10561 ----------------------
10563 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
10564 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10565 R
: constant Node_Id
:= Right_Opnd
(N
);
10571 if Is_Modular_Integer_Type
(Typ
) and then Nkind
(N
) /= N_Op_Not
then
10572 Error_Msg_Name_1
:= Chars
(Typ
);
10573 Check_SPARK_05_Restriction
10574 ("unary operator not defined for modular type%", N
);
10577 -- Deal with intrinsic unary operators
10579 if Comes_From_Source
(N
)
10580 and then Ekind
(Entity
(N
)) = E_Function
10581 and then Is_Imported
(Entity
(N
))
10582 and then Is_Intrinsic_Subprogram
(Entity
(N
))
10584 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10588 -- Deal with universal cases
10590 if Etype
(R
) = Universal_Integer
10592 Etype
(R
) = Universal_Real
10594 Check_For_Visible_Operator
(N
, B_Typ
);
10597 Set_Etype
(N
, B_Typ
);
10598 Resolve
(R
, B_Typ
);
10600 -- Generate warning for expressions like abs (x mod 2)
10602 if Warn_On_Redundant_Constructs
10603 and then Nkind
(N
) = N_Op_Abs
10605 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
10607 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
10608 Error_Msg_N
-- CODEFIX
10609 ("?r?abs applied to known non-negative value has no effect", N
);
10613 -- Deal with reference generation
10615 Check_Unset_Reference
(R
);
10616 Generate_Operator_Reference
(N
, B_Typ
);
10617 Analyze_Dimension
(N
);
10620 -- Set overflow checking bit. Much cleverer code needed here eventually
10621 -- and perhaps the Resolve routines should be separated for the various
10622 -- arithmetic operations, since they will need different processing ???
10624 if Nkind
(N
) in N_Op
then
10625 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
10626 Enable_Overflow_Check
(N
);
10630 -- Generate warning for expressions like -5 mod 3 for integers. No need
10631 -- to worry in the floating-point case, since parens do not affect the
10632 -- result so there is no point in giving in a warning.
10635 Norig
: constant Node_Id
:= Original_Node
(N
);
10644 if Warn_On_Questionable_Missing_Parens
10645 and then Comes_From_Source
(Norig
)
10646 and then Is_Integer_Type
(Typ
)
10647 and then Nkind
(Norig
) = N_Op_Minus
10649 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
10651 -- We are looking for cases where the right operand is not
10652 -- parenthesized, and is a binary operator, multiply, divide, or
10653 -- mod. These are the cases where the grouping can affect results.
10655 if Paren_Count
(Rorig
) = 0
10656 and then Nkind_In
(Rorig
, N_Op_Mod
, N_Op_Multiply
, N_Op_Divide
)
10658 -- For mod, we always give the warning, since the value is
10659 -- affected by the parenthesization (e.g. (-5) mod 315 /=
10660 -- -(5 mod 315)). But for the other cases, the only concern is
10661 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
10662 -- overflows, but (-2) * 64 does not). So we try to give the
10663 -- message only when overflow is possible.
10665 if Nkind
(Rorig
) /= N_Op_Mod
10666 and then Compile_Time_Known_Value
(R
)
10668 Val
:= Expr_Value
(R
);
10670 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
10671 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
10673 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
10676 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
10677 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
10679 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
10682 -- Note that the test below is deliberately excluding the
10683 -- largest negative number, since that is a potentially
10684 -- troublesome case (e.g. -2 * x, where the result is the
10685 -- largest negative integer has an overflow with 2 * x).
10687 if Val
> LB
and then Val
<= HB
then
10692 -- For the multiplication case, the only case we have to worry
10693 -- about is when (-a)*b is exactly the largest negative number
10694 -- so that -(a*b) can cause overflow. This can only happen if
10695 -- a is a power of 2, and more generally if any operand is a
10696 -- constant that is not a power of 2, then the parentheses
10697 -- cannot affect whether overflow occurs. We only bother to
10698 -- test the left most operand
10700 -- Loop looking at left operands for one that has known value
10703 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
10704 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
10705 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
10707 -- Operand value of 0 or 1 skips warning
10712 -- Otherwise check power of 2, if power of 2, warn, if
10713 -- anything else, skip warning.
10716 while Lval
/= 2 loop
10717 if Lval
mod 2 = 1 then
10728 -- Keep looking at left operands
10730 Opnd
:= Left_Opnd
(Opnd
);
10731 end loop Opnd_Loop
;
10733 -- For rem or "/" we can only have a problematic situation
10734 -- if the divisor has a value of minus one or one. Otherwise
10735 -- overflow is impossible (divisor > 1) or we have a case of
10736 -- division by zero in any case.
10738 if Nkind_In
(Rorig
, N_Op_Divide
, N_Op_Rem
)
10739 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
10740 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
10745 -- If we fall through warning should be issued
10747 -- Shouldn't we test Warn_On_Questionable_Missing_Parens ???
10750 ("??unary minus expression should be parenthesized here!", N
);
10754 end Resolve_Unary_Op
;
10756 ----------------------------------
10757 -- Resolve_Unchecked_Expression --
10758 ----------------------------------
10760 procedure Resolve_Unchecked_Expression
10765 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
10766 Set_Etype
(N
, Typ
);
10767 end Resolve_Unchecked_Expression
;
10769 ---------------------------------------
10770 -- Resolve_Unchecked_Type_Conversion --
10771 ---------------------------------------
10773 procedure Resolve_Unchecked_Type_Conversion
10777 pragma Warnings
(Off
, Typ
);
10779 Operand
: constant Node_Id
:= Expression
(N
);
10780 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
10783 -- Resolve operand using its own type
10785 Resolve
(Operand
, Opnd_Type
);
10787 -- In an inlined context, the unchecked conversion may be applied
10788 -- to a literal, in which case its type is the type of the context.
10789 -- (In other contexts conversions cannot apply to literals).
10792 and then (Opnd_Type
= Any_Character
or else
10793 Opnd_Type
= Any_Integer
or else
10794 Opnd_Type
= Any_Real
)
10796 Set_Etype
(Operand
, Typ
);
10799 Analyze_Dimension
(N
);
10800 Eval_Unchecked_Conversion
(N
);
10801 end Resolve_Unchecked_Type_Conversion
;
10803 ------------------------------
10804 -- Rewrite_Operator_As_Call --
10805 ------------------------------
10807 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
10808 Loc
: constant Source_Ptr
:= Sloc
(N
);
10809 Actuals
: constant List_Id
:= New_List
;
10813 if Nkind
(N
) in N_Binary_Op
then
10814 Append
(Left_Opnd
(N
), Actuals
);
10817 Append
(Right_Opnd
(N
), Actuals
);
10820 Make_Function_Call
(Sloc
=> Loc
,
10821 Name
=> New_Occurrence_Of
(Nam
, Loc
),
10822 Parameter_Associations
=> Actuals
);
10824 Preserve_Comes_From_Source
(New_N
, N
);
10825 Preserve_Comes_From_Source
(Name
(New_N
), N
);
10826 Rewrite
(N
, New_N
);
10827 Set_Etype
(N
, Etype
(Nam
));
10828 end Rewrite_Operator_As_Call
;
10830 ------------------------------
10831 -- Rewrite_Renamed_Operator --
10832 ------------------------------
10834 procedure Rewrite_Renamed_Operator
10839 Nam
: constant Name_Id
:= Chars
(Op
);
10840 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
10844 -- Do not perform this transformation within a pre/postcondition,
10845 -- because the expression will be re-analyzed, and the transformation
10846 -- might affect the visibility of the operator, e.g. in an instance.
10848 if In_Assertion_Expr
> 0 then
10852 -- Rewrite the operator node using the real operator, not its renaming.
10853 -- Exclude user-defined intrinsic operations of the same name, which are
10854 -- treated separately and rewritten as calls.
10856 if Ekind
(Op
) /= E_Function
or else Chars
(N
) /= Nam
then
10857 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
10858 Set_Chars
(Op_Node
, Nam
);
10859 Set_Etype
(Op_Node
, Etype
(N
));
10860 Set_Entity
(Op_Node
, Op
);
10861 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
10863 -- Indicate that both the original entity and its renaming are
10864 -- referenced at this point.
10866 Generate_Reference
(Entity
(N
), N
);
10867 Generate_Reference
(Op
, N
);
10870 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
10873 Rewrite
(N
, Op_Node
);
10875 -- If the context type is private, add the appropriate conversions so
10876 -- that the operator is applied to the full view. This is done in the
10877 -- routines that resolve intrinsic operators.
10879 if Is_Intrinsic_Subprogram
(Op
)
10880 and then Is_Private_Type
(Typ
)
10883 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
10884 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
10885 Resolve_Intrinsic_Operator
(N
, Typ
);
10887 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
10888 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10895 elsif Ekind
(Op
) = E_Function
and then Is_Intrinsic_Subprogram
(Op
) then
10897 -- Operator renames a user-defined operator of the same name. Use the
10898 -- original operator in the node, which is the one Gigi knows about.
10900 Set_Entity
(N
, Op
);
10901 Set_Is_Overloaded
(N
, False);
10903 end Rewrite_Renamed_Operator
;
10905 -----------------------
10906 -- Set_Slice_Subtype --
10907 -----------------------
10909 -- Build an implicit subtype declaration to represent the type delivered by
10910 -- the slice. This is an abbreviated version of an array subtype. We define
10911 -- an index subtype for the slice, using either the subtype name or the
10912 -- discrete range of the slice. To be consistent with index usage elsewhere
10913 -- we create a list header to hold the single index. This list is not
10914 -- otherwise attached to the syntax tree.
10916 procedure Set_Slice_Subtype
(N
: Node_Id
) is
10917 Loc
: constant Source_Ptr
:= Sloc
(N
);
10918 Index_List
: constant List_Id
:= New_List
;
10920 Index_Subtype
: Entity_Id
;
10921 Index_Type
: Entity_Id
;
10922 Slice_Subtype
: Entity_Id
;
10923 Drange
: constant Node_Id
:= Discrete_Range
(N
);
10926 Index_Type
:= Base_Type
(Etype
(Drange
));
10928 if Is_Entity_Name
(Drange
) then
10929 Index_Subtype
:= Entity
(Drange
);
10932 -- We force the evaluation of a range. This is definitely needed in
10933 -- the renamed case, and seems safer to do unconditionally. Note in
10934 -- any case that since we will create and insert an Itype referring
10935 -- to this range, we must make sure any side effect removal actions
10936 -- are inserted before the Itype definition.
10938 if Nkind
(Drange
) = N_Range
then
10939 Force_Evaluation
(Low_Bound
(Drange
));
10940 Force_Evaluation
(High_Bound
(Drange
));
10942 -- If the discrete range is given by a subtype indication, the
10943 -- type of the slice is the base of the subtype mark.
10945 elsif Nkind
(Drange
) = N_Subtype_Indication
then
10947 R
: constant Node_Id
:= Range_Expression
(Constraint
(Drange
));
10949 Index_Type
:= Base_Type
(Entity
(Subtype_Mark
(Drange
)));
10950 Force_Evaluation
(Low_Bound
(R
));
10951 Force_Evaluation
(High_Bound
(R
));
10955 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
10957 -- Take a new copy of Drange (where bounds have been rewritten to
10958 -- reference side-effect-free names). Using a separate tree ensures
10959 -- that further expansion (e.g. while rewriting a slice assignment
10960 -- into a FOR loop) does not attempt to remove side effects on the
10961 -- bounds again (which would cause the bounds in the index subtype
10962 -- definition to refer to temporaries before they are defined) (the
10963 -- reason is that some names are considered side effect free here
10964 -- for the subtype, but not in the context of a loop iteration
10967 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
10968 Set_Parent
(Scalar_Range
(Index_Subtype
), Index_Subtype
);
10969 Set_Etype
(Index_Subtype
, Index_Type
);
10970 Set_Size_Info
(Index_Subtype
, Index_Type
);
10971 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
10974 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
10976 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
10977 Set_Etype
(Index
, Index_Subtype
);
10978 Append
(Index
, Index_List
);
10980 Set_First_Index
(Slice_Subtype
, Index
);
10981 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
10982 Set_Is_Constrained
(Slice_Subtype
, True);
10984 Check_Compile_Time_Size
(Slice_Subtype
);
10986 -- The Etype of the existing Slice node is reset to this slice subtype.
10987 -- Its bounds are obtained from its first index.
10989 Set_Etype
(N
, Slice_Subtype
);
10991 -- For packed slice subtypes, freeze immediately (except in the case of
10992 -- being in a "spec expression" where we never freeze when we first see
10993 -- the expression).
10995 if Is_Packed
(Slice_Subtype
) and not In_Spec_Expression
then
10996 Freeze_Itype
(Slice_Subtype
, N
);
10998 -- For all other cases insert an itype reference in the slice's actions
10999 -- so that the itype is frozen at the proper place in the tree (i.e. at
11000 -- the point where actions for the slice are analyzed). Note that this
11001 -- is different from freezing the itype immediately, which might be
11002 -- premature (e.g. if the slice is within a transient scope). This needs
11003 -- to be done only if expansion is enabled.
11005 elsif Expander_Active
then
11006 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
11008 end Set_Slice_Subtype
;
11010 --------------------------------
11011 -- Set_String_Literal_Subtype --
11012 --------------------------------
11014 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
11015 Loc
: constant Source_Ptr
:= Sloc
(N
);
11016 Low_Bound
: constant Node_Id
:=
11017 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
11018 Subtype_Id
: Entity_Id
;
11021 if Nkind
(N
) /= N_String_Literal
then
11025 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
11026 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
11027 (String_Length
(Strval
(N
))));
11028 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
11029 Set_Is_Constrained
(Subtype_Id
);
11030 Set_Etype
(N
, Subtype_Id
);
11032 -- The low bound is set from the low bound of the corresponding index
11033 -- type. Note that we do not store the high bound in the string literal
11034 -- subtype, but it can be deduced if necessary from the length and the
11037 if Is_OK_Static_Expression
(Low_Bound
) then
11038 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
11040 -- If the lower bound is not static we create a range for the string
11041 -- literal, using the index type and the known length of the literal.
11042 -- The index type is not necessarily Positive, so the upper bound is
11043 -- computed as T'Val (T'Pos (Low_Bound) + L - 1).
11047 Index_List
: constant List_Id
:= New_List
;
11048 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
11049 High_Bound
: constant Node_Id
:=
11050 Make_Attribute_Reference
(Loc
,
11051 Attribute_Name
=> Name_Val
,
11053 New_Occurrence_Of
(Index_Type
, Loc
),
11054 Expressions
=> New_List
(
11057 Make_Attribute_Reference
(Loc
,
11058 Attribute_Name
=> Name_Pos
,
11060 New_Occurrence_Of
(Index_Type
, Loc
),
11062 New_List
(New_Copy_Tree
(Low_Bound
))),
11064 Make_Integer_Literal
(Loc
,
11065 String_Length
(Strval
(N
)) - 1))));
11067 Array_Subtype
: Entity_Id
;
11070 Index_Subtype
: Entity_Id
;
11073 if Is_Integer_Type
(Index_Type
) then
11074 Set_String_Literal_Low_Bound
11075 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
11078 -- If the index type is an enumeration type, build bounds
11079 -- expression with attributes.
11081 Set_String_Literal_Low_Bound
11083 Make_Attribute_Reference
(Loc
,
11084 Attribute_Name
=> Name_First
,
11086 New_Occurrence_Of
(Base_Type
(Index_Type
), Loc
)));
11087 Set_Etype
(String_Literal_Low_Bound
(Subtype_Id
), Index_Type
);
11090 Analyze_And_Resolve
(String_Literal_Low_Bound
(Subtype_Id
));
11092 -- Build bona fide subtype for the string, and wrap it in an
11093 -- unchecked conversion, because the backend expects the
11094 -- String_Literal_Subtype to have a static lower bound.
11097 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
11098 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
11099 Set_Scalar_Range
(Index_Subtype
, Drange
);
11100 Set_Parent
(Drange
, N
);
11101 Analyze_And_Resolve
(Drange
, Index_Type
);
11103 -- In the context, the Index_Type may already have a constraint,
11104 -- so use common base type on string subtype. The base type may
11105 -- be used when generating attributes of the string, for example
11106 -- in the context of a slice assignment.
11108 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
11109 Set_Size_Info
(Index_Subtype
, Index_Type
);
11110 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
11112 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
11114 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
11115 Set_Etype
(Index
, Index_Subtype
);
11116 Append
(Index
, Index_List
);
11118 Set_First_Index
(Array_Subtype
, Index
);
11119 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
11120 Set_Is_Constrained
(Array_Subtype
, True);
11123 Make_Unchecked_Type_Conversion
(Loc
,
11124 Subtype_Mark
=> New_Occurrence_Of
(Array_Subtype
, Loc
),
11125 Expression
=> Relocate_Node
(N
)));
11126 Set_Etype
(N
, Array_Subtype
);
11129 end Set_String_Literal_Subtype
;
11131 ------------------------------
11132 -- Simplify_Type_Conversion --
11133 ------------------------------
11135 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
11137 if Nkind
(N
) = N_Type_Conversion
then
11139 Operand
: constant Node_Id
:= Expression
(N
);
11140 Target_Typ
: constant Entity_Id
:= Etype
(N
);
11141 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
11144 -- Special processing if the conversion is the expression of a
11145 -- Rounding or Truncation attribute reference. In this case we
11148 -- ityp (ftyp'Rounding (x)) or ityp (ftyp'Truncation (x))
11154 -- with the Float_Truncate flag set to False or True respectively,
11155 -- which is more efficient.
11157 if Is_Floating_Point_Type
(Opnd_Typ
)
11159 (Is_Integer_Type
(Target_Typ
)
11160 or else (Is_Fixed_Point_Type
(Target_Typ
)
11161 and then Conversion_OK
(N
)))
11162 and then Nkind
(Operand
) = N_Attribute_Reference
11163 and then Nam_In
(Attribute_Name
(Operand
), Name_Rounding
,
11167 Truncate
: constant Boolean :=
11168 Attribute_Name
(Operand
) = Name_Truncation
;
11171 Relocate_Node
(First
(Expressions
(Operand
))));
11172 Set_Float_Truncate
(N
, Truncate
);
11177 end Simplify_Type_Conversion
;
11179 -----------------------------
11180 -- Unique_Fixed_Point_Type --
11181 -----------------------------
11183 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
11184 T1
: Entity_Id
:= Empty
;
11189 procedure Fixed_Point_Error
;
11190 -- Give error messages for true ambiguity. Messages are posted on node
11191 -- N, and entities T1, T2 are the possible interpretations.
11193 -----------------------
11194 -- Fixed_Point_Error --
11195 -----------------------
11197 procedure Fixed_Point_Error
is
11199 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
11200 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
11201 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
11202 end Fixed_Point_Error
;
11204 -- Start of processing for Unique_Fixed_Point_Type
11207 -- The operations on Duration are visible, so Duration is always a
11208 -- possible interpretation.
11210 T1
:= Standard_Duration
;
11212 -- Look for fixed-point types in enclosing scopes
11214 Scop
:= Current_Scope
;
11215 while Scop
/= Standard_Standard
loop
11216 T2
:= First_Entity
(Scop
);
11217 while Present
(T2
) loop
11218 if Is_Fixed_Point_Type
(T2
)
11219 and then Current_Entity
(T2
) = T2
11220 and then Scope
(Base_Type
(T2
)) = Scop
11222 if Present
(T1
) then
11233 Scop
:= Scope
(Scop
);
11236 -- Look for visible fixed type declarations in the context
11238 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
11239 while Present
(Item
) loop
11240 if Nkind
(Item
) = N_With_Clause
then
11241 Scop
:= Entity
(Name
(Item
));
11242 T2
:= First_Entity
(Scop
);
11243 while Present
(T2
) loop
11244 if Is_Fixed_Point_Type
(T2
)
11245 and then Scope
(Base_Type
(T2
)) = Scop
11246 and then (Is_Potentially_Use_Visible
(T2
) or else In_Use
(T2
))
11248 if Present
(T1
) then
11263 if Nkind
(N
) = N_Real_Literal
then
11265 ("??real literal interpreted as }!", N
, T1
);
11268 ("??universal_fixed expression interpreted as }!", N
, T1
);
11272 end Unique_Fixed_Point_Type
;
11274 ----------------------
11275 -- Valid_Conversion --
11276 ----------------------
11278 function Valid_Conversion
11280 Target
: Entity_Id
;
11282 Report_Errs
: Boolean := True) return Boolean
11284 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
11285 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
11286 Inc_Ancestor
: Entity_Id
;
11288 function Conversion_Check
11290 Msg
: String) return Boolean;
11291 -- Little routine to post Msg if Valid is False, returns Valid value
11293 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
);
11294 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
11296 procedure Conversion_Error_NE
11298 N
: Node_Or_Entity_Id
;
11299 E
: Node_Or_Entity_Id
);
11300 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
11302 function Valid_Tagged_Conversion
11303 (Target_Type
: Entity_Id
;
11304 Opnd_Type
: Entity_Id
) return Boolean;
11305 -- Specifically test for validity of tagged conversions
11307 function Valid_Array_Conversion
return Boolean;
11308 -- Check index and component conformance, and accessibility levels if
11309 -- the component types are anonymous access types (Ada 2005).
11311 ----------------------
11312 -- Conversion_Check --
11313 ----------------------
11315 function Conversion_Check
11317 Msg
: String) return Boolean
11322 -- A generic unit has already been analyzed and we have verified
11323 -- that a particular conversion is OK in that context. Since the
11324 -- instance is reanalyzed without relying on the relationships
11325 -- established during the analysis of the generic, it is possible
11326 -- to end up with inconsistent views of private types. Do not emit
11327 -- the error message in such cases. The rest of the machinery in
11328 -- Valid_Conversion still ensures the proper compatibility of
11329 -- target and operand types.
11331 and then not In_Instance
11333 Conversion_Error_N
(Msg
, Operand
);
11337 end Conversion_Check
;
11339 ------------------------
11340 -- Conversion_Error_N --
11341 ------------------------
11343 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
11345 if Report_Errs
then
11346 Error_Msg_N
(Msg
, N
);
11348 end Conversion_Error_N
;
11350 -------------------------
11351 -- Conversion_Error_NE --
11352 -------------------------
11354 procedure Conversion_Error_NE
11356 N
: Node_Or_Entity_Id
;
11357 E
: Node_Or_Entity_Id
)
11360 if Report_Errs
then
11361 Error_Msg_NE
(Msg
, N
, E
);
11363 end Conversion_Error_NE
;
11365 ----------------------------
11366 -- Valid_Array_Conversion --
11367 ----------------------------
11369 function Valid_Array_Conversion
return Boolean
11371 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
11372 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
11374 Opnd_Index
: Node_Id
;
11375 Opnd_Index_Type
: Entity_Id
;
11377 Target_Comp_Type
: constant Entity_Id
:=
11378 Component_Type
(Target_Type
);
11379 Target_Comp_Base
: constant Entity_Id
:=
11380 Base_Type
(Target_Comp_Type
);
11382 Target_Index
: Node_Id
;
11383 Target_Index_Type
: Entity_Id
;
11386 -- Error if wrong number of dimensions
11389 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
11392 ("incompatible number of dimensions for conversion", Operand
);
11395 -- Number of dimensions matches
11398 -- Loop through indexes of the two arrays
11400 Target_Index
:= First_Index
(Target_Type
);
11401 Opnd_Index
:= First_Index
(Opnd_Type
);
11402 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
11403 Target_Index_Type
:= Etype
(Target_Index
);
11404 Opnd_Index_Type
:= Etype
(Opnd_Index
);
11406 -- Error if index types are incompatible
11408 if not (Is_Integer_Type
(Target_Index_Type
)
11409 and then Is_Integer_Type
(Opnd_Index_Type
))
11410 and then (Root_Type
(Target_Index_Type
)
11411 /= Root_Type
(Opnd_Index_Type
))
11414 ("incompatible index types for array conversion",
11419 Next_Index
(Target_Index
);
11420 Next_Index
(Opnd_Index
);
11423 -- If component types have same base type, all set
11425 if Target_Comp_Base
= Opnd_Comp_Base
then
11428 -- Here if base types of components are not the same. The only
11429 -- time this is allowed is if we have anonymous access types.
11431 -- The conversion of arrays of anonymous access types can lead
11432 -- to dangling pointers. AI-392 formalizes the accessibility
11433 -- checks that must be applied to such conversions to prevent
11434 -- out-of-scope references.
11437 (Target_Comp_Base
, E_Anonymous_Access_Type
,
11438 E_Anonymous_Access_Subprogram_Type
)
11439 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
11441 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
11443 if Type_Access_Level
(Target_Type
) <
11444 Deepest_Type_Access_Level
(Opnd_Type
)
11446 if In_Instance_Body
then
11447 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11449 ("source array type has deeper accessibility "
11450 & "level than target<<", Operand
);
11451 Conversion_Error_N
("\Program_Error [<<", Operand
);
11453 Make_Raise_Program_Error
(Sloc
(N
),
11454 Reason
=> PE_Accessibility_Check_Failed
));
11455 Set_Etype
(N
, Target_Type
);
11458 -- Conversion not allowed because of accessibility levels
11462 ("source array type has deeper accessibility "
11463 & "level than target", Operand
);
11471 -- All other cases where component base types do not match
11475 ("incompatible component types for array conversion",
11480 -- Check that component subtypes statically match. For numeric
11481 -- types this means that both must be either constrained or
11482 -- unconstrained. For enumeration types the bounds must match.
11483 -- All of this is checked in Subtypes_Statically_Match.
11485 if not Subtypes_Statically_Match
11486 (Target_Comp_Type
, Opnd_Comp_Type
)
11489 ("component subtypes must statically match", Operand
);
11495 end Valid_Array_Conversion
;
11497 -----------------------------
11498 -- Valid_Tagged_Conversion --
11499 -----------------------------
11501 function Valid_Tagged_Conversion
11502 (Target_Type
: Entity_Id
;
11503 Opnd_Type
: Entity_Id
) return Boolean
11506 -- Upward conversions are allowed (RM 4.6(22))
11508 if Covers
(Target_Type
, Opnd_Type
)
11509 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
11513 -- Downward conversion are allowed if the operand is class-wide
11516 elsif Is_Class_Wide_Type
(Opnd_Type
)
11517 and then Covers
(Opnd_Type
, Target_Type
)
11521 elsif Covers
(Opnd_Type
, Target_Type
)
11522 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
11525 Conversion_Check
(False,
11526 "downward conversion of tagged objects not allowed");
11528 -- Ada 2005 (AI-251): The conversion to/from interface types is
11531 elsif Is_Interface
(Target_Type
) or else Is_Interface
(Opnd_Type
) then
11534 -- If the operand is a class-wide type obtained through a limited_
11535 -- with clause, and the context includes the non-limited view, use
11536 -- it to determine whether the conversion is legal.
11538 elsif Is_Class_Wide_Type
(Opnd_Type
)
11539 and then From_Limited_With
(Opnd_Type
)
11540 and then Present
(Non_Limited_View
(Etype
(Opnd_Type
)))
11541 and then Is_Interface
(Non_Limited_View
(Etype
(Opnd_Type
)))
11545 elsif Is_Access_Type
(Opnd_Type
)
11546 and then Is_Interface
(Directly_Designated_Type
(Opnd_Type
))
11551 Conversion_Error_NE
11552 ("invalid tagged conversion, not compatible with}",
11553 N
, First_Subtype
(Opnd_Type
));
11556 end Valid_Tagged_Conversion
;
11558 -- Start of processing for Valid_Conversion
11561 Check_Parameterless_Call
(Operand
);
11563 if Is_Overloaded
(Operand
) then
11573 -- Remove procedure calls, which syntactically cannot appear in
11574 -- this context, but which cannot be removed by type checking,
11575 -- because the context does not impose a type.
11577 -- The node may be labelled overloaded, but still contain only one
11578 -- interpretation because others were discarded earlier. If this
11579 -- is the case, retain the single interpretation if legal.
11581 Get_First_Interp
(Operand
, I
, It
);
11582 Opnd_Type
:= It
.Typ
;
11583 Get_Next_Interp
(I
, It
);
11585 if Present
(It
.Typ
)
11586 and then Opnd_Type
/= Standard_Void_Type
11588 -- More than one candidate interpretation is available
11590 Get_First_Interp
(Operand
, I
, It
);
11591 while Present
(It
.Typ
) loop
11592 if It
.Typ
= Standard_Void_Type
then
11596 -- When compiling for a system where Address is of a visible
11597 -- integer type, spurious ambiguities can be produced when
11598 -- arithmetic operations have a literal operand and return
11599 -- System.Address or a descendant of it. These ambiguities
11600 -- are usually resolved by the context, but for conversions
11601 -- there is no context type and the removal of the spurious
11602 -- operations must be done explicitly here.
11604 if not Address_Is_Private
11605 and then Is_Descendent_Of_Address
(It
.Typ
)
11610 Get_Next_Interp
(I
, It
);
11614 Get_First_Interp
(Operand
, I
, It
);
11618 if No
(It
.Typ
) then
11619 Conversion_Error_N
("illegal operand in conversion", Operand
);
11623 Get_Next_Interp
(I
, It
);
11625 if Present
(It
.Typ
) then
11628 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
11630 if It1
= No_Interp
then
11632 ("ambiguous operand in conversion", Operand
);
11634 -- If the interpretation involves a standard operator, use
11635 -- the location of the type, which may be user-defined.
11637 if Sloc
(It
.Nam
) = Standard_Location
then
11638 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
11640 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
11643 Conversion_Error_N
-- CODEFIX
11644 ("\\possible interpretation#!", Operand
);
11646 if Sloc
(N1
) = Standard_Location
then
11647 Error_Msg_Sloc
:= Sloc
(T1
);
11649 Error_Msg_Sloc
:= Sloc
(N1
);
11652 Conversion_Error_N
-- CODEFIX
11653 ("\\possible interpretation#!", Operand
);
11659 Set_Etype
(Operand
, It1
.Typ
);
11660 Opnd_Type
:= It1
.Typ
;
11664 -- Deal with conversion of integer type to address if the pragma
11665 -- Allow_Integer_Address is in effect. We convert the conversion to
11666 -- an unchecked conversion in this case and we are all done.
11668 if Address_Integer_Convert_OK
(Opnd_Type
, Target_Type
) then
11669 Rewrite
(N
, Unchecked_Convert_To
(Target_Type
, Expression
(N
)));
11670 Analyze_And_Resolve
(N
, Target_Type
);
11674 -- If we are within a child unit, check whether the type of the
11675 -- expression has an ancestor in a parent unit, in which case it
11676 -- belongs to its derivation class even if the ancestor is private.
11677 -- See RM 7.3.1 (5.2/3).
11679 Inc_Ancestor
:= Get_Incomplete_View_Of_Ancestor
(Opnd_Type
);
11683 if Is_Numeric_Type
(Target_Type
) then
11685 -- A universal fixed expression can be converted to any numeric type
11687 if Opnd_Type
= Universal_Fixed
then
11690 -- Also no need to check when in an instance or inlined body, because
11691 -- the legality has been established when the template was analyzed.
11692 -- Furthermore, numeric conversions may occur where only a private
11693 -- view of the operand type is visible at the instantiation point.
11694 -- This results in a spurious error if we check that the operand type
11695 -- is a numeric type.
11697 -- Note: in a previous version of this unit, the following tests were
11698 -- applied only for generated code (Comes_From_Source set to False),
11699 -- but in fact the test is required for source code as well, since
11700 -- this situation can arise in source code.
11702 elsif In_Instance
or else In_Inlined_Body
then
11705 -- Otherwise we need the conversion check
11708 return Conversion_Check
11709 (Is_Numeric_Type
(Opnd_Type
)
11711 (Present
(Inc_Ancestor
)
11712 and then Is_Numeric_Type
(Inc_Ancestor
)),
11713 "illegal operand for numeric conversion");
11718 elsif Is_Array_Type
(Target_Type
) then
11719 if not Is_Array_Type
(Opnd_Type
)
11720 or else Opnd_Type
= Any_Composite
11721 or else Opnd_Type
= Any_String
11724 ("illegal operand for array conversion", Operand
);
11728 return Valid_Array_Conversion
;
11731 -- Ada 2005 (AI-251): Anonymous access types where target references an
11734 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11735 E_Anonymous_Access_Type
)
11736 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
11738 -- Check the static accessibility rule of 4.6(17). Note that the
11739 -- check is not enforced when within an instance body, since the
11740 -- RM requires such cases to be caught at run time.
11742 -- If the operand is a rewriting of an allocator no check is needed
11743 -- because there are no accessibility issues.
11745 if Nkind
(Original_Node
(N
)) = N_Allocator
then
11748 elsif Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
11749 if Type_Access_Level
(Opnd_Type
) >
11750 Deepest_Type_Access_Level
(Target_Type
)
11752 -- In an instance, this is a run-time check, but one we know
11753 -- will fail, so generate an appropriate warning. The raise
11754 -- will be generated by Expand_N_Type_Conversion.
11756 if In_Instance_Body
then
11757 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11759 ("cannot convert local pointer to non-local access type<<",
11761 Conversion_Error_N
("\Program_Error [<<", Operand
);
11765 ("cannot convert local pointer to non-local access type",
11770 -- Special accessibility checks are needed in the case of access
11771 -- discriminants declared for a limited type.
11773 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11774 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11776 -- When the operand is a selected access discriminant the check
11777 -- needs to be made against the level of the object denoted by
11778 -- the prefix of the selected name (Object_Access_Level handles
11779 -- checking the prefix of the operand for this case).
11781 if Nkind
(Operand
) = N_Selected_Component
11782 and then Object_Access_Level
(Operand
) >
11783 Deepest_Type_Access_Level
(Target_Type
)
11785 -- In an instance, this is a run-time check, but one we know
11786 -- will fail, so generate an appropriate warning. The raise
11787 -- will be generated by Expand_N_Type_Conversion.
11789 if In_Instance_Body
then
11790 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11792 ("cannot convert access discriminant to non-local "
11793 & "access type<<", Operand
);
11794 Conversion_Error_N
("\Program_Error [<<", Operand
);
11796 -- Real error if not in instance body
11800 ("cannot convert access discriminant to non-local "
11801 & "access type", Operand
);
11806 -- The case of a reference to an access discriminant from
11807 -- within a limited type declaration (which will appear as
11808 -- a discriminal) is always illegal because the level of the
11809 -- discriminant is considered to be deeper than any (nameable)
11812 if Is_Entity_Name
(Operand
)
11813 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11815 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
11816 and then Present
(Discriminal_Link
(Entity
(Operand
)))
11819 ("discriminant has deeper accessibility level than target",
11828 -- General and anonymous access types
11830 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11831 E_Anonymous_Access_Type
)
11834 (Is_Access_Type
(Opnd_Type
)
11836 Ekind_In
(Opnd_Type
, E_Access_Subprogram_Type
,
11837 E_Access_Protected_Subprogram_Type
),
11838 "must be an access-to-object type")
11840 if Is_Access_Constant
(Opnd_Type
)
11841 and then not Is_Access_Constant
(Target_Type
)
11844 ("access-to-constant operand type not allowed", Operand
);
11848 -- Check the static accessibility rule of 4.6(17). Note that the
11849 -- check is not enforced when within an instance body, since the RM
11850 -- requires such cases to be caught at run time.
11852 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
11853 or else Is_Local_Anonymous_Access
(Target_Type
)
11854 or else Nkind
(Associated_Node_For_Itype
(Target_Type
)) =
11855 N_Object_Declaration
11857 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
11858 -- conversions from an anonymous access type to a named general
11859 -- access type. Such conversions are not allowed in the case of
11860 -- access parameters and stand-alone objects of an anonymous
11861 -- access type. The implicit conversion case is recognized by
11862 -- testing that Comes_From_Source is False and that it's been
11863 -- rewritten. The Comes_From_Source test isn't sufficient because
11864 -- nodes in inlined calls to predefined library routines can have
11865 -- Comes_From_Source set to False. (Is there a better way to test
11866 -- for implicit conversions???)
11868 if Ada_Version
>= Ada_2012
11869 and then not Comes_From_Source
(N
)
11870 and then N
/= Original_Node
(N
)
11871 and then Ekind
(Target_Type
) = E_General_Access_Type
11872 and then Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11874 if Is_Itype
(Opnd_Type
) then
11876 -- Implicit conversions aren't allowed for objects of an
11877 -- anonymous access type, since such objects have nonstatic
11878 -- levels in Ada 2012.
11880 if Nkind
(Associated_Node_For_Itype
(Opnd_Type
)) =
11881 N_Object_Declaration
11884 ("implicit conversion of stand-alone anonymous "
11885 & "access object not allowed", Operand
);
11888 -- Implicit conversions aren't allowed for anonymous access
11889 -- parameters. The "not Is_Local_Anonymous_Access_Type" test
11890 -- is done to exclude anonymous access results.
11892 elsif not Is_Local_Anonymous_Access
(Opnd_Type
)
11893 and then Nkind_In
(Associated_Node_For_Itype
(Opnd_Type
),
11894 N_Function_Specification
,
11895 N_Procedure_Specification
)
11898 ("implicit conversion of anonymous access formal "
11899 & "not allowed", Operand
);
11902 -- This is a case where there's an enclosing object whose
11903 -- to which the "statically deeper than" relationship does
11904 -- not apply (such as an access discriminant selected from
11905 -- a dereference of an access parameter).
11907 elsif Object_Access_Level
(Operand
)
11908 = Scope_Depth
(Standard_Standard
)
11911 ("implicit conversion of anonymous access value "
11912 & "not allowed", Operand
);
11915 -- In other cases, the level of the operand's type must be
11916 -- statically less deep than that of the target type, else
11917 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
11919 elsif Type_Access_Level
(Opnd_Type
) >
11920 Deepest_Type_Access_Level
(Target_Type
)
11923 ("implicit conversion of anonymous access value "
11924 & "violates accessibility", Operand
);
11929 elsif Type_Access_Level
(Opnd_Type
) >
11930 Deepest_Type_Access_Level
(Target_Type
)
11932 -- In an instance, this is a run-time check, but one we know
11933 -- will fail, so generate an appropriate warning. The raise
11934 -- will be generated by Expand_N_Type_Conversion.
11936 if In_Instance_Body
then
11937 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11939 ("cannot convert local pointer to non-local access type<<",
11941 Conversion_Error_N
("\Program_Error [<<", Operand
);
11943 -- If not in an instance body, this is a real error
11946 -- Avoid generation of spurious error message
11948 if not Error_Posted
(N
) then
11950 ("cannot convert local pointer to non-local access type",
11957 -- Special accessibility checks are needed in the case of access
11958 -- discriminants declared for a limited type.
11960 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11961 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11963 -- When the operand is a selected access discriminant the check
11964 -- needs to be made against the level of the object denoted by
11965 -- the prefix of the selected name (Object_Access_Level handles
11966 -- checking the prefix of the operand for this case).
11968 if Nkind
(Operand
) = N_Selected_Component
11969 and then Object_Access_Level
(Operand
) >
11970 Deepest_Type_Access_Level
(Target_Type
)
11972 -- In an instance, this is a run-time check, but one we know
11973 -- will fail, so generate an appropriate warning. The raise
11974 -- will be generated by Expand_N_Type_Conversion.
11976 if In_Instance_Body
then
11977 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11979 ("cannot convert access discriminant to non-local "
11980 & "access type<<", Operand
);
11981 Conversion_Error_N
("\Program_Error [<<", Operand
);
11983 -- If not in an instance body, this is a real error
11987 ("cannot convert access discriminant to non-local "
11988 & "access type", Operand
);
11993 -- The case of a reference to an access discriminant from
11994 -- within a limited type declaration (which will appear as
11995 -- a discriminal) is always illegal because the level of the
11996 -- discriminant is considered to be deeper than any (nameable)
11999 if Is_Entity_Name
(Operand
)
12001 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
12002 and then Present
(Discriminal_Link
(Entity
(Operand
)))
12005 ("discriminant has deeper accessibility level than target",
12012 -- In the presence of limited_with clauses we have to use non-limited
12013 -- views, if available.
12015 Check_Limited
: declare
12016 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
12017 -- Helper function to handle limited views
12019 --------------------------
12020 -- Full_Designated_Type --
12021 --------------------------
12023 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
12024 Desig
: constant Entity_Id
:= Designated_Type
(T
);
12027 -- Handle the limited view of a type
12029 if Is_Incomplete_Type
(Desig
)
12030 and then From_Limited_With
(Desig
)
12031 and then Present
(Non_Limited_View
(Desig
))
12033 return Available_View
(Desig
);
12037 end Full_Designated_Type
;
12039 -- Local Declarations
12041 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
12042 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
12044 Same_Base
: constant Boolean :=
12045 Base_Type
(Target
) = Base_Type
(Opnd
);
12047 -- Start of processing for Check_Limited
12050 if Is_Tagged_Type
(Target
) then
12051 return Valid_Tagged_Conversion
(Target
, Opnd
);
12054 if not Same_Base
then
12055 Conversion_Error_NE
12056 ("target designated type not compatible with }",
12057 N
, Base_Type
(Opnd
));
12060 -- Ada 2005 AI-384: legality rule is symmetric in both
12061 -- designated types. The conversion is legal (with possible
12062 -- constraint check) if either designated type is
12065 elsif Subtypes_Statically_Match
(Target
, Opnd
)
12067 (Has_Discriminants
(Target
)
12069 (not Is_Constrained
(Opnd
)
12070 or else not Is_Constrained
(Target
)))
12072 -- Special case, if Value_Size has been used to make the
12073 -- sizes different, the conversion is not allowed even
12074 -- though the subtypes statically match.
12076 if Known_Static_RM_Size
(Target
)
12077 and then Known_Static_RM_Size
(Opnd
)
12078 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
12080 Conversion_Error_NE
12081 ("target designated subtype not compatible with }",
12083 Conversion_Error_NE
12084 ("\because sizes of the two designated subtypes differ",
12088 -- Normal case where conversion is allowed
12096 ("target designated subtype not compatible with }",
12103 -- Access to subprogram types. If the operand is an access parameter,
12104 -- the type has a deeper accessibility that any master, and cannot be
12105 -- assigned. We must make an exception if the conversion is part of an
12106 -- assignment and the target is the return object of an extended return
12107 -- statement, because in that case the accessibility check takes place
12108 -- after the return.
12110 elsif Is_Access_Subprogram_Type
(Target_Type
)
12112 -- Note: this test of Opnd_Type is there to prevent entering this
12113 -- branch in the case of a remote access to subprogram type, which
12114 -- is internally represented as an E_Record_Type.
12116 and then Is_Access_Type
(Opnd_Type
)
12118 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
12119 and then Is_Entity_Name
(Operand
)
12120 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
12122 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
12123 or else not Is_Entity_Name
(Name
(Parent
(N
)))
12124 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
12127 ("illegal attempt to store anonymous access to subprogram",
12130 ("\value has deeper accessibility than any master "
12131 & "(RM 3.10.2 (13))",
12135 ("\use named access type for& instead of access parameter",
12136 Operand
, Entity
(Operand
));
12139 -- Check that the designated types are subtype conformant
12141 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
12142 Old_Id
=> Designated_Type
(Opnd_Type
),
12145 -- Check the static accessibility rule of 4.6(20)
12147 if Type_Access_Level
(Opnd_Type
) >
12148 Deepest_Type_Access_Level
(Target_Type
)
12151 ("operand type has deeper accessibility level than target",
12154 -- Check that if the operand type is declared in a generic body,
12155 -- then the target type must be declared within that same body
12156 -- (enforces last sentence of 4.6(20)).
12158 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
12160 O_Gen
: constant Node_Id
:=
12161 Enclosing_Generic_Body
(Opnd_Type
);
12166 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
12167 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
12168 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
12171 if T_Gen
/= O_Gen
then
12173 ("target type must be declared in same generic body "
12174 & "as operand type", N
);
12181 -- Remote access to subprogram types
12183 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
12184 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
12186 -- It is valid to convert from one RAS type to another provided
12187 -- that their specification statically match.
12189 -- Note: at this point, remote access to subprogram types have been
12190 -- expanded to their E_Record_Type representation, and we need to
12191 -- go back to the original access type definition using the
12192 -- Corresponding_Remote_Type attribute in order to check that the
12193 -- designated profiles match.
12195 pragma Assert
(Ekind
(Target_Type
) = E_Record_Type
);
12196 pragma Assert
(Ekind
(Opnd_Type
) = E_Record_Type
);
12198 Check_Subtype_Conformant
12200 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
12202 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
12207 -- If it was legal in the generic, it's legal in the instance
12209 elsif In_Instance_Body
then
12212 -- If both are tagged types, check legality of view conversions
12214 elsif Is_Tagged_Type
(Target_Type
)
12216 Is_Tagged_Type
(Opnd_Type
)
12218 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
12220 -- Types derived from the same root type are convertible
12222 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
12225 -- In an instance or an inlined body, there may be inconsistent views of
12226 -- the same type, or of types derived from a common root.
12228 elsif (In_Instance
or In_Inlined_Body
)
12230 Root_Type
(Underlying_Type
(Target_Type
)) =
12231 Root_Type
(Underlying_Type
(Opnd_Type
))
12235 -- Special check for common access type error case
12237 elsif Ekind
(Target_Type
) = E_Access_Type
12238 and then Is_Access_Type
(Opnd_Type
)
12240 Conversion_Error_N
("target type must be general access type!", N
);
12241 Conversion_Error_NE
-- CODEFIX
12242 ("add ALL to }!", N
, Target_Type
);
12245 -- Here we have a real conversion error
12248 Conversion_Error_NE
12249 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
12252 end Valid_Conversion
;