1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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_Aggr
; use Sem_Aggr
;
54 with Sem_Attr
; use Sem_Attr
;
55 with Sem_Cat
; use Sem_Cat
;
56 with Sem_Ch4
; use Sem_Ch4
;
57 with Sem_Ch6
; use Sem_Ch6
;
58 with Sem_Ch8
; use Sem_Ch8
;
59 with Sem_Disp
; use Sem_Disp
;
60 with Sem_Dist
; use Sem_Dist
;
61 with Sem_Elab
; use Sem_Elab
;
62 with Sem_Eval
; use Sem_Eval
;
63 with Sem_Intr
; use Sem_Intr
;
64 with Sem_Util
; use Sem_Util
;
65 with Sem_Type
; use Sem_Type
;
66 with Sem_Warn
; use Sem_Warn
;
67 with Sinfo
; use Sinfo
;
68 with Snames
; use Snames
;
69 with Stand
; use Stand
;
70 with Stringt
; use Stringt
;
71 with Targparm
; use Targparm
;
72 with Tbuild
; use Tbuild
;
73 with Uintp
; use Uintp
;
74 with Urealp
; use Urealp
;
76 package body Sem_Res
is
78 -----------------------
79 -- Local Subprograms --
80 -----------------------
82 -- Second pass (top-down) type checking and overload resolution procedures
83 -- Typ is the type required by context. These procedures propagate the
84 -- type information recursively to the descendants of N. If the node
85 -- is not overloaded, its Etype is established in the first pass. If
86 -- overloaded, the Resolve routines set the correct type. For arith.
87 -- operators, the Etype is the base type of the context.
89 -- Note that Resolve_Attribute is separated off in Sem_Attr
91 procedure Check_Discriminant_Use
(N
: Node_Id
);
92 -- Enforce the restrictions on the use of discriminants when constraining
93 -- a component of a discriminated type (record or concurrent type).
95 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
);
96 -- Given a node for an operator associated with type T, check that
97 -- the operator is visible. Operators all of whose operands are
98 -- universal must be checked for visibility during resolution
99 -- because their type is not determinable based on their operands.
101 procedure Check_Fully_Declared_Prefix
104 -- Check that the type of the prefix of a dereference is not incomplete
106 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean;
107 -- Given a call node, N, which is known to occur immediately within the
108 -- subprogram being called, determines whether it is a detectable case of
109 -- an infinite recursion, and if so, outputs appropriate messages. Returns
110 -- True if an infinite recursion is detected, and False otherwise.
112 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
);
113 -- If the type of the object being initialized uses the secondary stack
114 -- directly or indirectly, create a transient scope for the call to the
115 -- init proc. This is because we do not create transient scopes for the
116 -- initialization of individual components within the init proc itself.
117 -- Could be optimized away perhaps?
119 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean;
120 -- Utility to check whether the name in the call is a predefined
121 -- operator, in which case the call is made into an operator node.
122 -- An instance of an intrinsic conversion operation may be given
123 -- an operator name, but is not treated like an operator.
125 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
);
126 -- If a default expression in entry call N depends on the discriminants
127 -- of the task, it must be replaced with a reference to the discriminant
128 -- of the task being called.
130 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
);
131 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
);
132 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
);
133 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
134 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
);
135 procedure Resolve_Conditional_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
136 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
);
137 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
);
138 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
);
139 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
);
140 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
141 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
);
142 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
);
143 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
);
144 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
);
145 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
);
146 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
);
147 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
);
148 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
149 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
);
150 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
151 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
);
152 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
);
153 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
);
154 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
);
155 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
);
156 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
157 procedure Resolve_Subprogram_Info
(N
: Node_Id
; Typ
: Entity_Id
);
158 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
159 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
);
160 procedure Resolve_Unchecked_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
161 procedure Resolve_Unchecked_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
163 function Operator_Kind
165 Is_Binary
: Boolean) return Node_Kind
;
166 -- Utility to map the name of an operator into the corresponding Node. Used
167 -- by other node rewriting procedures.
169 procedure Resolve_Actuals
(N
: Node_Id
; Nam
: Entity_Id
);
170 -- Resolve actuals of call, and add default expressions for missing ones.
171 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
172 -- called subprogram.
174 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
);
175 -- Called from Resolve_Call, when the prefix denotes an entry or element
176 -- of entry family. Actuals are resolved as for subprograms, and the node
177 -- is rebuilt as an entry call. Also called for protected operations. Typ
178 -- is the context type, which is used when the operation is a protected
179 -- function with no arguments, and the return value is indexed.
181 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
182 -- A call to a user-defined intrinsic operator is rewritten as a call
183 -- to the corresponding predefined operator, with suitable conversions.
185 procedure Resolve_Intrinsic_Unary_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
186 -- Ditto, for unary operators (only arithmetic ones)
188 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
);
189 -- If an operator node resolves to a call to a user-defined operator,
190 -- rewrite the node as a function call.
192 procedure Make_Call_Into_Operator
196 -- Inverse transformation: if an operator is given in functional notation,
197 -- then after resolving the node, transform into an operator node, so
198 -- that operands are resolved properly. Recall that predefined operators
199 -- do not have a full signature and special resolution rules apply.
201 procedure Rewrite_Renamed_Operator
205 -- An operator can rename another, e.g. in an instantiation. In that
206 -- case, the proper operator node must be constructed and resolved.
208 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
);
209 -- The String_Literal_Subtype is built for all strings that are not
210 -- operands of a static concatenation operation. If the argument is
211 -- not a N_String_Literal node, then the call has no effect.
213 procedure Set_Slice_Subtype
(N
: Node_Id
);
214 -- Build subtype of array type, with the range specified by the slice
216 procedure Simplify_Type_Conversion
(N
: Node_Id
);
217 -- Called after N has been resolved and evaluated, but before range checks
218 -- have been applied. Currently simplifies a combination of floating-point
219 -- to integer conversion and Truncation attribute.
221 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
;
222 -- A universal_fixed expression in an universal context is unambiguous
223 -- if there is only one applicable fixed point type. Determining whether
224 -- there is only one requires a search over all visible entities, and
225 -- happens only in very pathological cases (see 6115-006).
227 function Valid_Conversion
230 Operand
: Node_Id
) return Boolean;
231 -- Verify legality rules given in 4.6 (8-23). Target is the target
232 -- type of the conversion, which may be an implicit conversion of
233 -- an actual parameter to an anonymous access type (in which case
234 -- N denotes the actual parameter and N = Operand).
236 -------------------------
237 -- Ambiguous_Character --
238 -------------------------
240 procedure Ambiguous_Character
(C
: Node_Id
) is
244 if Nkind
(C
) = N_Character_Literal
then
245 Error_Msg_N
("ambiguous character literal", C
);
247 -- First the ones in Standard
250 ("\\possible interpretation: Character!", C
);
252 ("\\possible interpretation: Wide_Character!", C
);
254 -- Include Wide_Wide_Character in Ada 2005 mode
256 if Ada_Version
>= Ada_05
then
258 ("\\possible interpretation: Wide_Wide_Character!", C
);
261 -- Now any other types that match
263 E
:= Current_Entity
(C
);
264 while Present
(E
) loop
265 Error_Msg_NE
("\\possible interpretation:}!", C
, Etype
(E
));
269 end Ambiguous_Character
;
271 -------------------------
272 -- Analyze_And_Resolve --
273 -------------------------
275 procedure Analyze_And_Resolve
(N
: Node_Id
) is
279 end Analyze_And_Resolve
;
281 procedure Analyze_And_Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
285 end Analyze_And_Resolve
;
287 -- Version withs check(s) suppressed
289 procedure Analyze_And_Resolve
294 Scop
: constant Entity_Id
:= Current_Scope
;
297 if Suppress
= All_Checks
then
299 Svg
: constant Suppress_Array
:= Scope_Suppress
;
301 Scope_Suppress
:= (others => True);
302 Analyze_And_Resolve
(N
, Typ
);
303 Scope_Suppress
:= Svg
;
308 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
311 Scope_Suppress
(Suppress
) := True;
312 Analyze_And_Resolve
(N
, Typ
);
313 Scope_Suppress
(Suppress
) := Svg
;
317 if Current_Scope
/= Scop
318 and then Scope_Is_Transient
320 -- This can only happen if a transient scope was created
321 -- for an inner expression, which will be removed upon
322 -- completion of the analysis of an enclosing construct.
323 -- The transient scope must have the suppress status of
324 -- the enclosing environment, not of this Analyze call.
326 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
329 end Analyze_And_Resolve
;
331 procedure Analyze_And_Resolve
335 Scop
: constant Entity_Id
:= Current_Scope
;
338 if Suppress
= All_Checks
then
340 Svg
: constant Suppress_Array
:= Scope_Suppress
;
342 Scope_Suppress
:= (others => True);
343 Analyze_And_Resolve
(N
);
344 Scope_Suppress
:= Svg
;
349 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
352 Scope_Suppress
(Suppress
) := True;
353 Analyze_And_Resolve
(N
);
354 Scope_Suppress
(Suppress
) := Svg
;
358 if Current_Scope
/= Scop
359 and then Scope_Is_Transient
361 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
364 end Analyze_And_Resolve
;
366 ----------------------------
367 -- Check_Discriminant_Use --
368 ----------------------------
370 procedure Check_Discriminant_Use
(N
: Node_Id
) is
371 PN
: constant Node_Id
:= Parent
(N
);
372 Disc
: constant Entity_Id
:= Entity
(N
);
377 -- Any use in a default expression is legal
379 if In_Default_Expression
then
382 elsif Nkind
(PN
) = N_Range
then
384 -- Discriminant cannot be used to constrain a scalar type
388 if Nkind
(P
) = N_Range_Constraint
389 and then Nkind
(Parent
(P
)) = N_Subtype_Indication
390 and then Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
392 Error_Msg_N
("discriminant cannot constrain scalar type", N
);
394 elsif Nkind
(P
) = N_Index_Or_Discriminant_Constraint
then
396 -- The following check catches the unusual case where
397 -- a discriminant appears within an index constraint
398 -- that is part of a larger expression within a constraint
399 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
400 -- For now we only check case of record components, and
401 -- note that a similar check should also apply in the
402 -- case of discriminant constraints below. ???
404 -- Note that the check for N_Subtype_Declaration below is to
405 -- detect the valid use of discriminants in the constraints of a
406 -- subtype declaration when this subtype declaration appears
407 -- inside the scope of a record type (which is syntactically
408 -- illegal, but which may be created as part of derived type
409 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
412 if Ekind
(Current_Scope
) = E_Record_Type
413 and then Scope
(Disc
) = Current_Scope
415 (Nkind
(Parent
(P
)) = N_Subtype_Indication
417 (Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
419 Nkind
(Parent
(Parent
(P
))) = N_Subtype_Declaration
)
420 and then Paren_Count
(N
) = 0)
423 ("discriminant must appear alone in component constraint", N
);
427 -- Detect a common beginner error:
429 -- type R (D : Positive := 100) is record
430 -- Name : String (1 .. D);
433 -- The default value causes an object of type R to be
434 -- allocated with room for Positive'Last characters.
442 function Large_Storage_Type
(T
: Entity_Id
) return Boolean;
443 -- Return True if type T has a large enough range that
444 -- any array whose index type covered the whole range of
445 -- the type would likely raise Storage_Error.
447 ------------------------
448 -- Large_Storage_Type --
449 ------------------------
451 function Large_Storage_Type
(T
: Entity_Id
) return Boolean is
456 T
= Standard_Positive
458 T
= Standard_Natural
;
459 end Large_Storage_Type
;
462 -- Check that the Disc has a large range
464 if not Large_Storage_Type
(Etype
(Disc
)) then
468 -- If the enclosing type is limited, we allocate only the
469 -- default value, not the maximum, and there is no need for
472 if Is_Limited_Type
(Scope
(Disc
)) then
476 -- Check that it is the high bound
478 if N
/= High_Bound
(PN
)
479 or else No
(Discriminant_Default_Value
(Disc
))
484 -- Check the array allows a large range at this bound.
485 -- First find the array
489 if Nkind
(SI
) /= N_Subtype_Indication
then
493 T
:= Entity
(Subtype_Mark
(SI
));
495 if not Is_Array_Type
(T
) then
499 -- Next, find the dimension
501 TB
:= First_Index
(T
);
502 CB
:= First
(Constraints
(P
));
504 and then Present
(TB
)
505 and then Present
(CB
)
516 -- Now, check the dimension has a large range
518 if not Large_Storage_Type
(Etype
(TB
)) then
522 -- Warn about the danger
525 ("?creation of & object may raise Storage_Error!",
534 -- Legal case is in index or discriminant constraint
536 elsif Nkind
(PN
) = N_Index_Or_Discriminant_Constraint
537 or else Nkind
(PN
) = N_Discriminant_Association
539 if Paren_Count
(N
) > 0 then
541 ("discriminant in constraint must appear alone", N
);
543 elsif Nkind
(N
) = N_Expanded_Name
544 and then Comes_From_Source
(N
)
547 ("discriminant must appear alone as a direct name", N
);
552 -- Otherwise, context is an expression. It should not be within
553 -- (i.e. a subexpression of) a constraint for a component.
558 while Nkind
(P
) /= N_Component_Declaration
559 and then Nkind
(P
) /= N_Subtype_Indication
560 and then Nkind
(P
) /= N_Entry_Declaration
567 -- If the discriminant is used in an expression that is a bound
568 -- of a scalar type, an Itype is created and the bounds are attached
569 -- to its range, not to the original subtype indication. Such use
570 -- is of course a double fault.
572 if (Nkind
(P
) = N_Subtype_Indication
574 (Nkind
(Parent
(P
)) = N_Component_Definition
576 Nkind
(Parent
(P
)) = N_Derived_Type_Definition
)
577 and then D
= Constraint
(P
))
579 -- The constraint itself may be given by a subtype indication,
580 -- rather than by a more common discrete range.
582 or else (Nkind
(P
) = N_Subtype_Indication
584 Nkind
(Parent
(P
)) = N_Index_Or_Discriminant_Constraint
)
585 or else Nkind
(P
) = N_Entry_Declaration
586 or else Nkind
(D
) = N_Defining_Identifier
589 ("discriminant in constraint must appear alone", N
);
592 end Check_Discriminant_Use
;
594 --------------------------------
595 -- Check_For_Visible_Operator --
596 --------------------------------
598 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
) is
600 if Is_Invisible_Operator
(N
, T
) then
602 ("operator for} is not directly visible!", N
, First_Subtype
(T
));
603 Error_Msg_N
("use clause would make operation legal!", N
);
605 end Check_For_Visible_Operator
;
607 ----------------------------------
608 -- Check_Fully_Declared_Prefix --
609 ----------------------------------
611 procedure Check_Fully_Declared_Prefix
616 -- Check that the designated type of the prefix of a dereference is
617 -- not an incomplete type. This cannot be done unconditionally, because
618 -- dereferences of private types are legal in default expressions. This
619 -- case is taken care of in Check_Fully_Declared, called below. There
620 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
622 -- This consideration also applies to similar checks for allocators,
623 -- qualified expressions, and type conversions.
625 -- An additional exception concerns other per-object expressions that
626 -- are not directly related to component declarations, in particular
627 -- representation pragmas for tasks. These will be per-object
628 -- expressions if they depend on discriminants or some global entity.
629 -- If the task has access discriminants, the designated type may be
630 -- incomplete at the point the expression is resolved. This resolution
631 -- takes place within the body of the initialization procedure, where
632 -- the discriminant is replaced by its discriminal.
634 if Is_Entity_Name
(Pref
)
635 and then Ekind
(Entity
(Pref
)) = E_In_Parameter
639 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
640 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
641 -- Analyze_Object_Renaming, and Freeze_Entity.
643 elsif Ada_Version
>= Ada_05
644 and then Is_Entity_Name
(Pref
)
645 and then Ekind
(Directly_Designated_Type
(Etype
(Pref
))) =
647 and then Is_Tagged_Type
(Directly_Designated_Type
(Etype
(Pref
)))
651 Check_Fully_Declared
(Typ
, Parent
(Pref
));
653 end Check_Fully_Declared_Prefix
;
655 ------------------------------
656 -- Check_Infinite_Recursion --
657 ------------------------------
659 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean is
663 function Same_Argument_List
return Boolean;
664 -- Check whether list of actuals is identical to list of formals
665 -- of called function (which is also the enclosing scope).
667 ------------------------
668 -- Same_Argument_List --
669 ------------------------
671 function Same_Argument_List
return Boolean is
677 if not Is_Entity_Name
(Name
(N
)) then
680 Subp
:= Entity
(Name
(N
));
683 F
:= First_Formal
(Subp
);
684 A
:= First_Actual
(N
);
685 while Present
(F
) and then Present
(A
) loop
686 if not Is_Entity_Name
(A
)
687 or else Entity
(A
) /= F
697 end Same_Argument_List
;
699 -- Start of processing for Check_Infinite_Recursion
702 -- Loop moving up tree, quitting if something tells us we are
703 -- definitely not in an infinite recursion situation.
708 exit when Nkind
(P
) = N_Subprogram_Body
;
710 if Nkind
(P
) = N_Or_Else
or else
711 Nkind
(P
) = N_And_Then
or else
712 Nkind
(P
) = N_If_Statement
or else
713 Nkind
(P
) = N_Case_Statement
717 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
718 and then C
/= First
(Statements
(P
))
720 -- If the call is the expression of a return statement and
721 -- the actuals are identical to the formals, it's worth a
722 -- warning. However, we skip this if there is an immediately
723 -- preceding raise statement, since the call is never executed.
725 -- Furthermore, this corresponds to a common idiom:
727 -- function F (L : Thing) return Boolean is
729 -- raise Program_Error;
733 -- for generating a stub function
735 if Nkind
(Parent
(N
)) = N_Simple_Return_Statement
736 and then Same_Argument_List
738 exit when not Is_List_Member
(Parent
(N
));
740 -- OK, return statement is in a statement list, look for raise
746 -- Skip past N_Freeze_Entity nodes generated by expansion
748 Nod
:= Prev
(Parent
(N
));
750 and then Nkind
(Nod
) = N_Freeze_Entity
755 -- If no raise statement, give warning
757 exit when Nkind
(Nod
) /= N_Raise_Statement
759 (Nkind
(Nod
) not in N_Raise_xxx_Error
760 or else Present
(Condition
(Nod
)));
771 Error_Msg_N
("!?possible infinite recursion", N
);
772 Error_Msg_N
("\!?Storage_Error may be raised at run time", N
);
775 end Check_Infinite_Recursion
;
777 -------------------------------
778 -- Check_Initialization_Call --
779 -------------------------------
781 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
) is
782 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
784 function Uses_SS
(T
: Entity_Id
) return Boolean;
785 -- Check whether the creation of an object of the type will involve
786 -- use of the secondary stack. If T is a record type, this is true
787 -- if the expression for some component uses the secondary stack, eg.
788 -- through a call to a function that returns an unconstrained value.
789 -- False if T is controlled, because cleanups occur elsewhere.
795 function Uses_SS
(T
: Entity_Id
) return Boolean is
798 Full_Type
: Entity_Id
:= Underlying_Type
(T
);
801 -- Normally we want to use the underlying type, but if it's not set
802 -- then continue with T.
804 if not Present
(Full_Type
) then
808 if Is_Controlled
(Full_Type
) then
811 elsif Is_Array_Type
(Full_Type
) then
812 return Uses_SS
(Component_Type
(Full_Type
));
814 elsif Is_Record_Type
(Full_Type
) then
815 Comp
:= First_Component
(Full_Type
);
816 while Present
(Comp
) loop
817 if Ekind
(Comp
) = E_Component
818 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
820 -- The expression for a dynamic component may be rewritten
821 -- as a dereference, so retrieve original node.
823 Expr
:= Original_Node
(Expression
(Parent
(Comp
)));
825 -- Return True if the expression is a call to a function
826 -- (including an attribute function such as Image) with
827 -- a result that requires a transient scope.
829 if (Nkind
(Expr
) = N_Function_Call
830 or else (Nkind
(Expr
) = N_Attribute_Reference
831 and then Present
(Expressions
(Expr
))))
832 and then Requires_Transient_Scope
(Etype
(Expr
))
836 elsif Uses_SS
(Etype
(Comp
)) then
841 Next_Component
(Comp
);
851 -- Start of processing for Check_Initialization_Call
854 -- Establish a transient scope if the type needs it
856 if Uses_SS
(Typ
) then
857 Establish_Transient_Scope
(First_Actual
(N
), Sec_Stack
=> True);
859 end Check_Initialization_Call
;
861 ------------------------------
862 -- Check_Parameterless_Call --
863 ------------------------------
865 procedure Check_Parameterless_Call
(N
: Node_Id
) is
868 function Prefix_Is_Access_Subp
return Boolean;
869 -- If the prefix is of an access_to_subprogram type, the node must be
870 -- rewritten as a call. Ditto if the prefix is overloaded and all its
871 -- interpretations are access to subprograms.
873 ---------------------------
874 -- Prefix_Is_Access_Subp --
875 ---------------------------
877 function Prefix_Is_Access_Subp
return Boolean is
882 if not Is_Overloaded
(N
) then
884 Ekind
(Etype
(N
)) = E_Subprogram_Type
885 and then Base_Type
(Etype
(Etype
(N
))) /= Standard_Void_Type
;
887 Get_First_Interp
(N
, I
, It
);
888 while Present
(It
.Typ
) loop
889 if Ekind
(It
.Typ
) /= E_Subprogram_Type
890 or else Base_Type
(Etype
(It
.Typ
)) = Standard_Void_Type
895 Get_Next_Interp
(I
, It
);
900 end Prefix_Is_Access_Subp
;
902 -- Start of processing for Check_Parameterless_Call
905 -- Defend against junk stuff if errors already detected
907 if Total_Errors_Detected
/= 0 then
908 if Nkind
(N
) in N_Has_Etype
and then Etype
(N
) = Any_Type
then
910 elsif Nkind
(N
) in N_Has_Chars
911 and then Chars
(N
) in Error_Name_Or_No_Name
919 -- If the context expects a value, and the name is a procedure,
920 -- this is most likely a missing 'Access. Do not try to resolve
921 -- the parameterless call, error will be caught when the outer
924 if Is_Entity_Name
(N
)
925 and then Ekind
(Entity
(N
)) = E_Procedure
926 and then not Is_Overloaded
(N
)
928 (Nkind
(Parent
(N
)) = N_Parameter_Association
929 or else Nkind
(Parent
(N
)) = N_Function_Call
930 or else Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
)
935 -- Rewrite as call if overloadable entity that is (or could be, in
936 -- the overloaded case) a function call. If we know for sure that
937 -- the entity is an enumeration literal, we do not rewrite it.
939 if (Is_Entity_Name
(N
)
940 and then Is_Overloadable
(Entity
(N
))
941 and then (Ekind
(Entity
(N
)) /= E_Enumeration_Literal
942 or else Is_Overloaded
(N
)))
944 -- Rewrite as call if it is an explicit deference of an expression of
945 -- a subprogram access type, and the suprogram type is not that of a
946 -- procedure or entry.
949 (Nkind
(N
) = N_Explicit_Dereference
and then Prefix_Is_Access_Subp
)
951 -- Rewrite as call if it is a selected component which is a function,
952 -- this is the case of a call to a protected function (which may be
953 -- overloaded with other protected operations).
956 (Nkind
(N
) = N_Selected_Component
957 and then (Ekind
(Entity
(Selector_Name
(N
))) = E_Function
959 ((Ekind
(Entity
(Selector_Name
(N
))) = E_Entry
961 Ekind
(Entity
(Selector_Name
(N
))) = E_Procedure
)
962 and then Is_Overloaded
(Selector_Name
(N
)))))
964 -- If one of the above three conditions is met, rewrite as call.
965 -- Apply the rewriting only once.
968 if Nkind
(Parent
(N
)) /= N_Function_Call
969 or else N
/= Name
(Parent
(N
))
973 -- If overloaded, overload set belongs to new copy
975 Save_Interps
(N
, Nam
);
977 -- Change node to parameterless function call (note that the
978 -- Parameter_Associations associations field is left set to Empty,
979 -- its normal default value since there are no parameters)
981 Change_Node
(N
, N_Function_Call
);
983 Set_Sloc
(N
, Sloc
(Nam
));
987 elsif Nkind
(N
) = N_Parameter_Association
then
988 Check_Parameterless_Call
(Explicit_Actual_Parameter
(N
));
990 end Check_Parameterless_Call
;
992 ----------------------
993 -- Is_Predefined_Op --
994 ----------------------
996 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean is
998 return Is_Intrinsic_Subprogram
(Nam
)
999 and then not Is_Generic_Instance
(Nam
)
1000 and then Chars
(Nam
) in Any_Operator_Name
1001 and then (No
(Alias
(Nam
))
1002 or else Is_Predefined_Op
(Alias
(Nam
)));
1003 end Is_Predefined_Op
;
1005 -----------------------------
1006 -- Make_Call_Into_Operator --
1007 -----------------------------
1009 procedure Make_Call_Into_Operator
1014 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
1015 Act1
: Node_Id
:= First_Actual
(N
);
1016 Act2
: Node_Id
:= Next_Actual
(Act1
);
1017 Error
: Boolean := False;
1018 Func
: constant Entity_Id
:= Entity
(Name
(N
));
1019 Is_Binary
: constant Boolean := Present
(Act2
);
1021 Opnd_Type
: Entity_Id
;
1022 Orig_Type
: Entity_Id
:= Empty
;
1025 type Kind_Test
is access function (E
: Entity_Id
) return Boolean;
1027 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean;
1028 -- Determine whether E is an access type declared by an access decla-
1029 -- ration, and not an (anonymous) allocator type.
1031 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean;
1032 -- If the operand is not universal, and the operator is given by a
1033 -- expanded name, verify that the operand has an interpretation with
1034 -- a type defined in the given scope of the operator.
1036 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
;
1037 -- Find a type of the given class in the package Pack that contains
1040 -----------------------------
1041 -- Is_Definite_Access_Type --
1042 -----------------------------
1044 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean is
1045 Btyp
: constant Entity_Id
:= Base_Type
(E
);
1047 return Ekind
(Btyp
) = E_Access_Type
1048 or else (Ekind
(Btyp
) = E_Access_Subprogram_Type
1049 and then Comes_From_Source
(Btyp
));
1050 end Is_Definite_Access_Type
;
1052 ---------------------------
1053 -- Operand_Type_In_Scope --
1054 ---------------------------
1056 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean is
1057 Nod
: constant Node_Id
:= Right_Opnd
(Op_Node
);
1062 if not Is_Overloaded
(Nod
) then
1063 return Scope
(Base_Type
(Etype
(Nod
))) = S
;
1066 Get_First_Interp
(Nod
, I
, It
);
1067 while Present
(It
.Typ
) loop
1068 if Scope
(Base_Type
(It
.Typ
)) = S
then
1072 Get_Next_Interp
(I
, It
);
1077 end Operand_Type_In_Scope
;
1083 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
is
1086 function In_Decl
return Boolean;
1087 -- Verify that node is not part of the type declaration for the
1088 -- candidate type, which would otherwise be invisible.
1094 function In_Decl
return Boolean is
1095 Decl_Node
: constant Node_Id
:= Parent
(E
);
1101 if Etype
(E
) = Any_Type
then
1104 elsif No
(Decl_Node
) then
1109 and then Nkind
(N2
) /= N_Compilation_Unit
1111 if N2
= Decl_Node
then
1122 -- Start of processing for Type_In_P
1125 -- If the context type is declared in the prefix package, this
1126 -- is the desired base type.
1128 if Scope
(Base_Type
(Typ
)) = Pack
1131 return Base_Type
(Typ
);
1134 E
:= First_Entity
(Pack
);
1135 while Present
(E
) loop
1137 and then not In_Decl
1149 -- Start of processing for Make_Call_Into_Operator
1152 Op_Node
:= New_Node
(Operator_Kind
(Op_Name
, Is_Binary
), Sloc
(N
));
1157 Set_Left_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1158 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act2
));
1159 Save_Interps
(Act1
, Left_Opnd
(Op_Node
));
1160 Save_Interps
(Act2
, Right_Opnd
(Op_Node
));
1161 Act1
:= Left_Opnd
(Op_Node
);
1162 Act2
:= Right_Opnd
(Op_Node
);
1167 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1168 Save_Interps
(Act1
, Right_Opnd
(Op_Node
));
1169 Act1
:= Right_Opnd
(Op_Node
);
1172 -- If the operator is denoted by an expanded name, and the prefix is
1173 -- not Standard, but the operator is a predefined one whose scope is
1174 -- Standard, then this is an implicit_operator, inserted as an
1175 -- interpretation by the procedure of the same name. This procedure
1176 -- overestimates the presence of implicit operators, because it does
1177 -- not examine the type of the operands. Verify now that the operand
1178 -- type appears in the given scope. If right operand is universal,
1179 -- check the other operand. In the case of concatenation, either
1180 -- argument can be the component type, so check the type of the result.
1181 -- If both arguments are literals, look for a type of the right kind
1182 -- defined in the given scope. This elaborate nonsense is brought to
1183 -- you courtesy of b33302a. The type itself must be frozen, so we must
1184 -- find the type of the proper class in the given scope.
1186 -- A final wrinkle is the multiplication operator for fixed point
1187 -- types, which is defined in Standard only, and not in the scope of
1188 -- the fixed_point type itself.
1190 if Nkind
(Name
(N
)) = N_Expanded_Name
then
1191 Pack
:= Entity
(Prefix
(Name
(N
)));
1193 -- If the entity being called is defined in the given package,
1194 -- it is a renaming of a predefined operator, and known to be
1197 if Scope
(Entity
(Name
(N
))) = Pack
1198 and then Pack
/= Standard_Standard
1202 -- Visibility does not need to be checked in an instance: if the
1203 -- operator was not visible in the generic it has been diagnosed
1204 -- already, else there is an implicit copy of it in the instance.
1206 elsif In_Instance
then
1209 elsif (Op_Name
= Name_Op_Multiply
1210 or else Op_Name
= Name_Op_Divide
)
1211 and then Is_Fixed_Point_Type
(Etype
(Left_Opnd
(Op_Node
)))
1212 and then Is_Fixed_Point_Type
(Etype
(Right_Opnd
(Op_Node
)))
1214 if Pack
/= Standard_Standard
then
1218 -- Ada 2005, AI-420: Predefined equality on Universal_Access
1221 elsif Ada_Version
>= Ada_05
1222 and then (Op_Name
= Name_Op_Eq
or else Op_Name
= Name_Op_Ne
)
1223 and then Ekind
(Etype
(Act1
)) = E_Anonymous_Access_Type
1228 Opnd_Type
:= Base_Type
(Etype
(Right_Opnd
(Op_Node
)));
1230 if Op_Name
= Name_Op_Concat
then
1231 Opnd_Type
:= Base_Type
(Typ
);
1233 elsif (Scope
(Opnd_Type
) = Standard_Standard
1235 or else (Nkind
(Right_Opnd
(Op_Node
)) = N_Attribute_Reference
1237 and then not Comes_From_Source
(Opnd_Type
))
1239 Opnd_Type
:= Base_Type
(Etype
(Left_Opnd
(Op_Node
)));
1242 if Scope
(Opnd_Type
) = Standard_Standard
then
1244 -- Verify that the scope contains a type that corresponds to
1245 -- the given literal. Optimize the case where Pack is Standard.
1247 if Pack
/= Standard_Standard
then
1249 if Opnd_Type
= Universal_Integer
then
1250 Orig_Type
:= Type_In_P
(Is_Integer_Type
'Access);
1252 elsif Opnd_Type
= Universal_Real
then
1253 Orig_Type
:= Type_In_P
(Is_Real_Type
'Access);
1255 elsif Opnd_Type
= Any_String
then
1256 Orig_Type
:= Type_In_P
(Is_String_Type
'Access);
1258 elsif Opnd_Type
= Any_Access
then
1259 Orig_Type
:= Type_In_P
(Is_Definite_Access_Type
'Access);
1261 elsif Opnd_Type
= Any_Composite
then
1262 Orig_Type
:= Type_In_P
(Is_Composite_Type
'Access);
1264 if Present
(Orig_Type
) then
1265 if Has_Private_Component
(Orig_Type
) then
1268 Set_Etype
(Act1
, Orig_Type
);
1271 Set_Etype
(Act2
, Orig_Type
);
1280 Error
:= No
(Orig_Type
);
1283 elsif Ekind
(Opnd_Type
) = E_Allocator_Type
1284 and then No
(Type_In_P
(Is_Definite_Access_Type
'Access))
1288 -- If the type is defined elsewhere, and the operator is not
1289 -- defined in the given scope (by a renaming declaration, e.g.)
1290 -- then this is an error as well. If an extension of System is
1291 -- present, and the type may be defined there, Pack must be
1294 elsif Scope
(Opnd_Type
) /= Pack
1295 and then Scope
(Op_Id
) /= Pack
1296 and then (No
(System_Aux_Id
)
1297 or else Scope
(Opnd_Type
) /= System_Aux_Id
1298 or else Pack
/= Scope
(System_Aux_Id
))
1300 if not Is_Overloaded
(Right_Opnd
(Op_Node
)) then
1303 Error
:= not Operand_Type_In_Scope
(Pack
);
1306 elsif Pack
= Standard_Standard
1307 and then not Operand_Type_In_Scope
(Standard_Standard
)
1314 Error_Msg_Node_2
:= Pack
;
1316 ("& not declared in&", N
, Selector_Name
(Name
(N
)));
1317 Set_Etype
(N
, Any_Type
);
1322 Set_Chars
(Op_Node
, Op_Name
);
1324 if not Is_Private_Type
(Etype
(N
)) then
1325 Set_Etype
(Op_Node
, Base_Type
(Etype
(N
)));
1327 Set_Etype
(Op_Node
, Etype
(N
));
1330 -- If this is a call to a function that renames a predefined equality,
1331 -- the renaming declaration provides a type that must be used to
1332 -- resolve the operands. This must be done now because resolution of
1333 -- the equality node will not resolve any remaining ambiguity, and it
1334 -- assumes that the first operand is not overloaded.
1336 if (Op_Name
= Name_Op_Eq
or else Op_Name
= Name_Op_Ne
)
1337 and then Ekind
(Func
) = E_Function
1338 and then Is_Overloaded
(Act1
)
1340 Resolve
(Act1
, Base_Type
(Etype
(First_Formal
(Func
))));
1341 Resolve
(Act2
, Base_Type
(Etype
(First_Formal
(Func
))));
1344 Set_Entity
(Op_Node
, Op_Id
);
1345 Generate_Reference
(Op_Id
, N
, ' ');
1346 Rewrite
(N
, Op_Node
);
1348 -- If this is an arithmetic operator and the result type is private,
1349 -- the operands and the result must be wrapped in conversion to
1350 -- expose the underlying numeric type and expand the proper checks,
1351 -- e.g. on division.
1353 if Is_Private_Type
(Typ
) then
1355 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1356 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
1357 Resolve_Intrinsic_Operator
(N
, Typ
);
1359 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
1360 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
1369 -- For predefined operators on literals, the operation freezes
1372 if Present
(Orig_Type
) then
1373 Set_Etype
(Act1
, Orig_Type
);
1374 Freeze_Expression
(Act1
);
1376 end Make_Call_Into_Operator
;
1382 function Operator_Kind
1384 Is_Binary
: Boolean) return Node_Kind
1390 if Op_Name
= Name_Op_And
then
1392 elsif Op_Name
= Name_Op_Or
then
1394 elsif Op_Name
= Name_Op_Xor
then
1396 elsif Op_Name
= Name_Op_Eq
then
1398 elsif Op_Name
= Name_Op_Ne
then
1400 elsif Op_Name
= Name_Op_Lt
then
1402 elsif Op_Name
= Name_Op_Le
then
1404 elsif Op_Name
= Name_Op_Gt
then
1406 elsif Op_Name
= Name_Op_Ge
then
1408 elsif Op_Name
= Name_Op_Add
then
1410 elsif Op_Name
= Name_Op_Subtract
then
1411 Kind
:= N_Op_Subtract
;
1412 elsif Op_Name
= Name_Op_Concat
then
1413 Kind
:= N_Op_Concat
;
1414 elsif Op_Name
= Name_Op_Multiply
then
1415 Kind
:= N_Op_Multiply
;
1416 elsif Op_Name
= Name_Op_Divide
then
1417 Kind
:= N_Op_Divide
;
1418 elsif Op_Name
= Name_Op_Mod
then
1420 elsif Op_Name
= Name_Op_Rem
then
1422 elsif Op_Name
= Name_Op_Expon
then
1425 raise Program_Error
;
1431 if Op_Name
= Name_Op_Add
then
1433 elsif Op_Name
= Name_Op_Subtract
then
1435 elsif Op_Name
= Name_Op_Abs
then
1437 elsif Op_Name
= Name_Op_Not
then
1440 raise Program_Error
;
1447 -----------------------------
1448 -- Pre_Analyze_And_Resolve --
1449 -----------------------------
1451 procedure Pre_Analyze_And_Resolve
(N
: Node_Id
; T
: Entity_Id
) is
1452 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1455 Full_Analysis
:= False;
1456 Expander_Mode_Save_And_Set
(False);
1458 -- We suppress all checks for this analysis, since the checks will
1459 -- be applied properly, and in the right location, when the default
1460 -- expression is reanalyzed and reexpanded later on.
1462 Analyze_And_Resolve
(N
, T
, Suppress
=> All_Checks
);
1464 Expander_Mode_Restore
;
1465 Full_Analysis
:= Save_Full_Analysis
;
1466 end Pre_Analyze_And_Resolve
;
1468 -- Version without context type
1470 procedure Pre_Analyze_And_Resolve
(N
: Node_Id
) is
1471 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1474 Full_Analysis
:= False;
1475 Expander_Mode_Save_And_Set
(False);
1478 Resolve
(N
, Etype
(N
), Suppress
=> All_Checks
);
1480 Expander_Mode_Restore
;
1481 Full_Analysis
:= Save_Full_Analysis
;
1482 end Pre_Analyze_And_Resolve
;
1484 ----------------------------------
1485 -- Replace_Actual_Discriminants --
1486 ----------------------------------
1488 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
) is
1489 Loc
: constant Source_Ptr
:= Sloc
(N
);
1490 Tsk
: Node_Id
:= Empty
;
1492 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
;
1498 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
is
1502 if Nkind
(Nod
) = N_Identifier
then
1503 Ent
:= Entity
(Nod
);
1506 and then Ekind
(Ent
) = E_Discriminant
1509 Make_Selected_Component
(Loc
,
1510 Prefix
=> New_Copy_Tree
(Tsk
, New_Sloc
=> Loc
),
1511 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Ent
))));
1513 Set_Etype
(Nod
, Etype
(Ent
));
1521 procedure Replace_Discrs
is new Traverse_Proc
(Process_Discr
);
1523 -- Start of processing for Replace_Actual_Discriminants
1526 if not Expander_Active
then
1530 if Nkind
(Name
(N
)) = N_Selected_Component
then
1531 Tsk
:= Prefix
(Name
(N
));
1533 elsif Nkind
(Name
(N
)) = N_Indexed_Component
then
1534 Tsk
:= Prefix
(Prefix
(Name
(N
)));
1540 Replace_Discrs
(Default
);
1542 end Replace_Actual_Discriminants
;
1548 procedure Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
1549 Ambiguous
: Boolean := False;
1550 Ctx_Type
: Entity_Id
:= Typ
;
1551 Expr_Type
: Entity_Id
:= Empty
; -- prevent junk warning
1552 Err_Type
: Entity_Id
:= Empty
;
1553 Found
: Boolean := False;
1556 I1
: Interp_Index
:= 0; -- prevent junk warning
1559 Seen
: Entity_Id
:= Empty
; -- prevent junk warning
1561 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean;
1562 -- Determine whether a node comes from a predefined library unit or
1565 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
);
1566 -- Try and fix up a literal so that it matches its expected type. New
1567 -- literals are manufactured if necessary to avoid cascaded errors.
1569 procedure Resolution_Failed
;
1570 -- Called when attempt at resolving current expression fails
1572 ------------------------------------
1573 -- Comes_From_Predefined_Lib_Unit --
1574 -------------------------------------
1576 function Comes_From_Predefined_Lib_Unit
(Nod
: Node_Id
) return Boolean is
1579 Sloc
(Nod
) = Standard_Location
1580 or else Is_Predefined_File_Name
(Unit_File_Name
(
1581 Get_Source_Unit
(Sloc
(Nod
))));
1582 end Comes_From_Predefined_Lib_Unit
;
1584 --------------------
1585 -- Patch_Up_Value --
1586 --------------------
1588 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
) is
1590 if Nkind
(N
) = N_Integer_Literal
1591 and then Is_Real_Type
(Typ
)
1594 Make_Real_Literal
(Sloc
(N
),
1595 Realval
=> UR_From_Uint
(Intval
(N
))));
1596 Set_Etype
(N
, Universal_Real
);
1597 Set_Is_Static_Expression
(N
);
1599 elsif Nkind
(N
) = N_Real_Literal
1600 and then Is_Integer_Type
(Typ
)
1603 Make_Integer_Literal
(Sloc
(N
),
1604 Intval
=> UR_To_Uint
(Realval
(N
))));
1605 Set_Etype
(N
, Universal_Integer
);
1606 Set_Is_Static_Expression
(N
);
1607 elsif Nkind
(N
) = N_String_Literal
1608 and then Is_Character_Type
(Typ
)
1610 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('A')));
1612 Make_Character_Literal
(Sloc
(N
),
1614 Char_Literal_Value
=>
1615 UI_From_Int
(Character'Pos ('A'))));
1616 Set_Etype
(N
, Any_Character
);
1617 Set_Is_Static_Expression
(N
);
1619 elsif Nkind
(N
) /= N_String_Literal
1620 and then Is_String_Type
(Typ
)
1623 Make_String_Literal
(Sloc
(N
),
1624 Strval
=> End_String
));
1626 elsif Nkind
(N
) = N_Range
then
1627 Patch_Up_Value
(Low_Bound
(N
), Typ
);
1628 Patch_Up_Value
(High_Bound
(N
), Typ
);
1632 -----------------------
1633 -- Resolution_Failed --
1634 -----------------------
1636 procedure Resolution_Failed
is
1638 Patch_Up_Value
(N
, Typ
);
1640 Debug_A_Exit
("resolving ", N
, " (done, resolution failed)");
1641 Set_Is_Overloaded
(N
, False);
1643 -- The caller will return without calling the expander, so we need
1644 -- to set the analyzed flag. Note that it is fine to set Analyzed
1645 -- to True even if we are in the middle of a shallow analysis,
1646 -- (see the spec of sem for more details) since this is an error
1647 -- situation anyway, and there is no point in repeating the
1648 -- analysis later (indeed it won't work to repeat it later, since
1649 -- we haven't got a clear resolution of which entity is being
1652 Set_Analyzed
(N
, True);
1654 end Resolution_Failed
;
1656 -- Start of processing for Resolve
1663 -- Access attribute on remote subprogram cannot be used for
1664 -- a non-remote access-to-subprogram type.
1666 if Nkind
(N
) = N_Attribute_Reference
1667 and then (Attribute_Name
(N
) = Name_Access
1668 or else Attribute_Name
(N
) = Name_Unrestricted_Access
1669 or else Attribute_Name
(N
) = Name_Unchecked_Access
)
1670 and then Comes_From_Source
(N
)
1671 and then Is_Entity_Name
(Prefix
(N
))
1672 and then Is_Subprogram
(Entity
(Prefix
(N
)))
1673 and then Is_Remote_Call_Interface
(Entity
(Prefix
(N
)))
1674 and then not Is_Remote_Access_To_Subprogram_Type
(Typ
)
1677 ("prefix must statically denote a non-remote subprogram", N
);
1680 From_Lib
:= Comes_From_Predefined_Lib_Unit
(N
);
1682 -- If the context is a Remote_Access_To_Subprogram, access attributes
1683 -- must be resolved with the corresponding fat pointer. There is no need
1684 -- to check for the attribute name since the return type of an
1685 -- attribute is never a remote type.
1687 if Nkind
(N
) = N_Attribute_Reference
1688 and then Comes_From_Source
(N
)
1689 and then (Is_Remote_Call_Interface
(Typ
)
1690 or else Is_Remote_Types
(Typ
))
1693 Attr
: constant Attribute_Id
:=
1694 Get_Attribute_Id
(Attribute_Name
(N
));
1695 Pref
: constant Node_Id
:= Prefix
(N
);
1698 Is_Remote
: Boolean := True;
1701 -- Check that Typ is a remote access-to-subprogram type
1703 if Is_Remote_Access_To_Subprogram_Type
(Typ
) then
1704 -- Prefix (N) must statically denote a remote subprogram
1705 -- declared in a package specification.
1707 if Attr
= Attribute_Access
then
1708 Decl
:= Unit_Declaration_Node
(Entity
(Pref
));
1710 if Nkind
(Decl
) = N_Subprogram_Body
then
1711 Spec
:= Corresponding_Spec
(Decl
);
1713 if not No
(Spec
) then
1714 Decl
:= Unit_Declaration_Node
(Spec
);
1718 Spec
:= Parent
(Decl
);
1720 if not Is_Entity_Name
(Prefix
(N
))
1721 or else Nkind
(Spec
) /= N_Package_Specification
1723 not Is_Remote_Call_Interface
(Defining_Entity
(Spec
))
1727 ("prefix must statically denote a remote subprogram ",
1732 -- If we are generating code for a distributed program.
1733 -- perform semantic checks against the corresponding
1736 if (Attr
= Attribute_Access
1737 or else Attr
= Attribute_Unchecked_Access
1738 or else Attr
= Attribute_Unrestricted_Access
)
1739 and then Expander_Active
1740 and then Get_PCS_Name
/= Name_No_DSA
1742 Check_Subtype_Conformant
1743 (New_Id
=> Entity
(Prefix
(N
)),
1744 Old_Id
=> Designated_Type
1745 (Corresponding_Remote_Type
(Typ
)),
1749 Process_Remote_AST_Attribute
(N
, Typ
);
1756 Debug_A_Entry
("resolving ", N
);
1758 if Comes_From_Source
(N
) then
1759 if Is_Fixed_Point_Type
(Typ
) then
1760 Check_Restriction
(No_Fixed_Point
, N
);
1762 elsif Is_Floating_Point_Type
(Typ
)
1763 and then Typ
/= Universal_Real
1764 and then Typ
/= Any_Real
1766 Check_Restriction
(No_Floating_Point
, N
);
1770 -- Return if already analyzed
1772 if Analyzed
(N
) then
1773 Debug_A_Exit
("resolving ", N
, " (done, already analyzed)");
1776 -- Return if type = Any_Type (previous error encountered)
1778 elsif Etype
(N
) = Any_Type
then
1779 Debug_A_Exit
("resolving ", N
, " (done, Etype = Any_Type)");
1783 Check_Parameterless_Call
(N
);
1785 -- If not overloaded, then we know the type, and all that needs doing
1786 -- is to check that this type is compatible with the context.
1788 if not Is_Overloaded
(N
) then
1789 Found
:= Covers
(Typ
, Etype
(N
));
1790 Expr_Type
:= Etype
(N
);
1792 -- In the overloaded case, we must select the interpretation that
1793 -- is compatible with the context (i.e. the type passed to Resolve)
1796 -- Loop through possible interpretations
1798 Get_First_Interp
(N
, I
, It
);
1799 Interp_Loop
: while Present
(It
.Typ
) loop
1801 -- We are only interested in interpretations that are compatible
1802 -- with the expected type, any other interpretations are ignored.
1804 if not Covers
(Typ
, It
.Typ
) then
1805 if Debug_Flag_V
then
1806 Write_Str
(" interpretation incompatible with context");
1811 -- Skip the current interpretation if it is disabled by an
1812 -- abstract operator. This action is performed only when the
1813 -- type against which we are resolving is the same as the
1814 -- type of the interpretation.
1816 if Ada_Version
>= Ada_05
1817 and then It
.Typ
= Typ
1818 and then Typ
/= Universal_Integer
1819 and then Typ
/= Universal_Real
1820 and then Present
(It
.Abstract_Op
)
1825 -- First matching interpretation
1831 Expr_Type
:= It
.Typ
;
1833 -- Matching interpretation that is not the first, maybe an
1834 -- error, but there are some cases where preference rules are
1835 -- used to choose between the two possibilities. These and
1836 -- some more obscure cases are handled in Disambiguate.
1839 -- If the current statement is part of a predefined library
1840 -- unit, then all interpretations which come from user level
1841 -- packages should not be considered.
1844 and then not Comes_From_Predefined_Lib_Unit
(It
.Nam
)
1849 Error_Msg_Sloc
:= Sloc
(Seen
);
1850 It1
:= Disambiguate
(N
, I1
, I
, Typ
);
1852 -- Disambiguation has succeeded. Skip the remaining
1855 if It1
/= No_Interp
then
1857 Expr_Type
:= It1
.Typ
;
1859 while Present
(It
.Typ
) loop
1860 Get_Next_Interp
(I
, It
);
1864 -- Before we issue an ambiguity complaint, check for
1865 -- the case of a subprogram call where at least one
1866 -- of the arguments is Any_Type, and if so, suppress
1867 -- the message, since it is a cascaded error.
1869 if Nkind
(N
) = N_Function_Call
1870 or else Nkind
(N
) = N_Procedure_Call_Statement
1877 A
:= First_Actual
(N
);
1878 while Present
(A
) loop
1881 if Nkind
(E
) = N_Parameter_Association
then
1882 E
:= Explicit_Actual_Parameter
(E
);
1885 if Etype
(E
) = Any_Type
then
1886 if Debug_Flag_V
then
1887 Write_Str
("Any_Type in call");
1898 elsif Nkind
(N
) in N_Binary_Op
1899 and then (Etype
(Left_Opnd
(N
)) = Any_Type
1900 or else Etype
(Right_Opnd
(N
)) = Any_Type
)
1904 elsif Nkind
(N
) in N_Unary_Op
1905 and then Etype
(Right_Opnd
(N
)) = Any_Type
1910 -- Not that special case, so issue message using the
1911 -- flag Ambiguous to control printing of the header
1912 -- message only at the start of an ambiguous set.
1914 if not Ambiguous
then
1915 if Nkind
(N
) = N_Function_Call
1916 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
1919 ("ambiguous expression "
1920 & "(cannot resolve indirect call)!", N
);
1923 ("ambiguous expression (cannot resolve&)!",
1929 if Nkind
(Parent
(Seen
)) = N_Full_Type_Declaration
then
1931 ("\\possible interpretation (inherited)#!", N
);
1933 Error_Msg_N
("\\possible interpretation#!", N
);
1937 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
1939 -- By default, the error message refers to the candidate
1940 -- interpretation. But if it is a predefined operator, it
1941 -- is implicitly declared at the declaration of the type
1942 -- of the operand. Recover the sloc of that declaration
1943 -- for the error message.
1945 if Nkind
(N
) in N_Op
1946 and then Scope
(It
.Nam
) = Standard_Standard
1947 and then not Is_Overloaded
(Right_Opnd
(N
))
1948 and then Scope
(Base_Type
(Etype
(Right_Opnd
(N
)))) /=
1951 Err_Type
:= First_Subtype
(Etype
(Right_Opnd
(N
)));
1953 if Comes_From_Source
(Err_Type
)
1954 and then Present
(Parent
(Err_Type
))
1956 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
1959 elsif Nkind
(N
) in N_Binary_Op
1960 and then Scope
(It
.Nam
) = Standard_Standard
1961 and then not Is_Overloaded
(Left_Opnd
(N
))
1962 and then Scope
(Base_Type
(Etype
(Left_Opnd
(N
)))) /=
1965 Err_Type
:= First_Subtype
(Etype
(Left_Opnd
(N
)));
1967 if Comes_From_Source
(Err_Type
)
1968 and then Present
(Parent
(Err_Type
))
1970 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
1973 -- If this is an indirect call, use the subprogram_type
1974 -- in the message, to have a meaningful location.
1975 -- Indicate as well if this is an inherited operation,
1976 -- created by a type declaration.
1978 elsif Nkind
(N
) = N_Function_Call
1979 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
1980 and then Is_Type
(It
.Nam
)
1984 Sloc
(Associated_Node_For_Itype
(Err_Type
));
1989 if Nkind
(N
) in N_Op
1990 and then Scope
(It
.Nam
) = Standard_Standard
1991 and then Present
(Err_Type
)
1993 -- Special-case the message for universal_fixed
1994 -- operators, which are not declared with the type
1995 -- of the operand, but appear forever in Standard.
1997 if It
.Typ
= Universal_Fixed
1998 and then Scope
(It
.Nam
) = Standard_Standard
2001 ("\\possible interpretation as " &
2002 "universal_fixed operation " &
2003 "(RM 4.5.5 (19))", N
);
2006 ("\\possible interpretation (predefined)#!", N
);
2010 Nkind
(Parent
(It
.Nam
)) = N_Full_Type_Declaration
2013 ("\\possible interpretation (inherited)#!", N
);
2015 Error_Msg_N
("\\possible interpretation#!", N
);
2021 -- We have a matching interpretation, Expr_Type is the type
2022 -- from this interpretation, and Seen is the entity.
2024 -- For an operator, just set the entity name. The type will be
2025 -- set by the specific operator resolution routine.
2027 if Nkind
(N
) in N_Op
then
2028 Set_Entity
(N
, Seen
);
2029 Generate_Reference
(Seen
, N
);
2031 elsif Nkind
(N
) = N_Character_Literal
then
2032 Set_Etype
(N
, Expr_Type
);
2034 -- For an explicit dereference, attribute reference, range,
2035 -- short-circuit form (which is not an operator node), or call
2036 -- with a name that is an explicit dereference, there is
2037 -- nothing to be done at this point.
2039 elsif Nkind
(N
) = N_Explicit_Dereference
2040 or else Nkind
(N
) = N_Attribute_Reference
2041 or else Nkind
(N
) = N_And_Then
2042 or else Nkind
(N
) = N_Indexed_Component
2043 or else Nkind
(N
) = N_Or_Else
2044 or else Nkind
(N
) = N_Range
2045 or else Nkind
(N
) = N_Selected_Component
2046 or else Nkind
(N
) = N_Slice
2047 or else Nkind
(Name
(N
)) = N_Explicit_Dereference
2051 -- For procedure or function calls, set the type of the name,
2052 -- and also the entity pointer for the prefix
2054 elsif (Nkind
(N
) = N_Procedure_Call_Statement
2055 or else Nkind
(N
) = N_Function_Call
)
2056 and then (Is_Entity_Name
(Name
(N
))
2057 or else Nkind
(Name
(N
)) = N_Operator_Symbol
)
2059 Set_Etype
(Name
(N
), Expr_Type
);
2060 Set_Entity
(Name
(N
), Seen
);
2061 Generate_Reference
(Seen
, Name
(N
));
2063 elsif Nkind
(N
) = N_Function_Call
2064 and then Nkind
(Name
(N
)) = N_Selected_Component
2066 Set_Etype
(Name
(N
), Expr_Type
);
2067 Set_Entity
(Selector_Name
(Name
(N
)), Seen
);
2068 Generate_Reference
(Seen
, Selector_Name
(Name
(N
)));
2070 -- For all other cases, just set the type of the Name
2073 Set_Etype
(Name
(N
), Expr_Type
);
2080 -- Move to next interpretation
2082 exit Interp_Loop
when No
(It
.Typ
);
2084 Get_Next_Interp
(I
, It
);
2085 end loop Interp_Loop
;
2088 -- At this stage Found indicates whether or not an acceptable
2089 -- interpretation exists. If not, then we have an error, except
2090 -- that if the context is Any_Type as a result of some other error,
2091 -- then we suppress the error report.
2094 if Typ
/= Any_Type
then
2096 -- If type we are looking for is Void, then this is the procedure
2097 -- call case, and the error is simply that what we gave is not a
2098 -- procedure name (we think of procedure calls as expressions with
2099 -- types internally, but the user doesn't think of them this way!)
2101 if Typ
= Standard_Void_Type
then
2103 -- Special case message if function used as a procedure
2105 if Nkind
(N
) = N_Procedure_Call_Statement
2106 and then Is_Entity_Name
(Name
(N
))
2107 and then Ekind
(Entity
(Name
(N
))) = E_Function
2110 ("cannot use function & in a procedure call",
2111 Name
(N
), Entity
(Name
(N
)));
2113 -- Otherwise give general message (not clear what cases this
2114 -- covers, but no harm in providing for them!)
2117 Error_Msg_N
("expect procedure name in procedure call", N
);
2122 -- Otherwise we do have a subexpression with the wrong type
2124 -- Check for the case of an allocator which uses an access type
2125 -- instead of the designated type. This is a common error and we
2126 -- specialize the message, posting an error on the operand of the
2127 -- allocator, complaining that we expected the designated type of
2130 elsif Nkind
(N
) = N_Allocator
2131 and then Ekind
(Typ
) in Access_Kind
2132 and then Ekind
(Etype
(N
)) in Access_Kind
2133 and then Designated_Type
(Etype
(N
)) = Typ
2135 Wrong_Type
(Expression
(N
), Designated_Type
(Typ
));
2138 -- Check for view mismatch on Null in instances, for which the
2139 -- view-swapping mechanism has no identifier.
2141 elsif (In_Instance
or else In_Inlined_Body
)
2142 and then (Nkind
(N
) = N_Null
)
2143 and then Is_Private_Type
(Typ
)
2144 and then Is_Access_Type
(Full_View
(Typ
))
2146 Resolve
(N
, Full_View
(Typ
));
2150 -- Check for an aggregate. Sometimes we can get bogus aggregates
2151 -- from misuse of parentheses, and we are about to complain about
2152 -- the aggregate without even looking inside it.
2154 -- Instead, if we have an aggregate of type Any_Composite, then
2155 -- analyze and resolve the component fields, and then only issue
2156 -- another message if we get no errors doing this (otherwise
2157 -- assume that the errors in the aggregate caused the problem).
2159 elsif Nkind
(N
) = N_Aggregate
2160 and then Etype
(N
) = Any_Composite
2162 -- Disable expansion in any case. If there is a type mismatch
2163 -- it may be fatal to try to expand the aggregate. The flag
2164 -- would otherwise be set to false when the error is posted.
2166 Expander_Active
:= False;
2169 procedure Check_Aggr
(Aggr
: Node_Id
);
2170 -- Check one aggregate, and set Found to True if we have a
2171 -- definite error in any of its elements
2173 procedure Check_Elmt
(Aelmt
: Node_Id
);
2174 -- Check one element of aggregate and set Found to True if
2175 -- we definitely have an error in the element.
2181 procedure Check_Aggr
(Aggr
: Node_Id
) is
2185 if Present
(Expressions
(Aggr
)) then
2186 Elmt
:= First
(Expressions
(Aggr
));
2187 while Present
(Elmt
) loop
2193 if Present
(Component_Associations
(Aggr
)) then
2194 Elmt
:= First
(Component_Associations
(Aggr
));
2195 while Present
(Elmt
) loop
2197 -- If this is a default-initialized component, then
2198 -- there is nothing to check. The box will be
2199 -- replaced by the appropriate call during late
2202 if not Box_Present
(Elmt
) then
2203 Check_Elmt
(Expression
(Elmt
));
2215 procedure Check_Elmt
(Aelmt
: Node_Id
) is
2217 -- If we have a nested aggregate, go inside it (to
2218 -- attempt a naked analyze-resolve of the aggregate
2219 -- can cause undesirable cascaded errors). Do not
2220 -- resolve expression if it needs a type from context,
2221 -- as for integer * fixed expression.
2223 if Nkind
(Aelmt
) = N_Aggregate
then
2229 if not Is_Overloaded
(Aelmt
)
2230 and then Etype
(Aelmt
) /= Any_Fixed
2235 if Etype
(Aelmt
) = Any_Type
then
2246 -- If an error message was issued already, Found got reset
2247 -- to True, so if it is still False, issue the standard
2248 -- Wrong_Type message.
2251 if Is_Overloaded
(N
)
2252 and then Nkind
(N
) = N_Function_Call
2255 Subp_Name
: Node_Id
;
2257 if Is_Entity_Name
(Name
(N
)) then
2258 Subp_Name
:= Name
(N
);
2260 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2262 -- Protected operation: retrieve operation name
2264 Subp_Name
:= Selector_Name
(Name
(N
));
2266 raise Program_Error
;
2269 Error_Msg_Node_2
:= Typ
;
2270 Error_Msg_NE
("no visible interpretation of&" &
2271 " matches expected type&", N
, Subp_Name
);
2274 if All_Errors_Mode
then
2276 Index
: Interp_Index
;
2280 Error_Msg_N
("\\possible interpretations:", N
);
2282 Get_First_Interp
(Name
(N
), Index
, It
);
2283 while Present
(It
.Nam
) loop
2284 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2285 Error_Msg_Node_2
:= It
.Nam
;
2287 ("\\ type& for & declared#", N
, It
.Typ
);
2288 Get_Next_Interp
(Index
, It
);
2293 Error_Msg_N
("\use -gnatf for details", N
);
2296 Wrong_Type
(N
, Typ
);
2304 -- Test if we have more than one interpretation for the context
2306 elsif Ambiguous
then
2310 -- Here we have an acceptable interpretation for the context
2313 -- Propagate type information and normalize tree for various
2314 -- predefined operations. If the context only imposes a class of
2315 -- types, rather than a specific type, propagate the actual type
2318 if Typ
= Any_Integer
2319 or else Typ
= Any_Boolean
2320 or else Typ
= Any_Modular
2321 or else Typ
= Any_Real
2322 or else Typ
= Any_Discrete
2324 Ctx_Type
:= Expr_Type
;
2326 -- Any_Fixed is legal in a real context only if a specific
2327 -- fixed point type is imposed. If Norman Cohen can be
2328 -- confused by this, it deserves a separate message.
2331 and then Expr_Type
= Any_Fixed
2333 Error_Msg_N
("illegal context for mixed mode operation", N
);
2334 Set_Etype
(N
, Universal_Real
);
2335 Ctx_Type
:= Universal_Real
;
2339 -- A user-defined operator is tranformed into a function call at
2340 -- this point, so that further processing knows that operators are
2341 -- really operators (i.e. are predefined operators). User-defined
2342 -- operators that are intrinsic are just renamings of the predefined
2343 -- ones, and need not be turned into calls either, but if they rename
2344 -- a different operator, we must transform the node accordingly.
2345 -- Instantiations of Unchecked_Conversion are intrinsic but are
2346 -- treated as functions, even if given an operator designator.
2348 if Nkind
(N
) in N_Op
2349 and then Present
(Entity
(N
))
2350 and then Ekind
(Entity
(N
)) /= E_Operator
2353 if not Is_Predefined_Op
(Entity
(N
)) then
2354 Rewrite_Operator_As_Call
(N
, Entity
(N
));
2356 elsif Present
(Alias
(Entity
(N
)))
2358 Nkind
(Parent
(Parent
(Entity
(N
))))
2359 = N_Subprogram_Renaming_Declaration
2361 Rewrite_Renamed_Operator
(N
, Alias
(Entity
(N
)), Typ
);
2363 -- If the node is rewritten, it will be fully resolved in
2364 -- Rewrite_Renamed_Operator.
2366 if Analyzed
(N
) then
2372 case N_Subexpr
'(Nkind (N)) is
2374 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2376 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2378 when N_And_Then | N_Or_Else
2379 => Resolve_Short_Circuit (N, Ctx_Type);
2381 when N_Attribute_Reference
2382 => Resolve_Attribute (N, Ctx_Type);
2384 when N_Character_Literal
2385 => Resolve_Character_Literal (N, Ctx_Type);
2387 when N_Conditional_Expression
2388 => Resolve_Conditional_Expression (N, Ctx_Type);
2390 when N_Expanded_Name
2391 => Resolve_Entity_Name (N, Ctx_Type);
2393 when N_Extension_Aggregate
2394 => Resolve_Extension_Aggregate (N, Ctx_Type);
2396 when N_Explicit_Dereference
2397 => Resolve_Explicit_Dereference (N, Ctx_Type);
2399 when N_Function_Call
2400 => Resolve_Call (N, Ctx_Type);
2403 => Resolve_Entity_Name (N, Ctx_Type);
2405 when N_Indexed_Component
2406 => Resolve_Indexed_Component (N, Ctx_Type);
2408 when N_Integer_Literal
2409 => Resolve_Integer_Literal (N, Ctx_Type);
2411 when N_Membership_Test
2412 => Resolve_Membership_Op (N, Ctx_Type);
2414 when N_Null => Resolve_Null (N, Ctx_Type);
2416 when N_Op_And | N_Op_Or | N_Op_Xor
2417 => Resolve_Logical_Op (N, Ctx_Type);
2419 when N_Op_Eq | N_Op_Ne
2420 => Resolve_Equality_Op (N, Ctx_Type);
2422 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2423 => Resolve_Comparison_Op (N, Ctx_Type);
2425 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2427 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2428 N_Op_Divide | N_Op_Mod | N_Op_Rem
2430 => Resolve_Arithmetic_Op (N, Ctx_Type);
2432 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2434 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2436 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2437 => Resolve_Unary_Op (N, Ctx_Type);
2439 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2441 when N_Procedure_Call_Statement
2442 => Resolve_Call (N, Ctx_Type);
2444 when N_Operator_Symbol
2445 => Resolve_Operator_Symbol (N, Ctx_Type);
2447 when N_Qualified_Expression
2448 => Resolve_Qualified_Expression (N, Ctx_Type);
2450 when N_Raise_xxx_Error
2451 => Set_Etype (N, Ctx_Type);
2453 when N_Range => Resolve_Range (N, Ctx_Type);
2456 => Resolve_Real_Literal (N, Ctx_Type);
2458 when N_Reference => Resolve_Reference (N, Ctx_Type);
2460 when N_Selected_Component
2461 => Resolve_Selected_Component (N, Ctx_Type);
2463 when N_Slice => Resolve_Slice (N, Ctx_Type);
2465 when N_String_Literal
2466 => Resolve_String_Literal (N, Ctx_Type);
2468 when N_Subprogram_Info
2469 => Resolve_Subprogram_Info (N, Ctx_Type);
2471 when N_Type_Conversion
2472 => Resolve_Type_Conversion (N, Ctx_Type);
2474 when N_Unchecked_Expression =>
2475 Resolve_Unchecked_Expression (N, Ctx_Type);
2477 when N_Unchecked_Type_Conversion =>
2478 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2482 -- If the subexpression was replaced by a non-subexpression, then
2483 -- all we do is to expand it. The only legitimate case we know of
2484 -- is converting procedure call statement to entry call statements,
2485 -- but there may be others, so we are making this test general.
2487 if Nkind (N) not in N_Subexpr then
2488 Debug_A_Exit ("resolving ", N, " (done)");
2493 -- The expression is definitely NOT overloaded at this point, so
2494 -- we reset the Is_Overloaded flag to avoid any confusion when
2495 -- reanalyzing the node.
2497 Set_Is_Overloaded (N, False);
2499 -- Freeze expression type, entity if it is a name, and designated
2500 -- type if it is an allocator (RM 13.14(10,11,13)).
2502 -- Now that the resolution of the type of the node is complete,
2503 -- and we did not detect an error, we can expand this node. We
2504 -- skip the expand call if we are in a default expression, see
2505 -- section "Handling of Default Expressions" in Sem spec.
2507 Debug_A_Exit ("resolving ", N, " (done)");
2509 -- We unconditionally freeze the expression, even if we are in
2510 -- default expression mode (the Freeze_Expression routine tests
2511 -- this flag and only freezes static types if it is set).
2513 Freeze_Expression (N);
2515 -- Now we can do the expansion
2525 -- Version with check(s) suppressed
2527 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2529 if Suppress = All_Checks then
2531 Svg : constant Suppress_Array := Scope_Suppress;
2533 Scope_Suppress := (others => True);
2535 Scope_Suppress := Svg;
2540 Svg : constant Boolean := Scope_Suppress (Suppress);
2542 Scope_Suppress (Suppress) := True;
2544 Scope_Suppress (Suppress) := Svg;
2553 -- Version with implicit type
2555 procedure Resolve (N : Node_Id) is
2557 Resolve (N, Etype (N));
2560 ---------------------
2561 -- Resolve_Actuals --
2562 ---------------------
2564 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2565 Loc : constant Source_Ptr := Sloc (N);
2570 Prev : Node_Id := Empty;
2572 procedure Check_Prefixed_Call;
2573 -- If the original node is an overloaded call in prefix notation,
2574 -- insert an 'Access or a dereference as needed over the first actual
.
2575 -- Try_Object_Operation has already verified that there is a valid
2576 -- interpretation, but the form of the actual can only be determined
2577 -- once the primitive operation is identified.
2579 procedure Insert_Default
;
2580 -- If the actual is missing in a call, insert in the actuals list
2581 -- an instance of the default expression. The insertion is always
2582 -- a named association.
2584 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean;
2585 -- Check whether T1 and T2, or their full views, are derived from a
2586 -- common type. Used to enforce the restrictions on array conversions
2589 -------------------------
2590 -- Check_Prefixed_Call --
2591 -------------------------
2593 procedure Check_Prefixed_Call
is
2594 Act
: constant Node_Id
:= First_Actual
(N
);
2595 A_Type
: constant Entity_Id
:= Etype
(Act
);
2596 F_Type
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
2597 Orig
: constant Node_Id
:= Original_Node
(N
);
2601 -- Check whether the call is a prefixed call, with or without
2602 -- additional actuals.
2604 if Nkind
(Orig
) = N_Selected_Component
2606 (Nkind
(Orig
) = N_Indexed_Component
2607 and then Nkind
(Prefix
(Orig
)) = N_Selected_Component
2608 and then Is_Entity_Name
(Prefix
(Prefix
(Orig
)))
2609 and then Is_Entity_Name
(Act
)
2610 and then Chars
(Act
) = Chars
(Prefix
(Prefix
(Orig
))))
2612 if Is_Access_Type
(A_Type
)
2613 and then not Is_Access_Type
(F_Type
)
2615 -- Introduce dereference on object in prefix
2618 Make_Explicit_Dereference
(Sloc
(Act
),
2619 Prefix
=> Relocate_Node
(Act
));
2620 Rewrite
(Act
, New_A
);
2623 elsif Is_Access_Type
(F_Type
)
2624 and then not Is_Access_Type
(A_Type
)
2626 -- Introduce an implicit 'Access in prefix
2628 if not Is_Aliased_View
(Act
) then
2630 ("object in prefixed call to& must be aliased"
2631 & " (RM-2005 4.3.1 (13))",
2636 Make_Attribute_Reference
(Loc
,
2637 Attribute_Name
=> Name_Access
,
2638 Prefix
=> Relocate_Node
(Act
)));
2643 end Check_Prefixed_Call
;
2645 --------------------
2646 -- Insert_Default --
2647 --------------------
2649 procedure Insert_Default
is
2654 -- Missing argument in call, nothing to insert
2656 if No
(Default_Value
(F
)) then
2660 -- Note that we do a full New_Copy_Tree, so that any associated
2661 -- Itypes are properly copied. This may not be needed any more,
2662 -- but it does no harm as a safety measure! Defaults of a generic
2663 -- formal may be out of bounds of the corresponding actual (see
2664 -- cc1311b) and an additional check may be required.
2669 New_Scope
=> Current_Scope
,
2672 if Is_Concurrent_Type
(Scope
(Nam
))
2673 and then Has_Discriminants
(Scope
(Nam
))
2675 Replace_Actual_Discriminants
(N
, Actval
);
2678 if Is_Overloadable
(Nam
)
2679 and then Present
(Alias
(Nam
))
2681 if Base_Type
(Etype
(F
)) /= Base_Type
(Etype
(Actval
))
2682 and then not Is_Tagged_Type
(Etype
(F
))
2684 -- If default is a real literal, do not introduce a
2685 -- conversion whose effect may depend on the run-time
2686 -- size of universal real.
2688 if Nkind
(Actval
) = N_Real_Literal
then
2689 Set_Etype
(Actval
, Base_Type
(Etype
(F
)));
2691 Actval
:= Unchecked_Convert_To
(Etype
(F
), Actval
);
2695 if Is_Scalar_Type
(Etype
(F
)) then
2696 Enable_Range_Check
(Actval
);
2699 Set_Parent
(Actval
, N
);
2701 -- Resolve aggregates with their base type, to avoid scope
2702 -- anomalies: the subtype was first built in the suprogram
2703 -- declaration, and the current call may be nested.
2705 if Nkind
(Actval
) = N_Aggregate
2706 and then Has_Discriminants
(Etype
(Actval
))
2708 Analyze_And_Resolve
(Actval
, Base_Type
(Etype
(Actval
)));
2710 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
2714 Set_Parent
(Actval
, N
);
2716 -- See note above concerning aggregates
2718 if Nkind
(Actval
) = N_Aggregate
2719 and then Has_Discriminants
(Etype
(Actval
))
2721 Analyze_And_Resolve
(Actval
, Base_Type
(Etype
(Actval
)));
2723 -- Resolve entities with their own type, which may differ
2724 -- from the type of a reference in a generic context (the
2725 -- view swapping mechanism did not anticipate the re-analysis
2726 -- of default values in calls).
2728 elsif Is_Entity_Name
(Actval
) then
2729 Analyze_And_Resolve
(Actval
, Etype
(Entity
(Actval
)));
2732 Analyze_And_Resolve
(Actval
, Etype
(Actval
));
2736 -- If default is a tag indeterminate function call, propagate
2737 -- tag to obtain proper dispatching.
2739 if Is_Controlling_Formal
(F
)
2740 and then Nkind
(Default_Value
(F
)) = N_Function_Call
2742 Set_Is_Controlling_Actual
(Actval
);
2747 -- If the default expression raises constraint error, then just
2748 -- silently replace it with an N_Raise_Constraint_Error node,
2749 -- since we already gave the warning on the subprogram spec.
2751 if Raises_Constraint_Error
(Actval
) then
2753 Make_Raise_Constraint_Error
(Loc
,
2754 Reason
=> CE_Range_Check_Failed
));
2755 Set_Raises_Constraint_Error
(Actval
);
2756 Set_Etype
(Actval
, Etype
(F
));
2760 Make_Parameter_Association
(Loc
,
2761 Explicit_Actual_Parameter
=> Actval
,
2762 Selector_Name
=> Make_Identifier
(Loc
, Chars
(F
)));
2764 -- Case of insertion is first named actual
2766 if No
(Prev
) or else
2767 Nkind
(Parent
(Prev
)) /= N_Parameter_Association
2769 Set_Next_Named_Actual
(Assoc
, First_Named_Actual
(N
));
2770 Set_First_Named_Actual
(N
, Actval
);
2773 if No
(Parameter_Associations
(N
)) then
2774 Set_Parameter_Associations
(N
, New_List
(Assoc
));
2776 Append
(Assoc
, Parameter_Associations
(N
));
2780 Insert_After
(Prev
, Assoc
);
2783 -- Case of insertion is not first named actual
2786 Set_Next_Named_Actual
2787 (Assoc
, Next_Named_Actual
(Parent
(Prev
)));
2788 Set_Next_Named_Actual
(Parent
(Prev
), Actval
);
2789 Append
(Assoc
, Parameter_Associations
(N
));
2792 Mark_Rewrite_Insertion
(Assoc
);
2793 Mark_Rewrite_Insertion
(Actval
);
2802 function Same_Ancestor
(T1
, T2
: Entity_Id
) return Boolean is
2803 FT1
: Entity_Id
:= T1
;
2804 FT2
: Entity_Id
:= T2
;
2807 if Is_Private_Type
(T1
)
2808 and then Present
(Full_View
(T1
))
2810 FT1
:= Full_View
(T1
);
2813 if Is_Private_Type
(T2
)
2814 and then Present
(Full_View
(T2
))
2816 FT2
:= Full_View
(T2
);
2819 return Root_Type
(Base_Type
(FT1
)) = Root_Type
(Base_Type
(FT2
));
2822 -- Start of processing for Resolve_Actuals
2825 if Present
(First_Actual
(N
)) then
2826 Check_Prefixed_Call
;
2829 A
:= First_Actual
(N
);
2830 F
:= First_Formal
(Nam
);
2831 while Present
(F
) loop
2832 if No
(A
) and then Needs_No_Actuals
(Nam
) then
2835 -- If we have an error in any actual or formal, indicated by
2836 -- a type of Any_Type, then abandon resolution attempt, and
2837 -- set result type to Any_Type.
2839 elsif (Present
(A
) and then Etype
(A
) = Any_Type
)
2840 or else Etype
(F
) = Any_Type
2842 Set_Etype
(N
, Any_Type
);
2846 -- Case where actual is present
2849 and then (Nkind
(Parent
(A
)) /= N_Parameter_Association
2851 Chars
(Selector_Name
(Parent
(A
))) = Chars
(F
))
2853 -- If the formal is Out or In_Out, do not resolve and expand the
2854 -- conversion, because it is subsequently expanded into explicit
2855 -- temporaries and assignments. However, the object of the
2856 -- conversion can be resolved. An exception is the case of tagged
2857 -- type conversion with a class-wide actual. In that case we want
2858 -- the tag check to occur and no temporary will be needed (no
2859 -- representation change can occur) and the parameter is passed by
2860 -- reference, so we go ahead and resolve the type conversion.
2861 -- Another exception is the case of reference to component or
2862 -- subcomponent of a bit-packed array, in which case we want to
2863 -- defer expansion to the point the in and out assignments are
2866 if Ekind
(F
) /= E_In_Parameter
2867 and then Nkind
(A
) = N_Type_Conversion
2868 and then not Is_Class_Wide_Type
(Etype
(Expression
(A
)))
2870 if Ekind
(F
) = E_In_Out_Parameter
2871 and then Is_Array_Type
(Etype
(F
))
2873 if Has_Aliased_Components
(Etype
(Expression
(A
)))
2874 /= Has_Aliased_Components
(Etype
(F
))
2876 if Ada_Version
< Ada_05
then
2878 ("both component types in a view conversion must be"
2879 & " aliased, or neither", A
);
2881 -- Ada 2005: rule is relaxed (see AI-363)
2883 elsif Has_Aliased_Components
(Etype
(F
))
2885 not Has_Aliased_Components
(Etype
(Expression
(A
)))
2888 ("view conversion operand must have aliased " &
2891 ("\since target type has aliased components", N
);
2894 elsif not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
2896 (Is_By_Reference_Type
(Etype
(F
))
2897 or else Is_By_Reference_Type
(Etype
(Expression
(A
))))
2900 ("view conversion between unrelated by reference " &
2901 "array types not allowed (\'A'I-00246)", A
);
2905 if (Conversion_OK
(A
)
2906 or else Valid_Conversion
(A
, Etype
(A
), Expression
(A
)))
2907 and then not Is_Ref_To_Bit_Packed_Array
(Expression
(A
))
2909 Resolve
(Expression
(A
));
2912 -- If the actual is a function call that returns a limited
2913 -- unconstrained object that needs finalization, create a
2914 -- transient scope for it, so that it can receive the proper
2915 -- finalization list.
2917 elsif Nkind
(A
) = N_Function_Call
2918 and then Is_Limited_Record
(Etype
(F
))
2919 and then not Is_Constrained
(Etype
(F
))
2920 and then Expander_Active
2922 (Is_Controlled
(Etype
(F
)) or else Has_Task
(Etype
(F
)))
2924 Establish_Transient_Scope
(A
, False);
2927 if Nkind
(A
) = N_Type_Conversion
2928 and then Is_Array_Type
(Etype
(F
))
2929 and then not Same_Ancestor
(Etype
(F
), Etype
(Expression
(A
)))
2931 (Is_Limited_Type
(Etype
(F
))
2932 or else Is_Limited_Type
(Etype
(Expression
(A
))))
2935 ("conversion between unrelated limited array types " &
2936 "not allowed (\A\I-00246)", A
);
2938 if Is_Limited_Type
(Etype
(F
)) then
2939 Explain_Limited_Type
(Etype
(F
), A
);
2942 if Is_Limited_Type
(Etype
(Expression
(A
))) then
2943 Explain_Limited_Type
(Etype
(Expression
(A
)), A
);
2947 -- (Ada 2005: AI-251): If the actual is an allocator whose
2948 -- directly designated type is a class-wide interface, we build
2949 -- an anonymous access type to use it as the type of the
2950 -- allocator. Later, when the subprogram call is expanded, if
2951 -- the interface has a secondary dispatch table the expander
2952 -- will add a type conversion to force the correct displacement
2955 if Nkind
(A
) = N_Allocator
then
2957 DDT
: constant Entity_Id
:=
2958 Directly_Designated_Type
(Base_Type
(Etype
(F
)));
2959 New_Itype
: Entity_Id
;
2961 if Is_Class_Wide_Type
(DDT
)
2962 and then Is_Interface
(DDT
)
2964 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, A
);
2965 Set_Etype
(New_Itype
, Etype
(A
));
2966 Init_Size_Align
(New_Itype
);
2967 Set_Directly_Designated_Type
(New_Itype
,
2968 Directly_Designated_Type
(Etype
(A
)));
2969 Set_Etype
(A
, New_Itype
);
2972 -- Ada 2005, AI-162:If the actual is an allocator, the
2973 -- innermost enclosing statement is the master of the
2974 -- created object. This needs to be done with expansion
2975 -- enabled only, otherwise the transient scope will not
2976 -- be removed in the expansion of the wrapped construct.
2978 if (Is_Controlled
(DDT
)
2979 or else Has_Task
(DDT
))
2980 and then Expander_Active
2982 Establish_Transient_Scope
(A
, False);
2987 -- (Ada 2005): The call may be to a primitive operation of
2988 -- a tagged synchronized type, declared outside of the type.
2989 -- In this case the controlling actual must be converted to
2990 -- its corresponding record type, which is the formal type.
2992 if Is_Concurrent_Type
(Etype
(A
))
2993 and then Etype
(F
) = Corresponding_Record_Type
(Etype
(A
))
2996 Unchecked_Convert_To
2997 (Corresponding_Record_Type
(Etype
(A
)), A
));
3000 Resolve
(A
, Etype
(F
));
3006 -- Perform error checks for IN and IN OUT parameters
3008 if Ekind
(F
) /= E_Out_Parameter
then
3010 -- Check unset reference. For scalar parameters, it is clearly
3011 -- wrong to pass an uninitialized value as either an IN or
3012 -- IN-OUT parameter. For composites, it is also clearly an
3013 -- error to pass a completely uninitialized value as an IN
3014 -- parameter, but the case of IN OUT is trickier. We prefer
3015 -- not to give a warning here. For example, suppose there is
3016 -- a routine that sets some component of a record to False.
3017 -- It is perfectly reasonable to make this IN-OUT and allow
3018 -- either initialized or uninitialized records to be passed
3021 -- For partially initialized composite values, we also avoid
3022 -- warnings, since it is quite likely that we are passing a
3023 -- partially initialized value and only the initialized fields
3024 -- will in fact be read in the subprogram.
3026 if Is_Scalar_Type
(A_Typ
)
3027 or else (Ekind
(F
) = E_In_Parameter
3028 and then not Is_Partially_Initialized_Type
(A_Typ
))
3030 Check_Unset_Reference
(A
);
3033 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3034 -- actual to a nested call, since this is case of reading an
3035 -- out parameter, which is not allowed.
3037 if Ada_Version
= Ada_83
3038 and then Is_Entity_Name
(A
)
3039 and then Ekind
(Entity
(A
)) = E_Out_Parameter
3041 Error_Msg_N
("(Ada 83) illegal reading of out parameter", A
);
3045 if Ekind
(F
) /= E_In_Parameter
3046 and then not Is_OK_Variable_For_Out_Formal
(A
)
3048 Error_Msg_NE
("actual for& must be a variable", A
, F
);
3050 if Is_Entity_Name
(A
) then
3051 Kill_Checks
(Entity
(A
));
3057 if Etype
(A
) = Any_Type
then
3058 Set_Etype
(N
, Any_Type
);
3062 -- Apply appropriate range checks for in, out, and in-out
3063 -- parameters. Out and in-out parameters also need a separate
3064 -- check, if there is a type conversion, to make sure the return
3065 -- value meets the constraints of the variable before the
3068 -- Gigi looks at the check flag and uses the appropriate types.
3069 -- For now since one flag is used there is an optimization which
3070 -- might not be done in the In Out case since Gigi does not do
3071 -- any analysis. More thought required about this ???
3073 if Ekind
(F
) = E_In_Parameter
3074 or else Ekind
(F
) = E_In_Out_Parameter
3076 if Is_Scalar_Type
(Etype
(A
)) then
3077 Apply_Scalar_Range_Check
(A
, F_Typ
);
3079 elsif Is_Array_Type
(Etype
(A
)) then
3080 Apply_Length_Check
(A
, F_Typ
);
3082 elsif Is_Record_Type
(F_Typ
)
3083 and then Has_Discriminants
(F_Typ
)
3084 and then Is_Constrained
(F_Typ
)
3085 and then (not Is_Derived_Type
(F_Typ
)
3086 or else Comes_From_Source
(Nam
))
3088 Apply_Discriminant_Check
(A
, F_Typ
);
3090 elsif Is_Access_Type
(F_Typ
)
3091 and then Is_Array_Type
(Designated_Type
(F_Typ
))
3092 and then Is_Constrained
(Designated_Type
(F_Typ
))
3094 Apply_Length_Check
(A
, F_Typ
);
3096 elsif Is_Access_Type
(F_Typ
)
3097 and then Has_Discriminants
(Designated_Type
(F_Typ
))
3098 and then Is_Constrained
(Designated_Type
(F_Typ
))
3100 Apply_Discriminant_Check
(A
, F_Typ
);
3103 Apply_Range_Check
(A
, F_Typ
);
3106 -- Ada 2005 (AI-231)
3108 if Ada_Version
>= Ada_05
3109 and then Is_Access_Type
(F_Typ
)
3110 and then Can_Never_Be_Null
(F_Typ
)
3111 and then Known_Null
(A
)
3113 Apply_Compile_Time_Constraint_Error
3115 Msg
=> "(Ada 2005) null not allowed in "
3116 & "null-excluding formal?",
3117 Reason
=> CE_Null_Not_Allowed
);
3121 if Ekind
(F
) = E_Out_Parameter
3122 or else Ekind
(F
) = E_In_Out_Parameter
3124 if Nkind
(A
) = N_Type_Conversion
then
3125 if Is_Scalar_Type
(A_Typ
) then
3126 Apply_Scalar_Range_Check
3127 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
3130 (Expression
(A
), Etype
(Expression
(A
)), A_Typ
);
3134 if Is_Scalar_Type
(F_Typ
) then
3135 Apply_Scalar_Range_Check
(A
, A_Typ
, F_Typ
);
3137 elsif Is_Array_Type
(F_Typ
)
3138 and then Ekind
(F
) = E_Out_Parameter
3140 Apply_Length_Check
(A
, F_Typ
);
3143 Apply_Range_Check
(A
, A_Typ
, F_Typ
);
3148 -- An actual associated with an access parameter is implicitly
3149 -- converted to the anonymous access type of the formal and
3150 -- must satisfy the legality checks for access conversions.
3152 if Ekind
(F_Typ
) = E_Anonymous_Access_Type
then
3153 if not Valid_Conversion
(A
, F_Typ
, A
) then
3155 ("invalid implicit conversion for access parameter", A
);
3159 -- Check bad case of atomic/volatile argument (RM C.6(12))
3161 if Is_By_Reference_Type
(Etype
(F
))
3162 and then Comes_From_Source
(N
)
3164 if Is_Atomic_Object
(A
)
3165 and then not Is_Atomic
(Etype
(F
))
3168 ("cannot pass atomic argument to non-atomic formal",
3171 elsif Is_Volatile_Object
(A
)
3172 and then not Is_Volatile
(Etype
(F
))
3175 ("cannot pass volatile argument to non-volatile formal",
3180 -- Check that subprograms don't have improper controlling
3181 -- arguments (RM 3.9.2 (9))
3183 -- A primitive operation may have an access parameter of an
3184 -- incomplete tagged type, but a dispatching call is illegal
3185 -- if the type is still incomplete.
3187 if Is_Controlling_Formal
(F
) then
3188 Set_Is_Controlling_Actual
(A
);
3190 if Ekind
(Etype
(F
)) = E_Anonymous_Access_Type
then
3192 Desig
: constant Entity_Id
:= Designated_Type
(Etype
(F
));
3194 if Ekind
(Desig
) = E_Incomplete_Type
3195 and then No
(Full_View
(Desig
))
3196 and then No
(Non_Limited_View
(Desig
))
3199 ("premature use of incomplete type& " &
3200 "in dispatching call", A
, Desig
);
3205 elsif Nkind
(A
) = N_Explicit_Dereference
then
3206 Validate_Remote_Access_To_Class_Wide_Type
(A
);
3209 if (Is_Class_Wide_Type
(A_Typ
) or else Is_Dynamically_Tagged
(A
))
3210 and then not Is_Class_Wide_Type
(F_Typ
)
3211 and then not Is_Controlling_Formal
(F
)
3213 Error_Msg_N
("class-wide argument not allowed here!", A
);
3215 if Is_Subprogram
(Nam
)
3216 and then Comes_From_Source
(Nam
)
3218 Error_Msg_Node_2
:= F_Typ
;
3220 ("& is not a dispatching operation of &!", A
, Nam
);
3223 elsif Is_Access_Type
(A_Typ
)
3224 and then Is_Access_Type
(F_Typ
)
3225 and then Ekind
(F_Typ
) /= E_Access_Subprogram_Type
3226 and then Ekind
(F_Typ
) /= E_Anonymous_Access_Subprogram_Type
3227 and then (Is_Class_Wide_Type
(Designated_Type
(A_Typ
))
3228 or else (Nkind
(A
) = N_Attribute_Reference
3230 Is_Class_Wide_Type
(Etype
(Prefix
(A
)))))
3231 and then not Is_Class_Wide_Type
(Designated_Type
(F_Typ
))
3232 and then not Is_Controlling_Formal
(F
)
3235 ("access to class-wide argument not allowed here!", A
);
3237 if Is_Subprogram
(Nam
)
3238 and then Comes_From_Source
(Nam
)
3240 Error_Msg_Node_2
:= Designated_Type
(F_Typ
);
3242 ("& is not a dispatching operation of &!", A
, Nam
);
3248 -- If it is a named association, treat the selector_name as
3249 -- a proper identifier, and mark the corresponding entity.
3251 if Nkind
(Parent
(A
)) = N_Parameter_Association
then
3252 Set_Entity
(Selector_Name
(Parent
(A
)), F
);
3253 Generate_Reference
(F
, Selector_Name
(Parent
(A
)));
3254 Set_Etype
(Selector_Name
(Parent
(A
)), F_Typ
);
3255 Generate_Reference
(F_Typ
, N
, ' ');
3260 if Ekind
(F
) /= E_Out_Parameter
then
3261 Check_Unset_Reference
(A
);
3266 -- Case where actual is not present
3274 end Resolve_Actuals
;
3276 -----------------------
3277 -- Resolve_Allocator --
3278 -----------------------
3280 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
) is
3281 E
: constant Node_Id
:= Expression
(N
);
3283 Discrim
: Entity_Id
;
3286 Assoc
: Node_Id
:= Empty
;
3289 procedure Check_Allocator_Discrim_Accessibility
3290 (Disc_Exp
: Node_Id
;
3291 Alloc_Typ
: Entity_Id
);
3292 -- Check that accessibility level associated with an access discriminant
3293 -- initialized in an allocator by the expression Disc_Exp is not deeper
3294 -- than the level of the allocator type Alloc_Typ. An error message is
3295 -- issued if this condition is violated. Specialized checks are done for
3296 -- the cases of a constraint expression which is an access attribute or
3297 -- an access discriminant.
3299 function In_Dispatching_Context
return Boolean;
3300 -- If the allocator is an actual in a call, it is allowed to be class-
3301 -- wide when the context is not because it is a controlling actual.
3303 procedure Propagate_Coextensions
(Root
: Node_Id
);
3304 -- Propagate all nested coextensions which are located one nesting
3305 -- level down the tree to the node Root. Example:
3308 -- Level_1_Coextension
3309 -- Level_2_Coextension
3311 -- The algorithm is paired with delay actions done by the Expander. In
3312 -- the above example, assume all coextensions are controlled types.
3313 -- The cycle of analysis, resolution and expansion will yield:
3315 -- 1) Analyze Top_Record
3316 -- 2) Analyze Level_1_Coextension
3317 -- 3) Analyze Level_2_Coextension
3318 -- 4) Resolve Level_2_Coextnesion. The allocator is marked as a
3320 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3321 -- generated to capture the allocated object. Temp_1 is attached
3322 -- to the coextension chain of Level_2_Coextension.
3323 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3324 -- coextension. A forward tree traversal is performed which finds
3325 -- Level_2_Coextension's list and copies its contents into its
3327 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3328 -- generated to capture the allocated object. Temp_2 is attached
3329 -- to the coextension chain of Level_1_Coextension. Currently, the
3330 -- contents of the list are [Temp_2, Temp_1].
3331 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3332 -- finds Level_1_Coextension's list and copies its contents into
3334 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3335 -- Temp_2 and attach them to Top_Record's finalization list.
3337 -------------------------------------------
3338 -- Check_Allocator_Discrim_Accessibility --
3339 -------------------------------------------
3341 procedure Check_Allocator_Discrim_Accessibility
3342 (Disc_Exp
: Node_Id
;
3343 Alloc_Typ
: Entity_Id
)
3346 if Type_Access_Level
(Etype
(Disc_Exp
)) >
3347 Type_Access_Level
(Alloc_Typ
)
3350 ("operand type has deeper level than allocator type", Disc_Exp
);
3352 -- When the expression is an Access attribute the level of the prefix
3353 -- object must not be deeper than that of the allocator's type.
3355 elsif Nkind
(Disc_Exp
) = N_Attribute_Reference
3356 and then Get_Attribute_Id
(Attribute_Name
(Disc_Exp
))
3358 and then Object_Access_Level
(Prefix
(Disc_Exp
))
3359 > Type_Access_Level
(Alloc_Typ
)
3362 ("prefix of attribute has deeper level than allocator type",
3365 -- When the expression is an access discriminant the check is against
3366 -- the level of the prefix object.
3368 elsif Ekind
(Etype
(Disc_Exp
)) = E_Anonymous_Access_Type
3369 and then Nkind
(Disc_Exp
) = N_Selected_Component
3370 and then Object_Access_Level
(Prefix
(Disc_Exp
))
3371 > Type_Access_Level
(Alloc_Typ
)
3374 ("access discriminant has deeper level than allocator type",
3377 -- All other cases are legal
3382 end Check_Allocator_Discrim_Accessibility
;
3384 ----------------------------
3385 -- In_Dispatching_Context --
3386 ----------------------------
3388 function In_Dispatching_Context
return Boolean is
3389 Par
: constant Node_Id
:= Parent
(N
);
3391 return (Nkind
(Par
) = N_Function_Call
3392 or else Nkind
(Par
) = N_Procedure_Call_Statement
)
3393 and then Is_Entity_Name
(Name
(Par
))
3394 and then Is_Dispatching_Operation
(Entity
(Name
(Par
)));
3395 end In_Dispatching_Context
;
3397 ----------------------------
3398 -- Propagate_Coextensions --
3399 ----------------------------
3401 procedure Propagate_Coextensions
(Root
: Node_Id
) is
3403 procedure Copy_List
(From
: Elist_Id
; To
: Elist_Id
);
3404 -- Copy the contents of list From into list To, preserving the
3405 -- order of elements.
3407 function Process_Allocator
(Nod
: Node_Id
) return Traverse_Result
;
3408 -- Recognize an allocator or a rewritten allocator node and add it
3409 -- allong with its nested coextensions to the list of Root.
3415 procedure Copy_List
(From
: Elist_Id
; To
: Elist_Id
) is
3416 From_Elmt
: Elmt_Id
;
3418 From_Elmt
:= First_Elmt
(From
);
3419 while Present
(From_Elmt
) loop
3420 Append_Elmt
(Node
(From_Elmt
), To
);
3421 Next_Elmt
(From_Elmt
);
3425 -----------------------
3426 -- Process_Allocator --
3427 -----------------------
3429 function Process_Allocator
(Nod
: Node_Id
) return Traverse_Result
is
3430 Orig_Nod
: Node_Id
:= Nod
;
3433 -- This is a possible rewritten subtype indication allocator. Any
3434 -- nested coextensions will appear as discriminant constraints.
3436 if Nkind
(Nod
) = N_Identifier
3437 and then Present
(Original_Node
(Nod
))
3438 and then Nkind
(Original_Node
(Nod
)) = N_Subtype_Indication
3442 Discr_Elmt
: Elmt_Id
;
3445 if Is_Record_Type
(Entity
(Nod
)) then
3447 First_Elmt
(Discriminant_Constraint
(Entity
(Nod
)));
3448 while Present
(Discr_Elmt
) loop
3449 Discr
:= Node
(Discr_Elmt
);
3451 if Nkind
(Discr
) = N_Identifier
3452 and then Present
(Original_Node
(Discr
))
3453 and then Nkind
(Original_Node
(Discr
)) = N_Allocator
3454 and then Present
(Coextensions
(
3455 Original_Node
(Discr
)))
3457 if No
(Coextensions
(Root
)) then
3458 Set_Coextensions
(Root
, New_Elmt_List
);
3462 (From
=> Coextensions
(Original_Node
(Discr
)),
3463 To
=> Coextensions
(Root
));
3466 Next_Elmt
(Discr_Elmt
);
3469 -- There is no need to continue the traversal of this
3470 -- subtree since all the information has already been
3477 -- Case of either a stand alone allocator or a rewritten allocator
3478 -- with an aggregate.
3481 if Present
(Original_Node
(Nod
)) then
3482 Orig_Nod
:= Original_Node
(Nod
);
3485 if Nkind
(Orig_Nod
) = N_Allocator
then
3487 -- Propagate the list of nested coextensions to the Root
3488 -- allocator. This is done through list copy since a single
3489 -- allocator may have multiple coextensions. Do not touch
3490 -- coextensions roots.
3492 if not Is_Coextension_Root
(Orig_Nod
)
3493 and then Present
(Coextensions
(Orig_Nod
))
3495 if No
(Coextensions
(Root
)) then
3496 Set_Coextensions
(Root
, New_Elmt_List
);
3500 (From
=> Coextensions
(Orig_Nod
),
3501 To
=> Coextensions
(Root
));
3504 -- There is no need to continue the traversal of this
3505 -- subtree since all the information has already been
3512 -- Keep on traversing, looking for the next allocator
3515 end Process_Allocator
;
3517 procedure Process_Allocators
is
3518 new Traverse_Proc
(Process_Allocator
);
3520 -- Start of processing for Propagate_Coextensions
3523 Process_Allocators
(Expression
(Root
));
3524 end Propagate_Coextensions
;
3526 -- Start of processing for Resolve_Allocator
3529 -- Replace general access with specific type
3531 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
3532 Set_Etype
(N
, Base_Type
(Typ
));
3535 if Is_Abstract_Type
(Typ
) then
3536 Error_Msg_N
("type of allocator cannot be abstract", N
);
3539 -- For qualified expression, resolve the expression using the
3540 -- given subtype (nothing to do for type mark, subtype indication)
3542 if Nkind
(E
) = N_Qualified_Expression
then
3543 if Is_Class_Wide_Type
(Etype
(E
))
3544 and then not Is_Class_Wide_Type
(Designated_Type
(Typ
))
3545 and then not In_Dispatching_Context
3548 ("class-wide allocator not allowed for this access type", N
);
3551 Resolve
(Expression
(E
), Etype
(E
));
3552 Check_Unset_Reference
(Expression
(E
));
3554 -- A qualified expression requires an exact match of the type,
3555 -- class-wide matching is not allowed.
3557 if (Is_Class_Wide_Type
(Etype
(Expression
(E
)))
3558 or else Is_Class_Wide_Type
(Etype
(E
)))
3559 and then Base_Type
(Etype
(Expression
(E
))) /= Base_Type
(Etype
(E
))
3561 Wrong_Type
(Expression
(E
), Etype
(E
));
3564 -- A special accessibility check is needed for allocators that
3565 -- constrain access discriminants. The level of the type of the
3566 -- expression used to constrain an access discriminant cannot be
3567 -- deeper than the type of the allocator (in constrast to access
3568 -- parameters, where the level of the actual can be arbitrary).
3570 -- We can't use Valid_Conversion to perform this check because
3571 -- in general the type of the allocator is unrelated to the type
3572 -- of the access discriminant.
3574 if Ekind
(Typ
) /= E_Anonymous_Access_Type
3575 or else Is_Local_Anonymous_Access
(Typ
)
3577 Subtyp
:= Entity
(Subtype_Mark
(E
));
3579 Aggr
:= Original_Node
(Expression
(E
));
3581 if Has_Discriminants
(Subtyp
)
3583 (Nkind
(Aggr
) = N_Aggregate
3585 Nkind
(Aggr
) = N_Extension_Aggregate
)
3587 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
3589 -- Get the first component expression of the aggregate
3591 if Present
(Expressions
(Aggr
)) then
3592 Disc_Exp
:= First
(Expressions
(Aggr
));
3594 elsif Present
(Component_Associations
(Aggr
)) then
3595 Assoc
:= First
(Component_Associations
(Aggr
));
3597 if Present
(Assoc
) then
3598 Disc_Exp
:= Expression
(Assoc
);
3607 while Present
(Discrim
) and then Present
(Disc_Exp
) loop
3608 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
3609 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
3612 Next_Discriminant
(Discrim
);
3614 if Present
(Discrim
) then
3615 if Present
(Assoc
) then
3617 Disc_Exp
:= Expression
(Assoc
);
3619 elsif Present
(Next
(Disc_Exp
)) then
3623 Assoc
:= First
(Component_Associations
(Aggr
));
3625 if Present
(Assoc
) then
3626 Disc_Exp
:= Expression
(Assoc
);
3636 -- For a subtype mark or subtype indication, freeze the subtype
3639 Freeze_Expression
(E
);
3641 if Is_Access_Constant
(Typ
) and then not No_Initialization
(N
) then
3643 ("initialization required for access-to-constant allocator", N
);
3646 -- A special accessibility check is needed for allocators that
3647 -- constrain access discriminants. The level of the type of the
3648 -- expression used to constrain an access discriminant cannot be
3649 -- deeper than the type of the allocator (in constrast to access
3650 -- parameters, where the level of the actual can be arbitrary).
3651 -- We can't use Valid_Conversion to perform this check because
3652 -- in general the type of the allocator is unrelated to the type
3653 -- of the access discriminant.
3655 if Nkind
(Original_Node
(E
)) = N_Subtype_Indication
3656 and then (Ekind
(Typ
) /= E_Anonymous_Access_Type
3657 or else Is_Local_Anonymous_Access
(Typ
))
3659 Subtyp
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
3661 if Has_Discriminants
(Subtyp
) then
3662 Discrim
:= First_Discriminant
(Base_Type
(Subtyp
));
3663 Constr
:= First
(Constraints
(Constraint
(Original_Node
(E
))));
3664 while Present
(Discrim
) and then Present
(Constr
) loop
3665 if Ekind
(Etype
(Discrim
)) = E_Anonymous_Access_Type
then
3666 if Nkind
(Constr
) = N_Discriminant_Association
then
3667 Disc_Exp
:= Original_Node
(Expression
(Constr
));
3669 Disc_Exp
:= Original_Node
(Constr
);
3672 Check_Allocator_Discrim_Accessibility
(Disc_Exp
, Typ
);
3675 Next_Discriminant
(Discrim
);
3682 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
3683 -- check that the level of the type of the created object is not deeper
3684 -- than the level of the allocator's access type, since extensions can
3685 -- now occur at deeper levels than their ancestor types. This is a
3686 -- static accessibility level check; a run-time check is also needed in
3687 -- the case of an initialized allocator with a class-wide argument (see
3688 -- Expand_Allocator_Expression).
3690 if Ada_Version
>= Ada_05
3691 and then Is_Class_Wide_Type
(Designated_Type
(Typ
))
3694 Exp_Typ
: Entity_Id
;
3697 if Nkind
(E
) = N_Qualified_Expression
then
3698 Exp_Typ
:= Etype
(E
);
3699 elsif Nkind
(E
) = N_Subtype_Indication
then
3700 Exp_Typ
:= Entity
(Subtype_Mark
(Original_Node
(E
)));
3702 Exp_Typ
:= Entity
(E
);
3705 if Type_Access_Level
(Exp_Typ
) > Type_Access_Level
(Typ
) then
3706 if In_Instance_Body
then
3707 Error_Msg_N
("?type in allocator has deeper level than" &
3708 " designated class-wide type", E
);
3709 Error_Msg_N
("\?Program_Error will be raised at run time",
3712 Make_Raise_Program_Error
(Sloc
(N
),
3713 Reason
=> PE_Accessibility_Check_Failed
));
3716 -- Do not apply Ada 2005 accessibility checks on a class-wide
3717 -- allocator if the type given in the allocator is a formal
3718 -- type. A run-time check will be performed in the instance.
3720 elsif not Is_Generic_Type
(Exp_Typ
) then
3721 Error_Msg_N
("type in allocator has deeper level than" &
3722 " designated class-wide type", E
);
3728 -- Check for allocation from an empty storage pool
3730 if No_Pool_Assigned
(Typ
) then
3732 Loc
: constant Source_Ptr
:= Sloc
(N
);
3734 Error_Msg_N
("?allocation from empty storage pool!", N
);
3735 Error_Msg_N
("\?Storage_Error will be raised at run time!", N
);
3737 Make_Raise_Storage_Error
(Loc
,
3738 Reason
=> SE_Empty_Storage_Pool
));
3741 -- If the context is an unchecked conversion, as may happen within
3742 -- an inlined subprogram, the allocator is being resolved with its
3743 -- own anonymous type. In that case, if the target type has a specific
3744 -- storage pool, it must be inherited explicitly by the allocator type.
3746 elsif Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
3747 and then No
(Associated_Storage_Pool
(Typ
))
3749 Set_Associated_Storage_Pool
3750 (Typ
, Associated_Storage_Pool
(Etype
(Parent
(N
))));
3753 -- An erroneous allocator may be rewritten as a raise Program_Error
3756 if Nkind
(N
) = N_Allocator
then
3758 -- An anonymous access discriminant is the definition of a
3761 if Ekind
(Typ
) = E_Anonymous_Access_Type
3762 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
3763 N_Discriminant_Specification
3765 -- Avoid marking an allocator as a dynamic coextension if it is
3766 -- within a static construct.
3768 if not Is_Static_Coextension
(N
) then
3769 Set_Is_Dynamic_Coextension
(N
);
3772 -- Cleanup for potential static coextensions
3775 Set_Is_Dynamic_Coextension
(N
, False);
3776 Set_Is_Static_Coextension
(N
, False);
3779 -- There is no need to propagate any nested coextensions if they
3780 -- are marked as static since they will be rewritten on the spot.
3782 if not Is_Static_Coextension
(N
) then
3783 Propagate_Coextensions
(N
);
3786 end Resolve_Allocator
;
3788 ---------------------------
3789 -- Resolve_Arithmetic_Op --
3790 ---------------------------
3792 -- Used for resolving all arithmetic operators except exponentiation
3794 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
3795 L
: constant Node_Id
:= Left_Opnd
(N
);
3796 R
: constant Node_Id
:= Right_Opnd
(N
);
3797 TL
: constant Entity_Id
:= Base_Type
(Etype
(L
));
3798 TR
: constant Entity_Id
:= Base_Type
(Etype
(R
));
3802 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
3803 -- We do the resolution using the base type, because intermediate values
3804 -- in expressions always are of the base type, not a subtype of it.
3806 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean;
3807 -- Returns True if N is in a context that expects "any real type"
3809 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean;
3810 -- Return True iff given type is Integer or universal real/integer
3812 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
);
3813 -- Choose type of integer literal in fixed-point operation to conform
3814 -- to available fixed-point type. T is the type of the other operand,
3815 -- which is needed to determine the expected type of N.
3817 procedure Set_Operand_Type
(N
: Node_Id
);
3818 -- Set operand type to T if universal
3820 -------------------------------
3821 -- Expected_Type_Is_Any_Real --
3822 -------------------------------
3824 function Expected_Type_Is_Any_Real
(N
: Node_Id
) return Boolean is
3826 -- N is the expression after "delta" in a fixed_point_definition;
3829 return Nkind
(Parent
(N
)) = N_Ordinary_Fixed_Point_Definition
3830 or else Nkind
(Parent
(N
)) = N_Decimal_Fixed_Point_Definition
3832 -- N is one of the bounds in a real_range_specification;
3835 or else Nkind
(Parent
(N
)) = N_Real_Range_Specification
3837 -- N is the expression of a delta_constraint;
3840 or else Nkind
(Parent
(N
)) = N_Delta_Constraint
;
3841 end Expected_Type_Is_Any_Real
;
3843 -----------------------------
3844 -- Is_Integer_Or_Universal --
3845 -----------------------------
3847 function Is_Integer_Or_Universal
(N
: Node_Id
) return Boolean is
3849 Index
: Interp_Index
;
3853 if not Is_Overloaded
(N
) then
3855 return Base_Type
(T
) = Base_Type
(Standard_Integer
)
3856 or else T
= Universal_Integer
3857 or else T
= Universal_Real
;
3859 Get_First_Interp
(N
, Index
, It
);
3860 while Present
(It
.Typ
) loop
3861 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
)
3862 or else It
.Typ
= Universal_Integer
3863 or else It
.Typ
= Universal_Real
3868 Get_Next_Interp
(Index
, It
);
3873 end Is_Integer_Or_Universal
;
3875 ----------------------------
3876 -- Set_Mixed_Mode_Operand --
3877 ----------------------------
3879 procedure Set_Mixed_Mode_Operand
(N
: Node_Id
; T
: Entity_Id
) is
3880 Index
: Interp_Index
;
3884 if Universal_Interpretation
(N
) = Universal_Integer
then
3886 -- A universal integer literal is resolved as standard integer
3887 -- except in the case of a fixed-point result, where we leave it
3888 -- as universal (to be handled by Exp_Fixd later on)
3890 if Is_Fixed_Point_Type
(T
) then
3891 Resolve
(N
, Universal_Integer
);
3893 Resolve
(N
, Standard_Integer
);
3896 elsif Universal_Interpretation
(N
) = Universal_Real
3897 and then (T
= Base_Type
(Standard_Integer
)
3898 or else T
= Universal_Integer
3899 or else T
= Universal_Real
)
3901 -- A universal real can appear in a fixed-type context. We resolve
3902 -- the literal with that context, even though this might raise an
3903 -- exception prematurely (the other operand may be zero).
3907 elsif Etype
(N
) = Base_Type
(Standard_Integer
)
3908 and then T
= Universal_Real
3909 and then Is_Overloaded
(N
)
3911 -- Integer arg in mixed-mode operation. Resolve with universal
3912 -- type, in case preference rule must be applied.
3914 Resolve
(N
, Universal_Integer
);
3917 and then B_Typ
/= Universal_Fixed
3919 -- Not a mixed-mode operation, resolve with context
3923 elsif Etype
(N
) = Any_Fixed
then
3925 -- N may itself be a mixed-mode operation, so use context type
3929 elsif Is_Fixed_Point_Type
(T
)
3930 and then B_Typ
= Universal_Fixed
3931 and then Is_Overloaded
(N
)
3933 -- Must be (fixed * fixed) operation, operand must have one
3934 -- compatible interpretation.
3936 Resolve
(N
, Any_Fixed
);
3938 elsif Is_Fixed_Point_Type
(B_Typ
)
3939 and then (T
= Universal_Real
3940 or else Is_Fixed_Point_Type
(T
))
3941 and then Is_Overloaded
(N
)
3943 -- C * F(X) in a fixed context, where C is a real literal or a
3944 -- fixed-point expression. F must have either a fixed type
3945 -- interpretation or an integer interpretation, but not both.
3947 Get_First_Interp
(N
, Index
, It
);
3948 while Present
(It
.Typ
) loop
3949 if Base_Type
(It
.Typ
) = Base_Type
(Standard_Integer
) then
3951 if Analyzed
(N
) then
3952 Error_Msg_N
("ambiguous operand in fixed operation", N
);
3954 Resolve
(N
, Standard_Integer
);
3957 elsif Is_Fixed_Point_Type
(It
.Typ
) then
3959 if Analyzed
(N
) then
3960 Error_Msg_N
("ambiguous operand in fixed operation", N
);
3962 Resolve
(N
, It
.Typ
);
3966 Get_Next_Interp
(Index
, It
);
3969 -- Reanalyze the literal with the fixed type of the context. If
3970 -- context is Universal_Fixed, we are within a conversion, leave
3971 -- the literal as a universal real because there is no usable
3972 -- fixed type, and the target of the conversion plays no role in
3986 if B_Typ
= Universal_Fixed
3987 and then Nkind
(Op2
) = N_Real_Literal
3989 T2
:= Universal_Real
;
3994 Set_Analyzed
(Op2
, False);
4001 end Set_Mixed_Mode_Operand
;
4003 ----------------------
4004 -- Set_Operand_Type --
4005 ----------------------
4007 procedure Set_Operand_Type
(N
: Node_Id
) is
4009 if Etype
(N
) = Universal_Integer
4010 or else Etype
(N
) = Universal_Real
4014 end Set_Operand_Type
;
4016 -- Start of processing for Resolve_Arithmetic_Op
4019 if Comes_From_Source
(N
)
4020 and then Ekind
(Entity
(N
)) = E_Function
4021 and then Is_Imported
(Entity
(N
))
4022 and then Is_Intrinsic_Subprogram
(Entity
(N
))
4024 Resolve_Intrinsic_Operator
(N
, Typ
);
4027 -- Special-case for mixed-mode universal expressions or fixed point
4028 -- type operation: each argument is resolved separately. The same
4029 -- treatment is required if one of the operands of a fixed point
4030 -- operation is universal real, since in this case we don't do a
4031 -- conversion to a specific fixed-point type (instead the expander
4032 -- takes care of the case).
4034 elsif (B_Typ
= Universal_Integer
4035 or else B_Typ
= Universal_Real
)
4036 and then Present
(Universal_Interpretation
(L
))
4037 and then Present
(Universal_Interpretation
(R
))
4039 Resolve
(L
, Universal_Interpretation
(L
));
4040 Resolve
(R
, Universal_Interpretation
(R
));
4041 Set_Etype
(N
, B_Typ
);
4043 elsif (B_Typ
= Universal_Real
4044 or else Etype
(N
) = Universal_Fixed
4045 or else (Etype
(N
) = Any_Fixed
4046 and then Is_Fixed_Point_Type
(B_Typ
))
4047 or else (Is_Fixed_Point_Type
(B_Typ
)
4048 and then (Is_Integer_Or_Universal
(L
)
4050 Is_Integer_Or_Universal
(R
))))
4051 and then (Nkind
(N
) = N_Op_Multiply
or else
4052 Nkind
(N
) = N_Op_Divide
)
4054 if TL
= Universal_Integer
or else TR
= Universal_Integer
then
4055 Check_For_Visible_Operator
(N
, B_Typ
);
4058 -- If context is a fixed type and one operand is integer, the
4059 -- other is resolved with the type of the context.
4061 if Is_Fixed_Point_Type
(B_Typ
)
4062 and then (Base_Type
(TL
) = Base_Type
(Standard_Integer
)
4063 or else TL
= Universal_Integer
)
4068 elsif Is_Fixed_Point_Type
(B_Typ
)
4069 and then (Base_Type
(TR
) = Base_Type
(Standard_Integer
)
4070 or else TR
= Universal_Integer
)
4076 Set_Mixed_Mode_Operand
(L
, TR
);
4077 Set_Mixed_Mode_Operand
(R
, TL
);
4080 -- Check the rule in RM05-4.5.5(19.1/2) disallowing the
4081 -- universal_fixed multiplying operators from being used when the
4082 -- expected type is also universal_fixed. Note that B_Typ will be
4083 -- Universal_Fixed in some cases where the expected type is actually
4084 -- Any_Real; Expected_Type_Is_Any_Real takes care of that case.
4086 if Etype
(N
) = Universal_Fixed
4087 or else Etype
(N
) = Any_Fixed
4089 if B_Typ
= Universal_Fixed
4090 and then not Expected_Type_Is_Any_Real
(N
)
4091 and then Nkind
(Parent
(N
)) /= N_Type_Conversion
4092 and then Nkind
(Parent
(N
)) /= N_Unchecked_Type_Conversion
4095 ("type cannot be determined from context!", N
);
4097 ("\explicit conversion to result type required", N
);
4099 Set_Etype
(L
, Any_Type
);
4100 Set_Etype
(R
, Any_Type
);
4103 if Ada_Version
= Ada_83
4104 and then Etype
(N
) = Universal_Fixed
4105 and then Nkind
(Parent
(N
)) /= N_Type_Conversion
4106 and then Nkind
(Parent
(N
)) /= N_Unchecked_Type_Conversion
4109 ("(Ada 83) fixed-point operation " &
4110 "needs explicit conversion",
4114 -- The expected type is "any real type" in contexts like
4115 -- type T is delta <universal_fixed-expression> ...
4116 -- in which case we need to set the type to Universal_Real
4117 -- so that static expression evaluation will work properly.
4119 if Expected_Type_Is_Any_Real
(N
) then
4120 Set_Etype
(N
, Universal_Real
);
4122 Set_Etype
(N
, B_Typ
);
4126 elsif Is_Fixed_Point_Type
(B_Typ
)
4127 and then (Is_Integer_Or_Universal
(L
)
4128 or else Nkind
(L
) = N_Real_Literal
4129 or else Nkind
(R
) = N_Real_Literal
4131 Is_Integer_Or_Universal
(R
))
4133 Set_Etype
(N
, B_Typ
);
4135 elsif Etype
(N
) = Any_Fixed
then
4137 -- If no previous errors, this is only possible if one operand
4138 -- is overloaded and the context is universal. Resolve as such.
4140 Set_Etype
(N
, B_Typ
);
4144 if (TL
= Universal_Integer
or else TL
= Universal_Real
)
4145 and then (TR
= Universal_Integer
or else TR
= Universal_Real
)
4147 Check_For_Visible_Operator
(N
, B_Typ
);
4150 -- If the context is Universal_Fixed and the operands are also
4151 -- universal fixed, this is an error, unless there is only one
4152 -- applicable fixed_point type (usually duration).
4154 if B_Typ
= Universal_Fixed
4155 and then Etype
(L
) = Universal_Fixed
4157 T
:= Unique_Fixed_Point_Type
(N
);
4159 if T
= Any_Type
then
4172 -- If one of the arguments was resolved to a non-universal type.
4173 -- label the result of the operation itself with the same type.
4174 -- Do the same for the universal argument, if any.
4176 T
:= Intersect_Types
(L
, R
);
4177 Set_Etype
(N
, Base_Type
(T
));
4178 Set_Operand_Type
(L
);
4179 Set_Operand_Type
(R
);
4182 Generate_Operator_Reference
(N
, Typ
);
4183 Eval_Arithmetic_Op
(N
);
4185 -- Set overflow and division checking bit. Much cleverer code needed
4186 -- here eventually and perhaps the Resolve routines should be separated
4187 -- for the various arithmetic operations, since they will need
4188 -- different processing. ???
4190 if Nkind
(N
) in N_Op
then
4191 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
4192 Enable_Overflow_Check
(N
);
4195 -- Give warning if explicit division by zero
4197 if (Nkind
(N
) = N_Op_Divide
4198 or else Nkind
(N
) = N_Op_Rem
4199 or else Nkind
(N
) = N_Op_Mod
)
4200 and then not Division_Checks_Suppressed
(Etype
(N
))
4202 Rop
:= Right_Opnd
(N
);
4204 if Compile_Time_Known_Value
(Rop
)
4205 and then ((Is_Integer_Type
(Etype
(Rop
))
4206 and then Expr_Value
(Rop
) = Uint_0
)
4208 (Is_Real_Type
(Etype
(Rop
))
4209 and then Expr_Value_R
(Rop
) = Ureal_0
))
4211 -- Specialize the warning message according to the operation
4215 Apply_Compile_Time_Constraint_Error
4216 (N
, "division by zero?", CE_Divide_By_Zero
,
4217 Loc
=> Sloc
(Right_Opnd
(N
)));
4220 Apply_Compile_Time_Constraint_Error
4221 (N
, "rem with zero divisor?", CE_Divide_By_Zero
,
4222 Loc
=> Sloc
(Right_Opnd
(N
)));
4225 Apply_Compile_Time_Constraint_Error
4226 (N
, "mod with zero divisor?", CE_Divide_By_Zero
,
4227 Loc
=> Sloc
(Right_Opnd
(N
)));
4229 -- Division by zero can only happen with division, rem,
4230 -- and mod operations.
4233 raise Program_Error
;
4236 -- Otherwise just set the flag to check at run time
4239 Activate_Division_Check
(N
);
4244 Check_Unset_Reference
(L
);
4245 Check_Unset_Reference
(R
);
4246 end Resolve_Arithmetic_Op
;
4252 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
4253 Loc
: constant Source_Ptr
:= Sloc
(N
);
4254 Subp
: constant Node_Id
:= Name
(N
);
4263 -- The context imposes a unique interpretation with type Typ on a
4264 -- procedure or function call. Find the entity of the subprogram that
4265 -- yields the expected type, and propagate the corresponding formal
4266 -- constraints on the actuals. The caller has established that an
4267 -- interpretation exists, and emitted an error if not unique.
4269 -- First deal with the case of a call to an access-to-subprogram,
4270 -- dereference made explicit in Analyze_Call.
4272 if Ekind
(Etype
(Subp
)) = E_Subprogram_Type
then
4273 if not Is_Overloaded
(Subp
) then
4274 Nam
:= Etype
(Subp
);
4277 -- Find the interpretation whose type (a subprogram type) has a
4278 -- return type that is compatible with the context. Analysis of
4279 -- the node has established that one exists.
4283 Get_First_Interp
(Subp
, I
, It
);
4284 while Present
(It
.Typ
) loop
4285 if Covers
(Typ
, Etype
(It
.Typ
)) then
4290 Get_Next_Interp
(I
, It
);
4294 raise Program_Error
;
4298 -- If the prefix is not an entity, then resolve it
4300 if not Is_Entity_Name
(Subp
) then
4301 Resolve
(Subp
, Nam
);
4304 -- For an indirect call, we always invalidate checks, since we do not
4305 -- know whether the subprogram is local or global. Yes we could do
4306 -- better here, e.g. by knowing that there are no local subprograms,
4307 -- but it does not seem worth the effort. Similarly, we kill all
4308 -- knowledge of current constant values.
4310 Kill_Current_Values
;
4312 -- If this is a procedure call which is really an entry call, do
4313 -- the conversion of the procedure call to an entry call. Protected
4314 -- operations use the same circuitry because the name in the call
4315 -- can be an arbitrary expression with special resolution rules.
4317 elsif Nkind
(Subp
) = N_Selected_Component
4318 or else Nkind
(Subp
) = N_Indexed_Component
4319 or else (Is_Entity_Name
(Subp
)
4320 and then Ekind
(Entity
(Subp
)) = E_Entry
)
4322 Resolve_Entry_Call
(N
, Typ
);
4323 Check_Elab_Call
(N
);
4325 -- Kill checks and constant values, as above for indirect case
4326 -- Who knows what happens when another task is activated?
4328 Kill_Current_Values
;
4331 -- Normal subprogram call with name established in Resolve
4333 elsif not (Is_Type
(Entity
(Subp
))) then
4334 Nam
:= Entity
(Subp
);
4335 Set_Entity_With_Style_Check
(Subp
, Nam
);
4337 -- Otherwise we must have the case of an overloaded call
4340 pragma Assert
(Is_Overloaded
(Subp
));
4341 Nam
:= Empty
; -- We know that it will be assigned in loop below
4343 Get_First_Interp
(Subp
, I
, It
);
4344 while Present
(It
.Typ
) loop
4345 if Covers
(Typ
, It
.Typ
) then
4347 Set_Entity_With_Style_Check
(Subp
, Nam
);
4351 Get_Next_Interp
(I
, It
);
4355 -- Check that a call to Current_Task does not occur in an entry body
4357 if Is_RTE
(Nam
, RE_Current_Task
) then
4367 if Nkind
(P
) = N_Entry_Body
4368 or else (Nkind
(P
) = N_Subprogram_Body
4369 and then Is_Entry_Barrier_Function
(P
))
4373 ("?& should not be used in entry body (RM C.7(17))",
4376 ("\Program_Error will be raised at run time?", N
, Nam
);
4378 Make_Raise_Program_Error
(Loc
,
4379 Reason
=> PE_Current_Task_In_Entry_Body
));
4380 Set_Etype
(N
, Rtype
);
4387 -- Check that a procedure call does not occur in the context of the
4388 -- entry call statement of a conditional or timed entry call. Note that
4389 -- the case of a call to a subprogram renaming of an entry will also be
4390 -- rejected. The test for N not being an N_Entry_Call_Statement is
4391 -- defensive, covering the possibility that the processing of entry
4392 -- calls might reach this point due to later modifications of the code
4395 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
4396 and then Nkind
(N
) /= N_Entry_Call_Statement
4397 and then Entry_Call_Statement
(Parent
(N
)) = N
4399 if Ada_Version
< Ada_05
then
4400 Error_Msg_N
("entry call required in select statement", N
);
4402 -- Ada 2005 (AI-345): If a procedure_call_statement is used
4403 -- for a procedure_or_entry_call, the procedure_name or pro-
4404 -- cedure_prefix of the procedure_call_statement shall denote
4405 -- an entry renamed by a procedure, or (a view of) a primitive
4406 -- subprogram of a limited interface whose first parameter is
4407 -- a controlling parameter.
4409 elsif Nkind
(N
) = N_Procedure_Call_Statement
4410 and then not Is_Renamed_Entry
(Nam
)
4411 and then not Is_Controlling_Limited_Procedure
(Nam
)
4414 ("entry call or dispatching primitive of interface required", N
);
4418 -- Check that this is not a call to a protected procedure or
4419 -- entry from within a protected function.
4421 if Ekind
(Current_Scope
) = E_Function
4422 and then Ekind
(Scope
(Current_Scope
)) = E_Protected_Type
4423 and then Ekind
(Nam
) /= E_Function
4424 and then Scope
(Nam
) = Scope
(Current_Scope
)
4426 Error_Msg_N
("within protected function, protected " &
4427 "object is constant", N
);
4428 Error_Msg_N
("\cannot call operation that may modify it", N
);
4431 -- Freeze the subprogram name if not in default expression. Note that we
4432 -- freeze procedure calls as well as function calls. Procedure calls are
4433 -- not frozen according to the rules (RM 13.14(14)) because it is
4434 -- impossible to have a procedure call to a non-frozen procedure in pure
4435 -- Ada, but in the code that we generate in the expander, this rule
4436 -- needs extending because we can generate procedure calls that need
4439 if Is_Entity_Name
(Subp
) and then not In_Default_Expression
then
4440 Freeze_Expression
(Subp
);
4443 -- For a predefined operator, the type of the result is the type imposed
4444 -- by context, except for a predefined operation on universal fixed.
4445 -- Otherwise The type of the call is the type returned by the subprogram
4448 if Is_Predefined_Op
(Nam
) then
4449 if Etype
(N
) /= Universal_Fixed
then
4453 -- If the subprogram returns an array type, and the context requires the
4454 -- component type of that array type, the node is really an indexing of
4455 -- the parameterless call. Resolve as such. A pathological case occurs
4456 -- when the type of the component is an access to the array type. In
4457 -- this case the call is truly ambiguous.
4459 elsif (Needs_No_Actuals
(Nam
) or else Needs_One_Actual
(Nam
))
4461 ((Is_Array_Type
(Etype
(Nam
))
4462 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
4463 or else (Is_Access_Type
(Etype
(Nam
))
4464 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
4467 Component_Type
(Designated_Type
(Etype
(Nam
))))))
4470 Index_Node
: Node_Id
;
4472 Ret_Type
: constant Entity_Id
:= Etype
(Nam
);
4475 if Is_Access_Type
(Ret_Type
)
4476 and then Ret_Type
= Component_Type
(Designated_Type
(Ret_Type
))
4479 ("cannot disambiguate function call and indexing", N
);
4481 New_Subp
:= Relocate_Node
(Subp
);
4482 Set_Entity
(Subp
, Nam
);
4484 if Component_Type
(Ret_Type
) /= Any_Type
then
4485 if Needs_No_Actuals
(Nam
) then
4487 -- Indexed call to a parameterless function
4490 Make_Indexed_Component
(Loc
,
4492 Make_Function_Call
(Loc
,
4494 Expressions
=> Parameter_Associations
(N
));
4496 -- An Ada 2005 prefixed call to a primitive operation
4497 -- whose first parameter is the prefix. This prefix was
4498 -- prepended to the parameter list, which is actually a
4499 -- list of indices. Remove the prefix in order to build
4500 -- the proper indexed component.
4503 Make_Indexed_Component
(Loc
,
4505 Make_Function_Call
(Loc
,
4507 Parameter_Associations
=>
4509 (Remove_Head
(Parameter_Associations
(N
)))),
4510 Expressions
=> Parameter_Associations
(N
));
4513 -- Since we are correcting a node classification error made
4514 -- by the parser, we call Replace rather than Rewrite.
4516 Replace
(N
, Index_Node
);
4517 Set_Etype
(Prefix
(N
), Ret_Type
);
4519 Resolve_Indexed_Component
(N
, Typ
);
4520 Check_Elab_Call
(Prefix
(N
));
4528 Set_Etype
(N
, Etype
(Nam
));
4531 -- In the case where the call is to an overloaded subprogram, Analyze
4532 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
4533 -- such a case Normalize_Actuals needs to be called once more to order
4534 -- the actuals correctly. Otherwise the call will have the ordering
4535 -- given by the last overloaded subprogram whether this is the correct
4536 -- one being called or not.
4538 if Is_Overloaded
(Subp
) then
4539 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
4540 pragma Assert
(Norm_OK
);
4543 -- In any case, call is fully resolved now. Reset Overload flag, to
4544 -- prevent subsequent overload resolution if node is analyzed again
4546 Set_Is_Overloaded
(Subp
, False);
4547 Set_Is_Overloaded
(N
, False);
4549 -- If we are calling the current subprogram from immediately within its
4550 -- body, then that is the case where we can sometimes detect cases of
4551 -- infinite recursion statically. Do not try this in case restriction
4552 -- No_Recursion is in effect anyway, and do it only for source calls.
4554 if Comes_From_Source
(N
) then
4555 Scop
:= Current_Scope
;
4558 and then not Restriction_Active
(No_Recursion
)
4559 and then Check_Infinite_Recursion
(N
)
4561 -- Here we detected and flagged an infinite recursion, so we do
4562 -- not need to test the case below for further warnings.
4566 -- If call is to immediately containing subprogram, then check for
4567 -- the case of a possible run-time detectable infinite recursion.
4570 Scope_Loop
: while Scop
/= Standard_Standard
loop
4573 -- Although in general case, recursion is not statically
4574 -- checkable, the case of calling an immediately containing
4575 -- subprogram is easy to catch.
4577 Check_Restriction
(No_Recursion
, N
);
4579 -- If the recursive call is to a parameterless subprogram,
4580 -- then even if we can't statically detect infinite
4581 -- recursion, this is pretty suspicious, and we output a
4582 -- warning. Furthermore, we will try later to detect some
4583 -- cases here at run time by expanding checking code (see
4584 -- Detect_Infinite_Recursion in package Exp_Ch6).
4586 -- If the recursive call is within a handler, do not emit a
4587 -- warning, because this is a common idiom: loop until input
4588 -- is correct, catch illegal input in handler and restart.
4590 if No
(First_Formal
(Nam
))
4591 and then Etype
(Nam
) = Standard_Void_Type
4592 and then not Error_Posted
(N
)
4593 and then Nkind
(Parent
(N
)) /= N_Exception_Handler
4595 -- For the case of a procedure call. We give the message
4596 -- only if the call is the first statement in a sequence
4597 -- of statements, or if all previous statements are
4598 -- simple assignments. This is simply a heuristic to
4599 -- decrease false positives, without losing too many good
4600 -- warnings. The idea is that these previous statements
4601 -- may affect global variables the procedure depends on.
4603 if Nkind
(N
) = N_Procedure_Call_Statement
4604 and then Is_List_Member
(N
)
4610 while Present
(P
) loop
4611 if Nkind
(P
) /= N_Assignment_Statement
then
4620 -- Do not give warning if we are in a conditional context
4623 K
: constant Node_Kind
:= Nkind
(Parent
(N
));
4625 if (K
= N_Loop_Statement
4626 and then Present
(Iteration_Scheme
(Parent
(N
))))
4627 or else K
= N_If_Statement
4628 or else K
= N_Elsif_Part
4629 or else K
= N_Case_Statement_Alternative
4635 -- Here warning is to be issued
4637 Set_Has_Recursive_Call
(Nam
);
4639 ("?possible infinite recursion!", N
);
4641 ("\?Storage_Error may be raised at run time!", N
);
4647 Scop
:= Scope
(Scop
);
4648 end loop Scope_Loop
;
4652 -- If subprogram name is a predefined operator, it was given in
4653 -- functional notation. Replace call node with operator node, so
4654 -- that actuals can be resolved appropriately.
4656 if Is_Predefined_Op
(Nam
) or else Ekind
(Nam
) = E_Operator
then
4657 Make_Call_Into_Operator
(N
, Typ
, Entity
(Name
(N
)));
4660 elsif Present
(Alias
(Nam
))
4661 and then Is_Predefined_Op
(Alias
(Nam
))
4663 Resolve_Actuals
(N
, Nam
);
4664 Make_Call_Into_Operator
(N
, Typ
, Alias
(Nam
));
4668 -- Create a transient scope if the resulting type requires it
4670 -- There are 4 notable exceptions: in init procs, the transient scope
4671 -- overhead is not needed and even incorrect due to the actual expansion
4672 -- of adjust calls; the second case is enumeration literal pseudo calls;
4673 -- the third case is intrinsic subprograms (Unchecked_Conversion and
4674 -- source information functions) that do not use the secondary stack
4675 -- even though the return type is unconstrained; the fourth case is a
4676 -- call to a build-in-place function, since such functions may allocate
4677 -- their result directly in a target object, and cases where the result
4678 -- does get allocated in the secondary stack are checked for within the
4679 -- specialized Exp_Ch6 procedures for expanding build-in-place calls.
4681 -- If this is an initialization call for a type whose initialization
4682 -- uses the secondary stack, we also need to create a transient scope
4683 -- for it, precisely because we will not do it within the init proc
4686 -- If the subprogram is marked Inlined_Always, then even if it returns
4687 -- an unconstrained type the call does not require use of the secondary
4691 and then Present
(First_Rep_Item
(Nam
))
4692 and then Nkind
(First_Rep_Item
(Nam
)) = N_Pragma
4693 and then Chars
(First_Rep_Item
(Nam
)) = Name_Inline_Always
4697 elsif Expander_Active
4698 and then Is_Type
(Etype
(Nam
))
4699 and then Requires_Transient_Scope
(Etype
(Nam
))
4700 and then not Is_Build_In_Place_Function
(Nam
)
4701 and then Ekind
(Nam
) /= E_Enumeration_Literal
4702 and then not Within_Init_Proc
4703 and then not Is_Intrinsic_Subprogram
(Nam
)
4705 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
4707 -- If the call appears within the bounds of a loop, it will
4708 -- be rewritten and reanalyzed, nothing left to do here.
4710 if Nkind
(N
) /= N_Function_Call
then
4714 elsif Is_Init_Proc
(Nam
)
4715 and then not Within_Init_Proc
4717 Check_Initialization_Call
(N
, Nam
);
4720 -- A protected function cannot be called within the definition of the
4721 -- enclosing protected type.
4723 if Is_Protected_Type
(Scope
(Nam
))
4724 and then In_Open_Scopes
(Scope
(Nam
))
4725 and then not Has_Completion
(Scope
(Nam
))
4728 ("& cannot be called before end of protected definition", N
, Nam
);
4731 -- Propagate interpretation to actuals, and add default expressions
4734 if Present
(First_Formal
(Nam
)) then
4735 Resolve_Actuals
(N
, Nam
);
4737 -- Overloaded literals are rewritten as function calls, for
4738 -- purpose of resolution. After resolution, we can replace
4739 -- the call with the literal itself.
4741 elsif Ekind
(Nam
) = E_Enumeration_Literal
then
4742 Copy_Node
(Subp
, N
);
4743 Resolve_Entity_Name
(N
, Typ
);
4745 -- Avoid validation, since it is a static function call
4747 Generate_Reference
(Nam
, Subp
);
4751 -- If the subprogram is not global, then kill all saved values and
4752 -- checks. This is a bit conservative, since in many cases we could do
4753 -- better, but it is not worth the effort. Similarly, we kill constant
4754 -- values. However we do not need to do this for internal entities
4755 -- (unless they are inherited user-defined subprograms), since they
4756 -- are not in the business of molesting local values.
4758 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
4759 -- kill all checks and values for calls to global subprograms. This
4760 -- takes care of the case where an access to a local subprogram is
4761 -- taken, and could be passed directly or indirectly and then called
4762 -- from almost any context.
4764 -- Note: we do not do this step till after resolving the actuals. That
4765 -- way we still take advantage of the current value information while
4766 -- scanning the actuals.
4768 if (not Is_Library_Level_Entity
(Nam
)
4769 or else Suppress_Value_Tracking_On_Call
(Current_Scope
))
4770 and then (Comes_From_Source
(Nam
)
4771 or else (Present
(Alias
(Nam
))
4772 and then Comes_From_Source
(Alias
(Nam
))))
4774 Kill_Current_Values
;
4777 -- If the subprogram is a primitive operation, check whether or not
4778 -- it is a correct dispatching call.
4780 if Is_Overloadable
(Nam
)
4781 and then Is_Dispatching_Operation
(Nam
)
4783 Check_Dispatching_Call
(N
);
4785 elsif Ekind
(Nam
) /= E_Subprogram_Type
4786 and then Is_Abstract_Subprogram
(Nam
)
4787 and then not In_Instance
4789 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Nam
);
4792 -- If this is a dispatching call, generate the appropriate reference,
4793 -- for better source navigation in GPS.
4795 if Is_Overloadable
(Nam
)
4796 and then Present
(Controlling_Argument
(N
))
4798 Generate_Reference
(Nam
, Subp
, 'R');
4800 Generate_Reference
(Nam
, Subp
);
4803 if Is_Intrinsic_Subprogram
(Nam
) then
4804 Check_Intrinsic_Call
(N
);
4808 Check_Elab_Call
(N
);
4811 -------------------------------
4812 -- Resolve_Character_Literal --
4813 -------------------------------
4815 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
4816 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
4820 -- Verify that the character does belong to the type of the context
4822 Set_Etype
(N
, B_Typ
);
4823 Eval_Character_Literal
(N
);
4825 -- Wide_Wide_Character literals must always be defined, since the set
4826 -- of wide wide character literals is complete, i.e. if a character
4827 -- literal is accepted by the parser, then it is OK for wide wide
4828 -- character (out of range character literals are rejected).
4830 if Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
4833 -- Always accept character literal for type Any_Character, which
4834 -- occurs in error situations and in comparisons of literals, both
4835 -- of which should accept all literals.
4837 elsif B_Typ
= Any_Character
then
4840 -- For Standard.Character or a type derived from it, check that
4841 -- the literal is in range
4843 elsif Root_Type
(B_Typ
) = Standard_Character
then
4844 if In_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
4848 -- For Standard.Wide_Character or a type derived from it, check
4849 -- that the literal is in range
4851 elsif Root_Type
(B_Typ
) = Standard_Wide_Character
then
4852 if In_Wide_Character_Range
(UI_To_CC
(Char_Literal_Value
(N
))) then
4856 -- For Standard.Wide_Wide_Character or a type derived from it, we
4857 -- know the literal is in range, since the parser checked!
4859 elsif Root_Type
(B_Typ
) = Standard_Wide_Wide_Character
then
4862 -- If the entity is already set, this has already been resolved in
4863 -- a generic context, or comes from expansion. Nothing else to do.
4865 elsif Present
(Entity
(N
)) then
4868 -- Otherwise we have a user defined character type, and we can use
4869 -- the standard visibility mechanisms to locate the referenced entity
4872 C
:= Current_Entity
(N
);
4873 while Present
(C
) loop
4874 if Etype
(C
) = B_Typ
then
4875 Set_Entity_With_Style_Check
(N
, C
);
4876 Generate_Reference
(C
, N
);
4884 -- If we fall through, then the literal does not match any of the
4885 -- entries of the enumeration type. This isn't just a constraint
4886 -- error situation, it is an illegality (see RM 4.2).
4889 ("character not defined for }", N
, First_Subtype
(B_Typ
));
4890 end Resolve_Character_Literal
;
4892 ---------------------------
4893 -- Resolve_Comparison_Op --
4894 ---------------------------
4896 -- Context requires a boolean type, and plays no role in resolution.
4897 -- Processing identical to that for equality operators. The result
4898 -- type is the base type, which matters when pathological subtypes of
4899 -- booleans with limited ranges are used.
4901 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
4902 L
: constant Node_Id
:= Left_Opnd
(N
);
4903 R
: constant Node_Id
:= Right_Opnd
(N
);
4907 -- If this is an intrinsic operation which is not predefined, use
4908 -- the types of its declared arguments to resolve the possibly
4909 -- overloaded operands. Otherwise the operands are unambiguous and
4910 -- specify the expected type.
4912 if Scope
(Entity
(N
)) /= Standard_Standard
then
4913 T
:= Etype
(First_Entity
(Entity
(N
)));
4916 T
:= Find_Unique_Type
(L
, R
);
4918 if T
= Any_Fixed
then
4919 T
:= Unique_Fixed_Point_Type
(L
);
4923 Set_Etype
(N
, Base_Type
(Typ
));
4924 Generate_Reference
(T
, N
, ' ');
4926 if T
/= Any_Type
then
4928 or else T
= Any_Composite
4929 or else T
= Any_Character
4931 if T
= Any_Character
then
4932 Ambiguous_Character
(L
);
4934 Error_Msg_N
("ambiguous operands for comparison", N
);
4937 Set_Etype
(N
, Any_Type
);
4943 Check_Unset_Reference
(L
);
4944 Check_Unset_Reference
(R
);
4945 Generate_Operator_Reference
(N
, T
);
4946 Eval_Relational_Op
(N
);
4949 end Resolve_Comparison_Op
;
4951 ------------------------------------
4952 -- Resolve_Conditional_Expression --
4953 ------------------------------------
4955 procedure Resolve_Conditional_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
4956 Condition
: constant Node_Id
:= First
(Expressions
(N
));
4957 Then_Expr
: constant Node_Id
:= Next
(Condition
);
4958 Else_Expr
: constant Node_Id
:= Next
(Then_Expr
);
4961 Resolve
(Condition
, Standard_Boolean
);
4962 Resolve
(Then_Expr
, Typ
);
4963 Resolve
(Else_Expr
, Typ
);
4966 Eval_Conditional_Expression
(N
);
4967 end Resolve_Conditional_Expression
;
4969 -----------------------------------------
4970 -- Resolve_Discrete_Subtype_Indication --
4971 -----------------------------------------
4973 procedure Resolve_Discrete_Subtype_Indication
4981 Analyze
(Subtype_Mark
(N
));
4982 S
:= Entity
(Subtype_Mark
(N
));
4984 if Nkind
(Constraint
(N
)) /= N_Range_Constraint
then
4985 Error_Msg_N
("expect range constraint for discrete type", N
);
4986 Set_Etype
(N
, Any_Type
);
4989 R
:= Range_Expression
(Constraint
(N
));
4997 if Base_Type
(S
) /= Base_Type
(Typ
) then
4999 ("expect subtype of }", N
, First_Subtype
(Typ
));
5001 -- Rewrite the constraint as a range of Typ
5002 -- to allow compilation to proceed further.
5005 Rewrite
(Low_Bound
(R
),
5006 Make_Attribute_Reference
(Sloc
(Low_Bound
(R
)),
5007 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
5008 Attribute_Name
=> Name_First
));
5009 Rewrite
(High_Bound
(R
),
5010 Make_Attribute_Reference
(Sloc
(High_Bound
(R
)),
5011 Prefix
=> New_Occurrence_Of
(Typ
, Sloc
(R
)),
5012 Attribute_Name
=> Name_First
));
5016 Set_Etype
(N
, Etype
(R
));
5018 -- Additionally, we must check that the bounds are compatible
5019 -- with the given subtype, which might be different from the
5020 -- type of the context.
5022 Apply_Range_Check
(R
, S
);
5024 -- ??? If the above check statically detects a Constraint_Error
5025 -- it replaces the offending bound(s) of the range R with a
5026 -- Constraint_Error node. When the itype which uses these bounds
5027 -- is frozen the resulting call to Duplicate_Subexpr generates
5028 -- a new temporary for the bounds.
5030 -- Unfortunately there are other itypes that are also made depend
5031 -- on these bounds, so when Duplicate_Subexpr is called they get
5032 -- a forward reference to the newly created temporaries and Gigi
5033 -- aborts on such forward references. This is probably sign of a
5034 -- more fundamental problem somewhere else in either the order of
5035 -- itype freezing or the way certain itypes are constructed.
5037 -- To get around this problem we call Remove_Side_Effects right
5038 -- away if either bounds of R are a Constraint_Error.
5041 L
: constant Node_Id
:= Low_Bound
(R
);
5042 H
: constant Node_Id
:= High_Bound
(R
);
5045 if Nkind
(L
) = N_Raise_Constraint_Error
then
5046 Remove_Side_Effects
(L
);
5049 if Nkind
(H
) = N_Raise_Constraint_Error
then
5050 Remove_Side_Effects
(H
);
5054 Check_Unset_Reference
(Low_Bound
(R
));
5055 Check_Unset_Reference
(High_Bound
(R
));
5058 end Resolve_Discrete_Subtype_Indication
;
5060 -------------------------
5061 -- Resolve_Entity_Name --
5062 -------------------------
5064 -- Used to resolve identifiers and expanded names
5066 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
) is
5067 E
: constant Entity_Id
:= Entity
(N
);
5070 -- If garbage from errors, set to Any_Type and return
5072 if No
(E
) and then Total_Errors_Detected
/= 0 then
5073 Set_Etype
(N
, Any_Type
);
5077 -- Replace named numbers by corresponding literals. Note that this is
5078 -- the one case where Resolve_Entity_Name must reset the Etype, since
5079 -- it is currently marked as universal.
5081 if Ekind
(E
) = E_Named_Integer
then
5083 Eval_Named_Integer
(N
);
5085 elsif Ekind
(E
) = E_Named_Real
then
5087 Eval_Named_Real
(N
);
5089 -- Allow use of subtype only if it is a concurrent type where we are
5090 -- currently inside the body. This will eventually be expanded
5091 -- into a call to Self (for tasks) or _object (for protected
5092 -- objects). Any other use of a subtype is invalid.
5094 elsif Is_Type
(E
) then
5095 if Is_Concurrent_Type
(E
)
5096 and then In_Open_Scopes
(E
)
5101 ("invalid use of subtype mark in expression or call", N
);
5104 -- Check discriminant use if entity is discriminant in current scope,
5105 -- i.e. discriminant of record or concurrent type currently being
5106 -- analyzed. Uses in corresponding body are unrestricted.
5108 elsif Ekind
(E
) = E_Discriminant
5109 and then Scope
(E
) = Current_Scope
5110 and then not Has_Completion
(Current_Scope
)
5112 Check_Discriminant_Use
(N
);
5114 -- A parameterless generic function cannot appear in a context that
5115 -- requires resolution.
5117 elsif Ekind
(E
) = E_Generic_Function
then
5118 Error_Msg_N
("illegal use of generic function", N
);
5120 elsif Ekind
(E
) = E_Out_Parameter
5121 and then Ada_Version
= Ada_83
5122 and then (Nkind
(Parent
(N
)) in N_Op
5123 or else (Nkind
(Parent
(N
)) = N_Assignment_Statement
5124 and then N
= Expression
(Parent
(N
)))
5125 or else Nkind
(Parent
(N
)) = N_Explicit_Dereference
)
5127 Error_Msg_N
("(Ada 83) illegal reading of out parameter", N
);
5129 -- In all other cases, just do the possible static evaluation
5132 -- A deferred constant that appears in an expression must have
5133 -- a completion, unless it has been removed by in-place expansion
5136 if Ekind
(E
) = E_Constant
5137 and then Comes_From_Source
(E
)
5138 and then No
(Constant_Value
(E
))
5139 and then Is_Frozen
(Etype
(E
))
5140 and then not In_Default_Expression
5141 and then not Is_Imported
(E
)
5144 if No_Initialization
(Parent
(E
))
5145 or else (Present
(Full_View
(E
))
5146 and then No_Initialization
(Parent
(Full_View
(E
))))
5151 "deferred constant is frozen before completion", N
);
5155 Eval_Entity_Name
(N
);
5157 end Resolve_Entity_Name
;
5163 procedure Resolve_Entry
(Entry_Name
: Node_Id
) is
5164 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
5172 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
;
5173 -- If the bounds of the entry family being called depend on task
5174 -- discriminants, build a new index subtype where a discriminant is
5175 -- replaced with the value of the discriminant of the target task.
5176 -- The target task is the prefix of the entry name in the call.
5178 -----------------------
5179 -- Actual_Index_Type --
5180 -----------------------
5182 function Actual_Index_Type
(E
: Entity_Id
) return Entity_Id
is
5183 Typ
: constant Entity_Id
:= Entry_Index_Type
(E
);
5184 Tsk
: constant Entity_Id
:= Scope
(E
);
5185 Lo
: constant Node_Id
:= Type_Low_Bound
(Typ
);
5186 Hi
: constant Node_Id
:= Type_High_Bound
(Typ
);
5189 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
;
5190 -- If the bound is given by a discriminant, replace with a reference
5191 -- to the discriminant of the same name in the target task.
5192 -- If the entry name is the target of a requeue statement and the
5193 -- entry is in the current protected object, the bound to be used
5194 -- is the discriminal of the object (see apply_range_checks for
5195 -- details of the transformation).
5197 -----------------------------
5198 -- Actual_Discriminant_Ref --
5199 -----------------------------
5201 function Actual_Discriminant_Ref
(Bound
: Node_Id
) return Node_Id
is
5202 Typ
: constant Entity_Id
:= Etype
(Bound
);
5206 Remove_Side_Effects
(Bound
);
5208 if not Is_Entity_Name
(Bound
)
5209 or else Ekind
(Entity
(Bound
)) /= E_Discriminant
5213 elsif Is_Protected_Type
(Tsk
)
5214 and then In_Open_Scopes
(Tsk
)
5215 and then Nkind
(Parent
(Entry_Name
)) = N_Requeue_Statement
5217 return New_Occurrence_Of
(Discriminal
(Entity
(Bound
)), Loc
);
5221 Make_Selected_Component
(Loc
,
5222 Prefix
=> New_Copy_Tree
(Prefix
(Prefix
(Entry_Name
))),
5223 Selector_Name
=> New_Occurrence_Of
(Entity
(Bound
), Loc
));
5228 end Actual_Discriminant_Ref
;
5230 -- Start of processing for Actual_Index_Type
5233 if not Has_Discriminants
(Tsk
)
5234 or else (not Is_Entity_Name
(Lo
)
5235 and then not Is_Entity_Name
(Hi
))
5237 return Entry_Index_Type
(E
);
5240 New_T
:= Create_Itype
(Ekind
(Typ
), Parent
(Entry_Name
));
5241 Set_Etype
(New_T
, Base_Type
(Typ
));
5242 Set_Size_Info
(New_T
, Typ
);
5243 Set_RM_Size
(New_T
, RM_Size
(Typ
));
5244 Set_Scalar_Range
(New_T
,
5245 Make_Range
(Sloc
(Entry_Name
),
5246 Low_Bound
=> Actual_Discriminant_Ref
(Lo
),
5247 High_Bound
=> Actual_Discriminant_Ref
(Hi
)));
5251 end Actual_Index_Type
;
5253 -- Start of processing of Resolve_Entry
5256 -- Find name of entry being called, and resolve prefix of name
5257 -- with its own type. The prefix can be overloaded, and the name
5258 -- and signature of the entry must be taken into account.
5260 if Nkind
(Entry_Name
) = N_Indexed_Component
then
5262 -- Case of dealing with entry family within the current tasks
5264 E_Name
:= Prefix
(Entry_Name
);
5267 E_Name
:= Entry_Name
;
5270 if Is_Entity_Name
(E_Name
) then
5271 -- Entry call to an entry (or entry family) in the current task.
5272 -- This is legal even though the task will deadlock. Rewrite as
5273 -- call to current task.
5275 -- This can also be a call to an entry in an enclosing task.
5276 -- If this is a single task, we have to retrieve its name,
5277 -- because the scope of the entry is the task type, not the
5278 -- object. If the enclosing task is a task type, the identity
5279 -- of the task is given by its own self variable.
5281 -- Finally this can be a requeue on an entry of the same task
5282 -- or protected object.
5284 S
:= Scope
(Entity
(E_Name
));
5286 for J
in reverse 0 .. Scope_Stack
.Last
loop
5288 if Is_Task_Type
(Scope_Stack
.Table
(J
).Entity
)
5289 and then not Comes_From_Source
(S
)
5291 -- S is an enclosing task or protected object. The concurrent
5292 -- declaration has been converted into a type declaration, and
5293 -- the object itself has an object declaration that follows
5294 -- the type in the same declarative part.
5296 Tsk
:= Next_Entity
(S
);
5297 while Etype
(Tsk
) /= S
loop
5304 elsif S
= Scope_Stack
.Table
(J
).Entity
then
5306 -- Call to current task. Will be transformed into call to Self
5314 Make_Selected_Component
(Loc
,
5315 Prefix
=> New_Occurrence_Of
(S
, Loc
),
5317 New_Occurrence_Of
(Entity
(E_Name
), Loc
));
5318 Rewrite
(E_Name
, New_N
);
5321 elsif Nkind
(Entry_Name
) = N_Selected_Component
5322 and then Is_Overloaded
(Prefix
(Entry_Name
))
5324 -- Use the entry name (which must be unique at this point) to
5325 -- find the prefix that returns the corresponding task type or
5329 Pref
: constant Node_Id
:= Prefix
(Entry_Name
);
5330 Ent
: constant Entity_Id
:= Entity
(Selector_Name
(Entry_Name
));
5335 Get_First_Interp
(Pref
, I
, It
);
5336 while Present
(It
.Typ
) loop
5337 if Scope
(Ent
) = It
.Typ
then
5338 Set_Etype
(Pref
, It
.Typ
);
5342 Get_Next_Interp
(I
, It
);
5347 if Nkind
(Entry_Name
) = N_Selected_Component
then
5348 Resolve
(Prefix
(Entry_Name
));
5350 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
5351 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
5352 Resolve
(Prefix
(Prefix
(Entry_Name
)));
5353 Index
:= First
(Expressions
(Entry_Name
));
5354 Resolve
(Index
, Entry_Index_Type
(Nam
));
5356 -- Up to this point the expression could have been the actual
5357 -- in a simple entry call, and be given by a named association.
5359 if Nkind
(Index
) = N_Parameter_Association
then
5360 Error_Msg_N
("expect expression for entry index", Index
);
5362 Apply_Range_Check
(Index
, Actual_Index_Type
(Nam
));
5367 ------------------------
5368 -- Resolve_Entry_Call --
5369 ------------------------
5371 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
) is
5372 Entry_Name
: constant Node_Id
:= Name
(N
);
5373 Loc
: constant Source_Ptr
:= Sloc
(Entry_Name
);
5375 First_Named
: Node_Id
;
5382 -- We kill all checks here, because it does not seem worth the
5383 -- effort to do anything better, an entry call is a big operation.
5387 -- Processing of the name is similar for entry calls and protected
5388 -- operation calls. Once the entity is determined, we can complete
5389 -- the resolution of the actuals.
5391 -- The selector may be overloaded, in the case of a protected object
5392 -- with overloaded functions. The type of the context is used for
5395 if Nkind
(Entry_Name
) = N_Selected_Component
5396 and then Is_Overloaded
(Selector_Name
(Entry_Name
))
5397 and then Typ
/= Standard_Void_Type
5404 Get_First_Interp
(Selector_Name
(Entry_Name
), I
, It
);
5405 while Present
(It
.Typ
) loop
5406 if Covers
(Typ
, It
.Typ
) then
5407 Set_Entity
(Selector_Name
(Entry_Name
), It
.Nam
);
5408 Set_Etype
(Entry_Name
, It
.Typ
);
5410 Generate_Reference
(It
.Typ
, N
, ' ');
5413 Get_Next_Interp
(I
, It
);
5418 Resolve_Entry
(Entry_Name
);
5420 if Nkind
(Entry_Name
) = N_Selected_Component
then
5422 -- Simple entry call
5424 Nam
:= Entity
(Selector_Name
(Entry_Name
));
5425 Obj
:= Prefix
(Entry_Name
);
5426 Was_Over
:= Is_Overloaded
(Selector_Name
(Entry_Name
));
5428 else pragma Assert
(Nkind
(Entry_Name
) = N_Indexed_Component
);
5430 -- Call to member of entry family
5432 Nam
:= Entity
(Selector_Name
(Prefix
(Entry_Name
)));
5433 Obj
:= Prefix
(Prefix
(Entry_Name
));
5434 Was_Over
:= Is_Overloaded
(Selector_Name
(Prefix
(Entry_Name
)));
5437 -- We cannot in general check the maximum depth of protected entry
5438 -- calls at compile time. But we can tell that any protected entry
5439 -- call at all violates a specified nesting depth of zero.
5441 if Is_Protected_Type
(Scope
(Nam
)) then
5442 Check_Restriction
(Max_Entry_Queue_Length
, N
);
5445 -- Use context type to disambiguate a protected function that can be
5446 -- called without actuals and that returns an array type, and where
5447 -- the argument list may be an indexing of the returned value.
5449 if Ekind
(Nam
) = E_Function
5450 and then Needs_No_Actuals
(Nam
)
5451 and then Present
(Parameter_Associations
(N
))
5453 ((Is_Array_Type
(Etype
(Nam
))
5454 and then Covers
(Typ
, Component_Type
(Etype
(Nam
))))
5456 or else (Is_Access_Type
(Etype
(Nam
))
5457 and then Is_Array_Type
(Designated_Type
(Etype
(Nam
)))
5458 and then Covers
(Typ
,
5459 Component_Type
(Designated_Type
(Etype
(Nam
))))))
5462 Index_Node
: Node_Id
;
5466 Make_Indexed_Component
(Loc
,
5468 Make_Function_Call
(Loc
,
5469 Name
=> Relocate_Node
(Entry_Name
)),
5470 Expressions
=> Parameter_Associations
(N
));
5472 -- Since we are correcting a node classification error made by
5473 -- the parser, we call Replace rather than Rewrite.
5475 Replace
(N
, Index_Node
);
5476 Set_Etype
(Prefix
(N
), Etype
(Nam
));
5478 Resolve_Indexed_Component
(N
, Typ
);
5483 -- The operation name may have been overloaded. Order the actuals
5484 -- according to the formals of the resolved entity, and set the
5485 -- return type to that of the operation.
5488 Normalize_Actuals
(N
, Nam
, False, Norm_OK
);
5489 pragma Assert
(Norm_OK
);
5490 Set_Etype
(N
, Etype
(Nam
));
5493 Resolve_Actuals
(N
, Nam
);
5494 Generate_Reference
(Nam
, Entry_Name
);
5496 if Ekind
(Nam
) = E_Entry
5497 or else Ekind
(Nam
) = E_Entry_Family
5499 Check_Potentially_Blocking_Operation
(N
);
5502 -- Verify that a procedure call cannot masquerade as an entry
5503 -- call where an entry call is expected.
5505 if Ekind
(Nam
) = E_Procedure
then
5506 if Nkind
(Parent
(N
)) = N_Entry_Call_Alternative
5507 and then N
= Entry_Call_Statement
(Parent
(N
))
5509 Error_Msg_N
("entry call required in select statement", N
);
5511 elsif Nkind
(Parent
(N
)) = N_Triggering_Alternative
5512 and then N
= Triggering_Statement
(Parent
(N
))
5514 Error_Msg_N
("triggering statement cannot be procedure call", N
);
5516 elsif Ekind
(Scope
(Nam
)) = E_Task_Type
5517 and then not In_Open_Scopes
(Scope
(Nam
))
5519 Error_Msg_N
("task has no entry with this name", Entry_Name
);
5523 -- After resolution, entry calls and protected procedure calls
5524 -- are changed into entry calls, for expansion. The structure
5525 -- of the node does not change, so it can safely be done in place.
5526 -- Protected function calls must keep their structure because they
5527 -- are subexpressions.
5529 if Ekind
(Nam
) /= E_Function
then
5531 -- A protected operation that is not a function may modify the
5532 -- corresponding object, and cannot apply to a constant.
5533 -- If this is an internal call, the prefix is the type itself.
5535 if Is_Protected_Type
(Scope
(Nam
))
5536 and then not Is_Variable
(Obj
)
5537 and then (not Is_Entity_Name
(Obj
)
5538 or else not Is_Type
(Entity
(Obj
)))
5541 ("prefix of protected procedure or entry call must be variable",
5545 Actuals
:= Parameter_Associations
(N
);
5546 First_Named
:= First_Named_Actual
(N
);
5549 Make_Entry_Call_Statement
(Loc
,
5551 Parameter_Associations
=> Actuals
));
5553 Set_First_Named_Actual
(N
, First_Named
);
5554 Set_Analyzed
(N
, True);
5556 -- Protected functions can return on the secondary stack, in which
5557 -- case we must trigger the transient scope mechanism.
5559 elsif Expander_Active
5560 and then Requires_Transient_Scope
(Etype
(Nam
))
5562 Establish_Transient_Scope
(N
, Sec_Stack
=> True);
5564 end Resolve_Entry_Call
;
5566 -------------------------
5567 -- Resolve_Equality_Op --
5568 -------------------------
5570 -- Both arguments must have the same type, and the boolean context
5571 -- does not participate in the resolution. The first pass verifies
5572 -- that the interpretation is not ambiguous, and the type of the left
5573 -- argument is correctly set, or is Any_Type in case of ambiguity.
5574 -- If both arguments are strings or aggregates, allocators, or Null,
5575 -- they are ambiguous even though they carry a single (universal) type.
5576 -- Diagnose this case here.
5578 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
5579 L
: constant Node_Id
:= Left_Opnd
(N
);
5580 R
: constant Node_Id
:= Right_Opnd
(N
);
5581 T
: Entity_Id
:= Find_Unique_Type
(L
, R
);
5583 function Find_Unique_Access_Type
return Entity_Id
;
5584 -- In the case of allocators, make a last-ditch attempt to find a single
5585 -- access type with the right designated type. This is semantically
5586 -- dubious, and of no interest to any real code, but c48008a makes it
5589 -----------------------------
5590 -- Find_Unique_Access_Type --
5591 -----------------------------
5593 function Find_Unique_Access_Type
return Entity_Id
is
5599 if Ekind
(Etype
(R
)) = E_Allocator_Type
then
5600 Acc
:= Designated_Type
(Etype
(R
));
5601 elsif Ekind
(Etype
(L
)) = E_Allocator_Type
then
5602 Acc
:= Designated_Type
(Etype
(L
));
5608 while S
/= Standard_Standard
loop
5609 E
:= First_Entity
(S
);
5610 while Present
(E
) loop
5612 and then Is_Access_Type
(E
)
5613 and then Ekind
(E
) /= E_Allocator_Type
5614 and then Designated_Type
(E
) = Base_Type
(Acc
)
5626 end Find_Unique_Access_Type
;
5628 -- Start of processing for Resolve_Equality_Op
5631 Set_Etype
(N
, Base_Type
(Typ
));
5632 Generate_Reference
(T
, N
, ' ');
5634 if T
= Any_Fixed
then
5635 T
:= Unique_Fixed_Point_Type
(L
);
5638 if T
/= Any_Type
then
5640 or else T
= Any_Composite
5641 or else T
= Any_Character
5643 if T
= Any_Character
then
5644 Ambiguous_Character
(L
);
5646 Error_Msg_N
("ambiguous operands for equality", N
);
5649 Set_Etype
(N
, Any_Type
);
5652 elsif T
= Any_Access
5653 or else Ekind
(T
) = E_Allocator_Type
5654 or else Ekind
(T
) = E_Access_Attribute_Type
5656 T
:= Find_Unique_Access_Type
;
5659 Error_Msg_N
("ambiguous operands for equality", N
);
5660 Set_Etype
(N
, Any_Type
);
5668 -- If the unique type is a class-wide type then it will be expanded
5669 -- into a dispatching call to the predefined primitive. Therefore we
5670 -- check here for potential violation of such restriction.
5672 if Is_Class_Wide_Type
(T
) then
5673 Check_Restriction
(No_Dispatching_Calls
, N
);
5676 if Warn_On_Redundant_Constructs
5677 and then Comes_From_Source
(N
)
5678 and then Is_Entity_Name
(R
)
5679 and then Entity
(R
) = Standard_True
5680 and then Comes_From_Source
(R
)
5682 Error_Msg_N
("?comparison with True is redundant!", R
);
5685 Check_Unset_Reference
(L
);
5686 Check_Unset_Reference
(R
);
5687 Generate_Operator_Reference
(N
, T
);
5689 -- If this is an inequality, it may be the implicit inequality
5690 -- created for a user-defined operation, in which case the corres-
5691 -- ponding equality operation is not intrinsic, and the operation
5692 -- cannot be constant-folded. Else fold.
5694 if Nkind
(N
) = N_Op_Eq
5695 or else Comes_From_Source
(Entity
(N
))
5696 or else Ekind
(Entity
(N
)) = E_Operator
5697 or else Is_Intrinsic_Subprogram
5698 (Corresponding_Equality
(Entity
(N
)))
5700 Eval_Relational_Op
(N
);
5701 elsif Nkind
(N
) = N_Op_Ne
5702 and then Is_Abstract_Subprogram
(Entity
(N
))
5704 Error_Msg_NE
("cannot call abstract subprogram &!", N
, Entity
(N
));
5707 -- Ada 2005: If one operand is an anonymous access type, convert
5708 -- the other operand to it, to ensure that the underlying types
5709 -- match in the back-end. Same for access_to_subprogram, and the
5710 -- conversion verifies that the types are subtype conformant.
5712 -- We apply the same conversion in the case one of the operands is
5713 -- a private subtype of the type of the other.
5715 -- Why the Expander_Active test here ???
5719 (Ekind
(T
) = E_Anonymous_Access_Type
5720 or else Ekind
(T
) = E_Anonymous_Access_Subprogram_Type
5721 or else Is_Private_Type
(T
))
5723 if Etype
(L
) /= T
then
5725 Make_Unchecked_Type_Conversion
(Sloc
(L
),
5726 Subtype_Mark
=> New_Occurrence_Of
(T
, Sloc
(L
)),
5727 Expression
=> Relocate_Node
(L
)));
5728 Analyze_And_Resolve
(L
, T
);
5731 if (Etype
(R
)) /= T
then
5733 Make_Unchecked_Type_Conversion
(Sloc
(R
),
5734 Subtype_Mark
=> New_Occurrence_Of
(Etype
(L
), Sloc
(R
)),
5735 Expression
=> Relocate_Node
(R
)));
5736 Analyze_And_Resolve
(R
, T
);
5740 end Resolve_Equality_Op
;
5742 ----------------------------------
5743 -- Resolve_Explicit_Dereference --
5744 ----------------------------------
5746 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
5747 Loc
: constant Source_Ptr
:= Sloc
(N
);
5749 P
: constant Node_Id
:= Prefix
(N
);
5754 Check_Fully_Declared_Prefix
(Typ
, P
);
5756 if Is_Overloaded
(P
) then
5758 -- Use the context type to select the prefix that has the correct
5761 Get_First_Interp
(P
, I
, It
);
5762 while Present
(It
.Typ
) loop
5763 exit when Is_Access_Type
(It
.Typ
)
5764 and then Covers
(Typ
, Designated_Type
(It
.Typ
));
5765 Get_Next_Interp
(I
, It
);
5768 if Present
(It
.Typ
) then
5769 Resolve
(P
, It
.Typ
);
5771 -- If no interpretation covers the designated type of the prefix,
5772 -- this is the pathological case where not all implementations of
5773 -- the prefix allow the interpretation of the node as a call. Now
5774 -- that the expected type is known, Remove other interpretations
5775 -- from prefix, rewrite it as a call, and resolve again, so that
5776 -- the proper call node is generated.
5778 Get_First_Interp
(P
, I
, It
);
5779 while Present
(It
.Typ
) loop
5780 if Ekind
(It
.Typ
) /= E_Access_Subprogram_Type
then
5784 Get_Next_Interp
(I
, It
);
5788 Make_Function_Call
(Loc
,
5790 Make_Explicit_Dereference
(Loc
,
5792 Parameter_Associations
=> New_List
);
5794 Save_Interps
(N
, New_N
);
5796 Analyze_And_Resolve
(N
, Typ
);
5800 Set_Etype
(N
, Designated_Type
(It
.Typ
));
5806 if Is_Access_Type
(Etype
(P
)) then
5807 Apply_Access_Check
(N
);
5810 -- If the designated type is a packed unconstrained array type, and the
5811 -- explicit dereference is not in the context of an attribute reference,
5812 -- then we must compute and set the actual subtype, since it is needed
5813 -- by Gigi. The reason we exclude the attribute case is that this is
5814 -- handled fine by Gigi, and in fact we use such attributes to build the
5815 -- actual subtype. We also exclude generated code (which builds actual
5816 -- subtypes directly if they are needed).
5818 if Is_Array_Type
(Etype
(N
))
5819 and then Is_Packed
(Etype
(N
))
5820 and then not Is_Constrained
(Etype
(N
))
5821 and then Nkind
(Parent
(N
)) /= N_Attribute_Reference
5822 and then Comes_From_Source
(N
)
5824 Set_Etype
(N
, Get_Actual_Subtype
(N
));
5827 -- Note: there is no Eval processing required for an explicit deference,
5828 -- because the type is known to be an allocators, and allocator
5829 -- expressions can never be static.
5831 end Resolve_Explicit_Dereference
;
5833 -------------------------------
5834 -- Resolve_Indexed_Component --
5835 -------------------------------
5837 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
5838 Name
: constant Node_Id
:= Prefix
(N
);
5840 Array_Type
: Entity_Id
:= Empty
; -- to prevent junk warning
5844 if Is_Overloaded
(Name
) then
5846 -- Use the context type to select the prefix that yields the correct
5852 I1
: Interp_Index
:= 0;
5853 P
: constant Node_Id
:= Prefix
(N
);
5854 Found
: Boolean := False;
5857 Get_First_Interp
(P
, I
, It
);
5858 while Present
(It
.Typ
) loop
5859 if (Is_Array_Type
(It
.Typ
)
5860 and then Covers
(Typ
, Component_Type
(It
.Typ
)))
5861 or else (Is_Access_Type
(It
.Typ
)
5862 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
5864 (Typ
, Component_Type
(Designated_Type
(It
.Typ
))))
5867 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
5869 if It
= No_Interp
then
5870 Error_Msg_N
("ambiguous prefix for indexing", N
);
5876 Array_Type
:= It
.Typ
;
5882 Array_Type
:= It
.Typ
;
5887 Get_Next_Interp
(I
, It
);
5892 Array_Type
:= Etype
(Name
);
5895 Resolve
(Name
, Array_Type
);
5896 Array_Type
:= Get_Actual_Subtype_If_Available
(Name
);
5898 -- If prefix is access type, dereference to get real array type.
5899 -- Note: we do not apply an access check because the expander always
5900 -- introduces an explicit dereference, and the check will happen there.
5902 if Is_Access_Type
(Array_Type
) then
5903 Array_Type
:= Designated_Type
(Array_Type
);
5906 -- If name was overloaded, set component type correctly now
5907 -- If a misplaced call to an entry family (which has no index typs)
5908 -- return. Error will be diagnosed from calling context.
5910 if Is_Array_Type
(Array_Type
) then
5911 Set_Etype
(N
, Component_Type
(Array_Type
));
5916 Index
:= First_Index
(Array_Type
);
5917 Expr
:= First
(Expressions
(N
));
5919 -- The prefix may have resolved to a string literal, in which case its
5920 -- etype has a special representation. This is only possible currently
5921 -- if the prefix is a static concatenation, written in functional
5924 if Ekind
(Array_Type
) = E_String_Literal_Subtype
then
5925 Resolve
(Expr
, Standard_Positive
);
5928 while Present
(Index
) and Present
(Expr
) loop
5929 Resolve
(Expr
, Etype
(Index
));
5930 Check_Unset_Reference
(Expr
);
5932 if Is_Scalar_Type
(Etype
(Expr
)) then
5933 Apply_Scalar_Range_Check
(Expr
, Etype
(Index
));
5935 Apply_Range_Check
(Expr
, Get_Actual_Subtype
(Index
));
5943 -- Do not generate the warning on suspicious index if we are analyzing
5944 -- package Ada.Tags; otherwise we will report the warning with the
5945 -- Prims_Ptr field of the dispatch table.
5947 if Scope
(Etype
(Prefix
(N
))) = Standard_Standard
5949 Is_RTU
(Cunit_Entity
(Get_Source_Unit
(Etype
(Prefix
(N
)))),
5952 Warn_On_Suspicious_Index
(Name
, First
(Expressions
(N
)));
5953 Eval_Indexed_Component
(N
);
5955 end Resolve_Indexed_Component
;
5957 -----------------------------
5958 -- Resolve_Integer_Literal --
5959 -----------------------------
5961 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
5964 Eval_Integer_Literal
(N
);
5965 end Resolve_Integer_Literal
;
5967 --------------------------------
5968 -- Resolve_Intrinsic_Operator --
5969 --------------------------------
5971 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
) is
5972 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
5979 while Scope
(Op
) /= Standard_Standard
loop
5981 pragma Assert
(Present
(Op
));
5985 Set_Is_Overloaded
(N
, False);
5987 -- If the operand type is private, rewrite with suitable conversions on
5988 -- the operands and the result, to expose the proper underlying numeric
5991 if Is_Private_Type
(Typ
) then
5992 Arg1
:= Unchecked_Convert_To
(Btyp
, Left_Opnd
(N
));
5994 if Nkind
(N
) = N_Op_Expon
then
5995 Arg2
:= Unchecked_Convert_To
(Standard_Integer
, Right_Opnd
(N
));
5997 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
6000 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
6001 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
6003 Set_Left_Opnd
(N
, Arg1
);
6004 Set_Right_Opnd
(N
, Arg2
);
6006 Set_Etype
(N
, Btyp
);
6007 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
6010 elsif Typ
/= Etype
(Left_Opnd
(N
))
6011 or else Typ
/= Etype
(Right_Opnd
(N
))
6013 -- Add explicit conversion where needed, and save interpretations
6014 -- in case operands are overloaded.
6016 Arg1
:= Convert_To
(Typ
, Left_Opnd
(N
));
6017 Arg2
:= Convert_To
(Typ
, Right_Opnd
(N
));
6019 if Nkind
(Arg1
) = N_Type_Conversion
then
6020 Save_Interps
(Left_Opnd
(N
), Expression
(Arg1
));
6022 Save_Interps
(Left_Opnd
(N
), Arg1
);
6025 if Nkind
(Arg2
) = N_Type_Conversion
then
6026 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
6028 Save_Interps
(Right_Opnd
(N
), Arg2
);
6031 Rewrite
(Left_Opnd
(N
), Arg1
);
6032 Rewrite
(Right_Opnd
(N
), Arg2
);
6035 Resolve_Arithmetic_Op
(N
, Typ
);
6038 Resolve_Arithmetic_Op
(N
, Typ
);
6040 end Resolve_Intrinsic_Operator
;
6042 --------------------------------------
6043 -- Resolve_Intrinsic_Unary_Operator --
6044 --------------------------------------
6046 procedure Resolve_Intrinsic_Unary_Operator
6050 Btyp
: constant Entity_Id
:= Base_Type
(Underlying_Type
(Typ
));
6056 while Scope
(Op
) /= Standard_Standard
loop
6058 pragma Assert
(Present
(Op
));
6063 if Is_Private_Type
(Typ
) then
6064 Arg2
:= Unchecked_Convert_To
(Btyp
, Right_Opnd
(N
));
6065 Save_Interps
(Right_Opnd
(N
), Expression
(Arg2
));
6067 Set_Right_Opnd
(N
, Arg2
);
6069 Set_Etype
(N
, Btyp
);
6070 Rewrite
(N
, Unchecked_Convert_To
(Typ
, N
));
6074 Resolve_Unary_Op
(N
, Typ
);
6076 end Resolve_Intrinsic_Unary_Operator
;
6078 ------------------------
6079 -- Resolve_Logical_Op --
6080 ------------------------
6082 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6084 N_Opr
: constant Node_Kind
:= Nkind
(N
);
6087 -- Predefined operations on scalar types yield the base type. On the
6088 -- other hand, logical operations on arrays yield the type of the
6089 -- arguments (and the context).
6091 if Is_Array_Type
(Typ
) then
6094 B_Typ
:= Base_Type
(Typ
);
6097 -- The following test is required because the operands of the operation
6098 -- may be literals, in which case the resulting type appears to be
6099 -- compatible with a signed integer type, when in fact it is compatible
6100 -- only with modular types. If the context itself is universal, the
6101 -- operation is illegal.
6103 if not Valid_Boolean_Arg
(Typ
) then
6104 Error_Msg_N
("invalid context for logical operation", N
);
6105 Set_Etype
(N
, Any_Type
);
6108 elsif Typ
= Any_Modular
then
6110 ("no modular type available in this context", N
);
6111 Set_Etype
(N
, Any_Type
);
6113 elsif Is_Modular_Integer_Type
(Typ
)
6114 and then Etype
(Left_Opnd
(N
)) = Universal_Integer
6115 and then Etype
(Right_Opnd
(N
)) = Universal_Integer
6117 Check_For_Visible_Operator
(N
, B_Typ
);
6120 Resolve
(Left_Opnd
(N
), B_Typ
);
6121 Resolve
(Right_Opnd
(N
), B_Typ
);
6123 Check_Unset_Reference
(Left_Opnd
(N
));
6124 Check_Unset_Reference
(Right_Opnd
(N
));
6126 Set_Etype
(N
, B_Typ
);
6127 Generate_Operator_Reference
(N
, B_Typ
);
6128 Eval_Logical_Op
(N
);
6130 -- Check for violation of restriction No_Direct_Boolean_Operators
6131 -- if the operator was not eliminated by the Eval_Logical_Op call.
6133 if Nkind
(N
) = N_Opr
6134 and then Root_Type
(Etype
(Left_Opnd
(N
))) = Standard_Boolean
6136 Check_Restriction
(No_Direct_Boolean_Operators
, N
);
6138 end Resolve_Logical_Op
;
6140 ---------------------------
6141 -- Resolve_Membership_Op --
6142 ---------------------------
6144 -- The context can only be a boolean type, and does not determine
6145 -- the arguments. Arguments should be unambiguous, but the preference
6146 -- rule for universal types applies.
6148 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
6149 pragma Warnings
(Off
, Typ
);
6151 L
: constant Node_Id
:= Left_Opnd
(N
);
6152 R
: constant Node_Id
:= Right_Opnd
(N
);
6156 if L
= Error
or else R
= Error
then
6160 if not Is_Overloaded
(R
)
6162 (Etype
(R
) = Universal_Integer
or else
6163 Etype
(R
) = Universal_Real
)
6164 and then Is_Overloaded
(L
)
6168 -- Ada 2005 (AI-251): Give support to the following case:
6170 -- type I is interface;
6171 -- type T is tagged ...
6173 -- function Test (O : I'Class) is
6175 -- return O in T'Class.
6178 -- In this case we have nothing else to do; the membership test will be
6179 -- done at run-time.
6181 elsif Ada_Version
>= Ada_05
6182 and then Is_Class_Wide_Type
(Etype
(L
))
6183 and then Is_Interface
(Etype
(L
))
6184 and then Is_Class_Wide_Type
(Etype
(R
))
6185 and then not Is_Interface
(Etype
(R
))
6190 T
:= Intersect_Types
(L
, R
);
6194 Check_Unset_Reference
(L
);
6196 if Nkind
(R
) = N_Range
6197 and then not Is_Scalar_Type
(T
)
6199 Error_Msg_N
("scalar type required for range", R
);
6202 if Is_Entity_Name
(R
) then
6203 Freeze_Expression
(R
);
6206 Check_Unset_Reference
(R
);
6209 Eval_Membership_Op
(N
);
6210 end Resolve_Membership_Op
;
6216 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
) is
6218 -- Handle restriction against anonymous null access values This
6219 -- restriction can be turned off using -gnatdh.
6221 -- Ada 2005 (AI-231): Remove restriction
6223 if Ada_Version
< Ada_05
6224 and then not Debug_Flag_J
6225 and then Ekind
(Typ
) = E_Anonymous_Access_Type
6226 and then Comes_From_Source
(N
)
6228 -- In the common case of a call which uses an explicitly null
6229 -- value for an access parameter, give specialized error msg
6231 if Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
6233 Nkind
(Parent
(N
)) = N_Function_Call
6236 ("null is not allowed as argument for an access parameter", N
);
6238 -- Standard message for all other cases (are there any?)
6242 ("null cannot be of an anonymous access type", N
);
6246 -- In a distributed context, null for a remote access to subprogram
6247 -- may need to be replaced with a special record aggregate. In this
6248 -- case, return after having done the transformation.
6250 if (Ekind
(Typ
) = E_Record_Type
6251 or else Is_Remote_Access_To_Subprogram_Type
(Typ
))
6252 and then Remote_AST_Null_Value
(N
, Typ
)
6257 -- The null literal takes its type from the context
6262 -----------------------
6263 -- Resolve_Op_Concat --
6264 -----------------------
6266 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
) is
6267 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6268 Op1
: constant Node_Id
:= Left_Opnd
(N
);
6269 Op2
: constant Node_Id
:= Right_Opnd
(N
);
6271 procedure Resolve_Concatenation_Arg
(Arg
: Node_Id
; Is_Comp
: Boolean);
6272 -- Internal procedure to resolve one operand of concatenation operator.
6273 -- The operand is either of the array type or of the component type.
6274 -- If the operand is an aggregate, and the component type is composite,
6275 -- this is ambiguous if component type has aggregates.
6277 -------------------------------
6278 -- Resolve_Concatenation_Arg --
6279 -------------------------------
6281 procedure Resolve_Concatenation_Arg
(Arg
: Node_Id
; Is_Comp
: Boolean) is
6285 or else (not Is_Overloaded
(Arg
)
6286 and then Etype
(Arg
) /= Any_Composite
6287 and then Covers
(Component_Type
(Typ
), Etype
(Arg
)))
6289 Resolve
(Arg
, Component_Type
(Typ
));
6291 Resolve
(Arg
, Btyp
);
6294 elsif Has_Compatible_Type
(Arg
, Component_Type
(Typ
)) then
6296 if Nkind
(Arg
) = N_Aggregate
6297 and then Is_Composite_Type
(Component_Type
(Typ
))
6299 if Is_Private_Type
(Component_Type
(Typ
)) then
6300 Resolve
(Arg
, Btyp
);
6303 Error_Msg_N
("ambiguous aggregate must be qualified", Arg
);
6304 Set_Etype
(Arg
, Any_Type
);
6308 if Is_Overloaded
(Arg
)
6309 and then Has_Compatible_Type
(Arg
, Typ
)
6310 and then Etype
(Arg
) /= Any_Type
6319 Get_First_Interp
(Arg
, I
, It
);
6321 Get_Next_Interp
(I
, It
);
6323 -- Special-case the error message when the overloading
6324 -- is caused by a function that yields and array and
6325 -- can be called without parameters.
6327 if It
.Nam
= Func
then
6328 Error_Msg_Sloc
:= Sloc
(Func
);
6329 Error_Msg_N
("ambiguous call to function#", Arg
);
6331 ("\\interpretation as call yields&", Arg
, Typ
);
6333 ("\\interpretation as indexing of call yields&",
6334 Arg
, Component_Type
(Typ
));
6338 ("ambiguous operand for concatenation!", Arg
);
6339 Get_First_Interp
(Arg
, I
, It
);
6340 while Present
(It
.Nam
) loop
6341 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
6343 if Base_Type
(It
.Typ
) = Base_Type
(Typ
)
6344 or else Base_Type
(It
.Typ
) =
6345 Base_Type
(Component_Type
(Typ
))
6347 Error_Msg_N
("\\possible interpretation#", Arg
);
6350 Get_Next_Interp
(I
, It
);
6356 Resolve
(Arg
, Component_Type
(Typ
));
6358 if Nkind
(Arg
) = N_String_Literal
then
6359 Set_Etype
(Arg
, Component_Type
(Typ
));
6362 if Arg
= Left_Opnd
(N
) then
6363 Set_Is_Component_Left_Opnd
(N
);
6365 Set_Is_Component_Right_Opnd
(N
);
6370 Resolve
(Arg
, Btyp
);
6373 Check_Unset_Reference
(Arg
);
6374 end Resolve_Concatenation_Arg
;
6376 -- Start of processing for Resolve_Op_Concat
6379 -- The parser folds an enormous sequence of concatenations of string
6380 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
6381 -- in the right. If the expression resolves to a predefined "&"
6382 -- operator, all is well. Otherwise, the parser's folding is wrong, so
6383 -- we give an error. See P_Simple_Expression in Par.Ch4.
6385 if Nkind
(Op2
) = N_String_Literal
6386 and then Is_Folded_In_Parser
(Op2
)
6387 and then Ekind
(Entity
(N
)) = E_Function
6389 pragma Assert
(Nkind
(Op1
) = N_String_Literal
-- should be ""
6390 and then String_Length
(Strval
(Op1
)) = 0);
6391 Error_Msg_N
("too many user-defined concatenations", N
);
6395 Set_Etype
(N
, Btyp
);
6397 if Is_Limited_Composite
(Btyp
) then
6398 Error_Msg_N
("concatenation not available for limited array", N
);
6399 Explain_Limited_Type
(Btyp
, N
);
6402 -- If the operands are themselves concatenations, resolve them as such
6403 -- directly. This removes several layers of recursion and allows GNAT to
6404 -- handle larger multiple concatenations.
6406 if Nkind
(Op1
) = N_Op_Concat
6407 and then not Is_Array_Type
(Component_Type
(Typ
))
6408 and then Entity
(Op1
) = Entity
(N
)
6410 Resolve_Op_Concat
(Op1
, Typ
);
6412 Resolve_Concatenation_Arg
6413 (Op1
, Is_Component_Left_Opnd
(N
));
6416 if Nkind
(Op2
) = N_Op_Concat
6417 and then not Is_Array_Type
(Component_Type
(Typ
))
6418 and then Entity
(Op2
) = Entity
(N
)
6420 Resolve_Op_Concat
(Op2
, Typ
);
6422 Resolve_Concatenation_Arg
6423 (Op2
, Is_Component_Right_Opnd
(N
));
6426 Generate_Operator_Reference
(N
, Typ
);
6428 if Is_String_Type
(Typ
) then
6429 Eval_Concatenation
(N
);
6432 -- If this is not a static concatenation, but the result is a
6433 -- string type (and not an array of strings) insure that static
6434 -- string operands have their subtypes properly constructed.
6436 if Nkind
(N
) /= N_String_Literal
6437 and then Is_Character_Type
(Component_Type
(Typ
))
6439 Set_String_Literal_Subtype
(Op1
, Typ
);
6440 Set_String_Literal_Subtype
(Op2
, Typ
);
6442 end Resolve_Op_Concat
;
6444 ----------------------
6445 -- Resolve_Op_Expon --
6446 ----------------------
6448 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
) is
6449 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
6452 -- Catch attempts to do fixed-point exponentation with universal
6453 -- operands, which is a case where the illegality is not caught during
6454 -- normal operator analysis.
6456 if Is_Fixed_Point_Type
(Typ
) and then Comes_From_Source
(N
) then
6457 Error_Msg_N
("exponentiation not available for fixed point", N
);
6461 if Comes_From_Source
(N
)
6462 and then Ekind
(Entity
(N
)) = E_Function
6463 and then Is_Imported
(Entity
(N
))
6464 and then Is_Intrinsic_Subprogram
(Entity
(N
))
6466 Resolve_Intrinsic_Operator
(N
, Typ
);
6470 if Etype
(Left_Opnd
(N
)) = Universal_Integer
6471 or else Etype
(Left_Opnd
(N
)) = Universal_Real
6473 Check_For_Visible_Operator
(N
, B_Typ
);
6476 -- We do the resolution using the base type, because intermediate values
6477 -- in expressions always are of the base type, not a subtype of it.
6479 Resolve
(Left_Opnd
(N
), B_Typ
);
6480 Resolve
(Right_Opnd
(N
), Standard_Integer
);
6482 Check_Unset_Reference
(Left_Opnd
(N
));
6483 Check_Unset_Reference
(Right_Opnd
(N
));
6485 Set_Etype
(N
, B_Typ
);
6486 Generate_Operator_Reference
(N
, B_Typ
);
6489 -- Set overflow checking bit. Much cleverer code needed here eventually
6490 -- and perhaps the Resolve routines should be separated for the various
6491 -- arithmetic operations, since they will need different processing. ???
6493 if Nkind
(N
) in N_Op
then
6494 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
6495 Enable_Overflow_Check
(N
);
6498 end Resolve_Op_Expon
;
6500 --------------------
6501 -- Resolve_Op_Not --
6502 --------------------
6504 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
) is
6507 function Parent_Is_Boolean
return Boolean;
6508 -- This function determines if the parent node is a boolean operator
6509 -- or operation (comparison op, membership test, or short circuit form)
6510 -- and the not in question is the left operand of this operation.
6511 -- Note that if the not is in parens, then false is returned.
6513 -----------------------
6514 -- Parent_Is_Boolean --
6515 -----------------------
6517 function Parent_Is_Boolean
return Boolean is
6519 if Paren_Count
(N
) /= 0 then
6523 case Nkind
(Parent
(N
)) is
6538 return Left_Opnd
(Parent
(N
)) = N
;
6544 end Parent_Is_Boolean
;
6546 -- Start of processing for Resolve_Op_Not
6549 -- Predefined operations on scalar types yield the base type. On the
6550 -- other hand, logical operations on arrays yield the type of the
6551 -- arguments (and the context).
6553 if Is_Array_Type
(Typ
) then
6556 B_Typ
:= Base_Type
(Typ
);
6559 -- Straigtforward case of incorrect arguments
6561 if not Valid_Boolean_Arg
(Typ
) then
6562 Error_Msg_N
("invalid operand type for operator&", N
);
6563 Set_Etype
(N
, Any_Type
);
6566 -- Special case of probable missing parens
6568 elsif Typ
= Universal_Integer
or else Typ
= Any_Modular
then
6569 if Parent_Is_Boolean
then
6571 ("operand of not must be enclosed in parentheses",
6575 ("no modular type available in this context", N
);
6578 Set_Etype
(N
, Any_Type
);
6581 -- OK resolution of not
6584 -- Warn if non-boolean types involved. This is a case like not a < b
6585 -- where a and b are modular, where we will get (not a) < b and most
6586 -- likely not (a < b) was intended.
6588 if Warn_On_Questionable_Missing_Parens
6589 and then not Is_Boolean_Type
(Typ
)
6590 and then Parent_Is_Boolean
6592 Error_Msg_N
("?not expression should be parenthesized here!", N
);
6595 Resolve
(Right_Opnd
(N
), B_Typ
);
6596 Check_Unset_Reference
(Right_Opnd
(N
));
6597 Set_Etype
(N
, B_Typ
);
6598 Generate_Operator_Reference
(N
, B_Typ
);
6603 -----------------------------
6604 -- Resolve_Operator_Symbol --
6605 -----------------------------
6607 -- Nothing to be done, all resolved already
6609 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
) is
6610 pragma Warnings
(Off
, N
);
6611 pragma Warnings
(Off
, Typ
);
6615 end Resolve_Operator_Symbol
;
6617 ----------------------------------
6618 -- Resolve_Qualified_Expression --
6619 ----------------------------------
6621 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
) is
6622 pragma Warnings
(Off
, Typ
);
6624 Target_Typ
: constant Entity_Id
:= Entity
(Subtype_Mark
(N
));
6625 Expr
: constant Node_Id
:= Expression
(N
);
6628 Resolve
(Expr
, Target_Typ
);
6630 -- A qualified expression requires an exact match of the type,
6631 -- class-wide matching is not allowed. However, if the qualifying
6632 -- type is specific and the expression has a class-wide type, it
6633 -- may still be okay, since it can be the result of the expansion
6634 -- of a call to a dispatching function, so we also have to check
6635 -- class-wideness of the type of the expression's original node.
6637 if (Is_Class_Wide_Type
(Target_Typ
)
6639 (Is_Class_Wide_Type
(Etype
(Expr
))
6640 and then Is_Class_Wide_Type
(Etype
(Original_Node
(Expr
)))))
6641 and then Base_Type
(Etype
(Expr
)) /= Base_Type
(Target_Typ
)
6643 Wrong_Type
(Expr
, Target_Typ
);
6646 -- If the target type is unconstrained, then we reset the type of
6647 -- the result from the type of the expression. For other cases, the
6648 -- actual subtype of the expression is the target type.
6650 if Is_Composite_Type
(Target_Typ
)
6651 and then not Is_Constrained
(Target_Typ
)
6653 Set_Etype
(N
, Etype
(Expr
));
6656 Eval_Qualified_Expression
(N
);
6657 end Resolve_Qualified_Expression
;
6663 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
) is
6664 L
: constant Node_Id
:= Low_Bound
(N
);
6665 H
: constant Node_Id
:= High_Bound
(N
);
6672 Check_Unset_Reference
(L
);
6673 Check_Unset_Reference
(H
);
6675 -- We have to check the bounds for being within the base range as
6676 -- required for a non-static context. Normally this is automatic and
6677 -- done as part of evaluating expressions, but the N_Range node is an
6678 -- exception, since in GNAT we consider this node to be a subexpression,
6679 -- even though in Ada it is not. The circuit in Sem_Eval could check for
6680 -- this, but that would put the test on the main evaluation path for
6683 Check_Non_Static_Context
(L
);
6684 Check_Non_Static_Context
(H
);
6686 -- Check for an ambiguous range over character literals. This will
6687 -- happen with a membership test involving only literals.
6689 if Typ
= Any_Character
then
6690 Ambiguous_Character
(L
);
6691 Set_Etype
(N
, Any_Type
);
6695 -- If bounds are static, constant-fold them, so size computations
6696 -- are identical between front-end and back-end. Do not perform this
6697 -- transformation while analyzing generic units, as type information
6698 -- would then be lost when reanalyzing the constant node in the
6701 if Is_Discrete_Type
(Typ
) and then Expander_Active
then
6702 if Is_OK_Static_Expression
(L
) then
6703 Fold_Uint
(L
, Expr_Value
(L
), Is_Static_Expression
(L
));
6706 if Is_OK_Static_Expression
(H
) then
6707 Fold_Uint
(H
, Expr_Value
(H
), Is_Static_Expression
(H
));
6712 --------------------------
6713 -- Resolve_Real_Literal --
6714 --------------------------
6716 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
6717 Actual_Typ
: constant Entity_Id
:= Etype
(N
);
6720 -- Special processing for fixed-point literals to make sure that the
6721 -- value is an exact multiple of small where this is required. We
6722 -- skip this for the universal real case, and also for generic types.
6724 if Is_Fixed_Point_Type
(Typ
)
6725 and then Typ
/= Universal_Fixed
6726 and then Typ
/= Any_Fixed
6727 and then not Is_Generic_Type
(Typ
)
6730 Val
: constant Ureal
:= Realval
(N
);
6731 Cintr
: constant Ureal
:= Val
/ Small_Value
(Typ
);
6732 Cint
: constant Uint
:= UR_Trunc
(Cintr
);
6733 Den
: constant Uint
:= Norm_Den
(Cintr
);
6737 -- Case of literal is not an exact multiple of the Small
6741 -- For a source program literal for a decimal fixed-point
6742 -- type, this is statically illegal (RM 4.9(36)).
6744 if Is_Decimal_Fixed_Point_Type
(Typ
)
6745 and then Actual_Typ
= Universal_Real
6746 and then Comes_From_Source
(N
)
6748 Error_Msg_N
("value has extraneous low order digits", N
);
6751 -- Generate a warning if literal from source
6753 if Is_Static_Expression
(N
)
6754 and then Warn_On_Bad_Fixed_Value
6757 ("?static fixed-point value is not a multiple of Small!",
6761 -- Replace literal by a value that is the exact representation
6762 -- of a value of the type, i.e. a multiple of the small value,
6763 -- by truncation, since Machine_Rounds is false for all GNAT
6764 -- fixed-point types (RM 4.9(38)).
6766 Stat
:= Is_Static_Expression
(N
);
6768 Make_Real_Literal
(Sloc
(N
),
6769 Realval
=> Small_Value
(Typ
) * Cint
));
6771 Set_Is_Static_Expression
(N
, Stat
);
6774 -- In all cases, set the corresponding integer field
6776 Set_Corresponding_Integer_Value
(N
, Cint
);
6780 -- Now replace the actual type by the expected type as usual
6783 Eval_Real_Literal
(N
);
6784 end Resolve_Real_Literal
;
6786 -----------------------
6787 -- Resolve_Reference --
6788 -----------------------
6790 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
) is
6791 P
: constant Node_Id
:= Prefix
(N
);
6794 -- Replace general access with specific type
6796 if Ekind
(Etype
(N
)) = E_Allocator_Type
then
6797 Set_Etype
(N
, Base_Type
(Typ
));
6800 Resolve
(P
, Designated_Type
(Etype
(N
)));
6802 -- If we are taking the reference of a volatile entity, then treat
6803 -- it as a potential modification of this entity. This is much too
6804 -- conservative, but is necessary because remove side effects can
6805 -- result in transformations of normal assignments into reference
6806 -- sequences that otherwise fail to notice the modification.
6808 if Is_Entity_Name
(P
) and then Treat_As_Volatile
(Entity
(P
)) then
6809 Note_Possible_Modification
(P
);
6811 end Resolve_Reference
;
6813 --------------------------------
6814 -- Resolve_Selected_Component --
6815 --------------------------------
6817 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
) is
6819 Comp1
: Entity_Id
:= Empty
; -- prevent junk warning
6820 P
: constant Node_Id
:= Prefix
(N
);
6821 S
: constant Node_Id
:= Selector_Name
(N
);
6822 T
: Entity_Id
:= Etype
(P
);
6824 I1
: Interp_Index
:= 0; -- prevent junk warning
6829 function Init_Component
return Boolean;
6830 -- Check whether this is the initialization of a component within an
6831 -- init proc (by assignment or call to another init proc). If true,
6832 -- there is no need for a discriminant check.
6834 --------------------
6835 -- Init_Component --
6836 --------------------
6838 function Init_Component
return Boolean is
6840 return Inside_Init_Proc
6841 and then Nkind
(Prefix
(N
)) = N_Identifier
6842 and then Chars
(Prefix
(N
)) = Name_uInit
6843 and then Nkind
(Parent
(Parent
(N
))) = N_Case_Statement_Alternative
;
6846 -- Start of processing for Resolve_Selected_Component
6849 if Is_Overloaded
(P
) then
6851 -- Use the context type to select the prefix that has a selector
6852 -- of the correct name and type.
6855 Get_First_Interp
(P
, I
, It
);
6857 Search
: while Present
(It
.Typ
) loop
6858 if Is_Access_Type
(It
.Typ
) then
6859 T
:= Designated_Type
(It
.Typ
);
6864 if Is_Record_Type
(T
) then
6865 Comp
:= First_Entity
(T
);
6866 while Present
(Comp
) loop
6867 if Chars
(Comp
) = Chars
(S
)
6868 and then Covers
(Etype
(Comp
), Typ
)
6877 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
6879 if It
= No_Interp
then
6881 ("ambiguous prefix for selected component", N
);
6888 -- There may be an implicit dereference. Retrieve
6889 -- designated record type.
6891 if Is_Access_Type
(It1
.Typ
) then
6892 T
:= Designated_Type
(It1
.Typ
);
6897 if Scope
(Comp1
) /= T
then
6899 -- Resolution chooses the new interpretation.
6900 -- Find the component with the right name.
6902 Comp1
:= First_Entity
(T
);
6903 while Present
(Comp1
)
6904 and then Chars
(Comp1
) /= Chars
(S
)
6906 Comp1
:= Next_Entity
(Comp1
);
6915 Comp
:= Next_Entity
(Comp
);
6920 Get_Next_Interp
(I
, It
);
6923 Resolve
(P
, It1
.Typ
);
6925 Set_Entity_With_Style_Check
(S
, Comp1
);
6928 -- Resolve prefix with its type
6933 -- Generate cross-reference. We needed to wait until full overloading
6934 -- resolution was complete to do this, since otherwise we can't tell if
6935 -- we are an Lvalue of not.
6937 if May_Be_Lvalue
(N
) then
6938 Generate_Reference
(Entity
(S
), S
, 'm');
6940 Generate_Reference
(Entity
(S
), S
, 'r');
6943 -- If prefix is an access type, the node will be transformed into an
6944 -- explicit dereference during expansion. The type of the node is the
6945 -- designated type of that of the prefix.
6947 if Is_Access_Type
(Etype
(P
)) then
6948 T
:= Designated_Type
(Etype
(P
));
6949 Check_Fully_Declared_Prefix
(T
, P
);
6954 if Has_Discriminants
(T
)
6955 and then (Ekind
(Entity
(S
)) = E_Component
6957 Ekind
(Entity
(S
)) = E_Discriminant
)
6958 and then Present
(Original_Record_Component
(Entity
(S
)))
6959 and then Ekind
(Original_Record_Component
(Entity
(S
))) = E_Component
6960 and then Present
(Discriminant_Checking_Func
6961 (Original_Record_Component
(Entity
(S
))))
6962 and then not Discriminant_Checks_Suppressed
(T
)
6963 and then not Init_Component
6965 Set_Do_Discriminant_Check
(N
);
6968 if Ekind
(Entity
(S
)) = E_Void
then
6969 Error_Msg_N
("premature use of component", S
);
6972 -- If the prefix is a record conversion, this may be a renamed
6973 -- discriminant whose bounds differ from those of the original
6974 -- one, so we must ensure that a range check is performed.
6976 if Nkind
(P
) = N_Type_Conversion
6977 and then Ekind
(Entity
(S
)) = E_Discriminant
6978 and then Is_Discrete_Type
(Typ
)
6980 Set_Etype
(N
, Base_Type
(Typ
));
6983 -- Note: No Eval processing is required, because the prefix is of a
6984 -- record type, or protected type, and neither can possibly be static.
6986 end Resolve_Selected_Component
;
6992 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
) is
6993 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
6994 L
: constant Node_Id
:= Left_Opnd
(N
);
6995 R
: constant Node_Id
:= Right_Opnd
(N
);
6998 -- We do the resolution using the base type, because intermediate values
6999 -- in expressions always are of the base type, not a subtype of it.
7002 Resolve
(R
, Standard_Natural
);
7004 Check_Unset_Reference
(L
);
7005 Check_Unset_Reference
(R
);
7007 Set_Etype
(N
, B_Typ
);
7008 Generate_Operator_Reference
(N
, B_Typ
);
7012 ---------------------------
7013 -- Resolve_Short_Circuit --
7014 ---------------------------
7016 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
) is
7017 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7018 L
: constant Node_Id
:= Left_Opnd
(N
);
7019 R
: constant Node_Id
:= Right_Opnd
(N
);
7025 Check_Unset_Reference
(L
);
7026 Check_Unset_Reference
(R
);
7028 Set_Etype
(N
, B_Typ
);
7029 Eval_Short_Circuit
(N
);
7030 end Resolve_Short_Circuit
;
7036 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
) is
7037 Name
: constant Node_Id
:= Prefix
(N
);
7038 Drange
: constant Node_Id
:= Discrete_Range
(N
);
7039 Array_Type
: Entity_Id
:= Empty
;
7043 if Is_Overloaded
(Name
) then
7045 -- Use the context type to select the prefix that yields the
7046 -- correct array type.
7050 I1
: Interp_Index
:= 0;
7052 P
: constant Node_Id
:= Prefix
(N
);
7053 Found
: Boolean := False;
7056 Get_First_Interp
(P
, I
, It
);
7057 while Present
(It
.Typ
) loop
7058 if (Is_Array_Type
(It
.Typ
)
7059 and then Covers
(Typ
, It
.Typ
))
7060 or else (Is_Access_Type
(It
.Typ
)
7061 and then Is_Array_Type
(Designated_Type
(It
.Typ
))
7062 and then Covers
(Typ
, Designated_Type
(It
.Typ
)))
7065 It
:= Disambiguate
(P
, I1
, I
, Any_Type
);
7067 if It
= No_Interp
then
7068 Error_Msg_N
("ambiguous prefix for slicing", N
);
7073 Array_Type
:= It
.Typ
;
7078 Array_Type
:= It
.Typ
;
7083 Get_Next_Interp
(I
, It
);
7088 Array_Type
:= Etype
(Name
);
7091 Resolve
(Name
, Array_Type
);
7093 if Is_Access_Type
(Array_Type
) then
7094 Apply_Access_Check
(N
);
7095 Array_Type
:= Designated_Type
(Array_Type
);
7097 -- If the prefix is an access to an unconstrained array, we must use
7098 -- the actual subtype of the object to perform the index checks. The
7099 -- object denoted by the prefix is implicit in the node, so we build
7100 -- an explicit representation for it in order to compute the actual
7103 if not Is_Constrained
(Array_Type
) then
7104 Remove_Side_Effects
(Prefix
(N
));
7107 Obj
: constant Node_Id
:=
7108 Make_Explicit_Dereference
(Sloc
(N
),
7109 Prefix
=> New_Copy_Tree
(Prefix
(N
)));
7111 Set_Etype
(Obj
, Array_Type
);
7112 Set_Parent
(Obj
, Parent
(N
));
7113 Array_Type
:= Get_Actual_Subtype
(Obj
);
7117 elsif Is_Entity_Name
(Name
)
7118 or else (Nkind
(Name
) = N_Function_Call
7119 and then not Is_Constrained
(Etype
(Name
)))
7121 Array_Type
:= Get_Actual_Subtype
(Name
);
7123 -- If the name is a selected component that depends on discriminants,
7124 -- build an actual subtype for it. This can happen only when the name
7125 -- itself is overloaded; otherwise the actual subtype is created when
7126 -- the selected component is analyzed.
7128 elsif Nkind
(Name
) = N_Selected_Component
7129 and then Full_Analysis
7130 and then Depends_On_Discriminant
(First_Index
(Array_Type
))
7133 Act_Decl
: constant Node_Id
:=
7134 Build_Actual_Subtype_Of_Component
(Array_Type
, Name
);
7136 Insert_Action
(N
, Act_Decl
);
7137 Array_Type
:= Defining_Identifier
(Act_Decl
);
7141 -- If name was overloaded, set slice type correctly now
7143 Set_Etype
(N
, Array_Type
);
7145 -- If the range is specified by a subtype mark, no resolution is
7146 -- necessary. Else resolve the bounds, and apply needed checks.
7148 if not Is_Entity_Name
(Drange
) then
7149 Index
:= First_Index
(Array_Type
);
7150 Resolve
(Drange
, Base_Type
(Etype
(Index
)));
7152 if Nkind
(Drange
) = N_Range
7154 -- Do not apply the range check to nodes associated with the
7155 -- frontend expansion of the dispatch table. We first check
7156 -- if Ada.Tags is already loaded to void the addition of an
7157 -- undesired dependence on such run-time unit.
7162 (RTU_Loaded
(Ada_Tags
)
7163 and then Nkind
(Prefix
(N
)) = N_Selected_Component
7164 and then Present
(Entity
(Selector_Name
(Prefix
(N
))))
7165 and then Entity
(Selector_Name
(Prefix
(N
))) =
7166 RTE_Record_Component
(RE_Prims_Ptr
)))
7168 Apply_Range_Check
(Drange
, Etype
(Index
));
7172 Set_Slice_Subtype
(N
);
7174 if Nkind
(Drange
) = N_Range
then
7175 Warn_On_Suspicious_Index
(Name
, Low_Bound
(Drange
));
7176 Warn_On_Suspicious_Index
(Name
, High_Bound
(Drange
));
7182 ----------------------------
7183 -- Resolve_String_Literal --
7184 ----------------------------
7186 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
7187 C_Typ
: constant Entity_Id
:= Component_Type
(Typ
);
7188 R_Typ
: constant Entity_Id
:= Root_Type
(C_Typ
);
7189 Loc
: constant Source_Ptr
:= Sloc
(N
);
7190 Str
: constant String_Id
:= Strval
(N
);
7191 Strlen
: constant Nat
:= String_Length
(Str
);
7192 Subtype_Id
: Entity_Id
;
7193 Need_Check
: Boolean;
7196 -- For a string appearing in a concatenation, defer creation of the
7197 -- string_literal_subtype until the end of the resolution of the
7198 -- concatenation, because the literal may be constant-folded away. This
7199 -- is a useful optimization for long concatenation expressions.
7201 -- If the string is an aggregate built for a single character (which
7202 -- happens in a non-static context) or a is null string to which special
7203 -- checks may apply, we build the subtype. Wide strings must also get a
7204 -- string subtype if they come from a one character aggregate. Strings
7205 -- generated by attributes might be static, but it is often hard to
7206 -- determine whether the enclosing context is static, so we generate
7207 -- subtypes for them as well, thus losing some rarer optimizations ???
7208 -- Same for strings that come from a static conversion.
7211 (Strlen
= 0 and then Typ
/= Standard_String
)
7212 or else Nkind
(Parent
(N
)) /= N_Op_Concat
7213 or else (N
/= Left_Opnd
(Parent
(N
))
7214 and then N
/= Right_Opnd
(Parent
(N
)))
7215 or else ((Typ
= Standard_Wide_String
7216 or else Typ
= Standard_Wide_Wide_String
)
7217 and then Nkind
(Original_Node
(N
)) /= N_String_Literal
);
7219 -- If the resolving type is itself a string literal subtype, we
7220 -- can just reuse it, since there is no point in creating another.
7222 if Ekind
(Typ
) = E_String_Literal_Subtype
then
7225 elsif Nkind
(Parent
(N
)) = N_Op_Concat
7226 and then not Need_Check
7227 and then Nkind
(Original_Node
(N
)) /= N_Character_Literal
7228 and then Nkind
(Original_Node
(N
)) /= N_Attribute_Reference
7229 and then Nkind
(Original_Node
(N
)) /= N_Qualified_Expression
7230 and then Nkind
(Original_Node
(N
)) /= N_Type_Conversion
7234 -- Otherwise we must create a string literal subtype. Note that the
7235 -- whole idea of string literal subtypes is simply to avoid the need
7236 -- for building a full fledged array subtype for each literal.
7238 Set_String_Literal_Subtype
(N
, Typ
);
7239 Subtype_Id
:= Etype
(N
);
7242 if Nkind
(Parent
(N
)) /= N_Op_Concat
7245 Set_Etype
(N
, Subtype_Id
);
7246 Eval_String_Literal
(N
);
7249 if Is_Limited_Composite
(Typ
)
7250 or else Is_Private_Composite
(Typ
)
7252 Error_Msg_N
("string literal not available for private array", N
);
7253 Set_Etype
(N
, Any_Type
);
7257 -- The validity of a null string has been checked in the
7258 -- call to Eval_String_Literal.
7263 -- Always accept string literal with component type Any_Character, which
7264 -- occurs in error situations and in comparisons of literals, both of
7265 -- which should accept all literals.
7267 elsif R_Typ
= Any_Character
then
7270 -- If the type is bit-packed, then we always tranform the string literal
7271 -- into a full fledged aggregate.
7273 elsif Is_Bit_Packed_Array
(Typ
) then
7276 -- Deal with cases of Wide_Wide_String, Wide_String, and String
7279 -- For Standard.Wide_Wide_String, or any other type whose component
7280 -- type is Standard.Wide_Wide_Character, we know that all the
7281 -- characters in the string must be acceptable, since the parser
7282 -- accepted the characters as valid character literals.
7284 if R_Typ
= Standard_Wide_Wide_Character
then
7287 -- For the case of Standard.String, or any other type whose component
7288 -- type is Standard.Character, we must make sure that there are no
7289 -- wide characters in the string, i.e. that it is entirely composed
7290 -- of characters in range of type Character.
7292 -- If the string literal is the result of a static concatenation, the
7293 -- test has already been performed on the components, and need not be
7296 elsif R_Typ
= Standard_Character
7297 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
7299 for J
in 1 .. Strlen
loop
7300 if not In_Character_Range
(Get_String_Char
(Str
, J
)) then
7302 -- If we are out of range, post error. This is one of the
7303 -- very few places that we place the flag in the middle of
7304 -- a token, right under the offending wide character.
7307 ("literal out of range of type Standard.Character",
7308 Source_Ptr
(Int
(Loc
) + J
));
7313 -- For the case of Standard.Wide_String, or any other type whose
7314 -- component type is Standard.Wide_Character, we must make sure that
7315 -- there are no wide characters in the string, i.e. that it is
7316 -- entirely composed of characters in range of type Wide_Character.
7318 -- If the string literal is the result of a static concatenation,
7319 -- the test has already been performed on the components, and need
7322 elsif R_Typ
= Standard_Wide_Character
7323 and then Nkind
(Original_Node
(N
)) /= N_Op_Concat
7325 for J
in 1 .. Strlen
loop
7326 if not In_Wide_Character_Range
(Get_String_Char
(Str
, J
)) then
7328 -- If we are out of range, post error. This is one of the
7329 -- very few places that we place the flag in the middle of
7330 -- a token, right under the offending wide character.
7332 -- This is not quite right, because characters in general
7333 -- will take more than one character position ???
7336 ("literal out of range of type Standard.Wide_Character",
7337 Source_Ptr
(Int
(Loc
) + J
));
7342 -- If the root type is not a standard character, then we will convert
7343 -- the string into an aggregate and will let the aggregate code do
7344 -- the checking. Standard Wide_Wide_Character is also OK here.
7350 -- See if the component type of the array corresponding to the string
7351 -- has compile time known bounds. If yes we can directly check
7352 -- whether the evaluation of the string will raise constraint error.
7353 -- Otherwise we need to transform the string literal into the
7354 -- corresponding character aggregate and let the aggregate
7355 -- code do the checking.
7357 if R_Typ
= Standard_Character
7358 or else R_Typ
= Standard_Wide_Character
7359 or else R_Typ
= Standard_Wide_Wide_Character
7361 -- Check for the case of full range, where we are definitely OK
7363 if Component_Type
(Typ
) = Base_Type
(Component_Type
(Typ
)) then
7367 -- Here the range is not the complete base type range, so check
7370 Comp_Typ_Lo
: constant Node_Id
:=
7371 Type_Low_Bound
(Component_Type
(Typ
));
7372 Comp_Typ_Hi
: constant Node_Id
:=
7373 Type_High_Bound
(Component_Type
(Typ
));
7378 if Compile_Time_Known_Value
(Comp_Typ_Lo
)
7379 and then Compile_Time_Known_Value
(Comp_Typ_Hi
)
7381 for J
in 1 .. Strlen
loop
7382 Char_Val
:= UI_From_Int
(Int
(Get_String_Char
(Str
, J
)));
7384 if Char_Val
< Expr_Value
(Comp_Typ_Lo
)
7385 or else Char_Val
> Expr_Value
(Comp_Typ_Hi
)
7387 Apply_Compile_Time_Constraint_Error
7388 (N
, "character out of range?", CE_Range_Check_Failed
,
7389 Loc
=> Source_Ptr
(Int
(Loc
) + J
));
7399 -- If we got here we meed to transform the string literal into the
7400 -- equivalent qualified positional array aggregate. This is rather
7401 -- heavy artillery for this situation, but it is hard work to avoid.
7404 Lits
: constant List_Id
:= New_List
;
7405 P
: Source_Ptr
:= Loc
+ 1;
7409 -- Build the character literals, we give them source locations that
7410 -- correspond to the string positions, which is a bit tricky given
7411 -- the possible presence of wide character escape sequences.
7413 for J
in 1 .. Strlen
loop
7414 C
:= Get_String_Char
(Str
, J
);
7415 Set_Character_Literal_Name
(C
);
7418 Make_Character_Literal
(P
,
7420 Char_Literal_Value
=> UI_From_CC
(C
)));
7422 if In_Character_Range
(C
) then
7425 -- Should we have a call to Skip_Wide here ???
7433 Make_Qualified_Expression
(Loc
,
7434 Subtype_Mark
=> New_Reference_To
(Typ
, Loc
),
7436 Make_Aggregate
(Loc
, Expressions
=> Lits
)));
7438 Analyze_And_Resolve
(N
, Typ
);
7440 end Resolve_String_Literal
;
7442 -----------------------------
7443 -- Resolve_Subprogram_Info --
7444 -----------------------------
7446 procedure Resolve_Subprogram_Info
(N
: Node_Id
; Typ
: Entity_Id
) is
7449 end Resolve_Subprogram_Info
;
7451 -----------------------------
7452 -- Resolve_Type_Conversion --
7453 -----------------------------
7455 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
) is
7456 Conv_OK
: constant Boolean := Conversion_OK
(N
);
7457 Operand
: constant Node_Id
:= Expression
(N
);
7458 Operand_Typ
: constant Entity_Id
:= Etype
(Operand
);
7459 Target_Typ
: constant Entity_Id
:= Etype
(N
);
7466 and then not Valid_Conversion
(N
, Target_Typ
, Operand
)
7471 if Etype
(Operand
) = Any_Fixed
then
7473 -- Mixed-mode operation involving a literal. Context must be a fixed
7474 -- type which is applied to the literal subsequently.
7476 if Is_Fixed_Point_Type
(Typ
) then
7477 Set_Etype
(Operand
, Universal_Real
);
7479 elsif Is_Numeric_Type
(Typ
)
7480 and then (Nkind
(Operand
) = N_Op_Multiply
7481 or else Nkind
(Operand
) = N_Op_Divide
)
7482 and then (Etype
(Right_Opnd
(Operand
)) = Universal_Real
7483 or else Etype
(Left_Opnd
(Operand
)) = Universal_Real
)
7485 -- Return if expression is ambiguous
7487 if Unique_Fixed_Point_Type
(N
) = Any_Type
then
7490 -- If nothing else, the available fixed type is Duration
7493 Set_Etype
(Operand
, Standard_Duration
);
7496 -- Resolve the real operand with largest available precision
7498 if Etype
(Right_Opnd
(Operand
)) = Universal_Real
then
7499 Rop
:= New_Copy_Tree
(Right_Opnd
(Operand
));
7501 Rop
:= New_Copy_Tree
(Left_Opnd
(Operand
));
7504 Resolve
(Rop
, Universal_Real
);
7506 -- If the operand is a literal (it could be a non-static and
7507 -- illegal exponentiation) check whether the use of Duration
7508 -- is potentially inaccurate.
7510 if Nkind
(Rop
) = N_Real_Literal
7511 and then Realval
(Rop
) /= Ureal_0
7512 and then abs (Realval
(Rop
)) < Delta_Value
(Standard_Duration
)
7515 ("?universal real operand can only " &
7516 "be interpreted as Duration!",
7519 ("\?precision will be lost in the conversion!", Rop
);
7522 elsif Is_Numeric_Type
(Typ
)
7523 and then Nkind
(Operand
) in N_Op
7524 and then Unique_Fixed_Point_Type
(N
) /= Any_Type
7526 Set_Etype
(Operand
, Standard_Duration
);
7529 Error_Msg_N
("invalid context for mixed mode operation", N
);
7530 Set_Etype
(Operand
, Any_Type
);
7537 -- Note: we do the Eval_Type_Conversion call before applying the
7538 -- required checks for a subtype conversion. This is important,
7539 -- since both are prepared under certain circumstances to change
7540 -- the type conversion to a constraint error node, but in the case
7541 -- of Eval_Type_Conversion this may reflect an illegality in the
7542 -- static case, and we would miss the illegality (getting only a
7543 -- warning message), if we applied the type conversion checks first.
7545 Eval_Type_Conversion
(N
);
7547 -- Even when evaluation is not possible, we may be able to simplify
7548 -- the conversion or its expression. This needs to be done before
7549 -- applying checks, since otherwise the checks may use the original
7550 -- expression and defeat the simplifications. This is specifically
7551 -- the case for elimination of the floating-point Truncation
7552 -- attribute in float-to-int conversions.
7554 Simplify_Type_Conversion
(N
);
7556 -- If after evaluation we still have a type conversion, then we
7557 -- may need to apply checks required for a subtype conversion.
7559 -- Skip these type conversion checks if universal fixed operands
7560 -- operands involved, since range checks are handled separately for
7561 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
7563 if Nkind
(N
) = N_Type_Conversion
7564 and then not Is_Generic_Type
(Root_Type
(Target_Typ
))
7565 and then Target_Typ
/= Universal_Fixed
7566 and then Operand_Typ
/= Universal_Fixed
7568 Apply_Type_Conversion_Checks
(N
);
7571 -- Issue warning for conversion of simple object to its own type
7572 -- We have to test the original nodes, since they may have been
7573 -- rewritten by various optimizations.
7575 Orig_N
:= Original_Node
(N
);
7577 if Warn_On_Redundant_Constructs
7578 and then Comes_From_Source
(Orig_N
)
7579 and then Nkind
(Orig_N
) = N_Type_Conversion
7580 and then not In_Instance
7582 Orig_N
:= Original_Node
(Expression
(Orig_N
));
7583 Orig_T
:= Target_Typ
;
7585 -- If the node is part of a larger expression, the Target_Type
7586 -- may not be the original type of the node if the context is a
7587 -- condition. Recover original type to see if conversion is needed.
7589 if Is_Boolean_Type
(Orig_T
)
7590 and then Nkind
(Parent
(N
)) in N_Op
7592 Orig_T
:= Etype
(Parent
(N
));
7595 if Is_Entity_Name
(Orig_N
)
7597 (Etype
(Entity
(Orig_N
)) = Orig_T
7599 (Ekind
(Entity
(Orig_N
)) = E_Loop_Parameter
7600 and then Covers
(Orig_T
, Etype
(Entity
(Orig_N
)))))
7602 Error_Msg_Node_2
:= Orig_T
;
7604 ("?redundant conversion, & is of type &!", N
, Entity
(Orig_N
));
7608 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
7609 -- No need to perform any interface conversion if the type of the
7610 -- expression coincides with the target type.
7612 if Ada_Version
>= Ada_05
7613 and then Expander_Active
7614 and then Operand_Typ
/= Target_Typ
7617 Opnd
: Entity_Id
:= Operand_Typ
;
7618 Target
: Entity_Id
:= Target_Typ
;
7621 if Is_Access_Type
(Opnd
) then
7622 Opnd
:= Directly_Designated_Type
(Opnd
);
7625 if Is_Access_Type
(Target_Typ
) then
7626 Target
:= Directly_Designated_Type
(Target
);
7629 if Opnd
= Target
then
7632 -- Conversion from interface type
7634 elsif Is_Interface
(Opnd
) then
7636 -- Ada 2005 (AI-217): Handle entities from limited views
7638 if From_With_Type
(Opnd
) then
7639 Error_Msg_Qual_Level
:= 99;
7640 Error_Msg_NE
("missing with-clause on package &", N
,
7641 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Opnd
))));
7643 ("type conversions require visibility of the full view",
7646 elsif From_With_Type
(Target
)
7648 (Is_Access_Type
(Target_Typ
)
7649 and then Present
(Non_Limited_View
(Etype
(Target
))))
7651 Error_Msg_Qual_Level
:= 99;
7652 Error_Msg_NE
("missing with-clause on package &", N
,
7653 Cunit_Entity
(Get_Source_Unit
(Base_Type
(Target
))));
7655 ("type conversions require visibility of the full view",
7659 Expand_Interface_Conversion
(N
, Is_Static
=> False);
7662 -- Conversion to interface type
7664 elsif Is_Interface
(Target
) then
7668 if Ekind
(Opnd
) = E_Protected_Subtype
7669 or else Ekind
(Opnd
) = E_Task_Subtype
7671 Opnd
:= Etype
(Opnd
);
7674 if not Interface_Present_In_Ancestor
7678 if Is_Class_Wide_Type
(Opnd
) then
7680 -- The static analysis is not enough to know if the
7681 -- interface is implemented or not. Hence we must pass
7682 -- the work to the expander to generate code to evaluate
7683 -- the conversion at run-time.
7685 Expand_Interface_Conversion
(N
, Is_Static
=> False);
7688 Error_Msg_Name_1
:= Chars
(Etype
(Target
));
7689 Error_Msg_Name_2
:= Chars
(Opnd
);
7691 ("wrong interface conversion (% is not a progenitor " &
7696 Expand_Interface_Conversion
(N
);
7701 end Resolve_Type_Conversion
;
7703 ----------------------
7704 -- Resolve_Unary_Op --
7705 ----------------------
7707 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
) is
7708 B_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7709 R
: constant Node_Id
:= Right_Opnd
(N
);
7715 -- Deal with intrinsic unary operators
7717 if Comes_From_Source
(N
)
7718 and then Ekind
(Entity
(N
)) = E_Function
7719 and then Is_Imported
(Entity
(N
))
7720 and then Is_Intrinsic_Subprogram
(Entity
(N
))
7722 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
7726 -- Deal with universal cases
7728 if Etype
(R
) = Universal_Integer
7730 Etype
(R
) = Universal_Real
7732 Check_For_Visible_Operator
(N
, B_Typ
);
7735 Set_Etype
(N
, B_Typ
);
7738 -- Generate warning for expressions like abs (x mod 2)
7740 if Warn_On_Redundant_Constructs
7741 and then Nkind
(N
) = N_Op_Abs
7743 Determine_Range
(Right_Opnd
(N
), OK
, Lo
, Hi
);
7745 if OK
and then Hi
>= Lo
and then Lo
>= 0 then
7747 ("?abs applied to known non-negative value has no effect", N
);
7751 -- Deal with reference generation
7753 Check_Unset_Reference
(R
);
7754 Generate_Operator_Reference
(N
, B_Typ
);
7757 -- Set overflow checking bit. Much cleverer code needed here eventually
7758 -- and perhaps the Resolve routines should be separated for the various
7759 -- arithmetic operations, since they will need different processing ???
7761 if Nkind
(N
) in N_Op
then
7762 if not Overflow_Checks_Suppressed
(Etype
(N
)) then
7763 Enable_Overflow_Check
(N
);
7767 -- Generate warning for expressions like -5 mod 3 for integers. No
7768 -- need to worry in the floating-point case, since parens do not affect
7769 -- the result so there is no point in giving in a warning.
7772 Norig
: constant Node_Id
:= Original_Node
(N
);
7781 if Warn_On_Questionable_Missing_Parens
7782 and then Comes_From_Source
(Norig
)
7783 and then Is_Integer_Type
(Typ
)
7784 and then Nkind
(Norig
) = N_Op_Minus
7786 Rorig
:= Original_Node
(Right_Opnd
(Norig
));
7788 -- We are looking for cases where the right operand is not
7789 -- parenthesized, and is a bianry operator, multiply, divide, or
7790 -- mod. These are the cases where the grouping can affect results.
7792 if Paren_Count
(Rorig
) = 0
7793 and then (Nkind
(Rorig
) = N_Op_Mod
7795 Nkind
(Rorig
) = N_Op_Multiply
7797 Nkind
(Rorig
) = N_Op_Divide
)
7799 -- For mod, we always give the warning, since the value is
7800 -- affected by the parenthesization (e.g. (-5) mod 315 /=
7801 -- (5 mod 315)). But for the other cases, the only concern is
7802 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
7803 -- overflows, but (-2) * 64 does not). So we try to give the
7804 -- message only when overflow is possible.
7806 if Nkind
(Rorig
) /= N_Op_Mod
7807 and then Compile_Time_Known_Value
(R
)
7809 Val
:= Expr_Value
(R
);
7811 if Compile_Time_Known_Value
(Type_High_Bound
(Typ
)) then
7812 HB
:= Expr_Value
(Type_High_Bound
(Typ
));
7814 HB
:= Expr_Value
(Type_High_Bound
(Base_Type
(Typ
)));
7817 if Compile_Time_Known_Value
(Type_Low_Bound
(Typ
)) then
7818 LB
:= Expr_Value
(Type_Low_Bound
(Typ
));
7820 LB
:= Expr_Value
(Type_Low_Bound
(Base_Type
(Typ
)));
7823 -- Note that the test below is deliberately excluding
7824 -- the largest negative number, since that is a potentially
7825 -- troublesome case (e.g. -2 * x, where the result is the
7826 -- largest negative integer has an overflow with 2 * x).
7828 if Val
> LB
and then Val
<= HB
then
7833 -- For the multiplication case, the only case we have to worry
7834 -- about is when (-a)*b is exactly the largest negative number
7835 -- so that -(a*b) can cause overflow. This can only happen if
7836 -- a is a power of 2, and more generally if any operand is a
7837 -- constant that is not a power of 2, then the parentheses
7838 -- cannot affect whether overflow occurs. We only bother to
7839 -- test the left most operand
7841 -- Loop looking at left operands for one that has known value
7844 Opnd_Loop
: while Nkind
(Opnd
) = N_Op_Multiply
loop
7845 if Compile_Time_Known_Value
(Left_Opnd
(Opnd
)) then
7846 Lval
:= UI_Abs
(Expr_Value
(Left_Opnd
(Opnd
)));
7848 -- Operand value of 0 or 1 skips warning
7853 -- Otherwise check power of 2, if power of 2, warn, if
7854 -- anything else, skip warning.
7857 while Lval
/= 2 loop
7858 if Lval
mod 2 = 1 then
7869 -- Keep looking at left operands
7871 Opnd
:= Left_Opnd
(Opnd
);
7874 -- For rem or "/" we can only have a problematic situation
7875 -- if the divisor has a value of minus one or one. Otherwise
7876 -- overflow is impossible (divisor > 1) or we have a case of
7877 -- division by zero in any case.
7879 if (Nkind
(Rorig
) = N_Op_Divide
7881 Nkind
(Rorig
) = N_Op_Rem
)
7882 and then Compile_Time_Known_Value
(Right_Opnd
(Rorig
))
7883 and then UI_Abs
(Expr_Value
(Right_Opnd
(Rorig
))) /= 1
7888 -- If we fall through warning should be issued
7891 ("?unary minus expression should be parenthesized here!", N
);
7895 end Resolve_Unary_Op
;
7897 ----------------------------------
7898 -- Resolve_Unchecked_Expression --
7899 ----------------------------------
7901 procedure Resolve_Unchecked_Expression
7906 Resolve
(Expression
(N
), Typ
, Suppress
=> All_Checks
);
7908 end Resolve_Unchecked_Expression
;
7910 ---------------------------------------
7911 -- Resolve_Unchecked_Type_Conversion --
7912 ---------------------------------------
7914 procedure Resolve_Unchecked_Type_Conversion
7918 pragma Warnings
(Off
, Typ
);
7920 Operand
: constant Node_Id
:= Expression
(N
);
7921 Opnd_Type
: constant Entity_Id
:= Etype
(Operand
);
7924 -- Resolve operand using its own type
7926 Resolve
(Operand
, Opnd_Type
);
7927 Eval_Unchecked_Conversion
(N
);
7929 end Resolve_Unchecked_Type_Conversion
;
7931 ------------------------------
7932 -- Rewrite_Operator_As_Call --
7933 ------------------------------
7935 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
) is
7936 Loc
: constant Source_Ptr
:= Sloc
(N
);
7937 Actuals
: constant List_Id
:= New_List
;
7941 if Nkind
(N
) in N_Binary_Op
then
7942 Append
(Left_Opnd
(N
), Actuals
);
7945 Append
(Right_Opnd
(N
), Actuals
);
7948 Make_Function_Call
(Sloc
=> Loc
,
7949 Name
=> New_Occurrence_Of
(Nam
, Loc
),
7950 Parameter_Associations
=> Actuals
);
7952 Preserve_Comes_From_Source
(New_N
, N
);
7953 Preserve_Comes_From_Source
(Name
(New_N
), N
);
7955 Set_Etype
(N
, Etype
(Nam
));
7956 end Rewrite_Operator_As_Call
;
7958 ------------------------------
7959 -- Rewrite_Renamed_Operator --
7960 ------------------------------
7962 procedure Rewrite_Renamed_Operator
7967 Nam
: constant Name_Id
:= Chars
(Op
);
7968 Is_Binary
: constant Boolean := Nkind
(N
) in N_Binary_Op
;
7972 -- Rewrite the operator node using the real operator, not its
7973 -- renaming. Exclude user-defined intrinsic operations of the same
7974 -- name, which are treated separately and rewritten as calls.
7976 if Ekind
(Op
) /= E_Function
7977 or else Chars
(N
) /= Nam
7979 Op_Node
:= New_Node
(Operator_Kind
(Nam
, Is_Binary
), Sloc
(N
));
7980 Set_Chars
(Op_Node
, Nam
);
7981 Set_Etype
(Op_Node
, Etype
(N
));
7982 Set_Entity
(Op_Node
, Op
);
7983 Set_Right_Opnd
(Op_Node
, Right_Opnd
(N
));
7985 -- Indicate that both the original entity and its renaming are
7986 -- referenced at this point.
7988 Generate_Reference
(Entity
(N
), N
);
7989 Generate_Reference
(Op
, N
);
7992 Set_Left_Opnd
(Op_Node
, Left_Opnd
(N
));
7995 Rewrite
(N
, Op_Node
);
7997 -- If the context type is private, add the appropriate conversions
7998 -- so that the operator is applied to the full view. This is done
7999 -- in the routines that resolve intrinsic operators,
8001 if Is_Intrinsic_Subprogram
(Op
)
8002 and then Is_Private_Type
(Typ
)
8005 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
8006 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
8007 Resolve_Intrinsic_Operator
(N
, Typ
);
8009 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
8010 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
8017 elsif Ekind
(Op
) = E_Function
8018 and then Is_Intrinsic_Subprogram
(Op
)
8020 -- Operator renames a user-defined operator of the same name. Use
8021 -- the original operator in the node, which is the one that Gigi
8025 Set_Is_Overloaded
(N
, False);
8027 end Rewrite_Renamed_Operator
;
8029 -----------------------
8030 -- Set_Slice_Subtype --
8031 -----------------------
8033 -- Build an implicit subtype declaration to represent the type delivered
8034 -- by the slice. This is an abbreviated version of an array subtype. We
8035 -- define an index subtype for the slice, using either the subtype name
8036 -- or the discrete range of the slice. To be consistent with index usage
8037 -- elsewhere, we create a list header to hold the single index. This list
8038 -- is not otherwise attached to the syntax tree.
8040 procedure Set_Slice_Subtype
(N
: Node_Id
) is
8041 Loc
: constant Source_Ptr
:= Sloc
(N
);
8042 Index_List
: constant List_Id
:= New_List
;
8044 Index_Subtype
: Entity_Id
;
8045 Index_Type
: Entity_Id
;
8046 Slice_Subtype
: Entity_Id
;
8047 Drange
: constant Node_Id
:= Discrete_Range
(N
);
8050 if Is_Entity_Name
(Drange
) then
8051 Index_Subtype
:= Entity
(Drange
);
8054 -- We force the evaluation of a range. This is definitely needed in
8055 -- the renamed case, and seems safer to do unconditionally. Note in
8056 -- any case that since we will create and insert an Itype referring
8057 -- to this range, we must make sure any side effect removal actions
8058 -- are inserted before the Itype definition.
8060 if Nkind
(Drange
) = N_Range
then
8061 Force_Evaluation
(Low_Bound
(Drange
));
8062 Force_Evaluation
(High_Bound
(Drange
));
8065 Index_Type
:= Base_Type
(Etype
(Drange
));
8067 Index_Subtype
:= Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
8069 Set_Scalar_Range
(Index_Subtype
, Drange
);
8070 Set_Etype
(Index_Subtype
, Index_Type
);
8071 Set_Size_Info
(Index_Subtype
, Index_Type
);
8072 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
8075 Slice_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
8077 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
8078 Set_Etype
(Index
, Index_Subtype
);
8079 Append
(Index
, Index_List
);
8081 Set_First_Index
(Slice_Subtype
, Index
);
8082 Set_Etype
(Slice_Subtype
, Base_Type
(Etype
(N
)));
8083 Set_Is_Constrained
(Slice_Subtype
, True);
8084 Init_Size_Align
(Slice_Subtype
);
8086 Check_Compile_Time_Size
(Slice_Subtype
);
8088 -- The Etype of the existing Slice node is reset to this slice subtype.
8089 -- Its bounds are obtained from its first index.
8091 Set_Etype
(N
, Slice_Subtype
);
8093 -- In the packed case, this must be immediately frozen
8095 -- Couldn't we always freeze here??? and if we did, then the above
8096 -- call to Check_Compile_Time_Size could be eliminated, which would
8097 -- be nice, because then that routine could be made private to Freeze.
8099 if Is_Packed
(Slice_Subtype
) and not In_Default_Expression
then
8100 Freeze_Itype
(Slice_Subtype
, N
);
8103 end Set_Slice_Subtype
;
8105 --------------------------------
8106 -- Set_String_Literal_Subtype --
8107 --------------------------------
8109 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
) is
8110 Loc
: constant Source_Ptr
:= Sloc
(N
);
8111 Low_Bound
: constant Node_Id
:=
8112 Type_Low_Bound
(Etype
(First_Index
(Typ
)));
8113 Subtype_Id
: Entity_Id
;
8116 if Nkind
(N
) /= N_String_Literal
then
8120 Subtype_Id
:= Create_Itype
(E_String_Literal_Subtype
, N
);
8121 Set_String_Literal_Length
(Subtype_Id
, UI_From_Int
8122 (String_Length
(Strval
(N
))));
8123 Set_Etype
(Subtype_Id
, Base_Type
(Typ
));
8124 Set_Is_Constrained
(Subtype_Id
);
8125 Set_Etype
(N
, Subtype_Id
);
8127 if Is_OK_Static_Expression
(Low_Bound
) then
8129 -- The low bound is set from the low bound of the corresponding
8130 -- index type. Note that we do not store the high bound in the
8131 -- string literal subtype, but it can be deduced if necessary
8132 -- from the length and the low bound.
8134 Set_String_Literal_Low_Bound
(Subtype_Id
, Low_Bound
);
8137 Set_String_Literal_Low_Bound
8138 (Subtype_Id
, Make_Integer_Literal
(Loc
, 1));
8139 Set_Etype
(String_Literal_Low_Bound
(Subtype_Id
), Standard_Positive
);
8141 -- Build bona fide subtype for the string, and wrap it in an
8142 -- unchecked conversion, because the backend expects the
8143 -- String_Literal_Subtype to have a static lower bound.
8146 Index_List
: constant List_Id
:= New_List
;
8147 Index_Type
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
8148 High_Bound
: constant Node_Id
:=
8150 Left_Opnd
=> New_Copy_Tree
(Low_Bound
),
8152 Make_Integer_Literal
(Loc
,
8153 String_Length
(Strval
(N
)) - 1));
8154 Array_Subtype
: Entity_Id
;
8155 Index_Subtype
: Entity_Id
;
8161 Create_Itype
(Subtype_Kind
(Ekind
(Index_Type
)), N
);
8162 Drange
:= Make_Range
(Loc
, New_Copy_Tree
(Low_Bound
), High_Bound
);
8163 Set_Scalar_Range
(Index_Subtype
, Drange
);
8164 Set_Parent
(Drange
, N
);
8165 Analyze_And_Resolve
(Drange
, Index_Type
);
8167 Set_Etype
(Index_Subtype
, Index_Type
);
8168 Set_Size_Info
(Index_Subtype
, Index_Type
);
8169 Set_RM_Size
(Index_Subtype
, RM_Size
(Index_Type
));
8171 Array_Subtype
:= Create_Itype
(E_Array_Subtype
, N
);
8173 Index
:= New_Occurrence_Of
(Index_Subtype
, Loc
);
8174 Set_Etype
(Index
, Index_Subtype
);
8175 Append
(Index
, Index_List
);
8177 Set_First_Index
(Array_Subtype
, Index
);
8178 Set_Etype
(Array_Subtype
, Base_Type
(Typ
));
8179 Set_Is_Constrained
(Array_Subtype
, True);
8180 Init_Size_Align
(Array_Subtype
);
8183 Make_Unchecked_Type_Conversion
(Loc
,
8184 Subtype_Mark
=> New_Occurrence_Of
(Array_Subtype
, Loc
),
8185 Expression
=> Relocate_Node
(N
)));
8186 Set_Etype
(N
, Array_Subtype
);
8189 end Set_String_Literal_Subtype
;
8191 ------------------------------
8192 -- Simplify_Type_Conversion --
8193 ------------------------------
8195 procedure Simplify_Type_Conversion
(N
: Node_Id
) is
8197 if Nkind
(N
) = N_Type_Conversion
then
8199 Operand
: constant Node_Id
:= Expression
(N
);
8200 Target_Typ
: constant Entity_Id
:= Etype
(N
);
8201 Opnd_Typ
: constant Entity_Id
:= Etype
(Operand
);
8204 if Is_Floating_Point_Type
(Opnd_Typ
)
8206 (Is_Integer_Type
(Target_Typ
)
8207 or else (Is_Fixed_Point_Type
(Target_Typ
)
8208 and then Conversion_OK
(N
)))
8209 and then Nkind
(Operand
) = N_Attribute_Reference
8210 and then Attribute_Name
(Operand
) = Name_Truncation
8212 -- Special processing required if the conversion is the expression
8213 -- of a Truncation attribute reference. In this case we replace:
8215 -- ityp (ftyp'Truncation (x))
8221 -- with the Float_Truncate flag set, which is more efficient
8225 Relocate_Node
(First
(Expressions
(Operand
))));
8226 Set_Float_Truncate
(N
, True);
8230 end Simplify_Type_Conversion
;
8232 -----------------------------
8233 -- Unique_Fixed_Point_Type --
8234 -----------------------------
8236 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
is
8237 T1
: Entity_Id
:= Empty
;
8242 procedure Fixed_Point_Error
;
8243 -- If true ambiguity, give details
8245 -----------------------
8246 -- Fixed_Point_Error --
8247 -----------------------
8249 procedure Fixed_Point_Error
is
8251 Error_Msg_N
("ambiguous universal_fixed_expression", N
);
8252 Error_Msg_NE
("\\possible interpretation as}", N
, T1
);
8253 Error_Msg_NE
("\\possible interpretation as}", N
, T2
);
8254 end Fixed_Point_Error
;
8256 -- Start of processing for Unique_Fixed_Point_Type
8259 -- The operations on Duration are visible, so Duration is always a
8260 -- possible interpretation.
8262 T1
:= Standard_Duration
;
8264 -- Look for fixed-point types in enclosing scopes
8266 Scop
:= Current_Scope
;
8267 while Scop
/= Standard_Standard
loop
8268 T2
:= First_Entity
(Scop
);
8269 while Present
(T2
) loop
8270 if Is_Fixed_Point_Type
(T2
)
8271 and then Current_Entity
(T2
) = T2
8272 and then Scope
(Base_Type
(T2
)) = Scop
8274 if Present
(T1
) then
8285 Scop
:= Scope
(Scop
);
8288 -- Look for visible fixed type declarations in the context
8290 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
8291 while Present
(Item
) loop
8292 if Nkind
(Item
) = N_With_Clause
then
8293 Scop
:= Entity
(Name
(Item
));
8294 T2
:= First_Entity
(Scop
);
8295 while Present
(T2
) loop
8296 if Is_Fixed_Point_Type
(T2
)
8297 and then Scope
(Base_Type
(T2
)) = Scop
8298 and then (Is_Potentially_Use_Visible
(T2
)
8299 or else In_Use
(T2
))
8301 if Present
(T1
) then
8316 if Nkind
(N
) = N_Real_Literal
then
8317 Error_Msg_NE
("?real literal interpreted as }!", N
, T1
);
8320 Error_Msg_NE
("?universal_fixed expression interpreted as }!", N
, T1
);
8324 end Unique_Fixed_Point_Type
;
8326 ----------------------
8327 -- Valid_Conversion --
8328 ----------------------
8330 function Valid_Conversion
8333 Operand
: Node_Id
) return Boolean
8335 Target_Type
: constant Entity_Id
:= Base_Type
(Target
);
8336 Opnd_Type
: Entity_Id
:= Etype
(Operand
);
8338 function Conversion_Check
8340 Msg
: String) return Boolean;
8341 -- Little routine to post Msg if Valid is False, returns Valid value
8343 function Valid_Tagged_Conversion
8344 (Target_Type
: Entity_Id
;
8345 Opnd_Type
: Entity_Id
) return Boolean;
8346 -- Specifically test for validity of tagged conversions
8348 function Valid_Array_Conversion
return Boolean;
8349 -- Check index and component conformance, and accessibility levels
8350 -- if the component types are anonymous access types (Ada 2005)
8352 ----------------------
8353 -- Conversion_Check --
8354 ----------------------
8356 function Conversion_Check
8358 Msg
: String) return Boolean
8362 Error_Msg_N
(Msg
, Operand
);
8366 end Conversion_Check
;
8368 ----------------------------
8369 -- Valid_Array_Conversion --
8370 ----------------------------
8372 function Valid_Array_Conversion
return Boolean
8374 Opnd_Comp_Type
: constant Entity_Id
:= Component_Type
(Opnd_Type
);
8375 Opnd_Comp_Base
: constant Entity_Id
:= Base_Type
(Opnd_Comp_Type
);
8377 Opnd_Index
: Node_Id
;
8378 Opnd_Index_Type
: Entity_Id
;
8380 Target_Comp_Type
: constant Entity_Id
:=
8381 Component_Type
(Target_Type
);
8382 Target_Comp_Base
: constant Entity_Id
:=
8383 Base_Type
(Target_Comp_Type
);
8385 Target_Index
: Node_Id
;
8386 Target_Index_Type
: Entity_Id
;
8389 -- Error if wrong number of dimensions
8392 Number_Dimensions
(Target_Type
) /= Number_Dimensions
(Opnd_Type
)
8395 ("incompatible number of dimensions for conversion", Operand
);
8398 -- Number of dimensions matches
8401 -- Loop through indexes of the two arrays
8403 Target_Index
:= First_Index
(Target_Type
);
8404 Opnd_Index
:= First_Index
(Opnd_Type
);
8405 while Present
(Target_Index
) and then Present
(Opnd_Index
) loop
8406 Target_Index_Type
:= Etype
(Target_Index
);
8407 Opnd_Index_Type
:= Etype
(Opnd_Index
);
8409 -- Error if index types are incompatible
8411 if not (Is_Integer_Type
(Target_Index_Type
)
8412 and then Is_Integer_Type
(Opnd_Index_Type
))
8413 and then (Root_Type
(Target_Index_Type
)
8414 /= Root_Type
(Opnd_Index_Type
))
8417 ("incompatible index types for array conversion",
8422 Next_Index
(Target_Index
);
8423 Next_Index
(Opnd_Index
);
8426 -- If component types have same base type, all set
8428 if Target_Comp_Base
= Opnd_Comp_Base
then
8431 -- Here if base types of components are not the same. The only
8432 -- time this is allowed is if we have anonymous access types.
8434 -- The conversion of arrays of anonymous access types can lead
8435 -- to dangling pointers. AI-392 formalizes the accessibility
8436 -- checks that must be applied to such conversions to prevent
8437 -- out-of-scope references.
8440 (Ekind
(Target_Comp_Base
) = E_Anonymous_Access_Type
8442 Ekind
(Target_Comp_Base
) = E_Anonymous_Access_Subprogram_Type
)
8443 and then Ekind
(Opnd_Comp_Base
) = Ekind
(Target_Comp_Base
)
8445 Subtypes_Statically_Match
(Target_Comp_Type
, Opnd_Comp_Type
)
8447 if Type_Access_Level
(Target_Type
) <
8448 Type_Access_Level
(Opnd_Type
)
8450 if In_Instance_Body
then
8451 Error_Msg_N
("?source array type " &
8452 "has deeper accessibility level than target", Operand
);
8453 Error_Msg_N
("\?Program_Error will be raised at run time",
8456 Make_Raise_Program_Error
(Sloc
(N
),
8457 Reason
=> PE_Accessibility_Check_Failed
));
8458 Set_Etype
(N
, Target_Type
);
8461 -- Conversion not allowed because of accessibility levels
8464 Error_Msg_N
("source array type " &
8465 "has deeper accessibility level than target", Operand
);
8472 -- All other cases where component base types do not match
8476 ("incompatible component types for array conversion",
8481 -- Check that component subtypes statically match
8483 if Is_Constrained
(Target_Comp_Type
) /=
8484 Is_Constrained
(Opnd_Comp_Type
)
8485 or else not Subtypes_Statically_Match
8486 (Target_Comp_Type
, Opnd_Comp_Type
)
8489 ("component subtypes must statically match", Operand
);
8495 end Valid_Array_Conversion
;
8497 -----------------------------
8498 -- Valid_Tagged_Conversion --
8499 -----------------------------
8501 function Valid_Tagged_Conversion
8502 (Target_Type
: Entity_Id
;
8503 Opnd_Type
: Entity_Id
) return Boolean
8506 -- Upward conversions are allowed (RM 4.6(22))
8508 if Covers
(Target_Type
, Opnd_Type
)
8509 or else Is_Ancestor
(Target_Type
, Opnd_Type
)
8513 -- Downward conversion are allowed if the operand is class-wide
8516 elsif Is_Class_Wide_Type
(Opnd_Type
)
8517 and then Covers
(Opnd_Type
, Target_Type
)
8521 elsif Covers
(Opnd_Type
, Target_Type
)
8522 or else Is_Ancestor
(Opnd_Type
, Target_Type
)
8525 Conversion_Check
(False,
8526 "downward conversion of tagged objects not allowed");
8528 -- Ada 2005 (AI-251): The conversion to/from interface types is
8531 elsif Is_Interface
(Target_Type
) or else Is_Interface
(Opnd_Type
) then
8534 -- If the operand is a class-wide type obtained through a limited_
8535 -- with clause, and the context includes the non-limited view, use
8536 -- it to determine whether the conversion is legal.
8538 elsif Is_Class_Wide_Type
(Opnd_Type
)
8539 and then From_With_Type
(Opnd_Type
)
8540 and then Present
(Non_Limited_View
(Etype
(Opnd_Type
)))
8541 and then Is_Interface
(Non_Limited_View
(Etype
(Opnd_Type
)))
8545 elsif Is_Access_Type
(Opnd_Type
)
8546 and then Is_Interface
(Directly_Designated_Type
(Opnd_Type
))
8552 ("invalid tagged conversion, not compatible with}",
8553 N
, First_Subtype
(Opnd_Type
));
8556 end Valid_Tagged_Conversion
;
8558 -- Start of processing for Valid_Conversion
8561 Check_Parameterless_Call
(Operand
);
8563 if Is_Overloaded
(Operand
) then
8572 -- Remove procedure calls, which syntactically cannot appear
8573 -- in this context, but which cannot be removed by type checking,
8574 -- because the context does not impose a type.
8576 -- When compiling for VMS, spurious ambiguities can be produced
8577 -- when arithmetic operations have a literal operand and return
8578 -- System.Address or a descendant of it. These ambiguities are
8579 -- otherwise resolved by the context, but for conversions there
8580 -- is no context type and the removal of the spurious operations
8581 -- must be done explicitly here.
8583 -- The node may be labelled overloaded, but still contain only
8584 -- one interpretation because others were discarded in previous
8585 -- filters. If this is the case, retain the single interpretation
8588 Get_First_Interp
(Operand
, I
, It
);
8589 Opnd_Type
:= It
.Typ
;
8590 Get_Next_Interp
(I
, It
);
8593 and then Opnd_Type
/= Standard_Void_Type
8595 -- More than one candidate interpretation is available
8597 Get_First_Interp
(Operand
, I
, It
);
8598 while Present
(It
.Typ
) loop
8599 if It
.Typ
= Standard_Void_Type
then
8603 if Present
(System_Aux_Id
)
8604 and then Is_Descendent_Of_Address
(It
.Typ
)
8609 Get_Next_Interp
(I
, It
);
8613 Get_First_Interp
(Operand
, I
, It
);
8618 Error_Msg_N
("illegal operand in conversion", Operand
);
8622 Get_Next_Interp
(I
, It
);
8624 if Present
(It
.Typ
) then
8626 It1
:= Disambiguate
(Operand
, I1
, I
, Any_Type
);
8628 if It1
= No_Interp
then
8629 Error_Msg_N
("ambiguous operand in conversion", Operand
);
8631 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
8632 Error_Msg_N
("\\possible interpretation#!", Operand
);
8634 Error_Msg_Sloc
:= Sloc
(N1
);
8635 Error_Msg_N
("\\possible interpretation#!", Operand
);
8641 Set_Etype
(Operand
, It1
.Typ
);
8642 Opnd_Type
:= It1
.Typ
;
8648 if Is_Numeric_Type
(Target_Type
) then
8650 -- A universal fixed expression can be converted to any numeric type
8652 if Opnd_Type
= Universal_Fixed
then
8655 -- Also no need to check when in an instance or inlined body, because
8656 -- the legality has been established when the template was analyzed.
8657 -- Furthermore, numeric conversions may occur where only a private
8658 -- view of the operand type is visible at the instanciation point.
8659 -- This results in a spurious error if we check that the operand type
8660 -- is a numeric type.
8662 -- Note: in a previous version of this unit, the following tests were
8663 -- applied only for generated code (Comes_From_Source set to False),
8664 -- but in fact the test is required for source code as well, since
8665 -- this situation can arise in source code.
8667 elsif In_Instance
or else In_Inlined_Body
then
8670 -- Otherwise we need the conversion check
8673 return Conversion_Check
8674 (Is_Numeric_Type
(Opnd_Type
),
8675 "illegal operand for numeric conversion");
8680 elsif Is_Array_Type
(Target_Type
) then
8681 if not Is_Array_Type
(Opnd_Type
)
8682 or else Opnd_Type
= Any_Composite
8683 or else Opnd_Type
= Any_String
8686 ("illegal operand for array conversion", Operand
);
8689 return Valid_Array_Conversion
;
8692 -- Ada 2005 (AI-251): Anonymous access types where target references an
8695 elsif (Ekind
(Target_Type
) = E_General_Access_Type
8697 Ekind
(Target_Type
) = E_Anonymous_Access_Type
)
8698 and then Is_Interface
(Directly_Designated_Type
(Target_Type
))
8700 -- Check the static accessibility rule of 4.6(17). Note that the
8701 -- check is not enforced when within an instance body, since the RM
8702 -- requires such cases to be caught at run time.
8704 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
then
8705 if Type_Access_Level
(Opnd_Type
) >
8706 Type_Access_Level
(Target_Type
)
8708 -- In an instance, this is a run-time check, but one we know
8709 -- will fail, so generate an appropriate warning. The raise
8710 -- will be generated by Expand_N_Type_Conversion.
8712 if In_Instance_Body
then
8714 ("?cannot convert local pointer to non-local access type",
8717 ("\?Program_Error will be raised at run time", Operand
);
8720 ("cannot convert local pointer to non-local access type",
8725 -- Special accessibility checks are needed in the case of access
8726 -- discriminants declared for a limited type.
8728 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
8729 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
8731 -- When the operand is a selected access discriminant the check
8732 -- needs to be made against the level of the object denoted by
8733 -- the prefix of the selected name. (Object_Access_Level
8734 -- handles checking the prefix of the operand for this case.)
8736 if Nkind
(Operand
) = N_Selected_Component
8737 and then Object_Access_Level
(Operand
) >
8738 Type_Access_Level
(Target_Type
)
8740 -- In an instance, this is a run-time check, but one we
8741 -- know will fail, so generate an appropriate warning.
8742 -- The raise will be generated by Expand_N_Type_Conversion.
8744 if In_Instance_Body
then
8746 ("?cannot convert access discriminant to non-local" &
8747 " access type", Operand
);
8749 ("\?Program_Error will be raised at run time", Operand
);
8752 ("cannot convert access discriminant to non-local" &
8753 " access type", Operand
);
8758 -- The case of a reference to an access discriminant from
8759 -- within a limited type declaration (which will appear as
8760 -- a discriminal) is always illegal because the level of the
8761 -- discriminant is considered to be deeper than any (namable)
8764 if Is_Entity_Name
(Operand
)
8765 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
8766 and then (Ekind
(Entity
(Operand
)) = E_In_Parameter
8767 or else Ekind
(Entity
(Operand
)) = E_Constant
)
8768 and then Present
(Discriminal_Link
(Entity
(Operand
)))
8771 ("discriminant has deeper accessibility level than target",
8780 -- General and anonymous access types
8782 elsif (Ekind
(Target_Type
) = E_General_Access_Type
8783 or else Ekind
(Target_Type
) = E_Anonymous_Access_Type
)
8786 (Is_Access_Type
(Opnd_Type
)
8787 and then Ekind
(Opnd_Type
) /=
8788 E_Access_Subprogram_Type
8789 and then Ekind
(Opnd_Type
) /=
8790 E_Access_Protected_Subprogram_Type
,
8791 "must be an access-to-object type")
8793 if Is_Access_Constant
(Opnd_Type
)
8794 and then not Is_Access_Constant
(Target_Type
)
8797 ("access-to-constant operand type not allowed", Operand
);
8801 -- Check the static accessibility rule of 4.6(17). Note that the
8802 -- check is not enforced when within an instance body, since the RM
8803 -- requires such cases to be caught at run time.
8805 if Ekind
(Target_Type
) /= E_Anonymous_Access_Type
8806 or else Is_Local_Anonymous_Access
(Target_Type
)
8808 if Type_Access_Level
(Opnd_Type
)
8809 > Type_Access_Level
(Target_Type
)
8811 -- In an instance, this is a run-time check, but one we
8812 -- know will fail, so generate an appropriate warning.
8813 -- The raise will be generated by Expand_N_Type_Conversion.
8815 if In_Instance_Body
then
8817 ("?cannot convert local pointer to non-local access type",
8820 ("\?Program_Error will be raised at run time", Operand
);
8823 -- Avoid generation of spurious error message
8825 if not Error_Posted
(N
) then
8827 ("cannot convert local pointer to non-local access type",
8834 -- Special accessibility checks are needed in the case of access
8835 -- discriminants declared for a limited type.
8837 elsif Ekind
(Opnd_Type
) = E_Anonymous_Access_Type
8838 and then not Is_Local_Anonymous_Access
(Opnd_Type
)
8841 -- When the operand is a selected access discriminant the check
8842 -- needs to be made against the level of the object denoted by
8843 -- the prefix of the selected name. (Object_Access_Level
8844 -- handles checking the prefix of the operand for this case.)
8846 if Nkind
(Operand
) = N_Selected_Component
8847 and then Object_Access_Level
(Operand
)
8848 > Type_Access_Level
(Target_Type
)
8850 -- In an instance, this is a run-time check, but one we
8851 -- know will fail, so generate an appropriate warning.
8852 -- The raise will be generated by Expand_N_Type_Conversion.
8854 if In_Instance_Body
then
8856 ("?cannot convert access discriminant to non-local" &
8857 " access type", Operand
);
8859 ("\?Program_Error will be raised at run time",
8864 ("cannot convert access discriminant to non-local" &
8865 " access type", Operand
);
8870 -- The case of a reference to an access discriminant from
8871 -- within a limited type declaration (which will appear as
8872 -- a discriminal) is always illegal because the level of the
8873 -- discriminant is considered to be deeper than any (namable)
8876 if Is_Entity_Name
(Operand
)
8877 and then (Ekind
(Entity
(Operand
)) = E_In_Parameter
8878 or else Ekind
(Entity
(Operand
)) = E_Constant
)
8879 and then Present
(Discriminal_Link
(Entity
(Operand
)))
8882 ("discriminant has deeper accessibility level than target",
8890 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
;
8891 -- Helper function to handle limited views
8893 --------------------------
8894 -- Full_Designated_Type --
8895 --------------------------
8897 function Full_Designated_Type
(T
: Entity_Id
) return Entity_Id
is
8898 Desig
: constant Entity_Id
:= Designated_Type
(T
);
8900 if From_With_Type
(Desig
)
8901 and then Is_Incomplete_Type
(Desig
)
8902 and then Present
(Non_Limited_View
(Desig
))
8904 return Non_Limited_View
(Desig
);
8908 end Full_Designated_Type
;
8910 Target
: constant Entity_Id
:= Full_Designated_Type
(Target_Type
);
8911 Opnd
: constant Entity_Id
:= Full_Designated_Type
(Opnd_Type
);
8913 Same_Base
: constant Boolean :=
8914 Base_Type
(Target
) = Base_Type
(Opnd
);
8917 if Is_Tagged_Type
(Target
) then
8918 return Valid_Tagged_Conversion
(Target
, Opnd
);
8921 if not Same_Base
then
8923 ("target designated type not compatible with }",
8924 N
, Base_Type
(Opnd
));
8927 -- Ada 2005 AI-384: legality rule is symmetric in both
8928 -- designated types. The conversion is legal (with possible
8929 -- constraint check) if either designated type is
8932 elsif Subtypes_Statically_Match
(Target
, Opnd
)
8934 (Has_Discriminants
(Target
)
8936 (not Is_Constrained
(Opnd
)
8937 or else not Is_Constrained
(Target
)))
8943 ("target designated subtype not compatible with }",
8950 -- Subprogram access types
8952 elsif (Ekind
(Target_Type
) = E_Access_Subprogram_Type
8954 Ekind
(Target_Type
) = E_Anonymous_Access_Subprogram_Type
)
8955 and then No
(Corresponding_Remote_Type
(Opnd_Type
))
8958 Ekind
(Base_Type
(Opnd_Type
)) = E_Anonymous_Access_Subprogram_Type
8961 ("illegal attempt to store anonymous access to subprogram",
8964 ("\value has deeper accessibility than any master " &
8968 if Is_Entity_Name
(Operand
)
8969 and then Ekind
(Entity
(Operand
)) = E_In_Parameter
8972 ("\use named access type for& instead of access parameter",
8973 Operand
, Entity
(Operand
));
8977 -- Check that the designated types are subtype conformant
8979 Check_Subtype_Conformant
(New_Id
=> Designated_Type
(Target_Type
),
8980 Old_Id
=> Designated_Type
(Opnd_Type
),
8983 -- Check the static accessibility rule of 4.6(20)
8985 if Type_Access_Level
(Opnd_Type
) >
8986 Type_Access_Level
(Target_Type
)
8989 ("operand type has deeper accessibility level than target",
8992 -- Check that if the operand type is declared in a generic body,
8993 -- then the target type must be declared within that same body
8994 -- (enforces last sentence of 4.6(20)).
8996 elsif Present
(Enclosing_Generic_Body
(Opnd_Type
)) then
8998 O_Gen
: constant Node_Id
:=
8999 Enclosing_Generic_Body
(Opnd_Type
);
9004 T_Gen
:= Enclosing_Generic_Body
(Target_Type
);
9005 while Present
(T_Gen
) and then T_Gen
/= O_Gen
loop
9006 T_Gen
:= Enclosing_Generic_Body
(T_Gen
);
9009 if T_Gen
/= O_Gen
then
9011 ("target type must be declared in same generic body"
9012 & " as operand type", N
);
9019 -- Remote subprogram access types
9021 elsif Is_Remote_Access_To_Subprogram_Type
(Target_Type
)
9022 and then Is_Remote_Access_To_Subprogram_Type
(Opnd_Type
)
9024 -- It is valid to convert from one RAS type to another provided
9025 -- that their specification statically match.
9027 Check_Subtype_Conformant
9029 Designated_Type
(Corresponding_Remote_Type
(Target_Type
)),
9031 Designated_Type
(Corresponding_Remote_Type
(Opnd_Type
)),
9036 -- If both are tagged types, check legality of view conversions
9038 elsif Is_Tagged_Type
(Target_Type
)
9039 and then Is_Tagged_Type
(Opnd_Type
)
9041 return Valid_Tagged_Conversion
(Target_Type
, Opnd_Type
);
9043 -- Types derived from the same root type are convertible
9045 elsif Root_Type
(Target_Type
) = Root_Type
(Opnd_Type
) then
9048 -- In an instance or an inlined body, there may be inconsistent
9049 -- views of the same type, or of types derived from a common root.
9051 elsif (In_Instance
or In_Inlined_Body
)
9053 Root_Type
(Underlying_Type
(Target_Type
)) =
9054 Root_Type
(Underlying_Type
(Opnd_Type
))
9058 -- Special check for common access type error case
9060 elsif Ekind
(Target_Type
) = E_Access_Type
9061 and then Is_Access_Type
(Opnd_Type
)
9063 Error_Msg_N
("target type must be general access type!", N
);
9064 Error_Msg_NE
("add ALL to }!", N
, Target_Type
);
9069 Error_Msg_NE
("invalid conversion, not compatible with }",
9074 end Valid_Conversion
;