1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Debug_A; use Debug_A;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Ch6; use Exp_Ch6;
36 with Exp_Ch7; use Exp_Ch7;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
41 with Itypes; use Itypes;
43 with Lib.Xref; use Lib.Xref;
44 with Namet; use Namet;
45 with Nmake; use Nmake;
46 with Nlists; use Nlists;
48 with Output; use Output;
49 with Restrict; use Restrict;
50 with Rident; use Rident;
51 with Rtsfind; use Rtsfind;
53 with Sem_Aux; use Sem_Aux;
54 with Sem_Aggr; use Sem_Aggr;
55 with Sem_Attr; use Sem_Attr;
56 with Sem_Cat; use Sem_Cat;
57 with Sem_Ch4; use Sem_Ch4;
58 with Sem_Ch6; use Sem_Ch6;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Elab; use Sem_Elab;
65 with Sem_Eval; use Sem_Eval;
66 with Sem_Intr; use Sem_Intr;
67 with Sem_Util; use Sem_Util;
68 with Sem_Type; use Sem_Type;
69 with Sem_Warn; use Sem_Warn;
70 with Sinfo; use Sinfo;
71 with Snames; use Snames;
72 with Stand; use Stand;
73 with Stringt; use Stringt;
74 with Style; use Style;
75 with Targparm; use Targparm;
76 with Tbuild; use Tbuild;
77 with Uintp; use Uintp;
78 with Urealp; use Urealp;
80 package body Sem_Res is
82 -----------------------
83 -- Local Subprograms --
84 -----------------------
86 -- Second pass (top-down) type checking and overload resolution procedures
87 -- Typ is the type required by context. These procedures propagate the
88 -- type information recursively to the descendants of N. If the node
89 -- is not overloaded, its Etype is established in the first pass. If
90 -- overloaded, the Resolve routines set the correct type. For arith.
91 -- operators, the Etype is the base type of the context.
93 -- Note that Resolve_Attribute is separated off in Sem_Attr
95 procedure Check_Discriminant_Use (N : Node_Id);
96 -- Enforce the restrictions on the use of discriminants when constraining
97 -- a component of a discriminated type (record or concurrent type).
99 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
100 -- Given a node for an operator associated with type T, check that
101 -- the operator is visible. Operators all of whose operands are
102 -- universal must be checked for visibility during resolution
103 -- because their type is not determinable based on their operands.
105 procedure Check_Fully_Declared_Prefix
108 -- Check that the type of the prefix of a dereference is not incomplete
110 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
111 -- Given a call node, N, which is known to occur immediately within the
112 -- subprogram being called, determines whether it is a detectable case of
113 -- an infinite recursion, and if so, outputs appropriate messages. Returns
114 -- True if an infinite recursion is detected, and False otherwise.
116 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
117 -- If the type of the object being initialized uses the secondary stack
118 -- directly or indirectly, create a transient scope for the call to the
119 -- init proc. This is because we do not create transient scopes for the
120 -- initialization of individual components within the init proc itself.
121 -- Could be optimized away perhaps?
123 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
124 -- Determine whether E is an access type declared by an access
125 -- declaration, and not an (anonymous) allocator type.
127 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
128 -- Utility to check whether the name in the call is a predefined
129 -- operator, in which case the call is made into an operator node.
130 -- An instance of an intrinsic conversion operation may be given
131 -- an operator name, but is not treated like an operator.
133 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
134 -- If a default expression in entry call N depends on the discriminants
135 -- of the task, it must be replaced with a reference to the discriminant
136 -- of the task being called.
138 procedure Resolve_Op_Concat_Arg
143 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
144 -- concatenation operator. The operand is either of the array type or of
145 -- the component type. If the operand is an aggregate, and the component
146 -- type is composite, this is ambiguous if component type has aggregates.
148 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
149 -- Does the first part of the work of Resolve_Op_Concat
151 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
152 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
153 -- has been resolved. See Resolve_Op_Concat for details.
155 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
156 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
157 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
158 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
159 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
160 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
161 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
162 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
163 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
164 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
165 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
166 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
167 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
168 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
169 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
170 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
171 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
172 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
173 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
174 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
175 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
176 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
177 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
178 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
179 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
180 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
185 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
186 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
188 function Operator_Kind
190 Is_Binary : Boolean) return Node_Kind;
191 -- Utility to map the name of an operator into the corresponding Node. Used
192 -- by other node rewriting procedures.
194 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
195 -- Resolve actuals of call, and add default expressions for missing ones.
196 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
197 -- called subprogram.
199 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
200 -- Called from Resolve_Call, when the prefix denotes an entry or element
201 -- of entry family. Actuals are resolved as for subprograms, and the node
202 -- is rebuilt as an entry call. Also called for protected operations. Typ
203 -- is the context type, which is used when the operation is a protected
204 -- function with no arguments, and the return value is indexed.
206 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
207 -- A call to a user-defined intrinsic operator is rewritten as a call
208 -- to the corresponding predefined operator, with suitable conversions.
210 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
211 -- Ditto, for unary operators (only arithmetic ones)
213 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
214 -- If an operator node resolves to a call to a user-defined operator,
215 -- rewrite the node as a function call.
217 procedure Make_Call_Into_Operator
221 -- Inverse transformation: if an operator is given in functional notation,
222 -- then after resolving the node, transform into an operator node, so
223 -- that operands are resolved properly. Recall that predefined operators
224 -- do not have a full signature and special resolution rules apply.
226 procedure Rewrite_Renamed_Operator
230 -- An operator can rename another, e.g. in an instantiation. In that
231 -- case, the proper operator node must be constructed and resolved.
233 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
234 -- The String_Literal_Subtype is built for all strings that are not
235 -- operands of a static concatenation operation. If the argument is
236 -- not a N_String_Literal node, then the call has no effect.
238 procedure Set_Slice_Subtype (N : Node_Id);
239 -- Build subtype of array type, with the range specified by the slice
241 procedure Simplify_Type_Conversion (N : Node_Id);
242 -- Called after N has been resolved and evaluated, but before range checks
243 -- have been applied. Currently simplifies a combination of floating-point
244 -- to integer conversion and Truncation attribute.
246 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
247 -- A universal_fixed expression in an universal context is unambiguous
248 -- if there is only one applicable fixed point type. Determining whether
249 -- there is only one requires a search over all visible entities, and
250 -- happens only in very pathological cases (see 6115-006).
252 function Valid_Conversion
255 Operand : Node_Id) return Boolean;
256 -- Verify legality rules given in 4.6 (8-23). Target is the target
257 -- type of the conversion, which may be an implicit conversion of
258 -- an actual parameter to an anonymous access type (in which case
259 -- N denotes the actual parameter and N = Operand).
261 -------------------------
262 -- Ambiguous_Character --
263 -------------------------
265 procedure Ambiguous_Character (C : Node_Id) is
269 if Nkind (C) = N_Character_Literal then
270 Error_Msg_N ("ambiguous character literal", C);
272 -- First the ones in Standard
275 ("\\possible interpretation: Character!", C);
277 ("\\possible interpretation: Wide_Character!", C);
279 -- Include Wide_Wide_Character in Ada 2005 mode
281 if Ada_Version >= Ada_05 then
283 ("\\possible interpretation: Wide_Wide_Character!", C);
286 -- Now any other types that match
288 E := Current_Entity (C);
289 while Present (E) loop
290 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
294 end Ambiguous_Character;
296 -------------------------
297 -- Analyze_And_Resolve --
298 -------------------------
300 procedure Analyze_And_Resolve (N : Node_Id) is
304 end Analyze_And_Resolve;
306 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
310 end Analyze_And_Resolve;
312 -- Version withs check(s) suppressed
314 procedure Analyze_And_Resolve
319 Scop : constant Entity_Id := Current_Scope;
322 if Suppress = All_Checks then
324 Svg : constant Suppress_Array := Scope_Suppress;
326 Scope_Suppress := (others => True);
327 Analyze_And_Resolve (N, Typ);
328 Scope_Suppress := Svg;
333 Svg : constant Boolean := Scope_Suppress (Suppress);
336 Scope_Suppress (Suppress) := True;
337 Analyze_And_Resolve (N, Typ);
338 Scope_Suppress (Suppress) := Svg;
342 if Current_Scope /= Scop
343 and then Scope_Is_Transient
345 -- This can only happen if a transient scope was created
346 -- for an inner expression, which will be removed upon
347 -- completion of the analysis of an enclosing construct.
348 -- The transient scope must have the suppress status of
349 -- the enclosing environment, not of this Analyze call.
351 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
354 end Analyze_And_Resolve;
356 procedure Analyze_And_Resolve
360 Scop : constant Entity_Id := Current_Scope;
363 if Suppress = All_Checks then
365 Svg : constant Suppress_Array := Scope_Suppress;
367 Scope_Suppress := (others => True);
368 Analyze_And_Resolve (N);
369 Scope_Suppress := Svg;
374 Svg : constant Boolean := Scope_Suppress (Suppress);
377 Scope_Suppress (Suppress) := True;
378 Analyze_And_Resolve (N);
379 Scope_Suppress (Suppress) := Svg;
383 if Current_Scope /= Scop
384 and then Scope_Is_Transient
386 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
389 end Analyze_And_Resolve;
391 ----------------------------
392 -- Check_Discriminant_Use --
393 ----------------------------
395 procedure Check_Discriminant_Use (N : Node_Id) is
396 PN : constant Node_Id := Parent (N);
397 Disc : constant Entity_Id := Entity (N);
402 -- Any use in a spec-expression is legal
404 if In_Spec_Expression then
407 elsif Nkind (PN) = N_Range then
409 -- Discriminant cannot be used to constrain a scalar type
413 if Nkind (P) = N_Range_Constraint
414 and then Nkind (Parent (P)) = N_Subtype_Indication
415 and then Nkind (Parent (Parent (P))) = N_Component_Definition
417 Error_Msg_N ("discriminant cannot constrain scalar type", N);
419 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
421 -- The following check catches the unusual case where
422 -- a discriminant appears within an index constraint
423 -- that is part of a larger expression within a constraint
424 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
425 -- For now we only check case of record components, and
426 -- note that a similar check should also apply in the
427 -- case of discriminant constraints below. ???
429 -- Note that the check for N_Subtype_Declaration below is to
430 -- detect the valid use of discriminants in the constraints of a
431 -- subtype declaration when this subtype declaration appears
432 -- inside the scope of a record type (which is syntactically
433 -- illegal, but which may be created as part of derived type
434 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
437 if Ekind (Current_Scope) = E_Record_Type
438 and then Scope (Disc) = Current_Scope
440 (Nkind (Parent (P)) = N_Subtype_Indication
442 Nkind_In (Parent (Parent (P)), N_Component_Definition,
443 N_Subtype_Declaration)
444 and then Paren_Count (N) = 0)
447 ("discriminant must appear alone in component constraint", N);
451 -- Detect a common error:
453 -- type R (D : Positive := 100) is record
454 -- Name : String (1 .. D);
457 -- The default value causes an object of type R to be allocated
458 -- with room for Positive'Last characters. The RM does not mandate
459 -- the allocation of the maximum size, but that is what GNAT does
460 -- so we should warn the programmer that there is a problem.
462 Check_Large : declare
468 function Large_Storage_Type (T : Entity_Id) return Boolean;
469 -- Return True if type T has a large enough range that
470 -- any array whose index type covered the whole range of
471 -- the type would likely raise Storage_Error.
473 ------------------------
474 -- Large_Storage_Type --
475 ------------------------
477 function Large_Storage_Type (T : Entity_Id) return Boolean is
479 -- The type is considered large if its bounds are known at
480 -- compile time and if it requires at least as many bits as
481 -- a Positive to store the possible values.
483 return Compile_Time_Known_Value (Type_Low_Bound (T))
484 and then Compile_Time_Known_Value (Type_High_Bound (T))
486 Minimum_Size (T, Biased => True) >=
487 RM_Size (Standard_Positive);
488 end Large_Storage_Type;
490 -- Start of processing for Check_Large
493 -- Check that the Disc has a large range
495 if not Large_Storage_Type (Etype (Disc)) then
499 -- If the enclosing type is limited, we allocate only the
500 -- default value, not the maximum, and there is no need for
503 if Is_Limited_Type (Scope (Disc)) then
507 -- Check that it is the high bound
509 if N /= High_Bound (PN)
510 or else No (Discriminant_Default_Value (Disc))
515 -- Check the array allows a large range at this bound.
516 -- First find the array
520 if Nkind (SI) /= N_Subtype_Indication then
524 T := Entity (Subtype_Mark (SI));
526 if not Is_Array_Type (T) then
530 -- Next, find the dimension
532 TB := First_Index (T);
533 CB := First (Constraints (P));
535 and then Present (TB)
536 and then Present (CB)
547 -- Now, check the dimension has a large range
549 if not Large_Storage_Type (Etype (TB)) then
553 -- Warn about the danger
556 ("?creation of & object may raise Storage_Error!",
565 -- Legal case is in index or discriminant constraint
567 elsif Nkind_In (PN, N_Index_Or_Discriminant_Constraint,
568 N_Discriminant_Association)
570 if Paren_Count (N) > 0 then
572 ("discriminant in constraint must appear alone", N);
574 elsif Nkind (N) = N_Expanded_Name
575 and then Comes_From_Source (N)
578 ("discriminant must appear alone as a direct name", N);
583 -- Otherwise, context is an expression. It should not be within
584 -- (i.e. a subexpression of) a constraint for a component.
589 while not Nkind_In (P, N_Component_Declaration,
590 N_Subtype_Indication,
598 -- If the discriminant is used in an expression that is a bound
599 -- of a scalar type, an Itype is created and the bounds are attached
600 -- to its range, not to the original subtype indication. Such use
601 -- is of course a double fault.
603 if (Nkind (P) = N_Subtype_Indication
604 and then Nkind_In (Parent (P), N_Component_Definition,
605 N_Derived_Type_Definition)
606 and then D = Constraint (P))
608 -- The constraint itself may be given by a subtype indication,
609 -- rather than by a more common discrete range.
611 or else (Nkind (P) = N_Subtype_Indication
613 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
614 or else Nkind (P) = N_Entry_Declaration
615 or else Nkind (D) = N_Defining_Identifier
618 ("discriminant in constraint must appear alone", N);
621 end Check_Discriminant_Use;
623 --------------------------------
624 -- Check_For_Visible_Operator --
625 --------------------------------
627 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
629 if Is_Invisible_Operator (N, T) then
631 ("operator for} is not directly visible!", N, First_Subtype (T));
632 Error_Msg_N ("use clause would make operation legal!", N);
634 end Check_For_Visible_Operator;
636 ----------------------------------
637 -- Check_Fully_Declared_Prefix --
638 ----------------------------------
640 procedure Check_Fully_Declared_Prefix
645 -- Check that the designated type of the prefix of a dereference is
646 -- not an incomplete type. This cannot be done unconditionally, because
647 -- dereferences of private types are legal in default expressions. This
648 -- case is taken care of in Check_Fully_Declared, called below. There
649 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
651 -- This consideration also applies to similar checks for allocators,
652 -- qualified expressions, and type conversions.
654 -- An additional exception concerns other per-object expressions that
655 -- are not directly related to component declarations, in particular
656 -- representation pragmas for tasks. These will be per-object
657 -- expressions if they depend on discriminants or some global entity.
658 -- If the task has access discriminants, the designated type may be
659 -- incomplete at the point the expression is resolved. This resolution
660 -- takes place within the body of the initialization procedure, where
661 -- the discriminant is replaced by its discriminal.
663 if Is_Entity_Name (Pref)
664 and then Ekind (Entity (Pref)) = E_In_Parameter
668 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
669 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
670 -- Analyze_Object_Renaming, and Freeze_Entity.
672 elsif Ada_Version >= Ada_05
673 and then Is_Entity_Name (Pref)
674 and then Ekind (Directly_Designated_Type (Etype (Pref))) =
676 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Pref)))
680 Check_Fully_Declared (Typ, Parent (Pref));
682 end Check_Fully_Declared_Prefix;
684 ------------------------------
685 -- Check_Infinite_Recursion --
686 ------------------------------
688 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
692 function Same_Argument_List return Boolean;
693 -- Check whether list of actuals is identical to list of formals
694 -- of called function (which is also the enclosing scope).
696 ------------------------
697 -- Same_Argument_List --
698 ------------------------
700 function Same_Argument_List return Boolean is
706 if not Is_Entity_Name (Name (N)) then
709 Subp := Entity (Name (N));
712 F := First_Formal (Subp);
713 A := First_Actual (N);
714 while Present (F) and then Present (A) loop
715 if not Is_Entity_Name (A)
716 or else Entity (A) /= F
726 end Same_Argument_List;
728 -- Start of processing for Check_Infinite_Recursion
731 -- Special case, if this is a procedure call and is a call to the
732 -- current procedure with the same argument list, then this is for
733 -- sure an infinite recursion and we insert a call to raise SE.
735 if Is_List_Member (N)
736 and then List_Length (List_Containing (N)) = 1
737 and then Same_Argument_List
740 P : constant Node_Id := Parent (N);
742 if Nkind (P) = N_Handled_Sequence_Of_Statements
743 and then Nkind (Parent (P)) = N_Subprogram_Body
744 and then Is_Empty_List (Declarations (Parent (P)))
746 Error_Msg_N ("!?infinite recursion", N);
747 Error_Msg_N ("\!?Storage_Error will be raised at run time", N);
749 Make_Raise_Storage_Error (Sloc (N),
750 Reason => SE_Infinite_Recursion));
756 -- If not that special case, search up tree, quitting if we reach a
757 -- construct (e.g. a conditional) that tells us that this is not a
758 -- case for an infinite recursion warning.
764 -- If no parent, then we were not inside a subprogram, this can for
765 -- example happen when processing certain pragmas in a spec. Just
766 -- return False in this case.
772 -- Done if we get to subprogram body, this is definitely an infinite
773 -- recursion case if we did not find anything to stop us.
775 exit when Nkind (P) = N_Subprogram_Body;
777 -- If appearing in conditional, result is false
779 if Nkind_In (P, N_Or_Else,
786 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
787 and then C /= First (Statements (P))
789 -- If the call is the expression of a return statement and the
790 -- actuals are identical to the formals, it's worth a warning.
791 -- However, we skip this if there is an immediately preceding
792 -- raise statement, since the call is never executed.
794 -- Furthermore, this corresponds to a common idiom:
796 -- function F (L : Thing) return Boolean is
798 -- raise Program_Error;
802 -- for generating a stub function
804 if Nkind (Parent (N)) = N_Simple_Return_Statement
805 and then Same_Argument_List
807 exit when not Is_List_Member (Parent (N));
809 -- OK, return statement is in a statement list, look for raise
815 -- Skip past N_Freeze_Entity nodes generated by expansion
817 Nod := Prev (Parent (N));
819 and then Nkind (Nod) = N_Freeze_Entity
824 -- If no raise statement, give warning
826 exit when Nkind (Nod) /= N_Raise_Statement
828 (Nkind (Nod) not in N_Raise_xxx_Error
829 or else Present (Condition (Nod)));
840 Error_Msg_N ("!?possible infinite recursion", N);
841 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
844 end Check_Infinite_Recursion;
846 -------------------------------
847 -- Check_Initialization_Call --
848 -------------------------------
850 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
851 Typ : constant Entity_Id := Etype (First_Formal (Nam));
853 function Uses_SS (T : Entity_Id) return Boolean;
854 -- Check whether the creation of an object of the type will involve
855 -- use of the secondary stack. If T is a record type, this is true
856 -- if the expression for some component uses the secondary stack, e.g.
857 -- through a call to a function that returns an unconstrained value.
858 -- False if T is controlled, because cleanups occur elsewhere.
864 function Uses_SS (T : Entity_Id) return Boolean is
867 Full_Type : Entity_Id := Underlying_Type (T);
870 -- Normally we want to use the underlying type, but if it's not set
871 -- then continue with T.
873 if not Present (Full_Type) then
877 if Is_Controlled (Full_Type) then
880 elsif Is_Array_Type (Full_Type) then
881 return Uses_SS (Component_Type (Full_Type));
883 elsif Is_Record_Type (Full_Type) then
884 Comp := First_Component (Full_Type);
885 while Present (Comp) loop
886 if Ekind (Comp) = E_Component
887 and then Nkind (Parent (Comp)) = N_Component_Declaration
889 -- The expression for a dynamic component may be rewritten
890 -- as a dereference, so retrieve original node.
892 Expr := Original_Node (Expression (Parent (Comp)));
894 -- Return True if the expression is a call to a function
895 -- (including an attribute function such as Image) with
896 -- a result that requires a transient scope.
898 if (Nkind (Expr) = N_Function_Call
899 or else (Nkind (Expr) = N_Attribute_Reference
900 and then Present (Expressions (Expr))))
901 and then Requires_Transient_Scope (Etype (Expr))
905 elsif Uses_SS (Etype (Comp)) then
910 Next_Component (Comp);
920 -- Start of processing for Check_Initialization_Call
923 -- Establish a transient scope if the type needs it
925 if Uses_SS (Typ) then
926 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
928 end Check_Initialization_Call;
930 ------------------------------
931 -- Check_Parameterless_Call --
932 ------------------------------
934 procedure Check_Parameterless_Call (N : Node_Id) is
937 function Prefix_Is_Access_Subp return Boolean;
938 -- If the prefix is of an access_to_subprogram type, the node must be
939 -- rewritten as a call. Ditto if the prefix is overloaded and all its
940 -- interpretations are access to subprograms.
942 ---------------------------
943 -- Prefix_Is_Access_Subp --
944 ---------------------------
946 function Prefix_Is_Access_Subp return Boolean is
951 if not Is_Overloaded (N) then
953 Ekind (Etype (N)) = E_Subprogram_Type
954 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
956 Get_First_Interp (N, I, It);
957 while Present (It.Typ) loop
958 if Ekind (It.Typ) /= E_Subprogram_Type
959 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
964 Get_Next_Interp (I, It);
969 end Prefix_Is_Access_Subp;
971 -- Start of processing for Check_Parameterless_Call
974 -- Defend against junk stuff if errors already detected
976 if Total_Errors_Detected /= 0 then
977 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
979 elsif Nkind (N) in N_Has_Chars
980 and then Chars (N) in Error_Name_Or_No_Name
988 -- If the context expects a value, and the name is a procedure, this is
989 -- most likely a missing 'Access. Don't try to resolve the parameterless
990 -- call, error will be caught when the outer call is analyzed.
992 if Is_Entity_Name (N)
993 and then Ekind (Entity (N)) = E_Procedure
994 and then not Is_Overloaded (N)
996 Nkind_In (Parent (N), N_Parameter_Association,
998 N_Procedure_Call_Statement)
1003 -- Rewrite as call if overloadable entity that is (or could be, in the
1004 -- overloaded case) a function call. If we know for sure that the entity
1005 -- is an enumeration literal, we do not rewrite it.
1007 if (Is_Entity_Name (N)
1008 and then Is_Overloadable (Entity (N))
1009 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1010 or else Is_Overloaded (N)))
1012 -- Rewrite as call if it is an explicit deference of an expression of
1013 -- a subprogram access type, and the subprogram type is not that of a
1014 -- procedure or entry.
1017 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1019 -- Rewrite as call if it is a selected component which is a function,
1020 -- this is the case of a call to a protected function (which may be
1021 -- overloaded with other protected operations).
1024 (Nkind (N) = N_Selected_Component
1025 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1027 ((Ekind (Entity (Selector_Name (N))) = E_Entry
1029 Ekind (Entity (Selector_Name (N))) = E_Procedure)
1030 and then Is_Overloaded (Selector_Name (N)))))
1032 -- If one of the above three conditions is met, rewrite as call.
1033 -- Apply the rewriting only once.
1036 if Nkind (Parent (N)) /= N_Function_Call
1037 or else N /= Name (Parent (N))
1039 Nam := New_Copy (N);
1041 -- If overloaded, overload set belongs to new copy
1043 Save_Interps (N, Nam);
1045 -- Change node to parameterless function call (note that the
1046 -- Parameter_Associations associations field is left set to Empty,
1047 -- its normal default value since there are no parameters)
1049 Change_Node (N, N_Function_Call);
1051 Set_Sloc (N, Sloc (Nam));
1055 elsif Nkind (N) = N_Parameter_Association then
1056 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1058 end Check_Parameterless_Call;
1060 -----------------------------
1061 -- Is_Definite_Access_Type --
1062 -----------------------------
1064 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1065 Btyp : constant Entity_Id := Base_Type (E);
1067 return Ekind (Btyp) = E_Access_Type
1068 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1069 and then Comes_From_Source (Btyp));
1070 end Is_Definite_Access_Type;
1072 ----------------------
1073 -- Is_Predefined_Op --
1074 ----------------------
1076 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1078 return Is_Intrinsic_Subprogram (Nam)
1079 and then not Is_Generic_Instance (Nam)
1080 and then Chars (Nam) in Any_Operator_Name
1081 and then (No (Alias (Nam))
1082 or else Is_Predefined_Op (Alias (Nam)));
1083 end Is_Predefined_Op;
1085 -----------------------------
1086 -- Make_Call_Into_Operator --
1087 -----------------------------
1089 procedure Make_Call_Into_Operator
1094 Op_Name : constant Name_Id := Chars (Op_Id);
1095 Act1 : Node_Id := First_Actual (N);
1096 Act2 : Node_Id := Next_Actual (Act1);
1097 Error : Boolean := False;
1098 Func : constant Entity_Id := Entity (Name (N));
1099 Is_Binary : constant Boolean := Present (Act2);
1101 Opnd_Type : Entity_Id;
1102 Orig_Type : Entity_Id := Empty;
1105 type Kind_Test is access function (E : Entity_Id) return Boolean;
1107 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1108 -- If the operand is not universal, and the operator is given by a
1109 -- expanded name, verify that the operand has an interpretation with
1110 -- a type defined in the given scope of the operator.
1112 function Type_In_P (Test : Kind_Test) return Entity_Id;
1113 -- Find a type of the given class in the package Pack that contains
1116 ---------------------------
1117 -- Operand_Type_In_Scope --
1118 ---------------------------
1120 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1121 Nod : constant Node_Id := Right_Opnd (Op_Node);
1126 if not Is_Overloaded (Nod) then
1127 return Scope (Base_Type (Etype (Nod))) = S;
1130 Get_First_Interp (Nod, I, It);
1131 while Present (It.Typ) loop
1132 if Scope (Base_Type (It.Typ)) = S then
1136 Get_Next_Interp (I, It);
1141 end Operand_Type_In_Scope;
1147 function Type_In_P (Test : Kind_Test) return Entity_Id is
1150 function In_Decl return Boolean;
1151 -- Verify that node is not part of the type declaration for the
1152 -- candidate type, which would otherwise be invisible.
1158 function In_Decl return Boolean is
1159 Decl_Node : constant Node_Id := Parent (E);
1165 if Etype (E) = Any_Type then
1168 elsif No (Decl_Node) then
1173 and then Nkind (N2) /= N_Compilation_Unit
1175 if N2 = Decl_Node then
1186 -- Start of processing for Type_In_P
1189 -- If the context type is declared in the prefix package, this
1190 -- is the desired base type.
1192 if Scope (Base_Type (Typ)) = Pack
1195 return Base_Type (Typ);
1198 E := First_Entity (Pack);
1199 while Present (E) loop
1201 and then not In_Decl
1213 -- Start of processing for Make_Call_Into_Operator
1216 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1221 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1222 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1223 Save_Interps (Act1, Left_Opnd (Op_Node));
1224 Save_Interps (Act2, Right_Opnd (Op_Node));
1225 Act1 := Left_Opnd (Op_Node);
1226 Act2 := Right_Opnd (Op_Node);
1231 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1232 Save_Interps (Act1, Right_Opnd (Op_Node));
1233 Act1 := Right_Opnd (Op_Node);
1236 -- If the operator is denoted by an expanded name, and the prefix is
1237 -- not Standard, but the operator is a predefined one whose scope is
1238 -- Standard, then this is an implicit_operator, inserted as an
1239 -- interpretation by the procedure of the same name. This procedure
1240 -- overestimates the presence of implicit operators, because it does
1241 -- not examine the type of the operands. Verify now that the operand
1242 -- type appears in the given scope. If right operand is universal,
1243 -- check the other operand. In the case of concatenation, either
1244 -- argument can be the component type, so check the type of the result.
1245 -- If both arguments are literals, look for a type of the right kind
1246 -- defined in the given scope. This elaborate nonsense is brought to
1247 -- you courtesy of b33302a. The type itself must be frozen, so we must
1248 -- find the type of the proper class in the given scope.
1250 -- A final wrinkle is the multiplication operator for fixed point
1251 -- types, which is defined in Standard only, and not in the scope of
1252 -- the fixed_point type itself.
1254 if Nkind (Name (N)) = N_Expanded_Name then
1255 Pack := Entity (Prefix (Name (N)));
1257 -- If the entity being called is defined in the given package,
1258 -- it is a renaming of a predefined operator, and known to be
1261 if Scope (Entity (Name (N))) = Pack
1262 and then Pack /= Standard_Standard
1266 -- Visibility does not need to be checked in an instance: if the
1267 -- operator was not visible in the generic it has been diagnosed
1268 -- already, else there is an implicit copy of it in the instance.
1270 elsif In_Instance then
1273 elsif (Op_Name = Name_Op_Multiply
1274 or else Op_Name = Name_Op_Divide)
1275 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1276 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1278 if Pack /= Standard_Standard then
1282 -- Ada 2005, AI-420: Predefined equality on Universal_Access
1285 elsif Ada_Version >= Ada_05
1286 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1287 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1292 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1294 if Op_Name = Name_Op_Concat then
1295 Opnd_Type := Base_Type (Typ);
1297 elsif (Scope (Opnd_Type) = Standard_Standard
1299 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1301 and then not Comes_From_Source (Opnd_Type))
1303 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1306 if Scope (Opnd_Type) = Standard_Standard then
1308 -- Verify that the scope contains a type that corresponds to
1309 -- the given literal. Optimize the case where Pack is Standard.
1311 if Pack /= Standard_Standard then
1313 if Opnd_Type = Universal_Integer then
1314 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1316 elsif Opnd_Type = Universal_Real then
1317 Orig_Type := Type_In_P (Is_Real_Type'Access);
1319 elsif Opnd_Type = Any_String then
1320 Orig_Type := Type_In_P (Is_String_Type'Access);
1322 elsif Opnd_Type = Any_Access then
1323 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1325 elsif Opnd_Type = Any_Composite then
1326 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1328 if Present (Orig_Type) then
1329 if Has_Private_Component (Orig_Type) then
1332 Set_Etype (Act1, Orig_Type);
1335 Set_Etype (Act2, Orig_Type);
1344 Error := No (Orig_Type);
1347 elsif Ekind (Opnd_Type) = E_Allocator_Type
1348 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1352 -- If the type is defined elsewhere, and the operator is not
1353 -- defined in the given scope (by a renaming declaration, e.g.)
1354 -- then this is an error as well. If an extension of System is
1355 -- present, and the type may be defined there, Pack must be
1358 elsif Scope (Opnd_Type) /= Pack
1359 and then Scope (Op_Id) /= Pack
1360 and then (No (System_Aux_Id)
1361 or else Scope (Opnd_Type) /= System_Aux_Id
1362 or else Pack /= Scope (System_Aux_Id))
1364 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1367 Error := not Operand_Type_In_Scope (Pack);
1370 elsif Pack = Standard_Standard
1371 and then not Operand_Type_In_Scope (Standard_Standard)
1378 Error_Msg_Node_2 := Pack;
1380 ("& not declared in&", N, Selector_Name (Name (N)));
1381 Set_Etype (N, Any_Type);
1386 Set_Chars (Op_Node, Op_Name);
1388 if not Is_Private_Type (Etype (N)) then
1389 Set_Etype (Op_Node, Base_Type (Etype (N)));
1391 Set_Etype (Op_Node, Etype (N));
1394 -- If this is a call to a function that renames a predefined equality,
1395 -- the renaming declaration provides a type that must be used to
1396 -- resolve the operands. This must be done now because resolution of
1397 -- the equality node will not resolve any remaining ambiguity, and it
1398 -- assumes that the first operand is not overloaded.
1400 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1401 and then Ekind (Func) = E_Function
1402 and then Is_Overloaded (Act1)
1404 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1405 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1408 Set_Entity (Op_Node, Op_Id);
1409 Generate_Reference (Op_Id, N, ' ');
1411 -- Do rewrite setting Comes_From_Source on the result if the original
1412 -- call came from source. Although it is not strictly the case that the
1413 -- operator as such comes from the source, logically it corresponds
1414 -- exactly to the function call in the source, so it should be marked
1415 -- this way (e.g. to make sure that validity checks work fine).
1418 CS : constant Boolean := Comes_From_Source (N);
1420 Rewrite (N, Op_Node);
1421 Set_Comes_From_Source (N, CS);
1424 -- If this is an arithmetic operator and the result type is private,
1425 -- the operands and the result must be wrapped in conversion to
1426 -- expose the underlying numeric type and expand the proper checks,
1427 -- e.g. on division.
1429 if Is_Private_Type (Typ) then
1431 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1432 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1433 Resolve_Intrinsic_Operator (N, Typ);
1435 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1436 Resolve_Intrinsic_Unary_Operator (N, Typ);
1445 -- For predefined operators on literals, the operation freezes
1448 if Present (Orig_Type) then
1449 Set_Etype (Act1, Orig_Type);
1450 Freeze_Expression (Act1);
1452 end Make_Call_Into_Operator;
1458 function Operator_Kind
1460 Is_Binary : Boolean) return Node_Kind
1466 if Op_Name = Name_Op_And then
1468 elsif Op_Name = Name_Op_Or then
1470 elsif Op_Name = Name_Op_Xor then
1472 elsif Op_Name = Name_Op_Eq then
1474 elsif Op_Name = Name_Op_Ne then
1476 elsif Op_Name = Name_Op_Lt then
1478 elsif Op_Name = Name_Op_Le then
1480 elsif Op_Name = Name_Op_Gt then
1482 elsif Op_Name = Name_Op_Ge then
1484 elsif Op_Name = Name_Op_Add then
1486 elsif Op_Name = Name_Op_Subtract then
1487 Kind := N_Op_Subtract;
1488 elsif Op_Name = Name_Op_Concat then
1489 Kind := N_Op_Concat;
1490 elsif Op_Name = Name_Op_Multiply then
1491 Kind := N_Op_Multiply;
1492 elsif Op_Name = Name_Op_Divide then
1493 Kind := N_Op_Divide;
1494 elsif Op_Name = Name_Op_Mod then
1496 elsif Op_Name = Name_Op_Rem then
1498 elsif Op_Name = Name_Op_Expon then
1501 raise Program_Error;
1507 if Op_Name = Name_Op_Add then
1509 elsif Op_Name = Name_Op_Subtract then
1511 elsif Op_Name = Name_Op_Abs then
1513 elsif Op_Name = Name_Op_Not then
1516 raise Program_Error;
1523 ----------------------------
1524 -- Preanalyze_And_Resolve --
1525 ----------------------------
1527 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1528 Save_Full_Analysis : constant Boolean := Full_Analysis;
1531 Full_Analysis := False;
1532 Expander_Mode_Save_And_Set (False);
1534 -- We suppress all checks for this analysis, since the checks will
1535 -- be applied properly, and in the right location, when the default
1536 -- expression is reanalyzed and reexpanded later on.
1538 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1540 Expander_Mode_Restore;
1541 Full_Analysis := Save_Full_Analysis;
1542 end Preanalyze_And_Resolve;
1544 -- Version without context type
1546 procedure Preanalyze_And_Resolve (N : Node_Id) is
1547 Save_Full_Analysis : constant Boolean := Full_Analysis;
1550 Full_Analysis := False;
1551 Expander_Mode_Save_And_Set (False);
1554 Resolve (N, Etype (N), Suppress => All_Checks);
1556 Expander_Mode_Restore;
1557 Full_Analysis := Save_Full_Analysis;
1558 end Preanalyze_And_Resolve;
1560 ----------------------------------
1561 -- Replace_Actual_Discriminants --
1562 ----------------------------------
1564 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1565 Loc : constant Source_Ptr := Sloc (N);
1566 Tsk : Node_Id := Empty;
1568 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1574 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1578 if Nkind (Nod) = N_Identifier then
1579 Ent := Entity (Nod);
1582 and then Ekind (Ent) = E_Discriminant
1585 Make_Selected_Component (Loc,
1586 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1587 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1589 Set_Etype (Nod, Etype (Ent));
1597 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1599 -- Start of processing for Replace_Actual_Discriminants
1602 if not Expander_Active then
1606 if Nkind (Name (N)) = N_Selected_Component then
1607 Tsk := Prefix (Name (N));
1609 elsif Nkind (Name (N)) = N_Indexed_Component then
1610 Tsk := Prefix (Prefix (Name (N)));
1616 Replace_Discrs (Default);
1618 end Replace_Actual_Discriminants;
1624 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1625 Ambiguous : Boolean := False;
1626 Ctx_Type : Entity_Id := Typ;
1627 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1628 Err_Type : Entity_Id := Empty;
1629 Found : Boolean := False;
1632 I1 : Interp_Index := 0; -- prevent junk warning
1635 Seen : Entity_Id := Empty; -- prevent junk warning
1637 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1638 -- Determine whether a node comes from a predefined library unit or
1641 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1642 -- Try and fix up a literal so that it matches its expected type. New
1643 -- literals are manufactured if necessary to avoid cascaded errors.
1645 procedure Resolution_Failed;
1646 -- Called when attempt at resolving current expression fails
1648 ------------------------------------
1649 -- Comes_From_Predefined_Lib_Unit --
1650 -------------------------------------
1652 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1655 Sloc (Nod) = Standard_Location
1656 or else Is_Predefined_File_Name (Unit_File_Name (
1657 Get_Source_Unit (Sloc (Nod))));
1658 end Comes_From_Predefined_Lib_Unit;
1660 --------------------
1661 -- Patch_Up_Value --
1662 --------------------
1664 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1666 if Nkind (N) = N_Integer_Literal
1667 and then Is_Real_Type (Typ)
1670 Make_Real_Literal (Sloc (N),
1671 Realval => UR_From_Uint (Intval (N))));
1672 Set_Etype (N, Universal_Real);
1673 Set_Is_Static_Expression (N);
1675 elsif Nkind (N) = N_Real_Literal
1676 and then Is_Integer_Type (Typ)
1679 Make_Integer_Literal (Sloc (N),
1680 Intval => UR_To_Uint (Realval (N))));
1681 Set_Etype (N, Universal_Integer);
1682 Set_Is_Static_Expression (N);
1684 elsif Nkind (N) = N_String_Literal
1685 and then Is_Character_Type (Typ)
1687 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1689 Make_Character_Literal (Sloc (N),
1691 Char_Literal_Value =>
1692 UI_From_Int (Character'Pos ('A'))));
1693 Set_Etype (N, Any_Character);
1694 Set_Is_Static_Expression (N);
1696 elsif Nkind (N) /= N_String_Literal
1697 and then Is_String_Type (Typ)
1700 Make_String_Literal (Sloc (N),
1701 Strval => End_String));
1703 elsif Nkind (N) = N_Range then
1704 Patch_Up_Value (Low_Bound (N), Typ);
1705 Patch_Up_Value (High_Bound (N), Typ);
1709 -----------------------
1710 -- Resolution_Failed --
1711 -----------------------
1713 procedure Resolution_Failed is
1715 Patch_Up_Value (N, Typ);
1717 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1718 Set_Is_Overloaded (N, False);
1720 -- The caller will return without calling the expander, so we need
1721 -- to set the analyzed flag. Note that it is fine to set Analyzed
1722 -- to True even if we are in the middle of a shallow analysis,
1723 -- (see the spec of sem for more details) since this is an error
1724 -- situation anyway, and there is no point in repeating the
1725 -- analysis later (indeed it won't work to repeat it later, since
1726 -- we haven't got a clear resolution of which entity is being
1729 Set_Analyzed (N, True);
1731 end Resolution_Failed;
1733 -- Start of processing for Resolve
1740 -- Access attribute on remote subprogram cannot be used for
1741 -- a non-remote access-to-subprogram type.
1743 if Nkind (N) = N_Attribute_Reference
1744 and then (Attribute_Name (N) = Name_Access
1745 or else Attribute_Name (N) = Name_Unrestricted_Access
1746 or else Attribute_Name (N) = Name_Unchecked_Access)
1747 and then Comes_From_Source (N)
1748 and then Is_Entity_Name (Prefix (N))
1749 and then Is_Subprogram (Entity (Prefix (N)))
1750 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1751 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1754 ("prefix must statically denote a non-remote subprogram", N);
1757 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1759 -- If the context is a Remote_Access_To_Subprogram, access attributes
1760 -- must be resolved with the corresponding fat pointer. There is no need
1761 -- to check for the attribute name since the return type of an
1762 -- attribute is never a remote type.
1764 if Nkind (N) = N_Attribute_Reference
1765 and then Comes_From_Source (N)
1766 and then (Is_Remote_Call_Interface (Typ)
1767 or else Is_Remote_Types (Typ))
1770 Attr : constant Attribute_Id :=
1771 Get_Attribute_Id (Attribute_Name (N));
1772 Pref : constant Node_Id := Prefix (N);
1775 Is_Remote : Boolean := True;
1778 -- Check that Typ is a remote access-to-subprogram type
1780 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1781 -- Prefix (N) must statically denote a remote subprogram
1782 -- declared in a package specification.
1784 if Attr = Attribute_Access then
1785 Decl := Unit_Declaration_Node (Entity (Pref));
1787 if Nkind (Decl) = N_Subprogram_Body then
1788 Spec := Corresponding_Spec (Decl);
1790 if not No (Spec) then
1791 Decl := Unit_Declaration_Node (Spec);
1795 Spec := Parent (Decl);
1797 if not Is_Entity_Name (Prefix (N))
1798 or else Nkind (Spec) /= N_Package_Specification
1800 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1804 ("prefix must statically denote a remote subprogram ",
1809 -- If we are generating code for a distributed program.
1810 -- perform semantic checks against the corresponding
1813 if (Attr = Attribute_Access
1814 or else Attr = Attribute_Unchecked_Access
1815 or else Attr = Attribute_Unrestricted_Access)
1816 and then Expander_Active
1817 and then Get_PCS_Name /= Name_No_DSA
1819 Check_Subtype_Conformant
1820 (New_Id => Entity (Prefix (N)),
1821 Old_Id => Designated_Type
1822 (Corresponding_Remote_Type (Typ)),
1826 Process_Remote_AST_Attribute (N, Typ);
1833 Debug_A_Entry ("resolving ", N);
1835 if Comes_From_Source (N) then
1836 if Is_Fixed_Point_Type (Typ) then
1837 Check_Restriction (No_Fixed_Point, N);
1839 elsif Is_Floating_Point_Type (Typ)
1840 and then Typ /= Universal_Real
1841 and then Typ /= Any_Real
1843 Check_Restriction (No_Floating_Point, N);
1847 -- Return if already analyzed
1849 if Analyzed (N) then
1850 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1853 -- Return if type = Any_Type (previous error encountered)
1855 elsif Etype (N) = Any_Type then
1856 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1860 Check_Parameterless_Call (N);
1862 -- If not overloaded, then we know the type, and all that needs doing
1863 -- is to check that this type is compatible with the context.
1865 if not Is_Overloaded (N) then
1866 Found := Covers (Typ, Etype (N));
1867 Expr_Type := Etype (N);
1869 -- In the overloaded case, we must select the interpretation that
1870 -- is compatible with the context (i.e. the type passed to Resolve)
1873 -- Loop through possible interpretations
1875 Get_First_Interp (N, I, It);
1876 Interp_Loop : while Present (It.Typ) loop
1878 -- We are only interested in interpretations that are compatible
1879 -- with the expected type, any other interpretations are ignored.
1881 if not Covers (Typ, It.Typ) then
1882 if Debug_Flag_V then
1883 Write_Str (" interpretation incompatible with context");
1888 -- Skip the current interpretation if it is disabled by an
1889 -- abstract operator. This action is performed only when the
1890 -- type against which we are resolving is the same as the
1891 -- type of the interpretation.
1893 if Ada_Version >= Ada_05
1894 and then It.Typ = Typ
1895 and then Typ /= Universal_Integer
1896 and then Typ /= Universal_Real
1897 and then Present (It.Abstract_Op)
1902 -- First matching interpretation
1908 Expr_Type := It.Typ;
1910 -- Matching interpretation that is not the first, maybe an
1911 -- error, but there are some cases where preference rules are
1912 -- used to choose between the two possibilities. These and
1913 -- some more obscure cases are handled in Disambiguate.
1916 -- If the current statement is part of a predefined library
1917 -- unit, then all interpretations which come from user level
1918 -- packages should not be considered.
1921 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
1926 Error_Msg_Sloc := Sloc (Seen);
1927 It1 := Disambiguate (N, I1, I, Typ);
1929 -- Disambiguation has succeeded. Skip the remaining
1932 if It1 /= No_Interp then
1934 Expr_Type := It1.Typ;
1936 while Present (It.Typ) loop
1937 Get_Next_Interp (I, It);
1941 -- Before we issue an ambiguity complaint, check for
1942 -- the case of a subprogram call where at least one
1943 -- of the arguments is Any_Type, and if so, suppress
1944 -- the message, since it is a cascaded error.
1946 if Nkind_In (N, N_Function_Call,
1947 N_Procedure_Call_Statement)
1954 A := First_Actual (N);
1955 while Present (A) loop
1958 if Nkind (E) = N_Parameter_Association then
1959 E := Explicit_Actual_Parameter (E);
1962 if Etype (E) = Any_Type then
1963 if Debug_Flag_V then
1964 Write_Str ("Any_Type in call");
1975 elsif Nkind (N) in N_Binary_Op
1976 and then (Etype (Left_Opnd (N)) = Any_Type
1977 or else Etype (Right_Opnd (N)) = Any_Type)
1981 elsif Nkind (N) in N_Unary_Op
1982 and then Etype (Right_Opnd (N)) = Any_Type
1987 -- Not that special case, so issue message using the
1988 -- flag Ambiguous to control printing of the header
1989 -- message only at the start of an ambiguous set.
1991 if not Ambiguous then
1992 if Nkind (N) = N_Function_Call
1993 and then Nkind (Name (N)) = N_Explicit_Dereference
1996 ("ambiguous expression "
1997 & "(cannot resolve indirect call)!", N);
2000 ("ambiguous expression (cannot resolve&)!",
2006 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2008 ("\\possible interpretation (inherited)#!", N);
2010 Error_Msg_N ("\\possible interpretation#!", N);
2014 Error_Msg_Sloc := Sloc (It.Nam);
2016 -- By default, the error message refers to the candidate
2017 -- interpretation. But if it is a predefined operator, it
2018 -- is implicitly declared at the declaration of the type
2019 -- of the operand. Recover the sloc of that declaration
2020 -- for the error message.
2022 if Nkind (N) in N_Op
2023 and then Scope (It.Nam) = Standard_Standard
2024 and then not Is_Overloaded (Right_Opnd (N))
2025 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2028 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2030 if Comes_From_Source (Err_Type)
2031 and then Present (Parent (Err_Type))
2033 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2036 elsif Nkind (N) in N_Binary_Op
2037 and then Scope (It.Nam) = Standard_Standard
2038 and then not Is_Overloaded (Left_Opnd (N))
2039 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2042 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2044 if Comes_From_Source (Err_Type)
2045 and then Present (Parent (Err_Type))
2047 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2050 -- If this is an indirect call, use the subprogram_type
2051 -- in the message, to have a meaningful location.
2052 -- Indicate as well if this is an inherited operation,
2053 -- created by a type declaration.
2055 elsif Nkind (N) = N_Function_Call
2056 and then Nkind (Name (N)) = N_Explicit_Dereference
2057 and then Is_Type (It.Nam)
2061 Sloc (Associated_Node_For_Itype (Err_Type));
2066 if Nkind (N) in N_Op
2067 and then Scope (It.Nam) = Standard_Standard
2068 and then Present (Err_Type)
2070 -- Special-case the message for universal_fixed
2071 -- operators, which are not declared with the type
2072 -- of the operand, but appear forever in Standard.
2074 if It.Typ = Universal_Fixed
2075 and then Scope (It.Nam) = Standard_Standard
2078 ("\\possible interpretation as " &
2079 "universal_fixed operation " &
2080 "(RM 4.5.5 (19))", N);
2083 ("\\possible interpretation (predefined)#!", N);
2087 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2090 ("\\possible interpretation (inherited)#!", N);
2092 Error_Msg_N ("\\possible interpretation#!", N);
2098 -- We have a matching interpretation, Expr_Type is the type
2099 -- from this interpretation, and Seen is the entity.
2101 -- For an operator, just set the entity name. The type will be
2102 -- set by the specific operator resolution routine.
2104 if Nkind (N) in N_Op then
2105 Set_Entity (N, Seen);
2106 Generate_Reference (Seen, N);
2108 elsif Nkind (N) = N_Character_Literal then
2109 Set_Etype (N, Expr_Type);
2111 -- For an explicit dereference, attribute reference, range,
2112 -- short-circuit form (which is not an operator node), or call
2113 -- with a name that is an explicit dereference, there is
2114 -- nothing to be done at this point.
2116 elsif Nkind_In (N, N_Explicit_Dereference,
2117 N_Attribute_Reference,
2119 N_Indexed_Component,
2122 N_Selected_Component,
2124 or else Nkind (Name (N)) = N_Explicit_Dereference
2128 -- For procedure or function calls, set the type of the name,
2129 -- and also the entity pointer for the prefix
2131 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2132 and then (Is_Entity_Name (Name (N))
2133 or else Nkind (Name (N)) = N_Operator_Symbol)
2135 Set_Etype (Name (N), Expr_Type);
2136 Set_Entity (Name (N), Seen);
2137 Generate_Reference (Seen, Name (N));
2139 elsif Nkind (N) = N_Function_Call
2140 and then Nkind (Name (N)) = N_Selected_Component
2142 Set_Etype (Name (N), Expr_Type);
2143 Set_Entity (Selector_Name (Name (N)), Seen);
2144 Generate_Reference (Seen, Selector_Name (Name (N)));
2146 -- For all other cases, just set the type of the Name
2149 Set_Etype (Name (N), Expr_Type);
2156 -- Move to next interpretation
2158 exit Interp_Loop when No (It.Typ);
2160 Get_Next_Interp (I, It);
2161 end loop Interp_Loop;
2164 -- At this stage Found indicates whether or not an acceptable
2165 -- interpretation exists. If not, then we have an error, except
2166 -- that if the context is Any_Type as a result of some other error,
2167 -- then we suppress the error report.
2170 if Typ /= Any_Type then
2172 -- If type we are looking for is Void, then this is the procedure
2173 -- call case, and the error is simply that what we gave is not a
2174 -- procedure name (we think of procedure calls as expressions with
2175 -- types internally, but the user doesn't think of them this way!)
2177 if Typ = Standard_Void_Type then
2179 -- Special case message if function used as a procedure
2181 if Nkind (N) = N_Procedure_Call_Statement
2182 and then Is_Entity_Name (Name (N))
2183 and then Ekind (Entity (Name (N))) = E_Function
2186 ("cannot use function & in a procedure call",
2187 Name (N), Entity (Name (N)));
2189 -- Otherwise give general message (not clear what cases this
2190 -- covers, but no harm in providing for them!)
2193 Error_Msg_N ("expect procedure name in procedure call", N);
2198 -- Otherwise we do have a subexpression with the wrong type
2200 -- Check for the case of an allocator which uses an access type
2201 -- instead of the designated type. This is a common error and we
2202 -- specialize the message, posting an error on the operand of the
2203 -- allocator, complaining that we expected the designated type of
2206 elsif Nkind (N) = N_Allocator
2207 and then Ekind (Typ) in Access_Kind
2208 and then Ekind (Etype (N)) in Access_Kind
2209 and then Designated_Type (Etype (N)) = Typ
2211 Wrong_Type (Expression (N), Designated_Type (Typ));
2214 -- Check for view mismatch on Null in instances, for which the
2215 -- view-swapping mechanism has no identifier.
2217 elsif (In_Instance or else In_Inlined_Body)
2218 and then (Nkind (N) = N_Null)
2219 and then Is_Private_Type (Typ)
2220 and then Is_Access_Type (Full_View (Typ))
2222 Resolve (N, Full_View (Typ));
2226 -- Check for an aggregate. Sometimes we can get bogus aggregates
2227 -- from misuse of parentheses, and we are about to complain about
2228 -- the aggregate without even looking inside it.
2230 -- Instead, if we have an aggregate of type Any_Composite, then
2231 -- analyze and resolve the component fields, and then only issue
2232 -- another message if we get no errors doing this (otherwise
2233 -- assume that the errors in the aggregate caused the problem).
2235 elsif Nkind (N) = N_Aggregate
2236 and then Etype (N) = Any_Composite
2238 -- Disable expansion in any case. If there is a type mismatch
2239 -- it may be fatal to try to expand the aggregate. The flag
2240 -- would otherwise be set to false when the error is posted.
2242 Expander_Active := False;
2245 procedure Check_Aggr (Aggr : Node_Id);
2246 -- Check one aggregate, and set Found to True if we have a
2247 -- definite error in any of its elements
2249 procedure Check_Elmt (Aelmt : Node_Id);
2250 -- Check one element of aggregate and set Found to True if
2251 -- we definitely have an error in the element.
2257 procedure Check_Aggr (Aggr : Node_Id) is
2261 if Present (Expressions (Aggr)) then
2262 Elmt := First (Expressions (Aggr));
2263 while Present (Elmt) loop
2269 if Present (Component_Associations (Aggr)) then
2270 Elmt := First (Component_Associations (Aggr));
2271 while Present (Elmt) loop
2273 -- If this is a default-initialized component, then
2274 -- there is nothing to check. The box will be
2275 -- replaced by the appropriate call during late
2278 if not Box_Present (Elmt) then
2279 Check_Elmt (Expression (Elmt));
2291 procedure Check_Elmt (Aelmt : Node_Id) is
2293 -- If we have a nested aggregate, go inside it (to
2294 -- attempt a naked analyze-resolve of the aggregate
2295 -- can cause undesirable cascaded errors). Do not
2296 -- resolve expression if it needs a type from context,
2297 -- as for integer * fixed expression.
2299 if Nkind (Aelmt) = N_Aggregate then
2305 if not Is_Overloaded (Aelmt)
2306 and then Etype (Aelmt) /= Any_Fixed
2311 if Etype (Aelmt) = Any_Type then
2322 -- If an error message was issued already, Found got reset
2323 -- to True, so if it is still False, issue the standard
2324 -- Wrong_Type message.
2327 if Is_Overloaded (N)
2328 and then Nkind (N) = N_Function_Call
2331 Subp_Name : Node_Id;
2333 if Is_Entity_Name (Name (N)) then
2334 Subp_Name := Name (N);
2336 elsif Nkind (Name (N)) = N_Selected_Component then
2338 -- Protected operation: retrieve operation name
2340 Subp_Name := Selector_Name (Name (N));
2342 raise Program_Error;
2345 Error_Msg_Node_2 := Typ;
2346 Error_Msg_NE ("no visible interpretation of&" &
2347 " matches expected type&", N, Subp_Name);
2350 if All_Errors_Mode then
2352 Index : Interp_Index;
2356 Error_Msg_N ("\\possible interpretations:", N);
2358 Get_First_Interp (Name (N), Index, It);
2359 while Present (It.Nam) loop
2360 Error_Msg_Sloc := Sloc (It.Nam);
2361 Error_Msg_Node_2 := It.Nam;
2363 ("\\ type& for & declared#", N, It.Typ);
2364 Get_Next_Interp (Index, It);
2369 Error_Msg_N ("\use -gnatf for details", N);
2372 Wrong_Type (N, Typ);
2380 -- Test if we have more than one interpretation for the context
2382 elsif Ambiguous then
2386 -- Here we have an acceptable interpretation for the context
2389 -- Propagate type information and normalize tree for various
2390 -- predefined operations. If the context only imposes a class of
2391 -- types, rather than a specific type, propagate the actual type
2394 if Typ = Any_Integer
2395 or else Typ = Any_Boolean
2396 or else Typ = Any_Modular
2397 or else Typ = Any_Real
2398 or else Typ = Any_Discrete
2400 Ctx_Type := Expr_Type;
2402 -- Any_Fixed is legal in a real context only if a specific
2403 -- fixed point type is imposed. If Norman Cohen can be
2404 -- confused by this, it deserves a separate message.
2407 and then Expr_Type = Any_Fixed
2409 Error_Msg_N ("illegal context for mixed mode operation", N);
2410 Set_Etype (N, Universal_Real);
2411 Ctx_Type := Universal_Real;
2415 -- A user-defined operator is transformed into a function call at
2416 -- this point, so that further processing knows that operators are
2417 -- really operators (i.e. are predefined operators). User-defined
2418 -- operators that are intrinsic are just renamings of the predefined
2419 -- ones, and need not be turned into calls either, but if they rename
2420 -- a different operator, we must transform the node accordingly.
2421 -- Instantiations of Unchecked_Conversion are intrinsic but are
2422 -- treated as functions, even if given an operator designator.
2424 if Nkind (N) in N_Op
2425 and then Present (Entity (N))
2426 and then Ekind (Entity (N)) /= E_Operator
2429 if not Is_Predefined_Op (Entity (N)) then
2430 Rewrite_Operator_As_Call (N, Entity (N));
2432 elsif Present (Alias (Entity (N)))
2434 Nkind (Parent (Parent (Entity (N)))) =
2435 N_Subprogram_Renaming_Declaration
2437 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2439 -- If the node is rewritten, it will be fully resolved in
2440 -- Rewrite_Renamed_Operator.
2442 if Analyzed (N) then
2448 case N_Subexpr'(Nkind (N)) is
2450 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2452 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2454 when N_And_Then | N_Or_Else
2455 => Resolve_Short_Circuit (N, Ctx_Type);
2457 when N_Attribute_Reference
2458 => Resolve_Attribute (N, Ctx_Type);
2460 when N_Character_Literal
2461 => Resolve_Character_Literal (N, Ctx_Type);
2463 when N_Conditional_Expression
2464 => Resolve_Conditional_Expression (N, Ctx_Type);
2466 when N_Expanded_Name
2467 => Resolve_Entity_Name (N, Ctx_Type);
2469 when N_Extension_Aggregate
2470 => Resolve_Extension_Aggregate (N, Ctx_Type);
2472 when N_Explicit_Dereference
2473 => Resolve_Explicit_Dereference (N, Ctx_Type);
2475 when N_Function_Call
2476 => Resolve_Call (N, Ctx_Type);
2479 => Resolve_Entity_Name (N, Ctx_Type);
2481 when N_Indexed_Component
2482 => Resolve_Indexed_Component (N, Ctx_Type);
2484 when N_Integer_Literal
2485 => Resolve_Integer_Literal (N, Ctx_Type);
2487 when N_Membership_Test
2488 => Resolve_Membership_Op (N, Ctx_Type);
2490 when N_Null => Resolve_Null (N, Ctx_Type);
2492 when N_Op_And | N_Op_Or | N_Op_Xor
2493 => Resolve_Logical_Op (N, Ctx_Type);
2495 when N_Op_Eq | N_Op_Ne
2496 => Resolve_Equality_Op (N, Ctx_Type);
2498 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2499 => Resolve_Comparison_Op (N, Ctx_Type);
2501 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2503 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2504 N_Op_Divide | N_Op_Mod | N_Op_Rem
2506 => Resolve_Arithmetic_Op (N, Ctx_Type);
2508 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2510 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2512 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2513 => Resolve_Unary_Op (N, Ctx_Type);
2515 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2517 when N_Procedure_Call_Statement
2518 => Resolve_Call (N, Ctx_Type);
2520 when N_Operator_Symbol
2521 => Resolve_Operator_Symbol (N, Ctx_Type);
2523 when N_Qualified_Expression
2524 => Resolve_Qualified_Expression (N, Ctx_Type);
2526 when N_Raise_xxx_Error
2527 => Set_Etype (N, Ctx_Type);
2529 when N_Range => Resolve_Range (N, Ctx_Type);
2532 => Resolve_Real_Literal (N, Ctx_Type);
2534 when N_Reference => Resolve_Reference (N, Ctx_Type);
2536 when N_Selected_Component
2537 => Resolve_Selected_Component (N, Ctx_Type);
2539 when N_Slice => Resolve_Slice (N, Ctx_Type);
2541 when N_String_Literal
2542 => Resolve_String_Literal (N, Ctx_Type);
2544 when N_Subprogram_Info
2545 => Resolve_Subprogram_Info (N, Ctx_Type);
2547 when N_Type_Conversion
2548 => Resolve_Type_Conversion (N, Ctx_Type);
2550 when N_Unchecked_Expression =>
2551 Resolve_Unchecked_Expression (N, Ctx_Type);
2553 when N_Unchecked_Type_Conversion =>
2554 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2558 -- If the subexpression was replaced by a non-subexpression, then
2559 -- all we do is to expand it. The only legitimate case we know of
2560 -- is converting procedure call statement to entry call statements,
2561 -- but there may be others, so we are making this test general.
2563 if Nkind (N) not in N_Subexpr then
2564 Debug_A_Exit ("resolving ", N, " (done)");
2569 -- The expression is definitely NOT overloaded at this point, so
2570 -- we reset the Is_Overloaded flag to avoid any confusion when
2571 -- reanalyzing the node.
2573 Set_Is_Overloaded (N, False);
2575 -- Freeze expression type, entity if it is a name, and designated
2576 -- type if it is an allocator (RM 13.14(10,11,13)).
2578 -- Now that the resolution of the type of the node is complete,
2579 -- and we did not detect an error, we can expand this node. We
2580 -- skip the expand call if we are in a default expression, see
2581 -- section "Handling of Default Expressions" in Sem spec.
2583 Debug_A_Exit ("resolving ", N, " (done)");
2585 -- We unconditionally freeze the expression, even if we are in
2586 -- default expression mode (the Freeze_Expression routine tests
2587 -- this flag and only freezes static types if it is set).
2589 Freeze_Expression (N);
2591 -- Now we can do the expansion
2601 -- Version with check(s) suppressed
2603 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2605 if Suppress = All_Checks then
2607 Svg : constant Suppress_Array := Scope_Suppress;
2609 Scope_Suppress := (others => True);
2611 Scope_Suppress := Svg;
2616 Svg : constant Boolean := Scope_Suppress (Suppress);
2618 Scope_Suppress (Suppress) := True;
2620 Scope_Suppress (Suppress) := Svg;
2629 -- Version with implicit type
2631 procedure Resolve (N : Node_Id) is
2633 Resolve (N, Etype (N));
2636 ---------------------
2637 -- Resolve_Actuals --
2638 ---------------------
2640 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2641 Loc : constant Source_Ptr := Sloc (N);
2646 Prev : Node_Id := Empty;
2649 procedure Check_Argument_Order;
2650 -- Performs a check for the case where the actuals are all simple
2651 -- identifiers that correspond to the formal names, but in the wrong
2652 -- order, which is considered suspicious and cause for a warning.
2654 procedure Check_Prefixed_Call;
2655 -- If the original node is an overloaded call in prefix notation,
2656 -- insert an 'Access or a dereference as needed over the first actual.
2657 -- Try_Object_Operation has already verified that there is a valid
2658 -- interpretation, but the form of the actual can only be determined
2659 -- once the primitive operation is identified.
2661 procedure Insert_Default;
2662 -- If the actual is missing in a call, insert in the actuals list
2663 -- an instance of the default expression. The insertion is always
2664 -- a named association.
2666 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2667 -- Check whether T1 and T2, or their full views, are derived from a
2668 -- common type. Used to enforce the restrictions on array conversions
2671 --------------------------
2672 -- Check_Argument_Order --
2673 --------------------------
2675 procedure Check_Argument_Order is
2677 -- Nothing to do if no parameters, or original node is neither a
2678 -- function call nor a procedure call statement (happens in the
2679 -- operator-transformed-to-function call case), or the call does
2680 -- not come from source, or this warning is off.
2682 if not Warn_On_Parameter_Order
2684 No (Parameter_Associations (N))
2686 not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2689 not Comes_From_Source (N)
2695 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2698 -- Nothing to do if only one parameter
2704 -- Here if at least two arguments
2707 Actuals : array (1 .. Nargs) of Node_Id;
2711 Wrong_Order : Boolean := False;
2712 -- Set True if an out of order case is found
2715 -- Collect identifier names of actuals, fail if any actual is
2716 -- not a simple identifier, and record max length of name.
2718 Actual := First (Parameter_Associations (N));
2719 for J in Actuals'Range loop
2720 if Nkind (Actual) /= N_Identifier then
2723 Actuals (J) := Actual;
2728 -- If we got this far, all actuals are identifiers and the list
2729 -- of their names is stored in the Actuals array.
2731 Formal := First_Formal (Nam);
2732 for J in Actuals'Range loop
2734 -- If we ran out of formals, that's odd, probably an error
2735 -- which will be detected elsewhere, but abandon the search.
2741 -- If name matches and is in order OK
2743 if Chars (Formal) = Chars (Actuals (J)) then
2747 -- If no match, see if it is elsewhere in list and if so
2748 -- flag potential wrong order if type is compatible.
2750 for K in Actuals'Range loop
2751 if Chars (Formal) = Chars (Actuals (K))
2753 Has_Compatible_Type (Actuals (K), Etype (Formal))
2755 Wrong_Order := True;
2765 <<Continue>> Next_Formal (Formal);
2768 -- If Formals left over, also probably an error, skip warning
2770 if Present (Formal) then
2774 -- Here we give the warning if something was out of order
2778 ("actuals for this call may be in wrong order?", N);
2782 end Check_Argument_Order;
2784 -------------------------
2785 -- Check_Prefixed_Call --
2786 -------------------------
2788 procedure Check_Prefixed_Call is
2789 Act : constant Node_Id := First_Actual (N);
2790 A_Type : constant Entity_Id := Etype (Act);
2791 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
2792 Orig : constant Node_Id := Original_Node (N);
2796 -- Check whether the call is a prefixed call, with or without
2797 -- additional actuals.
2799 if Nkind (Orig) = N_Selected_Component
2801 (Nkind (Orig) = N_Indexed_Component
2802 and then Nkind (Prefix (Orig)) = N_Selected_Component
2803 and then Is_Entity_Name (Prefix (Prefix (Orig)))
2804 and then Is_Entity_Name (Act)
2805 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
2807 if Is_Access_Type (A_Type)
2808 and then not Is_Access_Type (F_Type)
2810 -- Introduce dereference on object in prefix
2813 Make_Explicit_Dereference (Sloc (Act),
2814 Prefix => Relocate_Node (Act));
2815 Rewrite (Act, New_A);
2818 elsif Is_Access_Type (F_Type)
2819 and then not Is_Access_Type (A_Type)
2821 -- Introduce an implicit 'Access in prefix
2823 if not Is_Aliased_View (Act) then
2825 ("object in prefixed call to& must be aliased"
2826 & " (RM-2005 4.3.1 (13))",
2831 Make_Attribute_Reference (Loc,
2832 Attribute_Name => Name_Access,
2833 Prefix => Relocate_Node (Act)));
2838 end Check_Prefixed_Call;
2840 --------------------
2841 -- Insert_Default --
2842 --------------------
2844 procedure Insert_Default is
2849 -- Missing argument in call, nothing to insert
2851 if No (Default_Value (F)) then
2855 -- Note that we do a full New_Copy_Tree, so that any associated
2856 -- Itypes are properly copied. This may not be needed any more,
2857 -- but it does no harm as a safety measure! Defaults of a generic
2858 -- formal may be out of bounds of the corresponding actual (see
2859 -- cc1311b) and an additional check may be required.
2864 New_Scope => Current_Scope,
2867 if Is_Concurrent_Type (Scope (Nam))
2868 and then Has_Discriminants (Scope (Nam))
2870 Replace_Actual_Discriminants (N, Actval);
2873 if Is_Overloadable (Nam)
2874 and then Present (Alias (Nam))
2876 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2877 and then not Is_Tagged_Type (Etype (F))
2879 -- If default is a real literal, do not introduce a
2880 -- conversion whose effect may depend on the run-time
2881 -- size of universal real.
2883 if Nkind (Actval) = N_Real_Literal then
2884 Set_Etype (Actval, Base_Type (Etype (F)));
2886 Actval := Unchecked_Convert_To (Etype (F), Actval);
2890 if Is_Scalar_Type (Etype (F)) then
2891 Enable_Range_Check (Actval);
2894 Set_Parent (Actval, N);
2896 -- Resolve aggregates with their base type, to avoid scope
2897 -- anomalies: the subtype was first built in the subprogram
2898 -- declaration, and the current call may be nested.
2900 if Nkind (Actval) = N_Aggregate
2901 and then Has_Discriminants (Etype (Actval))
2903 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2905 Analyze_And_Resolve (Actval, Etype (Actval));
2909 Set_Parent (Actval, N);
2911 -- See note above concerning aggregates
2913 if Nkind (Actval) = N_Aggregate
2914 and then Has_Discriminants (Etype (Actval))
2916 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2918 -- Resolve entities with their own type, which may differ
2919 -- from the type of a reference in a generic context (the
2920 -- view swapping mechanism did not anticipate the re-analysis
2921 -- of default values in calls).
2923 elsif Is_Entity_Name (Actval) then
2924 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
2927 Analyze_And_Resolve (Actval, Etype (Actval));
2931 -- If default is a tag indeterminate function call, propagate
2932 -- tag to obtain proper dispatching.
2934 if Is_Controlling_Formal (F)
2935 and then Nkind (Default_Value (F)) = N_Function_Call
2937 Set_Is_Controlling_Actual (Actval);
2942 -- If the default expression raises constraint error, then just
2943 -- silently replace it with an N_Raise_Constraint_Error node,
2944 -- since we already gave the warning on the subprogram spec.
2946 if Raises_Constraint_Error (Actval) then
2948 Make_Raise_Constraint_Error (Loc,
2949 Reason => CE_Range_Check_Failed));
2950 Set_Raises_Constraint_Error (Actval);
2951 Set_Etype (Actval, Etype (F));
2955 Make_Parameter_Association (Loc,
2956 Explicit_Actual_Parameter => Actval,
2957 Selector_Name => Make_Identifier (Loc, Chars (F)));
2959 -- Case of insertion is first named actual
2961 if No (Prev) or else
2962 Nkind (Parent (Prev)) /= N_Parameter_Association
2964 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
2965 Set_First_Named_Actual (N, Actval);
2968 if No (Parameter_Associations (N)) then
2969 Set_Parameter_Associations (N, New_List (Assoc));
2971 Append (Assoc, Parameter_Associations (N));
2975 Insert_After (Prev, Assoc);
2978 -- Case of insertion is not first named actual
2981 Set_Next_Named_Actual
2982 (Assoc, Next_Named_Actual (Parent (Prev)));
2983 Set_Next_Named_Actual (Parent (Prev), Actval);
2984 Append (Assoc, Parameter_Associations (N));
2987 Mark_Rewrite_Insertion (Assoc);
2988 Mark_Rewrite_Insertion (Actval);
2997 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
2998 FT1 : Entity_Id := T1;
2999 FT2 : Entity_Id := T2;
3002 if Is_Private_Type (T1)
3003 and then Present (Full_View (T1))
3005 FT1 := Full_View (T1);
3008 if Is_Private_Type (T2)
3009 and then Present (Full_View (T2))
3011 FT2 := Full_View (T2);
3014 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3017 -- Start of processing for Resolve_Actuals
3020 Check_Argument_Order;
3022 if Present (First_Actual (N)) then
3023 Check_Prefixed_Call;
3026 A := First_Actual (N);
3027 F := First_Formal (Nam);
3028 while Present (F) loop
3029 if No (A) and then Needs_No_Actuals (Nam) then
3032 -- If we have an error in any actual or formal, indicated by
3033 -- a type of Any_Type, then abandon resolution attempt, and
3034 -- set result type to Any_Type.
3036 elsif (Present (A) and then Etype (A) = Any_Type)
3037 or else Etype (F) = Any_Type
3039 Set_Etype (N, Any_Type);
3043 -- Case where actual is present
3045 -- If the actual is an entity, generate a reference to it now. We
3046 -- do this before the actual is resolved, because a formal of some
3047 -- protected subprogram, or a task discriminant, will be rewritten
3048 -- during expansion, and the reference to the source entity may
3052 and then Is_Entity_Name (A)
3053 and then Comes_From_Source (N)
3055 Orig_A := Entity (A);
3057 if Present (Orig_A) then
3058 if Is_Formal (Orig_A)
3059 and then Ekind (F) /= E_In_Parameter
3061 Generate_Reference (Orig_A, A, 'm');
3062 elsif not Is_Overloaded (A) then
3063 Generate_Reference (Orig_A, A);
3069 and then (Nkind (Parent (A)) /= N_Parameter_Association
3071 Chars (Selector_Name (Parent (A))) = Chars (F))
3073 -- If style checking mode on, check match of formal name
3076 if Nkind (Parent (A)) = N_Parameter_Association then
3077 Check_Identifier (Selector_Name (Parent (A)), F);
3081 -- If the formal is Out or In_Out, do not resolve and expand the
3082 -- conversion, because it is subsequently expanded into explicit
3083 -- temporaries and assignments. However, the object of the
3084 -- conversion can be resolved. An exception is the case of tagged
3085 -- type conversion with a class-wide actual. In that case we want
3086 -- the tag check to occur and no temporary will be needed (no
3087 -- representation change can occur) and the parameter is passed by
3088 -- reference, so we go ahead and resolve the type conversion.
3089 -- Another exception is the case of reference to component or
3090 -- subcomponent of a bit-packed array, in which case we want to
3091 -- defer expansion to the point the in and out assignments are
3094 if Ekind (F) /= E_In_Parameter
3095 and then Nkind (A) = N_Type_Conversion
3096 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3098 if Ekind (F) = E_In_Out_Parameter
3099 and then Is_Array_Type (Etype (F))
3101 if Has_Aliased_Components (Etype (Expression (A)))
3102 /= Has_Aliased_Components (Etype (F))
3105 -- In a view conversion, the conversion must be legal in
3106 -- both directions, and thus both component types must be
3107 -- aliased, or neither (4.6 (8)).
3109 -- The additional rule 4.6 (24.9.2) seems unduly
3110 -- restrictive: the privacy requirement should not
3111 -- apply to generic types, and should be checked in
3112 -- an instance. ARG query is in order.
3115 ("both component types in a view conversion must be"
3116 & " aliased, or neither", A);
3119 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3121 if Is_By_Reference_Type (Etype (F))
3122 or else Is_By_Reference_Type (Etype (Expression (A)))
3125 ("view conversion between unrelated by reference " &
3126 "array types not allowed (\'A'I-00246)", A);
3129 Comp_Type : constant Entity_Id :=
3131 (Etype (Expression (A)));
3133 if Comes_From_Source (A)
3134 and then Ada_Version >= Ada_05
3136 ((Is_Private_Type (Comp_Type)
3137 and then not Is_Generic_Type (Comp_Type))
3138 or else Is_Tagged_Type (Comp_Type)
3139 or else Is_Volatile (Comp_Type))
3142 ("component type of a view conversion cannot"
3143 & " be private, tagged, or volatile"
3152 if (Conversion_OK (A)
3153 or else Valid_Conversion (A, Etype (A), Expression (A)))
3154 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3156 Resolve (Expression (A));
3159 -- If the actual is a function call that returns a limited
3160 -- unconstrained object that needs finalization, create a
3161 -- transient scope for it, so that it can receive the proper
3162 -- finalization list.
3164 elsif Nkind (A) = N_Function_Call
3165 and then Is_Limited_Record (Etype (F))
3166 and then not Is_Constrained (Etype (F))
3167 and then Expander_Active
3169 (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3171 Establish_Transient_Scope (A, False);
3173 -- A small optimization: if one of the actuals is a concatenation
3174 -- create a block around a procedure call to recover stack space.
3175 -- This alleviates stack usage when several procedure calls in
3176 -- the same statement list use concatenation.
3178 elsif Nkind (A) = N_Op_Concat
3179 and then Nkind (N) = N_Procedure_Call_Statement
3180 and then Expander_Active
3182 Establish_Transient_Scope (A, False);
3183 Resolve (A, Etype (F));
3186 if Nkind (A) = N_Type_Conversion
3187 and then Is_Array_Type (Etype (F))
3188 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3190 (Is_Limited_Type (Etype (F))
3191 or else Is_Limited_Type (Etype (Expression (A))))
3194 ("conversion between unrelated limited array types " &
3195 "not allowed (\A\I-00246)", A);
3197 if Is_Limited_Type (Etype (F)) then
3198 Explain_Limited_Type (Etype (F), A);
3201 if Is_Limited_Type (Etype (Expression (A))) then
3202 Explain_Limited_Type (Etype (Expression (A)), A);
3206 -- (Ada 2005: AI-251): If the actual is an allocator whose
3207 -- directly designated type is a class-wide interface, we build
3208 -- an anonymous access type to use it as the type of the
3209 -- allocator. Later, when the subprogram call is expanded, if
3210 -- the interface has a secondary dispatch table the expander
3211 -- will add a type conversion to force the correct displacement
3214 if Nkind (A) = N_Allocator then
3216 DDT : constant Entity_Id :=
3217 Directly_Designated_Type (Base_Type (Etype (F)));
3219 New_Itype : Entity_Id;
3222 if Is_Class_Wide_Type (DDT)
3223 and then Is_Interface (DDT)
3225 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3226 Set_Etype (New_Itype, Etype (A));
3227 Set_Directly_Designated_Type (New_Itype,
3228 Directly_Designated_Type (Etype (A)));
3229 Set_Etype (A, New_Itype);
3232 -- Ada 2005, AI-162:If the actual is an allocator, the
3233 -- innermost enclosing statement is the master of the
3234 -- created object. This needs to be done with expansion
3235 -- enabled only, otherwise the transient scope will not
3236 -- be removed in the expansion of the wrapped construct.
3238 if (Is_Controlled (DDT) or else Has_Task (DDT))
3239 and then Expander_Active
3241 Establish_Transient_Scope (A, False);
3246 -- (Ada 2005): The call may be to a primitive operation of
3247 -- a tagged synchronized type, declared outside of the type.
3248 -- In this case the controlling actual must be converted to
3249 -- its corresponding record type, which is the formal type.
3250 -- The actual may be a subtype, either because of a constraint
3251 -- or because it is a generic actual, so use base type to
3252 -- locate concurrent type.
3254 A_Typ := Base_Type (Etype (A));
3255 F_Typ := Base_Type (Etype (F));
3258 Full_A_Typ : Entity_Id;
3261 if Present (Full_View (A_Typ)) then
3262 Full_A_Typ := Base_Type (Full_View (A_Typ));
3264 Full_A_Typ := A_Typ;
3267 -- Tagged synchronized type (case 1): the actual is a
3270 if Is_Concurrent_Type (A_Typ)
3271 and then Corresponding_Record_Type (A_Typ) = F_Typ
3274 Unchecked_Convert_To
3275 (Corresponding_Record_Type (A_Typ), A));
3276 Resolve (A, Etype (F));
3278 -- Tagged synchronized type (case 2): the formal is a
3281 elsif Ekind (Full_A_Typ) = E_Record_Type
3283 (Corresponding_Concurrent_Type (Full_A_Typ))
3284 and then Is_Concurrent_Type (F_Typ)
3285 and then Present (Corresponding_Record_Type (F_Typ))
3286 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3288 Resolve (A, Corresponding_Record_Type (F_Typ));
3293 Resolve (A, Etype (F));
3301 -- For mode IN, if actual is an entity, and the type of the formal
3302 -- has warnings suppressed, then we reset Never_Set_In_Source for
3303 -- the calling entity. The reason for this is to catch cases like
3304 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3305 -- uses trickery to modify an IN parameter.
3307 if Ekind (F) = E_In_Parameter
3308 and then Is_Entity_Name (A)
3309 and then Present (Entity (A))
3310 and then Ekind (Entity (A)) = E_Variable
3311 and then Has_Warnings_Off (F_Typ)
3313 Set_Never_Set_In_Source (Entity (A), False);
3316 -- Perform error checks for IN and IN OUT parameters
3318 if Ekind (F) /= E_Out_Parameter then
3320 -- Check unset reference. For scalar parameters, it is clearly
3321 -- wrong to pass an uninitialized value as either an IN or
3322 -- IN-OUT parameter. For composites, it is also clearly an
3323 -- error to pass a completely uninitialized value as an IN
3324 -- parameter, but the case of IN OUT is trickier. We prefer
3325 -- not to give a warning here. For example, suppose there is
3326 -- a routine that sets some component of a record to False.
3327 -- It is perfectly reasonable to make this IN-OUT and allow
3328 -- either initialized or uninitialized records to be passed
3331 -- For partially initialized composite values, we also avoid
3332 -- warnings, since it is quite likely that we are passing a
3333 -- partially initialized value and only the initialized fields
3334 -- will in fact be read in the subprogram.
3336 if Is_Scalar_Type (A_Typ)
3337 or else (Ekind (F) = E_In_Parameter
3338 and then not Is_Partially_Initialized_Type (A_Typ))
3340 Check_Unset_Reference (A);
3343 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3344 -- actual to a nested call, since this is case of reading an
3345 -- out parameter, which is not allowed.
3347 if Ada_Version = Ada_83
3348 and then Is_Entity_Name (A)
3349 and then Ekind (Entity (A)) = E_Out_Parameter
3351 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3355 -- Case of OUT or IN OUT parameter
3357 if Ekind (F) /= E_In_Parameter then
3359 -- For an Out parameter, check for useless assignment. Note
3360 -- that we can't set Last_Assignment this early, because we may
3361 -- kill current values in Resolve_Call, and that call would
3362 -- clobber the Last_Assignment field.
3364 -- Note: call Warn_On_Useless_Assignment before doing the check
3365 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3366 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3367 -- reflects the last assignment, not this one!
3369 if Ekind (F) = E_Out_Parameter then
3370 if Warn_On_Modified_As_Out_Parameter (F)
3371 and then Is_Entity_Name (A)
3372 and then Present (Entity (A))
3373 and then Comes_From_Source (N)
3375 Warn_On_Useless_Assignment (Entity (A), A);
3379 -- Validate the form of the actual. Note that the call to
3380 -- Is_OK_Variable_For_Out_Formal generates the required
3381 -- reference in this case.
3383 if not Is_OK_Variable_For_Out_Formal (A) then
3384 Error_Msg_NE ("actual for& must be a variable", A, F);
3387 -- What's the following about???
3389 if Is_Entity_Name (A) then
3390 Kill_Checks (Entity (A));
3396 if Etype (A) = Any_Type then
3397 Set_Etype (N, Any_Type);
3401 -- Apply appropriate range checks for in, out, and in-out
3402 -- parameters. Out and in-out parameters also need a separate
3403 -- check, if there is a type conversion, to make sure the return
3404 -- value meets the constraints of the variable before the
3407 -- Gigi looks at the check flag and uses the appropriate types.
3408 -- For now since one flag is used there is an optimization which
3409 -- might not be done in the In Out case since Gigi does not do
3410 -- any analysis. More thought required about this ???
3412 if Ekind (F) = E_In_Parameter
3413 or else Ekind (F) = E_In_Out_Parameter
3415 if Is_Scalar_Type (Etype (A)) then
3416 Apply_Scalar_Range_Check (A, F_Typ);
3418 elsif Is_Array_Type (Etype (A)) then
3419 Apply_Length_Check (A, F_Typ);
3421 elsif Is_Record_Type (F_Typ)
3422 and then Has_Discriminants (F_Typ)
3423 and then Is_Constrained (F_Typ)
3424 and then (not Is_Derived_Type (F_Typ)
3425 or else Comes_From_Source (Nam))
3427 Apply_Discriminant_Check (A, F_Typ);
3429 elsif Is_Access_Type (F_Typ)
3430 and then Is_Array_Type (Designated_Type (F_Typ))
3431 and then Is_Constrained (Designated_Type (F_Typ))
3433 Apply_Length_Check (A, F_Typ);
3435 elsif Is_Access_Type (F_Typ)
3436 and then Has_Discriminants (Designated_Type (F_Typ))
3437 and then Is_Constrained (Designated_Type (F_Typ))
3439 Apply_Discriminant_Check (A, F_Typ);
3442 Apply_Range_Check (A, F_Typ);
3445 -- Ada 2005 (AI-231)
3447 if Ada_Version >= Ada_05
3448 and then Is_Access_Type (F_Typ)
3449 and then Can_Never_Be_Null (F_Typ)
3450 and then Known_Null (A)
3452 Apply_Compile_Time_Constraint_Error
3454 Msg => "(Ada 2005) null not allowed in "
3455 & "null-excluding formal?",
3456 Reason => CE_Null_Not_Allowed);
3460 if Ekind (F) = E_Out_Parameter
3461 or else Ekind (F) = E_In_Out_Parameter
3463 if Nkind (A) = N_Type_Conversion then
3464 if Is_Scalar_Type (A_Typ) then
3465 Apply_Scalar_Range_Check
3466 (Expression (A), Etype (Expression (A)), A_Typ);
3469 (Expression (A), Etype (Expression (A)), A_Typ);
3473 if Is_Scalar_Type (F_Typ) then
3474 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3476 elsif Is_Array_Type (F_Typ)
3477 and then Ekind (F) = E_Out_Parameter
3479 Apply_Length_Check (A, F_Typ);
3482 Apply_Range_Check (A, A_Typ, F_Typ);
3487 -- An actual associated with an access parameter is implicitly
3488 -- converted to the anonymous access type of the formal and must
3489 -- satisfy the legality checks for access conversions.
3491 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3492 if not Valid_Conversion (A, F_Typ, A) then
3494 ("invalid implicit conversion for access parameter", A);
3498 -- Check bad case of atomic/volatile argument (RM C.6(12))
3500 if Is_By_Reference_Type (Etype (F))
3501 and then Comes_From_Source (N)
3503 if Is_Atomic_Object (A)
3504 and then not Is_Atomic (Etype (F))
3507 ("cannot pass atomic argument to non-atomic formal",
3510 elsif Is_Volatile_Object (A)
3511 and then not Is_Volatile (Etype (F))
3514 ("cannot pass volatile argument to non-volatile formal",
3519 -- Check that subprograms don't have improper controlling
3520 -- arguments (RM 3.9.2 (9))
3522 -- A primitive operation may have an access parameter of an
3523 -- incomplete tagged type, but a dispatching call is illegal
3524 -- if the type is still incomplete.
3526 if Is_Controlling_Formal (F) then
3527 Set_Is_Controlling_Actual (A);
3529 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3531 Desig : constant Entity_Id := Designated_Type (Etype (F));
3533 if Ekind (Desig) = E_Incomplete_Type
3534 and then No (Full_View (Desig))
3535 and then No (Non_Limited_View (Desig))
3538 ("premature use of incomplete type& " &
3539 "in dispatching call", A, Desig);
3544 elsif Nkind (A) = N_Explicit_Dereference then
3545 Validate_Remote_Access_To_Class_Wide_Type (A);
3548 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3549 and then not Is_Class_Wide_Type (F_Typ)
3550 and then not Is_Controlling_Formal (F)
3552 Error_Msg_N ("class-wide argument not allowed here!", A);
3554 if Is_Subprogram (Nam)
3555 and then Comes_From_Source (Nam)
3557 Error_Msg_Node_2 := F_Typ;
3559 ("& is not a dispatching operation of &!", A, Nam);
3562 elsif Is_Access_Type (A_Typ)
3563 and then Is_Access_Type (F_Typ)
3564 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3565 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3566 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3567 or else (Nkind (A) = N_Attribute_Reference
3569 Is_Class_Wide_Type (Etype (Prefix (A)))))
3570 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3571 and then not Is_Controlling_Formal (F)
3574 ("access to class-wide argument not allowed here!", A);
3576 if Is_Subprogram (Nam)
3577 and then Comes_From_Source (Nam)
3579 Error_Msg_Node_2 := Designated_Type (F_Typ);
3581 ("& is not a dispatching operation of &!", A, Nam);
3587 -- If it is a named association, treat the selector_name as
3588 -- a proper identifier, and mark the corresponding entity.
3590 if Nkind (Parent (A)) = N_Parameter_Association then
3591 Set_Entity (Selector_Name (Parent (A)), F);
3592 Generate_Reference (F, Selector_Name (Parent (A)));
3593 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3594 Generate_Reference (F_Typ, N, ' ');
3599 if Ekind (F) /= E_Out_Parameter then
3600 Check_Unset_Reference (A);
3605 -- Case where actual is not present
3613 end Resolve_Actuals;
3615 -----------------------
3616 -- Resolve_Allocator --
3617 -----------------------
3619 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
3620 E : constant Node_Id := Expression (N);
3622 Discrim : Entity_Id;
3625 Assoc : Node_Id := Empty;
3628 procedure Check_Allocator_Discrim_Accessibility
3629 (Disc_Exp : Node_Id;
3630 Alloc_Typ : Entity_Id);
3631 -- Check that accessibility level associated with an access discriminant
3632 -- initialized in an allocator by the expression Disc_Exp is not deeper
3633 -- than the level of the allocator type Alloc_Typ. An error message is
3634 -- issued if this condition is violated. Specialized checks are done for
3635 -- the cases of a constraint expression which is an access attribute or
3636 -- an access discriminant.
3638 function In_Dispatching_Context return Boolean;
3639 -- If the allocator is an actual in a call, it is allowed to be class-
3640 -- wide when the context is not because it is a controlling actual.
3642 procedure Propagate_Coextensions (Root : Node_Id);
3643 -- Propagate all nested coextensions which are located one nesting
3644 -- level down the tree to the node Root. Example:
3647 -- Level_1_Coextension
3648 -- Level_2_Coextension
3650 -- The algorithm is paired with delay actions done by the Expander. In
3651 -- the above example, assume all coextensions are controlled types.
3652 -- The cycle of analysis, resolution and expansion will yield:
3654 -- 1) Analyze Top_Record
3655 -- 2) Analyze Level_1_Coextension
3656 -- 3) Analyze Level_2_Coextension
3657 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
3659 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3660 -- generated to capture the allocated object. Temp_1 is attached
3661 -- to the coextension chain of Level_2_Coextension.
3662 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3663 -- coextension. A forward tree traversal is performed which finds
3664 -- Level_2_Coextension's list and copies its contents into its
3666 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3667 -- generated to capture the allocated object. Temp_2 is attached
3668 -- to the coextension chain of Level_1_Coextension. Currently, the
3669 -- contents of the list are [Temp_2, Temp_1].
3670 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3671 -- finds Level_1_Coextension's list and copies its contents into
3673 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3674 -- Temp_2 and attach them to Top_Record's finalization list.
3676 -------------------------------------------
3677 -- Check_Allocator_Discrim_Accessibility --
3678 -------------------------------------------
3680 procedure Check_Allocator_Discrim_Accessibility
3681 (Disc_Exp : Node_Id;
3682 Alloc_Typ : Entity_Id)
3685 if Type_Access_Level (Etype (Disc_Exp)) >
3686 Type_Access_Level (Alloc_Typ)
3689 ("operand type has deeper level than allocator type", Disc_Exp);
3691 -- When the expression is an Access attribute the level of the prefix
3692 -- object must not be deeper than that of the allocator's type.
3694 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3695 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3697 and then Object_Access_Level (Prefix (Disc_Exp))
3698 > Type_Access_Level (Alloc_Typ)
3701 ("prefix of attribute has deeper level than allocator type",
3704 -- When the expression is an access discriminant the check is against
3705 -- the level of the prefix object.
3707 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3708 and then Nkind (Disc_Exp) = N_Selected_Component
3709 and then Object_Access_Level (Prefix (Disc_Exp))
3710 > Type_Access_Level (Alloc_Typ)
3713 ("access discriminant has deeper level than allocator type",
3716 -- All other cases are legal
3721 end Check_Allocator_Discrim_Accessibility;
3723 ----------------------------
3724 -- In_Dispatching_Context --
3725 ----------------------------
3727 function In_Dispatching_Context return Boolean is
3728 Par : constant Node_Id := Parent (N);
3730 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
3731 and then Is_Entity_Name (Name (Par))
3732 and then Is_Dispatching_Operation (Entity (Name (Par)));
3733 end In_Dispatching_Context;
3735 ----------------------------
3736 -- Propagate_Coextensions --
3737 ----------------------------
3739 procedure Propagate_Coextensions (Root : Node_Id) is
3741 procedure Copy_List (From : Elist_Id; To : Elist_Id);
3742 -- Copy the contents of list From into list To, preserving the
3743 -- order of elements.
3745 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
3746 -- Recognize an allocator or a rewritten allocator node and add it
3747 -- along with its nested coextensions to the list of Root.
3753 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
3754 From_Elmt : Elmt_Id;
3756 From_Elmt := First_Elmt (From);
3757 while Present (From_Elmt) loop
3758 Append_Elmt (Node (From_Elmt), To);
3759 Next_Elmt (From_Elmt);
3763 -----------------------
3764 -- Process_Allocator --
3765 -----------------------
3767 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
3768 Orig_Nod : Node_Id := Nod;
3771 -- This is a possible rewritten subtype indication allocator. Any
3772 -- nested coextensions will appear as discriminant constraints.
3774 if Nkind (Nod) = N_Identifier
3775 and then Present (Original_Node (Nod))
3776 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
3780 Discr_Elmt : Elmt_Id;
3783 if Is_Record_Type (Entity (Nod)) then
3785 First_Elmt (Discriminant_Constraint (Entity (Nod)));
3786 while Present (Discr_Elmt) loop
3787 Discr := Node (Discr_Elmt);
3789 if Nkind (Discr) = N_Identifier
3790 and then Present (Original_Node (Discr))
3791 and then Nkind (Original_Node (Discr)) = N_Allocator
3792 and then Present (Coextensions (
3793 Original_Node (Discr)))
3795 if No (Coextensions (Root)) then
3796 Set_Coextensions (Root, New_Elmt_List);
3800 (From => Coextensions (Original_Node (Discr)),
3801 To => Coextensions (Root));
3804 Next_Elmt (Discr_Elmt);
3807 -- There is no need to continue the traversal of this
3808 -- subtree since all the information has already been
3815 -- Case of either a stand alone allocator or a rewritten allocator
3816 -- with an aggregate.
3819 if Present (Original_Node (Nod)) then
3820 Orig_Nod := Original_Node (Nod);
3823 if Nkind (Orig_Nod) = N_Allocator then
3825 -- Propagate the list of nested coextensions to the Root
3826 -- allocator. This is done through list copy since a single
3827 -- allocator may have multiple coextensions. Do not touch
3828 -- coextensions roots.
3830 if not Is_Coextension_Root (Orig_Nod)
3831 and then Present (Coextensions (Orig_Nod))
3833 if No (Coextensions (Root)) then
3834 Set_Coextensions (Root, New_Elmt_List);
3838 (From => Coextensions (Orig_Nod),
3839 To => Coextensions (Root));
3842 -- There is no need to continue the traversal of this
3843 -- subtree since all the information has already been
3850 -- Keep on traversing, looking for the next allocator
3853 end Process_Allocator;
3855 procedure Process_Allocators is
3856 new Traverse_Proc (Process_Allocator);
3858 -- Start of processing for Propagate_Coextensions
3861 Process_Allocators (Expression (Root));
3862 end Propagate_Coextensions;
3864 -- Start of processing for Resolve_Allocator
3867 -- Replace general access with specific type
3869 if Ekind (Etype (N)) = E_Allocator_Type then
3870 Set_Etype (N, Base_Type (Typ));
3873 if Is_Abstract_Type (Typ) then
3874 Error_Msg_N ("type of allocator cannot be abstract", N);
3877 -- For qualified expression, resolve the expression using the
3878 -- given subtype (nothing to do for type mark, subtype indication)
3880 if Nkind (E) = N_Qualified_Expression then
3881 if Is_Class_Wide_Type (Etype (E))
3882 and then not Is_Class_Wide_Type (Designated_Type (Typ))
3883 and then not In_Dispatching_Context
3886 ("class-wide allocator not allowed for this access type", N);
3889 Resolve (Expression (E), Etype (E));
3890 Check_Unset_Reference (Expression (E));
3892 -- A qualified expression requires an exact match of the type,
3893 -- class-wide matching is not allowed.
3895 if (Is_Class_Wide_Type (Etype (Expression (E)))
3896 or else Is_Class_Wide_Type (Etype (E)))
3897 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
3899 Wrong_Type (Expression (E), Etype (E));
3902 -- A special accessibility check is needed for allocators that
3903 -- constrain access discriminants. The level of the type of the
3904 -- expression used to constrain an access discriminant cannot be
3905 -- deeper than the type of the allocator (in contrast to access
3906 -- parameters, where the level of the actual can be arbitrary).
3908 -- We can't use Valid_Conversion to perform this check because
3909 -- in general the type of the allocator is unrelated to the type
3910 -- of the access discriminant.
3912 if Ekind (Typ) /= E_Anonymous_Access_Type
3913 or else Is_Local_Anonymous_Access (Typ)
3915 Subtyp := Entity (Subtype_Mark (E));
3917 Aggr := Original_Node (Expression (E));
3919 if Has_Discriminants (Subtyp)
3920 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
3922 Discrim := First_Discriminant (Base_Type (Subtyp));
3924 -- Get the first component expression of the aggregate
3926 if Present (Expressions (Aggr)) then
3927 Disc_Exp := First (Expressions (Aggr));
3929 elsif Present (Component_Associations (Aggr)) then
3930 Assoc := First (Component_Associations (Aggr));
3932 if Present (Assoc) then
3933 Disc_Exp := Expression (Assoc);
3942 while Present (Discrim) and then Present (Disc_Exp) loop
3943 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
3944 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
3947 Next_Discriminant (Discrim);
3949 if Present (Discrim) then
3950 if Present (Assoc) then
3952 Disc_Exp := Expression (Assoc);
3954 elsif Present (Next (Disc_Exp)) then
3958 Assoc := First (Component_Associations (Aggr));
3960 if Present (Assoc) then
3961 Disc_Exp := Expression (Assoc);
3971 -- For a subtype mark or subtype indication, freeze the subtype
3974 Freeze_Expression (E);
3976 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
3978 ("initialization required for access-to-constant allocator", N);
3981 -- A special accessibility check is needed for allocators that
3982 -- constrain access discriminants. The level of the type of the
3983 -- expression used to constrain an access discriminant cannot be
3984 -- deeper than the type of the allocator (in contrast to access
3985 -- parameters, where the level of the actual can be arbitrary).
3986 -- We can't use Valid_Conversion to perform this check because
3987 -- in general the type of the allocator is unrelated to the type
3988 -- of the access discriminant.
3990 if Nkind (Original_Node (E)) = N_Subtype_Indication
3991 and then (Ekind (Typ) /= E_Anonymous_Access_Type
3992 or else Is_Local_Anonymous_Access (Typ))
3994 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
3996 if Has_Discriminants (Subtyp) then
3997 Discrim := First_Discriminant (Base_Type (Subtyp));
3998 Constr := First (Constraints (Constraint (Original_Node (E))));
3999 while Present (Discrim) and then Present (Constr) loop
4000 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4001 if Nkind (Constr) = N_Discriminant_Association then
4002 Disc_Exp := Original_Node (Expression (Constr));
4004 Disc_Exp := Original_Node (Constr);
4007 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4010 Next_Discriminant (Discrim);
4017 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4018 -- check that the level of the type of the created object is not deeper
4019 -- than the level of the allocator's access type, since extensions can
4020 -- now occur at deeper levels than their ancestor types. This is a
4021 -- static accessibility level check; a run-time check is also needed in
4022 -- the case of an initialized allocator with a class-wide argument (see
4023 -- Expand_Allocator_Expression).
4025 if Ada_Version >= Ada_05
4026 and then Is_Class_Wide_Type (Designated_Type (Typ))
4029 Exp_Typ : Entity_Id;
4032 if Nkind (E) = N_Qualified_Expression then
4033 Exp_Typ := Etype (E);
4034 elsif Nkind (E) = N_Subtype_Indication then
4035 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4037 Exp_Typ := Entity (E);
4040 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4041 if In_Instance_Body then
4042 Error_Msg_N ("?type in allocator has deeper level than" &
4043 " designated class-wide type", E);
4044 Error_Msg_N ("\?Program_Error will be raised at run time",
4047 Make_Raise_Program_Error (Sloc (N),
4048 Reason => PE_Accessibility_Check_Failed));
4051 -- Do not apply Ada 2005 accessibility checks on a class-wide
4052 -- allocator if the type given in the allocator is a formal
4053 -- type. A run-time check will be performed in the instance.
4055 elsif not Is_Generic_Type (Exp_Typ) then
4056 Error_Msg_N ("type in allocator has deeper level than" &
4057 " designated class-wide type", E);
4063 -- Check for allocation from an empty storage pool
4065 if No_Pool_Assigned (Typ) then
4067 Loc : constant Source_Ptr := Sloc (N);
4069 Error_Msg_N ("?allocation from empty storage pool!", N);
4070 Error_Msg_N ("\?Storage_Error will be raised at run time!", N);
4072 Make_Raise_Storage_Error (Loc,
4073 Reason => SE_Empty_Storage_Pool));
4076 -- If the context is an unchecked conversion, as may happen within
4077 -- an inlined subprogram, the allocator is being resolved with its
4078 -- own anonymous type. In that case, if the target type has a specific
4079 -- storage pool, it must be inherited explicitly by the allocator type.
4081 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4082 and then No (Associated_Storage_Pool (Typ))
4084 Set_Associated_Storage_Pool
4085 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4088 -- An erroneous allocator may be rewritten as a raise Program_Error
4091 if Nkind (N) = N_Allocator then
4093 -- An anonymous access discriminant is the definition of a
4096 if Ekind (Typ) = E_Anonymous_Access_Type
4097 and then Nkind (Associated_Node_For_Itype (Typ)) =
4098 N_Discriminant_Specification
4100 -- Avoid marking an allocator as a dynamic coextension if it is
4101 -- within a static construct.
4103 if not Is_Static_Coextension (N) then
4104 Set_Is_Dynamic_Coextension (N);
4107 -- Cleanup for potential static coextensions
4110 Set_Is_Dynamic_Coextension (N, False);
4111 Set_Is_Static_Coextension (N, False);
4114 -- There is no need to propagate any nested coextensions if they
4115 -- are marked as static since they will be rewritten on the spot.
4117 if not Is_Static_Coextension (N) then
4118 Propagate_Coextensions (N);
4121 end Resolve_Allocator;
4123 ---------------------------
4124 -- Resolve_Arithmetic_Op --
4125 ---------------------------
4127 -- Used for resolving all arithmetic operators except exponentiation
4129 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4130 L : constant Node_Id := Left_Opnd (N);
4131 R : constant Node_Id := Right_Opnd (N);
4132 TL : constant Entity_Id := Base_Type (Etype (L));
4133 TR : constant Entity_Id := Base_Type (Etype (R));
4137 B_Typ : constant Entity_Id := Base_Type (Typ);
4138 -- We do the resolution using the base type, because intermediate values
4139 -- in expressions always are of the base type, not a subtype of it.
4141 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4142 -- Returns True if N is in a context that expects "any real type"
4144 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4145 -- Return True iff given type is Integer or universal real/integer
4147 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4148 -- Choose type of integer literal in fixed-point operation to conform
4149 -- to available fixed-point type. T is the type of the other operand,
4150 -- which is needed to determine the expected type of N.
4152 procedure Set_Operand_Type (N : Node_Id);
4153 -- Set operand type to T if universal
4155 -------------------------------
4156 -- Expected_Type_Is_Any_Real --
4157 -------------------------------
4159 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4161 -- N is the expression after "delta" in a fixed_point_definition;
4164 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4165 N_Decimal_Fixed_Point_Definition,
4167 -- N is one of the bounds in a real_range_specification;
4170 N_Real_Range_Specification,
4172 -- N is the expression of a delta_constraint;
4175 N_Delta_Constraint);
4176 end Expected_Type_Is_Any_Real;
4178 -----------------------------
4179 -- Is_Integer_Or_Universal --
4180 -----------------------------
4182 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4184 Index : Interp_Index;
4188 if not Is_Overloaded (N) then
4190 return Base_Type (T) = Base_Type (Standard_Integer)
4191 or else T = Universal_Integer
4192 or else T = Universal_Real;
4194 Get_First_Interp (N, Index, It);
4195 while Present (It.Typ) loop
4196 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4197 or else It.Typ = Universal_Integer
4198 or else It.Typ = Universal_Real
4203 Get_Next_Interp (Index, It);
4208 end Is_Integer_Or_Universal;
4210 ----------------------------
4211 -- Set_Mixed_Mode_Operand --
4212 ----------------------------
4214 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4215 Index : Interp_Index;
4219 if Universal_Interpretation (N) = Universal_Integer then
4221 -- A universal integer literal is resolved as standard integer
4222 -- except in the case of a fixed-point result, where we leave it
4223 -- as universal (to be handled by Exp_Fixd later on)
4225 if Is_Fixed_Point_Type (T) then
4226 Resolve (N, Universal_Integer);
4228 Resolve (N, Standard_Integer);
4231 elsif Universal_Interpretation (N) = Universal_Real
4232 and then (T = Base_Type (Standard_Integer)
4233 or else T = Universal_Integer
4234 or else T = Universal_Real)
4236 -- A universal real can appear in a fixed-type context. We resolve
4237 -- the literal with that context, even though this might raise an
4238 -- exception prematurely (the other operand may be zero).
4242 elsif Etype (N) = Base_Type (Standard_Integer)
4243 and then T = Universal_Real
4244 and then Is_Overloaded (N)
4246 -- Integer arg in mixed-mode operation. Resolve with universal
4247 -- type, in case preference rule must be applied.
4249 Resolve (N, Universal_Integer);
4252 and then B_Typ /= Universal_Fixed
4254 -- Not a mixed-mode operation, resolve with context
4258 elsif Etype (N) = Any_Fixed then
4260 -- N may itself be a mixed-mode operation, so use context type
4264 elsif Is_Fixed_Point_Type (T)
4265 and then B_Typ = Universal_Fixed
4266 and then Is_Overloaded (N)
4268 -- Must be (fixed * fixed) operation, operand must have one
4269 -- compatible interpretation.
4271 Resolve (N, Any_Fixed);
4273 elsif Is_Fixed_Point_Type (B_Typ)
4274 and then (T = Universal_Real
4275 or else Is_Fixed_Point_Type (T))
4276 and then Is_Overloaded (N)
4278 -- C * F(X) in a fixed context, where C is a real literal or a
4279 -- fixed-point expression. F must have either a fixed type
4280 -- interpretation or an integer interpretation, but not both.
4282 Get_First_Interp (N, Index, It);
4283 while Present (It.Typ) loop
4284 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4286 if Analyzed (N) then
4287 Error_Msg_N ("ambiguous operand in fixed operation", N);
4289 Resolve (N, Standard_Integer);
4292 elsif Is_Fixed_Point_Type (It.Typ) then
4294 if Analyzed (N) then
4295 Error_Msg_N ("ambiguous operand in fixed operation", N);
4297 Resolve (N, It.Typ);
4301 Get_Next_Interp (Index, It);
4304 -- Reanalyze the literal with the fixed type of the context. If
4305 -- context is Universal_Fixed, we are within a conversion, leave
4306 -- the literal as a universal real because there is no usable
4307 -- fixed type, and the target of the conversion plays no role in
4321 if B_Typ = Universal_Fixed
4322 and then Nkind (Op2) = N_Real_Literal
4324 T2 := Universal_Real;
4329 Set_Analyzed (Op2, False);
4336 end Set_Mixed_Mode_Operand;
4338 ----------------------
4339 -- Set_Operand_Type --
4340 ----------------------
4342 procedure Set_Operand_Type (N : Node_Id) is
4344 if Etype (N) = Universal_Integer
4345 or else Etype (N) = Universal_Real
4349 end Set_Operand_Type;
4351 -- Start of processing for Resolve_Arithmetic_Op
4354 if Comes_From_Source (N)
4355 and then Ekind (Entity (N)) = E_Function
4356 and then Is_Imported (Entity (N))
4357 and then Is_Intrinsic_Subprogram (Entity (N))
4359 Resolve_Intrinsic_Operator (N, Typ);
4362 -- Special-case for mixed-mode universal expressions or fixed point
4363 -- type operation: each argument is resolved separately. The same
4364 -- treatment is required if one of the operands of a fixed point
4365 -- operation is universal real, since in this case we don't do a
4366 -- conversion to a specific fixed-point type (instead the expander
4367 -- takes care of the case).
4369 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4370 and then Present (Universal_Interpretation (L))
4371 and then Present (Universal_Interpretation (R))
4373 Resolve (L, Universal_Interpretation (L));
4374 Resolve (R, Universal_Interpretation (R));
4375 Set_Etype (N, B_Typ);
4377 elsif (B_Typ = Universal_Real
4378 or else Etype (N) = Universal_Fixed
4379 or else (Etype (N) = Any_Fixed
4380 and then Is_Fixed_Point_Type (B_Typ))
4381 or else (Is_Fixed_Point_Type (B_Typ)
4382 and then (Is_Integer_Or_Universal (L)
4384 Is_Integer_Or_Universal (R))))
4385 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4387 if TL = Universal_Integer or else TR = Universal_Integer then
4388 Check_For_Visible_Operator (N, B_Typ);
4391 -- If context is a fixed type and one operand is integer, the
4392 -- other is resolved with the type of the context.
4394 if Is_Fixed_Point_Type (B_Typ)
4395 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4396 or else TL = Universal_Integer)
4401 elsif Is_Fixed_Point_Type (B_Typ)
4402 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4403 or else TR = Universal_Integer)
4409 Set_Mixed_Mode_Operand (L, TR);
4410 Set_Mixed_Mode_Operand (R, TL);
4413 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4414 -- multiplying operators from being used when the expected type is
4415 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4416 -- some cases where the expected type is actually Any_Real;
4417 -- Expected_Type_Is_Any_Real takes care of that case.
4419 if Etype (N) = Universal_Fixed
4420 or else Etype (N) = Any_Fixed
4422 if B_Typ = Universal_Fixed
4423 and then not Expected_Type_Is_Any_Real (N)
4424 and then not Nkind_In (Parent (N), N_Type_Conversion,
4425 N_Unchecked_Type_Conversion)
4427 Error_Msg_N ("type cannot be determined from context!", N);
4428 Error_Msg_N ("\explicit conversion to result type required", N);
4430 Set_Etype (L, Any_Type);
4431 Set_Etype (R, Any_Type);
4434 if Ada_Version = Ada_83
4435 and then Etype (N) = Universal_Fixed
4437 Nkind_In (Parent (N), N_Type_Conversion,
4438 N_Unchecked_Type_Conversion)
4441 ("(Ada 83) fixed-point operation "
4442 & "needs explicit conversion", N);
4445 -- The expected type is "any real type" in contexts like
4446 -- type T is delta <universal_fixed-expression> ...
4447 -- in which case we need to set the type to Universal_Real
4448 -- so that static expression evaluation will work properly.
4450 if Expected_Type_Is_Any_Real (N) then
4451 Set_Etype (N, Universal_Real);
4453 Set_Etype (N, B_Typ);
4457 elsif Is_Fixed_Point_Type (B_Typ)
4458 and then (Is_Integer_Or_Universal (L)
4459 or else Nkind (L) = N_Real_Literal
4460 or else Nkind (R) = N_Real_Literal
4461 or else Is_Integer_Or_Universal (R))
4463 Set_Etype (N, B_Typ);
4465 elsif Etype (N) = Any_Fixed then
4467 -- If no previous errors, this is only possible if one operand
4468 -- is overloaded and the context is universal. Resolve as such.
4470 Set_Etype (N, B_Typ);
4474 if (TL = Universal_Integer or else TL = Universal_Real)
4476 (TR = Universal_Integer or else TR = Universal_Real)
4478 Check_For_Visible_Operator (N, B_Typ);
4481 -- If the context is Universal_Fixed and the operands are also
4482 -- universal fixed, this is an error, unless there is only one
4483 -- applicable fixed_point type (usually duration).
4485 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4486 T := Unique_Fixed_Point_Type (N);
4488 if T = Any_Type then
4501 -- If one of the arguments was resolved to a non-universal type.
4502 -- label the result of the operation itself with the same type.
4503 -- Do the same for the universal argument, if any.
4505 T := Intersect_Types (L, R);
4506 Set_Etype (N, Base_Type (T));
4507 Set_Operand_Type (L);
4508 Set_Operand_Type (R);
4511 Generate_Operator_Reference (N, Typ);
4512 Eval_Arithmetic_Op (N);
4514 -- Set overflow and division checking bit. Much cleverer code needed
4515 -- here eventually and perhaps the Resolve routines should be separated
4516 -- for the various arithmetic operations, since they will need
4517 -- different processing. ???
4519 if Nkind (N) in N_Op then
4520 if not Overflow_Checks_Suppressed (Etype (N)) then
4521 Enable_Overflow_Check (N);
4524 -- Give warning if explicit division by zero
4526 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4527 and then not Division_Checks_Suppressed (Etype (N))
4529 Rop := Right_Opnd (N);
4531 if Compile_Time_Known_Value (Rop)
4532 and then ((Is_Integer_Type (Etype (Rop))
4533 and then Expr_Value (Rop) = Uint_0)
4535 (Is_Real_Type (Etype (Rop))
4536 and then Expr_Value_R (Rop) = Ureal_0))
4538 -- Specialize the warning message according to the operation
4542 Apply_Compile_Time_Constraint_Error
4543 (N, "division by zero?", CE_Divide_By_Zero,
4544 Loc => Sloc (Right_Opnd (N)));
4547 Apply_Compile_Time_Constraint_Error
4548 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4549 Loc => Sloc (Right_Opnd (N)));
4552 Apply_Compile_Time_Constraint_Error
4553 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4554 Loc => Sloc (Right_Opnd (N)));
4556 -- Division by zero can only happen with division, rem,
4557 -- and mod operations.
4560 raise Program_Error;
4563 -- Otherwise just set the flag to check at run time
4566 Activate_Division_Check (N);
4570 -- If Restriction No_Implicit_Conditionals is active, then it is
4571 -- violated if either operand can be negative for mod, or for rem
4572 -- if both operands can be negative.
4574 if Restrictions.Set (No_Implicit_Conditionals)
4575 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4584 -- Set if corresponding operand might be negative
4587 Determine_Range (Left_Opnd (N), OK, Lo, Hi);
4588 LNeg := (not OK) or else Lo < 0;
4590 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
4591 RNeg := (not OK) or else Lo < 0;
4593 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4595 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
4597 Check_Restriction (No_Implicit_Conditionals, N);
4603 Check_Unset_Reference (L);
4604 Check_Unset_Reference (R);
4605 end Resolve_Arithmetic_Op;
4611 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
4612 Loc : constant Source_Ptr := Sloc (N);
4613 Subp : constant Node_Id := Name (N);
4622 -- The context imposes a unique interpretation with type Typ on a
4623 -- procedure or function call. Find the entity of the subprogram that
4624 -- yields the expected type, and propagate the corresponding formal
4625 -- constraints on the actuals. The caller has established that an
4626 -- interpretation exists, and emitted an error if not unique.
4628 -- First deal with the case of a call to an access-to-subprogram,
4629 -- dereference made explicit in Analyze_Call.
4631 if Ekind (Etype (Subp)) = E_Subprogram_Type then
4632 if not Is_Overloaded (Subp) then
4633 Nam := Etype (Subp);
4636 -- Find the interpretation whose type (a subprogram type) has a
4637 -- return type that is compatible with the context. Analysis of
4638 -- the node has established that one exists.
4642 Get_First_Interp (Subp, I, It);
4643 while Present (It.Typ) loop
4644 if Covers (Typ, Etype (It.Typ)) then
4649 Get_Next_Interp (I, It);
4653 raise Program_Error;
4657 -- If the prefix is not an entity, then resolve it
4659 if not Is_Entity_Name (Subp) then
4660 Resolve (Subp, Nam);
4663 -- For an indirect call, we always invalidate checks, since we do not
4664 -- know whether the subprogram is local or global. Yes we could do
4665 -- better here, e.g. by knowing that there are no local subprograms,
4666 -- but it does not seem worth the effort. Similarly, we kill all
4667 -- knowledge of current constant values.
4669 Kill_Current_Values;
4671 -- If this is a procedure call which is really an entry call, do
4672 -- the conversion of the procedure call to an entry call. Protected
4673 -- operations use the same circuitry because the name in the call
4674 -- can be an arbitrary expression with special resolution rules.
4676 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
4677 or else (Is_Entity_Name (Subp)
4678 and then Ekind (Entity (Subp)) = E_Entry)
4680 Resolve_Entry_Call (N, Typ);
4681 Check_Elab_Call (N);
4683 -- Kill checks and constant values, as above for indirect case
4684 -- Who knows what happens when another task is activated?
4686 Kill_Current_Values;
4689 -- Normal subprogram call with name established in Resolve
4691 elsif not (Is_Type (Entity (Subp))) then
4692 Nam := Entity (Subp);
4693 Set_Entity_With_Style_Check (Subp, Nam);
4695 -- Otherwise we must have the case of an overloaded call
4698 pragma Assert (Is_Overloaded (Subp));
4699 Nam := Empty; -- We know that it will be assigned in loop below
4701 Get_First_Interp (Subp, I, It);
4702 while Present (It.Typ) loop
4703 if Covers (Typ, It.Typ) then
4705 Set_Entity_With_Style_Check (Subp, Nam);
4709 Get_Next_Interp (I, It);
4713 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
4714 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
4715 and then Nkind (Subp) /= N_Explicit_Dereference
4716 and then Present (Parameter_Associations (N))
4718 -- The prefix is a parameterless function call that returns an access
4719 -- to subprogram. If parameters are present in the current call, add
4720 -- add an explicit dereference. We use the base type here because
4721 -- within an instance these may be subtypes.
4723 -- The dereference is added either in Analyze_Call or here. Should
4724 -- be consolidated ???
4726 Set_Is_Overloaded (Subp, False);
4727 Set_Etype (Subp, Etype (Nam));
4728 Insert_Explicit_Dereference (Subp);
4729 Nam := Designated_Type (Etype (Nam));
4730 Resolve (Subp, Nam);
4733 -- Check that a call to Current_Task does not occur in an entry body
4735 if Is_RTE (Nam, RE_Current_Task) then
4744 -- Exclude calls that occur within the default of a formal
4745 -- parameter of the entry, since those are evaluated outside
4748 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
4750 if Nkind (P) = N_Entry_Body
4751 or else (Nkind (P) = N_Subprogram_Body
4752 and then Is_Entry_Barrier_Function (P))
4756 ("?& should not be used in entry body (RM C.7(17))",
4759 ("\Program_Error will be raised at run time?", N, Nam);
4761 Make_Raise_Program_Error (Loc,
4762 Reason => PE_Current_Task_In_Entry_Body));
4763 Set_Etype (N, Rtype);
4770 -- Check that a procedure call does not occur in the context of the
4771 -- entry call statement of a conditional or timed entry call. Note that
4772 -- the case of a call to a subprogram renaming of an entry will also be
4773 -- rejected. The test for N not being an N_Entry_Call_Statement is
4774 -- defensive, covering the possibility that the processing of entry
4775 -- calls might reach this point due to later modifications of the code
4778 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4779 and then Nkind (N) /= N_Entry_Call_Statement
4780 and then Entry_Call_Statement (Parent (N)) = N
4782 if Ada_Version < Ada_05 then
4783 Error_Msg_N ("entry call required in select statement", N);
4785 -- Ada 2005 (AI-345): If a procedure_call_statement is used
4786 -- for a procedure_or_entry_call, the procedure_name or
4787 -- procedure_prefix of the procedure_call_statement shall denote
4788 -- an entry renamed by a procedure, or (a view of) a primitive
4789 -- subprogram of a limited interface whose first parameter is
4790 -- a controlling parameter.
4792 elsif Nkind (N) = N_Procedure_Call_Statement
4793 and then not Is_Renamed_Entry (Nam)
4794 and then not Is_Controlling_Limited_Procedure (Nam)
4797 ("entry call or dispatching primitive of interface required", N);
4801 -- Check that this is not a call to a protected procedure or entry from
4802 -- within a protected function.
4804 if Ekind (Current_Scope) = E_Function
4805 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
4806 and then Ekind (Nam) /= E_Function
4807 and then Scope (Nam) = Scope (Current_Scope)
4809 Error_Msg_N ("within protected function, protected " &
4810 "object is constant", N);
4811 Error_Msg_N ("\cannot call operation that may modify it", N);
4814 -- Freeze the subprogram name if not in a spec-expression. Note that we
4815 -- freeze procedure calls as well as function calls. Procedure calls are
4816 -- not frozen according to the rules (RM 13.14(14)) because it is
4817 -- impossible to have a procedure call to a non-frozen procedure in pure
4818 -- Ada, but in the code that we generate in the expander, this rule
4819 -- needs extending because we can generate procedure calls that need
4822 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
4823 Freeze_Expression (Subp);
4826 -- For a predefined operator, the type of the result is the type imposed
4827 -- by context, except for a predefined operation on universal fixed.
4828 -- Otherwise The type of the call is the type returned by the subprogram
4831 if Is_Predefined_Op (Nam) then
4832 if Etype (N) /= Universal_Fixed then
4836 -- If the subprogram returns an array type, and the context requires the
4837 -- component type of that array type, the node is really an indexing of
4838 -- the parameterless call. Resolve as such. A pathological case occurs
4839 -- when the type of the component is an access to the array type. In
4840 -- this case the call is truly ambiguous.
4842 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
4844 ((Is_Array_Type (Etype (Nam))
4845 and then Covers (Typ, Component_Type (Etype (Nam))))
4846 or else (Is_Access_Type (Etype (Nam))
4847 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4850 Component_Type (Designated_Type (Etype (Nam))))))
4853 Index_Node : Node_Id;
4855 Ret_Type : constant Entity_Id := Etype (Nam);
4858 if Is_Access_Type (Ret_Type)
4859 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
4862 ("cannot disambiguate function call and indexing", N);
4864 New_Subp := Relocate_Node (Subp);
4865 Set_Entity (Subp, Nam);
4867 if Component_Type (Ret_Type) /= Any_Type then
4868 if Needs_No_Actuals (Nam) then
4870 -- Indexed call to a parameterless function
4873 Make_Indexed_Component (Loc,
4875 Make_Function_Call (Loc,
4877 Expressions => Parameter_Associations (N));
4879 -- An Ada 2005 prefixed call to a primitive operation
4880 -- whose first parameter is the prefix. This prefix was
4881 -- prepended to the parameter list, which is actually a
4882 -- list of indices. Remove the prefix in order to build
4883 -- the proper indexed component.
4886 Make_Indexed_Component (Loc,
4888 Make_Function_Call (Loc,
4890 Parameter_Associations =>
4892 (Remove_Head (Parameter_Associations (N)))),
4893 Expressions => Parameter_Associations (N));
4896 -- Since we are correcting a node classification error made
4897 -- by the parser, we call Replace rather than Rewrite.
4899 Replace (N, Index_Node);
4900 Set_Etype (Prefix (N), Ret_Type);
4902 Resolve_Indexed_Component (N, Typ);
4903 Check_Elab_Call (Prefix (N));
4911 Set_Etype (N, Etype (Nam));
4914 -- In the case where the call is to an overloaded subprogram, Analyze
4915 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
4916 -- such a case Normalize_Actuals needs to be called once more to order
4917 -- the actuals correctly. Otherwise the call will have the ordering
4918 -- given by the last overloaded subprogram whether this is the correct
4919 -- one being called or not.
4921 if Is_Overloaded (Subp) then
4922 Normalize_Actuals (N, Nam, False, Norm_OK);
4923 pragma Assert (Norm_OK);
4926 -- In any case, call is fully resolved now. Reset Overload flag, to
4927 -- prevent subsequent overload resolution if node is analyzed again
4929 Set_Is_Overloaded (Subp, False);
4930 Set_Is_Overloaded (N, False);
4932 -- If we are calling the current subprogram from immediately within its
4933 -- body, then that is the case where we can sometimes detect cases of
4934 -- infinite recursion statically. Do not try this in case restriction
4935 -- No_Recursion is in effect anyway, and do it only for source calls.
4937 if Comes_From_Source (N) then
4938 Scop := Current_Scope;
4940 -- Issue warning for possible infinite recursion in the absence
4941 -- of the No_Recursion restriction.
4944 and then not Restriction_Active (No_Recursion)
4945 and then Check_Infinite_Recursion (N)
4947 -- Here we detected and flagged an infinite recursion, so we do
4948 -- not need to test the case below for further warnings. Also if
4949 -- we now have a raise SE node, we are all done.
4951 if Nkind (N) = N_Raise_Storage_Error then
4955 -- If call is to immediately containing subprogram, then check for
4956 -- the case of a possible run-time detectable infinite recursion.
4959 Scope_Loop : while Scop /= Standard_Standard loop
4962 -- Although in general case, recursion is not statically
4963 -- checkable, the case of calling an immediately containing
4964 -- subprogram is easy to catch.
4966 Check_Restriction (No_Recursion, N);
4968 -- If the recursive call is to a parameterless subprogram,
4969 -- then even if we can't statically detect infinite
4970 -- recursion, this is pretty suspicious, and we output a
4971 -- warning. Furthermore, we will try later to detect some
4972 -- cases here at run time by expanding checking code (see
4973 -- Detect_Infinite_Recursion in package Exp_Ch6).
4975 -- If the recursive call is within a handler, do not emit a
4976 -- warning, because this is a common idiom: loop until input
4977 -- is correct, catch illegal input in handler and restart.
4979 if No (First_Formal (Nam))
4980 and then Etype (Nam) = Standard_Void_Type
4981 and then not Error_Posted (N)
4982 and then Nkind (Parent (N)) /= N_Exception_Handler
4984 -- For the case of a procedure call. We give the message
4985 -- only if the call is the first statement in a sequence
4986 -- of statements, or if all previous statements are
4987 -- simple assignments. This is simply a heuristic to
4988 -- decrease false positives, without losing too many good
4989 -- warnings. The idea is that these previous statements
4990 -- may affect global variables the procedure depends on.
4992 if Nkind (N) = N_Procedure_Call_Statement
4993 and then Is_List_Member (N)
4999 while Present (P) loop
5000 if Nkind (P) /= N_Assignment_Statement then
5009 -- Do not give warning if we are in a conditional context
5012 K : constant Node_Kind := Nkind (Parent (N));
5014 if (K = N_Loop_Statement
5015 and then Present (Iteration_Scheme (Parent (N))))
5016 or else K = N_If_Statement
5017 or else K = N_Elsif_Part
5018 or else K = N_Case_Statement_Alternative
5024 -- Here warning is to be issued
5026 Set_Has_Recursive_Call (Nam);
5028 ("?possible infinite recursion!", N);
5030 ("\?Storage_Error may be raised at run time!", N);
5036 Scop := Scope (Scop);
5037 end loop Scope_Loop;
5041 -- If subprogram name is a predefined operator, it was given in
5042 -- functional notation. Replace call node with operator node, so
5043 -- that actuals can be resolved appropriately.
5045 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5046 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5049 elsif Present (Alias (Nam))
5050 and then Is_Predefined_Op (Alias (Nam))
5052 Resolve_Actuals (N, Nam);
5053 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5057 -- Create a transient scope if the resulting type requires it
5059 -- There are several notable exceptions:
5061 -- a) In init procs, the transient scope overhead is not needed, and is
5062 -- even incorrect when the call is a nested initialization call for a
5063 -- component whose expansion may generate adjust calls. However, if the
5064 -- call is some other procedure call within an initialization procedure
5065 -- (for example a call to Create_Task in the init_proc of the task
5066 -- run-time record) a transient scope must be created around this call.
5068 -- b) Enumeration literal pseudo-calls need no transient scope
5070 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5071 -- functions) do not use the secondary stack even though the return
5072 -- type may be unconstrained.
5074 -- d) Calls to a build-in-place function, since such functions may
5075 -- allocate their result directly in a target object, and cases where
5076 -- the result does get allocated in the secondary stack are checked for
5077 -- within the specialized Exp_Ch6 procedures for expanding those
5078 -- build-in-place calls.
5080 -- e) If the subprogram is marked Inline_Always, then even if it returns
5081 -- an unconstrained type the call does not require use of the secondary
5082 -- stack. However, inlining will only take place if the body to inline
5083 -- is already present. It may not be available if e.g. the subprogram is
5084 -- declared in a child instance.
5086 -- If this is an initialization call for a type whose construction
5087 -- uses the secondary stack, and it is not a nested call to initialize
5088 -- a component, we do need to create a transient scope for it. We
5089 -- check for this by traversing the type in Check_Initialization_Call.
5092 and then Has_Pragma_Inline_Always (Nam)
5093 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5094 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5098 elsif Ekind (Nam) = E_Enumeration_Literal
5099 or else Is_Build_In_Place_Function (Nam)
5100 or else Is_Intrinsic_Subprogram (Nam)
5104 elsif Expander_Active
5105 and then Is_Type (Etype (Nam))
5106 and then Requires_Transient_Scope (Etype (Nam))
5108 (not Within_Init_Proc
5110 (not Is_Init_Proc (Nam) and then Ekind (Nam) /= E_Function))
5112 Establish_Transient_Scope (N, Sec_Stack => True);
5114 -- If the call appears within the bounds of a loop, it will
5115 -- be rewritten and reanalyzed, nothing left to do here.
5117 if Nkind (N) /= N_Function_Call then
5121 elsif Is_Init_Proc (Nam)
5122 and then not Within_Init_Proc
5124 Check_Initialization_Call (N, Nam);
5127 -- A protected function cannot be called within the definition of the
5128 -- enclosing protected type.
5130 if Is_Protected_Type (Scope (Nam))
5131 and then In_Open_Scopes (Scope (Nam))
5132 and then not Has_Completion (Scope (Nam))
5135 ("& cannot be called before end of protected definition", N, Nam);
5138 -- Propagate interpretation to actuals, and add default expressions
5141 if Present (First_Formal (Nam)) then
5142 Resolve_Actuals (N, Nam);
5144 -- Overloaded literals are rewritten as function calls, for
5145 -- purpose of resolution. After resolution, we can replace
5146 -- the call with the literal itself.
5148 elsif Ekind (Nam) = E_Enumeration_Literal then
5149 Copy_Node (Subp, N);
5150 Resolve_Entity_Name (N, Typ);
5152 -- Avoid validation, since it is a static function call
5154 Generate_Reference (Nam, Subp);
5158 -- If the subprogram is not global, then kill all saved values and
5159 -- checks. This is a bit conservative, since in many cases we could do
5160 -- better, but it is not worth the effort. Similarly, we kill constant
5161 -- values. However we do not need to do this for internal entities
5162 -- (unless they are inherited user-defined subprograms), since they
5163 -- are not in the business of molesting local values.
5165 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5166 -- kill all checks and values for calls to global subprograms. This
5167 -- takes care of the case where an access to a local subprogram is
5168 -- taken, and could be passed directly or indirectly and then called
5169 -- from almost any context.
5171 -- Note: we do not do this step till after resolving the actuals. That
5172 -- way we still take advantage of the current value information while
5173 -- scanning the actuals.
5175 -- We suppress killing values if we are processing the nodes associated
5176 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5177 -- type kills all the values as part of analyzing the code that
5178 -- initializes the dispatch tables.
5180 if Inside_Freezing_Actions = 0
5181 and then (not Is_Library_Level_Entity (Nam)
5182 or else Suppress_Value_Tracking_On_Call
5183 (Nearest_Dynamic_Scope (Current_Scope)))
5184 and then (Comes_From_Source (Nam)
5185 or else (Present (Alias (Nam))
5186 and then Comes_From_Source (Alias (Nam))))
5188 Kill_Current_Values;
5191 -- If we are warning about unread OUT parameters, this is the place to
5192 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5193 -- after the above call to Kill_Current_Values (since that call clears
5194 -- the Last_Assignment field of all local variables).
5196 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5197 and then Comes_From_Source (N)
5198 and then In_Extended_Main_Source_Unit (N)
5205 F := First_Formal (Nam);
5206 A := First_Actual (N);
5207 while Present (F) and then Present (A) loop
5208 if (Ekind (F) = E_Out_Parameter
5209 or else Ekind (F) = E_In_Out_Parameter)
5210 and then Warn_On_Modified_As_Out_Parameter (F)
5211 and then Is_Entity_Name (A)
5212 and then Present (Entity (A))
5213 and then Comes_From_Source (N)
5214 and then Safe_To_Capture_Value (N, Entity (A))
5216 Set_Last_Assignment (Entity (A), A);
5225 -- If the subprogram is a primitive operation, check whether or not
5226 -- it is a correct dispatching call.
5228 if Is_Overloadable (Nam)
5229 and then Is_Dispatching_Operation (Nam)
5231 Check_Dispatching_Call (N);
5233 elsif Ekind (Nam) /= E_Subprogram_Type
5234 and then Is_Abstract_Subprogram (Nam)
5235 and then not In_Instance
5237 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5240 -- If this is a dispatching call, generate the appropriate reference,
5241 -- for better source navigation in GPS.
5243 if Is_Overloadable (Nam)
5244 and then Present (Controlling_Argument (N))
5246 Generate_Reference (Nam, Subp, 'R');
5248 -- Normal case, not a dispatching call
5251 Generate_Reference (Nam, Subp);
5254 if Is_Intrinsic_Subprogram (Nam) then
5255 Check_Intrinsic_Call (N);
5258 -- Check for violation of restriction No_Specific_Termination_Handlers
5259 -- and warn on a potentially blocking call to Abort_Task.
5261 if Is_RTE (Nam, RE_Set_Specific_Handler)
5263 Is_RTE (Nam, RE_Specific_Handler)
5265 Check_Restriction (No_Specific_Termination_Handlers, N);
5267 elsif Is_RTE (Nam, RE_Abort_Task) then
5268 Check_Potentially_Blocking_Operation (N);
5271 -- Issue an error for a call to an eliminated subprogram
5273 Check_For_Eliminated_Subprogram (Subp, Nam);
5275 -- All done, evaluate call and deal with elaboration issues
5278 Check_Elab_Call (N);
5281 -------------------------------
5282 -- Resolve_Character_Literal --
5283 -------------------------------
5285 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5286 B_Typ : constant Entity_Id := Base_Type (Typ);
5290 -- Verify that the character does belong to the type of the context
5292 Set_Etype (N, B_Typ);
5293 Eval_Character_Literal (N);
5295 -- Wide_Wide_Character literals must always be defined, since the set
5296 -- of wide wide character literals is complete, i.e. if a character
5297 -- literal is accepted by the parser, then it is OK for wide wide
5298 -- character (out of range character literals are rejected).
5300 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5303 -- Always accept character literal for type Any_Character, which
5304 -- occurs in error situations and in comparisons of literals, both
5305 -- of which should accept all literals.
5307 elsif B_Typ = Any_Character then
5310 -- For Standard.Character or a type derived from it, check that
5311 -- the literal is in range
5313 elsif Root_Type (B_Typ) = Standard_Character then
5314 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5318 -- For Standard.Wide_Character or a type derived from it, check
5319 -- that the literal is in range
5321 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5322 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5326 -- For Standard.Wide_Wide_Character or a type derived from it, we
5327 -- know the literal is in range, since the parser checked!
5329 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5332 -- If the entity is already set, this has already been resolved in
5333 -- a generic context, or comes from expansion. Nothing else to do.
5335 elsif Present (Entity (N)) then
5338 -- Otherwise we have a user defined character type, and we can use
5339 -- the standard visibility mechanisms to locate the referenced entity
5342 C := Current_Entity (N);
5343 while Present (C) loop
5344 if Etype (C) = B_Typ then
5345 Set_Entity_With_Style_Check (N, C);
5346 Generate_Reference (C, N);
5354 -- If we fall through, then the literal does not match any of the
5355 -- entries of the enumeration type. This isn't just a constraint
5356 -- error situation, it is an illegality (see RM 4.2).
5359 ("character not defined for }", N, First_Subtype (B_Typ));
5360 end Resolve_Character_Literal;
5362 ---------------------------
5363 -- Resolve_Comparison_Op --
5364 ---------------------------
5366 -- Context requires a boolean type, and plays no role in resolution.
5367 -- Processing identical to that for equality operators. The result
5368 -- type is the base type, which matters when pathological subtypes of
5369 -- booleans with limited ranges are used.
5371 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5372 L : constant Node_Id := Left_Opnd (N);
5373 R : constant Node_Id := Right_Opnd (N);
5377 -- If this is an intrinsic operation which is not predefined, use
5378 -- the types of its declared arguments to resolve the possibly
5379 -- overloaded operands. Otherwise the operands are unambiguous and
5380 -- specify the expected type.
5382 if Scope (Entity (N)) /= Standard_Standard then
5383 T := Etype (First_Entity (Entity (N)));
5386 T := Find_Unique_Type (L, R);
5388 if T = Any_Fixed then
5389 T := Unique_Fixed_Point_Type (L);
5393 Set_Etype (N, Base_Type (Typ));
5394 Generate_Reference (T, N, ' ');
5396 if T /= Any_Type then
5398 or else T = Any_Composite
5399 or else T = Any_Character
5401 if T = Any_Character then
5402 Ambiguous_Character (L);
5404 Error_Msg_N ("ambiguous operands for comparison", N);
5407 Set_Etype (N, Any_Type);
5413 Check_Unset_Reference (L);
5414 Check_Unset_Reference (R);
5415 Generate_Operator_Reference (N, T);
5416 Check_Low_Bound_Tested (N);
5417 Eval_Relational_Op (N);
5420 end Resolve_Comparison_Op;
5422 ------------------------------------
5423 -- Resolve_Conditional_Expression --
5424 ------------------------------------
5426 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
5427 Condition : constant Node_Id := First (Expressions (N));
5428 Then_Expr : constant Node_Id := Next (Condition);
5429 Else_Expr : constant Node_Id := Next (Then_Expr);
5432 Resolve (Condition, Standard_Boolean);
5433 Resolve (Then_Expr, Typ);
5434 Resolve (Else_Expr, Typ);
5437 Eval_Conditional_Expression (N);
5438 end Resolve_Conditional_Expression;
5440 -----------------------------------------
5441 -- Resolve_Discrete_Subtype_Indication --
5442 -----------------------------------------
5444 procedure Resolve_Discrete_Subtype_Indication
5452 Analyze (Subtype_Mark (N));
5453 S := Entity (Subtype_Mark (N));
5455 if Nkind (Constraint (N)) /= N_Range_Constraint then
5456 Error_Msg_N ("expect range constraint for discrete type", N);
5457 Set_Etype (N, Any_Type);
5460 R := Range_Expression (Constraint (N));
5468 if Base_Type (S) /= Base_Type (Typ) then
5470 ("expect subtype of }", N, First_Subtype (Typ));
5472 -- Rewrite the constraint as a range of Typ
5473 -- to allow compilation to proceed further.
5476 Rewrite (Low_Bound (R),
5477 Make_Attribute_Reference (Sloc (Low_Bound (R)),
5478 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5479 Attribute_Name => Name_First));
5480 Rewrite (High_Bound (R),
5481 Make_Attribute_Reference (Sloc (High_Bound (R)),
5482 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5483 Attribute_Name => Name_First));
5487 Set_Etype (N, Etype (R));
5489 -- Additionally, we must check that the bounds are compatible
5490 -- with the given subtype, which might be different from the
5491 -- type of the context.
5493 Apply_Range_Check (R, S);
5495 -- ??? If the above check statically detects a Constraint_Error
5496 -- it replaces the offending bound(s) of the range R with a
5497 -- Constraint_Error node. When the itype which uses these bounds
5498 -- is frozen the resulting call to Duplicate_Subexpr generates
5499 -- a new temporary for the bounds.
5501 -- Unfortunately there are other itypes that are also made depend
5502 -- on these bounds, so when Duplicate_Subexpr is called they get
5503 -- a forward reference to the newly created temporaries and Gigi
5504 -- aborts on such forward references. This is probably sign of a
5505 -- more fundamental problem somewhere else in either the order of
5506 -- itype freezing or the way certain itypes are constructed.
5508 -- To get around this problem we call Remove_Side_Effects right
5509 -- away if either bounds of R are a Constraint_Error.
5512 L : constant Node_Id := Low_Bound (R);
5513 H : constant Node_Id := High_Bound (R);
5516 if Nkind (L) = N_Raise_Constraint_Error then
5517 Remove_Side_Effects (L);
5520 if Nkind (H) = N_Raise_Constraint_Error then
5521 Remove_Side_Effects (H);
5525 Check_Unset_Reference (Low_Bound (R));
5526 Check_Unset_Reference (High_Bound (R));
5529 end Resolve_Discrete_Subtype_Indication;
5531 -------------------------
5532 -- Resolve_Entity_Name --
5533 -------------------------
5535 -- Used to resolve identifiers and expanded names
5537 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
5538 E : constant Entity_Id := Entity (N);
5541 -- If garbage from errors, set to Any_Type and return
5543 if No (E) and then Total_Errors_Detected /= 0 then
5544 Set_Etype (N, Any_Type);
5548 -- Replace named numbers by corresponding literals. Note that this is
5549 -- the one case where Resolve_Entity_Name must reset the Etype, since
5550 -- it is currently marked as universal.
5552 if Ekind (E) = E_Named_Integer then
5554 Eval_Named_Integer (N);
5556 elsif Ekind (E) = E_Named_Real then
5558 Eval_Named_Real (N);
5560 -- Allow use of subtype only if it is a concurrent type where we are
5561 -- currently inside the body. This will eventually be expanded
5562 -- into a call to Self (for tasks) or _object (for protected
5563 -- objects). Any other use of a subtype is invalid.
5565 elsif Is_Type (E) then
5566 if Is_Concurrent_Type (E)
5567 and then In_Open_Scopes (E)
5572 ("invalid use of subtype mark in expression or call", N);
5575 -- Check discriminant use if entity is discriminant in current scope,
5576 -- i.e. discriminant of record or concurrent type currently being
5577 -- analyzed. Uses in corresponding body are unrestricted.
5579 elsif Ekind (E) = E_Discriminant
5580 and then Scope (E) = Current_Scope
5581 and then not Has_Completion (Current_Scope)
5583 Check_Discriminant_Use (N);
5585 -- A parameterless generic function cannot appear in a context that
5586 -- requires resolution.
5588 elsif Ekind (E) = E_Generic_Function then
5589 Error_Msg_N ("illegal use of generic function", N);
5591 elsif Ekind (E) = E_Out_Parameter
5592 and then Ada_Version = Ada_83
5593 and then (Nkind (Parent (N)) in N_Op
5594 or else (Nkind (Parent (N)) = N_Assignment_Statement
5595 and then N = Expression (Parent (N)))
5596 or else Nkind (Parent (N)) = N_Explicit_Dereference)
5598 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
5600 -- In all other cases, just do the possible static evaluation
5603 -- A deferred constant that appears in an expression must have
5604 -- a completion, unless it has been removed by in-place expansion
5607 if Ekind (E) = E_Constant
5608 and then Comes_From_Source (E)
5609 and then No (Constant_Value (E))
5610 and then Is_Frozen (Etype (E))
5611 and then not In_Spec_Expression
5612 and then not Is_Imported (E)
5615 if No_Initialization (Parent (E))
5616 or else (Present (Full_View (E))
5617 and then No_Initialization (Parent (Full_View (E))))
5622 "deferred constant is frozen before completion", N);
5626 Eval_Entity_Name (N);
5628 end Resolve_Entity_Name;
5634 procedure Resolve_Entry (Entry_Name : Node_Id) is
5635 Loc : constant Source_Ptr := Sloc (Entry_Name);
5643 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
5644 -- If the bounds of the entry family being called depend on task
5645 -- discriminants, build a new index subtype where a discriminant is
5646 -- replaced with the value of the discriminant of the target task.
5647 -- The target task is the prefix of the entry name in the call.
5649 -----------------------
5650 -- Actual_Index_Type --
5651 -----------------------
5653 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
5654 Typ : constant Entity_Id := Entry_Index_Type (E);
5655 Tsk : constant Entity_Id := Scope (E);
5656 Lo : constant Node_Id := Type_Low_Bound (Typ);
5657 Hi : constant Node_Id := Type_High_Bound (Typ);
5660 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
5661 -- If the bound is given by a discriminant, replace with a reference
5662 -- to the discriminant of the same name in the target task.
5663 -- If the entry name is the target of a requeue statement and the
5664 -- entry is in the current protected object, the bound to be used
5665 -- is the discriminal of the object (see apply_range_checks for
5666 -- details of the transformation).
5668 -----------------------------
5669 -- Actual_Discriminant_Ref --
5670 -----------------------------
5672 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
5673 Typ : constant Entity_Id := Etype (Bound);
5677 Remove_Side_Effects (Bound);
5679 if not Is_Entity_Name (Bound)
5680 or else Ekind (Entity (Bound)) /= E_Discriminant
5684 elsif Is_Protected_Type (Tsk)
5685 and then In_Open_Scopes (Tsk)
5686 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
5688 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
5692 Make_Selected_Component (Loc,
5693 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
5694 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
5699 end Actual_Discriminant_Ref;
5701 -- Start of processing for Actual_Index_Type
5704 if not Has_Discriminants (Tsk)
5705 or else (not Is_Entity_Name (Lo)
5706 and then not Is_Entity_Name (Hi))
5708 return Entry_Index_Type (E);
5711 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
5712 Set_Etype (New_T, Base_Type (Typ));
5713 Set_Size_Info (New_T, Typ);
5714 Set_RM_Size (New_T, RM_Size (Typ));
5715 Set_Scalar_Range (New_T,
5716 Make_Range (Sloc (Entry_Name),
5717 Low_Bound => Actual_Discriminant_Ref (Lo),
5718 High_Bound => Actual_Discriminant_Ref (Hi)));
5722 end Actual_Index_Type;
5724 -- Start of processing of Resolve_Entry
5727 -- Find name of entry being called, and resolve prefix of name
5728 -- with its own type. The prefix can be overloaded, and the name
5729 -- and signature of the entry must be taken into account.
5731 if Nkind (Entry_Name) = N_Indexed_Component then
5733 -- Case of dealing with entry family within the current tasks
5735 E_Name := Prefix (Entry_Name);
5738 E_Name := Entry_Name;
5741 if Is_Entity_Name (E_Name) then
5742 -- Entry call to an entry (or entry family) in the current task.
5743 -- This is legal even though the task will deadlock. Rewrite as
5744 -- call to current task.
5746 -- This can also be a call to an entry in an enclosing task.
5747 -- If this is a single task, we have to retrieve its name,
5748 -- because the scope of the entry is the task type, not the
5749 -- object. If the enclosing task is a task type, the identity
5750 -- of the task is given by its own self variable.
5752 -- Finally this can be a requeue on an entry of the same task
5753 -- or protected object.
5755 S := Scope (Entity (E_Name));
5757 for J in reverse 0 .. Scope_Stack.Last loop
5759 if Is_Task_Type (Scope_Stack.Table (J).Entity)
5760 and then not Comes_From_Source (S)
5762 -- S is an enclosing task or protected object. The concurrent
5763 -- declaration has been converted into a type declaration, and
5764 -- the object itself has an object declaration that follows
5765 -- the type in the same declarative part.
5767 Tsk := Next_Entity (S);
5768 while Etype (Tsk) /= S loop
5775 elsif S = Scope_Stack.Table (J).Entity then
5777 -- Call to current task. Will be transformed into call to Self
5785 Make_Selected_Component (Loc,
5786 Prefix => New_Occurrence_Of (S, Loc),
5788 New_Occurrence_Of (Entity (E_Name), Loc));
5789 Rewrite (E_Name, New_N);
5792 elsif Nkind (Entry_Name) = N_Selected_Component
5793 and then Is_Overloaded (Prefix (Entry_Name))
5795 -- Use the entry name (which must be unique at this point) to
5796 -- find the prefix that returns the corresponding task type or
5800 Pref : constant Node_Id := Prefix (Entry_Name);
5801 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
5806 Get_First_Interp (Pref, I, It);
5807 while Present (It.Typ) loop
5808 if Scope (Ent) = It.Typ then
5809 Set_Etype (Pref, It.Typ);
5813 Get_Next_Interp (I, It);
5818 if Nkind (Entry_Name) = N_Selected_Component then
5819 Resolve (Prefix (Entry_Name));
5821 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
5822 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
5823 Resolve (Prefix (Prefix (Entry_Name)));
5824 Index := First (Expressions (Entry_Name));
5825 Resolve (Index, Entry_Index_Type (Nam));
5827 -- Up to this point the expression could have been the actual
5828 -- in a simple entry call, and be given by a named association.
5830 if Nkind (Index) = N_Parameter_Association then
5831 Error_Msg_N ("expect expression for entry index", Index);
5833 Apply_Range_Check (Index, Actual_Index_Type (Nam));
5838 ------------------------
5839 -- Resolve_Entry_Call --
5840 ------------------------
5842 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
5843 Entry_Name : constant Node_Id := Name (N);
5844 Loc : constant Source_Ptr := Sloc (Entry_Name);
5846 First_Named : Node_Id;
5853 -- We kill all checks here, because it does not seem worth the
5854 -- effort to do anything better, an entry call is a big operation.
5858 -- Processing of the name is similar for entry calls and protected
5859 -- operation calls. Once the entity is determined, we can complete
5860 -- the resolution of the actuals.
5862 -- The selector may be overloaded, in the case of a protected object
5863 -- with overloaded functions. The type of the context is used for
5866 if Nkind (Entry_Name) = N_Selected_Component
5867 and then Is_Overloaded (Selector_Name (Entry_Name))
5868 and then Typ /= Standard_Void_Type
5875 Get_First_Interp (Selector_Name (Entry_Name), I, It);
5876 while Present (It.Typ) loop
5877 if Covers (Typ, It.Typ) then
5878 Set_Entity (Selector_Name (Entry_Name), It.Nam);
5879 Set_Etype (Entry_Name, It.Typ);
5881 Generate_Reference (It.Typ, N, ' ');
5884 Get_Next_Interp (I, It);
5889 Resolve_Entry (Entry_Name);
5891 if Nkind (Entry_Name) = N_Selected_Component then
5893 -- Simple entry call
5895 Nam := Entity (Selector_Name (Entry_Name));
5896 Obj := Prefix (Entry_Name);
5897 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
5899 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
5901 -- Call to member of entry family
5903 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
5904 Obj := Prefix (Prefix (Entry_Name));
5905 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
5908 -- We cannot in general check the maximum depth of protected entry
5909 -- calls at compile time. But we can tell that any protected entry
5910 -- call at all violates a specified nesting depth of zero.
5912 if Is_Protected_Type (Scope (Nam)) then
5913 Check_Restriction (Max_Entry_Queue_Length, N);
5916 -- Use context type to disambiguate a protected function that can be
5917 -- called without actuals and that returns an array type, and where
5918 -- the argument list may be an indexing of the returned value.
5920 if Ekind (Nam) = E_Function
5921 and then Needs_No_Actuals (Nam)
5922 and then Present (Parameter_Associations (N))
5924 ((Is_Array_Type (Etype (Nam))
5925 and then Covers (Typ, Component_Type (Etype (Nam))))
5927 or else (Is_Access_Type (Etype (Nam))
5928 and then Is_Array_Type (Designated_Type (Etype (Nam)))
5929 and then Covers (Typ,
5930 Component_Type (Designated_Type (Etype (Nam))))))
5933 Index_Node : Node_Id;
5937 Make_Indexed_Component (Loc,
5939 Make_Function_Call (Loc,
5940 Name => Relocate_Node (Entry_Name)),
5941 Expressions => Parameter_Associations (N));
5943 -- Since we are correcting a node classification error made by
5944 -- the parser, we call Replace rather than Rewrite.
5946 Replace (N, Index_Node);
5947 Set_Etype (Prefix (N), Etype (Nam));
5949 Resolve_Indexed_Component (N, Typ);
5954 -- The operation name may have been overloaded. Order the actuals
5955 -- according to the formals of the resolved entity, and set the
5956 -- return type to that of the operation.
5959 Normalize_Actuals (N, Nam, False, Norm_OK);
5960 pragma Assert (Norm_OK);
5961 Set_Etype (N, Etype (Nam));
5964 Resolve_Actuals (N, Nam);
5965 Generate_Reference (Nam, Entry_Name);
5967 if Ekind (Nam) = E_Entry
5968 or else Ekind (Nam) = E_Entry_Family
5970 Check_Potentially_Blocking_Operation (N);
5973 -- Verify that a procedure call cannot masquerade as an entry
5974 -- call where an entry call is expected.
5976 if Ekind (Nam) = E_Procedure then
5977 if Nkind (Parent (N)) = N_Entry_Call_Alternative
5978 and then N = Entry_Call_Statement (Parent (N))
5980 Error_Msg_N ("entry call required in select statement", N);
5982 elsif Nkind (Parent (N)) = N_Triggering_Alternative
5983 and then N = Triggering_Statement (Parent (N))
5985 Error_Msg_N ("triggering statement cannot be procedure call", N);
5987 elsif Ekind (Scope (Nam)) = E_Task_Type
5988 and then not In_Open_Scopes (Scope (Nam))
5990 Error_Msg_N ("task has no entry with this name", Entry_Name);
5994 -- After resolution, entry calls and protected procedure calls
5995 -- are changed into entry calls, for expansion. The structure
5996 -- of the node does not change, so it can safely be done in place.
5997 -- Protected function calls must keep their structure because they
5998 -- are subexpressions.
6000 if Ekind (Nam) /= E_Function then
6002 -- A protected operation that is not a function may modify the
6003 -- corresponding object, and cannot apply to a constant.
6004 -- If this is an internal call, the prefix is the type itself.
6006 if Is_Protected_Type (Scope (Nam))
6007 and then not Is_Variable (Obj)
6008 and then (not Is_Entity_Name (Obj)
6009 or else not Is_Type (Entity (Obj)))
6012 ("prefix of protected procedure or entry call must be variable",
6016 Actuals := Parameter_Associations (N);
6017 First_Named := First_Named_Actual (N);
6020 Make_Entry_Call_Statement (Loc,
6022 Parameter_Associations => Actuals));
6024 Set_First_Named_Actual (N, First_Named);
6025 Set_Analyzed (N, True);
6027 -- Protected functions can return on the secondary stack, in which
6028 -- case we must trigger the transient scope mechanism.
6030 elsif Expander_Active
6031 and then Requires_Transient_Scope (Etype (Nam))
6033 Establish_Transient_Scope (N, Sec_Stack => True);
6035 end Resolve_Entry_Call;
6037 -------------------------
6038 -- Resolve_Equality_Op --
6039 -------------------------
6041 -- Both arguments must have the same type, and the boolean context
6042 -- does not participate in the resolution. The first pass verifies
6043 -- that the interpretation is not ambiguous, and the type of the left
6044 -- argument is correctly set, or is Any_Type in case of ambiguity.
6045 -- If both arguments are strings or aggregates, allocators, or Null,
6046 -- they are ambiguous even though they carry a single (universal) type.
6047 -- Diagnose this case here.
6049 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6050 L : constant Node_Id := Left_Opnd (N);
6051 R : constant Node_Id := Right_Opnd (N);
6052 T : Entity_Id := Find_Unique_Type (L, R);
6054 function Find_Unique_Access_Type return Entity_Id;
6055 -- In the case of allocators, make a last-ditch attempt to find a single
6056 -- access type with the right designated type. This is semantically
6057 -- dubious, and of no interest to any real code, but c48008a makes it
6060 -----------------------------
6061 -- Find_Unique_Access_Type --
6062 -----------------------------
6064 function Find_Unique_Access_Type return Entity_Id is
6070 if Ekind (Etype (R)) = E_Allocator_Type then
6071 Acc := Designated_Type (Etype (R));
6072 elsif Ekind (Etype (L)) = E_Allocator_Type then
6073 Acc := Designated_Type (Etype (L));
6079 while S /= Standard_Standard loop
6080 E := First_Entity (S);
6081 while Present (E) loop
6083 and then Is_Access_Type (E)
6084 and then Ekind (E) /= E_Allocator_Type
6085 and then Designated_Type (E) = Base_Type (Acc)
6097 end Find_Unique_Access_Type;
6099 -- Start of processing for Resolve_Equality_Op
6102 Set_Etype (N, Base_Type (Typ));
6103 Generate_Reference (T, N, ' ');
6105 if T = Any_Fixed then
6106 T := Unique_Fixed_Point_Type (L);
6109 if T /= Any_Type then
6111 or else T = Any_Composite
6112 or else T = Any_Character
6114 if T = Any_Character then
6115 Ambiguous_Character (L);
6117 Error_Msg_N ("ambiguous operands for equality", N);
6120 Set_Etype (N, Any_Type);
6123 elsif T = Any_Access
6124 or else Ekind (T) = E_Allocator_Type
6125 or else Ekind (T) = E_Access_Attribute_Type
6127 T := Find_Unique_Access_Type;
6130 Error_Msg_N ("ambiguous operands for equality", N);
6131 Set_Etype (N, Any_Type);
6139 -- If the unique type is a class-wide type then it will be expanded
6140 -- into a dispatching call to the predefined primitive. Therefore we
6141 -- check here for potential violation of such restriction.
6143 if Is_Class_Wide_Type (T) then
6144 Check_Restriction (No_Dispatching_Calls, N);
6147 if Warn_On_Redundant_Constructs
6148 and then Comes_From_Source (N)
6149 and then Is_Entity_Name (R)
6150 and then Entity (R) = Standard_True
6151 and then Comes_From_Source (R)
6153 Error_Msg_N ("?comparison with True is redundant!", R);
6156 Check_Unset_Reference (L);
6157 Check_Unset_Reference (R);
6158 Generate_Operator_Reference (N, T);
6159 Check_Low_Bound_Tested (N);
6161 -- If this is an inequality, it may be the implicit inequality
6162 -- created for a user-defined operation, in which case the corres-
6163 -- ponding equality operation is not intrinsic, and the operation
6164 -- cannot be constant-folded. Else fold.
6166 if Nkind (N) = N_Op_Eq
6167 or else Comes_From_Source (Entity (N))
6168 or else Ekind (Entity (N)) = E_Operator
6169 or else Is_Intrinsic_Subprogram
6170 (Corresponding_Equality (Entity (N)))
6172 Eval_Relational_Op (N);
6174 elsif Nkind (N) = N_Op_Ne
6175 and then Is_Abstract_Subprogram (Entity (N))
6177 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6180 -- Ada 2005: If one operand is an anonymous access type, convert
6181 -- the other operand to it, to ensure that the underlying types
6182 -- match in the back-end. Same for access_to_subprogram, and the
6183 -- conversion verifies that the types are subtype conformant.
6185 -- We apply the same conversion in the case one of the operands is
6186 -- a private subtype of the type of the other.
6188 -- Why the Expander_Active test here ???
6192 (Ekind (T) = E_Anonymous_Access_Type
6193 or else Ekind (T) = E_Anonymous_Access_Subprogram_Type
6194 or else Is_Private_Type (T))
6196 if Etype (L) /= T then
6198 Make_Unchecked_Type_Conversion (Sloc (L),
6199 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6200 Expression => Relocate_Node (L)));
6201 Analyze_And_Resolve (L, T);
6204 if (Etype (R)) /= T then
6206 Make_Unchecked_Type_Conversion (Sloc (R),
6207 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6208 Expression => Relocate_Node (R)));
6209 Analyze_And_Resolve (R, T);
6213 end Resolve_Equality_Op;
6215 ----------------------------------
6216 -- Resolve_Explicit_Dereference --
6217 ----------------------------------
6219 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6220 Loc : constant Source_Ptr := Sloc (N);
6222 P : constant Node_Id := Prefix (N);
6227 Check_Fully_Declared_Prefix (Typ, P);
6229 if Is_Overloaded (P) then
6231 -- Use the context type to select the prefix that has the correct
6234 Get_First_Interp (P, I, It);
6235 while Present (It.Typ) loop
6236 exit when Is_Access_Type (It.Typ)
6237 and then Covers (Typ, Designated_Type (It.Typ));
6238 Get_Next_Interp (I, It);
6241 if Present (It.Typ) then
6242 Resolve (P, It.Typ);
6244 -- If no interpretation covers the designated type of the prefix,
6245 -- this is the pathological case where not all implementations of
6246 -- the prefix allow the interpretation of the node as a call. Now
6247 -- that the expected type is known, Remove other interpretations
6248 -- from prefix, rewrite it as a call, and resolve again, so that
6249 -- the proper call node is generated.
6251 Get_First_Interp (P, I, It);
6252 while Present (It.Typ) loop
6253 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6257 Get_Next_Interp (I, It);
6261 Make_Function_Call (Loc,
6263 Make_Explicit_Dereference (Loc,
6265 Parameter_Associations => New_List);
6267 Save_Interps (N, New_N);
6269 Analyze_And_Resolve (N, Typ);
6273 Set_Etype (N, Designated_Type (It.Typ));
6279 if Is_Access_Type (Etype (P)) then
6280 Apply_Access_Check (N);
6283 -- If the designated type is a packed unconstrained array type, and the
6284 -- explicit dereference is not in the context of an attribute reference,
6285 -- then we must compute and set the actual subtype, since it is needed
6286 -- by Gigi. The reason we exclude the attribute case is that this is
6287 -- handled fine by Gigi, and in fact we use such attributes to build the
6288 -- actual subtype. We also exclude generated code (which builds actual
6289 -- subtypes directly if they are needed).
6291 if Is_Array_Type (Etype (N))
6292 and then Is_Packed (Etype (N))
6293 and then not Is_Constrained (Etype (N))
6294 and then Nkind (Parent (N)) /= N_Attribute_Reference
6295 and then Comes_From_Source (N)
6297 Set_Etype (N, Get_Actual_Subtype (N));
6300 -- Note: there is no Eval processing required for an explicit deference,
6301 -- because the type is known to be an allocators, and allocator
6302 -- expressions can never be static.
6304 end Resolve_Explicit_Dereference;
6306 -------------------------------
6307 -- Resolve_Indexed_Component --
6308 -------------------------------
6310 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
6311 Name : constant Node_Id := Prefix (N);
6313 Array_Type : Entity_Id := Empty; -- to prevent junk warning
6317 if Is_Overloaded (Name) then
6319 -- Use the context type to select the prefix that yields the correct
6325 I1 : Interp_Index := 0;
6326 P : constant Node_Id := Prefix (N);
6327 Found : Boolean := False;
6330 Get_First_Interp (P, I, It);
6331 while Present (It.Typ) loop
6332 if (Is_Array_Type (It.Typ)
6333 and then Covers (Typ, Component_Type (It.Typ)))
6334 or else (Is_Access_Type (It.Typ)
6335 and then Is_Array_Type (Designated_Type (It.Typ))
6337 (Typ, Component_Type (Designated_Type (It.Typ))))
6340 It := Disambiguate (P, I1, I, Any_Type);
6342 if It = No_Interp then
6343 Error_Msg_N ("ambiguous prefix for indexing", N);
6349 Array_Type := It.Typ;
6355 Array_Type := It.Typ;
6360 Get_Next_Interp (I, It);
6365 Array_Type := Etype (Name);
6368 Resolve (Name, Array_Type);
6369 Array_Type := Get_Actual_Subtype_If_Available (Name);
6371 -- If prefix is access type, dereference to get real array type.
6372 -- Note: we do not apply an access check because the expander always
6373 -- introduces an explicit dereference, and the check will happen there.
6375 if Is_Access_Type (Array_Type) then
6376 Array_Type := Designated_Type (Array_Type);
6379 -- If name was overloaded, set component type correctly now
6380 -- If a misplaced call to an entry family (which has no index types)
6381 -- return. Error will be diagnosed from calling context.
6383 if Is_Array_Type (Array_Type) then
6384 Set_Etype (N, Component_Type (Array_Type));
6389 Index := First_Index (Array_Type);
6390 Expr := First (Expressions (N));
6392 -- The prefix may have resolved to a string literal, in which case its
6393 -- etype has a special representation. This is only possible currently
6394 -- if the prefix is a static concatenation, written in functional
6397 if Ekind (Array_Type) = E_String_Literal_Subtype then
6398 Resolve (Expr, Standard_Positive);
6401 while Present (Index) and Present (Expr) loop
6402 Resolve (Expr, Etype (Index));
6403 Check_Unset_Reference (Expr);
6405 if Is_Scalar_Type (Etype (Expr)) then
6406 Apply_Scalar_Range_Check (Expr, Etype (Index));
6408 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
6416 -- Do not generate the warning on suspicious index if we are analyzing
6417 -- package Ada.Tags; otherwise we will report the warning with the
6418 -- Prims_Ptr field of the dispatch table.
6420 if Scope (Etype (Prefix (N))) = Standard_Standard
6422 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
6425 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
6426 Eval_Indexed_Component (N);
6428 end Resolve_Indexed_Component;
6430 -----------------------------
6431 -- Resolve_Integer_Literal --
6432 -----------------------------
6434 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
6437 Eval_Integer_Literal (N);
6438 end Resolve_Integer_Literal;
6440 --------------------------------
6441 -- Resolve_Intrinsic_Operator --
6442 --------------------------------
6444 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
6445 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6452 while Scope (Op) /= Standard_Standard loop
6454 pragma Assert (Present (Op));
6458 Set_Is_Overloaded (N, False);
6460 -- If the operand type is private, rewrite with suitable conversions on
6461 -- the operands and the result, to expose the proper underlying numeric
6464 if Is_Private_Type (Typ) then
6465 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
6467 if Nkind (N) = N_Op_Expon then
6468 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
6470 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6473 Save_Interps (Left_Opnd (N), Expression (Arg1));
6474 Save_Interps (Right_Opnd (N), Expression (Arg2));
6476 Set_Left_Opnd (N, Arg1);
6477 Set_Right_Opnd (N, Arg2);
6479 Set_Etype (N, Btyp);
6480 Rewrite (N, Unchecked_Convert_To (Typ, N));
6483 elsif Typ /= Etype (Left_Opnd (N))
6484 or else Typ /= Etype (Right_Opnd (N))
6486 -- Add explicit conversion where needed, and save interpretations
6487 -- in case operands are overloaded.
6489 Arg1 := Convert_To (Typ, Left_Opnd (N));
6490 Arg2 := Convert_To (Typ, Right_Opnd (N));
6492 if Nkind (Arg1) = N_Type_Conversion then
6493 Save_Interps (Left_Opnd (N), Expression (Arg1));
6495 Save_Interps (Left_Opnd (N), Arg1);
6498 if Nkind (Arg2) = N_Type_Conversion then
6499 Save_Interps (Right_Opnd (N), Expression (Arg2));
6501 Save_Interps (Right_Opnd (N), Arg2);
6504 Rewrite (Left_Opnd (N), Arg1);
6505 Rewrite (Right_Opnd (N), Arg2);
6508 Resolve_Arithmetic_Op (N, Typ);
6511 Resolve_Arithmetic_Op (N, Typ);
6513 end Resolve_Intrinsic_Operator;
6515 --------------------------------------
6516 -- Resolve_Intrinsic_Unary_Operator --
6517 --------------------------------------
6519 procedure Resolve_Intrinsic_Unary_Operator
6523 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6529 while Scope (Op) /= Standard_Standard loop
6531 pragma Assert (Present (Op));
6536 if Is_Private_Type (Typ) then
6537 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6538 Save_Interps (Right_Opnd (N), Expression (Arg2));
6540 Set_Right_Opnd (N, Arg2);
6542 Set_Etype (N, Btyp);
6543 Rewrite (N, Unchecked_Convert_To (Typ, N));
6547 Resolve_Unary_Op (N, Typ);
6549 end Resolve_Intrinsic_Unary_Operator;
6551 ------------------------
6552 -- Resolve_Logical_Op --
6553 ------------------------
6555 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
6557 N_Opr : constant Node_Kind := Nkind (N);
6560 -- Predefined operations on scalar types yield the base type. On the
6561 -- other hand, logical operations on arrays yield the type of the
6562 -- arguments (and the context).
6564 if Is_Array_Type (Typ) then
6567 B_Typ := Base_Type (Typ);
6570 -- The following test is required because the operands of the operation
6571 -- may be literals, in which case the resulting type appears to be
6572 -- compatible with a signed integer type, when in fact it is compatible
6573 -- only with modular types. If the context itself is universal, the
6574 -- operation is illegal.
6576 if not Valid_Boolean_Arg (Typ) then
6577 Error_Msg_N ("invalid context for logical operation", N);
6578 Set_Etype (N, Any_Type);
6581 elsif Typ = Any_Modular then
6583 ("no modular type available in this context", N);
6584 Set_Etype (N, Any_Type);
6586 elsif Is_Modular_Integer_Type (Typ)
6587 and then Etype (Left_Opnd (N)) = Universal_Integer
6588 and then Etype (Right_Opnd (N)) = Universal_Integer
6590 Check_For_Visible_Operator (N, B_Typ);
6593 Resolve (Left_Opnd (N), B_Typ);
6594 Resolve (Right_Opnd (N), B_Typ);
6596 Check_Unset_Reference (Left_Opnd (N));
6597 Check_Unset_Reference (Right_Opnd (N));
6599 Set_Etype (N, B_Typ);
6600 Generate_Operator_Reference (N, B_Typ);
6601 Eval_Logical_Op (N);
6603 -- Check for violation of restriction No_Direct_Boolean_Operators
6604 -- if the operator was not eliminated by the Eval_Logical_Op call.
6606 if Nkind (N) = N_Opr
6607 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
6609 Check_Restriction (No_Direct_Boolean_Operators, N);
6611 end Resolve_Logical_Op;
6613 ---------------------------
6614 -- Resolve_Membership_Op --
6615 ---------------------------
6617 -- The context can only be a boolean type, and does not determine
6618 -- the arguments. Arguments should be unambiguous, but the preference
6619 -- rule for universal types applies.
6621 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
6622 pragma Warnings (Off, Typ);
6624 L : constant Node_Id := Left_Opnd (N);
6625 R : constant Node_Id := Right_Opnd (N);
6629 if L = Error or else R = Error then
6633 if not Is_Overloaded (R)
6635 (Etype (R) = Universal_Integer or else
6636 Etype (R) = Universal_Real)
6637 and then Is_Overloaded (L)
6641 -- Ada 2005 (AI-251): Give support to the following case:
6643 -- type I is interface;
6644 -- type T is tagged ...
6646 -- function Test (O : I'Class) is
6648 -- return O in T'Class.
6651 -- In this case we have nothing else to do; the membership test will be
6652 -- done at run-time.
6654 elsif Ada_Version >= Ada_05
6655 and then Is_Class_Wide_Type (Etype (L))
6656 and then Is_Interface (Etype (L))
6657 and then Is_Class_Wide_Type (Etype (R))
6658 and then not Is_Interface (Etype (R))
6663 T := Intersect_Types (L, R);
6667 Check_Unset_Reference (L);
6669 if Nkind (R) = N_Range
6670 and then not Is_Scalar_Type (T)
6672 Error_Msg_N ("scalar type required for range", R);
6675 if Is_Entity_Name (R) then
6676 Freeze_Expression (R);
6679 Check_Unset_Reference (R);
6682 Eval_Membership_Op (N);
6683 end Resolve_Membership_Op;
6689 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
6690 Loc : constant Source_Ptr := Sloc (N);
6693 -- Handle restriction against anonymous null access values This
6694 -- restriction can be turned off using -gnatdj.
6696 -- Ada 2005 (AI-231): Remove restriction
6698 if Ada_Version < Ada_05
6699 and then not Debug_Flag_J
6700 and then Ekind (Typ) = E_Anonymous_Access_Type
6701 and then Comes_From_Source (N)
6703 -- In the common case of a call which uses an explicitly null
6704 -- value for an access parameter, give specialized error message.
6706 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
6710 ("null is not allowed as argument for an access parameter", N);
6712 -- Standard message for all other cases (are there any?)
6716 ("null cannot be of an anonymous access type", N);
6720 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
6721 -- assignment to a null-excluding object
6723 if Ada_Version >= Ada_05
6724 and then Can_Never_Be_Null (Typ)
6725 and then Nkind (Parent (N)) = N_Assignment_Statement
6727 if not Inside_Init_Proc then
6729 (Compile_Time_Constraint_Error (N,
6730 "(Ada 2005) null not allowed in null-excluding objects?"),
6731 Make_Raise_Constraint_Error (Loc,
6732 Reason => CE_Access_Check_Failed));
6735 Make_Raise_Constraint_Error (Loc,
6736 Reason => CE_Access_Check_Failed));
6740 -- In a distributed context, null for a remote access to subprogram
6741 -- may need to be replaced with a special record aggregate. In this
6742 -- case, return after having done the transformation.
6744 if (Ekind (Typ) = E_Record_Type
6745 or else Is_Remote_Access_To_Subprogram_Type (Typ))
6746 and then Remote_AST_Null_Value (N, Typ)
6751 -- The null literal takes its type from the context
6756 -----------------------
6757 -- Resolve_Op_Concat --
6758 -----------------------
6760 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
6762 -- We wish to avoid deep recursion, because concatenations are often
6763 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
6764 -- operands nonrecursively until we find something that is not a simple
6765 -- concatenation (A in this case). We resolve that, and then walk back
6766 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
6767 -- to do the rest of the work at each level. The Parent pointers allow
6768 -- us to avoid recursion, and thus avoid running out of memory. See also
6769 -- Sem_Ch4.Analyze_Concatenation, where a similar hack is used.
6775 -- The following code is equivalent to:
6777 -- Resolve_Op_Concat_First (NN, Typ);
6778 -- Resolve_Op_Concat_Arg (N, ...);
6779 -- Resolve_Op_Concat_Rest (N, Typ);
6781 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
6782 -- operand is a concatenation.
6784 -- Walk down left operands
6787 Resolve_Op_Concat_First (NN, Typ);
6788 Op1 := Left_Opnd (NN);
6789 exit when not (Nkind (Op1) = N_Op_Concat
6790 and then not Is_Array_Type (Component_Type (Typ))
6791 and then Entity (Op1) = Entity (NN));
6795 -- Now (given the above example) NN is A&B and Op1 is A
6797 -- First resolve Op1 ...
6799 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
6801 -- ... then walk NN back up until we reach N (where we started), calling
6802 -- Resolve_Op_Concat_Rest along the way.
6805 Resolve_Op_Concat_Rest (NN, Typ);
6809 end Resolve_Op_Concat;
6811 ---------------------------
6812 -- Resolve_Op_Concat_Arg --
6813 ---------------------------
6815 procedure Resolve_Op_Concat_Arg
6821 Btyp : constant Entity_Id := Base_Type (Typ);
6826 or else (not Is_Overloaded (Arg)
6827 and then Etype (Arg) /= Any_Composite
6828 and then Covers (Component_Type (Typ), Etype (Arg)))
6830 Resolve (Arg, Component_Type (Typ));
6832 Resolve (Arg, Btyp);
6835 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
6836 if Nkind (Arg) = N_Aggregate
6837 and then Is_Composite_Type (Component_Type (Typ))
6839 if Is_Private_Type (Component_Type (Typ)) then
6840 Resolve (Arg, Btyp);
6842 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
6843 Set_Etype (Arg, Any_Type);
6847 if Is_Overloaded (Arg)
6848 and then Has_Compatible_Type (Arg, Typ)
6849 and then Etype (Arg) /= Any_Type
6857 Get_First_Interp (Arg, I, It);
6859 Get_Next_Interp (I, It);
6861 -- Special-case the error message when the overloading is
6862 -- caused by a function that yields an array and can be
6863 -- called without parameters.
6865 if It.Nam = Func then
6866 Error_Msg_Sloc := Sloc (Func);
6867 Error_Msg_N ("ambiguous call to function#", Arg);
6869 ("\\interpretation as call yields&", Arg, Typ);
6871 ("\\interpretation as indexing of call yields&",
6872 Arg, Component_Type (Typ));
6876 ("ambiguous operand for concatenation!", Arg);
6877 Get_First_Interp (Arg, I, It);
6878 while Present (It.Nam) loop
6879 Error_Msg_Sloc := Sloc (It.Nam);
6881 if Base_Type (It.Typ) = Base_Type (Typ)
6882 or else Base_Type (It.Typ) =
6883 Base_Type (Component_Type (Typ))
6885 Error_Msg_N ("\\possible interpretation#", Arg);
6888 Get_Next_Interp (I, It);
6894 Resolve (Arg, Component_Type (Typ));
6896 if Nkind (Arg) = N_String_Literal then
6897 Set_Etype (Arg, Component_Type (Typ));
6900 if Arg = Left_Opnd (N) then
6901 Set_Is_Component_Left_Opnd (N);
6903 Set_Is_Component_Right_Opnd (N);
6908 Resolve (Arg, Btyp);
6911 Check_Unset_Reference (Arg);
6912 end Resolve_Op_Concat_Arg;
6914 -----------------------------
6915 -- Resolve_Op_Concat_First --
6916 -----------------------------
6918 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
6919 Btyp : constant Entity_Id := Base_Type (Typ);
6920 Op1 : constant Node_Id := Left_Opnd (N);
6921 Op2 : constant Node_Id := Right_Opnd (N);
6924 -- The parser folds an enormous sequence of concatenations of string
6925 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
6926 -- in the right. If the expression resolves to a predefined "&"
6927 -- operator, all is well. Otherwise, the parser's folding is wrong, so
6928 -- we give an error. See P_Simple_Expression in Par.Ch4.
6930 if Nkind (Op2) = N_String_Literal
6931 and then Is_Folded_In_Parser (Op2)
6932 and then Ekind (Entity (N)) = E_Function
6934 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
6935 and then String_Length (Strval (Op1)) = 0);
6936 Error_Msg_N ("too many user-defined concatenations", N);
6940 Set_Etype (N, Btyp);
6942 if Is_Limited_Composite (Btyp) then
6943 Error_Msg_N ("concatenation not available for limited array", N);
6944 Explain_Limited_Type (Btyp, N);
6946 end Resolve_Op_Concat_First;
6948 ----------------------------
6949 -- Resolve_Op_Concat_Rest --
6950 ----------------------------
6952 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
6953 Op1 : constant Node_Id := Left_Opnd (N);
6954 Op2 : constant Node_Id := Right_Opnd (N);
6957 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
6959 Generate_Operator_Reference (N, Typ);
6961 if Is_String_Type (Typ) then
6962 Eval_Concatenation (N);
6965 -- If this is not a static concatenation, but the result is a
6966 -- string type (and not an array of strings) ensure that static
6967 -- string operands have their subtypes properly constructed.
6969 if Nkind (N) /= N_String_Literal
6970 and then Is_Character_Type (Component_Type (Typ))
6972 Set_String_Literal_Subtype (Op1, Typ);
6973 Set_String_Literal_Subtype (Op2, Typ);
6975 end Resolve_Op_Concat_Rest;
6977 ----------------------
6978 -- Resolve_Op_Expon --
6979 ----------------------
6981 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
6982 B_Typ : constant Entity_Id := Base_Type (Typ);
6985 -- Catch attempts to do fixed-point exponentiation with universal
6986 -- operands, which is a case where the illegality is not caught during
6987 -- normal operator analysis.
6989 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
6990 Error_Msg_N ("exponentiation not available for fixed point", N);
6994 if Comes_From_Source (N)
6995 and then Ekind (Entity (N)) = E_Function
6996 and then Is_Imported (Entity (N))
6997 and then Is_Intrinsic_Subprogram (Entity (N))
6999 Resolve_Intrinsic_Operator (N, Typ);
7003 if Etype (Left_Opnd (N)) = Universal_Integer
7004 or else Etype (Left_Opnd (N)) = Universal_Real
7006 Check_For_Visible_Operator (N, B_Typ);
7009 -- We do the resolution using the base type, because intermediate values
7010 -- in expressions always are of the base type, not a subtype of it.
7012 Resolve (Left_Opnd (N), B_Typ);
7013 Resolve (Right_Opnd (N), Standard_Integer);
7015 Check_Unset_Reference (Left_Opnd (N));
7016 Check_Unset_Reference (Right_Opnd (N));
7018 Set_Etype (N, B_Typ);
7019 Generate_Operator_Reference (N, B_Typ);
7022 -- Set overflow checking bit. Much cleverer code needed here eventually
7023 -- and perhaps the Resolve routines should be separated for the various
7024 -- arithmetic operations, since they will need different processing. ???
7026 if Nkind (N) in N_Op then
7027 if not Overflow_Checks_Suppressed (Etype (N)) then
7028 Enable_Overflow_Check (N);
7031 end Resolve_Op_Expon;
7033 --------------------
7034 -- Resolve_Op_Not --
7035 --------------------
7037 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
7040 function Parent_Is_Boolean return Boolean;
7041 -- This function determines if the parent node is a boolean operator
7042 -- or operation (comparison op, membership test, or short circuit form)
7043 -- and the not in question is the left operand of this operation.
7044 -- Note that if the not is in parens, then false is returned.
7046 -----------------------
7047 -- Parent_Is_Boolean --
7048 -----------------------
7050 function Parent_Is_Boolean return Boolean is
7052 if Paren_Count (N) /= 0 then
7056 case Nkind (Parent (N)) is
7071 return Left_Opnd (Parent (N)) = N;
7077 end Parent_Is_Boolean;
7079 -- Start of processing for Resolve_Op_Not
7082 -- Predefined operations on scalar types yield the base type. On the
7083 -- other hand, logical operations on arrays yield the type of the
7084 -- arguments (and the context).
7086 if Is_Array_Type (Typ) then
7089 B_Typ := Base_Type (Typ);
7092 -- Straightforward case of incorrect arguments
7094 if not Valid_Boolean_Arg (Typ) then
7095 Error_Msg_N ("invalid operand type for operator&", N);
7096 Set_Etype (N, Any_Type);
7099 -- Special case of probable missing parens
7101 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7102 if Parent_Is_Boolean then
7104 ("operand of not must be enclosed in parentheses",
7108 ("no modular type available in this context", N);
7111 Set_Etype (N, Any_Type);
7114 -- OK resolution of not
7117 -- Warn if non-boolean types involved. This is a case like not a < b
7118 -- where a and b are modular, where we will get (not a) < b and most
7119 -- likely not (a < b) was intended.
7121 if Warn_On_Questionable_Missing_Parens
7122 and then not Is_Boolean_Type (Typ)
7123 and then Parent_Is_Boolean
7125 Error_Msg_N ("?not expression should be parenthesized here!", N);
7128 -- Warn on double negation if checking redundant constructs
7130 if Warn_On_Redundant_Constructs
7131 and then Comes_From_Source (N)
7132 and then Comes_From_Source (Right_Opnd (N))
7133 and then Root_Type (Typ) = Standard_Boolean
7134 and then Nkind (Right_Opnd (N)) = N_Op_Not
7136 Error_Msg_N ("redundant double negation?", N);
7139 -- Complete resolution and evaluation of NOT
7141 Resolve (Right_Opnd (N), B_Typ);
7142 Check_Unset_Reference (Right_Opnd (N));
7143 Set_Etype (N, B_Typ);
7144 Generate_Operator_Reference (N, B_Typ);
7149 -----------------------------
7150 -- Resolve_Operator_Symbol --
7151 -----------------------------
7153 -- Nothing to be done, all resolved already
7155 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
7156 pragma Warnings (Off, N);
7157 pragma Warnings (Off, Typ);
7161 end Resolve_Operator_Symbol;
7163 ----------------------------------
7164 -- Resolve_Qualified_Expression --
7165 ----------------------------------
7167 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
7168 pragma Warnings (Off, Typ);
7170 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
7171 Expr : constant Node_Id := Expression (N);
7174 Resolve (Expr, Target_Typ);
7176 -- A qualified expression requires an exact match of the type,
7177 -- class-wide matching is not allowed. However, if the qualifying
7178 -- type is specific and the expression has a class-wide type, it
7179 -- may still be okay, since it can be the result of the expansion
7180 -- of a call to a dispatching function, so we also have to check
7181 -- class-wideness of the type of the expression's original node.
7183 if (Is_Class_Wide_Type (Target_Typ)
7185 (Is_Class_Wide_Type (Etype (Expr))
7186 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
7187 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
7189 Wrong_Type (Expr, Target_Typ);
7192 -- If the target type is unconstrained, then we reset the type of
7193 -- the result from the type of the expression. For other cases, the
7194 -- actual subtype of the expression is the target type.
7196 if Is_Composite_Type (Target_Typ)
7197 and then not Is_Constrained (Target_Typ)
7199 Set_Etype (N, Etype (Expr));
7202 Eval_Qualified_Expression (N);
7203 end Resolve_Qualified_Expression;
7209 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
7210 L : constant Node_Id := Low_Bound (N);
7211 H : constant Node_Id := High_Bound (N);
7218 Check_Unset_Reference (L);
7219 Check_Unset_Reference (H);
7221 -- We have to check the bounds for being within the base range as
7222 -- required for a non-static context. Normally this is automatic and
7223 -- done as part of evaluating expressions, but the N_Range node is an
7224 -- exception, since in GNAT we consider this node to be a subexpression,
7225 -- even though in Ada it is not. The circuit in Sem_Eval could check for
7226 -- this, but that would put the test on the main evaluation path for
7229 Check_Non_Static_Context (L);
7230 Check_Non_Static_Context (H);
7232 -- Check for an ambiguous range over character literals. This will
7233 -- happen with a membership test involving only literals.
7235 if Typ = Any_Character then
7236 Ambiguous_Character (L);
7237 Set_Etype (N, Any_Type);
7241 -- If bounds are static, constant-fold them, so size computations
7242 -- are identical between front-end and back-end. Do not perform this
7243 -- transformation while analyzing generic units, as type information
7244 -- would then be lost when reanalyzing the constant node in the
7247 if Is_Discrete_Type (Typ) and then Expander_Active then
7248 if Is_OK_Static_Expression (L) then
7249 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
7252 if Is_OK_Static_Expression (H) then
7253 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
7258 --------------------------
7259 -- Resolve_Real_Literal --
7260 --------------------------
7262 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
7263 Actual_Typ : constant Entity_Id := Etype (N);
7266 -- Special processing for fixed-point literals to make sure that the
7267 -- value is an exact multiple of small where this is required. We
7268 -- skip this for the universal real case, and also for generic types.
7270 if Is_Fixed_Point_Type (Typ)
7271 and then Typ /= Universal_Fixed
7272 and then Typ /= Any_Fixed
7273 and then not Is_Generic_Type (Typ)
7276 Val : constant Ureal := Realval (N);
7277 Cintr : constant Ureal := Val / Small_Value (Typ);
7278 Cint : constant Uint := UR_Trunc (Cintr);
7279 Den : constant Uint := Norm_Den (Cintr);
7283 -- Case of literal is not an exact multiple of the Small
7287 -- For a source program literal for a decimal fixed-point
7288 -- type, this is statically illegal (RM 4.9(36)).
7290 if Is_Decimal_Fixed_Point_Type (Typ)
7291 and then Actual_Typ = Universal_Real
7292 and then Comes_From_Source (N)
7294 Error_Msg_N ("value has extraneous low order digits", N);
7297 -- Generate a warning if literal from source
7299 if Is_Static_Expression (N)
7300 and then Warn_On_Bad_Fixed_Value
7303 ("?static fixed-point value is not a multiple of Small!",
7307 -- Replace literal by a value that is the exact representation
7308 -- of a value of the type, i.e. a multiple of the small value,
7309 -- by truncation, since Machine_Rounds is false for all GNAT
7310 -- fixed-point types (RM 4.9(38)).
7312 Stat := Is_Static_Expression (N);
7314 Make_Real_Literal (Sloc (N),
7315 Realval => Small_Value (Typ) * Cint));
7317 Set_Is_Static_Expression (N, Stat);
7320 -- In all cases, set the corresponding integer field
7322 Set_Corresponding_Integer_Value (N, Cint);
7326 -- Now replace the actual type by the expected type as usual
7329 Eval_Real_Literal (N);
7330 end Resolve_Real_Literal;
7332 -----------------------
7333 -- Resolve_Reference --
7334 -----------------------
7336 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
7337 P : constant Node_Id := Prefix (N);
7340 -- Replace general access with specific type
7342 if Ekind (Etype (N)) = E_Allocator_Type then
7343 Set_Etype (N, Base_Type (Typ));
7346 Resolve (P, Designated_Type (Etype (N)));
7348 -- If we are taking the reference of a volatile entity, then treat
7349 -- it as a potential modification of this entity. This is much too
7350 -- conservative, but is necessary because remove side effects can
7351 -- result in transformations of normal assignments into reference
7352 -- sequences that otherwise fail to notice the modification.
7354 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
7355 Note_Possible_Modification (P, Sure => False);
7357 end Resolve_Reference;
7359 --------------------------------
7360 -- Resolve_Selected_Component --
7361 --------------------------------
7363 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
7365 Comp1 : Entity_Id := Empty; -- prevent junk warning
7366 P : constant Node_Id := Prefix (N);
7367 S : constant Node_Id := Selector_Name (N);
7368 T : Entity_Id := Etype (P);
7370 I1 : Interp_Index := 0; -- prevent junk warning
7375 function Init_Component return Boolean;
7376 -- Check whether this is the initialization of a component within an
7377 -- init proc (by assignment or call to another init proc). If true,
7378 -- there is no need for a discriminant check.
7380 --------------------
7381 -- Init_Component --
7382 --------------------
7384 function Init_Component return Boolean is
7386 return Inside_Init_Proc
7387 and then Nkind (Prefix (N)) = N_Identifier
7388 and then Chars (Prefix (N)) = Name_uInit
7389 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
7392 -- Start of processing for Resolve_Selected_Component
7395 if Is_Overloaded (P) then
7397 -- Use the context type to select the prefix that has a selector
7398 -- of the correct name and type.
7401 Get_First_Interp (P, I, It);
7403 Search : while Present (It.Typ) loop
7404 if Is_Access_Type (It.Typ) then
7405 T := Designated_Type (It.Typ);
7410 if Is_Record_Type (T) then
7412 -- The visible components of a class-wide type are those of
7415 if Is_Class_Wide_Type (T) then
7419 Comp := First_Entity (T);
7420 while Present (Comp) loop
7421 if Chars (Comp) = Chars (S)
7422 and then Covers (Etype (Comp), Typ)
7431 It := Disambiguate (P, I1, I, Any_Type);
7433 if It = No_Interp then
7435 ("ambiguous prefix for selected component", N);
7442 -- There may be an implicit dereference. Retrieve
7443 -- designated record type.
7445 if Is_Access_Type (It1.Typ) then
7446 T := Designated_Type (It1.Typ);
7451 if Scope (Comp1) /= T then
7453 -- Resolution chooses the new interpretation.
7454 -- Find the component with the right name.
7456 Comp1 := First_Entity (T);
7457 while Present (Comp1)
7458 and then Chars (Comp1) /= Chars (S)
7460 Comp1 := Next_Entity (Comp1);
7469 Comp := Next_Entity (Comp);
7474 Get_Next_Interp (I, It);
7477 Resolve (P, It1.Typ);
7479 Set_Entity_With_Style_Check (S, Comp1);
7482 -- Resolve prefix with its type
7487 -- Generate cross-reference. We needed to wait until full overloading
7488 -- resolution was complete to do this, since otherwise we can't tell if
7489 -- we are an Lvalue of not.
7491 if May_Be_Lvalue (N) then
7492 Generate_Reference (Entity (S), S, 'm');
7494 Generate_Reference (Entity (S), S, 'r');
7497 -- If prefix is an access type, the node will be transformed into an
7498 -- explicit dereference during expansion. The type of the node is the
7499 -- designated type of that of the prefix.
7501 if Is_Access_Type (Etype (P)) then
7502 T := Designated_Type (Etype (P));
7503 Check_Fully_Declared_Prefix (T, P);
7508 if Has_Discriminants (T)
7509 and then (Ekind (Entity (S)) = E_Component
7511 Ekind (Entity (S)) = E_Discriminant)
7512 and then Present (Original_Record_Component (Entity (S)))
7513 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
7514 and then Present (Discriminant_Checking_Func
7515 (Original_Record_Component (Entity (S))))
7516 and then not Discriminant_Checks_Suppressed (T)
7517 and then not Init_Component
7519 Set_Do_Discriminant_Check (N);
7522 if Ekind (Entity (S)) = E_Void then
7523 Error_Msg_N ("premature use of component", S);
7526 -- If the prefix is a record conversion, this may be a renamed
7527 -- discriminant whose bounds differ from those of the original
7528 -- one, so we must ensure that a range check is performed.
7530 if Nkind (P) = N_Type_Conversion
7531 and then Ekind (Entity (S)) = E_Discriminant
7532 and then Is_Discrete_Type (Typ)
7534 Set_Etype (N, Base_Type (Typ));
7537 -- Note: No Eval processing is required, because the prefix is of a
7538 -- record type, or protected type, and neither can possibly be static.
7540 end Resolve_Selected_Component;
7546 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
7547 B_Typ : constant Entity_Id := Base_Type (Typ);
7548 L : constant Node_Id := Left_Opnd (N);
7549 R : constant Node_Id := Right_Opnd (N);
7552 -- We do the resolution using the base type, because intermediate values
7553 -- in expressions always are of the base type, not a subtype of it.
7556 Resolve (R, Standard_Natural);
7558 Check_Unset_Reference (L);
7559 Check_Unset_Reference (R);
7561 Set_Etype (N, B_Typ);
7562 Generate_Operator_Reference (N, B_Typ);
7566 ---------------------------
7567 -- Resolve_Short_Circuit --
7568 ---------------------------
7570 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
7571 B_Typ : constant Entity_Id := Base_Type (Typ);
7572 L : constant Node_Id := Left_Opnd (N);
7573 R : constant Node_Id := Right_Opnd (N);
7579 -- Check for issuing warning for always False assert/check, this happens
7580 -- when assertions are turned off, in which case the pragma Assert/Check
7581 -- was transformed into:
7583 -- if False and then <condition> then ...
7585 -- and we detect this pattern
7587 if Warn_On_Assertion_Failure
7588 and then Is_Entity_Name (R)
7589 and then Entity (R) = Standard_False
7590 and then Nkind (Parent (N)) = N_If_Statement
7591 and then Nkind (N) = N_And_Then
7592 and then Is_Entity_Name (L)
7593 and then Entity (L) = Standard_False
7596 Orig : constant Node_Id := Original_Node (Parent (N));
7599 if Nkind (Orig) = N_Pragma
7600 and then Pragma_Name (Orig) = Name_Assert
7602 -- Don't want to warn if original condition is explicit False
7605 Expr : constant Node_Id :=
7608 (First (Pragma_Argument_Associations (Orig))));
7610 if Is_Entity_Name (Expr)
7611 and then Entity (Expr) = Standard_False
7615 -- Issue warning. Note that we don't want to make this
7616 -- an unconditional warning, because if the assert is
7617 -- within deleted code we do not want the warning. But
7618 -- we do not want the deletion of the IF/AND-THEN to
7619 -- take this message with it. We achieve this by making
7620 -- sure that the expanded code points to the Sloc of
7621 -- the expression, not the original pragma.
7623 Error_Msg_N ("?assertion would fail at run-time", Orig);
7627 -- Similar processing for Check pragma
7629 elsif Nkind (Orig) = N_Pragma
7630 and then Pragma_Name (Orig) = Name_Check
7632 -- Don't want to warn if original condition is explicit False
7635 Expr : constant Node_Id :=
7639 (Pragma_Argument_Associations (Orig)))));
7641 if Is_Entity_Name (Expr)
7642 and then Entity (Expr) = Standard_False
7646 Error_Msg_N ("?check would fail at run-time", Orig);
7653 -- Continue with processing of short circuit
7655 Check_Unset_Reference (L);
7656 Check_Unset_Reference (R);
7658 Set_Etype (N, B_Typ);
7659 Eval_Short_Circuit (N);
7660 end Resolve_Short_Circuit;
7666 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
7667 Name : constant Node_Id := Prefix (N);
7668 Drange : constant Node_Id := Discrete_Range (N);
7669 Array_Type : Entity_Id := Empty;
7673 if Is_Overloaded (Name) then
7675 -- Use the context type to select the prefix that yields the
7676 -- correct array type.
7680 I1 : Interp_Index := 0;
7682 P : constant Node_Id := Prefix (N);
7683 Found : Boolean := False;
7686 Get_First_Interp (P, I, It);
7687 while Present (It.Typ) loop
7688 if (Is_Array_Type (It.Typ)
7689 and then Covers (Typ, It.Typ))
7690 or else (Is_Access_Type (It.Typ)
7691 and then Is_Array_Type (Designated_Type (It.Typ))
7692 and then Covers (Typ, Designated_Type (It.Typ)))
7695 It := Disambiguate (P, I1, I, Any_Type);
7697 if It = No_Interp then
7698 Error_Msg_N ("ambiguous prefix for slicing", N);
7703 Array_Type := It.Typ;
7708 Array_Type := It.Typ;
7713 Get_Next_Interp (I, It);
7718 Array_Type := Etype (Name);
7721 Resolve (Name, Array_Type);
7723 if Is_Access_Type (Array_Type) then
7724 Apply_Access_Check (N);
7725 Array_Type := Designated_Type (Array_Type);
7727 -- If the prefix is an access to an unconstrained array, we must use
7728 -- the actual subtype of the object to perform the index checks. The
7729 -- object denoted by the prefix is implicit in the node, so we build
7730 -- an explicit representation for it in order to compute the actual
7733 if not Is_Constrained (Array_Type) then
7734 Remove_Side_Effects (Prefix (N));
7737 Obj : constant Node_Id :=
7738 Make_Explicit_Dereference (Sloc (N),
7739 Prefix => New_Copy_Tree (Prefix (N)));
7741 Set_Etype (Obj, Array_Type);
7742 Set_Parent (Obj, Parent (N));
7743 Array_Type := Get_Actual_Subtype (Obj);
7747 elsif Is_Entity_Name (Name)
7748 or else (Nkind (Name) = N_Function_Call
7749 and then not Is_Constrained (Etype (Name)))
7751 Array_Type := Get_Actual_Subtype (Name);
7753 -- If the name is a selected component that depends on discriminants,
7754 -- build an actual subtype for it. This can happen only when the name
7755 -- itself is overloaded; otherwise the actual subtype is created when
7756 -- the selected component is analyzed.
7758 elsif Nkind (Name) = N_Selected_Component
7759 and then Full_Analysis
7760 and then Depends_On_Discriminant (First_Index (Array_Type))
7763 Act_Decl : constant Node_Id :=
7764 Build_Actual_Subtype_Of_Component (Array_Type, Name);
7766 Insert_Action (N, Act_Decl);
7767 Array_Type := Defining_Identifier (Act_Decl);
7771 -- If name was overloaded, set slice type correctly now
7773 Set_Etype (N, Array_Type);
7775 -- If the range is specified by a subtype mark, no resolution is
7776 -- necessary. Else resolve the bounds, and apply needed checks.
7778 if not Is_Entity_Name (Drange) then
7779 Index := First_Index (Array_Type);
7780 Resolve (Drange, Base_Type (Etype (Index)));
7782 if Nkind (Drange) = N_Range
7784 -- Do not apply the range check to nodes associated with the
7785 -- frontend expansion of the dispatch table. We first check
7786 -- if Ada.Tags is already loaded to void the addition of an
7787 -- undesired dependence on such run-time unit.
7792 (RTU_Loaded (Ada_Tags)
7793 and then Nkind (Prefix (N)) = N_Selected_Component
7794 and then Present (Entity (Selector_Name (Prefix (N))))
7795 and then Entity (Selector_Name (Prefix (N))) =
7796 RTE_Record_Component (RE_Prims_Ptr)))
7798 Apply_Range_Check (Drange, Etype (Index));
7802 Set_Slice_Subtype (N);
7804 if Nkind (Drange) = N_Range then
7805 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
7806 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
7812 ----------------------------
7813 -- Resolve_String_Literal --
7814 ----------------------------
7816 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
7817 C_Typ : constant Entity_Id := Component_Type (Typ);
7818 R_Typ : constant Entity_Id := Root_Type (C_Typ);
7819 Loc : constant Source_Ptr := Sloc (N);
7820 Str : constant String_Id := Strval (N);
7821 Strlen : constant Nat := String_Length (Str);
7822 Subtype_Id : Entity_Id;
7823 Need_Check : Boolean;
7826 -- For a string appearing in a concatenation, defer creation of the
7827 -- string_literal_subtype until the end of the resolution of the
7828 -- concatenation, because the literal may be constant-folded away. This
7829 -- is a useful optimization for long concatenation expressions.
7831 -- If the string is an aggregate built for a single character (which
7832 -- happens in a non-static context) or a is null string to which special
7833 -- checks may apply, we build the subtype. Wide strings must also get a
7834 -- string subtype if they come from a one character aggregate. Strings
7835 -- generated by attributes might be static, but it is often hard to
7836 -- determine whether the enclosing context is static, so we generate
7837 -- subtypes for them as well, thus losing some rarer optimizations ???
7838 -- Same for strings that come from a static conversion.
7841 (Strlen = 0 and then Typ /= Standard_String)
7842 or else Nkind (Parent (N)) /= N_Op_Concat
7843 or else (N /= Left_Opnd (Parent (N))
7844 and then N /= Right_Opnd (Parent (N)))
7845 or else ((Typ = Standard_Wide_String
7846 or else Typ = Standard_Wide_Wide_String)
7847 and then Nkind (Original_Node (N)) /= N_String_Literal);
7849 -- If the resolving type is itself a string literal subtype, we
7850 -- can just reuse it, since there is no point in creating another.
7852 if Ekind (Typ) = E_String_Literal_Subtype then
7855 elsif Nkind (Parent (N)) = N_Op_Concat
7856 and then not Need_Check
7857 and then not Nkind_In (Original_Node (N), N_Character_Literal,
7858 N_Attribute_Reference,
7859 N_Qualified_Expression,
7864 -- Otherwise we must create a string literal subtype. Note that the
7865 -- whole idea of string literal subtypes is simply to avoid the need
7866 -- for building a full fledged array subtype for each literal.
7869 Set_String_Literal_Subtype (N, Typ);
7870 Subtype_Id := Etype (N);
7873 if Nkind (Parent (N)) /= N_Op_Concat
7876 Set_Etype (N, Subtype_Id);
7877 Eval_String_Literal (N);
7880 if Is_Limited_Composite (Typ)
7881 or else Is_Private_Composite (Typ)
7883 Error_Msg_N ("string literal not available for private array", N);
7884 Set_Etype (N, Any_Type);
7888 -- The validity of a null string has been checked in the
7889 -- call to Eval_String_Literal.
7894 -- Always accept string literal with component type Any_Character, which
7895 -- occurs in error situations and in comparisons of literals, both of
7896 -- which should accept all literals.
7898 elsif R_Typ = Any_Character then
7901 -- If the type is bit-packed, then we always transform the string
7902 -- literal into a full fledged aggregate.
7904 elsif Is_Bit_Packed_Array (Typ) then
7907 -- Deal with cases of Wide_Wide_String, Wide_String, and String
7910 -- For Standard.Wide_Wide_String, or any other type whose component
7911 -- type is Standard.Wide_Wide_Character, we know that all the
7912 -- characters in the string must be acceptable, since the parser
7913 -- accepted the characters as valid character literals.
7915 if R_Typ = Standard_Wide_Wide_Character then
7918 -- For the case of Standard.String, or any other type whose component
7919 -- type is Standard.Character, we must make sure that there are no
7920 -- wide characters in the string, i.e. that it is entirely composed
7921 -- of characters in range of type Character.
7923 -- If the string literal is the result of a static concatenation, the
7924 -- test has already been performed on the components, and need not be
7927 elsif R_Typ = Standard_Character
7928 and then Nkind (Original_Node (N)) /= N_Op_Concat
7930 for J in 1 .. Strlen loop
7931 if not In_Character_Range (Get_String_Char (Str, J)) then
7933 -- If we are out of range, post error. This is one of the
7934 -- very few places that we place the flag in the middle of
7935 -- a token, right under the offending wide character.
7938 ("literal out of range of type Standard.Character",
7939 Source_Ptr (Int (Loc) + J));
7944 -- For the case of Standard.Wide_String, or any other type whose
7945 -- component type is Standard.Wide_Character, we must make sure that
7946 -- there are no wide characters in the string, i.e. that it is
7947 -- entirely composed of characters in range of type Wide_Character.
7949 -- If the string literal is the result of a static concatenation,
7950 -- the test has already been performed on the components, and need
7953 elsif R_Typ = Standard_Wide_Character
7954 and then Nkind (Original_Node (N)) /= N_Op_Concat
7956 for J in 1 .. Strlen loop
7957 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
7959 -- If we are out of range, post error. This is one of the
7960 -- very few places that we place the flag in the middle of
7961 -- a token, right under the offending wide character.
7963 -- This is not quite right, because characters in general
7964 -- will take more than one character position ???
7967 ("literal out of range of type Standard.Wide_Character",
7968 Source_Ptr (Int (Loc) + J));
7973 -- If the root type is not a standard character, then we will convert
7974 -- the string into an aggregate and will let the aggregate code do
7975 -- the checking. Standard Wide_Wide_Character is also OK here.
7981 -- See if the component type of the array corresponding to the string
7982 -- has compile time known bounds. If yes we can directly check
7983 -- whether the evaluation of the string will raise constraint error.
7984 -- Otherwise we need to transform the string literal into the
7985 -- corresponding character aggregate and let the aggregate
7986 -- code do the checking.
7988 if Is_Standard_Character_Type (R_Typ) then
7990 -- Check for the case of full range, where we are definitely OK
7992 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
7996 -- Here the range is not the complete base type range, so check
7999 Comp_Typ_Lo : constant Node_Id :=
8000 Type_Low_Bound (Component_Type (Typ));
8001 Comp_Typ_Hi : constant Node_Id :=
8002 Type_High_Bound (Component_Type (Typ));
8007 if Compile_Time_Known_Value (Comp_Typ_Lo)
8008 and then Compile_Time_Known_Value (Comp_Typ_Hi)
8010 for J in 1 .. Strlen loop
8011 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
8013 if Char_Val < Expr_Value (Comp_Typ_Lo)
8014 or else Char_Val > Expr_Value (Comp_Typ_Hi)
8016 Apply_Compile_Time_Constraint_Error
8017 (N, "character out of range?", CE_Range_Check_Failed,
8018 Loc => Source_Ptr (Int (Loc) + J));
8028 -- If we got here we meed to transform the string literal into the
8029 -- equivalent qualified positional array aggregate. This is rather
8030 -- heavy artillery for this situation, but it is hard work to avoid.
8033 Lits : constant List_Id := New_List;
8034 P : Source_Ptr := Loc + 1;
8038 -- Build the character literals, we give them source locations that
8039 -- correspond to the string positions, which is a bit tricky given
8040 -- the possible presence of wide character escape sequences.
8042 for J in 1 .. Strlen loop
8043 C := Get_String_Char (Str, J);
8044 Set_Character_Literal_Name (C);
8047 Make_Character_Literal (P,
8049 Char_Literal_Value => UI_From_CC (C)));
8051 if In_Character_Range (C) then
8054 -- Should we have a call to Skip_Wide here ???
8062 Make_Qualified_Expression (Loc,
8063 Subtype_Mark => New_Reference_To (Typ, Loc),
8065 Make_Aggregate (Loc, Expressions => Lits)));
8067 Analyze_And_Resolve (N, Typ);
8069 end Resolve_String_Literal;
8071 -----------------------------
8072 -- Resolve_Subprogram_Info --
8073 -----------------------------
8075 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
8078 end Resolve_Subprogram_Info;
8080 -----------------------------
8081 -- Resolve_Type_Conversion --
8082 -----------------------------
8084 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
8085 Conv_OK : constant Boolean := Conversion_OK (N);
8086 Operand : constant Node_Id := Expression (N);
8087 Operand_Typ : constant Entity_Id := Etype (Operand);
8088 Target_Typ : constant Entity_Id := Etype (N);
8095 and then not Valid_Conversion (N, Target_Typ, Operand)
8100 if Etype (Operand) = Any_Fixed then
8102 -- Mixed-mode operation involving a literal. Context must be a fixed
8103 -- type which is applied to the literal subsequently.
8105 if Is_Fixed_Point_Type (Typ) then
8106 Set_Etype (Operand, Universal_Real);
8108 elsif Is_Numeric_Type (Typ)
8109 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
8110 and then (Etype (Right_Opnd (Operand)) = Universal_Real
8112 Etype (Left_Opnd (Operand)) = Universal_Real)
8114 -- Return if expression is ambiguous
8116 if Unique_Fixed_Point_Type (N) = Any_Type then
8119 -- If nothing else, the available fixed type is Duration
8122 Set_Etype (Operand, Standard_Duration);
8125 -- Resolve the real operand with largest available precision
8127 if Etype (Right_Opnd (Operand)) = Universal_Real then
8128 Rop := New_Copy_Tree (Right_Opnd (Operand));
8130 Rop := New_Copy_Tree (Left_Opnd (Operand));
8133 Resolve (Rop, Universal_Real);
8135 -- If the operand is a literal (it could be a non-static and
8136 -- illegal exponentiation) check whether the use of Duration
8137 -- is potentially inaccurate.
8139 if Nkind (Rop) = N_Real_Literal
8140 and then Realval (Rop) /= Ureal_0
8141 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
8144 ("?universal real operand can only " &
8145 "be interpreted as Duration!",
8148 ("\?precision will be lost in the conversion!", Rop);
8151 elsif Is_Numeric_Type (Typ)
8152 and then Nkind (Operand) in N_Op
8153 and then Unique_Fixed_Point_Type (N) /= Any_Type
8155 Set_Etype (Operand, Standard_Duration);
8158 Error_Msg_N ("invalid context for mixed mode operation", N);
8159 Set_Etype (Operand, Any_Type);
8166 -- Note: we do the Eval_Type_Conversion call before applying the
8167 -- required checks for a subtype conversion. This is important,
8168 -- since both are prepared under certain circumstances to change
8169 -- the type conversion to a constraint error node, but in the case
8170 -- of Eval_Type_Conversion this may reflect an illegality in the
8171 -- static case, and we would miss the illegality (getting only a
8172 -- warning message), if we applied the type conversion checks first.
8174 Eval_Type_Conversion (N);
8176 -- Even when evaluation is not possible, we may be able to simplify
8177 -- the conversion or its expression. This needs to be done before
8178 -- applying checks, since otherwise the checks may use the original
8179 -- expression and defeat the simplifications. This is specifically
8180 -- the case for elimination of the floating-point Truncation
8181 -- attribute in float-to-int conversions.
8183 Simplify_Type_Conversion (N);
8185 -- If after evaluation we still have a type conversion, then we
8186 -- may need to apply checks required for a subtype conversion.
8188 -- Skip these type conversion checks if universal fixed operands
8189 -- operands involved, since range checks are handled separately for
8190 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
8192 if Nkind (N) = N_Type_Conversion
8193 and then not Is_Generic_Type (Root_Type (Target_Typ))
8194 and then Target_Typ /= Universal_Fixed
8195 and then Operand_Typ /= Universal_Fixed
8197 Apply_Type_Conversion_Checks (N);
8200 -- Issue warning for conversion of simple object to its own type
8201 -- We have to test the original nodes, since they may have been
8202 -- rewritten by various optimizations.
8204 Orig_N := Original_Node (N);
8206 if Warn_On_Redundant_Constructs
8207 and then Comes_From_Source (Orig_N)
8208 and then Nkind (Orig_N) = N_Type_Conversion
8209 and then not In_Instance
8211 Orig_N := Original_Node (Expression (Orig_N));
8212 Orig_T := Target_Typ;
8214 -- If the node is part of a larger expression, the Target_Type
8215 -- may not be the original type of the node if the context is a
8216 -- condition. Recover original type to see if conversion is needed.
8218 if Is_Boolean_Type (Orig_T)
8219 and then Nkind (Parent (N)) in N_Op
8221 Orig_T := Etype (Parent (N));
8224 if Is_Entity_Name (Orig_N)
8226 (Etype (Entity (Orig_N)) = Orig_T
8228 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
8229 and then Covers (Orig_T, Etype (Entity (Orig_N)))))
8231 Error_Msg_Node_2 := Orig_T;
8233 ("?redundant conversion, & is of type &!", N, Entity (Orig_N));
8237 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
8238 -- No need to perform any interface conversion if the type of the
8239 -- expression coincides with the target type.
8241 if Ada_Version >= Ada_05
8242 and then Expander_Active
8243 and then Operand_Typ /= Target_Typ
8246 Opnd : Entity_Id := Operand_Typ;
8247 Target : Entity_Id := Target_Typ;
8250 if Is_Access_Type (Opnd) then
8251 Opnd := Directly_Designated_Type (Opnd);
8254 if Is_Access_Type (Target_Typ) then
8255 Target := Directly_Designated_Type (Target);
8258 if Opnd = Target then
8261 -- Conversion from interface type
8263 elsif Is_Interface (Opnd) then
8265 -- Ada 2005 (AI-217): Handle entities from limited views
8267 if From_With_Type (Opnd) then
8268 Error_Msg_Qual_Level := 99;
8269 Error_Msg_NE ("missing with-clause on package &", N,
8270 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
8272 ("type conversions require visibility of the full view",
8275 elsif From_With_Type (Target)
8277 (Is_Access_Type (Target_Typ)
8278 and then Present (Non_Limited_View (Etype (Target))))
8280 Error_Msg_Qual_Level := 99;
8281 Error_Msg_NE ("missing with-clause on package &", N,
8282 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
8284 ("type conversions require visibility of the full view",
8288 Expand_Interface_Conversion (N, Is_Static => False);
8291 -- Conversion to interface type
8293 elsif Is_Interface (Target) then
8297 if Ekind (Opnd) = E_Protected_Subtype
8298 or else Ekind (Opnd) = E_Task_Subtype
8300 Opnd := Etype (Opnd);
8303 if not Interface_Present_In_Ancestor
8307 if Is_Class_Wide_Type (Opnd) then
8309 -- The static analysis is not enough to know if the
8310 -- interface is implemented or not. Hence we must pass
8311 -- the work to the expander to generate code to evaluate
8312 -- the conversion at run-time.
8314 Expand_Interface_Conversion (N, Is_Static => False);
8317 Error_Msg_Name_1 := Chars (Etype (Target));
8318 Error_Msg_Name_2 := Chars (Opnd);
8320 ("wrong interface conversion (% is not a progenitor " &
8325 Expand_Interface_Conversion (N);
8330 end Resolve_Type_Conversion;
8332 ----------------------
8333 -- Resolve_Unary_Op --
8334 ----------------------
8336 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
8337 B_Typ : constant Entity_Id := Base_Type (Typ);
8338 R : constant Node_Id := Right_Opnd (N);
8344 -- Deal with intrinsic unary operators
8346 if Comes_From_Source (N)
8347 and then Ekind (Entity (N)) = E_Function
8348 and then Is_Imported (Entity (N))
8349 and then Is_Intrinsic_Subprogram (Entity (N))
8351 Resolve_Intrinsic_Unary_Operator (N, Typ);
8355 -- Deal with universal cases
8357 if Etype (R) = Universal_Integer
8359 Etype (R) = Universal_Real
8361 Check_For_Visible_Operator (N, B_Typ);
8364 Set_Etype (N, B_Typ);
8367 -- Generate warning for expressions like abs (x mod 2)
8369 if Warn_On_Redundant_Constructs
8370 and then Nkind (N) = N_Op_Abs
8372 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
8374 if OK and then Hi >= Lo and then Lo >= 0 then
8376 ("?abs applied to known non-negative value has no effect", N);
8380 -- Deal with reference generation
8382 Check_Unset_Reference (R);
8383 Generate_Operator_Reference (N, B_Typ);
8386 -- Set overflow checking bit. Much cleverer code needed here eventually
8387 -- and perhaps the Resolve routines should be separated for the various
8388 -- arithmetic operations, since they will need different processing ???
8390 if Nkind (N) in N_Op then
8391 if not Overflow_Checks_Suppressed (Etype (N)) then
8392 Enable_Overflow_Check (N);
8396 -- Generate warning for expressions like -5 mod 3 for integers. No
8397 -- need to worry in the floating-point case, since parens do not affect
8398 -- the result so there is no point in giving in a warning.
8401 Norig : constant Node_Id := Original_Node (N);
8410 if Warn_On_Questionable_Missing_Parens
8411 and then Comes_From_Source (Norig)
8412 and then Is_Integer_Type (Typ)
8413 and then Nkind (Norig) = N_Op_Minus
8415 Rorig := Original_Node (Right_Opnd (Norig));
8417 -- We are looking for cases where the right operand is not
8418 -- parenthesized, and is a binary operator, multiply, divide, or
8419 -- mod. These are the cases where the grouping can affect results.
8421 if Paren_Count (Rorig) = 0
8422 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
8424 -- For mod, we always give the warning, since the value is
8425 -- affected by the parenthesization (e.g. (-5) mod 315 /=
8426 -- (5 mod 315)). But for the other cases, the only concern is
8427 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
8428 -- overflows, but (-2) * 64 does not). So we try to give the
8429 -- message only when overflow is possible.
8431 if Nkind (Rorig) /= N_Op_Mod
8432 and then Compile_Time_Known_Value (R)
8434 Val := Expr_Value (R);
8436 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
8437 HB := Expr_Value (Type_High_Bound (Typ));
8439 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
8442 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
8443 LB := Expr_Value (Type_Low_Bound (Typ));
8445 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
8448 -- Note that the test below is deliberately excluding
8449 -- the largest negative number, since that is a potentially
8450 -- troublesome case (e.g. -2 * x, where the result is the
8451 -- largest negative integer has an overflow with 2 * x).
8453 if Val > LB and then Val <= HB then
8458 -- For the multiplication case, the only case we have to worry
8459 -- about is when (-a)*b is exactly the largest negative number
8460 -- so that -(a*b) can cause overflow. This can only happen if
8461 -- a is a power of 2, and more generally if any operand is a
8462 -- constant that is not a power of 2, then the parentheses
8463 -- cannot affect whether overflow occurs. We only bother to
8464 -- test the left most operand
8466 -- Loop looking at left operands for one that has known value
8469 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
8470 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
8471 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
8473 -- Operand value of 0 or 1 skips warning
8478 -- Otherwise check power of 2, if power of 2, warn, if
8479 -- anything else, skip warning.
8482 while Lval /= 2 loop
8483 if Lval mod 2 = 1 then
8494 -- Keep looking at left operands
8496 Opnd := Left_Opnd (Opnd);
8499 -- For rem or "/" we can only have a problematic situation
8500 -- if the divisor has a value of minus one or one. Otherwise
8501 -- overflow is impossible (divisor > 1) or we have a case of
8502 -- division by zero in any case.
8504 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
8505 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
8506 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
8511 -- If we fall through warning should be issued
8514 ("?unary minus expression should be parenthesized here!", N);
8518 end Resolve_Unary_Op;
8520 ----------------------------------
8521 -- Resolve_Unchecked_Expression --
8522 ----------------------------------
8524 procedure Resolve_Unchecked_Expression
8529 Resolve (Expression (N), Typ, Suppress => All_Checks);
8531 end Resolve_Unchecked_Expression;
8533 ---------------------------------------
8534 -- Resolve_Unchecked_Type_Conversion --
8535 ---------------------------------------
8537 procedure Resolve_Unchecked_Type_Conversion
8541 pragma Warnings (Off, Typ);
8543 Operand : constant Node_Id := Expression (N);
8544 Opnd_Type : constant Entity_Id := Etype (Operand);
8547 -- Resolve operand using its own type
8549 Resolve (Operand, Opnd_Type);
8550 Eval_Unchecked_Conversion (N);
8552 end Resolve_Unchecked_Type_Conversion;
8554 ------------------------------
8555 -- Rewrite_Operator_As_Call --
8556 ------------------------------
8558 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
8559 Loc : constant Source_Ptr := Sloc (N);
8560 Actuals : constant List_Id := New_List;
8564 if Nkind (N) in N_Binary_Op then
8565 Append (Left_Opnd (N), Actuals);
8568 Append (Right_Opnd (N), Actuals);
8571 Make_Function_Call (Sloc => Loc,
8572 Name => New_Occurrence_Of (Nam, Loc),
8573 Parameter_Associations => Actuals);
8575 Preserve_Comes_From_Source (New_N, N);
8576 Preserve_Comes_From_Source (Name (New_N), N);
8578 Set_Etype (N, Etype (Nam));
8579 end Rewrite_Operator_As_Call;
8581 ------------------------------
8582 -- Rewrite_Renamed_Operator --
8583 ------------------------------
8585 procedure Rewrite_Renamed_Operator
8590 Nam : constant Name_Id := Chars (Op);
8591 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
8595 -- Rewrite the operator node using the real operator, not its
8596 -- renaming. Exclude user-defined intrinsic operations of the same
8597 -- name, which are treated separately and rewritten as calls.
8599 if Ekind (Op) /= E_Function
8600 or else Chars (N) /= Nam
8602 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
8603 Set_Chars (Op_Node, Nam);
8604 Set_Etype (Op_Node, Etype (N));
8605 Set_Entity (Op_Node, Op);
8606 Set_Right_Opnd (Op_Node, Right_Opnd (N));
8608 -- Indicate that both the original entity and its renaming are
8609 -- referenced at this point.
8611 Generate_Reference (Entity (N), N);
8612 Generate_Reference (Op, N);
8615 Set_Left_Opnd (Op_Node, Left_Opnd (N));
8618 Rewrite (N, Op_Node);
8620 -- If the context type is private, add the appropriate conversions
8621 -- so that the operator is applied to the full view. This is done
8622 -- in the routines that resolve intrinsic operators,
8624 if Is_Intrinsic_Subprogram (Op)
8625 and then Is_Private_Type (Typ)
8628 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
8629 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
8630 Resolve_Intrinsic_Operator (N, Typ);
8632 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
8633 Resolve_Intrinsic_Unary_Operator (N, Typ);
8640 elsif Ekind (Op) = E_Function
8641 and then Is_Intrinsic_Subprogram (Op)
8643 -- Operator renames a user-defined operator of the same name. Use
8644 -- the original operator in the node, which is the one that Gigi
8648 Set_Is_Overloaded (N, False);
8650 end Rewrite_Renamed_Operator;
8652 -----------------------
8653 -- Set_Slice_Subtype --
8654 -----------------------
8656 -- Build an implicit subtype declaration to represent the type delivered
8657 -- by the slice. This is an abbreviated version of an array subtype. We
8658 -- define an index subtype for the slice, using either the subtype name
8659 -- or the discrete range of the slice. To be consistent with index usage
8660 -- elsewhere, we create a list header to hold the single index. This list
8661 -- is not otherwise attached to the syntax tree.
8663 procedure Set_Slice_Subtype (N : Node_Id) is
8664 Loc : constant Source_Ptr := Sloc (N);
8665 Index_List : constant List_Id := New_List;
8667 Index_Subtype : Entity_Id;
8668 Index_Type : Entity_Id;
8669 Slice_Subtype : Entity_Id;
8670 Drange : constant Node_Id := Discrete_Range (N);
8673 if Is_Entity_Name (Drange) then
8674 Index_Subtype := Entity (Drange);
8677 -- We force the evaluation of a range. This is definitely needed in
8678 -- the renamed case, and seems safer to do unconditionally. Note in
8679 -- any case that since we will create and insert an Itype referring
8680 -- to this range, we must make sure any side effect removal actions
8681 -- are inserted before the Itype definition.
8683 if Nkind (Drange) = N_Range then
8684 Force_Evaluation (Low_Bound (Drange));
8685 Force_Evaluation (High_Bound (Drange));
8688 Index_Type := Base_Type (Etype (Drange));
8690 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
8692 Set_Scalar_Range (Index_Subtype, Drange);
8693 Set_Etype (Index_Subtype, Index_Type);
8694 Set_Size_Info (Index_Subtype, Index_Type);
8695 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
8698 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
8700 Index := New_Occurrence_Of (Index_Subtype, Loc);
8701 Set_Etype (Index, Index_Subtype);
8702 Append (Index, Index_List);
8704 Set_First_Index (Slice_Subtype, Index);
8705 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
8706 Set_Is_Constrained (Slice_Subtype, True);
8708 Check_Compile_Time_Size (Slice_Subtype);
8710 -- The Etype of the existing Slice node is reset to this slice subtype.
8711 -- Its bounds are obtained from its first index.
8713 Set_Etype (N, Slice_Subtype);
8715 -- In the packed case, this must be immediately frozen
8717 -- Couldn't we always freeze here??? and if we did, then the above
8718 -- call to Check_Compile_Time_Size could be eliminated, which would
8719 -- be nice, because then that routine could be made private to Freeze.
8721 -- Why the test for In_Spec_Expression here ???
8723 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
8724 Freeze_Itype (Slice_Subtype, N);
8727 end Set_Slice_Subtype;
8729 --------------------------------
8730 -- Set_String_Literal_Subtype --
8731 --------------------------------
8733 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
8734 Loc : constant Source_Ptr := Sloc (N);
8735 Low_Bound : constant Node_Id :=
8736 Type_Low_Bound (Etype (First_Index (Typ)));
8737 Subtype_Id : Entity_Id;
8740 if Nkind (N) /= N_String_Literal then
8744 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
8745 Set_String_Literal_Length (Subtype_Id, UI_From_Int
8746 (String_Length (Strval (N))));
8747 Set_Etype (Subtype_Id, Base_Type (Typ));
8748 Set_Is_Constrained (Subtype_Id);
8749 Set_Etype (N, Subtype_Id);
8751 if Is_OK_Static_Expression (Low_Bound) then
8753 -- The low bound is set from the low bound of the corresponding
8754 -- index type. Note that we do not store the high bound in the
8755 -- string literal subtype, but it can be deduced if necessary
8756 -- from the length and the low bound.
8758 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
8761 Set_String_Literal_Low_Bound
8762 (Subtype_Id, Make_Integer_Literal (Loc, 1));
8763 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Standard_Positive);
8765 -- Build bona fide subtype for the string, and wrap it in an
8766 -- unchecked conversion, because the backend expects the
8767 -- String_Literal_Subtype to have a static lower bound.
8770 Index_List : constant List_Id := New_List;
8771 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
8772 High_Bound : constant Node_Id :=
8774 Left_Opnd => New_Copy_Tree (Low_Bound),
8776 Make_Integer_Literal (Loc,
8777 String_Length (Strval (N)) - 1));
8778 Array_Subtype : Entity_Id;
8779 Index_Subtype : Entity_Id;
8785 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
8786 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
8787 Set_Scalar_Range (Index_Subtype, Drange);
8788 Set_Parent (Drange, N);
8789 Analyze_And_Resolve (Drange, Index_Type);
8791 -- In the context, the Index_Type may already have a constraint,
8792 -- so use common base type on string subtype. The base type may
8793 -- be used when generating attributes of the string, for example
8794 -- in the context of a slice assignment.
8796 Set_Etype (Index_Subtype, Base_Type (Index_Type));
8797 Set_Size_Info (Index_Subtype, Index_Type);
8798 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
8800 Array_Subtype := Create_Itype (E_Array_Subtype, N);
8802 Index := New_Occurrence_Of (Index_Subtype, Loc);
8803 Set_Etype (Index, Index_Subtype);
8804 Append (Index, Index_List);
8806 Set_First_Index (Array_Subtype, Index);
8807 Set_Etype (Array_Subtype, Base_Type (Typ));
8808 Set_Is_Constrained (Array_Subtype, True);
8811 Make_Unchecked_Type_Conversion (Loc,
8812 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
8813 Expression => Relocate_Node (N)));
8814 Set_Etype (N, Array_Subtype);
8817 end Set_String_Literal_Subtype;
8819 ------------------------------
8820 -- Simplify_Type_Conversion --
8821 ------------------------------
8823 procedure Simplify_Type_Conversion (N : Node_Id) is
8825 if Nkind (N) = N_Type_Conversion then
8827 Operand : constant Node_Id := Expression (N);
8828 Target_Typ : constant Entity_Id := Etype (N);
8829 Opnd_Typ : constant Entity_Id := Etype (Operand);
8832 if Is_Floating_Point_Type (Opnd_Typ)
8834 (Is_Integer_Type (Target_Typ)
8835 or else (Is_Fixed_Point_Type (Target_Typ)
8836 and then Conversion_OK (N)))
8837 and then Nkind (Operand) = N_Attribute_Reference
8838 and then Attribute_Name (Operand) = Name_Truncation
8840 -- Special processing required if the conversion is the expression
8841 -- of a Truncation attribute reference. In this case we replace:
8843 -- ityp (ftyp'Truncation (x))
8849 -- with the Float_Truncate flag set, which is more efficient
8853 Relocate_Node (First (Expressions (Operand))));
8854 Set_Float_Truncate (N, True);
8858 end Simplify_Type_Conversion;
8860 -----------------------------
8861 -- Unique_Fixed_Point_Type --
8862 -----------------------------
8864 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
8865 T1 : Entity_Id := Empty;
8870 procedure Fixed_Point_Error;
8871 -- If true ambiguity, give details
8873 -----------------------
8874 -- Fixed_Point_Error --
8875 -----------------------
8877 procedure Fixed_Point_Error is
8879 Error_Msg_N ("ambiguous universal_fixed_expression", N);
8880 Error_Msg_NE ("\\possible interpretation as}", N, T1);
8881 Error_Msg_NE ("\\possible interpretation as}", N, T2);
8882 end Fixed_Point_Error;
8884 -- Start of processing for Unique_Fixed_Point_Type
8887 -- The operations on Duration are visible, so Duration is always a
8888 -- possible interpretation.
8890 T1 := Standard_Duration;
8892 -- Look for fixed-point types in enclosing scopes
8894 Scop := Current_Scope;
8895 while Scop /= Standard_Standard loop
8896 T2 := First_Entity (Scop);
8897 while Present (T2) loop
8898 if Is_Fixed_Point_Type (T2)
8899 and then Current_Entity (T2) = T2
8900 and then Scope (Base_Type (T2)) = Scop
8902 if Present (T1) then
8913 Scop := Scope (Scop);
8916 -- Look for visible fixed type declarations in the context
8918 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
8919 while Present (Item) loop
8920 if Nkind (Item) = N_With_Clause then
8921 Scop := Entity (Name (Item));
8922 T2 := First_Entity (Scop);
8923 while Present (T2) loop
8924 if Is_Fixed_Point_Type (T2)
8925 and then Scope (Base_Type (T2)) = Scop
8926 and then (Is_Potentially_Use_Visible (T2)
8927 or else In_Use (T2))
8929 if Present (T1) then
8944 if Nkind (N) = N_Real_Literal then
8945 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
8947 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
8951 end Unique_Fixed_Point_Type;
8953 ----------------------
8954 -- Valid_Conversion --
8955 ----------------------
8957 function Valid_Conversion
8960 Operand : Node_Id) return Boolean
8962 Target_Type : constant Entity_Id := Base_Type (Target);
8963 Opnd_Type : Entity_Id := Etype (Operand);
8965 function Conversion_Check
8967 Msg : String) return Boolean;
8968 -- Little routine to post Msg if Valid is False, returns Valid value
8970 function Valid_Tagged_Conversion
8971 (Target_Type : Entity_Id;
8972 Opnd_Type : Entity_Id) return Boolean;
8973 -- Specifically test for validity of tagged conversions
8975 function Valid_Array_Conversion return Boolean;
8976 -- Check index and component conformance, and accessibility levels
8977 -- if the component types are anonymous access types (Ada 2005)
8979 ----------------------
8980 -- Conversion_Check --
8981 ----------------------
8983 function Conversion_Check
8985 Msg : String) return Boolean
8989 Error_Msg_N (Msg, Operand);
8993 end Conversion_Check;
8995 ----------------------------
8996 -- Valid_Array_Conversion --
8997 ----------------------------
8999 function Valid_Array_Conversion return Boolean
9001 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
9002 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
9004 Opnd_Index : Node_Id;
9005 Opnd_Index_Type : Entity_Id;
9007 Target_Comp_Type : constant Entity_Id :=
9008 Component_Type (Target_Type);
9009 Target_Comp_Base : constant Entity_Id :=
9010 Base_Type (Target_Comp_Type);
9012 Target_Index : Node_Id;
9013 Target_Index_Type : Entity_Id;
9016 -- Error if wrong number of dimensions
9019 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
9022 ("incompatible number of dimensions for conversion", Operand);
9025 -- Number of dimensions matches
9028 -- Loop through indexes of the two arrays
9030 Target_Index := First_Index (Target_Type);
9031 Opnd_Index := First_Index (Opnd_Type);
9032 while Present (Target_Index) and then Present (Opnd_Index) loop
9033 Target_Index_Type := Etype (Target_Index);
9034 Opnd_Index_Type := Etype (Opnd_Index);
9036 -- Error if index types are incompatible
9038 if not (Is_Integer_Type (Target_Index_Type)
9039 and then Is_Integer_Type (Opnd_Index_Type))
9040 and then (Root_Type (Target_Index_Type)
9041 /= Root_Type (Opnd_Index_Type))
9044 ("incompatible index types for array conversion",
9049 Next_Index (Target_Index);
9050 Next_Index (Opnd_Index);
9053 -- If component types have same base type, all set
9055 if Target_Comp_Base = Opnd_Comp_Base then
9058 -- Here if base types of components are not the same. The only
9059 -- time this is allowed is if we have anonymous access types.
9061 -- The conversion of arrays of anonymous access types can lead
9062 -- to dangling pointers. AI-392 formalizes the accessibility
9063 -- checks that must be applied to such conversions to prevent
9064 -- out-of-scope references.
9067 (Ekind (Target_Comp_Base) = E_Anonymous_Access_Type
9069 Ekind (Target_Comp_Base) = E_Anonymous_Access_Subprogram_Type)
9070 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
9072 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
9074 if Type_Access_Level (Target_Type) <
9075 Type_Access_Level (Opnd_Type)
9077 if In_Instance_Body then
9078 Error_Msg_N ("?source array type " &
9079 "has deeper accessibility level than target", Operand);
9080 Error_Msg_N ("\?Program_Error will be raised at run time",
9083 Make_Raise_Program_Error (Sloc (N),
9084 Reason => PE_Accessibility_Check_Failed));
9085 Set_Etype (N, Target_Type);
9088 -- Conversion not allowed because of accessibility levels
9091 Error_Msg_N ("source array type " &
9092 "has deeper accessibility level than target", Operand);
9099 -- All other cases where component base types do not match
9103 ("incompatible component types for array conversion",
9108 -- Check that component subtypes statically match. For numeric
9109 -- types this means that both must be either constrained or
9110 -- unconstrained. For enumeration types the bounds must match.
9111 -- All of this is checked in Subtypes_Statically_Match.
9113 if not Subtypes_Statically_Match
9114 (Target_Comp_Type, Opnd_Comp_Type)
9117 ("component subtypes must statically match", Operand);
9123 end Valid_Array_Conversion;
9125 -----------------------------
9126 -- Valid_Tagged_Conversion --
9127 -----------------------------
9129 function Valid_Tagged_Conversion
9130 (Target_Type : Entity_Id;
9131 Opnd_Type : Entity_Id) return Boolean
9134 -- Upward conversions are allowed (RM 4.6(22))
9136 if Covers (Target_Type, Opnd_Type)
9137 or else Is_Ancestor (Target_Type, Opnd_Type)
9141 -- Downward conversion are allowed if the operand is class-wide
9144 elsif Is_Class_Wide_Type (Opnd_Type)
9145 and then Covers (Opnd_Type, Target_Type)
9149 elsif Covers (Opnd_Type, Target_Type)
9150 or else Is_Ancestor (Opnd_Type, Target_Type)
9153 Conversion_Check (False,
9154 "downward conversion of tagged objects not allowed");
9156 -- Ada 2005 (AI-251): The conversion to/from interface types is
9159 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
9162 -- If the operand is a class-wide type obtained through a limited_
9163 -- with clause, and the context includes the non-limited view, use
9164 -- it to determine whether the conversion is legal.
9166 elsif Is_Class_Wide_Type (Opnd_Type)
9167 and then From_With_Type (Opnd_Type)
9168 and then Present (Non_Limited_View (Etype (Opnd_Type)))
9169 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
9173 elsif Is_Access_Type (Opnd_Type)
9174 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
9180 ("invalid tagged conversion, not compatible with}",
9181 N, First_Subtype (Opnd_Type));
9184 end Valid_Tagged_Conversion;
9186 -- Start of processing for Valid_Conversion
9189 Check_Parameterless_Call (Operand);
9191 if Is_Overloaded (Operand) then
9200 -- Remove procedure calls, which syntactically cannot appear
9201 -- in this context, but which cannot be removed by type checking,
9202 -- because the context does not impose a type.
9204 -- When compiling for VMS, spurious ambiguities can be produced
9205 -- when arithmetic operations have a literal operand and return
9206 -- System.Address or a descendant of it. These ambiguities are
9207 -- otherwise resolved by the context, but for conversions there
9208 -- is no context type and the removal of the spurious operations
9209 -- must be done explicitly here.
9211 -- The node may be labelled overloaded, but still contain only
9212 -- one interpretation because others were discarded in previous
9213 -- filters. If this is the case, retain the single interpretation
9216 Get_First_Interp (Operand, I, It);
9217 Opnd_Type := It.Typ;
9218 Get_Next_Interp (I, It);
9221 and then Opnd_Type /= Standard_Void_Type
9223 -- More than one candidate interpretation is available
9225 Get_First_Interp (Operand, I, It);
9226 while Present (It.Typ) loop
9227 if It.Typ = Standard_Void_Type then
9231 if Present (System_Aux_Id)
9232 and then Is_Descendent_Of_Address (It.Typ)
9237 Get_Next_Interp (I, It);
9241 Get_First_Interp (Operand, I, It);
9246 Error_Msg_N ("illegal operand in conversion", Operand);
9250 Get_Next_Interp (I, It);
9252 if Present (It.Typ) then
9254 It1 := Disambiguate (Operand, I1, I, Any_Type);
9256 if It1 = No_Interp then
9257 Error_Msg_N ("ambiguous operand in conversion", Operand);
9259 Error_Msg_Sloc := Sloc (It.Nam);
9260 Error_Msg_N ("\\possible interpretation#!", Operand);
9262 Error_Msg_Sloc := Sloc (N1);
9263 Error_Msg_N ("\\possible interpretation#!", Operand);
9269 Set_Etype (Operand, It1.Typ);
9270 Opnd_Type := It1.Typ;
9276 if Is_Numeric_Type (Target_Type) then
9278 -- A universal fixed expression can be converted to any numeric type
9280 if Opnd_Type = Universal_Fixed then
9283 -- Also no need to check when in an instance or inlined body, because
9284 -- the legality has been established when the template was analyzed.
9285 -- Furthermore, numeric conversions may occur where only a private
9286 -- view of the operand type is visible at the instantiation point.
9287 -- This results in a spurious error if we check that the operand type
9288 -- is a numeric type.
9290 -- Note: in a previous version of this unit, the following tests were
9291 -- applied only for generated code (Comes_From_Source set to False),
9292 -- but in fact the test is required for source code as well, since
9293 -- this situation can arise in source code.
9295 elsif In_Instance or else In_Inlined_Body then
9298 -- Otherwise we need the conversion check
9301 return Conversion_Check
9302 (Is_Numeric_Type (Opnd_Type),
9303 "illegal operand for numeric conversion");
9308 elsif Is_Array_Type (Target_Type) then
9309 if not Is_Array_Type (Opnd_Type)
9310 or else Opnd_Type = Any_Composite
9311 or else Opnd_Type = Any_String
9314 ("illegal operand for array conversion", Operand);
9317 return Valid_Array_Conversion;
9320 -- Ada 2005 (AI-251): Anonymous access types where target references an
9323 elsif (Ekind (Target_Type) = E_General_Access_Type
9325 Ekind (Target_Type) = E_Anonymous_Access_Type)
9326 and then Is_Interface (Directly_Designated_Type (Target_Type))
9328 -- Check the static accessibility rule of 4.6(17). Note that the
9329 -- check is not enforced when within an instance body, since the RM
9330 -- requires such cases to be caught at run time.
9332 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
9333 if Type_Access_Level (Opnd_Type) >
9334 Type_Access_Level (Target_Type)
9336 -- In an instance, this is a run-time check, but one we know
9337 -- will fail, so generate an appropriate warning. The raise
9338 -- will be generated by Expand_N_Type_Conversion.
9340 if In_Instance_Body then
9342 ("?cannot convert local pointer to non-local access type",
9345 ("\?Program_Error will be raised at run time", Operand);
9348 ("cannot convert local pointer to non-local access type",
9353 -- Special accessibility checks are needed in the case of access
9354 -- discriminants declared for a limited type.
9356 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9357 and then not Is_Local_Anonymous_Access (Opnd_Type)
9359 -- When the operand is a selected access discriminant the check
9360 -- needs to be made against the level of the object denoted by
9361 -- the prefix of the selected name. (Object_Access_Level
9362 -- handles checking the prefix of the operand for this case.)
9364 if Nkind (Operand) = N_Selected_Component
9365 and then Object_Access_Level (Operand) >
9366 Type_Access_Level (Target_Type)
9368 -- In an instance, this is a run-time check, but one we
9369 -- know will fail, so generate an appropriate warning.
9370 -- The raise will be generated by Expand_N_Type_Conversion.
9372 if In_Instance_Body then
9374 ("?cannot convert access discriminant to non-local" &
9375 " access type", Operand);
9377 ("\?Program_Error will be raised at run time", Operand);
9380 ("cannot convert access discriminant to non-local" &
9381 " access type", Operand);
9386 -- The case of a reference to an access discriminant from
9387 -- within a limited type declaration (which will appear as
9388 -- a discriminal) is always illegal because the level of the
9389 -- discriminant is considered to be deeper than any (nameable)
9392 if Is_Entity_Name (Operand)
9393 and then not Is_Local_Anonymous_Access (Opnd_Type)
9394 and then (Ekind (Entity (Operand)) = E_In_Parameter
9395 or else Ekind (Entity (Operand)) = E_Constant)
9396 and then Present (Discriminal_Link (Entity (Operand)))
9399 ("discriminant has deeper accessibility level than target",
9408 -- General and anonymous access types
9410 elsif (Ekind (Target_Type) = E_General_Access_Type
9411 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
9414 (Is_Access_Type (Opnd_Type)
9415 and then Ekind (Opnd_Type) /=
9416 E_Access_Subprogram_Type
9417 and then Ekind (Opnd_Type) /=
9418 E_Access_Protected_Subprogram_Type,
9419 "must be an access-to-object type")
9421 if Is_Access_Constant (Opnd_Type)
9422 and then not Is_Access_Constant (Target_Type)
9425 ("access-to-constant operand type not allowed", Operand);
9429 -- Check the static accessibility rule of 4.6(17). Note that the
9430 -- check is not enforced when within an instance body, since the RM
9431 -- requires such cases to be caught at run time.
9433 if Ekind (Target_Type) /= E_Anonymous_Access_Type
9434 or else Is_Local_Anonymous_Access (Target_Type)
9436 if Type_Access_Level (Opnd_Type)
9437 > Type_Access_Level (Target_Type)
9439 -- In an instance, this is a run-time check, but one we
9440 -- know will fail, so generate an appropriate warning.
9441 -- The raise will be generated by Expand_N_Type_Conversion.
9443 if In_Instance_Body then
9445 ("?cannot convert local pointer to non-local access type",
9448 ("\?Program_Error will be raised at run time", Operand);
9451 -- Avoid generation of spurious error message
9453 if not Error_Posted (N) then
9455 ("cannot convert local pointer to non-local access type",
9462 -- Special accessibility checks are needed in the case of access
9463 -- discriminants declared for a limited type.
9465 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9466 and then not Is_Local_Anonymous_Access (Opnd_Type)
9469 -- When the operand is a selected access discriminant the check
9470 -- needs to be made against the level of the object denoted by
9471 -- the prefix of the selected name. (Object_Access_Level
9472 -- handles checking the prefix of the operand for this case.)
9474 if Nkind (Operand) = N_Selected_Component
9475 and then Object_Access_Level (Operand) >
9476 Type_Access_Level (Target_Type)
9478 -- In an instance, this is a run-time check, but one we
9479 -- know will fail, so generate an appropriate warning.
9480 -- The raise will be generated by Expand_N_Type_Conversion.
9482 if In_Instance_Body then
9484 ("?cannot convert access discriminant to non-local" &
9485 " access type", Operand);
9487 ("\?Program_Error will be raised at run time",
9492 ("cannot convert access discriminant to non-local" &
9493 " access type", Operand);
9498 -- The case of a reference to an access discriminant from
9499 -- within a limited type declaration (which will appear as
9500 -- a discriminal) is always illegal because the level of the
9501 -- discriminant is considered to be deeper than any (nameable)
9504 if Is_Entity_Name (Operand)
9505 and then (Ekind (Entity (Operand)) = E_In_Parameter
9506 or else Ekind (Entity (Operand)) = E_Constant)
9507 and then Present (Discriminal_Link (Entity (Operand)))
9510 ("discriminant has deeper accessibility level than target",
9518 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
9519 -- Helper function to handle limited views
9521 --------------------------
9522 -- Full_Designated_Type --
9523 --------------------------
9525 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
9526 Desig : constant Entity_Id := Designated_Type (T);
9528 if From_With_Type (Desig)
9529 and then Is_Incomplete_Type (Desig)
9530 and then Present (Non_Limited_View (Desig))
9532 return Non_Limited_View (Desig);
9536 end Full_Designated_Type;
9538 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
9539 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
9541 Same_Base : constant Boolean :=
9542 Base_Type (Target) = Base_Type (Opnd);
9545 if Is_Tagged_Type (Target) then
9546 return Valid_Tagged_Conversion (Target, Opnd);
9549 if not Same_Base then
9551 ("target designated type not compatible with }",
9552 N, Base_Type (Opnd));
9555 -- Ada 2005 AI-384: legality rule is symmetric in both
9556 -- designated types. The conversion is legal (with possible
9557 -- constraint check) if either designated type is
9560 elsif Subtypes_Statically_Match (Target, Opnd)
9562 (Has_Discriminants (Target)
9564 (not Is_Constrained (Opnd)
9565 or else not Is_Constrained (Target)))
9567 -- Special case, if Value_Size has been used to make the
9568 -- sizes different, the conversion is not allowed even
9569 -- though the subtypes statically match.
9571 if Known_Static_RM_Size (Target)
9572 and then Known_Static_RM_Size (Opnd)
9573 and then RM_Size (Target) /= RM_Size (Opnd)
9576 ("target designated subtype not compatible with }",
9579 ("\because sizes of the two designated subtypes differ",
9583 -- Normal case where conversion is allowed
9591 ("target designated subtype not compatible with }",
9598 -- Access to subprogram types. If the operand is an access parameter,
9599 -- the type has a deeper accessibility that any master, and cannot
9600 -- be assigned. We must make an exception if the conversion is part
9601 -- of an assignment and the target is the return object of an extended
9602 -- return statement, because in that case the accessibility check
9603 -- takes place after the return.
9605 elsif Is_Access_Subprogram_Type (Target_Type)
9606 and then No (Corresponding_Remote_Type (Opnd_Type))
9608 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
9609 and then Is_Entity_Name (Operand)
9610 and then Ekind (Entity (Operand)) = E_In_Parameter
9612 (Nkind (Parent (N)) /= N_Assignment_Statement
9613 or else not Is_Entity_Name (Name (Parent (N)))
9614 or else not Is_Return_Object (Entity (Name (Parent (N)))))
9617 ("illegal attempt to store anonymous access to subprogram",
9620 ("\value has deeper accessibility than any master " &
9625 ("\use named access type for& instead of access parameter",
9626 Operand, Entity (Operand));
9629 -- Check that the designated types are subtype conformant
9631 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
9632 Old_Id => Designated_Type (Opnd_Type),
9635 -- Check the static accessibility rule of 4.6(20)
9637 if Type_Access_Level (Opnd_Type) >
9638 Type_Access_Level (Target_Type)
9641 ("operand type has deeper accessibility level than target",
9644 -- Check that if the operand type is declared in a generic body,
9645 -- then the target type must be declared within that same body
9646 -- (enforces last sentence of 4.6(20)).
9648 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
9650 O_Gen : constant Node_Id :=
9651 Enclosing_Generic_Body (Opnd_Type);
9656 T_Gen := Enclosing_Generic_Body (Target_Type);
9657 while Present (T_Gen) and then T_Gen /= O_Gen loop
9658 T_Gen := Enclosing_Generic_Body (T_Gen);
9661 if T_Gen /= O_Gen then
9663 ("target type must be declared in same generic body"
9664 & " as operand type", N);
9671 -- Remote subprogram access types
9673 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
9674 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
9676 -- It is valid to convert from one RAS type to another provided
9677 -- that their specification statically match.
9679 Check_Subtype_Conformant
9681 Designated_Type (Corresponding_Remote_Type (Target_Type)),
9683 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
9688 -- If both are tagged types, check legality of view conversions
9690 elsif Is_Tagged_Type (Target_Type)
9691 and then Is_Tagged_Type (Opnd_Type)
9693 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
9695 -- Types derived from the same root type are convertible
9697 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
9700 -- In an instance or an inlined body, there may be inconsistent
9701 -- views of the same type, or of types derived from a common root.
9703 elsif (In_Instance or In_Inlined_Body)
9705 Root_Type (Underlying_Type (Target_Type)) =
9706 Root_Type (Underlying_Type (Opnd_Type))
9710 -- Special check for common access type error case
9712 elsif Ekind (Target_Type) = E_Access_Type
9713 and then Is_Access_Type (Opnd_Type)
9715 Error_Msg_N ("target type must be general access type!", N);
9716 Error_Msg_NE ("add ALL to }!", N, Target_Type);
9721 Error_Msg_NE ("invalid conversion, not compatible with }",
9726 end Valid_Conversion;