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 -- The volatile object appears as the expression of a type conversion
6700 -- occurring in a non-interfering context.
6702 elsif Nkind_In
(Context
, N_Type_Conversion
,
6703 N_Unchecked_Type_Conversion
)
6704 and then Expression
(Context
) = Obj_Ref
6705 and then Is_OK_Volatile_Context
6706 (Context
=> Parent
(Context
),
6711 -- Allow references to volatile objects in various checks. This is
6712 -- not a direct SPARK 2014 requirement.
6714 elsif Appears_In_Check
(Context
) then
6720 end Is_OK_Volatile_Context
;
6724 E
: constant Entity_Id
:= Entity
(N
);
6725 Par
: constant Node_Id
:= Parent
(N
);
6727 -- Start of processing for Resolve_Entity_Name
6730 -- If garbage from errors, set to Any_Type and return
6732 if No
(E
) and then Total_Errors_Detected
/= 0 then
6733 Set_Etype
(N
, Any_Type
);
6737 -- Replace named numbers by corresponding literals. Note that this is
6738 -- the one case where Resolve_Entity_Name must reset the Etype, since
6739 -- it is currently marked as universal.
6741 if Ekind
(E
) = E_Named_Integer
then
6743 Eval_Named_Integer
(N
);
6745 elsif Ekind
(E
) = E_Named_Real
then
6747 Eval_Named_Real
(N
);
6749 -- For enumeration literals, we need to make sure that a proper style
6750 -- check is done, since such literals are overloaded, and thus we did
6751 -- not do a style check during the first phase of analysis.
6753 elsif Ekind
(E
) = E_Enumeration_Literal
then
6754 Set_Entity_With_Checks
(N
, E
);
6755 Eval_Entity_Name
(N
);
6757 -- Case of subtype name appearing as an operand in expression
6759 elsif Is_Type
(E
) then
6761 -- Allow use of subtype if it is a concurrent type where we are
6762 -- currently inside the body. This will eventually be expanded into a
6763 -- call to Self (for tasks) or _object (for protected objects). Any
6764 -- other use of a subtype is invalid.
6766 if Is_Concurrent_Type
(E
)
6767 and then In_Open_Scopes
(E
)
6771 -- Any other use is an error
6775 ("invalid use of subtype mark in expression or call", N
);
6778 -- Check discriminant use if entity is discriminant in current scope,
6779 -- i.e. discriminant of record or concurrent type currently being
6780 -- analyzed. Uses in corresponding body are unrestricted.
6782 elsif Ekind
(E
) = E_Discriminant
6783 and then Scope
(E
) = Current_Scope
6784 and then not Has_Completion
(Current_Scope
)
6786 Check_Discriminant_Use
(N
);
6788 -- A parameterless generic function cannot appear in a context that
6789 -- requires resolution.
6791 elsif Ekind
(E
) = E_Generic_Function
then
6792 Error_Msg_N
("illegal use of generic function", N
);
6794 elsif Ekind
(E
) = E_Out_Parameter
6795 and then Ada_Version
= Ada_83
6796 and then (Nkind
(Parent
(N
)) in N_Op
6797 or else (Nkind
(Parent
(N
)) = N_Assignment_Statement
6798 and then N
= Expression
(Parent
(N
)))
6799 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
)
6801 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
6803 -- In all other cases, just do the possible static evaluation
6806 -- A deferred constant that appears in an expression must have a
6807 -- completion, unless it has been removed by in-place expansion of
6810 if Ekind
(E
) = E_Constant
6811 and then Comes_From_Source
(E
)
6812 and then No
(Constant_Value
(E
))
6813 and then Is_Frozen
(Etype
(E
))
6814 and then not In_Spec_Expression
6815 and then not Is_Imported
(E
)
6817 if No_Initialization
(Parent
(E
))
6818 or else (Present
(Full_View
(E
))
6819 and then No_Initialization
(Parent
(Full_View
(E
))))
6824 "deferred constant is frozen before completion", N
);
6828 Eval_Entity_Name
(N
);
6831 -- An effectively volatile object subject to enabled properties
6832 -- Async_Writers or Effective_Reads must appear in a specific context.
6833 -- The following checks are only relevant when SPARK_Mode is on as they
6834 -- are not standard Ada legality rules.
6837 and then Is_Object
(E
)
6838 and then Is_Effectively_Volatile
(E
)
6839 and then Comes_From_Source
(E
)
6841 (Async_Writers_Enabled
(E
) or else Effective_Reads_Enabled
(E
))
6843 -- The effectively volatile objects appears in a "non-interfering
6844 -- context" as defined in SPARK RM 7.1.3(13).
6846 if Is_OK_Volatile_Context
(Par
, N
) then
6849 -- Assume that references to effectively volatile objects that appear
6850 -- as actual parameters in a procedure call are always legal. The
6851 -- full legality check is done when the actuals are resolved.
6853 elsif Nkind
(Par
) = N_Procedure_Call_Statement
then
6856 -- Otherwise the context causes a side effect with respect to the
6857 -- effectively volatile object.
6861 ("volatile object cannot appear in this context "
6862 & "(SPARK RM 7.1.3(13))", N
);
6865 end Resolve_Entity_Name
;
6871 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
6872 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
6880 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
6881 -- If the bounds of the entry family being called depend on task
6882 -- discriminants, build a new index subtype where a discriminant is
6883 -- replaced with the value of the discriminant of the target task.
6884 -- The target task is the prefix of the entry name in the call.
6886 -----------------------
6887 -- Actual_Index_Type --
6888 -----------------------
6890 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
6891 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
6892 Tsk
: constant Entity_Id
:= Scope
(E
);
6893 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
6894 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
6897 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
6898 -- If the bound is given by a discriminant, replace with a reference
6899 -- to the discriminant of the same name in the target task. If the
6900 -- entry name is the target of a requeue statement and the entry is
6901 -- in the current protected object, the bound to be used is the
6902 -- discriminal of the object (see Apply_Range_Checks for details of
6903 -- the transformation).
6905 -----------------------------
6906 -- Actual_Discriminant_Ref --
6907 -----------------------------
6909 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
6910 Typ
: constant Entity_Id
:= Etype
(Bound
);
6914 Remove_Side_Effects
(Bound
);
6916 if not Is_Entity_Name
(Bound
)
6917 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
6921 elsif Is_Protected_Type
(Tsk
)
6922 and then In_Open_Scopes
(Tsk
)
6923 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
6925 -- Note: here Bound denotes a discriminant of the corresponding
6926 -- record type tskV, whose discriminal is a formal of the
6927 -- init-proc tskVIP. What we want is the body discriminal,
6928 -- which is associated to the discriminant of the original
6929 -- concurrent type tsk.
6931 return New_Occurrence_Of
6932 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
6936 Make_Selected_Component
(Loc
,
6937 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
6938 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
6943 end Actual_Discriminant_Ref
;
6945 -- Start of processing for Actual_Index_Type
6948 if not Has_Discriminants
(Tsk
)
6949 or else (not Is_Entity_Name
(Lo
) and then not Is_Entity_Name
(Hi
))
6951 return Entry_Index_Type
(E
);
6954 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
6955 Set_Etype
(New_T
, Base_Type
(Typ
));
6956 Set_Size_Info
(New_T
, Typ
);
6957 Set_RM_Size
(New_T
, RM_Size
(Typ
));
6958 Set_Scalar_Range
(New_T
,
6959 Make_Range
(Sloc
(Entry_Name
),
6960 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
6961 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
6965 end Actual_Index_Type
;
6967 -- Start of processing of Resolve_Entry
6970 -- Find name of entry being called, and resolve prefix of name with its
6971 -- own type. The prefix can be overloaded, and the name and signature of
6972 -- the entry must be taken into account.
6974 if Nkind
(Entry_Name
) = N_Indexed_Component
then
6976 -- Case of dealing with entry family within the current tasks
6978 E_Name
:= Prefix
(Entry_Name
);
6981 E_Name
:= Entry_Name
;
6984 if Is_Entity_Name
(E_Name
) then
6986 -- Entry call to an entry (or entry family) in the current task. This
6987 -- is legal even though the task will deadlock. Rewrite as call to
6990 -- This can also be a call to an entry in an enclosing task. If this
6991 -- is a single task, we have to retrieve its name, because the scope
6992 -- of the entry is the task type, not the object. If the enclosing
6993 -- task is a task type, the identity of the task is given by its own
6996 -- Finally this can be a requeue on an entry of the same task or
6997 -- protected object.
6999 S
:= Scope
(Entity
(E_Name
));
7001 for J
in reverse 0 .. Scope_Stack
.Last
loop
7002 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
7003 and then not Comes_From_Source
(S
)
7005 -- S is an enclosing task or protected object. The concurrent
7006 -- declaration has been converted into a type declaration, and
7007 -- the object itself has an object declaration that follows
7008 -- the type in the same declarative part.
7010 Tsk
:= Next_Entity
(S
);
7011 while Etype
(Tsk
) /= S
loop
7018 elsif S
= Scope_Stack
.Table
(J
).Entity
then
7020 -- Call to current task. Will be transformed into call to Self
7028 Make_Selected_Component
(Loc
,
7029 Prefix
=> New_Occurrence_Of
(S
, Loc
),
7031 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
7032 Rewrite
(E_Name
, New_N
);
7035 elsif Nkind
(Entry_Name
) = N_Selected_Component
7036 and then Is_Overloaded
(Prefix
(Entry_Name
))
7038 -- Use the entry name (which must be unique at this point) to find
7039 -- the prefix that returns the corresponding task/protected type.
7042 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
7043 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
7048 Get_First_Interp
(Pref
, I
, It
);
7049 while Present
(It
.Typ
) loop
7050 if Scope
(Ent
) = It
.Typ
then
7051 Set_Etype
(Pref
, It
.Typ
);
7055 Get_Next_Interp
(I
, It
);
7060 if Nkind
(Entry_Name
) = N_Selected_Component
then
7061 Resolve
(Prefix
(Entry_Name
));
7063 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7064 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7065 Resolve
(Prefix
(Prefix
(Entry_Name
)));
7066 Index
:= First
(Expressions
(Entry_Name
));
7067 Resolve
(Index
, Entry_Index_Type
(Nam
));
7069 -- Up to this point the expression could have been the actual in a
7070 -- simple entry call, and be given by a named association.
7072 if Nkind
(Index
) = N_Parameter_Association
then
7073 Error_Msg_N
("expect expression for entry index", Index
);
7075 Apply_Range_Check
(Index
, Actual_Index_Type
(Nam
));
7080 ------------------------
7081 -- Resolve_Entry_Call --
7082 ------------------------
7084 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
7085 Entry_Name
: constant Node_Id
:= Name
(N
);
7086 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
7088 First_Named
: Node_Id
;
7095 -- We kill all checks here, because it does not seem worth the effort to
7096 -- do anything better, an entry call is a big operation.
7100 -- Processing of the name is similar for entry calls and protected
7101 -- operation calls. Once the entity is determined, we can complete
7102 -- the resolution of the actuals.
7104 -- The selector may be overloaded, in the case of a protected object
7105 -- with overloaded functions. The type of the context is used for
7108 if Nkind
(Entry_Name
) = N_Selected_Component
7109 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
7110 and then Typ
/= Standard_Void_Type
7117 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
7118 while Present
(It
.Typ
) loop
7119 if Covers
(Typ
, It
.Typ
) then
7120 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
7121 Set_Etype
(Entry_Name
, It
.Typ
);
7123 Generate_Reference
(It
.Typ
, N
, ' ');
7126 Get_Next_Interp
(I
, It
);
7131 Resolve_Entry
(Entry_Name
);
7133 if Nkind
(Entry_Name
) = N_Selected_Component
then
7135 -- Simple entry call
7137 Nam
:= Entity
(Selector_Name
(Entry_Name
));
7138 Obj
:= Prefix
(Entry_Name
);
7139 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
7141 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
7143 -- Call to member of entry family
7145 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
7146 Obj
:= Prefix
(Prefix
(Entry_Name
));
7147 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
7150 -- We cannot in general check the maximum depth of protected entry calls
7151 -- at compile time. But we can tell that any protected entry call at all
7152 -- violates a specified nesting depth of zero.
7154 if Is_Protected_Type
(Scope
(Nam
)) then
7155 Check_Restriction
(Max_Entry_Queue_Length
, N
);
7158 -- Use context type to disambiguate a protected function that can be
7159 -- called without actuals and that returns an array type, and where the
7160 -- argument list may be an indexing of the returned value.
7162 if Ekind
(Nam
) = E_Function
7163 and then Needs_No_Actuals
(Nam
)
7164 and then Present
(Parameter_Associations
(N
))
7166 ((Is_Array_Type
(Etype
(Nam
))
7167 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
7169 or else (Is_Access_Type
(Etype
(Nam
))
7170 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
7174 Component_Type
(Designated_Type
(Etype
(Nam
))))))
7177 Index_Node
: Node_Id
;
7181 Make_Indexed_Component
(Loc
,
7183 Make_Function_Call
(Loc
, Name
=> Relocate_Node
(Entry_Name
)),
7184 Expressions
=> Parameter_Associations
(N
));
7186 -- Since we are correcting a node classification error made by the
7187 -- parser, we call Replace rather than Rewrite.
7189 Replace
(N
, Index_Node
);
7190 Set_Etype
(Prefix
(N
), Etype
(Nam
));
7192 Resolve_Indexed_Component
(N
, Typ
);
7197 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
)
7198 and then Present
(PPC_Wrapper
(Nam
))
7199 and then Current_Scope
/= PPC_Wrapper
(Nam
)
7201 -- Rewrite as call to the precondition wrapper, adding the task
7202 -- object to the list of actuals. If the call is to a member of an
7203 -- entry family, include the index as well.
7207 New_Actuals
: List_Id
;
7210 New_Actuals
:= New_List
(Obj
);
7212 if Nkind
(Entry_Name
) = N_Indexed_Component
then
7213 Append_To
(New_Actuals
,
7214 New_Copy_Tree
(First
(Expressions
(Entry_Name
))));
7217 Append_List
(Parameter_Associations
(N
), New_Actuals
);
7219 Make_Procedure_Call_Statement
(Loc
,
7221 New_Occurrence_Of
(PPC_Wrapper
(Nam
), Loc
),
7222 Parameter_Associations
=> New_Actuals
);
7223 Rewrite
(N
, New_Call
);
7225 -- Preanalyze and resolve new call. Current procedure is called
7226 -- from Resolve_Call, after which expansion will take place.
7228 Preanalyze_And_Resolve
(N
);
7233 -- The operation name may have been overloaded. Order the actuals
7234 -- according to the formals of the resolved entity, and set the return
7235 -- type to that of the operation.
7238 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
7239 pragma Assert
(Norm_OK
);
7240 Set_Etype
(N
, Etype
(Nam
));
7243 Resolve_Actuals
(N
, Nam
);
7244 Check_Internal_Protected_Use
(N
, Nam
);
7246 -- Create a call reference to the entry
7248 Generate_Reference
(Nam
, Entry_Name
, 's');
7250 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
) then
7251 Check_Potentially_Blocking_Operation
(N
);
7254 -- Verify that a procedure call cannot masquerade as an entry
7255 -- call where an entry call is expected.
7257 if Ekind
(Nam
) = E_Procedure
then
7258 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
7259 and then N
= Entry_Call_Statement
(Parent
(N
))
7261 Error_Msg_N
("entry call required in select statement", N
);
7263 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
7264 and then N
= Triggering_Statement
(Parent
(N
))
7266 Error_Msg_N
("triggering statement cannot be procedure call", N
);
7268 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
7269 and then not In_Open_Scopes
(Scope
(Nam
))
7271 Error_Msg_N
("task has no entry with this name", Entry_Name
);
7275 -- After resolution, entry calls and protected procedure calls are
7276 -- changed into entry calls, for expansion. The structure of the node
7277 -- does not change, so it can safely be done in place. Protected
7278 -- function calls must keep their structure because they are
7281 if Ekind
(Nam
) /= E_Function
then
7283 -- A protected operation that is not a function may modify the
7284 -- corresponding object, and cannot apply to a constant. If this
7285 -- is an internal call, the prefix is the type itself.
7287 if Is_Protected_Type
(Scope
(Nam
))
7288 and then not Is_Variable
(Obj
)
7289 and then (not Is_Entity_Name
(Obj
)
7290 or else not Is_Type
(Entity
(Obj
)))
7293 ("prefix of protected procedure or entry call must be variable",
7297 Actuals
:= Parameter_Associations
(N
);
7298 First_Named
:= First_Named_Actual
(N
);
7301 Make_Entry_Call_Statement
(Loc
,
7303 Parameter_Associations
=> Actuals
));
7305 Set_First_Named_Actual
(N
, First_Named
);
7306 Set_Analyzed
(N
, True);
7308 -- Protected functions can return on the secondary stack, in which
7309 -- case we must trigger the transient scope mechanism.
7311 elsif Expander_Active
7312 and then Requires_Transient_Scope
(Etype
(Nam
))
7314 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
7316 end Resolve_Entry_Call
;
7318 -------------------------
7319 -- Resolve_Equality_Op --
7320 -------------------------
7322 -- Both arguments must have the same type, and the boolean context does
7323 -- not participate in the resolution. The first pass verifies that the
7324 -- interpretation is not ambiguous, and the type of the left argument is
7325 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
7326 -- are strings or aggregates, allocators, or Null, they are ambiguous even
7327 -- though they carry a single (universal) type. Diagnose this case here.
7329 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7330 L
: constant Node_Id
:= Left_Opnd
(N
);
7331 R
: constant Node_Id
:= Right_Opnd
(N
);
7332 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
7334 procedure Check_If_Expression
(Cond
: Node_Id
);
7335 -- The resolution rule for if expressions requires that each such must
7336 -- have a unique type. This means that if several dependent expressions
7337 -- are of a non-null anonymous access type, and the context does not
7338 -- impose an expected type (as can be the case in an equality operation)
7339 -- the expression must be rejected.
7341 procedure Explain_Redundancy
(N
: Node_Id
);
7342 -- Attempt to explain the nature of a redundant comparison with True. If
7343 -- the expression N is too complex, this routine issues a general error
7346 function Find_Unique_Access_Type
return Entity_Id
;
7347 -- In the case of allocators and access attributes, the context must
7348 -- provide an indication of the specific access type to be used. If
7349 -- one operand is of such a "generic" access type, check whether there
7350 -- is a specific visible access type that has the same designated type.
7351 -- This is semantically dubious, and of no interest to any real code,
7352 -- but c48008a makes it all worthwhile.
7354 -------------------------
7355 -- Check_If_Expression --
7356 -------------------------
7358 procedure Check_If_Expression
(Cond
: Node_Id
) is
7359 Then_Expr
: Node_Id
;
7360 Else_Expr
: Node_Id
;
7363 if Nkind
(Cond
) = N_If_Expression
then
7364 Then_Expr
:= Next
(First
(Expressions
(Cond
)));
7365 Else_Expr
:= Next
(Then_Expr
);
7367 if Nkind
(Then_Expr
) /= N_Null
7368 and then Nkind
(Else_Expr
) /= N_Null
7370 Error_Msg_N
("cannot determine type of if expression", Cond
);
7373 end Check_If_Expression
;
7375 ------------------------
7376 -- Explain_Redundancy --
7377 ------------------------
7379 procedure Explain_Redundancy
(N
: Node_Id
) is
7387 -- Strip the operand down to an entity
7390 if Nkind
(Val
) = N_Selected_Component
then
7391 Val
:= Selector_Name
(Val
);
7397 -- The construct denotes an entity
7399 if Is_Entity_Name
(Val
) and then Present
(Entity
(Val
)) then
7400 Val_Id
:= Entity
(Val
);
7402 -- Do not generate an error message when the comparison is done
7403 -- against the enumeration literal Standard.True.
7405 if Ekind
(Val_Id
) /= E_Enumeration_Literal
then
7407 -- Build a customized error message
7410 Add_Str_To_Name_Buffer
("?r?");
7412 if Ekind
(Val_Id
) = E_Component
then
7413 Add_Str_To_Name_Buffer
("component ");
7415 elsif Ekind
(Val_Id
) = E_Constant
then
7416 Add_Str_To_Name_Buffer
("constant ");
7418 elsif Ekind
(Val_Id
) = E_Discriminant
then
7419 Add_Str_To_Name_Buffer
("discriminant ");
7421 elsif Is_Formal
(Val_Id
) then
7422 Add_Str_To_Name_Buffer
("parameter ");
7424 elsif Ekind
(Val_Id
) = E_Variable
then
7425 Add_Str_To_Name_Buffer
("variable ");
7428 Add_Str_To_Name_Buffer
("& is always True!");
7431 Error_Msg_NE
(Get_Name_String
(Error
), Val
, Val_Id
);
7434 -- The construct is too complex to disect, issue a general message
7437 Error_Msg_N
("?r?expression is always True!", Val
);
7439 end Explain_Redundancy
;
7441 -----------------------------
7442 -- Find_Unique_Access_Type --
7443 -----------------------------
7445 function Find_Unique_Access_Type
return Entity_Id
is
7451 if Ekind_In
(Etype
(R
), E_Allocator_Type
,
7452 E_Access_Attribute_Type
)
7454 Acc
:= Designated_Type
(Etype
(R
));
7456 elsif Ekind_In
(Etype
(L
), E_Allocator_Type
,
7457 E_Access_Attribute_Type
)
7459 Acc
:= Designated_Type
(Etype
(L
));
7465 while S
/= Standard_Standard
loop
7466 E
:= First_Entity
(S
);
7467 while Present
(E
) loop
7469 and then Is_Access_Type
(E
)
7470 and then Ekind
(E
) /= E_Allocator_Type
7471 and then Designated_Type
(E
) = Base_Type
(Acc
)
7483 end Find_Unique_Access_Type
;
7485 -- Start of processing for Resolve_Equality_Op
7488 Set_Etype
(N
, Base_Type
(Typ
));
7489 Generate_Reference
(T
, N
, ' ');
7491 if T
= Any_Fixed
then
7492 T
:= Unique_Fixed_Point_Type
(L
);
7495 if T
/= Any_Type
then
7496 if T
= Any_String
or else
7497 T
= Any_Composite
or else
7500 if T
= Any_Character
then
7501 Ambiguous_Character
(L
);
7503 Error_Msg_N
("ambiguous operands for equality", N
);
7506 Set_Etype
(N
, Any_Type
);
7509 elsif T
= Any_Access
7510 or else Ekind_In
(T
, E_Allocator_Type
, E_Access_Attribute_Type
)
7512 T
:= Find_Unique_Access_Type
;
7515 Error_Msg_N
("ambiguous operands for equality", N
);
7516 Set_Etype
(N
, Any_Type
);
7520 -- If expressions must have a single type, and if the context does
7521 -- not impose one the dependent expressions cannot be anonymous
7524 -- Why no similar processing for case expressions???
7526 elsif Ada_Version
>= Ada_2012
7527 and then Ekind_In
(Etype
(L
), E_Anonymous_Access_Type
,
7528 E_Anonymous_Access_Subprogram_Type
)
7529 and then Ekind_In
(Etype
(R
), E_Anonymous_Access_Type
,
7530 E_Anonymous_Access_Subprogram_Type
)
7532 Check_If_Expression
(L
);
7533 Check_If_Expression
(R
);
7539 -- In SPARK, equality operators = and /= for array types other than
7540 -- String are only defined when, for each index position, the
7541 -- operands have equal static bounds.
7543 if Is_Array_Type
(T
) then
7545 -- Protect call to Matching_Static_Array_Bounds to avoid costly
7546 -- operation if not needed.
7548 if Restriction_Check_Required
(SPARK_05
)
7549 and then Base_Type
(T
) /= Standard_String
7550 and then Base_Type
(Etype
(L
)) = Base_Type
(Etype
(R
))
7551 and then Etype
(L
) /= Any_Composite
-- or else L in error
7552 and then Etype
(R
) /= Any_Composite
-- or else R in error
7553 and then not Matching_Static_Array_Bounds
(Etype
(L
), Etype
(R
))
7555 Check_SPARK_05_Restriction
7556 ("array types should have matching static bounds", N
);
7560 -- If the unique type is a class-wide type then it will be expanded
7561 -- into a dispatching call to the predefined primitive. Therefore we
7562 -- check here for potential violation of such restriction.
7564 if Is_Class_Wide_Type
(T
) then
7565 Check_Restriction
(No_Dispatching_Calls
, N
);
7568 if Warn_On_Redundant_Constructs
7569 and then Comes_From_Source
(N
)
7570 and then Comes_From_Source
(R
)
7571 and then Is_Entity_Name
(R
)
7572 and then Entity
(R
) = Standard_True
7574 Error_Msg_N
-- CODEFIX
7575 ("?r?comparison with True is redundant!", N
);
7576 Explain_Redundancy
(Original_Node
(R
));
7579 Check_Unset_Reference
(L
);
7580 Check_Unset_Reference
(R
);
7581 Generate_Operator_Reference
(N
, T
);
7582 Check_Low_Bound_Tested
(N
);
7584 -- If this is an inequality, it may be the implicit inequality
7585 -- created for a user-defined operation, in which case the corres-
7586 -- ponding equality operation is not intrinsic, and the operation
7587 -- cannot be constant-folded. Else fold.
7589 if Nkind
(N
) = N_Op_Eq
7590 or else Comes_From_Source
(Entity
(N
))
7591 or else Ekind
(Entity
(N
)) = E_Operator
7592 or else Is_Intrinsic_Subprogram
7593 (Corresponding_Equality
(Entity
(N
)))
7595 Analyze_Dimension
(N
);
7596 Eval_Relational_Op
(N
);
7598 elsif Nkind
(N
) = N_Op_Ne
7599 and then Is_Abstract_Subprogram
(Entity
(N
))
7601 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Entity
(N
));
7604 -- Ada 2005: If one operand is an anonymous access type, convert the
7605 -- other operand to it, to ensure that the underlying types match in
7606 -- the back-end. Same for access_to_subprogram, and the conversion
7607 -- verifies that the types are subtype conformant.
7609 -- We apply the same conversion in the case one of the operands is a
7610 -- private subtype of the type of the other.
7612 -- Why the Expander_Active test here ???
7616 (Ekind_In
(T
, E_Anonymous_Access_Type
,
7617 E_Anonymous_Access_Subprogram_Type
)
7618 or else Is_Private_Type
(T
))
7620 if Etype
(L
) /= T
then
7622 Make_Unchecked_Type_Conversion
(Sloc
(L
),
7623 Subtype_Mark
=> New_Occurrence_Of
(T
, Sloc
(L
)),
7624 Expression
=> Relocate_Node
(L
)));
7625 Analyze_And_Resolve
(L
, T
);
7628 if (Etype
(R
)) /= T
then
7630 Make_Unchecked_Type_Conversion
(Sloc
(R
),
7631 Subtype_Mark
=> New_Occurrence_Of
(Etype
(L
), Sloc
(R
)),
7632 Expression
=> Relocate_Node
(R
)));
7633 Analyze_And_Resolve
(R
, T
);
7637 end Resolve_Equality_Op
;
7639 ----------------------------------
7640 -- Resolve_Explicit_Dereference --
7641 ----------------------------------
7643 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
7644 Loc
: constant Source_Ptr
:= Sloc
(N
);
7646 P
: constant Node_Id
:= Prefix
(N
);
7649 -- The candidate prefix type, if overloaded
7655 Check_Fully_Declared_Prefix
(Typ
, P
);
7658 -- A useful optimization: check whether the dereference denotes an
7659 -- element of a container, and if so rewrite it as a call to the
7660 -- corresponding Element function.
7662 -- Disabled for now, on advice of ARG. A more restricted form of the
7663 -- predicate might be acceptable ???
7665 -- if Is_Container_Element (N) then
7669 if Is_Overloaded
(P
) then
7671 -- Use the context type to select the prefix that has the correct
7672 -- designated type. Keep the first match, which will be the inner-
7675 Get_First_Interp
(P
, I
, It
);
7677 while Present
(It
.Typ
) loop
7678 if Is_Access_Type
(It
.Typ
)
7679 and then Covers
(Typ
, Designated_Type
(It
.Typ
))
7685 -- Remove access types that do not match, but preserve access
7686 -- to subprogram interpretations, in case a further dereference
7687 -- is needed (see below).
7689 elsif Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7693 Get_Next_Interp
(I
, It
);
7696 if Present
(P_Typ
) then
7698 Set_Etype
(N
, Designated_Type
(P_Typ
));
7701 -- If no interpretation covers the designated type of the prefix,
7702 -- this is the pathological case where not all implementations of
7703 -- the prefix allow the interpretation of the node as a call. Now
7704 -- that the expected type is known, Remove other interpretations
7705 -- from prefix, rewrite it as a call, and resolve again, so that
7706 -- the proper call node is generated.
7708 Get_First_Interp
(P
, I
, It
);
7709 while Present
(It
.Typ
) loop
7710 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
7714 Get_Next_Interp
(I
, It
);
7718 Make_Function_Call
(Loc
,
7720 Make_Explicit_Dereference
(Loc
,
7722 Parameter_Associations
=> New_List
);
7724 Save_Interps
(N
, New_N
);
7726 Analyze_And_Resolve
(N
, Typ
);
7730 -- If not overloaded, resolve P with its own type
7736 if Is_Access_Type
(Etype
(P
)) then
7737 Apply_Access_Check
(N
);
7740 -- If the designated type is a packed unconstrained array type, and the
7741 -- explicit dereference is not in the context of an attribute reference,
7742 -- then we must compute and set the actual subtype, since it is needed
7743 -- by Gigi. The reason we exclude the attribute case is that this is
7744 -- handled fine by Gigi, and in fact we use such attributes to build the
7745 -- actual subtype. We also exclude generated code (which builds actual
7746 -- subtypes directly if they are needed).
7748 if Is_Array_Type
(Etype
(N
))
7749 and then Is_Packed
(Etype
(N
))
7750 and then not Is_Constrained
(Etype
(N
))
7751 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
7752 and then Comes_From_Source
(N
)
7754 Set_Etype
(N
, Get_Actual_Subtype
(N
));
7757 -- Note: No Eval processing is required for an explicit dereference,
7758 -- because such a name can never be static.
7760 end Resolve_Explicit_Dereference
;
7762 -------------------------------------
7763 -- Resolve_Expression_With_Actions --
7764 -------------------------------------
7766 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
7770 -- If N has no actions, and its expression has been constant folded,
7771 -- then rewrite N as just its expression. Note, we can't do this in
7772 -- the general case of Is_Empty_List (Actions (N)) as this would cause
7773 -- Expression (N) to be expanded again.
7775 if Is_Empty_List
(Actions
(N
))
7776 and then Compile_Time_Known_Value
(Expression
(N
))
7778 Rewrite
(N
, Expression
(N
));
7780 end Resolve_Expression_With_Actions
;
7782 ----------------------------------
7783 -- Resolve_Generalized_Indexing --
7784 ----------------------------------
7786 procedure Resolve_Generalized_Indexing
(N
: Node_Id
; Typ
: Entity_Id
) is
7787 Indexing
: constant Node_Id
:= Generalized_Indexing
(N
);
7793 -- In ASIS mode, propagate the information about the indices back to
7794 -- to the original indexing node. The generalized indexing is either
7795 -- a function call, or a dereference of one. The actuals include the
7796 -- prefix of the original node, which is the container expression.
7799 Resolve
(Indexing
, Typ
);
7800 Set_Etype
(N
, Etype
(Indexing
));
7801 Set_Is_Overloaded
(N
, False);
7804 while Nkind_In
(Call
, N_Explicit_Dereference
, N_Selected_Component
)
7806 Call
:= Prefix
(Call
);
7809 if Nkind
(Call
) = N_Function_Call
then
7810 Indices
:= Parameter_Associations
(Call
);
7811 Pref
:= Remove_Head
(Indices
);
7812 Set_Expressions
(N
, Indices
);
7813 Set_Prefix
(N
, Pref
);
7817 Rewrite
(N
, Indexing
);
7820 end Resolve_Generalized_Indexing
;
7822 ---------------------------
7823 -- Resolve_If_Expression --
7824 ---------------------------
7826 procedure Resolve_If_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7827 Condition
: constant Node_Id
:= First
(Expressions
(N
));
7828 Then_Expr
: constant Node_Id
:= Next
(Condition
);
7829 Else_Expr
: Node_Id
:= Next
(Then_Expr
);
7830 Else_Typ
: Entity_Id
;
7831 Then_Typ
: Entity_Id
;
7834 Resolve
(Condition
, Any_Boolean
);
7835 Resolve
(Then_Expr
, Typ
);
7836 Then_Typ
:= Etype
(Then_Expr
);
7838 -- When the "then" expression is of a scalar subtype different from the
7839 -- result subtype, then insert a conversion to ensure the generation of
7840 -- a constraint check. The same is done for the else part below, again
7841 -- comparing subtypes rather than base types.
7843 if Is_Scalar_Type
(Then_Typ
)
7844 and then Then_Typ
/= Typ
7846 Rewrite
(Then_Expr
, Convert_To
(Typ
, Then_Expr
));
7847 Analyze_And_Resolve
(Then_Expr
, Typ
);
7850 -- If ELSE expression present, just resolve using the determined type
7852 if Present
(Else_Expr
) then
7853 Resolve
(Else_Expr
, Typ
);
7854 Else_Typ
:= Etype
(Else_Expr
);
7856 if Is_Scalar_Type
(Else_Typ
)
7857 and then Else_Typ
/= Typ
7859 Rewrite
(Else_Expr
, Convert_To
(Typ
, Else_Expr
));
7860 Analyze_And_Resolve
(Else_Expr
, Typ
);
7863 -- If no ELSE expression is present, root type must be Standard.Boolean
7864 -- and we provide a Standard.True result converted to the appropriate
7865 -- Boolean type (in case it is a derived boolean type).
7867 elsif Root_Type
(Typ
) = Standard_Boolean
then
7869 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
7870 Analyze_And_Resolve
(Else_Expr
, Typ
);
7871 Append_To
(Expressions
(N
), Else_Expr
);
7874 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
7875 Append_To
(Expressions
(N
), Error
);
7879 Eval_If_Expression
(N
);
7880 end Resolve_If_Expression
;
7882 -------------------------------
7883 -- Resolve_Indexed_Component --
7884 -------------------------------
7886 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
7887 Name
: constant Node_Id
:= Prefix
(N
);
7889 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
7893 if Present
(Generalized_Indexing
(N
)) then
7894 Resolve_Generalized_Indexing
(N
, Typ
);
7898 if Is_Overloaded
(Name
) then
7900 -- Use the context type to select the prefix that yields the correct
7906 I1
: Interp_Index
:= 0;
7907 P
: constant Node_Id
:= Prefix
(N
);
7908 Found
: Boolean := False;
7911 Get_First_Interp
(P
, I
, It
);
7912 while Present
(It
.Typ
) loop
7913 if (Is_Array_Type
(It
.Typ
)
7914 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
7915 or else (Is_Access_Type
(It
.Typ
)
7916 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
7920 Component_Type
(Designated_Type
(It
.Typ
))))
7923 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
7925 if It
= No_Interp
then
7926 Error_Msg_N
("ambiguous prefix for indexing", N
);
7932 Array_Type
:= It
.Typ
;
7938 Array_Type
:= It
.Typ
;
7943 Get_Next_Interp
(I
, It
);
7948 Array_Type
:= Etype
(Name
);
7951 Resolve
(Name
, Array_Type
);
7952 Array_Type
:= Get_Actual_Subtype_If_Available
(Name
);
7954 -- If prefix is access type, dereference to get real array type.
7955 -- Note: we do not apply an access check because the expander always
7956 -- introduces an explicit dereference, and the check will happen there.
7958 if Is_Access_Type
(Array_Type
) then
7959 Array_Type
:= Designated_Type
(Array_Type
);
7962 -- If name was overloaded, set component type correctly now
7963 -- If a misplaced call to an entry family (which has no index types)
7964 -- return. Error will be diagnosed from calling context.
7966 if Is_Array_Type
(Array_Type
) then
7967 Set_Etype
(N
, Component_Type
(Array_Type
));
7972 Index
:= First_Index
(Array_Type
);
7973 Expr
:= First
(Expressions
(N
));
7975 -- The prefix may have resolved to a string literal, in which case its
7976 -- etype has a special representation. This is only possible currently
7977 -- if the prefix is a static concatenation, written in functional
7980 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
7981 Resolve
(Expr
, Standard_Positive
);
7984 while Present
(Index
) and Present
(Expr
) loop
7985 Resolve
(Expr
, Etype
(Index
));
7986 Check_Unset_Reference
(Expr
);
7988 if Is_Scalar_Type
(Etype
(Expr
)) then
7989 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
7991 Apply_Range_Check
(Expr
, Get_Actual_Subtype
(Index
));
7999 Analyze_Dimension
(N
);
8001 -- Do not generate the warning on suspicious index if we are analyzing
8002 -- package Ada.Tags; otherwise we will report the warning with the
8003 -- Prims_Ptr field of the dispatch table.
8005 if Scope
(Etype
(Prefix
(N
))) = Standard_Standard
8007 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Prefix
(N
)))),
8010 Warn_On_Suspicious_Index
(Name
, First
(Expressions
(N
)));
8011 Eval_Indexed_Component
(N
);
8014 -- If the array type is atomic, and the component is not atomic, then
8015 -- this is worth a warning, since we have a situation where the access
8016 -- to the component may cause extra read/writes of the atomic array
8017 -- object, or partial word accesses, which could be unexpected.
8019 if Nkind
(N
) = N_Indexed_Component
8020 and then Is_Atomic_Ref_With_Address
(N
)
8021 and then not (Has_Atomic_Components
(Array_Type
)
8022 or else (Is_Entity_Name
(Prefix
(N
))
8023 and then Has_Atomic_Components
8024 (Entity
(Prefix
(N
)))))
8025 and then not Is_Atomic
(Component_Type
(Array_Type
))
8027 Error_Msg_N
("??access to non-atomic component of atomic array",
8029 Error_Msg_N
("??\may cause unexpected accesses to atomic object",
8032 end Resolve_Indexed_Component
;
8034 -----------------------------
8035 -- Resolve_Integer_Literal --
8036 -----------------------------
8038 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
8041 Eval_Integer_Literal
(N
);
8042 end Resolve_Integer_Literal
;
8044 --------------------------------
8045 -- Resolve_Intrinsic_Operator --
8046 --------------------------------
8048 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
8049 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8054 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
;
8055 -- If the operand is a literal, it cannot be the expression in a
8056 -- conversion. Use a qualified expression instead.
8058 function Convert_Operand
(Opnd
: Node_Id
) return Node_Id
is
8059 Loc
: constant Source_Ptr
:= Sloc
(Opnd
);
8062 if Nkind_In
(Opnd
, N_Integer_Literal
, N_Real_Literal
) then
8064 Make_Qualified_Expression
(Loc
,
8065 Subtype_Mark
=> New_Occurrence_Of
(Btyp
, Loc
),
8066 Expression
=> Relocate_Node
(Opnd
));
8070 Res
:= Unchecked_Convert_To
(Btyp
, Opnd
);
8074 end Convert_Operand
;
8076 -- Start of processing for Resolve_Intrinsic_Operator
8079 -- We must preserve the original entity in a generic setting, so that
8080 -- the legality of the operation can be verified in an instance.
8082 if not Expander_Active
then
8087 while Scope
(Op
) /= Standard_Standard
loop
8089 pragma Assert
(Present
(Op
));
8093 Set_Is_Overloaded
(N
, False);
8095 -- If the result or operand types are private, rewrite with unchecked
8096 -- conversions on the operands and the result, to expose the proper
8097 -- underlying numeric type.
8099 if Is_Private_Type
(Typ
)
8100 or else Is_Private_Type
(Etype
(Left_Opnd
(N
)))
8101 or else Is_Private_Type
(Etype
(Right_Opnd
(N
)))
8103 Arg1
:= Convert_Operand
(Left_Opnd
(N
));
8104 -- Unchecked_Convert_To (Btyp, Left_Opnd (N));
8105 -- What on earth is this commented out fragment of code???
8107 if Nkind
(N
) = N_Op_Expon
then
8108 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
8110 Arg2
:= Convert_Operand
(Right_Opnd
(N
));
8113 if Nkind
(Arg1
) = N_Type_Conversion
then
8114 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8117 if Nkind
(Arg2
) = N_Type_Conversion
then
8118 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8121 Set_Left_Opnd
(N
, Arg1
);
8122 Set_Right_Opnd
(N
, Arg2
);
8124 Set_Etype
(N
, Btyp
);
8125 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8128 elsif Typ
/= Etype
(Left_Opnd
(N
))
8129 or else Typ
/= Etype
(Right_Opnd
(N
))
8131 -- Add explicit conversion where needed, and save interpretations in
8132 -- case operands are overloaded.
8134 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
8135 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
8137 if Nkind
(Arg1
) = N_Type_Conversion
then
8138 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
8140 Save_Interps
(Left_Opnd
(N
), Arg1
);
8143 if Nkind
(Arg2
) = N_Type_Conversion
then
8144 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8146 Save_Interps
(Right_Opnd
(N
), Arg2
);
8149 Rewrite
(Left_Opnd
(N
), Arg1
);
8150 Rewrite
(Right_Opnd
(N
), Arg2
);
8153 Resolve_Arithmetic_Op
(N
, Typ
);
8156 Resolve_Arithmetic_Op
(N
, Typ
);
8158 end Resolve_Intrinsic_Operator
;
8160 --------------------------------------
8161 -- Resolve_Intrinsic_Unary_Operator --
8162 --------------------------------------
8164 procedure Resolve_Intrinsic_Unary_Operator
8168 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
8174 while Scope
(Op
) /= Standard_Standard
loop
8176 pragma Assert
(Present
(Op
));
8181 if Is_Private_Type
(Typ
) then
8182 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
8183 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
8185 Set_Right_Opnd
(N
, Arg2
);
8187 Set_Etype
(N
, Btyp
);
8188 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
8192 Resolve_Unary_Op
(N
, Typ
);
8194 end Resolve_Intrinsic_Unary_Operator
;
8196 ------------------------
8197 -- Resolve_Logical_Op --
8198 ------------------------
8200 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8204 Check_No_Direct_Boolean_Operators
(N
);
8206 -- Predefined operations on scalar types yield the base type. On the
8207 -- other hand, logical operations on arrays yield the type of the
8208 -- arguments (and the context).
8210 if Is_Array_Type
(Typ
) then
8213 B_Typ
:= Base_Type
(Typ
);
8216 -- The following test is required because the operands of the operation
8217 -- may be literals, in which case the resulting type appears to be
8218 -- compatible with a signed integer type, when in fact it is compatible
8219 -- only with modular types. If the context itself is universal, the
8220 -- operation is illegal.
8222 if not Valid_Boolean_Arg
(Typ
) then
8223 Error_Msg_N
("invalid context for logical operation", N
);
8224 Set_Etype
(N
, Any_Type
);
8227 elsif Typ
= Any_Modular
then
8229 ("no modular type available in this context", N
);
8230 Set_Etype
(N
, Any_Type
);
8233 elsif Is_Modular_Integer_Type
(Typ
)
8234 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
8235 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
8237 Check_For_Visible_Operator
(N
, B_Typ
);
8240 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
8241 -- is active and the result type is standard Boolean (do not mess with
8242 -- ops that return a nonstandard Boolean type, because something strange
8245 -- Note: you might expect this replacement to be done during expansion,
8246 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
8247 -- is used, no part of the right operand of an "and" or "or" operator
8248 -- should be executed if the left operand would short-circuit the
8249 -- evaluation of the corresponding "and then" or "or else". If we left
8250 -- the replacement to expansion time, then run-time checks associated
8251 -- with such operands would be evaluated unconditionally, due to being
8252 -- before the condition prior to the rewriting as short-circuit forms
8253 -- during expansion.
8255 if Short_Circuit_And_Or
8256 and then B_Typ
= Standard_Boolean
8257 and then Nkind_In
(N
, N_Op_And
, N_Op_Or
)
8259 if Nkind
(N
) = N_Op_And
then
8261 Make_And_Then
(Sloc
(N
),
8262 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8263 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8264 Analyze_And_Resolve
(N
, B_Typ
);
8266 -- Case of OR changed to OR ELSE
8270 Make_Or_Else
(Sloc
(N
),
8271 Left_Opnd
=> Relocate_Node
(Left_Opnd
(N
)),
8272 Right_Opnd
=> Relocate_Node
(Right_Opnd
(N
))));
8273 Analyze_And_Resolve
(N
, B_Typ
);
8276 -- Return now, since analysis of the rewritten ops will take care of
8277 -- other reference bookkeeping and expression folding.
8282 Resolve
(Left_Opnd
(N
), B_Typ
);
8283 Resolve
(Right_Opnd
(N
), B_Typ
);
8285 Check_Unset_Reference
(Left_Opnd
(N
));
8286 Check_Unset_Reference
(Right_Opnd
(N
));
8288 Set_Etype
(N
, B_Typ
);
8289 Generate_Operator_Reference
(N
, B_Typ
);
8290 Eval_Logical_Op
(N
);
8292 -- In SPARK, logical operations AND, OR and XOR for arrays are defined
8293 -- only when both operands have same static lower and higher bounds. Of
8294 -- course the types have to match, so only check if operands are
8295 -- compatible and the node itself has no errors.
8297 if Is_Array_Type
(B_Typ
)
8298 and then Nkind
(N
) in N_Binary_Op
8301 Left_Typ
: constant Node_Id
:= Etype
(Left_Opnd
(N
));
8302 Right_Typ
: constant Node_Id
:= Etype
(Right_Opnd
(N
));
8305 -- Protect call to Matching_Static_Array_Bounds to avoid costly
8306 -- operation if not needed.
8308 if Restriction_Check_Required
(SPARK_05
)
8309 and then Base_Type
(Left_Typ
) = Base_Type
(Right_Typ
)
8310 and then Left_Typ
/= Any_Composite
-- or Left_Opnd in error
8311 and then Right_Typ
/= Any_Composite
-- or Right_Opnd in error
8312 and then not Matching_Static_Array_Bounds
(Left_Typ
, Right_Typ
)
8314 Check_SPARK_05_Restriction
8315 ("array types should have matching static bounds", N
);
8320 Check_Function_Writable_Actuals
(N
);
8321 end Resolve_Logical_Op
;
8323 ---------------------------
8324 -- Resolve_Membership_Op --
8325 ---------------------------
8327 -- The context can only be a boolean type, and does not determine the
8328 -- arguments. Arguments should be unambiguous, but the preference rule for
8329 -- universal types applies.
8331 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8332 pragma Warnings
(Off
, Typ
);
8334 L
: constant Node_Id
:= Left_Opnd
(N
);
8335 R
: constant Node_Id
:= Right_Opnd
(N
);
8338 procedure Resolve_Set_Membership
;
8339 -- Analysis has determined a unique type for the left operand. Use it to
8340 -- resolve the disjuncts.
8342 ----------------------------
8343 -- Resolve_Set_Membership --
8344 ----------------------------
8346 procedure Resolve_Set_Membership
is
8348 Ltyp
: constant Entity_Id
:= Etype
(L
);
8353 Alt
:= First
(Alternatives
(N
));
8354 while Present
(Alt
) loop
8356 -- Alternative is an expression, a range
8357 -- or a subtype mark.
8359 if not Is_Entity_Name
(Alt
)
8360 or else not Is_Type
(Entity
(Alt
))
8362 Resolve
(Alt
, Ltyp
);
8368 -- Check for duplicates for discrete case
8370 if Is_Discrete_Type
(Ltyp
) then
8377 Alts
: array (0 .. List_Length
(Alternatives
(N
))) of Ent
;
8381 -- Loop checking duplicates. This is quadratic, but giant sets
8382 -- are unlikely in this context so it's a reasonable choice.
8385 Alt
:= First
(Alternatives
(N
));
8386 while Present
(Alt
) loop
8387 if Is_OK_Static_Expression
(Alt
)
8388 and then (Nkind_In
(Alt
, N_Integer_Literal
,
8389 N_Character_Literal
)
8390 or else Nkind
(Alt
) in N_Has_Entity
)
8393 Alts
(Nalts
) := (Alt
, Expr_Value
(Alt
));
8395 for J
in 1 .. Nalts
- 1 loop
8396 if Alts
(J
).Val
= Alts
(Nalts
).Val
then
8397 Error_Msg_Sloc
:= Sloc
(Alts
(J
).Alt
);
8398 Error_Msg_N
("duplicate of value given#??", Alt
);
8407 end Resolve_Set_Membership
;
8409 -- Start of processing for Resolve_Membership_Op
8412 if L
= Error
or else R
= Error
then
8416 if Present
(Alternatives
(N
)) then
8417 Resolve_Set_Membership
;
8420 elsif not Is_Overloaded
(R
)
8422 (Etype
(R
) = Universal_Integer
8424 Etype
(R
) = Universal_Real
)
8425 and then Is_Overloaded
(L
)
8429 -- Ada 2005 (AI-251): Support the following case:
8431 -- type I is interface;
8432 -- type T is tagged ...
8434 -- function Test (O : I'Class) is
8436 -- return O in T'Class.
8439 -- In this case we have nothing else to do. The membership test will be
8440 -- done at run time.
8442 elsif Ada_Version
>= Ada_2005
8443 and then Is_Class_Wide_Type
(Etype
(L
))
8444 and then Is_Interface
(Etype
(L
))
8445 and then Is_Class_Wide_Type
(Etype
(R
))
8446 and then not Is_Interface
(Etype
(R
))
8450 T
:= Intersect_Types
(L
, R
);
8453 -- If mixed-mode operations are present and operands are all literal,
8454 -- the only interpretation involves Duration, which is probably not
8455 -- the intention of the programmer.
8457 if T
= Any_Fixed
then
8458 T
:= Unique_Fixed_Point_Type
(N
);
8460 if T
= Any_Type
then
8466 Check_Unset_Reference
(L
);
8468 if Nkind
(R
) = N_Range
8469 and then not Is_Scalar_Type
(T
)
8471 Error_Msg_N
("scalar type required for range", R
);
8474 if Is_Entity_Name
(R
) then
8475 Freeze_Expression
(R
);
8478 Check_Unset_Reference
(R
);
8481 -- Here after resolving membership operation
8485 Eval_Membership_Op
(N
);
8486 Check_Function_Writable_Actuals
(N
);
8487 end Resolve_Membership_Op
;
8493 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
8494 Loc
: constant Source_Ptr
:= Sloc
(N
);
8497 -- Handle restriction against anonymous null access values This
8498 -- restriction can be turned off using -gnatdj.
8500 -- Ada 2005 (AI-231): Remove restriction
8502 if Ada_Version
< Ada_2005
8503 and then not Debug_Flag_J
8504 and then Ekind
(Typ
) = E_Anonymous_Access_Type
8505 and then Comes_From_Source
(N
)
8507 -- In the common case of a call which uses an explicitly null value
8508 -- for an access parameter, give specialized error message.
8510 if Nkind
(Parent
(N
)) in N_Subprogram_Call
then
8512 ("null is not allowed as argument for an access parameter", N
);
8514 -- Standard message for all other cases (are there any?)
8518 ("null cannot be of an anonymous access type", N
);
8522 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
8523 -- assignment to a null-excluding object
8525 if Ada_Version
>= Ada_2005
8526 and then Can_Never_Be_Null
(Typ
)
8527 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
8529 if not Inside_Init_Proc
then
8531 (Compile_Time_Constraint_Error
(N
,
8532 "(Ada 2005) null not allowed in null-excluding objects??"),
8533 Make_Raise_Constraint_Error
(Loc
,
8534 Reason
=> CE_Access_Check_Failed
));
8537 Make_Raise_Constraint_Error
(Loc
,
8538 Reason
=> CE_Access_Check_Failed
));
8542 -- In a distributed context, null for a remote access to subprogram may
8543 -- need to be replaced with a special record aggregate. In this case,
8544 -- return after having done the transformation.
8546 if (Ekind
(Typ
) = E_Record_Type
8547 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
8548 and then Remote_AST_Null_Value
(N
, Typ
)
8553 -- The null literal takes its type from the context
8558 -----------------------
8559 -- Resolve_Op_Concat --
8560 -----------------------
8562 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
8564 -- We wish to avoid deep recursion, because concatenations are often
8565 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
8566 -- operands nonrecursively until we find something that is not a simple
8567 -- concatenation (A in this case). We resolve that, and then walk back
8568 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
8569 -- to do the rest of the work at each level. The Parent pointers allow
8570 -- us to avoid recursion, and thus avoid running out of memory. See also
8571 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
8577 -- The following code is equivalent to:
8579 -- Resolve_Op_Concat_First (NN, Typ);
8580 -- Resolve_Op_Concat_Arg (N, ...);
8581 -- Resolve_Op_Concat_Rest (N, Typ);
8583 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
8584 -- operand is a concatenation.
8586 -- Walk down left operands
8589 Resolve_Op_Concat_First
(NN
, Typ
);
8590 Op1
:= Left_Opnd
(NN
);
8591 exit when not (Nkind
(Op1
) = N_Op_Concat
8592 and then not Is_Array_Type
(Component_Type
(Typ
))
8593 and then Entity
(Op1
) = Entity
(NN
));
8597 -- Now (given the above example) NN is A&B and Op1 is A
8599 -- First resolve Op1 ...
8601 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
8603 -- ... then walk NN back up until we reach N (where we started), calling
8604 -- Resolve_Op_Concat_Rest along the way.
8607 Resolve_Op_Concat_Rest
(NN
, Typ
);
8612 if Base_Type
(Etype
(N
)) /= Standard_String
then
8613 Check_SPARK_05_Restriction
8614 ("result of concatenation should have type String", N
);
8616 end Resolve_Op_Concat
;
8618 ---------------------------
8619 -- Resolve_Op_Concat_Arg --
8620 ---------------------------
8622 procedure Resolve_Op_Concat_Arg
8628 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8629 Ctyp
: constant Entity_Id
:= Component_Type
(Typ
);
8634 or else (not Is_Overloaded
(Arg
)
8635 and then Etype
(Arg
) /= Any_Composite
8636 and then Covers
(Ctyp
, Etype
(Arg
)))
8638 Resolve
(Arg
, Ctyp
);
8640 Resolve
(Arg
, Btyp
);
8643 -- If both Array & Array and Array & Component are visible, there is a
8644 -- potential ambiguity that must be reported.
8646 elsif Has_Compatible_Type
(Arg
, Ctyp
) then
8647 if Nkind
(Arg
) = N_Aggregate
8648 and then Is_Composite_Type
(Ctyp
)
8650 if Is_Private_Type
(Ctyp
) then
8651 Resolve
(Arg
, Btyp
);
8653 -- If the operation is user-defined and not overloaded use its
8654 -- profile. The operation may be a renaming, in which case it has
8655 -- been rewritten, and we want the original profile.
8657 elsif not Is_Overloaded
(N
)
8658 and then Comes_From_Source
(Entity
(Original_Node
(N
)))
8659 and then Ekind
(Entity
(Original_Node
(N
))) = E_Function
8663 (Next_Formal
(First_Formal
(Entity
(Original_Node
(N
))))));
8666 -- Otherwise an aggregate may match both the array type and the
8670 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
8671 Set_Etype
(Arg
, Any_Type
);
8675 if Is_Overloaded
(Arg
)
8676 and then Has_Compatible_Type
(Arg
, Typ
)
8677 and then Etype
(Arg
) /= Any_Type
8685 Get_First_Interp
(Arg
, I
, It
);
8687 Get_Next_Interp
(I
, It
);
8689 -- Special-case the error message when the overloading is
8690 -- caused by a function that yields an array and can be
8691 -- called without parameters.
8693 if It
.Nam
= Func
then
8694 Error_Msg_Sloc
:= Sloc
(Func
);
8695 Error_Msg_N
("ambiguous call to function#", Arg
);
8697 ("\\interpretation as call yields&", Arg
, Typ
);
8699 ("\\interpretation as indexing of call yields&",
8700 Arg
, Component_Type
(Typ
));
8703 Error_Msg_N
("ambiguous operand for concatenation!", Arg
);
8705 Get_First_Interp
(Arg
, I
, It
);
8706 while Present
(It
.Nam
) loop
8707 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
8709 if Base_Type
(It
.Typ
) = Btyp
8711 Base_Type
(It
.Typ
) = Base_Type
(Ctyp
)
8713 Error_Msg_N
-- CODEFIX
8714 ("\\possible interpretation#", Arg
);
8717 Get_Next_Interp
(I
, It
);
8723 Resolve
(Arg
, Component_Type
(Typ
));
8725 if Nkind
(Arg
) = N_String_Literal
then
8726 Set_Etype
(Arg
, Component_Type
(Typ
));
8729 if Arg
= Left_Opnd
(N
) then
8730 Set_Is_Component_Left_Opnd
(N
);
8732 Set_Is_Component_Right_Opnd
(N
);
8737 Resolve
(Arg
, Btyp
);
8740 -- Concatenation is restricted in SPARK: each operand must be either a
8741 -- string literal, the name of a string constant, a static character or
8742 -- string expression, or another concatenation. Arg cannot be a
8743 -- concatenation here as callers of Resolve_Op_Concat_Arg call it
8744 -- separately on each final operand, past concatenation operations.
8746 if Is_Character_Type
(Etype
(Arg
)) then
8747 if not Is_OK_Static_Expression
(Arg
) then
8748 Check_SPARK_05_Restriction
8749 ("character operand for concatenation should be static", Arg
);
8752 elsif Is_String_Type
(Etype
(Arg
)) then
8753 if not (Nkind_In
(Arg
, N_Identifier
, N_Expanded_Name
)
8754 and then Is_Constant_Object
(Entity
(Arg
)))
8755 and then not Is_OK_Static_Expression
(Arg
)
8757 Check_SPARK_05_Restriction
8758 ("string operand for concatenation should be static", Arg
);
8761 -- Do not issue error on an operand that is neither a character nor a
8762 -- string, as the error is issued in Resolve_Op_Concat.
8768 Check_Unset_Reference
(Arg
);
8769 end Resolve_Op_Concat_Arg
;
8771 -----------------------------
8772 -- Resolve_Op_Concat_First --
8773 -----------------------------
8775 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
8776 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
8777 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8778 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8781 -- The parser folds an enormous sequence of concatenations of string
8782 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
8783 -- in the right operand. If the expression resolves to a predefined "&"
8784 -- operator, all is well. Otherwise, the parser's folding is wrong, so
8785 -- we give an error. See P_Simple_Expression in Par.Ch4.
8787 if Nkind
(Op2
) = N_String_Literal
8788 and then Is_Folded_In_Parser
(Op2
)
8789 and then Ekind
(Entity
(N
)) = E_Function
8791 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
8792 and then String_Length
(Strval
(Op1
)) = 0);
8793 Error_Msg_N
("too many user-defined concatenations", N
);
8797 Set_Etype
(N
, Btyp
);
8799 if Is_Limited_Composite
(Btyp
) then
8800 Error_Msg_N
("concatenation not available for limited array", N
);
8801 Explain_Limited_Type
(Btyp
, N
);
8803 end Resolve_Op_Concat_First
;
8805 ----------------------------
8806 -- Resolve_Op_Concat_Rest --
8807 ----------------------------
8809 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
8810 Op1
: constant Node_Id
:= Left_Opnd
(N
);
8811 Op2
: constant Node_Id
:= Right_Opnd
(N
);
8814 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
8816 Generate_Operator_Reference
(N
, Typ
);
8818 if Is_String_Type
(Typ
) then
8819 Eval_Concatenation
(N
);
8822 -- If this is not a static concatenation, but the result is a string
8823 -- type (and not an array of strings) ensure that static string operands
8824 -- have their subtypes properly constructed.
8826 if Nkind
(N
) /= N_String_Literal
8827 and then Is_Character_Type
(Component_Type
(Typ
))
8829 Set_String_Literal_Subtype
(Op1
, Typ
);
8830 Set_String_Literal_Subtype
(Op2
, Typ
);
8832 end Resolve_Op_Concat_Rest
;
8834 ----------------------
8835 -- Resolve_Op_Expon --
8836 ----------------------
8838 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
8839 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
8842 -- Catch attempts to do fixed-point exponentiation with universal
8843 -- operands, which is a case where the illegality is not caught during
8844 -- normal operator analysis. This is not done in preanalysis mode
8845 -- since the tree is not fully decorated during preanalysis.
8847 if Full_Analysis
then
8848 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
8849 Error_Msg_N
("exponentiation not available for fixed point", N
);
8852 elsif Nkind
(Parent
(N
)) in N_Op
8853 and then Is_Fixed_Point_Type
(Etype
(Parent
(N
)))
8854 and then Etype
(N
) = Universal_Real
8855 and then Comes_From_Source
(N
)
8857 Error_Msg_N
("exponentiation not available for fixed point", N
);
8862 if Comes_From_Source
(N
)
8863 and then Ekind
(Entity
(N
)) = E_Function
8864 and then Is_Imported
(Entity
(N
))
8865 and then Is_Intrinsic_Subprogram
(Entity
(N
))
8867 Resolve_Intrinsic_Operator
(N
, Typ
);
8871 if Etype
(Left_Opnd
(N
)) = Universal_Integer
8872 or else Etype
(Left_Opnd
(N
)) = Universal_Real
8874 Check_For_Visible_Operator
(N
, B_Typ
);
8877 -- We do the resolution using the base type, because intermediate values
8878 -- in expressions are always of the base type, not a subtype of it.
8880 Resolve
(Left_Opnd
(N
), B_Typ
);
8881 Resolve
(Right_Opnd
(N
), Standard_Integer
);
8883 -- For integer types, right argument must be in Natural range
8885 if Is_Integer_Type
(Typ
) then
8886 Apply_Scalar_Range_Check
(Right_Opnd
(N
), Standard_Natural
);
8889 Check_Unset_Reference
(Left_Opnd
(N
));
8890 Check_Unset_Reference
(Right_Opnd
(N
));
8892 Set_Etype
(N
, B_Typ
);
8893 Generate_Operator_Reference
(N
, B_Typ
);
8895 Analyze_Dimension
(N
);
8897 if Ada_Version
>= Ada_2012
and then Has_Dimension_System
(B_Typ
) then
8898 -- Evaluate the exponentiation operator for dimensioned type
8900 Eval_Op_Expon_For_Dimensioned_Type
(N
, B_Typ
);
8905 -- Set overflow checking bit. Much cleverer code needed here eventually
8906 -- and perhaps the Resolve routines should be separated for the various
8907 -- arithmetic operations, since they will need different processing. ???
8909 if Nkind
(N
) in N_Op
then
8910 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
8911 Enable_Overflow_Check
(N
);
8914 end Resolve_Op_Expon
;
8916 --------------------
8917 -- Resolve_Op_Not --
8918 --------------------
8920 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
8923 function Parent_Is_Boolean
return Boolean;
8924 -- This function determines if the parent node is a boolean operator or
8925 -- operation (comparison op, membership test, or short circuit form) and
8926 -- the not in question is the left operand of this operation. Note that
8927 -- if the not is in parens, then false is returned.
8929 -----------------------
8930 -- Parent_Is_Boolean --
8931 -----------------------
8933 function Parent_Is_Boolean
return Boolean is
8935 if Paren_Count
(N
) /= 0 then
8939 case Nkind
(Parent
(N
)) is
8954 return Left_Opnd
(Parent
(N
)) = N
;
8960 end Parent_Is_Boolean
;
8962 -- Start of processing for Resolve_Op_Not
8965 -- Predefined operations on scalar types yield the base type. On the
8966 -- other hand, logical operations on arrays yield the type of the
8967 -- arguments (and the context).
8969 if Is_Array_Type
(Typ
) then
8972 B_Typ
:= Base_Type
(Typ
);
8975 -- Straightforward case of incorrect arguments
8977 if not Valid_Boolean_Arg
(Typ
) then
8978 Error_Msg_N
("invalid operand type for operator&", N
);
8979 Set_Etype
(N
, Any_Type
);
8982 -- Special case of probable missing parens
8984 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
8985 if Parent_Is_Boolean
then
8987 ("operand of not must be enclosed in parentheses",
8991 ("no modular type available in this context", N
);
8994 Set_Etype
(N
, Any_Type
);
8997 -- OK resolution of NOT
9000 -- Warn if non-boolean types involved. This is a case like not a < b
9001 -- where a and b are modular, where we will get (not a) < b and most
9002 -- likely not (a < b) was intended.
9004 if Warn_On_Questionable_Missing_Parens
9005 and then not Is_Boolean_Type
(Typ
)
9006 and then Parent_Is_Boolean
9008 Error_Msg_N
("?q?not expression should be parenthesized here!", N
);
9011 -- Warn on double negation if checking redundant constructs
9013 if Warn_On_Redundant_Constructs
9014 and then Comes_From_Source
(N
)
9015 and then Comes_From_Source
(Right_Opnd
(N
))
9016 and then Root_Type
(Typ
) = Standard_Boolean
9017 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
9019 Error_Msg_N
("redundant double negation?r?", N
);
9022 -- Complete resolution and evaluation of NOT
9024 Resolve
(Right_Opnd
(N
), B_Typ
);
9025 Check_Unset_Reference
(Right_Opnd
(N
));
9026 Set_Etype
(N
, B_Typ
);
9027 Generate_Operator_Reference
(N
, B_Typ
);
9032 -----------------------------
9033 -- Resolve_Operator_Symbol --
9034 -----------------------------
9036 -- Nothing to be done, all resolved already
9038 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
9039 pragma Warnings
(Off
, N
);
9040 pragma Warnings
(Off
, Typ
);
9044 end Resolve_Operator_Symbol
;
9046 ----------------------------------
9047 -- Resolve_Qualified_Expression --
9048 ----------------------------------
9050 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9051 pragma Warnings
(Off
, Typ
);
9053 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
9054 Expr
: constant Node_Id
:= Expression
(N
);
9057 Resolve
(Expr
, Target_Typ
);
9059 -- Protect call to Matching_Static_Array_Bounds to avoid costly
9060 -- operation if not needed.
9062 if Restriction_Check_Required
(SPARK_05
)
9063 and then Is_Array_Type
(Target_Typ
)
9064 and then Is_Array_Type
(Etype
(Expr
))
9065 and then Etype
(Expr
) /= Any_Composite
-- or else Expr in error
9066 and then not Matching_Static_Array_Bounds
(Target_Typ
, Etype
(Expr
))
9068 Check_SPARK_05_Restriction
9069 ("array types should have matching static bounds", N
);
9072 -- A qualified expression requires an exact match of the type, class-
9073 -- wide matching is not allowed. However, if the qualifying type is
9074 -- specific and the expression has a class-wide type, it may still be
9075 -- okay, since it can be the result of the expansion of a call to a
9076 -- dispatching function, so we also have to check class-wideness of the
9077 -- type of the expression's original node.
9079 if (Is_Class_Wide_Type
(Target_Typ
)
9081 (Is_Class_Wide_Type
(Etype
(Expr
))
9082 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
9083 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
9085 Wrong_Type
(Expr
, Target_Typ
);
9088 -- If the target type is unconstrained, then we reset the type of the
9089 -- result from the type of the expression. For other cases, the actual
9090 -- subtype of the expression is the target type.
9092 if Is_Composite_Type
(Target_Typ
)
9093 and then not Is_Constrained
(Target_Typ
)
9095 Set_Etype
(N
, Etype
(Expr
));
9098 Analyze_Dimension
(N
);
9099 Eval_Qualified_Expression
(N
);
9101 -- If we still have a qualified expression after the static evaluation,
9102 -- then apply a scalar range check if needed. The reason that we do this
9103 -- after the Eval call is that otherwise, the application of the range
9104 -- check may convert an illegal static expression and result in warning
9105 -- rather than giving an error (e.g Integer'(Integer'Last + 1)).
9107 if Nkind
(N
) = N_Qualified_Expression
and then Is_Scalar_Type
(Typ
) then
9108 Apply_Scalar_Range_Check
(Expr
, Typ
);
9110 end Resolve_Qualified_Expression
;
9112 ------------------------------
9113 -- Resolve_Raise_Expression --
9114 ------------------------------
9116 procedure Resolve_Raise_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
9118 if Typ
= Raise_Type
then
9119 Error_Msg_N
("cannot find unique type for raise expression", N
);
9120 Set_Etype
(N
, Any_Type
);
9124 end Resolve_Raise_Expression
;
9130 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
9131 L
: constant Node_Id
:= Low_Bound
(N
);
9132 H
: constant Node_Id
:= High_Bound
(N
);
9134 function First_Last_Ref
return Boolean;
9135 -- Returns True if N is of the form X'First .. X'Last where X is the
9136 -- same entity for both attributes.
9138 --------------------
9139 -- First_Last_Ref --
9140 --------------------
9142 function First_Last_Ref
return Boolean is
9143 Lorig
: constant Node_Id
:= Original_Node
(L
);
9144 Horig
: constant Node_Id
:= Original_Node
(H
);
9147 if Nkind
(Lorig
) = N_Attribute_Reference
9148 and then Nkind
(Horig
) = N_Attribute_Reference
9149 and then Attribute_Name
(Lorig
) = Name_First
9150 and then Attribute_Name
(Horig
) = Name_Last
9153 PL
: constant Node_Id
:= Prefix
(Lorig
);
9154 PH
: constant Node_Id
:= Prefix
(Horig
);
9156 if Is_Entity_Name
(PL
)
9157 and then Is_Entity_Name
(PH
)
9158 and then Entity
(PL
) = Entity
(PH
)
9168 -- Start of processing for Resolve_Range
9175 -- Check for inappropriate range on unordered enumeration type
9177 if Bad_Unordered_Enumeration_Reference
(N
, Typ
)
9179 -- Exclude X'First .. X'Last if X is the same entity for both
9181 and then not First_Last_Ref
9183 Error_Msg_Sloc
:= Sloc
(Typ
);
9185 ("subrange of unordered enumeration type& declared#?U?", N
, Typ
);
9188 Check_Unset_Reference
(L
);
9189 Check_Unset_Reference
(H
);
9191 -- We have to check the bounds for being within the base range as
9192 -- required for a non-static context. Normally this is automatic and
9193 -- done as part of evaluating expressions, but the N_Range node is an
9194 -- exception, since in GNAT we consider this node to be a subexpression,
9195 -- even though in Ada it is not. The circuit in Sem_Eval could check for
9196 -- this, but that would put the test on the main evaluation path for
9199 Check_Non_Static_Context
(L
);
9200 Check_Non_Static_Context
(H
);
9202 -- Check for an ambiguous range over character literals. This will
9203 -- happen with a membership test involving only literals.
9205 if Typ
= Any_Character
then
9206 Ambiguous_Character
(L
);
9207 Set_Etype
(N
, Any_Type
);
9211 -- If bounds are static, constant-fold them, so size computations are
9212 -- identical between front-end and back-end. Do not perform this
9213 -- transformation while analyzing generic units, as type information
9214 -- would be lost when reanalyzing the constant node in the instance.
9216 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
9217 if Is_OK_Static_Expression
(L
) then
9218 Fold_Uint
(L
, Expr_Value
(L
), Is_OK_Static_Expression
(L
));
9221 if Is_OK_Static_Expression
(H
) then
9222 Fold_Uint
(H
, Expr_Value
(H
), Is_OK_Static_Expression
(H
));
9227 --------------------------
9228 -- Resolve_Real_Literal --
9229 --------------------------
9231 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9232 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
9235 -- Special processing for fixed-point literals to make sure that the
9236 -- value is an exact multiple of small where this is required. We skip
9237 -- this for the universal real case, and also for generic types.
9239 if Is_Fixed_Point_Type
(Typ
)
9240 and then Typ
/= Universal_Fixed
9241 and then Typ
/= Any_Fixed
9242 and then not Is_Generic_Type
(Typ
)
9245 Val
: constant Ureal
:= Realval
(N
);
9246 Cintr
: constant Ureal
:= Val
/ Small_Value
(Typ
);
9247 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
9248 Den
: constant Uint
:= Norm_Den
(Cintr
);
9252 -- Case of literal is not an exact multiple of the Small
9256 -- For a source program literal for a decimal fixed-point type,
9257 -- this is statically illegal (RM 4.9(36)).
9259 if Is_Decimal_Fixed_Point_Type
(Typ
)
9260 and then Actual_Typ
= Universal_Real
9261 and then Comes_From_Source
(N
)
9263 Error_Msg_N
("value has extraneous low order digits", N
);
9266 -- Generate a warning if literal from source
9268 if Is_OK_Static_Expression
(N
)
9269 and then Warn_On_Bad_Fixed_Value
9272 ("?b?static fixed-point value is not a multiple of Small!",
9276 -- Replace literal by a value that is the exact representation
9277 -- of a value of the type, i.e. a multiple of the small value,
9278 -- by truncation, since Machine_Rounds is false for all GNAT
9279 -- fixed-point types (RM 4.9(38)).
9281 Stat
:= Is_OK_Static_Expression
(N
);
9283 Make_Real_Literal
(Sloc
(N
),
9284 Realval
=> Small_Value
(Typ
) * Cint
));
9286 Set_Is_Static_Expression
(N
, Stat
);
9289 -- In all cases, set the corresponding integer field
9291 Set_Corresponding_Integer_Value
(N
, Cint
);
9295 -- Now replace the actual type by the expected type as usual
9298 Eval_Real_Literal
(N
);
9299 end Resolve_Real_Literal
;
9301 -----------------------
9302 -- Resolve_Reference --
9303 -----------------------
9305 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
9306 P
: constant Node_Id
:= Prefix
(N
);
9309 -- Replace general access with specific type
9311 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
9312 Set_Etype
(N
, Base_Type
(Typ
));
9315 Resolve
(P
, Designated_Type
(Etype
(N
)));
9317 -- If we are taking the reference of a volatile entity, then treat it as
9318 -- a potential modification of this entity. This is too conservative,
9319 -- but necessary because remove side effects can cause transformations
9320 -- of normal assignments into reference sequences that otherwise fail to
9321 -- notice the modification.
9323 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
9324 Note_Possible_Modification
(P
, Sure
=> False);
9326 end Resolve_Reference
;
9328 --------------------------------
9329 -- Resolve_Selected_Component --
9330 --------------------------------
9332 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
9334 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
9335 P
: constant Node_Id
:= Prefix
(N
);
9336 S
: constant Node_Id
:= Selector_Name
(N
);
9337 T
: Entity_Id
:= Etype
(P
);
9339 I1
: Interp_Index
:= 0; -- prevent junk warning
9344 function Init_Component
return Boolean;
9345 -- Check whether this is the initialization of a component within an
9346 -- init proc (by assignment or call to another init proc). If true,
9347 -- there is no need for a discriminant check.
9349 --------------------
9350 -- Init_Component --
9351 --------------------
9353 function Init_Component
return Boolean is
9355 return Inside_Init_Proc
9356 and then Nkind
(Prefix
(N
)) = N_Identifier
9357 and then Chars
(Prefix
(N
)) = Name_uInit
9358 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
9361 -- Start of processing for Resolve_Selected_Component
9364 if Is_Overloaded
(P
) then
9366 -- Use the context type to select the prefix that has a selector
9367 -- of the correct name and type.
9370 Get_First_Interp
(P
, I
, It
);
9372 Search
: while Present
(It
.Typ
) loop
9373 if Is_Access_Type
(It
.Typ
) then
9374 T
:= Designated_Type
(It
.Typ
);
9379 -- Locate selected component. For a private prefix the selector
9380 -- can denote a discriminant.
9382 if Is_Record_Type
(T
) or else Is_Private_Type
(T
) then
9384 -- The visible components of a class-wide type are those of
9387 if Is_Class_Wide_Type
(T
) then
9391 Comp
:= First_Entity
(T
);
9392 while Present
(Comp
) loop
9393 if Chars
(Comp
) = Chars
(S
)
9394 and then Covers
(Typ
, Etype
(Comp
))
9403 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9405 if It
= No_Interp
then
9407 ("ambiguous prefix for selected component", N
);
9414 -- There may be an implicit dereference. Retrieve
9415 -- designated record type.
9417 if Is_Access_Type
(It1
.Typ
) then
9418 T
:= Designated_Type
(It1
.Typ
);
9423 if Scope
(Comp1
) /= T
then
9425 -- Resolution chooses the new interpretation.
9426 -- Find the component with the right name.
9428 Comp1
:= First_Entity
(T
);
9429 while Present
(Comp1
)
9430 and then Chars
(Comp1
) /= Chars
(S
)
9432 Comp1
:= Next_Entity
(Comp1
);
9441 Comp
:= Next_Entity
(Comp
);
9445 Get_Next_Interp
(I
, It
);
9448 -- There must be a legal interpretation at this point
9450 pragma Assert
(Found
);
9451 Resolve
(P
, It1
.Typ
);
9453 Set_Entity_With_Checks
(S
, Comp1
);
9456 -- Resolve prefix with its type
9461 -- Generate cross-reference. We needed to wait until full overloading
9462 -- resolution was complete to do this, since otherwise we can't tell if
9463 -- we are an lvalue or not.
9465 if May_Be_Lvalue
(N
) then
9466 Generate_Reference
(Entity
(S
), S
, 'm');
9468 Generate_Reference
(Entity
(S
), S
, 'r');
9471 -- If prefix is an access type, the node will be transformed into an
9472 -- explicit dereference during expansion. The type of the node is the
9473 -- designated type of that of the prefix.
9475 if Is_Access_Type
(Etype
(P
)) then
9476 T
:= Designated_Type
(Etype
(P
));
9477 Check_Fully_Declared_Prefix
(T
, P
);
9482 -- Set flag for expander if discriminant check required
9484 if Has_Discriminants
(T
)
9485 and then Ekind_In
(Entity
(S
), E_Component
, E_Discriminant
)
9486 and then Present
(Original_Record_Component
(Entity
(S
)))
9487 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
9488 and then not Discriminant_Checks_Suppressed
(T
)
9489 and then not Init_Component
9491 Set_Do_Discriminant_Check
(N
);
9494 if Ekind
(Entity
(S
)) = E_Void
then
9495 Error_Msg_N
("premature use of component", S
);
9498 -- If the prefix is a record conversion, this may be a renamed
9499 -- discriminant whose bounds differ from those of the original
9500 -- one, so we must ensure that a range check is performed.
9502 if Nkind
(P
) = N_Type_Conversion
9503 and then Ekind
(Entity
(S
)) = E_Discriminant
9504 and then Is_Discrete_Type
(Typ
)
9506 Set_Etype
(N
, Base_Type
(Typ
));
9509 -- Note: No Eval processing is required, because the prefix is of a
9510 -- record type, or protected type, and neither can possibly be static.
9512 -- If the record type is atomic, and the component is non-atomic, then
9513 -- this is worth a warning, since we have a situation where the access
9514 -- to the component may cause extra read/writes of the atomic array
9515 -- object, or partial word accesses, both of which may be unexpected.
9517 if Nkind
(N
) = N_Selected_Component
9518 and then Is_Atomic_Ref_With_Address
(N
)
9519 and then not Is_Atomic
(Entity
(S
))
9520 and then not Is_Atomic
(Etype
(Entity
(S
)))
9523 ("??access to non-atomic component of atomic record",
9526 ("\??may cause unexpected accesses to atomic object",
9530 Analyze_Dimension
(N
);
9531 end Resolve_Selected_Component
;
9537 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
9538 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9539 L
: constant Node_Id
:= Left_Opnd
(N
);
9540 R
: constant Node_Id
:= Right_Opnd
(N
);
9543 -- We do the resolution using the base type, because intermediate values
9544 -- in expressions always are of the base type, not a subtype of it.
9547 Resolve
(R
, Standard_Natural
);
9549 Check_Unset_Reference
(L
);
9550 Check_Unset_Reference
(R
);
9552 Set_Etype
(N
, B_Typ
);
9553 Generate_Operator_Reference
(N
, B_Typ
);
9557 ---------------------------
9558 -- Resolve_Short_Circuit --
9559 ---------------------------
9561 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
9562 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
9563 L
: constant Node_Id
:= Left_Opnd
(N
);
9564 R
: constant Node_Id
:= Right_Opnd
(N
);
9567 -- Ensure all actions associated with the left operand (e.g.
9568 -- finalization of transient controlled objects) are fully evaluated
9569 -- locally within an expression with actions. This is particularly
9570 -- helpful for coverage analysis. However this should not happen in
9573 if Expander_Active
then
9575 Reloc_L
: constant Node_Id
:= Relocate_Node
(L
);
9577 Save_Interps
(Old_N
=> L
, New_N
=> Reloc_L
);
9580 Make_Expression_With_Actions
(Sloc
(L
),
9581 Actions
=> New_List
,
9582 Expression
=> Reloc_L
));
9584 -- Set Comes_From_Source on L to preserve warnings for unset
9587 Set_Comes_From_Source
(L
, Comes_From_Source
(Reloc_L
));
9594 -- Check for issuing warning for always False assert/check, this happens
9595 -- when assertions are turned off, in which case the pragma Assert/Check
9596 -- was transformed into:
9598 -- if False and then <condition> then ...
9600 -- and we detect this pattern
9602 if Warn_On_Assertion_Failure
9603 and then Is_Entity_Name
(R
)
9604 and then Entity
(R
) = Standard_False
9605 and then Nkind
(Parent
(N
)) = N_If_Statement
9606 and then Nkind
(N
) = N_And_Then
9607 and then Is_Entity_Name
(L
)
9608 and then Entity
(L
) = Standard_False
9611 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
9614 -- Special handling of Asssert pragma
9616 if Nkind
(Orig
) = N_Pragma
9617 and then Pragma_Name
(Orig
) = Name_Assert
9620 Expr
: constant Node_Id
:=
9623 (First
(Pragma_Argument_Associations
(Orig
))));
9626 -- Don't warn if original condition is explicit False,
9627 -- since obviously the failure is expected in this case.
9629 if Is_Entity_Name
(Expr
)
9630 and then Entity
(Expr
) = Standard_False
9634 -- Issue warning. We do not want the deletion of the
9635 -- IF/AND-THEN to take this message with it. We achieve this
9636 -- by making sure that the expanded code points to the Sloc
9637 -- of the expression, not the original pragma.
9640 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
9641 -- The source location of the expression is not usually
9642 -- the best choice here. For example, it gets located on
9643 -- the last AND keyword in a chain of boolean expressiond
9644 -- AND'ed together. It is best to put the message on the
9645 -- first character of the assertion, which is the effect
9646 -- of the First_Node call here.
9649 ("?A?assertion would fail at run time!",
9651 (First
(Pragma_Argument_Associations
(Orig
))));
9655 -- Similar processing for Check pragma
9657 elsif Nkind
(Orig
) = N_Pragma
9658 and then Pragma_Name
(Orig
) = Name_Check
9660 -- Don't want to warn if original condition is explicit False
9663 Expr
: constant Node_Id
:=
9666 (Next
(First
(Pragma_Argument_Associations
(Orig
)))));
9668 if Is_Entity_Name
(Expr
)
9669 and then Entity
(Expr
) = Standard_False
9676 -- Again use Error_Msg_F rather than Error_Msg_N, see
9677 -- comment above for an explanation of why we do this.
9680 ("?A?check would fail at run time!",
9682 (Last
(Pragma_Argument_Associations
(Orig
))));
9689 -- Continue with processing of short circuit
9691 Check_Unset_Reference
(L
);
9692 Check_Unset_Reference
(R
);
9694 Set_Etype
(N
, B_Typ
);
9695 Eval_Short_Circuit
(N
);
9696 end Resolve_Short_Circuit
;
9702 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
9703 Drange
: constant Node_Id
:= Discrete_Range
(N
);
9704 Name
: constant Node_Id
:= Prefix
(N
);
9705 Array_Type
: Entity_Id
:= Empty
;
9706 Dexpr
: Node_Id
:= Empty
;
9707 Index_Type
: Entity_Id
;
9710 if Is_Overloaded
(Name
) then
9712 -- Use the context type to select the prefix that yields the correct
9717 I1
: Interp_Index
:= 0;
9719 P
: constant Node_Id
:= Prefix
(N
);
9720 Found
: Boolean := False;
9723 Get_First_Interp
(P
, I
, It
);
9724 while Present
(It
.Typ
) loop
9725 if (Is_Array_Type
(It
.Typ
)
9726 and then Covers
(Typ
, It
.Typ
))
9727 or else (Is_Access_Type
(It
.Typ
)
9728 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
9729 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
9732 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
9734 if It
= No_Interp
then
9735 Error_Msg_N
("ambiguous prefix for slicing", N
);
9740 Array_Type
:= It
.Typ
;
9745 Array_Type
:= It
.Typ
;
9750 Get_Next_Interp
(I
, It
);
9755 Array_Type
:= Etype
(Name
);
9758 Resolve
(Name
, Array_Type
);
9760 if Is_Access_Type
(Array_Type
) then
9761 Apply_Access_Check
(N
);
9762 Array_Type
:= Designated_Type
(Array_Type
);
9764 -- If the prefix is an access to an unconstrained array, we must use
9765 -- the actual subtype of the object to perform the index checks. The
9766 -- object denoted by the prefix is implicit in the node, so we build
9767 -- an explicit representation for it in order to compute the actual
9770 if not Is_Constrained
(Array_Type
) then
9771 Remove_Side_Effects
(Prefix
(N
));
9774 Obj
: constant Node_Id
:=
9775 Make_Explicit_Dereference
(Sloc
(N
),
9776 Prefix
=> New_Copy_Tree
(Prefix
(N
)));
9778 Set_Etype
(Obj
, Array_Type
);
9779 Set_Parent
(Obj
, Parent
(N
));
9780 Array_Type
:= Get_Actual_Subtype
(Obj
);
9784 elsif Is_Entity_Name
(Name
)
9785 or else Nkind
(Name
) = N_Explicit_Dereference
9786 or else (Nkind
(Name
) = N_Function_Call
9787 and then not Is_Constrained
(Etype
(Name
)))
9789 Array_Type
:= Get_Actual_Subtype
(Name
);
9791 -- If the name is a selected component that depends on discriminants,
9792 -- build an actual subtype for it. This can happen only when the name
9793 -- itself is overloaded; otherwise the actual subtype is created when
9794 -- the selected component is analyzed.
9796 elsif Nkind
(Name
) = N_Selected_Component
9797 and then Full_Analysis
9798 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
9801 Act_Decl
: constant Node_Id
:=
9802 Build_Actual_Subtype_Of_Component
(Array_Type
, Name
);
9804 Insert_Action
(N
, Act_Decl
);
9805 Array_Type
:= Defining_Identifier
(Act_Decl
);
9808 -- Maybe this should just be "else", instead of checking for the
9809 -- specific case of slice??? This is needed for the case where the
9810 -- prefix is an Image attribute, which gets expanded to a slice, and so
9811 -- has a constrained subtype which we want to use for the slice range
9812 -- check applied below (the range check won't get done if the
9813 -- unconstrained subtype of the 'Image is used).
9815 elsif Nkind
(Name
) = N_Slice
then
9816 Array_Type
:= Etype
(Name
);
9819 -- Obtain the type of the array index
9821 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
9822 Index_Type
:= Etype
(String_Literal_Low_Bound
(Array_Type
));
9824 Index_Type
:= Etype
(First_Index
(Array_Type
));
9827 -- If name was overloaded, set slice type correctly now
9829 Set_Etype
(N
, Array_Type
);
9831 -- Handle the generation of a range check that compares the array index
9832 -- against the discrete_range. The check is not applied to internally
9833 -- built nodes associated with the expansion of dispatch tables. Check
9834 -- that Ada.Tags has already been loaded to avoid extra dependencies on
9837 if Tagged_Type_Expansion
9838 and then RTU_Loaded
(Ada_Tags
)
9839 and then Nkind
(Prefix
(N
)) = N_Selected_Component
9840 and then Present
(Entity
(Selector_Name
(Prefix
(N
))))
9841 and then Entity
(Selector_Name
(Prefix
(N
))) =
9842 RTE_Record_Component
(RE_Prims_Ptr
)
9846 -- The discrete_range is specified by a subtype indication. Create a
9847 -- shallow copy and inherit the type, parent and source location from
9848 -- the discrete_range. This ensures that the range check is inserted
9849 -- relative to the slice and that the runtime exception points to the
9850 -- proper construct.
9852 elsif Is_Entity_Name
(Drange
) then
9853 Dexpr
:= New_Copy
(Scalar_Range
(Entity
(Drange
)));
9855 Set_Etype
(Dexpr
, Etype
(Drange
));
9856 Set_Parent
(Dexpr
, Parent
(Drange
));
9857 Set_Sloc
(Dexpr
, Sloc
(Drange
));
9859 -- The discrete_range is a regular range. Resolve the bounds and remove
9860 -- their side effects.
9863 Resolve
(Drange
, Base_Type
(Index_Type
));
9865 if Nkind
(Drange
) = N_Range
then
9866 Force_Evaluation
(Low_Bound
(Drange
));
9867 Force_Evaluation
(High_Bound
(Drange
));
9873 if Present
(Dexpr
) then
9874 Apply_Range_Check
(Dexpr
, Index_Type
);
9877 Set_Slice_Subtype
(N
);
9879 -- Check bad use of type with predicates
9885 if Nkind
(Drange
) = N_Subtype_Indication
9886 and then Has_Predicates
(Entity
(Subtype_Mark
(Drange
)))
9888 Subt
:= Entity
(Subtype_Mark
(Drange
));
9890 Subt
:= Etype
(Drange
);
9893 if Has_Predicates
(Subt
) then
9894 Bad_Predicated_Subtype_Use
9895 ("subtype& has predicate, not allowed in slice", Drange
, Subt
);
9899 -- Otherwise here is where we check suspicious indexes
9901 if Nkind
(Drange
) = N_Range
then
9902 Warn_On_Suspicious_Index
(Name
, Low_Bound
(Drange
));
9903 Warn_On_Suspicious_Index
(Name
, High_Bound
(Drange
));
9906 Analyze_Dimension
(N
);
9910 ----------------------------
9911 -- Resolve_String_Literal --
9912 ----------------------------
9914 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
9915 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
9916 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
9917 Loc
: constant Source_Ptr
:= Sloc
(N
);
9918 Str
: constant String_Id
:= Strval
(N
);
9919 Strlen
: constant Nat
:= String_Length
(Str
);
9920 Subtype_Id
: Entity_Id
;
9921 Need_Check
: Boolean;
9924 -- For a string appearing in a concatenation, defer creation of the
9925 -- string_literal_subtype until the end of the resolution of the
9926 -- concatenation, because the literal may be constant-folded away. This
9927 -- is a useful optimization for long concatenation expressions.
9929 -- If the string is an aggregate built for a single character (which
9930 -- happens in a non-static context) or a is null string to which special
9931 -- checks may apply, we build the subtype. Wide strings must also get a
9932 -- string subtype if they come from a one character aggregate. Strings
9933 -- generated by attributes might be static, but it is often hard to
9934 -- determine whether the enclosing context is static, so we generate
9935 -- subtypes for them as well, thus losing some rarer optimizations ???
9936 -- Same for strings that come from a static conversion.
9939 (Strlen
= 0 and then Typ
/= Standard_String
)
9940 or else Nkind
(Parent
(N
)) /= N_Op_Concat
9941 or else (N
/= Left_Opnd
(Parent
(N
))
9942 and then N
/= Right_Opnd
(Parent
(N
)))
9943 or else ((Typ
= Standard_Wide_String
9944 or else Typ
= Standard_Wide_Wide_String
)
9945 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
9947 -- If the resolving type is itself a string literal subtype, we can just
9948 -- reuse it, since there is no point in creating another.
9950 if Ekind
(Typ
) = E_String_Literal_Subtype
then
9953 elsif Nkind
(Parent
(N
)) = N_Op_Concat
9954 and then not Need_Check
9955 and then not Nkind_In
(Original_Node
(N
), N_Character_Literal
,
9956 N_Attribute_Reference
,
9957 N_Qualified_Expression
,
9962 -- Do not generate a string literal subtype for the default expression
9963 -- of a formal parameter in GNATprove mode. This is because the string
9964 -- subtype is associated with the freezing actions of the subprogram,
9965 -- however freezing is disabled in GNATprove mode and as a result the
9966 -- subtype is unavailable.
9968 elsif GNATprove_Mode
9969 and then Nkind
(Parent
(N
)) = N_Parameter_Specification
9973 -- Otherwise we must create a string literal subtype. Note that the
9974 -- whole idea of string literal subtypes is simply to avoid the need
9975 -- for building a full fledged array subtype for each literal.
9978 Set_String_Literal_Subtype
(N
, Typ
);
9979 Subtype_Id
:= Etype
(N
);
9982 if Nkind
(Parent
(N
)) /= N_Op_Concat
9985 Set_Etype
(N
, Subtype_Id
);
9986 Eval_String_Literal
(N
);
9989 if Is_Limited_Composite
(Typ
)
9990 or else Is_Private_Composite
(Typ
)
9992 Error_Msg_N
("string literal not available for private array", N
);
9993 Set_Etype
(N
, Any_Type
);
9997 -- The validity of a null string has been checked in the call to
9998 -- Eval_String_Literal.
10003 -- Always accept string literal with component type Any_Character, which
10004 -- occurs in error situations and in comparisons of literals, both of
10005 -- which should accept all literals.
10007 elsif R_Typ
= Any_Character
then
10010 -- If the type is bit-packed, then we always transform the string
10011 -- literal into a full fledged aggregate.
10013 elsif Is_Bit_Packed_Array
(Typ
) then
10016 -- Deal with cases of Wide_Wide_String, Wide_String, and String
10019 -- For Standard.Wide_Wide_String, or any other type whose component
10020 -- type is Standard.Wide_Wide_Character, we know that all the
10021 -- characters in the string must be acceptable, since the parser
10022 -- accepted the characters as valid character literals.
10024 if R_Typ
= Standard_Wide_Wide_Character
then
10027 -- For the case of Standard.String, or any other type whose component
10028 -- type is Standard.Character, we must make sure that there are no
10029 -- wide characters in the string, i.e. that it is entirely composed
10030 -- of characters in range of type Character.
10032 -- If the string literal is the result of a static concatenation, the
10033 -- test has already been performed on the components, and need not be
10036 elsif R_Typ
= Standard_Character
10037 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
10039 for J
in 1 .. Strlen
loop
10040 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
10042 -- If we are out of range, post error. This is one of the
10043 -- very few places that we place the flag in the middle of
10044 -- a token, right under the offending wide character. Not
10045 -- quite clear if this is right wrt wide character encoding
10046 -- sequences, but it's only an error message.
10049 ("literal out of range of type Standard.Character",
10050 Source_Ptr
(Int
(Loc
) + J
));
10055 -- For the case of Standard.Wide_String, or any other type whose
10056 -- component type is Standard.Wide_Character, we must make sure that
10057 -- there are no wide characters in the string, i.e. that it is
10058 -- entirely composed of characters in range of type Wide_Character.
10060 -- If the string literal is the result of a static concatenation,
10061 -- the test has already been performed on the components, and need
10062 -- not be repeated.
10064 elsif R_Typ
= Standard_Wide_Character
10065 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
10067 for J
in 1 .. Strlen
loop
10068 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
10070 -- If we are out of range, post error. This is one of the
10071 -- very few places that we place the flag in the middle of
10072 -- a token, right under the offending wide character.
10074 -- This is not quite right, because characters in general
10075 -- will take more than one character position ???
10078 ("literal out of range of type Standard.Wide_Character",
10079 Source_Ptr
(Int
(Loc
) + J
));
10084 -- If the root type is not a standard character, then we will convert
10085 -- the string into an aggregate and will let the aggregate code do
10086 -- the checking. Standard Wide_Wide_Character is also OK here.
10092 -- See if the component type of the array corresponding to the string
10093 -- has compile time known bounds. If yes we can directly check
10094 -- whether the evaluation of the string will raise constraint error.
10095 -- Otherwise we need to transform the string literal into the
10096 -- corresponding character aggregate and let the aggregate code do
10099 if Is_Standard_Character_Type
(R_Typ
) then
10101 -- Check for the case of full range, where we are definitely OK
10103 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
10107 -- Here the range is not the complete base type range, so check
10110 Comp_Typ_Lo
: constant Node_Id
:=
10111 Type_Low_Bound
(Component_Type
(Typ
));
10112 Comp_Typ_Hi
: constant Node_Id
:=
10113 Type_High_Bound
(Component_Type
(Typ
));
10118 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
10119 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
10121 for J
in 1 .. Strlen
loop
10122 Char_Val
:= UI_From_Int
(Int
(Get_String_Char
(Str
, J
)));
10124 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
10125 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
10127 Apply_Compile_Time_Constraint_Error
10128 (N
, "character out of range??",
10129 CE_Range_Check_Failed
,
10130 Loc
=> Source_Ptr
(Int
(Loc
) + J
));
10140 -- If we got here we meed to transform the string literal into the
10141 -- equivalent qualified positional array aggregate. This is rather
10142 -- heavy artillery for this situation, but it is hard work to avoid.
10145 Lits
: constant List_Id
:= New_List
;
10146 P
: Source_Ptr
:= Loc
+ 1;
10150 -- Build the character literals, we give them source locations that
10151 -- correspond to the string positions, which is a bit tricky given
10152 -- the possible presence of wide character escape sequences.
10154 for J
in 1 .. Strlen
loop
10155 C
:= Get_String_Char
(Str
, J
);
10156 Set_Character_Literal_Name
(C
);
10159 Make_Character_Literal
(P
,
10160 Chars
=> Name_Find
,
10161 Char_Literal_Value
=> UI_From_CC
(C
)));
10163 if In_Character_Range
(C
) then
10166 -- Should we have a call to Skip_Wide here ???
10175 Make_Qualified_Expression
(Loc
,
10176 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
10178 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
10180 Analyze_And_Resolve
(N
, Typ
);
10182 end Resolve_String_Literal
;
10184 -----------------------------
10185 -- Resolve_Type_Conversion --
10186 -----------------------------
10188 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
10189 Conv_OK
: constant Boolean := Conversion_OK
(N
);
10190 Operand
: constant Node_Id
:= Expression
(N
);
10191 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
10192 Target_Typ
: constant Entity_Id
:= Etype
(N
);
10197 Test_Redundant
: Boolean := Warn_On_Redundant_Constructs
;
10198 -- Set to False to suppress cases where we want to suppress the test
10199 -- for redundancy to avoid possible false positives on this warning.
10203 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
10208 -- If the Operand Etype is Universal_Fixed, then the conversion is
10209 -- never redundant. We need this check because by the time we have
10210 -- finished the rather complex transformation, the conversion looks
10211 -- redundant when it is not.
10213 if Operand_Typ
= Universal_Fixed
then
10214 Test_Redundant
:= False;
10216 -- If the operand is marked as Any_Fixed, then special processing is
10217 -- required. This is also a case where we suppress the test for a
10218 -- redundant conversion, since most certainly it is not redundant.
10220 elsif Operand_Typ
= Any_Fixed
then
10221 Test_Redundant
:= False;
10223 -- Mixed-mode operation involving a literal. Context must be a fixed
10224 -- type which is applied to the literal subsequently.
10226 if Is_Fixed_Point_Type
(Typ
) then
10227 Set_Etype
(Operand
, Universal_Real
);
10229 elsif Is_Numeric_Type
(Typ
)
10230 and then Nkind_In
(Operand
, N_Op_Multiply
, N_Op_Divide
)
10231 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
10233 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
10235 -- Return if expression is ambiguous
10237 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
10240 -- If nothing else, the available fixed type is Duration
10243 Set_Etype
(Operand
, Standard_Duration
);
10246 -- Resolve the real operand with largest available precision
10248 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
10249 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
10251 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
10254 Resolve
(Rop
, Universal_Real
);
10256 -- If the operand is a literal (it could be a non-static and
10257 -- illegal exponentiation) check whether the use of Duration
10258 -- is potentially inaccurate.
10260 if Nkind
(Rop
) = N_Real_Literal
10261 and then Realval
(Rop
) /= Ureal_0
10262 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
10265 ("??universal real operand can only "
10266 & "be interpreted as Duration!", Rop
);
10268 ("\??precision will be lost in the conversion!", Rop
);
10271 elsif Is_Numeric_Type
(Typ
)
10272 and then Nkind
(Operand
) in N_Op
10273 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
10275 Set_Etype
(Operand
, Standard_Duration
);
10278 Error_Msg_N
("invalid context for mixed mode operation", N
);
10279 Set_Etype
(Operand
, Any_Type
);
10286 -- In SPARK, a type conversion between array types should be restricted
10287 -- to types which have matching static bounds.
10289 -- Protect call to Matching_Static_Array_Bounds to avoid costly
10290 -- operation if not needed.
10292 if Restriction_Check_Required
(SPARK_05
)
10293 and then Is_Array_Type
(Target_Typ
)
10294 and then Is_Array_Type
(Operand_Typ
)
10295 and then Operand_Typ
/= Any_Composite
-- or else Operand in error
10296 and then not Matching_Static_Array_Bounds
(Target_Typ
, Operand_Typ
)
10298 Check_SPARK_05_Restriction
10299 ("array types should have matching static bounds", N
);
10302 -- In formal mode, the operand of an ancestor type conversion must be an
10303 -- object (not an expression).
10305 if Is_Tagged_Type
(Target_Typ
)
10306 and then not Is_Class_Wide_Type
(Target_Typ
)
10307 and then Is_Tagged_Type
(Operand_Typ
)
10308 and then not Is_Class_Wide_Type
(Operand_Typ
)
10309 and then Is_Ancestor
(Target_Typ
, Operand_Typ
)
10310 and then not Is_SPARK_05_Object_Reference
(Operand
)
10312 Check_SPARK_05_Restriction
("object required", Operand
);
10315 Analyze_Dimension
(N
);
10317 -- Note: we do the Eval_Type_Conversion call before applying the
10318 -- required checks for a subtype conversion. This is important, since
10319 -- both are prepared under certain circumstances to change the type
10320 -- conversion to a constraint error node, but in the case of
10321 -- Eval_Type_Conversion this may reflect an illegality in the static
10322 -- case, and we would miss the illegality (getting only a warning
10323 -- message), if we applied the type conversion checks first.
10325 Eval_Type_Conversion
(N
);
10327 -- Even when evaluation is not possible, we may be able to simplify the
10328 -- conversion or its expression. This needs to be done before applying
10329 -- checks, since otherwise the checks may use the original expression
10330 -- and defeat the simplifications. This is specifically the case for
10331 -- elimination of the floating-point Truncation attribute in
10332 -- float-to-int conversions.
10334 Simplify_Type_Conversion
(N
);
10336 -- If after evaluation we still have a type conversion, then we may need
10337 -- to apply checks required for a subtype conversion.
10339 -- Skip these type conversion checks if universal fixed operands
10340 -- operands involved, since range checks are handled separately for
10341 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
10343 if Nkind
(N
) = N_Type_Conversion
10344 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
10345 and then Target_Typ
/= Universal_Fixed
10346 and then Operand_Typ
/= Universal_Fixed
10348 Apply_Type_Conversion_Checks
(N
);
10351 -- Issue warning for conversion of simple object to its own type. We
10352 -- have to test the original nodes, since they may have been rewritten
10353 -- by various optimizations.
10355 Orig_N
:= Original_Node
(N
);
10357 -- Here we test for a redundant conversion if the warning mode is
10358 -- active (and was not locally reset), and we have a type conversion
10359 -- from source not appearing in a generic instance.
10362 and then Nkind
(Orig_N
) = N_Type_Conversion
10363 and then Comes_From_Source
(Orig_N
)
10364 and then not In_Instance
10366 Orig_N
:= Original_Node
(Expression
(Orig_N
));
10367 Orig_T
:= Target_Typ
;
10369 -- If the node is part of a larger expression, the Target_Type
10370 -- may not be the original type of the node if the context is a
10371 -- condition. Recover original type to see if conversion is needed.
10373 if Is_Boolean_Type
(Orig_T
)
10374 and then Nkind
(Parent
(N
)) in N_Op
10376 Orig_T
:= Etype
(Parent
(N
));
10379 -- If we have an entity name, then give the warning if the entity
10380 -- is the right type, or if it is a loop parameter covered by the
10381 -- original type (that's needed because loop parameters have an
10382 -- odd subtype coming from the bounds).
10384 if (Is_Entity_Name
(Orig_N
)
10386 (Etype
(Entity
(Orig_N
)) = Orig_T
10388 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
10389 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
))))))
10391 -- If not an entity, then type of expression must match
10393 or else Etype
(Orig_N
) = Orig_T
10395 -- One more check, do not give warning if the analyzed conversion
10396 -- has an expression with non-static bounds, and the bounds of the
10397 -- target are static. This avoids junk warnings in cases where the
10398 -- conversion is necessary to establish staticness, for example in
10399 -- a case statement.
10401 if not Is_OK_Static_Subtype
(Operand_Typ
)
10402 and then Is_OK_Static_Subtype
(Target_Typ
)
10406 -- Finally, if this type conversion occurs in a context requiring
10407 -- a prefix, and the expression is a qualified expression then the
10408 -- type conversion is not redundant, since a qualified expression
10409 -- is not a prefix, whereas a type conversion is. For example, "X
10410 -- := T'(Funx(...)).Y;" is illegal because a selected component
10411 -- requires a prefix, but a type conversion makes it legal: "X :=
10412 -- T(T'(Funx(...))).Y;"
10414 -- In Ada 2012, a qualified expression is a name, so this idiom is
10415 -- no longer needed, but we still suppress the warning because it
10416 -- seems unfriendly for warnings to pop up when you switch to the
10417 -- newer language version.
10419 elsif Nkind
(Orig_N
) = N_Qualified_Expression
10420 and then Nkind_In
(Parent
(N
), N_Attribute_Reference
,
10421 N_Indexed_Component
,
10422 N_Selected_Component
,
10424 N_Explicit_Dereference
)
10428 -- Never warn on conversion to Long_Long_Integer'Base since
10429 -- that is most likely an artifact of the extended overflow
10430 -- checking and comes from complex expanded code.
10432 elsif Orig_T
= Base_Type
(Standard_Long_Long_Integer
) then
10435 -- Here we give the redundant conversion warning. If it is an
10436 -- entity, give the name of the entity in the message. If not,
10437 -- just mention the expression.
10439 -- Shoudn't we test Warn_On_Redundant_Constructs here ???
10442 if Is_Entity_Name
(Orig_N
) then
10443 Error_Msg_Node_2
:= Orig_T
;
10444 Error_Msg_NE
-- CODEFIX
10445 ("??redundant conversion, & is of type &!",
10446 N
, Entity
(Orig_N
));
10449 ("??redundant conversion, expression is of type&!",
10456 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
10457 -- No need to perform any interface conversion if the type of the
10458 -- expression coincides with the target type.
10460 if Ada_Version
>= Ada_2005
10461 and then Expander_Active
10462 and then Operand_Typ
/= Target_Typ
10465 Opnd
: Entity_Id
:= Operand_Typ
;
10466 Target
: Entity_Id
:= Target_Typ
;
10469 -- If the type of the operand is a limited view, use the non-
10470 -- limited view when available.
10472 if From_Limited_With
(Opnd
)
10473 and then Ekind
(Opnd
) in Incomplete_Kind
10474 and then Present
(Non_Limited_View
(Opnd
))
10476 Opnd
:= Non_Limited_View
(Opnd
);
10477 Set_Etype
(Expression
(N
), Opnd
);
10480 if Is_Access_Type
(Opnd
) then
10481 Opnd
:= Designated_Type
(Opnd
);
10484 if Is_Access_Type
(Target_Typ
) then
10485 Target
:= Designated_Type
(Target
);
10488 if Opnd
= Target
then
10491 -- Conversion from interface type
10493 elsif Is_Interface
(Opnd
) then
10495 -- Ada 2005 (AI-217): Handle entities from limited views
10497 if From_Limited_With
(Opnd
) then
10498 Error_Msg_Qual_Level
:= 99;
10499 Error_Msg_NE
-- CODEFIX
10500 ("missing WITH clause on package &", N
,
10501 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
10503 ("type conversions require visibility of the full view",
10506 elsif From_Limited_With
(Target
)
10508 (Is_Access_Type
(Target_Typ
)
10509 and then Present
(Non_Limited_View
(Etype
(Target
))))
10511 Error_Msg_Qual_Level
:= 99;
10512 Error_Msg_NE
-- CODEFIX
10513 ("missing WITH clause on package &", N
,
10514 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
10516 ("type conversions require visibility of the full view",
10520 Expand_Interface_Conversion
(N
);
10523 -- Conversion to interface type
10525 elsif Is_Interface
(Target
) then
10529 if Ekind_In
(Opnd
, E_Protected_Subtype
, E_Task_Subtype
) then
10530 Opnd
:= Etype
(Opnd
);
10533 if Is_Class_Wide_Type
(Opnd
)
10534 or else Interface_Present_In_Ancestor
10538 Expand_Interface_Conversion
(N
);
10540 Error_Msg_Name_1
:= Chars
(Etype
(Target
));
10541 Error_Msg_Name_2
:= Chars
(Opnd
);
10543 ("wrong interface conversion (% is not a progenitor "
10550 -- Ada 2012: if target type has predicates, the result requires a
10551 -- predicate check. If the context is a call to another predicate
10552 -- check we must prevent infinite recursion.
10554 if Has_Predicates
(Target_Typ
) then
10555 if Nkind
(Parent
(N
)) = N_Function_Call
10556 and then Present
(Name
(Parent
(N
)))
10557 and then (Is_Predicate_Function
(Entity
(Name
(Parent
(N
))))
10559 Is_Predicate_Function_M
(Entity
(Name
(Parent
(N
)))))
10564 Apply_Predicate_Check
(N
, Target_Typ
);
10568 -- If at this stage we have a real to integer conversion, make sure
10569 -- that the Do_Range_Check flag is set, because such conversions in
10570 -- general need a range check. We only need this if expansion is off
10571 -- or we are in GNATProve mode.
10573 if Nkind
(N
) = N_Type_Conversion
10574 and then (GNATprove_Mode
or not Expander_Active
)
10575 and then Is_Integer_Type
(Target_Typ
)
10576 and then Is_Real_Type
(Operand_Typ
)
10578 Set_Do_Range_Check
(Operand
);
10580 end Resolve_Type_Conversion
;
10582 ----------------------
10583 -- Resolve_Unary_Op --
10584 ----------------------
10586 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
10587 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
10588 R
: constant Node_Id
:= Right_Opnd
(N
);
10594 if Is_Modular_Integer_Type
(Typ
) and then Nkind
(N
) /= N_Op_Not
then
10595 Error_Msg_Name_1
:= Chars
(Typ
);
10596 Check_SPARK_05_Restriction
10597 ("unary operator not defined for modular type%", N
);
10600 -- Deal with intrinsic unary operators
10602 if Comes_From_Source
(N
)
10603 and then Ekind
(Entity
(N
)) = E_Function
10604 and then Is_Imported
(Entity
(N
))
10605 and then Is_Intrinsic_Subprogram
(Entity
(N
))
10607 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10611 -- Deal with universal cases
10613 if Etype
(R
) = Universal_Integer
10615 Etype
(R
) = Universal_Real
10617 Check_For_Visible_Operator
(N
, B_Typ
);
10620 Set_Etype
(N
, B_Typ
);
10621 Resolve
(R
, B_Typ
);
10623 -- Generate warning for expressions like abs (x mod 2)
10625 if Warn_On_Redundant_Constructs
10626 and then Nkind
(N
) = N_Op_Abs
10628 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
10630 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
10631 Error_Msg_N
-- CODEFIX
10632 ("?r?abs applied to known non-negative value has no effect", N
);
10636 -- Deal with reference generation
10638 Check_Unset_Reference
(R
);
10639 Generate_Operator_Reference
(N
, B_Typ
);
10640 Analyze_Dimension
(N
);
10643 -- Set overflow checking bit. Much cleverer code needed here eventually
10644 -- and perhaps the Resolve routines should be separated for the various
10645 -- arithmetic operations, since they will need different processing ???
10647 if Nkind
(N
) in N_Op
then
10648 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
10649 Enable_Overflow_Check
(N
);
10653 -- Generate warning for expressions like -5 mod 3 for integers. No need
10654 -- to worry in the floating-point case, since parens do not affect the
10655 -- result so there is no point in giving in a warning.
10658 Norig
: constant Node_Id
:= Original_Node
(N
);
10667 if Warn_On_Questionable_Missing_Parens
10668 and then Comes_From_Source
(Norig
)
10669 and then Is_Integer_Type
(Typ
)
10670 and then Nkind
(Norig
) = N_Op_Minus
10672 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
10674 -- We are looking for cases where the right operand is not
10675 -- parenthesized, and is a binary operator, multiply, divide, or
10676 -- mod. These are the cases where the grouping can affect results.
10678 if Paren_Count
(Rorig
) = 0
10679 and then Nkind_In
(Rorig
, N_Op_Mod
, N_Op_Multiply
, N_Op_Divide
)
10681 -- For mod, we always give the warning, since the value is
10682 -- affected by the parenthesization (e.g. (-5) mod 315 /=
10683 -- -(5 mod 315)). But for the other cases, the only concern is
10684 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
10685 -- overflows, but (-2) * 64 does not). So we try to give the
10686 -- message only when overflow is possible.
10688 if Nkind
(Rorig
) /= N_Op_Mod
10689 and then Compile_Time_Known_Value
(R
)
10691 Val
:= Expr_Value
(R
);
10693 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
10694 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
10696 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
10699 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
10700 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
10702 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
10705 -- Note that the test below is deliberately excluding the
10706 -- largest negative number, since that is a potentially
10707 -- troublesome case (e.g. -2 * x, where the result is the
10708 -- largest negative integer has an overflow with 2 * x).
10710 if Val
> LB
and then Val
<= HB
then
10715 -- For the multiplication case, the only case we have to worry
10716 -- about is when (-a)*b is exactly the largest negative number
10717 -- so that -(a*b) can cause overflow. This can only happen if
10718 -- a is a power of 2, and more generally if any operand is a
10719 -- constant that is not a power of 2, then the parentheses
10720 -- cannot affect whether overflow occurs. We only bother to
10721 -- test the left most operand
10723 -- Loop looking at left operands for one that has known value
10726 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
10727 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
10728 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
10730 -- Operand value of 0 or 1 skips warning
10735 -- Otherwise check power of 2, if power of 2, warn, if
10736 -- anything else, skip warning.
10739 while Lval
/= 2 loop
10740 if Lval
mod 2 = 1 then
10751 -- Keep looking at left operands
10753 Opnd
:= Left_Opnd
(Opnd
);
10754 end loop Opnd_Loop
;
10756 -- For rem or "/" we can only have a problematic situation
10757 -- if the divisor has a value of minus one or one. Otherwise
10758 -- overflow is impossible (divisor > 1) or we have a case of
10759 -- division by zero in any case.
10761 if Nkind_In
(Rorig
, N_Op_Divide
, N_Op_Rem
)
10762 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
10763 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
10768 -- If we fall through warning should be issued
10770 -- Shouldn't we test Warn_On_Questionable_Missing_Parens ???
10773 ("??unary minus expression should be parenthesized here!", N
);
10777 end Resolve_Unary_Op
;
10779 ----------------------------------
10780 -- Resolve_Unchecked_Expression --
10781 ----------------------------------
10783 procedure Resolve_Unchecked_Expression
10788 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
10789 Set_Etype
(N
, Typ
);
10790 end Resolve_Unchecked_Expression
;
10792 ---------------------------------------
10793 -- Resolve_Unchecked_Type_Conversion --
10794 ---------------------------------------
10796 procedure Resolve_Unchecked_Type_Conversion
10800 pragma Warnings
(Off
, Typ
);
10802 Operand
: constant Node_Id
:= Expression
(N
);
10803 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
10806 -- Resolve operand using its own type
10808 Resolve
(Operand
, Opnd_Type
);
10810 -- In an inlined context, the unchecked conversion may be applied
10811 -- to a literal, in which case its type is the type of the context.
10812 -- (In other contexts conversions cannot apply to literals).
10815 and then (Opnd_Type
= Any_Character
or else
10816 Opnd_Type
= Any_Integer
or else
10817 Opnd_Type
= Any_Real
)
10819 Set_Etype
(Operand
, Typ
);
10822 Analyze_Dimension
(N
);
10823 Eval_Unchecked_Conversion
(N
);
10824 end Resolve_Unchecked_Type_Conversion
;
10826 ------------------------------
10827 -- Rewrite_Operator_As_Call --
10828 ------------------------------
10830 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
10831 Loc
: constant Source_Ptr
:= Sloc
(N
);
10832 Actuals
: constant List_Id
:= New_List
;
10836 if Nkind
(N
) in N_Binary_Op
then
10837 Append
(Left_Opnd
(N
), Actuals
);
10840 Append
(Right_Opnd
(N
), Actuals
);
10843 Make_Function_Call
(Sloc
=> Loc
,
10844 Name
=> New_Occurrence_Of
(Nam
, Loc
),
10845 Parameter_Associations
=> Actuals
);
10847 Preserve_Comes_From_Source
(New_N
, N
);
10848 Preserve_Comes_From_Source
(Name
(New_N
), N
);
10849 Rewrite
(N
, New_N
);
10850 Set_Etype
(N
, Etype
(Nam
));
10851 end Rewrite_Operator_As_Call
;
10853 ------------------------------
10854 -- Rewrite_Renamed_Operator --
10855 ------------------------------
10857 procedure Rewrite_Renamed_Operator
10862 Nam
: constant Name_Id
:= Chars
(Op
);
10863 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
10867 -- Do not perform this transformation within a pre/postcondition,
10868 -- because the expression will be re-analyzed, and the transformation
10869 -- might affect the visibility of the operator, e.g. in an instance.
10871 if In_Assertion_Expr
> 0 then
10875 -- Rewrite the operator node using the real operator, not its renaming.
10876 -- Exclude user-defined intrinsic operations of the same name, which are
10877 -- treated separately and rewritten as calls.
10879 if Ekind
(Op
) /= E_Function
or else Chars
(N
) /= Nam
then
10880 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
10881 Set_Chars
(Op_Node
, Nam
);
10882 Set_Etype
(Op_Node
, Etype
(N
));
10883 Set_Entity
(Op_Node
, Op
);
10884 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
10886 -- Indicate that both the original entity and its renaming are
10887 -- referenced at this point.
10889 Generate_Reference
(Entity
(N
), N
);
10890 Generate_Reference
(Op
, N
);
10893 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
10896 Rewrite
(N
, Op_Node
);
10898 -- If the context type is private, add the appropriate conversions so
10899 -- that the operator is applied to the full view. This is done in the
10900 -- routines that resolve intrinsic operators.
10902 if Is_Intrinsic_Subprogram
(Op
)
10903 and then Is_Private_Type
(Typ
)
10906 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
10907 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
10908 Resolve_Intrinsic_Operator
(N
, Typ
);
10910 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
10911 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
10918 elsif Ekind
(Op
) = E_Function
and then Is_Intrinsic_Subprogram
(Op
) then
10920 -- Operator renames a user-defined operator of the same name. Use the
10921 -- original operator in the node, which is the one Gigi knows about.
10923 Set_Entity
(N
, Op
);
10924 Set_Is_Overloaded
(N
, False);
10926 end Rewrite_Renamed_Operator
;
10928 -----------------------
10929 -- Set_Slice_Subtype --
10930 -----------------------
10932 -- Build an implicit subtype declaration to represent the type delivered by
10933 -- the slice. This is an abbreviated version of an array subtype. We define
10934 -- an index subtype for the slice, using either the subtype name or the
10935 -- discrete range of the slice. To be consistent with index usage elsewhere
10936 -- we create a list header to hold the single index. This list is not
10937 -- otherwise attached to the syntax tree.
10939 procedure Set_Slice_Subtype
(N
: Node_Id
) is
10940 Loc
: constant Source_Ptr
:= Sloc
(N
);
10941 Index_List
: constant List_Id
:= New_List
;
10943 Index_Subtype
: Entity_Id
;
10944 Index_Type
: Entity_Id
;
10945 Slice_Subtype
: Entity_Id
;
10946 Drange
: constant Node_Id
:= Discrete_Range
(N
);
10949 Index_Type
:= Base_Type
(Etype
(Drange
));
10951 if Is_Entity_Name
(Drange
) then
10952 Index_Subtype
:= Entity
(Drange
);
10955 -- We force the evaluation of a range. This is definitely needed in
10956 -- the renamed case, and seems safer to do unconditionally. Note in
10957 -- any case that since we will create and insert an Itype referring
10958 -- to this range, we must make sure any side effect removal actions
10959 -- are inserted before the Itype definition.
10961 if Nkind
(Drange
) = N_Range
then
10962 Force_Evaluation
(Low_Bound
(Drange
));
10963 Force_Evaluation
(High_Bound
(Drange
));
10965 -- If the discrete range is given by a subtype indication, the
10966 -- type of the slice is the base of the subtype mark.
10968 elsif Nkind
(Drange
) = N_Subtype_Indication
then
10970 R
: constant Node_Id
:= Range_Expression
(Constraint
(Drange
));
10972 Index_Type
:= Base_Type
(Entity
(Subtype_Mark
(Drange
)));
10973 Force_Evaluation
(Low_Bound
(R
));
10974 Force_Evaluation
(High_Bound
(R
));
10978 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
10980 -- Take a new copy of Drange (where bounds have been rewritten to
10981 -- reference side-effect-free names). Using a separate tree ensures
10982 -- that further expansion (e.g. while rewriting a slice assignment
10983 -- into a FOR loop) does not attempt to remove side effects on the
10984 -- bounds again (which would cause the bounds in the index subtype
10985 -- definition to refer to temporaries before they are defined) (the
10986 -- reason is that some names are considered side effect free here
10987 -- for the subtype, but not in the context of a loop iteration
10990 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
10991 Set_Parent
(Scalar_Range
(Index_Subtype
), Index_Subtype
);
10992 Set_Etype
(Index_Subtype
, Index_Type
);
10993 Set_Size_Info
(Index_Subtype
, Index_Type
);
10994 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
10997 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
10999 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
11000 Set_Etype
(Index
, Index_Subtype
);
11001 Append
(Index
, Index_List
);
11003 Set_First_Index
(Slice_Subtype
, Index
);
11004 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
11005 Set_Is_Constrained
(Slice_Subtype
, True);
11007 Check_Compile_Time_Size
(Slice_Subtype
);
11009 -- The Etype of the existing Slice node is reset to this slice subtype.
11010 -- Its bounds are obtained from its first index.
11012 Set_Etype
(N
, Slice_Subtype
);
11014 -- For packed slice subtypes, freeze immediately (except in the case of
11015 -- being in a "spec expression" where we never freeze when we first see
11016 -- the expression).
11018 if Is_Packed
(Slice_Subtype
) and not In_Spec_Expression
then
11019 Freeze_Itype
(Slice_Subtype
, N
);
11021 -- For all other cases insert an itype reference in the slice's actions
11022 -- so that the itype is frozen at the proper place in the tree (i.e. at
11023 -- the point where actions for the slice are analyzed). Note that this
11024 -- is different from freezing the itype immediately, which might be
11025 -- premature (e.g. if the slice is within a transient scope). This needs
11026 -- to be done only if expansion is enabled.
11028 elsif Expander_Active
then
11029 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
11031 end Set_Slice_Subtype
;
11033 --------------------------------
11034 -- Set_String_Literal_Subtype --
11035 --------------------------------
11037 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
11038 Loc
: constant Source_Ptr
:= Sloc
(N
);
11039 Low_Bound
: constant Node_Id
:=
11040 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
11041 Subtype_Id
: Entity_Id
;
11044 if Nkind
(N
) /= N_String_Literal
then
11048 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
11049 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
11050 (String_Length
(Strval
(N
))));
11051 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
11052 Set_Is_Constrained
(Subtype_Id
);
11053 Set_Etype
(N
, Subtype_Id
);
11055 -- The low bound is set from the low bound of the corresponding index
11056 -- type. Note that we do not store the high bound in the string literal
11057 -- subtype, but it can be deduced if necessary from the length and the
11060 if Is_OK_Static_Expression
(Low_Bound
) then
11061 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
11063 -- If the lower bound is not static we create a range for the string
11064 -- literal, using the index type and the known length of the literal.
11065 -- The index type is not necessarily Positive, so the upper bound is
11066 -- computed as T'Val (T'Pos (Low_Bound) + L - 1).
11070 Index_List
: constant List_Id
:= New_List
;
11071 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
11072 High_Bound
: constant Node_Id
:=
11073 Make_Attribute_Reference
(Loc
,
11074 Attribute_Name
=> Name_Val
,
11076 New_Occurrence_Of
(Index_Type
, Loc
),
11077 Expressions
=> New_List
(
11080 Make_Attribute_Reference
(Loc
,
11081 Attribute_Name
=> Name_Pos
,
11083 New_Occurrence_Of
(Index_Type
, Loc
),
11085 New_List
(New_Copy_Tree
(Low_Bound
))),
11087 Make_Integer_Literal
(Loc
,
11088 String_Length
(Strval
(N
)) - 1))));
11090 Array_Subtype
: Entity_Id
;
11093 Index_Subtype
: Entity_Id
;
11096 if Is_Integer_Type
(Index_Type
) then
11097 Set_String_Literal_Low_Bound
11098 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
11101 -- If the index type is an enumeration type, build bounds
11102 -- expression with attributes.
11104 Set_String_Literal_Low_Bound
11106 Make_Attribute_Reference
(Loc
,
11107 Attribute_Name
=> Name_First
,
11109 New_Occurrence_Of
(Base_Type
(Index_Type
), Loc
)));
11110 Set_Etype
(String_Literal_Low_Bound
(Subtype_Id
), Index_Type
);
11113 Analyze_And_Resolve
(String_Literal_Low_Bound
(Subtype_Id
));
11115 -- Build bona fide subtype for the string, and wrap it in an
11116 -- unchecked conversion, because the backend expects the
11117 -- String_Literal_Subtype to have a static lower bound.
11120 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
11121 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
11122 Set_Scalar_Range
(Index_Subtype
, Drange
);
11123 Set_Parent
(Drange
, N
);
11124 Analyze_And_Resolve
(Drange
, Index_Type
);
11126 -- In the context, the Index_Type may already have a constraint,
11127 -- so use common base type on string subtype. The base type may
11128 -- be used when generating attributes of the string, for example
11129 -- in the context of a slice assignment.
11131 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
11132 Set_Size_Info
(Index_Subtype
, Index_Type
);
11133 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
11135 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
11137 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
11138 Set_Etype
(Index
, Index_Subtype
);
11139 Append
(Index
, Index_List
);
11141 Set_First_Index
(Array_Subtype
, Index
);
11142 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
11143 Set_Is_Constrained
(Array_Subtype
, True);
11146 Make_Unchecked_Type_Conversion
(Loc
,
11147 Subtype_Mark
=> New_Occurrence_Of
(Array_Subtype
, Loc
),
11148 Expression
=> Relocate_Node
(N
)));
11149 Set_Etype
(N
, Array_Subtype
);
11152 end Set_String_Literal_Subtype
;
11154 ------------------------------
11155 -- Simplify_Type_Conversion --
11156 ------------------------------
11158 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
11160 if Nkind
(N
) = N_Type_Conversion
then
11162 Operand
: constant Node_Id
:= Expression
(N
);
11163 Target_Typ
: constant Entity_Id
:= Etype
(N
);
11164 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
11167 -- Special processing if the conversion is the expression of a
11168 -- Rounding or Truncation attribute reference. In this case we
11171 -- ityp (ftyp'Rounding (x)) or ityp (ftyp'Truncation (x))
11177 -- with the Float_Truncate flag set to False or True respectively,
11178 -- which is more efficient.
11180 if Is_Floating_Point_Type
(Opnd_Typ
)
11182 (Is_Integer_Type
(Target_Typ
)
11183 or else (Is_Fixed_Point_Type
(Target_Typ
)
11184 and then Conversion_OK
(N
)))
11185 and then Nkind
(Operand
) = N_Attribute_Reference
11186 and then Nam_In
(Attribute_Name
(Operand
), Name_Rounding
,
11190 Truncate
: constant Boolean :=
11191 Attribute_Name
(Operand
) = Name_Truncation
;
11194 Relocate_Node
(First
(Expressions
(Operand
))));
11195 Set_Float_Truncate
(N
, Truncate
);
11200 end Simplify_Type_Conversion
;
11202 -----------------------------
11203 -- Unique_Fixed_Point_Type --
11204 -----------------------------
11206 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
11207 T1
: Entity_Id
:= Empty
;
11212 procedure Fixed_Point_Error
;
11213 -- Give error messages for true ambiguity. Messages are posted on node
11214 -- N, and entities T1, T2 are the possible interpretations.
11216 -----------------------
11217 -- Fixed_Point_Error --
11218 -----------------------
11220 procedure Fixed_Point_Error
is
11222 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
11223 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
11224 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
11225 end Fixed_Point_Error
;
11227 -- Start of processing for Unique_Fixed_Point_Type
11230 -- The operations on Duration are visible, so Duration is always a
11231 -- possible interpretation.
11233 T1
:= Standard_Duration
;
11235 -- Look for fixed-point types in enclosing scopes
11237 Scop
:= Current_Scope
;
11238 while Scop
/= Standard_Standard
loop
11239 T2
:= First_Entity
(Scop
);
11240 while Present
(T2
) loop
11241 if Is_Fixed_Point_Type
(T2
)
11242 and then Current_Entity
(T2
) = T2
11243 and then Scope
(Base_Type
(T2
)) = Scop
11245 if Present
(T1
) then
11256 Scop
:= Scope
(Scop
);
11259 -- Look for visible fixed type declarations in the context
11261 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
11262 while Present
(Item
) loop
11263 if Nkind
(Item
) = N_With_Clause
then
11264 Scop
:= Entity
(Name
(Item
));
11265 T2
:= First_Entity
(Scop
);
11266 while Present
(T2
) loop
11267 if Is_Fixed_Point_Type
(T2
)
11268 and then Scope
(Base_Type
(T2
)) = Scop
11269 and then (Is_Potentially_Use_Visible
(T2
) or else In_Use
(T2
))
11271 if Present
(T1
) then
11286 if Nkind
(N
) = N_Real_Literal
then
11288 ("??real literal interpreted as }!", N
, T1
);
11291 ("??universal_fixed expression interpreted as }!", N
, T1
);
11295 end Unique_Fixed_Point_Type
;
11297 ----------------------
11298 -- Valid_Conversion --
11299 ----------------------
11301 function Valid_Conversion
11303 Target
: Entity_Id
;
11305 Report_Errs
: Boolean := True) return Boolean
11307 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
11308 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
11309 Inc_Ancestor
: Entity_Id
;
11311 function Conversion_Check
11313 Msg
: String) return Boolean;
11314 -- Little routine to post Msg if Valid is False, returns Valid value
11316 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
);
11317 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
11319 procedure Conversion_Error_NE
11321 N
: Node_Or_Entity_Id
;
11322 E
: Node_Or_Entity_Id
);
11323 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
11325 function Valid_Tagged_Conversion
11326 (Target_Type
: Entity_Id
;
11327 Opnd_Type
: Entity_Id
) return Boolean;
11328 -- Specifically test for validity of tagged conversions
11330 function Valid_Array_Conversion
return Boolean;
11331 -- Check index and component conformance, and accessibility levels if
11332 -- the component types are anonymous access types (Ada 2005).
11334 ----------------------
11335 -- Conversion_Check --
11336 ----------------------
11338 function Conversion_Check
11340 Msg
: String) return Boolean
11345 -- A generic unit has already been analyzed and we have verified
11346 -- that a particular conversion is OK in that context. Since the
11347 -- instance is reanalyzed without relying on the relationships
11348 -- established during the analysis of the generic, it is possible
11349 -- to end up with inconsistent views of private types. Do not emit
11350 -- the error message in such cases. The rest of the machinery in
11351 -- Valid_Conversion still ensures the proper compatibility of
11352 -- target and operand types.
11354 and then not In_Instance
11356 Conversion_Error_N
(Msg
, Operand
);
11360 end Conversion_Check
;
11362 ------------------------
11363 -- Conversion_Error_N --
11364 ------------------------
11366 procedure Conversion_Error_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
11368 if Report_Errs
then
11369 Error_Msg_N
(Msg
, N
);
11371 end Conversion_Error_N
;
11373 -------------------------
11374 -- Conversion_Error_NE --
11375 -------------------------
11377 procedure Conversion_Error_NE
11379 N
: Node_Or_Entity_Id
;
11380 E
: Node_Or_Entity_Id
)
11383 if Report_Errs
then
11384 Error_Msg_NE
(Msg
, N
, E
);
11386 end Conversion_Error_NE
;
11388 ----------------------------
11389 -- Valid_Array_Conversion --
11390 ----------------------------
11392 function Valid_Array_Conversion
return Boolean
11394 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
11395 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
11397 Opnd_Index
: Node_Id
;
11398 Opnd_Index_Type
: Entity_Id
;
11400 Target_Comp_Type
: constant Entity_Id
:=
11401 Component_Type
(Target_Type
);
11402 Target_Comp_Base
: constant Entity_Id
:=
11403 Base_Type
(Target_Comp_Type
);
11405 Target_Index
: Node_Id
;
11406 Target_Index_Type
: Entity_Id
;
11409 -- Error if wrong number of dimensions
11412 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
11415 ("incompatible number of dimensions for conversion", Operand
);
11418 -- Number of dimensions matches
11421 -- Loop through indexes of the two arrays
11423 Target_Index
:= First_Index
(Target_Type
);
11424 Opnd_Index
:= First_Index
(Opnd_Type
);
11425 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
11426 Target_Index_Type
:= Etype
(Target_Index
);
11427 Opnd_Index_Type
:= Etype
(Opnd_Index
);
11429 -- Error if index types are incompatible
11431 if not (Is_Integer_Type
(Target_Index_Type
)
11432 and then Is_Integer_Type
(Opnd_Index_Type
))
11433 and then (Root_Type
(Target_Index_Type
)
11434 /= Root_Type
(Opnd_Index_Type
))
11437 ("incompatible index types for array conversion",
11442 Next_Index
(Target_Index
);
11443 Next_Index
(Opnd_Index
);
11446 -- If component types have same base type, all set
11448 if Target_Comp_Base
= Opnd_Comp_Base
then
11451 -- Here if base types of components are not the same. The only
11452 -- time this is allowed is if we have anonymous access types.
11454 -- The conversion of arrays of anonymous access types can lead
11455 -- to dangling pointers. AI-392 formalizes the accessibility
11456 -- checks that must be applied to such conversions to prevent
11457 -- out-of-scope references.
11460 (Target_Comp_Base
, E_Anonymous_Access_Type
,
11461 E_Anonymous_Access_Subprogram_Type
)
11462 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
11464 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
11466 if Type_Access_Level
(Target_Type
) <
11467 Deepest_Type_Access_Level
(Opnd_Type
)
11469 if In_Instance_Body
then
11470 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11472 ("source array type has deeper accessibility "
11473 & "level than target<<", Operand
);
11474 Conversion_Error_N
("\Program_Error [<<", Operand
);
11476 Make_Raise_Program_Error
(Sloc
(N
),
11477 Reason
=> PE_Accessibility_Check_Failed
));
11478 Set_Etype
(N
, Target_Type
);
11481 -- Conversion not allowed because of accessibility levels
11485 ("source array type has deeper accessibility "
11486 & "level than target", Operand
);
11494 -- All other cases where component base types do not match
11498 ("incompatible component types for array conversion",
11503 -- Check that component subtypes statically match. For numeric
11504 -- types this means that both must be either constrained or
11505 -- unconstrained. For enumeration types the bounds must match.
11506 -- All of this is checked in Subtypes_Statically_Match.
11508 if not Subtypes_Statically_Match
11509 (Target_Comp_Type
, Opnd_Comp_Type
)
11512 ("component subtypes must statically match", Operand
);
11518 end Valid_Array_Conversion
;
11520 -----------------------------
11521 -- Valid_Tagged_Conversion --
11522 -----------------------------
11524 function Valid_Tagged_Conversion
11525 (Target_Type
: Entity_Id
;
11526 Opnd_Type
: Entity_Id
) return Boolean
11529 -- Upward conversions are allowed (RM 4.6(22))
11531 if Covers
(Target_Type
, Opnd_Type
)
11532 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
11536 -- Downward conversion are allowed if the operand is class-wide
11539 elsif Is_Class_Wide_Type
(Opnd_Type
)
11540 and then Covers
(Opnd_Type
, Target_Type
)
11544 elsif Covers
(Opnd_Type
, Target_Type
)
11545 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
11548 Conversion_Check
(False,
11549 "downward conversion of tagged objects not allowed");
11551 -- Ada 2005 (AI-251): The conversion to/from interface types is
11554 elsif Is_Interface
(Target_Type
) or else Is_Interface
(Opnd_Type
) then
11557 -- If the operand is a class-wide type obtained through a limited_
11558 -- with clause, and the context includes the non-limited view, use
11559 -- it to determine whether the conversion is legal.
11561 elsif Is_Class_Wide_Type
(Opnd_Type
)
11562 and then From_Limited_With
(Opnd_Type
)
11563 and then Present
(Non_Limited_View
(Etype
(Opnd_Type
)))
11564 and then Is_Interface
(Non_Limited_View
(Etype
(Opnd_Type
)))
11568 elsif Is_Access_Type
(Opnd_Type
)
11569 and then Is_Interface
(Directly_Designated_Type
(Opnd_Type
))
11574 Conversion_Error_NE
11575 ("invalid tagged conversion, not compatible with}",
11576 N
, First_Subtype
(Opnd_Type
));
11579 end Valid_Tagged_Conversion
;
11581 -- Start of processing for Valid_Conversion
11584 Check_Parameterless_Call
(Operand
);
11586 if Is_Overloaded
(Operand
) then
11596 -- Remove procedure calls, which syntactically cannot appear in
11597 -- this context, but which cannot be removed by type checking,
11598 -- because the context does not impose a type.
11600 -- The node may be labelled overloaded, but still contain only one
11601 -- interpretation because others were discarded earlier. If this
11602 -- is the case, retain the single interpretation if legal.
11604 Get_First_Interp
(Operand
, I
, It
);
11605 Opnd_Type
:= It
.Typ
;
11606 Get_Next_Interp
(I
, It
);
11608 if Present
(It
.Typ
)
11609 and then Opnd_Type
/= Standard_Void_Type
11611 -- More than one candidate interpretation is available
11613 Get_First_Interp
(Operand
, I
, It
);
11614 while Present
(It
.Typ
) loop
11615 if It
.Typ
= Standard_Void_Type
then
11619 -- When compiling for a system where Address is of a visible
11620 -- integer type, spurious ambiguities can be produced when
11621 -- arithmetic operations have a literal operand and return
11622 -- System.Address or a descendant of it. These ambiguities
11623 -- are usually resolved by the context, but for conversions
11624 -- there is no context type and the removal of the spurious
11625 -- operations must be done explicitly here.
11627 if not Address_Is_Private
11628 and then Is_Descendent_Of_Address
(It
.Typ
)
11633 Get_Next_Interp
(I
, It
);
11637 Get_First_Interp
(Operand
, I
, It
);
11641 if No
(It
.Typ
) then
11642 Conversion_Error_N
("illegal operand in conversion", Operand
);
11646 Get_Next_Interp
(I
, It
);
11648 if Present
(It
.Typ
) then
11651 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
11653 if It1
= No_Interp
then
11655 ("ambiguous operand in conversion", Operand
);
11657 -- If the interpretation involves a standard operator, use
11658 -- the location of the type, which may be user-defined.
11660 if Sloc
(It
.Nam
) = Standard_Location
then
11661 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
11663 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
11666 Conversion_Error_N
-- CODEFIX
11667 ("\\possible interpretation#!", Operand
);
11669 if Sloc
(N1
) = Standard_Location
then
11670 Error_Msg_Sloc
:= Sloc
(T1
);
11672 Error_Msg_Sloc
:= Sloc
(N1
);
11675 Conversion_Error_N
-- CODEFIX
11676 ("\\possible interpretation#!", Operand
);
11682 Set_Etype
(Operand
, It1
.Typ
);
11683 Opnd_Type
:= It1
.Typ
;
11687 -- Deal with conversion of integer type to address if the pragma
11688 -- Allow_Integer_Address is in effect. We convert the conversion to
11689 -- an unchecked conversion in this case and we are all done.
11691 if Address_Integer_Convert_OK
(Opnd_Type
, Target_Type
) then
11692 Rewrite
(N
, Unchecked_Convert_To
(Target_Type
, Expression
(N
)));
11693 Analyze_And_Resolve
(N
, Target_Type
);
11697 -- If we are within a child unit, check whether the type of the
11698 -- expression has an ancestor in a parent unit, in which case it
11699 -- belongs to its derivation class even if the ancestor is private.
11700 -- See RM 7.3.1 (5.2/3).
11702 Inc_Ancestor
:= Get_Incomplete_View_Of_Ancestor
(Opnd_Type
);
11706 if Is_Numeric_Type
(Target_Type
) then
11708 -- A universal fixed expression can be converted to any numeric type
11710 if Opnd_Type
= Universal_Fixed
then
11713 -- Also no need to check when in an instance or inlined body, because
11714 -- the legality has been established when the template was analyzed.
11715 -- Furthermore, numeric conversions may occur where only a private
11716 -- view of the operand type is visible at the instantiation point.
11717 -- This results in a spurious error if we check that the operand type
11718 -- is a numeric type.
11720 -- Note: in a previous version of this unit, the following tests were
11721 -- applied only for generated code (Comes_From_Source set to False),
11722 -- but in fact the test is required for source code as well, since
11723 -- this situation can arise in source code.
11725 elsif In_Instance
or else In_Inlined_Body
then
11728 -- Otherwise we need the conversion check
11731 return Conversion_Check
11732 (Is_Numeric_Type
(Opnd_Type
)
11734 (Present
(Inc_Ancestor
)
11735 and then Is_Numeric_Type
(Inc_Ancestor
)),
11736 "illegal operand for numeric conversion");
11741 elsif Is_Array_Type
(Target_Type
) then
11742 if not Is_Array_Type
(Opnd_Type
)
11743 or else Opnd_Type
= Any_Composite
11744 or else Opnd_Type
= Any_String
11747 ("illegal operand for array conversion", Operand
);
11751 return Valid_Array_Conversion
;
11754 -- Ada 2005 (AI-251): Anonymous access types where target references an
11757 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11758 E_Anonymous_Access_Type
)
11759 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
11761 -- Check the static accessibility rule of 4.6(17). Note that the
11762 -- check is not enforced when within an instance body, since the
11763 -- RM requires such cases to be caught at run time.
11765 -- If the operand is a rewriting of an allocator no check is needed
11766 -- because there are no accessibility issues.
11768 if Nkind
(Original_Node
(N
)) = N_Allocator
then
11771 elsif Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
11772 if Type_Access_Level
(Opnd_Type
) >
11773 Deepest_Type_Access_Level
(Target_Type
)
11775 -- In an instance, this is a run-time check, but one we know
11776 -- will fail, so generate an appropriate warning. The raise
11777 -- will be generated by Expand_N_Type_Conversion.
11779 if In_Instance_Body
then
11780 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11782 ("cannot convert local pointer to non-local access type<<",
11784 Conversion_Error_N
("\Program_Error [<<", Operand
);
11788 ("cannot convert local pointer to non-local access type",
11793 -- Special accessibility checks are needed in the case of access
11794 -- discriminants declared for a limited type.
11796 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11797 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11799 -- When the operand is a selected access discriminant the check
11800 -- needs to be made against the level of the object denoted by
11801 -- the prefix of the selected name (Object_Access_Level handles
11802 -- checking the prefix of the operand for this case).
11804 if Nkind
(Operand
) = N_Selected_Component
11805 and then Object_Access_Level
(Operand
) >
11806 Deepest_Type_Access_Level
(Target_Type
)
11808 -- In an instance, this is a run-time check, but one we know
11809 -- will fail, so generate an appropriate warning. The raise
11810 -- will be generated by Expand_N_Type_Conversion.
11812 if In_Instance_Body
then
11813 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11815 ("cannot convert access discriminant to non-local "
11816 & "access type<<", Operand
);
11817 Conversion_Error_N
("\Program_Error [<<", Operand
);
11819 -- Real error if not in instance body
11823 ("cannot convert access discriminant to non-local "
11824 & "access type", Operand
);
11829 -- The case of a reference to an access discriminant from
11830 -- within a limited type declaration (which will appear as
11831 -- a discriminal) is always illegal because the level of the
11832 -- discriminant is considered to be deeper than any (nameable)
11835 if Is_Entity_Name
(Operand
)
11836 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11838 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
11839 and then Present
(Discriminal_Link
(Entity
(Operand
)))
11842 ("discriminant has deeper accessibility level than target",
11851 -- General and anonymous access types
11853 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
11854 E_Anonymous_Access_Type
)
11857 (Is_Access_Type
(Opnd_Type
)
11859 Ekind_In
(Opnd_Type
, E_Access_Subprogram_Type
,
11860 E_Access_Protected_Subprogram_Type
),
11861 "must be an access-to-object type")
11863 if Is_Access_Constant
(Opnd_Type
)
11864 and then not Is_Access_Constant
(Target_Type
)
11867 ("access-to-constant operand type not allowed", Operand
);
11871 -- Check the static accessibility rule of 4.6(17). Note that the
11872 -- check is not enforced when within an instance body, since the RM
11873 -- requires such cases to be caught at run time.
11875 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
11876 or else Is_Local_Anonymous_Access
(Target_Type
)
11877 or else Nkind
(Associated_Node_For_Itype
(Target_Type
)) =
11878 N_Object_Declaration
11880 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
11881 -- conversions from an anonymous access type to a named general
11882 -- access type. Such conversions are not allowed in the case of
11883 -- access parameters and stand-alone objects of an anonymous
11884 -- access type. The implicit conversion case is recognized by
11885 -- testing that Comes_From_Source is False and that it's been
11886 -- rewritten. The Comes_From_Source test isn't sufficient because
11887 -- nodes in inlined calls to predefined library routines can have
11888 -- Comes_From_Source set to False. (Is there a better way to test
11889 -- for implicit conversions???)
11891 if Ada_Version
>= Ada_2012
11892 and then not Comes_From_Source
(N
)
11893 and then N
/= Original_Node
(N
)
11894 and then Ekind
(Target_Type
) = E_General_Access_Type
11895 and then Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11897 if Is_Itype
(Opnd_Type
) then
11899 -- Implicit conversions aren't allowed for objects of an
11900 -- anonymous access type, since such objects have nonstatic
11901 -- levels in Ada 2012.
11903 if Nkind
(Associated_Node_For_Itype
(Opnd_Type
)) =
11904 N_Object_Declaration
11907 ("implicit conversion of stand-alone anonymous "
11908 & "access object not allowed", Operand
);
11911 -- Implicit conversions aren't allowed for anonymous access
11912 -- parameters. The "not Is_Local_Anonymous_Access_Type" test
11913 -- is done to exclude anonymous access results.
11915 elsif not Is_Local_Anonymous_Access
(Opnd_Type
)
11916 and then Nkind_In
(Associated_Node_For_Itype
(Opnd_Type
),
11917 N_Function_Specification
,
11918 N_Procedure_Specification
)
11921 ("implicit conversion of anonymous access formal "
11922 & "not allowed", Operand
);
11925 -- This is a case where there's an enclosing object whose
11926 -- to which the "statically deeper than" relationship does
11927 -- not apply (such as an access discriminant selected from
11928 -- a dereference of an access parameter).
11930 elsif Object_Access_Level
(Operand
)
11931 = Scope_Depth
(Standard_Standard
)
11934 ("implicit conversion of anonymous access value "
11935 & "not allowed", Operand
);
11938 -- In other cases, the level of the operand's type must be
11939 -- statically less deep than that of the target type, else
11940 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
11942 elsif Type_Access_Level
(Opnd_Type
) >
11943 Deepest_Type_Access_Level
(Target_Type
)
11946 ("implicit conversion of anonymous access value "
11947 & "violates accessibility", Operand
);
11952 elsif Type_Access_Level
(Opnd_Type
) >
11953 Deepest_Type_Access_Level
(Target_Type
)
11955 -- In an instance, this is a run-time check, but one we know
11956 -- will fail, so generate an appropriate warning. The raise
11957 -- will be generated by Expand_N_Type_Conversion.
11959 if In_Instance_Body
then
11960 Error_Msg_Warn
:= SPARK_Mode
/= On
;
11962 ("cannot convert local pointer to non-local access type<<",
11964 Conversion_Error_N
("\Program_Error [<<", Operand
);
11966 -- If not in an instance body, this is a real error
11969 -- Avoid generation of spurious error message
11971 if not Error_Posted
(N
) then
11973 ("cannot convert local pointer to non-local access type",
11980 -- Special accessibility checks are needed in the case of access
11981 -- discriminants declared for a limited type.
11983 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
11984 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
11986 -- When the operand is a selected access discriminant the check
11987 -- needs to be made against the level of the object denoted by
11988 -- the prefix of the selected name (Object_Access_Level handles
11989 -- checking the prefix of the operand for this case).
11991 if Nkind
(Operand
) = N_Selected_Component
11992 and then Object_Access_Level
(Operand
) >
11993 Deepest_Type_Access_Level
(Target_Type
)
11995 -- In an instance, this is a run-time check, but one we know
11996 -- will fail, so generate an appropriate warning. The raise
11997 -- will be generated by Expand_N_Type_Conversion.
11999 if In_Instance_Body
then
12000 Error_Msg_Warn
:= SPARK_Mode
/= On
;
12002 ("cannot convert access discriminant to non-local "
12003 & "access type<<", Operand
);
12004 Conversion_Error_N
("\Program_Error [<<", Operand
);
12006 -- If not in an instance body, this is a real error
12010 ("cannot convert access discriminant to non-local "
12011 & "access type", Operand
);
12016 -- The case of a reference to an access discriminant from
12017 -- within a limited type declaration (which will appear as
12018 -- a discriminal) is always illegal because the level of the
12019 -- discriminant is considered to be deeper than any (nameable)
12022 if Is_Entity_Name
(Operand
)
12024 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
12025 and then Present
(Discriminal_Link
(Entity
(Operand
)))
12028 ("discriminant has deeper accessibility level than target",
12035 -- In the presence of limited_with clauses we have to use non-limited
12036 -- views, if available.
12038 Check_Limited
: declare
12039 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
12040 -- Helper function to handle limited views
12042 --------------------------
12043 -- Full_Designated_Type --
12044 --------------------------
12046 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
12047 Desig
: constant Entity_Id
:= Designated_Type
(T
);
12050 -- Handle the limited view of a type
12052 if Is_Incomplete_Type
(Desig
)
12053 and then From_Limited_With
(Desig
)
12054 and then Present
(Non_Limited_View
(Desig
))
12056 return Available_View
(Desig
);
12060 end Full_Designated_Type
;
12062 -- Local Declarations
12064 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
12065 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
12067 Same_Base
: constant Boolean :=
12068 Base_Type
(Target
) = Base_Type
(Opnd
);
12070 -- Start of processing for Check_Limited
12073 if Is_Tagged_Type
(Target
) then
12074 return Valid_Tagged_Conversion
(Target
, Opnd
);
12077 if not Same_Base
then
12078 Conversion_Error_NE
12079 ("target designated type not compatible with }",
12080 N
, Base_Type
(Opnd
));
12083 -- Ada 2005 AI-384: legality rule is symmetric in both
12084 -- designated types. The conversion is legal (with possible
12085 -- constraint check) if either designated type is
12088 elsif Subtypes_Statically_Match
(Target
, Opnd
)
12090 (Has_Discriminants
(Target
)
12092 (not Is_Constrained
(Opnd
)
12093 or else not Is_Constrained
(Target
)))
12095 -- Special case, if Value_Size has been used to make the
12096 -- sizes different, the conversion is not allowed even
12097 -- though the subtypes statically match.
12099 if Known_Static_RM_Size
(Target
)
12100 and then Known_Static_RM_Size
(Opnd
)
12101 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
12103 Conversion_Error_NE
12104 ("target designated subtype not compatible with }",
12106 Conversion_Error_NE
12107 ("\because sizes of the two designated subtypes differ",
12111 -- Normal case where conversion is allowed
12119 ("target designated subtype not compatible with }",
12126 -- Access to subprogram types. If the operand is an access parameter,
12127 -- the type has a deeper accessibility that any master, and cannot be
12128 -- assigned. We must make an exception if the conversion is part of an
12129 -- assignment and the target is the return object of an extended return
12130 -- statement, because in that case the accessibility check takes place
12131 -- after the return.
12133 elsif Is_Access_Subprogram_Type
(Target_Type
)
12135 -- Note: this test of Opnd_Type is there to prevent entering this
12136 -- branch in the case of a remote access to subprogram type, which
12137 -- is internally represented as an E_Record_Type.
12139 and then Is_Access_Type
(Opnd_Type
)
12141 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
12142 and then Is_Entity_Name
(Operand
)
12143 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
12145 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
12146 or else not Is_Entity_Name
(Name
(Parent
(N
)))
12147 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
12150 ("illegal attempt to store anonymous access to subprogram",
12153 ("\value has deeper accessibility than any master "
12154 & "(RM 3.10.2 (13))",
12158 ("\use named access type for& instead of access parameter",
12159 Operand
, Entity
(Operand
));
12162 -- Check that the designated types are subtype conformant
12164 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
12165 Old_Id
=> Designated_Type
(Opnd_Type
),
12168 -- Check the static accessibility rule of 4.6(20)
12170 if Type_Access_Level
(Opnd_Type
) >
12171 Deepest_Type_Access_Level
(Target_Type
)
12174 ("operand type has deeper accessibility level than target",
12177 -- Check that if the operand type is declared in a generic body,
12178 -- then the target type must be declared within that same body
12179 -- (enforces last sentence of 4.6(20)).
12181 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
12183 O_Gen
: constant Node_Id
:=
12184 Enclosing_Generic_Body
(Opnd_Type
);
12189 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
12190 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
12191 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
12194 if T_Gen
/= O_Gen
then
12196 ("target type must be declared in same generic body "
12197 & "as operand type", N
);
12204 -- Remote access to subprogram types
12206 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
12207 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
12209 -- It is valid to convert from one RAS type to another provided
12210 -- that their specification statically match.
12212 -- Note: at this point, remote access to subprogram types have been
12213 -- expanded to their E_Record_Type representation, and we need to
12214 -- go back to the original access type definition using the
12215 -- Corresponding_Remote_Type attribute in order to check that the
12216 -- designated profiles match.
12218 pragma Assert
(Ekind
(Target_Type
) = E_Record_Type
);
12219 pragma Assert
(Ekind
(Opnd_Type
) = E_Record_Type
);
12221 Check_Subtype_Conformant
12223 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
12225 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
12230 -- If it was legal in the generic, it's legal in the instance
12232 elsif In_Instance_Body
then
12235 -- If both are tagged types, check legality of view conversions
12237 elsif Is_Tagged_Type
(Target_Type
)
12239 Is_Tagged_Type
(Opnd_Type
)
12241 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
12243 -- Types derived from the same root type are convertible
12245 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
12248 -- In an instance or an inlined body, there may be inconsistent views of
12249 -- the same type, or of types derived from a common root.
12251 elsif (In_Instance
or In_Inlined_Body
)
12253 Root_Type
(Underlying_Type
(Target_Type
)) =
12254 Root_Type
(Underlying_Type
(Opnd_Type
))
12258 -- Special check for common access type error case
12260 elsif Ekind
(Target_Type
) = E_Access_Type
12261 and then Is_Access_Type
(Opnd_Type
)
12263 Conversion_Error_N
("target type must be general access type!", N
);
12264 Conversion_Error_NE
-- CODEFIX
12265 ("add ALL to }!", N
, Target_Type
);
12268 -- Here we have a real conversion error
12271 Conversion_Error_NE
12272 ("invalid conversion, not compatible with }", N
, Opnd_Type
);
12275 end Valid_Conversion
;