1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Debug_A
; use Debug_A
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
33 with Expander
; use Expander
;
34 with Exp_Ch7
; use Exp_Ch7
;
35 with Exp_Tss
; use Exp_Tss
;
36 with Exp_Util
; use Exp_Util
;
37 with Freeze
; use Freeze
;
38 with Itypes
; use Itypes
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
; use Namet
;
42 with Nmake
; use Nmake
;
43 with Nlists
; use Nlists
;
45 with Output
; use Output
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Aggr
; use Sem_Aggr
;
51 with Sem_Attr
; use Sem_Attr
;
52 with Sem_Cat
; use Sem_Cat
;
53 with Sem_Ch4
; use Sem_Ch4
;
54 with Sem_Ch6
; use Sem_Ch6
;
55 with Sem_Ch8
; use Sem_Ch8
;
56 with Sem_Disp
; use Sem_Disp
;
57 with Sem_Dist
; use Sem_Dist
;
58 with Sem_Elab
; use Sem_Elab
;
59 with Sem_Eval
; use Sem_Eval
;
60 with Sem_Intr
; use Sem_Intr
;
61 with Sem_Util
; use Sem_Util
;
62 with Sem_Type
; use Sem_Type
;
63 with Sem_Warn
; use Sem_Warn
;
64 with Sinfo
; use Sinfo
;
65 with Snames
; use Snames
;
66 with Stand
; use Stand
;
67 with Stringt
; use Stringt
;
68 with Targparm
; use Targparm
;
69 with Tbuild
; use Tbuild
;
70 with Uintp
; use Uintp
;
71 with Urealp
; use Urealp
;
73 package body Sem_Res
is
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 -- Second pass (top-down) type checking and overload resolution procedures
80 -- Typ is the type required by context. These procedures propagate the
81 -- type information recursively to the descendants of N. If the node
82 -- is not overloaded, its Etype is established in the first pass. If
83 -- overloaded, the Resolve routines set the correct type. For arith.
84 -- operators, the Etype is the base type of the context.
86 -- Note that Resolve_Attribute is separated off in Sem_Attr
88 procedure Ambiguous_Character
(C
: Node_Id
);
89 -- Give list of candidate interpretations when a character literal cannot
92 procedure Check_Direct_Boolean_Op
(N
: Node_Id
);
93 -- N is a binary operator node which may possibly operate on Boolean
94 -- operands. If the operator does have Boolean operands, then a call is
95 -- made to check the restriction No_Direct_Boolean_Operators.
97 procedure Check_Discriminant_Use
(N
: Node_Id
);
98 -- Enforce the restrictions on the use of discriminants when constraining
99 -- a component of a discriminated type (record or concurrent type).
101 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
);
102 -- Given a node for an operator associated with type T, check that
103 -- the operator is visible. Operators all of whose operands are
104 -- universal must be checked for visibility during resolution
105 -- because their type is not determinable based on their operands.
107 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean;
108 -- Given a call node, N, which is known to occur immediately within the
109 -- subprogram being called, determines whether it is a detectable case of
110 -- an infinite recursion, and if so, outputs appropriate messages. Returns
111 -- True if an infinite recursion is detected, and False otherwise.
113 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
);
114 -- If the type of the object being initialized uses the secondary stack
115 -- directly or indirectly, create a transient scope for the call to the
116 -- init proc. This is because we do not create transient scopes for the
117 -- initialization of individual components within the init proc itself.
118 -- Could be optimized away perhaps?
120 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean;
121 -- Utility to check whether the name in the call is a predefined
122 -- operator, in which case the call is made into an operator node.
123 -- An instance of an intrinsic conversion operation may be given
124 -- an operator name, but is not treated like an operator.
126 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
);
127 -- If a default expression in entry call N depends on the discriminants
128 -- of the task, it must be replaced with a reference to the discriminant
129 -- of the task being called.
131 procedure Resolve_Allocator
(N
: Node_Id
; Typ
: Entity_Id
);
132 procedure Resolve_Arithmetic_Op
(N
: Node_Id
; Typ
: Entity_Id
);
133 procedure Resolve_Call
(N
: Node_Id
; Typ
: Entity_Id
);
134 procedure Resolve_Character_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
135 procedure Resolve_Comparison_Op
(N
: Node_Id
; Typ
: Entity_Id
);
136 procedure Resolve_Conditional_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
137 procedure Resolve_Equality_Op
(N
: Node_Id
; Typ
: Entity_Id
);
138 procedure Resolve_Explicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
);
139 procedure Resolve_Entity_Name
(N
: Node_Id
; Typ
: Entity_Id
);
140 procedure Resolve_Indexed_Component
(N
: Node_Id
; Typ
: Entity_Id
);
141 procedure Resolve_Integer_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
142 procedure Resolve_Logical_Op
(N
: Node_Id
; Typ
: Entity_Id
);
143 procedure Resolve_Membership_Op
(N
: Node_Id
; Typ
: Entity_Id
);
144 procedure Resolve_Null
(N
: Node_Id
; Typ
: Entity_Id
);
145 procedure Resolve_Operator_Symbol
(N
: Node_Id
; Typ
: Entity_Id
);
146 procedure Resolve_Op_Concat
(N
: Node_Id
; Typ
: Entity_Id
);
147 procedure Resolve_Op_Expon
(N
: Node_Id
; Typ
: Entity_Id
);
148 procedure Resolve_Op_Not
(N
: Node_Id
; Typ
: Entity_Id
);
149 procedure Resolve_Qualified_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
150 procedure Resolve_Range
(N
: Node_Id
; Typ
: Entity_Id
);
151 procedure Resolve_Real_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
152 procedure Resolve_Reference
(N
: Node_Id
; Typ
: Entity_Id
);
153 procedure Resolve_Selected_Component
(N
: Node_Id
; Typ
: Entity_Id
);
154 procedure Resolve_Shift
(N
: Node_Id
; Typ
: Entity_Id
);
155 procedure Resolve_Short_Circuit
(N
: Node_Id
; Typ
: Entity_Id
);
156 procedure Resolve_Slice
(N
: Node_Id
; Typ
: Entity_Id
);
157 procedure Resolve_String_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
158 procedure Resolve_Subprogram_Info
(N
: Node_Id
; Typ
: Entity_Id
);
159 procedure Resolve_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
160 procedure Resolve_Unary_Op
(N
: Node_Id
; Typ
: Entity_Id
);
161 procedure Resolve_Unchecked_Expression
(N
: Node_Id
; Typ
: Entity_Id
);
162 procedure Resolve_Unchecked_Type_Conversion
(N
: Node_Id
; Typ
: Entity_Id
);
164 function Operator_Kind
166 Is_Binary
: Boolean) return Node_Kind
;
167 -- Utility to map the name of an operator into the corresponding Node. Used
168 -- by other node rewriting procedures.
170 procedure Resolve_Actuals
(N
: Node_Id
; Nam
: Entity_Id
);
171 -- Resolve actuals of call, and add default expressions for missing ones.
172 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
173 -- called subprogram.
175 procedure Resolve_Entry_Call
(N
: Node_Id
; Typ
: Entity_Id
);
176 -- Called from Resolve_Call, when the prefix denotes an entry or element
177 -- of entry family. Actuals are resolved as for subprograms, and the node
178 -- is rebuilt as an entry call. Also called for protected operations. Typ
179 -- is the context type, which is used when the operation is a protected
180 -- function with no arguments, and the return value is indexed.
182 procedure Resolve_Intrinsic_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
183 -- A call to a user-defined intrinsic operator is rewritten as a call
184 -- to the corresponding predefined operator, with suitable conversions.
186 procedure Resolve_Intrinsic_Unary_Operator
(N
: Node_Id
; Typ
: Entity_Id
);
187 -- Ditto, for unary operators (only arithmetic ones)
189 procedure Rewrite_Operator_As_Call
(N
: Node_Id
; Nam
: Entity_Id
);
190 -- If an operator node resolves to a call to a user-defined operator,
191 -- rewrite the node as a function call.
193 procedure Make_Call_Into_Operator
197 -- Inverse transformation: if an operator is given in functional notation,
198 -- then after resolving the node, transform into an operator node, so
199 -- that operands are resolved properly. Recall that predefined operators
200 -- do not have a full signature and special resolution rules apply.
202 procedure Rewrite_Renamed_Operator
206 -- An operator can rename another, e.g. in an instantiation. In that
207 -- case, the proper operator node must be constructed and resolved.
209 procedure Set_String_Literal_Subtype
(N
: Node_Id
; Typ
: Entity_Id
);
210 -- The String_Literal_Subtype is built for all strings that are not
211 -- operands of a static concatenation operation. If the argument is
212 -- not a N_String_Literal node, then the call has no effect.
214 procedure Set_Slice_Subtype
(N
: Node_Id
);
215 -- Build subtype of array type, with the range specified by the slice
217 function Unique_Fixed_Point_Type
(N
: Node_Id
) return Entity_Id
;
218 -- A universal_fixed expression in an universal context is unambiguous
219 -- if there is only one applicable fixed point type. Determining whether
220 -- there is only one requires a search over all visible entities, and
221 -- happens only in very pathological cases (see 6115-006).
223 function Valid_Conversion
226 Operand
: Node_Id
) return Boolean;
227 -- Verify legality rules given in 4.6 (8-23). Target is the target
228 -- type of the conversion, which may be an implicit conversion of
229 -- an actual parameter to an anonymous access type (in which case
230 -- N denotes the actual parameter and N = Operand).
232 -------------------------
233 -- Ambiguous_Character --
234 -------------------------
236 procedure Ambiguous_Character
(C
: Node_Id
) is
240 if Nkind
(C
) = N_Character_Literal
then
241 Error_Msg_N
("ambiguous character literal", C
);
243 ("\possible interpretations: Character, Wide_Character!", C
);
245 E
:= Current_Entity
(C
);
249 while Present
(E
) loop
250 Error_Msg_NE
("\possible interpretation:}!", C
, Etype
(E
));
255 end Ambiguous_Character
;
257 -------------------------
258 -- Analyze_And_Resolve --
259 -------------------------
261 procedure Analyze_And_Resolve
(N
: Node_Id
) is
265 end Analyze_And_Resolve
;
267 procedure Analyze_And_Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
271 end Analyze_And_Resolve
;
273 -- Version withs check(s) suppressed
275 procedure Analyze_And_Resolve
280 Scop
: constant Entity_Id
:= Current_Scope
;
283 if Suppress
= All_Checks
then
285 Svg
: constant Suppress_Array
:= Scope_Suppress
;
288 Scope_Suppress
:= (others => True);
289 Analyze_And_Resolve
(N
, Typ
);
290 Scope_Suppress
:= Svg
;
295 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
298 Scope_Suppress
(Suppress
) := True;
299 Analyze_And_Resolve
(N
, Typ
);
300 Scope_Suppress
(Suppress
) := Svg
;
304 if Current_Scope
/= Scop
305 and then Scope_Is_Transient
307 -- This can only happen if a transient scope was created
308 -- for an inner expression, which will be removed upon
309 -- completion of the analysis of an enclosing construct.
310 -- The transient scope must have the suppress status of
311 -- the enclosing environment, not of this Analyze call.
313 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
316 end Analyze_And_Resolve
;
318 procedure Analyze_And_Resolve
322 Scop
: constant Entity_Id
:= Current_Scope
;
325 if Suppress
= All_Checks
then
327 Svg
: constant Suppress_Array
:= Scope_Suppress
;
330 Scope_Suppress
:= (others => True);
331 Analyze_And_Resolve
(N
);
332 Scope_Suppress
:= Svg
;
337 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
340 Scope_Suppress
(Suppress
) := True;
341 Analyze_And_Resolve
(N
);
342 Scope_Suppress
(Suppress
) := Svg
;
346 if Current_Scope
/= Scop
347 and then Scope_Is_Transient
349 Scope_Stack
.Table
(Scope_Stack
.Last
).Save_Scope_Suppress
:=
352 end Analyze_And_Resolve
;
354 -----------------------------
355 -- Check_Direct_Boolean_Op --
356 -----------------------------
358 procedure Check_Direct_Boolean_Op
(N
: Node_Id
) is
360 if Root_Type
(Etype
(Left_Opnd
(N
))) = Standard_Boolean
then
361 Check_Restriction
(No_Direct_Boolean_Operators
, N
);
363 end Check_Direct_Boolean_Op
;
365 ----------------------------
366 -- Check_Discriminant_Use --
367 ----------------------------
369 procedure Check_Discriminant_Use
(N
: Node_Id
) is
370 PN
: constant Node_Id
:= Parent
(N
);
371 Disc
: constant Entity_Id
:= Entity
(N
);
376 -- Any use in a default expression is legal
378 if In_Default_Expression
then
381 elsif Nkind
(PN
) = N_Range
then
383 -- Discriminant cannot be used to constrain a scalar type
387 if Nkind
(P
) = N_Range_Constraint
388 and then Nkind
(Parent
(P
)) = N_Subtype_Indication
389 and then Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
391 Error_Msg_N
("discriminant cannot constrain scalar type", N
);
393 elsif Nkind
(P
) = N_Index_Or_Discriminant_Constraint
then
395 -- The following check catches the unusual case where
396 -- a discriminant appears within an index constraint
397 -- that is part of a larger expression within a constraint
398 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
399 -- For now we only check case of record components, and
400 -- note that a similar check should also apply in the
401 -- case of discriminant constraints below. ???
403 -- Note that the check for N_Subtype_Declaration below is to
404 -- detect the valid use of discriminants in the constraints of a
405 -- subtype declaration when this subtype declaration appears
406 -- inside the scope of a record type (which is syntactically
407 -- illegal, but which may be created as part of derived type
408 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
411 if Ekind
(Current_Scope
) = E_Record_Type
412 and then Scope
(Disc
) = Current_Scope
414 (Nkind
(Parent
(P
)) = N_Subtype_Indication
416 (Nkind
(Parent
(Parent
(P
))) = N_Component_Definition
418 Nkind
(Parent
(Parent
(P
))) = N_Subtype_Declaration
)
419 and then Paren_Count
(N
) = 0)
422 ("discriminant must appear alone in component constraint", N
);
426 -- Detect a common beginner error:
428 -- type R (D : Positive := 100) is record
429 -- Name : String (1 .. D);
432 -- The default value causes an object of type R to be
433 -- allocated with room for Positive'Last characters.
441 function Large_Storage_Type
(T
: Entity_Id
) return Boolean;
442 -- Return True if type T has a large enough range that
443 -- any array whose index type covered the whole range of
444 -- the type would likely raise Storage_Error.
446 ------------------------
447 -- Large_Storage_Type --
448 ------------------------
450 function Large_Storage_Type
(T
: Entity_Id
) return Boolean is
455 T
= Standard_Positive
457 T
= Standard_Natural
;
458 end Large_Storage_Type
;
461 -- Check that the Disc has a large range
463 if not Large_Storage_Type
(Etype
(Disc
)) then
467 -- If the enclosing type is limited, we allocate only the
468 -- default value, not the maximum, and there is no need for
471 if Is_Limited_Type
(Scope
(Disc
)) then
475 -- Check that it is the high bound
477 if N
/= High_Bound
(PN
)
478 or else not Present
(Discriminant_Default_Value
(Disc
))
483 -- Check the array allows a large range at this bound.
484 -- First find the array
488 if Nkind
(SI
) /= N_Subtype_Indication
then
492 T
:= Entity
(Subtype_Mark
(SI
));
494 if not Is_Array_Type
(T
) then
498 -- Next, find the dimension
500 TB
:= First_Index
(T
);
501 CB
:= First
(Constraints
(P
));
503 and then Present
(TB
)
504 and then Present
(CB
)
515 -- Now, check the dimension has a large range
517 if not Large_Storage_Type
(Etype
(TB
)) then
521 -- Warn about the danger
524 ("creation of & object may raise Storage_Error?",
533 -- Legal case is in index or discriminant constraint
535 elsif Nkind
(PN
) = N_Index_Or_Discriminant_Constraint
536 or else Nkind
(PN
) = N_Discriminant_Association
538 if Paren_Count
(N
) > 0 then
540 ("discriminant in constraint must appear alone", N
);
545 -- Otherwise, context is an expression. It should not be within
546 -- (i.e. a subexpression of) a constraint for a component.
552 while Nkind
(P
) /= N_Component_Declaration
553 and then Nkind
(P
) /= N_Subtype_Indication
554 and then Nkind
(P
) /= N_Entry_Declaration
561 -- If the discriminant is used in an expression that is a bound
562 -- of a scalar type, an Itype is created and the bounds are attached
563 -- to its range, not to the original subtype indication. Such use
564 -- is of course a double fault.
566 if (Nkind
(P
) = N_Subtype_Indication
568 (Nkind
(Parent
(P
)) = N_Component_Definition
570 Nkind
(Parent
(P
)) = N_Derived_Type_Definition
)
571 and then D
= Constraint
(P
))
573 -- The constraint itself may be given by a subtype indication,
574 -- rather than by a more common discrete range.
576 or else (Nkind
(P
) = N_Subtype_Indication
578 Nkind
(Parent
(P
)) = N_Index_Or_Discriminant_Constraint
)
579 or else Nkind
(P
) = N_Entry_Declaration
580 or else Nkind
(D
) = N_Defining_Identifier
583 ("discriminant in constraint must appear alone", N
);
586 end Check_Discriminant_Use
;
588 --------------------------------
589 -- Check_For_Visible_Operator --
590 --------------------------------
592 procedure Check_For_Visible_Operator
(N
: Node_Id
; T
: Entity_Id
) is
594 if Is_Invisible_Operator
(N
, T
) then
596 ("operator for} is not directly visible!", N
, First_Subtype
(T
));
597 Error_Msg_N
("use clause would make operation legal!", N
);
599 end Check_For_Visible_Operator
;
601 ------------------------------
602 -- Check_Infinite_Recursion --
603 ------------------------------
605 function Check_Infinite_Recursion
(N
: Node_Id
) return Boolean is
609 function Same_Argument_List
return Boolean;
610 -- Check whether list of actuals is identical to list of formals
611 -- of called function (which is also the enclosing scope).
613 ------------------------
614 -- Same_Argument_List --
615 ------------------------
617 function Same_Argument_List
return Boolean is
623 if not Is_Entity_Name
(Name
(N
)) then
626 Subp
:= Entity
(Name
(N
));
629 F
:= First_Formal
(Subp
);
630 A
:= First_Actual
(N
);
631 while Present
(F
) and then Present
(A
) loop
632 if not Is_Entity_Name
(A
)
633 or else Entity
(A
) /= F
643 end Same_Argument_List
;
645 -- Start of processing for Check_Infinite_Recursion
648 -- Loop moving up tree, quitting if something tells us we are
649 -- definitely not in an infinite recursion situation.
654 exit when Nkind
(P
) = N_Subprogram_Body
;
656 if Nkind
(P
) = N_Or_Else
or else
657 Nkind
(P
) = N_And_Then
or else
658 Nkind
(P
) = N_If_Statement
or else
659 Nkind
(P
) = N_Case_Statement
663 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
664 and then C
/= First
(Statements
(P
))
666 -- If the call is the expression of a return statement and
667 -- the actuals are identical to the formals, it's worth a
668 -- warning. However, we skip this if there is an immediately
669 -- preceding raise statement, since the call is never executed.
671 -- Furthermore, this corresponds to a common idiom:
673 -- function F (L : Thing) return Boolean is
675 -- raise Program_Error;
679 -- for generating a stub function
681 if Nkind
(Parent
(N
)) = N_Return_Statement
682 and then Same_Argument_List
684 exit when not Is_List_Member
(Parent
(N
))
685 or else (Nkind
(Prev
(Parent
(N
))) /= N_Raise_Statement
687 (Nkind
(Prev
(Parent
(N
))) not in N_Raise_xxx_Error
689 Present
(Condition
(Prev
(Parent
(N
))))));
699 Error_Msg_N
("possible infinite recursion?", N
);
700 Error_Msg_N
("\Storage_Error may be raised at run time?", N
);
703 end Check_Infinite_Recursion
;
705 -------------------------------
706 -- Check_Initialization_Call --
707 -------------------------------
709 procedure Check_Initialization_Call
(N
: Entity_Id
; Nam
: Entity_Id
) is
710 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Nam
));
712 function Uses_SS
(T
: Entity_Id
) return Boolean;
713 -- Check whether the creation of an object of the type will involve
714 -- use of the secondary stack. If T is a record type, this is true
715 -- if the expression for some component uses the secondary stack, eg.
716 -- through a call to a function that returns an unconstrained value.
717 -- False if T is controlled, because cleanups occur elsewhere.
723 function Uses_SS
(T
: Entity_Id
) return Boolean is
728 if Is_Controlled
(T
) then
731 elsif Is_Array_Type
(T
) then
732 return Uses_SS
(Component_Type
(T
));
734 elsif Is_Record_Type
(T
) then
735 Comp
:= First_Component
(T
);
737 while Present
(Comp
) loop
739 if Ekind
(Comp
) = E_Component
740 and then Nkind
(Parent
(Comp
)) = N_Component_Declaration
742 Expr
:= Expression
(Parent
(Comp
));
744 -- The expression for a dynamic component may be
745 -- rewritten as a dereference. Retrieve original
748 if Nkind
(Original_Node
(Expr
)) = N_Function_Call
749 and then Requires_Transient_Scope
(Etype
(Expr
))
753 elsif Uses_SS
(Etype
(Comp
)) then
758 Next_Component
(Comp
);
768 -- Start of processing for Check_Initialization_Call
771 -- Nothing to do if functions do not use the secondary stack for
772 -- returns (i.e. they use a depressed stack pointer instead).
774 if Functions_Return_By_DSP_On_Target
then
777 -- Otherwise establish a transient scope if the type needs it
779 elsif Uses_SS
(Typ
) then
780 Establish_Transient_Scope
(First_Actual
(N
), Sec_Stack
=> True);
782 end Check_Initialization_Call
;
784 ------------------------------
785 -- Check_Parameterless_Call --
786 ------------------------------
788 procedure Check_Parameterless_Call
(N
: Node_Id
) is
791 function Prefix_Is_Access_Subp
return Boolean;
792 -- If the prefix is of an access_to_subprogram type, the node must be
793 -- rewritten as a call. Ditto if the prefix is overloaded and all its
794 -- interpretations are access to subprograms.
796 ---------------------------
797 -- Prefix_Is_Access_Subp --
798 ---------------------------
800 function Prefix_Is_Access_Subp
return Boolean is
805 if not Is_Overloaded
(N
) then
807 Ekind
(Etype
(N
)) = E_Subprogram_Type
808 and then Base_Type
(Etype
(Etype
(N
))) /= Standard_Void_Type
;
810 Get_First_Interp
(N
, I
, It
);
811 while Present
(It
.Typ
) loop
812 if Ekind
(It
.Typ
) /= E_Subprogram_Type
813 or else Base_Type
(Etype
(It
.Typ
)) = Standard_Void_Type
818 Get_Next_Interp
(I
, It
);
823 end Prefix_Is_Access_Subp
;
825 -- Start of processing for Check_Parameterless_Call
828 -- Defend against junk stuff if errors already detected
830 if Total_Errors_Detected
/= 0 then
831 if Nkind
(N
) in N_Has_Etype
and then Etype
(N
) = Any_Type
then
833 elsif Nkind
(N
) in N_Has_Chars
834 and then Chars
(N
) in Error_Name_Or_No_Name
842 -- If the context expects a value, and the name is a procedure,
843 -- this is most likely a missing 'Access. Do not try to resolve
844 -- the parameterless call, error will be caught when the outer
847 if Is_Entity_Name
(N
)
848 and then Ekind
(Entity
(N
)) = E_Procedure
849 and then not Is_Overloaded
(N
)
851 (Nkind
(Parent
(N
)) = N_Parameter_Association
852 or else Nkind
(Parent
(N
)) = N_Function_Call
853 or else Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
)
858 -- Rewrite as call if overloadable entity that is (or could be, in
859 -- the overloaded case) a function call. If we know for sure that
860 -- the entity is an enumeration literal, we do not rewrite it.
862 if (Is_Entity_Name
(N
)
863 and then Is_Overloadable
(Entity
(N
))
864 and then (Ekind
(Entity
(N
)) /= E_Enumeration_Literal
865 or else Is_Overloaded
(N
)))
867 -- Rewrite as call if it is an explicit deference of an expression of
868 -- a subprogram access type, and the suprogram type is not that of a
869 -- procedure or entry.
872 (Nkind
(N
) = N_Explicit_Dereference
and then Prefix_Is_Access_Subp
)
874 -- Rewrite as call if it is a selected component which is a function,
875 -- this is the case of a call to a protected function (which may be
876 -- overloaded with other protected operations).
879 (Nkind
(N
) = N_Selected_Component
880 and then (Ekind
(Entity
(Selector_Name
(N
))) = E_Function
882 ((Ekind
(Entity
(Selector_Name
(N
))) = E_Entry
884 Ekind
(Entity
(Selector_Name
(N
))) = E_Procedure
)
885 and then Is_Overloaded
(Selector_Name
(N
)))))
887 -- If one of the above three conditions is met, rewrite as call.
888 -- Apply the rewriting only once.
891 if Nkind
(Parent
(N
)) /= N_Function_Call
892 or else N
/= Name
(Parent
(N
))
896 -- If overloaded, overload set belongs to new copy
898 Save_Interps
(N
, Nam
);
900 -- Change node to parameterless function call (note that the
901 -- Parameter_Associations associations field is left set to Empty,
902 -- its normal default value since there are no parameters)
904 Change_Node
(N
, N_Function_Call
);
906 Set_Sloc
(N
, Sloc
(Nam
));
910 elsif Nkind
(N
) = N_Parameter_Association
then
911 Check_Parameterless_Call
(Explicit_Actual_Parameter
(N
));
913 end Check_Parameterless_Call
;
915 ----------------------
916 -- Is_Predefined_Op --
917 ----------------------
919 function Is_Predefined_Op
(Nam
: Entity_Id
) return Boolean is
921 return Is_Intrinsic_Subprogram
(Nam
)
922 and then not Is_Generic_Instance
(Nam
)
923 and then Chars
(Nam
) in Any_Operator_Name
924 and then (No
(Alias
(Nam
))
925 or else Is_Predefined_Op
(Alias
(Nam
)));
926 end Is_Predefined_Op
;
928 -----------------------------
929 -- Make_Call_Into_Operator --
930 -----------------------------
932 procedure Make_Call_Into_Operator
937 Op_Name
: constant Name_Id
:= Chars
(Op_Id
);
938 Act1
: Node_Id
:= First_Actual
(N
);
939 Act2
: Node_Id
:= Next_Actual
(Act1
);
940 Error
: Boolean := False;
941 Func
: constant Entity_Id
:= Entity
(Name
(N
));
942 Is_Binary
: constant Boolean := Present
(Act2
);
944 Opnd_Type
: Entity_Id
;
945 Orig_Type
: Entity_Id
:= Empty
;
948 type Kind_Test
is access function (E
: Entity_Id
) return Boolean;
950 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean;
951 -- Determine whether E is an access type declared by an access decla-
952 -- ration, and not an (anonymous) allocator type.
954 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean;
955 -- If the operand is not universal, and the operator is given by a
956 -- expanded name, verify that the operand has an interpretation with
957 -- a type defined in the given scope of the operator.
959 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
;
960 -- Find a type of the given class in the package Pack that contains
963 -----------------------------
964 -- Is_Definite_Access_Type --
965 -----------------------------
967 function Is_Definite_Access_Type
(E
: Entity_Id
) return Boolean is
968 Btyp
: constant Entity_Id
:= Base_Type
(E
);
970 return Ekind
(Btyp
) = E_Access_Type
971 or else (Ekind
(Btyp
) = E_Access_Subprogram_Type
972 and then Comes_From_Source
(Btyp
));
973 end Is_Definite_Access_Type
;
975 ---------------------------
976 -- Operand_Type_In_Scope --
977 ---------------------------
979 function Operand_Type_In_Scope
(S
: Entity_Id
) return Boolean is
980 Nod
: constant Node_Id
:= Right_Opnd
(Op_Node
);
985 if not Is_Overloaded
(Nod
) then
986 return Scope
(Base_Type
(Etype
(Nod
))) = S
;
989 Get_First_Interp
(Nod
, I
, It
);
991 while Present
(It
.Typ
) loop
993 if Scope
(Base_Type
(It
.Typ
)) = S
then
997 Get_Next_Interp
(I
, It
);
1002 end Operand_Type_In_Scope
;
1008 function Type_In_P
(Test
: Kind_Test
) return Entity_Id
is
1011 function In_Decl
return Boolean;
1012 -- Verify that node is not part of the type declaration for the
1013 -- candidate type, which would otherwise be invisible.
1019 function In_Decl
return Boolean is
1020 Decl_Node
: constant Node_Id
:= Parent
(E
);
1026 if Etype
(E
) = Any_Type
then
1029 elsif No
(Decl_Node
) then
1034 and then Nkind
(N2
) /= N_Compilation_Unit
1036 if N2
= Decl_Node
then
1047 -- Start of processing for Type_In_P
1050 -- If the context type is declared in the prefix package, this
1051 -- is the desired base type.
1053 if Scope
(Base_Type
(Typ
)) = Pack
1056 return Base_Type
(Typ
);
1059 E
:= First_Entity
(Pack
);
1061 while Present
(E
) loop
1064 and then not In_Decl
1076 -- Start of processing for Make_Call_Into_Operator
1079 Op_Node
:= New_Node
(Operator_Kind
(Op_Name
, Is_Binary
), Sloc
(N
));
1084 Set_Left_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1085 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act2
));
1086 Save_Interps
(Act1
, Left_Opnd
(Op_Node
));
1087 Save_Interps
(Act2
, Right_Opnd
(Op_Node
));
1088 Act1
:= Left_Opnd
(Op_Node
);
1089 Act2
:= Right_Opnd
(Op_Node
);
1094 Set_Right_Opnd
(Op_Node
, Relocate_Node
(Act1
));
1095 Save_Interps
(Act1
, Right_Opnd
(Op_Node
));
1096 Act1
:= Right_Opnd
(Op_Node
);
1099 -- If the operator is denoted by an expanded name, and the prefix is
1100 -- not Standard, but the operator is a predefined one whose scope is
1101 -- Standard, then this is an implicit_operator, inserted as an
1102 -- interpretation by the procedure of the same name. This procedure
1103 -- overestimates the presence of implicit operators, because it does
1104 -- not examine the type of the operands. Verify now that the operand
1105 -- type appears in the given scope. If right operand is universal,
1106 -- check the other operand. In the case of concatenation, either
1107 -- argument can be the component type, so check the type of the result.
1108 -- If both arguments are literals, look for a type of the right kind
1109 -- defined in the given scope. This elaborate nonsense is brought to
1110 -- you courtesy of b33302a. The type itself must be frozen, so we must
1111 -- find the type of the proper class in the given scope.
1113 -- A final wrinkle is the multiplication operator for fixed point
1114 -- types, which is defined in Standard only, and not in the scope of
1115 -- the fixed_point type itself.
1117 if Nkind
(Name
(N
)) = N_Expanded_Name
then
1118 Pack
:= Entity
(Prefix
(Name
(N
)));
1120 -- If the entity being called is defined in the given package,
1121 -- it is a renaming of a predefined operator, and known to be
1124 if Scope
(Entity
(Name
(N
))) = Pack
1125 and then Pack
/= Standard_Standard
1129 elsif (Op_Name
= Name_Op_Multiply
1130 or else Op_Name
= Name_Op_Divide
)
1131 and then Is_Fixed_Point_Type
(Etype
(Left_Opnd
(Op_Node
)))
1132 and then Is_Fixed_Point_Type
(Etype
(Right_Opnd
(Op_Node
)))
1134 if Pack
/= Standard_Standard
then
1139 Opnd_Type
:= Base_Type
(Etype
(Right_Opnd
(Op_Node
)));
1141 if Op_Name
= Name_Op_Concat
then
1142 Opnd_Type
:= Base_Type
(Typ
);
1144 elsif (Scope
(Opnd_Type
) = Standard_Standard
1146 or else (Nkind
(Right_Opnd
(Op_Node
)) = N_Attribute_Reference
1148 and then not Comes_From_Source
(Opnd_Type
))
1150 Opnd_Type
:= Base_Type
(Etype
(Left_Opnd
(Op_Node
)));
1153 if Scope
(Opnd_Type
) = Standard_Standard
then
1155 -- Verify that the scope contains a type that corresponds to
1156 -- the given literal. Optimize the case where Pack is Standard.
1158 if Pack
/= Standard_Standard
then
1160 if Opnd_Type
= Universal_Integer
then
1161 Orig_Type
:= Type_In_P
(Is_Integer_Type
'Access);
1163 elsif Opnd_Type
= Universal_Real
then
1164 Orig_Type
:= Type_In_P
(Is_Real_Type
'Access);
1166 elsif Opnd_Type
= Any_String
then
1167 Orig_Type
:= Type_In_P
(Is_String_Type
'Access);
1169 elsif Opnd_Type
= Any_Access
then
1170 Orig_Type
:= Type_In_P
(Is_Definite_Access_Type
'Access);
1172 elsif Opnd_Type
= Any_Composite
then
1173 Orig_Type
:= Type_In_P
(Is_Composite_Type
'Access);
1175 if Present
(Orig_Type
) then
1176 if Has_Private_Component
(Orig_Type
) then
1179 Set_Etype
(Act1
, Orig_Type
);
1182 Set_Etype
(Act2
, Orig_Type
);
1191 Error
:= No
(Orig_Type
);
1194 elsif Ekind
(Opnd_Type
) = E_Allocator_Type
1195 and then No
(Type_In_P
(Is_Definite_Access_Type
'Access))
1199 -- If the type is defined elsewhere, and the operator is not
1200 -- defined in the given scope (by a renaming declaration, e.g.)
1201 -- then this is an error as well. If an extension of System is
1202 -- present, and the type may be defined there, Pack must be
1205 elsif Scope
(Opnd_Type
) /= Pack
1206 and then Scope
(Op_Id
) /= Pack
1207 and then (No
(System_Aux_Id
)
1208 or else Scope
(Opnd_Type
) /= System_Aux_Id
1209 or else Pack
/= Scope
(System_Aux_Id
))
1211 if not Is_Overloaded
(Right_Opnd
(Op_Node
)) then
1214 Error
:= not Operand_Type_In_Scope
(Pack
);
1217 elsif Pack
= Standard_Standard
1218 and then not Operand_Type_In_Scope
(Standard_Standard
)
1225 Error_Msg_Node_2
:= Pack
;
1227 ("& not declared in&", N
, Selector_Name
(Name
(N
)));
1228 Set_Etype
(N
, Any_Type
);
1233 Set_Chars
(Op_Node
, Op_Name
);
1235 if not Is_Private_Type
(Etype
(N
)) then
1236 Set_Etype
(Op_Node
, Base_Type
(Etype
(N
)));
1238 Set_Etype
(Op_Node
, Etype
(N
));
1241 -- If this is a call to a function that renames a predefined equality,
1242 -- the renaming declaration provides a type that must be used to
1243 -- resolve the operands. This must be done now because resolution of
1244 -- the equality node will not resolve any remaining ambiguity, and it
1245 -- assumes that the first operand is not overloaded.
1247 if (Op_Name
= Name_Op_Eq
or else Op_Name
= Name_Op_Ne
)
1248 and then Ekind
(Func
) = E_Function
1249 and then Is_Overloaded
(Act1
)
1251 Resolve
(Act1
, Base_Type
(Etype
(First_Formal
(Func
))));
1252 Resolve
(Act2
, Base_Type
(Etype
(First_Formal
(Func
))));
1255 Set_Entity
(Op_Node
, Op_Id
);
1256 Generate_Reference
(Op_Id
, N
, ' ');
1257 Rewrite
(N
, Op_Node
);
1259 -- If this is an arithmetic operator and the result type is private,
1260 -- the operands and the result must be wrapped in conversion to
1261 -- expose the underlying numeric type and expand the proper checks,
1262 -- e.g. on division.
1264 if Is_Private_Type
(Typ
) then
1266 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1267 N_Op_Expon | N_Op_Mod | N_Op_Rem
=>
1268 Resolve_Intrinsic_Operator
(N
, Typ
);
1270 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
1271 Resolve_Intrinsic_Unary_Operator
(N
, Typ
);
1280 -- For predefined operators on literals, the operation freezes
1283 if Present
(Orig_Type
) then
1284 Set_Etype
(Act1
, Orig_Type
);
1285 Freeze_Expression
(Act1
);
1287 end Make_Call_Into_Operator
;
1293 function Operator_Kind
1295 Is_Binary
: Boolean) return Node_Kind
1301 if Op_Name
= Name_Op_And
then Kind
:= N_Op_And
;
1302 elsif Op_Name
= Name_Op_Or
then Kind
:= N_Op_Or
;
1303 elsif Op_Name
= Name_Op_Xor
then Kind
:= N_Op_Xor
;
1304 elsif Op_Name
= Name_Op_Eq
then Kind
:= N_Op_Eq
;
1305 elsif Op_Name
= Name_Op_Ne
then Kind
:= N_Op_Ne
;
1306 elsif Op_Name
= Name_Op_Lt
then Kind
:= N_Op_Lt
;
1307 elsif Op_Name
= Name_Op_Le
then Kind
:= N_Op_Le
;
1308 elsif Op_Name
= Name_Op_Gt
then Kind
:= N_Op_Gt
;
1309 elsif Op_Name
= Name_Op_Ge
then Kind
:= N_Op_Ge
;
1310 elsif Op_Name
= Name_Op_Add
then Kind
:= N_Op_Add
;
1311 elsif Op_Name
= Name_Op_Subtract
then Kind
:= N_Op_Subtract
;
1312 elsif Op_Name
= Name_Op_Concat
then Kind
:= N_Op_Concat
;
1313 elsif Op_Name
= Name_Op_Multiply
then Kind
:= N_Op_Multiply
;
1314 elsif Op_Name
= Name_Op_Divide
then Kind
:= N_Op_Divide
;
1315 elsif Op_Name
= Name_Op_Mod
then Kind
:= N_Op_Mod
;
1316 elsif Op_Name
= Name_Op_Rem
then Kind
:= N_Op_Rem
;
1317 elsif Op_Name
= Name_Op_Expon
then Kind
:= N_Op_Expon
;
1319 raise Program_Error
;
1325 if Op_Name
= Name_Op_Add
then Kind
:= N_Op_Plus
;
1326 elsif Op_Name
= Name_Op_Subtract
then Kind
:= N_Op_Minus
;
1327 elsif Op_Name
= Name_Op_Abs
then Kind
:= N_Op_Abs
;
1328 elsif Op_Name
= Name_Op_Not
then Kind
:= N_Op_Not
;
1330 raise Program_Error
;
1337 -----------------------------
1338 -- Pre_Analyze_And_Resolve --
1339 -----------------------------
1341 procedure Pre_Analyze_And_Resolve
(N
: Node_Id
; T
: Entity_Id
) is
1342 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1345 Full_Analysis
:= False;
1346 Expander_Mode_Save_And_Set
(False);
1348 -- We suppress all checks for this analysis, since the checks will
1349 -- be applied properly, and in the right location, when the default
1350 -- expression is reanalyzed and reexpanded later on.
1352 Analyze_And_Resolve
(N
, T
, Suppress
=> All_Checks
);
1354 Expander_Mode_Restore
;
1355 Full_Analysis
:= Save_Full_Analysis
;
1356 end Pre_Analyze_And_Resolve
;
1358 -- Version without context type
1360 procedure Pre_Analyze_And_Resolve
(N
: Node_Id
) is
1361 Save_Full_Analysis
: constant Boolean := Full_Analysis
;
1364 Full_Analysis
:= False;
1365 Expander_Mode_Save_And_Set
(False);
1368 Resolve
(N
, Etype
(N
), Suppress
=> All_Checks
);
1370 Expander_Mode_Restore
;
1371 Full_Analysis
:= Save_Full_Analysis
;
1372 end Pre_Analyze_And_Resolve
;
1374 ----------------------------------
1375 -- Replace_Actual_Discriminants --
1376 ----------------------------------
1378 procedure Replace_Actual_Discriminants
(N
: Node_Id
; Default
: Node_Id
) is
1379 Loc
: constant Source_Ptr
:= Sloc
(N
);
1380 Tsk
: Node_Id
:= Empty
;
1382 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
;
1388 function Process_Discr
(Nod
: Node_Id
) return Traverse_Result
is
1392 if Nkind
(Nod
) = N_Identifier
then
1393 Ent
:= Entity
(Nod
);
1396 and then Ekind
(Ent
) = E_Discriminant
1399 Make_Selected_Component
(Loc
,
1400 Prefix
=> New_Copy_Tree
(Tsk
, New_Sloc
=> Loc
),
1401 Selector_Name
=> Make_Identifier
(Loc
, Chars
(Ent
))));
1403 Set_Etype
(Nod
, Etype
(Ent
));
1411 procedure Replace_Discrs
is new Traverse_Proc
(Process_Discr
);
1413 -- Start of processing for Replace_Actual_Discriminants
1416 if not Expander_Active
then
1420 if Nkind
(Name
(N
)) = N_Selected_Component
then
1421 Tsk
:= Prefix
(Name
(N
));
1423 elsif Nkind
(Name
(N
)) = N_Indexed_Component
then
1424 Tsk
:= Prefix
(Prefix
(Name
(N
)));
1430 Replace_Discrs
(Default
);
1432 end Replace_Actual_Discriminants
;
1438 procedure Resolve
(N
: Node_Id
; Typ
: Entity_Id
) is
1440 I1
: Interp_Index
:= 0; -- prevent junk warning
1443 Found
: Boolean := False;
1444 Seen
: Entity_Id
:= Empty
; -- prevent junk warning
1445 Ctx_Type
: Entity_Id
:= Typ
;
1446 Expr_Type
: Entity_Id
:= Empty
; -- prevent junk warning
1447 Err_Type
: Entity_Id
:= Empty
;
1448 Ambiguous
: Boolean := False;
1450 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
);
1451 -- Try and fix up a literal so that it matches its expected type. New
1452 -- literals are manufactured if necessary to avoid cascaded errors.
1454 procedure Resolution_Failed
;
1455 -- Called when attempt at resolving current expression fails
1457 --------------------
1458 -- Patch_Up_Value --
1459 --------------------
1461 procedure Patch_Up_Value
(N
: Node_Id
; Typ
: Entity_Id
) is
1463 if Nkind
(N
) = N_Integer_Literal
1464 and then Is_Real_Type
(Typ
)
1467 Make_Real_Literal
(Sloc
(N
),
1468 Realval
=> UR_From_Uint
(Intval
(N
))));
1469 Set_Etype
(N
, Universal_Real
);
1470 Set_Is_Static_Expression
(N
);
1472 elsif Nkind
(N
) = N_Real_Literal
1473 and then Is_Integer_Type
(Typ
)
1476 Make_Integer_Literal
(Sloc
(N
),
1477 Intval
=> UR_To_Uint
(Realval
(N
))));
1478 Set_Etype
(N
, Universal_Integer
);
1479 Set_Is_Static_Expression
(N
);
1480 elsif Nkind
(N
) = N_String_Literal
1481 and then Is_Character_Type
(Typ
)
1483 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('A')));
1485 Make_Character_Literal
(Sloc
(N
),
1487 Char_Literal_Value
=>
1488 UI_From_Int
(Character'Pos ('A'))));
1489 Set_Etype
(N
, Any_Character
);
1490 Set_Is_Static_Expression
(N
);
1492 elsif Nkind
(N
) /= N_String_Literal
1493 and then Is_String_Type
(Typ
)
1496 Make_String_Literal
(Sloc
(N
),
1497 Strval
=> End_String
));
1499 elsif Nkind
(N
) = N_Range
then
1500 Patch_Up_Value
(Low_Bound
(N
), Typ
);
1501 Patch_Up_Value
(High_Bound
(N
), Typ
);
1505 -----------------------
1506 -- Resolution_Failed --
1507 -----------------------
1509 procedure Resolution_Failed
is
1511 Patch_Up_Value
(N
, Typ
);
1513 Debug_A_Exit
("resolving ", N
, " (done, resolution failed)");
1514 Set_Is_Overloaded
(N
, False);
1516 -- The caller will return without calling the expander, so we need
1517 -- to set the analyzed flag. Note that it is fine to set Analyzed
1518 -- to True even if we are in the middle of a shallow analysis,
1519 -- (see the spec of sem for more details) since this is an error
1520 -- situation anyway, and there is no point in repeating the
1521 -- analysis later (indeed it won't work to repeat it later, since
1522 -- we haven't got a clear resolution of which entity is being
1525 Set_Analyzed
(N
, True);
1527 end Resolution_Failed
;
1529 -- Start of processing for Resolve
1536 -- Access attribute on remote subprogram cannot be used for
1537 -- a non-remote access-to-subprogram type.
1539 if Nkind
(N
) = N_Attribute_Reference
1540 and then (Attribute_Name
(N
) = Name_Access
1541 or else Attribute_Name
(N
) = Name_Unrestricted_Access
1542 or else Attribute_Name
(N
) = Name_Unchecked_Access
)
1543 and then Comes_From_Source
(N
)
1544 and then Is_Entity_Name
(Prefix
(N
))
1545 and then Is_Subprogram
(Entity
(Prefix
(N
)))
1546 and then Is_Remote_Call_Interface
(Entity
(Prefix
(N
)))
1547 and then not Is_Remote_Access_To_Subprogram_Type
(Typ
)
1550 ("prefix must statically denote a non-remote subprogram", N
);
1553 -- If the context is a Remote_Access_To_Subprogram, access attributes
1554 -- must be resolved with the corresponding fat pointer. There is no need
1555 -- to check for the attribute name since the return type of an
1556 -- attribute is never a remote type.
1558 if Nkind
(N
) = N_Attribute_Reference
1559 and then Comes_From_Source
(N
)
1560 and then (Is_Remote_Call_Interface
(Typ
)
1561 or else Is_Remote_Types
(Typ
))
1564 Attr
: constant Attribute_Id
:=
1565 Get_Attribute_Id
(Attribute_Name
(N
));
1566 Pref
: constant Node_Id
:= Prefix
(N
);
1569 Is_Remote
: Boolean := True;
1572 -- Check that Typ is a remote access-to-subprogram type
1574 if Is_Remote_Access_To_Subprogram_Type
(Typ
) then
1575 -- Prefix (N) must statically denote a remote subprogram
1576 -- declared in a package specification.
1578 if Attr
= Attribute_Access
then
1579 Decl
:= Unit_Declaration_Node
(Entity
(Pref
));
1581 if Nkind
(Decl
) = N_Subprogram_Body
then
1582 Spec
:= Corresponding_Spec
(Decl
);
1584 if not No
(Spec
) then
1585 Decl
:= Unit_Declaration_Node
(Spec
);
1589 Spec
:= Parent
(Decl
);
1591 if not Is_Entity_Name
(Prefix
(N
))
1592 or else Nkind
(Spec
) /= N_Package_Specification
1594 not Is_Remote_Call_Interface
(Defining_Entity
(Spec
))
1598 ("prefix must statically denote a remote subprogram ",
1603 -- If we are generating code for a distributed program.
1604 -- perform semantic checks against the corresponding
1607 if (Attr
= Attribute_Access
1608 or else Attr
= Attribute_Unchecked_Access
1609 or else Attr
= Attribute_Unrestricted_Access
)
1610 and then Expander_Active
1611 and then Get_PCS_Name
/= Name_No_DSA
1613 Check_Subtype_Conformant
1614 (New_Id
=> Entity
(Prefix
(N
)),
1615 Old_Id
=> Designated_Type
1616 (Corresponding_Remote_Type
(Typ
)),
1619 Process_Remote_AST_Attribute
(N
, Typ
);
1626 Debug_A_Entry
("resolving ", N
);
1628 if Comes_From_Source
(N
) then
1629 if Is_Fixed_Point_Type
(Typ
) then
1630 Check_Restriction
(No_Fixed_Point
, N
);
1632 elsif Is_Floating_Point_Type
(Typ
)
1633 and then Typ
/= Universal_Real
1634 and then Typ
/= Any_Real
1636 Check_Restriction
(No_Floating_Point
, N
);
1640 -- Return if already analyzed
1642 if Analyzed
(N
) then
1643 Debug_A_Exit
("resolving ", N
, " (done, already analyzed)");
1646 -- Return if type = Any_Type (previous error encountered)
1648 elsif Etype
(N
) = Any_Type
then
1649 Debug_A_Exit
("resolving ", N
, " (done, Etype = Any_Type)");
1653 Check_Parameterless_Call
(N
);
1655 -- If not overloaded, then we know the type, and all that needs doing
1656 -- is to check that this type is compatible with the context.
1658 if not Is_Overloaded
(N
) then
1659 Found
:= Covers
(Typ
, Etype
(N
));
1660 Expr_Type
:= Etype
(N
);
1662 -- In the overloaded case, we must select the interpretation that
1663 -- is compatible with the context (i.e. the type passed to Resolve)
1666 Get_First_Interp
(N
, I
, It
);
1668 -- Loop through possible interpretations
1670 Interp_Loop
: while Present
(It
.Typ
) loop
1672 -- We are only interested in interpretations that are compatible
1673 -- with the expected type, any other interpretations are ignored
1675 if not Covers
(Typ
, It
.Typ
) then
1676 if Debug_Flag_V
then
1677 Write_Str
(" interpretation incompatible with context");
1682 -- First matching interpretation
1688 Expr_Type
:= It
.Typ
;
1690 -- Matching interpretation that is not the first, maybe an
1691 -- error, but there are some cases where preference rules are
1692 -- used to choose between the two possibilities. These and
1693 -- some more obscure cases are handled in Disambiguate.
1696 Error_Msg_Sloc
:= Sloc
(Seen
);
1697 It1
:= Disambiguate
(N
, I1
, I
, Typ
);
1699 -- Disambiguation has succeeded. Skip the remaining
1702 if It1
/= No_Interp
then
1704 Expr_Type
:= It1
.Typ
;
1706 while Present
(It
.Typ
) loop
1707 Get_Next_Interp
(I
, It
);
1711 -- Before we issue an ambiguity complaint, check for
1712 -- the case of a subprogram call where at least one
1713 -- of the arguments is Any_Type, and if so, suppress
1714 -- the message, since it is a cascaded error.
1716 if Nkind
(N
) = N_Function_Call
1717 or else Nkind
(N
) = N_Procedure_Call_Statement
1720 A
: Node_Id
:= First_Actual
(N
);
1724 while Present
(A
) loop
1727 if Nkind
(E
) = N_Parameter_Association
then
1728 E
:= Explicit_Actual_Parameter
(E
);
1731 if Etype
(E
) = Any_Type
then
1732 if Debug_Flag_V
then
1733 Write_Str
("Any_Type in call");
1744 elsif Nkind
(N
) in N_Binary_Op
1745 and then (Etype
(Left_Opnd
(N
)) = Any_Type
1746 or else Etype
(Right_Opnd
(N
)) = Any_Type
)
1750 elsif Nkind
(N
) in N_Unary_Op
1751 and then Etype
(Right_Opnd
(N
)) = Any_Type
1756 -- Not that special case, so issue message using the
1757 -- flag Ambiguous to control printing of the header
1758 -- message only at the start of an ambiguous set.
1760 if not Ambiguous
then
1762 ("ambiguous expression (cannot resolve&)!",
1766 ("possible interpretation#!", N
);
1770 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
1772 -- By default, the error message refers to the candidate
1773 -- interpretation. But if it is a predefined operator,
1774 -- it is implicitly declared at the declaration of
1775 -- the type of the operand. Recover the sloc of that
1776 -- declaration for the error message.
1778 if Nkind
(N
) in N_Op
1779 and then Scope
(It
.Nam
) = Standard_Standard
1780 and then not Is_Overloaded
(Right_Opnd
(N
))
1781 and then Scope
(Base_Type
(Etype
(Right_Opnd
(N
))))
1782 /= Standard_Standard
1784 Err_Type
:= First_Subtype
(Etype
(Right_Opnd
(N
)));
1786 if Comes_From_Source
(Err_Type
)
1787 and then Present
(Parent
(Err_Type
))
1789 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
1792 elsif Nkind
(N
) in N_Binary_Op
1793 and then Scope
(It
.Nam
) = Standard_Standard
1794 and then not Is_Overloaded
(Left_Opnd
(N
))
1795 and then Scope
(Base_Type
(Etype
(Left_Opnd
(N
))))
1796 /= Standard_Standard
1798 Err_Type
:= First_Subtype
(Etype
(Left_Opnd
(N
)));
1800 if Comes_From_Source
(Err_Type
)
1801 and then Present
(Parent
(Err_Type
))
1803 Error_Msg_Sloc
:= Sloc
(Parent
(Err_Type
));
1809 if Nkind
(N
) in N_Op
1810 and then Scope
(It
.Nam
) = Standard_Standard
1811 and then Present
(Err_Type
)
1814 ("possible interpretation (predefined)#!", N
);
1816 Error_Msg_N
("possible interpretation#!", N
);
1822 -- We have a matching interpretation, Expr_Type is the
1823 -- type from this interpretation, and Seen is the entity.
1825 -- For an operator, just set the entity name. The type will
1826 -- be set by the specific operator resolution routine.
1828 if Nkind
(N
) in N_Op
then
1829 Set_Entity
(N
, Seen
);
1830 Generate_Reference
(Seen
, N
);
1832 elsif Nkind
(N
) = N_Character_Literal
then
1833 Set_Etype
(N
, Expr_Type
);
1835 -- For an explicit dereference, attribute reference, range,
1836 -- short-circuit form (which is not an operator node),
1837 -- or a call with a name that is an explicit dereference,
1838 -- there is nothing to be done at this point.
1840 elsif Nkind
(N
) = N_Explicit_Dereference
1841 or else Nkind
(N
) = N_Attribute_Reference
1842 or else Nkind
(N
) = N_And_Then
1843 or else Nkind
(N
) = N_Indexed_Component
1844 or else Nkind
(N
) = N_Or_Else
1845 or else Nkind
(N
) = N_Range
1846 or else Nkind
(N
) = N_Selected_Component
1847 or else Nkind
(N
) = N_Slice
1848 or else Nkind
(Name
(N
)) = N_Explicit_Dereference
1852 -- For procedure or function calls, set the type of the
1853 -- name, and also the entity pointer for the prefix
1855 elsif (Nkind
(N
) = N_Procedure_Call_Statement
1856 or else Nkind
(N
) = N_Function_Call
)
1857 and then (Is_Entity_Name
(Name
(N
))
1858 or else Nkind
(Name
(N
)) = N_Operator_Symbol
)
1860 Set_Etype
(Name
(N
), Expr_Type
);
1861 Set_Entity
(Name
(N
), Seen
);
1862 Generate_Reference
(Seen
, Name
(N
));
1864 elsif Nkind
(N
) = N_Function_Call
1865 and then Nkind
(Name
(N
)) = N_Selected_Component
1867 Set_Etype
(Name
(N
), Expr_Type
);
1868 Set_Entity
(Selector_Name
(Name
(N
)), Seen
);
1869 Generate_Reference
(Seen
, Selector_Name
(Name
(N
)));
1871 -- For all other cases, just set the type of the Name
1874 Set_Etype
(Name
(N
), Expr_Type
);
1879 -- Move to next interpretation
1881 exit Interp_Loop
when not Present
(It
.Typ
);
1883 Get_Next_Interp
(I
, It
);
1884 end loop Interp_Loop
;
1887 -- At this stage Found indicates whether or not an acceptable
1888 -- interpretation exists. If not, then we have an error, except
1889 -- that if the context is Any_Type as a result of some other error,
1890 -- then we suppress the error report.
1893 if Typ
/= Any_Type
then
1895 -- If type we are looking for is Void, then this is the
1896 -- procedure call case, and the error is simply that what
1897 -- we gave is not a procedure name (we think of procedure
1898 -- calls as expressions with types internally, but the user
1899 -- doesn't think of them this way!)
1901 if Typ
= Standard_Void_Type
then
1903 -- Special case message if function used as a procedure
1905 if Nkind
(N
) = N_Procedure_Call_Statement
1906 and then Is_Entity_Name
(Name
(N
))
1907 and then Ekind
(Entity
(Name
(N
))) = E_Function
1910 ("cannot use function & in a procedure call",
1911 Name
(N
), Entity
(Name
(N
)));
1913 -- Otherwise give general message (not clear what cases
1914 -- this covers, but no harm in providing for them!)
1917 Error_Msg_N
("expect procedure name in procedure call", N
);
1922 -- Otherwise we do have a subexpression with the wrong type
1924 -- Check for the case of an allocator which uses an access
1925 -- type instead of the designated type. This is a common
1926 -- error and we specialize the message, posting an error
1927 -- on the operand of the allocator, complaining that we
1928 -- expected the designated type of the allocator.
1930 elsif Nkind
(N
) = N_Allocator
1931 and then Ekind
(Typ
) in Access_Kind
1932 and then Ekind
(Etype
(N
)) in Access_Kind
1933 and then Designated_Type
(Etype
(N
)) = Typ
1935 Wrong_Type
(Expression
(N
), Designated_Type
(Typ
));
1938 -- Check for view mismatch on Null in instances, for
1939 -- which the view-swapping mechanism has no identifier.
1941 elsif (In_Instance
or else In_Inlined_Body
)
1942 and then (Nkind
(N
) = N_Null
)
1943 and then Is_Private_Type
(Typ
)
1944 and then Is_Access_Type
(Full_View
(Typ
))
1946 Resolve
(N
, Full_View
(Typ
));
1950 -- Check for an aggregate. Sometimes we can get bogus
1951 -- aggregates from misuse of parentheses, and we are
1952 -- about to complain about the aggregate without even
1953 -- looking inside it.
1955 -- Instead, if we have an aggregate of type Any_Composite,
1956 -- then analyze and resolve the component fields, and then
1957 -- only issue another message if we get no errors doing
1958 -- this (otherwise assume that the errors in the aggregate
1959 -- caused the problem).
1961 elsif Nkind
(N
) = N_Aggregate
1962 and then Etype
(N
) = Any_Composite
1964 -- Disable expansion in any case. If there is a type mismatch
1965 -- it may be fatal to try to expand the aggregate. The flag
1966 -- would otherwise be set to false when the error is posted.
1968 Expander_Active
:= False;
1971 procedure Check_Aggr
(Aggr
: Node_Id
);
1972 -- Check one aggregate, and set Found to True if we
1973 -- have a definite error in any of its elements
1975 procedure Check_Elmt
(Aelmt
: Node_Id
);
1976 -- Check one element of aggregate and set Found to
1977 -- True if we definitely have an error in the element.
1979 procedure Check_Aggr
(Aggr
: Node_Id
) is
1983 if Present
(Expressions
(Aggr
)) then
1984 Elmt
:= First
(Expressions
(Aggr
));
1985 while Present
(Elmt
) loop
1991 if Present
(Component_Associations
(Aggr
)) then
1992 Elmt
:= First
(Component_Associations
(Aggr
));
1993 while Present
(Elmt
) loop
1994 Check_Elmt
(Expression
(Elmt
));
2004 procedure Check_Elmt
(Aelmt
: Node_Id
) is
2006 -- If we have a nested aggregate, go inside it (to
2007 -- attempt a naked analyze-resolve of the aggregate
2008 -- can cause undesirable cascaded errors). Do not
2009 -- resolve expression if it needs a type from context,
2010 -- as for integer * fixed expression.
2012 if Nkind
(Aelmt
) = N_Aggregate
then
2018 if not Is_Overloaded
(Aelmt
)
2019 and then Etype
(Aelmt
) /= Any_Fixed
2024 if Etype
(Aelmt
) = Any_Type
then
2035 -- If an error message was issued already, Found got reset
2036 -- to True, so if it is still False, issue the standard
2037 -- Wrong_Type message.
2040 if Is_Overloaded
(N
)
2041 and then Nkind
(N
) = N_Function_Call
2044 Subp_Name
: Node_Id
;
2046 if Is_Entity_Name
(Name
(N
)) then
2047 Subp_Name
:= Name
(N
);
2049 elsif Nkind
(Name
(N
)) = N_Selected_Component
then
2051 -- Protected operation: retrieve operation name
2053 Subp_Name
:= Selector_Name
(Name
(N
));
2055 raise Program_Error
;
2058 Error_Msg_Node_2
:= Typ
;
2059 Error_Msg_NE
("no visible interpretation of&" &
2060 " matches expected type&", N
, Subp_Name
);
2063 if All_Errors_Mode
then
2065 Index
: Interp_Index
;
2069 Error_Msg_N
("\possible interpretations:", N
);
2070 Get_First_Interp
(Name
(N
), Index
, It
);
2072 while Present
(It
.Nam
) loop
2074 Error_Msg_Sloc
:= Sloc
(It
.Nam
);
2075 Error_Msg_Node_2
:= It
.Typ
;
2076 Error_Msg_NE
("\& declared#, type&",
2079 Get_Next_Interp
(Index
, It
);
2083 Error_Msg_N
("\use -gnatf for details", N
);
2086 Wrong_Type
(N
, Typ
);
2094 -- Test if we have more than one interpretation for the context
2096 elsif Ambiguous
then
2100 -- Here we have an acceptable interpretation for the context
2103 -- Propagate type information and normalize tree for various
2104 -- predefined operations. If the context only imposes a class of
2105 -- types, rather than a specific type, propagate the actual type
2108 if Typ
= Any_Integer
2109 or else Typ
= Any_Boolean
2110 or else Typ
= Any_Modular
2111 or else Typ
= Any_Real
2112 or else Typ
= Any_Discrete
2114 Ctx_Type
:= Expr_Type
;
2116 -- Any_Fixed is legal in a real context only if a specific
2117 -- fixed point type is imposed. If Norman Cohen can be
2118 -- confused by this, it deserves a separate message.
2121 and then Expr_Type
= Any_Fixed
2123 Error_Msg_N
("Illegal context for mixed mode operation", N
);
2124 Set_Etype
(N
, Universal_Real
);
2125 Ctx_Type
:= Universal_Real
;
2129 -- A user-defined operator is tranformed into a function call at
2130 -- this point, so that further processing knows that operators are
2131 -- really operators (i.e. are predefined operators). User-defined
2132 -- operators that are intrinsic are just renamings of the predefined
2133 -- ones, and need not be turned into calls either, but if they rename
2134 -- a different operator, we must transform the node accordingly.
2135 -- Instantiations of Unchecked_Conversion are intrinsic but are
2136 -- treated as functions, even if given an operator designator.
2138 if Nkind
(N
) in N_Op
2139 and then Present
(Entity
(N
))
2140 and then Ekind
(Entity
(N
)) /= E_Operator
2143 if not Is_Predefined_Op
(Entity
(N
)) then
2144 Rewrite_Operator_As_Call
(N
, Entity
(N
));
2146 elsif Present
(Alias
(Entity
(N
)))
2148 Nkind
(Parent
(Parent
(Entity
(N
))))
2149 = N_Subprogram_Renaming_Declaration
2151 Rewrite_Renamed_Operator
(N
, Alias
(Entity
(N
)), Typ
);
2153 -- If the node is rewritten, it will be fully resolved in
2154 -- Rewrite_Renamed_Operator.
2156 if Analyzed
(N
) then
2162 case N_Subexpr
'(Nkind (N)) is
2164 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2166 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2168 when N_And_Then | N_Or_Else
2169 => Resolve_Short_Circuit (N, Ctx_Type);
2171 when N_Attribute_Reference
2172 => Resolve_Attribute (N, Ctx_Type);
2174 when N_Character_Literal
2175 => Resolve_Character_Literal (N, Ctx_Type);
2177 when N_Conditional_Expression
2178 => Resolve_Conditional_Expression (N, Ctx_Type);
2180 when N_Expanded_Name
2181 => Resolve_Entity_Name (N, Ctx_Type);
2183 when N_Extension_Aggregate
2184 => Resolve_Extension_Aggregate (N, Ctx_Type);
2186 when N_Explicit_Dereference
2187 => Resolve_Explicit_Dereference (N, Ctx_Type);
2189 when N_Function_Call
2190 => Resolve_Call (N, Ctx_Type);
2193 => Resolve_Entity_Name (N, Ctx_Type);
2195 when N_In | N_Not_In
2196 => Resolve_Membership_Op (N, Ctx_Type);
2198 when N_Indexed_Component
2199 => Resolve_Indexed_Component (N, Ctx_Type);
2201 when N_Integer_Literal
2202 => Resolve_Integer_Literal (N, Ctx_Type);
2204 when N_Null => Resolve_Null (N, Ctx_Type);
2206 when N_Op_And | N_Op_Or | N_Op_Xor
2207 => Resolve_Logical_Op (N, Ctx_Type);
2209 when N_Op_Eq | N_Op_Ne
2210 => Resolve_Equality_Op (N, Ctx_Type);
2212 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2213 => Resolve_Comparison_Op (N, Ctx_Type);
2215 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2217 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2218 N_Op_Divide | N_Op_Mod | N_Op_Rem
2220 => Resolve_Arithmetic_Op (N, Ctx_Type);
2222 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2224 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2226 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2227 => Resolve_Unary_Op (N, Ctx_Type);
2229 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2231 when N_Procedure_Call_Statement
2232 => Resolve_Call (N, Ctx_Type);
2234 when N_Operator_Symbol
2235 => Resolve_Operator_Symbol (N, Ctx_Type);
2237 when N_Qualified_Expression
2238 => Resolve_Qualified_Expression (N, Ctx_Type);
2240 when N_Raise_xxx_Error
2241 => Set_Etype (N, Ctx_Type);
2243 when N_Range => Resolve_Range (N, Ctx_Type);
2246 => Resolve_Real_Literal (N, Ctx_Type);
2248 when N_Reference => Resolve_Reference (N, Ctx_Type);
2250 when N_Selected_Component
2251 => Resolve_Selected_Component (N, Ctx_Type);
2253 when N_Slice => Resolve_Slice (N, Ctx_Type);
2255 when N_String_Literal
2256 => Resolve_String_Literal (N, Ctx_Type);
2258 when N_Subprogram_Info
2259 => Resolve_Subprogram_Info (N, Ctx_Type);
2261 when N_Type_Conversion
2262 => Resolve_Type_Conversion (N, Ctx_Type);
2264 when N_Unchecked_Expression =>
2265 Resolve_Unchecked_Expression (N, Ctx_Type);
2267 when N_Unchecked_Type_Conversion =>
2268 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2272 -- If the subexpression was replaced by a non-subexpression, then
2273 -- all we do is to expand it. The only legitimate case we know of
2274 -- is converting procedure call statement to entry call statements,
2275 -- but there may be others, so we are making this test general.
2277 if Nkind (N) not in N_Subexpr then
2278 Debug_A_Exit ("resolving ", N, " (done)");
2283 -- The expression is definitely NOT overloaded at this point, so
2284 -- we reset the Is_Overloaded flag to avoid any confusion when
2285 -- reanalyzing the node.
2287 Set_Is_Overloaded (N, False);
2289 -- Freeze expression type, entity if it is a name, and designated
2290 -- type if it is an allocator (RM 13.14(10,11,13)).
2292 -- Now that the resolution of the type of the node is complete,
2293 -- and we did not detect an error, we can expand this node. We
2294 -- skip the expand call if we are in a default expression, see
2295 -- section "Handling of Default Expressions" in Sem spec.
2297 Debug_A_Exit ("resolving ", N, " (done)");
2299 -- We unconditionally freeze the expression, even if we are in
2300 -- default expression mode (the Freeze_Expression routine tests
2301 -- this flag and only freezes static types if it is set).
2303 Freeze_Expression (N);
2305 -- Now we can do the expansion
2315 -- Version with check(s) suppressed
2317 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2319 if Suppress = All_Checks then
2321 Svg : constant Suppress_Array := Scope_Suppress;
2324 Scope_Suppress := (others => True);
2326 Scope_Suppress := Svg;
2331 Svg : constant Boolean := Scope_Suppress (Suppress);
2334 Scope_Suppress (Suppress) := True;
2336 Scope_Suppress (Suppress) := Svg;
2345 -- Version with implicit type
2347 procedure Resolve (N : Node_Id) is
2349 Resolve (N, Etype (N));
2352 ---------------------
2353 -- Resolve_Actuals --
2354 ---------------------
2356 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2357 Loc : constant Source_Ptr := Sloc (N);
2362 Prev : Node_Id := Empty;
2364 procedure Insert_Default;
2365 -- If the actual is missing in a call, insert in the actuals list
2366 -- an instance of the default expression. The insertion is always
2367 -- a named association.
2369 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2370 -- Check whether T1 and T2, or their full views, are derived from a
2371 -- common type. Used to enforce the restrictions on array conversions
2374 --------------------
2375 -- Insert_Default --
2376 --------------------
2378 procedure Insert_Default is
2383 -- Missing argument in call, nothing to insert
2385 if No (Default_Value (F)) then
2389 -- Note that we do a full New_Copy_Tree, so that any associated
2390 -- Itypes are properly copied. This may not be needed any more,
2391 -- but it does no harm as a safety measure! Defaults of a generic
2392 -- formal may be out of bounds of the corresponding actual (see
2393 -- cc1311b) and an additional check may be required.
2395 Actval := New_Copy_Tree (Default_Value (F),
2396 New_Scope => Current_Scope, New_Sloc => Loc);
2398 if Is_Concurrent_Type (Scope (Nam))
2399 and then Has_Discriminants (Scope (Nam))
2401 Replace_Actual_Discriminants (N, Actval);
2404 if Is_Overloadable (Nam)
2405 and then Present (Alias (Nam))
2407 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2408 and then not Is_Tagged_Type (Etype (F))
2410 -- If default is a real literal, do not introduce a
2411 -- conversion whose effect may depend on the run-time
2412 -- size of universal real.
2414 if Nkind (Actval) = N_Real_Literal then
2415 Set_Etype (Actval, Base_Type (Etype (F)));
2417 Actval := Unchecked_Convert_To (Etype (F), Actval);
2421 if Is_Scalar_Type (Etype (F)) then
2422 Enable_Range_Check (Actval);
2425 Set_Parent (Actval, N);
2427 -- Resolve aggregates with their base type, to avoid scope
2428 -- anomalies: the subtype was first built in the suprogram
2429 -- declaration, and the current call may be nested.
2431 if Nkind (Actval) = N_Aggregate
2432 and then Has_Discriminants (Etype (Actval))
2434 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2436 Analyze_And_Resolve (Actval, Etype (Actval));
2440 Set_Parent (Actval, N);
2442 -- See note above concerning aggregates
2444 if Nkind (Actval) = N_Aggregate
2445 and then Has_Discriminants (Etype (Actval))
2447 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2449 -- Resolve entities with their own type, which may differ
2450 -- from the type of a reference in a generic context (the
2451 -- view swapping mechanism did not anticipate the re-analysis
2452 -- of default values in calls).
2454 elsif Is_Entity_Name (Actval) then
2455 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
2458 Analyze_And_Resolve (Actval, Etype (Actval));
2462 -- If default is a tag indeterminate function call, propagate
2463 -- tag to obtain proper dispatching.
2465 if Is_Controlling_Formal (F)
2466 and then Nkind (Default_Value (F)) = N_Function_Call
2468 Set_Is_Controlling_Actual (Actval);
2473 -- If the default expression raises constraint error, then just
2474 -- silently replace it with an N_Raise_Constraint_Error node,
2475 -- since we already gave the warning on the subprogram spec.
2477 if Raises_Constraint_Error (Actval) then
2479 Make_Raise_Constraint_Error (Loc,
2480 Reason => CE_Range_Check_Failed));
2481 Set_Raises_Constraint_Error (Actval);
2482 Set_Etype (Actval, Etype (F));
2486 Make_Parameter_Association (Loc,
2487 Explicit_Actual_Parameter => Actval,
2488 Selector_Name => Make_Identifier (Loc, Chars (F)));
2490 -- Case of insertion is first named actual
2492 if No (Prev) or else
2493 Nkind (Parent (Prev)) /= N_Parameter_Association
2495 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
2496 Set_First_Named_Actual (N, Actval);
2499 if not Present (Parameter_Associations (N)) then
2500 Set_Parameter_Associations (N, New_List (Assoc));
2502 Append (Assoc, Parameter_Associations (N));
2506 Insert_After (Prev, Assoc);
2509 -- Case of insertion is not first named actual
2512 Set_Next_Named_Actual
2513 (Assoc, Next_Named_Actual (Parent (Prev)));
2514 Set_Next_Named_Actual (Parent (Prev), Actval);
2515 Append (Assoc, Parameter_Associations (N));
2518 Mark_Rewrite_Insertion (Assoc);
2519 Mark_Rewrite_Insertion (Actval);
2528 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
2529 FT1 : Entity_Id := T1;
2530 FT2 : Entity_Id := T2;
2533 if Is_Private_Type (T1)
2534 and then Present (Full_View (T1))
2536 FT1 := Full_View (T1);
2539 if Is_Private_Type (T2)
2540 and then Present (Full_View (T2))
2542 FT2 := Full_View (T2);
2545 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
2548 -- Start of processing for Resolve_Actuals
2551 A := First_Actual (N);
2552 F := First_Formal (Nam);
2553 while Present (F) loop
2554 if No (A) and then Needs_No_Actuals (Nam) then
2557 -- If we have an error in any actual or formal, indicated by
2558 -- a type of Any_Type, then abandon resolution attempt, and
2559 -- set result type to Any_Type.
2561 elsif (Present (A) and then Etype (A) = Any_Type)
2562 or else Etype (F) = Any_Type
2564 Set_Etype (N, Any_Type);
2569 and then (Nkind (Parent (A)) /= N_Parameter_Association
2571 Chars (Selector_Name (Parent (A))) = Chars (F))
2573 -- If the formal is Out or In_Out, do not resolve and expand the
2574 -- conversion, because it is subsequently expanded into explicit
2575 -- temporaries and assignments. However, the object of the
2576 -- conversion can be resolved. An exception is the case of
2577 -- a tagged type conversion with a class-wide actual. In that
2578 -- case we want the tag check to occur and no temporary will
2579 -- will be needed (no representation change can occur) and
2580 -- the parameter is passed by reference, so we go ahead and
2581 -- resolve the type conversion.
2583 if Ekind (F) /= E_In_Parameter
2584 and then Nkind (A) = N_Type_Conversion
2585 and then not Is_Class_Wide_Type (Etype (Expression (A)))
2587 if Ekind (F) = E_In_Out_Parameter
2588 and then Is_Array_Type (Etype (F))
2590 if Has_Aliased_Components (Etype (Expression (A)))
2591 /= Has_Aliased_Components (Etype (F))
2594 ("both component types in a view conversion must be"
2595 & " aliased, or neither", A);
2597 elsif not Same_Ancestor (Etype (F), Etype (Expression (A)))
2599 (Is_By_Reference_Type (Etype (F))
2600 or else Is_By_Reference_Type (Etype (Expression (A))))
2603 ("view conversion between unrelated by_reference "
2604 & "array types not allowed (\A\I-00246)?", A);
2608 if Conversion_OK (A)
2609 or else Valid_Conversion (A, Etype (A), Expression (A))
2611 Resolve (Expression (A));
2615 if Nkind (A) = N_Type_Conversion
2616 and then Is_Array_Type (Etype (F))
2617 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
2619 (Is_Limited_Type (Etype (F))
2620 or else Is_Limited_Type (Etype (Expression (A))))
2623 ("Conversion between unrelated limited array types "
2624 & "not allowed (\A\I-00246)?", A);
2626 -- Disable explanation (which produces additional errors)
2627 -- until AI is approved and warning becomes an error.
2629 -- if Is_Limited_Type (Etype (F)) then
2630 -- Explain_Limited_Type (Etype (F), A);
2633 -- if Is_Limited_Type (Etype (Expression (A))) then
2634 -- Explain_Limited_Type (Etype (Expression (A)), A);
2638 Resolve (A, Etype (F));
2644 -- Perform error checks for IN and IN OUT parameters
2646 if Ekind (F) /= E_Out_Parameter then
2648 -- Check unset reference. For scalar parameters, it is clearly
2649 -- wrong to pass an uninitialized value as either an IN or
2650 -- IN-OUT parameter. For composites, it is also clearly an
2651 -- error to pass a completely uninitialized value as an IN
2652 -- parameter, but the case of IN OUT is trickier. We prefer
2653 -- not to give a warning here. For example, suppose there is
2654 -- a routine that sets some component of a record to False.
2655 -- It is perfectly reasonable to make this IN-OUT and allow
2656 -- either initialized or uninitialized records to be passed
2659 -- For partially initialized composite values, we also avoid
2660 -- warnings, since it is quite likely that we are passing a
2661 -- partially initialized value and only the initialized fields
2662 -- will in fact be read in the subprogram.
2664 if Is_Scalar_Type (A_Typ)
2665 or else (Ekind (F) = E_In_Parameter
2666 and then not Is_Partially_Initialized_Type (A_Typ))
2668 Check_Unset_Reference (A);
2671 -- In Ada 83 we cannot pass an OUT parameter as an IN
2672 -- or IN OUT actual to a nested call, since this is a
2673 -- case of reading an out parameter, which is not allowed.
2675 if Ada_Version = Ada_83
2676 and then Is_Entity_Name (A)
2677 and then Ekind (Entity (A)) = E_Out_Parameter
2679 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
2683 if Ekind (F) /= E_In_Parameter
2684 and then not Is_OK_Variable_For_Out_Formal (A)
2686 Error_Msg_NE ("actual for& must be a variable", A, F);
2688 if Is_Entity_Name (A) then
2689 Kill_Checks (Entity (A));
2695 if Etype (A) = Any_Type then
2696 Set_Etype (N, Any_Type);
2700 -- Apply appropriate range checks for in, out, and in-out
2701 -- parameters. Out and in-out parameters also need a separate
2702 -- check, if there is a type conversion, to make sure the return
2703 -- value meets the constraints of the variable before the
2706 -- Gigi looks at the check flag and uses the appropriate types.
2707 -- For now since one flag is used there is an optimization which
2708 -- might not be done in the In Out case since Gigi does not do
2709 -- any analysis. More thought required about this ???
2711 if Ekind (F) = E_In_Parameter
2712 or else Ekind (F) = E_In_Out_Parameter
2714 if Is_Scalar_Type (Etype (A)) then
2715 Apply_Scalar_Range_Check (A, F_Typ);
2717 elsif Is_Array_Type (Etype (A)) then
2718 Apply_Length_Check (A, F_Typ);
2720 elsif Is_Record_Type (F_Typ)
2721 and then Has_Discriminants (F_Typ)
2722 and then Is_Constrained (F_Typ)
2723 and then (not Is_Derived_Type (F_Typ)
2724 or else Comes_From_Source (Nam))
2726 Apply_Discriminant_Check (A, F_Typ);
2728 elsif Is_Access_Type (F_Typ)
2729 and then Is_Array_Type (Designated_Type (F_Typ))
2730 and then Is_Constrained (Designated_Type (F_Typ))
2732 Apply_Length_Check (A, F_Typ);
2734 elsif Is_Access_Type (F_Typ)
2735 and then Has_Discriminants (Designated_Type (F_Typ))
2736 and then Is_Constrained (Designated_Type (F_Typ))
2738 Apply_Discriminant_Check (A, F_Typ);
2741 Apply_Range_Check (A, F_Typ);
2744 -- Ada 2005 (AI-231)
2746 if Ada_Version >= Ada_05
2747 and then Is_Access_Type (F_Typ)
2748 and then (Can_Never_Be_Null (F)
2749 or else Can_Never_Be_Null (F_Typ))
2751 if Nkind (A) = N_Null then
2752 Apply_Compile_Time_Constraint_Error
2754 Msg => "(Ada 2005) NULL not allowed in "
2755 & "null-excluding formal?",
2756 Reason => CE_Null_Not_Allowed);
2761 if Ekind (F) = E_Out_Parameter
2762 or else Ekind (F) = E_In_Out_Parameter
2764 if Nkind (A) = N_Type_Conversion then
2765 if Is_Scalar_Type (A_Typ) then
2766 Apply_Scalar_Range_Check
2767 (Expression (A), Etype (Expression (A)), A_Typ);
2770 (Expression (A), Etype (Expression (A)), A_Typ);
2774 if Is_Scalar_Type (F_Typ) then
2775 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
2777 elsif Is_Array_Type (F_Typ)
2778 and then Ekind (F) = E_Out_Parameter
2780 Apply_Length_Check (A, F_Typ);
2783 Apply_Range_Check (A, A_Typ, F_Typ);
2788 -- An actual associated with an access parameter is implicitly
2789 -- converted to the anonymous access type of the formal and
2790 -- must satisfy the legality checks for access conversions.
2792 if Ekind (F_Typ) = E_Anonymous_Access_Type then
2793 if not Valid_Conversion (A, F_Typ, A) then
2795 ("invalid implicit conversion for access parameter", A);
2799 -- Check bad case of atomic/volatile argument (RM C.6(12))
2801 if Is_By_Reference_Type (Etype (F))
2802 and then Comes_From_Source (N)
2804 if Is_Atomic_Object (A)
2805 and then not Is_Atomic (Etype (F))
2808 ("cannot pass atomic argument to non-atomic formal",
2811 elsif Is_Volatile_Object (A)
2812 and then not Is_Volatile (Etype (F))
2815 ("cannot pass volatile argument to non-volatile formal",
2820 -- Check that subprograms don't have improper controlling
2821 -- arguments (RM 3.9.2 (9))
2823 if Is_Controlling_Formal (F) then
2824 Set_Is_Controlling_Actual (A);
2825 elsif Nkind (A) = N_Explicit_Dereference then
2826 Validate_Remote_Access_To_Class_Wide_Type (A);
2829 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
2830 and then not Is_Class_Wide_Type (F_Typ)
2831 and then not Is_Controlling_Formal (F)
2833 Error_Msg_N ("class-wide argument not allowed here!", A);
2835 if Is_Subprogram (Nam)
2836 and then Comes_From_Source (Nam)
2838 Error_Msg_Node_2 := F_Typ;
2840 ("& is not a dispatching operation of &!", A, Nam);
2843 elsif Is_Access_Type (A_Typ)
2844 and then Is_Access_Type (F_Typ)
2845 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
2846 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
2847 or else (Nkind (A) = N_Attribute_Reference
2849 Is_Class_Wide_Type (Etype (Prefix (A)))))
2850 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
2851 and then not Is_Controlling_Formal (F)
2854 ("access to class-wide argument not allowed here!", A);
2856 if Is_Subprogram (Nam)
2857 and then Comes_From_Source (Nam)
2859 Error_Msg_Node_2 := Designated_Type (F_Typ);
2861 ("& is not a dispatching operation of &!", A, Nam);
2867 -- If it is a named association, treat the selector_name as
2868 -- a proper identifier, and mark the corresponding entity.
2870 if Nkind (Parent (A)) = N_Parameter_Association then
2871 Set_Entity (Selector_Name (Parent (A)), F);
2872 Generate_Reference (F, Selector_Name (Parent (A)));
2873 Set_Etype (Selector_Name (Parent (A)), F_Typ);
2874 Generate_Reference (F_Typ, N, ' ');
2879 if Ekind (F) /= E_Out_Parameter then
2880 Check_Unset_Reference (A);
2885 -- Case where actual is not present
2893 end Resolve_Actuals;
2895 -----------------------
2896 -- Resolve_Allocator --
2897 -----------------------
2899 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
2900 E : constant Node_Id := Expression (N);
2902 Discrim : Entity_Id;
2906 function In_Dispatching_Context return Boolean;
2907 -- If the allocator is an actual in a call, it is allowed to be
2908 -- class-wide when the context is not because it is a controlling
2911 ----------------------------
2912 -- In_Dispatching_Context --
2913 ----------------------------
2915 function In_Dispatching_Context return Boolean is
2916 Par : constant Node_Id := Parent (N);
2919 return (Nkind (Par) = N_Function_Call
2920 or else Nkind (Par) = N_Procedure_Call_Statement)
2921 and then Is_Entity_Name (Name (Par))
2922 and then Is_Dispatching_Operation (Entity (Name (Par)));
2923 end In_Dispatching_Context;
2925 -- Start of processing for Resolve_Allocator
2928 -- Replace general access with specific type
2930 if Ekind (Etype (N)) = E_Allocator_Type then
2931 Set_Etype (N, Base_Type (Typ));
2934 if Is_Abstract (Typ) then
2935 Error_Msg_N ("type of allocator cannot be abstract", N);
2938 -- For qualified expression, resolve the expression using the
2939 -- given subtype (nothing to do for type mark, subtype indication)
2941 if Nkind (E) = N_Qualified_Expression then
2942 if Is_Class_Wide_Type (Etype (E))
2943 and then not Is_Class_Wide_Type (Designated_Type (Typ))
2944 and then not In_Dispatching_Context
2947 ("class-wide allocator not allowed for this access type", N);
2950 Resolve (Expression (E), Etype (E));
2951 Check_Unset_Reference (Expression (E));
2953 -- A qualified expression requires an exact match of the type,
2954 -- class-wide matching is not allowed.
2956 if (Is_Class_Wide_Type (Etype (Expression (E)))
2957 or else Is_Class_Wide_Type (Etype (E)))
2958 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
2960 Wrong_Type (Expression (E), Etype (E));
2963 -- For a subtype mark or subtype indication, freeze the subtype
2966 Freeze_Expression (E);
2968 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
2970 ("initialization required for access-to-constant allocator", N);
2973 -- A special accessibility check is needed for allocators that
2974 -- constrain access discriminants. The level of the type of the
2975 -- expression used to contrain an access discriminant cannot be
2976 -- deeper than the type of the allocator (in constrast to access
2977 -- parameters, where the level of the actual can be arbitrary).
2978 -- We can't use Valid_Conversion to perform this check because
2979 -- in general the type of the allocator is unrelated to the type
2980 -- of the access discriminant. Note that specialized checks are
2981 -- needed for the cases of a constraint expression which is an
2982 -- access attribute or an access discriminant.
2984 if Nkind (Original_Node (E)) = N_Subtype_Indication
2985 and then Ekind (Typ) /= E_Anonymous_Access_Type
2987 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
2989 if Has_Discriminants (Subtyp) then
2990 Discrim := First_Discriminant (Base_Type (Subtyp));
2991 Constr := First (Constraints (Constraint (Original_Node (E))));
2993 while Present (Discrim) and then Present (Constr) loop
2994 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
2995 if Nkind (Constr) = N_Discriminant_Association then
2996 Disc_Exp := Original_Node (Expression (Constr));
2998 Disc_Exp := Original_Node (Constr);
3001 if Type_Access_Level (Etype (Disc_Exp))
3002 > Type_Access_Level (Typ)
3005 ("operand type has deeper level than allocator type",
3008 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3009 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3011 and then Object_Access_Level (Prefix (Disc_Exp))
3012 > Type_Access_Level (Typ)
3015 ("prefix of attribute has deeper level than"
3016 & " allocator type", Disc_Exp);
3018 -- When the operand is an access discriminant the check
3019 -- is against the level of the prefix object.
3021 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3022 and then Nkind (Disc_Exp) = N_Selected_Component
3023 and then Object_Access_Level (Prefix (Disc_Exp))
3024 > Type_Access_Level (Typ)
3027 ("access discriminant has deeper level than"
3028 & " allocator type", Disc_Exp);
3031 Next_Discriminant (Discrim);
3038 -- Check for allocation from an empty storage pool
3040 if No_Pool_Assigned (Typ) then
3042 Loc : constant Source_Ptr := Sloc (N);
3045 Error_Msg_N ("?allocation from empty storage pool!", N);
3046 Error_Msg_N ("?Storage_Error will be raised at run time!", N);
3048 Make_Raise_Storage_Error (Loc,
3049 Reason => SE_Empty_Storage_Pool));
3052 end Resolve_Allocator;
3054 ---------------------------
3055 -- Resolve_Arithmetic_Op --
3056 ---------------------------
3058 -- Used for resolving all arithmetic operators except exponentiation
3060 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
3061 L : constant Node_Id := Left_Opnd (N);
3062 R : constant Node_Id := Right_Opnd (N);
3063 TL : constant Entity_Id := Base_Type (Etype (L));
3064 TR : constant Entity_Id := Base_Type (Etype (R));
3068 B_Typ : constant Entity_Id := Base_Type (Typ);
3069 -- We do the resolution using the base type, because intermediate values
3070 -- in expressions always are of the base type, not a subtype of it.
3072 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
3073 -- Return True iff given type is Integer or universal real/integer
3075 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
3076 -- Choose type of integer literal in fixed-point operation to conform
3077 -- to available fixed-point type. T is the type of the other operand,
3078 -- which is needed to determine the expected type of N.
3080 procedure Set_Operand_Type (N : Node_Id);
3081 -- Set operand type to T if universal
3083 -----------------------------
3084 -- Is_Integer_Or_Universal --
3085 -----------------------------
3087 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
3089 Index : Interp_Index;
3093 if not Is_Overloaded (N) then
3095 return Base_Type (T) = Base_Type (Standard_Integer)
3096 or else T = Universal_Integer
3097 or else T = Universal_Real;
3099 Get_First_Interp (N, Index, It);
3101 while Present (It.Typ) loop
3103 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
3104 or else It.Typ = Universal_Integer
3105 or else It.Typ = Universal_Real
3110 Get_Next_Interp (Index, It);
3115 end Is_Integer_Or_Universal;
3117 ----------------------------
3118 -- Set_Mixed_Mode_Operand --
3119 ----------------------------
3121 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
3122 Index : Interp_Index;
3126 if Universal_Interpretation (N) = Universal_Integer then
3128 -- A universal integer literal is resolved as standard integer
3129 -- except in the case of a fixed-point result, where we leave
3130 -- it as universal (to be handled by Exp_Fixd later on)
3132 if Is_Fixed_Point_Type (T) then
3133 Resolve (N, Universal_Integer);
3135 Resolve (N, Standard_Integer);
3138 elsif Universal_Interpretation (N) = Universal_Real
3139 and then (T = Base_Type (Standard_Integer)
3140 or else T = Universal_Integer
3141 or else T = Universal_Real)
3143 -- A universal real can appear in a fixed-type context. We resolve
3144 -- the literal with that context, even though this might raise an
3145 -- exception prematurely (the other operand may be zero).
3149 elsif Etype (N) = Base_Type (Standard_Integer)
3150 and then T = Universal_Real
3151 and then Is_Overloaded (N)
3153 -- Integer arg in mixed-mode operation. Resolve with universal
3154 -- type, in case preference rule must be applied.
3156 Resolve (N, Universal_Integer);
3159 and then B_Typ /= Universal_Fixed
3161 -- Not a mixed-mode operation, resolve with context
3165 elsif Etype (N) = Any_Fixed then
3167 -- N may itself be a mixed-mode operation, so use context type
3171 elsif Is_Fixed_Point_Type (T)
3172 and then B_Typ = Universal_Fixed
3173 and then Is_Overloaded (N)
3175 -- Must be (fixed * fixed) operation, operand must have one
3176 -- compatible interpretation.
3178 Resolve (N, Any_Fixed);
3180 elsif Is_Fixed_Point_Type (B_Typ)
3181 and then (T = Universal_Real
3182 or else Is_Fixed_Point_Type (T))
3183 and then Is_Overloaded (N)
3185 -- C * F(X) in a fixed context, where C is a real literal or a
3186 -- fixed-point expression. F must have either a fixed type
3187 -- interpretation or an integer interpretation, but not both.
3189 Get_First_Interp (N, Index, It);
3191 while Present (It.Typ) loop
3192 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
3194 if Analyzed (N) then
3195 Error_Msg_N ("ambiguous operand in fixed operation", N);
3197 Resolve (N, Standard_Integer);
3200 elsif Is_Fixed_Point_Type (It.Typ) then
3202 if Analyzed (N) then
3203 Error_Msg_N ("ambiguous operand in fixed operation", N);
3205 Resolve (N, It.Typ);
3209 Get_Next_Interp (Index, It);
3212 -- Reanalyze the literal with the fixed type of the context.
3213 -- If context is Universal_Fixed, we are within a conversion,
3214 -- leave the literal as a universal real because there is no
3215 -- usable fixed type, and the target of the conversion plays
3216 -- no role in the resolution.
3229 if B_Typ = Universal_Fixed
3230 and then Nkind (Op2) = N_Real_Literal
3232 T2 := Universal_Real;
3237 Set_Analyzed (Op2, False);
3244 end Set_Mixed_Mode_Operand;
3246 ----------------------
3247 -- Set_Operand_Type --
3248 ----------------------
3250 procedure Set_Operand_Type (N : Node_Id) is
3252 if Etype (N) = Universal_Integer
3253 or else Etype (N) = Universal_Real
3257 end Set_Operand_Type;
3259 -- Start of processing for Resolve_Arithmetic_Op
3262 if Comes_From_Source (N)
3263 and then Ekind (Entity (N)) = E_Function
3264 and then Is_Imported (Entity (N))
3265 and then Is_Intrinsic_Subprogram (Entity (N))
3267 Resolve_Intrinsic_Operator (N, Typ);
3270 -- Special-case for mixed-mode universal expressions or fixed point
3271 -- type operation: each argument is resolved separately. The same
3272 -- treatment is required if one of the operands of a fixed point
3273 -- operation is universal real, since in this case we don't do a
3274 -- conversion to a specific fixed-point type (instead the expander
3275 -- takes care of the case).
3277 elsif (B_Typ = Universal_Integer
3278 or else B_Typ = Universal_Real)
3279 and then Present (Universal_Interpretation (L))
3280 and then Present (Universal_Interpretation (R))
3282 Resolve (L, Universal_Interpretation (L));
3283 Resolve (R, Universal_Interpretation (R));
3284 Set_Etype (N, B_Typ);
3286 elsif (B_Typ = Universal_Real
3287 or else Etype (N) = Universal_Fixed
3288 or else (Etype (N) = Any_Fixed
3289 and then Is_Fixed_Point_Type (B_Typ))
3290 or else (Is_Fixed_Point_Type (B_Typ)
3291 and then (Is_Integer_Or_Universal (L)
3293 Is_Integer_Or_Universal (R))))
3294 and then (Nkind (N) = N_Op_Multiply or else
3295 Nkind (N) = N_Op_Divide)
3297 if TL = Universal_Integer or else TR = Universal_Integer then
3298 Check_For_Visible_Operator (N, B_Typ);
3301 -- If context is a fixed type and one operand is integer, the
3302 -- other is resolved with the type of the context.
3304 if Is_Fixed_Point_Type (B_Typ)
3305 and then (Base_Type (TL) = Base_Type (Standard_Integer)
3306 or else TL = Universal_Integer)
3311 elsif Is_Fixed_Point_Type (B_Typ)
3312 and then (Base_Type (TR) = Base_Type (Standard_Integer)
3313 or else TR = Universal_Integer)
3319 Set_Mixed_Mode_Operand (L, TR);
3320 Set_Mixed_Mode_Operand (R, TL);
3323 if Etype (N) = Universal_Fixed
3324 or else Etype (N) = Any_Fixed
3326 if B_Typ = Universal_Fixed
3327 and then Nkind (Parent (N)) /= N_Type_Conversion
3328 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3331 ("type cannot be determined from context!", N);
3333 ("\explicit conversion to result type required", N);
3335 Set_Etype (L, Any_Type);
3336 Set_Etype (R, Any_Type);
3339 if Ada_Version = Ada_83
3340 and then Etype (N) = Universal_Fixed
3341 and then Nkind (Parent (N)) /= N_Type_Conversion
3342 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3345 ("(Ada 83) fixed-point operation " &
3346 "needs explicit conversion",
3350 Set_Etype (N, B_Typ);
3353 elsif Is_Fixed_Point_Type (B_Typ)
3354 and then (Is_Integer_Or_Universal (L)
3355 or else Nkind (L) = N_Real_Literal
3356 or else Nkind (R) = N_Real_Literal
3358 Is_Integer_Or_Universal (R))
3360 Set_Etype (N, B_Typ);
3362 elsif Etype (N) = Any_Fixed then
3364 -- If no previous errors, this is only possible if one operand
3365 -- is overloaded and the context is universal. Resolve as such.
3367 Set_Etype (N, B_Typ);
3371 if (TL = Universal_Integer or else TL = Universal_Real)
3372 and then (TR = Universal_Integer or else TR = Universal_Real)
3374 Check_For_Visible_Operator (N, B_Typ);
3377 -- If the context is Universal_Fixed and the operands are also
3378 -- universal fixed, this is an error, unless there is only one
3379 -- applicable fixed_point type (usually duration).
3381 if B_Typ = Universal_Fixed
3382 and then Etype (L) = Universal_Fixed
3384 T := Unique_Fixed_Point_Type (N);
3386 if T = Any_Type then
3399 -- If one of the arguments was resolved to a non-universal type.
3400 -- label the result of the operation itself with the same type.
3401 -- Do the same for the universal argument, if any.
3403 T := Intersect_Types (L, R);
3404 Set_Etype (N, Base_Type (T));
3405 Set_Operand_Type (L);
3406 Set_Operand_Type (R);
3409 Generate_Operator_Reference (N, Typ);
3410 Eval_Arithmetic_Op (N);
3412 -- Set overflow and division checking bit. Much cleverer code needed
3413 -- here eventually and perhaps the Resolve routines should be separated
3414 -- for the various arithmetic operations, since they will need
3415 -- different processing. ???
3417 if Nkind (N) in N_Op then
3418 if not Overflow_Checks_Suppressed (Etype (N)) then
3419 Enable_Overflow_Check (N);
3422 -- Give warning if explicit division by zero
3424 if (Nkind (N) = N_Op_Divide
3425 or else Nkind (N) = N_Op_Rem
3426 or else Nkind (N) = N_Op_Mod)
3427 and then not Division_Checks_Suppressed (Etype (N))
3429 Rop := Right_Opnd (N);
3431 if Compile_Time_Known_Value (Rop)
3432 and then ((Is_Integer_Type (Etype (Rop))
3433 and then Expr_Value (Rop) = Uint_0)
3435 (Is_Real_Type (Etype (Rop))
3436 and then Expr_Value_R (Rop) = Ureal_0))
3438 Apply_Compile_Time_Constraint_Error
3439 (N, "division by zero?", CE_Divide_By_Zero,
3440 Loc => Sloc (Right_Opnd (N)));
3442 -- Otherwise just set the flag to check at run time
3445 Set_Do_Division_Check (N);
3450 Check_Unset_Reference (L);
3451 Check_Unset_Reference (R);
3452 end Resolve_Arithmetic_Op;
3458 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
3459 Loc : constant Source_Ptr := Sloc (N);
3460 Subp : constant Node_Id := Name (N);
3469 -- The context imposes a unique interpretation with type Typ on
3470 -- a procedure or function call. Find the entity of the subprogram
3471 -- that yields the expected type, and propagate the corresponding
3472 -- formal constraints on the actuals. The caller has established
3473 -- that an interpretation exists, and emitted an error if not unique.
3475 -- First deal with the case of a call to an access-to-subprogram,
3476 -- dereference made explicit in Analyze_Call.
3478 if Ekind (Etype (Subp)) = E_Subprogram_Type then
3479 if not Is_Overloaded (Subp) then
3480 Nam := Etype (Subp);
3483 -- Find the interpretation whose type (a subprogram type)
3484 -- has a return type that is compatible with the context.
3485 -- Analysis of the node has established that one exists.
3487 Get_First_Interp (Subp, I, It);
3490 while Present (It.Typ) loop
3491 if Covers (Typ, Etype (It.Typ)) then
3496 Get_Next_Interp (I, It);
3500 raise Program_Error;
3504 -- If the prefix is not an entity, then resolve it
3506 if not Is_Entity_Name (Subp) then
3507 Resolve (Subp, Nam);
3510 -- For an indirect call, we always invalidate checks, since we
3511 -- do not know whether the subprogram is local or global. Yes
3512 -- we could do better here, e.g. by knowing that there are no
3513 -- local subprograms, but it does not seem worth the effort.
3514 -- Similarly, we kill al knowledge of current constant values.
3516 Kill_Current_Values;
3518 -- If this is a procedure call which is really an entry call, do
3519 -- the conversion of the procedure call to an entry call. Protected
3520 -- operations use the same circuitry because the name in the call
3521 -- can be an arbitrary expression with special resolution rules.
3523 elsif Nkind (Subp) = N_Selected_Component
3524 or else Nkind (Subp) = N_Indexed_Component
3525 or else (Is_Entity_Name (Subp)
3526 and then Ekind (Entity (Subp)) = E_Entry)
3528 Resolve_Entry_Call (N, Typ);
3529 Check_Elab_Call (N);
3531 -- Kill checks and constant values, as above for indirect case
3532 -- Who knows what happens when another task is activated?
3534 Kill_Current_Values;
3537 -- Normal subprogram call with name established in Resolve
3539 elsif not (Is_Type (Entity (Subp))) then
3540 Nam := Entity (Subp);
3541 Set_Entity_With_Style_Check (Subp, Nam);
3542 Generate_Reference (Nam, Subp);
3544 -- Otherwise we must have the case of an overloaded call
3547 pragma Assert (Is_Overloaded (Subp));
3548 Nam := Empty; -- We know that it will be assigned in loop below.
3550 Get_First_Interp (Subp, I, It);
3552 while Present (It.Typ) loop
3553 if Covers (Typ, It.Typ) then
3555 Set_Entity_With_Style_Check (Subp, Nam);
3556 Generate_Reference (Nam, Subp);
3560 Get_Next_Interp (I, It);
3564 -- Check that a call to Current_Task does not occur in an entry body
3566 if Is_RTE (Nam, RE_Current_Task) then
3576 if Nkind (P) = N_Entry_Body then
3578 ("& should not be used in entry body ('R
'M C
.7(17))",
3586 -- Cannot call thread body directly
3588 if Is_Thread_Body (Nam) then
3589 Error_Msg_N ("cannot call thread
body directly
", N);
3592 -- If the subprogram is not global, then kill all checks. This is
3593 -- a bit conservative, since in many cases we could do better, but
3594 -- it is not worth the effort. Similarly, we kill constant values.
3595 -- However we do not need to do this for internal entities (unless
3596 -- they are inherited user-defined subprograms), since they are not
3597 -- in the business of molesting global values.
3599 if not Is_Library_Level_Entity (Nam)
3600 and then (Comes_From_Source (Nam)
3601 or else (Present (Alias (Nam))
3602 and then Comes_From_Source (Alias (Nam))))
3604 Kill_Current_Values;
3607 -- Check for call to obsolescent subprogram
3609 if Warn_On_Obsolescent_Feature
3610 and then Is_Subprogram (Nam)
3611 and then Is_Obsolescent (Nam)
3613 Error_Msg_NE ("call to obsolescent subprogram
&?
", N, Nam);
3615 -- Output additional warning if present
3617 W := Obsolescent_Warning (Nam);
3620 Name_Buffer (1) := '|';
3621 Name_Buffer (2) := '?';
3624 -- Add characters to message, protecting all of them
3626 for J in 1 .. String_Length (Strval (W)) loop
3627 Add_Char_To_Name_Buffer (''');
3628 Add_Char_To_Name_Buffer
3629 (Get_Character (Get_String_Char (Strval (W), J)));
3632 Error_Msg_N (Name_Buffer (1 .. Name_Len), N);
3636 -- Check that a procedure call does not occur in the context
3637 -- of the entry call statement of a conditional or timed
3638 -- entry call. Note that the case of a call to a subprogram
3639 -- renaming of an entry will also be rejected. The test
3640 -- for N not being an N_Entry_Call_Statement is defensive,
3641 -- covering the possibility that the processing of entry
3642 -- calls might reach this point due to later modifications
3643 -- of the code above.
3645 if Nkind (Parent (N)) = N_Entry_Call_Alternative
3646 and then Nkind (N) /= N_Entry_Call_Statement
3647 and then Entry_Call_Statement (Parent (N)) = N
3649 Error_Msg_N ("entry call required
in select statement
", N);
3652 -- Check that this is not a call to a protected procedure or
3653 -- entry from within a protected function.
3655 if Ekind (Current_Scope) = E_Function
3656 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
3657 and then Ekind (Nam) /= E_Function
3658 and then Scope (Nam) = Scope (Current_Scope)
3660 Error_Msg_N ("within
protected function, protected " &
3661 "object
is constant", N);
3662 Error_Msg_N ("\cannot call operation that may modify it
", N);
3665 -- Freeze the subprogram name if not in default expression. Note
3666 -- that we freeze procedure calls as well as function calls.
3667 -- Procedure calls are not frozen according to the rules (RM
3668 -- 13.14(14)) because it is impossible to have a procedure call to
3669 -- a non-frozen procedure in pure Ada, but in the code that we
3670 -- generate in the expander, this rule needs extending because we
3671 -- can generate procedure calls that need freezing.
3673 if Is_Entity_Name (Subp) and then not In_Default_Expression then
3674 Freeze_Expression (Subp);
3677 -- For a predefined operator, the type of the result is the type
3678 -- imposed by context, except for a predefined operation on universal
3679 -- fixed. Otherwise The type of the call is the type returned by the
3680 -- subprogram being called.
3682 if Is_Predefined_Op (Nam) then
3683 if Etype (N) /= Universal_Fixed then
3687 -- If the subprogram returns an array type, and the context
3688 -- requires the component type of that array type, the node is
3689 -- really an indexing of the parameterless call. Resolve as such.
3690 -- A pathological case occurs when the type of the component is
3691 -- an access to the array type. In this case the call is truly
3694 elsif Needs_No_Actuals (Nam)
3696 ((Is_Array_Type (Etype (Nam))
3697 and then Covers (Typ, Component_Type (Etype (Nam))))
3698 or else (Is_Access_Type (Etype (Nam))
3699 and then Is_Array_Type (Designated_Type (Etype (Nam)))
3702 Component_Type (Designated_Type (Etype (Nam))))))
3705 Index_Node : Node_Id;
3707 Ret_Type : constant Entity_Id := Etype (Nam);
3710 if Is_Access_Type (Ret_Type)
3711 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
3714 ("cannot disambiguate
function call
and indexing
", N);
3716 New_Subp := Relocate_Node (Subp);
3717 Set_Entity (Subp, Nam);
3719 if Component_Type (Ret_Type) /= Any_Type then
3721 Make_Indexed_Component (Loc,
3723 Make_Function_Call (Loc,
3725 Expressions => Parameter_Associations (N));
3727 -- Since we are correcting a node classification error made
3728 -- by the parser, we call Replace rather than Rewrite.
3730 Replace (N, Index_Node);
3731 Set_Etype (Prefix (N), Ret_Type);
3733 Resolve_Indexed_Component (N, Typ);
3734 Check_Elab_Call (Prefix (N));
3742 Set_Etype (N, Etype (Nam));
3745 -- In the case where the call is to an overloaded subprogram, Analyze
3746 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
3747 -- such a case Normalize_Actuals needs to be called once more to order
3748 -- the actuals correctly. Otherwise the call will have the ordering
3749 -- given by the last overloaded subprogram whether this is the correct
3750 -- one being called or not.
3752 if Is_Overloaded (Subp) then
3753 Normalize_Actuals (N, Nam, False, Norm_OK);
3754 pragma Assert (Norm_OK);
3757 -- In any case, call is fully resolved now. Reset Overload flag, to
3758 -- prevent subsequent overload resolution if node is analyzed again
3760 Set_Is_Overloaded (Subp, False);
3761 Set_Is_Overloaded (N, False);
3763 -- If we are calling the current subprogram from immediately within
3764 -- its body, then that is the case where we can sometimes detect
3765 -- cases of infinite recursion statically. Do not try this in case
3766 -- restriction No_Recursion is in effect anyway.
3768 Scop := Current_Scope;
3771 and then not Restriction_Active (No_Recursion)
3772 and then Check_Infinite_Recursion (N)
3774 -- Here we detected and flagged an infinite recursion, so we do
3775 -- not need to test the case below for further warnings.
3779 -- If call is to immediately containing subprogram, then check for
3780 -- the case of a possible run-time detectable infinite recursion.
3783 while Scop /= Standard_Standard loop
3785 -- Although in general recursion is not statically checkable,
3786 -- the case of calling an immediately containing subprogram
3787 -- is easy to catch.
3789 Check_Restriction (No_Recursion, N);
3791 -- If the recursive call is to a parameterless procedure, then
3792 -- even if we can't statically detect infinite recursion, this
3793 -- is pretty suspicious, and we output a warning. Furthermore,
3794 -- we will try later to detect some cases here at run time by
3795 -- expanding checking code (see Detect_Infinite_Recursion in
3796 -- package Exp_Ch6).
3798 -- If the recursive call is within a handler we do not emit a
3799 -- warning, because this is a common idiom: loop until input
3800 -- is correct, catch illegal input in handler and restart.
3802 if No (First_Formal (Nam))
3803 and then Etype (Nam) = Standard_Void_Type
3804 and then not Error_Posted (N)
3805 and then Nkind (Parent (N)) /= N_Exception_Handler
3807 Set_Has_Recursive_Call (Nam);
3808 Error_Msg_N ("possible infinite recursion?
", N);
3809 Error_Msg_N ("Storage_Error may be raised
at run time?
", N);
3815 Scop := Scope (Scop);
3819 -- If subprogram name is a predefined operator, it was given in
3820 -- functional notation. Replace call node with operator node, so
3821 -- that actuals can be resolved appropriately.
3823 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
3824 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
3827 elsif Present (Alias (Nam))
3828 and then Is_Predefined_Op (Alias (Nam))
3830 Resolve_Actuals (N, Nam);
3831 Make_Call_Into_Operator (N, Typ, Alias (Nam));
3835 -- Create a transient scope if the resulting type requires it
3837 -- There are 3 notable exceptions: in init procs, the transient scope
3838 -- overhead is not needed and even incorrect due to the actual expansion
3839 -- of adjust calls; the second case is enumeration literal pseudo calls,
3840 -- the other case is intrinsic subprograms (Unchecked_Conversion and
3841 -- source information functions) that do not use the secondary stack
3842 -- even though the return type is unconstrained.
3844 -- If this is an initialization call for a type whose initialization
3845 -- uses the secondary stack, we also need to create a transient scope
3846 -- for it, precisely because we will not do it within the init proc
3850 and then Is_Type (Etype (Nam))
3851 and then Requires_Transient_Scope (Etype (Nam))
3852 and then Ekind (Nam) /= E_Enumeration_Literal
3853 and then not Within_Init_Proc
3854 and then not Is_Intrinsic_Subprogram (Nam)
3856 Establish_Transient_Scope
3857 (N, Sec_Stack => not Functions_Return_By_DSP_On_Target);
3859 -- If the call appears within the bounds of a loop, it will
3860 -- be rewritten and reanalyzed, nothing left to do here.
3862 if Nkind (N) /= N_Function_Call then
3866 elsif Is_Init_Proc (Nam)
3867 and then not Within_Init_Proc
3869 Check_Initialization_Call (N, Nam);
3872 -- A protected function cannot be called within the definition of the
3873 -- enclosing protected type.
3875 if Is_Protected_Type (Scope (Nam))
3876 and then In_Open_Scopes (Scope (Nam))
3877 and then not Has_Completion (Scope (Nam))
3880 ("& cannot be called before
end of protected definition
", N, Nam);
3883 -- Propagate interpretation to actuals, and add default expressions
3886 if Present (First_Formal (Nam)) then
3887 Resolve_Actuals (N, Nam);
3889 -- Overloaded literals are rewritten as function calls, for
3890 -- purpose of resolution. After resolution, we can replace
3891 -- the call with the literal itself.
3893 elsif Ekind (Nam) = E_Enumeration_Literal then
3894 Copy_Node (Subp, N);
3895 Resolve_Entity_Name (N, Typ);
3897 -- Avoid validation, since it is a static function call
3902 -- If the subprogram is a primitive operation, check whether or not
3903 -- it is a correct dispatching call.
3905 if Is_Overloadable (Nam)
3906 and then Is_Dispatching_Operation (Nam)
3908 Check_Dispatching_Call (N);
3910 elsif Is_Abstract (Nam)
3911 and then not In_Instance
3913 Error_Msg_NE ("cannot call
abstract subprogram
&!", N, Nam);
3916 if Is_Intrinsic_Subprogram (Nam) then
3917 Check_Intrinsic_Call (N);
3921 Check_Elab_Call (N);
3924 -------------------------------
3925 -- Resolve_Character_Literal --
3926 -------------------------------
3928 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
3929 B_Typ : constant Entity_Id := Base_Type (Typ);
3933 -- Verify that the character does belong to the type of the context
3935 Set_Etype (N, B_Typ);
3936 Eval_Character_Literal (N);
3938 -- Wide_Wide_Character literals must always be defined, since the set
3939 -- of wide wide character literals is complete, i.e. if a character
3940 -- literal is accepted by the parser, then it is OK for wide wide
3941 -- character (out of range character literals are rejected).
3943 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
3946 -- Always accept character literal for type Any_Character, which
3947 -- occurs in error situations and in comparisons of literals, both
3948 -- of which should accept all literals.
3950 elsif B_Typ = Any_Character then
3953 -- For Standard.Character or a type derived from it, check that
3954 -- the literal is in range
3956 elsif Root_Type (B_Typ) = Standard_Character then
3957 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
3961 -- For Standard.Wide_Character or a type derived from it, check
3962 -- that the literal is in range
3964 elsif Root_Type (B_Typ) = Standard_Wide_Character then
3965 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
3969 -- For Standard.Wide_Wide_Character or a type derived from it, we
3970 -- know the literal is in range, since the parser checked!
3972 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
3975 -- If the entity is already set, this has already been resolved in
3976 -- a generic context, or comes from expansion. Nothing else to do.
3978 elsif Present (Entity (N)) then
3981 -- Otherwise we have a user defined character type, and we can use
3982 -- the standard visibility mechanisms to locate the referenced entity
3985 C := Current_Entity (N);
3987 while Present (C) loop
3988 if Etype (C) = B_Typ then
3989 Set_Entity_With_Style_Check (N, C);
3990 Generate_Reference (C, N);
3998 -- If we fall through, then the literal does not match any of the
3999 -- entries of the enumeration type. This isn't just a constraint
4000 -- error situation, it is an illegality (see RM 4.2).
4003 ("character not defined
for }", N, First_Subtype (B_Typ));
4004 end Resolve_Character_Literal;
4006 ---------------------------
4007 -- Resolve_Comparison_Op --
4008 ---------------------------
4010 -- Context requires a boolean type, and plays no role in resolution.
4011 -- Processing identical to that for equality operators. The result
4012 -- type is the base type, which matters when pathological subtypes of
4013 -- booleans with limited ranges are used.
4015 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
4016 L : constant Node_Id := Left_Opnd (N);
4017 R : constant Node_Id := Right_Opnd (N);
4021 Check_Direct_Boolean_Op (N);
4023 -- If this is an intrinsic operation which is not predefined, use
4024 -- the types of its declared arguments to resolve the possibly
4025 -- overloaded operands. Otherwise the operands are unambiguous and
4026 -- specify the expected type.
4028 if Scope (Entity (N)) /= Standard_Standard then
4029 T := Etype (First_Entity (Entity (N)));
4031 T := Find_Unique_Type (L, R);
4033 if T = Any_Fixed then
4034 T := Unique_Fixed_Point_Type (L);
4038 Set_Etype (N, Base_Type (Typ));
4039 Generate_Reference (T, N, ' ');
4041 if T /= Any_Type then
4043 or else T = Any_Composite
4044 or else T = Any_Character
4046 if T = Any_Character then
4047 Ambiguous_Character (L);
4049 Error_Msg_N ("ambiguous operands
for comparison
", N);
4052 Set_Etype (N, Any_Type);
4058 Check_Unset_Reference (L);
4059 Check_Unset_Reference (R);
4060 Generate_Operator_Reference (N, T);
4061 Eval_Relational_Op (N);
4064 end Resolve_Comparison_Op;
4066 ------------------------------------
4067 -- Resolve_Conditional_Expression --
4068 ------------------------------------
4070 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
4071 Condition : constant Node_Id := First (Expressions (N));
4072 Then_Expr : constant Node_Id := Next (Condition);
4073 Else_Expr : constant Node_Id := Next (Then_Expr);
4076 Resolve (Condition, Standard_Boolean);
4077 Resolve (Then_Expr, Typ);
4078 Resolve (Else_Expr, Typ);
4081 Eval_Conditional_Expression (N);
4082 end Resolve_Conditional_Expression;
4084 -----------------------------------------
4085 -- Resolve_Discrete_Subtype_Indication --
4086 -----------------------------------------
4088 procedure Resolve_Discrete_Subtype_Indication
4096 Analyze (Subtype_Mark (N));
4097 S := Entity (Subtype_Mark (N));
4099 if Nkind (Constraint (N)) /= N_Range_Constraint then
4100 Error_Msg_N ("expect
range constraint
for discrete
type", N);
4101 Set_Etype (N, Any_Type);
4104 R := Range_Expression (Constraint (N));
4112 if Base_Type (S) /= Base_Type (Typ) then
4114 ("expect
subtype of }", N, First_Subtype (Typ));
4116 -- Rewrite the constraint as a range of Typ
4117 -- to allow compilation to proceed further.
4120 Rewrite (Low_Bound (R),
4121 Make_Attribute_Reference (Sloc (Low_Bound (R)),
4122 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4123 Attribute_Name => Name_First));
4124 Rewrite (High_Bound (R),
4125 Make_Attribute_Reference (Sloc (High_Bound (R)),
4126 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4127 Attribute_Name => Name_First));
4131 Set_Etype (N, Etype (R));
4133 -- Additionally, we must check that the bounds are compatible
4134 -- with the given subtype, which might be different from the
4135 -- type of the context.
4137 Apply_Range_Check (R, S);
4139 -- ??? If the above check statically detects a Constraint_Error
4140 -- it replaces the offending bound(s) of the range R with a
4141 -- Constraint_Error node. When the itype which uses these bounds
4142 -- is frozen the resulting call to Duplicate_Subexpr generates
4143 -- a new temporary for the bounds.
4145 -- Unfortunately there are other itypes that are also made depend
4146 -- on these bounds, so when Duplicate_Subexpr is called they get
4147 -- a forward reference to the newly created temporaries and Gigi
4148 -- aborts on such forward references. This is probably sign of a
4149 -- more fundamental problem somewhere else in either the order of
4150 -- itype freezing or the way certain itypes are constructed.
4152 -- To get around this problem we call Remove_Side_Effects right
4153 -- away if either bounds of R are a Constraint_Error.
4156 L : constant Node_Id := Low_Bound (R);
4157 H : constant Node_Id := High_Bound (R);
4160 if Nkind (L) = N_Raise_Constraint_Error then
4161 Remove_Side_Effects (L);
4164 if Nkind (H) = N_Raise_Constraint_Error then
4165 Remove_Side_Effects (H);
4169 Check_Unset_Reference (Low_Bound (R));
4170 Check_Unset_Reference (High_Bound (R));
4173 end Resolve_Discrete_Subtype_Indication;
4175 -------------------------
4176 -- Resolve_Entity_Name --
4177 -------------------------
4179 -- Used to resolve identifiers and expanded names
4181 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
4182 E : constant Entity_Id := Entity (N);
4185 -- If garbage from errors, set to Any_Type and return
4187 if No (E) and then Total_Errors_Detected /= 0 then
4188 Set_Etype (N, Any_Type);
4192 -- Replace named numbers by corresponding literals. Note that this is
4193 -- the one case where Resolve_Entity_Name must reset the Etype, since
4194 -- it is currently marked as universal.
4196 if Ekind (E) = E_Named_Integer then
4198 Eval_Named_Integer (N);
4200 elsif Ekind (E) = E_Named_Real then
4202 Eval_Named_Real (N);
4204 -- Allow use of subtype only if it is a concurrent type where we are
4205 -- currently inside the body. This will eventually be expanded
4206 -- into a call to Self (for tasks) or _object (for protected
4207 -- objects). Any other use of a subtype is invalid.
4209 elsif Is_Type (E) then
4210 if Is_Concurrent_Type (E)
4211 and then In_Open_Scopes (E)
4216 ("Invalid
use of subtype mark
in expression
or call
", N);
4219 -- Check discriminant use if entity is discriminant in current scope,
4220 -- i.e. discriminant of record or concurrent type currently being
4221 -- analyzed. Uses in corresponding body are unrestricted.
4223 elsif Ekind (E) = E_Discriminant
4224 and then Scope (E) = Current_Scope
4225 and then not Has_Completion (Current_Scope)
4227 Check_Discriminant_Use (N);
4229 -- A parameterless generic function cannot appear in a context that
4230 -- requires resolution.
4232 elsif Ekind (E) = E_Generic_Function then
4233 Error_Msg_N ("illegal
use of generic function", N);
4235 elsif Ekind (E) = E_Out_Parameter
4236 and then Ada_Version = Ada_83
4237 and then (Nkind (Parent (N)) in N_Op
4238 or else (Nkind (Parent (N)) = N_Assignment_Statement
4239 and then N = Expression (Parent (N)))
4240 or else Nkind (Parent (N)) = N_Explicit_Dereference)
4242 Error_Msg_N ("(Ada
83) illegal reading
of out parameter
", N);
4244 -- In all other cases, just do the possible static evaluation
4247 -- A deferred constant that appears in an expression must have
4248 -- a completion, unless it has been removed by in-place expansion
4251 if Ekind (E) = E_Constant
4252 and then Comes_From_Source (E)
4253 and then No (Constant_Value (E))
4254 and then Is_Frozen (Etype (E))
4255 and then not In_Default_Expression
4256 and then not Is_Imported (E)
4259 if No_Initialization (Parent (E))
4260 or else (Present (Full_View (E))
4261 and then No_Initialization (Parent (Full_View (E))))
4266 "deferred
constant is frozen before completion
", N);
4270 Eval_Entity_Name (N);
4272 end Resolve_Entity_Name;
4278 procedure Resolve_Entry (Entry_Name : Node_Id) is
4279 Loc : constant Source_Ptr := Sloc (Entry_Name);
4287 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
4288 -- If the bounds of the entry family being called depend on task
4289 -- discriminants, build a new index subtype where a discriminant is
4290 -- replaced with the value of the discriminant of the target task.
4291 -- The target task is the prefix of the entry name in the call.
4293 -----------------------
4294 -- Actual_Index_Type --
4295 -----------------------
4297 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
4298 Typ : constant Entity_Id := Entry_Index_Type (E);
4299 Tsk : constant Entity_Id := Scope (E);
4300 Lo : constant Node_Id := Type_Low_Bound (Typ);
4301 Hi : constant Node_Id := Type_High_Bound (Typ);
4304 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
4305 -- If the bound is given by a discriminant, replace with a reference
4306 -- to the discriminant of the same name in the target task.
4307 -- If the entry name is the target of a requeue statement and the
4308 -- entry is in the current protected object, the bound to be used
4309 -- is the discriminal of the object (see apply_range_checks for
4310 -- details of the transformation).
4312 -----------------------------
4313 -- Actual_Discriminant_Ref --
4314 -----------------------------
4316 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
4317 Typ : constant Entity_Id := Etype (Bound);
4321 Remove_Side_Effects (Bound);
4323 if not Is_Entity_Name (Bound)
4324 or else Ekind (Entity (Bound)) /= E_Discriminant
4328 elsif Is_Protected_Type (Tsk)
4329 and then In_Open_Scopes (Tsk)
4330 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
4332 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
4336 Make_Selected_Component (Loc,
4337 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
4338 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
4343 end Actual_Discriminant_Ref;
4345 -- Start of processing for Actual_Index_Type
4348 if not Has_Discriminants (Tsk)
4349 or else (not Is_Entity_Name (Lo)
4350 and then not Is_Entity_Name (Hi))
4352 return Entry_Index_Type (E);
4355 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
4356 Set_Etype (New_T, Base_Type (Typ));
4357 Set_Size_Info (New_T, Typ);
4358 Set_RM_Size (New_T, RM_Size (Typ));
4359 Set_Scalar_Range (New_T,
4360 Make_Range (Sloc (Entry_Name),
4361 Low_Bound => Actual_Discriminant_Ref (Lo),
4362 High_Bound => Actual_Discriminant_Ref (Hi)));
4366 end Actual_Index_Type;
4368 -- Start of processing of Resolve_Entry
4371 -- Find name of entry being called, and resolve prefix of name
4372 -- with its own type. The prefix can be overloaded, and the name
4373 -- and signature of the entry must be taken into account.
4375 if Nkind (Entry_Name) = N_Indexed_Component then
4377 -- Case of dealing with entry family within the current tasks
4379 E_Name := Prefix (Entry_Name);
4382 E_Name := Entry_Name;
4385 if Is_Entity_Name (E_Name) then
4386 -- Entry call to an entry (or entry family) in the current task.
4387 -- This is legal even though the task will deadlock. Rewrite as
4388 -- call to current task.
4390 -- This can also be a call to an entry in an enclosing task.
4391 -- If this is a single task, we have to retrieve its name,
4392 -- because the scope of the entry is the task type, not the
4393 -- object. If the enclosing task is a task type, the identity
4394 -- of the task is given by its own self variable.
4396 -- Finally this can be a requeue on an entry of the same task
4397 -- or protected object.
4399 S := Scope (Entity (E_Name));
4401 for J in reverse 0 .. Scope_Stack.Last loop
4403 if Is_Task_Type (Scope_Stack.Table (J).Entity)
4404 and then not Comes_From_Source (S)
4406 -- S is an enclosing task or protected object. The concurrent
4407 -- declaration has been converted into a type declaration, and
4408 -- the object itself has an object declaration that follows
4409 -- the type in the same declarative part.
4411 Tsk := Next_Entity (S);
4413 while Etype (Tsk) /= S loop
4420 elsif S = Scope_Stack.Table (J).Entity then
4422 -- Call to current task. Will be transformed into call to Self
4430 Make_Selected_Component (Loc,
4431 Prefix => New_Occurrence_Of (S, Loc),
4433 New_Occurrence_Of (Entity (E_Name), Loc));
4434 Rewrite (E_Name, New_N);
4437 elsif Nkind (Entry_Name) = N_Selected_Component
4438 and then Is_Overloaded (Prefix (Entry_Name))
4440 -- Use the entry name (which must be unique at this point) to
4441 -- find the prefix that returns the corresponding task type or
4445 Pref : constant Node_Id := Prefix (Entry_Name);
4446 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
4451 Get_First_Interp (Pref, I, It);
4453 while Present (It.Typ) loop
4455 if Scope (Ent) = It.Typ then
4456 Set_Etype (Pref, It.Typ);
4460 Get_Next_Interp (I, It);
4465 if Nkind (Entry_Name) = N_Selected_Component then
4466 Resolve (Prefix (Entry_Name));
4468 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4469 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4470 Resolve (Prefix (Prefix (Entry_Name)));
4471 Index := First (Expressions (Entry_Name));
4472 Resolve (Index, Entry_Index_Type (Nam));
4474 -- Up to this point the expression could have been the actual
4475 -- in a simple entry call, and be given by a named association.
4477 if Nkind (Index) = N_Parameter_Association then
4478 Error_Msg_N ("expect expression
for entry index
", Index);
4480 Apply_Range_Check (Index, Actual_Index_Type (Nam));
4485 ------------------------
4486 -- Resolve_Entry_Call --
4487 ------------------------
4489 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
4490 Entry_Name : constant Node_Id := Name (N);
4491 Loc : constant Source_Ptr := Sloc (Entry_Name);
4493 First_Named : Node_Id;
4500 -- We kill all checks here, because it does not seem worth the
4501 -- effort to do anything better, an entry call is a big operation.
4505 -- Processing of the name is similar for entry calls and protected
4506 -- operation calls. Once the entity is determined, we can complete
4507 -- the resolution of the actuals.
4509 -- The selector may be overloaded, in the case of a protected object
4510 -- with overloaded functions. The type of the context is used for
4513 if Nkind (Entry_Name) = N_Selected_Component
4514 and then Is_Overloaded (Selector_Name (Entry_Name))
4515 and then Typ /= Standard_Void_Type
4522 Get_First_Interp (Selector_Name (Entry_Name), I, It);
4524 while Present (It.Typ) loop
4526 if Covers (Typ, It.Typ) then
4527 Set_Entity (Selector_Name (Entry_Name), It.Nam);
4528 Set_Etype (Entry_Name, It.Typ);
4530 Generate_Reference (It.Typ, N, ' ');
4533 Get_Next_Interp (I, It);
4538 Resolve_Entry (Entry_Name);
4540 if Nkind (Entry_Name) = N_Selected_Component then
4542 -- Simple entry call
4544 Nam := Entity (Selector_Name (Entry_Name));
4545 Obj := Prefix (Entry_Name);
4546 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
4548 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4550 -- Call to member of entry family
4552 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4553 Obj := Prefix (Prefix (Entry_Name));
4554 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
4557 -- We cannot in general check the maximum depth of protected entry
4558 -- calls at compile time. But we can tell that any protected entry
4559 -- call at all violates a specified nesting depth of zero.
4561 if Is_Protected_Type (Scope (Nam)) then
4562 Check_Restriction (Max_Entry_Queue_Length, N);
4565 -- Use context type to disambiguate a protected function that can be
4566 -- called without actuals and that returns an array type, and where
4567 -- the argument list may be an indexing of the returned value.
4569 if Ekind (Nam) = E_Function
4570 and then Needs_No_Actuals (Nam)
4571 and then Present (Parameter_Associations (N))
4573 ((Is_Array_Type (Etype (Nam))
4574 and then Covers (Typ, Component_Type (Etype (Nam))))
4576 or else (Is_Access_Type (Etype (Nam))
4577 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4578 and then Covers (Typ,
4579 Component_Type (Designated_Type (Etype (Nam))))))
4582 Index_Node : Node_Id;
4586 Make_Indexed_Component (Loc,
4588 Make_Function_Call (Loc,
4589 Name => Relocate_Node (Entry_Name)),
4590 Expressions => Parameter_Associations (N));
4592 -- Since we are correcting a node classification error made by
4593 -- the parser, we call Replace rather than Rewrite.
4595 Replace (N, Index_Node);
4596 Set_Etype (Prefix (N), Etype (Nam));
4598 Resolve_Indexed_Component (N, Typ);
4603 -- The operation name may have been overloaded. Order the actuals
4604 -- according to the formals of the resolved entity, and set the
4605 -- return type to that of the operation.
4608 Normalize_Actuals (N, Nam, False, Norm_OK);
4609 pragma Assert (Norm_OK);
4610 Set_Etype (N, Etype (Nam));
4613 Resolve_Actuals (N, Nam);
4614 Generate_Reference (Nam, Entry_Name);
4616 if Ekind (Nam) = E_Entry
4617 or else Ekind (Nam) = E_Entry_Family
4619 Check_Potentially_Blocking_Operation (N);
4622 -- Verify that a procedure call cannot masquerade as an entry
4623 -- call where an entry call is expected.
4625 if Ekind (Nam) = E_Procedure then
4626 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4627 and then N = Entry_Call_Statement (Parent (N))
4629 Error_Msg_N ("entry call required
in select statement
", N);
4631 elsif Nkind (Parent (N)) = N_Triggering_Alternative
4632 and then N = Triggering_Statement (Parent (N))
4634 Error_Msg_N ("triggering statement cannot be
procedure call
", N);
4636 elsif Ekind (Scope (Nam)) = E_Task_Type
4637 and then not In_Open_Scopes (Scope (Nam))
4639 Error_Msg_N ("Task has no
entry with this name
", Entry_Name);
4643 -- After resolution, entry calls and protected procedure calls
4644 -- are changed into entry calls, for expansion. The structure
4645 -- of the node does not change, so it can safely be done in place.
4646 -- Protected function calls must keep their structure because they
4647 -- are subexpressions.
4649 if Ekind (Nam) /= E_Function then
4651 -- A protected operation that is not a function may modify the
4652 -- corresponding object, and cannot apply to a constant.
4653 -- If this is an internal call, the prefix is the type itself.
4655 if Is_Protected_Type (Scope (Nam))
4656 and then not Is_Variable (Obj)
4657 and then (not Is_Entity_Name (Obj)
4658 or else not Is_Type (Entity (Obj)))
4661 ("prefix
of protected procedure or entry call must be variable
",
4665 Actuals := Parameter_Associations (N);
4666 First_Named := First_Named_Actual (N);
4669 Make_Entry_Call_Statement (Loc,
4671 Parameter_Associations => Actuals));
4673 Set_First_Named_Actual (N, First_Named);
4674 Set_Analyzed (N, True);
4676 -- Protected functions can return on the secondary stack, in which
4677 -- case we must trigger the transient scope mechanism
4679 elsif Expander_Active
4680 and then Requires_Transient_Scope (Etype (Nam))
4682 Establish_Transient_Scope (N,
4683 Sec_Stack => not Functions_Return_By_DSP_On_Target);
4685 end Resolve_Entry_Call;
4687 -------------------------
4688 -- Resolve_Equality_Op --
4689 -------------------------
4691 -- Both arguments must have the same type, and the boolean context
4692 -- does not participate in the resolution. The first pass verifies
4693 -- that the interpretation is not ambiguous, and the type of the left
4694 -- argument is correctly set, or is Any_Type in case of ambiguity.
4695 -- If both arguments are strings or aggregates, allocators, or Null,
4696 -- they are ambiguous even though they carry a single (universal) type.
4697 -- Diagnose this case here.
4699 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
4700 L : constant Node_Id := Left_Opnd (N);
4701 R : constant Node_Id := Right_Opnd (N);
4702 T : Entity_Id := Find_Unique_Type (L, R);
4704 function Find_Unique_Access_Type return Entity_Id;
4705 -- In the case of allocators, make a last-ditch attempt to find a single
4706 -- access type with the right designated type. This is semantically
4707 -- dubious, and of no interest to any real code, but c48008a makes it
4710 -----------------------------
4711 -- Find_Unique_Access_Type --
4712 -----------------------------
4714 function Find_Unique_Access_Type return Entity_Id is
4717 S : Entity_Id := Current_Scope;
4720 if Ekind (Etype (R)) = E_Allocator_Type then
4721 Acc := Designated_Type (Etype (R));
4723 elsif Ekind (Etype (L)) = E_Allocator_Type then
4724 Acc := Designated_Type (Etype (L));
4730 while S /= Standard_Standard loop
4731 E := First_Entity (S);
4733 while Present (E) loop
4736 and then Is_Access_Type (E)
4737 and then Ekind (E) /= E_Allocator_Type
4738 and then Designated_Type (E) = Base_Type (Acc)
4750 end Find_Unique_Access_Type;
4752 -- Start of processing for Resolve_Equality_Op
4755 Check_Direct_Boolean_Op (N);
4757 Set_Etype (N, Base_Type (Typ));
4758 Generate_Reference (T, N, ' ');
4760 if T = Any_Fixed then
4761 T := Unique_Fixed_Point_Type (L);
4764 if T /= Any_Type then
4767 or else T = Any_Composite
4768 or else T = Any_Character
4771 if T = Any_Character then
4772 Ambiguous_Character (L);
4774 Error_Msg_N ("ambiguous operands
for equality
", N);
4777 Set_Etype (N, Any_Type);
4780 elsif T = Any_Access
4781 or else Ekind (T) = E_Allocator_Type
4783 T := Find_Unique_Access_Type;
4786 Error_Msg_N ("ambiguous operands
for equality
", N);
4787 Set_Etype (N, Any_Type);
4795 if Warn_On_Redundant_Constructs
4796 and then Comes_From_Source (N)
4797 and then Is_Entity_Name (R)
4798 and then Entity (R) = Standard_True
4799 and then Comes_From_Source (R)
4801 Error_Msg_N ("comparison
with True is redundant?
", R);
4804 Check_Unset_Reference (L);
4805 Check_Unset_Reference (R);
4806 Generate_Operator_Reference (N, T);
4808 -- If this is an inequality, it may be the implicit inequality
4809 -- created for a user-defined operation, in which case the corres-
4810 -- ponding equality operation is not intrinsic, and the operation
4811 -- cannot be constant-folded. Else fold.
4813 if Nkind (N) = N_Op_Eq
4814 or else Comes_From_Source (Entity (N))
4815 or else Ekind (Entity (N)) = E_Operator
4816 or else Is_Intrinsic_Subprogram
4817 (Corresponding_Equality (Entity (N)))
4819 Eval_Relational_Op (N);
4820 elsif Nkind (N) = N_Op_Ne
4821 and then Is_Abstract (Entity (N))
4823 Error_Msg_NE ("cannot call
abstract subprogram
&!", N, Entity (N));
4826 end Resolve_Equality_Op;
4828 ----------------------------------
4829 -- Resolve_Explicit_Dereference --
4830 ----------------------------------
4832 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
4833 Loc : constant Source_Ptr := Sloc (N);
4835 P : constant Node_Id := Prefix (N);
4840 -- Now that we know the type, check that this is not a
4841 -- dereference of an uncompleted type. Note that this
4842 -- is not entirely correct, because dereferences of
4843 -- private types are legal in default expressions.
4844 -- This consideration also applies to similar checks
4845 -- for allocators, qualified expressions, and type
4848 Check_Fully_Declared (Typ, N);
4850 if Is_Overloaded (P) then
4852 -- Use the context type to select the prefix that has the
4853 -- correct designated type.
4855 Get_First_Interp (P, I, It);
4856 while Present (It.Typ) loop
4857 exit when Is_Access_Type (It.Typ)
4858 and then Covers (Typ, Designated_Type (It.Typ));
4860 Get_Next_Interp (I, It);
4863 if Present (It.Typ) then
4864 Resolve (P, It.Typ);
4866 -- If no interpretation covers the designated type of the
4867 -- prefix, this is the pathological case where not all
4868 -- implementations of the prefix allow the interpretation
4869 -- of the node as a call. Now that the expected type is known,
4870 -- Remove other interpretations from prefix, rewrite it as
4871 -- a call, and resolve again, so that the proper call node
4874 Get_First_Interp (P, I, It);
4875 while Present (It.Typ) loop
4876 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
4880 Get_Next_Interp (I, It);
4884 Make_Function_Call (Loc,
4886 Make_Explicit_Dereference (Loc,
4888 Parameter_Associations => New_List);
4890 Save_Interps (N, New_N);
4892 Analyze_And_Resolve (N, Typ);
4896 Set_Etype (N, Designated_Type (It.Typ));
4902 if Is_Access_Type (Etype (P)) then
4903 Apply_Access_Check (N);
4906 -- If the designated type is a packed unconstrained array type,
4907 -- and the explicit dereference is not in the context of an
4908 -- attribute reference, then we must compute and set the actual
4909 -- subtype, since it is needed by Gigi. The reason we exclude
4910 -- the attribute case is that this is handled fine by Gigi, and
4911 -- in fact we use such attributes to build the actual subtype.
4912 -- We also exclude generated code (which builds actual subtypes
4913 -- directly if they are needed).
4915 if Is_Array_Type (Etype (N))
4916 and then Is_Packed (Etype (N))
4917 and then not Is_Constrained (Etype (N))
4918 and then Nkind (Parent (N)) /= N_Attribute_Reference
4919 and then Comes_From_Source (N)
4921 Set_Etype (N, Get_Actual_Subtype (N));
4924 -- Note: there is no Eval processing required for an explicit
4925 -- deference, because the type is known to be an allocators, and
4926 -- allocator expressions can never be static.
4928 end Resolve_Explicit_Dereference;
4930 -------------------------------
4931 -- Resolve_Indexed_Component --
4932 -------------------------------
4934 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
4935 Name : constant Node_Id := Prefix (N);
4937 Array_Type : Entity_Id := Empty; -- to prevent junk warning
4941 if Is_Overloaded (Name) then
4943 -- Use the context type to select the prefix that yields the
4944 -- correct component type.
4949 I1 : Interp_Index := 0;
4950 P : constant Node_Id := Prefix (N);
4951 Found : Boolean := False;
4954 Get_First_Interp (P, I, It);
4956 while Present (It.Typ) loop
4958 if (Is_Array_Type (It.Typ)
4959 and then Covers (Typ, Component_Type (It.Typ)))
4960 or else (Is_Access_Type (It.Typ)
4961 and then Is_Array_Type (Designated_Type (It.Typ))
4963 (Typ, Component_Type (Designated_Type (It.Typ))))
4966 It := Disambiguate (P, I1, I, Any_Type);
4968 if It = No_Interp then
4969 Error_Msg_N ("ambiguous prefix
for indexing
", N);
4975 Array_Type := It.Typ;
4981 Array_Type := It.Typ;
4986 Get_Next_Interp (I, It);
4991 Array_Type := Etype (Name);
4994 Resolve (Name, Array_Type);
4995 Array_Type := Get_Actual_Subtype_If_Available (Name);
4997 -- If prefix is access type, dereference to get real array type.
4998 -- Note: we do not apply an access check because the expander always
4999 -- introduces an explicit dereference, and the check will happen there.
5001 if Is_Access_Type (Array_Type) then
5002 Array_Type := Designated_Type (Array_Type);
5005 -- If name was overloaded, set component type correctly now
5007 Set_Etype (N, Component_Type (Array_Type));
5009 Index := First_Index (Array_Type);
5010 Expr := First (Expressions (N));
5012 -- The prefix may have resolved to a string literal, in which case
5013 -- its etype has a special representation. This is only possible
5014 -- currently if the prefix is a static concatenation, written in
5015 -- functional notation.
5017 if Ekind (Array_Type) = E_String_Literal_Subtype then
5018 Resolve (Expr, Standard_Positive);
5021 while Present (Index) and Present (Expr) loop
5022 Resolve (Expr, Etype (Index));
5023 Check_Unset_Reference (Expr);
5025 if Is_Scalar_Type (Etype (Expr)) then
5026 Apply_Scalar_Range_Check (Expr, Etype (Index));
5028 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
5036 Eval_Indexed_Component (N);
5037 end Resolve_Indexed_Component;
5039 -----------------------------
5040 -- Resolve_Integer_Literal --
5041 -----------------------------
5043 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
5046 Eval_Integer_Literal (N);
5047 end Resolve_Integer_Literal;
5049 --------------------------------
5050 -- Resolve_Intrinsic_Operator --
5051 --------------------------------
5053 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
5054 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
5062 while Scope (Op) /= Standard_Standard loop
5064 pragma Assert (Present (Op));
5068 Set_Is_Overloaded (N, False);
5070 -- If the operand type is private, rewrite with suitable
5071 -- conversions on the operands and the result, to expose
5072 -- the proper underlying numeric type.
5074 if Is_Private_Type (Typ) then
5075 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
5077 if Nkind (N) = N_Op_Expon then
5078 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
5080 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5083 Save_Interps (Left_Opnd (N), Expression (Arg1));
5084 Save_Interps (Right_Opnd (N), Expression (Arg2));
5086 Set_Left_Opnd (N, Arg1);
5087 Set_Right_Opnd (N, Arg2);
5089 Set_Etype (N, Btyp);
5090 Rewrite (N, Unchecked_Convert_To (Typ, N));
5093 elsif Typ /= Etype (Left_Opnd (N))
5094 or else Typ /= Etype (Right_Opnd (N))
5096 -- Add explicit conversion where needed, and save interpretations
5097 -- in case operands are overloaded.
5099 Arg1 := Convert_To (Typ, Left_Opnd (N));
5100 Arg2 := Convert_To (Typ, Right_Opnd (N));
5102 if Nkind (Arg1) = N_Type_Conversion then
5103 Save_Interps (Left_Opnd (N), Expression (Arg1));
5105 Save_Interps (Left_Opnd (N), Arg1);
5108 if Nkind (Arg2) = N_Type_Conversion then
5109 Save_Interps (Right_Opnd (N), Expression (Arg2));
5111 Save_Interps (Right_Opnd (N), Arg2);
5114 Rewrite (Left_Opnd (N), Arg1);
5115 Rewrite (Right_Opnd (N), Arg2);
5118 Resolve_Arithmetic_Op (N, Typ);
5121 Resolve_Arithmetic_Op (N, Typ);
5123 end Resolve_Intrinsic_Operator;
5125 --------------------------------------
5126 -- Resolve_Intrinsic_Unary_Operator --
5127 --------------------------------------
5129 procedure Resolve_Intrinsic_Unary_Operator
5133 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
5140 while Scope (Op) /= Standard_Standard loop
5142 pragma Assert (Present (Op));
5147 if Is_Private_Type (Typ) then
5148 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5149 Save_Interps (Right_Opnd (N), Expression (Arg2));
5151 Set_Right_Opnd (N, Arg2);
5153 Set_Etype (N, Btyp);
5154 Rewrite (N, Unchecked_Convert_To (Typ, N));
5158 Resolve_Unary_Op (N, Typ);
5160 end Resolve_Intrinsic_Unary_Operator;
5162 ------------------------
5163 -- Resolve_Logical_Op --
5164 ------------------------
5166 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
5170 Check_Direct_Boolean_Op (N);
5172 -- Predefined operations on scalar types yield the base type. On
5173 -- the other hand, logical operations on arrays yield the type of
5174 -- the arguments (and the context).
5176 if Is_Array_Type (Typ) then
5179 B_Typ := Base_Type (Typ);
5182 -- The following test is required because the operands of the operation
5183 -- may be literals, in which case the resulting type appears to be
5184 -- compatible with a signed integer type, when in fact it is compatible
5185 -- only with modular types. If the context itself is universal, the
5186 -- operation is illegal.
5188 if not Valid_Boolean_Arg (Typ) then
5189 Error_Msg_N ("invalid context
for logical operation
", N);
5190 Set_Etype (N, Any_Type);
5193 elsif Typ = Any_Modular then
5195 ("no modular
type available
in this context
", N);
5196 Set_Etype (N, Any_Type);
5198 elsif Is_Modular_Integer_Type (Typ)
5199 and then Etype (Left_Opnd (N)) = Universal_Integer
5200 and then Etype (Right_Opnd (N)) = Universal_Integer
5202 Check_For_Visible_Operator (N, B_Typ);
5205 Resolve (Left_Opnd (N), B_Typ);
5206 Resolve (Right_Opnd (N), B_Typ);
5208 Check_Unset_Reference (Left_Opnd (N));
5209 Check_Unset_Reference (Right_Opnd (N));
5211 Set_Etype (N, B_Typ);
5212 Generate_Operator_Reference (N, B_Typ);
5213 Eval_Logical_Op (N);
5214 end Resolve_Logical_Op;
5216 ---------------------------
5217 -- Resolve_Membership_Op --
5218 ---------------------------
5220 -- The context can only be a boolean type, and does not determine
5221 -- the arguments. Arguments should be unambiguous, but the preference
5222 -- rule for universal types applies.
5224 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
5225 pragma Warnings (Off, Typ);
5227 L : constant Node_Id := Left_Opnd (N);
5228 R : constant Node_Id := Right_Opnd (N);
5232 if L = Error or else R = Error then
5236 if not Is_Overloaded (R)
5238 (Etype (R) = Universal_Integer or else
5239 Etype (R) = Universal_Real)
5240 and then Is_Overloaded (L)
5244 T := Intersect_Types (L, R);
5248 Check_Unset_Reference (L);
5250 if Nkind (R) = N_Range
5251 and then not Is_Scalar_Type (T)
5253 Error_Msg_N ("scalar
type required
for range", R);
5256 if Is_Entity_Name (R) then
5257 Freeze_Expression (R);
5260 Check_Unset_Reference (R);
5263 Eval_Membership_Op (N);
5264 end Resolve_Membership_Op;
5270 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
5272 -- Handle restriction against anonymous null access values
5273 -- This restriction can be turned off using -gnatdh.
5275 -- Ada 2005 (AI-231): Remove restriction
5277 if Ada_Version < Ada_05
5278 and then not Debug_Flag_J
5279 and then Ekind (Typ) = E_Anonymous_Access_Type
5280 and then Comes_From_Source (N)
5282 -- In the common case of a call which uses an explicitly null
5283 -- value for an access parameter, give specialized error msg
5285 if Nkind (Parent (N)) = N_Procedure_Call_Statement
5287 Nkind (Parent (N)) = N_Function_Call
5290 ("null is not allowed as argument
for an
access parameter
", N);
5292 -- Standard message for all other cases (are there any?)
5296 ("null cannot be
of an anonymous
access type", N);
5300 -- In a distributed context, null for a remote access to subprogram
5301 -- may need to be replaced with a special record aggregate. In this
5302 -- case, return after having done the transformation.
5304 if (Ekind (Typ) = E_Record_Type
5305 or else Is_Remote_Access_To_Subprogram_Type (Typ))
5306 and then Remote_AST_Null_Value (N, Typ)
5311 -- The null literal takes its type from the context
5316 -----------------------
5317 -- Resolve_Op_Concat --
5318 -----------------------
5320 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
5321 Btyp : constant Entity_Id := Base_Type (Typ);
5322 Op1 : constant Node_Id := Left_Opnd (N);
5323 Op2 : constant Node_Id := Right_Opnd (N);
5325 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean);
5326 -- Internal procedure to resolve one operand of concatenation operator.
5327 -- The operand is either of the array type or of the component type.
5328 -- If the operand is an aggregate, and the component type is composite,
5329 -- this is ambiguous if component type has aggregates.
5331 -------------------------------
5332 -- Resolve_Concatenation_Arg --
5333 -------------------------------
5335 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean) is
5339 or else (not Is_Overloaded (Arg)
5340 and then Etype (Arg) /= Any_Composite
5341 and then Covers (Component_Type (Typ), Etype (Arg)))
5343 Resolve (Arg, Component_Type (Typ));
5345 Resolve (Arg, Btyp);
5348 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
5350 if Nkind (Arg) = N_Aggregate
5351 and then Is_Composite_Type (Component_Type (Typ))
5353 if Is_Private_Type (Component_Type (Typ)) then
5354 Resolve (Arg, Btyp);
5357 Error_Msg_N ("ambiguous aggregate must be qualified
", Arg);
5358 Set_Etype (Arg, Any_Type);
5362 if Is_Overloaded (Arg)
5363 and then Has_Compatible_Type (Arg, Typ)
5364 and then Etype (Arg) /= Any_Type
5366 Error_Msg_N ("ambiguous operand
for concatenation
!", Arg);
5373 Get_First_Interp (Arg, I, It);
5375 while Present (It.Nam) loop
5377 if Base_Type (Etype (It.Nam)) = Base_Type (Typ)
5378 or else Base_Type (Etype (It.Nam)) =
5379 Base_Type (Component_Type (Typ))
5381 Error_Msg_Sloc := Sloc (It.Nam);
5382 Error_Msg_N ("\possible interpretation#
", Arg);
5385 Get_Next_Interp (I, It);
5390 Resolve (Arg, Component_Type (Typ));
5392 if Nkind (Arg) = N_String_Literal then
5393 Set_Etype (Arg, Component_Type (Typ));
5396 if Arg = Left_Opnd (N) then
5397 Set_Is_Component_Left_Opnd (N);
5399 Set_Is_Component_Right_Opnd (N);
5404 Resolve (Arg, Btyp);
5407 Check_Unset_Reference (Arg);
5408 end Resolve_Concatenation_Arg;
5410 -- Start of processing for Resolve_Op_Concat
5413 Set_Etype (N, Btyp);
5415 if Is_Limited_Composite (Btyp) then
5416 Error_Msg_N ("concatenation
not available
for limited array", N);
5417 Explain_Limited_Type (Btyp, N);
5420 -- If the operands are themselves concatenations, resolve them as
5421 -- such directly. This removes several layers of recursion and allows
5422 -- GNAT to handle larger multiple concatenations.
5424 if Nkind (Op1) = N_Op_Concat
5425 and then not Is_Array_Type (Component_Type (Typ))
5426 and then Entity (Op1) = Entity (N)
5428 Resolve_Op_Concat (Op1, Typ);
5430 Resolve_Concatenation_Arg
5431 (Op1, Is_Component_Left_Opnd (N));
5434 if Nkind (Op2) = N_Op_Concat
5435 and then not Is_Array_Type (Component_Type (Typ))
5436 and then Entity (Op2) = Entity (N)
5438 Resolve_Op_Concat (Op2, Typ);
5440 Resolve_Concatenation_Arg
5441 (Op2, Is_Component_Right_Opnd (N));
5444 Generate_Operator_Reference (N, Typ);
5446 if Is_String_Type (Typ) then
5447 Eval_Concatenation (N);
5450 -- If this is not a static concatenation, but the result is a
5451 -- string type (and not an array of strings) insure that static
5452 -- string operands have their subtypes properly constructed.
5454 if Nkind (N) /= N_String_Literal
5455 and then Is_Character_Type (Component_Type (Typ))
5457 Set_String_Literal_Subtype (Op1, Typ);
5458 Set_String_Literal_Subtype (Op2, Typ);
5460 end Resolve_Op_Concat;
5462 ----------------------
5463 -- Resolve_Op_Expon --
5464 ----------------------
5466 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
5467 B_Typ : constant Entity_Id := Base_Type (Typ);
5470 -- Catch attempts to do fixed-point exponentation with universal
5471 -- operands, which is a case where the illegality is not caught
5472 -- during normal operator analysis.
5474 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
5475 Error_Msg_N ("exponentiation
not available
for fixed point
", N);
5479 if Comes_From_Source (N)
5480 and then Ekind (Entity (N)) = E_Function
5481 and then Is_Imported (Entity (N))
5482 and then Is_Intrinsic_Subprogram (Entity (N))
5484 Resolve_Intrinsic_Operator (N, Typ);
5488 if Etype (Left_Opnd (N)) = Universal_Integer
5489 or else Etype (Left_Opnd (N)) = Universal_Real
5491 Check_For_Visible_Operator (N, B_Typ);
5494 -- We do the resolution using the base type, because intermediate values
5495 -- in expressions always are of the base type, not a subtype of it.
5497 Resolve (Left_Opnd (N), B_Typ);
5498 Resolve (Right_Opnd (N), Standard_Integer);
5500 Check_Unset_Reference (Left_Opnd (N));
5501 Check_Unset_Reference (Right_Opnd (N));
5503 Set_Etype (N, B_Typ);
5504 Generate_Operator_Reference (N, B_Typ);
5507 -- Set overflow checking bit. Much cleverer code needed here eventually
5508 -- and perhaps the Resolve routines should be separated for the various
5509 -- arithmetic operations, since they will need different processing. ???
5511 if Nkind (N) in N_Op then
5512 if not Overflow_Checks_Suppressed (Etype (N)) then
5513 Enable_Overflow_Check (N);
5516 end Resolve_Op_Expon;
5518 --------------------
5519 -- Resolve_Op_Not --
5520 --------------------
5522 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
5525 function Parent_Is_Boolean return Boolean;
5526 -- This function determines if the parent node is a boolean operator
5527 -- or operation (comparison op, membership test, or short circuit form)
5528 -- and the not in question is the left operand of this operation.
5529 -- Note that if the not is in parens, then false is returned.
5531 function Parent_Is_Boolean return Boolean is
5533 if Paren_Count (N) /= 0 then
5537 case Nkind (Parent (N)) is
5552 return Left_Opnd (Parent (N)) = N;
5558 end Parent_Is_Boolean;
5560 -- Start of processing for Resolve_Op_Not
5563 -- Predefined operations on scalar types yield the base type. On
5564 -- the other hand, logical operations on arrays yield the type of
5565 -- the arguments (and the context).
5567 if Is_Array_Type (Typ) then
5570 B_Typ := Base_Type (Typ);
5573 if not Valid_Boolean_Arg (Typ) then
5574 Error_Msg_N ("invalid operand
type for operator
&", N);
5575 Set_Etype (N, Any_Type);
5578 elsif Typ = Universal_Integer or else Typ = Any_Modular then
5579 if Parent_Is_Boolean then
5581 ("operand
of not must be enclosed
in parentheses
",
5585 ("no modular
type available
in this context
", N);
5588 Set_Etype (N, Any_Type);
5592 if not Is_Boolean_Type (Typ)
5593 and then Parent_Is_Boolean
5595 Error_Msg_N ("?
not expression should be parenthesized here
", N);
5598 Resolve (Right_Opnd (N), B_Typ);
5599 Check_Unset_Reference (Right_Opnd (N));
5600 Set_Etype (N, B_Typ);
5601 Generate_Operator_Reference (N, B_Typ);
5606 -----------------------------
5607 -- Resolve_Operator_Symbol --
5608 -----------------------------
5610 -- Nothing to be done, all resolved already
5612 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
5613 pragma Warnings (Off, N);
5614 pragma Warnings (Off, Typ);
5618 end Resolve_Operator_Symbol;
5620 ----------------------------------
5621 -- Resolve_Qualified_Expression --
5622 ----------------------------------
5624 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
5625 pragma Warnings (Off, Typ);
5627 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
5628 Expr : constant Node_Id := Expression (N);
5631 Resolve (Expr, Target_Typ);
5633 -- A qualified expression requires an exact match of the type,
5634 -- class-wide matching is not allowed.
5636 if Is_Class_Wide_Type (Target_Typ)
5637 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
5639 Wrong_Type (Expr, Target_Typ);
5642 -- If the target type is unconstrained, then we reset the type of
5643 -- the result from the type of the expression. For other cases, the
5644 -- actual subtype of the expression is the target type.
5646 if Is_Composite_Type (Target_Typ)
5647 and then not Is_Constrained (Target_Typ)
5649 Set_Etype (N, Etype (Expr));
5652 Eval_Qualified_Expression (N);
5653 end Resolve_Qualified_Expression;
5659 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
5660 L : constant Node_Id := Low_Bound (N);
5661 H : constant Node_Id := High_Bound (N);
5668 Check_Unset_Reference (L);
5669 Check_Unset_Reference (H);
5671 -- We have to check the bounds for being within the base range as
5672 -- required for a non-static context. Normally this is automatic
5673 -- and done as part of evaluating expressions, but the N_Range
5674 -- node is an exception, since in GNAT we consider this node to
5675 -- be a subexpression, even though in Ada it is not. The circuit
5676 -- in Sem_Eval could check for this, but that would put the test
5677 -- on the main evaluation path for expressions.
5679 Check_Non_Static_Context (L);
5680 Check_Non_Static_Context (H);
5682 -- If bounds are static, constant-fold them, so size computations
5683 -- are identical between front-end and back-end. Do not perform this
5684 -- transformation while analyzing generic units, as type information
5685 -- would then be lost when reanalyzing the constant node in the
5688 if Is_Discrete_Type (Typ) and then Expander_Active then
5689 if Is_OK_Static_Expression (L) then
5690 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
5693 if Is_OK_Static_Expression (H) then
5694 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
5699 --------------------------
5700 -- Resolve_Real_Literal --
5701 --------------------------
5703 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
5704 Actual_Typ : constant Entity_Id := Etype (N);
5707 -- Special processing for fixed-point literals to make sure that the
5708 -- value is an exact multiple of small where this is required. We
5709 -- skip this for the universal real case, and also for generic types.
5711 if Is_Fixed_Point_Type (Typ)
5712 and then Typ /= Universal_Fixed
5713 and then Typ /= Any_Fixed
5714 and then not Is_Generic_Type (Typ)
5717 Val : constant Ureal := Realval (N);
5718 Cintr : constant Ureal := Val / Small_Value (Typ);
5719 Cint : constant Uint := UR_Trunc (Cintr);
5720 Den : constant Uint := Norm_Den (Cintr);
5724 -- Case of literal is not an exact multiple of the Small
5728 -- For a source program literal for a decimal fixed-point
5729 -- type, this is statically illegal (RM 4.9(36)).
5731 if Is_Decimal_Fixed_Point_Type (Typ)
5732 and then Actual_Typ = Universal_Real
5733 and then Comes_From_Source (N)
5735 Error_Msg_N ("value has extraneous low order
digits", N);
5738 -- Generate a warning if literal from source
5740 if Is_Static_Expression (N)
5741 and then Warn_On_Bad_Fixed_Value
5744 ("static fixed
-point value
is not a multiple
of Small?
",
5748 -- Replace literal by a value that is the exact representation
5749 -- of a value of the type, i.e. a multiple of the small value,
5750 -- by truncation, since Machine_Rounds is false for all GNAT
5751 -- fixed-point types (RM 4.9(38)).
5753 Stat := Is_Static_Expression (N);
5755 Make_Real_Literal (Sloc (N),
5756 Realval => Small_Value (Typ) * Cint));
5758 Set_Is_Static_Expression (N, Stat);
5763 -- In all cases, set the corresponding integer field
5765 Set_Corresponding_Integer_Value (N, Cint);
5769 -- Now replace the actual type by the expected type as usual
5772 Eval_Real_Literal (N);
5773 end Resolve_Real_Literal;
5775 -----------------------
5776 -- Resolve_Reference --
5777 -----------------------
5779 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
5780 P : constant Node_Id := Prefix (N);
5783 -- Replace general access with specific type
5785 if Ekind (Etype (N)) = E_Allocator_Type then
5786 Set_Etype (N, Base_Type (Typ));
5789 Resolve (P, Designated_Type (Etype (N)));
5791 -- If we are taking the reference of a volatile entity, then treat
5792 -- it as a potential modification of this entity. This is much too
5793 -- conservative, but is necessary because remove side effects can
5794 -- result in transformations of normal assignments into reference
5795 -- sequences that otherwise fail to notice the modification.
5797 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
5798 Note_Possible_Modification (P);
5800 end Resolve_Reference;
5802 --------------------------------
5803 -- Resolve_Selected_Component --
5804 --------------------------------
5806 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
5808 Comp1 : Entity_Id := Empty; -- prevent junk warning
5809 P : constant Node_Id := Prefix (N);
5810 S : constant Node_Id := Selector_Name (N);
5811 T : Entity_Id := Etype (P);
5813 I1 : Interp_Index := 0; -- prevent junk warning
5818 function Init_Component return Boolean;
5819 -- Check whether this is the initialization of a component within an
5820 -- init proc (by assignment or call to another init proc). If true,
5821 -- there is no need for a discriminant check.
5823 --------------------
5824 -- Init_Component --
5825 --------------------
5827 function Init_Component return Boolean is
5829 return Inside_Init_Proc
5830 and then Nkind (Prefix (N)) = N_Identifier
5831 and then Chars (Prefix (N)) = Name_uInit
5832 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
5835 -- Start of processing for Resolve_Selected_Component
5838 if Is_Overloaded (P) then
5840 -- Use the context type to select the prefix that has a selector
5841 -- of the correct name and type.
5844 Get_First_Interp (P, I, It);
5846 Search : while Present (It.Typ) loop
5847 if Is_Access_Type (It.Typ) then
5848 T := Designated_Type (It.Typ);
5853 if Is_Record_Type (T) then
5854 Comp := First_Entity (T);
5856 while Present (Comp) loop
5858 if Chars (Comp) = Chars (S)
5859 and then Covers (Etype (Comp), Typ)
5868 It := Disambiguate (P, I1, I, Any_Type);
5870 if It = No_Interp then
5872 ("ambiguous prefix
for selected component
", N);
5879 if Scope (Comp1) /= It1.Typ then
5881 -- Resolution chooses the new interpretation.
5882 -- Find the component with the right name.
5884 Comp1 := First_Entity (It1.Typ);
5886 while Present (Comp1)
5887 and then Chars (Comp1) /= Chars (S)
5889 Comp1 := Next_Entity (Comp1);
5898 Comp := Next_Entity (Comp);
5903 Get_Next_Interp (I, It);
5906 Resolve (P, It1.Typ);
5908 Set_Entity (S, Comp1);
5911 -- Resolve prefix with its type
5916 -- If prefix is an access type, the node will be transformed into
5917 -- an explicit dereference during expansion. The type of the node
5918 -- is the designated type of that of the prefix.
5920 if Is_Access_Type (Etype (P)) then
5921 T := Designated_Type (Etype (P));
5926 if Has_Discriminants (T)
5927 and then (Ekind (Entity (S)) = E_Component
5929 Ekind (Entity (S)) = E_Discriminant)
5930 and then Present (Original_Record_Component (Entity (S)))
5931 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
5932 and then Present (Discriminant_Checking_Func
5933 (Original_Record_Component (Entity (S))))
5934 and then not Discriminant_Checks_Suppressed (T)
5935 and then not Init_Component
5937 Set_Do_Discriminant_Check (N);
5940 if Ekind (Entity (S)) = E_Void then
5941 Error_Msg_N ("premature
use of component
", S);
5944 -- If the prefix is a record conversion, this may be a renamed
5945 -- discriminant whose bounds differ from those of the original
5946 -- one, so we must ensure that a range check is performed.
5948 if Nkind (P) = N_Type_Conversion
5949 and then Ekind (Entity (S)) = E_Discriminant
5950 and then Is_Discrete_Type (Typ)
5952 Set_Etype (N, Base_Type (Typ));
5955 -- Note: No Eval processing is required, because the prefix is of a
5956 -- record type, or protected type, and neither can possibly be static.
5958 end Resolve_Selected_Component;
5964 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
5965 B_Typ : constant Entity_Id := Base_Type (Typ);
5966 L : constant Node_Id := Left_Opnd (N);
5967 R : constant Node_Id := Right_Opnd (N);
5970 -- We do the resolution using the base type, because intermediate values
5971 -- in expressions always are of the base type, not a subtype of it.
5974 Resolve (R, Standard_Natural);
5976 Check_Unset_Reference (L);
5977 Check_Unset_Reference (R);
5979 Set_Etype (N, B_Typ);
5980 Generate_Operator_Reference (N, B_Typ);
5984 ---------------------------
5985 -- Resolve_Short_Circuit --
5986 ---------------------------
5988 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
5989 B_Typ : constant Entity_Id := Base_Type (Typ);
5990 L : constant Node_Id := Left_Opnd (N);
5991 R : constant Node_Id := Right_Opnd (N);
5997 Check_Unset_Reference (L);
5998 Check_Unset_Reference (R);
6000 Set_Etype (N, B_Typ);
6001 Eval_Short_Circuit (N);
6002 end Resolve_Short_Circuit;
6008 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
6009 Name : constant Node_Id := Prefix (N);
6010 Drange : constant Node_Id := Discrete_Range (N);
6011 Array_Type : Entity_Id := Empty;
6015 if Is_Overloaded (Name) then
6017 -- Use the context type to select the prefix that yields the
6018 -- correct array type.
6022 I1 : Interp_Index := 0;
6024 P : constant Node_Id := Prefix (N);
6025 Found : Boolean := False;
6028 Get_First_Interp (P, I, It);
6030 while Present (It.Typ) loop
6032 if (Is_Array_Type (It.Typ)
6033 and then Covers (Typ, It.Typ))
6034 or else (Is_Access_Type (It.Typ)
6035 and then Is_Array_Type (Designated_Type (It.Typ))
6036 and then Covers (Typ, Designated_Type (It.Typ)))
6039 It := Disambiguate (P, I1, I, Any_Type);
6041 if It = No_Interp then
6042 Error_Msg_N ("ambiguous prefix
for slicing
", N);
6047 Array_Type := It.Typ;
6052 Array_Type := It.Typ;
6057 Get_Next_Interp (I, It);
6062 Array_Type := Etype (Name);
6065 Resolve (Name, Array_Type);
6067 if Is_Access_Type (Array_Type) then
6068 Apply_Access_Check (N);
6069 Array_Type := Designated_Type (Array_Type);
6071 -- If the prefix is an access to an unconstrained array, we must
6072 -- use the actual subtype of the object to perform the index checks.
6073 -- The object denoted by the prefix is implicit in the node, so we
6074 -- build an explicit representation for it in order to compute the
6077 if not Is_Constrained (Array_Type) then
6078 Remove_Side_Effects (Prefix (N));
6081 Obj : constant Node_Id :=
6082 Make_Explicit_Dereference (Sloc (N),
6083 Prefix => New_Copy_Tree (Prefix (N)));
6085 Set_Etype (Obj, Array_Type);
6086 Set_Parent (Obj, Parent (N));
6087 Array_Type := Get_Actual_Subtype (Obj);
6091 elsif Is_Entity_Name (Name)
6092 or else (Nkind (Name) = N_Function_Call
6093 and then not Is_Constrained (Etype (Name)))
6095 Array_Type := Get_Actual_Subtype (Name);
6098 -- If name was overloaded, set slice type correctly now
6100 Set_Etype (N, Array_Type);
6102 -- If the range is specified by a subtype mark, no resolution
6103 -- is necessary. Else resolve the bounds, and apply needed checks.
6105 if not Is_Entity_Name (Drange) then
6106 Index := First_Index (Array_Type);
6107 Resolve (Drange, Base_Type (Etype (Index)));
6109 if Nkind (Drange) = N_Range then
6110 Apply_Range_Check (Drange, Etype (Index));
6114 Set_Slice_Subtype (N);
6118 ----------------------------
6119 -- Resolve_String_Literal --
6120 ----------------------------
6122 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
6123 C_Typ : constant Entity_Id := Component_Type (Typ);
6124 R_Typ : constant Entity_Id := Root_Type (C_Typ);
6125 Loc : constant Source_Ptr := Sloc (N);
6126 Str : constant String_Id := Strval (N);
6127 Strlen : constant Nat := String_Length (Str);
6128 Subtype_Id : Entity_Id;
6129 Need_Check : Boolean;
6132 -- For a string appearing in a concatenation, defer creation of the
6133 -- string_literal_subtype until the end of the resolution of the
6134 -- concatenation, because the literal may be constant-folded away.
6135 -- This is a useful optimization for long concatenation expressions.
6137 -- If the string is an aggregate built for a single character (which
6138 -- happens in a non-static context) or a is null string to which special
6139 -- checks may apply, we build the subtype. Wide strings must also get
6140 -- a string subtype if they come from a one character aggregate. Strings
6141 -- generated by attributes might be static, but it is often hard to
6142 -- determine whether the enclosing context is static, so we generate
6143 -- subtypes for them as well, thus losing some rarer optimizations ???
6144 -- Same for strings that come from a static conversion.
6147 (Strlen = 0 and then Typ /= Standard_String)
6148 or else Nkind (Parent (N)) /= N_Op_Concat
6149 or else (N /= Left_Opnd (Parent (N))
6150 and then N /= Right_Opnd (Parent (N)))
6151 or else ((Typ = Standard_Wide_String
6152 or else Typ = Standard_Wide_Wide_String)
6153 and then Nkind (Original_Node (N)) /= N_String_Literal);
6155 -- If the resolving type is itself a string literal subtype, we
6156 -- can just reuse it, since there is no point in creating another.
6158 if Ekind (Typ) = E_String_Literal_Subtype then
6161 elsif Nkind (Parent (N)) = N_Op_Concat
6162 and then not Need_Check
6163 and then Nkind (Original_Node (N)) /= N_Character_Literal
6164 and then Nkind (Original_Node (N)) /= N_Attribute_Reference
6165 and then Nkind (Original_Node (N)) /= N_Qualified_Expression
6166 and then Nkind (Original_Node (N)) /= N_Type_Conversion
6170 -- Otherwise we must create a string literal subtype. Note that the
6171 -- whole idea of string literal subtypes is simply to avoid the need
6172 -- for building a full fledged array subtype for each literal.
6174 Set_String_Literal_Subtype (N, Typ);
6175 Subtype_Id := Etype (N);
6178 if Nkind (Parent (N)) /= N_Op_Concat
6181 Set_Etype (N, Subtype_Id);
6182 Eval_String_Literal (N);
6185 if Is_Limited_Composite (Typ)
6186 or else Is_Private_Composite (Typ)
6188 Error_Msg_N ("string literal
not available
for private array", N);
6189 Set_Etype (N, Any_Type);
6193 -- The validity of a null string has been checked in the
6194 -- call to Eval_String_Literal.
6199 -- Always accept string literal with component type Any_Character,
6200 -- which occurs in error situations and in comparisons of literals,
6201 -- both of which should accept all literals.
6203 elsif R_Typ = Any_Character then
6206 -- If the type is bit-packed, then we always tranform the string
6207 -- literal into a full fledged aggregate.
6209 elsif Is_Bit_Packed_Array (Typ) then
6212 -- Deal with cases of Wide_Wide_String, Wide_String, and String
6215 -- For Standard.Wide_Wide_String, or any other type whose component
6216 -- type is Standard.Wide_Wide_Character, we know that all the
6217 -- characters in the string must be acceptable, since the parser
6218 -- accepted the characters as valid character literals.
6220 if R_Typ = Standard_Wide_Wide_Character then
6223 -- For the case of Standard.String, or any other type whose
6224 -- component type is Standard.Character, we must make sure that
6225 -- there are no wide characters in the string, i.e. that it is
6226 -- entirely composed of characters in range of type Character.
6228 -- If the string literal is the result of a static concatenation,
6229 -- the test has already been performed on the components, and need
6232 elsif R_Typ = Standard_Character
6233 and then Nkind (Original_Node (N)) /= N_Op_Concat
6235 for J in 1 .. Strlen loop
6236 if not In_Character_Range (Get_String_Char (Str, J)) then
6238 -- If we are out of range, post error. This is one of the
6239 -- very few places that we place the flag in the middle of
6240 -- a token, right under the offending wide character.
6243 ("literal
out of range of type Standard
.Character",
6244 Source_Ptr (Int (Loc) + J));
6249 -- For the case of Standard.Wide_String, or any other type whose
6250 -- component type is Standard.Wide_Character, we must make sure that
6251 -- there are no wide characters in the string, i.e. that it is
6252 -- entirely composed of characters in range of type Wide_Character.
6254 -- If the string literal is the result of a static concatenation,
6255 -- the test has already been performed on the components, and need
6258 elsif R_Typ = Standard_Wide_Character
6259 and then Nkind (Original_Node (N)) /= N_Op_Concat
6261 for J in 1 .. Strlen loop
6262 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
6264 -- If we are out of range, post error. This is one of the
6265 -- very few places that we place the flag in the middle of
6266 -- a token, right under the offending wide character.
6268 -- This is not quite right, because characters in general
6269 -- will take more than one character position ???
6272 ("literal
out of range of type Standard
.Wide_Character",
6273 Source_Ptr (Int (Loc) + J));
6278 -- If the root type is not a standard character, then we will convert
6279 -- the string into an aggregate and will let the aggregate code do
6280 -- the checking. Standard Wide_Wide_Character is also OK here.
6286 -- See if the component type of the array corresponding to the
6287 -- string has compile time known bounds. If yes we can directly
6288 -- check whether the evaluation of the string will raise constraint
6289 -- error. Otherwise we need to transform the string literal into
6290 -- the corresponding character aggregate and let the aggregate
6291 -- code do the checking.
6293 if R_Typ = Standard_Character
6294 or else R_Typ = Standard_Wide_Character
6295 or else R_Typ = Standard_Wide_Wide_Character
6297 -- Check for the case of full range, where we are definitely OK
6299 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
6303 -- Here the range is not the complete base type range, so check
6306 Comp_Typ_Lo : constant Node_Id :=
6307 Type_Low_Bound (Component_Type (Typ));
6308 Comp_Typ_Hi : constant Node_Id :=
6309 Type_High_Bound (Component_Type (Typ));
6314 if Compile_Time_Known_Value (Comp_Typ_Lo)
6315 and then Compile_Time_Known_Value (Comp_Typ_Hi)
6317 for J in 1 .. Strlen loop
6318 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
6320 if Char_Val < Expr_Value (Comp_Typ_Lo)
6321 or else Char_Val > Expr_Value (Comp_Typ_Hi)
6323 Apply_Compile_Time_Constraint_Error
6324 (N, "character out of range?
", CE_Range_Check_Failed,
6325 Loc => Source_Ptr (Int (Loc) + J));
6335 -- If we got here we meed to transform the string literal into the
6336 -- equivalent qualified positional array aggregate. This is rather
6337 -- heavy artillery for this situation, but it is hard work to avoid.
6340 Lits : constant List_Id := New_List;
6341 P : Source_Ptr := Loc + 1;
6345 -- Build the character literals, we give them source locations
6346 -- that correspond to the string positions, which is a bit tricky
6347 -- given the possible presence of wide character escape sequences.
6349 for J in 1 .. Strlen loop
6350 C := Get_String_Char (Str, J);
6351 Set_Character_Literal_Name (C);
6354 Make_Character_Literal (P,
6356 Char_Literal_Value => UI_From_CC (C)));
6358 if In_Character_Range (C) then
6361 -- Should we have a call to Skip_Wide here ???
6369 Make_Qualified_Expression (Loc,
6370 Subtype_Mark => New_Reference_To (Typ, Loc),
6372 Make_Aggregate (Loc, Expressions => Lits)));
6374 Analyze_And_Resolve (N, Typ);
6376 end Resolve_String_Literal;
6378 -----------------------------
6379 -- Resolve_Subprogram_Info --
6380 -----------------------------
6382 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
6385 end Resolve_Subprogram_Info;
6387 -----------------------------
6388 -- Resolve_Type_Conversion --
6389 -----------------------------
6391 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
6392 Target_Type : constant Entity_Id := Etype (N);
6393 Conv_OK : constant Boolean := Conversion_OK (N);
6395 Opnd_Type : Entity_Id;
6401 Operand := Expression (N);
6404 and then not Valid_Conversion (N, Target_Type, Operand)
6409 if Etype (Operand) = Any_Fixed then
6411 -- Mixed-mode operation involving a literal. Context must be a fixed
6412 -- type which is applied to the literal subsequently.
6414 if Is_Fixed_Point_Type (Typ) then
6415 Set_Etype (Operand, Universal_Real);
6417 elsif Is_Numeric_Type (Typ)
6418 and then (Nkind (Operand) = N_Op_Multiply
6419 or else Nkind (Operand) = N_Op_Divide)
6420 and then (Etype (Right_Opnd (Operand)) = Universal_Real
6421 or else Etype (Left_Opnd (Operand)) = Universal_Real)
6423 -- Return if expression is ambiguous
6425 if Unique_Fixed_Point_Type (N) = Any_Type then
6428 -- If nothing else, the available fixed type is Duration
6431 Set_Etype (Operand, Standard_Duration);
6434 -- Resolve the real operand with largest available precision
6435 if Etype (Right_Opnd (Operand)) = Universal_Real then
6436 Rop := New_Copy_Tree (Right_Opnd (Operand));
6438 Rop := New_Copy_Tree (Left_Opnd (Operand));
6441 Resolve (Rop, Standard_Long_Long_Float);
6443 -- If the operand is a literal (it could be a non-static and
6444 -- illegal exponentiation) check whether the use of Duration
6445 -- is potentially inaccurate.
6447 if Nkind (Rop) = N_Real_Literal
6448 and then Realval (Rop) /= Ureal_0
6449 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
6451 Error_Msg_N ("universal real operand can only be interpreted?
",
6453 Error_Msg_N ("\as
Duration, and will lose precision?
", Rop);
6456 elsif Is_Numeric_Type (Typ)
6457 and then Nkind (Operand) in N_Op
6458 and then Unique_Fixed_Point_Type (N) /= Any_Type
6460 Set_Etype (Operand, Standard_Duration);
6463 Error_Msg_N ("invalid context
for mixed mode operation
", N);
6464 Set_Etype (Operand, Any_Type);
6469 Opnd_Type := Etype (Operand);
6472 -- Note: we do the Eval_Type_Conversion call before applying the
6473 -- required checks for a subtype conversion. This is important,
6474 -- since both are prepared under certain circumstances to change
6475 -- the type conversion to a constraint error node, but in the case
6476 -- of Eval_Type_Conversion this may reflect an illegality in the
6477 -- static case, and we would miss the illegality (getting only a
6478 -- warning message), if we applied the type conversion checks first.
6480 Eval_Type_Conversion (N);
6482 -- If after evaluation, we still have a type conversion, then we
6483 -- may need to apply checks required for a subtype conversion.
6485 -- Skip these type conversion checks if universal fixed operands
6486 -- operands involved, since range checks are handled separately for
6487 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
6489 if Nkind (N) = N_Type_Conversion
6490 and then not Is_Generic_Type (Root_Type (Target_Type))
6491 and then Target_Type /= Universal_Fixed
6492 and then Opnd_Type /= Universal_Fixed
6494 Apply_Type_Conversion_Checks (N);
6497 -- Issue warning for conversion of simple object to its own type
6498 -- We have to test the original nodes, since they may have been
6499 -- rewritten by various optimizations.
6501 Orig_N := Original_Node (N);
6503 if Warn_On_Redundant_Constructs
6504 and then Comes_From_Source (Orig_N)
6505 and then Nkind (Orig_N) = N_Type_Conversion
6506 and then not In_Instance
6508 Orig_N := Original_Node (Expression (Orig_N));
6509 Orig_T := Target_Type;
6511 -- If the node is part of a larger expression, the Target_Type
6512 -- may not be the original type of the node if the context is a
6513 -- condition. Recover original type to see if conversion is needed.
6515 if Is_Boolean_Type (Orig_T)
6516 and then Nkind (Parent (N)) in N_Op
6518 Orig_T := Etype (Parent (N));
6521 if Is_Entity_Name (Orig_N)
6522 and then Etype (Entity (Orig_N)) = Orig_T
6525 ("?useless conversion
, & has this
type", N, Entity (Orig_N));
6528 end Resolve_Type_Conversion;
6530 ----------------------
6531 -- Resolve_Unary_Op --
6532 ----------------------
6534 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
6535 B_Typ : constant Entity_Id := Base_Type (Typ);
6536 R : constant Node_Id := Right_Opnd (N);
6542 -- Generate warning for expressions like abs (x mod 2)
6544 if Warn_On_Redundant_Constructs
6545 and then Nkind (N) = N_Op_Abs
6547 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
6549 if OK and then Hi >= Lo and then Lo >= 0 then
6551 ("?
abs applied to known non
-negative value has no effect
", N);
6555 -- Generate warning for expressions like -5 mod 3
6557 if Paren_Count (N) = 0
6558 and then Nkind (N) = N_Op_Minus
6559 and then Nkind (Right_Opnd (N)) = N_Op_Mod
6560 and then Comes_From_Source (N)
6563 ("?unary minus expression should be parenthesized here
", N);
6566 if Comes_From_Source (N)
6567 and then Ekind (Entity (N)) = E_Function
6568 and then Is_Imported (Entity (N))
6569 and then Is_Intrinsic_Subprogram (Entity (N))
6571 Resolve_Intrinsic_Unary_Operator (N, Typ);
6575 if Etype (R) = Universal_Integer
6576 or else Etype (R) = Universal_Real
6578 Check_For_Visible_Operator (N, B_Typ);
6581 Set_Etype (N, B_Typ);
6584 Check_Unset_Reference (R);
6585 Generate_Operator_Reference (N, B_Typ);
6588 -- Set overflow checking bit. Much cleverer code needed here eventually
6589 -- and perhaps the Resolve routines should be separated for the various
6590 -- arithmetic operations, since they will need different processing ???
6592 if Nkind (N) in N_Op then
6593 if not Overflow_Checks_Suppressed (Etype (N)) then
6594 Enable_Overflow_Check (N);
6597 end Resolve_Unary_Op;
6599 ----------------------------------
6600 -- Resolve_Unchecked_Expression --
6601 ----------------------------------
6603 procedure Resolve_Unchecked_Expression
6608 Resolve (Expression (N), Typ, Suppress => All_Checks);
6610 end Resolve_Unchecked_Expression;
6612 ---------------------------------------
6613 -- Resolve_Unchecked_Type_Conversion --
6614 ---------------------------------------
6616 procedure Resolve_Unchecked_Type_Conversion
6620 pragma Warnings (Off, Typ);
6622 Operand : constant Node_Id := Expression (N);
6623 Opnd_Type : constant Entity_Id := Etype (Operand);
6626 -- Resolve operand using its own type
6628 Resolve (Operand, Opnd_Type);
6629 Eval_Unchecked_Conversion (N);
6631 end Resolve_Unchecked_Type_Conversion;
6633 ------------------------------
6634 -- Rewrite_Operator_As_Call --
6635 ------------------------------
6637 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
6638 Loc : constant Source_Ptr := Sloc (N);
6639 Actuals : constant List_Id := New_List;
6643 if Nkind (N) in N_Binary_Op then
6644 Append (Left_Opnd (N), Actuals);
6647 Append (Right_Opnd (N), Actuals);
6650 Make_Function_Call (Sloc => Loc,
6651 Name => New_Occurrence_Of (Nam, Loc),
6652 Parameter_Associations => Actuals);
6654 Preserve_Comes_From_Source (New_N, N);
6655 Preserve_Comes_From_Source (Name (New_N), N);
6657 Set_Etype (N, Etype (Nam));
6658 end Rewrite_Operator_As_Call;
6660 ------------------------------
6661 -- Rewrite_Renamed_Operator --
6662 ------------------------------
6664 procedure Rewrite_Renamed_Operator
6669 Nam : constant Name_Id := Chars (Op);
6670 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
6674 -- Rewrite the operator node using the real operator, not its
6675 -- renaming. Exclude user-defined intrinsic operations of the same
6676 -- name, which are treated separately and rewritten as calls.
6678 if Ekind (Op) /= E_Function
6679 or else Chars (N) /= Nam
6681 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
6682 Set_Chars (Op_Node, Nam);
6683 Set_Etype (Op_Node, Etype (N));
6684 Set_Entity (Op_Node, Op);
6685 Set_Right_Opnd (Op_Node, Right_Opnd (N));
6687 -- Indicate that both the original entity and its renaming
6688 -- are referenced at this point.
6690 Generate_Reference (Entity (N), N);
6691 Generate_Reference (Op, N);
6694 Set_Left_Opnd (Op_Node, Left_Opnd (N));
6697 Rewrite (N, Op_Node);
6699 -- If the context type is private, add the appropriate conversions
6700 -- so that the operator is applied to the full view. This is done
6701 -- in the routines that resolve intrinsic operators,
6703 if Is_Intrinsic_Subprogram (Op)
6704 and then Is_Private_Type (Typ)
6707 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
6708 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
6709 Resolve_Intrinsic_Operator (N, Typ);
6711 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
6712 Resolve_Intrinsic_Unary_Operator (N, Typ);
6719 elsif Ekind (Op) = E_Function
6720 and then Is_Intrinsic_Subprogram (Op)
6722 -- Operator renames a user-defined operator of the same name. Use
6723 -- the original operator in the node, which is the one that gigi
6727 Set_Is_Overloaded (N, False);
6729 end Rewrite_Renamed_Operator;
6731 -----------------------
6732 -- Set_Slice_Subtype --
6733 -----------------------
6735 -- Build an implicit subtype declaration to represent the type delivered
6736 -- by the slice. This is an abbreviated version of an array subtype. We
6737 -- define an index subtype for the slice, using either the subtype name
6738 -- or the discrete range of the slice. To be consistent with index usage
6739 -- elsewhere, we create a list header to hold the single index. This list
6740 -- is not otherwise attached to the syntax tree.
6742 procedure Set_Slice_Subtype (N : Node_Id) is
6743 Loc : constant Source_Ptr := Sloc (N);
6744 Index_List : constant List_Id := New_List;
6746 Index_Subtype : Entity_Id;
6747 Index_Type : Entity_Id;
6748 Slice_Subtype : Entity_Id;
6749 Drange : constant Node_Id := Discrete_Range (N);
6752 if Is_Entity_Name (Drange) then
6753 Index_Subtype := Entity (Drange);
6756 -- We force the evaluation of a range. This is definitely needed in
6757 -- the renamed case, and seems safer to do unconditionally. Note in
6758 -- any case that since we will create and insert an Itype referring
6759 -- to this range, we must make sure any side effect removal actions
6760 -- are inserted before the Itype definition.
6762 if Nkind (Drange) = N_Range then
6763 Force_Evaluation (Low_Bound (Drange));
6764 Force_Evaluation (High_Bound (Drange));
6767 Index_Type := Base_Type (Etype (Drange));
6769 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
6771 Set_Scalar_Range (Index_Subtype, Drange);
6772 Set_Etype (Index_Subtype, Index_Type);
6773 Set_Size_Info (Index_Subtype, Index_Type);
6774 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
6777 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
6779 Index := New_Occurrence_Of (Index_Subtype, Loc);
6780 Set_Etype (Index, Index_Subtype);
6781 Append (Index, Index_List);
6783 Set_First_Index (Slice_Subtype, Index);
6784 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
6785 Set_Is_Constrained (Slice_Subtype, True);
6786 Init_Size_Align (Slice_Subtype);
6788 Check_Compile_Time_Size (Slice_Subtype);
6790 -- The Etype of the existing Slice node is reset to this slice
6791 -- subtype. Its bounds are obtained from its first index.
6793 Set_Etype (N, Slice_Subtype);
6795 -- In the packed case, this must be immediately frozen
6797 -- Couldn't we always freeze here??? and if we did, then the above
6798 -- call to Check_Compile_Time_Size could be eliminated, which would
6799 -- be nice, because then that routine could be made private to Freeze.
6801 if Is_Packed (Slice_Subtype) and not In_Default_Expression then
6802 Freeze_Itype (Slice_Subtype, N);
6805 end Set_Slice_Subtype;
6807 --------------------------------
6808 -- Set_String_Literal_Subtype --
6809 --------------------------------
6811 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
6812 Subtype_Id : Entity_Id;
6815 if Nkind (N) /= N_String_Literal then
6818 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
6821 Set_String_Literal_Length (Subtype_Id, UI_From_Int
6822 (String_Length (Strval (N))));
6823 Set_Etype (Subtype_Id, Base_Type (Typ));
6824 Set_Is_Constrained (Subtype_Id);
6826 -- The low bound is set from the low bound of the corresponding
6827 -- index type. Note that we do not store the high bound in the
6828 -- string literal subtype, but it can be deduced if necssary
6829 -- from the length and the low bound.
6831 Set_String_Literal_Low_Bound
6832 (Subtype_Id, Type_Low_Bound (Etype (First_Index (Typ))));
6834 Set_Etype (N, Subtype_Id);
6835 end Set_String_Literal_Subtype;
6837 -----------------------------
6838 -- Unique_Fixed_Point_Type --
6839 -----------------------------
6841 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
6842 T1 : Entity_Id := Empty;
6847 procedure Fixed_Point_Error;
6848 -- If true ambiguity, give details
6850 -----------------------
6851 -- Fixed_Point_Error --
6852 -----------------------
6854 procedure Fixed_Point_Error is
6856 Error_Msg_N ("ambiguous universal_fixed_expression
", N);
6857 Error_Msg_NE ("\possible interpretation as
}", N, T1);
6858 Error_Msg_NE ("\possible interpretation as
}", N, T2);
6859 end Fixed_Point_Error;
6861 -- Start of processing for Unique_Fixed_Point_Type
6864 -- The operations on Duration are visible, so Duration is always a
6865 -- possible interpretation.
6867 T1 := Standard_Duration;
6869 -- Look for fixed-point types in enclosing scopes
6871 Scop := Current_Scope;
6872 while Scop /= Standard_Standard loop
6873 T2 := First_Entity (Scop);
6875 while Present (T2) loop
6876 if Is_Fixed_Point_Type (T2)
6877 and then Current_Entity (T2) = T2
6878 and then Scope (Base_Type (T2)) = Scop
6880 if Present (T1) then
6891 Scop := Scope (Scop);
6894 -- Look for visible fixed type declarations in the context
6896 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
6897 while Present (Item) loop
6898 if Nkind (Item) = N_With_Clause then
6899 Scop := Entity (Name (Item));
6900 T2 := First_Entity (Scop);
6902 while Present (T2) loop
6903 if Is_Fixed_Point_Type (T2)
6904 and then Scope (Base_Type (T2)) = Scop
6905 and then (Is_Potentially_Use_Visible (T2)
6906 or else In_Use (T2))
6908 if Present (T1) then
6923 if Nkind (N) = N_Real_Literal then
6924 Error_Msg_NE ("real literal interpreted as
}?
", N, T1);
6927 Error_Msg_NE ("universal_fixed expression interpreted as
}?
", N, T1);
6931 end Unique_Fixed_Point_Type;
6933 ----------------------
6934 -- Valid_Conversion --
6935 ----------------------
6937 function Valid_Conversion
6940 Operand : Node_Id) return Boolean
6942 Target_Type : constant Entity_Id := Base_Type (Target);
6943 Opnd_Type : Entity_Id := Etype (Operand);
6945 function Conversion_Check
6947 Msg : String) return Boolean;
6948 -- Little routine to post Msg if Valid is False, returns Valid value
6950 function Valid_Tagged_Conversion
6951 (Target_Type : Entity_Id;
6952 Opnd_Type : Entity_Id) return Boolean;
6953 -- Specifically test for validity of tagged conversions
6955 ----------------------
6956 -- Conversion_Check --
6957 ----------------------
6959 function Conversion_Check
6961 Msg : String) return Boolean
6965 Error_Msg_N (Msg, Operand);
6969 end Conversion_Check;
6971 -----------------------------
6972 -- Valid_Tagged_Conversion --
6973 -----------------------------
6975 function Valid_Tagged_Conversion
6976 (Target_Type : Entity_Id;
6977 Opnd_Type : Entity_Id) return Boolean
6980 -- Upward conversions are allowed (RM 4.6(22))
6982 if Covers (Target_Type, Opnd_Type)
6983 or else Is_Ancestor (Target_Type, Opnd_Type)
6987 -- Downward conversion are allowed if the operand is class-wide
6990 elsif Is_Class_Wide_Type (Opnd_Type)
6991 and then Covers (Opnd_Type, Target_Type)
6995 elsif Covers (Opnd_Type, Target_Type)
6996 or else Is_Ancestor (Opnd_Type, Target_Type)
6999 Conversion_Check (False,
7000 "downward conversion
of tagged objects
not allowed
");
7003 ("invalid
tagged conversion
, not compatible
with}",
7004 N, First_Subtype (Opnd_Type));
7007 end Valid_Tagged_Conversion;
7009 -- Start of processing for Valid_Conversion
7012 Check_Parameterless_Call (Operand);
7014 if Is_Overloaded (Operand) then
7023 -- Remove procedure calls, which syntactically cannot appear
7024 -- in this context, but which cannot be removed by type checking,
7025 -- because the context does not impose a type.
7027 Get_First_Interp (Operand, I, It);
7029 while Present (It.Typ) loop
7031 if It.Typ = Standard_Void_Type then
7035 Get_Next_Interp (I, It);
7038 Get_First_Interp (Operand, I, It);
7043 Error_Msg_N ("illegal operand
in conversion
", Operand);
7047 Get_Next_Interp (I, It);
7049 if Present (It.Typ) then
7051 It1 := Disambiguate (Operand, I1, I, Any_Type);
7053 if It1 = No_Interp then
7054 Error_Msg_N ("ambiguous operand
in conversion
", Operand);
7056 Error_Msg_Sloc := Sloc (It.Nam);
7057 Error_Msg_N ("possible interpretation#
!", Operand);
7059 Error_Msg_Sloc := Sloc (N1);
7060 Error_Msg_N ("possible interpretation#
!", Operand);
7066 Set_Etype (Operand, It1.Typ);
7067 Opnd_Type := It1.Typ;
7071 if Chars (Current_Scope) = Name_Unchecked_Conversion then
7073 -- This check is dubious, what if there were a user defined
7074 -- scope whose name was Unchecked_Conversion ???
7078 elsif Is_Numeric_Type (Target_Type) then
7079 if Opnd_Type = Universal_Fixed then
7082 elsif (In_Instance or else In_Inlined_Body)
7083 and then not Comes_From_Source (N)
7088 return Conversion_Check (Is_Numeric_Type (Opnd_Type),
7089 "illegal operand
for numeric conversion
");
7092 elsif Is_Array_Type (Target_Type) then
7093 if not Is_Array_Type (Opnd_Type)
7094 or else Opnd_Type = Any_Composite
7095 or else Opnd_Type = Any_String
7098 ("illegal operand
for array conversion
", Operand);
7101 elsif Number_Dimensions (Target_Type) /=
7102 Number_Dimensions (Opnd_Type)
7105 ("incompatible number
of dimensions
for conversion
", Operand);
7110 Target_Index : Node_Id := First_Index (Target_Type);
7111 Opnd_Index : Node_Id := First_Index (Opnd_Type);
7113 Target_Index_Type : Entity_Id;
7114 Opnd_Index_Type : Entity_Id;
7116 Target_Comp_Type : constant Entity_Id :=
7117 Component_Type (Target_Type);
7118 Opnd_Comp_Type : constant Entity_Id :=
7119 Component_Type (Opnd_Type);
7122 while Present (Target_Index) and then Present (Opnd_Index) loop
7123 Target_Index_Type := Etype (Target_Index);
7124 Opnd_Index_Type := Etype (Opnd_Index);
7126 if not (Is_Integer_Type (Target_Index_Type)
7127 and then Is_Integer_Type (Opnd_Index_Type))
7128 and then (Root_Type (Target_Index_Type)
7129 /= Root_Type (Opnd_Index_Type))
7132 ("incompatible index types
for array conversion
",
7137 Next_Index (Target_Index);
7138 Next_Index (Opnd_Index);
7141 if Base_Type (Target_Comp_Type) /=
7142 Base_Type (Opnd_Comp_Type)
7145 ("incompatible component types
for array conversion
",
7150 Is_Constrained (Target_Comp_Type)
7151 /= Is_Constrained (Opnd_Comp_Type)
7152 or else not Subtypes_Statically_Match
7153 (Target_Comp_Type, Opnd_Comp_Type)
7156 ("component subtypes must statically match
", Operand);
7165 elsif (Ekind (Target_Type) = E_General_Access_Type
7166 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
7169 (Is_Access_Type (Opnd_Type)
7170 and then Ekind (Opnd_Type) /=
7171 E_Access_Subprogram_Type
7172 and then Ekind (Opnd_Type) /=
7173 E_Access_Protected_Subprogram_Type,
7174 "must be an
access-to
-object
type")
7176 if Is_Access_Constant (Opnd_Type)
7177 and then not Is_Access_Constant (Target_Type)
7180 ("access-to
-constant operand
type not allowed
", Operand);
7184 -- Check the static accessibility rule of 4.6(17). Note that
7185 -- the check is not enforced when within an instance body, since
7186 -- the RM requires such cases to be caught at run time.
7188 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
7189 if Type_Access_Level (Opnd_Type)
7190 > Type_Access_Level (Target_Type)
7192 -- In an instance, this is a run-time check, but one we
7193 -- know will fail, so generate an appropriate warning.
7194 -- The raise will be generated by Expand_N_Type_Conversion.
7196 if In_Instance_Body then
7198 ("?cannot convert local pointer to non
-local
access type",
7201 ("?Program_Error will be raised
at run time
", Operand);
7205 ("cannot convert local pointer to non
-local
access type",
7210 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type then
7212 -- When the operand is a selected access discriminant
7213 -- the check needs to be made against the level of the
7214 -- object denoted by the prefix of the selected name.
7215 -- (Object_Access_Level handles checking the prefix
7216 -- of the operand for this case.)
7218 if Nkind (Operand) = N_Selected_Component
7219 and then Object_Access_Level (Operand)
7220 > Type_Access_Level (Target_Type)
7222 -- In an instance, this is a run-time check, but one we
7223 -- know will fail, so generate an appropriate warning.
7224 -- The raise will be generated by Expand_N_Type_Conversion.
7226 if In_Instance_Body then
7228 ("?cannot convert
access discriminant to non
-local
" &
7229 " access type", Operand);
7231 ("?Program_Error will be raised
at run time
", Operand);
7235 ("cannot convert
access discriminant to non
-local
" &
7236 " access type", Operand);
7241 -- The case of a reference to an access discriminant
7242 -- from within a type declaration (which will appear
7243 -- as a discriminal) is always illegal because the
7244 -- level of the discriminant is considered to be
7245 -- deeper than any (namable) access type.
7247 if Is_Entity_Name (Operand)
7248 and then (Ekind (Entity (Operand)) = E_In_Parameter
7249 or else Ekind (Entity (Operand)) = E_Constant)
7250 and then Present (Discriminal_Link (Entity (Operand)))
7253 ("discriminant has deeper accessibility level than target
",
7261 Target : constant Entity_Id := Designated_Type (Target_Type);
7262 Opnd : constant Entity_Id := Designated_Type (Opnd_Type);
7265 if Is_Tagged_Type (Target) then
7266 return Valid_Tagged_Conversion (Target, Opnd);
7269 if Base_Type (Target) /= Base_Type (Opnd) then
7271 ("target designated
type not compatible
with }",
7272 N, Base_Type (Opnd));
7275 -- Ada 2005 AI-384: legality rule is symmetric in both
7276 -- designated types. The conversion is legal (with possible
7277 -- constraint check) if either designated type is
7280 elsif Subtypes_Statically_Match (Target, Opnd)
7282 (Has_Discriminants (Target)
7284 (not Is_Constrained (Opnd)
7285 or else not Is_Constrained (Target)))
7291 ("target designated
subtype not compatible
with }",
7298 elsif (Ekind (Target_Type) = E_Access_Subprogram_Type
7300 Ekind (Target_Type) = E_Anonymous_Access_Subprogram_Type)
7301 and then No (Corresponding_Remote_Type (Opnd_Type))
7302 and then Conversion_Check
7303 (Ekind (Base_Type (Opnd_Type)) = E_Access_Subprogram_Type,
7304 "illegal operand
for access subprogram conversion
")
7306 -- Check that the designated types are subtype conformant
7308 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
7309 Old_Id => Designated_Type (Opnd_Type),
7312 -- Check the static accessibility rule of 4.6(20)
7314 if Type_Access_Level (Opnd_Type) >
7315 Type_Access_Level (Target_Type)
7318 ("operand
type has deeper accessibility level than target
",
7321 -- Check that if the operand type is declared in a generic body,
7322 -- then the target type must be declared within that same body
7323 -- (enforces last sentence of 4.6(20)).
7325 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
7327 O_Gen : constant Node_Id :=
7328 Enclosing_Generic_Body (Opnd_Type);
7331 Enclosing_Generic_Body (Target_Type);
7334 while Present (T_Gen) and then T_Gen /= O_Gen loop
7335 T_Gen := Enclosing_Generic_Body (T_Gen);
7338 if T_Gen /= O_Gen then
7340 ("target
type must be declared
in same
generic body"
7341 & " as operand
type", N);
7348 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
7349 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
7351 -- It is valid to convert from one RAS type to another provided
7352 -- that their specification statically match.
7354 Check_Subtype_Conformant
7356 Designated_Type (Corresponding_Remote_Type (Target_Type)),
7358 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
7363 elsif Is_Tagged_Type (Target_Type) then
7364 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
7366 -- Types derived from the same root type are convertible
7368 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
7371 -- In an instance, there may be inconsistent views of the same
7372 -- type, or types derived from the same type.
7375 and then Underlying_Type (Target_Type) = Underlying_Type (Opnd_Type)
7379 -- Special check for common access type error case
7381 elsif Ekind (Target_Type) = E_Access_Type
7382 and then Is_Access_Type (Opnd_Type)
7384 Error_Msg_N ("target
type must be general
access type!", N);
7385 Error_Msg_NE ("add
ALL to
}!", N, Target_Type);
7390 Error_Msg_NE ("invalid conversion
, not compatible
with }",
7395 end Valid_Conversion;