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 Snames; use Snames;
72 with Stand; use Stand;
73 with Stringt; use Stringt;
74 with Style; use Style;
75 with Tbuild; use Tbuild;
76 with Uintp; use Uintp;
77 with Urealp; use Urealp;
79 package body Sem_Res is
81 -----------------------
82 -- Local Subprograms --
83 -----------------------
85 -- Second pass (top-down) type checking and overload resolution procedures
86 -- Typ is the type required by context. These procedures propagate the
87 -- type information recursively to the descendants of N. If the node
88 -- is not overloaded, its Etype is established in the first pass. If
89 -- overloaded, the Resolve routines set the correct type. For arith.
90 -- operators, the Etype is the base type of the context.
92 -- Note that Resolve_Attribute is separated off in Sem_Attr
94 procedure Check_Discriminant_Use (N : Node_Id);
95 -- Enforce the restrictions on the use of discriminants when constraining
96 -- a component of a discriminated type (record or concurrent type).
98 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
99 -- Given a node for an operator associated with type T, check that
100 -- the operator is visible. Operators all of whose operands are
101 -- universal must be checked for visibility during resolution
102 -- because their type is not determinable based on their operands.
104 procedure Check_Fully_Declared_Prefix
107 -- Check that the type of the prefix of a dereference is not incomplete
109 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
110 -- Given a call node, N, which is known to occur immediately within the
111 -- subprogram being called, determines whether it is a detectable case of
112 -- an infinite recursion, and if so, outputs appropriate messages. Returns
113 -- True if an infinite recursion is detected, and False otherwise.
115 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
116 -- If the type of the object being initialized uses the secondary stack
117 -- directly or indirectly, create a transient scope for the call to the
118 -- init proc. This is because we do not create transient scopes for the
119 -- initialization of individual components within the init proc itself.
120 -- Could be optimized away perhaps?
122 procedure Check_No_Direct_Boolean_Operators (N : Node_Id);
123 -- N is the node for a logical operator. If the operator is predefined, and
124 -- the root type of the operands is Standard.Boolean, then a check is made
125 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
126 -- the style check for Style_Check_Boolean_And_Or.
128 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
129 -- Determine whether E is an access type declared by an access
130 -- declaration, and not an (anonymous) allocator type.
132 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
133 -- Utility to check whether the name in the call is a predefined
134 -- operator, in which case the call is made into an operator node.
135 -- An instance of an intrinsic conversion operation may be given
136 -- an operator name, but is not treated like an operator.
138 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
139 -- If a default expression in entry call N depends on the discriminants
140 -- of the task, it must be replaced with a reference to the discriminant
141 -- of the task being called.
143 procedure Resolve_Op_Concat_Arg
148 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
149 -- concatenation operator. The operand is either of the array type or of
150 -- the component type. If the operand is an aggregate, and the component
151 -- type is composite, this is ambiguous if component type has aggregates.
153 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
154 -- Does the first part of the work of Resolve_Op_Concat
156 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
157 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
158 -- has been resolved. See Resolve_Op_Concat for details.
160 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
161 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
162 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
163 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
164 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
165 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
166 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
167 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
168 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
169 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id);
170 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
171 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
172 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
173 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
174 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
175 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
176 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
177 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
178 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
179 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
180 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
185 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
186 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
187 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
188 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
189 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
190 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
191 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
192 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
194 function Operator_Kind
196 Is_Binary : Boolean) return Node_Kind;
197 -- Utility to map the name of an operator into the corresponding Node. Used
198 -- by other node rewriting procedures.
200 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
201 -- Resolve actuals of call, and add default expressions for missing ones.
202 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
203 -- called subprogram.
205 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
206 -- Called from Resolve_Call, when the prefix denotes an entry or element
207 -- of entry family. Actuals are resolved as for subprograms, and the node
208 -- is rebuilt as an entry call. Also called for protected operations. Typ
209 -- is the context type, which is used when the operation is a protected
210 -- function with no arguments, and the return value is indexed.
212 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
213 -- A call to a user-defined intrinsic operator is rewritten as a call
214 -- to the corresponding predefined operator, with suitable conversions.
216 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
217 -- Ditto, for unary operators (only arithmetic ones)
219 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
220 -- If an operator node resolves to a call to a user-defined operator,
221 -- rewrite the node as a function call.
223 procedure Make_Call_Into_Operator
227 -- Inverse transformation: if an operator is given in functional notation,
228 -- then after resolving the node, transform into an operator node, so
229 -- that operands are resolved properly. Recall that predefined operators
230 -- do not have a full signature and special resolution rules apply.
232 procedure Rewrite_Renamed_Operator
236 -- An operator can rename another, e.g. in an instantiation. In that
237 -- case, the proper operator node must be constructed and resolved.
239 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
240 -- The String_Literal_Subtype is built for all strings that are not
241 -- operands of a static concatenation operation. If the argument is
242 -- not a N_String_Literal node, then the call has no effect.
244 procedure Set_Slice_Subtype (N : Node_Id);
245 -- Build subtype of array type, with the range specified by the slice
247 procedure Simplify_Type_Conversion (N : Node_Id);
248 -- Called after N has been resolved and evaluated, but before range checks
249 -- have been applied. Currently simplifies a combination of floating-point
250 -- to integer conversion and Truncation attribute.
252 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
253 -- A universal_fixed expression in an universal context is unambiguous
254 -- if there is only one applicable fixed point type. Determining whether
255 -- there is only one requires a search over all visible entities, and
256 -- happens only in very pathological cases (see 6115-006).
258 function Valid_Conversion
261 Operand : Node_Id) return Boolean;
262 -- Verify legality rules given in 4.6 (8-23). Target is the target
263 -- type of the conversion, which may be an implicit conversion of
264 -- an actual parameter to an anonymous access type (in which case
265 -- N denotes the actual parameter and N = Operand).
267 -------------------------
268 -- Ambiguous_Character --
269 -------------------------
271 procedure Ambiguous_Character (C : Node_Id) is
275 if Nkind (C) = N_Character_Literal then
276 Error_Msg_N ("ambiguous character literal", C);
278 -- First the ones in Standard
281 ("\\possible interpretation: Character!", C);
283 ("\\possible interpretation: Wide_Character!", C);
285 -- Include Wide_Wide_Character in Ada 2005 mode
287 if Ada_Version >= Ada_05 then
289 ("\\possible interpretation: Wide_Wide_Character!", C);
292 -- Now any other types that match
294 E := Current_Entity (C);
295 while Present (E) loop
296 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
300 end Ambiguous_Character;
302 -------------------------
303 -- Analyze_And_Resolve --
304 -------------------------
306 procedure Analyze_And_Resolve (N : Node_Id) is
310 end Analyze_And_Resolve;
312 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
316 end Analyze_And_Resolve;
318 -- Version withs check(s) suppressed
320 procedure Analyze_And_Resolve
325 Scop : constant Entity_Id := Current_Scope;
328 if Suppress = All_Checks then
330 Svg : constant Suppress_Array := Scope_Suppress;
332 Scope_Suppress := (others => True);
333 Analyze_And_Resolve (N, Typ);
334 Scope_Suppress := Svg;
339 Svg : constant Boolean := Scope_Suppress (Suppress);
342 Scope_Suppress (Suppress) := True;
343 Analyze_And_Resolve (N, Typ);
344 Scope_Suppress (Suppress) := Svg;
348 if Current_Scope /= Scop
349 and then Scope_Is_Transient
351 -- This can only happen if a transient scope was created
352 -- for an inner expression, which will be removed upon
353 -- completion of the analysis of an enclosing construct.
354 -- The transient scope must have the suppress status of
355 -- the enclosing environment, not of this Analyze call.
357 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
360 end Analyze_And_Resolve;
362 procedure Analyze_And_Resolve
366 Scop : constant Entity_Id := Current_Scope;
369 if Suppress = All_Checks then
371 Svg : constant Suppress_Array := Scope_Suppress;
373 Scope_Suppress := (others => True);
374 Analyze_And_Resolve (N);
375 Scope_Suppress := Svg;
380 Svg : constant Boolean := Scope_Suppress (Suppress);
383 Scope_Suppress (Suppress) := True;
384 Analyze_And_Resolve (N);
385 Scope_Suppress (Suppress) := Svg;
389 if Current_Scope /= Scop
390 and then Scope_Is_Transient
392 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
395 end Analyze_And_Resolve;
397 ----------------------------
398 -- Check_Discriminant_Use --
399 ----------------------------
401 procedure Check_Discriminant_Use (N : Node_Id) is
402 PN : constant Node_Id := Parent (N);
403 Disc : constant Entity_Id := Entity (N);
408 -- Any use in a spec-expression is legal
410 if In_Spec_Expression then
413 elsif Nkind (PN) = N_Range then
415 -- Discriminant cannot be used to constrain a scalar type
419 if Nkind (P) = N_Range_Constraint
420 and then Nkind (Parent (P)) = N_Subtype_Indication
421 and then Nkind (Parent (Parent (P))) = N_Component_Definition
423 Error_Msg_N ("discriminant cannot constrain scalar type", N);
425 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
427 -- The following check catches the unusual case where
428 -- a discriminant appears within an index constraint
429 -- that is part of a larger expression within a constraint
430 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
431 -- For now we only check case of record components, and
432 -- note that a similar check should also apply in the
433 -- case of discriminant constraints below. ???
435 -- Note that the check for N_Subtype_Declaration below is to
436 -- detect the valid use of discriminants in the constraints of a
437 -- subtype declaration when this subtype declaration appears
438 -- inside the scope of a record type (which is syntactically
439 -- illegal, but which may be created as part of derived type
440 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
443 if Ekind (Current_Scope) = E_Record_Type
444 and then Scope (Disc) = Current_Scope
446 (Nkind (Parent (P)) = N_Subtype_Indication
448 Nkind_In (Parent (Parent (P)), N_Component_Definition,
449 N_Subtype_Declaration)
450 and then Paren_Count (N) = 0)
453 ("discriminant must appear alone in component constraint", N);
457 -- Detect a common error:
459 -- type R (D : Positive := 100) is record
460 -- Name : String (1 .. D);
463 -- The default value causes an object of type R to be allocated
464 -- with room for Positive'Last characters. The RM does not mandate
465 -- the allocation of the maximum size, but that is what GNAT does
466 -- so we should warn the programmer that there is a problem.
468 Check_Large : declare
474 function Large_Storage_Type (T : Entity_Id) return Boolean;
475 -- Return True if type T has a large enough range that
476 -- any array whose index type covered the whole range of
477 -- the type would likely raise Storage_Error.
479 ------------------------
480 -- Large_Storage_Type --
481 ------------------------
483 function Large_Storage_Type (T : Entity_Id) return Boolean is
485 -- The type is considered large if its bounds are known at
486 -- compile time and if it requires at least as many bits as
487 -- a Positive to store the possible values.
489 return Compile_Time_Known_Value (Type_Low_Bound (T))
490 and then Compile_Time_Known_Value (Type_High_Bound (T))
492 Minimum_Size (T, Biased => True) >=
493 RM_Size (Standard_Positive);
494 end Large_Storage_Type;
496 -- Start of processing for Check_Large
499 -- Check that the Disc has a large range
501 if not Large_Storage_Type (Etype (Disc)) then
505 -- If the enclosing type is limited, we allocate only the
506 -- default value, not the maximum, and there is no need for
509 if Is_Limited_Type (Scope (Disc)) then
513 -- Check that it is the high bound
515 if N /= High_Bound (PN)
516 or else No (Discriminant_Default_Value (Disc))
521 -- Check the array allows a large range at this bound.
522 -- First find the array
526 if Nkind (SI) /= N_Subtype_Indication then
530 T := Entity (Subtype_Mark (SI));
532 if not Is_Array_Type (T) then
536 -- Next, find the dimension
538 TB := First_Index (T);
539 CB := First (Constraints (P));
541 and then Present (TB)
542 and then Present (CB)
553 -- Now, check the dimension has a large range
555 if not Large_Storage_Type (Etype (TB)) then
559 -- Warn about the danger
562 ("?creation of & object may raise Storage_Error!",
571 -- Legal case is in index or discriminant constraint
573 elsif Nkind_In (PN, N_Index_Or_Discriminant_Constraint,
574 N_Discriminant_Association)
576 if Paren_Count (N) > 0 then
578 ("discriminant in constraint must appear alone", N);
580 elsif Nkind (N) = N_Expanded_Name
581 and then Comes_From_Source (N)
584 ("discriminant must appear alone as a direct name", N);
589 -- Otherwise, context is an expression. It should not be within
590 -- (i.e. a subexpression of) a constraint for a component.
595 while not Nkind_In (P, N_Component_Declaration,
596 N_Subtype_Indication,
604 -- If the discriminant is used in an expression that is a bound
605 -- of a scalar type, an Itype is created and the bounds are attached
606 -- to its range, not to the original subtype indication. Such use
607 -- is of course a double fault.
609 if (Nkind (P) = N_Subtype_Indication
610 and then Nkind_In (Parent (P), N_Component_Definition,
611 N_Derived_Type_Definition)
612 and then D = Constraint (P))
614 -- The constraint itself may be given by a subtype indication,
615 -- rather than by a more common discrete range.
617 or else (Nkind (P) = N_Subtype_Indication
619 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
620 or else Nkind (P) = N_Entry_Declaration
621 or else Nkind (D) = N_Defining_Identifier
624 ("discriminant in constraint must appear alone", N);
627 end Check_Discriminant_Use;
629 --------------------------------
630 -- Check_For_Visible_Operator --
631 --------------------------------
633 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
635 if Is_Invisible_Operator (N, T) then
637 ("operator for} is not directly visible!", N, First_Subtype (T));
638 Error_Msg_N ("use clause would make operation legal!", N);
640 end Check_For_Visible_Operator;
642 ----------------------------------
643 -- Check_Fully_Declared_Prefix --
644 ----------------------------------
646 procedure Check_Fully_Declared_Prefix
651 -- Check that the designated type of the prefix of a dereference is
652 -- not an incomplete type. This cannot be done unconditionally, because
653 -- dereferences of private types are legal in default expressions. This
654 -- case is taken care of in Check_Fully_Declared, called below. There
655 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
657 -- This consideration also applies to similar checks for allocators,
658 -- qualified expressions, and type conversions.
660 -- An additional exception concerns other per-object expressions that
661 -- are not directly related to component declarations, in particular
662 -- representation pragmas for tasks. These will be per-object
663 -- expressions if they depend on discriminants or some global entity.
664 -- If the task has access discriminants, the designated type may be
665 -- incomplete at the point the expression is resolved. This resolution
666 -- takes place within the body of the initialization procedure, where
667 -- the discriminant is replaced by its discriminal.
669 if Is_Entity_Name (Pref)
670 and then Ekind (Entity (Pref)) = E_In_Parameter
674 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
675 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
676 -- Analyze_Object_Renaming, and Freeze_Entity.
678 elsif Ada_Version >= Ada_05
679 and then Is_Entity_Name (Pref)
680 and then Is_Access_Type (Etype (Pref))
681 and then Ekind (Directly_Designated_Type (Etype (Pref))) =
683 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Pref)))
687 Check_Fully_Declared (Typ, Parent (Pref));
689 end Check_Fully_Declared_Prefix;
691 ------------------------------
692 -- Check_Infinite_Recursion --
693 ------------------------------
695 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
699 function Same_Argument_List return Boolean;
700 -- Check whether list of actuals is identical to list of formals
701 -- of called function (which is also the enclosing scope).
703 ------------------------
704 -- Same_Argument_List --
705 ------------------------
707 function Same_Argument_List return Boolean is
713 if not Is_Entity_Name (Name (N)) then
716 Subp := Entity (Name (N));
719 F := First_Formal (Subp);
720 A := First_Actual (N);
721 while Present (F) and then Present (A) loop
722 if not Is_Entity_Name (A)
723 or else Entity (A) /= F
733 end Same_Argument_List;
735 -- Start of processing for Check_Infinite_Recursion
738 -- Special case, if this is a procedure call and is a call to the
739 -- current procedure with the same argument list, then this is for
740 -- sure an infinite recursion and we insert a call to raise SE.
742 if Is_List_Member (N)
743 and then List_Length (List_Containing (N)) = 1
744 and then Same_Argument_List
747 P : constant Node_Id := Parent (N);
749 if Nkind (P) = N_Handled_Sequence_Of_Statements
750 and then Nkind (Parent (P)) = N_Subprogram_Body
751 and then Is_Empty_List (Declarations (Parent (P)))
753 Error_Msg_N ("!?infinite recursion", N);
754 Error_Msg_N ("\!?Storage_Error will be raised at run time", N);
756 Make_Raise_Storage_Error (Sloc (N),
757 Reason => SE_Infinite_Recursion));
763 -- If not that special case, search up tree, quitting if we reach a
764 -- construct (e.g. a conditional) that tells us that this is not a
765 -- case for an infinite recursion warning.
771 -- If no parent, then we were not inside a subprogram, this can for
772 -- example happen when processing certain pragmas in a spec. Just
773 -- return False in this case.
779 -- Done if we get to subprogram body, this is definitely an infinite
780 -- recursion case if we did not find anything to stop us.
782 exit when Nkind (P) = N_Subprogram_Body;
784 -- If appearing in conditional, result is false
786 if Nkind_In (P, N_Or_Else,
793 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
794 and then C /= First (Statements (P))
796 -- If the call is the expression of a return statement and the
797 -- actuals are identical to the formals, it's worth a warning.
798 -- However, we skip this if there is an immediately preceding
799 -- raise statement, since the call is never executed.
801 -- Furthermore, this corresponds to a common idiom:
803 -- function F (L : Thing) return Boolean is
805 -- raise Program_Error;
809 -- for generating a stub function
811 if Nkind (Parent (N)) = N_Simple_Return_Statement
812 and then Same_Argument_List
814 exit when not Is_List_Member (Parent (N));
816 -- OK, return statement is in a statement list, look for raise
822 -- Skip past N_Freeze_Entity nodes generated by expansion
824 Nod := Prev (Parent (N));
826 and then Nkind (Nod) = N_Freeze_Entity
831 -- If no raise statement, give warning
833 exit when Nkind (Nod) /= N_Raise_Statement
835 (Nkind (Nod) not in N_Raise_xxx_Error
836 or else Present (Condition (Nod)));
847 Error_Msg_N ("!?possible infinite recursion", N);
848 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
851 end Check_Infinite_Recursion;
853 -------------------------------
854 -- Check_Initialization_Call --
855 -------------------------------
857 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
858 Typ : constant Entity_Id := Etype (First_Formal (Nam));
860 function Uses_SS (T : Entity_Id) return Boolean;
861 -- Check whether the creation of an object of the type will involve
862 -- use of the secondary stack. If T is a record type, this is true
863 -- if the expression for some component uses the secondary stack, e.g.
864 -- through a call to a function that returns an unconstrained value.
865 -- False if T is controlled, because cleanups occur elsewhere.
871 function Uses_SS (T : Entity_Id) return Boolean is
874 Full_Type : Entity_Id := Underlying_Type (T);
877 -- Normally we want to use the underlying type, but if it's not set
878 -- then continue with T.
880 if not Present (Full_Type) then
884 if Is_Controlled (Full_Type) then
887 elsif Is_Array_Type (Full_Type) then
888 return Uses_SS (Component_Type (Full_Type));
890 elsif Is_Record_Type (Full_Type) then
891 Comp := First_Component (Full_Type);
892 while Present (Comp) loop
893 if Ekind (Comp) = E_Component
894 and then Nkind (Parent (Comp)) = N_Component_Declaration
896 -- The expression for a dynamic component may be rewritten
897 -- as a dereference, so retrieve original node.
899 Expr := Original_Node (Expression (Parent (Comp)));
901 -- Return True if the expression is a call to a function
902 -- (including an attribute function such as Image) with
903 -- a result that requires a transient scope.
905 if (Nkind (Expr) = N_Function_Call
906 or else (Nkind (Expr) = N_Attribute_Reference
907 and then Present (Expressions (Expr))))
908 and then Requires_Transient_Scope (Etype (Expr))
912 elsif Uses_SS (Etype (Comp)) then
917 Next_Component (Comp);
927 -- Start of processing for Check_Initialization_Call
930 -- Establish a transient scope if the type needs it
932 if Uses_SS (Typ) then
933 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
935 end Check_Initialization_Call;
937 ---------------------------------------
938 -- Check_No_Direct_Boolean_Operators --
939 ---------------------------------------
941 procedure Check_No_Direct_Boolean_Operators (N : Node_Id) is
943 if Scope (Entity (N)) = Standard_Standard
944 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
946 -- Restriction only applies to original source code
948 if Comes_From_Source (N) then
949 Check_Restriction (No_Direct_Boolean_Operators, N);
954 Check_Boolean_Operator (N);
956 end Check_No_Direct_Boolean_Operators;
958 ------------------------------
959 -- Check_Parameterless_Call --
960 ------------------------------
962 procedure Check_Parameterless_Call (N : Node_Id) is
965 function Prefix_Is_Access_Subp return Boolean;
966 -- If the prefix is of an access_to_subprogram type, the node must be
967 -- rewritten as a call. Ditto if the prefix is overloaded and all its
968 -- interpretations are access to subprograms.
970 ---------------------------
971 -- Prefix_Is_Access_Subp --
972 ---------------------------
974 function Prefix_Is_Access_Subp return Boolean is
979 if not Is_Overloaded (N) then
981 Ekind (Etype (N)) = E_Subprogram_Type
982 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
984 Get_First_Interp (N, I, It);
985 while Present (It.Typ) loop
986 if Ekind (It.Typ) /= E_Subprogram_Type
987 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
992 Get_Next_Interp (I, It);
997 end Prefix_Is_Access_Subp;
999 -- Start of processing for Check_Parameterless_Call
1002 -- Defend against junk stuff if errors already detected
1004 if Total_Errors_Detected /= 0 then
1005 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
1007 elsif Nkind (N) in N_Has_Chars
1008 and then Chars (N) in Error_Name_Or_No_Name
1016 -- If the context expects a value, and the name is a procedure, this is
1017 -- most likely a missing 'Access. Don't try to resolve the parameterless
1018 -- call, error will be caught when the outer call is analyzed.
1020 if Is_Entity_Name (N)
1021 and then Ekind (Entity (N)) = E_Procedure
1022 and then not Is_Overloaded (N)
1024 Nkind_In (Parent (N), N_Parameter_Association,
1026 N_Procedure_Call_Statement)
1031 -- Rewrite as call if overloadable entity that is (or could be, in the
1032 -- overloaded case) a function call. If we know for sure that the entity
1033 -- is an enumeration literal, we do not rewrite it.
1035 if (Is_Entity_Name (N)
1036 and then Is_Overloadable (Entity (N))
1037 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1038 or else Is_Overloaded (N)))
1040 -- Rewrite as call if it is an explicit dereference of an expression of
1041 -- a subprogram access type, and the subprogram type is not that of a
1042 -- procedure or entry.
1045 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1047 -- Rewrite as call if it is a selected component which is a function,
1048 -- this is the case of a call to a protected function (which may be
1049 -- overloaded with other protected operations).
1052 (Nkind (N) = N_Selected_Component
1053 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1055 ((Ekind (Entity (Selector_Name (N))) = E_Entry
1057 Ekind (Entity (Selector_Name (N))) = E_Procedure)
1058 and then Is_Overloaded (Selector_Name (N)))))
1060 -- If one of the above three conditions is met, rewrite as call.
1061 -- Apply the rewriting only once.
1064 if Nkind (Parent (N)) /= N_Function_Call
1065 or else N /= Name (Parent (N))
1067 Nam := New_Copy (N);
1069 -- If overloaded, overload set belongs to new copy
1071 Save_Interps (N, Nam);
1073 -- Change node to parameterless function call (note that the
1074 -- Parameter_Associations associations field is left set to Empty,
1075 -- its normal default value since there are no parameters)
1077 Change_Node (N, N_Function_Call);
1079 Set_Sloc (N, Sloc (Nam));
1083 elsif Nkind (N) = N_Parameter_Association then
1084 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1086 end Check_Parameterless_Call;
1088 -----------------------------
1089 -- Is_Definite_Access_Type --
1090 -----------------------------
1092 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1093 Btyp : constant Entity_Id := Base_Type (E);
1095 return Ekind (Btyp) = E_Access_Type
1096 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1097 and then Comes_From_Source (Btyp));
1098 end Is_Definite_Access_Type;
1100 ----------------------
1101 -- Is_Predefined_Op --
1102 ----------------------
1104 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1106 return Is_Intrinsic_Subprogram (Nam)
1107 and then not Is_Generic_Instance (Nam)
1108 and then Chars (Nam) in Any_Operator_Name
1109 and then (No (Alias (Nam))
1110 or else Is_Predefined_Op (Alias (Nam)));
1111 end Is_Predefined_Op;
1113 -----------------------------
1114 -- Make_Call_Into_Operator --
1115 -----------------------------
1117 procedure Make_Call_Into_Operator
1122 Op_Name : constant Name_Id := Chars (Op_Id);
1123 Act1 : Node_Id := First_Actual (N);
1124 Act2 : Node_Id := Next_Actual (Act1);
1125 Error : Boolean := False;
1126 Func : constant Entity_Id := Entity (Name (N));
1127 Is_Binary : constant Boolean := Present (Act2);
1129 Opnd_Type : Entity_Id;
1130 Orig_Type : Entity_Id := Empty;
1133 type Kind_Test is access function (E : Entity_Id) return Boolean;
1135 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1136 -- If the operand is not universal, and the operator is given by a
1137 -- expanded name, verify that the operand has an interpretation with
1138 -- a type defined in the given scope of the operator.
1140 function Type_In_P (Test : Kind_Test) return Entity_Id;
1141 -- Find a type of the given class in the package Pack that contains
1144 ---------------------------
1145 -- Operand_Type_In_Scope --
1146 ---------------------------
1148 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1149 Nod : constant Node_Id := Right_Opnd (Op_Node);
1154 if not Is_Overloaded (Nod) then
1155 return Scope (Base_Type (Etype (Nod))) = S;
1158 Get_First_Interp (Nod, I, It);
1159 while Present (It.Typ) loop
1160 if Scope (Base_Type (It.Typ)) = S then
1164 Get_Next_Interp (I, It);
1169 end Operand_Type_In_Scope;
1175 function Type_In_P (Test : Kind_Test) return Entity_Id is
1178 function In_Decl return Boolean;
1179 -- Verify that node is not part of the type declaration for the
1180 -- candidate type, which would otherwise be invisible.
1186 function In_Decl return Boolean is
1187 Decl_Node : constant Node_Id := Parent (E);
1193 if Etype (E) = Any_Type then
1196 elsif No (Decl_Node) then
1201 and then Nkind (N2) /= N_Compilation_Unit
1203 if N2 = Decl_Node then
1214 -- Start of processing for Type_In_P
1217 -- If the context type is declared in the prefix package, this
1218 -- is the desired base type.
1220 if Scope (Base_Type (Typ)) = Pack
1223 return Base_Type (Typ);
1226 E := First_Entity (Pack);
1227 while Present (E) loop
1229 and then not In_Decl
1241 -- Start of processing for Make_Call_Into_Operator
1244 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1249 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1250 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1251 Save_Interps (Act1, Left_Opnd (Op_Node));
1252 Save_Interps (Act2, Right_Opnd (Op_Node));
1253 Act1 := Left_Opnd (Op_Node);
1254 Act2 := Right_Opnd (Op_Node);
1259 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1260 Save_Interps (Act1, Right_Opnd (Op_Node));
1261 Act1 := Right_Opnd (Op_Node);
1264 -- If the operator is denoted by an expanded name, and the prefix is
1265 -- not Standard, but the operator is a predefined one whose scope is
1266 -- Standard, then this is an implicit_operator, inserted as an
1267 -- interpretation by the procedure of the same name. This procedure
1268 -- overestimates the presence of implicit operators, because it does
1269 -- not examine the type of the operands. Verify now that the operand
1270 -- type appears in the given scope. If right operand is universal,
1271 -- check the other operand. In the case of concatenation, either
1272 -- argument can be the component type, so check the type of the result.
1273 -- If both arguments are literals, look for a type of the right kind
1274 -- defined in the given scope. This elaborate nonsense is brought to
1275 -- you courtesy of b33302a. The type itself must be frozen, so we must
1276 -- find the type of the proper class in the given scope.
1278 -- A final wrinkle is the multiplication operator for fixed point
1279 -- types, which is defined in Standard only, and not in the scope of
1280 -- the fixed_point type itself.
1282 if Nkind (Name (N)) = N_Expanded_Name then
1283 Pack := Entity (Prefix (Name (N)));
1285 -- If the entity being called is defined in the given package,
1286 -- it is a renaming of a predefined operator, and known to be
1289 if Scope (Entity (Name (N))) = Pack
1290 and then Pack /= Standard_Standard
1294 -- Visibility does not need to be checked in an instance: if the
1295 -- operator was not visible in the generic it has been diagnosed
1296 -- already, else there is an implicit copy of it in the instance.
1298 elsif In_Instance then
1301 elsif (Op_Name = Name_Op_Multiply
1302 or else Op_Name = Name_Op_Divide)
1303 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1304 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1306 if Pack /= Standard_Standard then
1310 -- Ada 2005, AI-420: Predefined equality on Universal_Access
1313 elsif Ada_Version >= Ada_05
1314 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1315 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1320 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1322 if Op_Name = Name_Op_Concat then
1323 Opnd_Type := Base_Type (Typ);
1325 elsif (Scope (Opnd_Type) = Standard_Standard
1327 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1329 and then not Comes_From_Source (Opnd_Type))
1331 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1334 if Scope (Opnd_Type) = Standard_Standard then
1336 -- Verify that the scope contains a type that corresponds to
1337 -- the given literal. Optimize the case where Pack is Standard.
1339 if Pack /= Standard_Standard then
1341 if Opnd_Type = Universal_Integer then
1342 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1344 elsif Opnd_Type = Universal_Real then
1345 Orig_Type := Type_In_P (Is_Real_Type'Access);
1347 elsif Opnd_Type = Any_String then
1348 Orig_Type := Type_In_P (Is_String_Type'Access);
1350 elsif Opnd_Type = Any_Access then
1351 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1353 elsif Opnd_Type = Any_Composite then
1354 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1356 if Present (Orig_Type) then
1357 if Has_Private_Component (Orig_Type) then
1360 Set_Etype (Act1, Orig_Type);
1363 Set_Etype (Act2, Orig_Type);
1372 Error := No (Orig_Type);
1375 elsif Ekind (Opnd_Type) = E_Allocator_Type
1376 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1380 -- If the type is defined elsewhere, and the operator is not
1381 -- defined in the given scope (by a renaming declaration, e.g.)
1382 -- then this is an error as well. If an extension of System is
1383 -- present, and the type may be defined there, Pack must be
1386 elsif Scope (Opnd_Type) /= Pack
1387 and then Scope (Op_Id) /= Pack
1388 and then (No (System_Aux_Id)
1389 or else Scope (Opnd_Type) /= System_Aux_Id
1390 or else Pack /= Scope (System_Aux_Id))
1392 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1395 Error := not Operand_Type_In_Scope (Pack);
1398 elsif Pack = Standard_Standard
1399 and then not Operand_Type_In_Scope (Standard_Standard)
1406 Error_Msg_Node_2 := Pack;
1408 ("& not declared in&", N, Selector_Name (Name (N)));
1409 Set_Etype (N, Any_Type);
1414 Set_Chars (Op_Node, Op_Name);
1416 if not Is_Private_Type (Etype (N)) then
1417 Set_Etype (Op_Node, Base_Type (Etype (N)));
1419 Set_Etype (Op_Node, Etype (N));
1422 -- If this is a call to a function that renames a predefined equality,
1423 -- the renaming declaration provides a type that must be used to
1424 -- resolve the operands. This must be done now because resolution of
1425 -- the equality node will not resolve any remaining ambiguity, and it
1426 -- assumes that the first operand is not overloaded.
1428 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1429 and then Ekind (Func) = E_Function
1430 and then Is_Overloaded (Act1)
1432 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1433 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1436 Set_Entity (Op_Node, Op_Id);
1437 Generate_Reference (Op_Id, N, ' ');
1439 -- Do rewrite setting Comes_From_Source on the result if the original
1440 -- call came from source. Although it is not strictly the case that the
1441 -- operator as such comes from the source, logically it corresponds
1442 -- exactly to the function call in the source, so it should be marked
1443 -- this way (e.g. to make sure that validity checks work fine).
1446 CS : constant Boolean := Comes_From_Source (N);
1448 Rewrite (N, Op_Node);
1449 Set_Comes_From_Source (N, CS);
1452 -- If this is an arithmetic operator and the result type is private,
1453 -- the operands and the result must be wrapped in conversion to
1454 -- expose the underlying numeric type and expand the proper checks,
1455 -- e.g. on division.
1457 if Is_Private_Type (Typ) then
1459 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1460 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1461 Resolve_Intrinsic_Operator (N, Typ);
1463 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1464 Resolve_Intrinsic_Unary_Operator (N, Typ);
1473 -- For predefined operators on literals, the operation freezes
1476 if Present (Orig_Type) then
1477 Set_Etype (Act1, Orig_Type);
1478 Freeze_Expression (Act1);
1480 end Make_Call_Into_Operator;
1486 function Operator_Kind
1488 Is_Binary : Boolean) return Node_Kind
1494 if Op_Name = Name_Op_And then
1496 elsif Op_Name = Name_Op_Or then
1498 elsif Op_Name = Name_Op_Xor then
1500 elsif Op_Name = Name_Op_Eq then
1502 elsif Op_Name = Name_Op_Ne then
1504 elsif Op_Name = Name_Op_Lt then
1506 elsif Op_Name = Name_Op_Le then
1508 elsif Op_Name = Name_Op_Gt then
1510 elsif Op_Name = Name_Op_Ge then
1512 elsif Op_Name = Name_Op_Add then
1514 elsif Op_Name = Name_Op_Subtract then
1515 Kind := N_Op_Subtract;
1516 elsif Op_Name = Name_Op_Concat then
1517 Kind := N_Op_Concat;
1518 elsif Op_Name = Name_Op_Multiply then
1519 Kind := N_Op_Multiply;
1520 elsif Op_Name = Name_Op_Divide then
1521 Kind := N_Op_Divide;
1522 elsif Op_Name = Name_Op_Mod then
1524 elsif Op_Name = Name_Op_Rem then
1526 elsif Op_Name = Name_Op_Expon then
1529 raise Program_Error;
1535 if Op_Name = Name_Op_Add then
1537 elsif Op_Name = Name_Op_Subtract then
1539 elsif Op_Name = Name_Op_Abs then
1541 elsif Op_Name = Name_Op_Not then
1544 raise Program_Error;
1551 ----------------------------
1552 -- Preanalyze_And_Resolve --
1553 ----------------------------
1555 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1556 Save_Full_Analysis : constant Boolean := Full_Analysis;
1559 Full_Analysis := False;
1560 Expander_Mode_Save_And_Set (False);
1562 -- We suppress all checks for this analysis, since the checks will
1563 -- be applied properly, and in the right location, when the default
1564 -- expression is reanalyzed and reexpanded later on.
1566 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1568 Expander_Mode_Restore;
1569 Full_Analysis := Save_Full_Analysis;
1570 end Preanalyze_And_Resolve;
1572 -- Version without context type
1574 procedure Preanalyze_And_Resolve (N : Node_Id) is
1575 Save_Full_Analysis : constant Boolean := Full_Analysis;
1578 Full_Analysis := False;
1579 Expander_Mode_Save_And_Set (False);
1582 Resolve (N, Etype (N), Suppress => All_Checks);
1584 Expander_Mode_Restore;
1585 Full_Analysis := Save_Full_Analysis;
1586 end Preanalyze_And_Resolve;
1588 ----------------------------------
1589 -- Replace_Actual_Discriminants --
1590 ----------------------------------
1592 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1593 Loc : constant Source_Ptr := Sloc (N);
1594 Tsk : Node_Id := Empty;
1596 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1602 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1606 if Nkind (Nod) = N_Identifier then
1607 Ent := Entity (Nod);
1610 and then Ekind (Ent) = E_Discriminant
1613 Make_Selected_Component (Loc,
1614 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1615 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1617 Set_Etype (Nod, Etype (Ent));
1625 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1627 -- Start of processing for Replace_Actual_Discriminants
1630 if not Expander_Active then
1634 if Nkind (Name (N)) = N_Selected_Component then
1635 Tsk := Prefix (Name (N));
1637 elsif Nkind (Name (N)) = N_Indexed_Component then
1638 Tsk := Prefix (Prefix (Name (N)));
1644 Replace_Discrs (Default);
1646 end Replace_Actual_Discriminants;
1652 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1653 Ambiguous : Boolean := False;
1654 Ctx_Type : Entity_Id := Typ;
1655 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1656 Err_Type : Entity_Id := Empty;
1657 Found : Boolean := False;
1660 I1 : Interp_Index := 0; -- prevent junk warning
1663 Seen : Entity_Id := Empty; -- prevent junk warning
1665 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1666 -- Determine whether a node comes from a predefined library unit or
1669 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1670 -- Try and fix up a literal so that it matches its expected type. New
1671 -- literals are manufactured if necessary to avoid cascaded errors.
1673 procedure Report_Ambiguous_Argument;
1674 -- Additional diagnostics when an ambiguous call has an ambiguous
1675 -- argument (typically a controlling actual).
1677 procedure Resolution_Failed;
1678 -- Called when attempt at resolving current expression fails
1680 ------------------------------------
1681 -- Comes_From_Predefined_Lib_Unit --
1682 -------------------------------------
1684 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1687 Sloc (Nod) = Standard_Location
1688 or else Is_Predefined_File_Name (Unit_File_Name (
1689 Get_Source_Unit (Sloc (Nod))));
1690 end Comes_From_Predefined_Lib_Unit;
1692 --------------------
1693 -- Patch_Up_Value --
1694 --------------------
1696 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1698 if Nkind (N) = N_Integer_Literal
1699 and then Is_Real_Type (Typ)
1702 Make_Real_Literal (Sloc (N),
1703 Realval => UR_From_Uint (Intval (N))));
1704 Set_Etype (N, Universal_Real);
1705 Set_Is_Static_Expression (N);
1707 elsif Nkind (N) = N_Real_Literal
1708 and then Is_Integer_Type (Typ)
1711 Make_Integer_Literal (Sloc (N),
1712 Intval => UR_To_Uint (Realval (N))));
1713 Set_Etype (N, Universal_Integer);
1714 Set_Is_Static_Expression (N);
1716 elsif Nkind (N) = N_String_Literal
1717 and then Is_Character_Type (Typ)
1719 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1721 Make_Character_Literal (Sloc (N),
1723 Char_Literal_Value =>
1724 UI_From_Int (Character'Pos ('A'))));
1725 Set_Etype (N, Any_Character);
1726 Set_Is_Static_Expression (N);
1728 elsif Nkind (N) /= N_String_Literal
1729 and then Is_String_Type (Typ)
1732 Make_String_Literal (Sloc (N),
1733 Strval => End_String));
1735 elsif Nkind (N) = N_Range then
1736 Patch_Up_Value (Low_Bound (N), Typ);
1737 Patch_Up_Value (High_Bound (N), Typ);
1741 -------------------------------
1742 -- Report_Ambiguous_Argument --
1743 -------------------------------
1745 procedure Report_Ambiguous_Argument is
1746 Arg : constant Node_Id := First (Parameter_Associations (N));
1751 if Nkind (Arg) = N_Function_Call
1752 and then Is_Entity_Name (Name (Arg))
1753 and then Is_Overloaded (Name (Arg))
1755 Error_Msg_NE ("ambiguous call to&", Arg, Name (Arg));
1757 -- Could use comments on what is going on here ???
1759 Get_First_Interp (Name (Arg), I, It);
1760 while Present (It.Nam) loop
1761 Error_Msg_Sloc := Sloc (It.Nam);
1763 if Nkind (Parent (It.Nam)) = N_Full_Type_Declaration then
1764 Error_Msg_N ("interpretation (inherited) #!", Arg);
1766 Error_Msg_N ("interpretation #!", Arg);
1769 Get_Next_Interp (I, It);
1772 end Report_Ambiguous_Argument;
1774 -----------------------
1775 -- Resolution_Failed --
1776 -----------------------
1778 procedure Resolution_Failed is
1780 Patch_Up_Value (N, Typ);
1782 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1783 Set_Is_Overloaded (N, False);
1785 -- The caller will return without calling the expander, so we need
1786 -- to set the analyzed flag. Note that it is fine to set Analyzed
1787 -- to True even if we are in the middle of a shallow analysis,
1788 -- (see the spec of sem for more details) since this is an error
1789 -- situation anyway, and there is no point in repeating the
1790 -- analysis later (indeed it won't work to repeat it later, since
1791 -- we haven't got a clear resolution of which entity is being
1794 Set_Analyzed (N, True);
1796 end Resolution_Failed;
1798 -- Start of processing for Resolve
1805 -- Access attribute on remote subprogram cannot be used for
1806 -- a non-remote access-to-subprogram type.
1808 if Nkind (N) = N_Attribute_Reference
1809 and then (Attribute_Name (N) = Name_Access
1810 or else Attribute_Name (N) = Name_Unrestricted_Access
1811 or else Attribute_Name (N) = Name_Unchecked_Access)
1812 and then Comes_From_Source (N)
1813 and then Is_Entity_Name (Prefix (N))
1814 and then Is_Subprogram (Entity (Prefix (N)))
1815 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1816 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1819 ("prefix must statically denote a non-remote subprogram", N);
1822 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1824 -- If the context is a Remote_Access_To_Subprogram, access attributes
1825 -- must be resolved with the corresponding fat pointer. There is no need
1826 -- to check for the attribute name since the return type of an
1827 -- attribute is never a remote type.
1829 if Nkind (N) = N_Attribute_Reference
1830 and then Comes_From_Source (N)
1831 and then (Is_Remote_Call_Interface (Typ)
1832 or else Is_Remote_Types (Typ))
1835 Attr : constant Attribute_Id :=
1836 Get_Attribute_Id (Attribute_Name (N));
1837 Pref : constant Node_Id := Prefix (N);
1840 Is_Remote : Boolean := True;
1843 -- Check that Typ is a remote access-to-subprogram type
1845 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1847 -- Prefix (N) must statically denote a remote subprogram
1848 -- declared in a package specification.
1850 if Attr = Attribute_Access then
1851 Decl := Unit_Declaration_Node (Entity (Pref));
1853 if Nkind (Decl) = N_Subprogram_Body then
1854 Spec := Corresponding_Spec (Decl);
1856 if not No (Spec) then
1857 Decl := Unit_Declaration_Node (Spec);
1861 Spec := Parent (Decl);
1863 if not Is_Entity_Name (Prefix (N))
1864 or else Nkind (Spec) /= N_Package_Specification
1866 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1870 ("prefix must statically denote a remote subprogram ",
1875 -- If we are generating code for a distributed program.
1876 -- perform semantic checks against the corresponding
1879 if (Attr = Attribute_Access
1880 or else Attr = Attribute_Unchecked_Access
1881 or else Attr = Attribute_Unrestricted_Access)
1882 and then Expander_Active
1883 and then Get_PCS_Name /= Name_No_DSA
1885 Check_Subtype_Conformant
1886 (New_Id => Entity (Prefix (N)),
1887 Old_Id => Designated_Type
1888 (Corresponding_Remote_Type (Typ)),
1892 Process_Remote_AST_Attribute (N, Typ);
1899 Debug_A_Entry ("resolving ", N);
1901 if Comes_From_Source (N) then
1902 if Is_Fixed_Point_Type (Typ) then
1903 Check_Restriction (No_Fixed_Point, N);
1905 elsif Is_Floating_Point_Type (Typ)
1906 and then Typ /= Universal_Real
1907 and then Typ /= Any_Real
1909 Check_Restriction (No_Floating_Point, N);
1913 -- Return if already analyzed
1915 if Analyzed (N) then
1916 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1919 -- Return if type = Any_Type (previous error encountered)
1921 elsif Etype (N) = Any_Type then
1922 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1926 Check_Parameterless_Call (N);
1928 -- If not overloaded, then we know the type, and all that needs doing
1929 -- is to check that this type is compatible with the context.
1931 if not Is_Overloaded (N) then
1932 Found := Covers (Typ, Etype (N));
1933 Expr_Type := Etype (N);
1935 -- In the overloaded case, we must select the interpretation that
1936 -- is compatible with the context (i.e. the type passed to Resolve)
1939 -- Loop through possible interpretations
1941 Get_First_Interp (N, I, It);
1942 Interp_Loop : while Present (It.Typ) loop
1944 -- We are only interested in interpretations that are compatible
1945 -- with the expected type, any other interpretations are ignored.
1947 if not Covers (Typ, It.Typ) then
1948 if Debug_Flag_V then
1949 Write_Str (" interpretation incompatible with context");
1954 -- Skip the current interpretation if it is disabled by an
1955 -- abstract operator. This action is performed only when the
1956 -- type against which we are resolving is the same as the
1957 -- type of the interpretation.
1959 if Ada_Version >= Ada_05
1960 and then It.Typ = Typ
1961 and then Typ /= Universal_Integer
1962 and then Typ /= Universal_Real
1963 and then Present (It.Abstract_Op)
1968 -- First matching interpretation
1974 Expr_Type := It.Typ;
1976 -- Matching interpretation that is not the first, maybe an
1977 -- error, but there are some cases where preference rules are
1978 -- used to choose between the two possibilities. These and
1979 -- some more obscure cases are handled in Disambiguate.
1982 -- If the current statement is part of a predefined library
1983 -- unit, then all interpretations which come from user level
1984 -- packages should not be considered.
1987 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
1992 Error_Msg_Sloc := Sloc (Seen);
1993 It1 := Disambiguate (N, I1, I, Typ);
1995 -- Disambiguation has succeeded. Skip the remaining
1998 if It1 /= No_Interp then
2000 Expr_Type := It1.Typ;
2002 while Present (It.Typ) loop
2003 Get_Next_Interp (I, It);
2007 -- Before we issue an ambiguity complaint, check for
2008 -- the case of a subprogram call where at least one
2009 -- of the arguments is Any_Type, and if so, suppress
2010 -- the message, since it is a cascaded error.
2012 if Nkind_In (N, N_Function_Call,
2013 N_Procedure_Call_Statement)
2020 A := First_Actual (N);
2021 while Present (A) loop
2024 if Nkind (E) = N_Parameter_Association then
2025 E := Explicit_Actual_Parameter (E);
2028 if Etype (E) = Any_Type then
2029 if Debug_Flag_V then
2030 Write_Str ("Any_Type in call");
2041 elsif Nkind (N) in N_Binary_Op
2042 and then (Etype (Left_Opnd (N)) = Any_Type
2043 or else Etype (Right_Opnd (N)) = Any_Type)
2047 elsif Nkind (N) in N_Unary_Op
2048 and then Etype (Right_Opnd (N)) = Any_Type
2053 -- Not that special case, so issue message using the
2054 -- flag Ambiguous to control printing of the header
2055 -- message only at the start of an ambiguous set.
2057 if not Ambiguous then
2058 if Nkind (N) = N_Function_Call
2059 and then Nkind (Name (N)) = N_Explicit_Dereference
2062 ("ambiguous expression "
2063 & "(cannot resolve indirect call)!", N);
2065 Error_Msg_NE -- CODEFIX
2066 ("ambiguous expression (cannot resolve&)!",
2072 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2074 ("\\possible interpretation (inherited)#!", N);
2076 Error_Msg_N -- CODEFIX
2077 ("\\possible interpretation#!", N);
2081 (N, N_Procedure_Call_Statement, N_Function_Call)
2082 and then Present (Parameter_Associations (N))
2084 Report_Ambiguous_Argument;
2088 Error_Msg_Sloc := Sloc (It.Nam);
2090 -- By default, the error message refers to the candidate
2091 -- interpretation. But if it is a predefined operator, it
2092 -- is implicitly declared at the declaration of the type
2093 -- of the operand. Recover the sloc of that declaration
2094 -- for the error message.
2096 if Nkind (N) in N_Op
2097 and then Scope (It.Nam) = Standard_Standard
2098 and then not Is_Overloaded (Right_Opnd (N))
2099 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2102 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2104 if Comes_From_Source (Err_Type)
2105 and then Present (Parent (Err_Type))
2107 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2110 elsif Nkind (N) in N_Binary_Op
2111 and then Scope (It.Nam) = Standard_Standard
2112 and then not Is_Overloaded (Left_Opnd (N))
2113 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2116 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2118 if Comes_From_Source (Err_Type)
2119 and then Present (Parent (Err_Type))
2121 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2124 -- If this is an indirect call, use the subprogram_type
2125 -- in the message, to have a meaningful location.
2126 -- Also indicate if this is an inherited operation,
2127 -- created by a type declaration.
2129 elsif Nkind (N) = N_Function_Call
2130 and then Nkind (Name (N)) = N_Explicit_Dereference
2131 and then Is_Type (It.Nam)
2135 Sloc (Associated_Node_For_Itype (Err_Type));
2140 if Nkind (N) in N_Op
2141 and then Scope (It.Nam) = Standard_Standard
2142 and then Present (Err_Type)
2144 -- Special-case the message for universal_fixed
2145 -- operators, which are not declared with the type
2146 -- of the operand, but appear forever in Standard.
2148 if It.Typ = Universal_Fixed
2149 and then Scope (It.Nam) = Standard_Standard
2152 ("\\possible interpretation as " &
2153 "universal_fixed operation " &
2154 "(RM 4.5.5 (19))", N);
2157 ("\\possible interpretation (predefined)#!", N);
2161 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2164 ("\\possible interpretation (inherited)#!", N);
2166 Error_Msg_N -- CODEFIX
2167 ("\\possible interpretation#!", N);
2173 -- We have a matching interpretation, Expr_Type is the type
2174 -- from this interpretation, and Seen is the entity.
2176 -- For an operator, just set the entity name. The type will be
2177 -- set by the specific operator resolution routine.
2179 if Nkind (N) in N_Op then
2180 Set_Entity (N, Seen);
2181 Generate_Reference (Seen, N);
2183 elsif Nkind (N) = N_Character_Literal then
2184 Set_Etype (N, Expr_Type);
2186 elsif Nkind (N) = N_Conditional_Expression then
2187 Set_Etype (N, Expr_Type);
2189 -- For an explicit dereference, attribute reference, range,
2190 -- short-circuit form (which is not an operator node), or call
2191 -- with a name that is an explicit dereference, there is
2192 -- nothing to be done at this point.
2194 elsif Nkind_In (N, N_Explicit_Dereference,
2195 N_Attribute_Reference,
2197 N_Indexed_Component,
2200 N_Selected_Component,
2202 or else Nkind (Name (N)) = N_Explicit_Dereference
2206 -- For procedure or function calls, set the type of the name,
2207 -- and also the entity pointer for the prefix.
2209 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2210 and then (Is_Entity_Name (Name (N))
2211 or else Nkind (Name (N)) = N_Operator_Symbol)
2213 Set_Etype (Name (N), Expr_Type);
2214 Set_Entity (Name (N), Seen);
2215 Generate_Reference (Seen, Name (N));
2217 elsif Nkind (N) = N_Function_Call
2218 and then Nkind (Name (N)) = N_Selected_Component
2220 Set_Etype (Name (N), Expr_Type);
2221 Set_Entity (Selector_Name (Name (N)), Seen);
2222 Generate_Reference (Seen, Selector_Name (Name (N)));
2224 -- For all other cases, just set the type of the Name
2227 Set_Etype (Name (N), Expr_Type);
2234 -- Move to next interpretation
2236 exit Interp_Loop when No (It.Typ);
2238 Get_Next_Interp (I, It);
2239 end loop Interp_Loop;
2242 -- At this stage Found indicates whether or not an acceptable
2243 -- interpretation exists. If not, then we have an error, except that if
2244 -- the context is Any_Type as a result of some other error, then we
2245 -- suppress the error report.
2248 if Typ /= Any_Type then
2250 -- If type we are looking for is Void, then this is the procedure
2251 -- call case, and the error is simply that what we gave is not a
2252 -- procedure name (we think of procedure calls as expressions with
2253 -- types internally, but the user doesn't think of them this way!)
2255 if Typ = Standard_Void_Type then
2257 -- Special case message if function used as a procedure
2259 if Nkind (N) = N_Procedure_Call_Statement
2260 and then Is_Entity_Name (Name (N))
2261 and then Ekind (Entity (Name (N))) = E_Function
2264 ("cannot use function & in a procedure call",
2265 Name (N), Entity (Name (N)));
2267 -- Otherwise give general message (not clear what cases this
2268 -- covers, but no harm in providing for them!)
2271 Error_Msg_N ("expect procedure name in procedure call", N);
2276 -- Otherwise we do have a subexpression with the wrong type
2278 -- Check for the case of an allocator which uses an access type
2279 -- instead of the designated type. This is a common error and we
2280 -- specialize the message, posting an error on the operand of the
2281 -- allocator, complaining that we expected the designated type of
2284 elsif Nkind (N) = N_Allocator
2285 and then Ekind (Typ) in Access_Kind
2286 and then Ekind (Etype (N)) in Access_Kind
2287 and then Designated_Type (Etype (N)) = Typ
2289 Wrong_Type (Expression (N), Designated_Type (Typ));
2292 -- Check for view mismatch on Null in instances, for which the
2293 -- view-swapping mechanism has no identifier.
2295 elsif (In_Instance or else In_Inlined_Body)
2296 and then (Nkind (N) = N_Null)
2297 and then Is_Private_Type (Typ)
2298 and then Is_Access_Type (Full_View (Typ))
2300 Resolve (N, Full_View (Typ));
2304 -- Check for an aggregate. Sometimes we can get bogus aggregates
2305 -- from misuse of parentheses, and we are about to complain about
2306 -- the aggregate without even looking inside it.
2308 -- Instead, if we have an aggregate of type Any_Composite, then
2309 -- analyze and resolve the component fields, and then only issue
2310 -- another message if we get no errors doing this (otherwise
2311 -- assume that the errors in the aggregate caused the problem).
2313 elsif Nkind (N) = N_Aggregate
2314 and then Etype (N) = Any_Composite
2316 -- Disable expansion in any case. If there is a type mismatch
2317 -- it may be fatal to try to expand the aggregate. The flag
2318 -- would otherwise be set to false when the error is posted.
2320 Expander_Active := False;
2323 procedure Check_Aggr (Aggr : Node_Id);
2324 -- Check one aggregate, and set Found to True if we have a
2325 -- definite error in any of its elements
2327 procedure Check_Elmt (Aelmt : Node_Id);
2328 -- Check one element of aggregate and set Found to True if
2329 -- we definitely have an error in the element.
2335 procedure Check_Aggr (Aggr : Node_Id) is
2339 if Present (Expressions (Aggr)) then
2340 Elmt := First (Expressions (Aggr));
2341 while Present (Elmt) loop
2347 if Present (Component_Associations (Aggr)) then
2348 Elmt := First (Component_Associations (Aggr));
2349 while Present (Elmt) loop
2351 -- If this is a default-initialized component, then
2352 -- there is nothing to check. The box will be
2353 -- replaced by the appropriate call during late
2356 if not Box_Present (Elmt) then
2357 Check_Elmt (Expression (Elmt));
2369 procedure Check_Elmt (Aelmt : Node_Id) is
2371 -- If we have a nested aggregate, go inside it (to
2372 -- attempt a naked analyze-resolve of the aggregate
2373 -- can cause undesirable cascaded errors). Do not
2374 -- resolve expression if it needs a type from context,
2375 -- as for integer * fixed expression.
2377 if Nkind (Aelmt) = N_Aggregate then
2383 if not Is_Overloaded (Aelmt)
2384 and then Etype (Aelmt) /= Any_Fixed
2389 if Etype (Aelmt) = Any_Type then
2400 -- If an error message was issued already, Found got reset
2401 -- to True, so if it is still False, issue the standard
2402 -- Wrong_Type message.
2405 if Is_Overloaded (N)
2406 and then Nkind (N) = N_Function_Call
2409 Subp_Name : Node_Id;
2411 if Is_Entity_Name (Name (N)) then
2412 Subp_Name := Name (N);
2414 elsif Nkind (Name (N)) = N_Selected_Component then
2416 -- Protected operation: retrieve operation name
2418 Subp_Name := Selector_Name (Name (N));
2420 raise Program_Error;
2423 Error_Msg_Node_2 := Typ;
2424 Error_Msg_NE ("no visible interpretation of&" &
2425 " matches expected type&", N, Subp_Name);
2428 if All_Errors_Mode then
2430 Index : Interp_Index;
2434 Error_Msg_N ("\\possible interpretations:", N);
2436 Get_First_Interp (Name (N), Index, It);
2437 while Present (It.Nam) loop
2438 Error_Msg_Sloc := Sloc (It.Nam);
2439 Error_Msg_Node_2 := It.Nam;
2441 ("\\ type& for & declared#", N, It.Typ);
2442 Get_Next_Interp (Index, It);
2447 Error_Msg_N ("\use -gnatf for details", N);
2450 Wrong_Type (N, Typ);
2458 -- Test if we have more than one interpretation for the context
2460 elsif Ambiguous then
2464 -- Here we have an acceptable interpretation for the context
2467 -- Propagate type information and normalize tree for various
2468 -- predefined operations. If the context only imposes a class of
2469 -- types, rather than a specific type, propagate the actual type
2472 if Typ = Any_Integer
2473 or else Typ = Any_Boolean
2474 or else Typ = Any_Modular
2475 or else Typ = Any_Real
2476 or else Typ = Any_Discrete
2478 Ctx_Type := Expr_Type;
2480 -- Any_Fixed is legal in a real context only if a specific
2481 -- fixed point type is imposed. If Norman Cohen can be
2482 -- confused by this, it deserves a separate message.
2485 and then Expr_Type = Any_Fixed
2487 Error_Msg_N ("illegal context for mixed mode operation", N);
2488 Set_Etype (N, Universal_Real);
2489 Ctx_Type := Universal_Real;
2493 -- A user-defined operator is transformed into a function call at
2494 -- this point, so that further processing knows that operators are
2495 -- really operators (i.e. are predefined operators). User-defined
2496 -- operators that are intrinsic are just renamings of the predefined
2497 -- ones, and need not be turned into calls either, but if they rename
2498 -- a different operator, we must transform the node accordingly.
2499 -- Instantiations of Unchecked_Conversion are intrinsic but are
2500 -- treated as functions, even if given an operator designator.
2502 if Nkind (N) in N_Op
2503 and then Present (Entity (N))
2504 and then Ekind (Entity (N)) /= E_Operator
2507 if not Is_Predefined_Op (Entity (N)) then
2508 Rewrite_Operator_As_Call (N, Entity (N));
2510 elsif Present (Alias (Entity (N)))
2512 Nkind (Parent (Parent (Entity (N)))) =
2513 N_Subprogram_Renaming_Declaration
2515 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2517 -- If the node is rewritten, it will be fully resolved in
2518 -- Rewrite_Renamed_Operator.
2520 if Analyzed (N) then
2526 case N_Subexpr'(Nkind (N)) is
2528 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2530 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2532 when N_Short_Circuit
2533 => Resolve_Short_Circuit (N, Ctx_Type);
2535 when N_Attribute_Reference
2536 => Resolve_Attribute (N, Ctx_Type);
2538 when N_Character_Literal
2539 => Resolve_Character_Literal (N, Ctx_Type);
2541 when N_Conditional_Expression
2542 => Resolve_Conditional_Expression (N, Ctx_Type);
2544 when N_Expanded_Name
2545 => Resolve_Entity_Name (N, Ctx_Type);
2547 when N_Explicit_Dereference
2548 => Resolve_Explicit_Dereference (N, Ctx_Type);
2550 when N_Expression_With_Actions
2551 => Resolve_Expression_With_Actions (N, Ctx_Type);
2553 when N_Extension_Aggregate
2554 => Resolve_Extension_Aggregate (N, Ctx_Type);
2556 when N_Function_Call
2557 => Resolve_Call (N, Ctx_Type);
2560 => Resolve_Entity_Name (N, Ctx_Type);
2562 when N_Indexed_Component
2563 => Resolve_Indexed_Component (N, Ctx_Type);
2565 when N_Integer_Literal
2566 => Resolve_Integer_Literal (N, Ctx_Type);
2568 when N_Membership_Test
2569 => Resolve_Membership_Op (N, Ctx_Type);
2571 when N_Null => Resolve_Null (N, Ctx_Type);
2573 when N_Op_And | N_Op_Or | N_Op_Xor
2574 => Resolve_Logical_Op (N, Ctx_Type);
2576 when N_Op_Eq | N_Op_Ne
2577 => Resolve_Equality_Op (N, Ctx_Type);
2579 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2580 => Resolve_Comparison_Op (N, Ctx_Type);
2582 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2584 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2585 N_Op_Divide | N_Op_Mod | N_Op_Rem
2587 => Resolve_Arithmetic_Op (N, Ctx_Type);
2589 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2591 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2593 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2594 => Resolve_Unary_Op (N, Ctx_Type);
2596 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2598 when N_Procedure_Call_Statement
2599 => Resolve_Call (N, Ctx_Type);
2601 when N_Operator_Symbol
2602 => Resolve_Operator_Symbol (N, Ctx_Type);
2604 when N_Qualified_Expression
2605 => Resolve_Qualified_Expression (N, Ctx_Type);
2607 when N_Raise_xxx_Error
2608 => Set_Etype (N, Ctx_Type);
2610 when N_Range => Resolve_Range (N, Ctx_Type);
2613 => Resolve_Real_Literal (N, Ctx_Type);
2615 when N_Reference => Resolve_Reference (N, Ctx_Type);
2617 when N_Selected_Component
2618 => Resolve_Selected_Component (N, Ctx_Type);
2620 when N_Slice => Resolve_Slice (N, Ctx_Type);
2622 when N_String_Literal
2623 => Resolve_String_Literal (N, Ctx_Type);
2625 when N_Subprogram_Info
2626 => Resolve_Subprogram_Info (N, Ctx_Type);
2628 when N_Type_Conversion
2629 => Resolve_Type_Conversion (N, Ctx_Type);
2631 when N_Unchecked_Expression =>
2632 Resolve_Unchecked_Expression (N, Ctx_Type);
2634 when N_Unchecked_Type_Conversion =>
2635 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2639 -- If the subexpression was replaced by a non-subexpression, then
2640 -- all we do is to expand it. The only legitimate case we know of
2641 -- is converting procedure call statement to entry call statements,
2642 -- but there may be others, so we are making this test general.
2644 if Nkind (N) not in N_Subexpr then
2645 Debug_A_Exit ("resolving ", N, " (done)");
2650 -- The expression is definitely NOT overloaded at this point, so
2651 -- we reset the Is_Overloaded flag to avoid any confusion when
2652 -- reanalyzing the node.
2654 Set_Is_Overloaded (N, False);
2656 -- Freeze expression type, entity if it is a name, and designated
2657 -- type if it is an allocator (RM 13.14(10,11,13)).
2659 -- Now that the resolution of the type of the node is complete,
2660 -- and we did not detect an error, we can expand this node. We
2661 -- skip the expand call if we are in a default expression, see
2662 -- section "Handling of Default Expressions" in Sem spec.
2664 Debug_A_Exit ("resolving ", N, " (done)");
2666 -- We unconditionally freeze the expression, even if we are in
2667 -- default expression mode (the Freeze_Expression routine tests
2668 -- this flag and only freezes static types if it is set).
2670 Freeze_Expression (N);
2672 -- Now we can do the expansion
2682 -- Version with check(s) suppressed
2684 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2686 if Suppress = All_Checks then
2688 Svg : constant Suppress_Array := Scope_Suppress;
2690 Scope_Suppress := (others => True);
2692 Scope_Suppress := Svg;
2697 Svg : constant Boolean := Scope_Suppress (Suppress);
2699 Scope_Suppress (Suppress) := True;
2701 Scope_Suppress (Suppress) := Svg;
2710 -- Version with implicit type
2712 procedure Resolve (N : Node_Id) is
2714 Resolve (N, Etype (N));
2717 ---------------------
2718 -- Resolve_Actuals --
2719 ---------------------
2721 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2722 Loc : constant Source_Ptr := Sloc (N);
2727 Prev : Node_Id := Empty;
2730 procedure Check_Argument_Order;
2731 -- Performs a check for the case where the actuals are all simple
2732 -- identifiers that correspond to the formal names, but in the wrong
2733 -- order, which is considered suspicious and cause for a warning.
2735 procedure Check_Prefixed_Call;
2736 -- If the original node is an overloaded call in prefix notation,
2737 -- insert an 'Access or a dereference as needed over the first actual.
2738 -- Try_Object_Operation has already verified that there is a valid
2739 -- interpretation, but the form of the actual can only be determined
2740 -- once the primitive operation is identified.
2742 procedure Insert_Default;
2743 -- If the actual is missing in a call, insert in the actuals list
2744 -- an instance of the default expression. The insertion is always
2745 -- a named association.
2747 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2748 -- Check whether T1 and T2, or their full views, are derived from a
2749 -- common type. Used to enforce the restrictions on array conversions
2752 function Static_Concatenation (N : Node_Id) return Boolean;
2753 -- Predicate to determine whether an actual that is a concatenation
2754 -- will be evaluated statically and does not need a transient scope.
2755 -- This must be determined before the actual is resolved and expanded
2756 -- because if needed the transient scope must be introduced earlier.
2758 --------------------------
2759 -- Check_Argument_Order --
2760 --------------------------
2762 procedure Check_Argument_Order is
2764 -- Nothing to do if no parameters, or original node is neither a
2765 -- function call nor a procedure call statement (happens in the
2766 -- operator-transformed-to-function call case), or the call does
2767 -- not come from source, or this warning is off.
2769 if not Warn_On_Parameter_Order
2771 No (Parameter_Associations (N))
2773 not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2776 not Comes_From_Source (N)
2782 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2785 -- Nothing to do if only one parameter
2791 -- Here if at least two arguments
2794 Actuals : array (1 .. Nargs) of Node_Id;
2798 Wrong_Order : Boolean := False;
2799 -- Set True if an out of order case is found
2802 -- Collect identifier names of actuals, fail if any actual is
2803 -- not a simple identifier, and record max length of name.
2805 Actual := First (Parameter_Associations (N));
2806 for J in Actuals'Range loop
2807 if Nkind (Actual) /= N_Identifier then
2810 Actuals (J) := Actual;
2815 -- If we got this far, all actuals are identifiers and the list
2816 -- of their names is stored in the Actuals array.
2818 Formal := First_Formal (Nam);
2819 for J in Actuals'Range loop
2821 -- If we ran out of formals, that's odd, probably an error
2822 -- which will be detected elsewhere, but abandon the search.
2828 -- If name matches and is in order OK
2830 if Chars (Formal) = Chars (Actuals (J)) then
2834 -- If no match, see if it is elsewhere in list and if so
2835 -- flag potential wrong order if type is compatible.
2837 for K in Actuals'Range loop
2838 if Chars (Formal) = Chars (Actuals (K))
2840 Has_Compatible_Type (Actuals (K), Etype (Formal))
2842 Wrong_Order := True;
2852 <<Continue>> Next_Formal (Formal);
2855 -- If Formals left over, also probably an error, skip warning
2857 if Present (Formal) then
2861 -- Here we give the warning if something was out of order
2865 ("actuals for this call may be in wrong order?", N);
2869 end Check_Argument_Order;
2871 -------------------------
2872 -- Check_Prefixed_Call --
2873 -------------------------
2875 procedure Check_Prefixed_Call is
2876 Act : constant Node_Id := First_Actual (N);
2877 A_Type : constant Entity_Id := Etype (Act);
2878 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
2879 Orig : constant Node_Id := Original_Node (N);
2883 -- Check whether the call is a prefixed call, with or without
2884 -- additional actuals.
2886 if Nkind (Orig) = N_Selected_Component
2888 (Nkind (Orig) = N_Indexed_Component
2889 and then Nkind (Prefix (Orig)) = N_Selected_Component
2890 and then Is_Entity_Name (Prefix (Prefix (Orig)))
2891 and then Is_Entity_Name (Act)
2892 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
2894 if Is_Access_Type (A_Type)
2895 and then not Is_Access_Type (F_Type)
2897 -- Introduce dereference on object in prefix
2900 Make_Explicit_Dereference (Sloc (Act),
2901 Prefix => Relocate_Node (Act));
2902 Rewrite (Act, New_A);
2905 elsif Is_Access_Type (F_Type)
2906 and then not Is_Access_Type (A_Type)
2908 -- Introduce an implicit 'Access in prefix
2910 if not Is_Aliased_View (Act) then
2912 ("object in prefixed call to& must be aliased"
2913 & " (RM-2005 4.3.1 (13))",
2918 Make_Attribute_Reference (Loc,
2919 Attribute_Name => Name_Access,
2920 Prefix => Relocate_Node (Act)));
2925 end Check_Prefixed_Call;
2927 --------------------
2928 -- Insert_Default --
2929 --------------------
2931 procedure Insert_Default is
2936 -- Missing argument in call, nothing to insert
2938 if No (Default_Value (F)) then
2942 -- Note that we do a full New_Copy_Tree, so that any associated
2943 -- Itypes are properly copied. This may not be needed any more,
2944 -- but it does no harm as a safety measure! Defaults of a generic
2945 -- formal may be out of bounds of the corresponding actual (see
2946 -- cc1311b) and an additional check may be required.
2951 New_Scope => Current_Scope,
2954 if Is_Concurrent_Type (Scope (Nam))
2955 and then Has_Discriminants (Scope (Nam))
2957 Replace_Actual_Discriminants (N, Actval);
2960 if Is_Overloadable (Nam)
2961 and then Present (Alias (Nam))
2963 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2964 and then not Is_Tagged_Type (Etype (F))
2966 -- If default is a real literal, do not introduce a
2967 -- conversion whose effect may depend on the run-time
2968 -- size of universal real.
2970 if Nkind (Actval) = N_Real_Literal then
2971 Set_Etype (Actval, Base_Type (Etype (F)));
2973 Actval := Unchecked_Convert_To (Etype (F), Actval);
2977 if Is_Scalar_Type (Etype (F)) then
2978 Enable_Range_Check (Actval);
2981 Set_Parent (Actval, N);
2983 -- Resolve aggregates with their base type, to avoid scope
2984 -- anomalies: the subtype was first built in the subprogram
2985 -- declaration, and the current call may be nested.
2987 if Nkind (Actval) = N_Aggregate then
2988 Analyze_And_Resolve (Actval, Etype (F));
2990 Analyze_And_Resolve (Actval, Etype (Actval));
2994 Set_Parent (Actval, N);
2996 -- See note above concerning aggregates
2998 if Nkind (Actval) = N_Aggregate
2999 and then Has_Discriminants (Etype (Actval))
3001 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
3003 -- Resolve entities with their own type, which may differ
3004 -- from the type of a reference in a generic context (the
3005 -- view swapping mechanism did not anticipate the re-analysis
3006 -- of default values in calls).
3008 elsif Is_Entity_Name (Actval) then
3009 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
3012 Analyze_And_Resolve (Actval, Etype (Actval));
3016 -- If default is a tag indeterminate function call, propagate
3017 -- tag to obtain proper dispatching.
3019 if Is_Controlling_Formal (F)
3020 and then Nkind (Default_Value (F)) = N_Function_Call
3022 Set_Is_Controlling_Actual (Actval);
3027 -- If the default expression raises constraint error, then just
3028 -- silently replace it with an N_Raise_Constraint_Error node,
3029 -- since we already gave the warning on the subprogram spec.
3031 if Raises_Constraint_Error (Actval) then
3033 Make_Raise_Constraint_Error (Loc,
3034 Reason => CE_Range_Check_Failed));
3035 Set_Raises_Constraint_Error (Actval);
3036 Set_Etype (Actval, Etype (F));
3040 Make_Parameter_Association (Loc,
3041 Explicit_Actual_Parameter => Actval,
3042 Selector_Name => Make_Identifier (Loc, Chars (F)));
3044 -- Case of insertion is first named actual
3046 if No (Prev) or else
3047 Nkind (Parent (Prev)) /= N_Parameter_Association
3049 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
3050 Set_First_Named_Actual (N, Actval);
3053 if No (Parameter_Associations (N)) then
3054 Set_Parameter_Associations (N, New_List (Assoc));
3056 Append (Assoc, Parameter_Associations (N));
3060 Insert_After (Prev, Assoc);
3063 -- Case of insertion is not first named actual
3066 Set_Next_Named_Actual
3067 (Assoc, Next_Named_Actual (Parent (Prev)));
3068 Set_Next_Named_Actual (Parent (Prev), Actval);
3069 Append (Assoc, Parameter_Associations (N));
3072 Mark_Rewrite_Insertion (Assoc);
3073 Mark_Rewrite_Insertion (Actval);
3082 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
3083 FT1 : Entity_Id := T1;
3084 FT2 : Entity_Id := T2;
3087 if Is_Private_Type (T1)
3088 and then Present (Full_View (T1))
3090 FT1 := Full_View (T1);
3093 if Is_Private_Type (T2)
3094 and then Present (Full_View (T2))
3096 FT2 := Full_View (T2);
3099 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3102 --------------------------
3103 -- Static_Concatenation --
3104 --------------------------
3106 function Static_Concatenation (N : Node_Id) return Boolean is
3109 when N_String_Literal =>
3114 -- Concatenation is static when both operands are static
3115 -- and the concatenation operator is a predefined one.
3117 return Scope (Entity (N)) = Standard_Standard
3119 Static_Concatenation (Left_Opnd (N))
3121 Static_Concatenation (Right_Opnd (N));
3124 if Is_Entity_Name (N) then
3126 Ent : constant Entity_Id := Entity (N);
3128 return Ekind (Ent) = E_Constant
3129 and then Present (Constant_Value (Ent))
3131 Is_Static_Expression (Constant_Value (Ent));
3138 end Static_Concatenation;
3140 -- Start of processing for Resolve_Actuals
3143 Check_Argument_Order;
3145 if Present (First_Actual (N)) then
3146 Check_Prefixed_Call;
3149 A := First_Actual (N);
3150 F := First_Formal (Nam);
3151 while Present (F) loop
3152 if No (A) and then Needs_No_Actuals (Nam) then
3155 -- If we have an error in any actual or formal, indicated by a type
3156 -- of Any_Type, then abandon resolution attempt, and set result type
3159 elsif (Present (A) and then Etype (A) = Any_Type)
3160 or else Etype (F) = Any_Type
3162 Set_Etype (N, Any_Type);
3166 -- Case where actual is present
3168 -- If the actual is an entity, generate a reference to it now. We
3169 -- do this before the actual is resolved, because a formal of some
3170 -- protected subprogram, or a task discriminant, will be rewritten
3171 -- during expansion, and the reference to the source entity may
3175 and then Is_Entity_Name (A)
3176 and then Comes_From_Source (N)
3178 Orig_A := Entity (A);
3180 if Present (Orig_A) then
3181 if Is_Formal (Orig_A)
3182 and then Ekind (F) /= E_In_Parameter
3184 Generate_Reference (Orig_A, A, 'm');
3185 elsif not Is_Overloaded (A) then
3186 Generate_Reference (Orig_A, A);
3192 and then (Nkind (Parent (A)) /= N_Parameter_Association
3194 Chars (Selector_Name (Parent (A))) = Chars (F))
3196 -- If style checking mode on, check match of formal name
3199 if Nkind (Parent (A)) = N_Parameter_Association then
3200 Check_Identifier (Selector_Name (Parent (A)), F);
3204 -- If the formal is Out or In_Out, do not resolve and expand the
3205 -- conversion, because it is subsequently expanded into explicit
3206 -- temporaries and assignments. However, the object of the
3207 -- conversion can be resolved. An exception is the case of tagged
3208 -- type conversion with a class-wide actual. In that case we want
3209 -- the tag check to occur and no temporary will be needed (no
3210 -- representation change can occur) and the parameter is passed by
3211 -- reference, so we go ahead and resolve the type conversion.
3212 -- Another exception is the case of reference to component or
3213 -- subcomponent of a bit-packed array, in which case we want to
3214 -- defer expansion to the point the in and out assignments are
3217 if Ekind (F) /= E_In_Parameter
3218 and then Nkind (A) = N_Type_Conversion
3219 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3221 if Ekind (F) = E_In_Out_Parameter
3222 and then Is_Array_Type (Etype (F))
3224 if Has_Aliased_Components (Etype (Expression (A)))
3225 /= Has_Aliased_Components (Etype (F))
3228 -- In a view conversion, the conversion must be legal in
3229 -- both directions, and thus both component types must be
3230 -- aliased, or neither (4.6 (8)).
3232 -- The additional rule 4.6 (24.9.2) seems unduly
3233 -- restrictive: the privacy requirement should not apply
3234 -- to generic types, and should be checked in an
3235 -- instance. ARG query is in order ???
3238 ("both component types in a view conversion must be"
3239 & " aliased, or neither", A);
3242 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3244 if Is_By_Reference_Type (Etype (F))
3245 or else Is_By_Reference_Type (Etype (Expression (A)))
3248 ("view conversion between unrelated by reference " &
3249 "array types not allowed (\'A'I-00246)", A);
3252 Comp_Type : constant Entity_Id :=
3254 (Etype (Expression (A)));
3256 if Comes_From_Source (A)
3257 and then Ada_Version >= Ada_05
3259 ((Is_Private_Type (Comp_Type)
3260 and then not Is_Generic_Type (Comp_Type))
3261 or else Is_Tagged_Type (Comp_Type)
3262 or else Is_Volatile (Comp_Type))
3265 ("component type of a view conversion cannot"
3266 & " be private, tagged, or volatile"
3275 if (Conversion_OK (A)
3276 or else Valid_Conversion (A, Etype (A), Expression (A)))
3277 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3279 Resolve (Expression (A));
3282 -- If the actual is a function call that returns a limited
3283 -- unconstrained object that needs finalization, create a
3284 -- transient scope for it, so that it can receive the proper
3285 -- finalization list.
3287 elsif Nkind (A) = N_Function_Call
3288 and then Is_Limited_Record (Etype (F))
3289 and then not Is_Constrained (Etype (F))
3290 and then Expander_Active
3292 (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3294 Establish_Transient_Scope (A, False);
3296 -- A small optimization: if one of the actuals is a concatenation
3297 -- create a block around a procedure call to recover stack space.
3298 -- This alleviates stack usage when several procedure calls in
3299 -- the same statement list use concatenation. We do not perform
3300 -- this wrapping for code statements, where the argument is a
3301 -- static string, and we want to preserve warnings involving
3302 -- sequences of such statements.
3304 elsif Nkind (A) = N_Op_Concat
3305 and then Nkind (N) = N_Procedure_Call_Statement
3306 and then Expander_Active
3308 not (Is_Intrinsic_Subprogram (Nam)
3309 and then Chars (Nam) = Name_Asm)
3310 and then not Static_Concatenation (A)
3312 Establish_Transient_Scope (A, False);
3313 Resolve (A, Etype (F));
3316 if Nkind (A) = N_Type_Conversion
3317 and then Is_Array_Type (Etype (F))
3318 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3320 (Is_Limited_Type (Etype (F))
3321 or else Is_Limited_Type (Etype (Expression (A))))
3324 ("conversion between unrelated limited array types " &
3325 "not allowed (\A\I-00246)", A);
3327 if Is_Limited_Type (Etype (F)) then
3328 Explain_Limited_Type (Etype (F), A);
3331 if Is_Limited_Type (Etype (Expression (A))) then
3332 Explain_Limited_Type (Etype (Expression (A)), A);
3336 -- (Ada 2005: AI-251): If the actual is an allocator whose
3337 -- directly designated type is a class-wide interface, we build
3338 -- an anonymous access type to use it as the type of the
3339 -- allocator. Later, when the subprogram call is expanded, if
3340 -- the interface has a secondary dispatch table the expander
3341 -- will add a type conversion to force the correct displacement
3344 if Nkind (A) = N_Allocator then
3346 DDT : constant Entity_Id :=
3347 Directly_Designated_Type (Base_Type (Etype (F)));
3349 New_Itype : Entity_Id;
3352 if Is_Class_Wide_Type (DDT)
3353 and then Is_Interface (DDT)
3355 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3356 Set_Etype (New_Itype, Etype (A));
3357 Set_Directly_Designated_Type (New_Itype,
3358 Directly_Designated_Type (Etype (A)));
3359 Set_Etype (A, New_Itype);
3362 -- Ada 2005, AI-162:If the actual is an allocator, the
3363 -- innermost enclosing statement is the master of the
3364 -- created object. This needs to be done with expansion
3365 -- enabled only, otherwise the transient scope will not
3366 -- be removed in the expansion of the wrapped construct.
3368 if (Is_Controlled (DDT) or else Has_Task (DDT))
3369 and then Expander_Active
3371 Establish_Transient_Scope (A, False);
3376 -- (Ada 2005): The call may be to a primitive operation of
3377 -- a tagged synchronized type, declared outside of the type.
3378 -- In this case the controlling actual must be converted to
3379 -- its corresponding record type, which is the formal type.
3380 -- The actual may be a subtype, either because of a constraint
3381 -- or because it is a generic actual, so use base type to
3382 -- locate concurrent type.
3384 A_Typ := Base_Type (Etype (A));
3385 F_Typ := Base_Type (Etype (F));
3388 Full_A_Typ : Entity_Id;
3391 if Present (Full_View (A_Typ)) then
3392 Full_A_Typ := Base_Type (Full_View (A_Typ));
3394 Full_A_Typ := A_Typ;
3397 -- Tagged synchronized type (case 1): the actual is a
3400 if Is_Concurrent_Type (A_Typ)
3401 and then Corresponding_Record_Type (A_Typ) = F_Typ
3404 Unchecked_Convert_To
3405 (Corresponding_Record_Type (A_Typ), A));
3406 Resolve (A, Etype (F));
3408 -- Tagged synchronized type (case 2): the formal is a
3411 elsif Ekind (Full_A_Typ) = E_Record_Type
3413 (Corresponding_Concurrent_Type (Full_A_Typ))
3414 and then Is_Concurrent_Type (F_Typ)
3415 and then Present (Corresponding_Record_Type (F_Typ))
3416 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3418 Resolve (A, Corresponding_Record_Type (F_Typ));
3423 Resolve (A, Etype (F));
3431 -- For mode IN, if actual is an entity, and the type of the formal
3432 -- has warnings suppressed, then we reset Never_Set_In_Source for
3433 -- the calling entity. The reason for this is to catch cases like
3434 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3435 -- uses trickery to modify an IN parameter.
3437 if Ekind (F) = E_In_Parameter
3438 and then Is_Entity_Name (A)
3439 and then Present (Entity (A))
3440 and then Ekind (Entity (A)) = E_Variable
3441 and then Has_Warnings_Off (F_Typ)
3443 Set_Never_Set_In_Source (Entity (A), False);
3446 -- Perform error checks for IN and IN OUT parameters
3448 if Ekind (F) /= E_Out_Parameter then
3450 -- Check unset reference. For scalar parameters, it is clearly
3451 -- wrong to pass an uninitialized value as either an IN or
3452 -- IN-OUT parameter. For composites, it is also clearly an
3453 -- error to pass a completely uninitialized value as an IN
3454 -- parameter, but the case of IN OUT is trickier. We prefer
3455 -- not to give a warning here. For example, suppose there is
3456 -- a routine that sets some component of a record to False.
3457 -- It is perfectly reasonable to make this IN-OUT and allow
3458 -- either initialized or uninitialized records to be passed
3461 -- For partially initialized composite values, we also avoid
3462 -- warnings, since it is quite likely that we are passing a
3463 -- partially initialized value and only the initialized fields
3464 -- will in fact be read in the subprogram.
3466 if Is_Scalar_Type (A_Typ)
3467 or else (Ekind (F) = E_In_Parameter
3468 and then not Is_Partially_Initialized_Type (A_Typ))
3470 Check_Unset_Reference (A);
3473 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3474 -- actual to a nested call, since this is case of reading an
3475 -- out parameter, which is not allowed.
3477 if Ada_Version = Ada_83
3478 and then Is_Entity_Name (A)
3479 and then Ekind (Entity (A)) = E_Out_Parameter
3481 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3485 -- Case of OUT or IN OUT parameter
3487 if Ekind (F) /= E_In_Parameter then
3489 -- For an Out parameter, check for useless assignment. Note
3490 -- that we can't set Last_Assignment this early, because we may
3491 -- kill current values in Resolve_Call, and that call would
3492 -- clobber the Last_Assignment field.
3494 -- Note: call Warn_On_Useless_Assignment before doing the check
3495 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3496 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3497 -- reflects the last assignment, not this one!
3499 if Ekind (F) = E_Out_Parameter then
3500 if Warn_On_Modified_As_Out_Parameter (F)
3501 and then Is_Entity_Name (A)
3502 and then Present (Entity (A))
3503 and then Comes_From_Source (N)
3505 Warn_On_Useless_Assignment (Entity (A), A);
3509 -- Validate the form of the actual. Note that the call to
3510 -- Is_OK_Variable_For_Out_Formal generates the required
3511 -- reference in this case.
3513 if not Is_OK_Variable_For_Out_Formal (A) then
3514 Error_Msg_NE ("actual for& must be a variable", A, F);
3517 -- What's the following about???
3519 if Is_Entity_Name (A) then
3520 Kill_Checks (Entity (A));
3526 if Etype (A) = Any_Type then
3527 Set_Etype (N, Any_Type);
3531 -- Apply appropriate range checks for in, out, and in-out
3532 -- parameters. Out and in-out parameters also need a separate
3533 -- check, if there is a type conversion, to make sure the return
3534 -- value meets the constraints of the variable before the
3537 -- Gigi looks at the check flag and uses the appropriate types.
3538 -- For now since one flag is used there is an optimization which
3539 -- might not be done in the In Out case since Gigi does not do
3540 -- any analysis. More thought required about this ???
3542 if Ekind_In (F, E_In_Parameter, E_In_Out_Parameter) then
3543 if Is_Scalar_Type (Etype (A)) then
3544 Apply_Scalar_Range_Check (A, F_Typ);
3546 elsif Is_Array_Type (Etype (A)) then
3547 Apply_Length_Check (A, F_Typ);
3549 elsif Is_Record_Type (F_Typ)
3550 and then Has_Discriminants (F_Typ)
3551 and then Is_Constrained (F_Typ)
3552 and then (not Is_Derived_Type (F_Typ)
3553 or else Comes_From_Source (Nam))
3555 Apply_Discriminant_Check (A, F_Typ);
3557 elsif Is_Access_Type (F_Typ)
3558 and then Is_Array_Type (Designated_Type (F_Typ))
3559 and then Is_Constrained (Designated_Type (F_Typ))
3561 Apply_Length_Check (A, F_Typ);
3563 elsif Is_Access_Type (F_Typ)
3564 and then Has_Discriminants (Designated_Type (F_Typ))
3565 and then Is_Constrained (Designated_Type (F_Typ))
3567 Apply_Discriminant_Check (A, F_Typ);
3570 Apply_Range_Check (A, F_Typ);
3573 -- Ada 2005 (AI-231)
3575 if Ada_Version >= Ada_05
3576 and then Is_Access_Type (F_Typ)
3577 and then Can_Never_Be_Null (F_Typ)
3578 and then Known_Null (A)
3580 Apply_Compile_Time_Constraint_Error
3582 Msg => "(Ada 2005) null not allowed in "
3583 & "null-excluding formal?",
3584 Reason => CE_Null_Not_Allowed);
3588 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter) then
3589 if Nkind (A) = N_Type_Conversion then
3590 if Is_Scalar_Type (A_Typ) then
3591 Apply_Scalar_Range_Check
3592 (Expression (A), Etype (Expression (A)), A_Typ);
3595 (Expression (A), Etype (Expression (A)), A_Typ);
3599 if Is_Scalar_Type (F_Typ) then
3600 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3602 elsif Is_Array_Type (F_Typ)
3603 and then Ekind (F) = E_Out_Parameter
3605 Apply_Length_Check (A, F_Typ);
3608 Apply_Range_Check (A, A_Typ, F_Typ);
3613 -- An actual associated with an access parameter is implicitly
3614 -- converted to the anonymous access type of the formal and must
3615 -- satisfy the legality checks for access conversions.
3617 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3618 if not Valid_Conversion (A, F_Typ, A) then
3620 ("invalid implicit conversion for access parameter", A);
3624 -- Check bad case of atomic/volatile argument (RM C.6(12))
3626 if Is_By_Reference_Type (Etype (F))
3627 and then Comes_From_Source (N)
3629 if Is_Atomic_Object (A)
3630 and then not Is_Atomic (Etype (F))
3633 ("cannot pass atomic argument to non-atomic formal",
3636 elsif Is_Volatile_Object (A)
3637 and then not Is_Volatile (Etype (F))
3640 ("cannot pass volatile argument to non-volatile formal",
3645 -- Check that subprograms don't have improper controlling
3646 -- arguments (RM 3.9.2 (9)).
3648 -- A primitive operation may have an access parameter of an
3649 -- incomplete tagged type, but a dispatching call is illegal
3650 -- if the type is still incomplete.
3652 if Is_Controlling_Formal (F) then
3653 Set_Is_Controlling_Actual (A);
3655 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3657 Desig : constant Entity_Id := Designated_Type (Etype (F));
3659 if Ekind (Desig) = E_Incomplete_Type
3660 and then No (Full_View (Desig))
3661 and then No (Non_Limited_View (Desig))
3664 ("premature use of incomplete type& " &
3665 "in dispatching call", A, Desig);
3670 elsif Nkind (A) = N_Explicit_Dereference then
3671 Validate_Remote_Access_To_Class_Wide_Type (A);
3674 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3675 and then not Is_Class_Wide_Type (F_Typ)
3676 and then not Is_Controlling_Formal (F)
3678 Error_Msg_N ("class-wide argument not allowed here!", A);
3680 if Is_Subprogram (Nam)
3681 and then Comes_From_Source (Nam)
3683 Error_Msg_Node_2 := F_Typ;
3685 ("& is not a dispatching operation of &!", A, Nam);
3688 elsif Is_Access_Type (A_Typ)
3689 and then Is_Access_Type (F_Typ)
3690 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3691 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3692 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3693 or else (Nkind (A) = N_Attribute_Reference
3695 Is_Class_Wide_Type (Etype (Prefix (A)))))
3696 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3697 and then not Is_Controlling_Formal (F)
3699 -- Disable these checks for call to imported C++ subprograms
3702 (Is_Entity_Name (Name (N))
3703 and then Is_Imported (Entity (Name (N)))
3704 and then Convention (Entity (Name (N))) = Convention_CPP)
3707 ("access to class-wide argument not allowed here!", A);
3709 if Is_Subprogram (Nam)
3710 and then Comes_From_Source (Nam)
3712 Error_Msg_Node_2 := Designated_Type (F_Typ);
3714 ("& is not a dispatching operation of &!", A, Nam);
3720 -- If it is a named association, treat the selector_name as
3721 -- a proper identifier, and mark the corresponding entity.
3723 if Nkind (Parent (A)) = N_Parameter_Association then
3724 Set_Entity (Selector_Name (Parent (A)), F);
3725 Generate_Reference (F, Selector_Name (Parent (A)));
3726 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3727 Generate_Reference (F_Typ, N, ' ');
3732 if Ekind (F) /= E_Out_Parameter then
3733 Check_Unset_Reference (A);
3738 -- Case where actual is not present
3746 end Resolve_Actuals;
3748 -----------------------
3749 -- Resolve_Allocator --
3750 -----------------------
3752 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
3753 E : constant Node_Id := Expression (N);
3755 Discrim : Entity_Id;
3758 Assoc : Node_Id := Empty;
3761 procedure Check_Allocator_Discrim_Accessibility
3762 (Disc_Exp : Node_Id;
3763 Alloc_Typ : Entity_Id);
3764 -- Check that accessibility level associated with an access discriminant
3765 -- initialized in an allocator by the expression Disc_Exp is not deeper
3766 -- than the level of the allocator type Alloc_Typ. An error message is
3767 -- issued if this condition is violated. Specialized checks are done for
3768 -- the cases of a constraint expression which is an access attribute or
3769 -- an access discriminant.
3771 function In_Dispatching_Context return Boolean;
3772 -- If the allocator is an actual in a call, it is allowed to be class-
3773 -- wide when the context is not because it is a controlling actual.
3775 procedure Propagate_Coextensions (Root : Node_Id);
3776 -- Propagate all nested coextensions which are located one nesting
3777 -- level down the tree to the node Root. Example:
3780 -- Level_1_Coextension
3781 -- Level_2_Coextension
3783 -- The algorithm is paired with delay actions done by the Expander. In
3784 -- the above example, assume all coextensions are controlled types.
3785 -- The cycle of analysis, resolution and expansion will yield:
3787 -- 1) Analyze Top_Record
3788 -- 2) Analyze Level_1_Coextension
3789 -- 3) Analyze Level_2_Coextension
3790 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
3792 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3793 -- generated to capture the allocated object. Temp_1 is attached
3794 -- to the coextension chain of Level_2_Coextension.
3795 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3796 -- coextension. A forward tree traversal is performed which finds
3797 -- Level_2_Coextension's list and copies its contents into its
3799 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3800 -- generated to capture the allocated object. Temp_2 is attached
3801 -- to the coextension chain of Level_1_Coextension. Currently, the
3802 -- contents of the list are [Temp_2, Temp_1].
3803 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3804 -- finds Level_1_Coextension's list and copies its contents into
3806 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3807 -- Temp_2 and attach them to Top_Record's finalization list.
3809 -------------------------------------------
3810 -- Check_Allocator_Discrim_Accessibility --
3811 -------------------------------------------
3813 procedure Check_Allocator_Discrim_Accessibility
3814 (Disc_Exp : Node_Id;
3815 Alloc_Typ : Entity_Id)
3818 if Type_Access_Level (Etype (Disc_Exp)) >
3819 Type_Access_Level (Alloc_Typ)
3822 ("operand type has deeper level than allocator type", Disc_Exp);
3824 -- When the expression is an Access attribute the level of the prefix
3825 -- object must not be deeper than that of the allocator's type.
3827 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3828 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3830 and then Object_Access_Level (Prefix (Disc_Exp))
3831 > Type_Access_Level (Alloc_Typ)
3834 ("prefix of attribute has deeper level than allocator type",
3837 -- When the expression is an access discriminant the check is against
3838 -- the level of the prefix object.
3840 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3841 and then Nkind (Disc_Exp) = N_Selected_Component
3842 and then Object_Access_Level (Prefix (Disc_Exp))
3843 > Type_Access_Level (Alloc_Typ)
3846 ("access discriminant has deeper level than allocator type",
3849 -- All other cases are legal
3854 end Check_Allocator_Discrim_Accessibility;
3856 ----------------------------
3857 -- In_Dispatching_Context --
3858 ----------------------------
3860 function In_Dispatching_Context return Boolean is
3861 Par : constant Node_Id := Parent (N);
3863 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
3864 and then Is_Entity_Name (Name (Par))
3865 and then Is_Dispatching_Operation (Entity (Name (Par)));
3866 end In_Dispatching_Context;
3868 ----------------------------
3869 -- Propagate_Coextensions --
3870 ----------------------------
3872 procedure Propagate_Coextensions (Root : Node_Id) is
3874 procedure Copy_List (From : Elist_Id; To : Elist_Id);
3875 -- Copy the contents of list From into list To, preserving the
3876 -- order of elements.
3878 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
3879 -- Recognize an allocator or a rewritten allocator node and add it
3880 -- along with its nested coextensions to the list of Root.
3886 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
3887 From_Elmt : Elmt_Id;
3889 From_Elmt := First_Elmt (From);
3890 while Present (From_Elmt) loop
3891 Append_Elmt (Node (From_Elmt), To);
3892 Next_Elmt (From_Elmt);
3896 -----------------------
3897 -- Process_Allocator --
3898 -----------------------
3900 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
3901 Orig_Nod : Node_Id := Nod;
3904 -- This is a possible rewritten subtype indication allocator. Any
3905 -- nested coextensions will appear as discriminant constraints.
3907 if Nkind (Nod) = N_Identifier
3908 and then Present (Original_Node (Nod))
3909 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
3913 Discr_Elmt : Elmt_Id;
3916 if Is_Record_Type (Entity (Nod)) then
3918 First_Elmt (Discriminant_Constraint (Entity (Nod)));
3919 while Present (Discr_Elmt) loop
3920 Discr := Node (Discr_Elmt);
3922 if Nkind (Discr) = N_Identifier
3923 and then Present (Original_Node (Discr))
3924 and then Nkind (Original_Node (Discr)) = N_Allocator
3925 and then Present (Coextensions (
3926 Original_Node (Discr)))
3928 if No (Coextensions (Root)) then
3929 Set_Coextensions (Root, New_Elmt_List);
3933 (From => Coextensions (Original_Node (Discr)),
3934 To => Coextensions (Root));
3937 Next_Elmt (Discr_Elmt);
3940 -- There is no need to continue the traversal of this
3941 -- subtree since all the information has already been
3948 -- Case of either a stand alone allocator or a rewritten allocator
3949 -- with an aggregate.
3952 if Present (Original_Node (Nod)) then
3953 Orig_Nod := Original_Node (Nod);
3956 if Nkind (Orig_Nod) = N_Allocator then
3958 -- Propagate the list of nested coextensions to the Root
3959 -- allocator. This is done through list copy since a single
3960 -- allocator may have multiple coextensions. Do not touch
3961 -- coextensions roots.
3963 if not Is_Coextension_Root (Orig_Nod)
3964 and then Present (Coextensions (Orig_Nod))
3966 if No (Coextensions (Root)) then
3967 Set_Coextensions (Root, New_Elmt_List);
3971 (From => Coextensions (Orig_Nod),
3972 To => Coextensions (Root));
3975 -- There is no need to continue the traversal of this
3976 -- subtree since all the information has already been
3983 -- Keep on traversing, looking for the next allocator
3986 end Process_Allocator;
3988 procedure Process_Allocators is
3989 new Traverse_Proc (Process_Allocator);
3991 -- Start of processing for Propagate_Coextensions
3994 Process_Allocators (Expression (Root));
3995 end Propagate_Coextensions;
3997 -- Start of processing for Resolve_Allocator
4000 -- Replace general access with specific type
4002 if Ekind (Etype (N)) = E_Allocator_Type then
4003 Set_Etype (N, Base_Type (Typ));
4006 if Is_Abstract_Type (Typ) then
4007 Error_Msg_N ("type of allocator cannot be abstract", N);
4010 -- For qualified expression, resolve the expression using the
4011 -- given subtype (nothing to do for type mark, subtype indication)
4013 if Nkind (E) = N_Qualified_Expression then
4014 if Is_Class_Wide_Type (Etype (E))
4015 and then not Is_Class_Wide_Type (Designated_Type (Typ))
4016 and then not In_Dispatching_Context
4019 ("class-wide allocator not allowed for this access type", N);
4022 Resolve (Expression (E), Etype (E));
4023 Check_Unset_Reference (Expression (E));
4025 -- A qualified expression requires an exact match of the type,
4026 -- class-wide matching is not allowed.
4028 if (Is_Class_Wide_Type (Etype (Expression (E)))
4029 or else Is_Class_Wide_Type (Etype (E)))
4030 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
4032 Wrong_Type (Expression (E), Etype (E));
4035 -- A special accessibility check is needed for allocators that
4036 -- constrain access discriminants. The level of the type of the
4037 -- expression used to constrain an access discriminant cannot be
4038 -- deeper than the type of the allocator (in contrast to access
4039 -- parameters, where the level of the actual can be arbitrary).
4041 -- We can't use Valid_Conversion to perform this check because
4042 -- in general the type of the allocator is unrelated to the type
4043 -- of the access discriminant.
4045 if Ekind (Typ) /= E_Anonymous_Access_Type
4046 or else Is_Local_Anonymous_Access (Typ)
4048 Subtyp := Entity (Subtype_Mark (E));
4050 Aggr := Original_Node (Expression (E));
4052 if Has_Discriminants (Subtyp)
4053 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
4055 Discrim := First_Discriminant (Base_Type (Subtyp));
4057 -- Get the first component expression of the aggregate
4059 if Present (Expressions (Aggr)) then
4060 Disc_Exp := First (Expressions (Aggr));
4062 elsif Present (Component_Associations (Aggr)) then
4063 Assoc := First (Component_Associations (Aggr));
4065 if Present (Assoc) then
4066 Disc_Exp := Expression (Assoc);
4075 while Present (Discrim) and then Present (Disc_Exp) loop
4076 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4077 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4080 Next_Discriminant (Discrim);
4082 if Present (Discrim) then
4083 if Present (Assoc) then
4085 Disc_Exp := Expression (Assoc);
4087 elsif Present (Next (Disc_Exp)) then
4091 Assoc := First (Component_Associations (Aggr));
4093 if Present (Assoc) then
4094 Disc_Exp := Expression (Assoc);
4104 -- For a subtype mark or subtype indication, freeze the subtype
4107 Freeze_Expression (E);
4109 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
4111 ("initialization required for access-to-constant allocator", N);
4114 -- A special accessibility check is needed for allocators that
4115 -- constrain access discriminants. The level of the type of the
4116 -- expression used to constrain an access discriminant cannot be
4117 -- deeper than the type of the allocator (in contrast to access
4118 -- parameters, where the level of the actual can be arbitrary).
4119 -- We can't use Valid_Conversion to perform this check because
4120 -- in general the type of the allocator is unrelated to the type
4121 -- of the access discriminant.
4123 if Nkind (Original_Node (E)) = N_Subtype_Indication
4124 and then (Ekind (Typ) /= E_Anonymous_Access_Type
4125 or else Is_Local_Anonymous_Access (Typ))
4127 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
4129 if Has_Discriminants (Subtyp) then
4130 Discrim := First_Discriminant (Base_Type (Subtyp));
4131 Constr := First (Constraints (Constraint (Original_Node (E))));
4132 while Present (Discrim) and then Present (Constr) loop
4133 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4134 if Nkind (Constr) = N_Discriminant_Association then
4135 Disc_Exp := Original_Node (Expression (Constr));
4137 Disc_Exp := Original_Node (Constr);
4140 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4143 Next_Discriminant (Discrim);
4150 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4151 -- check that the level of the type of the created object is not deeper
4152 -- than the level of the allocator's access type, since extensions can
4153 -- now occur at deeper levels than their ancestor types. This is a
4154 -- static accessibility level check; a run-time check is also needed in
4155 -- the case of an initialized allocator with a class-wide argument (see
4156 -- Expand_Allocator_Expression).
4158 if Ada_Version >= Ada_05
4159 and then Is_Class_Wide_Type (Designated_Type (Typ))
4162 Exp_Typ : Entity_Id;
4165 if Nkind (E) = N_Qualified_Expression then
4166 Exp_Typ := Etype (E);
4167 elsif Nkind (E) = N_Subtype_Indication then
4168 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4170 Exp_Typ := Entity (E);
4173 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4174 if In_Instance_Body then
4175 Error_Msg_N ("?type in allocator has deeper level than" &
4176 " designated class-wide type", E);
4177 Error_Msg_N ("\?Program_Error will be raised at run time",
4180 Make_Raise_Program_Error (Sloc (N),
4181 Reason => PE_Accessibility_Check_Failed));
4184 -- Do not apply Ada 2005 accessibility checks on a class-wide
4185 -- allocator if the type given in the allocator is a formal
4186 -- type. A run-time check will be performed in the instance.
4188 elsif not Is_Generic_Type (Exp_Typ) then
4189 Error_Msg_N ("type in allocator has deeper level than" &
4190 " designated class-wide type", E);
4196 -- Check for allocation from an empty storage pool
4198 if No_Pool_Assigned (Typ) then
4200 Loc : constant Source_Ptr := Sloc (N);
4202 Error_Msg_N ("?allocation from empty storage pool!", N);
4203 Error_Msg_N ("\?Storage_Error will be raised at run time!", N);
4205 Make_Raise_Storage_Error (Loc,
4206 Reason => SE_Empty_Storage_Pool));
4209 -- If the context is an unchecked conversion, as may happen within
4210 -- an inlined subprogram, the allocator is being resolved with its
4211 -- own anonymous type. In that case, if the target type has a specific
4212 -- storage pool, it must be inherited explicitly by the allocator type.
4214 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4215 and then No (Associated_Storage_Pool (Typ))
4217 Set_Associated_Storage_Pool
4218 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4221 -- An erroneous allocator may be rewritten as a raise Program_Error
4224 if Nkind (N) = N_Allocator then
4226 -- An anonymous access discriminant is the definition of a
4229 if Ekind (Typ) = E_Anonymous_Access_Type
4230 and then Nkind (Associated_Node_For_Itype (Typ)) =
4231 N_Discriminant_Specification
4233 -- Avoid marking an allocator as a dynamic coextension if it is
4234 -- within a static construct.
4236 if not Is_Static_Coextension (N) then
4237 Set_Is_Dynamic_Coextension (N);
4240 -- Cleanup for potential static coextensions
4243 Set_Is_Dynamic_Coextension (N, False);
4244 Set_Is_Static_Coextension (N, False);
4247 -- There is no need to propagate any nested coextensions if they
4248 -- are marked as static since they will be rewritten on the spot.
4250 if not Is_Static_Coextension (N) then
4251 Propagate_Coextensions (N);
4254 end Resolve_Allocator;
4256 ---------------------------
4257 -- Resolve_Arithmetic_Op --
4258 ---------------------------
4260 -- Used for resolving all arithmetic operators except exponentiation
4262 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4263 L : constant Node_Id := Left_Opnd (N);
4264 R : constant Node_Id := Right_Opnd (N);
4265 TL : constant Entity_Id := Base_Type (Etype (L));
4266 TR : constant Entity_Id := Base_Type (Etype (R));
4270 B_Typ : constant Entity_Id := Base_Type (Typ);
4271 -- We do the resolution using the base type, because intermediate values
4272 -- in expressions always are of the base type, not a subtype of it.
4274 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4275 -- Returns True if N is in a context that expects "any real type"
4277 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4278 -- Return True iff given type is Integer or universal real/integer
4280 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4281 -- Choose type of integer literal in fixed-point operation to conform
4282 -- to available fixed-point type. T is the type of the other operand,
4283 -- which is needed to determine the expected type of N.
4285 procedure Set_Operand_Type (N : Node_Id);
4286 -- Set operand type to T if universal
4288 -------------------------------
4289 -- Expected_Type_Is_Any_Real --
4290 -------------------------------
4292 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4294 -- N is the expression after "delta" in a fixed_point_definition;
4297 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4298 N_Decimal_Fixed_Point_Definition,
4300 -- N is one of the bounds in a real_range_specification;
4303 N_Real_Range_Specification,
4305 -- N is the expression of a delta_constraint;
4308 N_Delta_Constraint);
4309 end Expected_Type_Is_Any_Real;
4311 -----------------------------
4312 -- Is_Integer_Or_Universal --
4313 -----------------------------
4315 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4317 Index : Interp_Index;
4321 if not Is_Overloaded (N) then
4323 return Base_Type (T) = Base_Type (Standard_Integer)
4324 or else T = Universal_Integer
4325 or else T = Universal_Real;
4327 Get_First_Interp (N, Index, It);
4328 while Present (It.Typ) loop
4329 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4330 or else It.Typ = Universal_Integer
4331 or else It.Typ = Universal_Real
4336 Get_Next_Interp (Index, It);
4341 end Is_Integer_Or_Universal;
4343 ----------------------------
4344 -- Set_Mixed_Mode_Operand --
4345 ----------------------------
4347 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4348 Index : Interp_Index;
4352 if Universal_Interpretation (N) = Universal_Integer then
4354 -- A universal integer literal is resolved as standard integer
4355 -- except in the case of a fixed-point result, where we leave it
4356 -- as universal (to be handled by Exp_Fixd later on)
4358 if Is_Fixed_Point_Type (T) then
4359 Resolve (N, Universal_Integer);
4361 Resolve (N, Standard_Integer);
4364 elsif Universal_Interpretation (N) = Universal_Real
4365 and then (T = Base_Type (Standard_Integer)
4366 or else T = Universal_Integer
4367 or else T = Universal_Real)
4369 -- A universal real can appear in a fixed-type context. We resolve
4370 -- the literal with that context, even though this might raise an
4371 -- exception prematurely (the other operand may be zero).
4375 elsif Etype (N) = Base_Type (Standard_Integer)
4376 and then T = Universal_Real
4377 and then Is_Overloaded (N)
4379 -- Integer arg in mixed-mode operation. Resolve with universal
4380 -- type, in case preference rule must be applied.
4382 Resolve (N, Universal_Integer);
4385 and then B_Typ /= Universal_Fixed
4387 -- Not a mixed-mode operation, resolve with context
4391 elsif Etype (N) = Any_Fixed then
4393 -- N may itself be a mixed-mode operation, so use context type
4397 elsif Is_Fixed_Point_Type (T)
4398 and then B_Typ = Universal_Fixed
4399 and then Is_Overloaded (N)
4401 -- Must be (fixed * fixed) operation, operand must have one
4402 -- compatible interpretation.
4404 Resolve (N, Any_Fixed);
4406 elsif Is_Fixed_Point_Type (B_Typ)
4407 and then (T = Universal_Real
4408 or else Is_Fixed_Point_Type (T))
4409 and then Is_Overloaded (N)
4411 -- C * F(X) in a fixed context, where C is a real literal or a
4412 -- fixed-point expression. F must have either a fixed type
4413 -- interpretation or an integer interpretation, but not both.
4415 Get_First_Interp (N, Index, It);
4416 while Present (It.Typ) loop
4417 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4419 if Analyzed (N) then
4420 Error_Msg_N ("ambiguous operand in fixed operation", N);
4422 Resolve (N, Standard_Integer);
4425 elsif Is_Fixed_Point_Type (It.Typ) then
4427 if Analyzed (N) then
4428 Error_Msg_N ("ambiguous operand in fixed operation", N);
4430 Resolve (N, It.Typ);
4434 Get_Next_Interp (Index, It);
4437 -- Reanalyze the literal with the fixed type of the context. If
4438 -- context is Universal_Fixed, we are within a conversion, leave
4439 -- the literal as a universal real because there is no usable
4440 -- fixed type, and the target of the conversion plays no role in
4454 if B_Typ = Universal_Fixed
4455 and then Nkind (Op2) = N_Real_Literal
4457 T2 := Universal_Real;
4462 Set_Analyzed (Op2, False);
4469 end Set_Mixed_Mode_Operand;
4471 ----------------------
4472 -- Set_Operand_Type --
4473 ----------------------
4475 procedure Set_Operand_Type (N : Node_Id) is
4477 if Etype (N) = Universal_Integer
4478 or else Etype (N) = Universal_Real
4482 end Set_Operand_Type;
4484 -- Start of processing for Resolve_Arithmetic_Op
4487 if Comes_From_Source (N)
4488 and then Ekind (Entity (N)) = E_Function
4489 and then Is_Imported (Entity (N))
4490 and then Is_Intrinsic_Subprogram (Entity (N))
4492 Resolve_Intrinsic_Operator (N, Typ);
4495 -- Special-case for mixed-mode universal expressions or fixed point
4496 -- type operation: each argument is resolved separately. The same
4497 -- treatment is required if one of the operands of a fixed point
4498 -- operation is universal real, since in this case we don't do a
4499 -- conversion to a specific fixed-point type (instead the expander
4500 -- takes care of the case).
4502 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4503 and then Present (Universal_Interpretation (L))
4504 and then Present (Universal_Interpretation (R))
4506 Resolve (L, Universal_Interpretation (L));
4507 Resolve (R, Universal_Interpretation (R));
4508 Set_Etype (N, B_Typ);
4510 elsif (B_Typ = Universal_Real
4511 or else Etype (N) = Universal_Fixed
4512 or else (Etype (N) = Any_Fixed
4513 and then Is_Fixed_Point_Type (B_Typ))
4514 or else (Is_Fixed_Point_Type (B_Typ)
4515 and then (Is_Integer_Or_Universal (L)
4517 Is_Integer_Or_Universal (R))))
4518 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4520 if TL = Universal_Integer or else TR = Universal_Integer then
4521 Check_For_Visible_Operator (N, B_Typ);
4524 -- If context is a fixed type and one operand is integer, the
4525 -- other is resolved with the type of the context.
4527 if Is_Fixed_Point_Type (B_Typ)
4528 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4529 or else TL = Universal_Integer)
4534 elsif Is_Fixed_Point_Type (B_Typ)
4535 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4536 or else TR = Universal_Integer)
4542 Set_Mixed_Mode_Operand (L, TR);
4543 Set_Mixed_Mode_Operand (R, TL);
4546 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4547 -- multiplying operators from being used when the expected type is
4548 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4549 -- some cases where the expected type is actually Any_Real;
4550 -- Expected_Type_Is_Any_Real takes care of that case.
4552 if Etype (N) = Universal_Fixed
4553 or else Etype (N) = Any_Fixed
4555 if B_Typ = Universal_Fixed
4556 and then not Expected_Type_Is_Any_Real (N)
4557 and then not Nkind_In (Parent (N), N_Type_Conversion,
4558 N_Unchecked_Type_Conversion)
4560 Error_Msg_N ("type cannot be determined from context!", N);
4561 Error_Msg_N ("\explicit conversion to result type required", N);
4563 Set_Etype (L, Any_Type);
4564 Set_Etype (R, Any_Type);
4567 if Ada_Version = Ada_83
4568 and then Etype (N) = Universal_Fixed
4570 Nkind_In (Parent (N), N_Type_Conversion,
4571 N_Unchecked_Type_Conversion)
4574 ("(Ada 83) fixed-point operation "
4575 & "needs explicit conversion", N);
4578 -- The expected type is "any real type" in contexts like
4579 -- type T is delta <universal_fixed-expression> ...
4580 -- in which case we need to set the type to Universal_Real
4581 -- so that static expression evaluation will work properly.
4583 if Expected_Type_Is_Any_Real (N) then
4584 Set_Etype (N, Universal_Real);
4586 Set_Etype (N, B_Typ);
4590 elsif Is_Fixed_Point_Type (B_Typ)
4591 and then (Is_Integer_Or_Universal (L)
4592 or else Nkind (L) = N_Real_Literal
4593 or else Nkind (R) = N_Real_Literal
4594 or else Is_Integer_Or_Universal (R))
4596 Set_Etype (N, B_Typ);
4598 elsif Etype (N) = Any_Fixed then
4600 -- If no previous errors, this is only possible if one operand
4601 -- is overloaded and the context is universal. Resolve as such.
4603 Set_Etype (N, B_Typ);
4607 if (TL = Universal_Integer or else TL = Universal_Real)
4609 (TR = Universal_Integer or else TR = Universal_Real)
4611 Check_For_Visible_Operator (N, B_Typ);
4614 -- If the context is Universal_Fixed and the operands are also
4615 -- universal fixed, this is an error, unless there is only one
4616 -- applicable fixed_point type (usually duration).
4618 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4619 T := Unique_Fixed_Point_Type (N);
4621 if T = Any_Type then
4634 -- If one of the arguments was resolved to a non-universal type.
4635 -- label the result of the operation itself with the same type.
4636 -- Do the same for the universal argument, if any.
4638 T := Intersect_Types (L, R);
4639 Set_Etype (N, Base_Type (T));
4640 Set_Operand_Type (L);
4641 Set_Operand_Type (R);
4644 Generate_Operator_Reference (N, Typ);
4645 Eval_Arithmetic_Op (N);
4647 -- Set overflow and division checking bit. Much cleverer code needed
4648 -- here eventually and perhaps the Resolve routines should be separated
4649 -- for the various arithmetic operations, since they will need
4650 -- different processing. ???
4652 if Nkind (N) in N_Op then
4653 if not Overflow_Checks_Suppressed (Etype (N)) then
4654 Enable_Overflow_Check (N);
4657 -- Give warning if explicit division by zero
4659 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4660 and then not Division_Checks_Suppressed (Etype (N))
4662 Rop := Right_Opnd (N);
4664 if Compile_Time_Known_Value (Rop)
4665 and then ((Is_Integer_Type (Etype (Rop))
4666 and then Expr_Value (Rop) = Uint_0)
4668 (Is_Real_Type (Etype (Rop))
4669 and then Expr_Value_R (Rop) = Ureal_0))
4671 -- Specialize the warning message according to the operation
4675 Apply_Compile_Time_Constraint_Error
4676 (N, "division by zero?", CE_Divide_By_Zero,
4677 Loc => Sloc (Right_Opnd (N)));
4680 Apply_Compile_Time_Constraint_Error
4681 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4682 Loc => Sloc (Right_Opnd (N)));
4685 Apply_Compile_Time_Constraint_Error
4686 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4687 Loc => Sloc (Right_Opnd (N)));
4689 -- Division by zero can only happen with division, rem,
4690 -- and mod operations.
4693 raise Program_Error;
4696 -- Otherwise just set the flag to check at run time
4699 Activate_Division_Check (N);
4703 -- If Restriction No_Implicit_Conditionals is active, then it is
4704 -- violated if either operand can be negative for mod, or for rem
4705 -- if both operands can be negative.
4707 if Restrictions.Set (No_Implicit_Conditionals)
4708 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4717 -- Set if corresponding operand might be negative
4721 (Left_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4722 LNeg := (not OK) or else Lo < 0;
4725 (Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4726 RNeg := (not OK) or else Lo < 0;
4728 -- Check if we will be generating conditionals. There are two
4729 -- cases where that can happen, first for REM, the only case
4730 -- is largest negative integer mod -1, where the division can
4731 -- overflow, but we still have to give the right result. The
4732 -- front end generates a test for this annoying case. Here we
4733 -- just test if both operands can be negative (that's what the
4734 -- expander does, so we match its logic here).
4736 -- The second case is mod where either operand can be negative.
4737 -- In this case, the back end has to generate additonal tests.
4739 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4741 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
4743 Check_Restriction (No_Implicit_Conditionals, N);
4749 Check_Unset_Reference (L);
4750 Check_Unset_Reference (R);
4751 end Resolve_Arithmetic_Op;
4757 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
4758 Loc : constant Source_Ptr := Sloc (N);
4759 Subp : constant Node_Id := Name (N);
4767 function Same_Or_Aliased_Subprograms
4769 E : Entity_Id) return Boolean;
4770 -- Returns True if the subprogram entity S is the same as E or else
4771 -- S is an alias of E.
4773 ---------------------------------
4774 -- Same_Or_Aliased_Subprograms --
4775 ---------------------------------
4777 function Same_Or_Aliased_Subprograms
4779 E : Entity_Id) return Boolean
4781 Subp_Alias : constant Entity_Id := Alias (S);
4784 or else (Present (Subp_Alias) and then Subp_Alias = E);
4785 end Same_Or_Aliased_Subprograms;
4787 -- Start of processing for Resolve_Call
4790 -- The context imposes a unique interpretation with type Typ on a
4791 -- procedure or function call. Find the entity of the subprogram that
4792 -- yields the expected type, and propagate the corresponding formal
4793 -- constraints on the actuals. The caller has established that an
4794 -- interpretation exists, and emitted an error if not unique.
4796 -- First deal with the case of a call to an access-to-subprogram,
4797 -- dereference made explicit in Analyze_Call.
4799 if Ekind (Etype (Subp)) = E_Subprogram_Type then
4800 if not Is_Overloaded (Subp) then
4801 Nam := Etype (Subp);
4804 -- Find the interpretation whose type (a subprogram type) has a
4805 -- return type that is compatible with the context. Analysis of
4806 -- the node has established that one exists.
4810 Get_First_Interp (Subp, I, It);
4811 while Present (It.Typ) loop
4812 if Covers (Typ, Etype (It.Typ)) then
4817 Get_Next_Interp (I, It);
4821 raise Program_Error;
4825 -- If the prefix is not an entity, then resolve it
4827 if not Is_Entity_Name (Subp) then
4828 Resolve (Subp, Nam);
4831 -- For an indirect call, we always invalidate checks, since we do not
4832 -- know whether the subprogram is local or global. Yes we could do
4833 -- better here, e.g. by knowing that there are no local subprograms,
4834 -- but it does not seem worth the effort. Similarly, we kill all
4835 -- knowledge of current constant values.
4837 Kill_Current_Values;
4839 -- If this is a procedure call which is really an entry call, do
4840 -- the conversion of the procedure call to an entry call. Protected
4841 -- operations use the same circuitry because the name in the call
4842 -- can be an arbitrary expression with special resolution rules.
4844 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
4845 or else (Is_Entity_Name (Subp)
4846 and then Ekind (Entity (Subp)) = E_Entry)
4848 Resolve_Entry_Call (N, Typ);
4849 Check_Elab_Call (N);
4851 -- Kill checks and constant values, as above for indirect case
4852 -- Who knows what happens when another task is activated?
4854 Kill_Current_Values;
4857 -- Normal subprogram call with name established in Resolve
4859 elsif not (Is_Type (Entity (Subp))) then
4860 Nam := Entity (Subp);
4861 Set_Entity_With_Style_Check (Subp, Nam);
4863 -- Otherwise we must have the case of an overloaded call
4866 pragma Assert (Is_Overloaded (Subp));
4868 -- Initialize Nam to prevent warning (we know it will be assigned
4869 -- in the loop below, but the compiler does not know that).
4873 Get_First_Interp (Subp, I, It);
4874 while Present (It.Typ) loop
4875 if Covers (Typ, It.Typ) then
4877 Set_Entity_With_Style_Check (Subp, Nam);
4881 Get_Next_Interp (I, It);
4885 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
4886 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
4887 and then Nkind (Subp) /= N_Explicit_Dereference
4888 and then Present (Parameter_Associations (N))
4890 -- The prefix is a parameterless function call that returns an access
4891 -- to subprogram. If parameters are present in the current call, add
4892 -- add an explicit dereference. We use the base type here because
4893 -- within an instance these may be subtypes.
4895 -- The dereference is added either in Analyze_Call or here. Should
4896 -- be consolidated ???
4898 Set_Is_Overloaded (Subp, False);
4899 Set_Etype (Subp, Etype (Nam));
4900 Insert_Explicit_Dereference (Subp);
4901 Nam := Designated_Type (Etype (Nam));
4902 Resolve (Subp, Nam);
4905 -- Check that a call to Current_Task does not occur in an entry body
4907 if Is_RTE (Nam, RE_Current_Task) then
4916 -- Exclude calls that occur within the default of a formal
4917 -- parameter of the entry, since those are evaluated outside
4920 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
4922 if Nkind (P) = N_Entry_Body
4923 or else (Nkind (P) = N_Subprogram_Body
4924 and then Is_Entry_Barrier_Function (P))
4928 ("?& should not be used in entry body (RM C.7(17))",
4931 ("\Program_Error will be raised at run time?", N, Nam);
4933 Make_Raise_Program_Error (Loc,
4934 Reason => PE_Current_Task_In_Entry_Body));
4935 Set_Etype (N, Rtype);
4942 -- Check that a procedure call does not occur in the context of the
4943 -- entry call statement of a conditional or timed entry call. Note that
4944 -- the case of a call to a subprogram renaming of an entry will also be
4945 -- rejected. The test for N not being an N_Entry_Call_Statement is
4946 -- defensive, covering the possibility that the processing of entry
4947 -- calls might reach this point due to later modifications of the code
4950 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4951 and then Nkind (N) /= N_Entry_Call_Statement
4952 and then Entry_Call_Statement (Parent (N)) = N
4954 if Ada_Version < Ada_05 then
4955 Error_Msg_N ("entry call required in select statement", N);
4957 -- Ada 2005 (AI-345): If a procedure_call_statement is used
4958 -- for a procedure_or_entry_call, the procedure_name or
4959 -- procedure_prefix of the procedure_call_statement shall denote
4960 -- an entry renamed by a procedure, or (a view of) a primitive
4961 -- subprogram of a limited interface whose first parameter is
4962 -- a controlling parameter.
4964 elsif Nkind (N) = N_Procedure_Call_Statement
4965 and then not Is_Renamed_Entry (Nam)
4966 and then not Is_Controlling_Limited_Procedure (Nam)
4969 ("entry call or dispatching primitive of interface required", N);
4973 -- Check that this is not a call to a protected procedure or entry from
4974 -- within a protected function.
4976 if Ekind (Current_Scope) = E_Function
4977 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
4978 and then Ekind (Nam) /= E_Function
4979 and then Scope (Nam) = Scope (Current_Scope)
4981 Error_Msg_N ("within protected function, protected " &
4982 "object is constant", N);
4983 Error_Msg_N ("\cannot call operation that may modify it", N);
4986 -- Freeze the subprogram name if not in a spec-expression. Note that we
4987 -- freeze procedure calls as well as function calls. Procedure calls are
4988 -- not frozen according to the rules (RM 13.14(14)) because it is
4989 -- impossible to have a procedure call to a non-frozen procedure in pure
4990 -- Ada, but in the code that we generate in the expander, this rule
4991 -- needs extending because we can generate procedure calls that need
4994 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
4995 Freeze_Expression (Subp);
4998 -- For a predefined operator, the type of the result is the type imposed
4999 -- by context, except for a predefined operation on universal fixed.
5000 -- Otherwise The type of the call is the type returned by the subprogram
5003 if Is_Predefined_Op (Nam) then
5004 if Etype (N) /= Universal_Fixed then
5008 -- If the subprogram returns an array type, and the context requires the
5009 -- component type of that array type, the node is really an indexing of
5010 -- the parameterless call. Resolve as such. A pathological case occurs
5011 -- when the type of the component is an access to the array type. In
5012 -- this case the call is truly ambiguous.
5014 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
5016 ((Is_Array_Type (Etype (Nam))
5017 and then Covers (Typ, Component_Type (Etype (Nam))))
5018 or else (Is_Access_Type (Etype (Nam))
5019 and then Is_Array_Type (Designated_Type (Etype (Nam)))
5022 Component_Type (Designated_Type (Etype (Nam))))))
5025 Index_Node : Node_Id;
5027 Ret_Type : constant Entity_Id := Etype (Nam);
5030 if Is_Access_Type (Ret_Type)
5031 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
5034 ("cannot disambiguate function call and indexing", N);
5036 New_Subp := Relocate_Node (Subp);
5037 Set_Entity (Subp, Nam);
5039 if (Is_Array_Type (Ret_Type)
5040 and then Component_Type (Ret_Type) /= Any_Type)
5042 (Is_Access_Type (Ret_Type)
5044 Component_Type (Designated_Type (Ret_Type)) /= Any_Type)
5046 if Needs_No_Actuals (Nam) then
5048 -- Indexed call to a parameterless function
5051 Make_Indexed_Component (Loc,
5053 Make_Function_Call (Loc,
5055 Expressions => Parameter_Associations (N));
5057 -- An Ada 2005 prefixed call to a primitive operation
5058 -- whose first parameter is the prefix. This prefix was
5059 -- prepended to the parameter list, which is actually a
5060 -- list of indices. Remove the prefix in order to build
5061 -- the proper indexed component.
5064 Make_Indexed_Component (Loc,
5066 Make_Function_Call (Loc,
5068 Parameter_Associations =>
5070 (Remove_Head (Parameter_Associations (N)))),
5071 Expressions => Parameter_Associations (N));
5074 -- Since we are correcting a node classification error made
5075 -- by the parser, we call Replace rather than Rewrite.
5077 Replace (N, Index_Node);
5078 Set_Etype (Prefix (N), Ret_Type);
5080 Resolve_Indexed_Component (N, Typ);
5081 Check_Elab_Call (Prefix (N));
5089 Set_Etype (N, Etype (Nam));
5092 -- In the case where the call is to an overloaded subprogram, Analyze
5093 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5094 -- such a case Normalize_Actuals needs to be called once more to order
5095 -- the actuals correctly. Otherwise the call will have the ordering
5096 -- given by the last overloaded subprogram whether this is the correct
5097 -- one being called or not.
5099 if Is_Overloaded (Subp) then
5100 Normalize_Actuals (N, Nam, False, Norm_OK);
5101 pragma Assert (Norm_OK);
5104 -- In any case, call is fully resolved now. Reset Overload flag, to
5105 -- prevent subsequent overload resolution if node is analyzed again
5107 Set_Is_Overloaded (Subp, False);
5108 Set_Is_Overloaded (N, False);
5110 -- If we are calling the current subprogram from immediately within its
5111 -- body, then that is the case where we can sometimes detect cases of
5112 -- infinite recursion statically. Do not try this in case restriction
5113 -- No_Recursion is in effect anyway, and do it only for source calls.
5115 if Comes_From_Source (N) then
5116 Scop := Current_Scope;
5118 -- Issue warning for possible infinite recursion in the absence
5119 -- of the No_Recursion restriction.
5121 if Same_Or_Aliased_Subprograms (Nam, Scop)
5122 and then not Restriction_Active (No_Recursion)
5123 and then Check_Infinite_Recursion (N)
5125 -- Here we detected and flagged an infinite recursion, so we do
5126 -- not need to test the case below for further warnings. Also if
5127 -- we now have a raise SE node, we are all done.
5129 if Nkind (N) = N_Raise_Storage_Error then
5133 -- If call is to immediately containing subprogram, then check for
5134 -- the case of a possible run-time detectable infinite recursion.
5137 Scope_Loop : while Scop /= Standard_Standard loop
5138 if Same_Or_Aliased_Subprograms (Nam, Scop) then
5140 -- Although in general case, recursion is not statically
5141 -- checkable, the case of calling an immediately containing
5142 -- subprogram is easy to catch.
5144 Check_Restriction (No_Recursion, N);
5146 -- If the recursive call is to a parameterless subprogram,
5147 -- then even if we can't statically detect infinite
5148 -- recursion, this is pretty suspicious, and we output a
5149 -- warning. Furthermore, we will try later to detect some
5150 -- cases here at run time by expanding checking code (see
5151 -- Detect_Infinite_Recursion in package Exp_Ch6).
5153 -- If the recursive call is within a handler, do not emit a
5154 -- warning, because this is a common idiom: loop until input
5155 -- is correct, catch illegal input in handler and restart.
5157 if No (First_Formal (Nam))
5158 and then Etype (Nam) = Standard_Void_Type
5159 and then not Error_Posted (N)
5160 and then Nkind (Parent (N)) /= N_Exception_Handler
5162 -- For the case of a procedure call. We give the message
5163 -- only if the call is the first statement in a sequence
5164 -- of statements, or if all previous statements are
5165 -- simple assignments. This is simply a heuristic to
5166 -- decrease false positives, without losing too many good
5167 -- warnings. The idea is that these previous statements
5168 -- may affect global variables the procedure depends on.
5170 if Nkind (N) = N_Procedure_Call_Statement
5171 and then Is_List_Member (N)
5177 while Present (P) loop
5178 if Nkind (P) /= N_Assignment_Statement then
5187 -- Do not give warning if we are in a conditional context
5190 K : constant Node_Kind := Nkind (Parent (N));
5192 if (K = N_Loop_Statement
5193 and then Present (Iteration_Scheme (Parent (N))))
5194 or else K = N_If_Statement
5195 or else K = N_Elsif_Part
5196 or else K = N_Case_Statement_Alternative
5202 -- Here warning is to be issued
5204 Set_Has_Recursive_Call (Nam);
5206 ("?possible infinite recursion!", N);
5208 ("\?Storage_Error may be raised at run time!", N);
5214 Scop := Scope (Scop);
5215 end loop Scope_Loop;
5219 -- If subprogram name is a predefined operator, it was given in
5220 -- functional notation. Replace call node with operator node, so
5221 -- that actuals can be resolved appropriately.
5223 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5224 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5227 elsif Present (Alias (Nam))
5228 and then Is_Predefined_Op (Alias (Nam))
5230 Resolve_Actuals (N, Nam);
5231 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5235 -- Create a transient scope if the resulting type requires it
5237 -- There are several notable exceptions:
5239 -- a) In init procs, the transient scope overhead is not needed, and is
5240 -- even incorrect when the call is a nested initialization call for a
5241 -- component whose expansion may generate adjust calls. However, if the
5242 -- call is some other procedure call within an initialization procedure
5243 -- (for example a call to Create_Task in the init_proc of the task
5244 -- run-time record) a transient scope must be created around this call.
5246 -- b) Enumeration literal pseudo-calls need no transient scope
5248 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5249 -- functions) do not use the secondary stack even though the return
5250 -- type may be unconstrained.
5252 -- d) Calls to a build-in-place function, since such functions may
5253 -- allocate their result directly in a target object, and cases where
5254 -- the result does get allocated in the secondary stack are checked for
5255 -- within the specialized Exp_Ch6 procedures for expanding those
5256 -- build-in-place calls.
5258 -- e) If the subprogram is marked Inline_Always, then even if it returns
5259 -- an unconstrained type the call does not require use of the secondary
5260 -- stack. However, inlining will only take place if the body to inline
5261 -- is already present. It may not be available if e.g. the subprogram is
5262 -- declared in a child instance.
5264 -- If this is an initialization call for a type whose construction
5265 -- uses the secondary stack, and it is not a nested call to initialize
5266 -- a component, we do need to create a transient scope for it. We
5267 -- check for this by traversing the type in Check_Initialization_Call.
5270 and then Has_Pragma_Inline_Always (Nam)
5271 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5272 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5276 elsif Ekind (Nam) = E_Enumeration_Literal
5277 or else Is_Build_In_Place_Function (Nam)
5278 or else Is_Intrinsic_Subprogram (Nam)
5282 elsif Expander_Active
5283 and then Is_Type (Etype (Nam))
5284 and then Requires_Transient_Scope (Etype (Nam))
5286 (not Within_Init_Proc
5288 (not Is_Init_Proc (Nam) and then Ekind (Nam) /= E_Function))
5290 Establish_Transient_Scope (N, Sec_Stack => True);
5292 -- If the call appears within the bounds of a loop, it will
5293 -- be rewritten and reanalyzed, nothing left to do here.
5295 if Nkind (N) /= N_Function_Call then
5299 elsif Is_Init_Proc (Nam)
5300 and then not Within_Init_Proc
5302 Check_Initialization_Call (N, Nam);
5305 -- A protected function cannot be called within the definition of the
5306 -- enclosing protected type.
5308 if Is_Protected_Type (Scope (Nam))
5309 and then In_Open_Scopes (Scope (Nam))
5310 and then not Has_Completion (Scope (Nam))
5313 ("& cannot be called before end of protected definition", N, Nam);
5316 -- Propagate interpretation to actuals, and add default expressions
5319 if Present (First_Formal (Nam)) then
5320 Resolve_Actuals (N, Nam);
5322 -- Overloaded literals are rewritten as function calls, for purpose of
5323 -- resolution. After resolution, we can replace the call with the
5326 elsif Ekind (Nam) = E_Enumeration_Literal then
5327 Copy_Node (Subp, N);
5328 Resolve_Entity_Name (N, Typ);
5330 -- Avoid validation, since it is a static function call
5332 Generate_Reference (Nam, Subp);
5336 -- If the subprogram is not global, then kill all saved values and
5337 -- checks. This is a bit conservative, since in many cases we could do
5338 -- better, but it is not worth the effort. Similarly, we kill constant
5339 -- values. However we do not need to do this for internal entities
5340 -- (unless they are inherited user-defined subprograms), since they
5341 -- are not in the business of molesting local values.
5343 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5344 -- kill all checks and values for calls to global subprograms. This
5345 -- takes care of the case where an access to a local subprogram is
5346 -- taken, and could be passed directly or indirectly and then called
5347 -- from almost any context.
5349 -- Note: we do not do this step till after resolving the actuals. That
5350 -- way we still take advantage of the current value information while
5351 -- scanning the actuals.
5353 -- We suppress killing values if we are processing the nodes associated
5354 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5355 -- type kills all the values as part of analyzing the code that
5356 -- initializes the dispatch tables.
5358 if Inside_Freezing_Actions = 0
5359 and then (not Is_Library_Level_Entity (Nam)
5360 or else Suppress_Value_Tracking_On_Call
5361 (Nearest_Dynamic_Scope (Current_Scope)))
5362 and then (Comes_From_Source (Nam)
5363 or else (Present (Alias (Nam))
5364 and then Comes_From_Source (Alias (Nam))))
5366 Kill_Current_Values;
5369 -- If we are warning about unread OUT parameters, this is the place to
5370 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5371 -- after the above call to Kill_Current_Values (since that call clears
5372 -- the Last_Assignment field of all local variables).
5374 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5375 and then Comes_From_Source (N)
5376 and then In_Extended_Main_Source_Unit (N)
5383 F := First_Formal (Nam);
5384 A := First_Actual (N);
5385 while Present (F) and then Present (A) loop
5386 if (Ekind (F) = E_Out_Parameter
5388 Ekind (F) = E_In_Out_Parameter)
5389 and then Warn_On_Modified_As_Out_Parameter (F)
5390 and then Is_Entity_Name (A)
5391 and then Present (Entity (A))
5392 and then Comes_From_Source (N)
5393 and then Safe_To_Capture_Value (N, Entity (A))
5395 Set_Last_Assignment (Entity (A), A);
5404 -- If the subprogram is a primitive operation, check whether or not
5405 -- it is a correct dispatching call.
5407 if Is_Overloadable (Nam)
5408 and then Is_Dispatching_Operation (Nam)
5410 Check_Dispatching_Call (N);
5412 elsif Ekind (Nam) /= E_Subprogram_Type
5413 and then Is_Abstract_Subprogram (Nam)
5414 and then not In_Instance
5416 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5419 -- If this is a dispatching call, generate the appropriate reference,
5420 -- for better source navigation in GPS.
5422 if Is_Overloadable (Nam)
5423 and then Present (Controlling_Argument (N))
5425 Generate_Reference (Nam, Subp, 'R');
5427 -- Normal case, not a dispatching call
5430 Generate_Reference (Nam, Subp);
5433 if Is_Intrinsic_Subprogram (Nam) then
5434 Check_Intrinsic_Call (N);
5437 -- Check for violation of restriction No_Specific_Termination_Handlers
5438 -- and warn on a potentially blocking call to Abort_Task.
5440 if Is_RTE (Nam, RE_Set_Specific_Handler)
5442 Is_RTE (Nam, RE_Specific_Handler)
5444 Check_Restriction (No_Specific_Termination_Handlers, N);
5446 elsif Is_RTE (Nam, RE_Abort_Task) then
5447 Check_Potentially_Blocking_Operation (N);
5450 -- Issue an error for a call to an eliminated subprogram. We skip this
5451 -- in a spec expression, e.g. a call in a default parameter value, since
5452 -- we are not really doing a call at this time. That's important because
5453 -- the spec expression may itself belong to an eliminated subprogram.
5455 if not In_Spec_Expression then
5456 Check_For_Eliminated_Subprogram (Subp, Nam);
5459 -- All done, evaluate call and deal with elaboration issues
5462 Check_Elab_Call (N);
5463 Warn_On_Overlapping_Actuals (Nam, N);
5466 -------------------------------
5467 -- Resolve_Character_Literal --
5468 -------------------------------
5470 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5471 B_Typ : constant Entity_Id := Base_Type (Typ);
5475 -- Verify that the character does belong to the type of the context
5477 Set_Etype (N, B_Typ);
5478 Eval_Character_Literal (N);
5480 -- Wide_Wide_Character literals must always be defined, since the set
5481 -- of wide wide character literals is complete, i.e. if a character
5482 -- literal is accepted by the parser, then it is OK for wide wide
5483 -- character (out of range character literals are rejected).
5485 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5488 -- Always accept character literal for type Any_Character, which
5489 -- occurs in error situations and in comparisons of literals, both
5490 -- of which should accept all literals.
5492 elsif B_Typ = Any_Character then
5495 -- For Standard.Character or a type derived from it, check that
5496 -- the literal is in range
5498 elsif Root_Type (B_Typ) = Standard_Character then
5499 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5503 -- For Standard.Wide_Character or a type derived from it, check
5504 -- that the literal is in range
5506 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5507 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5511 -- For Standard.Wide_Wide_Character or a type derived from it, we
5512 -- know the literal is in range, since the parser checked!
5514 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5517 -- If the entity is already set, this has already been resolved in a
5518 -- generic context, or comes from expansion. Nothing else to do.
5520 elsif Present (Entity (N)) then
5523 -- Otherwise we have a user defined character type, and we can use the
5524 -- standard visibility mechanisms to locate the referenced entity.
5527 C := Current_Entity (N);
5528 while Present (C) loop
5529 if Etype (C) = B_Typ then
5530 Set_Entity_With_Style_Check (N, C);
5531 Generate_Reference (C, N);
5539 -- If we fall through, then the literal does not match any of the
5540 -- entries of the enumeration type. This isn't just a constraint
5541 -- error situation, it is an illegality (see RM 4.2).
5544 ("character not defined for }", N, First_Subtype (B_Typ));
5545 end Resolve_Character_Literal;
5547 ---------------------------
5548 -- Resolve_Comparison_Op --
5549 ---------------------------
5551 -- Context requires a boolean type, and plays no role in resolution.
5552 -- Processing identical to that for equality operators. The result
5553 -- type is the base type, which matters when pathological subtypes of
5554 -- booleans with limited ranges are used.
5556 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5557 L : constant Node_Id := Left_Opnd (N);
5558 R : constant Node_Id := Right_Opnd (N);
5562 -- If this is an intrinsic operation which is not predefined, use the
5563 -- types of its declared arguments to resolve the possibly overloaded
5564 -- operands. Otherwise the operands are unambiguous and specify the
5567 if Scope (Entity (N)) /= Standard_Standard then
5568 T := Etype (First_Entity (Entity (N)));
5571 T := Find_Unique_Type (L, R);
5573 if T = Any_Fixed then
5574 T := Unique_Fixed_Point_Type (L);
5578 Set_Etype (N, Base_Type (Typ));
5579 Generate_Reference (T, N, ' ');
5581 if T /= Any_Type then
5582 if T = Any_String or else
5583 T = Any_Composite or else
5586 if T = Any_Character then
5587 Ambiguous_Character (L);
5589 Error_Msg_N ("ambiguous operands for comparison", N);
5592 Set_Etype (N, Any_Type);
5598 Check_Unset_Reference (L);
5599 Check_Unset_Reference (R);
5600 Generate_Operator_Reference (N, T);
5601 Check_Low_Bound_Tested (N);
5602 Eval_Relational_Op (N);
5605 end Resolve_Comparison_Op;
5607 ------------------------------------
5608 -- Resolve_Conditional_Expression --
5609 ------------------------------------
5611 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
5612 Condition : constant Node_Id := First (Expressions (N));
5613 Then_Expr : constant Node_Id := Next (Condition);
5614 Else_Expr : Node_Id := Next (Then_Expr);
5617 Resolve (Condition, Any_Boolean);
5618 Resolve (Then_Expr, Typ);
5620 -- If ELSE expression present, just resolve using the determined type
5622 if Present (Else_Expr) then
5623 Resolve (Else_Expr, Typ);
5625 -- If no ELSE expression is present, root type must be Standard.Boolean
5626 -- and we provide a Standard.True result converted to the appropriate
5627 -- Boolean type (in case it is a derived boolean type).
5629 elsif Root_Type (Typ) = Standard_Boolean then
5631 Convert_To (Typ, New_Occurrence_Of (Standard_True, Sloc (N)));
5632 Analyze_And_Resolve (Else_Expr, Typ);
5633 Append_To (Expressions (N), Else_Expr);
5636 Error_Msg_N ("can only omit ELSE expression in Boolean case", N);
5637 Append_To (Expressions (N), Error);
5641 Eval_Conditional_Expression (N);
5642 end Resolve_Conditional_Expression;
5644 -----------------------------------------
5645 -- Resolve_Discrete_Subtype_Indication --
5646 -----------------------------------------
5648 procedure Resolve_Discrete_Subtype_Indication
5656 Analyze (Subtype_Mark (N));
5657 S := Entity (Subtype_Mark (N));
5659 if Nkind (Constraint (N)) /= N_Range_Constraint then
5660 Error_Msg_N ("expect range constraint for discrete type", N);
5661 Set_Etype (N, Any_Type);
5664 R := Range_Expression (Constraint (N));
5672 if Base_Type (S) /= Base_Type (Typ) then
5674 ("expect subtype of }", N, First_Subtype (Typ));
5676 -- Rewrite the constraint as a range of Typ
5677 -- to allow compilation to proceed further.
5680 Rewrite (Low_Bound (R),
5681 Make_Attribute_Reference (Sloc (Low_Bound (R)),
5682 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5683 Attribute_Name => Name_First));
5684 Rewrite (High_Bound (R),
5685 Make_Attribute_Reference (Sloc (High_Bound (R)),
5686 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5687 Attribute_Name => Name_First));
5691 Set_Etype (N, Etype (R));
5693 -- Additionally, we must check that the bounds are compatible
5694 -- with the given subtype, which might be different from the
5695 -- type of the context.
5697 Apply_Range_Check (R, S);
5699 -- ??? If the above check statically detects a Constraint_Error
5700 -- it replaces the offending bound(s) of the range R with a
5701 -- Constraint_Error node. When the itype which uses these bounds
5702 -- is frozen the resulting call to Duplicate_Subexpr generates
5703 -- a new temporary for the bounds.
5705 -- Unfortunately there are other itypes that are also made depend
5706 -- on these bounds, so when Duplicate_Subexpr is called they get
5707 -- a forward reference to the newly created temporaries and Gigi
5708 -- aborts on such forward references. This is probably sign of a
5709 -- more fundamental problem somewhere else in either the order of
5710 -- itype freezing or the way certain itypes are constructed.
5712 -- To get around this problem we call Remove_Side_Effects right
5713 -- away if either bounds of R are a Constraint_Error.
5716 L : constant Node_Id := Low_Bound (R);
5717 H : constant Node_Id := High_Bound (R);
5720 if Nkind (L) = N_Raise_Constraint_Error then
5721 Remove_Side_Effects (L);
5724 if Nkind (H) = N_Raise_Constraint_Error then
5725 Remove_Side_Effects (H);
5729 Check_Unset_Reference (Low_Bound (R));
5730 Check_Unset_Reference (High_Bound (R));
5733 end Resolve_Discrete_Subtype_Indication;
5735 -------------------------
5736 -- Resolve_Entity_Name --
5737 -------------------------
5739 -- Used to resolve identifiers and expanded names
5741 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
5742 E : constant Entity_Id := Entity (N);
5745 -- If garbage from errors, set to Any_Type and return
5747 if No (E) and then Total_Errors_Detected /= 0 then
5748 Set_Etype (N, Any_Type);
5752 -- Replace named numbers by corresponding literals. Note that this is
5753 -- the one case where Resolve_Entity_Name must reset the Etype, since
5754 -- it is currently marked as universal.
5756 if Ekind (E) = E_Named_Integer then
5758 Eval_Named_Integer (N);
5760 elsif Ekind (E) = E_Named_Real then
5762 Eval_Named_Real (N);
5764 -- Allow use of subtype only if it is a concurrent type where we are
5765 -- currently inside the body. This will eventually be expanded into a
5766 -- call to Self (for tasks) or _object (for protected objects). Any
5767 -- other use of a subtype is invalid.
5769 elsif Is_Type (E) then
5770 if Is_Concurrent_Type (E)
5771 and then In_Open_Scopes (E)
5776 ("invalid use of subtype mark in expression or call", N);
5779 -- Check discriminant use if entity is discriminant in current scope,
5780 -- i.e. discriminant of record or concurrent type currently being
5781 -- analyzed. Uses in corresponding body are unrestricted.
5783 elsif Ekind (E) = E_Discriminant
5784 and then Scope (E) = Current_Scope
5785 and then not Has_Completion (Current_Scope)
5787 Check_Discriminant_Use (N);
5789 -- A parameterless generic function cannot appear in a context that
5790 -- requires resolution.
5792 elsif Ekind (E) = E_Generic_Function then
5793 Error_Msg_N ("illegal use of generic function", N);
5795 elsif Ekind (E) = E_Out_Parameter
5796 and then Ada_Version = Ada_83
5797 and then (Nkind (Parent (N)) in N_Op
5798 or else (Nkind (Parent (N)) = N_Assignment_Statement
5799 and then N = Expression (Parent (N)))
5800 or else Nkind (Parent (N)) = N_Explicit_Dereference)
5802 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
5804 -- In all other cases, just do the possible static evaluation
5807 -- A deferred constant that appears in an expression must have a
5808 -- completion, unless it has been removed by in-place expansion of
5811 if Ekind (E) = E_Constant
5812 and then Comes_From_Source (E)
5813 and then No (Constant_Value (E))
5814 and then Is_Frozen (Etype (E))
5815 and then not In_Spec_Expression
5816 and then not Is_Imported (E)
5819 if No_Initialization (Parent (E))
5820 or else (Present (Full_View (E))
5821 and then No_Initialization (Parent (Full_View (E))))
5826 "deferred constant is frozen before completion", N);
5830 Eval_Entity_Name (N);
5832 end Resolve_Entity_Name;
5838 procedure Resolve_Entry (Entry_Name : Node_Id) is
5839 Loc : constant Source_Ptr := Sloc (Entry_Name);
5847 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
5848 -- If the bounds of the entry family being called depend on task
5849 -- discriminants, build a new index subtype where a discriminant is
5850 -- replaced with the value of the discriminant of the target task.
5851 -- The target task is the prefix of the entry name in the call.
5853 -----------------------
5854 -- Actual_Index_Type --
5855 -----------------------
5857 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
5858 Typ : constant Entity_Id := Entry_Index_Type (E);
5859 Tsk : constant Entity_Id := Scope (E);
5860 Lo : constant Node_Id := Type_Low_Bound (Typ);
5861 Hi : constant Node_Id := Type_High_Bound (Typ);
5864 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
5865 -- If the bound is given by a discriminant, replace with a reference
5866 -- to the discriminant of the same name in the target task. If the
5867 -- entry name is the target of a requeue statement and the entry is
5868 -- in the current protected object, the bound to be used is the
5869 -- discriminal of the object (see apply_range_checks for details of
5870 -- the transformation).
5872 -----------------------------
5873 -- Actual_Discriminant_Ref --
5874 -----------------------------
5876 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
5877 Typ : constant Entity_Id := Etype (Bound);
5881 Remove_Side_Effects (Bound);
5883 if not Is_Entity_Name (Bound)
5884 or else Ekind (Entity (Bound)) /= E_Discriminant
5888 elsif Is_Protected_Type (Tsk)
5889 and then In_Open_Scopes (Tsk)
5890 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
5892 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
5896 Make_Selected_Component (Loc,
5897 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
5898 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
5903 end Actual_Discriminant_Ref;
5905 -- Start of processing for Actual_Index_Type
5908 if not Has_Discriminants (Tsk)
5909 or else (not Is_Entity_Name (Lo)
5911 not Is_Entity_Name (Hi))
5913 return Entry_Index_Type (E);
5916 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
5917 Set_Etype (New_T, Base_Type (Typ));
5918 Set_Size_Info (New_T, Typ);
5919 Set_RM_Size (New_T, RM_Size (Typ));
5920 Set_Scalar_Range (New_T,
5921 Make_Range (Sloc (Entry_Name),
5922 Low_Bound => Actual_Discriminant_Ref (Lo),
5923 High_Bound => Actual_Discriminant_Ref (Hi)));
5927 end Actual_Index_Type;
5929 -- Start of processing of Resolve_Entry
5932 -- Find name of entry being called, and resolve prefix of name
5933 -- with its own type. The prefix can be overloaded, and the name
5934 -- and signature of the entry must be taken into account.
5936 if Nkind (Entry_Name) = N_Indexed_Component then
5938 -- Case of dealing with entry family within the current tasks
5940 E_Name := Prefix (Entry_Name);
5943 E_Name := Entry_Name;
5946 if Is_Entity_Name (E_Name) then
5948 -- Entry call to an entry (or entry family) in the current task. This
5949 -- is legal even though the task will deadlock. Rewrite as call to
5952 -- This can also be a call to an entry in an enclosing task. If this
5953 -- is a single task, we have to retrieve its name, because the scope
5954 -- of the entry is the task type, not the object. If the enclosing
5955 -- task is a task type, the identity of the task is given by its own
5958 -- Finally this can be a requeue on an entry of the same task or
5959 -- protected object.
5961 S := Scope (Entity (E_Name));
5963 for J in reverse 0 .. Scope_Stack.Last loop
5964 if Is_Task_Type (Scope_Stack.Table (J).Entity)
5965 and then not Comes_From_Source (S)
5967 -- S is an enclosing task or protected object. The concurrent
5968 -- declaration has been converted into a type declaration, and
5969 -- the object itself has an object declaration that follows
5970 -- the type in the same declarative part.
5972 Tsk := Next_Entity (S);
5973 while Etype (Tsk) /= S loop
5980 elsif S = Scope_Stack.Table (J).Entity then
5982 -- Call to current task. Will be transformed into call to Self
5990 Make_Selected_Component (Loc,
5991 Prefix => New_Occurrence_Of (S, Loc),
5993 New_Occurrence_Of (Entity (E_Name), Loc));
5994 Rewrite (E_Name, New_N);
5997 elsif Nkind (Entry_Name) = N_Selected_Component
5998 and then Is_Overloaded (Prefix (Entry_Name))
6000 -- Use the entry name (which must be unique at this point) to find
6001 -- the prefix that returns the corresponding task type or protected
6005 Pref : constant Node_Id := Prefix (Entry_Name);
6006 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
6011 Get_First_Interp (Pref, I, It);
6012 while Present (It.Typ) loop
6013 if Scope (Ent) = It.Typ then
6014 Set_Etype (Pref, It.Typ);
6018 Get_Next_Interp (I, It);
6023 if Nkind (Entry_Name) = N_Selected_Component then
6024 Resolve (Prefix (Entry_Name));
6026 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6027 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6028 Resolve (Prefix (Prefix (Entry_Name)));
6029 Index := First (Expressions (Entry_Name));
6030 Resolve (Index, Entry_Index_Type (Nam));
6032 -- Up to this point the expression could have been the actual in a
6033 -- simple entry call, and be given by a named association.
6035 if Nkind (Index) = N_Parameter_Association then
6036 Error_Msg_N ("expect expression for entry index", Index);
6038 Apply_Range_Check (Index, Actual_Index_Type (Nam));
6043 ------------------------
6044 -- Resolve_Entry_Call --
6045 ------------------------
6047 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
6048 Entry_Name : constant Node_Id := Name (N);
6049 Loc : constant Source_Ptr := Sloc (Entry_Name);
6051 First_Named : Node_Id;
6058 -- We kill all checks here, because it does not seem worth the effort to
6059 -- do anything better, an entry call is a big operation.
6063 -- Processing of the name is similar for entry calls and protected
6064 -- operation calls. Once the entity is determined, we can complete
6065 -- the resolution of the actuals.
6067 -- The selector may be overloaded, in the case of a protected object
6068 -- with overloaded functions. The type of the context is used for
6071 if Nkind (Entry_Name) = N_Selected_Component
6072 and then Is_Overloaded (Selector_Name (Entry_Name))
6073 and then Typ /= Standard_Void_Type
6080 Get_First_Interp (Selector_Name (Entry_Name), I, It);
6081 while Present (It.Typ) loop
6082 if Covers (Typ, It.Typ) then
6083 Set_Entity (Selector_Name (Entry_Name), It.Nam);
6084 Set_Etype (Entry_Name, It.Typ);
6086 Generate_Reference (It.Typ, N, ' ');
6089 Get_Next_Interp (I, It);
6094 Resolve_Entry (Entry_Name);
6096 if Nkind (Entry_Name) = N_Selected_Component then
6098 -- Simple entry call
6100 Nam := Entity (Selector_Name (Entry_Name));
6101 Obj := Prefix (Entry_Name);
6102 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
6104 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6106 -- Call to member of entry family
6108 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6109 Obj := Prefix (Prefix (Entry_Name));
6110 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
6113 -- We cannot in general check the maximum depth of protected entry
6114 -- calls at compile time. But we can tell that any protected entry
6115 -- call at all violates a specified nesting depth of zero.
6117 if Is_Protected_Type (Scope (Nam)) then
6118 Check_Restriction (Max_Entry_Queue_Length, N);
6121 -- Use context type to disambiguate a protected function that can be
6122 -- called without actuals and that returns an array type, and where
6123 -- the argument list may be an indexing of the returned value.
6125 if Ekind (Nam) = E_Function
6126 and then Needs_No_Actuals (Nam)
6127 and then Present (Parameter_Associations (N))
6129 ((Is_Array_Type (Etype (Nam))
6130 and then Covers (Typ, Component_Type (Etype (Nam))))
6132 or else (Is_Access_Type (Etype (Nam))
6133 and then Is_Array_Type (Designated_Type (Etype (Nam)))
6134 and then Covers (Typ,
6135 Component_Type (Designated_Type (Etype (Nam))))))
6138 Index_Node : Node_Id;
6142 Make_Indexed_Component (Loc,
6144 Make_Function_Call (Loc,
6145 Name => Relocate_Node (Entry_Name)),
6146 Expressions => Parameter_Associations (N));
6148 -- Since we are correcting a node classification error made by
6149 -- the parser, we call Replace rather than Rewrite.
6151 Replace (N, Index_Node);
6152 Set_Etype (Prefix (N), Etype (Nam));
6154 Resolve_Indexed_Component (N, Typ);
6159 -- The operation name may have been overloaded. Order the actuals
6160 -- according to the formals of the resolved entity, and set the
6161 -- return type to that of the operation.
6164 Normalize_Actuals (N, Nam, False, Norm_OK);
6165 pragma Assert (Norm_OK);
6166 Set_Etype (N, Etype (Nam));
6169 Resolve_Actuals (N, Nam);
6170 Generate_Reference (Nam, Entry_Name);
6172 if Ekind_In (Nam, E_Entry, E_Entry_Family) then
6173 Check_Potentially_Blocking_Operation (N);
6176 -- Verify that a procedure call cannot masquerade as an entry
6177 -- call where an entry call is expected.
6179 if Ekind (Nam) = E_Procedure then
6180 if Nkind (Parent (N)) = N_Entry_Call_Alternative
6181 and then N = Entry_Call_Statement (Parent (N))
6183 Error_Msg_N ("entry call required in select statement", N);
6185 elsif Nkind (Parent (N)) = N_Triggering_Alternative
6186 and then N = Triggering_Statement (Parent (N))
6188 Error_Msg_N ("triggering statement cannot be procedure call", N);
6190 elsif Ekind (Scope (Nam)) = E_Task_Type
6191 and then not In_Open_Scopes (Scope (Nam))
6193 Error_Msg_N ("task has no entry with this name", Entry_Name);
6197 -- After resolution, entry calls and protected procedure calls are
6198 -- changed into entry calls, for expansion. The structure of the node
6199 -- does not change, so it can safely be done in place. Protected
6200 -- function calls must keep their structure because they are
6203 if Ekind (Nam) /= E_Function then
6205 -- A protected operation that is not a function may modify the
6206 -- corresponding object, and cannot apply to a constant. If this
6207 -- is an internal call, the prefix is the type itself.
6209 if Is_Protected_Type (Scope (Nam))
6210 and then not Is_Variable (Obj)
6211 and then (not Is_Entity_Name (Obj)
6212 or else not Is_Type (Entity (Obj)))
6215 ("prefix of protected procedure or entry call must be variable",
6219 Actuals := Parameter_Associations (N);
6220 First_Named := First_Named_Actual (N);
6223 Make_Entry_Call_Statement (Loc,
6225 Parameter_Associations => Actuals));
6227 Set_First_Named_Actual (N, First_Named);
6228 Set_Analyzed (N, True);
6230 -- Protected functions can return on the secondary stack, in which
6231 -- case we must trigger the transient scope mechanism.
6233 elsif Expander_Active
6234 and then Requires_Transient_Scope (Etype (Nam))
6236 Establish_Transient_Scope (N, Sec_Stack => True);
6238 end Resolve_Entry_Call;
6240 -------------------------
6241 -- Resolve_Equality_Op --
6242 -------------------------
6244 -- Both arguments must have the same type, and the boolean context does
6245 -- not participate in the resolution. The first pass verifies that the
6246 -- interpretation is not ambiguous, and the type of the left argument is
6247 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6248 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6249 -- though they carry a single (universal) type. Diagnose this case here.
6251 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6252 L : constant Node_Id := Left_Opnd (N);
6253 R : constant Node_Id := Right_Opnd (N);
6254 T : Entity_Id := Find_Unique_Type (L, R);
6256 function Find_Unique_Access_Type return Entity_Id;
6257 -- In the case of allocators, make a last-ditch attempt to find a single
6258 -- access type with the right designated type. This is semantically
6259 -- dubious, and of no interest to any real code, but c48008a makes it
6262 -----------------------------
6263 -- Find_Unique_Access_Type --
6264 -----------------------------
6266 function Find_Unique_Access_Type return Entity_Id is
6272 if Ekind (Etype (R)) = E_Allocator_Type then
6273 Acc := Designated_Type (Etype (R));
6274 elsif Ekind (Etype (L)) = E_Allocator_Type then
6275 Acc := Designated_Type (Etype (L));
6281 while S /= Standard_Standard loop
6282 E := First_Entity (S);
6283 while Present (E) loop
6285 and then Is_Access_Type (E)
6286 and then Ekind (E) /= E_Allocator_Type
6287 and then Designated_Type (E) = Base_Type (Acc)
6299 end Find_Unique_Access_Type;
6301 -- Start of processing for Resolve_Equality_Op
6304 Set_Etype (N, Base_Type (Typ));
6305 Generate_Reference (T, N, ' ');
6307 if T = Any_Fixed then
6308 T := Unique_Fixed_Point_Type (L);
6311 if T /= Any_Type then
6313 or else T = Any_Composite
6314 or else T = Any_Character
6316 if T = Any_Character then
6317 Ambiguous_Character (L);
6319 Error_Msg_N ("ambiguous operands for equality", N);
6322 Set_Etype (N, Any_Type);
6325 elsif T = Any_Access
6326 or else Ekind (T) = E_Allocator_Type
6327 or else Ekind (T) = E_Access_Attribute_Type
6329 T := Find_Unique_Access_Type;
6332 Error_Msg_N ("ambiguous operands for equality", N);
6333 Set_Etype (N, Any_Type);
6341 -- If the unique type is a class-wide type then it will be expanded
6342 -- into a dispatching call to the predefined primitive. Therefore we
6343 -- check here for potential violation of such restriction.
6345 if Is_Class_Wide_Type (T) then
6346 Check_Restriction (No_Dispatching_Calls, N);
6349 if Warn_On_Redundant_Constructs
6350 and then Comes_From_Source (N)
6351 and then Is_Entity_Name (R)
6352 and then Entity (R) = Standard_True
6353 and then Comes_From_Source (R)
6355 Error_Msg_N ("?comparison with True is redundant!", R);
6358 Check_Unset_Reference (L);
6359 Check_Unset_Reference (R);
6360 Generate_Operator_Reference (N, T);
6361 Check_Low_Bound_Tested (N);
6363 -- If this is an inequality, it may be the implicit inequality
6364 -- created for a user-defined operation, in which case the corres-
6365 -- ponding equality operation is not intrinsic, and the operation
6366 -- cannot be constant-folded. Else fold.
6368 if Nkind (N) = N_Op_Eq
6369 or else Comes_From_Source (Entity (N))
6370 or else Ekind (Entity (N)) = E_Operator
6371 or else Is_Intrinsic_Subprogram
6372 (Corresponding_Equality (Entity (N)))
6374 Eval_Relational_Op (N);
6376 elsif Nkind (N) = N_Op_Ne
6377 and then Is_Abstract_Subprogram (Entity (N))
6379 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6382 -- Ada 2005: If one operand is an anonymous access type, convert the
6383 -- other operand to it, to ensure that the underlying types match in
6384 -- the back-end. Same for access_to_subprogram, and the conversion
6385 -- verifies that the types are subtype conformant.
6387 -- We apply the same conversion in the case one of the operands is a
6388 -- private subtype of the type of the other.
6390 -- Why the Expander_Active test here ???
6394 (Ekind (T) = E_Anonymous_Access_Type
6395 or else Ekind (T) = E_Anonymous_Access_Subprogram_Type
6396 or else Is_Private_Type (T))
6398 if Etype (L) /= T then
6400 Make_Unchecked_Type_Conversion (Sloc (L),
6401 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6402 Expression => Relocate_Node (L)));
6403 Analyze_And_Resolve (L, T);
6406 if (Etype (R)) /= T then
6408 Make_Unchecked_Type_Conversion (Sloc (R),
6409 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6410 Expression => Relocate_Node (R)));
6411 Analyze_And_Resolve (R, T);
6415 end Resolve_Equality_Op;
6417 ----------------------------------
6418 -- Resolve_Explicit_Dereference --
6419 ----------------------------------
6421 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6422 Loc : constant Source_Ptr := Sloc (N);
6424 P : constant Node_Id := Prefix (N);
6429 Check_Fully_Declared_Prefix (Typ, P);
6431 if Is_Overloaded (P) then
6433 -- Use the context type to select the prefix that has the correct
6436 Get_First_Interp (P, I, It);
6437 while Present (It.Typ) loop
6438 exit when Is_Access_Type (It.Typ)
6439 and then Covers (Typ, Designated_Type (It.Typ));
6440 Get_Next_Interp (I, It);
6443 if Present (It.Typ) then
6444 Resolve (P, It.Typ);
6446 -- If no interpretation covers the designated type of the prefix,
6447 -- this is the pathological case where not all implementations of
6448 -- the prefix allow the interpretation of the node as a call. Now
6449 -- that the expected type is known, Remove other interpretations
6450 -- from prefix, rewrite it as a call, and resolve again, so that
6451 -- the proper call node is generated.
6453 Get_First_Interp (P, I, It);
6454 while Present (It.Typ) loop
6455 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6459 Get_Next_Interp (I, It);
6463 Make_Function_Call (Loc,
6465 Make_Explicit_Dereference (Loc,
6467 Parameter_Associations => New_List);
6469 Save_Interps (N, New_N);
6471 Analyze_And_Resolve (N, Typ);
6475 Set_Etype (N, Designated_Type (It.Typ));
6481 if Is_Access_Type (Etype (P)) then
6482 Apply_Access_Check (N);
6485 -- If the designated type is a packed unconstrained array type, and the
6486 -- explicit dereference is not in the context of an attribute reference,
6487 -- then we must compute and set the actual subtype, since it is needed
6488 -- by Gigi. The reason we exclude the attribute case is that this is
6489 -- handled fine by Gigi, and in fact we use such attributes to build the
6490 -- actual subtype. We also exclude generated code (which builds actual
6491 -- subtypes directly if they are needed).
6493 if Is_Array_Type (Etype (N))
6494 and then Is_Packed (Etype (N))
6495 and then not Is_Constrained (Etype (N))
6496 and then Nkind (Parent (N)) /= N_Attribute_Reference
6497 and then Comes_From_Source (N)
6499 Set_Etype (N, Get_Actual_Subtype (N));
6502 -- Note: No Eval processing is required for an explicit dereference,
6503 -- because such a name can never be static.
6505 end Resolve_Explicit_Dereference;
6507 -------------------------------------
6508 -- Resolve_Expression_With_Actions --
6509 -------------------------------------
6511 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id) is
6514 end Resolve_Expression_With_Actions;
6516 -------------------------------
6517 -- Resolve_Indexed_Component --
6518 -------------------------------
6520 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
6521 Name : constant Node_Id := Prefix (N);
6523 Array_Type : Entity_Id := Empty; -- to prevent junk warning
6527 if Is_Overloaded (Name) then
6529 -- Use the context type to select the prefix that yields the correct
6535 I1 : Interp_Index := 0;
6536 P : constant Node_Id := Prefix (N);
6537 Found : Boolean := False;
6540 Get_First_Interp (P, I, It);
6541 while Present (It.Typ) loop
6542 if (Is_Array_Type (It.Typ)
6543 and then Covers (Typ, Component_Type (It.Typ)))
6544 or else (Is_Access_Type (It.Typ)
6545 and then Is_Array_Type (Designated_Type (It.Typ))
6547 (Typ, Component_Type (Designated_Type (It.Typ))))
6550 It := Disambiguate (P, I1, I, Any_Type);
6552 if It = No_Interp then
6553 Error_Msg_N ("ambiguous prefix for indexing", N);
6559 Array_Type := It.Typ;
6565 Array_Type := It.Typ;
6570 Get_Next_Interp (I, It);
6575 Array_Type := Etype (Name);
6578 Resolve (Name, Array_Type);
6579 Array_Type := Get_Actual_Subtype_If_Available (Name);
6581 -- If prefix is access type, dereference to get real array type.
6582 -- Note: we do not apply an access check because the expander always
6583 -- introduces an explicit dereference, and the check will happen there.
6585 if Is_Access_Type (Array_Type) then
6586 Array_Type := Designated_Type (Array_Type);
6589 -- If name was overloaded, set component type correctly now
6590 -- If a misplaced call to an entry family (which has no index types)
6591 -- return. Error will be diagnosed from calling context.
6593 if Is_Array_Type (Array_Type) then
6594 Set_Etype (N, Component_Type (Array_Type));
6599 Index := First_Index (Array_Type);
6600 Expr := First (Expressions (N));
6602 -- The prefix may have resolved to a string literal, in which case its
6603 -- etype has a special representation. This is only possible currently
6604 -- if the prefix is a static concatenation, written in functional
6607 if Ekind (Array_Type) = E_String_Literal_Subtype then
6608 Resolve (Expr, Standard_Positive);
6611 while Present (Index) and Present (Expr) loop
6612 Resolve (Expr, Etype (Index));
6613 Check_Unset_Reference (Expr);
6615 if Is_Scalar_Type (Etype (Expr)) then
6616 Apply_Scalar_Range_Check (Expr, Etype (Index));
6618 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
6626 -- Do not generate the warning on suspicious index if we are analyzing
6627 -- package Ada.Tags; otherwise we will report the warning with the
6628 -- Prims_Ptr field of the dispatch table.
6630 if Scope (Etype (Prefix (N))) = Standard_Standard
6632 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
6635 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
6636 Eval_Indexed_Component (N);
6639 -- If the array type is atomic, and is packed, and we are in a left side
6640 -- context, then this is worth a warning, since we have a situation
6641 -- where the access to the component may cause extra read/writes of
6642 -- the atomic array object, which could be considered unexpected.
6644 if Nkind (N) = N_Indexed_Component
6645 and then (Is_Atomic (Array_Type)
6646 or else (Is_Entity_Name (Prefix (N))
6647 and then Is_Atomic (Entity (Prefix (N)))))
6648 and then Is_Bit_Packed_Array (Array_Type)
6651 Error_Msg_N ("?assignment to component of packed atomic array",
6653 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
6656 end Resolve_Indexed_Component;
6658 -----------------------------
6659 -- Resolve_Integer_Literal --
6660 -----------------------------
6662 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
6665 Eval_Integer_Literal (N);
6666 end Resolve_Integer_Literal;
6668 --------------------------------
6669 -- Resolve_Intrinsic_Operator --
6670 --------------------------------
6672 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
6673 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6680 while Scope (Op) /= Standard_Standard loop
6682 pragma Assert (Present (Op));
6686 Set_Is_Overloaded (N, False);
6688 -- If the operand type is private, rewrite with suitable conversions on
6689 -- the operands and the result, to expose the proper underlying numeric
6692 if Is_Private_Type (Typ) then
6693 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
6695 if Nkind (N) = N_Op_Expon then
6696 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
6698 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6701 Save_Interps (Left_Opnd (N), Expression (Arg1));
6702 Save_Interps (Right_Opnd (N), Expression (Arg2));
6704 Set_Left_Opnd (N, Arg1);
6705 Set_Right_Opnd (N, Arg2);
6707 Set_Etype (N, Btyp);
6708 Rewrite (N, Unchecked_Convert_To (Typ, N));
6711 elsif Typ /= Etype (Left_Opnd (N))
6712 or else Typ /= Etype (Right_Opnd (N))
6714 -- Add explicit conversion where needed, and save interpretations in
6715 -- case operands are overloaded.
6717 Arg1 := Convert_To (Typ, Left_Opnd (N));
6718 Arg2 := Convert_To (Typ, Right_Opnd (N));
6720 if Nkind (Arg1) = N_Type_Conversion then
6721 Save_Interps (Left_Opnd (N), Expression (Arg1));
6723 Save_Interps (Left_Opnd (N), Arg1);
6726 if Nkind (Arg2) = N_Type_Conversion then
6727 Save_Interps (Right_Opnd (N), Expression (Arg2));
6729 Save_Interps (Right_Opnd (N), Arg2);
6732 Rewrite (Left_Opnd (N), Arg1);
6733 Rewrite (Right_Opnd (N), Arg2);
6736 Resolve_Arithmetic_Op (N, Typ);
6739 Resolve_Arithmetic_Op (N, Typ);
6741 end Resolve_Intrinsic_Operator;
6743 --------------------------------------
6744 -- Resolve_Intrinsic_Unary_Operator --
6745 --------------------------------------
6747 procedure Resolve_Intrinsic_Unary_Operator
6751 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6757 while Scope (Op) /= Standard_Standard loop
6759 pragma Assert (Present (Op));
6764 if Is_Private_Type (Typ) then
6765 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6766 Save_Interps (Right_Opnd (N), Expression (Arg2));
6768 Set_Right_Opnd (N, Arg2);
6770 Set_Etype (N, Btyp);
6771 Rewrite (N, Unchecked_Convert_To (Typ, N));
6775 Resolve_Unary_Op (N, Typ);
6777 end Resolve_Intrinsic_Unary_Operator;
6779 ------------------------
6780 -- Resolve_Logical_Op --
6781 ------------------------
6783 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
6787 Check_No_Direct_Boolean_Operators (N);
6789 -- Predefined operations on scalar types yield the base type. On the
6790 -- other hand, logical operations on arrays yield the type of the
6791 -- arguments (and the context).
6793 if Is_Array_Type (Typ) then
6796 B_Typ := Base_Type (Typ);
6799 -- OK if this is a VMS-specific intrinsic operation
6801 if Is_VMS_Operator (Entity (N)) then
6804 -- The following test is required because the operands of the operation
6805 -- may be literals, in which case the resulting type appears to be
6806 -- compatible with a signed integer type, when in fact it is compatible
6807 -- only with modular types. If the context itself is universal, the
6808 -- operation is illegal.
6810 elsif not Valid_Boolean_Arg (Typ) then
6811 Error_Msg_N ("invalid context for logical operation", N);
6812 Set_Etype (N, Any_Type);
6815 elsif Typ = Any_Modular then
6817 ("no modular type available in this context", N);
6818 Set_Etype (N, Any_Type);
6820 elsif Is_Modular_Integer_Type (Typ)
6821 and then Etype (Left_Opnd (N)) = Universal_Integer
6822 and then Etype (Right_Opnd (N)) = Universal_Integer
6824 Check_For_Visible_Operator (N, B_Typ);
6827 Resolve (Left_Opnd (N), B_Typ);
6828 Resolve (Right_Opnd (N), B_Typ);
6830 Check_Unset_Reference (Left_Opnd (N));
6831 Check_Unset_Reference (Right_Opnd (N));
6833 Set_Etype (N, B_Typ);
6834 Generate_Operator_Reference (N, B_Typ);
6835 Eval_Logical_Op (N);
6836 end Resolve_Logical_Op;
6838 ---------------------------
6839 -- Resolve_Membership_Op --
6840 ---------------------------
6842 -- The context can only be a boolean type, and does not determine
6843 -- the arguments. Arguments should be unambiguous, but the preference
6844 -- rule for universal types applies.
6846 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
6847 pragma Warnings (Off, Typ);
6849 L : constant Node_Id := Left_Opnd (N);
6850 R : constant Node_Id := Right_Opnd (N);
6853 procedure Resolve_Set_Membership;
6854 -- Analysis has determined a unique type for the left operand.
6855 -- Use it to resolve the disjuncts.
6857 ----------------------------
6858 -- Resolve_Set_Membership --
6859 ----------------------------
6861 procedure Resolve_Set_Membership is
6865 Resolve (L, Etype (L));
6867 Alt := First (Alternatives (N));
6868 while Present (Alt) loop
6870 -- Alternative is an expression, a range
6871 -- or a subtype mark.
6873 if not Is_Entity_Name (Alt)
6874 or else not Is_Type (Entity (Alt))
6876 Resolve (Alt, Etype (L));
6881 end Resolve_Set_Membership;
6883 -- Start of processing for Resolve_Membership_Op
6886 if L = Error or else R = Error then
6890 if Present (Alternatives (N)) then
6891 Resolve_Set_Membership;
6894 elsif not Is_Overloaded (R)
6896 (Etype (R) = Universal_Integer or else
6897 Etype (R) = Universal_Real)
6898 and then Is_Overloaded (L)
6902 -- Ada 2005 (AI-251): Support the following case:
6904 -- type I is interface;
6905 -- type T is tagged ...
6907 -- function Test (O : I'Class) is
6909 -- return O in T'Class.
6912 -- In this case we have nothing else to do. The membership test will be
6913 -- done at run-time.
6915 elsif Ada_Version >= Ada_05
6916 and then Is_Class_Wide_Type (Etype (L))
6917 and then Is_Interface (Etype (L))
6918 and then Is_Class_Wide_Type (Etype (R))
6919 and then not Is_Interface (Etype (R))
6924 T := Intersect_Types (L, R);
6928 Check_Unset_Reference (L);
6930 if Nkind (R) = N_Range
6931 and then not Is_Scalar_Type (T)
6933 Error_Msg_N ("scalar type required for range", R);
6936 if Is_Entity_Name (R) then
6937 Freeze_Expression (R);
6940 Check_Unset_Reference (R);
6943 Eval_Membership_Op (N);
6944 end Resolve_Membership_Op;
6950 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
6951 Loc : constant Source_Ptr := Sloc (N);
6954 -- Handle restriction against anonymous null access values This
6955 -- restriction can be turned off using -gnatdj.
6957 -- Ada 2005 (AI-231): Remove restriction
6959 if Ada_Version < Ada_05
6960 and then not Debug_Flag_J
6961 and then Ekind (Typ) = E_Anonymous_Access_Type
6962 and then Comes_From_Source (N)
6964 -- In the common case of a call which uses an explicitly null value
6965 -- for an access parameter, give specialized error message.
6967 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
6971 ("null is not allowed as argument for an access parameter", N);
6973 -- Standard message for all other cases (are there any?)
6977 ("null cannot be of an anonymous access type", N);
6981 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
6982 -- assignment to a null-excluding object
6984 if Ada_Version >= Ada_05
6985 and then Can_Never_Be_Null (Typ)
6986 and then Nkind (Parent (N)) = N_Assignment_Statement
6988 if not Inside_Init_Proc then
6990 (Compile_Time_Constraint_Error (N,
6991 "(Ada 2005) null not allowed in null-excluding objects?"),
6992 Make_Raise_Constraint_Error (Loc,
6993 Reason => CE_Access_Check_Failed));
6996 Make_Raise_Constraint_Error (Loc,
6997 Reason => CE_Access_Check_Failed));
7001 -- In a distributed context, null for a remote access to subprogram may
7002 -- need to be replaced with a special record aggregate. In this case,
7003 -- return after having done the transformation.
7005 if (Ekind (Typ) = E_Record_Type
7006 or else Is_Remote_Access_To_Subprogram_Type (Typ))
7007 and then Remote_AST_Null_Value (N, Typ)
7012 -- The null literal takes its type from the context
7017 -----------------------
7018 -- Resolve_Op_Concat --
7019 -----------------------
7021 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
7023 -- We wish to avoid deep recursion, because concatenations are often
7024 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
7025 -- operands nonrecursively until we find something that is not a simple
7026 -- concatenation (A in this case). We resolve that, and then walk back
7027 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
7028 -- to do the rest of the work at each level. The Parent pointers allow
7029 -- us to avoid recursion, and thus avoid running out of memory. See also
7030 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
7036 -- The following code is equivalent to:
7038 -- Resolve_Op_Concat_First (NN, Typ);
7039 -- Resolve_Op_Concat_Arg (N, ...);
7040 -- Resolve_Op_Concat_Rest (N, Typ);
7042 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
7043 -- operand is a concatenation.
7045 -- Walk down left operands
7048 Resolve_Op_Concat_First (NN, Typ);
7049 Op1 := Left_Opnd (NN);
7050 exit when not (Nkind (Op1) = N_Op_Concat
7051 and then not Is_Array_Type (Component_Type (Typ))
7052 and then Entity (Op1) = Entity (NN));
7056 -- Now (given the above example) NN is A&B and Op1 is A
7058 -- First resolve Op1 ...
7060 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
7062 -- ... then walk NN back up until we reach N (where we started), calling
7063 -- Resolve_Op_Concat_Rest along the way.
7066 Resolve_Op_Concat_Rest (NN, Typ);
7070 end Resolve_Op_Concat;
7072 ---------------------------
7073 -- Resolve_Op_Concat_Arg --
7074 ---------------------------
7076 procedure Resolve_Op_Concat_Arg
7082 Btyp : constant Entity_Id := Base_Type (Typ);
7087 or else (not Is_Overloaded (Arg)
7088 and then Etype (Arg) /= Any_Composite
7089 and then Covers (Component_Type (Typ), Etype (Arg)))
7091 Resolve (Arg, Component_Type (Typ));
7093 Resolve (Arg, Btyp);
7096 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
7097 if Nkind (Arg) = N_Aggregate
7098 and then Is_Composite_Type (Component_Type (Typ))
7100 if Is_Private_Type (Component_Type (Typ)) then
7101 Resolve (Arg, Btyp);
7103 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
7104 Set_Etype (Arg, Any_Type);
7108 if Is_Overloaded (Arg)
7109 and then Has_Compatible_Type (Arg, Typ)
7110 and then Etype (Arg) /= Any_Type
7118 Get_First_Interp (Arg, I, It);
7120 Get_Next_Interp (I, It);
7122 -- Special-case the error message when the overloading is
7123 -- caused by a function that yields an array and can be
7124 -- called without parameters.
7126 if It.Nam = Func then
7127 Error_Msg_Sloc := Sloc (Func);
7128 Error_Msg_N ("ambiguous call to function#", Arg);
7130 ("\\interpretation as call yields&", Arg, Typ);
7132 ("\\interpretation as indexing of call yields&",
7133 Arg, Component_Type (Typ));
7137 ("ambiguous operand for concatenation!", Arg);
7138 Get_First_Interp (Arg, I, It);
7139 while Present (It.Nam) loop
7140 Error_Msg_Sloc := Sloc (It.Nam);
7142 if Base_Type (It.Typ) = Base_Type (Typ)
7143 or else Base_Type (It.Typ) =
7144 Base_Type (Component_Type (Typ))
7146 Error_Msg_N -- CODEFIX
7147 ("\\possible interpretation#", Arg);
7150 Get_Next_Interp (I, It);
7156 Resolve (Arg, Component_Type (Typ));
7158 if Nkind (Arg) = N_String_Literal then
7159 Set_Etype (Arg, Component_Type (Typ));
7162 if Arg = Left_Opnd (N) then
7163 Set_Is_Component_Left_Opnd (N);
7165 Set_Is_Component_Right_Opnd (N);
7170 Resolve (Arg, Btyp);
7173 Check_Unset_Reference (Arg);
7174 end Resolve_Op_Concat_Arg;
7176 -----------------------------
7177 -- Resolve_Op_Concat_First --
7178 -----------------------------
7180 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
7181 Btyp : constant Entity_Id := Base_Type (Typ);
7182 Op1 : constant Node_Id := Left_Opnd (N);
7183 Op2 : constant Node_Id := Right_Opnd (N);
7186 -- The parser folds an enormous sequence of concatenations of string
7187 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
7188 -- in the right operand. If the expression resolves to a predefined "&"
7189 -- operator, all is well. Otherwise, the parser's folding is wrong, so
7190 -- we give an error. See P_Simple_Expression in Par.Ch4.
7192 if Nkind (Op2) = N_String_Literal
7193 and then Is_Folded_In_Parser (Op2)
7194 and then Ekind (Entity (N)) = E_Function
7196 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
7197 and then String_Length (Strval (Op1)) = 0);
7198 Error_Msg_N ("too many user-defined concatenations", N);
7202 Set_Etype (N, Btyp);
7204 if Is_Limited_Composite (Btyp) then
7205 Error_Msg_N ("concatenation not available for limited array", N);
7206 Explain_Limited_Type (Btyp, N);
7208 end Resolve_Op_Concat_First;
7210 ----------------------------
7211 -- Resolve_Op_Concat_Rest --
7212 ----------------------------
7214 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
7215 Op1 : constant Node_Id := Left_Opnd (N);
7216 Op2 : constant Node_Id := Right_Opnd (N);
7219 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
7221 Generate_Operator_Reference (N, Typ);
7223 if Is_String_Type (Typ) then
7224 Eval_Concatenation (N);
7227 -- If this is not a static concatenation, but the result is a string
7228 -- type (and not an array of strings) ensure that static string operands
7229 -- have their subtypes properly constructed.
7231 if Nkind (N) /= N_String_Literal
7232 and then Is_Character_Type (Component_Type (Typ))
7234 Set_String_Literal_Subtype (Op1, Typ);
7235 Set_String_Literal_Subtype (Op2, Typ);
7237 end Resolve_Op_Concat_Rest;
7239 ----------------------
7240 -- Resolve_Op_Expon --
7241 ----------------------
7243 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
7244 B_Typ : constant Entity_Id := Base_Type (Typ);
7247 -- Catch attempts to do fixed-point exponentiation with universal
7248 -- operands, which is a case where the illegality is not caught during
7249 -- normal operator analysis.
7251 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
7252 Error_Msg_N ("exponentiation not available for fixed point", N);
7256 if Comes_From_Source (N)
7257 and then Ekind (Entity (N)) = E_Function
7258 and then Is_Imported (Entity (N))
7259 and then Is_Intrinsic_Subprogram (Entity (N))
7261 Resolve_Intrinsic_Operator (N, Typ);
7265 if Etype (Left_Opnd (N)) = Universal_Integer
7266 or else Etype (Left_Opnd (N)) = Universal_Real
7268 Check_For_Visible_Operator (N, B_Typ);
7271 -- We do the resolution using the base type, because intermediate values
7272 -- in expressions always are of the base type, not a subtype of it.
7274 Resolve (Left_Opnd (N), B_Typ);
7275 Resolve (Right_Opnd (N), Standard_Integer);
7277 Check_Unset_Reference (Left_Opnd (N));
7278 Check_Unset_Reference (Right_Opnd (N));
7280 Set_Etype (N, B_Typ);
7281 Generate_Operator_Reference (N, B_Typ);
7284 -- Set overflow checking bit. Much cleverer code needed here eventually
7285 -- and perhaps the Resolve routines should be separated for the various
7286 -- arithmetic operations, since they will need different processing. ???
7288 if Nkind (N) in N_Op then
7289 if not Overflow_Checks_Suppressed (Etype (N)) then
7290 Enable_Overflow_Check (N);
7293 end Resolve_Op_Expon;
7295 --------------------
7296 -- Resolve_Op_Not --
7297 --------------------
7299 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
7302 function Parent_Is_Boolean return Boolean;
7303 -- This function determines if the parent node is a boolean operator
7304 -- or operation (comparison op, membership test, or short circuit form)
7305 -- and the not in question is the left operand of this operation.
7306 -- Note that if the not is in parens, then false is returned.
7308 -----------------------
7309 -- Parent_Is_Boolean --
7310 -----------------------
7312 function Parent_Is_Boolean return Boolean is
7314 if Paren_Count (N) /= 0 then
7318 case Nkind (Parent (N)) is
7333 return Left_Opnd (Parent (N)) = N;
7339 end Parent_Is_Boolean;
7341 -- Start of processing for Resolve_Op_Not
7344 -- Predefined operations on scalar types yield the base type. On the
7345 -- other hand, logical operations on arrays yield the type of the
7346 -- arguments (and the context).
7348 if Is_Array_Type (Typ) then
7351 B_Typ := Base_Type (Typ);
7354 if Is_VMS_Operator (Entity (N)) then
7357 -- Straightforward case of incorrect arguments
7359 elsif not Valid_Boolean_Arg (Typ) then
7360 Error_Msg_N ("invalid operand type for operator&", N);
7361 Set_Etype (N, Any_Type);
7364 -- Special case of probable missing parens
7366 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7367 if Parent_Is_Boolean then
7369 ("operand of not must be enclosed in parentheses",
7373 ("no modular type available in this context", N);
7376 Set_Etype (N, Any_Type);
7379 -- OK resolution of not
7382 -- Warn if non-boolean types involved. This is a case like not a < b
7383 -- where a and b are modular, where we will get (not a) < b and most
7384 -- likely not (a < b) was intended.
7386 if Warn_On_Questionable_Missing_Parens
7387 and then not Is_Boolean_Type (Typ)
7388 and then Parent_Is_Boolean
7390 Error_Msg_N ("?not expression should be parenthesized here!", N);
7393 -- Warn on double negation if checking redundant constructs
7395 if Warn_On_Redundant_Constructs
7396 and then Comes_From_Source (N)
7397 and then Comes_From_Source (Right_Opnd (N))
7398 and then Root_Type (Typ) = Standard_Boolean
7399 and then Nkind (Right_Opnd (N)) = N_Op_Not
7401 Error_Msg_N ("redundant double negation?", N);
7404 -- Complete resolution and evaluation of NOT
7406 Resolve (Right_Opnd (N), B_Typ);
7407 Check_Unset_Reference (Right_Opnd (N));
7408 Set_Etype (N, B_Typ);
7409 Generate_Operator_Reference (N, B_Typ);
7414 -----------------------------
7415 -- Resolve_Operator_Symbol --
7416 -----------------------------
7418 -- Nothing to be done, all resolved already
7420 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
7421 pragma Warnings (Off, N);
7422 pragma Warnings (Off, Typ);
7426 end Resolve_Operator_Symbol;
7428 ----------------------------------
7429 -- Resolve_Qualified_Expression --
7430 ----------------------------------
7432 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
7433 pragma Warnings (Off, Typ);
7435 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
7436 Expr : constant Node_Id := Expression (N);
7439 Resolve (Expr, Target_Typ);
7441 -- A qualified expression requires an exact match of the type,
7442 -- class-wide matching is not allowed. However, if the qualifying
7443 -- type is specific and the expression has a class-wide type, it
7444 -- may still be okay, since it can be the result of the expansion
7445 -- of a call to a dispatching function, so we also have to check
7446 -- class-wideness of the type of the expression's original node.
7448 if (Is_Class_Wide_Type (Target_Typ)
7450 (Is_Class_Wide_Type (Etype (Expr))
7451 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
7452 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
7454 Wrong_Type (Expr, Target_Typ);
7457 -- If the target type is unconstrained, then we reset the type of
7458 -- the result from the type of the expression. For other cases, the
7459 -- actual subtype of the expression is the target type.
7461 if Is_Composite_Type (Target_Typ)
7462 and then not Is_Constrained (Target_Typ)
7464 Set_Etype (N, Etype (Expr));
7467 Eval_Qualified_Expression (N);
7468 end Resolve_Qualified_Expression;
7474 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
7475 L : constant Node_Id := Low_Bound (N);
7476 H : constant Node_Id := High_Bound (N);
7483 Check_Unset_Reference (L);
7484 Check_Unset_Reference (H);
7486 -- We have to check the bounds for being within the base range as
7487 -- required for a non-static context. Normally this is automatic and
7488 -- done as part of evaluating expressions, but the N_Range node is an
7489 -- exception, since in GNAT we consider this node to be a subexpression,
7490 -- even though in Ada it is not. The circuit in Sem_Eval could check for
7491 -- this, but that would put the test on the main evaluation path for
7494 Check_Non_Static_Context (L);
7495 Check_Non_Static_Context (H);
7497 -- Check for an ambiguous range over character literals. This will
7498 -- happen with a membership test involving only literals.
7500 if Typ = Any_Character then
7501 Ambiguous_Character (L);
7502 Set_Etype (N, Any_Type);
7506 -- If bounds are static, constant-fold them, so size computations
7507 -- are identical between front-end and back-end. Do not perform this
7508 -- transformation while analyzing generic units, as type information
7509 -- would then be lost when reanalyzing the constant node in the
7512 if Is_Discrete_Type (Typ) and then Expander_Active then
7513 if Is_OK_Static_Expression (L) then
7514 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
7517 if Is_OK_Static_Expression (H) then
7518 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
7523 --------------------------
7524 -- Resolve_Real_Literal --
7525 --------------------------
7527 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
7528 Actual_Typ : constant Entity_Id := Etype (N);
7531 -- Special processing for fixed-point literals to make sure that the
7532 -- value is an exact multiple of small where this is required. We
7533 -- skip this for the universal real case, and also for generic types.
7535 if Is_Fixed_Point_Type (Typ)
7536 and then Typ /= Universal_Fixed
7537 and then Typ /= Any_Fixed
7538 and then not Is_Generic_Type (Typ)
7541 Val : constant Ureal := Realval (N);
7542 Cintr : constant Ureal := Val / Small_Value (Typ);
7543 Cint : constant Uint := UR_Trunc (Cintr);
7544 Den : constant Uint := Norm_Den (Cintr);
7548 -- Case of literal is not an exact multiple of the Small
7552 -- For a source program literal for a decimal fixed-point
7553 -- type, this is statically illegal (RM 4.9(36)).
7555 if Is_Decimal_Fixed_Point_Type (Typ)
7556 and then Actual_Typ = Universal_Real
7557 and then Comes_From_Source (N)
7559 Error_Msg_N ("value has extraneous low order digits", N);
7562 -- Generate a warning if literal from source
7564 if Is_Static_Expression (N)
7565 and then Warn_On_Bad_Fixed_Value
7568 ("?static fixed-point value is not a multiple of Small!",
7572 -- Replace literal by a value that is the exact representation
7573 -- of a value of the type, i.e. a multiple of the small value,
7574 -- by truncation, since Machine_Rounds is false for all GNAT
7575 -- fixed-point types (RM 4.9(38)).
7577 Stat := Is_Static_Expression (N);
7579 Make_Real_Literal (Sloc (N),
7580 Realval => Small_Value (Typ) * Cint));
7582 Set_Is_Static_Expression (N, Stat);
7585 -- In all cases, set the corresponding integer field
7587 Set_Corresponding_Integer_Value (N, Cint);
7591 -- Now replace the actual type by the expected type as usual
7594 Eval_Real_Literal (N);
7595 end Resolve_Real_Literal;
7597 -----------------------
7598 -- Resolve_Reference --
7599 -----------------------
7601 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
7602 P : constant Node_Id := Prefix (N);
7605 -- Replace general access with specific type
7607 if Ekind (Etype (N)) = E_Allocator_Type then
7608 Set_Etype (N, Base_Type (Typ));
7611 Resolve (P, Designated_Type (Etype (N)));
7613 -- If we are taking the reference of a volatile entity, then treat
7614 -- it as a potential modification of this entity. This is much too
7615 -- conservative, but is necessary because remove side effects can
7616 -- result in transformations of normal assignments into reference
7617 -- sequences that otherwise fail to notice the modification.
7619 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
7620 Note_Possible_Modification (P, Sure => False);
7622 end Resolve_Reference;
7624 --------------------------------
7625 -- Resolve_Selected_Component --
7626 --------------------------------
7628 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
7630 Comp1 : Entity_Id := Empty; -- prevent junk warning
7631 P : constant Node_Id := Prefix (N);
7632 S : constant Node_Id := Selector_Name (N);
7633 T : Entity_Id := Etype (P);
7635 I1 : Interp_Index := 0; -- prevent junk warning
7640 function Init_Component return Boolean;
7641 -- Check whether this is the initialization of a component within an
7642 -- init proc (by assignment or call to another init proc). If true,
7643 -- there is no need for a discriminant check.
7645 --------------------
7646 -- Init_Component --
7647 --------------------
7649 function Init_Component return Boolean is
7651 return Inside_Init_Proc
7652 and then Nkind (Prefix (N)) = N_Identifier
7653 and then Chars (Prefix (N)) = Name_uInit
7654 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
7657 -- Start of processing for Resolve_Selected_Component
7660 if Is_Overloaded (P) then
7662 -- Use the context type to select the prefix that has a selector
7663 -- of the correct name and type.
7666 Get_First_Interp (P, I, It);
7668 Search : while Present (It.Typ) loop
7669 if Is_Access_Type (It.Typ) then
7670 T := Designated_Type (It.Typ);
7675 if Is_Record_Type (T) then
7677 -- The visible components of a class-wide type are those of
7680 if Is_Class_Wide_Type (T) then
7684 Comp := First_Entity (T);
7685 while Present (Comp) loop
7686 if Chars (Comp) = Chars (S)
7687 and then Covers (Etype (Comp), Typ)
7696 It := Disambiguate (P, I1, I, Any_Type);
7698 if It = No_Interp then
7700 ("ambiguous prefix for selected component", N);
7707 -- There may be an implicit dereference. Retrieve
7708 -- designated record type.
7710 if Is_Access_Type (It1.Typ) then
7711 T := Designated_Type (It1.Typ);
7716 if Scope (Comp1) /= T then
7718 -- Resolution chooses the new interpretation.
7719 -- Find the component with the right name.
7721 Comp1 := First_Entity (T);
7722 while Present (Comp1)
7723 and then Chars (Comp1) /= Chars (S)
7725 Comp1 := Next_Entity (Comp1);
7734 Comp := Next_Entity (Comp);
7738 Get_Next_Interp (I, It);
7741 Resolve (P, It1.Typ);
7743 Set_Entity_With_Style_Check (S, Comp1);
7746 -- Resolve prefix with its type
7751 -- Generate cross-reference. We needed to wait until full overloading
7752 -- resolution was complete to do this, since otherwise we can't tell if
7753 -- we are an lvalue or not.
7755 if May_Be_Lvalue (N) then
7756 Generate_Reference (Entity (S), S, 'm');
7758 Generate_Reference (Entity (S), S, 'r');
7761 -- If prefix is an access type, the node will be transformed into an
7762 -- explicit dereference during expansion. The type of the node is the
7763 -- designated type of that of the prefix.
7765 if Is_Access_Type (Etype (P)) then
7766 T := Designated_Type (Etype (P));
7767 Check_Fully_Declared_Prefix (T, P);
7772 if Has_Discriminants (T)
7773 and then (Ekind (Entity (S)) = E_Component
7775 Ekind (Entity (S)) = E_Discriminant)
7776 and then Present (Original_Record_Component (Entity (S)))
7777 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
7778 and then Present (Discriminant_Checking_Func
7779 (Original_Record_Component (Entity (S))))
7780 and then not Discriminant_Checks_Suppressed (T)
7781 and then not Init_Component
7783 Set_Do_Discriminant_Check (N);
7786 if Ekind (Entity (S)) = E_Void then
7787 Error_Msg_N ("premature use of component", S);
7790 -- If the prefix is a record conversion, this may be a renamed
7791 -- discriminant whose bounds differ from those of the original
7792 -- one, so we must ensure that a range check is performed.
7794 if Nkind (P) = N_Type_Conversion
7795 and then Ekind (Entity (S)) = E_Discriminant
7796 and then Is_Discrete_Type (Typ)
7798 Set_Etype (N, Base_Type (Typ));
7801 -- Note: No Eval processing is required, because the prefix is of a
7802 -- record type, or protected type, and neither can possibly be static.
7804 -- If the array type is atomic, and is packed, and we are in a left side
7805 -- context, then this is worth a warning, since we have a situation
7806 -- where the access to the component may cause extra read/writes of
7807 -- the atomic array object, which could be considered unexpected.
7809 if Nkind (N) = N_Selected_Component
7810 and then (Is_Atomic (T)
7811 or else (Is_Entity_Name (Prefix (N))
7812 and then Is_Atomic (Entity (Prefix (N)))))
7813 and then Is_Packed (T)
7816 Error_Msg_N ("?assignment to component of packed atomic record",
7818 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
7821 end Resolve_Selected_Component;
7827 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
7828 B_Typ : constant Entity_Id := Base_Type (Typ);
7829 L : constant Node_Id := Left_Opnd (N);
7830 R : constant Node_Id := Right_Opnd (N);
7833 -- We do the resolution using the base type, because intermediate values
7834 -- in expressions always are of the base type, not a subtype of it.
7837 Resolve (R, Standard_Natural);
7839 Check_Unset_Reference (L);
7840 Check_Unset_Reference (R);
7842 Set_Etype (N, B_Typ);
7843 Generate_Operator_Reference (N, B_Typ);
7847 ---------------------------
7848 -- Resolve_Short_Circuit --
7849 ---------------------------
7851 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
7852 B_Typ : constant Entity_Id := Base_Type (Typ);
7853 L : constant Node_Id := Left_Opnd (N);
7854 R : constant Node_Id := Right_Opnd (N);
7860 -- Check for issuing warning for always False assert/check, this happens
7861 -- when assertions are turned off, in which case the pragma Assert/Check
7862 -- was transformed into:
7864 -- if False and then <condition> then ...
7866 -- and we detect this pattern
7868 if Warn_On_Assertion_Failure
7869 and then Is_Entity_Name (R)
7870 and then Entity (R) = Standard_False
7871 and then Nkind (Parent (N)) = N_If_Statement
7872 and then Nkind (N) = N_And_Then
7873 and then Is_Entity_Name (L)
7874 and then Entity (L) = Standard_False
7877 Orig : constant Node_Id := Original_Node (Parent (N));
7880 if Nkind (Orig) = N_Pragma
7881 and then Pragma_Name (Orig) = Name_Assert
7883 -- Don't want to warn if original condition is explicit False
7886 Expr : constant Node_Id :=
7889 (First (Pragma_Argument_Associations (Orig))));
7891 if Is_Entity_Name (Expr)
7892 and then Entity (Expr) = Standard_False
7896 -- Issue warning. We do not want the deletion of the
7897 -- IF/AND-THEN to take this message with it. We achieve
7898 -- this by making sure that the expanded code points to
7899 -- the Sloc of the expression, not the original pragma.
7902 ("?assertion would fail at run-time!",
7904 (First (Pragma_Argument_Associations (Orig))));
7908 -- Similar processing for Check pragma
7910 elsif Nkind (Orig) = N_Pragma
7911 and then Pragma_Name (Orig) = Name_Check
7913 -- Don't want to warn if original condition is explicit False
7916 Expr : constant Node_Id :=
7920 (Pragma_Argument_Associations (Orig)))));
7922 if Is_Entity_Name (Expr)
7923 and then Entity (Expr) = Standard_False
7928 ("?check would fail at run-time!",
7930 (Last (Pragma_Argument_Associations (Orig))));
7937 -- Continue with processing of short circuit
7939 Check_Unset_Reference (L);
7940 Check_Unset_Reference (R);
7942 Set_Etype (N, B_Typ);
7943 Eval_Short_Circuit (N);
7944 end Resolve_Short_Circuit;
7950 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
7951 Name : constant Node_Id := Prefix (N);
7952 Drange : constant Node_Id := Discrete_Range (N);
7953 Array_Type : Entity_Id := Empty;
7957 if Is_Overloaded (Name) then
7959 -- Use the context type to select the prefix that yields the correct
7964 I1 : Interp_Index := 0;
7966 P : constant Node_Id := Prefix (N);
7967 Found : Boolean := False;
7970 Get_First_Interp (P, I, It);
7971 while Present (It.Typ) loop
7972 if (Is_Array_Type (It.Typ)
7973 and then Covers (Typ, It.Typ))
7974 or else (Is_Access_Type (It.Typ)
7975 and then Is_Array_Type (Designated_Type (It.Typ))
7976 and then Covers (Typ, Designated_Type (It.Typ)))
7979 It := Disambiguate (P, I1, I, Any_Type);
7981 if It = No_Interp then
7982 Error_Msg_N ("ambiguous prefix for slicing", N);
7987 Array_Type := It.Typ;
7992 Array_Type := It.Typ;
7997 Get_Next_Interp (I, It);
8002 Array_Type := Etype (Name);
8005 Resolve (Name, Array_Type);
8007 if Is_Access_Type (Array_Type) then
8008 Apply_Access_Check (N);
8009 Array_Type := Designated_Type (Array_Type);
8011 -- If the prefix is an access to an unconstrained array, we must use
8012 -- the actual subtype of the object to perform the index checks. The
8013 -- object denoted by the prefix is implicit in the node, so we build
8014 -- an explicit representation for it in order to compute the actual
8017 if not Is_Constrained (Array_Type) then
8018 Remove_Side_Effects (Prefix (N));
8021 Obj : constant Node_Id :=
8022 Make_Explicit_Dereference (Sloc (N),
8023 Prefix => New_Copy_Tree (Prefix (N)));
8025 Set_Etype (Obj, Array_Type);
8026 Set_Parent (Obj, Parent (N));
8027 Array_Type := Get_Actual_Subtype (Obj);
8031 elsif Is_Entity_Name (Name)
8032 or else (Nkind (Name) = N_Function_Call
8033 and then not Is_Constrained (Etype (Name)))
8035 Array_Type := Get_Actual_Subtype (Name);
8037 -- If the name is a selected component that depends on discriminants,
8038 -- build an actual subtype for it. This can happen only when the name
8039 -- itself is overloaded; otherwise the actual subtype is created when
8040 -- the selected component is analyzed.
8042 elsif Nkind (Name) = N_Selected_Component
8043 and then Full_Analysis
8044 and then Depends_On_Discriminant (First_Index (Array_Type))
8047 Act_Decl : constant Node_Id :=
8048 Build_Actual_Subtype_Of_Component (Array_Type, Name);
8050 Insert_Action (N, Act_Decl);
8051 Array_Type := Defining_Identifier (Act_Decl);
8054 -- Maybe this should just be "else", instead of checking for the
8055 -- specific case of slice??? This is needed for the case where
8056 -- the prefix is an Image attribute, which gets expanded to a
8057 -- slice, and so has a constrained subtype which we want to use
8058 -- for the slice range check applied below (the range check won't
8059 -- get done if the unconstrained subtype of the 'Image is used).
8061 elsif Nkind (Name) = N_Slice then
8062 Array_Type := Etype (Name);
8065 -- If name was overloaded, set slice type correctly now
8067 Set_Etype (N, Array_Type);
8069 -- If the range is specified by a subtype mark, no resolution is
8070 -- necessary. Else resolve the bounds, and apply needed checks.
8072 if not Is_Entity_Name (Drange) then
8073 Index := First_Index (Array_Type);
8074 Resolve (Drange, Base_Type (Etype (Index)));
8076 if Nkind (Drange) = N_Range
8078 -- Do not apply the range check to nodes associated with the
8079 -- frontend expansion of the dispatch table. We first check
8080 -- if Ada.Tags is already loaded to void the addition of an
8081 -- undesired dependence on such run-time unit.
8084 (not Tagged_Type_Expansion
8086 (RTU_Loaded (Ada_Tags)
8087 and then Nkind (Prefix (N)) = N_Selected_Component
8088 and then Present (Entity (Selector_Name (Prefix (N))))
8089 and then Entity (Selector_Name (Prefix (N))) =
8090 RTE_Record_Component (RE_Prims_Ptr)))
8092 Apply_Range_Check (Drange, Etype (Index));
8096 Set_Slice_Subtype (N);
8098 if Nkind (Drange) = N_Range then
8099 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
8100 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
8106 ----------------------------
8107 -- Resolve_String_Literal --
8108 ----------------------------
8110 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
8111 C_Typ : constant Entity_Id := Component_Type (Typ);
8112 R_Typ : constant Entity_Id := Root_Type (C_Typ);
8113 Loc : constant Source_Ptr := Sloc (N);
8114 Str : constant String_Id := Strval (N);
8115 Strlen : constant Nat := String_Length (Str);
8116 Subtype_Id : Entity_Id;
8117 Need_Check : Boolean;
8120 -- For a string appearing in a concatenation, defer creation of the
8121 -- string_literal_subtype until the end of the resolution of the
8122 -- concatenation, because the literal may be constant-folded away. This
8123 -- is a useful optimization for long concatenation expressions.
8125 -- If the string is an aggregate built for a single character (which
8126 -- happens in a non-static context) or a is null string to which special
8127 -- checks may apply, we build the subtype. Wide strings must also get a
8128 -- string subtype if they come from a one character aggregate. Strings
8129 -- generated by attributes might be static, but it is often hard to
8130 -- determine whether the enclosing context is static, so we generate
8131 -- subtypes for them as well, thus losing some rarer optimizations ???
8132 -- Same for strings that come from a static conversion.
8135 (Strlen = 0 and then Typ /= Standard_String)
8136 or else Nkind (Parent (N)) /= N_Op_Concat
8137 or else (N /= Left_Opnd (Parent (N))
8138 and then N /= Right_Opnd (Parent (N)))
8139 or else ((Typ = Standard_Wide_String
8140 or else Typ = Standard_Wide_Wide_String)
8141 and then Nkind (Original_Node (N)) /= N_String_Literal);
8143 -- If the resolving type is itself a string literal subtype, we can just
8144 -- reuse it, since there is no point in creating another.
8146 if Ekind (Typ) = E_String_Literal_Subtype then
8149 elsif Nkind (Parent (N)) = N_Op_Concat
8150 and then not Need_Check
8151 and then not Nkind_In (Original_Node (N), N_Character_Literal,
8152 N_Attribute_Reference,
8153 N_Qualified_Expression,
8158 -- Otherwise we must create a string literal subtype. Note that the
8159 -- whole idea of string literal subtypes is simply to avoid the need
8160 -- for building a full fledged array subtype for each literal.
8163 Set_String_Literal_Subtype (N, Typ);
8164 Subtype_Id := Etype (N);
8167 if Nkind (Parent (N)) /= N_Op_Concat
8170 Set_Etype (N, Subtype_Id);
8171 Eval_String_Literal (N);
8174 if Is_Limited_Composite (Typ)
8175 or else Is_Private_Composite (Typ)
8177 Error_Msg_N ("string literal not available for private array", N);
8178 Set_Etype (N, Any_Type);
8182 -- The validity of a null string has been checked in the call to
8183 -- Eval_String_Literal.
8188 -- Always accept string literal with component type Any_Character, which
8189 -- occurs in error situations and in comparisons of literals, both of
8190 -- which should accept all literals.
8192 elsif R_Typ = Any_Character then
8195 -- If the type is bit-packed, then we always transform the string
8196 -- literal into a full fledged aggregate.
8198 elsif Is_Bit_Packed_Array (Typ) then
8201 -- Deal with cases of Wide_Wide_String, Wide_String, and String
8204 -- For Standard.Wide_Wide_String, or any other type whose component
8205 -- type is Standard.Wide_Wide_Character, we know that all the
8206 -- characters in the string must be acceptable, since the parser
8207 -- accepted the characters as valid character literals.
8209 if R_Typ = Standard_Wide_Wide_Character then
8212 -- For the case of Standard.String, or any other type whose component
8213 -- type is Standard.Character, we must make sure that there are no
8214 -- wide characters in the string, i.e. that it is entirely composed
8215 -- of characters in range of type Character.
8217 -- If the string literal is the result of a static concatenation, the
8218 -- test has already been performed on the components, and need not be
8221 elsif R_Typ = Standard_Character
8222 and then Nkind (Original_Node (N)) /= N_Op_Concat
8224 for J in 1 .. Strlen loop
8225 if not In_Character_Range (Get_String_Char (Str, J)) then
8227 -- If we are out of range, post error. This is one of the
8228 -- very few places that we place the flag in the middle of
8229 -- a token, right under the offending wide character. Not
8230 -- quite clear if this is right wrt wide character encoding
8231 -- sequences, but it's only an error message!
8234 ("literal out of range of type Standard.Character",
8235 Source_Ptr (Int (Loc) + J));
8240 -- For the case of Standard.Wide_String, or any other type whose
8241 -- component type is Standard.Wide_Character, we must make sure that
8242 -- there are no wide characters in the string, i.e. that it is
8243 -- entirely composed of characters in range of type Wide_Character.
8245 -- If the string literal is the result of a static concatenation,
8246 -- the test has already been performed on the components, and need
8249 elsif R_Typ = Standard_Wide_Character
8250 and then Nkind (Original_Node (N)) /= N_Op_Concat
8252 for J in 1 .. Strlen loop
8253 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
8255 -- If we are out of range, post error. This is one of the
8256 -- very few places that we place the flag in the middle of
8257 -- a token, right under the offending wide character.
8259 -- This is not quite right, because characters in general
8260 -- will take more than one character position ???
8263 ("literal out of range of type Standard.Wide_Character",
8264 Source_Ptr (Int (Loc) + J));
8269 -- If the root type is not a standard character, then we will convert
8270 -- the string into an aggregate and will let the aggregate code do
8271 -- the checking. Standard Wide_Wide_Character is also OK here.
8277 -- See if the component type of the array corresponding to the string
8278 -- has compile time known bounds. If yes we can directly check
8279 -- whether the evaluation of the string will raise constraint error.
8280 -- Otherwise we need to transform the string literal into the
8281 -- corresponding character aggregate and let the aggregate
8282 -- code do the checking.
8284 if Is_Standard_Character_Type (R_Typ) then
8286 -- Check for the case of full range, where we are definitely OK
8288 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
8292 -- Here the range is not the complete base type range, so check
8295 Comp_Typ_Lo : constant Node_Id :=
8296 Type_Low_Bound (Component_Type (Typ));
8297 Comp_Typ_Hi : constant Node_Id :=
8298 Type_High_Bound (Component_Type (Typ));
8303 if Compile_Time_Known_Value (Comp_Typ_Lo)
8304 and then Compile_Time_Known_Value (Comp_Typ_Hi)
8306 for J in 1 .. Strlen loop
8307 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
8309 if Char_Val < Expr_Value (Comp_Typ_Lo)
8310 or else Char_Val > Expr_Value (Comp_Typ_Hi)
8312 Apply_Compile_Time_Constraint_Error
8313 (N, "character out of range?", CE_Range_Check_Failed,
8314 Loc => Source_Ptr (Int (Loc) + J));
8324 -- If we got here we meed to transform the string literal into the
8325 -- equivalent qualified positional array aggregate. This is rather
8326 -- heavy artillery for this situation, but it is hard work to avoid.
8329 Lits : constant List_Id := New_List;
8330 P : Source_Ptr := Loc + 1;
8334 -- Build the character literals, we give them source locations that
8335 -- correspond to the string positions, which is a bit tricky given
8336 -- the possible presence of wide character escape sequences.
8338 for J in 1 .. Strlen loop
8339 C := Get_String_Char (Str, J);
8340 Set_Character_Literal_Name (C);
8343 Make_Character_Literal (P,
8345 Char_Literal_Value => UI_From_CC (C)));
8347 if In_Character_Range (C) then
8350 -- Should we have a call to Skip_Wide here ???
8358 Make_Qualified_Expression (Loc,
8359 Subtype_Mark => New_Reference_To (Typ, Loc),
8361 Make_Aggregate (Loc, Expressions => Lits)));
8363 Analyze_And_Resolve (N, Typ);
8365 end Resolve_String_Literal;
8367 -----------------------------
8368 -- Resolve_Subprogram_Info --
8369 -----------------------------
8371 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
8374 end Resolve_Subprogram_Info;
8376 -----------------------------
8377 -- Resolve_Type_Conversion --
8378 -----------------------------
8380 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
8381 Conv_OK : constant Boolean := Conversion_OK (N);
8382 Operand : constant Node_Id := Expression (N);
8383 Operand_Typ : constant Entity_Id := Etype (Operand);
8384 Target_Typ : constant Entity_Id := Etype (N);
8391 and then not Valid_Conversion (N, Target_Typ, Operand)
8396 if Etype (Operand) = Any_Fixed then
8398 -- Mixed-mode operation involving a literal. Context must be a fixed
8399 -- type which is applied to the literal subsequently.
8401 if Is_Fixed_Point_Type (Typ) then
8402 Set_Etype (Operand, Universal_Real);
8404 elsif Is_Numeric_Type (Typ)
8405 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
8406 and then (Etype (Right_Opnd (Operand)) = Universal_Real
8408 Etype (Left_Opnd (Operand)) = Universal_Real)
8410 -- Return if expression is ambiguous
8412 if Unique_Fixed_Point_Type (N) = Any_Type then
8415 -- If nothing else, the available fixed type is Duration
8418 Set_Etype (Operand, Standard_Duration);
8421 -- Resolve the real operand with largest available precision
8423 if Etype (Right_Opnd (Operand)) = Universal_Real then
8424 Rop := New_Copy_Tree (Right_Opnd (Operand));
8426 Rop := New_Copy_Tree (Left_Opnd (Operand));
8429 Resolve (Rop, Universal_Real);
8431 -- If the operand is a literal (it could be a non-static and
8432 -- illegal exponentiation) check whether the use of Duration
8433 -- is potentially inaccurate.
8435 if Nkind (Rop) = N_Real_Literal
8436 and then Realval (Rop) /= Ureal_0
8437 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
8440 ("?universal real operand can only " &
8441 "be interpreted as Duration!",
8444 ("\?precision will be lost in the conversion!", Rop);
8447 elsif Is_Numeric_Type (Typ)
8448 and then Nkind (Operand) in N_Op
8449 and then Unique_Fixed_Point_Type (N) /= Any_Type
8451 Set_Etype (Operand, Standard_Duration);
8454 Error_Msg_N ("invalid context for mixed mode operation", N);
8455 Set_Etype (Operand, Any_Type);
8462 -- Note: we do the Eval_Type_Conversion call before applying the
8463 -- required checks for a subtype conversion. This is important, since
8464 -- both are prepared under certain circumstances to change the type
8465 -- conversion to a constraint error node, but in the case of
8466 -- Eval_Type_Conversion this may reflect an illegality in the static
8467 -- case, and we would miss the illegality (getting only a warning
8468 -- message), if we applied the type conversion checks first.
8470 Eval_Type_Conversion (N);
8472 -- Even when evaluation is not possible, we may be able to simplify the
8473 -- conversion or its expression. This needs to be done before applying
8474 -- checks, since otherwise the checks may use the original expression
8475 -- and defeat the simplifications. This is specifically the case for
8476 -- elimination of the floating-point Truncation attribute in
8477 -- float-to-int conversions.
8479 Simplify_Type_Conversion (N);
8481 -- If after evaluation we still have a type conversion, then we may need
8482 -- to apply checks required for a subtype conversion.
8484 -- Skip these type conversion checks if universal fixed operands
8485 -- operands involved, since range checks are handled separately for
8486 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
8488 if Nkind (N) = N_Type_Conversion
8489 and then not Is_Generic_Type (Root_Type (Target_Typ))
8490 and then Target_Typ /= Universal_Fixed
8491 and then Operand_Typ /= Universal_Fixed
8493 Apply_Type_Conversion_Checks (N);
8496 -- Issue warning for conversion of simple object to its own type. We
8497 -- have to test the original nodes, since they may have been rewritten
8498 -- by various optimizations.
8500 Orig_N := Original_Node (N);
8502 if Warn_On_Redundant_Constructs
8503 and then Comes_From_Source (Orig_N)
8504 and then Nkind (Orig_N) = N_Type_Conversion
8505 and then not In_Instance
8507 Orig_N := Original_Node (Expression (Orig_N));
8508 Orig_T := Target_Typ;
8510 -- If the node is part of a larger expression, the Target_Type
8511 -- may not be the original type of the node if the context is a
8512 -- condition. Recover original type to see if conversion is needed.
8514 if Is_Boolean_Type (Orig_T)
8515 and then Nkind (Parent (N)) in N_Op
8517 Orig_T := Etype (Parent (N));
8520 if Is_Entity_Name (Orig_N)
8522 (Etype (Entity (Orig_N)) = Orig_T
8524 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
8525 and then Covers (Orig_T, Etype (Entity (Orig_N)))))
8527 -- One more check, do not give warning if the analyzed conversion
8528 -- has an expression with non-static bounds, and the bounds of the
8529 -- target are static. This avoids junk warnings in cases where the
8530 -- conversion is necessary to establish staticness, for example in
8531 -- a case statement.
8533 if not Is_OK_Static_Subtype (Operand_Typ)
8534 and then Is_OK_Static_Subtype (Target_Typ)
8538 -- Here we give the redundant conversion warning
8541 Error_Msg_Node_2 := Orig_T;
8542 Error_Msg_NE -- CODEFIX
8543 ("?redundant conversion, & is of type &!",
8544 N, Entity (Orig_N));
8549 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
8550 -- No need to perform any interface conversion if the type of the
8551 -- expression coincides with the target type.
8553 if Ada_Version >= Ada_05
8554 and then Expander_Active
8555 and then Operand_Typ /= Target_Typ
8558 Opnd : Entity_Id := Operand_Typ;
8559 Target : Entity_Id := Target_Typ;
8562 if Is_Access_Type (Opnd) then
8563 Opnd := Directly_Designated_Type (Opnd);
8566 if Is_Access_Type (Target_Typ) then
8567 Target := Directly_Designated_Type (Target);
8570 if Opnd = Target then
8573 -- Conversion from interface type
8575 elsif Is_Interface (Opnd) then
8577 -- Ada 2005 (AI-217): Handle entities from limited views
8579 if From_With_Type (Opnd) then
8580 Error_Msg_Qual_Level := 99;
8581 Error_Msg_NE ("missing WITH clause on package &", N,
8582 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
8584 ("type conversions require visibility of the full view",
8587 elsif From_With_Type (Target)
8589 (Is_Access_Type (Target_Typ)
8590 and then Present (Non_Limited_View (Etype (Target))))
8592 Error_Msg_Qual_Level := 99;
8593 Error_Msg_NE ("missing WITH clause on package &", N,
8594 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
8596 ("type conversions require visibility of the full view",
8600 Expand_Interface_Conversion (N, Is_Static => False);
8603 -- Conversion to interface type
8605 elsif Is_Interface (Target) then
8609 if Ekind_In (Opnd, E_Protected_Subtype, E_Task_Subtype) then
8610 Opnd := Etype (Opnd);
8613 if not Interface_Present_In_Ancestor
8617 if Is_Class_Wide_Type (Opnd) then
8619 -- The static analysis is not enough to know if the
8620 -- interface is implemented or not. Hence we must pass
8621 -- the work to the expander to generate code to evaluate
8622 -- the conversion at run-time.
8624 Expand_Interface_Conversion (N, Is_Static => False);
8627 Error_Msg_Name_1 := Chars (Etype (Target));
8628 Error_Msg_Name_2 := Chars (Opnd);
8630 ("wrong interface conversion (% is not a progenitor " &
8635 Expand_Interface_Conversion (N);
8640 end Resolve_Type_Conversion;
8642 ----------------------
8643 -- Resolve_Unary_Op --
8644 ----------------------
8646 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
8647 B_Typ : constant Entity_Id := Base_Type (Typ);
8648 R : constant Node_Id := Right_Opnd (N);
8654 -- Deal with intrinsic unary operators
8656 if Comes_From_Source (N)
8657 and then Ekind (Entity (N)) = E_Function
8658 and then Is_Imported (Entity (N))
8659 and then Is_Intrinsic_Subprogram (Entity (N))
8661 Resolve_Intrinsic_Unary_Operator (N, Typ);
8665 -- Deal with universal cases
8667 if Etype (R) = Universal_Integer
8669 Etype (R) = Universal_Real
8671 Check_For_Visible_Operator (N, B_Typ);
8674 Set_Etype (N, B_Typ);
8677 -- Generate warning for expressions like abs (x mod 2)
8679 if Warn_On_Redundant_Constructs
8680 and then Nkind (N) = N_Op_Abs
8682 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
8684 if OK and then Hi >= Lo and then Lo >= 0 then
8686 ("?abs applied to known non-negative value has no effect", N);
8690 -- Deal with reference generation
8692 Check_Unset_Reference (R);
8693 Generate_Operator_Reference (N, B_Typ);
8696 -- Set overflow checking bit. Much cleverer code needed here eventually
8697 -- and perhaps the Resolve routines should be separated for the various
8698 -- arithmetic operations, since they will need different processing ???
8700 if Nkind (N) in N_Op then
8701 if not Overflow_Checks_Suppressed (Etype (N)) then
8702 Enable_Overflow_Check (N);
8706 -- Generate warning for expressions like -5 mod 3 for integers. No need
8707 -- to worry in the floating-point case, since parens do not affect the
8708 -- result so there is no point in giving in a warning.
8711 Norig : constant Node_Id := Original_Node (N);
8720 if Warn_On_Questionable_Missing_Parens
8721 and then Comes_From_Source (Norig)
8722 and then Is_Integer_Type (Typ)
8723 and then Nkind (Norig) = N_Op_Minus
8725 Rorig := Original_Node (Right_Opnd (Norig));
8727 -- We are looking for cases where the right operand is not
8728 -- parenthesized, and is a binary operator, multiply, divide, or
8729 -- mod. These are the cases where the grouping can affect results.
8731 if Paren_Count (Rorig) = 0
8732 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
8734 -- For mod, we always give the warning, since the value is
8735 -- affected by the parenthesization (e.g. (-5) mod 315 /=
8736 -- -(5 mod 315)). But for the other cases, the only concern is
8737 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
8738 -- overflows, but (-2) * 64 does not). So we try to give the
8739 -- message only when overflow is possible.
8741 if Nkind (Rorig) /= N_Op_Mod
8742 and then Compile_Time_Known_Value (R)
8744 Val := Expr_Value (R);
8746 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
8747 HB := Expr_Value (Type_High_Bound (Typ));
8749 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
8752 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
8753 LB := Expr_Value (Type_Low_Bound (Typ));
8755 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
8758 -- Note that the test below is deliberately excluding the
8759 -- largest negative number, since that is a potentially
8760 -- troublesome case (e.g. -2 * x, where the result is the
8761 -- largest negative integer has an overflow with 2 * x).
8763 if Val > LB and then Val <= HB then
8768 -- For the multiplication case, the only case we have to worry
8769 -- about is when (-a)*b is exactly the largest negative number
8770 -- so that -(a*b) can cause overflow. This can only happen if
8771 -- a is a power of 2, and more generally if any operand is a
8772 -- constant that is not a power of 2, then the parentheses
8773 -- cannot affect whether overflow occurs. We only bother to
8774 -- test the left most operand
8776 -- Loop looking at left operands for one that has known value
8779 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
8780 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
8781 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
8783 -- Operand value of 0 or 1 skips warning
8788 -- Otherwise check power of 2, if power of 2, warn, if
8789 -- anything else, skip warning.
8792 while Lval /= 2 loop
8793 if Lval mod 2 = 1 then
8804 -- Keep looking at left operands
8806 Opnd := Left_Opnd (Opnd);
8809 -- For rem or "/" we can only have a problematic situation
8810 -- if the divisor has a value of minus one or one. Otherwise
8811 -- overflow is impossible (divisor > 1) or we have a case of
8812 -- division by zero in any case.
8814 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
8815 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
8816 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
8821 -- If we fall through warning should be issued
8824 ("?unary minus expression should be parenthesized here!", N);
8828 end Resolve_Unary_Op;
8830 ----------------------------------
8831 -- Resolve_Unchecked_Expression --
8832 ----------------------------------
8834 procedure Resolve_Unchecked_Expression
8839 Resolve (Expression (N), Typ, Suppress => All_Checks);
8841 end Resolve_Unchecked_Expression;
8843 ---------------------------------------
8844 -- Resolve_Unchecked_Type_Conversion --
8845 ---------------------------------------
8847 procedure Resolve_Unchecked_Type_Conversion
8851 pragma Warnings (Off, Typ);
8853 Operand : constant Node_Id := Expression (N);
8854 Opnd_Type : constant Entity_Id := Etype (Operand);
8857 -- Resolve operand using its own type
8859 Resolve (Operand, Opnd_Type);
8860 Eval_Unchecked_Conversion (N);
8862 end Resolve_Unchecked_Type_Conversion;
8864 ------------------------------
8865 -- Rewrite_Operator_As_Call --
8866 ------------------------------
8868 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
8869 Loc : constant Source_Ptr := Sloc (N);
8870 Actuals : constant List_Id := New_List;
8874 if Nkind (N) in N_Binary_Op then
8875 Append (Left_Opnd (N), Actuals);
8878 Append (Right_Opnd (N), Actuals);
8881 Make_Function_Call (Sloc => Loc,
8882 Name => New_Occurrence_Of (Nam, Loc),
8883 Parameter_Associations => Actuals);
8885 Preserve_Comes_From_Source (New_N, N);
8886 Preserve_Comes_From_Source (Name (New_N), N);
8888 Set_Etype (N, Etype (Nam));
8889 end Rewrite_Operator_As_Call;
8891 ------------------------------
8892 -- Rewrite_Renamed_Operator --
8893 ------------------------------
8895 procedure Rewrite_Renamed_Operator
8900 Nam : constant Name_Id := Chars (Op);
8901 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
8905 -- Rewrite the operator node using the real operator, not its renaming.
8906 -- Exclude user-defined intrinsic operations of the same name, which are
8907 -- treated separately and rewritten as calls.
8909 if Ekind (Op) /= E_Function
8910 or else Chars (N) /= Nam
8912 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
8913 Set_Chars (Op_Node, Nam);
8914 Set_Etype (Op_Node, Etype (N));
8915 Set_Entity (Op_Node, Op);
8916 Set_Right_Opnd (Op_Node, Right_Opnd (N));
8918 -- Indicate that both the original entity and its renaming are
8919 -- referenced at this point.
8921 Generate_Reference (Entity (N), N);
8922 Generate_Reference (Op, N);
8925 Set_Left_Opnd (Op_Node, Left_Opnd (N));
8928 Rewrite (N, Op_Node);
8930 -- If the context type is private, add the appropriate conversions
8931 -- so that the operator is applied to the full view. This is done
8932 -- in the routines that resolve intrinsic operators,
8934 if Is_Intrinsic_Subprogram (Op)
8935 and then Is_Private_Type (Typ)
8938 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
8939 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
8940 Resolve_Intrinsic_Operator (N, Typ);
8942 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
8943 Resolve_Intrinsic_Unary_Operator (N, Typ);
8950 elsif Ekind (Op) = E_Function
8951 and then Is_Intrinsic_Subprogram (Op)
8953 -- Operator renames a user-defined operator of the same name. Use
8954 -- the original operator in the node, which is the one that Gigi
8958 Set_Is_Overloaded (N, False);
8960 end Rewrite_Renamed_Operator;
8962 -----------------------
8963 -- Set_Slice_Subtype --
8964 -----------------------
8966 -- Build an implicit subtype declaration to represent the type delivered
8967 -- by the slice. This is an abbreviated version of an array subtype. We
8968 -- define an index subtype for the slice, using either the subtype name
8969 -- or the discrete range of the slice. To be consistent with index usage
8970 -- elsewhere, we create a list header to hold the single index. This list
8971 -- is not otherwise attached to the syntax tree.
8973 procedure Set_Slice_Subtype (N : Node_Id) is
8974 Loc : constant Source_Ptr := Sloc (N);
8975 Index_List : constant List_Id := New_List;
8977 Index_Subtype : Entity_Id;
8978 Index_Type : Entity_Id;
8979 Slice_Subtype : Entity_Id;
8980 Drange : constant Node_Id := Discrete_Range (N);
8983 if Is_Entity_Name (Drange) then
8984 Index_Subtype := Entity (Drange);
8987 -- We force the evaluation of a range. This is definitely needed in
8988 -- the renamed case, and seems safer to do unconditionally. Note in
8989 -- any case that since we will create and insert an Itype referring
8990 -- to this range, we must make sure any side effect removal actions
8991 -- are inserted before the Itype definition.
8993 if Nkind (Drange) = N_Range then
8994 Force_Evaluation (Low_Bound (Drange));
8995 Force_Evaluation (High_Bound (Drange));
8998 Index_Type := Base_Type (Etype (Drange));
9000 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9002 -- Take a new copy of Drange (where bounds have been rewritten to
9003 -- reference side-effect-vree names). Using a separate tree ensures
9004 -- that further expansion (e.g while rewriting a slice assignment
9005 -- into a FOR loop) does not attempt to remove side effects on the
9006 -- bounds again (which would cause the bounds in the index subtype
9007 -- definition to refer to temporaries before they are defined) (the
9008 -- reason is that some names are considered side effect free here
9009 -- for the subtype, but not in the context of a loop iteration
9012 Set_Scalar_Range (Index_Subtype, New_Copy_Tree (Drange));
9013 Set_Etype (Index_Subtype, Index_Type);
9014 Set_Size_Info (Index_Subtype, Index_Type);
9015 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9018 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
9020 Index := New_Occurrence_Of (Index_Subtype, Loc);
9021 Set_Etype (Index, Index_Subtype);
9022 Append (Index, Index_List);
9024 Set_First_Index (Slice_Subtype, Index);
9025 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
9026 Set_Is_Constrained (Slice_Subtype, True);
9028 Check_Compile_Time_Size (Slice_Subtype);
9030 -- The Etype of the existing Slice node is reset to this slice subtype.
9031 -- Its bounds are obtained from its first index.
9033 Set_Etype (N, Slice_Subtype);
9035 -- For packed slice subtypes, freeze immediately (except in the
9036 -- case of being in a "spec expression" where we never freeze
9037 -- when we first see the expression).
9039 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
9040 Freeze_Itype (Slice_Subtype, N);
9042 -- For all other cases insert an itype reference in the slice's actions
9043 -- so that the itype is frozen at the proper place in the tree (i.e. at
9044 -- the point where actions for the slice are analyzed). Note that this
9045 -- is different from freezing the itype immediately, which might be
9046 -- premature (e.g. if the slice is within a transient scope).
9049 Ensure_Defined (Typ => Slice_Subtype, N => N);
9051 end Set_Slice_Subtype;
9053 --------------------------------
9054 -- Set_String_Literal_Subtype --
9055 --------------------------------
9057 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
9058 Loc : constant Source_Ptr := Sloc (N);
9059 Low_Bound : constant Node_Id :=
9060 Type_Low_Bound (Etype (First_Index (Typ)));
9061 Subtype_Id : Entity_Id;
9064 if Nkind (N) /= N_String_Literal then
9068 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
9069 Set_String_Literal_Length (Subtype_Id, UI_From_Int
9070 (String_Length (Strval (N))));
9071 Set_Etype (Subtype_Id, Base_Type (Typ));
9072 Set_Is_Constrained (Subtype_Id);
9073 Set_Etype (N, Subtype_Id);
9075 if Is_OK_Static_Expression (Low_Bound) then
9077 -- The low bound is set from the low bound of the corresponding
9078 -- index type. Note that we do not store the high bound in the
9079 -- string literal subtype, but it can be deduced if necessary
9080 -- from the length and the low bound.
9082 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
9085 Set_String_Literal_Low_Bound
9086 (Subtype_Id, Make_Integer_Literal (Loc, 1));
9087 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Standard_Positive);
9089 -- Build bona fide subtype for the string, and wrap it in an
9090 -- unchecked conversion, because the backend expects the
9091 -- String_Literal_Subtype to have a static lower bound.
9094 Index_List : constant List_Id := New_List;
9095 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
9096 High_Bound : constant Node_Id :=
9098 Left_Opnd => New_Copy_Tree (Low_Bound),
9100 Make_Integer_Literal (Loc,
9101 String_Length (Strval (N)) - 1));
9102 Array_Subtype : Entity_Id;
9103 Index_Subtype : Entity_Id;
9109 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9110 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
9111 Set_Scalar_Range (Index_Subtype, Drange);
9112 Set_Parent (Drange, N);
9113 Analyze_And_Resolve (Drange, Index_Type);
9115 -- In the context, the Index_Type may already have a constraint,
9116 -- so use common base type on string subtype. The base type may
9117 -- be used when generating attributes of the string, for example
9118 -- in the context of a slice assignment.
9120 Set_Etype (Index_Subtype, Base_Type (Index_Type));
9121 Set_Size_Info (Index_Subtype, Index_Type);
9122 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9124 Array_Subtype := Create_Itype (E_Array_Subtype, N);
9126 Index := New_Occurrence_Of (Index_Subtype, Loc);
9127 Set_Etype (Index, Index_Subtype);
9128 Append (Index, Index_List);
9130 Set_First_Index (Array_Subtype, Index);
9131 Set_Etype (Array_Subtype, Base_Type (Typ));
9132 Set_Is_Constrained (Array_Subtype, True);
9135 Make_Unchecked_Type_Conversion (Loc,
9136 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
9137 Expression => Relocate_Node (N)));
9138 Set_Etype (N, Array_Subtype);
9141 end Set_String_Literal_Subtype;
9143 ------------------------------
9144 -- Simplify_Type_Conversion --
9145 ------------------------------
9147 procedure Simplify_Type_Conversion (N : Node_Id) is
9149 if Nkind (N) = N_Type_Conversion then
9151 Operand : constant Node_Id := Expression (N);
9152 Target_Typ : constant Entity_Id := Etype (N);
9153 Opnd_Typ : constant Entity_Id := Etype (Operand);
9156 if Is_Floating_Point_Type (Opnd_Typ)
9158 (Is_Integer_Type (Target_Typ)
9159 or else (Is_Fixed_Point_Type (Target_Typ)
9160 and then Conversion_OK (N)))
9161 and then Nkind (Operand) = N_Attribute_Reference
9162 and then Attribute_Name (Operand) = Name_Truncation
9164 -- Special processing required if the conversion is the expression
9165 -- of a Truncation attribute reference. In this case we replace:
9167 -- ityp (ftyp'Truncation (x))
9173 -- with the Float_Truncate flag set, which is more efficient
9177 Relocate_Node (First (Expressions (Operand))));
9178 Set_Float_Truncate (N, True);
9182 end Simplify_Type_Conversion;
9184 -----------------------------
9185 -- Unique_Fixed_Point_Type --
9186 -----------------------------
9188 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
9189 T1 : Entity_Id := Empty;
9194 procedure Fixed_Point_Error;
9195 -- Give error messages for true ambiguity. Messages are posted on node
9196 -- N, and entities T1, T2 are the possible interpretations.
9198 -----------------------
9199 -- Fixed_Point_Error --
9200 -----------------------
9202 procedure Fixed_Point_Error is
9204 Error_Msg_N ("ambiguous universal_fixed_expression", N);
9205 Error_Msg_NE ("\\possible interpretation as}", N, T1);
9206 Error_Msg_NE ("\\possible interpretation as}", N, T2);
9207 end Fixed_Point_Error;
9209 -- Start of processing for Unique_Fixed_Point_Type
9212 -- The operations on Duration are visible, so Duration is always a
9213 -- possible interpretation.
9215 T1 := Standard_Duration;
9217 -- Look for fixed-point types in enclosing scopes
9219 Scop := Current_Scope;
9220 while Scop /= Standard_Standard loop
9221 T2 := First_Entity (Scop);
9222 while Present (T2) loop
9223 if Is_Fixed_Point_Type (T2)
9224 and then Current_Entity (T2) = T2
9225 and then Scope (Base_Type (T2)) = Scop
9227 if Present (T1) then
9238 Scop := Scope (Scop);
9241 -- Look for visible fixed type declarations in the context
9243 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
9244 while Present (Item) loop
9245 if Nkind (Item) = N_With_Clause then
9246 Scop := Entity (Name (Item));
9247 T2 := First_Entity (Scop);
9248 while Present (T2) loop
9249 if Is_Fixed_Point_Type (T2)
9250 and then Scope (Base_Type (T2)) = Scop
9251 and then (Is_Potentially_Use_Visible (T2)
9252 or else In_Use (T2))
9254 if Present (T1) then
9269 if Nkind (N) = N_Real_Literal then
9270 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
9272 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
9276 end Unique_Fixed_Point_Type;
9278 ----------------------
9279 -- Valid_Conversion --
9280 ----------------------
9282 function Valid_Conversion
9285 Operand : Node_Id) return Boolean
9287 Target_Type : constant Entity_Id := Base_Type (Target);
9288 Opnd_Type : Entity_Id := Etype (Operand);
9290 function Conversion_Check
9292 Msg : String) return Boolean;
9293 -- Little routine to post Msg if Valid is False, returns Valid value
9295 function Valid_Tagged_Conversion
9296 (Target_Type : Entity_Id;
9297 Opnd_Type : Entity_Id) return Boolean;
9298 -- Specifically test for validity of tagged conversions
9300 function Valid_Array_Conversion return Boolean;
9301 -- Check index and component conformance, and accessibility levels
9302 -- if the component types are anonymous access types (Ada 2005)
9304 ----------------------
9305 -- Conversion_Check --
9306 ----------------------
9308 function Conversion_Check
9310 Msg : String) return Boolean
9314 Error_Msg_N (Msg, Operand);
9318 end Conversion_Check;
9320 ----------------------------
9321 -- Valid_Array_Conversion --
9322 ----------------------------
9324 function Valid_Array_Conversion return Boolean
9326 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
9327 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
9329 Opnd_Index : Node_Id;
9330 Opnd_Index_Type : Entity_Id;
9332 Target_Comp_Type : constant Entity_Id :=
9333 Component_Type (Target_Type);
9334 Target_Comp_Base : constant Entity_Id :=
9335 Base_Type (Target_Comp_Type);
9337 Target_Index : Node_Id;
9338 Target_Index_Type : Entity_Id;
9341 -- Error if wrong number of dimensions
9344 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
9347 ("incompatible number of dimensions for conversion", Operand);
9350 -- Number of dimensions matches
9353 -- Loop through indexes of the two arrays
9355 Target_Index := First_Index (Target_Type);
9356 Opnd_Index := First_Index (Opnd_Type);
9357 while Present (Target_Index) and then Present (Opnd_Index) loop
9358 Target_Index_Type := Etype (Target_Index);
9359 Opnd_Index_Type := Etype (Opnd_Index);
9361 -- Error if index types are incompatible
9363 if not (Is_Integer_Type (Target_Index_Type)
9364 and then Is_Integer_Type (Opnd_Index_Type))
9365 and then (Root_Type (Target_Index_Type)
9366 /= Root_Type (Opnd_Index_Type))
9369 ("incompatible index types for array conversion",
9374 Next_Index (Target_Index);
9375 Next_Index (Opnd_Index);
9378 -- If component types have same base type, all set
9380 if Target_Comp_Base = Opnd_Comp_Base then
9383 -- Here if base types of components are not the same. The only
9384 -- time this is allowed is if we have anonymous access types.
9386 -- The conversion of arrays of anonymous access types can lead
9387 -- to dangling pointers. AI-392 formalizes the accessibility
9388 -- checks that must be applied to such conversions to prevent
9389 -- out-of-scope references.
9392 (Ekind (Target_Comp_Base) = E_Anonymous_Access_Type
9394 Ekind (Target_Comp_Base) = E_Anonymous_Access_Subprogram_Type)
9395 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
9397 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
9399 if Type_Access_Level (Target_Type) <
9400 Type_Access_Level (Opnd_Type)
9402 if In_Instance_Body then
9403 Error_Msg_N ("?source array type " &
9404 "has deeper accessibility level than target", Operand);
9405 Error_Msg_N ("\?Program_Error will be raised at run time",
9408 Make_Raise_Program_Error (Sloc (N),
9409 Reason => PE_Accessibility_Check_Failed));
9410 Set_Etype (N, Target_Type);
9413 -- Conversion not allowed because of accessibility levels
9416 Error_Msg_N ("source array type " &
9417 "has deeper accessibility level than target", Operand);
9424 -- All other cases where component base types do not match
9428 ("incompatible component types for array conversion",
9433 -- Check that component subtypes statically match. For numeric
9434 -- types this means that both must be either constrained or
9435 -- unconstrained. For enumeration types the bounds must match.
9436 -- All of this is checked in Subtypes_Statically_Match.
9438 if not Subtypes_Statically_Match
9439 (Target_Comp_Type, Opnd_Comp_Type)
9442 ("component subtypes must statically match", Operand);
9448 end Valid_Array_Conversion;
9450 -----------------------------
9451 -- Valid_Tagged_Conversion --
9452 -----------------------------
9454 function Valid_Tagged_Conversion
9455 (Target_Type : Entity_Id;
9456 Opnd_Type : Entity_Id) return Boolean
9459 -- Upward conversions are allowed (RM 4.6(22))
9461 if Covers (Target_Type, Opnd_Type)
9462 or else Is_Ancestor (Target_Type, Opnd_Type)
9466 -- Downward conversion are allowed if the operand is class-wide
9469 elsif Is_Class_Wide_Type (Opnd_Type)
9470 and then Covers (Opnd_Type, Target_Type)
9474 elsif Covers (Opnd_Type, Target_Type)
9475 or else Is_Ancestor (Opnd_Type, Target_Type)
9478 Conversion_Check (False,
9479 "downward conversion of tagged objects not allowed");
9481 -- Ada 2005 (AI-251): The conversion to/from interface types is
9484 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
9487 -- If the operand is a class-wide type obtained through a limited_
9488 -- with clause, and the context includes the non-limited view, use
9489 -- it to determine whether the conversion is legal.
9491 elsif Is_Class_Wide_Type (Opnd_Type)
9492 and then From_With_Type (Opnd_Type)
9493 and then Present (Non_Limited_View (Etype (Opnd_Type)))
9494 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
9498 elsif Is_Access_Type (Opnd_Type)
9499 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
9505 ("invalid tagged conversion, not compatible with}",
9506 N, First_Subtype (Opnd_Type));
9509 end Valid_Tagged_Conversion;
9511 -- Start of processing for Valid_Conversion
9514 Check_Parameterless_Call (Operand);
9516 if Is_Overloaded (Operand) then
9525 -- Remove procedure calls, which syntactically cannot appear in
9526 -- this context, but which cannot be removed by type checking,
9527 -- because the context does not impose a type.
9529 -- When compiling for VMS, spurious ambiguities can be produced
9530 -- when arithmetic operations have a literal operand and return
9531 -- System.Address or a descendant of it. These ambiguities are
9532 -- otherwise resolved by the context, but for conversions there
9533 -- is no context type and the removal of the spurious operations
9534 -- must be done explicitly here.
9536 -- The node may be labelled overloaded, but still contain only
9537 -- one interpretation because others were discarded in previous
9538 -- filters. If this is the case, retain the single interpretation
9541 Get_First_Interp (Operand, I, It);
9542 Opnd_Type := It.Typ;
9543 Get_Next_Interp (I, It);
9546 and then Opnd_Type /= Standard_Void_Type
9548 -- More than one candidate interpretation is available
9550 Get_First_Interp (Operand, I, It);
9551 while Present (It.Typ) loop
9552 if It.Typ = Standard_Void_Type then
9556 if Present (System_Aux_Id)
9557 and then Is_Descendent_Of_Address (It.Typ)
9562 Get_Next_Interp (I, It);
9566 Get_First_Interp (Operand, I, It);
9571 Error_Msg_N ("illegal operand in conversion", Operand);
9575 Get_Next_Interp (I, It);
9577 if Present (It.Typ) then
9579 It1 := Disambiguate (Operand, I1, I, Any_Type);
9581 if It1 = No_Interp then
9582 Error_Msg_N ("ambiguous operand in conversion", Operand);
9584 Error_Msg_Sloc := Sloc (It.Nam);
9585 Error_Msg_N -- CODEFIX
9586 ("\\possible interpretation#!", Operand);
9588 Error_Msg_Sloc := Sloc (N1);
9589 Error_Msg_N -- CODEFIX
9590 ("\\possible interpretation#!", Operand);
9596 Set_Etype (Operand, It1.Typ);
9597 Opnd_Type := It1.Typ;
9603 if Is_Numeric_Type (Target_Type) then
9605 -- A universal fixed expression can be converted to any numeric type
9607 if Opnd_Type = Universal_Fixed then
9610 -- Also no need to check when in an instance or inlined body, because
9611 -- the legality has been established when the template was analyzed.
9612 -- Furthermore, numeric conversions may occur where only a private
9613 -- view of the operand type is visible at the instantiation point.
9614 -- This results in a spurious error if we check that the operand type
9615 -- is a numeric type.
9617 -- Note: in a previous version of this unit, the following tests were
9618 -- applied only for generated code (Comes_From_Source set to False),
9619 -- but in fact the test is required for source code as well, since
9620 -- this situation can arise in source code.
9622 elsif In_Instance or else In_Inlined_Body then
9625 -- Otherwise we need the conversion check
9628 return Conversion_Check
9629 (Is_Numeric_Type (Opnd_Type),
9630 "illegal operand for numeric conversion");
9635 elsif Is_Array_Type (Target_Type) then
9636 if not Is_Array_Type (Opnd_Type)
9637 or else Opnd_Type = Any_Composite
9638 or else Opnd_Type = Any_String
9641 ("illegal operand for array conversion", Operand);
9644 return Valid_Array_Conversion;
9647 -- Ada 2005 (AI-251): Anonymous access types where target references an
9650 elsif (Ekind (Target_Type) = E_General_Access_Type
9652 Ekind (Target_Type) = E_Anonymous_Access_Type)
9653 and then Is_Interface (Directly_Designated_Type (Target_Type))
9655 -- Check the static accessibility rule of 4.6(17). Note that the
9656 -- check is not enforced when within an instance body, since the
9657 -- RM requires such cases to be caught at run time.
9659 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
9660 if Type_Access_Level (Opnd_Type) >
9661 Type_Access_Level (Target_Type)
9663 -- In an instance, this is a run-time check, but one we know
9664 -- will fail, so generate an appropriate warning. The raise
9665 -- will be generated by Expand_N_Type_Conversion.
9667 if In_Instance_Body then
9669 ("?cannot convert local pointer to non-local access type",
9672 ("\?Program_Error will be raised at run time", Operand);
9675 ("cannot convert local pointer to non-local access type",
9680 -- Special accessibility checks are needed in the case of access
9681 -- discriminants declared for a limited type.
9683 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9684 and then not Is_Local_Anonymous_Access (Opnd_Type)
9686 -- When the operand is a selected access discriminant the check
9687 -- needs to be made against the level of the object denoted by
9688 -- the prefix of the selected name (Object_Access_Level handles
9689 -- checking the prefix of the operand for this case).
9691 if Nkind (Operand) = N_Selected_Component
9692 and then Object_Access_Level (Operand) >
9693 Type_Access_Level (Target_Type)
9695 -- In an instance, this is a run-time check, but one we know
9696 -- will fail, so generate an appropriate warning. The raise
9697 -- will be generated by Expand_N_Type_Conversion.
9699 if In_Instance_Body then
9701 ("?cannot convert access discriminant to non-local" &
9702 " access type", Operand);
9704 ("\?Program_Error will be raised at run time", Operand);
9707 ("cannot convert access discriminant to non-local" &
9708 " access type", Operand);
9713 -- The case of a reference to an access discriminant from
9714 -- within a limited type declaration (which will appear as
9715 -- a discriminal) is always illegal because the level of the
9716 -- discriminant is considered to be deeper than any (nameable)
9719 if Is_Entity_Name (Operand)
9720 and then not Is_Local_Anonymous_Access (Opnd_Type)
9721 and then (Ekind (Entity (Operand)) = E_In_Parameter
9722 or else Ekind (Entity (Operand)) = E_Constant)
9723 and then Present (Discriminal_Link (Entity (Operand)))
9726 ("discriminant has deeper accessibility level than target",
9735 -- General and anonymous access types
9737 elsif (Ekind (Target_Type) = E_General_Access_Type
9738 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
9741 (Is_Access_Type (Opnd_Type)
9742 and then Ekind (Opnd_Type) /=
9743 E_Access_Subprogram_Type
9744 and then Ekind (Opnd_Type) /=
9745 E_Access_Protected_Subprogram_Type,
9746 "must be an access-to-object type")
9748 if Is_Access_Constant (Opnd_Type)
9749 and then not Is_Access_Constant (Target_Type)
9752 ("access-to-constant operand type not allowed", Operand);
9756 -- Check the static accessibility rule of 4.6(17). Note that the
9757 -- check is not enforced when within an instance body, since the RM
9758 -- requires such cases to be caught at run time.
9760 if Ekind (Target_Type) /= E_Anonymous_Access_Type
9761 or else Is_Local_Anonymous_Access (Target_Type)
9763 if Type_Access_Level (Opnd_Type)
9764 > Type_Access_Level (Target_Type)
9766 -- In an instance, this is a run-time check, but one we know
9767 -- will fail, so generate an appropriate warning. The raise
9768 -- will be generated by Expand_N_Type_Conversion.
9770 if In_Instance_Body then
9772 ("?cannot convert local pointer to non-local access type",
9775 ("\?Program_Error will be raised at run time", Operand);
9778 -- Avoid generation of spurious error message
9780 if not Error_Posted (N) then
9782 ("cannot convert local pointer to non-local access type",
9789 -- Special accessibility checks are needed in the case of access
9790 -- discriminants declared for a limited type.
9792 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9793 and then not Is_Local_Anonymous_Access (Opnd_Type)
9795 -- When the operand is a selected access discriminant the check
9796 -- needs to be made against the level of the object denoted by
9797 -- the prefix of the selected name (Object_Access_Level handles
9798 -- checking the prefix of the operand for this case).
9800 if Nkind (Operand) = N_Selected_Component
9801 and then Object_Access_Level (Operand) >
9802 Type_Access_Level (Target_Type)
9804 -- In an instance, this is a run-time check, but one we know
9805 -- will fail, so generate an appropriate warning. The raise
9806 -- will be generated by Expand_N_Type_Conversion.
9808 if In_Instance_Body then
9810 ("?cannot convert access discriminant to non-local" &
9811 " access type", Operand);
9813 ("\?Program_Error will be raised at run time",
9818 ("cannot convert access discriminant to non-local" &
9819 " access type", Operand);
9824 -- The case of a reference to an access discriminant from
9825 -- within a limited type declaration (which will appear as
9826 -- a discriminal) is always illegal because the level of the
9827 -- discriminant is considered to be deeper than any (nameable)
9830 if Is_Entity_Name (Operand)
9831 and then (Ekind (Entity (Operand)) = E_In_Parameter
9832 or else Ekind (Entity (Operand)) = E_Constant)
9833 and then Present (Discriminal_Link (Entity (Operand)))
9836 ("discriminant has deeper accessibility level than target",
9843 -- In the presence of limited_with clauses we have to use non-limited
9844 -- views, if available.
9846 Check_Limited : declare
9847 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
9848 -- Helper function to handle limited views
9850 --------------------------
9851 -- Full_Designated_Type --
9852 --------------------------
9854 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
9855 Desig : constant Entity_Id := Designated_Type (T);
9858 -- Handle the limited view of a type
9860 if Is_Incomplete_Type (Desig)
9861 and then From_With_Type (Desig)
9862 and then Present (Non_Limited_View (Desig))
9864 return Available_View (Desig);
9868 end Full_Designated_Type;
9870 -- Local Declarations
9872 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
9873 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
9875 Same_Base : constant Boolean :=
9876 Base_Type (Target) = Base_Type (Opnd);
9878 -- Start of processing for Check_Limited
9881 if Is_Tagged_Type (Target) then
9882 return Valid_Tagged_Conversion (Target, Opnd);
9885 if not Same_Base then
9887 ("target designated type not compatible with }",
9888 N, Base_Type (Opnd));
9891 -- Ada 2005 AI-384: legality rule is symmetric in both
9892 -- designated types. The conversion is legal (with possible
9893 -- constraint check) if either designated type is
9896 elsif Subtypes_Statically_Match (Target, Opnd)
9898 (Has_Discriminants (Target)
9900 (not Is_Constrained (Opnd)
9901 or else not Is_Constrained (Target)))
9903 -- Special case, if Value_Size has been used to make the
9904 -- sizes different, the conversion is not allowed even
9905 -- though the subtypes statically match.
9907 if Known_Static_RM_Size (Target)
9908 and then Known_Static_RM_Size (Opnd)
9909 and then RM_Size (Target) /= RM_Size (Opnd)
9912 ("target designated subtype not compatible with }",
9915 ("\because sizes of the two designated subtypes differ",
9919 -- Normal case where conversion is allowed
9927 ("target designated subtype not compatible with }",
9934 -- Access to subprogram types. If the operand is an access parameter,
9935 -- the type has a deeper accessibility that any master, and cannot
9936 -- be assigned. We must make an exception if the conversion is part
9937 -- of an assignment and the target is the return object of an extended
9938 -- return statement, because in that case the accessibility check
9939 -- takes place after the return.
9941 elsif Is_Access_Subprogram_Type (Target_Type)
9942 and then No (Corresponding_Remote_Type (Opnd_Type))
9944 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
9945 and then Is_Entity_Name (Operand)
9946 and then Ekind (Entity (Operand)) = E_In_Parameter
9948 (Nkind (Parent (N)) /= N_Assignment_Statement
9949 or else not Is_Entity_Name (Name (Parent (N)))
9950 or else not Is_Return_Object (Entity (Name (Parent (N)))))
9953 ("illegal attempt to store anonymous access to subprogram",
9956 ("\value has deeper accessibility than any master " &
9961 ("\use named access type for& instead of access parameter",
9962 Operand, Entity (Operand));
9965 -- Check that the designated types are subtype conformant
9967 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
9968 Old_Id => Designated_Type (Opnd_Type),
9971 -- Check the static accessibility rule of 4.6(20)
9973 if Type_Access_Level (Opnd_Type) >
9974 Type_Access_Level (Target_Type)
9977 ("operand type has deeper accessibility level than target",
9980 -- Check that if the operand type is declared in a generic body,
9981 -- then the target type must be declared within that same body
9982 -- (enforces last sentence of 4.6(20)).
9984 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
9986 O_Gen : constant Node_Id :=
9987 Enclosing_Generic_Body (Opnd_Type);
9992 T_Gen := Enclosing_Generic_Body (Target_Type);
9993 while Present (T_Gen) and then T_Gen /= O_Gen loop
9994 T_Gen := Enclosing_Generic_Body (T_Gen);
9997 if T_Gen /= O_Gen then
9999 ("target type must be declared in same generic body"
10000 & " as operand type", N);
10007 -- Remote subprogram access types
10009 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
10010 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
10012 -- It is valid to convert from one RAS type to another provided
10013 -- that their specification statically match.
10015 Check_Subtype_Conformant
10017 Designated_Type (Corresponding_Remote_Type (Target_Type)),
10019 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
10024 -- If both are tagged types, check legality of view conversions
10026 elsif Is_Tagged_Type (Target_Type)
10027 and then Is_Tagged_Type (Opnd_Type)
10029 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
10031 -- Types derived from the same root type are convertible
10033 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
10036 -- In an instance or an inlined body, there may be inconsistent
10037 -- views of the same type, or of types derived from a common root.
10039 elsif (In_Instance or In_Inlined_Body)
10041 Root_Type (Underlying_Type (Target_Type)) =
10042 Root_Type (Underlying_Type (Opnd_Type))
10046 -- Special check for common access type error case
10048 elsif Ekind (Target_Type) = E_Access_Type
10049 and then Is_Access_Type (Opnd_Type)
10051 Error_Msg_N ("target type must be general access type!", N);
10052 Error_Msg_NE ("add ALL to }!", N, Target_Type);
10056 Error_Msg_NE ("invalid conversion, not compatible with }",
10060 end Valid_Conversion;