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,
827 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
828 and then C /= First (Statements (P))
830 -- If the call is the expression of a return statement and the
831 -- actuals are identical to the formals, it's worth a warning.
832 -- However, we skip this if there is an immediately preceding
833 -- raise statement, since the call is never executed.
835 -- Furthermore, this corresponds to a common idiom:
837 -- function F (L : Thing) return Boolean is
839 -- raise Program_Error;
843 -- for generating a stub function
845 if Nkind (Parent (N)) = N_Simple_Return_Statement
846 and then Same_Argument_List
848 exit when not Is_List_Member (Parent (N));
850 -- OK, return statement is in a statement list, look for raise
856 -- Skip past N_Freeze_Entity nodes generated by expansion
858 Nod := Prev (Parent (N));
860 and then Nkind (Nod) = N_Freeze_Entity
865 -- If no raise statement, give warning
867 exit when Nkind (Nod) /= N_Raise_Statement
869 (Nkind (Nod) not in N_Raise_xxx_Error
870 or else Present (Condition (Nod)));
881 Error_Msg_N ("!?possible infinite recursion", N);
882 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
885 end Check_Infinite_Recursion;
887 -------------------------------
888 -- Check_Initialization_Call --
889 -------------------------------
891 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
892 Typ : constant Entity_Id := Etype (First_Formal (Nam));
894 function Uses_SS (T : Entity_Id) return Boolean;
895 -- Check whether the creation of an object of the type will involve
896 -- use of the secondary stack. If T is a record type, this is true
897 -- if the expression for some component uses the secondary stack, e.g.
898 -- through a call to a function that returns an unconstrained value.
899 -- False if T is controlled, because cleanups occur elsewhere.
905 function Uses_SS (T : Entity_Id) return Boolean is
908 Full_Type : Entity_Id := Underlying_Type (T);
911 -- Normally we want to use the underlying type, but if it's not set
912 -- then continue with T.
914 if not Present (Full_Type) then
918 if Is_Controlled (Full_Type) then
921 elsif Is_Array_Type (Full_Type) then
922 return Uses_SS (Component_Type (Full_Type));
924 elsif Is_Record_Type (Full_Type) then
925 Comp := First_Component (Full_Type);
926 while Present (Comp) loop
927 if Ekind (Comp) = E_Component
928 and then Nkind (Parent (Comp)) = N_Component_Declaration
930 -- The expression for a dynamic component may be rewritten
931 -- as a dereference, so retrieve original node.
933 Expr := Original_Node (Expression (Parent (Comp)));
935 -- Return True if the expression is a call to a function
936 -- (including an attribute function such as Image, or a
937 -- user-defined operator) with a result that requires a
940 if (Nkind (Expr) = N_Function_Call
941 or else Nkind (Expr) in N_Op
942 or else (Nkind (Expr) = N_Attribute_Reference
943 and then Present (Expressions (Expr))))
944 and then Requires_Transient_Scope (Etype (Expr))
948 elsif Uses_SS (Etype (Comp)) then
953 Next_Component (Comp);
963 -- Start of processing for Check_Initialization_Call
966 -- Establish a transient scope if the type needs it
968 if Uses_SS (Typ) then
969 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
971 end Check_Initialization_Call;
973 ---------------------------------------
974 -- Check_No_Direct_Boolean_Operators --
975 ---------------------------------------
977 procedure Check_No_Direct_Boolean_Operators (N : Node_Id) is
979 if Scope (Entity (N)) = Standard_Standard
980 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
982 -- Restriction only applies to original source code
984 if Comes_From_Source (N) then
985 Check_Restriction (No_Direct_Boolean_Operators, N);
990 Check_Boolean_Operator (N);
992 end Check_No_Direct_Boolean_Operators;
994 ------------------------------
995 -- Check_Parameterless_Call --
996 ------------------------------
998 procedure Check_Parameterless_Call (N : Node_Id) is
1001 function Prefix_Is_Access_Subp return Boolean;
1002 -- If the prefix is of an access_to_subprogram type, the node must be
1003 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1004 -- interpretations are access to subprograms.
1006 ---------------------------
1007 -- Prefix_Is_Access_Subp --
1008 ---------------------------
1010 function Prefix_Is_Access_Subp return Boolean is
1015 -- If the context is an attribute reference that can apply to
1016 -- functions, this is never a parameterless call (RM 4.1.4(6)).
1018 if Nkind (Parent (N)) = N_Attribute_Reference
1019 and then (Attribute_Name (Parent (N)) = Name_Address
1020 or else Attribute_Name (Parent (N)) = Name_Code_Address
1021 or else Attribute_Name (Parent (N)) = Name_Access)
1026 if not Is_Overloaded (N) then
1028 Ekind (Etype (N)) = E_Subprogram_Type
1029 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
1031 Get_First_Interp (N, I, It);
1032 while Present (It.Typ) loop
1033 if Ekind (It.Typ) /= E_Subprogram_Type
1034 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
1039 Get_Next_Interp (I, It);
1044 end Prefix_Is_Access_Subp;
1046 -- Start of processing for Check_Parameterless_Call
1049 -- Defend against junk stuff if errors already detected
1051 if Total_Errors_Detected /= 0 then
1052 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
1054 elsif Nkind (N) in N_Has_Chars
1055 and then Chars (N) in Error_Name_Or_No_Name
1063 -- If the context expects a value, and the name is a procedure, this is
1064 -- most likely a missing 'Access. Don't try to resolve the parameterless
1065 -- call, error will be caught when the outer call is analyzed.
1067 if Is_Entity_Name (N)
1068 and then Ekind (Entity (N)) = E_Procedure
1069 and then not Is_Overloaded (N)
1071 Nkind_In (Parent (N), N_Parameter_Association,
1073 N_Procedure_Call_Statement)
1078 -- Rewrite as call if overloadable entity that is (or could be, in the
1079 -- overloaded case) a function call. If we know for sure that the entity
1080 -- is an enumeration literal, we do not rewrite it.
1082 -- If the entity is the name of an operator, it cannot be a call because
1083 -- operators cannot have default parameters. In this case, this must be
1084 -- a string whose contents coincide with an operator name. Set the kind
1085 -- of the node appropriately.
1087 if (Is_Entity_Name (N)
1088 and then Nkind (N) /= N_Operator_Symbol
1089 and then Is_Overloadable (Entity (N))
1090 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1091 or else Is_Overloaded (N)))
1093 -- Rewrite as call if it is an explicit dereference of an expression of
1094 -- a subprogram access type, and the subprogram type is not that of a
1095 -- procedure or entry.
1098 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1100 -- Rewrite as call if it is a selected component which is a function,
1101 -- this is the case of a call to a protected function (which may be
1102 -- overloaded with other protected operations).
1105 (Nkind (N) = N_Selected_Component
1106 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1108 (Ekind_In (Entity (Selector_Name (N)), E_Entry,
1110 and then Is_Overloaded (Selector_Name (N)))))
1112 -- If one of the above three conditions is met, rewrite as call.
1113 -- Apply the rewriting only once.
1116 if Nkind (Parent (N)) /= N_Function_Call
1117 or else N /= Name (Parent (N))
1119 Nam := New_Copy (N);
1121 -- If overloaded, overload set belongs to new copy
1123 Save_Interps (N, Nam);
1125 -- Change node to parameterless function call (note that the
1126 -- Parameter_Associations associations field is left set to Empty,
1127 -- its normal default value since there are no parameters)
1129 Change_Node (N, N_Function_Call);
1131 Set_Sloc (N, Sloc (Nam));
1135 elsif Nkind (N) = N_Parameter_Association then
1136 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1138 elsif Nkind (N) = N_Operator_Symbol then
1139 Change_Operator_Symbol_To_String_Literal (N);
1140 Set_Is_Overloaded (N, False);
1141 Set_Etype (N, Any_String);
1143 end Check_Parameterless_Call;
1145 -----------------------------
1146 -- Is_Definite_Access_Type --
1147 -----------------------------
1149 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1150 Btyp : constant Entity_Id := Base_Type (E);
1152 return Ekind (Btyp) = E_Access_Type
1153 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1154 and then Comes_From_Source (Btyp));
1155 end Is_Definite_Access_Type;
1157 ----------------------
1158 -- Is_Predefined_Op --
1159 ----------------------
1161 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1163 -- Predefined operators are intrinsic subprograms
1165 if not Is_Intrinsic_Subprogram (Nam) then
1169 -- A call to a back-end builtin is never a predefined operator
1171 if Is_Imported (Nam) and then Present (Interface_Name (Nam)) then
1175 return not Is_Generic_Instance (Nam)
1176 and then Chars (Nam) in Any_Operator_Name
1177 and then (No (Alias (Nam)) or else Is_Predefined_Op (Alias (Nam)));
1178 end Is_Predefined_Op;
1180 -----------------------------
1181 -- Make_Call_Into_Operator --
1182 -----------------------------
1184 procedure Make_Call_Into_Operator
1189 Op_Name : constant Name_Id := Chars (Op_Id);
1190 Act1 : Node_Id := First_Actual (N);
1191 Act2 : Node_Id := Next_Actual (Act1);
1192 Error : Boolean := False;
1193 Func : constant Entity_Id := Entity (Name (N));
1194 Is_Binary : constant Boolean := Present (Act2);
1196 Opnd_Type : Entity_Id;
1197 Orig_Type : Entity_Id := Empty;
1200 type Kind_Test is access function (E : Entity_Id) return Boolean;
1202 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1203 -- If the operand is not universal, and the operator is given by an
1204 -- expanded name, verify that the operand has an interpretation with a
1205 -- type defined in the given scope of the operator.
1207 function Type_In_P (Test : Kind_Test) return Entity_Id;
1208 -- Find a type of the given class in package Pack that contains the
1211 ---------------------------
1212 -- Operand_Type_In_Scope --
1213 ---------------------------
1215 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1216 Nod : constant Node_Id := Right_Opnd (Op_Node);
1221 if not Is_Overloaded (Nod) then
1222 return Scope (Base_Type (Etype (Nod))) = S;
1225 Get_First_Interp (Nod, I, It);
1226 while Present (It.Typ) loop
1227 if Scope (Base_Type (It.Typ)) = S then
1231 Get_Next_Interp (I, It);
1236 end Operand_Type_In_Scope;
1242 function Type_In_P (Test : Kind_Test) return Entity_Id is
1245 function In_Decl return Boolean;
1246 -- Verify that node is not part of the type declaration for the
1247 -- candidate type, which would otherwise be invisible.
1253 function In_Decl return Boolean is
1254 Decl_Node : constant Node_Id := Parent (E);
1260 if Etype (E) = Any_Type then
1263 elsif No (Decl_Node) then
1268 and then Nkind (N2) /= N_Compilation_Unit
1270 if N2 = Decl_Node then
1281 -- Start of processing for Type_In_P
1284 -- If the context type is declared in the prefix package, this is the
1285 -- desired base type.
1287 if Scope (Base_Type (Typ)) = Pack and then Test (Typ) then
1288 return Base_Type (Typ);
1291 E := First_Entity (Pack);
1292 while Present (E) loop
1294 and then not In_Decl
1306 -- Start of processing for Make_Call_Into_Operator
1309 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1314 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1315 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1316 Save_Interps (Act1, Left_Opnd (Op_Node));
1317 Save_Interps (Act2, Right_Opnd (Op_Node));
1318 Act1 := Left_Opnd (Op_Node);
1319 Act2 := Right_Opnd (Op_Node);
1324 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1325 Save_Interps (Act1, Right_Opnd (Op_Node));
1326 Act1 := Right_Opnd (Op_Node);
1329 -- If the operator is denoted by an expanded name, and the prefix is
1330 -- not Standard, but the operator is a predefined one whose scope is
1331 -- Standard, then this is an implicit_operator, inserted as an
1332 -- interpretation by the procedure of the same name. This procedure
1333 -- overestimates the presence of implicit operators, because it does
1334 -- not examine the type of the operands. Verify now that the operand
1335 -- type appears in the given scope. If right operand is universal,
1336 -- check the other operand. In the case of concatenation, either
1337 -- argument can be the component type, so check the type of the result.
1338 -- If both arguments are literals, look for a type of the right kind
1339 -- defined in the given scope. This elaborate nonsense is brought to
1340 -- you courtesy of b33302a. The type itself must be frozen, so we must
1341 -- find the type of the proper class in the given scope.
1343 -- A final wrinkle is the multiplication operator for fixed point types,
1344 -- which is defined in Standard only, and not in the scope of the
1345 -- fixed point type itself.
1347 if Nkind (Name (N)) = N_Expanded_Name then
1348 Pack := Entity (Prefix (Name (N)));
1350 -- If the entity being called is defined in the given package, it is
1351 -- a renaming of a predefined operator, and known to be legal.
1353 if Scope (Entity (Name (N))) = Pack
1354 and then Pack /= Standard_Standard
1358 -- Visibility does not need to be checked in an instance: if the
1359 -- operator was not visible in the generic it has been diagnosed
1360 -- already, else there is an implicit copy of it in the instance.
1362 elsif In_Instance then
1365 elsif (Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide)
1366 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1367 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1369 if Pack /= Standard_Standard then
1373 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1376 elsif Ada_Version >= Ada_2005
1377 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1378 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1383 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1385 if Op_Name = Name_Op_Concat then
1386 Opnd_Type := Base_Type (Typ);
1388 elsif (Scope (Opnd_Type) = Standard_Standard
1390 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1392 and then not Comes_From_Source (Opnd_Type))
1394 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1397 if Scope (Opnd_Type) = Standard_Standard then
1399 -- Verify that the scope contains a type that corresponds to
1400 -- the given literal. Optimize the case where Pack is Standard.
1402 if Pack /= Standard_Standard then
1404 if Opnd_Type = Universal_Integer then
1405 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1407 elsif Opnd_Type = Universal_Real then
1408 Orig_Type := Type_In_P (Is_Real_Type'Access);
1410 elsif Opnd_Type = Any_String then
1411 Orig_Type := Type_In_P (Is_String_Type'Access);
1413 elsif Opnd_Type = Any_Access then
1414 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1416 elsif Opnd_Type = Any_Composite then
1417 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1419 if Present (Orig_Type) then
1420 if Has_Private_Component (Orig_Type) then
1423 Set_Etype (Act1, Orig_Type);
1426 Set_Etype (Act2, Orig_Type);
1435 Error := No (Orig_Type);
1438 elsif Ekind (Opnd_Type) = E_Allocator_Type
1439 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1443 -- If the type is defined elsewhere, and the operator is not
1444 -- defined in the given scope (by a renaming declaration, e.g.)
1445 -- then this is an error as well. If an extension of System is
1446 -- present, and the type may be defined there, Pack must be
1449 elsif Scope (Opnd_Type) /= Pack
1450 and then Scope (Op_Id) /= Pack
1451 and then (No (System_Aux_Id)
1452 or else Scope (Opnd_Type) /= System_Aux_Id
1453 or else Pack /= Scope (System_Aux_Id))
1455 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1458 Error := not Operand_Type_In_Scope (Pack);
1461 elsif Pack = Standard_Standard
1462 and then not Operand_Type_In_Scope (Standard_Standard)
1469 Error_Msg_Node_2 := Pack;
1471 ("& not declared in&", N, Selector_Name (Name (N)));
1472 Set_Etype (N, Any_Type);
1475 -- Detect a mismatch between the context type and the result type
1476 -- in the named package, which is otherwise not detected if the
1477 -- operands are universal. Check is only needed if source entity is
1478 -- an operator, not a function that renames an operator.
1480 elsif Nkind (Parent (N)) /= N_Type_Conversion
1481 and then Ekind (Entity (Name (N))) = E_Operator
1482 and then Is_Numeric_Type (Typ)
1483 and then not Is_Universal_Numeric_Type (Typ)
1484 and then Scope (Base_Type (Typ)) /= Pack
1485 and then not In_Instance
1487 if Is_Fixed_Point_Type (Typ)
1488 and then (Op_Name = Name_Op_Multiply
1490 Op_Name = Name_Op_Divide)
1492 -- Already checked above
1496 -- Operator may be defined in an extension of System
1498 elsif Present (System_Aux_Id)
1499 and then Scope (Opnd_Type) = System_Aux_Id
1504 -- Could we use Wrong_Type here??? (this would require setting
1505 -- Etype (N) to the actual type found where Typ was expected).
1507 Error_Msg_NE ("expect }", N, Typ);
1512 Set_Chars (Op_Node, Op_Name);
1514 if not Is_Private_Type (Etype (N)) then
1515 Set_Etype (Op_Node, Base_Type (Etype (N)));
1517 Set_Etype (Op_Node, Etype (N));
1520 -- If this is a call to a function that renames a predefined equality,
1521 -- the renaming declaration provides a type that must be used to
1522 -- resolve the operands. This must be done now because resolution of
1523 -- the equality node will not resolve any remaining ambiguity, and it
1524 -- assumes that the first operand is not overloaded.
1526 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1527 and then Ekind (Func) = E_Function
1528 and then Is_Overloaded (Act1)
1530 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1531 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1534 Set_Entity (Op_Node, Op_Id);
1535 Generate_Reference (Op_Id, N, ' ');
1537 -- Do rewrite setting Comes_From_Source on the result if the original
1538 -- call came from source. Although it is not strictly the case that the
1539 -- operator as such comes from the source, logically it corresponds
1540 -- exactly to the function call in the source, so it should be marked
1541 -- this way (e.g. to make sure that validity checks work fine).
1544 CS : constant Boolean := Comes_From_Source (N);
1546 Rewrite (N, Op_Node);
1547 Set_Comes_From_Source (N, CS);
1550 -- If this is an arithmetic operator and the result type is private,
1551 -- the operands and the result must be wrapped in conversion to
1552 -- expose the underlying numeric type and expand the proper checks,
1553 -- e.g. on division.
1555 if Is_Private_Type (Typ) then
1557 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1558 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1559 Resolve_Intrinsic_Operator (N, Typ);
1561 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1562 Resolve_Intrinsic_Unary_Operator (N, Typ);
1570 end Make_Call_Into_Operator;
1576 function Operator_Kind
1578 Is_Binary : Boolean) return Node_Kind
1584 if Op_Name = Name_Op_And then
1586 elsif Op_Name = Name_Op_Or then
1588 elsif Op_Name = Name_Op_Xor then
1590 elsif Op_Name = Name_Op_Eq then
1592 elsif Op_Name = Name_Op_Ne then
1594 elsif Op_Name = Name_Op_Lt then
1596 elsif Op_Name = Name_Op_Le then
1598 elsif Op_Name = Name_Op_Gt then
1600 elsif Op_Name = Name_Op_Ge then
1602 elsif Op_Name = Name_Op_Add then
1604 elsif Op_Name = Name_Op_Subtract then
1605 Kind := N_Op_Subtract;
1606 elsif Op_Name = Name_Op_Concat then
1607 Kind := N_Op_Concat;
1608 elsif Op_Name = Name_Op_Multiply then
1609 Kind := N_Op_Multiply;
1610 elsif Op_Name = Name_Op_Divide then
1611 Kind := N_Op_Divide;
1612 elsif Op_Name = Name_Op_Mod then
1614 elsif Op_Name = Name_Op_Rem then
1616 elsif Op_Name = Name_Op_Expon then
1619 raise Program_Error;
1625 if Op_Name = Name_Op_Add then
1627 elsif Op_Name = Name_Op_Subtract then
1629 elsif Op_Name = Name_Op_Abs then
1631 elsif Op_Name = Name_Op_Not then
1634 raise Program_Error;
1641 ----------------------------
1642 -- Preanalyze_And_Resolve --
1643 ----------------------------
1645 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1646 Save_Full_Analysis : constant Boolean := Full_Analysis;
1649 Full_Analysis := False;
1650 Expander_Mode_Save_And_Set (False);
1652 -- We suppress all checks for this analysis, since the checks will
1653 -- be applied properly, and in the right location, when the default
1654 -- expression is reanalyzed and reexpanded later on.
1656 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1658 Expander_Mode_Restore;
1659 Full_Analysis := Save_Full_Analysis;
1660 end Preanalyze_And_Resolve;
1662 -- Version without context type
1664 procedure Preanalyze_And_Resolve (N : Node_Id) is
1665 Save_Full_Analysis : constant Boolean := Full_Analysis;
1668 Full_Analysis := False;
1669 Expander_Mode_Save_And_Set (False);
1672 Resolve (N, Etype (N), Suppress => All_Checks);
1674 Expander_Mode_Restore;
1675 Full_Analysis := Save_Full_Analysis;
1676 end Preanalyze_And_Resolve;
1678 ----------------------------------
1679 -- Replace_Actual_Discriminants --
1680 ----------------------------------
1682 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1683 Loc : constant Source_Ptr := Sloc (N);
1684 Tsk : Node_Id := Empty;
1686 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1692 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1696 if Nkind (Nod) = N_Identifier then
1697 Ent := Entity (Nod);
1700 and then Ekind (Ent) = E_Discriminant
1703 Make_Selected_Component (Loc,
1704 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1705 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1707 Set_Etype (Nod, Etype (Ent));
1715 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1717 -- Start of processing for Replace_Actual_Discriminants
1720 if not Expander_Active then
1724 if Nkind (Name (N)) = N_Selected_Component then
1725 Tsk := Prefix (Name (N));
1727 elsif Nkind (Name (N)) = N_Indexed_Component then
1728 Tsk := Prefix (Prefix (Name (N)));
1734 Replace_Discrs (Default);
1736 end Replace_Actual_Discriminants;
1742 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1743 Ambiguous : Boolean := False;
1744 Ctx_Type : Entity_Id := Typ;
1745 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1746 Err_Type : Entity_Id := Empty;
1747 Found : Boolean := False;
1750 I1 : Interp_Index := 0; -- prevent junk warning
1753 Seen : Entity_Id := Empty; -- prevent junk warning
1755 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1756 -- Determine whether a node comes from a predefined library unit or
1759 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1760 -- Try and fix up a literal so that it matches its expected type. New
1761 -- literals are manufactured if necessary to avoid cascaded errors.
1763 procedure Report_Ambiguous_Argument;
1764 -- Additional diagnostics when an ambiguous call has an ambiguous
1765 -- argument (typically a controlling actual).
1767 procedure Resolution_Failed;
1768 -- Called when attempt at resolving current expression fails
1770 ------------------------------------
1771 -- Comes_From_Predefined_Lib_Unit --
1772 -------------------------------------
1774 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1777 Sloc (Nod) = Standard_Location
1778 or else Is_Predefined_File_Name (Unit_File_Name (
1779 Get_Source_Unit (Sloc (Nod))));
1780 end Comes_From_Predefined_Lib_Unit;
1782 --------------------
1783 -- Patch_Up_Value --
1784 --------------------
1786 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1788 if Nkind (N) = N_Integer_Literal
1789 and then Is_Real_Type (Typ)
1792 Make_Real_Literal (Sloc (N),
1793 Realval => UR_From_Uint (Intval (N))));
1794 Set_Etype (N, Universal_Real);
1795 Set_Is_Static_Expression (N);
1797 elsif Nkind (N) = N_Real_Literal
1798 and then Is_Integer_Type (Typ)
1801 Make_Integer_Literal (Sloc (N),
1802 Intval => UR_To_Uint (Realval (N))));
1803 Set_Etype (N, Universal_Integer);
1804 Set_Is_Static_Expression (N);
1806 elsif Nkind (N) = N_String_Literal
1807 and then Is_Character_Type (Typ)
1809 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1811 Make_Character_Literal (Sloc (N),
1813 Char_Literal_Value =>
1814 UI_From_Int (Character'Pos ('A'))));
1815 Set_Etype (N, Any_Character);
1816 Set_Is_Static_Expression (N);
1818 elsif Nkind (N) /= N_String_Literal
1819 and then Is_String_Type (Typ)
1822 Make_String_Literal (Sloc (N),
1823 Strval => End_String));
1825 elsif Nkind (N) = N_Range then
1826 Patch_Up_Value (Low_Bound (N), Typ);
1827 Patch_Up_Value (High_Bound (N), Typ);
1831 -------------------------------
1832 -- Report_Ambiguous_Argument --
1833 -------------------------------
1835 procedure Report_Ambiguous_Argument is
1836 Arg : constant Node_Id := First (Parameter_Associations (N));
1841 if Nkind (Arg) = N_Function_Call
1842 and then Is_Entity_Name (Name (Arg))
1843 and then Is_Overloaded (Name (Arg))
1845 Error_Msg_NE ("ambiguous call to&", Arg, Name (Arg));
1847 -- Could use comments on what is going on here ???
1849 Get_First_Interp (Name (Arg), I, It);
1850 while Present (It.Nam) loop
1851 Error_Msg_Sloc := Sloc (It.Nam);
1853 if Nkind (Parent (It.Nam)) = N_Full_Type_Declaration then
1854 Error_Msg_N ("interpretation (inherited) #!", Arg);
1856 Error_Msg_N ("interpretation #!", Arg);
1859 Get_Next_Interp (I, It);
1862 end Report_Ambiguous_Argument;
1864 -----------------------
1865 -- Resolution_Failed --
1866 -----------------------
1868 procedure Resolution_Failed is
1870 Patch_Up_Value (N, Typ);
1872 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1873 Set_Is_Overloaded (N, False);
1875 -- The caller will return without calling the expander, so we need
1876 -- to set the analyzed flag. Note that it is fine to set Analyzed
1877 -- to True even if we are in the middle of a shallow analysis,
1878 -- (see the spec of sem for more details) since this is an error
1879 -- situation anyway, and there is no point in repeating the
1880 -- analysis later (indeed it won't work to repeat it later, since
1881 -- we haven't got a clear resolution of which entity is being
1884 Set_Analyzed (N, True);
1886 end Resolution_Failed;
1888 -- Start of processing for Resolve
1895 -- Access attribute on remote subprogram cannot be used for
1896 -- a non-remote access-to-subprogram type.
1898 if Nkind (N) = N_Attribute_Reference
1899 and then (Attribute_Name (N) = Name_Access
1900 or else Attribute_Name (N) = Name_Unrestricted_Access
1901 or else Attribute_Name (N) = Name_Unchecked_Access)
1902 and then Comes_From_Source (N)
1903 and then Is_Entity_Name (Prefix (N))
1904 and then Is_Subprogram (Entity (Prefix (N)))
1905 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1906 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1909 ("prefix must statically denote a non-remote subprogram", N);
1912 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1914 -- If the context is a Remote_Access_To_Subprogram, access attributes
1915 -- must be resolved with the corresponding fat pointer. There is no need
1916 -- to check for the attribute name since the return type of an
1917 -- attribute is never a remote type.
1919 if Nkind (N) = N_Attribute_Reference
1920 and then Comes_From_Source (N)
1921 and then (Is_Remote_Call_Interface (Typ)
1922 or else Is_Remote_Types (Typ))
1925 Attr : constant Attribute_Id :=
1926 Get_Attribute_Id (Attribute_Name (N));
1927 Pref : constant Node_Id := Prefix (N);
1930 Is_Remote : Boolean := True;
1933 -- Check that Typ is a remote access-to-subprogram type
1935 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1937 -- Prefix (N) must statically denote a remote subprogram
1938 -- declared in a package specification.
1940 if Attr = Attribute_Access then
1941 Decl := Unit_Declaration_Node (Entity (Pref));
1943 if Nkind (Decl) = N_Subprogram_Body then
1944 Spec := Corresponding_Spec (Decl);
1946 if not No (Spec) then
1947 Decl := Unit_Declaration_Node (Spec);
1951 Spec := Parent (Decl);
1953 if not Is_Entity_Name (Prefix (N))
1954 or else Nkind (Spec) /= N_Package_Specification
1956 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1960 ("prefix must statically denote a remote subprogram ",
1965 -- If we are generating code for a distributed program.
1966 -- perform semantic checks against the corresponding
1969 if (Attr = Attribute_Access
1970 or else Attr = Attribute_Unchecked_Access
1971 or else Attr = Attribute_Unrestricted_Access)
1972 and then Expander_Active
1973 and then Get_PCS_Name /= Name_No_DSA
1975 Check_Subtype_Conformant
1976 (New_Id => Entity (Prefix (N)),
1977 Old_Id => Designated_Type
1978 (Corresponding_Remote_Type (Typ)),
1982 Process_Remote_AST_Attribute (N, Typ);
1989 Debug_A_Entry ("resolving ", N);
1991 if Comes_From_Source (N) then
1992 if Is_Fixed_Point_Type (Typ) then
1993 Check_Restriction (No_Fixed_Point, N);
1995 elsif Is_Floating_Point_Type (Typ)
1996 and then Typ /= Universal_Real
1997 and then Typ /= Any_Real
1999 Check_Restriction (No_Floating_Point, N);
2003 -- Return if already analyzed
2005 if Analyzed (N) then
2006 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
2009 -- Return if type = Any_Type (previous error encountered)
2011 elsif Etype (N) = Any_Type then
2012 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
2016 Check_Parameterless_Call (N);
2018 -- If not overloaded, then we know the type, and all that needs doing
2019 -- is to check that this type is compatible with the context.
2021 if not Is_Overloaded (N) then
2022 Found := Covers (Typ, Etype (N));
2023 Expr_Type := Etype (N);
2025 -- In the overloaded case, we must select the interpretation that
2026 -- is compatible with the context (i.e. the type passed to Resolve)
2029 -- Loop through possible interpretations
2031 Get_First_Interp (N, I, It);
2032 Interp_Loop : while Present (It.Typ) loop
2034 -- We are only interested in interpretations that are compatible
2035 -- with the expected type, any other interpretations are ignored.
2037 if not Covers (Typ, It.Typ) then
2038 if Debug_Flag_V then
2039 Write_Str (" interpretation incompatible with context");
2044 -- Skip the current interpretation if it is disabled by an
2045 -- abstract operator. This action is performed only when the
2046 -- type against which we are resolving is the same as the
2047 -- type of the interpretation.
2049 if Ada_Version >= Ada_2005
2050 and then It.Typ = Typ
2051 and then Typ /= Universal_Integer
2052 and then Typ /= Universal_Real
2053 and then Present (It.Abstract_Op)
2058 -- First matching interpretation
2064 Expr_Type := It.Typ;
2066 -- Matching interpretation that is not the first, maybe an
2067 -- error, but there are some cases where preference rules are
2068 -- used to choose between the two possibilities. These and
2069 -- some more obscure cases are handled in Disambiguate.
2072 -- If the current statement is part of a predefined library
2073 -- unit, then all interpretations which come from user level
2074 -- packages should not be considered.
2077 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
2082 Error_Msg_Sloc := Sloc (Seen);
2083 It1 := Disambiguate (N, I1, I, Typ);
2085 -- Disambiguation has succeeded. Skip the remaining
2088 if It1 /= No_Interp then
2090 Expr_Type := It1.Typ;
2092 while Present (It.Typ) loop
2093 Get_Next_Interp (I, It);
2097 -- Before we issue an ambiguity complaint, check for
2098 -- the case of a subprogram call where at least one
2099 -- of the arguments is Any_Type, and if so, suppress
2100 -- the message, since it is a cascaded error.
2102 if Nkind_In (N, N_Function_Call,
2103 N_Procedure_Call_Statement)
2110 A := First_Actual (N);
2111 while Present (A) loop
2114 if Nkind (E) = N_Parameter_Association then
2115 E := Explicit_Actual_Parameter (E);
2118 if Etype (E) = Any_Type then
2119 if Debug_Flag_V then
2120 Write_Str ("Any_Type in call");
2131 elsif Nkind (N) in N_Binary_Op
2132 and then (Etype (Left_Opnd (N)) = Any_Type
2133 or else Etype (Right_Opnd (N)) = Any_Type)
2137 elsif Nkind (N) in N_Unary_Op
2138 and then Etype (Right_Opnd (N)) = Any_Type
2143 -- Not that special case, so issue message using the
2144 -- flag Ambiguous to control printing of the header
2145 -- message only at the start of an ambiguous set.
2147 if not Ambiguous then
2148 if Nkind (N) = N_Function_Call
2149 and then Nkind (Name (N)) = N_Explicit_Dereference
2152 ("ambiguous expression "
2153 & "(cannot resolve indirect call)!", N);
2155 Error_Msg_NE -- CODEFIX
2156 ("ambiguous expression (cannot resolve&)!",
2162 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2164 ("\\possible interpretation (inherited)#!", N);
2166 Error_Msg_N -- CODEFIX
2167 ("\\possible interpretation#!", N);
2171 (N, N_Procedure_Call_Statement, N_Function_Call)
2172 and then Present (Parameter_Associations (N))
2174 Report_Ambiguous_Argument;
2178 Error_Msg_Sloc := Sloc (It.Nam);
2180 -- By default, the error message refers to the candidate
2181 -- interpretation. But if it is a predefined operator, it
2182 -- is implicitly declared at the declaration of the type
2183 -- of the operand. Recover the sloc of that declaration
2184 -- for the error message.
2186 if Nkind (N) in N_Op
2187 and then Scope (It.Nam) = Standard_Standard
2188 and then not Is_Overloaded (Right_Opnd (N))
2189 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2192 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2194 if Comes_From_Source (Err_Type)
2195 and then Present (Parent (Err_Type))
2197 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2200 elsif Nkind (N) in N_Binary_Op
2201 and then Scope (It.Nam) = Standard_Standard
2202 and then not Is_Overloaded (Left_Opnd (N))
2203 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2206 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2208 if Comes_From_Source (Err_Type)
2209 and then Present (Parent (Err_Type))
2211 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2214 -- If this is an indirect call, use the subprogram_type
2215 -- in the message, to have a meaningful location.
2216 -- Also indicate if this is an inherited operation,
2217 -- created by a type declaration.
2219 elsif Nkind (N) = N_Function_Call
2220 and then Nkind (Name (N)) = N_Explicit_Dereference
2221 and then Is_Type (It.Nam)
2225 Sloc (Associated_Node_For_Itype (Err_Type));
2230 if Nkind (N) in N_Op
2231 and then Scope (It.Nam) = Standard_Standard
2232 and then Present (Err_Type)
2234 -- Special-case the message for universal_fixed
2235 -- operators, which are not declared with the type
2236 -- of the operand, but appear forever in Standard.
2238 if It.Typ = Universal_Fixed
2239 and then Scope (It.Nam) = Standard_Standard
2242 ("\\possible interpretation as " &
2243 "universal_fixed operation " &
2244 "(RM 4.5.5 (19))", N);
2247 ("\\possible interpretation (predefined)#!", N);
2251 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2254 ("\\possible interpretation (inherited)#!", N);
2256 Error_Msg_N -- CODEFIX
2257 ("\\possible interpretation#!", N);
2263 -- We have a matching interpretation, Expr_Type is the type
2264 -- from this interpretation, and Seen is the entity.
2266 -- For an operator, just set the entity name. The type will be
2267 -- set by the specific operator resolution routine.
2269 if Nkind (N) in N_Op then
2270 Set_Entity (N, Seen);
2271 Generate_Reference (Seen, N);
2273 elsif Nkind (N) = N_Case_Expression then
2274 Set_Etype (N, Expr_Type);
2276 elsif Nkind (N) = N_Character_Literal then
2277 Set_Etype (N, Expr_Type);
2279 elsif Nkind (N) = N_Conditional_Expression then
2280 Set_Etype (N, Expr_Type);
2282 -- For an explicit dereference, attribute reference, range,
2283 -- short-circuit form (which is not an operator node), or call
2284 -- with a name that is an explicit dereference, there is
2285 -- nothing to be done at this point.
2287 elsif Nkind_In (N, N_Explicit_Dereference,
2288 N_Attribute_Reference,
2290 N_Indexed_Component,
2293 N_Selected_Component,
2295 or else Nkind (Name (N)) = N_Explicit_Dereference
2299 -- For procedure or function calls, set the type of the name,
2300 -- and also the entity pointer for the prefix.
2302 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2303 and then Is_Entity_Name (Name (N))
2305 Set_Etype (Name (N), Expr_Type);
2306 Set_Entity (Name (N), Seen);
2307 Generate_Reference (Seen, Name (N));
2309 elsif Nkind (N) = N_Function_Call
2310 and then Nkind (Name (N)) = N_Selected_Component
2312 Set_Etype (Name (N), Expr_Type);
2313 Set_Entity (Selector_Name (Name (N)), Seen);
2314 Generate_Reference (Seen, Selector_Name (Name (N)));
2316 -- For all other cases, just set the type of the Name
2319 Set_Etype (Name (N), Expr_Type);
2326 -- Move to next interpretation
2328 exit Interp_Loop when No (It.Typ);
2330 Get_Next_Interp (I, It);
2331 end loop Interp_Loop;
2334 -- At this stage Found indicates whether or not an acceptable
2335 -- interpretation exists. If not, then we have an error, except that if
2336 -- the context is Any_Type as a result of some other error, then we
2337 -- suppress the error report.
2340 if Typ /= Any_Type then
2342 -- If type we are looking for is Void, then this is the procedure
2343 -- call case, and the error is simply that what we gave is not a
2344 -- procedure name (we think of procedure calls as expressions with
2345 -- types internally, but the user doesn't think of them this way!)
2347 if Typ = Standard_Void_Type then
2349 -- Special case message if function used as a procedure
2351 if Nkind (N) = N_Procedure_Call_Statement
2352 and then Is_Entity_Name (Name (N))
2353 and then Ekind (Entity (Name (N))) = E_Function
2356 ("cannot use function & in a procedure call",
2357 Name (N), Entity (Name (N)));
2359 -- Otherwise give general message (not clear what cases this
2360 -- covers, but no harm in providing for them!)
2363 Error_Msg_N ("expect procedure name in procedure call", N);
2368 -- Otherwise we do have a subexpression with the wrong type
2370 -- Check for the case of an allocator which uses an access type
2371 -- instead of the designated type. This is a common error and we
2372 -- specialize the message, posting an error on the operand of the
2373 -- allocator, complaining that we expected the designated type of
2376 elsif Nkind (N) = N_Allocator
2377 and then Ekind (Typ) in Access_Kind
2378 and then Ekind (Etype (N)) in Access_Kind
2379 and then Designated_Type (Etype (N)) = Typ
2381 Wrong_Type (Expression (N), Designated_Type (Typ));
2384 -- Check for view mismatch on Null in instances, for which the
2385 -- view-swapping mechanism has no identifier.
2387 elsif (In_Instance or else In_Inlined_Body)
2388 and then (Nkind (N) = N_Null)
2389 and then Is_Private_Type (Typ)
2390 and then Is_Access_Type (Full_View (Typ))
2392 Resolve (N, Full_View (Typ));
2396 -- Check for an aggregate. Sometimes we can get bogus aggregates
2397 -- from misuse of parentheses, and we are about to complain about
2398 -- the aggregate without even looking inside it.
2400 -- Instead, if we have an aggregate of type Any_Composite, then
2401 -- analyze and resolve the component fields, and then only issue
2402 -- another message if we get no errors doing this (otherwise
2403 -- assume that the errors in the aggregate caused the problem).
2405 elsif Nkind (N) = N_Aggregate
2406 and then Etype (N) = Any_Composite
2408 -- Disable expansion in any case. If there is a type mismatch
2409 -- it may be fatal to try to expand the aggregate. The flag
2410 -- would otherwise be set to false when the error is posted.
2412 Expander_Active := False;
2415 procedure Check_Aggr (Aggr : Node_Id);
2416 -- Check one aggregate, and set Found to True if we have a
2417 -- definite error in any of its elements
2419 procedure Check_Elmt (Aelmt : Node_Id);
2420 -- Check one element of aggregate and set Found to True if
2421 -- we definitely have an error in the element.
2427 procedure Check_Aggr (Aggr : Node_Id) is
2431 if Present (Expressions (Aggr)) then
2432 Elmt := First (Expressions (Aggr));
2433 while Present (Elmt) loop
2439 if Present (Component_Associations (Aggr)) then
2440 Elmt := First (Component_Associations (Aggr));
2441 while Present (Elmt) loop
2443 -- If this is a default-initialized component, then
2444 -- there is nothing to check. The box will be
2445 -- replaced by the appropriate call during late
2448 if not Box_Present (Elmt) then
2449 Check_Elmt (Expression (Elmt));
2461 procedure Check_Elmt (Aelmt : Node_Id) is
2463 -- If we have a nested aggregate, go inside it (to
2464 -- attempt a naked analyze-resolve of the aggregate
2465 -- can cause undesirable cascaded errors). Do not
2466 -- resolve expression if it needs a type from context,
2467 -- as for integer * fixed expression.
2469 if Nkind (Aelmt) = N_Aggregate then
2475 if not Is_Overloaded (Aelmt)
2476 and then Etype (Aelmt) /= Any_Fixed
2481 if Etype (Aelmt) = Any_Type then
2492 -- If an error message was issued already, Found got reset
2493 -- to True, so if it is still False, issue the standard
2494 -- Wrong_Type message.
2497 if Is_Overloaded (N)
2498 and then Nkind (N) = N_Function_Call
2501 Subp_Name : Node_Id;
2503 if Is_Entity_Name (Name (N)) then
2504 Subp_Name := Name (N);
2506 elsif Nkind (Name (N)) = N_Selected_Component then
2508 -- Protected operation: retrieve operation name
2510 Subp_Name := Selector_Name (Name (N));
2512 raise Program_Error;
2515 Error_Msg_Node_2 := Typ;
2516 Error_Msg_NE ("no visible interpretation of&" &
2517 " matches expected type&", N, Subp_Name);
2520 if All_Errors_Mode then
2522 Index : Interp_Index;
2526 Error_Msg_N ("\\possible interpretations:", N);
2528 Get_First_Interp (Name (N), Index, It);
2529 while Present (It.Nam) loop
2530 Error_Msg_Sloc := Sloc (It.Nam);
2531 Error_Msg_Node_2 := It.Nam;
2533 ("\\ type& for & declared#", N, It.Typ);
2534 Get_Next_Interp (Index, It);
2539 Error_Msg_N ("\use -gnatf for details", N);
2542 Wrong_Type (N, Typ);
2550 -- Test if we have more than one interpretation for the context
2552 elsif Ambiguous then
2556 -- Here we have an acceptable interpretation for the context
2559 -- Propagate type information and normalize tree for various
2560 -- predefined operations. If the context only imposes a class of
2561 -- types, rather than a specific type, propagate the actual type
2564 if Typ = Any_Integer
2565 or else Typ = Any_Boolean
2566 or else Typ = Any_Modular
2567 or else Typ = Any_Real
2568 or else Typ = Any_Discrete
2570 Ctx_Type := Expr_Type;
2572 -- Any_Fixed is legal in a real context only if a specific
2573 -- fixed point type is imposed. If Norman Cohen can be
2574 -- confused by this, it deserves a separate message.
2577 and then Expr_Type = Any_Fixed
2579 Error_Msg_N ("illegal context for mixed mode operation", N);
2580 Set_Etype (N, Universal_Real);
2581 Ctx_Type := Universal_Real;
2585 -- A user-defined operator is transformed into a function call at
2586 -- this point, so that further processing knows that operators are
2587 -- really operators (i.e. are predefined operators). User-defined
2588 -- operators that are intrinsic are just renamings of the predefined
2589 -- ones, and need not be turned into calls either, but if they rename
2590 -- a different operator, we must transform the node accordingly.
2591 -- Instantiations of Unchecked_Conversion are intrinsic but are
2592 -- treated as functions, even if given an operator designator.
2594 if Nkind (N) in N_Op
2595 and then Present (Entity (N))
2596 and then Ekind (Entity (N)) /= E_Operator
2599 if not Is_Predefined_Op (Entity (N)) then
2600 Rewrite_Operator_As_Call (N, Entity (N));
2602 elsif Present (Alias (Entity (N)))
2604 Nkind (Parent (Parent (Entity (N)))) =
2605 N_Subprogram_Renaming_Declaration
2607 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2609 -- If the node is rewritten, it will be fully resolved in
2610 -- Rewrite_Renamed_Operator.
2612 if Analyzed (N) then
2618 case N_Subexpr'(Nkind (N)) is
2620 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2622 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2624 when N_Short_Circuit
2625 => Resolve_Short_Circuit (N, Ctx_Type);
2627 when N_Attribute_Reference
2628 => Resolve_Attribute (N, Ctx_Type);
2630 when N_Case_Expression
2631 => Resolve_Case_Expression (N, Ctx_Type);
2633 when N_Character_Literal
2634 => Resolve_Character_Literal (N, Ctx_Type);
2636 when N_Conditional_Expression
2637 => Resolve_Conditional_Expression (N, Ctx_Type);
2639 when N_Expanded_Name
2640 => Resolve_Entity_Name (N, Ctx_Type);
2642 when N_Explicit_Dereference
2643 => Resolve_Explicit_Dereference (N, Ctx_Type);
2645 when N_Expression_With_Actions
2646 => Resolve_Expression_With_Actions (N, Ctx_Type);
2648 when N_Extension_Aggregate
2649 => Resolve_Extension_Aggregate (N, Ctx_Type);
2651 when N_Function_Call
2652 => Resolve_Call (N, Ctx_Type);
2655 => Resolve_Entity_Name (N, Ctx_Type);
2657 when N_Indexed_Component
2658 => Resolve_Indexed_Component (N, Ctx_Type);
2660 when N_Integer_Literal
2661 => Resolve_Integer_Literal (N, Ctx_Type);
2663 when N_Membership_Test
2664 => Resolve_Membership_Op (N, Ctx_Type);
2666 when N_Null => Resolve_Null (N, Ctx_Type);
2668 when N_Op_And | N_Op_Or | N_Op_Xor
2669 => Resolve_Logical_Op (N, Ctx_Type);
2671 when N_Op_Eq | N_Op_Ne
2672 => Resolve_Equality_Op (N, Ctx_Type);
2674 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2675 => Resolve_Comparison_Op (N, Ctx_Type);
2677 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2679 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2680 N_Op_Divide | N_Op_Mod | N_Op_Rem
2682 => Resolve_Arithmetic_Op (N, Ctx_Type);
2684 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2686 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2688 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2689 => Resolve_Unary_Op (N, Ctx_Type);
2691 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2693 when N_Procedure_Call_Statement
2694 => Resolve_Call (N, Ctx_Type);
2696 when N_Operator_Symbol
2697 => Resolve_Operator_Symbol (N, Ctx_Type);
2699 when N_Qualified_Expression
2700 => Resolve_Qualified_Expression (N, Ctx_Type);
2702 when N_Quantified_Expression
2703 => Resolve_Quantified_Expression (N, Ctx_Type);
2705 when N_Raise_xxx_Error
2706 => Set_Etype (N, Ctx_Type);
2708 when N_Range => Resolve_Range (N, Ctx_Type);
2711 => Resolve_Real_Literal (N, Ctx_Type);
2713 when N_Reference => Resolve_Reference (N, Ctx_Type);
2715 when N_Selected_Component
2716 => Resolve_Selected_Component (N, Ctx_Type);
2718 when N_Slice => Resolve_Slice (N, Ctx_Type);
2720 when N_String_Literal
2721 => Resolve_String_Literal (N, Ctx_Type);
2723 when N_Subprogram_Info
2724 => Resolve_Subprogram_Info (N, Ctx_Type);
2726 when N_Type_Conversion
2727 => Resolve_Type_Conversion (N, Ctx_Type);
2729 when N_Unchecked_Expression =>
2730 Resolve_Unchecked_Expression (N, Ctx_Type);
2732 when N_Unchecked_Type_Conversion =>
2733 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2736 -- If the subexpression was replaced by a non-subexpression, then
2737 -- all we do is to expand it. The only legitimate case we know of
2738 -- is converting procedure call statement to entry call statements,
2739 -- but there may be others, so we are making this test general.
2741 if Nkind (N) not in N_Subexpr then
2742 Debug_A_Exit ("resolving ", N, " (done)");
2747 -- AI05-144-2: Check dangerous order dependence within an expression
2748 -- that is not a subexpression. Exclude RHS of an assignment, because
2749 -- both sides may have side-effects and the check must be performed
2750 -- over the statement.
2752 if Nkind (Parent (N)) not in N_Subexpr
2753 and then Nkind (Parent (N)) /= N_Assignment_Statement
2754 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2756 Check_Order_Dependence;
2759 -- The expression is definitely NOT overloaded at this point, so
2760 -- we reset the Is_Overloaded flag to avoid any confusion when
2761 -- reanalyzing the node.
2763 Set_Is_Overloaded (N, False);
2765 -- Freeze expression type, entity if it is a name, and designated
2766 -- type if it is an allocator (RM 13.14(10,11,13)).
2768 -- Now that the resolution of the type of the node is complete,
2769 -- and we did not detect an error, we can expand this node. We
2770 -- skip the expand call if we are in a default expression, see
2771 -- section "Handling of Default Expressions" in Sem spec.
2773 Debug_A_Exit ("resolving ", N, " (done)");
2775 -- We unconditionally freeze the expression, even if we are in
2776 -- default expression mode (the Freeze_Expression routine tests
2777 -- this flag and only freezes static types if it is set).
2779 Freeze_Expression (N);
2781 -- Now we can do the expansion
2791 -- Version with check(s) suppressed
2793 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2795 if Suppress = All_Checks then
2797 Svg : constant Suppress_Array := Scope_Suppress;
2799 Scope_Suppress := (others => True);
2801 Scope_Suppress := Svg;
2806 Svg : constant Boolean := Scope_Suppress (Suppress);
2808 Scope_Suppress (Suppress) := True;
2810 Scope_Suppress (Suppress) := Svg;
2819 -- Version with implicit type
2821 procedure Resolve (N : Node_Id) is
2823 Resolve (N, Etype (N));
2826 ---------------------
2827 -- Resolve_Actuals --
2828 ---------------------
2830 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2831 Loc : constant Source_Ptr := Sloc (N);
2836 Prev : Node_Id := Empty;
2839 procedure Check_Argument_Order;
2840 -- Performs a check for the case where the actuals are all simple
2841 -- identifiers that correspond to the formal names, but in the wrong
2842 -- order, which is considered suspicious and cause for a warning.
2844 procedure Check_Prefixed_Call;
2845 -- If the original node is an overloaded call in prefix notation,
2846 -- insert an 'Access or a dereference as needed over the first actual.
2847 -- Try_Object_Operation has already verified that there is a valid
2848 -- interpretation, but the form of the actual can only be determined
2849 -- once the primitive operation is identified.
2851 procedure Insert_Default;
2852 -- If the actual is missing in a call, insert in the actuals list
2853 -- an instance of the default expression. The insertion is always
2854 -- a named association.
2856 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2857 -- Check whether T1 and T2, or their full views, are derived from a
2858 -- common type. Used to enforce the restrictions on array conversions
2861 function Static_Concatenation (N : Node_Id) return Boolean;
2862 -- Predicate to determine whether an actual that is a concatenation
2863 -- will be evaluated statically and does not need a transient scope.
2864 -- This must be determined before the actual is resolved and expanded
2865 -- because if needed the transient scope must be introduced earlier.
2867 --------------------------
2868 -- Check_Argument_Order --
2869 --------------------------
2871 procedure Check_Argument_Order is
2873 -- Nothing to do if no parameters, or original node is neither a
2874 -- function call nor a procedure call statement (happens in the
2875 -- operator-transformed-to-function call case), or the call does
2876 -- not come from source, or this warning is off.
2878 if not Warn_On_Parameter_Order
2880 No (Parameter_Associations (N))
2882 not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2885 not Comes_From_Source (N)
2891 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2894 -- Nothing to do if only one parameter
2900 -- Here if at least two arguments
2903 Actuals : array (1 .. Nargs) of Node_Id;
2907 Wrong_Order : Boolean := False;
2908 -- Set True if an out of order case is found
2911 -- Collect identifier names of actuals, fail if any actual is
2912 -- not a simple identifier, and record max length of name.
2914 Actual := First (Parameter_Associations (N));
2915 for J in Actuals'Range loop
2916 if Nkind (Actual) /= N_Identifier then
2919 Actuals (J) := Actual;
2924 -- If we got this far, all actuals are identifiers and the list
2925 -- of their names is stored in the Actuals array.
2927 Formal := First_Formal (Nam);
2928 for J in Actuals'Range loop
2930 -- If we ran out of formals, that's odd, probably an error
2931 -- which will be detected elsewhere, but abandon the search.
2937 -- If name matches and is in order OK
2939 if Chars (Formal) = Chars (Actuals (J)) then
2943 -- If no match, see if it is elsewhere in list and if so
2944 -- flag potential wrong order if type is compatible.
2946 for K in Actuals'Range loop
2947 if Chars (Formal) = Chars (Actuals (K))
2949 Has_Compatible_Type (Actuals (K), Etype (Formal))
2951 Wrong_Order := True;
2961 <<Continue>> Next_Formal (Formal);
2964 -- If Formals left over, also probably an error, skip warning
2966 if Present (Formal) then
2970 -- Here we give the warning if something was out of order
2974 ("actuals for this call may be in wrong order?", N);
2978 end Check_Argument_Order;
2980 -------------------------
2981 -- Check_Prefixed_Call --
2982 -------------------------
2984 procedure Check_Prefixed_Call is
2985 Act : constant Node_Id := First_Actual (N);
2986 A_Type : constant Entity_Id := Etype (Act);
2987 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
2988 Orig : constant Node_Id := Original_Node (N);
2992 -- Check whether the call is a prefixed call, with or without
2993 -- additional actuals.
2995 if Nkind (Orig) = N_Selected_Component
2997 (Nkind (Orig) = N_Indexed_Component
2998 and then Nkind (Prefix (Orig)) = N_Selected_Component
2999 and then Is_Entity_Name (Prefix (Prefix (Orig)))
3000 and then Is_Entity_Name (Act)
3001 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
3003 if Is_Access_Type (A_Type)
3004 and then not Is_Access_Type (F_Type)
3006 -- Introduce dereference on object in prefix
3009 Make_Explicit_Dereference (Sloc (Act),
3010 Prefix => Relocate_Node (Act));
3011 Rewrite (Act, New_A);
3014 elsif Is_Access_Type (F_Type)
3015 and then not Is_Access_Type (A_Type)
3017 -- Introduce an implicit 'Access in prefix
3019 if not Is_Aliased_View (Act) then
3021 ("object in prefixed call to& must be aliased"
3022 & " (RM-2005 4.3.1 (13))",
3027 Make_Attribute_Reference (Loc,
3028 Attribute_Name => Name_Access,
3029 Prefix => Relocate_Node (Act)));
3034 end Check_Prefixed_Call;
3036 --------------------
3037 -- Insert_Default --
3038 --------------------
3040 procedure Insert_Default is
3045 -- Missing argument in call, nothing to insert
3047 if No (Default_Value (F)) then
3051 -- Note that we do a full New_Copy_Tree, so that any associated
3052 -- Itypes are properly copied. This may not be needed any more,
3053 -- but it does no harm as a safety measure! Defaults of a generic
3054 -- formal may be out of bounds of the corresponding actual (see
3055 -- cc1311b) and an additional check may be required.
3060 New_Scope => Current_Scope,
3063 if Is_Concurrent_Type (Scope (Nam))
3064 and then Has_Discriminants (Scope (Nam))
3066 Replace_Actual_Discriminants (N, Actval);
3069 if Is_Overloadable (Nam)
3070 and then Present (Alias (Nam))
3072 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
3073 and then not Is_Tagged_Type (Etype (F))
3075 -- If default is a real literal, do not introduce a
3076 -- conversion whose effect may depend on the run-time
3077 -- size of universal real.
3079 if Nkind (Actval) = N_Real_Literal then
3080 Set_Etype (Actval, Base_Type (Etype (F)));
3082 Actval := Unchecked_Convert_To (Etype (F), Actval);
3086 if Is_Scalar_Type (Etype (F)) then
3087 Enable_Range_Check (Actval);
3090 Set_Parent (Actval, N);
3092 -- Resolve aggregates with their base type, to avoid scope
3093 -- anomalies: the subtype was first built in the subprogram
3094 -- declaration, and the current call may be nested.
3096 if Nkind (Actval) = N_Aggregate then
3097 Analyze_And_Resolve (Actval, Etype (F));
3099 Analyze_And_Resolve (Actval, Etype (Actval));
3103 Set_Parent (Actval, N);
3105 -- See note above concerning aggregates
3107 if Nkind (Actval) = N_Aggregate
3108 and then Has_Discriminants (Etype (Actval))
3110 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
3112 -- Resolve entities with their own type, which may differ
3113 -- from the type of a reference in a generic context (the
3114 -- view swapping mechanism did not anticipate the re-analysis
3115 -- of default values in calls).
3117 elsif Is_Entity_Name (Actval) then
3118 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
3121 Analyze_And_Resolve (Actval, Etype (Actval));
3125 -- If default is a tag indeterminate function call, propagate
3126 -- tag to obtain proper dispatching.
3128 if Is_Controlling_Formal (F)
3129 and then Nkind (Default_Value (F)) = N_Function_Call
3131 Set_Is_Controlling_Actual (Actval);
3136 -- If the default expression raises constraint error, then just
3137 -- silently replace it with an N_Raise_Constraint_Error node,
3138 -- since we already gave the warning on the subprogram spec.
3139 -- If node is already a Raise_Constraint_Error leave as is, to
3140 -- prevent loops in the warnings removal machinery.
3142 if Raises_Constraint_Error (Actval)
3143 and then Nkind (Actval) /= N_Raise_Constraint_Error
3146 Make_Raise_Constraint_Error (Loc,
3147 Reason => CE_Range_Check_Failed));
3148 Set_Raises_Constraint_Error (Actval);
3149 Set_Etype (Actval, Etype (F));
3153 Make_Parameter_Association (Loc,
3154 Explicit_Actual_Parameter => Actval,
3155 Selector_Name => Make_Identifier (Loc, Chars (F)));
3157 -- Case of insertion is first named actual
3159 if No (Prev) or else
3160 Nkind (Parent (Prev)) /= N_Parameter_Association
3162 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
3163 Set_First_Named_Actual (N, Actval);
3166 if No (Parameter_Associations (N)) then
3167 Set_Parameter_Associations (N, New_List (Assoc));
3169 Append (Assoc, Parameter_Associations (N));
3173 Insert_After (Prev, Assoc);
3176 -- Case of insertion is not first named actual
3179 Set_Next_Named_Actual
3180 (Assoc, Next_Named_Actual (Parent (Prev)));
3181 Set_Next_Named_Actual (Parent (Prev), Actval);
3182 Append (Assoc, Parameter_Associations (N));
3185 Mark_Rewrite_Insertion (Assoc);
3186 Mark_Rewrite_Insertion (Actval);
3195 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
3196 FT1 : Entity_Id := T1;
3197 FT2 : Entity_Id := T2;
3200 if Is_Private_Type (T1)
3201 and then Present (Full_View (T1))
3203 FT1 := Full_View (T1);
3206 if Is_Private_Type (T2)
3207 and then Present (Full_View (T2))
3209 FT2 := Full_View (T2);
3212 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3215 --------------------------
3216 -- Static_Concatenation --
3217 --------------------------
3219 function Static_Concatenation (N : Node_Id) return Boolean is
3222 when N_String_Literal =>
3227 -- Concatenation is static when both operands are static
3228 -- and the concatenation operator is a predefined one.
3230 return Scope (Entity (N)) = Standard_Standard
3232 Static_Concatenation (Left_Opnd (N))
3234 Static_Concatenation (Right_Opnd (N));
3237 if Is_Entity_Name (N) then
3239 Ent : constant Entity_Id := Entity (N);
3241 return Ekind (Ent) = E_Constant
3242 and then Present (Constant_Value (Ent))
3244 Is_Static_Expression (Constant_Value (Ent));
3251 end Static_Concatenation;
3253 -- Start of processing for Resolve_Actuals
3256 Check_Argument_Order;
3258 if Present (First_Actual (N)) then
3259 Check_Prefixed_Call;
3262 A := First_Actual (N);
3263 F := First_Formal (Nam);
3264 while Present (F) loop
3265 if No (A) and then Needs_No_Actuals (Nam) then
3268 -- If we have an error in any actual or formal, indicated by a type
3269 -- of Any_Type, then abandon resolution attempt, and set result type
3272 elsif (Present (A) and then Etype (A) = Any_Type)
3273 or else Etype (F) = Any_Type
3275 Set_Etype (N, Any_Type);
3279 -- Case where actual is present
3281 -- If the actual is an entity, generate a reference to it now. We
3282 -- do this before the actual is resolved, because a formal of some
3283 -- protected subprogram, or a task discriminant, will be rewritten
3284 -- during expansion, and the reference to the source entity may
3288 and then Is_Entity_Name (A)
3289 and then Comes_From_Source (N)
3291 Orig_A := Entity (A);
3293 if Present (Orig_A) then
3294 if Is_Formal (Orig_A)
3295 and then Ekind (F) /= E_In_Parameter
3297 Generate_Reference (Orig_A, A, 'm');
3298 elsif not Is_Overloaded (A) then
3299 Generate_Reference (Orig_A, A);
3305 and then (Nkind (Parent (A)) /= N_Parameter_Association
3307 Chars (Selector_Name (Parent (A))) = Chars (F))
3309 -- If style checking mode on, check match of formal name
3312 if Nkind (Parent (A)) = N_Parameter_Association then
3313 Check_Identifier (Selector_Name (Parent (A)), F);
3317 -- If the formal is Out or In_Out, do not resolve and expand the
3318 -- conversion, because it is subsequently expanded into explicit
3319 -- temporaries and assignments. However, the object of the
3320 -- conversion can be resolved. An exception is the case of tagged
3321 -- type conversion with a class-wide actual. In that case we want
3322 -- the tag check to occur and no temporary will be needed (no
3323 -- representation change can occur) and the parameter is passed by
3324 -- reference, so we go ahead and resolve the type conversion.
3325 -- Another exception is the case of reference to component or
3326 -- subcomponent of a bit-packed array, in which case we want to
3327 -- defer expansion to the point the in and out assignments are
3330 if Ekind (F) /= E_In_Parameter
3331 and then Nkind (A) = N_Type_Conversion
3332 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3334 if Ekind (F) = E_In_Out_Parameter
3335 and then Is_Array_Type (Etype (F))
3337 -- In a view conversion, the conversion must be legal in
3338 -- both directions, and thus both component types must be
3339 -- aliased, or neither (4.6 (8)).
3341 -- The extra rule in 4.6 (24.9.2) seems unduly restrictive:
3342 -- the privacy requirement should not apply to generic
3343 -- types, and should be checked in an instance. ARG query
3346 if Has_Aliased_Components (Etype (Expression (A))) /=
3347 Has_Aliased_Components (Etype (F))
3350 ("both component types in a view conversion must be"
3351 & " aliased, or neither", A);
3353 -- Comment here??? what set of cases???
3356 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3358 -- Check view conv between unrelated by ref array types
3360 if Is_By_Reference_Type (Etype (F))
3361 or else Is_By_Reference_Type (Etype (Expression (A)))
3364 ("view conversion between unrelated by reference " &
3365 "array types not allowed (\'A'I-00246)", A);
3367 -- In Ada 2005 mode, check view conversion component
3368 -- type cannot be private, tagged, or volatile. Note
3369 -- that we only apply this to source conversions. The
3370 -- generated code can contain conversions which are
3371 -- not subject to this test, and we cannot extract the
3372 -- component type in such cases since it is not present.
3374 elsif Comes_From_Source (A)
3375 and then Ada_Version >= Ada_2005
3378 Comp_Type : constant Entity_Id :=
3380 (Etype (Expression (A)));
3382 if (Is_Private_Type (Comp_Type)
3383 and then not Is_Generic_Type (Comp_Type))
3384 or else Is_Tagged_Type (Comp_Type)
3385 or else Is_Volatile (Comp_Type)
3388 ("component type of a view conversion cannot"
3389 & " be private, tagged, or volatile"
3398 -- Resolve expression if conversion is all OK
3400 if (Conversion_OK (A)
3401 or else Valid_Conversion (A, Etype (A), Expression (A)))
3402 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3404 Resolve (Expression (A));
3407 -- If the actual is a function call that returns a limited
3408 -- unconstrained object that needs finalization, create a
3409 -- transient scope for it, so that it can receive the proper
3410 -- finalization list.
3412 elsif Nkind (A) = N_Function_Call
3413 and then Is_Limited_Record (Etype (F))
3414 and then not Is_Constrained (Etype (F))
3415 and then Expander_Active
3417 (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3419 Establish_Transient_Scope (A, False);
3421 -- A small optimization: if one of the actuals is a concatenation
3422 -- create a block around a procedure call to recover stack space.
3423 -- This alleviates stack usage when several procedure calls in
3424 -- the same statement list use concatenation. We do not perform
3425 -- this wrapping for code statements, where the argument is a
3426 -- static string, and we want to preserve warnings involving
3427 -- sequences of such statements.
3429 elsif Nkind (A) = N_Op_Concat
3430 and then Nkind (N) = N_Procedure_Call_Statement
3431 and then Expander_Active
3433 not (Is_Intrinsic_Subprogram (Nam)
3434 and then Chars (Nam) = Name_Asm)
3435 and then not Static_Concatenation (A)
3437 Establish_Transient_Scope (A, False);
3438 Resolve (A, Etype (F));
3441 if Nkind (A) = N_Type_Conversion
3442 and then Is_Array_Type (Etype (F))
3443 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3445 (Is_Limited_Type (Etype (F))
3446 or else Is_Limited_Type (Etype (Expression (A))))
3449 ("conversion between unrelated limited array types " &
3450 "not allowed (\A\I-00246)", A);
3452 if Is_Limited_Type (Etype (F)) then
3453 Explain_Limited_Type (Etype (F), A);
3456 if Is_Limited_Type (Etype (Expression (A))) then
3457 Explain_Limited_Type (Etype (Expression (A)), A);
3461 -- (Ada 2005: AI-251): If the actual is an allocator whose
3462 -- directly designated type is a class-wide interface, we build
3463 -- an anonymous access type to use it as the type of the
3464 -- allocator. Later, when the subprogram call is expanded, if
3465 -- the interface has a secondary dispatch table the expander
3466 -- will add a type conversion to force the correct displacement
3469 if Nkind (A) = N_Allocator then
3471 DDT : constant Entity_Id :=
3472 Directly_Designated_Type (Base_Type (Etype (F)));
3474 New_Itype : Entity_Id;
3477 if Is_Class_Wide_Type (DDT)
3478 and then Is_Interface (DDT)
3480 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3481 Set_Etype (New_Itype, Etype (A));
3482 Set_Directly_Designated_Type (New_Itype,
3483 Directly_Designated_Type (Etype (A)));
3484 Set_Etype (A, New_Itype);
3487 -- Ada 2005, AI-162:If the actual is an allocator, the
3488 -- innermost enclosing statement is the master of the
3489 -- created object. This needs to be done with expansion
3490 -- enabled only, otherwise the transient scope will not
3491 -- be removed in the expansion of the wrapped construct.
3493 if (Is_Controlled (DDT) or else Has_Task (DDT))
3494 and then Expander_Active
3496 Establish_Transient_Scope (A, False);
3501 -- (Ada 2005): The call may be to a primitive operation of
3502 -- a tagged synchronized type, declared outside of the type.
3503 -- In this case the controlling actual must be converted to
3504 -- its corresponding record type, which is the formal type.
3505 -- The actual may be a subtype, either because of a constraint
3506 -- or because it is a generic actual, so use base type to
3507 -- locate concurrent type.
3509 A_Typ := Base_Type (Etype (A));
3510 F_Typ := Base_Type (Etype (F));
3513 Full_A_Typ : Entity_Id;
3516 if Present (Full_View (A_Typ)) then
3517 Full_A_Typ := Base_Type (Full_View (A_Typ));
3519 Full_A_Typ := A_Typ;
3522 -- Tagged synchronized type (case 1): the actual is a
3525 if Is_Concurrent_Type (A_Typ)
3526 and then Corresponding_Record_Type (A_Typ) = F_Typ
3529 Unchecked_Convert_To
3530 (Corresponding_Record_Type (A_Typ), A));
3531 Resolve (A, Etype (F));
3533 -- Tagged synchronized type (case 2): the formal is a
3536 elsif Ekind (Full_A_Typ) = E_Record_Type
3538 (Corresponding_Concurrent_Type (Full_A_Typ))
3539 and then Is_Concurrent_Type (F_Typ)
3540 and then Present (Corresponding_Record_Type (F_Typ))
3541 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3543 Resolve (A, Corresponding_Record_Type (F_Typ));
3548 Resolve (A, Etype (F));
3556 -- Save actual for subsequent check on order dependence, and
3557 -- indicate whether actual is modifiable. For AI05-0144-2.
3559 Save_Actual (A, Ekind (F) /= E_In_Parameter);
3561 -- For mode IN, if actual is an entity, and the type of the formal
3562 -- has warnings suppressed, then we reset Never_Set_In_Source for
3563 -- the calling entity. The reason for this is to catch cases like
3564 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3565 -- uses trickery to modify an IN parameter.
3567 if Ekind (F) = E_In_Parameter
3568 and then Is_Entity_Name (A)
3569 and then Present (Entity (A))
3570 and then Ekind (Entity (A)) = E_Variable
3571 and then Has_Warnings_Off (F_Typ)
3573 Set_Never_Set_In_Source (Entity (A), False);
3576 -- Perform error checks for IN and IN OUT parameters
3578 if Ekind (F) /= E_Out_Parameter then
3580 -- Check unset reference. For scalar parameters, it is clearly
3581 -- wrong to pass an uninitialized value as either an IN or
3582 -- IN-OUT parameter. For composites, it is also clearly an
3583 -- error to pass a completely uninitialized value as an IN
3584 -- parameter, but the case of IN OUT is trickier. We prefer
3585 -- not to give a warning here. For example, suppose there is
3586 -- a routine that sets some component of a record to False.
3587 -- It is perfectly reasonable to make this IN-OUT and allow
3588 -- either initialized or uninitialized records to be passed
3591 -- For partially initialized composite values, we also avoid
3592 -- warnings, since it is quite likely that we are passing a
3593 -- partially initialized value and only the initialized fields
3594 -- will in fact be read in the subprogram.
3596 if Is_Scalar_Type (A_Typ)
3597 or else (Ekind (F) = E_In_Parameter
3598 and then not Is_Partially_Initialized_Type (A_Typ))
3600 Check_Unset_Reference (A);
3603 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3604 -- actual to a nested call, since this is case of reading an
3605 -- out parameter, which is not allowed.
3607 if Ada_Version = Ada_83
3608 and then Is_Entity_Name (A)
3609 and then Ekind (Entity (A)) = E_Out_Parameter
3611 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3615 -- Case of OUT or IN OUT parameter
3617 if Ekind (F) /= E_In_Parameter then
3619 -- For an Out parameter, check for useless assignment. Note
3620 -- that we can't set Last_Assignment this early, because we may
3621 -- kill current values in Resolve_Call, and that call would
3622 -- clobber the Last_Assignment field.
3624 -- Note: call Warn_On_Useless_Assignment before doing the check
3625 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3626 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3627 -- reflects the last assignment, not this one!
3629 if Ekind (F) = E_Out_Parameter then
3630 if Warn_On_Modified_As_Out_Parameter (F)
3631 and then Is_Entity_Name (A)
3632 and then Present (Entity (A))
3633 and then Comes_From_Source (N)
3635 Warn_On_Useless_Assignment (Entity (A), A);
3639 -- Validate the form of the actual. Note that the call to
3640 -- Is_OK_Variable_For_Out_Formal generates the required
3641 -- reference in this case.
3643 if not Is_OK_Variable_For_Out_Formal (A) then
3644 Error_Msg_NE ("actual for& must be a variable", A, F);
3647 -- What's the following about???
3649 if Is_Entity_Name (A) then
3650 Kill_Checks (Entity (A));
3656 if Etype (A) = Any_Type then
3657 Set_Etype (N, Any_Type);
3661 -- Apply appropriate range checks for in, out, and in-out
3662 -- parameters. Out and in-out parameters also need a separate
3663 -- check, if there is a type conversion, to make sure the return
3664 -- value meets the constraints of the variable before the
3667 -- Gigi looks at the check flag and uses the appropriate types.
3668 -- For now since one flag is used there is an optimization which
3669 -- might not be done in the In Out case since Gigi does not do
3670 -- any analysis. More thought required about this ???
3672 if Ekind_In (F, E_In_Parameter, E_In_Out_Parameter) then
3674 -- Apply predicate checks, unless this is a call to the
3675 -- predicate check function itself, which would cause an
3676 -- infinite recursion.
3678 if not (Ekind (Nam) = E_Function
3679 and then Has_Predicates (Nam))
3681 Apply_Predicate_Check (A, F_Typ);
3684 -- Apply required constraint checks
3686 if Is_Scalar_Type (Etype (A)) then
3687 Apply_Scalar_Range_Check (A, F_Typ);
3689 elsif Is_Array_Type (Etype (A)) then
3690 Apply_Length_Check (A, F_Typ);
3692 elsif Is_Record_Type (F_Typ)
3693 and then Has_Discriminants (F_Typ)
3694 and then Is_Constrained (F_Typ)
3695 and then (not Is_Derived_Type (F_Typ)
3696 or else Comes_From_Source (Nam))
3698 Apply_Discriminant_Check (A, F_Typ);
3700 elsif Is_Access_Type (F_Typ)
3701 and then Is_Array_Type (Designated_Type (F_Typ))
3702 and then Is_Constrained (Designated_Type (F_Typ))
3704 Apply_Length_Check (A, F_Typ);
3706 elsif Is_Access_Type (F_Typ)
3707 and then Has_Discriminants (Designated_Type (F_Typ))
3708 and then Is_Constrained (Designated_Type (F_Typ))
3710 Apply_Discriminant_Check (A, F_Typ);
3713 Apply_Range_Check (A, F_Typ);
3716 -- Ada 2005 (AI-231): Note that the controlling parameter case
3717 -- already existed in Ada 95, which is partially checked
3718 -- elsewhere (see Checks), and we don't want the warning
3719 -- message to differ.
3721 if Is_Access_Type (F_Typ)
3722 and then Can_Never_Be_Null (F_Typ)
3723 and then Known_Null (A)
3725 if Is_Controlling_Formal (F) then
3726 Apply_Compile_Time_Constraint_Error
3728 Msg => "null value not allowed here?",
3729 Reason => CE_Access_Check_Failed);
3731 elsif Ada_Version >= Ada_2005 then
3732 Apply_Compile_Time_Constraint_Error
3734 Msg => "(Ada 2005) null not allowed in "
3735 & "null-excluding formal?",
3736 Reason => CE_Null_Not_Allowed);
3741 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter) then
3742 if Nkind (A) = N_Type_Conversion then
3743 if Is_Scalar_Type (A_Typ) then
3744 Apply_Scalar_Range_Check
3745 (Expression (A), Etype (Expression (A)), A_Typ);
3748 (Expression (A), Etype (Expression (A)), A_Typ);
3752 if Is_Scalar_Type (F_Typ) then
3753 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3755 elsif Is_Array_Type (F_Typ)
3756 and then Ekind (F) = E_Out_Parameter
3758 Apply_Length_Check (A, F_Typ);
3761 Apply_Range_Check (A, A_Typ, F_Typ);
3766 -- An actual associated with an access parameter is implicitly
3767 -- converted to the anonymous access type of the formal and must
3768 -- satisfy the legality checks for access conversions.
3770 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3771 if not Valid_Conversion (A, F_Typ, A) then
3773 ("invalid implicit conversion for access parameter", A);
3777 -- Check bad case of atomic/volatile argument (RM C.6(12))
3779 if Is_By_Reference_Type (Etype (F))
3780 and then Comes_From_Source (N)
3782 if Is_Atomic_Object (A)
3783 and then not Is_Atomic (Etype (F))
3786 ("cannot pass atomic argument to non-atomic formal",
3789 elsif Is_Volatile_Object (A)
3790 and then not Is_Volatile (Etype (F))
3793 ("cannot pass volatile argument to non-volatile formal",
3798 -- Check that subprograms don't have improper controlling
3799 -- arguments (RM 3.9.2 (9)).
3801 -- A primitive operation may have an access parameter of an
3802 -- incomplete tagged type, but a dispatching call is illegal
3803 -- if the type is still incomplete.
3805 if Is_Controlling_Formal (F) then
3806 Set_Is_Controlling_Actual (A);
3808 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3810 Desig : constant Entity_Id := Designated_Type (Etype (F));
3812 if Ekind (Desig) = E_Incomplete_Type
3813 and then No (Full_View (Desig))
3814 and then No (Non_Limited_View (Desig))
3817 ("premature use of incomplete type& " &
3818 "in dispatching call", A, Desig);
3823 elsif Nkind (A) = N_Explicit_Dereference then
3824 Validate_Remote_Access_To_Class_Wide_Type (A);
3827 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3828 and then not Is_Class_Wide_Type (F_Typ)
3829 and then not Is_Controlling_Formal (F)
3831 Error_Msg_N ("class-wide argument not allowed here!", A);
3833 if Is_Subprogram (Nam)
3834 and then Comes_From_Source (Nam)
3836 Error_Msg_Node_2 := F_Typ;
3838 ("& is not a dispatching operation of &!", A, Nam);
3841 elsif Is_Access_Type (A_Typ)
3842 and then Is_Access_Type (F_Typ)
3843 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3844 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3845 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3846 or else (Nkind (A) = N_Attribute_Reference
3848 Is_Class_Wide_Type (Etype (Prefix (A)))))
3849 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3850 and then not Is_Controlling_Formal (F)
3852 -- Disable these checks for call to imported C++ subprograms
3855 (Is_Entity_Name (Name (N))
3856 and then Is_Imported (Entity (Name (N)))
3857 and then Convention (Entity (Name (N))) = Convention_CPP)
3860 ("access to class-wide argument not allowed here!", A);
3862 if Is_Subprogram (Nam)
3863 and then Comes_From_Source (Nam)
3865 Error_Msg_Node_2 := Designated_Type (F_Typ);
3867 ("& is not a dispatching operation of &!", A, Nam);
3873 -- If it is a named association, treat the selector_name as a
3874 -- proper identifier, and mark the corresponding entity.
3876 if Nkind (Parent (A)) = N_Parameter_Association then
3877 Set_Entity (Selector_Name (Parent (A)), F);
3878 Generate_Reference (F, Selector_Name (Parent (A)));
3879 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3880 Generate_Reference (F_Typ, N, ' ');
3885 if Ekind (F) /= E_Out_Parameter then
3886 Check_Unset_Reference (A);
3891 -- Case where actual is not present
3899 end Resolve_Actuals;
3901 -----------------------
3902 -- Resolve_Allocator --
3903 -----------------------
3905 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
3906 E : constant Node_Id := Expression (N);
3908 Discrim : Entity_Id;
3911 Assoc : Node_Id := Empty;
3914 procedure Check_Allocator_Discrim_Accessibility
3915 (Disc_Exp : Node_Id;
3916 Alloc_Typ : Entity_Id);
3917 -- Check that accessibility level associated with an access discriminant
3918 -- initialized in an allocator by the expression Disc_Exp is not deeper
3919 -- than the level of the allocator type Alloc_Typ. An error message is
3920 -- issued if this condition is violated. Specialized checks are done for
3921 -- the cases of a constraint expression which is an access attribute or
3922 -- an access discriminant.
3924 function In_Dispatching_Context return Boolean;
3925 -- If the allocator is an actual in a call, it is allowed to be class-
3926 -- wide when the context is not because it is a controlling actual.
3928 procedure Propagate_Coextensions (Root : Node_Id);
3929 -- Propagate all nested coextensions which are located one nesting
3930 -- level down the tree to the node Root. Example:
3933 -- Level_1_Coextension
3934 -- Level_2_Coextension
3936 -- The algorithm is paired with delay actions done by the Expander. In
3937 -- the above example, assume all coextensions are controlled types.
3938 -- The cycle of analysis, resolution and expansion will yield:
3940 -- 1) Analyze Top_Record
3941 -- 2) Analyze Level_1_Coextension
3942 -- 3) Analyze Level_2_Coextension
3943 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
3945 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3946 -- generated to capture the allocated object. Temp_1 is attached
3947 -- to the coextension chain of Level_2_Coextension.
3948 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3949 -- coextension. A forward tree traversal is performed which finds
3950 -- Level_2_Coextension's list and copies its contents into its
3952 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3953 -- generated to capture the allocated object. Temp_2 is attached
3954 -- to the coextension chain of Level_1_Coextension. Currently, the
3955 -- contents of the list are [Temp_2, Temp_1].
3956 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3957 -- finds Level_1_Coextension's list and copies its contents into
3959 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3960 -- Temp_2 and attach them to Top_Record's finalization list.
3962 -------------------------------------------
3963 -- Check_Allocator_Discrim_Accessibility --
3964 -------------------------------------------
3966 procedure Check_Allocator_Discrim_Accessibility
3967 (Disc_Exp : Node_Id;
3968 Alloc_Typ : Entity_Id)
3971 if Type_Access_Level (Etype (Disc_Exp)) >
3972 Type_Access_Level (Alloc_Typ)
3975 ("operand type has deeper level than allocator type", Disc_Exp);
3977 -- When the expression is an Access attribute the level of the prefix
3978 -- object must not be deeper than that of the allocator's type.
3980 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3981 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3983 and then Object_Access_Level (Prefix (Disc_Exp))
3984 > Type_Access_Level (Alloc_Typ)
3987 ("prefix of attribute has deeper level than allocator type",
3990 -- When the expression is an access discriminant the check is against
3991 -- the level of the prefix object.
3993 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3994 and then Nkind (Disc_Exp) = N_Selected_Component
3995 and then Object_Access_Level (Prefix (Disc_Exp))
3996 > Type_Access_Level (Alloc_Typ)
3999 ("access discriminant has deeper level than allocator type",
4002 -- All other cases are legal
4007 end Check_Allocator_Discrim_Accessibility;
4009 ----------------------------
4010 -- In_Dispatching_Context --
4011 ----------------------------
4013 function In_Dispatching_Context return Boolean is
4014 Par : constant Node_Id := Parent (N);
4016 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
4017 and then Is_Entity_Name (Name (Par))
4018 and then Is_Dispatching_Operation (Entity (Name (Par)));
4019 end In_Dispatching_Context;
4021 ----------------------------
4022 -- Propagate_Coextensions --
4023 ----------------------------
4025 procedure Propagate_Coextensions (Root : Node_Id) is
4027 procedure Copy_List (From : Elist_Id; To : Elist_Id);
4028 -- Copy the contents of list From into list To, preserving the
4029 -- order of elements.
4031 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
4032 -- Recognize an allocator or a rewritten allocator node and add it
4033 -- along with its nested coextensions to the list of Root.
4039 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
4040 From_Elmt : Elmt_Id;
4042 From_Elmt := First_Elmt (From);
4043 while Present (From_Elmt) loop
4044 Append_Elmt (Node (From_Elmt), To);
4045 Next_Elmt (From_Elmt);
4049 -----------------------
4050 -- Process_Allocator --
4051 -----------------------
4053 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
4054 Orig_Nod : Node_Id := Nod;
4057 -- This is a possible rewritten subtype indication allocator. Any
4058 -- nested coextensions will appear as discriminant constraints.
4060 if Nkind (Nod) = N_Identifier
4061 and then Present (Original_Node (Nod))
4062 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
4066 Discr_Elmt : Elmt_Id;
4069 if Is_Record_Type (Entity (Nod)) then
4071 First_Elmt (Discriminant_Constraint (Entity (Nod)));
4072 while Present (Discr_Elmt) loop
4073 Discr := Node (Discr_Elmt);
4075 if Nkind (Discr) = N_Identifier
4076 and then Present (Original_Node (Discr))
4077 and then Nkind (Original_Node (Discr)) = N_Allocator
4078 and then Present (Coextensions (
4079 Original_Node (Discr)))
4081 if No (Coextensions (Root)) then
4082 Set_Coextensions (Root, New_Elmt_List);
4086 (From => Coextensions (Original_Node (Discr)),
4087 To => Coextensions (Root));
4090 Next_Elmt (Discr_Elmt);
4093 -- There is no need to continue the traversal of this
4094 -- subtree since all the information has already been
4101 -- Case of either a stand alone allocator or a rewritten allocator
4102 -- with an aggregate.
4105 if Present (Original_Node (Nod)) then
4106 Orig_Nod := Original_Node (Nod);
4109 if Nkind (Orig_Nod) = N_Allocator then
4111 -- Propagate the list of nested coextensions to the Root
4112 -- allocator. This is done through list copy since a single
4113 -- allocator may have multiple coextensions. Do not touch
4114 -- coextensions roots.
4116 if not Is_Coextension_Root (Orig_Nod)
4117 and then Present (Coextensions (Orig_Nod))
4119 if No (Coextensions (Root)) then
4120 Set_Coextensions (Root, New_Elmt_List);
4124 (From => Coextensions (Orig_Nod),
4125 To => Coextensions (Root));
4128 -- There is no need to continue the traversal of this
4129 -- subtree since all the information has already been
4136 -- Keep on traversing, looking for the next allocator
4139 end Process_Allocator;
4141 procedure Process_Allocators is
4142 new Traverse_Proc (Process_Allocator);
4144 -- Start of processing for Propagate_Coextensions
4147 Process_Allocators (Expression (Root));
4148 end Propagate_Coextensions;
4150 -- Start of processing for Resolve_Allocator
4153 -- Replace general access with specific type
4155 if Ekind (Etype (N)) = E_Allocator_Type then
4156 Set_Etype (N, Base_Type (Typ));
4159 if Is_Abstract_Type (Typ) then
4160 Error_Msg_N ("type of allocator cannot be abstract", N);
4163 -- For qualified expression, resolve the expression using the
4164 -- given subtype (nothing to do for type mark, subtype indication)
4166 if Nkind (E) = N_Qualified_Expression then
4167 if Is_Class_Wide_Type (Etype (E))
4168 and then not Is_Class_Wide_Type (Designated_Type (Typ))
4169 and then not In_Dispatching_Context
4172 ("class-wide allocator not allowed for this access type", N);
4175 Resolve (Expression (E), Etype (E));
4176 Check_Unset_Reference (Expression (E));
4178 -- A qualified expression requires an exact match of the type,
4179 -- class-wide matching is not allowed.
4181 if (Is_Class_Wide_Type (Etype (Expression (E)))
4182 or else Is_Class_Wide_Type (Etype (E)))
4183 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
4185 Wrong_Type (Expression (E), Etype (E));
4188 -- A special accessibility check is needed for allocators that
4189 -- constrain access discriminants. The level of the type of the
4190 -- expression used to constrain an access discriminant cannot be
4191 -- deeper than the type of the allocator (in contrast to access
4192 -- parameters, where the level of the actual can be arbitrary).
4194 -- We can't use Valid_Conversion to perform this check because
4195 -- in general the type of the allocator is unrelated to the type
4196 -- of the access discriminant.
4198 if Ekind (Typ) /= E_Anonymous_Access_Type
4199 or else Is_Local_Anonymous_Access (Typ)
4201 Subtyp := Entity (Subtype_Mark (E));
4203 Aggr := Original_Node (Expression (E));
4205 if Has_Discriminants (Subtyp)
4206 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
4208 Discrim := First_Discriminant (Base_Type (Subtyp));
4210 -- Get the first component expression of the aggregate
4212 if Present (Expressions (Aggr)) then
4213 Disc_Exp := First (Expressions (Aggr));
4215 elsif Present (Component_Associations (Aggr)) then
4216 Assoc := First (Component_Associations (Aggr));
4218 if Present (Assoc) then
4219 Disc_Exp := Expression (Assoc);
4228 while Present (Discrim) and then Present (Disc_Exp) loop
4229 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4230 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4233 Next_Discriminant (Discrim);
4235 if Present (Discrim) then
4236 if Present (Assoc) then
4238 Disc_Exp := Expression (Assoc);
4240 elsif Present (Next (Disc_Exp)) then
4244 Assoc := First (Component_Associations (Aggr));
4246 if Present (Assoc) then
4247 Disc_Exp := Expression (Assoc);
4257 -- For a subtype mark or subtype indication, freeze the subtype
4260 Freeze_Expression (E);
4262 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
4264 ("initialization required for access-to-constant allocator", N);
4267 -- A special accessibility check is needed for allocators that
4268 -- constrain access discriminants. The level of the type of the
4269 -- expression used to constrain an access discriminant cannot be
4270 -- deeper than the type of the allocator (in contrast to access
4271 -- parameters, where the level of the actual can be arbitrary).
4272 -- We can't use Valid_Conversion to perform this check because
4273 -- in general the type of the allocator is unrelated to the type
4274 -- of the access discriminant.
4276 if Nkind (Original_Node (E)) = N_Subtype_Indication
4277 and then (Ekind (Typ) /= E_Anonymous_Access_Type
4278 or else Is_Local_Anonymous_Access (Typ))
4280 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
4282 if Has_Discriminants (Subtyp) then
4283 Discrim := First_Discriminant (Base_Type (Subtyp));
4284 Constr := First (Constraints (Constraint (Original_Node (E))));
4285 while Present (Discrim) and then Present (Constr) loop
4286 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4287 if Nkind (Constr) = N_Discriminant_Association then
4288 Disc_Exp := Original_Node (Expression (Constr));
4290 Disc_Exp := Original_Node (Constr);
4293 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4296 Next_Discriminant (Discrim);
4303 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4304 -- check that the level of the type of the created object is not deeper
4305 -- than the level of the allocator's access type, since extensions can
4306 -- now occur at deeper levels than their ancestor types. This is a
4307 -- static accessibility level check; a run-time check is also needed in
4308 -- the case of an initialized allocator with a class-wide argument (see
4309 -- Expand_Allocator_Expression).
4311 if Ada_Version >= Ada_2005
4312 and then Is_Class_Wide_Type (Designated_Type (Typ))
4315 Exp_Typ : Entity_Id;
4318 if Nkind (E) = N_Qualified_Expression then
4319 Exp_Typ := Etype (E);
4320 elsif Nkind (E) = N_Subtype_Indication then
4321 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4323 Exp_Typ := Entity (E);
4326 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4327 if In_Instance_Body then
4328 Error_Msg_N ("?type in allocator has deeper level than" &
4329 " designated class-wide type", E);
4330 Error_Msg_N ("\?Program_Error will be raised at run time",
4333 Make_Raise_Program_Error (Sloc (N),
4334 Reason => PE_Accessibility_Check_Failed));
4337 -- Do not apply Ada 2005 accessibility checks on a class-wide
4338 -- allocator if the type given in the allocator is a formal
4339 -- type. A run-time check will be performed in the instance.
4341 elsif not Is_Generic_Type (Exp_Typ) then
4342 Error_Msg_N ("type in allocator has deeper level than" &
4343 " designated class-wide type", E);
4349 -- Check for allocation from an empty storage pool
4351 if No_Pool_Assigned (Typ) then
4352 Error_Msg_N ("allocation from empty storage pool!", N);
4354 -- If the context is an unchecked conversion, as may happen within
4355 -- an inlined subprogram, the allocator is being resolved with its
4356 -- own anonymous type. In that case, if the target type has a specific
4357 -- storage pool, it must be inherited explicitly by the allocator type.
4359 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4360 and then No (Associated_Storage_Pool (Typ))
4362 Set_Associated_Storage_Pool
4363 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4366 if Ekind (Etype (N)) = E_Anonymous_Access_Type then
4367 Check_Restriction (No_Anonymous_Allocators, N);
4370 -- An erroneous allocator may be rewritten as a raise Program_Error
4373 if Nkind (N) = N_Allocator then
4375 -- An anonymous access discriminant is the definition of a
4378 if Ekind (Typ) = E_Anonymous_Access_Type
4379 and then Nkind (Associated_Node_For_Itype (Typ)) =
4380 N_Discriminant_Specification
4382 -- Avoid marking an allocator as a dynamic coextension if it is
4383 -- within a static construct.
4385 if not Is_Static_Coextension (N) then
4386 Set_Is_Dynamic_Coextension (N);
4389 -- Cleanup for potential static coextensions
4392 Set_Is_Dynamic_Coextension (N, False);
4393 Set_Is_Static_Coextension (N, False);
4396 -- There is no need to propagate any nested coextensions if they
4397 -- are marked as static since they will be rewritten on the spot.
4399 if not Is_Static_Coextension (N) then
4400 Propagate_Coextensions (N);
4403 end Resolve_Allocator;
4405 ---------------------------
4406 -- Resolve_Arithmetic_Op --
4407 ---------------------------
4409 -- Used for resolving all arithmetic operators except exponentiation
4411 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4412 L : constant Node_Id := Left_Opnd (N);
4413 R : constant Node_Id := Right_Opnd (N);
4414 TL : constant Entity_Id := Base_Type (Etype (L));
4415 TR : constant Entity_Id := Base_Type (Etype (R));
4419 B_Typ : constant Entity_Id := Base_Type (Typ);
4420 -- We do the resolution using the base type, because intermediate values
4421 -- in expressions always are of the base type, not a subtype of it.
4423 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4424 -- Returns True if N is in a context that expects "any real type"
4426 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4427 -- Return True iff given type is Integer or universal real/integer
4429 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4430 -- Choose type of integer literal in fixed-point operation to conform
4431 -- to available fixed-point type. T is the type of the other operand,
4432 -- which is needed to determine the expected type of N.
4434 procedure Set_Operand_Type (N : Node_Id);
4435 -- Set operand type to T if universal
4437 -------------------------------
4438 -- Expected_Type_Is_Any_Real --
4439 -------------------------------
4441 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4443 -- N is the expression after "delta" in a fixed_point_definition;
4446 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4447 N_Decimal_Fixed_Point_Definition,
4449 -- N is one of the bounds in a real_range_specification;
4452 N_Real_Range_Specification,
4454 -- N is the expression of a delta_constraint;
4457 N_Delta_Constraint);
4458 end Expected_Type_Is_Any_Real;
4460 -----------------------------
4461 -- Is_Integer_Or_Universal --
4462 -----------------------------
4464 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4466 Index : Interp_Index;
4470 if not Is_Overloaded (N) then
4472 return Base_Type (T) = Base_Type (Standard_Integer)
4473 or else T = Universal_Integer
4474 or else T = Universal_Real;
4476 Get_First_Interp (N, Index, It);
4477 while Present (It.Typ) loop
4478 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4479 or else It.Typ = Universal_Integer
4480 or else It.Typ = Universal_Real
4485 Get_Next_Interp (Index, It);
4490 end Is_Integer_Or_Universal;
4492 ----------------------------
4493 -- Set_Mixed_Mode_Operand --
4494 ----------------------------
4496 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4497 Index : Interp_Index;
4501 if Universal_Interpretation (N) = Universal_Integer then
4503 -- A universal integer literal is resolved as standard integer
4504 -- except in the case of a fixed-point result, where we leave it
4505 -- as universal (to be handled by Exp_Fixd later on)
4507 if Is_Fixed_Point_Type (T) then
4508 Resolve (N, Universal_Integer);
4510 Resolve (N, Standard_Integer);
4513 elsif Universal_Interpretation (N) = Universal_Real
4514 and then (T = Base_Type (Standard_Integer)
4515 or else T = Universal_Integer
4516 or else T = Universal_Real)
4518 -- A universal real can appear in a fixed-type context. We resolve
4519 -- the literal with that context, even though this might raise an
4520 -- exception prematurely (the other operand may be zero).
4524 elsif Etype (N) = Base_Type (Standard_Integer)
4525 and then T = Universal_Real
4526 and then Is_Overloaded (N)
4528 -- Integer arg in mixed-mode operation. Resolve with universal
4529 -- type, in case preference rule must be applied.
4531 Resolve (N, Universal_Integer);
4534 and then B_Typ /= Universal_Fixed
4536 -- Not a mixed-mode operation, resolve with context
4540 elsif Etype (N) = Any_Fixed then
4542 -- N may itself be a mixed-mode operation, so use context type
4546 elsif Is_Fixed_Point_Type (T)
4547 and then B_Typ = Universal_Fixed
4548 and then Is_Overloaded (N)
4550 -- Must be (fixed * fixed) operation, operand must have one
4551 -- compatible interpretation.
4553 Resolve (N, Any_Fixed);
4555 elsif Is_Fixed_Point_Type (B_Typ)
4556 and then (T = Universal_Real
4557 or else Is_Fixed_Point_Type (T))
4558 and then Is_Overloaded (N)
4560 -- C * F(X) in a fixed context, where C is a real literal or a
4561 -- fixed-point expression. F must have either a fixed type
4562 -- interpretation or an integer interpretation, but not both.
4564 Get_First_Interp (N, Index, It);
4565 while Present (It.Typ) loop
4566 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4568 if Analyzed (N) then
4569 Error_Msg_N ("ambiguous operand in fixed operation", N);
4571 Resolve (N, Standard_Integer);
4574 elsif Is_Fixed_Point_Type (It.Typ) then
4576 if Analyzed (N) then
4577 Error_Msg_N ("ambiguous operand in fixed operation", N);
4579 Resolve (N, It.Typ);
4583 Get_Next_Interp (Index, It);
4586 -- Reanalyze the literal with the fixed type of the context. If
4587 -- context is Universal_Fixed, we are within a conversion, leave
4588 -- the literal as a universal real because there is no usable
4589 -- fixed type, and the target of the conversion plays no role in
4603 if B_Typ = Universal_Fixed
4604 and then Nkind (Op2) = N_Real_Literal
4606 T2 := Universal_Real;
4611 Set_Analyzed (Op2, False);
4618 end Set_Mixed_Mode_Operand;
4620 ----------------------
4621 -- Set_Operand_Type --
4622 ----------------------
4624 procedure Set_Operand_Type (N : Node_Id) is
4626 if Etype (N) = Universal_Integer
4627 or else Etype (N) = Universal_Real
4631 end Set_Operand_Type;
4633 -- Start of processing for Resolve_Arithmetic_Op
4636 if Comes_From_Source (N)
4637 and then Ekind (Entity (N)) = E_Function
4638 and then Is_Imported (Entity (N))
4639 and then Is_Intrinsic_Subprogram (Entity (N))
4641 Resolve_Intrinsic_Operator (N, Typ);
4644 -- Special-case for mixed-mode universal expressions or fixed point
4645 -- type operation: each argument is resolved separately. The same
4646 -- treatment is required if one of the operands of a fixed point
4647 -- operation is universal real, since in this case we don't do a
4648 -- conversion to a specific fixed-point type (instead the expander
4649 -- takes care of the case).
4651 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4652 and then Present (Universal_Interpretation (L))
4653 and then Present (Universal_Interpretation (R))
4655 Resolve (L, Universal_Interpretation (L));
4656 Resolve (R, Universal_Interpretation (R));
4657 Set_Etype (N, B_Typ);
4659 elsif (B_Typ = Universal_Real
4660 or else Etype (N) = Universal_Fixed
4661 or else (Etype (N) = Any_Fixed
4662 and then Is_Fixed_Point_Type (B_Typ))
4663 or else (Is_Fixed_Point_Type (B_Typ)
4664 and then (Is_Integer_Or_Universal (L)
4666 Is_Integer_Or_Universal (R))))
4667 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4669 if TL = Universal_Integer or else TR = Universal_Integer then
4670 Check_For_Visible_Operator (N, B_Typ);
4673 -- If context is a fixed type and one operand is integer, the
4674 -- other is resolved with the type of the context.
4676 if Is_Fixed_Point_Type (B_Typ)
4677 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4678 or else TL = Universal_Integer)
4683 elsif Is_Fixed_Point_Type (B_Typ)
4684 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4685 or else TR = Universal_Integer)
4691 Set_Mixed_Mode_Operand (L, TR);
4692 Set_Mixed_Mode_Operand (R, TL);
4695 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4696 -- multiplying operators from being used when the expected type is
4697 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4698 -- some cases where the expected type is actually Any_Real;
4699 -- Expected_Type_Is_Any_Real takes care of that case.
4701 if Etype (N) = Universal_Fixed
4702 or else Etype (N) = Any_Fixed
4704 if B_Typ = Universal_Fixed
4705 and then not Expected_Type_Is_Any_Real (N)
4706 and then not Nkind_In (Parent (N), N_Type_Conversion,
4707 N_Unchecked_Type_Conversion)
4709 Error_Msg_N ("type cannot be determined from context!", N);
4710 Error_Msg_N ("\explicit conversion to result type required", N);
4712 Set_Etype (L, Any_Type);
4713 Set_Etype (R, Any_Type);
4716 if Ada_Version = Ada_83
4717 and then Etype (N) = Universal_Fixed
4719 Nkind_In (Parent (N), N_Type_Conversion,
4720 N_Unchecked_Type_Conversion)
4723 ("(Ada 83) fixed-point operation "
4724 & "needs explicit conversion", N);
4727 -- The expected type is "any real type" in contexts like
4728 -- type T is delta <universal_fixed-expression> ...
4729 -- in which case we need to set the type to Universal_Real
4730 -- so that static expression evaluation will work properly.
4732 if Expected_Type_Is_Any_Real (N) then
4733 Set_Etype (N, Universal_Real);
4735 Set_Etype (N, B_Typ);
4739 elsif Is_Fixed_Point_Type (B_Typ)
4740 and then (Is_Integer_Or_Universal (L)
4741 or else Nkind (L) = N_Real_Literal
4742 or else Nkind (R) = N_Real_Literal
4743 or else Is_Integer_Or_Universal (R))
4745 Set_Etype (N, B_Typ);
4747 elsif Etype (N) = Any_Fixed then
4749 -- If no previous errors, this is only possible if one operand
4750 -- is overloaded and the context is universal. Resolve as such.
4752 Set_Etype (N, B_Typ);
4756 if (TL = Universal_Integer or else TL = Universal_Real)
4758 (TR = Universal_Integer or else TR = Universal_Real)
4760 Check_For_Visible_Operator (N, B_Typ);
4763 -- If the context is Universal_Fixed and the operands are also
4764 -- universal fixed, this is an error, unless there is only one
4765 -- applicable fixed_point type (usually Duration).
4767 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4768 T := Unique_Fixed_Point_Type (N);
4770 if T = Any_Type then
4783 -- If one of the arguments was resolved to a non-universal type.
4784 -- label the result of the operation itself with the same type.
4785 -- Do the same for the universal argument, if any.
4787 T := Intersect_Types (L, R);
4788 Set_Etype (N, Base_Type (T));
4789 Set_Operand_Type (L);
4790 Set_Operand_Type (R);
4793 Generate_Operator_Reference (N, Typ);
4794 Eval_Arithmetic_Op (N);
4796 -- Set overflow and division checking bit. Much cleverer code needed
4797 -- here eventually and perhaps the Resolve routines should be separated
4798 -- for the various arithmetic operations, since they will need
4799 -- different processing. ???
4801 if Nkind (N) in N_Op then
4802 if not Overflow_Checks_Suppressed (Etype (N)) then
4803 Enable_Overflow_Check (N);
4806 -- Give warning if explicit division by zero
4808 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4809 and then not Division_Checks_Suppressed (Etype (N))
4811 Rop := Right_Opnd (N);
4813 if Compile_Time_Known_Value (Rop)
4814 and then ((Is_Integer_Type (Etype (Rop))
4815 and then Expr_Value (Rop) = Uint_0)
4817 (Is_Real_Type (Etype (Rop))
4818 and then Expr_Value_R (Rop) = Ureal_0))
4820 -- Specialize the warning message according to the operation
4824 Apply_Compile_Time_Constraint_Error
4825 (N, "division by zero?", CE_Divide_By_Zero,
4826 Loc => Sloc (Right_Opnd (N)));
4829 Apply_Compile_Time_Constraint_Error
4830 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4831 Loc => Sloc (Right_Opnd (N)));
4834 Apply_Compile_Time_Constraint_Error
4835 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4836 Loc => Sloc (Right_Opnd (N)));
4838 -- Division by zero can only happen with division, rem,
4839 -- and mod operations.
4842 raise Program_Error;
4845 -- Otherwise just set the flag to check at run time
4848 Activate_Division_Check (N);
4852 -- If Restriction No_Implicit_Conditionals is active, then it is
4853 -- violated if either operand can be negative for mod, or for rem
4854 -- if both operands can be negative.
4856 if Restriction_Check_Required (No_Implicit_Conditionals)
4857 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4866 -- Set if corresponding operand might be negative
4870 (Left_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4871 LNeg := (not OK) or else Lo < 0;
4874 (Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4875 RNeg := (not OK) or else Lo < 0;
4877 -- Check if we will be generating conditionals. There are two
4878 -- cases where that can happen, first for REM, the only case
4879 -- is largest negative integer mod -1, where the division can
4880 -- overflow, but we still have to give the right result. The
4881 -- front end generates a test for this annoying case. Here we
4882 -- just test if both operands can be negative (that's what the
4883 -- expander does, so we match its logic here).
4885 -- The second case is mod where either operand can be negative.
4886 -- In this case, the back end has to generate additonal tests.
4888 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4890 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
4892 Check_Restriction (No_Implicit_Conditionals, N);
4898 Check_Unset_Reference (L);
4899 Check_Unset_Reference (R);
4900 end Resolve_Arithmetic_Op;
4906 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
4907 Loc : constant Source_Ptr := Sloc (N);
4908 Subp : constant Node_Id := Name (N);
4916 function Same_Or_Aliased_Subprograms
4918 E : Entity_Id) return Boolean;
4919 -- Returns True if the subprogram entity S is the same as E or else
4920 -- S is an alias of E.
4922 ---------------------------------
4923 -- Same_Or_Aliased_Subprograms --
4924 ---------------------------------
4926 function Same_Or_Aliased_Subprograms
4928 E : Entity_Id) return Boolean
4930 Subp_Alias : constant Entity_Id := Alias (S);
4933 or else (Present (Subp_Alias) and then Subp_Alias = E);
4934 end Same_Or_Aliased_Subprograms;
4936 -- Start of processing for Resolve_Call
4939 -- The context imposes a unique interpretation with type Typ on a
4940 -- procedure or function call. Find the entity of the subprogram that
4941 -- yields the expected type, and propagate the corresponding formal
4942 -- constraints on the actuals. The caller has established that an
4943 -- interpretation exists, and emitted an error if not unique.
4945 -- First deal with the case of a call to an access-to-subprogram,
4946 -- dereference made explicit in Analyze_Call.
4948 if Ekind (Etype (Subp)) = E_Subprogram_Type then
4949 if not Is_Overloaded (Subp) then
4950 Nam := Etype (Subp);
4953 -- Find the interpretation whose type (a subprogram type) has a
4954 -- return type that is compatible with the context. Analysis of
4955 -- the node has established that one exists.
4959 Get_First_Interp (Subp, I, It);
4960 while Present (It.Typ) loop
4961 if Covers (Typ, Etype (It.Typ)) then
4966 Get_Next_Interp (I, It);
4970 raise Program_Error;
4974 -- If the prefix is not an entity, then resolve it
4976 if not Is_Entity_Name (Subp) then
4977 Resolve (Subp, Nam);
4980 -- For an indirect call, we always invalidate checks, since we do not
4981 -- know whether the subprogram is local or global. Yes we could do
4982 -- better here, e.g. by knowing that there are no local subprograms,
4983 -- but it does not seem worth the effort. Similarly, we kill all
4984 -- knowledge of current constant values.
4986 Kill_Current_Values;
4988 -- If this is a procedure call which is really an entry call, do
4989 -- the conversion of the procedure call to an entry call. Protected
4990 -- operations use the same circuitry because the name in the call
4991 -- can be an arbitrary expression with special resolution rules.
4993 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
4994 or else (Is_Entity_Name (Subp)
4995 and then Ekind (Entity (Subp)) = E_Entry)
4997 Resolve_Entry_Call (N, Typ);
4998 Check_Elab_Call (N);
5000 -- Kill checks and constant values, as above for indirect case
5001 -- Who knows what happens when another task is activated?
5003 Kill_Current_Values;
5006 -- Normal subprogram call with name established in Resolve
5008 elsif not (Is_Type (Entity (Subp))) then
5009 Nam := Entity (Subp);
5010 Set_Entity_With_Style_Check (Subp, Nam);
5012 -- Otherwise we must have the case of an overloaded call
5015 pragma Assert (Is_Overloaded (Subp));
5017 -- Initialize Nam to prevent warning (we know it will be assigned
5018 -- in the loop below, but the compiler does not know that).
5022 Get_First_Interp (Subp, I, It);
5023 while Present (It.Typ) loop
5024 if Covers (Typ, It.Typ) then
5026 Set_Entity_With_Style_Check (Subp, Nam);
5030 Get_Next_Interp (I, It);
5034 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
5035 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
5036 and then Nkind (Subp) /= N_Explicit_Dereference
5037 and then Present (Parameter_Associations (N))
5039 -- The prefix is a parameterless function call that returns an access
5040 -- to subprogram. If parameters are present in the current call, add
5041 -- add an explicit dereference. We use the base type here because
5042 -- within an instance these may be subtypes.
5044 -- The dereference is added either in Analyze_Call or here. Should
5045 -- be consolidated ???
5047 Set_Is_Overloaded (Subp, False);
5048 Set_Etype (Subp, Etype (Nam));
5049 Insert_Explicit_Dereference (Subp);
5050 Nam := Designated_Type (Etype (Nam));
5051 Resolve (Subp, Nam);
5054 -- Check that a call to Current_Task does not occur in an entry body
5056 if Is_RTE (Nam, RE_Current_Task) then
5065 -- Exclude calls that occur within the default of a formal
5066 -- parameter of the entry, since those are evaluated outside
5069 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
5071 if Nkind (P) = N_Entry_Body
5072 or else (Nkind (P) = N_Subprogram_Body
5073 and then Is_Entry_Barrier_Function (P))
5077 ("?& should not be used in entry body (RM C.7(17))",
5080 ("\Program_Error will be raised at run time?", N, Nam);
5082 Make_Raise_Program_Error (Loc,
5083 Reason => PE_Current_Task_In_Entry_Body));
5084 Set_Etype (N, Rtype);
5091 -- Check that a procedure call does not occur in the context of the
5092 -- entry call statement of a conditional or timed entry call. Note that
5093 -- the case of a call to a subprogram renaming of an entry will also be
5094 -- rejected. The test for N not being an N_Entry_Call_Statement is
5095 -- defensive, covering the possibility that the processing of entry
5096 -- calls might reach this point due to later modifications of the code
5099 if Nkind (Parent (N)) = N_Entry_Call_Alternative
5100 and then Nkind (N) /= N_Entry_Call_Statement
5101 and then Entry_Call_Statement (Parent (N)) = N
5103 if Ada_Version < Ada_2005 then
5104 Error_Msg_N ("entry call required in select statement", N);
5106 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5107 -- for a procedure_or_entry_call, the procedure_name or
5108 -- procedure_prefix of the procedure_call_statement shall denote
5109 -- an entry renamed by a procedure, or (a view of) a primitive
5110 -- subprogram of a limited interface whose first parameter is
5111 -- a controlling parameter.
5113 elsif Nkind (N) = N_Procedure_Call_Statement
5114 and then not Is_Renamed_Entry (Nam)
5115 and then not Is_Controlling_Limited_Procedure (Nam)
5118 ("entry call or dispatching primitive of interface required", N);
5122 -- Check that this is not a call to a protected procedure or entry from
5123 -- within a protected function.
5125 if Ekind (Current_Scope) = E_Function
5126 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
5127 and then Ekind (Nam) /= E_Function
5128 and then Scope (Nam) = Scope (Current_Scope)
5130 Error_Msg_N ("within protected function, protected " &
5131 "object is constant", N);
5132 Error_Msg_N ("\cannot call operation that may modify it", N);
5135 -- Freeze the subprogram name if not in a spec-expression. Note that we
5136 -- freeze procedure calls as well as function calls. Procedure calls are
5137 -- not frozen according to the rules (RM 13.14(14)) because it is
5138 -- impossible to have a procedure call to a non-frozen procedure in pure
5139 -- Ada, but in the code that we generate in the expander, this rule
5140 -- needs extending because we can generate procedure calls that need
5143 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
5144 Freeze_Expression (Subp);
5147 -- For a predefined operator, the type of the result is the type imposed
5148 -- by context, except for a predefined operation on universal fixed.
5149 -- Otherwise The type of the call is the type returned by the subprogram
5152 if Is_Predefined_Op (Nam) then
5153 if Etype (N) /= Universal_Fixed then
5157 -- If the subprogram returns an array type, and the context requires the
5158 -- component type of that array type, the node is really an indexing of
5159 -- the parameterless call. Resolve as such. A pathological case occurs
5160 -- when the type of the component is an access to the array type. In
5161 -- this case the call is truly ambiguous.
5163 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
5165 ((Is_Array_Type (Etype (Nam))
5166 and then Covers (Typ, Component_Type (Etype (Nam))))
5167 or else (Is_Access_Type (Etype (Nam))
5168 and then Is_Array_Type (Designated_Type (Etype (Nam)))
5171 Component_Type (Designated_Type (Etype (Nam))))))
5174 Index_Node : Node_Id;
5176 Ret_Type : constant Entity_Id := Etype (Nam);
5179 if Is_Access_Type (Ret_Type)
5180 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
5183 ("cannot disambiguate function call and indexing", N);
5185 New_Subp := Relocate_Node (Subp);
5186 Set_Entity (Subp, Nam);
5188 if (Is_Array_Type (Ret_Type)
5189 and then Component_Type (Ret_Type) /= Any_Type)
5191 (Is_Access_Type (Ret_Type)
5193 Component_Type (Designated_Type (Ret_Type)) /= Any_Type)
5195 if Needs_No_Actuals (Nam) then
5197 -- Indexed call to a parameterless function
5200 Make_Indexed_Component (Loc,
5202 Make_Function_Call (Loc,
5204 Expressions => Parameter_Associations (N));
5206 -- An Ada 2005 prefixed call to a primitive operation
5207 -- whose first parameter is the prefix. This prefix was
5208 -- prepended to the parameter list, which is actually a
5209 -- list of indexes. Remove the prefix in order to build
5210 -- the proper indexed component.
5213 Make_Indexed_Component (Loc,
5215 Make_Function_Call (Loc,
5217 Parameter_Associations =>
5219 (Remove_Head (Parameter_Associations (N)))),
5220 Expressions => Parameter_Associations (N));
5223 -- Preserve the parenthesis count of the node
5225 Set_Paren_Count (Index_Node, Paren_Count (N));
5227 -- Since we are correcting a node classification error made
5228 -- by the parser, we call Replace rather than Rewrite.
5230 Replace (N, Index_Node);
5232 Set_Etype (Prefix (N), Ret_Type);
5234 Resolve_Indexed_Component (N, Typ);
5235 Check_Elab_Call (Prefix (N));
5243 Set_Etype (N, Etype (Nam));
5246 -- In the case where the call is to an overloaded subprogram, Analyze
5247 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5248 -- such a case Normalize_Actuals needs to be called once more to order
5249 -- the actuals correctly. Otherwise the call will have the ordering
5250 -- given by the last overloaded subprogram whether this is the correct
5251 -- one being called or not.
5253 if Is_Overloaded (Subp) then
5254 Normalize_Actuals (N, Nam, False, Norm_OK);
5255 pragma Assert (Norm_OK);
5258 -- In any case, call is fully resolved now. Reset Overload flag, to
5259 -- prevent subsequent overload resolution if node is analyzed again
5261 Set_Is_Overloaded (Subp, False);
5262 Set_Is_Overloaded (N, False);
5264 -- If we are calling the current subprogram from immediately within its
5265 -- body, then that is the case where we can sometimes detect cases of
5266 -- infinite recursion statically. Do not try this in case restriction
5267 -- No_Recursion is in effect anyway, and do it only for source calls.
5269 if Comes_From_Source (N) then
5270 Scop := Current_Scope;
5272 -- Issue warning for possible infinite recursion in the absence
5273 -- of the No_Recursion restriction.
5275 if Same_Or_Aliased_Subprograms (Nam, Scop)
5276 and then not Restriction_Active (No_Recursion)
5277 and then Check_Infinite_Recursion (N)
5279 -- Here we detected and flagged an infinite recursion, so we do
5280 -- not need to test the case below for further warnings. Also if
5281 -- we now have a raise SE node, we are all done.
5283 if Nkind (N) = N_Raise_Storage_Error then
5287 -- If call is to immediately containing subprogram, then check for
5288 -- the case of a possible run-time detectable infinite recursion.
5291 Scope_Loop : while Scop /= Standard_Standard loop
5292 if Same_Or_Aliased_Subprograms (Nam, Scop) then
5294 -- Although in general case, recursion is not statically
5295 -- checkable, the case of calling an immediately containing
5296 -- subprogram is easy to catch.
5298 Check_Restriction (No_Recursion, N);
5300 -- If the recursive call is to a parameterless subprogram,
5301 -- then even if we can't statically detect infinite
5302 -- recursion, this is pretty suspicious, and we output a
5303 -- warning. Furthermore, we will try later to detect some
5304 -- cases here at run time by expanding checking code (see
5305 -- Detect_Infinite_Recursion in package Exp_Ch6).
5307 -- If the recursive call is within a handler, do not emit a
5308 -- warning, because this is a common idiom: loop until input
5309 -- is correct, catch illegal input in handler and restart.
5311 if No (First_Formal (Nam))
5312 and then Etype (Nam) = Standard_Void_Type
5313 and then not Error_Posted (N)
5314 and then Nkind (Parent (N)) /= N_Exception_Handler
5316 -- For the case of a procedure call. We give the message
5317 -- only if the call is the first statement in a sequence
5318 -- of statements, or if all previous statements are
5319 -- simple assignments. This is simply a heuristic to
5320 -- decrease false positives, without losing too many good
5321 -- warnings. The idea is that these previous statements
5322 -- may affect global variables the procedure depends on.
5324 if Nkind (N) = N_Procedure_Call_Statement
5325 and then Is_List_Member (N)
5331 while Present (P) loop
5332 if Nkind (P) /= N_Assignment_Statement then
5341 -- Do not give warning if we are in a conditional context
5344 K : constant Node_Kind := Nkind (Parent (N));
5346 if (K = N_Loop_Statement
5347 and then Present (Iteration_Scheme (Parent (N))))
5348 or else K = N_If_Statement
5349 or else K = N_Elsif_Part
5350 or else K = N_Case_Statement_Alternative
5356 -- Here warning is to be issued
5358 Set_Has_Recursive_Call (Nam);
5360 ("?possible infinite recursion!", N);
5362 ("\?Storage_Error may be raised at run time!", N);
5368 Scop := Scope (Scop);
5369 end loop Scope_Loop;
5373 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5375 Check_Obsolescent_2005_Entity (Nam, Subp);
5377 -- If subprogram name is a predefined operator, it was given in
5378 -- functional notation. Replace call node with operator node, so
5379 -- that actuals can be resolved appropriately.
5381 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5382 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5385 elsif Present (Alias (Nam))
5386 and then Is_Predefined_Op (Alias (Nam))
5388 Resolve_Actuals (N, Nam);
5389 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5393 -- Create a transient scope if the resulting type requires it
5395 -- There are several notable exceptions:
5397 -- a) In init procs, the transient scope overhead is not needed, and is
5398 -- even incorrect when the call is a nested initialization call for a
5399 -- component whose expansion may generate adjust calls. However, if the
5400 -- call is some other procedure call within an initialization procedure
5401 -- (for example a call to Create_Task in the init_proc of the task
5402 -- run-time record) a transient scope must be created around this call.
5404 -- b) Enumeration literal pseudo-calls need no transient scope
5406 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5407 -- functions) do not use the secondary stack even though the return
5408 -- type may be unconstrained.
5410 -- d) Calls to a build-in-place function, since such functions may
5411 -- allocate their result directly in a target object, and cases where
5412 -- the result does get allocated in the secondary stack are checked for
5413 -- within the specialized Exp_Ch6 procedures for expanding those
5414 -- build-in-place calls.
5416 -- e) If the subprogram is marked Inline_Always, then even if it returns
5417 -- an unconstrained type the call does not require use of the secondary
5418 -- stack. However, inlining will only take place if the body to inline
5419 -- is already present. It may not be available if e.g. the subprogram is
5420 -- declared in a child instance.
5422 -- If this is an initialization call for a type whose construction
5423 -- uses the secondary stack, and it is not a nested call to initialize
5424 -- a component, we do need to create a transient scope for it. We
5425 -- check for this by traversing the type in Check_Initialization_Call.
5428 and then Has_Pragma_Inline_Always (Nam)
5429 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5430 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5434 elsif Ekind (Nam) = E_Enumeration_Literal
5435 or else Is_Build_In_Place_Function (Nam)
5436 or else Is_Intrinsic_Subprogram (Nam)
5440 elsif Expander_Active
5441 and then Is_Type (Etype (Nam))
5442 and then Requires_Transient_Scope (Etype (Nam))
5444 (not Within_Init_Proc
5446 (not Is_Init_Proc (Nam) and then Ekind (Nam) /= E_Function))
5448 Establish_Transient_Scope (N, Sec_Stack => True);
5450 -- If the call appears within the bounds of a loop, it will
5451 -- be rewritten and reanalyzed, nothing left to do here.
5453 if Nkind (N) /= N_Function_Call then
5457 elsif Is_Init_Proc (Nam)
5458 and then not Within_Init_Proc
5460 Check_Initialization_Call (N, Nam);
5463 -- A protected function cannot be called within the definition of the
5464 -- enclosing protected type.
5466 if Is_Protected_Type (Scope (Nam))
5467 and then In_Open_Scopes (Scope (Nam))
5468 and then not Has_Completion (Scope (Nam))
5471 ("& cannot be called before end of protected definition", N, Nam);
5474 -- Propagate interpretation to actuals, and add default expressions
5477 if Present (First_Formal (Nam)) then
5478 Resolve_Actuals (N, Nam);
5480 -- Overloaded literals are rewritten as function calls, for purpose of
5481 -- resolution. After resolution, we can replace the call with the
5484 elsif Ekind (Nam) = E_Enumeration_Literal then
5485 Copy_Node (Subp, N);
5486 Resolve_Entity_Name (N, Typ);
5488 -- Avoid validation, since it is a static function call
5490 Generate_Reference (Nam, Subp);
5494 -- If the subprogram is not global, then kill all saved values and
5495 -- checks. This is a bit conservative, since in many cases we could do
5496 -- better, but it is not worth the effort. Similarly, we kill constant
5497 -- values. However we do not need to do this for internal entities
5498 -- (unless they are inherited user-defined subprograms), since they
5499 -- are not in the business of molesting local values.
5501 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5502 -- kill all checks and values for calls to global subprograms. This
5503 -- takes care of the case where an access to a local subprogram is
5504 -- taken, and could be passed directly or indirectly and then called
5505 -- from almost any context.
5507 -- Note: we do not do this step till after resolving the actuals. That
5508 -- way we still take advantage of the current value information while
5509 -- scanning the actuals.
5511 -- We suppress killing values if we are processing the nodes associated
5512 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5513 -- type kills all the values as part of analyzing the code that
5514 -- initializes the dispatch tables.
5516 if Inside_Freezing_Actions = 0
5517 and then (not Is_Library_Level_Entity (Nam)
5518 or else Suppress_Value_Tracking_On_Call
5519 (Nearest_Dynamic_Scope (Current_Scope)))
5520 and then (Comes_From_Source (Nam)
5521 or else (Present (Alias (Nam))
5522 and then Comes_From_Source (Alias (Nam))))
5524 Kill_Current_Values;
5527 -- If we are warning about unread OUT parameters, this is the place to
5528 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5529 -- after the above call to Kill_Current_Values (since that call clears
5530 -- the Last_Assignment field of all local variables).
5532 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5533 and then Comes_From_Source (N)
5534 and then In_Extended_Main_Source_Unit (N)
5541 F := First_Formal (Nam);
5542 A := First_Actual (N);
5543 while Present (F) and then Present (A) loop
5544 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter)
5545 and then Warn_On_Modified_As_Out_Parameter (F)
5546 and then Is_Entity_Name (A)
5547 and then Present (Entity (A))
5548 and then Comes_From_Source (N)
5549 and then Safe_To_Capture_Value (N, Entity (A))
5551 Set_Last_Assignment (Entity (A), A);
5560 -- If the subprogram is a primitive operation, check whether or not
5561 -- it is a correct dispatching call.
5563 if Is_Overloadable (Nam)
5564 and then Is_Dispatching_Operation (Nam)
5566 Check_Dispatching_Call (N);
5568 elsif Ekind (Nam) /= E_Subprogram_Type
5569 and then Is_Abstract_Subprogram (Nam)
5570 and then not In_Instance
5572 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5575 -- If this is a dispatching call, generate the appropriate reference,
5576 -- for better source navigation in GPS.
5578 if Is_Overloadable (Nam)
5579 and then Present (Controlling_Argument (N))
5581 Generate_Reference (Nam, Subp, 'R');
5583 -- Normal case, not a dispatching call. Generate a call reference.
5586 Generate_Reference (Nam, Subp, 's');
5589 if Is_Intrinsic_Subprogram (Nam) then
5590 Check_Intrinsic_Call (N);
5593 -- Check for violation of restriction No_Specific_Termination_Handlers
5594 -- and warn on a potentially blocking call to Abort_Task.
5596 if Is_RTE (Nam, RE_Set_Specific_Handler)
5598 Is_RTE (Nam, RE_Specific_Handler)
5600 Check_Restriction (No_Specific_Termination_Handlers, N);
5602 elsif Is_RTE (Nam, RE_Abort_Task) then
5603 Check_Potentially_Blocking_Operation (N);
5606 -- A call to Ada.Real_Time.Timing_Events.Set_Handler violates
5607 -- restriction No_Relative_Delay (AI-0211).
5609 if Is_RTE (Nam, RE_Set_Handler) then
5610 Check_Restriction (No_Relative_Delay, N);
5613 -- Issue an error for a call to an eliminated subprogram. We skip this
5614 -- in a spec expression, e.g. a call in a default parameter value, since
5615 -- we are not really doing a call at this time. That's important because
5616 -- the spec expression may itself belong to an eliminated subprogram.
5618 if not In_Spec_Expression then
5619 Check_For_Eliminated_Subprogram (Subp, Nam);
5622 -- All done, evaluate call and deal with elaboration issues
5625 Check_Elab_Call (N);
5626 Warn_On_Overlapping_Actuals (Nam, N);
5629 -----------------------------
5630 -- Resolve_Case_Expression --
5631 -----------------------------
5633 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id) is
5637 Alt := First (Alternatives (N));
5638 while Present (Alt) loop
5639 Resolve (Expression (Alt), Typ);
5644 Eval_Case_Expression (N);
5645 end Resolve_Case_Expression;
5647 -------------------------------
5648 -- Resolve_Character_Literal --
5649 -------------------------------
5651 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5652 B_Typ : constant Entity_Id := Base_Type (Typ);
5656 -- Verify that the character does belong to the type of the context
5658 Set_Etype (N, B_Typ);
5659 Eval_Character_Literal (N);
5661 -- Wide_Wide_Character literals must always be defined, since the set
5662 -- of wide wide character literals is complete, i.e. if a character
5663 -- literal is accepted by the parser, then it is OK for wide wide
5664 -- character (out of range character literals are rejected).
5666 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5669 -- Always accept character literal for type Any_Character, which
5670 -- occurs in error situations and in comparisons of literals, both
5671 -- of which should accept all literals.
5673 elsif B_Typ = Any_Character then
5676 -- For Standard.Character or a type derived from it, check that
5677 -- the literal is in range
5679 elsif Root_Type (B_Typ) = Standard_Character then
5680 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5684 -- For Standard.Wide_Character or a type derived from it, check
5685 -- that the literal is in range
5687 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5688 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5692 -- For Standard.Wide_Wide_Character or a type derived from it, we
5693 -- know the literal is in range, since the parser checked!
5695 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5698 -- If the entity is already set, this has already been resolved in a
5699 -- generic context, or comes from expansion. Nothing else to do.
5701 elsif Present (Entity (N)) then
5704 -- Otherwise we have a user defined character type, and we can use the
5705 -- standard visibility mechanisms to locate the referenced entity.
5708 C := Current_Entity (N);
5709 while Present (C) loop
5710 if Etype (C) = B_Typ then
5711 Set_Entity_With_Style_Check (N, C);
5712 Generate_Reference (C, N);
5720 -- If we fall through, then the literal does not match any of the
5721 -- entries of the enumeration type. This isn't just a constraint
5722 -- error situation, it is an illegality (see RM 4.2).
5725 ("character not defined for }", N, First_Subtype (B_Typ));
5726 end Resolve_Character_Literal;
5728 ---------------------------
5729 -- Resolve_Comparison_Op --
5730 ---------------------------
5732 -- Context requires a boolean type, and plays no role in resolution.
5733 -- Processing identical to that for equality operators. The result
5734 -- type is the base type, which matters when pathological subtypes of
5735 -- booleans with limited ranges are used.
5737 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5738 L : constant Node_Id := Left_Opnd (N);
5739 R : constant Node_Id := Right_Opnd (N);
5743 -- If this is an intrinsic operation which is not predefined, use the
5744 -- types of its declared arguments to resolve the possibly overloaded
5745 -- operands. Otherwise the operands are unambiguous and specify the
5748 if Scope (Entity (N)) /= Standard_Standard then
5749 T := Etype (First_Entity (Entity (N)));
5752 T := Find_Unique_Type (L, R);
5754 if T = Any_Fixed then
5755 T := Unique_Fixed_Point_Type (L);
5759 Set_Etype (N, Base_Type (Typ));
5760 Generate_Reference (T, N, ' ');
5762 -- Skip remaining processing if already set to Any_Type
5764 if T = Any_Type then
5768 -- Deal with other error cases
5770 if T = Any_String or else
5771 T = Any_Composite or else
5774 if T = Any_Character then
5775 Ambiguous_Character (L);
5777 Error_Msg_N ("ambiguous operands for comparison", N);
5780 Set_Etype (N, Any_Type);
5784 -- Resolve the operands if types OK
5788 Check_Unset_Reference (L);
5789 Check_Unset_Reference (R);
5790 Generate_Operator_Reference (N, T);
5791 Check_Low_Bound_Tested (N);
5793 -- Check comparison on unordered enumeration
5795 if Comes_From_Source (N)
5796 and then Bad_Unordered_Enumeration_Reference (N, Etype (L))
5798 Error_Msg_N ("comparison on unordered enumeration type?", N);
5801 -- Evaluate the relation (note we do this after the above check
5802 -- since this Eval call may change N to True/False.
5804 Eval_Relational_Op (N);
5805 end Resolve_Comparison_Op;
5807 ------------------------------------
5808 -- Resolve_Conditional_Expression --
5809 ------------------------------------
5811 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
5812 Condition : constant Node_Id := First (Expressions (N));
5813 Then_Expr : constant Node_Id := Next (Condition);
5814 Else_Expr : Node_Id := Next (Then_Expr);
5817 Resolve (Condition, Any_Boolean);
5818 Resolve (Then_Expr, Typ);
5820 -- If ELSE expression present, just resolve using the determined type
5822 if Present (Else_Expr) then
5823 Resolve (Else_Expr, Typ);
5825 -- If no ELSE expression is present, root type must be Standard.Boolean
5826 -- and we provide a Standard.True result converted to the appropriate
5827 -- Boolean type (in case it is a derived boolean type).
5829 elsif Root_Type (Typ) = Standard_Boolean then
5831 Convert_To (Typ, New_Occurrence_Of (Standard_True, Sloc (N)));
5832 Analyze_And_Resolve (Else_Expr, Typ);
5833 Append_To (Expressions (N), Else_Expr);
5836 Error_Msg_N ("can only omit ELSE expression in Boolean case", N);
5837 Append_To (Expressions (N), Error);
5841 Eval_Conditional_Expression (N);
5842 end Resolve_Conditional_Expression;
5844 -----------------------------------------
5845 -- Resolve_Discrete_Subtype_Indication --
5846 -----------------------------------------
5848 procedure Resolve_Discrete_Subtype_Indication
5856 Analyze (Subtype_Mark (N));
5857 S := Entity (Subtype_Mark (N));
5859 if Nkind (Constraint (N)) /= N_Range_Constraint then
5860 Error_Msg_N ("expect range constraint for discrete type", N);
5861 Set_Etype (N, Any_Type);
5864 R := Range_Expression (Constraint (N));
5872 if Base_Type (S) /= Base_Type (Typ) then
5874 ("expect subtype of }", N, First_Subtype (Typ));
5876 -- Rewrite the constraint as a range of Typ
5877 -- to allow compilation to proceed further.
5880 Rewrite (Low_Bound (R),
5881 Make_Attribute_Reference (Sloc (Low_Bound (R)),
5882 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5883 Attribute_Name => Name_First));
5884 Rewrite (High_Bound (R),
5885 Make_Attribute_Reference (Sloc (High_Bound (R)),
5886 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5887 Attribute_Name => Name_First));
5891 Set_Etype (N, Etype (R));
5893 -- Additionally, we must check that the bounds are compatible
5894 -- with the given subtype, which might be different from the
5895 -- type of the context.
5897 Apply_Range_Check (R, S);
5899 -- ??? If the above check statically detects a Constraint_Error
5900 -- it replaces the offending bound(s) of the range R with a
5901 -- Constraint_Error node. When the itype which uses these bounds
5902 -- is frozen the resulting call to Duplicate_Subexpr generates
5903 -- a new temporary for the bounds.
5905 -- Unfortunately there are other itypes that are also made depend
5906 -- on these bounds, so when Duplicate_Subexpr is called they get
5907 -- a forward reference to the newly created temporaries and Gigi
5908 -- aborts on such forward references. This is probably sign of a
5909 -- more fundamental problem somewhere else in either the order of
5910 -- itype freezing or the way certain itypes are constructed.
5912 -- To get around this problem we call Remove_Side_Effects right
5913 -- away if either bounds of R are a Constraint_Error.
5916 L : constant Node_Id := Low_Bound (R);
5917 H : constant Node_Id := High_Bound (R);
5920 if Nkind (L) = N_Raise_Constraint_Error then
5921 Remove_Side_Effects (L);
5924 if Nkind (H) = N_Raise_Constraint_Error then
5925 Remove_Side_Effects (H);
5929 Check_Unset_Reference (Low_Bound (R));
5930 Check_Unset_Reference (High_Bound (R));
5933 end Resolve_Discrete_Subtype_Indication;
5935 -------------------------
5936 -- Resolve_Entity_Name --
5937 -------------------------
5939 -- Used to resolve identifiers and expanded names
5941 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
5942 E : constant Entity_Id := Entity (N);
5945 -- If garbage from errors, set to Any_Type and return
5947 if No (E) and then Total_Errors_Detected /= 0 then
5948 Set_Etype (N, Any_Type);
5952 -- Replace named numbers by corresponding literals. Note that this is
5953 -- the one case where Resolve_Entity_Name must reset the Etype, since
5954 -- it is currently marked as universal.
5956 if Ekind (E) = E_Named_Integer then
5958 Eval_Named_Integer (N);
5960 elsif Ekind (E) = E_Named_Real then
5962 Eval_Named_Real (N);
5964 -- For enumeration literals, we need to make sure that a proper style
5965 -- check is done, since such literals are overloaded, and thus we did
5966 -- not do a style check during the first phase of analysis.
5968 elsif Ekind (E) = E_Enumeration_Literal then
5969 Set_Entity_With_Style_Check (N, E);
5970 Eval_Entity_Name (N);
5972 -- Case of subtype name appearing as an operand in expression
5974 elsif Is_Type (E) then
5976 -- Allow use of subtype if it is a concurrent type where we are
5977 -- currently inside the body. This will eventually be expanded into a
5978 -- call to Self (for tasks) or _object (for protected objects). Any
5979 -- other use of a subtype is invalid.
5981 if Is_Concurrent_Type (E)
5982 and then In_Open_Scopes (E)
5986 -- Any other use is an eror
5990 ("invalid use of subtype mark in expression or call", N);
5993 -- Check discriminant use if entity is discriminant in current scope,
5994 -- i.e. discriminant of record or concurrent type currently being
5995 -- analyzed. Uses in corresponding body are unrestricted.
5997 elsif Ekind (E) = E_Discriminant
5998 and then Scope (E) = Current_Scope
5999 and then not Has_Completion (Current_Scope)
6001 Check_Discriminant_Use (N);
6003 -- A parameterless generic function cannot appear in a context that
6004 -- requires resolution.
6006 elsif Ekind (E) = E_Generic_Function then
6007 Error_Msg_N ("illegal use of generic function", N);
6009 elsif Ekind (E) = E_Out_Parameter
6010 and then Ada_Version = Ada_83
6011 and then (Nkind (Parent (N)) in N_Op
6012 or else (Nkind (Parent (N)) = N_Assignment_Statement
6013 and then N = Expression (Parent (N)))
6014 or else Nkind (Parent (N)) = N_Explicit_Dereference)
6016 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
6018 -- In all other cases, just do the possible static evaluation
6021 -- A deferred constant that appears in an expression must have a
6022 -- completion, unless it has been removed by in-place expansion of
6025 if Ekind (E) = E_Constant
6026 and then Comes_From_Source (E)
6027 and then No (Constant_Value (E))
6028 and then Is_Frozen (Etype (E))
6029 and then not In_Spec_Expression
6030 and then not Is_Imported (E)
6032 if No_Initialization (Parent (E))
6033 or else (Present (Full_View (E))
6034 and then No_Initialization (Parent (Full_View (E))))
6039 "deferred constant is frozen before completion", N);
6043 Eval_Entity_Name (N);
6045 end Resolve_Entity_Name;
6051 procedure Resolve_Entry (Entry_Name : Node_Id) is
6052 Loc : constant Source_Ptr := Sloc (Entry_Name);
6060 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
6061 -- If the bounds of the entry family being called depend on task
6062 -- discriminants, build a new index subtype where a discriminant is
6063 -- replaced with the value of the discriminant of the target task.
6064 -- The target task is the prefix of the entry name in the call.
6066 -----------------------
6067 -- Actual_Index_Type --
6068 -----------------------
6070 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
6071 Typ : constant Entity_Id := Entry_Index_Type (E);
6072 Tsk : constant Entity_Id := Scope (E);
6073 Lo : constant Node_Id := Type_Low_Bound (Typ);
6074 Hi : constant Node_Id := Type_High_Bound (Typ);
6077 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
6078 -- If the bound is given by a discriminant, replace with a reference
6079 -- to the discriminant of the same name in the target task. If the
6080 -- entry name is the target of a requeue statement and the entry is
6081 -- in the current protected object, the bound to be used is the
6082 -- discriminal of the object (see Apply_Range_Checks for details of
6083 -- the transformation).
6085 -----------------------------
6086 -- Actual_Discriminant_Ref --
6087 -----------------------------
6089 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
6090 Typ : constant Entity_Id := Etype (Bound);
6094 Remove_Side_Effects (Bound);
6096 if not Is_Entity_Name (Bound)
6097 or else Ekind (Entity (Bound)) /= E_Discriminant
6101 elsif Is_Protected_Type (Tsk)
6102 and then In_Open_Scopes (Tsk)
6103 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
6105 -- Note: here Bound denotes a discriminant of the corresponding
6106 -- record type tskV, whose discriminal is a formal of the
6107 -- init-proc tskVIP. What we want is the body discriminal,
6108 -- which is associated to the discriminant of the original
6109 -- concurrent type tsk.
6111 return New_Occurrence_Of
6112 (Find_Body_Discriminal (Entity (Bound)), Loc);
6116 Make_Selected_Component (Loc,
6117 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
6118 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
6123 end Actual_Discriminant_Ref;
6125 -- Start of processing for Actual_Index_Type
6128 if not Has_Discriminants (Tsk)
6129 or else (not Is_Entity_Name (Lo)
6131 not Is_Entity_Name (Hi))
6133 return Entry_Index_Type (E);
6136 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
6137 Set_Etype (New_T, Base_Type (Typ));
6138 Set_Size_Info (New_T, Typ);
6139 Set_RM_Size (New_T, RM_Size (Typ));
6140 Set_Scalar_Range (New_T,
6141 Make_Range (Sloc (Entry_Name),
6142 Low_Bound => Actual_Discriminant_Ref (Lo),
6143 High_Bound => Actual_Discriminant_Ref (Hi)));
6147 end Actual_Index_Type;
6149 -- Start of processing of Resolve_Entry
6152 -- Find name of entry being called, and resolve prefix of name
6153 -- with its own type. The prefix can be overloaded, and the name
6154 -- and signature of the entry must be taken into account.
6156 if Nkind (Entry_Name) = N_Indexed_Component then
6158 -- Case of dealing with entry family within the current tasks
6160 E_Name := Prefix (Entry_Name);
6163 E_Name := Entry_Name;
6166 if Is_Entity_Name (E_Name) then
6168 -- Entry call to an entry (or entry family) in the current task. This
6169 -- is legal even though the task will deadlock. Rewrite as call to
6172 -- This can also be a call to an entry in an enclosing task. If this
6173 -- is a single task, we have to retrieve its name, because the scope
6174 -- of the entry is the task type, not the object. If the enclosing
6175 -- task is a task type, the identity of the task is given by its own
6178 -- Finally this can be a requeue on an entry of the same task or
6179 -- protected object.
6181 S := Scope (Entity (E_Name));
6183 for J in reverse 0 .. Scope_Stack.Last loop
6184 if Is_Task_Type (Scope_Stack.Table (J).Entity)
6185 and then not Comes_From_Source (S)
6187 -- S is an enclosing task or protected object. The concurrent
6188 -- declaration has been converted into a type declaration, and
6189 -- the object itself has an object declaration that follows
6190 -- the type in the same declarative part.
6192 Tsk := Next_Entity (S);
6193 while Etype (Tsk) /= S loop
6200 elsif S = Scope_Stack.Table (J).Entity then
6202 -- Call to current task. Will be transformed into call to Self
6210 Make_Selected_Component (Loc,
6211 Prefix => New_Occurrence_Of (S, Loc),
6213 New_Occurrence_Of (Entity (E_Name), Loc));
6214 Rewrite (E_Name, New_N);
6217 elsif Nkind (Entry_Name) = N_Selected_Component
6218 and then Is_Overloaded (Prefix (Entry_Name))
6220 -- Use the entry name (which must be unique at this point) to find
6221 -- the prefix that returns the corresponding task type or protected
6225 Pref : constant Node_Id := Prefix (Entry_Name);
6226 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
6231 Get_First_Interp (Pref, I, It);
6232 while Present (It.Typ) loop
6233 if Scope (Ent) = It.Typ then
6234 Set_Etype (Pref, It.Typ);
6238 Get_Next_Interp (I, It);
6243 if Nkind (Entry_Name) = N_Selected_Component then
6244 Resolve (Prefix (Entry_Name));
6246 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6247 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6248 Resolve (Prefix (Prefix (Entry_Name)));
6249 Index := First (Expressions (Entry_Name));
6250 Resolve (Index, Entry_Index_Type (Nam));
6252 -- Up to this point the expression could have been the actual in a
6253 -- simple entry call, and be given by a named association.
6255 if Nkind (Index) = N_Parameter_Association then
6256 Error_Msg_N ("expect expression for entry index", Index);
6258 Apply_Range_Check (Index, Actual_Index_Type (Nam));
6263 ------------------------
6264 -- Resolve_Entry_Call --
6265 ------------------------
6267 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
6268 Entry_Name : constant Node_Id := Name (N);
6269 Loc : constant Source_Ptr := Sloc (Entry_Name);
6271 First_Named : Node_Id;
6278 -- We kill all checks here, because it does not seem worth the effort to
6279 -- do anything better, an entry call is a big operation.
6283 -- Processing of the name is similar for entry calls and protected
6284 -- operation calls. Once the entity is determined, we can complete
6285 -- the resolution of the actuals.
6287 -- The selector may be overloaded, in the case of a protected object
6288 -- with overloaded functions. The type of the context is used for
6291 if Nkind (Entry_Name) = N_Selected_Component
6292 and then Is_Overloaded (Selector_Name (Entry_Name))
6293 and then Typ /= Standard_Void_Type
6300 Get_First_Interp (Selector_Name (Entry_Name), I, It);
6301 while Present (It.Typ) loop
6302 if Covers (Typ, It.Typ) then
6303 Set_Entity (Selector_Name (Entry_Name), It.Nam);
6304 Set_Etype (Entry_Name, It.Typ);
6306 Generate_Reference (It.Typ, N, ' ');
6309 Get_Next_Interp (I, It);
6314 Resolve_Entry (Entry_Name);
6316 if Nkind (Entry_Name) = N_Selected_Component then
6318 -- Simple entry call
6320 Nam := Entity (Selector_Name (Entry_Name));
6321 Obj := Prefix (Entry_Name);
6322 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
6324 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6326 -- Call to member of entry family
6328 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6329 Obj := Prefix (Prefix (Entry_Name));
6330 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
6333 -- We cannot in general check the maximum depth of protected entry
6334 -- calls at compile time. But we can tell that any protected entry
6335 -- call at all violates a specified nesting depth of zero.
6337 if Is_Protected_Type (Scope (Nam)) then
6338 Check_Restriction (Max_Entry_Queue_Length, N);
6341 -- Use context type to disambiguate a protected function that can be
6342 -- called without actuals and that returns an array type, and where
6343 -- the argument list may be an indexing of the returned value.
6345 if Ekind (Nam) = E_Function
6346 and then Needs_No_Actuals (Nam)
6347 and then Present (Parameter_Associations (N))
6349 ((Is_Array_Type (Etype (Nam))
6350 and then Covers (Typ, Component_Type (Etype (Nam))))
6352 or else (Is_Access_Type (Etype (Nam))
6353 and then Is_Array_Type (Designated_Type (Etype (Nam)))
6354 and then Covers (Typ,
6355 Component_Type (Designated_Type (Etype (Nam))))))
6358 Index_Node : Node_Id;
6362 Make_Indexed_Component (Loc,
6364 Make_Function_Call (Loc,
6365 Name => Relocate_Node (Entry_Name)),
6366 Expressions => Parameter_Associations (N));
6368 -- Since we are correcting a node classification error made by
6369 -- the parser, we call Replace rather than Rewrite.
6371 Replace (N, Index_Node);
6372 Set_Etype (Prefix (N), Etype (Nam));
6374 Resolve_Indexed_Component (N, Typ);
6379 if Ekind_In (Nam, E_Entry, E_Entry_Family)
6380 and then Present (PPC_Wrapper (Nam))
6381 and then Current_Scope /= PPC_Wrapper (Nam)
6383 -- Rewrite as call to the precondition wrapper, adding the task
6384 -- object to the list of actuals. If the call is to a member of
6385 -- an entry family, include the index as well.
6389 New_Actuals : List_Id;
6391 New_Actuals := New_List (Obj);
6393 if Nkind (Entry_Name) = N_Indexed_Component then
6394 Append_To (New_Actuals,
6395 New_Copy_Tree (First (Expressions (Entry_Name))));
6398 Append_List (Parameter_Associations (N), New_Actuals);
6400 Make_Procedure_Call_Statement (Loc,
6402 New_Occurrence_Of (PPC_Wrapper (Nam), Loc),
6403 Parameter_Associations => New_Actuals);
6404 Rewrite (N, New_Call);
6405 Analyze_And_Resolve (N);
6410 -- The operation name may have been overloaded. Order the actuals
6411 -- according to the formals of the resolved entity, and set the
6412 -- return type to that of the operation.
6415 Normalize_Actuals (N, Nam, False, Norm_OK);
6416 pragma Assert (Norm_OK);
6417 Set_Etype (N, Etype (Nam));
6420 Resolve_Actuals (N, Nam);
6422 -- Create a call reference to the entry
6424 Generate_Reference (Nam, Entry_Name, 's');
6426 if Ekind_In (Nam, E_Entry, E_Entry_Family) then
6427 Check_Potentially_Blocking_Operation (N);
6430 -- Verify that a procedure call cannot masquerade as an entry
6431 -- call where an entry call is expected.
6433 if Ekind (Nam) = E_Procedure then
6434 if Nkind (Parent (N)) = N_Entry_Call_Alternative
6435 and then N = Entry_Call_Statement (Parent (N))
6437 Error_Msg_N ("entry call required in select statement", N);
6439 elsif Nkind (Parent (N)) = N_Triggering_Alternative
6440 and then N = Triggering_Statement (Parent (N))
6442 Error_Msg_N ("triggering statement cannot be procedure call", N);
6444 elsif Ekind (Scope (Nam)) = E_Task_Type
6445 and then not In_Open_Scopes (Scope (Nam))
6447 Error_Msg_N ("task has no entry with this name", Entry_Name);
6451 -- After resolution, entry calls and protected procedure calls are
6452 -- changed into entry calls, for expansion. The structure of the node
6453 -- does not change, so it can safely be done in place. Protected
6454 -- function calls must keep their structure because they are
6457 if Ekind (Nam) /= E_Function then
6459 -- A protected operation that is not a function may modify the
6460 -- corresponding object, and cannot apply to a constant. If this
6461 -- is an internal call, the prefix is the type itself.
6463 if Is_Protected_Type (Scope (Nam))
6464 and then not Is_Variable (Obj)
6465 and then (not Is_Entity_Name (Obj)
6466 or else not Is_Type (Entity (Obj)))
6469 ("prefix of protected procedure or entry call must be variable",
6473 Actuals := Parameter_Associations (N);
6474 First_Named := First_Named_Actual (N);
6477 Make_Entry_Call_Statement (Loc,
6479 Parameter_Associations => Actuals));
6481 Set_First_Named_Actual (N, First_Named);
6482 Set_Analyzed (N, True);
6484 -- Protected functions can return on the secondary stack, in which
6485 -- case we must trigger the transient scope mechanism.
6487 elsif Expander_Active
6488 and then Requires_Transient_Scope (Etype (Nam))
6490 Establish_Transient_Scope (N, Sec_Stack => True);
6492 end Resolve_Entry_Call;
6494 -------------------------
6495 -- Resolve_Equality_Op --
6496 -------------------------
6498 -- Both arguments must have the same type, and the boolean context does
6499 -- not participate in the resolution. The first pass verifies that the
6500 -- interpretation is not ambiguous, and the type of the left argument is
6501 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6502 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6503 -- though they carry a single (universal) type. Diagnose this case here.
6505 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6506 L : constant Node_Id := Left_Opnd (N);
6507 R : constant Node_Id := Right_Opnd (N);
6508 T : Entity_Id := Find_Unique_Type (L, R);
6510 procedure Check_Conditional_Expression (Cond : Node_Id);
6511 -- The resolution rule for conditional expressions requires that each
6512 -- such must have a unique type. This means that if several dependent
6513 -- expressions are of a non-null anonymous access type, and the context
6514 -- does not impose an expected type (as can be the case in an equality
6515 -- operation) the expression must be rejected.
6517 function Find_Unique_Access_Type return Entity_Id;
6518 -- In the case of allocators, make a last-ditch attempt to find a single
6519 -- access type with the right designated type. This is semantically
6520 -- dubious, and of no interest to any real code, but c48008a makes it
6523 ----------------------------------
6524 -- Check_Conditional_Expression --
6525 ----------------------------------
6527 procedure Check_Conditional_Expression (Cond : Node_Id) is
6528 Then_Expr : Node_Id;
6529 Else_Expr : Node_Id;
6532 if Nkind (Cond) = N_Conditional_Expression then
6533 Then_Expr := Next (First (Expressions (Cond)));
6534 Else_Expr := Next (Then_Expr);
6536 if Nkind (Then_Expr) /= N_Null
6537 and then Nkind (Else_Expr) /= N_Null
6540 ("cannot determine type of conditional expression", Cond);
6543 end Check_Conditional_Expression;
6545 -----------------------------
6546 -- Find_Unique_Access_Type --
6547 -----------------------------
6549 function Find_Unique_Access_Type return Entity_Id is
6555 if Ekind (Etype (R)) = E_Allocator_Type then
6556 Acc := Designated_Type (Etype (R));
6557 elsif Ekind (Etype (L)) = E_Allocator_Type then
6558 Acc := Designated_Type (Etype (L));
6564 while S /= Standard_Standard loop
6565 E := First_Entity (S);
6566 while Present (E) loop
6568 and then Is_Access_Type (E)
6569 and then Ekind (E) /= E_Allocator_Type
6570 and then Designated_Type (E) = Base_Type (Acc)
6582 end Find_Unique_Access_Type;
6584 -- Start of processing for Resolve_Equality_Op
6587 Set_Etype (N, Base_Type (Typ));
6588 Generate_Reference (T, N, ' ');
6590 if T = Any_Fixed then
6591 T := Unique_Fixed_Point_Type (L);
6594 if T /= Any_Type then
6596 or else T = Any_Composite
6597 or else T = Any_Character
6599 if T = Any_Character then
6600 Ambiguous_Character (L);
6602 Error_Msg_N ("ambiguous operands for equality", N);
6605 Set_Etype (N, Any_Type);
6608 elsif T = Any_Access
6609 or else Ekind_In (T, E_Allocator_Type, E_Access_Attribute_Type)
6611 T := Find_Unique_Access_Type;
6614 Error_Msg_N ("ambiguous operands for equality", N);
6615 Set_Etype (N, Any_Type);
6619 -- Conditional expressions must have a single type, and if the
6620 -- context does not impose one the dependent expressions cannot
6621 -- be anonymous access types.
6623 elsif Ada_Version >= Ada_2012
6624 and then Ekind_In (Etype (L), E_Anonymous_Access_Type,
6625 E_Anonymous_Access_Subprogram_Type)
6626 and then Ekind_In (Etype (R), E_Anonymous_Access_Type,
6627 E_Anonymous_Access_Subprogram_Type)
6629 Check_Conditional_Expression (L);
6630 Check_Conditional_Expression (R);
6636 -- If the unique type is a class-wide type then it will be expanded
6637 -- into a dispatching call to the predefined primitive. Therefore we
6638 -- check here for potential violation of such restriction.
6640 if Is_Class_Wide_Type (T) then
6641 Check_Restriction (No_Dispatching_Calls, N);
6644 if Warn_On_Redundant_Constructs
6645 and then Comes_From_Source (N)
6646 and then Is_Entity_Name (R)
6647 and then Entity (R) = Standard_True
6648 and then Comes_From_Source (R)
6650 Error_Msg_N -- CODEFIX
6651 ("?comparison with True is redundant!", R);
6654 Check_Unset_Reference (L);
6655 Check_Unset_Reference (R);
6656 Generate_Operator_Reference (N, T);
6657 Check_Low_Bound_Tested (N);
6659 -- If this is an inequality, it may be the implicit inequality
6660 -- created for a user-defined operation, in which case the corres-
6661 -- ponding equality operation is not intrinsic, and the operation
6662 -- cannot be constant-folded. Else fold.
6664 if Nkind (N) = N_Op_Eq
6665 or else Comes_From_Source (Entity (N))
6666 or else Ekind (Entity (N)) = E_Operator
6667 or else Is_Intrinsic_Subprogram
6668 (Corresponding_Equality (Entity (N)))
6670 Eval_Relational_Op (N);
6672 elsif Nkind (N) = N_Op_Ne
6673 and then Is_Abstract_Subprogram (Entity (N))
6675 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6678 -- Ada 2005: If one operand is an anonymous access type, convert the
6679 -- other operand to it, to ensure that the underlying types match in
6680 -- the back-end. Same for access_to_subprogram, and the conversion
6681 -- verifies that the types are subtype conformant.
6683 -- We apply the same conversion in the case one of the operands is a
6684 -- private subtype of the type of the other.
6686 -- Why the Expander_Active test here ???
6690 (Ekind_In (T, E_Anonymous_Access_Type,
6691 E_Anonymous_Access_Subprogram_Type)
6692 or else Is_Private_Type (T))
6694 if Etype (L) /= T then
6696 Make_Unchecked_Type_Conversion (Sloc (L),
6697 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6698 Expression => Relocate_Node (L)));
6699 Analyze_And_Resolve (L, T);
6702 if (Etype (R)) /= T then
6704 Make_Unchecked_Type_Conversion (Sloc (R),
6705 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6706 Expression => Relocate_Node (R)));
6707 Analyze_And_Resolve (R, T);
6711 end Resolve_Equality_Op;
6713 ----------------------------------
6714 -- Resolve_Explicit_Dereference --
6715 ----------------------------------
6717 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6718 Loc : constant Source_Ptr := Sloc (N);
6720 P : constant Node_Id := Prefix (N);
6725 Check_Fully_Declared_Prefix (Typ, P);
6727 if Is_Overloaded (P) then
6729 -- Use the context type to select the prefix that has the correct
6732 Get_First_Interp (P, I, It);
6733 while Present (It.Typ) loop
6734 exit when Is_Access_Type (It.Typ)
6735 and then Covers (Typ, Designated_Type (It.Typ));
6736 Get_Next_Interp (I, It);
6739 if Present (It.Typ) then
6740 Resolve (P, It.Typ);
6742 -- If no interpretation covers the designated type of the prefix,
6743 -- this is the pathological case where not all implementations of
6744 -- the prefix allow the interpretation of the node as a call. Now
6745 -- that the expected type is known, Remove other interpretations
6746 -- from prefix, rewrite it as a call, and resolve again, so that
6747 -- the proper call node is generated.
6749 Get_First_Interp (P, I, It);
6750 while Present (It.Typ) loop
6751 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6755 Get_Next_Interp (I, It);
6759 Make_Function_Call (Loc,
6761 Make_Explicit_Dereference (Loc,
6763 Parameter_Associations => New_List);
6765 Save_Interps (N, New_N);
6767 Analyze_And_Resolve (N, Typ);
6771 Set_Etype (N, Designated_Type (It.Typ));
6777 if Is_Access_Type (Etype (P)) then
6778 Apply_Access_Check (N);
6781 -- If the designated type is a packed unconstrained array type, and the
6782 -- explicit dereference is not in the context of an attribute reference,
6783 -- then we must compute and set the actual subtype, since it is needed
6784 -- by Gigi. The reason we exclude the attribute case is that this is
6785 -- handled fine by Gigi, and in fact we use such attributes to build the
6786 -- actual subtype. We also exclude generated code (which builds actual
6787 -- subtypes directly if they are needed).
6789 if Is_Array_Type (Etype (N))
6790 and then Is_Packed (Etype (N))
6791 and then not Is_Constrained (Etype (N))
6792 and then Nkind (Parent (N)) /= N_Attribute_Reference
6793 and then Comes_From_Source (N)
6795 Set_Etype (N, Get_Actual_Subtype (N));
6798 -- Note: No Eval processing is required for an explicit dereference,
6799 -- because such a name can never be static.
6801 end Resolve_Explicit_Dereference;
6803 -------------------------------------
6804 -- Resolve_Expression_With_Actions --
6805 -------------------------------------
6807 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id) is
6810 end Resolve_Expression_With_Actions;
6812 -------------------------------
6813 -- Resolve_Indexed_Component --
6814 -------------------------------
6816 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
6817 Name : constant Node_Id := Prefix (N);
6819 Array_Type : Entity_Id := Empty; -- to prevent junk warning
6823 if Is_Overloaded (Name) then
6825 -- Use the context type to select the prefix that yields the correct
6831 I1 : Interp_Index := 0;
6832 P : constant Node_Id := Prefix (N);
6833 Found : Boolean := False;
6836 Get_First_Interp (P, I, It);
6837 while Present (It.Typ) loop
6838 if (Is_Array_Type (It.Typ)
6839 and then Covers (Typ, Component_Type (It.Typ)))
6840 or else (Is_Access_Type (It.Typ)
6841 and then Is_Array_Type (Designated_Type (It.Typ))
6843 (Typ, Component_Type (Designated_Type (It.Typ))))
6846 It := Disambiguate (P, I1, I, Any_Type);
6848 if It = No_Interp then
6849 Error_Msg_N ("ambiguous prefix for indexing", N);
6855 Array_Type := It.Typ;
6861 Array_Type := It.Typ;
6866 Get_Next_Interp (I, It);
6871 Array_Type := Etype (Name);
6874 Resolve (Name, Array_Type);
6875 Array_Type := Get_Actual_Subtype_If_Available (Name);
6877 -- If prefix is access type, dereference to get real array type.
6878 -- Note: we do not apply an access check because the expander always
6879 -- introduces an explicit dereference, and the check will happen there.
6881 if Is_Access_Type (Array_Type) then
6882 Array_Type := Designated_Type (Array_Type);
6885 -- If name was overloaded, set component type correctly now
6886 -- If a misplaced call to an entry family (which has no index types)
6887 -- return. Error will be diagnosed from calling context.
6889 if Is_Array_Type (Array_Type) then
6890 Set_Etype (N, Component_Type (Array_Type));
6895 Index := First_Index (Array_Type);
6896 Expr := First (Expressions (N));
6898 -- The prefix may have resolved to a string literal, in which case its
6899 -- etype has a special representation. This is only possible currently
6900 -- if the prefix is a static concatenation, written in functional
6903 if Ekind (Array_Type) = E_String_Literal_Subtype then
6904 Resolve (Expr, Standard_Positive);
6907 while Present (Index) and Present (Expr) loop
6908 Resolve (Expr, Etype (Index));
6909 Check_Unset_Reference (Expr);
6911 if Is_Scalar_Type (Etype (Expr)) then
6912 Apply_Scalar_Range_Check (Expr, Etype (Index));
6914 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
6922 -- Do not generate the warning on suspicious index if we are analyzing
6923 -- package Ada.Tags; otherwise we will report the warning with the
6924 -- Prims_Ptr field of the dispatch table.
6926 if Scope (Etype (Prefix (N))) = Standard_Standard
6928 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
6931 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
6932 Eval_Indexed_Component (N);
6935 -- If the array type is atomic, and is packed, and we are in a left side
6936 -- context, then this is worth a warning, since we have a situation
6937 -- where the access to the component may cause extra read/writes of
6938 -- the atomic array object, which could be considered unexpected.
6940 if Nkind (N) = N_Indexed_Component
6941 and then (Is_Atomic (Array_Type)
6942 or else (Is_Entity_Name (Prefix (N))
6943 and then Is_Atomic (Entity (Prefix (N)))))
6944 and then Is_Bit_Packed_Array (Array_Type)
6947 Error_Msg_N ("?assignment to component of packed atomic array",
6949 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
6952 end Resolve_Indexed_Component;
6954 -----------------------------
6955 -- Resolve_Integer_Literal --
6956 -----------------------------
6958 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
6961 Eval_Integer_Literal (N);
6962 end Resolve_Integer_Literal;
6964 --------------------------------
6965 -- Resolve_Intrinsic_Operator --
6966 --------------------------------
6968 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
6969 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6971 Orig_Op : constant Entity_Id := Entity (N);
6976 -- We must preserve the original entity in a generic setting, so that
6977 -- the legality of the operation can be verified in an instance.
6979 if not Expander_Active then
6984 while Scope (Op) /= Standard_Standard loop
6986 pragma Assert (Present (Op));
6990 Set_Is_Overloaded (N, False);
6992 -- If the operand type is private, rewrite with suitable conversions on
6993 -- the operands and the result, to expose the proper underlying numeric
6996 if Is_Private_Type (Typ) then
6997 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
6999 if Nkind (N) = N_Op_Expon then
7000 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
7002 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7005 if Nkind (Arg1) = N_Type_Conversion then
7006 Save_Interps (Left_Opnd (N), Expression (Arg1));
7009 if Nkind (Arg2) = N_Type_Conversion then
7010 Save_Interps (Right_Opnd (N), Expression (Arg2));
7013 Set_Left_Opnd (N, Arg1);
7014 Set_Right_Opnd (N, Arg2);
7016 Set_Etype (N, Btyp);
7017 Rewrite (N, Unchecked_Convert_To (Typ, N));
7020 elsif Typ /= Etype (Left_Opnd (N))
7021 or else Typ /= Etype (Right_Opnd (N))
7023 -- Add explicit conversion where needed, and save interpretations in
7024 -- case operands are overloaded. If the context is a VMS operation,
7025 -- assert that the conversion is legal (the operands have the proper
7026 -- types to select the VMS intrinsic). Note that in rare cases the
7027 -- VMS operators may be visible, but the default System is being used
7028 -- and Address is a private type.
7030 Arg1 := Convert_To (Typ, Left_Opnd (N));
7031 Arg2 := Convert_To (Typ, Right_Opnd (N));
7033 if Nkind (Arg1) = N_Type_Conversion then
7034 Save_Interps (Left_Opnd (N), Expression (Arg1));
7036 if Is_VMS_Operator (Orig_Op) then
7037 Set_Conversion_OK (Arg1);
7040 Save_Interps (Left_Opnd (N), Arg1);
7043 if Nkind (Arg2) = N_Type_Conversion then
7044 Save_Interps (Right_Opnd (N), Expression (Arg2));
7046 if Is_VMS_Operator (Orig_Op) then
7047 Set_Conversion_OK (Arg2);
7050 Save_Interps (Right_Opnd (N), Arg2);
7053 Rewrite (Left_Opnd (N), Arg1);
7054 Rewrite (Right_Opnd (N), Arg2);
7057 Resolve_Arithmetic_Op (N, Typ);
7060 Resolve_Arithmetic_Op (N, Typ);
7062 end Resolve_Intrinsic_Operator;
7064 --------------------------------------
7065 -- Resolve_Intrinsic_Unary_Operator --
7066 --------------------------------------
7068 procedure Resolve_Intrinsic_Unary_Operator
7072 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
7078 while Scope (Op) /= Standard_Standard loop
7080 pragma Assert (Present (Op));
7085 if Is_Private_Type (Typ) then
7086 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7087 Save_Interps (Right_Opnd (N), Expression (Arg2));
7089 Set_Right_Opnd (N, Arg2);
7091 Set_Etype (N, Btyp);
7092 Rewrite (N, Unchecked_Convert_To (Typ, N));
7096 Resolve_Unary_Op (N, Typ);
7098 end Resolve_Intrinsic_Unary_Operator;
7100 ------------------------
7101 -- Resolve_Logical_Op --
7102 ------------------------
7104 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
7108 Check_No_Direct_Boolean_Operators (N);
7110 -- Predefined operations on scalar types yield the base type. On the
7111 -- other hand, logical operations on arrays yield the type of the
7112 -- arguments (and the context).
7114 if Is_Array_Type (Typ) then
7117 B_Typ := Base_Type (Typ);
7120 -- OK if this is a VMS-specific intrinsic operation
7122 if Is_VMS_Operator (Entity (N)) then
7125 -- The following test is required because the operands of the operation
7126 -- may be literals, in which case the resulting type appears to be
7127 -- compatible with a signed integer type, when in fact it is compatible
7128 -- only with modular types. If the context itself is universal, the
7129 -- operation is illegal.
7131 elsif not Valid_Boolean_Arg (Typ) then
7132 Error_Msg_N ("invalid context for logical operation", N);
7133 Set_Etype (N, Any_Type);
7136 elsif Typ = Any_Modular then
7138 ("no modular type available in this context", N);
7139 Set_Etype (N, Any_Type);
7141 elsif Is_Modular_Integer_Type (Typ)
7142 and then Etype (Left_Opnd (N)) = Universal_Integer
7143 and then Etype (Right_Opnd (N)) = Universal_Integer
7145 Check_For_Visible_Operator (N, B_Typ);
7148 Resolve (Left_Opnd (N), B_Typ);
7149 Resolve (Right_Opnd (N), B_Typ);
7151 Check_Unset_Reference (Left_Opnd (N));
7152 Check_Unset_Reference (Right_Opnd (N));
7154 Set_Etype (N, B_Typ);
7155 Generate_Operator_Reference (N, B_Typ);
7156 Eval_Logical_Op (N);
7157 end Resolve_Logical_Op;
7159 ---------------------------
7160 -- Resolve_Membership_Op --
7161 ---------------------------
7163 -- The context can only be a boolean type, and does not determine
7164 -- the arguments. Arguments should be unambiguous, but the preference
7165 -- rule for universal types applies.
7167 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
7168 pragma Warnings (Off, Typ);
7170 L : constant Node_Id := Left_Opnd (N);
7171 R : constant Node_Id := Right_Opnd (N);
7174 procedure Resolve_Set_Membership;
7175 -- Analysis has determined a unique type for the left operand.
7176 -- Use it to resolve the disjuncts.
7178 ----------------------------
7179 -- Resolve_Set_Membership --
7180 ----------------------------
7182 procedure Resolve_Set_Membership is
7186 Resolve (L, Etype (L));
7188 Alt := First (Alternatives (N));
7189 while Present (Alt) loop
7191 -- Alternative is an expression, a range
7192 -- or a subtype mark.
7194 if not Is_Entity_Name (Alt)
7195 or else not Is_Type (Entity (Alt))
7197 Resolve (Alt, Etype (L));
7202 end Resolve_Set_Membership;
7204 -- Start of processing for Resolve_Membership_Op
7207 if L = Error or else R = Error then
7211 if Present (Alternatives (N)) then
7212 Resolve_Set_Membership;
7215 elsif not Is_Overloaded (R)
7217 (Etype (R) = Universal_Integer or else
7218 Etype (R) = Universal_Real)
7219 and then Is_Overloaded (L)
7223 -- Ada 2005 (AI-251): Support the following case:
7225 -- type I is interface;
7226 -- type T is tagged ...
7228 -- function Test (O : I'Class) is
7230 -- return O in T'Class.
7233 -- In this case we have nothing else to do. The membership test will be
7234 -- done at run time.
7236 elsif Ada_Version >= Ada_2005
7237 and then Is_Class_Wide_Type (Etype (L))
7238 and then Is_Interface (Etype (L))
7239 and then Is_Class_Wide_Type (Etype (R))
7240 and then not Is_Interface (Etype (R))
7245 T := Intersect_Types (L, R);
7248 -- If mixed-mode operations are present and operands are all literal,
7249 -- the only interpretation involves Duration, which is probably not
7250 -- the intention of the programmer.
7252 if T = Any_Fixed then
7253 T := Unique_Fixed_Point_Type (N);
7255 if T = Any_Type then
7261 Check_Unset_Reference (L);
7263 if Nkind (R) = N_Range
7264 and then not Is_Scalar_Type (T)
7266 Error_Msg_N ("scalar type required for range", R);
7269 if Is_Entity_Name (R) then
7270 Freeze_Expression (R);
7273 Check_Unset_Reference (R);
7276 Eval_Membership_Op (N);
7277 end Resolve_Membership_Op;
7283 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
7284 Loc : constant Source_Ptr := Sloc (N);
7287 -- Handle restriction against anonymous null access values This
7288 -- restriction can be turned off using -gnatdj.
7290 -- Ada 2005 (AI-231): Remove restriction
7292 if Ada_Version < Ada_2005
7293 and then not Debug_Flag_J
7294 and then Ekind (Typ) = E_Anonymous_Access_Type
7295 and then Comes_From_Source (N)
7297 -- In the common case of a call which uses an explicitly null value
7298 -- for an access parameter, give specialized error message.
7300 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
7304 ("null is not allowed as argument for an access parameter", N);
7306 -- Standard message for all other cases (are there any?)
7310 ("null cannot be of an anonymous access type", N);
7314 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
7315 -- assignment to a null-excluding object
7317 if Ada_Version >= Ada_2005
7318 and then Can_Never_Be_Null (Typ)
7319 and then Nkind (Parent (N)) = N_Assignment_Statement
7321 if not Inside_Init_Proc then
7323 (Compile_Time_Constraint_Error (N,
7324 "(Ada 2005) null not allowed in null-excluding objects?"),
7325 Make_Raise_Constraint_Error (Loc,
7326 Reason => CE_Access_Check_Failed));
7329 Make_Raise_Constraint_Error (Loc,
7330 Reason => CE_Access_Check_Failed));
7334 -- In a distributed context, null for a remote access to subprogram may
7335 -- need to be replaced with a special record aggregate. In this case,
7336 -- return after having done the transformation.
7338 if (Ekind (Typ) = E_Record_Type
7339 or else Is_Remote_Access_To_Subprogram_Type (Typ))
7340 and then Remote_AST_Null_Value (N, Typ)
7345 -- The null literal takes its type from the context
7350 -----------------------
7351 -- Resolve_Op_Concat --
7352 -----------------------
7354 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
7356 -- We wish to avoid deep recursion, because concatenations are often
7357 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
7358 -- operands nonrecursively until we find something that is not a simple
7359 -- concatenation (A in this case). We resolve that, and then walk back
7360 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
7361 -- to do the rest of the work at each level. The Parent pointers allow
7362 -- us to avoid recursion, and thus avoid running out of memory. See also
7363 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
7369 -- The following code is equivalent to:
7371 -- Resolve_Op_Concat_First (NN, Typ);
7372 -- Resolve_Op_Concat_Arg (N, ...);
7373 -- Resolve_Op_Concat_Rest (N, Typ);
7375 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
7376 -- operand is a concatenation.
7378 -- Walk down left operands
7381 Resolve_Op_Concat_First (NN, Typ);
7382 Op1 := Left_Opnd (NN);
7383 exit when not (Nkind (Op1) = N_Op_Concat
7384 and then not Is_Array_Type (Component_Type (Typ))
7385 and then Entity (Op1) = Entity (NN));
7389 -- Now (given the above example) NN is A&B and Op1 is A
7391 -- First resolve Op1 ...
7393 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
7395 -- ... then walk NN back up until we reach N (where we started), calling
7396 -- Resolve_Op_Concat_Rest along the way.
7399 Resolve_Op_Concat_Rest (NN, Typ);
7403 end Resolve_Op_Concat;
7405 ---------------------------
7406 -- Resolve_Op_Concat_Arg --
7407 ---------------------------
7409 procedure Resolve_Op_Concat_Arg
7415 Btyp : constant Entity_Id := Base_Type (Typ);
7420 or else (not Is_Overloaded (Arg)
7421 and then Etype (Arg) /= Any_Composite
7422 and then Covers (Component_Type (Typ), Etype (Arg)))
7424 Resolve (Arg, Component_Type (Typ));
7426 Resolve (Arg, Btyp);
7429 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
7430 if Nkind (Arg) = N_Aggregate
7431 and then Is_Composite_Type (Component_Type (Typ))
7433 if Is_Private_Type (Component_Type (Typ)) then
7434 Resolve (Arg, Btyp);
7436 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
7437 Set_Etype (Arg, Any_Type);
7441 if Is_Overloaded (Arg)
7442 and then Has_Compatible_Type (Arg, Typ)
7443 and then Etype (Arg) /= Any_Type
7451 Get_First_Interp (Arg, I, It);
7453 Get_Next_Interp (I, It);
7455 -- Special-case the error message when the overloading is
7456 -- caused by a function that yields an array and can be
7457 -- called without parameters.
7459 if It.Nam = Func then
7460 Error_Msg_Sloc := Sloc (Func);
7461 Error_Msg_N ("ambiguous call to function#", Arg);
7463 ("\\interpretation as call yields&", Arg, Typ);
7465 ("\\interpretation as indexing of call yields&",
7466 Arg, Component_Type (Typ));
7470 ("ambiguous operand for concatenation!", Arg);
7471 Get_First_Interp (Arg, I, It);
7472 while Present (It.Nam) loop
7473 Error_Msg_Sloc := Sloc (It.Nam);
7475 if Base_Type (It.Typ) = Base_Type (Typ)
7476 or else Base_Type (It.Typ) =
7477 Base_Type (Component_Type (Typ))
7479 Error_Msg_N -- CODEFIX
7480 ("\\possible interpretation#", Arg);
7483 Get_Next_Interp (I, It);
7489 Resolve (Arg, Component_Type (Typ));
7491 if Nkind (Arg) = N_String_Literal then
7492 Set_Etype (Arg, Component_Type (Typ));
7495 if Arg = Left_Opnd (N) then
7496 Set_Is_Component_Left_Opnd (N);
7498 Set_Is_Component_Right_Opnd (N);
7503 Resolve (Arg, Btyp);
7506 Check_Unset_Reference (Arg);
7507 end Resolve_Op_Concat_Arg;
7509 -----------------------------
7510 -- Resolve_Op_Concat_First --
7511 -----------------------------
7513 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
7514 Btyp : constant Entity_Id := Base_Type (Typ);
7515 Op1 : constant Node_Id := Left_Opnd (N);
7516 Op2 : constant Node_Id := Right_Opnd (N);
7519 -- The parser folds an enormous sequence of concatenations of string
7520 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
7521 -- in the right operand. If the expression resolves to a predefined "&"
7522 -- operator, all is well. Otherwise, the parser's folding is wrong, so
7523 -- we give an error. See P_Simple_Expression in Par.Ch4.
7525 if Nkind (Op2) = N_String_Literal
7526 and then Is_Folded_In_Parser (Op2)
7527 and then Ekind (Entity (N)) = E_Function
7529 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
7530 and then String_Length (Strval (Op1)) = 0);
7531 Error_Msg_N ("too many user-defined concatenations", N);
7535 Set_Etype (N, Btyp);
7537 if Is_Limited_Composite (Btyp) then
7538 Error_Msg_N ("concatenation not available for limited array", N);
7539 Explain_Limited_Type (Btyp, N);
7541 end Resolve_Op_Concat_First;
7543 ----------------------------
7544 -- Resolve_Op_Concat_Rest --
7545 ----------------------------
7547 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
7548 Op1 : constant Node_Id := Left_Opnd (N);
7549 Op2 : constant Node_Id := Right_Opnd (N);
7552 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
7554 Generate_Operator_Reference (N, Typ);
7556 if Is_String_Type (Typ) then
7557 Eval_Concatenation (N);
7560 -- If this is not a static concatenation, but the result is a string
7561 -- type (and not an array of strings) ensure that static string operands
7562 -- have their subtypes properly constructed.
7564 if Nkind (N) /= N_String_Literal
7565 and then Is_Character_Type (Component_Type (Typ))
7567 Set_String_Literal_Subtype (Op1, Typ);
7568 Set_String_Literal_Subtype (Op2, Typ);
7570 end Resolve_Op_Concat_Rest;
7572 ----------------------
7573 -- Resolve_Op_Expon --
7574 ----------------------
7576 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
7577 B_Typ : constant Entity_Id := Base_Type (Typ);
7580 -- Catch attempts to do fixed-point exponentiation with universal
7581 -- operands, which is a case where the illegality is not caught during
7582 -- normal operator analysis.
7584 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
7585 Error_Msg_N ("exponentiation not available for fixed point", N);
7589 if Comes_From_Source (N)
7590 and then Ekind (Entity (N)) = E_Function
7591 and then Is_Imported (Entity (N))
7592 and then Is_Intrinsic_Subprogram (Entity (N))
7594 Resolve_Intrinsic_Operator (N, Typ);
7598 if Etype (Left_Opnd (N)) = Universal_Integer
7599 or else Etype (Left_Opnd (N)) = Universal_Real
7601 Check_For_Visible_Operator (N, B_Typ);
7604 -- We do the resolution using the base type, because intermediate values
7605 -- in expressions always are of the base type, not a subtype of it.
7607 Resolve (Left_Opnd (N), B_Typ);
7608 Resolve (Right_Opnd (N), Standard_Integer);
7610 Check_Unset_Reference (Left_Opnd (N));
7611 Check_Unset_Reference (Right_Opnd (N));
7613 Set_Etype (N, B_Typ);
7614 Generate_Operator_Reference (N, B_Typ);
7617 -- Set overflow checking bit. Much cleverer code needed here eventually
7618 -- and perhaps the Resolve routines should be separated for the various
7619 -- arithmetic operations, since they will need different processing. ???
7621 if Nkind (N) in N_Op then
7622 if not Overflow_Checks_Suppressed (Etype (N)) then
7623 Enable_Overflow_Check (N);
7626 end Resolve_Op_Expon;
7628 --------------------
7629 -- Resolve_Op_Not --
7630 --------------------
7632 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
7635 function Parent_Is_Boolean return Boolean;
7636 -- This function determines if the parent node is a boolean operator
7637 -- or operation (comparison op, membership test, or short circuit form)
7638 -- and the not in question is the left operand of this operation.
7639 -- Note that if the not is in parens, then false is returned.
7641 -----------------------
7642 -- Parent_Is_Boolean --
7643 -----------------------
7645 function Parent_Is_Boolean return Boolean is
7647 if Paren_Count (N) /= 0 then
7651 case Nkind (Parent (N)) is
7666 return Left_Opnd (Parent (N)) = N;
7672 end Parent_Is_Boolean;
7674 -- Start of processing for Resolve_Op_Not
7677 -- Predefined operations on scalar types yield the base type. On the
7678 -- other hand, logical operations on arrays yield the type of the
7679 -- arguments (and the context).
7681 if Is_Array_Type (Typ) then
7684 B_Typ := Base_Type (Typ);
7687 if Is_VMS_Operator (Entity (N)) then
7690 -- Straightforward case of incorrect arguments
7692 elsif not Valid_Boolean_Arg (Typ) then
7693 Error_Msg_N ("invalid operand type for operator&", N);
7694 Set_Etype (N, Any_Type);
7697 -- Special case of probable missing parens
7699 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7700 if Parent_Is_Boolean then
7702 ("operand of not must be enclosed in parentheses",
7706 ("no modular type available in this context", N);
7709 Set_Etype (N, Any_Type);
7712 -- OK resolution of not
7715 -- Warn if non-boolean types involved. This is a case like not a < b
7716 -- where a and b are modular, where we will get (not a) < b and most
7717 -- likely not (a < b) was intended.
7719 if Warn_On_Questionable_Missing_Parens
7720 and then not Is_Boolean_Type (Typ)
7721 and then Parent_Is_Boolean
7723 Error_Msg_N ("?not expression should be parenthesized here!", N);
7726 -- Warn on double negation if checking redundant constructs
7728 if Warn_On_Redundant_Constructs
7729 and then Comes_From_Source (N)
7730 and then Comes_From_Source (Right_Opnd (N))
7731 and then Root_Type (Typ) = Standard_Boolean
7732 and then Nkind (Right_Opnd (N)) = N_Op_Not
7734 Error_Msg_N ("redundant double negation?", N);
7737 -- Complete resolution and evaluation of NOT
7739 Resolve (Right_Opnd (N), B_Typ);
7740 Check_Unset_Reference (Right_Opnd (N));
7741 Set_Etype (N, B_Typ);
7742 Generate_Operator_Reference (N, B_Typ);
7747 -----------------------------
7748 -- Resolve_Operator_Symbol --
7749 -----------------------------
7751 -- Nothing to be done, all resolved already
7753 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
7754 pragma Warnings (Off, N);
7755 pragma Warnings (Off, Typ);
7759 end Resolve_Operator_Symbol;
7761 ----------------------------------
7762 -- Resolve_Qualified_Expression --
7763 ----------------------------------
7765 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
7766 pragma Warnings (Off, Typ);
7768 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
7769 Expr : constant Node_Id := Expression (N);
7772 Resolve (Expr, Target_Typ);
7774 -- A qualified expression requires an exact match of the type,
7775 -- class-wide matching is not allowed. However, if the qualifying
7776 -- type is specific and the expression has a class-wide type, it
7777 -- may still be okay, since it can be the result of the expansion
7778 -- of a call to a dispatching function, so we also have to check
7779 -- class-wideness of the type of the expression's original node.
7781 if (Is_Class_Wide_Type (Target_Typ)
7783 (Is_Class_Wide_Type (Etype (Expr))
7784 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
7785 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
7787 Wrong_Type (Expr, Target_Typ);
7790 -- If the target type is unconstrained, then we reset the type of the
7791 -- result from the type of the expression. For other cases, the actual
7792 -- subtype of the expression is the target type.
7794 if Is_Composite_Type (Target_Typ)
7795 and then not Is_Constrained (Target_Typ)
7797 Set_Etype (N, Etype (Expr));
7800 Eval_Qualified_Expression (N);
7801 end Resolve_Qualified_Expression;
7803 -----------------------------------
7804 -- Resolve_Quantified_Expression --
7805 -----------------------------------
7807 procedure Resolve_Quantified_Expression (N : Node_Id; Typ : Entity_Id) is
7809 -- The loop structure is already resolved during its analysis, only the
7810 -- resolution of the condition needs to be done.
7812 Resolve (Condition (N), Typ);
7813 end Resolve_Quantified_Expression;
7819 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
7820 L : constant Node_Id := Low_Bound (N);
7821 H : constant Node_Id := High_Bound (N);
7823 function First_Last_Ref return Boolean;
7824 -- Returns True if N is of the form X'First .. X'Last where X is the
7825 -- same entity for both attributes.
7827 --------------------
7828 -- First_Last_Ref --
7829 --------------------
7831 function First_Last_Ref return Boolean is
7832 Lorig : constant Node_Id := Original_Node (L);
7833 Horig : constant Node_Id := Original_Node (H);
7836 if Nkind (Lorig) = N_Attribute_Reference
7837 and then Nkind (Horig) = N_Attribute_Reference
7838 and then Attribute_Name (Lorig) = Name_First
7839 and then Attribute_Name (Horig) = Name_Last
7842 PL : constant Node_Id := Prefix (Lorig);
7843 PH : constant Node_Id := Prefix (Horig);
7845 if Is_Entity_Name (PL)
7846 and then Is_Entity_Name (PH)
7847 and then Entity (PL) = Entity (PH)
7857 -- Start of processing for Resolve_Range
7864 -- Check for inappropriate range on unordered enumeration type
7866 if Bad_Unordered_Enumeration_Reference (N, Typ)
7868 -- Exclude X'First .. X'Last if X is the same entity for both
7870 and then not First_Last_Ref
7872 Error_Msg ("subrange of unordered enumeration type?", Sloc (N));
7875 Check_Unset_Reference (L);
7876 Check_Unset_Reference (H);
7878 -- We have to check the bounds for being within the base range as
7879 -- required for a non-static context. Normally this is automatic and
7880 -- done as part of evaluating expressions, but the N_Range node is an
7881 -- exception, since in GNAT we consider this node to be a subexpression,
7882 -- even though in Ada it is not. The circuit in Sem_Eval could check for
7883 -- this, but that would put the test on the main evaluation path for
7886 Check_Non_Static_Context (L);
7887 Check_Non_Static_Context (H);
7889 -- Check for an ambiguous range over character literals. This will
7890 -- happen with a membership test involving only literals.
7892 if Typ = Any_Character then
7893 Ambiguous_Character (L);
7894 Set_Etype (N, Any_Type);
7898 -- If bounds are static, constant-fold them, so size computations
7899 -- are identical between front-end and back-end. Do not perform this
7900 -- transformation while analyzing generic units, as type information
7901 -- would then be lost when reanalyzing the constant node in the
7904 if Is_Discrete_Type (Typ) and then Expander_Active then
7905 if Is_OK_Static_Expression (L) then
7906 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
7909 if Is_OK_Static_Expression (H) then
7910 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
7915 --------------------------
7916 -- Resolve_Real_Literal --
7917 --------------------------
7919 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
7920 Actual_Typ : constant Entity_Id := Etype (N);
7923 -- Special processing for fixed-point literals to make sure that the
7924 -- value is an exact multiple of small where this is required. We
7925 -- skip this for the universal real case, and also for generic types.
7927 if Is_Fixed_Point_Type (Typ)
7928 and then Typ /= Universal_Fixed
7929 and then Typ /= Any_Fixed
7930 and then not Is_Generic_Type (Typ)
7933 Val : constant Ureal := Realval (N);
7934 Cintr : constant Ureal := Val / Small_Value (Typ);
7935 Cint : constant Uint := UR_Trunc (Cintr);
7936 Den : constant Uint := Norm_Den (Cintr);
7940 -- Case of literal is not an exact multiple of the Small
7944 -- For a source program literal for a decimal fixed-point
7945 -- type, this is statically illegal (RM 4.9(36)).
7947 if Is_Decimal_Fixed_Point_Type (Typ)
7948 and then Actual_Typ = Universal_Real
7949 and then Comes_From_Source (N)
7951 Error_Msg_N ("value has extraneous low order digits", N);
7954 -- Generate a warning if literal from source
7956 if Is_Static_Expression (N)
7957 and then Warn_On_Bad_Fixed_Value
7960 ("?static fixed-point value is not a multiple of Small!",
7964 -- Replace literal by a value that is the exact representation
7965 -- of a value of the type, i.e. a multiple of the small value,
7966 -- by truncation, since Machine_Rounds is false for all GNAT
7967 -- fixed-point types (RM 4.9(38)).
7969 Stat := Is_Static_Expression (N);
7971 Make_Real_Literal (Sloc (N),
7972 Realval => Small_Value (Typ) * Cint));
7974 Set_Is_Static_Expression (N, Stat);
7977 -- In all cases, set the corresponding integer field
7979 Set_Corresponding_Integer_Value (N, Cint);
7983 -- Now replace the actual type by the expected type as usual
7986 Eval_Real_Literal (N);
7987 end Resolve_Real_Literal;
7989 -----------------------
7990 -- Resolve_Reference --
7991 -----------------------
7993 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
7994 P : constant Node_Id := Prefix (N);
7997 -- Replace general access with specific type
7999 if Ekind (Etype (N)) = E_Allocator_Type then
8000 Set_Etype (N, Base_Type (Typ));
8003 Resolve (P, Designated_Type (Etype (N)));
8005 -- If we are taking the reference of a volatile entity, then treat
8006 -- it as a potential modification of this entity. This is much too
8007 -- conservative, but is necessary because remove side effects can
8008 -- result in transformations of normal assignments into reference
8009 -- sequences that otherwise fail to notice the modification.
8011 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
8012 Note_Possible_Modification (P, Sure => False);
8014 end Resolve_Reference;
8016 --------------------------------
8017 -- Resolve_Selected_Component --
8018 --------------------------------
8020 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
8022 Comp1 : Entity_Id := Empty; -- prevent junk warning
8023 P : constant Node_Id := Prefix (N);
8024 S : constant Node_Id := Selector_Name (N);
8025 T : Entity_Id := Etype (P);
8027 I1 : Interp_Index := 0; -- prevent junk warning
8032 function Init_Component return Boolean;
8033 -- Check whether this is the initialization of a component within an
8034 -- init proc (by assignment or call to another init proc). If true,
8035 -- there is no need for a discriminant check.
8037 --------------------
8038 -- Init_Component --
8039 --------------------
8041 function Init_Component return Boolean is
8043 return Inside_Init_Proc
8044 and then Nkind (Prefix (N)) = N_Identifier
8045 and then Chars (Prefix (N)) = Name_uInit
8046 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
8049 -- Start of processing for Resolve_Selected_Component
8052 if Is_Overloaded (P) then
8054 -- Use the context type to select the prefix that has a selector
8055 -- of the correct name and type.
8058 Get_First_Interp (P, I, It);
8060 Search : while Present (It.Typ) loop
8061 if Is_Access_Type (It.Typ) then
8062 T := Designated_Type (It.Typ);
8067 if Is_Record_Type (T) then
8069 -- The visible components of a class-wide type are those of
8072 if Is_Class_Wide_Type (T) then
8076 Comp := First_Entity (T);
8077 while Present (Comp) loop
8078 if Chars (Comp) = Chars (S)
8079 and then Covers (Etype (Comp), Typ)
8088 It := Disambiguate (P, I1, I, Any_Type);
8090 if It = No_Interp then
8092 ("ambiguous prefix for selected component", N);
8099 -- There may be an implicit dereference. Retrieve
8100 -- designated record type.
8102 if Is_Access_Type (It1.Typ) then
8103 T := Designated_Type (It1.Typ);
8108 if Scope (Comp1) /= T then
8110 -- Resolution chooses the new interpretation.
8111 -- Find the component with the right name.
8113 Comp1 := First_Entity (T);
8114 while Present (Comp1)
8115 and then Chars (Comp1) /= Chars (S)
8117 Comp1 := Next_Entity (Comp1);
8126 Comp := Next_Entity (Comp);
8130 Get_Next_Interp (I, It);
8133 Resolve (P, It1.Typ);
8135 Set_Entity_With_Style_Check (S, Comp1);
8138 -- Resolve prefix with its type
8143 -- Generate cross-reference. We needed to wait until full overloading
8144 -- resolution was complete to do this, since otherwise we can't tell if
8145 -- we are an lvalue or not.
8147 if May_Be_Lvalue (N) then
8148 Generate_Reference (Entity (S), S, 'm');
8150 Generate_Reference (Entity (S), S, 'r');
8153 -- If prefix is an access type, the node will be transformed into an
8154 -- explicit dereference during expansion. The type of the node is the
8155 -- designated type of that of the prefix.
8157 if Is_Access_Type (Etype (P)) then
8158 T := Designated_Type (Etype (P));
8159 Check_Fully_Declared_Prefix (T, P);
8164 if Has_Discriminants (T)
8165 and then Ekind_In (Entity (S), E_Component, E_Discriminant)
8166 and then Present (Original_Record_Component (Entity (S)))
8167 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
8168 and then Present (Discriminant_Checking_Func
8169 (Original_Record_Component (Entity (S))))
8170 and then not Discriminant_Checks_Suppressed (T)
8171 and then not Init_Component
8173 Set_Do_Discriminant_Check (N);
8176 if Ekind (Entity (S)) = E_Void then
8177 Error_Msg_N ("premature use of component", S);
8180 -- If the prefix is a record conversion, this may be a renamed
8181 -- discriminant whose bounds differ from those of the original
8182 -- one, so we must ensure that a range check is performed.
8184 if Nkind (P) = N_Type_Conversion
8185 and then Ekind (Entity (S)) = E_Discriminant
8186 and then Is_Discrete_Type (Typ)
8188 Set_Etype (N, Base_Type (Typ));
8191 -- Note: No Eval processing is required, because the prefix is of a
8192 -- record type, or protected type, and neither can possibly be static.
8194 -- If the array type is atomic, and is packed, and we are in a left side
8195 -- context, then this is worth a warning, since we have a situation
8196 -- where the access to the component may cause extra read/writes of
8197 -- the atomic array object, which could be considered unexpected.
8199 if Nkind (N) = N_Selected_Component
8200 and then (Is_Atomic (T)
8201 or else (Is_Entity_Name (Prefix (N))
8202 and then Is_Atomic (Entity (Prefix (N)))))
8203 and then Is_Packed (T)
8206 Error_Msg_N ("?assignment to component of packed atomic record",
8208 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
8211 end Resolve_Selected_Component;
8217 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
8218 B_Typ : constant Entity_Id := Base_Type (Typ);
8219 L : constant Node_Id := Left_Opnd (N);
8220 R : constant Node_Id := Right_Opnd (N);
8223 -- We do the resolution using the base type, because intermediate values
8224 -- in expressions always are of the base type, not a subtype of it.
8227 Resolve (R, Standard_Natural);
8229 Check_Unset_Reference (L);
8230 Check_Unset_Reference (R);
8232 Set_Etype (N, B_Typ);
8233 Generate_Operator_Reference (N, B_Typ);
8237 ---------------------------
8238 -- Resolve_Short_Circuit --
8239 ---------------------------
8241 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
8242 B_Typ : constant Entity_Id := Base_Type (Typ);
8243 L : constant Node_Id := Left_Opnd (N);
8244 R : constant Node_Id := Right_Opnd (N);
8250 -- Check for issuing warning for always False assert/check, this happens
8251 -- when assertions are turned off, in which case the pragma Assert/Check
8252 -- was transformed into:
8254 -- if False and then <condition> then ...
8256 -- and we detect this pattern
8258 if Warn_On_Assertion_Failure
8259 and then Is_Entity_Name (R)
8260 and then Entity (R) = Standard_False
8261 and then Nkind (Parent (N)) = N_If_Statement
8262 and then Nkind (N) = N_And_Then
8263 and then Is_Entity_Name (L)
8264 and then Entity (L) = Standard_False
8267 Orig : constant Node_Id := Original_Node (Parent (N));
8270 if Nkind (Orig) = N_Pragma
8271 and then Pragma_Name (Orig) = Name_Assert
8273 -- Don't want to warn if original condition is explicit False
8276 Expr : constant Node_Id :=
8279 (First (Pragma_Argument_Associations (Orig))));
8281 if Is_Entity_Name (Expr)
8282 and then Entity (Expr) = Standard_False
8286 -- Issue warning. We do not want the deletion of the
8287 -- IF/AND-THEN to take this message with it. We achieve
8288 -- this by making sure that the expanded code points to
8289 -- the Sloc of the expression, not the original pragma.
8292 ("?assertion would fail at run time!",
8294 (First (Pragma_Argument_Associations (Orig))));
8298 -- Similar processing for Check pragma
8300 elsif Nkind (Orig) = N_Pragma
8301 and then Pragma_Name (Orig) = Name_Check
8303 -- Don't want to warn if original condition is explicit False
8306 Expr : constant Node_Id :=
8310 (Pragma_Argument_Associations (Orig)))));
8312 if Is_Entity_Name (Expr)
8313 and then Entity (Expr) = Standard_False
8318 ("?check would fail at run time!",
8320 (Last (Pragma_Argument_Associations (Orig))));
8327 -- Continue with processing of short circuit
8329 Check_Unset_Reference (L);
8330 Check_Unset_Reference (R);
8332 Set_Etype (N, B_Typ);
8333 Eval_Short_Circuit (N);
8334 end Resolve_Short_Circuit;
8340 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
8341 Name : constant Node_Id := Prefix (N);
8342 Drange : constant Node_Id := Discrete_Range (N);
8343 Array_Type : Entity_Id := Empty;
8347 if Is_Overloaded (Name) then
8349 -- Use the context type to select the prefix that yields the correct
8354 I1 : Interp_Index := 0;
8356 P : constant Node_Id := Prefix (N);
8357 Found : Boolean := False;
8360 Get_First_Interp (P, I, It);
8361 while Present (It.Typ) loop
8362 if (Is_Array_Type (It.Typ)
8363 and then Covers (Typ, It.Typ))
8364 or else (Is_Access_Type (It.Typ)
8365 and then Is_Array_Type (Designated_Type (It.Typ))
8366 and then Covers (Typ, Designated_Type (It.Typ)))
8369 It := Disambiguate (P, I1, I, Any_Type);
8371 if It = No_Interp then
8372 Error_Msg_N ("ambiguous prefix for slicing", N);
8377 Array_Type := It.Typ;
8382 Array_Type := It.Typ;
8387 Get_Next_Interp (I, It);
8392 Array_Type := Etype (Name);
8395 Resolve (Name, Array_Type);
8397 if Is_Access_Type (Array_Type) then
8398 Apply_Access_Check (N);
8399 Array_Type := Designated_Type (Array_Type);
8401 -- If the prefix is an access to an unconstrained array, we must use
8402 -- the actual subtype of the object to perform the index checks. The
8403 -- object denoted by the prefix is implicit in the node, so we build
8404 -- an explicit representation for it in order to compute the actual
8407 if not Is_Constrained (Array_Type) then
8408 Remove_Side_Effects (Prefix (N));
8411 Obj : constant Node_Id :=
8412 Make_Explicit_Dereference (Sloc (N),
8413 Prefix => New_Copy_Tree (Prefix (N)));
8415 Set_Etype (Obj, Array_Type);
8416 Set_Parent (Obj, Parent (N));
8417 Array_Type := Get_Actual_Subtype (Obj);
8421 elsif Is_Entity_Name (Name)
8422 or else Nkind (Name) = N_Explicit_Dereference
8423 or else (Nkind (Name) = N_Function_Call
8424 and then not Is_Constrained (Etype (Name)))
8426 Array_Type := Get_Actual_Subtype (Name);
8428 -- If the name is a selected component that depends on discriminants,
8429 -- build an actual subtype for it. This can happen only when the name
8430 -- itself is overloaded; otherwise the actual subtype is created when
8431 -- the selected component is analyzed.
8433 elsif Nkind (Name) = N_Selected_Component
8434 and then Full_Analysis
8435 and then Depends_On_Discriminant (First_Index (Array_Type))
8438 Act_Decl : constant Node_Id :=
8439 Build_Actual_Subtype_Of_Component (Array_Type, Name);
8441 Insert_Action (N, Act_Decl);
8442 Array_Type := Defining_Identifier (Act_Decl);
8445 -- Maybe this should just be "else", instead of checking for the
8446 -- specific case of slice??? This is needed for the case where
8447 -- the prefix is an Image attribute, which gets expanded to a
8448 -- slice, and so has a constrained subtype which we want to use
8449 -- for the slice range check applied below (the range check won't
8450 -- get done if the unconstrained subtype of the 'Image is used).
8452 elsif Nkind (Name) = N_Slice then
8453 Array_Type := Etype (Name);
8456 -- If name was overloaded, set slice type correctly now
8458 Set_Etype (N, Array_Type);
8460 -- If the range is specified by a subtype mark, no resolution is
8461 -- necessary. Else resolve the bounds, and apply needed checks.
8463 if not Is_Entity_Name (Drange) then
8464 Index := First_Index (Array_Type);
8465 Resolve (Drange, Base_Type (Etype (Index)));
8467 if Nkind (Drange) = N_Range then
8469 -- Ensure that side effects in the bounds are properly handled
8471 Remove_Side_Effects (Low_Bound (Drange), Variable_Ref => True);
8472 Remove_Side_Effects (High_Bound (Drange), Variable_Ref => True);
8474 -- Do not apply the range check to nodes associated with the
8475 -- frontend expansion of the dispatch table. We first check
8476 -- if Ada.Tags is already loaded to avoid the addition of an
8477 -- undesired dependence on such run-time unit.
8479 if not Tagged_Type_Expansion
8481 (RTU_Loaded (Ada_Tags)
8482 and then Nkind (Prefix (N)) = N_Selected_Component
8483 and then Present (Entity (Selector_Name (Prefix (N))))
8484 and then Entity (Selector_Name (Prefix (N))) =
8485 RTE_Record_Component (RE_Prims_Ptr))
8487 Apply_Range_Check (Drange, Etype (Index));
8492 Set_Slice_Subtype (N);
8494 -- Check bad use of type with predicates
8496 if Has_Predicates (Etype (Drange)) then
8497 Bad_Predicated_Subtype_Use
8498 ("subtype& has predicate, not allowed in slice",
8499 Drange, Etype (Drange));
8501 -- Otherwise here is where we check suspicious indexes
8503 elsif Nkind (Drange) = N_Range then
8504 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
8505 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
8511 ----------------------------
8512 -- Resolve_String_Literal --
8513 ----------------------------
8515 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
8516 C_Typ : constant Entity_Id := Component_Type (Typ);
8517 R_Typ : constant Entity_Id := Root_Type (C_Typ);
8518 Loc : constant Source_Ptr := Sloc (N);
8519 Str : constant String_Id := Strval (N);
8520 Strlen : constant Nat := String_Length (Str);
8521 Subtype_Id : Entity_Id;
8522 Need_Check : Boolean;
8525 -- For a string appearing in a concatenation, defer creation of the
8526 -- string_literal_subtype until the end of the resolution of the
8527 -- concatenation, because the literal may be constant-folded away. This
8528 -- is a useful optimization for long concatenation expressions.
8530 -- If the string is an aggregate built for a single character (which
8531 -- happens in a non-static context) or a is null string to which special
8532 -- checks may apply, we build the subtype. Wide strings must also get a
8533 -- string subtype if they come from a one character aggregate. Strings
8534 -- generated by attributes might be static, but it is often hard to
8535 -- determine whether the enclosing context is static, so we generate
8536 -- subtypes for them as well, thus losing some rarer optimizations ???
8537 -- Same for strings that come from a static conversion.
8540 (Strlen = 0 and then Typ /= Standard_String)
8541 or else Nkind (Parent (N)) /= N_Op_Concat
8542 or else (N /= Left_Opnd (Parent (N))
8543 and then N /= Right_Opnd (Parent (N)))
8544 or else ((Typ = Standard_Wide_String
8545 or else Typ = Standard_Wide_Wide_String)
8546 and then Nkind (Original_Node (N)) /= N_String_Literal);
8548 -- If the resolving type is itself a string literal subtype, we can just
8549 -- reuse it, since there is no point in creating another.
8551 if Ekind (Typ) = E_String_Literal_Subtype then
8554 elsif Nkind (Parent (N)) = N_Op_Concat
8555 and then not Need_Check
8556 and then not Nkind_In (Original_Node (N), N_Character_Literal,
8557 N_Attribute_Reference,
8558 N_Qualified_Expression,
8563 -- Otherwise we must create a string literal subtype. Note that the
8564 -- whole idea of string literal subtypes is simply to avoid the need
8565 -- for building a full fledged array subtype for each literal.
8568 Set_String_Literal_Subtype (N, Typ);
8569 Subtype_Id := Etype (N);
8572 if Nkind (Parent (N)) /= N_Op_Concat
8575 Set_Etype (N, Subtype_Id);
8576 Eval_String_Literal (N);
8579 if Is_Limited_Composite (Typ)
8580 or else Is_Private_Composite (Typ)
8582 Error_Msg_N ("string literal not available for private array", N);
8583 Set_Etype (N, Any_Type);
8587 -- The validity of a null string has been checked in the call to
8588 -- Eval_String_Literal.
8593 -- Always accept string literal with component type Any_Character, which
8594 -- occurs in error situations and in comparisons of literals, both of
8595 -- which should accept all literals.
8597 elsif R_Typ = Any_Character then
8600 -- If the type is bit-packed, then we always transform the string
8601 -- literal into a full fledged aggregate.
8603 elsif Is_Bit_Packed_Array (Typ) then
8606 -- Deal with cases of Wide_Wide_String, Wide_String, and String
8609 -- For Standard.Wide_Wide_String, or any other type whose component
8610 -- type is Standard.Wide_Wide_Character, we know that all the
8611 -- characters in the string must be acceptable, since the parser
8612 -- accepted the characters as valid character literals.
8614 if R_Typ = Standard_Wide_Wide_Character then
8617 -- For the case of Standard.String, or any other type whose component
8618 -- type is Standard.Character, we must make sure that there are no
8619 -- wide characters in the string, i.e. that it is entirely composed
8620 -- of characters in range of type Character.
8622 -- If the string literal is the result of a static concatenation, the
8623 -- test has already been performed on the components, and need not be
8626 elsif R_Typ = Standard_Character
8627 and then Nkind (Original_Node (N)) /= N_Op_Concat
8629 for J in 1 .. Strlen loop
8630 if not In_Character_Range (Get_String_Char (Str, J)) then
8632 -- If we are out of range, post error. This is one of the
8633 -- very few places that we place the flag in the middle of
8634 -- a token, right under the offending wide character. Not
8635 -- quite clear if this is right wrt wide character encoding
8636 -- sequences, but it's only an error message!
8639 ("literal out of range of type Standard.Character",
8640 Source_Ptr (Int (Loc) + J));
8645 -- For the case of Standard.Wide_String, or any other type whose
8646 -- component type is Standard.Wide_Character, we must make sure that
8647 -- there are no wide characters in the string, i.e. that it is
8648 -- entirely composed of characters in range of type Wide_Character.
8650 -- If the string literal is the result of a static concatenation,
8651 -- the test has already been performed on the components, and need
8654 elsif R_Typ = Standard_Wide_Character
8655 and then Nkind (Original_Node (N)) /= N_Op_Concat
8657 for J in 1 .. Strlen loop
8658 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
8660 -- If we are out of range, post error. This is one of the
8661 -- very few places that we place the flag in the middle of
8662 -- a token, right under the offending wide character.
8664 -- This is not quite right, because characters in general
8665 -- will take more than one character position ???
8668 ("literal out of range of type Standard.Wide_Character",
8669 Source_Ptr (Int (Loc) + J));
8674 -- If the root type is not a standard character, then we will convert
8675 -- the string into an aggregate and will let the aggregate code do
8676 -- the checking. Standard Wide_Wide_Character is also OK here.
8682 -- See if the component type of the array corresponding to the string
8683 -- has compile time known bounds. If yes we can directly check
8684 -- whether the evaluation of the string will raise constraint error.
8685 -- Otherwise we need to transform the string literal into the
8686 -- corresponding character aggregate and let the aggregate
8687 -- code do the checking.
8689 if Is_Standard_Character_Type (R_Typ) then
8691 -- Check for the case of full range, where we are definitely OK
8693 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
8697 -- Here the range is not the complete base type range, so check
8700 Comp_Typ_Lo : constant Node_Id :=
8701 Type_Low_Bound (Component_Type (Typ));
8702 Comp_Typ_Hi : constant Node_Id :=
8703 Type_High_Bound (Component_Type (Typ));
8708 if Compile_Time_Known_Value (Comp_Typ_Lo)
8709 and then Compile_Time_Known_Value (Comp_Typ_Hi)
8711 for J in 1 .. Strlen loop
8712 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
8714 if Char_Val < Expr_Value (Comp_Typ_Lo)
8715 or else Char_Val > Expr_Value (Comp_Typ_Hi)
8717 Apply_Compile_Time_Constraint_Error
8718 (N, "character out of range?", CE_Range_Check_Failed,
8719 Loc => Source_Ptr (Int (Loc) + J));
8729 -- If we got here we meed to transform the string literal into the
8730 -- equivalent qualified positional array aggregate. This is rather
8731 -- heavy artillery for this situation, but it is hard work to avoid.
8734 Lits : constant List_Id := New_List;
8735 P : Source_Ptr := Loc + 1;
8739 -- Build the character literals, we give them source locations that
8740 -- correspond to the string positions, which is a bit tricky given
8741 -- the possible presence of wide character escape sequences.
8743 for J in 1 .. Strlen loop
8744 C := Get_String_Char (Str, J);
8745 Set_Character_Literal_Name (C);
8748 Make_Character_Literal (P,
8750 Char_Literal_Value => UI_From_CC (C)));
8752 if In_Character_Range (C) then
8755 -- Should we have a call to Skip_Wide here ???
8763 Make_Qualified_Expression (Loc,
8764 Subtype_Mark => New_Reference_To (Typ, Loc),
8766 Make_Aggregate (Loc, Expressions => Lits)));
8768 Analyze_And_Resolve (N, Typ);
8770 end Resolve_String_Literal;
8772 -----------------------------
8773 -- Resolve_Subprogram_Info --
8774 -----------------------------
8776 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
8779 end Resolve_Subprogram_Info;
8781 -----------------------------
8782 -- Resolve_Type_Conversion --
8783 -----------------------------
8785 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
8786 Conv_OK : constant Boolean := Conversion_OK (N);
8787 Operand : constant Node_Id := Expression (N);
8788 Operand_Typ : constant Entity_Id := Etype (Operand);
8789 Target_Typ : constant Entity_Id := Etype (N);
8794 Test_Redundant : Boolean := Warn_On_Redundant_Constructs;
8795 -- Set to False to suppress cases where we want to suppress the test
8796 -- for redundancy to avoid possible false positives on this warning.
8800 and then not Valid_Conversion (N, Target_Typ, Operand)
8805 -- If the Operand Etype is Universal_Fixed, then the conversion is
8806 -- never redundant. We need this check because by the time we have
8807 -- finished the rather complex transformation, the conversion looks
8808 -- redundant when it is not.
8810 if Operand_Typ = Universal_Fixed then
8811 Test_Redundant := False;
8813 -- If the operand is marked as Any_Fixed, then special processing is
8814 -- required. This is also a case where we suppress the test for a
8815 -- redundant conversion, since most certainly it is not redundant.
8817 elsif Operand_Typ = Any_Fixed then
8818 Test_Redundant := False;
8820 -- Mixed-mode operation involving a literal. Context must be a fixed
8821 -- type which is applied to the literal subsequently.
8823 if Is_Fixed_Point_Type (Typ) then
8824 Set_Etype (Operand, Universal_Real);
8826 elsif Is_Numeric_Type (Typ)
8827 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
8828 and then (Etype (Right_Opnd (Operand)) = Universal_Real
8830 Etype (Left_Opnd (Operand)) = Universal_Real)
8832 -- Return if expression is ambiguous
8834 if Unique_Fixed_Point_Type (N) = Any_Type then
8837 -- If nothing else, the available fixed type is Duration
8840 Set_Etype (Operand, Standard_Duration);
8843 -- Resolve the real operand with largest available precision
8845 if Etype (Right_Opnd (Operand)) = Universal_Real then
8846 Rop := New_Copy_Tree (Right_Opnd (Operand));
8848 Rop := New_Copy_Tree (Left_Opnd (Operand));
8851 Resolve (Rop, Universal_Real);
8853 -- If the operand is a literal (it could be a non-static and
8854 -- illegal exponentiation) check whether the use of Duration
8855 -- is potentially inaccurate.
8857 if Nkind (Rop) = N_Real_Literal
8858 and then Realval (Rop) /= Ureal_0
8859 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
8862 ("?universal real operand can only " &
8863 "be interpreted as Duration!",
8866 ("\?precision will be lost in the conversion!", Rop);
8869 elsif Is_Numeric_Type (Typ)
8870 and then Nkind (Operand) in N_Op
8871 and then Unique_Fixed_Point_Type (N) /= Any_Type
8873 Set_Etype (Operand, Standard_Duration);
8876 Error_Msg_N ("invalid context for mixed mode operation", N);
8877 Set_Etype (Operand, Any_Type);
8884 -- Note: we do the Eval_Type_Conversion call before applying the
8885 -- required checks for a subtype conversion. This is important, since
8886 -- both are prepared under certain circumstances to change the type
8887 -- conversion to a constraint error node, but in the case of
8888 -- Eval_Type_Conversion this may reflect an illegality in the static
8889 -- case, and we would miss the illegality (getting only a warning
8890 -- message), if we applied the type conversion checks first.
8892 Eval_Type_Conversion (N);
8894 -- Even when evaluation is not possible, we may be able to simplify the
8895 -- conversion or its expression. This needs to be done before applying
8896 -- checks, since otherwise the checks may use the original expression
8897 -- and defeat the simplifications. This is specifically the case for
8898 -- elimination of the floating-point Truncation attribute in
8899 -- float-to-int conversions.
8901 Simplify_Type_Conversion (N);
8903 -- If after evaluation we still have a type conversion, then we may need
8904 -- to apply checks required for a subtype conversion.
8906 -- Skip these type conversion checks if universal fixed operands
8907 -- operands involved, since range checks are handled separately for
8908 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
8910 if Nkind (N) = N_Type_Conversion
8911 and then not Is_Generic_Type (Root_Type (Target_Typ))
8912 and then Target_Typ /= Universal_Fixed
8913 and then Operand_Typ /= Universal_Fixed
8915 Apply_Type_Conversion_Checks (N);
8918 -- Issue warning for conversion of simple object to its own type. We
8919 -- have to test the original nodes, since they may have been rewritten
8920 -- by various optimizations.
8922 Orig_N := Original_Node (N);
8924 -- Here we test for a redundant conversion if the warning mode is
8925 -- active (and was not locally reset), and we have a type conversion
8926 -- from source not appearing in a generic instance.
8929 and then Nkind (Orig_N) = N_Type_Conversion
8930 and then Comes_From_Source (Orig_N)
8931 and then not In_Instance
8933 Orig_N := Original_Node (Expression (Orig_N));
8934 Orig_T := Target_Typ;
8936 -- If the node is part of a larger expression, the Target_Type
8937 -- may not be the original type of the node if the context is a
8938 -- condition. Recover original type to see if conversion is needed.
8940 if Is_Boolean_Type (Orig_T)
8941 and then Nkind (Parent (N)) in N_Op
8943 Orig_T := Etype (Parent (N));
8946 -- If we have an entity name, then give the warning if the entity
8947 -- is the right type, or if it is a loop parameter covered by the
8948 -- original type (that's needed because loop parameters have an
8949 -- odd subtype coming from the bounds).
8951 if (Is_Entity_Name (Orig_N)
8953 (Etype (Entity (Orig_N)) = Orig_T
8955 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
8956 and then Covers (Orig_T, Etype (Entity (Orig_N))))))
8958 -- If not an entity, then type of expression must match
8960 or else Etype (Orig_N) = Orig_T
8962 -- One more check, do not give warning if the analyzed conversion
8963 -- has an expression with non-static bounds, and the bounds of the
8964 -- target are static. This avoids junk warnings in cases where the
8965 -- conversion is necessary to establish staticness, for example in
8966 -- a case statement.
8968 if not Is_OK_Static_Subtype (Operand_Typ)
8969 and then Is_OK_Static_Subtype (Target_Typ)
8973 -- Finally, if this type conversion occurs in a context that
8974 -- requires a prefix, and the expression is a qualified expression
8975 -- then the type conversion is not redundant, because a qualified
8976 -- expression is not a prefix, whereas a type conversion is. For
8977 -- example, "X := T'(Funx(...)).Y;" is illegal because a selected
8978 -- component requires a prefix, but a type conversion makes it
8979 -- legal: "X := T(T'(Funx(...))).Y;"
8981 -- In Ada 2012, a qualified expression is a name, so this idiom is
8982 -- no longer needed, but we still suppress the warning because it
8983 -- seems unfriendly for warnings to pop up when you switch to the
8984 -- newer language version.
8986 elsif Nkind (Orig_N) = N_Qualified_Expression
8987 and then Nkind_In (Parent (N), N_Attribute_Reference,
8988 N_Indexed_Component,
8989 N_Selected_Component,
8991 N_Explicit_Dereference)
8995 -- Here we give the redundant conversion warning. If it is an
8996 -- entity, give the name of the entity in the message. If not,
8997 -- just mention the expression.
9000 if Is_Entity_Name (Orig_N) then
9001 Error_Msg_Node_2 := Orig_T;
9002 Error_Msg_NE -- CODEFIX
9003 ("?redundant conversion, & is of type &!",
9004 N, Entity (Orig_N));
9007 ("?redundant conversion, expression is of type&!",
9014 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
9015 -- No need to perform any interface conversion if the type of the
9016 -- expression coincides with the target type.
9018 if Ada_Version >= Ada_2005
9019 and then Expander_Active
9020 and then Operand_Typ /= Target_Typ
9023 Opnd : Entity_Id := Operand_Typ;
9024 Target : Entity_Id := Target_Typ;
9027 if Is_Access_Type (Opnd) then
9028 Opnd := Designated_Type (Opnd);
9031 if Is_Access_Type (Target_Typ) then
9032 Target := Designated_Type (Target);
9035 if Opnd = Target then
9038 -- Conversion from interface type
9040 elsif Is_Interface (Opnd) then
9042 -- Ada 2005 (AI-217): Handle entities from limited views
9044 if From_With_Type (Opnd) then
9045 Error_Msg_Qual_Level := 99;
9046 Error_Msg_NE -- CODEFIX
9047 ("missing WITH clause on package &", N,
9048 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
9050 ("type conversions require visibility of the full view",
9053 elsif From_With_Type (Target)
9055 (Is_Access_Type (Target_Typ)
9056 and then Present (Non_Limited_View (Etype (Target))))
9058 Error_Msg_Qual_Level := 99;
9059 Error_Msg_NE -- CODEFIX
9060 ("missing WITH clause on package &", N,
9061 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
9063 ("type conversions require visibility of the full view",
9067 Expand_Interface_Conversion (N, Is_Static => False);
9070 -- Conversion to interface type
9072 elsif Is_Interface (Target) then
9076 if Ekind_In (Opnd, E_Protected_Subtype, E_Task_Subtype) then
9077 Opnd := Etype (Opnd);
9080 if not Interface_Present_In_Ancestor
9084 if Is_Class_Wide_Type (Opnd) then
9086 -- The static analysis is not enough to know if the
9087 -- interface is implemented or not. Hence we must pass
9088 -- the work to the expander to generate code to evaluate
9089 -- the conversion at run time.
9091 Expand_Interface_Conversion (N, Is_Static => False);
9094 Error_Msg_Name_1 := Chars (Etype (Target));
9095 Error_Msg_Name_2 := Chars (Opnd);
9097 ("wrong interface conversion (% is not a progenitor " &
9102 Expand_Interface_Conversion (N);
9107 end Resolve_Type_Conversion;
9109 ----------------------
9110 -- Resolve_Unary_Op --
9111 ----------------------
9113 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
9114 B_Typ : constant Entity_Id := Base_Type (Typ);
9115 R : constant Node_Id := Right_Opnd (N);
9121 -- Deal with intrinsic unary operators
9123 if Comes_From_Source (N)
9124 and then Ekind (Entity (N)) = E_Function
9125 and then Is_Imported (Entity (N))
9126 and then Is_Intrinsic_Subprogram (Entity (N))
9128 Resolve_Intrinsic_Unary_Operator (N, Typ);
9132 -- Deal with universal cases
9134 if Etype (R) = Universal_Integer
9136 Etype (R) = Universal_Real
9138 Check_For_Visible_Operator (N, B_Typ);
9141 Set_Etype (N, B_Typ);
9144 -- Generate warning for expressions like abs (x mod 2)
9146 if Warn_On_Redundant_Constructs
9147 and then Nkind (N) = N_Op_Abs
9149 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
9151 if OK and then Hi >= Lo and then Lo >= 0 then
9152 Error_Msg_N -- CODEFIX
9153 ("?abs applied to known non-negative value has no effect", N);
9157 -- Deal with reference generation
9159 Check_Unset_Reference (R);
9160 Generate_Operator_Reference (N, B_Typ);
9163 -- Set overflow checking bit. Much cleverer code needed here eventually
9164 -- and perhaps the Resolve routines should be separated for the various
9165 -- arithmetic operations, since they will need different processing ???
9167 if Nkind (N) in N_Op then
9168 if not Overflow_Checks_Suppressed (Etype (N)) then
9169 Enable_Overflow_Check (N);
9173 -- Generate warning for expressions like -5 mod 3 for integers. No need
9174 -- to worry in the floating-point case, since parens do not affect the
9175 -- result so there is no point in giving in a warning.
9178 Norig : constant Node_Id := Original_Node (N);
9187 if Warn_On_Questionable_Missing_Parens
9188 and then Comes_From_Source (Norig)
9189 and then Is_Integer_Type (Typ)
9190 and then Nkind (Norig) = N_Op_Minus
9192 Rorig := Original_Node (Right_Opnd (Norig));
9194 -- We are looking for cases where the right operand is not
9195 -- parenthesized, and is a binary operator, multiply, divide, or
9196 -- mod. These are the cases where the grouping can affect results.
9198 if Paren_Count (Rorig) = 0
9199 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
9201 -- For mod, we always give the warning, since the value is
9202 -- affected by the parenthesization (e.g. (-5) mod 315 /=
9203 -- -(5 mod 315)). But for the other cases, the only concern is
9204 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
9205 -- overflows, but (-2) * 64 does not). So we try to give the
9206 -- message only when overflow is possible.
9208 if Nkind (Rorig) /= N_Op_Mod
9209 and then Compile_Time_Known_Value (R)
9211 Val := Expr_Value (R);
9213 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
9214 HB := Expr_Value (Type_High_Bound (Typ));
9216 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
9219 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
9220 LB := Expr_Value (Type_Low_Bound (Typ));
9222 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
9225 -- Note that the test below is deliberately excluding the
9226 -- largest negative number, since that is a potentially
9227 -- troublesome case (e.g. -2 * x, where the result is the
9228 -- largest negative integer has an overflow with 2 * x).
9230 if Val > LB and then Val <= HB then
9235 -- For the multiplication case, the only case we have to worry
9236 -- about is when (-a)*b is exactly the largest negative number
9237 -- so that -(a*b) can cause overflow. This can only happen if
9238 -- a is a power of 2, and more generally if any operand is a
9239 -- constant that is not a power of 2, then the parentheses
9240 -- cannot affect whether overflow occurs. We only bother to
9241 -- test the left most operand
9243 -- Loop looking at left operands for one that has known value
9246 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
9247 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
9248 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
9250 -- Operand value of 0 or 1 skips warning
9255 -- Otherwise check power of 2, if power of 2, warn, if
9256 -- anything else, skip warning.
9259 while Lval /= 2 loop
9260 if Lval mod 2 = 1 then
9271 -- Keep looking at left operands
9273 Opnd := Left_Opnd (Opnd);
9276 -- For rem or "/" we can only have a problematic situation
9277 -- if the divisor has a value of minus one or one. Otherwise
9278 -- overflow is impossible (divisor > 1) or we have a case of
9279 -- division by zero in any case.
9281 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
9282 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
9283 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
9288 -- If we fall through warning should be issued
9291 ("?unary minus expression should be parenthesized here!", N);
9295 end Resolve_Unary_Op;
9297 ----------------------------------
9298 -- Resolve_Unchecked_Expression --
9299 ----------------------------------
9301 procedure Resolve_Unchecked_Expression
9306 Resolve (Expression (N), Typ, Suppress => All_Checks);
9308 end Resolve_Unchecked_Expression;
9310 ---------------------------------------
9311 -- Resolve_Unchecked_Type_Conversion --
9312 ---------------------------------------
9314 procedure Resolve_Unchecked_Type_Conversion
9318 pragma Warnings (Off, Typ);
9320 Operand : constant Node_Id := Expression (N);
9321 Opnd_Type : constant Entity_Id := Etype (Operand);
9324 -- Resolve operand using its own type
9326 Resolve (Operand, Opnd_Type);
9327 Eval_Unchecked_Conversion (N);
9328 end Resolve_Unchecked_Type_Conversion;
9330 ------------------------------
9331 -- Rewrite_Operator_As_Call --
9332 ------------------------------
9334 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
9335 Loc : constant Source_Ptr := Sloc (N);
9336 Actuals : constant List_Id := New_List;
9340 if Nkind (N) in N_Binary_Op then
9341 Append (Left_Opnd (N), Actuals);
9344 Append (Right_Opnd (N), Actuals);
9347 Make_Function_Call (Sloc => Loc,
9348 Name => New_Occurrence_Of (Nam, Loc),
9349 Parameter_Associations => Actuals);
9351 Preserve_Comes_From_Source (New_N, N);
9352 Preserve_Comes_From_Source (Name (New_N), N);
9354 Set_Etype (N, Etype (Nam));
9355 end Rewrite_Operator_As_Call;
9357 ------------------------------
9358 -- Rewrite_Renamed_Operator --
9359 ------------------------------
9361 procedure Rewrite_Renamed_Operator
9366 Nam : constant Name_Id := Chars (Op);
9367 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
9371 -- Rewrite the operator node using the real operator, not its renaming.
9372 -- Exclude user-defined intrinsic operations of the same name, which are
9373 -- treated separately and rewritten as calls.
9375 if Ekind (Op) /= E_Function or else Chars (N) /= Nam then
9376 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
9377 Set_Chars (Op_Node, Nam);
9378 Set_Etype (Op_Node, Etype (N));
9379 Set_Entity (Op_Node, Op);
9380 Set_Right_Opnd (Op_Node, Right_Opnd (N));
9382 -- Indicate that both the original entity and its renaming are
9383 -- referenced at this point.
9385 Generate_Reference (Entity (N), N);
9386 Generate_Reference (Op, N);
9389 Set_Left_Opnd (Op_Node, Left_Opnd (N));
9392 Rewrite (N, Op_Node);
9394 -- If the context type is private, add the appropriate conversions so
9395 -- that the operator is applied to the full view. This is done in the
9396 -- routines that resolve intrinsic operators.
9398 if Is_Intrinsic_Subprogram (Op)
9399 and then Is_Private_Type (Typ)
9402 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
9403 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
9404 Resolve_Intrinsic_Operator (N, Typ);
9406 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
9407 Resolve_Intrinsic_Unary_Operator (N, Typ);
9414 elsif Ekind (Op) = E_Function and then Is_Intrinsic_Subprogram (Op) then
9416 -- Operator renames a user-defined operator of the same name. Use the
9417 -- original operator in the node, which is the one Gigi knows about.
9420 Set_Is_Overloaded (N, False);
9422 end Rewrite_Renamed_Operator;
9424 -----------------------
9425 -- Set_Slice_Subtype --
9426 -----------------------
9428 -- Build an implicit subtype declaration to represent the type delivered by
9429 -- the slice. This is an abbreviated version of an array subtype. We define
9430 -- an index subtype for the slice, using either the subtype name or the
9431 -- discrete range of the slice. To be consistent with index usage elsewhere
9432 -- we create a list header to hold the single index. This list is not
9433 -- otherwise attached to the syntax tree.
9435 procedure Set_Slice_Subtype (N : Node_Id) is
9436 Loc : constant Source_Ptr := Sloc (N);
9437 Index_List : constant List_Id := New_List;
9439 Index_Subtype : Entity_Id;
9440 Index_Type : Entity_Id;
9441 Slice_Subtype : Entity_Id;
9442 Drange : constant Node_Id := Discrete_Range (N);
9445 if Is_Entity_Name (Drange) then
9446 Index_Subtype := Entity (Drange);
9449 -- We force the evaluation of a range. This is definitely needed in
9450 -- the renamed case, and seems safer to do unconditionally. Note in
9451 -- any case that since we will create and insert an Itype referring
9452 -- to this range, we must make sure any side effect removal actions
9453 -- are inserted before the Itype definition.
9455 if Nkind (Drange) = N_Range then
9456 Force_Evaluation (Low_Bound (Drange));
9457 Force_Evaluation (High_Bound (Drange));
9460 Index_Type := Base_Type (Etype (Drange));
9462 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9464 -- Take a new copy of Drange (where bounds have been rewritten to
9465 -- reference side-effect-free names). Using a separate tree ensures
9466 -- that further expansion (e.g. while rewriting a slice assignment
9467 -- into a FOR loop) does not attempt to remove side effects on the
9468 -- bounds again (which would cause the bounds in the index subtype
9469 -- definition to refer to temporaries before they are defined) (the
9470 -- reason is that some names are considered side effect free here
9471 -- for the subtype, but not in the context of a loop iteration
9474 Set_Scalar_Range (Index_Subtype, New_Copy_Tree (Drange));
9475 Set_Etype (Index_Subtype, Index_Type);
9476 Set_Size_Info (Index_Subtype, Index_Type);
9477 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9480 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
9482 Index := New_Occurrence_Of (Index_Subtype, Loc);
9483 Set_Etype (Index, Index_Subtype);
9484 Append (Index, Index_List);
9486 Set_First_Index (Slice_Subtype, Index);
9487 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
9488 Set_Is_Constrained (Slice_Subtype, True);
9490 Check_Compile_Time_Size (Slice_Subtype);
9492 -- The Etype of the existing Slice node is reset to this slice subtype.
9493 -- Its bounds are obtained from its first index.
9495 Set_Etype (N, Slice_Subtype);
9497 -- For packed slice subtypes, freeze immediately (except in the
9498 -- case of being in a "spec expression" where we never freeze
9499 -- when we first see the expression).
9501 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
9502 Freeze_Itype (Slice_Subtype, N);
9504 -- For all other cases insert an itype reference in the slice's actions
9505 -- so that the itype is frozen at the proper place in the tree (i.e. at
9506 -- the point where actions for the slice are analyzed). Note that this
9507 -- is different from freezing the itype immediately, which might be
9508 -- premature (e.g. if the slice is within a transient scope).
9511 Ensure_Defined (Typ => Slice_Subtype, N => N);
9513 end Set_Slice_Subtype;
9515 --------------------------------
9516 -- Set_String_Literal_Subtype --
9517 --------------------------------
9519 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
9520 Loc : constant Source_Ptr := Sloc (N);
9521 Low_Bound : constant Node_Id :=
9522 Type_Low_Bound (Etype (First_Index (Typ)));
9523 Subtype_Id : Entity_Id;
9526 if Nkind (N) /= N_String_Literal then
9530 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
9531 Set_String_Literal_Length (Subtype_Id, UI_From_Int
9532 (String_Length (Strval (N))));
9533 Set_Etype (Subtype_Id, Base_Type (Typ));
9534 Set_Is_Constrained (Subtype_Id);
9535 Set_Etype (N, Subtype_Id);
9537 if Is_OK_Static_Expression (Low_Bound) then
9539 -- The low bound is set from the low bound of the corresponding index
9540 -- type. Note that we do not store the high bound in the string literal
9541 -- subtype, but it can be deduced if necessary from the length and the
9544 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
9547 Set_String_Literal_Low_Bound
9548 (Subtype_Id, Make_Integer_Literal (Loc, 1));
9549 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Standard_Positive);
9551 -- Build bona fide subtype for the string, and wrap it in an
9552 -- unchecked conversion, because the backend expects the
9553 -- String_Literal_Subtype to have a static lower bound.
9556 Index_List : constant List_Id := New_List;
9557 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
9558 High_Bound : constant Node_Id :=
9560 Left_Opnd => New_Copy_Tree (Low_Bound),
9562 Make_Integer_Literal (Loc,
9563 String_Length (Strval (N)) - 1));
9564 Array_Subtype : Entity_Id;
9565 Index_Subtype : Entity_Id;
9571 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9572 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
9573 Set_Scalar_Range (Index_Subtype, Drange);
9574 Set_Parent (Drange, N);
9575 Analyze_And_Resolve (Drange, Index_Type);
9577 -- In the context, the Index_Type may already have a constraint,
9578 -- so use common base type on string subtype. The base type may
9579 -- be used when generating attributes of the string, for example
9580 -- in the context of a slice assignment.
9582 Set_Etype (Index_Subtype, Base_Type (Index_Type));
9583 Set_Size_Info (Index_Subtype, Index_Type);
9584 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9586 Array_Subtype := Create_Itype (E_Array_Subtype, N);
9588 Index := New_Occurrence_Of (Index_Subtype, Loc);
9589 Set_Etype (Index, Index_Subtype);
9590 Append (Index, Index_List);
9592 Set_First_Index (Array_Subtype, Index);
9593 Set_Etype (Array_Subtype, Base_Type (Typ));
9594 Set_Is_Constrained (Array_Subtype, True);
9597 Make_Unchecked_Type_Conversion (Loc,
9598 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
9599 Expression => Relocate_Node (N)));
9600 Set_Etype (N, Array_Subtype);
9603 end Set_String_Literal_Subtype;
9605 ------------------------------
9606 -- Simplify_Type_Conversion --
9607 ------------------------------
9609 procedure Simplify_Type_Conversion (N : Node_Id) is
9611 if Nkind (N) = N_Type_Conversion then
9613 Operand : constant Node_Id := Expression (N);
9614 Target_Typ : constant Entity_Id := Etype (N);
9615 Opnd_Typ : constant Entity_Id := Etype (Operand);
9618 if Is_Floating_Point_Type (Opnd_Typ)
9620 (Is_Integer_Type (Target_Typ)
9621 or else (Is_Fixed_Point_Type (Target_Typ)
9622 and then Conversion_OK (N)))
9623 and then Nkind (Operand) = N_Attribute_Reference
9624 and then Attribute_Name (Operand) = Name_Truncation
9626 -- Special processing required if the conversion is the expression
9627 -- of a Truncation attribute reference. In this case we replace:
9629 -- ityp (ftyp'Truncation (x))
9635 -- with the Float_Truncate flag set, which is more efficient.
9639 Relocate_Node (First (Expressions (Operand))));
9640 Set_Float_Truncate (N, True);
9644 end Simplify_Type_Conversion;
9646 -----------------------------
9647 -- Unique_Fixed_Point_Type --
9648 -----------------------------
9650 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
9651 T1 : Entity_Id := Empty;
9656 procedure Fixed_Point_Error;
9657 -- Give error messages for true ambiguity. Messages are posted on node
9658 -- N, and entities T1, T2 are the possible interpretations.
9660 -----------------------
9661 -- Fixed_Point_Error --
9662 -----------------------
9664 procedure Fixed_Point_Error is
9666 Error_Msg_N ("ambiguous universal_fixed_expression", N);
9667 Error_Msg_NE ("\\possible interpretation as}", N, T1);
9668 Error_Msg_NE ("\\possible interpretation as}", N, T2);
9669 end Fixed_Point_Error;
9671 -- Start of processing for Unique_Fixed_Point_Type
9674 -- The operations on Duration are visible, so Duration is always a
9675 -- possible interpretation.
9677 T1 := Standard_Duration;
9679 -- Look for fixed-point types in enclosing scopes
9681 Scop := Current_Scope;
9682 while Scop /= Standard_Standard loop
9683 T2 := First_Entity (Scop);
9684 while Present (T2) loop
9685 if Is_Fixed_Point_Type (T2)
9686 and then Current_Entity (T2) = T2
9687 and then Scope (Base_Type (T2)) = Scop
9689 if Present (T1) then
9700 Scop := Scope (Scop);
9703 -- Look for visible fixed type declarations in the context
9705 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
9706 while Present (Item) loop
9707 if Nkind (Item) = N_With_Clause then
9708 Scop := Entity (Name (Item));
9709 T2 := First_Entity (Scop);
9710 while Present (T2) loop
9711 if Is_Fixed_Point_Type (T2)
9712 and then Scope (Base_Type (T2)) = Scop
9713 and then (Is_Potentially_Use_Visible (T2)
9714 or else In_Use (T2))
9716 if Present (T1) then
9731 if Nkind (N) = N_Real_Literal then
9732 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
9734 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
9738 end Unique_Fixed_Point_Type;
9740 ----------------------
9741 -- Valid_Conversion --
9742 ----------------------
9744 function Valid_Conversion
9747 Operand : Node_Id) return Boolean
9749 Target_Type : constant Entity_Id := Base_Type (Target);
9750 Opnd_Type : Entity_Id := Etype (Operand);
9752 function Conversion_Check
9754 Msg : String) return Boolean;
9755 -- Little routine to post Msg if Valid is False, returns Valid value
9757 function Valid_Tagged_Conversion
9758 (Target_Type : Entity_Id;
9759 Opnd_Type : Entity_Id) return Boolean;
9760 -- Specifically test for validity of tagged conversions
9762 function Valid_Array_Conversion return Boolean;
9763 -- Check index and component conformance, and accessibility levels if
9764 -- the component types are anonymous access types (Ada 2005).
9766 ----------------------
9767 -- Conversion_Check --
9768 ----------------------
9770 function Conversion_Check
9772 Msg : String) return Boolean
9776 Error_Msg_N (Msg, Operand);
9780 end Conversion_Check;
9782 ----------------------------
9783 -- Valid_Array_Conversion --
9784 ----------------------------
9786 function Valid_Array_Conversion return Boolean
9788 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
9789 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
9791 Opnd_Index : Node_Id;
9792 Opnd_Index_Type : Entity_Id;
9794 Target_Comp_Type : constant Entity_Id :=
9795 Component_Type (Target_Type);
9796 Target_Comp_Base : constant Entity_Id :=
9797 Base_Type (Target_Comp_Type);
9799 Target_Index : Node_Id;
9800 Target_Index_Type : Entity_Id;
9803 -- Error if wrong number of dimensions
9806 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
9809 ("incompatible number of dimensions for conversion", Operand);
9812 -- Number of dimensions matches
9815 -- Loop through indexes of the two arrays
9817 Target_Index := First_Index (Target_Type);
9818 Opnd_Index := First_Index (Opnd_Type);
9819 while Present (Target_Index) and then Present (Opnd_Index) loop
9820 Target_Index_Type := Etype (Target_Index);
9821 Opnd_Index_Type := Etype (Opnd_Index);
9823 -- Error if index types are incompatible
9825 if not (Is_Integer_Type (Target_Index_Type)
9826 and then Is_Integer_Type (Opnd_Index_Type))
9827 and then (Root_Type (Target_Index_Type)
9828 /= Root_Type (Opnd_Index_Type))
9831 ("incompatible index types for array conversion",
9836 Next_Index (Target_Index);
9837 Next_Index (Opnd_Index);
9840 -- If component types have same base type, all set
9842 if Target_Comp_Base = Opnd_Comp_Base then
9845 -- Here if base types of components are not the same. The only
9846 -- time this is allowed is if we have anonymous access types.
9848 -- The conversion of arrays of anonymous access types can lead
9849 -- to dangling pointers. AI-392 formalizes the accessibility
9850 -- checks that must be applied to such conversions to prevent
9851 -- out-of-scope references.
9854 Ekind_In (Target_Comp_Base, E_Anonymous_Access_Type,
9855 E_Anonymous_Access_Subprogram_Type)
9856 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
9858 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
9860 if Type_Access_Level (Target_Type) <
9861 Type_Access_Level (Opnd_Type)
9863 if In_Instance_Body then
9864 Error_Msg_N ("?source array type " &
9865 "has deeper accessibility level than target", Operand);
9866 Error_Msg_N ("\?Program_Error will be raised at run time",
9869 Make_Raise_Program_Error (Sloc (N),
9870 Reason => PE_Accessibility_Check_Failed));
9871 Set_Etype (N, Target_Type);
9874 -- Conversion not allowed because of accessibility levels
9877 Error_Msg_N ("source array type " &
9878 "has deeper accessibility level than target", Operand);
9885 -- All other cases where component base types do not match
9889 ("incompatible component types for array conversion",
9894 -- Check that component subtypes statically match. For numeric
9895 -- types this means that both must be either constrained or
9896 -- unconstrained. For enumeration types the bounds must match.
9897 -- All of this is checked in Subtypes_Statically_Match.
9899 if not Subtypes_Statically_Match
9900 (Target_Comp_Type, Opnd_Comp_Type)
9903 ("component subtypes must statically match", Operand);
9909 end Valid_Array_Conversion;
9911 -----------------------------
9912 -- Valid_Tagged_Conversion --
9913 -----------------------------
9915 function Valid_Tagged_Conversion
9916 (Target_Type : Entity_Id;
9917 Opnd_Type : Entity_Id) return Boolean
9920 -- Upward conversions are allowed (RM 4.6(22))
9922 if Covers (Target_Type, Opnd_Type)
9923 or else Is_Ancestor (Target_Type, Opnd_Type)
9927 -- Downward conversion are allowed if the operand is class-wide
9930 elsif Is_Class_Wide_Type (Opnd_Type)
9931 and then Covers (Opnd_Type, Target_Type)
9935 elsif Covers (Opnd_Type, Target_Type)
9936 or else Is_Ancestor (Opnd_Type, Target_Type)
9939 Conversion_Check (False,
9940 "downward conversion of tagged objects not allowed");
9942 -- Ada 2005 (AI-251): The conversion to/from interface types is
9945 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
9948 -- If the operand is a class-wide type obtained through a limited_
9949 -- with clause, and the context includes the non-limited view, use
9950 -- it to determine whether the conversion is legal.
9952 elsif Is_Class_Wide_Type (Opnd_Type)
9953 and then From_With_Type (Opnd_Type)
9954 and then Present (Non_Limited_View (Etype (Opnd_Type)))
9955 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
9959 elsif Is_Access_Type (Opnd_Type)
9960 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
9966 ("invalid tagged conversion, not compatible with}",
9967 N, First_Subtype (Opnd_Type));
9970 end Valid_Tagged_Conversion;
9972 -- Start of processing for Valid_Conversion
9975 Check_Parameterless_Call (Operand);
9977 if Is_Overloaded (Operand) then
9987 -- Remove procedure calls, which syntactically cannot appear in
9988 -- this context, but which cannot be removed by type checking,
9989 -- because the context does not impose a type.
9991 -- When compiling for VMS, spurious ambiguities can be produced
9992 -- when arithmetic operations have a literal operand and return
9993 -- System.Address or a descendant of it. These ambiguities are
9994 -- otherwise resolved by the context, but for conversions there
9995 -- is no context type and the removal of the spurious operations
9996 -- must be done explicitly here.
9998 -- The node may be labelled overloaded, but still contain only one
9999 -- interpretation because others were discarded earlier. If this
10000 -- is the case, retain the single interpretation if legal.
10002 Get_First_Interp (Operand, I, It);
10003 Opnd_Type := It.Typ;
10004 Get_Next_Interp (I, It);
10006 if Present (It.Typ)
10007 and then Opnd_Type /= Standard_Void_Type
10009 -- More than one candidate interpretation is available
10011 Get_First_Interp (Operand, I, It);
10012 while Present (It.Typ) loop
10013 if It.Typ = Standard_Void_Type then
10017 if Present (System_Aux_Id)
10018 and then Is_Descendent_Of_Address (It.Typ)
10023 Get_Next_Interp (I, It);
10027 Get_First_Interp (Operand, I, It);
10031 if No (It.Typ) then
10032 Error_Msg_N ("illegal operand in conversion", Operand);
10036 Get_Next_Interp (I, It);
10038 if Present (It.Typ) then
10041 It1 := Disambiguate (Operand, I1, I, Any_Type);
10043 if It1 = No_Interp then
10044 Error_Msg_N ("ambiguous operand in conversion", Operand);
10046 -- If the interpretation involves a standard operator, use
10047 -- the location of the type, which may be user-defined.
10049 if Sloc (It.Nam) = Standard_Location then
10050 Error_Msg_Sloc := Sloc (It.Typ);
10052 Error_Msg_Sloc := Sloc (It.Nam);
10055 Error_Msg_N -- CODEFIX
10056 ("\\possible interpretation#!", Operand);
10058 if Sloc (N1) = Standard_Location then
10059 Error_Msg_Sloc := Sloc (T1);
10061 Error_Msg_Sloc := Sloc (N1);
10064 Error_Msg_N -- CODEFIX
10065 ("\\possible interpretation#!", Operand);
10071 Set_Etype (Operand, It1.Typ);
10072 Opnd_Type := It1.Typ;
10078 if Is_Numeric_Type (Target_Type) then
10080 -- A universal fixed expression can be converted to any numeric type
10082 if Opnd_Type = Universal_Fixed then
10085 -- Also no need to check when in an instance or inlined body, because
10086 -- the legality has been established when the template was analyzed.
10087 -- Furthermore, numeric conversions may occur where only a private
10088 -- view of the operand type is visible at the instantiation point.
10089 -- This results in a spurious error if we check that the operand type
10090 -- is a numeric type.
10092 -- Note: in a previous version of this unit, the following tests were
10093 -- applied only for generated code (Comes_From_Source set to False),
10094 -- but in fact the test is required for source code as well, since
10095 -- this situation can arise in source code.
10097 elsif In_Instance or else In_Inlined_Body then
10100 -- Otherwise we need the conversion check
10103 return Conversion_Check
10104 (Is_Numeric_Type (Opnd_Type),
10105 "illegal operand for numeric conversion");
10110 elsif Is_Array_Type (Target_Type) then
10111 if not Is_Array_Type (Opnd_Type)
10112 or else Opnd_Type = Any_Composite
10113 or else Opnd_Type = Any_String
10115 Error_Msg_N ("illegal operand for array conversion", Operand);
10118 return Valid_Array_Conversion;
10121 -- Ada 2005 (AI-251): Anonymous access types where target references an
10124 elsif Ekind_In (Target_Type, E_General_Access_Type,
10125 E_Anonymous_Access_Type)
10126 and then Is_Interface (Directly_Designated_Type (Target_Type))
10128 -- Check the static accessibility rule of 4.6(17). Note that the
10129 -- check is not enforced when within an instance body, since the
10130 -- RM requires such cases to be caught at run time.
10132 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
10133 if Type_Access_Level (Opnd_Type) >
10134 Type_Access_Level (Target_Type)
10136 -- In an instance, this is a run-time check, but one we know
10137 -- will fail, so generate an appropriate warning. The raise
10138 -- will be generated by Expand_N_Type_Conversion.
10140 if In_Instance_Body then
10142 ("?cannot convert local pointer to non-local access type",
10145 ("\?Program_Error will be raised at run time", Operand);
10148 ("cannot convert local pointer to non-local access type",
10153 -- Special accessibility checks are needed in the case of access
10154 -- discriminants declared for a limited type.
10156 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10157 and then not Is_Local_Anonymous_Access (Opnd_Type)
10159 -- When the operand is a selected access discriminant the check
10160 -- needs to be made against the level of the object denoted by
10161 -- the prefix of the selected name (Object_Access_Level handles
10162 -- checking the prefix of the operand for this case).
10164 if Nkind (Operand) = N_Selected_Component
10165 and then Object_Access_Level (Operand) >
10166 Type_Access_Level (Target_Type)
10168 -- In an instance, this is a run-time check, but one we know
10169 -- will fail, so generate an appropriate warning. The raise
10170 -- will be generated by Expand_N_Type_Conversion.
10172 if In_Instance_Body then
10174 ("?cannot convert access discriminant to non-local" &
10175 " access type", Operand);
10177 ("\?Program_Error will be raised at run time", Operand);
10180 ("cannot convert access discriminant to non-local" &
10181 " access type", Operand);
10186 -- The case of a reference to an access discriminant from
10187 -- within a limited type declaration (which will appear as
10188 -- a discriminal) is always illegal because the level of the
10189 -- discriminant is considered to be deeper than any (nameable)
10192 if Is_Entity_Name (Operand)
10193 and then not Is_Local_Anonymous_Access (Opnd_Type)
10195 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10196 and then Present (Discriminal_Link (Entity (Operand)))
10199 ("discriminant has deeper accessibility level than target",
10208 -- General and anonymous access types
10210 elsif Ekind_In (Target_Type, E_General_Access_Type,
10211 E_Anonymous_Access_Type)
10214 (Is_Access_Type (Opnd_Type)
10216 Ekind_In (Opnd_Type, E_Access_Subprogram_Type,
10217 E_Access_Protected_Subprogram_Type),
10218 "must be an access-to-object type")
10220 if Is_Access_Constant (Opnd_Type)
10221 and then not Is_Access_Constant (Target_Type)
10224 ("access-to-constant operand type not allowed", Operand);
10228 -- Check the static accessibility rule of 4.6(17). Note that the
10229 -- check is not enforced when within an instance body, since the RM
10230 -- requires such cases to be caught at run time.
10232 if Ekind (Target_Type) /= E_Anonymous_Access_Type
10233 or else Is_Local_Anonymous_Access (Target_Type)
10235 if Type_Access_Level (Opnd_Type)
10236 > Type_Access_Level (Target_Type)
10238 -- In an instance, this is a run-time check, but one we know
10239 -- will fail, so generate an appropriate warning. The raise
10240 -- will be generated by Expand_N_Type_Conversion.
10242 if In_Instance_Body then
10244 ("?cannot convert local pointer to non-local access type",
10247 ("\?Program_Error will be raised at run time", Operand);
10250 -- Avoid generation of spurious error message
10252 if not Error_Posted (N) then
10254 ("cannot convert local pointer to non-local access type",
10261 -- Special accessibility checks are needed in the case of access
10262 -- discriminants declared for a limited type.
10264 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10265 and then not Is_Local_Anonymous_Access (Opnd_Type)
10267 -- When the operand is a selected access discriminant the check
10268 -- needs to be made against the level of the object denoted by
10269 -- the prefix of the selected name (Object_Access_Level handles
10270 -- checking the prefix of the operand for this case).
10272 if Nkind (Operand) = N_Selected_Component
10273 and then Object_Access_Level (Operand) >
10274 Type_Access_Level (Target_Type)
10276 -- In an instance, this is a run-time check, but one we know
10277 -- will fail, so generate an appropriate warning. The raise
10278 -- will be generated by Expand_N_Type_Conversion.
10280 if In_Instance_Body then
10282 ("?cannot convert access discriminant to non-local" &
10283 " access type", Operand);
10285 ("\?Program_Error will be raised at run time",
10290 ("cannot convert access discriminant to non-local" &
10291 " access type", Operand);
10296 -- The case of a reference to an access discriminant from
10297 -- within a limited type declaration (which will appear as
10298 -- a discriminal) is always illegal because the level of the
10299 -- discriminant is considered to be deeper than any (nameable)
10302 if Is_Entity_Name (Operand)
10304 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10305 and then Present (Discriminal_Link (Entity (Operand)))
10308 ("discriminant has deeper accessibility level than target",
10315 -- In the presence of limited_with clauses we have to use non-limited
10316 -- views, if available.
10318 Check_Limited : declare
10319 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
10320 -- Helper function to handle limited views
10322 --------------------------
10323 -- Full_Designated_Type --
10324 --------------------------
10326 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
10327 Desig : constant Entity_Id := Designated_Type (T);
10330 -- Handle the limited view of a type
10332 if Is_Incomplete_Type (Desig)
10333 and then From_With_Type (Desig)
10334 and then Present (Non_Limited_View (Desig))
10336 return Available_View (Desig);
10340 end Full_Designated_Type;
10342 -- Local Declarations
10344 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
10345 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
10347 Same_Base : constant Boolean :=
10348 Base_Type (Target) = Base_Type (Opnd);
10350 -- Start of processing for Check_Limited
10353 if Is_Tagged_Type (Target) then
10354 return Valid_Tagged_Conversion (Target, Opnd);
10357 if not Same_Base then
10359 ("target designated type not compatible with }",
10360 N, Base_Type (Opnd));
10363 -- Ada 2005 AI-384: legality rule is symmetric in both
10364 -- designated types. The conversion is legal (with possible
10365 -- constraint check) if either designated type is
10368 elsif Subtypes_Statically_Match (Target, Opnd)
10370 (Has_Discriminants (Target)
10372 (not Is_Constrained (Opnd)
10373 or else not Is_Constrained (Target)))
10375 -- Special case, if Value_Size has been used to make the
10376 -- sizes different, the conversion is not allowed even
10377 -- though the subtypes statically match.
10379 if Known_Static_RM_Size (Target)
10380 and then Known_Static_RM_Size (Opnd)
10381 and then RM_Size (Target) /= RM_Size (Opnd)
10384 ("target designated subtype not compatible with }",
10387 ("\because sizes of the two designated subtypes differ",
10391 -- Normal case where conversion is allowed
10399 ("target designated subtype not compatible with }",
10406 -- Access to subprogram types. If the operand is an access parameter,
10407 -- the type has a deeper accessibility that any master, and cannot be
10408 -- assigned. We must make an exception if the conversion is part of an
10409 -- assignment and the target is the return object of an extended return
10410 -- statement, because in that case the accessibility check takes place
10411 -- after the return.
10413 elsif Is_Access_Subprogram_Type (Target_Type)
10414 and then No (Corresponding_Remote_Type (Opnd_Type))
10416 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
10417 and then Is_Entity_Name (Operand)
10418 and then Ekind (Entity (Operand)) = E_In_Parameter
10420 (Nkind (Parent (N)) /= N_Assignment_Statement
10421 or else not Is_Entity_Name (Name (Parent (N)))
10422 or else not Is_Return_Object (Entity (Name (Parent (N)))))
10425 ("illegal attempt to store anonymous access to subprogram",
10428 ("\value has deeper accessibility than any master " &
10429 "(RM 3.10.2 (13))",
10433 ("\use named access type for& instead of access parameter",
10434 Operand, Entity (Operand));
10437 -- Check that the designated types are subtype conformant
10439 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
10440 Old_Id => Designated_Type (Opnd_Type),
10443 -- Check the static accessibility rule of 4.6(20)
10445 if Type_Access_Level (Opnd_Type) >
10446 Type_Access_Level (Target_Type)
10449 ("operand type has deeper accessibility level than target",
10452 -- Check that if the operand type is declared in a generic body,
10453 -- then the target type must be declared within that same body
10454 -- (enforces last sentence of 4.6(20)).
10456 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
10458 O_Gen : constant Node_Id :=
10459 Enclosing_Generic_Body (Opnd_Type);
10464 T_Gen := Enclosing_Generic_Body (Target_Type);
10465 while Present (T_Gen) and then T_Gen /= O_Gen loop
10466 T_Gen := Enclosing_Generic_Body (T_Gen);
10469 if T_Gen /= O_Gen then
10471 ("target type must be declared in same generic body"
10472 & " as operand type", N);
10479 -- Remote subprogram access types
10481 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
10482 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
10484 -- It is valid to convert from one RAS type to another provided
10485 -- that their specification statically match.
10487 Check_Subtype_Conformant
10489 Designated_Type (Corresponding_Remote_Type (Target_Type)),
10491 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
10496 -- If both are tagged types, check legality of view conversions
10498 elsif Is_Tagged_Type (Target_Type)
10500 Is_Tagged_Type (Opnd_Type)
10502 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
10504 -- Types derived from the same root type are convertible
10506 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
10509 -- In an instance or an inlined body, there may be inconsistent views of
10510 -- the same type, or of types derived from a common root.
10512 elsif (In_Instance or In_Inlined_Body)
10514 Root_Type (Underlying_Type (Target_Type)) =
10515 Root_Type (Underlying_Type (Opnd_Type))
10519 -- Special check for common access type error case
10521 elsif Ekind (Target_Type) = E_Access_Type
10522 and then Is_Access_Type (Opnd_Type)
10524 Error_Msg_N ("target type must be general access type!", N);
10525 Error_Msg_NE -- CODEFIX
10526 ("add ALL to }!", N, Target_Type);
10530 Error_Msg_NE ("invalid conversion, not compatible with }",
10534 end Valid_Conversion;