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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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_Disp; use Exp_Disp;
35 with Exp_Ch7; use Exp_Ch7;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Freeze; use Freeze;
39 with Itypes; use Itypes;
41 with Lib.Xref; use Lib.Xref;
42 with Namet; use Namet;
43 with Nmake; use Nmake;
44 with Nlists; use Nlists;
46 with Output; use Output;
47 with Restrict; use Restrict;
48 with Rident; use Rident;
49 with Rtsfind; use Rtsfind;
51 with Sem_Aggr; use Sem_Aggr;
52 with Sem_Attr; use Sem_Attr;
53 with Sem_Cat; use Sem_Cat;
54 with Sem_Ch4; use Sem_Ch4;
55 with Sem_Ch6; use Sem_Ch6;
56 with Sem_Ch8; use Sem_Ch8;
57 with Sem_Disp; use Sem_Disp;
58 with Sem_Dist; use Sem_Dist;
59 with Sem_Elab; use Sem_Elab;
60 with Sem_Eval; use Sem_Eval;
61 with Sem_Intr; use Sem_Intr;
62 with Sem_Util; use Sem_Util;
63 with Sem_Type; use Sem_Type;
64 with Sem_Warn; use Sem_Warn;
65 with Sinfo; use Sinfo;
66 with Snames; use Snames;
67 with Stand; use Stand;
68 with Stringt; use Stringt;
69 with Targparm; use Targparm;
70 with Tbuild; use Tbuild;
71 with Uintp; use Uintp;
72 with Urealp; use Urealp;
74 package body Sem_Res is
76 -----------------------
77 -- Local Subprograms --
78 -----------------------
80 -- Second pass (top-down) type checking and overload resolution procedures
81 -- Typ is the type required by context. These procedures propagate the
82 -- type information recursively to the descendants of N. If the node
83 -- is not overloaded, its Etype is established in the first pass. If
84 -- overloaded, the Resolve routines set the correct type. For arith.
85 -- operators, the Etype is the base type of the context.
87 -- Note that Resolve_Attribute is separated off in Sem_Attr
89 procedure Ambiguous_Character (C : Node_Id);
90 -- Give list of candidate interpretations when a character literal cannot
93 procedure Check_Direct_Boolean_Op (N : Node_Id);
94 -- N is a binary operator node which may possibly operate on Boolean
95 -- operands. If the operator does have Boolean operands, then a call is
96 -- made to check the restriction No_Direct_Boolean_Operators.
98 procedure Check_Discriminant_Use (N : Node_Id);
99 -- Enforce the restrictions on the use of discriminants when constraining
100 -- a component of a discriminated type (record or concurrent type).
102 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
103 -- Given a node for an operator associated with type T, check that
104 -- the operator is visible. Operators all of whose operands are
105 -- universal must be checked for visibility during resolution
106 -- because their type is not determinable based on their operands.
108 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
109 -- Given a call node, N, which is known to occur immediately within the
110 -- subprogram being called, determines whether it is a detectable case of
111 -- an infinite recursion, and if so, outputs appropriate messages. Returns
112 -- True if an infinite recursion is detected, and False otherwise.
114 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
115 -- If the type of the object being initialized uses the secondary stack
116 -- directly or indirectly, create a transient scope for the call to the
117 -- init proc. This is because we do not create transient scopes for the
118 -- initialization of individual components within the init proc itself.
119 -- Could be optimized away perhaps?
121 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
122 -- Utility to check whether the name in the call is a predefined
123 -- operator, in which case the call is made into an operator node.
124 -- An instance of an intrinsic conversion operation may be given
125 -- an operator name, but is not treated like an operator.
127 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
128 -- If a default expression in entry call N depends on the discriminants
129 -- of the task, it must be replaced with a reference to the discriminant
130 -- of the task being called.
132 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
133 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
134 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
135 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
136 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
137 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
138 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
139 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
140 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
141 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
142 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
143 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
144 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
145 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
146 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
147 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
148 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
149 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
150 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
151 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
152 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
153 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
154 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
155 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
156 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
157 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
158 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
159 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
160 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
161 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
162 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
163 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
165 function Operator_Kind
167 Is_Binary : Boolean) return Node_Kind;
168 -- Utility to map the name of an operator into the corresponding Node. Used
169 -- by other node rewriting procedures.
171 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
172 -- Resolve actuals of call, and add default expressions for missing ones.
173 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
174 -- called subprogram.
176 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
177 -- Called from Resolve_Call, when the prefix denotes an entry or element
178 -- of entry family. Actuals are resolved as for subprograms, and the node
179 -- is rebuilt as an entry call. Also called for protected operations. Typ
180 -- is the context type, which is used when the operation is a protected
181 -- function with no arguments, and the return value is indexed.
183 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
184 -- A call to a user-defined intrinsic operator is rewritten as a call
185 -- to the corresponding predefined operator, with suitable conversions.
187 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
188 -- Ditto, for unary operators (only arithmetic ones)
190 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
191 -- If an operator node resolves to a call to a user-defined operator,
192 -- rewrite the node as a function call.
194 procedure Make_Call_Into_Operator
198 -- Inverse transformation: if an operator is given in functional notation,
199 -- then after resolving the node, transform into an operator node, so
200 -- that operands are resolved properly. Recall that predefined operators
201 -- do not have a full signature and special resolution rules apply.
203 procedure Rewrite_Renamed_Operator
207 -- An operator can rename another, e.g. in an instantiation. In that
208 -- case, the proper operator node must be constructed and resolved.
210 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
211 -- The String_Literal_Subtype is built for all strings that are not
212 -- operands of a static concatenation operation. If the argument is
213 -- not a N_String_Literal node, then the call has no effect.
215 procedure Set_Slice_Subtype (N : Node_Id);
216 -- Build subtype of array type, with the range specified by the slice
218 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
219 -- A universal_fixed expression in an universal context is unambiguous
220 -- if there is only one applicable fixed point type. Determining whether
221 -- there is only one requires a search over all visible entities, and
222 -- happens only in very pathological cases (see 6115-006).
224 function Valid_Conversion
227 Operand : Node_Id) return Boolean;
228 -- Verify legality rules given in 4.6 (8-23). Target is the target
229 -- type of the conversion, which may be an implicit conversion of
230 -- an actual parameter to an anonymous access type (in which case
231 -- N denotes the actual parameter and N = Operand).
233 -------------------------
234 -- Ambiguous_Character --
235 -------------------------
237 procedure Ambiguous_Character (C : Node_Id) is
241 if Nkind (C) = N_Character_Literal then
242 Error_Msg_N ("ambiguous character literal", C);
244 ("\possible interpretations: Character, Wide_Character!", C);
246 E := Current_Entity (C);
247 while Present (E) loop
248 Error_Msg_NE ("\possible interpretation:}!", C, Etype (E));
252 end Ambiguous_Character;
254 -------------------------
255 -- Analyze_And_Resolve --
256 -------------------------
258 procedure Analyze_And_Resolve (N : Node_Id) is
262 end Analyze_And_Resolve;
264 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
268 end Analyze_And_Resolve;
270 -- Version withs check(s) suppressed
272 procedure Analyze_And_Resolve
277 Scop : constant Entity_Id := Current_Scope;
280 if Suppress = All_Checks then
282 Svg : constant Suppress_Array := Scope_Suppress;
285 Scope_Suppress := (others => True);
286 Analyze_And_Resolve (N, Typ);
287 Scope_Suppress := Svg;
292 Svg : constant Boolean := Scope_Suppress (Suppress);
295 Scope_Suppress (Suppress) := True;
296 Analyze_And_Resolve (N, Typ);
297 Scope_Suppress (Suppress) := Svg;
301 if Current_Scope /= Scop
302 and then Scope_Is_Transient
304 -- This can only happen if a transient scope was created
305 -- for an inner expression, which will be removed upon
306 -- completion of the analysis of an enclosing construct.
307 -- The transient scope must have the suppress status of
308 -- the enclosing environment, not of this Analyze call.
310 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
313 end Analyze_And_Resolve;
315 procedure Analyze_And_Resolve
319 Scop : constant Entity_Id := Current_Scope;
322 if Suppress = All_Checks then
324 Svg : constant Suppress_Array := Scope_Suppress;
327 Scope_Suppress := (others => True);
328 Analyze_And_Resolve (N);
329 Scope_Suppress := Svg;
334 Svg : constant Boolean := Scope_Suppress (Suppress);
337 Scope_Suppress (Suppress) := True;
338 Analyze_And_Resolve (N);
339 Scope_Suppress (Suppress) := Svg;
343 if Current_Scope /= Scop
344 and then Scope_Is_Transient
346 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
349 end Analyze_And_Resolve;
351 -----------------------------
352 -- Check_Direct_Boolean_Op --
353 -----------------------------
355 procedure Check_Direct_Boolean_Op (N : Node_Id) is
358 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
360 Check_Restriction (No_Direct_Boolean_Operators, N);
362 end Check_Direct_Boolean_Op;
364 ----------------------------
365 -- Check_Discriminant_Use --
366 ----------------------------
368 procedure Check_Discriminant_Use (N : Node_Id) is
369 PN : constant Node_Id := Parent (N);
370 Disc : constant Entity_Id := Entity (N);
375 -- Any use in a default expression is legal
377 if In_Default_Expression then
380 elsif Nkind (PN) = N_Range then
382 -- Discriminant cannot be used to constrain a scalar type
386 if Nkind (P) = N_Range_Constraint
387 and then Nkind (Parent (P)) = N_Subtype_Indication
388 and then Nkind (Parent (Parent (P))) = N_Component_Definition
390 Error_Msg_N ("discriminant cannot constrain scalar type", N);
392 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
394 -- The following check catches the unusual case where
395 -- a discriminant appears within an index constraint
396 -- that is part of a larger expression within a constraint
397 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
398 -- For now we only check case of record components, and
399 -- note that a similar check should also apply in the
400 -- case of discriminant constraints below. ???
402 -- Note that the check for N_Subtype_Declaration below is to
403 -- detect the valid use of discriminants in the constraints of a
404 -- subtype declaration when this subtype declaration appears
405 -- inside the scope of a record type (which is syntactically
406 -- illegal, but which may be created as part of derived type
407 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
410 if Ekind (Current_Scope) = E_Record_Type
411 and then Scope (Disc) = Current_Scope
413 (Nkind (Parent (P)) = N_Subtype_Indication
415 (Nkind (Parent (Parent (P))) = N_Component_Definition
417 Nkind (Parent (Parent (P))) = N_Subtype_Declaration)
418 and then Paren_Count (N) = 0)
421 ("discriminant must appear alone in component constraint", N);
425 -- Detect a common beginner error:
427 -- type R (D : Positive := 100) is record
428 -- Name : String (1 .. D);
431 -- The default value causes an object of type R to be
432 -- allocated with room for Positive'Last characters.
440 function Large_Storage_Type (T : Entity_Id) return Boolean;
441 -- Return True if type T has a large enough range that
442 -- any array whose index type covered the whole range of
443 -- the type would likely raise Storage_Error.
445 ------------------------
446 -- Large_Storage_Type --
447 ------------------------
449 function Large_Storage_Type (T : Entity_Id) return Boolean is
454 T = Standard_Positive
456 T = Standard_Natural;
457 end Large_Storage_Type;
460 -- Check that the Disc has a large range
462 if not Large_Storage_Type (Etype (Disc)) then
466 -- If the enclosing type is limited, we allocate only the
467 -- default value, not the maximum, and there is no need for
470 if Is_Limited_Type (Scope (Disc)) then
474 -- Check that it is the high bound
476 if N /= High_Bound (PN)
477 or else not Present (Discriminant_Default_Value (Disc))
482 -- Check the array allows a large range at this bound.
483 -- First find the array
487 if Nkind (SI) /= N_Subtype_Indication then
491 T := Entity (Subtype_Mark (SI));
493 if not Is_Array_Type (T) then
497 -- Next, find the dimension
499 TB := First_Index (T);
500 CB := First (Constraints (P));
502 and then Present (TB)
503 and then Present (CB)
514 -- Now, check the dimension has a large range
516 if not Large_Storage_Type (Etype (TB)) then
520 -- Warn about the danger
523 ("creation of & object may raise Storage_Error?",
532 -- Legal case is in index or discriminant constraint
534 elsif Nkind (PN) = N_Index_Or_Discriminant_Constraint
535 or else Nkind (PN) = N_Discriminant_Association
537 if Paren_Count (N) > 0 then
539 ("discriminant in constraint must appear alone", N);
541 elsif Nkind (N) = N_Expanded_Name
542 and then Comes_From_Source (N)
545 ("discriminant must appear alone as a direct name", N);
550 -- Otherwise, context is an expression. It should not be within
551 -- (i.e. a subexpression of) a constraint for a component.
556 while Nkind (P) /= N_Component_Declaration
557 and then Nkind (P) /= N_Subtype_Indication
558 and then Nkind (P) /= N_Entry_Declaration
565 -- If the discriminant is used in an expression that is a bound
566 -- of a scalar type, an Itype is created and the bounds are attached
567 -- to its range, not to the original subtype indication. Such use
568 -- is of course a double fault.
570 if (Nkind (P) = N_Subtype_Indication
572 (Nkind (Parent (P)) = N_Component_Definition
574 Nkind (Parent (P)) = N_Derived_Type_Definition)
575 and then D = Constraint (P))
577 -- The constraint itself may be given by a subtype indication,
578 -- rather than by a more common discrete range.
580 or else (Nkind (P) = N_Subtype_Indication
582 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
583 or else Nkind (P) = N_Entry_Declaration
584 or else Nkind (D) = N_Defining_Identifier
587 ("discriminant in constraint must appear alone", N);
590 end Check_Discriminant_Use;
592 --------------------------------
593 -- Check_For_Visible_Operator --
594 --------------------------------
596 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
598 if Is_Invisible_Operator (N, T) then
600 ("operator for} is not directly visible!", N, First_Subtype (T));
601 Error_Msg_N ("use clause would make operation legal!", N);
603 end Check_For_Visible_Operator;
605 ------------------------------
606 -- Check_Infinite_Recursion --
607 ------------------------------
609 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
613 function Same_Argument_List return Boolean;
614 -- Check whether list of actuals is identical to list of formals
615 -- of called function (which is also the enclosing scope).
617 ------------------------
618 -- Same_Argument_List --
619 ------------------------
621 function Same_Argument_List return Boolean is
627 if not Is_Entity_Name (Name (N)) then
630 Subp := Entity (Name (N));
633 F := First_Formal (Subp);
634 A := First_Actual (N);
635 while Present (F) and then Present (A) loop
636 if not Is_Entity_Name (A)
637 or else Entity (A) /= F
647 end Same_Argument_List;
649 -- Start of processing for Check_Infinite_Recursion
652 -- Loop moving up tree, quitting if something tells us we are
653 -- definitely not in an infinite recursion situation.
658 exit when Nkind (P) = N_Subprogram_Body;
660 if Nkind (P) = N_Or_Else or else
661 Nkind (P) = N_And_Then or else
662 Nkind (P) = N_If_Statement or else
663 Nkind (P) = N_Case_Statement
667 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
668 and then C /= First (Statements (P))
670 -- If the call is the expression of a return statement and
671 -- the actuals are identical to the formals, it's worth a
672 -- warning. However, we skip this if there is an immediately
673 -- preceding raise statement, since the call is never executed.
675 -- Furthermore, this corresponds to a common idiom:
677 -- function F (L : Thing) return Boolean is
679 -- raise Program_Error;
683 -- for generating a stub function
685 if Nkind (Parent (N)) = N_Return_Statement
686 and then Same_Argument_List
688 exit when not Is_List_Member (Parent (N))
689 or else (Nkind (Prev (Parent (N))) /= N_Raise_Statement
691 (Nkind (Prev (Parent (N))) not in N_Raise_xxx_Error
693 Present (Condition (Prev (Parent (N))))));
703 Error_Msg_N ("possible infinite recursion?", N);
704 Error_Msg_N ("\Storage_Error may be raised at run time?", N);
707 end Check_Infinite_Recursion;
709 -------------------------------
710 -- Check_Initialization_Call --
711 -------------------------------
713 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
714 Typ : constant Entity_Id := Etype (First_Formal (Nam));
716 function Uses_SS (T : Entity_Id) return Boolean;
717 -- Check whether the creation of an object of the type will involve
718 -- use of the secondary stack. If T is a record type, this is true
719 -- if the expression for some component uses the secondary stack, eg.
720 -- through a call to a function that returns an unconstrained value.
721 -- False if T is controlled, because cleanups occur elsewhere.
727 function Uses_SS (T : Entity_Id) return Boolean is
732 if Is_Controlled (T) then
735 elsif Is_Array_Type (T) then
736 return Uses_SS (Component_Type (T));
738 elsif Is_Record_Type (T) then
739 Comp := First_Component (T);
740 while Present (Comp) loop
741 if Ekind (Comp) = E_Component
742 and then Nkind (Parent (Comp)) = N_Component_Declaration
744 Expr := Expression (Parent (Comp));
746 -- The expression for a dynamic component may be
747 -- rewritten as a dereference. Retrieve original
750 if Nkind (Original_Node (Expr)) = N_Function_Call
751 and then Requires_Transient_Scope (Etype (Expr))
755 elsif Uses_SS (Etype (Comp)) then
760 Next_Component (Comp);
770 -- Start of processing for Check_Initialization_Call
773 -- Nothing to do if functions do not use the secondary stack for
774 -- returns (i.e. they use a depressed stack pointer instead).
776 if Functions_Return_By_DSP_On_Target then
779 -- Otherwise establish a transient scope if the type needs it
781 elsif Uses_SS (Typ) then
782 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
784 end Check_Initialization_Call;
786 ------------------------------
787 -- Check_Parameterless_Call --
788 ------------------------------
790 procedure Check_Parameterless_Call (N : Node_Id) is
793 function Prefix_Is_Access_Subp return Boolean;
794 -- If the prefix is of an access_to_subprogram type, the node must be
795 -- rewritten as a call. Ditto if the prefix is overloaded and all its
796 -- interpretations are access to subprograms.
798 ---------------------------
799 -- Prefix_Is_Access_Subp --
800 ---------------------------
802 function Prefix_Is_Access_Subp return Boolean is
807 if not Is_Overloaded (N) then
809 Ekind (Etype (N)) = E_Subprogram_Type
810 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
812 Get_First_Interp (N, I, It);
813 while Present (It.Typ) loop
814 if Ekind (It.Typ) /= E_Subprogram_Type
815 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
820 Get_Next_Interp (I, It);
825 end Prefix_Is_Access_Subp;
827 -- Start of processing for Check_Parameterless_Call
830 -- Defend against junk stuff if errors already detected
832 if Total_Errors_Detected /= 0 then
833 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
835 elsif Nkind (N) in N_Has_Chars
836 and then Chars (N) in Error_Name_Or_No_Name
844 -- If the context expects a value, and the name is a procedure,
845 -- this is most likely a missing 'Access. Do not try to resolve
846 -- the parameterless call, error will be caught when the outer
849 if Is_Entity_Name (N)
850 and then Ekind (Entity (N)) = E_Procedure
851 and then not Is_Overloaded (N)
853 (Nkind (Parent (N)) = N_Parameter_Association
854 or else Nkind (Parent (N)) = N_Function_Call
855 or else Nkind (Parent (N)) = N_Procedure_Call_Statement)
860 -- Rewrite as call if overloadable entity that is (or could be, in
861 -- the overloaded case) a function call. If we know for sure that
862 -- the entity is an enumeration literal, we do not rewrite it.
864 if (Is_Entity_Name (N)
865 and then Is_Overloadable (Entity (N))
866 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
867 or else Is_Overloaded (N)))
869 -- Rewrite as call if it is an explicit deference of an expression of
870 -- a subprogram access type, and the suprogram type is not that of a
871 -- procedure or entry.
874 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
876 -- Rewrite as call if it is a selected component which is a function,
877 -- this is the case of a call to a protected function (which may be
878 -- overloaded with other protected operations).
881 (Nkind (N) = N_Selected_Component
882 and then (Ekind (Entity (Selector_Name (N))) = E_Function
884 ((Ekind (Entity (Selector_Name (N))) = E_Entry
886 Ekind (Entity (Selector_Name (N))) = E_Procedure)
887 and then Is_Overloaded (Selector_Name (N)))))
889 -- If one of the above three conditions is met, rewrite as call.
890 -- Apply the rewriting only once.
893 if Nkind (Parent (N)) /= N_Function_Call
894 or else N /= Name (Parent (N))
898 -- If overloaded, overload set belongs to new copy
900 Save_Interps (N, Nam);
902 -- Change node to parameterless function call (note that the
903 -- Parameter_Associations associations field is left set to Empty,
904 -- its normal default value since there are no parameters)
906 Change_Node (N, N_Function_Call);
908 Set_Sloc (N, Sloc (Nam));
912 elsif Nkind (N) = N_Parameter_Association then
913 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
915 end Check_Parameterless_Call;
917 ----------------------
918 -- Is_Predefined_Op --
919 ----------------------
921 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
923 return Is_Intrinsic_Subprogram (Nam)
924 and then not Is_Generic_Instance (Nam)
925 and then Chars (Nam) in Any_Operator_Name
926 and then (No (Alias (Nam))
927 or else Is_Predefined_Op (Alias (Nam)));
928 end Is_Predefined_Op;
930 -----------------------------
931 -- Make_Call_Into_Operator --
932 -----------------------------
934 procedure Make_Call_Into_Operator
939 Op_Name : constant Name_Id := Chars (Op_Id);
940 Act1 : Node_Id := First_Actual (N);
941 Act2 : Node_Id := Next_Actual (Act1);
942 Error : Boolean := False;
943 Func : constant Entity_Id := Entity (Name (N));
944 Is_Binary : constant Boolean := Present (Act2);
946 Opnd_Type : Entity_Id;
947 Orig_Type : Entity_Id := Empty;
950 type Kind_Test is access function (E : Entity_Id) return Boolean;
952 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
953 -- Determine whether E is an access type declared by an access decla-
954 -- ration, and not an (anonymous) allocator type.
956 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
957 -- If the operand is not universal, and the operator is given by a
958 -- expanded name, verify that the operand has an interpretation with
959 -- a type defined in the given scope of the operator.
961 function Type_In_P (Test : Kind_Test) return Entity_Id;
962 -- Find a type of the given class in the package Pack that contains
965 -----------------------------
966 -- Is_Definite_Access_Type --
967 -----------------------------
969 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
970 Btyp : constant Entity_Id := Base_Type (E);
972 return Ekind (Btyp) = E_Access_Type
973 or else (Ekind (Btyp) = E_Access_Subprogram_Type
974 and then Comes_From_Source (Btyp));
975 end Is_Definite_Access_Type;
977 ---------------------------
978 -- Operand_Type_In_Scope --
979 ---------------------------
981 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
982 Nod : constant Node_Id := Right_Opnd (Op_Node);
987 if not Is_Overloaded (Nod) then
988 return Scope (Base_Type (Etype (Nod))) = S;
991 Get_First_Interp (Nod, I, It);
992 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);
1060 while Present (E) loop
1062 and then not In_Decl
1074 -- Start of processing for Make_Call_Into_Operator
1077 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1082 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1083 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1084 Save_Interps (Act1, Left_Opnd (Op_Node));
1085 Save_Interps (Act2, Right_Opnd (Op_Node));
1086 Act1 := Left_Opnd (Op_Node);
1087 Act2 := Right_Opnd (Op_Node);
1092 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1093 Save_Interps (Act1, Right_Opnd (Op_Node));
1094 Act1 := Right_Opnd (Op_Node);
1097 -- If the operator is denoted by an expanded name, and the prefix is
1098 -- not Standard, but the operator is a predefined one whose scope is
1099 -- Standard, then this is an implicit_operator, inserted as an
1100 -- interpretation by the procedure of the same name. This procedure
1101 -- overestimates the presence of implicit operators, because it does
1102 -- not examine the type of the operands. Verify now that the operand
1103 -- type appears in the given scope. If right operand is universal,
1104 -- check the other operand. In the case of concatenation, either
1105 -- argument can be the component type, so check the type of the result.
1106 -- If both arguments are literals, look for a type of the right kind
1107 -- defined in the given scope. This elaborate nonsense is brought to
1108 -- you courtesy of b33302a. The type itself must be frozen, so we must
1109 -- find the type of the proper class in the given scope.
1111 -- A final wrinkle is the multiplication operator for fixed point
1112 -- types, which is defined in Standard only, and not in the scope of
1113 -- the fixed_point type itself.
1115 if Nkind (Name (N)) = N_Expanded_Name then
1116 Pack := Entity (Prefix (Name (N)));
1118 -- If the entity being called is defined in the given package,
1119 -- it is a renaming of a predefined operator, and known to be
1122 if Scope (Entity (Name (N))) = Pack
1123 and then Pack /= Standard_Standard
1127 elsif (Op_Name = Name_Op_Multiply
1128 or else Op_Name = Name_Op_Divide)
1129 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1130 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1132 if Pack /= Standard_Standard then
1137 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1139 if Op_Name = Name_Op_Concat then
1140 Opnd_Type := Base_Type (Typ);
1142 elsif (Scope (Opnd_Type) = Standard_Standard
1144 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1146 and then not Comes_From_Source (Opnd_Type))
1148 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1151 if Scope (Opnd_Type) = Standard_Standard then
1153 -- Verify that the scope contains a type that corresponds to
1154 -- the given literal. Optimize the case where Pack is Standard.
1156 if Pack /= Standard_Standard then
1158 if Opnd_Type = Universal_Integer then
1159 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1161 elsif Opnd_Type = Universal_Real then
1162 Orig_Type := Type_In_P (Is_Real_Type'Access);
1164 elsif Opnd_Type = Any_String then
1165 Orig_Type := Type_In_P (Is_String_Type'Access);
1167 elsif Opnd_Type = Any_Access then
1168 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1170 elsif Opnd_Type = Any_Composite then
1171 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1173 if Present (Orig_Type) then
1174 if Has_Private_Component (Orig_Type) then
1177 Set_Etype (Act1, Orig_Type);
1180 Set_Etype (Act2, Orig_Type);
1189 Error := No (Orig_Type);
1192 elsif Ekind (Opnd_Type) = E_Allocator_Type
1193 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1197 -- If the type is defined elsewhere, and the operator is not
1198 -- defined in the given scope (by a renaming declaration, e.g.)
1199 -- then this is an error as well. If an extension of System is
1200 -- present, and the type may be defined there, Pack must be
1203 elsif Scope (Opnd_Type) /= Pack
1204 and then Scope (Op_Id) /= Pack
1205 and then (No (System_Aux_Id)
1206 or else Scope (Opnd_Type) /= System_Aux_Id
1207 or else Pack /= Scope (System_Aux_Id))
1209 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1212 Error := not Operand_Type_In_Scope (Pack);
1215 elsif Pack = Standard_Standard
1216 and then not Operand_Type_In_Scope (Standard_Standard)
1223 Error_Msg_Node_2 := Pack;
1225 ("& not declared in&", N, Selector_Name (Name (N)));
1226 Set_Etype (N, Any_Type);
1231 Set_Chars (Op_Node, Op_Name);
1233 if not Is_Private_Type (Etype (N)) then
1234 Set_Etype (Op_Node, Base_Type (Etype (N)));
1236 Set_Etype (Op_Node, Etype (N));
1239 -- If this is a call to a function that renames a predefined equality,
1240 -- the renaming declaration provides a type that must be used to
1241 -- resolve the operands. This must be done now because resolution of
1242 -- the equality node will not resolve any remaining ambiguity, and it
1243 -- assumes that the first operand is not overloaded.
1245 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1246 and then Ekind (Func) = E_Function
1247 and then Is_Overloaded (Act1)
1249 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1250 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1253 Set_Entity (Op_Node, Op_Id);
1254 Generate_Reference (Op_Id, N, ' ');
1255 Rewrite (N, Op_Node);
1257 -- If this is an arithmetic operator and the result type is private,
1258 -- the operands and the result must be wrapped in conversion to
1259 -- expose the underlying numeric type and expand the proper checks,
1260 -- e.g. on division.
1262 if Is_Private_Type (Typ) then
1264 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1265 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1266 Resolve_Intrinsic_Operator (N, Typ);
1268 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1269 Resolve_Intrinsic_Unary_Operator (N, Typ);
1278 -- For predefined operators on literals, the operation freezes
1281 if Present (Orig_Type) then
1282 Set_Etype (Act1, Orig_Type);
1283 Freeze_Expression (Act1);
1285 end Make_Call_Into_Operator;
1291 function Operator_Kind
1293 Is_Binary : Boolean) return Node_Kind
1299 if Op_Name = Name_Op_And then Kind := N_Op_And;
1300 elsif Op_Name = Name_Op_Or then Kind := N_Op_Or;
1301 elsif Op_Name = Name_Op_Xor then Kind := N_Op_Xor;
1302 elsif Op_Name = Name_Op_Eq then Kind := N_Op_Eq;
1303 elsif Op_Name = Name_Op_Ne then Kind := N_Op_Ne;
1304 elsif Op_Name = Name_Op_Lt then Kind := N_Op_Lt;
1305 elsif Op_Name = Name_Op_Le then Kind := N_Op_Le;
1306 elsif Op_Name = Name_Op_Gt then Kind := N_Op_Gt;
1307 elsif Op_Name = Name_Op_Ge then Kind := N_Op_Ge;
1308 elsif Op_Name = Name_Op_Add then Kind := N_Op_Add;
1309 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Subtract;
1310 elsif Op_Name = Name_Op_Concat then Kind := N_Op_Concat;
1311 elsif Op_Name = Name_Op_Multiply then Kind := N_Op_Multiply;
1312 elsif Op_Name = Name_Op_Divide then Kind := N_Op_Divide;
1313 elsif Op_Name = Name_Op_Mod then Kind := N_Op_Mod;
1314 elsif Op_Name = Name_Op_Rem then Kind := N_Op_Rem;
1315 elsif Op_Name = Name_Op_Expon then Kind := N_Op_Expon;
1317 raise Program_Error;
1323 if Op_Name = Name_Op_Add then Kind := N_Op_Plus;
1324 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Minus;
1325 elsif Op_Name = Name_Op_Abs then Kind := N_Op_Abs;
1326 elsif Op_Name = Name_Op_Not then Kind := N_Op_Not;
1328 raise Program_Error;
1335 -----------------------------
1336 -- Pre_Analyze_And_Resolve --
1337 -----------------------------
1339 procedure Pre_Analyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1340 Save_Full_Analysis : constant Boolean := Full_Analysis;
1343 Full_Analysis := False;
1344 Expander_Mode_Save_And_Set (False);
1346 -- We suppress all checks for this analysis, since the checks will
1347 -- be applied properly, and in the right location, when the default
1348 -- expression is reanalyzed and reexpanded later on.
1350 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1352 Expander_Mode_Restore;
1353 Full_Analysis := Save_Full_Analysis;
1354 end Pre_Analyze_And_Resolve;
1356 -- Version without context type
1358 procedure Pre_Analyze_And_Resolve (N : Node_Id) is
1359 Save_Full_Analysis : constant Boolean := Full_Analysis;
1362 Full_Analysis := False;
1363 Expander_Mode_Save_And_Set (False);
1366 Resolve (N, Etype (N), Suppress => All_Checks);
1368 Expander_Mode_Restore;
1369 Full_Analysis := Save_Full_Analysis;
1370 end Pre_Analyze_And_Resolve;
1372 ----------------------------------
1373 -- Replace_Actual_Discriminants --
1374 ----------------------------------
1376 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1377 Loc : constant Source_Ptr := Sloc (N);
1378 Tsk : Node_Id := Empty;
1380 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1386 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1390 if Nkind (Nod) = N_Identifier then
1391 Ent := Entity (Nod);
1394 and then Ekind (Ent) = E_Discriminant
1397 Make_Selected_Component (Loc,
1398 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1399 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1401 Set_Etype (Nod, Etype (Ent));
1409 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1411 -- Start of processing for Replace_Actual_Discriminants
1414 if not Expander_Active then
1418 if Nkind (Name (N)) = N_Selected_Component then
1419 Tsk := Prefix (Name (N));
1421 elsif Nkind (Name (N)) = N_Indexed_Component then
1422 Tsk := Prefix (Prefix (Name (N)));
1428 Replace_Discrs (Default);
1430 end Replace_Actual_Discriminants;
1436 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1438 I1 : Interp_Index := 0; -- prevent junk warning
1441 Found : Boolean := False;
1442 Seen : Entity_Id := Empty; -- prevent junk warning
1443 Ctx_Type : Entity_Id := Typ;
1444 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1445 Err_Type : Entity_Id := Empty;
1446 Ambiguous : Boolean := False;
1448 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1449 -- Try and fix up a literal so that it matches its expected type. New
1450 -- literals are manufactured if necessary to avoid cascaded errors.
1452 procedure Resolution_Failed;
1453 -- Called when attempt at resolving current expression fails
1455 --------------------
1456 -- Patch_Up_Value --
1457 --------------------
1459 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1461 if Nkind (N) = N_Integer_Literal
1462 and then Is_Real_Type (Typ)
1465 Make_Real_Literal (Sloc (N),
1466 Realval => UR_From_Uint (Intval (N))));
1467 Set_Etype (N, Universal_Real);
1468 Set_Is_Static_Expression (N);
1470 elsif Nkind (N) = N_Real_Literal
1471 and then Is_Integer_Type (Typ)
1474 Make_Integer_Literal (Sloc (N),
1475 Intval => UR_To_Uint (Realval (N))));
1476 Set_Etype (N, Universal_Integer);
1477 Set_Is_Static_Expression (N);
1478 elsif Nkind (N) = N_String_Literal
1479 and then Is_Character_Type (Typ)
1481 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1483 Make_Character_Literal (Sloc (N),
1485 Char_Literal_Value =>
1486 UI_From_Int (Character'Pos ('A'))));
1487 Set_Etype (N, Any_Character);
1488 Set_Is_Static_Expression (N);
1490 elsif Nkind (N) /= N_String_Literal
1491 and then Is_String_Type (Typ)
1494 Make_String_Literal (Sloc (N),
1495 Strval => End_String));
1497 elsif Nkind (N) = N_Range then
1498 Patch_Up_Value (Low_Bound (N), Typ);
1499 Patch_Up_Value (High_Bound (N), Typ);
1503 -----------------------
1504 -- Resolution_Failed --
1505 -----------------------
1507 procedure Resolution_Failed is
1509 Patch_Up_Value (N, Typ);
1511 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1512 Set_Is_Overloaded (N, False);
1514 -- The caller will return without calling the expander, so we need
1515 -- to set the analyzed flag. Note that it is fine to set Analyzed
1516 -- to True even if we are in the middle of a shallow analysis,
1517 -- (see the spec of sem for more details) since this is an error
1518 -- situation anyway, and there is no point in repeating the
1519 -- analysis later (indeed it won't work to repeat it later, since
1520 -- we haven't got a clear resolution of which entity is being
1523 Set_Analyzed (N, True);
1525 end Resolution_Failed;
1527 -- Start of processing for Resolve
1534 -- Access attribute on remote subprogram cannot be used for
1535 -- a non-remote access-to-subprogram type.
1537 if Nkind (N) = N_Attribute_Reference
1538 and then (Attribute_Name (N) = Name_Access
1539 or else Attribute_Name (N) = Name_Unrestricted_Access
1540 or else Attribute_Name (N) = Name_Unchecked_Access)
1541 and then Comes_From_Source (N)
1542 and then Is_Entity_Name (Prefix (N))
1543 and then Is_Subprogram (Entity (Prefix (N)))
1544 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1545 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1548 ("prefix must statically denote a non-remote subprogram", N);
1551 -- If the context is a Remote_Access_To_Subprogram, access attributes
1552 -- must be resolved with the corresponding fat pointer. There is no need
1553 -- to check for the attribute name since the return type of an
1554 -- attribute is never a remote type.
1556 if Nkind (N) = N_Attribute_Reference
1557 and then Comes_From_Source (N)
1558 and then (Is_Remote_Call_Interface (Typ)
1559 or else Is_Remote_Types (Typ))
1562 Attr : constant Attribute_Id :=
1563 Get_Attribute_Id (Attribute_Name (N));
1564 Pref : constant Node_Id := Prefix (N);
1567 Is_Remote : Boolean := True;
1570 -- Check that Typ is a remote access-to-subprogram type
1572 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1573 -- Prefix (N) must statically denote a remote subprogram
1574 -- declared in a package specification.
1576 if Attr = Attribute_Access then
1577 Decl := Unit_Declaration_Node (Entity (Pref));
1579 if Nkind (Decl) = N_Subprogram_Body then
1580 Spec := Corresponding_Spec (Decl);
1582 if not No (Spec) then
1583 Decl := Unit_Declaration_Node (Spec);
1587 Spec := Parent (Decl);
1589 if not Is_Entity_Name (Prefix (N))
1590 or else Nkind (Spec) /= N_Package_Specification
1592 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1596 ("prefix must statically denote a remote subprogram ",
1601 -- If we are generating code for a distributed program.
1602 -- perform semantic checks against the corresponding
1605 if (Attr = Attribute_Access
1606 or else Attr = Attribute_Unchecked_Access
1607 or else Attr = Attribute_Unrestricted_Access)
1608 and then Expander_Active
1609 and then Get_PCS_Name /= Name_No_DSA
1611 Check_Subtype_Conformant
1612 (New_Id => Entity (Prefix (N)),
1613 Old_Id => Designated_Type
1614 (Corresponding_Remote_Type (Typ)),
1617 Process_Remote_AST_Attribute (N, Typ);
1624 Debug_A_Entry ("resolving ", N);
1626 if Comes_From_Source (N) then
1627 if Is_Fixed_Point_Type (Typ) then
1628 Check_Restriction (No_Fixed_Point, N);
1630 elsif Is_Floating_Point_Type (Typ)
1631 and then Typ /= Universal_Real
1632 and then Typ /= Any_Real
1634 Check_Restriction (No_Floating_Point, N);
1638 -- Return if already analyzed
1640 if Analyzed (N) then
1641 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1644 -- Return if type = Any_Type (previous error encountered)
1646 elsif Etype (N) = Any_Type then
1647 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1651 Check_Parameterless_Call (N);
1653 -- If not overloaded, then we know the type, and all that needs doing
1654 -- is to check that this type is compatible with the context.
1656 if not Is_Overloaded (N) then
1657 Found := Covers (Typ, Etype (N));
1658 Expr_Type := Etype (N);
1660 -- In the overloaded case, we must select the interpretation that
1661 -- is compatible with the context (i.e. the type passed to Resolve)
1664 -- Loop through possible interpretations
1666 Get_First_Interp (N, I, It);
1667 Interp_Loop : while Present (It.Typ) loop
1669 -- We are only interested in interpretations that are compatible
1670 -- with the expected type, any other interpretations are ignored
1672 if not Covers (Typ, It.Typ) then
1673 if Debug_Flag_V then
1674 Write_Str (" interpretation incompatible with context");
1679 -- First matching interpretation
1685 Expr_Type := It.Typ;
1687 -- Matching interpretation that is not the first, maybe an
1688 -- error, but there are some cases where preference rules are
1689 -- used to choose between the two possibilities. These and
1690 -- some more obscure cases are handled in Disambiguate.
1693 Error_Msg_Sloc := Sloc (Seen);
1694 It1 := Disambiguate (N, I1, I, Typ);
1696 -- Disambiguation has succeeded. Skip the remaining
1699 if It1 /= No_Interp then
1701 Expr_Type := It1.Typ;
1703 while Present (It.Typ) loop
1704 Get_Next_Interp (I, It);
1708 -- Before we issue an ambiguity complaint, check for
1709 -- the case of a subprogram call where at least one
1710 -- of the arguments is Any_Type, and if so, suppress
1711 -- the message, since it is a cascaded error.
1713 if Nkind (N) = N_Function_Call
1714 or else Nkind (N) = N_Procedure_Call_Statement
1721 A := First_Actual (N);
1722 while Present (A) loop
1725 if Nkind (E) = N_Parameter_Association then
1726 E := Explicit_Actual_Parameter (E);
1729 if Etype (E) = Any_Type then
1730 if Debug_Flag_V then
1731 Write_Str ("Any_Type in call");
1742 elsif Nkind (N) in N_Binary_Op
1743 and then (Etype (Left_Opnd (N)) = Any_Type
1744 or else Etype (Right_Opnd (N)) = Any_Type)
1748 elsif Nkind (N) in N_Unary_Op
1749 and then Etype (Right_Opnd (N)) = Any_Type
1754 -- Not that special case, so issue message using the
1755 -- flag Ambiguous to control printing of the header
1756 -- message only at the start of an ambiguous set.
1758 if not Ambiguous then
1760 ("ambiguous expression (cannot resolve&)!",
1764 ("possible interpretation#!", N);
1768 Error_Msg_Sloc := Sloc (It.Nam);
1770 -- By default, the error message refers to the candidate
1771 -- interpretation. But if it is a predefined operator,
1772 -- it is implicitly declared at the declaration of
1773 -- the type of the operand. Recover the sloc of that
1774 -- declaration for the error message.
1776 if Nkind (N) in N_Op
1777 and then Scope (It.Nam) = Standard_Standard
1778 and then not Is_Overloaded (Right_Opnd (N))
1779 and then Scope (Base_Type (Etype (Right_Opnd (N))))
1780 /= Standard_Standard
1782 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
1784 if Comes_From_Source (Err_Type)
1785 and then Present (Parent (Err_Type))
1787 Error_Msg_Sloc := Sloc (Parent (Err_Type));
1790 elsif Nkind (N) in N_Binary_Op
1791 and then Scope (It.Nam) = Standard_Standard
1792 and then not Is_Overloaded (Left_Opnd (N))
1793 and then Scope (Base_Type (Etype (Left_Opnd (N))))
1794 /= Standard_Standard
1796 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
1798 if Comes_From_Source (Err_Type)
1799 and then Present (Parent (Err_Type))
1801 Error_Msg_Sloc := Sloc (Parent (Err_Type));
1807 if Nkind (N) in N_Op
1808 and then Scope (It.Nam) = Standard_Standard
1809 and then Present (Err_Type)
1812 ("possible interpretation (predefined)#!", N);
1814 Error_Msg_N ("possible interpretation#!", N);
1820 -- We have a matching interpretation, Expr_Type is the
1821 -- type from this interpretation, and Seen is the entity.
1823 -- For an operator, just set the entity name. The type will
1824 -- be set by the specific operator resolution routine.
1826 if Nkind (N) in N_Op then
1827 Set_Entity (N, Seen);
1828 Generate_Reference (Seen, N);
1830 elsif Nkind (N) = N_Character_Literal then
1831 Set_Etype (N, Expr_Type);
1833 -- For an explicit dereference, attribute reference, range,
1834 -- short-circuit form (which is not an operator node),
1835 -- or a call with a name that is an explicit dereference,
1836 -- there is nothing to be done at this point.
1838 elsif Nkind (N) = N_Explicit_Dereference
1839 or else Nkind (N) = N_Attribute_Reference
1840 or else Nkind (N) = N_And_Then
1841 or else Nkind (N) = N_Indexed_Component
1842 or else Nkind (N) = N_Or_Else
1843 or else Nkind (N) = N_Range
1844 or else Nkind (N) = N_Selected_Component
1845 or else Nkind (N) = N_Slice
1846 or else Nkind (Name (N)) = N_Explicit_Dereference
1850 -- For procedure or function calls, set the type of the
1851 -- name, and also the entity pointer for the prefix
1853 elsif (Nkind (N) = N_Procedure_Call_Statement
1854 or else Nkind (N) = N_Function_Call)
1855 and then (Is_Entity_Name (Name (N))
1856 or else Nkind (Name (N)) = N_Operator_Symbol)
1858 Set_Etype (Name (N), Expr_Type);
1859 Set_Entity (Name (N), Seen);
1860 Generate_Reference (Seen, Name (N));
1862 elsif Nkind (N) = N_Function_Call
1863 and then Nkind (Name (N)) = N_Selected_Component
1865 Set_Etype (Name (N), Expr_Type);
1866 Set_Entity (Selector_Name (Name (N)), Seen);
1867 Generate_Reference (Seen, Selector_Name (Name (N)));
1869 -- For all other cases, just set the type of the Name
1872 Set_Etype (Name (N), Expr_Type);
1877 -- Move to next interpretation
1879 exit Interp_Loop when not Present (It.Typ);
1881 Get_Next_Interp (I, It);
1882 end loop Interp_Loop;
1885 -- At this stage Found indicates whether or not an acceptable
1886 -- interpretation exists. If not, then we have an error, except
1887 -- that if the context is Any_Type as a result of some other error,
1888 -- then we suppress the error report.
1891 if Typ /= Any_Type then
1893 -- If type we are looking for is Void, then this is the
1894 -- procedure call case, and the error is simply that what
1895 -- we gave is not a procedure name (we think of procedure
1896 -- calls as expressions with types internally, but the user
1897 -- doesn't think of them this way!)
1899 if Typ = Standard_Void_Type then
1901 -- Special case message if function used as a procedure
1903 if Nkind (N) = N_Procedure_Call_Statement
1904 and then Is_Entity_Name (Name (N))
1905 and then Ekind (Entity (Name (N))) = E_Function
1908 ("cannot use function & in a procedure call",
1909 Name (N), Entity (Name (N)));
1911 -- Otherwise give general message (not clear what cases
1912 -- this covers, but no harm in providing for them!)
1915 Error_Msg_N ("expect procedure name in procedure call", N);
1920 -- Otherwise we do have a subexpression with the wrong type
1922 -- Check for the case of an allocator which uses an access
1923 -- type instead of the designated type. This is a common
1924 -- error and we specialize the message, posting an error
1925 -- on the operand of the allocator, complaining that we
1926 -- expected the designated type of the allocator.
1928 elsif Nkind (N) = N_Allocator
1929 and then Ekind (Typ) in Access_Kind
1930 and then Ekind (Etype (N)) in Access_Kind
1931 and then Designated_Type (Etype (N)) = Typ
1933 Wrong_Type (Expression (N), Designated_Type (Typ));
1936 -- Check for view mismatch on Null in instances, for
1937 -- which the view-swapping mechanism has no identifier.
1939 elsif (In_Instance or else In_Inlined_Body)
1940 and then (Nkind (N) = N_Null)
1941 and then Is_Private_Type (Typ)
1942 and then Is_Access_Type (Full_View (Typ))
1944 Resolve (N, Full_View (Typ));
1948 -- Check for an aggregate. Sometimes we can get bogus
1949 -- aggregates from misuse of parentheses, and we are
1950 -- about to complain about the aggregate without even
1951 -- looking inside it.
1953 -- Instead, if we have an aggregate of type Any_Composite,
1954 -- then analyze and resolve the component fields, and then
1955 -- only issue another message if we get no errors doing
1956 -- this (otherwise assume that the errors in the aggregate
1957 -- caused the problem).
1959 elsif Nkind (N) = N_Aggregate
1960 and then Etype (N) = Any_Composite
1962 -- Disable expansion in any case. If there is a type mismatch
1963 -- it may be fatal to try to expand the aggregate. The flag
1964 -- would otherwise be set to false when the error is posted.
1966 Expander_Active := False;
1969 procedure Check_Aggr (Aggr : Node_Id);
1970 -- Check one aggregate, and set Found to True if we
1971 -- have a definite error in any of its elements
1973 procedure Check_Elmt (Aelmt : Node_Id);
1974 -- Check one element of aggregate and set Found to
1975 -- True if we definitely have an error in the element.
1977 procedure Check_Aggr (Aggr : Node_Id) is
1981 if Present (Expressions (Aggr)) then
1982 Elmt := First (Expressions (Aggr));
1983 while Present (Elmt) loop
1989 if Present (Component_Associations (Aggr)) then
1990 Elmt := First (Component_Associations (Aggr));
1991 while Present (Elmt) loop
1992 Check_Elmt (Expression (Elmt));
2002 procedure Check_Elmt (Aelmt : Node_Id) is
2004 -- If we have a nested aggregate, go inside it (to
2005 -- attempt a naked analyze-resolve of the aggregate
2006 -- can cause undesirable cascaded errors). Do not
2007 -- resolve expression if it needs a type from context,
2008 -- as for integer * fixed expression.
2010 if Nkind (Aelmt) = N_Aggregate then
2016 if not Is_Overloaded (Aelmt)
2017 and then Etype (Aelmt) /= Any_Fixed
2022 if Etype (Aelmt) = Any_Type then
2033 -- If an error message was issued already, Found got reset
2034 -- to True, so if it is still False, issue the standard
2035 -- Wrong_Type message.
2038 if Is_Overloaded (N)
2039 and then Nkind (N) = N_Function_Call
2042 Subp_Name : Node_Id;
2044 if Is_Entity_Name (Name (N)) then
2045 Subp_Name := Name (N);
2047 elsif Nkind (Name (N)) = N_Selected_Component then
2049 -- Protected operation: retrieve operation name
2051 Subp_Name := Selector_Name (Name (N));
2053 raise Program_Error;
2056 Error_Msg_Node_2 := Typ;
2057 Error_Msg_NE ("no visible interpretation of&" &
2058 " matches expected type&", N, Subp_Name);
2061 if All_Errors_Mode then
2063 Index : Interp_Index;
2067 Error_Msg_N ("\possible interpretations:", N);
2069 Get_First_Interp (Name (N), Index, It);
2070 while Present (It.Nam) loop
2071 Error_Msg_Sloc := Sloc (It.Nam);
2072 Error_Msg_Node_2 := It.Typ;
2073 Error_Msg_NE ("\& declared#, type&",
2076 Get_Next_Interp (Index, It);
2080 Error_Msg_N ("\use -gnatf for details", N);
2083 Wrong_Type (N, Typ);
2091 -- Test if we have more than one interpretation for the context
2093 elsif Ambiguous then
2097 -- Here we have an acceptable interpretation for the context
2100 -- Propagate type information and normalize tree for various
2101 -- predefined operations. If the context only imposes a class of
2102 -- types, rather than a specific type, propagate the actual type
2105 if Typ = Any_Integer
2106 or else Typ = Any_Boolean
2107 or else Typ = Any_Modular
2108 or else Typ = Any_Real
2109 or else Typ = Any_Discrete
2111 Ctx_Type := Expr_Type;
2113 -- Any_Fixed is legal in a real context only if a specific
2114 -- fixed point type is imposed. If Norman Cohen can be
2115 -- confused by this, it deserves a separate message.
2118 and then Expr_Type = Any_Fixed
2120 Error_Msg_N ("illegal context for mixed mode operation", N);
2121 Set_Etype (N, Universal_Real);
2122 Ctx_Type := Universal_Real;
2126 -- A user-defined operator is tranformed into a function call at
2127 -- this point, so that further processing knows that operators are
2128 -- really operators (i.e. are predefined operators). User-defined
2129 -- operators that are intrinsic are just renamings of the predefined
2130 -- ones, and need not be turned into calls either, but if they rename
2131 -- a different operator, we must transform the node accordingly.
2132 -- Instantiations of Unchecked_Conversion are intrinsic but are
2133 -- treated as functions, even if given an operator designator.
2135 if Nkind (N) in N_Op
2136 and then Present (Entity (N))
2137 and then Ekind (Entity (N)) /= E_Operator
2140 if not Is_Predefined_Op (Entity (N)) then
2141 Rewrite_Operator_As_Call (N, Entity (N));
2143 elsif Present (Alias (Entity (N)))
2145 Nkind (Parent (Parent (Entity (N))))
2146 = N_Subprogram_Renaming_Declaration
2148 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2150 -- If the node is rewritten, it will be fully resolved in
2151 -- Rewrite_Renamed_Operator.
2153 if Analyzed (N) then
2159 case N_Subexpr'(Nkind (N)) is
2161 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2163 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2165 when N_And_Then | N_Or_Else
2166 => Resolve_Short_Circuit (N, Ctx_Type);
2168 when N_Attribute_Reference
2169 => Resolve_Attribute (N, Ctx_Type);
2171 when N_Character_Literal
2172 => Resolve_Character_Literal (N, Ctx_Type);
2174 when N_Conditional_Expression
2175 => Resolve_Conditional_Expression (N, Ctx_Type);
2177 when N_Expanded_Name
2178 => Resolve_Entity_Name (N, Ctx_Type);
2180 when N_Extension_Aggregate
2181 => Resolve_Extension_Aggregate (N, Ctx_Type);
2183 when N_Explicit_Dereference
2184 => Resolve_Explicit_Dereference (N, Ctx_Type);
2186 when N_Function_Call
2187 => Resolve_Call (N, Ctx_Type);
2190 => Resolve_Entity_Name (N, Ctx_Type);
2192 when N_In | N_Not_In
2193 => Resolve_Membership_Op (N, Ctx_Type);
2195 when N_Indexed_Component
2196 => Resolve_Indexed_Component (N, Ctx_Type);
2198 when N_Integer_Literal
2199 => Resolve_Integer_Literal (N, Ctx_Type);
2201 when N_Null => Resolve_Null (N, Ctx_Type);
2203 when N_Op_And | N_Op_Or | N_Op_Xor
2204 => Resolve_Logical_Op (N, Ctx_Type);
2206 when N_Op_Eq | N_Op_Ne
2207 => Resolve_Equality_Op (N, Ctx_Type);
2209 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2210 => Resolve_Comparison_Op (N, Ctx_Type);
2212 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2214 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2215 N_Op_Divide | N_Op_Mod | N_Op_Rem
2217 => Resolve_Arithmetic_Op (N, Ctx_Type);
2219 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2221 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2223 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2224 => Resolve_Unary_Op (N, Ctx_Type);
2226 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2228 when N_Procedure_Call_Statement
2229 => Resolve_Call (N, Ctx_Type);
2231 when N_Operator_Symbol
2232 => Resolve_Operator_Symbol (N, Ctx_Type);
2234 when N_Qualified_Expression
2235 => Resolve_Qualified_Expression (N, Ctx_Type);
2237 when N_Raise_xxx_Error
2238 => Set_Etype (N, Ctx_Type);
2240 when N_Range => Resolve_Range (N, Ctx_Type);
2243 => Resolve_Real_Literal (N, Ctx_Type);
2245 when N_Reference => Resolve_Reference (N, Ctx_Type);
2247 when N_Selected_Component
2248 => Resolve_Selected_Component (N, Ctx_Type);
2250 when N_Slice => Resolve_Slice (N, Ctx_Type);
2252 when N_String_Literal
2253 => Resolve_String_Literal (N, Ctx_Type);
2255 when N_Subprogram_Info
2256 => Resolve_Subprogram_Info (N, Ctx_Type);
2258 when N_Type_Conversion
2259 => Resolve_Type_Conversion (N, Ctx_Type);
2261 when N_Unchecked_Expression =>
2262 Resolve_Unchecked_Expression (N, Ctx_Type);
2264 when N_Unchecked_Type_Conversion =>
2265 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2269 -- If the subexpression was replaced by a non-subexpression, then
2270 -- all we do is to expand it. The only legitimate case we know of
2271 -- is converting procedure call statement to entry call statements,
2272 -- but there may be others, so we are making this test general.
2274 if Nkind (N) not in N_Subexpr then
2275 Debug_A_Exit ("resolving ", N, " (done)");
2280 -- The expression is definitely NOT overloaded at this point, so
2281 -- we reset the Is_Overloaded flag to avoid any confusion when
2282 -- reanalyzing the node.
2284 Set_Is_Overloaded (N, False);
2286 -- Freeze expression type, entity if it is a name, and designated
2287 -- type if it is an allocator (RM 13.14(10,11,13)).
2289 -- Now that the resolution of the type of the node is complete,
2290 -- and we did not detect an error, we can expand this node. We
2291 -- skip the expand call if we are in a default expression, see
2292 -- section "Handling of Default Expressions" in Sem spec.
2294 Debug_A_Exit ("resolving ", N, " (done)");
2296 -- We unconditionally freeze the expression, even if we are in
2297 -- default expression mode (the Freeze_Expression routine tests
2298 -- this flag and only freezes static types if it is set).
2300 Freeze_Expression (N);
2302 -- Now we can do the expansion
2312 -- Version with check(s) suppressed
2314 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2316 if Suppress = All_Checks then
2318 Svg : constant Suppress_Array := Scope_Suppress;
2321 Scope_Suppress := (others => True);
2323 Scope_Suppress := Svg;
2328 Svg : constant Boolean := Scope_Suppress (Suppress);
2331 Scope_Suppress (Suppress) := True;
2333 Scope_Suppress (Suppress) := Svg;
2342 -- Version with implicit type
2344 procedure Resolve (N : Node_Id) is
2346 Resolve (N, Etype (N));
2349 ---------------------
2350 -- Resolve_Actuals --
2351 ---------------------
2353 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2354 Loc : constant Source_Ptr := Sloc (N);
2359 Prev : Node_Id := Empty;
2361 procedure Insert_Default;
2362 -- If the actual is missing in a call, insert in the actuals list
2363 -- an instance of the default expression. The insertion is always
2364 -- a named association.
2366 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2367 -- Check whether T1 and T2, or their full views, are derived from a
2368 -- common type. Used to enforce the restrictions on array conversions
2371 --------------------
2372 -- Insert_Default --
2373 --------------------
2375 procedure Insert_Default is
2380 -- Missing argument in call, nothing to insert
2382 if No (Default_Value (F)) then
2386 -- Note that we do a full New_Copy_Tree, so that any associated
2387 -- Itypes are properly copied. This may not be needed any more,
2388 -- but it does no harm as a safety measure! Defaults of a generic
2389 -- formal may be out of bounds of the corresponding actual (see
2390 -- cc1311b) and an additional check may be required.
2392 Actval := New_Copy_Tree (Default_Value (F),
2393 New_Scope => Current_Scope, New_Sloc => Loc);
2395 if Is_Concurrent_Type (Scope (Nam))
2396 and then Has_Discriminants (Scope (Nam))
2398 Replace_Actual_Discriminants (N, Actval);
2401 if Is_Overloadable (Nam)
2402 and then Present (Alias (Nam))
2404 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2405 and then not Is_Tagged_Type (Etype (F))
2407 -- If default is a real literal, do not introduce a
2408 -- conversion whose effect may depend on the run-time
2409 -- size of universal real.
2411 if Nkind (Actval) = N_Real_Literal then
2412 Set_Etype (Actval, Base_Type (Etype (F)));
2414 Actval := Unchecked_Convert_To (Etype (F), Actval);
2418 if Is_Scalar_Type (Etype (F)) then
2419 Enable_Range_Check (Actval);
2422 Set_Parent (Actval, N);
2424 -- Resolve aggregates with their base type, to avoid scope
2425 -- anomalies: the subtype was first built in the suprogram
2426 -- declaration, and the current call may be nested.
2428 if Nkind (Actval) = N_Aggregate
2429 and then Has_Discriminants (Etype (Actval))
2431 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2433 Analyze_And_Resolve (Actval, Etype (Actval));
2437 Set_Parent (Actval, N);
2439 -- See note above concerning aggregates
2441 if Nkind (Actval) = N_Aggregate
2442 and then Has_Discriminants (Etype (Actval))
2444 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2446 -- Resolve entities with their own type, which may differ
2447 -- from the type of a reference in a generic context (the
2448 -- view swapping mechanism did not anticipate the re-analysis
2449 -- of default values in calls).
2451 elsif Is_Entity_Name (Actval) then
2452 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
2455 Analyze_And_Resolve (Actval, Etype (Actval));
2459 -- If default is a tag indeterminate function call, propagate
2460 -- tag to obtain proper dispatching.
2462 if Is_Controlling_Formal (F)
2463 and then Nkind (Default_Value (F)) = N_Function_Call
2465 Set_Is_Controlling_Actual (Actval);
2470 -- If the default expression raises constraint error, then just
2471 -- silently replace it with an N_Raise_Constraint_Error node,
2472 -- since we already gave the warning on the subprogram spec.
2474 if Raises_Constraint_Error (Actval) then
2476 Make_Raise_Constraint_Error (Loc,
2477 Reason => CE_Range_Check_Failed));
2478 Set_Raises_Constraint_Error (Actval);
2479 Set_Etype (Actval, Etype (F));
2483 Make_Parameter_Association (Loc,
2484 Explicit_Actual_Parameter => Actval,
2485 Selector_Name => Make_Identifier (Loc, Chars (F)));
2487 -- Case of insertion is first named actual
2489 if No (Prev) or else
2490 Nkind (Parent (Prev)) /= N_Parameter_Association
2492 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
2493 Set_First_Named_Actual (N, Actval);
2496 if not Present (Parameter_Associations (N)) then
2497 Set_Parameter_Associations (N, New_List (Assoc));
2499 Append (Assoc, Parameter_Associations (N));
2503 Insert_After (Prev, Assoc);
2506 -- Case of insertion is not first named actual
2509 Set_Next_Named_Actual
2510 (Assoc, Next_Named_Actual (Parent (Prev)));
2511 Set_Next_Named_Actual (Parent (Prev), Actval);
2512 Append (Assoc, Parameter_Associations (N));
2515 Mark_Rewrite_Insertion (Assoc);
2516 Mark_Rewrite_Insertion (Actval);
2525 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
2526 FT1 : Entity_Id := T1;
2527 FT2 : Entity_Id := T2;
2530 if Is_Private_Type (T1)
2531 and then Present (Full_View (T1))
2533 FT1 := Full_View (T1);
2536 if Is_Private_Type (T2)
2537 and then Present (Full_View (T2))
2539 FT2 := Full_View (T2);
2542 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
2545 -- Start of processing for Resolve_Actuals
2548 A := First_Actual (N);
2549 F := First_Formal (Nam);
2550 while Present (F) loop
2551 if No (A) and then Needs_No_Actuals (Nam) then
2554 -- If we have an error in any actual or formal, indicated by
2555 -- a type of Any_Type, then abandon resolution attempt, and
2556 -- set result type to Any_Type.
2558 elsif (Present (A) and then Etype (A) = Any_Type)
2559 or else Etype (F) = Any_Type
2561 Set_Etype (N, Any_Type);
2566 and then (Nkind (Parent (A)) /= N_Parameter_Association
2568 Chars (Selector_Name (Parent (A))) = Chars (F))
2570 -- If the formal is Out or In_Out, do not resolve and expand the
2571 -- conversion, because it is subsequently expanded into explicit
2572 -- temporaries and assignments. However, the object of the
2573 -- conversion can be resolved. An exception is the case of a
2574 -- tagged type conversion with a class-wide actual. In that case
2575 -- we want the tag check to occur and no temporary will be needed
2576 -- (no representation change can occur) and the parameter is
2577 -- passed by reference, so we go ahead and resolve the type
2578 -- conversion. Another excpetion is the case of reference to a
2579 -- component or subcomponent of a bit-packed array, in which case
2580 -- we want to defer expansion to the point the in and out
2581 -- assignments are performed.
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))
2593 if Ada_Version < Ada_05 then
2595 ("both component types in a view conversion must be"
2596 & " aliased, or neither", A);
2598 -- Ada 2005: rule is relaxed (see AI-363)
2600 elsif Has_Aliased_Components (Etype (F))
2602 not Has_Aliased_Components (Etype (Expression (A)))
2605 ("view conversion operand must have aliased " &
2608 ("\since target type has aliased components", N);
2611 elsif not Same_Ancestor (Etype (F), Etype (Expression (A)))
2613 (Is_By_Reference_Type (Etype (F))
2614 or else Is_By_Reference_Type (Etype (Expression (A))))
2617 ("view conversion between unrelated by reference " &
2618 "array types not allowed (\'A'I-00246)", A);
2622 if (Conversion_OK (A)
2623 or else Valid_Conversion (A, Etype (A), Expression (A)))
2624 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
2626 Resolve (Expression (A));
2630 if Nkind (A) = N_Type_Conversion
2631 and then Is_Array_Type (Etype (F))
2632 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
2634 (Is_Limited_Type (Etype (F))
2635 or else Is_Limited_Type (Etype (Expression (A))))
2638 ("conversion between unrelated limited array types " &
2639 "not allowed (\A\I-00246)", A);
2641 if Is_Limited_Type (Etype (F)) then
2642 Explain_Limited_Type (Etype (F), A);
2645 if Is_Limited_Type (Etype (Expression (A))) then
2646 Explain_Limited_Type (Etype (Expression (A)), A);
2650 Resolve (A, Etype (F));
2656 -- Perform error checks for IN and IN OUT parameters
2658 if Ekind (F) /= E_Out_Parameter then
2660 -- Check unset reference. For scalar parameters, it is clearly
2661 -- wrong to pass an uninitialized value as either an IN or
2662 -- IN-OUT parameter. For composites, it is also clearly an
2663 -- error to pass a completely uninitialized value as an IN
2664 -- parameter, but the case of IN OUT is trickier. We prefer
2665 -- not to give a warning here. For example, suppose there is
2666 -- a routine that sets some component of a record to False.
2667 -- It is perfectly reasonable to make this IN-OUT and allow
2668 -- either initialized or uninitialized records to be passed
2671 -- For partially initialized composite values, we also avoid
2672 -- warnings, since it is quite likely that we are passing a
2673 -- partially initialized value and only the initialized fields
2674 -- will in fact be read in the subprogram.
2676 if Is_Scalar_Type (A_Typ)
2677 or else (Ekind (F) = E_In_Parameter
2678 and then not Is_Partially_Initialized_Type (A_Typ))
2680 Check_Unset_Reference (A);
2683 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
2684 -- actual to a nested call, since this is case of reading an
2685 -- out parameter, which is not allowed.
2687 if Ada_Version = Ada_83
2688 and then Is_Entity_Name (A)
2689 and then Ekind (Entity (A)) = E_Out_Parameter
2691 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
2695 if Ekind (F) /= E_In_Parameter
2696 and then not Is_OK_Variable_For_Out_Formal (A)
2698 Error_Msg_NE ("actual for& must be a variable", A, F);
2700 if Is_Entity_Name (A) then
2701 Kill_Checks (Entity (A));
2707 if Etype (A) = Any_Type then
2708 Set_Etype (N, Any_Type);
2712 -- Apply appropriate range checks for in, out, and in-out
2713 -- parameters. Out and in-out parameters also need a separate
2714 -- check, if there is a type conversion, to make sure the return
2715 -- value meets the constraints of the variable before the
2718 -- Gigi looks at the check flag and uses the appropriate types.
2719 -- For now since one flag is used there is an optimization which
2720 -- might not be done in the In Out case since Gigi does not do
2721 -- any analysis. More thought required about this ???
2723 if Ekind (F) = E_In_Parameter
2724 or else Ekind (F) = E_In_Out_Parameter
2726 if Is_Scalar_Type (Etype (A)) then
2727 Apply_Scalar_Range_Check (A, F_Typ);
2729 elsif Is_Array_Type (Etype (A)) then
2730 Apply_Length_Check (A, F_Typ);
2732 elsif Is_Record_Type (F_Typ)
2733 and then Has_Discriminants (F_Typ)
2734 and then Is_Constrained (F_Typ)
2735 and then (not Is_Derived_Type (F_Typ)
2736 or else Comes_From_Source (Nam))
2738 Apply_Discriminant_Check (A, F_Typ);
2740 elsif Is_Access_Type (F_Typ)
2741 and then Is_Array_Type (Designated_Type (F_Typ))
2742 and then Is_Constrained (Designated_Type (F_Typ))
2744 Apply_Length_Check (A, F_Typ);
2746 elsif Is_Access_Type (F_Typ)
2747 and then Has_Discriminants (Designated_Type (F_Typ))
2748 and then Is_Constrained (Designated_Type (F_Typ))
2750 Apply_Discriminant_Check (A, F_Typ);
2753 Apply_Range_Check (A, F_Typ);
2756 -- Ada 2005 (AI-231)
2758 if Ada_Version >= Ada_05
2759 and then Is_Access_Type (F_Typ)
2760 and then Can_Never_Be_Null (F_Typ)
2761 and then Nkind (A) = N_Null
2763 Apply_Compile_Time_Constraint_Error
2765 Msg => "(Ada 2005) NULL not allowed in "
2766 & "null-excluding formal?",
2767 Reason => CE_Null_Not_Allowed);
2771 if Ekind (F) = E_Out_Parameter
2772 or else Ekind (F) = E_In_Out_Parameter
2774 if Nkind (A) = N_Type_Conversion then
2775 if Is_Scalar_Type (A_Typ) then
2776 Apply_Scalar_Range_Check
2777 (Expression (A), Etype (Expression (A)), A_Typ);
2780 (Expression (A), Etype (Expression (A)), A_Typ);
2784 if Is_Scalar_Type (F_Typ) then
2785 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
2787 elsif Is_Array_Type (F_Typ)
2788 and then Ekind (F) = E_Out_Parameter
2790 Apply_Length_Check (A, F_Typ);
2793 Apply_Range_Check (A, A_Typ, F_Typ);
2798 -- An actual associated with an access parameter is implicitly
2799 -- converted to the anonymous access type of the formal and
2800 -- must satisfy the legality checks for access conversions.
2802 if Ekind (F_Typ) = E_Anonymous_Access_Type then
2803 if not Valid_Conversion (A, F_Typ, A) then
2805 ("invalid implicit conversion for access parameter", A);
2809 -- Check bad case of atomic/volatile argument (RM C.6(12))
2811 if Is_By_Reference_Type (Etype (F))
2812 and then Comes_From_Source (N)
2814 if Is_Atomic_Object (A)
2815 and then not Is_Atomic (Etype (F))
2818 ("cannot pass atomic argument to non-atomic formal",
2821 elsif Is_Volatile_Object (A)
2822 and then not Is_Volatile (Etype (F))
2825 ("cannot pass volatile argument to non-volatile formal",
2830 -- Check that subprograms don't have improper controlling
2831 -- arguments (RM 3.9.2 (9))
2833 if Is_Controlling_Formal (F) then
2834 Set_Is_Controlling_Actual (A);
2835 elsif Nkind (A) = N_Explicit_Dereference then
2836 Validate_Remote_Access_To_Class_Wide_Type (A);
2839 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
2840 and then not Is_Class_Wide_Type (F_Typ)
2841 and then not Is_Controlling_Formal (F)
2843 Error_Msg_N ("class-wide argument not allowed here!", A);
2845 if Is_Subprogram (Nam)
2846 and then Comes_From_Source (Nam)
2848 Error_Msg_Node_2 := F_Typ;
2850 ("& is not a dispatching operation of &!", A, Nam);
2853 elsif Is_Access_Type (A_Typ)
2854 and then Is_Access_Type (F_Typ)
2855 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
2856 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
2857 or else (Nkind (A) = N_Attribute_Reference
2859 Is_Class_Wide_Type (Etype (Prefix (A)))))
2860 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
2861 and then not Is_Controlling_Formal (F)
2864 ("access to class-wide argument not allowed here!", A);
2866 if Is_Subprogram (Nam)
2867 and then Comes_From_Source (Nam)
2869 Error_Msg_Node_2 := Designated_Type (F_Typ);
2871 ("& is not a dispatching operation of &!", A, Nam);
2877 -- If it is a named association, treat the selector_name as
2878 -- a proper identifier, and mark the corresponding entity.
2880 if Nkind (Parent (A)) = N_Parameter_Association then
2881 Set_Entity (Selector_Name (Parent (A)), F);
2882 Generate_Reference (F, Selector_Name (Parent (A)));
2883 Set_Etype (Selector_Name (Parent (A)), F_Typ);
2884 Generate_Reference (F_Typ, N, ' ');
2889 if Ekind (F) /= E_Out_Parameter then
2890 Check_Unset_Reference (A);
2895 -- Case where actual is not present
2903 end Resolve_Actuals;
2905 -----------------------
2906 -- Resolve_Allocator --
2907 -----------------------
2909 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
2910 E : constant Node_Id := Expression (N);
2912 Discrim : Entity_Id;
2916 function In_Dispatching_Context return Boolean;
2917 -- If the allocator is an actual in a call, it is allowed to be
2918 -- class-wide when the context is not because it is a controlling
2921 ----------------------------
2922 -- In_Dispatching_Context --
2923 ----------------------------
2925 function In_Dispatching_Context return Boolean is
2926 Par : constant Node_Id := Parent (N);
2929 return (Nkind (Par) = N_Function_Call
2930 or else Nkind (Par) = N_Procedure_Call_Statement)
2931 and then Is_Entity_Name (Name (Par))
2932 and then Is_Dispatching_Operation (Entity (Name (Par)));
2933 end In_Dispatching_Context;
2935 -- Start of processing for Resolve_Allocator
2938 -- Replace general access with specific type
2940 if Ekind (Etype (N)) = E_Allocator_Type then
2941 Set_Etype (N, Base_Type (Typ));
2944 if Is_Abstract (Typ) then
2945 Error_Msg_N ("type of allocator cannot be abstract", N);
2948 -- For qualified expression, resolve the expression using the
2949 -- given subtype (nothing to do for type mark, subtype indication)
2951 if Nkind (E) = N_Qualified_Expression then
2952 if Is_Class_Wide_Type (Etype (E))
2953 and then not Is_Class_Wide_Type (Designated_Type (Typ))
2954 and then not In_Dispatching_Context
2957 ("class-wide allocator not allowed for this access type", N);
2960 Resolve (Expression (E), Etype (E));
2961 Check_Unset_Reference (Expression (E));
2963 -- A qualified expression requires an exact match of the type,
2964 -- class-wide matching is not allowed.
2966 if (Is_Class_Wide_Type (Etype (Expression (E)))
2967 or else Is_Class_Wide_Type (Etype (E)))
2968 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
2970 Wrong_Type (Expression (E), Etype (E));
2973 -- For a subtype mark or subtype indication, freeze the subtype
2976 Freeze_Expression (E);
2978 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
2980 ("initialization required for access-to-constant allocator", N);
2983 -- A special accessibility check is needed for allocators that
2984 -- constrain access discriminants. The level of the type of the
2985 -- expression used to contrain an access discriminant cannot be
2986 -- deeper than the type of the allocator (in constrast to access
2987 -- parameters, where the level of the actual can be arbitrary).
2988 -- We can't use Valid_Conversion to perform this check because
2989 -- in general the type of the allocator is unrelated to the type
2990 -- of the access discriminant. Note that specialized checks are
2991 -- needed for the cases of a constraint expression which is an
2992 -- access attribute or an access discriminant.
2994 if Nkind (Original_Node (E)) = N_Subtype_Indication
2995 and then Ekind (Typ) /= E_Anonymous_Access_Type
2997 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
2999 if Has_Discriminants (Subtyp) then
3000 Discrim := First_Discriminant (Base_Type (Subtyp));
3001 Constr := First (Constraints (Constraint (Original_Node (E))));
3002 while Present (Discrim) and then Present (Constr) loop
3003 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
3004 if Nkind (Constr) = N_Discriminant_Association then
3005 Disc_Exp := Original_Node (Expression (Constr));
3007 Disc_Exp := Original_Node (Constr);
3010 if Type_Access_Level (Etype (Disc_Exp))
3011 > Type_Access_Level (Typ)
3014 ("operand type has deeper level than allocator type",
3017 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3018 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3020 and then Object_Access_Level (Prefix (Disc_Exp))
3021 > Type_Access_Level (Typ)
3024 ("prefix of attribute has deeper level than"
3025 & " allocator type", Disc_Exp);
3027 -- When the operand is an access discriminant the check
3028 -- is against the level of the prefix object.
3030 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3031 and then Nkind (Disc_Exp) = N_Selected_Component
3032 and then Object_Access_Level (Prefix (Disc_Exp))
3033 > Type_Access_Level (Typ)
3036 ("access discriminant has deeper level than"
3037 & " allocator type", Disc_Exp);
3040 Next_Discriminant (Discrim);
3047 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
3048 -- check that the level of the type of the created object is not deeper
3049 -- than the level of the allocator's access type, since extensions can
3050 -- now occur at deeper levels than their ancestor types. This is a
3051 -- static accessibility level check; a run-time check is also needed in
3052 -- the case of an initialized allocator with a class-wide argument (see
3053 -- Expand_Allocator_Expression).
3055 if Ada_Version >= Ada_05
3056 and then Is_Class_Wide_Type (Designated_Type (Typ))
3059 Exp_Typ : Entity_Id;
3062 if Nkind (E) = N_Qualified_Expression then
3063 Exp_Typ := Etype (E);
3064 elsif Nkind (E) = N_Subtype_Indication then
3065 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
3067 Exp_Typ := Entity (E);
3070 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
3071 if In_Instance_Body then
3072 Error_Msg_N ("?type in allocator has deeper level than" &
3073 " designated class-wide type", E);
3074 Error_Msg_N ("?Program_Error will be raised at run time", E);
3076 Make_Raise_Program_Error (Sloc (N),
3077 Reason => PE_Accessibility_Check_Failed));
3080 Error_Msg_N ("type in allocator has deeper level than" &
3081 " designated class-wide type", E);
3087 -- Check for allocation from an empty storage pool
3089 if No_Pool_Assigned (Typ) then
3091 Loc : constant Source_Ptr := Sloc (N);
3093 Error_Msg_N ("?allocation from empty storage pool!", N);
3094 Error_Msg_N ("?Storage_Error will be raised at run time!", N);
3096 Make_Raise_Storage_Error (Loc,
3097 Reason => SE_Empty_Storage_Pool));
3100 -- If the context is an unchecked conversion, as may happen within
3101 -- an inlined subprogram, the allocator is being resolved with its
3102 -- own anonymous type. In that case, if the target type has a specific
3103 -- storage pool, it must be inherited explicitly by the allocator type.
3105 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
3106 and then No (Associated_Storage_Pool (Typ))
3108 Set_Associated_Storage_Pool
3109 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
3111 end Resolve_Allocator;
3113 ---------------------------
3114 -- Resolve_Arithmetic_Op --
3115 ---------------------------
3117 -- Used for resolving all arithmetic operators except exponentiation
3119 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
3120 L : constant Node_Id := Left_Opnd (N);
3121 R : constant Node_Id := Right_Opnd (N);
3122 TL : constant Entity_Id := Base_Type (Etype (L));
3123 TR : constant Entity_Id := Base_Type (Etype (R));
3127 B_Typ : constant Entity_Id := Base_Type (Typ);
3128 -- We do the resolution using the base type, because intermediate values
3129 -- in expressions always are of the base type, not a subtype of it.
3131 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
3132 -- Return True iff given type is Integer or universal real/integer
3134 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
3135 -- Choose type of integer literal in fixed-point operation to conform
3136 -- to available fixed-point type. T is the type of the other operand,
3137 -- which is needed to determine the expected type of N.
3139 procedure Set_Operand_Type (N : Node_Id);
3140 -- Set operand type to T if universal
3142 -----------------------------
3143 -- Is_Integer_Or_Universal --
3144 -----------------------------
3146 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
3148 Index : Interp_Index;
3152 if not Is_Overloaded (N) then
3154 return Base_Type (T) = Base_Type (Standard_Integer)
3155 or else T = Universal_Integer
3156 or else T = Universal_Real;
3158 Get_First_Interp (N, Index, It);
3159 while Present (It.Typ) loop
3160 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
3161 or else It.Typ = Universal_Integer
3162 or else It.Typ = Universal_Real
3167 Get_Next_Interp (Index, It);
3172 end Is_Integer_Or_Universal;
3174 ----------------------------
3175 -- Set_Mixed_Mode_Operand --
3176 ----------------------------
3178 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
3179 Index : Interp_Index;
3183 if Universal_Interpretation (N) = Universal_Integer then
3185 -- A universal integer literal is resolved as standard integer
3186 -- except in the case of a fixed-point result, where we leave it
3187 -- as universal (to be handled by Exp_Fixd later on)
3189 if Is_Fixed_Point_Type (T) then
3190 Resolve (N, Universal_Integer);
3192 Resolve (N, Standard_Integer);
3195 elsif Universal_Interpretation (N) = Universal_Real
3196 and then (T = Base_Type (Standard_Integer)
3197 or else T = Universal_Integer
3198 or else T = Universal_Real)
3200 -- A universal real can appear in a fixed-type context. We resolve
3201 -- the literal with that context, even though this might raise an
3202 -- exception prematurely (the other operand may be zero).
3206 elsif Etype (N) = Base_Type (Standard_Integer)
3207 and then T = Universal_Real
3208 and then Is_Overloaded (N)
3210 -- Integer arg in mixed-mode operation. Resolve with universal
3211 -- type, in case preference rule must be applied.
3213 Resolve (N, Universal_Integer);
3216 and then B_Typ /= Universal_Fixed
3218 -- Not a mixed-mode operation, resolve with context
3222 elsif Etype (N) = Any_Fixed then
3224 -- N may itself be a mixed-mode operation, so use context type
3228 elsif Is_Fixed_Point_Type (T)
3229 and then B_Typ = Universal_Fixed
3230 and then Is_Overloaded (N)
3232 -- Must be (fixed * fixed) operation, operand must have one
3233 -- compatible interpretation.
3235 Resolve (N, Any_Fixed);
3237 elsif Is_Fixed_Point_Type (B_Typ)
3238 and then (T = Universal_Real
3239 or else Is_Fixed_Point_Type (T))
3240 and then Is_Overloaded (N)
3242 -- C * F(X) in a fixed context, where C is a real literal or a
3243 -- fixed-point expression. F must have either a fixed type
3244 -- interpretation or an integer interpretation, but not both.
3246 Get_First_Interp (N, Index, It);
3247 while Present (It.Typ) loop
3248 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
3250 if Analyzed (N) then
3251 Error_Msg_N ("ambiguous operand in fixed operation", N);
3253 Resolve (N, Standard_Integer);
3256 elsif Is_Fixed_Point_Type (It.Typ) then
3258 if Analyzed (N) then
3259 Error_Msg_N ("ambiguous operand in fixed operation", N);
3261 Resolve (N, It.Typ);
3265 Get_Next_Interp (Index, It);
3268 -- Reanalyze the literal with the fixed type of the context. If
3269 -- context is Universal_Fixed, we are within a conversion, leave
3270 -- the literal as a universal real because there is no usable
3271 -- fixed type, and the target of the conversion plays no role in
3285 if B_Typ = Universal_Fixed
3286 and then Nkind (Op2) = N_Real_Literal
3288 T2 := Universal_Real;
3293 Set_Analyzed (Op2, False);
3300 end Set_Mixed_Mode_Operand;
3302 ----------------------
3303 -- Set_Operand_Type --
3304 ----------------------
3306 procedure Set_Operand_Type (N : Node_Id) is
3308 if Etype (N) = Universal_Integer
3309 or else Etype (N) = Universal_Real
3313 end Set_Operand_Type;
3315 -- Start of processing for Resolve_Arithmetic_Op
3318 if Comes_From_Source (N)
3319 and then Ekind (Entity (N)) = E_Function
3320 and then Is_Imported (Entity (N))
3321 and then Is_Intrinsic_Subprogram (Entity (N))
3323 Resolve_Intrinsic_Operator (N, Typ);
3326 -- Special-case for mixed-mode universal expressions or fixed point
3327 -- type operation: each argument is resolved separately. The same
3328 -- treatment is required if one of the operands of a fixed point
3329 -- operation is universal real, since in this case we don't do a
3330 -- conversion to a specific fixed-point type (instead the expander
3331 -- takes care of the case).
3333 elsif (B_Typ = Universal_Integer
3334 or else B_Typ = Universal_Real)
3335 and then Present (Universal_Interpretation (L))
3336 and then Present (Universal_Interpretation (R))
3338 Resolve (L, Universal_Interpretation (L));
3339 Resolve (R, Universal_Interpretation (R));
3340 Set_Etype (N, B_Typ);
3342 elsif (B_Typ = Universal_Real
3343 or else Etype (N) = Universal_Fixed
3344 or else (Etype (N) = Any_Fixed
3345 and then Is_Fixed_Point_Type (B_Typ))
3346 or else (Is_Fixed_Point_Type (B_Typ)
3347 and then (Is_Integer_Or_Universal (L)
3349 Is_Integer_Or_Universal (R))))
3350 and then (Nkind (N) = N_Op_Multiply or else
3351 Nkind (N) = N_Op_Divide)
3353 if TL = Universal_Integer or else TR = Universal_Integer then
3354 Check_For_Visible_Operator (N, B_Typ);
3357 -- If context is a fixed type and one operand is integer, the
3358 -- other is resolved with the type of the context.
3360 if Is_Fixed_Point_Type (B_Typ)
3361 and then (Base_Type (TL) = Base_Type (Standard_Integer)
3362 or else TL = Universal_Integer)
3367 elsif Is_Fixed_Point_Type (B_Typ)
3368 and then (Base_Type (TR) = Base_Type (Standard_Integer)
3369 or else TR = Universal_Integer)
3375 Set_Mixed_Mode_Operand (L, TR);
3376 Set_Mixed_Mode_Operand (R, TL);
3379 if Etype (N) = Universal_Fixed
3380 or else Etype (N) = Any_Fixed
3382 if B_Typ = Universal_Fixed
3383 and then Nkind (Parent (N)) /= N_Type_Conversion
3384 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3387 ("type cannot be determined from context!", N);
3389 ("\explicit conversion to result type required", N);
3391 Set_Etype (L, Any_Type);
3392 Set_Etype (R, Any_Type);
3395 if Ada_Version = Ada_83
3396 and then Etype (N) = Universal_Fixed
3397 and then Nkind (Parent (N)) /= N_Type_Conversion
3398 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3401 ("(Ada 83) fixed-point operation " &
3402 "needs explicit conversion",
3406 Set_Etype (N, B_Typ);
3409 elsif Is_Fixed_Point_Type (B_Typ)
3410 and then (Is_Integer_Or_Universal (L)
3411 or else Nkind (L) = N_Real_Literal
3412 or else Nkind (R) = N_Real_Literal
3414 Is_Integer_Or_Universal (R))
3416 Set_Etype (N, B_Typ);
3418 elsif Etype (N) = Any_Fixed then
3420 -- If no previous errors, this is only possible if one operand
3421 -- is overloaded and the context is universal. Resolve as such.
3423 Set_Etype (N, B_Typ);
3427 if (TL = Universal_Integer or else TL = Universal_Real)
3428 and then (TR = Universal_Integer or else TR = Universal_Real)
3430 Check_For_Visible_Operator (N, B_Typ);
3433 -- If the context is Universal_Fixed and the operands are also
3434 -- universal fixed, this is an error, unless there is only one
3435 -- applicable fixed_point type (usually duration).
3437 if B_Typ = Universal_Fixed
3438 and then Etype (L) = Universal_Fixed
3440 T := Unique_Fixed_Point_Type (N);
3442 if T = Any_Type then
3455 -- If one of the arguments was resolved to a non-universal type.
3456 -- label the result of the operation itself with the same type.
3457 -- Do the same for the universal argument, if any.
3459 T := Intersect_Types (L, R);
3460 Set_Etype (N, Base_Type (T));
3461 Set_Operand_Type (L);
3462 Set_Operand_Type (R);
3465 Generate_Operator_Reference (N, Typ);
3466 Eval_Arithmetic_Op (N);
3468 -- Set overflow and division checking bit. Much cleverer code needed
3469 -- here eventually and perhaps the Resolve routines should be separated
3470 -- for the various arithmetic operations, since they will need
3471 -- different processing. ???
3473 if Nkind (N) in N_Op then
3474 if not Overflow_Checks_Suppressed (Etype (N)) then
3475 Enable_Overflow_Check (N);
3478 -- Give warning if explicit division by zero
3480 if (Nkind (N) = N_Op_Divide
3481 or else Nkind (N) = N_Op_Rem
3482 or else Nkind (N) = N_Op_Mod)
3483 and then not Division_Checks_Suppressed (Etype (N))
3485 Rop := Right_Opnd (N);
3487 if Compile_Time_Known_Value (Rop)
3488 and then ((Is_Integer_Type (Etype (Rop))
3489 and then Expr_Value (Rop) = Uint_0)
3491 (Is_Real_Type (Etype (Rop))
3492 and then Expr_Value_R (Rop) = Ureal_0))
3494 Apply_Compile_Time_Constraint_Error
3495 (N, "division by zero?", CE_Divide_By_Zero,
3496 Loc => Sloc (Right_Opnd (N)));
3498 -- Otherwise just set the flag to check at run time
3501 Set_Do_Division_Check (N);
3506 Check_Unset_Reference (L);
3507 Check_Unset_Reference (R);
3508 end Resolve_Arithmetic_Op;
3514 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
3515 Loc : constant Source_Ptr := Sloc (N);
3516 Subp : constant Node_Id := Name (N);
3525 -- The context imposes a unique interpretation with type Typ on a
3526 -- procedure or function call. Find the entity of the subprogram that
3527 -- yields the expected type, and propagate the corresponding formal
3528 -- constraints on the actuals. The caller has established that an
3529 -- interpretation exists, and emitted an error if not unique.
3531 -- First deal with the case of a call to an access-to-subprogram,
3532 -- dereference made explicit in Analyze_Call.
3534 if Ekind (Etype (Subp)) = E_Subprogram_Type then
3535 if not Is_Overloaded (Subp) then
3536 Nam := Etype (Subp);
3539 -- Find the interpretation whose type (a subprogram type) has a
3540 -- return type that is compatible with the context. Analysis of
3541 -- the node has established that one exists.
3545 Get_First_Interp (Subp, I, It);
3546 while Present (It.Typ) loop
3547 if Covers (Typ, Etype (It.Typ)) then
3552 Get_Next_Interp (I, It);
3556 raise Program_Error;
3560 -- If the prefix is not an entity, then resolve it
3562 if not Is_Entity_Name (Subp) then
3563 Resolve (Subp, Nam);
3566 -- For an indirect call, we always invalidate checks, since we do not
3567 -- know whether the subprogram is local or global. Yes we could do
3568 -- better here, e.g. by knowing that there are no local subprograms,
3569 -- but it does not seem worth the effort. Similarly, we kill al
3570 -- knowledge of current constant values.
3572 Kill_Current_Values;
3574 -- If this is a procedure call which is really an entry call, do the
3575 -- conversion of the procedure call to an entry call. Protected
3576 -- operations use the same circuitry because the name in the call can be
3577 -- an arbitrary expression with special resolution rules.
3579 elsif Nkind (Subp) = N_Selected_Component
3580 or else Nkind (Subp) = N_Indexed_Component
3581 or else (Is_Entity_Name (Subp)
3582 and then Ekind (Entity (Subp)) = E_Entry)
3584 Resolve_Entry_Call (N, Typ);
3585 Check_Elab_Call (N);
3587 -- Kill checks and constant values, as above for indirect case
3588 -- Who knows what happens when another task is activated?
3590 Kill_Current_Values;
3593 -- Normal subprogram call with name established in Resolve
3595 elsif not (Is_Type (Entity (Subp))) then
3596 Nam := Entity (Subp);
3597 Set_Entity_With_Style_Check (Subp, Nam);
3598 Generate_Reference (Nam, Subp);
3600 -- Otherwise we must have the case of an overloaded call
3603 pragma Assert (Is_Overloaded (Subp));
3604 Nam := Empty; -- We know that it will be assigned in loop below
3606 Get_First_Interp (Subp, I, It);
3607 while Present (It.Typ) loop
3608 if Covers (Typ, It.Typ) then
3610 Set_Entity_With_Style_Check (Subp, Nam);
3611 Generate_Reference (Nam, Subp);
3615 Get_Next_Interp (I, It);
3619 -- Check that a call to Current_Task does not occur in an entry body
3621 if Is_RTE (Nam, RE_Current_Task) then
3631 if Nkind (P) = N_Entry_Body then
3633 ("& should not be used in entry body ('R'M C.7(17))",
3641 -- Cannot call thread body directly
3643 if Is_Thread_Body (Nam) then
3644 Error_Msg_N ("cannot call thread body directly", N);
3647 -- If the subprogram is not global, then kill all checks. This is a bit
3648 -- conservative, since in many cases we could do better, but it is not
3649 -- worth the effort. Similarly, we kill constant values. However we do
3650 -- not need to do this for internal entities (unless they are inherited
3651 -- user-defined subprograms), since they are not in the business of
3652 -- molesting global values.
3654 if not Is_Library_Level_Entity (Nam)
3655 and then (Comes_From_Source (Nam)
3656 or else (Present (Alias (Nam))
3657 and then Comes_From_Source (Alias (Nam))))
3659 Kill_Current_Values;
3662 -- Deal with call to obsolescent subprogram. Note that we always allow
3663 -- such calls in the compiler itself and the run-time, since we assume
3664 -- that we know what we are doing in such cases. For example, the calls
3665 -- in Ada.Characters.Handling to its own obsolescent subprograms are
3668 if Is_Obsolescent (Nam) and then not GNAT_Mode then
3669 Check_Restriction (No_Obsolescent_Features, N);
3671 if Warn_On_Obsolescent_Feature then
3672 Error_Msg_NE ("call to obsolescent subprogram&?", N, Nam);
3674 -- Output additional warning if present
3676 W := Obsolescent_Warning (Nam);
3679 Name_Buffer (1) := '|';
3680 Name_Buffer (2) := '?';
3683 -- Add characters to message, and output message
3685 for J in 1 .. String_Length (Strval (W)) loop
3686 Add_Char_To_Name_Buffer (''');
3687 Add_Char_To_Name_Buffer
3688 (Get_Character (Get_String_Char (Strval (W), J)));
3691 Error_Msg_N (Name_Buffer (1 .. Name_Len), N);
3696 -- Check that a procedure call does not occur in the context of the
3697 -- entry call statement of a conditional or timed entry call. Note that
3698 -- the case of a call to a subprogram renaming of an entry will also be
3699 -- rejected. The test for N not being an N_Entry_Call_Statement is
3700 -- defensive, covering the possibility that the processing of entry
3701 -- calls might reach this point due to later modifications of the code
3704 if Nkind (Parent (N)) = N_Entry_Call_Alternative
3705 and then Nkind (N) /= N_Entry_Call_Statement
3706 and then Entry_Call_Statement (Parent (N)) = N
3708 if Ada_Version < Ada_05 then
3709 Error_Msg_N ("entry call required in select statement", N);
3711 -- Ada 2005 (AI-345): If a procedure_call_statement is used
3712 -- for a procedure_or_entry_call, the procedure_name or pro-
3713 -- cedure_prefix of the procedure_call_statement shall denote
3714 -- an entry renamed by a procedure, or (a view of) a primitive
3715 -- subprogram of a limited interface whose first parameter is
3716 -- a controlling parameter.
3718 elsif Nkind (N) = N_Procedure_Call_Statement
3719 and then not Is_Renamed_Entry (Nam)
3720 and then not Is_Controlling_Limited_Procedure (Nam)
3723 ("procedure or entry call required in select statement", N);
3727 -- Check that this is not a call to a protected procedure or
3728 -- entry from within a protected function.
3730 if Ekind (Current_Scope) = E_Function
3731 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
3732 and then Ekind (Nam) /= E_Function
3733 and then Scope (Nam) = Scope (Current_Scope)
3735 Error_Msg_N ("within protected function, protected " &
3736 "object is constant", N);
3737 Error_Msg_N ("\cannot call operation that may modify it", N);
3740 -- Freeze the subprogram name if not in default expression. Note that we
3741 -- freeze procedure calls as well as function calls. Procedure calls are
3742 -- not frozen according to the rules (RM 13.14(14)) because it is
3743 -- impossible to have a procedure call to a non-frozen procedure in pure
3744 -- Ada, but in the code that we generate in the expander, this rule
3745 -- needs extending because we can generate procedure calls that need
3748 if Is_Entity_Name (Subp) and then not In_Default_Expression then
3749 Freeze_Expression (Subp);
3752 -- For a predefined operator, the type of the result is the type imposed
3753 -- by context, except for a predefined operation on universal fixed.
3754 -- Otherwise The type of the call is the type returned by the subprogram
3757 if Is_Predefined_Op (Nam) then
3758 if Etype (N) /= Universal_Fixed then
3762 -- If the subprogram returns an array type, and the context requires the
3763 -- component type of that array type, the node is really an indexing of
3764 -- the parameterless call. Resolve as such. A pathological case occurs
3765 -- when the type of the component is an access to the array type. In
3766 -- this case the call is truly ambiguous.
3768 elsif Needs_No_Actuals (Nam)
3770 ((Is_Array_Type (Etype (Nam))
3771 and then Covers (Typ, Component_Type (Etype (Nam))))
3772 or else (Is_Access_Type (Etype (Nam))
3773 and then Is_Array_Type (Designated_Type (Etype (Nam)))
3776 Component_Type (Designated_Type (Etype (Nam))))))
3779 Index_Node : Node_Id;
3781 Ret_Type : constant Entity_Id := Etype (Nam);
3784 if Is_Access_Type (Ret_Type)
3785 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
3788 ("cannot disambiguate function call and indexing", N);
3790 New_Subp := Relocate_Node (Subp);
3791 Set_Entity (Subp, Nam);
3793 if Component_Type (Ret_Type) /= Any_Type then
3795 Make_Indexed_Component (Loc,
3797 Make_Function_Call (Loc,
3799 Expressions => Parameter_Associations (N));
3801 -- Since we are correcting a node classification error made
3802 -- by the parser, we call Replace rather than Rewrite.
3804 Replace (N, Index_Node);
3805 Set_Etype (Prefix (N), Ret_Type);
3807 Resolve_Indexed_Component (N, Typ);
3808 Check_Elab_Call (Prefix (N));
3816 Set_Etype (N, Etype (Nam));
3819 -- In the case where the call is to an overloaded subprogram, Analyze
3820 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
3821 -- such a case Normalize_Actuals needs to be called once more to order
3822 -- the actuals correctly. Otherwise the call will have the ordering
3823 -- given by the last overloaded subprogram whether this is the correct
3824 -- one being called or not.
3826 if Is_Overloaded (Subp) then
3827 Normalize_Actuals (N, Nam, False, Norm_OK);
3828 pragma Assert (Norm_OK);
3831 -- In any case, call is fully resolved now. Reset Overload flag, to
3832 -- prevent subsequent overload resolution if node is analyzed again
3834 Set_Is_Overloaded (Subp, False);
3835 Set_Is_Overloaded (N, False);
3837 -- If we are calling the current subprogram from immediately within its
3838 -- body, then that is the case where we can sometimes detect cases of
3839 -- infinite recursion statically. Do not try this in case restriction
3840 -- No_Recursion is in effect anyway.
3842 Scop := Current_Scope;
3845 and then not Restriction_Active (No_Recursion)
3846 and then Check_Infinite_Recursion (N)
3848 -- Here we detected and flagged an infinite recursion, so we do
3849 -- not need to test the case below for further warnings.
3853 -- If call is to immediately containing subprogram, then check for
3854 -- the case of a possible run-time detectable infinite recursion.
3857 while Scop /= Standard_Standard loop
3859 -- Although in general recursion is not statically checkable,
3860 -- the case of calling an immediately containing subprogram
3861 -- is easy to catch.
3863 Check_Restriction (No_Recursion, N);
3865 -- If the recursive call is to a parameterless procedure, then
3866 -- even if we can't statically detect infinite recursion, this
3867 -- is pretty suspicious, and we output a warning. Furthermore,
3868 -- we will try later to detect some cases here at run time by
3869 -- expanding checking code (see Detect_Infinite_Recursion in
3870 -- package Exp_Ch6).
3872 -- If the recursive call is within a handler we do not emit a
3873 -- warning, because this is a common idiom: loop until input
3874 -- is correct, catch illegal input in handler and restart.
3876 if No (First_Formal (Nam))
3877 and then Etype (Nam) = Standard_Void_Type
3878 and then not Error_Posted (N)
3879 and then Nkind (Parent (N)) /= N_Exception_Handler
3881 Set_Has_Recursive_Call (Nam);
3882 Error_Msg_N ("possible infinite recursion?", N);
3883 Error_Msg_N ("Storage_Error may be raised at run time?", N);
3889 Scop := Scope (Scop);
3893 -- If subprogram name is a predefined operator, it was given in
3894 -- functional notation. Replace call node with operator node, so
3895 -- that actuals can be resolved appropriately.
3897 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
3898 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
3901 elsif Present (Alias (Nam))
3902 and then Is_Predefined_Op (Alias (Nam))
3904 Resolve_Actuals (N, Nam);
3905 Make_Call_Into_Operator (N, Typ, Alias (Nam));
3909 -- Create a transient scope if the resulting type requires it
3911 -- There are 3 notable exceptions: in init procs, the transient scope
3912 -- overhead is not needed and even incorrect due to the actual expansion
3913 -- of adjust calls; the second case is enumeration literal pseudo calls,
3914 -- the other case is intrinsic subprograms (Unchecked_Conversion and
3915 -- source information functions) that do not use the secondary stack
3916 -- even though the return type is unconstrained.
3918 -- If this is an initialization call for a type whose initialization
3919 -- uses the secondary stack, we also need to create a transient scope
3920 -- for it, precisely because we will not do it within the init proc
3924 and then Is_Type (Etype (Nam))
3925 and then Requires_Transient_Scope (Etype (Nam))
3926 and then Ekind (Nam) /= E_Enumeration_Literal
3927 and then not Within_Init_Proc
3928 and then not Is_Intrinsic_Subprogram (Nam)
3930 Establish_Transient_Scope
3931 (N, Sec_Stack => not Functions_Return_By_DSP_On_Target);
3933 -- If the call appears within the bounds of a loop, it will
3934 -- be rewritten and reanalyzed, nothing left to do here.
3936 if Nkind (N) /= N_Function_Call then
3940 elsif Is_Init_Proc (Nam)
3941 and then not Within_Init_Proc
3943 Check_Initialization_Call (N, Nam);
3946 -- A protected function cannot be called within the definition of the
3947 -- enclosing protected type.
3949 if Is_Protected_Type (Scope (Nam))
3950 and then In_Open_Scopes (Scope (Nam))
3951 and then not Has_Completion (Scope (Nam))
3954 ("& cannot be called before end of protected definition", N, Nam);
3957 -- Propagate interpretation to actuals, and add default expressions
3960 if Present (First_Formal (Nam)) then
3961 Resolve_Actuals (N, Nam);
3963 -- Overloaded literals are rewritten as function calls, for
3964 -- purpose of resolution. After resolution, we can replace
3965 -- the call with the literal itself.
3967 elsif Ekind (Nam) = E_Enumeration_Literal then
3968 Copy_Node (Subp, N);
3969 Resolve_Entity_Name (N, Typ);
3971 -- Avoid validation, since it is a static function call
3976 -- If the subprogram is a primitive operation, check whether or not
3977 -- it is a correct dispatching call.
3979 if Is_Overloadable (Nam)
3980 and then Is_Dispatching_Operation (Nam)
3982 Check_Dispatching_Call (N);
3984 elsif Is_Abstract (Nam)
3985 and then not In_Instance
3987 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
3990 if Is_Intrinsic_Subprogram (Nam) then
3991 Check_Intrinsic_Call (N);
3995 Check_Elab_Call (N);
3998 -------------------------------
3999 -- Resolve_Character_Literal --
4000 -------------------------------
4002 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
4003 B_Typ : constant Entity_Id := Base_Type (Typ);
4007 -- Verify that the character does belong to the type of the context
4009 Set_Etype (N, B_Typ);
4010 Eval_Character_Literal (N);
4012 -- Wide_Wide_Character literals must always be defined, since the set
4013 -- of wide wide character literals is complete, i.e. if a character
4014 -- literal is accepted by the parser, then it is OK for wide wide
4015 -- character (out of range character literals are rejected).
4017 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
4020 -- Always accept character literal for type Any_Character, which
4021 -- occurs in error situations and in comparisons of literals, both
4022 -- of which should accept all literals.
4024 elsif B_Typ = Any_Character then
4027 -- For Standard.Character or a type derived from it, check that
4028 -- the literal is in range
4030 elsif Root_Type (B_Typ) = Standard_Character then
4031 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
4035 -- For Standard.Wide_Character or a type derived from it, check
4036 -- that the literal is in range
4038 elsif Root_Type (B_Typ) = Standard_Wide_Character then
4039 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
4043 -- For Standard.Wide_Wide_Character or a type derived from it, we
4044 -- know the literal is in range, since the parser checked!
4046 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
4049 -- If the entity is already set, this has already been resolved in
4050 -- a generic context, or comes from expansion. Nothing else to do.
4052 elsif Present (Entity (N)) then
4055 -- Otherwise we have a user defined character type, and we can use
4056 -- the standard visibility mechanisms to locate the referenced entity
4059 C := Current_Entity (N);
4060 while Present (C) loop
4061 if Etype (C) = B_Typ then
4062 Set_Entity_With_Style_Check (N, C);
4063 Generate_Reference (C, N);
4071 -- If we fall through, then the literal does not match any of the
4072 -- entries of the enumeration type. This isn't just a constraint
4073 -- error situation, it is an illegality (see RM 4.2).
4076 ("character not defined for }", N, First_Subtype (B_Typ));
4077 end Resolve_Character_Literal;
4079 ---------------------------
4080 -- Resolve_Comparison_Op --
4081 ---------------------------
4083 -- Context requires a boolean type, and plays no role in resolution.
4084 -- Processing identical to that for equality operators. The result
4085 -- type is the base type, which matters when pathological subtypes of
4086 -- booleans with limited ranges are used.
4088 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
4089 L : constant Node_Id := Left_Opnd (N);
4090 R : constant Node_Id := Right_Opnd (N);
4094 -- If this is an intrinsic operation which is not predefined, use
4095 -- the types of its declared arguments to resolve the possibly
4096 -- overloaded operands. Otherwise the operands are unambiguous and
4097 -- specify the expected type.
4099 if Scope (Entity (N)) /= Standard_Standard then
4100 T := Etype (First_Entity (Entity (N)));
4103 T := Find_Unique_Type (L, R);
4105 if T = Any_Fixed then
4106 T := Unique_Fixed_Point_Type (L);
4110 Set_Etype (N, Base_Type (Typ));
4111 Generate_Reference (T, N, ' ');
4113 if T /= Any_Type then
4115 or else T = Any_Composite
4116 or else T = Any_Character
4118 if T = Any_Character then
4119 Ambiguous_Character (L);
4121 Error_Msg_N ("ambiguous operands for comparison", N);
4124 Set_Etype (N, Any_Type);
4130 Check_Unset_Reference (L);
4131 Check_Unset_Reference (R);
4132 Generate_Operator_Reference (N, T);
4133 Eval_Relational_Op (N);
4134 Check_Direct_Boolean_Op (N);
4137 end Resolve_Comparison_Op;
4139 ------------------------------------
4140 -- Resolve_Conditional_Expression --
4141 ------------------------------------
4143 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
4144 Condition : constant Node_Id := First (Expressions (N));
4145 Then_Expr : constant Node_Id := Next (Condition);
4146 Else_Expr : constant Node_Id := Next (Then_Expr);
4149 Resolve (Condition, Standard_Boolean);
4150 Resolve (Then_Expr, Typ);
4151 Resolve (Else_Expr, Typ);
4154 Eval_Conditional_Expression (N);
4155 end Resolve_Conditional_Expression;
4157 -----------------------------------------
4158 -- Resolve_Discrete_Subtype_Indication --
4159 -----------------------------------------
4161 procedure Resolve_Discrete_Subtype_Indication
4169 Analyze (Subtype_Mark (N));
4170 S := Entity (Subtype_Mark (N));
4172 if Nkind (Constraint (N)) /= N_Range_Constraint then
4173 Error_Msg_N ("expect range constraint for discrete type", N);
4174 Set_Etype (N, Any_Type);
4177 R := Range_Expression (Constraint (N));
4185 if Base_Type (S) /= Base_Type (Typ) then
4187 ("expect subtype of }", N, First_Subtype (Typ));
4189 -- Rewrite the constraint as a range of Typ
4190 -- to allow compilation to proceed further.
4193 Rewrite (Low_Bound (R),
4194 Make_Attribute_Reference (Sloc (Low_Bound (R)),
4195 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4196 Attribute_Name => Name_First));
4197 Rewrite (High_Bound (R),
4198 Make_Attribute_Reference (Sloc (High_Bound (R)),
4199 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4200 Attribute_Name => Name_First));
4204 Set_Etype (N, Etype (R));
4206 -- Additionally, we must check that the bounds are compatible
4207 -- with the given subtype, which might be different from the
4208 -- type of the context.
4210 Apply_Range_Check (R, S);
4212 -- ??? If the above check statically detects a Constraint_Error
4213 -- it replaces the offending bound(s) of the range R with a
4214 -- Constraint_Error node. When the itype which uses these bounds
4215 -- is frozen the resulting call to Duplicate_Subexpr generates
4216 -- a new temporary for the bounds.
4218 -- Unfortunately there are other itypes that are also made depend
4219 -- on these bounds, so when Duplicate_Subexpr is called they get
4220 -- a forward reference to the newly created temporaries and Gigi
4221 -- aborts on such forward references. This is probably sign of a
4222 -- more fundamental problem somewhere else in either the order of
4223 -- itype freezing or the way certain itypes are constructed.
4225 -- To get around this problem we call Remove_Side_Effects right
4226 -- away if either bounds of R are a Constraint_Error.
4229 L : constant Node_Id := Low_Bound (R);
4230 H : constant Node_Id := High_Bound (R);
4233 if Nkind (L) = N_Raise_Constraint_Error then
4234 Remove_Side_Effects (L);
4237 if Nkind (H) = N_Raise_Constraint_Error then
4238 Remove_Side_Effects (H);
4242 Check_Unset_Reference (Low_Bound (R));
4243 Check_Unset_Reference (High_Bound (R));
4246 end Resolve_Discrete_Subtype_Indication;
4248 -------------------------
4249 -- Resolve_Entity_Name --
4250 -------------------------
4252 -- Used to resolve identifiers and expanded names
4254 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
4255 E : constant Entity_Id := Entity (N);
4258 -- If garbage from errors, set to Any_Type and return
4260 if No (E) and then Total_Errors_Detected /= 0 then
4261 Set_Etype (N, Any_Type);
4265 -- Replace named numbers by corresponding literals. Note that this is
4266 -- the one case where Resolve_Entity_Name must reset the Etype, since
4267 -- it is currently marked as universal.
4269 if Ekind (E) = E_Named_Integer then
4271 Eval_Named_Integer (N);
4273 elsif Ekind (E) = E_Named_Real then
4275 Eval_Named_Real (N);
4277 -- Allow use of subtype only if it is a concurrent type where we are
4278 -- currently inside the body. This will eventually be expanded
4279 -- into a call to Self (for tasks) or _object (for protected
4280 -- objects). Any other use of a subtype is invalid.
4282 elsif Is_Type (E) then
4283 if Is_Concurrent_Type (E)
4284 and then In_Open_Scopes (E)
4289 ("invalid use of subtype mark in expression or call", N);
4292 -- Check discriminant use if entity is discriminant in current scope,
4293 -- i.e. discriminant of record or concurrent type currently being
4294 -- analyzed. Uses in corresponding body are unrestricted.
4296 elsif Ekind (E) = E_Discriminant
4297 and then Scope (E) = Current_Scope
4298 and then not Has_Completion (Current_Scope)
4300 Check_Discriminant_Use (N);
4302 -- A parameterless generic function cannot appear in a context that
4303 -- requires resolution.
4305 elsif Ekind (E) = E_Generic_Function then
4306 Error_Msg_N ("illegal use of generic function", N);
4308 elsif Ekind (E) = E_Out_Parameter
4309 and then Ada_Version = Ada_83
4310 and then (Nkind (Parent (N)) in N_Op
4311 or else (Nkind (Parent (N)) = N_Assignment_Statement
4312 and then N = Expression (Parent (N)))
4313 or else Nkind (Parent (N)) = N_Explicit_Dereference)
4315 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
4317 -- In all other cases, just do the possible static evaluation
4320 -- A deferred constant that appears in an expression must have
4321 -- a completion, unless it has been removed by in-place expansion
4324 if Ekind (E) = E_Constant
4325 and then Comes_From_Source (E)
4326 and then No (Constant_Value (E))
4327 and then Is_Frozen (Etype (E))
4328 and then not In_Default_Expression
4329 and then not Is_Imported (E)
4332 if No_Initialization (Parent (E))
4333 or else (Present (Full_View (E))
4334 and then No_Initialization (Parent (Full_View (E))))
4339 "deferred constant is frozen before completion", N);
4343 Eval_Entity_Name (N);
4345 end Resolve_Entity_Name;
4351 procedure Resolve_Entry (Entry_Name : Node_Id) is
4352 Loc : constant Source_Ptr := Sloc (Entry_Name);
4360 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
4361 -- If the bounds of the entry family being called depend on task
4362 -- discriminants, build a new index subtype where a discriminant is
4363 -- replaced with the value of the discriminant of the target task.
4364 -- The target task is the prefix of the entry name in the call.
4366 -----------------------
4367 -- Actual_Index_Type --
4368 -----------------------
4370 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
4371 Typ : constant Entity_Id := Entry_Index_Type (E);
4372 Tsk : constant Entity_Id := Scope (E);
4373 Lo : constant Node_Id := Type_Low_Bound (Typ);
4374 Hi : constant Node_Id := Type_High_Bound (Typ);
4377 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
4378 -- If the bound is given by a discriminant, replace with a reference
4379 -- to the discriminant of the same name in the target task.
4380 -- If the entry name is the target of a requeue statement and the
4381 -- entry is in the current protected object, the bound to be used
4382 -- is the discriminal of the object (see apply_range_checks for
4383 -- details of the transformation).
4385 -----------------------------
4386 -- Actual_Discriminant_Ref --
4387 -----------------------------
4389 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
4390 Typ : constant Entity_Id := Etype (Bound);
4394 Remove_Side_Effects (Bound);
4396 if not Is_Entity_Name (Bound)
4397 or else Ekind (Entity (Bound)) /= E_Discriminant
4401 elsif Is_Protected_Type (Tsk)
4402 and then In_Open_Scopes (Tsk)
4403 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
4405 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
4409 Make_Selected_Component (Loc,
4410 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
4411 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
4416 end Actual_Discriminant_Ref;
4418 -- Start of processing for Actual_Index_Type
4421 if not Has_Discriminants (Tsk)
4422 or else (not Is_Entity_Name (Lo)
4423 and then not Is_Entity_Name (Hi))
4425 return Entry_Index_Type (E);
4428 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
4429 Set_Etype (New_T, Base_Type (Typ));
4430 Set_Size_Info (New_T, Typ);
4431 Set_RM_Size (New_T, RM_Size (Typ));
4432 Set_Scalar_Range (New_T,
4433 Make_Range (Sloc (Entry_Name),
4434 Low_Bound => Actual_Discriminant_Ref (Lo),
4435 High_Bound => Actual_Discriminant_Ref (Hi)));
4439 end Actual_Index_Type;
4441 -- Start of processing of Resolve_Entry
4444 -- Find name of entry being called, and resolve prefix of name
4445 -- with its own type. The prefix can be overloaded, and the name
4446 -- and signature of the entry must be taken into account.
4448 if Nkind (Entry_Name) = N_Indexed_Component then
4450 -- Case of dealing with entry family within the current tasks
4452 E_Name := Prefix (Entry_Name);
4455 E_Name := Entry_Name;
4458 if Is_Entity_Name (E_Name) then
4459 -- Entry call to an entry (or entry family) in the current task.
4460 -- This is legal even though the task will deadlock. Rewrite as
4461 -- call to current task.
4463 -- This can also be a call to an entry in an enclosing task.
4464 -- If this is a single task, we have to retrieve its name,
4465 -- because the scope of the entry is the task type, not the
4466 -- object. If the enclosing task is a task type, the identity
4467 -- of the task is given by its own self variable.
4469 -- Finally this can be a requeue on an entry of the same task
4470 -- or protected object.
4472 S := Scope (Entity (E_Name));
4474 for J in reverse 0 .. Scope_Stack.Last loop
4476 if Is_Task_Type (Scope_Stack.Table (J).Entity)
4477 and then not Comes_From_Source (S)
4479 -- S is an enclosing task or protected object. The concurrent
4480 -- declaration has been converted into a type declaration, and
4481 -- the object itself has an object declaration that follows
4482 -- the type in the same declarative part.
4484 Tsk := Next_Entity (S);
4485 while Etype (Tsk) /= S loop
4492 elsif S = Scope_Stack.Table (J).Entity then
4494 -- Call to current task. Will be transformed into call to Self
4502 Make_Selected_Component (Loc,
4503 Prefix => New_Occurrence_Of (S, Loc),
4505 New_Occurrence_Of (Entity (E_Name), Loc));
4506 Rewrite (E_Name, New_N);
4509 elsif Nkind (Entry_Name) = N_Selected_Component
4510 and then Is_Overloaded (Prefix (Entry_Name))
4512 -- Use the entry name (which must be unique at this point) to
4513 -- find the prefix that returns the corresponding task type or
4517 Pref : constant Node_Id := Prefix (Entry_Name);
4518 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
4523 Get_First_Interp (Pref, I, It);
4524 while Present (It.Typ) loop
4525 if Scope (Ent) = It.Typ then
4526 Set_Etype (Pref, It.Typ);
4530 Get_Next_Interp (I, It);
4535 if Nkind (Entry_Name) = N_Selected_Component then
4536 Resolve (Prefix (Entry_Name));
4538 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4539 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4540 Resolve (Prefix (Prefix (Entry_Name)));
4541 Index := First (Expressions (Entry_Name));
4542 Resolve (Index, Entry_Index_Type (Nam));
4544 -- Up to this point the expression could have been the actual
4545 -- in a simple entry call, and be given by a named association.
4547 if Nkind (Index) = N_Parameter_Association then
4548 Error_Msg_N ("expect expression for entry index", Index);
4550 Apply_Range_Check (Index, Actual_Index_Type (Nam));
4555 ------------------------
4556 -- Resolve_Entry_Call --
4557 ------------------------
4559 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
4560 Entry_Name : constant Node_Id := Name (N);
4561 Loc : constant Source_Ptr := Sloc (Entry_Name);
4563 First_Named : Node_Id;
4570 -- We kill all checks here, because it does not seem worth the
4571 -- effort to do anything better, an entry call is a big operation.
4575 -- Processing of the name is similar for entry calls and protected
4576 -- operation calls. Once the entity is determined, we can complete
4577 -- the resolution of the actuals.
4579 -- The selector may be overloaded, in the case of a protected object
4580 -- with overloaded functions. The type of the context is used for
4583 if Nkind (Entry_Name) = N_Selected_Component
4584 and then Is_Overloaded (Selector_Name (Entry_Name))
4585 and then Typ /= Standard_Void_Type
4592 Get_First_Interp (Selector_Name (Entry_Name), I, It);
4593 while Present (It.Typ) loop
4594 if Covers (Typ, It.Typ) then
4595 Set_Entity (Selector_Name (Entry_Name), It.Nam);
4596 Set_Etype (Entry_Name, It.Typ);
4598 Generate_Reference (It.Typ, N, ' ');
4601 Get_Next_Interp (I, It);
4606 Resolve_Entry (Entry_Name);
4608 if Nkind (Entry_Name) = N_Selected_Component then
4610 -- Simple entry call
4612 Nam := Entity (Selector_Name (Entry_Name));
4613 Obj := Prefix (Entry_Name);
4614 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
4616 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4618 -- Call to member of entry family
4620 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4621 Obj := Prefix (Prefix (Entry_Name));
4622 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
4625 -- We cannot in general check the maximum depth of protected entry
4626 -- calls at compile time. But we can tell that any protected entry
4627 -- call at all violates a specified nesting depth of zero.
4629 if Is_Protected_Type (Scope (Nam)) then
4630 Check_Restriction (Max_Entry_Queue_Length, N);
4633 -- Use context type to disambiguate a protected function that can be
4634 -- called without actuals and that returns an array type, and where
4635 -- the argument list may be an indexing of the returned value.
4637 if Ekind (Nam) = E_Function
4638 and then Needs_No_Actuals (Nam)
4639 and then Present (Parameter_Associations (N))
4641 ((Is_Array_Type (Etype (Nam))
4642 and then Covers (Typ, Component_Type (Etype (Nam))))
4644 or else (Is_Access_Type (Etype (Nam))
4645 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4646 and then Covers (Typ,
4647 Component_Type (Designated_Type (Etype (Nam))))))
4650 Index_Node : Node_Id;
4654 Make_Indexed_Component (Loc,
4656 Make_Function_Call (Loc,
4657 Name => Relocate_Node (Entry_Name)),
4658 Expressions => Parameter_Associations (N));
4660 -- Since we are correcting a node classification error made by
4661 -- the parser, we call Replace rather than Rewrite.
4663 Replace (N, Index_Node);
4664 Set_Etype (Prefix (N), Etype (Nam));
4666 Resolve_Indexed_Component (N, Typ);
4671 -- The operation name may have been overloaded. Order the actuals
4672 -- according to the formals of the resolved entity, and set the
4673 -- return type to that of the operation.
4676 Normalize_Actuals (N, Nam, False, Norm_OK);
4677 pragma Assert (Norm_OK);
4678 Set_Etype (N, Etype (Nam));
4681 Resolve_Actuals (N, Nam);
4682 Generate_Reference (Nam, Entry_Name);
4684 if Ekind (Nam) = E_Entry
4685 or else Ekind (Nam) = E_Entry_Family
4687 Check_Potentially_Blocking_Operation (N);
4690 -- Verify that a procedure call cannot masquerade as an entry
4691 -- call where an entry call is expected.
4693 if Ekind (Nam) = E_Procedure then
4694 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4695 and then N = Entry_Call_Statement (Parent (N))
4697 Error_Msg_N ("entry call required in select statement", N);
4699 elsif Nkind (Parent (N)) = N_Triggering_Alternative
4700 and then N = Triggering_Statement (Parent (N))
4702 Error_Msg_N ("triggering statement cannot be procedure call", N);
4704 elsif Ekind (Scope (Nam)) = E_Task_Type
4705 and then not In_Open_Scopes (Scope (Nam))
4707 Error_Msg_N ("task has no entry with this name", Entry_Name);
4711 -- After resolution, entry calls and protected procedure calls
4712 -- are changed into entry calls, for expansion. The structure
4713 -- of the node does not change, so it can safely be done in place.
4714 -- Protected function calls must keep their structure because they
4715 -- are subexpressions.
4717 if Ekind (Nam) /= E_Function then
4719 -- A protected operation that is not a function may modify the
4720 -- corresponding object, and cannot apply to a constant.
4721 -- If this is an internal call, the prefix is the type itself.
4723 if Is_Protected_Type (Scope (Nam))
4724 and then not Is_Variable (Obj)
4725 and then (not Is_Entity_Name (Obj)
4726 or else not Is_Type (Entity (Obj)))
4729 ("prefix of protected procedure or entry call must be variable",
4733 Actuals := Parameter_Associations (N);
4734 First_Named := First_Named_Actual (N);
4737 Make_Entry_Call_Statement (Loc,
4739 Parameter_Associations => Actuals));
4741 Set_First_Named_Actual (N, First_Named);
4742 Set_Analyzed (N, True);
4744 -- Protected functions can return on the secondary stack, in which
4745 -- case we must trigger the transient scope mechanism.
4747 elsif Expander_Active
4748 and then Requires_Transient_Scope (Etype (Nam))
4750 Establish_Transient_Scope (N,
4751 Sec_Stack => not Functions_Return_By_DSP_On_Target);
4753 end Resolve_Entry_Call;
4755 -------------------------
4756 -- Resolve_Equality_Op --
4757 -------------------------
4759 -- Both arguments must have the same type, and the boolean context
4760 -- does not participate in the resolution. The first pass verifies
4761 -- that the interpretation is not ambiguous, and the type of the left
4762 -- argument is correctly set, or is Any_Type in case of ambiguity.
4763 -- If both arguments are strings or aggregates, allocators, or Null,
4764 -- they are ambiguous even though they carry a single (universal) type.
4765 -- Diagnose this case here.
4767 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
4768 L : constant Node_Id := Left_Opnd (N);
4769 R : constant Node_Id := Right_Opnd (N);
4770 T : Entity_Id := Find_Unique_Type (L, R);
4772 function Find_Unique_Access_Type return Entity_Id;
4773 -- In the case of allocators, make a last-ditch attempt to find a single
4774 -- access type with the right designated type. This is semantically
4775 -- dubious, and of no interest to any real code, but c48008a makes it
4778 -----------------------------
4779 -- Find_Unique_Access_Type --
4780 -----------------------------
4782 function Find_Unique_Access_Type return Entity_Id is
4788 if Ekind (Etype (R)) = E_Allocator_Type then
4789 Acc := Designated_Type (Etype (R));
4791 elsif Ekind (Etype (L)) = E_Allocator_Type then
4792 Acc := Designated_Type (Etype (L));
4799 while S /= Standard_Standard loop
4800 E := First_Entity (S);
4801 while Present (E) loop
4803 and then Is_Access_Type (E)
4804 and then Ekind (E) /= E_Allocator_Type
4805 and then Designated_Type (E) = Base_Type (Acc)
4817 end Find_Unique_Access_Type;
4819 -- Start of processing for Resolve_Equality_Op
4822 Set_Etype (N, Base_Type (Typ));
4823 Generate_Reference (T, N, ' ');
4825 if T = Any_Fixed then
4826 T := Unique_Fixed_Point_Type (L);
4829 if T /= Any_Type then
4831 or else T = Any_Composite
4832 or else T = Any_Character
4834 if T = Any_Character then
4835 Ambiguous_Character (L);
4837 Error_Msg_N ("ambiguous operands for equality", N);
4840 Set_Etype (N, Any_Type);
4843 elsif T = Any_Access
4844 or else Ekind (T) = E_Allocator_Type
4846 T := Find_Unique_Access_Type;
4849 Error_Msg_N ("ambiguous operands for equality", N);
4850 Set_Etype (N, Any_Type);
4858 if Warn_On_Redundant_Constructs
4859 and then Comes_From_Source (N)
4860 and then Is_Entity_Name (R)
4861 and then Entity (R) = Standard_True
4862 and then Comes_From_Source (R)
4864 Error_Msg_N ("comparison with True is redundant?", R);
4867 Check_Unset_Reference (L);
4868 Check_Unset_Reference (R);
4869 Generate_Operator_Reference (N, T);
4871 -- If this is an inequality, it may be the implicit inequality
4872 -- created for a user-defined operation, in which case the corres-
4873 -- ponding equality operation is not intrinsic, and the operation
4874 -- cannot be constant-folded. Else fold.
4876 if Nkind (N) = N_Op_Eq
4877 or else Comes_From_Source (Entity (N))
4878 or else Ekind (Entity (N)) = E_Operator
4879 or else Is_Intrinsic_Subprogram
4880 (Corresponding_Equality (Entity (N)))
4882 Eval_Relational_Op (N);
4883 elsif Nkind (N) = N_Op_Ne
4884 and then Is_Abstract (Entity (N))
4886 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
4889 Check_Direct_Boolean_Op (N);
4891 end Resolve_Equality_Op;
4893 ----------------------------------
4894 -- Resolve_Explicit_Dereference --
4895 ----------------------------------
4897 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
4898 Loc : constant Source_Ptr := Sloc (N);
4900 P : constant Node_Id := Prefix (N);
4905 -- Now that we know the type, check that this is not dereference of an
4906 -- uncompleted type. Note that this is not entirely correct, because
4907 -- dereferences of private types are legal in default expressions. This
4908 -- exception is taken care of in Check_Fully_Declared.
4910 -- This consideration also applies to similar checks for allocators,
4911 -- qualified expressions, and type conversions.
4913 -- An additional exception concerns other per-object expressions that
4914 -- are not directly related to component declarations, in particular
4915 -- representation pragmas for tasks. These will be per-object
4916 -- expressions if they depend on discriminants or some global entity.
4917 -- If the task has access discriminants, the designated type may be
4918 -- incomplete at the point the expression is resolved. This resolution
4919 -- takes place within the body of the initialization procedure, where
4920 -- the discriminant is replaced by its discriminal.
4922 if Is_Entity_Name (Prefix (N))
4923 and then Ekind (Entity (Prefix (N))) = E_In_Parameter
4927 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
4928 -- are handled by Analyze_Access_Attribute, Analyze_Assignment, Analyze_
4929 -- Object_Renaming, and Freeze_Entity.
4931 elsif Ada_Version >= Ada_05
4932 and then Is_Entity_Name (Prefix (N))
4933 and then Ekind (Directly_Designated_Type (Etype (Prefix (N))))
4935 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Prefix (N))))
4939 Check_Fully_Declared (Typ, N);
4942 if Is_Overloaded (P) then
4944 -- Use the context type to select the prefix that has the correct
4947 Get_First_Interp (P, I, It);
4948 while Present (It.Typ) loop
4949 exit when Is_Access_Type (It.Typ)
4950 and then Covers (Typ, Designated_Type (It.Typ));
4951 Get_Next_Interp (I, It);
4954 if Present (It.Typ) then
4955 Resolve (P, It.Typ);
4957 -- If no interpretation covers the designated type of the prefix,
4958 -- this is the pathological case where not all implementations of
4959 -- the prefix allow the interpretation of the node as a call. Now
4960 -- that the expected type is known, Remove other interpretations
4961 -- from prefix, rewrite it as a call, and resolve again, so that
4962 -- the proper call node is generated.
4964 Get_First_Interp (P, I, It);
4965 while Present (It.Typ) loop
4966 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
4970 Get_Next_Interp (I, It);
4974 Make_Function_Call (Loc,
4976 Make_Explicit_Dereference (Loc,
4978 Parameter_Associations => New_List);
4980 Save_Interps (N, New_N);
4982 Analyze_And_Resolve (N, Typ);
4986 Set_Etype (N, Designated_Type (It.Typ));
4992 if Is_Access_Type (Etype (P)) then
4993 Apply_Access_Check (N);
4996 -- If the designated type is a packed unconstrained array type, and the
4997 -- explicit dereference is not in the context of an attribute reference,
4998 -- then we must compute and set the actual subtype, since it is needed
4999 -- by Gigi. The reason we exclude the attribute case is that this is
5000 -- handled fine by Gigi, and in fact we use such attributes to build the
5001 -- actual subtype. We also exclude generated code (which builds actual
5002 -- subtypes directly if they are needed).
5004 if Is_Array_Type (Etype (N))
5005 and then Is_Packed (Etype (N))
5006 and then not Is_Constrained (Etype (N))
5007 and then Nkind (Parent (N)) /= N_Attribute_Reference
5008 and then Comes_From_Source (N)
5010 Set_Etype (N, Get_Actual_Subtype (N));
5013 -- Note: there is no Eval processing required for an explicit deference,
5014 -- because the type is known to be an allocators, and allocator
5015 -- expressions can never be static.
5017 end Resolve_Explicit_Dereference;
5019 -------------------------------
5020 -- Resolve_Indexed_Component --
5021 -------------------------------
5023 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
5024 Name : constant Node_Id := Prefix (N);
5026 Array_Type : Entity_Id := Empty; -- to prevent junk warning
5030 if Is_Overloaded (Name) then
5032 -- Use the context type to select the prefix that yields the correct
5038 I1 : Interp_Index := 0;
5039 P : constant Node_Id := Prefix (N);
5040 Found : Boolean := False;
5043 Get_First_Interp (P, I, It);
5044 while Present (It.Typ) loop
5045 if (Is_Array_Type (It.Typ)
5046 and then Covers (Typ, Component_Type (It.Typ)))
5047 or else (Is_Access_Type (It.Typ)
5048 and then Is_Array_Type (Designated_Type (It.Typ))
5050 (Typ, Component_Type (Designated_Type (It.Typ))))
5053 It := Disambiguate (P, I1, I, Any_Type);
5055 if It = No_Interp then
5056 Error_Msg_N ("ambiguous prefix for indexing", N);
5062 Array_Type := It.Typ;
5068 Array_Type := It.Typ;
5073 Get_Next_Interp (I, It);
5078 Array_Type := Etype (Name);
5081 Resolve (Name, Array_Type);
5082 Array_Type := Get_Actual_Subtype_If_Available (Name);
5084 -- If prefix is access type, dereference to get real array type.
5085 -- Note: we do not apply an access check because the expander always
5086 -- introduces an explicit dereference, and the check will happen there.
5088 if Is_Access_Type (Array_Type) then
5089 Array_Type := Designated_Type (Array_Type);
5092 -- If name was overloaded, set component type correctly now
5094 Set_Etype (N, Component_Type (Array_Type));
5096 Index := First_Index (Array_Type);
5097 Expr := First (Expressions (N));
5099 -- The prefix may have resolved to a string literal, in which case its
5100 -- etype has a special representation. This is only possible currently
5101 -- if the prefix is a static concatenation, written in functional
5104 if Ekind (Array_Type) = E_String_Literal_Subtype then
5105 Resolve (Expr, Standard_Positive);
5108 while Present (Index) and Present (Expr) loop
5109 Resolve (Expr, Etype (Index));
5110 Check_Unset_Reference (Expr);
5112 if Is_Scalar_Type (Etype (Expr)) then
5113 Apply_Scalar_Range_Check (Expr, Etype (Index));
5115 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
5123 Eval_Indexed_Component (N);
5124 end Resolve_Indexed_Component;
5126 -----------------------------
5127 -- Resolve_Integer_Literal --
5128 -----------------------------
5130 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
5133 Eval_Integer_Literal (N);
5134 end Resolve_Integer_Literal;
5136 --------------------------------
5137 -- Resolve_Intrinsic_Operator --
5138 --------------------------------
5140 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
5141 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
5148 while Scope (Op) /= Standard_Standard loop
5150 pragma Assert (Present (Op));
5154 Set_Is_Overloaded (N, False);
5156 -- If the operand type is private, rewrite with suitable conversions on
5157 -- the operands and the result, to expose the proper underlying numeric
5160 if Is_Private_Type (Typ) then
5161 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
5163 if Nkind (N) = N_Op_Expon then
5164 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
5166 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5169 Save_Interps (Left_Opnd (N), Expression (Arg1));
5170 Save_Interps (Right_Opnd (N), Expression (Arg2));
5172 Set_Left_Opnd (N, Arg1);
5173 Set_Right_Opnd (N, Arg2);
5175 Set_Etype (N, Btyp);
5176 Rewrite (N, Unchecked_Convert_To (Typ, N));
5179 elsif Typ /= Etype (Left_Opnd (N))
5180 or else Typ /= Etype (Right_Opnd (N))
5182 -- Add explicit conversion where needed, and save interpretations
5183 -- in case operands are overloaded.
5185 Arg1 := Convert_To (Typ, Left_Opnd (N));
5186 Arg2 := Convert_To (Typ, Right_Opnd (N));
5188 if Nkind (Arg1) = N_Type_Conversion then
5189 Save_Interps (Left_Opnd (N), Expression (Arg1));
5191 Save_Interps (Left_Opnd (N), Arg1);
5194 if Nkind (Arg2) = N_Type_Conversion then
5195 Save_Interps (Right_Opnd (N), Expression (Arg2));
5197 Save_Interps (Right_Opnd (N), Arg2);
5200 Rewrite (Left_Opnd (N), Arg1);
5201 Rewrite (Right_Opnd (N), Arg2);
5204 Resolve_Arithmetic_Op (N, Typ);
5207 Resolve_Arithmetic_Op (N, Typ);
5209 end Resolve_Intrinsic_Operator;
5211 --------------------------------------
5212 -- Resolve_Intrinsic_Unary_Operator --
5213 --------------------------------------
5215 procedure Resolve_Intrinsic_Unary_Operator
5219 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
5225 while Scope (Op) /= Standard_Standard loop
5227 pragma Assert (Present (Op));
5232 if Is_Private_Type (Typ) then
5233 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5234 Save_Interps (Right_Opnd (N), Expression (Arg2));
5236 Set_Right_Opnd (N, Arg2);
5238 Set_Etype (N, Btyp);
5239 Rewrite (N, Unchecked_Convert_To (Typ, N));
5243 Resolve_Unary_Op (N, Typ);
5245 end Resolve_Intrinsic_Unary_Operator;
5247 ------------------------
5248 -- Resolve_Logical_Op --
5249 ------------------------
5251 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
5255 -- Predefined operations on scalar types yield the base type. On the
5256 -- other hand, logical operations on arrays yield the type of the
5257 -- arguments (and the context).
5259 if Is_Array_Type (Typ) then
5262 B_Typ := Base_Type (Typ);
5265 -- The following test is required because the operands of the operation
5266 -- may be literals, in which case the resulting type appears to be
5267 -- compatible with a signed integer type, when in fact it is compatible
5268 -- only with modular types. If the context itself is universal, the
5269 -- operation is illegal.
5271 if not Valid_Boolean_Arg (Typ) then
5272 Error_Msg_N ("invalid context for logical operation", N);
5273 Set_Etype (N, Any_Type);
5276 elsif Typ = Any_Modular then
5278 ("no modular type available in this context", N);
5279 Set_Etype (N, Any_Type);
5281 elsif Is_Modular_Integer_Type (Typ)
5282 and then Etype (Left_Opnd (N)) = Universal_Integer
5283 and then Etype (Right_Opnd (N)) = Universal_Integer
5285 Check_For_Visible_Operator (N, B_Typ);
5288 Resolve (Left_Opnd (N), B_Typ);
5289 Resolve (Right_Opnd (N), B_Typ);
5291 Check_Unset_Reference (Left_Opnd (N));
5292 Check_Unset_Reference (Right_Opnd (N));
5294 Set_Etype (N, B_Typ);
5295 Generate_Operator_Reference (N, B_Typ);
5296 Eval_Logical_Op (N);
5297 Check_Direct_Boolean_Op (N);
5298 end Resolve_Logical_Op;
5300 ---------------------------
5301 -- Resolve_Membership_Op --
5302 ---------------------------
5304 -- The context can only be a boolean type, and does not determine
5305 -- the arguments. Arguments should be unambiguous, but the preference
5306 -- rule for universal types applies.
5308 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
5309 pragma Warnings (Off, Typ);
5311 L : constant Node_Id := Left_Opnd (N);
5312 R : constant Node_Id := Right_Opnd (N);
5316 if L = Error or else R = Error then
5320 if not Is_Overloaded (R)
5322 (Etype (R) = Universal_Integer or else
5323 Etype (R) = Universal_Real)
5324 and then Is_Overloaded (L)
5328 -- Ada 2005 (AI-251): Give support to the following case:
5330 -- type I is interface;
5331 -- type T is tagged ...
5333 -- function Test (O : in I'Class) is
5335 -- return O in T'Class.
5338 -- In this case we have nothing else to do; the membership test will be
5339 -- done at run-time.
5341 elsif Ada_Version >= Ada_05
5342 and then Is_Class_Wide_Type (Etype (L))
5343 and then Is_Interface (Etype (L))
5344 and then Is_Class_Wide_Type (Etype (R))
5345 and then not Is_Interface (Etype (R))
5350 T := Intersect_Types (L, R);
5354 Check_Unset_Reference (L);
5356 if Nkind (R) = N_Range
5357 and then not Is_Scalar_Type (T)
5359 Error_Msg_N ("scalar type required for range", R);
5362 if Is_Entity_Name (R) then
5363 Freeze_Expression (R);
5366 Check_Unset_Reference (R);
5369 Eval_Membership_Op (N);
5370 end Resolve_Membership_Op;
5376 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
5378 -- Handle restriction against anonymous null access values This
5379 -- restriction can be turned off using -gnatdh.
5381 -- Ada 2005 (AI-231): Remove restriction
5383 if Ada_Version < Ada_05
5384 and then not Debug_Flag_J
5385 and then Ekind (Typ) = E_Anonymous_Access_Type
5386 and then Comes_From_Source (N)
5388 -- In the common case of a call which uses an explicitly null
5389 -- value for an access parameter, give specialized error msg
5391 if Nkind (Parent (N)) = N_Procedure_Call_Statement
5393 Nkind (Parent (N)) = N_Function_Call
5396 ("null is not allowed as argument for an access parameter", N);
5398 -- Standard message for all other cases (are there any?)
5402 ("null cannot be of an anonymous access type", N);
5406 -- In a distributed context, null for a remote access to subprogram
5407 -- may need to be replaced with a special record aggregate. In this
5408 -- case, return after having done the transformation.
5410 if (Ekind (Typ) = E_Record_Type
5411 or else Is_Remote_Access_To_Subprogram_Type (Typ))
5412 and then Remote_AST_Null_Value (N, Typ)
5417 -- The null literal takes its type from the context
5422 -----------------------
5423 -- Resolve_Op_Concat --
5424 -----------------------
5426 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
5427 Btyp : constant Entity_Id := Base_Type (Typ);
5428 Op1 : constant Node_Id := Left_Opnd (N);
5429 Op2 : constant Node_Id := Right_Opnd (N);
5431 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean);
5432 -- Internal procedure to resolve one operand of concatenation operator.
5433 -- The operand is either of the array type or of the component type.
5434 -- If the operand is an aggregate, and the component type is composite,
5435 -- this is ambiguous if component type has aggregates.
5437 -------------------------------
5438 -- Resolve_Concatenation_Arg --
5439 -------------------------------
5441 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean) is
5445 or else (not Is_Overloaded (Arg)
5446 and then Etype (Arg) /= Any_Composite
5447 and then Covers (Component_Type (Typ), Etype (Arg)))
5449 Resolve (Arg, Component_Type (Typ));
5451 Resolve (Arg, Btyp);
5454 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
5456 if Nkind (Arg) = N_Aggregate
5457 and then Is_Composite_Type (Component_Type (Typ))
5459 if Is_Private_Type (Component_Type (Typ)) then
5460 Resolve (Arg, Btyp);
5463 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
5464 Set_Etype (Arg, Any_Type);
5468 if Is_Overloaded (Arg)
5469 and then Has_Compatible_Type (Arg, Typ)
5470 and then Etype (Arg) /= Any_Type
5472 Error_Msg_N ("ambiguous operand for concatenation!", Arg);
5479 Get_First_Interp (Arg, I, It);
5480 while Present (It.Nam) loop
5481 if Base_Type (Etype (It.Nam)) = Base_Type (Typ)
5482 or else Base_Type (Etype (It.Nam)) =
5483 Base_Type (Component_Type (Typ))
5485 Error_Msg_Sloc := Sloc (It.Nam);
5486 Error_Msg_N ("\possible interpretation#", Arg);
5489 Get_Next_Interp (I, It);
5494 Resolve (Arg, Component_Type (Typ));
5496 if Nkind (Arg) = N_String_Literal then
5497 Set_Etype (Arg, Component_Type (Typ));
5500 if Arg = Left_Opnd (N) then
5501 Set_Is_Component_Left_Opnd (N);
5503 Set_Is_Component_Right_Opnd (N);
5508 Resolve (Arg, Btyp);
5511 Check_Unset_Reference (Arg);
5512 end Resolve_Concatenation_Arg;
5514 -- Start of processing for Resolve_Op_Concat
5517 Set_Etype (N, Btyp);
5519 if Is_Limited_Composite (Btyp) then
5520 Error_Msg_N ("concatenation not available for limited array", N);
5521 Explain_Limited_Type (Btyp, N);
5524 -- If the operands are themselves concatenations, resolve them as such
5525 -- directly. This removes several layers of recursion and allows GNAT to
5526 -- handle larger multiple concatenations.
5528 if Nkind (Op1) = N_Op_Concat
5529 and then not Is_Array_Type (Component_Type (Typ))
5530 and then Entity (Op1) = Entity (N)
5532 Resolve_Op_Concat (Op1, Typ);
5534 Resolve_Concatenation_Arg
5535 (Op1, Is_Component_Left_Opnd (N));
5538 if Nkind (Op2) = N_Op_Concat
5539 and then not Is_Array_Type (Component_Type (Typ))
5540 and then Entity (Op2) = Entity (N)
5542 Resolve_Op_Concat (Op2, Typ);
5544 Resolve_Concatenation_Arg
5545 (Op2, Is_Component_Right_Opnd (N));
5548 Generate_Operator_Reference (N, Typ);
5550 if Is_String_Type (Typ) then
5551 Eval_Concatenation (N);
5554 -- If this is not a static concatenation, but the result is a
5555 -- string type (and not an array of strings) insure that static
5556 -- string operands have their subtypes properly constructed.
5558 if Nkind (N) /= N_String_Literal
5559 and then Is_Character_Type (Component_Type (Typ))
5561 Set_String_Literal_Subtype (Op1, Typ);
5562 Set_String_Literal_Subtype (Op2, Typ);
5564 end Resolve_Op_Concat;
5566 ----------------------
5567 -- Resolve_Op_Expon --
5568 ----------------------
5570 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
5571 B_Typ : constant Entity_Id := Base_Type (Typ);
5574 -- Catch attempts to do fixed-point exponentation with universal
5575 -- operands, which is a case where the illegality is not caught during
5576 -- normal operator analysis.
5578 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
5579 Error_Msg_N ("exponentiation not available for fixed point", N);
5583 if Comes_From_Source (N)
5584 and then Ekind (Entity (N)) = E_Function
5585 and then Is_Imported (Entity (N))
5586 and then Is_Intrinsic_Subprogram (Entity (N))
5588 Resolve_Intrinsic_Operator (N, Typ);
5592 if Etype (Left_Opnd (N)) = Universal_Integer
5593 or else Etype (Left_Opnd (N)) = Universal_Real
5595 Check_For_Visible_Operator (N, B_Typ);
5598 -- We do the resolution using the base type, because intermediate values
5599 -- in expressions always are of the base type, not a subtype of it.
5601 Resolve (Left_Opnd (N), B_Typ);
5602 Resolve (Right_Opnd (N), Standard_Integer);
5604 Check_Unset_Reference (Left_Opnd (N));
5605 Check_Unset_Reference (Right_Opnd (N));
5607 Set_Etype (N, B_Typ);
5608 Generate_Operator_Reference (N, B_Typ);
5611 -- Set overflow checking bit. Much cleverer code needed here eventually
5612 -- and perhaps the Resolve routines should be separated for the various
5613 -- arithmetic operations, since they will need different processing. ???
5615 if Nkind (N) in N_Op then
5616 if not Overflow_Checks_Suppressed (Etype (N)) then
5617 Enable_Overflow_Check (N);
5620 end Resolve_Op_Expon;
5622 --------------------
5623 -- Resolve_Op_Not --
5624 --------------------
5626 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
5629 function Parent_Is_Boolean return Boolean;
5630 -- This function determines if the parent node is a boolean operator
5631 -- or operation (comparison op, membership test, or short circuit form)
5632 -- and the not in question is the left operand of this operation.
5633 -- Note that if the not is in parens, then false is returned.
5635 function Parent_Is_Boolean return Boolean is
5637 if Paren_Count (N) /= 0 then
5641 case Nkind (Parent (N)) is
5656 return Left_Opnd (Parent (N)) = N;
5662 end Parent_Is_Boolean;
5664 -- Start of processing for Resolve_Op_Not
5667 -- Predefined operations on scalar types yield the base type. On the
5668 -- other hand, logical operations on arrays yield the type of the
5669 -- arguments (and the context).
5671 if Is_Array_Type (Typ) then
5674 B_Typ := Base_Type (Typ);
5677 if not Valid_Boolean_Arg (Typ) then
5678 Error_Msg_N ("invalid operand type for operator&", N);
5679 Set_Etype (N, Any_Type);
5682 elsif Typ = Universal_Integer or else Typ = Any_Modular then
5683 if Parent_Is_Boolean then
5685 ("operand of not must be enclosed in parentheses",
5689 ("no modular type available in this context", N);
5692 Set_Etype (N, Any_Type);
5696 if not Is_Boolean_Type (Typ)
5697 and then Parent_Is_Boolean
5699 Error_Msg_N ("?not expression should be parenthesized here", N);
5702 Resolve (Right_Opnd (N), B_Typ);
5703 Check_Unset_Reference (Right_Opnd (N));
5704 Set_Etype (N, B_Typ);
5705 Generate_Operator_Reference (N, B_Typ);
5710 -----------------------------
5711 -- Resolve_Operator_Symbol --
5712 -----------------------------
5714 -- Nothing to be done, all resolved already
5716 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
5717 pragma Warnings (Off, N);
5718 pragma Warnings (Off, Typ);
5722 end Resolve_Operator_Symbol;
5724 ----------------------------------
5725 -- Resolve_Qualified_Expression --
5726 ----------------------------------
5728 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
5729 pragma Warnings (Off, Typ);
5731 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
5732 Expr : constant Node_Id := Expression (N);
5735 Resolve (Expr, Target_Typ);
5737 -- A qualified expression requires an exact match of the type,
5738 -- class-wide matching is not allowed. However, if the qualifying
5739 -- type is specific and the expression has a class-wide type, it
5740 -- may still be okay, since it can be the result of the expansion
5741 -- of a call to a dispatching function, so we also have to check
5742 -- class-wideness of the type of the expression's original node.
5744 if (Is_Class_Wide_Type (Target_Typ)
5746 (Is_Class_Wide_Type (Etype (Expr))
5747 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
5748 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
5750 Wrong_Type (Expr, Target_Typ);
5753 -- If the target type is unconstrained, then we reset the type of
5754 -- the result from the type of the expression. For other cases, the
5755 -- actual subtype of the expression is the target type.
5757 if Is_Composite_Type (Target_Typ)
5758 and then not Is_Constrained (Target_Typ)
5760 Set_Etype (N, Etype (Expr));
5763 Eval_Qualified_Expression (N);
5764 end Resolve_Qualified_Expression;
5770 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
5771 L : constant Node_Id := Low_Bound (N);
5772 H : constant Node_Id := High_Bound (N);
5779 Check_Unset_Reference (L);
5780 Check_Unset_Reference (H);
5782 -- We have to check the bounds for being within the base range as
5783 -- required for a non-static context. Normally this is automatic and
5784 -- done as part of evaluating expressions, but the N_Range node is an
5785 -- exception, since in GNAT we consider this node to be a subexpression,
5786 -- even though in Ada it is not. The circuit in Sem_Eval could check for
5787 -- this, but that would put the test on the main evaluation path for
5790 Check_Non_Static_Context (L);
5791 Check_Non_Static_Context (H);
5793 -- If bounds are static, constant-fold them, so size computations
5794 -- are identical between front-end and back-end. Do not perform this
5795 -- transformation while analyzing generic units, as type information
5796 -- would then be lost when reanalyzing the constant node in the
5799 if Is_Discrete_Type (Typ) and then Expander_Active then
5800 if Is_OK_Static_Expression (L) then
5801 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
5804 if Is_OK_Static_Expression (H) then
5805 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
5810 --------------------------
5811 -- Resolve_Real_Literal --
5812 --------------------------
5814 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
5815 Actual_Typ : constant Entity_Id := Etype (N);
5818 -- Special processing for fixed-point literals to make sure that the
5819 -- value is an exact multiple of small where this is required. We
5820 -- skip this for the universal real case, and also for generic types.
5822 if Is_Fixed_Point_Type (Typ)
5823 and then Typ /= Universal_Fixed
5824 and then Typ /= Any_Fixed
5825 and then not Is_Generic_Type (Typ)
5828 Val : constant Ureal := Realval (N);
5829 Cintr : constant Ureal := Val / Small_Value (Typ);
5830 Cint : constant Uint := UR_Trunc (Cintr);
5831 Den : constant Uint := Norm_Den (Cintr);
5835 -- Case of literal is not an exact multiple of the Small
5839 -- For a source program literal for a decimal fixed-point
5840 -- type, this is statically illegal (RM 4.9(36)).
5842 if Is_Decimal_Fixed_Point_Type (Typ)
5843 and then Actual_Typ = Universal_Real
5844 and then Comes_From_Source (N)
5846 Error_Msg_N ("value has extraneous low order digits", N);
5849 -- Generate a warning if literal from source
5851 if Is_Static_Expression (N)
5852 and then Warn_On_Bad_Fixed_Value
5855 ("static fixed-point value is not a multiple of Small?",
5859 -- Replace literal by a value that is the exact representation
5860 -- of a value of the type, i.e. a multiple of the small value,
5861 -- by truncation, since Machine_Rounds is false for all GNAT
5862 -- fixed-point types (RM 4.9(38)).
5864 Stat := Is_Static_Expression (N);
5866 Make_Real_Literal (Sloc (N),
5867 Realval => Small_Value (Typ) * Cint));
5869 Set_Is_Static_Expression (N, Stat);
5872 -- In all cases, set the corresponding integer field
5874 Set_Corresponding_Integer_Value (N, Cint);
5878 -- Now replace the actual type by the expected type as usual
5881 Eval_Real_Literal (N);
5882 end Resolve_Real_Literal;
5884 -----------------------
5885 -- Resolve_Reference --
5886 -----------------------
5888 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
5889 P : constant Node_Id := Prefix (N);
5892 -- Replace general access with specific type
5894 if Ekind (Etype (N)) = E_Allocator_Type then
5895 Set_Etype (N, Base_Type (Typ));
5898 Resolve (P, Designated_Type (Etype (N)));
5900 -- If we are taking the reference of a volatile entity, then treat
5901 -- it as a potential modification of this entity. This is much too
5902 -- conservative, but is necessary because remove side effects can
5903 -- result in transformations of normal assignments into reference
5904 -- sequences that otherwise fail to notice the modification.
5906 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
5907 Note_Possible_Modification (P);
5909 end Resolve_Reference;
5911 --------------------------------
5912 -- Resolve_Selected_Component --
5913 --------------------------------
5915 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
5917 Comp1 : Entity_Id := Empty; -- prevent junk warning
5918 P : constant Node_Id := Prefix (N);
5919 S : constant Node_Id := Selector_Name (N);
5920 T : Entity_Id := Etype (P);
5922 I1 : Interp_Index := 0; -- prevent junk warning
5927 function Init_Component return Boolean;
5928 -- Check whether this is the initialization of a component within an
5929 -- init proc (by assignment or call to another init proc). If true,
5930 -- there is no need for a discriminant check.
5932 --------------------
5933 -- Init_Component --
5934 --------------------
5936 function Init_Component return Boolean is
5938 return Inside_Init_Proc
5939 and then Nkind (Prefix (N)) = N_Identifier
5940 and then Chars (Prefix (N)) = Name_uInit
5941 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
5944 -- Start of processing for Resolve_Selected_Component
5947 if Is_Overloaded (P) then
5949 -- Use the context type to select the prefix that has a selector
5950 -- of the correct name and type.
5953 Get_First_Interp (P, I, It);
5955 Search : while Present (It.Typ) loop
5956 if Is_Access_Type (It.Typ) then
5957 T := Designated_Type (It.Typ);
5962 if Is_Record_Type (T) then
5963 Comp := First_Entity (T);
5964 while Present (Comp) loop
5965 if Chars (Comp) = Chars (S)
5966 and then Covers (Etype (Comp), Typ)
5975 It := Disambiguate (P, I1, I, Any_Type);
5977 if It = No_Interp then
5979 ("ambiguous prefix for selected component", N);
5986 if Scope (Comp1) /= It1.Typ then
5988 -- Resolution chooses the new interpretation.
5989 -- Find the component with the right name.
5991 Comp1 := First_Entity (It1.Typ);
5992 while Present (Comp1)
5993 and then Chars (Comp1) /= Chars (S)
5995 Comp1 := Next_Entity (Comp1);
6004 Comp := Next_Entity (Comp);
6009 Get_Next_Interp (I, It);
6012 Resolve (P, It1.Typ);
6014 Set_Entity (S, Comp1);
6017 -- Resolve prefix with its type
6022 -- If prefix is an access type, the node will be transformed into
6023 -- an explicit dereference during expansion. The type of the node
6024 -- is the designated type of that of the prefix.
6026 if Is_Access_Type (Etype (P)) then
6027 T := Designated_Type (Etype (P));
6032 if Has_Discriminants (T)
6033 and then (Ekind (Entity (S)) = E_Component
6035 Ekind (Entity (S)) = E_Discriminant)
6036 and then Present (Original_Record_Component (Entity (S)))
6037 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
6038 and then Present (Discriminant_Checking_Func
6039 (Original_Record_Component (Entity (S))))
6040 and then not Discriminant_Checks_Suppressed (T)
6041 and then not Init_Component
6043 Set_Do_Discriminant_Check (N);
6046 if Ekind (Entity (S)) = E_Void then
6047 Error_Msg_N ("premature use of component", S);
6050 -- If the prefix is a record conversion, this may be a renamed
6051 -- discriminant whose bounds differ from those of the original
6052 -- one, so we must ensure that a range check is performed.
6054 if Nkind (P) = N_Type_Conversion
6055 and then Ekind (Entity (S)) = E_Discriminant
6056 and then Is_Discrete_Type (Typ)
6058 Set_Etype (N, Base_Type (Typ));
6061 -- Note: No Eval processing is required, because the prefix is of a
6062 -- record type, or protected type, and neither can possibly be static.
6064 end Resolve_Selected_Component;
6070 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
6071 B_Typ : constant Entity_Id := Base_Type (Typ);
6072 L : constant Node_Id := Left_Opnd (N);
6073 R : constant Node_Id := Right_Opnd (N);
6076 -- We do the resolution using the base type, because intermediate values
6077 -- in expressions always are of the base type, not a subtype of it.
6080 Resolve (R, Standard_Natural);
6082 Check_Unset_Reference (L);
6083 Check_Unset_Reference (R);
6085 Set_Etype (N, B_Typ);
6086 Generate_Operator_Reference (N, B_Typ);
6090 ---------------------------
6091 -- Resolve_Short_Circuit --
6092 ---------------------------
6094 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
6095 B_Typ : constant Entity_Id := Base_Type (Typ);
6096 L : constant Node_Id := Left_Opnd (N);
6097 R : constant Node_Id := Right_Opnd (N);
6103 Check_Unset_Reference (L);
6104 Check_Unset_Reference (R);
6106 Set_Etype (N, B_Typ);
6107 Eval_Short_Circuit (N);
6108 end Resolve_Short_Circuit;
6114 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
6115 Name : constant Node_Id := Prefix (N);
6116 Drange : constant Node_Id := Discrete_Range (N);
6117 Array_Type : Entity_Id := Empty;
6121 if Is_Overloaded (Name) then
6123 -- Use the context type to select the prefix that yields the
6124 -- correct array type.
6128 I1 : Interp_Index := 0;
6130 P : constant Node_Id := Prefix (N);
6131 Found : Boolean := False;
6134 Get_First_Interp (P, I, It);
6135 while Present (It.Typ) loop
6136 if (Is_Array_Type (It.Typ)
6137 and then Covers (Typ, It.Typ))
6138 or else (Is_Access_Type (It.Typ)
6139 and then Is_Array_Type (Designated_Type (It.Typ))
6140 and then Covers (Typ, Designated_Type (It.Typ)))
6143 It := Disambiguate (P, I1, I, Any_Type);
6145 if It = No_Interp then
6146 Error_Msg_N ("ambiguous prefix for slicing", N);
6151 Array_Type := It.Typ;
6156 Array_Type := It.Typ;
6161 Get_Next_Interp (I, It);
6166 Array_Type := Etype (Name);
6169 Resolve (Name, Array_Type);
6171 if Is_Access_Type (Array_Type) then
6172 Apply_Access_Check (N);
6173 Array_Type := Designated_Type (Array_Type);
6175 -- If the prefix is an access to an unconstrained array, we must
6176 -- use the actual subtype of the object to perform the index checks.
6177 -- The object denoted by the prefix is implicit in the node, so we
6178 -- build an explicit representation for it in order to compute the
6181 if not Is_Constrained (Array_Type) then
6182 Remove_Side_Effects (Prefix (N));
6185 Obj : constant Node_Id :=
6186 Make_Explicit_Dereference (Sloc (N),
6187 Prefix => New_Copy_Tree (Prefix (N)));
6189 Set_Etype (Obj, Array_Type);
6190 Set_Parent (Obj, Parent (N));
6191 Array_Type := Get_Actual_Subtype (Obj);
6195 elsif Is_Entity_Name (Name)
6196 or else (Nkind (Name) = N_Function_Call
6197 and then not Is_Constrained (Etype (Name)))
6199 Array_Type := Get_Actual_Subtype (Name);
6202 -- If name was overloaded, set slice type correctly now
6204 Set_Etype (N, Array_Type);
6206 -- If the range is specified by a subtype mark, no resolution
6207 -- is necessary. Else resolve the bounds, and apply needed checks.
6209 if not Is_Entity_Name (Drange) then
6210 Index := First_Index (Array_Type);
6211 Resolve (Drange, Base_Type (Etype (Index)));
6213 if Nkind (Drange) = N_Range then
6214 Apply_Range_Check (Drange, Etype (Index));
6218 Set_Slice_Subtype (N);
6222 ----------------------------
6223 -- Resolve_String_Literal --
6224 ----------------------------
6226 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
6227 C_Typ : constant Entity_Id := Component_Type (Typ);
6228 R_Typ : constant Entity_Id := Root_Type (C_Typ);
6229 Loc : constant Source_Ptr := Sloc (N);
6230 Str : constant String_Id := Strval (N);
6231 Strlen : constant Nat := String_Length (Str);
6232 Subtype_Id : Entity_Id;
6233 Need_Check : Boolean;
6236 -- For a string appearing in a concatenation, defer creation of the
6237 -- string_literal_subtype until the end of the resolution of the
6238 -- concatenation, because the literal may be constant-folded away.
6239 -- This is a useful optimization for long concatenation expressions.
6241 -- If the string is an aggregate built for a single character (which
6242 -- happens in a non-static context) or a is null string to which special
6243 -- checks may apply, we build the subtype. Wide strings must also get
6244 -- a string subtype if they come from a one character aggregate. Strings
6245 -- generated by attributes might be static, but it is often hard to
6246 -- determine whether the enclosing context is static, so we generate
6247 -- subtypes for them as well, thus losing some rarer optimizations ???
6248 -- Same for strings that come from a static conversion.
6251 (Strlen = 0 and then Typ /= Standard_String)
6252 or else Nkind (Parent (N)) /= N_Op_Concat
6253 or else (N /= Left_Opnd (Parent (N))
6254 and then N /= Right_Opnd (Parent (N)))
6255 or else ((Typ = Standard_Wide_String
6256 or else Typ = Standard_Wide_Wide_String)
6257 and then Nkind (Original_Node (N)) /= N_String_Literal);
6259 -- If the resolving type is itself a string literal subtype, we
6260 -- can just reuse it, since there is no point in creating another.
6262 if Ekind (Typ) = E_String_Literal_Subtype then
6265 elsif Nkind (Parent (N)) = N_Op_Concat
6266 and then not Need_Check
6267 and then Nkind (Original_Node (N)) /= N_Character_Literal
6268 and then Nkind (Original_Node (N)) /= N_Attribute_Reference
6269 and then Nkind (Original_Node (N)) /= N_Qualified_Expression
6270 and then Nkind (Original_Node (N)) /= N_Type_Conversion
6274 -- Otherwise we must create a string literal subtype. Note that the
6275 -- whole idea of string literal subtypes is simply to avoid the need
6276 -- for building a full fledged array subtype for each literal.
6278 Set_String_Literal_Subtype (N, Typ);
6279 Subtype_Id := Etype (N);
6282 if Nkind (Parent (N)) /= N_Op_Concat
6285 Set_Etype (N, Subtype_Id);
6286 Eval_String_Literal (N);
6289 if Is_Limited_Composite (Typ)
6290 or else Is_Private_Composite (Typ)
6292 Error_Msg_N ("string literal not available for private array", N);
6293 Set_Etype (N, Any_Type);
6297 -- The validity of a null string has been checked in the
6298 -- call to Eval_String_Literal.
6303 -- Always accept string literal with component type Any_Character,
6304 -- which occurs in error situations and in comparisons of literals,
6305 -- both of which should accept all literals.
6307 elsif R_Typ = Any_Character then
6310 -- If the type is bit-packed, then we always tranform the string
6311 -- literal into a full fledged aggregate.
6313 elsif Is_Bit_Packed_Array (Typ) then
6316 -- Deal with cases of Wide_Wide_String, Wide_String, and String
6319 -- For Standard.Wide_Wide_String, or any other type whose component
6320 -- type is Standard.Wide_Wide_Character, we know that all the
6321 -- characters in the string must be acceptable, since the parser
6322 -- accepted the characters as valid character literals.
6324 if R_Typ = Standard_Wide_Wide_Character then
6327 -- For the case of Standard.String, or any other type whose
6328 -- component type is Standard.Character, we must make sure that
6329 -- there are no wide characters in the string, i.e. that it is
6330 -- entirely composed of characters in range of type Character.
6332 -- If the string literal is the result of a static concatenation,
6333 -- the test has already been performed on the components, and need
6336 elsif R_Typ = Standard_Character
6337 and then Nkind (Original_Node (N)) /= N_Op_Concat
6339 for J in 1 .. Strlen loop
6340 if not In_Character_Range (Get_String_Char (Str, J)) then
6342 -- If we are out of range, post error. This is one of the
6343 -- very few places that we place the flag in the middle of
6344 -- a token, right under the offending wide character.
6347 ("literal out of range of type Standard.Character",
6348 Source_Ptr (Int (Loc) + J));
6353 -- For the case of Standard.Wide_String, or any other type whose
6354 -- component type is Standard.Wide_Character, we must make sure that
6355 -- there are no wide characters in the string, i.e. that it is
6356 -- entirely composed of characters in range of type Wide_Character.
6358 -- If the string literal is the result of a static concatenation,
6359 -- the test has already been performed on the components, and need
6362 elsif R_Typ = Standard_Wide_Character
6363 and then Nkind (Original_Node (N)) /= N_Op_Concat
6365 for J in 1 .. Strlen loop
6366 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
6368 -- If we are out of range, post error. This is one of the
6369 -- very few places that we place the flag in the middle of
6370 -- a token, right under the offending wide character.
6372 -- This is not quite right, because characters in general
6373 -- will take more than one character position ???
6376 ("literal out of range of type Standard.Wide_Character",
6377 Source_Ptr (Int (Loc) + J));
6382 -- If the root type is not a standard character, then we will convert
6383 -- the string into an aggregate and will let the aggregate code do
6384 -- the checking. Standard Wide_Wide_Character is also OK here.
6390 -- See if the component type of the array corresponding to the
6391 -- string has compile time known bounds. If yes we can directly
6392 -- check whether the evaluation of the string will raise constraint
6393 -- error. Otherwise we need to transform the string literal into
6394 -- the corresponding character aggregate and let the aggregate
6395 -- code do the checking.
6397 if R_Typ = Standard_Character
6398 or else R_Typ = Standard_Wide_Character
6399 or else R_Typ = Standard_Wide_Wide_Character
6401 -- Check for the case of full range, where we are definitely OK
6403 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
6407 -- Here the range is not the complete base type range, so check
6410 Comp_Typ_Lo : constant Node_Id :=
6411 Type_Low_Bound (Component_Type (Typ));
6412 Comp_Typ_Hi : constant Node_Id :=
6413 Type_High_Bound (Component_Type (Typ));
6418 if Compile_Time_Known_Value (Comp_Typ_Lo)
6419 and then Compile_Time_Known_Value (Comp_Typ_Hi)
6421 for J in 1 .. Strlen loop
6422 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
6424 if Char_Val < Expr_Value (Comp_Typ_Lo)
6425 or else Char_Val > Expr_Value (Comp_Typ_Hi)
6427 Apply_Compile_Time_Constraint_Error
6428 (N, "character out of range?", CE_Range_Check_Failed,
6429 Loc => Source_Ptr (Int (Loc) + J));
6439 -- If we got here we meed to transform the string literal into the
6440 -- equivalent qualified positional array aggregate. This is rather
6441 -- heavy artillery for this situation, but it is hard work to avoid.
6444 Lits : constant List_Id := New_List;
6445 P : Source_Ptr := Loc + 1;
6449 -- Build the character literals, we give them source locations
6450 -- that correspond to the string positions, which is a bit tricky
6451 -- given the possible presence of wide character escape sequences.
6453 for J in 1 .. Strlen loop
6454 C := Get_String_Char (Str, J);
6455 Set_Character_Literal_Name (C);
6458 Make_Character_Literal (P,
6460 Char_Literal_Value => UI_From_CC (C)));
6462 if In_Character_Range (C) then
6465 -- Should we have a call to Skip_Wide here ???
6473 Make_Qualified_Expression (Loc,
6474 Subtype_Mark => New_Reference_To (Typ, Loc),
6476 Make_Aggregate (Loc, Expressions => Lits)));
6478 Analyze_And_Resolve (N, Typ);
6480 end Resolve_String_Literal;
6482 -----------------------------
6483 -- Resolve_Subprogram_Info --
6484 -----------------------------
6486 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
6489 end Resolve_Subprogram_Info;
6491 -----------------------------
6492 -- Resolve_Type_Conversion --
6493 -----------------------------
6495 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
6496 Conv_OK : constant Boolean := Conversion_OK (N);
6497 Target_Type : Entity_Id := Etype (N);
6499 Opnd_Type : Entity_Id;
6505 Operand := Expression (N);
6508 and then not Valid_Conversion (N, Target_Type, Operand)
6513 if Etype (Operand) = Any_Fixed then
6515 -- Mixed-mode operation involving a literal. Context must be a fixed
6516 -- type which is applied to the literal subsequently.
6518 if Is_Fixed_Point_Type (Typ) then
6519 Set_Etype (Operand, Universal_Real);
6521 elsif Is_Numeric_Type (Typ)
6522 and then (Nkind (Operand) = N_Op_Multiply
6523 or else Nkind (Operand) = N_Op_Divide)
6524 and then (Etype (Right_Opnd (Operand)) = Universal_Real
6525 or else Etype (Left_Opnd (Operand)) = Universal_Real)
6527 -- Return if expression is ambiguous
6529 if Unique_Fixed_Point_Type (N) = Any_Type then
6532 -- If nothing else, the available fixed type is Duration
6535 Set_Etype (Operand, Standard_Duration);
6538 -- Resolve the real operand with largest available precision
6539 if Etype (Right_Opnd (Operand)) = Universal_Real then
6540 Rop := New_Copy_Tree (Right_Opnd (Operand));
6542 Rop := New_Copy_Tree (Left_Opnd (Operand));
6545 Resolve (Rop, Standard_Long_Long_Float);
6547 -- If the operand is a literal (it could be a non-static and
6548 -- illegal exponentiation) check whether the use of Duration
6549 -- is potentially inaccurate.
6551 if Nkind (Rop) = N_Real_Literal
6552 and then Realval (Rop) /= Ureal_0
6553 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
6555 Error_Msg_N ("universal real operand can only be interpreted?",
6557 Error_Msg_N ("\as Duration, and will lose precision?", Rop);
6560 elsif Is_Numeric_Type (Typ)
6561 and then Nkind (Operand) in N_Op
6562 and then Unique_Fixed_Point_Type (N) /= Any_Type
6564 Set_Etype (Operand, Standard_Duration);
6567 Error_Msg_N ("invalid context for mixed mode operation", N);
6568 Set_Etype (Operand, Any_Type);
6573 Opnd_Type := Etype (Operand);
6576 -- Note: we do the Eval_Type_Conversion call before applying the
6577 -- required checks for a subtype conversion. This is important,
6578 -- since both are prepared under certain circumstances to change
6579 -- the type conversion to a constraint error node, but in the case
6580 -- of Eval_Type_Conversion this may reflect an illegality in the
6581 -- static case, and we would miss the illegality (getting only a
6582 -- warning message), if we applied the type conversion checks first.
6584 Eval_Type_Conversion (N);
6586 -- If after evaluation, we still have a type conversion, then we
6587 -- may need to apply checks required for a subtype conversion.
6589 -- Skip these type conversion checks if universal fixed operands
6590 -- operands involved, since range checks are handled separately for
6591 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
6593 if Nkind (N) = N_Type_Conversion
6594 and then not Is_Generic_Type (Root_Type (Target_Type))
6595 and then Target_Type /= Universal_Fixed
6596 and then Opnd_Type /= Universal_Fixed
6598 Apply_Type_Conversion_Checks (N);
6601 -- Issue warning for conversion of simple object to its own type
6602 -- We have to test the original nodes, since they may have been
6603 -- rewritten by various optimizations.
6605 Orig_N := Original_Node (N);
6607 if Warn_On_Redundant_Constructs
6608 and then Comes_From_Source (Orig_N)
6609 and then Nkind (Orig_N) = N_Type_Conversion
6610 and then not In_Instance
6612 Orig_N := Original_Node (Expression (Orig_N));
6613 Orig_T := Target_Type;
6615 -- If the node is part of a larger expression, the Target_Type
6616 -- may not be the original type of the node if the context is a
6617 -- condition. Recover original type to see if conversion is needed.
6619 if Is_Boolean_Type (Orig_T)
6620 and then Nkind (Parent (N)) in N_Op
6622 Orig_T := Etype (Parent (N));
6625 if Is_Entity_Name (Orig_N)
6626 and then Etype (Entity (Orig_N)) = Orig_T
6629 ("?useless conversion, & has this type", N, Entity (Orig_N));
6633 -- Ada 2005 (AI-251): Handle conversions to abstract interface types
6635 if Ada_Version >= Ada_05 then
6636 if Is_Access_Type (Target_Type) then
6637 Target_Type := Directly_Designated_Type (Target_Type);
6640 if Is_Class_Wide_Type (Target_Type) then
6641 Target_Type := Etype (Target_Type);
6644 if Is_Interface (Target_Type) then
6645 if Is_Access_Type (Opnd_Type) then
6646 Opnd_Type := Directly_Designated_Type (Opnd_Type);
6649 if Is_Class_Wide_Type (Opnd_Type) then
6650 Opnd_Type := Etype (Opnd_Type);
6653 if not Interface_Present_In_Ancestor
6655 Iface => Target_Type)
6658 ("(Ada 2005) does not implement interface }",
6659 Operand, Target_Type);
6662 -- If a conversion to an interface type appears as an actual in
6663 -- a source call, it will be expanded when the enclosing call
6664 -- itself is examined in Expand_Interface_Formals. Otherwise,
6665 -- generate the proper conversion code now, using the tag of
6668 if (Nkind (Parent (N)) = N_Procedure_Call_Statement
6669 or else Nkind (Parent (N)) = N_Function_Call)
6670 and then Comes_From_Source (N)
6674 Expand_Interface_Conversion (N);
6679 end Resolve_Type_Conversion;
6681 ----------------------
6682 -- Resolve_Unary_Op --
6683 ----------------------
6685 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
6686 B_Typ : constant Entity_Id := Base_Type (Typ);
6687 R : constant Node_Id := Right_Opnd (N);
6693 -- Generate warning for expressions like abs (x mod 2)
6695 if Warn_On_Redundant_Constructs
6696 and then Nkind (N) = N_Op_Abs
6698 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
6700 if OK and then Hi >= Lo and then Lo >= 0 then
6702 ("?abs applied to known non-negative value has no effect", N);
6706 -- Generate warning for expressions like -5 mod 3
6708 if Paren_Count (N) = 0
6709 and then Nkind (N) = N_Op_Minus
6710 and then Nkind (Right_Opnd (N)) = N_Op_Mod
6711 and then Comes_From_Source (N)
6714 ("?unary minus expression should be parenthesized here", N);
6717 if Comes_From_Source (N)
6718 and then Ekind (Entity (N)) = E_Function
6719 and then Is_Imported (Entity (N))
6720 and then Is_Intrinsic_Subprogram (Entity (N))
6722 Resolve_Intrinsic_Unary_Operator (N, Typ);
6726 if Etype (R) = Universal_Integer
6727 or else Etype (R) = Universal_Real
6729 Check_For_Visible_Operator (N, B_Typ);
6732 Set_Etype (N, B_Typ);
6735 Check_Unset_Reference (R);
6736 Generate_Operator_Reference (N, B_Typ);
6739 -- Set overflow checking bit. Much cleverer code needed here eventually
6740 -- and perhaps the Resolve routines should be separated for the various
6741 -- arithmetic operations, since they will need different processing ???
6743 if Nkind (N) in N_Op then
6744 if not Overflow_Checks_Suppressed (Etype (N)) then
6745 Enable_Overflow_Check (N);
6748 end Resolve_Unary_Op;
6750 ----------------------------------
6751 -- Resolve_Unchecked_Expression --
6752 ----------------------------------
6754 procedure Resolve_Unchecked_Expression
6759 Resolve (Expression (N), Typ, Suppress => All_Checks);
6761 end Resolve_Unchecked_Expression;
6763 ---------------------------------------
6764 -- Resolve_Unchecked_Type_Conversion --
6765 ---------------------------------------
6767 procedure Resolve_Unchecked_Type_Conversion
6771 pragma Warnings (Off, Typ);
6773 Operand : constant Node_Id := Expression (N);
6774 Opnd_Type : constant Entity_Id := Etype (Operand);
6777 -- Resolve operand using its own type
6779 Resolve (Operand, Opnd_Type);
6780 Eval_Unchecked_Conversion (N);
6782 end Resolve_Unchecked_Type_Conversion;
6784 ------------------------------
6785 -- Rewrite_Operator_As_Call --
6786 ------------------------------
6788 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
6789 Loc : constant Source_Ptr := Sloc (N);
6790 Actuals : constant List_Id := New_List;
6794 if Nkind (N) in N_Binary_Op then
6795 Append (Left_Opnd (N), Actuals);
6798 Append (Right_Opnd (N), Actuals);
6801 Make_Function_Call (Sloc => Loc,
6802 Name => New_Occurrence_Of (Nam, Loc),
6803 Parameter_Associations => Actuals);
6805 Preserve_Comes_From_Source (New_N, N);
6806 Preserve_Comes_From_Source (Name (New_N), N);
6808 Set_Etype (N, Etype (Nam));
6809 end Rewrite_Operator_As_Call;
6811 ------------------------------
6812 -- Rewrite_Renamed_Operator --
6813 ------------------------------
6815 procedure Rewrite_Renamed_Operator
6820 Nam : constant Name_Id := Chars (Op);
6821 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
6825 -- Rewrite the operator node using the real operator, not its
6826 -- renaming. Exclude user-defined intrinsic operations of the same
6827 -- name, which are treated separately and rewritten as calls.
6829 if Ekind (Op) /= E_Function
6830 or else Chars (N) /= Nam
6832 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
6833 Set_Chars (Op_Node, Nam);
6834 Set_Etype (Op_Node, Etype (N));
6835 Set_Entity (Op_Node, Op);
6836 Set_Right_Opnd (Op_Node, Right_Opnd (N));
6838 -- Indicate that both the original entity and its renaming
6839 -- are referenced at this point.
6841 Generate_Reference (Entity (N), N);
6842 Generate_Reference (Op, N);
6845 Set_Left_Opnd (Op_Node, Left_Opnd (N));
6848 Rewrite (N, Op_Node);
6850 -- If the context type is private, add the appropriate conversions
6851 -- so that the operator is applied to the full view. This is done
6852 -- in the routines that resolve intrinsic operators,
6854 if Is_Intrinsic_Subprogram (Op)
6855 and then Is_Private_Type (Typ)
6858 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
6859 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
6860 Resolve_Intrinsic_Operator (N, Typ);
6862 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
6863 Resolve_Intrinsic_Unary_Operator (N, Typ);
6870 elsif Ekind (Op) = E_Function
6871 and then Is_Intrinsic_Subprogram (Op)
6873 -- Operator renames a user-defined operator of the same name. Use
6874 -- the original operator in the node, which is the one that gigi
6878 Set_Is_Overloaded (N, False);
6880 end Rewrite_Renamed_Operator;
6882 -----------------------
6883 -- Set_Slice_Subtype --
6884 -----------------------
6886 -- Build an implicit subtype declaration to represent the type delivered
6887 -- by the slice. This is an abbreviated version of an array subtype. We
6888 -- define an index subtype for the slice, using either the subtype name
6889 -- or the discrete range of the slice. To be consistent with index usage
6890 -- elsewhere, we create a list header to hold the single index. This list
6891 -- is not otherwise attached to the syntax tree.
6893 procedure Set_Slice_Subtype (N : Node_Id) is
6894 Loc : constant Source_Ptr := Sloc (N);
6895 Index_List : constant List_Id := New_List;
6897 Index_Subtype : Entity_Id;
6898 Index_Type : Entity_Id;
6899 Slice_Subtype : Entity_Id;
6900 Drange : constant Node_Id := Discrete_Range (N);
6903 if Is_Entity_Name (Drange) then
6904 Index_Subtype := Entity (Drange);
6907 -- We force the evaluation of a range. This is definitely needed in
6908 -- the renamed case, and seems safer to do unconditionally. Note in
6909 -- any case that since we will create and insert an Itype referring
6910 -- to this range, we must make sure any side effect removal actions
6911 -- are inserted before the Itype definition.
6913 if Nkind (Drange) = N_Range then
6914 Force_Evaluation (Low_Bound (Drange));
6915 Force_Evaluation (High_Bound (Drange));
6918 Index_Type := Base_Type (Etype (Drange));
6920 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
6922 Set_Scalar_Range (Index_Subtype, Drange);
6923 Set_Etype (Index_Subtype, Index_Type);
6924 Set_Size_Info (Index_Subtype, Index_Type);
6925 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
6928 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
6930 Index := New_Occurrence_Of (Index_Subtype, Loc);
6931 Set_Etype (Index, Index_Subtype);
6932 Append (Index, Index_List);
6934 Set_First_Index (Slice_Subtype, Index);
6935 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
6936 Set_Is_Constrained (Slice_Subtype, True);
6937 Init_Size_Align (Slice_Subtype);
6939 Check_Compile_Time_Size (Slice_Subtype);
6941 -- The Etype of the existing Slice node is reset to this slice
6942 -- subtype. Its bounds are obtained from its first index.
6944 Set_Etype (N, Slice_Subtype);
6946 -- In the packed case, this must be immediately frozen
6948 -- Couldn't we always freeze here??? and if we did, then the above
6949 -- call to Check_Compile_Time_Size could be eliminated, which would
6950 -- be nice, because then that routine could be made private to Freeze.
6952 if Is_Packed (Slice_Subtype) and not In_Default_Expression then
6953 Freeze_Itype (Slice_Subtype, N);
6956 end Set_Slice_Subtype;
6958 --------------------------------
6959 -- Set_String_Literal_Subtype --
6960 --------------------------------
6962 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
6963 Subtype_Id : Entity_Id;
6966 if Nkind (N) /= N_String_Literal then
6969 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
6972 Set_String_Literal_Length (Subtype_Id, UI_From_Int
6973 (String_Length (Strval (N))));
6974 Set_Etype (Subtype_Id, Base_Type (Typ));
6975 Set_Is_Constrained (Subtype_Id);
6977 -- The low bound is set from the low bound of the corresponding
6978 -- index type. Note that we do not store the high bound in the
6979 -- string literal subtype, but it can be deduced if necssary
6980 -- from the length and the low bound.
6982 Set_String_Literal_Low_Bound
6983 (Subtype_Id, Type_Low_Bound (Etype (First_Index (Typ))));
6985 Set_Etype (N, Subtype_Id);
6986 end Set_String_Literal_Subtype;
6988 -----------------------------
6989 -- Unique_Fixed_Point_Type --
6990 -----------------------------
6992 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
6993 T1 : Entity_Id := Empty;
6998 procedure Fixed_Point_Error;
6999 -- If true ambiguity, give details
7001 -----------------------
7002 -- Fixed_Point_Error --
7003 -----------------------
7005 procedure Fixed_Point_Error is
7007 Error_Msg_N ("ambiguous universal_fixed_expression", N);
7008 Error_Msg_NE ("\possible interpretation as}", N, T1);
7009 Error_Msg_NE ("\possible interpretation as}", N, T2);
7010 end Fixed_Point_Error;
7012 -- Start of processing for Unique_Fixed_Point_Type
7015 -- The operations on Duration are visible, so Duration is always a
7016 -- possible interpretation.
7018 T1 := Standard_Duration;
7020 -- Look for fixed-point types in enclosing scopes
7022 Scop := Current_Scope;
7023 while Scop /= Standard_Standard loop
7024 T2 := First_Entity (Scop);
7025 while Present (T2) loop
7026 if Is_Fixed_Point_Type (T2)
7027 and then Current_Entity (T2) = T2
7028 and then Scope (Base_Type (T2)) = Scop
7030 if Present (T1) then
7041 Scop := Scope (Scop);
7044 -- Look for visible fixed type declarations in the context
7046 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
7047 while Present (Item) loop
7048 if Nkind (Item) = N_With_Clause then
7049 Scop := Entity (Name (Item));
7050 T2 := First_Entity (Scop);
7051 while Present (T2) loop
7052 if Is_Fixed_Point_Type (T2)
7053 and then Scope (Base_Type (T2)) = Scop
7054 and then (Is_Potentially_Use_Visible (T2)
7055 or else In_Use (T2))
7057 if Present (T1) then
7072 if Nkind (N) = N_Real_Literal then
7073 Error_Msg_NE ("real literal interpreted as }?", N, T1);
7076 Error_Msg_NE ("universal_fixed expression interpreted as }?", N, T1);
7080 end Unique_Fixed_Point_Type;
7082 ----------------------
7083 -- Valid_Conversion --
7084 ----------------------
7086 function Valid_Conversion
7089 Operand : Node_Id) return Boolean
7091 Target_Type : constant Entity_Id := Base_Type (Target);
7092 Opnd_Type : Entity_Id := Etype (Operand);
7094 function Conversion_Check
7096 Msg : String) return Boolean;
7097 -- Little routine to post Msg if Valid is False, returns Valid value
7099 function Valid_Tagged_Conversion
7100 (Target_Type : Entity_Id;
7101 Opnd_Type : Entity_Id) return Boolean;
7102 -- Specifically test for validity of tagged conversions
7104 ----------------------
7105 -- Conversion_Check --
7106 ----------------------
7108 function Conversion_Check
7110 Msg : String) return Boolean
7114 Error_Msg_N (Msg, Operand);
7118 end Conversion_Check;
7120 -----------------------------
7121 -- Valid_Tagged_Conversion --
7122 -----------------------------
7124 function Valid_Tagged_Conversion
7125 (Target_Type : Entity_Id;
7126 Opnd_Type : Entity_Id) return Boolean
7129 -- Upward conversions are allowed (RM 4.6(22))
7131 if Covers (Target_Type, Opnd_Type)
7132 or else Is_Ancestor (Target_Type, Opnd_Type)
7136 -- Downward conversion are allowed if the operand is class-wide
7139 elsif Is_Class_Wide_Type (Opnd_Type)
7140 and then Covers (Opnd_Type, Target_Type)
7144 elsif Covers (Opnd_Type, Target_Type)
7145 or else Is_Ancestor (Opnd_Type, Target_Type)
7148 Conversion_Check (False,
7149 "downward conversion of tagged objects not allowed");
7151 -- Ada 2005 (AI-251): The conversion of a tagged type to an
7152 -- abstract interface type is always valid
7154 elsif Is_Interface (Target_Type) then
7159 ("invalid tagged conversion, not compatible with}",
7160 N, First_Subtype (Opnd_Type));
7163 end Valid_Tagged_Conversion;
7165 -- Start of processing for Valid_Conversion
7168 Check_Parameterless_Call (Operand);
7170 if Is_Overloaded (Operand) then
7179 -- Remove procedure calls, which syntactically cannot appear
7180 -- in this context, but which cannot be removed by type checking,
7181 -- because the context does not impose a type.
7183 -- When compiling for VMS, spurious ambiguities can be produced
7184 -- when arithmetic operations have a literal operand and return
7185 -- System.Address or a descendant of it. These ambiguities are
7186 -- otherwise resolved by the context, but for conversions there
7187 -- is no context type and the removal of the spurious operations
7188 -- must be done explicitly here.
7190 Get_First_Interp (Operand, I, It);
7192 while Present (It.Typ) loop
7193 if It.Typ = Standard_Void_Type then
7197 if Present (System_Aux_Id)
7198 and then Is_Descendent_Of_Address (It.Typ)
7203 Get_Next_Interp (I, It);
7206 Get_First_Interp (Operand, I, It);
7211 Error_Msg_N ("illegal operand in conversion", Operand);
7215 Get_Next_Interp (I, It);
7217 if Present (It.Typ) then
7219 It1 := Disambiguate (Operand, I1, I, Any_Type);
7221 if It1 = No_Interp then
7222 Error_Msg_N ("ambiguous operand in conversion", Operand);
7224 Error_Msg_Sloc := Sloc (It.Nam);
7225 Error_Msg_N ("possible interpretation#!", Operand);
7227 Error_Msg_Sloc := Sloc (N1);
7228 Error_Msg_N ("possible interpretation#!", Operand);
7234 Set_Etype (Operand, It1.Typ);
7235 Opnd_Type := It1.Typ;
7239 if Chars (Current_Scope) = Name_Unchecked_Conversion then
7241 -- This check is dubious, what if there were a user defined
7242 -- scope whose name was Unchecked_Conversion ???
7246 elsif Is_Numeric_Type (Target_Type) then
7247 if Opnd_Type = Universal_Fixed then
7250 elsif (In_Instance or else In_Inlined_Body)
7251 and then not Comes_From_Source (N)
7256 return Conversion_Check (Is_Numeric_Type (Opnd_Type),
7257 "illegal operand for numeric conversion");
7260 elsif Is_Array_Type (Target_Type) then
7261 if not Is_Array_Type (Opnd_Type)
7262 or else Opnd_Type = Any_Composite
7263 or else Opnd_Type = Any_String
7266 ("illegal operand for array conversion", Operand);
7269 elsif Number_Dimensions (Target_Type) /=
7270 Number_Dimensions (Opnd_Type)
7273 ("incompatible number of dimensions for conversion", Operand);
7278 Target_Index : Node_Id := First_Index (Target_Type);
7279 Opnd_Index : Node_Id := First_Index (Opnd_Type);
7281 Target_Index_Type : Entity_Id;
7282 Opnd_Index_Type : Entity_Id;
7284 Target_Comp_Type : constant Entity_Id :=
7285 Component_Type (Target_Type);
7286 Opnd_Comp_Type : constant Entity_Id :=
7287 Component_Type (Opnd_Type);
7290 while Present (Target_Index) and then Present (Opnd_Index) loop
7291 Target_Index_Type := Etype (Target_Index);
7292 Opnd_Index_Type := Etype (Opnd_Index);
7294 if not (Is_Integer_Type (Target_Index_Type)
7295 and then Is_Integer_Type (Opnd_Index_Type))
7296 and then (Root_Type (Target_Index_Type)
7297 /= Root_Type (Opnd_Index_Type))
7300 ("incompatible index types for array conversion",
7305 Next_Index (Target_Index);
7306 Next_Index (Opnd_Index);
7309 if Base_Type (Target_Comp_Type) /=
7310 Base_Type (Opnd_Comp_Type)
7313 ("incompatible component types for array conversion",
7318 Is_Constrained (Target_Comp_Type)
7319 /= Is_Constrained (Opnd_Comp_Type)
7320 or else not Subtypes_Statically_Match
7321 (Target_Comp_Type, Opnd_Comp_Type)
7324 ("component subtypes must statically match", Operand);
7333 -- Ada 2005 (AI-251)
7335 elsif (Ekind (Target_Type) = E_General_Access_Type
7336 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
7337 and then Is_Interface (Directly_Designated_Type (Target_Type))
7339 -- Check the static accessibility rule of 4.6(17). Note that the
7340 -- check is not enforced when within an instance body, since the RM
7341 -- requires such cases to be caught at run time.
7343 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
7344 if Type_Access_Level (Opnd_Type) >
7345 Type_Access_Level (Target_Type)
7347 -- In an instance, this is a run-time check, but one we know
7348 -- will fail, so generate an appropriate warning. The raise
7349 -- will be generated by Expand_N_Type_Conversion.
7351 if In_Instance_Body then
7353 ("?cannot convert local pointer to non-local access type",
7356 ("?Program_Error will be raised at run time", Operand);
7360 ("cannot convert local pointer to non-local access type",
7365 -- Special accessibility checks are needed in the case of access
7366 -- discriminants declared for a limited type.
7368 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
7369 and then not Is_Local_Anonymous_Access (Opnd_Type)
7371 -- When the operand is a selected access discriminant the check
7372 -- needs to be made against the level of the object denoted by
7373 -- the prefix of the selected name. (Object_Access_Level
7374 -- handles checking the prefix of the operand for this case.)
7376 if Nkind (Operand) = N_Selected_Component
7377 and then Object_Access_Level (Operand)
7378 > Type_Access_Level (Target_Type)
7380 -- In an instance, this is a run-time check, but one we
7381 -- know will fail, so generate an appropriate warning.
7382 -- The raise will be generated by Expand_N_Type_Conversion.
7384 if In_Instance_Body then
7386 ("?cannot convert access discriminant to non-local" &
7387 " access type", Operand);
7389 ("?Program_Error will be raised at run time", Operand);
7393 ("cannot convert access discriminant to non-local" &
7394 " access type", Operand);
7399 -- The case of a reference to an access discriminant from
7400 -- within a limited type declaration (which will appear as
7401 -- a discriminal) is always illegal because the level of the
7402 -- discriminant is considered to be deeper than any (namable)
7405 if Is_Entity_Name (Operand)
7406 and then not Is_Local_Anonymous_Access (Opnd_Type)
7407 and then (Ekind (Entity (Operand)) = E_In_Parameter
7408 or else Ekind (Entity (Operand)) = E_Constant)
7409 and then Present (Discriminal_Link (Entity (Operand)))
7412 ("discriminant has deeper accessibility level than target",
7421 elsif (Ekind (Target_Type) = E_General_Access_Type
7422 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
7425 (Is_Access_Type (Opnd_Type)
7426 and then Ekind (Opnd_Type) /=
7427 E_Access_Subprogram_Type
7428 and then Ekind (Opnd_Type) /=
7429 E_Access_Protected_Subprogram_Type,
7430 "must be an access-to-object type")
7432 if Is_Access_Constant (Opnd_Type)
7433 and then not Is_Access_Constant (Target_Type)
7436 ("access-to-constant operand type not allowed", Operand);
7440 -- Check the static accessibility rule of 4.6(17). Note that the
7441 -- check is not enforced when within an instance body, since the RM
7442 -- requires such cases to be caught at run time.
7444 if Ekind (Target_Type) /= E_Anonymous_Access_Type
7445 or else Is_Local_Anonymous_Access (Target_Type)
7447 if Type_Access_Level (Opnd_Type)
7448 > Type_Access_Level (Target_Type)
7450 -- In an instance, this is a run-time check, but one we
7451 -- know will fail, so generate an appropriate warning.
7452 -- The raise will be generated by Expand_N_Type_Conversion.
7454 if In_Instance_Body then
7456 ("?cannot convert local pointer to non-local access type",
7459 ("?Program_Error will be raised at run time", Operand);
7463 ("cannot convert local pointer to non-local access type",
7468 -- Special accessibility checks are needed in the case of access
7469 -- discriminants declared for a limited type.
7471 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
7472 and then not Is_Local_Anonymous_Access (Opnd_Type)
7475 -- When the operand is a selected access discriminant the check
7476 -- needs to be made against the level of the object denoted by
7477 -- the prefix of the selected name. (Object_Access_Level
7478 -- handles checking the prefix of the operand for this case.)
7480 if Nkind (Operand) = N_Selected_Component
7481 and then Object_Access_Level (Operand)
7482 > Type_Access_Level (Target_Type)
7484 -- In an instance, this is a run-time check, but one we
7485 -- know will fail, so generate an appropriate warning.
7486 -- The raise will be generated by Expand_N_Type_Conversion.
7488 if In_Instance_Body then
7490 ("?cannot convert access discriminant to non-local" &
7491 " access type", Operand);
7493 ("?Program_Error will be raised at run time", Operand);
7497 ("cannot convert access discriminant to non-local" &
7498 " access type", Operand);
7503 -- The case of a reference to an access discriminant from
7504 -- within a limited type declaration (which will appear as
7505 -- a discriminal) is always illegal because the level of the
7506 -- discriminant is considered to be deeper than any (namable)
7509 if Is_Entity_Name (Operand)
7510 and then (Ekind (Entity (Operand)) = E_In_Parameter
7511 or else Ekind (Entity (Operand)) = E_Constant)
7512 and then Present (Discriminal_Link (Entity (Operand)))
7515 ("discriminant has deeper accessibility level than target",
7523 Target : constant Entity_Id := Designated_Type (Target_Type);
7524 Opnd : constant Entity_Id := Designated_Type (Opnd_Type);
7527 if Is_Tagged_Type (Target) then
7528 return Valid_Tagged_Conversion (Target, Opnd);
7531 if Base_Type (Target) /= Base_Type (Opnd) then
7533 ("target designated type not compatible with }",
7534 N, Base_Type (Opnd));
7537 -- Ada 2005 AI-384: legality rule is symmetric in both
7538 -- designated types. The conversion is legal (with possible
7539 -- constraint check) if either designated type is
7542 elsif Subtypes_Statically_Match (Target, Opnd)
7544 (Has_Discriminants (Target)
7546 (not Is_Constrained (Opnd)
7547 or else not Is_Constrained (Target)))
7553 ("target designated subtype not compatible with }",
7560 elsif (Ekind (Target_Type) = E_Access_Subprogram_Type
7562 Ekind (Target_Type) = E_Anonymous_Access_Subprogram_Type)
7563 and then No (Corresponding_Remote_Type (Opnd_Type))
7564 and then Conversion_Check
7565 (Ekind (Base_Type (Opnd_Type)) = E_Access_Subprogram_Type,
7566 "illegal operand for access subprogram conversion")
7568 -- Check that the designated types are subtype conformant
7570 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
7571 Old_Id => Designated_Type (Opnd_Type),
7574 -- Check the static accessibility rule of 4.6(20)
7576 if Type_Access_Level (Opnd_Type) >
7577 Type_Access_Level (Target_Type)
7580 ("operand type has deeper accessibility level than target",
7583 -- Check that if the operand type is declared in a generic body,
7584 -- then the target type must be declared within that same body
7585 -- (enforces last sentence of 4.6(20)).
7587 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
7589 O_Gen : constant Node_Id :=
7590 Enclosing_Generic_Body (Opnd_Type);
7595 T_Gen := Enclosing_Generic_Body (Target_Type);
7596 while Present (T_Gen) and then T_Gen /= O_Gen loop
7597 T_Gen := Enclosing_Generic_Body (T_Gen);
7600 if T_Gen /= O_Gen then
7602 ("target type must be declared in same generic body"
7603 & " as operand type", N);
7610 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
7611 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
7613 -- It is valid to convert from one RAS type to another provided
7614 -- that their specification statically match.
7616 Check_Subtype_Conformant
7618 Designated_Type (Corresponding_Remote_Type (Target_Type)),
7620 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
7625 elsif Is_Tagged_Type (Target_Type) then
7626 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
7628 -- Types derived from the same root type are convertible
7630 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
7633 -- In an instance, there may be inconsistent views of the same
7634 -- type, or types derived from the same type.
7637 and then Underlying_Type (Target_Type) = Underlying_Type (Opnd_Type)
7641 -- Special check for common access type error case
7643 elsif Ekind (Target_Type) = E_Access_Type
7644 and then Is_Access_Type (Opnd_Type)
7646 Error_Msg_N ("target type must be general access type!", N);
7647 Error_Msg_NE ("add ALL to }!", N, Target_Type);
7652 Error_Msg_NE ("invalid conversion, not compatible with }",
7657 end Valid_Conversion;