1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Debug_A; use Debug_A;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Ch7; use Exp_Ch7;
35 with Exp_Tss; use Exp_Tss;
36 with Exp_Util; use Exp_Util;
37 with Freeze; use Freeze;
38 with Itypes; use Itypes;
40 with Lib.Xref; use Lib.Xref;
41 with Namet; use Namet;
42 with Nmake; use Nmake;
43 with Nlists; use Nlists;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
50 with Sem_Aggr; use Sem_Aggr;
51 with Sem_Attr; use Sem_Attr;
52 with Sem_Cat; use Sem_Cat;
53 with Sem_Ch4; use Sem_Ch4;
54 with Sem_Ch6; use Sem_Ch6;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Dist; use Sem_Dist;
58 with Sem_Elab; use Sem_Elab;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Intr; use Sem_Intr;
61 with Sem_Util; use Sem_Util;
62 with Sem_Type; use Sem_Type;
63 with Sem_Warn; use Sem_Warn;
64 with Sinfo; use Sinfo;
65 with Snames; use Snames;
66 with Stand; use Stand;
67 with Stringt; use Stringt;
68 with Targparm; use Targparm;
69 with Tbuild; use Tbuild;
70 with Uintp; use Uintp;
71 with Urealp; use Urealp;
73 package body Sem_Res is
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 -- Second pass (top-down) type checking and overload resolution procedures
80 -- Typ is the type required by context. These procedures propagate the
81 -- type information recursively to the descendants of N. If the node
82 -- is not overloaded, its Etype is established in the first pass. If
83 -- overloaded, the Resolve routines set the correct type. For arith.
84 -- operators, the Etype is the base type of the context.
86 -- Note that Resolve_Attribute is separated off in Sem_Attr
88 procedure Ambiguous_Character (C : Node_Id);
89 -- Give list of candidate interpretations when a character literal cannot
92 procedure Check_Direct_Boolean_Op (N : Node_Id);
93 -- N is a binary operator node which may possibly operate on Boolean
94 -- operands. If the operator does have Boolean operands, then a call is
95 -- made to check the restriction No_Direct_Boolean_Operators.
97 procedure Check_Discriminant_Use (N : Node_Id);
98 -- Enforce the restrictions on the use of discriminants when constraining
99 -- a component of a discriminated type (record or concurrent type).
101 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
102 -- Given a node for an operator associated with type T, check that
103 -- the operator is visible. Operators all of whose operands are
104 -- universal must be checked for visibility during resolution
105 -- because their type is not determinable based on their operands.
107 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
108 -- Given a call node, N, which is known to occur immediately within the
109 -- subprogram being called, determines whether it is a detectable case of
110 -- an infinite recursion, and if so, outputs appropriate messages. Returns
111 -- True if an infinite recursion is detected, and False otherwise.
113 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
114 -- If the type of the object being initialized uses the secondary stack
115 -- directly or indirectly, create a transient scope for the call to the
116 -- init proc. This is because we do not create transient scopes for the
117 -- initialization of individual components within the init proc itself.
118 -- Could be optimized away perhaps?
120 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
121 -- Utility to check whether the name in the call is a predefined
122 -- operator, in which case the call is made into an operator node.
123 -- An instance of an intrinsic conversion operation may be given
124 -- an operator name, but is not treated like an operator.
126 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
127 -- If a default expression in entry call N depends on the discriminants
128 -- of the task, it must be replaced with a reference to the discriminant
129 -- of the task being called.
131 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
132 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
133 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
134 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
135 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
136 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
137 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
138 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
139 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
140 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
141 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
142 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
143 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
144 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
145 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
146 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
147 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
148 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
149 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
150 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
151 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
152 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
153 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
154 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
155 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
156 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
157 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
158 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
159 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
160 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
161 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
162 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
164 function Operator_Kind
166 Is_Binary : Boolean) return Node_Kind;
167 -- Utility to map the name of an operator into the corresponding Node. Used
168 -- by other node rewriting procedures.
170 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
171 -- Resolve actuals of call, and add default expressions for missing ones.
173 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
174 -- Called from Resolve_Call, when the prefix denotes an entry or element
175 -- of entry family. Actuals are resolved as for subprograms, and the node
176 -- is rebuilt as an entry call. Also called for protected operations. Typ
177 -- is the context type, which is used when the operation is a protected
178 -- function with no arguments, and the return value is indexed.
180 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
181 -- A call to a user-defined intrinsic operator is rewritten as a call
182 -- to the corresponding predefined operator, with suitable conversions.
184 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
185 -- Ditto, for unary operators (only arithmetic ones).
187 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
188 -- If an operator node resolves to a call to a user-defined operator,
189 -- rewrite the node as a function call.
191 procedure Make_Call_Into_Operator
195 -- Inverse transformation: if an operator is given in functional notation,
196 -- then after resolving the node, transform into an operator node, so
197 -- that operands are resolved properly. Recall that predefined operators
198 -- do not have a full signature and special resolution rules apply.
200 procedure Rewrite_Renamed_Operator
204 -- An operator can rename another, e.g. in an instantiation. In that
205 -- case, the proper operator node must be constructed and resolved.
207 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
208 -- The String_Literal_Subtype is built for all strings that are not
209 -- operands of a static concatenation operation. If the argument is
210 -- not a N_String_Literal node, then the call has no effect.
212 procedure Set_Slice_Subtype (N : Node_Id);
213 -- Build subtype of array type, with the range specified by the slice
215 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
216 -- A universal_fixed expression in an universal context is unambiguous
217 -- if there is only one applicable fixed point type. Determining whether
218 -- there is only one requires a search over all visible entities, and
219 -- happens only in very pathological cases (see 6115-006).
221 function Valid_Conversion
224 Operand : Node_Id) return Boolean;
225 -- Verify legality rules given in 4.6 (8-23). Target is the target
226 -- type of the conversion, which may be an implicit conversion of
227 -- an actual parameter to an anonymous access type (in which case
228 -- N denotes the actual parameter and N = Operand).
230 -------------------------
231 -- Ambiguous_Character --
232 -------------------------
234 procedure Ambiguous_Character (C : Node_Id) is
238 if Nkind (C) = N_Character_Literal then
239 Error_Msg_N ("ambiguous character literal", C);
241 ("\possible interpretations: Character, Wide_Character!", C);
243 E := Current_Entity (C);
247 while Present (E) loop
248 Error_Msg_NE ("\possible interpretation:}!", C, Etype (E));
253 end Ambiguous_Character;
255 -------------------------
256 -- Analyze_And_Resolve --
257 -------------------------
259 procedure Analyze_And_Resolve (N : Node_Id) is
263 end Analyze_And_Resolve;
265 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
269 end Analyze_And_Resolve;
271 -- Version withs check(s) suppressed
273 procedure Analyze_And_Resolve
278 Scop : constant Entity_Id := Current_Scope;
281 if Suppress = All_Checks then
283 Svg : constant Suppress_Array := Scope_Suppress;
286 Scope_Suppress := (others => True);
287 Analyze_And_Resolve (N, Typ);
288 Scope_Suppress := Svg;
293 Svg : constant Boolean := Scope_Suppress (Suppress);
296 Scope_Suppress (Suppress) := True;
297 Analyze_And_Resolve (N, Typ);
298 Scope_Suppress (Suppress) := Svg;
302 if Current_Scope /= Scop
303 and then Scope_Is_Transient
305 -- This can only happen if a transient scope was created
306 -- for an inner expression, which will be removed upon
307 -- completion of the analysis of an enclosing construct.
308 -- The transient scope must have the suppress status of
309 -- the enclosing environment, not of this Analyze call.
311 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
314 end Analyze_And_Resolve;
316 procedure Analyze_And_Resolve
320 Scop : constant Entity_Id := Current_Scope;
323 if Suppress = All_Checks then
325 Svg : constant Suppress_Array := Scope_Suppress;
328 Scope_Suppress := (others => True);
329 Analyze_And_Resolve (N);
330 Scope_Suppress := Svg;
335 Svg : constant Boolean := Scope_Suppress (Suppress);
338 Scope_Suppress (Suppress) := True;
339 Analyze_And_Resolve (N);
340 Scope_Suppress (Suppress) := Svg;
344 if Current_Scope /= Scop
345 and then Scope_Is_Transient
347 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
350 end Analyze_And_Resolve;
352 -----------------------------
353 -- Check_Direct_Boolean_Op --
354 -----------------------------
356 procedure Check_Direct_Boolean_Op (N : Node_Id) is
358 if Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean then
359 Check_Restriction (No_Direct_Boolean_Operators, N);
361 end Check_Direct_Boolean_Op;
363 ----------------------------
364 -- Check_Discriminant_Use --
365 ----------------------------
367 procedure Check_Discriminant_Use (N : Node_Id) is
368 PN : constant Node_Id := Parent (N);
369 Disc : constant Entity_Id := Entity (N);
374 -- Any use in a default expression is legal.
376 if In_Default_Expression then
379 elsif Nkind (PN) = N_Range then
381 -- Discriminant cannot be used to constrain a scalar type.
385 if Nkind (P) = N_Range_Constraint
386 and then Nkind (Parent (P)) = N_Subtype_Indication
387 and then Nkind (Parent (Parent (P))) = N_Component_Definition
389 Error_Msg_N ("discriminant cannot constrain scalar type", N);
391 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
393 -- The following check catches the unusual case where
394 -- a discriminant appears within an index constraint
395 -- that is part of a larger expression within a constraint
396 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
397 -- For now we only check case of record components, and
398 -- note that a similar check should also apply in the
399 -- case of discriminant constraints below. ???
401 -- Note that the check for N_Subtype_Declaration below is to
402 -- detect the valid use of discriminants in the constraints of a
403 -- subtype declaration when this subtype declaration appears
404 -- inside the scope of a record type (which is syntactically
405 -- illegal, but which may be created as part of derived type
406 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
409 if Ekind (Current_Scope) = E_Record_Type
410 and then Scope (Disc) = Current_Scope
412 (Nkind (Parent (P)) = N_Subtype_Indication
414 (Nkind (Parent (Parent (P))) = N_Component_Definition
416 Nkind (Parent (Parent (P))) = N_Subtype_Declaration)
417 and then Paren_Count (N) = 0)
420 ("discriminant must appear alone in component constraint", N);
424 -- Detect a common beginner error:
426 -- type R (D : Positive := 100) is record
427 -- Name : String (1 .. D);
430 -- The default value causes an object of type R to be
431 -- allocated with room for Positive'Last characters.
439 function Large_Storage_Type (T : Entity_Id) return Boolean;
440 -- Return True if type T has a large enough range that
441 -- any array whose index type covered the whole range of
442 -- the type would likely raise Storage_Error.
444 ------------------------
445 -- Large_Storage_Type --
446 ------------------------
448 function Large_Storage_Type (T : Entity_Id) return Boolean is
453 T = Standard_Positive
455 T = Standard_Natural;
456 end Large_Storage_Type;
459 -- Check that the Disc has a large range
461 if not Large_Storage_Type (Etype (Disc)) then
465 -- If the enclosing type is limited, we allocate only the
466 -- default value, not the maximum, and there is no need for
469 if Is_Limited_Type (Scope (Disc)) then
473 -- Check that it is the high bound
475 if N /= High_Bound (PN)
476 or else not Present (Discriminant_Default_Value (Disc))
481 -- Check the array allows a large range at this bound.
482 -- First find the array
486 if Nkind (SI) /= N_Subtype_Indication then
490 T := Entity (Subtype_Mark (SI));
492 if not Is_Array_Type (T) then
496 -- Next, find the dimension
498 TB := First_Index (T);
499 CB := First (Constraints (P));
501 and then Present (TB)
502 and then Present (CB)
513 -- Now, check the dimension has a large range
515 if not Large_Storage_Type (Etype (TB)) then
519 -- Warn about the danger
522 ("creation of & object may raise Storage_Error?",
531 -- Legal case is in index or discriminant constraint
533 elsif Nkind (PN) = N_Index_Or_Discriminant_Constraint
534 or else Nkind (PN) = N_Discriminant_Association
536 if Paren_Count (N) > 0 then
538 ("discriminant in constraint must appear alone", N);
543 -- Otherwise, context is an expression. It should not be within
544 -- (i.e. a subexpression of) a constraint for a component.
550 while Nkind (P) /= N_Component_Declaration
551 and then Nkind (P) /= N_Subtype_Indication
552 and then Nkind (P) /= N_Entry_Declaration
559 -- If the discriminant is used in an expression that is a bound
560 -- of a scalar type, an Itype is created and the bounds are attached
561 -- to its range, not to the original subtype indication. Such use
562 -- is of course a double fault.
564 if (Nkind (P) = N_Subtype_Indication
566 (Nkind (Parent (P)) = N_Component_Definition
568 Nkind (Parent (P)) = N_Derived_Type_Definition)
569 and then D = Constraint (P))
571 -- The constraint itself may be given by a subtype indication,
572 -- rather than by a more common discrete range.
574 or else (Nkind (P) = N_Subtype_Indication
576 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
577 or else Nkind (P) = N_Entry_Declaration
578 or else Nkind (D) = N_Defining_Identifier
581 ("discriminant in constraint must appear alone", N);
584 end Check_Discriminant_Use;
586 --------------------------------
587 -- Check_For_Visible_Operator --
588 --------------------------------
590 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
592 if Is_Invisible_Operator (N, T) then
594 ("operator for} is not directly visible!", N, First_Subtype (T));
595 Error_Msg_N ("use clause would make operation legal!", N);
597 end Check_For_Visible_Operator;
599 ------------------------------
600 -- Check_Infinite_Recursion --
601 ------------------------------
603 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
607 function Same_Argument_List return Boolean;
608 -- Check whether list of actuals is identical to list of formals
609 -- of called function (which is also the enclosing scope).
611 ------------------------
612 -- Same_Argument_List --
613 ------------------------
615 function Same_Argument_List return Boolean is
621 if not Is_Entity_Name (Name (N)) then
624 Subp := Entity (Name (N));
627 F := First_Formal (Subp);
628 A := First_Actual (N);
630 while Present (F) and then Present (A) loop
631 if not Is_Entity_Name (A)
632 or else Entity (A) /= F
642 end Same_Argument_List;
644 -- Start of processing for Check_Infinite_Recursion
647 -- Loop moving up tree, quitting if something tells us we are
648 -- definitely not in an infinite recursion situation.
653 exit when Nkind (P) = N_Subprogram_Body;
655 if Nkind (P) = N_Or_Else or else
656 Nkind (P) = N_And_Then or else
657 Nkind (P) = N_If_Statement or else
658 Nkind (P) = N_Case_Statement
662 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
663 and then C /= First (Statements (P))
665 -- If the call is the expression of a return statement and
666 -- the actuals are identical to the formals, it's worth a
667 -- warning. However, we skip this if there is an immediately
668 -- preceding raise statement, since the call is never executed.
670 -- Furthermore, this corresponds to a common idiom:
672 -- function F (L : Thing) return Boolean is
674 -- raise Program_Error;
678 -- for generating a stub function
680 if Nkind (Parent (N)) = N_Return_Statement
681 and then Same_Argument_List
683 exit when not Is_List_Member (Parent (N))
684 or else (Nkind (Prev (Parent (N))) /= N_Raise_Statement
686 (Nkind (Prev (Parent (N))) not in N_Raise_xxx_Error
688 Present (Condition (Prev (Parent (N))))));
698 Error_Msg_N ("possible infinite recursion?", N);
699 Error_Msg_N ("\Storage_Error may be raised at run time?", N);
702 end Check_Infinite_Recursion;
704 -------------------------------
705 -- Check_Initialization_Call --
706 -------------------------------
708 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
709 Typ : constant Entity_Id := Etype (First_Formal (Nam));
711 function Uses_SS (T : Entity_Id) return Boolean;
712 -- Check whether the creation of an object of the type will involve
713 -- use of the secondary stack. If T is a record type, this is true
714 -- if the expression for some component uses the secondary stack, eg.
715 -- through a call to a function that returns an unconstrained value.
716 -- False if T is controlled, because cleanups occur elsewhere.
722 function Uses_SS (T : Entity_Id) return Boolean is
727 if Is_Controlled (T) then
730 elsif Is_Array_Type (T) then
731 return Uses_SS (Component_Type (T));
733 elsif Is_Record_Type (T) then
734 Comp := First_Component (T);
736 while Present (Comp) loop
738 if Ekind (Comp) = E_Component
739 and then Nkind (Parent (Comp)) = N_Component_Declaration
741 Expr := Expression (Parent (Comp));
743 -- The expression for a dynamic component may be
744 -- rewritten as a dereference. Retrieve original
747 if Nkind (Original_Node (Expr)) = N_Function_Call
748 and then Requires_Transient_Scope (Etype (Expr))
752 elsif Uses_SS (Etype (Comp)) then
757 Next_Component (Comp);
767 -- Start of processing for Check_Initialization_Call
770 -- Nothing to do if functions do not use the secondary stack for
771 -- returns (i.e. they use a depressed stack pointer instead).
773 if Functions_Return_By_DSP_On_Target then
776 -- Otherwise establish a transient scope if the type needs it
778 elsif Uses_SS (Typ) then
779 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
781 end Check_Initialization_Call;
783 ------------------------------
784 -- Check_Parameterless_Call --
785 ------------------------------
787 procedure Check_Parameterless_Call (N : Node_Id) is
791 -- Defend against junk stuff if errors already detected
793 if Total_Errors_Detected /= 0 then
794 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
796 elsif Nkind (N) in N_Has_Chars
797 and then Chars (N) in Error_Name_Or_No_Name
805 -- If the context expects a value, and the name is a procedure,
806 -- this is most likely a missing 'Access. Do not try to resolve
807 -- the parameterless call, error will be caught when the outer
810 if Is_Entity_Name (N)
811 and then Ekind (Entity (N)) = E_Procedure
812 and then not Is_Overloaded (N)
814 (Nkind (Parent (N)) = N_Parameter_Association
815 or else Nkind (Parent (N)) = N_Function_Call
816 or else Nkind (Parent (N)) = N_Procedure_Call_Statement)
821 -- Rewrite as call if overloadable entity that is (or could be, in
822 -- the overloaded case) a function call. If we know for sure that
823 -- the entity is an enumeration literal, we do not rewrite it.
825 if (Is_Entity_Name (N)
826 and then Is_Overloadable (Entity (N))
827 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
828 or else Is_Overloaded (N)))
830 -- Rewrite as call if it is an explicit deference of an expression of
831 -- a subprogram access type, and the suprogram type is not that of a
832 -- procedure or entry.
835 (Nkind (N) = N_Explicit_Dereference
836 and then Ekind (Etype (N)) = E_Subprogram_Type
837 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type)
839 -- Rewrite as call if it is a selected component which is a function,
840 -- this is the case of a call to a protected function (which may be
841 -- overloaded with other protected operations).
844 (Nkind (N) = N_Selected_Component
845 and then (Ekind (Entity (Selector_Name (N))) = E_Function
847 ((Ekind (Entity (Selector_Name (N))) = E_Entry
849 Ekind (Entity (Selector_Name (N))) = E_Procedure)
850 and then Is_Overloaded (Selector_Name (N)))))
852 -- If one of the above three conditions is met, rewrite as call.
853 -- Apply the rewriting only once.
856 if Nkind (Parent (N)) /= N_Function_Call
857 or else N /= Name (Parent (N))
861 -- If overloaded, overload set belongs to new copy.
863 Save_Interps (N, Nam);
865 -- Change node to parameterless function call (note that the
866 -- Parameter_Associations associations field is left set to Empty,
867 -- its normal default value since there are no parameters)
869 Change_Node (N, N_Function_Call);
871 Set_Sloc (N, Sloc (Nam));
875 elsif Nkind (N) = N_Parameter_Association then
876 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
878 end Check_Parameterless_Call;
880 ----------------------
881 -- Is_Predefined_Op --
882 ----------------------
884 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
886 return Is_Intrinsic_Subprogram (Nam)
887 and then not Is_Generic_Instance (Nam)
888 and then Chars (Nam) in Any_Operator_Name
889 and then (No (Alias (Nam))
890 or else Is_Predefined_Op (Alias (Nam)));
891 end Is_Predefined_Op;
893 -----------------------------
894 -- Make_Call_Into_Operator --
895 -----------------------------
897 procedure Make_Call_Into_Operator
902 Op_Name : constant Name_Id := Chars (Op_Id);
903 Act1 : Node_Id := First_Actual (N);
904 Act2 : Node_Id := Next_Actual (Act1);
905 Error : Boolean := False;
906 Func : constant Entity_Id := Entity (Name (N));
907 Is_Binary : constant Boolean := Present (Act2);
909 Opnd_Type : Entity_Id;
910 Orig_Type : Entity_Id := Empty;
913 type Kind_Test is access function (E : Entity_Id) return Boolean;
915 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
916 -- Determine whether E is an access type declared by an access decla-
917 -- ration, and not an (anonymous) allocator type.
919 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
920 -- If the operand is not universal, and the operator is given by a
921 -- expanded name, verify that the operand has an interpretation with
922 -- a type defined in the given scope of the operator.
924 function Type_In_P (Test : Kind_Test) return Entity_Id;
925 -- Find a type of the given class in the package Pack that contains
928 -----------------------------
929 -- Is_Definite_Access_Type --
930 -----------------------------
932 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
933 Btyp : constant Entity_Id := Base_Type (E);
935 return Ekind (Btyp) = E_Access_Type
936 or else (Ekind (Btyp) = E_Access_Subprogram_Type
937 and then Comes_From_Source (Btyp));
938 end Is_Definite_Access_Type;
940 ---------------------------
941 -- Operand_Type_In_Scope --
942 ---------------------------
944 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
945 Nod : constant Node_Id := Right_Opnd (Op_Node);
950 if not Is_Overloaded (Nod) then
951 return Scope (Base_Type (Etype (Nod))) = S;
954 Get_First_Interp (Nod, I, It);
956 while Present (It.Typ) loop
958 if Scope (Base_Type (It.Typ)) = S then
962 Get_Next_Interp (I, It);
967 end Operand_Type_In_Scope;
973 function Type_In_P (Test : Kind_Test) return Entity_Id is
976 function In_Decl return Boolean;
977 -- Verify that node is not part of the type declaration for the
978 -- candidate type, which would otherwise be invisible.
984 function In_Decl return Boolean is
985 Decl_Node : constant Node_Id := Parent (E);
991 if Etype (E) = Any_Type then
994 elsif No (Decl_Node) then
999 and then Nkind (N2) /= N_Compilation_Unit
1001 if N2 = Decl_Node then
1012 -- Start of processing for Type_In_P
1015 -- If the context type is declared in the prefix package, this
1016 -- is the desired base type.
1018 if Scope (Base_Type (Typ)) = Pack
1021 return Base_Type (Typ);
1024 E := First_Entity (Pack);
1026 while Present (E) loop
1029 and then not In_Decl
1041 -- Start of processing for Make_Call_Into_Operator
1044 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1049 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1050 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1051 Save_Interps (Act1, Left_Opnd (Op_Node));
1052 Save_Interps (Act2, Right_Opnd (Op_Node));
1053 Act1 := Left_Opnd (Op_Node);
1054 Act2 := Right_Opnd (Op_Node);
1059 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1060 Save_Interps (Act1, Right_Opnd (Op_Node));
1061 Act1 := Right_Opnd (Op_Node);
1064 -- If the operator is denoted by an expanded name, and the prefix is
1065 -- not Standard, but the operator is a predefined one whose scope is
1066 -- Standard, then this is an implicit_operator, inserted as an
1067 -- interpretation by the procedure of the same name. This procedure
1068 -- overestimates the presence of implicit operators, because it does
1069 -- not examine the type of the operands. Verify now that the operand
1070 -- type appears in the given scope. If right operand is universal,
1071 -- check the other operand. In the case of concatenation, either
1072 -- argument can be the component type, so check the type of the result.
1073 -- If both arguments are literals, look for a type of the right kind
1074 -- defined in the given scope. This elaborate nonsense is brought to
1075 -- you courtesy of b33302a. The type itself must be frozen, so we must
1076 -- find the type of the proper class in the given scope.
1078 -- A final wrinkle is the multiplication operator for fixed point
1079 -- types, which is defined in Standard only, and not in the scope of
1080 -- the fixed_point type itself.
1082 if Nkind (Name (N)) = N_Expanded_Name then
1083 Pack := Entity (Prefix (Name (N)));
1085 -- If the entity being called is defined in the given package,
1086 -- it is a renaming of a predefined operator, and known to be
1089 if Scope (Entity (Name (N))) = Pack
1090 and then Pack /= Standard_Standard
1094 elsif (Op_Name = Name_Op_Multiply
1095 or else Op_Name = Name_Op_Divide)
1096 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1097 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1099 if Pack /= Standard_Standard then
1104 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1106 if Op_Name = Name_Op_Concat then
1107 Opnd_Type := Base_Type (Typ);
1109 elsif (Scope (Opnd_Type) = Standard_Standard
1111 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1113 and then not Comes_From_Source (Opnd_Type))
1115 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1118 if Scope (Opnd_Type) = Standard_Standard then
1120 -- Verify that the scope contains a type that corresponds to
1121 -- the given literal. Optimize the case where Pack is Standard.
1123 if Pack /= Standard_Standard then
1125 if Opnd_Type = Universal_Integer then
1126 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1128 elsif Opnd_Type = Universal_Real then
1129 Orig_Type := Type_In_P (Is_Real_Type'Access);
1131 elsif Opnd_Type = Any_String then
1132 Orig_Type := Type_In_P (Is_String_Type'Access);
1134 elsif Opnd_Type = Any_Access then
1135 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1137 elsif Opnd_Type = Any_Composite then
1138 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1140 if Present (Orig_Type) then
1141 if Has_Private_Component (Orig_Type) then
1144 Set_Etype (Act1, Orig_Type);
1147 Set_Etype (Act2, Orig_Type);
1156 Error := No (Orig_Type);
1159 elsif Ekind (Opnd_Type) = E_Allocator_Type
1160 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1164 -- If the type is defined elsewhere, and the operator is not
1165 -- defined in the given scope (by a renaming declaration, e.g.)
1166 -- then this is an error as well. If an extension of System is
1167 -- present, and the type may be defined there, Pack must be
1170 elsif Scope (Opnd_Type) /= Pack
1171 and then Scope (Op_Id) /= Pack
1172 and then (No (System_Aux_Id)
1173 or else Scope (Opnd_Type) /= System_Aux_Id
1174 or else Pack /= Scope (System_Aux_Id))
1178 elsif Pack = Standard_Standard
1179 and then not Operand_Type_In_Scope (Standard_Standard)
1186 Error_Msg_Node_2 := Pack;
1188 ("& not declared in&", N, Selector_Name (Name (N)));
1189 Set_Etype (N, Any_Type);
1194 Set_Chars (Op_Node, Op_Name);
1196 if not Is_Private_Type (Etype (N)) then
1197 Set_Etype (Op_Node, Base_Type (Etype (N)));
1199 Set_Etype (Op_Node, Etype (N));
1202 -- If this is a call to a function that renames a predefined equality,
1203 -- the renaming declaration provides a type that must be used to
1204 -- resolve the operands. This must be done now because resolution of
1205 -- the equality node will not resolve any remaining ambiguity, and it
1206 -- assumes that the first operand is not overloaded.
1208 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1209 and then Ekind (Func) = E_Function
1210 and then Is_Overloaded (Act1)
1212 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1213 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1216 Set_Entity (Op_Node, Op_Id);
1217 Generate_Reference (Op_Id, N, ' ');
1218 Rewrite (N, Op_Node);
1220 -- If this is an arithmetic operator and the result type is private,
1221 -- the operands and the result must be wrapped in conversion to
1222 -- expose the underlying numeric type and expand the proper checks,
1223 -- e.g. on division.
1225 if Is_Private_Type (Typ) then
1227 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1228 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1229 Resolve_Intrinsic_Operator (N, Typ);
1231 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1232 Resolve_Intrinsic_Unary_Operator (N, Typ);
1241 -- For predefined operators on literals, the operation freezes
1244 if Present (Orig_Type) then
1245 Set_Etype (Act1, Orig_Type);
1246 Freeze_Expression (Act1);
1248 end Make_Call_Into_Operator;
1254 function Operator_Kind
1256 Is_Binary : Boolean) return Node_Kind
1262 if Op_Name = Name_Op_And then Kind := N_Op_And;
1263 elsif Op_Name = Name_Op_Or then Kind := N_Op_Or;
1264 elsif Op_Name = Name_Op_Xor then Kind := N_Op_Xor;
1265 elsif Op_Name = Name_Op_Eq then Kind := N_Op_Eq;
1266 elsif Op_Name = Name_Op_Ne then Kind := N_Op_Ne;
1267 elsif Op_Name = Name_Op_Lt then Kind := N_Op_Lt;
1268 elsif Op_Name = Name_Op_Le then Kind := N_Op_Le;
1269 elsif Op_Name = Name_Op_Gt then Kind := N_Op_Gt;
1270 elsif Op_Name = Name_Op_Ge then Kind := N_Op_Ge;
1271 elsif Op_Name = Name_Op_Add then Kind := N_Op_Add;
1272 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Subtract;
1273 elsif Op_Name = Name_Op_Concat then Kind := N_Op_Concat;
1274 elsif Op_Name = Name_Op_Multiply then Kind := N_Op_Multiply;
1275 elsif Op_Name = Name_Op_Divide then Kind := N_Op_Divide;
1276 elsif Op_Name = Name_Op_Mod then Kind := N_Op_Mod;
1277 elsif Op_Name = Name_Op_Rem then Kind := N_Op_Rem;
1278 elsif Op_Name = Name_Op_Expon then Kind := N_Op_Expon;
1280 raise Program_Error;
1286 if Op_Name = Name_Op_Add then Kind := N_Op_Plus;
1287 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Minus;
1288 elsif Op_Name = Name_Op_Abs then Kind := N_Op_Abs;
1289 elsif Op_Name = Name_Op_Not then Kind := N_Op_Not;
1291 raise Program_Error;
1298 -----------------------------
1299 -- Pre_Analyze_And_Resolve --
1300 -----------------------------
1302 procedure Pre_Analyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1303 Save_Full_Analysis : constant Boolean := Full_Analysis;
1306 Full_Analysis := False;
1307 Expander_Mode_Save_And_Set (False);
1309 -- We suppress all checks for this analysis, since the checks will
1310 -- be applied properly, and in the right location, when the default
1311 -- expression is reanalyzed and reexpanded later on.
1313 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1315 Expander_Mode_Restore;
1316 Full_Analysis := Save_Full_Analysis;
1317 end Pre_Analyze_And_Resolve;
1319 -- Version without context type.
1321 procedure Pre_Analyze_And_Resolve (N : Node_Id) is
1322 Save_Full_Analysis : constant Boolean := Full_Analysis;
1325 Full_Analysis := False;
1326 Expander_Mode_Save_And_Set (False);
1329 Resolve (N, Etype (N), Suppress => All_Checks);
1331 Expander_Mode_Restore;
1332 Full_Analysis := Save_Full_Analysis;
1333 end Pre_Analyze_And_Resolve;
1335 ----------------------------------
1336 -- Replace_Actual_Discriminants --
1337 ----------------------------------
1339 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1340 Loc : constant Source_Ptr := Sloc (N);
1341 Tsk : Node_Id := Empty;
1343 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1349 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1353 if Nkind (Nod) = N_Identifier then
1354 Ent := Entity (Nod);
1357 and then Ekind (Ent) = E_Discriminant
1360 Make_Selected_Component (Loc,
1361 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1362 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1364 Set_Etype (Nod, Etype (Ent));
1372 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1374 -- Start of processing for Replace_Actual_Discriminants
1377 if not Expander_Active then
1381 if Nkind (Name (N)) = N_Selected_Component then
1382 Tsk := Prefix (Name (N));
1384 elsif Nkind (Name (N)) = N_Indexed_Component then
1385 Tsk := Prefix (Prefix (Name (N)));
1391 Replace_Discrs (Default);
1393 end Replace_Actual_Discriminants;
1399 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1401 I1 : Interp_Index := 0; -- prevent junk warning
1404 Found : Boolean := False;
1405 Seen : Entity_Id := Empty; -- prevent junk warning
1406 Ctx_Type : Entity_Id := Typ;
1407 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1408 Err_Type : Entity_Id := Empty;
1409 Ambiguous : Boolean := False;
1411 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1412 -- Try and fix up a literal so that it matches its expected type. New
1413 -- literals are manufactured if necessary to avoid cascaded errors.
1415 procedure Resolution_Failed;
1416 -- Called when attempt at resolving current expression fails
1418 --------------------
1419 -- Patch_Up_Value --
1420 --------------------
1422 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1424 if Nkind (N) = N_Integer_Literal
1425 and then Is_Real_Type (Typ)
1428 Make_Real_Literal (Sloc (N),
1429 Realval => UR_From_Uint (Intval (N))));
1430 Set_Etype (N, Universal_Real);
1431 Set_Is_Static_Expression (N);
1433 elsif Nkind (N) = N_Real_Literal
1434 and then Is_Integer_Type (Typ)
1437 Make_Integer_Literal (Sloc (N),
1438 Intval => UR_To_Uint (Realval (N))));
1439 Set_Etype (N, Universal_Integer);
1440 Set_Is_Static_Expression (N);
1441 elsif Nkind (N) = N_String_Literal
1442 and then Is_Character_Type (Typ)
1444 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1446 Make_Character_Literal (Sloc (N),
1448 Char_Literal_Value => Char_Code (Character'Pos ('A'))));
1449 Set_Etype (N, Any_Character);
1450 Set_Is_Static_Expression (N);
1452 elsif Nkind (N) /= N_String_Literal
1453 and then Is_String_Type (Typ)
1456 Make_String_Literal (Sloc (N),
1457 Strval => End_String));
1459 elsif Nkind (N) = N_Range then
1460 Patch_Up_Value (Low_Bound (N), Typ);
1461 Patch_Up_Value (High_Bound (N), Typ);
1465 -----------------------
1466 -- Resolution_Failed --
1467 -----------------------
1469 procedure Resolution_Failed is
1471 Patch_Up_Value (N, Typ);
1473 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1474 Set_Is_Overloaded (N, False);
1476 -- The caller will return without calling the expander, so we need
1477 -- to set the analyzed flag. Note that it is fine to set Analyzed
1478 -- to True even if we are in the middle of a shallow analysis,
1479 -- (see the spec of sem for more details) since this is an error
1480 -- situation anyway, and there is no point in repeating the
1481 -- analysis later (indeed it won't work to repeat it later, since
1482 -- we haven't got a clear resolution of which entity is being
1485 Set_Analyzed (N, True);
1487 end Resolution_Failed;
1489 -- Start of processing for Resolve
1496 -- Access attribute on remote subprogram cannot be used for
1497 -- a non-remote access-to-subprogram type.
1499 if Nkind (N) = N_Attribute_Reference
1500 and then (Attribute_Name (N) = Name_Access
1501 or else Attribute_Name (N) = Name_Unrestricted_Access
1502 or else Attribute_Name (N) = Name_Unchecked_Access)
1503 and then Comes_From_Source (N)
1504 and then Is_Entity_Name (Prefix (N))
1505 and then Is_Subprogram (Entity (Prefix (N)))
1506 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1507 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1510 ("prefix must statically denote a non-remote subprogram", N);
1513 -- If the context is a Remote_Access_To_Subprogram, access attributes
1514 -- must be resolved with the corresponding fat pointer. There is no need
1515 -- to check for the attribute name since the return type of an
1516 -- attribute is never a remote type.
1518 if Nkind (N) = N_Attribute_Reference
1519 and then Comes_From_Source (N)
1520 and then (Is_Remote_Call_Interface (Typ)
1521 or else Is_Remote_Types (Typ))
1524 Attr : constant Attribute_Id :=
1525 Get_Attribute_Id (Attribute_Name (N));
1526 Pref : constant Node_Id := Prefix (N);
1529 Is_Remote : Boolean := True;
1532 -- Check that Typ is a fat pointer with a reference to a RAS as
1533 -- original access type.
1536 (Ekind (Typ) = E_Access_Subprogram_Type
1537 and then Present (Equivalent_Type (Typ)))
1539 (Ekind (Typ) = E_Record_Type
1540 and then Present (Corresponding_Remote_Type (Typ)))
1543 -- Prefix (N) must statically denote a remote subprogram
1544 -- declared in a package specification.
1546 if Attr = Attribute_Access then
1547 Decl := Unit_Declaration_Node (Entity (Pref));
1549 if Nkind (Decl) = N_Subprogram_Body then
1550 Spec := Corresponding_Spec (Decl);
1552 if not No (Spec) then
1553 Decl := Unit_Declaration_Node (Spec);
1557 Spec := Parent (Decl);
1559 if not Is_Entity_Name (Prefix (N))
1560 or else Nkind (Spec) /= N_Package_Specification
1562 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1566 ("prefix must statically denote a remote subprogram ",
1571 -- If we are generating code for a distributed program.
1572 -- perform semantic checks against the corresponding
1575 if (Attr = Attribute_Access
1576 or else Attr = Attribute_Unchecked_Access
1577 or else Attr = Attribute_Unrestricted_Access)
1578 and then Expander_Active
1580 Check_Subtype_Conformant
1581 (New_Id => Entity (Prefix (N)),
1582 Old_Id => Designated_Type
1583 (Corresponding_Remote_Type (Typ)),
1586 Process_Remote_AST_Attribute (N, Typ);
1593 Debug_A_Entry ("resolving ", N);
1595 if Comes_From_Source (N) then
1596 if Is_Fixed_Point_Type (Typ) then
1597 Check_Restriction (No_Fixed_Point, N);
1599 elsif Is_Floating_Point_Type (Typ)
1600 and then Typ /= Universal_Real
1601 and then Typ /= Any_Real
1603 Check_Restriction (No_Floating_Point, N);
1607 -- Return if already analyzed
1609 if Analyzed (N) then
1610 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1613 -- Return if type = Any_Type (previous error encountered)
1615 elsif Etype (N) = Any_Type then
1616 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1620 Check_Parameterless_Call (N);
1622 -- If not overloaded, then we know the type, and all that needs doing
1623 -- is to check that this type is compatible with the context.
1625 if not Is_Overloaded (N) then
1626 Found := Covers (Typ, Etype (N));
1627 Expr_Type := Etype (N);
1629 -- In the overloaded case, we must select the interpretation that
1630 -- is compatible with the context (i.e. the type passed to Resolve)
1633 Get_First_Interp (N, I, It);
1635 -- Loop through possible interpretations
1637 Interp_Loop : while Present (It.Typ) loop
1639 -- We are only interested in interpretations that are compatible
1640 -- with the expected type, any other interpretations are ignored
1642 if not Covers (Typ, It.Typ) then
1643 if Debug_Flag_V then
1644 Write_Str (" interpretation incompatible with context");
1649 -- First matching interpretation
1655 Expr_Type := It.Typ;
1657 -- Matching interpretation that is not the first, maybe an
1658 -- error, but there are some cases where preference rules are
1659 -- used to choose between the two possibilities. These and
1660 -- some more obscure cases are handled in Disambiguate.
1663 Error_Msg_Sloc := Sloc (Seen);
1664 It1 := Disambiguate (N, I1, I, Typ);
1666 -- Disambiguation has succeeded. Skip the remaining
1669 if It1 /= No_Interp then
1671 Expr_Type := It1.Typ;
1673 while Present (It.Typ) loop
1674 Get_Next_Interp (I, It);
1678 -- Before we issue an ambiguity complaint, check for
1679 -- the case of a subprogram call where at least one
1680 -- of the arguments is Any_Type, and if so, suppress
1681 -- the message, since it is a cascaded error.
1683 if Nkind (N) = N_Function_Call
1684 or else Nkind (N) = N_Procedure_Call_Statement
1687 A : Node_Id := First_Actual (N);
1691 while Present (A) loop
1694 if Nkind (E) = N_Parameter_Association then
1695 E := Explicit_Actual_Parameter (E);
1698 if Etype (E) = Any_Type then
1699 if Debug_Flag_V then
1700 Write_Str ("Any_Type in call");
1711 elsif Nkind (N) in N_Binary_Op
1712 and then (Etype (Left_Opnd (N)) = Any_Type
1713 or else Etype (Right_Opnd (N)) = Any_Type)
1717 elsif Nkind (N) in N_Unary_Op
1718 and then Etype (Right_Opnd (N)) = Any_Type
1723 -- Not that special case, so issue message using the
1724 -- flag Ambiguous to control printing of the header
1725 -- message only at the start of an ambiguous set.
1727 if not Ambiguous then
1729 ("ambiguous expression (cannot resolve&)!",
1733 ("possible interpretation#!", N);
1737 Error_Msg_Sloc := Sloc (It.Nam);
1739 -- By default, the error message refers to the candidate
1740 -- interpretation. But if it is a predefined operator,
1741 -- it is implicitly declared at the declaration of
1742 -- the type of the operand. Recover the sloc of that
1743 -- declaration for the error message.
1745 if Nkind (N) in N_Op
1746 and then Scope (It.Nam) = Standard_Standard
1747 and then not Is_Overloaded (Right_Opnd (N))
1748 and then Scope (Base_Type (Etype (Right_Opnd (N))))
1749 /= Standard_Standard
1751 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
1753 if Comes_From_Source (Err_Type)
1754 and then Present (Parent (Err_Type))
1756 Error_Msg_Sloc := Sloc (Parent (Err_Type));
1759 elsif Nkind (N) in N_Binary_Op
1760 and then Scope (It.Nam) = Standard_Standard
1761 and then not Is_Overloaded (Left_Opnd (N))
1762 and then Scope (Base_Type (Etype (Left_Opnd (N))))
1763 /= Standard_Standard
1765 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
1767 if Comes_From_Source (Err_Type)
1768 and then Present (Parent (Err_Type))
1770 Error_Msg_Sloc := Sloc (Parent (Err_Type));
1776 if Nkind (N) in N_Op
1777 and then Scope (It.Nam) = Standard_Standard
1778 and then Present (Err_Type)
1781 ("possible interpretation (predefined)#!", N);
1783 Error_Msg_N ("possible interpretation#!", N);
1789 -- We have a matching interpretation, Expr_Type is the
1790 -- type from this interpretation, and Seen is the entity.
1792 -- For an operator, just set the entity name. The type will
1793 -- be set by the specific operator resolution routine.
1795 if Nkind (N) in N_Op then
1796 Set_Entity (N, Seen);
1797 Generate_Reference (Seen, N);
1799 elsif Nkind (N) = N_Character_Literal then
1800 Set_Etype (N, Expr_Type);
1802 -- For an explicit dereference, attribute reference, range,
1803 -- short-circuit form (which is not an operator node),
1804 -- or a call with a name that is an explicit dereference,
1805 -- there is nothing to be done at this point.
1807 elsif Nkind (N) = N_Explicit_Dereference
1808 or else Nkind (N) = N_Attribute_Reference
1809 or else Nkind (N) = N_And_Then
1810 or else Nkind (N) = N_Indexed_Component
1811 or else Nkind (N) = N_Or_Else
1812 or else Nkind (N) = N_Range
1813 or else Nkind (N) = N_Selected_Component
1814 or else Nkind (N) = N_Slice
1815 or else Nkind (Name (N)) = N_Explicit_Dereference
1819 -- For procedure or function calls, set the type of the
1820 -- name, and also the entity pointer for the prefix
1822 elsif (Nkind (N) = N_Procedure_Call_Statement
1823 or else Nkind (N) = N_Function_Call)
1824 and then (Is_Entity_Name (Name (N))
1825 or else Nkind (Name (N)) = N_Operator_Symbol)
1827 Set_Etype (Name (N), Expr_Type);
1828 Set_Entity (Name (N), Seen);
1829 Generate_Reference (Seen, Name (N));
1831 elsif Nkind (N) = N_Function_Call
1832 and then Nkind (Name (N)) = N_Selected_Component
1834 Set_Etype (Name (N), Expr_Type);
1835 Set_Entity (Selector_Name (Name (N)), Seen);
1836 Generate_Reference (Seen, Selector_Name (Name (N)));
1838 -- For all other cases, just set the type of the Name
1841 Set_Etype (Name (N), Expr_Type);
1846 -- Move to next interpretation
1848 exit Interp_Loop when not Present (It.Typ);
1850 Get_Next_Interp (I, It);
1851 end loop Interp_Loop;
1854 -- At this stage Found indicates whether or not an acceptable
1855 -- interpretation exists. If not, then we have an error, except
1856 -- that if the context is Any_Type as a result of some other error,
1857 -- then we suppress the error report.
1860 if Typ /= Any_Type then
1862 -- If type we are looking for is Void, then this is the
1863 -- procedure call case, and the error is simply that what
1864 -- we gave is not a procedure name (we think of procedure
1865 -- calls as expressions with types internally, but the user
1866 -- doesn't think of them this way!)
1868 if Typ = Standard_Void_Type then
1870 -- Special case message if function used as a procedure
1872 if Nkind (N) = N_Procedure_Call_Statement
1873 and then Is_Entity_Name (Name (N))
1874 and then Ekind (Entity (Name (N))) = E_Function
1877 ("cannot use function & in a procedure call",
1878 Name (N), Entity (Name (N)));
1880 -- Otherwise give general message (not clear what cases
1881 -- this covers, but no harm in providing for them!)
1884 Error_Msg_N ("expect procedure name in procedure call", N);
1889 -- Otherwise we do have a subexpression with the wrong type
1891 -- Check for the case of an allocator which uses an access
1892 -- type instead of the designated type. This is a common
1893 -- error and we specialize the message, posting an error
1894 -- on the operand of the allocator, complaining that we
1895 -- expected the designated type of the allocator.
1897 elsif Nkind (N) = N_Allocator
1898 and then Ekind (Typ) in Access_Kind
1899 and then Ekind (Etype (N)) in Access_Kind
1900 and then Designated_Type (Etype (N)) = Typ
1902 Wrong_Type (Expression (N), Designated_Type (Typ));
1905 -- Check for view mismatch on Null in instances, for
1906 -- which the view-swapping mechanism has no identifier.
1908 elsif (In_Instance or else In_Inlined_Body)
1909 and then (Nkind (N) = N_Null)
1910 and then Is_Private_Type (Typ)
1911 and then Is_Access_Type (Full_View (Typ))
1913 Resolve (N, Full_View (Typ));
1917 -- Check for an aggregate. Sometimes we can get bogus
1918 -- aggregates from misuse of parentheses, and we are
1919 -- about to complain about the aggregate without even
1920 -- looking inside it.
1922 -- Instead, if we have an aggregate of type Any_Composite,
1923 -- then analyze and resolve the component fields, and then
1924 -- only issue another message if we get no errors doing
1925 -- this (otherwise assume that the errors in the aggregate
1926 -- caused the problem).
1928 elsif Nkind (N) = N_Aggregate
1929 and then Etype (N) = Any_Composite
1931 -- Disable expansion in any case. If there is a type mismatch
1932 -- it may be fatal to try to expand the aggregate. The flag
1933 -- would otherwise be set to false when the error is posted.
1935 Expander_Active := False;
1938 procedure Check_Aggr (Aggr : Node_Id);
1939 -- Check one aggregate, and set Found to True if we
1940 -- have a definite error in any of its elements
1942 procedure Check_Elmt (Aelmt : Node_Id);
1943 -- Check one element of aggregate and set Found to
1944 -- True if we definitely have an error in the element.
1946 procedure Check_Aggr (Aggr : Node_Id) is
1950 if Present (Expressions (Aggr)) then
1951 Elmt := First (Expressions (Aggr));
1952 while Present (Elmt) loop
1958 if Present (Component_Associations (Aggr)) then
1959 Elmt := First (Component_Associations (Aggr));
1960 while Present (Elmt) loop
1961 Check_Elmt (Expression (Elmt));
1971 procedure Check_Elmt (Aelmt : Node_Id) is
1973 -- If we have a nested aggregate, go inside it (to
1974 -- attempt a naked analyze-resolve of the aggregate
1975 -- can cause undesirable cascaded errors). Do not
1976 -- resolve expression if it needs a type from context,
1977 -- as for integer * fixed expression.
1979 if Nkind (Aelmt) = N_Aggregate then
1985 if not Is_Overloaded (Aelmt)
1986 and then Etype (Aelmt) /= Any_Fixed
1991 if Etype (Aelmt) = Any_Type then
2002 -- If an error message was issued already, Found got reset
2003 -- to True, so if it is still False, issue the standard
2004 -- Wrong_Type message.
2007 if Is_Overloaded (N)
2008 and then Nkind (N) = N_Function_Call
2011 Subp_Name : Node_Id;
2013 if Is_Entity_Name (Name (N)) then
2014 Subp_Name := Name (N);
2016 elsif Nkind (Name (N)) = N_Selected_Component then
2018 -- Protected operation: retrieve operation name.
2020 Subp_Name := Selector_Name (Name (N));
2022 raise Program_Error;
2025 Error_Msg_Node_2 := Typ;
2026 Error_Msg_NE ("no visible interpretation of&" &
2027 " matches expected type&", N, Subp_Name);
2030 if All_Errors_Mode then
2032 Index : Interp_Index;
2036 Error_Msg_N ("\possible interpretations:", N);
2037 Get_First_Interp (Name (N), Index, It);
2039 while Present (It.Nam) loop
2041 Error_Msg_Sloc := Sloc (It.Nam);
2042 Error_Msg_Node_2 := It.Typ;
2043 Error_Msg_NE ("\& declared#, type&",
2046 Get_Next_Interp (Index, It);
2050 Error_Msg_N ("\use -gnatf for details", N);
2053 Wrong_Type (N, Typ);
2061 -- Test if we have more than one interpretation for the context
2063 elsif Ambiguous then
2067 -- Here we have an acceptable interpretation for the context
2070 -- Propagate type information and normalize tree for various
2071 -- predefined operations. If the context only imposes a class of
2072 -- types, rather than a specific type, propagate the actual type
2075 if Typ = Any_Integer
2076 or else Typ = Any_Boolean
2077 or else Typ = Any_Modular
2078 or else Typ = Any_Real
2079 or else Typ = Any_Discrete
2081 Ctx_Type := Expr_Type;
2083 -- Any_Fixed is legal in a real context only if a specific
2084 -- fixed point type is imposed. If Norman Cohen can be
2085 -- confused by this, it deserves a separate message.
2088 and then Expr_Type = Any_Fixed
2090 Error_Msg_N ("Illegal context for mixed mode operation", N);
2091 Set_Etype (N, Universal_Real);
2092 Ctx_Type := Universal_Real;
2096 -- A user-defined operator is tranformed into a function call at
2097 -- this point, so that further processing knows that operators are
2098 -- really operators (i.e. are predefined operators). User-defined
2099 -- operators that are intrinsic are just renamings of the predefined
2100 -- ones, and need not be turned into calls either, but if they rename
2101 -- a different operator, we must transform the node accordingly.
2102 -- Instantiations of Unchecked_Conversion are intrinsic but are
2103 -- treated as functions, even if given an operator designator.
2105 if Nkind (N) in N_Op
2106 and then Present (Entity (N))
2107 and then Ekind (Entity (N)) /= E_Operator
2110 if not Is_Predefined_Op (Entity (N)) then
2111 Rewrite_Operator_As_Call (N, Entity (N));
2113 elsif Present (Alias (Entity (N)))
2115 Nkind (Parent (Parent (Entity (N))))
2116 = N_Subprogram_Renaming_Declaration
2118 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2120 -- If the node is rewritten, it will be fully resolved in
2121 -- Rewrite_Renamed_Operator.
2123 if Analyzed (N) then
2129 case N_Subexpr'(Nkind (N)) is
2131 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2133 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2135 when N_And_Then | N_Or_Else
2136 => Resolve_Short_Circuit (N, Ctx_Type);
2138 when N_Attribute_Reference
2139 => Resolve_Attribute (N, Ctx_Type);
2141 when N_Character_Literal
2142 => Resolve_Character_Literal (N, Ctx_Type);
2144 when N_Conditional_Expression
2145 => Resolve_Conditional_Expression (N, Ctx_Type);
2147 when N_Expanded_Name
2148 => Resolve_Entity_Name (N, Ctx_Type);
2150 when N_Extension_Aggregate
2151 => Resolve_Extension_Aggregate (N, Ctx_Type);
2153 when N_Explicit_Dereference
2154 => Resolve_Explicit_Dereference (N, Ctx_Type);
2156 when N_Function_Call
2157 => Resolve_Call (N, Ctx_Type);
2160 => Resolve_Entity_Name (N, Ctx_Type);
2162 when N_In | N_Not_In
2163 => Resolve_Membership_Op (N, Ctx_Type);
2165 when N_Indexed_Component
2166 => Resolve_Indexed_Component (N, Ctx_Type);
2168 when N_Integer_Literal
2169 => Resolve_Integer_Literal (N, Ctx_Type);
2171 when N_Null => Resolve_Null (N, Ctx_Type);
2173 when N_Op_And | N_Op_Or | N_Op_Xor
2174 => Resolve_Logical_Op (N, Ctx_Type);
2176 when N_Op_Eq | N_Op_Ne
2177 => Resolve_Equality_Op (N, Ctx_Type);
2179 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2180 => Resolve_Comparison_Op (N, Ctx_Type);
2182 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2184 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2185 N_Op_Divide | N_Op_Mod | N_Op_Rem
2187 => Resolve_Arithmetic_Op (N, Ctx_Type);
2189 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2191 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2193 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2194 => Resolve_Unary_Op (N, Ctx_Type);
2196 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2198 when N_Procedure_Call_Statement
2199 => Resolve_Call (N, Ctx_Type);
2201 when N_Operator_Symbol
2202 => Resolve_Operator_Symbol (N, Ctx_Type);
2204 when N_Qualified_Expression
2205 => Resolve_Qualified_Expression (N, Ctx_Type);
2207 when N_Raise_xxx_Error
2208 => Set_Etype (N, Ctx_Type);
2210 when N_Range => Resolve_Range (N, Ctx_Type);
2213 => Resolve_Real_Literal (N, Ctx_Type);
2215 when N_Reference => Resolve_Reference (N, Ctx_Type);
2217 when N_Selected_Component
2218 => Resolve_Selected_Component (N, Ctx_Type);
2220 when N_Slice => Resolve_Slice (N, Ctx_Type);
2222 when N_String_Literal
2223 => Resolve_String_Literal (N, Ctx_Type);
2225 when N_Subprogram_Info
2226 => Resolve_Subprogram_Info (N, Ctx_Type);
2228 when N_Type_Conversion
2229 => Resolve_Type_Conversion (N, Ctx_Type);
2231 when N_Unchecked_Expression =>
2232 Resolve_Unchecked_Expression (N, Ctx_Type);
2234 when N_Unchecked_Type_Conversion =>
2235 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2239 -- If the subexpression was replaced by a non-subexpression, then
2240 -- all we do is to expand it. The only legitimate case we know of
2241 -- is converting procedure call statement to entry call statements,
2242 -- but there may be others, so we are making this test general.
2244 if Nkind (N) not in N_Subexpr then
2245 Debug_A_Exit ("resolving ", N, " (done)");
2250 -- The expression is definitely NOT overloaded at this point, so
2251 -- we reset the Is_Overloaded flag to avoid any confusion when
2252 -- reanalyzing the node.
2254 Set_Is_Overloaded (N, False);
2256 -- Freeze expression type, entity if it is a name, and designated
2257 -- type if it is an allocator (RM 13.14(10,11,13)).
2259 -- Now that the resolution of the type of the node is complete,
2260 -- and we did not detect an error, we can expand this node. We
2261 -- skip the expand call if we are in a default expression, see
2262 -- section "Handling of Default Expressions" in Sem spec.
2264 Debug_A_Exit ("resolving ", N, " (done)");
2266 -- We unconditionally freeze the expression, even if we are in
2267 -- default expression mode (the Freeze_Expression routine tests
2268 -- this flag and only freezes static types if it is set).
2270 Freeze_Expression (N);
2272 -- Now we can do the expansion
2282 -- Version with check(s) suppressed
2284 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2286 if Suppress = All_Checks then
2288 Svg : constant Suppress_Array := Scope_Suppress;
2291 Scope_Suppress := (others => True);
2293 Scope_Suppress := Svg;
2298 Svg : constant Boolean := Scope_Suppress (Suppress);
2301 Scope_Suppress (Suppress) := True;
2303 Scope_Suppress (Suppress) := Svg;
2312 -- Version with implicit type
2314 procedure Resolve (N : Node_Id) is
2316 Resolve (N, Etype (N));
2319 ---------------------
2320 -- Resolve_Actuals --
2321 ---------------------
2323 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2324 Loc : constant Source_Ptr := Sloc (N);
2329 Prev : Node_Id := Empty;
2331 procedure Insert_Default;
2332 -- If the actual is missing in a call, insert in the actuals list
2333 -- an instance of the default expression. The insertion is always
2334 -- a named association.
2336 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2337 -- Check whether T1 and T2, or their full views, are derived from a
2338 -- common type. Used to enforce the restrictions on array conversions
2341 --------------------
2342 -- Insert_Default --
2343 --------------------
2345 procedure Insert_Default is
2350 -- Missing argument in call, nothing to insert
2352 if No (Default_Value (F)) then
2356 -- Note that we do a full New_Copy_Tree, so that any associated
2357 -- Itypes are properly copied. This may not be needed any more,
2358 -- but it does no harm as a safety measure! Defaults of a generic
2359 -- formal may be out of bounds of the corresponding actual (see
2360 -- cc1311b) and an additional check may be required.
2362 Actval := New_Copy_Tree (Default_Value (F),
2363 New_Scope => Current_Scope, New_Sloc => Loc);
2365 if Is_Concurrent_Type (Scope (Nam))
2366 and then Has_Discriminants (Scope (Nam))
2368 Replace_Actual_Discriminants (N, Actval);
2371 if Is_Overloadable (Nam)
2372 and then Present (Alias (Nam))
2374 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2375 and then not Is_Tagged_Type (Etype (F))
2377 -- If default is a real literal, do not introduce a
2378 -- conversion whose effect may depend on the run-time
2379 -- size of universal real.
2381 if Nkind (Actval) = N_Real_Literal then
2382 Set_Etype (Actval, Base_Type (Etype (F)));
2384 Actval := Unchecked_Convert_To (Etype (F), Actval);
2388 if Is_Scalar_Type (Etype (F)) then
2389 Enable_Range_Check (Actval);
2392 Set_Parent (Actval, N);
2394 -- Resolve aggregates with their base type, to avoid scope
2395 -- anomalies: the subtype was first built in the suprogram
2396 -- declaration, and the current call may be nested.
2398 if Nkind (Actval) = N_Aggregate
2399 and then Has_Discriminants (Etype (Actval))
2401 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2403 Analyze_And_Resolve (Actval, Etype (Actval));
2407 Set_Parent (Actval, N);
2409 -- See note above concerning aggregates.
2411 if Nkind (Actval) = N_Aggregate
2412 and then Has_Discriminants (Etype (Actval))
2414 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2416 -- Resolve entities with their own type, which may differ
2417 -- from the type of a reference in a generic context (the
2418 -- view swapping mechanism did not anticipate the re-analysis
2419 -- of default values in calls).
2421 elsif Is_Entity_Name (Actval) then
2422 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
2425 Analyze_And_Resolve (Actval, Etype (Actval));
2429 -- If default is a tag indeterminate function call, propagate
2430 -- tag to obtain proper dispatching.
2432 if Is_Controlling_Formal (F)
2433 and then Nkind (Default_Value (F)) = N_Function_Call
2435 Set_Is_Controlling_Actual (Actval);
2440 -- If the default expression raises constraint error, then just
2441 -- silently replace it with an N_Raise_Constraint_Error node,
2442 -- since we already gave the warning on the subprogram spec.
2444 if Raises_Constraint_Error (Actval) then
2446 Make_Raise_Constraint_Error (Loc,
2447 Reason => CE_Range_Check_Failed));
2448 Set_Raises_Constraint_Error (Actval);
2449 Set_Etype (Actval, Etype (F));
2453 Make_Parameter_Association (Loc,
2454 Explicit_Actual_Parameter => Actval,
2455 Selector_Name => Make_Identifier (Loc, Chars (F)));
2457 -- Case of insertion is first named actual
2459 if No (Prev) or else
2460 Nkind (Parent (Prev)) /= N_Parameter_Association
2462 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
2463 Set_First_Named_Actual (N, Actval);
2466 if not Present (Parameter_Associations (N)) then
2467 Set_Parameter_Associations (N, New_List (Assoc));
2469 Append (Assoc, Parameter_Associations (N));
2473 Insert_After (Prev, Assoc);
2476 -- Case of insertion is not first named actual
2479 Set_Next_Named_Actual
2480 (Assoc, Next_Named_Actual (Parent (Prev)));
2481 Set_Next_Named_Actual (Parent (Prev), Actval);
2482 Append (Assoc, Parameter_Associations (N));
2485 Mark_Rewrite_Insertion (Assoc);
2486 Mark_Rewrite_Insertion (Actval);
2495 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
2496 FT1 : Entity_Id := T1;
2497 FT2 : Entity_Id := T2;
2500 if Is_Private_Type (T1)
2501 and then Present (Full_View (T1))
2503 FT1 := Full_View (T1);
2506 if Is_Private_Type (T2)
2507 and then Present (Full_View (T2))
2509 FT2 := Full_View (T2);
2512 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
2515 -- Start of processing for Resolve_Actuals
2518 A := First_Actual (N);
2519 F := First_Formal (Nam);
2521 while Present (F) loop
2522 if No (A) and then Needs_No_Actuals (Nam) then
2525 -- If we have an error in any actual or formal, indicated by
2526 -- a type of Any_Type, then abandon resolution attempt, and
2527 -- set result type to Any_Type.
2529 elsif (Present (A) and then Etype (A) = Any_Type)
2530 or else Etype (F) = Any_Type
2532 Set_Etype (N, Any_Type);
2537 and then (Nkind (Parent (A)) /= N_Parameter_Association
2539 Chars (Selector_Name (Parent (A))) = Chars (F))
2541 -- If the formal is Out or In_Out, do not resolve and expand the
2542 -- conversion, because it is subsequently expanded into explicit
2543 -- temporaries and assignments. However, the object of the
2544 -- conversion can be resolved. An exception is the case of
2545 -- a tagged type conversion with a class-wide actual. In that
2546 -- case we want the tag check to occur and no temporary will
2547 -- will be needed (no representation change can occur) and
2548 -- the parameter is passed by reference, so we go ahead and
2549 -- resolve the type conversion.
2551 if Ekind (F) /= E_In_Parameter
2552 and then Nkind (A) = N_Type_Conversion
2553 and then not Is_Class_Wide_Type (Etype (Expression (A)))
2555 if Ekind (F) = E_In_Out_Parameter
2556 and then Is_Array_Type (Etype (F))
2558 if Has_Aliased_Components (Etype (Expression (A)))
2559 /= Has_Aliased_Components (Etype (F))
2562 ("both component types in a view conversion must be"
2563 & " aliased, or neither", A);
2565 elsif not Same_Ancestor (Etype (F), Etype (Expression (A)))
2567 (Is_By_Reference_Type (Etype (F))
2568 or else Is_By_Reference_Type (Etype (Expression (A))))
2571 ("view conversion between unrelated by_reference "
2572 & "array types not allowed (\A\I-00246)?", A);
2576 if Conversion_OK (A)
2577 or else Valid_Conversion (A, Etype (A), Expression (A))
2579 Resolve (Expression (A));
2583 if Nkind (A) = N_Type_Conversion
2584 and then Is_Array_Type (Etype (F))
2585 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
2587 (Is_Limited_Type (Etype (F))
2588 or else Is_Limited_Type (Etype (Expression (A))))
2591 ("Conversion between unrelated limited array types "
2592 & "not allowed (\A\I-00246)?", A);
2594 -- Disable explanation (which produces additional errors)
2595 -- until AI is approved and warning becomes an error.
2597 -- if Is_Limited_Type (Etype (F)) then
2598 -- Explain_Limited_Type (Etype (F), A);
2601 -- if Is_Limited_Type (Etype (Expression (A))) then
2602 -- Explain_Limited_Type (Etype (Expression (A)), A);
2606 Resolve (A, Etype (F));
2612 -- Perform error checks for IN and IN OUT parameters
2614 if Ekind (F) /= E_Out_Parameter then
2616 -- Check unset reference. For scalar parameters, it is clearly
2617 -- wrong to pass an uninitialized value as either an IN or
2618 -- IN-OUT parameter. For composites, it is also clearly an
2619 -- error to pass a completely uninitialized value as an IN
2620 -- parameter, but the case of IN OUT is trickier. We prefer
2621 -- not to give a warning here. For example, suppose there is
2622 -- a routine that sets some component of a record to False.
2623 -- It is perfectly reasonable to make this IN-OUT and allow
2624 -- either initialized or uninitialized records to be passed
2627 -- For partially initialized composite values, we also avoid
2628 -- warnings, since it is quite likely that we are passing a
2629 -- partially initialized value and only the initialized fields
2630 -- will in fact be read in the subprogram.
2632 if Is_Scalar_Type (A_Typ)
2633 or else (Ekind (F) = E_In_Parameter
2634 and then not Is_Partially_Initialized_Type (A_Typ))
2636 Check_Unset_Reference (A);
2639 -- In Ada 83 we cannot pass an OUT parameter as an IN
2640 -- or IN OUT actual to a nested call, since this is a
2641 -- case of reading an out parameter, which is not allowed.
2643 if Ada_Version = Ada_83
2644 and then Is_Entity_Name (A)
2645 and then Ekind (Entity (A)) = E_Out_Parameter
2647 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
2651 if Ekind (F) /= E_In_Parameter
2652 and then not Is_OK_Variable_For_Out_Formal (A)
2654 Error_Msg_NE ("actual for& must be a variable", A, F);
2656 if Is_Entity_Name (A) then
2657 Kill_Checks (Entity (A));
2663 if Etype (A) = Any_Type then
2664 Set_Etype (N, Any_Type);
2668 -- Apply appropriate range checks for in, out, and in-out
2669 -- parameters. Out and in-out parameters also need a separate
2670 -- check, if there is a type conversion, to make sure the return
2671 -- value meets the constraints of the variable before the
2674 -- Gigi looks at the check flag and uses the appropriate types.
2675 -- For now since one flag is used there is an optimization which
2676 -- might not be done in the In Out case since Gigi does not do
2677 -- any analysis. More thought required about this ???
2679 if Ekind (F) = E_In_Parameter
2680 or else Ekind (F) = E_In_Out_Parameter
2682 if Is_Scalar_Type (Etype (A)) then
2683 Apply_Scalar_Range_Check (A, F_Typ);
2685 elsif Is_Array_Type (Etype (A)) then
2686 Apply_Length_Check (A, F_Typ);
2688 elsif Is_Record_Type (F_Typ)
2689 and then Has_Discriminants (F_Typ)
2690 and then Is_Constrained (F_Typ)
2691 and then (not Is_Derived_Type (F_Typ)
2692 or else Comes_From_Source (Nam))
2694 Apply_Discriminant_Check (A, F_Typ);
2696 elsif Is_Access_Type (F_Typ)
2697 and then Is_Array_Type (Designated_Type (F_Typ))
2698 and then Is_Constrained (Designated_Type (F_Typ))
2700 Apply_Length_Check (A, F_Typ);
2702 elsif Is_Access_Type (F_Typ)
2703 and then Has_Discriminants (Designated_Type (F_Typ))
2704 and then Is_Constrained (Designated_Type (F_Typ))
2706 Apply_Discriminant_Check (A, F_Typ);
2709 Apply_Range_Check (A, F_Typ);
2712 -- Ada 2005 (AI-231)
2714 if Ada_Version >= Ada_05
2715 and then Is_Access_Type (F_Typ)
2716 and then (Can_Never_Be_Null (F)
2717 or else Can_Never_Be_Null (F_Typ))
2719 if Nkind (A) = N_Null then
2721 ("(Ada 2005) not allowed for " &
2722 "null-exclusion formal", A, F_Typ);
2727 if Ekind (F) = E_Out_Parameter
2728 or else Ekind (F) = E_In_Out_Parameter
2730 if Nkind (A) = N_Type_Conversion then
2731 if Is_Scalar_Type (A_Typ) then
2732 Apply_Scalar_Range_Check
2733 (Expression (A), Etype (Expression (A)), A_Typ);
2736 (Expression (A), Etype (Expression (A)), A_Typ);
2740 if Is_Scalar_Type (F_Typ) then
2741 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
2743 elsif Is_Array_Type (F_Typ)
2744 and then Ekind (F) = E_Out_Parameter
2746 Apply_Length_Check (A, F_Typ);
2749 Apply_Range_Check (A, A_Typ, F_Typ);
2754 -- An actual associated with an access parameter is implicitly
2755 -- converted to the anonymous access type of the formal and
2756 -- must satisfy the legality checks for access conversions.
2758 if Ekind (F_Typ) = E_Anonymous_Access_Type then
2759 if not Valid_Conversion (A, F_Typ, A) then
2761 ("invalid implicit conversion for access parameter", A);
2765 -- Check bad case of atomic/volatile argument (RM C.6(12))
2767 if Is_By_Reference_Type (Etype (F))
2768 and then Comes_From_Source (N)
2770 if Is_Atomic_Object (A)
2771 and then not Is_Atomic (Etype (F))
2774 ("cannot pass atomic argument to non-atomic formal",
2777 elsif Is_Volatile_Object (A)
2778 and then not Is_Volatile (Etype (F))
2781 ("cannot pass volatile argument to non-volatile formal",
2786 -- Check that subprograms don't have improper controlling
2787 -- arguments (RM 3.9.2 (9))
2789 if Is_Controlling_Formal (F) then
2790 Set_Is_Controlling_Actual (A);
2791 elsif Nkind (A) = N_Explicit_Dereference then
2792 Validate_Remote_Access_To_Class_Wide_Type (A);
2795 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
2796 and then not Is_Class_Wide_Type (F_Typ)
2797 and then not Is_Controlling_Formal (F)
2799 Error_Msg_N ("class-wide argument not allowed here!", A);
2801 if Is_Subprogram (Nam)
2802 and then Comes_From_Source (Nam)
2804 Error_Msg_Node_2 := F_Typ;
2806 ("& is not a primitive operation of &!", A, Nam);
2809 elsif Is_Access_Type (A_Typ)
2810 and then Is_Access_Type (F_Typ)
2811 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
2812 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
2813 or else (Nkind (A) = N_Attribute_Reference
2815 Is_Class_Wide_Type (Etype (Prefix (A)))))
2816 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
2817 and then not Is_Controlling_Formal (F)
2820 ("access to class-wide argument not allowed here!", A);
2822 if Is_Subprogram (Nam)
2823 and then Comes_From_Source (Nam)
2825 Error_Msg_Node_2 := Designated_Type (F_Typ);
2827 ("& is not a primitive operation of &!", A, Nam);
2833 -- If it is a named association, treat the selector_name as
2834 -- a proper identifier, and mark the corresponding entity.
2836 if Nkind (Parent (A)) = N_Parameter_Association then
2837 Set_Entity (Selector_Name (Parent (A)), F);
2838 Generate_Reference (F, Selector_Name (Parent (A)));
2839 Set_Etype (Selector_Name (Parent (A)), F_Typ);
2840 Generate_Reference (F_Typ, N, ' ');
2845 if Ekind (F) /= E_Out_Parameter then
2846 Check_Unset_Reference (A);
2851 -- Case where actual is not present
2859 end Resolve_Actuals;
2861 -----------------------
2862 -- Resolve_Allocator --
2863 -----------------------
2865 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
2866 E : constant Node_Id := Expression (N);
2868 Discrim : Entity_Id;
2872 function In_Dispatching_Context return Boolean;
2873 -- If the allocator is an actual in a call, it is allowed to be
2874 -- class-wide when the context is not because it is a controlling
2877 ----------------------------
2878 -- In_Dispatching_Context --
2879 ----------------------------
2881 function In_Dispatching_Context return Boolean is
2882 Par : constant Node_Id := Parent (N);
2885 return (Nkind (Par) = N_Function_Call
2886 or else Nkind (Par) = N_Procedure_Call_Statement)
2887 and then Is_Entity_Name (Name (Par))
2888 and then Is_Dispatching_Operation (Entity (Name (Par)));
2889 end In_Dispatching_Context;
2891 -- Start of processing for Resolve_Allocator
2894 -- Replace general access with specific type
2896 if Ekind (Etype (N)) = E_Allocator_Type then
2897 Set_Etype (N, Base_Type (Typ));
2900 if Is_Abstract (Typ) then
2901 Error_Msg_N ("type of allocator cannot be abstract", N);
2904 -- For qualified expression, resolve the expression using the
2905 -- given subtype (nothing to do for type mark, subtype indication)
2907 if Nkind (E) = N_Qualified_Expression then
2908 if Is_Class_Wide_Type (Etype (E))
2909 and then not Is_Class_Wide_Type (Designated_Type (Typ))
2910 and then not In_Dispatching_Context
2913 ("class-wide allocator not allowed for this access type", N);
2916 Resolve (Expression (E), Etype (E));
2917 Check_Unset_Reference (Expression (E));
2919 -- A qualified expression requires an exact match of the type,
2920 -- class-wide matching is not allowed.
2922 if (Is_Class_Wide_Type (Etype (Expression (E)))
2923 or else Is_Class_Wide_Type (Etype (E)))
2924 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
2926 Wrong_Type (Expression (E), Etype (E));
2929 -- For a subtype mark or subtype indication, freeze the subtype
2932 Freeze_Expression (E);
2934 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
2936 ("initialization required for access-to-constant allocator", N);
2939 -- A special accessibility check is needed for allocators that
2940 -- constrain access discriminants. The level of the type of the
2941 -- expression used to contrain an access discriminant cannot be
2942 -- deeper than the type of the allocator (in constrast to access
2943 -- parameters, where the level of the actual can be arbitrary).
2944 -- We can't use Valid_Conversion to perform this check because
2945 -- in general the type of the allocator is unrelated to the type
2946 -- of the access discriminant. Note that specialized checks are
2947 -- needed for the cases of a constraint expression which is an
2948 -- access attribute or an access discriminant.
2950 if Nkind (Original_Node (E)) = N_Subtype_Indication
2951 and then Ekind (Typ) /= E_Anonymous_Access_Type
2953 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
2955 if Has_Discriminants (Subtyp) then
2956 Discrim := First_Discriminant (Base_Type (Subtyp));
2957 Constr := First (Constraints (Constraint (Original_Node (E))));
2959 while Present (Discrim) and then Present (Constr) loop
2960 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
2961 if Nkind (Constr) = N_Discriminant_Association then
2962 Disc_Exp := Original_Node (Expression (Constr));
2964 Disc_Exp := Original_Node (Constr);
2967 if Type_Access_Level (Etype (Disc_Exp))
2968 > Type_Access_Level (Typ)
2971 ("operand type has deeper level than allocator type",
2974 elsif Nkind (Disc_Exp) = N_Attribute_Reference
2975 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
2977 and then Object_Access_Level (Prefix (Disc_Exp))
2978 > Type_Access_Level (Typ)
2981 ("prefix of attribute has deeper level than"
2982 & " allocator type", Disc_Exp);
2984 -- When the operand is an access discriminant the check
2985 -- is against the level of the prefix object.
2987 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
2988 and then Nkind (Disc_Exp) = N_Selected_Component
2989 and then Object_Access_Level (Prefix (Disc_Exp))
2990 > Type_Access_Level (Typ)
2993 ("access discriminant has deeper level than"
2994 & " allocator type", Disc_Exp);
2997 Next_Discriminant (Discrim);
3004 -- Check for allocation from an empty storage pool
3006 if No_Pool_Assigned (Typ) then
3008 Loc : constant Source_Ptr := Sloc (N);
3011 Error_Msg_N ("?allocation from empty storage pool!", N);
3012 Error_Msg_N ("?Storage_Error will be raised at run time!", N);
3014 Make_Raise_Storage_Error (Loc,
3015 Reason => SE_Empty_Storage_Pool));
3018 end Resolve_Allocator;
3020 ---------------------------
3021 -- Resolve_Arithmetic_Op --
3022 ---------------------------
3024 -- Used for resolving all arithmetic operators except exponentiation
3026 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
3027 L : constant Node_Id := Left_Opnd (N);
3028 R : constant Node_Id := Right_Opnd (N);
3029 TL : constant Entity_Id := Base_Type (Etype (L));
3030 TR : constant Entity_Id := Base_Type (Etype (R));
3034 B_Typ : constant Entity_Id := Base_Type (Typ);
3035 -- We do the resolution using the base type, because intermediate values
3036 -- in expressions always are of the base type, not a subtype of it.
3038 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
3039 -- Return True iff given type is Integer or universal real/integer
3041 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
3042 -- Choose type of integer literal in fixed-point operation to conform
3043 -- to available fixed-point type. T is the type of the other operand,
3044 -- which is needed to determine the expected type of N.
3046 procedure Set_Operand_Type (N : Node_Id);
3047 -- Set operand type to T if universal
3049 -----------------------------
3050 -- Is_Integer_Or_Universal --
3051 -----------------------------
3053 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
3055 Index : Interp_Index;
3059 if not Is_Overloaded (N) then
3061 return Base_Type (T) = Base_Type (Standard_Integer)
3062 or else T = Universal_Integer
3063 or else T = Universal_Real;
3065 Get_First_Interp (N, Index, It);
3067 while Present (It.Typ) loop
3069 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
3070 or else It.Typ = Universal_Integer
3071 or else It.Typ = Universal_Real
3076 Get_Next_Interp (Index, It);
3081 end Is_Integer_Or_Universal;
3083 ----------------------------
3084 -- Set_Mixed_Mode_Operand --
3085 ----------------------------
3087 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
3088 Index : Interp_Index;
3092 if Universal_Interpretation (N) = Universal_Integer then
3094 -- A universal integer literal is resolved as standard integer
3095 -- except in the case of a fixed-point result, where we leave
3096 -- it as universal (to be handled by Exp_Fixd later on)
3098 if Is_Fixed_Point_Type (T) then
3099 Resolve (N, Universal_Integer);
3101 Resolve (N, Standard_Integer);
3104 elsif Universal_Interpretation (N) = Universal_Real
3105 and then (T = Base_Type (Standard_Integer)
3106 or else T = Universal_Integer
3107 or else T = Universal_Real)
3109 -- A universal real can appear in a fixed-type context. We resolve
3110 -- the literal with that context, even though this might raise an
3111 -- exception prematurely (the other operand may be zero).
3115 elsif Etype (N) = Base_Type (Standard_Integer)
3116 and then T = Universal_Real
3117 and then Is_Overloaded (N)
3119 -- Integer arg in mixed-mode operation. Resolve with universal
3120 -- type, in case preference rule must be applied.
3122 Resolve (N, Universal_Integer);
3125 and then B_Typ /= Universal_Fixed
3127 -- Not a mixed-mode operation. Resolve with context.
3131 elsif Etype (N) = Any_Fixed then
3133 -- N may itself be a mixed-mode operation, so use context type.
3137 elsif Is_Fixed_Point_Type (T)
3138 and then B_Typ = Universal_Fixed
3139 and then Is_Overloaded (N)
3141 -- Must be (fixed * fixed) operation, operand must have one
3142 -- compatible interpretation.
3144 Resolve (N, Any_Fixed);
3146 elsif Is_Fixed_Point_Type (B_Typ)
3147 and then (T = Universal_Real
3148 or else Is_Fixed_Point_Type (T))
3149 and then Is_Overloaded (N)
3151 -- C * F(X) in a fixed context, where C is a real literal or a
3152 -- fixed-point expression. F must have either a fixed type
3153 -- interpretation or an integer interpretation, but not both.
3155 Get_First_Interp (N, Index, It);
3157 while Present (It.Typ) loop
3158 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
3160 if Analyzed (N) then
3161 Error_Msg_N ("ambiguous operand in fixed operation", N);
3163 Resolve (N, Standard_Integer);
3166 elsif Is_Fixed_Point_Type (It.Typ) then
3168 if Analyzed (N) then
3169 Error_Msg_N ("ambiguous operand in fixed operation", N);
3171 Resolve (N, It.Typ);
3175 Get_Next_Interp (Index, It);
3178 -- Reanalyze the literal with the fixed type of the context.
3179 -- If context is Universal_Fixed, we are within a conversion,
3180 -- leave the literal as a universal real because there is no
3181 -- usable fixed type, and the target of the conversion plays
3182 -- no role in the resolution.
3195 if B_Typ = Universal_Fixed
3196 and then Nkind (Op2) = N_Real_Literal
3198 T2 := Universal_Real;
3203 Set_Analyzed (Op2, False);
3210 end Set_Mixed_Mode_Operand;
3212 ----------------------
3213 -- Set_Operand_Type --
3214 ----------------------
3216 procedure Set_Operand_Type (N : Node_Id) is
3218 if Etype (N) = Universal_Integer
3219 or else Etype (N) = Universal_Real
3223 end Set_Operand_Type;
3225 -- Start of processing for Resolve_Arithmetic_Op
3228 if Comes_From_Source (N)
3229 and then Ekind (Entity (N)) = E_Function
3230 and then Is_Imported (Entity (N))
3231 and then Is_Intrinsic_Subprogram (Entity (N))
3233 Resolve_Intrinsic_Operator (N, Typ);
3236 -- Special-case for mixed-mode universal expressions or fixed point
3237 -- type operation: each argument is resolved separately. The same
3238 -- treatment is required if one of the operands of a fixed point
3239 -- operation is universal real, since in this case we don't do a
3240 -- conversion to a specific fixed-point type (instead the expander
3241 -- takes care of the case).
3243 elsif (B_Typ = Universal_Integer
3244 or else B_Typ = Universal_Real)
3245 and then Present (Universal_Interpretation (L))
3246 and then Present (Universal_Interpretation (R))
3248 Resolve (L, Universal_Interpretation (L));
3249 Resolve (R, Universal_Interpretation (R));
3250 Set_Etype (N, B_Typ);
3252 elsif (B_Typ = Universal_Real
3253 or else Etype (N) = Universal_Fixed
3254 or else (Etype (N) = Any_Fixed
3255 and then Is_Fixed_Point_Type (B_Typ))
3256 or else (Is_Fixed_Point_Type (B_Typ)
3257 and then (Is_Integer_Or_Universal (L)
3259 Is_Integer_Or_Universal (R))))
3260 and then (Nkind (N) = N_Op_Multiply or else
3261 Nkind (N) = N_Op_Divide)
3263 if TL = Universal_Integer or else TR = Universal_Integer then
3264 Check_For_Visible_Operator (N, B_Typ);
3267 -- If context is a fixed type and one operand is integer, the
3268 -- other is resolved with the type of the context.
3270 if Is_Fixed_Point_Type (B_Typ)
3271 and then (Base_Type (TL) = Base_Type (Standard_Integer)
3272 or else TL = Universal_Integer)
3277 elsif Is_Fixed_Point_Type (B_Typ)
3278 and then (Base_Type (TR) = Base_Type (Standard_Integer)
3279 or else TR = Universal_Integer)
3285 Set_Mixed_Mode_Operand (L, TR);
3286 Set_Mixed_Mode_Operand (R, TL);
3289 if Etype (N) = Universal_Fixed
3290 or else Etype (N) = Any_Fixed
3292 if B_Typ = Universal_Fixed
3293 and then Nkind (Parent (N)) /= N_Type_Conversion
3294 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3297 ("type cannot be determined from context!", N);
3299 ("\explicit conversion to result type required", N);
3301 Set_Etype (L, Any_Type);
3302 Set_Etype (R, Any_Type);
3305 if Ada_Version = Ada_83
3306 and then Etype (N) = Universal_Fixed
3307 and then Nkind (Parent (N)) /= N_Type_Conversion
3308 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3311 ("(Ada 83) fixed-point operation " &
3312 "needs explicit conversion",
3316 Set_Etype (N, B_Typ);
3319 elsif Is_Fixed_Point_Type (B_Typ)
3320 and then (Is_Integer_Or_Universal (L)
3321 or else Nkind (L) = N_Real_Literal
3322 or else Nkind (R) = N_Real_Literal
3324 Is_Integer_Or_Universal (R))
3326 Set_Etype (N, B_Typ);
3328 elsif Etype (N) = Any_Fixed then
3330 -- If no previous errors, this is only possible if one operand
3331 -- is overloaded and the context is universal. Resolve as such.
3333 Set_Etype (N, B_Typ);
3337 if (TL = Universal_Integer or else TL = Universal_Real)
3338 and then (TR = Universal_Integer or else TR = Universal_Real)
3340 Check_For_Visible_Operator (N, B_Typ);
3343 -- If the context is Universal_Fixed and the operands are also
3344 -- universal fixed, this is an error, unless there is only one
3345 -- applicable fixed_point type (usually duration).
3347 if B_Typ = Universal_Fixed
3348 and then Etype (L) = Universal_Fixed
3350 T := Unique_Fixed_Point_Type (N);
3352 if T = Any_Type then
3365 -- If one of the arguments was resolved to a non-universal type.
3366 -- label the result of the operation itself with the same type.
3367 -- Do the same for the universal argument, if any.
3369 T := Intersect_Types (L, R);
3370 Set_Etype (N, Base_Type (T));
3371 Set_Operand_Type (L);
3372 Set_Operand_Type (R);
3375 Generate_Operator_Reference (N, Typ);
3376 Eval_Arithmetic_Op (N);
3378 -- Set overflow and division checking bit. Much cleverer code needed
3379 -- here eventually and perhaps the Resolve routines should be separated
3380 -- for the various arithmetic operations, since they will need
3381 -- different processing. ???
3383 if Nkind (N) in N_Op then
3384 if not Overflow_Checks_Suppressed (Etype (N)) then
3385 Enable_Overflow_Check (N);
3388 -- Give warning if explicit division by zero
3390 if (Nkind (N) = N_Op_Divide
3391 or else Nkind (N) = N_Op_Rem
3392 or else Nkind (N) = N_Op_Mod)
3393 and then not Division_Checks_Suppressed (Etype (N))
3395 Rop := Right_Opnd (N);
3397 if Compile_Time_Known_Value (Rop)
3398 and then ((Is_Integer_Type (Etype (Rop))
3399 and then Expr_Value (Rop) = Uint_0)
3401 (Is_Real_Type (Etype (Rop))
3402 and then Expr_Value_R (Rop) = Ureal_0))
3404 Apply_Compile_Time_Constraint_Error
3405 (N, "division by zero?", CE_Divide_By_Zero,
3406 Loc => Sloc (Right_Opnd (N)));
3408 -- Otherwise just set the flag to check at run time
3411 Set_Do_Division_Check (N);
3416 Check_Unset_Reference (L);
3417 Check_Unset_Reference (R);
3418 end Resolve_Arithmetic_Op;
3424 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
3425 Loc : constant Source_Ptr := Sloc (N);
3426 Subp : constant Node_Id := Name (N);
3435 -- The context imposes a unique interpretation with type Typ on
3436 -- a procedure or function call. Find the entity of the subprogram
3437 -- that yields the expected type, and propagate the corresponding
3438 -- formal constraints on the actuals. The caller has established
3439 -- that an interpretation exists, and emitted an error if not unique.
3441 -- First deal with the case of a call to an access-to-subprogram,
3442 -- dereference made explicit in Analyze_Call.
3444 if Ekind (Etype (Subp)) = E_Subprogram_Type then
3445 if not Is_Overloaded (Subp) then
3446 Nam := Etype (Subp);
3449 -- Find the interpretation whose type (a subprogram type)
3450 -- has a return type that is compatible with the context.
3451 -- Analysis of the node has established that one exists.
3453 Get_First_Interp (Subp, I, It);
3456 while Present (It.Typ) loop
3457 if Covers (Typ, Etype (It.Typ)) then
3462 Get_Next_Interp (I, It);
3466 raise Program_Error;
3470 -- If the prefix is not an entity, then resolve it
3472 if not Is_Entity_Name (Subp) then
3473 Resolve (Subp, Nam);
3476 -- For an indirect call, we always invalidate checks, since we
3477 -- do not know whether the subprogram is local or global. Yes
3478 -- we could do better here, e.g. by knowing that there are no
3479 -- local subprograms, but it does not seem worth the effort.
3480 -- Similarly, we kill al knowledge of current constant values.
3482 Kill_Current_Values;
3484 -- If this is a procedure call which is really an entry call, do
3485 -- the conversion of the procedure call to an entry call. Protected
3486 -- operations use the same circuitry because the name in the call
3487 -- can be an arbitrary expression with special resolution rules.
3489 elsif Nkind (Subp) = N_Selected_Component
3490 or else Nkind (Subp) = N_Indexed_Component
3491 or else (Is_Entity_Name (Subp)
3492 and then Ekind (Entity (Subp)) = E_Entry)
3494 Resolve_Entry_Call (N, Typ);
3495 Check_Elab_Call (N);
3497 -- Kill checks and constant values, as above for indirect case
3498 -- Who knows what happens when another task is activated?
3500 Kill_Current_Values;
3503 -- Normal subprogram call with name established in Resolve
3505 elsif not (Is_Type (Entity (Subp))) then
3506 Nam := Entity (Subp);
3507 Set_Entity_With_Style_Check (Subp, Nam);
3508 Generate_Reference (Nam, Subp);
3510 -- Otherwise we must have the case of an overloaded call
3513 pragma Assert (Is_Overloaded (Subp));
3514 Nam := Empty; -- We know that it will be assigned in loop below.
3516 Get_First_Interp (Subp, I, It);
3518 while Present (It.Typ) loop
3519 if Covers (Typ, It.Typ) then
3521 Set_Entity_With_Style_Check (Subp, Nam);
3522 Generate_Reference (Nam, Subp);
3526 Get_Next_Interp (I, It);
3530 -- Check that a call to Current_Task does not occur in an entry body
3532 if Is_RTE (Nam, RE_Current_Task) then
3542 if Nkind (P) = N_Entry_Body then
3544 ("& should not be used in entry body ('R'M C.7(17))",
3552 -- Cannot call thread body directly
3554 if Is_Thread_Body (Nam) then
3555 Error_Msg_N ("cannot call thread body directly", N);
3558 -- If the subprogram is not global, then kill all checks. This is
3559 -- a bit conservative, since in many cases we could do better, but
3560 -- it is not worth the effort. Similarly, we kill constant values.
3561 -- However we do not need to do this for internal entities (unless
3562 -- they are inherited user-defined subprograms), since they are not
3563 -- in the business of molesting global values.
3565 if not Is_Library_Level_Entity (Nam)
3566 and then (Comes_From_Source (Nam)
3567 or else (Present (Alias (Nam))
3568 and then Comes_From_Source (Alias (Nam))))
3570 Kill_Current_Values;
3573 -- Check for call to obsolescent subprogram
3575 if Warn_On_Obsolescent_Feature then
3576 Decl := Parent (Parent (Nam));
3578 if Nkind (Decl) = N_Subprogram_Declaration
3579 and then Is_List_Member (Decl)
3580 and then Nkind (Next (Decl)) = N_Pragma
3583 P : constant Node_Id := Next (Decl);
3586 if Chars (P) = Name_Obsolescent then
3587 Error_Msg_NE ("call to obsolescent subprogram&?", N, Nam);
3589 if Pragma_Argument_Associations (P) /= No_List then
3590 Name_Buffer (1) := '|';
3591 Name_Buffer (2) := '?';
3593 Add_String_To_Name_Buffer
3595 (First (Pragma_Argument_Associations (P)))));
3596 Error_Msg_N (Name_Buffer (1 .. Name_Len), N);
3603 -- Check that a procedure call does not occur in the context
3604 -- of the entry call statement of a conditional or timed
3605 -- entry call. Note that the case of a call to a subprogram
3606 -- renaming of an entry will also be rejected. The test
3607 -- for N not being an N_Entry_Call_Statement is defensive,
3608 -- covering the possibility that the processing of entry
3609 -- calls might reach this point due to later modifications
3610 -- of the code above.
3612 if Nkind (Parent (N)) = N_Entry_Call_Alternative
3613 and then Nkind (N) /= N_Entry_Call_Statement
3614 and then Entry_Call_Statement (Parent (N)) = N
3616 Error_Msg_N ("entry call required in select statement", N);
3619 -- Check that this is not a call to a protected procedure or
3620 -- entry from within a protected function.
3622 if Ekind (Current_Scope) = E_Function
3623 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
3624 and then Ekind (Nam) /= E_Function
3625 and then Scope (Nam) = Scope (Current_Scope)
3627 Error_Msg_N ("within protected function, protected " &
3628 "object is constant", N);
3629 Error_Msg_N ("\cannot call operation that may modify it", N);
3632 -- Freeze the subprogram name if not in default expression. Note
3633 -- that we freeze procedure calls as well as function calls.
3634 -- Procedure calls are not frozen according to the rules (RM
3635 -- 13.14(14)) because it is impossible to have a procedure call to
3636 -- a non-frozen procedure in pure Ada, but in the code that we
3637 -- generate in the expander, this rule needs extending because we
3638 -- can generate procedure calls that need freezing.
3640 if Is_Entity_Name (Subp) and then not In_Default_Expression then
3641 Freeze_Expression (Subp);
3644 -- For a predefined operator, the type of the result is the type
3645 -- imposed by context, except for a predefined operation on universal
3646 -- fixed. Otherwise The type of the call is the type returned by the
3647 -- subprogram being called.
3649 if Is_Predefined_Op (Nam) then
3650 if Etype (N) /= Universal_Fixed then
3654 -- If the subprogram returns an array type, and the context
3655 -- requires the component type of that array type, the node is
3656 -- really an indexing of the parameterless call. Resolve as such.
3657 -- A pathological case occurs when the type of the component is
3658 -- an access to the array type. In this case the call is truly
3661 elsif Needs_No_Actuals (Nam)
3663 ((Is_Array_Type (Etype (Nam))
3664 and then Covers (Typ, Component_Type (Etype (Nam))))
3665 or else (Is_Access_Type (Etype (Nam))
3666 and then Is_Array_Type (Designated_Type (Etype (Nam)))
3669 Component_Type (Designated_Type (Etype (Nam))))))
3672 Index_Node : Node_Id;
3674 Ret_Type : constant Entity_Id := Etype (Nam);
3677 if Is_Access_Type (Ret_Type)
3678 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
3681 ("cannot disambiguate function call and indexing", N);
3683 New_Subp := Relocate_Node (Subp);
3684 Set_Entity (Subp, Nam);
3686 if Component_Type (Ret_Type) /= Any_Type then
3688 Make_Indexed_Component (Loc,
3690 Make_Function_Call (Loc,
3692 Expressions => Parameter_Associations (N));
3694 -- Since we are correcting a node classification error made
3695 -- by the parser, we call Replace rather than Rewrite.
3697 Replace (N, Index_Node);
3698 Set_Etype (Prefix (N), Ret_Type);
3700 Resolve_Indexed_Component (N, Typ);
3701 Check_Elab_Call (Prefix (N));
3709 Set_Etype (N, Etype (Nam));
3712 -- In the case where the call is to an overloaded subprogram, Analyze
3713 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
3714 -- such a case Normalize_Actuals needs to be called once more to order
3715 -- the actuals correctly. Otherwise the call will have the ordering
3716 -- given by the last overloaded subprogram whether this is the correct
3717 -- one being called or not.
3719 if Is_Overloaded (Subp) then
3720 Normalize_Actuals (N, Nam, False, Norm_OK);
3721 pragma Assert (Norm_OK);
3724 -- In any case, call is fully resolved now. Reset Overload flag, to
3725 -- prevent subsequent overload resolution if node is analyzed again
3727 Set_Is_Overloaded (Subp, False);
3728 Set_Is_Overloaded (N, False);
3730 -- If we are calling the current subprogram from immediately within
3731 -- its body, then that is the case where we can sometimes detect
3732 -- cases of infinite recursion statically. Do not try this in case
3733 -- restriction No_Recursion is in effect anyway.
3735 Scop := Current_Scope;
3738 and then not Restriction_Active (No_Recursion)
3739 and then Check_Infinite_Recursion (N)
3741 -- Here we detected and flagged an infinite recursion, so we do
3742 -- not need to test the case below for further warnings.
3746 -- If call is to immediately containing subprogram, then check for
3747 -- the case of a possible run-time detectable infinite recursion.
3750 while Scop /= Standard_Standard loop
3752 -- Although in general recursion is not statically checkable,
3753 -- the case of calling an immediately containing subprogram
3754 -- is easy to catch.
3756 Check_Restriction (No_Recursion, N);
3758 -- If the recursive call is to a parameterless procedure, then
3759 -- even if we can't statically detect infinite recursion, this
3760 -- is pretty suspicious, and we output a warning. Furthermore,
3761 -- we will try later to detect some cases here at run time by
3762 -- expanding checking code (see Detect_Infinite_Recursion in
3763 -- package Exp_Ch6).
3765 -- If the recursive call is within a handler we do not emit a
3766 -- warning, because this is a common idiom: loop until input
3767 -- is correct, catch illegal input in handler and restart.
3769 if No (First_Formal (Nam))
3770 and then Etype (Nam) = Standard_Void_Type
3771 and then not Error_Posted (N)
3772 and then Nkind (Parent (N)) /= N_Exception_Handler
3774 Set_Has_Recursive_Call (Nam);
3775 Error_Msg_N ("possible infinite recursion?", N);
3776 Error_Msg_N ("Storage_Error may be raised at run time?", N);
3782 Scop := Scope (Scop);
3786 -- If subprogram name is a predefined operator, it was given in
3787 -- functional notation. Replace call node with operator node, so
3788 -- that actuals can be resolved appropriately.
3790 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
3791 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
3794 elsif Present (Alias (Nam))
3795 and then Is_Predefined_Op (Alias (Nam))
3797 Resolve_Actuals (N, Nam);
3798 Make_Call_Into_Operator (N, Typ, Alias (Nam));
3802 -- Create a transient scope if the resulting type requires it
3804 -- There are 3 notable exceptions: in init procs, the transient scope
3805 -- overhead is not needed and even incorrect due to the actual expansion
3806 -- of adjust calls; the second case is enumeration literal pseudo calls,
3807 -- the other case is intrinsic subprograms (Unchecked_Conversion and
3808 -- source information functions) that do not use the secondary stack
3809 -- even though the return type is unconstrained.
3811 -- If this is an initialization call for a type whose initialization
3812 -- uses the secondary stack, we also need to create a transient scope
3813 -- for it, precisely because we will not do it within the init proc
3817 and then Is_Type (Etype (Nam))
3818 and then Requires_Transient_Scope (Etype (Nam))
3819 and then Ekind (Nam) /= E_Enumeration_Literal
3820 and then not Within_Init_Proc
3821 and then not Is_Intrinsic_Subprogram (Nam)
3823 Establish_Transient_Scope
3824 (N, Sec_Stack => not Functions_Return_By_DSP_On_Target);
3826 -- If the call appears within the bounds of a loop, it will
3827 -- be rewritten and reanalyzed, nothing left to do here.
3829 if Nkind (N) /= N_Function_Call then
3833 elsif Is_Init_Proc (Nam)
3834 and then not Within_Init_Proc
3836 Check_Initialization_Call (N, Nam);
3839 -- A protected function cannot be called within the definition of the
3840 -- enclosing protected type.
3842 if Is_Protected_Type (Scope (Nam))
3843 and then In_Open_Scopes (Scope (Nam))
3844 and then not Has_Completion (Scope (Nam))
3847 ("& cannot be called before end of protected definition", N, Nam);
3850 -- Propagate interpretation to actuals, and add default expressions
3853 if Present (First_Formal (Nam)) then
3854 Resolve_Actuals (N, Nam);
3856 -- Overloaded literals are rewritten as function calls, for
3857 -- purpose of resolution. After resolution, we can replace
3858 -- the call with the literal itself.
3860 elsif Ekind (Nam) = E_Enumeration_Literal then
3861 Copy_Node (Subp, N);
3862 Resolve_Entity_Name (N, Typ);
3864 -- Avoid validation, since it is a static function call
3869 -- If the subprogram is a primitive operation, check whether or not
3870 -- it is a correct dispatching call.
3872 if Is_Overloadable (Nam)
3873 and then Is_Dispatching_Operation (Nam)
3875 Check_Dispatching_Call (N);
3877 elsif Is_Abstract (Nam)
3878 and then not In_Instance
3880 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
3883 if Is_Intrinsic_Subprogram (Nam) then
3884 Check_Intrinsic_Call (N);
3888 Check_Elab_Call (N);
3891 -------------------------------
3892 -- Resolve_Character_Literal --
3893 -------------------------------
3895 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
3896 B_Typ : constant Entity_Id := Base_Type (Typ);
3900 -- Verify that the character does belong to the type of the context
3902 Set_Etype (N, B_Typ);
3903 Eval_Character_Literal (N);
3905 -- Wide_Character literals must always be defined, since the set of
3906 -- wide character literals is complete, i.e. if a character literal
3907 -- is accepted by the parser, then it is OK for wide character.
3909 if Root_Type (B_Typ) = Standard_Wide_Character then
3912 -- Always accept character literal for type Any_Character, which
3913 -- occurs in error situations and in comparisons of literals, both
3914 -- of which should accept all literals.
3916 elsif B_Typ = Any_Character then
3919 -- For Standard.Character or a type derived from it, check that
3920 -- the literal is in range
3922 elsif Root_Type (B_Typ) = Standard_Character then
3923 if In_Character_Range (Char_Literal_Value (N)) then
3927 -- If the entity is already set, this has already been resolved in
3928 -- a generic context, or comes from expansion. Nothing else to do.
3930 elsif Present (Entity (N)) then
3933 -- Otherwise we have a user defined character type, and we can use
3934 -- the standard visibility mechanisms to locate the referenced entity
3937 C := Current_Entity (N);
3939 while Present (C) loop
3940 if Etype (C) = B_Typ then
3941 Set_Entity_With_Style_Check (N, C);
3942 Generate_Reference (C, N);
3950 -- If we fall through, then the literal does not match any of the
3951 -- entries of the enumeration type. This isn't just a constraint
3952 -- error situation, it is an illegality (see RM 4.2).
3955 ("character not defined for }", N, First_Subtype (B_Typ));
3956 end Resolve_Character_Literal;
3958 ---------------------------
3959 -- Resolve_Comparison_Op --
3960 ---------------------------
3962 -- Context requires a boolean type, and plays no role in resolution.
3963 -- Processing identical to that for equality operators. The result
3964 -- type is the base type, which matters when pathological subtypes of
3965 -- booleans with limited ranges are used.
3967 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
3968 L : constant Node_Id := Left_Opnd (N);
3969 R : constant Node_Id := Right_Opnd (N);
3973 Check_Direct_Boolean_Op (N);
3975 -- If this is an intrinsic operation which is not predefined, use
3976 -- the types of its declared arguments to resolve the possibly
3977 -- overloaded operands. Otherwise the operands are unambiguous and
3978 -- specify the expected type.
3980 if Scope (Entity (N)) /= Standard_Standard then
3981 T := Etype (First_Entity (Entity (N)));
3983 T := Find_Unique_Type (L, R);
3985 if T = Any_Fixed then
3986 T := Unique_Fixed_Point_Type (L);
3990 Set_Etype (N, Base_Type (Typ));
3991 Generate_Reference (T, N, ' ');
3993 if T /= Any_Type then
3995 or else T = Any_Composite
3996 or else T = Any_Character
3998 if T = Any_Character then
3999 Ambiguous_Character (L);
4001 Error_Msg_N ("ambiguous operands for comparison", N);
4004 Set_Etype (N, Any_Type);
4010 Check_Unset_Reference (L);
4011 Check_Unset_Reference (R);
4012 Generate_Operator_Reference (N, T);
4013 Eval_Relational_Op (N);
4016 end Resolve_Comparison_Op;
4018 ------------------------------------
4019 -- Resolve_Conditional_Expression --
4020 ------------------------------------
4022 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
4023 Condition : constant Node_Id := First (Expressions (N));
4024 Then_Expr : constant Node_Id := Next (Condition);
4025 Else_Expr : constant Node_Id := Next (Then_Expr);
4028 Resolve (Condition, Standard_Boolean);
4029 Resolve (Then_Expr, Typ);
4030 Resolve (Else_Expr, Typ);
4033 Eval_Conditional_Expression (N);
4034 end Resolve_Conditional_Expression;
4036 -----------------------------------------
4037 -- Resolve_Discrete_Subtype_Indication --
4038 -----------------------------------------
4040 procedure Resolve_Discrete_Subtype_Indication
4048 Analyze (Subtype_Mark (N));
4049 S := Entity (Subtype_Mark (N));
4051 if Nkind (Constraint (N)) /= N_Range_Constraint then
4052 Error_Msg_N ("expect range constraint for discrete type", N);
4053 Set_Etype (N, Any_Type);
4056 R := Range_Expression (Constraint (N));
4064 if Base_Type (S) /= Base_Type (Typ) then
4066 ("expect subtype of }", N, First_Subtype (Typ));
4068 -- Rewrite the constraint as a range of Typ
4069 -- to allow compilation to proceed further.
4072 Rewrite (Low_Bound (R),
4073 Make_Attribute_Reference (Sloc (Low_Bound (R)),
4074 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4075 Attribute_Name => Name_First));
4076 Rewrite (High_Bound (R),
4077 Make_Attribute_Reference (Sloc (High_Bound (R)),
4078 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4079 Attribute_Name => Name_First));
4083 Set_Etype (N, Etype (R));
4085 -- Additionally, we must check that the bounds are compatible
4086 -- with the given subtype, which might be different from the
4087 -- type of the context.
4089 Apply_Range_Check (R, S);
4091 -- ??? If the above check statically detects a Constraint_Error
4092 -- it replaces the offending bound(s) of the range R with a
4093 -- Constraint_Error node. When the itype which uses these bounds
4094 -- is frozen the resulting call to Duplicate_Subexpr generates
4095 -- a new temporary for the bounds.
4097 -- Unfortunately there are other itypes that are also made depend
4098 -- on these bounds, so when Duplicate_Subexpr is called they get
4099 -- a forward reference to the newly created temporaries and Gigi
4100 -- aborts on such forward references. This is probably sign of a
4101 -- more fundamental problem somewhere else in either the order of
4102 -- itype freezing or the way certain itypes are constructed.
4104 -- To get around this problem we call Remove_Side_Effects right
4105 -- away if either bounds of R are a Constraint_Error.
4108 L : constant Node_Id := Low_Bound (R);
4109 H : constant Node_Id := High_Bound (R);
4112 if Nkind (L) = N_Raise_Constraint_Error then
4113 Remove_Side_Effects (L);
4116 if Nkind (H) = N_Raise_Constraint_Error then
4117 Remove_Side_Effects (H);
4121 Check_Unset_Reference (Low_Bound (R));
4122 Check_Unset_Reference (High_Bound (R));
4125 end Resolve_Discrete_Subtype_Indication;
4127 -------------------------
4128 -- Resolve_Entity_Name --
4129 -------------------------
4131 -- Used to resolve identifiers and expanded names
4133 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
4134 E : constant Entity_Id := Entity (N);
4137 -- If garbage from errors, set to Any_Type and return
4139 if No (E) and then Total_Errors_Detected /= 0 then
4140 Set_Etype (N, Any_Type);
4144 -- Replace named numbers by corresponding literals. Note that this is
4145 -- the one case where Resolve_Entity_Name must reset the Etype, since
4146 -- it is currently marked as universal.
4148 if Ekind (E) = E_Named_Integer then
4150 Eval_Named_Integer (N);
4152 elsif Ekind (E) = E_Named_Real then
4154 Eval_Named_Real (N);
4156 -- Allow use of subtype only if it is a concurrent type where we are
4157 -- currently inside the body. This will eventually be expanded
4158 -- into a call to Self (for tasks) or _object (for protected
4159 -- objects). Any other use of a subtype is invalid.
4161 elsif Is_Type (E) then
4162 if Is_Concurrent_Type (E)
4163 and then In_Open_Scopes (E)
4168 ("Invalid use of subtype mark in expression or call", N);
4171 -- Check discriminant use if entity is discriminant in current scope,
4172 -- i.e. discriminant of record or concurrent type currently being
4173 -- analyzed. Uses in corresponding body are unrestricted.
4175 elsif Ekind (E) = E_Discriminant
4176 and then Scope (E) = Current_Scope
4177 and then not Has_Completion (Current_Scope)
4179 Check_Discriminant_Use (N);
4181 -- A parameterless generic function cannot appear in a context that
4182 -- requires resolution.
4184 elsif Ekind (E) = E_Generic_Function then
4185 Error_Msg_N ("illegal use of generic function", N);
4187 elsif Ekind (E) = E_Out_Parameter
4188 and then Ada_Version = Ada_83
4189 and then (Nkind (Parent (N)) in N_Op
4190 or else (Nkind (Parent (N)) = N_Assignment_Statement
4191 and then N = Expression (Parent (N)))
4192 or else Nkind (Parent (N)) = N_Explicit_Dereference)
4194 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
4196 -- In all other cases, just do the possible static evaluation
4199 -- A deferred constant that appears in an expression must have
4200 -- a completion, unless it has been removed by in-place expansion
4203 if Ekind (E) = E_Constant
4204 and then Comes_From_Source (E)
4205 and then No (Constant_Value (E))
4206 and then Is_Frozen (Etype (E))
4207 and then not In_Default_Expression
4208 and then not Is_Imported (E)
4211 if No_Initialization (Parent (E))
4212 or else (Present (Full_View (E))
4213 and then No_Initialization (Parent (Full_View (E))))
4218 "deferred constant is frozen before completion", N);
4222 Eval_Entity_Name (N);
4224 end Resolve_Entity_Name;
4230 procedure Resolve_Entry (Entry_Name : Node_Id) is
4231 Loc : constant Source_Ptr := Sloc (Entry_Name);
4239 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
4240 -- If the bounds of the entry family being called depend on task
4241 -- discriminants, build a new index subtype where a discriminant is
4242 -- replaced with the value of the discriminant of the target task.
4243 -- The target task is the prefix of the entry name in the call.
4245 -----------------------
4246 -- Actual_Index_Type --
4247 -----------------------
4249 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
4250 Typ : constant Entity_Id := Entry_Index_Type (E);
4251 Tsk : constant Entity_Id := Scope (E);
4252 Lo : constant Node_Id := Type_Low_Bound (Typ);
4253 Hi : constant Node_Id := Type_High_Bound (Typ);
4256 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
4257 -- If the bound is given by a discriminant, replace with a reference
4258 -- to the discriminant of the same name in the target task.
4259 -- If the entry name is the target of a requeue statement and the
4260 -- entry is in the current protected object, the bound to be used
4261 -- is the discriminal of the object (see apply_range_checks for
4262 -- details of the transformation).
4264 -----------------------------
4265 -- Actual_Discriminant_Ref --
4266 -----------------------------
4268 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
4269 Typ : constant Entity_Id := Etype (Bound);
4273 Remove_Side_Effects (Bound);
4275 if not Is_Entity_Name (Bound)
4276 or else Ekind (Entity (Bound)) /= E_Discriminant
4280 elsif Is_Protected_Type (Tsk)
4281 and then In_Open_Scopes (Tsk)
4282 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
4284 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
4288 Make_Selected_Component (Loc,
4289 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
4290 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
4295 end Actual_Discriminant_Ref;
4297 -- Start of processing for Actual_Index_Type
4300 if not Has_Discriminants (Tsk)
4301 or else (not Is_Entity_Name (Lo)
4302 and then not Is_Entity_Name (Hi))
4304 return Entry_Index_Type (E);
4307 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
4308 Set_Etype (New_T, Base_Type (Typ));
4309 Set_Size_Info (New_T, Typ);
4310 Set_RM_Size (New_T, RM_Size (Typ));
4311 Set_Scalar_Range (New_T,
4312 Make_Range (Sloc (Entry_Name),
4313 Low_Bound => Actual_Discriminant_Ref (Lo),
4314 High_Bound => Actual_Discriminant_Ref (Hi)));
4318 end Actual_Index_Type;
4320 -- Start of processing of Resolve_Entry
4323 -- Find name of entry being called, and resolve prefix of name
4324 -- with its own type. The prefix can be overloaded, and the name
4325 -- and signature of the entry must be taken into account.
4327 if Nkind (Entry_Name) = N_Indexed_Component then
4329 -- Case of dealing with entry family within the current tasks
4331 E_Name := Prefix (Entry_Name);
4334 E_Name := Entry_Name;
4337 if Is_Entity_Name (E_Name) then
4338 -- Entry call to an entry (or entry family) in the current task.
4339 -- This is legal even though the task will deadlock. Rewrite as
4340 -- call to current task.
4342 -- This can also be a call to an entry in an enclosing task.
4343 -- If this is a single task, we have to retrieve its name,
4344 -- because the scope of the entry is the task type, not the
4345 -- object. If the enclosing task is a task type, the identity
4346 -- of the task is given by its own self variable.
4348 -- Finally this can be a requeue on an entry of the same task
4349 -- or protected object.
4351 S := Scope (Entity (E_Name));
4353 for J in reverse 0 .. Scope_Stack.Last loop
4355 if Is_Task_Type (Scope_Stack.Table (J).Entity)
4356 and then not Comes_From_Source (S)
4358 -- S is an enclosing task or protected object. The concurrent
4359 -- declaration has been converted into a type declaration, and
4360 -- the object itself has an object declaration that follows
4361 -- the type in the same declarative part.
4363 Tsk := Next_Entity (S);
4365 while Etype (Tsk) /= S loop
4372 elsif S = Scope_Stack.Table (J).Entity then
4374 -- Call to current task. Will be transformed into call to Self
4382 Make_Selected_Component (Loc,
4383 Prefix => New_Occurrence_Of (S, Loc),
4385 New_Occurrence_Of (Entity (E_Name), Loc));
4386 Rewrite (E_Name, New_N);
4389 elsif Nkind (Entry_Name) = N_Selected_Component
4390 and then Is_Overloaded (Prefix (Entry_Name))
4392 -- Use the entry name (which must be unique at this point) to
4393 -- find the prefix that returns the corresponding task type or
4397 Pref : constant Node_Id := Prefix (Entry_Name);
4398 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
4403 Get_First_Interp (Pref, I, It);
4405 while Present (It.Typ) loop
4407 if Scope (Ent) = It.Typ then
4408 Set_Etype (Pref, It.Typ);
4412 Get_Next_Interp (I, It);
4417 if Nkind (Entry_Name) = N_Selected_Component then
4418 Resolve (Prefix (Entry_Name));
4420 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4421 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4422 Resolve (Prefix (Prefix (Entry_Name)));
4423 Index := First (Expressions (Entry_Name));
4424 Resolve (Index, Entry_Index_Type (Nam));
4426 -- Up to this point the expression could have been the actual
4427 -- in a simple entry call, and be given by a named association.
4429 if Nkind (Index) = N_Parameter_Association then
4430 Error_Msg_N ("expect expression for entry index", Index);
4432 Apply_Range_Check (Index, Actual_Index_Type (Nam));
4437 ------------------------
4438 -- Resolve_Entry_Call --
4439 ------------------------
4441 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
4442 Entry_Name : constant Node_Id := Name (N);
4443 Loc : constant Source_Ptr := Sloc (Entry_Name);
4445 First_Named : Node_Id;
4452 -- We kill all checks here, because it does not seem worth the
4453 -- effort to do anything better, an entry call is a big operation.
4457 -- Processing of the name is similar for entry calls and protected
4458 -- operation calls. Once the entity is determined, we can complete
4459 -- the resolution of the actuals.
4461 -- The selector may be overloaded, in the case of a protected object
4462 -- with overloaded functions. The type of the context is used for
4465 if Nkind (Entry_Name) = N_Selected_Component
4466 and then Is_Overloaded (Selector_Name (Entry_Name))
4467 and then Typ /= Standard_Void_Type
4474 Get_First_Interp (Selector_Name (Entry_Name), I, It);
4476 while Present (It.Typ) loop
4478 if Covers (Typ, It.Typ) then
4479 Set_Entity (Selector_Name (Entry_Name), It.Nam);
4480 Set_Etype (Entry_Name, It.Typ);
4482 Generate_Reference (It.Typ, N, ' ');
4485 Get_Next_Interp (I, It);
4490 Resolve_Entry (Entry_Name);
4492 if Nkind (Entry_Name) = N_Selected_Component then
4494 -- Simple entry call.
4496 Nam := Entity (Selector_Name (Entry_Name));
4497 Obj := Prefix (Entry_Name);
4498 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
4500 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4502 -- Call to member of entry family.
4504 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4505 Obj := Prefix (Prefix (Entry_Name));
4506 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
4509 -- We cannot in general check the maximum depth of protected entry
4510 -- calls at compile time. But we can tell that any protected entry
4511 -- call at all violates a specified nesting depth of zero.
4513 if Is_Protected_Type (Scope (Nam)) then
4514 Check_Restriction (Max_Entry_Queue_Length, N);
4517 -- Use context type to disambiguate a protected function that can be
4518 -- called without actuals and that returns an array type, and where
4519 -- the argument list may be an indexing of the returned value.
4521 if Ekind (Nam) = E_Function
4522 and then Needs_No_Actuals (Nam)
4523 and then Present (Parameter_Associations (N))
4525 ((Is_Array_Type (Etype (Nam))
4526 and then Covers (Typ, Component_Type (Etype (Nam))))
4528 or else (Is_Access_Type (Etype (Nam))
4529 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4530 and then Covers (Typ,
4531 Component_Type (Designated_Type (Etype (Nam))))))
4534 Index_Node : Node_Id;
4538 Make_Indexed_Component (Loc,
4540 Make_Function_Call (Loc,
4541 Name => Relocate_Node (Entry_Name)),
4542 Expressions => Parameter_Associations (N));
4544 -- Since we are correcting a node classification error made by
4545 -- the parser, we call Replace rather than Rewrite.
4547 Replace (N, Index_Node);
4548 Set_Etype (Prefix (N), Etype (Nam));
4550 Resolve_Indexed_Component (N, Typ);
4555 -- The operation name may have been overloaded. Order the actuals
4556 -- according to the formals of the resolved entity, and set the
4557 -- return type to that of the operation.
4560 Normalize_Actuals (N, Nam, False, Norm_OK);
4561 pragma Assert (Norm_OK);
4562 Set_Etype (N, Etype (Nam));
4565 Resolve_Actuals (N, Nam);
4566 Generate_Reference (Nam, Entry_Name);
4568 if Ekind (Nam) = E_Entry
4569 or else Ekind (Nam) = E_Entry_Family
4571 Check_Potentially_Blocking_Operation (N);
4574 -- Verify that a procedure call cannot masquerade as an entry
4575 -- call where an entry call is expected.
4577 if Ekind (Nam) = E_Procedure then
4578 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4579 and then N = Entry_Call_Statement (Parent (N))
4581 Error_Msg_N ("entry call required in select statement", N);
4583 elsif Nkind (Parent (N)) = N_Triggering_Alternative
4584 and then N = Triggering_Statement (Parent (N))
4586 Error_Msg_N ("triggering statement cannot be procedure call", N);
4588 elsif Ekind (Scope (Nam)) = E_Task_Type
4589 and then not In_Open_Scopes (Scope (Nam))
4591 Error_Msg_N ("Task has no entry with this name", Entry_Name);
4595 -- After resolution, entry calls and protected procedure calls
4596 -- are changed into entry calls, for expansion. The structure
4597 -- of the node does not change, so it can safely be done in place.
4598 -- Protected function calls must keep their structure because they
4599 -- are subexpressions.
4601 if Ekind (Nam) /= E_Function then
4603 -- A protected operation that is not a function may modify the
4604 -- corresponding object, and cannot apply to a constant.
4605 -- If this is an internal call, the prefix is the type itself.
4607 if Is_Protected_Type (Scope (Nam))
4608 and then not Is_Variable (Obj)
4609 and then (not Is_Entity_Name (Obj)
4610 or else not Is_Type (Entity (Obj)))
4613 ("prefix of protected procedure or entry call must be variable",
4617 Actuals := Parameter_Associations (N);
4618 First_Named := First_Named_Actual (N);
4621 Make_Entry_Call_Statement (Loc,
4623 Parameter_Associations => Actuals));
4625 Set_First_Named_Actual (N, First_Named);
4626 Set_Analyzed (N, True);
4628 -- Protected functions can return on the secondary stack, in which
4629 -- case we must trigger the transient scope mechanism
4631 elsif Expander_Active
4632 and then Requires_Transient_Scope (Etype (Nam))
4634 Establish_Transient_Scope (N,
4635 Sec_Stack => not Functions_Return_By_DSP_On_Target);
4637 end Resolve_Entry_Call;
4639 -------------------------
4640 -- Resolve_Equality_Op --
4641 -------------------------
4643 -- Both arguments must have the same type, and the boolean context
4644 -- does not participate in the resolution. The first pass verifies
4645 -- that the interpretation is not ambiguous, and the type of the left
4646 -- argument is correctly set, or is Any_Type in case of ambiguity.
4647 -- If both arguments are strings or aggregates, allocators, or Null,
4648 -- they are ambiguous even though they carry a single (universal) type.
4649 -- Diagnose this case here.
4651 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
4652 L : constant Node_Id := Left_Opnd (N);
4653 R : constant Node_Id := Right_Opnd (N);
4654 T : Entity_Id := Find_Unique_Type (L, R);
4656 function Find_Unique_Access_Type return Entity_Id;
4657 -- In the case of allocators, make a last-ditch attempt to find a single
4658 -- access type with the right designated type. This is semantically
4659 -- dubious, and of no interest to any real code, but c48008a makes it
4662 -----------------------------
4663 -- Find_Unique_Access_Type --
4664 -----------------------------
4666 function Find_Unique_Access_Type return Entity_Id is
4669 S : Entity_Id := Current_Scope;
4672 if Ekind (Etype (R)) = E_Allocator_Type then
4673 Acc := Designated_Type (Etype (R));
4675 elsif Ekind (Etype (L)) = E_Allocator_Type then
4676 Acc := Designated_Type (Etype (L));
4682 while S /= Standard_Standard loop
4683 E := First_Entity (S);
4685 while Present (E) loop
4688 and then Is_Access_Type (E)
4689 and then Ekind (E) /= E_Allocator_Type
4690 and then Designated_Type (E) = Base_Type (Acc)
4702 end Find_Unique_Access_Type;
4704 -- Start of processing for Resolve_Equality_Op
4707 Check_Direct_Boolean_Op (N);
4709 Set_Etype (N, Base_Type (Typ));
4710 Generate_Reference (T, N, ' ');
4712 if T = Any_Fixed then
4713 T := Unique_Fixed_Point_Type (L);
4716 if T /= Any_Type then
4719 or else T = Any_Composite
4720 or else T = Any_Character
4723 if T = Any_Character then
4724 Ambiguous_Character (L);
4726 Error_Msg_N ("ambiguous operands for equality", N);
4729 Set_Etype (N, Any_Type);
4732 elsif T = Any_Access
4733 or else Ekind (T) = E_Allocator_Type
4735 T := Find_Unique_Access_Type;
4738 Error_Msg_N ("ambiguous operands for equality", N);
4739 Set_Etype (N, Any_Type);
4747 if Warn_On_Redundant_Constructs
4748 and then Comes_From_Source (N)
4749 and then Is_Entity_Name (R)
4750 and then Entity (R) = Standard_True
4751 and then Comes_From_Source (R)
4753 Error_Msg_N ("comparison with True is redundant?", R);
4756 Check_Unset_Reference (L);
4757 Check_Unset_Reference (R);
4758 Generate_Operator_Reference (N, T);
4760 -- If this is an inequality, it may be the implicit inequality
4761 -- created for a user-defined operation, in which case the corres-
4762 -- ponding equality operation is not intrinsic, and the operation
4763 -- cannot be constant-folded. Else fold.
4765 if Nkind (N) = N_Op_Eq
4766 or else Comes_From_Source (Entity (N))
4767 or else Ekind (Entity (N)) = E_Operator
4768 or else Is_Intrinsic_Subprogram
4769 (Corresponding_Equality (Entity (N)))
4771 Eval_Relational_Op (N);
4772 elsif Nkind (N) = N_Op_Ne
4773 and then Is_Abstract (Entity (N))
4775 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
4778 end Resolve_Equality_Op;
4780 ----------------------------------
4781 -- Resolve_Explicit_Dereference --
4782 ----------------------------------
4784 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
4785 P : constant Node_Id := Prefix (N);
4790 -- Now that we know the type, check that this is not a
4791 -- dereference of an uncompleted type. Note that this
4792 -- is not entirely correct, because dereferences of
4793 -- private types are legal in default expressions.
4794 -- This consideration also applies to similar checks
4795 -- for allocators, qualified expressions, and type
4798 Check_Fully_Declared (Typ, N);
4800 if Is_Overloaded (P) then
4802 -- Use the context type to select the prefix that has the
4803 -- correct designated type.
4805 Get_First_Interp (P, I, It);
4806 while Present (It.Typ) loop
4807 exit when Is_Access_Type (It.Typ)
4808 and then Covers (Typ, Designated_Type (It.Typ));
4810 Get_Next_Interp (I, It);
4813 Resolve (P, It.Typ);
4814 Set_Etype (N, Designated_Type (It.Typ));
4820 if Is_Access_Type (Etype (P)) then
4821 Apply_Access_Check (N);
4824 -- If the designated type is a packed unconstrained array type,
4825 -- and the explicit dereference is not in the context of an
4826 -- attribute reference, then we must compute and set the actual
4827 -- subtype, since it is needed by Gigi. The reason we exclude
4828 -- the attribute case is that this is handled fine by Gigi, and
4829 -- in fact we use such attributes to build the actual subtype.
4830 -- We also exclude generated code (which builds actual subtypes
4831 -- directly if they are needed).
4833 if Is_Array_Type (Etype (N))
4834 and then Is_Packed (Etype (N))
4835 and then not Is_Constrained (Etype (N))
4836 and then Nkind (Parent (N)) /= N_Attribute_Reference
4837 and then Comes_From_Source (N)
4839 Set_Etype (N, Get_Actual_Subtype (N));
4842 -- Note: there is no Eval processing required for an explicit
4843 -- deference, because the type is known to be an allocators, and
4844 -- allocator expressions can never be static.
4846 end Resolve_Explicit_Dereference;
4848 -------------------------------
4849 -- Resolve_Indexed_Component --
4850 -------------------------------
4852 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
4853 Name : constant Node_Id := Prefix (N);
4855 Array_Type : Entity_Id := Empty; -- to prevent junk warning
4859 if Is_Overloaded (Name) then
4861 -- Use the context type to select the prefix that yields the
4862 -- correct component type.
4867 I1 : Interp_Index := 0;
4868 P : constant Node_Id := Prefix (N);
4869 Found : Boolean := False;
4872 Get_First_Interp (P, I, It);
4874 while Present (It.Typ) loop
4876 if (Is_Array_Type (It.Typ)
4877 and then Covers (Typ, Component_Type (It.Typ)))
4878 or else (Is_Access_Type (It.Typ)
4879 and then Is_Array_Type (Designated_Type (It.Typ))
4881 (Typ, Component_Type (Designated_Type (It.Typ))))
4884 It := Disambiguate (P, I1, I, Any_Type);
4886 if It = No_Interp then
4887 Error_Msg_N ("ambiguous prefix for indexing", N);
4893 Array_Type := It.Typ;
4899 Array_Type := It.Typ;
4904 Get_Next_Interp (I, It);
4909 Array_Type := Etype (Name);
4912 Resolve (Name, Array_Type);
4913 Array_Type := Get_Actual_Subtype_If_Available (Name);
4915 -- If prefix is access type, dereference to get real array type.
4916 -- Note: we do not apply an access check because the expander always
4917 -- introduces an explicit dereference, and the check will happen there.
4919 if Is_Access_Type (Array_Type) then
4920 Array_Type := Designated_Type (Array_Type);
4923 -- If name was overloaded, set component type correctly now.
4925 Set_Etype (N, Component_Type (Array_Type));
4927 Index := First_Index (Array_Type);
4928 Expr := First (Expressions (N));
4930 -- The prefix may have resolved to a string literal, in which case
4931 -- its etype has a special representation. This is only possible
4932 -- currently if the prefix is a static concatenation, written in
4933 -- functional notation.
4935 if Ekind (Array_Type) = E_String_Literal_Subtype then
4936 Resolve (Expr, Standard_Positive);
4939 while Present (Index) and Present (Expr) loop
4940 Resolve (Expr, Etype (Index));
4941 Check_Unset_Reference (Expr);
4943 if Is_Scalar_Type (Etype (Expr)) then
4944 Apply_Scalar_Range_Check (Expr, Etype (Index));
4946 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
4954 Eval_Indexed_Component (N);
4955 end Resolve_Indexed_Component;
4957 -----------------------------
4958 -- Resolve_Integer_Literal --
4959 -----------------------------
4961 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
4964 Eval_Integer_Literal (N);
4965 end Resolve_Integer_Literal;
4967 --------------------------------
4968 -- Resolve_Intrinsic_Operator --
4969 --------------------------------
4971 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
4972 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
4980 while Scope (Op) /= Standard_Standard loop
4982 pragma Assert (Present (Op));
4986 Set_Is_Overloaded (N, False);
4988 -- If the operand type is private, rewrite with suitable
4989 -- conversions on the operands and the result, to expose
4990 -- the proper underlying numeric type.
4992 if Is_Private_Type (Typ) then
4993 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
4995 if Nkind (N) = N_Op_Expon then
4996 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
4998 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5001 Save_Interps (Left_Opnd (N), Expression (Arg1));
5002 Save_Interps (Right_Opnd (N), Expression (Arg2));
5004 Set_Left_Opnd (N, Arg1);
5005 Set_Right_Opnd (N, Arg2);
5007 Set_Etype (N, Btyp);
5008 Rewrite (N, Unchecked_Convert_To (Typ, N));
5011 elsif Typ /= Etype (Left_Opnd (N))
5012 or else Typ /= Etype (Right_Opnd (N))
5014 -- Add explicit conversion where needed, and save interpretations
5015 -- in case operands are overloaded.
5017 Arg1 := Convert_To (Typ, Left_Opnd (N));
5018 Arg2 := Convert_To (Typ, Right_Opnd (N));
5020 if Nkind (Arg1) = N_Type_Conversion then
5021 Save_Interps (Left_Opnd (N), Expression (Arg1));
5023 Save_Interps (Left_Opnd (N), Arg1);
5026 if Nkind (Arg2) = N_Type_Conversion then
5027 Save_Interps (Right_Opnd (N), Expression (Arg2));
5029 Save_Interps (Right_Opnd (N), Arg2);
5032 Rewrite (Left_Opnd (N), Arg1);
5033 Rewrite (Right_Opnd (N), Arg2);
5036 Resolve_Arithmetic_Op (N, Typ);
5039 Resolve_Arithmetic_Op (N, Typ);
5041 end Resolve_Intrinsic_Operator;
5043 --------------------------------------
5044 -- Resolve_Intrinsic_Unary_Operator --
5045 --------------------------------------
5047 procedure Resolve_Intrinsic_Unary_Operator
5051 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
5058 while Scope (Op) /= Standard_Standard loop
5060 pragma Assert (Present (Op));
5065 if Is_Private_Type (Typ) then
5066 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5067 Save_Interps (Right_Opnd (N), Expression (Arg2));
5069 Set_Right_Opnd (N, Arg2);
5071 Set_Etype (N, Btyp);
5072 Rewrite (N, Unchecked_Convert_To (Typ, N));
5076 Resolve_Unary_Op (N, Typ);
5078 end Resolve_Intrinsic_Unary_Operator;
5080 ------------------------
5081 -- Resolve_Logical_Op --
5082 ------------------------
5084 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
5088 Check_Direct_Boolean_Op (N);
5090 -- Predefined operations on scalar types yield the base type. On
5091 -- the other hand, logical operations on arrays yield the type of
5092 -- the arguments (and the context).
5094 if Is_Array_Type (Typ) then
5097 B_Typ := Base_Type (Typ);
5100 -- The following test is required because the operands of the operation
5101 -- may be literals, in which case the resulting type appears to be
5102 -- compatible with a signed integer type, when in fact it is compatible
5103 -- only with modular types. If the context itself is universal, the
5104 -- operation is illegal.
5106 if not Valid_Boolean_Arg (Typ) then
5107 Error_Msg_N ("invalid context for logical operation", N);
5108 Set_Etype (N, Any_Type);
5111 elsif Typ = Any_Modular then
5113 ("no modular type available in this context", N);
5114 Set_Etype (N, Any_Type);
5116 elsif Is_Modular_Integer_Type (Typ)
5117 and then Etype (Left_Opnd (N)) = Universal_Integer
5118 and then Etype (Right_Opnd (N)) = Universal_Integer
5120 Check_For_Visible_Operator (N, B_Typ);
5123 Resolve (Left_Opnd (N), B_Typ);
5124 Resolve (Right_Opnd (N), B_Typ);
5126 Check_Unset_Reference (Left_Opnd (N));
5127 Check_Unset_Reference (Right_Opnd (N));
5129 Set_Etype (N, B_Typ);
5130 Generate_Operator_Reference (N, B_Typ);
5131 Eval_Logical_Op (N);
5132 end Resolve_Logical_Op;
5134 ---------------------------
5135 -- Resolve_Membership_Op --
5136 ---------------------------
5138 -- The context can only be a boolean type, and does not determine
5139 -- the arguments. Arguments should be unambiguous, but the preference
5140 -- rule for universal types applies.
5142 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
5143 pragma Warnings (Off, Typ);
5145 L : constant Node_Id := Left_Opnd (N);
5146 R : constant Node_Id := Right_Opnd (N);
5150 if L = Error or else R = Error then
5154 if not Is_Overloaded (R)
5156 (Etype (R) = Universal_Integer or else
5157 Etype (R) = Universal_Real)
5158 and then Is_Overloaded (L)
5162 T := Intersect_Types (L, R);
5166 Check_Unset_Reference (L);
5168 if Nkind (R) = N_Range
5169 and then not Is_Scalar_Type (T)
5171 Error_Msg_N ("scalar type required for range", R);
5174 if Is_Entity_Name (R) then
5175 Freeze_Expression (R);
5178 Check_Unset_Reference (R);
5181 Eval_Membership_Op (N);
5182 end Resolve_Membership_Op;
5188 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
5190 -- Handle restriction against anonymous null access values
5191 -- This restriction can be turned off using -gnatdh.
5193 -- Ada 2005 (AI-231): Remove restriction
5195 if Ada_Version < Ada_05
5196 and then not Debug_Flag_J
5197 and then Ekind (Typ) = E_Anonymous_Access_Type
5198 and then Comes_From_Source (N)
5200 -- In the common case of a call which uses an explicitly null
5201 -- value for an access parameter, give specialized error msg
5203 if Nkind (Parent (N)) = N_Procedure_Call_Statement
5205 Nkind (Parent (N)) = N_Function_Call
5208 ("null is not allowed as argument for an access parameter", N);
5210 -- Standard message for all other cases (are there any?)
5214 ("null cannot be of an anonymous access type", N);
5218 -- In a distributed context, null for a remote access to subprogram
5219 -- may need to be replaced with a special record aggregate. In this
5220 -- case, return after having done the transformation.
5222 if (Ekind (Typ) = E_Record_Type
5223 or else Is_Remote_Access_To_Subprogram_Type (Typ))
5224 and then Remote_AST_Null_Value (N, Typ)
5229 -- The null literal takes its type from the context.
5234 -----------------------
5235 -- Resolve_Op_Concat --
5236 -----------------------
5238 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
5239 Btyp : constant Entity_Id := Base_Type (Typ);
5240 Op1 : constant Node_Id := Left_Opnd (N);
5241 Op2 : constant Node_Id := Right_Opnd (N);
5243 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean);
5244 -- Internal procedure to resolve one operand of concatenation operator.
5245 -- The operand is either of the array type or of the component type.
5246 -- If the operand is an aggregate, and the component type is composite,
5247 -- this is ambiguous if component type has aggregates.
5249 -------------------------------
5250 -- Resolve_Concatenation_Arg --
5251 -------------------------------
5253 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean) is
5257 or else (not Is_Overloaded (Arg)
5258 and then Etype (Arg) /= Any_Composite
5259 and then Covers (Component_Type (Typ), Etype (Arg)))
5261 Resolve (Arg, Component_Type (Typ));
5263 Resolve (Arg, Btyp);
5266 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
5268 if Nkind (Arg) = N_Aggregate
5269 and then Is_Composite_Type (Component_Type (Typ))
5271 if Is_Private_Type (Component_Type (Typ)) then
5272 Resolve (Arg, Btyp);
5275 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
5276 Set_Etype (Arg, Any_Type);
5280 if Is_Overloaded (Arg)
5281 and then Has_Compatible_Type (Arg, Typ)
5282 and then Etype (Arg) /= Any_Type
5284 Error_Msg_N ("ambiguous operand for concatenation!", Arg);
5291 Get_First_Interp (Arg, I, It);
5293 while Present (It.Nam) loop
5295 if Base_Type (Etype (It.Nam)) = Base_Type (Typ)
5296 or else Base_Type (Etype (It.Nam)) =
5297 Base_Type (Component_Type (Typ))
5299 Error_Msg_Sloc := Sloc (It.Nam);
5300 Error_Msg_N ("\possible interpretation#", Arg);
5303 Get_Next_Interp (I, It);
5308 Resolve (Arg, Component_Type (Typ));
5310 if Nkind (Arg) = N_String_Literal then
5311 Set_Etype (Arg, Component_Type (Typ));
5314 if Arg = Left_Opnd (N) then
5315 Set_Is_Component_Left_Opnd (N);
5317 Set_Is_Component_Right_Opnd (N);
5322 Resolve (Arg, Btyp);
5325 Check_Unset_Reference (Arg);
5326 end Resolve_Concatenation_Arg;
5328 -- Start of processing for Resolve_Op_Concat
5331 Set_Etype (N, Btyp);
5333 if Is_Limited_Composite (Btyp) then
5334 Error_Msg_N ("concatenation not available for limited array", N);
5335 Explain_Limited_Type (Btyp, N);
5338 -- If the operands are themselves concatenations, resolve them as
5339 -- such directly. This removes several layers of recursion and allows
5340 -- GNAT to handle larger multiple concatenations.
5342 if Nkind (Op1) = N_Op_Concat
5343 and then not Is_Array_Type (Component_Type (Typ))
5344 and then Entity (Op1) = Entity (N)
5346 Resolve_Op_Concat (Op1, Typ);
5348 Resolve_Concatenation_Arg
5349 (Op1, Is_Component_Left_Opnd (N));
5352 if Nkind (Op2) = N_Op_Concat
5353 and then not Is_Array_Type (Component_Type (Typ))
5354 and then Entity (Op2) = Entity (N)
5356 Resolve_Op_Concat (Op2, Typ);
5358 Resolve_Concatenation_Arg
5359 (Op2, Is_Component_Right_Opnd (N));
5362 Generate_Operator_Reference (N, Typ);
5364 if Is_String_Type (Typ) then
5365 Eval_Concatenation (N);
5368 -- If this is not a static concatenation, but the result is a
5369 -- string type (and not an array of strings) insure that static
5370 -- string operands have their subtypes properly constructed.
5372 if Nkind (N) /= N_String_Literal
5373 and then Is_Character_Type (Component_Type (Typ))
5375 Set_String_Literal_Subtype (Op1, Typ);
5376 Set_String_Literal_Subtype (Op2, Typ);
5378 end Resolve_Op_Concat;
5380 ----------------------
5381 -- Resolve_Op_Expon --
5382 ----------------------
5384 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
5385 B_Typ : constant Entity_Id := Base_Type (Typ);
5388 -- Catch attempts to do fixed-point exponentation with universal
5389 -- operands, which is a case where the illegality is not caught
5390 -- during normal operator analysis.
5392 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
5393 Error_Msg_N ("exponentiation not available for fixed point", N);
5397 if Comes_From_Source (N)
5398 and then Ekind (Entity (N)) = E_Function
5399 and then Is_Imported (Entity (N))
5400 and then Is_Intrinsic_Subprogram (Entity (N))
5402 Resolve_Intrinsic_Operator (N, Typ);
5406 if Etype (Left_Opnd (N)) = Universal_Integer
5407 or else Etype (Left_Opnd (N)) = Universal_Real
5409 Check_For_Visible_Operator (N, B_Typ);
5412 -- We do the resolution using the base type, because intermediate values
5413 -- in expressions always are of the base type, not a subtype of it.
5415 Resolve (Left_Opnd (N), B_Typ);
5416 Resolve (Right_Opnd (N), Standard_Integer);
5418 Check_Unset_Reference (Left_Opnd (N));
5419 Check_Unset_Reference (Right_Opnd (N));
5421 Set_Etype (N, B_Typ);
5422 Generate_Operator_Reference (N, B_Typ);
5425 -- Set overflow checking bit. Much cleverer code needed here eventually
5426 -- and perhaps the Resolve routines should be separated for the various
5427 -- arithmetic operations, since they will need different processing. ???
5429 if Nkind (N) in N_Op then
5430 if not Overflow_Checks_Suppressed (Etype (N)) then
5431 Enable_Overflow_Check (N);
5434 end Resolve_Op_Expon;
5436 --------------------
5437 -- Resolve_Op_Not --
5438 --------------------
5440 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
5443 function Parent_Is_Boolean return Boolean;
5444 -- This function determines if the parent node is a boolean operator
5445 -- or operation (comparison op, membership test, or short circuit form)
5446 -- and the not in question is the left operand of this operation.
5447 -- Note that if the not is in parens, then false is returned.
5449 function Parent_Is_Boolean return Boolean is
5451 if Paren_Count (N) /= 0 then
5455 case Nkind (Parent (N)) is
5470 return Left_Opnd (Parent (N)) = N;
5476 end Parent_Is_Boolean;
5478 -- Start of processing for Resolve_Op_Not
5481 -- Predefined operations on scalar types yield the base type. On
5482 -- the other hand, logical operations on arrays yield the type of
5483 -- the arguments (and the context).
5485 if Is_Array_Type (Typ) then
5488 B_Typ := Base_Type (Typ);
5491 if not Valid_Boolean_Arg (Typ) then
5492 Error_Msg_N ("invalid operand type for operator&", N);
5493 Set_Etype (N, Any_Type);
5496 elsif Typ = Universal_Integer or else Typ = Any_Modular then
5497 if Parent_Is_Boolean then
5499 ("operand of not must be enclosed in parentheses",
5503 ("no modular type available in this context", N);
5506 Set_Etype (N, Any_Type);
5510 if not Is_Boolean_Type (Typ)
5511 and then Parent_Is_Boolean
5513 Error_Msg_N ("?not expression should be parenthesized here", N);
5516 Resolve (Right_Opnd (N), B_Typ);
5517 Check_Unset_Reference (Right_Opnd (N));
5518 Set_Etype (N, B_Typ);
5519 Generate_Operator_Reference (N, B_Typ);
5524 -----------------------------
5525 -- Resolve_Operator_Symbol --
5526 -----------------------------
5528 -- Nothing to be done, all resolved already
5530 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
5531 pragma Warnings (Off, N);
5532 pragma Warnings (Off, Typ);
5536 end Resolve_Operator_Symbol;
5538 ----------------------------------
5539 -- Resolve_Qualified_Expression --
5540 ----------------------------------
5542 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
5543 pragma Warnings (Off, Typ);
5545 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
5546 Expr : constant Node_Id := Expression (N);
5549 Resolve (Expr, Target_Typ);
5551 -- A qualified expression requires an exact match of the type,
5552 -- class-wide matching is not allowed.
5554 if Is_Class_Wide_Type (Target_Typ)
5555 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
5557 Wrong_Type (Expr, Target_Typ);
5560 -- If the target type is unconstrained, then we reset the type of
5561 -- the result from the type of the expression. For other cases, the
5562 -- actual subtype of the expression is the target type.
5564 if Is_Composite_Type (Target_Typ)
5565 and then not Is_Constrained (Target_Typ)
5567 Set_Etype (N, Etype (Expr));
5570 Eval_Qualified_Expression (N);
5571 end Resolve_Qualified_Expression;
5577 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
5578 L : constant Node_Id := Low_Bound (N);
5579 H : constant Node_Id := High_Bound (N);
5586 Check_Unset_Reference (L);
5587 Check_Unset_Reference (H);
5589 -- We have to check the bounds for being within the base range as
5590 -- required for a non-static context. Normally this is automatic
5591 -- and done as part of evaluating expressions, but the N_Range
5592 -- node is an exception, since in GNAT we consider this node to
5593 -- be a subexpression, even though in Ada it is not. The circuit
5594 -- in Sem_Eval could check for this, but that would put the test
5595 -- on the main evaluation path for expressions.
5597 Check_Non_Static_Context (L);
5598 Check_Non_Static_Context (H);
5600 -- If bounds are static, constant-fold them, so size computations
5601 -- are identical between front-end and back-end. Do not perform this
5602 -- transformation while analyzing generic units, as type information
5603 -- would then be lost when reanalyzing the constant node in the
5606 if Is_Discrete_Type (Typ) and then Expander_Active then
5607 if Is_OK_Static_Expression (L) then
5608 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
5611 if Is_OK_Static_Expression (H) then
5612 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
5617 --------------------------
5618 -- Resolve_Real_Literal --
5619 --------------------------
5621 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
5622 Actual_Typ : constant Entity_Id := Etype (N);
5625 -- Special processing for fixed-point literals to make sure that the
5626 -- value is an exact multiple of small where this is required. We
5627 -- skip this for the universal real case, and also for generic types.
5629 if Is_Fixed_Point_Type (Typ)
5630 and then Typ /= Universal_Fixed
5631 and then Typ /= Any_Fixed
5632 and then not Is_Generic_Type (Typ)
5635 Val : constant Ureal := Realval (N);
5636 Cintr : constant Ureal := Val / Small_Value (Typ);
5637 Cint : constant Uint := UR_Trunc (Cintr);
5638 Den : constant Uint := Norm_Den (Cintr);
5642 -- Case of literal is not an exact multiple of the Small
5646 -- For a source program literal for a decimal fixed-point
5647 -- type, this is statically illegal (RM 4.9(36)).
5649 if Is_Decimal_Fixed_Point_Type (Typ)
5650 and then Actual_Typ = Universal_Real
5651 and then Comes_From_Source (N)
5653 Error_Msg_N ("value has extraneous low order digits", N);
5656 -- Replace literal by a value that is the exact representation
5657 -- of a value of the type, i.e. a multiple of the small value,
5658 -- by truncation, since Machine_Rounds is false for all GNAT
5659 -- fixed-point types (RM 4.9(38)).
5661 Stat := Is_Static_Expression (N);
5663 Make_Real_Literal (Sloc (N),
5664 Realval => Small_Value (Typ) * Cint));
5666 Set_Is_Static_Expression (N, Stat);
5669 -- In all cases, set the corresponding integer field
5671 Set_Corresponding_Integer_Value (N, Cint);
5675 -- Now replace the actual type by the expected type as usual
5678 Eval_Real_Literal (N);
5679 end Resolve_Real_Literal;
5681 -----------------------
5682 -- Resolve_Reference --
5683 -----------------------
5685 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
5686 P : constant Node_Id := Prefix (N);
5689 -- Replace general access with specific type
5691 if Ekind (Etype (N)) = E_Allocator_Type then
5692 Set_Etype (N, Base_Type (Typ));
5695 Resolve (P, Designated_Type (Etype (N)));
5697 -- If we are taking the reference of a volatile entity, then treat
5698 -- it as a potential modification of this entity. This is much too
5699 -- conservative, but is necessary because remove side effects can
5700 -- result in transformations of normal assignments into reference
5701 -- sequences that otherwise fail to notice the modification.
5703 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
5704 Note_Possible_Modification (P);
5706 end Resolve_Reference;
5708 --------------------------------
5709 -- Resolve_Selected_Component --
5710 --------------------------------
5712 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
5714 Comp1 : Entity_Id := Empty; -- prevent junk warning
5715 P : constant Node_Id := Prefix (N);
5716 S : constant Node_Id := Selector_Name (N);
5717 T : Entity_Id := Etype (P);
5719 I1 : Interp_Index := 0; -- prevent junk warning
5724 function Init_Component return Boolean;
5725 -- Check whether this is the initialization of a component within an
5726 -- init proc (by assignment or call to another init proc). If true,
5727 -- there is no need for a discriminant check.
5729 --------------------
5730 -- Init_Component --
5731 --------------------
5733 function Init_Component return Boolean is
5735 return Inside_Init_Proc
5736 and then Nkind (Prefix (N)) = N_Identifier
5737 and then Chars (Prefix (N)) = Name_uInit
5738 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
5741 -- Start of processing for Resolve_Selected_Component
5744 if Is_Overloaded (P) then
5746 -- Use the context type to select the prefix that has a selector
5747 -- of the correct name and type.
5750 Get_First_Interp (P, I, It);
5752 Search : while Present (It.Typ) loop
5753 if Is_Access_Type (It.Typ) then
5754 T := Designated_Type (It.Typ);
5759 if Is_Record_Type (T) then
5760 Comp := First_Entity (T);
5762 while Present (Comp) loop
5764 if Chars (Comp) = Chars (S)
5765 and then Covers (Etype (Comp), Typ)
5774 It := Disambiguate (P, I1, I, Any_Type);
5776 if It = No_Interp then
5778 ("ambiguous prefix for selected component", N);
5785 if Scope (Comp1) /= It1.Typ then
5787 -- Resolution chooses the new interpretation.
5788 -- Find the component with the right name.
5790 Comp1 := First_Entity (It1.Typ);
5792 while Present (Comp1)
5793 and then Chars (Comp1) /= Chars (S)
5795 Comp1 := Next_Entity (Comp1);
5804 Comp := Next_Entity (Comp);
5809 Get_Next_Interp (I, It);
5812 Resolve (P, It1.Typ);
5814 Set_Entity (S, Comp1);
5817 -- Resolve prefix with its type
5822 -- Deal with access type case
5824 if Is_Access_Type (Etype (P)) then
5825 Apply_Access_Check (N);
5826 T := Designated_Type (Etype (P));
5831 if Has_Discriminants (T)
5832 and then (Ekind (Entity (S)) = E_Component
5834 Ekind (Entity (S)) = E_Discriminant)
5835 and then Present (Original_Record_Component (Entity (S)))
5836 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
5837 and then Present (Discriminant_Checking_Func
5838 (Original_Record_Component (Entity (S))))
5839 and then not Discriminant_Checks_Suppressed (T)
5840 and then not Init_Component
5842 Set_Do_Discriminant_Check (N);
5845 if Ekind (Entity (S)) = E_Void then
5846 Error_Msg_N ("premature use of component", S);
5849 -- If the prefix is a record conversion, this may be a renamed
5850 -- discriminant whose bounds differ from those of the original
5851 -- one, so we must ensure that a range check is performed.
5853 if Nkind (P) = N_Type_Conversion
5854 and then Ekind (Entity (S)) = E_Discriminant
5855 and then Is_Discrete_Type (Typ)
5857 Set_Etype (N, Base_Type (Typ));
5860 -- Note: No Eval processing is required, because the prefix is of a
5861 -- record type, or protected type, and neither can possibly be static.
5863 end Resolve_Selected_Component;
5869 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
5870 B_Typ : constant Entity_Id := Base_Type (Typ);
5871 L : constant Node_Id := Left_Opnd (N);
5872 R : constant Node_Id := Right_Opnd (N);
5875 -- We do the resolution using the base type, because intermediate values
5876 -- in expressions always are of the base type, not a subtype of it.
5879 Resolve (R, Standard_Natural);
5881 Check_Unset_Reference (L);
5882 Check_Unset_Reference (R);
5884 Set_Etype (N, B_Typ);
5885 Generate_Operator_Reference (N, B_Typ);
5889 ---------------------------
5890 -- Resolve_Short_Circuit --
5891 ---------------------------
5893 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
5894 B_Typ : constant Entity_Id := Base_Type (Typ);
5895 L : constant Node_Id := Left_Opnd (N);
5896 R : constant Node_Id := Right_Opnd (N);
5902 Check_Unset_Reference (L);
5903 Check_Unset_Reference (R);
5905 Set_Etype (N, B_Typ);
5906 Eval_Short_Circuit (N);
5907 end Resolve_Short_Circuit;
5913 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
5914 Name : constant Node_Id := Prefix (N);
5915 Drange : constant Node_Id := Discrete_Range (N);
5916 Array_Type : Entity_Id := Empty;
5920 if Is_Overloaded (Name) then
5922 -- Use the context type to select the prefix that yields the
5923 -- correct array type.
5927 I1 : Interp_Index := 0;
5929 P : constant Node_Id := Prefix (N);
5930 Found : Boolean := False;
5933 Get_First_Interp (P, I, It);
5935 while Present (It.Typ) loop
5937 if (Is_Array_Type (It.Typ)
5938 and then Covers (Typ, It.Typ))
5939 or else (Is_Access_Type (It.Typ)
5940 and then Is_Array_Type (Designated_Type (It.Typ))
5941 and then Covers (Typ, Designated_Type (It.Typ)))
5944 It := Disambiguate (P, I1, I, Any_Type);
5946 if It = No_Interp then
5947 Error_Msg_N ("ambiguous prefix for slicing", N);
5952 Array_Type := It.Typ;
5957 Array_Type := It.Typ;
5962 Get_Next_Interp (I, It);
5967 Array_Type := Etype (Name);
5970 Resolve (Name, Array_Type);
5972 if Is_Access_Type (Array_Type) then
5973 Apply_Access_Check (N);
5974 Array_Type := Designated_Type (Array_Type);
5976 elsif Is_Entity_Name (Name)
5977 or else (Nkind (Name) = N_Function_Call
5978 and then not Is_Constrained (Etype (Name)))
5980 Array_Type := Get_Actual_Subtype (Name);
5983 -- If name was overloaded, set slice type correctly now
5985 Set_Etype (N, Array_Type);
5987 -- If the range is specified by a subtype mark, no resolution
5990 if not Is_Entity_Name (Drange) then
5991 Index := First_Index (Array_Type);
5992 Resolve (Drange, Base_Type (Etype (Index)));
5994 if Nkind (Drange) = N_Range then
5995 Apply_Range_Check (Drange, Etype (Index));
5999 Set_Slice_Subtype (N);
6003 ----------------------------
6004 -- Resolve_String_Literal --
6005 ----------------------------
6007 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
6008 C_Typ : constant Entity_Id := Component_Type (Typ);
6009 R_Typ : constant Entity_Id := Root_Type (C_Typ);
6010 Loc : constant Source_Ptr := Sloc (N);
6011 Str : constant String_Id := Strval (N);
6012 Strlen : constant Nat := String_Length (Str);
6013 Subtype_Id : Entity_Id;
6014 Need_Check : Boolean;
6017 -- For a string appearing in a concatenation, defer creation of the
6018 -- string_literal_subtype until the end of the resolution of the
6019 -- concatenation, because the literal may be constant-folded away.
6020 -- This is a useful optimization for long concatenation expressions.
6022 -- If the string is an aggregate built for a single character (which
6023 -- happens in a non-static context) or a is null string to which special
6024 -- checks may apply, we build the subtype. Wide strings must also get
6025 -- a string subtype if they come from a one character aggregate. Strings
6026 -- generated by attributes might be static, but it is often hard to
6027 -- determine whether the enclosing context is static, so we generate
6028 -- subtypes for them as well, thus losing some rarer optimizations ???
6029 -- Same for strings that come from a static conversion.
6032 (Strlen = 0 and then Typ /= Standard_String)
6033 or else Nkind (Parent (N)) /= N_Op_Concat
6034 or else (N /= Left_Opnd (Parent (N))
6035 and then N /= Right_Opnd (Parent (N)))
6036 or else (Typ = Standard_Wide_String
6037 and then Nkind (Original_Node (N)) /= N_String_Literal);
6039 -- If the resolving type is itself a string literal subtype, we
6040 -- can just reuse it, since there is no point in creating another.
6042 if Ekind (Typ) = E_String_Literal_Subtype then
6045 elsif Nkind (Parent (N)) = N_Op_Concat
6046 and then not Need_Check
6047 and then Nkind (Original_Node (N)) /= N_Character_Literal
6048 and then Nkind (Original_Node (N)) /= N_Attribute_Reference
6049 and then Nkind (Original_Node (N)) /= N_Qualified_Expression
6050 and then Nkind (Original_Node (N)) /= N_Type_Conversion
6054 -- Otherwise we must create a string literal subtype. Note that the
6055 -- whole idea of string literal subtypes is simply to avoid the need
6056 -- for building a full fledged array subtype for each literal.
6058 Set_String_Literal_Subtype (N, Typ);
6059 Subtype_Id := Etype (N);
6062 if Nkind (Parent (N)) /= N_Op_Concat
6065 Set_Etype (N, Subtype_Id);
6066 Eval_String_Literal (N);
6069 if Is_Limited_Composite (Typ)
6070 or else Is_Private_Composite (Typ)
6072 Error_Msg_N ("string literal not available for private array", N);
6073 Set_Etype (N, Any_Type);
6077 -- The validity of a null string has been checked in the
6078 -- call to Eval_String_Literal.
6083 -- Always accept string literal with component type Any_Character,
6084 -- which occurs in error situations and in comparisons of literals,
6085 -- both of which should accept all literals.
6087 elsif R_Typ = Any_Character then
6090 -- If the type is bit-packed, then we always tranform the string
6091 -- literal into a full fledged aggregate.
6093 elsif Is_Bit_Packed_Array (Typ) then
6096 -- Deal with cases of Wide_String and String
6099 -- For Standard.Wide_String, or any other type whose component
6100 -- type is Standard.Wide_Character, we know that all the
6101 -- characters in the string must be acceptable, since the parser
6102 -- accepted the characters as valid character literals.
6104 if R_Typ = Standard_Wide_Character then
6107 -- For the case of Standard.String, or any other type whose
6108 -- component type is Standard.Character, we must make sure that
6109 -- there are no wide characters in the string, i.e. that it is
6110 -- entirely composed of characters in range of type String.
6112 -- If the string literal is the result of a static concatenation,
6113 -- the test has already been performed on the components, and need
6116 elsif R_Typ = Standard_Character
6117 and then Nkind (Original_Node (N)) /= N_Op_Concat
6119 for J in 1 .. Strlen loop
6120 if not In_Character_Range (Get_String_Char (Str, J)) then
6122 -- If we are out of range, post error. This is one of the
6123 -- very few places that we place the flag in the middle of
6124 -- a token, right under the offending wide character.
6127 ("literal out of range of type Character",
6128 Source_Ptr (Int (Loc) + J));
6133 -- If the root type is not a standard character, then we will convert
6134 -- the string into an aggregate and will let the aggregate code do
6142 -- See if the component type of the array corresponding to the
6143 -- string has compile time known bounds. If yes we can directly
6144 -- check whether the evaluation of the string will raise constraint
6145 -- error. Otherwise we need to transform the string literal into
6146 -- the corresponding character aggregate and let the aggregate
6147 -- code do the checking.
6149 if R_Typ = Standard_Wide_Character
6150 or else R_Typ = Standard_Character
6152 -- Check for the case of full range, where we are definitely OK
6154 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
6158 -- Here the range is not the complete base type range, so check
6161 Comp_Typ_Lo : constant Node_Id :=
6162 Type_Low_Bound (Component_Type (Typ));
6163 Comp_Typ_Hi : constant Node_Id :=
6164 Type_High_Bound (Component_Type (Typ));
6169 if Compile_Time_Known_Value (Comp_Typ_Lo)
6170 and then Compile_Time_Known_Value (Comp_Typ_Hi)
6172 for J in 1 .. Strlen loop
6173 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
6175 if Char_Val < Expr_Value (Comp_Typ_Lo)
6176 or else Char_Val > Expr_Value (Comp_Typ_Hi)
6178 Apply_Compile_Time_Constraint_Error
6179 (N, "character out of range?", CE_Range_Check_Failed,
6180 Loc => Source_Ptr (Int (Loc) + J));
6190 -- If we got here we meed to transform the string literal into the
6191 -- equivalent qualified positional array aggregate. This is rather
6192 -- heavy artillery for this situation, but it is hard work to avoid.
6195 Lits : constant List_Id := New_List;
6196 P : Source_Ptr := Loc + 1;
6200 -- Build the character literals, we give them source locations
6201 -- that correspond to the string positions, which is a bit tricky
6202 -- given the possible presence of wide character escape sequences.
6204 for J in 1 .. Strlen loop
6205 C := Get_String_Char (Str, J);
6206 Set_Character_Literal_Name (C);
6209 Make_Character_Literal (P, Name_Find, C));
6211 if In_Character_Range (C) then
6214 -- Should we have a call to Skip_Wide here ???
6222 Make_Qualified_Expression (Loc,
6223 Subtype_Mark => New_Reference_To (Typ, Loc),
6225 Make_Aggregate (Loc, Expressions => Lits)));
6227 Analyze_And_Resolve (N, Typ);
6229 end Resolve_String_Literal;
6231 -----------------------------
6232 -- Resolve_Subprogram_Info --
6233 -----------------------------
6235 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
6238 end Resolve_Subprogram_Info;
6240 -----------------------------
6241 -- Resolve_Type_Conversion --
6242 -----------------------------
6244 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
6245 Target_Type : constant Entity_Id := Etype (N);
6246 Conv_OK : constant Boolean := Conversion_OK (N);
6248 Opnd_Type : Entity_Id;
6254 Operand := Expression (N);
6257 and then not Valid_Conversion (N, Target_Type, Operand)
6262 if Etype (Operand) = Any_Fixed then
6264 -- Mixed-mode operation involving a literal. Context must be a fixed
6265 -- type which is applied to the literal subsequently.
6267 if Is_Fixed_Point_Type (Typ) then
6268 Set_Etype (Operand, Universal_Real);
6270 elsif Is_Numeric_Type (Typ)
6271 and then (Nkind (Operand) = N_Op_Multiply
6272 or else Nkind (Operand) = N_Op_Divide)
6273 and then (Etype (Right_Opnd (Operand)) = Universal_Real
6274 or else Etype (Left_Opnd (Operand)) = Universal_Real)
6276 if Unique_Fixed_Point_Type (N) = Any_Type then
6277 return; -- expression is ambiguous.
6279 Set_Etype (Operand, Standard_Duration);
6282 if Etype (Right_Opnd (Operand)) = Universal_Real then
6283 Rop := New_Copy_Tree (Right_Opnd (Operand));
6285 Rop := New_Copy_Tree (Left_Opnd (Operand));
6288 Resolve (Rop, Standard_Long_Long_Float);
6290 if Realval (Rop) /= Ureal_0
6291 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
6293 Error_Msg_N ("universal real operand can only be interpreted?",
6295 Error_Msg_N ("\as Duration, and will lose precision?", Rop);
6298 elsif Is_Numeric_Type (Typ)
6299 and then Nkind (Operand) in N_Op
6300 and then Unique_Fixed_Point_Type (N) /= Any_Type
6302 Set_Etype (Operand, Standard_Duration);
6305 Error_Msg_N ("invalid context for mixed mode operation", N);
6306 Set_Etype (Operand, Any_Type);
6311 Opnd_Type := Etype (Operand);
6314 -- Note: we do the Eval_Type_Conversion call before applying the
6315 -- required checks for a subtype conversion. This is important,
6316 -- since both are prepared under certain circumstances to change
6317 -- the type conversion to a constraint error node, but in the case
6318 -- of Eval_Type_Conversion this may reflect an illegality in the
6319 -- static case, and we would miss the illegality (getting only a
6320 -- warning message), if we applied the type conversion checks first.
6322 Eval_Type_Conversion (N);
6324 -- If after evaluation, we still have a type conversion, then we
6325 -- may need to apply checks required for a subtype conversion.
6327 -- Skip these type conversion checks if universal fixed operands
6328 -- operands involved, since range checks are handled separately for
6329 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
6331 if Nkind (N) = N_Type_Conversion
6332 and then not Is_Generic_Type (Root_Type (Target_Type))
6333 and then Target_Type /= Universal_Fixed
6334 and then Opnd_Type /= Universal_Fixed
6336 Apply_Type_Conversion_Checks (N);
6339 -- Issue warning for conversion of simple object to its own type
6340 -- We have to test the original nodes, since they may have been
6341 -- rewritten by various optimizations.
6343 Orig_N := Original_Node (N);
6345 if Warn_On_Redundant_Constructs
6346 and then Comes_From_Source (Orig_N)
6347 and then Nkind (Orig_N) = N_Type_Conversion
6348 and then not In_Instance
6350 Orig_N := Original_Node (Expression (Orig_N));
6351 Orig_T := Target_Type;
6353 -- If the node is part of a larger expression, the Target_Type
6354 -- may not be the original type of the node if the context is a
6355 -- condition. Recover original type to see if conversion is needed.
6357 if Is_Boolean_Type (Orig_T)
6358 and then Nkind (Parent (N)) in N_Op
6360 Orig_T := Etype (Parent (N));
6363 if Is_Entity_Name (Orig_N)
6364 and then Etype (Entity (Orig_N)) = Orig_T
6367 ("?useless conversion, & has this type", N, Entity (Orig_N));
6370 end Resolve_Type_Conversion;
6372 ----------------------
6373 -- Resolve_Unary_Op --
6374 ----------------------
6376 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
6377 B_Typ : constant Entity_Id := Base_Type (Typ);
6378 R : constant Node_Id := Right_Opnd (N);
6384 -- Generate warning for expressions like abs (x mod 2)
6386 if Warn_On_Redundant_Constructs
6387 and then Nkind (N) = N_Op_Abs
6389 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
6391 if OK and then Hi >= Lo and then Lo >= 0 then
6393 ("?abs applied to known non-negative value has no effect", N);
6397 -- Generate warning for expressions like -5 mod 3
6399 if Paren_Count (N) = 0
6400 and then Nkind (N) = N_Op_Minus
6401 and then Nkind (Right_Opnd (N)) = N_Op_Mod
6402 and then Comes_From_Source (N)
6405 ("?unary minus expression should be parenthesized here", N);
6408 if Comes_From_Source (N)
6409 and then Ekind (Entity (N)) = E_Function
6410 and then Is_Imported (Entity (N))
6411 and then Is_Intrinsic_Subprogram (Entity (N))
6413 Resolve_Intrinsic_Unary_Operator (N, Typ);
6417 if Etype (R) = Universal_Integer
6418 or else Etype (R) = Universal_Real
6420 Check_For_Visible_Operator (N, B_Typ);
6423 Set_Etype (N, B_Typ);
6426 Check_Unset_Reference (R);
6427 Generate_Operator_Reference (N, B_Typ);
6430 -- Set overflow checking bit. Much cleverer code needed here eventually
6431 -- and perhaps the Resolve routines should be separated for the various
6432 -- arithmetic operations, since they will need different processing ???
6434 if Nkind (N) in N_Op then
6435 if not Overflow_Checks_Suppressed (Etype (N)) then
6436 Enable_Overflow_Check (N);
6439 end Resolve_Unary_Op;
6441 ----------------------------------
6442 -- Resolve_Unchecked_Expression --
6443 ----------------------------------
6445 procedure Resolve_Unchecked_Expression
6450 Resolve (Expression (N), Typ, Suppress => All_Checks);
6452 end Resolve_Unchecked_Expression;
6454 ---------------------------------------
6455 -- Resolve_Unchecked_Type_Conversion --
6456 ---------------------------------------
6458 procedure Resolve_Unchecked_Type_Conversion
6462 pragma Warnings (Off, Typ);
6464 Operand : constant Node_Id := Expression (N);
6465 Opnd_Type : constant Entity_Id := Etype (Operand);
6468 -- Resolve operand using its own type.
6470 Resolve (Operand, Opnd_Type);
6471 Eval_Unchecked_Conversion (N);
6473 end Resolve_Unchecked_Type_Conversion;
6475 ------------------------------
6476 -- Rewrite_Operator_As_Call --
6477 ------------------------------
6479 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
6480 Loc : constant Source_Ptr := Sloc (N);
6481 Actuals : constant List_Id := New_List;
6485 if Nkind (N) in N_Binary_Op then
6486 Append (Left_Opnd (N), Actuals);
6489 Append (Right_Opnd (N), Actuals);
6492 Make_Function_Call (Sloc => Loc,
6493 Name => New_Occurrence_Of (Nam, Loc),
6494 Parameter_Associations => Actuals);
6496 Preserve_Comes_From_Source (New_N, N);
6497 Preserve_Comes_From_Source (Name (New_N), N);
6499 Set_Etype (N, Etype (Nam));
6500 end Rewrite_Operator_As_Call;
6502 ------------------------------
6503 -- Rewrite_Renamed_Operator --
6504 ------------------------------
6506 procedure Rewrite_Renamed_Operator
6511 Nam : constant Name_Id := Chars (Op);
6512 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
6516 -- Rewrite the operator node using the real operator, not its
6517 -- renaming. Exclude user-defined intrinsic operations of the same
6518 -- name, which are treated separately and rewritten as calls.
6520 if Ekind (Op) /= E_Function
6521 or else Chars (N) /= Nam
6523 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
6524 Set_Chars (Op_Node, Nam);
6525 Set_Etype (Op_Node, Etype (N));
6526 Set_Entity (Op_Node, Op);
6527 Set_Right_Opnd (Op_Node, Right_Opnd (N));
6529 -- Indicate that both the original entity and its renaming
6530 -- are referenced at this point.
6532 Generate_Reference (Entity (N), N);
6533 Generate_Reference (Op, N);
6536 Set_Left_Opnd (Op_Node, Left_Opnd (N));
6539 Rewrite (N, Op_Node);
6541 -- If the context type is private, add the appropriate conversions
6542 -- so that the operator is applied to the full view. This is done
6543 -- in the routines that resolve intrinsic operators,
6545 if Is_Intrinsic_Subprogram (Op)
6546 and then Is_Private_Type (Typ)
6549 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
6550 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
6551 Resolve_Intrinsic_Operator (N, Typ);
6553 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
6554 Resolve_Intrinsic_Unary_Operator (N, Typ);
6561 elsif Ekind (Op) = E_Function
6562 and then Is_Intrinsic_Subprogram (Op)
6564 -- Operator renames a user-defined operator of the same name. Use
6565 -- the original operator in the node, which is the one that gigi
6569 Set_Is_Overloaded (N, False);
6571 end Rewrite_Renamed_Operator;
6573 -----------------------
6574 -- Set_Slice_Subtype --
6575 -----------------------
6577 -- Build an implicit subtype declaration to represent the type delivered
6578 -- by the slice. This is an abbreviated version of an array subtype. We
6579 -- define an index subtype for the slice, using either the subtype name
6580 -- or the discrete range of the slice. To be consistent with index usage
6581 -- elsewhere, we create a list header to hold the single index. This list
6582 -- is not otherwise attached to the syntax tree.
6584 procedure Set_Slice_Subtype (N : Node_Id) is
6585 Loc : constant Source_Ptr := Sloc (N);
6586 Index_List : constant List_Id := New_List;
6588 Index_Subtype : Entity_Id;
6589 Index_Type : Entity_Id;
6590 Slice_Subtype : Entity_Id;
6591 Drange : constant Node_Id := Discrete_Range (N);
6594 if Is_Entity_Name (Drange) then
6595 Index_Subtype := Entity (Drange);
6598 -- We force the evaluation of a range. This is definitely needed in
6599 -- the renamed case, and seems safer to do unconditionally. Note in
6600 -- any case that since we will create and insert an Itype referring
6601 -- to this range, we must make sure any side effect removal actions
6602 -- are inserted before the Itype definition.
6604 if Nkind (Drange) = N_Range then
6605 Force_Evaluation (Low_Bound (Drange));
6606 Force_Evaluation (High_Bound (Drange));
6609 Index_Type := Base_Type (Etype (Drange));
6611 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
6613 Set_Scalar_Range (Index_Subtype, Drange);
6614 Set_Etype (Index_Subtype, Index_Type);
6615 Set_Size_Info (Index_Subtype, Index_Type);
6616 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
6619 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
6621 Index := New_Occurrence_Of (Index_Subtype, Loc);
6622 Set_Etype (Index, Index_Subtype);
6623 Append (Index, Index_List);
6625 Set_First_Index (Slice_Subtype, Index);
6626 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
6627 Set_Is_Constrained (Slice_Subtype, True);
6628 Init_Size_Align (Slice_Subtype);
6630 Check_Compile_Time_Size (Slice_Subtype);
6632 -- The Etype of the existing Slice node is reset to this slice
6633 -- subtype. Its bounds are obtained from its first index.
6635 Set_Etype (N, Slice_Subtype);
6637 -- In the packed case, this must be immediately frozen
6639 -- Couldn't we always freeze here??? and if we did, then the above
6640 -- call to Check_Compile_Time_Size could be eliminated, which would
6641 -- be nice, because then that routine could be made private to Freeze.
6643 if Is_Packed (Slice_Subtype) and not In_Default_Expression then
6644 Freeze_Itype (Slice_Subtype, N);
6647 end Set_Slice_Subtype;
6649 --------------------------------
6650 -- Set_String_Literal_Subtype --
6651 --------------------------------
6653 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
6654 Subtype_Id : Entity_Id;
6657 if Nkind (N) /= N_String_Literal then
6660 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
6663 Set_String_Literal_Length (Subtype_Id, UI_From_Int
6664 (String_Length (Strval (N))));
6665 Set_Etype (Subtype_Id, Base_Type (Typ));
6666 Set_Is_Constrained (Subtype_Id);
6668 -- The low bound is set from the low bound of the corresponding
6669 -- index type. Note that we do not store the high bound in the
6670 -- string literal subtype, but it can be deduced if necssary
6671 -- from the length and the low bound.
6673 Set_String_Literal_Low_Bound
6674 (Subtype_Id, Type_Low_Bound (Etype (First_Index (Typ))));
6676 Set_Etype (N, Subtype_Id);
6677 end Set_String_Literal_Subtype;
6679 -----------------------------
6680 -- Unique_Fixed_Point_Type --
6681 -----------------------------
6683 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
6684 T1 : Entity_Id := Empty;
6689 procedure Fixed_Point_Error;
6690 -- If true ambiguity, give details.
6692 procedure Fixed_Point_Error is
6694 Error_Msg_N ("ambiguous universal_fixed_expression", N);
6695 Error_Msg_NE ("\possible interpretation as}", N, T1);
6696 Error_Msg_NE ("\possible interpretation as}", N, T2);
6697 end Fixed_Point_Error;
6700 -- The operations on Duration are visible, so Duration is always a
6701 -- possible interpretation.
6703 T1 := Standard_Duration;
6705 -- Look for fixed-point types in enclosing scopes.
6707 Scop := Current_Scope;
6708 while Scop /= Standard_Standard loop
6709 T2 := First_Entity (Scop);
6711 while Present (T2) loop
6712 if Is_Fixed_Point_Type (T2)
6713 and then Current_Entity (T2) = T2
6714 and then Scope (Base_Type (T2)) = Scop
6716 if Present (T1) then
6727 Scop := Scope (Scop);
6730 -- Look for visible fixed type declarations in the context.
6732 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
6733 while Present (Item) loop
6734 if Nkind (Item) = N_With_Clause then
6735 Scop := Entity (Name (Item));
6736 T2 := First_Entity (Scop);
6738 while Present (T2) loop
6739 if Is_Fixed_Point_Type (T2)
6740 and then Scope (Base_Type (T2)) = Scop
6741 and then (Is_Potentially_Use_Visible (T2)
6742 or else In_Use (T2))
6744 if Present (T1) then
6759 if Nkind (N) = N_Real_Literal then
6760 Error_Msg_NE ("real literal interpreted as }?", N, T1);
6763 Error_Msg_NE ("universal_fixed expression interpreted as }?", N, T1);
6767 end Unique_Fixed_Point_Type;
6769 ----------------------
6770 -- Valid_Conversion --
6771 ----------------------
6773 function Valid_Conversion
6776 Operand : Node_Id) return Boolean
6778 Target_Type : constant Entity_Id := Base_Type (Target);
6779 Opnd_Type : Entity_Id := Etype (Operand);
6781 function Conversion_Check
6783 Msg : String) return Boolean;
6784 -- Little routine to post Msg if Valid is False, returns Valid value
6786 function Valid_Tagged_Conversion
6787 (Target_Type : Entity_Id;
6788 Opnd_Type : Entity_Id) return Boolean;
6789 -- Specifically test for validity of tagged conversions
6791 ----------------------
6792 -- Conversion_Check --
6793 ----------------------
6795 function Conversion_Check
6797 Msg : String) return Boolean
6801 Error_Msg_N (Msg, Operand);
6805 end Conversion_Check;
6807 -----------------------------
6808 -- Valid_Tagged_Conversion --
6809 -----------------------------
6811 function Valid_Tagged_Conversion
6812 (Target_Type : Entity_Id;
6813 Opnd_Type : Entity_Id) return Boolean
6816 -- Upward conversions are allowed (RM 4.6(22)).
6818 if Covers (Target_Type, Opnd_Type)
6819 or else Is_Ancestor (Target_Type, Opnd_Type)
6823 -- Downward conversion are allowed if the operand is
6824 -- is class-wide (RM 4.6(23)).
6826 elsif Is_Class_Wide_Type (Opnd_Type)
6827 and then Covers (Opnd_Type, Target_Type)
6831 elsif Covers (Opnd_Type, Target_Type)
6832 or else Is_Ancestor (Opnd_Type, Target_Type)
6835 Conversion_Check (False,
6836 "downward conversion of tagged objects not allowed");
6839 ("invalid tagged conversion, not compatible with}",
6840 N, First_Subtype (Opnd_Type));
6843 end Valid_Tagged_Conversion;
6845 -- Start of processing for Valid_Conversion
6848 Check_Parameterless_Call (Operand);
6850 if Is_Overloaded (Operand) then
6859 -- Remove procedure calls, which syntactically cannot appear
6860 -- in this context, but which cannot be removed by type checking,
6861 -- because the context does not impose a type.
6863 Get_First_Interp (Operand, I, It);
6865 while Present (It.Typ) loop
6867 if It.Typ = Standard_Void_Type then
6871 Get_Next_Interp (I, It);
6874 Get_First_Interp (Operand, I, It);
6879 Error_Msg_N ("illegal operand in conversion", Operand);
6883 Get_Next_Interp (I, It);
6885 if Present (It.Typ) then
6887 It1 := Disambiguate (Operand, I1, I, Any_Type);
6889 if It1 = No_Interp then
6890 Error_Msg_N ("ambiguous operand in conversion", Operand);
6892 Error_Msg_Sloc := Sloc (It.Nam);
6893 Error_Msg_N ("possible interpretation#!", Operand);
6895 Error_Msg_Sloc := Sloc (N1);
6896 Error_Msg_N ("possible interpretation#!", Operand);
6902 Set_Etype (Operand, It1.Typ);
6903 Opnd_Type := It1.Typ;
6907 if Chars (Current_Scope) = Name_Unchecked_Conversion then
6909 -- This check is dubious, what if there were a user defined
6910 -- scope whose name was Unchecked_Conversion ???
6914 elsif Is_Numeric_Type (Target_Type) then
6915 if Opnd_Type = Universal_Fixed then
6918 elsif (In_Instance or else In_Inlined_Body)
6919 and then not Comes_From_Source (N)
6924 return Conversion_Check (Is_Numeric_Type (Opnd_Type),
6925 "illegal operand for numeric conversion");
6928 elsif Is_Array_Type (Target_Type) then
6929 if not Is_Array_Type (Opnd_Type)
6930 or else Opnd_Type = Any_Composite
6931 or else Opnd_Type = Any_String
6934 ("illegal operand for array conversion", Operand);
6937 elsif Number_Dimensions (Target_Type) /=
6938 Number_Dimensions (Opnd_Type)
6941 ("incompatible number of dimensions for conversion", Operand);
6946 Target_Index : Node_Id := First_Index (Target_Type);
6947 Opnd_Index : Node_Id := First_Index (Opnd_Type);
6949 Target_Index_Type : Entity_Id;
6950 Opnd_Index_Type : Entity_Id;
6952 Target_Comp_Type : constant Entity_Id :=
6953 Component_Type (Target_Type);
6954 Opnd_Comp_Type : constant Entity_Id :=
6955 Component_Type (Opnd_Type);
6958 while Present (Target_Index) and then Present (Opnd_Index) loop
6959 Target_Index_Type := Etype (Target_Index);
6960 Opnd_Index_Type := Etype (Opnd_Index);
6962 if not (Is_Integer_Type (Target_Index_Type)
6963 and then Is_Integer_Type (Opnd_Index_Type))
6964 and then (Root_Type (Target_Index_Type)
6965 /= Root_Type (Opnd_Index_Type))
6968 ("incompatible index types for array conversion",
6973 Next_Index (Target_Index);
6974 Next_Index (Opnd_Index);
6977 if Base_Type (Target_Comp_Type) /=
6978 Base_Type (Opnd_Comp_Type)
6981 ("incompatible component types for array conversion",
6986 Is_Constrained (Target_Comp_Type)
6987 /= Is_Constrained (Opnd_Comp_Type)
6988 or else not Subtypes_Statically_Match
6989 (Target_Comp_Type, Opnd_Comp_Type)
6992 ("component subtypes must statically match", Operand);
7001 elsif (Ekind (Target_Type) = E_General_Access_Type
7002 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
7005 (Is_Access_Type (Opnd_Type)
7006 and then Ekind (Opnd_Type) /=
7007 E_Access_Subprogram_Type
7008 and then Ekind (Opnd_Type) /=
7009 E_Access_Protected_Subprogram_Type,
7010 "must be an access-to-object type")
7012 if Is_Access_Constant (Opnd_Type)
7013 and then not Is_Access_Constant (Target_Type)
7016 ("access-to-constant operand type not allowed", Operand);
7020 -- Check the static accessibility rule of 4.6(17). Note that
7021 -- the check is not enforced when within an instance body, since
7022 -- the RM requires such cases to be caught at run time.
7024 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
7025 if Type_Access_Level (Opnd_Type)
7026 > Type_Access_Level (Target_Type)
7028 -- In an instance, this is a run-time check, but one we
7029 -- know will fail, so generate an appropriate warning.
7030 -- The raise will be generated by Expand_N_Type_Conversion.
7032 if In_Instance_Body then
7034 ("?cannot convert local pointer to non-local access type",
7037 ("?Program_Error will be raised at run time", Operand);
7041 ("cannot convert local pointer to non-local access type",
7046 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type then
7048 -- When the operand is a selected access discriminant
7049 -- the check needs to be made against the level of the
7050 -- object denoted by the prefix of the selected name.
7051 -- (Object_Access_Level handles checking the prefix
7052 -- of the operand for this case.)
7054 if Nkind (Operand) = N_Selected_Component
7055 and then Object_Access_Level (Operand)
7056 > Type_Access_Level (Target_Type)
7058 -- In an instance, this is a run-time check, but one we
7059 -- know will fail, so generate an appropriate warning.
7060 -- The raise will be generated by Expand_N_Type_Conversion.
7062 if In_Instance_Body then
7064 ("?cannot convert access discriminant to non-local" &
7065 " access type", Operand);
7067 ("?Program_Error will be raised at run time", Operand);
7071 ("cannot convert access discriminant to non-local" &
7072 " access type", Operand);
7077 -- The case of a reference to an access discriminant
7078 -- from within a type declaration (which will appear
7079 -- as a discriminal) is always illegal because the
7080 -- level of the discriminant is considered to be
7081 -- deeper than any (namable) access type.
7083 if Is_Entity_Name (Operand)
7084 and then (Ekind (Entity (Operand)) = E_In_Parameter
7085 or else Ekind (Entity (Operand)) = E_Constant)
7086 and then Present (Discriminal_Link (Entity (Operand)))
7089 ("discriminant has deeper accessibility level than target",
7097 Target : constant Entity_Id := Designated_Type (Target_Type);
7098 Opnd : constant Entity_Id := Designated_Type (Opnd_Type);
7101 if Is_Tagged_Type (Target) then
7102 return Valid_Tagged_Conversion (Target, Opnd);
7105 if Base_Type (Target) /= Base_Type (Opnd) then
7107 ("target designated type not compatible with }",
7108 N, Base_Type (Opnd));
7111 elsif not Subtypes_Statically_Match (Target, Opnd)
7112 and then (not Has_Discriminants (Target)
7113 or else Is_Constrained (Target))
7116 ("target designated subtype not compatible with }",
7126 elsif (Ekind (Target_Type) = E_Access_Subprogram_Type
7128 Ekind (Target_Type) = E_Anonymous_Access_Subprogram_Type)
7129 and then Conversion_Check
7130 (Ekind (Base_Type (Opnd_Type)) = E_Access_Subprogram_Type,
7131 "illegal operand for access subprogram conversion")
7133 -- Check that the designated types are subtype conformant
7135 if not Subtype_Conformant (Designated_Type (Opnd_Type),
7136 Designated_Type (Target_Type))
7139 ("operand type is not subtype conformant with target type",
7143 -- Check the static accessibility rule of 4.6(20)
7145 if Type_Access_Level (Opnd_Type) >
7146 Type_Access_Level (Target_Type)
7149 ("operand type has deeper accessibility level than target",
7152 -- Check that if the operand type is declared in a generic body,
7153 -- then the target type must be declared within that same body
7154 -- (enforces last sentence of 4.6(20)).
7156 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
7158 O_Gen : constant Node_Id :=
7159 Enclosing_Generic_Body (Opnd_Type);
7162 Enclosing_Generic_Body (Target_Type);
7165 while Present (T_Gen) and then T_Gen /= O_Gen loop
7166 T_Gen := Enclosing_Generic_Body (T_Gen);
7169 if T_Gen /= O_Gen then
7171 ("target type must be declared in same generic body"
7172 & " as operand type", N);
7179 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
7180 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
7182 -- It is valid to convert from one RAS type to another provided
7183 -- that their specification statically match.
7185 Check_Subtype_Conformant
7187 Designated_Type (Corresponding_Remote_Type (Target_Type)),
7189 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
7194 elsif Is_Tagged_Type (Target_Type) then
7195 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
7197 -- Types derived from the same root type are convertible.
7199 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
7202 -- In an instance, there may be inconsistent views of the same
7203 -- type, or types derived from the same type.
7206 and then Underlying_Type (Target_Type) = Underlying_Type (Opnd_Type)
7210 -- Special check for common access type error case
7212 elsif Ekind (Target_Type) = E_Access_Type
7213 and then Is_Access_Type (Opnd_Type)
7215 Error_Msg_N ("target type must be general access type!", N);
7216 Error_Msg_NE ("add ALL to }!", N, Target_Type);
7221 Error_Msg_NE ("invalid conversion, not compatible with }",
7226 end Valid_Conversion;