1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Debug_A; use Debug_A;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Ch6; use Exp_Ch6;
36 with Exp_Ch7; use Exp_Ch7;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
41 with Itypes; use Itypes;
43 with Lib.Xref; use Lib.Xref;
44 with Namet; use Namet;
45 with Nmake; use Nmake;
46 with Nlists; use Nlists;
48 with Output; use Output;
49 with Restrict; use Restrict;
50 with Rident; use Rident;
51 with Rtsfind; use Rtsfind;
53 with Sem_Aux; use Sem_Aux;
54 with Sem_Aggr; use Sem_Aggr;
55 with Sem_Attr; use Sem_Attr;
56 with Sem_Cat; use Sem_Cat;
57 with Sem_Ch4; use Sem_Ch4;
58 with Sem_Ch6; use Sem_Ch6;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Elab; use Sem_Elab;
65 with Sem_Eval; use Sem_Eval;
66 with Sem_Intr; use Sem_Intr;
67 with Sem_Util; use Sem_Util;
68 with Sem_Type; use Sem_Type;
69 with Sem_Warn; use Sem_Warn;
70 with Sinfo; use Sinfo;
71 with Snames; use Snames;
72 with Stand; use Stand;
73 with Stringt; use Stringt;
74 with Style; use Style;
75 with 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 comparison or logical operator. If the operator
124 -- is predefined, and the root type of the operands is Standard.Boolean,
125 -- then a check is made for restriction No_Direct_Boolean_Operators.
127 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
128 -- Determine whether E is an access type declared by an access
129 -- declaration, and not an (anonymous) allocator type.
131 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
132 -- Utility to check whether the name in the call is a predefined
133 -- operator, in which case the call is made into an operator node.
134 -- An instance of an intrinsic conversion operation may be given
135 -- an operator name, but is not treated like an operator.
137 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
138 -- If a default expression in entry call N depends on the discriminants
139 -- of the task, it must be replaced with a reference to the discriminant
140 -- of the task being called.
142 procedure Resolve_Op_Concat_Arg
147 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
148 -- concatenation operator. The operand is either of the array type or of
149 -- the component type. If the operand is an aggregate, and the component
150 -- type is composite, this is ambiguous if component type has aggregates.
152 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
153 -- Does the first part of the work of Resolve_Op_Concat
155 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
156 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
157 -- has been resolved. See Resolve_Op_Concat for details.
159 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
160 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
161 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
162 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
163 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
164 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
165 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
166 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
167 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
168 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
169 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
170 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
171 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
172 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
173 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
174 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
175 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
176 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
177 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
178 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
179 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
180 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
185 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
186 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
187 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
188 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
189 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
190 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
192 function Operator_Kind
194 Is_Binary : Boolean) return Node_Kind;
195 -- Utility to map the name of an operator into the corresponding Node. Used
196 -- by other node rewriting procedures.
198 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
199 -- Resolve actuals of call, and add default expressions for missing ones.
200 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
201 -- called subprogram.
203 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
204 -- Called from Resolve_Call, when the prefix denotes an entry or element
205 -- of entry family. Actuals are resolved as for subprograms, and the node
206 -- is rebuilt as an entry call. Also called for protected operations. Typ
207 -- is the context type, which is used when the operation is a protected
208 -- function with no arguments, and the return value is indexed.
210 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
211 -- A call to a user-defined intrinsic operator is rewritten as a call
212 -- to the corresponding predefined operator, with suitable conversions.
214 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
215 -- Ditto, for unary operators (only arithmetic ones)
217 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
218 -- If an operator node resolves to a call to a user-defined operator,
219 -- rewrite the node as a function call.
221 procedure Make_Call_Into_Operator
225 -- Inverse transformation: if an operator is given in functional notation,
226 -- then after resolving the node, transform into an operator node, so
227 -- that operands are resolved properly. Recall that predefined operators
228 -- do not have a full signature and special resolution rules apply.
230 procedure Rewrite_Renamed_Operator
234 -- An operator can rename another, e.g. in an instantiation. In that
235 -- case, the proper operator node must be constructed and resolved.
237 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
238 -- The String_Literal_Subtype is built for all strings that are not
239 -- operands of a static concatenation operation. If the argument is
240 -- not a N_String_Literal node, then the call has no effect.
242 procedure Set_Slice_Subtype (N : Node_Id);
243 -- Build subtype of array type, with the range specified by the slice
245 procedure Simplify_Type_Conversion (N : Node_Id);
246 -- Called after N has been resolved and evaluated, but before range checks
247 -- have been applied. Currently simplifies a combination of floating-point
248 -- to integer conversion and Truncation attribute.
250 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
251 -- A universal_fixed expression in an universal context is unambiguous
252 -- if there is only one applicable fixed point type. Determining whether
253 -- there is only one requires a search over all visible entities, and
254 -- happens only in very pathological cases (see 6115-006).
256 function Valid_Conversion
259 Operand : Node_Id) return Boolean;
260 -- Verify legality rules given in 4.6 (8-23). Target is the target
261 -- type of the conversion, which may be an implicit conversion of
262 -- an actual parameter to an anonymous access type (in which case
263 -- N denotes the actual parameter and N = Operand).
265 -------------------------
266 -- Ambiguous_Character --
267 -------------------------
269 procedure Ambiguous_Character (C : Node_Id) is
273 if Nkind (C) = N_Character_Literal then
274 Error_Msg_N ("ambiguous character literal", C);
276 -- First the ones in Standard
279 ("\\possible interpretation: Character!", C);
281 ("\\possible interpretation: Wide_Character!", C);
283 -- Include Wide_Wide_Character in Ada 2005 mode
285 if Ada_Version >= Ada_05 then
287 ("\\possible interpretation: Wide_Wide_Character!", C);
290 -- Now any other types that match
292 E := Current_Entity (C);
293 while Present (E) loop
294 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
298 end Ambiguous_Character;
300 -------------------------
301 -- Analyze_And_Resolve --
302 -------------------------
304 procedure Analyze_And_Resolve (N : Node_Id) is
308 end Analyze_And_Resolve;
310 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
314 end Analyze_And_Resolve;
316 -- Version withs check(s) suppressed
318 procedure Analyze_And_Resolve
323 Scop : constant Entity_Id := Current_Scope;
326 if Suppress = All_Checks then
328 Svg : constant Suppress_Array := Scope_Suppress;
330 Scope_Suppress := (others => True);
331 Analyze_And_Resolve (N, Typ);
332 Scope_Suppress := Svg;
337 Svg : constant Boolean := Scope_Suppress (Suppress);
340 Scope_Suppress (Suppress) := True;
341 Analyze_And_Resolve (N, Typ);
342 Scope_Suppress (Suppress) := Svg;
346 if Current_Scope /= Scop
347 and then Scope_Is_Transient
349 -- This can only happen if a transient scope was created
350 -- for an inner expression, which will be removed upon
351 -- completion of the analysis of an enclosing construct.
352 -- The transient scope must have the suppress status of
353 -- the enclosing environment, not of this Analyze call.
355 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
358 end Analyze_And_Resolve;
360 procedure Analyze_And_Resolve
364 Scop : constant Entity_Id := Current_Scope;
367 if Suppress = All_Checks then
369 Svg : constant Suppress_Array := Scope_Suppress;
371 Scope_Suppress := (others => True);
372 Analyze_And_Resolve (N);
373 Scope_Suppress := Svg;
378 Svg : constant Boolean := Scope_Suppress (Suppress);
381 Scope_Suppress (Suppress) := True;
382 Analyze_And_Resolve (N);
383 Scope_Suppress (Suppress) := Svg;
387 if Current_Scope /= Scop
388 and then Scope_Is_Transient
390 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
393 end Analyze_And_Resolve;
395 ----------------------------
396 -- Check_Discriminant_Use --
397 ----------------------------
399 procedure Check_Discriminant_Use (N : Node_Id) is
400 PN : constant Node_Id := Parent (N);
401 Disc : constant Entity_Id := Entity (N);
406 -- Any use in a spec-expression is legal
408 if In_Spec_Expression then
411 elsif Nkind (PN) = N_Range then
413 -- Discriminant cannot be used to constrain a scalar type
417 if Nkind (P) = N_Range_Constraint
418 and then Nkind (Parent (P)) = N_Subtype_Indication
419 and then Nkind (Parent (Parent (P))) = N_Component_Definition
421 Error_Msg_N ("discriminant cannot constrain scalar type", N);
423 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
425 -- The following check catches the unusual case where
426 -- a discriminant appears within an index constraint
427 -- that is part of a larger expression within a constraint
428 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
429 -- For now we only check case of record components, and
430 -- note that a similar check should also apply in the
431 -- case of discriminant constraints below. ???
433 -- Note that the check for N_Subtype_Declaration below is to
434 -- detect the valid use of discriminants in the constraints of a
435 -- subtype declaration when this subtype declaration appears
436 -- inside the scope of a record type (which is syntactically
437 -- illegal, but which may be created as part of derived type
438 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
441 if Ekind (Current_Scope) = E_Record_Type
442 and then Scope (Disc) = Current_Scope
444 (Nkind (Parent (P)) = N_Subtype_Indication
446 Nkind_In (Parent (Parent (P)), N_Component_Definition,
447 N_Subtype_Declaration)
448 and then Paren_Count (N) = 0)
451 ("discriminant must appear alone in component constraint", N);
455 -- Detect a common error:
457 -- type R (D : Positive := 100) is record
458 -- Name : String (1 .. D);
461 -- The default value causes an object of type R to be allocated
462 -- with room for Positive'Last characters. The RM does not mandate
463 -- the allocation of the maximum size, but that is what GNAT does
464 -- so we should warn the programmer that there is a problem.
466 Check_Large : declare
472 function Large_Storage_Type (T : Entity_Id) return Boolean;
473 -- Return True if type T has a large enough range that
474 -- any array whose index type covered the whole range of
475 -- the type would likely raise Storage_Error.
477 ------------------------
478 -- Large_Storage_Type --
479 ------------------------
481 function Large_Storage_Type (T : Entity_Id) return Boolean is
483 -- The type is considered large if its bounds are known at
484 -- compile time and if it requires at least as many bits as
485 -- a Positive to store the possible values.
487 return Compile_Time_Known_Value (Type_Low_Bound (T))
488 and then Compile_Time_Known_Value (Type_High_Bound (T))
490 Minimum_Size (T, Biased => True) >=
491 RM_Size (Standard_Positive);
492 end Large_Storage_Type;
494 -- Start of processing for Check_Large
497 -- Check that the Disc has a large range
499 if not Large_Storage_Type (Etype (Disc)) then
503 -- If the enclosing type is limited, we allocate only the
504 -- default value, not the maximum, and there is no need for
507 if Is_Limited_Type (Scope (Disc)) then
511 -- Check that it is the high bound
513 if N /= High_Bound (PN)
514 or else No (Discriminant_Default_Value (Disc))
519 -- Check the array allows a large range at this bound.
520 -- First find the array
524 if Nkind (SI) /= N_Subtype_Indication then
528 T := Entity (Subtype_Mark (SI));
530 if not Is_Array_Type (T) then
534 -- Next, find the dimension
536 TB := First_Index (T);
537 CB := First (Constraints (P));
539 and then Present (TB)
540 and then Present (CB)
551 -- Now, check the dimension has a large range
553 if not Large_Storage_Type (Etype (TB)) then
557 -- Warn about the danger
560 ("?creation of & object may raise Storage_Error!",
569 -- Legal case is in index or discriminant constraint
571 elsif Nkind_In (PN, N_Index_Or_Discriminant_Constraint,
572 N_Discriminant_Association)
574 if Paren_Count (N) > 0 then
576 ("discriminant in constraint must appear alone", N);
578 elsif Nkind (N) = N_Expanded_Name
579 and then Comes_From_Source (N)
582 ("discriminant must appear alone as a direct name", N);
587 -- Otherwise, context is an expression. It should not be within
588 -- (i.e. a subexpression of) a constraint for a component.
593 while not Nkind_In (P, N_Component_Declaration,
594 N_Subtype_Indication,
602 -- If the discriminant is used in an expression that is a bound
603 -- of a scalar type, an Itype is created and the bounds are attached
604 -- to its range, not to the original subtype indication. Such use
605 -- is of course a double fault.
607 if (Nkind (P) = N_Subtype_Indication
608 and then Nkind_In (Parent (P), N_Component_Definition,
609 N_Derived_Type_Definition)
610 and then D = Constraint (P))
612 -- The constraint itself may be given by a subtype indication,
613 -- rather than by a more common discrete range.
615 or else (Nkind (P) = N_Subtype_Indication
617 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
618 or else Nkind (P) = N_Entry_Declaration
619 or else Nkind (D) = N_Defining_Identifier
622 ("discriminant in constraint must appear alone", N);
625 end Check_Discriminant_Use;
627 --------------------------------
628 -- Check_For_Visible_Operator --
629 --------------------------------
631 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
633 if Is_Invisible_Operator (N, T) then
635 ("operator for} is not directly visible!", N, First_Subtype (T));
636 Error_Msg_N ("use clause would make operation legal!", N);
638 end Check_For_Visible_Operator;
640 ----------------------------------
641 -- Check_Fully_Declared_Prefix --
642 ----------------------------------
644 procedure Check_Fully_Declared_Prefix
649 -- Check that the designated type of the prefix of a dereference is
650 -- not an incomplete type. This cannot be done unconditionally, because
651 -- dereferences of private types are legal in default expressions. This
652 -- case is taken care of in Check_Fully_Declared, called below. There
653 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
655 -- This consideration also applies to similar checks for allocators,
656 -- qualified expressions, and type conversions.
658 -- An additional exception concerns other per-object expressions that
659 -- are not directly related to component declarations, in particular
660 -- representation pragmas for tasks. These will be per-object
661 -- expressions if they depend on discriminants or some global entity.
662 -- If the task has access discriminants, the designated type may be
663 -- incomplete at the point the expression is resolved. This resolution
664 -- takes place within the body of the initialization procedure, where
665 -- the discriminant is replaced by its discriminal.
667 if Is_Entity_Name (Pref)
668 and then Ekind (Entity (Pref)) = E_In_Parameter
672 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
673 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
674 -- Analyze_Object_Renaming, and Freeze_Entity.
676 elsif Ada_Version >= Ada_05
677 and then Is_Entity_Name (Pref)
678 and then Is_Access_Type (Etype (Pref))
679 and then Ekind (Directly_Designated_Type (Etype (Pref))) =
681 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Pref)))
685 Check_Fully_Declared (Typ, Parent (Pref));
687 end Check_Fully_Declared_Prefix;
689 ------------------------------
690 -- Check_Infinite_Recursion --
691 ------------------------------
693 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
697 function Same_Argument_List return Boolean;
698 -- Check whether list of actuals is identical to list of formals
699 -- of called function (which is also the enclosing scope).
701 ------------------------
702 -- Same_Argument_List --
703 ------------------------
705 function Same_Argument_List return Boolean is
711 if not Is_Entity_Name (Name (N)) then
714 Subp := Entity (Name (N));
717 F := First_Formal (Subp);
718 A := First_Actual (N);
719 while Present (F) and then Present (A) loop
720 if not Is_Entity_Name (A)
721 or else Entity (A) /= F
731 end Same_Argument_List;
733 -- Start of processing for Check_Infinite_Recursion
736 -- Special case, if this is a procedure call and is a call to the
737 -- current procedure with the same argument list, then this is for
738 -- sure an infinite recursion and we insert a call to raise SE.
740 if Is_List_Member (N)
741 and then List_Length (List_Containing (N)) = 1
742 and then Same_Argument_List
745 P : constant Node_Id := Parent (N);
747 if Nkind (P) = N_Handled_Sequence_Of_Statements
748 and then Nkind (Parent (P)) = N_Subprogram_Body
749 and then Is_Empty_List (Declarations (Parent (P)))
751 Error_Msg_N ("!?infinite recursion", N);
752 Error_Msg_N ("\!?Storage_Error will be raised at run time", N);
754 Make_Raise_Storage_Error (Sloc (N),
755 Reason => SE_Infinite_Recursion));
761 -- If not that special case, search up tree, quitting if we reach a
762 -- construct (e.g. a conditional) that tells us that this is not a
763 -- case for an infinite recursion warning.
769 -- If no parent, then we were not inside a subprogram, this can for
770 -- example happen when processing certain pragmas in a spec. Just
771 -- return False in this case.
777 -- Done if we get to subprogram body, this is definitely an infinite
778 -- recursion case if we did not find anything to stop us.
780 exit when Nkind (P) = N_Subprogram_Body;
782 -- If appearing in conditional, result is false
784 if Nkind_In (P, N_Or_Else,
791 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
792 and then C /= First (Statements (P))
794 -- If the call is the expression of a return statement and the
795 -- actuals are identical to the formals, it's worth a warning.
796 -- However, we skip this if there is an immediately preceding
797 -- raise statement, since the call is never executed.
799 -- Furthermore, this corresponds to a common idiom:
801 -- function F (L : Thing) return Boolean is
803 -- raise Program_Error;
807 -- for generating a stub function
809 if Nkind (Parent (N)) = N_Simple_Return_Statement
810 and then Same_Argument_List
812 exit when not Is_List_Member (Parent (N));
814 -- OK, return statement is in a statement list, look for raise
820 -- Skip past N_Freeze_Entity nodes generated by expansion
822 Nod := Prev (Parent (N));
824 and then Nkind (Nod) = N_Freeze_Entity
829 -- If no raise statement, give warning
831 exit when Nkind (Nod) /= N_Raise_Statement
833 (Nkind (Nod) not in N_Raise_xxx_Error
834 or else Present (Condition (Nod)));
845 Error_Msg_N ("!?possible infinite recursion", N);
846 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
849 end Check_Infinite_Recursion;
851 -------------------------------
852 -- Check_Initialization_Call --
853 -------------------------------
855 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
856 Typ : constant Entity_Id := Etype (First_Formal (Nam));
858 function Uses_SS (T : Entity_Id) return Boolean;
859 -- Check whether the creation of an object of the type will involve
860 -- use of the secondary stack. If T is a record type, this is true
861 -- if the expression for some component uses the secondary stack, e.g.
862 -- through a call to a function that returns an unconstrained value.
863 -- False if T is controlled, because cleanups occur elsewhere.
869 function Uses_SS (T : Entity_Id) return Boolean is
872 Full_Type : Entity_Id := Underlying_Type (T);
875 -- Normally we want to use the underlying type, but if it's not set
876 -- then continue with T.
878 if not Present (Full_Type) then
882 if Is_Controlled (Full_Type) then
885 elsif Is_Array_Type (Full_Type) then
886 return Uses_SS (Component_Type (Full_Type));
888 elsif Is_Record_Type (Full_Type) then
889 Comp := First_Component (Full_Type);
890 while Present (Comp) loop
891 if Ekind (Comp) = E_Component
892 and then Nkind (Parent (Comp)) = N_Component_Declaration
894 -- The expression for a dynamic component may be rewritten
895 -- as a dereference, so retrieve original node.
897 Expr := Original_Node (Expression (Parent (Comp)));
899 -- Return True if the expression is a call to a function
900 -- (including an attribute function such as Image) with
901 -- a result that requires a transient scope.
903 if (Nkind (Expr) = N_Function_Call
904 or else (Nkind (Expr) = N_Attribute_Reference
905 and then Present (Expressions (Expr))))
906 and then Requires_Transient_Scope (Etype (Expr))
910 elsif Uses_SS (Etype (Comp)) then
915 Next_Component (Comp);
925 -- Start of processing for Check_Initialization_Call
928 -- Establish a transient scope if the type needs it
930 if Uses_SS (Typ) then
931 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
933 end Check_Initialization_Call;
935 ---------------------------------------
936 -- Check_No_Direct_Boolean_Operators --
937 ---------------------------------------
939 procedure Check_No_Direct_Boolean_Operators (N : Node_Id) is
941 if Scope (Entity (N)) = Standard_Standard
942 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
944 -- Restriction does not apply to generated code
946 if not Comes_From_Source (N) then
949 -- Restriction does not apply for A=False, A=True
951 elsif Nkind (N) = N_Op_Eq
952 and then (Is_Entity_Name (Right_Opnd (N))
953 and then (Entity (Right_Opnd (N)) = Standard_True
955 Entity (Right_Opnd (N)) = Standard_False))
959 -- Otherwise restriction applies
962 Check_Restriction (No_Direct_Boolean_Operators, N);
965 end Check_No_Direct_Boolean_Operators;
967 ------------------------------
968 -- Check_Parameterless_Call --
969 ------------------------------
971 procedure Check_Parameterless_Call (N : Node_Id) is
974 function Prefix_Is_Access_Subp return Boolean;
975 -- If the prefix is of an access_to_subprogram type, the node must be
976 -- rewritten as a call. Ditto if the prefix is overloaded and all its
977 -- interpretations are access to subprograms.
979 ---------------------------
980 -- Prefix_Is_Access_Subp --
981 ---------------------------
983 function Prefix_Is_Access_Subp return Boolean is
988 if not Is_Overloaded (N) then
990 Ekind (Etype (N)) = E_Subprogram_Type
991 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
993 Get_First_Interp (N, I, It);
994 while Present (It.Typ) loop
995 if Ekind (It.Typ) /= E_Subprogram_Type
996 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
1001 Get_Next_Interp (I, It);
1006 end Prefix_Is_Access_Subp;
1008 -- Start of processing for Check_Parameterless_Call
1011 -- Defend against junk stuff if errors already detected
1013 if Total_Errors_Detected /= 0 then
1014 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
1016 elsif Nkind (N) in N_Has_Chars
1017 and then Chars (N) in Error_Name_Or_No_Name
1025 -- If the context expects a value, and the name is a procedure, this is
1026 -- most likely a missing 'Access. Don't try to resolve the parameterless
1027 -- call, error will be caught when the outer call is analyzed.
1029 if Is_Entity_Name (N)
1030 and then Ekind (Entity (N)) = E_Procedure
1031 and then not Is_Overloaded (N)
1033 Nkind_In (Parent (N), N_Parameter_Association,
1035 N_Procedure_Call_Statement)
1040 -- Rewrite as call if overloadable entity that is (or could be, in the
1041 -- overloaded case) a function call. If we know for sure that the entity
1042 -- is an enumeration literal, we do not rewrite it.
1044 if (Is_Entity_Name (N)
1045 and then Is_Overloadable (Entity (N))
1046 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1047 or else Is_Overloaded (N)))
1049 -- Rewrite as call if it is an explicit deference of an expression of
1050 -- a subprogram access type, and the subprogram type is not that of a
1051 -- procedure or entry.
1054 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1056 -- Rewrite as call if it is a selected component which is a function,
1057 -- this is the case of a call to a protected function (which may be
1058 -- overloaded with other protected operations).
1061 (Nkind (N) = N_Selected_Component
1062 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1064 ((Ekind (Entity (Selector_Name (N))) = E_Entry
1066 Ekind (Entity (Selector_Name (N))) = E_Procedure)
1067 and then Is_Overloaded (Selector_Name (N)))))
1069 -- If one of the above three conditions is met, rewrite as call.
1070 -- Apply the rewriting only once.
1073 if Nkind (Parent (N)) /= N_Function_Call
1074 or else N /= Name (Parent (N))
1076 Nam := New_Copy (N);
1078 -- If overloaded, overload set belongs to new copy
1080 Save_Interps (N, Nam);
1082 -- Change node to parameterless function call (note that the
1083 -- Parameter_Associations associations field is left set to Empty,
1084 -- its normal default value since there are no parameters)
1086 Change_Node (N, N_Function_Call);
1088 Set_Sloc (N, Sloc (Nam));
1092 elsif Nkind (N) = N_Parameter_Association then
1093 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1095 end Check_Parameterless_Call;
1097 -----------------------------
1098 -- Is_Definite_Access_Type --
1099 -----------------------------
1101 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1102 Btyp : constant Entity_Id := Base_Type (E);
1104 return Ekind (Btyp) = E_Access_Type
1105 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1106 and then Comes_From_Source (Btyp));
1107 end Is_Definite_Access_Type;
1109 ----------------------
1110 -- Is_Predefined_Op --
1111 ----------------------
1113 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1115 return Is_Intrinsic_Subprogram (Nam)
1116 and then not Is_Generic_Instance (Nam)
1117 and then Chars (Nam) in Any_Operator_Name
1118 and then (No (Alias (Nam))
1119 or else Is_Predefined_Op (Alias (Nam)));
1120 end Is_Predefined_Op;
1122 -----------------------------
1123 -- Make_Call_Into_Operator --
1124 -----------------------------
1126 procedure Make_Call_Into_Operator
1131 Op_Name : constant Name_Id := Chars (Op_Id);
1132 Act1 : Node_Id := First_Actual (N);
1133 Act2 : Node_Id := Next_Actual (Act1);
1134 Error : Boolean := False;
1135 Func : constant Entity_Id := Entity (Name (N));
1136 Is_Binary : constant Boolean := Present (Act2);
1138 Opnd_Type : Entity_Id;
1139 Orig_Type : Entity_Id := Empty;
1142 type Kind_Test is access function (E : Entity_Id) return Boolean;
1144 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1145 -- If the operand is not universal, and the operator is given by a
1146 -- expanded name, verify that the operand has an interpretation with
1147 -- a type defined in the given scope of the operator.
1149 function Type_In_P (Test : Kind_Test) return Entity_Id;
1150 -- Find a type of the given class in the package Pack that contains
1153 ---------------------------
1154 -- Operand_Type_In_Scope --
1155 ---------------------------
1157 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1158 Nod : constant Node_Id := Right_Opnd (Op_Node);
1163 if not Is_Overloaded (Nod) then
1164 return Scope (Base_Type (Etype (Nod))) = S;
1167 Get_First_Interp (Nod, I, It);
1168 while Present (It.Typ) loop
1169 if Scope (Base_Type (It.Typ)) = S then
1173 Get_Next_Interp (I, It);
1178 end Operand_Type_In_Scope;
1184 function Type_In_P (Test : Kind_Test) return Entity_Id is
1187 function In_Decl return Boolean;
1188 -- Verify that node is not part of the type declaration for the
1189 -- candidate type, which would otherwise be invisible.
1195 function In_Decl return Boolean is
1196 Decl_Node : constant Node_Id := Parent (E);
1202 if Etype (E) = Any_Type then
1205 elsif No (Decl_Node) then
1210 and then Nkind (N2) /= N_Compilation_Unit
1212 if N2 = Decl_Node then
1223 -- Start of processing for Type_In_P
1226 -- If the context type is declared in the prefix package, this
1227 -- is the desired base type.
1229 if Scope (Base_Type (Typ)) = Pack
1232 return Base_Type (Typ);
1235 E := First_Entity (Pack);
1236 while Present (E) loop
1238 and then not In_Decl
1250 -- Start of processing for Make_Call_Into_Operator
1253 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1258 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1259 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1260 Save_Interps (Act1, Left_Opnd (Op_Node));
1261 Save_Interps (Act2, Right_Opnd (Op_Node));
1262 Act1 := Left_Opnd (Op_Node);
1263 Act2 := Right_Opnd (Op_Node);
1268 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1269 Save_Interps (Act1, Right_Opnd (Op_Node));
1270 Act1 := Right_Opnd (Op_Node);
1273 -- If the operator is denoted by an expanded name, and the prefix is
1274 -- not Standard, but the operator is a predefined one whose scope is
1275 -- Standard, then this is an implicit_operator, inserted as an
1276 -- interpretation by the procedure of the same name. This procedure
1277 -- overestimates the presence of implicit operators, because it does
1278 -- not examine the type of the operands. Verify now that the operand
1279 -- type appears in the given scope. If right operand is universal,
1280 -- check the other operand. In the case of concatenation, either
1281 -- argument can be the component type, so check the type of the result.
1282 -- If both arguments are literals, look for a type of the right kind
1283 -- defined in the given scope. This elaborate nonsense is brought to
1284 -- you courtesy of b33302a. The type itself must be frozen, so we must
1285 -- find the type of the proper class in the given scope.
1287 -- A final wrinkle is the multiplication operator for fixed point
1288 -- types, which is defined in Standard only, and not in the scope of
1289 -- the fixed_point type itself.
1291 if Nkind (Name (N)) = N_Expanded_Name then
1292 Pack := Entity (Prefix (Name (N)));
1294 -- If the entity being called is defined in the given package,
1295 -- it is a renaming of a predefined operator, and known to be
1298 if Scope (Entity (Name (N))) = Pack
1299 and then Pack /= Standard_Standard
1303 -- Visibility does not need to be checked in an instance: if the
1304 -- operator was not visible in the generic it has been diagnosed
1305 -- already, else there is an implicit copy of it in the instance.
1307 elsif In_Instance then
1310 elsif (Op_Name = Name_Op_Multiply
1311 or else Op_Name = Name_Op_Divide)
1312 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1313 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1315 if Pack /= Standard_Standard then
1319 -- Ada 2005, AI-420: Predefined equality on Universal_Access
1322 elsif Ada_Version >= Ada_05
1323 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1324 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1329 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1331 if Op_Name = Name_Op_Concat then
1332 Opnd_Type := Base_Type (Typ);
1334 elsif (Scope (Opnd_Type) = Standard_Standard
1336 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1338 and then not Comes_From_Source (Opnd_Type))
1340 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1343 if Scope (Opnd_Type) = Standard_Standard then
1345 -- Verify that the scope contains a type that corresponds to
1346 -- the given literal. Optimize the case where Pack is Standard.
1348 if Pack /= Standard_Standard then
1350 if Opnd_Type = Universal_Integer then
1351 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1353 elsif Opnd_Type = Universal_Real then
1354 Orig_Type := Type_In_P (Is_Real_Type'Access);
1356 elsif Opnd_Type = Any_String then
1357 Orig_Type := Type_In_P (Is_String_Type'Access);
1359 elsif Opnd_Type = Any_Access then
1360 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1362 elsif Opnd_Type = Any_Composite then
1363 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1365 if Present (Orig_Type) then
1366 if Has_Private_Component (Orig_Type) then
1369 Set_Etype (Act1, Orig_Type);
1372 Set_Etype (Act2, Orig_Type);
1381 Error := No (Orig_Type);
1384 elsif Ekind (Opnd_Type) = E_Allocator_Type
1385 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1389 -- If the type is defined elsewhere, and the operator is not
1390 -- defined in the given scope (by a renaming declaration, e.g.)
1391 -- then this is an error as well. If an extension of System is
1392 -- present, and the type may be defined there, Pack must be
1395 elsif Scope (Opnd_Type) /= Pack
1396 and then Scope (Op_Id) /= Pack
1397 and then (No (System_Aux_Id)
1398 or else Scope (Opnd_Type) /= System_Aux_Id
1399 or else Pack /= Scope (System_Aux_Id))
1401 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1404 Error := not Operand_Type_In_Scope (Pack);
1407 elsif Pack = Standard_Standard
1408 and then not Operand_Type_In_Scope (Standard_Standard)
1415 Error_Msg_Node_2 := Pack;
1417 ("& not declared in&", N, Selector_Name (Name (N)));
1418 Set_Etype (N, Any_Type);
1423 Set_Chars (Op_Node, Op_Name);
1425 if not Is_Private_Type (Etype (N)) then
1426 Set_Etype (Op_Node, Base_Type (Etype (N)));
1428 Set_Etype (Op_Node, Etype (N));
1431 -- If this is a call to a function that renames a predefined equality,
1432 -- the renaming declaration provides a type that must be used to
1433 -- resolve the operands. This must be done now because resolution of
1434 -- the equality node will not resolve any remaining ambiguity, and it
1435 -- assumes that the first operand is not overloaded.
1437 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1438 and then Ekind (Func) = E_Function
1439 and then Is_Overloaded (Act1)
1441 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1442 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1445 Set_Entity (Op_Node, Op_Id);
1446 Generate_Reference (Op_Id, N, ' ');
1448 -- Do rewrite setting Comes_From_Source on the result if the original
1449 -- call came from source. Although it is not strictly the case that the
1450 -- operator as such comes from the source, logically it corresponds
1451 -- exactly to the function call in the source, so it should be marked
1452 -- this way (e.g. to make sure that validity checks work fine).
1455 CS : constant Boolean := Comes_From_Source (N);
1457 Rewrite (N, Op_Node);
1458 Set_Comes_From_Source (N, CS);
1461 -- If this is an arithmetic operator and the result type is private,
1462 -- the operands and the result must be wrapped in conversion to
1463 -- expose the underlying numeric type and expand the proper checks,
1464 -- e.g. on division.
1466 if Is_Private_Type (Typ) then
1468 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1469 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1470 Resolve_Intrinsic_Operator (N, Typ);
1472 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1473 Resolve_Intrinsic_Unary_Operator (N, Typ);
1482 -- For predefined operators on literals, the operation freezes
1485 if Present (Orig_Type) then
1486 Set_Etype (Act1, Orig_Type);
1487 Freeze_Expression (Act1);
1489 end Make_Call_Into_Operator;
1495 function Operator_Kind
1497 Is_Binary : Boolean) return Node_Kind
1503 if Op_Name = Name_Op_And then
1505 elsif Op_Name = Name_Op_Or then
1507 elsif Op_Name = Name_Op_Xor then
1509 elsif Op_Name = Name_Op_Eq then
1511 elsif Op_Name = Name_Op_Ne then
1513 elsif Op_Name = Name_Op_Lt then
1515 elsif Op_Name = Name_Op_Le then
1517 elsif Op_Name = Name_Op_Gt then
1519 elsif Op_Name = Name_Op_Ge then
1521 elsif Op_Name = Name_Op_Add then
1523 elsif Op_Name = Name_Op_Subtract then
1524 Kind := N_Op_Subtract;
1525 elsif Op_Name = Name_Op_Concat then
1526 Kind := N_Op_Concat;
1527 elsif Op_Name = Name_Op_Multiply then
1528 Kind := N_Op_Multiply;
1529 elsif Op_Name = Name_Op_Divide then
1530 Kind := N_Op_Divide;
1531 elsif Op_Name = Name_Op_Mod then
1533 elsif Op_Name = Name_Op_Rem then
1535 elsif Op_Name = Name_Op_Expon then
1538 raise Program_Error;
1544 if Op_Name = Name_Op_Add then
1546 elsif Op_Name = Name_Op_Subtract then
1548 elsif Op_Name = Name_Op_Abs then
1550 elsif Op_Name = Name_Op_Not then
1553 raise Program_Error;
1560 ----------------------------
1561 -- Preanalyze_And_Resolve --
1562 ----------------------------
1564 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1565 Save_Full_Analysis : constant Boolean := Full_Analysis;
1568 Full_Analysis := False;
1569 Expander_Mode_Save_And_Set (False);
1571 -- We suppress all checks for this analysis, since the checks will
1572 -- be applied properly, and in the right location, when the default
1573 -- expression is reanalyzed and reexpanded later on.
1575 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1577 Expander_Mode_Restore;
1578 Full_Analysis := Save_Full_Analysis;
1579 end Preanalyze_And_Resolve;
1581 -- Version without context type
1583 procedure Preanalyze_And_Resolve (N : Node_Id) is
1584 Save_Full_Analysis : constant Boolean := Full_Analysis;
1587 Full_Analysis := False;
1588 Expander_Mode_Save_And_Set (False);
1591 Resolve (N, Etype (N), Suppress => All_Checks);
1593 Expander_Mode_Restore;
1594 Full_Analysis := Save_Full_Analysis;
1595 end Preanalyze_And_Resolve;
1597 ----------------------------------
1598 -- Replace_Actual_Discriminants --
1599 ----------------------------------
1601 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1602 Loc : constant Source_Ptr := Sloc (N);
1603 Tsk : Node_Id := Empty;
1605 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1611 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1615 if Nkind (Nod) = N_Identifier then
1616 Ent := Entity (Nod);
1619 and then Ekind (Ent) = E_Discriminant
1622 Make_Selected_Component (Loc,
1623 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1624 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1626 Set_Etype (Nod, Etype (Ent));
1634 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1636 -- Start of processing for Replace_Actual_Discriminants
1639 if not Expander_Active then
1643 if Nkind (Name (N)) = N_Selected_Component then
1644 Tsk := Prefix (Name (N));
1646 elsif Nkind (Name (N)) = N_Indexed_Component then
1647 Tsk := Prefix (Prefix (Name (N)));
1653 Replace_Discrs (Default);
1655 end Replace_Actual_Discriminants;
1661 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1662 Ambiguous : Boolean := False;
1663 Ctx_Type : Entity_Id := Typ;
1664 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1665 Err_Type : Entity_Id := Empty;
1666 Found : Boolean := False;
1669 I1 : Interp_Index := 0; -- prevent junk warning
1672 Seen : Entity_Id := Empty; -- prevent junk warning
1674 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1675 -- Determine whether a node comes from a predefined library unit or
1678 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1679 -- Try and fix up a literal so that it matches its expected type. New
1680 -- literals are manufactured if necessary to avoid cascaded errors.
1682 procedure Resolution_Failed;
1683 -- Called when attempt at resolving current expression fails
1685 ------------------------------------
1686 -- Comes_From_Predefined_Lib_Unit --
1687 -------------------------------------
1689 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1692 Sloc (Nod) = Standard_Location
1693 or else Is_Predefined_File_Name (Unit_File_Name (
1694 Get_Source_Unit (Sloc (Nod))));
1695 end Comes_From_Predefined_Lib_Unit;
1697 --------------------
1698 -- Patch_Up_Value --
1699 --------------------
1701 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1703 if Nkind (N) = N_Integer_Literal
1704 and then Is_Real_Type (Typ)
1707 Make_Real_Literal (Sloc (N),
1708 Realval => UR_From_Uint (Intval (N))));
1709 Set_Etype (N, Universal_Real);
1710 Set_Is_Static_Expression (N);
1712 elsif Nkind (N) = N_Real_Literal
1713 and then Is_Integer_Type (Typ)
1716 Make_Integer_Literal (Sloc (N),
1717 Intval => UR_To_Uint (Realval (N))));
1718 Set_Etype (N, Universal_Integer);
1719 Set_Is_Static_Expression (N);
1721 elsif Nkind (N) = N_String_Literal
1722 and then Is_Character_Type (Typ)
1724 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1726 Make_Character_Literal (Sloc (N),
1728 Char_Literal_Value =>
1729 UI_From_Int (Character'Pos ('A'))));
1730 Set_Etype (N, Any_Character);
1731 Set_Is_Static_Expression (N);
1733 elsif Nkind (N) /= N_String_Literal
1734 and then Is_String_Type (Typ)
1737 Make_String_Literal (Sloc (N),
1738 Strval => End_String));
1740 elsif Nkind (N) = N_Range then
1741 Patch_Up_Value (Low_Bound (N), Typ);
1742 Patch_Up_Value (High_Bound (N), Typ);
1746 -----------------------
1747 -- Resolution_Failed --
1748 -----------------------
1750 procedure Resolution_Failed is
1752 Patch_Up_Value (N, Typ);
1754 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1755 Set_Is_Overloaded (N, False);
1757 -- The caller will return without calling the expander, so we need
1758 -- to set the analyzed flag. Note that it is fine to set Analyzed
1759 -- to True even if we are in the middle of a shallow analysis,
1760 -- (see the spec of sem for more details) since this is an error
1761 -- situation anyway, and there is no point in repeating the
1762 -- analysis later (indeed it won't work to repeat it later, since
1763 -- we haven't got a clear resolution of which entity is being
1766 Set_Analyzed (N, True);
1768 end Resolution_Failed;
1770 -- Start of processing for Resolve
1777 -- Access attribute on remote subprogram cannot be used for
1778 -- a non-remote access-to-subprogram type.
1780 if Nkind (N) = N_Attribute_Reference
1781 and then (Attribute_Name (N) = Name_Access
1782 or else Attribute_Name (N) = Name_Unrestricted_Access
1783 or else Attribute_Name (N) = Name_Unchecked_Access)
1784 and then Comes_From_Source (N)
1785 and then Is_Entity_Name (Prefix (N))
1786 and then Is_Subprogram (Entity (Prefix (N)))
1787 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1788 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1791 ("prefix must statically denote a non-remote subprogram", N);
1794 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1796 -- If the context is a Remote_Access_To_Subprogram, access attributes
1797 -- must be resolved with the corresponding fat pointer. There is no need
1798 -- to check for the attribute name since the return type of an
1799 -- attribute is never a remote type.
1801 if Nkind (N) = N_Attribute_Reference
1802 and then Comes_From_Source (N)
1803 and then (Is_Remote_Call_Interface (Typ)
1804 or else Is_Remote_Types (Typ))
1807 Attr : constant Attribute_Id :=
1808 Get_Attribute_Id (Attribute_Name (N));
1809 Pref : constant Node_Id := Prefix (N);
1812 Is_Remote : Boolean := True;
1815 -- Check that Typ is a remote access-to-subprogram type
1817 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1818 -- Prefix (N) must statically denote a remote subprogram
1819 -- declared in a package specification.
1821 if Attr = Attribute_Access then
1822 Decl := Unit_Declaration_Node (Entity (Pref));
1824 if Nkind (Decl) = N_Subprogram_Body then
1825 Spec := Corresponding_Spec (Decl);
1827 if not No (Spec) then
1828 Decl := Unit_Declaration_Node (Spec);
1832 Spec := Parent (Decl);
1834 if not Is_Entity_Name (Prefix (N))
1835 or else Nkind (Spec) /= N_Package_Specification
1837 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1841 ("prefix must statically denote a remote subprogram ",
1846 -- If we are generating code for a distributed program.
1847 -- perform semantic checks against the corresponding
1850 if (Attr = Attribute_Access
1851 or else Attr = Attribute_Unchecked_Access
1852 or else Attr = Attribute_Unrestricted_Access)
1853 and then Expander_Active
1854 and then Get_PCS_Name /= Name_No_DSA
1856 Check_Subtype_Conformant
1857 (New_Id => Entity (Prefix (N)),
1858 Old_Id => Designated_Type
1859 (Corresponding_Remote_Type (Typ)),
1863 Process_Remote_AST_Attribute (N, Typ);
1870 Debug_A_Entry ("resolving ", N);
1872 if Comes_From_Source (N) then
1873 if Is_Fixed_Point_Type (Typ) then
1874 Check_Restriction (No_Fixed_Point, N);
1876 elsif Is_Floating_Point_Type (Typ)
1877 and then Typ /= Universal_Real
1878 and then Typ /= Any_Real
1880 Check_Restriction (No_Floating_Point, N);
1884 -- Return if already analyzed
1886 if Analyzed (N) then
1887 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1890 -- Return if type = Any_Type (previous error encountered)
1892 elsif Etype (N) = Any_Type then
1893 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1897 Check_Parameterless_Call (N);
1899 -- If not overloaded, then we know the type, and all that needs doing
1900 -- is to check that this type is compatible with the context.
1902 if not Is_Overloaded (N) then
1903 Found := Covers (Typ, Etype (N));
1904 Expr_Type := Etype (N);
1906 -- In the overloaded case, we must select the interpretation that
1907 -- is compatible with the context (i.e. the type passed to Resolve)
1910 -- Loop through possible interpretations
1912 Get_First_Interp (N, I, It);
1913 Interp_Loop : while Present (It.Typ) loop
1915 -- We are only interested in interpretations that are compatible
1916 -- with the expected type, any other interpretations are ignored.
1918 if not Covers (Typ, It.Typ) then
1919 if Debug_Flag_V then
1920 Write_Str (" interpretation incompatible with context");
1925 -- Skip the current interpretation if it is disabled by an
1926 -- abstract operator. This action is performed only when the
1927 -- type against which we are resolving is the same as the
1928 -- type of the interpretation.
1930 if Ada_Version >= Ada_05
1931 and then It.Typ = Typ
1932 and then Typ /= Universal_Integer
1933 and then Typ /= Universal_Real
1934 and then Present (It.Abstract_Op)
1939 -- First matching interpretation
1945 Expr_Type := It.Typ;
1947 -- Matching interpretation that is not the first, maybe an
1948 -- error, but there are some cases where preference rules are
1949 -- used to choose between the two possibilities. These and
1950 -- some more obscure cases are handled in Disambiguate.
1953 -- If the current statement is part of a predefined library
1954 -- unit, then all interpretations which come from user level
1955 -- packages should not be considered.
1958 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
1963 Error_Msg_Sloc := Sloc (Seen);
1964 It1 := Disambiguate (N, I1, I, Typ);
1966 -- Disambiguation has succeeded. Skip the remaining
1969 if It1 /= No_Interp then
1971 Expr_Type := It1.Typ;
1973 while Present (It.Typ) loop
1974 Get_Next_Interp (I, It);
1978 -- Before we issue an ambiguity complaint, check for
1979 -- the case of a subprogram call where at least one
1980 -- of the arguments is Any_Type, and if so, suppress
1981 -- the message, since it is a cascaded error.
1983 if Nkind_In (N, N_Function_Call,
1984 N_Procedure_Call_Statement)
1991 A := First_Actual (N);
1992 while Present (A) loop
1995 if Nkind (E) = N_Parameter_Association then
1996 E := Explicit_Actual_Parameter (E);
1999 if Etype (E) = Any_Type then
2000 if Debug_Flag_V then
2001 Write_Str ("Any_Type in call");
2012 elsif Nkind (N) in N_Binary_Op
2013 and then (Etype (Left_Opnd (N)) = Any_Type
2014 or else Etype (Right_Opnd (N)) = Any_Type)
2018 elsif Nkind (N) in N_Unary_Op
2019 and then Etype (Right_Opnd (N)) = Any_Type
2024 -- Not that special case, so issue message using the
2025 -- flag Ambiguous to control printing of the header
2026 -- message only at the start of an ambiguous set.
2028 if not Ambiguous then
2029 if Nkind (N) = N_Function_Call
2030 and then Nkind (Name (N)) = N_Explicit_Dereference
2033 ("ambiguous expression "
2034 & "(cannot resolve indirect call)!", N);
2036 Error_Msg_NE -- CODEFIX
2037 ("ambiguous expression (cannot resolve&)!",
2043 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2045 ("\\possible interpretation (inherited)#!", N);
2047 Error_Msg_N -- CODEFIX
2048 ("\\possible interpretation#!", N);
2052 Error_Msg_Sloc := Sloc (It.Nam);
2054 -- By default, the error message refers to the candidate
2055 -- interpretation. But if it is a predefined operator, it
2056 -- is implicitly declared at the declaration of the type
2057 -- of the operand. Recover the sloc of that declaration
2058 -- for the error message.
2060 if Nkind (N) in N_Op
2061 and then Scope (It.Nam) = Standard_Standard
2062 and then not Is_Overloaded (Right_Opnd (N))
2063 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2066 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2068 if Comes_From_Source (Err_Type)
2069 and then Present (Parent (Err_Type))
2071 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2074 elsif Nkind (N) in N_Binary_Op
2075 and then Scope (It.Nam) = Standard_Standard
2076 and then not Is_Overloaded (Left_Opnd (N))
2077 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2080 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2082 if Comes_From_Source (Err_Type)
2083 and then Present (Parent (Err_Type))
2085 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2088 -- If this is an indirect call, use the subprogram_type
2089 -- in the message, to have a meaningful location.
2090 -- Indicate as well if this is an inherited operation,
2091 -- created by a type declaration.
2093 elsif Nkind (N) = N_Function_Call
2094 and then Nkind (Name (N)) = N_Explicit_Dereference
2095 and then Is_Type (It.Nam)
2099 Sloc (Associated_Node_For_Itype (Err_Type));
2104 if Nkind (N) in N_Op
2105 and then Scope (It.Nam) = Standard_Standard
2106 and then Present (Err_Type)
2108 -- Special-case the message for universal_fixed
2109 -- operators, which are not declared with the type
2110 -- of the operand, but appear forever in Standard.
2112 if It.Typ = Universal_Fixed
2113 and then Scope (It.Nam) = Standard_Standard
2116 ("\\possible interpretation as " &
2117 "universal_fixed operation " &
2118 "(RM 4.5.5 (19))", N);
2121 ("\\possible interpretation (predefined)#!", N);
2125 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2128 ("\\possible interpretation (inherited)#!", N);
2130 Error_Msg_N -- CODEFIX
2131 ("\\possible interpretation#!", N);
2137 -- We have a matching interpretation, Expr_Type is the type
2138 -- from this interpretation, and Seen is the entity.
2140 -- For an operator, just set the entity name. The type will be
2141 -- set by the specific operator resolution routine.
2143 if Nkind (N) in N_Op then
2144 Set_Entity (N, Seen);
2145 Generate_Reference (Seen, N);
2147 elsif Nkind (N) = N_Character_Literal then
2148 Set_Etype (N, Expr_Type);
2150 elsif Nkind (N) = N_Conditional_Expression then
2151 Set_Etype (N, Expr_Type);
2153 -- For an explicit dereference, attribute reference, range,
2154 -- short-circuit form (which is not an operator node), or call
2155 -- with a name that is an explicit dereference, there is
2156 -- nothing to be done at this point.
2158 elsif Nkind_In (N, N_Explicit_Dereference,
2159 N_Attribute_Reference,
2161 N_Indexed_Component,
2164 N_Selected_Component,
2166 or else Nkind (Name (N)) = N_Explicit_Dereference
2170 -- For procedure or function calls, set the type of the name,
2171 -- and also the entity pointer for the prefix
2173 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2174 and then (Is_Entity_Name (Name (N))
2175 or else Nkind (Name (N)) = N_Operator_Symbol)
2177 Set_Etype (Name (N), Expr_Type);
2178 Set_Entity (Name (N), Seen);
2179 Generate_Reference (Seen, Name (N));
2181 elsif Nkind (N) = N_Function_Call
2182 and then Nkind (Name (N)) = N_Selected_Component
2184 Set_Etype (Name (N), Expr_Type);
2185 Set_Entity (Selector_Name (Name (N)), Seen);
2186 Generate_Reference (Seen, Selector_Name (Name (N)));
2188 -- For all other cases, just set the type of the Name
2191 Set_Etype (Name (N), Expr_Type);
2198 -- Move to next interpretation
2200 exit Interp_Loop when No (It.Typ);
2202 Get_Next_Interp (I, It);
2203 end loop Interp_Loop;
2206 -- At this stage Found indicates whether or not an acceptable
2207 -- interpretation exists. If not, then we have an error, except
2208 -- that if the context is Any_Type as a result of some other error,
2209 -- then we suppress the error report.
2212 if Typ /= Any_Type then
2214 -- If type we are looking for is Void, then this is the procedure
2215 -- call case, and the error is simply that what we gave is not a
2216 -- procedure name (we think of procedure calls as expressions with
2217 -- types internally, but the user doesn't think of them this way!)
2219 if Typ = Standard_Void_Type then
2221 -- Special case message if function used as a procedure
2223 if Nkind (N) = N_Procedure_Call_Statement
2224 and then Is_Entity_Name (Name (N))
2225 and then Ekind (Entity (Name (N))) = E_Function
2228 ("cannot use function & in a procedure call",
2229 Name (N), Entity (Name (N)));
2231 -- Otherwise give general message (not clear what cases this
2232 -- covers, but no harm in providing for them!)
2235 Error_Msg_N ("expect procedure name in procedure call", N);
2240 -- Otherwise we do have a subexpression with the wrong type
2242 -- Check for the case of an allocator which uses an access type
2243 -- instead of the designated type. This is a common error and we
2244 -- specialize the message, posting an error on the operand of the
2245 -- allocator, complaining that we expected the designated type of
2248 elsif Nkind (N) = N_Allocator
2249 and then Ekind (Typ) in Access_Kind
2250 and then Ekind (Etype (N)) in Access_Kind
2251 and then Designated_Type (Etype (N)) = Typ
2253 Wrong_Type (Expression (N), Designated_Type (Typ));
2256 -- Check for view mismatch on Null in instances, for which the
2257 -- view-swapping mechanism has no identifier.
2259 elsif (In_Instance or else In_Inlined_Body)
2260 and then (Nkind (N) = N_Null)
2261 and then Is_Private_Type (Typ)
2262 and then Is_Access_Type (Full_View (Typ))
2264 Resolve (N, Full_View (Typ));
2268 -- Check for an aggregate. Sometimes we can get bogus aggregates
2269 -- from misuse of parentheses, and we are about to complain about
2270 -- the aggregate without even looking inside it.
2272 -- Instead, if we have an aggregate of type Any_Composite, then
2273 -- analyze and resolve the component fields, and then only issue
2274 -- another message if we get no errors doing this (otherwise
2275 -- assume that the errors in the aggregate caused the problem).
2277 elsif Nkind (N) = N_Aggregate
2278 and then Etype (N) = Any_Composite
2280 -- Disable expansion in any case. If there is a type mismatch
2281 -- it may be fatal to try to expand the aggregate. The flag
2282 -- would otherwise be set to false when the error is posted.
2284 Expander_Active := False;
2287 procedure Check_Aggr (Aggr : Node_Id);
2288 -- Check one aggregate, and set Found to True if we have a
2289 -- definite error in any of its elements
2291 procedure Check_Elmt (Aelmt : Node_Id);
2292 -- Check one element of aggregate and set Found to True if
2293 -- we definitely have an error in the element.
2299 procedure Check_Aggr (Aggr : Node_Id) is
2303 if Present (Expressions (Aggr)) then
2304 Elmt := First (Expressions (Aggr));
2305 while Present (Elmt) loop
2311 if Present (Component_Associations (Aggr)) then
2312 Elmt := First (Component_Associations (Aggr));
2313 while Present (Elmt) loop
2315 -- If this is a default-initialized component, then
2316 -- there is nothing to check. The box will be
2317 -- replaced by the appropriate call during late
2320 if not Box_Present (Elmt) then
2321 Check_Elmt (Expression (Elmt));
2333 procedure Check_Elmt (Aelmt : Node_Id) is
2335 -- If we have a nested aggregate, go inside it (to
2336 -- attempt a naked analyze-resolve of the aggregate
2337 -- can cause undesirable cascaded errors). Do not
2338 -- resolve expression if it needs a type from context,
2339 -- as for integer * fixed expression.
2341 if Nkind (Aelmt) = N_Aggregate then
2347 if not Is_Overloaded (Aelmt)
2348 and then Etype (Aelmt) /= Any_Fixed
2353 if Etype (Aelmt) = Any_Type then
2364 -- If an error message was issued already, Found got reset
2365 -- to True, so if it is still False, issue the standard
2366 -- Wrong_Type message.
2369 if Is_Overloaded (N)
2370 and then Nkind (N) = N_Function_Call
2373 Subp_Name : Node_Id;
2375 if Is_Entity_Name (Name (N)) then
2376 Subp_Name := Name (N);
2378 elsif Nkind (Name (N)) = N_Selected_Component then
2380 -- Protected operation: retrieve operation name
2382 Subp_Name := Selector_Name (Name (N));
2384 raise Program_Error;
2387 Error_Msg_Node_2 := Typ;
2388 Error_Msg_NE ("no visible interpretation of&" &
2389 " matches expected type&", N, Subp_Name);
2392 if All_Errors_Mode then
2394 Index : Interp_Index;
2398 Error_Msg_N ("\\possible interpretations:", N);
2400 Get_First_Interp (Name (N), Index, It);
2401 while Present (It.Nam) loop
2402 Error_Msg_Sloc := Sloc (It.Nam);
2403 Error_Msg_Node_2 := It.Nam;
2405 ("\\ type& for & declared#", N, It.Typ);
2406 Get_Next_Interp (Index, It);
2411 Error_Msg_N ("\use -gnatf for details", N);
2414 Wrong_Type (N, Typ);
2422 -- Test if we have more than one interpretation for the context
2424 elsif Ambiguous then
2428 -- Here we have an acceptable interpretation for the context
2431 -- Propagate type information and normalize tree for various
2432 -- predefined operations. If the context only imposes a class of
2433 -- types, rather than a specific type, propagate the actual type
2436 if Typ = Any_Integer
2437 or else Typ = Any_Boolean
2438 or else Typ = Any_Modular
2439 or else Typ = Any_Real
2440 or else Typ = Any_Discrete
2442 Ctx_Type := Expr_Type;
2444 -- Any_Fixed is legal in a real context only if a specific
2445 -- fixed point type is imposed. If Norman Cohen can be
2446 -- confused by this, it deserves a separate message.
2449 and then Expr_Type = Any_Fixed
2451 Error_Msg_N ("illegal context for mixed mode operation", N);
2452 Set_Etype (N, Universal_Real);
2453 Ctx_Type := Universal_Real;
2457 -- A user-defined operator is transformed into a function call at
2458 -- this point, so that further processing knows that operators are
2459 -- really operators (i.e. are predefined operators). User-defined
2460 -- operators that are intrinsic are just renamings of the predefined
2461 -- ones, and need not be turned into calls either, but if they rename
2462 -- a different operator, we must transform the node accordingly.
2463 -- Instantiations of Unchecked_Conversion are intrinsic but are
2464 -- treated as functions, even if given an operator designator.
2466 if Nkind (N) in N_Op
2467 and then Present (Entity (N))
2468 and then Ekind (Entity (N)) /= E_Operator
2471 if not Is_Predefined_Op (Entity (N)) then
2472 Rewrite_Operator_As_Call (N, Entity (N));
2474 elsif Present (Alias (Entity (N)))
2476 Nkind (Parent (Parent (Entity (N)))) =
2477 N_Subprogram_Renaming_Declaration
2479 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2481 -- If the node is rewritten, it will be fully resolved in
2482 -- Rewrite_Renamed_Operator.
2484 if Analyzed (N) then
2490 case N_Subexpr'(Nkind (N)) is
2492 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2494 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2496 when N_Short_Circuit
2497 => Resolve_Short_Circuit (N, Ctx_Type);
2499 when N_Attribute_Reference
2500 => Resolve_Attribute (N, Ctx_Type);
2502 when N_Character_Literal
2503 => Resolve_Character_Literal (N, Ctx_Type);
2505 when N_Conditional_Expression
2506 => Resolve_Conditional_Expression (N, Ctx_Type);
2508 when N_Expanded_Name
2509 => Resolve_Entity_Name (N, Ctx_Type);
2511 when N_Extension_Aggregate
2512 => Resolve_Extension_Aggregate (N, Ctx_Type);
2514 when N_Explicit_Dereference
2515 => Resolve_Explicit_Dereference (N, Ctx_Type);
2517 when N_Function_Call
2518 => Resolve_Call (N, Ctx_Type);
2521 => Resolve_Entity_Name (N, Ctx_Type);
2523 when N_Indexed_Component
2524 => Resolve_Indexed_Component (N, Ctx_Type);
2526 when N_Integer_Literal
2527 => Resolve_Integer_Literal (N, Ctx_Type);
2529 when N_Membership_Test
2530 => Resolve_Membership_Op (N, Ctx_Type);
2532 when N_Null => Resolve_Null (N, Ctx_Type);
2534 when N_Op_And | N_Op_Or | N_Op_Xor
2535 => Resolve_Logical_Op (N, Ctx_Type);
2537 when N_Op_Eq | N_Op_Ne
2538 => Resolve_Equality_Op (N, Ctx_Type);
2540 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2541 => Resolve_Comparison_Op (N, Ctx_Type);
2543 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2545 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2546 N_Op_Divide | N_Op_Mod | N_Op_Rem
2548 => Resolve_Arithmetic_Op (N, Ctx_Type);
2550 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2552 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2554 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2555 => Resolve_Unary_Op (N, Ctx_Type);
2557 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2559 when N_Procedure_Call_Statement
2560 => Resolve_Call (N, Ctx_Type);
2562 when N_Operator_Symbol
2563 => Resolve_Operator_Symbol (N, Ctx_Type);
2565 when N_Qualified_Expression
2566 => Resolve_Qualified_Expression (N, Ctx_Type);
2568 when N_Raise_xxx_Error
2569 => Set_Etype (N, Ctx_Type);
2571 when N_Range => Resolve_Range (N, Ctx_Type);
2574 => Resolve_Real_Literal (N, Ctx_Type);
2576 when N_Reference => Resolve_Reference (N, Ctx_Type);
2578 when N_Selected_Component
2579 => Resolve_Selected_Component (N, Ctx_Type);
2581 when N_Slice => Resolve_Slice (N, Ctx_Type);
2583 when N_String_Literal
2584 => Resolve_String_Literal (N, Ctx_Type);
2586 when N_Subprogram_Info
2587 => Resolve_Subprogram_Info (N, Ctx_Type);
2589 when N_Type_Conversion
2590 => Resolve_Type_Conversion (N, Ctx_Type);
2592 when N_Unchecked_Expression =>
2593 Resolve_Unchecked_Expression (N, Ctx_Type);
2595 when N_Unchecked_Type_Conversion =>
2596 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2600 -- If the subexpression was replaced by a non-subexpression, then
2601 -- all we do is to expand it. The only legitimate case we know of
2602 -- is converting procedure call statement to entry call statements,
2603 -- but there may be others, so we are making this test general.
2605 if Nkind (N) not in N_Subexpr then
2606 Debug_A_Exit ("resolving ", N, " (done)");
2611 -- The expression is definitely NOT overloaded at this point, so
2612 -- we reset the Is_Overloaded flag to avoid any confusion when
2613 -- reanalyzing the node.
2615 Set_Is_Overloaded (N, False);
2617 -- Freeze expression type, entity if it is a name, and designated
2618 -- type if it is an allocator (RM 13.14(10,11,13)).
2620 -- Now that the resolution of the type of the node is complete,
2621 -- and we did not detect an error, we can expand this node. We
2622 -- skip the expand call if we are in a default expression, see
2623 -- section "Handling of Default Expressions" in Sem spec.
2625 Debug_A_Exit ("resolving ", N, " (done)");
2627 -- We unconditionally freeze the expression, even if we are in
2628 -- default expression mode (the Freeze_Expression routine tests
2629 -- this flag and only freezes static types if it is set).
2631 Freeze_Expression (N);
2633 -- Now we can do the expansion
2643 -- Version with check(s) suppressed
2645 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2647 if Suppress = All_Checks then
2649 Svg : constant Suppress_Array := Scope_Suppress;
2651 Scope_Suppress := (others => True);
2653 Scope_Suppress := Svg;
2658 Svg : constant Boolean := Scope_Suppress (Suppress);
2660 Scope_Suppress (Suppress) := True;
2662 Scope_Suppress (Suppress) := Svg;
2671 -- Version with implicit type
2673 procedure Resolve (N : Node_Id) is
2675 Resolve (N, Etype (N));
2678 ---------------------
2679 -- Resolve_Actuals --
2680 ---------------------
2682 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2683 Loc : constant Source_Ptr := Sloc (N);
2688 Prev : Node_Id := Empty;
2691 procedure Check_Argument_Order;
2692 -- Performs a check for the case where the actuals are all simple
2693 -- identifiers that correspond to the formal names, but in the wrong
2694 -- order, which is considered suspicious and cause for a warning.
2696 procedure Check_Prefixed_Call;
2697 -- If the original node is an overloaded call in prefix notation,
2698 -- insert an 'Access or a dereference as needed over the first actual.
2699 -- Try_Object_Operation has already verified that there is a valid
2700 -- interpretation, but the form of the actual can only be determined
2701 -- once the primitive operation is identified.
2703 procedure Insert_Default;
2704 -- If the actual is missing in a call, insert in the actuals list
2705 -- an instance of the default expression. The insertion is always
2706 -- a named association.
2708 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2709 -- Check whether T1 and T2, or their full views, are derived from a
2710 -- common type. Used to enforce the restrictions on array conversions
2713 function Static_Concatenation (N : Node_Id) return Boolean;
2714 -- Predicate to determine whether an actual that is a concatenation
2715 -- will be evaluated statically and does not need a transient scope.
2716 -- This must be determined before the actual is resolved and expanded
2717 -- because if needed the transient scope must be introduced earlier.
2719 --------------------------
2720 -- Check_Argument_Order --
2721 --------------------------
2723 procedure Check_Argument_Order is
2725 -- Nothing to do if no parameters, or original node is neither a
2726 -- function call nor a procedure call statement (happens in the
2727 -- operator-transformed-to-function call case), or the call does
2728 -- not come from source, or this warning is off.
2730 if not Warn_On_Parameter_Order
2732 No (Parameter_Associations (N))
2734 not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2737 not Comes_From_Source (N)
2743 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2746 -- Nothing to do if only one parameter
2752 -- Here if at least two arguments
2755 Actuals : array (1 .. Nargs) of Node_Id;
2759 Wrong_Order : Boolean := False;
2760 -- Set True if an out of order case is found
2763 -- Collect identifier names of actuals, fail if any actual is
2764 -- not a simple identifier, and record max length of name.
2766 Actual := First (Parameter_Associations (N));
2767 for J in Actuals'Range loop
2768 if Nkind (Actual) /= N_Identifier then
2771 Actuals (J) := Actual;
2776 -- If we got this far, all actuals are identifiers and the list
2777 -- of their names is stored in the Actuals array.
2779 Formal := First_Formal (Nam);
2780 for J in Actuals'Range loop
2782 -- If we ran out of formals, that's odd, probably an error
2783 -- which will be detected elsewhere, but abandon the search.
2789 -- If name matches and is in order OK
2791 if Chars (Formal) = Chars (Actuals (J)) then
2795 -- If no match, see if it is elsewhere in list and if so
2796 -- flag potential wrong order if type is compatible.
2798 for K in Actuals'Range loop
2799 if Chars (Formal) = Chars (Actuals (K))
2801 Has_Compatible_Type (Actuals (K), Etype (Formal))
2803 Wrong_Order := True;
2813 <<Continue>> Next_Formal (Formal);
2816 -- If Formals left over, also probably an error, skip warning
2818 if Present (Formal) then
2822 -- Here we give the warning if something was out of order
2826 ("actuals for this call may be in wrong order?", N);
2830 end Check_Argument_Order;
2832 -------------------------
2833 -- Check_Prefixed_Call --
2834 -------------------------
2836 procedure Check_Prefixed_Call is
2837 Act : constant Node_Id := First_Actual (N);
2838 A_Type : constant Entity_Id := Etype (Act);
2839 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
2840 Orig : constant Node_Id := Original_Node (N);
2844 -- Check whether the call is a prefixed call, with or without
2845 -- additional actuals.
2847 if Nkind (Orig) = N_Selected_Component
2849 (Nkind (Orig) = N_Indexed_Component
2850 and then Nkind (Prefix (Orig)) = N_Selected_Component
2851 and then Is_Entity_Name (Prefix (Prefix (Orig)))
2852 and then Is_Entity_Name (Act)
2853 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
2855 if Is_Access_Type (A_Type)
2856 and then not Is_Access_Type (F_Type)
2858 -- Introduce dereference on object in prefix
2861 Make_Explicit_Dereference (Sloc (Act),
2862 Prefix => Relocate_Node (Act));
2863 Rewrite (Act, New_A);
2866 elsif Is_Access_Type (F_Type)
2867 and then not Is_Access_Type (A_Type)
2869 -- Introduce an implicit 'Access in prefix
2871 if not Is_Aliased_View (Act) then
2873 ("object in prefixed call to& must be aliased"
2874 & " (RM-2005 4.3.1 (13))",
2879 Make_Attribute_Reference (Loc,
2880 Attribute_Name => Name_Access,
2881 Prefix => Relocate_Node (Act)));
2886 end Check_Prefixed_Call;
2888 --------------------
2889 -- Insert_Default --
2890 --------------------
2892 procedure Insert_Default is
2897 -- Missing argument in call, nothing to insert
2899 if No (Default_Value (F)) then
2903 -- Note that we do a full New_Copy_Tree, so that any associated
2904 -- Itypes are properly copied. This may not be needed any more,
2905 -- but it does no harm as a safety measure! Defaults of a generic
2906 -- formal may be out of bounds of the corresponding actual (see
2907 -- cc1311b) and an additional check may be required.
2912 New_Scope => Current_Scope,
2915 if Is_Concurrent_Type (Scope (Nam))
2916 and then Has_Discriminants (Scope (Nam))
2918 Replace_Actual_Discriminants (N, Actval);
2921 if Is_Overloadable (Nam)
2922 and then Present (Alias (Nam))
2924 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2925 and then not Is_Tagged_Type (Etype (F))
2927 -- If default is a real literal, do not introduce a
2928 -- conversion whose effect may depend on the run-time
2929 -- size of universal real.
2931 if Nkind (Actval) = N_Real_Literal then
2932 Set_Etype (Actval, Base_Type (Etype (F)));
2934 Actval := Unchecked_Convert_To (Etype (F), Actval);
2938 if Is_Scalar_Type (Etype (F)) then
2939 Enable_Range_Check (Actval);
2942 Set_Parent (Actval, N);
2944 -- Resolve aggregates with their base type, to avoid scope
2945 -- anomalies: the subtype was first built in the subprogram
2946 -- declaration, and the current call may be nested.
2948 if Nkind (Actval) = N_Aggregate
2949 and then Has_Discriminants (Etype (Actval))
2951 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2953 Analyze_And_Resolve (Actval, Etype (Actval));
2957 Set_Parent (Actval, N);
2959 -- See note above concerning aggregates
2961 if Nkind (Actval) = N_Aggregate
2962 and then Has_Discriminants (Etype (Actval))
2964 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2966 -- Resolve entities with their own type, which may differ
2967 -- from the type of a reference in a generic context (the
2968 -- view swapping mechanism did not anticipate the re-analysis
2969 -- of default values in calls).
2971 elsif Is_Entity_Name (Actval) then
2972 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
2975 Analyze_And_Resolve (Actval, Etype (Actval));
2979 -- If default is a tag indeterminate function call, propagate
2980 -- tag to obtain proper dispatching.
2982 if Is_Controlling_Formal (F)
2983 and then Nkind (Default_Value (F)) = N_Function_Call
2985 Set_Is_Controlling_Actual (Actval);
2990 -- If the default expression raises constraint error, then just
2991 -- silently replace it with an N_Raise_Constraint_Error node,
2992 -- since we already gave the warning on the subprogram spec.
2994 if Raises_Constraint_Error (Actval) then
2996 Make_Raise_Constraint_Error (Loc,
2997 Reason => CE_Range_Check_Failed));
2998 Set_Raises_Constraint_Error (Actval);
2999 Set_Etype (Actval, Etype (F));
3003 Make_Parameter_Association (Loc,
3004 Explicit_Actual_Parameter => Actval,
3005 Selector_Name => Make_Identifier (Loc, Chars (F)));
3007 -- Case of insertion is first named actual
3009 if No (Prev) or else
3010 Nkind (Parent (Prev)) /= N_Parameter_Association
3012 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
3013 Set_First_Named_Actual (N, Actval);
3016 if No (Parameter_Associations (N)) then
3017 Set_Parameter_Associations (N, New_List (Assoc));
3019 Append (Assoc, Parameter_Associations (N));
3023 Insert_After (Prev, Assoc);
3026 -- Case of insertion is not first named actual
3029 Set_Next_Named_Actual
3030 (Assoc, Next_Named_Actual (Parent (Prev)));
3031 Set_Next_Named_Actual (Parent (Prev), Actval);
3032 Append (Assoc, Parameter_Associations (N));
3035 Mark_Rewrite_Insertion (Assoc);
3036 Mark_Rewrite_Insertion (Actval);
3045 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
3046 FT1 : Entity_Id := T1;
3047 FT2 : Entity_Id := T2;
3050 if Is_Private_Type (T1)
3051 and then Present (Full_View (T1))
3053 FT1 := Full_View (T1);
3056 if Is_Private_Type (T2)
3057 and then Present (Full_View (T2))
3059 FT2 := Full_View (T2);
3062 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3065 --------------------------
3066 -- Static_Concatenation --
3067 --------------------------
3069 function Static_Concatenation (N : Node_Id) return Boolean is
3072 when N_String_Literal =>
3077 -- Concatenation is static when both operands are static
3078 -- and the concatenation operator is a predefined one.
3080 return Scope (Entity (N)) = Standard_Standard
3082 Static_Concatenation (Left_Opnd (N))
3084 Static_Concatenation (Right_Opnd (N));
3087 if Is_Entity_Name (N) then
3089 Ent : constant Entity_Id := Entity (N);
3091 return Ekind (Ent) = E_Constant
3092 and then Present (Constant_Value (Ent))
3094 Is_Static_Expression (Constant_Value (Ent));
3101 end Static_Concatenation;
3103 -- Start of processing for Resolve_Actuals
3106 Check_Argument_Order;
3108 if Present (First_Actual (N)) then
3109 Check_Prefixed_Call;
3112 A := First_Actual (N);
3113 F := First_Formal (Nam);
3114 while Present (F) loop
3115 if No (A) and then Needs_No_Actuals (Nam) then
3118 -- If we have an error in any actual or formal, indicated by a type
3119 -- of Any_Type, then abandon resolution attempt, and set result type
3122 elsif (Present (A) and then Etype (A) = Any_Type)
3123 or else Etype (F) = Any_Type
3125 Set_Etype (N, Any_Type);
3129 -- Case where actual is present
3131 -- If the actual is an entity, generate a reference to it now. We
3132 -- do this before the actual is resolved, because a formal of some
3133 -- protected subprogram, or a task discriminant, will be rewritten
3134 -- during expansion, and the reference to the source entity may
3138 and then Is_Entity_Name (A)
3139 and then Comes_From_Source (N)
3141 Orig_A := Entity (A);
3143 if Present (Orig_A) then
3144 if Is_Formal (Orig_A)
3145 and then Ekind (F) /= E_In_Parameter
3147 Generate_Reference (Orig_A, A, 'm');
3148 elsif not Is_Overloaded (A) then
3149 Generate_Reference (Orig_A, A);
3155 and then (Nkind (Parent (A)) /= N_Parameter_Association
3157 Chars (Selector_Name (Parent (A))) = Chars (F))
3159 -- If style checking mode on, check match of formal name
3162 if Nkind (Parent (A)) = N_Parameter_Association then
3163 Check_Identifier (Selector_Name (Parent (A)), F);
3167 -- If the formal is Out or In_Out, do not resolve and expand the
3168 -- conversion, because it is subsequently expanded into explicit
3169 -- temporaries and assignments. However, the object of the
3170 -- conversion can be resolved. An exception is the case of tagged
3171 -- type conversion with a class-wide actual. In that case we want
3172 -- the tag check to occur and no temporary will be needed (no
3173 -- representation change can occur) and the parameter is passed by
3174 -- reference, so we go ahead and resolve the type conversion.
3175 -- Another exception is the case of reference to component or
3176 -- subcomponent of a bit-packed array, in which case we want to
3177 -- defer expansion to the point the in and out assignments are
3180 if Ekind (F) /= E_In_Parameter
3181 and then Nkind (A) = N_Type_Conversion
3182 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3184 if Ekind (F) = E_In_Out_Parameter
3185 and then Is_Array_Type (Etype (F))
3187 if Has_Aliased_Components (Etype (Expression (A)))
3188 /= Has_Aliased_Components (Etype (F))
3191 -- In a view conversion, the conversion must be legal in
3192 -- both directions, and thus both component types must be
3193 -- aliased, or neither (4.6 (8)).
3195 -- The additional rule 4.6 (24.9.2) seems unduly
3196 -- restrictive: the privacy requirement should not apply
3197 -- to generic types, and should be checked in an
3198 -- instance. ARG query is in order ???
3201 ("both component types in a view conversion must be"
3202 & " aliased, or neither", A);
3205 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3207 if Is_By_Reference_Type (Etype (F))
3208 or else Is_By_Reference_Type (Etype (Expression (A)))
3211 ("view conversion between unrelated by reference " &
3212 "array types not allowed (\'A'I-00246)", A);
3215 Comp_Type : constant Entity_Id :=
3217 (Etype (Expression (A)));
3219 if Comes_From_Source (A)
3220 and then Ada_Version >= Ada_05
3222 ((Is_Private_Type (Comp_Type)
3223 and then not Is_Generic_Type (Comp_Type))
3224 or else Is_Tagged_Type (Comp_Type)
3225 or else Is_Volatile (Comp_Type))
3228 ("component type of a view conversion cannot"
3229 & " be private, tagged, or volatile"
3238 if (Conversion_OK (A)
3239 or else Valid_Conversion (A, Etype (A), Expression (A)))
3240 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3242 Resolve (Expression (A));
3245 -- If the actual is a function call that returns a limited
3246 -- unconstrained object that needs finalization, create a
3247 -- transient scope for it, so that it can receive the proper
3248 -- finalization list.
3250 elsif Nkind (A) = N_Function_Call
3251 and then Is_Limited_Record (Etype (F))
3252 and then not Is_Constrained (Etype (F))
3253 and then Expander_Active
3255 (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3257 Establish_Transient_Scope (A, False);
3259 -- A small optimization: if one of the actuals is a concatenation
3260 -- create a block around a procedure call to recover stack space.
3261 -- This alleviates stack usage when several procedure calls in
3262 -- the same statement list use concatenation. We do not perform
3263 -- this wrapping for code statements, where the argument is a
3264 -- static string, and we want to preserve warnings involving
3265 -- sequences of such statements.
3267 elsif Nkind (A) = N_Op_Concat
3268 and then Nkind (N) = N_Procedure_Call_Statement
3269 and then Expander_Active
3271 not (Is_Intrinsic_Subprogram (Nam)
3272 and then Chars (Nam) = Name_Asm)
3273 and then not Static_Concatenation (A)
3275 Establish_Transient_Scope (A, False);
3276 Resolve (A, Etype (F));
3279 if Nkind (A) = N_Type_Conversion
3280 and then Is_Array_Type (Etype (F))
3281 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3283 (Is_Limited_Type (Etype (F))
3284 or else Is_Limited_Type (Etype (Expression (A))))
3287 ("conversion between unrelated limited array types " &
3288 "not allowed (\A\I-00246)", A);
3290 if Is_Limited_Type (Etype (F)) then
3291 Explain_Limited_Type (Etype (F), A);
3294 if Is_Limited_Type (Etype (Expression (A))) then
3295 Explain_Limited_Type (Etype (Expression (A)), A);
3299 -- (Ada 2005: AI-251): If the actual is an allocator whose
3300 -- directly designated type is a class-wide interface, we build
3301 -- an anonymous access type to use it as the type of the
3302 -- allocator. Later, when the subprogram call is expanded, if
3303 -- the interface has a secondary dispatch table the expander
3304 -- will add a type conversion to force the correct displacement
3307 if Nkind (A) = N_Allocator then
3309 DDT : constant Entity_Id :=
3310 Directly_Designated_Type (Base_Type (Etype (F)));
3312 New_Itype : Entity_Id;
3315 if Is_Class_Wide_Type (DDT)
3316 and then Is_Interface (DDT)
3318 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3319 Set_Etype (New_Itype, Etype (A));
3320 Set_Directly_Designated_Type (New_Itype,
3321 Directly_Designated_Type (Etype (A)));
3322 Set_Etype (A, New_Itype);
3325 -- Ada 2005, AI-162:If the actual is an allocator, the
3326 -- innermost enclosing statement is the master of the
3327 -- created object. This needs to be done with expansion
3328 -- enabled only, otherwise the transient scope will not
3329 -- be removed in the expansion of the wrapped construct.
3331 if (Is_Controlled (DDT) or else Has_Task (DDT))
3332 and then Expander_Active
3334 Establish_Transient_Scope (A, False);
3339 -- (Ada 2005): The call may be to a primitive operation of
3340 -- a tagged synchronized type, declared outside of the type.
3341 -- In this case the controlling actual must be converted to
3342 -- its corresponding record type, which is the formal type.
3343 -- The actual may be a subtype, either because of a constraint
3344 -- or because it is a generic actual, so use base type to
3345 -- locate concurrent type.
3347 A_Typ := Base_Type (Etype (A));
3348 F_Typ := Base_Type (Etype (F));
3351 Full_A_Typ : Entity_Id;
3354 if Present (Full_View (A_Typ)) then
3355 Full_A_Typ := Base_Type (Full_View (A_Typ));
3357 Full_A_Typ := A_Typ;
3360 -- Tagged synchronized type (case 1): the actual is a
3363 if Is_Concurrent_Type (A_Typ)
3364 and then Corresponding_Record_Type (A_Typ) = F_Typ
3367 Unchecked_Convert_To
3368 (Corresponding_Record_Type (A_Typ), A));
3369 Resolve (A, Etype (F));
3371 -- Tagged synchronized type (case 2): the formal is a
3374 elsif Ekind (Full_A_Typ) = E_Record_Type
3376 (Corresponding_Concurrent_Type (Full_A_Typ))
3377 and then Is_Concurrent_Type (F_Typ)
3378 and then Present (Corresponding_Record_Type (F_Typ))
3379 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3381 Resolve (A, Corresponding_Record_Type (F_Typ));
3386 Resolve (A, Etype (F));
3394 -- For mode IN, if actual is an entity, and the type of the formal
3395 -- has warnings suppressed, then we reset Never_Set_In_Source for
3396 -- the calling entity. The reason for this is to catch cases like
3397 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3398 -- uses trickery to modify an IN parameter.
3400 if Ekind (F) = E_In_Parameter
3401 and then Is_Entity_Name (A)
3402 and then Present (Entity (A))
3403 and then Ekind (Entity (A)) = E_Variable
3404 and then Has_Warnings_Off (F_Typ)
3406 Set_Never_Set_In_Source (Entity (A), False);
3409 -- Perform error checks for IN and IN OUT parameters
3411 if Ekind (F) /= E_Out_Parameter then
3413 -- Check unset reference. For scalar parameters, it is clearly
3414 -- wrong to pass an uninitialized value as either an IN or
3415 -- IN-OUT parameter. For composites, it is also clearly an
3416 -- error to pass a completely uninitialized value as an IN
3417 -- parameter, but the case of IN OUT is trickier. We prefer
3418 -- not to give a warning here. For example, suppose there is
3419 -- a routine that sets some component of a record to False.
3420 -- It is perfectly reasonable to make this IN-OUT and allow
3421 -- either initialized or uninitialized records to be passed
3424 -- For partially initialized composite values, we also avoid
3425 -- warnings, since it is quite likely that we are passing a
3426 -- partially initialized value and only the initialized fields
3427 -- will in fact be read in the subprogram.
3429 if Is_Scalar_Type (A_Typ)
3430 or else (Ekind (F) = E_In_Parameter
3431 and then not Is_Partially_Initialized_Type (A_Typ))
3433 Check_Unset_Reference (A);
3436 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3437 -- actual to a nested call, since this is case of reading an
3438 -- out parameter, which is not allowed.
3440 if Ada_Version = Ada_83
3441 and then Is_Entity_Name (A)
3442 and then Ekind (Entity (A)) = E_Out_Parameter
3444 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3448 -- Case of OUT or IN OUT parameter
3450 if Ekind (F) /= E_In_Parameter then
3452 -- For an Out parameter, check for useless assignment. Note
3453 -- that we can't set Last_Assignment this early, because we may
3454 -- kill current values in Resolve_Call, and that call would
3455 -- clobber the Last_Assignment field.
3457 -- Note: call Warn_On_Useless_Assignment before doing the check
3458 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3459 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3460 -- reflects the last assignment, not this one!
3462 if Ekind (F) = E_Out_Parameter then
3463 if Warn_On_Modified_As_Out_Parameter (F)
3464 and then Is_Entity_Name (A)
3465 and then Present (Entity (A))
3466 and then Comes_From_Source (N)
3468 Warn_On_Useless_Assignment (Entity (A), A);
3472 -- Validate the form of the actual. Note that the call to
3473 -- Is_OK_Variable_For_Out_Formal generates the required
3474 -- reference in this case.
3476 if not Is_OK_Variable_For_Out_Formal (A) then
3477 Error_Msg_NE ("actual for& must be a variable", A, F);
3480 -- What's the following about???
3482 if Is_Entity_Name (A) then
3483 Kill_Checks (Entity (A));
3489 if Etype (A) = Any_Type then
3490 Set_Etype (N, Any_Type);
3494 -- Apply appropriate range checks for in, out, and in-out
3495 -- parameters. Out and in-out parameters also need a separate
3496 -- check, if there is a type conversion, to make sure the return
3497 -- value meets the constraints of the variable before the
3500 -- Gigi looks at the check flag and uses the appropriate types.
3501 -- For now since one flag is used there is an optimization which
3502 -- might not be done in the In Out case since Gigi does not do
3503 -- any analysis. More thought required about this ???
3505 if Ekind (F) = E_In_Parameter
3506 or else Ekind (F) = E_In_Out_Parameter
3508 if Is_Scalar_Type (Etype (A)) then
3509 Apply_Scalar_Range_Check (A, F_Typ);
3511 elsif Is_Array_Type (Etype (A)) then
3512 Apply_Length_Check (A, F_Typ);
3514 elsif Is_Record_Type (F_Typ)
3515 and then Has_Discriminants (F_Typ)
3516 and then Is_Constrained (F_Typ)
3517 and then (not Is_Derived_Type (F_Typ)
3518 or else Comes_From_Source (Nam))
3520 Apply_Discriminant_Check (A, F_Typ);
3522 elsif Is_Access_Type (F_Typ)
3523 and then Is_Array_Type (Designated_Type (F_Typ))
3524 and then Is_Constrained (Designated_Type (F_Typ))
3526 Apply_Length_Check (A, F_Typ);
3528 elsif Is_Access_Type (F_Typ)
3529 and then Has_Discriminants (Designated_Type (F_Typ))
3530 and then Is_Constrained (Designated_Type (F_Typ))
3532 Apply_Discriminant_Check (A, F_Typ);
3535 Apply_Range_Check (A, F_Typ);
3538 -- Ada 2005 (AI-231)
3540 if Ada_Version >= Ada_05
3541 and then Is_Access_Type (F_Typ)
3542 and then Can_Never_Be_Null (F_Typ)
3543 and then Known_Null (A)
3545 Apply_Compile_Time_Constraint_Error
3547 Msg => "(Ada 2005) null not allowed in "
3548 & "null-excluding formal?",
3549 Reason => CE_Null_Not_Allowed);
3553 if Ekind (F) = E_Out_Parameter
3554 or else Ekind (F) = E_In_Out_Parameter
3556 if Nkind (A) = N_Type_Conversion then
3557 if Is_Scalar_Type (A_Typ) then
3558 Apply_Scalar_Range_Check
3559 (Expression (A), Etype (Expression (A)), A_Typ);
3562 (Expression (A), Etype (Expression (A)), A_Typ);
3566 if Is_Scalar_Type (F_Typ) then
3567 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3569 elsif Is_Array_Type (F_Typ)
3570 and then Ekind (F) = E_Out_Parameter
3572 Apply_Length_Check (A, F_Typ);
3575 Apply_Range_Check (A, A_Typ, F_Typ);
3580 -- An actual associated with an access parameter is implicitly
3581 -- converted to the anonymous access type of the formal and must
3582 -- satisfy the legality checks for access conversions.
3584 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3585 if not Valid_Conversion (A, F_Typ, A) then
3587 ("invalid implicit conversion for access parameter", A);
3591 -- Check bad case of atomic/volatile argument (RM C.6(12))
3593 if Is_By_Reference_Type (Etype (F))
3594 and then Comes_From_Source (N)
3596 if Is_Atomic_Object (A)
3597 and then not Is_Atomic (Etype (F))
3600 ("cannot pass atomic argument to non-atomic formal",
3603 elsif Is_Volatile_Object (A)
3604 and then not Is_Volatile (Etype (F))
3607 ("cannot pass volatile argument to non-volatile formal",
3612 -- Check that subprograms don't have improper controlling
3613 -- arguments (RM 3.9.2 (9)).
3615 -- A primitive operation may have an access parameter of an
3616 -- incomplete tagged type, but a dispatching call is illegal
3617 -- if the type is still incomplete.
3619 if Is_Controlling_Formal (F) then
3620 Set_Is_Controlling_Actual (A);
3622 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3624 Desig : constant Entity_Id := Designated_Type (Etype (F));
3626 if Ekind (Desig) = E_Incomplete_Type
3627 and then No (Full_View (Desig))
3628 and then No (Non_Limited_View (Desig))
3631 ("premature use of incomplete type& " &
3632 "in dispatching call", A, Desig);
3637 elsif Nkind (A) = N_Explicit_Dereference then
3638 Validate_Remote_Access_To_Class_Wide_Type (A);
3641 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3642 and then not Is_Class_Wide_Type (F_Typ)
3643 and then not Is_Controlling_Formal (F)
3645 Error_Msg_N ("class-wide argument not allowed here!", A);
3647 if Is_Subprogram (Nam)
3648 and then Comes_From_Source (Nam)
3650 Error_Msg_Node_2 := F_Typ;
3652 ("& is not a dispatching operation of &!", A, Nam);
3655 elsif Is_Access_Type (A_Typ)
3656 and then Is_Access_Type (F_Typ)
3657 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3658 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3659 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3660 or else (Nkind (A) = N_Attribute_Reference
3662 Is_Class_Wide_Type (Etype (Prefix (A)))))
3663 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3664 and then not Is_Controlling_Formal (F)
3667 ("access to class-wide argument not allowed here!", A);
3669 if Is_Subprogram (Nam)
3670 and then Comes_From_Source (Nam)
3672 Error_Msg_Node_2 := Designated_Type (F_Typ);
3674 ("& is not a dispatching operation of &!", A, Nam);
3680 -- If it is a named association, treat the selector_name as
3681 -- a proper identifier, and mark the corresponding entity.
3683 if Nkind (Parent (A)) = N_Parameter_Association then
3684 Set_Entity (Selector_Name (Parent (A)), F);
3685 Generate_Reference (F, Selector_Name (Parent (A)));
3686 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3687 Generate_Reference (F_Typ, N, ' ');
3692 if Ekind (F) /= E_Out_Parameter then
3693 Check_Unset_Reference (A);
3698 -- Case where actual is not present
3706 end Resolve_Actuals;
3708 -----------------------
3709 -- Resolve_Allocator --
3710 -----------------------
3712 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
3713 E : constant Node_Id := Expression (N);
3715 Discrim : Entity_Id;
3718 Assoc : Node_Id := Empty;
3721 procedure Check_Allocator_Discrim_Accessibility
3722 (Disc_Exp : Node_Id;
3723 Alloc_Typ : Entity_Id);
3724 -- Check that accessibility level associated with an access discriminant
3725 -- initialized in an allocator by the expression Disc_Exp is not deeper
3726 -- than the level of the allocator type Alloc_Typ. An error message is
3727 -- issued if this condition is violated. Specialized checks are done for
3728 -- the cases of a constraint expression which is an access attribute or
3729 -- an access discriminant.
3731 function In_Dispatching_Context return Boolean;
3732 -- If the allocator is an actual in a call, it is allowed to be class-
3733 -- wide when the context is not because it is a controlling actual.
3735 procedure Propagate_Coextensions (Root : Node_Id);
3736 -- Propagate all nested coextensions which are located one nesting
3737 -- level down the tree to the node Root. Example:
3740 -- Level_1_Coextension
3741 -- Level_2_Coextension
3743 -- The algorithm is paired with delay actions done by the Expander. In
3744 -- the above example, assume all coextensions are controlled types.
3745 -- The cycle of analysis, resolution and expansion will yield:
3747 -- 1) Analyze Top_Record
3748 -- 2) Analyze Level_1_Coextension
3749 -- 3) Analyze Level_2_Coextension
3750 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
3752 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3753 -- generated to capture the allocated object. Temp_1 is attached
3754 -- to the coextension chain of Level_2_Coextension.
3755 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3756 -- coextension. A forward tree traversal is performed which finds
3757 -- Level_2_Coextension's list and copies its contents into its
3759 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3760 -- generated to capture the allocated object. Temp_2 is attached
3761 -- to the coextension chain of Level_1_Coextension. Currently, the
3762 -- contents of the list are [Temp_2, Temp_1].
3763 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3764 -- finds Level_1_Coextension's list and copies its contents into
3766 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3767 -- Temp_2 and attach them to Top_Record's finalization list.
3769 -------------------------------------------
3770 -- Check_Allocator_Discrim_Accessibility --
3771 -------------------------------------------
3773 procedure Check_Allocator_Discrim_Accessibility
3774 (Disc_Exp : Node_Id;
3775 Alloc_Typ : Entity_Id)
3778 if Type_Access_Level (Etype (Disc_Exp)) >
3779 Type_Access_Level (Alloc_Typ)
3782 ("operand type has deeper level than allocator type", Disc_Exp);
3784 -- When the expression is an Access attribute the level of the prefix
3785 -- object must not be deeper than that of the allocator's type.
3787 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3788 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3790 and then Object_Access_Level (Prefix (Disc_Exp))
3791 > Type_Access_Level (Alloc_Typ)
3794 ("prefix of attribute has deeper level than allocator type",
3797 -- When the expression is an access discriminant the check is against
3798 -- the level of the prefix object.
3800 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3801 and then Nkind (Disc_Exp) = N_Selected_Component
3802 and then Object_Access_Level (Prefix (Disc_Exp))
3803 > Type_Access_Level (Alloc_Typ)
3806 ("access discriminant has deeper level than allocator type",
3809 -- All other cases are legal
3814 end Check_Allocator_Discrim_Accessibility;
3816 ----------------------------
3817 -- In_Dispatching_Context --
3818 ----------------------------
3820 function In_Dispatching_Context return Boolean is
3821 Par : constant Node_Id := Parent (N);
3823 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
3824 and then Is_Entity_Name (Name (Par))
3825 and then Is_Dispatching_Operation (Entity (Name (Par)));
3826 end In_Dispatching_Context;
3828 ----------------------------
3829 -- Propagate_Coextensions --
3830 ----------------------------
3832 procedure Propagate_Coextensions (Root : Node_Id) is
3834 procedure Copy_List (From : Elist_Id; To : Elist_Id);
3835 -- Copy the contents of list From into list To, preserving the
3836 -- order of elements.
3838 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
3839 -- Recognize an allocator or a rewritten allocator node and add it
3840 -- along with its nested coextensions to the list of Root.
3846 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
3847 From_Elmt : Elmt_Id;
3849 From_Elmt := First_Elmt (From);
3850 while Present (From_Elmt) loop
3851 Append_Elmt (Node (From_Elmt), To);
3852 Next_Elmt (From_Elmt);
3856 -----------------------
3857 -- Process_Allocator --
3858 -----------------------
3860 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
3861 Orig_Nod : Node_Id := Nod;
3864 -- This is a possible rewritten subtype indication allocator. Any
3865 -- nested coextensions will appear as discriminant constraints.
3867 if Nkind (Nod) = N_Identifier
3868 and then Present (Original_Node (Nod))
3869 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
3873 Discr_Elmt : Elmt_Id;
3876 if Is_Record_Type (Entity (Nod)) then
3878 First_Elmt (Discriminant_Constraint (Entity (Nod)));
3879 while Present (Discr_Elmt) loop
3880 Discr := Node (Discr_Elmt);
3882 if Nkind (Discr) = N_Identifier
3883 and then Present (Original_Node (Discr))
3884 and then Nkind (Original_Node (Discr)) = N_Allocator
3885 and then Present (Coextensions (
3886 Original_Node (Discr)))
3888 if No (Coextensions (Root)) then
3889 Set_Coextensions (Root, New_Elmt_List);
3893 (From => Coextensions (Original_Node (Discr)),
3894 To => Coextensions (Root));
3897 Next_Elmt (Discr_Elmt);
3900 -- There is no need to continue the traversal of this
3901 -- subtree since all the information has already been
3908 -- Case of either a stand alone allocator or a rewritten allocator
3909 -- with an aggregate.
3912 if Present (Original_Node (Nod)) then
3913 Orig_Nod := Original_Node (Nod);
3916 if Nkind (Orig_Nod) = N_Allocator then
3918 -- Propagate the list of nested coextensions to the Root
3919 -- allocator. This is done through list copy since a single
3920 -- allocator may have multiple coextensions. Do not touch
3921 -- coextensions roots.
3923 if not Is_Coextension_Root (Orig_Nod)
3924 and then Present (Coextensions (Orig_Nod))
3926 if No (Coextensions (Root)) then
3927 Set_Coextensions (Root, New_Elmt_List);
3931 (From => Coextensions (Orig_Nod),
3932 To => Coextensions (Root));
3935 -- There is no need to continue the traversal of this
3936 -- subtree since all the information has already been
3943 -- Keep on traversing, looking for the next allocator
3946 end Process_Allocator;
3948 procedure Process_Allocators is
3949 new Traverse_Proc (Process_Allocator);
3951 -- Start of processing for Propagate_Coextensions
3954 Process_Allocators (Expression (Root));
3955 end Propagate_Coextensions;
3957 -- Start of processing for Resolve_Allocator
3960 -- Replace general access with specific type
3962 if Ekind (Etype (N)) = E_Allocator_Type then
3963 Set_Etype (N, Base_Type (Typ));
3966 if Is_Abstract_Type (Typ) then
3967 Error_Msg_N ("type of allocator cannot be abstract", N);
3970 -- For qualified expression, resolve the expression using the
3971 -- given subtype (nothing to do for type mark, subtype indication)
3973 if Nkind (E) = N_Qualified_Expression then
3974 if Is_Class_Wide_Type (Etype (E))
3975 and then not Is_Class_Wide_Type (Designated_Type (Typ))
3976 and then not In_Dispatching_Context
3979 ("class-wide allocator not allowed for this access type", N);
3982 Resolve (Expression (E), Etype (E));
3983 Check_Unset_Reference (Expression (E));
3985 -- A qualified expression requires an exact match of the type,
3986 -- class-wide matching is not allowed.
3988 if (Is_Class_Wide_Type (Etype (Expression (E)))
3989 or else Is_Class_Wide_Type (Etype (E)))
3990 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
3992 Wrong_Type (Expression (E), Etype (E));
3995 -- A special accessibility check is needed for allocators that
3996 -- constrain access discriminants. The level of the type of the
3997 -- expression used to constrain an access discriminant cannot be
3998 -- deeper than the type of the allocator (in contrast to access
3999 -- parameters, where the level of the actual can be arbitrary).
4001 -- We can't use Valid_Conversion to perform this check because
4002 -- in general the type of the allocator is unrelated to the type
4003 -- of the access discriminant.
4005 if Ekind (Typ) /= E_Anonymous_Access_Type
4006 or else Is_Local_Anonymous_Access (Typ)
4008 Subtyp := Entity (Subtype_Mark (E));
4010 Aggr := Original_Node (Expression (E));
4012 if Has_Discriminants (Subtyp)
4013 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
4015 Discrim := First_Discriminant (Base_Type (Subtyp));
4017 -- Get the first component expression of the aggregate
4019 if Present (Expressions (Aggr)) then
4020 Disc_Exp := First (Expressions (Aggr));
4022 elsif Present (Component_Associations (Aggr)) then
4023 Assoc := First (Component_Associations (Aggr));
4025 if Present (Assoc) then
4026 Disc_Exp := Expression (Assoc);
4035 while Present (Discrim) and then Present (Disc_Exp) loop
4036 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4037 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4040 Next_Discriminant (Discrim);
4042 if Present (Discrim) then
4043 if Present (Assoc) then
4045 Disc_Exp := Expression (Assoc);
4047 elsif Present (Next (Disc_Exp)) then
4051 Assoc := First (Component_Associations (Aggr));
4053 if Present (Assoc) then
4054 Disc_Exp := Expression (Assoc);
4064 -- For a subtype mark or subtype indication, freeze the subtype
4067 Freeze_Expression (E);
4069 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
4071 ("initialization required for access-to-constant allocator", N);
4074 -- A special accessibility check is needed for allocators that
4075 -- constrain access discriminants. The level of the type of the
4076 -- expression used to constrain an access discriminant cannot be
4077 -- deeper than the type of the allocator (in contrast to access
4078 -- parameters, where the level of the actual can be arbitrary).
4079 -- We can't use Valid_Conversion to perform this check because
4080 -- in general the type of the allocator is unrelated to the type
4081 -- of the access discriminant.
4083 if Nkind (Original_Node (E)) = N_Subtype_Indication
4084 and then (Ekind (Typ) /= E_Anonymous_Access_Type
4085 or else Is_Local_Anonymous_Access (Typ))
4087 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
4089 if Has_Discriminants (Subtyp) then
4090 Discrim := First_Discriminant (Base_Type (Subtyp));
4091 Constr := First (Constraints (Constraint (Original_Node (E))));
4092 while Present (Discrim) and then Present (Constr) loop
4093 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4094 if Nkind (Constr) = N_Discriminant_Association then
4095 Disc_Exp := Original_Node (Expression (Constr));
4097 Disc_Exp := Original_Node (Constr);
4100 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4103 Next_Discriminant (Discrim);
4110 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4111 -- check that the level of the type of the created object is not deeper
4112 -- than the level of the allocator's access type, since extensions can
4113 -- now occur at deeper levels than their ancestor types. This is a
4114 -- static accessibility level check; a run-time check is also needed in
4115 -- the case of an initialized allocator with a class-wide argument (see
4116 -- Expand_Allocator_Expression).
4118 if Ada_Version >= Ada_05
4119 and then Is_Class_Wide_Type (Designated_Type (Typ))
4122 Exp_Typ : Entity_Id;
4125 if Nkind (E) = N_Qualified_Expression then
4126 Exp_Typ := Etype (E);
4127 elsif Nkind (E) = N_Subtype_Indication then
4128 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4130 Exp_Typ := Entity (E);
4133 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4134 if In_Instance_Body then
4135 Error_Msg_N ("?type in allocator has deeper level than" &
4136 " designated class-wide type", E);
4137 Error_Msg_N ("\?Program_Error will be raised at run time",
4140 Make_Raise_Program_Error (Sloc (N),
4141 Reason => PE_Accessibility_Check_Failed));
4144 -- Do not apply Ada 2005 accessibility checks on a class-wide
4145 -- allocator if the type given in the allocator is a formal
4146 -- type. A run-time check will be performed in the instance.
4148 elsif not Is_Generic_Type (Exp_Typ) then
4149 Error_Msg_N ("type in allocator has deeper level than" &
4150 " designated class-wide type", E);
4156 -- Check for allocation from an empty storage pool
4158 if No_Pool_Assigned (Typ) then
4160 Loc : constant Source_Ptr := Sloc (N);
4162 Error_Msg_N ("?allocation from empty storage pool!", N);
4163 Error_Msg_N ("\?Storage_Error will be raised at run time!", N);
4165 Make_Raise_Storage_Error (Loc,
4166 Reason => SE_Empty_Storage_Pool));
4169 -- If the context is an unchecked conversion, as may happen within
4170 -- an inlined subprogram, the allocator is being resolved with its
4171 -- own anonymous type. In that case, if the target type has a specific
4172 -- storage pool, it must be inherited explicitly by the allocator type.
4174 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4175 and then No (Associated_Storage_Pool (Typ))
4177 Set_Associated_Storage_Pool
4178 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4181 -- An erroneous allocator may be rewritten as a raise Program_Error
4184 if Nkind (N) = N_Allocator then
4186 -- An anonymous access discriminant is the definition of a
4189 if Ekind (Typ) = E_Anonymous_Access_Type
4190 and then Nkind (Associated_Node_For_Itype (Typ)) =
4191 N_Discriminant_Specification
4193 -- Avoid marking an allocator as a dynamic coextension if it is
4194 -- within a static construct.
4196 if not Is_Static_Coextension (N) then
4197 Set_Is_Dynamic_Coextension (N);
4200 -- Cleanup for potential static coextensions
4203 Set_Is_Dynamic_Coextension (N, False);
4204 Set_Is_Static_Coextension (N, False);
4207 -- There is no need to propagate any nested coextensions if they
4208 -- are marked as static since they will be rewritten on the spot.
4210 if not Is_Static_Coextension (N) then
4211 Propagate_Coextensions (N);
4214 end Resolve_Allocator;
4216 ---------------------------
4217 -- Resolve_Arithmetic_Op --
4218 ---------------------------
4220 -- Used for resolving all arithmetic operators except exponentiation
4222 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4223 L : constant Node_Id := Left_Opnd (N);
4224 R : constant Node_Id := Right_Opnd (N);
4225 TL : constant Entity_Id := Base_Type (Etype (L));
4226 TR : constant Entity_Id := Base_Type (Etype (R));
4230 B_Typ : constant Entity_Id := Base_Type (Typ);
4231 -- We do the resolution using the base type, because intermediate values
4232 -- in expressions always are of the base type, not a subtype of it.
4234 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4235 -- Returns True if N is in a context that expects "any real type"
4237 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4238 -- Return True iff given type is Integer or universal real/integer
4240 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4241 -- Choose type of integer literal in fixed-point operation to conform
4242 -- to available fixed-point type. T is the type of the other operand,
4243 -- which is needed to determine the expected type of N.
4245 procedure Set_Operand_Type (N : Node_Id);
4246 -- Set operand type to T if universal
4248 -------------------------------
4249 -- Expected_Type_Is_Any_Real --
4250 -------------------------------
4252 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4254 -- N is the expression after "delta" in a fixed_point_definition;
4257 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4258 N_Decimal_Fixed_Point_Definition,
4260 -- N is one of the bounds in a real_range_specification;
4263 N_Real_Range_Specification,
4265 -- N is the expression of a delta_constraint;
4268 N_Delta_Constraint);
4269 end Expected_Type_Is_Any_Real;
4271 -----------------------------
4272 -- Is_Integer_Or_Universal --
4273 -----------------------------
4275 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4277 Index : Interp_Index;
4281 if not Is_Overloaded (N) then
4283 return Base_Type (T) = Base_Type (Standard_Integer)
4284 or else T = Universal_Integer
4285 or else T = Universal_Real;
4287 Get_First_Interp (N, Index, It);
4288 while Present (It.Typ) loop
4289 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4290 or else It.Typ = Universal_Integer
4291 or else It.Typ = Universal_Real
4296 Get_Next_Interp (Index, It);
4301 end Is_Integer_Or_Universal;
4303 ----------------------------
4304 -- Set_Mixed_Mode_Operand --
4305 ----------------------------
4307 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4308 Index : Interp_Index;
4312 if Universal_Interpretation (N) = Universal_Integer then
4314 -- A universal integer literal is resolved as standard integer
4315 -- except in the case of a fixed-point result, where we leave it
4316 -- as universal (to be handled by Exp_Fixd later on)
4318 if Is_Fixed_Point_Type (T) then
4319 Resolve (N, Universal_Integer);
4321 Resolve (N, Standard_Integer);
4324 elsif Universal_Interpretation (N) = Universal_Real
4325 and then (T = Base_Type (Standard_Integer)
4326 or else T = Universal_Integer
4327 or else T = Universal_Real)
4329 -- A universal real can appear in a fixed-type context. We resolve
4330 -- the literal with that context, even though this might raise an
4331 -- exception prematurely (the other operand may be zero).
4335 elsif Etype (N) = Base_Type (Standard_Integer)
4336 and then T = Universal_Real
4337 and then Is_Overloaded (N)
4339 -- Integer arg in mixed-mode operation. Resolve with universal
4340 -- type, in case preference rule must be applied.
4342 Resolve (N, Universal_Integer);
4345 and then B_Typ /= Universal_Fixed
4347 -- Not a mixed-mode operation, resolve with context
4351 elsif Etype (N) = Any_Fixed then
4353 -- N may itself be a mixed-mode operation, so use context type
4357 elsif Is_Fixed_Point_Type (T)
4358 and then B_Typ = Universal_Fixed
4359 and then Is_Overloaded (N)
4361 -- Must be (fixed * fixed) operation, operand must have one
4362 -- compatible interpretation.
4364 Resolve (N, Any_Fixed);
4366 elsif Is_Fixed_Point_Type (B_Typ)
4367 and then (T = Universal_Real
4368 or else Is_Fixed_Point_Type (T))
4369 and then Is_Overloaded (N)
4371 -- C * F(X) in a fixed context, where C is a real literal or a
4372 -- fixed-point expression. F must have either a fixed type
4373 -- interpretation or an integer interpretation, but not both.
4375 Get_First_Interp (N, Index, It);
4376 while Present (It.Typ) loop
4377 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4379 if Analyzed (N) then
4380 Error_Msg_N ("ambiguous operand in fixed operation", N);
4382 Resolve (N, Standard_Integer);
4385 elsif Is_Fixed_Point_Type (It.Typ) then
4387 if Analyzed (N) then
4388 Error_Msg_N ("ambiguous operand in fixed operation", N);
4390 Resolve (N, It.Typ);
4394 Get_Next_Interp (Index, It);
4397 -- Reanalyze the literal with the fixed type of the context. If
4398 -- context is Universal_Fixed, we are within a conversion, leave
4399 -- the literal as a universal real because there is no usable
4400 -- fixed type, and the target of the conversion plays no role in
4414 if B_Typ = Universal_Fixed
4415 and then Nkind (Op2) = N_Real_Literal
4417 T2 := Universal_Real;
4422 Set_Analyzed (Op2, False);
4429 end Set_Mixed_Mode_Operand;
4431 ----------------------
4432 -- Set_Operand_Type --
4433 ----------------------
4435 procedure Set_Operand_Type (N : Node_Id) is
4437 if Etype (N) = Universal_Integer
4438 or else Etype (N) = Universal_Real
4442 end Set_Operand_Type;
4444 -- Start of processing for Resolve_Arithmetic_Op
4447 if Comes_From_Source (N)
4448 and then Ekind (Entity (N)) = E_Function
4449 and then Is_Imported (Entity (N))
4450 and then Is_Intrinsic_Subprogram (Entity (N))
4452 Resolve_Intrinsic_Operator (N, Typ);
4455 -- Special-case for mixed-mode universal expressions or fixed point
4456 -- type operation: each argument is resolved separately. The same
4457 -- treatment is required if one of the operands of a fixed point
4458 -- operation is universal real, since in this case we don't do a
4459 -- conversion to a specific fixed-point type (instead the expander
4460 -- takes care of the case).
4462 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4463 and then Present (Universal_Interpretation (L))
4464 and then Present (Universal_Interpretation (R))
4466 Resolve (L, Universal_Interpretation (L));
4467 Resolve (R, Universal_Interpretation (R));
4468 Set_Etype (N, B_Typ);
4470 elsif (B_Typ = Universal_Real
4471 or else Etype (N) = Universal_Fixed
4472 or else (Etype (N) = Any_Fixed
4473 and then Is_Fixed_Point_Type (B_Typ))
4474 or else (Is_Fixed_Point_Type (B_Typ)
4475 and then (Is_Integer_Or_Universal (L)
4477 Is_Integer_Or_Universal (R))))
4478 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4480 if TL = Universal_Integer or else TR = Universal_Integer then
4481 Check_For_Visible_Operator (N, B_Typ);
4484 -- If context is a fixed type and one operand is integer, the
4485 -- other is resolved with the type of the context.
4487 if Is_Fixed_Point_Type (B_Typ)
4488 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4489 or else TL = Universal_Integer)
4494 elsif Is_Fixed_Point_Type (B_Typ)
4495 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4496 or else TR = Universal_Integer)
4502 Set_Mixed_Mode_Operand (L, TR);
4503 Set_Mixed_Mode_Operand (R, TL);
4506 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4507 -- multiplying operators from being used when the expected type is
4508 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4509 -- some cases where the expected type is actually Any_Real;
4510 -- Expected_Type_Is_Any_Real takes care of that case.
4512 if Etype (N) = Universal_Fixed
4513 or else Etype (N) = Any_Fixed
4515 if B_Typ = Universal_Fixed
4516 and then not Expected_Type_Is_Any_Real (N)
4517 and then not Nkind_In (Parent (N), N_Type_Conversion,
4518 N_Unchecked_Type_Conversion)
4520 Error_Msg_N ("type cannot be determined from context!", N);
4521 Error_Msg_N ("\explicit conversion to result type required", N);
4523 Set_Etype (L, Any_Type);
4524 Set_Etype (R, Any_Type);
4527 if Ada_Version = Ada_83
4528 and then Etype (N) = Universal_Fixed
4530 Nkind_In (Parent (N), N_Type_Conversion,
4531 N_Unchecked_Type_Conversion)
4534 ("(Ada 83) fixed-point operation "
4535 & "needs explicit conversion", N);
4538 -- The expected type is "any real type" in contexts like
4539 -- type T is delta <universal_fixed-expression> ...
4540 -- in which case we need to set the type to Universal_Real
4541 -- so that static expression evaluation will work properly.
4543 if Expected_Type_Is_Any_Real (N) then
4544 Set_Etype (N, Universal_Real);
4546 Set_Etype (N, B_Typ);
4550 elsif Is_Fixed_Point_Type (B_Typ)
4551 and then (Is_Integer_Or_Universal (L)
4552 or else Nkind (L) = N_Real_Literal
4553 or else Nkind (R) = N_Real_Literal
4554 or else Is_Integer_Or_Universal (R))
4556 Set_Etype (N, B_Typ);
4558 elsif Etype (N) = Any_Fixed then
4560 -- If no previous errors, this is only possible if one operand
4561 -- is overloaded and the context is universal. Resolve as such.
4563 Set_Etype (N, B_Typ);
4567 if (TL = Universal_Integer or else TL = Universal_Real)
4569 (TR = Universal_Integer or else TR = Universal_Real)
4571 Check_For_Visible_Operator (N, B_Typ);
4574 -- If the context is Universal_Fixed and the operands are also
4575 -- universal fixed, this is an error, unless there is only one
4576 -- applicable fixed_point type (usually duration).
4578 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4579 T := Unique_Fixed_Point_Type (N);
4581 if T = Any_Type then
4594 -- If one of the arguments was resolved to a non-universal type.
4595 -- label the result of the operation itself with the same type.
4596 -- Do the same for the universal argument, if any.
4598 T := Intersect_Types (L, R);
4599 Set_Etype (N, Base_Type (T));
4600 Set_Operand_Type (L);
4601 Set_Operand_Type (R);
4604 Generate_Operator_Reference (N, Typ);
4605 Eval_Arithmetic_Op (N);
4607 -- Set overflow and division checking bit. Much cleverer code needed
4608 -- here eventually and perhaps the Resolve routines should be separated
4609 -- for the various arithmetic operations, since they will need
4610 -- different processing. ???
4612 if Nkind (N) in N_Op then
4613 if not Overflow_Checks_Suppressed (Etype (N)) then
4614 Enable_Overflow_Check (N);
4617 -- Give warning if explicit division by zero
4619 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4620 and then not Division_Checks_Suppressed (Etype (N))
4622 Rop := Right_Opnd (N);
4624 if Compile_Time_Known_Value (Rop)
4625 and then ((Is_Integer_Type (Etype (Rop))
4626 and then Expr_Value (Rop) = Uint_0)
4628 (Is_Real_Type (Etype (Rop))
4629 and then Expr_Value_R (Rop) = Ureal_0))
4631 -- Specialize the warning message according to the operation
4635 Apply_Compile_Time_Constraint_Error
4636 (N, "division by zero?", CE_Divide_By_Zero,
4637 Loc => Sloc (Right_Opnd (N)));
4640 Apply_Compile_Time_Constraint_Error
4641 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4642 Loc => Sloc (Right_Opnd (N)));
4645 Apply_Compile_Time_Constraint_Error
4646 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4647 Loc => Sloc (Right_Opnd (N)));
4649 -- Division by zero can only happen with division, rem,
4650 -- and mod operations.
4653 raise Program_Error;
4656 -- Otherwise just set the flag to check at run time
4659 Activate_Division_Check (N);
4663 -- If Restriction No_Implicit_Conditionals is active, then it is
4664 -- violated if either operand can be negative for mod, or for rem
4665 -- if both operands can be negative.
4667 if Restrictions.Set (No_Implicit_Conditionals)
4668 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4677 -- Set if corresponding operand might be negative
4680 Determine_Range (Left_Opnd (N), OK, Lo, Hi);
4681 LNeg := (not OK) or else Lo < 0;
4683 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
4684 RNeg := (not OK) or else Lo < 0;
4686 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4688 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
4690 Check_Restriction (No_Implicit_Conditionals, N);
4696 Check_Unset_Reference (L);
4697 Check_Unset_Reference (R);
4698 end Resolve_Arithmetic_Op;
4704 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
4705 Loc : constant Source_Ptr := Sloc (N);
4706 Subp : constant Node_Id := Name (N);
4715 -- The context imposes a unique interpretation with type Typ on a
4716 -- procedure or function call. Find the entity of the subprogram that
4717 -- yields the expected type, and propagate the corresponding formal
4718 -- constraints on the actuals. The caller has established that an
4719 -- interpretation exists, and emitted an error if not unique.
4721 -- First deal with the case of a call to an access-to-subprogram,
4722 -- dereference made explicit in Analyze_Call.
4724 if Ekind (Etype (Subp)) = E_Subprogram_Type then
4725 if not Is_Overloaded (Subp) then
4726 Nam := Etype (Subp);
4729 -- Find the interpretation whose type (a subprogram type) has a
4730 -- return type that is compatible with the context. Analysis of
4731 -- the node has established that one exists.
4735 Get_First_Interp (Subp, I, It);
4736 while Present (It.Typ) loop
4737 if Covers (Typ, Etype (It.Typ)) then
4742 Get_Next_Interp (I, It);
4746 raise Program_Error;
4750 -- If the prefix is not an entity, then resolve it
4752 if not Is_Entity_Name (Subp) then
4753 Resolve (Subp, Nam);
4756 -- For an indirect call, we always invalidate checks, since we do not
4757 -- know whether the subprogram is local or global. Yes we could do
4758 -- better here, e.g. by knowing that there are no local subprograms,
4759 -- but it does not seem worth the effort. Similarly, we kill all
4760 -- knowledge of current constant values.
4762 Kill_Current_Values;
4764 -- If this is a procedure call which is really an entry call, do
4765 -- the conversion of the procedure call to an entry call. Protected
4766 -- operations use the same circuitry because the name in the call
4767 -- can be an arbitrary expression with special resolution rules.
4769 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
4770 or else (Is_Entity_Name (Subp)
4771 and then Ekind (Entity (Subp)) = E_Entry)
4773 Resolve_Entry_Call (N, Typ);
4774 Check_Elab_Call (N);
4776 -- Kill checks and constant values, as above for indirect case
4777 -- Who knows what happens when another task is activated?
4779 Kill_Current_Values;
4782 -- Normal subprogram call with name established in Resolve
4784 elsif not (Is_Type (Entity (Subp))) then
4785 Nam := Entity (Subp);
4786 Set_Entity_With_Style_Check (Subp, Nam);
4788 -- Otherwise we must have the case of an overloaded call
4791 pragma Assert (Is_Overloaded (Subp));
4793 -- Initialize Nam to prevent warning (we know it will be assigned
4794 -- in the loop below, but the compiler does not know that).
4798 Get_First_Interp (Subp, I, It);
4799 while Present (It.Typ) loop
4800 if Covers (Typ, It.Typ) then
4802 Set_Entity_With_Style_Check (Subp, Nam);
4806 Get_Next_Interp (I, It);
4810 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
4811 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
4812 and then Nkind (Subp) /= N_Explicit_Dereference
4813 and then Present (Parameter_Associations (N))
4815 -- The prefix is a parameterless function call that returns an access
4816 -- to subprogram. If parameters are present in the current call, add
4817 -- add an explicit dereference. We use the base type here because
4818 -- within an instance these may be subtypes.
4820 -- The dereference is added either in Analyze_Call or here. Should
4821 -- be consolidated ???
4823 Set_Is_Overloaded (Subp, False);
4824 Set_Etype (Subp, Etype (Nam));
4825 Insert_Explicit_Dereference (Subp);
4826 Nam := Designated_Type (Etype (Nam));
4827 Resolve (Subp, Nam);
4830 -- Check that a call to Current_Task does not occur in an entry body
4832 if Is_RTE (Nam, RE_Current_Task) then
4841 -- Exclude calls that occur within the default of a formal
4842 -- parameter of the entry, since those are evaluated outside
4845 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
4847 if Nkind (P) = N_Entry_Body
4848 or else (Nkind (P) = N_Subprogram_Body
4849 and then Is_Entry_Barrier_Function (P))
4853 ("?& should not be used in entry body (RM C.7(17))",
4856 ("\Program_Error will be raised at run time?", N, Nam);
4858 Make_Raise_Program_Error (Loc,
4859 Reason => PE_Current_Task_In_Entry_Body));
4860 Set_Etype (N, Rtype);
4867 -- Check that a procedure call does not occur in the context of the
4868 -- entry call statement of a conditional or timed entry call. Note that
4869 -- the case of a call to a subprogram renaming of an entry will also be
4870 -- rejected. The test for N not being an N_Entry_Call_Statement is
4871 -- defensive, covering the possibility that the processing of entry
4872 -- calls might reach this point due to later modifications of the code
4875 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4876 and then Nkind (N) /= N_Entry_Call_Statement
4877 and then Entry_Call_Statement (Parent (N)) = N
4879 if Ada_Version < Ada_05 then
4880 Error_Msg_N ("entry call required in select statement", N);
4882 -- Ada 2005 (AI-345): If a procedure_call_statement is used
4883 -- for a procedure_or_entry_call, the procedure_name or
4884 -- procedure_prefix of the procedure_call_statement shall denote
4885 -- an entry renamed by a procedure, or (a view of) a primitive
4886 -- subprogram of a limited interface whose first parameter is
4887 -- a controlling parameter.
4889 elsif Nkind (N) = N_Procedure_Call_Statement
4890 and then not Is_Renamed_Entry (Nam)
4891 and then not Is_Controlling_Limited_Procedure (Nam)
4894 ("entry call or dispatching primitive of interface required", N);
4898 -- Check that this is not a call to a protected procedure or entry from
4899 -- within a protected function.
4901 if Ekind (Current_Scope) = E_Function
4902 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
4903 and then Ekind (Nam) /= E_Function
4904 and then Scope (Nam) = Scope (Current_Scope)
4906 Error_Msg_N ("within protected function, protected " &
4907 "object is constant", N);
4908 Error_Msg_N ("\cannot call operation that may modify it", N);
4911 -- Freeze the subprogram name if not in a spec-expression. Note that we
4912 -- freeze procedure calls as well as function calls. Procedure calls are
4913 -- not frozen according to the rules (RM 13.14(14)) because it is
4914 -- impossible to have a procedure call to a non-frozen procedure in pure
4915 -- Ada, but in the code that we generate in the expander, this rule
4916 -- needs extending because we can generate procedure calls that need
4919 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
4920 Freeze_Expression (Subp);
4923 -- For a predefined operator, the type of the result is the type imposed
4924 -- by context, except for a predefined operation on universal fixed.
4925 -- Otherwise The type of the call is the type returned by the subprogram
4928 if Is_Predefined_Op (Nam) then
4929 if Etype (N) /= Universal_Fixed then
4933 -- If the subprogram returns an array type, and the context requires the
4934 -- component type of that array type, the node is really an indexing of
4935 -- the parameterless call. Resolve as such. A pathological case occurs
4936 -- when the type of the component is an access to the array type. In
4937 -- this case the call is truly ambiguous.
4939 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
4941 ((Is_Array_Type (Etype (Nam))
4942 and then Covers (Typ, Component_Type (Etype (Nam))))
4943 or else (Is_Access_Type (Etype (Nam))
4944 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4947 Component_Type (Designated_Type (Etype (Nam))))))
4950 Index_Node : Node_Id;
4952 Ret_Type : constant Entity_Id := Etype (Nam);
4955 if Is_Access_Type (Ret_Type)
4956 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
4959 ("cannot disambiguate function call and indexing", N);
4961 New_Subp := Relocate_Node (Subp);
4962 Set_Entity (Subp, Nam);
4964 if Component_Type (Ret_Type) /= Any_Type then
4965 if Needs_No_Actuals (Nam) then
4967 -- Indexed call to a parameterless function
4970 Make_Indexed_Component (Loc,
4972 Make_Function_Call (Loc,
4974 Expressions => Parameter_Associations (N));
4976 -- An Ada 2005 prefixed call to a primitive operation
4977 -- whose first parameter is the prefix. This prefix was
4978 -- prepended to the parameter list, which is actually a
4979 -- list of indices. Remove the prefix in order to build
4980 -- the proper indexed component.
4983 Make_Indexed_Component (Loc,
4985 Make_Function_Call (Loc,
4987 Parameter_Associations =>
4989 (Remove_Head (Parameter_Associations (N)))),
4990 Expressions => Parameter_Associations (N));
4993 -- Since we are correcting a node classification error made
4994 -- by the parser, we call Replace rather than Rewrite.
4996 Replace (N, Index_Node);
4997 Set_Etype (Prefix (N), Ret_Type);
4999 Resolve_Indexed_Component (N, Typ);
5000 Check_Elab_Call (Prefix (N));
5008 Set_Etype (N, Etype (Nam));
5011 -- In the case where the call is to an overloaded subprogram, Analyze
5012 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5013 -- such a case Normalize_Actuals needs to be called once more to order
5014 -- the actuals correctly. Otherwise the call will have the ordering
5015 -- given by the last overloaded subprogram whether this is the correct
5016 -- one being called or not.
5018 if Is_Overloaded (Subp) then
5019 Normalize_Actuals (N, Nam, False, Norm_OK);
5020 pragma Assert (Norm_OK);
5023 -- In any case, call is fully resolved now. Reset Overload flag, to
5024 -- prevent subsequent overload resolution if node is analyzed again
5026 Set_Is_Overloaded (Subp, False);
5027 Set_Is_Overloaded (N, False);
5029 -- If we are calling the current subprogram from immediately within its
5030 -- body, then that is the case where we can sometimes detect cases of
5031 -- infinite recursion statically. Do not try this in case restriction
5032 -- No_Recursion is in effect anyway, and do it only for source calls.
5034 if Comes_From_Source (N) then
5035 Scop := Current_Scope;
5037 -- Issue warning for possible infinite recursion in the absence
5038 -- of the No_Recursion restriction.
5041 and then not Restriction_Active (No_Recursion)
5042 and then Check_Infinite_Recursion (N)
5044 -- Here we detected and flagged an infinite recursion, so we do
5045 -- not need to test the case below for further warnings. Also if
5046 -- we now have a raise SE node, we are all done.
5048 if Nkind (N) = N_Raise_Storage_Error then
5052 -- If call is to immediately containing subprogram, then check for
5053 -- the case of a possible run-time detectable infinite recursion.
5056 Scope_Loop : while Scop /= Standard_Standard loop
5059 -- Although in general case, recursion is not statically
5060 -- checkable, the case of calling an immediately containing
5061 -- subprogram is easy to catch.
5063 Check_Restriction (No_Recursion, N);
5065 -- If the recursive call is to a parameterless subprogram,
5066 -- then even if we can't statically detect infinite
5067 -- recursion, this is pretty suspicious, and we output a
5068 -- warning. Furthermore, we will try later to detect some
5069 -- cases here at run time by expanding checking code (see
5070 -- Detect_Infinite_Recursion in package Exp_Ch6).
5072 -- If the recursive call is within a handler, do not emit a
5073 -- warning, because this is a common idiom: loop until input
5074 -- is correct, catch illegal input in handler and restart.
5076 if No (First_Formal (Nam))
5077 and then Etype (Nam) = Standard_Void_Type
5078 and then not Error_Posted (N)
5079 and then Nkind (Parent (N)) /= N_Exception_Handler
5081 -- For the case of a procedure call. We give the message
5082 -- only if the call is the first statement in a sequence
5083 -- of statements, or if all previous statements are
5084 -- simple assignments. This is simply a heuristic to
5085 -- decrease false positives, without losing too many good
5086 -- warnings. The idea is that these previous statements
5087 -- may affect global variables the procedure depends on.
5089 if Nkind (N) = N_Procedure_Call_Statement
5090 and then Is_List_Member (N)
5096 while Present (P) loop
5097 if Nkind (P) /= N_Assignment_Statement then
5106 -- Do not give warning if we are in a conditional context
5109 K : constant Node_Kind := Nkind (Parent (N));
5111 if (K = N_Loop_Statement
5112 and then Present (Iteration_Scheme (Parent (N))))
5113 or else K = N_If_Statement
5114 or else K = N_Elsif_Part
5115 or else K = N_Case_Statement_Alternative
5121 -- Here warning is to be issued
5123 Set_Has_Recursive_Call (Nam);
5125 ("?possible infinite recursion!", N);
5127 ("\?Storage_Error may be raised at run time!", N);
5133 Scop := Scope (Scop);
5134 end loop Scope_Loop;
5138 -- If subprogram name is a predefined operator, it was given in
5139 -- functional notation. Replace call node with operator node, so
5140 -- that actuals can be resolved appropriately.
5142 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5143 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5146 elsif Present (Alias (Nam))
5147 and then Is_Predefined_Op (Alias (Nam))
5149 Resolve_Actuals (N, Nam);
5150 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5154 -- Create a transient scope if the resulting type requires it
5156 -- There are several notable exceptions:
5158 -- a) In init procs, the transient scope overhead is not needed, and is
5159 -- even incorrect when the call is a nested initialization call for a
5160 -- component whose expansion may generate adjust calls. However, if the
5161 -- call is some other procedure call within an initialization procedure
5162 -- (for example a call to Create_Task in the init_proc of the task
5163 -- run-time record) a transient scope must be created around this call.
5165 -- b) Enumeration literal pseudo-calls need no transient scope
5167 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5168 -- functions) do not use the secondary stack even though the return
5169 -- type may be unconstrained.
5171 -- d) Calls to a build-in-place function, since such functions may
5172 -- allocate their result directly in a target object, and cases where
5173 -- the result does get allocated in the secondary stack are checked for
5174 -- within the specialized Exp_Ch6 procedures for expanding those
5175 -- build-in-place calls.
5177 -- e) If the subprogram is marked Inline_Always, then even if it returns
5178 -- an unconstrained type the call does not require use of the secondary
5179 -- stack. However, inlining will only take place if the body to inline
5180 -- is already present. It may not be available if e.g. the subprogram is
5181 -- declared in a child instance.
5183 -- If this is an initialization call for a type whose construction
5184 -- uses the secondary stack, and it is not a nested call to initialize
5185 -- a component, we do need to create a transient scope for it. We
5186 -- check for this by traversing the type in Check_Initialization_Call.
5189 and then Has_Pragma_Inline_Always (Nam)
5190 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5191 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5195 elsif Ekind (Nam) = E_Enumeration_Literal
5196 or else Is_Build_In_Place_Function (Nam)
5197 or else Is_Intrinsic_Subprogram (Nam)
5201 elsif Expander_Active
5202 and then Is_Type (Etype (Nam))
5203 and then Requires_Transient_Scope (Etype (Nam))
5205 (not Within_Init_Proc
5207 (not Is_Init_Proc (Nam) and then Ekind (Nam) /= E_Function))
5209 Establish_Transient_Scope (N, Sec_Stack => True);
5211 -- If the call appears within the bounds of a loop, it will
5212 -- be rewritten and reanalyzed, nothing left to do here.
5214 if Nkind (N) /= N_Function_Call then
5218 elsif Is_Init_Proc (Nam)
5219 and then not Within_Init_Proc
5221 Check_Initialization_Call (N, Nam);
5224 -- A protected function cannot be called within the definition of the
5225 -- enclosing protected type.
5227 if Is_Protected_Type (Scope (Nam))
5228 and then In_Open_Scopes (Scope (Nam))
5229 and then not Has_Completion (Scope (Nam))
5232 ("& cannot be called before end of protected definition", N, Nam);
5235 -- Propagate interpretation to actuals, and add default expressions
5238 if Present (First_Formal (Nam)) then
5239 Resolve_Actuals (N, Nam);
5241 -- Overloaded literals are rewritten as function calls, for purpose of
5242 -- resolution. After resolution, we can replace the call with the
5245 elsif Ekind (Nam) = E_Enumeration_Literal then
5246 Copy_Node (Subp, N);
5247 Resolve_Entity_Name (N, Typ);
5249 -- Avoid validation, since it is a static function call
5251 Generate_Reference (Nam, Subp);
5255 -- If the subprogram is not global, then kill all saved values and
5256 -- checks. This is a bit conservative, since in many cases we could do
5257 -- better, but it is not worth the effort. Similarly, we kill constant
5258 -- values. However we do not need to do this for internal entities
5259 -- (unless they are inherited user-defined subprograms), since they
5260 -- are not in the business of molesting local values.
5262 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5263 -- kill all checks and values for calls to global subprograms. This
5264 -- takes care of the case where an access to a local subprogram is
5265 -- taken, and could be passed directly or indirectly and then called
5266 -- from almost any context.
5268 -- Note: we do not do this step till after resolving the actuals. That
5269 -- way we still take advantage of the current value information while
5270 -- scanning the actuals.
5272 -- We suppress killing values if we are processing the nodes associated
5273 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5274 -- type kills all the values as part of analyzing the code that
5275 -- initializes the dispatch tables.
5277 if Inside_Freezing_Actions = 0
5278 and then (not Is_Library_Level_Entity (Nam)
5279 or else Suppress_Value_Tracking_On_Call
5280 (Nearest_Dynamic_Scope (Current_Scope)))
5281 and then (Comes_From_Source (Nam)
5282 or else (Present (Alias (Nam))
5283 and then Comes_From_Source (Alias (Nam))))
5285 Kill_Current_Values;
5288 -- If we are warning about unread OUT parameters, this is the place to
5289 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5290 -- after the above call to Kill_Current_Values (since that call clears
5291 -- the Last_Assignment field of all local variables).
5293 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5294 and then Comes_From_Source (N)
5295 and then In_Extended_Main_Source_Unit (N)
5302 F := First_Formal (Nam);
5303 A := First_Actual (N);
5304 while Present (F) and then Present (A) loop
5305 if (Ekind (F) = E_Out_Parameter
5307 Ekind (F) = E_In_Out_Parameter)
5308 and then Warn_On_Modified_As_Out_Parameter (F)
5309 and then Is_Entity_Name (A)
5310 and then Present (Entity (A))
5311 and then Comes_From_Source (N)
5312 and then Safe_To_Capture_Value (N, Entity (A))
5314 Set_Last_Assignment (Entity (A), A);
5323 -- If the subprogram is a primitive operation, check whether or not
5324 -- it is a correct dispatching call.
5326 if Is_Overloadable (Nam)
5327 and then Is_Dispatching_Operation (Nam)
5329 Check_Dispatching_Call (N);
5331 elsif Ekind (Nam) /= E_Subprogram_Type
5332 and then Is_Abstract_Subprogram (Nam)
5333 and then not In_Instance
5335 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5338 -- If this is a dispatching call, generate the appropriate reference,
5339 -- for better source navigation in GPS.
5341 if Is_Overloadable (Nam)
5342 and then Present (Controlling_Argument (N))
5344 Generate_Reference (Nam, Subp, 'R');
5346 -- Normal case, not a dispatching call
5349 Generate_Reference (Nam, Subp);
5352 if Is_Intrinsic_Subprogram (Nam) then
5353 Check_Intrinsic_Call (N);
5356 -- Check for violation of restriction No_Specific_Termination_Handlers
5357 -- and warn on a potentially blocking call to Abort_Task.
5359 if Is_RTE (Nam, RE_Set_Specific_Handler)
5361 Is_RTE (Nam, RE_Specific_Handler)
5363 Check_Restriction (No_Specific_Termination_Handlers, N);
5365 elsif Is_RTE (Nam, RE_Abort_Task) then
5366 Check_Potentially_Blocking_Operation (N);
5369 -- Issue an error for a call to an eliminated subprogram
5371 Check_For_Eliminated_Subprogram (Subp, Nam);
5373 -- All done, evaluate call and deal with elaboration issues
5376 Check_Elab_Call (N);
5379 -------------------------------
5380 -- Resolve_Character_Literal --
5381 -------------------------------
5383 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5384 B_Typ : constant Entity_Id := Base_Type (Typ);
5388 -- Verify that the character does belong to the type of the context
5390 Set_Etype (N, B_Typ);
5391 Eval_Character_Literal (N);
5393 -- Wide_Wide_Character literals must always be defined, since the set
5394 -- of wide wide character literals is complete, i.e. if a character
5395 -- literal is accepted by the parser, then it is OK for wide wide
5396 -- character (out of range character literals are rejected).
5398 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5401 -- Always accept character literal for type Any_Character, which
5402 -- occurs in error situations and in comparisons of literals, both
5403 -- of which should accept all literals.
5405 elsif B_Typ = Any_Character then
5408 -- For Standard.Character or a type derived from it, check that
5409 -- the literal is in range
5411 elsif Root_Type (B_Typ) = Standard_Character then
5412 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5416 -- For Standard.Wide_Character or a type derived from it, check
5417 -- that the literal is in range
5419 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5420 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5424 -- For Standard.Wide_Wide_Character or a type derived from it, we
5425 -- know the literal is in range, since the parser checked!
5427 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5430 -- If the entity is already set, this has already been resolved in a
5431 -- generic context, or comes from expansion. Nothing else to do.
5433 elsif Present (Entity (N)) then
5436 -- Otherwise we have a user defined character type, and we can use the
5437 -- standard visibility mechanisms to locate the referenced entity.
5440 C := Current_Entity (N);
5441 while Present (C) loop
5442 if Etype (C) = B_Typ then
5443 Set_Entity_With_Style_Check (N, C);
5444 Generate_Reference (C, N);
5452 -- If we fall through, then the literal does not match any of the
5453 -- entries of the enumeration type. This isn't just a constraint
5454 -- error situation, it is an illegality (see RM 4.2).
5457 ("character not defined for }", N, First_Subtype (B_Typ));
5458 end Resolve_Character_Literal;
5460 ---------------------------
5461 -- Resolve_Comparison_Op --
5462 ---------------------------
5464 -- Context requires a boolean type, and plays no role in resolution.
5465 -- Processing identical to that for equality operators. The result
5466 -- type is the base type, which matters when pathological subtypes of
5467 -- booleans with limited ranges are used.
5469 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5470 L : constant Node_Id := Left_Opnd (N);
5471 R : constant Node_Id := Right_Opnd (N);
5475 Check_No_Direct_Boolean_Operators (N);
5477 -- If this is an intrinsic operation which is not predefined, use the
5478 -- types of its declared arguments to resolve the possibly overloaded
5479 -- operands. Otherwise the operands are unambiguous and specify the
5482 if Scope (Entity (N)) /= Standard_Standard then
5483 T := Etype (First_Entity (Entity (N)));
5486 T := Find_Unique_Type (L, R);
5488 if T = Any_Fixed then
5489 T := Unique_Fixed_Point_Type (L);
5493 Set_Etype (N, Base_Type (Typ));
5494 Generate_Reference (T, N, ' ');
5496 if T /= Any_Type then
5497 if T = Any_String or else
5498 T = Any_Composite or else
5501 if T = Any_Character then
5502 Ambiguous_Character (L);
5504 Error_Msg_N ("ambiguous operands for comparison", N);
5507 Set_Etype (N, Any_Type);
5513 Check_Unset_Reference (L);
5514 Check_Unset_Reference (R);
5515 Generate_Operator_Reference (N, T);
5516 Check_Low_Bound_Tested (N);
5517 Eval_Relational_Op (N);
5520 end Resolve_Comparison_Op;
5522 ------------------------------------
5523 -- Resolve_Conditional_Expression --
5524 ------------------------------------
5526 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
5527 Condition : constant Node_Id := First (Expressions (N));
5528 Then_Expr : constant Node_Id := Next (Condition);
5529 Else_Expr : Node_Id := Next (Then_Expr);
5532 Resolve (Condition, Any_Boolean);
5533 Resolve (Then_Expr, Typ);
5535 -- If ELSE expression present, just resolve using the determined type
5537 if Present (Else_Expr) then
5538 Resolve (Else_Expr, Typ);
5540 -- If no ELSE expression is present, root type must be Standard.Boolean
5541 -- and we provide a Standard.True result converted to the appropriate
5542 -- Boolean type (in case it is a derived boolean type).
5544 elsif Root_Type (Typ) = Standard_Boolean then
5546 Convert_To (Typ, New_Occurrence_Of (Standard_True, Sloc (N)));
5547 Analyze_And_Resolve (Else_Expr, Typ);
5548 Append_To (Expressions (N), Else_Expr);
5551 Error_Msg_N ("can only omit ELSE expression in Boolean case", N);
5552 Append_To (Expressions (N), Error);
5556 Eval_Conditional_Expression (N);
5557 end Resolve_Conditional_Expression;
5559 -----------------------------------------
5560 -- Resolve_Discrete_Subtype_Indication --
5561 -----------------------------------------
5563 procedure Resolve_Discrete_Subtype_Indication
5571 Analyze (Subtype_Mark (N));
5572 S := Entity (Subtype_Mark (N));
5574 if Nkind (Constraint (N)) /= N_Range_Constraint then
5575 Error_Msg_N ("expect range constraint for discrete type", N);
5576 Set_Etype (N, Any_Type);
5579 R := Range_Expression (Constraint (N));
5587 if Base_Type (S) /= Base_Type (Typ) then
5589 ("expect subtype of }", N, First_Subtype (Typ));
5591 -- Rewrite the constraint as a range of Typ
5592 -- to allow compilation to proceed further.
5595 Rewrite (Low_Bound (R),
5596 Make_Attribute_Reference (Sloc (Low_Bound (R)),
5597 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5598 Attribute_Name => Name_First));
5599 Rewrite (High_Bound (R),
5600 Make_Attribute_Reference (Sloc (High_Bound (R)),
5601 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5602 Attribute_Name => Name_First));
5606 Set_Etype (N, Etype (R));
5608 -- Additionally, we must check that the bounds are compatible
5609 -- with the given subtype, which might be different from the
5610 -- type of the context.
5612 Apply_Range_Check (R, S);
5614 -- ??? If the above check statically detects a Constraint_Error
5615 -- it replaces the offending bound(s) of the range R with a
5616 -- Constraint_Error node. When the itype which uses these bounds
5617 -- is frozen the resulting call to Duplicate_Subexpr generates
5618 -- a new temporary for the bounds.
5620 -- Unfortunately there are other itypes that are also made depend
5621 -- on these bounds, so when Duplicate_Subexpr is called they get
5622 -- a forward reference to the newly created temporaries and Gigi
5623 -- aborts on such forward references. This is probably sign of a
5624 -- more fundamental problem somewhere else in either the order of
5625 -- itype freezing or the way certain itypes are constructed.
5627 -- To get around this problem we call Remove_Side_Effects right
5628 -- away if either bounds of R are a Constraint_Error.
5631 L : constant Node_Id := Low_Bound (R);
5632 H : constant Node_Id := High_Bound (R);
5635 if Nkind (L) = N_Raise_Constraint_Error then
5636 Remove_Side_Effects (L);
5639 if Nkind (H) = N_Raise_Constraint_Error then
5640 Remove_Side_Effects (H);
5644 Check_Unset_Reference (Low_Bound (R));
5645 Check_Unset_Reference (High_Bound (R));
5648 end Resolve_Discrete_Subtype_Indication;
5650 -------------------------
5651 -- Resolve_Entity_Name --
5652 -------------------------
5654 -- Used to resolve identifiers and expanded names
5656 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
5657 E : constant Entity_Id := Entity (N);
5660 -- If garbage from errors, set to Any_Type and return
5662 if No (E) and then Total_Errors_Detected /= 0 then
5663 Set_Etype (N, Any_Type);
5667 -- Replace named numbers by corresponding literals. Note that this is
5668 -- the one case where Resolve_Entity_Name must reset the Etype, since
5669 -- it is currently marked as universal.
5671 if Ekind (E) = E_Named_Integer then
5673 Eval_Named_Integer (N);
5675 elsif Ekind (E) = E_Named_Real then
5677 Eval_Named_Real (N);
5679 -- Allow use of subtype only if it is a concurrent type where we are
5680 -- currently inside the body. This will eventually be expanded into a
5681 -- call to Self (for tasks) or _object (for protected objects). Any
5682 -- other use of a subtype is invalid.
5684 elsif Is_Type (E) then
5685 if Is_Concurrent_Type (E)
5686 and then In_Open_Scopes (E)
5691 ("invalid use of subtype mark in expression or call", N);
5694 -- Check discriminant use if entity is discriminant in current scope,
5695 -- i.e. discriminant of record or concurrent type currently being
5696 -- analyzed. Uses in corresponding body are unrestricted.
5698 elsif Ekind (E) = E_Discriminant
5699 and then Scope (E) = Current_Scope
5700 and then not Has_Completion (Current_Scope)
5702 Check_Discriminant_Use (N);
5704 -- A parameterless generic function cannot appear in a context that
5705 -- requires resolution.
5707 elsif Ekind (E) = E_Generic_Function then
5708 Error_Msg_N ("illegal use of generic function", N);
5710 elsif Ekind (E) = E_Out_Parameter
5711 and then Ada_Version = Ada_83
5712 and then (Nkind (Parent (N)) in N_Op
5713 or else (Nkind (Parent (N)) = N_Assignment_Statement
5714 and then N = Expression (Parent (N)))
5715 or else Nkind (Parent (N)) = N_Explicit_Dereference)
5717 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
5719 -- In all other cases, just do the possible static evaluation
5722 -- A deferred constant that appears in an expression must have a
5723 -- completion, unless it has been removed by in-place expansion of
5726 if Ekind (E) = E_Constant
5727 and then Comes_From_Source (E)
5728 and then No (Constant_Value (E))
5729 and then Is_Frozen (Etype (E))
5730 and then not In_Spec_Expression
5731 and then not Is_Imported (E)
5734 if No_Initialization (Parent (E))
5735 or else (Present (Full_View (E))
5736 and then No_Initialization (Parent (Full_View (E))))
5741 "deferred constant is frozen before completion", N);
5745 Eval_Entity_Name (N);
5747 end Resolve_Entity_Name;
5753 procedure Resolve_Entry (Entry_Name : Node_Id) is
5754 Loc : constant Source_Ptr := Sloc (Entry_Name);
5762 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
5763 -- If the bounds of the entry family being called depend on task
5764 -- discriminants, build a new index subtype where a discriminant is
5765 -- replaced with the value of the discriminant of the target task.
5766 -- The target task is the prefix of the entry name in the call.
5768 -----------------------
5769 -- Actual_Index_Type --
5770 -----------------------
5772 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
5773 Typ : constant Entity_Id := Entry_Index_Type (E);
5774 Tsk : constant Entity_Id := Scope (E);
5775 Lo : constant Node_Id := Type_Low_Bound (Typ);
5776 Hi : constant Node_Id := Type_High_Bound (Typ);
5779 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
5780 -- If the bound is given by a discriminant, replace with a reference
5781 -- to the discriminant of the same name in the target task. If the
5782 -- entry name is the target of a requeue statement and the entry is
5783 -- in the current protected object, the bound to be used is the
5784 -- discriminal of the object (see apply_range_checks for details of
5785 -- the transformation).
5787 -----------------------------
5788 -- Actual_Discriminant_Ref --
5789 -----------------------------
5791 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
5792 Typ : constant Entity_Id := Etype (Bound);
5796 Remove_Side_Effects (Bound);
5798 if not Is_Entity_Name (Bound)
5799 or else Ekind (Entity (Bound)) /= E_Discriminant
5803 elsif Is_Protected_Type (Tsk)
5804 and then In_Open_Scopes (Tsk)
5805 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
5807 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
5811 Make_Selected_Component (Loc,
5812 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
5813 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
5818 end Actual_Discriminant_Ref;
5820 -- Start of processing for Actual_Index_Type
5823 if not Has_Discriminants (Tsk)
5824 or else (not Is_Entity_Name (Lo)
5826 not Is_Entity_Name (Hi))
5828 return Entry_Index_Type (E);
5831 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
5832 Set_Etype (New_T, Base_Type (Typ));
5833 Set_Size_Info (New_T, Typ);
5834 Set_RM_Size (New_T, RM_Size (Typ));
5835 Set_Scalar_Range (New_T,
5836 Make_Range (Sloc (Entry_Name),
5837 Low_Bound => Actual_Discriminant_Ref (Lo),
5838 High_Bound => Actual_Discriminant_Ref (Hi)));
5842 end Actual_Index_Type;
5844 -- Start of processing of Resolve_Entry
5847 -- Find name of entry being called, and resolve prefix of name
5848 -- with its own type. The prefix can be overloaded, and the name
5849 -- and signature of the entry must be taken into account.
5851 if Nkind (Entry_Name) = N_Indexed_Component then
5853 -- Case of dealing with entry family within the current tasks
5855 E_Name := Prefix (Entry_Name);
5858 E_Name := Entry_Name;
5861 if Is_Entity_Name (E_Name) then
5863 -- Entry call to an entry (or entry family) in the current task. This
5864 -- is legal even though the task will deadlock. Rewrite as call to
5867 -- This can also be a call to an entry in an enclosing task. If this
5868 -- is a single task, we have to retrieve its name, because the scope
5869 -- of the entry is the task type, not the object. If the enclosing
5870 -- task is a task type, the identity of the task is given by its own
5873 -- Finally this can be a requeue on an entry of the same task or
5874 -- protected object.
5876 S := Scope (Entity (E_Name));
5878 for J in reverse 0 .. Scope_Stack.Last loop
5879 if Is_Task_Type (Scope_Stack.Table (J).Entity)
5880 and then not Comes_From_Source (S)
5882 -- S is an enclosing task or protected object. The concurrent
5883 -- declaration has been converted into a type declaration, and
5884 -- the object itself has an object declaration that follows
5885 -- the type in the same declarative part.
5887 Tsk := Next_Entity (S);
5888 while Etype (Tsk) /= S loop
5895 elsif S = Scope_Stack.Table (J).Entity then
5897 -- Call to current task. Will be transformed into call to Self
5905 Make_Selected_Component (Loc,
5906 Prefix => New_Occurrence_Of (S, Loc),
5908 New_Occurrence_Of (Entity (E_Name), Loc));
5909 Rewrite (E_Name, New_N);
5912 elsif Nkind (Entry_Name) = N_Selected_Component
5913 and then Is_Overloaded (Prefix (Entry_Name))
5915 -- Use the entry name (which must be unique at this point) to find
5916 -- the prefix that returns the corresponding task type or protected
5920 Pref : constant Node_Id := Prefix (Entry_Name);
5921 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
5926 Get_First_Interp (Pref, I, It);
5927 while Present (It.Typ) loop
5928 if Scope (Ent) = It.Typ then
5929 Set_Etype (Pref, It.Typ);
5933 Get_Next_Interp (I, It);
5938 if Nkind (Entry_Name) = N_Selected_Component then
5939 Resolve (Prefix (Entry_Name));
5941 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
5942 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
5943 Resolve (Prefix (Prefix (Entry_Name)));
5944 Index := First (Expressions (Entry_Name));
5945 Resolve (Index, Entry_Index_Type (Nam));
5947 -- Up to this point the expression could have been the actual in a
5948 -- simple entry call, and be given by a named association.
5950 if Nkind (Index) = N_Parameter_Association then
5951 Error_Msg_N ("expect expression for entry index", Index);
5953 Apply_Range_Check (Index, Actual_Index_Type (Nam));
5958 ------------------------
5959 -- Resolve_Entry_Call --
5960 ------------------------
5962 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
5963 Entry_Name : constant Node_Id := Name (N);
5964 Loc : constant Source_Ptr := Sloc (Entry_Name);
5966 First_Named : Node_Id;
5973 -- We kill all checks here, because it does not seem worth the effort to
5974 -- do anything better, an entry call is a big operation.
5978 -- Processing of the name is similar for entry calls and protected
5979 -- operation calls. Once the entity is determined, we can complete
5980 -- the resolution of the actuals.
5982 -- The selector may be overloaded, in the case of a protected object
5983 -- with overloaded functions. The type of the context is used for
5986 if Nkind (Entry_Name) = N_Selected_Component
5987 and then Is_Overloaded (Selector_Name (Entry_Name))
5988 and then Typ /= Standard_Void_Type
5995 Get_First_Interp (Selector_Name (Entry_Name), I, It);
5996 while Present (It.Typ) loop
5997 if Covers (Typ, It.Typ) then
5998 Set_Entity (Selector_Name (Entry_Name), It.Nam);
5999 Set_Etype (Entry_Name, It.Typ);
6001 Generate_Reference (It.Typ, N, ' ');
6004 Get_Next_Interp (I, It);
6009 Resolve_Entry (Entry_Name);
6011 if Nkind (Entry_Name) = N_Selected_Component then
6013 -- Simple entry call
6015 Nam := Entity (Selector_Name (Entry_Name));
6016 Obj := Prefix (Entry_Name);
6017 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
6019 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6021 -- Call to member of entry family
6023 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6024 Obj := Prefix (Prefix (Entry_Name));
6025 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
6028 -- We cannot in general check the maximum depth of protected entry
6029 -- calls at compile time. But we can tell that any protected entry
6030 -- call at all violates a specified nesting depth of zero.
6032 if Is_Protected_Type (Scope (Nam)) then
6033 Check_Restriction (Max_Entry_Queue_Length, N);
6036 -- Use context type to disambiguate a protected function that can be
6037 -- called without actuals and that returns an array type, and where
6038 -- the argument list may be an indexing of the returned value.
6040 if Ekind (Nam) = E_Function
6041 and then Needs_No_Actuals (Nam)
6042 and then Present (Parameter_Associations (N))
6044 ((Is_Array_Type (Etype (Nam))
6045 and then Covers (Typ, Component_Type (Etype (Nam))))
6047 or else (Is_Access_Type (Etype (Nam))
6048 and then Is_Array_Type (Designated_Type (Etype (Nam)))
6049 and then Covers (Typ,
6050 Component_Type (Designated_Type (Etype (Nam))))))
6053 Index_Node : Node_Id;
6057 Make_Indexed_Component (Loc,
6059 Make_Function_Call (Loc,
6060 Name => Relocate_Node (Entry_Name)),
6061 Expressions => Parameter_Associations (N));
6063 -- Since we are correcting a node classification error made by
6064 -- the parser, we call Replace rather than Rewrite.
6066 Replace (N, Index_Node);
6067 Set_Etype (Prefix (N), Etype (Nam));
6069 Resolve_Indexed_Component (N, Typ);
6074 -- The operation name may have been overloaded. Order the actuals
6075 -- according to the formals of the resolved entity, and set the
6076 -- return type to that of the operation.
6079 Normalize_Actuals (N, Nam, False, Norm_OK);
6080 pragma Assert (Norm_OK);
6081 Set_Etype (N, Etype (Nam));
6084 Resolve_Actuals (N, Nam);
6085 Generate_Reference (Nam, Entry_Name);
6087 if Ekind (Nam) = E_Entry
6088 or else Ekind (Nam) = E_Entry_Family
6090 Check_Potentially_Blocking_Operation (N);
6093 -- Verify that a procedure call cannot masquerade as an entry
6094 -- call where an entry call is expected.
6096 if Ekind (Nam) = E_Procedure then
6097 if Nkind (Parent (N)) = N_Entry_Call_Alternative
6098 and then N = Entry_Call_Statement (Parent (N))
6100 Error_Msg_N ("entry call required in select statement", N);
6102 elsif Nkind (Parent (N)) = N_Triggering_Alternative
6103 and then N = Triggering_Statement (Parent (N))
6105 Error_Msg_N ("triggering statement cannot be procedure call", N);
6107 elsif Ekind (Scope (Nam)) = E_Task_Type
6108 and then not In_Open_Scopes (Scope (Nam))
6110 Error_Msg_N ("task has no entry with this name", Entry_Name);
6114 -- After resolution, entry calls and protected procedure calls are
6115 -- changed into entry calls, for expansion. The structure of the node
6116 -- does not change, so it can safely be done in place. Protected
6117 -- function calls must keep their structure because they are
6120 if Ekind (Nam) /= E_Function then
6122 -- A protected operation that is not a function may modify the
6123 -- corresponding object, and cannot apply to a constant. If this
6124 -- is an internal call, the prefix is the type itself.
6126 if Is_Protected_Type (Scope (Nam))
6127 and then not Is_Variable (Obj)
6128 and then (not Is_Entity_Name (Obj)
6129 or else not Is_Type (Entity (Obj)))
6132 ("prefix of protected procedure or entry call must be variable",
6136 Actuals := Parameter_Associations (N);
6137 First_Named := First_Named_Actual (N);
6140 Make_Entry_Call_Statement (Loc,
6142 Parameter_Associations => Actuals));
6144 Set_First_Named_Actual (N, First_Named);
6145 Set_Analyzed (N, True);
6147 -- Protected functions can return on the secondary stack, in which
6148 -- case we must trigger the transient scope mechanism.
6150 elsif Expander_Active
6151 and then Requires_Transient_Scope (Etype (Nam))
6153 Establish_Transient_Scope (N, Sec_Stack => True);
6155 end Resolve_Entry_Call;
6157 -------------------------
6158 -- Resolve_Equality_Op --
6159 -------------------------
6161 -- Both arguments must have the same type, and the boolean context does
6162 -- not participate in the resolution. The first pass verifies that the
6163 -- interpretation is not ambiguous, and the type of the left argument is
6164 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6165 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6166 -- though they carry a single (universal) type. Diagnose this case here.
6168 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6169 L : constant Node_Id := Left_Opnd (N);
6170 R : constant Node_Id := Right_Opnd (N);
6171 T : Entity_Id := Find_Unique_Type (L, R);
6173 function Find_Unique_Access_Type return Entity_Id;
6174 -- In the case of allocators, make a last-ditch attempt to find a single
6175 -- access type with the right designated type. This is semantically
6176 -- dubious, and of no interest to any real code, but c48008a makes it
6179 -----------------------------
6180 -- Find_Unique_Access_Type --
6181 -----------------------------
6183 function Find_Unique_Access_Type return Entity_Id is
6189 if Ekind (Etype (R)) = E_Allocator_Type then
6190 Acc := Designated_Type (Etype (R));
6191 elsif Ekind (Etype (L)) = E_Allocator_Type then
6192 Acc := Designated_Type (Etype (L));
6198 while S /= Standard_Standard loop
6199 E := First_Entity (S);
6200 while Present (E) loop
6202 and then Is_Access_Type (E)
6203 and then Ekind (E) /= E_Allocator_Type
6204 and then Designated_Type (E) = Base_Type (Acc)
6216 end Find_Unique_Access_Type;
6218 -- Start of processing for Resolve_Equality_Op
6221 Check_No_Direct_Boolean_Operators (N);
6223 Set_Etype (N, Base_Type (Typ));
6224 Generate_Reference (T, N, ' ');
6226 if T = Any_Fixed then
6227 T := Unique_Fixed_Point_Type (L);
6230 if T /= Any_Type then
6232 or else T = Any_Composite
6233 or else T = Any_Character
6235 if T = Any_Character then
6236 Ambiguous_Character (L);
6238 Error_Msg_N ("ambiguous operands for equality", N);
6241 Set_Etype (N, Any_Type);
6244 elsif T = Any_Access
6245 or else Ekind (T) = E_Allocator_Type
6246 or else Ekind (T) = E_Access_Attribute_Type
6248 T := Find_Unique_Access_Type;
6251 Error_Msg_N ("ambiguous operands for equality", N);
6252 Set_Etype (N, Any_Type);
6260 -- If the unique type is a class-wide type then it will be expanded
6261 -- into a dispatching call to the predefined primitive. Therefore we
6262 -- check here for potential violation of such restriction.
6264 if Is_Class_Wide_Type (T) then
6265 Check_Restriction (No_Dispatching_Calls, N);
6268 if Warn_On_Redundant_Constructs
6269 and then Comes_From_Source (N)
6270 and then Is_Entity_Name (R)
6271 and then Entity (R) = Standard_True
6272 and then Comes_From_Source (R)
6274 Error_Msg_N ("?comparison with True is redundant!", R);
6277 Check_Unset_Reference (L);
6278 Check_Unset_Reference (R);
6279 Generate_Operator_Reference (N, T);
6280 Check_Low_Bound_Tested (N);
6282 -- If this is an inequality, it may be the implicit inequality
6283 -- created for a user-defined operation, in which case the corres-
6284 -- ponding equality operation is not intrinsic, and the operation
6285 -- cannot be constant-folded. Else fold.
6287 if Nkind (N) = N_Op_Eq
6288 or else Comes_From_Source (Entity (N))
6289 or else Ekind (Entity (N)) = E_Operator
6290 or else Is_Intrinsic_Subprogram
6291 (Corresponding_Equality (Entity (N)))
6293 Eval_Relational_Op (N);
6295 elsif Nkind (N) = N_Op_Ne
6296 and then Is_Abstract_Subprogram (Entity (N))
6298 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6301 -- Ada 2005: If one operand is an anonymous access type, convert the
6302 -- other operand to it, to ensure that the underlying types match in
6303 -- the back-end. Same for access_to_subprogram, and the conversion
6304 -- verifies that the types are subtype conformant.
6306 -- We apply the same conversion in the case one of the operands is a
6307 -- private subtype of the type of the other.
6309 -- Why the Expander_Active test here ???
6313 (Ekind (T) = E_Anonymous_Access_Type
6314 or else Ekind (T) = E_Anonymous_Access_Subprogram_Type
6315 or else Is_Private_Type (T))
6317 if Etype (L) /= T then
6319 Make_Unchecked_Type_Conversion (Sloc (L),
6320 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6321 Expression => Relocate_Node (L)));
6322 Analyze_And_Resolve (L, T);
6325 if (Etype (R)) /= T then
6327 Make_Unchecked_Type_Conversion (Sloc (R),
6328 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6329 Expression => Relocate_Node (R)));
6330 Analyze_And_Resolve (R, T);
6334 end Resolve_Equality_Op;
6336 ----------------------------------
6337 -- Resolve_Explicit_Dereference --
6338 ----------------------------------
6340 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6341 Loc : constant Source_Ptr := Sloc (N);
6343 P : constant Node_Id := Prefix (N);
6348 Check_Fully_Declared_Prefix (Typ, P);
6350 if Is_Overloaded (P) then
6352 -- Use the context type to select the prefix that has the correct
6355 Get_First_Interp (P, I, It);
6356 while Present (It.Typ) loop
6357 exit when Is_Access_Type (It.Typ)
6358 and then Covers (Typ, Designated_Type (It.Typ));
6359 Get_Next_Interp (I, It);
6362 if Present (It.Typ) then
6363 Resolve (P, It.Typ);
6365 -- If no interpretation covers the designated type of the prefix,
6366 -- this is the pathological case where not all implementations of
6367 -- the prefix allow the interpretation of the node as a call. Now
6368 -- that the expected type is known, Remove other interpretations
6369 -- from prefix, rewrite it as a call, and resolve again, so that
6370 -- the proper call node is generated.
6372 Get_First_Interp (P, I, It);
6373 while Present (It.Typ) loop
6374 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6378 Get_Next_Interp (I, It);
6382 Make_Function_Call (Loc,
6384 Make_Explicit_Dereference (Loc,
6386 Parameter_Associations => New_List);
6388 Save_Interps (N, New_N);
6390 Analyze_And_Resolve (N, Typ);
6394 Set_Etype (N, Designated_Type (It.Typ));
6400 if Is_Access_Type (Etype (P)) then
6401 Apply_Access_Check (N);
6404 -- If the designated type is a packed unconstrained array type, and the
6405 -- explicit dereference is not in the context of an attribute reference,
6406 -- then we must compute and set the actual subtype, since it is needed
6407 -- by Gigi. The reason we exclude the attribute case is that this is
6408 -- handled fine by Gigi, and in fact we use such attributes to build the
6409 -- actual subtype. We also exclude generated code (which builds actual
6410 -- subtypes directly if they are needed).
6412 if Is_Array_Type (Etype (N))
6413 and then Is_Packed (Etype (N))
6414 and then not Is_Constrained (Etype (N))
6415 and then Nkind (Parent (N)) /= N_Attribute_Reference
6416 and then Comes_From_Source (N)
6418 Set_Etype (N, Get_Actual_Subtype (N));
6421 -- Note: there is no Eval processing required for an explicit deference,
6422 -- because the type is known to be an allocators, and allocator
6423 -- expressions can never be static.
6425 end Resolve_Explicit_Dereference;
6427 -------------------------------
6428 -- Resolve_Indexed_Component --
6429 -------------------------------
6431 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
6432 Name : constant Node_Id := Prefix (N);
6434 Array_Type : Entity_Id := Empty; -- to prevent junk warning
6438 if Is_Overloaded (Name) then
6440 -- Use the context type to select the prefix that yields the correct
6446 I1 : Interp_Index := 0;
6447 P : constant Node_Id := Prefix (N);
6448 Found : Boolean := False;
6451 Get_First_Interp (P, I, It);
6452 while Present (It.Typ) loop
6453 if (Is_Array_Type (It.Typ)
6454 and then Covers (Typ, Component_Type (It.Typ)))
6455 or else (Is_Access_Type (It.Typ)
6456 and then Is_Array_Type (Designated_Type (It.Typ))
6458 (Typ, Component_Type (Designated_Type (It.Typ))))
6461 It := Disambiguate (P, I1, I, Any_Type);
6463 if It = No_Interp then
6464 Error_Msg_N ("ambiguous prefix for indexing", N);
6470 Array_Type := It.Typ;
6476 Array_Type := It.Typ;
6481 Get_Next_Interp (I, It);
6486 Array_Type := Etype (Name);
6489 Resolve (Name, Array_Type);
6490 Array_Type := Get_Actual_Subtype_If_Available (Name);
6492 -- If prefix is access type, dereference to get real array type.
6493 -- Note: we do not apply an access check because the expander always
6494 -- introduces an explicit dereference, and the check will happen there.
6496 if Is_Access_Type (Array_Type) then
6497 Array_Type := Designated_Type (Array_Type);
6500 -- If name was overloaded, set component type correctly now
6501 -- If a misplaced call to an entry family (which has no index types)
6502 -- return. Error will be diagnosed from calling context.
6504 if Is_Array_Type (Array_Type) then
6505 Set_Etype (N, Component_Type (Array_Type));
6510 Index := First_Index (Array_Type);
6511 Expr := First (Expressions (N));
6513 -- The prefix may have resolved to a string literal, in which case its
6514 -- etype has a special representation. This is only possible currently
6515 -- if the prefix is a static concatenation, written in functional
6518 if Ekind (Array_Type) = E_String_Literal_Subtype then
6519 Resolve (Expr, Standard_Positive);
6522 while Present (Index) and Present (Expr) loop
6523 Resolve (Expr, Etype (Index));
6524 Check_Unset_Reference (Expr);
6526 if Is_Scalar_Type (Etype (Expr)) then
6527 Apply_Scalar_Range_Check (Expr, Etype (Index));
6529 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
6537 -- Do not generate the warning on suspicious index if we are analyzing
6538 -- package Ada.Tags; otherwise we will report the warning with the
6539 -- Prims_Ptr field of the dispatch table.
6541 if Scope (Etype (Prefix (N))) = Standard_Standard
6543 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
6546 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
6547 Eval_Indexed_Component (N);
6549 end Resolve_Indexed_Component;
6551 -----------------------------
6552 -- Resolve_Integer_Literal --
6553 -----------------------------
6555 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
6558 Eval_Integer_Literal (N);
6559 end Resolve_Integer_Literal;
6561 --------------------------------
6562 -- Resolve_Intrinsic_Operator --
6563 --------------------------------
6565 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
6566 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6573 while Scope (Op) /= Standard_Standard loop
6575 pragma Assert (Present (Op));
6579 Set_Is_Overloaded (N, False);
6581 -- If the operand type is private, rewrite with suitable conversions on
6582 -- the operands and the result, to expose the proper underlying numeric
6585 if Is_Private_Type (Typ) then
6586 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
6588 if Nkind (N) = N_Op_Expon then
6589 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
6591 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6594 Save_Interps (Left_Opnd (N), Expression (Arg1));
6595 Save_Interps (Right_Opnd (N), Expression (Arg2));
6597 Set_Left_Opnd (N, Arg1);
6598 Set_Right_Opnd (N, Arg2);
6600 Set_Etype (N, Btyp);
6601 Rewrite (N, Unchecked_Convert_To (Typ, N));
6604 elsif Typ /= Etype (Left_Opnd (N))
6605 or else Typ /= Etype (Right_Opnd (N))
6607 -- Add explicit conversion where needed, and save interpretations in
6608 -- case operands are overloaded.
6610 Arg1 := Convert_To (Typ, Left_Opnd (N));
6611 Arg2 := Convert_To (Typ, Right_Opnd (N));
6613 if Nkind (Arg1) = N_Type_Conversion then
6614 Save_Interps (Left_Opnd (N), Expression (Arg1));
6616 Save_Interps (Left_Opnd (N), Arg1);
6619 if Nkind (Arg2) = N_Type_Conversion then
6620 Save_Interps (Right_Opnd (N), Expression (Arg2));
6622 Save_Interps (Right_Opnd (N), Arg2);
6625 Rewrite (Left_Opnd (N), Arg1);
6626 Rewrite (Right_Opnd (N), Arg2);
6629 Resolve_Arithmetic_Op (N, Typ);
6632 Resolve_Arithmetic_Op (N, Typ);
6634 end Resolve_Intrinsic_Operator;
6636 --------------------------------------
6637 -- Resolve_Intrinsic_Unary_Operator --
6638 --------------------------------------
6640 procedure Resolve_Intrinsic_Unary_Operator
6644 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6650 while Scope (Op) /= Standard_Standard loop
6652 pragma Assert (Present (Op));
6657 if Is_Private_Type (Typ) then
6658 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6659 Save_Interps (Right_Opnd (N), Expression (Arg2));
6661 Set_Right_Opnd (N, Arg2);
6663 Set_Etype (N, Btyp);
6664 Rewrite (N, Unchecked_Convert_To (Typ, N));
6668 Resolve_Unary_Op (N, Typ);
6670 end Resolve_Intrinsic_Unary_Operator;
6672 ------------------------
6673 -- Resolve_Logical_Op --
6674 ------------------------
6676 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
6680 Check_No_Direct_Boolean_Operators (N);
6682 -- Predefined operations on scalar types yield the base type. On the
6683 -- other hand, logical operations on arrays yield the type of the
6684 -- arguments (and the context).
6686 if Is_Array_Type (Typ) then
6689 B_Typ := Base_Type (Typ);
6692 -- The following test is required because the operands of the operation
6693 -- may be literals, in which case the resulting type appears to be
6694 -- compatible with a signed integer type, when in fact it is compatible
6695 -- only with modular types. If the context itself is universal, the
6696 -- operation is illegal.
6698 if not Valid_Boolean_Arg (Typ) then
6699 Error_Msg_N ("invalid context for logical operation", N);
6700 Set_Etype (N, Any_Type);
6703 elsif Typ = Any_Modular then
6705 ("no modular type available in this context", N);
6706 Set_Etype (N, Any_Type);
6708 elsif Is_Modular_Integer_Type (Typ)
6709 and then Etype (Left_Opnd (N)) = Universal_Integer
6710 and then Etype (Right_Opnd (N)) = Universal_Integer
6712 Check_For_Visible_Operator (N, B_Typ);
6715 Resolve (Left_Opnd (N), B_Typ);
6716 Resolve (Right_Opnd (N), B_Typ);
6718 Check_Unset_Reference (Left_Opnd (N));
6719 Check_Unset_Reference (Right_Opnd (N));
6721 Set_Etype (N, B_Typ);
6722 Generate_Operator_Reference (N, B_Typ);
6723 Eval_Logical_Op (N);
6724 end Resolve_Logical_Op;
6726 ---------------------------
6727 -- Resolve_Membership_Op --
6728 ---------------------------
6730 -- The context can only be a boolean type, and does not determine
6731 -- the arguments. Arguments should be unambiguous, but the preference
6732 -- rule for universal types applies.
6734 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
6735 pragma Warnings (Off, Typ);
6737 L : constant Node_Id := Left_Opnd (N);
6738 R : constant Node_Id := Right_Opnd (N);
6742 if L = Error or else R = Error then
6746 if not Is_Overloaded (R)
6748 (Etype (R) = Universal_Integer or else
6749 Etype (R) = Universal_Real)
6750 and then Is_Overloaded (L)
6754 -- Ada 2005 (AI-251): Support the following case:
6756 -- type I is interface;
6757 -- type T is tagged ...
6759 -- function Test (O : I'Class) is
6761 -- return O in T'Class.
6764 -- In this case we have nothing else to do. The membership test will be
6765 -- done at run-time.
6767 elsif Ada_Version >= Ada_05
6768 and then Is_Class_Wide_Type (Etype (L))
6769 and then Is_Interface (Etype (L))
6770 and then Is_Class_Wide_Type (Etype (R))
6771 and then not Is_Interface (Etype (R))
6776 T := Intersect_Types (L, R);
6780 Check_Unset_Reference (L);
6782 if Nkind (R) = N_Range
6783 and then not Is_Scalar_Type (T)
6785 Error_Msg_N ("scalar type required for range", R);
6788 if Is_Entity_Name (R) then
6789 Freeze_Expression (R);
6792 Check_Unset_Reference (R);
6795 Eval_Membership_Op (N);
6796 end Resolve_Membership_Op;
6802 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
6803 Loc : constant Source_Ptr := Sloc (N);
6806 -- Handle restriction against anonymous null access values This
6807 -- restriction can be turned off using -gnatdj.
6809 -- Ada 2005 (AI-231): Remove restriction
6811 if Ada_Version < Ada_05
6812 and then not Debug_Flag_J
6813 and then Ekind (Typ) = E_Anonymous_Access_Type
6814 and then Comes_From_Source (N)
6816 -- In the common case of a call which uses an explicitly null value
6817 -- for an access parameter, give specialized error message.
6819 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
6823 ("null is not allowed as argument for an access parameter", N);
6825 -- Standard message for all other cases (are there any?)
6829 ("null cannot be of an anonymous access type", N);
6833 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
6834 -- assignment to a null-excluding object
6836 if Ada_Version >= Ada_05
6837 and then Can_Never_Be_Null (Typ)
6838 and then Nkind (Parent (N)) = N_Assignment_Statement
6840 if not Inside_Init_Proc then
6842 (Compile_Time_Constraint_Error (N,
6843 "(Ada 2005) null not allowed in null-excluding objects?"),
6844 Make_Raise_Constraint_Error (Loc,
6845 Reason => CE_Access_Check_Failed));
6848 Make_Raise_Constraint_Error (Loc,
6849 Reason => CE_Access_Check_Failed));
6853 -- In a distributed context, null for a remote access to subprogram may
6854 -- need to be replaced with a special record aggregate. In this case,
6855 -- return after having done the transformation.
6857 if (Ekind (Typ) = E_Record_Type
6858 or else Is_Remote_Access_To_Subprogram_Type (Typ))
6859 and then Remote_AST_Null_Value (N, Typ)
6864 -- The null literal takes its type from the context
6869 -----------------------
6870 -- Resolve_Op_Concat --
6871 -----------------------
6873 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
6875 -- We wish to avoid deep recursion, because concatenations are often
6876 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
6877 -- operands nonrecursively until we find something that is not a simple
6878 -- concatenation (A in this case). We resolve that, and then walk back
6879 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
6880 -- to do the rest of the work at each level. The Parent pointers allow
6881 -- us to avoid recursion, and thus avoid running out of memory. See also
6882 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
6888 -- The following code is equivalent to:
6890 -- Resolve_Op_Concat_First (NN, Typ);
6891 -- Resolve_Op_Concat_Arg (N, ...);
6892 -- Resolve_Op_Concat_Rest (N, Typ);
6894 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
6895 -- operand is a concatenation.
6897 -- Walk down left operands
6900 Resolve_Op_Concat_First (NN, Typ);
6901 Op1 := Left_Opnd (NN);
6902 exit when not (Nkind (Op1) = N_Op_Concat
6903 and then not Is_Array_Type (Component_Type (Typ))
6904 and then Entity (Op1) = Entity (NN));
6908 -- Now (given the above example) NN is A&B and Op1 is A
6910 -- First resolve Op1 ...
6912 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
6914 -- ... then walk NN back up until we reach N (where we started), calling
6915 -- Resolve_Op_Concat_Rest along the way.
6918 Resolve_Op_Concat_Rest (NN, Typ);
6922 end Resolve_Op_Concat;
6924 ---------------------------
6925 -- Resolve_Op_Concat_Arg --
6926 ---------------------------
6928 procedure Resolve_Op_Concat_Arg
6934 Btyp : constant Entity_Id := Base_Type (Typ);
6939 or else (not Is_Overloaded (Arg)
6940 and then Etype (Arg) /= Any_Composite
6941 and then Covers (Component_Type (Typ), Etype (Arg)))
6943 Resolve (Arg, Component_Type (Typ));
6945 Resolve (Arg, Btyp);
6948 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
6949 if Nkind (Arg) = N_Aggregate
6950 and then Is_Composite_Type (Component_Type (Typ))
6952 if Is_Private_Type (Component_Type (Typ)) then
6953 Resolve (Arg, Btyp);
6955 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
6956 Set_Etype (Arg, Any_Type);
6960 if Is_Overloaded (Arg)
6961 and then Has_Compatible_Type (Arg, Typ)
6962 and then Etype (Arg) /= Any_Type
6970 Get_First_Interp (Arg, I, It);
6972 Get_Next_Interp (I, It);
6974 -- Special-case the error message when the overloading is
6975 -- caused by a function that yields an array and can be
6976 -- called without parameters.
6978 if It.Nam = Func then
6979 Error_Msg_Sloc := Sloc (Func);
6980 Error_Msg_N ("ambiguous call to function#", Arg);
6982 ("\\interpretation as call yields&", Arg, Typ);
6984 ("\\interpretation as indexing of call yields&",
6985 Arg, Component_Type (Typ));
6989 ("ambiguous operand for concatenation!", Arg);
6990 Get_First_Interp (Arg, I, It);
6991 while Present (It.Nam) loop
6992 Error_Msg_Sloc := Sloc (It.Nam);
6994 if Base_Type (It.Typ) = Base_Type (Typ)
6995 or else Base_Type (It.Typ) =
6996 Base_Type (Component_Type (Typ))
6998 Error_Msg_N -- CODEFIX
6999 ("\\possible interpretation#", Arg);
7002 Get_Next_Interp (I, It);
7008 Resolve (Arg, Component_Type (Typ));
7010 if Nkind (Arg) = N_String_Literal then
7011 Set_Etype (Arg, Component_Type (Typ));
7014 if Arg = Left_Opnd (N) then
7015 Set_Is_Component_Left_Opnd (N);
7017 Set_Is_Component_Right_Opnd (N);
7022 Resolve (Arg, Btyp);
7025 Check_Unset_Reference (Arg);
7026 end Resolve_Op_Concat_Arg;
7028 -----------------------------
7029 -- Resolve_Op_Concat_First --
7030 -----------------------------
7032 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
7033 Btyp : constant Entity_Id := Base_Type (Typ);
7034 Op1 : constant Node_Id := Left_Opnd (N);
7035 Op2 : constant Node_Id := Right_Opnd (N);
7038 -- The parser folds an enormous sequence of concatenations of string
7039 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
7040 -- in the right operand. If the expression resolves to a predefined "&"
7041 -- operator, all is well. Otherwise, the parser's folding is wrong, so
7042 -- we give an error. See P_Simple_Expression in Par.Ch4.
7044 if Nkind (Op2) = N_String_Literal
7045 and then Is_Folded_In_Parser (Op2)
7046 and then Ekind (Entity (N)) = E_Function
7048 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
7049 and then String_Length (Strval (Op1)) = 0);
7050 Error_Msg_N ("too many user-defined concatenations", N);
7054 Set_Etype (N, Btyp);
7056 if Is_Limited_Composite (Btyp) then
7057 Error_Msg_N ("concatenation not available for limited array", N);
7058 Explain_Limited_Type (Btyp, N);
7060 end Resolve_Op_Concat_First;
7062 ----------------------------
7063 -- Resolve_Op_Concat_Rest --
7064 ----------------------------
7066 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
7067 Op1 : constant Node_Id := Left_Opnd (N);
7068 Op2 : constant Node_Id := Right_Opnd (N);
7071 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
7073 Generate_Operator_Reference (N, Typ);
7075 if Is_String_Type (Typ) then
7076 Eval_Concatenation (N);
7079 -- If this is not a static concatenation, but the result is a string
7080 -- type (and not an array of strings) ensure that static string operands
7081 -- have their subtypes properly constructed.
7083 if Nkind (N) /= N_String_Literal
7084 and then Is_Character_Type (Component_Type (Typ))
7086 Set_String_Literal_Subtype (Op1, Typ);
7087 Set_String_Literal_Subtype (Op2, Typ);
7089 end Resolve_Op_Concat_Rest;
7091 ----------------------
7092 -- Resolve_Op_Expon --
7093 ----------------------
7095 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
7096 B_Typ : constant Entity_Id := Base_Type (Typ);
7099 -- Catch attempts to do fixed-point exponentiation with universal
7100 -- operands, which is a case where the illegality is not caught during
7101 -- normal operator analysis.
7103 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
7104 Error_Msg_N ("exponentiation not available for fixed point", N);
7108 if Comes_From_Source (N)
7109 and then Ekind (Entity (N)) = E_Function
7110 and then Is_Imported (Entity (N))
7111 and then Is_Intrinsic_Subprogram (Entity (N))
7113 Resolve_Intrinsic_Operator (N, Typ);
7117 if Etype (Left_Opnd (N)) = Universal_Integer
7118 or else Etype (Left_Opnd (N)) = Universal_Real
7120 Check_For_Visible_Operator (N, B_Typ);
7123 -- We do the resolution using the base type, because intermediate values
7124 -- in expressions always are of the base type, not a subtype of it.
7126 Resolve (Left_Opnd (N), B_Typ);
7127 Resolve (Right_Opnd (N), Standard_Integer);
7129 Check_Unset_Reference (Left_Opnd (N));
7130 Check_Unset_Reference (Right_Opnd (N));
7132 Set_Etype (N, B_Typ);
7133 Generate_Operator_Reference (N, B_Typ);
7136 -- Set overflow checking bit. Much cleverer code needed here eventually
7137 -- and perhaps the Resolve routines should be separated for the various
7138 -- arithmetic operations, since they will need different processing. ???
7140 if Nkind (N) in N_Op then
7141 if not Overflow_Checks_Suppressed (Etype (N)) then
7142 Enable_Overflow_Check (N);
7145 end Resolve_Op_Expon;
7147 --------------------
7148 -- Resolve_Op_Not --
7149 --------------------
7151 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
7154 function Parent_Is_Boolean return Boolean;
7155 -- This function determines if the parent node is a boolean operator
7156 -- or operation (comparison op, membership test, or short circuit form)
7157 -- and the not in question is the left operand of this operation.
7158 -- Note that if the not is in parens, then false is returned.
7160 -----------------------
7161 -- Parent_Is_Boolean --
7162 -----------------------
7164 function Parent_Is_Boolean return Boolean is
7166 if Paren_Count (N) /= 0 then
7170 case Nkind (Parent (N)) is
7185 return Left_Opnd (Parent (N)) = N;
7191 end Parent_Is_Boolean;
7193 -- Start of processing for Resolve_Op_Not
7196 -- Predefined operations on scalar types yield the base type. On the
7197 -- other hand, logical operations on arrays yield the type of the
7198 -- arguments (and the context).
7200 if Is_Array_Type (Typ) then
7203 B_Typ := Base_Type (Typ);
7206 -- Straightforward case of incorrect arguments
7208 if not Valid_Boolean_Arg (Typ) then
7209 Error_Msg_N ("invalid operand type for operator&", N);
7210 Set_Etype (N, Any_Type);
7213 -- Special case of probable missing parens
7215 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7216 if Parent_Is_Boolean then
7218 ("operand of not must be enclosed in parentheses",
7222 ("no modular type available in this context", N);
7225 Set_Etype (N, Any_Type);
7228 -- OK resolution of not
7231 -- Warn if non-boolean types involved. This is a case like not a < b
7232 -- where a and b are modular, where we will get (not a) < b and most
7233 -- likely not (a < b) was intended.
7235 if Warn_On_Questionable_Missing_Parens
7236 and then not Is_Boolean_Type (Typ)
7237 and then Parent_Is_Boolean
7239 Error_Msg_N ("?not expression should be parenthesized here!", N);
7242 -- Warn on double negation if checking redundant constructs
7244 if Warn_On_Redundant_Constructs
7245 and then Comes_From_Source (N)
7246 and then Comes_From_Source (Right_Opnd (N))
7247 and then Root_Type (Typ) = Standard_Boolean
7248 and then Nkind (Right_Opnd (N)) = N_Op_Not
7250 Error_Msg_N ("redundant double negation?", N);
7253 -- Complete resolution and evaluation of NOT
7255 Resolve (Right_Opnd (N), B_Typ);
7256 Check_Unset_Reference (Right_Opnd (N));
7257 Set_Etype (N, B_Typ);
7258 Generate_Operator_Reference (N, B_Typ);
7263 -----------------------------
7264 -- Resolve_Operator_Symbol --
7265 -----------------------------
7267 -- Nothing to be done, all resolved already
7269 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
7270 pragma Warnings (Off, N);
7271 pragma Warnings (Off, Typ);
7275 end Resolve_Operator_Symbol;
7277 ----------------------------------
7278 -- Resolve_Qualified_Expression --
7279 ----------------------------------
7281 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
7282 pragma Warnings (Off, Typ);
7284 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
7285 Expr : constant Node_Id := Expression (N);
7288 Resolve (Expr, Target_Typ);
7290 -- A qualified expression requires an exact match of the type,
7291 -- class-wide matching is not allowed. However, if the qualifying
7292 -- type is specific and the expression has a class-wide type, it
7293 -- may still be okay, since it can be the result of the expansion
7294 -- of a call to a dispatching function, so we also have to check
7295 -- class-wideness of the type of the expression's original node.
7297 if (Is_Class_Wide_Type (Target_Typ)
7299 (Is_Class_Wide_Type (Etype (Expr))
7300 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
7301 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
7303 Wrong_Type (Expr, Target_Typ);
7306 -- If the target type is unconstrained, then we reset the type of
7307 -- the result from the type of the expression. For other cases, the
7308 -- actual subtype of the expression is the target type.
7310 if Is_Composite_Type (Target_Typ)
7311 and then not Is_Constrained (Target_Typ)
7313 Set_Etype (N, Etype (Expr));
7316 Eval_Qualified_Expression (N);
7317 end Resolve_Qualified_Expression;
7323 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
7324 L : constant Node_Id := Low_Bound (N);
7325 H : constant Node_Id := High_Bound (N);
7332 Check_Unset_Reference (L);
7333 Check_Unset_Reference (H);
7335 -- We have to check the bounds for being within the base range as
7336 -- required for a non-static context. Normally this is automatic and
7337 -- done as part of evaluating expressions, but the N_Range node is an
7338 -- exception, since in GNAT we consider this node to be a subexpression,
7339 -- even though in Ada it is not. The circuit in Sem_Eval could check for
7340 -- this, but that would put the test on the main evaluation path for
7343 Check_Non_Static_Context (L);
7344 Check_Non_Static_Context (H);
7346 -- Check for an ambiguous range over character literals. This will
7347 -- happen with a membership test involving only literals.
7349 if Typ = Any_Character then
7350 Ambiguous_Character (L);
7351 Set_Etype (N, Any_Type);
7355 -- If bounds are static, constant-fold them, so size computations
7356 -- are identical between front-end and back-end. Do not perform this
7357 -- transformation while analyzing generic units, as type information
7358 -- would then be lost when reanalyzing the constant node in the
7361 if Is_Discrete_Type (Typ) and then Expander_Active then
7362 if Is_OK_Static_Expression (L) then
7363 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
7366 if Is_OK_Static_Expression (H) then
7367 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
7372 --------------------------
7373 -- Resolve_Real_Literal --
7374 --------------------------
7376 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
7377 Actual_Typ : constant Entity_Id := Etype (N);
7380 -- Special processing for fixed-point literals to make sure that the
7381 -- value is an exact multiple of small where this is required. We
7382 -- skip this for the universal real case, and also for generic types.
7384 if Is_Fixed_Point_Type (Typ)
7385 and then Typ /= Universal_Fixed
7386 and then Typ /= Any_Fixed
7387 and then not Is_Generic_Type (Typ)
7390 Val : constant Ureal := Realval (N);
7391 Cintr : constant Ureal := Val / Small_Value (Typ);
7392 Cint : constant Uint := UR_Trunc (Cintr);
7393 Den : constant Uint := Norm_Den (Cintr);
7397 -- Case of literal is not an exact multiple of the Small
7401 -- For a source program literal for a decimal fixed-point
7402 -- type, this is statically illegal (RM 4.9(36)).
7404 if Is_Decimal_Fixed_Point_Type (Typ)
7405 and then Actual_Typ = Universal_Real
7406 and then Comes_From_Source (N)
7408 Error_Msg_N ("value has extraneous low order digits", N);
7411 -- Generate a warning if literal from source
7413 if Is_Static_Expression (N)
7414 and then Warn_On_Bad_Fixed_Value
7417 ("?static fixed-point value is not a multiple of Small!",
7421 -- Replace literal by a value that is the exact representation
7422 -- of a value of the type, i.e. a multiple of the small value,
7423 -- by truncation, since Machine_Rounds is false for all GNAT
7424 -- fixed-point types (RM 4.9(38)).
7426 Stat := Is_Static_Expression (N);
7428 Make_Real_Literal (Sloc (N),
7429 Realval => Small_Value (Typ) * Cint));
7431 Set_Is_Static_Expression (N, Stat);
7434 -- In all cases, set the corresponding integer field
7436 Set_Corresponding_Integer_Value (N, Cint);
7440 -- Now replace the actual type by the expected type as usual
7443 Eval_Real_Literal (N);
7444 end Resolve_Real_Literal;
7446 -----------------------
7447 -- Resolve_Reference --
7448 -----------------------
7450 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
7451 P : constant Node_Id := Prefix (N);
7454 -- Replace general access with specific type
7456 if Ekind (Etype (N)) = E_Allocator_Type then
7457 Set_Etype (N, Base_Type (Typ));
7460 Resolve (P, Designated_Type (Etype (N)));
7462 -- If we are taking the reference of a volatile entity, then treat
7463 -- it as a potential modification of this entity. This is much too
7464 -- conservative, but is necessary because remove side effects can
7465 -- result in transformations of normal assignments into reference
7466 -- sequences that otherwise fail to notice the modification.
7468 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
7469 Note_Possible_Modification (P, Sure => False);
7471 end Resolve_Reference;
7473 --------------------------------
7474 -- Resolve_Selected_Component --
7475 --------------------------------
7477 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
7479 Comp1 : Entity_Id := Empty; -- prevent junk warning
7480 P : constant Node_Id := Prefix (N);
7481 S : constant Node_Id := Selector_Name (N);
7482 T : Entity_Id := Etype (P);
7484 I1 : Interp_Index := 0; -- prevent junk warning
7489 function Init_Component return Boolean;
7490 -- Check whether this is the initialization of a component within an
7491 -- init proc (by assignment or call to another init proc). If true,
7492 -- there is no need for a discriminant check.
7494 --------------------
7495 -- Init_Component --
7496 --------------------
7498 function Init_Component return Boolean is
7500 return Inside_Init_Proc
7501 and then Nkind (Prefix (N)) = N_Identifier
7502 and then Chars (Prefix (N)) = Name_uInit
7503 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
7506 -- Start of processing for Resolve_Selected_Component
7509 if Is_Overloaded (P) then
7511 -- Use the context type to select the prefix that has a selector
7512 -- of the correct name and type.
7515 Get_First_Interp (P, I, It);
7517 Search : while Present (It.Typ) loop
7518 if Is_Access_Type (It.Typ) then
7519 T := Designated_Type (It.Typ);
7524 if Is_Record_Type (T) then
7526 -- The visible components of a class-wide type are those of
7529 if Is_Class_Wide_Type (T) then
7533 Comp := First_Entity (T);
7534 while Present (Comp) loop
7535 if Chars (Comp) = Chars (S)
7536 and then Covers (Etype (Comp), Typ)
7545 It := Disambiguate (P, I1, I, Any_Type);
7547 if It = No_Interp then
7549 ("ambiguous prefix for selected component", N);
7556 -- There may be an implicit dereference. Retrieve
7557 -- designated record type.
7559 if Is_Access_Type (It1.Typ) then
7560 T := Designated_Type (It1.Typ);
7565 if Scope (Comp1) /= T then
7567 -- Resolution chooses the new interpretation.
7568 -- Find the component with the right name.
7570 Comp1 := First_Entity (T);
7571 while Present (Comp1)
7572 and then Chars (Comp1) /= Chars (S)
7574 Comp1 := Next_Entity (Comp1);
7583 Comp := Next_Entity (Comp);
7588 Get_Next_Interp (I, It);
7591 Resolve (P, It1.Typ);
7593 Set_Entity_With_Style_Check (S, Comp1);
7596 -- Resolve prefix with its type
7601 -- Generate cross-reference. We needed to wait until full overloading
7602 -- resolution was complete to do this, since otherwise we can't tell if
7603 -- we are an lvalue of not.
7605 if May_Be_Lvalue (N) then
7606 Generate_Reference (Entity (S), S, 'm');
7608 Generate_Reference (Entity (S), S, 'r');
7611 -- If prefix is an access type, the node will be transformed into an
7612 -- explicit dereference during expansion. The type of the node is the
7613 -- designated type of that of the prefix.
7615 if Is_Access_Type (Etype (P)) then
7616 T := Designated_Type (Etype (P));
7617 Check_Fully_Declared_Prefix (T, P);
7622 if Has_Discriminants (T)
7623 and then (Ekind (Entity (S)) = E_Component
7625 Ekind (Entity (S)) = E_Discriminant)
7626 and then Present (Original_Record_Component (Entity (S)))
7627 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
7628 and then Present (Discriminant_Checking_Func
7629 (Original_Record_Component (Entity (S))))
7630 and then not Discriminant_Checks_Suppressed (T)
7631 and then not Init_Component
7633 Set_Do_Discriminant_Check (N);
7636 if Ekind (Entity (S)) = E_Void then
7637 Error_Msg_N ("premature use of component", S);
7640 -- If the prefix is a record conversion, this may be a renamed
7641 -- discriminant whose bounds differ from those of the original
7642 -- one, so we must ensure that a range check is performed.
7644 if Nkind (P) = N_Type_Conversion
7645 and then Ekind (Entity (S)) = E_Discriminant
7646 and then Is_Discrete_Type (Typ)
7648 Set_Etype (N, Base_Type (Typ));
7651 -- Note: No Eval processing is required, because the prefix is of a
7652 -- record type, or protected type, and neither can possibly be static.
7654 end Resolve_Selected_Component;
7660 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
7661 B_Typ : constant Entity_Id := Base_Type (Typ);
7662 L : constant Node_Id := Left_Opnd (N);
7663 R : constant Node_Id := Right_Opnd (N);
7666 -- We do the resolution using the base type, because intermediate values
7667 -- in expressions always are of the base type, not a subtype of it.
7670 Resolve (R, Standard_Natural);
7672 Check_Unset_Reference (L);
7673 Check_Unset_Reference (R);
7675 Set_Etype (N, B_Typ);
7676 Generate_Operator_Reference (N, B_Typ);
7680 ---------------------------
7681 -- Resolve_Short_Circuit --
7682 ---------------------------
7684 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
7685 B_Typ : constant Entity_Id := Base_Type (Typ);
7686 L : constant Node_Id := Left_Opnd (N);
7687 R : constant Node_Id := Right_Opnd (N);
7693 -- Check for issuing warning for always False assert/check, this happens
7694 -- when assertions are turned off, in which case the pragma Assert/Check
7695 -- was transformed into:
7697 -- if False and then <condition> then ...
7699 -- and we detect this pattern
7701 if Warn_On_Assertion_Failure
7702 and then Is_Entity_Name (R)
7703 and then Entity (R) = Standard_False
7704 and then Nkind (Parent (N)) = N_If_Statement
7705 and then Nkind (N) = N_And_Then
7706 and then Is_Entity_Name (L)
7707 and then Entity (L) = Standard_False
7710 Orig : constant Node_Id := Original_Node (Parent (N));
7713 if Nkind (Orig) = N_Pragma
7714 and then Pragma_Name (Orig) = Name_Assert
7716 -- Don't want to warn if original condition is explicit False
7719 Expr : constant Node_Id :=
7722 (First (Pragma_Argument_Associations (Orig))));
7724 if Is_Entity_Name (Expr)
7725 and then Entity (Expr) = Standard_False
7729 -- Issue warning. Note that we don't want to make this
7730 -- an unconditional warning, because if the assert is
7731 -- within deleted code we do not want the warning. But
7732 -- we do not want the deletion of the IF/AND-THEN to
7733 -- take this message with it. We achieve this by making
7734 -- sure that the expanded code points to the Sloc of
7735 -- the expression, not the original pragma.
7737 Error_Msg_N ("?assertion would fail at run-time", Orig);
7741 -- Similar processing for Check pragma
7743 elsif Nkind (Orig) = N_Pragma
7744 and then Pragma_Name (Orig) = Name_Check
7746 -- Don't want to warn if original condition is explicit False
7749 Expr : constant Node_Id :=
7753 (Pragma_Argument_Associations (Orig)))));
7755 if Is_Entity_Name (Expr)
7756 and then Entity (Expr) = Standard_False
7760 Error_Msg_N ("?check would fail at run-time", Orig);
7767 -- Continue with processing of short circuit
7769 Check_Unset_Reference (L);
7770 Check_Unset_Reference (R);
7772 Set_Etype (N, B_Typ);
7773 Eval_Short_Circuit (N);
7774 end Resolve_Short_Circuit;
7780 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
7781 Name : constant Node_Id := Prefix (N);
7782 Drange : constant Node_Id := Discrete_Range (N);
7783 Array_Type : Entity_Id := Empty;
7787 if Is_Overloaded (Name) then
7789 -- Use the context type to select the prefix that yields the correct
7794 I1 : Interp_Index := 0;
7796 P : constant Node_Id := Prefix (N);
7797 Found : Boolean := False;
7800 Get_First_Interp (P, I, It);
7801 while Present (It.Typ) loop
7802 if (Is_Array_Type (It.Typ)
7803 and then Covers (Typ, It.Typ))
7804 or else (Is_Access_Type (It.Typ)
7805 and then Is_Array_Type (Designated_Type (It.Typ))
7806 and then Covers (Typ, Designated_Type (It.Typ)))
7809 It := Disambiguate (P, I1, I, Any_Type);
7811 if It = No_Interp then
7812 Error_Msg_N ("ambiguous prefix for slicing", N);
7817 Array_Type := It.Typ;
7822 Array_Type := It.Typ;
7827 Get_Next_Interp (I, It);
7832 Array_Type := Etype (Name);
7835 Resolve (Name, Array_Type);
7837 if Is_Access_Type (Array_Type) then
7838 Apply_Access_Check (N);
7839 Array_Type := Designated_Type (Array_Type);
7841 -- If the prefix is an access to an unconstrained array, we must use
7842 -- the actual subtype of the object to perform the index checks. The
7843 -- object denoted by the prefix is implicit in the node, so we build
7844 -- an explicit representation for it in order to compute the actual
7847 if not Is_Constrained (Array_Type) then
7848 Remove_Side_Effects (Prefix (N));
7851 Obj : constant Node_Id :=
7852 Make_Explicit_Dereference (Sloc (N),
7853 Prefix => New_Copy_Tree (Prefix (N)));
7855 Set_Etype (Obj, Array_Type);
7856 Set_Parent (Obj, Parent (N));
7857 Array_Type := Get_Actual_Subtype (Obj);
7861 elsif Is_Entity_Name (Name)
7862 or else (Nkind (Name) = N_Function_Call
7863 and then not Is_Constrained (Etype (Name)))
7865 Array_Type := Get_Actual_Subtype (Name);
7867 -- If the name is a selected component that depends on discriminants,
7868 -- build an actual subtype for it. This can happen only when the name
7869 -- itself is overloaded; otherwise the actual subtype is created when
7870 -- the selected component is analyzed.
7872 elsif Nkind (Name) = N_Selected_Component
7873 and then Full_Analysis
7874 and then Depends_On_Discriminant (First_Index (Array_Type))
7877 Act_Decl : constant Node_Id :=
7878 Build_Actual_Subtype_Of_Component (Array_Type, Name);
7880 Insert_Action (N, Act_Decl);
7881 Array_Type := Defining_Identifier (Act_Decl);
7884 -- Maybe this should just be "else", instead of checking for the
7885 -- specific case of slice??? This is needed for the case where
7886 -- the prefix is an Image attribute, which gets expanded to a
7887 -- slice, and so has a constrained subtype which we want to use
7888 -- for the slice range check applied below (the range check won't
7889 -- get done if the unconstrained subtype of the 'Image is used).
7891 elsif Nkind (Name) = N_Slice then
7892 Array_Type := Etype (Name);
7895 -- If name was overloaded, set slice type correctly now
7897 Set_Etype (N, Array_Type);
7899 -- If the range is specified by a subtype mark, no resolution is
7900 -- necessary. Else resolve the bounds, and apply needed checks.
7902 if not Is_Entity_Name (Drange) then
7903 Index := First_Index (Array_Type);
7904 Resolve (Drange, Base_Type (Etype (Index)));
7906 if Nkind (Drange) = N_Range
7908 -- Do not apply the range check to nodes associated with the
7909 -- frontend expansion of the dispatch table. We first check
7910 -- if Ada.Tags is already loaded to void the addition of an
7911 -- undesired dependence on such run-time unit.
7914 (not Tagged_Type_Expansion
7916 (RTU_Loaded (Ada_Tags)
7917 and then Nkind (Prefix (N)) = N_Selected_Component
7918 and then Present (Entity (Selector_Name (Prefix (N))))
7919 and then Entity (Selector_Name (Prefix (N))) =
7920 RTE_Record_Component (RE_Prims_Ptr)))
7922 Apply_Range_Check (Drange, Etype (Index));
7926 Set_Slice_Subtype (N);
7928 if Nkind (Drange) = N_Range then
7929 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
7930 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
7936 ----------------------------
7937 -- Resolve_String_Literal --
7938 ----------------------------
7940 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
7941 C_Typ : constant Entity_Id := Component_Type (Typ);
7942 R_Typ : constant Entity_Id := Root_Type (C_Typ);
7943 Loc : constant Source_Ptr := Sloc (N);
7944 Str : constant String_Id := Strval (N);
7945 Strlen : constant Nat := String_Length (Str);
7946 Subtype_Id : Entity_Id;
7947 Need_Check : Boolean;
7950 -- For a string appearing in a concatenation, defer creation of the
7951 -- string_literal_subtype until the end of the resolution of the
7952 -- concatenation, because the literal may be constant-folded away. This
7953 -- is a useful optimization for long concatenation expressions.
7955 -- If the string is an aggregate built for a single character (which
7956 -- happens in a non-static context) or a is null string to which special
7957 -- checks may apply, we build the subtype. Wide strings must also get a
7958 -- string subtype if they come from a one character aggregate. Strings
7959 -- generated by attributes might be static, but it is often hard to
7960 -- determine whether the enclosing context is static, so we generate
7961 -- subtypes for them as well, thus losing some rarer optimizations ???
7962 -- Same for strings that come from a static conversion.
7965 (Strlen = 0 and then Typ /= Standard_String)
7966 or else Nkind (Parent (N)) /= N_Op_Concat
7967 or else (N /= Left_Opnd (Parent (N))
7968 and then N /= Right_Opnd (Parent (N)))
7969 or else ((Typ = Standard_Wide_String
7970 or else Typ = Standard_Wide_Wide_String)
7971 and then Nkind (Original_Node (N)) /= N_String_Literal);
7973 -- If the resolving type is itself a string literal subtype, we can just
7974 -- reuse it, since there is no point in creating another.
7976 if Ekind (Typ) = E_String_Literal_Subtype then
7979 elsif Nkind (Parent (N)) = N_Op_Concat
7980 and then not Need_Check
7981 and then not Nkind_In (Original_Node (N), N_Character_Literal,
7982 N_Attribute_Reference,
7983 N_Qualified_Expression,
7988 -- Otherwise we must create a string literal subtype. Note that the
7989 -- whole idea of string literal subtypes is simply to avoid the need
7990 -- for building a full fledged array subtype for each literal.
7993 Set_String_Literal_Subtype (N, Typ);
7994 Subtype_Id := Etype (N);
7997 if Nkind (Parent (N)) /= N_Op_Concat
8000 Set_Etype (N, Subtype_Id);
8001 Eval_String_Literal (N);
8004 if Is_Limited_Composite (Typ)
8005 or else Is_Private_Composite (Typ)
8007 Error_Msg_N ("string literal not available for private array", N);
8008 Set_Etype (N, Any_Type);
8012 -- The validity of a null string has been checked in the call to
8013 -- Eval_String_Literal.
8018 -- Always accept string literal with component type Any_Character, which
8019 -- occurs in error situations and in comparisons of literals, both of
8020 -- which should accept all literals.
8022 elsif R_Typ = Any_Character then
8025 -- If the type is bit-packed, then we always transform the string
8026 -- literal into a full fledged aggregate.
8028 elsif Is_Bit_Packed_Array (Typ) then
8031 -- Deal with cases of Wide_Wide_String, Wide_String, and String
8034 -- For Standard.Wide_Wide_String, or any other type whose component
8035 -- type is Standard.Wide_Wide_Character, we know that all the
8036 -- characters in the string must be acceptable, since the parser
8037 -- accepted the characters as valid character literals.
8039 if R_Typ = Standard_Wide_Wide_Character then
8042 -- For the case of Standard.String, or any other type whose component
8043 -- type is Standard.Character, we must make sure that there are no
8044 -- wide characters in the string, i.e. that it is entirely composed
8045 -- of characters in range of type Character.
8047 -- If the string literal is the result of a static concatenation, the
8048 -- test has already been performed on the components, and need not be
8051 elsif R_Typ = Standard_Character
8052 and then Nkind (Original_Node (N)) /= N_Op_Concat
8054 for J in 1 .. Strlen loop
8055 if not In_Character_Range (Get_String_Char (Str, J)) then
8057 -- If we are out of range, post error. This is one of the
8058 -- very few places that we place the flag in the middle of
8059 -- a token, right under the offending wide character. Not
8060 -- quite clear if this is right wrt wide character encoding
8061 -- sequences, but it's only an error message!
8064 ("literal out of range of type Standard.Character",
8065 Source_Ptr (Int (Loc) + J));
8070 -- For the case of Standard.Wide_String, or any other type whose
8071 -- component type is Standard.Wide_Character, we must make sure that
8072 -- there are no wide characters in the string, i.e. that it is
8073 -- entirely composed of characters in range of type Wide_Character.
8075 -- If the string literal is the result of a static concatenation,
8076 -- the test has already been performed on the components, and need
8079 elsif R_Typ = Standard_Wide_Character
8080 and then Nkind (Original_Node (N)) /= N_Op_Concat
8082 for J in 1 .. Strlen loop
8083 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
8085 -- If we are out of range, post error. This is one of the
8086 -- very few places that we place the flag in the middle of
8087 -- a token, right under the offending wide character.
8089 -- This is not quite right, because characters in general
8090 -- will take more than one character position ???
8093 ("literal out of range of type Standard.Wide_Character",
8094 Source_Ptr (Int (Loc) + J));
8099 -- If the root type is not a standard character, then we will convert
8100 -- the string into an aggregate and will let the aggregate code do
8101 -- the checking. Standard Wide_Wide_Character is also OK here.
8107 -- See if the component type of the array corresponding to the string
8108 -- has compile time known bounds. If yes we can directly check
8109 -- whether the evaluation of the string will raise constraint error.
8110 -- Otherwise we need to transform the string literal into the
8111 -- corresponding character aggregate and let the aggregate
8112 -- code do the checking.
8114 if Is_Standard_Character_Type (R_Typ) then
8116 -- Check for the case of full range, where we are definitely OK
8118 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
8122 -- Here the range is not the complete base type range, so check
8125 Comp_Typ_Lo : constant Node_Id :=
8126 Type_Low_Bound (Component_Type (Typ));
8127 Comp_Typ_Hi : constant Node_Id :=
8128 Type_High_Bound (Component_Type (Typ));
8133 if Compile_Time_Known_Value (Comp_Typ_Lo)
8134 and then Compile_Time_Known_Value (Comp_Typ_Hi)
8136 for J in 1 .. Strlen loop
8137 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
8139 if Char_Val < Expr_Value (Comp_Typ_Lo)
8140 or else Char_Val > Expr_Value (Comp_Typ_Hi)
8142 Apply_Compile_Time_Constraint_Error
8143 (N, "character out of range?", CE_Range_Check_Failed,
8144 Loc => Source_Ptr (Int (Loc) + J));
8154 -- If we got here we meed to transform the string literal into the
8155 -- equivalent qualified positional array aggregate. This is rather
8156 -- heavy artillery for this situation, but it is hard work to avoid.
8159 Lits : constant List_Id := New_List;
8160 P : Source_Ptr := Loc + 1;
8164 -- Build the character literals, we give them source locations that
8165 -- correspond to the string positions, which is a bit tricky given
8166 -- the possible presence of wide character escape sequences.
8168 for J in 1 .. Strlen loop
8169 C := Get_String_Char (Str, J);
8170 Set_Character_Literal_Name (C);
8173 Make_Character_Literal (P,
8175 Char_Literal_Value => UI_From_CC (C)));
8177 if In_Character_Range (C) then
8180 -- Should we have a call to Skip_Wide here ???
8188 Make_Qualified_Expression (Loc,
8189 Subtype_Mark => New_Reference_To (Typ, Loc),
8191 Make_Aggregate (Loc, Expressions => Lits)));
8193 Analyze_And_Resolve (N, Typ);
8195 end Resolve_String_Literal;
8197 -----------------------------
8198 -- Resolve_Subprogram_Info --
8199 -----------------------------
8201 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
8204 end Resolve_Subprogram_Info;
8206 -----------------------------
8207 -- Resolve_Type_Conversion --
8208 -----------------------------
8210 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
8211 Conv_OK : constant Boolean := Conversion_OK (N);
8212 Operand : constant Node_Id := Expression (N);
8213 Operand_Typ : constant Entity_Id := Etype (Operand);
8214 Target_Typ : constant Entity_Id := Etype (N);
8221 and then not Valid_Conversion (N, Target_Typ, Operand)
8226 if Etype (Operand) = Any_Fixed then
8228 -- Mixed-mode operation involving a literal. Context must be a fixed
8229 -- type which is applied to the literal subsequently.
8231 if Is_Fixed_Point_Type (Typ) then
8232 Set_Etype (Operand, Universal_Real);
8234 elsif Is_Numeric_Type (Typ)
8235 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
8236 and then (Etype (Right_Opnd (Operand)) = Universal_Real
8238 Etype (Left_Opnd (Operand)) = Universal_Real)
8240 -- Return if expression is ambiguous
8242 if Unique_Fixed_Point_Type (N) = Any_Type then
8245 -- If nothing else, the available fixed type is Duration
8248 Set_Etype (Operand, Standard_Duration);
8251 -- Resolve the real operand with largest available precision
8253 if Etype (Right_Opnd (Operand)) = Universal_Real then
8254 Rop := New_Copy_Tree (Right_Opnd (Operand));
8256 Rop := New_Copy_Tree (Left_Opnd (Operand));
8259 Resolve (Rop, Universal_Real);
8261 -- If the operand is a literal (it could be a non-static and
8262 -- illegal exponentiation) check whether the use of Duration
8263 -- is potentially inaccurate.
8265 if Nkind (Rop) = N_Real_Literal
8266 and then Realval (Rop) /= Ureal_0
8267 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
8270 ("?universal real operand can only " &
8271 "be interpreted as Duration!",
8274 ("\?precision will be lost in the conversion!", Rop);
8277 elsif Is_Numeric_Type (Typ)
8278 and then Nkind (Operand) in N_Op
8279 and then Unique_Fixed_Point_Type (N) /= Any_Type
8281 Set_Etype (Operand, Standard_Duration);
8284 Error_Msg_N ("invalid context for mixed mode operation", N);
8285 Set_Etype (Operand, Any_Type);
8292 -- Note: we do the Eval_Type_Conversion call before applying the
8293 -- required checks for a subtype conversion. This is important, since
8294 -- both are prepared under certain circumstances to change the type
8295 -- conversion to a constraint error node, but in the case of
8296 -- Eval_Type_Conversion this may reflect an illegality in the static
8297 -- case, and we would miss the illegality (getting only a warning
8298 -- message), if we applied the type conversion checks first.
8300 Eval_Type_Conversion (N);
8302 -- Even when evaluation is not possible, we may be able to simplify the
8303 -- conversion or its expression. This needs to be done before applying
8304 -- checks, since otherwise the checks may use the original expression
8305 -- and defeat the simplifications. This is specifically the case for
8306 -- elimination of the floating-point Truncation attribute in
8307 -- float-to-int conversions.
8309 Simplify_Type_Conversion (N);
8311 -- If after evaluation we still have a type conversion, then we may need
8312 -- to apply checks required for a subtype conversion.
8314 -- Skip these type conversion checks if universal fixed operands
8315 -- operands involved, since range checks are handled separately for
8316 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
8318 if Nkind (N) = N_Type_Conversion
8319 and then not Is_Generic_Type (Root_Type (Target_Typ))
8320 and then Target_Typ /= Universal_Fixed
8321 and then Operand_Typ /= Universal_Fixed
8323 Apply_Type_Conversion_Checks (N);
8326 -- Issue warning for conversion of simple object to its own type. We
8327 -- have to test the original nodes, since they may have been rewritten
8328 -- by various optimizations.
8330 Orig_N := Original_Node (N);
8332 if Warn_On_Redundant_Constructs
8333 and then Comes_From_Source (Orig_N)
8334 and then Nkind (Orig_N) = N_Type_Conversion
8335 and then not In_Instance
8337 Orig_N := Original_Node (Expression (Orig_N));
8338 Orig_T := Target_Typ;
8340 -- If the node is part of a larger expression, the Target_Type
8341 -- may not be the original type of the node if the context is a
8342 -- condition. Recover original type to see if conversion is needed.
8344 if Is_Boolean_Type (Orig_T)
8345 and then Nkind (Parent (N)) in N_Op
8347 Orig_T := Etype (Parent (N));
8350 if Is_Entity_Name (Orig_N)
8352 (Etype (Entity (Orig_N)) = Orig_T
8354 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
8355 and then Covers (Orig_T, Etype (Entity (Orig_N)))))
8357 Error_Msg_Node_2 := Orig_T;
8358 Error_Msg_NE -- CODEFIX
8359 ("?redundant conversion, & is of type &!", N, Entity (Orig_N));
8363 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
8364 -- No need to perform any interface conversion if the type of the
8365 -- expression coincides with the target type.
8367 if Ada_Version >= Ada_05
8368 and then Expander_Active
8369 and then Operand_Typ /= Target_Typ
8372 Opnd : Entity_Id := Operand_Typ;
8373 Target : Entity_Id := Target_Typ;
8376 if Is_Access_Type (Opnd) then
8377 Opnd := Directly_Designated_Type (Opnd);
8380 if Is_Access_Type (Target_Typ) then
8381 Target := Directly_Designated_Type (Target);
8384 if Opnd = Target then
8387 -- Conversion from interface type
8389 elsif Is_Interface (Opnd) then
8391 -- Ada 2005 (AI-217): Handle entities from limited views
8393 if From_With_Type (Opnd) then
8394 Error_Msg_Qual_Level := 99;
8395 Error_Msg_NE ("missing WITH clause on package &", N,
8396 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
8398 ("type conversions require visibility of the full view",
8401 elsif From_With_Type (Target)
8403 (Is_Access_Type (Target_Typ)
8404 and then Present (Non_Limited_View (Etype (Target))))
8406 Error_Msg_Qual_Level := 99;
8407 Error_Msg_NE ("missing WITH clause on package &", N,
8408 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
8410 ("type conversions require visibility of the full view",
8414 Expand_Interface_Conversion (N, Is_Static => False);
8417 -- Conversion to interface type
8419 elsif Is_Interface (Target) then
8423 if Ekind (Opnd) = E_Protected_Subtype
8424 or else Ekind (Opnd) = E_Task_Subtype
8426 Opnd := Etype (Opnd);
8429 if not Interface_Present_In_Ancestor
8433 if Is_Class_Wide_Type (Opnd) then
8435 -- The static analysis is not enough to know if the
8436 -- interface is implemented or not. Hence we must pass
8437 -- the work to the expander to generate code to evaluate
8438 -- the conversion at run-time.
8440 Expand_Interface_Conversion (N, Is_Static => False);
8443 Error_Msg_Name_1 := Chars (Etype (Target));
8444 Error_Msg_Name_2 := Chars (Opnd);
8446 ("wrong interface conversion (% is not a progenitor " &
8451 Expand_Interface_Conversion (N);
8456 end Resolve_Type_Conversion;
8458 ----------------------
8459 -- Resolve_Unary_Op --
8460 ----------------------
8462 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
8463 B_Typ : constant Entity_Id := Base_Type (Typ);
8464 R : constant Node_Id := Right_Opnd (N);
8470 -- Deal with intrinsic unary operators
8472 if Comes_From_Source (N)
8473 and then Ekind (Entity (N)) = E_Function
8474 and then Is_Imported (Entity (N))
8475 and then Is_Intrinsic_Subprogram (Entity (N))
8477 Resolve_Intrinsic_Unary_Operator (N, Typ);
8481 -- Deal with universal cases
8483 if Etype (R) = Universal_Integer
8485 Etype (R) = Universal_Real
8487 Check_For_Visible_Operator (N, B_Typ);
8490 Set_Etype (N, B_Typ);
8493 -- Generate warning for expressions like abs (x mod 2)
8495 if Warn_On_Redundant_Constructs
8496 and then Nkind (N) = N_Op_Abs
8498 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
8500 if OK and then Hi >= Lo and then Lo >= 0 then
8502 ("?abs applied to known non-negative value has no effect", N);
8506 -- Deal with reference generation
8508 Check_Unset_Reference (R);
8509 Generate_Operator_Reference (N, B_Typ);
8512 -- Set overflow checking bit. Much cleverer code needed here eventually
8513 -- and perhaps the Resolve routines should be separated for the various
8514 -- arithmetic operations, since they will need different processing ???
8516 if Nkind (N) in N_Op then
8517 if not Overflow_Checks_Suppressed (Etype (N)) then
8518 Enable_Overflow_Check (N);
8522 -- Generate warning for expressions like -5 mod 3 for integers. No need
8523 -- to worry in the floating-point case, since parens do not affect the
8524 -- result so there is no point in giving in a warning.
8527 Norig : constant Node_Id := Original_Node (N);
8536 if Warn_On_Questionable_Missing_Parens
8537 and then Comes_From_Source (Norig)
8538 and then Is_Integer_Type (Typ)
8539 and then Nkind (Norig) = N_Op_Minus
8541 Rorig := Original_Node (Right_Opnd (Norig));
8543 -- We are looking for cases where the right operand is not
8544 -- parenthesized, and is a binary operator, multiply, divide, or
8545 -- mod. These are the cases where the grouping can affect results.
8547 if Paren_Count (Rorig) = 0
8548 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
8550 -- For mod, we always give the warning, since the value is
8551 -- affected by the parenthesization (e.g. (-5) mod 315 /=
8552 -- -(5 mod 315)). But for the other cases, the only concern is
8553 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
8554 -- overflows, but (-2) * 64 does not). So we try to give the
8555 -- message only when overflow is possible.
8557 if Nkind (Rorig) /= N_Op_Mod
8558 and then Compile_Time_Known_Value (R)
8560 Val := Expr_Value (R);
8562 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
8563 HB := Expr_Value (Type_High_Bound (Typ));
8565 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
8568 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
8569 LB := Expr_Value (Type_Low_Bound (Typ));
8571 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
8574 -- Note that the test below is deliberately excluding the
8575 -- largest negative number, since that is a potentially
8576 -- troublesome case (e.g. -2 * x, where the result is the
8577 -- largest negative integer has an overflow with 2 * x).
8579 if Val > LB and then Val <= HB then
8584 -- For the multiplication case, the only case we have to worry
8585 -- about is when (-a)*b is exactly the largest negative number
8586 -- so that -(a*b) can cause overflow. This can only happen if
8587 -- a is a power of 2, and more generally if any operand is a
8588 -- constant that is not a power of 2, then the parentheses
8589 -- cannot affect whether overflow occurs. We only bother to
8590 -- test the left most operand
8592 -- Loop looking at left operands for one that has known value
8595 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
8596 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
8597 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
8599 -- Operand value of 0 or 1 skips warning
8604 -- Otherwise check power of 2, if power of 2, warn, if
8605 -- anything else, skip warning.
8608 while Lval /= 2 loop
8609 if Lval mod 2 = 1 then
8620 -- Keep looking at left operands
8622 Opnd := Left_Opnd (Opnd);
8625 -- For rem or "/" we can only have a problematic situation
8626 -- if the divisor has a value of minus one or one. Otherwise
8627 -- overflow is impossible (divisor > 1) or we have a case of
8628 -- division by zero in any case.
8630 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
8631 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
8632 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
8637 -- If we fall through warning should be issued
8640 ("?unary minus expression should be parenthesized here!", N);
8644 end Resolve_Unary_Op;
8646 ----------------------------------
8647 -- Resolve_Unchecked_Expression --
8648 ----------------------------------
8650 procedure Resolve_Unchecked_Expression
8655 Resolve (Expression (N), Typ, Suppress => All_Checks);
8657 end Resolve_Unchecked_Expression;
8659 ---------------------------------------
8660 -- Resolve_Unchecked_Type_Conversion --
8661 ---------------------------------------
8663 procedure Resolve_Unchecked_Type_Conversion
8667 pragma Warnings (Off, Typ);
8669 Operand : constant Node_Id := Expression (N);
8670 Opnd_Type : constant Entity_Id := Etype (Operand);
8673 -- Resolve operand using its own type
8675 Resolve (Operand, Opnd_Type);
8676 Eval_Unchecked_Conversion (N);
8678 end Resolve_Unchecked_Type_Conversion;
8680 ------------------------------
8681 -- Rewrite_Operator_As_Call --
8682 ------------------------------
8684 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
8685 Loc : constant Source_Ptr := Sloc (N);
8686 Actuals : constant List_Id := New_List;
8690 if Nkind (N) in N_Binary_Op then
8691 Append (Left_Opnd (N), Actuals);
8694 Append (Right_Opnd (N), Actuals);
8697 Make_Function_Call (Sloc => Loc,
8698 Name => New_Occurrence_Of (Nam, Loc),
8699 Parameter_Associations => Actuals);
8701 Preserve_Comes_From_Source (New_N, N);
8702 Preserve_Comes_From_Source (Name (New_N), N);
8704 Set_Etype (N, Etype (Nam));
8705 end Rewrite_Operator_As_Call;
8707 ------------------------------
8708 -- Rewrite_Renamed_Operator --
8709 ------------------------------
8711 procedure Rewrite_Renamed_Operator
8716 Nam : constant Name_Id := Chars (Op);
8717 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
8721 -- Rewrite the operator node using the real operator, not its renaming.
8722 -- Exclude user-defined intrinsic operations of the same name, which are
8723 -- treated separately and rewritten as calls.
8725 if Ekind (Op) /= E_Function
8726 or else Chars (N) /= Nam
8728 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
8729 Set_Chars (Op_Node, Nam);
8730 Set_Etype (Op_Node, Etype (N));
8731 Set_Entity (Op_Node, Op);
8732 Set_Right_Opnd (Op_Node, Right_Opnd (N));
8734 -- Indicate that both the original entity and its renaming are
8735 -- referenced at this point.
8737 Generate_Reference (Entity (N), N);
8738 Generate_Reference (Op, N);
8741 Set_Left_Opnd (Op_Node, Left_Opnd (N));
8744 Rewrite (N, Op_Node);
8746 -- If the context type is private, add the appropriate conversions
8747 -- so that the operator is applied to the full view. This is done
8748 -- in the routines that resolve intrinsic operators,
8750 if Is_Intrinsic_Subprogram (Op)
8751 and then Is_Private_Type (Typ)
8754 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
8755 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
8756 Resolve_Intrinsic_Operator (N, Typ);
8758 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
8759 Resolve_Intrinsic_Unary_Operator (N, Typ);
8766 elsif Ekind (Op) = E_Function
8767 and then Is_Intrinsic_Subprogram (Op)
8769 -- Operator renames a user-defined operator of the same name. Use
8770 -- the original operator in the node, which is the one that Gigi
8774 Set_Is_Overloaded (N, False);
8776 end Rewrite_Renamed_Operator;
8778 -----------------------
8779 -- Set_Slice_Subtype --
8780 -----------------------
8782 -- Build an implicit subtype declaration to represent the type delivered
8783 -- by the slice. This is an abbreviated version of an array subtype. We
8784 -- define an index subtype for the slice, using either the subtype name
8785 -- or the discrete range of the slice. To be consistent with index usage
8786 -- elsewhere, we create a list header to hold the single index. This list
8787 -- is not otherwise attached to the syntax tree.
8789 procedure Set_Slice_Subtype (N : Node_Id) is
8790 Loc : constant Source_Ptr := Sloc (N);
8791 Index_List : constant List_Id := New_List;
8793 Index_Subtype : Entity_Id;
8794 Index_Type : Entity_Id;
8795 Slice_Subtype : Entity_Id;
8796 Drange : constant Node_Id := Discrete_Range (N);
8799 if Is_Entity_Name (Drange) then
8800 Index_Subtype := Entity (Drange);
8803 -- We force the evaluation of a range. This is definitely needed in
8804 -- the renamed case, and seems safer to do unconditionally. Note in
8805 -- any case that since we will create and insert an Itype referring
8806 -- to this range, we must make sure any side effect removal actions
8807 -- are inserted before the Itype definition.
8809 if Nkind (Drange) = N_Range then
8810 Force_Evaluation (Low_Bound (Drange));
8811 Force_Evaluation (High_Bound (Drange));
8814 Index_Type := Base_Type (Etype (Drange));
8816 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
8818 Set_Scalar_Range (Index_Subtype, Drange);
8819 Set_Etype (Index_Subtype, Index_Type);
8820 Set_Size_Info (Index_Subtype, Index_Type);
8821 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
8824 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
8826 Index := New_Occurrence_Of (Index_Subtype, Loc);
8827 Set_Etype (Index, Index_Subtype);
8828 Append (Index, Index_List);
8830 Set_First_Index (Slice_Subtype, Index);
8831 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
8832 Set_Is_Constrained (Slice_Subtype, True);
8834 Check_Compile_Time_Size (Slice_Subtype);
8836 -- The Etype of the existing Slice node is reset to this slice subtype.
8837 -- Its bounds are obtained from its first index.
8839 Set_Etype (N, Slice_Subtype);
8841 -- In the packed case, this must be immediately frozen
8843 -- Couldn't we always freeze here??? and if we did, then the above
8844 -- call to Check_Compile_Time_Size could be eliminated, which would
8845 -- be nice, because then that routine could be made private to Freeze.
8847 -- Why the test for In_Spec_Expression here ???
8849 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
8850 Freeze_Itype (Slice_Subtype, N);
8853 end Set_Slice_Subtype;
8855 --------------------------------
8856 -- Set_String_Literal_Subtype --
8857 --------------------------------
8859 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
8860 Loc : constant Source_Ptr := Sloc (N);
8861 Low_Bound : constant Node_Id :=
8862 Type_Low_Bound (Etype (First_Index (Typ)));
8863 Subtype_Id : Entity_Id;
8866 if Nkind (N) /= N_String_Literal then
8870 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
8871 Set_String_Literal_Length (Subtype_Id, UI_From_Int
8872 (String_Length (Strval (N))));
8873 Set_Etype (Subtype_Id, Base_Type (Typ));
8874 Set_Is_Constrained (Subtype_Id);
8875 Set_Etype (N, Subtype_Id);
8877 if Is_OK_Static_Expression (Low_Bound) then
8879 -- The low bound is set from the low bound of the corresponding
8880 -- index type. Note that we do not store the high bound in the
8881 -- string literal subtype, but it can be deduced if necessary
8882 -- from the length and the low bound.
8884 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
8887 Set_String_Literal_Low_Bound
8888 (Subtype_Id, Make_Integer_Literal (Loc, 1));
8889 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Standard_Positive);
8891 -- Build bona fide subtype for the string, and wrap it in an
8892 -- unchecked conversion, because the backend expects the
8893 -- String_Literal_Subtype to have a static lower bound.
8896 Index_List : constant List_Id := New_List;
8897 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
8898 High_Bound : constant Node_Id :=
8900 Left_Opnd => New_Copy_Tree (Low_Bound),
8902 Make_Integer_Literal (Loc,
8903 String_Length (Strval (N)) - 1));
8904 Array_Subtype : Entity_Id;
8905 Index_Subtype : Entity_Id;
8911 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
8912 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
8913 Set_Scalar_Range (Index_Subtype, Drange);
8914 Set_Parent (Drange, N);
8915 Analyze_And_Resolve (Drange, Index_Type);
8917 -- In the context, the Index_Type may already have a constraint,
8918 -- so use common base type on string subtype. The base type may
8919 -- be used when generating attributes of the string, for example
8920 -- in the context of a slice assignment.
8922 Set_Etype (Index_Subtype, Base_Type (Index_Type));
8923 Set_Size_Info (Index_Subtype, Index_Type);
8924 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
8926 Array_Subtype := Create_Itype (E_Array_Subtype, N);
8928 Index := New_Occurrence_Of (Index_Subtype, Loc);
8929 Set_Etype (Index, Index_Subtype);
8930 Append (Index, Index_List);
8932 Set_First_Index (Array_Subtype, Index);
8933 Set_Etype (Array_Subtype, Base_Type (Typ));
8934 Set_Is_Constrained (Array_Subtype, True);
8937 Make_Unchecked_Type_Conversion (Loc,
8938 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
8939 Expression => Relocate_Node (N)));
8940 Set_Etype (N, Array_Subtype);
8943 end Set_String_Literal_Subtype;
8945 ------------------------------
8946 -- Simplify_Type_Conversion --
8947 ------------------------------
8949 procedure Simplify_Type_Conversion (N : Node_Id) is
8951 if Nkind (N) = N_Type_Conversion then
8953 Operand : constant Node_Id := Expression (N);
8954 Target_Typ : constant Entity_Id := Etype (N);
8955 Opnd_Typ : constant Entity_Id := Etype (Operand);
8958 if Is_Floating_Point_Type (Opnd_Typ)
8960 (Is_Integer_Type (Target_Typ)
8961 or else (Is_Fixed_Point_Type (Target_Typ)
8962 and then Conversion_OK (N)))
8963 and then Nkind (Operand) = N_Attribute_Reference
8964 and then Attribute_Name (Operand) = Name_Truncation
8966 -- Special processing required if the conversion is the expression
8967 -- of a Truncation attribute reference. In this case we replace:
8969 -- ityp (ftyp'Truncation (x))
8975 -- with the Float_Truncate flag set, which is more efficient
8979 Relocate_Node (First (Expressions (Operand))));
8980 Set_Float_Truncate (N, True);
8984 end Simplify_Type_Conversion;
8986 -----------------------------
8987 -- Unique_Fixed_Point_Type --
8988 -----------------------------
8990 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
8991 T1 : Entity_Id := Empty;
8996 procedure Fixed_Point_Error;
8997 -- Give error messages for true ambiguity. Messages are posted on node
8998 -- N, and entities T1, T2 are the possible interpretations.
9000 -----------------------
9001 -- Fixed_Point_Error --
9002 -----------------------
9004 procedure Fixed_Point_Error is
9006 Error_Msg_N ("ambiguous universal_fixed_expression", N);
9007 Error_Msg_NE ("\\possible interpretation as}", N, T1);
9008 Error_Msg_NE ("\\possible interpretation as}", N, T2);
9009 end Fixed_Point_Error;
9011 -- Start of processing for Unique_Fixed_Point_Type
9014 -- The operations on Duration are visible, so Duration is always a
9015 -- possible interpretation.
9017 T1 := Standard_Duration;
9019 -- Look for fixed-point types in enclosing scopes
9021 Scop := Current_Scope;
9022 while Scop /= Standard_Standard loop
9023 T2 := First_Entity (Scop);
9024 while Present (T2) loop
9025 if Is_Fixed_Point_Type (T2)
9026 and then Current_Entity (T2) = T2
9027 and then Scope (Base_Type (T2)) = Scop
9029 if Present (T1) then
9040 Scop := Scope (Scop);
9043 -- Look for visible fixed type declarations in the context
9045 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
9046 while Present (Item) loop
9047 if Nkind (Item) = N_With_Clause then
9048 Scop := Entity (Name (Item));
9049 T2 := First_Entity (Scop);
9050 while Present (T2) loop
9051 if Is_Fixed_Point_Type (T2)
9052 and then Scope (Base_Type (T2)) = Scop
9053 and then (Is_Potentially_Use_Visible (T2)
9054 or else In_Use (T2))
9056 if Present (T1) then
9071 if Nkind (N) = N_Real_Literal then
9072 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
9074 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
9078 end Unique_Fixed_Point_Type;
9080 ----------------------
9081 -- Valid_Conversion --
9082 ----------------------
9084 function Valid_Conversion
9087 Operand : Node_Id) return Boolean
9089 Target_Type : constant Entity_Id := Base_Type (Target);
9090 Opnd_Type : Entity_Id := Etype (Operand);
9092 function Conversion_Check
9094 Msg : String) return Boolean;
9095 -- Little routine to post Msg if Valid is False, returns Valid value
9097 function Valid_Tagged_Conversion
9098 (Target_Type : Entity_Id;
9099 Opnd_Type : Entity_Id) return Boolean;
9100 -- Specifically test for validity of tagged conversions
9102 function Valid_Array_Conversion return Boolean;
9103 -- Check index and component conformance, and accessibility levels
9104 -- if the component types are anonymous access types (Ada 2005)
9106 ----------------------
9107 -- Conversion_Check --
9108 ----------------------
9110 function Conversion_Check
9112 Msg : String) return Boolean
9116 Error_Msg_N (Msg, Operand);
9120 end Conversion_Check;
9122 ----------------------------
9123 -- Valid_Array_Conversion --
9124 ----------------------------
9126 function Valid_Array_Conversion return Boolean
9128 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
9129 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
9131 Opnd_Index : Node_Id;
9132 Opnd_Index_Type : Entity_Id;
9134 Target_Comp_Type : constant Entity_Id :=
9135 Component_Type (Target_Type);
9136 Target_Comp_Base : constant Entity_Id :=
9137 Base_Type (Target_Comp_Type);
9139 Target_Index : Node_Id;
9140 Target_Index_Type : Entity_Id;
9143 -- Error if wrong number of dimensions
9146 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
9149 ("incompatible number of dimensions for conversion", Operand);
9152 -- Number of dimensions matches
9155 -- Loop through indexes of the two arrays
9157 Target_Index := First_Index (Target_Type);
9158 Opnd_Index := First_Index (Opnd_Type);
9159 while Present (Target_Index) and then Present (Opnd_Index) loop
9160 Target_Index_Type := Etype (Target_Index);
9161 Opnd_Index_Type := Etype (Opnd_Index);
9163 -- Error if index types are incompatible
9165 if not (Is_Integer_Type (Target_Index_Type)
9166 and then Is_Integer_Type (Opnd_Index_Type))
9167 and then (Root_Type (Target_Index_Type)
9168 /= Root_Type (Opnd_Index_Type))
9171 ("incompatible index types for array conversion",
9176 Next_Index (Target_Index);
9177 Next_Index (Opnd_Index);
9180 -- If component types have same base type, all set
9182 if Target_Comp_Base = Opnd_Comp_Base then
9185 -- Here if base types of components are not the same. The only
9186 -- time this is allowed is if we have anonymous access types.
9188 -- The conversion of arrays of anonymous access types can lead
9189 -- to dangling pointers. AI-392 formalizes the accessibility
9190 -- checks that must be applied to such conversions to prevent
9191 -- out-of-scope references.
9194 (Ekind (Target_Comp_Base) = E_Anonymous_Access_Type
9196 Ekind (Target_Comp_Base) = E_Anonymous_Access_Subprogram_Type)
9197 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
9199 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
9201 if Type_Access_Level (Target_Type) <
9202 Type_Access_Level (Opnd_Type)
9204 if In_Instance_Body then
9205 Error_Msg_N ("?source array type " &
9206 "has deeper accessibility level than target", Operand);
9207 Error_Msg_N ("\?Program_Error will be raised at run time",
9210 Make_Raise_Program_Error (Sloc (N),
9211 Reason => PE_Accessibility_Check_Failed));
9212 Set_Etype (N, Target_Type);
9215 -- Conversion not allowed because of accessibility levels
9218 Error_Msg_N ("source array type " &
9219 "has deeper accessibility level than target", Operand);
9226 -- All other cases where component base types do not match
9230 ("incompatible component types for array conversion",
9235 -- Check that component subtypes statically match. For numeric
9236 -- types this means that both must be either constrained or
9237 -- unconstrained. For enumeration types the bounds must match.
9238 -- All of this is checked in Subtypes_Statically_Match.
9240 if not Subtypes_Statically_Match
9241 (Target_Comp_Type, Opnd_Comp_Type)
9244 ("component subtypes must statically match", Operand);
9250 end Valid_Array_Conversion;
9252 -----------------------------
9253 -- Valid_Tagged_Conversion --
9254 -----------------------------
9256 function Valid_Tagged_Conversion
9257 (Target_Type : Entity_Id;
9258 Opnd_Type : Entity_Id) return Boolean
9261 -- Upward conversions are allowed (RM 4.6(22))
9263 if Covers (Target_Type, Opnd_Type)
9264 or else Is_Ancestor (Target_Type, Opnd_Type)
9268 -- Downward conversion are allowed if the operand is class-wide
9271 elsif Is_Class_Wide_Type (Opnd_Type)
9272 and then Covers (Opnd_Type, Target_Type)
9276 elsif Covers (Opnd_Type, Target_Type)
9277 or else Is_Ancestor (Opnd_Type, Target_Type)
9280 Conversion_Check (False,
9281 "downward conversion of tagged objects not allowed");
9283 -- Ada 2005 (AI-251): The conversion to/from interface types is
9286 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
9289 -- If the operand is a class-wide type obtained through a limited_
9290 -- with clause, and the context includes the non-limited view, use
9291 -- it to determine whether the conversion is legal.
9293 elsif Is_Class_Wide_Type (Opnd_Type)
9294 and then From_With_Type (Opnd_Type)
9295 and then Present (Non_Limited_View (Etype (Opnd_Type)))
9296 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
9300 elsif Is_Access_Type (Opnd_Type)
9301 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
9307 ("invalid tagged conversion, not compatible with}",
9308 N, First_Subtype (Opnd_Type));
9311 end Valid_Tagged_Conversion;
9313 -- Start of processing for Valid_Conversion
9316 Check_Parameterless_Call (Operand);
9318 if Is_Overloaded (Operand) then
9327 -- Remove procedure calls, which syntactically cannot appear in
9328 -- this context, but which cannot be removed by type checking,
9329 -- because the context does not impose a type.
9331 -- When compiling for VMS, spurious ambiguities can be produced
9332 -- when arithmetic operations have a literal operand and return
9333 -- System.Address or a descendant of it. These ambiguities are
9334 -- otherwise resolved by the context, but for conversions there
9335 -- is no context type and the removal of the spurious operations
9336 -- must be done explicitly here.
9338 -- The node may be labelled overloaded, but still contain only
9339 -- one interpretation because others were discarded in previous
9340 -- filters. If this is the case, retain the single interpretation
9343 Get_First_Interp (Operand, I, It);
9344 Opnd_Type := It.Typ;
9345 Get_Next_Interp (I, It);
9348 and then Opnd_Type /= Standard_Void_Type
9350 -- More than one candidate interpretation is available
9352 Get_First_Interp (Operand, I, It);
9353 while Present (It.Typ) loop
9354 if It.Typ = Standard_Void_Type then
9358 if Present (System_Aux_Id)
9359 and then Is_Descendent_Of_Address (It.Typ)
9364 Get_Next_Interp (I, It);
9368 Get_First_Interp (Operand, I, It);
9373 Error_Msg_N ("illegal operand in conversion", Operand);
9377 Get_Next_Interp (I, It);
9379 if Present (It.Typ) then
9381 It1 := Disambiguate (Operand, I1, I, Any_Type);
9383 if It1 = No_Interp then
9384 Error_Msg_N ("ambiguous operand in conversion", Operand);
9386 Error_Msg_Sloc := Sloc (It.Nam);
9387 Error_Msg_N -- CODEFIX
9388 ("\\possible interpretation#!", Operand);
9390 Error_Msg_Sloc := Sloc (N1);
9391 Error_Msg_N -- CODEFIX
9392 ("\\possible interpretation#!", Operand);
9398 Set_Etype (Operand, It1.Typ);
9399 Opnd_Type := It1.Typ;
9405 if Is_Numeric_Type (Target_Type) then
9407 -- A universal fixed expression can be converted to any numeric type
9409 if Opnd_Type = Universal_Fixed then
9412 -- Also no need to check when in an instance or inlined body, because
9413 -- the legality has been established when the template was analyzed.
9414 -- Furthermore, numeric conversions may occur where only a private
9415 -- view of the operand type is visible at the instantiation point.
9416 -- This results in a spurious error if we check that the operand type
9417 -- is a numeric type.
9419 -- Note: in a previous version of this unit, the following tests were
9420 -- applied only for generated code (Comes_From_Source set to False),
9421 -- but in fact the test is required for source code as well, since
9422 -- this situation can arise in source code.
9424 elsif In_Instance or else In_Inlined_Body then
9427 -- Otherwise we need the conversion check
9430 return Conversion_Check
9431 (Is_Numeric_Type (Opnd_Type),
9432 "illegal operand for numeric conversion");
9437 elsif Is_Array_Type (Target_Type) then
9438 if not Is_Array_Type (Opnd_Type)
9439 or else Opnd_Type = Any_Composite
9440 or else Opnd_Type = Any_String
9443 ("illegal operand for array conversion", Operand);
9446 return Valid_Array_Conversion;
9449 -- Ada 2005 (AI-251): Anonymous access types where target references an
9452 elsif (Ekind (Target_Type) = E_General_Access_Type
9454 Ekind (Target_Type) = E_Anonymous_Access_Type)
9455 and then Is_Interface (Directly_Designated_Type (Target_Type))
9457 -- Check the static accessibility rule of 4.6(17). Note that the
9458 -- check is not enforced when within an instance body, since the
9459 -- RM requires such cases to be caught at run time.
9461 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
9462 if Type_Access_Level (Opnd_Type) >
9463 Type_Access_Level (Target_Type)
9465 -- In an instance, this is a run-time check, but one we know
9466 -- will fail, so generate an appropriate warning. The raise
9467 -- will be generated by Expand_N_Type_Conversion.
9469 if In_Instance_Body then
9471 ("?cannot convert local pointer to non-local access type",
9474 ("\?Program_Error will be raised at run time", Operand);
9477 ("cannot convert local pointer to non-local access type",
9482 -- Special accessibility checks are needed in the case of access
9483 -- discriminants declared for a limited type.
9485 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9486 and then not Is_Local_Anonymous_Access (Opnd_Type)
9488 -- When the operand is a selected access discriminant the check
9489 -- needs to be made against the level of the object denoted by
9490 -- the prefix of the selected name (Object_Access_Level handles
9491 -- checking the prefix of the operand for this case).
9493 if Nkind (Operand) = N_Selected_Component
9494 and then Object_Access_Level (Operand) >
9495 Type_Access_Level (Target_Type)
9497 -- In an instance, this is a run-time check, but one we know
9498 -- will fail, so generate an appropriate warning. The raise
9499 -- will be generated by Expand_N_Type_Conversion.
9501 if In_Instance_Body then
9503 ("?cannot convert access discriminant to non-local" &
9504 " access type", Operand);
9506 ("\?Program_Error will be raised at run time", Operand);
9509 ("cannot convert access discriminant to non-local" &
9510 " access type", Operand);
9515 -- The case of a reference to an access discriminant from
9516 -- within a limited type declaration (which will appear as
9517 -- a discriminal) is always illegal because the level of the
9518 -- discriminant is considered to be deeper than any (nameable)
9521 if Is_Entity_Name (Operand)
9522 and then not Is_Local_Anonymous_Access (Opnd_Type)
9523 and then (Ekind (Entity (Operand)) = E_In_Parameter
9524 or else Ekind (Entity (Operand)) = E_Constant)
9525 and then Present (Discriminal_Link (Entity (Operand)))
9528 ("discriminant has deeper accessibility level than target",
9537 -- General and anonymous access types
9539 elsif (Ekind (Target_Type) = E_General_Access_Type
9540 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
9543 (Is_Access_Type (Opnd_Type)
9544 and then Ekind (Opnd_Type) /=
9545 E_Access_Subprogram_Type
9546 and then Ekind (Opnd_Type) /=
9547 E_Access_Protected_Subprogram_Type,
9548 "must be an access-to-object type")
9550 if Is_Access_Constant (Opnd_Type)
9551 and then not Is_Access_Constant (Target_Type)
9554 ("access-to-constant operand type not allowed", Operand);
9558 -- Check the static accessibility rule of 4.6(17). Note that the
9559 -- check is not enforced when within an instance body, since the RM
9560 -- requires such cases to be caught at run time.
9562 if Ekind (Target_Type) /= E_Anonymous_Access_Type
9563 or else Is_Local_Anonymous_Access (Target_Type)
9565 if Type_Access_Level (Opnd_Type)
9566 > Type_Access_Level (Target_Type)
9568 -- In an instance, this is a run-time check, but one we know
9569 -- will fail, so generate an appropriate warning. The raise
9570 -- will be generated by Expand_N_Type_Conversion.
9572 if In_Instance_Body then
9574 ("?cannot convert local pointer to non-local access type",
9577 ("\?Program_Error will be raised at run time", Operand);
9580 -- Avoid generation of spurious error message
9582 if not Error_Posted (N) then
9584 ("cannot convert local pointer to non-local access type",
9591 -- Special accessibility checks are needed in the case of access
9592 -- discriminants declared for a limited type.
9594 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9595 and then not Is_Local_Anonymous_Access (Opnd_Type)
9598 -- When the operand is a selected access discriminant the check
9599 -- needs to be made against the level of the object denoted by
9600 -- the prefix of the selected name (Object_Access_Level handles
9601 -- checking the prefix of the operand for this case).
9603 if Nkind (Operand) = N_Selected_Component
9604 and then Object_Access_Level (Operand) >
9605 Type_Access_Level (Target_Type)
9607 -- In an instance, this is a run-time check, but one we know
9608 -- will fail, so generate an appropriate warning. The raise
9609 -- will be generated by Expand_N_Type_Conversion.
9611 if In_Instance_Body then
9613 ("?cannot convert access discriminant to non-local" &
9614 " access type", Operand);
9616 ("\?Program_Error will be raised at run time",
9621 ("cannot convert access discriminant to non-local" &
9622 " access type", Operand);
9627 -- The case of a reference to an access discriminant from
9628 -- within a limited type declaration (which will appear as
9629 -- a discriminal) is always illegal because the level of the
9630 -- discriminant is considered to be deeper than any (nameable)
9633 if Is_Entity_Name (Operand)
9634 and then (Ekind (Entity (Operand)) = E_In_Parameter
9635 or else Ekind (Entity (Operand)) = E_Constant)
9636 and then Present (Discriminal_Link (Entity (Operand)))
9639 ("discriminant has deeper accessibility level than target",
9646 -- In the presence of limited_with clauses we have to use non-limited
9647 -- views, if available.
9649 Check_Limited : declare
9650 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
9651 -- Helper function to handle limited views
9653 --------------------------
9654 -- Full_Designated_Type --
9655 --------------------------
9657 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
9658 Desig : constant Entity_Id := Designated_Type (T);
9661 -- Handle the limited view of a type
9663 if Is_Incomplete_Type (Desig)
9664 and then From_With_Type (Desig)
9665 and then Present (Non_Limited_View (Desig))
9667 return Available_View (Desig);
9671 end Full_Designated_Type;
9673 -- Local Declarations
9675 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
9676 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
9678 Same_Base : constant Boolean :=
9679 Base_Type (Target) = Base_Type (Opnd);
9681 -- Start of processing for Check_Limited
9684 if Is_Tagged_Type (Target) then
9685 return Valid_Tagged_Conversion (Target, Opnd);
9688 if not Same_Base then
9690 ("target designated type not compatible with }",
9691 N, Base_Type (Opnd));
9694 -- Ada 2005 AI-384: legality rule is symmetric in both
9695 -- designated types. The conversion is legal (with possible
9696 -- constraint check) if either designated type is
9699 elsif Subtypes_Statically_Match (Target, Opnd)
9701 (Has_Discriminants (Target)
9703 (not Is_Constrained (Opnd)
9704 or else not Is_Constrained (Target)))
9706 -- Special case, if Value_Size has been used to make the
9707 -- sizes different, the conversion is not allowed even
9708 -- though the subtypes statically match.
9710 if Known_Static_RM_Size (Target)
9711 and then Known_Static_RM_Size (Opnd)
9712 and then RM_Size (Target) /= RM_Size (Opnd)
9715 ("target designated subtype not compatible with }",
9718 ("\because sizes of the two designated subtypes differ",
9722 -- Normal case where conversion is allowed
9730 ("target designated subtype not compatible with }",
9737 -- Access to subprogram types. If the operand is an access parameter,
9738 -- the type has a deeper accessibility that any master, and cannot
9739 -- be assigned. We must make an exception if the conversion is part
9740 -- of an assignment and the target is the return object of an extended
9741 -- return statement, because in that case the accessibility check
9742 -- takes place after the return.
9744 elsif Is_Access_Subprogram_Type (Target_Type)
9745 and then No (Corresponding_Remote_Type (Opnd_Type))
9747 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
9748 and then Is_Entity_Name (Operand)
9749 and then Ekind (Entity (Operand)) = E_In_Parameter
9751 (Nkind (Parent (N)) /= N_Assignment_Statement
9752 or else not Is_Entity_Name (Name (Parent (N)))
9753 or else not Is_Return_Object (Entity (Name (Parent (N)))))
9756 ("illegal attempt to store anonymous access to subprogram",
9759 ("\value has deeper accessibility than any master " &
9764 ("\use named access type for& instead of access parameter",
9765 Operand, Entity (Operand));
9768 -- Check that the designated types are subtype conformant
9770 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
9771 Old_Id => Designated_Type (Opnd_Type),
9774 -- Check the static accessibility rule of 4.6(20)
9776 if Type_Access_Level (Opnd_Type) >
9777 Type_Access_Level (Target_Type)
9780 ("operand type has deeper accessibility level than target",
9783 -- Check that if the operand type is declared in a generic body,
9784 -- then the target type must be declared within that same body
9785 -- (enforces last sentence of 4.6(20)).
9787 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
9789 O_Gen : constant Node_Id :=
9790 Enclosing_Generic_Body (Opnd_Type);
9795 T_Gen := Enclosing_Generic_Body (Target_Type);
9796 while Present (T_Gen) and then T_Gen /= O_Gen loop
9797 T_Gen := Enclosing_Generic_Body (T_Gen);
9800 if T_Gen /= O_Gen then
9802 ("target type must be declared in same generic body"
9803 & " as operand type", N);
9810 -- Remote subprogram access types
9812 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
9813 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
9815 -- It is valid to convert from one RAS type to another provided
9816 -- that their specification statically match.
9818 Check_Subtype_Conformant
9820 Designated_Type (Corresponding_Remote_Type (Target_Type)),
9822 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
9827 -- If both are tagged types, check legality of view conversions
9829 elsif Is_Tagged_Type (Target_Type)
9830 and then Is_Tagged_Type (Opnd_Type)
9832 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
9834 -- Types derived from the same root type are convertible
9836 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
9839 -- In an instance or an inlined body, there may be inconsistent
9840 -- views of the same type, or of types derived from a common root.
9842 elsif (In_Instance or In_Inlined_Body)
9844 Root_Type (Underlying_Type (Target_Type)) =
9845 Root_Type (Underlying_Type (Opnd_Type))
9849 -- Special check for common access type error case
9851 elsif Ekind (Target_Type) = E_Access_Type
9852 and then Is_Access_Type (Opnd_Type)
9854 Error_Msg_N ("target type must be general access type!", N);
9855 Error_Msg_NE ("add ALL to }!", N, Target_Type);
9859 Error_Msg_NE ("invalid conversion, not compatible with }",
9863 end Valid_Conversion;