1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 Sinfo.CN; use Sinfo.CN;
72 with Snames; use Snames;
73 with Stand; use Stand;
74 with Stringt; use Stringt;
75 with Style; use Style;
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 function Bad_Unordered_Enumeration_Reference
97 T : Entity_Id) return Boolean;
98 -- Node N contains a potentially dubious reference to type T, either an
99 -- explicit comparison, or an explicit range. This function returns True
100 -- if the type T is an enumeration type for which No pragma Order has been
101 -- given, and the reference N is not in the same extended source unit as
102 -- the declaration of T.
104 procedure Check_Discriminant_Use (N : Node_Id);
105 -- Enforce the restrictions on the use of discriminants when constraining
106 -- a component of a discriminated type (record or concurrent type).
108 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
109 -- Given a node for an operator associated with type T, check that
110 -- the operator is visible. Operators all of whose operands are
111 -- universal must be checked for visibility during resolution
112 -- because their type is not determinable based on their operands.
114 procedure Check_Fully_Declared_Prefix
117 -- Check that the type of the prefix of a dereference is not incomplete
119 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
120 -- Given a call node, N, which is known to occur immediately within the
121 -- subprogram being called, determines whether it is a detectable case of
122 -- an infinite recursion, and if so, outputs appropriate messages. Returns
123 -- True if an infinite recursion is detected, and False otherwise.
125 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
126 -- If the type of the object being initialized uses the secondary stack
127 -- directly or indirectly, create a transient scope for the call to the
128 -- init proc. This is because we do not create transient scopes for the
129 -- initialization of individual components within the init proc itself.
130 -- Could be optimized away perhaps?
132 procedure Check_No_Direct_Boolean_Operators (N : Node_Id);
133 -- N is the node for a logical operator. If the operator is predefined, and
134 -- the root type of the operands is Standard.Boolean, then a check is made
135 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
136 -- the style check for Style_Check_Boolean_And_Or.
138 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
139 -- Determine whether E is an access type declared by an access
140 -- declaration, and not an (anonymous) allocator type.
142 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
143 -- Utility to check whether the entity for an operator is a predefined
144 -- operator, in which case the expression is left as an operator in the
145 -- tree (else it is rewritten into a call). An instance of an intrinsic
146 -- conversion operation may be given an operator name, but is not treated
147 -- like an operator. Note that an operator that is an imported back-end
148 -- builtin has convention Intrinsic, but is expected to be rewritten into
149 -- a call, so such an operator is not treated as predefined by this
152 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
153 -- If a default expression in entry call N depends on the discriminants
154 -- of the task, it must be replaced with a reference to the discriminant
155 -- of the task being called.
157 procedure Resolve_Op_Concat_Arg
162 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
163 -- concatenation operator. The operand is either of the array type or of
164 -- the component type. If the operand is an aggregate, and the component
165 -- type is composite, this is ambiguous if component type has aggregates.
167 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
168 -- Does the first part of the work of Resolve_Op_Concat
170 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
171 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
172 -- has been resolved. See Resolve_Op_Concat for details.
174 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
175 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
176 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
177 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id);
178 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
179 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
180 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id);
185 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
186 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
187 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
188 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
189 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
190 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
191 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
192 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
193 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
194 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
195 procedure Resolve_Quantified_Expression (N : Node_Id; Typ : Entity_Id);
196 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
197 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
198 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
199 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
200 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
201 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
202 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
203 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
204 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
205 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
206 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
207 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
208 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
210 function Operator_Kind
212 Is_Binary : Boolean) return Node_Kind;
213 -- Utility to map the name of an operator into the corresponding Node. Used
214 -- by other node rewriting procedures.
216 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
217 -- Resolve actuals of call, and add default expressions for missing ones.
218 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
219 -- called subprogram.
221 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
222 -- Called from Resolve_Call, when the prefix denotes an entry or element
223 -- of entry family. Actuals are resolved as for subprograms, and the node
224 -- is rebuilt as an entry call. Also called for protected operations. Typ
225 -- is the context type, which is used when the operation is a protected
226 -- function with no arguments, and the return value is indexed.
228 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
229 -- A call to a user-defined intrinsic operator is rewritten as a call
230 -- to the corresponding predefined operator, with suitable conversions.
231 -- Note that this applies only for intrinsic operators that denote
232 -- predefined operators, not operators that are intrinsic imports of
233 -- back-end builtins.
235 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
236 -- Ditto, for unary operators (arithmetic ones and "not" on signed
237 -- integer types for VMS).
239 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
240 -- If an operator node resolves to a call to a user-defined operator,
241 -- rewrite the node as a function call.
243 procedure Make_Call_Into_Operator
247 -- Inverse transformation: if an operator is given in functional notation,
248 -- then after resolving the node, transform into an operator node, so
249 -- that operands are resolved properly. Recall that predefined operators
250 -- do not have a full signature and special resolution rules apply.
252 procedure Rewrite_Renamed_Operator
256 -- An operator can rename another, e.g. in an instantiation. In that
257 -- case, the proper operator node must be constructed and resolved.
259 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
260 -- The String_Literal_Subtype is built for all strings that are not
261 -- operands of a static concatenation operation. If the argument is
262 -- not a N_String_Literal node, then the call has no effect.
264 procedure Set_Slice_Subtype (N : Node_Id);
265 -- Build subtype of array type, with the range specified by the slice
267 procedure Simplify_Type_Conversion (N : Node_Id);
268 -- Called after N has been resolved and evaluated, but before range checks
269 -- have been applied. Currently simplifies a combination of floating-point
270 -- to integer conversion and Truncation attribute.
272 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
273 -- A universal_fixed expression in an universal context is unambiguous
274 -- if there is only one applicable fixed point type. Determining whether
275 -- there is only one requires a search over all visible entities, and
276 -- happens only in very pathological cases (see 6115-006).
278 function Valid_Conversion
281 Operand : Node_Id) return Boolean;
282 -- Verify legality rules given in 4.6 (8-23). Target is the target
283 -- type of the conversion, which may be an implicit conversion of
284 -- an actual parameter to an anonymous access type (in which case
285 -- N denotes the actual parameter and N = Operand).
287 -------------------------
288 -- Ambiguous_Character --
289 -------------------------
291 procedure Ambiguous_Character (C : Node_Id) is
295 if Nkind (C) = N_Character_Literal then
296 Error_Msg_N ("ambiguous character literal", C);
298 -- First the ones in Standard
300 Error_Msg_N ("\\possible interpretation: Character!", C);
301 Error_Msg_N ("\\possible interpretation: Wide_Character!", C);
303 -- Include Wide_Wide_Character in Ada 2005 mode
305 if Ada_Version >= Ada_2005 then
306 Error_Msg_N ("\\possible interpretation: Wide_Wide_Character!", C);
309 -- Now any other types that match
311 E := Current_Entity (C);
312 while Present (E) loop
313 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
317 end Ambiguous_Character;
319 -------------------------
320 -- Analyze_And_Resolve --
321 -------------------------
323 procedure Analyze_And_Resolve (N : Node_Id) is
327 end Analyze_And_Resolve;
329 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
333 end Analyze_And_Resolve;
335 -- Version withs check(s) suppressed
337 procedure Analyze_And_Resolve
342 Scop : constant Entity_Id := Current_Scope;
345 if Suppress = All_Checks then
347 Svg : constant Suppress_Array := Scope_Suppress;
349 Scope_Suppress := (others => True);
350 Analyze_And_Resolve (N, Typ);
351 Scope_Suppress := Svg;
356 Svg : constant Boolean := Scope_Suppress (Suppress);
359 Scope_Suppress (Suppress) := True;
360 Analyze_And_Resolve (N, Typ);
361 Scope_Suppress (Suppress) := Svg;
365 if Current_Scope /= Scop
366 and then Scope_Is_Transient
368 -- This can only happen if a transient scope was created
369 -- for an inner expression, which will be removed upon
370 -- completion of the analysis of an enclosing construct.
371 -- The transient scope must have the suppress status of
372 -- the enclosing environment, not of this Analyze call.
374 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
377 end Analyze_And_Resolve;
379 procedure Analyze_And_Resolve
383 Scop : constant Entity_Id := Current_Scope;
386 if Suppress = All_Checks then
388 Svg : constant Suppress_Array := Scope_Suppress;
390 Scope_Suppress := (others => True);
391 Analyze_And_Resolve (N);
392 Scope_Suppress := Svg;
397 Svg : constant Boolean := Scope_Suppress (Suppress);
400 Scope_Suppress (Suppress) := True;
401 Analyze_And_Resolve (N);
402 Scope_Suppress (Suppress) := Svg;
406 if Current_Scope /= Scop
407 and then Scope_Is_Transient
409 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
412 end Analyze_And_Resolve;
414 ----------------------------------------
415 -- Bad_Unordered_Enumeration_Reference --
416 ----------------------------------------
418 function Bad_Unordered_Enumeration_Reference
420 T : Entity_Id) return Boolean
423 return Is_Enumeration_Type (T)
424 and then Comes_From_Source (N)
425 and then Warn_On_Unordered_Enumeration_Type
426 and then not Has_Pragma_Ordered (T)
427 and then not In_Same_Extended_Unit (N, T);
428 end Bad_Unordered_Enumeration_Reference;
430 ----------------------------
431 -- Check_Discriminant_Use --
432 ----------------------------
434 procedure Check_Discriminant_Use (N : Node_Id) is
435 PN : constant Node_Id := Parent (N);
436 Disc : constant Entity_Id := Entity (N);
441 -- Any use in a spec-expression is legal
443 if In_Spec_Expression then
446 elsif Nkind (PN) = N_Range then
448 -- Discriminant cannot be used to constrain a scalar type
452 if Nkind (P) = N_Range_Constraint
453 and then Nkind (Parent (P)) = N_Subtype_Indication
454 and then Nkind (Parent (Parent (P))) = N_Component_Definition
456 Error_Msg_N ("discriminant cannot constrain scalar type", N);
458 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
460 -- The following check catches the unusual case where
461 -- a discriminant appears within an index constraint
462 -- that is part of a larger expression within a constraint
463 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
464 -- For now we only check case of record components, and
465 -- note that a similar check should also apply in the
466 -- case of discriminant constraints below. ???
468 -- Note that the check for N_Subtype_Declaration below is to
469 -- detect the valid use of discriminants in the constraints of a
470 -- subtype declaration when this subtype declaration appears
471 -- inside the scope of a record type (which is syntactically
472 -- illegal, but which may be created as part of derived type
473 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
476 if Ekind (Current_Scope) = E_Record_Type
477 and then Scope (Disc) = Current_Scope
479 (Nkind (Parent (P)) = N_Subtype_Indication
481 Nkind_In (Parent (Parent (P)), N_Component_Definition,
482 N_Subtype_Declaration)
483 and then Paren_Count (N) = 0)
486 ("discriminant must appear alone in component constraint", N);
490 -- Detect a common error:
492 -- type R (D : Positive := 100) is record
493 -- Name : String (1 .. D);
496 -- The default value causes an object of type R to be allocated
497 -- with room for Positive'Last characters. The RM does not mandate
498 -- the allocation of the maximum size, but that is what GNAT does
499 -- so we should warn the programmer that there is a problem.
501 Check_Large : declare
507 function Large_Storage_Type (T : Entity_Id) return Boolean;
508 -- Return True if type T has a large enough range that
509 -- any array whose index type covered the whole range of
510 -- the type would likely raise Storage_Error.
512 ------------------------
513 -- Large_Storage_Type --
514 ------------------------
516 function Large_Storage_Type (T : Entity_Id) return Boolean is
518 -- The type is considered large if its bounds are known at
519 -- compile time and if it requires at least as many bits as
520 -- a Positive to store the possible values.
522 return Compile_Time_Known_Value (Type_Low_Bound (T))
523 and then Compile_Time_Known_Value (Type_High_Bound (T))
525 Minimum_Size (T, Biased => True) >=
526 RM_Size (Standard_Positive);
527 end Large_Storage_Type;
529 -- Start of processing for Check_Large
532 -- Check that the Disc has a large range
534 if not Large_Storage_Type (Etype (Disc)) then
538 -- If the enclosing type is limited, we allocate only the
539 -- default value, not the maximum, and there is no need for
542 if Is_Limited_Type (Scope (Disc)) then
546 -- Check that it is the high bound
548 if N /= High_Bound (PN)
549 or else No (Discriminant_Default_Value (Disc))
554 -- Check the array allows a large range at this bound.
555 -- First find the array
559 if Nkind (SI) /= N_Subtype_Indication then
563 T := Entity (Subtype_Mark (SI));
565 if not Is_Array_Type (T) then
569 -- Next, find the dimension
571 TB := First_Index (T);
572 CB := First (Constraints (P));
574 and then Present (TB)
575 and then Present (CB)
586 -- Now, check the dimension has a large range
588 if not Large_Storage_Type (Etype (TB)) then
592 -- Warn about the danger
595 ("?creation of & object may raise Storage_Error!",
604 -- Legal case is in index or discriminant constraint
606 elsif Nkind_In (PN, N_Index_Or_Discriminant_Constraint,
607 N_Discriminant_Association)
609 if Paren_Count (N) > 0 then
611 ("discriminant in constraint must appear alone", N);
613 elsif Nkind (N) = N_Expanded_Name
614 and then Comes_From_Source (N)
617 ("discriminant must appear alone as a direct name", N);
622 -- Otherwise, context is an expression. It should not be within
623 -- (i.e. a subexpression of) a constraint for a component.
628 while not Nkind_In (P, N_Component_Declaration,
629 N_Subtype_Indication,
637 -- If the discriminant is used in an expression that is a bound
638 -- of a scalar type, an Itype is created and the bounds are attached
639 -- to its range, not to the original subtype indication. Such use
640 -- is of course a double fault.
642 if (Nkind (P) = N_Subtype_Indication
643 and then Nkind_In (Parent (P), N_Component_Definition,
644 N_Derived_Type_Definition)
645 and then D = Constraint (P))
647 -- The constraint itself may be given by a subtype indication,
648 -- rather than by a more common discrete range.
650 or else (Nkind (P) = N_Subtype_Indication
652 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
653 or else Nkind (P) = N_Entry_Declaration
654 or else Nkind (D) = N_Defining_Identifier
657 ("discriminant in constraint must appear alone", N);
660 end Check_Discriminant_Use;
662 --------------------------------
663 -- Check_For_Visible_Operator --
664 --------------------------------
666 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
668 if Is_Invisible_Operator (N, T) then
669 Error_Msg_NE -- CODEFIX
670 ("operator for} is not directly visible!", N, First_Subtype (T));
671 Error_Msg_N -- CODEFIX
672 ("use clause would make operation legal!", N);
674 end Check_For_Visible_Operator;
676 ----------------------------------
677 -- Check_Fully_Declared_Prefix --
678 ----------------------------------
680 procedure Check_Fully_Declared_Prefix
685 -- Check that the designated type of the prefix of a dereference is
686 -- not an incomplete type. This cannot be done unconditionally, because
687 -- dereferences of private types are legal in default expressions. This
688 -- case is taken care of in Check_Fully_Declared, called below. There
689 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
691 -- This consideration also applies to similar checks for allocators,
692 -- qualified expressions, and type conversions.
694 -- An additional exception concerns other per-object expressions that
695 -- are not directly related to component declarations, in particular
696 -- representation pragmas for tasks. These will be per-object
697 -- expressions if they depend on discriminants or some global entity.
698 -- If the task has access discriminants, the designated type may be
699 -- incomplete at the point the expression is resolved. This resolution
700 -- takes place within the body of the initialization procedure, where
701 -- the discriminant is replaced by its discriminal.
703 if Is_Entity_Name (Pref)
704 and then Ekind (Entity (Pref)) = E_In_Parameter
708 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
709 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
710 -- Analyze_Object_Renaming, and Freeze_Entity.
712 elsif Ada_Version >= Ada_2005
713 and then Is_Entity_Name (Pref)
714 and then Is_Access_Type (Etype (Pref))
715 and then Ekind (Directly_Designated_Type (Etype (Pref))) =
717 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Pref)))
721 Check_Fully_Declared (Typ, Parent (Pref));
723 end Check_Fully_Declared_Prefix;
725 ------------------------------
726 -- Check_Infinite_Recursion --
727 ------------------------------
729 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
733 function Same_Argument_List return Boolean;
734 -- Check whether list of actuals is identical to list of formals
735 -- of called function (which is also the enclosing scope).
737 ------------------------
738 -- Same_Argument_List --
739 ------------------------
741 function Same_Argument_List return Boolean is
747 if not Is_Entity_Name (Name (N)) then
750 Subp := Entity (Name (N));
753 F := First_Formal (Subp);
754 A := First_Actual (N);
755 while Present (F) and then Present (A) loop
756 if not Is_Entity_Name (A)
757 or else Entity (A) /= F
767 end Same_Argument_List;
769 -- Start of processing for Check_Infinite_Recursion
772 -- Special case, if this is a procedure call and is a call to the
773 -- current procedure with the same argument list, then this is for
774 -- sure an infinite recursion and we insert a call to raise SE.
776 if Is_List_Member (N)
777 and then List_Length (List_Containing (N)) = 1
778 and then Same_Argument_List
781 P : constant Node_Id := Parent (N);
783 if Nkind (P) = N_Handled_Sequence_Of_Statements
784 and then Nkind (Parent (P)) = N_Subprogram_Body
785 and then Is_Empty_List (Declarations (Parent (P)))
787 Error_Msg_N ("!?infinite recursion", N);
788 Error_Msg_N ("\!?Storage_Error will be raised at run time", N);
790 Make_Raise_Storage_Error (Sloc (N),
791 Reason => SE_Infinite_Recursion));
797 -- If not that special case, search up tree, quitting if we reach a
798 -- construct (e.g. a conditional) that tells us that this is not a
799 -- case for an infinite recursion warning.
805 -- If no parent, then we were not inside a subprogram, this can for
806 -- example happen when processing certain pragmas in a spec. Just
807 -- return False in this case.
813 -- Done if we get to subprogram body, this is definitely an infinite
814 -- recursion case if we did not find anything to stop us.
816 exit when Nkind (P) = N_Subprogram_Body;
818 -- If appearing in conditional, result is false
820 if Nkind_In (P, N_Or_Else,
824 N_Conditional_Expression,
829 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
830 and then C /= First (Statements (P))
832 -- If the call is the expression of a return statement and the
833 -- actuals are identical to the formals, it's worth a warning.
834 -- However, we skip this if there is an immediately preceding
835 -- raise statement, since the call is never executed.
837 -- Furthermore, this corresponds to a common idiom:
839 -- function F (L : Thing) return Boolean is
841 -- raise Program_Error;
845 -- for generating a stub function
847 if Nkind (Parent (N)) = N_Simple_Return_Statement
848 and then Same_Argument_List
850 exit when not Is_List_Member (Parent (N));
852 -- OK, return statement is in a statement list, look for raise
858 -- Skip past N_Freeze_Entity nodes generated by expansion
860 Nod := Prev (Parent (N));
862 and then Nkind (Nod) = N_Freeze_Entity
867 -- If no raise statement, give warning
869 exit when Nkind (Nod) /= N_Raise_Statement
871 (Nkind (Nod) not in N_Raise_xxx_Error
872 or else Present (Condition (Nod)));
883 Error_Msg_N ("!?possible infinite recursion", N);
884 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
887 end Check_Infinite_Recursion;
889 -------------------------------
890 -- Check_Initialization_Call --
891 -------------------------------
893 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
894 Typ : constant Entity_Id := Etype (First_Formal (Nam));
896 function Uses_SS (T : Entity_Id) return Boolean;
897 -- Check whether the creation of an object of the type will involve
898 -- use of the secondary stack. If T is a record type, this is true
899 -- if the expression for some component uses the secondary stack, e.g.
900 -- through a call to a function that returns an unconstrained value.
901 -- False if T is controlled, because cleanups occur elsewhere.
907 function Uses_SS (T : Entity_Id) return Boolean is
910 Full_Type : Entity_Id := Underlying_Type (T);
913 -- Normally we want to use the underlying type, but if it's not set
914 -- then continue with T.
916 if not Present (Full_Type) then
920 if Is_Controlled (Full_Type) then
923 elsif Is_Array_Type (Full_Type) then
924 return Uses_SS (Component_Type (Full_Type));
926 elsif Is_Record_Type (Full_Type) then
927 Comp := First_Component (Full_Type);
928 while Present (Comp) loop
929 if Ekind (Comp) = E_Component
930 and then Nkind (Parent (Comp)) = N_Component_Declaration
932 -- The expression for a dynamic component may be rewritten
933 -- as a dereference, so retrieve original node.
935 Expr := Original_Node (Expression (Parent (Comp)));
937 -- Return True if the expression is a call to a function
938 -- (including an attribute function such as Image, or a
939 -- user-defined operator) with a result that requires a
942 if (Nkind (Expr) = N_Function_Call
943 or else Nkind (Expr) in N_Op
944 or else (Nkind (Expr) = N_Attribute_Reference
945 and then Present (Expressions (Expr))))
946 and then Requires_Transient_Scope (Etype (Expr))
950 elsif Uses_SS (Etype (Comp)) then
955 Next_Component (Comp);
965 -- Start of processing for Check_Initialization_Call
968 -- Establish a transient scope if the type needs it
970 if Uses_SS (Typ) then
971 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
973 end Check_Initialization_Call;
975 ---------------------------------------
976 -- Check_No_Direct_Boolean_Operators --
977 ---------------------------------------
979 procedure Check_No_Direct_Boolean_Operators (N : Node_Id) is
981 if Scope (Entity (N)) = Standard_Standard
982 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
984 -- Restriction only applies to original source code
986 if Comes_From_Source (N) then
987 Check_Restriction (No_Direct_Boolean_Operators, N);
992 Check_Boolean_Operator (N);
994 end Check_No_Direct_Boolean_Operators;
996 ------------------------------
997 -- Check_Parameterless_Call --
998 ------------------------------
1000 procedure Check_Parameterless_Call (N : Node_Id) is
1003 function Prefix_Is_Access_Subp return Boolean;
1004 -- If the prefix is of an access_to_subprogram type, the node must be
1005 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1006 -- interpretations are access to subprograms.
1008 ---------------------------
1009 -- Prefix_Is_Access_Subp --
1010 ---------------------------
1012 function Prefix_Is_Access_Subp return Boolean is
1017 -- If the context is an attribute reference that can apply to
1018 -- functions, this is never a parameterless call (RM 4.1.4(6)).
1020 if Nkind (Parent (N)) = N_Attribute_Reference
1021 and then (Attribute_Name (Parent (N)) = Name_Address
1022 or else Attribute_Name (Parent (N)) = Name_Code_Address
1023 or else Attribute_Name (Parent (N)) = Name_Access)
1028 if not Is_Overloaded (N) then
1030 Ekind (Etype (N)) = E_Subprogram_Type
1031 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
1033 Get_First_Interp (N, I, It);
1034 while Present (It.Typ) loop
1035 if Ekind (It.Typ) /= E_Subprogram_Type
1036 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
1041 Get_Next_Interp (I, It);
1046 end Prefix_Is_Access_Subp;
1048 -- Start of processing for Check_Parameterless_Call
1051 -- Defend against junk stuff if errors already detected
1053 if Total_Errors_Detected /= 0 then
1054 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
1056 elsif Nkind (N) in N_Has_Chars
1057 and then Chars (N) in Error_Name_Or_No_Name
1065 -- If the context expects a value, and the name is a procedure, this is
1066 -- most likely a missing 'Access. Don't try to resolve the parameterless
1067 -- call, error will be caught when the outer call is analyzed.
1069 if Is_Entity_Name (N)
1070 and then Ekind (Entity (N)) = E_Procedure
1071 and then not Is_Overloaded (N)
1073 Nkind_In (Parent (N), N_Parameter_Association,
1075 N_Procedure_Call_Statement)
1080 -- Rewrite as call if overloadable entity that is (or could be, in the
1081 -- overloaded case) a function call. If we know for sure that the entity
1082 -- is an enumeration literal, we do not rewrite it.
1084 -- If the entity is the name of an operator, it cannot be a call because
1085 -- operators cannot have default parameters. In this case, this must be
1086 -- a string whose contents coincide with an operator name. Set the kind
1087 -- of the node appropriately.
1089 if (Is_Entity_Name (N)
1090 and then Nkind (N) /= N_Operator_Symbol
1091 and then Is_Overloadable (Entity (N))
1092 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1093 or else Is_Overloaded (N)))
1095 -- Rewrite as call if it is an explicit dereference of an expression of
1096 -- a subprogram access type, and the subprogram type is not that of a
1097 -- procedure or entry.
1100 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1102 -- Rewrite as call if it is a selected component which is a function,
1103 -- this is the case of a call to a protected function (which may be
1104 -- overloaded with other protected operations).
1107 (Nkind (N) = N_Selected_Component
1108 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1110 (Ekind_In (Entity (Selector_Name (N)), E_Entry,
1112 and then Is_Overloaded (Selector_Name (N)))))
1114 -- If one of the above three conditions is met, rewrite as call.
1115 -- Apply the rewriting only once.
1118 if Nkind (Parent (N)) /= N_Function_Call
1119 or else N /= Name (Parent (N))
1121 Nam := New_Copy (N);
1123 -- If overloaded, overload set belongs to new copy
1125 Save_Interps (N, Nam);
1127 -- Change node to parameterless function call (note that the
1128 -- Parameter_Associations associations field is left set to Empty,
1129 -- its normal default value since there are no parameters)
1131 Change_Node (N, N_Function_Call);
1133 Set_Sloc (N, Sloc (Nam));
1137 elsif Nkind (N) = N_Parameter_Association then
1138 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1140 elsif Nkind (N) = N_Operator_Symbol then
1141 Change_Operator_Symbol_To_String_Literal (N);
1142 Set_Is_Overloaded (N, False);
1143 Set_Etype (N, Any_String);
1145 end Check_Parameterless_Call;
1147 -----------------------------
1148 -- Is_Definite_Access_Type --
1149 -----------------------------
1151 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1152 Btyp : constant Entity_Id := Base_Type (E);
1154 return Ekind (Btyp) = E_Access_Type
1155 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1156 and then Comes_From_Source (Btyp));
1157 end Is_Definite_Access_Type;
1159 ----------------------
1160 -- Is_Predefined_Op --
1161 ----------------------
1163 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1165 -- Predefined operators are intrinsic subprograms
1167 if not Is_Intrinsic_Subprogram (Nam) then
1171 -- A call to a back-end builtin is never a predefined operator
1173 if Is_Imported (Nam) and then Present (Interface_Name (Nam)) then
1177 return not Is_Generic_Instance (Nam)
1178 and then Chars (Nam) in Any_Operator_Name
1179 and then (No (Alias (Nam)) or else Is_Predefined_Op (Alias (Nam)));
1180 end Is_Predefined_Op;
1182 -----------------------------
1183 -- Make_Call_Into_Operator --
1184 -----------------------------
1186 procedure Make_Call_Into_Operator
1191 Op_Name : constant Name_Id := Chars (Op_Id);
1192 Act1 : Node_Id := First_Actual (N);
1193 Act2 : Node_Id := Next_Actual (Act1);
1194 Error : Boolean := False;
1195 Func : constant Entity_Id := Entity (Name (N));
1196 Is_Binary : constant Boolean := Present (Act2);
1198 Opnd_Type : Entity_Id;
1199 Orig_Type : Entity_Id := Empty;
1202 type Kind_Test is access function (E : Entity_Id) return Boolean;
1204 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1205 -- If the operand is not universal, and the operator is given by an
1206 -- expanded name, verify that the operand has an interpretation with a
1207 -- type defined in the given scope of the operator.
1209 function Type_In_P (Test : Kind_Test) return Entity_Id;
1210 -- Find a type of the given class in package Pack that contains the
1213 ---------------------------
1214 -- Operand_Type_In_Scope --
1215 ---------------------------
1217 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1218 Nod : constant Node_Id := Right_Opnd (Op_Node);
1223 if not Is_Overloaded (Nod) then
1224 return Scope (Base_Type (Etype (Nod))) = S;
1227 Get_First_Interp (Nod, I, It);
1228 while Present (It.Typ) loop
1229 if Scope (Base_Type (It.Typ)) = S then
1233 Get_Next_Interp (I, It);
1238 end Operand_Type_In_Scope;
1244 function Type_In_P (Test : Kind_Test) return Entity_Id is
1247 function In_Decl return Boolean;
1248 -- Verify that node is not part of the type declaration for the
1249 -- candidate type, which would otherwise be invisible.
1255 function In_Decl return Boolean is
1256 Decl_Node : constant Node_Id := Parent (E);
1262 if Etype (E) = Any_Type then
1265 elsif No (Decl_Node) then
1270 and then Nkind (N2) /= N_Compilation_Unit
1272 if N2 = Decl_Node then
1283 -- Start of processing for Type_In_P
1286 -- If the context type is declared in the prefix package, this is the
1287 -- desired base type.
1289 if Scope (Base_Type (Typ)) = Pack and then Test (Typ) then
1290 return Base_Type (Typ);
1293 E := First_Entity (Pack);
1294 while Present (E) loop
1296 and then not In_Decl
1308 -- Start of processing for Make_Call_Into_Operator
1311 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1316 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1317 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1318 Save_Interps (Act1, Left_Opnd (Op_Node));
1319 Save_Interps (Act2, Right_Opnd (Op_Node));
1320 Act1 := Left_Opnd (Op_Node);
1321 Act2 := Right_Opnd (Op_Node);
1326 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1327 Save_Interps (Act1, Right_Opnd (Op_Node));
1328 Act1 := Right_Opnd (Op_Node);
1331 -- If the operator is denoted by an expanded name, and the prefix is
1332 -- not Standard, but the operator is a predefined one whose scope is
1333 -- Standard, then this is an implicit_operator, inserted as an
1334 -- interpretation by the procedure of the same name. This procedure
1335 -- overestimates the presence of implicit operators, because it does
1336 -- not examine the type of the operands. Verify now that the operand
1337 -- type appears in the given scope. If right operand is universal,
1338 -- check the other operand. In the case of concatenation, either
1339 -- argument can be the component type, so check the type of the result.
1340 -- If both arguments are literals, look for a type of the right kind
1341 -- defined in the given scope. This elaborate nonsense is brought to
1342 -- you courtesy of b33302a. The type itself must be frozen, so we must
1343 -- find the type of the proper class in the given scope.
1345 -- A final wrinkle is the multiplication operator for fixed point types,
1346 -- which is defined in Standard only, and not in the scope of the
1347 -- fixed point type itself.
1349 if Nkind (Name (N)) = N_Expanded_Name then
1350 Pack := Entity (Prefix (Name (N)));
1352 -- If the entity being called is defined in the given package, it is
1353 -- a renaming of a predefined operator, and known to be legal.
1355 if Scope (Entity (Name (N))) = Pack
1356 and then Pack /= Standard_Standard
1360 -- Visibility does not need to be checked in an instance: if the
1361 -- operator was not visible in the generic it has been diagnosed
1362 -- already, else there is an implicit copy of it in the instance.
1364 elsif In_Instance then
1367 elsif (Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide)
1368 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1369 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1371 if Pack /= Standard_Standard then
1375 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1378 elsif Ada_Version >= Ada_2005
1379 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1380 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1385 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1387 if Op_Name = Name_Op_Concat then
1388 Opnd_Type := Base_Type (Typ);
1390 elsif (Scope (Opnd_Type) = Standard_Standard
1392 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1394 and then not Comes_From_Source (Opnd_Type))
1396 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1399 if Scope (Opnd_Type) = Standard_Standard then
1401 -- Verify that the scope contains a type that corresponds to
1402 -- the given literal. Optimize the case where Pack is Standard.
1404 if Pack /= Standard_Standard then
1406 if Opnd_Type = Universal_Integer then
1407 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1409 elsif Opnd_Type = Universal_Real then
1410 Orig_Type := Type_In_P (Is_Real_Type'Access);
1412 elsif Opnd_Type = Any_String then
1413 Orig_Type := Type_In_P (Is_String_Type'Access);
1415 elsif Opnd_Type = Any_Access then
1416 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1418 elsif Opnd_Type = Any_Composite then
1419 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1421 if Present (Orig_Type) then
1422 if Has_Private_Component (Orig_Type) then
1425 Set_Etype (Act1, Orig_Type);
1428 Set_Etype (Act2, Orig_Type);
1437 Error := No (Orig_Type);
1440 elsif Ekind (Opnd_Type) = E_Allocator_Type
1441 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1445 -- If the type is defined elsewhere, and the operator is not
1446 -- defined in the given scope (by a renaming declaration, e.g.)
1447 -- then this is an error as well. If an extension of System is
1448 -- present, and the type may be defined there, Pack must be
1451 elsif Scope (Opnd_Type) /= Pack
1452 and then Scope (Op_Id) /= Pack
1453 and then (No (System_Aux_Id)
1454 or else Scope (Opnd_Type) /= System_Aux_Id
1455 or else Pack /= Scope (System_Aux_Id))
1457 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1460 Error := not Operand_Type_In_Scope (Pack);
1463 elsif Pack = Standard_Standard
1464 and then not Operand_Type_In_Scope (Standard_Standard)
1471 Error_Msg_Node_2 := Pack;
1473 ("& not declared in&", N, Selector_Name (Name (N)));
1474 Set_Etype (N, Any_Type);
1477 -- Detect a mismatch between the context type and the result type
1478 -- in the named package, which is otherwise not detected if the
1479 -- operands are universal. Check is only needed if source entity is
1480 -- an operator, not a function that renames an operator.
1482 elsif Nkind (Parent (N)) /= N_Type_Conversion
1483 and then Ekind (Entity (Name (N))) = E_Operator
1484 and then Is_Numeric_Type (Typ)
1485 and then not Is_Universal_Numeric_Type (Typ)
1486 and then Scope (Base_Type (Typ)) /= Pack
1487 and then not In_Instance
1489 if Is_Fixed_Point_Type (Typ)
1490 and then (Op_Name = Name_Op_Multiply
1492 Op_Name = Name_Op_Divide)
1494 -- Already checked above
1498 -- Operator may be defined in an extension of System
1500 elsif Present (System_Aux_Id)
1501 and then Scope (Opnd_Type) = System_Aux_Id
1506 -- Could we use Wrong_Type here??? (this would require setting
1507 -- Etype (N) to the actual type found where Typ was expected).
1509 Error_Msg_NE ("expect }", N, Typ);
1514 Set_Chars (Op_Node, Op_Name);
1516 if not Is_Private_Type (Etype (N)) then
1517 Set_Etype (Op_Node, Base_Type (Etype (N)));
1519 Set_Etype (Op_Node, Etype (N));
1522 -- If this is a call to a function that renames a predefined equality,
1523 -- the renaming declaration provides a type that must be used to
1524 -- resolve the operands. This must be done now because resolution of
1525 -- the equality node will not resolve any remaining ambiguity, and it
1526 -- assumes that the first operand is not overloaded.
1528 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1529 and then Ekind (Func) = E_Function
1530 and then Is_Overloaded (Act1)
1532 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1533 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1536 Set_Entity (Op_Node, Op_Id);
1537 Generate_Reference (Op_Id, N, ' ');
1539 -- Do rewrite setting Comes_From_Source on the result if the original
1540 -- call came from source. Although it is not strictly the case that the
1541 -- operator as such comes from the source, logically it corresponds
1542 -- exactly to the function call in the source, so it should be marked
1543 -- this way (e.g. to make sure that validity checks work fine).
1546 CS : constant Boolean := Comes_From_Source (N);
1548 Rewrite (N, Op_Node);
1549 Set_Comes_From_Source (N, CS);
1552 -- If this is an arithmetic operator and the result type is private,
1553 -- the operands and the result must be wrapped in conversion to
1554 -- expose the underlying numeric type and expand the proper checks,
1555 -- e.g. on division.
1557 if Is_Private_Type (Typ) then
1559 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1560 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1561 Resolve_Intrinsic_Operator (N, Typ);
1563 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1564 Resolve_Intrinsic_Unary_Operator (N, Typ);
1572 end Make_Call_Into_Operator;
1578 function Operator_Kind
1580 Is_Binary : Boolean) return Node_Kind
1586 if Op_Name = Name_Op_And then
1588 elsif Op_Name = Name_Op_Or then
1590 elsif Op_Name = Name_Op_Xor then
1592 elsif Op_Name = Name_Op_Eq then
1594 elsif Op_Name = Name_Op_Ne then
1596 elsif Op_Name = Name_Op_Lt then
1598 elsif Op_Name = Name_Op_Le then
1600 elsif Op_Name = Name_Op_Gt then
1602 elsif Op_Name = Name_Op_Ge then
1604 elsif Op_Name = Name_Op_Add then
1606 elsif Op_Name = Name_Op_Subtract then
1607 Kind := N_Op_Subtract;
1608 elsif Op_Name = Name_Op_Concat then
1609 Kind := N_Op_Concat;
1610 elsif Op_Name = Name_Op_Multiply then
1611 Kind := N_Op_Multiply;
1612 elsif Op_Name = Name_Op_Divide then
1613 Kind := N_Op_Divide;
1614 elsif Op_Name = Name_Op_Mod then
1616 elsif Op_Name = Name_Op_Rem then
1618 elsif Op_Name = Name_Op_Expon then
1621 raise Program_Error;
1627 if Op_Name = Name_Op_Add then
1629 elsif Op_Name = Name_Op_Subtract then
1631 elsif Op_Name = Name_Op_Abs then
1633 elsif Op_Name = Name_Op_Not then
1636 raise Program_Error;
1643 ----------------------------
1644 -- Preanalyze_And_Resolve --
1645 ----------------------------
1647 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1648 Save_Full_Analysis : constant Boolean := Full_Analysis;
1651 Full_Analysis := False;
1652 Expander_Mode_Save_And_Set (False);
1654 -- We suppress all checks for this analysis, since the checks will
1655 -- be applied properly, and in the right location, when the default
1656 -- expression is reanalyzed and reexpanded later on.
1658 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1660 Expander_Mode_Restore;
1661 Full_Analysis := Save_Full_Analysis;
1662 end Preanalyze_And_Resolve;
1664 -- Version without context type
1666 procedure Preanalyze_And_Resolve (N : Node_Id) is
1667 Save_Full_Analysis : constant Boolean := Full_Analysis;
1670 Full_Analysis := False;
1671 Expander_Mode_Save_And_Set (False);
1674 Resolve (N, Etype (N), Suppress => All_Checks);
1676 Expander_Mode_Restore;
1677 Full_Analysis := Save_Full_Analysis;
1678 end Preanalyze_And_Resolve;
1680 ----------------------------------
1681 -- Replace_Actual_Discriminants --
1682 ----------------------------------
1684 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1685 Loc : constant Source_Ptr := Sloc (N);
1686 Tsk : Node_Id := Empty;
1688 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1694 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1698 if Nkind (Nod) = N_Identifier then
1699 Ent := Entity (Nod);
1702 and then Ekind (Ent) = E_Discriminant
1705 Make_Selected_Component (Loc,
1706 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1707 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1709 Set_Etype (Nod, Etype (Ent));
1717 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1719 -- Start of processing for Replace_Actual_Discriminants
1722 if not Expander_Active then
1726 if Nkind (Name (N)) = N_Selected_Component then
1727 Tsk := Prefix (Name (N));
1729 elsif Nkind (Name (N)) = N_Indexed_Component then
1730 Tsk := Prefix (Prefix (Name (N)));
1736 Replace_Discrs (Default);
1738 end Replace_Actual_Discriminants;
1744 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1745 Ambiguous : Boolean := False;
1746 Ctx_Type : Entity_Id := Typ;
1747 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1748 Err_Type : Entity_Id := Empty;
1749 Found : Boolean := False;
1752 I1 : Interp_Index := 0; -- prevent junk warning
1755 Seen : Entity_Id := Empty; -- prevent junk warning
1757 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1758 -- Determine whether a node comes from a predefined library unit or
1761 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1762 -- Try and fix up a literal so that it matches its expected type. New
1763 -- literals are manufactured if necessary to avoid cascaded errors.
1765 procedure Report_Ambiguous_Argument;
1766 -- Additional diagnostics when an ambiguous call has an ambiguous
1767 -- argument (typically a controlling actual).
1769 procedure Resolution_Failed;
1770 -- Called when attempt at resolving current expression fails
1772 ------------------------------------
1773 -- Comes_From_Predefined_Lib_Unit --
1774 -------------------------------------
1776 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1779 Sloc (Nod) = Standard_Location
1780 or else Is_Predefined_File_Name (Unit_File_Name (
1781 Get_Source_Unit (Sloc (Nod))));
1782 end Comes_From_Predefined_Lib_Unit;
1784 --------------------
1785 -- Patch_Up_Value --
1786 --------------------
1788 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1790 if Nkind (N) = N_Integer_Literal
1791 and then Is_Real_Type (Typ)
1794 Make_Real_Literal (Sloc (N),
1795 Realval => UR_From_Uint (Intval (N))));
1796 Set_Etype (N, Universal_Real);
1797 Set_Is_Static_Expression (N);
1799 elsif Nkind (N) = N_Real_Literal
1800 and then Is_Integer_Type (Typ)
1803 Make_Integer_Literal (Sloc (N),
1804 Intval => UR_To_Uint (Realval (N))));
1805 Set_Etype (N, Universal_Integer);
1806 Set_Is_Static_Expression (N);
1808 elsif Nkind (N) = N_String_Literal
1809 and then Is_Character_Type (Typ)
1811 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1813 Make_Character_Literal (Sloc (N),
1815 Char_Literal_Value =>
1816 UI_From_Int (Character'Pos ('A'))));
1817 Set_Etype (N, Any_Character);
1818 Set_Is_Static_Expression (N);
1820 elsif Nkind (N) /= N_String_Literal
1821 and then Is_String_Type (Typ)
1824 Make_String_Literal (Sloc (N),
1825 Strval => End_String));
1827 elsif Nkind (N) = N_Range then
1828 Patch_Up_Value (Low_Bound (N), Typ);
1829 Patch_Up_Value (High_Bound (N), Typ);
1833 -------------------------------
1834 -- Report_Ambiguous_Argument --
1835 -------------------------------
1837 procedure Report_Ambiguous_Argument is
1838 Arg : constant Node_Id := First (Parameter_Associations (N));
1843 if Nkind (Arg) = N_Function_Call
1844 and then Is_Entity_Name (Name (Arg))
1845 and then Is_Overloaded (Name (Arg))
1847 Error_Msg_NE ("ambiguous call to&", Arg, Name (Arg));
1849 -- Could use comments on what is going on here ???
1851 Get_First_Interp (Name (Arg), I, It);
1852 while Present (It.Nam) loop
1853 Error_Msg_Sloc := Sloc (It.Nam);
1855 if Nkind (Parent (It.Nam)) = N_Full_Type_Declaration then
1856 Error_Msg_N ("interpretation (inherited) #!", Arg);
1858 Error_Msg_N ("interpretation #!", Arg);
1861 Get_Next_Interp (I, It);
1864 end Report_Ambiguous_Argument;
1866 -----------------------
1867 -- Resolution_Failed --
1868 -----------------------
1870 procedure Resolution_Failed is
1872 Patch_Up_Value (N, Typ);
1874 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1875 Set_Is_Overloaded (N, False);
1877 -- The caller will return without calling the expander, so we need
1878 -- to set the analyzed flag. Note that it is fine to set Analyzed
1879 -- to True even if we are in the middle of a shallow analysis,
1880 -- (see the spec of sem for more details) since this is an error
1881 -- situation anyway, and there is no point in repeating the
1882 -- analysis later (indeed it won't work to repeat it later, since
1883 -- we haven't got a clear resolution of which entity is being
1886 Set_Analyzed (N, True);
1888 end Resolution_Failed;
1890 -- Start of processing for Resolve
1897 -- Access attribute on remote subprogram cannot be used for
1898 -- a non-remote access-to-subprogram type.
1900 if Nkind (N) = N_Attribute_Reference
1901 and then (Attribute_Name (N) = Name_Access
1902 or else Attribute_Name (N) = Name_Unrestricted_Access
1903 or else Attribute_Name (N) = Name_Unchecked_Access)
1904 and then Comes_From_Source (N)
1905 and then Is_Entity_Name (Prefix (N))
1906 and then Is_Subprogram (Entity (Prefix (N)))
1907 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1908 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1911 ("prefix must statically denote a non-remote subprogram", N);
1914 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1916 -- If the context is a Remote_Access_To_Subprogram, access attributes
1917 -- must be resolved with the corresponding fat pointer. There is no need
1918 -- to check for the attribute name since the return type of an
1919 -- attribute is never a remote type.
1921 if Nkind (N) = N_Attribute_Reference
1922 and then Comes_From_Source (N)
1923 and then (Is_Remote_Call_Interface (Typ)
1924 or else Is_Remote_Types (Typ))
1927 Attr : constant Attribute_Id :=
1928 Get_Attribute_Id (Attribute_Name (N));
1929 Pref : constant Node_Id := Prefix (N);
1932 Is_Remote : Boolean := True;
1935 -- Check that Typ is a remote access-to-subprogram type
1937 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1939 -- Prefix (N) must statically denote a remote subprogram
1940 -- declared in a package specification.
1942 if Attr = Attribute_Access then
1943 Decl := Unit_Declaration_Node (Entity (Pref));
1945 if Nkind (Decl) = N_Subprogram_Body then
1946 Spec := Corresponding_Spec (Decl);
1948 if not No (Spec) then
1949 Decl := Unit_Declaration_Node (Spec);
1953 Spec := Parent (Decl);
1955 if not Is_Entity_Name (Prefix (N))
1956 or else Nkind (Spec) /= N_Package_Specification
1958 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1962 ("prefix must statically denote a remote subprogram ",
1967 -- If we are generating code for a distributed program.
1968 -- perform semantic checks against the corresponding
1971 if (Attr = Attribute_Access
1972 or else Attr = Attribute_Unchecked_Access
1973 or else Attr = Attribute_Unrestricted_Access)
1974 and then Expander_Active
1975 and then Get_PCS_Name /= Name_No_DSA
1977 Check_Subtype_Conformant
1978 (New_Id => Entity (Prefix (N)),
1979 Old_Id => Designated_Type
1980 (Corresponding_Remote_Type (Typ)),
1984 Process_Remote_AST_Attribute (N, Typ);
1991 Debug_A_Entry ("resolving ", N);
1993 if Comes_From_Source (N) then
1994 if Is_Fixed_Point_Type (Typ) then
1995 Check_Restriction (No_Fixed_Point, N);
1997 elsif Is_Floating_Point_Type (Typ)
1998 and then Typ /= Universal_Real
1999 and then Typ /= Any_Real
2001 Check_Restriction (No_Floating_Point, N);
2005 -- Return if already analyzed
2007 if Analyzed (N) then
2008 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
2011 -- Return if type = Any_Type (previous error encountered)
2013 elsif Etype (N) = Any_Type then
2014 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
2018 Check_Parameterless_Call (N);
2020 -- If not overloaded, then we know the type, and all that needs doing
2021 -- is to check that this type is compatible with the context.
2023 if not Is_Overloaded (N) then
2024 Found := Covers (Typ, Etype (N));
2025 Expr_Type := Etype (N);
2027 -- In the overloaded case, we must select the interpretation that
2028 -- is compatible with the context (i.e. the type passed to Resolve)
2031 -- Loop through possible interpretations
2033 Get_First_Interp (N, I, It);
2034 Interp_Loop : while Present (It.Typ) loop
2036 -- We are only interested in interpretations that are compatible
2037 -- with the expected type, any other interpretations are ignored.
2039 if not Covers (Typ, It.Typ) then
2040 if Debug_Flag_V then
2041 Write_Str (" interpretation incompatible with context");
2046 -- Skip the current interpretation if it is disabled by an
2047 -- abstract operator. This action is performed only when the
2048 -- type against which we are resolving is the same as the
2049 -- type of the interpretation.
2051 if Ada_Version >= Ada_2005
2052 and then It.Typ = Typ
2053 and then Typ /= Universal_Integer
2054 and then Typ /= Universal_Real
2055 and then Present (It.Abstract_Op)
2060 -- First matching interpretation
2066 Expr_Type := It.Typ;
2068 -- Matching interpretation that is not the first, maybe an
2069 -- error, but there are some cases where preference rules are
2070 -- used to choose between the two possibilities. These and
2071 -- some more obscure cases are handled in Disambiguate.
2074 -- If the current statement is part of a predefined library
2075 -- unit, then all interpretations which come from user level
2076 -- packages should not be considered.
2079 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
2084 Error_Msg_Sloc := Sloc (Seen);
2085 It1 := Disambiguate (N, I1, I, Typ);
2087 -- Disambiguation has succeeded. Skip the remaining
2090 if It1 /= No_Interp then
2092 Expr_Type := It1.Typ;
2094 while Present (It.Typ) loop
2095 Get_Next_Interp (I, It);
2099 -- Before we issue an ambiguity complaint, check for
2100 -- the case of a subprogram call where at least one
2101 -- of the arguments is Any_Type, and if so, suppress
2102 -- the message, since it is a cascaded error.
2104 if Nkind_In (N, N_Function_Call,
2105 N_Procedure_Call_Statement)
2112 A := First_Actual (N);
2113 while Present (A) loop
2116 if Nkind (E) = N_Parameter_Association then
2117 E := Explicit_Actual_Parameter (E);
2120 if Etype (E) = Any_Type then
2121 if Debug_Flag_V then
2122 Write_Str ("Any_Type in call");
2133 elsif Nkind (N) in N_Binary_Op
2134 and then (Etype (Left_Opnd (N)) = Any_Type
2135 or else Etype (Right_Opnd (N)) = Any_Type)
2139 elsif Nkind (N) in N_Unary_Op
2140 and then Etype (Right_Opnd (N)) = Any_Type
2145 -- Not that special case, so issue message using the
2146 -- flag Ambiguous to control printing of the header
2147 -- message only at the start of an ambiguous set.
2149 if not Ambiguous then
2150 if Nkind (N) = N_Function_Call
2151 and then Nkind (Name (N)) = N_Explicit_Dereference
2154 ("ambiguous expression "
2155 & "(cannot resolve indirect call)!", N);
2157 Error_Msg_NE -- CODEFIX
2158 ("ambiguous expression (cannot resolve&)!",
2164 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2166 ("\\possible interpretation (inherited)#!", N);
2168 Error_Msg_N -- CODEFIX
2169 ("\\possible interpretation#!", N);
2173 (N, N_Procedure_Call_Statement, N_Function_Call)
2174 and then Present (Parameter_Associations (N))
2176 Report_Ambiguous_Argument;
2180 Error_Msg_Sloc := Sloc (It.Nam);
2182 -- By default, the error message refers to the candidate
2183 -- interpretation. But if it is a predefined operator, it
2184 -- is implicitly declared at the declaration of the type
2185 -- of the operand. Recover the sloc of that declaration
2186 -- for the error message.
2188 if Nkind (N) in N_Op
2189 and then Scope (It.Nam) = Standard_Standard
2190 and then not Is_Overloaded (Right_Opnd (N))
2191 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2194 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2196 if Comes_From_Source (Err_Type)
2197 and then Present (Parent (Err_Type))
2199 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2202 elsif Nkind (N) in N_Binary_Op
2203 and then Scope (It.Nam) = Standard_Standard
2204 and then not Is_Overloaded (Left_Opnd (N))
2205 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2208 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2210 if Comes_From_Source (Err_Type)
2211 and then Present (Parent (Err_Type))
2213 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2216 -- If this is an indirect call, use the subprogram_type
2217 -- in the message, to have a meaningful location.
2218 -- Also indicate if this is an inherited operation,
2219 -- created by a type declaration.
2221 elsif Nkind (N) = N_Function_Call
2222 and then Nkind (Name (N)) = N_Explicit_Dereference
2223 and then Is_Type (It.Nam)
2227 Sloc (Associated_Node_For_Itype (Err_Type));
2232 if Nkind (N) in N_Op
2233 and then Scope (It.Nam) = Standard_Standard
2234 and then Present (Err_Type)
2236 -- Special-case the message for universal_fixed
2237 -- operators, which are not declared with the type
2238 -- of the operand, but appear forever in Standard.
2240 if It.Typ = Universal_Fixed
2241 and then Scope (It.Nam) = Standard_Standard
2244 ("\\possible interpretation as " &
2245 "universal_fixed operation " &
2246 "(RM 4.5.5 (19))", N);
2249 ("\\possible interpretation (predefined)#!", N);
2253 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2256 ("\\possible interpretation (inherited)#!", N);
2258 Error_Msg_N -- CODEFIX
2259 ("\\possible interpretation#!", N);
2265 -- We have a matching interpretation, Expr_Type is the type
2266 -- from this interpretation, and Seen is the entity.
2268 -- For an operator, just set the entity name. The type will be
2269 -- set by the specific operator resolution routine.
2271 if Nkind (N) in N_Op then
2272 Set_Entity (N, Seen);
2273 Generate_Reference (Seen, N);
2275 elsif Nkind (N) = N_Case_Expression then
2276 Set_Etype (N, Expr_Type);
2278 elsif Nkind (N) = N_Character_Literal then
2279 Set_Etype (N, Expr_Type);
2281 elsif Nkind (N) = N_Conditional_Expression then
2282 Set_Etype (N, Expr_Type);
2284 -- For an explicit dereference, attribute reference, range,
2285 -- short-circuit form (which is not an operator node), or call
2286 -- with a name that is an explicit dereference, there is
2287 -- nothing to be done at this point.
2289 elsif Nkind_In (N, N_Explicit_Dereference,
2290 N_Attribute_Reference,
2292 N_Indexed_Component,
2295 N_Selected_Component,
2297 or else Nkind (Name (N)) = N_Explicit_Dereference
2301 -- For procedure or function calls, set the type of the name,
2302 -- and also the entity pointer for the prefix.
2304 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2305 and then Is_Entity_Name (Name (N))
2307 Set_Etype (Name (N), Expr_Type);
2308 Set_Entity (Name (N), Seen);
2309 Generate_Reference (Seen, Name (N));
2311 elsif Nkind (N) = N_Function_Call
2312 and then Nkind (Name (N)) = N_Selected_Component
2314 Set_Etype (Name (N), Expr_Type);
2315 Set_Entity (Selector_Name (Name (N)), Seen);
2316 Generate_Reference (Seen, Selector_Name (Name (N)));
2318 -- For all other cases, just set the type of the Name
2321 Set_Etype (Name (N), Expr_Type);
2328 -- Move to next interpretation
2330 exit Interp_Loop when No (It.Typ);
2332 Get_Next_Interp (I, It);
2333 end loop Interp_Loop;
2336 -- At this stage Found indicates whether or not an acceptable
2337 -- interpretation exists. If not, then we have an error, except that if
2338 -- the context is Any_Type as a result of some other error, then we
2339 -- suppress the error report.
2342 if Typ /= Any_Type then
2344 -- If type we are looking for is Void, then this is the procedure
2345 -- call case, and the error is simply that what we gave is not a
2346 -- procedure name (we think of procedure calls as expressions with
2347 -- types internally, but the user doesn't think of them this way!)
2349 if Typ = Standard_Void_Type then
2351 -- Special case message if function used as a procedure
2353 if Nkind (N) = N_Procedure_Call_Statement
2354 and then Is_Entity_Name (Name (N))
2355 and then Ekind (Entity (Name (N))) = E_Function
2358 ("cannot use function & in a procedure call",
2359 Name (N), Entity (Name (N)));
2361 -- Otherwise give general message (not clear what cases this
2362 -- covers, but no harm in providing for them!)
2365 Error_Msg_N ("expect procedure name in procedure call", N);
2370 -- Otherwise we do have a subexpression with the wrong type
2372 -- Check for the case of an allocator which uses an access type
2373 -- instead of the designated type. This is a common error and we
2374 -- specialize the message, posting an error on the operand of the
2375 -- allocator, complaining that we expected the designated type of
2378 elsif Nkind (N) = N_Allocator
2379 and then Ekind (Typ) in Access_Kind
2380 and then Ekind (Etype (N)) in Access_Kind
2381 and then Designated_Type (Etype (N)) = Typ
2383 Wrong_Type (Expression (N), Designated_Type (Typ));
2386 -- Check for view mismatch on Null in instances, for which the
2387 -- view-swapping mechanism has no identifier.
2389 elsif (In_Instance or else In_Inlined_Body)
2390 and then (Nkind (N) = N_Null)
2391 and then Is_Private_Type (Typ)
2392 and then Is_Access_Type (Full_View (Typ))
2394 Resolve (N, Full_View (Typ));
2398 -- Check for an aggregate. Sometimes we can get bogus aggregates
2399 -- from misuse of parentheses, and we are about to complain about
2400 -- the aggregate without even looking inside it.
2402 -- Instead, if we have an aggregate of type Any_Composite, then
2403 -- analyze and resolve the component fields, and then only issue
2404 -- another message if we get no errors doing this (otherwise
2405 -- assume that the errors in the aggregate caused the problem).
2407 elsif Nkind (N) = N_Aggregate
2408 and then Etype (N) = Any_Composite
2410 -- Disable expansion in any case. If there is a type mismatch
2411 -- it may be fatal to try to expand the aggregate. The flag
2412 -- would otherwise be set to false when the error is posted.
2414 Expander_Active := False;
2417 procedure Check_Aggr (Aggr : Node_Id);
2418 -- Check one aggregate, and set Found to True if we have a
2419 -- definite error in any of its elements
2421 procedure Check_Elmt (Aelmt : Node_Id);
2422 -- Check one element of aggregate and set Found to True if
2423 -- we definitely have an error in the element.
2429 procedure Check_Aggr (Aggr : Node_Id) is
2433 if Present (Expressions (Aggr)) then
2434 Elmt := First (Expressions (Aggr));
2435 while Present (Elmt) loop
2441 if Present (Component_Associations (Aggr)) then
2442 Elmt := First (Component_Associations (Aggr));
2443 while Present (Elmt) loop
2445 -- If this is a default-initialized component, then
2446 -- there is nothing to check. The box will be
2447 -- replaced by the appropriate call during late
2450 if not Box_Present (Elmt) then
2451 Check_Elmt (Expression (Elmt));
2463 procedure Check_Elmt (Aelmt : Node_Id) is
2465 -- If we have a nested aggregate, go inside it (to
2466 -- attempt a naked analyze-resolve of the aggregate
2467 -- can cause undesirable cascaded errors). Do not
2468 -- resolve expression if it needs a type from context,
2469 -- as for integer * fixed expression.
2471 if Nkind (Aelmt) = N_Aggregate then
2477 if not Is_Overloaded (Aelmt)
2478 and then Etype (Aelmt) /= Any_Fixed
2483 if Etype (Aelmt) = Any_Type then
2494 -- If an error message was issued already, Found got reset
2495 -- to True, so if it is still False, issue the standard
2496 -- Wrong_Type message.
2499 if Is_Overloaded (N)
2500 and then Nkind (N) = N_Function_Call
2503 Subp_Name : Node_Id;
2505 if Is_Entity_Name (Name (N)) then
2506 Subp_Name := Name (N);
2508 elsif Nkind (Name (N)) = N_Selected_Component then
2510 -- Protected operation: retrieve operation name
2512 Subp_Name := Selector_Name (Name (N));
2514 raise Program_Error;
2517 Error_Msg_Node_2 := Typ;
2518 Error_Msg_NE ("no visible interpretation of&" &
2519 " matches expected type&", N, Subp_Name);
2522 if All_Errors_Mode then
2524 Index : Interp_Index;
2528 Error_Msg_N ("\\possible interpretations:", N);
2530 Get_First_Interp (Name (N), Index, It);
2531 while Present (It.Nam) loop
2532 Error_Msg_Sloc := Sloc (It.Nam);
2533 Error_Msg_Node_2 := It.Nam;
2535 ("\\ type& for & declared#", N, It.Typ);
2536 Get_Next_Interp (Index, It);
2541 Error_Msg_N ("\use -gnatf for details", N);
2544 Wrong_Type (N, Typ);
2552 -- Test if we have more than one interpretation for the context
2554 elsif Ambiguous then
2558 -- Here we have an acceptable interpretation for the context
2561 -- Propagate type information and normalize tree for various
2562 -- predefined operations. If the context only imposes a class of
2563 -- types, rather than a specific type, propagate the actual type
2566 if Typ = Any_Integer
2567 or else Typ = Any_Boolean
2568 or else Typ = Any_Modular
2569 or else Typ = Any_Real
2570 or else Typ = Any_Discrete
2572 Ctx_Type := Expr_Type;
2574 -- Any_Fixed is legal in a real context only if a specific
2575 -- fixed point type is imposed. If Norman Cohen can be
2576 -- confused by this, it deserves a separate message.
2579 and then Expr_Type = Any_Fixed
2581 Error_Msg_N ("illegal context for mixed mode operation", N);
2582 Set_Etype (N, Universal_Real);
2583 Ctx_Type := Universal_Real;
2587 -- A user-defined operator is transformed into a function call at
2588 -- this point, so that further processing knows that operators are
2589 -- really operators (i.e. are predefined operators). User-defined
2590 -- operators that are intrinsic are just renamings of the predefined
2591 -- ones, and need not be turned into calls either, but if they rename
2592 -- a different operator, we must transform the node accordingly.
2593 -- Instantiations of Unchecked_Conversion are intrinsic but are
2594 -- treated as functions, even if given an operator designator.
2596 if Nkind (N) in N_Op
2597 and then Present (Entity (N))
2598 and then Ekind (Entity (N)) /= E_Operator
2601 if not Is_Predefined_Op (Entity (N)) then
2602 Rewrite_Operator_As_Call (N, Entity (N));
2604 elsif Present (Alias (Entity (N)))
2606 Nkind (Parent (Parent (Entity (N)))) =
2607 N_Subprogram_Renaming_Declaration
2609 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2611 -- If the node is rewritten, it will be fully resolved in
2612 -- Rewrite_Renamed_Operator.
2614 if Analyzed (N) then
2620 case N_Subexpr'(Nkind (N)) is
2622 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2624 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2626 when N_Short_Circuit
2627 => Resolve_Short_Circuit (N, Ctx_Type);
2629 when N_Attribute_Reference
2630 => Resolve_Attribute (N, Ctx_Type);
2632 when N_Case_Expression
2633 => Resolve_Case_Expression (N, Ctx_Type);
2635 when N_Character_Literal
2636 => Resolve_Character_Literal (N, Ctx_Type);
2638 when N_Conditional_Expression
2639 => Resolve_Conditional_Expression (N, Ctx_Type);
2641 when N_Expanded_Name
2642 => Resolve_Entity_Name (N, Ctx_Type);
2644 when N_Explicit_Dereference
2645 => Resolve_Explicit_Dereference (N, Ctx_Type);
2647 when N_Expression_With_Actions
2648 => Resolve_Expression_With_Actions (N, Ctx_Type);
2650 when N_Extension_Aggregate
2651 => Resolve_Extension_Aggregate (N, Ctx_Type);
2653 when N_Function_Call
2654 => Resolve_Call (N, Ctx_Type);
2657 => Resolve_Entity_Name (N, Ctx_Type);
2659 when N_Indexed_Component
2660 => Resolve_Indexed_Component (N, Ctx_Type);
2662 when N_Integer_Literal
2663 => Resolve_Integer_Literal (N, Ctx_Type);
2665 when N_Membership_Test
2666 => Resolve_Membership_Op (N, Ctx_Type);
2668 when N_Null => Resolve_Null (N, Ctx_Type);
2670 when N_Op_And | N_Op_Or | N_Op_Xor
2671 => Resolve_Logical_Op (N, Ctx_Type);
2673 when N_Op_Eq | N_Op_Ne
2674 => Resolve_Equality_Op (N, Ctx_Type);
2676 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2677 => Resolve_Comparison_Op (N, Ctx_Type);
2679 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2681 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2682 N_Op_Divide | N_Op_Mod | N_Op_Rem
2684 => Resolve_Arithmetic_Op (N, Ctx_Type);
2686 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2688 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2690 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2691 => Resolve_Unary_Op (N, Ctx_Type);
2693 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2695 when N_Procedure_Call_Statement
2696 => Resolve_Call (N, Ctx_Type);
2698 when N_Operator_Symbol
2699 => Resolve_Operator_Symbol (N, Ctx_Type);
2701 when N_Qualified_Expression
2702 => Resolve_Qualified_Expression (N, Ctx_Type);
2704 when N_Quantified_Expression
2705 => Resolve_Quantified_Expression (N, Ctx_Type);
2707 when N_Raise_xxx_Error
2708 => Set_Etype (N, Ctx_Type);
2710 when N_Range => Resolve_Range (N, Ctx_Type);
2713 => Resolve_Real_Literal (N, Ctx_Type);
2715 when N_Reference => Resolve_Reference (N, Ctx_Type);
2717 when N_Selected_Component
2718 => Resolve_Selected_Component (N, Ctx_Type);
2720 when N_Slice => Resolve_Slice (N, Ctx_Type);
2722 when N_String_Literal
2723 => Resolve_String_Literal (N, Ctx_Type);
2725 when N_Subprogram_Info
2726 => Resolve_Subprogram_Info (N, Ctx_Type);
2728 when N_Type_Conversion
2729 => Resolve_Type_Conversion (N, Ctx_Type);
2731 when N_Unchecked_Expression =>
2732 Resolve_Unchecked_Expression (N, Ctx_Type);
2734 when N_Unchecked_Type_Conversion =>
2735 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2738 -- If the subexpression was replaced by a non-subexpression, then
2739 -- all we do is to expand it. The only legitimate case we know of
2740 -- is converting procedure call statement to entry call statements,
2741 -- but there may be others, so we are making this test general.
2743 if Nkind (N) not in N_Subexpr then
2744 Debug_A_Exit ("resolving ", N, " (done)");
2749 -- AI05-144-2: Check dangerous order dependence within an expression
2750 -- that is not a subexpression. Exclude RHS of an assignment, because
2751 -- both sides may have side-effects and the check must be performed
2752 -- over the statement.
2754 if Nkind (Parent (N)) not in N_Subexpr
2755 and then Nkind (Parent (N)) /= N_Assignment_Statement
2756 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2758 Check_Order_Dependence;
2761 -- The expression is definitely NOT overloaded at this point, so
2762 -- we reset the Is_Overloaded flag to avoid any confusion when
2763 -- reanalyzing the node.
2765 Set_Is_Overloaded (N, False);
2767 -- Freeze expression type, entity if it is a name, and designated
2768 -- type if it is an allocator (RM 13.14(10,11,13)).
2770 -- Now that the resolution of the type of the node is complete,
2771 -- and we did not detect an error, we can expand this node. We
2772 -- skip the expand call if we are in a default expression, see
2773 -- section "Handling of Default Expressions" in Sem spec.
2775 Debug_A_Exit ("resolving ", N, " (done)");
2777 -- We unconditionally freeze the expression, even if we are in
2778 -- default expression mode (the Freeze_Expression routine tests
2779 -- this flag and only freezes static types if it is set).
2781 Freeze_Expression (N);
2783 -- Now we can do the expansion
2793 -- Version with check(s) suppressed
2795 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2797 if Suppress = All_Checks then
2799 Svg : constant Suppress_Array := Scope_Suppress;
2801 Scope_Suppress := (others => True);
2803 Scope_Suppress := Svg;
2808 Svg : constant Boolean := Scope_Suppress (Suppress);
2810 Scope_Suppress (Suppress) := True;
2812 Scope_Suppress (Suppress) := Svg;
2821 -- Version with implicit type
2823 procedure Resolve (N : Node_Id) is
2825 Resolve (N, Etype (N));
2828 ---------------------
2829 -- Resolve_Actuals --
2830 ---------------------
2832 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2833 Loc : constant Source_Ptr := Sloc (N);
2838 Prev : Node_Id := Empty;
2841 procedure Check_Argument_Order;
2842 -- Performs a check for the case where the actuals are all simple
2843 -- identifiers that correspond to the formal names, but in the wrong
2844 -- order, which is considered suspicious and cause for a warning.
2846 procedure Check_Prefixed_Call;
2847 -- If the original node is an overloaded call in prefix notation,
2848 -- insert an 'Access or a dereference as needed over the first actual.
2849 -- Try_Object_Operation has already verified that there is a valid
2850 -- interpretation, but the form of the actual can only be determined
2851 -- once the primitive operation is identified.
2853 procedure Insert_Default;
2854 -- If the actual is missing in a call, insert in the actuals list
2855 -- an instance of the default expression. The insertion is always
2856 -- a named association.
2858 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2859 -- Check whether T1 and T2, or their full views, are derived from a
2860 -- common type. Used to enforce the restrictions on array conversions
2863 function Static_Concatenation (N : Node_Id) return Boolean;
2864 -- Predicate to determine whether an actual that is a concatenation
2865 -- will be evaluated statically and does not need a transient scope.
2866 -- This must be determined before the actual is resolved and expanded
2867 -- because if needed the transient scope must be introduced earlier.
2869 --------------------------
2870 -- Check_Argument_Order --
2871 --------------------------
2873 procedure Check_Argument_Order is
2875 -- Nothing to do if no parameters, or original node is neither a
2876 -- function call nor a procedure call statement (happens in the
2877 -- operator-transformed-to-function call case), or the call does
2878 -- not come from source, or this warning is off.
2880 if not Warn_On_Parameter_Order
2882 No (Parameter_Associations (N))
2884 not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2887 not Comes_From_Source (N)
2893 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2896 -- Nothing to do if only one parameter
2902 -- Here if at least two arguments
2905 Actuals : array (1 .. Nargs) of Node_Id;
2909 Wrong_Order : Boolean := False;
2910 -- Set True if an out of order case is found
2913 -- Collect identifier names of actuals, fail if any actual is
2914 -- not a simple identifier, and record max length of name.
2916 Actual := First (Parameter_Associations (N));
2917 for J in Actuals'Range loop
2918 if Nkind (Actual) /= N_Identifier then
2921 Actuals (J) := Actual;
2926 -- If we got this far, all actuals are identifiers and the list
2927 -- of their names is stored in the Actuals array.
2929 Formal := First_Formal (Nam);
2930 for J in Actuals'Range loop
2932 -- If we ran out of formals, that's odd, probably an error
2933 -- which will be detected elsewhere, but abandon the search.
2939 -- If name matches and is in order OK
2941 if Chars (Formal) = Chars (Actuals (J)) then
2945 -- If no match, see if it is elsewhere in list and if so
2946 -- flag potential wrong order if type is compatible.
2948 for K in Actuals'Range loop
2949 if Chars (Formal) = Chars (Actuals (K))
2951 Has_Compatible_Type (Actuals (K), Etype (Formal))
2953 Wrong_Order := True;
2963 <<Continue>> Next_Formal (Formal);
2966 -- If Formals left over, also probably an error, skip warning
2968 if Present (Formal) then
2972 -- Here we give the warning if something was out of order
2976 ("actuals for this call may be in wrong order?", N);
2980 end Check_Argument_Order;
2982 -------------------------
2983 -- Check_Prefixed_Call --
2984 -------------------------
2986 procedure Check_Prefixed_Call is
2987 Act : constant Node_Id := First_Actual (N);
2988 A_Type : constant Entity_Id := Etype (Act);
2989 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
2990 Orig : constant Node_Id := Original_Node (N);
2994 -- Check whether the call is a prefixed call, with or without
2995 -- additional actuals.
2997 if Nkind (Orig) = N_Selected_Component
2999 (Nkind (Orig) = N_Indexed_Component
3000 and then Nkind (Prefix (Orig)) = N_Selected_Component
3001 and then Is_Entity_Name (Prefix (Prefix (Orig)))
3002 and then Is_Entity_Name (Act)
3003 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
3005 if Is_Access_Type (A_Type)
3006 and then not Is_Access_Type (F_Type)
3008 -- Introduce dereference on object in prefix
3011 Make_Explicit_Dereference (Sloc (Act),
3012 Prefix => Relocate_Node (Act));
3013 Rewrite (Act, New_A);
3016 elsif Is_Access_Type (F_Type)
3017 and then not Is_Access_Type (A_Type)
3019 -- Introduce an implicit 'Access in prefix
3021 if not Is_Aliased_View (Act) then
3023 ("object in prefixed call to& must be aliased"
3024 & " (RM-2005 4.3.1 (13))",
3029 Make_Attribute_Reference (Loc,
3030 Attribute_Name => Name_Access,
3031 Prefix => Relocate_Node (Act)));
3036 end Check_Prefixed_Call;
3038 --------------------
3039 -- Insert_Default --
3040 --------------------
3042 procedure Insert_Default is
3047 -- Missing argument in call, nothing to insert
3049 if No (Default_Value (F)) then
3053 -- Note that we do a full New_Copy_Tree, so that any associated
3054 -- Itypes are properly copied. This may not be needed any more,
3055 -- but it does no harm as a safety measure! Defaults of a generic
3056 -- formal may be out of bounds of the corresponding actual (see
3057 -- cc1311b) and an additional check may be required.
3062 New_Scope => Current_Scope,
3065 if Is_Concurrent_Type (Scope (Nam))
3066 and then Has_Discriminants (Scope (Nam))
3068 Replace_Actual_Discriminants (N, Actval);
3071 if Is_Overloadable (Nam)
3072 and then Present (Alias (Nam))
3074 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
3075 and then not Is_Tagged_Type (Etype (F))
3077 -- If default is a real literal, do not introduce a
3078 -- conversion whose effect may depend on the run-time
3079 -- size of universal real.
3081 if Nkind (Actval) = N_Real_Literal then
3082 Set_Etype (Actval, Base_Type (Etype (F)));
3084 Actval := Unchecked_Convert_To (Etype (F), Actval);
3088 if Is_Scalar_Type (Etype (F)) then
3089 Enable_Range_Check (Actval);
3092 Set_Parent (Actval, N);
3094 -- Resolve aggregates with their base type, to avoid scope
3095 -- anomalies: the subtype was first built in the subprogram
3096 -- declaration, and the current call may be nested.
3098 if Nkind (Actval) = N_Aggregate then
3099 Analyze_And_Resolve (Actval, Etype (F));
3101 Analyze_And_Resolve (Actval, Etype (Actval));
3105 Set_Parent (Actval, N);
3107 -- See note above concerning aggregates
3109 if Nkind (Actval) = N_Aggregate
3110 and then Has_Discriminants (Etype (Actval))
3112 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
3114 -- Resolve entities with their own type, which may differ
3115 -- from the type of a reference in a generic context (the
3116 -- view swapping mechanism did not anticipate the re-analysis
3117 -- of default values in calls).
3119 elsif Is_Entity_Name (Actval) then
3120 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
3123 Analyze_And_Resolve (Actval, Etype (Actval));
3127 -- If default is a tag indeterminate function call, propagate
3128 -- tag to obtain proper dispatching.
3130 if Is_Controlling_Formal (F)
3131 and then Nkind (Default_Value (F)) = N_Function_Call
3133 Set_Is_Controlling_Actual (Actval);
3138 -- If the default expression raises constraint error, then just
3139 -- silently replace it with an N_Raise_Constraint_Error node,
3140 -- since we already gave the warning on the subprogram spec.
3141 -- If node is already a Raise_Constraint_Error leave as is, to
3142 -- prevent loops in the warnings removal machinery.
3144 if Raises_Constraint_Error (Actval)
3145 and then Nkind (Actval) /= N_Raise_Constraint_Error
3148 Make_Raise_Constraint_Error (Loc,
3149 Reason => CE_Range_Check_Failed));
3150 Set_Raises_Constraint_Error (Actval);
3151 Set_Etype (Actval, Etype (F));
3155 Make_Parameter_Association (Loc,
3156 Explicit_Actual_Parameter => Actval,
3157 Selector_Name => Make_Identifier (Loc, Chars (F)));
3159 -- Case of insertion is first named actual
3161 if No (Prev) or else
3162 Nkind (Parent (Prev)) /= N_Parameter_Association
3164 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
3165 Set_First_Named_Actual (N, Actval);
3168 if No (Parameter_Associations (N)) then
3169 Set_Parameter_Associations (N, New_List (Assoc));
3171 Append (Assoc, Parameter_Associations (N));
3175 Insert_After (Prev, Assoc);
3178 -- Case of insertion is not first named actual
3181 Set_Next_Named_Actual
3182 (Assoc, Next_Named_Actual (Parent (Prev)));
3183 Set_Next_Named_Actual (Parent (Prev), Actval);
3184 Append (Assoc, Parameter_Associations (N));
3187 Mark_Rewrite_Insertion (Assoc);
3188 Mark_Rewrite_Insertion (Actval);
3197 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
3198 FT1 : Entity_Id := T1;
3199 FT2 : Entity_Id := T2;
3202 if Is_Private_Type (T1)
3203 and then Present (Full_View (T1))
3205 FT1 := Full_View (T1);
3208 if Is_Private_Type (T2)
3209 and then Present (Full_View (T2))
3211 FT2 := Full_View (T2);
3214 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3217 --------------------------
3218 -- Static_Concatenation --
3219 --------------------------
3221 function Static_Concatenation (N : Node_Id) return Boolean is
3224 when N_String_Literal =>
3229 -- Concatenation is static when both operands are static
3230 -- and the concatenation operator is a predefined one.
3232 return Scope (Entity (N)) = Standard_Standard
3234 Static_Concatenation (Left_Opnd (N))
3236 Static_Concatenation (Right_Opnd (N));
3239 if Is_Entity_Name (N) then
3241 Ent : constant Entity_Id := Entity (N);
3243 return Ekind (Ent) = E_Constant
3244 and then Present (Constant_Value (Ent))
3246 Is_Static_Expression (Constant_Value (Ent));
3253 end Static_Concatenation;
3255 -- Start of processing for Resolve_Actuals
3258 Check_Argument_Order;
3260 if Present (First_Actual (N)) then
3261 Check_Prefixed_Call;
3264 A := First_Actual (N);
3265 F := First_Formal (Nam);
3266 while Present (F) loop
3267 if No (A) and then Needs_No_Actuals (Nam) then
3270 -- If we have an error in any actual or formal, indicated by a type
3271 -- of Any_Type, then abandon resolution attempt, and set result type
3274 elsif (Present (A) and then Etype (A) = Any_Type)
3275 or else Etype (F) = Any_Type
3277 Set_Etype (N, Any_Type);
3281 -- Case where actual is present
3283 -- If the actual is an entity, generate a reference to it now. We
3284 -- do this before the actual is resolved, because a formal of some
3285 -- protected subprogram, or a task discriminant, will be rewritten
3286 -- during expansion, and the reference to the source entity may
3290 and then Is_Entity_Name (A)
3291 and then Comes_From_Source (N)
3293 Orig_A := Entity (A);
3295 if Present (Orig_A) then
3296 if Is_Formal (Orig_A)
3297 and then Ekind (F) /= E_In_Parameter
3299 Generate_Reference (Orig_A, A, 'm');
3300 elsif not Is_Overloaded (A) then
3301 Generate_Reference (Orig_A, A);
3307 and then (Nkind (Parent (A)) /= N_Parameter_Association
3309 Chars (Selector_Name (Parent (A))) = Chars (F))
3311 -- If style checking mode on, check match of formal name
3314 if Nkind (Parent (A)) = N_Parameter_Association then
3315 Check_Identifier (Selector_Name (Parent (A)), F);
3319 -- If the formal is Out or In_Out, do not resolve and expand the
3320 -- conversion, because it is subsequently expanded into explicit
3321 -- temporaries and assignments. However, the object of the
3322 -- conversion can be resolved. An exception is the case of tagged
3323 -- type conversion with a class-wide actual. In that case we want
3324 -- the tag check to occur and no temporary will be needed (no
3325 -- representation change can occur) and the parameter is passed by
3326 -- reference, so we go ahead and resolve the type conversion.
3327 -- Another exception is the case of reference to component or
3328 -- subcomponent of a bit-packed array, in which case we want to
3329 -- defer expansion to the point the in and out assignments are
3332 if Ekind (F) /= E_In_Parameter
3333 and then Nkind (A) = N_Type_Conversion
3334 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3336 if Ekind (F) = E_In_Out_Parameter
3337 and then Is_Array_Type (Etype (F))
3339 -- In a view conversion, the conversion must be legal in
3340 -- both directions, and thus both component types must be
3341 -- aliased, or neither (4.6 (8)).
3343 -- The extra rule in 4.6 (24.9.2) seems unduly restrictive:
3344 -- the privacy requirement should not apply to generic
3345 -- types, and should be checked in an instance. ARG query
3348 if Has_Aliased_Components (Etype (Expression (A))) /=
3349 Has_Aliased_Components (Etype (F))
3352 ("both component types in a view conversion must be"
3353 & " aliased, or neither", A);
3355 -- Comment here??? what set of cases???
3358 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3360 -- Check view conv between unrelated by ref array types
3362 if Is_By_Reference_Type (Etype (F))
3363 or else Is_By_Reference_Type (Etype (Expression (A)))
3366 ("view conversion between unrelated by reference " &
3367 "array types not allowed (\'A'I-00246)", A);
3369 -- In Ada 2005 mode, check view conversion component
3370 -- type cannot be private, tagged, or volatile. Note
3371 -- that we only apply this to source conversions. The
3372 -- generated code can contain conversions which are
3373 -- not subject to this test, and we cannot extract the
3374 -- component type in such cases since it is not present.
3376 elsif Comes_From_Source (A)
3377 and then Ada_Version >= Ada_2005
3380 Comp_Type : constant Entity_Id :=
3382 (Etype (Expression (A)));
3384 if (Is_Private_Type (Comp_Type)
3385 and then not Is_Generic_Type (Comp_Type))
3386 or else Is_Tagged_Type (Comp_Type)
3387 or else Is_Volatile (Comp_Type)
3390 ("component type of a view conversion cannot"
3391 & " be private, tagged, or volatile"
3400 -- Resolve expression if conversion is all OK
3402 if (Conversion_OK (A)
3403 or else Valid_Conversion (A, Etype (A), Expression (A)))
3404 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3406 Resolve (Expression (A));
3409 -- If the actual is a function call that returns a limited
3410 -- unconstrained object that needs finalization, create a
3411 -- transient scope for it, so that it can receive the proper
3412 -- finalization list.
3414 elsif Nkind (A) = N_Function_Call
3415 and then Is_Limited_Record (Etype (F))
3416 and then not Is_Constrained (Etype (F))
3417 and then Expander_Active
3419 (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3421 Establish_Transient_Scope (A, False);
3423 -- A small optimization: if one of the actuals is a concatenation
3424 -- create a block around a procedure call to recover stack space.
3425 -- This alleviates stack usage when several procedure calls in
3426 -- the same statement list use concatenation. We do not perform
3427 -- this wrapping for code statements, where the argument is a
3428 -- static string, and we want to preserve warnings involving
3429 -- sequences of such statements.
3431 elsif Nkind (A) = N_Op_Concat
3432 and then Nkind (N) = N_Procedure_Call_Statement
3433 and then Expander_Active
3435 not (Is_Intrinsic_Subprogram (Nam)
3436 and then Chars (Nam) = Name_Asm)
3437 and then not Static_Concatenation (A)
3439 Establish_Transient_Scope (A, False);
3440 Resolve (A, Etype (F));
3443 if Nkind (A) = N_Type_Conversion
3444 and then Is_Array_Type (Etype (F))
3445 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3447 (Is_Limited_Type (Etype (F))
3448 or else Is_Limited_Type (Etype (Expression (A))))
3451 ("conversion between unrelated limited array types " &
3452 "not allowed (\A\I-00246)", A);
3454 if Is_Limited_Type (Etype (F)) then
3455 Explain_Limited_Type (Etype (F), A);
3458 if Is_Limited_Type (Etype (Expression (A))) then
3459 Explain_Limited_Type (Etype (Expression (A)), A);
3463 -- (Ada 2005: AI-251): If the actual is an allocator whose
3464 -- directly designated type is a class-wide interface, we build
3465 -- an anonymous access type to use it as the type of the
3466 -- allocator. Later, when the subprogram call is expanded, if
3467 -- the interface has a secondary dispatch table the expander
3468 -- will add a type conversion to force the correct displacement
3471 if Nkind (A) = N_Allocator then
3473 DDT : constant Entity_Id :=
3474 Directly_Designated_Type (Base_Type (Etype (F)));
3476 New_Itype : Entity_Id;
3479 if Is_Class_Wide_Type (DDT)
3480 and then Is_Interface (DDT)
3482 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3483 Set_Etype (New_Itype, Etype (A));
3484 Set_Directly_Designated_Type (New_Itype,
3485 Directly_Designated_Type (Etype (A)));
3486 Set_Etype (A, New_Itype);
3489 -- Ada 2005, AI-162:If the actual is an allocator, the
3490 -- innermost enclosing statement is the master of the
3491 -- created object. This needs to be done with expansion
3492 -- enabled only, otherwise the transient scope will not
3493 -- be removed in the expansion of the wrapped construct.
3495 if (Is_Controlled (DDT) or else Has_Task (DDT))
3496 and then Expander_Active
3498 Establish_Transient_Scope (A, False);
3503 -- (Ada 2005): The call may be to a primitive operation of
3504 -- a tagged synchronized type, declared outside of the type.
3505 -- In this case the controlling actual must be converted to
3506 -- its corresponding record type, which is the formal type.
3507 -- The actual may be a subtype, either because of a constraint
3508 -- or because it is a generic actual, so use base type to
3509 -- locate concurrent type.
3511 A_Typ := Base_Type (Etype (A));
3512 F_Typ := Base_Type (Etype (F));
3515 Full_A_Typ : Entity_Id;
3518 if Present (Full_View (A_Typ)) then
3519 Full_A_Typ := Base_Type (Full_View (A_Typ));
3521 Full_A_Typ := A_Typ;
3524 -- Tagged synchronized type (case 1): the actual is a
3527 if Is_Concurrent_Type (A_Typ)
3528 and then Corresponding_Record_Type (A_Typ) = F_Typ
3531 Unchecked_Convert_To
3532 (Corresponding_Record_Type (A_Typ), A));
3533 Resolve (A, Etype (F));
3535 -- Tagged synchronized type (case 2): the formal is a
3538 elsif Ekind (Full_A_Typ) = E_Record_Type
3540 (Corresponding_Concurrent_Type (Full_A_Typ))
3541 and then Is_Concurrent_Type (F_Typ)
3542 and then Present (Corresponding_Record_Type (F_Typ))
3543 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3545 Resolve (A, Corresponding_Record_Type (F_Typ));
3550 Resolve (A, Etype (F));
3558 -- Save actual for subsequent check on order dependence, and
3559 -- indicate whether actual is modifiable. For AI05-0144-2.
3561 Save_Actual (A, Ekind (F) /= E_In_Parameter);
3563 -- For mode IN, if actual is an entity, and the type of the formal
3564 -- has warnings suppressed, then we reset Never_Set_In_Source for
3565 -- the calling entity. The reason for this is to catch cases like
3566 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3567 -- uses trickery to modify an IN parameter.
3569 if Ekind (F) = E_In_Parameter
3570 and then Is_Entity_Name (A)
3571 and then Present (Entity (A))
3572 and then Ekind (Entity (A)) = E_Variable
3573 and then Has_Warnings_Off (F_Typ)
3575 Set_Never_Set_In_Source (Entity (A), False);
3578 -- Perform error checks for IN and IN OUT parameters
3580 if Ekind (F) /= E_Out_Parameter then
3582 -- Check unset reference. For scalar parameters, it is clearly
3583 -- wrong to pass an uninitialized value as either an IN or
3584 -- IN-OUT parameter. For composites, it is also clearly an
3585 -- error to pass a completely uninitialized value as an IN
3586 -- parameter, but the case of IN OUT is trickier. We prefer
3587 -- not to give a warning here. For example, suppose there is
3588 -- a routine that sets some component of a record to False.
3589 -- It is perfectly reasonable to make this IN-OUT and allow
3590 -- either initialized or uninitialized records to be passed
3593 -- For partially initialized composite values, we also avoid
3594 -- warnings, since it is quite likely that we are passing a
3595 -- partially initialized value and only the initialized fields
3596 -- will in fact be read in the subprogram.
3598 if Is_Scalar_Type (A_Typ)
3599 or else (Ekind (F) = E_In_Parameter
3600 and then not Is_Partially_Initialized_Type (A_Typ))
3602 Check_Unset_Reference (A);
3605 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3606 -- actual to a nested call, since this is case of reading an
3607 -- out parameter, which is not allowed.
3609 if Ada_Version = Ada_83
3610 and then Is_Entity_Name (A)
3611 and then Ekind (Entity (A)) = E_Out_Parameter
3613 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3617 -- Case of OUT or IN OUT parameter
3619 if Ekind (F) /= E_In_Parameter then
3621 -- For an Out parameter, check for useless assignment. Note
3622 -- that we can't set Last_Assignment this early, because we may
3623 -- kill current values in Resolve_Call, and that call would
3624 -- clobber the Last_Assignment field.
3626 -- Note: call Warn_On_Useless_Assignment before doing the check
3627 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3628 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3629 -- reflects the last assignment, not this one!
3631 if Ekind (F) = E_Out_Parameter then
3632 if Warn_On_Modified_As_Out_Parameter (F)
3633 and then Is_Entity_Name (A)
3634 and then Present (Entity (A))
3635 and then Comes_From_Source (N)
3637 Warn_On_Useless_Assignment (Entity (A), A);
3641 -- Validate the form of the actual. Note that the call to
3642 -- Is_OK_Variable_For_Out_Formal generates the required
3643 -- reference in this case.
3645 if not Is_OK_Variable_For_Out_Formal (A) then
3646 Error_Msg_NE ("actual for& must be a variable", A, F);
3649 -- What's the following about???
3651 if Is_Entity_Name (A) then
3652 Kill_Checks (Entity (A));
3658 if Etype (A) = Any_Type then
3659 Set_Etype (N, Any_Type);
3663 -- Apply appropriate range checks for in, out, and in-out
3664 -- parameters. Out and in-out parameters also need a separate
3665 -- check, if there is a type conversion, to make sure the return
3666 -- value meets the constraints of the variable before the
3669 -- Gigi looks at the check flag and uses the appropriate types.
3670 -- For now since one flag is used there is an optimization which
3671 -- might not be done in the In Out case since Gigi does not do
3672 -- any analysis. More thought required about this ???
3674 if Ekind_In (F, E_In_Parameter, E_In_Out_Parameter) then
3676 -- Apply predicate checks, unless this is a call to the
3677 -- predicate check function itself, which would cause an
3678 -- infinite recursion.
3680 if not (Ekind (Nam) = E_Function
3681 and then Has_Predicates (Nam))
3683 Apply_Predicate_Check (A, F_Typ);
3686 -- Apply required constraint checks
3688 if Is_Scalar_Type (Etype (A)) then
3689 Apply_Scalar_Range_Check (A, F_Typ);
3691 elsif Is_Array_Type (Etype (A)) then
3692 Apply_Length_Check (A, F_Typ);
3694 elsif Is_Record_Type (F_Typ)
3695 and then Has_Discriminants (F_Typ)
3696 and then Is_Constrained (F_Typ)
3697 and then (not Is_Derived_Type (F_Typ)
3698 or else Comes_From_Source (Nam))
3700 Apply_Discriminant_Check (A, F_Typ);
3702 elsif Is_Access_Type (F_Typ)
3703 and then Is_Array_Type (Designated_Type (F_Typ))
3704 and then Is_Constrained (Designated_Type (F_Typ))
3706 Apply_Length_Check (A, F_Typ);
3708 elsif Is_Access_Type (F_Typ)
3709 and then Has_Discriminants (Designated_Type (F_Typ))
3710 and then Is_Constrained (Designated_Type (F_Typ))
3712 Apply_Discriminant_Check (A, F_Typ);
3715 Apply_Range_Check (A, F_Typ);
3718 -- Ada 2005 (AI-231): Note that the controlling parameter case
3719 -- already existed in Ada 95, which is partially checked
3720 -- elsewhere (see Checks), and we don't want the warning
3721 -- message to differ.
3723 if Is_Access_Type (F_Typ)
3724 and then Can_Never_Be_Null (F_Typ)
3725 and then Known_Null (A)
3727 if Is_Controlling_Formal (F) then
3728 Apply_Compile_Time_Constraint_Error
3730 Msg => "null value not allowed here?",
3731 Reason => CE_Access_Check_Failed);
3733 elsif Ada_Version >= Ada_2005 then
3734 Apply_Compile_Time_Constraint_Error
3736 Msg => "(Ada 2005) null not allowed in "
3737 & "null-excluding formal?",
3738 Reason => CE_Null_Not_Allowed);
3743 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter) then
3744 if Nkind (A) = N_Type_Conversion then
3745 if Is_Scalar_Type (A_Typ) then
3746 Apply_Scalar_Range_Check
3747 (Expression (A), Etype (Expression (A)), A_Typ);
3750 (Expression (A), Etype (Expression (A)), A_Typ);
3754 if Is_Scalar_Type (F_Typ) then
3755 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3757 elsif Is_Array_Type (F_Typ)
3758 and then Ekind (F) = E_Out_Parameter
3760 Apply_Length_Check (A, F_Typ);
3763 Apply_Range_Check (A, A_Typ, F_Typ);
3768 -- An actual associated with an access parameter is implicitly
3769 -- converted to the anonymous access type of the formal and must
3770 -- satisfy the legality checks for access conversions.
3772 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3773 if not Valid_Conversion (A, F_Typ, A) then
3775 ("invalid implicit conversion for access parameter", A);
3779 -- Check bad case of atomic/volatile argument (RM C.6(12))
3781 if Is_By_Reference_Type (Etype (F))
3782 and then Comes_From_Source (N)
3784 if Is_Atomic_Object (A)
3785 and then not Is_Atomic (Etype (F))
3788 ("cannot pass atomic argument to non-atomic formal",
3791 elsif Is_Volatile_Object (A)
3792 and then not Is_Volatile (Etype (F))
3795 ("cannot pass volatile argument to non-volatile formal",
3800 -- Check that subprograms don't have improper controlling
3801 -- arguments (RM 3.9.2 (9)).
3803 -- A primitive operation may have an access parameter of an
3804 -- incomplete tagged type, but a dispatching call is illegal
3805 -- if the type is still incomplete.
3807 if Is_Controlling_Formal (F) then
3808 Set_Is_Controlling_Actual (A);
3810 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3812 Desig : constant Entity_Id := Designated_Type (Etype (F));
3814 if Ekind (Desig) = E_Incomplete_Type
3815 and then No (Full_View (Desig))
3816 and then No (Non_Limited_View (Desig))
3819 ("premature use of incomplete type& " &
3820 "in dispatching call", A, Desig);
3825 elsif Nkind (A) = N_Explicit_Dereference then
3826 Validate_Remote_Access_To_Class_Wide_Type (A);
3829 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3830 and then not Is_Class_Wide_Type (F_Typ)
3831 and then not Is_Controlling_Formal (F)
3833 Error_Msg_N ("class-wide argument not allowed here!", A);
3835 if Is_Subprogram (Nam)
3836 and then Comes_From_Source (Nam)
3838 Error_Msg_Node_2 := F_Typ;
3840 ("& is not a dispatching operation of &!", A, Nam);
3843 elsif Is_Access_Type (A_Typ)
3844 and then Is_Access_Type (F_Typ)
3845 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3846 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3847 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3848 or else (Nkind (A) = N_Attribute_Reference
3850 Is_Class_Wide_Type (Etype (Prefix (A)))))
3851 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3852 and then not Is_Controlling_Formal (F)
3854 -- Disable these checks for call to imported C++ subprograms
3857 (Is_Entity_Name (Name (N))
3858 and then Is_Imported (Entity (Name (N)))
3859 and then Convention (Entity (Name (N))) = Convention_CPP)
3862 ("access to class-wide argument not allowed here!", A);
3864 if Is_Subprogram (Nam)
3865 and then Comes_From_Source (Nam)
3867 Error_Msg_Node_2 := Designated_Type (F_Typ);
3869 ("& is not a dispatching operation of &!", A, Nam);
3875 -- If it is a named association, treat the selector_name as a
3876 -- proper identifier, and mark the corresponding entity.
3878 if Nkind (Parent (A)) = N_Parameter_Association then
3879 Set_Entity (Selector_Name (Parent (A)), F);
3880 Generate_Reference (F, Selector_Name (Parent (A)));
3881 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3882 Generate_Reference (F_Typ, N, ' ');
3887 if Ekind (F) /= E_Out_Parameter then
3888 Check_Unset_Reference (A);
3893 -- Case where actual is not present
3901 end Resolve_Actuals;
3903 -----------------------
3904 -- Resolve_Allocator --
3905 -----------------------
3907 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
3908 E : constant Node_Id := Expression (N);
3910 Discrim : Entity_Id;
3913 Assoc : Node_Id := Empty;
3916 procedure Check_Allocator_Discrim_Accessibility
3917 (Disc_Exp : Node_Id;
3918 Alloc_Typ : Entity_Id);
3919 -- Check that accessibility level associated with an access discriminant
3920 -- initialized in an allocator by the expression Disc_Exp is not deeper
3921 -- than the level of the allocator type Alloc_Typ. An error message is
3922 -- issued if this condition is violated. Specialized checks are done for
3923 -- the cases of a constraint expression which is an access attribute or
3924 -- an access discriminant.
3926 function In_Dispatching_Context return Boolean;
3927 -- If the allocator is an actual in a call, it is allowed to be class-
3928 -- wide when the context is not because it is a controlling actual.
3930 procedure Propagate_Coextensions (Root : Node_Id);
3931 -- Propagate all nested coextensions which are located one nesting
3932 -- level down the tree to the node Root. Example:
3935 -- Level_1_Coextension
3936 -- Level_2_Coextension
3938 -- The algorithm is paired with delay actions done by the Expander. In
3939 -- the above example, assume all coextensions are controlled types.
3940 -- The cycle of analysis, resolution and expansion will yield:
3942 -- 1) Analyze Top_Record
3943 -- 2) Analyze Level_1_Coextension
3944 -- 3) Analyze Level_2_Coextension
3945 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
3947 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3948 -- generated to capture the allocated object. Temp_1 is attached
3949 -- to the coextension chain of Level_2_Coextension.
3950 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3951 -- coextension. A forward tree traversal is performed which finds
3952 -- Level_2_Coextension's list and copies its contents into its
3954 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3955 -- generated to capture the allocated object. Temp_2 is attached
3956 -- to the coextension chain of Level_1_Coextension. Currently, the
3957 -- contents of the list are [Temp_2, Temp_1].
3958 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3959 -- finds Level_1_Coextension's list and copies its contents into
3961 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3962 -- Temp_2 and attach them to Top_Record's finalization list.
3964 -------------------------------------------
3965 -- Check_Allocator_Discrim_Accessibility --
3966 -------------------------------------------
3968 procedure Check_Allocator_Discrim_Accessibility
3969 (Disc_Exp : Node_Id;
3970 Alloc_Typ : Entity_Id)
3973 if Type_Access_Level (Etype (Disc_Exp)) >
3974 Type_Access_Level (Alloc_Typ)
3977 ("operand type has deeper level than allocator type", Disc_Exp);
3979 -- When the expression is an Access attribute the level of the prefix
3980 -- object must not be deeper than that of the allocator's type.
3982 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3983 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3985 and then Object_Access_Level (Prefix (Disc_Exp))
3986 > Type_Access_Level (Alloc_Typ)
3989 ("prefix of attribute has deeper level than allocator type",
3992 -- When the expression is an access discriminant the check is against
3993 -- the level of the prefix object.
3995 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3996 and then Nkind (Disc_Exp) = N_Selected_Component
3997 and then Object_Access_Level (Prefix (Disc_Exp))
3998 > Type_Access_Level (Alloc_Typ)
4001 ("access discriminant has deeper level than allocator type",
4004 -- All other cases are legal
4009 end Check_Allocator_Discrim_Accessibility;
4011 ----------------------------
4012 -- In_Dispatching_Context --
4013 ----------------------------
4015 function In_Dispatching_Context return Boolean is
4016 Par : constant Node_Id := Parent (N);
4018 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
4019 and then Is_Entity_Name (Name (Par))
4020 and then Is_Dispatching_Operation (Entity (Name (Par)));
4021 end In_Dispatching_Context;
4023 ----------------------------
4024 -- Propagate_Coextensions --
4025 ----------------------------
4027 procedure Propagate_Coextensions (Root : Node_Id) is
4029 procedure Copy_List (From : Elist_Id; To : Elist_Id);
4030 -- Copy the contents of list From into list To, preserving the
4031 -- order of elements.
4033 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
4034 -- Recognize an allocator or a rewritten allocator node and add it
4035 -- along with its nested coextensions to the list of Root.
4041 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
4042 From_Elmt : Elmt_Id;
4044 From_Elmt := First_Elmt (From);
4045 while Present (From_Elmt) loop
4046 Append_Elmt (Node (From_Elmt), To);
4047 Next_Elmt (From_Elmt);
4051 -----------------------
4052 -- Process_Allocator --
4053 -----------------------
4055 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
4056 Orig_Nod : Node_Id := Nod;
4059 -- This is a possible rewritten subtype indication allocator. Any
4060 -- nested coextensions will appear as discriminant constraints.
4062 if Nkind (Nod) = N_Identifier
4063 and then Present (Original_Node (Nod))
4064 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
4068 Discr_Elmt : Elmt_Id;
4071 if Is_Record_Type (Entity (Nod)) then
4073 First_Elmt (Discriminant_Constraint (Entity (Nod)));
4074 while Present (Discr_Elmt) loop
4075 Discr := Node (Discr_Elmt);
4077 if Nkind (Discr) = N_Identifier
4078 and then Present (Original_Node (Discr))
4079 and then Nkind (Original_Node (Discr)) = N_Allocator
4080 and then Present (Coextensions (
4081 Original_Node (Discr)))
4083 if No (Coextensions (Root)) then
4084 Set_Coextensions (Root, New_Elmt_List);
4088 (From => Coextensions (Original_Node (Discr)),
4089 To => Coextensions (Root));
4092 Next_Elmt (Discr_Elmt);
4095 -- There is no need to continue the traversal of this
4096 -- subtree since all the information has already been
4103 -- Case of either a stand alone allocator or a rewritten allocator
4104 -- with an aggregate.
4107 if Present (Original_Node (Nod)) then
4108 Orig_Nod := Original_Node (Nod);
4111 if Nkind (Orig_Nod) = N_Allocator then
4113 -- Propagate the list of nested coextensions to the Root
4114 -- allocator. This is done through list copy since a single
4115 -- allocator may have multiple coextensions. Do not touch
4116 -- coextensions roots.
4118 if not Is_Coextension_Root (Orig_Nod)
4119 and then Present (Coextensions (Orig_Nod))
4121 if No (Coextensions (Root)) then
4122 Set_Coextensions (Root, New_Elmt_List);
4126 (From => Coextensions (Orig_Nod),
4127 To => Coextensions (Root));
4130 -- There is no need to continue the traversal of this
4131 -- subtree since all the information has already been
4138 -- Keep on traversing, looking for the next allocator
4141 end Process_Allocator;
4143 procedure Process_Allocators is
4144 new Traverse_Proc (Process_Allocator);
4146 -- Start of processing for Propagate_Coextensions
4149 Process_Allocators (Expression (Root));
4150 end Propagate_Coextensions;
4152 -- Start of processing for Resolve_Allocator
4155 -- Replace general access with specific type
4157 if Ekind (Etype (N)) = E_Allocator_Type then
4158 Set_Etype (N, Base_Type (Typ));
4161 if Is_Abstract_Type (Typ) then
4162 Error_Msg_N ("type of allocator cannot be abstract", N);
4165 -- For qualified expression, resolve the expression using the
4166 -- given subtype (nothing to do for type mark, subtype indication)
4168 if Nkind (E) = N_Qualified_Expression then
4169 if Is_Class_Wide_Type (Etype (E))
4170 and then not Is_Class_Wide_Type (Designated_Type (Typ))
4171 and then not In_Dispatching_Context
4174 ("class-wide allocator not allowed for this access type", N);
4177 Resolve (Expression (E), Etype (E));
4178 Check_Unset_Reference (Expression (E));
4180 -- A qualified expression requires an exact match of the type,
4181 -- class-wide matching is not allowed.
4183 if (Is_Class_Wide_Type (Etype (Expression (E)))
4184 or else Is_Class_Wide_Type (Etype (E)))
4185 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
4187 Wrong_Type (Expression (E), Etype (E));
4190 -- A special accessibility check is needed for allocators that
4191 -- constrain access discriminants. The level of the type of the
4192 -- expression used to constrain an access discriminant cannot be
4193 -- deeper than the type of the allocator (in contrast to access
4194 -- parameters, where the level of the actual can be arbitrary).
4196 -- We can't use Valid_Conversion to perform this check because
4197 -- in general the type of the allocator is unrelated to the type
4198 -- of the access discriminant.
4200 if Ekind (Typ) /= E_Anonymous_Access_Type
4201 or else Is_Local_Anonymous_Access (Typ)
4203 Subtyp := Entity (Subtype_Mark (E));
4205 Aggr := Original_Node (Expression (E));
4207 if Has_Discriminants (Subtyp)
4208 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
4210 Discrim := First_Discriminant (Base_Type (Subtyp));
4212 -- Get the first component expression of the aggregate
4214 if Present (Expressions (Aggr)) then
4215 Disc_Exp := First (Expressions (Aggr));
4217 elsif Present (Component_Associations (Aggr)) then
4218 Assoc := First (Component_Associations (Aggr));
4220 if Present (Assoc) then
4221 Disc_Exp := Expression (Assoc);
4230 while Present (Discrim) and then Present (Disc_Exp) loop
4231 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4232 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4235 Next_Discriminant (Discrim);
4237 if Present (Discrim) then
4238 if Present (Assoc) then
4240 Disc_Exp := Expression (Assoc);
4242 elsif Present (Next (Disc_Exp)) then
4246 Assoc := First (Component_Associations (Aggr));
4248 if Present (Assoc) then
4249 Disc_Exp := Expression (Assoc);
4259 -- For a subtype mark or subtype indication, freeze the subtype
4262 Freeze_Expression (E);
4264 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
4266 ("initialization required for access-to-constant allocator", N);
4269 -- A special accessibility check is needed for allocators that
4270 -- constrain access discriminants. The level of the type of the
4271 -- expression used to constrain an access discriminant cannot be
4272 -- deeper than the type of the allocator (in contrast to access
4273 -- parameters, where the level of the actual can be arbitrary).
4274 -- We can't use Valid_Conversion to perform this check because
4275 -- in general the type of the allocator is unrelated to the type
4276 -- of the access discriminant.
4278 if Nkind (Original_Node (E)) = N_Subtype_Indication
4279 and then (Ekind (Typ) /= E_Anonymous_Access_Type
4280 or else Is_Local_Anonymous_Access (Typ))
4282 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
4284 if Has_Discriminants (Subtyp) then
4285 Discrim := First_Discriminant (Base_Type (Subtyp));
4286 Constr := First (Constraints (Constraint (Original_Node (E))));
4287 while Present (Discrim) and then Present (Constr) loop
4288 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4289 if Nkind (Constr) = N_Discriminant_Association then
4290 Disc_Exp := Original_Node (Expression (Constr));
4292 Disc_Exp := Original_Node (Constr);
4295 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4298 Next_Discriminant (Discrim);
4305 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4306 -- check that the level of the type of the created object is not deeper
4307 -- than the level of the allocator's access type, since extensions can
4308 -- now occur at deeper levels than their ancestor types. This is a
4309 -- static accessibility level check; a run-time check is also needed in
4310 -- the case of an initialized allocator with a class-wide argument (see
4311 -- Expand_Allocator_Expression).
4313 if Ada_Version >= Ada_2005
4314 and then Is_Class_Wide_Type (Designated_Type (Typ))
4317 Exp_Typ : Entity_Id;
4320 if Nkind (E) = N_Qualified_Expression then
4321 Exp_Typ := Etype (E);
4322 elsif Nkind (E) = N_Subtype_Indication then
4323 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4325 Exp_Typ := Entity (E);
4328 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4329 if In_Instance_Body then
4330 Error_Msg_N ("?type in allocator has deeper level than" &
4331 " designated class-wide type", E);
4332 Error_Msg_N ("\?Program_Error will be raised at run time",
4335 Make_Raise_Program_Error (Sloc (N),
4336 Reason => PE_Accessibility_Check_Failed));
4339 -- Do not apply Ada 2005 accessibility checks on a class-wide
4340 -- allocator if the type given in the allocator is a formal
4341 -- type. A run-time check will be performed in the instance.
4343 elsif not Is_Generic_Type (Exp_Typ) then
4344 Error_Msg_N ("type in allocator has deeper level than" &
4345 " designated class-wide type", E);
4351 -- Check for allocation from an empty storage pool
4353 if No_Pool_Assigned (Typ) then
4354 Error_Msg_N ("allocation from empty storage pool!", N);
4356 -- If the context is an unchecked conversion, as may happen within
4357 -- an inlined subprogram, the allocator is being resolved with its
4358 -- own anonymous type. In that case, if the target type has a specific
4359 -- storage pool, it must be inherited explicitly by the allocator type.
4361 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4362 and then No (Associated_Storage_Pool (Typ))
4364 Set_Associated_Storage_Pool
4365 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4368 if Ekind (Etype (N)) = E_Anonymous_Access_Type then
4369 Check_Restriction (No_Anonymous_Allocators, N);
4372 -- An erroneous allocator may be rewritten as a raise Program_Error
4375 if Nkind (N) = N_Allocator then
4377 -- An anonymous access discriminant is the definition of a
4380 if Ekind (Typ) = E_Anonymous_Access_Type
4381 and then Nkind (Associated_Node_For_Itype (Typ)) =
4382 N_Discriminant_Specification
4384 -- Avoid marking an allocator as a dynamic coextension if it is
4385 -- within a static construct.
4387 if not Is_Static_Coextension (N) then
4388 Set_Is_Dynamic_Coextension (N);
4391 -- Cleanup for potential static coextensions
4394 Set_Is_Dynamic_Coextension (N, False);
4395 Set_Is_Static_Coextension (N, False);
4398 -- There is no need to propagate any nested coextensions if they
4399 -- are marked as static since they will be rewritten on the spot.
4401 if not Is_Static_Coextension (N) then
4402 Propagate_Coextensions (N);
4405 end Resolve_Allocator;
4407 ---------------------------
4408 -- Resolve_Arithmetic_Op --
4409 ---------------------------
4411 -- Used for resolving all arithmetic operators except exponentiation
4413 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4414 L : constant Node_Id := Left_Opnd (N);
4415 R : constant Node_Id := Right_Opnd (N);
4416 TL : constant Entity_Id := Base_Type (Etype (L));
4417 TR : constant Entity_Id := Base_Type (Etype (R));
4421 B_Typ : constant Entity_Id := Base_Type (Typ);
4422 -- We do the resolution using the base type, because intermediate values
4423 -- in expressions always are of the base type, not a subtype of it.
4425 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4426 -- Returns True if N is in a context that expects "any real type"
4428 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4429 -- Return True iff given type is Integer or universal real/integer
4431 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4432 -- Choose type of integer literal in fixed-point operation to conform
4433 -- to available fixed-point type. T is the type of the other operand,
4434 -- which is needed to determine the expected type of N.
4436 procedure Set_Operand_Type (N : Node_Id);
4437 -- Set operand type to T if universal
4439 -------------------------------
4440 -- Expected_Type_Is_Any_Real --
4441 -------------------------------
4443 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4445 -- N is the expression after "delta" in a fixed_point_definition;
4448 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4449 N_Decimal_Fixed_Point_Definition,
4451 -- N is one of the bounds in a real_range_specification;
4454 N_Real_Range_Specification,
4456 -- N is the expression of a delta_constraint;
4459 N_Delta_Constraint);
4460 end Expected_Type_Is_Any_Real;
4462 -----------------------------
4463 -- Is_Integer_Or_Universal --
4464 -----------------------------
4466 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4468 Index : Interp_Index;
4472 if not Is_Overloaded (N) then
4474 return Base_Type (T) = Base_Type (Standard_Integer)
4475 or else T = Universal_Integer
4476 or else T = Universal_Real;
4478 Get_First_Interp (N, Index, It);
4479 while Present (It.Typ) loop
4480 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4481 or else It.Typ = Universal_Integer
4482 or else It.Typ = Universal_Real
4487 Get_Next_Interp (Index, It);
4492 end Is_Integer_Or_Universal;
4494 ----------------------------
4495 -- Set_Mixed_Mode_Operand --
4496 ----------------------------
4498 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4499 Index : Interp_Index;
4503 if Universal_Interpretation (N) = Universal_Integer then
4505 -- A universal integer literal is resolved as standard integer
4506 -- except in the case of a fixed-point result, where we leave it
4507 -- as universal (to be handled by Exp_Fixd later on)
4509 if Is_Fixed_Point_Type (T) then
4510 Resolve (N, Universal_Integer);
4512 Resolve (N, Standard_Integer);
4515 elsif Universal_Interpretation (N) = Universal_Real
4516 and then (T = Base_Type (Standard_Integer)
4517 or else T = Universal_Integer
4518 or else T = Universal_Real)
4520 -- A universal real can appear in a fixed-type context. We resolve
4521 -- the literal with that context, even though this might raise an
4522 -- exception prematurely (the other operand may be zero).
4526 elsif Etype (N) = Base_Type (Standard_Integer)
4527 and then T = Universal_Real
4528 and then Is_Overloaded (N)
4530 -- Integer arg in mixed-mode operation. Resolve with universal
4531 -- type, in case preference rule must be applied.
4533 Resolve (N, Universal_Integer);
4536 and then B_Typ /= Universal_Fixed
4538 -- Not a mixed-mode operation, resolve with context
4542 elsif Etype (N) = Any_Fixed then
4544 -- N may itself be a mixed-mode operation, so use context type
4548 elsif Is_Fixed_Point_Type (T)
4549 and then B_Typ = Universal_Fixed
4550 and then Is_Overloaded (N)
4552 -- Must be (fixed * fixed) operation, operand must have one
4553 -- compatible interpretation.
4555 Resolve (N, Any_Fixed);
4557 elsif Is_Fixed_Point_Type (B_Typ)
4558 and then (T = Universal_Real
4559 or else Is_Fixed_Point_Type (T))
4560 and then Is_Overloaded (N)
4562 -- C * F(X) in a fixed context, where C is a real literal or a
4563 -- fixed-point expression. F must have either a fixed type
4564 -- interpretation or an integer interpretation, but not both.
4566 Get_First_Interp (N, Index, It);
4567 while Present (It.Typ) loop
4568 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4570 if Analyzed (N) then
4571 Error_Msg_N ("ambiguous operand in fixed operation", N);
4573 Resolve (N, Standard_Integer);
4576 elsif Is_Fixed_Point_Type (It.Typ) then
4578 if Analyzed (N) then
4579 Error_Msg_N ("ambiguous operand in fixed operation", N);
4581 Resolve (N, It.Typ);
4585 Get_Next_Interp (Index, It);
4588 -- Reanalyze the literal with the fixed type of the context. If
4589 -- context is Universal_Fixed, we are within a conversion, leave
4590 -- the literal as a universal real because there is no usable
4591 -- fixed type, and the target of the conversion plays no role in
4605 if B_Typ = Universal_Fixed
4606 and then Nkind (Op2) = N_Real_Literal
4608 T2 := Universal_Real;
4613 Set_Analyzed (Op2, False);
4620 end Set_Mixed_Mode_Operand;
4622 ----------------------
4623 -- Set_Operand_Type --
4624 ----------------------
4626 procedure Set_Operand_Type (N : Node_Id) is
4628 if Etype (N) = Universal_Integer
4629 or else Etype (N) = Universal_Real
4633 end Set_Operand_Type;
4635 -- Start of processing for Resolve_Arithmetic_Op
4638 if Comes_From_Source (N)
4639 and then Ekind (Entity (N)) = E_Function
4640 and then Is_Imported (Entity (N))
4641 and then Is_Intrinsic_Subprogram (Entity (N))
4643 Resolve_Intrinsic_Operator (N, Typ);
4646 -- Special-case for mixed-mode universal expressions or fixed point
4647 -- type operation: each argument is resolved separately. The same
4648 -- treatment is required if one of the operands of a fixed point
4649 -- operation is universal real, since in this case we don't do a
4650 -- conversion to a specific fixed-point type (instead the expander
4651 -- takes care of the case).
4653 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4654 and then Present (Universal_Interpretation (L))
4655 and then Present (Universal_Interpretation (R))
4657 Resolve (L, Universal_Interpretation (L));
4658 Resolve (R, Universal_Interpretation (R));
4659 Set_Etype (N, B_Typ);
4661 elsif (B_Typ = Universal_Real
4662 or else Etype (N) = Universal_Fixed
4663 or else (Etype (N) = Any_Fixed
4664 and then Is_Fixed_Point_Type (B_Typ))
4665 or else (Is_Fixed_Point_Type (B_Typ)
4666 and then (Is_Integer_Or_Universal (L)
4668 Is_Integer_Or_Universal (R))))
4669 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4671 if TL = Universal_Integer or else TR = Universal_Integer then
4672 Check_For_Visible_Operator (N, B_Typ);
4675 -- If context is a fixed type and one operand is integer, the
4676 -- other is resolved with the type of the context.
4678 if Is_Fixed_Point_Type (B_Typ)
4679 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4680 or else TL = Universal_Integer)
4685 elsif Is_Fixed_Point_Type (B_Typ)
4686 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4687 or else TR = Universal_Integer)
4693 Set_Mixed_Mode_Operand (L, TR);
4694 Set_Mixed_Mode_Operand (R, TL);
4697 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4698 -- multiplying operators from being used when the expected type is
4699 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4700 -- some cases where the expected type is actually Any_Real;
4701 -- Expected_Type_Is_Any_Real takes care of that case.
4703 if Etype (N) = Universal_Fixed
4704 or else Etype (N) = Any_Fixed
4706 if B_Typ = Universal_Fixed
4707 and then not Expected_Type_Is_Any_Real (N)
4708 and then not Nkind_In (Parent (N), N_Type_Conversion,
4709 N_Unchecked_Type_Conversion)
4711 Error_Msg_N ("type cannot be determined from context!", N);
4712 Error_Msg_N ("\explicit conversion to result type required", N);
4714 Set_Etype (L, Any_Type);
4715 Set_Etype (R, Any_Type);
4718 if Ada_Version = Ada_83
4719 and then Etype (N) = Universal_Fixed
4721 Nkind_In (Parent (N), N_Type_Conversion,
4722 N_Unchecked_Type_Conversion)
4725 ("(Ada 83) fixed-point operation "
4726 & "needs explicit conversion", N);
4729 -- The expected type is "any real type" in contexts like
4730 -- type T is delta <universal_fixed-expression> ...
4731 -- in which case we need to set the type to Universal_Real
4732 -- so that static expression evaluation will work properly.
4734 if Expected_Type_Is_Any_Real (N) then
4735 Set_Etype (N, Universal_Real);
4737 Set_Etype (N, B_Typ);
4741 elsif Is_Fixed_Point_Type (B_Typ)
4742 and then (Is_Integer_Or_Universal (L)
4743 or else Nkind (L) = N_Real_Literal
4744 or else Nkind (R) = N_Real_Literal
4745 or else Is_Integer_Or_Universal (R))
4747 Set_Etype (N, B_Typ);
4749 elsif Etype (N) = Any_Fixed then
4751 -- If no previous errors, this is only possible if one operand
4752 -- is overloaded and the context is universal. Resolve as such.
4754 Set_Etype (N, B_Typ);
4758 if (TL = Universal_Integer or else TL = Universal_Real)
4760 (TR = Universal_Integer or else TR = Universal_Real)
4762 Check_For_Visible_Operator (N, B_Typ);
4765 -- If the context is Universal_Fixed and the operands are also
4766 -- universal fixed, this is an error, unless there is only one
4767 -- applicable fixed_point type (usually Duration).
4769 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4770 T := Unique_Fixed_Point_Type (N);
4772 if T = Any_Type then
4785 -- If one of the arguments was resolved to a non-universal type.
4786 -- label the result of the operation itself with the same type.
4787 -- Do the same for the universal argument, if any.
4789 T := Intersect_Types (L, R);
4790 Set_Etype (N, Base_Type (T));
4791 Set_Operand_Type (L);
4792 Set_Operand_Type (R);
4795 Generate_Operator_Reference (N, Typ);
4796 Eval_Arithmetic_Op (N);
4798 -- Set overflow and division checking bit. Much cleverer code needed
4799 -- here eventually and perhaps the Resolve routines should be separated
4800 -- for the various arithmetic operations, since they will need
4801 -- different processing. ???
4803 if Nkind (N) in N_Op then
4804 if not Overflow_Checks_Suppressed (Etype (N)) then
4805 Enable_Overflow_Check (N);
4808 -- Give warning if explicit division by zero
4810 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4811 and then not Division_Checks_Suppressed (Etype (N))
4813 Rop := Right_Opnd (N);
4815 if Compile_Time_Known_Value (Rop)
4816 and then ((Is_Integer_Type (Etype (Rop))
4817 and then Expr_Value (Rop) = Uint_0)
4819 (Is_Real_Type (Etype (Rop))
4820 and then Expr_Value_R (Rop) = Ureal_0))
4822 -- Specialize the warning message according to the operation
4826 Apply_Compile_Time_Constraint_Error
4827 (N, "division by zero?", CE_Divide_By_Zero,
4828 Loc => Sloc (Right_Opnd (N)));
4831 Apply_Compile_Time_Constraint_Error
4832 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4833 Loc => Sloc (Right_Opnd (N)));
4836 Apply_Compile_Time_Constraint_Error
4837 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4838 Loc => Sloc (Right_Opnd (N)));
4840 -- Division by zero can only happen with division, rem,
4841 -- and mod operations.
4844 raise Program_Error;
4847 -- Otherwise just set the flag to check at run time
4850 Activate_Division_Check (N);
4854 -- If Restriction No_Implicit_Conditionals is active, then it is
4855 -- violated if either operand can be negative for mod, or for rem
4856 -- if both operands can be negative.
4858 if Restriction_Check_Required (No_Implicit_Conditionals)
4859 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4868 -- Set if corresponding operand might be negative
4872 (Left_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4873 LNeg := (not OK) or else Lo < 0;
4876 (Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4877 RNeg := (not OK) or else Lo < 0;
4879 -- Check if we will be generating conditionals. There are two
4880 -- cases where that can happen, first for REM, the only case
4881 -- is largest negative integer mod -1, where the division can
4882 -- overflow, but we still have to give the right result. The
4883 -- front end generates a test for this annoying case. Here we
4884 -- just test if both operands can be negative (that's what the
4885 -- expander does, so we match its logic here).
4887 -- The second case is mod where either operand can be negative.
4888 -- In this case, the back end has to generate additonal tests.
4890 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4892 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
4894 Check_Restriction (No_Implicit_Conditionals, N);
4900 Check_Unset_Reference (L);
4901 Check_Unset_Reference (R);
4902 end Resolve_Arithmetic_Op;
4908 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
4909 Loc : constant Source_Ptr := Sloc (N);
4910 Subp : constant Node_Id := Name (N);
4918 function Same_Or_Aliased_Subprograms
4920 E : Entity_Id) return Boolean;
4921 -- Returns True if the subprogram entity S is the same as E or else
4922 -- S is an alias of E.
4924 ---------------------------------
4925 -- Same_Or_Aliased_Subprograms --
4926 ---------------------------------
4928 function Same_Or_Aliased_Subprograms
4930 E : Entity_Id) return Boolean
4932 Subp_Alias : constant Entity_Id := Alias (S);
4935 or else (Present (Subp_Alias) and then Subp_Alias = E);
4936 end Same_Or_Aliased_Subprograms;
4938 -- Start of processing for Resolve_Call
4941 -- The context imposes a unique interpretation with type Typ on a
4942 -- procedure or function call. Find the entity of the subprogram that
4943 -- yields the expected type, and propagate the corresponding formal
4944 -- constraints on the actuals. The caller has established that an
4945 -- interpretation exists, and emitted an error if not unique.
4947 -- First deal with the case of a call to an access-to-subprogram,
4948 -- dereference made explicit in Analyze_Call.
4950 if Ekind (Etype (Subp)) = E_Subprogram_Type then
4951 if not Is_Overloaded (Subp) then
4952 Nam := Etype (Subp);
4955 -- Find the interpretation whose type (a subprogram type) has a
4956 -- return type that is compatible with the context. Analysis of
4957 -- the node has established that one exists.
4961 Get_First_Interp (Subp, I, It);
4962 while Present (It.Typ) loop
4963 if Covers (Typ, Etype (It.Typ)) then
4968 Get_Next_Interp (I, It);
4972 raise Program_Error;
4976 -- If the prefix is not an entity, then resolve it
4978 if not Is_Entity_Name (Subp) then
4979 Resolve (Subp, Nam);
4982 -- For an indirect call, we always invalidate checks, since we do not
4983 -- know whether the subprogram is local or global. Yes we could do
4984 -- better here, e.g. by knowing that there are no local subprograms,
4985 -- but it does not seem worth the effort. Similarly, we kill all
4986 -- knowledge of current constant values.
4988 Kill_Current_Values;
4990 -- If this is a procedure call which is really an entry call, do
4991 -- the conversion of the procedure call to an entry call. Protected
4992 -- operations use the same circuitry because the name in the call
4993 -- can be an arbitrary expression with special resolution rules.
4995 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
4996 or else (Is_Entity_Name (Subp)
4997 and then Ekind (Entity (Subp)) = E_Entry)
4999 Resolve_Entry_Call (N, Typ);
5000 Check_Elab_Call (N);
5002 -- Kill checks and constant values, as above for indirect case
5003 -- Who knows what happens when another task is activated?
5005 Kill_Current_Values;
5008 -- Normal subprogram call with name established in Resolve
5010 elsif not (Is_Type (Entity (Subp))) then
5011 Nam := Entity (Subp);
5012 Set_Entity_With_Style_Check (Subp, Nam);
5014 -- Otherwise we must have the case of an overloaded call
5017 pragma Assert (Is_Overloaded (Subp));
5019 -- Initialize Nam to prevent warning (we know it will be assigned
5020 -- in the loop below, but the compiler does not know that).
5024 Get_First_Interp (Subp, I, It);
5025 while Present (It.Typ) loop
5026 if Covers (Typ, It.Typ) then
5028 Set_Entity_With_Style_Check (Subp, Nam);
5032 Get_Next_Interp (I, It);
5036 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
5037 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
5038 and then Nkind (Subp) /= N_Explicit_Dereference
5039 and then Present (Parameter_Associations (N))
5041 -- The prefix is a parameterless function call that returns an access
5042 -- to subprogram. If parameters are present in the current call, add
5043 -- add an explicit dereference. We use the base type here because
5044 -- within an instance these may be subtypes.
5046 -- The dereference is added either in Analyze_Call or here. Should
5047 -- be consolidated ???
5049 Set_Is_Overloaded (Subp, False);
5050 Set_Etype (Subp, Etype (Nam));
5051 Insert_Explicit_Dereference (Subp);
5052 Nam := Designated_Type (Etype (Nam));
5053 Resolve (Subp, Nam);
5056 -- Check that a call to Current_Task does not occur in an entry body
5058 if Is_RTE (Nam, RE_Current_Task) then
5067 -- Exclude calls that occur within the default of a formal
5068 -- parameter of the entry, since those are evaluated outside
5071 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
5073 if Nkind (P) = N_Entry_Body
5074 or else (Nkind (P) = N_Subprogram_Body
5075 and then Is_Entry_Barrier_Function (P))
5079 ("?& should not be used in entry body (RM C.7(17))",
5082 ("\Program_Error will be raised at run time?", N, Nam);
5084 Make_Raise_Program_Error (Loc,
5085 Reason => PE_Current_Task_In_Entry_Body));
5086 Set_Etype (N, Rtype);
5093 -- Check that a procedure call does not occur in the context of the
5094 -- entry call statement of a conditional or timed entry call. Note that
5095 -- the case of a call to a subprogram renaming of an entry will also be
5096 -- rejected. The test for N not being an N_Entry_Call_Statement is
5097 -- defensive, covering the possibility that the processing of entry
5098 -- calls might reach this point due to later modifications of the code
5101 if Nkind (Parent (N)) = N_Entry_Call_Alternative
5102 and then Nkind (N) /= N_Entry_Call_Statement
5103 and then Entry_Call_Statement (Parent (N)) = N
5105 if Ada_Version < Ada_2005 then
5106 Error_Msg_N ("entry call required in select statement", N);
5108 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5109 -- for a procedure_or_entry_call, the procedure_name or
5110 -- procedure_prefix of the procedure_call_statement shall denote
5111 -- an entry renamed by a procedure, or (a view of) a primitive
5112 -- subprogram of a limited interface whose first parameter is
5113 -- a controlling parameter.
5115 elsif Nkind (N) = N_Procedure_Call_Statement
5116 and then not Is_Renamed_Entry (Nam)
5117 and then not Is_Controlling_Limited_Procedure (Nam)
5120 ("entry call or dispatching primitive of interface required", N);
5124 -- Check that this is not a call to a protected procedure or entry from
5125 -- within a protected function.
5127 if Ekind (Current_Scope) = E_Function
5128 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
5129 and then Ekind (Nam) /= E_Function
5130 and then Scope (Nam) = Scope (Current_Scope)
5132 Error_Msg_N ("within protected function, protected " &
5133 "object is constant", N);
5134 Error_Msg_N ("\cannot call operation that may modify it", N);
5137 -- Freeze the subprogram name if not in a spec-expression. Note that we
5138 -- freeze procedure calls as well as function calls. Procedure calls are
5139 -- not frozen according to the rules (RM 13.14(14)) because it is
5140 -- impossible to have a procedure call to a non-frozen procedure in pure
5141 -- Ada, but in the code that we generate in the expander, this rule
5142 -- needs extending because we can generate procedure calls that need
5145 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
5146 Freeze_Expression (Subp);
5149 -- For a predefined operator, the type of the result is the type imposed
5150 -- by context, except for a predefined operation on universal fixed.
5151 -- Otherwise The type of the call is the type returned by the subprogram
5154 if Is_Predefined_Op (Nam) then
5155 if Etype (N) /= Universal_Fixed then
5159 -- If the subprogram returns an array type, and the context requires the
5160 -- component type of that array type, the node is really an indexing of
5161 -- the parameterless call. Resolve as such. A pathological case occurs
5162 -- when the type of the component is an access to the array type. In
5163 -- this case the call is truly ambiguous.
5165 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
5167 ((Is_Array_Type (Etype (Nam))
5168 and then Covers (Typ, Component_Type (Etype (Nam))))
5169 or else (Is_Access_Type (Etype (Nam))
5170 and then Is_Array_Type (Designated_Type (Etype (Nam)))
5173 Component_Type (Designated_Type (Etype (Nam))))))
5176 Index_Node : Node_Id;
5178 Ret_Type : constant Entity_Id := Etype (Nam);
5181 if Is_Access_Type (Ret_Type)
5182 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
5185 ("cannot disambiguate function call and indexing", N);
5187 New_Subp := Relocate_Node (Subp);
5188 Set_Entity (Subp, Nam);
5190 if (Is_Array_Type (Ret_Type)
5191 and then Component_Type (Ret_Type) /= Any_Type)
5193 (Is_Access_Type (Ret_Type)
5195 Component_Type (Designated_Type (Ret_Type)) /= Any_Type)
5197 if Needs_No_Actuals (Nam) then
5199 -- Indexed call to a parameterless function
5202 Make_Indexed_Component (Loc,
5204 Make_Function_Call (Loc,
5206 Expressions => Parameter_Associations (N));
5208 -- An Ada 2005 prefixed call to a primitive operation
5209 -- whose first parameter is the prefix. This prefix was
5210 -- prepended to the parameter list, which is actually a
5211 -- list of indexes. Remove the prefix in order to build
5212 -- the proper indexed component.
5215 Make_Indexed_Component (Loc,
5217 Make_Function_Call (Loc,
5219 Parameter_Associations =>
5221 (Remove_Head (Parameter_Associations (N)))),
5222 Expressions => Parameter_Associations (N));
5225 -- Preserve the parenthesis count of the node
5227 Set_Paren_Count (Index_Node, Paren_Count (N));
5229 -- Since we are correcting a node classification error made
5230 -- by the parser, we call Replace rather than Rewrite.
5232 Replace (N, Index_Node);
5234 Set_Etype (Prefix (N), Ret_Type);
5236 Resolve_Indexed_Component (N, Typ);
5237 Check_Elab_Call (Prefix (N));
5245 Set_Etype (N, Etype (Nam));
5248 -- In the case where the call is to an overloaded subprogram, Analyze
5249 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5250 -- such a case Normalize_Actuals needs to be called once more to order
5251 -- the actuals correctly. Otherwise the call will have the ordering
5252 -- given by the last overloaded subprogram whether this is the correct
5253 -- one being called or not.
5255 if Is_Overloaded (Subp) then
5256 Normalize_Actuals (N, Nam, False, Norm_OK);
5257 pragma Assert (Norm_OK);
5260 -- In any case, call is fully resolved now. Reset Overload flag, to
5261 -- prevent subsequent overload resolution if node is analyzed again
5263 Set_Is_Overloaded (Subp, False);
5264 Set_Is_Overloaded (N, False);
5266 -- If we are calling the current subprogram from immediately within its
5267 -- body, then that is the case where we can sometimes detect cases of
5268 -- infinite recursion statically. Do not try this in case restriction
5269 -- No_Recursion is in effect anyway, and do it only for source calls.
5271 if Comes_From_Source (N) then
5272 Scop := Current_Scope;
5274 -- Issue warning for possible infinite recursion in the absence
5275 -- of the No_Recursion restriction.
5277 if Same_Or_Aliased_Subprograms (Nam, Scop)
5278 and then not Restriction_Active (No_Recursion)
5279 and then Check_Infinite_Recursion (N)
5281 -- Here we detected and flagged an infinite recursion, so we do
5282 -- not need to test the case below for further warnings. Also we
5283 -- are all done if we now have a raise SE node.
5285 if Nkind (N) = N_Raise_Storage_Error then
5289 -- If call is to immediately containing subprogram, then check for
5290 -- the case of a possible run-time detectable infinite recursion.
5293 Scope_Loop : while Scop /= Standard_Standard loop
5294 if Same_Or_Aliased_Subprograms (Nam, Scop) then
5296 -- Although in general case, recursion is not statically
5297 -- checkable, the case of calling an immediately containing
5298 -- subprogram is easy to catch.
5300 Check_Restriction (No_Recursion, N);
5302 -- If the recursive call is to a parameterless subprogram,
5303 -- then even if we can't statically detect infinite
5304 -- recursion, this is pretty suspicious, and we output a
5305 -- warning. Furthermore, we will try later to detect some
5306 -- cases here at run time by expanding checking code (see
5307 -- Detect_Infinite_Recursion in package Exp_Ch6).
5309 -- If the recursive call is within a handler, do not emit a
5310 -- warning, because this is a common idiom: loop until input
5311 -- is correct, catch illegal input in handler and restart.
5313 if No (First_Formal (Nam))
5314 and then Etype (Nam) = Standard_Void_Type
5315 and then not Error_Posted (N)
5316 and then Nkind (Parent (N)) /= N_Exception_Handler
5318 -- For the case of a procedure call. We give the message
5319 -- only if the call is the first statement in a sequence
5320 -- of statements, or if all previous statements are
5321 -- simple assignments. This is simply a heuristic to
5322 -- decrease false positives, without losing too many good
5323 -- warnings. The idea is that these previous statements
5324 -- may affect global variables the procedure depends on.
5326 if Nkind (N) = N_Procedure_Call_Statement
5327 and then Is_List_Member (N)
5333 while Present (P) loop
5334 if Nkind (P) /= N_Assignment_Statement then
5343 -- Do not give warning if we are in a conditional context
5346 K : constant Node_Kind := Nkind (Parent (N));
5348 if (K = N_Loop_Statement
5349 and then Present (Iteration_Scheme (Parent (N))))
5350 or else K = N_If_Statement
5351 or else K = N_Elsif_Part
5352 or else K = N_Case_Statement_Alternative
5358 -- Here warning is to be issued
5360 Set_Has_Recursive_Call (Nam);
5362 ("?possible infinite recursion!", N);
5364 ("\?Storage_Error may be raised at run time!", N);
5370 Scop := Scope (Scop);
5371 end loop Scope_Loop;
5375 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5377 Check_Obsolescent_2005_Entity (Nam, Subp);
5379 -- If subprogram name is a predefined operator, it was given in
5380 -- functional notation. Replace call node with operator node, so
5381 -- that actuals can be resolved appropriately.
5383 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5384 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5387 elsif Present (Alias (Nam))
5388 and then Is_Predefined_Op (Alias (Nam))
5390 Resolve_Actuals (N, Nam);
5391 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5395 -- Create a transient scope if the resulting type requires it
5397 -- There are several notable exceptions:
5399 -- a) In init procs, the transient scope overhead is not needed, and is
5400 -- even incorrect when the call is a nested initialization call for a
5401 -- component whose expansion may generate adjust calls. However, if the
5402 -- call is some other procedure call within an initialization procedure
5403 -- (for example a call to Create_Task in the init_proc of the task
5404 -- run-time record) a transient scope must be created around this call.
5406 -- b) Enumeration literal pseudo-calls need no transient scope
5408 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5409 -- functions) do not use the secondary stack even though the return
5410 -- type may be unconstrained.
5412 -- d) Calls to a build-in-place function, since such functions may
5413 -- allocate their result directly in a target object, and cases where
5414 -- the result does get allocated in the secondary stack are checked for
5415 -- within the specialized Exp_Ch6 procedures for expanding those
5416 -- build-in-place calls.
5418 -- e) If the subprogram is marked Inline_Always, then even if it returns
5419 -- an unconstrained type the call does not require use of the secondary
5420 -- stack. However, inlining will only take place if the body to inline
5421 -- is already present. It may not be available if e.g. the subprogram is
5422 -- declared in a child instance.
5424 -- If this is an initialization call for a type whose construction
5425 -- uses the secondary stack, and it is not a nested call to initialize
5426 -- a component, we do need to create a transient scope for it. We
5427 -- check for this by traversing the type in Check_Initialization_Call.
5430 and then Has_Pragma_Inline_Always (Nam)
5431 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5432 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5436 elsif Ekind (Nam) = E_Enumeration_Literal
5437 or else Is_Build_In_Place_Function (Nam)
5438 or else Is_Intrinsic_Subprogram (Nam)
5442 elsif Expander_Active
5443 and then Is_Type (Etype (Nam))
5444 and then Requires_Transient_Scope (Etype (Nam))
5446 (not Within_Init_Proc
5448 (not Is_Init_Proc (Nam) and then Ekind (Nam) /= E_Function))
5450 Establish_Transient_Scope (N, Sec_Stack => True);
5452 -- If the call appears within the bounds of a loop, it will
5453 -- be rewritten and reanalyzed, nothing left to do here.
5455 if Nkind (N) /= N_Function_Call then
5459 elsif Is_Init_Proc (Nam)
5460 and then not Within_Init_Proc
5462 Check_Initialization_Call (N, Nam);
5465 -- A protected function cannot be called within the definition of the
5466 -- enclosing protected type.
5468 if Is_Protected_Type (Scope (Nam))
5469 and then In_Open_Scopes (Scope (Nam))
5470 and then not Has_Completion (Scope (Nam))
5473 ("& cannot be called before end of protected definition", N, Nam);
5476 -- Propagate interpretation to actuals, and add default expressions
5479 if Present (First_Formal (Nam)) then
5480 Resolve_Actuals (N, Nam);
5482 -- Overloaded literals are rewritten as function calls, for purpose of
5483 -- resolution. After resolution, we can replace the call with the
5486 elsif Ekind (Nam) = E_Enumeration_Literal then
5487 Copy_Node (Subp, N);
5488 Resolve_Entity_Name (N, Typ);
5490 -- Avoid validation, since it is a static function call
5492 Generate_Reference (Nam, Subp);
5496 -- If the subprogram is not global, then kill all saved values and
5497 -- checks. This is a bit conservative, since in many cases we could do
5498 -- better, but it is not worth the effort. Similarly, we kill constant
5499 -- values. However we do not need to do this for internal entities
5500 -- (unless they are inherited user-defined subprograms), since they
5501 -- are not in the business of molesting local values.
5503 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5504 -- kill all checks and values for calls to global subprograms. This
5505 -- takes care of the case where an access to a local subprogram is
5506 -- taken, and could be passed directly or indirectly and then called
5507 -- from almost any context.
5509 -- Note: we do not do this step till after resolving the actuals. That
5510 -- way we still take advantage of the current value information while
5511 -- scanning the actuals.
5513 -- We suppress killing values if we are processing the nodes associated
5514 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5515 -- type kills all the values as part of analyzing the code that
5516 -- initializes the dispatch tables.
5518 if Inside_Freezing_Actions = 0
5519 and then (not Is_Library_Level_Entity (Nam)
5520 or else Suppress_Value_Tracking_On_Call
5521 (Nearest_Dynamic_Scope (Current_Scope)))
5522 and then (Comes_From_Source (Nam)
5523 or else (Present (Alias (Nam))
5524 and then Comes_From_Source (Alias (Nam))))
5526 Kill_Current_Values;
5529 -- If we are warning about unread OUT parameters, this is the place to
5530 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5531 -- after the above call to Kill_Current_Values (since that call clears
5532 -- the Last_Assignment field of all local variables).
5534 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5535 and then Comes_From_Source (N)
5536 and then In_Extended_Main_Source_Unit (N)
5543 F := First_Formal (Nam);
5544 A := First_Actual (N);
5545 while Present (F) and then Present (A) loop
5546 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter)
5547 and then Warn_On_Modified_As_Out_Parameter (F)
5548 and then Is_Entity_Name (A)
5549 and then Present (Entity (A))
5550 and then Comes_From_Source (N)
5551 and then Safe_To_Capture_Value (N, Entity (A))
5553 Set_Last_Assignment (Entity (A), A);
5562 -- If the subprogram is a primitive operation, check whether or not
5563 -- it is a correct dispatching call.
5565 if Is_Overloadable (Nam)
5566 and then Is_Dispatching_Operation (Nam)
5568 Check_Dispatching_Call (N);
5570 elsif Ekind (Nam) /= E_Subprogram_Type
5571 and then Is_Abstract_Subprogram (Nam)
5572 and then not In_Instance
5574 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5577 -- If this is a dispatching call, generate the appropriate reference,
5578 -- for better source navigation in GPS.
5580 if Is_Overloadable (Nam)
5581 and then Present (Controlling_Argument (N))
5583 Generate_Reference (Nam, Subp, 'R');
5585 -- Normal case, not a dispatching call. Generate a call reference.
5588 Generate_Reference (Nam, Subp, 's');
5591 if Is_Intrinsic_Subprogram (Nam) then
5592 Check_Intrinsic_Call (N);
5595 -- Check for violation of restriction No_Specific_Termination_Handlers
5596 -- and warn on a potentially blocking call to Abort_Task.
5598 if Is_RTE (Nam, RE_Set_Specific_Handler)
5600 Is_RTE (Nam, RE_Specific_Handler)
5602 Check_Restriction (No_Specific_Termination_Handlers, N);
5604 elsif Is_RTE (Nam, RE_Abort_Task) then
5605 Check_Potentially_Blocking_Operation (N);
5608 -- A call to Ada.Real_Time.Timing_Events.Set_Handler violates
5609 -- restriction No_Relative_Delay (AI-0211).
5611 if Is_RTE (Nam, RE_Set_Handler) then
5612 Check_Restriction (No_Relative_Delay, N);
5615 -- Issue an error for a call to an eliminated subprogram. We skip this
5616 -- in a spec expression, e.g. a call in a default parameter value, since
5617 -- we are not really doing a call at this time. That's important because
5618 -- the spec expression may itself belong to an eliminated subprogram.
5620 if not In_Spec_Expression then
5621 Check_For_Eliminated_Subprogram (Subp, Nam);
5624 -- All done, evaluate call and deal with elaboration issues
5627 Check_Elab_Call (N);
5628 Warn_On_Overlapping_Actuals (Nam, N);
5631 -----------------------------
5632 -- Resolve_Case_Expression --
5633 -----------------------------
5635 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id) is
5639 Alt := First (Alternatives (N));
5640 while Present (Alt) loop
5641 Resolve (Expression (Alt), Typ);
5646 Eval_Case_Expression (N);
5647 end Resolve_Case_Expression;
5649 -------------------------------
5650 -- Resolve_Character_Literal --
5651 -------------------------------
5653 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5654 B_Typ : constant Entity_Id := Base_Type (Typ);
5658 -- Verify that the character does belong to the type of the context
5660 Set_Etype (N, B_Typ);
5661 Eval_Character_Literal (N);
5663 -- Wide_Wide_Character literals must always be defined, since the set
5664 -- of wide wide character literals is complete, i.e. if a character
5665 -- literal is accepted by the parser, then it is OK for wide wide
5666 -- character (out of range character literals are rejected).
5668 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5671 -- Always accept character literal for type Any_Character, which
5672 -- occurs in error situations and in comparisons of literals, both
5673 -- of which should accept all literals.
5675 elsif B_Typ = Any_Character then
5678 -- For Standard.Character or a type derived from it, check that
5679 -- the literal is in range
5681 elsif Root_Type (B_Typ) = Standard_Character then
5682 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5686 -- For Standard.Wide_Character or a type derived from it, check
5687 -- that the literal is in range
5689 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5690 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5694 -- For Standard.Wide_Wide_Character or a type derived from it, we
5695 -- know the literal is in range, since the parser checked!
5697 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5700 -- If the entity is already set, this has already been resolved in a
5701 -- generic context, or comes from expansion. Nothing else to do.
5703 elsif Present (Entity (N)) then
5706 -- Otherwise we have a user defined character type, and we can use the
5707 -- standard visibility mechanisms to locate the referenced entity.
5710 C := Current_Entity (N);
5711 while Present (C) loop
5712 if Etype (C) = B_Typ then
5713 Set_Entity_With_Style_Check (N, C);
5714 Generate_Reference (C, N);
5722 -- If we fall through, then the literal does not match any of the
5723 -- entries of the enumeration type. This isn't just a constraint
5724 -- error situation, it is an illegality (see RM 4.2).
5727 ("character not defined for }", N, First_Subtype (B_Typ));
5728 end Resolve_Character_Literal;
5730 ---------------------------
5731 -- Resolve_Comparison_Op --
5732 ---------------------------
5734 -- Context requires a boolean type, and plays no role in resolution.
5735 -- Processing identical to that for equality operators. The result
5736 -- type is the base type, which matters when pathological subtypes of
5737 -- booleans with limited ranges are used.
5739 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5740 L : constant Node_Id := Left_Opnd (N);
5741 R : constant Node_Id := Right_Opnd (N);
5745 -- If this is an intrinsic operation which is not predefined, use the
5746 -- types of its declared arguments to resolve the possibly overloaded
5747 -- operands. Otherwise the operands are unambiguous and specify the
5750 if Scope (Entity (N)) /= Standard_Standard then
5751 T := Etype (First_Entity (Entity (N)));
5754 T := Find_Unique_Type (L, R);
5756 if T = Any_Fixed then
5757 T := Unique_Fixed_Point_Type (L);
5761 Set_Etype (N, Base_Type (Typ));
5762 Generate_Reference (T, N, ' ');
5764 -- Skip remaining processing if already set to Any_Type
5766 if T = Any_Type then
5770 -- Deal with other error cases
5772 if T = Any_String or else
5773 T = Any_Composite or else
5776 if T = Any_Character then
5777 Ambiguous_Character (L);
5779 Error_Msg_N ("ambiguous operands for comparison", N);
5782 Set_Etype (N, Any_Type);
5786 -- Resolve the operands if types OK
5790 Check_Unset_Reference (L);
5791 Check_Unset_Reference (R);
5792 Generate_Operator_Reference (N, T);
5793 Check_Low_Bound_Tested (N);
5795 -- Check comparison on unordered enumeration
5797 if Comes_From_Source (N)
5798 and then Bad_Unordered_Enumeration_Reference (N, Etype (L))
5800 Error_Msg_N ("comparison on unordered enumeration type?", N);
5803 -- Evaluate the relation (note we do this after the above check
5804 -- since this Eval call may change N to True/False.
5806 Eval_Relational_Op (N);
5807 end Resolve_Comparison_Op;
5809 ------------------------------------
5810 -- Resolve_Conditional_Expression --
5811 ------------------------------------
5813 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
5814 Condition : constant Node_Id := First (Expressions (N));
5815 Then_Expr : constant Node_Id := Next (Condition);
5816 Else_Expr : Node_Id := Next (Then_Expr);
5819 Resolve (Condition, Any_Boolean);
5820 Resolve (Then_Expr, Typ);
5822 -- If ELSE expression present, just resolve using the determined type
5824 if Present (Else_Expr) then
5825 Resolve (Else_Expr, Typ);
5827 -- If no ELSE expression is present, root type must be Standard.Boolean
5828 -- and we provide a Standard.True result converted to the appropriate
5829 -- Boolean type (in case it is a derived boolean type).
5831 elsif Root_Type (Typ) = Standard_Boolean then
5833 Convert_To (Typ, New_Occurrence_Of (Standard_True, Sloc (N)));
5834 Analyze_And_Resolve (Else_Expr, Typ);
5835 Append_To (Expressions (N), Else_Expr);
5838 Error_Msg_N ("can only omit ELSE expression in Boolean case", N);
5839 Append_To (Expressions (N), Error);
5843 Eval_Conditional_Expression (N);
5844 end Resolve_Conditional_Expression;
5846 -----------------------------------------
5847 -- Resolve_Discrete_Subtype_Indication --
5848 -----------------------------------------
5850 procedure Resolve_Discrete_Subtype_Indication
5858 Analyze (Subtype_Mark (N));
5859 S := Entity (Subtype_Mark (N));
5861 if Nkind (Constraint (N)) /= N_Range_Constraint then
5862 Error_Msg_N ("expect range constraint for discrete type", N);
5863 Set_Etype (N, Any_Type);
5866 R := Range_Expression (Constraint (N));
5874 if Base_Type (S) /= Base_Type (Typ) then
5876 ("expect subtype of }", N, First_Subtype (Typ));
5878 -- Rewrite the constraint as a range of Typ
5879 -- to allow compilation to proceed further.
5882 Rewrite (Low_Bound (R),
5883 Make_Attribute_Reference (Sloc (Low_Bound (R)),
5884 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5885 Attribute_Name => Name_First));
5886 Rewrite (High_Bound (R),
5887 Make_Attribute_Reference (Sloc (High_Bound (R)),
5888 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5889 Attribute_Name => Name_First));
5893 Set_Etype (N, Etype (R));
5895 -- Additionally, we must check that the bounds are compatible
5896 -- with the given subtype, which might be different from the
5897 -- type of the context.
5899 Apply_Range_Check (R, S);
5901 -- ??? If the above check statically detects a Constraint_Error
5902 -- it replaces the offending bound(s) of the range R with a
5903 -- Constraint_Error node. When the itype which uses these bounds
5904 -- is frozen the resulting call to Duplicate_Subexpr generates
5905 -- a new temporary for the bounds.
5907 -- Unfortunately there are other itypes that are also made depend
5908 -- on these bounds, so when Duplicate_Subexpr is called they get
5909 -- a forward reference to the newly created temporaries and Gigi
5910 -- aborts on such forward references. This is probably sign of a
5911 -- more fundamental problem somewhere else in either the order of
5912 -- itype freezing or the way certain itypes are constructed.
5914 -- To get around this problem we call Remove_Side_Effects right
5915 -- away if either bounds of R are a Constraint_Error.
5918 L : constant Node_Id := Low_Bound (R);
5919 H : constant Node_Id := High_Bound (R);
5922 if Nkind (L) = N_Raise_Constraint_Error then
5923 Remove_Side_Effects (L);
5926 if Nkind (H) = N_Raise_Constraint_Error then
5927 Remove_Side_Effects (H);
5931 Check_Unset_Reference (Low_Bound (R));
5932 Check_Unset_Reference (High_Bound (R));
5935 end Resolve_Discrete_Subtype_Indication;
5937 -------------------------
5938 -- Resolve_Entity_Name --
5939 -------------------------
5941 -- Used to resolve identifiers and expanded names
5943 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
5944 E : constant Entity_Id := Entity (N);
5947 -- If garbage from errors, set to Any_Type and return
5949 if No (E) and then Total_Errors_Detected /= 0 then
5950 Set_Etype (N, Any_Type);
5954 -- Replace named numbers by corresponding literals. Note that this is
5955 -- the one case where Resolve_Entity_Name must reset the Etype, since
5956 -- it is currently marked as universal.
5958 if Ekind (E) = E_Named_Integer then
5960 Eval_Named_Integer (N);
5962 elsif Ekind (E) = E_Named_Real then
5964 Eval_Named_Real (N);
5966 -- For enumeration literals, we need to make sure that a proper style
5967 -- check is done, since such literals are overloaded, and thus we did
5968 -- not do a style check during the first phase of analysis.
5970 elsif Ekind (E) = E_Enumeration_Literal then
5971 Set_Entity_With_Style_Check (N, E);
5972 Eval_Entity_Name (N);
5974 -- Case of subtype name appearing as an operand in expression
5976 elsif Is_Type (E) then
5978 -- Allow use of subtype if it is a concurrent type where we are
5979 -- currently inside the body. This will eventually be expanded into a
5980 -- call to Self (for tasks) or _object (for protected objects). Any
5981 -- other use of a subtype is invalid.
5983 if Is_Concurrent_Type (E)
5984 and then In_Open_Scopes (E)
5988 -- Any other use is an eror
5992 ("invalid use of subtype mark in expression or call", N);
5995 -- Check discriminant use if entity is discriminant in current scope,
5996 -- i.e. discriminant of record or concurrent type currently being
5997 -- analyzed. Uses in corresponding body are unrestricted.
5999 elsif Ekind (E) = E_Discriminant
6000 and then Scope (E) = Current_Scope
6001 and then not Has_Completion (Current_Scope)
6003 Check_Discriminant_Use (N);
6005 -- A parameterless generic function cannot appear in a context that
6006 -- requires resolution.
6008 elsif Ekind (E) = E_Generic_Function then
6009 Error_Msg_N ("illegal use of generic function", N);
6011 elsif Ekind (E) = E_Out_Parameter
6012 and then Ada_Version = Ada_83
6013 and then (Nkind (Parent (N)) in N_Op
6014 or else (Nkind (Parent (N)) = N_Assignment_Statement
6015 and then N = Expression (Parent (N)))
6016 or else Nkind (Parent (N)) = N_Explicit_Dereference)
6018 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
6020 -- In all other cases, just do the possible static evaluation
6023 -- A deferred constant that appears in an expression must have a
6024 -- completion, unless it has been removed by in-place expansion of
6027 if Ekind (E) = E_Constant
6028 and then Comes_From_Source (E)
6029 and then No (Constant_Value (E))
6030 and then Is_Frozen (Etype (E))
6031 and then not In_Spec_Expression
6032 and then not Is_Imported (E)
6034 if No_Initialization (Parent (E))
6035 or else (Present (Full_View (E))
6036 and then No_Initialization (Parent (Full_View (E))))
6041 "deferred constant is frozen before completion", N);
6045 Eval_Entity_Name (N);
6047 end Resolve_Entity_Name;
6053 procedure Resolve_Entry (Entry_Name : Node_Id) is
6054 Loc : constant Source_Ptr := Sloc (Entry_Name);
6062 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
6063 -- If the bounds of the entry family being called depend on task
6064 -- discriminants, build a new index subtype where a discriminant is
6065 -- replaced with the value of the discriminant of the target task.
6066 -- The target task is the prefix of the entry name in the call.
6068 -----------------------
6069 -- Actual_Index_Type --
6070 -----------------------
6072 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
6073 Typ : constant Entity_Id := Entry_Index_Type (E);
6074 Tsk : constant Entity_Id := Scope (E);
6075 Lo : constant Node_Id := Type_Low_Bound (Typ);
6076 Hi : constant Node_Id := Type_High_Bound (Typ);
6079 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
6080 -- If the bound is given by a discriminant, replace with a reference
6081 -- to the discriminant of the same name in the target task. If the
6082 -- entry name is the target of a requeue statement and the entry is
6083 -- in the current protected object, the bound to be used is the
6084 -- discriminal of the object (see Apply_Range_Checks for details of
6085 -- the transformation).
6087 -----------------------------
6088 -- Actual_Discriminant_Ref --
6089 -----------------------------
6091 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
6092 Typ : constant Entity_Id := Etype (Bound);
6096 Remove_Side_Effects (Bound);
6098 if not Is_Entity_Name (Bound)
6099 or else Ekind (Entity (Bound)) /= E_Discriminant
6103 elsif Is_Protected_Type (Tsk)
6104 and then In_Open_Scopes (Tsk)
6105 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
6107 -- Note: here Bound denotes a discriminant of the corresponding
6108 -- record type tskV, whose discriminal is a formal of the
6109 -- init-proc tskVIP. What we want is the body discriminal,
6110 -- which is associated to the discriminant of the original
6111 -- concurrent type tsk.
6113 return New_Occurrence_Of
6114 (Find_Body_Discriminal (Entity (Bound)), Loc);
6118 Make_Selected_Component (Loc,
6119 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
6120 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
6125 end Actual_Discriminant_Ref;
6127 -- Start of processing for Actual_Index_Type
6130 if not Has_Discriminants (Tsk)
6131 or else (not Is_Entity_Name (Lo)
6133 not Is_Entity_Name (Hi))
6135 return Entry_Index_Type (E);
6138 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
6139 Set_Etype (New_T, Base_Type (Typ));
6140 Set_Size_Info (New_T, Typ);
6141 Set_RM_Size (New_T, RM_Size (Typ));
6142 Set_Scalar_Range (New_T,
6143 Make_Range (Sloc (Entry_Name),
6144 Low_Bound => Actual_Discriminant_Ref (Lo),
6145 High_Bound => Actual_Discriminant_Ref (Hi)));
6149 end Actual_Index_Type;
6151 -- Start of processing of Resolve_Entry
6154 -- Find name of entry being called, and resolve prefix of name
6155 -- with its own type. The prefix can be overloaded, and the name
6156 -- and signature of the entry must be taken into account.
6158 if Nkind (Entry_Name) = N_Indexed_Component then
6160 -- Case of dealing with entry family within the current tasks
6162 E_Name := Prefix (Entry_Name);
6165 E_Name := Entry_Name;
6168 if Is_Entity_Name (E_Name) then
6170 -- Entry call to an entry (or entry family) in the current task. This
6171 -- is legal even though the task will deadlock. Rewrite as call to
6174 -- This can also be a call to an entry in an enclosing task. If this
6175 -- is a single task, we have to retrieve its name, because the scope
6176 -- of the entry is the task type, not the object. If the enclosing
6177 -- task is a task type, the identity of the task is given by its own
6180 -- Finally this can be a requeue on an entry of the same task or
6181 -- protected object.
6183 S := Scope (Entity (E_Name));
6185 for J in reverse 0 .. Scope_Stack.Last loop
6186 if Is_Task_Type (Scope_Stack.Table (J).Entity)
6187 and then not Comes_From_Source (S)
6189 -- S is an enclosing task or protected object. The concurrent
6190 -- declaration has been converted into a type declaration, and
6191 -- the object itself has an object declaration that follows
6192 -- the type in the same declarative part.
6194 Tsk := Next_Entity (S);
6195 while Etype (Tsk) /= S loop
6202 elsif S = Scope_Stack.Table (J).Entity then
6204 -- Call to current task. Will be transformed into call to Self
6212 Make_Selected_Component (Loc,
6213 Prefix => New_Occurrence_Of (S, Loc),
6215 New_Occurrence_Of (Entity (E_Name), Loc));
6216 Rewrite (E_Name, New_N);
6219 elsif Nkind (Entry_Name) = N_Selected_Component
6220 and then Is_Overloaded (Prefix (Entry_Name))
6222 -- Use the entry name (which must be unique at this point) to find
6223 -- the prefix that returns the corresponding task type or protected
6227 Pref : constant Node_Id := Prefix (Entry_Name);
6228 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
6233 Get_First_Interp (Pref, I, It);
6234 while Present (It.Typ) loop
6235 if Scope (Ent) = It.Typ then
6236 Set_Etype (Pref, It.Typ);
6240 Get_Next_Interp (I, It);
6245 if Nkind (Entry_Name) = N_Selected_Component then
6246 Resolve (Prefix (Entry_Name));
6248 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6249 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6250 Resolve (Prefix (Prefix (Entry_Name)));
6251 Index := First (Expressions (Entry_Name));
6252 Resolve (Index, Entry_Index_Type (Nam));
6254 -- Up to this point the expression could have been the actual in a
6255 -- simple entry call, and be given by a named association.
6257 if Nkind (Index) = N_Parameter_Association then
6258 Error_Msg_N ("expect expression for entry index", Index);
6260 Apply_Range_Check (Index, Actual_Index_Type (Nam));
6265 ------------------------
6266 -- Resolve_Entry_Call --
6267 ------------------------
6269 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
6270 Entry_Name : constant Node_Id := Name (N);
6271 Loc : constant Source_Ptr := Sloc (Entry_Name);
6273 First_Named : Node_Id;
6280 -- We kill all checks here, because it does not seem worth the effort to
6281 -- do anything better, an entry call is a big operation.
6285 -- Processing of the name is similar for entry calls and protected
6286 -- operation calls. Once the entity is determined, we can complete
6287 -- the resolution of the actuals.
6289 -- The selector may be overloaded, in the case of a protected object
6290 -- with overloaded functions. The type of the context is used for
6293 if Nkind (Entry_Name) = N_Selected_Component
6294 and then Is_Overloaded (Selector_Name (Entry_Name))
6295 and then Typ /= Standard_Void_Type
6302 Get_First_Interp (Selector_Name (Entry_Name), I, It);
6303 while Present (It.Typ) loop
6304 if Covers (Typ, It.Typ) then
6305 Set_Entity (Selector_Name (Entry_Name), It.Nam);
6306 Set_Etype (Entry_Name, It.Typ);
6308 Generate_Reference (It.Typ, N, ' ');
6311 Get_Next_Interp (I, It);
6316 Resolve_Entry (Entry_Name);
6318 if Nkind (Entry_Name) = N_Selected_Component then
6320 -- Simple entry call
6322 Nam := Entity (Selector_Name (Entry_Name));
6323 Obj := Prefix (Entry_Name);
6324 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
6326 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6328 -- Call to member of entry family
6330 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6331 Obj := Prefix (Prefix (Entry_Name));
6332 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
6335 -- We cannot in general check the maximum depth of protected entry
6336 -- calls at compile time. But we can tell that any protected entry
6337 -- call at all violates a specified nesting depth of zero.
6339 if Is_Protected_Type (Scope (Nam)) then
6340 Check_Restriction (Max_Entry_Queue_Length, N);
6343 -- Use context type to disambiguate a protected function that can be
6344 -- called without actuals and that returns an array type, and where
6345 -- the argument list may be an indexing of the returned value.
6347 if Ekind (Nam) = E_Function
6348 and then Needs_No_Actuals (Nam)
6349 and then Present (Parameter_Associations (N))
6351 ((Is_Array_Type (Etype (Nam))
6352 and then Covers (Typ, Component_Type (Etype (Nam))))
6354 or else (Is_Access_Type (Etype (Nam))
6355 and then Is_Array_Type (Designated_Type (Etype (Nam)))
6356 and then Covers (Typ,
6357 Component_Type (Designated_Type (Etype (Nam))))))
6360 Index_Node : Node_Id;
6364 Make_Indexed_Component (Loc,
6366 Make_Function_Call (Loc,
6367 Name => Relocate_Node (Entry_Name)),
6368 Expressions => Parameter_Associations (N));
6370 -- Since we are correcting a node classification error made by
6371 -- the parser, we call Replace rather than Rewrite.
6373 Replace (N, Index_Node);
6374 Set_Etype (Prefix (N), Etype (Nam));
6376 Resolve_Indexed_Component (N, Typ);
6381 if Ekind_In (Nam, E_Entry, E_Entry_Family)
6382 and then Present (PPC_Wrapper (Nam))
6383 and then Current_Scope /= PPC_Wrapper (Nam)
6385 -- Rewrite as call to the precondition wrapper, adding the task
6386 -- object to the list of actuals. If the call is to a member of
6387 -- an entry family, include the index as well.
6391 New_Actuals : List_Id;
6393 New_Actuals := New_List (Obj);
6395 if Nkind (Entry_Name) = N_Indexed_Component then
6396 Append_To (New_Actuals,
6397 New_Copy_Tree (First (Expressions (Entry_Name))));
6400 Append_List (Parameter_Associations (N), New_Actuals);
6402 Make_Procedure_Call_Statement (Loc,
6404 New_Occurrence_Of (PPC_Wrapper (Nam), Loc),
6405 Parameter_Associations => New_Actuals);
6406 Rewrite (N, New_Call);
6407 Analyze_And_Resolve (N);
6412 -- The operation name may have been overloaded. Order the actuals
6413 -- according to the formals of the resolved entity, and set the
6414 -- return type to that of the operation.
6417 Normalize_Actuals (N, Nam, False, Norm_OK);
6418 pragma Assert (Norm_OK);
6419 Set_Etype (N, Etype (Nam));
6422 Resolve_Actuals (N, Nam);
6424 -- Create a call reference to the entry
6426 Generate_Reference (Nam, Entry_Name, 's');
6428 if Ekind_In (Nam, E_Entry, E_Entry_Family) then
6429 Check_Potentially_Blocking_Operation (N);
6432 -- Verify that a procedure call cannot masquerade as an entry
6433 -- call where an entry call is expected.
6435 if Ekind (Nam) = E_Procedure then
6436 if Nkind (Parent (N)) = N_Entry_Call_Alternative
6437 and then N = Entry_Call_Statement (Parent (N))
6439 Error_Msg_N ("entry call required in select statement", N);
6441 elsif Nkind (Parent (N)) = N_Triggering_Alternative
6442 and then N = Triggering_Statement (Parent (N))
6444 Error_Msg_N ("triggering statement cannot be procedure call", N);
6446 elsif Ekind (Scope (Nam)) = E_Task_Type
6447 and then not In_Open_Scopes (Scope (Nam))
6449 Error_Msg_N ("task has no entry with this name", Entry_Name);
6453 -- After resolution, entry calls and protected procedure calls are
6454 -- changed into entry calls, for expansion. The structure of the node
6455 -- does not change, so it can safely be done in place. Protected
6456 -- function calls must keep their structure because they are
6459 if Ekind (Nam) /= E_Function then
6461 -- A protected operation that is not a function may modify the
6462 -- corresponding object, and cannot apply to a constant. If this
6463 -- is an internal call, the prefix is the type itself.
6465 if Is_Protected_Type (Scope (Nam))
6466 and then not Is_Variable (Obj)
6467 and then (not Is_Entity_Name (Obj)
6468 or else not Is_Type (Entity (Obj)))
6471 ("prefix of protected procedure or entry call must be variable",
6475 Actuals := Parameter_Associations (N);
6476 First_Named := First_Named_Actual (N);
6479 Make_Entry_Call_Statement (Loc,
6481 Parameter_Associations => Actuals));
6483 Set_First_Named_Actual (N, First_Named);
6484 Set_Analyzed (N, True);
6486 -- Protected functions can return on the secondary stack, in which
6487 -- case we must trigger the transient scope mechanism.
6489 elsif Expander_Active
6490 and then Requires_Transient_Scope (Etype (Nam))
6492 Establish_Transient_Scope (N, Sec_Stack => True);
6494 end Resolve_Entry_Call;
6496 -------------------------
6497 -- Resolve_Equality_Op --
6498 -------------------------
6500 -- Both arguments must have the same type, and the boolean context does
6501 -- not participate in the resolution. The first pass verifies that the
6502 -- interpretation is not ambiguous, and the type of the left argument is
6503 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6504 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6505 -- though they carry a single (universal) type. Diagnose this case here.
6507 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6508 L : constant Node_Id := Left_Opnd (N);
6509 R : constant Node_Id := Right_Opnd (N);
6510 T : Entity_Id := Find_Unique_Type (L, R);
6512 procedure Check_Conditional_Expression (Cond : Node_Id);
6513 -- The resolution rule for conditional expressions requires that each
6514 -- such must have a unique type. This means that if several dependent
6515 -- expressions are of a non-null anonymous access type, and the context
6516 -- does not impose an expected type (as can be the case in an equality
6517 -- operation) the expression must be rejected.
6519 function Find_Unique_Access_Type return Entity_Id;
6520 -- In the case of allocators, make a last-ditch attempt to find a single
6521 -- access type with the right designated type. This is semantically
6522 -- dubious, and of no interest to any real code, but c48008a makes it
6525 ----------------------------------
6526 -- Check_Conditional_Expression --
6527 ----------------------------------
6529 procedure Check_Conditional_Expression (Cond : Node_Id) is
6530 Then_Expr : Node_Id;
6531 Else_Expr : Node_Id;
6534 if Nkind (Cond) = N_Conditional_Expression then
6535 Then_Expr := Next (First (Expressions (Cond)));
6536 Else_Expr := Next (Then_Expr);
6538 if Nkind (Then_Expr) /= N_Null
6539 and then Nkind (Else_Expr) /= N_Null
6542 ("cannot determine type of conditional expression", Cond);
6545 end Check_Conditional_Expression;
6547 -----------------------------
6548 -- Find_Unique_Access_Type --
6549 -----------------------------
6551 function Find_Unique_Access_Type return Entity_Id is
6557 if Ekind (Etype (R)) = E_Allocator_Type then
6558 Acc := Designated_Type (Etype (R));
6559 elsif Ekind (Etype (L)) = E_Allocator_Type then
6560 Acc := Designated_Type (Etype (L));
6566 while S /= Standard_Standard loop
6567 E := First_Entity (S);
6568 while Present (E) loop
6570 and then Is_Access_Type (E)
6571 and then Ekind (E) /= E_Allocator_Type
6572 and then Designated_Type (E) = Base_Type (Acc)
6584 end Find_Unique_Access_Type;
6586 -- Start of processing for Resolve_Equality_Op
6589 Set_Etype (N, Base_Type (Typ));
6590 Generate_Reference (T, N, ' ');
6592 if T = Any_Fixed then
6593 T := Unique_Fixed_Point_Type (L);
6596 if T /= Any_Type then
6598 or else T = Any_Composite
6599 or else T = Any_Character
6601 if T = Any_Character then
6602 Ambiguous_Character (L);
6604 Error_Msg_N ("ambiguous operands for equality", N);
6607 Set_Etype (N, Any_Type);
6610 elsif T = Any_Access
6611 or else Ekind_In (T, E_Allocator_Type, E_Access_Attribute_Type)
6613 T := Find_Unique_Access_Type;
6616 Error_Msg_N ("ambiguous operands for equality", N);
6617 Set_Etype (N, Any_Type);
6621 -- Conditional expressions must have a single type, and if the
6622 -- context does not impose one the dependent expressions cannot
6623 -- be anonymous access types.
6625 elsif Ada_Version >= Ada_2012
6626 and then Ekind_In (Etype (L), E_Anonymous_Access_Type,
6627 E_Anonymous_Access_Subprogram_Type)
6628 and then Ekind_In (Etype (R), E_Anonymous_Access_Type,
6629 E_Anonymous_Access_Subprogram_Type)
6631 Check_Conditional_Expression (L);
6632 Check_Conditional_Expression (R);
6638 -- If the unique type is a class-wide type then it will be expanded
6639 -- into a dispatching call to the predefined primitive. Therefore we
6640 -- check here for potential violation of such restriction.
6642 if Is_Class_Wide_Type (T) then
6643 Check_Restriction (No_Dispatching_Calls, N);
6646 if Warn_On_Redundant_Constructs
6647 and then Comes_From_Source (N)
6648 and then Is_Entity_Name (R)
6649 and then Entity (R) = Standard_True
6650 and then Comes_From_Source (R)
6652 Error_Msg_N -- CODEFIX
6653 ("?comparison with True is redundant!", R);
6656 Check_Unset_Reference (L);
6657 Check_Unset_Reference (R);
6658 Generate_Operator_Reference (N, T);
6659 Check_Low_Bound_Tested (N);
6661 -- If this is an inequality, it may be the implicit inequality
6662 -- created for a user-defined operation, in which case the corres-
6663 -- ponding equality operation is not intrinsic, and the operation
6664 -- cannot be constant-folded. Else fold.
6666 if Nkind (N) = N_Op_Eq
6667 or else Comes_From_Source (Entity (N))
6668 or else Ekind (Entity (N)) = E_Operator
6669 or else Is_Intrinsic_Subprogram
6670 (Corresponding_Equality (Entity (N)))
6672 Eval_Relational_Op (N);
6674 elsif Nkind (N) = N_Op_Ne
6675 and then Is_Abstract_Subprogram (Entity (N))
6677 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6680 -- Ada 2005: If one operand is an anonymous access type, convert the
6681 -- other operand to it, to ensure that the underlying types match in
6682 -- the back-end. Same for access_to_subprogram, and the conversion
6683 -- verifies that the types are subtype conformant.
6685 -- We apply the same conversion in the case one of the operands is a
6686 -- private subtype of the type of the other.
6688 -- Why the Expander_Active test here ???
6692 (Ekind_In (T, E_Anonymous_Access_Type,
6693 E_Anonymous_Access_Subprogram_Type)
6694 or else Is_Private_Type (T))
6696 if Etype (L) /= T then
6698 Make_Unchecked_Type_Conversion (Sloc (L),
6699 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6700 Expression => Relocate_Node (L)));
6701 Analyze_And_Resolve (L, T);
6704 if (Etype (R)) /= T then
6706 Make_Unchecked_Type_Conversion (Sloc (R),
6707 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6708 Expression => Relocate_Node (R)));
6709 Analyze_And_Resolve (R, T);
6713 end Resolve_Equality_Op;
6715 ----------------------------------
6716 -- Resolve_Explicit_Dereference --
6717 ----------------------------------
6719 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6720 Loc : constant Source_Ptr := Sloc (N);
6722 P : constant Node_Id := Prefix (N);
6727 Check_Fully_Declared_Prefix (Typ, P);
6729 if Is_Overloaded (P) then
6731 -- Use the context type to select the prefix that has the correct
6734 Get_First_Interp (P, I, It);
6735 while Present (It.Typ) loop
6736 exit when Is_Access_Type (It.Typ)
6737 and then Covers (Typ, Designated_Type (It.Typ));
6738 Get_Next_Interp (I, It);
6741 if Present (It.Typ) then
6742 Resolve (P, It.Typ);
6744 -- If no interpretation covers the designated type of the prefix,
6745 -- this is the pathological case where not all implementations of
6746 -- the prefix allow the interpretation of the node as a call. Now
6747 -- that the expected type is known, Remove other interpretations
6748 -- from prefix, rewrite it as a call, and resolve again, so that
6749 -- the proper call node is generated.
6751 Get_First_Interp (P, I, It);
6752 while Present (It.Typ) loop
6753 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6757 Get_Next_Interp (I, It);
6761 Make_Function_Call (Loc,
6763 Make_Explicit_Dereference (Loc,
6765 Parameter_Associations => New_List);
6767 Save_Interps (N, New_N);
6769 Analyze_And_Resolve (N, Typ);
6773 Set_Etype (N, Designated_Type (It.Typ));
6779 if Is_Access_Type (Etype (P)) then
6780 Apply_Access_Check (N);
6783 -- If the designated type is a packed unconstrained array type, and the
6784 -- explicit dereference is not in the context of an attribute reference,
6785 -- then we must compute and set the actual subtype, since it is needed
6786 -- by Gigi. The reason we exclude the attribute case is that this is
6787 -- handled fine by Gigi, and in fact we use such attributes to build the
6788 -- actual subtype. We also exclude generated code (which builds actual
6789 -- subtypes directly if they are needed).
6791 if Is_Array_Type (Etype (N))
6792 and then Is_Packed (Etype (N))
6793 and then not Is_Constrained (Etype (N))
6794 and then Nkind (Parent (N)) /= N_Attribute_Reference
6795 and then Comes_From_Source (N)
6797 Set_Etype (N, Get_Actual_Subtype (N));
6800 -- Note: No Eval processing is required for an explicit dereference,
6801 -- because such a name can never be static.
6803 end Resolve_Explicit_Dereference;
6805 -------------------------------------
6806 -- Resolve_Expression_With_Actions --
6807 -------------------------------------
6809 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id) is
6812 end Resolve_Expression_With_Actions;
6814 -------------------------------
6815 -- Resolve_Indexed_Component --
6816 -------------------------------
6818 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
6819 Name : constant Node_Id := Prefix (N);
6821 Array_Type : Entity_Id := Empty; -- to prevent junk warning
6825 if Is_Overloaded (Name) then
6827 -- Use the context type to select the prefix that yields the correct
6833 I1 : Interp_Index := 0;
6834 P : constant Node_Id := Prefix (N);
6835 Found : Boolean := False;
6838 Get_First_Interp (P, I, It);
6839 while Present (It.Typ) loop
6840 if (Is_Array_Type (It.Typ)
6841 and then Covers (Typ, Component_Type (It.Typ)))
6842 or else (Is_Access_Type (It.Typ)
6843 and then Is_Array_Type (Designated_Type (It.Typ))
6845 (Typ, Component_Type (Designated_Type (It.Typ))))
6848 It := Disambiguate (P, I1, I, Any_Type);
6850 if It = No_Interp then
6851 Error_Msg_N ("ambiguous prefix for indexing", N);
6857 Array_Type := It.Typ;
6863 Array_Type := It.Typ;
6868 Get_Next_Interp (I, It);
6873 Array_Type := Etype (Name);
6876 Resolve (Name, Array_Type);
6877 Array_Type := Get_Actual_Subtype_If_Available (Name);
6879 -- If prefix is access type, dereference to get real array type.
6880 -- Note: we do not apply an access check because the expander always
6881 -- introduces an explicit dereference, and the check will happen there.
6883 if Is_Access_Type (Array_Type) then
6884 Array_Type := Designated_Type (Array_Type);
6887 -- If name was overloaded, set component type correctly now
6888 -- If a misplaced call to an entry family (which has no index types)
6889 -- return. Error will be diagnosed from calling context.
6891 if Is_Array_Type (Array_Type) then
6892 Set_Etype (N, Component_Type (Array_Type));
6897 Index := First_Index (Array_Type);
6898 Expr := First (Expressions (N));
6900 -- The prefix may have resolved to a string literal, in which case its
6901 -- etype has a special representation. This is only possible currently
6902 -- if the prefix is a static concatenation, written in functional
6905 if Ekind (Array_Type) = E_String_Literal_Subtype then
6906 Resolve (Expr, Standard_Positive);
6909 while Present (Index) and Present (Expr) loop
6910 Resolve (Expr, Etype (Index));
6911 Check_Unset_Reference (Expr);
6913 if Is_Scalar_Type (Etype (Expr)) then
6914 Apply_Scalar_Range_Check (Expr, Etype (Index));
6916 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
6924 -- Do not generate the warning on suspicious index if we are analyzing
6925 -- package Ada.Tags; otherwise we will report the warning with the
6926 -- Prims_Ptr field of the dispatch table.
6928 if Scope (Etype (Prefix (N))) = Standard_Standard
6930 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
6933 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
6934 Eval_Indexed_Component (N);
6937 -- If the array type is atomic, and is packed, and we are in a left side
6938 -- context, then this is worth a warning, since we have a situation
6939 -- where the access to the component may cause extra read/writes of
6940 -- the atomic array object, which could be considered unexpected.
6942 if Nkind (N) = N_Indexed_Component
6943 and then (Is_Atomic (Array_Type)
6944 or else (Is_Entity_Name (Prefix (N))
6945 and then Is_Atomic (Entity (Prefix (N)))))
6946 and then Is_Bit_Packed_Array (Array_Type)
6949 Error_Msg_N ("?assignment to component of packed atomic array",
6951 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
6954 end Resolve_Indexed_Component;
6956 -----------------------------
6957 -- Resolve_Integer_Literal --
6958 -----------------------------
6960 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
6963 Eval_Integer_Literal (N);
6964 end Resolve_Integer_Literal;
6966 --------------------------------
6967 -- Resolve_Intrinsic_Operator --
6968 --------------------------------
6970 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
6971 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6973 Orig_Op : constant Entity_Id := Entity (N);
6978 -- We must preserve the original entity in a generic setting, so that
6979 -- the legality of the operation can be verified in an instance.
6981 if not Expander_Active then
6986 while Scope (Op) /= Standard_Standard loop
6988 pragma Assert (Present (Op));
6992 Set_Is_Overloaded (N, False);
6994 -- If the operand type is private, rewrite with suitable conversions on
6995 -- the operands and the result, to expose the proper underlying numeric
6998 if Is_Private_Type (Typ) then
6999 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
7001 if Nkind (N) = N_Op_Expon then
7002 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
7004 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7007 if Nkind (Arg1) = N_Type_Conversion then
7008 Save_Interps (Left_Opnd (N), Expression (Arg1));
7011 if Nkind (Arg2) = N_Type_Conversion then
7012 Save_Interps (Right_Opnd (N), Expression (Arg2));
7015 Set_Left_Opnd (N, Arg1);
7016 Set_Right_Opnd (N, Arg2);
7018 Set_Etype (N, Btyp);
7019 Rewrite (N, Unchecked_Convert_To (Typ, N));
7022 elsif Typ /= Etype (Left_Opnd (N))
7023 or else Typ /= Etype (Right_Opnd (N))
7025 -- Add explicit conversion where needed, and save interpretations in
7026 -- case operands are overloaded. If the context is a VMS operation,
7027 -- assert that the conversion is legal (the operands have the proper
7028 -- types to select the VMS intrinsic). Note that in rare cases the
7029 -- VMS operators may be visible, but the default System is being used
7030 -- and Address is a private type.
7032 Arg1 := Convert_To (Typ, Left_Opnd (N));
7033 Arg2 := Convert_To (Typ, Right_Opnd (N));
7035 if Nkind (Arg1) = N_Type_Conversion then
7036 Save_Interps (Left_Opnd (N), Expression (Arg1));
7038 if Is_VMS_Operator (Orig_Op) then
7039 Set_Conversion_OK (Arg1);
7042 Save_Interps (Left_Opnd (N), Arg1);
7045 if Nkind (Arg2) = N_Type_Conversion then
7046 Save_Interps (Right_Opnd (N), Expression (Arg2));
7048 if Is_VMS_Operator (Orig_Op) then
7049 Set_Conversion_OK (Arg2);
7052 Save_Interps (Right_Opnd (N), Arg2);
7055 Rewrite (Left_Opnd (N), Arg1);
7056 Rewrite (Right_Opnd (N), Arg2);
7059 Resolve_Arithmetic_Op (N, Typ);
7062 Resolve_Arithmetic_Op (N, Typ);
7064 end Resolve_Intrinsic_Operator;
7066 --------------------------------------
7067 -- Resolve_Intrinsic_Unary_Operator --
7068 --------------------------------------
7070 procedure Resolve_Intrinsic_Unary_Operator
7074 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
7080 while Scope (Op) /= Standard_Standard loop
7082 pragma Assert (Present (Op));
7087 if Is_Private_Type (Typ) then
7088 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7089 Save_Interps (Right_Opnd (N), Expression (Arg2));
7091 Set_Right_Opnd (N, Arg2);
7093 Set_Etype (N, Btyp);
7094 Rewrite (N, Unchecked_Convert_To (Typ, N));
7098 Resolve_Unary_Op (N, Typ);
7100 end Resolve_Intrinsic_Unary_Operator;
7102 ------------------------
7103 -- Resolve_Logical_Op --
7104 ------------------------
7106 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
7110 Check_No_Direct_Boolean_Operators (N);
7112 -- Predefined operations on scalar types yield the base type. On the
7113 -- other hand, logical operations on arrays yield the type of the
7114 -- arguments (and the context).
7116 if Is_Array_Type (Typ) then
7119 B_Typ := Base_Type (Typ);
7122 -- OK if this is a VMS-specific intrinsic operation
7124 if Is_VMS_Operator (Entity (N)) then
7127 -- The following test is required because the operands of the operation
7128 -- may be literals, in which case the resulting type appears to be
7129 -- compatible with a signed integer type, when in fact it is compatible
7130 -- only with modular types. If the context itself is universal, the
7131 -- operation is illegal.
7133 elsif not Valid_Boolean_Arg (Typ) then
7134 Error_Msg_N ("invalid context for logical operation", N);
7135 Set_Etype (N, Any_Type);
7138 elsif Typ = Any_Modular then
7140 ("no modular type available in this context", N);
7141 Set_Etype (N, Any_Type);
7143 elsif Is_Modular_Integer_Type (Typ)
7144 and then Etype (Left_Opnd (N)) = Universal_Integer
7145 and then Etype (Right_Opnd (N)) = Universal_Integer
7147 Check_For_Visible_Operator (N, B_Typ);
7150 Resolve (Left_Opnd (N), B_Typ);
7151 Resolve (Right_Opnd (N), B_Typ);
7153 Check_Unset_Reference (Left_Opnd (N));
7154 Check_Unset_Reference (Right_Opnd (N));
7156 Set_Etype (N, B_Typ);
7157 Generate_Operator_Reference (N, B_Typ);
7158 Eval_Logical_Op (N);
7159 end Resolve_Logical_Op;
7161 ---------------------------
7162 -- Resolve_Membership_Op --
7163 ---------------------------
7165 -- The context can only be a boolean type, and does not determine
7166 -- the arguments. Arguments should be unambiguous, but the preference
7167 -- rule for universal types applies.
7169 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
7170 pragma Warnings (Off, Typ);
7172 L : constant Node_Id := Left_Opnd (N);
7173 R : constant Node_Id := Right_Opnd (N);
7176 procedure Resolve_Set_Membership;
7177 -- Analysis has determined a unique type for the left operand.
7178 -- Use it to resolve the disjuncts.
7180 ----------------------------
7181 -- Resolve_Set_Membership --
7182 ----------------------------
7184 procedure Resolve_Set_Membership is
7188 Resolve (L, Etype (L));
7190 Alt := First (Alternatives (N));
7191 while Present (Alt) loop
7193 -- Alternative is an expression, a range
7194 -- or a subtype mark.
7196 if not Is_Entity_Name (Alt)
7197 or else not Is_Type (Entity (Alt))
7199 Resolve (Alt, Etype (L));
7204 end Resolve_Set_Membership;
7206 -- Start of processing for Resolve_Membership_Op
7209 if L = Error or else R = Error then
7213 if Present (Alternatives (N)) then
7214 Resolve_Set_Membership;
7217 elsif not Is_Overloaded (R)
7219 (Etype (R) = Universal_Integer or else
7220 Etype (R) = Universal_Real)
7221 and then Is_Overloaded (L)
7225 -- Ada 2005 (AI-251): Support the following case:
7227 -- type I is interface;
7228 -- type T is tagged ...
7230 -- function Test (O : I'Class) is
7232 -- return O in T'Class.
7235 -- In this case we have nothing else to do. The membership test will be
7236 -- done at run time.
7238 elsif Ada_Version >= Ada_2005
7239 and then Is_Class_Wide_Type (Etype (L))
7240 and then Is_Interface (Etype (L))
7241 and then Is_Class_Wide_Type (Etype (R))
7242 and then not Is_Interface (Etype (R))
7247 T := Intersect_Types (L, R);
7250 -- If mixed-mode operations are present and operands are all literal,
7251 -- the only interpretation involves Duration, which is probably not
7252 -- the intention of the programmer.
7254 if T = Any_Fixed then
7255 T := Unique_Fixed_Point_Type (N);
7257 if T = Any_Type then
7263 Check_Unset_Reference (L);
7265 if Nkind (R) = N_Range
7266 and then not Is_Scalar_Type (T)
7268 Error_Msg_N ("scalar type required for range", R);
7271 if Is_Entity_Name (R) then
7272 Freeze_Expression (R);
7275 Check_Unset_Reference (R);
7278 Eval_Membership_Op (N);
7279 end Resolve_Membership_Op;
7285 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
7286 Loc : constant Source_Ptr := Sloc (N);
7289 -- Handle restriction against anonymous null access values This
7290 -- restriction can be turned off using -gnatdj.
7292 -- Ada 2005 (AI-231): Remove restriction
7294 if Ada_Version < Ada_2005
7295 and then not Debug_Flag_J
7296 and then Ekind (Typ) = E_Anonymous_Access_Type
7297 and then Comes_From_Source (N)
7299 -- In the common case of a call which uses an explicitly null value
7300 -- for an access parameter, give specialized error message.
7302 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
7306 ("null is not allowed as argument for an access parameter", N);
7308 -- Standard message for all other cases (are there any?)
7312 ("null cannot be of an anonymous access type", N);
7316 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
7317 -- assignment to a null-excluding object
7319 if Ada_Version >= Ada_2005
7320 and then Can_Never_Be_Null (Typ)
7321 and then Nkind (Parent (N)) = N_Assignment_Statement
7323 if not Inside_Init_Proc then
7325 (Compile_Time_Constraint_Error (N,
7326 "(Ada 2005) null not allowed in null-excluding objects?"),
7327 Make_Raise_Constraint_Error (Loc,
7328 Reason => CE_Access_Check_Failed));
7331 Make_Raise_Constraint_Error (Loc,
7332 Reason => CE_Access_Check_Failed));
7336 -- In a distributed context, null for a remote access to subprogram may
7337 -- need to be replaced with a special record aggregate. In this case,
7338 -- return after having done the transformation.
7340 if (Ekind (Typ) = E_Record_Type
7341 or else Is_Remote_Access_To_Subprogram_Type (Typ))
7342 and then Remote_AST_Null_Value (N, Typ)
7347 -- The null literal takes its type from the context
7352 -----------------------
7353 -- Resolve_Op_Concat --
7354 -----------------------
7356 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
7358 -- We wish to avoid deep recursion, because concatenations are often
7359 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
7360 -- operands nonrecursively until we find something that is not a simple
7361 -- concatenation (A in this case). We resolve that, and then walk back
7362 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
7363 -- to do the rest of the work at each level. The Parent pointers allow
7364 -- us to avoid recursion, and thus avoid running out of memory. See also
7365 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
7371 -- The following code is equivalent to:
7373 -- Resolve_Op_Concat_First (NN, Typ);
7374 -- Resolve_Op_Concat_Arg (N, ...);
7375 -- Resolve_Op_Concat_Rest (N, Typ);
7377 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
7378 -- operand is a concatenation.
7380 -- Walk down left operands
7383 Resolve_Op_Concat_First (NN, Typ);
7384 Op1 := Left_Opnd (NN);
7385 exit when not (Nkind (Op1) = N_Op_Concat
7386 and then not Is_Array_Type (Component_Type (Typ))
7387 and then Entity (Op1) = Entity (NN));
7391 -- Now (given the above example) NN is A&B and Op1 is A
7393 -- First resolve Op1 ...
7395 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
7397 -- ... then walk NN back up until we reach N (where we started), calling
7398 -- Resolve_Op_Concat_Rest along the way.
7401 Resolve_Op_Concat_Rest (NN, Typ);
7405 end Resolve_Op_Concat;
7407 ---------------------------
7408 -- Resolve_Op_Concat_Arg --
7409 ---------------------------
7411 procedure Resolve_Op_Concat_Arg
7417 Btyp : constant Entity_Id := Base_Type (Typ);
7422 or else (not Is_Overloaded (Arg)
7423 and then Etype (Arg) /= Any_Composite
7424 and then Covers (Component_Type (Typ), Etype (Arg)))
7426 Resolve (Arg, Component_Type (Typ));
7428 Resolve (Arg, Btyp);
7431 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
7432 if Nkind (Arg) = N_Aggregate
7433 and then Is_Composite_Type (Component_Type (Typ))
7435 if Is_Private_Type (Component_Type (Typ)) then
7436 Resolve (Arg, Btyp);
7438 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
7439 Set_Etype (Arg, Any_Type);
7443 if Is_Overloaded (Arg)
7444 and then Has_Compatible_Type (Arg, Typ)
7445 and then Etype (Arg) /= Any_Type
7453 Get_First_Interp (Arg, I, It);
7455 Get_Next_Interp (I, It);
7457 -- Special-case the error message when the overloading is
7458 -- caused by a function that yields an array and can be
7459 -- called without parameters.
7461 if It.Nam = Func then
7462 Error_Msg_Sloc := Sloc (Func);
7463 Error_Msg_N ("ambiguous call to function#", Arg);
7465 ("\\interpretation as call yields&", Arg, Typ);
7467 ("\\interpretation as indexing of call yields&",
7468 Arg, Component_Type (Typ));
7472 ("ambiguous operand for concatenation!", Arg);
7473 Get_First_Interp (Arg, I, It);
7474 while Present (It.Nam) loop
7475 Error_Msg_Sloc := Sloc (It.Nam);
7477 if Base_Type (It.Typ) = Base_Type (Typ)
7478 or else Base_Type (It.Typ) =
7479 Base_Type (Component_Type (Typ))
7481 Error_Msg_N -- CODEFIX
7482 ("\\possible interpretation#", Arg);
7485 Get_Next_Interp (I, It);
7491 Resolve (Arg, Component_Type (Typ));
7493 if Nkind (Arg) = N_String_Literal then
7494 Set_Etype (Arg, Component_Type (Typ));
7497 if Arg = Left_Opnd (N) then
7498 Set_Is_Component_Left_Opnd (N);
7500 Set_Is_Component_Right_Opnd (N);
7505 Resolve (Arg, Btyp);
7508 Check_Unset_Reference (Arg);
7509 end Resolve_Op_Concat_Arg;
7511 -----------------------------
7512 -- Resolve_Op_Concat_First --
7513 -----------------------------
7515 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
7516 Btyp : constant Entity_Id := Base_Type (Typ);
7517 Op1 : constant Node_Id := Left_Opnd (N);
7518 Op2 : constant Node_Id := Right_Opnd (N);
7521 -- The parser folds an enormous sequence of concatenations of string
7522 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
7523 -- in the right operand. If the expression resolves to a predefined "&"
7524 -- operator, all is well. Otherwise, the parser's folding is wrong, so
7525 -- we give an error. See P_Simple_Expression in Par.Ch4.
7527 if Nkind (Op2) = N_String_Literal
7528 and then Is_Folded_In_Parser (Op2)
7529 and then Ekind (Entity (N)) = E_Function
7531 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
7532 and then String_Length (Strval (Op1)) = 0);
7533 Error_Msg_N ("too many user-defined concatenations", N);
7537 Set_Etype (N, Btyp);
7539 if Is_Limited_Composite (Btyp) then
7540 Error_Msg_N ("concatenation not available for limited array", N);
7541 Explain_Limited_Type (Btyp, N);
7543 end Resolve_Op_Concat_First;
7545 ----------------------------
7546 -- Resolve_Op_Concat_Rest --
7547 ----------------------------
7549 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
7550 Op1 : constant Node_Id := Left_Opnd (N);
7551 Op2 : constant Node_Id := Right_Opnd (N);
7554 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
7556 Generate_Operator_Reference (N, Typ);
7558 if Is_String_Type (Typ) then
7559 Eval_Concatenation (N);
7562 -- If this is not a static concatenation, but the result is a string
7563 -- type (and not an array of strings) ensure that static string operands
7564 -- have their subtypes properly constructed.
7566 if Nkind (N) /= N_String_Literal
7567 and then Is_Character_Type (Component_Type (Typ))
7569 Set_String_Literal_Subtype (Op1, Typ);
7570 Set_String_Literal_Subtype (Op2, Typ);
7572 end Resolve_Op_Concat_Rest;
7574 ----------------------
7575 -- Resolve_Op_Expon --
7576 ----------------------
7578 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
7579 B_Typ : constant Entity_Id := Base_Type (Typ);
7582 -- Catch attempts to do fixed-point exponentiation with universal
7583 -- operands, which is a case where the illegality is not caught during
7584 -- normal operator analysis.
7586 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
7587 Error_Msg_N ("exponentiation not available for fixed point", N);
7591 if Comes_From_Source (N)
7592 and then Ekind (Entity (N)) = E_Function
7593 and then Is_Imported (Entity (N))
7594 and then Is_Intrinsic_Subprogram (Entity (N))
7596 Resolve_Intrinsic_Operator (N, Typ);
7600 if Etype (Left_Opnd (N)) = Universal_Integer
7601 or else Etype (Left_Opnd (N)) = Universal_Real
7603 Check_For_Visible_Operator (N, B_Typ);
7606 -- We do the resolution using the base type, because intermediate values
7607 -- in expressions always are of the base type, not a subtype of it.
7609 Resolve (Left_Opnd (N), B_Typ);
7610 Resolve (Right_Opnd (N), Standard_Integer);
7612 Check_Unset_Reference (Left_Opnd (N));
7613 Check_Unset_Reference (Right_Opnd (N));
7615 Set_Etype (N, B_Typ);
7616 Generate_Operator_Reference (N, B_Typ);
7619 -- Set overflow checking bit. Much cleverer code needed here eventually
7620 -- and perhaps the Resolve routines should be separated for the various
7621 -- arithmetic operations, since they will need different processing. ???
7623 if Nkind (N) in N_Op then
7624 if not Overflow_Checks_Suppressed (Etype (N)) then
7625 Enable_Overflow_Check (N);
7628 end Resolve_Op_Expon;
7630 --------------------
7631 -- Resolve_Op_Not --
7632 --------------------
7634 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
7637 function Parent_Is_Boolean return Boolean;
7638 -- This function determines if the parent node is a boolean operator
7639 -- or operation (comparison op, membership test, or short circuit form)
7640 -- and the not in question is the left operand of this operation.
7641 -- Note that if the not is in parens, then false is returned.
7643 -----------------------
7644 -- Parent_Is_Boolean --
7645 -----------------------
7647 function Parent_Is_Boolean return Boolean is
7649 if Paren_Count (N) /= 0 then
7653 case Nkind (Parent (N)) is
7668 return Left_Opnd (Parent (N)) = N;
7674 end Parent_Is_Boolean;
7676 -- Start of processing for Resolve_Op_Not
7679 -- Predefined operations on scalar types yield the base type. On the
7680 -- other hand, logical operations on arrays yield the type of the
7681 -- arguments (and the context).
7683 if Is_Array_Type (Typ) then
7686 B_Typ := Base_Type (Typ);
7689 if Is_VMS_Operator (Entity (N)) then
7692 -- Straightforward case of incorrect arguments
7694 elsif not Valid_Boolean_Arg (Typ) then
7695 Error_Msg_N ("invalid operand type for operator&", N);
7696 Set_Etype (N, Any_Type);
7699 -- Special case of probable missing parens
7701 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7702 if Parent_Is_Boolean then
7704 ("operand of not must be enclosed in parentheses",
7708 ("no modular type available in this context", N);
7711 Set_Etype (N, Any_Type);
7714 -- OK resolution of not
7717 -- Warn if non-boolean types involved. This is a case like not a < b
7718 -- where a and b are modular, where we will get (not a) < b and most
7719 -- likely not (a < b) was intended.
7721 if Warn_On_Questionable_Missing_Parens
7722 and then not Is_Boolean_Type (Typ)
7723 and then Parent_Is_Boolean
7725 Error_Msg_N ("?not expression should be parenthesized here!", N);
7728 -- Warn on double negation if checking redundant constructs
7730 if Warn_On_Redundant_Constructs
7731 and then Comes_From_Source (N)
7732 and then Comes_From_Source (Right_Opnd (N))
7733 and then Root_Type (Typ) = Standard_Boolean
7734 and then Nkind (Right_Opnd (N)) = N_Op_Not
7736 Error_Msg_N ("redundant double negation?", N);
7739 -- Complete resolution and evaluation of NOT
7741 Resolve (Right_Opnd (N), B_Typ);
7742 Check_Unset_Reference (Right_Opnd (N));
7743 Set_Etype (N, B_Typ);
7744 Generate_Operator_Reference (N, B_Typ);
7749 -----------------------------
7750 -- Resolve_Operator_Symbol --
7751 -----------------------------
7753 -- Nothing to be done, all resolved already
7755 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
7756 pragma Warnings (Off, N);
7757 pragma Warnings (Off, Typ);
7761 end Resolve_Operator_Symbol;
7763 ----------------------------------
7764 -- Resolve_Qualified_Expression --
7765 ----------------------------------
7767 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
7768 pragma Warnings (Off, Typ);
7770 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
7771 Expr : constant Node_Id := Expression (N);
7774 Resolve (Expr, Target_Typ);
7776 -- A qualified expression requires an exact match of the type,
7777 -- class-wide matching is not allowed. However, if the qualifying
7778 -- type is specific and the expression has a class-wide type, it
7779 -- may still be okay, since it can be the result of the expansion
7780 -- of a call to a dispatching function, so we also have to check
7781 -- class-wideness of the type of the expression's original node.
7783 if (Is_Class_Wide_Type (Target_Typ)
7785 (Is_Class_Wide_Type (Etype (Expr))
7786 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
7787 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
7789 Wrong_Type (Expr, Target_Typ);
7792 -- If the target type is unconstrained, then we reset the type of the
7793 -- result from the type of the expression. For other cases, the actual
7794 -- subtype of the expression is the target type.
7796 if Is_Composite_Type (Target_Typ)
7797 and then not Is_Constrained (Target_Typ)
7799 Set_Etype (N, Etype (Expr));
7802 Eval_Qualified_Expression (N);
7803 end Resolve_Qualified_Expression;
7805 -----------------------------------
7806 -- Resolve_Quantified_Expression --
7807 -----------------------------------
7809 procedure Resolve_Quantified_Expression (N : Node_Id; Typ : Entity_Id) is
7811 -- The loop structure is already resolved during its analysis, only the
7812 -- resolution of the condition needs to be done. Expansion is disabled
7813 -- so that checks and other generated code are inserted in the tree
7814 -- after expression has been rewritten as a loop.
7816 Expander_Mode_Save_And_Set (False);
7817 Resolve (Condition (N), Typ);
7818 Expander_Mode_Restore;
7819 end Resolve_Quantified_Expression;
7825 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
7826 L : constant Node_Id := Low_Bound (N);
7827 H : constant Node_Id := High_Bound (N);
7829 function First_Last_Ref return Boolean;
7830 -- Returns True if N is of the form X'First .. X'Last where X is the
7831 -- same entity for both attributes.
7833 --------------------
7834 -- First_Last_Ref --
7835 --------------------
7837 function First_Last_Ref return Boolean is
7838 Lorig : constant Node_Id := Original_Node (L);
7839 Horig : constant Node_Id := Original_Node (H);
7842 if Nkind (Lorig) = N_Attribute_Reference
7843 and then Nkind (Horig) = N_Attribute_Reference
7844 and then Attribute_Name (Lorig) = Name_First
7845 and then Attribute_Name (Horig) = Name_Last
7848 PL : constant Node_Id := Prefix (Lorig);
7849 PH : constant Node_Id := Prefix (Horig);
7851 if Is_Entity_Name (PL)
7852 and then Is_Entity_Name (PH)
7853 and then Entity (PL) = Entity (PH)
7863 -- Start of processing for Resolve_Range
7870 -- Check for inappropriate range on unordered enumeration type
7872 if Bad_Unordered_Enumeration_Reference (N, Typ)
7874 -- Exclude X'First .. X'Last if X is the same entity for both
7876 and then not First_Last_Ref
7878 Error_Msg ("subrange of unordered enumeration type?", Sloc (N));
7881 Check_Unset_Reference (L);
7882 Check_Unset_Reference (H);
7884 -- We have to check the bounds for being within the base range as
7885 -- required for a non-static context. Normally this is automatic and
7886 -- done as part of evaluating expressions, but the N_Range node is an
7887 -- exception, since in GNAT we consider this node to be a subexpression,
7888 -- even though in Ada it is not. The circuit in Sem_Eval could check for
7889 -- this, but that would put the test on the main evaluation path for
7892 Check_Non_Static_Context (L);
7893 Check_Non_Static_Context (H);
7895 -- Check for an ambiguous range over character literals. This will
7896 -- happen with a membership test involving only literals.
7898 if Typ = Any_Character then
7899 Ambiguous_Character (L);
7900 Set_Etype (N, Any_Type);
7904 -- If bounds are static, constant-fold them, so size computations
7905 -- are identical between front-end and back-end. Do not perform this
7906 -- transformation while analyzing generic units, as type information
7907 -- would then be lost when reanalyzing the constant node in the
7910 if Is_Discrete_Type (Typ) and then Expander_Active then
7911 if Is_OK_Static_Expression (L) then
7912 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
7915 if Is_OK_Static_Expression (H) then
7916 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
7921 --------------------------
7922 -- Resolve_Real_Literal --
7923 --------------------------
7925 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
7926 Actual_Typ : constant Entity_Id := Etype (N);
7929 -- Special processing for fixed-point literals to make sure that the
7930 -- value is an exact multiple of small where this is required. We
7931 -- skip this for the universal real case, and also for generic types.
7933 if Is_Fixed_Point_Type (Typ)
7934 and then Typ /= Universal_Fixed
7935 and then Typ /= Any_Fixed
7936 and then not Is_Generic_Type (Typ)
7939 Val : constant Ureal := Realval (N);
7940 Cintr : constant Ureal := Val / Small_Value (Typ);
7941 Cint : constant Uint := UR_Trunc (Cintr);
7942 Den : constant Uint := Norm_Den (Cintr);
7946 -- Case of literal is not an exact multiple of the Small
7950 -- For a source program literal for a decimal fixed-point
7951 -- type, this is statically illegal (RM 4.9(36)).
7953 if Is_Decimal_Fixed_Point_Type (Typ)
7954 and then Actual_Typ = Universal_Real
7955 and then Comes_From_Source (N)
7957 Error_Msg_N ("value has extraneous low order digits", N);
7960 -- Generate a warning if literal from source
7962 if Is_Static_Expression (N)
7963 and then Warn_On_Bad_Fixed_Value
7966 ("?static fixed-point value is not a multiple of Small!",
7970 -- Replace literal by a value that is the exact representation
7971 -- of a value of the type, i.e. a multiple of the small value,
7972 -- by truncation, since Machine_Rounds is false for all GNAT
7973 -- fixed-point types (RM 4.9(38)).
7975 Stat := Is_Static_Expression (N);
7977 Make_Real_Literal (Sloc (N),
7978 Realval => Small_Value (Typ) * Cint));
7980 Set_Is_Static_Expression (N, Stat);
7983 -- In all cases, set the corresponding integer field
7985 Set_Corresponding_Integer_Value (N, Cint);
7989 -- Now replace the actual type by the expected type as usual
7992 Eval_Real_Literal (N);
7993 end Resolve_Real_Literal;
7995 -----------------------
7996 -- Resolve_Reference --
7997 -----------------------
7999 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
8000 P : constant Node_Id := Prefix (N);
8003 -- Replace general access with specific type
8005 if Ekind (Etype (N)) = E_Allocator_Type then
8006 Set_Etype (N, Base_Type (Typ));
8009 Resolve (P, Designated_Type (Etype (N)));
8011 -- If we are taking the reference of a volatile entity, then treat
8012 -- it as a potential modification of this entity. This is much too
8013 -- conservative, but is necessary because remove side effects can
8014 -- result in transformations of normal assignments into reference
8015 -- sequences that otherwise fail to notice the modification.
8017 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
8018 Note_Possible_Modification (P, Sure => False);
8020 end Resolve_Reference;
8022 --------------------------------
8023 -- Resolve_Selected_Component --
8024 --------------------------------
8026 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
8028 Comp1 : Entity_Id := Empty; -- prevent junk warning
8029 P : constant Node_Id := Prefix (N);
8030 S : constant Node_Id := Selector_Name (N);
8031 T : Entity_Id := Etype (P);
8033 I1 : Interp_Index := 0; -- prevent junk warning
8038 function Init_Component return Boolean;
8039 -- Check whether this is the initialization of a component within an
8040 -- init proc (by assignment or call to another init proc). If true,
8041 -- there is no need for a discriminant check.
8043 --------------------
8044 -- Init_Component --
8045 --------------------
8047 function Init_Component return Boolean is
8049 return Inside_Init_Proc
8050 and then Nkind (Prefix (N)) = N_Identifier
8051 and then Chars (Prefix (N)) = Name_uInit
8052 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
8055 -- Start of processing for Resolve_Selected_Component
8058 if Is_Overloaded (P) then
8060 -- Use the context type to select the prefix that has a selector
8061 -- of the correct name and type.
8064 Get_First_Interp (P, I, It);
8066 Search : while Present (It.Typ) loop
8067 if Is_Access_Type (It.Typ) then
8068 T := Designated_Type (It.Typ);
8073 if Is_Record_Type (T) then
8075 -- The visible components of a class-wide type are those of
8078 if Is_Class_Wide_Type (T) then
8082 Comp := First_Entity (T);
8083 while Present (Comp) loop
8084 if Chars (Comp) = Chars (S)
8085 and then Covers (Etype (Comp), Typ)
8094 It := Disambiguate (P, I1, I, Any_Type);
8096 if It = No_Interp then
8098 ("ambiguous prefix for selected component", N);
8105 -- There may be an implicit dereference. Retrieve
8106 -- designated record type.
8108 if Is_Access_Type (It1.Typ) then
8109 T := Designated_Type (It1.Typ);
8114 if Scope (Comp1) /= T then
8116 -- Resolution chooses the new interpretation.
8117 -- Find the component with the right name.
8119 Comp1 := First_Entity (T);
8120 while Present (Comp1)
8121 and then Chars (Comp1) /= Chars (S)
8123 Comp1 := Next_Entity (Comp1);
8132 Comp := Next_Entity (Comp);
8136 Get_Next_Interp (I, It);
8139 Resolve (P, It1.Typ);
8141 Set_Entity_With_Style_Check (S, Comp1);
8144 -- Resolve prefix with its type
8149 -- Generate cross-reference. We needed to wait until full overloading
8150 -- resolution was complete to do this, since otherwise we can't tell if
8151 -- we are an lvalue or not.
8153 if May_Be_Lvalue (N) then
8154 Generate_Reference (Entity (S), S, 'm');
8156 Generate_Reference (Entity (S), S, 'r');
8159 -- If prefix is an access type, the node will be transformed into an
8160 -- explicit dereference during expansion. The type of the node is the
8161 -- designated type of that of the prefix.
8163 if Is_Access_Type (Etype (P)) then
8164 T := Designated_Type (Etype (P));
8165 Check_Fully_Declared_Prefix (T, P);
8170 if Has_Discriminants (T)
8171 and then Ekind_In (Entity (S), E_Component, E_Discriminant)
8172 and then Present (Original_Record_Component (Entity (S)))
8173 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
8174 and then Present (Discriminant_Checking_Func
8175 (Original_Record_Component (Entity (S))))
8176 and then not Discriminant_Checks_Suppressed (T)
8177 and then not Init_Component
8179 Set_Do_Discriminant_Check (N);
8182 if Ekind (Entity (S)) = E_Void then
8183 Error_Msg_N ("premature use of component", S);
8186 -- If the prefix is a record conversion, this may be a renamed
8187 -- discriminant whose bounds differ from those of the original
8188 -- one, so we must ensure that a range check is performed.
8190 if Nkind (P) = N_Type_Conversion
8191 and then Ekind (Entity (S)) = E_Discriminant
8192 and then Is_Discrete_Type (Typ)
8194 Set_Etype (N, Base_Type (Typ));
8197 -- Note: No Eval processing is required, because the prefix is of a
8198 -- record type, or protected type, and neither can possibly be static.
8200 -- If the array type is atomic, and is packed, and we are in a left side
8201 -- context, then this is worth a warning, since we have a situation
8202 -- where the access to the component may cause extra read/writes of
8203 -- the atomic array object, which could be considered unexpected.
8205 if Nkind (N) = N_Selected_Component
8206 and then (Is_Atomic (T)
8207 or else (Is_Entity_Name (Prefix (N))
8208 and then Is_Atomic (Entity (Prefix (N)))))
8209 and then Is_Packed (T)
8212 Error_Msg_N ("?assignment to component of packed atomic record",
8214 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
8217 end Resolve_Selected_Component;
8223 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
8224 B_Typ : constant Entity_Id := Base_Type (Typ);
8225 L : constant Node_Id := Left_Opnd (N);
8226 R : constant Node_Id := Right_Opnd (N);
8229 -- We do the resolution using the base type, because intermediate values
8230 -- in expressions always are of the base type, not a subtype of it.
8233 Resolve (R, Standard_Natural);
8235 Check_Unset_Reference (L);
8236 Check_Unset_Reference (R);
8238 Set_Etype (N, B_Typ);
8239 Generate_Operator_Reference (N, B_Typ);
8243 ---------------------------
8244 -- Resolve_Short_Circuit --
8245 ---------------------------
8247 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
8248 B_Typ : constant Entity_Id := Base_Type (Typ);
8249 L : constant Node_Id := Left_Opnd (N);
8250 R : constant Node_Id := Right_Opnd (N);
8256 -- Check for issuing warning for always False assert/check, this happens
8257 -- when assertions are turned off, in which case the pragma Assert/Check
8258 -- was transformed into:
8260 -- if False and then <condition> then ...
8262 -- and we detect this pattern
8264 if Warn_On_Assertion_Failure
8265 and then Is_Entity_Name (R)
8266 and then Entity (R) = Standard_False
8267 and then Nkind (Parent (N)) = N_If_Statement
8268 and then Nkind (N) = N_And_Then
8269 and then Is_Entity_Name (L)
8270 and then Entity (L) = Standard_False
8273 Orig : constant Node_Id := Original_Node (Parent (N));
8276 if Nkind (Orig) = N_Pragma
8277 and then Pragma_Name (Orig) = Name_Assert
8279 -- Don't want to warn if original condition is explicit False
8282 Expr : constant Node_Id :=
8285 (First (Pragma_Argument_Associations (Orig))));
8287 if Is_Entity_Name (Expr)
8288 and then Entity (Expr) = Standard_False
8292 -- Issue warning. We do not want the deletion of the
8293 -- IF/AND-THEN to take this message with it. We achieve
8294 -- this by making sure that the expanded code points to
8295 -- the Sloc of the expression, not the original pragma.
8298 ("?assertion would fail at run time!",
8300 (First (Pragma_Argument_Associations (Orig))));
8304 -- Similar processing for Check pragma
8306 elsif Nkind (Orig) = N_Pragma
8307 and then Pragma_Name (Orig) = Name_Check
8309 -- Don't want to warn if original condition is explicit False
8312 Expr : constant Node_Id :=
8316 (Pragma_Argument_Associations (Orig)))));
8318 if Is_Entity_Name (Expr)
8319 and then Entity (Expr) = Standard_False
8324 ("?check would fail at run time!",
8326 (Last (Pragma_Argument_Associations (Orig))));
8333 -- Continue with processing of short circuit
8335 Check_Unset_Reference (L);
8336 Check_Unset_Reference (R);
8338 Set_Etype (N, B_Typ);
8339 Eval_Short_Circuit (N);
8340 end Resolve_Short_Circuit;
8346 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
8347 Name : constant Node_Id := Prefix (N);
8348 Drange : constant Node_Id := Discrete_Range (N);
8349 Array_Type : Entity_Id := Empty;
8353 if Is_Overloaded (Name) then
8355 -- Use the context type to select the prefix that yields the correct
8360 I1 : Interp_Index := 0;
8362 P : constant Node_Id := Prefix (N);
8363 Found : Boolean := False;
8366 Get_First_Interp (P, I, It);
8367 while Present (It.Typ) loop
8368 if (Is_Array_Type (It.Typ)
8369 and then Covers (Typ, It.Typ))
8370 or else (Is_Access_Type (It.Typ)
8371 and then Is_Array_Type (Designated_Type (It.Typ))
8372 and then Covers (Typ, Designated_Type (It.Typ)))
8375 It := Disambiguate (P, I1, I, Any_Type);
8377 if It = No_Interp then
8378 Error_Msg_N ("ambiguous prefix for slicing", N);
8383 Array_Type := It.Typ;
8388 Array_Type := It.Typ;
8393 Get_Next_Interp (I, It);
8398 Array_Type := Etype (Name);
8401 Resolve (Name, Array_Type);
8403 if Is_Access_Type (Array_Type) then
8404 Apply_Access_Check (N);
8405 Array_Type := Designated_Type (Array_Type);
8407 -- If the prefix is an access to an unconstrained array, we must use
8408 -- the actual subtype of the object to perform the index checks. The
8409 -- object denoted by the prefix is implicit in the node, so we build
8410 -- an explicit representation for it in order to compute the actual
8413 if not Is_Constrained (Array_Type) then
8414 Remove_Side_Effects (Prefix (N));
8417 Obj : constant Node_Id :=
8418 Make_Explicit_Dereference (Sloc (N),
8419 Prefix => New_Copy_Tree (Prefix (N)));
8421 Set_Etype (Obj, Array_Type);
8422 Set_Parent (Obj, Parent (N));
8423 Array_Type := Get_Actual_Subtype (Obj);
8427 elsif Is_Entity_Name (Name)
8428 or else Nkind (Name) = N_Explicit_Dereference
8429 or else (Nkind (Name) = N_Function_Call
8430 and then not Is_Constrained (Etype (Name)))
8432 Array_Type := Get_Actual_Subtype (Name);
8434 -- If the name is a selected component that depends on discriminants,
8435 -- build an actual subtype for it. This can happen only when the name
8436 -- itself is overloaded; otherwise the actual subtype is created when
8437 -- the selected component is analyzed.
8439 elsif Nkind (Name) = N_Selected_Component
8440 and then Full_Analysis
8441 and then Depends_On_Discriminant (First_Index (Array_Type))
8444 Act_Decl : constant Node_Id :=
8445 Build_Actual_Subtype_Of_Component (Array_Type, Name);
8447 Insert_Action (N, Act_Decl);
8448 Array_Type := Defining_Identifier (Act_Decl);
8451 -- Maybe this should just be "else", instead of checking for the
8452 -- specific case of slice??? This is needed for the case where
8453 -- the prefix is an Image attribute, which gets expanded to a
8454 -- slice, and so has a constrained subtype which we want to use
8455 -- for the slice range check applied below (the range check won't
8456 -- get done if the unconstrained subtype of the 'Image is used).
8458 elsif Nkind (Name) = N_Slice then
8459 Array_Type := Etype (Name);
8462 -- If name was overloaded, set slice type correctly now
8464 Set_Etype (N, Array_Type);
8466 -- If the range is specified by a subtype mark, no resolution is
8467 -- necessary. Else resolve the bounds, and apply needed checks.
8469 if not Is_Entity_Name (Drange) then
8470 Index := First_Index (Array_Type);
8471 Resolve (Drange, Base_Type (Etype (Index)));
8473 if Nkind (Drange) = N_Range then
8475 -- Ensure that side effects in the bounds are properly handled
8477 Remove_Side_Effects (Low_Bound (Drange), Variable_Ref => True);
8478 Remove_Side_Effects (High_Bound (Drange), Variable_Ref => True);
8480 -- Do not apply the range check to nodes associated with the
8481 -- frontend expansion of the dispatch table. We first check
8482 -- if Ada.Tags is already loaded to avoid the addition of an
8483 -- undesired dependence on such run-time unit.
8485 if not Tagged_Type_Expansion
8487 (RTU_Loaded (Ada_Tags)
8488 and then Nkind (Prefix (N)) = N_Selected_Component
8489 and then Present (Entity (Selector_Name (Prefix (N))))
8490 and then Entity (Selector_Name (Prefix (N))) =
8491 RTE_Record_Component (RE_Prims_Ptr))
8493 Apply_Range_Check (Drange, Etype (Index));
8498 Set_Slice_Subtype (N);
8500 -- Check bad use of type with predicates
8502 if Has_Predicates (Etype (Drange)) then
8503 Bad_Predicated_Subtype_Use
8504 ("subtype& has predicate, not allowed in slice",
8505 Drange, Etype (Drange));
8507 -- Otherwise here is where we check suspicious indexes
8509 elsif Nkind (Drange) = N_Range then
8510 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
8511 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
8517 ----------------------------
8518 -- Resolve_String_Literal --
8519 ----------------------------
8521 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
8522 C_Typ : constant Entity_Id := Component_Type (Typ);
8523 R_Typ : constant Entity_Id := Root_Type (C_Typ);
8524 Loc : constant Source_Ptr := Sloc (N);
8525 Str : constant String_Id := Strval (N);
8526 Strlen : constant Nat := String_Length (Str);
8527 Subtype_Id : Entity_Id;
8528 Need_Check : Boolean;
8531 -- For a string appearing in a concatenation, defer creation of the
8532 -- string_literal_subtype until the end of the resolution of the
8533 -- concatenation, because the literal may be constant-folded away. This
8534 -- is a useful optimization for long concatenation expressions.
8536 -- If the string is an aggregate built for a single character (which
8537 -- happens in a non-static context) or a is null string to which special
8538 -- checks may apply, we build the subtype. Wide strings must also get a
8539 -- string subtype if they come from a one character aggregate. Strings
8540 -- generated by attributes might be static, but it is often hard to
8541 -- determine whether the enclosing context is static, so we generate
8542 -- subtypes for them as well, thus losing some rarer optimizations ???
8543 -- Same for strings that come from a static conversion.
8546 (Strlen = 0 and then Typ /= Standard_String)
8547 or else Nkind (Parent (N)) /= N_Op_Concat
8548 or else (N /= Left_Opnd (Parent (N))
8549 and then N /= Right_Opnd (Parent (N)))
8550 or else ((Typ = Standard_Wide_String
8551 or else Typ = Standard_Wide_Wide_String)
8552 and then Nkind (Original_Node (N)) /= N_String_Literal);
8554 -- If the resolving type is itself a string literal subtype, we can just
8555 -- reuse it, since there is no point in creating another.
8557 if Ekind (Typ) = E_String_Literal_Subtype then
8560 elsif Nkind (Parent (N)) = N_Op_Concat
8561 and then not Need_Check
8562 and then not Nkind_In (Original_Node (N), N_Character_Literal,
8563 N_Attribute_Reference,
8564 N_Qualified_Expression,
8569 -- Otherwise we must create a string literal subtype. Note that the
8570 -- whole idea of string literal subtypes is simply to avoid the need
8571 -- for building a full fledged array subtype for each literal.
8574 Set_String_Literal_Subtype (N, Typ);
8575 Subtype_Id := Etype (N);
8578 if Nkind (Parent (N)) /= N_Op_Concat
8581 Set_Etype (N, Subtype_Id);
8582 Eval_String_Literal (N);
8585 if Is_Limited_Composite (Typ)
8586 or else Is_Private_Composite (Typ)
8588 Error_Msg_N ("string literal not available for private array", N);
8589 Set_Etype (N, Any_Type);
8593 -- The validity of a null string has been checked in the call to
8594 -- Eval_String_Literal.
8599 -- Always accept string literal with component type Any_Character, which
8600 -- occurs in error situations and in comparisons of literals, both of
8601 -- which should accept all literals.
8603 elsif R_Typ = Any_Character then
8606 -- If the type is bit-packed, then we always transform the string
8607 -- literal into a full fledged aggregate.
8609 elsif Is_Bit_Packed_Array (Typ) then
8612 -- Deal with cases of Wide_Wide_String, Wide_String, and String
8615 -- For Standard.Wide_Wide_String, or any other type whose component
8616 -- type is Standard.Wide_Wide_Character, we know that all the
8617 -- characters in the string must be acceptable, since the parser
8618 -- accepted the characters as valid character literals.
8620 if R_Typ = Standard_Wide_Wide_Character then
8623 -- For the case of Standard.String, or any other type whose component
8624 -- type is Standard.Character, we must make sure that there are no
8625 -- wide characters in the string, i.e. that it is entirely composed
8626 -- of characters in range of type Character.
8628 -- If the string literal is the result of a static concatenation, the
8629 -- test has already been performed on the components, and need not be
8632 elsif R_Typ = Standard_Character
8633 and then Nkind (Original_Node (N)) /= N_Op_Concat
8635 for J in 1 .. Strlen loop
8636 if not In_Character_Range (Get_String_Char (Str, J)) then
8638 -- If we are out of range, post error. This is one of the
8639 -- very few places that we place the flag in the middle of
8640 -- a token, right under the offending wide character. Not
8641 -- quite clear if this is right wrt wide character encoding
8642 -- sequences, but it's only an error message!
8645 ("literal out of range of type Standard.Character",
8646 Source_Ptr (Int (Loc) + J));
8651 -- For the case of Standard.Wide_String, or any other type whose
8652 -- component type is Standard.Wide_Character, we must make sure that
8653 -- there are no wide characters in the string, i.e. that it is
8654 -- entirely composed of characters in range of type Wide_Character.
8656 -- If the string literal is the result of a static concatenation,
8657 -- the test has already been performed on the components, and need
8660 elsif R_Typ = Standard_Wide_Character
8661 and then Nkind (Original_Node (N)) /= N_Op_Concat
8663 for J in 1 .. Strlen loop
8664 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
8666 -- If we are out of range, post error. This is one of the
8667 -- very few places that we place the flag in the middle of
8668 -- a token, right under the offending wide character.
8670 -- This is not quite right, because characters in general
8671 -- will take more than one character position ???
8674 ("literal out of range of type Standard.Wide_Character",
8675 Source_Ptr (Int (Loc) + J));
8680 -- If the root type is not a standard character, then we will convert
8681 -- the string into an aggregate and will let the aggregate code do
8682 -- the checking. Standard Wide_Wide_Character is also OK here.
8688 -- See if the component type of the array corresponding to the string
8689 -- has compile time known bounds. If yes we can directly check
8690 -- whether the evaluation of the string will raise constraint error.
8691 -- Otherwise we need to transform the string literal into the
8692 -- corresponding character aggregate and let the aggregate
8693 -- code do the checking.
8695 if Is_Standard_Character_Type (R_Typ) then
8697 -- Check for the case of full range, where we are definitely OK
8699 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
8703 -- Here the range is not the complete base type range, so check
8706 Comp_Typ_Lo : constant Node_Id :=
8707 Type_Low_Bound (Component_Type (Typ));
8708 Comp_Typ_Hi : constant Node_Id :=
8709 Type_High_Bound (Component_Type (Typ));
8714 if Compile_Time_Known_Value (Comp_Typ_Lo)
8715 and then Compile_Time_Known_Value (Comp_Typ_Hi)
8717 for J in 1 .. Strlen loop
8718 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
8720 if Char_Val < Expr_Value (Comp_Typ_Lo)
8721 or else Char_Val > Expr_Value (Comp_Typ_Hi)
8723 Apply_Compile_Time_Constraint_Error
8724 (N, "character out of range?", CE_Range_Check_Failed,
8725 Loc => Source_Ptr (Int (Loc) + J));
8735 -- If we got here we meed to transform the string literal into the
8736 -- equivalent qualified positional array aggregate. This is rather
8737 -- heavy artillery for this situation, but it is hard work to avoid.
8740 Lits : constant List_Id := New_List;
8741 P : Source_Ptr := Loc + 1;
8745 -- Build the character literals, we give them source locations that
8746 -- correspond to the string positions, which is a bit tricky given
8747 -- the possible presence of wide character escape sequences.
8749 for J in 1 .. Strlen loop
8750 C := Get_String_Char (Str, J);
8751 Set_Character_Literal_Name (C);
8754 Make_Character_Literal (P,
8756 Char_Literal_Value => UI_From_CC (C)));
8758 if In_Character_Range (C) then
8761 -- Should we have a call to Skip_Wide here ???
8769 Make_Qualified_Expression (Loc,
8770 Subtype_Mark => New_Reference_To (Typ, Loc),
8772 Make_Aggregate (Loc, Expressions => Lits)));
8774 Analyze_And_Resolve (N, Typ);
8776 end Resolve_String_Literal;
8778 -----------------------------
8779 -- Resolve_Subprogram_Info --
8780 -----------------------------
8782 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
8785 end Resolve_Subprogram_Info;
8787 -----------------------------
8788 -- Resolve_Type_Conversion --
8789 -----------------------------
8791 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
8792 Conv_OK : constant Boolean := Conversion_OK (N);
8793 Operand : constant Node_Id := Expression (N);
8794 Operand_Typ : constant Entity_Id := Etype (Operand);
8795 Target_Typ : constant Entity_Id := Etype (N);
8800 Test_Redundant : Boolean := Warn_On_Redundant_Constructs;
8801 -- Set to False to suppress cases where we want to suppress the test
8802 -- for redundancy to avoid possible false positives on this warning.
8806 and then not Valid_Conversion (N, Target_Typ, Operand)
8811 -- If the Operand Etype is Universal_Fixed, then the conversion is
8812 -- never redundant. We need this check because by the time we have
8813 -- finished the rather complex transformation, the conversion looks
8814 -- redundant when it is not.
8816 if Operand_Typ = Universal_Fixed then
8817 Test_Redundant := False;
8819 -- If the operand is marked as Any_Fixed, then special processing is
8820 -- required. This is also a case where we suppress the test for a
8821 -- redundant conversion, since most certainly it is not redundant.
8823 elsif Operand_Typ = Any_Fixed then
8824 Test_Redundant := False;
8826 -- Mixed-mode operation involving a literal. Context must be a fixed
8827 -- type which is applied to the literal subsequently.
8829 if Is_Fixed_Point_Type (Typ) then
8830 Set_Etype (Operand, Universal_Real);
8832 elsif Is_Numeric_Type (Typ)
8833 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
8834 and then (Etype (Right_Opnd (Operand)) = Universal_Real
8836 Etype (Left_Opnd (Operand)) = Universal_Real)
8838 -- Return if expression is ambiguous
8840 if Unique_Fixed_Point_Type (N) = Any_Type then
8843 -- If nothing else, the available fixed type is Duration
8846 Set_Etype (Operand, Standard_Duration);
8849 -- Resolve the real operand with largest available precision
8851 if Etype (Right_Opnd (Operand)) = Universal_Real then
8852 Rop := New_Copy_Tree (Right_Opnd (Operand));
8854 Rop := New_Copy_Tree (Left_Opnd (Operand));
8857 Resolve (Rop, Universal_Real);
8859 -- If the operand is a literal (it could be a non-static and
8860 -- illegal exponentiation) check whether the use of Duration
8861 -- is potentially inaccurate.
8863 if Nkind (Rop) = N_Real_Literal
8864 and then Realval (Rop) /= Ureal_0
8865 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
8868 ("?universal real operand can only " &
8869 "be interpreted as Duration!",
8872 ("\?precision will be lost in the conversion!", Rop);
8875 elsif Is_Numeric_Type (Typ)
8876 and then Nkind (Operand) in N_Op
8877 and then Unique_Fixed_Point_Type (N) /= Any_Type
8879 Set_Etype (Operand, Standard_Duration);
8882 Error_Msg_N ("invalid context for mixed mode operation", N);
8883 Set_Etype (Operand, Any_Type);
8890 -- Note: we do the Eval_Type_Conversion call before applying the
8891 -- required checks for a subtype conversion. This is important, since
8892 -- both are prepared under certain circumstances to change the type
8893 -- conversion to a constraint error node, but in the case of
8894 -- Eval_Type_Conversion this may reflect an illegality in the static
8895 -- case, and we would miss the illegality (getting only a warning
8896 -- message), if we applied the type conversion checks first.
8898 Eval_Type_Conversion (N);
8900 -- Even when evaluation is not possible, we may be able to simplify the
8901 -- conversion or its expression. This needs to be done before applying
8902 -- checks, since otherwise the checks may use the original expression
8903 -- and defeat the simplifications. This is specifically the case for
8904 -- elimination of the floating-point Truncation attribute in
8905 -- float-to-int conversions.
8907 Simplify_Type_Conversion (N);
8909 -- If after evaluation we still have a type conversion, then we may need
8910 -- to apply checks required for a subtype conversion.
8912 -- Skip these type conversion checks if universal fixed operands
8913 -- operands involved, since range checks are handled separately for
8914 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
8916 if Nkind (N) = N_Type_Conversion
8917 and then not Is_Generic_Type (Root_Type (Target_Typ))
8918 and then Target_Typ /= Universal_Fixed
8919 and then Operand_Typ /= Universal_Fixed
8921 Apply_Type_Conversion_Checks (N);
8924 -- Issue warning for conversion of simple object to its own type. We
8925 -- have to test the original nodes, since they may have been rewritten
8926 -- by various optimizations.
8928 Orig_N := Original_Node (N);
8930 -- Here we test for a redundant conversion if the warning mode is
8931 -- active (and was not locally reset), and we have a type conversion
8932 -- from source not appearing in a generic instance.
8935 and then Nkind (Orig_N) = N_Type_Conversion
8936 and then Comes_From_Source (Orig_N)
8937 and then not In_Instance
8939 Orig_N := Original_Node (Expression (Orig_N));
8940 Orig_T := Target_Typ;
8942 -- If the node is part of a larger expression, the Target_Type
8943 -- may not be the original type of the node if the context is a
8944 -- condition. Recover original type to see if conversion is needed.
8946 if Is_Boolean_Type (Orig_T)
8947 and then Nkind (Parent (N)) in N_Op
8949 Orig_T := Etype (Parent (N));
8952 -- If we have an entity name, then give the warning if the entity
8953 -- is the right type, or if it is a loop parameter covered by the
8954 -- original type (that's needed because loop parameters have an
8955 -- odd subtype coming from the bounds).
8957 if (Is_Entity_Name (Orig_N)
8959 (Etype (Entity (Orig_N)) = Orig_T
8961 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
8962 and then Covers (Orig_T, Etype (Entity (Orig_N))))))
8964 -- If not an entity, then type of expression must match
8966 or else Etype (Orig_N) = Orig_T
8968 -- One more check, do not give warning if the analyzed conversion
8969 -- has an expression with non-static bounds, and the bounds of the
8970 -- target are static. This avoids junk warnings in cases where the
8971 -- conversion is necessary to establish staticness, for example in
8972 -- a case statement.
8974 if not Is_OK_Static_Subtype (Operand_Typ)
8975 and then Is_OK_Static_Subtype (Target_Typ)
8979 -- Finally, if this type conversion occurs in a context that
8980 -- requires a prefix, and the expression is a qualified expression
8981 -- then the type conversion is not redundant, because a qualified
8982 -- expression is not a prefix, whereas a type conversion is. For
8983 -- example, "X := T'(Funx(...)).Y;" is illegal because a selected
8984 -- component requires a prefix, but a type conversion makes it
8985 -- legal: "X := T(T'(Funx(...))).Y;"
8987 -- In Ada 2012, a qualified expression is a name, so this idiom is
8988 -- no longer needed, but we still suppress the warning because it
8989 -- seems unfriendly for warnings to pop up when you switch to the
8990 -- newer language version.
8992 elsif Nkind (Orig_N) = N_Qualified_Expression
8993 and then Nkind_In (Parent (N), N_Attribute_Reference,
8994 N_Indexed_Component,
8995 N_Selected_Component,
8997 N_Explicit_Dereference)
9001 -- Here we give the redundant conversion warning. If it is an
9002 -- entity, give the name of the entity in the message. If not,
9003 -- just mention the expression.
9006 if Is_Entity_Name (Orig_N) then
9007 Error_Msg_Node_2 := Orig_T;
9008 Error_Msg_NE -- CODEFIX
9009 ("?redundant conversion, & is of type &!",
9010 N, Entity (Orig_N));
9013 ("?redundant conversion, expression is of type&!",
9020 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
9021 -- No need to perform any interface conversion if the type of the
9022 -- expression coincides with the target type.
9024 if Ada_Version >= Ada_2005
9025 and then Expander_Active
9026 and then Operand_Typ /= Target_Typ
9029 Opnd : Entity_Id := Operand_Typ;
9030 Target : Entity_Id := Target_Typ;
9033 if Is_Access_Type (Opnd) then
9034 Opnd := Designated_Type (Opnd);
9037 if Is_Access_Type (Target_Typ) then
9038 Target := Designated_Type (Target);
9041 if Opnd = Target then
9044 -- Conversion from interface type
9046 elsif Is_Interface (Opnd) then
9048 -- Ada 2005 (AI-217): Handle entities from limited views
9050 if From_With_Type (Opnd) then
9051 Error_Msg_Qual_Level := 99;
9052 Error_Msg_NE -- CODEFIX
9053 ("missing WITH clause on package &", N,
9054 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
9056 ("type conversions require visibility of the full view",
9059 elsif From_With_Type (Target)
9061 (Is_Access_Type (Target_Typ)
9062 and then Present (Non_Limited_View (Etype (Target))))
9064 Error_Msg_Qual_Level := 99;
9065 Error_Msg_NE -- CODEFIX
9066 ("missing WITH clause on package &", N,
9067 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
9069 ("type conversions require visibility of the full view",
9073 Expand_Interface_Conversion (N, Is_Static => False);
9076 -- Conversion to interface type
9078 elsif Is_Interface (Target) then
9082 if Ekind_In (Opnd, E_Protected_Subtype, E_Task_Subtype) then
9083 Opnd := Etype (Opnd);
9086 if not Interface_Present_In_Ancestor
9090 if Is_Class_Wide_Type (Opnd) then
9092 -- The static analysis is not enough to know if the
9093 -- interface is implemented or not. Hence we must pass
9094 -- the work to the expander to generate code to evaluate
9095 -- the conversion at run time.
9097 Expand_Interface_Conversion (N, Is_Static => False);
9100 Error_Msg_Name_1 := Chars (Etype (Target));
9101 Error_Msg_Name_2 := Chars (Opnd);
9103 ("wrong interface conversion (% is not a progenitor " &
9108 Expand_Interface_Conversion (N);
9113 end Resolve_Type_Conversion;
9115 ----------------------
9116 -- Resolve_Unary_Op --
9117 ----------------------
9119 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
9120 B_Typ : constant Entity_Id := Base_Type (Typ);
9121 R : constant Node_Id := Right_Opnd (N);
9127 -- Deal with intrinsic unary operators
9129 if Comes_From_Source (N)
9130 and then Ekind (Entity (N)) = E_Function
9131 and then Is_Imported (Entity (N))
9132 and then Is_Intrinsic_Subprogram (Entity (N))
9134 Resolve_Intrinsic_Unary_Operator (N, Typ);
9138 -- Deal with universal cases
9140 if Etype (R) = Universal_Integer
9142 Etype (R) = Universal_Real
9144 Check_For_Visible_Operator (N, B_Typ);
9147 Set_Etype (N, B_Typ);
9150 -- Generate warning for expressions like abs (x mod 2)
9152 if Warn_On_Redundant_Constructs
9153 and then Nkind (N) = N_Op_Abs
9155 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
9157 if OK and then Hi >= Lo and then Lo >= 0 then
9158 Error_Msg_N -- CODEFIX
9159 ("?abs applied to known non-negative value has no effect", N);
9163 -- Deal with reference generation
9165 Check_Unset_Reference (R);
9166 Generate_Operator_Reference (N, B_Typ);
9169 -- Set overflow checking bit. Much cleverer code needed here eventually
9170 -- and perhaps the Resolve routines should be separated for the various
9171 -- arithmetic operations, since they will need different processing ???
9173 if Nkind (N) in N_Op then
9174 if not Overflow_Checks_Suppressed (Etype (N)) then
9175 Enable_Overflow_Check (N);
9179 -- Generate warning for expressions like -5 mod 3 for integers. No need
9180 -- to worry in the floating-point case, since parens do not affect the
9181 -- result so there is no point in giving in a warning.
9184 Norig : constant Node_Id := Original_Node (N);
9193 if Warn_On_Questionable_Missing_Parens
9194 and then Comes_From_Source (Norig)
9195 and then Is_Integer_Type (Typ)
9196 and then Nkind (Norig) = N_Op_Minus
9198 Rorig := Original_Node (Right_Opnd (Norig));
9200 -- We are looking for cases where the right operand is not
9201 -- parenthesized, and is a binary operator, multiply, divide, or
9202 -- mod. These are the cases where the grouping can affect results.
9204 if Paren_Count (Rorig) = 0
9205 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
9207 -- For mod, we always give the warning, since the value is
9208 -- affected by the parenthesization (e.g. (-5) mod 315 /=
9209 -- -(5 mod 315)). But for the other cases, the only concern is
9210 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
9211 -- overflows, but (-2) * 64 does not). So we try to give the
9212 -- message only when overflow is possible.
9214 if Nkind (Rorig) /= N_Op_Mod
9215 and then Compile_Time_Known_Value (R)
9217 Val := Expr_Value (R);
9219 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
9220 HB := Expr_Value (Type_High_Bound (Typ));
9222 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
9225 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
9226 LB := Expr_Value (Type_Low_Bound (Typ));
9228 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
9231 -- Note that the test below is deliberately excluding the
9232 -- largest negative number, since that is a potentially
9233 -- troublesome case (e.g. -2 * x, where the result is the
9234 -- largest negative integer has an overflow with 2 * x).
9236 if Val > LB and then Val <= HB then
9241 -- For the multiplication case, the only case we have to worry
9242 -- about is when (-a)*b is exactly the largest negative number
9243 -- so that -(a*b) can cause overflow. This can only happen if
9244 -- a is a power of 2, and more generally if any operand is a
9245 -- constant that is not a power of 2, then the parentheses
9246 -- cannot affect whether overflow occurs. We only bother to
9247 -- test the left most operand
9249 -- Loop looking at left operands for one that has known value
9252 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
9253 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
9254 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
9256 -- Operand value of 0 or 1 skips warning
9261 -- Otherwise check power of 2, if power of 2, warn, if
9262 -- anything else, skip warning.
9265 while Lval /= 2 loop
9266 if Lval mod 2 = 1 then
9277 -- Keep looking at left operands
9279 Opnd := Left_Opnd (Opnd);
9282 -- For rem or "/" we can only have a problematic situation
9283 -- if the divisor has a value of minus one or one. Otherwise
9284 -- overflow is impossible (divisor > 1) or we have a case of
9285 -- division by zero in any case.
9287 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
9288 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
9289 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
9294 -- If we fall through warning should be issued
9297 ("?unary minus expression should be parenthesized here!", N);
9301 end Resolve_Unary_Op;
9303 ----------------------------------
9304 -- Resolve_Unchecked_Expression --
9305 ----------------------------------
9307 procedure Resolve_Unchecked_Expression
9312 Resolve (Expression (N), Typ, Suppress => All_Checks);
9314 end Resolve_Unchecked_Expression;
9316 ---------------------------------------
9317 -- Resolve_Unchecked_Type_Conversion --
9318 ---------------------------------------
9320 procedure Resolve_Unchecked_Type_Conversion
9324 pragma Warnings (Off, Typ);
9326 Operand : constant Node_Id := Expression (N);
9327 Opnd_Type : constant Entity_Id := Etype (Operand);
9330 -- Resolve operand using its own type
9332 Resolve (Operand, Opnd_Type);
9333 Eval_Unchecked_Conversion (N);
9334 end Resolve_Unchecked_Type_Conversion;
9336 ------------------------------
9337 -- Rewrite_Operator_As_Call --
9338 ------------------------------
9340 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
9341 Loc : constant Source_Ptr := Sloc (N);
9342 Actuals : constant List_Id := New_List;
9346 if Nkind (N) in N_Binary_Op then
9347 Append (Left_Opnd (N), Actuals);
9350 Append (Right_Opnd (N), Actuals);
9353 Make_Function_Call (Sloc => Loc,
9354 Name => New_Occurrence_Of (Nam, Loc),
9355 Parameter_Associations => Actuals);
9357 Preserve_Comes_From_Source (New_N, N);
9358 Preserve_Comes_From_Source (Name (New_N), N);
9360 Set_Etype (N, Etype (Nam));
9361 end Rewrite_Operator_As_Call;
9363 ------------------------------
9364 -- Rewrite_Renamed_Operator --
9365 ------------------------------
9367 procedure Rewrite_Renamed_Operator
9372 Nam : constant Name_Id := Chars (Op);
9373 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
9377 -- Rewrite the operator node using the real operator, not its renaming.
9378 -- Exclude user-defined intrinsic operations of the same name, which are
9379 -- treated separately and rewritten as calls.
9381 if Ekind (Op) /= E_Function or else Chars (N) /= Nam then
9382 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
9383 Set_Chars (Op_Node, Nam);
9384 Set_Etype (Op_Node, Etype (N));
9385 Set_Entity (Op_Node, Op);
9386 Set_Right_Opnd (Op_Node, Right_Opnd (N));
9388 -- Indicate that both the original entity and its renaming are
9389 -- referenced at this point.
9391 Generate_Reference (Entity (N), N);
9392 Generate_Reference (Op, N);
9395 Set_Left_Opnd (Op_Node, Left_Opnd (N));
9398 Rewrite (N, Op_Node);
9400 -- If the context type is private, add the appropriate conversions so
9401 -- that the operator is applied to the full view. This is done in the
9402 -- routines that resolve intrinsic operators.
9404 if Is_Intrinsic_Subprogram (Op)
9405 and then Is_Private_Type (Typ)
9408 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
9409 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
9410 Resolve_Intrinsic_Operator (N, Typ);
9412 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
9413 Resolve_Intrinsic_Unary_Operator (N, Typ);
9420 elsif Ekind (Op) = E_Function and then Is_Intrinsic_Subprogram (Op) then
9422 -- Operator renames a user-defined operator of the same name. Use the
9423 -- original operator in the node, which is the one Gigi knows about.
9426 Set_Is_Overloaded (N, False);
9428 end Rewrite_Renamed_Operator;
9430 -----------------------
9431 -- Set_Slice_Subtype --
9432 -----------------------
9434 -- Build an implicit subtype declaration to represent the type delivered by
9435 -- the slice. This is an abbreviated version of an array subtype. We define
9436 -- an index subtype for the slice, using either the subtype name or the
9437 -- discrete range of the slice. To be consistent with index usage elsewhere
9438 -- we create a list header to hold the single index. This list is not
9439 -- otherwise attached to the syntax tree.
9441 procedure Set_Slice_Subtype (N : Node_Id) is
9442 Loc : constant Source_Ptr := Sloc (N);
9443 Index_List : constant List_Id := New_List;
9445 Index_Subtype : Entity_Id;
9446 Index_Type : Entity_Id;
9447 Slice_Subtype : Entity_Id;
9448 Drange : constant Node_Id := Discrete_Range (N);
9451 if Is_Entity_Name (Drange) then
9452 Index_Subtype := Entity (Drange);
9455 -- We force the evaluation of a range. This is definitely needed in
9456 -- the renamed case, and seems safer to do unconditionally. Note in
9457 -- any case that since we will create and insert an Itype referring
9458 -- to this range, we must make sure any side effect removal actions
9459 -- are inserted before the Itype definition.
9461 if Nkind (Drange) = N_Range then
9462 Force_Evaluation (Low_Bound (Drange));
9463 Force_Evaluation (High_Bound (Drange));
9466 Index_Type := Base_Type (Etype (Drange));
9468 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9470 -- Take a new copy of Drange (where bounds have been rewritten to
9471 -- reference side-effect-free names). Using a separate tree ensures
9472 -- that further expansion (e.g. while rewriting a slice assignment
9473 -- into a FOR loop) does not attempt to remove side effects on the
9474 -- bounds again (which would cause the bounds in the index subtype
9475 -- definition to refer to temporaries before they are defined) (the
9476 -- reason is that some names are considered side effect free here
9477 -- for the subtype, but not in the context of a loop iteration
9480 Set_Scalar_Range (Index_Subtype, New_Copy_Tree (Drange));
9481 Set_Etype (Index_Subtype, Index_Type);
9482 Set_Size_Info (Index_Subtype, Index_Type);
9483 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9486 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
9488 Index := New_Occurrence_Of (Index_Subtype, Loc);
9489 Set_Etype (Index, Index_Subtype);
9490 Append (Index, Index_List);
9492 Set_First_Index (Slice_Subtype, Index);
9493 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
9494 Set_Is_Constrained (Slice_Subtype, True);
9496 Check_Compile_Time_Size (Slice_Subtype);
9498 -- The Etype of the existing Slice node is reset to this slice subtype.
9499 -- Its bounds are obtained from its first index.
9501 Set_Etype (N, Slice_Subtype);
9503 -- For packed slice subtypes, freeze immediately (except in the
9504 -- case of being in a "spec expression" where we never freeze
9505 -- when we first see the expression).
9507 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
9508 Freeze_Itype (Slice_Subtype, N);
9510 -- For all other cases insert an itype reference in the slice's actions
9511 -- so that the itype is frozen at the proper place in the tree (i.e. at
9512 -- the point where actions for the slice are analyzed). Note that this
9513 -- is different from freezing the itype immediately, which might be
9514 -- premature (e.g. if the slice is within a transient scope).
9517 Ensure_Defined (Typ => Slice_Subtype, N => N);
9519 end Set_Slice_Subtype;
9521 --------------------------------
9522 -- Set_String_Literal_Subtype --
9523 --------------------------------
9525 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
9526 Loc : constant Source_Ptr := Sloc (N);
9527 Low_Bound : constant Node_Id :=
9528 Type_Low_Bound (Etype (First_Index (Typ)));
9529 Subtype_Id : Entity_Id;
9532 if Nkind (N) /= N_String_Literal then
9536 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
9537 Set_String_Literal_Length (Subtype_Id, UI_From_Int
9538 (String_Length (Strval (N))));
9539 Set_Etype (Subtype_Id, Base_Type (Typ));
9540 Set_Is_Constrained (Subtype_Id);
9541 Set_Etype (N, Subtype_Id);
9543 if Is_OK_Static_Expression (Low_Bound) then
9545 -- The low bound is set from the low bound of the corresponding index
9546 -- type. Note that we do not store the high bound in the string literal
9547 -- subtype, but it can be deduced if necessary from the length and the
9550 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
9553 Set_String_Literal_Low_Bound
9554 (Subtype_Id, Make_Integer_Literal (Loc, 1));
9555 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Standard_Positive);
9557 -- Build bona fide subtype for the string, and wrap it in an
9558 -- unchecked conversion, because the backend expects the
9559 -- String_Literal_Subtype to have a static lower bound.
9562 Index_List : constant List_Id := New_List;
9563 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
9564 High_Bound : constant Node_Id :=
9566 Left_Opnd => New_Copy_Tree (Low_Bound),
9568 Make_Integer_Literal (Loc,
9569 String_Length (Strval (N)) - 1));
9570 Array_Subtype : Entity_Id;
9571 Index_Subtype : Entity_Id;
9577 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9578 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
9579 Set_Scalar_Range (Index_Subtype, Drange);
9580 Set_Parent (Drange, N);
9581 Analyze_And_Resolve (Drange, Index_Type);
9583 -- In the context, the Index_Type may already have a constraint,
9584 -- so use common base type on string subtype. The base type may
9585 -- be used when generating attributes of the string, for example
9586 -- in the context of a slice assignment.
9588 Set_Etype (Index_Subtype, Base_Type (Index_Type));
9589 Set_Size_Info (Index_Subtype, Index_Type);
9590 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9592 Array_Subtype := Create_Itype (E_Array_Subtype, N);
9594 Index := New_Occurrence_Of (Index_Subtype, Loc);
9595 Set_Etype (Index, Index_Subtype);
9596 Append (Index, Index_List);
9598 Set_First_Index (Array_Subtype, Index);
9599 Set_Etype (Array_Subtype, Base_Type (Typ));
9600 Set_Is_Constrained (Array_Subtype, True);
9603 Make_Unchecked_Type_Conversion (Loc,
9604 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
9605 Expression => Relocate_Node (N)));
9606 Set_Etype (N, Array_Subtype);
9609 end Set_String_Literal_Subtype;
9611 ------------------------------
9612 -- Simplify_Type_Conversion --
9613 ------------------------------
9615 procedure Simplify_Type_Conversion (N : Node_Id) is
9617 if Nkind (N) = N_Type_Conversion then
9619 Operand : constant Node_Id := Expression (N);
9620 Target_Typ : constant Entity_Id := Etype (N);
9621 Opnd_Typ : constant Entity_Id := Etype (Operand);
9624 if Is_Floating_Point_Type (Opnd_Typ)
9626 (Is_Integer_Type (Target_Typ)
9627 or else (Is_Fixed_Point_Type (Target_Typ)
9628 and then Conversion_OK (N)))
9629 and then Nkind (Operand) = N_Attribute_Reference
9630 and then Attribute_Name (Operand) = Name_Truncation
9632 -- Special processing required if the conversion is the expression
9633 -- of a Truncation attribute reference. In this case we replace:
9635 -- ityp (ftyp'Truncation (x))
9641 -- with the Float_Truncate flag set, which is more efficient.
9645 Relocate_Node (First (Expressions (Operand))));
9646 Set_Float_Truncate (N, True);
9650 end Simplify_Type_Conversion;
9652 -----------------------------
9653 -- Unique_Fixed_Point_Type --
9654 -----------------------------
9656 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
9657 T1 : Entity_Id := Empty;
9662 procedure Fixed_Point_Error;
9663 -- Give error messages for true ambiguity. Messages are posted on node
9664 -- N, and entities T1, T2 are the possible interpretations.
9666 -----------------------
9667 -- Fixed_Point_Error --
9668 -----------------------
9670 procedure Fixed_Point_Error is
9672 Error_Msg_N ("ambiguous universal_fixed_expression", N);
9673 Error_Msg_NE ("\\possible interpretation as}", N, T1);
9674 Error_Msg_NE ("\\possible interpretation as}", N, T2);
9675 end Fixed_Point_Error;
9677 -- Start of processing for Unique_Fixed_Point_Type
9680 -- The operations on Duration are visible, so Duration is always a
9681 -- possible interpretation.
9683 T1 := Standard_Duration;
9685 -- Look for fixed-point types in enclosing scopes
9687 Scop := Current_Scope;
9688 while Scop /= Standard_Standard loop
9689 T2 := First_Entity (Scop);
9690 while Present (T2) loop
9691 if Is_Fixed_Point_Type (T2)
9692 and then Current_Entity (T2) = T2
9693 and then Scope (Base_Type (T2)) = Scop
9695 if Present (T1) then
9706 Scop := Scope (Scop);
9709 -- Look for visible fixed type declarations in the context
9711 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
9712 while Present (Item) loop
9713 if Nkind (Item) = N_With_Clause then
9714 Scop := Entity (Name (Item));
9715 T2 := First_Entity (Scop);
9716 while Present (T2) loop
9717 if Is_Fixed_Point_Type (T2)
9718 and then Scope (Base_Type (T2)) = Scop
9719 and then (Is_Potentially_Use_Visible (T2)
9720 or else In_Use (T2))
9722 if Present (T1) then
9737 if Nkind (N) = N_Real_Literal then
9738 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
9740 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
9744 end Unique_Fixed_Point_Type;
9746 ----------------------
9747 -- Valid_Conversion --
9748 ----------------------
9750 function Valid_Conversion
9753 Operand : Node_Id) return Boolean
9755 Target_Type : constant Entity_Id := Base_Type (Target);
9756 Opnd_Type : Entity_Id := Etype (Operand);
9758 function Conversion_Check
9760 Msg : String) return Boolean;
9761 -- Little routine to post Msg if Valid is False, returns Valid value
9763 function Valid_Tagged_Conversion
9764 (Target_Type : Entity_Id;
9765 Opnd_Type : Entity_Id) return Boolean;
9766 -- Specifically test for validity of tagged conversions
9768 function Valid_Array_Conversion return Boolean;
9769 -- Check index and component conformance, and accessibility levels if
9770 -- the component types are anonymous access types (Ada 2005).
9772 ----------------------
9773 -- Conversion_Check --
9774 ----------------------
9776 function Conversion_Check
9778 Msg : String) return Boolean
9782 Error_Msg_N (Msg, Operand);
9786 end Conversion_Check;
9788 ----------------------------
9789 -- Valid_Array_Conversion --
9790 ----------------------------
9792 function Valid_Array_Conversion return Boolean
9794 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
9795 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
9797 Opnd_Index : Node_Id;
9798 Opnd_Index_Type : Entity_Id;
9800 Target_Comp_Type : constant Entity_Id :=
9801 Component_Type (Target_Type);
9802 Target_Comp_Base : constant Entity_Id :=
9803 Base_Type (Target_Comp_Type);
9805 Target_Index : Node_Id;
9806 Target_Index_Type : Entity_Id;
9809 -- Error if wrong number of dimensions
9812 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
9815 ("incompatible number of dimensions for conversion", Operand);
9818 -- Number of dimensions matches
9821 -- Loop through indexes of the two arrays
9823 Target_Index := First_Index (Target_Type);
9824 Opnd_Index := First_Index (Opnd_Type);
9825 while Present (Target_Index) and then Present (Opnd_Index) loop
9826 Target_Index_Type := Etype (Target_Index);
9827 Opnd_Index_Type := Etype (Opnd_Index);
9829 -- Error if index types are incompatible
9831 if not (Is_Integer_Type (Target_Index_Type)
9832 and then Is_Integer_Type (Opnd_Index_Type))
9833 and then (Root_Type (Target_Index_Type)
9834 /= Root_Type (Opnd_Index_Type))
9837 ("incompatible index types for array conversion",
9842 Next_Index (Target_Index);
9843 Next_Index (Opnd_Index);
9846 -- If component types have same base type, all set
9848 if Target_Comp_Base = Opnd_Comp_Base then
9851 -- Here if base types of components are not the same. The only
9852 -- time this is allowed is if we have anonymous access types.
9854 -- The conversion of arrays of anonymous access types can lead
9855 -- to dangling pointers. AI-392 formalizes the accessibility
9856 -- checks that must be applied to such conversions to prevent
9857 -- out-of-scope references.
9860 Ekind_In (Target_Comp_Base, E_Anonymous_Access_Type,
9861 E_Anonymous_Access_Subprogram_Type)
9862 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
9864 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
9866 if Type_Access_Level (Target_Type) <
9867 Type_Access_Level (Opnd_Type)
9869 if In_Instance_Body then
9870 Error_Msg_N ("?source array type " &
9871 "has deeper accessibility level than target", Operand);
9872 Error_Msg_N ("\?Program_Error will be raised at run time",
9875 Make_Raise_Program_Error (Sloc (N),
9876 Reason => PE_Accessibility_Check_Failed));
9877 Set_Etype (N, Target_Type);
9880 -- Conversion not allowed because of accessibility levels
9883 Error_Msg_N ("source array type " &
9884 "has deeper accessibility level than target", Operand);
9891 -- All other cases where component base types do not match
9895 ("incompatible component types for array conversion",
9900 -- Check that component subtypes statically match. For numeric
9901 -- types this means that both must be either constrained or
9902 -- unconstrained. For enumeration types the bounds must match.
9903 -- All of this is checked in Subtypes_Statically_Match.
9905 if not Subtypes_Statically_Match
9906 (Target_Comp_Type, Opnd_Comp_Type)
9909 ("component subtypes must statically match", Operand);
9915 end Valid_Array_Conversion;
9917 -----------------------------
9918 -- Valid_Tagged_Conversion --
9919 -----------------------------
9921 function Valid_Tagged_Conversion
9922 (Target_Type : Entity_Id;
9923 Opnd_Type : Entity_Id) return Boolean
9926 -- Upward conversions are allowed (RM 4.6(22))
9928 if Covers (Target_Type, Opnd_Type)
9929 or else Is_Ancestor (Target_Type, Opnd_Type)
9933 -- Downward conversion are allowed if the operand is class-wide
9936 elsif Is_Class_Wide_Type (Opnd_Type)
9937 and then Covers (Opnd_Type, Target_Type)
9941 elsif Covers (Opnd_Type, Target_Type)
9942 or else Is_Ancestor (Opnd_Type, Target_Type)
9945 Conversion_Check (False,
9946 "downward conversion of tagged objects not allowed");
9948 -- Ada 2005 (AI-251): The conversion to/from interface types is
9951 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
9954 -- If the operand is a class-wide type obtained through a limited_
9955 -- with clause, and the context includes the non-limited view, use
9956 -- it to determine whether the conversion is legal.
9958 elsif Is_Class_Wide_Type (Opnd_Type)
9959 and then From_With_Type (Opnd_Type)
9960 and then Present (Non_Limited_View (Etype (Opnd_Type)))
9961 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
9965 elsif Is_Access_Type (Opnd_Type)
9966 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
9972 ("invalid tagged conversion, not compatible with}",
9973 N, First_Subtype (Opnd_Type));
9976 end Valid_Tagged_Conversion;
9978 -- Start of processing for Valid_Conversion
9981 Check_Parameterless_Call (Operand);
9983 if Is_Overloaded (Operand) then
9993 -- Remove procedure calls, which syntactically cannot appear in
9994 -- this context, but which cannot be removed by type checking,
9995 -- because the context does not impose a type.
9997 -- When compiling for VMS, spurious ambiguities can be produced
9998 -- when arithmetic operations have a literal operand and return
9999 -- System.Address or a descendant of it. These ambiguities are
10000 -- otherwise resolved by the context, but for conversions there
10001 -- is no context type and the removal of the spurious operations
10002 -- must be done explicitly here.
10004 -- The node may be labelled overloaded, but still contain only one
10005 -- interpretation because others were discarded earlier. If this
10006 -- is the case, retain the single interpretation if legal.
10008 Get_First_Interp (Operand, I, It);
10009 Opnd_Type := It.Typ;
10010 Get_Next_Interp (I, It);
10012 if Present (It.Typ)
10013 and then Opnd_Type /= Standard_Void_Type
10015 -- More than one candidate interpretation is available
10017 Get_First_Interp (Operand, I, It);
10018 while Present (It.Typ) loop
10019 if It.Typ = Standard_Void_Type then
10023 if Present (System_Aux_Id)
10024 and then Is_Descendent_Of_Address (It.Typ)
10029 Get_Next_Interp (I, It);
10033 Get_First_Interp (Operand, I, It);
10037 if No (It.Typ) then
10038 Error_Msg_N ("illegal operand in conversion", Operand);
10042 Get_Next_Interp (I, It);
10044 if Present (It.Typ) then
10047 It1 := Disambiguate (Operand, I1, I, Any_Type);
10049 if It1 = No_Interp then
10050 Error_Msg_N ("ambiguous operand in conversion", Operand);
10052 -- If the interpretation involves a standard operator, use
10053 -- the location of the type, which may be user-defined.
10055 if Sloc (It.Nam) = Standard_Location then
10056 Error_Msg_Sloc := Sloc (It.Typ);
10058 Error_Msg_Sloc := Sloc (It.Nam);
10061 Error_Msg_N -- CODEFIX
10062 ("\\possible interpretation#!", Operand);
10064 if Sloc (N1) = Standard_Location then
10065 Error_Msg_Sloc := Sloc (T1);
10067 Error_Msg_Sloc := Sloc (N1);
10070 Error_Msg_N -- CODEFIX
10071 ("\\possible interpretation#!", Operand);
10077 Set_Etype (Operand, It1.Typ);
10078 Opnd_Type := It1.Typ;
10084 if Is_Numeric_Type (Target_Type) then
10086 -- A universal fixed expression can be converted to any numeric type
10088 if Opnd_Type = Universal_Fixed then
10091 -- Also no need to check when in an instance or inlined body, because
10092 -- the legality has been established when the template was analyzed.
10093 -- Furthermore, numeric conversions may occur where only a private
10094 -- view of the operand type is visible at the instantiation point.
10095 -- This results in a spurious error if we check that the operand type
10096 -- is a numeric type.
10098 -- Note: in a previous version of this unit, the following tests were
10099 -- applied only for generated code (Comes_From_Source set to False),
10100 -- but in fact the test is required for source code as well, since
10101 -- this situation can arise in source code.
10103 elsif In_Instance or else In_Inlined_Body then
10106 -- Otherwise we need the conversion check
10109 return Conversion_Check
10110 (Is_Numeric_Type (Opnd_Type),
10111 "illegal operand for numeric conversion");
10116 elsif Is_Array_Type (Target_Type) then
10117 if not Is_Array_Type (Opnd_Type)
10118 or else Opnd_Type = Any_Composite
10119 or else Opnd_Type = Any_String
10121 Error_Msg_N ("illegal operand for array conversion", Operand);
10124 return Valid_Array_Conversion;
10127 -- Ada 2005 (AI-251): Anonymous access types where target references an
10130 elsif Ekind_In (Target_Type, E_General_Access_Type,
10131 E_Anonymous_Access_Type)
10132 and then Is_Interface (Directly_Designated_Type (Target_Type))
10134 -- Check the static accessibility rule of 4.6(17). Note that the
10135 -- check is not enforced when within an instance body, since the
10136 -- RM requires such cases to be caught at run time.
10138 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
10139 if Type_Access_Level (Opnd_Type) >
10140 Type_Access_Level (Target_Type)
10142 -- In an instance, this is a run-time check, but one we know
10143 -- will fail, so generate an appropriate warning. The raise
10144 -- will be generated by Expand_N_Type_Conversion.
10146 if In_Instance_Body then
10148 ("?cannot convert local pointer to non-local access type",
10151 ("\?Program_Error will be raised at run time", Operand);
10154 ("cannot convert local pointer to non-local access type",
10159 -- Special accessibility checks are needed in the case of access
10160 -- discriminants declared for a limited type.
10162 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10163 and then not Is_Local_Anonymous_Access (Opnd_Type)
10165 -- When the operand is a selected access discriminant the check
10166 -- needs to be made against the level of the object denoted by
10167 -- the prefix of the selected name (Object_Access_Level handles
10168 -- checking the prefix of the operand for this case).
10170 if Nkind (Operand) = N_Selected_Component
10171 and then Object_Access_Level (Operand) >
10172 Type_Access_Level (Target_Type)
10174 -- In an instance, this is a run-time check, but one we know
10175 -- will fail, so generate an appropriate warning. The raise
10176 -- will be generated by Expand_N_Type_Conversion.
10178 if In_Instance_Body then
10180 ("?cannot convert access discriminant to non-local" &
10181 " access type", Operand);
10183 ("\?Program_Error will be raised at run time", Operand);
10186 ("cannot convert access discriminant to non-local" &
10187 " access type", Operand);
10192 -- The case of a reference to an access discriminant from
10193 -- within a limited type declaration (which will appear as
10194 -- a discriminal) is always illegal because the level of the
10195 -- discriminant is considered to be deeper than any (nameable)
10198 if Is_Entity_Name (Operand)
10199 and then not Is_Local_Anonymous_Access (Opnd_Type)
10201 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10202 and then Present (Discriminal_Link (Entity (Operand)))
10205 ("discriminant has deeper accessibility level than target",
10214 -- General and anonymous access types
10216 elsif Ekind_In (Target_Type, E_General_Access_Type,
10217 E_Anonymous_Access_Type)
10220 (Is_Access_Type (Opnd_Type)
10222 Ekind_In (Opnd_Type, E_Access_Subprogram_Type,
10223 E_Access_Protected_Subprogram_Type),
10224 "must be an access-to-object type")
10226 if Is_Access_Constant (Opnd_Type)
10227 and then not Is_Access_Constant (Target_Type)
10230 ("access-to-constant operand type not allowed", Operand);
10234 -- Check the static accessibility rule of 4.6(17). Note that the
10235 -- check is not enforced when within an instance body, since the RM
10236 -- requires such cases to be caught at run time.
10238 if Ekind (Target_Type) /= E_Anonymous_Access_Type
10239 or else Is_Local_Anonymous_Access (Target_Type)
10241 if Type_Access_Level (Opnd_Type)
10242 > Type_Access_Level (Target_Type)
10244 -- In an instance, this is a run-time check, but one we know
10245 -- will fail, so generate an appropriate warning. The raise
10246 -- will be generated by Expand_N_Type_Conversion.
10248 if In_Instance_Body then
10250 ("?cannot convert local pointer to non-local access type",
10253 ("\?Program_Error will be raised at run time", Operand);
10256 -- Avoid generation of spurious error message
10258 if not Error_Posted (N) then
10260 ("cannot convert local pointer to non-local access type",
10267 -- Special accessibility checks are needed in the case of access
10268 -- discriminants declared for a limited type.
10270 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10271 and then not Is_Local_Anonymous_Access (Opnd_Type)
10273 -- When the operand is a selected access discriminant the check
10274 -- needs to be made against the level of the object denoted by
10275 -- the prefix of the selected name (Object_Access_Level handles
10276 -- checking the prefix of the operand for this case).
10278 if Nkind (Operand) = N_Selected_Component
10279 and then Object_Access_Level (Operand) >
10280 Type_Access_Level (Target_Type)
10282 -- In an instance, this is a run-time check, but one we know
10283 -- will fail, so generate an appropriate warning. The raise
10284 -- will be generated by Expand_N_Type_Conversion.
10286 if In_Instance_Body then
10288 ("?cannot convert access discriminant to non-local" &
10289 " access type", Operand);
10291 ("\?Program_Error will be raised at run time",
10296 ("cannot convert access discriminant to non-local" &
10297 " access type", Operand);
10302 -- The case of a reference to an access discriminant from
10303 -- within a limited type declaration (which will appear as
10304 -- a discriminal) is always illegal because the level of the
10305 -- discriminant is considered to be deeper than any (nameable)
10308 if Is_Entity_Name (Operand)
10310 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10311 and then Present (Discriminal_Link (Entity (Operand)))
10314 ("discriminant has deeper accessibility level than target",
10321 -- In the presence of limited_with clauses we have to use non-limited
10322 -- views, if available.
10324 Check_Limited : declare
10325 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
10326 -- Helper function to handle limited views
10328 --------------------------
10329 -- Full_Designated_Type --
10330 --------------------------
10332 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
10333 Desig : constant Entity_Id := Designated_Type (T);
10336 -- Handle the limited view of a type
10338 if Is_Incomplete_Type (Desig)
10339 and then From_With_Type (Desig)
10340 and then Present (Non_Limited_View (Desig))
10342 return Available_View (Desig);
10346 end Full_Designated_Type;
10348 -- Local Declarations
10350 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
10351 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
10353 Same_Base : constant Boolean :=
10354 Base_Type (Target) = Base_Type (Opnd);
10356 -- Start of processing for Check_Limited
10359 if Is_Tagged_Type (Target) then
10360 return Valid_Tagged_Conversion (Target, Opnd);
10363 if not Same_Base then
10365 ("target designated type not compatible with }",
10366 N, Base_Type (Opnd));
10369 -- Ada 2005 AI-384: legality rule is symmetric in both
10370 -- designated types. The conversion is legal (with possible
10371 -- constraint check) if either designated type is
10374 elsif Subtypes_Statically_Match (Target, Opnd)
10376 (Has_Discriminants (Target)
10378 (not Is_Constrained (Opnd)
10379 or else not Is_Constrained (Target)))
10381 -- Special case, if Value_Size has been used to make the
10382 -- sizes different, the conversion is not allowed even
10383 -- though the subtypes statically match.
10385 if Known_Static_RM_Size (Target)
10386 and then Known_Static_RM_Size (Opnd)
10387 and then RM_Size (Target) /= RM_Size (Opnd)
10390 ("target designated subtype not compatible with }",
10393 ("\because sizes of the two designated subtypes differ",
10397 -- Normal case where conversion is allowed
10405 ("target designated subtype not compatible with }",
10412 -- Access to subprogram types. If the operand is an access parameter,
10413 -- the type has a deeper accessibility that any master, and cannot be
10414 -- assigned. We must make an exception if the conversion is part of an
10415 -- assignment and the target is the return object of an extended return
10416 -- statement, because in that case the accessibility check takes place
10417 -- after the return.
10419 elsif Is_Access_Subprogram_Type (Target_Type)
10420 and then No (Corresponding_Remote_Type (Opnd_Type))
10422 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
10423 and then Is_Entity_Name (Operand)
10424 and then Ekind (Entity (Operand)) = E_In_Parameter
10426 (Nkind (Parent (N)) /= N_Assignment_Statement
10427 or else not Is_Entity_Name (Name (Parent (N)))
10428 or else not Is_Return_Object (Entity (Name (Parent (N)))))
10431 ("illegal attempt to store anonymous access to subprogram",
10434 ("\value has deeper accessibility than any master " &
10435 "(RM 3.10.2 (13))",
10439 ("\use named access type for& instead of access parameter",
10440 Operand, Entity (Operand));
10443 -- Check that the designated types are subtype conformant
10445 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
10446 Old_Id => Designated_Type (Opnd_Type),
10449 -- Check the static accessibility rule of 4.6(20)
10451 if Type_Access_Level (Opnd_Type) >
10452 Type_Access_Level (Target_Type)
10455 ("operand type has deeper accessibility level than target",
10458 -- Check that if the operand type is declared in a generic body,
10459 -- then the target type must be declared within that same body
10460 -- (enforces last sentence of 4.6(20)).
10462 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
10464 O_Gen : constant Node_Id :=
10465 Enclosing_Generic_Body (Opnd_Type);
10470 T_Gen := Enclosing_Generic_Body (Target_Type);
10471 while Present (T_Gen) and then T_Gen /= O_Gen loop
10472 T_Gen := Enclosing_Generic_Body (T_Gen);
10475 if T_Gen /= O_Gen then
10477 ("target type must be declared in same generic body"
10478 & " as operand type", N);
10485 -- Remote subprogram access types
10487 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
10488 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
10490 -- It is valid to convert from one RAS type to another provided
10491 -- that their specification statically match.
10493 Check_Subtype_Conformant
10495 Designated_Type (Corresponding_Remote_Type (Target_Type)),
10497 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
10502 -- If both are tagged types, check legality of view conversions
10504 elsif Is_Tagged_Type (Target_Type)
10506 Is_Tagged_Type (Opnd_Type)
10508 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
10510 -- Types derived from the same root type are convertible
10512 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
10515 -- In an instance or an inlined body, there may be inconsistent views of
10516 -- the same type, or of types derived from a common root.
10518 elsif (In_Instance or In_Inlined_Body)
10520 Root_Type (Underlying_Type (Target_Type)) =
10521 Root_Type (Underlying_Type (Opnd_Type))
10525 -- Special check for common access type error case
10527 elsif Ekind (Target_Type) = E_Access_Type
10528 and then Is_Access_Type (Opnd_Type)
10530 Error_Msg_N ("target type must be general access type!", N);
10531 Error_Msg_NE -- CODEFIX
10532 ("add ALL to }!", N, Target_Type);
10536 Error_Msg_NE ("invalid conversion, not compatible with }",
10540 end Valid_Conversion;