1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Expander
; use Expander
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Ch6
; use Exp_Ch6
;
36 with Exp_Ch7
; use Exp_Ch7
;
37 with Exp_Tss
; use Exp_Tss
;
38 with Exp_Util
; use Exp_Util
;
39 with Fname
; use Fname
;
40 with Freeze
; use Freeze
;
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_Disp
; use Sem_Disp
;
62 with Sem_Dist
; use Sem_Dist
;
63 with Sem_Elim
; use Sem_Elim
;
64 with Sem_Elab
; use Sem_Elab
;
65 with Sem_Eval
; use Sem_Eval
;
66 with Sem_Intr
; use Sem_Intr
;
67 with Sem_Util
; use Sem_Util
;
68 with Sem_Type
; use Sem_Type
;
69 with Sem_Warn
; use Sem_Warn
;
70 with Sinfo
; use Sinfo
;
71 with Snames
; use Snames
;
72 with Stand
; use Stand
;
73 with Stringt
; use Stringt
;
74 with Style
; use Style
;
75 with Tbuild
; use Tbuild
;
76 with Uintp
; use Uintp
;
77 with Urealp
; use Urealp
;
79 package body Sem_Res
is
81 -----------------------
82 -- Local Subprograms --
83 -----------------------
85 -- Second pass (top-down) type checking and overload resolution procedures
86 -- Typ is the type required by context. These procedures propagate the
87 -- type information recursively to the descendants of N. If the node
88 -- is not overloaded, its Etype is established in the first pass. If
89 -- overloaded, the Resolve routines set the correct type. For arith.
90 -- operators, the Etype is the base type of the context.
92 -- Note that Resolve_Attribute is separated off in Sem_Attr
94 procedure Check_Discriminant_Use
(N
: Node_Id
);
95 -- Enforce the restrictions on the use of discriminants when constraining
96 -- a component of a discriminated type (record or concurrent type).
98 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
);
99 -- Given a node for an operator associated with type T, check that
100 -- the operator is visible. Operators all of whose operands are
101 -- universal must be checked for visibility during resolution
102 -- because their type is not determinable based on their operands.
104 procedure Check_Fully_Declared_Prefix
107 -- Check that the type of the prefix of a dereference is not incomplete
109 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean;
110 -- Given a call node, N, which is known to occur immediately within the
111 -- subprogram being called, determines whether it is a detectable case of
112 -- an infinite recursion, and if so, outputs appropriate messages. Returns
113 -- True if an infinite recursion is detected, and False otherwise.
115 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
);
116 -- If the type of the object being initialized uses the secondary stack
117 -- directly or indirectly, create a transient scope for the call to the
118 -- init proc. This is because we do not create transient scopes for the
119 -- initialization of individual components within the init proc itself.
120 -- Could be optimized away perhaps?
122 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
);
123 -- N is the node for a logical operator. If the operator is predefined, and
124 -- the root type of the operands is Standard.Boolean, then a check is made
125 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
126 -- the style check for Style_Check_Boolean_And_Or.
128 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean;
129 -- Determine whether E is an access type declared by an access
130 -- declaration, and not an (anonymous) allocator type.
132 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean;
133 -- Utility to check whether the entity for an operator is a predefined
134 -- operator, in which case the expression is left as an operator in the
135 -- tree (else it is rewritten into a call). An instance of an intrinsic
136 -- conversion operation may be given an operator name, but is not treated
137 -- like an operator. Note that an operator that is an imported back-end
138 -- builtin has convention Intrinsic, but is expected to be rewritten into
139 -- a call, so such an operator is not treated as predefined by this
142 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
);
143 -- If a default expression in entry call N depends on the discriminants
144 -- of the task, it must be replaced with a reference to the discriminant
145 -- of the task being called.
147 procedure Resolve_Op_Concat_Arg
152 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
153 -- concatenation operator. The operand is either of the array type or of
154 -- the component type. If the operand is an aggregate, and the component
155 -- type is composite, this is ambiguous if component type has aggregates.
157 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
);
158 -- Does the first part of the work of Resolve_Op_Concat
160 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
);
161 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
162 -- has been resolved. See Resolve_Op_Concat for details.
164 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
);
165 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
);
166 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
);
167 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
168 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
169 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
);
170 procedure Resolve_Conditional_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
171 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
);
172 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
);
173 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
);
174 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
);
175 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
);
176 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
177 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
);
178 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
);
179 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
);
180 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
);
181 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
);
182 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
);
183 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
);
184 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
185 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
);
186 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
187 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
);
188 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
);
189 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
);
190 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
);
191 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
);
192 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
193 procedure Resolve_Subprogram_Info
(N
: Node_Id
; Typ
: Entity_Id
);
194 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
195 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
);
196 procedure Resolve_Unchecked_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
197 procedure Resolve_Unchecked_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
199 function Operator_Kind
201 Is_Binary
: Boolean) return Node_Kind
;
202 -- Utility to map the name of an operator into the corresponding Node. Used
203 -- by other node rewriting procedures.
205 procedure Resolve_Actuals
(N
: Node_Id
; Nam
: Entity_Id
);
206 -- Resolve actuals of call, and add default expressions for missing ones.
207 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
208 -- called subprogram.
210 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
);
211 -- Called from Resolve_Call, when the prefix denotes an entry or element
212 -- of entry family. Actuals are resolved as for subprograms, and the node
213 -- is rebuilt as an entry call. Also called for protected operations. Typ
214 -- is the context type, which is used when the operation is a protected
215 -- function with no arguments, and the return value is indexed.
217 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
218 -- A call to a user-defined intrinsic operator is rewritten as a call
219 -- to the corresponding predefined operator, with suitable conversions.
220 -- Note that this applies only for intrinsic operators that denote
221 -- predefined operators, not operators that are intrinsic imports of
222 -- back-end builtins.
224 procedure Resolve_Intrinsic_Unary_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
225 -- Ditto, for unary operators (arithmetic ones and "not" on signed
226 -- integer types for VMS).
228 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
);
229 -- If an operator node resolves to a call to a user-defined operator,
230 -- rewrite the node as a function call.
232 procedure Make_Call_Into_Operator
236 -- Inverse transformation: if an operator is given in functional notation,
237 -- then after resolving the node, transform into an operator node, so
238 -- that operands are resolved properly. Recall that predefined operators
239 -- do not have a full signature and special resolution rules apply.
241 procedure Rewrite_Renamed_Operator
245 -- An operator can rename another, e.g. in an instantiation. In that
246 -- case, the proper operator node must be constructed and resolved.
248 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
);
249 -- The String_Literal_Subtype is built for all strings that are not
250 -- operands of a static concatenation operation. If the argument is
251 -- not a N_String_Literal node, then the call has no effect.
253 procedure Set_Slice_Subtype
(N
: Node_Id
);
254 -- Build subtype of array type, with the range specified by the slice
256 procedure Simplify_Type_Conversion
(N
: Node_Id
);
257 -- Called after N has been resolved and evaluated, but before range checks
258 -- have been applied. Currently simplifies a combination of floating-point
259 -- to integer conversion and Truncation attribute.
261 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
;
262 -- A universal_fixed expression in an universal context is unambiguous
263 -- if there is only one applicable fixed point type. Determining whether
264 -- there is only one requires a search over all visible entities, and
265 -- happens only in very pathological cases (see 6115-006).
267 function Valid_Conversion
270 Operand
: Node_Id
) return Boolean;
271 -- Verify legality rules given in 4.6 (8-23). Target is the target
272 -- type of the conversion, which may be an implicit conversion of
273 -- an actual parameter to an anonymous access type (in which case
274 -- N denotes the actual parameter and N = Operand).
276 -------------------------
277 -- Ambiguous_Character --
278 -------------------------
280 procedure Ambiguous_Character
(C
: Node_Id
) is
284 if Nkind
(C
) = N_Character_Literal
then
285 Error_Msg_N
("ambiguous character literal", C
);
287 -- First the ones in Standard
289 Error_Msg_N
("\\possible interpretation: Character!", C
);
290 Error_Msg_N
("\\possible interpretation: Wide_Character!", C
);
292 -- Include Wide_Wide_Character in Ada 2005 mode
294 if Ada_Version
>= Ada_05
then
295 Error_Msg_N
("\\possible interpretation: Wide_Wide_Character!", C
);
298 -- Now any other types that match
300 E
:= Current_Entity
(C
);
301 while Present
(E
) loop
302 Error_Msg_NE
("\\possible interpretation:}!", C
, Etype
(E
));
306 end Ambiguous_Character
;
308 -------------------------
309 -- Analyze_And_Resolve --
310 -------------------------
312 procedure Analyze_And_Resolve
(N
: Node_Id
) is
316 end Analyze_And_Resolve
;
318 procedure Analyze_And_Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
322 end Analyze_And_Resolve
;
324 -- Version withs check(s) suppressed
326 procedure Analyze_And_Resolve
331 Scop
: constant Entity_Id
:= Current_Scope
;
334 if Suppress
= All_Checks
then
336 Svg
: constant Suppress_Array
:= Scope_Suppress
;
338 Scope_Suppress
:= (others => True);
339 Analyze_And_Resolve
(N
, Typ
);
340 Scope_Suppress
:= Svg
;
345 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
348 Scope_Suppress
(Suppress
) := True;
349 Analyze_And_Resolve
(N
, Typ
);
350 Scope_Suppress
(Suppress
) := Svg
;
354 if Current_Scope
/= Scop
355 and then Scope_Is_Transient
357 -- This can only happen if a transient scope was created
358 -- for an inner expression, which will be removed upon
359 -- completion of the analysis of an enclosing construct.
360 -- The transient scope must have the suppress status of
361 -- the enclosing environment, not of this Analyze call.
363 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
366 end Analyze_And_Resolve
;
368 procedure Analyze_And_Resolve
372 Scop
: constant Entity_Id
:= Current_Scope
;
375 if Suppress
= All_Checks
then
377 Svg
: constant Suppress_Array
:= Scope_Suppress
;
379 Scope_Suppress
:= (others => True);
380 Analyze_And_Resolve
(N
);
381 Scope_Suppress
:= Svg
;
386 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
389 Scope_Suppress
(Suppress
) := True;
390 Analyze_And_Resolve
(N
);
391 Scope_Suppress
(Suppress
) := Svg
;
395 if Current_Scope
/= Scop
396 and then Scope_Is_Transient
398 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
401 end Analyze_And_Resolve
;
403 ----------------------------
404 -- Check_Discriminant_Use --
405 ----------------------------
407 procedure Check_Discriminant_Use
(N
: Node_Id
) is
408 PN
: constant Node_Id
:= Parent
(N
);
409 Disc
: constant Entity_Id
:= Entity
(N
);
414 -- Any use in a spec-expression is legal
416 if In_Spec_Expression
then
419 elsif Nkind
(PN
) = N_Range
then
421 -- Discriminant cannot be used to constrain a scalar type
425 if Nkind
(P
) = N_Range_Constraint
426 and then Nkind
(Parent
(P
)) = N_Subtype_Indication
427 and then Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
429 Error_Msg_N
("discriminant cannot constrain scalar type", N
);
431 elsif Nkind
(P
) = N_Index_Or_Discriminant_Constraint
then
433 -- The following check catches the unusual case where
434 -- a discriminant appears within an index constraint
435 -- that is part of a larger expression within a constraint
436 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
437 -- For now we only check case of record components, and
438 -- note that a similar check should also apply in the
439 -- case of discriminant constraints below. ???
441 -- Note that the check for N_Subtype_Declaration below is to
442 -- detect the valid use of discriminants in the constraints of a
443 -- subtype declaration when this subtype declaration appears
444 -- inside the scope of a record type (which is syntactically
445 -- illegal, but which may be created as part of derived type
446 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
449 if Ekind
(Current_Scope
) = E_Record_Type
450 and then Scope
(Disc
) = Current_Scope
452 (Nkind
(Parent
(P
)) = N_Subtype_Indication
454 Nkind_In
(Parent
(Parent
(P
)), N_Component_Definition
,
455 N_Subtype_Declaration
)
456 and then Paren_Count
(N
) = 0)
459 ("discriminant must appear alone in component constraint", N
);
463 -- Detect a common error:
465 -- type R (D : Positive := 100) is record
466 -- Name : String (1 .. D);
469 -- The default value causes an object of type R to be allocated
470 -- with room for Positive'Last characters. The RM does not mandate
471 -- the allocation of the maximum size, but that is what GNAT does
472 -- so we should warn the programmer that there is a problem.
474 Check_Large
: declare
480 function Large_Storage_Type
(T
: Entity_Id
) return Boolean;
481 -- Return True if type T has a large enough range that
482 -- any array whose index type covered the whole range of
483 -- the type would likely raise Storage_Error.
485 ------------------------
486 -- Large_Storage_Type --
487 ------------------------
489 function Large_Storage_Type
(T
: Entity_Id
) return Boolean is
491 -- The type is considered large if its bounds are known at
492 -- compile time and if it requires at least as many bits as
493 -- a Positive to store the possible values.
495 return Compile_Time_Known_Value
(Type_Low_Bound
(T
))
496 and then Compile_Time_Known_Value
(Type_High_Bound
(T
))
498 Minimum_Size
(T
, Biased
=> True) >=
499 RM_Size
(Standard_Positive
);
500 end Large_Storage_Type
;
502 -- Start of processing for Check_Large
505 -- Check that the Disc has a large range
507 if not Large_Storage_Type
(Etype
(Disc
)) then
511 -- If the enclosing type is limited, we allocate only the
512 -- default value, not the maximum, and there is no need for
515 if Is_Limited_Type
(Scope
(Disc
)) then
519 -- Check that it is the high bound
521 if N
/= High_Bound
(PN
)
522 or else No
(Discriminant_Default_Value
(Disc
))
527 -- Check the array allows a large range at this bound.
528 -- First find the array
532 if Nkind
(SI
) /= N_Subtype_Indication
then
536 T
:= Entity
(Subtype_Mark
(SI
));
538 if not Is_Array_Type
(T
) then
542 -- Next, find the dimension
544 TB
:= First_Index
(T
);
545 CB
:= First
(Constraints
(P
));
547 and then Present
(TB
)
548 and then Present
(CB
)
559 -- Now, check the dimension has a large range
561 if not Large_Storage_Type
(Etype
(TB
)) then
565 -- Warn about the danger
568 ("?creation of & object may raise Storage_Error!",
577 -- Legal case is in index or discriminant constraint
579 elsif Nkind_In
(PN
, N_Index_Or_Discriminant_Constraint
,
580 N_Discriminant_Association
)
582 if Paren_Count
(N
) > 0 then
584 ("discriminant in constraint must appear alone", N
);
586 elsif Nkind
(N
) = N_Expanded_Name
587 and then Comes_From_Source
(N
)
590 ("discriminant must appear alone as a direct name", N
);
595 -- Otherwise, context is an expression. It should not be within
596 -- (i.e. a subexpression of) a constraint for a component.
601 while not Nkind_In
(P
, N_Component_Declaration
,
602 N_Subtype_Indication
,
610 -- If the discriminant is used in an expression that is a bound
611 -- of a scalar type, an Itype is created and the bounds are attached
612 -- to its range, not to the original subtype indication. Such use
613 -- is of course a double fault.
615 if (Nkind
(P
) = N_Subtype_Indication
616 and then Nkind_In
(Parent
(P
), N_Component_Definition
,
617 N_Derived_Type_Definition
)
618 and then D
= Constraint
(P
))
620 -- The constraint itself may be given by a subtype indication,
621 -- rather than by a more common discrete range.
623 or else (Nkind
(P
) = N_Subtype_Indication
625 Nkind
(Parent
(P
)) = N_Index_Or_Discriminant_Constraint
)
626 or else Nkind
(P
) = N_Entry_Declaration
627 or else Nkind
(D
) = N_Defining_Identifier
630 ("discriminant in constraint must appear alone", N
);
633 end Check_Discriminant_Use
;
635 --------------------------------
636 -- Check_For_Visible_Operator --
637 --------------------------------
639 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
) is
641 if Is_Invisible_Operator
(N
, T
) then
642 Error_Msg_NE
-- CODEFIX
643 ("operator for} is not directly visible!", N
, First_Subtype
(T
));
644 Error_Msg_N
-- CODEFIX
645 ("use clause would make operation legal!", N
);
647 end Check_For_Visible_Operator
;
649 ----------------------------------
650 -- Check_Fully_Declared_Prefix --
651 ----------------------------------
653 procedure Check_Fully_Declared_Prefix
658 -- Check that the designated type of the prefix of a dereference is
659 -- not an incomplete type. This cannot be done unconditionally, because
660 -- dereferences of private types are legal in default expressions. This
661 -- case is taken care of in Check_Fully_Declared, called below. There
662 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
664 -- This consideration also applies to similar checks for allocators,
665 -- qualified expressions, and type conversions.
667 -- An additional exception concerns other per-object expressions that
668 -- are not directly related to component declarations, in particular
669 -- representation pragmas for tasks. These will be per-object
670 -- expressions if they depend on discriminants or some global entity.
671 -- If the task has access discriminants, the designated type may be
672 -- incomplete at the point the expression is resolved. This resolution
673 -- takes place within the body of the initialization procedure, where
674 -- the discriminant is replaced by its discriminal.
676 if Is_Entity_Name
(Pref
)
677 and then Ekind
(Entity
(Pref
)) = E_In_Parameter
681 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
682 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
683 -- Analyze_Object_Renaming, and Freeze_Entity.
685 elsif Ada_Version
>= Ada_05
686 and then Is_Entity_Name
(Pref
)
687 and then Is_Access_Type
(Etype
(Pref
))
688 and then Ekind
(Directly_Designated_Type
(Etype
(Pref
))) =
690 and then Is_Tagged_Type
(Directly_Designated_Type
(Etype
(Pref
)))
694 Check_Fully_Declared
(Typ
, Parent
(Pref
));
696 end Check_Fully_Declared_Prefix
;
698 ------------------------------
699 -- Check_Infinite_Recursion --
700 ------------------------------
702 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean is
706 function Same_Argument_List
return Boolean;
707 -- Check whether list of actuals is identical to list of formals
708 -- of called function (which is also the enclosing scope).
710 ------------------------
711 -- Same_Argument_List --
712 ------------------------
714 function Same_Argument_List
return Boolean is
720 if not Is_Entity_Name
(Name
(N
)) then
723 Subp
:= Entity
(Name
(N
));
726 F
:= First_Formal
(Subp
);
727 A
:= First_Actual
(N
);
728 while Present
(F
) and then Present
(A
) loop
729 if not Is_Entity_Name
(A
)
730 or else Entity
(A
) /= F
740 end Same_Argument_List
;
742 -- Start of processing for Check_Infinite_Recursion
745 -- Special case, if this is a procedure call and is a call to the
746 -- current procedure with the same argument list, then this is for
747 -- sure an infinite recursion and we insert a call to raise SE.
749 if Is_List_Member
(N
)
750 and then List_Length
(List_Containing
(N
)) = 1
751 and then Same_Argument_List
754 P
: constant Node_Id
:= Parent
(N
);
756 if Nkind
(P
) = N_Handled_Sequence_Of_Statements
757 and then Nkind
(Parent
(P
)) = N_Subprogram_Body
758 and then Is_Empty_List
(Declarations
(Parent
(P
)))
760 Error_Msg_N
("!?infinite recursion", N
);
761 Error_Msg_N
("\!?Storage_Error will be raised at run time", N
);
763 Make_Raise_Storage_Error
(Sloc
(N
),
764 Reason
=> SE_Infinite_Recursion
));
770 -- If not that special case, search up tree, quitting if we reach a
771 -- construct (e.g. a conditional) that tells us that this is not a
772 -- case for an infinite recursion warning.
778 -- If no parent, then we were not inside a subprogram, this can for
779 -- example happen when processing certain pragmas in a spec. Just
780 -- return False in this case.
786 -- Done if we get to subprogram body, this is definitely an infinite
787 -- recursion case if we did not find anything to stop us.
789 exit when Nkind
(P
) = N_Subprogram_Body
;
791 -- If appearing in conditional, result is false
793 if Nkind_In
(P
, N_Or_Else
,
800 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
801 and then C
/= First
(Statements
(P
))
803 -- If the call is the expression of a return statement and the
804 -- actuals are identical to the formals, it's worth a warning.
805 -- However, we skip this if there is an immediately preceding
806 -- raise statement, since the call is never executed.
808 -- Furthermore, this corresponds to a common idiom:
810 -- function F (L : Thing) return Boolean is
812 -- raise Program_Error;
816 -- for generating a stub function
818 if Nkind
(Parent
(N
)) = N_Simple_Return_Statement
819 and then Same_Argument_List
821 exit when not Is_List_Member
(Parent
(N
));
823 -- OK, return statement is in a statement list, look for raise
829 -- Skip past N_Freeze_Entity nodes generated by expansion
831 Nod
:= Prev
(Parent
(N
));
833 and then Nkind
(Nod
) = N_Freeze_Entity
838 -- If no raise statement, give warning
840 exit when Nkind
(Nod
) /= N_Raise_Statement
842 (Nkind
(Nod
) not in N_Raise_xxx_Error
843 or else Present
(Condition
(Nod
)));
854 Error_Msg_N
("!?possible infinite recursion", N
);
855 Error_Msg_N
("\!?Storage_Error may be raised at run time", N
);
858 end Check_Infinite_Recursion
;
860 -------------------------------
861 -- Check_Initialization_Call --
862 -------------------------------
864 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
) is
865 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
867 function Uses_SS
(T
: Entity_Id
) return Boolean;
868 -- Check whether the creation of an object of the type will involve
869 -- use of the secondary stack. If T is a record type, this is true
870 -- if the expression for some component uses the secondary stack, e.g.
871 -- through a call to a function that returns an unconstrained value.
872 -- False if T is controlled, because cleanups occur elsewhere.
878 function Uses_SS
(T
: Entity_Id
) return Boolean is
881 Full_Type
: Entity_Id
:= Underlying_Type
(T
);
884 -- Normally we want to use the underlying type, but if it's not set
885 -- then continue with T.
887 if not Present
(Full_Type
) then
891 if Is_Controlled
(Full_Type
) then
894 elsif Is_Array_Type
(Full_Type
) then
895 return Uses_SS
(Component_Type
(Full_Type
));
897 elsif Is_Record_Type
(Full_Type
) then
898 Comp
:= First_Component
(Full_Type
);
899 while Present
(Comp
) loop
900 if Ekind
(Comp
) = E_Component
901 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
903 -- The expression for a dynamic component may be rewritten
904 -- as a dereference, so retrieve original node.
906 Expr
:= Original_Node
(Expression
(Parent
(Comp
)));
908 -- Return True if the expression is a call to a function
909 -- (including an attribute function such as Image, or a
910 -- user-defined operator) with a result that requires a
913 if (Nkind
(Expr
) = N_Function_Call
914 or else Nkind
(Expr
) in N_Op
915 or else (Nkind
(Expr
) = N_Attribute_Reference
916 and then Present
(Expressions
(Expr
))))
917 and then Requires_Transient_Scope
(Etype
(Expr
))
921 elsif Uses_SS
(Etype
(Comp
)) then
926 Next_Component
(Comp
);
936 -- Start of processing for Check_Initialization_Call
939 -- Establish a transient scope if the type needs it
941 if Uses_SS
(Typ
) then
942 Establish_Transient_Scope
(First_Actual
(N
), Sec_Stack
=> True);
944 end Check_Initialization_Call
;
946 ---------------------------------------
947 -- Check_No_Direct_Boolean_Operators --
948 ---------------------------------------
950 procedure Check_No_Direct_Boolean_Operators
(N
: Node_Id
) is
952 if Scope
(Entity
(N
)) = Standard_Standard
953 and then Root_Type
(Etype
(Left_Opnd
(N
))) = Standard_Boolean
955 -- Restriction only applies to original source code
957 if Comes_From_Source
(N
) then
958 Check_Restriction
(No_Direct_Boolean_Operators
, N
);
963 Check_Boolean_Operator
(N
);
965 end Check_No_Direct_Boolean_Operators
;
967 ------------------------------
968 -- Check_Parameterless_Call --
969 ------------------------------
971 procedure Check_Parameterless_Call
(N
: Node_Id
) is
974 function Prefix_Is_Access_Subp
return Boolean;
975 -- If the prefix is of an access_to_subprogram type, the node must be
976 -- rewritten as a call. Ditto if the prefix is overloaded and all its
977 -- interpretations are access to subprograms.
979 ---------------------------
980 -- Prefix_Is_Access_Subp --
981 ---------------------------
983 function Prefix_Is_Access_Subp
return Boolean is
988 if not Is_Overloaded
(N
) then
990 Ekind
(Etype
(N
)) = E_Subprogram_Type
991 and then Base_Type
(Etype
(Etype
(N
))) /= Standard_Void_Type
;
993 Get_First_Interp
(N
, I
, It
);
994 while Present
(It
.Typ
) loop
995 if Ekind
(It
.Typ
) /= E_Subprogram_Type
996 or else Base_Type
(Etype
(It
.Typ
)) = Standard_Void_Type
1001 Get_Next_Interp
(I
, It
);
1006 end Prefix_Is_Access_Subp
;
1008 -- Start of processing for Check_Parameterless_Call
1011 -- Defend against junk stuff if errors already detected
1013 if Total_Errors_Detected
/= 0 then
1014 if Nkind
(N
) in N_Has_Etype
and then Etype
(N
) = Any_Type
then
1016 elsif Nkind
(N
) in N_Has_Chars
1017 and then Chars
(N
) in Error_Name_Or_No_Name
1025 -- If the context expects a value, and the name is a procedure, this is
1026 -- most likely a missing 'Access. Don't try to resolve the parameterless
1027 -- call, error will be caught when the outer call is analyzed.
1029 if Is_Entity_Name
(N
)
1030 and then Ekind
(Entity
(N
)) = E_Procedure
1031 and then not Is_Overloaded
(N
)
1033 Nkind_In
(Parent
(N
), N_Parameter_Association
,
1035 N_Procedure_Call_Statement
)
1040 -- Rewrite as call if overloadable entity that is (or could be, in the
1041 -- overloaded case) a function call. If we know for sure that the entity
1042 -- is an enumeration literal, we do not rewrite it.
1044 if (Is_Entity_Name
(N
)
1045 and then Is_Overloadable
(Entity
(N
))
1046 and then (Ekind
(Entity
(N
)) /= E_Enumeration_Literal
1047 or else Is_Overloaded
(N
)))
1049 -- Rewrite as call if it is an explicit dereference of an expression of
1050 -- a subprogram access type, and the subprogram type is not that of a
1051 -- procedure or entry.
1054 (Nkind
(N
) = N_Explicit_Dereference
and then Prefix_Is_Access_Subp
)
1056 -- Rewrite as call if it is a selected component which is a function,
1057 -- this is the case of a call to a protected function (which may be
1058 -- overloaded with other protected operations).
1061 (Nkind
(N
) = N_Selected_Component
1062 and then (Ekind
(Entity
(Selector_Name
(N
))) = E_Function
1064 (Ekind_In
(Entity
(Selector_Name
(N
)), E_Entry
,
1066 and then Is_Overloaded
(Selector_Name
(N
)))))
1068 -- If one of the above three conditions is met, rewrite as call.
1069 -- Apply the rewriting only once.
1072 if Nkind
(Parent
(N
)) /= N_Function_Call
1073 or else N
/= Name
(Parent
(N
))
1075 Nam
:= New_Copy
(N
);
1077 -- If overloaded, overload set belongs to new copy
1079 Save_Interps
(N
, Nam
);
1081 -- Change node to parameterless function call (note that the
1082 -- Parameter_Associations associations field is left set to Empty,
1083 -- its normal default value since there are no parameters)
1085 Change_Node
(N
, N_Function_Call
);
1087 Set_Sloc
(N
, Sloc
(Nam
));
1091 elsif Nkind
(N
) = N_Parameter_Association
then
1092 Check_Parameterless_Call
(Explicit_Actual_Parameter
(N
));
1094 end Check_Parameterless_Call
;
1096 -----------------------------
1097 -- Is_Definite_Access_Type --
1098 -----------------------------
1100 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean is
1101 Btyp
: constant Entity_Id
:= Base_Type
(E
);
1103 return Ekind
(Btyp
) = E_Access_Type
1104 or else (Ekind
(Btyp
) = E_Access_Subprogram_Type
1105 and then Comes_From_Source
(Btyp
));
1106 end Is_Definite_Access_Type
;
1108 ----------------------
1109 -- Is_Predefined_Op --
1110 ----------------------
1112 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean is
1114 -- Predefined operators are intrinsic subprograms
1116 if not Is_Intrinsic_Subprogram
(Nam
) then
1120 -- A call to a back-end builtin is never a predefined operator
1122 if Is_Imported
(Nam
) and then Present
(Interface_Name
(Nam
)) then
1126 return not Is_Generic_Instance
(Nam
)
1127 and then Chars
(Nam
) in Any_Operator_Name
1128 and then (No
(Alias
(Nam
)) or else Is_Predefined_Op
(Alias
(Nam
)));
1129 end Is_Predefined_Op
;
1131 -----------------------------
1132 -- Make_Call_Into_Operator --
1133 -----------------------------
1135 procedure Make_Call_Into_Operator
1140 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
1141 Act1
: Node_Id
:= First_Actual
(N
);
1142 Act2
: Node_Id
:= Next_Actual
(Act1
);
1143 Error
: Boolean := False;
1144 Func
: constant Entity_Id
:= Entity
(Name
(N
));
1145 Is_Binary
: constant Boolean := Present
(Act2
);
1147 Opnd_Type
: Entity_Id
;
1148 Orig_Type
: Entity_Id
:= Empty
;
1151 type Kind_Test
is access function (E
: Entity_Id
) return Boolean;
1153 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean;
1154 -- If the operand is not universal, and the operator is given by a
1155 -- expanded name, verify that the operand has an interpretation with
1156 -- a type defined in the given scope of the operator.
1158 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
;
1159 -- Find a type of the given class in the package Pack that contains
1162 ---------------------------
1163 -- Operand_Type_In_Scope --
1164 ---------------------------
1166 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean is
1167 Nod
: constant Node_Id
:= Right_Opnd
(Op_Node
);
1172 if not Is_Overloaded
(Nod
) then
1173 return Scope
(Base_Type
(Etype
(Nod
))) = S
;
1176 Get_First_Interp
(Nod
, I
, It
);
1177 while Present
(It
.Typ
) loop
1178 if Scope
(Base_Type
(It
.Typ
)) = S
then
1182 Get_Next_Interp
(I
, It
);
1187 end Operand_Type_In_Scope
;
1193 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
is
1196 function In_Decl
return Boolean;
1197 -- Verify that node is not part of the type declaration for the
1198 -- candidate type, which would otherwise be invisible.
1204 function In_Decl
return Boolean is
1205 Decl_Node
: constant Node_Id
:= Parent
(E
);
1211 if Etype
(E
) = Any_Type
then
1214 elsif No
(Decl_Node
) then
1219 and then Nkind
(N2
) /= N_Compilation_Unit
1221 if N2
= Decl_Node
then
1232 -- Start of processing for Type_In_P
1235 -- If the context type is declared in the prefix package, this
1236 -- is the desired base type.
1238 if Scope
(Base_Type
(Typ
)) = Pack
1241 return Base_Type
(Typ
);
1244 E
:= First_Entity
(Pack
);
1245 while Present
(E
) loop
1247 and then not In_Decl
1259 -- Start of processing for Make_Call_Into_Operator
1262 Op_Node
:= New_Node
(Operator_Kind
(Op_Name
, Is_Binary
), Sloc
(N
));
1267 Set_Left_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1268 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act2
));
1269 Save_Interps
(Act1
, Left_Opnd
(Op_Node
));
1270 Save_Interps
(Act2
, Right_Opnd
(Op_Node
));
1271 Act1
:= Left_Opnd
(Op_Node
);
1272 Act2
:= Right_Opnd
(Op_Node
);
1277 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1278 Save_Interps
(Act1
, Right_Opnd
(Op_Node
));
1279 Act1
:= Right_Opnd
(Op_Node
);
1282 -- If the operator is denoted by an expanded name, and the prefix is
1283 -- not Standard, but the operator is a predefined one whose scope is
1284 -- Standard, then this is an implicit_operator, inserted as an
1285 -- interpretation by the procedure of the same name. This procedure
1286 -- overestimates the presence of implicit operators, because it does
1287 -- not examine the type of the operands. Verify now that the operand
1288 -- type appears in the given scope. If right operand is universal,
1289 -- check the other operand. In the case of concatenation, either
1290 -- argument can be the component type, so check the type of the result.
1291 -- If both arguments are literals, look for a type of the right kind
1292 -- defined in the given scope. This elaborate nonsense is brought to
1293 -- you courtesy of b33302a. The type itself must be frozen, so we must
1294 -- find the type of the proper class in the given scope.
1296 -- A final wrinkle is the multiplication operator for fixed point types,
1297 -- which is defined in Standard only, and not in the scope of the
1298 -- fixed_point type itself.
1300 if Nkind
(Name
(N
)) = N_Expanded_Name
then
1301 Pack
:= Entity
(Prefix
(Name
(N
)));
1303 -- If the entity being called is defined in the given package, it is
1304 -- a renaming of a predefined operator, and known to be legal.
1306 if Scope
(Entity
(Name
(N
))) = Pack
1307 and then Pack
/= Standard_Standard
1311 -- Visibility does not need to be checked in an instance: if the
1312 -- operator was not visible in the generic it has been diagnosed
1313 -- already, else there is an implicit copy of it in the instance.
1315 elsif In_Instance
then
1318 elsif (Op_Name
= Name_Op_Multiply
or else Op_Name
= Name_Op_Divide
)
1319 and then Is_Fixed_Point_Type
(Etype
(Left_Opnd
(Op_Node
)))
1320 and then Is_Fixed_Point_Type
(Etype
(Right_Opnd
(Op_Node
)))
1322 if Pack
/= Standard_Standard
then
1326 -- Ada 2005, AI-420: Predefined equality on Universal_Access is
1329 elsif Ada_Version
>= Ada_05
1330 and then (Op_Name
= Name_Op_Eq
or else Op_Name
= Name_Op_Ne
)
1331 and then Ekind
(Etype
(Act1
)) = E_Anonymous_Access_Type
1336 Opnd_Type
:= Base_Type
(Etype
(Right_Opnd
(Op_Node
)));
1338 if Op_Name
= Name_Op_Concat
then
1339 Opnd_Type
:= Base_Type
(Typ
);
1341 elsif (Scope
(Opnd_Type
) = Standard_Standard
1343 or else (Nkind
(Right_Opnd
(Op_Node
)) = N_Attribute_Reference
1345 and then not Comes_From_Source
(Opnd_Type
))
1347 Opnd_Type
:= Base_Type
(Etype
(Left_Opnd
(Op_Node
)));
1350 if Scope
(Opnd_Type
) = Standard_Standard
then
1352 -- Verify that the scope contains a type that corresponds to
1353 -- the given literal. Optimize the case where Pack is Standard.
1355 if Pack
/= Standard_Standard
then
1357 if Opnd_Type
= Universal_Integer
then
1358 Orig_Type
:= Type_In_P
(Is_Integer_Type
'Access);
1360 elsif Opnd_Type
= Universal_Real
then
1361 Orig_Type
:= Type_In_P
(Is_Real_Type
'Access);
1363 elsif Opnd_Type
= Any_String
then
1364 Orig_Type
:= Type_In_P
(Is_String_Type
'Access);
1366 elsif Opnd_Type
= Any_Access
then
1367 Orig_Type
:= Type_In_P
(Is_Definite_Access_Type
'Access);
1369 elsif Opnd_Type
= Any_Composite
then
1370 Orig_Type
:= Type_In_P
(Is_Composite_Type
'Access);
1372 if Present
(Orig_Type
) then
1373 if Has_Private_Component
(Orig_Type
) then
1376 Set_Etype
(Act1
, Orig_Type
);
1379 Set_Etype
(Act2
, Orig_Type
);
1388 Error
:= No
(Orig_Type
);
1391 elsif Ekind
(Opnd_Type
) = E_Allocator_Type
1392 and then No
(Type_In_P
(Is_Definite_Access_Type
'Access))
1396 -- If the type is defined elsewhere, and the operator is not
1397 -- defined in the given scope (by a renaming declaration, e.g.)
1398 -- then this is an error as well. If an extension of System is
1399 -- present, and the type may be defined there, Pack must be
1402 elsif Scope
(Opnd_Type
) /= Pack
1403 and then Scope
(Op_Id
) /= Pack
1404 and then (No
(System_Aux_Id
)
1405 or else Scope
(Opnd_Type
) /= System_Aux_Id
1406 or else Pack
/= Scope
(System_Aux_Id
))
1408 if not Is_Overloaded
(Right_Opnd
(Op_Node
)) then
1411 Error
:= not Operand_Type_In_Scope
(Pack
);
1414 elsif Pack
= Standard_Standard
1415 and then not Operand_Type_In_Scope
(Standard_Standard
)
1422 Error_Msg_Node_2
:= Pack
;
1424 ("& not declared in&", N
, Selector_Name
(Name
(N
)));
1425 Set_Etype
(N
, Any_Type
);
1428 -- Detect a mismatch between the context type and the result type
1429 -- in the named package, which is otherwise not detected if the
1430 -- operands are universal. Check is only needed if source entity is
1431 -- an operator, not a function that renames an operator.
1433 elsif Nkind
(Parent
(N
)) /= N_Type_Conversion
1434 and then Ekind
(Entity
(Name
(N
))) = E_Operator
1435 and then Is_Numeric_Type
(Typ
)
1436 and then not Is_Universal_Numeric_Type
(Typ
)
1437 and then Scope
(Base_Type
(Typ
)) /= Pack
1438 and then not In_Instance
1440 if Is_Fixed_Point_Type
(Typ
)
1441 and then (Op_Name
= Name_Op_Multiply
1443 Op_Name
= Name_Op_Divide
)
1445 -- Already checked above
1449 -- Operator may be defined in an extension of System
1451 elsif Present
(System_Aux_Id
)
1452 and then Scope
(Opnd_Type
) = System_Aux_Id
1457 -- Could we use Wrong_Type here??? (this would require setting
1458 -- Etype (N) to the actual type found where Typ was expected).
1460 Error_Msg_NE
("expect }", N
, Typ
);
1465 Set_Chars
(Op_Node
, Op_Name
);
1467 if not Is_Private_Type
(Etype
(N
)) then
1468 Set_Etype
(Op_Node
, Base_Type
(Etype
(N
)));
1470 Set_Etype
(Op_Node
, Etype
(N
));
1473 -- If this is a call to a function that renames a predefined equality,
1474 -- the renaming declaration provides a type that must be used to
1475 -- resolve the operands. This must be done now because resolution of
1476 -- the equality node will not resolve any remaining ambiguity, and it
1477 -- assumes that the first operand is not overloaded.
1479 if (Op_Name
= Name_Op_Eq
or else Op_Name
= Name_Op_Ne
)
1480 and then Ekind
(Func
) = E_Function
1481 and then Is_Overloaded
(Act1
)
1483 Resolve
(Act1
, Base_Type
(Etype
(First_Formal
(Func
))));
1484 Resolve
(Act2
, Base_Type
(Etype
(First_Formal
(Func
))));
1487 Set_Entity
(Op_Node
, Op_Id
);
1488 Generate_Reference
(Op_Id
, N
, ' ');
1490 -- Do rewrite setting Comes_From_Source on the result if the original
1491 -- call came from source. Although it is not strictly the case that the
1492 -- operator as such comes from the source, logically it corresponds
1493 -- exactly to the function call in the source, so it should be marked
1494 -- this way (e.g. to make sure that validity checks work fine).
1497 CS
: constant Boolean := Comes_From_Source
(N
);
1499 Rewrite
(N
, Op_Node
);
1500 Set_Comes_From_Source
(N
, CS
);
1503 -- If this is an arithmetic operator and the result type is private,
1504 -- the operands and the result must be wrapped in conversion to
1505 -- expose the underlying numeric type and expand the proper checks,
1506 -- e.g. on division.
1508 if Is_Private_Type
(Typ
) then
1510 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1511 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
1512 Resolve_Intrinsic_Operator
(N
, Typ
);
1514 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
1515 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
1523 end Make_Call_Into_Operator
;
1529 function Operator_Kind
1531 Is_Binary
: Boolean) return Node_Kind
1537 if Op_Name
= Name_Op_And
then
1539 elsif Op_Name
= Name_Op_Or
then
1541 elsif Op_Name
= Name_Op_Xor
then
1543 elsif Op_Name
= Name_Op_Eq
then
1545 elsif Op_Name
= Name_Op_Ne
then
1547 elsif Op_Name
= Name_Op_Lt
then
1549 elsif Op_Name
= Name_Op_Le
then
1551 elsif Op_Name
= Name_Op_Gt
then
1553 elsif Op_Name
= Name_Op_Ge
then
1555 elsif Op_Name
= Name_Op_Add
then
1557 elsif Op_Name
= Name_Op_Subtract
then
1558 Kind
:= N_Op_Subtract
;
1559 elsif Op_Name
= Name_Op_Concat
then
1560 Kind
:= N_Op_Concat
;
1561 elsif Op_Name
= Name_Op_Multiply
then
1562 Kind
:= N_Op_Multiply
;
1563 elsif Op_Name
= Name_Op_Divide
then
1564 Kind
:= N_Op_Divide
;
1565 elsif Op_Name
= Name_Op_Mod
then
1567 elsif Op_Name
= Name_Op_Rem
then
1569 elsif Op_Name
= Name_Op_Expon
then
1572 raise Program_Error
;
1578 if Op_Name
= Name_Op_Add
then
1580 elsif Op_Name
= Name_Op_Subtract
then
1582 elsif Op_Name
= Name_Op_Abs
then
1584 elsif Op_Name
= Name_Op_Not
then
1587 raise Program_Error
;
1594 ----------------------------
1595 -- Preanalyze_And_Resolve --
1596 ----------------------------
1598 procedure Preanalyze_And_Resolve
(N
: Node_Id
; T
: Entity_Id
) is
1599 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1602 Full_Analysis
:= False;
1603 Expander_Mode_Save_And_Set
(False);
1605 -- We suppress all checks for this analysis, since the checks will
1606 -- be applied properly, and in the right location, when the default
1607 -- expression is reanalyzed and reexpanded later on.
1609 Analyze_And_Resolve
(N
, T
, Suppress
=> All_Checks
);
1611 Expander_Mode_Restore
;
1612 Full_Analysis
:= Save_Full_Analysis
;
1613 end Preanalyze_And_Resolve
;
1615 -- Version without context type
1617 procedure Preanalyze_And_Resolve
(N
: Node_Id
) is
1618 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1621 Full_Analysis
:= False;
1622 Expander_Mode_Save_And_Set
(False);
1625 Resolve
(N
, Etype
(N
), Suppress
=> All_Checks
);
1627 Expander_Mode_Restore
;
1628 Full_Analysis
:= Save_Full_Analysis
;
1629 end Preanalyze_And_Resolve
;
1631 ----------------------------------
1632 -- Replace_Actual_Discriminants --
1633 ----------------------------------
1635 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
) is
1636 Loc
: constant Source_Ptr
:= Sloc
(N
);
1637 Tsk
: Node_Id
:= Empty
;
1639 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
;
1645 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
is
1649 if Nkind
(Nod
) = N_Identifier
then
1650 Ent
:= Entity
(Nod
);
1653 and then Ekind
(Ent
) = E_Discriminant
1656 Make_Selected_Component
(Loc
,
1657 Prefix
=> New_Copy_Tree
(Tsk
, New_Sloc
=> Loc
),
1658 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Ent
))));
1660 Set_Etype
(Nod
, Etype
(Ent
));
1668 procedure Replace_Discrs
is new Traverse_Proc
(Process_Discr
);
1670 -- Start of processing for Replace_Actual_Discriminants
1673 if not Expander_Active
then
1677 if Nkind
(Name
(N
)) = N_Selected_Component
then
1678 Tsk
:= Prefix
(Name
(N
));
1680 elsif Nkind
(Name
(N
)) = N_Indexed_Component
then
1681 Tsk
:= Prefix
(Prefix
(Name
(N
)));
1687 Replace_Discrs
(Default
);
1689 end Replace_Actual_Discriminants
;
1695 procedure Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
1696 Ambiguous
: Boolean := False;
1697 Ctx_Type
: Entity_Id
:= Typ
;
1698 Expr_Type
: Entity_Id
:= Empty
; -- prevent junk warning
1699 Err_Type
: Entity_Id
:= Empty
;
1700 Found
: Boolean := False;
1703 I1
: Interp_Index
:= 0; -- prevent junk warning
1706 Seen
: Entity_Id
:= Empty
; -- prevent junk warning
1708 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean;
1709 -- Determine whether a node comes from a predefined library unit or
1712 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
);
1713 -- Try and fix up a literal so that it matches its expected type. New
1714 -- literals are manufactured if necessary to avoid cascaded errors.
1716 procedure Report_Ambiguous_Argument
;
1717 -- Additional diagnostics when an ambiguous call has an ambiguous
1718 -- argument (typically a controlling actual).
1720 procedure Resolution_Failed
;
1721 -- Called when attempt at resolving current expression fails
1723 ------------------------------------
1724 -- Comes_From_Predefined_Lib_Unit --
1725 -------------------------------------
1727 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean is
1730 Sloc
(Nod
) = Standard_Location
1731 or else Is_Predefined_File_Name
(Unit_File_Name
(
1732 Get_Source_Unit
(Sloc
(Nod
))));
1733 end Comes_From_Predefined_Lib_Unit
;
1735 --------------------
1736 -- Patch_Up_Value --
1737 --------------------
1739 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
) is
1741 if Nkind
(N
) = N_Integer_Literal
1742 and then Is_Real_Type
(Typ
)
1745 Make_Real_Literal
(Sloc
(N
),
1746 Realval
=> UR_From_Uint
(Intval
(N
))));
1747 Set_Etype
(N
, Universal_Real
);
1748 Set_Is_Static_Expression
(N
);
1750 elsif Nkind
(N
) = N_Real_Literal
1751 and then Is_Integer_Type
(Typ
)
1754 Make_Integer_Literal
(Sloc
(N
),
1755 Intval
=> UR_To_Uint
(Realval
(N
))));
1756 Set_Etype
(N
, Universal_Integer
);
1757 Set_Is_Static_Expression
(N
);
1759 elsif Nkind
(N
) = N_String_Literal
1760 and then Is_Character_Type
(Typ
)
1762 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('A')));
1764 Make_Character_Literal
(Sloc
(N
),
1766 Char_Literal_Value
=>
1767 UI_From_Int
(Character'Pos ('A'))));
1768 Set_Etype
(N
, Any_Character
);
1769 Set_Is_Static_Expression
(N
);
1771 elsif Nkind
(N
) /= N_String_Literal
1772 and then Is_String_Type
(Typ
)
1775 Make_String_Literal
(Sloc
(N
),
1776 Strval
=> End_String
));
1778 elsif Nkind
(N
) = N_Range
then
1779 Patch_Up_Value
(Low_Bound
(N
), Typ
);
1780 Patch_Up_Value
(High_Bound
(N
), Typ
);
1784 -------------------------------
1785 -- Report_Ambiguous_Argument --
1786 -------------------------------
1788 procedure Report_Ambiguous_Argument
is
1789 Arg
: constant Node_Id
:= First
(Parameter_Associations
(N
));
1794 if Nkind
(Arg
) = N_Function_Call
1795 and then Is_Entity_Name
(Name
(Arg
))
1796 and then Is_Overloaded
(Name
(Arg
))
1798 Error_Msg_NE
("ambiguous call to&", Arg
, Name
(Arg
));
1800 -- Could use comments on what is going on here ???
1802 Get_First_Interp
(Name
(Arg
), I
, It
);
1803 while Present
(It
.Nam
) loop
1804 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
1806 if Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
then
1807 Error_Msg_N
("interpretation (inherited) #!", Arg
);
1809 Error_Msg_N
("interpretation #!", Arg
);
1812 Get_Next_Interp
(I
, It
);
1815 end Report_Ambiguous_Argument
;
1817 -----------------------
1818 -- Resolution_Failed --
1819 -----------------------
1821 procedure Resolution_Failed
is
1823 Patch_Up_Value
(N
, Typ
);
1825 Debug_A_Exit
("resolving ", N
, " (done, resolution failed)");
1826 Set_Is_Overloaded
(N
, False);
1828 -- The caller will return without calling the expander, so we need
1829 -- to set the analyzed flag. Note that it is fine to set Analyzed
1830 -- to True even if we are in the middle of a shallow analysis,
1831 -- (see the spec of sem for more details) since this is an error
1832 -- situation anyway, and there is no point in repeating the
1833 -- analysis later (indeed it won't work to repeat it later, since
1834 -- we haven't got a clear resolution of which entity is being
1837 Set_Analyzed
(N
, True);
1839 end Resolution_Failed
;
1841 -- Start of processing for Resolve
1848 -- Access attribute on remote subprogram cannot be used for
1849 -- a non-remote access-to-subprogram type.
1851 if Nkind
(N
) = N_Attribute_Reference
1852 and then (Attribute_Name
(N
) = Name_Access
1853 or else Attribute_Name
(N
) = Name_Unrestricted_Access
1854 or else Attribute_Name
(N
) = Name_Unchecked_Access
)
1855 and then Comes_From_Source
(N
)
1856 and then Is_Entity_Name
(Prefix
(N
))
1857 and then Is_Subprogram
(Entity
(Prefix
(N
)))
1858 and then Is_Remote_Call_Interface
(Entity
(Prefix
(N
)))
1859 and then not Is_Remote_Access_To_Subprogram_Type
(Typ
)
1862 ("prefix must statically denote a non-remote subprogram", N
);
1865 From_Lib
:= Comes_From_Predefined_Lib_Unit
(N
);
1867 -- If the context is a Remote_Access_To_Subprogram, access attributes
1868 -- must be resolved with the corresponding fat pointer. There is no need
1869 -- to check for the attribute name since the return type of an
1870 -- attribute is never a remote type.
1872 if Nkind
(N
) = N_Attribute_Reference
1873 and then Comes_From_Source
(N
)
1874 and then (Is_Remote_Call_Interface
(Typ
)
1875 or else Is_Remote_Types
(Typ
))
1878 Attr
: constant Attribute_Id
:=
1879 Get_Attribute_Id
(Attribute_Name
(N
));
1880 Pref
: constant Node_Id
:= Prefix
(N
);
1883 Is_Remote
: Boolean := True;
1886 -- Check that Typ is a remote access-to-subprogram type
1888 if Is_Remote_Access_To_Subprogram_Type
(Typ
) then
1890 -- Prefix (N) must statically denote a remote subprogram
1891 -- declared in a package specification.
1893 if Attr
= Attribute_Access
then
1894 Decl
:= Unit_Declaration_Node
(Entity
(Pref
));
1896 if Nkind
(Decl
) = N_Subprogram_Body
then
1897 Spec
:= Corresponding_Spec
(Decl
);
1899 if not No
(Spec
) then
1900 Decl
:= Unit_Declaration_Node
(Spec
);
1904 Spec
:= Parent
(Decl
);
1906 if not Is_Entity_Name
(Prefix
(N
))
1907 or else Nkind
(Spec
) /= N_Package_Specification
1909 not Is_Remote_Call_Interface
(Defining_Entity
(Spec
))
1913 ("prefix must statically denote a remote subprogram ",
1918 -- If we are generating code for a distributed program.
1919 -- perform semantic checks against the corresponding
1922 if (Attr
= Attribute_Access
1923 or else Attr
= Attribute_Unchecked_Access
1924 or else Attr
= Attribute_Unrestricted_Access
)
1925 and then Expander_Active
1926 and then Get_PCS_Name
/= Name_No_DSA
1928 Check_Subtype_Conformant
1929 (New_Id
=> Entity
(Prefix
(N
)),
1930 Old_Id
=> Designated_Type
1931 (Corresponding_Remote_Type
(Typ
)),
1935 Process_Remote_AST_Attribute
(N
, Typ
);
1942 Debug_A_Entry
("resolving ", N
);
1944 if Comes_From_Source
(N
) then
1945 if Is_Fixed_Point_Type
(Typ
) then
1946 Check_Restriction
(No_Fixed_Point
, N
);
1948 elsif Is_Floating_Point_Type
(Typ
)
1949 and then Typ
/= Universal_Real
1950 and then Typ
/= Any_Real
1952 Check_Restriction
(No_Floating_Point
, N
);
1956 -- Return if already analyzed
1958 if Analyzed
(N
) then
1959 Debug_A_Exit
("resolving ", N
, " (done, already analyzed)");
1962 -- Return if type = Any_Type (previous error encountered)
1964 elsif Etype
(N
) = Any_Type
then
1965 Debug_A_Exit
("resolving ", N
, " (done, Etype = Any_Type)");
1969 Check_Parameterless_Call
(N
);
1971 -- If not overloaded, then we know the type, and all that needs doing
1972 -- is to check that this type is compatible with the context.
1974 if not Is_Overloaded
(N
) then
1975 Found
:= Covers
(Typ
, Etype
(N
));
1976 Expr_Type
:= Etype
(N
);
1978 -- In the overloaded case, we must select the interpretation that
1979 -- is compatible with the context (i.e. the type passed to Resolve)
1982 -- Loop through possible interpretations
1984 Get_First_Interp
(N
, I
, It
);
1985 Interp_Loop
: while Present
(It
.Typ
) loop
1987 -- We are only interested in interpretations that are compatible
1988 -- with the expected type, any other interpretations are ignored.
1990 if not Covers
(Typ
, It
.Typ
) then
1991 if Debug_Flag_V
then
1992 Write_Str
(" interpretation incompatible with context");
1997 -- Skip the current interpretation if it is disabled by an
1998 -- abstract operator. This action is performed only when the
1999 -- type against which we are resolving is the same as the
2000 -- type of the interpretation.
2002 if Ada_Version
>= Ada_05
2003 and then It
.Typ
= Typ
2004 and then Typ
/= Universal_Integer
2005 and then Typ
/= Universal_Real
2006 and then Present
(It
.Abstract_Op
)
2011 -- First matching interpretation
2017 Expr_Type
:= It
.Typ
;
2019 -- Matching interpretation that is not the first, maybe an
2020 -- error, but there are some cases where preference rules are
2021 -- used to choose between the two possibilities. These and
2022 -- some more obscure cases are handled in Disambiguate.
2025 -- If the current statement is part of a predefined library
2026 -- unit, then all interpretations which come from user level
2027 -- packages should not be considered.
2030 and then not Comes_From_Predefined_Lib_Unit
(It
.Nam
)
2035 Error_Msg_Sloc
:= Sloc
(Seen
);
2036 It1
:= Disambiguate
(N
, I1
, I
, Typ
);
2038 -- Disambiguation has succeeded. Skip the remaining
2041 if It1
/= No_Interp
then
2043 Expr_Type
:= It1
.Typ
;
2045 while Present
(It
.Typ
) loop
2046 Get_Next_Interp
(I
, It
);
2050 -- Before we issue an ambiguity complaint, check for
2051 -- the case of a subprogram call where at least one
2052 -- of the arguments is Any_Type, and if so, suppress
2053 -- the message, since it is a cascaded error.
2055 if Nkind_In
(N
, N_Function_Call
,
2056 N_Procedure_Call_Statement
)
2063 A
:= First_Actual
(N
);
2064 while Present
(A
) loop
2067 if Nkind
(E
) = N_Parameter_Association
then
2068 E
:= Explicit_Actual_Parameter
(E
);
2071 if Etype
(E
) = Any_Type
then
2072 if Debug_Flag_V
then
2073 Write_Str
("Any_Type in call");
2084 elsif Nkind
(N
) in N_Binary_Op
2085 and then (Etype
(Left_Opnd
(N
)) = Any_Type
2086 or else Etype
(Right_Opnd
(N
)) = Any_Type
)
2090 elsif Nkind
(N
) in N_Unary_Op
2091 and then Etype
(Right_Opnd
(N
)) = Any_Type
2096 -- Not that special case, so issue message using the
2097 -- flag Ambiguous to control printing of the header
2098 -- message only at the start of an ambiguous set.
2100 if not Ambiguous
then
2101 if Nkind
(N
) = N_Function_Call
2102 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2105 ("ambiguous expression "
2106 & "(cannot resolve indirect call)!", N
);
2108 Error_Msg_NE
-- CODEFIX
2109 ("ambiguous expression (cannot resolve&)!",
2115 if Nkind
(Parent
(Seen
)) = N_Full_Type_Declaration
then
2117 ("\\possible interpretation (inherited)#!", N
);
2119 Error_Msg_N
-- CODEFIX
2120 ("\\possible interpretation#!", N
);
2124 (N
, N_Procedure_Call_Statement
, N_Function_Call
)
2125 and then Present
(Parameter_Associations
(N
))
2127 Report_Ambiguous_Argument
;
2131 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2133 -- By default, the error message refers to the candidate
2134 -- interpretation. But if it is a predefined operator, it
2135 -- is implicitly declared at the declaration of the type
2136 -- of the operand. Recover the sloc of that declaration
2137 -- for the error message.
2139 if Nkind
(N
) in N_Op
2140 and then Scope
(It
.Nam
) = Standard_Standard
2141 and then not Is_Overloaded
(Right_Opnd
(N
))
2142 and then Scope
(Base_Type
(Etype
(Right_Opnd
(N
)))) /=
2145 Err_Type
:= First_Subtype
(Etype
(Right_Opnd
(N
)));
2147 if Comes_From_Source
(Err_Type
)
2148 and then Present
(Parent
(Err_Type
))
2150 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2153 elsif Nkind
(N
) in N_Binary_Op
2154 and then Scope
(It
.Nam
) = Standard_Standard
2155 and then not Is_Overloaded
(Left_Opnd
(N
))
2156 and then Scope
(Base_Type
(Etype
(Left_Opnd
(N
)))) /=
2159 Err_Type
:= First_Subtype
(Etype
(Left_Opnd
(N
)));
2161 if Comes_From_Source
(Err_Type
)
2162 and then Present
(Parent
(Err_Type
))
2164 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
2167 -- If this is an indirect call, use the subprogram_type
2168 -- in the message, to have a meaningful location.
2169 -- Also indicate if this is an inherited operation,
2170 -- created by a type declaration.
2172 elsif Nkind
(N
) = N_Function_Call
2173 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2174 and then Is_Type
(It
.Nam
)
2178 Sloc
(Associated_Node_For_Itype
(Err_Type
));
2183 if Nkind
(N
) in N_Op
2184 and then Scope
(It
.Nam
) = Standard_Standard
2185 and then Present
(Err_Type
)
2187 -- Special-case the message for universal_fixed
2188 -- operators, which are not declared with the type
2189 -- of the operand, but appear forever in Standard.
2191 if It
.Typ
= Universal_Fixed
2192 and then Scope
(It
.Nam
) = Standard_Standard
2195 ("\\possible interpretation as " &
2196 "universal_fixed operation " &
2197 "(RM 4.5.5 (19))", N
);
2200 ("\\possible interpretation (predefined)#!", N
);
2204 Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
2207 ("\\possible interpretation (inherited)#!", N
);
2209 Error_Msg_N
-- CODEFIX
2210 ("\\possible interpretation#!", N
);
2216 -- We have a matching interpretation, Expr_Type is the type
2217 -- from this interpretation, and Seen is the entity.
2219 -- For an operator, just set the entity name. The type will be
2220 -- set by the specific operator resolution routine.
2222 if Nkind
(N
) in N_Op
then
2223 Set_Entity
(N
, Seen
);
2224 Generate_Reference
(Seen
, N
);
2226 elsif Nkind
(N
) = N_Case_Expression
then
2227 Set_Etype
(N
, Expr_Type
);
2229 elsif Nkind
(N
) = N_Character_Literal
then
2230 Set_Etype
(N
, Expr_Type
);
2232 elsif Nkind
(N
) = N_Conditional_Expression
then
2233 Set_Etype
(N
, Expr_Type
);
2235 -- For an explicit dereference, attribute reference, range,
2236 -- short-circuit form (which is not an operator node), or call
2237 -- with a name that is an explicit dereference, there is
2238 -- nothing to be done at this point.
2240 elsif Nkind_In
(N
, N_Explicit_Dereference
,
2241 N_Attribute_Reference
,
2243 N_Indexed_Component
,
2246 N_Selected_Component
,
2248 or else Nkind
(Name
(N
)) = N_Explicit_Dereference
2252 -- For procedure or function calls, set the type of the name,
2253 -- and also the entity pointer for the prefix.
2255 elsif Nkind_In
(N
, N_Procedure_Call_Statement
, N_Function_Call
)
2256 and then (Is_Entity_Name
(Name
(N
))
2257 or else Nkind
(Name
(N
)) = N_Operator_Symbol
)
2259 Set_Etype
(Name
(N
), Expr_Type
);
2260 Set_Entity
(Name
(N
), Seen
);
2261 Generate_Reference
(Seen
, Name
(N
));
2263 elsif Nkind
(N
) = N_Function_Call
2264 and then Nkind
(Name
(N
)) = N_Selected_Component
2266 Set_Etype
(Name
(N
), Expr_Type
);
2267 Set_Entity
(Selector_Name
(Name
(N
)), Seen
);
2268 Generate_Reference
(Seen
, Selector_Name
(Name
(N
)));
2270 -- For all other cases, just set the type of the Name
2273 Set_Etype
(Name
(N
), Expr_Type
);
2280 -- Move to next interpretation
2282 exit Interp_Loop
when No
(It
.Typ
);
2284 Get_Next_Interp
(I
, It
);
2285 end loop Interp_Loop
;
2288 -- At this stage Found indicates whether or not an acceptable
2289 -- interpretation exists. If not, then we have an error, except that if
2290 -- the context is Any_Type as a result of some other error, then we
2291 -- suppress the error report.
2294 if Typ
/= Any_Type
then
2296 -- If type we are looking for is Void, then this is the procedure
2297 -- call case, and the error is simply that what we gave is not a
2298 -- procedure name (we think of procedure calls as expressions with
2299 -- types internally, but the user doesn't think of them this way!)
2301 if Typ
= Standard_Void_Type
then
2303 -- Special case message if function used as a procedure
2305 if Nkind
(N
) = N_Procedure_Call_Statement
2306 and then Is_Entity_Name
(Name
(N
))
2307 and then Ekind
(Entity
(Name
(N
))) = E_Function
2310 ("cannot use function & in a procedure call",
2311 Name
(N
), Entity
(Name
(N
)));
2313 -- Otherwise give general message (not clear what cases this
2314 -- covers, but no harm in providing for them!)
2317 Error_Msg_N
("expect procedure name in procedure call", N
);
2322 -- Otherwise we do have a subexpression with the wrong type
2324 -- Check for the case of an allocator which uses an access type
2325 -- instead of the designated type. This is a common error and we
2326 -- specialize the message, posting an error on the operand of the
2327 -- allocator, complaining that we expected the designated type of
2330 elsif Nkind
(N
) = N_Allocator
2331 and then Ekind
(Typ
) in Access_Kind
2332 and then Ekind
(Etype
(N
)) in Access_Kind
2333 and then Designated_Type
(Etype
(N
)) = Typ
2335 Wrong_Type
(Expression
(N
), Designated_Type
(Typ
));
2338 -- Check for view mismatch on Null in instances, for which the
2339 -- view-swapping mechanism has no identifier.
2341 elsif (In_Instance
or else In_Inlined_Body
)
2342 and then (Nkind
(N
) = N_Null
)
2343 and then Is_Private_Type
(Typ
)
2344 and then Is_Access_Type
(Full_View
(Typ
))
2346 Resolve
(N
, Full_View
(Typ
));
2350 -- Check for an aggregate. Sometimes we can get bogus aggregates
2351 -- from misuse of parentheses, and we are about to complain about
2352 -- the aggregate without even looking inside it.
2354 -- Instead, if we have an aggregate of type Any_Composite, then
2355 -- analyze and resolve the component fields, and then only issue
2356 -- another message if we get no errors doing this (otherwise
2357 -- assume that the errors in the aggregate caused the problem).
2359 elsif Nkind
(N
) = N_Aggregate
2360 and then Etype
(N
) = Any_Composite
2362 -- Disable expansion in any case. If there is a type mismatch
2363 -- it may be fatal to try to expand the aggregate. The flag
2364 -- would otherwise be set to false when the error is posted.
2366 Expander_Active
:= False;
2369 procedure Check_Aggr
(Aggr
: Node_Id
);
2370 -- Check one aggregate, and set Found to True if we have a
2371 -- definite error in any of its elements
2373 procedure Check_Elmt
(Aelmt
: Node_Id
);
2374 -- Check one element of aggregate and set Found to True if
2375 -- we definitely have an error in the element.
2381 procedure Check_Aggr
(Aggr
: Node_Id
) is
2385 if Present
(Expressions
(Aggr
)) then
2386 Elmt
:= First
(Expressions
(Aggr
));
2387 while Present
(Elmt
) loop
2393 if Present
(Component_Associations
(Aggr
)) then
2394 Elmt
:= First
(Component_Associations
(Aggr
));
2395 while Present
(Elmt
) loop
2397 -- If this is a default-initialized component, then
2398 -- there is nothing to check. The box will be
2399 -- replaced by the appropriate call during late
2402 if not Box_Present
(Elmt
) then
2403 Check_Elmt
(Expression
(Elmt
));
2415 procedure Check_Elmt
(Aelmt
: Node_Id
) is
2417 -- If we have a nested aggregate, go inside it (to
2418 -- attempt a naked analyze-resolve of the aggregate
2419 -- can cause undesirable cascaded errors). Do not
2420 -- resolve expression if it needs a type from context,
2421 -- as for integer * fixed expression.
2423 if Nkind
(Aelmt
) = N_Aggregate
then
2429 if not Is_Overloaded
(Aelmt
)
2430 and then Etype
(Aelmt
) /= Any_Fixed
2435 if Etype
(Aelmt
) = Any_Type
then
2446 -- If an error message was issued already, Found got reset
2447 -- to True, so if it is still False, issue the standard
2448 -- Wrong_Type message.
2451 if Is_Overloaded
(N
)
2452 and then Nkind
(N
) = N_Function_Call
2455 Subp_Name
: Node_Id
;
2457 if Is_Entity_Name
(Name
(N
)) then
2458 Subp_Name
:= Name
(N
);
2460 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2462 -- Protected operation: retrieve operation name
2464 Subp_Name
:= Selector_Name
(Name
(N
));
2466 raise Program_Error
;
2469 Error_Msg_Node_2
:= Typ
;
2470 Error_Msg_NE
("no visible interpretation of&" &
2471 " matches expected type&", N
, Subp_Name
);
2474 if All_Errors_Mode
then
2476 Index
: Interp_Index
;
2480 Error_Msg_N
("\\possible interpretations:", N
);
2482 Get_First_Interp
(Name
(N
), Index
, It
);
2483 while Present
(It
.Nam
) loop
2484 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2485 Error_Msg_Node_2
:= It
.Nam
;
2487 ("\\ type& for & declared#", N
, It
.Typ
);
2488 Get_Next_Interp
(Index
, It
);
2493 Error_Msg_N
("\use -gnatf for details", N
);
2496 Wrong_Type
(N
, Typ
);
2504 -- Test if we have more than one interpretation for the context
2506 elsif Ambiguous
then
2510 -- Here we have an acceptable interpretation for the context
2513 -- Propagate type information and normalize tree for various
2514 -- predefined operations. If the context only imposes a class of
2515 -- types, rather than a specific type, propagate the actual type
2518 if Typ
= Any_Integer
2519 or else Typ
= Any_Boolean
2520 or else Typ
= Any_Modular
2521 or else Typ
= Any_Real
2522 or else Typ
= Any_Discrete
2524 Ctx_Type
:= Expr_Type
;
2526 -- Any_Fixed is legal in a real context only if a specific
2527 -- fixed point type is imposed. If Norman Cohen can be
2528 -- confused by this, it deserves a separate message.
2531 and then Expr_Type
= Any_Fixed
2533 Error_Msg_N
("illegal context for mixed mode operation", N
);
2534 Set_Etype
(N
, Universal_Real
);
2535 Ctx_Type
:= Universal_Real
;
2539 -- A user-defined operator is transformed into a function call at
2540 -- this point, so that further processing knows that operators are
2541 -- really operators (i.e. are predefined operators). User-defined
2542 -- operators that are intrinsic are just renamings of the predefined
2543 -- ones, and need not be turned into calls either, but if they rename
2544 -- a different operator, we must transform the node accordingly.
2545 -- Instantiations of Unchecked_Conversion are intrinsic but are
2546 -- treated as functions, even if given an operator designator.
2548 if Nkind
(N
) in N_Op
2549 and then Present
(Entity
(N
))
2550 and then Ekind
(Entity
(N
)) /= E_Operator
2553 if not Is_Predefined_Op
(Entity
(N
)) then
2554 Rewrite_Operator_As_Call
(N
, Entity
(N
));
2556 elsif Present
(Alias
(Entity
(N
)))
2558 Nkind
(Parent
(Parent
(Entity
(N
)))) =
2559 N_Subprogram_Renaming_Declaration
2561 Rewrite_Renamed_Operator
(N
, Alias
(Entity
(N
)), Typ
);
2563 -- If the node is rewritten, it will be fully resolved in
2564 -- Rewrite_Renamed_Operator.
2566 if Analyzed
(N
) then
2572 case N_Subexpr
'(Nkind (N)) is
2574 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2576 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2578 when N_Short_Circuit
2579 => Resolve_Short_Circuit (N, Ctx_Type);
2581 when N_Attribute_Reference
2582 => Resolve_Attribute (N, Ctx_Type);
2584 when N_Case_Expression
2585 => Resolve_Case_Expression (N, Ctx_Type);
2587 when N_Character_Literal
2588 => Resolve_Character_Literal (N, Ctx_Type);
2590 when N_Conditional_Expression
2591 => Resolve_Conditional_Expression (N, Ctx_Type);
2593 when N_Expanded_Name
2594 => Resolve_Entity_Name (N, Ctx_Type);
2596 when N_Explicit_Dereference
2597 => Resolve_Explicit_Dereference (N, Ctx_Type);
2599 when N_Expression_With_Actions
2600 => Resolve_Expression_With_Actions (N, Ctx_Type);
2602 when N_Extension_Aggregate
2603 => Resolve_Extension_Aggregate (N, Ctx_Type);
2605 when N_Function_Call
2606 => Resolve_Call (N, Ctx_Type);
2609 => Resolve_Entity_Name (N, Ctx_Type);
2611 when N_Indexed_Component
2612 => Resolve_Indexed_Component (N, Ctx_Type);
2614 when N_Integer_Literal
2615 => Resolve_Integer_Literal (N, Ctx_Type);
2617 when N_Membership_Test
2618 => Resolve_Membership_Op (N, Ctx_Type);
2620 when N_Null => Resolve_Null (N, Ctx_Type);
2622 when N_Op_And | N_Op_Or | N_Op_Xor
2623 => Resolve_Logical_Op (N, Ctx_Type);
2625 when N_Op_Eq | N_Op_Ne
2626 => Resolve_Equality_Op (N, Ctx_Type);
2628 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2629 => Resolve_Comparison_Op (N, Ctx_Type);
2631 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2633 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2634 N_Op_Divide | N_Op_Mod | N_Op_Rem
2636 => Resolve_Arithmetic_Op (N, Ctx_Type);
2638 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2640 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2642 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2643 => Resolve_Unary_Op (N, Ctx_Type);
2645 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2647 when N_Procedure_Call_Statement
2648 => Resolve_Call (N, Ctx_Type);
2650 when N_Operator_Symbol
2651 => Resolve_Operator_Symbol (N, Ctx_Type);
2653 when N_Qualified_Expression
2654 => Resolve_Qualified_Expression (N, Ctx_Type);
2656 when N_Raise_xxx_Error
2657 => Set_Etype (N, Ctx_Type);
2659 when N_Range => Resolve_Range (N, Ctx_Type);
2662 => Resolve_Real_Literal (N, Ctx_Type);
2664 when N_Reference => Resolve_Reference (N, Ctx_Type);
2666 when N_Selected_Component
2667 => Resolve_Selected_Component (N, Ctx_Type);
2669 when N_Slice => Resolve_Slice (N, Ctx_Type);
2671 when N_String_Literal
2672 => Resolve_String_Literal (N, Ctx_Type);
2674 when N_Subprogram_Info
2675 => Resolve_Subprogram_Info (N, Ctx_Type);
2677 when N_Type_Conversion
2678 => Resolve_Type_Conversion (N, Ctx_Type);
2680 when N_Unchecked_Expression =>
2681 Resolve_Unchecked_Expression (N, Ctx_Type);
2683 when N_Unchecked_Type_Conversion =>
2684 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2687 -- If the subexpression was replaced by a non-subexpression, then
2688 -- all we do is to expand it. The only legitimate case we know of
2689 -- is converting procedure call statement to entry call statements,
2690 -- but there may be others, so we are making this test general.
2692 if Nkind (N) not in N_Subexpr then
2693 Debug_A_Exit ("resolving ", N, " (done)");
2698 -- The expression is definitely NOT overloaded at this point, so
2699 -- we reset the Is_Overloaded flag to avoid any confusion when
2700 -- reanalyzing the node.
2702 Set_Is_Overloaded (N, False);
2704 -- Freeze expression type, entity if it is a name, and designated
2705 -- type if it is an allocator (RM 13.14(10,11,13)).
2707 -- Now that the resolution of the type of the node is complete,
2708 -- and we did not detect an error, we can expand this node. We
2709 -- skip the expand call if we are in a default expression, see
2710 -- section "Handling of Default Expressions" in Sem spec.
2712 Debug_A_Exit ("resolving ", N, " (done)");
2714 -- We unconditionally freeze the expression, even if we are in
2715 -- default expression mode (the Freeze_Expression routine tests
2716 -- this flag and only freezes static types if it is set).
2718 Freeze_Expression (N);
2720 -- Now we can do the expansion
2730 -- Version with check(s) suppressed
2732 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2734 if Suppress = All_Checks then
2736 Svg : constant Suppress_Array := Scope_Suppress;
2738 Scope_Suppress := (others => True);
2740 Scope_Suppress := Svg;
2745 Svg : constant Boolean := Scope_Suppress (Suppress);
2747 Scope_Suppress (Suppress) := True;
2749 Scope_Suppress (Suppress) := Svg;
2758 -- Version with implicit type
2760 procedure Resolve (N : Node_Id) is
2762 Resolve (N, Etype (N));
2765 ---------------------
2766 -- Resolve_Actuals --
2767 ---------------------
2769 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2770 Loc : constant Source_Ptr := Sloc (N);
2775 Prev : Node_Id := Empty;
2778 procedure Check_Argument_Order;
2779 -- Performs a check for the case where the actuals are all simple
2780 -- identifiers that correspond to the formal names, but in the wrong
2781 -- order, which is considered suspicious and cause for a warning.
2783 procedure Check_Prefixed_Call;
2784 -- If the original node is an overloaded call in prefix notation,
2785 -- insert an 'Access or a dereference as needed over the first actual
.
2786 -- Try_Object_Operation has already verified that there is a valid
2787 -- interpretation, but the form of the actual can only be determined
2788 -- once the primitive operation is identified.
2790 procedure Insert_Default
;
2791 -- If the actual is missing in a call, insert in the actuals list
2792 -- an instance of the default expression. The insertion is always
2793 -- a named association.
2795 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean;
2796 -- Check whether T1 and T2, or their full views, are derived from a
2797 -- common type. Used to enforce the restrictions on array conversions
2800 function Static_Concatenation
(N
: Node_Id
) return Boolean;
2801 -- Predicate to determine whether an actual that is a concatenation
2802 -- will be evaluated statically and does not need a transient scope.
2803 -- This must be determined before the actual is resolved and expanded
2804 -- because if needed the transient scope must be introduced earlier.
2806 --------------------------
2807 -- Check_Argument_Order --
2808 --------------------------
2810 procedure Check_Argument_Order
is
2812 -- Nothing to do if no parameters, or original node is neither a
2813 -- function call nor a procedure call statement (happens in the
2814 -- operator-transformed-to-function call case), or the call does
2815 -- not come from source, or this warning is off.
2817 if not Warn_On_Parameter_Order
2819 No
(Parameter_Associations
(N
))
2821 not Nkind_In
(Original_Node
(N
), N_Procedure_Call_Statement
,
2824 not Comes_From_Source
(N
)
2830 Nargs
: constant Nat
:= List_Length
(Parameter_Associations
(N
));
2833 -- Nothing to do if only one parameter
2839 -- Here if at least two arguments
2842 Actuals
: array (1 .. Nargs
) of Node_Id
;
2846 Wrong_Order
: Boolean := False;
2847 -- Set True if an out of order case is found
2850 -- Collect identifier names of actuals, fail if any actual is
2851 -- not a simple identifier, and record max length of name.
2853 Actual
:= First
(Parameter_Associations
(N
));
2854 for J
in Actuals
'Range loop
2855 if Nkind
(Actual
) /= N_Identifier
then
2858 Actuals
(J
) := Actual
;
2863 -- If we got this far, all actuals are identifiers and the list
2864 -- of their names is stored in the Actuals array.
2866 Formal
:= First_Formal
(Nam
);
2867 for J
in Actuals
'Range loop
2869 -- If we ran out of formals, that's odd, probably an error
2870 -- which will be detected elsewhere, but abandon the search.
2876 -- If name matches and is in order OK
2878 if Chars
(Formal
) = Chars
(Actuals
(J
)) then
2882 -- If no match, see if it is elsewhere in list and if so
2883 -- flag potential wrong order if type is compatible.
2885 for K
in Actuals
'Range loop
2886 if Chars
(Formal
) = Chars
(Actuals
(K
))
2888 Has_Compatible_Type
(Actuals
(K
), Etype
(Formal
))
2890 Wrong_Order
:= True;
2900 <<Continue
>> Next_Formal
(Formal
);
2903 -- If Formals left over, also probably an error, skip warning
2905 if Present
(Formal
) then
2909 -- Here we give the warning if something was out of order
2913 ("actuals for this call may be in wrong order?", N
);
2917 end Check_Argument_Order
;
2919 -------------------------
2920 -- Check_Prefixed_Call --
2921 -------------------------
2923 procedure Check_Prefixed_Call
is
2924 Act
: constant Node_Id
:= First_Actual
(N
);
2925 A_Type
: constant Entity_Id
:= Etype
(Act
);
2926 F_Type
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
2927 Orig
: constant Node_Id
:= Original_Node
(N
);
2931 -- Check whether the call is a prefixed call, with or without
2932 -- additional actuals.
2934 if Nkind
(Orig
) = N_Selected_Component
2936 (Nkind
(Orig
) = N_Indexed_Component
2937 and then Nkind
(Prefix
(Orig
)) = N_Selected_Component
2938 and then Is_Entity_Name
(Prefix
(Prefix
(Orig
)))
2939 and then Is_Entity_Name
(Act
)
2940 and then Chars
(Act
) = Chars
(Prefix
(Prefix
(Orig
))))
2942 if Is_Access_Type
(A_Type
)
2943 and then not Is_Access_Type
(F_Type
)
2945 -- Introduce dereference on object in prefix
2948 Make_Explicit_Dereference
(Sloc
(Act
),
2949 Prefix
=> Relocate_Node
(Act
));
2950 Rewrite
(Act
, New_A
);
2953 elsif Is_Access_Type
(F_Type
)
2954 and then not Is_Access_Type
(A_Type
)
2956 -- Introduce an implicit 'Access in prefix
2958 if not Is_Aliased_View
(Act
) then
2960 ("object in prefixed call to& must be aliased"
2961 & " (RM-2005 4.3.1 (13))",
2966 Make_Attribute_Reference
(Loc
,
2967 Attribute_Name
=> Name_Access
,
2968 Prefix
=> Relocate_Node
(Act
)));
2973 end Check_Prefixed_Call
;
2975 --------------------
2976 -- Insert_Default --
2977 --------------------
2979 procedure Insert_Default
is
2984 -- Missing argument in call, nothing to insert
2986 if No
(Default_Value
(F
)) then
2990 -- Note that we do a full New_Copy_Tree, so that any associated
2991 -- Itypes are properly copied. This may not be needed any more,
2992 -- but it does no harm as a safety measure! Defaults of a generic
2993 -- formal may be out of bounds of the corresponding actual (see
2994 -- cc1311b) and an additional check may be required.
2999 New_Scope
=> Current_Scope
,
3002 if Is_Concurrent_Type
(Scope
(Nam
))
3003 and then Has_Discriminants
(Scope
(Nam
))
3005 Replace_Actual_Discriminants
(N
, Actval
);
3008 if Is_Overloadable
(Nam
)
3009 and then Present
(Alias
(Nam
))
3011 if Base_Type
(Etype
(F
)) /= Base_Type
(Etype
(Actval
))
3012 and then not Is_Tagged_Type
(Etype
(F
))
3014 -- If default is a real literal, do not introduce a
3015 -- conversion whose effect may depend on the run-time
3016 -- size of universal real.
3018 if Nkind
(Actval
) = N_Real_Literal
then
3019 Set_Etype
(Actval
, Base_Type
(Etype
(F
)));
3021 Actval
:= Unchecked_Convert_To
(Etype
(F
), Actval
);
3025 if Is_Scalar_Type
(Etype
(F
)) then
3026 Enable_Range_Check
(Actval
);
3029 Set_Parent
(Actval
, N
);
3031 -- Resolve aggregates with their base type, to avoid scope
3032 -- anomalies: the subtype was first built in the subprogram
3033 -- declaration, and the current call may be nested.
3035 if Nkind
(Actval
) = N_Aggregate
then
3036 Analyze_And_Resolve
(Actval
, Etype
(F
));
3038 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3042 Set_Parent
(Actval
, N
);
3044 -- See note above concerning aggregates
3046 if Nkind
(Actval
) = N_Aggregate
3047 and then Has_Discriminants
(Etype
(Actval
))
3049 Analyze_And_Resolve
(Actval
, Base_Type
(Etype
(Actval
)));
3051 -- Resolve entities with their own type, which may differ
3052 -- from the type of a reference in a generic context (the
3053 -- view swapping mechanism did not anticipate the re-analysis
3054 -- of default values in calls).
3056 elsif Is_Entity_Name
(Actval
) then
3057 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Actval
)));
3060 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
3064 -- If default is a tag indeterminate function call, propagate
3065 -- tag to obtain proper dispatching.
3067 if Is_Controlling_Formal
(F
)
3068 and then Nkind
(Default_Value
(F
)) = N_Function_Call
3070 Set_Is_Controlling_Actual
(Actval
);
3075 -- If the default expression raises constraint error, then just
3076 -- silently replace it with an N_Raise_Constraint_Error node,
3077 -- since we already gave the warning on the subprogram spec.
3079 if Raises_Constraint_Error
(Actval
) then
3081 Make_Raise_Constraint_Error
(Loc
,
3082 Reason
=> CE_Range_Check_Failed
));
3083 Set_Raises_Constraint_Error
(Actval
);
3084 Set_Etype
(Actval
, Etype
(F
));
3088 Make_Parameter_Association
(Loc
,
3089 Explicit_Actual_Parameter
=> Actval
,
3090 Selector_Name
=> Make_Identifier
(Loc
, Chars
(F
)));
3092 -- Case of insertion is first named actual
3094 if No
(Prev
) or else
3095 Nkind
(Parent
(Prev
)) /= N_Parameter_Association
3097 Set_Next_Named_Actual
(Assoc
, First_Named_Actual
(N
));
3098 Set_First_Named_Actual
(N
, Actval
);
3101 if No
(Parameter_Associations
(N
)) then
3102 Set_Parameter_Associations
(N
, New_List
(Assoc
));
3104 Append
(Assoc
, Parameter_Associations
(N
));
3108 Insert_After
(Prev
, Assoc
);
3111 -- Case of insertion is not first named actual
3114 Set_Next_Named_Actual
3115 (Assoc
, Next_Named_Actual
(Parent
(Prev
)));
3116 Set_Next_Named_Actual
(Parent
(Prev
), Actval
);
3117 Append
(Assoc
, Parameter_Associations
(N
));
3120 Mark_Rewrite_Insertion
(Assoc
);
3121 Mark_Rewrite_Insertion
(Actval
);
3130 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean is
3131 FT1
: Entity_Id
:= T1
;
3132 FT2
: Entity_Id
:= T2
;
3135 if Is_Private_Type
(T1
)
3136 and then Present
(Full_View
(T1
))
3138 FT1
:= Full_View
(T1
);
3141 if Is_Private_Type
(T2
)
3142 and then Present
(Full_View
(T2
))
3144 FT2
:= Full_View
(T2
);
3147 return Root_Type
(Base_Type
(FT1
)) = Root_Type
(Base_Type
(FT2
));
3150 --------------------------
3151 -- Static_Concatenation --
3152 --------------------------
3154 function Static_Concatenation
(N
: Node_Id
) return Boolean is
3157 when N_String_Literal
=>
3162 -- Concatenation is static when both operands are static
3163 -- and the concatenation operator is a predefined one.
3165 return Scope
(Entity
(N
)) = Standard_Standard
3167 Static_Concatenation
(Left_Opnd
(N
))
3169 Static_Concatenation
(Right_Opnd
(N
));
3172 if Is_Entity_Name
(N
) then
3174 Ent
: constant Entity_Id
:= Entity
(N
);
3176 return Ekind
(Ent
) = E_Constant
3177 and then Present
(Constant_Value
(Ent
))
3179 Is_Static_Expression
(Constant_Value
(Ent
));
3186 end Static_Concatenation
;
3188 -- Start of processing for Resolve_Actuals
3191 Check_Argument_Order
;
3193 if Present
(First_Actual
(N
)) then
3194 Check_Prefixed_Call
;
3197 A
:= First_Actual
(N
);
3198 F
:= First_Formal
(Nam
);
3199 while Present
(F
) loop
3200 if No
(A
) and then Needs_No_Actuals
(Nam
) then
3203 -- If we have an error in any actual or formal, indicated by a type
3204 -- of Any_Type, then abandon resolution attempt, and set result type
3207 elsif (Present
(A
) and then Etype
(A
) = Any_Type
)
3208 or else Etype
(F
) = Any_Type
3210 Set_Etype
(N
, Any_Type
);
3214 -- Case where actual is present
3216 -- If the actual is an entity, generate a reference to it now. We
3217 -- do this before the actual is resolved, because a formal of some
3218 -- protected subprogram, or a task discriminant, will be rewritten
3219 -- during expansion, and the reference to the source entity may
3223 and then Is_Entity_Name
(A
)
3224 and then Comes_From_Source
(N
)
3226 Orig_A
:= Entity
(A
);
3228 if Present
(Orig_A
) then
3229 if Is_Formal
(Orig_A
)
3230 and then Ekind
(F
) /= E_In_Parameter
3232 Generate_Reference
(Orig_A
, A
, 'm');
3233 elsif not Is_Overloaded
(A
) then
3234 Generate_Reference
(Orig_A
, A
);
3240 and then (Nkind
(Parent
(A
)) /= N_Parameter_Association
3242 Chars
(Selector_Name
(Parent
(A
))) = Chars
(F
))
3244 -- If style checking mode on, check match of formal name
3247 if Nkind
(Parent
(A
)) = N_Parameter_Association
then
3248 Check_Identifier
(Selector_Name
(Parent
(A
)), F
);
3252 -- If the formal is Out or In_Out, do not resolve and expand the
3253 -- conversion, because it is subsequently expanded into explicit
3254 -- temporaries and assignments. However, the object of the
3255 -- conversion can be resolved. An exception is the case of tagged
3256 -- type conversion with a class-wide actual. In that case we want
3257 -- the tag check to occur and no temporary will be needed (no
3258 -- representation change can occur) and the parameter is passed by
3259 -- reference, so we go ahead and resolve the type conversion.
3260 -- Another exception is the case of reference to component or
3261 -- subcomponent of a bit-packed array, in which case we want to
3262 -- defer expansion to the point the in and out assignments are
3265 if Ekind
(F
) /= E_In_Parameter
3266 and then Nkind
(A
) = N_Type_Conversion
3267 and then not Is_Class_Wide_Type
(Etype
(Expression
(A
)))
3269 if Ekind
(F
) = E_In_Out_Parameter
3270 and then Is_Array_Type
(Etype
(F
))
3272 if Has_Aliased_Components
(Etype
(Expression
(A
)))
3273 /= Has_Aliased_Components
(Etype
(F
))
3276 -- In a view conversion, the conversion must be legal in
3277 -- both directions, and thus both component types must be
3278 -- aliased, or neither (4.6 (8)).
3280 -- The additional rule 4.6 (24.9.2) seems unduly
3281 -- restrictive: the privacy requirement should not apply
3282 -- to generic types, and should be checked in an
3283 -- instance. ARG query is in order ???
3286 ("both component types in a view conversion must be"
3287 & " aliased, or neither", A
);
3290 not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
3292 if Is_By_Reference_Type
(Etype
(F
))
3293 or else Is_By_Reference_Type
(Etype
(Expression
(A
)))
3296 ("view conversion between unrelated by reference " &
3297 "array types not allowed (\'A'I-00246)", A
);
3300 Comp_Type
: constant Entity_Id
:=
3302 (Etype
(Expression
(A
)));
3304 if Comes_From_Source
(A
)
3305 and then Ada_Version
>= Ada_05
3307 ((Is_Private_Type
(Comp_Type
)
3308 and then not Is_Generic_Type
(Comp_Type
))
3309 or else Is_Tagged_Type
(Comp_Type
)
3310 or else Is_Volatile
(Comp_Type
))
3313 ("component type of a view conversion cannot"
3314 & " be private, tagged, or volatile"
3323 if (Conversion_OK
(A
)
3324 or else Valid_Conversion
(A
, Etype
(A
), Expression
(A
)))
3325 and then not Is_Ref_To_Bit_Packed_Array
(Expression
(A
))
3327 Resolve
(Expression
(A
));
3330 -- If the actual is a function call that returns a limited
3331 -- unconstrained object that needs finalization, create a
3332 -- transient scope for it, so that it can receive the proper
3333 -- finalization list.
3335 elsif Nkind
(A
) = N_Function_Call
3336 and then Is_Limited_Record
(Etype
(F
))
3337 and then not Is_Constrained
(Etype
(F
))
3338 and then Expander_Active
3340 (Is_Controlled
(Etype
(F
)) or else Has_Task
(Etype
(F
)))
3342 Establish_Transient_Scope
(A
, False);
3344 -- A small optimization: if one of the actuals is a concatenation
3345 -- create a block around a procedure call to recover stack space.
3346 -- This alleviates stack usage when several procedure calls in
3347 -- the same statement list use concatenation. We do not perform
3348 -- this wrapping for code statements, where the argument is a
3349 -- static string, and we want to preserve warnings involving
3350 -- sequences of such statements.
3352 elsif Nkind
(A
) = N_Op_Concat
3353 and then Nkind
(N
) = N_Procedure_Call_Statement
3354 and then Expander_Active
3356 not (Is_Intrinsic_Subprogram
(Nam
)
3357 and then Chars
(Nam
) = Name_Asm
)
3358 and then not Static_Concatenation
(A
)
3360 Establish_Transient_Scope
(A
, False);
3361 Resolve
(A
, Etype
(F
));
3364 if Nkind
(A
) = N_Type_Conversion
3365 and then Is_Array_Type
(Etype
(F
))
3366 and then not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
3368 (Is_Limited_Type
(Etype
(F
))
3369 or else Is_Limited_Type
(Etype
(Expression
(A
))))
3372 ("conversion between unrelated limited array types " &
3373 "not allowed (\A\I-00246)", A
);
3375 if Is_Limited_Type
(Etype
(F
)) then
3376 Explain_Limited_Type
(Etype
(F
), A
);
3379 if Is_Limited_Type
(Etype
(Expression
(A
))) then
3380 Explain_Limited_Type
(Etype
(Expression
(A
)), A
);
3384 -- (Ada 2005: AI-251): If the actual is an allocator whose
3385 -- directly designated type is a class-wide interface, we build
3386 -- an anonymous access type to use it as the type of the
3387 -- allocator. Later, when the subprogram call is expanded, if
3388 -- the interface has a secondary dispatch table the expander
3389 -- will add a type conversion to force the correct displacement
3392 if Nkind
(A
) = N_Allocator
then
3394 DDT
: constant Entity_Id
:=
3395 Directly_Designated_Type
(Base_Type
(Etype
(F
)));
3397 New_Itype
: Entity_Id
;
3400 if Is_Class_Wide_Type
(DDT
)
3401 and then Is_Interface
(DDT
)
3403 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, A
);
3404 Set_Etype
(New_Itype
, Etype
(A
));
3405 Set_Directly_Designated_Type
(New_Itype
,
3406 Directly_Designated_Type
(Etype
(A
)));
3407 Set_Etype
(A
, New_Itype
);
3410 -- Ada 2005, AI-162:If the actual is an allocator, the
3411 -- innermost enclosing statement is the master of the
3412 -- created object. This needs to be done with expansion
3413 -- enabled only, otherwise the transient scope will not
3414 -- be removed in the expansion of the wrapped construct.
3416 if (Is_Controlled
(DDT
) or else Has_Task
(DDT
))
3417 and then Expander_Active
3419 Establish_Transient_Scope
(A
, False);
3424 -- (Ada 2005): The call may be to a primitive operation of
3425 -- a tagged synchronized type, declared outside of the type.
3426 -- In this case the controlling actual must be converted to
3427 -- its corresponding record type, which is the formal type.
3428 -- The actual may be a subtype, either because of a constraint
3429 -- or because it is a generic actual, so use base type to
3430 -- locate concurrent type.
3432 A_Typ
:= Base_Type
(Etype
(A
));
3433 F_Typ
:= Base_Type
(Etype
(F
));
3436 Full_A_Typ
: Entity_Id
;
3439 if Present
(Full_View
(A_Typ
)) then
3440 Full_A_Typ
:= Base_Type
(Full_View
(A_Typ
));
3442 Full_A_Typ
:= A_Typ
;
3445 -- Tagged synchronized type (case 1): the actual is a
3448 if Is_Concurrent_Type
(A_Typ
)
3449 and then Corresponding_Record_Type
(A_Typ
) = F_Typ
3452 Unchecked_Convert_To
3453 (Corresponding_Record_Type
(A_Typ
), A
));
3454 Resolve
(A
, Etype
(F
));
3456 -- Tagged synchronized type (case 2): the formal is a
3459 elsif Ekind
(Full_A_Typ
) = E_Record_Type
3461 (Corresponding_Concurrent_Type
(Full_A_Typ
))
3462 and then Is_Concurrent_Type
(F_Typ
)
3463 and then Present
(Corresponding_Record_Type
(F_Typ
))
3464 and then Full_A_Typ
= Corresponding_Record_Type
(F_Typ
)
3466 Resolve
(A
, Corresponding_Record_Type
(F_Typ
));
3471 Resolve
(A
, Etype
(F
));
3479 -- Save actual for subsequent check on order dependence,
3480 -- and indicate whether actual is modifiable. For AI05-0144
3483 -- Ekind (F) /= E_In_Parameter or else Is_Access_Type (F_Typ));
3484 -- Why is this code commented out ???
3486 -- For mode IN, if actual is an entity, and the type of the formal
3487 -- has warnings suppressed, then we reset Never_Set_In_Source for
3488 -- the calling entity. The reason for this is to catch cases like
3489 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3490 -- uses trickery to modify an IN parameter.
3492 if Ekind
(F
) = E_In_Parameter
3493 and then Is_Entity_Name
(A
)
3494 and then Present
(Entity
(A
))
3495 and then Ekind
(Entity
(A
)) = E_Variable
3496 and then Has_Warnings_Off
(F_Typ
)
3498 Set_Never_Set_In_Source
(Entity
(A
), False);
3501 -- Perform error checks for IN and IN OUT parameters
3503 if Ekind
(F
) /= E_Out_Parameter
then
3505 -- Check unset reference. For scalar parameters, it is clearly
3506 -- wrong to pass an uninitialized value as either an IN or
3507 -- IN-OUT parameter. For composites, it is also clearly an
3508 -- error to pass a completely uninitialized value as an IN
3509 -- parameter, but the case of IN OUT is trickier. We prefer
3510 -- not to give a warning here. For example, suppose there is
3511 -- a routine that sets some component of a record to False.
3512 -- It is perfectly reasonable to make this IN-OUT and allow
3513 -- either initialized or uninitialized records to be passed
3516 -- For partially initialized composite values, we also avoid
3517 -- warnings, since it is quite likely that we are passing a
3518 -- partially initialized value and only the initialized fields
3519 -- will in fact be read in the subprogram.
3521 if Is_Scalar_Type
(A_Typ
)
3522 or else (Ekind
(F
) = E_In_Parameter
3523 and then not Is_Partially_Initialized_Type
(A_Typ
))
3525 Check_Unset_Reference
(A
);
3528 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3529 -- actual to a nested call, since this is case of reading an
3530 -- out parameter, which is not allowed.
3532 if Ada_Version
= Ada_83
3533 and then Is_Entity_Name
(A
)
3534 and then Ekind
(Entity
(A
)) = E_Out_Parameter
3536 Error_Msg_N
("(Ada 83) illegal reading of out parameter", A
);
3540 -- Case of OUT or IN OUT parameter
3542 if Ekind
(F
) /= E_In_Parameter
then
3544 -- For an Out parameter, check for useless assignment. Note
3545 -- that we can't set Last_Assignment this early, because we may
3546 -- kill current values in Resolve_Call, and that call would
3547 -- clobber the Last_Assignment field.
3549 -- Note: call Warn_On_Useless_Assignment before doing the check
3550 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3551 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3552 -- reflects the last assignment, not this one!
3554 if Ekind
(F
) = E_Out_Parameter
then
3555 if Warn_On_Modified_As_Out_Parameter
(F
)
3556 and then Is_Entity_Name
(A
)
3557 and then Present
(Entity
(A
))
3558 and then Comes_From_Source
(N
)
3560 Warn_On_Useless_Assignment
(Entity
(A
), A
);
3564 -- Validate the form of the actual. Note that the call to
3565 -- Is_OK_Variable_For_Out_Formal generates the required
3566 -- reference in this case.
3568 if not Is_OK_Variable_For_Out_Formal
(A
) then
3569 Error_Msg_NE
("actual for& must be a variable", A
, F
);
3572 -- What's the following about???
3574 if Is_Entity_Name
(A
) then
3575 Kill_Checks
(Entity
(A
));
3581 if Etype
(A
) = Any_Type
then
3582 Set_Etype
(N
, Any_Type
);
3586 -- Apply appropriate range checks for in, out, and in-out
3587 -- parameters. Out and in-out parameters also need a separate
3588 -- check, if there is a type conversion, to make sure the return
3589 -- value meets the constraints of the variable before the
3592 -- Gigi looks at the check flag and uses the appropriate types.
3593 -- For now since one flag is used there is an optimization which
3594 -- might not be done in the In Out case since Gigi does not do
3595 -- any analysis. More thought required about this ???
3597 if Ekind_In
(F
, E_In_Parameter
, E_In_Out_Parameter
) then
3598 if Is_Scalar_Type
(Etype
(A
)) then
3599 Apply_Scalar_Range_Check
(A
, F_Typ
);
3601 elsif Is_Array_Type
(Etype
(A
)) then
3602 Apply_Length_Check
(A
, F_Typ
);
3604 elsif Is_Record_Type
(F_Typ
)
3605 and then Has_Discriminants
(F_Typ
)
3606 and then Is_Constrained
(F_Typ
)
3607 and then (not Is_Derived_Type
(F_Typ
)
3608 or else Comes_From_Source
(Nam
))
3610 Apply_Discriminant_Check
(A
, F_Typ
);
3612 elsif Is_Access_Type
(F_Typ
)
3613 and then Is_Array_Type
(Designated_Type
(F_Typ
))
3614 and then Is_Constrained
(Designated_Type
(F_Typ
))
3616 Apply_Length_Check
(A
, F_Typ
);
3618 elsif Is_Access_Type
(F_Typ
)
3619 and then Has_Discriminants
(Designated_Type
(F_Typ
))
3620 and then Is_Constrained
(Designated_Type
(F_Typ
))
3622 Apply_Discriminant_Check
(A
, F_Typ
);
3625 Apply_Range_Check
(A
, F_Typ
);
3628 -- Ada 2005 (AI-231)
3630 if Ada_Version
>= Ada_05
3631 and then Is_Access_Type
(F_Typ
)
3632 and then Can_Never_Be_Null
(F_Typ
)
3633 and then Known_Null
(A
)
3635 Apply_Compile_Time_Constraint_Error
3637 Msg
=> "(Ada 2005) null not allowed in "
3638 & "null-excluding formal?",
3639 Reason
=> CE_Null_Not_Allowed
);
3643 if Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
) then
3644 if Nkind
(A
) = N_Type_Conversion
then
3645 if Is_Scalar_Type
(A_Typ
) then
3646 Apply_Scalar_Range_Check
3647 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
3650 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
3654 if Is_Scalar_Type
(F_Typ
) then
3655 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
3657 elsif Is_Array_Type
(F_Typ
)
3658 and then Ekind
(F
) = E_Out_Parameter
3660 Apply_Length_Check
(A
, F_Typ
);
3663 Apply_Range_Check
(A
, A_Typ
, F_Typ
);
3668 -- An actual associated with an access parameter is implicitly
3669 -- converted to the anonymous access type of the formal and must
3670 -- satisfy the legality checks for access conversions.
3672 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
3673 if not Valid_Conversion
(A
, F_Typ
, A
) then
3675 ("invalid implicit conversion for access parameter", A
);
3679 -- Check bad case of atomic/volatile argument (RM C.6(12))
3681 if Is_By_Reference_Type
(Etype
(F
))
3682 and then Comes_From_Source
(N
)
3684 if Is_Atomic_Object
(A
)
3685 and then not Is_Atomic
(Etype
(F
))
3688 ("cannot pass atomic argument to non-atomic formal",
3691 elsif Is_Volatile_Object
(A
)
3692 and then not Is_Volatile
(Etype
(F
))
3695 ("cannot pass volatile argument to non-volatile formal",
3700 -- Check that subprograms don't have improper controlling
3701 -- arguments (RM 3.9.2 (9)).
3703 -- A primitive operation may have an access parameter of an
3704 -- incomplete tagged type, but a dispatching call is illegal
3705 -- if the type is still incomplete.
3707 if Is_Controlling_Formal
(F
) then
3708 Set_Is_Controlling_Actual
(A
);
3710 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
3712 Desig
: constant Entity_Id
:= Designated_Type
(Etype
(F
));
3714 if Ekind
(Desig
) = E_Incomplete_Type
3715 and then No
(Full_View
(Desig
))
3716 and then No
(Non_Limited_View
(Desig
))
3719 ("premature use of incomplete type& " &
3720 "in dispatching call", A
, Desig
);
3725 elsif Nkind
(A
) = N_Explicit_Dereference
then
3726 Validate_Remote_Access_To_Class_Wide_Type
(A
);
3729 if (Is_Class_Wide_Type
(A_Typ
) or else Is_Dynamically_Tagged
(A
))
3730 and then not Is_Class_Wide_Type
(F_Typ
)
3731 and then not Is_Controlling_Formal
(F
)
3733 Error_Msg_N
("class-wide argument not allowed here!", A
);
3735 if Is_Subprogram
(Nam
)
3736 and then Comes_From_Source
(Nam
)
3738 Error_Msg_Node_2
:= F_Typ
;
3740 ("& is not a dispatching operation of &!", A
, Nam
);
3743 elsif Is_Access_Type
(A_Typ
)
3744 and then Is_Access_Type
(F_Typ
)
3745 and then Ekind
(F_Typ
) /= E_Access_Subprogram_Type
3746 and then Ekind
(F_Typ
) /= E_Anonymous_Access_Subprogram_Type
3747 and then (Is_Class_Wide_Type
(Designated_Type
(A_Typ
))
3748 or else (Nkind
(A
) = N_Attribute_Reference
3750 Is_Class_Wide_Type
(Etype
(Prefix
(A
)))))
3751 and then not Is_Class_Wide_Type
(Designated_Type
(F_Typ
))
3752 and then not Is_Controlling_Formal
(F
)
3754 -- Disable these checks for call to imported C++ subprograms
3757 (Is_Entity_Name
(Name
(N
))
3758 and then Is_Imported
(Entity
(Name
(N
)))
3759 and then Convention
(Entity
(Name
(N
))) = Convention_CPP
)
3762 ("access to class-wide argument not allowed here!", A
);
3764 if Is_Subprogram
(Nam
)
3765 and then Comes_From_Source
(Nam
)
3767 Error_Msg_Node_2
:= Designated_Type
(F_Typ
);
3769 ("& is not a dispatching operation of &!", A
, Nam
);
3775 -- If it is a named association, treat the selector_name as
3776 -- a proper identifier, and mark the corresponding entity.
3778 if Nkind
(Parent
(A
)) = N_Parameter_Association
then
3779 Set_Entity
(Selector_Name
(Parent
(A
)), F
);
3780 Generate_Reference
(F
, Selector_Name
(Parent
(A
)));
3781 Set_Etype
(Selector_Name
(Parent
(A
)), F_Typ
);
3782 Generate_Reference
(F_Typ
, N
, ' ');
3787 if Ekind
(F
) /= E_Out_Parameter
then
3788 Check_Unset_Reference
(A
);
3793 -- Case where actual is not present
3801 end Resolve_Actuals
;
3803 -----------------------
3804 -- Resolve_Allocator --
3805 -----------------------
3807 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
) is
3808 E
: constant Node_Id
:= Expression
(N
);
3810 Discrim
: Entity_Id
;
3813 Assoc
: Node_Id
:= Empty
;
3816 procedure Check_Allocator_Discrim_Accessibility
3817 (Disc_Exp
: Node_Id
;
3818 Alloc_Typ
: Entity_Id
);
3819 -- Check that accessibility level associated with an access discriminant
3820 -- initialized in an allocator by the expression Disc_Exp is not deeper
3821 -- than the level of the allocator type Alloc_Typ. An error message is
3822 -- issued if this condition is violated. Specialized checks are done for
3823 -- the cases of a constraint expression which is an access attribute or
3824 -- an access discriminant.
3826 function In_Dispatching_Context
return Boolean;
3827 -- If the allocator is an actual in a call, it is allowed to be class-
3828 -- wide when the context is not because it is a controlling actual.
3830 procedure Propagate_Coextensions
(Root
: Node_Id
);
3831 -- Propagate all nested coextensions which are located one nesting
3832 -- level down the tree to the node Root. Example:
3835 -- Level_1_Coextension
3836 -- Level_2_Coextension
3838 -- The algorithm is paired with delay actions done by the Expander. In
3839 -- the above example, assume all coextensions are controlled types.
3840 -- The cycle of analysis, resolution and expansion will yield:
3842 -- 1) Analyze Top_Record
3843 -- 2) Analyze Level_1_Coextension
3844 -- 3) Analyze Level_2_Coextension
3845 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
3847 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3848 -- generated to capture the allocated object. Temp_1 is attached
3849 -- to the coextension chain of Level_2_Coextension.
3850 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3851 -- coextension. A forward tree traversal is performed which finds
3852 -- Level_2_Coextension's list and copies its contents into its
3854 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3855 -- generated to capture the allocated object. Temp_2 is attached
3856 -- to the coextension chain of Level_1_Coextension. Currently, the
3857 -- contents of the list are [Temp_2, Temp_1].
3858 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3859 -- finds Level_1_Coextension's list and copies its contents into
3861 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3862 -- Temp_2 and attach them to Top_Record's finalization list.
3864 -------------------------------------------
3865 -- Check_Allocator_Discrim_Accessibility --
3866 -------------------------------------------
3868 procedure Check_Allocator_Discrim_Accessibility
3869 (Disc_Exp
: Node_Id
;
3870 Alloc_Typ
: Entity_Id
)
3873 if Type_Access_Level
(Etype
(Disc_Exp
)) >
3874 Type_Access_Level
(Alloc_Typ
)
3877 ("operand type has deeper level than allocator type", Disc_Exp
);
3879 -- When the expression is an Access attribute the level of the prefix
3880 -- object must not be deeper than that of the allocator's type.
3882 elsif Nkind
(Disc_Exp
) = N_Attribute_Reference
3883 and then Get_Attribute_Id
(Attribute_Name
(Disc_Exp
))
3885 and then Object_Access_Level
(Prefix
(Disc_Exp
))
3886 > Type_Access_Level
(Alloc_Typ
)
3889 ("prefix of attribute has deeper level than allocator type",
3892 -- When the expression is an access discriminant the check is against
3893 -- the level of the prefix object.
3895 elsif Ekind
(Etype
(Disc_Exp
)) = E_Anonymous_Access_Type
3896 and then Nkind
(Disc_Exp
) = N_Selected_Component
3897 and then Object_Access_Level
(Prefix
(Disc_Exp
))
3898 > Type_Access_Level
(Alloc_Typ
)
3901 ("access discriminant has deeper level than allocator type",
3904 -- All other cases are legal
3909 end Check_Allocator_Discrim_Accessibility
;
3911 ----------------------------
3912 -- In_Dispatching_Context --
3913 ----------------------------
3915 function In_Dispatching_Context
return Boolean is
3916 Par
: constant Node_Id
:= Parent
(N
);
3918 return Nkind_In
(Par
, N_Function_Call
, N_Procedure_Call_Statement
)
3919 and then Is_Entity_Name
(Name
(Par
))
3920 and then Is_Dispatching_Operation
(Entity
(Name
(Par
)));
3921 end In_Dispatching_Context
;
3923 ----------------------------
3924 -- Propagate_Coextensions --
3925 ----------------------------
3927 procedure Propagate_Coextensions
(Root
: Node_Id
) is
3929 procedure Copy_List
(From
: Elist_Id
; To
: Elist_Id
);
3930 -- Copy the contents of list From into list To, preserving the
3931 -- order of elements.
3933 function Process_Allocator
(Nod
: Node_Id
) return Traverse_Result
;
3934 -- Recognize an allocator or a rewritten allocator node and add it
3935 -- along with its nested coextensions to the list of Root.
3941 procedure Copy_List
(From
: Elist_Id
; To
: Elist_Id
) is
3942 From_Elmt
: Elmt_Id
;
3944 From_Elmt
:= First_Elmt
(From
);
3945 while Present
(From_Elmt
) loop
3946 Append_Elmt
(Node
(From_Elmt
), To
);
3947 Next_Elmt
(From_Elmt
);
3951 -----------------------
3952 -- Process_Allocator --
3953 -----------------------
3955 function Process_Allocator
(Nod
: Node_Id
) return Traverse_Result
is
3956 Orig_Nod
: Node_Id
:= Nod
;
3959 -- This is a possible rewritten subtype indication allocator. Any
3960 -- nested coextensions will appear as discriminant constraints.
3962 if Nkind
(Nod
) = N_Identifier
3963 and then Present
(Original_Node
(Nod
))
3964 and then Nkind
(Original_Node
(Nod
)) = N_Subtype_Indication
3968 Discr_Elmt
: Elmt_Id
;
3971 if Is_Record_Type
(Entity
(Nod
)) then
3973 First_Elmt
(Discriminant_Constraint
(Entity
(Nod
)));
3974 while Present
(Discr_Elmt
) loop
3975 Discr
:= Node
(Discr_Elmt
);
3977 if Nkind
(Discr
) = N_Identifier
3978 and then Present
(Original_Node
(Discr
))
3979 and then Nkind
(Original_Node
(Discr
)) = N_Allocator
3980 and then Present
(Coextensions
(
3981 Original_Node
(Discr
)))
3983 if No
(Coextensions
(Root
)) then
3984 Set_Coextensions
(Root
, New_Elmt_List
);
3988 (From
=> Coextensions
(Original_Node
(Discr
)),
3989 To
=> Coextensions
(Root
));
3992 Next_Elmt
(Discr_Elmt
);
3995 -- There is no need to continue the traversal of this
3996 -- subtree since all the information has already been
4003 -- Case of either a stand alone allocator or a rewritten allocator
4004 -- with an aggregate.
4007 if Present
(Original_Node
(Nod
)) then
4008 Orig_Nod
:= Original_Node
(Nod
);
4011 if Nkind
(Orig_Nod
) = N_Allocator
then
4013 -- Propagate the list of nested coextensions to the Root
4014 -- allocator. This is done through list copy since a single
4015 -- allocator may have multiple coextensions. Do not touch
4016 -- coextensions roots.
4018 if not Is_Coextension_Root
(Orig_Nod
)
4019 and then Present
(Coextensions
(Orig_Nod
))
4021 if No
(Coextensions
(Root
)) then
4022 Set_Coextensions
(Root
, New_Elmt_List
);
4026 (From
=> Coextensions
(Orig_Nod
),
4027 To
=> Coextensions
(Root
));
4030 -- There is no need to continue the traversal of this
4031 -- subtree since all the information has already been
4038 -- Keep on traversing, looking for the next allocator
4041 end Process_Allocator
;
4043 procedure Process_Allocators
is
4044 new Traverse_Proc
(Process_Allocator
);
4046 -- Start of processing for Propagate_Coextensions
4049 Process_Allocators
(Expression
(Root
));
4050 end Propagate_Coextensions
;
4052 -- Start of processing for Resolve_Allocator
4055 -- Replace general access with specific type
4057 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
4058 Set_Etype
(N
, Base_Type
(Typ
));
4061 if Is_Abstract_Type
(Typ
) then
4062 Error_Msg_N
("type of allocator cannot be abstract", N
);
4065 -- For qualified expression, resolve the expression using the
4066 -- given subtype (nothing to do for type mark, subtype indication)
4068 if Nkind
(E
) = N_Qualified_Expression
then
4069 if Is_Class_Wide_Type
(Etype
(E
))
4070 and then not Is_Class_Wide_Type
(Designated_Type
(Typ
))
4071 and then not In_Dispatching_Context
4074 ("class-wide allocator not allowed for this access type", N
);
4077 Resolve
(Expression
(E
), Etype
(E
));
4078 Check_Unset_Reference
(Expression
(E
));
4080 -- A qualified expression requires an exact match of the type,
4081 -- class-wide matching is not allowed.
4083 if (Is_Class_Wide_Type
(Etype
(Expression
(E
)))
4084 or else Is_Class_Wide_Type
(Etype
(E
)))
4085 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Etype
(E
))
4087 Wrong_Type
(Expression
(E
), Etype
(E
));
4090 -- A special accessibility check is needed for allocators that
4091 -- constrain access discriminants. The level of the type of the
4092 -- expression used to constrain an access discriminant cannot be
4093 -- deeper than the type of the allocator (in contrast to access
4094 -- parameters, where the level of the actual can be arbitrary).
4096 -- We can't use Valid_Conversion to perform this check because
4097 -- in general the type of the allocator is unrelated to the type
4098 -- of the access discriminant.
4100 if Ekind
(Typ
) /= E_Anonymous_Access_Type
4101 or else Is_Local_Anonymous_Access
(Typ
)
4103 Subtyp
:= Entity
(Subtype_Mark
(E
));
4105 Aggr
:= Original_Node
(Expression
(E
));
4107 if Has_Discriminants
(Subtyp
)
4108 and then Nkind_In
(Aggr
, N_Aggregate
, N_Extension_Aggregate
)
4110 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
4112 -- Get the first component expression of the aggregate
4114 if Present
(Expressions
(Aggr
)) then
4115 Disc_Exp
:= First
(Expressions
(Aggr
));
4117 elsif Present
(Component_Associations
(Aggr
)) then
4118 Assoc
:= First
(Component_Associations
(Aggr
));
4120 if Present
(Assoc
) then
4121 Disc_Exp
:= Expression
(Assoc
);
4130 while Present
(Discrim
) and then Present
(Disc_Exp
) loop
4131 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
4132 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
4135 Next_Discriminant
(Discrim
);
4137 if Present
(Discrim
) then
4138 if Present
(Assoc
) then
4140 Disc_Exp
:= Expression
(Assoc
);
4142 elsif Present
(Next
(Disc_Exp
)) then
4146 Assoc
:= First
(Component_Associations
(Aggr
));
4148 if Present
(Assoc
) then
4149 Disc_Exp
:= Expression
(Assoc
);
4159 -- For a subtype mark or subtype indication, freeze the subtype
4162 Freeze_Expression
(E
);
4164 if Is_Access_Constant
(Typ
) and then not No_Initialization
(N
) then
4166 ("initialization required for access-to-constant allocator", N
);
4169 -- A special accessibility check is needed for allocators that
4170 -- constrain access discriminants. The level of the type of the
4171 -- expression used to constrain an access discriminant cannot be
4172 -- deeper than the type of the allocator (in contrast to access
4173 -- parameters, where the level of the actual can be arbitrary).
4174 -- We can't use Valid_Conversion to perform this check because
4175 -- in general the type of the allocator is unrelated to the type
4176 -- of the access discriminant.
4178 if Nkind
(Original_Node
(E
)) = N_Subtype_Indication
4179 and then (Ekind
(Typ
) /= E_Anonymous_Access_Type
4180 or else Is_Local_Anonymous_Access
(Typ
))
4182 Subtyp
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
4184 if Has_Discriminants
(Subtyp
) then
4185 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
4186 Constr
:= First
(Constraints
(Constraint
(Original_Node
(E
))));
4187 while Present
(Discrim
) and then Present
(Constr
) loop
4188 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
4189 if Nkind
(Constr
) = N_Discriminant_Association
then
4190 Disc_Exp
:= Original_Node
(Expression
(Constr
));
4192 Disc_Exp
:= Original_Node
(Constr
);
4195 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
4198 Next_Discriminant
(Discrim
);
4205 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4206 -- check that the level of the type of the created object is not deeper
4207 -- than the level of the allocator's access type, since extensions can
4208 -- now occur at deeper levels than their ancestor types. This is a
4209 -- static accessibility level check; a run-time check is also needed in
4210 -- the case of an initialized allocator with a class-wide argument (see
4211 -- Expand_Allocator_Expression).
4213 if Ada_Version
>= Ada_05
4214 and then Is_Class_Wide_Type
(Designated_Type
(Typ
))
4217 Exp_Typ
: Entity_Id
;
4220 if Nkind
(E
) = N_Qualified_Expression
then
4221 Exp_Typ
:= Etype
(E
);
4222 elsif Nkind
(E
) = N_Subtype_Indication
then
4223 Exp_Typ
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
4225 Exp_Typ
:= Entity
(E
);
4228 if Type_Access_Level
(Exp_Typ
) > Type_Access_Level
(Typ
) then
4229 if In_Instance_Body
then
4230 Error_Msg_N
("?type in allocator has deeper level than" &
4231 " designated class-wide type", E
);
4232 Error_Msg_N
("\?Program_Error will be raised at run time",
4235 Make_Raise_Program_Error
(Sloc
(N
),
4236 Reason
=> PE_Accessibility_Check_Failed
));
4239 -- Do not apply Ada 2005 accessibility checks on a class-wide
4240 -- allocator if the type given in the allocator is a formal
4241 -- type. A run-time check will be performed in the instance.
4243 elsif not Is_Generic_Type
(Exp_Typ
) then
4244 Error_Msg_N
("type in allocator has deeper level than" &
4245 " designated class-wide type", E
);
4251 -- Check for allocation from an empty storage pool
4253 if No_Pool_Assigned
(Typ
) then
4255 Loc
: constant Source_Ptr
:= Sloc
(N
);
4257 Error_Msg_N
("?allocation from empty storage pool!", N
);
4258 Error_Msg_N
("\?Storage_Error will be raised at run time!", N
);
4260 Make_Raise_Storage_Error
(Loc
,
4261 Reason
=> SE_Empty_Storage_Pool
));
4264 -- If the context is an unchecked conversion, as may happen within
4265 -- an inlined subprogram, the allocator is being resolved with its
4266 -- own anonymous type. In that case, if the target type has a specific
4267 -- storage pool, it must be inherited explicitly by the allocator type.
4269 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
4270 and then No
(Associated_Storage_Pool
(Typ
))
4272 Set_Associated_Storage_Pool
4273 (Typ
, Associated_Storage_Pool
(Etype
(Parent
(N
))));
4276 -- An erroneous allocator may be rewritten as a raise Program_Error
4279 if Nkind
(N
) = N_Allocator
then
4281 -- An anonymous access discriminant is the definition of a
4284 if Ekind
(Typ
) = E_Anonymous_Access_Type
4285 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
4286 N_Discriminant_Specification
4288 -- Avoid marking an allocator as a dynamic coextension if it is
4289 -- within a static construct.
4291 if not Is_Static_Coextension
(N
) then
4292 Set_Is_Dynamic_Coextension
(N
);
4295 -- Cleanup for potential static coextensions
4298 Set_Is_Dynamic_Coextension
(N
, False);
4299 Set_Is_Static_Coextension
(N
, False);
4302 -- There is no need to propagate any nested coextensions if they
4303 -- are marked as static since they will be rewritten on the spot.
4305 if not Is_Static_Coextension
(N
) then
4306 Propagate_Coextensions
(N
);
4309 end Resolve_Allocator
;
4311 ---------------------------
4312 -- Resolve_Arithmetic_Op --
4313 ---------------------------
4315 -- Used for resolving all arithmetic operators except exponentiation
4317 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
4318 L
: constant Node_Id
:= Left_Opnd
(N
);
4319 R
: constant Node_Id
:= Right_Opnd
(N
);
4320 TL
: constant Entity_Id
:= Base_Type
(Etype
(L
));
4321 TR
: constant Entity_Id
:= Base_Type
(Etype
(R
));
4325 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
4326 -- We do the resolution using the base type, because intermediate values
4327 -- in expressions always are of the base type, not a subtype of it.
4329 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean;
4330 -- Returns True if N is in a context that expects "any real type"
4332 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean;
4333 -- Return True iff given type is Integer or universal real/integer
4335 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
);
4336 -- Choose type of integer literal in fixed-point operation to conform
4337 -- to available fixed-point type. T is the type of the other operand,
4338 -- which is needed to determine the expected type of N.
4340 procedure Set_Operand_Type
(N
: Node_Id
);
4341 -- Set operand type to T if universal
4343 -------------------------------
4344 -- Expected_Type_Is_Any_Real --
4345 -------------------------------
4347 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean is
4349 -- N is the expression after "delta" in a fixed_point_definition;
4352 return Nkind_In
(Parent
(N
), N_Ordinary_Fixed_Point_Definition
,
4353 N_Decimal_Fixed_Point_Definition
,
4355 -- N is one of the bounds in a real_range_specification;
4358 N_Real_Range_Specification
,
4360 -- N is the expression of a delta_constraint;
4363 N_Delta_Constraint
);
4364 end Expected_Type_Is_Any_Real
;
4366 -----------------------------
4367 -- Is_Integer_Or_Universal --
4368 -----------------------------
4370 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean is
4372 Index
: Interp_Index
;
4376 if not Is_Overloaded
(N
) then
4378 return Base_Type
(T
) = Base_Type
(Standard_Integer
)
4379 or else T
= Universal_Integer
4380 or else T
= Universal_Real
;
4382 Get_First_Interp
(N
, Index
, It
);
4383 while Present
(It
.Typ
) loop
4384 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
)
4385 or else It
.Typ
= Universal_Integer
4386 or else It
.Typ
= Universal_Real
4391 Get_Next_Interp
(Index
, It
);
4396 end Is_Integer_Or_Universal
;
4398 ----------------------------
4399 -- Set_Mixed_Mode_Operand --
4400 ----------------------------
4402 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
) is
4403 Index
: Interp_Index
;
4407 if Universal_Interpretation
(N
) = Universal_Integer
then
4409 -- A universal integer literal is resolved as standard integer
4410 -- except in the case of a fixed-point result, where we leave it
4411 -- as universal (to be handled by Exp_Fixd later on)
4413 if Is_Fixed_Point_Type
(T
) then
4414 Resolve
(N
, Universal_Integer
);
4416 Resolve
(N
, Standard_Integer
);
4419 elsif Universal_Interpretation
(N
) = Universal_Real
4420 and then (T
= Base_Type
(Standard_Integer
)
4421 or else T
= Universal_Integer
4422 or else T
= Universal_Real
)
4424 -- A universal real can appear in a fixed-type context. We resolve
4425 -- the literal with that context, even though this might raise an
4426 -- exception prematurely (the other operand may be zero).
4430 elsif Etype
(N
) = Base_Type
(Standard_Integer
)
4431 and then T
= Universal_Real
4432 and then Is_Overloaded
(N
)
4434 -- Integer arg in mixed-mode operation. Resolve with universal
4435 -- type, in case preference rule must be applied.
4437 Resolve
(N
, Universal_Integer
);
4440 and then B_Typ
/= Universal_Fixed
4442 -- Not a mixed-mode operation, resolve with context
4446 elsif Etype
(N
) = Any_Fixed
then
4448 -- N may itself be a mixed-mode operation, so use context type
4452 elsif Is_Fixed_Point_Type
(T
)
4453 and then B_Typ
= Universal_Fixed
4454 and then Is_Overloaded
(N
)
4456 -- Must be (fixed * fixed) operation, operand must have one
4457 -- compatible interpretation.
4459 Resolve
(N
, Any_Fixed
);
4461 elsif Is_Fixed_Point_Type
(B_Typ
)
4462 and then (T
= Universal_Real
4463 or else Is_Fixed_Point_Type
(T
))
4464 and then Is_Overloaded
(N
)
4466 -- C * F(X) in a fixed context, where C is a real literal or a
4467 -- fixed-point expression. F must have either a fixed type
4468 -- interpretation or an integer interpretation, but not both.
4470 Get_First_Interp
(N
, Index
, It
);
4471 while Present
(It
.Typ
) loop
4472 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
) then
4474 if Analyzed
(N
) then
4475 Error_Msg_N
("ambiguous operand in fixed operation", N
);
4477 Resolve
(N
, Standard_Integer
);
4480 elsif Is_Fixed_Point_Type
(It
.Typ
) then
4482 if Analyzed
(N
) then
4483 Error_Msg_N
("ambiguous operand in fixed operation", N
);
4485 Resolve
(N
, It
.Typ
);
4489 Get_Next_Interp
(Index
, It
);
4492 -- Reanalyze the literal with the fixed type of the context. If
4493 -- context is Universal_Fixed, we are within a conversion, leave
4494 -- the literal as a universal real because there is no usable
4495 -- fixed type, and the target of the conversion plays no role in
4509 if B_Typ
= Universal_Fixed
4510 and then Nkind
(Op2
) = N_Real_Literal
4512 T2
:= Universal_Real
;
4517 Set_Analyzed
(Op2
, False);
4524 end Set_Mixed_Mode_Operand
;
4526 ----------------------
4527 -- Set_Operand_Type --
4528 ----------------------
4530 procedure Set_Operand_Type
(N
: Node_Id
) is
4532 if Etype
(N
) = Universal_Integer
4533 or else Etype
(N
) = Universal_Real
4537 end Set_Operand_Type
;
4539 -- Start of processing for Resolve_Arithmetic_Op
4542 if Comes_From_Source
(N
)
4543 and then Ekind
(Entity
(N
)) = E_Function
4544 and then Is_Imported
(Entity
(N
))
4545 and then Is_Intrinsic_Subprogram
(Entity
(N
))
4547 Resolve_Intrinsic_Operator
(N
, Typ
);
4550 -- Special-case for mixed-mode universal expressions or fixed point
4551 -- type operation: each argument is resolved separately. The same
4552 -- treatment is required if one of the operands of a fixed point
4553 -- operation is universal real, since in this case we don't do a
4554 -- conversion to a specific fixed-point type (instead the expander
4555 -- takes care of the case).
4557 elsif (B_Typ
= Universal_Integer
or else B_Typ
= Universal_Real
)
4558 and then Present
(Universal_Interpretation
(L
))
4559 and then Present
(Universal_Interpretation
(R
))
4561 Resolve
(L
, Universal_Interpretation
(L
));
4562 Resolve
(R
, Universal_Interpretation
(R
));
4563 Set_Etype
(N
, B_Typ
);
4565 elsif (B_Typ
= Universal_Real
4566 or else Etype
(N
) = Universal_Fixed
4567 or else (Etype
(N
) = Any_Fixed
4568 and then Is_Fixed_Point_Type
(B_Typ
))
4569 or else (Is_Fixed_Point_Type
(B_Typ
)
4570 and then (Is_Integer_Or_Universal
(L
)
4572 Is_Integer_Or_Universal
(R
))))
4573 and then Nkind_In
(N
, N_Op_Multiply
, N_Op_Divide
)
4575 if TL
= Universal_Integer
or else TR
= Universal_Integer
then
4576 Check_For_Visible_Operator
(N
, B_Typ
);
4579 -- If context is a fixed type and one operand is integer, the
4580 -- other is resolved with the type of the context.
4582 if Is_Fixed_Point_Type
(B_Typ
)
4583 and then (Base_Type
(TL
) = Base_Type
(Standard_Integer
)
4584 or else TL
= Universal_Integer
)
4589 elsif Is_Fixed_Point_Type
(B_Typ
)
4590 and then (Base_Type
(TR
) = Base_Type
(Standard_Integer
)
4591 or else TR
= Universal_Integer
)
4597 Set_Mixed_Mode_Operand
(L
, TR
);
4598 Set_Mixed_Mode_Operand
(R
, TL
);
4601 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4602 -- multiplying operators from being used when the expected type is
4603 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4604 -- some cases where the expected type is actually Any_Real;
4605 -- Expected_Type_Is_Any_Real takes care of that case.
4607 if Etype
(N
) = Universal_Fixed
4608 or else Etype
(N
) = Any_Fixed
4610 if B_Typ
= Universal_Fixed
4611 and then not Expected_Type_Is_Any_Real
(N
)
4612 and then not Nkind_In
(Parent
(N
), N_Type_Conversion
,
4613 N_Unchecked_Type_Conversion
)
4615 Error_Msg_N
("type cannot be determined from context!", N
);
4616 Error_Msg_N
("\explicit conversion to result type required", N
);
4618 Set_Etype
(L
, Any_Type
);
4619 Set_Etype
(R
, Any_Type
);
4622 if Ada_Version
= Ada_83
4623 and then Etype
(N
) = Universal_Fixed
4625 Nkind_In
(Parent
(N
), N_Type_Conversion
,
4626 N_Unchecked_Type_Conversion
)
4629 ("(Ada 83) fixed-point operation "
4630 & "needs explicit conversion", N
);
4633 -- The expected type is "any real type" in contexts like
4634 -- type T is delta <universal_fixed-expression> ...
4635 -- in which case we need to set the type to Universal_Real
4636 -- so that static expression evaluation will work properly.
4638 if Expected_Type_Is_Any_Real
(N
) then
4639 Set_Etype
(N
, Universal_Real
);
4641 Set_Etype
(N
, B_Typ
);
4645 elsif Is_Fixed_Point_Type
(B_Typ
)
4646 and then (Is_Integer_Or_Universal
(L
)
4647 or else Nkind
(L
) = N_Real_Literal
4648 or else Nkind
(R
) = N_Real_Literal
4649 or else Is_Integer_Or_Universal
(R
))
4651 Set_Etype
(N
, B_Typ
);
4653 elsif Etype
(N
) = Any_Fixed
then
4655 -- If no previous errors, this is only possible if one operand
4656 -- is overloaded and the context is universal. Resolve as such.
4658 Set_Etype
(N
, B_Typ
);
4662 if (TL
= Universal_Integer
or else TL
= Universal_Real
)
4664 (TR
= Universal_Integer
or else TR
= Universal_Real
)
4666 Check_For_Visible_Operator
(N
, B_Typ
);
4669 -- If the context is Universal_Fixed and the operands are also
4670 -- universal fixed, this is an error, unless there is only one
4671 -- applicable fixed_point type (usually Duration).
4673 if B_Typ
= Universal_Fixed
and then Etype
(L
) = Universal_Fixed
then
4674 T
:= Unique_Fixed_Point_Type
(N
);
4676 if T
= Any_Type
then
4689 -- If one of the arguments was resolved to a non-universal type.
4690 -- label the result of the operation itself with the same type.
4691 -- Do the same for the universal argument, if any.
4693 T
:= Intersect_Types
(L
, R
);
4694 Set_Etype
(N
, Base_Type
(T
));
4695 Set_Operand_Type
(L
);
4696 Set_Operand_Type
(R
);
4699 Generate_Operator_Reference
(N
, Typ
);
4700 Eval_Arithmetic_Op
(N
);
4702 -- Set overflow and division checking bit. Much cleverer code needed
4703 -- here eventually and perhaps the Resolve routines should be separated
4704 -- for the various arithmetic operations, since they will need
4705 -- different processing. ???
4707 if Nkind
(N
) in N_Op
then
4708 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
4709 Enable_Overflow_Check
(N
);
4712 -- Give warning if explicit division by zero
4714 if Nkind_In
(N
, N_Op_Divide
, N_Op_Rem
, N_Op_Mod
)
4715 and then not Division_Checks_Suppressed
(Etype
(N
))
4717 Rop
:= Right_Opnd
(N
);
4719 if Compile_Time_Known_Value
(Rop
)
4720 and then ((Is_Integer_Type
(Etype
(Rop
))
4721 and then Expr_Value
(Rop
) = Uint_0
)
4723 (Is_Real_Type
(Etype
(Rop
))
4724 and then Expr_Value_R
(Rop
) = Ureal_0
))
4726 -- Specialize the warning message according to the operation
4730 Apply_Compile_Time_Constraint_Error
4731 (N
, "division by zero?", CE_Divide_By_Zero
,
4732 Loc
=> Sloc
(Right_Opnd
(N
)));
4735 Apply_Compile_Time_Constraint_Error
4736 (N
, "rem with zero divisor?", CE_Divide_By_Zero
,
4737 Loc
=> Sloc
(Right_Opnd
(N
)));
4740 Apply_Compile_Time_Constraint_Error
4741 (N
, "mod with zero divisor?", CE_Divide_By_Zero
,
4742 Loc
=> Sloc
(Right_Opnd
(N
)));
4744 -- Division by zero can only happen with division, rem,
4745 -- and mod operations.
4748 raise Program_Error
;
4751 -- Otherwise just set the flag to check at run time
4754 Activate_Division_Check
(N
);
4758 -- If Restriction No_Implicit_Conditionals is active, then it is
4759 -- violated if either operand can be negative for mod, or for rem
4760 -- if both operands can be negative.
4762 if Restrictions
.Set
(No_Implicit_Conditionals
)
4763 and then Nkind_In
(N
, N_Op_Rem
, N_Op_Mod
)
4772 -- Set if corresponding operand might be negative
4776 (Left_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
4777 LNeg
:= (not OK
) or else Lo
< 0;
4780 (Right_Opnd
(N
), OK
, Lo
, Hi
, Assume_Valid
=> True);
4781 RNeg
:= (not OK
) or else Lo
< 0;
4783 -- Check if we will be generating conditionals. There are two
4784 -- cases where that can happen, first for REM, the only case
4785 -- is largest negative integer mod -1, where the division can
4786 -- overflow, but we still have to give the right result. The
4787 -- front end generates a test for this annoying case. Here we
4788 -- just test if both operands can be negative (that's what the
4789 -- expander does, so we match its logic here).
4791 -- The second case is mod where either operand can be negative.
4792 -- In this case, the back end has to generate additonal tests.
4794 if (Nkind
(N
) = N_Op_Rem
and then (LNeg
and RNeg
))
4796 (Nkind
(N
) = N_Op_Mod
and then (LNeg
or RNeg
))
4798 Check_Restriction
(No_Implicit_Conditionals
, N
);
4804 Check_Unset_Reference
(L
);
4805 Check_Unset_Reference
(R
);
4806 end Resolve_Arithmetic_Op
;
4812 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
4813 Loc
: constant Source_Ptr
:= Sloc
(N
);
4814 Subp
: constant Node_Id
:= Name
(N
);
4822 function Same_Or_Aliased_Subprograms
4824 E
: Entity_Id
) return Boolean;
4825 -- Returns True if the subprogram entity S is the same as E or else
4826 -- S is an alias of E.
4828 ---------------------------------
4829 -- Same_Or_Aliased_Subprograms --
4830 ---------------------------------
4832 function Same_Or_Aliased_Subprograms
4834 E
: Entity_Id
) return Boolean
4836 Subp_Alias
: constant Entity_Id
:= Alias
(S
);
4839 or else (Present
(Subp_Alias
) and then Subp_Alias
= E
);
4840 end Same_Or_Aliased_Subprograms
;
4842 -- Start of processing for Resolve_Call
4845 -- The context imposes a unique interpretation with type Typ on a
4846 -- procedure or function call. Find the entity of the subprogram that
4847 -- yields the expected type, and propagate the corresponding formal
4848 -- constraints on the actuals. The caller has established that an
4849 -- interpretation exists, and emitted an error if not unique.
4851 -- First deal with the case of a call to an access-to-subprogram,
4852 -- dereference made explicit in Analyze_Call.
4854 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
4855 if not Is_Overloaded
(Subp
) then
4856 Nam
:= Etype
(Subp
);
4859 -- Find the interpretation whose type (a subprogram type) has a
4860 -- return type that is compatible with the context. Analysis of
4861 -- the node has established that one exists.
4865 Get_First_Interp
(Subp
, I
, It
);
4866 while Present
(It
.Typ
) loop
4867 if Covers
(Typ
, Etype
(It
.Typ
)) then
4872 Get_Next_Interp
(I
, It
);
4876 raise Program_Error
;
4880 -- If the prefix is not an entity, then resolve it
4882 if not Is_Entity_Name
(Subp
) then
4883 Resolve
(Subp
, Nam
);
4886 -- For an indirect call, we always invalidate checks, since we do not
4887 -- know whether the subprogram is local or global. Yes we could do
4888 -- better here, e.g. by knowing that there are no local subprograms,
4889 -- but it does not seem worth the effort. Similarly, we kill all
4890 -- knowledge of current constant values.
4892 Kill_Current_Values
;
4894 -- If this is a procedure call which is really an entry call, do
4895 -- the conversion of the procedure call to an entry call. Protected
4896 -- operations use the same circuitry because the name in the call
4897 -- can be an arbitrary expression with special resolution rules.
4899 elsif Nkind_In
(Subp
, N_Selected_Component
, N_Indexed_Component
)
4900 or else (Is_Entity_Name
(Subp
)
4901 and then Ekind
(Entity
(Subp
)) = E_Entry
)
4903 Resolve_Entry_Call
(N
, Typ
);
4904 Check_Elab_Call
(N
);
4906 -- Kill checks and constant values, as above for indirect case
4907 -- Who knows what happens when another task is activated?
4909 Kill_Current_Values
;
4912 -- Normal subprogram call with name established in Resolve
4914 elsif not (Is_Type
(Entity
(Subp
))) then
4915 Nam
:= Entity
(Subp
);
4916 Set_Entity_With_Style_Check
(Subp
, Nam
);
4918 -- Otherwise we must have the case of an overloaded call
4921 pragma Assert
(Is_Overloaded
(Subp
));
4923 -- Initialize Nam to prevent warning (we know it will be assigned
4924 -- in the loop below, but the compiler does not know that).
4928 Get_First_Interp
(Subp
, I
, It
);
4929 while Present
(It
.Typ
) loop
4930 if Covers
(Typ
, It
.Typ
) then
4932 Set_Entity_With_Style_Check
(Subp
, Nam
);
4936 Get_Next_Interp
(I
, It
);
4940 if Is_Access_Subprogram_Type
(Base_Type
(Etype
(Nam
)))
4941 and then not Is_Access_Subprogram_Type
(Base_Type
(Typ
))
4942 and then Nkind
(Subp
) /= N_Explicit_Dereference
4943 and then Present
(Parameter_Associations
(N
))
4945 -- The prefix is a parameterless function call that returns an access
4946 -- to subprogram. If parameters are present in the current call, add
4947 -- add an explicit dereference. We use the base type here because
4948 -- within an instance these may be subtypes.
4950 -- The dereference is added either in Analyze_Call or here. Should
4951 -- be consolidated ???
4953 Set_Is_Overloaded
(Subp
, False);
4954 Set_Etype
(Subp
, Etype
(Nam
));
4955 Insert_Explicit_Dereference
(Subp
);
4956 Nam
:= Designated_Type
(Etype
(Nam
));
4957 Resolve
(Subp
, Nam
);
4960 -- Check that a call to Current_Task does not occur in an entry body
4962 if Is_RTE
(Nam
, RE_Current_Task
) then
4971 -- Exclude calls that occur within the default of a formal
4972 -- parameter of the entry, since those are evaluated outside
4975 exit when No
(P
) or else Nkind
(P
) = N_Parameter_Specification
;
4977 if Nkind
(P
) = N_Entry_Body
4978 or else (Nkind
(P
) = N_Subprogram_Body
4979 and then Is_Entry_Barrier_Function
(P
))
4983 ("?& should not be used in entry body (RM C.7(17))",
4986 ("\Program_Error will be raised at run time?", N
, Nam
);
4988 Make_Raise_Program_Error
(Loc
,
4989 Reason
=> PE_Current_Task_In_Entry_Body
));
4990 Set_Etype
(N
, Rtype
);
4997 -- Check that a procedure call does not occur in the context of the
4998 -- entry call statement of a conditional or timed entry call. Note that
4999 -- the case of a call to a subprogram renaming of an entry will also be
5000 -- rejected. The test for N not being an N_Entry_Call_Statement is
5001 -- defensive, covering the possibility that the processing of entry
5002 -- calls might reach this point due to later modifications of the code
5005 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
5006 and then Nkind
(N
) /= N_Entry_Call_Statement
5007 and then Entry_Call_Statement
(Parent
(N
)) = N
5009 if Ada_Version
< Ada_05
then
5010 Error_Msg_N
("entry call required in select statement", N
);
5012 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5013 -- for a procedure_or_entry_call, the procedure_name or
5014 -- procedure_prefix of the procedure_call_statement shall denote
5015 -- an entry renamed by a procedure, or (a view of) a primitive
5016 -- subprogram of a limited interface whose first parameter is
5017 -- a controlling parameter.
5019 elsif Nkind
(N
) = N_Procedure_Call_Statement
5020 and then not Is_Renamed_Entry
(Nam
)
5021 and then not Is_Controlling_Limited_Procedure
(Nam
)
5024 ("entry call or dispatching primitive of interface required", N
);
5028 -- Check that this is not a call to a protected procedure or entry from
5029 -- within a protected function.
5031 if Ekind
(Current_Scope
) = E_Function
5032 and then Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
5033 and then Ekind
(Nam
) /= E_Function
5034 and then Scope
(Nam
) = Scope
(Current_Scope
)
5036 Error_Msg_N
("within protected function, protected " &
5037 "object is constant", N
);
5038 Error_Msg_N
("\cannot call operation that may modify it", N
);
5041 -- Freeze the subprogram name if not in a spec-expression. Note that we
5042 -- freeze procedure calls as well as function calls. Procedure calls are
5043 -- not frozen according to the rules (RM 13.14(14)) because it is
5044 -- impossible to have a procedure call to a non-frozen procedure in pure
5045 -- Ada, but in the code that we generate in the expander, this rule
5046 -- needs extending because we can generate procedure calls that need
5049 if Is_Entity_Name
(Subp
) and then not In_Spec_Expression
then
5050 Freeze_Expression
(Subp
);
5053 -- For a predefined operator, the type of the result is the type imposed
5054 -- by context, except for a predefined operation on universal fixed.
5055 -- Otherwise The type of the call is the type returned by the subprogram
5058 if Is_Predefined_Op
(Nam
) then
5059 if Etype
(N
) /= Universal_Fixed
then
5063 -- If the subprogram returns an array type, and the context requires the
5064 -- component type of that array type, the node is really an indexing of
5065 -- the parameterless call. Resolve as such. A pathological case occurs
5066 -- when the type of the component is an access to the array type. In
5067 -- this case the call is truly ambiguous.
5069 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
5071 ((Is_Array_Type
(Etype
(Nam
))
5072 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
5073 or else (Is_Access_Type
(Etype
(Nam
))
5074 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
5077 Component_Type
(Designated_Type
(Etype
(Nam
))))))
5080 Index_Node
: Node_Id
;
5082 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
5085 if Is_Access_Type
(Ret_Type
)
5086 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
5089 ("cannot disambiguate function call and indexing", N
);
5091 New_Subp
:= Relocate_Node
(Subp
);
5092 Set_Entity
(Subp
, Nam
);
5094 if (Is_Array_Type
(Ret_Type
)
5095 and then Component_Type
(Ret_Type
) /= Any_Type
)
5097 (Is_Access_Type
(Ret_Type
)
5099 Component_Type
(Designated_Type
(Ret_Type
)) /= Any_Type
)
5101 if Needs_No_Actuals
(Nam
) then
5103 -- Indexed call to a parameterless function
5106 Make_Indexed_Component
(Loc
,
5108 Make_Function_Call
(Loc
,
5110 Expressions
=> Parameter_Associations
(N
));
5112 -- An Ada 2005 prefixed call to a primitive operation
5113 -- whose first parameter is the prefix. This prefix was
5114 -- prepended to the parameter list, which is actually a
5115 -- list of indices. Remove the prefix in order to build
5116 -- the proper indexed component.
5119 Make_Indexed_Component
(Loc
,
5121 Make_Function_Call
(Loc
,
5123 Parameter_Associations
=>
5125 (Remove_Head
(Parameter_Associations
(N
)))),
5126 Expressions
=> Parameter_Associations
(N
));
5129 -- Preserve the parenthesis count of the node
5131 Set_Paren_Count
(Index_Node
, Paren_Count
(N
));
5133 -- Since we are correcting a node classification error made
5134 -- by the parser, we call Replace rather than Rewrite.
5136 Replace
(N
, Index_Node
);
5138 Set_Etype
(Prefix
(N
), Ret_Type
);
5140 Resolve_Indexed_Component
(N
, Typ
);
5141 Check_Elab_Call
(Prefix
(N
));
5149 Set_Etype
(N
, Etype
(Nam
));
5152 -- In the case where the call is to an overloaded subprogram, Analyze
5153 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5154 -- such a case Normalize_Actuals needs to be called once more to order
5155 -- the actuals correctly. Otherwise the call will have the ordering
5156 -- given by the last overloaded subprogram whether this is the correct
5157 -- one being called or not.
5159 if Is_Overloaded
(Subp
) then
5160 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
5161 pragma Assert
(Norm_OK
);
5164 -- In any case, call is fully resolved now. Reset Overload flag, to
5165 -- prevent subsequent overload resolution if node is analyzed again
5167 Set_Is_Overloaded
(Subp
, False);
5168 Set_Is_Overloaded
(N
, False);
5170 -- If we are calling the current subprogram from immediately within its
5171 -- body, then that is the case where we can sometimes detect cases of
5172 -- infinite recursion statically. Do not try this in case restriction
5173 -- No_Recursion is in effect anyway, and do it only for source calls.
5175 if Comes_From_Source
(N
) then
5176 Scop
:= Current_Scope
;
5178 -- Issue warning for possible infinite recursion in the absence
5179 -- of the No_Recursion restriction.
5181 if Same_Or_Aliased_Subprograms
(Nam
, Scop
)
5182 and then not Restriction_Active
(No_Recursion
)
5183 and then Check_Infinite_Recursion
(N
)
5185 -- Here we detected and flagged an infinite recursion, so we do
5186 -- not need to test the case below for further warnings. Also if
5187 -- we now have a raise SE node, we are all done.
5189 if Nkind
(N
) = N_Raise_Storage_Error
then
5193 -- If call is to immediately containing subprogram, then check for
5194 -- the case of a possible run-time detectable infinite recursion.
5197 Scope_Loop
: while Scop
/= Standard_Standard
loop
5198 if Same_Or_Aliased_Subprograms
(Nam
, Scop
) then
5200 -- Although in general case, recursion is not statically
5201 -- checkable, the case of calling an immediately containing
5202 -- subprogram is easy to catch.
5204 Check_Restriction
(No_Recursion
, N
);
5206 -- If the recursive call is to a parameterless subprogram,
5207 -- then even if we can't statically detect infinite
5208 -- recursion, this is pretty suspicious, and we output a
5209 -- warning. Furthermore, we will try later to detect some
5210 -- cases here at run time by expanding checking code (see
5211 -- Detect_Infinite_Recursion in package Exp_Ch6).
5213 -- If the recursive call is within a handler, do not emit a
5214 -- warning, because this is a common idiom: loop until input
5215 -- is correct, catch illegal input in handler and restart.
5217 if No
(First_Formal
(Nam
))
5218 and then Etype
(Nam
) = Standard_Void_Type
5219 and then not Error_Posted
(N
)
5220 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
5222 -- For the case of a procedure call. We give the message
5223 -- only if the call is the first statement in a sequence
5224 -- of statements, or if all previous statements are
5225 -- simple assignments. This is simply a heuristic to
5226 -- decrease false positives, without losing too many good
5227 -- warnings. The idea is that these previous statements
5228 -- may affect global variables the procedure depends on.
5230 if Nkind
(N
) = N_Procedure_Call_Statement
5231 and then Is_List_Member
(N
)
5237 while Present
(P
) loop
5238 if Nkind
(P
) /= N_Assignment_Statement
then
5247 -- Do not give warning if we are in a conditional context
5250 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
5252 if (K
= N_Loop_Statement
5253 and then Present
(Iteration_Scheme
(Parent
(N
))))
5254 or else K
= N_If_Statement
5255 or else K
= N_Elsif_Part
5256 or else K
= N_Case_Statement_Alternative
5262 -- Here warning is to be issued
5264 Set_Has_Recursive_Call
(Nam
);
5266 ("?possible infinite recursion!", N
);
5268 ("\?Storage_Error may be raised at run time!", N
);
5274 Scop
:= Scope
(Scop
);
5275 end loop Scope_Loop
;
5279 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5281 Check_Obsolescent_2005_Entity
(Nam
, Subp
);
5283 -- If subprogram name is a predefined operator, it was given in
5284 -- functional notation. Replace call node with operator node, so
5285 -- that actuals can be resolved appropriately.
5287 if Is_Predefined_Op
(Nam
) or else Ekind
(Nam
) = E_Operator
then
5288 Make_Call_Into_Operator
(N
, Typ
, Entity
(Name
(N
)));
5291 elsif Present
(Alias
(Nam
))
5292 and then Is_Predefined_Op
(Alias
(Nam
))
5294 Resolve_Actuals
(N
, Nam
);
5295 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
5299 -- Create a transient scope if the resulting type requires it
5301 -- There are several notable exceptions:
5303 -- a) In init procs, the transient scope overhead is not needed, and is
5304 -- even incorrect when the call is a nested initialization call for a
5305 -- component whose expansion may generate adjust calls. However, if the
5306 -- call is some other procedure call within an initialization procedure
5307 -- (for example a call to Create_Task in the init_proc of the task
5308 -- run-time record) a transient scope must be created around this call.
5310 -- b) Enumeration literal pseudo-calls need no transient scope
5312 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5313 -- functions) do not use the secondary stack even though the return
5314 -- type may be unconstrained.
5316 -- d) Calls to a build-in-place function, since such functions may
5317 -- allocate their result directly in a target object, and cases where
5318 -- the result does get allocated in the secondary stack are checked for
5319 -- within the specialized Exp_Ch6 procedures for expanding those
5320 -- build-in-place calls.
5322 -- e) If the subprogram is marked Inline_Always, then even if it returns
5323 -- an unconstrained type the call does not require use of the secondary
5324 -- stack. However, inlining will only take place if the body to inline
5325 -- is already present. It may not be available if e.g. the subprogram is
5326 -- declared in a child instance.
5328 -- If this is an initialization call for a type whose construction
5329 -- uses the secondary stack, and it is not a nested call to initialize
5330 -- a component, we do need to create a transient scope for it. We
5331 -- check for this by traversing the type in Check_Initialization_Call.
5334 and then Has_Pragma_Inline_Always
(Nam
)
5335 and then Nkind
(Unit_Declaration_Node
(Nam
)) = N_Subprogram_Declaration
5336 and then Present
(Body_To_Inline
(Unit_Declaration_Node
(Nam
)))
5340 elsif Ekind
(Nam
) = E_Enumeration_Literal
5341 or else Is_Build_In_Place_Function
(Nam
)
5342 or else Is_Intrinsic_Subprogram
(Nam
)
5346 elsif Expander_Active
5347 and then Is_Type
(Etype
(Nam
))
5348 and then Requires_Transient_Scope
(Etype
(Nam
))
5350 (not Within_Init_Proc
5352 (not Is_Init_Proc
(Nam
) and then Ekind
(Nam
) /= E_Function
))
5354 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
5356 -- If the call appears within the bounds of a loop, it will
5357 -- be rewritten and reanalyzed, nothing left to do here.
5359 if Nkind
(N
) /= N_Function_Call
then
5363 elsif Is_Init_Proc
(Nam
)
5364 and then not Within_Init_Proc
5366 Check_Initialization_Call
(N
, Nam
);
5369 -- A protected function cannot be called within the definition of the
5370 -- enclosing protected type.
5372 if Is_Protected_Type
(Scope
(Nam
))
5373 and then In_Open_Scopes
(Scope
(Nam
))
5374 and then not Has_Completion
(Scope
(Nam
))
5377 ("& cannot be called before end of protected definition", N
, Nam
);
5380 -- Propagate interpretation to actuals, and add default expressions
5383 if Present
(First_Formal
(Nam
)) then
5384 Resolve_Actuals
(N
, Nam
);
5386 -- Overloaded literals are rewritten as function calls, for purpose of
5387 -- resolution. After resolution, we can replace the call with the
5390 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
5391 Copy_Node
(Subp
, N
);
5392 Resolve_Entity_Name
(N
, Typ
);
5394 -- Avoid validation, since it is a static function call
5396 Generate_Reference
(Nam
, Subp
);
5400 -- If the subprogram is not global, then kill all saved values and
5401 -- checks. This is a bit conservative, since in many cases we could do
5402 -- better, but it is not worth the effort. Similarly, we kill constant
5403 -- values. However we do not need to do this for internal entities
5404 -- (unless they are inherited user-defined subprograms), since they
5405 -- are not in the business of molesting local values.
5407 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5408 -- kill all checks and values for calls to global subprograms. This
5409 -- takes care of the case where an access to a local subprogram is
5410 -- taken, and could be passed directly or indirectly and then called
5411 -- from almost any context.
5413 -- Note: we do not do this step till after resolving the actuals. That
5414 -- way we still take advantage of the current value information while
5415 -- scanning the actuals.
5417 -- We suppress killing values if we are processing the nodes associated
5418 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5419 -- type kills all the values as part of analyzing the code that
5420 -- initializes the dispatch tables.
5422 if Inside_Freezing_Actions
= 0
5423 and then (not Is_Library_Level_Entity
(Nam
)
5424 or else Suppress_Value_Tracking_On_Call
5425 (Nearest_Dynamic_Scope
(Current_Scope
)))
5426 and then (Comes_From_Source
(Nam
)
5427 or else (Present
(Alias
(Nam
))
5428 and then Comes_From_Source
(Alias
(Nam
))))
5430 Kill_Current_Values
;
5433 -- If we are warning about unread OUT parameters, this is the place to
5434 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5435 -- after the above call to Kill_Current_Values (since that call clears
5436 -- the Last_Assignment field of all local variables).
5438 if (Warn_On_Modified_Unread
or Warn_On_All_Unread_Out_Parameters
)
5439 and then Comes_From_Source
(N
)
5440 and then In_Extended_Main_Source_Unit
(N
)
5447 F
:= First_Formal
(Nam
);
5448 A
:= First_Actual
(N
);
5449 while Present
(F
) and then Present
(A
) loop
5450 if Ekind_In
(F
, E_Out_Parameter
, E_In_Out_Parameter
)
5451 and then Warn_On_Modified_As_Out_Parameter
(F
)
5452 and then Is_Entity_Name
(A
)
5453 and then Present
(Entity
(A
))
5454 and then Comes_From_Source
(N
)
5455 and then Safe_To_Capture_Value
(N
, Entity
(A
))
5457 Set_Last_Assignment
(Entity
(A
), A
);
5466 -- If the subprogram is a primitive operation, check whether or not
5467 -- it is a correct dispatching call.
5469 if Is_Overloadable
(Nam
)
5470 and then Is_Dispatching_Operation
(Nam
)
5472 Check_Dispatching_Call
(N
);
5474 elsif Ekind
(Nam
) /= E_Subprogram_Type
5475 and then Is_Abstract_Subprogram
(Nam
)
5476 and then not In_Instance
5478 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Nam
);
5481 -- If this is a dispatching call, generate the appropriate reference,
5482 -- for better source navigation in GPS.
5484 if Is_Overloadable
(Nam
)
5485 and then Present
(Controlling_Argument
(N
))
5487 Generate_Reference
(Nam
, Subp
, 'R');
5489 -- Normal case, not a dispatching call
5492 Generate_Reference
(Nam
, Subp
);
5495 if Is_Intrinsic_Subprogram
(Nam
) then
5496 Check_Intrinsic_Call
(N
);
5499 -- Check for violation of restriction No_Specific_Termination_Handlers
5500 -- and warn on a potentially blocking call to Abort_Task.
5502 if Is_RTE
(Nam
, RE_Set_Specific_Handler
)
5504 Is_RTE
(Nam
, RE_Specific_Handler
)
5506 Check_Restriction
(No_Specific_Termination_Handlers
, N
);
5508 elsif Is_RTE
(Nam
, RE_Abort_Task
) then
5509 Check_Potentially_Blocking_Operation
(N
);
5512 -- Issue an error for a call to an eliminated subprogram. We skip this
5513 -- in a spec expression, e.g. a call in a default parameter value, since
5514 -- we are not really doing a call at this time. That's important because
5515 -- the spec expression may itself belong to an eliminated subprogram.
5517 if not In_Spec_Expression
then
5518 Check_For_Eliminated_Subprogram
(Subp
, Nam
);
5521 -- All done, evaluate call and deal with elaboration issues
5524 Check_Elab_Call
(N
);
5525 Warn_On_Overlapping_Actuals
(Nam
, N
);
5528 -----------------------------
5529 -- Resolve_Case_Expression --
5530 -----------------------------
5532 procedure Resolve_Case_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
5536 Alt
:= First
(Alternatives
(N
));
5537 while Present
(Alt
) loop
5538 Resolve
(Expression
(Alt
), Typ
);
5543 Eval_Case_Expression
(N
);
5544 end Resolve_Case_Expression
;
5546 -------------------------------
5547 -- Resolve_Character_Literal --
5548 -------------------------------
5550 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
5551 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
5555 -- Verify that the character does belong to the type of the context
5557 Set_Etype
(N
, B_Typ
);
5558 Eval_Character_Literal
(N
);
5560 -- Wide_Wide_Character literals must always be defined, since the set
5561 -- of wide wide character literals is complete, i.e. if a character
5562 -- literal is accepted by the parser, then it is OK for wide wide
5563 -- character (out of range character literals are rejected).
5565 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
5568 -- Always accept character literal for type Any_Character, which
5569 -- occurs in error situations and in comparisons of literals, both
5570 -- of which should accept all literals.
5572 elsif B_Typ
= Any_Character
then
5575 -- For Standard.Character or a type derived from it, check that
5576 -- the literal is in range
5578 elsif Root_Type
(B_Typ
) = Standard_Character
then
5579 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
5583 -- For Standard.Wide_Character or a type derived from it, check
5584 -- that the literal is in range
5586 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
5587 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
5591 -- For Standard.Wide_Wide_Character or a type derived from it, we
5592 -- know the literal is in range, since the parser checked!
5594 elsif Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
5597 -- If the entity is already set, this has already been resolved in a
5598 -- generic context, or comes from expansion. Nothing else to do.
5600 elsif Present
(Entity
(N
)) then
5603 -- Otherwise we have a user defined character type, and we can use the
5604 -- standard visibility mechanisms to locate the referenced entity.
5607 C
:= Current_Entity
(N
);
5608 while Present
(C
) loop
5609 if Etype
(C
) = B_Typ
then
5610 Set_Entity_With_Style_Check
(N
, C
);
5611 Generate_Reference
(C
, N
);
5619 -- If we fall through, then the literal does not match any of the
5620 -- entries of the enumeration type. This isn't just a constraint
5621 -- error situation, it is an illegality (see RM 4.2).
5624 ("character not defined for }", N
, First_Subtype
(B_Typ
));
5625 end Resolve_Character_Literal
;
5627 ---------------------------
5628 -- Resolve_Comparison_Op --
5629 ---------------------------
5631 -- Context requires a boolean type, and plays no role in resolution.
5632 -- Processing identical to that for equality operators. The result
5633 -- type is the base type, which matters when pathological subtypes of
5634 -- booleans with limited ranges are used.
5636 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
5637 L
: constant Node_Id
:= Left_Opnd
(N
);
5638 R
: constant Node_Id
:= Right_Opnd
(N
);
5642 -- If this is an intrinsic operation which is not predefined, use the
5643 -- types of its declared arguments to resolve the possibly overloaded
5644 -- operands. Otherwise the operands are unambiguous and specify the
5647 if Scope
(Entity
(N
)) /= Standard_Standard
then
5648 T
:= Etype
(First_Entity
(Entity
(N
)));
5651 T
:= Find_Unique_Type
(L
, R
);
5653 if T
= Any_Fixed
then
5654 T
:= Unique_Fixed_Point_Type
(L
);
5658 Set_Etype
(N
, Base_Type
(Typ
));
5659 Generate_Reference
(T
, N
, ' ');
5661 if T
/= Any_Type
then
5662 if T
= Any_String
or else
5663 T
= Any_Composite
or else
5666 if T
= Any_Character
then
5667 Ambiguous_Character
(L
);
5669 Error_Msg_N
("ambiguous operands for comparison", N
);
5672 Set_Etype
(N
, Any_Type
);
5678 Check_Unset_Reference
(L
);
5679 Check_Unset_Reference
(R
);
5680 Generate_Operator_Reference
(N
, T
);
5681 Check_Low_Bound_Tested
(N
);
5682 Eval_Relational_Op
(N
);
5685 end Resolve_Comparison_Op
;
5687 ------------------------------------
5688 -- Resolve_Conditional_Expression --
5689 ------------------------------------
5691 procedure Resolve_Conditional_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
5692 Condition
: constant Node_Id
:= First
(Expressions
(N
));
5693 Then_Expr
: constant Node_Id
:= Next
(Condition
);
5694 Else_Expr
: Node_Id
:= Next
(Then_Expr
);
5697 Resolve
(Condition
, Any_Boolean
);
5698 Resolve
(Then_Expr
, Typ
);
5700 -- If ELSE expression present, just resolve using the determined type
5702 if Present
(Else_Expr
) then
5703 Resolve
(Else_Expr
, Typ
);
5705 -- If no ELSE expression is present, root type must be Standard.Boolean
5706 -- and we provide a Standard.True result converted to the appropriate
5707 -- Boolean type (in case it is a derived boolean type).
5709 elsif Root_Type
(Typ
) = Standard_Boolean
then
5711 Convert_To
(Typ
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
5712 Analyze_And_Resolve
(Else_Expr
, Typ
);
5713 Append_To
(Expressions
(N
), Else_Expr
);
5716 Error_Msg_N
("can only omit ELSE expression in Boolean case", N
);
5717 Append_To
(Expressions
(N
), Error
);
5721 Eval_Conditional_Expression
(N
);
5722 end Resolve_Conditional_Expression
;
5724 -----------------------------------------
5725 -- Resolve_Discrete_Subtype_Indication --
5726 -----------------------------------------
5728 procedure Resolve_Discrete_Subtype_Indication
5736 Analyze
(Subtype_Mark
(N
));
5737 S
:= Entity
(Subtype_Mark
(N
));
5739 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
5740 Error_Msg_N
("expect range constraint for discrete type", N
);
5741 Set_Etype
(N
, Any_Type
);
5744 R
:= Range_Expression
(Constraint
(N
));
5752 if Base_Type
(S
) /= Base_Type
(Typ
) then
5754 ("expect subtype of }", N
, First_Subtype
(Typ
));
5756 -- Rewrite the constraint as a range of Typ
5757 -- to allow compilation to proceed further.
5760 Rewrite
(Low_Bound
(R
),
5761 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
5762 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
5763 Attribute_Name
=> Name_First
));
5764 Rewrite
(High_Bound
(R
),
5765 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
5766 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
5767 Attribute_Name
=> Name_First
));
5771 Set_Etype
(N
, Etype
(R
));
5773 -- Additionally, we must check that the bounds are compatible
5774 -- with the given subtype, which might be different from the
5775 -- type of the context.
5777 Apply_Range_Check
(R
, S
);
5779 -- ??? If the above check statically detects a Constraint_Error
5780 -- it replaces the offending bound(s) of the range R with a
5781 -- Constraint_Error node. When the itype which uses these bounds
5782 -- is frozen the resulting call to Duplicate_Subexpr generates
5783 -- a new temporary for the bounds.
5785 -- Unfortunately there are other itypes that are also made depend
5786 -- on these bounds, so when Duplicate_Subexpr is called they get
5787 -- a forward reference to the newly created temporaries and Gigi
5788 -- aborts on such forward references. This is probably sign of a
5789 -- more fundamental problem somewhere else in either the order of
5790 -- itype freezing or the way certain itypes are constructed.
5792 -- To get around this problem we call Remove_Side_Effects right
5793 -- away if either bounds of R are a Constraint_Error.
5796 L
: constant Node_Id
:= Low_Bound
(R
);
5797 H
: constant Node_Id
:= High_Bound
(R
);
5800 if Nkind
(L
) = N_Raise_Constraint_Error
then
5801 Remove_Side_Effects
(L
);
5804 if Nkind
(H
) = N_Raise_Constraint_Error
then
5805 Remove_Side_Effects
(H
);
5809 Check_Unset_Reference
(Low_Bound
(R
));
5810 Check_Unset_Reference
(High_Bound
(R
));
5813 end Resolve_Discrete_Subtype_Indication
;
5815 -------------------------
5816 -- Resolve_Entity_Name --
5817 -------------------------
5819 -- Used to resolve identifiers and expanded names
5821 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
5822 E
: constant Entity_Id
:= Entity
(N
);
5825 -- If garbage from errors, set to Any_Type and return
5827 if No
(E
) and then Total_Errors_Detected
/= 0 then
5828 Set_Etype
(N
, Any_Type
);
5832 -- Replace named numbers by corresponding literals. Note that this is
5833 -- the one case where Resolve_Entity_Name must reset the Etype, since
5834 -- it is currently marked as universal.
5836 if Ekind
(E
) = E_Named_Integer
then
5838 Eval_Named_Integer
(N
);
5840 elsif Ekind
(E
) = E_Named_Real
then
5842 Eval_Named_Real
(N
);
5844 -- For enumeration literals, we need to make sure that a proper style
5845 -- check is done, since such literals are overloaded, and thus we did
5846 -- not do a style check during the first phase of analysis.
5848 elsif Ekind
(E
) = E_Enumeration_Literal
then
5849 Set_Entity_With_Style_Check
(N
, E
);
5850 Eval_Entity_Name
(N
);
5852 -- Allow use of subtype only if it is a concurrent type where we are
5853 -- currently inside the body. This will eventually be expanded into a
5854 -- call to Self (for tasks) or _object (for protected objects). Any
5855 -- other use of a subtype is invalid.
5857 elsif Is_Type
(E
) then
5858 if Is_Concurrent_Type
(E
)
5859 and then In_Open_Scopes
(E
)
5864 ("invalid use of subtype mark in expression or call", N
);
5867 -- Check discriminant use if entity is discriminant in current scope,
5868 -- i.e. discriminant of record or concurrent type currently being
5869 -- analyzed. Uses in corresponding body are unrestricted.
5871 elsif Ekind
(E
) = E_Discriminant
5872 and then Scope
(E
) = Current_Scope
5873 and then not Has_Completion
(Current_Scope
)
5875 Check_Discriminant_Use
(N
);
5877 -- A parameterless generic function cannot appear in a context that
5878 -- requires resolution.
5880 elsif Ekind
(E
) = E_Generic_Function
then
5881 Error_Msg_N
("illegal use of generic function", N
);
5883 elsif Ekind
(E
) = E_Out_Parameter
5884 and then Ada_Version
= Ada_83
5885 and then (Nkind
(Parent
(N
)) in N_Op
5886 or else (Nkind
(Parent
(N
)) = N_Assignment_Statement
5887 and then N
= Expression
(Parent
(N
)))
5888 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
)
5890 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
5892 -- In all other cases, just do the possible static evaluation
5895 -- A deferred constant that appears in an expression must have a
5896 -- completion, unless it has been removed by in-place expansion of
5899 if Ekind
(E
) = E_Constant
5900 and then Comes_From_Source
(E
)
5901 and then No
(Constant_Value
(E
))
5902 and then Is_Frozen
(Etype
(E
))
5903 and then not In_Spec_Expression
5904 and then not Is_Imported
(E
)
5906 if No_Initialization
(Parent
(E
))
5907 or else (Present
(Full_View
(E
))
5908 and then No_Initialization
(Parent
(Full_View
(E
))))
5913 "deferred constant is frozen before completion", N
);
5917 Eval_Entity_Name
(N
);
5919 end Resolve_Entity_Name
;
5925 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
5926 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
5934 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
5935 -- If the bounds of the entry family being called depend on task
5936 -- discriminants, build a new index subtype where a discriminant is
5937 -- replaced with the value of the discriminant of the target task.
5938 -- The target task is the prefix of the entry name in the call.
5940 -----------------------
5941 -- Actual_Index_Type --
5942 -----------------------
5944 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
5945 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
5946 Tsk
: constant Entity_Id
:= Scope
(E
);
5947 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
5948 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
5951 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
5952 -- If the bound is given by a discriminant, replace with a reference
5953 -- to the discriminant of the same name in the target task. If the
5954 -- entry name is the target of a requeue statement and the entry is
5955 -- in the current protected object, the bound to be used is the
5956 -- discriminal of the object (see Apply_Range_Checks for details of
5957 -- the transformation).
5959 -----------------------------
5960 -- Actual_Discriminant_Ref --
5961 -----------------------------
5963 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
5964 Typ
: constant Entity_Id
:= Etype
(Bound
);
5968 Remove_Side_Effects
(Bound
);
5970 if not Is_Entity_Name
(Bound
)
5971 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
5975 elsif Is_Protected_Type
(Tsk
)
5976 and then In_Open_Scopes
(Tsk
)
5977 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
5979 -- Note: here Bound denotes a discriminant of the corresponding
5980 -- record type tskV, whose discriminal is a formal of the
5981 -- init-proc tskVIP. What we want is the body discriminal,
5982 -- which is associated to the discriminant of the original
5983 -- concurrent type tsk.
5985 return New_Occurrence_Of
5986 (Find_Body_Discriminal
(Entity
(Bound
)), Loc
);
5990 Make_Selected_Component
(Loc
,
5991 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
5992 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
5997 end Actual_Discriminant_Ref
;
5999 -- Start of processing for Actual_Index_Type
6002 if not Has_Discriminants
(Tsk
)
6003 or else (not Is_Entity_Name
(Lo
)
6005 not Is_Entity_Name
(Hi
))
6007 return Entry_Index_Type
(E
);
6010 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
6011 Set_Etype
(New_T
, Base_Type
(Typ
));
6012 Set_Size_Info
(New_T
, Typ
);
6013 Set_RM_Size
(New_T
, RM_Size
(Typ
));
6014 Set_Scalar_Range
(New_T
,
6015 Make_Range
(Sloc
(Entry_Name
),
6016 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
6017 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
6021 end Actual_Index_Type
;
6023 -- Start of processing of Resolve_Entry
6026 -- Find name of entry being called, and resolve prefix of name
6027 -- with its own type. The prefix can be overloaded, and the name
6028 -- and signature of the entry must be taken into account.
6030 if Nkind
(Entry_Name
) = N_Indexed_Component
then
6032 -- Case of dealing with entry family within the current tasks
6034 E_Name
:= Prefix
(Entry_Name
);
6037 E_Name
:= Entry_Name
;
6040 if Is_Entity_Name
(E_Name
) then
6042 -- Entry call to an entry (or entry family) in the current task. This
6043 -- is legal even though the task will deadlock. Rewrite as call to
6046 -- This can also be a call to an entry in an enclosing task. If this
6047 -- is a single task, we have to retrieve its name, because the scope
6048 -- of the entry is the task type, not the object. If the enclosing
6049 -- task is a task type, the identity of the task is given by its own
6052 -- Finally this can be a requeue on an entry of the same task or
6053 -- protected object.
6055 S
:= Scope
(Entity
(E_Name
));
6057 for J
in reverse 0 .. Scope_Stack
.Last
loop
6058 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
6059 and then not Comes_From_Source
(S
)
6061 -- S is an enclosing task or protected object. The concurrent
6062 -- declaration has been converted into a type declaration, and
6063 -- the object itself has an object declaration that follows
6064 -- the type in the same declarative part.
6066 Tsk
:= Next_Entity
(S
);
6067 while Etype
(Tsk
) /= S
loop
6074 elsif S
= Scope_Stack
.Table
(J
).Entity
then
6076 -- Call to current task. Will be transformed into call to Self
6084 Make_Selected_Component
(Loc
,
6085 Prefix
=> New_Occurrence_Of
(S
, Loc
),
6087 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
6088 Rewrite
(E_Name
, New_N
);
6091 elsif Nkind
(Entry_Name
) = N_Selected_Component
6092 and then Is_Overloaded
(Prefix
(Entry_Name
))
6094 -- Use the entry name (which must be unique at this point) to find
6095 -- the prefix that returns the corresponding task type or protected
6099 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
6100 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
6105 Get_First_Interp
(Pref
, I
, It
);
6106 while Present
(It
.Typ
) loop
6107 if Scope
(Ent
) = It
.Typ
then
6108 Set_Etype
(Pref
, It
.Typ
);
6112 Get_Next_Interp
(I
, It
);
6117 if Nkind
(Entry_Name
) = N_Selected_Component
then
6118 Resolve
(Prefix
(Entry_Name
));
6120 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
6121 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
6122 Resolve
(Prefix
(Prefix
(Entry_Name
)));
6123 Index
:= First
(Expressions
(Entry_Name
));
6124 Resolve
(Index
, Entry_Index_Type
(Nam
));
6126 -- Up to this point the expression could have been the actual in a
6127 -- simple entry call, and be given by a named association.
6129 if Nkind
(Index
) = N_Parameter_Association
then
6130 Error_Msg_N
("expect expression for entry index", Index
);
6132 Apply_Range_Check
(Index
, Actual_Index_Type
(Nam
));
6137 ------------------------
6138 -- Resolve_Entry_Call --
6139 ------------------------
6141 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
6142 Entry_Name
: constant Node_Id
:= Name
(N
);
6143 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
6145 First_Named
: Node_Id
;
6152 -- We kill all checks here, because it does not seem worth the effort to
6153 -- do anything better, an entry call is a big operation.
6157 -- Processing of the name is similar for entry calls and protected
6158 -- operation calls. Once the entity is determined, we can complete
6159 -- the resolution of the actuals.
6161 -- The selector may be overloaded, in the case of a protected object
6162 -- with overloaded functions. The type of the context is used for
6165 if Nkind
(Entry_Name
) = N_Selected_Component
6166 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
6167 and then Typ
/= Standard_Void_Type
6174 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
6175 while Present
(It
.Typ
) loop
6176 if Covers
(Typ
, It
.Typ
) then
6177 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
6178 Set_Etype
(Entry_Name
, It
.Typ
);
6180 Generate_Reference
(It
.Typ
, N
, ' ');
6183 Get_Next_Interp
(I
, It
);
6188 Resolve_Entry
(Entry_Name
);
6190 if Nkind
(Entry_Name
) = N_Selected_Component
then
6192 -- Simple entry call
6194 Nam
:= Entity
(Selector_Name
(Entry_Name
));
6195 Obj
:= Prefix
(Entry_Name
);
6196 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
6198 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
6200 -- Call to member of entry family
6202 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
6203 Obj
:= Prefix
(Prefix
(Entry_Name
));
6204 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
6207 -- We cannot in general check the maximum depth of protected entry
6208 -- calls at compile time. But we can tell that any protected entry
6209 -- call at all violates a specified nesting depth of zero.
6211 if Is_Protected_Type
(Scope
(Nam
)) then
6212 Check_Restriction
(Max_Entry_Queue_Length
, N
);
6215 -- Use context type to disambiguate a protected function that can be
6216 -- called without actuals and that returns an array type, and where
6217 -- the argument list may be an indexing of the returned value.
6219 if Ekind
(Nam
) = E_Function
6220 and then Needs_No_Actuals
(Nam
)
6221 and then Present
(Parameter_Associations
(N
))
6223 ((Is_Array_Type
(Etype
(Nam
))
6224 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
6226 or else (Is_Access_Type
(Etype
(Nam
))
6227 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
6228 and then Covers
(Typ
,
6229 Component_Type
(Designated_Type
(Etype
(Nam
))))))
6232 Index_Node
: Node_Id
;
6236 Make_Indexed_Component
(Loc
,
6238 Make_Function_Call
(Loc
,
6239 Name
=> Relocate_Node
(Entry_Name
)),
6240 Expressions
=> Parameter_Associations
(N
));
6242 -- Since we are correcting a node classification error made by
6243 -- the parser, we call Replace rather than Rewrite.
6245 Replace
(N
, Index_Node
);
6246 Set_Etype
(Prefix
(N
), Etype
(Nam
));
6248 Resolve_Indexed_Component
(N
, Typ
);
6253 -- The operation name may have been overloaded. Order the actuals
6254 -- according to the formals of the resolved entity, and set the
6255 -- return type to that of the operation.
6258 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
6259 pragma Assert
(Norm_OK
);
6260 Set_Etype
(N
, Etype
(Nam
));
6263 Resolve_Actuals
(N
, Nam
);
6264 Generate_Reference
(Nam
, Entry_Name
);
6266 if Ekind_In
(Nam
, E_Entry
, E_Entry_Family
) then
6267 Check_Potentially_Blocking_Operation
(N
);
6270 -- Verify that a procedure call cannot masquerade as an entry
6271 -- call where an entry call is expected.
6273 if Ekind
(Nam
) = E_Procedure
then
6274 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
6275 and then N
= Entry_Call_Statement
(Parent
(N
))
6277 Error_Msg_N
("entry call required in select statement", N
);
6279 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
6280 and then N
= Triggering_Statement
(Parent
(N
))
6282 Error_Msg_N
("triggering statement cannot be procedure call", N
);
6284 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
6285 and then not In_Open_Scopes
(Scope
(Nam
))
6287 Error_Msg_N
("task has no entry with this name", Entry_Name
);
6291 -- After resolution, entry calls and protected procedure calls are
6292 -- changed into entry calls, for expansion. The structure of the node
6293 -- does not change, so it can safely be done in place. Protected
6294 -- function calls must keep their structure because they are
6297 if Ekind
(Nam
) /= E_Function
then
6299 -- A protected operation that is not a function may modify the
6300 -- corresponding object, and cannot apply to a constant. If this
6301 -- is an internal call, the prefix is the type itself.
6303 if Is_Protected_Type
(Scope
(Nam
))
6304 and then not Is_Variable
(Obj
)
6305 and then (not Is_Entity_Name
(Obj
)
6306 or else not Is_Type
(Entity
(Obj
)))
6309 ("prefix of protected procedure or entry call must be variable",
6313 Actuals
:= Parameter_Associations
(N
);
6314 First_Named
:= First_Named_Actual
(N
);
6317 Make_Entry_Call_Statement
(Loc
,
6319 Parameter_Associations
=> Actuals
));
6321 Set_First_Named_Actual
(N
, First_Named
);
6322 Set_Analyzed
(N
, True);
6324 -- Protected functions can return on the secondary stack, in which
6325 -- case we must trigger the transient scope mechanism.
6327 elsif Expander_Active
6328 and then Requires_Transient_Scope
(Etype
(Nam
))
6330 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
6332 end Resolve_Entry_Call
;
6334 -------------------------
6335 -- Resolve_Equality_Op --
6336 -------------------------
6338 -- Both arguments must have the same type, and the boolean context does
6339 -- not participate in the resolution. The first pass verifies that the
6340 -- interpretation is not ambiguous, and the type of the left argument is
6341 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6342 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6343 -- though they carry a single (universal) type. Diagnose this case here.
6345 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6346 L
: constant Node_Id
:= Left_Opnd
(N
);
6347 R
: constant Node_Id
:= Right_Opnd
(N
);
6348 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
6350 function Find_Unique_Access_Type
return Entity_Id
;
6351 -- In the case of allocators, make a last-ditch attempt to find a single
6352 -- access type with the right designated type. This is semantically
6353 -- dubious, and of no interest to any real code, but c48008a makes it
6356 -----------------------------
6357 -- Find_Unique_Access_Type --
6358 -----------------------------
6360 function Find_Unique_Access_Type
return Entity_Id
is
6366 if Ekind
(Etype
(R
)) = E_Allocator_Type
then
6367 Acc
:= Designated_Type
(Etype
(R
));
6368 elsif Ekind
(Etype
(L
)) = E_Allocator_Type
then
6369 Acc
:= Designated_Type
(Etype
(L
));
6375 while S
/= Standard_Standard
loop
6376 E
:= First_Entity
(S
);
6377 while Present
(E
) loop
6379 and then Is_Access_Type
(E
)
6380 and then Ekind
(E
) /= E_Allocator_Type
6381 and then Designated_Type
(E
) = Base_Type
(Acc
)
6393 end Find_Unique_Access_Type
;
6395 -- Start of processing for Resolve_Equality_Op
6398 Set_Etype
(N
, Base_Type
(Typ
));
6399 Generate_Reference
(T
, N
, ' ');
6401 if T
= Any_Fixed
then
6402 T
:= Unique_Fixed_Point_Type
(L
);
6405 if T
/= Any_Type
then
6407 or else T
= Any_Composite
6408 or else T
= Any_Character
6410 if T
= Any_Character
then
6411 Ambiguous_Character
(L
);
6413 Error_Msg_N
("ambiguous operands for equality", N
);
6416 Set_Etype
(N
, Any_Type
);
6419 elsif T
= Any_Access
6420 or else Ekind_In
(T
, E_Allocator_Type
, E_Access_Attribute_Type
)
6422 T
:= Find_Unique_Access_Type
;
6425 Error_Msg_N
("ambiguous operands for equality", N
);
6426 Set_Etype
(N
, Any_Type
);
6434 -- If the unique type is a class-wide type then it will be expanded
6435 -- into a dispatching call to the predefined primitive. Therefore we
6436 -- check here for potential violation of such restriction.
6438 if Is_Class_Wide_Type
(T
) then
6439 Check_Restriction
(No_Dispatching_Calls
, N
);
6442 if Warn_On_Redundant_Constructs
6443 and then Comes_From_Source
(N
)
6444 and then Is_Entity_Name
(R
)
6445 and then Entity
(R
) = Standard_True
6446 and then Comes_From_Source
(R
)
6448 Error_Msg_N
-- CODEFIX
6449 ("?comparison with True is redundant!", R
);
6452 Check_Unset_Reference
(L
);
6453 Check_Unset_Reference
(R
);
6454 Generate_Operator_Reference
(N
, T
);
6455 Check_Low_Bound_Tested
(N
);
6457 -- If this is an inequality, it may be the implicit inequality
6458 -- created for a user-defined operation, in which case the corres-
6459 -- ponding equality operation is not intrinsic, and the operation
6460 -- cannot be constant-folded. Else fold.
6462 if Nkind
(N
) = N_Op_Eq
6463 or else Comes_From_Source
(Entity
(N
))
6464 or else Ekind
(Entity
(N
)) = E_Operator
6465 or else Is_Intrinsic_Subprogram
6466 (Corresponding_Equality
(Entity
(N
)))
6468 Eval_Relational_Op
(N
);
6470 elsif Nkind
(N
) = N_Op_Ne
6471 and then Is_Abstract_Subprogram
(Entity
(N
))
6473 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Entity
(N
));
6476 -- Ada 2005: If one operand is an anonymous access type, convert the
6477 -- other operand to it, to ensure that the underlying types match in
6478 -- the back-end. Same for access_to_subprogram, and the conversion
6479 -- verifies that the types are subtype conformant.
6481 -- We apply the same conversion in the case one of the operands is a
6482 -- private subtype of the type of the other.
6484 -- Why the Expander_Active test here ???
6488 (Ekind_In
(T
, E_Anonymous_Access_Type
,
6489 E_Anonymous_Access_Subprogram_Type
)
6490 or else Is_Private_Type
(T
))
6492 if Etype
(L
) /= T
then
6494 Make_Unchecked_Type_Conversion
(Sloc
(L
),
6495 Subtype_Mark
=> New_Occurrence_Of
(T
, Sloc
(L
)),
6496 Expression
=> Relocate_Node
(L
)));
6497 Analyze_And_Resolve
(L
, T
);
6500 if (Etype
(R
)) /= T
then
6502 Make_Unchecked_Type_Conversion
(Sloc
(R
),
6503 Subtype_Mark
=> New_Occurrence_Of
(Etype
(L
), Sloc
(R
)),
6504 Expression
=> Relocate_Node
(R
)));
6505 Analyze_And_Resolve
(R
, T
);
6509 end Resolve_Equality_Op
;
6511 ----------------------------------
6512 -- Resolve_Explicit_Dereference --
6513 ----------------------------------
6515 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
6516 Loc
: constant Source_Ptr
:= Sloc
(N
);
6518 P
: constant Node_Id
:= Prefix
(N
);
6523 Check_Fully_Declared_Prefix
(Typ
, P
);
6525 if Is_Overloaded
(P
) then
6527 -- Use the context type to select the prefix that has the correct
6530 Get_First_Interp
(P
, I
, It
);
6531 while Present
(It
.Typ
) loop
6532 exit when Is_Access_Type
(It
.Typ
)
6533 and then Covers
(Typ
, Designated_Type
(It
.Typ
));
6534 Get_Next_Interp
(I
, It
);
6537 if Present
(It
.Typ
) then
6538 Resolve
(P
, It
.Typ
);
6540 -- If no interpretation covers the designated type of the prefix,
6541 -- this is the pathological case where not all implementations of
6542 -- the prefix allow the interpretation of the node as a call. Now
6543 -- that the expected type is known, Remove other interpretations
6544 -- from prefix, rewrite it as a call, and resolve again, so that
6545 -- the proper call node is generated.
6547 Get_First_Interp
(P
, I
, It
);
6548 while Present
(It
.Typ
) loop
6549 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
6553 Get_Next_Interp
(I
, It
);
6557 Make_Function_Call
(Loc
,
6559 Make_Explicit_Dereference
(Loc
,
6561 Parameter_Associations
=> New_List
);
6563 Save_Interps
(N
, New_N
);
6565 Analyze_And_Resolve
(N
, Typ
);
6569 Set_Etype
(N
, Designated_Type
(It
.Typ
));
6575 if Is_Access_Type
(Etype
(P
)) then
6576 Apply_Access_Check
(N
);
6579 -- If the designated type is a packed unconstrained array type, and the
6580 -- explicit dereference is not in the context of an attribute reference,
6581 -- then we must compute and set the actual subtype, since it is needed
6582 -- by Gigi. The reason we exclude the attribute case is that this is
6583 -- handled fine by Gigi, and in fact we use such attributes to build the
6584 -- actual subtype. We also exclude generated code (which builds actual
6585 -- subtypes directly if they are needed).
6587 if Is_Array_Type
(Etype
(N
))
6588 and then Is_Packed
(Etype
(N
))
6589 and then not Is_Constrained
(Etype
(N
))
6590 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
6591 and then Comes_From_Source
(N
)
6593 Set_Etype
(N
, Get_Actual_Subtype
(N
));
6596 -- Note: No Eval processing is required for an explicit dereference,
6597 -- because such a name can never be static.
6599 end Resolve_Explicit_Dereference
;
6601 -------------------------------------
6602 -- Resolve_Expression_With_Actions --
6603 -------------------------------------
6605 procedure Resolve_Expression_With_Actions
(N
: Node_Id
; Typ
: Entity_Id
) is
6608 end Resolve_Expression_With_Actions
;
6610 -------------------------------
6611 -- Resolve_Indexed_Component --
6612 -------------------------------
6614 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
6615 Name
: constant Node_Id
:= Prefix
(N
);
6617 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
6621 if Is_Overloaded
(Name
) then
6623 -- Use the context type to select the prefix that yields the correct
6629 I1
: Interp_Index
:= 0;
6630 P
: constant Node_Id
:= Prefix
(N
);
6631 Found
: Boolean := False;
6634 Get_First_Interp
(P
, I
, It
);
6635 while Present
(It
.Typ
) loop
6636 if (Is_Array_Type
(It
.Typ
)
6637 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
6638 or else (Is_Access_Type
(It
.Typ
)
6639 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
6641 (Typ
, Component_Type
(Designated_Type
(It
.Typ
))))
6644 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
6646 if It
= No_Interp
then
6647 Error_Msg_N
("ambiguous prefix for indexing", N
);
6653 Array_Type
:= It
.Typ
;
6659 Array_Type
:= It
.Typ
;
6664 Get_Next_Interp
(I
, It
);
6669 Array_Type
:= Etype
(Name
);
6672 Resolve
(Name
, Array_Type
);
6673 Array_Type
:= Get_Actual_Subtype_If_Available
(Name
);
6675 -- If prefix is access type, dereference to get real array type.
6676 -- Note: we do not apply an access check because the expander always
6677 -- introduces an explicit dereference, and the check will happen there.
6679 if Is_Access_Type
(Array_Type
) then
6680 Array_Type
:= Designated_Type
(Array_Type
);
6683 -- If name was overloaded, set component type correctly now
6684 -- If a misplaced call to an entry family (which has no index types)
6685 -- return. Error will be diagnosed from calling context.
6687 if Is_Array_Type
(Array_Type
) then
6688 Set_Etype
(N
, Component_Type
(Array_Type
));
6693 Index
:= First_Index
(Array_Type
);
6694 Expr
:= First
(Expressions
(N
));
6696 -- The prefix may have resolved to a string literal, in which case its
6697 -- etype has a special representation. This is only possible currently
6698 -- if the prefix is a static concatenation, written in functional
6701 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
6702 Resolve
(Expr
, Standard_Positive
);
6705 while Present
(Index
) and Present
(Expr
) loop
6706 Resolve
(Expr
, Etype
(Index
));
6707 Check_Unset_Reference
(Expr
);
6709 if Is_Scalar_Type
(Etype
(Expr
)) then
6710 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
6712 Apply_Range_Check
(Expr
, Get_Actual_Subtype
(Index
));
6720 -- Do not generate the warning on suspicious index if we are analyzing
6721 -- package Ada.Tags; otherwise we will report the warning with the
6722 -- Prims_Ptr field of the dispatch table.
6724 if Scope
(Etype
(Prefix
(N
))) = Standard_Standard
6726 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Prefix
(N
)))),
6729 Warn_On_Suspicious_Index
(Name
, First
(Expressions
(N
)));
6730 Eval_Indexed_Component
(N
);
6733 -- If the array type is atomic, and is packed, and we are in a left side
6734 -- context, then this is worth a warning, since we have a situation
6735 -- where the access to the component may cause extra read/writes of
6736 -- the atomic array object, which could be considered unexpected.
6738 if Nkind
(N
) = N_Indexed_Component
6739 and then (Is_Atomic
(Array_Type
)
6740 or else (Is_Entity_Name
(Prefix
(N
))
6741 and then Is_Atomic
(Entity
(Prefix
(N
)))))
6742 and then Is_Bit_Packed_Array
(Array_Type
)
6745 Error_Msg_N
("?assignment to component of packed atomic array",
6747 Error_Msg_N
("?\may cause unexpected accesses to atomic object",
6750 end Resolve_Indexed_Component
;
6752 -----------------------------
6753 -- Resolve_Integer_Literal --
6754 -----------------------------
6756 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
6759 Eval_Integer_Literal
(N
);
6760 end Resolve_Integer_Literal
;
6762 --------------------------------
6763 -- Resolve_Intrinsic_Operator --
6764 --------------------------------
6766 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
6767 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
6769 Orig_Op
: constant Entity_Id
:= Entity
(N
);
6774 -- We must preserve the original entity in a generic setting, so that
6775 -- the legality of the operation can be verified in an instance.
6777 if not Expander_Active
then
6782 while Scope
(Op
) /= Standard_Standard
loop
6784 pragma Assert
(Present
(Op
));
6788 Set_Is_Overloaded
(N
, False);
6790 -- If the operand type is private, rewrite with suitable conversions on
6791 -- the operands and the result, to expose the proper underlying numeric
6794 if Is_Private_Type
(Typ
) then
6795 Arg1
:= Unchecked_Convert_To
(Btyp
, Left_Opnd
(N
));
6797 if Nkind
(N
) = N_Op_Expon
then
6798 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
6800 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
6803 if Nkind
(Arg1
) = N_Type_Conversion
then
6804 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
6807 if Nkind
(Arg2
) = N_Type_Conversion
then
6808 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
6811 Set_Left_Opnd
(N
, Arg1
);
6812 Set_Right_Opnd
(N
, Arg2
);
6814 Set_Etype
(N
, Btyp
);
6815 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
6818 elsif Typ
/= Etype
(Left_Opnd
(N
))
6819 or else Typ
/= Etype
(Right_Opnd
(N
))
6821 -- Add explicit conversion where needed, and save interpretations in
6822 -- case operands are overloaded. If the context is a VMS operation,
6823 -- assert that the conversion is legal (the operands have the proper
6824 -- types to select the VMS intrinsic). Note that in rare cases the
6825 -- VMS operators may be visible, but the default System is being used
6826 -- and Address is a private type.
6828 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
6829 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
6831 if Nkind
(Arg1
) = N_Type_Conversion
then
6832 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
6834 if Is_VMS_Operator
(Orig_Op
) then
6835 Set_Conversion_OK
(Arg1
);
6838 Save_Interps
(Left_Opnd
(N
), Arg1
);
6841 if Nkind
(Arg2
) = N_Type_Conversion
then
6842 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
6844 if Is_VMS_Operator
(Orig_Op
) then
6845 Set_Conversion_OK
(Arg2
);
6848 Save_Interps
(Right_Opnd
(N
), Arg2
);
6851 Rewrite
(Left_Opnd
(N
), Arg1
);
6852 Rewrite
(Right_Opnd
(N
), Arg2
);
6855 Resolve_Arithmetic_Op
(N
, Typ
);
6858 Resolve_Arithmetic_Op
(N
, Typ
);
6860 end Resolve_Intrinsic_Operator
;
6862 --------------------------------------
6863 -- Resolve_Intrinsic_Unary_Operator --
6864 --------------------------------------
6866 procedure Resolve_Intrinsic_Unary_Operator
6870 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
6876 while Scope
(Op
) /= Standard_Standard
loop
6878 pragma Assert
(Present
(Op
));
6883 if Is_Private_Type
(Typ
) then
6884 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
6885 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
6887 Set_Right_Opnd
(N
, Arg2
);
6889 Set_Etype
(N
, Btyp
);
6890 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
6894 Resolve_Unary_Op
(N
, Typ
);
6896 end Resolve_Intrinsic_Unary_Operator
;
6898 ------------------------
6899 -- Resolve_Logical_Op --
6900 ------------------------
6902 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6906 Check_No_Direct_Boolean_Operators
(N
);
6908 -- Predefined operations on scalar types yield the base type. On the
6909 -- other hand, logical operations on arrays yield the type of the
6910 -- arguments (and the context).
6912 if Is_Array_Type
(Typ
) then
6915 B_Typ
:= Base_Type
(Typ
);
6918 -- OK if this is a VMS-specific intrinsic operation
6920 if Is_VMS_Operator
(Entity
(N
)) then
6923 -- The following test is required because the operands of the operation
6924 -- may be literals, in which case the resulting type appears to be
6925 -- compatible with a signed integer type, when in fact it is compatible
6926 -- only with modular types. If the context itself is universal, the
6927 -- operation is illegal.
6929 elsif not Valid_Boolean_Arg
(Typ
) then
6930 Error_Msg_N
("invalid context for logical operation", N
);
6931 Set_Etype
(N
, Any_Type
);
6934 elsif Typ
= Any_Modular
then
6936 ("no modular type available in this context", N
);
6937 Set_Etype
(N
, Any_Type
);
6939 elsif Is_Modular_Integer_Type
(Typ
)
6940 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
6941 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
6943 Check_For_Visible_Operator
(N
, B_Typ
);
6946 Resolve
(Left_Opnd
(N
), B_Typ
);
6947 Resolve
(Right_Opnd
(N
), B_Typ
);
6949 Check_Unset_Reference
(Left_Opnd
(N
));
6950 Check_Unset_Reference
(Right_Opnd
(N
));
6952 Set_Etype
(N
, B_Typ
);
6953 Generate_Operator_Reference
(N
, B_Typ
);
6954 Eval_Logical_Op
(N
);
6955 end Resolve_Logical_Op
;
6957 ---------------------------
6958 -- Resolve_Membership_Op --
6959 ---------------------------
6961 -- The context can only be a boolean type, and does not determine
6962 -- the arguments. Arguments should be unambiguous, but the preference
6963 -- rule for universal types applies.
6965 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6966 pragma Warnings
(Off
, Typ
);
6968 L
: constant Node_Id
:= Left_Opnd
(N
);
6969 R
: constant Node_Id
:= Right_Opnd
(N
);
6972 procedure Resolve_Set_Membership
;
6973 -- Analysis has determined a unique type for the left operand.
6974 -- Use it to resolve the disjuncts.
6976 ----------------------------
6977 -- Resolve_Set_Membership --
6978 ----------------------------
6980 procedure Resolve_Set_Membership
is
6984 Resolve
(L
, Etype
(L
));
6986 Alt
:= First
(Alternatives
(N
));
6987 while Present
(Alt
) loop
6989 -- Alternative is an expression, a range
6990 -- or a subtype mark.
6992 if not Is_Entity_Name
(Alt
)
6993 or else not Is_Type
(Entity
(Alt
))
6995 Resolve
(Alt
, Etype
(L
));
7000 end Resolve_Set_Membership
;
7002 -- Start of processing for Resolve_Membership_Op
7005 if L
= Error
or else R
= Error
then
7009 if Present
(Alternatives
(N
)) then
7010 Resolve_Set_Membership
;
7013 elsif not Is_Overloaded
(R
)
7015 (Etype
(R
) = Universal_Integer
or else
7016 Etype
(R
) = Universal_Real
)
7017 and then Is_Overloaded
(L
)
7021 -- Ada 2005 (AI-251): Support the following case:
7023 -- type I is interface;
7024 -- type T is tagged ...
7026 -- function Test (O : I'Class) is
7028 -- return O in T'Class.
7031 -- In this case we have nothing else to do. The membership test will be
7032 -- done at run-time.
7034 elsif Ada_Version
>= Ada_05
7035 and then Is_Class_Wide_Type
(Etype
(L
))
7036 and then Is_Interface
(Etype
(L
))
7037 and then Is_Class_Wide_Type
(Etype
(R
))
7038 and then not Is_Interface
(Etype
(R
))
7043 T
:= Intersect_Types
(L
, R
);
7046 -- If mixed-mode operations are present and operands are all literal,
7047 -- the only interpretation involves Duration, which is probably not
7048 -- the intention of the programmer.
7050 if T
= Any_Fixed
then
7051 T
:= Unique_Fixed_Point_Type
(N
);
7053 if T
= Any_Type
then
7059 Check_Unset_Reference
(L
);
7061 if Nkind
(R
) = N_Range
7062 and then not Is_Scalar_Type
(T
)
7064 Error_Msg_N
("scalar type required for range", R
);
7067 if Is_Entity_Name
(R
) then
7068 Freeze_Expression
(R
);
7071 Check_Unset_Reference
(R
);
7074 Eval_Membership_Op
(N
);
7075 end Resolve_Membership_Op
;
7081 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
7082 Loc
: constant Source_Ptr
:= Sloc
(N
);
7085 -- Handle restriction against anonymous null access values This
7086 -- restriction can be turned off using -gnatdj.
7088 -- Ada 2005 (AI-231): Remove restriction
7090 if Ada_Version
< Ada_05
7091 and then not Debug_Flag_J
7092 and then Ekind
(Typ
) = E_Anonymous_Access_Type
7093 and then Comes_From_Source
(N
)
7095 -- In the common case of a call which uses an explicitly null value
7096 -- for an access parameter, give specialized error message.
7098 if Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
7102 ("null is not allowed as argument for an access parameter", N
);
7104 -- Standard message for all other cases (are there any?)
7108 ("null cannot be of an anonymous access type", N
);
7112 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
7113 -- assignment to a null-excluding object
7115 if Ada_Version
>= Ada_05
7116 and then Can_Never_Be_Null
(Typ
)
7117 and then Nkind
(Parent
(N
)) = N_Assignment_Statement
7119 if not Inside_Init_Proc
then
7121 (Compile_Time_Constraint_Error
(N
,
7122 "(Ada 2005) null not allowed in null-excluding objects?"),
7123 Make_Raise_Constraint_Error
(Loc
,
7124 Reason
=> CE_Access_Check_Failed
));
7127 Make_Raise_Constraint_Error
(Loc
,
7128 Reason
=> CE_Access_Check_Failed
));
7132 -- In a distributed context, null for a remote access to subprogram may
7133 -- need to be replaced with a special record aggregate. In this case,
7134 -- return after having done the transformation.
7136 if (Ekind
(Typ
) = E_Record_Type
7137 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
7138 and then Remote_AST_Null_Value
(N
, Typ
)
7143 -- The null literal takes its type from the context
7148 -----------------------
7149 -- Resolve_Op_Concat --
7150 -----------------------
7152 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
7154 -- We wish to avoid deep recursion, because concatenations are often
7155 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
7156 -- operands nonrecursively until we find something that is not a simple
7157 -- concatenation (A in this case). We resolve that, and then walk back
7158 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
7159 -- to do the rest of the work at each level. The Parent pointers allow
7160 -- us to avoid recursion, and thus avoid running out of memory. See also
7161 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
7167 -- The following code is equivalent to:
7169 -- Resolve_Op_Concat_First (NN, Typ);
7170 -- Resolve_Op_Concat_Arg (N, ...);
7171 -- Resolve_Op_Concat_Rest (N, Typ);
7173 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
7174 -- operand is a concatenation.
7176 -- Walk down left operands
7179 Resolve_Op_Concat_First
(NN
, Typ
);
7180 Op1
:= Left_Opnd
(NN
);
7181 exit when not (Nkind
(Op1
) = N_Op_Concat
7182 and then not Is_Array_Type
(Component_Type
(Typ
))
7183 and then Entity
(Op1
) = Entity
(NN
));
7187 -- Now (given the above example) NN is A&B and Op1 is A
7189 -- First resolve Op1 ...
7191 Resolve_Op_Concat_Arg
(NN
, Op1
, Typ
, Is_Component_Left_Opnd
(NN
));
7193 -- ... then walk NN back up until we reach N (where we started), calling
7194 -- Resolve_Op_Concat_Rest along the way.
7197 Resolve_Op_Concat_Rest
(NN
, Typ
);
7201 end Resolve_Op_Concat
;
7203 ---------------------------
7204 -- Resolve_Op_Concat_Arg --
7205 ---------------------------
7207 procedure Resolve_Op_Concat_Arg
7213 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7218 or else (not Is_Overloaded
(Arg
)
7219 and then Etype
(Arg
) /= Any_Composite
7220 and then Covers
(Component_Type
(Typ
), Etype
(Arg
)))
7222 Resolve
(Arg
, Component_Type
(Typ
));
7224 Resolve
(Arg
, Btyp
);
7227 elsif Has_Compatible_Type
(Arg
, Component_Type
(Typ
)) then
7228 if Nkind
(Arg
) = N_Aggregate
7229 and then Is_Composite_Type
(Component_Type
(Typ
))
7231 if Is_Private_Type
(Component_Type
(Typ
)) then
7232 Resolve
(Arg
, Btyp
);
7234 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
7235 Set_Etype
(Arg
, Any_Type
);
7239 if Is_Overloaded
(Arg
)
7240 and then Has_Compatible_Type
(Arg
, Typ
)
7241 and then Etype
(Arg
) /= Any_Type
7249 Get_First_Interp
(Arg
, I
, It
);
7251 Get_Next_Interp
(I
, It
);
7253 -- Special-case the error message when the overloading is
7254 -- caused by a function that yields an array and can be
7255 -- called without parameters.
7257 if It
.Nam
= Func
then
7258 Error_Msg_Sloc
:= Sloc
(Func
);
7259 Error_Msg_N
("ambiguous call to function#", Arg
);
7261 ("\\interpretation as call yields&", Arg
, Typ
);
7263 ("\\interpretation as indexing of call yields&",
7264 Arg
, Component_Type
(Typ
));
7268 ("ambiguous operand for concatenation!", Arg
);
7269 Get_First_Interp
(Arg
, I
, It
);
7270 while Present
(It
.Nam
) loop
7271 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
7273 if Base_Type
(It
.Typ
) = Base_Type
(Typ
)
7274 or else Base_Type
(It
.Typ
) =
7275 Base_Type
(Component_Type
(Typ
))
7277 Error_Msg_N
-- CODEFIX
7278 ("\\possible interpretation#", Arg
);
7281 Get_Next_Interp
(I
, It
);
7287 Resolve
(Arg
, Component_Type
(Typ
));
7289 if Nkind
(Arg
) = N_String_Literal
then
7290 Set_Etype
(Arg
, Component_Type
(Typ
));
7293 if Arg
= Left_Opnd
(N
) then
7294 Set_Is_Component_Left_Opnd
(N
);
7296 Set_Is_Component_Right_Opnd
(N
);
7301 Resolve
(Arg
, Btyp
);
7304 Check_Unset_Reference
(Arg
);
7305 end Resolve_Op_Concat_Arg
;
7307 -----------------------------
7308 -- Resolve_Op_Concat_First --
7309 -----------------------------
7311 procedure Resolve_Op_Concat_First
(N
: Node_Id
; Typ
: Entity_Id
) is
7312 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7313 Op1
: constant Node_Id
:= Left_Opnd
(N
);
7314 Op2
: constant Node_Id
:= Right_Opnd
(N
);
7317 -- The parser folds an enormous sequence of concatenations of string
7318 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
7319 -- in the right operand. If the expression resolves to a predefined "&"
7320 -- operator, all is well. Otherwise, the parser's folding is wrong, so
7321 -- we give an error. See P_Simple_Expression in Par.Ch4.
7323 if Nkind
(Op2
) = N_String_Literal
7324 and then Is_Folded_In_Parser
(Op2
)
7325 and then Ekind
(Entity
(N
)) = E_Function
7327 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
7328 and then String_Length
(Strval
(Op1
)) = 0);
7329 Error_Msg_N
("too many user-defined concatenations", N
);
7333 Set_Etype
(N
, Btyp
);
7335 if Is_Limited_Composite
(Btyp
) then
7336 Error_Msg_N
("concatenation not available for limited array", N
);
7337 Explain_Limited_Type
(Btyp
, N
);
7339 end Resolve_Op_Concat_First
;
7341 ----------------------------
7342 -- Resolve_Op_Concat_Rest --
7343 ----------------------------
7345 procedure Resolve_Op_Concat_Rest
(N
: Node_Id
; Typ
: Entity_Id
) is
7346 Op1
: constant Node_Id
:= Left_Opnd
(N
);
7347 Op2
: constant Node_Id
:= Right_Opnd
(N
);
7350 Resolve_Op_Concat_Arg
(N
, Op2
, Typ
, Is_Component_Right_Opnd
(N
));
7352 Generate_Operator_Reference
(N
, Typ
);
7354 if Is_String_Type
(Typ
) then
7355 Eval_Concatenation
(N
);
7358 -- If this is not a static concatenation, but the result is a string
7359 -- type (and not an array of strings) ensure that static string operands
7360 -- have their subtypes properly constructed.
7362 if Nkind
(N
) /= N_String_Literal
7363 and then Is_Character_Type
(Component_Type
(Typ
))
7365 Set_String_Literal_Subtype
(Op1
, Typ
);
7366 Set_String_Literal_Subtype
(Op2
, Typ
);
7368 end Resolve_Op_Concat_Rest
;
7370 ----------------------
7371 -- Resolve_Op_Expon --
7372 ----------------------
7374 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
7375 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7378 -- Catch attempts to do fixed-point exponentiation with universal
7379 -- operands, which is a case where the illegality is not caught during
7380 -- normal operator analysis.
7382 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
7383 Error_Msg_N
("exponentiation not available for fixed point", N
);
7387 if Comes_From_Source
(N
)
7388 and then Ekind
(Entity
(N
)) = E_Function
7389 and then Is_Imported
(Entity
(N
))
7390 and then Is_Intrinsic_Subprogram
(Entity
(N
))
7392 Resolve_Intrinsic_Operator
(N
, Typ
);
7396 if Etype
(Left_Opnd
(N
)) = Universal_Integer
7397 or else Etype
(Left_Opnd
(N
)) = Universal_Real
7399 Check_For_Visible_Operator
(N
, B_Typ
);
7402 -- We do the resolution using the base type, because intermediate values
7403 -- in expressions always are of the base type, not a subtype of it.
7405 Resolve
(Left_Opnd
(N
), B_Typ
);
7406 Resolve
(Right_Opnd
(N
), Standard_Integer
);
7408 Check_Unset_Reference
(Left_Opnd
(N
));
7409 Check_Unset_Reference
(Right_Opnd
(N
));
7411 Set_Etype
(N
, B_Typ
);
7412 Generate_Operator_Reference
(N
, B_Typ
);
7415 -- Set overflow checking bit. Much cleverer code needed here eventually
7416 -- and perhaps the Resolve routines should be separated for the various
7417 -- arithmetic operations, since they will need different processing. ???
7419 if Nkind
(N
) in N_Op
then
7420 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
7421 Enable_Overflow_Check
(N
);
7424 end Resolve_Op_Expon
;
7426 --------------------
7427 -- Resolve_Op_Not --
7428 --------------------
7430 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
7433 function Parent_Is_Boolean
return Boolean;
7434 -- This function determines if the parent node is a boolean operator
7435 -- or operation (comparison op, membership test, or short circuit form)
7436 -- and the not in question is the left operand of this operation.
7437 -- Note that if the not is in parens, then false is returned.
7439 -----------------------
7440 -- Parent_Is_Boolean --
7441 -----------------------
7443 function Parent_Is_Boolean
return Boolean is
7445 if Paren_Count
(N
) /= 0 then
7449 case Nkind
(Parent
(N
)) is
7464 return Left_Opnd
(Parent
(N
)) = N
;
7470 end Parent_Is_Boolean
;
7472 -- Start of processing for Resolve_Op_Not
7475 -- Predefined operations on scalar types yield the base type. On the
7476 -- other hand, logical operations on arrays yield the type of the
7477 -- arguments (and the context).
7479 if Is_Array_Type
(Typ
) then
7482 B_Typ
:= Base_Type
(Typ
);
7485 if Is_VMS_Operator
(Entity
(N
)) then
7488 -- Straightforward case of incorrect arguments
7490 elsif not Valid_Boolean_Arg
(Typ
) then
7491 Error_Msg_N
("invalid operand type for operator&", N
);
7492 Set_Etype
(N
, Any_Type
);
7495 -- Special case of probable missing parens
7497 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
7498 if Parent_Is_Boolean
then
7500 ("operand of not must be enclosed in parentheses",
7504 ("no modular type available in this context", N
);
7507 Set_Etype
(N
, Any_Type
);
7510 -- OK resolution of not
7513 -- Warn if non-boolean types involved. This is a case like not a < b
7514 -- where a and b are modular, where we will get (not a) < b and most
7515 -- likely not (a < b) was intended.
7517 if Warn_On_Questionable_Missing_Parens
7518 and then not Is_Boolean_Type
(Typ
)
7519 and then Parent_Is_Boolean
7521 Error_Msg_N
("?not expression should be parenthesized here!", N
);
7524 -- Warn on double negation if checking redundant constructs
7526 if Warn_On_Redundant_Constructs
7527 and then Comes_From_Source
(N
)
7528 and then Comes_From_Source
(Right_Opnd
(N
))
7529 and then Root_Type
(Typ
) = Standard_Boolean
7530 and then Nkind
(Right_Opnd
(N
)) = N_Op_Not
7532 Error_Msg_N
("redundant double negation?", N
);
7535 -- Complete resolution and evaluation of NOT
7537 Resolve
(Right_Opnd
(N
), B_Typ
);
7538 Check_Unset_Reference
(Right_Opnd
(N
));
7539 Set_Etype
(N
, B_Typ
);
7540 Generate_Operator_Reference
(N
, B_Typ
);
7545 -----------------------------
7546 -- Resolve_Operator_Symbol --
7547 -----------------------------
7549 -- Nothing to be done, all resolved already
7551 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
7552 pragma Warnings
(Off
, N
);
7553 pragma Warnings
(Off
, Typ
);
7557 end Resolve_Operator_Symbol
;
7559 ----------------------------------
7560 -- Resolve_Qualified_Expression --
7561 ----------------------------------
7563 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
7564 pragma Warnings
(Off
, Typ
);
7566 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
7567 Expr
: constant Node_Id
:= Expression
(N
);
7570 Resolve
(Expr
, Target_Typ
);
7572 -- A qualified expression requires an exact match of the type,
7573 -- class-wide matching is not allowed. However, if the qualifying
7574 -- type is specific and the expression has a class-wide type, it
7575 -- may still be okay, since it can be the result of the expansion
7576 -- of a call to a dispatching function, so we also have to check
7577 -- class-wideness of the type of the expression's original node.
7579 if (Is_Class_Wide_Type
(Target_Typ
)
7581 (Is_Class_Wide_Type
(Etype
(Expr
))
7582 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
7583 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
7585 Wrong_Type
(Expr
, Target_Typ
);
7588 -- If the target type is unconstrained, then we reset the type of
7589 -- the result from the type of the expression. For other cases, the
7590 -- actual subtype of the expression is the target type.
7592 if Is_Composite_Type
(Target_Typ
)
7593 and then not Is_Constrained
(Target_Typ
)
7595 Set_Etype
(N
, Etype
(Expr
));
7598 Eval_Qualified_Expression
(N
);
7599 end Resolve_Qualified_Expression
;
7605 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
7606 L
: constant Node_Id
:= Low_Bound
(N
);
7607 H
: constant Node_Id
:= High_Bound
(N
);
7614 Check_Unset_Reference
(L
);
7615 Check_Unset_Reference
(H
);
7617 -- We have to check the bounds for being within the base range as
7618 -- required for a non-static context. Normally this is automatic and
7619 -- done as part of evaluating expressions, but the N_Range node is an
7620 -- exception, since in GNAT we consider this node to be a subexpression,
7621 -- even though in Ada it is not. The circuit in Sem_Eval could check for
7622 -- this, but that would put the test on the main evaluation path for
7625 Check_Non_Static_Context
(L
);
7626 Check_Non_Static_Context
(H
);
7628 -- Check for an ambiguous range over character literals. This will
7629 -- happen with a membership test involving only literals.
7631 if Typ
= Any_Character
then
7632 Ambiguous_Character
(L
);
7633 Set_Etype
(N
, Any_Type
);
7637 -- If bounds are static, constant-fold them, so size computations
7638 -- are identical between front-end and back-end. Do not perform this
7639 -- transformation while analyzing generic units, as type information
7640 -- would then be lost when reanalyzing the constant node in the
7643 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
7644 if Is_OK_Static_Expression
(L
) then
7645 Fold_Uint
(L
, Expr_Value
(L
), Is_Static_Expression
(L
));
7648 if Is_OK_Static_Expression
(H
) then
7649 Fold_Uint
(H
, Expr_Value
(H
), Is_Static_Expression
(H
));
7654 --------------------------
7655 -- Resolve_Real_Literal --
7656 --------------------------
7658 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
7659 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
7662 -- Special processing for fixed-point literals to make sure that the
7663 -- value is an exact multiple of small where this is required. We
7664 -- skip this for the universal real case, and also for generic types.
7666 if Is_Fixed_Point_Type
(Typ
)
7667 and then Typ
/= Universal_Fixed
7668 and then Typ
/= Any_Fixed
7669 and then not Is_Generic_Type
(Typ
)
7672 Val
: constant Ureal
:= Realval
(N
);
7673 Cintr
: constant Ureal
:= Val
/ Small_Value
(Typ
);
7674 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
7675 Den
: constant Uint
:= Norm_Den
(Cintr
);
7679 -- Case of literal is not an exact multiple of the Small
7683 -- For a source program literal for a decimal fixed-point
7684 -- type, this is statically illegal (RM 4.9(36)).
7686 if Is_Decimal_Fixed_Point_Type
(Typ
)
7687 and then Actual_Typ
= Universal_Real
7688 and then Comes_From_Source
(N
)
7690 Error_Msg_N
("value has extraneous low order digits", N
);
7693 -- Generate a warning if literal from source
7695 if Is_Static_Expression
(N
)
7696 and then Warn_On_Bad_Fixed_Value
7699 ("?static fixed-point value is not a multiple of Small!",
7703 -- Replace literal by a value that is the exact representation
7704 -- of a value of the type, i.e. a multiple of the small value,
7705 -- by truncation, since Machine_Rounds is false for all GNAT
7706 -- fixed-point types (RM 4.9(38)).
7708 Stat
:= Is_Static_Expression
(N
);
7710 Make_Real_Literal
(Sloc
(N
),
7711 Realval
=> Small_Value
(Typ
) * Cint
));
7713 Set_Is_Static_Expression
(N
, Stat
);
7716 -- In all cases, set the corresponding integer field
7718 Set_Corresponding_Integer_Value
(N
, Cint
);
7722 -- Now replace the actual type by the expected type as usual
7725 Eval_Real_Literal
(N
);
7726 end Resolve_Real_Literal
;
7728 -----------------------
7729 -- Resolve_Reference --
7730 -----------------------
7732 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
7733 P
: constant Node_Id
:= Prefix
(N
);
7736 -- Replace general access with specific type
7738 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
7739 Set_Etype
(N
, Base_Type
(Typ
));
7742 Resolve
(P
, Designated_Type
(Etype
(N
)));
7744 -- If we are taking the reference of a volatile entity, then treat
7745 -- it as a potential modification of this entity. This is much too
7746 -- conservative, but is necessary because remove side effects can
7747 -- result in transformations of normal assignments into reference
7748 -- sequences that otherwise fail to notice the modification.
7750 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
7751 Note_Possible_Modification
(P
, Sure
=> False);
7753 end Resolve_Reference
;
7755 --------------------------------
7756 -- Resolve_Selected_Component --
7757 --------------------------------
7759 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
7761 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
7762 P
: constant Node_Id
:= Prefix
(N
);
7763 S
: constant Node_Id
:= Selector_Name
(N
);
7764 T
: Entity_Id
:= Etype
(P
);
7766 I1
: Interp_Index
:= 0; -- prevent junk warning
7771 function Init_Component
return Boolean;
7772 -- Check whether this is the initialization of a component within an
7773 -- init proc (by assignment or call to another init proc). If true,
7774 -- there is no need for a discriminant check.
7776 --------------------
7777 -- Init_Component --
7778 --------------------
7780 function Init_Component
return Boolean is
7782 return Inside_Init_Proc
7783 and then Nkind
(Prefix
(N
)) = N_Identifier
7784 and then Chars
(Prefix
(N
)) = Name_uInit
7785 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
7788 -- Start of processing for Resolve_Selected_Component
7791 if Is_Overloaded
(P
) then
7793 -- Use the context type to select the prefix that has a selector
7794 -- of the correct name and type.
7797 Get_First_Interp
(P
, I
, It
);
7799 Search
: while Present
(It
.Typ
) loop
7800 if Is_Access_Type
(It
.Typ
) then
7801 T
:= Designated_Type
(It
.Typ
);
7806 if Is_Record_Type
(T
) then
7808 -- The visible components of a class-wide type are those of
7811 if Is_Class_Wide_Type
(T
) then
7815 Comp
:= First_Entity
(T
);
7816 while Present
(Comp
) loop
7817 if Chars
(Comp
) = Chars
(S
)
7818 and then Covers
(Etype
(Comp
), Typ
)
7827 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
7829 if It
= No_Interp
then
7831 ("ambiguous prefix for selected component", N
);
7838 -- There may be an implicit dereference. Retrieve
7839 -- designated record type.
7841 if Is_Access_Type
(It1
.Typ
) then
7842 T
:= Designated_Type
(It1
.Typ
);
7847 if Scope
(Comp1
) /= T
then
7849 -- Resolution chooses the new interpretation.
7850 -- Find the component with the right name.
7852 Comp1
:= First_Entity
(T
);
7853 while Present
(Comp1
)
7854 and then Chars
(Comp1
) /= Chars
(S
)
7856 Comp1
:= Next_Entity
(Comp1
);
7865 Comp
:= Next_Entity
(Comp
);
7869 Get_Next_Interp
(I
, It
);
7872 Resolve
(P
, It1
.Typ
);
7874 Set_Entity_With_Style_Check
(S
, Comp1
);
7877 -- Resolve prefix with its type
7882 -- Generate cross-reference. We needed to wait until full overloading
7883 -- resolution was complete to do this, since otherwise we can't tell if
7884 -- we are an lvalue or not.
7886 if May_Be_Lvalue
(N
) then
7887 Generate_Reference
(Entity
(S
), S
, 'm');
7889 Generate_Reference
(Entity
(S
), S
, 'r');
7892 -- If prefix is an access type, the node will be transformed into an
7893 -- explicit dereference during expansion. The type of the node is the
7894 -- designated type of that of the prefix.
7896 if Is_Access_Type
(Etype
(P
)) then
7897 T
:= Designated_Type
(Etype
(P
));
7898 Check_Fully_Declared_Prefix
(T
, P
);
7903 if Has_Discriminants
(T
)
7904 and then Ekind_In
(Entity
(S
), E_Component
, E_Discriminant
)
7905 and then Present
(Original_Record_Component
(Entity
(S
)))
7906 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
7907 and then Present
(Discriminant_Checking_Func
7908 (Original_Record_Component
(Entity
(S
))))
7909 and then not Discriminant_Checks_Suppressed
(T
)
7910 and then not Init_Component
7912 Set_Do_Discriminant_Check
(N
);
7915 if Ekind
(Entity
(S
)) = E_Void
then
7916 Error_Msg_N
("premature use of component", S
);
7919 -- If the prefix is a record conversion, this may be a renamed
7920 -- discriminant whose bounds differ from those of the original
7921 -- one, so we must ensure that a range check is performed.
7923 if Nkind
(P
) = N_Type_Conversion
7924 and then Ekind
(Entity
(S
)) = E_Discriminant
7925 and then Is_Discrete_Type
(Typ
)
7927 Set_Etype
(N
, Base_Type
(Typ
));
7930 -- Note: No Eval processing is required, because the prefix is of a
7931 -- record type, or protected type, and neither can possibly be static.
7933 -- If the array type is atomic, and is packed, and we are in a left side
7934 -- context, then this is worth a warning, since we have a situation
7935 -- where the access to the component may cause extra read/writes of
7936 -- the atomic array object, which could be considered unexpected.
7938 if Nkind
(N
) = N_Selected_Component
7939 and then (Is_Atomic
(T
)
7940 or else (Is_Entity_Name
(Prefix
(N
))
7941 and then Is_Atomic
(Entity
(Prefix
(N
)))))
7942 and then Is_Packed
(T
)
7945 Error_Msg_N
("?assignment to component of packed atomic record",
7947 Error_Msg_N
("?\may cause unexpected accesses to atomic object",
7950 end Resolve_Selected_Component
;
7956 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
7957 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7958 L
: constant Node_Id
:= Left_Opnd
(N
);
7959 R
: constant Node_Id
:= Right_Opnd
(N
);
7962 -- We do the resolution using the base type, because intermediate values
7963 -- in expressions always are of the base type, not a subtype of it.
7966 Resolve
(R
, Standard_Natural
);
7968 Check_Unset_Reference
(L
);
7969 Check_Unset_Reference
(R
);
7971 Set_Etype
(N
, B_Typ
);
7972 Generate_Operator_Reference
(N
, B_Typ
);
7976 ---------------------------
7977 -- Resolve_Short_Circuit --
7978 ---------------------------
7980 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
7981 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7982 L
: constant Node_Id
:= Left_Opnd
(N
);
7983 R
: constant Node_Id
:= Right_Opnd
(N
);
7986 -- Why are the calls to Check_Order_Dependence commented out ???
7988 -- Check_Order_Dependence; -- For AI05-0144
7990 -- Check_Order_Dependence; -- For AI05-0144
7992 -- Check for issuing warning for always False assert/check, this happens
7993 -- when assertions are turned off, in which case the pragma Assert/Check
7994 -- was transformed into:
7996 -- if False and then <condition> then ...
7998 -- and we detect this pattern
8000 if Warn_On_Assertion_Failure
8001 and then Is_Entity_Name
(R
)
8002 and then Entity
(R
) = Standard_False
8003 and then Nkind
(Parent
(N
)) = N_If_Statement
8004 and then Nkind
(N
) = N_And_Then
8005 and then Is_Entity_Name
(L
)
8006 and then Entity
(L
) = Standard_False
8009 Orig
: constant Node_Id
:= Original_Node
(Parent
(N
));
8012 if Nkind
(Orig
) = N_Pragma
8013 and then Pragma_Name
(Orig
) = Name_Assert
8015 -- Don't want to warn if original condition is explicit False
8018 Expr
: constant Node_Id
:=
8021 (First
(Pragma_Argument_Associations
(Orig
))));
8023 if Is_Entity_Name
(Expr
)
8024 and then Entity
(Expr
) = Standard_False
8028 -- Issue warning. We do not want the deletion of the
8029 -- IF/AND-THEN to take this message with it. We achieve
8030 -- this by making sure that the expanded code points to
8031 -- the Sloc of the expression, not the original pragma.
8034 ("?assertion would fail at run-time!",
8036 (First
(Pragma_Argument_Associations
(Orig
))));
8040 -- Similar processing for Check pragma
8042 elsif Nkind
(Orig
) = N_Pragma
8043 and then Pragma_Name
(Orig
) = Name_Check
8045 -- Don't want to warn if original condition is explicit False
8048 Expr
: constant Node_Id
:=
8052 (Pragma_Argument_Associations
(Orig
)))));
8054 if Is_Entity_Name
(Expr
)
8055 and then Entity
(Expr
) = Standard_False
8060 ("?check would fail at run-time!",
8062 (Last
(Pragma_Argument_Associations
(Orig
))));
8069 -- Continue with processing of short circuit
8071 Check_Unset_Reference
(L
);
8072 Check_Unset_Reference
(R
);
8074 Set_Etype
(N
, B_Typ
);
8075 Eval_Short_Circuit
(N
);
8076 end Resolve_Short_Circuit
;
8082 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
8083 Name
: constant Node_Id
:= Prefix
(N
);
8084 Drange
: constant Node_Id
:= Discrete_Range
(N
);
8085 Array_Type
: Entity_Id
:= Empty
;
8089 if Is_Overloaded
(Name
) then
8091 -- Use the context type to select the prefix that yields the correct
8096 I1
: Interp_Index
:= 0;
8098 P
: constant Node_Id
:= Prefix
(N
);
8099 Found
: Boolean := False;
8102 Get_First_Interp
(P
, I
, It
);
8103 while Present
(It
.Typ
) loop
8104 if (Is_Array_Type
(It
.Typ
)
8105 and then Covers
(Typ
, It
.Typ
))
8106 or else (Is_Access_Type
(It
.Typ
)
8107 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
8108 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
8111 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
8113 if It
= No_Interp
then
8114 Error_Msg_N
("ambiguous prefix for slicing", N
);
8119 Array_Type
:= It
.Typ
;
8124 Array_Type
:= It
.Typ
;
8129 Get_Next_Interp
(I
, It
);
8134 Array_Type
:= Etype
(Name
);
8137 Resolve
(Name
, Array_Type
);
8139 if Is_Access_Type
(Array_Type
) then
8140 Apply_Access_Check
(N
);
8141 Array_Type
:= Designated_Type
(Array_Type
);
8143 -- If the prefix is an access to an unconstrained array, we must use
8144 -- the actual subtype of the object to perform the index checks. The
8145 -- object denoted by the prefix is implicit in the node, so we build
8146 -- an explicit representation for it in order to compute the actual
8149 if not Is_Constrained
(Array_Type
) then
8150 Remove_Side_Effects
(Prefix
(N
));
8153 Obj
: constant Node_Id
:=
8154 Make_Explicit_Dereference
(Sloc
(N
),
8155 Prefix
=> New_Copy_Tree
(Prefix
(N
)));
8157 Set_Etype
(Obj
, Array_Type
);
8158 Set_Parent
(Obj
, Parent
(N
));
8159 Array_Type
:= Get_Actual_Subtype
(Obj
);
8163 elsif Is_Entity_Name
(Name
)
8164 or else Nkind
(Name
) = N_Explicit_Dereference
8165 or else (Nkind
(Name
) = N_Function_Call
8166 and then not Is_Constrained
(Etype
(Name
)))
8168 Array_Type
:= Get_Actual_Subtype
(Name
);
8170 -- If the name is a selected component that depends on discriminants,
8171 -- build an actual subtype for it. This can happen only when the name
8172 -- itself is overloaded; otherwise the actual subtype is created when
8173 -- the selected component is analyzed.
8175 elsif Nkind
(Name
) = N_Selected_Component
8176 and then Full_Analysis
8177 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
8180 Act_Decl
: constant Node_Id
:=
8181 Build_Actual_Subtype_Of_Component
(Array_Type
, Name
);
8183 Insert_Action
(N
, Act_Decl
);
8184 Array_Type
:= Defining_Identifier
(Act_Decl
);
8187 -- Maybe this should just be "else", instead of checking for the
8188 -- specific case of slice??? This is needed for the case where
8189 -- the prefix is an Image attribute, which gets expanded to a
8190 -- slice, and so has a constrained subtype which we want to use
8191 -- for the slice range check applied below (the range check won't
8192 -- get done if the unconstrained subtype of the 'Image is used).
8194 elsif Nkind
(Name
) = N_Slice
then
8195 Array_Type
:= Etype
(Name
);
8198 -- If name was overloaded, set slice type correctly now
8200 Set_Etype
(N
, Array_Type
);
8202 -- If the range is specified by a subtype mark, no resolution is
8203 -- necessary. Else resolve the bounds, and apply needed checks.
8205 if not Is_Entity_Name
(Drange
) then
8206 Index
:= First_Index
(Array_Type
);
8207 Resolve
(Drange
, Base_Type
(Etype
(Index
)));
8209 if Nkind
(Drange
) = N_Range
8211 -- Do not apply the range check to nodes associated with the
8212 -- frontend expansion of the dispatch table. We first check
8213 -- if Ada.Tags is already loaded to void the addition of an
8214 -- undesired dependence on such run-time unit.
8217 (not Tagged_Type_Expansion
8219 (RTU_Loaded
(Ada_Tags
)
8220 and then Nkind
(Prefix
(N
)) = N_Selected_Component
8221 and then Present
(Entity
(Selector_Name
(Prefix
(N
))))
8222 and then Entity
(Selector_Name
(Prefix
(N
))) =
8223 RTE_Record_Component
(RE_Prims_Ptr
)))
8225 Apply_Range_Check
(Drange
, Etype
(Index
));
8229 Set_Slice_Subtype
(N
);
8231 if Nkind
(Drange
) = N_Range
then
8232 Warn_On_Suspicious_Index
(Name
, Low_Bound
(Drange
));
8233 Warn_On_Suspicious_Index
(Name
, High_Bound
(Drange
));
8239 ----------------------------
8240 -- Resolve_String_Literal --
8241 ----------------------------
8243 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
8244 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
8245 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
8246 Loc
: constant Source_Ptr
:= Sloc
(N
);
8247 Str
: constant String_Id
:= Strval
(N
);
8248 Strlen
: constant Nat
:= String_Length
(Str
);
8249 Subtype_Id
: Entity_Id
;
8250 Need_Check
: Boolean;
8253 -- For a string appearing in a concatenation, defer creation of the
8254 -- string_literal_subtype until the end of the resolution of the
8255 -- concatenation, because the literal may be constant-folded away. This
8256 -- is a useful optimization for long concatenation expressions.
8258 -- If the string is an aggregate built for a single character (which
8259 -- happens in a non-static context) or a is null string to which special
8260 -- checks may apply, we build the subtype. Wide strings must also get a
8261 -- string subtype if they come from a one character aggregate. Strings
8262 -- generated by attributes might be static, but it is often hard to
8263 -- determine whether the enclosing context is static, so we generate
8264 -- subtypes for them as well, thus losing some rarer optimizations ???
8265 -- Same for strings that come from a static conversion.
8268 (Strlen
= 0 and then Typ
/= Standard_String
)
8269 or else Nkind
(Parent
(N
)) /= N_Op_Concat
8270 or else (N
/= Left_Opnd
(Parent
(N
))
8271 and then N
/= Right_Opnd
(Parent
(N
)))
8272 or else ((Typ
= Standard_Wide_String
8273 or else Typ
= Standard_Wide_Wide_String
)
8274 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
8276 -- If the resolving type is itself a string literal subtype, we can just
8277 -- reuse it, since there is no point in creating another.
8279 if Ekind
(Typ
) = E_String_Literal_Subtype
then
8282 elsif Nkind
(Parent
(N
)) = N_Op_Concat
8283 and then not Need_Check
8284 and then not Nkind_In
(Original_Node
(N
), N_Character_Literal
,
8285 N_Attribute_Reference
,
8286 N_Qualified_Expression
,
8291 -- Otherwise we must create a string literal subtype. Note that the
8292 -- whole idea of string literal subtypes is simply to avoid the need
8293 -- for building a full fledged array subtype for each literal.
8296 Set_String_Literal_Subtype
(N
, Typ
);
8297 Subtype_Id
:= Etype
(N
);
8300 if Nkind
(Parent
(N
)) /= N_Op_Concat
8303 Set_Etype
(N
, Subtype_Id
);
8304 Eval_String_Literal
(N
);
8307 if Is_Limited_Composite
(Typ
)
8308 or else Is_Private_Composite
(Typ
)
8310 Error_Msg_N
("string literal not available for private array", N
);
8311 Set_Etype
(N
, Any_Type
);
8315 -- The validity of a null string has been checked in the call to
8316 -- Eval_String_Literal.
8321 -- Always accept string literal with component type Any_Character, which
8322 -- occurs in error situations and in comparisons of literals, both of
8323 -- which should accept all literals.
8325 elsif R_Typ
= Any_Character
then
8328 -- If the type is bit-packed, then we always transform the string
8329 -- literal into a full fledged aggregate.
8331 elsif Is_Bit_Packed_Array
(Typ
) then
8334 -- Deal with cases of Wide_Wide_String, Wide_String, and String
8337 -- For Standard.Wide_Wide_String, or any other type whose component
8338 -- type is Standard.Wide_Wide_Character, we know that all the
8339 -- characters in the string must be acceptable, since the parser
8340 -- accepted the characters as valid character literals.
8342 if R_Typ
= Standard_Wide_Wide_Character
then
8345 -- For the case of Standard.String, or any other type whose component
8346 -- type is Standard.Character, we must make sure that there are no
8347 -- wide characters in the string, i.e. that it is entirely composed
8348 -- of characters in range of type Character.
8350 -- If the string literal is the result of a static concatenation, the
8351 -- test has already been performed on the components, and need not be
8354 elsif R_Typ
= Standard_Character
8355 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
8357 for J
in 1 .. Strlen
loop
8358 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
8360 -- If we are out of range, post error. This is one of the
8361 -- very few places that we place the flag in the middle of
8362 -- a token, right under the offending wide character. Not
8363 -- quite clear if this is right wrt wide character encoding
8364 -- sequences, but it's only an error message!
8367 ("literal out of range of type Standard.Character",
8368 Source_Ptr
(Int
(Loc
) + J
));
8373 -- For the case of Standard.Wide_String, or any other type whose
8374 -- component type is Standard.Wide_Character, we must make sure that
8375 -- there are no wide characters in the string, i.e. that it is
8376 -- entirely composed of characters in range of type Wide_Character.
8378 -- If the string literal is the result of a static concatenation,
8379 -- the test has already been performed on the components, and need
8382 elsif R_Typ
= Standard_Wide_Character
8383 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
8385 for J
in 1 .. Strlen
loop
8386 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
8388 -- If we are out of range, post error. This is one of the
8389 -- very few places that we place the flag in the middle of
8390 -- a token, right under the offending wide character.
8392 -- This is not quite right, because characters in general
8393 -- will take more than one character position ???
8396 ("literal out of range of type Standard.Wide_Character",
8397 Source_Ptr
(Int
(Loc
) + J
));
8402 -- If the root type is not a standard character, then we will convert
8403 -- the string into an aggregate and will let the aggregate code do
8404 -- the checking. Standard Wide_Wide_Character is also OK here.
8410 -- See if the component type of the array corresponding to the string
8411 -- has compile time known bounds. If yes we can directly check
8412 -- whether the evaluation of the string will raise constraint error.
8413 -- Otherwise we need to transform the string literal into the
8414 -- corresponding character aggregate and let the aggregate
8415 -- code do the checking.
8417 if Is_Standard_Character_Type
(R_Typ
) then
8419 -- Check for the case of full range, where we are definitely OK
8421 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
8425 -- Here the range is not the complete base type range, so check
8428 Comp_Typ_Lo
: constant Node_Id
:=
8429 Type_Low_Bound
(Component_Type
(Typ
));
8430 Comp_Typ_Hi
: constant Node_Id
:=
8431 Type_High_Bound
(Component_Type
(Typ
));
8436 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
8437 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
8439 for J
in 1 .. Strlen
loop
8440 Char_Val
:= UI_From_Int
(Int
(Get_String_Char
(Str
, J
)));
8442 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
8443 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
8445 Apply_Compile_Time_Constraint_Error
8446 (N
, "character out of range?", CE_Range_Check_Failed
,
8447 Loc
=> Source_Ptr
(Int
(Loc
) + J
));
8457 -- If we got here we meed to transform the string literal into the
8458 -- equivalent qualified positional array aggregate. This is rather
8459 -- heavy artillery for this situation, but it is hard work to avoid.
8462 Lits
: constant List_Id
:= New_List
;
8463 P
: Source_Ptr
:= Loc
+ 1;
8467 -- Build the character literals, we give them source locations that
8468 -- correspond to the string positions, which is a bit tricky given
8469 -- the possible presence of wide character escape sequences.
8471 for J
in 1 .. Strlen
loop
8472 C
:= Get_String_Char
(Str
, J
);
8473 Set_Character_Literal_Name
(C
);
8476 Make_Character_Literal
(P
,
8478 Char_Literal_Value
=> UI_From_CC
(C
)));
8480 if In_Character_Range
(C
) then
8483 -- Should we have a call to Skip_Wide here ???
8491 Make_Qualified_Expression
(Loc
,
8492 Subtype_Mark
=> New_Reference_To
(Typ
, Loc
),
8494 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
8496 Analyze_And_Resolve
(N
, Typ
);
8498 end Resolve_String_Literal
;
8500 -----------------------------
8501 -- Resolve_Subprogram_Info --
8502 -----------------------------
8504 procedure Resolve_Subprogram_Info
(N
: Node_Id
; Typ
: Entity_Id
) is
8507 end Resolve_Subprogram_Info
;
8509 -----------------------------
8510 -- Resolve_Type_Conversion --
8511 -----------------------------
8513 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
8514 Conv_OK
: constant Boolean := Conversion_OK
(N
);
8515 Operand
: constant Node_Id
:= Expression
(N
);
8516 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
8517 Target_Typ
: constant Entity_Id
:= Etype
(N
);
8524 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
8529 if Etype
(Operand
) = Any_Fixed
then
8531 -- Mixed-mode operation involving a literal. Context must be a fixed
8532 -- type which is applied to the literal subsequently.
8534 if Is_Fixed_Point_Type
(Typ
) then
8535 Set_Etype
(Operand
, Universal_Real
);
8537 elsif Is_Numeric_Type
(Typ
)
8538 and then Nkind_In
(Operand
, N_Op_Multiply
, N_Op_Divide
)
8539 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
8541 Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
8543 -- Return if expression is ambiguous
8545 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
8548 -- If nothing else, the available fixed type is Duration
8551 Set_Etype
(Operand
, Standard_Duration
);
8554 -- Resolve the real operand with largest available precision
8556 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
8557 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
8559 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
8562 Resolve
(Rop
, Universal_Real
);
8564 -- If the operand is a literal (it could be a non-static and
8565 -- illegal exponentiation) check whether the use of Duration
8566 -- is potentially inaccurate.
8568 if Nkind
(Rop
) = N_Real_Literal
8569 and then Realval
(Rop
) /= Ureal_0
8570 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
8573 ("?universal real operand can only " &
8574 "be interpreted as Duration!",
8577 ("\?precision will be lost in the conversion!", Rop
);
8580 elsif Is_Numeric_Type
(Typ
)
8581 and then Nkind
(Operand
) in N_Op
8582 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
8584 Set_Etype
(Operand
, Standard_Duration
);
8587 Error_Msg_N
("invalid context for mixed mode operation", N
);
8588 Set_Etype
(Operand
, Any_Type
);
8595 -- Note: we do the Eval_Type_Conversion call before applying the
8596 -- required checks for a subtype conversion. This is important, since
8597 -- both are prepared under certain circumstances to change the type
8598 -- conversion to a constraint error node, but in the case of
8599 -- Eval_Type_Conversion this may reflect an illegality in the static
8600 -- case, and we would miss the illegality (getting only a warning
8601 -- message), if we applied the type conversion checks first.
8603 Eval_Type_Conversion
(N
);
8605 -- Even when evaluation is not possible, we may be able to simplify the
8606 -- conversion or its expression. This needs to be done before applying
8607 -- checks, since otherwise the checks may use the original expression
8608 -- and defeat the simplifications. This is specifically the case for
8609 -- elimination of the floating-point Truncation attribute in
8610 -- float-to-int conversions.
8612 Simplify_Type_Conversion
(N
);
8614 -- If after evaluation we still have a type conversion, then we may need
8615 -- to apply checks required for a subtype conversion.
8617 -- Skip these type conversion checks if universal fixed operands
8618 -- operands involved, since range checks are handled separately for
8619 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
8621 if Nkind
(N
) = N_Type_Conversion
8622 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
8623 and then Target_Typ
/= Universal_Fixed
8624 and then Operand_Typ
/= Universal_Fixed
8626 Apply_Type_Conversion_Checks
(N
);
8629 -- Issue warning for conversion of simple object to its own type. We
8630 -- have to test the original nodes, since they may have been rewritten
8631 -- by various optimizations.
8633 Orig_N
:= Original_Node
(N
);
8635 if Warn_On_Redundant_Constructs
8636 and then Comes_From_Source
(Orig_N
)
8637 and then Nkind
(Orig_N
) = N_Type_Conversion
8638 and then not In_Instance
8640 Orig_N
:= Original_Node
(Expression
(Orig_N
));
8641 Orig_T
:= Target_Typ
;
8643 -- If the node is part of a larger expression, the Target_Type
8644 -- may not be the original type of the node if the context is a
8645 -- condition. Recover original type to see if conversion is needed.
8647 if Is_Boolean_Type
(Orig_T
)
8648 and then Nkind
(Parent
(N
)) in N_Op
8650 Orig_T
:= Etype
(Parent
(N
));
8653 if Is_Entity_Name
(Orig_N
)
8655 (Etype
(Entity
(Orig_N
)) = Orig_T
8657 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
8658 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
)))))
8660 -- One more check, do not give warning if the analyzed conversion
8661 -- has an expression with non-static bounds, and the bounds of the
8662 -- target are static. This avoids junk warnings in cases where the
8663 -- conversion is necessary to establish staticness, for example in
8664 -- a case statement.
8666 if not Is_OK_Static_Subtype
(Operand_Typ
)
8667 and then Is_OK_Static_Subtype
(Target_Typ
)
8671 -- Here we give the redundant conversion warning
8674 Error_Msg_Node_2
:= Orig_T
;
8675 Error_Msg_NE
-- CODEFIX
8676 ("?redundant conversion, & is of type &!",
8677 N
, Entity
(Orig_N
));
8682 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
8683 -- No need to perform any interface conversion if the type of the
8684 -- expression coincides with the target type.
8686 if Ada_Version
>= Ada_05
8687 and then Expander_Active
8688 and then Operand_Typ
/= Target_Typ
8691 Opnd
: Entity_Id
:= Operand_Typ
;
8692 Target
: Entity_Id
:= Target_Typ
;
8695 if Is_Access_Type
(Opnd
) then
8696 Opnd
:= Designated_Type
(Opnd
);
8699 if Is_Access_Type
(Target_Typ
) then
8700 Target
:= Designated_Type
(Target
);
8703 if Opnd
= Target
then
8706 -- Conversion from interface type
8708 elsif Is_Interface
(Opnd
) then
8710 -- Ada 2005 (AI-217): Handle entities from limited views
8712 if From_With_Type
(Opnd
) then
8713 Error_Msg_Qual_Level
:= 99;
8714 Error_Msg_NE
-- CODEFIX
8715 ("missing WITH clause on package &", N
,
8716 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
8718 ("type conversions require visibility of the full view",
8721 elsif From_With_Type
(Target
)
8723 (Is_Access_Type
(Target_Typ
)
8724 and then Present
(Non_Limited_View
(Etype
(Target
))))
8726 Error_Msg_Qual_Level
:= 99;
8727 Error_Msg_NE
-- CODEFIX
8728 ("missing WITH clause on package &", N
,
8729 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
8731 ("type conversions require visibility of the full view",
8735 Expand_Interface_Conversion
(N
, Is_Static
=> False);
8738 -- Conversion to interface type
8740 elsif Is_Interface
(Target
) then
8744 if Ekind_In
(Opnd
, E_Protected_Subtype
, E_Task_Subtype
) then
8745 Opnd
:= Etype
(Opnd
);
8748 if not Interface_Present_In_Ancestor
8752 if Is_Class_Wide_Type
(Opnd
) then
8754 -- The static analysis is not enough to know if the
8755 -- interface is implemented or not. Hence we must pass
8756 -- the work to the expander to generate code to evaluate
8757 -- the conversion at run-time.
8759 Expand_Interface_Conversion
(N
, Is_Static
=> False);
8762 Error_Msg_Name_1
:= Chars
(Etype
(Target
));
8763 Error_Msg_Name_2
:= Chars
(Opnd
);
8765 ("wrong interface conversion (% is not a progenitor " &
8770 Expand_Interface_Conversion
(N
);
8775 end Resolve_Type_Conversion
;
8777 ----------------------
8778 -- Resolve_Unary_Op --
8779 ----------------------
8781 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
8782 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
8783 R
: constant Node_Id
:= Right_Opnd
(N
);
8789 -- Deal with intrinsic unary operators
8791 if Comes_From_Source
(N
)
8792 and then Ekind
(Entity
(N
)) = E_Function
8793 and then Is_Imported
(Entity
(N
))
8794 and then Is_Intrinsic_Subprogram
(Entity
(N
))
8796 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
8800 -- Deal with universal cases
8802 if Etype
(R
) = Universal_Integer
8804 Etype
(R
) = Universal_Real
8806 Check_For_Visible_Operator
(N
, B_Typ
);
8809 Set_Etype
(N
, B_Typ
);
8812 -- Generate warning for expressions like abs (x mod 2)
8814 if Warn_On_Redundant_Constructs
8815 and then Nkind
(N
) = N_Op_Abs
8817 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
8819 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
8820 Error_Msg_N
-- CODEFIX
8821 ("?abs applied to known non-negative value has no effect", N
);
8825 -- Deal with reference generation
8827 Check_Unset_Reference
(R
);
8828 Generate_Operator_Reference
(N
, B_Typ
);
8831 -- Set overflow checking bit. Much cleverer code needed here eventually
8832 -- and perhaps the Resolve routines should be separated for the various
8833 -- arithmetic operations, since they will need different processing ???
8835 if Nkind
(N
) in N_Op
then
8836 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
8837 Enable_Overflow_Check
(N
);
8841 -- Generate warning for expressions like -5 mod 3 for integers. No need
8842 -- to worry in the floating-point case, since parens do not affect the
8843 -- result so there is no point in giving in a warning.
8846 Norig
: constant Node_Id
:= Original_Node
(N
);
8855 if Warn_On_Questionable_Missing_Parens
8856 and then Comes_From_Source
(Norig
)
8857 and then Is_Integer_Type
(Typ
)
8858 and then Nkind
(Norig
) = N_Op_Minus
8860 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
8862 -- We are looking for cases where the right operand is not
8863 -- parenthesized, and is a binary operator, multiply, divide, or
8864 -- mod. These are the cases where the grouping can affect results.
8866 if Paren_Count
(Rorig
) = 0
8867 and then Nkind_In
(Rorig
, N_Op_Mod
, N_Op_Multiply
, N_Op_Divide
)
8869 -- For mod, we always give the warning, since the value is
8870 -- affected by the parenthesization (e.g. (-5) mod 315 /=
8871 -- -(5 mod 315)). But for the other cases, the only concern is
8872 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
8873 -- overflows, but (-2) * 64 does not). So we try to give the
8874 -- message only when overflow is possible.
8876 if Nkind
(Rorig
) /= N_Op_Mod
8877 and then Compile_Time_Known_Value
(R
)
8879 Val
:= Expr_Value
(R
);
8881 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
8882 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
8884 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
8887 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
8888 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
8890 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
8893 -- Note that the test below is deliberately excluding the
8894 -- largest negative number, since that is a potentially
8895 -- troublesome case (e.g. -2 * x, where the result is the
8896 -- largest negative integer has an overflow with 2 * x).
8898 if Val
> LB
and then Val
<= HB
then
8903 -- For the multiplication case, the only case we have to worry
8904 -- about is when (-a)*b is exactly the largest negative number
8905 -- so that -(a*b) can cause overflow. This can only happen if
8906 -- a is a power of 2, and more generally if any operand is a
8907 -- constant that is not a power of 2, then the parentheses
8908 -- cannot affect whether overflow occurs. We only bother to
8909 -- test the left most operand
8911 -- Loop looking at left operands for one that has known value
8914 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
8915 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
8916 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
8918 -- Operand value of 0 or 1 skips warning
8923 -- Otherwise check power of 2, if power of 2, warn, if
8924 -- anything else, skip warning.
8927 while Lval
/= 2 loop
8928 if Lval
mod 2 = 1 then
8939 -- Keep looking at left operands
8941 Opnd
:= Left_Opnd
(Opnd
);
8944 -- For rem or "/" we can only have a problematic situation
8945 -- if the divisor has a value of minus one or one. Otherwise
8946 -- overflow is impossible (divisor > 1) or we have a case of
8947 -- division by zero in any case.
8949 if Nkind_In
(Rorig
, N_Op_Divide
, N_Op_Rem
)
8950 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
8951 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
8956 -- If we fall through warning should be issued
8959 ("?unary minus expression should be parenthesized here!", N
);
8963 end Resolve_Unary_Op
;
8965 ----------------------------------
8966 -- Resolve_Unchecked_Expression --
8967 ----------------------------------
8969 procedure Resolve_Unchecked_Expression
8974 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
8976 end Resolve_Unchecked_Expression
;
8978 ---------------------------------------
8979 -- Resolve_Unchecked_Type_Conversion --
8980 ---------------------------------------
8982 procedure Resolve_Unchecked_Type_Conversion
8986 pragma Warnings
(Off
, Typ
);
8988 Operand
: constant Node_Id
:= Expression
(N
);
8989 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
8992 -- Resolve operand using its own type
8994 Resolve
(Operand
, Opnd_Type
);
8995 Eval_Unchecked_Conversion
(N
);
8997 end Resolve_Unchecked_Type_Conversion
;
8999 ------------------------------
9000 -- Rewrite_Operator_As_Call --
9001 ------------------------------
9003 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
9004 Loc
: constant Source_Ptr
:= Sloc
(N
);
9005 Actuals
: constant List_Id
:= New_List
;
9009 if Nkind
(N
) in N_Binary_Op
then
9010 Append
(Left_Opnd
(N
), Actuals
);
9013 Append
(Right_Opnd
(N
), Actuals
);
9016 Make_Function_Call
(Sloc
=> Loc
,
9017 Name
=> New_Occurrence_Of
(Nam
, Loc
),
9018 Parameter_Associations
=> Actuals
);
9020 Preserve_Comes_From_Source
(New_N
, N
);
9021 Preserve_Comes_From_Source
(Name
(New_N
), N
);
9023 Set_Etype
(N
, Etype
(Nam
));
9024 end Rewrite_Operator_As_Call
;
9026 ------------------------------
9027 -- Rewrite_Renamed_Operator --
9028 ------------------------------
9030 procedure Rewrite_Renamed_Operator
9035 Nam
: constant Name_Id
:= Chars
(Op
);
9036 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
9040 -- Rewrite the operator node using the real operator, not its renaming.
9041 -- Exclude user-defined intrinsic operations of the same name, which are
9042 -- treated separately and rewritten as calls.
9044 if Ekind
(Op
) /= E_Function
or else Chars
(N
) /= Nam
then
9045 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
9046 Set_Chars
(Op_Node
, Nam
);
9047 Set_Etype
(Op_Node
, Etype
(N
));
9048 Set_Entity
(Op_Node
, Op
);
9049 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
9051 -- Indicate that both the original entity and its renaming are
9052 -- referenced at this point.
9054 Generate_Reference
(Entity
(N
), N
);
9055 Generate_Reference
(Op
, N
);
9058 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
9061 Rewrite
(N
, Op_Node
);
9063 -- If the context type is private, add the appropriate conversions
9064 -- so that the operator is applied to the full view. This is done
9065 -- in the routines that resolve intrinsic operators,
9067 if Is_Intrinsic_Subprogram
(Op
)
9068 and then Is_Private_Type
(Typ
)
9071 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
9072 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
9073 Resolve_Intrinsic_Operator
(N
, Typ
);
9075 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
9076 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
9083 elsif Ekind
(Op
) = E_Function
and then Is_Intrinsic_Subprogram
(Op
) then
9085 -- Operator renames a user-defined operator of the same name. Use
9086 -- the original operator in the node, which is the one that Gigi
9090 Set_Is_Overloaded
(N
, False);
9092 end Rewrite_Renamed_Operator
;
9094 -----------------------
9095 -- Set_Slice_Subtype --
9096 -----------------------
9098 -- Build an implicit subtype declaration to represent the type delivered
9099 -- by the slice. This is an abbreviated version of an array subtype. We
9100 -- define an index subtype for the slice, using either the subtype name
9101 -- or the discrete range of the slice. To be consistent with index usage
9102 -- elsewhere, we create a list header to hold the single index. This list
9103 -- is not otherwise attached to the syntax tree.
9105 procedure Set_Slice_Subtype
(N
: Node_Id
) is
9106 Loc
: constant Source_Ptr
:= Sloc
(N
);
9107 Index_List
: constant List_Id
:= New_List
;
9109 Index_Subtype
: Entity_Id
;
9110 Index_Type
: Entity_Id
;
9111 Slice_Subtype
: Entity_Id
;
9112 Drange
: constant Node_Id
:= Discrete_Range
(N
);
9115 if Is_Entity_Name
(Drange
) then
9116 Index_Subtype
:= Entity
(Drange
);
9119 -- We force the evaluation of a range. This is definitely needed in
9120 -- the renamed case, and seems safer to do unconditionally. Note in
9121 -- any case that since we will create and insert an Itype referring
9122 -- to this range, we must make sure any side effect removal actions
9123 -- are inserted before the Itype definition.
9125 if Nkind
(Drange
) = N_Range
then
9126 Force_Evaluation
(Low_Bound
(Drange
));
9127 Force_Evaluation
(High_Bound
(Drange
));
9130 Index_Type
:= Base_Type
(Etype
(Drange
));
9132 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
9134 -- Take a new copy of Drange (where bounds have been rewritten to
9135 -- reference side-effect-vree names). Using a separate tree ensures
9136 -- that further expansion (e.g while rewriting a slice assignment
9137 -- into a FOR loop) does not attempt to remove side effects on the
9138 -- bounds again (which would cause the bounds in the index subtype
9139 -- definition to refer to temporaries before they are defined) (the
9140 -- reason is that some names are considered side effect free here
9141 -- for the subtype, but not in the context of a loop iteration
9144 Set_Scalar_Range
(Index_Subtype
, New_Copy_Tree
(Drange
));
9145 Set_Etype
(Index_Subtype
, Index_Type
);
9146 Set_Size_Info
(Index_Subtype
, Index_Type
);
9147 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
9150 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
9152 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
9153 Set_Etype
(Index
, Index_Subtype
);
9154 Append
(Index
, Index_List
);
9156 Set_First_Index
(Slice_Subtype
, Index
);
9157 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
9158 Set_Is_Constrained
(Slice_Subtype
, True);
9160 Check_Compile_Time_Size
(Slice_Subtype
);
9162 -- The Etype of the existing Slice node is reset to this slice subtype.
9163 -- Its bounds are obtained from its first index.
9165 Set_Etype
(N
, Slice_Subtype
);
9167 -- For packed slice subtypes, freeze immediately (except in the
9168 -- case of being in a "spec expression" where we never freeze
9169 -- when we first see the expression).
9171 if Is_Packed
(Slice_Subtype
) and not In_Spec_Expression
then
9172 Freeze_Itype
(Slice_Subtype
, N
);
9174 -- For all other cases insert an itype reference in the slice's actions
9175 -- so that the itype is frozen at the proper place in the tree (i.e. at
9176 -- the point where actions for the slice are analyzed). Note that this
9177 -- is different from freezing the itype immediately, which might be
9178 -- premature (e.g. if the slice is within a transient scope).
9181 Ensure_Defined
(Typ
=> Slice_Subtype
, N
=> N
);
9183 end Set_Slice_Subtype
;
9185 --------------------------------
9186 -- Set_String_Literal_Subtype --
9187 --------------------------------
9189 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
9190 Loc
: constant Source_Ptr
:= Sloc
(N
);
9191 Low_Bound
: constant Node_Id
:=
9192 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
9193 Subtype_Id
: Entity_Id
;
9196 if Nkind
(N
) /= N_String_Literal
then
9200 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
9201 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
9202 (String_Length
(Strval
(N
))));
9203 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
9204 Set_Is_Constrained
(Subtype_Id
);
9205 Set_Etype
(N
, Subtype_Id
);
9207 if Is_OK_Static_Expression
(Low_Bound
) then
9209 -- The low bound is set from the low bound of the corresponding
9210 -- index type. Note that we do not store the high bound in the
9211 -- string literal subtype, but it can be deduced if necessary
9212 -- from the length and the low bound.
9214 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
9217 Set_String_Literal_Low_Bound
9218 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
9219 Set_Etype
(String_Literal_Low_Bound
(Subtype_Id
), Standard_Positive
);
9221 -- Build bona fide subtype for the string, and wrap it in an
9222 -- unchecked conversion, because the backend expects the
9223 -- String_Literal_Subtype to have a static lower bound.
9226 Index_List
: constant List_Id
:= New_List
;
9227 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
9228 High_Bound
: constant Node_Id
:=
9230 Left_Opnd
=> New_Copy_Tree
(Low_Bound
),
9232 Make_Integer_Literal
(Loc
,
9233 String_Length
(Strval
(N
)) - 1));
9234 Array_Subtype
: Entity_Id
;
9235 Index_Subtype
: Entity_Id
;
9241 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
9242 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
9243 Set_Scalar_Range
(Index_Subtype
, Drange
);
9244 Set_Parent
(Drange
, N
);
9245 Analyze_And_Resolve
(Drange
, Index_Type
);
9247 -- In the context, the Index_Type may already have a constraint,
9248 -- so use common base type on string subtype. The base type may
9249 -- be used when generating attributes of the string, for example
9250 -- in the context of a slice assignment.
9252 Set_Etype
(Index_Subtype
, Base_Type
(Index_Type
));
9253 Set_Size_Info
(Index_Subtype
, Index_Type
);
9254 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
9256 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
9258 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
9259 Set_Etype
(Index
, Index_Subtype
);
9260 Append
(Index
, Index_List
);
9262 Set_First_Index
(Array_Subtype
, Index
);
9263 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
9264 Set_Is_Constrained
(Array_Subtype
, True);
9267 Make_Unchecked_Type_Conversion
(Loc
,
9268 Subtype_Mark
=> New_Occurrence_Of
(Array_Subtype
, Loc
),
9269 Expression
=> Relocate_Node
(N
)));
9270 Set_Etype
(N
, Array_Subtype
);
9273 end Set_String_Literal_Subtype
;
9275 ------------------------------
9276 -- Simplify_Type_Conversion --
9277 ------------------------------
9279 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
9281 if Nkind
(N
) = N_Type_Conversion
then
9283 Operand
: constant Node_Id
:= Expression
(N
);
9284 Target_Typ
: constant Entity_Id
:= Etype
(N
);
9285 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
9288 if Is_Floating_Point_Type
(Opnd_Typ
)
9290 (Is_Integer_Type
(Target_Typ
)
9291 or else (Is_Fixed_Point_Type
(Target_Typ
)
9292 and then Conversion_OK
(N
)))
9293 and then Nkind
(Operand
) = N_Attribute_Reference
9294 and then Attribute_Name
(Operand
) = Name_Truncation
9296 -- Special processing required if the conversion is the expression
9297 -- of a Truncation attribute reference. In this case we replace:
9299 -- ityp (ftyp'Truncation (x))
9305 -- with the Float_Truncate flag set, which is more efficient
9309 Relocate_Node
(First
(Expressions
(Operand
))));
9310 Set_Float_Truncate
(N
, True);
9314 end Simplify_Type_Conversion
;
9316 -----------------------------
9317 -- Unique_Fixed_Point_Type --
9318 -----------------------------
9320 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
9321 T1
: Entity_Id
:= Empty
;
9326 procedure Fixed_Point_Error
;
9327 -- Give error messages for true ambiguity. Messages are posted on node
9328 -- N, and entities T1, T2 are the possible interpretations.
9330 -----------------------
9331 -- Fixed_Point_Error --
9332 -----------------------
9334 procedure Fixed_Point_Error
is
9336 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
9337 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
9338 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
9339 end Fixed_Point_Error
;
9341 -- Start of processing for Unique_Fixed_Point_Type
9344 -- The operations on Duration are visible, so Duration is always a
9345 -- possible interpretation.
9347 T1
:= Standard_Duration
;
9349 -- Look for fixed-point types in enclosing scopes
9351 Scop
:= Current_Scope
;
9352 while Scop
/= Standard_Standard
loop
9353 T2
:= First_Entity
(Scop
);
9354 while Present
(T2
) loop
9355 if Is_Fixed_Point_Type
(T2
)
9356 and then Current_Entity
(T2
) = T2
9357 and then Scope
(Base_Type
(T2
)) = Scop
9359 if Present
(T1
) then
9370 Scop
:= Scope
(Scop
);
9373 -- Look for visible fixed type declarations in the context
9375 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
9376 while Present
(Item
) loop
9377 if Nkind
(Item
) = N_With_Clause
then
9378 Scop
:= Entity
(Name
(Item
));
9379 T2
:= First_Entity
(Scop
);
9380 while Present
(T2
) loop
9381 if Is_Fixed_Point_Type
(T2
)
9382 and then Scope
(Base_Type
(T2
)) = Scop
9383 and then (Is_Potentially_Use_Visible
(T2
)
9384 or else In_Use
(T2
))
9386 if Present
(T1
) then
9401 if Nkind
(N
) = N_Real_Literal
then
9402 Error_Msg_NE
("?real literal interpreted as }!", N
, T1
);
9404 Error_Msg_NE
("?universal_fixed expression interpreted as }!", N
, T1
);
9408 end Unique_Fixed_Point_Type
;
9410 ----------------------
9411 -- Valid_Conversion --
9412 ----------------------
9414 function Valid_Conversion
9417 Operand
: Node_Id
) return Boolean
9419 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
9420 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
9422 function Conversion_Check
9424 Msg
: String) return Boolean;
9425 -- Little routine to post Msg if Valid is False, returns Valid value
9427 function Valid_Tagged_Conversion
9428 (Target_Type
: Entity_Id
;
9429 Opnd_Type
: Entity_Id
) return Boolean;
9430 -- Specifically test for validity of tagged conversions
9432 function Valid_Array_Conversion
return Boolean;
9433 -- Check index and component conformance, and accessibility levels
9434 -- if the component types are anonymous access types (Ada 2005)
9436 ----------------------
9437 -- Conversion_Check --
9438 ----------------------
9440 function Conversion_Check
9442 Msg
: String) return Boolean
9446 Error_Msg_N
(Msg
, Operand
);
9450 end Conversion_Check
;
9452 ----------------------------
9453 -- Valid_Array_Conversion --
9454 ----------------------------
9456 function Valid_Array_Conversion
return Boolean
9458 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
9459 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
9461 Opnd_Index
: Node_Id
;
9462 Opnd_Index_Type
: Entity_Id
;
9464 Target_Comp_Type
: constant Entity_Id
:=
9465 Component_Type
(Target_Type
);
9466 Target_Comp_Base
: constant Entity_Id
:=
9467 Base_Type
(Target_Comp_Type
);
9469 Target_Index
: Node_Id
;
9470 Target_Index_Type
: Entity_Id
;
9473 -- Error if wrong number of dimensions
9476 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
9479 ("incompatible number of dimensions for conversion", Operand
);
9482 -- Number of dimensions matches
9485 -- Loop through indexes of the two arrays
9487 Target_Index
:= First_Index
(Target_Type
);
9488 Opnd_Index
:= First_Index
(Opnd_Type
);
9489 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
9490 Target_Index_Type
:= Etype
(Target_Index
);
9491 Opnd_Index_Type
:= Etype
(Opnd_Index
);
9493 -- Error if index types are incompatible
9495 if not (Is_Integer_Type
(Target_Index_Type
)
9496 and then Is_Integer_Type
(Opnd_Index_Type
))
9497 and then (Root_Type
(Target_Index_Type
)
9498 /= Root_Type
(Opnd_Index_Type
))
9501 ("incompatible index types for array conversion",
9506 Next_Index
(Target_Index
);
9507 Next_Index
(Opnd_Index
);
9510 -- If component types have same base type, all set
9512 if Target_Comp_Base
= Opnd_Comp_Base
then
9515 -- Here if base types of components are not the same. The only
9516 -- time this is allowed is if we have anonymous access types.
9518 -- The conversion of arrays of anonymous access types can lead
9519 -- to dangling pointers. AI-392 formalizes the accessibility
9520 -- checks that must be applied to such conversions to prevent
9521 -- out-of-scope references.
9524 Ekind_In
(Target_Comp_Base
, E_Anonymous_Access_Type
,
9525 E_Anonymous_Access_Subprogram_Type
)
9526 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
9528 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
9530 if Type_Access_Level
(Target_Type
) <
9531 Type_Access_Level
(Opnd_Type
)
9533 if In_Instance_Body
then
9534 Error_Msg_N
("?source array type " &
9535 "has deeper accessibility level than target", Operand
);
9536 Error_Msg_N
("\?Program_Error will be raised at run time",
9539 Make_Raise_Program_Error
(Sloc
(N
),
9540 Reason
=> PE_Accessibility_Check_Failed
));
9541 Set_Etype
(N
, Target_Type
);
9544 -- Conversion not allowed because of accessibility levels
9547 Error_Msg_N
("source array type " &
9548 "has deeper accessibility level than target", Operand
);
9555 -- All other cases where component base types do not match
9559 ("incompatible component types for array conversion",
9564 -- Check that component subtypes statically match. For numeric
9565 -- types this means that both must be either constrained or
9566 -- unconstrained. For enumeration types the bounds must match.
9567 -- All of this is checked in Subtypes_Statically_Match.
9569 if not Subtypes_Statically_Match
9570 (Target_Comp_Type
, Opnd_Comp_Type
)
9573 ("component subtypes must statically match", Operand
);
9579 end Valid_Array_Conversion
;
9581 -----------------------------
9582 -- Valid_Tagged_Conversion --
9583 -----------------------------
9585 function Valid_Tagged_Conversion
9586 (Target_Type
: Entity_Id
;
9587 Opnd_Type
: Entity_Id
) return Boolean
9590 -- Upward conversions are allowed (RM 4.6(22))
9592 if Covers
(Target_Type
, Opnd_Type
)
9593 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
9597 -- Downward conversion are allowed if the operand is class-wide
9600 elsif Is_Class_Wide_Type
(Opnd_Type
)
9601 and then Covers
(Opnd_Type
, Target_Type
)
9605 elsif Covers
(Opnd_Type
, Target_Type
)
9606 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
9609 Conversion_Check
(False,
9610 "downward conversion of tagged objects not allowed");
9612 -- Ada 2005 (AI-251): The conversion to/from interface types is
9615 elsif Is_Interface
(Target_Type
) or else Is_Interface
(Opnd_Type
) then
9618 -- If the operand is a class-wide type obtained through a limited_
9619 -- with clause, and the context includes the non-limited view, use
9620 -- it to determine whether the conversion is legal.
9622 elsif Is_Class_Wide_Type
(Opnd_Type
)
9623 and then From_With_Type
(Opnd_Type
)
9624 and then Present
(Non_Limited_View
(Etype
(Opnd_Type
)))
9625 and then Is_Interface
(Non_Limited_View
(Etype
(Opnd_Type
)))
9629 elsif Is_Access_Type
(Opnd_Type
)
9630 and then Is_Interface
(Directly_Designated_Type
(Opnd_Type
))
9636 ("invalid tagged conversion, not compatible with}",
9637 N
, First_Subtype
(Opnd_Type
));
9640 end Valid_Tagged_Conversion
;
9642 -- Start of processing for Valid_Conversion
9645 Check_Parameterless_Call
(Operand
);
9647 if Is_Overloaded
(Operand
) then
9657 -- Remove procedure calls, which syntactically cannot appear in
9658 -- this context, but which cannot be removed by type checking,
9659 -- because the context does not impose a type.
9661 -- When compiling for VMS, spurious ambiguities can be produced
9662 -- when arithmetic operations have a literal operand and return
9663 -- System.Address or a descendant of it. These ambiguities are
9664 -- otherwise resolved by the context, but for conversions there
9665 -- is no context type and the removal of the spurious operations
9666 -- must be done explicitly here.
9668 -- The node may be labelled overloaded, but still contain only
9669 -- one interpretation because others were discarded in previous
9670 -- filters. If this is the case, retain the single interpretation
9673 Get_First_Interp
(Operand
, I
, It
);
9674 Opnd_Type
:= It
.Typ
;
9675 Get_Next_Interp
(I
, It
);
9678 and then Opnd_Type
/= Standard_Void_Type
9680 -- More than one candidate interpretation is available
9682 Get_First_Interp
(Operand
, I
, It
);
9683 while Present
(It
.Typ
) loop
9684 if It
.Typ
= Standard_Void_Type
then
9688 if Present
(System_Aux_Id
)
9689 and then Is_Descendent_Of_Address
(It
.Typ
)
9694 Get_Next_Interp
(I
, It
);
9698 Get_First_Interp
(Operand
, I
, It
);
9703 Error_Msg_N
("illegal operand in conversion", Operand
);
9707 Get_Next_Interp
(I
, It
);
9709 if Present
(It
.Typ
) then
9712 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
9714 if It1
= No_Interp
then
9715 Error_Msg_N
("ambiguous operand in conversion", Operand
);
9717 -- If the interpretation involves a standard operator, use
9718 -- the location of the type, which may be user-defined.
9720 if Sloc
(It
.Nam
) = Standard_Location
then
9721 Error_Msg_Sloc
:= Sloc
(It
.Typ
);
9723 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
9726 Error_Msg_N
-- CODEFIX
9727 ("\\possible interpretation#!", Operand
);
9729 if Sloc
(N1
) = Standard_Location
then
9730 Error_Msg_Sloc
:= Sloc
(T1
);
9732 Error_Msg_Sloc
:= Sloc
(N1
);
9735 Error_Msg_N
-- CODEFIX
9736 ("\\possible interpretation#!", Operand
);
9742 Set_Etype
(Operand
, It1
.Typ
);
9743 Opnd_Type
:= It1
.Typ
;
9749 if Is_Numeric_Type
(Target_Type
) then
9751 -- A universal fixed expression can be converted to any numeric type
9753 if Opnd_Type
= Universal_Fixed
then
9756 -- Also no need to check when in an instance or inlined body, because
9757 -- the legality has been established when the template was analyzed.
9758 -- Furthermore, numeric conversions may occur where only a private
9759 -- view of the operand type is visible at the instantiation point.
9760 -- This results in a spurious error if we check that the operand type
9761 -- is a numeric type.
9763 -- Note: in a previous version of this unit, the following tests were
9764 -- applied only for generated code (Comes_From_Source set to False),
9765 -- but in fact the test is required for source code as well, since
9766 -- this situation can arise in source code.
9768 elsif In_Instance
or else In_Inlined_Body
then
9771 -- Otherwise we need the conversion check
9774 return Conversion_Check
9775 (Is_Numeric_Type
(Opnd_Type
),
9776 "illegal operand for numeric conversion");
9781 elsif Is_Array_Type
(Target_Type
) then
9782 if not Is_Array_Type
(Opnd_Type
)
9783 or else Opnd_Type
= Any_Composite
9784 or else Opnd_Type
= Any_String
9787 ("illegal operand for array conversion", Operand
);
9790 return Valid_Array_Conversion
;
9793 -- Ada 2005 (AI-251): Anonymous access types where target references an
9796 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
9797 E_Anonymous_Access_Type
)
9798 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
9800 -- Check the static accessibility rule of 4.6(17). Note that the
9801 -- check is not enforced when within an instance body, since the
9802 -- RM requires such cases to be caught at run time.
9804 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
9805 if Type_Access_Level
(Opnd_Type
) >
9806 Type_Access_Level
(Target_Type
)
9808 -- In an instance, this is a run-time check, but one we know
9809 -- will fail, so generate an appropriate warning. The raise
9810 -- will be generated by Expand_N_Type_Conversion.
9812 if In_Instance_Body
then
9814 ("?cannot convert local pointer to non-local access type",
9817 ("\?Program_Error will be raised at run time", Operand
);
9820 ("cannot convert local pointer to non-local access type",
9825 -- Special accessibility checks are needed in the case of access
9826 -- discriminants declared for a limited type.
9828 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
9829 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
9831 -- When the operand is a selected access discriminant the check
9832 -- needs to be made against the level of the object denoted by
9833 -- the prefix of the selected name (Object_Access_Level handles
9834 -- checking the prefix of the operand for this case).
9836 if Nkind
(Operand
) = N_Selected_Component
9837 and then Object_Access_Level
(Operand
) >
9838 Type_Access_Level
(Target_Type
)
9840 -- In an instance, this is a run-time check, but one we know
9841 -- will fail, so generate an appropriate warning. The raise
9842 -- will be generated by Expand_N_Type_Conversion.
9844 if In_Instance_Body
then
9846 ("?cannot convert access discriminant to non-local" &
9847 " access type", Operand
);
9849 ("\?Program_Error will be raised at run time", Operand
);
9852 ("cannot convert access discriminant to non-local" &
9853 " access type", Operand
);
9858 -- The case of a reference to an access discriminant from
9859 -- within a limited type declaration (which will appear as
9860 -- a discriminal) is always illegal because the level of the
9861 -- discriminant is considered to be deeper than any (nameable)
9864 if Is_Entity_Name
(Operand
)
9865 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
9867 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
9868 and then Present
(Discriminal_Link
(Entity
(Operand
)))
9871 ("discriminant has deeper accessibility level than target",
9880 -- General and anonymous access types
9882 elsif Ekind_In
(Target_Type
, E_General_Access_Type
,
9883 E_Anonymous_Access_Type
)
9886 (Is_Access_Type
(Opnd_Type
)
9888 Ekind_In
(Opnd_Type
, E_Access_Subprogram_Type
,
9889 E_Access_Protected_Subprogram_Type
),
9890 "must be an access-to-object type")
9892 if Is_Access_Constant
(Opnd_Type
)
9893 and then not Is_Access_Constant
(Target_Type
)
9896 ("access-to-constant operand type not allowed", Operand
);
9900 -- Check the static accessibility rule of 4.6(17). Note that the
9901 -- check is not enforced when within an instance body, since the RM
9902 -- requires such cases to be caught at run time.
9904 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
9905 or else Is_Local_Anonymous_Access
(Target_Type
)
9907 if Type_Access_Level
(Opnd_Type
)
9908 > Type_Access_Level
(Target_Type
)
9910 -- In an instance, this is a run-time check, but one we know
9911 -- will fail, so generate an appropriate warning. The raise
9912 -- will be generated by Expand_N_Type_Conversion.
9914 if In_Instance_Body
then
9916 ("?cannot convert local pointer to non-local access type",
9919 ("\?Program_Error will be raised at run time", Operand
);
9922 -- Avoid generation of spurious error message
9924 if not Error_Posted
(N
) then
9926 ("cannot convert local pointer to non-local access type",
9933 -- Special accessibility checks are needed in the case of access
9934 -- discriminants declared for a limited type.
9936 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
9937 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
9939 -- When the operand is a selected access discriminant the check
9940 -- needs to be made against the level of the object denoted by
9941 -- the prefix of the selected name (Object_Access_Level handles
9942 -- checking the prefix of the operand for this case).
9944 if Nkind
(Operand
) = N_Selected_Component
9945 and then Object_Access_Level
(Operand
) >
9946 Type_Access_Level
(Target_Type
)
9948 -- In an instance, this is a run-time check, but one we know
9949 -- will fail, so generate an appropriate warning. The raise
9950 -- will be generated by Expand_N_Type_Conversion.
9952 if In_Instance_Body
then
9954 ("?cannot convert access discriminant to non-local" &
9955 " access type", Operand
);
9957 ("\?Program_Error will be raised at run time",
9962 ("cannot convert access discriminant to non-local" &
9963 " access type", Operand
);
9968 -- The case of a reference to an access discriminant from
9969 -- within a limited type declaration (which will appear as
9970 -- a discriminal) is always illegal because the level of the
9971 -- discriminant is considered to be deeper than any (nameable)
9974 if Is_Entity_Name
(Operand
)
9976 Ekind_In
(Entity
(Operand
), E_In_Parameter
, E_Constant
)
9977 and then Present
(Discriminal_Link
(Entity
(Operand
)))
9980 ("discriminant has deeper accessibility level than target",
9987 -- In the presence of limited_with clauses we have to use non-limited
9988 -- views, if available.
9990 Check_Limited
: declare
9991 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
9992 -- Helper function to handle limited views
9994 --------------------------
9995 -- Full_Designated_Type --
9996 --------------------------
9998 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
9999 Desig
: constant Entity_Id
:= Designated_Type
(T
);
10002 -- Handle the limited view of a type
10004 if Is_Incomplete_Type
(Desig
)
10005 and then From_With_Type
(Desig
)
10006 and then Present
(Non_Limited_View
(Desig
))
10008 return Available_View
(Desig
);
10012 end Full_Designated_Type
;
10014 -- Local Declarations
10016 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
10017 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
10019 Same_Base
: constant Boolean :=
10020 Base_Type
(Target
) = Base_Type
(Opnd
);
10022 -- Start of processing for Check_Limited
10025 if Is_Tagged_Type
(Target
) then
10026 return Valid_Tagged_Conversion
(Target
, Opnd
);
10029 if not Same_Base
then
10031 ("target designated type not compatible with }",
10032 N
, Base_Type
(Opnd
));
10035 -- Ada 2005 AI-384: legality rule is symmetric in both
10036 -- designated types. The conversion is legal (with possible
10037 -- constraint check) if either designated type is
10040 elsif Subtypes_Statically_Match
(Target
, Opnd
)
10042 (Has_Discriminants
(Target
)
10044 (not Is_Constrained
(Opnd
)
10045 or else not Is_Constrained
(Target
)))
10047 -- Special case, if Value_Size has been used to make the
10048 -- sizes different, the conversion is not allowed even
10049 -- though the subtypes statically match.
10051 if Known_Static_RM_Size
(Target
)
10052 and then Known_Static_RM_Size
(Opnd
)
10053 and then RM_Size
(Target
) /= RM_Size
(Opnd
)
10056 ("target designated subtype not compatible with }",
10059 ("\because sizes of the two designated subtypes differ",
10063 -- Normal case where conversion is allowed
10071 ("target designated subtype not compatible with }",
10078 -- Access to subprogram types. If the operand is an access parameter,
10079 -- the type has a deeper accessibility that any master, and cannot
10080 -- be assigned. We must make an exception if the conversion is part
10081 -- of an assignment and the target is the return object of an extended
10082 -- return statement, because in that case the accessibility check
10083 -- takes place after the return.
10085 elsif Is_Access_Subprogram_Type
(Target_Type
)
10086 and then No
(Corresponding_Remote_Type
(Opnd_Type
))
10088 if Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
10089 and then Is_Entity_Name
(Operand
)
10090 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
10092 (Nkind
(Parent
(N
)) /= N_Assignment_Statement
10093 or else not Is_Entity_Name
(Name
(Parent
(N
)))
10094 or else not Is_Return_Object
(Entity
(Name
(Parent
(N
)))))
10097 ("illegal attempt to store anonymous access to subprogram",
10100 ("\value has deeper accessibility than any master " &
10101 "(RM 3.10.2 (13))",
10105 ("\use named access type for& instead of access parameter",
10106 Operand
, Entity
(Operand
));
10109 -- Check that the designated types are subtype conformant
10111 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
10112 Old_Id
=> Designated_Type
(Opnd_Type
),
10115 -- Check the static accessibility rule of 4.6(20)
10117 if Type_Access_Level
(Opnd_Type
) >
10118 Type_Access_Level
(Target_Type
)
10121 ("operand type has deeper accessibility level than target",
10124 -- Check that if the operand type is declared in a generic body,
10125 -- then the target type must be declared within that same body
10126 -- (enforces last sentence of 4.6(20)).
10128 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
10130 O_Gen
: constant Node_Id
:=
10131 Enclosing_Generic_Body
(Opnd_Type
);
10136 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
10137 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
10138 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
10141 if T_Gen
/= O_Gen
then
10143 ("target type must be declared in same generic body"
10144 & " as operand type", N
);
10151 -- Remote subprogram access types
10153 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
10154 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
10156 -- It is valid to convert from one RAS type to another provided
10157 -- that their specification statically match.
10159 Check_Subtype_Conformant
10161 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
10163 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
10168 -- If both are tagged types, check legality of view conversions
10170 elsif Is_Tagged_Type
(Target_Type
)
10171 and then Is_Tagged_Type
(Opnd_Type
)
10173 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
10175 -- Types derived from the same root type are convertible
10177 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
10180 -- In an instance or an inlined body, there may be inconsistent
10181 -- views of the same type, or of types derived from a common root.
10183 elsif (In_Instance
or In_Inlined_Body
)
10185 Root_Type
(Underlying_Type
(Target_Type
)) =
10186 Root_Type
(Underlying_Type
(Opnd_Type
))
10190 -- Special check for common access type error case
10192 elsif Ekind
(Target_Type
) = E_Access_Type
10193 and then Is_Access_Type
(Opnd_Type
)
10195 Error_Msg_N
("target type must be general access type!", N
);
10196 Error_Msg_NE
-- CODEFIX
10197 ("add ALL to }!", N
, Target_Type
);
10201 Error_Msg_NE
("invalid conversion, not compatible with }",
10205 end Valid_Conversion
;