1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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_Aggr; use Sem_Aggr;
54 with Sem_Attr; use Sem_Attr;
55 with Sem_Cat; use Sem_Cat;
56 with Sem_Ch4; use Sem_Ch4;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch13; use Sem_Ch13;
60 with Sem_Disp; use Sem_Disp;
61 with Sem_Dist; use Sem_Dist;
62 with Sem_Elab; use Sem_Elab;
63 with Sem_Eval; use Sem_Eval;
64 with Sem_Intr; use Sem_Intr;
65 with Sem_Util; use Sem_Util;
66 with Sem_Type; use Sem_Type;
67 with Sem_Warn; use Sem_Warn;
68 with Sinfo; use Sinfo;
69 with Snames; use Snames;
70 with Stand; use Stand;
71 with Stringt; use Stringt;
72 with Style; use Style;
73 with Targparm; use Targparm;
74 with Tbuild; use Tbuild;
75 with Uintp; use Uintp;
76 with Urealp; use Urealp;
78 package body Sem_Res is
80 -----------------------
81 -- Local Subprograms --
82 -----------------------
84 -- Second pass (top-down) type checking and overload resolution procedures
85 -- Typ is the type required by context. These procedures propagate the
86 -- type information recursively to the descendants of N. If the node
87 -- is not overloaded, its Etype is established in the first pass. If
88 -- overloaded, the Resolve routines set the correct type. For arith.
89 -- operators, the Etype is the base type of the context.
91 -- Note that Resolve_Attribute is separated off in Sem_Attr
93 procedure Check_Discriminant_Use (N : Node_Id);
94 -- Enforce the restrictions on the use of discriminants when constraining
95 -- a component of a discriminated type (record or concurrent type).
97 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
98 -- Given a node for an operator associated with type T, check that
99 -- the operator is visible. Operators all of whose operands are
100 -- universal must be checked for visibility during resolution
101 -- because their type is not determinable based on their operands.
103 procedure Check_Fully_Declared_Prefix
106 -- Check that the type of the prefix of a dereference is not incomplete
108 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
109 -- Given a call node, N, which is known to occur immediately within the
110 -- subprogram being called, determines whether it is a detectable case of
111 -- an infinite recursion, and if so, outputs appropriate messages. Returns
112 -- True if an infinite recursion is detected, and False otherwise.
114 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
115 -- If the type of the object being initialized uses the secondary stack
116 -- directly or indirectly, create a transient scope for the call to the
117 -- init proc. This is because we do not create transient scopes for the
118 -- initialization of individual components within the init proc itself.
119 -- Could be optimized away perhaps?
121 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
122 -- Determine whether E is an access type declared by an access
123 -- declaration, and not an (anonymous) allocator type.
125 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
126 -- Utility to check whether the name in the call is a predefined
127 -- operator, in which case the call is made into an operator node.
128 -- An instance of an intrinsic conversion operation may be given
129 -- an operator name, but is not treated like an operator.
131 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
132 -- If a default expression in entry call N depends on the discriminants
133 -- of the task, it must be replaced with a reference to the discriminant
134 -- of the task being called.
136 procedure Resolve_Op_Concat_Arg
141 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
142 -- concatenation operator. The operand is either of the array type or of
143 -- the component type. If the operand is an aggregate, and the component
144 -- type is composite, this is ambiguous if component type has aggregates.
146 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
147 -- Does the first part of the work of Resolve_Op_Concat
149 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
150 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
151 -- has been resolved. See Resolve_Op_Concat for details.
153 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
154 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
155 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
156 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
157 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
158 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
159 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
160 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
161 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
162 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
163 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
164 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
165 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
166 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
167 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
168 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
169 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
170 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
171 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
172 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
173 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
174 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
175 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
176 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
177 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
178 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
179 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
180 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
186 function Operator_Kind
188 Is_Binary : Boolean) return Node_Kind;
189 -- Utility to map the name of an operator into the corresponding Node. Used
190 -- by other node rewriting procedures.
192 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
193 -- Resolve actuals of call, and add default expressions for missing ones.
194 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
195 -- called subprogram.
197 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
198 -- Called from Resolve_Call, when the prefix denotes an entry or element
199 -- of entry family. Actuals are resolved as for subprograms, and the node
200 -- is rebuilt as an entry call. Also called for protected operations. Typ
201 -- is the context type, which is used when the operation is a protected
202 -- function with no arguments, and the return value is indexed.
204 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
205 -- A call to a user-defined intrinsic operator is rewritten as a call
206 -- to the corresponding predefined operator, with suitable conversions.
208 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
209 -- Ditto, for unary operators (only arithmetic ones)
211 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
212 -- If an operator node resolves to a call to a user-defined operator,
213 -- rewrite the node as a function call.
215 procedure Make_Call_Into_Operator
219 -- Inverse transformation: if an operator is given in functional notation,
220 -- then after resolving the node, transform into an operator node, so
221 -- that operands are resolved properly. Recall that predefined operators
222 -- do not have a full signature and special resolution rules apply.
224 procedure Rewrite_Renamed_Operator
228 -- An operator can rename another, e.g. in an instantiation. In that
229 -- case, the proper operator node must be constructed and resolved.
231 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
232 -- The String_Literal_Subtype is built for all strings that are not
233 -- operands of a static concatenation operation. If the argument is
234 -- not a N_String_Literal node, then the call has no effect.
236 procedure Set_Slice_Subtype (N : Node_Id);
237 -- Build subtype of array type, with the range specified by the slice
239 procedure Simplify_Type_Conversion (N : Node_Id);
240 -- Called after N has been resolved and evaluated, but before range checks
241 -- have been applied. Currently simplifies a combination of floating-point
242 -- to integer conversion and Truncation attribute.
244 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
245 -- A universal_fixed expression in an universal context is unambiguous
246 -- if there is only one applicable fixed point type. Determining whether
247 -- there is only one requires a search over all visible entities, and
248 -- happens only in very pathological cases (see 6115-006).
250 function Valid_Conversion
253 Operand : Node_Id) return Boolean;
254 -- Verify legality rules given in 4.6 (8-23). Target is the target
255 -- type of the conversion, which may be an implicit conversion of
256 -- an actual parameter to an anonymous access type (in which case
257 -- N denotes the actual parameter and N = Operand).
259 -------------------------
260 -- Ambiguous_Character --
261 -------------------------
263 procedure Ambiguous_Character (C : Node_Id) is
267 if Nkind (C) = N_Character_Literal then
268 Error_Msg_N ("ambiguous character literal", C);
270 -- First the ones in Standard
273 ("\\possible interpretation: Character!", C);
275 ("\\possible interpretation: Wide_Character!", C);
277 -- Include Wide_Wide_Character in Ada 2005 mode
279 if Ada_Version >= Ada_05 then
281 ("\\possible interpretation: Wide_Wide_Character!", C);
284 -- Now any other types that match
286 E := Current_Entity (C);
287 while Present (E) loop
288 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
292 end Ambiguous_Character;
294 -------------------------
295 -- Analyze_And_Resolve --
296 -------------------------
298 procedure Analyze_And_Resolve (N : Node_Id) is
302 end Analyze_And_Resolve;
304 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
308 end Analyze_And_Resolve;
310 -- Version withs check(s) suppressed
312 procedure Analyze_And_Resolve
317 Scop : constant Entity_Id := Current_Scope;
320 if Suppress = All_Checks then
322 Svg : constant Suppress_Array := Scope_Suppress;
324 Scope_Suppress := (others => True);
325 Analyze_And_Resolve (N, Typ);
326 Scope_Suppress := Svg;
331 Svg : constant Boolean := Scope_Suppress (Suppress);
334 Scope_Suppress (Suppress) := True;
335 Analyze_And_Resolve (N, Typ);
336 Scope_Suppress (Suppress) := Svg;
340 if Current_Scope /= Scop
341 and then Scope_Is_Transient
343 -- This can only happen if a transient scope was created
344 -- for an inner expression, which will be removed upon
345 -- completion of the analysis of an enclosing construct.
346 -- The transient scope must have the suppress status of
347 -- the enclosing environment, not of this Analyze call.
349 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
352 end Analyze_And_Resolve;
354 procedure Analyze_And_Resolve
358 Scop : constant Entity_Id := Current_Scope;
361 if Suppress = All_Checks then
363 Svg : constant Suppress_Array := Scope_Suppress;
365 Scope_Suppress := (others => True);
366 Analyze_And_Resolve (N);
367 Scope_Suppress := Svg;
372 Svg : constant Boolean := Scope_Suppress (Suppress);
375 Scope_Suppress (Suppress) := True;
376 Analyze_And_Resolve (N);
377 Scope_Suppress (Suppress) := Svg;
381 if Current_Scope /= Scop
382 and then Scope_Is_Transient
384 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
387 end Analyze_And_Resolve;
389 ----------------------------
390 -- Check_Discriminant_Use --
391 ----------------------------
393 procedure Check_Discriminant_Use (N : Node_Id) is
394 PN : constant Node_Id := Parent (N);
395 Disc : constant Entity_Id := Entity (N);
400 -- Any use in a spec-expression is legal
402 if In_Spec_Expression then
405 elsif Nkind (PN) = N_Range then
407 -- Discriminant cannot be used to constrain a scalar type
411 if Nkind (P) = N_Range_Constraint
412 and then Nkind (Parent (P)) = N_Subtype_Indication
413 and then Nkind (Parent (Parent (P))) = N_Component_Definition
415 Error_Msg_N ("discriminant cannot constrain scalar type", N);
417 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
419 -- The following check catches the unusual case where
420 -- a discriminant appears within an index constraint
421 -- that is part of a larger expression within a constraint
422 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
423 -- For now we only check case of record components, and
424 -- note that a similar check should also apply in the
425 -- case of discriminant constraints below. ???
427 -- Note that the check for N_Subtype_Declaration below is to
428 -- detect the valid use of discriminants in the constraints of a
429 -- subtype declaration when this subtype declaration appears
430 -- inside the scope of a record type (which is syntactically
431 -- illegal, but which may be created as part of derived type
432 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
435 if Ekind (Current_Scope) = E_Record_Type
436 and then Scope (Disc) = Current_Scope
438 (Nkind (Parent (P)) = N_Subtype_Indication
440 Nkind_In (Parent (Parent (P)), N_Component_Definition,
441 N_Subtype_Declaration)
442 and then Paren_Count (N) = 0)
445 ("discriminant must appear alone in component constraint", N);
449 -- Detect a common beginner error:
451 -- type R (D : Positive := 100) is record
452 -- Name : String (1 .. D);
455 -- The default value causes an object of type R to be
456 -- allocated with room for Positive'Last characters.
464 function Large_Storage_Type (T : Entity_Id) return Boolean;
465 -- Return True if type T has a large enough range that
466 -- any array whose index type covered the whole range of
467 -- the type would likely raise Storage_Error.
469 ------------------------
470 -- Large_Storage_Type --
471 ------------------------
473 function Large_Storage_Type (T : Entity_Id) return Boolean is
475 -- The type is considered large if its bounds are known at
476 -- compile time and if it requires at least as many bits as
477 -- a Positive to store the possible values.
479 return Compile_Time_Known_Value (Type_Low_Bound (T))
480 and then Compile_Time_Known_Value (Type_High_Bound (T))
482 Minimum_Size (T, Biased => True) >=
483 Esize (Standard_Integer) - 1;
484 end Large_Storage_Type;
487 -- Check that the Disc has a large range
489 if not Large_Storage_Type (Etype (Disc)) then
493 -- If the enclosing type is limited, we allocate only the
494 -- default value, not the maximum, and there is no need for
497 if Is_Limited_Type (Scope (Disc)) then
501 -- Check that it is the high bound
503 if N /= High_Bound (PN)
504 or else No (Discriminant_Default_Value (Disc))
509 -- Check the array allows a large range at this bound.
510 -- First find the array
514 if Nkind (SI) /= N_Subtype_Indication then
518 T := Entity (Subtype_Mark (SI));
520 if not Is_Array_Type (T) then
524 -- Next, find the dimension
526 TB := First_Index (T);
527 CB := First (Constraints (P));
529 and then Present (TB)
530 and then Present (CB)
541 -- Now, check the dimension has a large range
543 if not Large_Storage_Type (Etype (TB)) then
547 -- Warn about the danger
550 ("?creation of & object may raise Storage_Error!",
559 -- Legal case is in index or discriminant constraint
561 elsif Nkind_In (PN, N_Index_Or_Discriminant_Constraint,
562 N_Discriminant_Association)
564 if Paren_Count (N) > 0 then
566 ("discriminant in constraint must appear alone", N);
568 elsif Nkind (N) = N_Expanded_Name
569 and then Comes_From_Source (N)
572 ("discriminant must appear alone as a direct name", N);
577 -- Otherwise, context is an expression. It should not be within
578 -- (i.e. a subexpression of) a constraint for a component.
583 while not Nkind_In (P, N_Component_Declaration,
584 N_Subtype_Indication,
592 -- If the discriminant is used in an expression that is a bound
593 -- of a scalar type, an Itype is created and the bounds are attached
594 -- to its range, not to the original subtype indication. Such use
595 -- is of course a double fault.
597 if (Nkind (P) = N_Subtype_Indication
598 and then Nkind_In (Parent (P), N_Component_Definition,
599 N_Derived_Type_Definition)
600 and then D = Constraint (P))
602 -- The constraint itself may be given by a subtype indication,
603 -- rather than by a more common discrete range.
605 or else (Nkind (P) = N_Subtype_Indication
607 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
608 or else Nkind (P) = N_Entry_Declaration
609 or else Nkind (D) = N_Defining_Identifier
612 ("discriminant in constraint must appear alone", N);
615 end Check_Discriminant_Use;
617 --------------------------------
618 -- Check_For_Visible_Operator --
619 --------------------------------
621 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
623 if Is_Invisible_Operator (N, T) then
625 ("operator for} is not directly visible!", N, First_Subtype (T));
626 Error_Msg_N ("use clause would make operation legal!", N);
628 end Check_For_Visible_Operator;
630 ----------------------------------
631 -- Check_Fully_Declared_Prefix --
632 ----------------------------------
634 procedure Check_Fully_Declared_Prefix
639 -- Check that the designated type of the prefix of a dereference is
640 -- not an incomplete type. This cannot be done unconditionally, because
641 -- dereferences of private types are legal in default expressions. This
642 -- case is taken care of in Check_Fully_Declared, called below. There
643 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
645 -- This consideration also applies to similar checks for allocators,
646 -- qualified expressions, and type conversions.
648 -- An additional exception concerns other per-object expressions that
649 -- are not directly related to component declarations, in particular
650 -- representation pragmas for tasks. These will be per-object
651 -- expressions if they depend on discriminants or some global entity.
652 -- If the task has access discriminants, the designated type may be
653 -- incomplete at the point the expression is resolved. This resolution
654 -- takes place within the body of the initialization procedure, where
655 -- the discriminant is replaced by its discriminal.
657 if Is_Entity_Name (Pref)
658 and then Ekind (Entity (Pref)) = E_In_Parameter
662 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
663 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
664 -- Analyze_Object_Renaming, and Freeze_Entity.
666 elsif Ada_Version >= Ada_05
667 and then Is_Entity_Name (Pref)
668 and then Ekind (Directly_Designated_Type (Etype (Pref))) =
670 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Pref)))
674 Check_Fully_Declared (Typ, Parent (Pref));
676 end Check_Fully_Declared_Prefix;
678 ------------------------------
679 -- Check_Infinite_Recursion --
680 ------------------------------
682 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
686 function Same_Argument_List return Boolean;
687 -- Check whether list of actuals is identical to list of formals
688 -- of called function (which is also the enclosing scope).
690 ------------------------
691 -- Same_Argument_List --
692 ------------------------
694 function Same_Argument_List return Boolean is
700 if not Is_Entity_Name (Name (N)) then
703 Subp := Entity (Name (N));
706 F := First_Formal (Subp);
707 A := First_Actual (N);
708 while Present (F) and then Present (A) loop
709 if not Is_Entity_Name (A)
710 or else Entity (A) /= F
720 end Same_Argument_List;
722 -- Start of processing for Check_Infinite_Recursion
725 -- Special case, if this is a procedure call and is a call to the
726 -- current procedure with the same argument list, then this is for
727 -- sure an infinite recursion and we insert a call to raise SE.
729 if Is_List_Member (N)
730 and then List_Length (List_Containing (N)) = 1
731 and then Same_Argument_List
734 P : constant Node_Id := Parent (N);
736 if Nkind (P) = N_Handled_Sequence_Of_Statements
737 and then Nkind (Parent (P)) = N_Subprogram_Body
738 and then Is_Empty_List (Declarations (Parent (P)))
740 Error_Msg_N ("!?infinite recursion", N);
741 Error_Msg_N ("\!?Storage_Error will be raised at run time", N);
743 Make_Raise_Storage_Error (Sloc (N),
744 Reason => SE_Infinite_Recursion));
750 -- If not that special case, search up tree, quitting if we reach a
751 -- construct (e.g. a conditional) that tells us that this is not a
752 -- case for an infinite recursion warning.
758 -- If no parent, then we were not inside a subprogram, this can for
759 -- example happen when processing certain pragmas in a spec. Just
760 -- return False in this case.
766 -- Done if we get to subprogram body, this is definitely an infinite
767 -- recursion case if we did not find anything to stop us.
769 exit when Nkind (P) = N_Subprogram_Body;
771 -- If appearing in conditional, result is false
773 if Nkind_In (P, N_Or_Else,
780 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
781 and then C /= First (Statements (P))
783 -- If the call is the expression of a return statement and the
784 -- actuals are identical to the formals, it's worth a warning.
785 -- However, we skip this if there is an immediately preceding
786 -- raise statement, since the call is never executed.
788 -- Furthermore, this corresponds to a common idiom:
790 -- function F (L : Thing) return Boolean is
792 -- raise Program_Error;
796 -- for generating a stub function
798 if Nkind (Parent (N)) = N_Simple_Return_Statement
799 and then Same_Argument_List
801 exit when not Is_List_Member (Parent (N));
803 -- OK, return statement is in a statement list, look for raise
809 -- Skip past N_Freeze_Entity nodes generated by expansion
811 Nod := Prev (Parent (N));
813 and then Nkind (Nod) = N_Freeze_Entity
818 -- If no raise statement, give warning
820 exit when Nkind (Nod) /= N_Raise_Statement
822 (Nkind (Nod) not in N_Raise_xxx_Error
823 or else Present (Condition (Nod)));
834 Error_Msg_N ("!?possible infinite recursion", N);
835 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
838 end Check_Infinite_Recursion;
840 -------------------------------
841 -- Check_Initialization_Call --
842 -------------------------------
844 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
845 Typ : constant Entity_Id := Etype (First_Formal (Nam));
847 function Uses_SS (T : Entity_Id) return Boolean;
848 -- Check whether the creation of an object of the type will involve
849 -- use of the secondary stack. If T is a record type, this is true
850 -- if the expression for some component uses the secondary stack, e.g.
851 -- through a call to a function that returns an unconstrained value.
852 -- False if T is controlled, because cleanups occur elsewhere.
858 function Uses_SS (T : Entity_Id) return Boolean is
861 Full_Type : Entity_Id := Underlying_Type (T);
864 -- Normally we want to use the underlying type, but if it's not set
865 -- then continue with T.
867 if not Present (Full_Type) then
871 if Is_Controlled (Full_Type) then
874 elsif Is_Array_Type (Full_Type) then
875 return Uses_SS (Component_Type (Full_Type));
877 elsif Is_Record_Type (Full_Type) then
878 Comp := First_Component (Full_Type);
879 while Present (Comp) loop
880 if Ekind (Comp) = E_Component
881 and then Nkind (Parent (Comp)) = N_Component_Declaration
883 -- The expression for a dynamic component may be rewritten
884 -- as a dereference, so retrieve original node.
886 Expr := Original_Node (Expression (Parent (Comp)));
888 -- Return True if the expression is a call to a function
889 -- (including an attribute function such as Image) with
890 -- a result that requires a transient scope.
892 if (Nkind (Expr) = N_Function_Call
893 or else (Nkind (Expr) = N_Attribute_Reference
894 and then Present (Expressions (Expr))))
895 and then Requires_Transient_Scope (Etype (Expr))
899 elsif Uses_SS (Etype (Comp)) then
904 Next_Component (Comp);
914 -- Start of processing for Check_Initialization_Call
917 -- Establish a transient scope if the type needs it
919 if Uses_SS (Typ) then
920 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
922 end Check_Initialization_Call;
924 ------------------------------
925 -- Check_Parameterless_Call --
926 ------------------------------
928 procedure Check_Parameterless_Call (N : Node_Id) is
931 function Prefix_Is_Access_Subp return Boolean;
932 -- If the prefix is of an access_to_subprogram type, the node must be
933 -- rewritten as a call. Ditto if the prefix is overloaded and all its
934 -- interpretations are access to subprograms.
936 ---------------------------
937 -- Prefix_Is_Access_Subp --
938 ---------------------------
940 function Prefix_Is_Access_Subp return Boolean is
945 if not Is_Overloaded (N) then
947 Ekind (Etype (N)) = E_Subprogram_Type
948 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
950 Get_First_Interp (N, I, It);
951 while Present (It.Typ) loop
952 if Ekind (It.Typ) /= E_Subprogram_Type
953 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
958 Get_Next_Interp (I, It);
963 end Prefix_Is_Access_Subp;
965 -- Start of processing for Check_Parameterless_Call
968 -- Defend against junk stuff if errors already detected
970 if Total_Errors_Detected /= 0 then
971 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
973 elsif Nkind (N) in N_Has_Chars
974 and then Chars (N) in Error_Name_Or_No_Name
982 -- If the context expects a value, and the name is a procedure, this is
983 -- most likely a missing 'Access. Don't try to resolve the parameterless
984 -- call, error will be caught when the outer call is analyzed.
986 if Is_Entity_Name (N)
987 and then Ekind (Entity (N)) = E_Procedure
988 and then not Is_Overloaded (N)
990 Nkind_In (Parent (N), N_Parameter_Association,
992 N_Procedure_Call_Statement)
997 -- Rewrite as call if overloadable entity that is (or could be, in the
998 -- overloaded case) a function call. If we know for sure that the entity
999 -- is an enumeration literal, we do not rewrite it.
1001 if (Is_Entity_Name (N)
1002 and then Is_Overloadable (Entity (N))
1003 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1004 or else Is_Overloaded (N)))
1006 -- Rewrite as call if it is an explicit deference of an expression of
1007 -- a subprogram access type, and the subprogram type is not that of a
1008 -- procedure or entry.
1011 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1013 -- Rewrite as call if it is a selected component which is a function,
1014 -- this is the case of a call to a protected function (which may be
1015 -- overloaded with other protected operations).
1018 (Nkind (N) = N_Selected_Component
1019 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1021 ((Ekind (Entity (Selector_Name (N))) = E_Entry
1023 Ekind (Entity (Selector_Name (N))) = E_Procedure)
1024 and then Is_Overloaded (Selector_Name (N)))))
1026 -- If one of the above three conditions is met, rewrite as call.
1027 -- Apply the rewriting only once.
1030 if Nkind (Parent (N)) /= N_Function_Call
1031 or else N /= Name (Parent (N))
1033 Nam := New_Copy (N);
1035 -- If overloaded, overload set belongs to new copy
1037 Save_Interps (N, Nam);
1039 -- Change node to parameterless function call (note that the
1040 -- Parameter_Associations associations field is left set to Empty,
1041 -- its normal default value since there are no parameters)
1043 Change_Node (N, N_Function_Call);
1045 Set_Sloc (N, Sloc (Nam));
1049 elsif Nkind (N) = N_Parameter_Association then
1050 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1052 end Check_Parameterless_Call;
1054 -----------------------------
1055 -- Is_Definite_Access_Type --
1056 -----------------------------
1058 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1059 Btyp : constant Entity_Id := Base_Type (E);
1061 return Ekind (Btyp) = E_Access_Type
1062 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1063 and then Comes_From_Source (Btyp));
1064 end Is_Definite_Access_Type;
1066 ----------------------
1067 -- Is_Predefined_Op --
1068 ----------------------
1070 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1072 return Is_Intrinsic_Subprogram (Nam)
1073 and then not Is_Generic_Instance (Nam)
1074 and then Chars (Nam) in Any_Operator_Name
1075 and then (No (Alias (Nam))
1076 or else Is_Predefined_Op (Alias (Nam)));
1077 end Is_Predefined_Op;
1079 -----------------------------
1080 -- Make_Call_Into_Operator --
1081 -----------------------------
1083 procedure Make_Call_Into_Operator
1088 Op_Name : constant Name_Id := Chars (Op_Id);
1089 Act1 : Node_Id := First_Actual (N);
1090 Act2 : Node_Id := Next_Actual (Act1);
1091 Error : Boolean := False;
1092 Func : constant Entity_Id := Entity (Name (N));
1093 Is_Binary : constant Boolean := Present (Act2);
1095 Opnd_Type : Entity_Id;
1096 Orig_Type : Entity_Id := Empty;
1099 type Kind_Test is access function (E : Entity_Id) return Boolean;
1101 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1102 -- If the operand is not universal, and the operator is given by a
1103 -- expanded name, verify that the operand has an interpretation with
1104 -- a type defined in the given scope of the operator.
1106 function Type_In_P (Test : Kind_Test) return Entity_Id;
1107 -- Find a type of the given class in the package Pack that contains
1110 ---------------------------
1111 -- Operand_Type_In_Scope --
1112 ---------------------------
1114 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1115 Nod : constant Node_Id := Right_Opnd (Op_Node);
1120 if not Is_Overloaded (Nod) then
1121 return Scope (Base_Type (Etype (Nod))) = S;
1124 Get_First_Interp (Nod, I, It);
1125 while Present (It.Typ) loop
1126 if Scope (Base_Type (It.Typ)) = S then
1130 Get_Next_Interp (I, It);
1135 end Operand_Type_In_Scope;
1141 function Type_In_P (Test : Kind_Test) return Entity_Id is
1144 function In_Decl return Boolean;
1145 -- Verify that node is not part of the type declaration for the
1146 -- candidate type, which would otherwise be invisible.
1152 function In_Decl return Boolean is
1153 Decl_Node : constant Node_Id := Parent (E);
1159 if Etype (E) = Any_Type then
1162 elsif No (Decl_Node) then
1167 and then Nkind (N2) /= N_Compilation_Unit
1169 if N2 = Decl_Node then
1180 -- Start of processing for Type_In_P
1183 -- If the context type is declared in the prefix package, this
1184 -- is the desired base type.
1186 if Scope (Base_Type (Typ)) = Pack
1189 return Base_Type (Typ);
1192 E := First_Entity (Pack);
1193 while Present (E) loop
1195 and then not In_Decl
1207 -- Start of processing for Make_Call_Into_Operator
1210 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1215 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1216 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1217 Save_Interps (Act1, Left_Opnd (Op_Node));
1218 Save_Interps (Act2, Right_Opnd (Op_Node));
1219 Act1 := Left_Opnd (Op_Node);
1220 Act2 := Right_Opnd (Op_Node);
1225 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1226 Save_Interps (Act1, Right_Opnd (Op_Node));
1227 Act1 := Right_Opnd (Op_Node);
1230 -- If the operator is denoted by an expanded name, and the prefix is
1231 -- not Standard, but the operator is a predefined one whose scope is
1232 -- Standard, then this is an implicit_operator, inserted as an
1233 -- interpretation by the procedure of the same name. This procedure
1234 -- overestimates the presence of implicit operators, because it does
1235 -- not examine the type of the operands. Verify now that the operand
1236 -- type appears in the given scope. If right operand is universal,
1237 -- check the other operand. In the case of concatenation, either
1238 -- argument can be the component type, so check the type of the result.
1239 -- If both arguments are literals, look for a type of the right kind
1240 -- defined in the given scope. This elaborate nonsense is brought to
1241 -- you courtesy of b33302a. The type itself must be frozen, so we must
1242 -- find the type of the proper class in the given scope.
1244 -- A final wrinkle is the multiplication operator for fixed point
1245 -- types, which is defined in Standard only, and not in the scope of
1246 -- the fixed_point type itself.
1248 if Nkind (Name (N)) = N_Expanded_Name then
1249 Pack := Entity (Prefix (Name (N)));
1251 -- If the entity being called is defined in the given package,
1252 -- it is a renaming of a predefined operator, and known to be
1255 if Scope (Entity (Name (N))) = Pack
1256 and then Pack /= Standard_Standard
1260 -- Visibility does not need to be checked in an instance: if the
1261 -- operator was not visible in the generic it has been diagnosed
1262 -- already, else there is an implicit copy of it in the instance.
1264 elsif In_Instance then
1267 elsif (Op_Name = Name_Op_Multiply
1268 or else Op_Name = Name_Op_Divide)
1269 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1270 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1272 if Pack /= Standard_Standard then
1276 -- Ada 2005, AI-420: Predefined equality on Universal_Access
1279 elsif Ada_Version >= Ada_05
1280 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1281 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1286 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1288 if Op_Name = Name_Op_Concat then
1289 Opnd_Type := Base_Type (Typ);
1291 elsif (Scope (Opnd_Type) = Standard_Standard
1293 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1295 and then not Comes_From_Source (Opnd_Type))
1297 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1300 if Scope (Opnd_Type) = Standard_Standard then
1302 -- Verify that the scope contains a type that corresponds to
1303 -- the given literal. Optimize the case where Pack is Standard.
1305 if Pack /= Standard_Standard then
1307 if Opnd_Type = Universal_Integer then
1308 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1310 elsif Opnd_Type = Universal_Real then
1311 Orig_Type := Type_In_P (Is_Real_Type'Access);
1313 elsif Opnd_Type = Any_String then
1314 Orig_Type := Type_In_P (Is_String_Type'Access);
1316 elsif Opnd_Type = Any_Access then
1317 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1319 elsif Opnd_Type = Any_Composite then
1320 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1322 if Present (Orig_Type) then
1323 if Has_Private_Component (Orig_Type) then
1326 Set_Etype (Act1, Orig_Type);
1329 Set_Etype (Act2, Orig_Type);
1338 Error := No (Orig_Type);
1341 elsif Ekind (Opnd_Type) = E_Allocator_Type
1342 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1346 -- If the type is defined elsewhere, and the operator is not
1347 -- defined in the given scope (by a renaming declaration, e.g.)
1348 -- then this is an error as well. If an extension of System is
1349 -- present, and the type may be defined there, Pack must be
1352 elsif Scope (Opnd_Type) /= Pack
1353 and then Scope (Op_Id) /= Pack
1354 and then (No (System_Aux_Id)
1355 or else Scope (Opnd_Type) /= System_Aux_Id
1356 or else Pack /= Scope (System_Aux_Id))
1358 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1361 Error := not Operand_Type_In_Scope (Pack);
1364 elsif Pack = Standard_Standard
1365 and then not Operand_Type_In_Scope (Standard_Standard)
1372 Error_Msg_Node_2 := Pack;
1374 ("& not declared in&", N, Selector_Name (Name (N)));
1375 Set_Etype (N, Any_Type);
1380 Set_Chars (Op_Node, Op_Name);
1382 if not Is_Private_Type (Etype (N)) then
1383 Set_Etype (Op_Node, Base_Type (Etype (N)));
1385 Set_Etype (Op_Node, Etype (N));
1388 -- If this is a call to a function that renames a predefined equality,
1389 -- the renaming declaration provides a type that must be used to
1390 -- resolve the operands. This must be done now because resolution of
1391 -- the equality node will not resolve any remaining ambiguity, and it
1392 -- assumes that the first operand is not overloaded.
1394 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1395 and then Ekind (Func) = E_Function
1396 and then Is_Overloaded (Act1)
1398 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1399 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1402 Set_Entity (Op_Node, Op_Id);
1403 Generate_Reference (Op_Id, N, ' ');
1405 -- Do rewrite setting Comes_From_Source on the result if the original
1406 -- call came from source. Although it is not strictly the case that the
1407 -- operator as such comes from the source, logically it corresponds
1408 -- exactly to the function call in the source, so it should be marked
1409 -- this way (e.g. to make sure that validity checks work fine).
1412 CS : constant Boolean := Comes_From_Source (N);
1414 Rewrite (N, Op_Node);
1415 Set_Comes_From_Source (N, CS);
1418 -- If this is an arithmetic operator and the result type is private,
1419 -- the operands and the result must be wrapped in conversion to
1420 -- expose the underlying numeric type and expand the proper checks,
1421 -- e.g. on division.
1423 if Is_Private_Type (Typ) then
1425 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1426 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1427 Resolve_Intrinsic_Operator (N, Typ);
1429 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1430 Resolve_Intrinsic_Unary_Operator (N, Typ);
1439 -- For predefined operators on literals, the operation freezes
1442 if Present (Orig_Type) then
1443 Set_Etype (Act1, Orig_Type);
1444 Freeze_Expression (Act1);
1446 end Make_Call_Into_Operator;
1452 function Operator_Kind
1454 Is_Binary : Boolean) return Node_Kind
1460 if Op_Name = Name_Op_And then
1462 elsif Op_Name = Name_Op_Or then
1464 elsif Op_Name = Name_Op_Xor then
1466 elsif Op_Name = Name_Op_Eq then
1468 elsif Op_Name = Name_Op_Ne then
1470 elsif Op_Name = Name_Op_Lt then
1472 elsif Op_Name = Name_Op_Le then
1474 elsif Op_Name = Name_Op_Gt then
1476 elsif Op_Name = Name_Op_Ge then
1478 elsif Op_Name = Name_Op_Add then
1480 elsif Op_Name = Name_Op_Subtract then
1481 Kind := N_Op_Subtract;
1482 elsif Op_Name = Name_Op_Concat then
1483 Kind := N_Op_Concat;
1484 elsif Op_Name = Name_Op_Multiply then
1485 Kind := N_Op_Multiply;
1486 elsif Op_Name = Name_Op_Divide then
1487 Kind := N_Op_Divide;
1488 elsif Op_Name = Name_Op_Mod then
1490 elsif Op_Name = Name_Op_Rem then
1492 elsif Op_Name = Name_Op_Expon then
1495 raise Program_Error;
1501 if Op_Name = Name_Op_Add then
1503 elsif Op_Name = Name_Op_Subtract then
1505 elsif Op_Name = Name_Op_Abs then
1507 elsif Op_Name = Name_Op_Not then
1510 raise Program_Error;
1517 ----------------------------
1518 -- Preanalyze_And_Resolve --
1519 ----------------------------
1521 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1522 Save_Full_Analysis : constant Boolean := Full_Analysis;
1525 Full_Analysis := False;
1526 Expander_Mode_Save_And_Set (False);
1528 -- We suppress all checks for this analysis, since the checks will
1529 -- be applied properly, and in the right location, when the default
1530 -- expression is reanalyzed and reexpanded later on.
1532 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1534 Expander_Mode_Restore;
1535 Full_Analysis := Save_Full_Analysis;
1536 end Preanalyze_And_Resolve;
1538 -- Version without context type
1540 procedure Preanalyze_And_Resolve (N : Node_Id) is
1541 Save_Full_Analysis : constant Boolean := Full_Analysis;
1544 Full_Analysis := False;
1545 Expander_Mode_Save_And_Set (False);
1548 Resolve (N, Etype (N), Suppress => All_Checks);
1550 Expander_Mode_Restore;
1551 Full_Analysis := Save_Full_Analysis;
1552 end Preanalyze_And_Resolve;
1554 ----------------------------------
1555 -- Replace_Actual_Discriminants --
1556 ----------------------------------
1558 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1559 Loc : constant Source_Ptr := Sloc (N);
1560 Tsk : Node_Id := Empty;
1562 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1568 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1572 if Nkind (Nod) = N_Identifier then
1573 Ent := Entity (Nod);
1576 and then Ekind (Ent) = E_Discriminant
1579 Make_Selected_Component (Loc,
1580 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1581 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1583 Set_Etype (Nod, Etype (Ent));
1591 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1593 -- Start of processing for Replace_Actual_Discriminants
1596 if not Expander_Active then
1600 if Nkind (Name (N)) = N_Selected_Component then
1601 Tsk := Prefix (Name (N));
1603 elsif Nkind (Name (N)) = N_Indexed_Component then
1604 Tsk := Prefix (Prefix (Name (N)));
1610 Replace_Discrs (Default);
1612 end Replace_Actual_Discriminants;
1618 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1619 Ambiguous : Boolean := False;
1620 Ctx_Type : Entity_Id := Typ;
1621 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1622 Err_Type : Entity_Id := Empty;
1623 Found : Boolean := False;
1626 I1 : Interp_Index := 0; -- prevent junk warning
1629 Seen : Entity_Id := Empty; -- prevent junk warning
1631 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1632 -- Determine whether a node comes from a predefined library unit or
1635 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1636 -- Try and fix up a literal so that it matches its expected type. New
1637 -- literals are manufactured if necessary to avoid cascaded errors.
1639 procedure Resolution_Failed;
1640 -- Called when attempt at resolving current expression fails
1642 ------------------------------------
1643 -- Comes_From_Predefined_Lib_Unit --
1644 -------------------------------------
1646 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1649 Sloc (Nod) = Standard_Location
1650 or else Is_Predefined_File_Name (Unit_File_Name (
1651 Get_Source_Unit (Sloc (Nod))));
1652 end Comes_From_Predefined_Lib_Unit;
1654 --------------------
1655 -- Patch_Up_Value --
1656 --------------------
1658 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1660 if Nkind (N) = N_Integer_Literal
1661 and then Is_Real_Type (Typ)
1664 Make_Real_Literal (Sloc (N),
1665 Realval => UR_From_Uint (Intval (N))));
1666 Set_Etype (N, Universal_Real);
1667 Set_Is_Static_Expression (N);
1669 elsif Nkind (N) = N_Real_Literal
1670 and then Is_Integer_Type (Typ)
1673 Make_Integer_Literal (Sloc (N),
1674 Intval => UR_To_Uint (Realval (N))));
1675 Set_Etype (N, Universal_Integer);
1676 Set_Is_Static_Expression (N);
1678 elsif Nkind (N) = N_String_Literal
1679 and then Is_Character_Type (Typ)
1681 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1683 Make_Character_Literal (Sloc (N),
1685 Char_Literal_Value =>
1686 UI_From_Int (Character'Pos ('A'))));
1687 Set_Etype (N, Any_Character);
1688 Set_Is_Static_Expression (N);
1690 elsif Nkind (N) /= N_String_Literal
1691 and then Is_String_Type (Typ)
1694 Make_String_Literal (Sloc (N),
1695 Strval => End_String));
1697 elsif Nkind (N) = N_Range then
1698 Patch_Up_Value (Low_Bound (N), Typ);
1699 Patch_Up_Value (High_Bound (N), Typ);
1703 -----------------------
1704 -- Resolution_Failed --
1705 -----------------------
1707 procedure Resolution_Failed is
1709 Patch_Up_Value (N, Typ);
1711 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1712 Set_Is_Overloaded (N, False);
1714 -- The caller will return without calling the expander, so we need
1715 -- to set the analyzed flag. Note that it is fine to set Analyzed
1716 -- to True even if we are in the middle of a shallow analysis,
1717 -- (see the spec of sem for more details) since this is an error
1718 -- situation anyway, and there is no point in repeating the
1719 -- analysis later (indeed it won't work to repeat it later, since
1720 -- we haven't got a clear resolution of which entity is being
1723 Set_Analyzed (N, True);
1725 end Resolution_Failed;
1727 -- Start of processing for Resolve
1734 -- Access attribute on remote subprogram cannot be used for
1735 -- a non-remote access-to-subprogram type.
1737 if Nkind (N) = N_Attribute_Reference
1738 and then (Attribute_Name (N) = Name_Access
1739 or else Attribute_Name (N) = Name_Unrestricted_Access
1740 or else Attribute_Name (N) = Name_Unchecked_Access)
1741 and then Comes_From_Source (N)
1742 and then Is_Entity_Name (Prefix (N))
1743 and then Is_Subprogram (Entity (Prefix (N)))
1744 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1745 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1748 ("prefix must statically denote a non-remote subprogram", N);
1751 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1753 -- If the context is a Remote_Access_To_Subprogram, access attributes
1754 -- must be resolved with the corresponding fat pointer. There is no need
1755 -- to check for the attribute name since the return type of an
1756 -- attribute is never a remote type.
1758 if Nkind (N) = N_Attribute_Reference
1759 and then Comes_From_Source (N)
1760 and then (Is_Remote_Call_Interface (Typ)
1761 or else Is_Remote_Types (Typ))
1764 Attr : constant Attribute_Id :=
1765 Get_Attribute_Id (Attribute_Name (N));
1766 Pref : constant Node_Id := Prefix (N);
1769 Is_Remote : Boolean := True;
1772 -- Check that Typ is a remote access-to-subprogram type
1774 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1775 -- Prefix (N) must statically denote a remote subprogram
1776 -- declared in a package specification.
1778 if Attr = Attribute_Access then
1779 Decl := Unit_Declaration_Node (Entity (Pref));
1781 if Nkind (Decl) = N_Subprogram_Body then
1782 Spec := Corresponding_Spec (Decl);
1784 if not No (Spec) then
1785 Decl := Unit_Declaration_Node (Spec);
1789 Spec := Parent (Decl);
1791 if not Is_Entity_Name (Prefix (N))
1792 or else Nkind (Spec) /= N_Package_Specification
1794 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1798 ("prefix must statically denote a remote subprogram ",
1803 -- If we are generating code for a distributed program.
1804 -- perform semantic checks against the corresponding
1807 if (Attr = Attribute_Access
1808 or else Attr = Attribute_Unchecked_Access
1809 or else Attr = Attribute_Unrestricted_Access)
1810 and then Expander_Active
1811 and then Get_PCS_Name /= Name_No_DSA
1813 Check_Subtype_Conformant
1814 (New_Id => Entity (Prefix (N)),
1815 Old_Id => Designated_Type
1816 (Corresponding_Remote_Type (Typ)),
1820 Process_Remote_AST_Attribute (N, Typ);
1827 Debug_A_Entry ("resolving ", N);
1829 if Comes_From_Source (N) then
1830 if Is_Fixed_Point_Type (Typ) then
1831 Check_Restriction (No_Fixed_Point, N);
1833 elsif Is_Floating_Point_Type (Typ)
1834 and then Typ /= Universal_Real
1835 and then Typ /= Any_Real
1837 Check_Restriction (No_Floating_Point, N);
1841 -- Return if already analyzed
1843 if Analyzed (N) then
1844 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1847 -- Return if type = Any_Type (previous error encountered)
1849 elsif Etype (N) = Any_Type then
1850 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1854 Check_Parameterless_Call (N);
1856 -- If not overloaded, then we know the type, and all that needs doing
1857 -- is to check that this type is compatible with the context.
1859 if not Is_Overloaded (N) then
1860 Found := Covers (Typ, Etype (N));
1861 Expr_Type := Etype (N);
1863 -- In the overloaded case, we must select the interpretation that
1864 -- is compatible with the context (i.e. the type passed to Resolve)
1867 -- Loop through possible interpretations
1869 Get_First_Interp (N, I, It);
1870 Interp_Loop : while Present (It.Typ) loop
1872 -- We are only interested in interpretations that are compatible
1873 -- with the expected type, any other interpretations are ignored.
1875 if not Covers (Typ, It.Typ) then
1876 if Debug_Flag_V then
1877 Write_Str (" interpretation incompatible with context");
1882 -- Skip the current interpretation if it is disabled by an
1883 -- abstract operator. This action is performed only when the
1884 -- type against which we are resolving is the same as the
1885 -- type of the interpretation.
1887 if Ada_Version >= Ada_05
1888 and then It.Typ = Typ
1889 and then Typ /= Universal_Integer
1890 and then Typ /= Universal_Real
1891 and then Present (It.Abstract_Op)
1896 -- First matching interpretation
1902 Expr_Type := It.Typ;
1904 -- Matching interpretation that is not the first, maybe an
1905 -- error, but there are some cases where preference rules are
1906 -- used to choose between the two possibilities. These and
1907 -- some more obscure cases are handled in Disambiguate.
1910 -- If the current statement is part of a predefined library
1911 -- unit, then all interpretations which come from user level
1912 -- packages should not be considered.
1915 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
1920 Error_Msg_Sloc := Sloc (Seen);
1921 It1 := Disambiguate (N, I1, I, Typ);
1923 -- Disambiguation has succeeded. Skip the remaining
1926 if It1 /= No_Interp then
1928 Expr_Type := It1.Typ;
1930 while Present (It.Typ) loop
1931 Get_Next_Interp (I, It);
1935 -- Before we issue an ambiguity complaint, check for
1936 -- the case of a subprogram call where at least one
1937 -- of the arguments is Any_Type, and if so, suppress
1938 -- the message, since it is a cascaded error.
1940 if Nkind_In (N, N_Function_Call,
1941 N_Procedure_Call_Statement)
1948 A := First_Actual (N);
1949 while Present (A) loop
1952 if Nkind (E) = N_Parameter_Association then
1953 E := Explicit_Actual_Parameter (E);
1956 if Etype (E) = Any_Type then
1957 if Debug_Flag_V then
1958 Write_Str ("Any_Type in call");
1969 elsif Nkind (N) in N_Binary_Op
1970 and then (Etype (Left_Opnd (N)) = Any_Type
1971 or else Etype (Right_Opnd (N)) = Any_Type)
1975 elsif Nkind (N) in N_Unary_Op
1976 and then Etype (Right_Opnd (N)) = Any_Type
1981 -- Not that special case, so issue message using the
1982 -- flag Ambiguous to control printing of the header
1983 -- message only at the start of an ambiguous set.
1985 if not Ambiguous then
1986 if Nkind (N) = N_Function_Call
1987 and then Nkind (Name (N)) = N_Explicit_Dereference
1990 ("ambiguous expression "
1991 & "(cannot resolve indirect call)!", N);
1994 ("ambiguous expression (cannot resolve&)!",
2000 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2002 ("\\possible interpretation (inherited)#!", N);
2004 Error_Msg_N ("\\possible interpretation#!", N);
2008 Error_Msg_Sloc := Sloc (It.Nam);
2010 -- By default, the error message refers to the candidate
2011 -- interpretation. But if it is a predefined operator, it
2012 -- is implicitly declared at the declaration of the type
2013 -- of the operand. Recover the sloc of that declaration
2014 -- for the error message.
2016 if Nkind (N) in N_Op
2017 and then Scope (It.Nam) = Standard_Standard
2018 and then not Is_Overloaded (Right_Opnd (N))
2019 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2022 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2024 if Comes_From_Source (Err_Type)
2025 and then Present (Parent (Err_Type))
2027 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2030 elsif Nkind (N) in N_Binary_Op
2031 and then Scope (It.Nam) = Standard_Standard
2032 and then not Is_Overloaded (Left_Opnd (N))
2033 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2036 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2038 if Comes_From_Source (Err_Type)
2039 and then Present (Parent (Err_Type))
2041 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2044 -- If this is an indirect call, use the subprogram_type
2045 -- in the message, to have a meaningful location.
2046 -- Indicate as well if this is an inherited operation,
2047 -- created by a type declaration.
2049 elsif Nkind (N) = N_Function_Call
2050 and then Nkind (Name (N)) = N_Explicit_Dereference
2051 and then Is_Type (It.Nam)
2055 Sloc (Associated_Node_For_Itype (Err_Type));
2060 if Nkind (N) in N_Op
2061 and then Scope (It.Nam) = Standard_Standard
2062 and then Present (Err_Type)
2064 -- Special-case the message for universal_fixed
2065 -- operators, which are not declared with the type
2066 -- of the operand, but appear forever in Standard.
2068 if It.Typ = Universal_Fixed
2069 and then Scope (It.Nam) = Standard_Standard
2072 ("\\possible interpretation as " &
2073 "universal_fixed operation " &
2074 "(RM 4.5.5 (19))", N);
2077 ("\\possible interpretation (predefined)#!", N);
2081 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2084 ("\\possible interpretation (inherited)#!", N);
2086 Error_Msg_N ("\\possible interpretation#!", N);
2092 -- We have a matching interpretation, Expr_Type is the type
2093 -- from this interpretation, and Seen is the entity.
2095 -- For an operator, just set the entity name. The type will be
2096 -- set by the specific operator resolution routine.
2098 if Nkind (N) in N_Op then
2099 Set_Entity (N, Seen);
2100 Generate_Reference (Seen, N);
2102 elsif Nkind (N) = N_Character_Literal then
2103 Set_Etype (N, Expr_Type);
2105 -- For an explicit dereference, attribute reference, range,
2106 -- short-circuit form (which is not an operator node), or call
2107 -- with a name that is an explicit dereference, there is
2108 -- nothing to be done at this point.
2110 elsif Nkind_In (N, N_Explicit_Dereference,
2111 N_Attribute_Reference,
2113 N_Indexed_Component,
2116 N_Selected_Component,
2118 or else Nkind (Name (N)) = N_Explicit_Dereference
2122 -- For procedure or function calls, set the type of the name,
2123 -- and also the entity pointer for the prefix
2125 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2126 and then (Is_Entity_Name (Name (N))
2127 or else Nkind (Name (N)) = N_Operator_Symbol)
2129 Set_Etype (Name (N), Expr_Type);
2130 Set_Entity (Name (N), Seen);
2131 Generate_Reference (Seen, Name (N));
2133 elsif Nkind (N) = N_Function_Call
2134 and then Nkind (Name (N)) = N_Selected_Component
2136 Set_Etype (Name (N), Expr_Type);
2137 Set_Entity (Selector_Name (Name (N)), Seen);
2138 Generate_Reference (Seen, Selector_Name (Name (N)));
2140 -- For all other cases, just set the type of the Name
2143 Set_Etype (Name (N), Expr_Type);
2150 -- Move to next interpretation
2152 exit Interp_Loop when No (It.Typ);
2154 Get_Next_Interp (I, It);
2155 end loop Interp_Loop;
2158 -- At this stage Found indicates whether or not an acceptable
2159 -- interpretation exists. If not, then we have an error, except
2160 -- that if the context is Any_Type as a result of some other error,
2161 -- then we suppress the error report.
2164 if Typ /= Any_Type then
2166 -- If type we are looking for is Void, then this is the procedure
2167 -- call case, and the error is simply that what we gave is not a
2168 -- procedure name (we think of procedure calls as expressions with
2169 -- types internally, but the user doesn't think of them this way!)
2171 if Typ = Standard_Void_Type then
2173 -- Special case message if function used as a procedure
2175 if Nkind (N) = N_Procedure_Call_Statement
2176 and then Is_Entity_Name (Name (N))
2177 and then Ekind (Entity (Name (N))) = E_Function
2180 ("cannot use function & in a procedure call",
2181 Name (N), Entity (Name (N)));
2183 -- Otherwise give general message (not clear what cases this
2184 -- covers, but no harm in providing for them!)
2187 Error_Msg_N ("expect procedure name in procedure call", N);
2192 -- Otherwise we do have a subexpression with the wrong type
2194 -- Check for the case of an allocator which uses an access type
2195 -- instead of the designated type. This is a common error and we
2196 -- specialize the message, posting an error on the operand of the
2197 -- allocator, complaining that we expected the designated type of
2200 elsif Nkind (N) = N_Allocator
2201 and then Ekind (Typ) in Access_Kind
2202 and then Ekind (Etype (N)) in Access_Kind
2203 and then Designated_Type (Etype (N)) = Typ
2205 Wrong_Type (Expression (N), Designated_Type (Typ));
2208 -- Check for view mismatch on Null in instances, for which the
2209 -- view-swapping mechanism has no identifier.
2211 elsif (In_Instance or else In_Inlined_Body)
2212 and then (Nkind (N) = N_Null)
2213 and then Is_Private_Type (Typ)
2214 and then Is_Access_Type (Full_View (Typ))
2216 Resolve (N, Full_View (Typ));
2220 -- Check for an aggregate. Sometimes we can get bogus aggregates
2221 -- from misuse of parentheses, and we are about to complain about
2222 -- the aggregate without even looking inside it.
2224 -- Instead, if we have an aggregate of type Any_Composite, then
2225 -- analyze and resolve the component fields, and then only issue
2226 -- another message if we get no errors doing this (otherwise
2227 -- assume that the errors in the aggregate caused the problem).
2229 elsif Nkind (N) = N_Aggregate
2230 and then Etype (N) = Any_Composite
2232 -- Disable expansion in any case. If there is a type mismatch
2233 -- it may be fatal to try to expand the aggregate. The flag
2234 -- would otherwise be set to false when the error is posted.
2236 Expander_Active := False;
2239 procedure Check_Aggr (Aggr : Node_Id);
2240 -- Check one aggregate, and set Found to True if we have a
2241 -- definite error in any of its elements
2243 procedure Check_Elmt (Aelmt : Node_Id);
2244 -- Check one element of aggregate and set Found to True if
2245 -- we definitely have an error in the element.
2251 procedure Check_Aggr (Aggr : Node_Id) is
2255 if Present (Expressions (Aggr)) then
2256 Elmt := First (Expressions (Aggr));
2257 while Present (Elmt) loop
2263 if Present (Component_Associations (Aggr)) then
2264 Elmt := First (Component_Associations (Aggr));
2265 while Present (Elmt) loop
2267 -- If this is a default-initialized component, then
2268 -- there is nothing to check. The box will be
2269 -- replaced by the appropriate call during late
2272 if not Box_Present (Elmt) then
2273 Check_Elmt (Expression (Elmt));
2285 procedure Check_Elmt (Aelmt : Node_Id) is
2287 -- If we have a nested aggregate, go inside it (to
2288 -- attempt a naked analyze-resolve of the aggregate
2289 -- can cause undesirable cascaded errors). Do not
2290 -- resolve expression if it needs a type from context,
2291 -- as for integer * fixed expression.
2293 if Nkind (Aelmt) = N_Aggregate then
2299 if not Is_Overloaded (Aelmt)
2300 and then Etype (Aelmt) /= Any_Fixed
2305 if Etype (Aelmt) = Any_Type then
2316 -- If an error message was issued already, Found got reset
2317 -- to True, so if it is still False, issue the standard
2318 -- Wrong_Type message.
2321 if Is_Overloaded (N)
2322 and then Nkind (N) = N_Function_Call
2325 Subp_Name : Node_Id;
2327 if Is_Entity_Name (Name (N)) then
2328 Subp_Name := Name (N);
2330 elsif Nkind (Name (N)) = N_Selected_Component then
2332 -- Protected operation: retrieve operation name
2334 Subp_Name := Selector_Name (Name (N));
2336 raise Program_Error;
2339 Error_Msg_Node_2 := Typ;
2340 Error_Msg_NE ("no visible interpretation of&" &
2341 " matches expected type&", N, Subp_Name);
2344 if All_Errors_Mode then
2346 Index : Interp_Index;
2350 Error_Msg_N ("\\possible interpretations:", N);
2352 Get_First_Interp (Name (N), Index, It);
2353 while Present (It.Nam) loop
2354 Error_Msg_Sloc := Sloc (It.Nam);
2355 Error_Msg_Node_2 := It.Nam;
2357 ("\\ type& for & declared#", N, It.Typ);
2358 Get_Next_Interp (Index, It);
2363 Error_Msg_N ("\use -gnatf for details", N);
2366 Wrong_Type (N, Typ);
2374 -- Test if we have more than one interpretation for the context
2376 elsif Ambiguous then
2380 -- Here we have an acceptable interpretation for the context
2383 -- Propagate type information and normalize tree for various
2384 -- predefined operations. If the context only imposes a class of
2385 -- types, rather than a specific type, propagate the actual type
2388 if Typ = Any_Integer
2389 or else Typ = Any_Boolean
2390 or else Typ = Any_Modular
2391 or else Typ = Any_Real
2392 or else Typ = Any_Discrete
2394 Ctx_Type := Expr_Type;
2396 -- Any_Fixed is legal in a real context only if a specific
2397 -- fixed point type is imposed. If Norman Cohen can be
2398 -- confused by this, it deserves a separate message.
2401 and then Expr_Type = Any_Fixed
2403 Error_Msg_N ("illegal context for mixed mode operation", N);
2404 Set_Etype (N, Universal_Real);
2405 Ctx_Type := Universal_Real;
2409 -- A user-defined operator is transformed into a function call at
2410 -- this point, so that further processing knows that operators are
2411 -- really operators (i.e. are predefined operators). User-defined
2412 -- operators that are intrinsic are just renamings of the predefined
2413 -- ones, and need not be turned into calls either, but if they rename
2414 -- a different operator, we must transform the node accordingly.
2415 -- Instantiations of Unchecked_Conversion are intrinsic but are
2416 -- treated as functions, even if given an operator designator.
2418 if Nkind (N) in N_Op
2419 and then Present (Entity (N))
2420 and then Ekind (Entity (N)) /= E_Operator
2423 if not Is_Predefined_Op (Entity (N)) then
2424 Rewrite_Operator_As_Call (N, Entity (N));
2426 elsif Present (Alias (Entity (N)))
2428 Nkind (Parent (Parent (Entity (N)))) =
2429 N_Subprogram_Renaming_Declaration
2431 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2433 -- If the node is rewritten, it will be fully resolved in
2434 -- Rewrite_Renamed_Operator.
2436 if Analyzed (N) then
2442 case N_Subexpr'(Nkind (N)) is
2444 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2446 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2448 when N_And_Then | N_Or_Else
2449 => Resolve_Short_Circuit (N, Ctx_Type);
2451 when N_Attribute_Reference
2452 => Resolve_Attribute (N, Ctx_Type);
2454 when N_Character_Literal
2455 => Resolve_Character_Literal (N, Ctx_Type);
2457 when N_Conditional_Expression
2458 => Resolve_Conditional_Expression (N, Ctx_Type);
2460 when N_Expanded_Name
2461 => Resolve_Entity_Name (N, Ctx_Type);
2463 when N_Extension_Aggregate
2464 => Resolve_Extension_Aggregate (N, Ctx_Type);
2466 when N_Explicit_Dereference
2467 => Resolve_Explicit_Dereference (N, Ctx_Type);
2469 when N_Function_Call
2470 => Resolve_Call (N, Ctx_Type);
2473 => Resolve_Entity_Name (N, Ctx_Type);
2475 when N_Indexed_Component
2476 => Resolve_Indexed_Component (N, Ctx_Type);
2478 when N_Integer_Literal
2479 => Resolve_Integer_Literal (N, Ctx_Type);
2481 when N_Membership_Test
2482 => Resolve_Membership_Op (N, Ctx_Type);
2484 when N_Null => Resolve_Null (N, Ctx_Type);
2486 when N_Op_And | N_Op_Or | N_Op_Xor
2487 => Resolve_Logical_Op (N, Ctx_Type);
2489 when N_Op_Eq | N_Op_Ne
2490 => Resolve_Equality_Op (N, Ctx_Type);
2492 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2493 => Resolve_Comparison_Op (N, Ctx_Type);
2495 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2497 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2498 N_Op_Divide | N_Op_Mod | N_Op_Rem
2500 => Resolve_Arithmetic_Op (N, Ctx_Type);
2502 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2504 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2506 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2507 => Resolve_Unary_Op (N, Ctx_Type);
2509 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2511 when N_Procedure_Call_Statement
2512 => Resolve_Call (N, Ctx_Type);
2514 when N_Operator_Symbol
2515 => Resolve_Operator_Symbol (N, Ctx_Type);
2517 when N_Qualified_Expression
2518 => Resolve_Qualified_Expression (N, Ctx_Type);
2520 when N_Raise_xxx_Error
2521 => Set_Etype (N, Ctx_Type);
2523 when N_Range => Resolve_Range (N, Ctx_Type);
2526 => Resolve_Real_Literal (N, Ctx_Type);
2528 when N_Reference => Resolve_Reference (N, Ctx_Type);
2530 when N_Selected_Component
2531 => Resolve_Selected_Component (N, Ctx_Type);
2533 when N_Slice => Resolve_Slice (N, Ctx_Type);
2535 when N_String_Literal
2536 => Resolve_String_Literal (N, Ctx_Type);
2538 when N_Subprogram_Info
2539 => Resolve_Subprogram_Info (N, Ctx_Type);
2541 when N_Type_Conversion
2542 => Resolve_Type_Conversion (N, Ctx_Type);
2544 when N_Unchecked_Expression =>
2545 Resolve_Unchecked_Expression (N, Ctx_Type);
2547 when N_Unchecked_Type_Conversion =>
2548 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2552 -- If the subexpression was replaced by a non-subexpression, then
2553 -- all we do is to expand it. The only legitimate case we know of
2554 -- is converting procedure call statement to entry call statements,
2555 -- but there may be others, so we are making this test general.
2557 if Nkind (N) not in N_Subexpr then
2558 Debug_A_Exit ("resolving ", N, " (done)");
2563 -- The expression is definitely NOT overloaded at this point, so
2564 -- we reset the Is_Overloaded flag to avoid any confusion when
2565 -- reanalyzing the node.
2567 Set_Is_Overloaded (N, False);
2569 -- Freeze expression type, entity if it is a name, and designated
2570 -- type if it is an allocator (RM 13.14(10,11,13)).
2572 -- Now that the resolution of the type of the node is complete,
2573 -- and we did not detect an error, we can expand this node. We
2574 -- skip the expand call if we are in a default expression, see
2575 -- section "Handling of Default Expressions" in Sem spec.
2577 Debug_A_Exit ("resolving ", N, " (done)");
2579 -- We unconditionally freeze the expression, even if we are in
2580 -- default expression mode (the Freeze_Expression routine tests
2581 -- this flag and only freezes static types if it is set).
2583 Freeze_Expression (N);
2585 -- Now we can do the expansion
2595 -- Version with check(s) suppressed
2597 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2599 if Suppress = All_Checks then
2601 Svg : constant Suppress_Array := Scope_Suppress;
2603 Scope_Suppress := (others => True);
2605 Scope_Suppress := Svg;
2610 Svg : constant Boolean := Scope_Suppress (Suppress);
2612 Scope_Suppress (Suppress) := True;
2614 Scope_Suppress (Suppress) := Svg;
2623 -- Version with implicit type
2625 procedure Resolve (N : Node_Id) is
2627 Resolve (N, Etype (N));
2630 ---------------------
2631 -- Resolve_Actuals --
2632 ---------------------
2634 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2635 Loc : constant Source_Ptr := Sloc (N);
2640 Prev : Node_Id := Empty;
2643 procedure Check_Argument_Order;
2644 -- Performs a check for the case where the actuals are all simple
2645 -- identifiers that correspond to the formal names, but in the wrong
2646 -- order, which is considered suspicious and cause for a warning.
2648 procedure Check_Prefixed_Call;
2649 -- If the original node is an overloaded call in prefix notation,
2650 -- insert an 'Access or a dereference as needed over the first actual.
2651 -- Try_Object_Operation has already verified that there is a valid
2652 -- interpretation, but the form of the actual can only be determined
2653 -- once the primitive operation is identified.
2655 procedure Insert_Default;
2656 -- If the actual is missing in a call, insert in the actuals list
2657 -- an instance of the default expression. The insertion is always
2658 -- a named association.
2660 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2661 -- Check whether T1 and T2, or their full views, are derived from a
2662 -- common type. Used to enforce the restrictions on array conversions
2665 --------------------------
2666 -- Check_Argument_Order --
2667 --------------------------
2669 procedure Check_Argument_Order is
2671 -- Nothing to do if no parameters, or original node is neither a
2672 -- function call nor a procedure call statement (happens in the
2673 -- operator-transformed-to-function call case), or the call does
2674 -- not come from source, or this warning is off.
2676 if not Warn_On_Parameter_Order
2678 No (Parameter_Associations (N))
2680 not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2683 not Comes_From_Source (N)
2689 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2692 -- Nothing to do if only one parameter
2698 -- Here if at least two arguments
2701 Actuals : array (1 .. Nargs) of Node_Id;
2705 Wrong_Order : Boolean := False;
2706 -- Set True if an out of order case is found
2709 -- Collect identifier names of actuals, fail if any actual is
2710 -- not a simple identifier, and record max length of name.
2712 Actual := First (Parameter_Associations (N));
2713 for J in Actuals'Range loop
2714 if Nkind (Actual) /= N_Identifier then
2717 Actuals (J) := Actual;
2722 -- If we got this far, all actuals are identifiers and the list
2723 -- of their names is stored in the Actuals array.
2725 Formal := First_Formal (Nam);
2726 for J in Actuals'Range loop
2728 -- If we ran out of formals, that's odd, probably an error
2729 -- which will be detected elsewhere, but abandon the search.
2735 -- If name matches and is in order OK
2737 if Chars (Formal) = Chars (Actuals (J)) then
2741 -- If no match, see if it is elsewhere in list and if so
2742 -- flag potential wrong order if type is compatible.
2744 for K in Actuals'Range loop
2745 if Chars (Formal) = Chars (Actuals (K))
2747 Has_Compatible_Type (Actuals (K), Etype (Formal))
2749 Wrong_Order := True;
2759 <<Continue>> Next_Formal (Formal);
2762 -- If Formals left over, also probably an error, skip warning
2764 if Present (Formal) then
2768 -- Here we give the warning if something was out of order
2772 ("actuals for this call may be in wrong order?", N);
2776 end Check_Argument_Order;
2778 -------------------------
2779 -- Check_Prefixed_Call --
2780 -------------------------
2782 procedure Check_Prefixed_Call is
2783 Act : constant Node_Id := First_Actual (N);
2784 A_Type : constant Entity_Id := Etype (Act);
2785 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
2786 Orig : constant Node_Id := Original_Node (N);
2790 -- Check whether the call is a prefixed call, with or without
2791 -- additional actuals.
2793 if Nkind (Orig) = N_Selected_Component
2795 (Nkind (Orig) = N_Indexed_Component
2796 and then Nkind (Prefix (Orig)) = N_Selected_Component
2797 and then Is_Entity_Name (Prefix (Prefix (Orig)))
2798 and then Is_Entity_Name (Act)
2799 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
2801 if Is_Access_Type (A_Type)
2802 and then not Is_Access_Type (F_Type)
2804 -- Introduce dereference on object in prefix
2807 Make_Explicit_Dereference (Sloc (Act),
2808 Prefix => Relocate_Node (Act));
2809 Rewrite (Act, New_A);
2812 elsif Is_Access_Type (F_Type)
2813 and then not Is_Access_Type (A_Type)
2815 -- Introduce an implicit 'Access in prefix
2817 if not Is_Aliased_View (Act) then
2819 ("object in prefixed call to& must be aliased"
2820 & " (RM-2005 4.3.1 (13))",
2825 Make_Attribute_Reference (Loc,
2826 Attribute_Name => Name_Access,
2827 Prefix => Relocate_Node (Act)));
2832 end Check_Prefixed_Call;
2834 --------------------
2835 -- Insert_Default --
2836 --------------------
2838 procedure Insert_Default is
2843 -- Missing argument in call, nothing to insert
2845 if No (Default_Value (F)) then
2849 -- Note that we do a full New_Copy_Tree, so that any associated
2850 -- Itypes are properly copied. This may not be needed any more,
2851 -- but it does no harm as a safety measure! Defaults of a generic
2852 -- formal may be out of bounds of the corresponding actual (see
2853 -- cc1311b) and an additional check may be required.
2858 New_Scope => Current_Scope,
2861 if Is_Concurrent_Type (Scope (Nam))
2862 and then Has_Discriminants (Scope (Nam))
2864 Replace_Actual_Discriminants (N, Actval);
2867 if Is_Overloadable (Nam)
2868 and then Present (Alias (Nam))
2870 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2871 and then not Is_Tagged_Type (Etype (F))
2873 -- If default is a real literal, do not introduce a
2874 -- conversion whose effect may depend on the run-time
2875 -- size of universal real.
2877 if Nkind (Actval) = N_Real_Literal then
2878 Set_Etype (Actval, Base_Type (Etype (F)));
2880 Actval := Unchecked_Convert_To (Etype (F), Actval);
2884 if Is_Scalar_Type (Etype (F)) then
2885 Enable_Range_Check (Actval);
2888 Set_Parent (Actval, N);
2890 -- Resolve aggregates with their base type, to avoid scope
2891 -- anomalies: the subtype was first built in the subprogram
2892 -- declaration, and the current call may be nested.
2894 if Nkind (Actval) = N_Aggregate
2895 and then Has_Discriminants (Etype (Actval))
2897 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2899 Analyze_And_Resolve (Actval, Etype (Actval));
2903 Set_Parent (Actval, N);
2905 -- See note above concerning aggregates
2907 if Nkind (Actval) = N_Aggregate
2908 and then Has_Discriminants (Etype (Actval))
2910 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2912 -- Resolve entities with their own type, which may differ
2913 -- from the type of a reference in a generic context (the
2914 -- view swapping mechanism did not anticipate the re-analysis
2915 -- of default values in calls).
2917 elsif Is_Entity_Name (Actval) then
2918 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
2921 Analyze_And_Resolve (Actval, Etype (Actval));
2925 -- If default is a tag indeterminate function call, propagate
2926 -- tag to obtain proper dispatching.
2928 if Is_Controlling_Formal (F)
2929 and then Nkind (Default_Value (F)) = N_Function_Call
2931 Set_Is_Controlling_Actual (Actval);
2936 -- If the default expression raises constraint error, then just
2937 -- silently replace it with an N_Raise_Constraint_Error node,
2938 -- since we already gave the warning on the subprogram spec.
2940 if Raises_Constraint_Error (Actval) then
2942 Make_Raise_Constraint_Error (Loc,
2943 Reason => CE_Range_Check_Failed));
2944 Set_Raises_Constraint_Error (Actval);
2945 Set_Etype (Actval, Etype (F));
2949 Make_Parameter_Association (Loc,
2950 Explicit_Actual_Parameter => Actval,
2951 Selector_Name => Make_Identifier (Loc, Chars (F)));
2953 -- Case of insertion is first named actual
2955 if No (Prev) or else
2956 Nkind (Parent (Prev)) /= N_Parameter_Association
2958 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
2959 Set_First_Named_Actual (N, Actval);
2962 if No (Parameter_Associations (N)) then
2963 Set_Parameter_Associations (N, New_List (Assoc));
2965 Append (Assoc, Parameter_Associations (N));
2969 Insert_After (Prev, Assoc);
2972 -- Case of insertion is not first named actual
2975 Set_Next_Named_Actual
2976 (Assoc, Next_Named_Actual (Parent (Prev)));
2977 Set_Next_Named_Actual (Parent (Prev), Actval);
2978 Append (Assoc, Parameter_Associations (N));
2981 Mark_Rewrite_Insertion (Assoc);
2982 Mark_Rewrite_Insertion (Actval);
2991 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
2992 FT1 : Entity_Id := T1;
2993 FT2 : Entity_Id := T2;
2996 if Is_Private_Type (T1)
2997 and then Present (Full_View (T1))
2999 FT1 := Full_View (T1);
3002 if Is_Private_Type (T2)
3003 and then Present (Full_View (T2))
3005 FT2 := Full_View (T2);
3008 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3011 -- Start of processing for Resolve_Actuals
3014 Check_Argument_Order;
3016 if Present (First_Actual (N)) then
3017 Check_Prefixed_Call;
3020 A := First_Actual (N);
3021 F := First_Formal (Nam);
3022 while Present (F) loop
3023 if No (A) and then Needs_No_Actuals (Nam) then
3026 -- If we have an error in any actual or formal, indicated by
3027 -- a type of Any_Type, then abandon resolution attempt, and
3028 -- set result type to Any_Type.
3030 elsif (Present (A) and then Etype (A) = Any_Type)
3031 or else Etype (F) = Any_Type
3033 Set_Etype (N, Any_Type);
3037 -- Case where actual is present
3039 -- If the actual is an entity, generate a reference to it now. We
3040 -- do this before the actual is resolved, because a formal of some
3041 -- protected subprogram, or a task discriminant, will be rewritten
3042 -- during expansion, and the reference to the source entity may
3046 and then Is_Entity_Name (A)
3047 and then Comes_From_Source (N)
3049 Orig_A := Entity (A);
3051 if Present (Orig_A) then
3052 if Is_Formal (Orig_A)
3053 and then Ekind (F) /= E_In_Parameter
3055 Generate_Reference (Orig_A, A, 'm');
3056 elsif not Is_Overloaded (A) then
3057 Generate_Reference (Orig_A, A);
3063 and then (Nkind (Parent (A)) /= N_Parameter_Association
3065 Chars (Selector_Name (Parent (A))) = Chars (F))
3067 -- If style checking mode on, check match of formal name
3070 if Nkind (Parent (A)) = N_Parameter_Association then
3071 Check_Identifier (Selector_Name (Parent (A)), F);
3075 -- If the formal is Out or In_Out, do not resolve and expand the
3076 -- conversion, because it is subsequently expanded into explicit
3077 -- temporaries and assignments. However, the object of the
3078 -- conversion can be resolved. An exception is the case of tagged
3079 -- type conversion with a class-wide actual. In that case we want
3080 -- the tag check to occur and no temporary will be needed (no
3081 -- representation change can occur) and the parameter is passed by
3082 -- reference, so we go ahead and resolve the type conversion.
3083 -- Another exception is the case of reference to component or
3084 -- subcomponent of a bit-packed array, in which case we want to
3085 -- defer expansion to the point the in and out assignments are
3088 if Ekind (F) /= E_In_Parameter
3089 and then Nkind (A) = N_Type_Conversion
3090 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3092 if Ekind (F) = E_In_Out_Parameter
3093 and then Is_Array_Type (Etype (F))
3095 if Has_Aliased_Components (Etype (Expression (A)))
3096 /= Has_Aliased_Components (Etype (F))
3099 -- In a view conversion, the conversion must be legal in
3100 -- both directions, and thus both component types must be
3101 -- aliased, or neither (4.6 (8)).
3103 -- The additional rule 4.6 (24.9.2) seems unduly
3104 -- restrictive: the privacy requirement should not
3105 -- apply to generic types, and should be checked in
3106 -- an instance. ARG query is in order.
3109 ("both component types in a view conversion must be"
3110 & " aliased, or neither", A);
3113 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3115 if Is_By_Reference_Type (Etype (F))
3116 or else Is_By_Reference_Type (Etype (Expression (A)))
3119 ("view conversion between unrelated by reference " &
3120 "array types not allowed (\'A'I-00246)", A);
3123 Comp_Type : constant Entity_Id :=
3125 (Etype (Expression (A)));
3127 if Comes_From_Source (A)
3128 and then Ada_Version >= Ada_05
3130 ((Is_Private_Type (Comp_Type)
3131 and then not Is_Generic_Type (Comp_Type))
3132 or else Is_Tagged_Type (Comp_Type)
3133 or else Is_Volatile (Comp_Type))
3136 ("component type of a view conversion cannot"
3137 & " be private, tagged, or volatile"
3146 if (Conversion_OK (A)
3147 or else Valid_Conversion (A, Etype (A), Expression (A)))
3148 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3150 Resolve (Expression (A));
3153 -- If the actual is a function call that returns a limited
3154 -- unconstrained object that needs finalization, create a
3155 -- transient scope for it, so that it can receive the proper
3156 -- finalization list.
3158 elsif Nkind (A) = N_Function_Call
3159 and then Is_Limited_Record (Etype (F))
3160 and then not Is_Constrained (Etype (F))
3161 and then Expander_Active
3163 (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3165 Establish_Transient_Scope (A, False);
3168 if Nkind (A) = N_Type_Conversion
3169 and then Is_Array_Type (Etype (F))
3170 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3172 (Is_Limited_Type (Etype (F))
3173 or else Is_Limited_Type (Etype (Expression (A))))
3176 ("conversion between unrelated limited array types " &
3177 "not allowed (\A\I-00246)", A);
3179 if Is_Limited_Type (Etype (F)) then
3180 Explain_Limited_Type (Etype (F), A);
3183 if Is_Limited_Type (Etype (Expression (A))) then
3184 Explain_Limited_Type (Etype (Expression (A)), A);
3188 -- (Ada 2005: AI-251): If the actual is an allocator whose
3189 -- directly designated type is a class-wide interface, we build
3190 -- an anonymous access type to use it as the type of the
3191 -- allocator. Later, when the subprogram call is expanded, if
3192 -- the interface has a secondary dispatch table the expander
3193 -- will add a type conversion to force the correct displacement
3196 if Nkind (A) = N_Allocator then
3198 DDT : constant Entity_Id :=
3199 Directly_Designated_Type (Base_Type (Etype (F)));
3201 New_Itype : Entity_Id;
3204 if Is_Class_Wide_Type (DDT)
3205 and then Is_Interface (DDT)
3207 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3208 Set_Etype (New_Itype, Etype (A));
3209 Set_Directly_Designated_Type (New_Itype,
3210 Directly_Designated_Type (Etype (A)));
3211 Set_Etype (A, New_Itype);
3214 -- Ada 2005, AI-162:If the actual is an allocator, the
3215 -- innermost enclosing statement is the master of the
3216 -- created object. This needs to be done with expansion
3217 -- enabled only, otherwise the transient scope will not
3218 -- be removed in the expansion of the wrapped construct.
3220 if (Is_Controlled (DDT) or else Has_Task (DDT))
3221 and then Expander_Active
3223 Establish_Transient_Scope (A, False);
3228 -- (Ada 2005): The call may be to a primitive operation of
3229 -- a tagged synchronized type, declared outside of the type.
3230 -- In this case the controlling actual must be converted to
3231 -- its corresponding record type, which is the formal type.
3232 -- The actual may be a subtype, either because of a constraint
3233 -- or because it is a generic actual, so use base type to
3234 -- locate concurrent type.
3236 A_Typ := Base_Type (Etype (A));
3237 F_Typ := Base_Type (Etype (F));
3240 Full_A_Typ : Entity_Id;
3243 if Present (Full_View (A_Typ)) then
3244 Full_A_Typ := Base_Type (Full_View (A_Typ));
3246 Full_A_Typ := A_Typ;
3249 -- Tagged synchronized type (case 1): the actual is a
3252 if Is_Concurrent_Type (A_Typ)
3253 and then Corresponding_Record_Type (A_Typ) = F_Typ
3256 Unchecked_Convert_To
3257 (Corresponding_Record_Type (A_Typ), A));
3258 Resolve (A, Etype (F));
3260 -- Tagged synchronized type (case 2): the formal is a
3263 elsif Ekind (Full_A_Typ) = E_Record_Type
3265 (Corresponding_Concurrent_Type (Full_A_Typ))
3266 and then Is_Concurrent_Type (F_Typ)
3267 and then Present (Corresponding_Record_Type (F_Typ))
3268 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3270 Resolve (A, Corresponding_Record_Type (F_Typ));
3275 Resolve (A, Etype (F));
3283 -- For mode IN, if actual is an entity, and the type of the formal
3284 -- has warnings suppressed, then we reset Never_Set_In_Source for
3285 -- the calling entity. The reason for this is to catch cases like
3286 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3287 -- uses trickery to modify an IN parameter.
3289 if Ekind (F) = E_In_Parameter
3290 and then Is_Entity_Name (A)
3291 and then Present (Entity (A))
3292 and then Ekind (Entity (A)) = E_Variable
3293 and then Has_Warnings_Off (F_Typ)
3295 Set_Never_Set_In_Source (Entity (A), False);
3298 -- Perform error checks for IN and IN OUT parameters
3300 if Ekind (F) /= E_Out_Parameter then
3302 -- Check unset reference. For scalar parameters, it is clearly
3303 -- wrong to pass an uninitialized value as either an IN or
3304 -- IN-OUT parameter. For composites, it is also clearly an
3305 -- error to pass a completely uninitialized value as an IN
3306 -- parameter, but the case of IN OUT is trickier. We prefer
3307 -- not to give a warning here. For example, suppose there is
3308 -- a routine that sets some component of a record to False.
3309 -- It is perfectly reasonable to make this IN-OUT and allow
3310 -- either initialized or uninitialized records to be passed
3313 -- For partially initialized composite values, we also avoid
3314 -- warnings, since it is quite likely that we are passing a
3315 -- partially initialized value and only the initialized fields
3316 -- will in fact be read in the subprogram.
3318 if Is_Scalar_Type (A_Typ)
3319 or else (Ekind (F) = E_In_Parameter
3320 and then not Is_Partially_Initialized_Type (A_Typ))
3322 Check_Unset_Reference (A);
3325 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3326 -- actual to a nested call, since this is case of reading an
3327 -- out parameter, which is not allowed.
3329 if Ada_Version = Ada_83
3330 and then Is_Entity_Name (A)
3331 and then Ekind (Entity (A)) = E_Out_Parameter
3333 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3337 -- Case of OUT or IN OUT parameter
3339 if Ekind (F) /= E_In_Parameter then
3341 -- For an Out parameter, check for useless assignment. Note
3342 -- that we can't set Last_Assignment this early, because we may
3343 -- kill current values in Resolve_Call, and that call would
3344 -- clobber the Last_Assignment field.
3346 -- Note: call Warn_On_Useless_Assignment before doing the check
3347 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3348 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3349 -- reflects the last assignment, not this one!
3351 if Ekind (F) = E_Out_Parameter then
3352 if Warn_On_Modified_As_Out_Parameter (F)
3353 and then Is_Entity_Name (A)
3354 and then Present (Entity (A))
3355 and then Comes_From_Source (N)
3357 Warn_On_Useless_Assignment (Entity (A), A);
3361 -- Validate the form of the actual. Note that the call to
3362 -- Is_OK_Variable_For_Out_Formal generates the required
3363 -- reference in this case.
3365 if not Is_OK_Variable_For_Out_Formal (A) then
3366 Error_Msg_NE ("actual for& must be a variable", A, F);
3369 -- What's the following about???
3371 if Is_Entity_Name (A) then
3372 Kill_Checks (Entity (A));
3378 if Etype (A) = Any_Type then
3379 Set_Etype (N, Any_Type);
3383 -- Apply appropriate range checks for in, out, and in-out
3384 -- parameters. Out and in-out parameters also need a separate
3385 -- check, if there is a type conversion, to make sure the return
3386 -- value meets the constraints of the variable before the
3389 -- Gigi looks at the check flag and uses the appropriate types.
3390 -- For now since one flag is used there is an optimization which
3391 -- might not be done in the In Out case since Gigi does not do
3392 -- any analysis. More thought required about this ???
3394 if Ekind (F) = E_In_Parameter
3395 or else Ekind (F) = E_In_Out_Parameter
3397 if Is_Scalar_Type (Etype (A)) then
3398 Apply_Scalar_Range_Check (A, F_Typ);
3400 elsif Is_Array_Type (Etype (A)) then
3401 Apply_Length_Check (A, F_Typ);
3403 elsif Is_Record_Type (F_Typ)
3404 and then Has_Discriminants (F_Typ)
3405 and then Is_Constrained (F_Typ)
3406 and then (not Is_Derived_Type (F_Typ)
3407 or else Comes_From_Source (Nam))
3409 Apply_Discriminant_Check (A, F_Typ);
3411 elsif Is_Access_Type (F_Typ)
3412 and then Is_Array_Type (Designated_Type (F_Typ))
3413 and then Is_Constrained (Designated_Type (F_Typ))
3415 Apply_Length_Check (A, F_Typ);
3417 elsif Is_Access_Type (F_Typ)
3418 and then Has_Discriminants (Designated_Type (F_Typ))
3419 and then Is_Constrained (Designated_Type (F_Typ))
3421 Apply_Discriminant_Check (A, F_Typ);
3424 Apply_Range_Check (A, F_Typ);
3427 -- Ada 2005 (AI-231)
3429 if Ada_Version >= Ada_05
3430 and then Is_Access_Type (F_Typ)
3431 and then Can_Never_Be_Null (F_Typ)
3432 and then Known_Null (A)
3434 Apply_Compile_Time_Constraint_Error
3436 Msg => "(Ada 2005) null not allowed in "
3437 & "null-excluding formal?",
3438 Reason => CE_Null_Not_Allowed);
3442 if Ekind (F) = E_Out_Parameter
3443 or else Ekind (F) = E_In_Out_Parameter
3445 if Nkind (A) = N_Type_Conversion then
3446 if Is_Scalar_Type (A_Typ) then
3447 Apply_Scalar_Range_Check
3448 (Expression (A), Etype (Expression (A)), A_Typ);
3451 (Expression (A), Etype (Expression (A)), A_Typ);
3455 if Is_Scalar_Type (F_Typ) then
3456 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3458 elsif Is_Array_Type (F_Typ)
3459 and then Ekind (F) = E_Out_Parameter
3461 Apply_Length_Check (A, F_Typ);
3464 Apply_Range_Check (A, A_Typ, F_Typ);
3469 -- An actual associated with an access parameter is implicitly
3470 -- converted to the anonymous access type of the formal and must
3471 -- satisfy the legality checks for access conversions.
3473 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3474 if not Valid_Conversion (A, F_Typ, A) then
3476 ("invalid implicit conversion for access parameter", A);
3480 -- Check bad case of atomic/volatile argument (RM C.6(12))
3482 if Is_By_Reference_Type (Etype (F))
3483 and then Comes_From_Source (N)
3485 if Is_Atomic_Object (A)
3486 and then not Is_Atomic (Etype (F))
3489 ("cannot pass atomic argument to non-atomic formal",
3492 elsif Is_Volatile_Object (A)
3493 and then not Is_Volatile (Etype (F))
3496 ("cannot pass volatile argument to non-volatile formal",
3501 -- Check that subprograms don't have improper controlling
3502 -- arguments (RM 3.9.2 (9))
3504 -- A primitive operation may have an access parameter of an
3505 -- incomplete tagged type, but a dispatching call is illegal
3506 -- if the type is still incomplete.
3508 if Is_Controlling_Formal (F) then
3509 Set_Is_Controlling_Actual (A);
3511 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3513 Desig : constant Entity_Id := Designated_Type (Etype (F));
3515 if Ekind (Desig) = E_Incomplete_Type
3516 and then No (Full_View (Desig))
3517 and then No (Non_Limited_View (Desig))
3520 ("premature use of incomplete type& " &
3521 "in dispatching call", A, Desig);
3526 elsif Nkind (A) = N_Explicit_Dereference then
3527 Validate_Remote_Access_To_Class_Wide_Type (A);
3530 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3531 and then not Is_Class_Wide_Type (F_Typ)
3532 and then not Is_Controlling_Formal (F)
3534 Error_Msg_N ("class-wide argument not allowed here!", A);
3536 if Is_Subprogram (Nam)
3537 and then Comes_From_Source (Nam)
3539 Error_Msg_Node_2 := F_Typ;
3541 ("& is not a dispatching operation of &!", A, Nam);
3544 elsif Is_Access_Type (A_Typ)
3545 and then Is_Access_Type (F_Typ)
3546 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3547 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3548 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3549 or else (Nkind (A) = N_Attribute_Reference
3551 Is_Class_Wide_Type (Etype (Prefix (A)))))
3552 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3553 and then not Is_Controlling_Formal (F)
3556 ("access to class-wide argument not allowed here!", A);
3558 if Is_Subprogram (Nam)
3559 and then Comes_From_Source (Nam)
3561 Error_Msg_Node_2 := Designated_Type (F_Typ);
3563 ("& is not a dispatching operation of &!", A, Nam);
3569 -- If it is a named association, treat the selector_name as
3570 -- a proper identifier, and mark the corresponding entity.
3572 if Nkind (Parent (A)) = N_Parameter_Association then
3573 Set_Entity (Selector_Name (Parent (A)), F);
3574 Generate_Reference (F, Selector_Name (Parent (A)));
3575 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3576 Generate_Reference (F_Typ, N, ' ');
3581 if Ekind (F) /= E_Out_Parameter then
3582 Check_Unset_Reference (A);
3587 -- Case where actual is not present
3595 end Resolve_Actuals;
3597 -----------------------
3598 -- Resolve_Allocator --
3599 -----------------------
3601 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
3602 E : constant Node_Id := Expression (N);
3604 Discrim : Entity_Id;
3607 Assoc : Node_Id := Empty;
3610 procedure Check_Allocator_Discrim_Accessibility
3611 (Disc_Exp : Node_Id;
3612 Alloc_Typ : Entity_Id);
3613 -- Check that accessibility level associated with an access discriminant
3614 -- initialized in an allocator by the expression Disc_Exp is not deeper
3615 -- than the level of the allocator type Alloc_Typ. An error message is
3616 -- issued if this condition is violated. Specialized checks are done for
3617 -- the cases of a constraint expression which is an access attribute or
3618 -- an access discriminant.
3620 function In_Dispatching_Context return Boolean;
3621 -- If the allocator is an actual in a call, it is allowed to be class-
3622 -- wide when the context is not because it is a controlling actual.
3624 procedure Propagate_Coextensions (Root : Node_Id);
3625 -- Propagate all nested coextensions which are located one nesting
3626 -- level down the tree to the node Root. Example:
3629 -- Level_1_Coextension
3630 -- Level_2_Coextension
3632 -- The algorithm is paired with delay actions done by the Expander. In
3633 -- the above example, assume all coextensions are controlled types.
3634 -- The cycle of analysis, resolution and expansion will yield:
3636 -- 1) Analyze Top_Record
3637 -- 2) Analyze Level_1_Coextension
3638 -- 3) Analyze Level_2_Coextension
3639 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
3641 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3642 -- generated to capture the allocated object. Temp_1 is attached
3643 -- to the coextension chain of Level_2_Coextension.
3644 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3645 -- coextension. A forward tree traversal is performed which finds
3646 -- Level_2_Coextension's list and copies its contents into its
3648 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3649 -- generated to capture the allocated object. Temp_2 is attached
3650 -- to the coextension chain of Level_1_Coextension. Currently, the
3651 -- contents of the list are [Temp_2, Temp_1].
3652 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3653 -- finds Level_1_Coextension's list and copies its contents into
3655 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3656 -- Temp_2 and attach them to Top_Record's finalization list.
3658 -------------------------------------------
3659 -- Check_Allocator_Discrim_Accessibility --
3660 -------------------------------------------
3662 procedure Check_Allocator_Discrim_Accessibility
3663 (Disc_Exp : Node_Id;
3664 Alloc_Typ : Entity_Id)
3667 if Type_Access_Level (Etype (Disc_Exp)) >
3668 Type_Access_Level (Alloc_Typ)
3671 ("operand type has deeper level than allocator type", Disc_Exp);
3673 -- When the expression is an Access attribute the level of the prefix
3674 -- object must not be deeper than that of the allocator's type.
3676 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3677 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3679 and then Object_Access_Level (Prefix (Disc_Exp))
3680 > Type_Access_Level (Alloc_Typ)
3683 ("prefix of attribute has deeper level than allocator type",
3686 -- When the expression is an access discriminant the check is against
3687 -- the level of the prefix object.
3689 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3690 and then Nkind (Disc_Exp) = N_Selected_Component
3691 and then Object_Access_Level (Prefix (Disc_Exp))
3692 > Type_Access_Level (Alloc_Typ)
3695 ("access discriminant has deeper level than allocator type",
3698 -- All other cases are legal
3703 end Check_Allocator_Discrim_Accessibility;
3705 ----------------------------
3706 -- In_Dispatching_Context --
3707 ----------------------------
3709 function In_Dispatching_Context return Boolean is
3710 Par : constant Node_Id := Parent (N);
3712 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
3713 and then Is_Entity_Name (Name (Par))
3714 and then Is_Dispatching_Operation (Entity (Name (Par)));
3715 end In_Dispatching_Context;
3717 ----------------------------
3718 -- Propagate_Coextensions --
3719 ----------------------------
3721 procedure Propagate_Coextensions (Root : Node_Id) is
3723 procedure Copy_List (From : Elist_Id; To : Elist_Id);
3724 -- Copy the contents of list From into list To, preserving the
3725 -- order of elements.
3727 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
3728 -- Recognize an allocator or a rewritten allocator node and add it
3729 -- along with its nested coextensions to the list of Root.
3735 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
3736 From_Elmt : Elmt_Id;
3738 From_Elmt := First_Elmt (From);
3739 while Present (From_Elmt) loop
3740 Append_Elmt (Node (From_Elmt), To);
3741 Next_Elmt (From_Elmt);
3745 -----------------------
3746 -- Process_Allocator --
3747 -----------------------
3749 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
3750 Orig_Nod : Node_Id := Nod;
3753 -- This is a possible rewritten subtype indication allocator. Any
3754 -- nested coextensions will appear as discriminant constraints.
3756 if Nkind (Nod) = N_Identifier
3757 and then Present (Original_Node (Nod))
3758 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
3762 Discr_Elmt : Elmt_Id;
3765 if Is_Record_Type (Entity (Nod)) then
3767 First_Elmt (Discriminant_Constraint (Entity (Nod)));
3768 while Present (Discr_Elmt) loop
3769 Discr := Node (Discr_Elmt);
3771 if Nkind (Discr) = N_Identifier
3772 and then Present (Original_Node (Discr))
3773 and then Nkind (Original_Node (Discr)) = N_Allocator
3774 and then Present (Coextensions (
3775 Original_Node (Discr)))
3777 if No (Coextensions (Root)) then
3778 Set_Coextensions (Root, New_Elmt_List);
3782 (From => Coextensions (Original_Node (Discr)),
3783 To => Coextensions (Root));
3786 Next_Elmt (Discr_Elmt);
3789 -- There is no need to continue the traversal of this
3790 -- subtree since all the information has already been
3797 -- Case of either a stand alone allocator or a rewritten allocator
3798 -- with an aggregate.
3801 if Present (Original_Node (Nod)) then
3802 Orig_Nod := Original_Node (Nod);
3805 if Nkind (Orig_Nod) = N_Allocator then
3807 -- Propagate the list of nested coextensions to the Root
3808 -- allocator. This is done through list copy since a single
3809 -- allocator may have multiple coextensions. Do not touch
3810 -- coextensions roots.
3812 if not Is_Coextension_Root (Orig_Nod)
3813 and then Present (Coextensions (Orig_Nod))
3815 if No (Coextensions (Root)) then
3816 Set_Coextensions (Root, New_Elmt_List);
3820 (From => Coextensions (Orig_Nod),
3821 To => Coextensions (Root));
3824 -- There is no need to continue the traversal of this
3825 -- subtree since all the information has already been
3832 -- Keep on traversing, looking for the next allocator
3835 end Process_Allocator;
3837 procedure Process_Allocators is
3838 new Traverse_Proc (Process_Allocator);
3840 -- Start of processing for Propagate_Coextensions
3843 Process_Allocators (Expression (Root));
3844 end Propagate_Coextensions;
3846 -- Start of processing for Resolve_Allocator
3849 -- Replace general access with specific type
3851 if Ekind (Etype (N)) = E_Allocator_Type then
3852 Set_Etype (N, Base_Type (Typ));
3855 if Is_Abstract_Type (Typ) then
3856 Error_Msg_N ("type of allocator cannot be abstract", N);
3859 -- For qualified expression, resolve the expression using the
3860 -- given subtype (nothing to do for type mark, subtype indication)
3862 if Nkind (E) = N_Qualified_Expression then
3863 if Is_Class_Wide_Type (Etype (E))
3864 and then not Is_Class_Wide_Type (Designated_Type (Typ))
3865 and then not In_Dispatching_Context
3868 ("class-wide allocator not allowed for this access type", N);
3871 Resolve (Expression (E), Etype (E));
3872 Check_Unset_Reference (Expression (E));
3874 -- A qualified expression requires an exact match of the type,
3875 -- class-wide matching is not allowed.
3877 if (Is_Class_Wide_Type (Etype (Expression (E)))
3878 or else Is_Class_Wide_Type (Etype (E)))
3879 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
3881 Wrong_Type (Expression (E), Etype (E));
3884 -- A special accessibility check is needed for allocators that
3885 -- constrain access discriminants. The level of the type of the
3886 -- expression used to constrain an access discriminant cannot be
3887 -- deeper than the type of the allocator (in contrast to access
3888 -- parameters, where the level of the actual can be arbitrary).
3890 -- We can't use Valid_Conversion to perform this check because
3891 -- in general the type of the allocator is unrelated to the type
3892 -- of the access discriminant.
3894 if Ekind (Typ) /= E_Anonymous_Access_Type
3895 or else Is_Local_Anonymous_Access (Typ)
3897 Subtyp := Entity (Subtype_Mark (E));
3899 Aggr := Original_Node (Expression (E));
3901 if Has_Discriminants (Subtyp)
3902 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
3904 Discrim := First_Discriminant (Base_Type (Subtyp));
3906 -- Get the first component expression of the aggregate
3908 if Present (Expressions (Aggr)) then
3909 Disc_Exp := First (Expressions (Aggr));
3911 elsif Present (Component_Associations (Aggr)) then
3912 Assoc := First (Component_Associations (Aggr));
3914 if Present (Assoc) then
3915 Disc_Exp := Expression (Assoc);
3924 while Present (Discrim) and then Present (Disc_Exp) loop
3925 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
3926 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
3929 Next_Discriminant (Discrim);
3931 if Present (Discrim) then
3932 if Present (Assoc) then
3934 Disc_Exp := Expression (Assoc);
3936 elsif Present (Next (Disc_Exp)) then
3940 Assoc := First (Component_Associations (Aggr));
3942 if Present (Assoc) then
3943 Disc_Exp := Expression (Assoc);
3953 -- For a subtype mark or subtype indication, freeze the subtype
3956 Freeze_Expression (E);
3958 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
3960 ("initialization required for access-to-constant allocator", N);
3963 -- A special accessibility check is needed for allocators that
3964 -- constrain access discriminants. The level of the type of the
3965 -- expression used to constrain an access discriminant cannot be
3966 -- deeper than the type of the allocator (in contrast to access
3967 -- parameters, where the level of the actual can be arbitrary).
3968 -- We can't use Valid_Conversion to perform this check because
3969 -- in general the type of the allocator is unrelated to the type
3970 -- of the access discriminant.
3972 if Nkind (Original_Node (E)) = N_Subtype_Indication
3973 and then (Ekind (Typ) /= E_Anonymous_Access_Type
3974 or else Is_Local_Anonymous_Access (Typ))
3976 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
3978 if Has_Discriminants (Subtyp) then
3979 Discrim := First_Discriminant (Base_Type (Subtyp));
3980 Constr := First (Constraints (Constraint (Original_Node (E))));
3981 while Present (Discrim) and then Present (Constr) loop
3982 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
3983 if Nkind (Constr) = N_Discriminant_Association then
3984 Disc_Exp := Original_Node (Expression (Constr));
3986 Disc_Exp := Original_Node (Constr);
3989 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
3992 Next_Discriminant (Discrim);
3999 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4000 -- check that the level of the type of the created object is not deeper
4001 -- than the level of the allocator's access type, since extensions can
4002 -- now occur at deeper levels than their ancestor types. This is a
4003 -- static accessibility level check; a run-time check is also needed in
4004 -- the case of an initialized allocator with a class-wide argument (see
4005 -- Expand_Allocator_Expression).
4007 if Ada_Version >= Ada_05
4008 and then Is_Class_Wide_Type (Designated_Type (Typ))
4011 Exp_Typ : Entity_Id;
4014 if Nkind (E) = N_Qualified_Expression then
4015 Exp_Typ := Etype (E);
4016 elsif Nkind (E) = N_Subtype_Indication then
4017 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4019 Exp_Typ := Entity (E);
4022 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4023 if In_Instance_Body then
4024 Error_Msg_N ("?type in allocator has deeper level than" &
4025 " designated class-wide type", E);
4026 Error_Msg_N ("\?Program_Error will be raised at run time",
4029 Make_Raise_Program_Error (Sloc (N),
4030 Reason => PE_Accessibility_Check_Failed));
4033 -- Do not apply Ada 2005 accessibility checks on a class-wide
4034 -- allocator if the type given in the allocator is a formal
4035 -- type. A run-time check will be performed in the instance.
4037 elsif not Is_Generic_Type (Exp_Typ) then
4038 Error_Msg_N ("type in allocator has deeper level than" &
4039 " designated class-wide type", E);
4045 -- Check for allocation from an empty storage pool
4047 if No_Pool_Assigned (Typ) then
4049 Loc : constant Source_Ptr := Sloc (N);
4051 Error_Msg_N ("?allocation from empty storage pool!", N);
4052 Error_Msg_N ("\?Storage_Error will be raised at run time!", N);
4054 Make_Raise_Storage_Error (Loc,
4055 Reason => SE_Empty_Storage_Pool));
4058 -- If the context is an unchecked conversion, as may happen within
4059 -- an inlined subprogram, the allocator is being resolved with its
4060 -- own anonymous type. In that case, if the target type has a specific
4061 -- storage pool, it must be inherited explicitly by the allocator type.
4063 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4064 and then No (Associated_Storage_Pool (Typ))
4066 Set_Associated_Storage_Pool
4067 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4070 -- An erroneous allocator may be rewritten as a raise Program_Error
4073 if Nkind (N) = N_Allocator then
4075 -- An anonymous access discriminant is the definition of a
4078 if Ekind (Typ) = E_Anonymous_Access_Type
4079 and then Nkind (Associated_Node_For_Itype (Typ)) =
4080 N_Discriminant_Specification
4082 -- Avoid marking an allocator as a dynamic coextension if it is
4083 -- within a static construct.
4085 if not Is_Static_Coextension (N) then
4086 Set_Is_Dynamic_Coextension (N);
4089 -- Cleanup for potential static coextensions
4092 Set_Is_Dynamic_Coextension (N, False);
4093 Set_Is_Static_Coextension (N, False);
4096 -- There is no need to propagate any nested coextensions if they
4097 -- are marked as static since they will be rewritten on the spot.
4099 if not Is_Static_Coextension (N) then
4100 Propagate_Coextensions (N);
4103 end Resolve_Allocator;
4105 ---------------------------
4106 -- Resolve_Arithmetic_Op --
4107 ---------------------------
4109 -- Used for resolving all arithmetic operators except exponentiation
4111 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4112 L : constant Node_Id := Left_Opnd (N);
4113 R : constant Node_Id := Right_Opnd (N);
4114 TL : constant Entity_Id := Base_Type (Etype (L));
4115 TR : constant Entity_Id := Base_Type (Etype (R));
4119 B_Typ : constant Entity_Id := Base_Type (Typ);
4120 -- We do the resolution using the base type, because intermediate values
4121 -- in expressions always are of the base type, not a subtype of it.
4123 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4124 -- Returns True if N is in a context that expects "any real type"
4126 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4127 -- Return True iff given type is Integer or universal real/integer
4129 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4130 -- Choose type of integer literal in fixed-point operation to conform
4131 -- to available fixed-point type. T is the type of the other operand,
4132 -- which is needed to determine the expected type of N.
4134 procedure Set_Operand_Type (N : Node_Id);
4135 -- Set operand type to T if universal
4137 -------------------------------
4138 -- Expected_Type_Is_Any_Real --
4139 -------------------------------
4141 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4143 -- N is the expression after "delta" in a fixed_point_definition;
4146 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4147 N_Decimal_Fixed_Point_Definition,
4149 -- N is one of the bounds in a real_range_specification;
4152 N_Real_Range_Specification,
4154 -- N is the expression of a delta_constraint;
4157 N_Delta_Constraint);
4158 end Expected_Type_Is_Any_Real;
4160 -----------------------------
4161 -- Is_Integer_Or_Universal --
4162 -----------------------------
4164 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4166 Index : Interp_Index;
4170 if not Is_Overloaded (N) then
4172 return Base_Type (T) = Base_Type (Standard_Integer)
4173 or else T = Universal_Integer
4174 or else T = Universal_Real;
4176 Get_First_Interp (N, Index, It);
4177 while Present (It.Typ) loop
4178 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4179 or else It.Typ = Universal_Integer
4180 or else It.Typ = Universal_Real
4185 Get_Next_Interp (Index, It);
4190 end Is_Integer_Or_Universal;
4192 ----------------------------
4193 -- Set_Mixed_Mode_Operand --
4194 ----------------------------
4196 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4197 Index : Interp_Index;
4201 if Universal_Interpretation (N) = Universal_Integer then
4203 -- A universal integer literal is resolved as standard integer
4204 -- except in the case of a fixed-point result, where we leave it
4205 -- as universal (to be handled by Exp_Fixd later on)
4207 if Is_Fixed_Point_Type (T) then
4208 Resolve (N, Universal_Integer);
4210 Resolve (N, Standard_Integer);
4213 elsif Universal_Interpretation (N) = Universal_Real
4214 and then (T = Base_Type (Standard_Integer)
4215 or else T = Universal_Integer
4216 or else T = Universal_Real)
4218 -- A universal real can appear in a fixed-type context. We resolve
4219 -- the literal with that context, even though this might raise an
4220 -- exception prematurely (the other operand may be zero).
4224 elsif Etype (N) = Base_Type (Standard_Integer)
4225 and then T = Universal_Real
4226 and then Is_Overloaded (N)
4228 -- Integer arg in mixed-mode operation. Resolve with universal
4229 -- type, in case preference rule must be applied.
4231 Resolve (N, Universal_Integer);
4234 and then B_Typ /= Universal_Fixed
4236 -- Not a mixed-mode operation, resolve with context
4240 elsif Etype (N) = Any_Fixed then
4242 -- N may itself be a mixed-mode operation, so use context type
4246 elsif Is_Fixed_Point_Type (T)
4247 and then B_Typ = Universal_Fixed
4248 and then Is_Overloaded (N)
4250 -- Must be (fixed * fixed) operation, operand must have one
4251 -- compatible interpretation.
4253 Resolve (N, Any_Fixed);
4255 elsif Is_Fixed_Point_Type (B_Typ)
4256 and then (T = Universal_Real
4257 or else Is_Fixed_Point_Type (T))
4258 and then Is_Overloaded (N)
4260 -- C * F(X) in a fixed context, where C is a real literal or a
4261 -- fixed-point expression. F must have either a fixed type
4262 -- interpretation or an integer interpretation, but not both.
4264 Get_First_Interp (N, Index, It);
4265 while Present (It.Typ) loop
4266 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4268 if Analyzed (N) then
4269 Error_Msg_N ("ambiguous operand in fixed operation", N);
4271 Resolve (N, Standard_Integer);
4274 elsif Is_Fixed_Point_Type (It.Typ) then
4276 if Analyzed (N) then
4277 Error_Msg_N ("ambiguous operand in fixed operation", N);
4279 Resolve (N, It.Typ);
4283 Get_Next_Interp (Index, It);
4286 -- Reanalyze the literal with the fixed type of the context. If
4287 -- context is Universal_Fixed, we are within a conversion, leave
4288 -- the literal as a universal real because there is no usable
4289 -- fixed type, and the target of the conversion plays no role in
4303 if B_Typ = Universal_Fixed
4304 and then Nkind (Op2) = N_Real_Literal
4306 T2 := Universal_Real;
4311 Set_Analyzed (Op2, False);
4318 end Set_Mixed_Mode_Operand;
4320 ----------------------
4321 -- Set_Operand_Type --
4322 ----------------------
4324 procedure Set_Operand_Type (N : Node_Id) is
4326 if Etype (N) = Universal_Integer
4327 or else Etype (N) = Universal_Real
4331 end Set_Operand_Type;
4333 -- Start of processing for Resolve_Arithmetic_Op
4336 if Comes_From_Source (N)
4337 and then Ekind (Entity (N)) = E_Function
4338 and then Is_Imported (Entity (N))
4339 and then Is_Intrinsic_Subprogram (Entity (N))
4341 Resolve_Intrinsic_Operator (N, Typ);
4344 -- Special-case for mixed-mode universal expressions or fixed point
4345 -- type operation: each argument is resolved separately. The same
4346 -- treatment is required if one of the operands of a fixed point
4347 -- operation is universal real, since in this case we don't do a
4348 -- conversion to a specific fixed-point type (instead the expander
4349 -- takes care of the case).
4351 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4352 and then Present (Universal_Interpretation (L))
4353 and then Present (Universal_Interpretation (R))
4355 Resolve (L, Universal_Interpretation (L));
4356 Resolve (R, Universal_Interpretation (R));
4357 Set_Etype (N, B_Typ);
4359 elsif (B_Typ = Universal_Real
4360 or else Etype (N) = Universal_Fixed
4361 or else (Etype (N) = Any_Fixed
4362 and then Is_Fixed_Point_Type (B_Typ))
4363 or else (Is_Fixed_Point_Type (B_Typ)
4364 and then (Is_Integer_Or_Universal (L)
4366 Is_Integer_Or_Universal (R))))
4367 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4369 if TL = Universal_Integer or else TR = Universal_Integer then
4370 Check_For_Visible_Operator (N, B_Typ);
4373 -- If context is a fixed type and one operand is integer, the
4374 -- other is resolved with the type of the context.
4376 if Is_Fixed_Point_Type (B_Typ)
4377 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4378 or else TL = Universal_Integer)
4383 elsif Is_Fixed_Point_Type (B_Typ)
4384 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4385 or else TR = Universal_Integer)
4391 Set_Mixed_Mode_Operand (L, TR);
4392 Set_Mixed_Mode_Operand (R, TL);
4395 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4396 -- multiplying operators from being used when the expected type is
4397 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4398 -- some cases where the expected type is actually Any_Real;
4399 -- Expected_Type_Is_Any_Real takes care of that case.
4401 if Etype (N) = Universal_Fixed
4402 or else Etype (N) = Any_Fixed
4404 if B_Typ = Universal_Fixed
4405 and then not Expected_Type_Is_Any_Real (N)
4406 and then not Nkind_In (Parent (N), N_Type_Conversion,
4407 N_Unchecked_Type_Conversion)
4409 Error_Msg_N ("type cannot be determined from context!", N);
4410 Error_Msg_N ("\explicit conversion to result type required", N);
4412 Set_Etype (L, Any_Type);
4413 Set_Etype (R, Any_Type);
4416 if Ada_Version = Ada_83
4417 and then Etype (N) = Universal_Fixed
4419 Nkind_In (Parent (N), N_Type_Conversion,
4420 N_Unchecked_Type_Conversion)
4423 ("(Ada 83) fixed-point operation "
4424 & "needs explicit conversion", N);
4427 -- The expected type is "any real type" in contexts like
4428 -- type T is delta <universal_fixed-expression> ...
4429 -- in which case we need to set the type to Universal_Real
4430 -- so that static expression evaluation will work properly.
4432 if Expected_Type_Is_Any_Real (N) then
4433 Set_Etype (N, Universal_Real);
4435 Set_Etype (N, B_Typ);
4439 elsif Is_Fixed_Point_Type (B_Typ)
4440 and then (Is_Integer_Or_Universal (L)
4441 or else Nkind (L) = N_Real_Literal
4442 or else Nkind (R) = N_Real_Literal
4443 or else Is_Integer_Or_Universal (R))
4445 Set_Etype (N, B_Typ);
4447 elsif Etype (N) = Any_Fixed then
4449 -- If no previous errors, this is only possible if one operand
4450 -- is overloaded and the context is universal. Resolve as such.
4452 Set_Etype (N, B_Typ);
4456 if (TL = Universal_Integer or else TL = Universal_Real)
4458 (TR = Universal_Integer or else TR = Universal_Real)
4460 Check_For_Visible_Operator (N, B_Typ);
4463 -- If the context is Universal_Fixed and the operands are also
4464 -- universal fixed, this is an error, unless there is only one
4465 -- applicable fixed_point type (usually duration).
4467 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4468 T := Unique_Fixed_Point_Type (N);
4470 if T = Any_Type then
4483 -- If one of the arguments was resolved to a non-universal type.
4484 -- label the result of the operation itself with the same type.
4485 -- Do the same for the universal argument, if any.
4487 T := Intersect_Types (L, R);
4488 Set_Etype (N, Base_Type (T));
4489 Set_Operand_Type (L);
4490 Set_Operand_Type (R);
4493 Generate_Operator_Reference (N, Typ);
4494 Eval_Arithmetic_Op (N);
4496 -- Set overflow and division checking bit. Much cleverer code needed
4497 -- here eventually and perhaps the Resolve routines should be separated
4498 -- for the various arithmetic operations, since they will need
4499 -- different processing. ???
4501 if Nkind (N) in N_Op then
4502 if not Overflow_Checks_Suppressed (Etype (N)) then
4503 Enable_Overflow_Check (N);
4506 -- Give warning if explicit division by zero
4508 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4509 and then not Division_Checks_Suppressed (Etype (N))
4511 Rop := Right_Opnd (N);
4513 if Compile_Time_Known_Value (Rop)
4514 and then ((Is_Integer_Type (Etype (Rop))
4515 and then Expr_Value (Rop) = Uint_0)
4517 (Is_Real_Type (Etype (Rop))
4518 and then Expr_Value_R (Rop) = Ureal_0))
4520 -- Specialize the warning message according to the operation
4524 Apply_Compile_Time_Constraint_Error
4525 (N, "division by zero?", CE_Divide_By_Zero,
4526 Loc => Sloc (Right_Opnd (N)));
4529 Apply_Compile_Time_Constraint_Error
4530 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4531 Loc => Sloc (Right_Opnd (N)));
4534 Apply_Compile_Time_Constraint_Error
4535 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4536 Loc => Sloc (Right_Opnd (N)));
4538 -- Division by zero can only happen with division, rem,
4539 -- and mod operations.
4542 raise Program_Error;
4545 -- Otherwise just set the flag to check at run time
4548 Activate_Division_Check (N);
4552 -- If Restriction No_Implicit_Conditionals is active, then it is
4553 -- violated if either operand can be negative for mod, or for rem
4554 -- if both operands can be negative.
4556 if Restrictions.Set (No_Implicit_Conditionals)
4557 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4566 -- Set if corresponding operand might be negative
4569 Determine_Range (Left_Opnd (N), OK, Lo, Hi);
4570 LNeg := (not OK) or else Lo < 0;
4572 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
4573 RNeg := (not OK) or else Lo < 0;
4575 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4577 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
4579 Check_Restriction (No_Implicit_Conditionals, N);
4585 Check_Unset_Reference (L);
4586 Check_Unset_Reference (R);
4587 end Resolve_Arithmetic_Op;
4593 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
4594 Loc : constant Source_Ptr := Sloc (N);
4595 Subp : constant Node_Id := Name (N);
4604 -- The context imposes a unique interpretation with type Typ on a
4605 -- procedure or function call. Find the entity of the subprogram that
4606 -- yields the expected type, and propagate the corresponding formal
4607 -- constraints on the actuals. The caller has established that an
4608 -- interpretation exists, and emitted an error if not unique.
4610 -- First deal with the case of a call to an access-to-subprogram,
4611 -- dereference made explicit in Analyze_Call.
4613 if Ekind (Etype (Subp)) = E_Subprogram_Type then
4614 if not Is_Overloaded (Subp) then
4615 Nam := Etype (Subp);
4618 -- Find the interpretation whose type (a subprogram type) has a
4619 -- return type that is compatible with the context. Analysis of
4620 -- the node has established that one exists.
4624 Get_First_Interp (Subp, I, It);
4625 while Present (It.Typ) loop
4626 if Covers (Typ, Etype (It.Typ)) then
4631 Get_Next_Interp (I, It);
4635 raise Program_Error;
4639 -- If the prefix is not an entity, then resolve it
4641 if not Is_Entity_Name (Subp) then
4642 Resolve (Subp, Nam);
4645 -- For an indirect call, we always invalidate checks, since we do not
4646 -- know whether the subprogram is local or global. Yes we could do
4647 -- better here, e.g. by knowing that there are no local subprograms,
4648 -- but it does not seem worth the effort. Similarly, we kill all
4649 -- knowledge of current constant values.
4651 Kill_Current_Values;
4653 -- If this is a procedure call which is really an entry call, do
4654 -- the conversion of the procedure call to an entry call. Protected
4655 -- operations use the same circuitry because the name in the call
4656 -- can be an arbitrary expression with special resolution rules.
4658 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
4659 or else (Is_Entity_Name (Subp)
4660 and then Ekind (Entity (Subp)) = E_Entry)
4662 Resolve_Entry_Call (N, Typ);
4663 Check_Elab_Call (N);
4665 -- Kill checks and constant values, as above for indirect case
4666 -- Who knows what happens when another task is activated?
4668 Kill_Current_Values;
4671 -- Normal subprogram call with name established in Resolve
4673 elsif not (Is_Type (Entity (Subp))) then
4674 Nam := Entity (Subp);
4675 Set_Entity_With_Style_Check (Subp, Nam);
4677 -- Otherwise we must have the case of an overloaded call
4680 pragma Assert (Is_Overloaded (Subp));
4681 Nam := Empty; -- We know that it will be assigned in loop below
4683 Get_First_Interp (Subp, I, It);
4684 while Present (It.Typ) loop
4685 if Covers (Typ, It.Typ) then
4687 Set_Entity_With_Style_Check (Subp, Nam);
4691 Get_Next_Interp (I, It);
4695 -- Check that a call to Current_Task does not occur in an entry body
4697 if Is_RTE (Nam, RE_Current_Task) then
4706 -- Exclude calls that occur within the default of a formal
4707 -- parameter of the entry, since those are evaluated outside
4710 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
4712 if Nkind (P) = N_Entry_Body
4713 or else (Nkind (P) = N_Subprogram_Body
4714 and then Is_Entry_Barrier_Function (P))
4718 ("?& should not be used in entry body (RM C.7(17))",
4721 ("\Program_Error will be raised at run time?", N, Nam);
4723 Make_Raise_Program_Error (Loc,
4724 Reason => PE_Current_Task_In_Entry_Body));
4725 Set_Etype (N, Rtype);
4732 -- Check that a procedure call does not occur in the context of the
4733 -- entry call statement of a conditional or timed entry call. Note that
4734 -- the case of a call to a subprogram renaming of an entry will also be
4735 -- rejected. The test for N not being an N_Entry_Call_Statement is
4736 -- defensive, covering the possibility that the processing of entry
4737 -- calls might reach this point due to later modifications of the code
4740 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4741 and then Nkind (N) /= N_Entry_Call_Statement
4742 and then Entry_Call_Statement (Parent (N)) = N
4744 if Ada_Version < Ada_05 then
4745 Error_Msg_N ("entry call required in select statement", N);
4747 -- Ada 2005 (AI-345): If a procedure_call_statement is used
4748 -- for a procedure_or_entry_call, the procedure_name or pro-
4749 -- cedure_prefix of the procedure_call_statement shall denote
4750 -- an entry renamed by a procedure, or (a view of) a primitive
4751 -- subprogram of a limited interface whose first parameter is
4752 -- a controlling parameter.
4754 elsif Nkind (N) = N_Procedure_Call_Statement
4755 and then not Is_Renamed_Entry (Nam)
4756 and then not Is_Controlling_Limited_Procedure (Nam)
4759 ("entry call or dispatching primitive of interface required", N);
4763 -- Check that this is not a call to a protected procedure or
4764 -- entry from within a protected function.
4766 if Ekind (Current_Scope) = E_Function
4767 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
4768 and then Ekind (Nam) /= E_Function
4769 and then Scope (Nam) = Scope (Current_Scope)
4771 Error_Msg_N ("within protected function, protected " &
4772 "object is constant", N);
4773 Error_Msg_N ("\cannot call operation that may modify it", N);
4776 -- Freeze the subprogram name if not in a spec-expression. Note that we
4777 -- freeze procedure calls as well as function calls. Procedure calls are
4778 -- not frozen according to the rules (RM 13.14(14)) because it is
4779 -- impossible to have a procedure call to a non-frozen procedure in pure
4780 -- Ada, but in the code that we generate in the expander, this rule
4781 -- needs extending because we can generate procedure calls that need
4784 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
4785 Freeze_Expression (Subp);
4788 -- For a predefined operator, the type of the result is the type imposed
4789 -- by context, except for a predefined operation on universal fixed.
4790 -- Otherwise The type of the call is the type returned by the subprogram
4793 if Is_Predefined_Op (Nam) then
4794 if Etype (N) /= Universal_Fixed then
4798 -- If the subprogram returns an array type, and the context requires the
4799 -- component type of that array type, the node is really an indexing of
4800 -- the parameterless call. Resolve as such. A pathological case occurs
4801 -- when the type of the component is an access to the array type. In
4802 -- this case the call is truly ambiguous.
4804 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
4806 ((Is_Array_Type (Etype (Nam))
4807 and then Covers (Typ, Component_Type (Etype (Nam))))
4808 or else (Is_Access_Type (Etype (Nam))
4809 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4812 Component_Type (Designated_Type (Etype (Nam))))))
4815 Index_Node : Node_Id;
4817 Ret_Type : constant Entity_Id := Etype (Nam);
4820 if Is_Access_Type (Ret_Type)
4821 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
4824 ("cannot disambiguate function call and indexing", N);
4826 New_Subp := Relocate_Node (Subp);
4827 Set_Entity (Subp, Nam);
4829 if Component_Type (Ret_Type) /= Any_Type then
4830 if Needs_No_Actuals (Nam) then
4832 -- Indexed call to a parameterless function
4835 Make_Indexed_Component (Loc,
4837 Make_Function_Call (Loc,
4839 Expressions => Parameter_Associations (N));
4841 -- An Ada 2005 prefixed call to a primitive operation
4842 -- whose first parameter is the prefix. This prefix was
4843 -- prepended to the parameter list, which is actually a
4844 -- list of indices. Remove the prefix in order to build
4845 -- the proper indexed component.
4848 Make_Indexed_Component (Loc,
4850 Make_Function_Call (Loc,
4852 Parameter_Associations =>
4854 (Remove_Head (Parameter_Associations (N)))),
4855 Expressions => Parameter_Associations (N));
4858 -- Since we are correcting a node classification error made
4859 -- by the parser, we call Replace rather than Rewrite.
4861 Replace (N, Index_Node);
4862 Set_Etype (Prefix (N), Ret_Type);
4864 Resolve_Indexed_Component (N, Typ);
4865 Check_Elab_Call (Prefix (N));
4873 Set_Etype (N, Etype (Nam));
4876 -- In the case where the call is to an overloaded subprogram, Analyze
4877 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
4878 -- such a case Normalize_Actuals needs to be called once more to order
4879 -- the actuals correctly. Otherwise the call will have the ordering
4880 -- given by the last overloaded subprogram whether this is the correct
4881 -- one being called or not.
4883 if Is_Overloaded (Subp) then
4884 Normalize_Actuals (N, Nam, False, Norm_OK);
4885 pragma Assert (Norm_OK);
4888 -- In any case, call is fully resolved now. Reset Overload flag, to
4889 -- prevent subsequent overload resolution if node is analyzed again
4891 Set_Is_Overloaded (Subp, False);
4892 Set_Is_Overloaded (N, False);
4894 -- If we are calling the current subprogram from immediately within its
4895 -- body, then that is the case where we can sometimes detect cases of
4896 -- infinite recursion statically. Do not try this in case restriction
4897 -- No_Recursion is in effect anyway, and do it only for source calls.
4899 if Comes_From_Source (N) then
4900 Scop := Current_Scope;
4902 -- Issue warning for possible infinite recursion in the absence
4903 -- of the No_Recursion restriction.
4906 and then not Restriction_Active (No_Recursion)
4907 and then Check_Infinite_Recursion (N)
4909 -- Here we detected and flagged an infinite recursion, so we do
4910 -- not need to test the case below for further warnings. Also if
4911 -- we now have a raise SE node, we are all done.
4913 if Nkind (N) = N_Raise_Storage_Error then
4917 -- If call is to immediately containing subprogram, then check for
4918 -- the case of a possible run-time detectable infinite recursion.
4921 Scope_Loop : while Scop /= Standard_Standard loop
4924 -- Although in general case, recursion is not statically
4925 -- checkable, the case of calling an immediately containing
4926 -- subprogram is easy to catch.
4928 Check_Restriction (No_Recursion, N);
4930 -- If the recursive call is to a parameterless subprogram,
4931 -- then even if we can't statically detect infinite
4932 -- recursion, this is pretty suspicious, and we output a
4933 -- warning. Furthermore, we will try later to detect some
4934 -- cases here at run time by expanding checking code (see
4935 -- Detect_Infinite_Recursion in package Exp_Ch6).
4937 -- If the recursive call is within a handler, do not emit a
4938 -- warning, because this is a common idiom: loop until input
4939 -- is correct, catch illegal input in handler and restart.
4941 if No (First_Formal (Nam))
4942 and then Etype (Nam) = Standard_Void_Type
4943 and then not Error_Posted (N)
4944 and then Nkind (Parent (N)) /= N_Exception_Handler
4946 -- For the case of a procedure call. We give the message
4947 -- only if the call is the first statement in a sequence
4948 -- of statements, or if all previous statements are
4949 -- simple assignments. This is simply a heuristic to
4950 -- decrease false positives, without losing too many good
4951 -- warnings. The idea is that these previous statements
4952 -- may affect global variables the procedure depends on.
4954 if Nkind (N) = N_Procedure_Call_Statement
4955 and then Is_List_Member (N)
4961 while Present (P) loop
4962 if Nkind (P) /= N_Assignment_Statement then
4971 -- Do not give warning if we are in a conditional context
4974 K : constant Node_Kind := Nkind (Parent (N));
4976 if (K = N_Loop_Statement
4977 and then Present (Iteration_Scheme (Parent (N))))
4978 or else K = N_If_Statement
4979 or else K = N_Elsif_Part
4980 or else K = N_Case_Statement_Alternative
4986 -- Here warning is to be issued
4988 Set_Has_Recursive_Call (Nam);
4990 ("?possible infinite recursion!", N);
4992 ("\?Storage_Error may be raised at run time!", N);
4998 Scop := Scope (Scop);
4999 end loop Scope_Loop;
5003 -- If subprogram name is a predefined operator, it was given in
5004 -- functional notation. Replace call node with operator node, so
5005 -- that actuals can be resolved appropriately.
5007 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5008 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5011 elsif Present (Alias (Nam))
5012 and then Is_Predefined_Op (Alias (Nam))
5014 Resolve_Actuals (N, Nam);
5015 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5019 -- Create a transient scope if the resulting type requires it
5021 -- There are 4 notable exceptions: in init procs, the transient scope
5022 -- overhead is not needed and even incorrect due to the actual expansion
5023 -- of adjust calls; the second case is enumeration literal pseudo calls;
5024 -- the third case is intrinsic subprograms (Unchecked_Conversion and
5025 -- source information functions) that do not use the secondary stack
5026 -- even though the return type is unconstrained; the fourth case is a
5027 -- call to a build-in-place function, since such functions may allocate
5028 -- their result directly in a target object, and cases where the result
5029 -- does get allocated in the secondary stack are checked for within the
5030 -- specialized Exp_Ch6 procedures for expanding build-in-place calls.
5032 -- If this is an initialization call for a type whose initialization
5033 -- uses the secondary stack, we also need to create a transient scope
5034 -- for it, precisely because we will not do it within the init proc
5037 -- If the subprogram is marked Inline_Always, then even if it returns
5038 -- an unconstrained type the call does not require use of the secondary
5039 -- stack. However, inlining will only take place if the body to inline
5040 -- is already present. It may not be available if e.g. the subprogram is
5041 -- declared in a child instance.
5044 and then Has_Pragma_Inline_Always (Nam)
5045 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5046 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5050 elsif Expander_Active
5051 and then Is_Type (Etype (Nam))
5052 and then Requires_Transient_Scope (Etype (Nam))
5053 and then not Is_Build_In_Place_Function (Nam)
5054 and then Ekind (Nam) /= E_Enumeration_Literal
5055 and then not Within_Init_Proc
5056 and then not Is_Intrinsic_Subprogram (Nam)
5058 Establish_Transient_Scope (N, Sec_Stack => True);
5060 -- If the call appears within the bounds of a loop, it will
5061 -- be rewritten and reanalyzed, nothing left to do here.
5063 if Nkind (N) /= N_Function_Call then
5067 elsif Is_Init_Proc (Nam)
5068 and then not Within_Init_Proc
5070 Check_Initialization_Call (N, Nam);
5073 -- A protected function cannot be called within the definition of the
5074 -- enclosing protected type.
5076 if Is_Protected_Type (Scope (Nam))
5077 and then In_Open_Scopes (Scope (Nam))
5078 and then not Has_Completion (Scope (Nam))
5081 ("& cannot be called before end of protected definition", N, Nam);
5084 -- Propagate interpretation to actuals, and add default expressions
5087 if Present (First_Formal (Nam)) then
5088 Resolve_Actuals (N, Nam);
5090 -- Overloaded literals are rewritten as function calls, for
5091 -- purpose of resolution. After resolution, we can replace
5092 -- the call with the literal itself.
5094 elsif Ekind (Nam) = E_Enumeration_Literal then
5095 Copy_Node (Subp, N);
5096 Resolve_Entity_Name (N, Typ);
5098 -- Avoid validation, since it is a static function call
5100 Generate_Reference (Nam, Subp);
5104 -- If the subprogram is not global, then kill all saved values and
5105 -- checks. This is a bit conservative, since in many cases we could do
5106 -- better, but it is not worth the effort. Similarly, we kill constant
5107 -- values. However we do not need to do this for internal entities
5108 -- (unless they are inherited user-defined subprograms), since they
5109 -- are not in the business of molesting local values.
5111 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5112 -- kill all checks and values for calls to global subprograms. This
5113 -- takes care of the case where an access to a local subprogram is
5114 -- taken, and could be passed directly or indirectly and then called
5115 -- from almost any context.
5117 -- Note: we do not do this step till after resolving the actuals. That
5118 -- way we still take advantage of the current value information while
5119 -- scanning the actuals.
5121 -- We suppress killing values if we are processing the nodes associated
5122 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5123 -- type kills all the values as part of analyzing the code that
5124 -- initializes the dispatch tables.
5126 if Inside_Freezing_Actions = 0
5127 and then (not Is_Library_Level_Entity (Nam)
5128 or else Suppress_Value_Tracking_On_Call (Current_Scope))
5129 and then (Comes_From_Source (Nam)
5130 or else (Present (Alias (Nam))
5131 and then Comes_From_Source (Alias (Nam))))
5133 Kill_Current_Values;
5136 -- If we are warning about unread OUT parameters, this is the place to
5137 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5138 -- after the above call to Kill_Current_Values (since that call clears
5139 -- the Last_Assignment field of all local variables).
5141 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5142 and then Comes_From_Source (N)
5143 and then In_Extended_Main_Source_Unit (N)
5150 F := First_Formal (Nam);
5151 A := First_Actual (N);
5152 while Present (F) and then Present (A) loop
5153 if (Ekind (F) = E_Out_Parameter
5154 or else Ekind (F) = E_In_Out_Parameter)
5155 and then Warn_On_Modified_As_Out_Parameter (F)
5156 and then Is_Entity_Name (A)
5157 and then Present (Entity (A))
5158 and then Comes_From_Source (N)
5159 and then Safe_To_Capture_Value (N, Entity (A))
5161 Set_Last_Assignment (Entity (A), A);
5170 -- If the subprogram is a primitive operation, check whether or not
5171 -- it is a correct dispatching call.
5173 if Is_Overloadable (Nam)
5174 and then Is_Dispatching_Operation (Nam)
5176 Check_Dispatching_Call (N);
5178 elsif Ekind (Nam) /= E_Subprogram_Type
5179 and then Is_Abstract_Subprogram (Nam)
5180 and then not In_Instance
5182 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5185 -- If this is a dispatching call, generate the appropriate reference,
5186 -- for better source navigation in GPS.
5188 if Is_Overloadable (Nam)
5189 and then Present (Controlling_Argument (N))
5191 Generate_Reference (Nam, Subp, 'R');
5193 Generate_Reference (Nam, Subp);
5196 if Is_Intrinsic_Subprogram (Nam) then
5197 Check_Intrinsic_Call (N);
5200 -- Check for violation of restriction No_Specific_Termination_Handlers
5202 if Is_RTE (Nam, RE_Set_Specific_Handler)
5204 Is_RTE (Nam, RE_Specific_Handler)
5206 Check_Restriction (No_Specific_Termination_Handlers, N);
5209 -- All done, evaluate call and deal with elaboration issues
5212 Check_Elab_Call (N);
5215 -------------------------------
5216 -- Resolve_Character_Literal --
5217 -------------------------------
5219 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5220 B_Typ : constant Entity_Id := Base_Type (Typ);
5224 -- Verify that the character does belong to the type of the context
5226 Set_Etype (N, B_Typ);
5227 Eval_Character_Literal (N);
5229 -- Wide_Wide_Character literals must always be defined, since the set
5230 -- of wide wide character literals is complete, i.e. if a character
5231 -- literal is accepted by the parser, then it is OK for wide wide
5232 -- character (out of range character literals are rejected).
5234 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5237 -- Always accept character literal for type Any_Character, which
5238 -- occurs in error situations and in comparisons of literals, both
5239 -- of which should accept all literals.
5241 elsif B_Typ = Any_Character then
5244 -- For Standard.Character or a type derived from it, check that
5245 -- the literal is in range
5247 elsif Root_Type (B_Typ) = Standard_Character then
5248 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5252 -- For Standard.Wide_Character or a type derived from it, check
5253 -- that the literal is in range
5255 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5256 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5260 -- For Standard.Wide_Wide_Character or a type derived from it, we
5261 -- know the literal is in range, since the parser checked!
5263 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5266 -- If the entity is already set, this has already been resolved in
5267 -- a generic context, or comes from expansion. Nothing else to do.
5269 elsif Present (Entity (N)) then
5272 -- Otherwise we have a user defined character type, and we can use
5273 -- the standard visibility mechanisms to locate the referenced entity
5276 C := Current_Entity (N);
5277 while Present (C) loop
5278 if Etype (C) = B_Typ then
5279 Set_Entity_With_Style_Check (N, C);
5280 Generate_Reference (C, N);
5288 -- If we fall through, then the literal does not match any of the
5289 -- entries of the enumeration type. This isn't just a constraint
5290 -- error situation, it is an illegality (see RM 4.2).
5293 ("character not defined for }", N, First_Subtype (B_Typ));
5294 end Resolve_Character_Literal;
5296 ---------------------------
5297 -- Resolve_Comparison_Op --
5298 ---------------------------
5300 -- Context requires a boolean type, and plays no role in resolution.
5301 -- Processing identical to that for equality operators. The result
5302 -- type is the base type, which matters when pathological subtypes of
5303 -- booleans with limited ranges are used.
5305 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5306 L : constant Node_Id := Left_Opnd (N);
5307 R : constant Node_Id := Right_Opnd (N);
5311 -- If this is an intrinsic operation which is not predefined, use
5312 -- the types of its declared arguments to resolve the possibly
5313 -- overloaded operands. Otherwise the operands are unambiguous and
5314 -- specify the expected type.
5316 if Scope (Entity (N)) /= Standard_Standard then
5317 T := Etype (First_Entity (Entity (N)));
5320 T := Find_Unique_Type (L, R);
5322 if T = Any_Fixed then
5323 T := Unique_Fixed_Point_Type (L);
5327 Set_Etype (N, Base_Type (Typ));
5328 Generate_Reference (T, N, ' ');
5330 if T /= Any_Type then
5332 or else T = Any_Composite
5333 or else T = Any_Character
5335 if T = Any_Character then
5336 Ambiguous_Character (L);
5338 Error_Msg_N ("ambiguous operands for comparison", N);
5341 Set_Etype (N, Any_Type);
5347 Check_Unset_Reference (L);
5348 Check_Unset_Reference (R);
5349 Generate_Operator_Reference (N, T);
5350 Eval_Relational_Op (N);
5353 end Resolve_Comparison_Op;
5355 ------------------------------------
5356 -- Resolve_Conditional_Expression --
5357 ------------------------------------
5359 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
5360 Condition : constant Node_Id := First (Expressions (N));
5361 Then_Expr : constant Node_Id := Next (Condition);
5362 Else_Expr : constant Node_Id := Next (Then_Expr);
5365 Resolve (Condition, Standard_Boolean);
5366 Resolve (Then_Expr, Typ);
5367 Resolve (Else_Expr, Typ);
5370 Eval_Conditional_Expression (N);
5371 end Resolve_Conditional_Expression;
5373 -----------------------------------------
5374 -- Resolve_Discrete_Subtype_Indication --
5375 -----------------------------------------
5377 procedure Resolve_Discrete_Subtype_Indication
5385 Analyze (Subtype_Mark (N));
5386 S := Entity (Subtype_Mark (N));
5388 if Nkind (Constraint (N)) /= N_Range_Constraint then
5389 Error_Msg_N ("expect range constraint for discrete type", N);
5390 Set_Etype (N, Any_Type);
5393 R := Range_Expression (Constraint (N));
5401 if Base_Type (S) /= Base_Type (Typ) then
5403 ("expect subtype of }", N, First_Subtype (Typ));
5405 -- Rewrite the constraint as a range of Typ
5406 -- to allow compilation to proceed further.
5409 Rewrite (Low_Bound (R),
5410 Make_Attribute_Reference (Sloc (Low_Bound (R)),
5411 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5412 Attribute_Name => Name_First));
5413 Rewrite (High_Bound (R),
5414 Make_Attribute_Reference (Sloc (High_Bound (R)),
5415 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5416 Attribute_Name => Name_First));
5420 Set_Etype (N, Etype (R));
5422 -- Additionally, we must check that the bounds are compatible
5423 -- with the given subtype, which might be different from the
5424 -- type of the context.
5426 Apply_Range_Check (R, S);
5428 -- ??? If the above check statically detects a Constraint_Error
5429 -- it replaces the offending bound(s) of the range R with a
5430 -- Constraint_Error node. When the itype which uses these bounds
5431 -- is frozen the resulting call to Duplicate_Subexpr generates
5432 -- a new temporary for the bounds.
5434 -- Unfortunately there are other itypes that are also made depend
5435 -- on these bounds, so when Duplicate_Subexpr is called they get
5436 -- a forward reference to the newly created temporaries and Gigi
5437 -- aborts on such forward references. This is probably sign of a
5438 -- more fundamental problem somewhere else in either the order of
5439 -- itype freezing or the way certain itypes are constructed.
5441 -- To get around this problem we call Remove_Side_Effects right
5442 -- away if either bounds of R are a Constraint_Error.
5445 L : constant Node_Id := Low_Bound (R);
5446 H : constant Node_Id := High_Bound (R);
5449 if Nkind (L) = N_Raise_Constraint_Error then
5450 Remove_Side_Effects (L);
5453 if Nkind (H) = N_Raise_Constraint_Error then
5454 Remove_Side_Effects (H);
5458 Check_Unset_Reference (Low_Bound (R));
5459 Check_Unset_Reference (High_Bound (R));
5462 end Resolve_Discrete_Subtype_Indication;
5464 -------------------------
5465 -- Resolve_Entity_Name --
5466 -------------------------
5468 -- Used to resolve identifiers and expanded names
5470 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
5471 E : constant Entity_Id := Entity (N);
5474 -- If garbage from errors, set to Any_Type and return
5476 if No (E) and then Total_Errors_Detected /= 0 then
5477 Set_Etype (N, Any_Type);
5481 -- Replace named numbers by corresponding literals. Note that this is
5482 -- the one case where Resolve_Entity_Name must reset the Etype, since
5483 -- it is currently marked as universal.
5485 if Ekind (E) = E_Named_Integer then
5487 Eval_Named_Integer (N);
5489 elsif Ekind (E) = E_Named_Real then
5491 Eval_Named_Real (N);
5493 -- Allow use of subtype only if it is a concurrent type where we are
5494 -- currently inside the body. This will eventually be expanded
5495 -- into a call to Self (for tasks) or _object (for protected
5496 -- objects). Any other use of a subtype is invalid.
5498 elsif Is_Type (E) then
5499 if Is_Concurrent_Type (E)
5500 and then In_Open_Scopes (E)
5505 ("invalid use of subtype mark in expression or call", N);
5508 -- Check discriminant use if entity is discriminant in current scope,
5509 -- i.e. discriminant of record or concurrent type currently being
5510 -- analyzed. Uses in corresponding body are unrestricted.
5512 elsif Ekind (E) = E_Discriminant
5513 and then Scope (E) = Current_Scope
5514 and then not Has_Completion (Current_Scope)
5516 Check_Discriminant_Use (N);
5518 -- A parameterless generic function cannot appear in a context that
5519 -- requires resolution.
5521 elsif Ekind (E) = E_Generic_Function then
5522 Error_Msg_N ("illegal use of generic function", N);
5524 elsif Ekind (E) = E_Out_Parameter
5525 and then Ada_Version = Ada_83
5526 and then (Nkind (Parent (N)) in N_Op
5527 or else (Nkind (Parent (N)) = N_Assignment_Statement
5528 and then N = Expression (Parent (N)))
5529 or else Nkind (Parent (N)) = N_Explicit_Dereference)
5531 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
5533 -- In all other cases, just do the possible static evaluation
5536 -- A deferred constant that appears in an expression must have
5537 -- a completion, unless it has been removed by in-place expansion
5540 if Ekind (E) = E_Constant
5541 and then Comes_From_Source (E)
5542 and then No (Constant_Value (E))
5543 and then Is_Frozen (Etype (E))
5544 and then not In_Spec_Expression
5545 and then not Is_Imported (E)
5548 if No_Initialization (Parent (E))
5549 or else (Present (Full_View (E))
5550 and then No_Initialization (Parent (Full_View (E))))
5555 "deferred constant is frozen before completion", N);
5559 Eval_Entity_Name (N);
5561 end Resolve_Entity_Name;
5567 procedure Resolve_Entry (Entry_Name : Node_Id) is
5568 Loc : constant Source_Ptr := Sloc (Entry_Name);
5576 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
5577 -- If the bounds of the entry family being called depend on task
5578 -- discriminants, build a new index subtype where a discriminant is
5579 -- replaced with the value of the discriminant of the target task.
5580 -- The target task is the prefix of the entry name in the call.
5582 -----------------------
5583 -- Actual_Index_Type --
5584 -----------------------
5586 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
5587 Typ : constant Entity_Id := Entry_Index_Type (E);
5588 Tsk : constant Entity_Id := Scope (E);
5589 Lo : constant Node_Id := Type_Low_Bound (Typ);
5590 Hi : constant Node_Id := Type_High_Bound (Typ);
5593 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
5594 -- If the bound is given by a discriminant, replace with a reference
5595 -- to the discriminant of the same name in the target task.
5596 -- If the entry name is the target of a requeue statement and the
5597 -- entry is in the current protected object, the bound to be used
5598 -- is the discriminal of the object (see apply_range_checks for
5599 -- details of the transformation).
5601 -----------------------------
5602 -- Actual_Discriminant_Ref --
5603 -----------------------------
5605 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
5606 Typ : constant Entity_Id := Etype (Bound);
5610 Remove_Side_Effects (Bound);
5612 if not Is_Entity_Name (Bound)
5613 or else Ekind (Entity (Bound)) /= E_Discriminant
5617 elsif Is_Protected_Type (Tsk)
5618 and then In_Open_Scopes (Tsk)
5619 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
5621 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
5625 Make_Selected_Component (Loc,
5626 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
5627 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
5632 end Actual_Discriminant_Ref;
5634 -- Start of processing for Actual_Index_Type
5637 if not Has_Discriminants (Tsk)
5638 or else (not Is_Entity_Name (Lo)
5639 and then not Is_Entity_Name (Hi))
5641 return Entry_Index_Type (E);
5644 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
5645 Set_Etype (New_T, Base_Type (Typ));
5646 Set_Size_Info (New_T, Typ);
5647 Set_RM_Size (New_T, RM_Size (Typ));
5648 Set_Scalar_Range (New_T,
5649 Make_Range (Sloc (Entry_Name),
5650 Low_Bound => Actual_Discriminant_Ref (Lo),
5651 High_Bound => Actual_Discriminant_Ref (Hi)));
5655 end Actual_Index_Type;
5657 -- Start of processing of Resolve_Entry
5660 -- Find name of entry being called, and resolve prefix of name
5661 -- with its own type. The prefix can be overloaded, and the name
5662 -- and signature of the entry must be taken into account.
5664 if Nkind (Entry_Name) = N_Indexed_Component then
5666 -- Case of dealing with entry family within the current tasks
5668 E_Name := Prefix (Entry_Name);
5671 E_Name := Entry_Name;
5674 if Is_Entity_Name (E_Name) then
5675 -- Entry call to an entry (or entry family) in the current task.
5676 -- This is legal even though the task will deadlock. Rewrite as
5677 -- call to current task.
5679 -- This can also be a call to an entry in an enclosing task.
5680 -- If this is a single task, we have to retrieve its name,
5681 -- because the scope of the entry is the task type, not the
5682 -- object. If the enclosing task is a task type, the identity
5683 -- of the task is given by its own self variable.
5685 -- Finally this can be a requeue on an entry of the same task
5686 -- or protected object.
5688 S := Scope (Entity (E_Name));
5690 for J in reverse 0 .. Scope_Stack.Last loop
5692 if Is_Task_Type (Scope_Stack.Table (J).Entity)
5693 and then not Comes_From_Source (S)
5695 -- S is an enclosing task or protected object. The concurrent
5696 -- declaration has been converted into a type declaration, and
5697 -- the object itself has an object declaration that follows
5698 -- the type in the same declarative part.
5700 Tsk := Next_Entity (S);
5701 while Etype (Tsk) /= S loop
5708 elsif S = Scope_Stack.Table (J).Entity then
5710 -- Call to current task. Will be transformed into call to Self
5718 Make_Selected_Component (Loc,
5719 Prefix => New_Occurrence_Of (S, Loc),
5721 New_Occurrence_Of (Entity (E_Name), Loc));
5722 Rewrite (E_Name, New_N);
5725 elsif Nkind (Entry_Name) = N_Selected_Component
5726 and then Is_Overloaded (Prefix (Entry_Name))
5728 -- Use the entry name (which must be unique at this point) to
5729 -- find the prefix that returns the corresponding task type or
5733 Pref : constant Node_Id := Prefix (Entry_Name);
5734 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
5739 Get_First_Interp (Pref, I, It);
5740 while Present (It.Typ) loop
5741 if Scope (Ent) = It.Typ then
5742 Set_Etype (Pref, It.Typ);
5746 Get_Next_Interp (I, It);
5751 if Nkind (Entry_Name) = N_Selected_Component then
5752 Resolve (Prefix (Entry_Name));
5754 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
5755 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
5756 Resolve (Prefix (Prefix (Entry_Name)));
5757 Index := First (Expressions (Entry_Name));
5758 Resolve (Index, Entry_Index_Type (Nam));
5760 -- Up to this point the expression could have been the actual
5761 -- in a simple entry call, and be given by a named association.
5763 if Nkind (Index) = N_Parameter_Association then
5764 Error_Msg_N ("expect expression for entry index", Index);
5766 Apply_Range_Check (Index, Actual_Index_Type (Nam));
5771 ------------------------
5772 -- Resolve_Entry_Call --
5773 ------------------------
5775 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
5776 Entry_Name : constant Node_Id := Name (N);
5777 Loc : constant Source_Ptr := Sloc (Entry_Name);
5779 First_Named : Node_Id;
5786 -- We kill all checks here, because it does not seem worth the
5787 -- effort to do anything better, an entry call is a big operation.
5791 -- Processing of the name is similar for entry calls and protected
5792 -- operation calls. Once the entity is determined, we can complete
5793 -- the resolution of the actuals.
5795 -- The selector may be overloaded, in the case of a protected object
5796 -- with overloaded functions. The type of the context is used for
5799 if Nkind (Entry_Name) = N_Selected_Component
5800 and then Is_Overloaded (Selector_Name (Entry_Name))
5801 and then Typ /= Standard_Void_Type
5808 Get_First_Interp (Selector_Name (Entry_Name), I, It);
5809 while Present (It.Typ) loop
5810 if Covers (Typ, It.Typ) then
5811 Set_Entity (Selector_Name (Entry_Name), It.Nam);
5812 Set_Etype (Entry_Name, It.Typ);
5814 Generate_Reference (It.Typ, N, ' ');
5817 Get_Next_Interp (I, It);
5822 Resolve_Entry (Entry_Name);
5824 if Nkind (Entry_Name) = N_Selected_Component then
5826 -- Simple entry call
5828 Nam := Entity (Selector_Name (Entry_Name));
5829 Obj := Prefix (Entry_Name);
5830 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
5832 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
5834 -- Call to member of entry family
5836 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
5837 Obj := Prefix (Prefix (Entry_Name));
5838 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
5841 -- We cannot in general check the maximum depth of protected entry
5842 -- calls at compile time. But we can tell that any protected entry
5843 -- call at all violates a specified nesting depth of zero.
5845 if Is_Protected_Type (Scope (Nam)) then
5846 Check_Restriction (Max_Entry_Queue_Length, N);
5849 -- Use context type to disambiguate a protected function that can be
5850 -- called without actuals and that returns an array type, and where
5851 -- the argument list may be an indexing of the returned value.
5853 if Ekind (Nam) = E_Function
5854 and then Needs_No_Actuals (Nam)
5855 and then Present (Parameter_Associations (N))
5857 ((Is_Array_Type (Etype (Nam))
5858 and then Covers (Typ, Component_Type (Etype (Nam))))
5860 or else (Is_Access_Type (Etype (Nam))
5861 and then Is_Array_Type (Designated_Type (Etype (Nam)))
5862 and then Covers (Typ,
5863 Component_Type (Designated_Type (Etype (Nam))))))
5866 Index_Node : Node_Id;
5870 Make_Indexed_Component (Loc,
5872 Make_Function_Call (Loc,
5873 Name => Relocate_Node (Entry_Name)),
5874 Expressions => Parameter_Associations (N));
5876 -- Since we are correcting a node classification error made by
5877 -- the parser, we call Replace rather than Rewrite.
5879 Replace (N, Index_Node);
5880 Set_Etype (Prefix (N), Etype (Nam));
5882 Resolve_Indexed_Component (N, Typ);
5887 -- The operation name may have been overloaded. Order the actuals
5888 -- according to the formals of the resolved entity, and set the
5889 -- return type to that of the operation.
5892 Normalize_Actuals (N, Nam, False, Norm_OK);
5893 pragma Assert (Norm_OK);
5894 Set_Etype (N, Etype (Nam));
5897 Resolve_Actuals (N, Nam);
5898 Generate_Reference (Nam, Entry_Name);
5900 if Ekind (Nam) = E_Entry
5901 or else Ekind (Nam) = E_Entry_Family
5903 Check_Potentially_Blocking_Operation (N);
5906 -- Verify that a procedure call cannot masquerade as an entry
5907 -- call where an entry call is expected.
5909 if Ekind (Nam) = E_Procedure then
5910 if Nkind (Parent (N)) = N_Entry_Call_Alternative
5911 and then N = Entry_Call_Statement (Parent (N))
5913 Error_Msg_N ("entry call required in select statement", N);
5915 elsif Nkind (Parent (N)) = N_Triggering_Alternative
5916 and then N = Triggering_Statement (Parent (N))
5918 Error_Msg_N ("triggering statement cannot be procedure call", N);
5920 elsif Ekind (Scope (Nam)) = E_Task_Type
5921 and then not In_Open_Scopes (Scope (Nam))
5923 Error_Msg_N ("task has no entry with this name", Entry_Name);
5927 -- After resolution, entry calls and protected procedure calls
5928 -- are changed into entry calls, for expansion. The structure
5929 -- of the node does not change, so it can safely be done in place.
5930 -- Protected function calls must keep their structure because they
5931 -- are subexpressions.
5933 if Ekind (Nam) /= E_Function then
5935 -- A protected operation that is not a function may modify the
5936 -- corresponding object, and cannot apply to a constant.
5937 -- If this is an internal call, the prefix is the type itself.
5939 if Is_Protected_Type (Scope (Nam))
5940 and then not Is_Variable (Obj)
5941 and then (not Is_Entity_Name (Obj)
5942 or else not Is_Type (Entity (Obj)))
5945 ("prefix of protected procedure or entry call must be variable",
5949 Actuals := Parameter_Associations (N);
5950 First_Named := First_Named_Actual (N);
5953 Make_Entry_Call_Statement (Loc,
5955 Parameter_Associations => Actuals));
5957 Set_First_Named_Actual (N, First_Named);
5958 Set_Analyzed (N, True);
5960 -- Protected functions can return on the secondary stack, in which
5961 -- case we must trigger the transient scope mechanism.
5963 elsif Expander_Active
5964 and then Requires_Transient_Scope (Etype (Nam))
5966 Establish_Transient_Scope (N, Sec_Stack => True);
5968 end Resolve_Entry_Call;
5970 -------------------------
5971 -- Resolve_Equality_Op --
5972 -------------------------
5974 -- Both arguments must have the same type, and the boolean context
5975 -- does not participate in the resolution. The first pass verifies
5976 -- that the interpretation is not ambiguous, and the type of the left
5977 -- argument is correctly set, or is Any_Type in case of ambiguity.
5978 -- If both arguments are strings or aggregates, allocators, or Null,
5979 -- they are ambiguous even though they carry a single (universal) type.
5980 -- Diagnose this case here.
5982 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
5983 L : constant Node_Id := Left_Opnd (N);
5984 R : constant Node_Id := Right_Opnd (N);
5985 T : Entity_Id := Find_Unique_Type (L, R);
5987 function Find_Unique_Access_Type return Entity_Id;
5988 -- In the case of allocators, make a last-ditch attempt to find a single
5989 -- access type with the right designated type. This is semantically
5990 -- dubious, and of no interest to any real code, but c48008a makes it
5993 -----------------------------
5994 -- Find_Unique_Access_Type --
5995 -----------------------------
5997 function Find_Unique_Access_Type return Entity_Id is
6003 if Ekind (Etype (R)) = E_Allocator_Type then
6004 Acc := Designated_Type (Etype (R));
6005 elsif Ekind (Etype (L)) = E_Allocator_Type then
6006 Acc := Designated_Type (Etype (L));
6012 while S /= Standard_Standard loop
6013 E := First_Entity (S);
6014 while Present (E) loop
6016 and then Is_Access_Type (E)
6017 and then Ekind (E) /= E_Allocator_Type
6018 and then Designated_Type (E) = Base_Type (Acc)
6030 end Find_Unique_Access_Type;
6032 -- Start of processing for Resolve_Equality_Op
6035 Set_Etype (N, Base_Type (Typ));
6036 Generate_Reference (T, N, ' ');
6038 if T = Any_Fixed then
6039 T := Unique_Fixed_Point_Type (L);
6042 if T /= Any_Type then
6044 or else T = Any_Composite
6045 or else T = Any_Character
6047 if T = Any_Character then
6048 Ambiguous_Character (L);
6050 Error_Msg_N ("ambiguous operands for equality", N);
6053 Set_Etype (N, Any_Type);
6056 elsif T = Any_Access
6057 or else Ekind (T) = E_Allocator_Type
6058 or else Ekind (T) = E_Access_Attribute_Type
6060 T := Find_Unique_Access_Type;
6063 Error_Msg_N ("ambiguous operands for equality", N);
6064 Set_Etype (N, Any_Type);
6072 -- If the unique type is a class-wide type then it will be expanded
6073 -- into a dispatching call to the predefined primitive. Therefore we
6074 -- check here for potential violation of such restriction.
6076 if Is_Class_Wide_Type (T) then
6077 Check_Restriction (No_Dispatching_Calls, N);
6080 if Warn_On_Redundant_Constructs
6081 and then Comes_From_Source (N)
6082 and then Is_Entity_Name (R)
6083 and then Entity (R) = Standard_True
6084 and then Comes_From_Source (R)
6086 Error_Msg_N ("?comparison with True is redundant!", R);
6089 Check_Unset_Reference (L);
6090 Check_Unset_Reference (R);
6091 Generate_Operator_Reference (N, T);
6093 -- If this is an inequality, it may be the implicit inequality
6094 -- created for a user-defined operation, in which case the corres-
6095 -- ponding equality operation is not intrinsic, and the operation
6096 -- cannot be constant-folded. Else fold.
6098 if Nkind (N) = N_Op_Eq
6099 or else Comes_From_Source (Entity (N))
6100 or else Ekind (Entity (N)) = E_Operator
6101 or else Is_Intrinsic_Subprogram
6102 (Corresponding_Equality (Entity (N)))
6104 Eval_Relational_Op (N);
6106 elsif Nkind (N) = N_Op_Ne
6107 and then Is_Abstract_Subprogram (Entity (N))
6109 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6112 -- Ada 2005: If one operand is an anonymous access type, convert
6113 -- the other operand to it, to ensure that the underlying types
6114 -- match in the back-end. Same for access_to_subprogram, and the
6115 -- conversion verifies that the types are subtype conformant.
6117 -- We apply the same conversion in the case one of the operands is
6118 -- a private subtype of the type of the other.
6120 -- Why the Expander_Active test here ???
6124 (Ekind (T) = E_Anonymous_Access_Type
6125 or else Ekind (T) = E_Anonymous_Access_Subprogram_Type
6126 or else Is_Private_Type (T))
6128 if Etype (L) /= T then
6130 Make_Unchecked_Type_Conversion (Sloc (L),
6131 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6132 Expression => Relocate_Node (L)));
6133 Analyze_And_Resolve (L, T);
6136 if (Etype (R)) /= T then
6138 Make_Unchecked_Type_Conversion (Sloc (R),
6139 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6140 Expression => Relocate_Node (R)));
6141 Analyze_And_Resolve (R, T);
6145 end Resolve_Equality_Op;
6147 ----------------------------------
6148 -- Resolve_Explicit_Dereference --
6149 ----------------------------------
6151 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6152 Loc : constant Source_Ptr := Sloc (N);
6154 P : constant Node_Id := Prefix (N);
6159 Check_Fully_Declared_Prefix (Typ, P);
6161 if Is_Overloaded (P) then
6163 -- Use the context type to select the prefix that has the correct
6166 Get_First_Interp (P, I, It);
6167 while Present (It.Typ) loop
6168 exit when Is_Access_Type (It.Typ)
6169 and then Covers (Typ, Designated_Type (It.Typ));
6170 Get_Next_Interp (I, It);
6173 if Present (It.Typ) then
6174 Resolve (P, It.Typ);
6176 -- If no interpretation covers the designated type of the prefix,
6177 -- this is the pathological case where not all implementations of
6178 -- the prefix allow the interpretation of the node as a call. Now
6179 -- that the expected type is known, Remove other interpretations
6180 -- from prefix, rewrite it as a call, and resolve again, so that
6181 -- the proper call node is generated.
6183 Get_First_Interp (P, I, It);
6184 while Present (It.Typ) loop
6185 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6189 Get_Next_Interp (I, It);
6193 Make_Function_Call (Loc,
6195 Make_Explicit_Dereference (Loc,
6197 Parameter_Associations => New_List);
6199 Save_Interps (N, New_N);
6201 Analyze_And_Resolve (N, Typ);
6205 Set_Etype (N, Designated_Type (It.Typ));
6211 if Is_Access_Type (Etype (P)) then
6212 Apply_Access_Check (N);
6215 -- If the designated type is a packed unconstrained array type, and the
6216 -- explicit dereference is not in the context of an attribute reference,
6217 -- then we must compute and set the actual subtype, since it is needed
6218 -- by Gigi. The reason we exclude the attribute case is that this is
6219 -- handled fine by Gigi, and in fact we use such attributes to build the
6220 -- actual subtype. We also exclude generated code (which builds actual
6221 -- subtypes directly if they are needed).
6223 if Is_Array_Type (Etype (N))
6224 and then Is_Packed (Etype (N))
6225 and then not Is_Constrained (Etype (N))
6226 and then Nkind (Parent (N)) /= N_Attribute_Reference
6227 and then Comes_From_Source (N)
6229 Set_Etype (N, Get_Actual_Subtype (N));
6232 -- Note: there is no Eval processing required for an explicit deference,
6233 -- because the type is known to be an allocators, and allocator
6234 -- expressions can never be static.
6236 end Resolve_Explicit_Dereference;
6238 -------------------------------
6239 -- Resolve_Indexed_Component --
6240 -------------------------------
6242 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
6243 Name : constant Node_Id := Prefix (N);
6245 Array_Type : Entity_Id := Empty; -- to prevent junk warning
6249 if Is_Overloaded (Name) then
6251 -- Use the context type to select the prefix that yields the correct
6257 I1 : Interp_Index := 0;
6258 P : constant Node_Id := Prefix (N);
6259 Found : Boolean := False;
6262 Get_First_Interp (P, I, It);
6263 while Present (It.Typ) loop
6264 if (Is_Array_Type (It.Typ)
6265 and then Covers (Typ, Component_Type (It.Typ)))
6266 or else (Is_Access_Type (It.Typ)
6267 and then Is_Array_Type (Designated_Type (It.Typ))
6269 (Typ, Component_Type (Designated_Type (It.Typ))))
6272 It := Disambiguate (P, I1, I, Any_Type);
6274 if It = No_Interp then
6275 Error_Msg_N ("ambiguous prefix for indexing", N);
6281 Array_Type := It.Typ;
6287 Array_Type := It.Typ;
6292 Get_Next_Interp (I, It);
6297 Array_Type := Etype (Name);
6300 Resolve (Name, Array_Type);
6301 Array_Type := Get_Actual_Subtype_If_Available (Name);
6303 -- If prefix is access type, dereference to get real array type.
6304 -- Note: we do not apply an access check because the expander always
6305 -- introduces an explicit dereference, and the check will happen there.
6307 if Is_Access_Type (Array_Type) then
6308 Array_Type := Designated_Type (Array_Type);
6311 -- If name was overloaded, set component type correctly now
6312 -- If a misplaced call to an entry family (which has no index types)
6313 -- return. Error will be diagnosed from calling context.
6315 if Is_Array_Type (Array_Type) then
6316 Set_Etype (N, Component_Type (Array_Type));
6321 Index := First_Index (Array_Type);
6322 Expr := First (Expressions (N));
6324 -- The prefix may have resolved to a string literal, in which case its
6325 -- etype has a special representation. This is only possible currently
6326 -- if the prefix is a static concatenation, written in functional
6329 if Ekind (Array_Type) = E_String_Literal_Subtype then
6330 Resolve (Expr, Standard_Positive);
6333 while Present (Index) and Present (Expr) loop
6334 Resolve (Expr, Etype (Index));
6335 Check_Unset_Reference (Expr);
6337 if Is_Scalar_Type (Etype (Expr)) then
6338 Apply_Scalar_Range_Check (Expr, Etype (Index));
6340 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
6348 -- Do not generate the warning on suspicious index if we are analyzing
6349 -- package Ada.Tags; otherwise we will report the warning with the
6350 -- Prims_Ptr field of the dispatch table.
6352 if Scope (Etype (Prefix (N))) = Standard_Standard
6354 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
6357 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
6358 Eval_Indexed_Component (N);
6360 end Resolve_Indexed_Component;
6362 -----------------------------
6363 -- Resolve_Integer_Literal --
6364 -----------------------------
6366 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
6369 Eval_Integer_Literal (N);
6370 end Resolve_Integer_Literal;
6372 --------------------------------
6373 -- Resolve_Intrinsic_Operator --
6374 --------------------------------
6376 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
6377 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6384 while Scope (Op) /= Standard_Standard loop
6386 pragma Assert (Present (Op));
6390 Set_Is_Overloaded (N, False);
6392 -- If the operand type is private, rewrite with suitable conversions on
6393 -- the operands and the result, to expose the proper underlying numeric
6396 if Is_Private_Type (Typ) then
6397 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
6399 if Nkind (N) = N_Op_Expon then
6400 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
6402 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6405 Save_Interps (Left_Opnd (N), Expression (Arg1));
6406 Save_Interps (Right_Opnd (N), Expression (Arg2));
6408 Set_Left_Opnd (N, Arg1);
6409 Set_Right_Opnd (N, Arg2);
6411 Set_Etype (N, Btyp);
6412 Rewrite (N, Unchecked_Convert_To (Typ, N));
6415 elsif Typ /= Etype (Left_Opnd (N))
6416 or else Typ /= Etype (Right_Opnd (N))
6418 -- Add explicit conversion where needed, and save interpretations
6419 -- in case operands are overloaded.
6421 Arg1 := Convert_To (Typ, Left_Opnd (N));
6422 Arg2 := Convert_To (Typ, Right_Opnd (N));
6424 if Nkind (Arg1) = N_Type_Conversion then
6425 Save_Interps (Left_Opnd (N), Expression (Arg1));
6427 Save_Interps (Left_Opnd (N), Arg1);
6430 if Nkind (Arg2) = N_Type_Conversion then
6431 Save_Interps (Right_Opnd (N), Expression (Arg2));
6433 Save_Interps (Right_Opnd (N), Arg2);
6436 Rewrite (Left_Opnd (N), Arg1);
6437 Rewrite (Right_Opnd (N), Arg2);
6440 Resolve_Arithmetic_Op (N, Typ);
6443 Resolve_Arithmetic_Op (N, Typ);
6445 end Resolve_Intrinsic_Operator;
6447 --------------------------------------
6448 -- Resolve_Intrinsic_Unary_Operator --
6449 --------------------------------------
6451 procedure Resolve_Intrinsic_Unary_Operator
6455 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6461 while Scope (Op) /= Standard_Standard loop
6463 pragma Assert (Present (Op));
6468 if Is_Private_Type (Typ) then
6469 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6470 Save_Interps (Right_Opnd (N), Expression (Arg2));
6472 Set_Right_Opnd (N, Arg2);
6474 Set_Etype (N, Btyp);
6475 Rewrite (N, Unchecked_Convert_To (Typ, N));
6479 Resolve_Unary_Op (N, Typ);
6481 end Resolve_Intrinsic_Unary_Operator;
6483 ------------------------
6484 -- Resolve_Logical_Op --
6485 ------------------------
6487 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
6489 N_Opr : constant Node_Kind := Nkind (N);
6492 -- Predefined operations on scalar types yield the base type. On the
6493 -- other hand, logical operations on arrays yield the type of the
6494 -- arguments (and the context).
6496 if Is_Array_Type (Typ) then
6499 B_Typ := Base_Type (Typ);
6502 -- The following test is required because the operands of the operation
6503 -- may be literals, in which case the resulting type appears to be
6504 -- compatible with a signed integer type, when in fact it is compatible
6505 -- only with modular types. If the context itself is universal, the
6506 -- operation is illegal.
6508 if not Valid_Boolean_Arg (Typ) then
6509 Error_Msg_N ("invalid context for logical operation", N);
6510 Set_Etype (N, Any_Type);
6513 elsif Typ = Any_Modular then
6515 ("no modular type available in this context", N);
6516 Set_Etype (N, Any_Type);
6518 elsif Is_Modular_Integer_Type (Typ)
6519 and then Etype (Left_Opnd (N)) = Universal_Integer
6520 and then Etype (Right_Opnd (N)) = Universal_Integer
6522 Check_For_Visible_Operator (N, B_Typ);
6525 Resolve (Left_Opnd (N), B_Typ);
6526 Resolve (Right_Opnd (N), B_Typ);
6528 Check_Unset_Reference (Left_Opnd (N));
6529 Check_Unset_Reference (Right_Opnd (N));
6531 Set_Etype (N, B_Typ);
6532 Generate_Operator_Reference (N, B_Typ);
6533 Eval_Logical_Op (N);
6535 -- Check for violation of restriction No_Direct_Boolean_Operators
6536 -- if the operator was not eliminated by the Eval_Logical_Op call.
6538 if Nkind (N) = N_Opr
6539 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
6541 Check_Restriction (No_Direct_Boolean_Operators, N);
6543 end Resolve_Logical_Op;
6545 ---------------------------
6546 -- Resolve_Membership_Op --
6547 ---------------------------
6549 -- The context can only be a boolean type, and does not determine
6550 -- the arguments. Arguments should be unambiguous, but the preference
6551 -- rule for universal types applies.
6553 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
6554 pragma Warnings (Off, Typ);
6556 L : constant Node_Id := Left_Opnd (N);
6557 R : constant Node_Id := Right_Opnd (N);
6561 if L = Error or else R = Error then
6565 if not Is_Overloaded (R)
6567 (Etype (R) = Universal_Integer or else
6568 Etype (R) = Universal_Real)
6569 and then Is_Overloaded (L)
6573 -- Ada 2005 (AI-251): Give support to the following case:
6575 -- type I is interface;
6576 -- type T is tagged ...
6578 -- function Test (O : I'Class) is
6580 -- return O in T'Class.
6583 -- In this case we have nothing else to do; the membership test will be
6584 -- done at run-time.
6586 elsif Ada_Version >= Ada_05
6587 and then Is_Class_Wide_Type (Etype (L))
6588 and then Is_Interface (Etype (L))
6589 and then Is_Class_Wide_Type (Etype (R))
6590 and then not Is_Interface (Etype (R))
6595 T := Intersect_Types (L, R);
6599 Check_Unset_Reference (L);
6601 if Nkind (R) = N_Range
6602 and then not Is_Scalar_Type (T)
6604 Error_Msg_N ("scalar type required for range", R);
6607 if Is_Entity_Name (R) then
6608 Freeze_Expression (R);
6611 Check_Unset_Reference (R);
6614 Eval_Membership_Op (N);
6615 end Resolve_Membership_Op;
6621 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
6623 -- Handle restriction against anonymous null access values This
6624 -- restriction can be turned off using -gnatdj.
6626 -- Ada 2005 (AI-231): Remove restriction
6628 if Ada_Version < Ada_05
6629 and then not Debug_Flag_J
6630 and then Ekind (Typ) = E_Anonymous_Access_Type
6631 and then Comes_From_Source (N)
6633 -- In the common case of a call which uses an explicitly null
6634 -- value for an access parameter, give specialized error message.
6636 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
6640 ("null is not allowed as argument for an access parameter", N);
6642 -- Standard message for all other cases (are there any?)
6646 ("null cannot be of an anonymous access type", N);
6650 -- In a distributed context, null for a remote access to subprogram
6651 -- may need to be replaced with a special record aggregate. In this
6652 -- case, return after having done the transformation.
6654 if (Ekind (Typ) = E_Record_Type
6655 or else Is_Remote_Access_To_Subprogram_Type (Typ))
6656 and then Remote_AST_Null_Value (N, Typ)
6661 -- The null literal takes its type from the context
6666 -----------------------
6667 -- Resolve_Op_Concat --
6668 -----------------------
6670 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
6672 -- We wish to avoid deep recursion, because concatenations are often
6673 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
6674 -- operands nonrecursively until we find something that is not a simple
6675 -- concatenation (A in this case). We resolve that, and then walk back
6676 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
6677 -- to do the rest of the work at each level. The Parent pointers allow
6678 -- us to avoid recursion, and thus avoid running out of memory. See also
6679 -- Sem_Ch4.Analyze_Concatenation, where a similar hack is used.
6685 -- The following code is equivalent to:
6687 -- Resolve_Op_Concat_First (NN, Typ);
6688 -- Resolve_Op_Concat_Arg (N, ...);
6689 -- Resolve_Op_Concat_Rest (N, Typ);
6691 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
6692 -- operand is a concatenation.
6694 -- Walk down left operands
6697 Resolve_Op_Concat_First (NN, Typ);
6698 Op1 := Left_Opnd (NN);
6699 exit when not (Nkind (Op1) = N_Op_Concat
6700 and then not Is_Array_Type (Component_Type (Typ))
6701 and then Entity (Op1) = Entity (NN));
6705 -- Now (given the above example) NN is A&B and Op1 is A
6707 -- First resolve Op1 ...
6709 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
6711 -- ... then walk NN back up until we reach N (where we started), calling
6712 -- Resolve_Op_Concat_Rest along the way.
6715 Resolve_Op_Concat_Rest (NN, Typ);
6719 end Resolve_Op_Concat;
6721 ---------------------------
6722 -- Resolve_Op_Concat_Arg --
6723 ---------------------------
6725 procedure Resolve_Op_Concat_Arg
6731 Btyp : constant Entity_Id := Base_Type (Typ);
6736 or else (not Is_Overloaded (Arg)
6737 and then Etype (Arg) /= Any_Composite
6738 and then Covers (Component_Type (Typ), Etype (Arg)))
6740 Resolve (Arg, Component_Type (Typ));
6742 Resolve (Arg, Btyp);
6745 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
6746 if Nkind (Arg) = N_Aggregate
6747 and then Is_Composite_Type (Component_Type (Typ))
6749 if Is_Private_Type (Component_Type (Typ)) then
6750 Resolve (Arg, Btyp);
6752 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
6753 Set_Etype (Arg, Any_Type);
6757 if Is_Overloaded (Arg)
6758 and then Has_Compatible_Type (Arg, Typ)
6759 and then Etype (Arg) /= Any_Type
6767 Get_First_Interp (Arg, I, It);
6769 Get_Next_Interp (I, It);
6771 -- Special-case the error message when the overloading is
6772 -- caused by a function that yields an array and can be
6773 -- called without parameters.
6775 if It.Nam = Func then
6776 Error_Msg_Sloc := Sloc (Func);
6777 Error_Msg_N ("ambiguous call to function#", Arg);
6779 ("\\interpretation as call yields&", Arg, Typ);
6781 ("\\interpretation as indexing of call yields&",
6782 Arg, Component_Type (Typ));
6786 ("ambiguous operand for concatenation!", Arg);
6787 Get_First_Interp (Arg, I, It);
6788 while Present (It.Nam) loop
6789 Error_Msg_Sloc := Sloc (It.Nam);
6791 if Base_Type (It.Typ) = Base_Type (Typ)
6792 or else Base_Type (It.Typ) =
6793 Base_Type (Component_Type (Typ))
6795 Error_Msg_N ("\\possible interpretation#", Arg);
6798 Get_Next_Interp (I, It);
6804 Resolve (Arg, Component_Type (Typ));
6806 if Nkind (Arg) = N_String_Literal then
6807 Set_Etype (Arg, Component_Type (Typ));
6810 if Arg = Left_Opnd (N) then
6811 Set_Is_Component_Left_Opnd (N);
6813 Set_Is_Component_Right_Opnd (N);
6818 Resolve (Arg, Btyp);
6821 Check_Unset_Reference (Arg);
6822 end Resolve_Op_Concat_Arg;
6824 -----------------------------
6825 -- Resolve_Op_Concat_First --
6826 -----------------------------
6828 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
6829 Btyp : constant Entity_Id := Base_Type (Typ);
6830 Op1 : constant Node_Id := Left_Opnd (N);
6831 Op2 : constant Node_Id := Right_Opnd (N);
6834 -- The parser folds an enormous sequence of concatenations of string
6835 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
6836 -- in the right. If the expression resolves to a predefined "&"
6837 -- operator, all is well. Otherwise, the parser's folding is wrong, so
6838 -- we give an error. See P_Simple_Expression in Par.Ch4.
6840 if Nkind (Op2) = N_String_Literal
6841 and then Is_Folded_In_Parser (Op2)
6842 and then Ekind (Entity (N)) = E_Function
6844 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
6845 and then String_Length (Strval (Op1)) = 0);
6846 Error_Msg_N ("too many user-defined concatenations", N);
6850 Set_Etype (N, Btyp);
6852 if Is_Limited_Composite (Btyp) then
6853 Error_Msg_N ("concatenation not available for limited array", N);
6854 Explain_Limited_Type (Btyp, N);
6856 end Resolve_Op_Concat_First;
6858 ----------------------------
6859 -- Resolve_Op_Concat_Rest --
6860 ----------------------------
6862 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
6863 Op1 : constant Node_Id := Left_Opnd (N);
6864 Op2 : constant Node_Id := Right_Opnd (N);
6867 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
6869 Generate_Operator_Reference (N, Typ);
6871 if Is_String_Type (Typ) then
6872 Eval_Concatenation (N);
6875 -- If this is not a static concatenation, but the result is a
6876 -- string type (and not an array of strings) ensure that static
6877 -- string operands have their subtypes properly constructed.
6879 if Nkind (N) /= N_String_Literal
6880 and then Is_Character_Type (Component_Type (Typ))
6882 Set_String_Literal_Subtype (Op1, Typ);
6883 Set_String_Literal_Subtype (Op2, Typ);
6885 end Resolve_Op_Concat_Rest;
6887 ----------------------
6888 -- Resolve_Op_Expon --
6889 ----------------------
6891 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
6892 B_Typ : constant Entity_Id := Base_Type (Typ);
6895 -- Catch attempts to do fixed-point exponentiation with universal
6896 -- operands, which is a case where the illegality is not caught during
6897 -- normal operator analysis.
6899 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
6900 Error_Msg_N ("exponentiation not available for fixed point", N);
6904 if Comes_From_Source (N)
6905 and then Ekind (Entity (N)) = E_Function
6906 and then Is_Imported (Entity (N))
6907 and then Is_Intrinsic_Subprogram (Entity (N))
6909 Resolve_Intrinsic_Operator (N, Typ);
6913 if Etype (Left_Opnd (N)) = Universal_Integer
6914 or else Etype (Left_Opnd (N)) = Universal_Real
6916 Check_For_Visible_Operator (N, B_Typ);
6919 -- We do the resolution using the base type, because intermediate values
6920 -- in expressions always are of the base type, not a subtype of it.
6922 Resolve (Left_Opnd (N), B_Typ);
6923 Resolve (Right_Opnd (N), Standard_Integer);
6925 Check_Unset_Reference (Left_Opnd (N));
6926 Check_Unset_Reference (Right_Opnd (N));
6928 Set_Etype (N, B_Typ);
6929 Generate_Operator_Reference (N, B_Typ);
6932 -- Set overflow checking bit. Much cleverer code needed here eventually
6933 -- and perhaps the Resolve routines should be separated for the various
6934 -- arithmetic operations, since they will need different processing. ???
6936 if Nkind (N) in N_Op then
6937 if not Overflow_Checks_Suppressed (Etype (N)) then
6938 Enable_Overflow_Check (N);
6941 end Resolve_Op_Expon;
6943 --------------------
6944 -- Resolve_Op_Not --
6945 --------------------
6947 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
6950 function Parent_Is_Boolean return Boolean;
6951 -- This function determines if the parent node is a boolean operator
6952 -- or operation (comparison op, membership test, or short circuit form)
6953 -- and the not in question is the left operand of this operation.
6954 -- Note that if the not is in parens, then false is returned.
6956 -----------------------
6957 -- Parent_Is_Boolean --
6958 -----------------------
6960 function Parent_Is_Boolean return Boolean is
6962 if Paren_Count (N) /= 0 then
6966 case Nkind (Parent (N)) is
6981 return Left_Opnd (Parent (N)) = N;
6987 end Parent_Is_Boolean;
6989 -- Start of processing for Resolve_Op_Not
6992 -- Predefined operations on scalar types yield the base type. On the
6993 -- other hand, logical operations on arrays yield the type of the
6994 -- arguments (and the context).
6996 if Is_Array_Type (Typ) then
6999 B_Typ := Base_Type (Typ);
7002 -- Straightforward case of incorrect arguments
7004 if not Valid_Boolean_Arg (Typ) then
7005 Error_Msg_N ("invalid operand type for operator&", N);
7006 Set_Etype (N, Any_Type);
7009 -- Special case of probable missing parens
7011 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7012 if Parent_Is_Boolean then
7014 ("operand of not must be enclosed in parentheses",
7018 ("no modular type available in this context", N);
7021 Set_Etype (N, Any_Type);
7024 -- OK resolution of not
7027 -- Warn if non-boolean types involved. This is a case like not a < b
7028 -- where a and b are modular, where we will get (not a) < b and most
7029 -- likely not (a < b) was intended.
7031 if Warn_On_Questionable_Missing_Parens
7032 and then not Is_Boolean_Type (Typ)
7033 and then Parent_Is_Boolean
7035 Error_Msg_N ("?not expression should be parenthesized here!", N);
7038 -- Warn on double negation if checking redundant constructs
7040 if Warn_On_Redundant_Constructs
7041 and then Comes_From_Source (N)
7042 and then Comes_From_Source (Right_Opnd (N))
7043 and then Root_Type (Typ) = Standard_Boolean
7044 and then Nkind (Right_Opnd (N)) = N_Op_Not
7046 Error_Msg_N ("redundant double negation?", N);
7049 -- Complete resolution and evaluation of NOT
7051 Resolve (Right_Opnd (N), B_Typ);
7052 Check_Unset_Reference (Right_Opnd (N));
7053 Set_Etype (N, B_Typ);
7054 Generate_Operator_Reference (N, B_Typ);
7059 -----------------------------
7060 -- Resolve_Operator_Symbol --
7061 -----------------------------
7063 -- Nothing to be done, all resolved already
7065 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
7066 pragma Warnings (Off, N);
7067 pragma Warnings (Off, Typ);
7071 end Resolve_Operator_Symbol;
7073 ----------------------------------
7074 -- Resolve_Qualified_Expression --
7075 ----------------------------------
7077 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
7078 pragma Warnings (Off, Typ);
7080 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
7081 Expr : constant Node_Id := Expression (N);
7084 Resolve (Expr, Target_Typ);
7086 -- A qualified expression requires an exact match of the type,
7087 -- class-wide matching is not allowed. However, if the qualifying
7088 -- type is specific and the expression has a class-wide type, it
7089 -- may still be okay, since it can be the result of the expansion
7090 -- of a call to a dispatching function, so we also have to check
7091 -- class-wideness of the type of the expression's original node.
7093 if (Is_Class_Wide_Type (Target_Typ)
7095 (Is_Class_Wide_Type (Etype (Expr))
7096 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
7097 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
7099 Wrong_Type (Expr, Target_Typ);
7102 -- If the target type is unconstrained, then we reset the type of
7103 -- the result from the type of the expression. For other cases, the
7104 -- actual subtype of the expression is the target type.
7106 if Is_Composite_Type (Target_Typ)
7107 and then not Is_Constrained (Target_Typ)
7109 Set_Etype (N, Etype (Expr));
7112 Eval_Qualified_Expression (N);
7113 end Resolve_Qualified_Expression;
7119 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
7120 L : constant Node_Id := Low_Bound (N);
7121 H : constant Node_Id := High_Bound (N);
7128 Check_Unset_Reference (L);
7129 Check_Unset_Reference (H);
7131 -- We have to check the bounds for being within the base range as
7132 -- required for a non-static context. Normally this is automatic and
7133 -- done as part of evaluating expressions, but the N_Range node is an
7134 -- exception, since in GNAT we consider this node to be a subexpression,
7135 -- even though in Ada it is not. The circuit in Sem_Eval could check for
7136 -- this, but that would put the test on the main evaluation path for
7139 Check_Non_Static_Context (L);
7140 Check_Non_Static_Context (H);
7142 -- Check for an ambiguous range over character literals. This will
7143 -- happen with a membership test involving only literals.
7145 if Typ = Any_Character then
7146 Ambiguous_Character (L);
7147 Set_Etype (N, Any_Type);
7151 -- If bounds are static, constant-fold them, so size computations
7152 -- are identical between front-end and back-end. Do not perform this
7153 -- transformation while analyzing generic units, as type information
7154 -- would then be lost when reanalyzing the constant node in the
7157 if Is_Discrete_Type (Typ) and then Expander_Active then
7158 if Is_OK_Static_Expression (L) then
7159 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
7162 if Is_OK_Static_Expression (H) then
7163 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
7168 --------------------------
7169 -- Resolve_Real_Literal --
7170 --------------------------
7172 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
7173 Actual_Typ : constant Entity_Id := Etype (N);
7176 -- Special processing for fixed-point literals to make sure that the
7177 -- value is an exact multiple of small where this is required. We
7178 -- skip this for the universal real case, and also for generic types.
7180 if Is_Fixed_Point_Type (Typ)
7181 and then Typ /= Universal_Fixed
7182 and then Typ /= Any_Fixed
7183 and then not Is_Generic_Type (Typ)
7186 Val : constant Ureal := Realval (N);
7187 Cintr : constant Ureal := Val / Small_Value (Typ);
7188 Cint : constant Uint := UR_Trunc (Cintr);
7189 Den : constant Uint := Norm_Den (Cintr);
7193 -- Case of literal is not an exact multiple of the Small
7197 -- For a source program literal for a decimal fixed-point
7198 -- type, this is statically illegal (RM 4.9(36)).
7200 if Is_Decimal_Fixed_Point_Type (Typ)
7201 and then Actual_Typ = Universal_Real
7202 and then Comes_From_Source (N)
7204 Error_Msg_N ("value has extraneous low order digits", N);
7207 -- Generate a warning if literal from source
7209 if Is_Static_Expression (N)
7210 and then Warn_On_Bad_Fixed_Value
7213 ("?static fixed-point value is not a multiple of Small!",
7217 -- Replace literal by a value that is the exact representation
7218 -- of a value of the type, i.e. a multiple of the small value,
7219 -- by truncation, since Machine_Rounds is false for all GNAT
7220 -- fixed-point types (RM 4.9(38)).
7222 Stat := Is_Static_Expression (N);
7224 Make_Real_Literal (Sloc (N),
7225 Realval => Small_Value (Typ) * Cint));
7227 Set_Is_Static_Expression (N, Stat);
7230 -- In all cases, set the corresponding integer field
7232 Set_Corresponding_Integer_Value (N, Cint);
7236 -- Now replace the actual type by the expected type as usual
7239 Eval_Real_Literal (N);
7240 end Resolve_Real_Literal;
7242 -----------------------
7243 -- Resolve_Reference --
7244 -----------------------
7246 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
7247 P : constant Node_Id := Prefix (N);
7250 -- Replace general access with specific type
7252 if Ekind (Etype (N)) = E_Allocator_Type then
7253 Set_Etype (N, Base_Type (Typ));
7256 Resolve (P, Designated_Type (Etype (N)));
7258 -- If we are taking the reference of a volatile entity, then treat
7259 -- it as a potential modification of this entity. This is much too
7260 -- conservative, but is necessary because remove side effects can
7261 -- result in transformations of normal assignments into reference
7262 -- sequences that otherwise fail to notice the modification.
7264 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
7265 Note_Possible_Modification (P, Sure => False);
7267 end Resolve_Reference;
7269 --------------------------------
7270 -- Resolve_Selected_Component --
7271 --------------------------------
7273 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
7275 Comp1 : Entity_Id := Empty; -- prevent junk warning
7276 P : constant Node_Id := Prefix (N);
7277 S : constant Node_Id := Selector_Name (N);
7278 T : Entity_Id := Etype (P);
7280 I1 : Interp_Index := 0; -- prevent junk warning
7285 function Init_Component return Boolean;
7286 -- Check whether this is the initialization of a component within an
7287 -- init proc (by assignment or call to another init proc). If true,
7288 -- there is no need for a discriminant check.
7290 --------------------
7291 -- Init_Component --
7292 --------------------
7294 function Init_Component return Boolean is
7296 return Inside_Init_Proc
7297 and then Nkind (Prefix (N)) = N_Identifier
7298 and then Chars (Prefix (N)) = Name_uInit
7299 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
7302 -- Start of processing for Resolve_Selected_Component
7305 if Is_Overloaded (P) then
7307 -- Use the context type to select the prefix that has a selector
7308 -- of the correct name and type.
7311 Get_First_Interp (P, I, It);
7313 Search : while Present (It.Typ) loop
7314 if Is_Access_Type (It.Typ) then
7315 T := Designated_Type (It.Typ);
7320 if Is_Record_Type (T) then
7322 -- The visible components of a class-wide type are those of
7325 if Is_Class_Wide_Type (T) then
7329 Comp := First_Entity (T);
7330 while Present (Comp) loop
7331 if Chars (Comp) = Chars (S)
7332 and then Covers (Etype (Comp), Typ)
7341 It := Disambiguate (P, I1, I, Any_Type);
7343 if It = No_Interp then
7345 ("ambiguous prefix for selected component", N);
7352 -- There may be an implicit dereference. Retrieve
7353 -- designated record type.
7355 if Is_Access_Type (It1.Typ) then
7356 T := Designated_Type (It1.Typ);
7361 if Scope (Comp1) /= T then
7363 -- Resolution chooses the new interpretation.
7364 -- Find the component with the right name.
7366 Comp1 := First_Entity (T);
7367 while Present (Comp1)
7368 and then Chars (Comp1) /= Chars (S)
7370 Comp1 := Next_Entity (Comp1);
7379 Comp := Next_Entity (Comp);
7384 Get_Next_Interp (I, It);
7387 Resolve (P, It1.Typ);
7389 Set_Entity_With_Style_Check (S, Comp1);
7392 -- Resolve prefix with its type
7397 -- Generate cross-reference. We needed to wait until full overloading
7398 -- resolution was complete to do this, since otherwise we can't tell if
7399 -- we are an Lvalue of not.
7401 if May_Be_Lvalue (N) then
7402 Generate_Reference (Entity (S), S, 'm');
7404 Generate_Reference (Entity (S), S, 'r');
7407 -- If prefix is an access type, the node will be transformed into an
7408 -- explicit dereference during expansion. The type of the node is the
7409 -- designated type of that of the prefix.
7411 if Is_Access_Type (Etype (P)) then
7412 T := Designated_Type (Etype (P));
7413 Check_Fully_Declared_Prefix (T, P);
7418 if Has_Discriminants (T)
7419 and then (Ekind (Entity (S)) = E_Component
7421 Ekind (Entity (S)) = E_Discriminant)
7422 and then Present (Original_Record_Component (Entity (S)))
7423 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
7424 and then Present (Discriminant_Checking_Func
7425 (Original_Record_Component (Entity (S))))
7426 and then not Discriminant_Checks_Suppressed (T)
7427 and then not Init_Component
7429 Set_Do_Discriminant_Check (N);
7432 if Ekind (Entity (S)) = E_Void then
7433 Error_Msg_N ("premature use of component", S);
7436 -- If the prefix is a record conversion, this may be a renamed
7437 -- discriminant whose bounds differ from those of the original
7438 -- one, so we must ensure that a range check is performed.
7440 if Nkind (P) = N_Type_Conversion
7441 and then Ekind (Entity (S)) = E_Discriminant
7442 and then Is_Discrete_Type (Typ)
7444 Set_Etype (N, Base_Type (Typ));
7447 -- Note: No Eval processing is required, because the prefix is of a
7448 -- record type, or protected type, and neither can possibly be static.
7450 end Resolve_Selected_Component;
7456 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
7457 B_Typ : constant Entity_Id := Base_Type (Typ);
7458 L : constant Node_Id := Left_Opnd (N);
7459 R : constant Node_Id := Right_Opnd (N);
7462 -- We do the resolution using the base type, because intermediate values
7463 -- in expressions always are of the base type, not a subtype of it.
7466 Resolve (R, Standard_Natural);
7468 Check_Unset_Reference (L);
7469 Check_Unset_Reference (R);
7471 Set_Etype (N, B_Typ);
7472 Generate_Operator_Reference (N, B_Typ);
7476 ---------------------------
7477 -- Resolve_Short_Circuit --
7478 ---------------------------
7480 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
7481 B_Typ : constant Entity_Id := Base_Type (Typ);
7482 L : constant Node_Id := Left_Opnd (N);
7483 R : constant Node_Id := Right_Opnd (N);
7489 -- Check for issuing warning for always False assert/check, this happens
7490 -- when assertions are turned off, in which case the pragma Assert/Check
7491 -- was transformed into:
7493 -- if False and then <condition> then ...
7495 -- and we detect this pattern
7497 if Warn_On_Assertion_Failure
7498 and then Is_Entity_Name (R)
7499 and then Entity (R) = Standard_False
7500 and then Nkind (Parent (N)) = N_If_Statement
7501 and then Nkind (N) = N_And_Then
7502 and then Is_Entity_Name (L)
7503 and then Entity (L) = Standard_False
7506 Orig : constant Node_Id := Original_Node (Parent (N));
7509 if Nkind (Orig) = N_Pragma
7510 and then Pragma_Name (Orig) = Name_Assert
7512 -- Don't want to warn if original condition is explicit False
7515 Expr : constant Node_Id :=
7518 (First (Pragma_Argument_Associations (Orig))));
7520 if Is_Entity_Name (Expr)
7521 and then Entity (Expr) = Standard_False
7525 -- Issue warning. Note that we don't want to make this
7526 -- an unconditional warning, because if the assert is
7527 -- within deleted code we do not want the warning. But
7528 -- we do not want the deletion of the IF/AND-THEN to
7529 -- take this message with it. We achieve this by making
7530 -- sure that the expanded code points to the Sloc of
7531 -- the expression, not the original pragma.
7533 Error_Msg_N ("?assertion would fail at run-time", Orig);
7537 -- Similar processing for Check pragma
7539 elsif Nkind (Orig) = N_Pragma
7540 and then Pragma_Name (Orig) = Name_Check
7542 -- Don't want to warn if original condition is explicit False
7545 Expr : constant Node_Id :=
7549 (Pragma_Argument_Associations (Orig)))));
7551 if Is_Entity_Name (Expr)
7552 and then Entity (Expr) = Standard_False
7556 Error_Msg_N ("?check would fail at run-time", Orig);
7563 -- Continue with processing of short circuit
7565 Check_Unset_Reference (L);
7566 Check_Unset_Reference (R);
7568 Set_Etype (N, B_Typ);
7569 Eval_Short_Circuit (N);
7570 end Resolve_Short_Circuit;
7576 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
7577 Name : constant Node_Id := Prefix (N);
7578 Drange : constant Node_Id := Discrete_Range (N);
7579 Array_Type : Entity_Id := Empty;
7583 if Is_Overloaded (Name) then
7585 -- Use the context type to select the prefix that yields the
7586 -- correct array type.
7590 I1 : Interp_Index := 0;
7592 P : constant Node_Id := Prefix (N);
7593 Found : Boolean := False;
7596 Get_First_Interp (P, I, It);
7597 while Present (It.Typ) loop
7598 if (Is_Array_Type (It.Typ)
7599 and then Covers (Typ, It.Typ))
7600 or else (Is_Access_Type (It.Typ)
7601 and then Is_Array_Type (Designated_Type (It.Typ))
7602 and then Covers (Typ, Designated_Type (It.Typ)))
7605 It := Disambiguate (P, I1, I, Any_Type);
7607 if It = No_Interp then
7608 Error_Msg_N ("ambiguous prefix for slicing", N);
7613 Array_Type := It.Typ;
7618 Array_Type := It.Typ;
7623 Get_Next_Interp (I, It);
7628 Array_Type := Etype (Name);
7631 Resolve (Name, Array_Type);
7633 if Is_Access_Type (Array_Type) then
7634 Apply_Access_Check (N);
7635 Array_Type := Designated_Type (Array_Type);
7637 -- If the prefix is an access to an unconstrained array, we must use
7638 -- the actual subtype of the object to perform the index checks. The
7639 -- object denoted by the prefix is implicit in the node, so we build
7640 -- an explicit representation for it in order to compute the actual
7643 if not Is_Constrained (Array_Type) then
7644 Remove_Side_Effects (Prefix (N));
7647 Obj : constant Node_Id :=
7648 Make_Explicit_Dereference (Sloc (N),
7649 Prefix => New_Copy_Tree (Prefix (N)));
7651 Set_Etype (Obj, Array_Type);
7652 Set_Parent (Obj, Parent (N));
7653 Array_Type := Get_Actual_Subtype (Obj);
7657 elsif Is_Entity_Name (Name)
7658 or else (Nkind (Name) = N_Function_Call
7659 and then not Is_Constrained (Etype (Name)))
7661 Array_Type := Get_Actual_Subtype (Name);
7663 -- If the name is a selected component that depends on discriminants,
7664 -- build an actual subtype for it. This can happen only when the name
7665 -- itself is overloaded; otherwise the actual subtype is created when
7666 -- the selected component is analyzed.
7668 elsif Nkind (Name) = N_Selected_Component
7669 and then Full_Analysis
7670 and then Depends_On_Discriminant (First_Index (Array_Type))
7673 Act_Decl : constant Node_Id :=
7674 Build_Actual_Subtype_Of_Component (Array_Type, Name);
7676 Insert_Action (N, Act_Decl);
7677 Array_Type := Defining_Identifier (Act_Decl);
7681 -- If name was overloaded, set slice type correctly now
7683 Set_Etype (N, Array_Type);
7685 -- If the range is specified by a subtype mark, no resolution is
7686 -- necessary. Else resolve the bounds, and apply needed checks.
7688 if not Is_Entity_Name (Drange) then
7689 Index := First_Index (Array_Type);
7690 Resolve (Drange, Base_Type (Etype (Index)));
7692 if Nkind (Drange) = N_Range
7694 -- Do not apply the range check to nodes associated with the
7695 -- frontend expansion of the dispatch table. We first check
7696 -- if Ada.Tags is already loaded to void the addition of an
7697 -- undesired dependence on such run-time unit.
7702 (RTU_Loaded (Ada_Tags)
7703 and then Nkind (Prefix (N)) = N_Selected_Component
7704 and then Present (Entity (Selector_Name (Prefix (N))))
7705 and then Entity (Selector_Name (Prefix (N))) =
7706 RTE_Record_Component (RE_Prims_Ptr)))
7708 Apply_Range_Check (Drange, Etype (Index));
7712 Set_Slice_Subtype (N);
7714 if Nkind (Drange) = N_Range then
7715 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
7716 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
7722 ----------------------------
7723 -- Resolve_String_Literal --
7724 ----------------------------
7726 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
7727 C_Typ : constant Entity_Id := Component_Type (Typ);
7728 R_Typ : constant Entity_Id := Root_Type (C_Typ);
7729 Loc : constant Source_Ptr := Sloc (N);
7730 Str : constant String_Id := Strval (N);
7731 Strlen : constant Nat := String_Length (Str);
7732 Subtype_Id : Entity_Id;
7733 Need_Check : Boolean;
7736 -- For a string appearing in a concatenation, defer creation of the
7737 -- string_literal_subtype until the end of the resolution of the
7738 -- concatenation, because the literal may be constant-folded away. This
7739 -- is a useful optimization for long concatenation expressions.
7741 -- If the string is an aggregate built for a single character (which
7742 -- happens in a non-static context) or a is null string to which special
7743 -- checks may apply, we build the subtype. Wide strings must also get a
7744 -- string subtype if they come from a one character aggregate. Strings
7745 -- generated by attributes might be static, but it is often hard to
7746 -- determine whether the enclosing context is static, so we generate
7747 -- subtypes for them as well, thus losing some rarer optimizations ???
7748 -- Same for strings that come from a static conversion.
7751 (Strlen = 0 and then Typ /= Standard_String)
7752 or else Nkind (Parent (N)) /= N_Op_Concat
7753 or else (N /= Left_Opnd (Parent (N))
7754 and then N /= Right_Opnd (Parent (N)))
7755 or else ((Typ = Standard_Wide_String
7756 or else Typ = Standard_Wide_Wide_String)
7757 and then Nkind (Original_Node (N)) /= N_String_Literal);
7759 -- If the resolving type is itself a string literal subtype, we
7760 -- can just reuse it, since there is no point in creating another.
7762 if Ekind (Typ) = E_String_Literal_Subtype then
7765 elsif Nkind (Parent (N)) = N_Op_Concat
7766 and then not Need_Check
7767 and then not Nkind_In (Original_Node (N), N_Character_Literal,
7768 N_Attribute_Reference,
7769 N_Qualified_Expression,
7774 -- Otherwise we must create a string literal subtype. Note that the
7775 -- whole idea of string literal subtypes is simply to avoid the need
7776 -- for building a full fledged array subtype for each literal.
7779 Set_String_Literal_Subtype (N, Typ);
7780 Subtype_Id := Etype (N);
7783 if Nkind (Parent (N)) /= N_Op_Concat
7786 Set_Etype (N, Subtype_Id);
7787 Eval_String_Literal (N);
7790 if Is_Limited_Composite (Typ)
7791 or else Is_Private_Composite (Typ)
7793 Error_Msg_N ("string literal not available for private array", N);
7794 Set_Etype (N, Any_Type);
7798 -- The validity of a null string has been checked in the
7799 -- call to Eval_String_Literal.
7804 -- Always accept string literal with component type Any_Character, which
7805 -- occurs in error situations and in comparisons of literals, both of
7806 -- which should accept all literals.
7808 elsif R_Typ = Any_Character then
7811 -- If the type is bit-packed, then we always transform the string
7812 -- literal into a full fledged aggregate.
7814 elsif Is_Bit_Packed_Array (Typ) then
7817 -- Deal with cases of Wide_Wide_String, Wide_String, and String
7820 -- For Standard.Wide_Wide_String, or any other type whose component
7821 -- type is Standard.Wide_Wide_Character, we know that all the
7822 -- characters in the string must be acceptable, since the parser
7823 -- accepted the characters as valid character literals.
7825 if R_Typ = Standard_Wide_Wide_Character then
7828 -- For the case of Standard.String, or any other type whose component
7829 -- type is Standard.Character, we must make sure that there are no
7830 -- wide characters in the string, i.e. that it is entirely composed
7831 -- of characters in range of type Character.
7833 -- If the string literal is the result of a static concatenation, the
7834 -- test has already been performed on the components, and need not be
7837 elsif R_Typ = Standard_Character
7838 and then Nkind (Original_Node (N)) /= N_Op_Concat
7840 for J in 1 .. Strlen loop
7841 if not In_Character_Range (Get_String_Char (Str, J)) then
7843 -- If we are out of range, post error. This is one of the
7844 -- very few places that we place the flag in the middle of
7845 -- a token, right under the offending wide character.
7848 ("literal out of range of type Standard.Character",
7849 Source_Ptr (Int (Loc) + J));
7854 -- For the case of Standard.Wide_String, or any other type whose
7855 -- component type is Standard.Wide_Character, we must make sure that
7856 -- there are no wide characters in the string, i.e. that it is
7857 -- entirely composed of characters in range of type Wide_Character.
7859 -- If the string literal is the result of a static concatenation,
7860 -- the test has already been performed on the components, and need
7863 elsif R_Typ = Standard_Wide_Character
7864 and then Nkind (Original_Node (N)) /= N_Op_Concat
7866 for J in 1 .. Strlen loop
7867 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
7869 -- If we are out of range, post error. This is one of the
7870 -- very few places that we place the flag in the middle of
7871 -- a token, right under the offending wide character.
7873 -- This is not quite right, because characters in general
7874 -- will take more than one character position ???
7877 ("literal out of range of type Standard.Wide_Character",
7878 Source_Ptr (Int (Loc) + J));
7883 -- If the root type is not a standard character, then we will convert
7884 -- the string into an aggregate and will let the aggregate code do
7885 -- the checking. Standard Wide_Wide_Character is also OK here.
7891 -- See if the component type of the array corresponding to the string
7892 -- has compile time known bounds. If yes we can directly check
7893 -- whether the evaluation of the string will raise constraint error.
7894 -- Otherwise we need to transform the string literal into the
7895 -- corresponding character aggregate and let the aggregate
7896 -- code do the checking.
7898 if Is_Standard_Character_Type (R_Typ) then
7900 -- Check for the case of full range, where we are definitely OK
7902 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
7906 -- Here the range is not the complete base type range, so check
7909 Comp_Typ_Lo : constant Node_Id :=
7910 Type_Low_Bound (Component_Type (Typ));
7911 Comp_Typ_Hi : constant Node_Id :=
7912 Type_High_Bound (Component_Type (Typ));
7917 if Compile_Time_Known_Value (Comp_Typ_Lo)
7918 and then Compile_Time_Known_Value (Comp_Typ_Hi)
7920 for J in 1 .. Strlen loop
7921 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
7923 if Char_Val < Expr_Value (Comp_Typ_Lo)
7924 or else Char_Val > Expr_Value (Comp_Typ_Hi)
7926 Apply_Compile_Time_Constraint_Error
7927 (N, "character out of range?", CE_Range_Check_Failed,
7928 Loc => Source_Ptr (Int (Loc) + J));
7938 -- If we got here we meed to transform the string literal into the
7939 -- equivalent qualified positional array aggregate. This is rather
7940 -- heavy artillery for this situation, but it is hard work to avoid.
7943 Lits : constant List_Id := New_List;
7944 P : Source_Ptr := Loc + 1;
7948 -- Build the character literals, we give them source locations that
7949 -- correspond to the string positions, which is a bit tricky given
7950 -- the possible presence of wide character escape sequences.
7952 for J in 1 .. Strlen loop
7953 C := Get_String_Char (Str, J);
7954 Set_Character_Literal_Name (C);
7957 Make_Character_Literal (P,
7959 Char_Literal_Value => UI_From_CC (C)));
7961 if In_Character_Range (C) then
7964 -- Should we have a call to Skip_Wide here ???
7972 Make_Qualified_Expression (Loc,
7973 Subtype_Mark => New_Reference_To (Typ, Loc),
7975 Make_Aggregate (Loc, Expressions => Lits)));
7977 Analyze_And_Resolve (N, Typ);
7979 end Resolve_String_Literal;
7981 -----------------------------
7982 -- Resolve_Subprogram_Info --
7983 -----------------------------
7985 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
7988 end Resolve_Subprogram_Info;
7990 -----------------------------
7991 -- Resolve_Type_Conversion --
7992 -----------------------------
7994 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
7995 Conv_OK : constant Boolean := Conversion_OK (N);
7996 Operand : constant Node_Id := Expression (N);
7997 Operand_Typ : constant Entity_Id := Etype (Operand);
7998 Target_Typ : constant Entity_Id := Etype (N);
8005 and then not Valid_Conversion (N, Target_Typ, Operand)
8010 if Etype (Operand) = Any_Fixed then
8012 -- Mixed-mode operation involving a literal. Context must be a fixed
8013 -- type which is applied to the literal subsequently.
8015 if Is_Fixed_Point_Type (Typ) then
8016 Set_Etype (Operand, Universal_Real);
8018 elsif Is_Numeric_Type (Typ)
8019 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
8020 and then (Etype (Right_Opnd (Operand)) = Universal_Real
8022 Etype (Left_Opnd (Operand)) = Universal_Real)
8024 -- Return if expression is ambiguous
8026 if Unique_Fixed_Point_Type (N) = Any_Type then
8029 -- If nothing else, the available fixed type is Duration
8032 Set_Etype (Operand, Standard_Duration);
8035 -- Resolve the real operand with largest available precision
8037 if Etype (Right_Opnd (Operand)) = Universal_Real then
8038 Rop := New_Copy_Tree (Right_Opnd (Operand));
8040 Rop := New_Copy_Tree (Left_Opnd (Operand));
8043 Resolve (Rop, Universal_Real);
8045 -- If the operand is a literal (it could be a non-static and
8046 -- illegal exponentiation) check whether the use of Duration
8047 -- is potentially inaccurate.
8049 if Nkind (Rop) = N_Real_Literal
8050 and then Realval (Rop) /= Ureal_0
8051 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
8054 ("?universal real operand can only " &
8055 "be interpreted as Duration!",
8058 ("\?precision will be lost in the conversion!", Rop);
8061 elsif Is_Numeric_Type (Typ)
8062 and then Nkind (Operand) in N_Op
8063 and then Unique_Fixed_Point_Type (N) /= Any_Type
8065 Set_Etype (Operand, Standard_Duration);
8068 Error_Msg_N ("invalid context for mixed mode operation", N);
8069 Set_Etype (Operand, Any_Type);
8076 -- Note: we do the Eval_Type_Conversion call before applying the
8077 -- required checks for a subtype conversion. This is important,
8078 -- since both are prepared under certain circumstances to change
8079 -- the type conversion to a constraint error node, but in the case
8080 -- of Eval_Type_Conversion this may reflect an illegality in the
8081 -- static case, and we would miss the illegality (getting only a
8082 -- warning message), if we applied the type conversion checks first.
8084 Eval_Type_Conversion (N);
8086 -- Even when evaluation is not possible, we may be able to simplify
8087 -- the conversion or its expression. This needs to be done before
8088 -- applying checks, since otherwise the checks may use the original
8089 -- expression and defeat the simplifications. This is specifically
8090 -- the case for elimination of the floating-point Truncation
8091 -- attribute in float-to-int conversions.
8093 Simplify_Type_Conversion (N);
8095 -- If after evaluation we still have a type conversion, then we
8096 -- may need to apply checks required for a subtype conversion.
8098 -- Skip these type conversion checks if universal fixed operands
8099 -- operands involved, since range checks are handled separately for
8100 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
8102 if Nkind (N) = N_Type_Conversion
8103 and then not Is_Generic_Type (Root_Type (Target_Typ))
8104 and then Target_Typ /= Universal_Fixed
8105 and then Operand_Typ /= Universal_Fixed
8107 Apply_Type_Conversion_Checks (N);
8110 -- Issue warning for conversion of simple object to its own type
8111 -- We have to test the original nodes, since they may have been
8112 -- rewritten by various optimizations.
8114 Orig_N := Original_Node (N);
8116 if Warn_On_Redundant_Constructs
8117 and then Comes_From_Source (Orig_N)
8118 and then Nkind (Orig_N) = N_Type_Conversion
8119 and then not In_Instance
8121 Orig_N := Original_Node (Expression (Orig_N));
8122 Orig_T := Target_Typ;
8124 -- If the node is part of a larger expression, the Target_Type
8125 -- may not be the original type of the node if the context is a
8126 -- condition. Recover original type to see if conversion is needed.
8128 if Is_Boolean_Type (Orig_T)
8129 and then Nkind (Parent (N)) in N_Op
8131 Orig_T := Etype (Parent (N));
8134 if Is_Entity_Name (Orig_N)
8136 (Etype (Entity (Orig_N)) = Orig_T
8138 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
8139 and then Covers (Orig_T, Etype (Entity (Orig_N)))))
8141 Error_Msg_Node_2 := Orig_T;
8143 ("?redundant conversion, & is of type &!", N, Entity (Orig_N));
8147 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
8148 -- No need to perform any interface conversion if the type of the
8149 -- expression coincides with the target type.
8151 if Ada_Version >= Ada_05
8152 and then Expander_Active
8153 and then Operand_Typ /= Target_Typ
8156 Opnd : Entity_Id := Operand_Typ;
8157 Target : Entity_Id := Target_Typ;
8160 if Is_Access_Type (Opnd) then
8161 Opnd := Directly_Designated_Type (Opnd);
8164 if Is_Access_Type (Target_Typ) then
8165 Target := Directly_Designated_Type (Target);
8168 if Opnd = Target then
8171 -- Conversion from interface type
8173 elsif Is_Interface (Opnd) then
8175 -- Ada 2005 (AI-217): Handle entities from limited views
8177 if From_With_Type (Opnd) then
8178 Error_Msg_Qual_Level := 99;
8179 Error_Msg_NE ("missing with-clause on package &", N,
8180 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
8182 ("type conversions require visibility of the full view",
8185 elsif From_With_Type (Target)
8187 (Is_Access_Type (Target_Typ)
8188 and then Present (Non_Limited_View (Etype (Target))))
8190 Error_Msg_Qual_Level := 99;
8191 Error_Msg_NE ("missing with-clause on package &", N,
8192 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
8194 ("type conversions require visibility of the full view",
8198 Expand_Interface_Conversion (N, Is_Static => False);
8201 -- Conversion to interface type
8203 elsif Is_Interface (Target) then
8207 if Ekind (Opnd) = E_Protected_Subtype
8208 or else Ekind (Opnd) = E_Task_Subtype
8210 Opnd := Etype (Opnd);
8213 if not Interface_Present_In_Ancestor
8217 if Is_Class_Wide_Type (Opnd) then
8219 -- The static analysis is not enough to know if the
8220 -- interface is implemented or not. Hence we must pass
8221 -- the work to the expander to generate code to evaluate
8222 -- the conversion at run-time.
8224 Expand_Interface_Conversion (N, Is_Static => False);
8227 Error_Msg_Name_1 := Chars (Etype (Target));
8228 Error_Msg_Name_2 := Chars (Opnd);
8230 ("wrong interface conversion (% is not a progenitor " &
8235 Expand_Interface_Conversion (N);
8240 end Resolve_Type_Conversion;
8242 ----------------------
8243 -- Resolve_Unary_Op --
8244 ----------------------
8246 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
8247 B_Typ : constant Entity_Id := Base_Type (Typ);
8248 R : constant Node_Id := Right_Opnd (N);
8254 -- Deal with intrinsic unary operators
8256 if Comes_From_Source (N)
8257 and then Ekind (Entity (N)) = E_Function
8258 and then Is_Imported (Entity (N))
8259 and then Is_Intrinsic_Subprogram (Entity (N))
8261 Resolve_Intrinsic_Unary_Operator (N, Typ);
8265 -- Deal with universal cases
8267 if Etype (R) = Universal_Integer
8269 Etype (R) = Universal_Real
8271 Check_For_Visible_Operator (N, B_Typ);
8274 Set_Etype (N, B_Typ);
8277 -- Generate warning for expressions like abs (x mod 2)
8279 if Warn_On_Redundant_Constructs
8280 and then Nkind (N) = N_Op_Abs
8282 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
8284 if OK and then Hi >= Lo and then Lo >= 0 then
8286 ("?abs applied to known non-negative value has no effect", N);
8290 -- Deal with reference generation
8292 Check_Unset_Reference (R);
8293 Generate_Operator_Reference (N, B_Typ);
8296 -- Set overflow checking bit. Much cleverer code needed here eventually
8297 -- and perhaps the Resolve routines should be separated for the various
8298 -- arithmetic operations, since they will need different processing ???
8300 if Nkind (N) in N_Op then
8301 if not Overflow_Checks_Suppressed (Etype (N)) then
8302 Enable_Overflow_Check (N);
8306 -- Generate warning for expressions like -5 mod 3 for integers. No
8307 -- need to worry in the floating-point case, since parens do not affect
8308 -- the result so there is no point in giving in a warning.
8311 Norig : constant Node_Id := Original_Node (N);
8320 if Warn_On_Questionable_Missing_Parens
8321 and then Comes_From_Source (Norig)
8322 and then Is_Integer_Type (Typ)
8323 and then Nkind (Norig) = N_Op_Minus
8325 Rorig := Original_Node (Right_Opnd (Norig));
8327 -- We are looking for cases where the right operand is not
8328 -- parenthesized, and is a binary operator, multiply, divide, or
8329 -- mod. These are the cases where the grouping can affect results.
8331 if Paren_Count (Rorig) = 0
8332 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
8334 -- For mod, we always give the warning, since the value is
8335 -- affected by the parenthesization (e.g. (-5) mod 315 /=
8336 -- (5 mod 315)). But for the other cases, the only concern is
8337 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
8338 -- overflows, but (-2) * 64 does not). So we try to give the
8339 -- message only when overflow is possible.
8341 if Nkind (Rorig) /= N_Op_Mod
8342 and then Compile_Time_Known_Value (R)
8344 Val := Expr_Value (R);
8346 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
8347 HB := Expr_Value (Type_High_Bound (Typ));
8349 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
8352 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
8353 LB := Expr_Value (Type_Low_Bound (Typ));
8355 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
8358 -- Note that the test below is deliberately excluding
8359 -- the largest negative number, since that is a potentially
8360 -- troublesome case (e.g. -2 * x, where the result is the
8361 -- largest negative integer has an overflow with 2 * x).
8363 if Val > LB and then Val <= HB then
8368 -- For the multiplication case, the only case we have to worry
8369 -- about is when (-a)*b is exactly the largest negative number
8370 -- so that -(a*b) can cause overflow. This can only happen if
8371 -- a is a power of 2, and more generally if any operand is a
8372 -- constant that is not a power of 2, then the parentheses
8373 -- cannot affect whether overflow occurs. We only bother to
8374 -- test the left most operand
8376 -- Loop looking at left operands for one that has known value
8379 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
8380 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
8381 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
8383 -- Operand value of 0 or 1 skips warning
8388 -- Otherwise check power of 2, if power of 2, warn, if
8389 -- anything else, skip warning.
8392 while Lval /= 2 loop
8393 if Lval mod 2 = 1 then
8404 -- Keep looking at left operands
8406 Opnd := Left_Opnd (Opnd);
8409 -- For rem or "/" we can only have a problematic situation
8410 -- if the divisor has a value of minus one or one. Otherwise
8411 -- overflow is impossible (divisor > 1) or we have a case of
8412 -- division by zero in any case.
8414 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
8415 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
8416 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
8421 -- If we fall through warning should be issued
8424 ("?unary minus expression should be parenthesized here!", N);
8428 end Resolve_Unary_Op;
8430 ----------------------------------
8431 -- Resolve_Unchecked_Expression --
8432 ----------------------------------
8434 procedure Resolve_Unchecked_Expression
8439 Resolve (Expression (N), Typ, Suppress => All_Checks);
8441 end Resolve_Unchecked_Expression;
8443 ---------------------------------------
8444 -- Resolve_Unchecked_Type_Conversion --
8445 ---------------------------------------
8447 procedure Resolve_Unchecked_Type_Conversion
8451 pragma Warnings (Off, Typ);
8453 Operand : constant Node_Id := Expression (N);
8454 Opnd_Type : constant Entity_Id := Etype (Operand);
8457 -- Resolve operand using its own type
8459 Resolve (Operand, Opnd_Type);
8460 Eval_Unchecked_Conversion (N);
8462 end Resolve_Unchecked_Type_Conversion;
8464 ------------------------------
8465 -- Rewrite_Operator_As_Call --
8466 ------------------------------
8468 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
8469 Loc : constant Source_Ptr := Sloc (N);
8470 Actuals : constant List_Id := New_List;
8474 if Nkind (N) in N_Binary_Op then
8475 Append (Left_Opnd (N), Actuals);
8478 Append (Right_Opnd (N), Actuals);
8481 Make_Function_Call (Sloc => Loc,
8482 Name => New_Occurrence_Of (Nam, Loc),
8483 Parameter_Associations => Actuals);
8485 Preserve_Comes_From_Source (New_N, N);
8486 Preserve_Comes_From_Source (Name (New_N), N);
8488 Set_Etype (N, Etype (Nam));
8489 end Rewrite_Operator_As_Call;
8491 ------------------------------
8492 -- Rewrite_Renamed_Operator --
8493 ------------------------------
8495 procedure Rewrite_Renamed_Operator
8500 Nam : constant Name_Id := Chars (Op);
8501 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
8505 -- Rewrite the operator node using the real operator, not its
8506 -- renaming. Exclude user-defined intrinsic operations of the same
8507 -- name, which are treated separately and rewritten as calls.
8509 if Ekind (Op) /= E_Function
8510 or else Chars (N) /= Nam
8512 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
8513 Set_Chars (Op_Node, Nam);
8514 Set_Etype (Op_Node, Etype (N));
8515 Set_Entity (Op_Node, Op);
8516 Set_Right_Opnd (Op_Node, Right_Opnd (N));
8518 -- Indicate that both the original entity and its renaming are
8519 -- referenced at this point.
8521 Generate_Reference (Entity (N), N);
8522 Generate_Reference (Op, N);
8525 Set_Left_Opnd (Op_Node, Left_Opnd (N));
8528 Rewrite (N, Op_Node);
8530 -- If the context type is private, add the appropriate conversions
8531 -- so that the operator is applied to the full view. This is done
8532 -- in the routines that resolve intrinsic operators,
8534 if Is_Intrinsic_Subprogram (Op)
8535 and then Is_Private_Type (Typ)
8538 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
8539 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
8540 Resolve_Intrinsic_Operator (N, Typ);
8542 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
8543 Resolve_Intrinsic_Unary_Operator (N, Typ);
8550 elsif Ekind (Op) = E_Function
8551 and then Is_Intrinsic_Subprogram (Op)
8553 -- Operator renames a user-defined operator of the same name. Use
8554 -- the original operator in the node, which is the one that Gigi
8558 Set_Is_Overloaded (N, False);
8560 end Rewrite_Renamed_Operator;
8562 -----------------------
8563 -- Set_Slice_Subtype --
8564 -----------------------
8566 -- Build an implicit subtype declaration to represent the type delivered
8567 -- by the slice. This is an abbreviated version of an array subtype. We
8568 -- define an index subtype for the slice, using either the subtype name
8569 -- or the discrete range of the slice. To be consistent with index usage
8570 -- elsewhere, we create a list header to hold the single index. This list
8571 -- is not otherwise attached to the syntax tree.
8573 procedure Set_Slice_Subtype (N : Node_Id) is
8574 Loc : constant Source_Ptr := Sloc (N);
8575 Index_List : constant List_Id := New_List;
8577 Index_Subtype : Entity_Id;
8578 Index_Type : Entity_Id;
8579 Slice_Subtype : Entity_Id;
8580 Drange : constant Node_Id := Discrete_Range (N);
8583 if Is_Entity_Name (Drange) then
8584 Index_Subtype := Entity (Drange);
8587 -- We force the evaluation of a range. This is definitely needed in
8588 -- the renamed case, and seems safer to do unconditionally. Note in
8589 -- any case that since we will create and insert an Itype referring
8590 -- to this range, we must make sure any side effect removal actions
8591 -- are inserted before the Itype definition.
8593 if Nkind (Drange) = N_Range then
8594 Force_Evaluation (Low_Bound (Drange));
8595 Force_Evaluation (High_Bound (Drange));
8598 Index_Type := Base_Type (Etype (Drange));
8600 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
8602 Set_Scalar_Range (Index_Subtype, Drange);
8603 Set_Etype (Index_Subtype, Index_Type);
8604 Set_Size_Info (Index_Subtype, Index_Type);
8605 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
8608 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
8610 Index := New_Occurrence_Of (Index_Subtype, Loc);
8611 Set_Etype (Index, Index_Subtype);
8612 Append (Index, Index_List);
8614 Set_First_Index (Slice_Subtype, Index);
8615 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
8616 Set_Is_Constrained (Slice_Subtype, True);
8618 Check_Compile_Time_Size (Slice_Subtype);
8620 -- The Etype of the existing Slice node is reset to this slice subtype.
8621 -- Its bounds are obtained from its first index.
8623 Set_Etype (N, Slice_Subtype);
8625 -- In the packed case, this must be immediately frozen
8627 -- Couldn't we always freeze here??? and if we did, then the above
8628 -- call to Check_Compile_Time_Size could be eliminated, which would
8629 -- be nice, because then that routine could be made private to Freeze.
8631 -- Why the test for In_Spec_Expression here ???
8633 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
8634 Freeze_Itype (Slice_Subtype, N);
8637 end Set_Slice_Subtype;
8639 --------------------------------
8640 -- Set_String_Literal_Subtype --
8641 --------------------------------
8643 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
8644 Loc : constant Source_Ptr := Sloc (N);
8645 Low_Bound : constant Node_Id :=
8646 Type_Low_Bound (Etype (First_Index (Typ)));
8647 Subtype_Id : Entity_Id;
8650 if Nkind (N) /= N_String_Literal then
8654 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
8655 Set_String_Literal_Length (Subtype_Id, UI_From_Int
8656 (String_Length (Strval (N))));
8657 Set_Etype (Subtype_Id, Base_Type (Typ));
8658 Set_Is_Constrained (Subtype_Id);
8659 Set_Etype (N, Subtype_Id);
8661 if Is_OK_Static_Expression (Low_Bound) then
8663 -- The low bound is set from the low bound of the corresponding
8664 -- index type. Note that we do not store the high bound in the
8665 -- string literal subtype, but it can be deduced if necessary
8666 -- from the length and the low bound.
8668 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
8671 Set_String_Literal_Low_Bound
8672 (Subtype_Id, Make_Integer_Literal (Loc, 1));
8673 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Standard_Positive);
8675 -- Build bona fide subtype for the string, and wrap it in an
8676 -- unchecked conversion, because the backend expects the
8677 -- String_Literal_Subtype to have a static lower bound.
8680 Index_List : constant List_Id := New_List;
8681 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
8682 High_Bound : constant Node_Id :=
8684 Left_Opnd => New_Copy_Tree (Low_Bound),
8686 Make_Integer_Literal (Loc,
8687 String_Length (Strval (N)) - 1));
8688 Array_Subtype : Entity_Id;
8689 Index_Subtype : Entity_Id;
8695 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
8696 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
8697 Set_Scalar_Range (Index_Subtype, Drange);
8698 Set_Parent (Drange, N);
8699 Analyze_And_Resolve (Drange, Index_Type);
8701 -- In the context, the Index_Type may already have a constraint,
8702 -- so use common base type on string subtype. The base type may
8703 -- be used when generating attributes of the string, for example
8704 -- in the context of a slice assignment.
8706 Set_Etype (Index_Subtype, Base_Type (Index_Type));
8707 Set_Size_Info (Index_Subtype, Index_Type);
8708 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
8710 Array_Subtype := Create_Itype (E_Array_Subtype, N);
8712 Index := New_Occurrence_Of (Index_Subtype, Loc);
8713 Set_Etype (Index, Index_Subtype);
8714 Append (Index, Index_List);
8716 Set_First_Index (Array_Subtype, Index);
8717 Set_Etype (Array_Subtype, Base_Type (Typ));
8718 Set_Is_Constrained (Array_Subtype, True);
8721 Make_Unchecked_Type_Conversion (Loc,
8722 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
8723 Expression => Relocate_Node (N)));
8724 Set_Etype (N, Array_Subtype);
8727 end Set_String_Literal_Subtype;
8729 ------------------------------
8730 -- Simplify_Type_Conversion --
8731 ------------------------------
8733 procedure Simplify_Type_Conversion (N : Node_Id) is
8735 if Nkind (N) = N_Type_Conversion then
8737 Operand : constant Node_Id := Expression (N);
8738 Target_Typ : constant Entity_Id := Etype (N);
8739 Opnd_Typ : constant Entity_Id := Etype (Operand);
8742 if Is_Floating_Point_Type (Opnd_Typ)
8744 (Is_Integer_Type (Target_Typ)
8745 or else (Is_Fixed_Point_Type (Target_Typ)
8746 and then Conversion_OK (N)))
8747 and then Nkind (Operand) = N_Attribute_Reference
8748 and then Attribute_Name (Operand) = Name_Truncation
8750 -- Special processing required if the conversion is the expression
8751 -- of a Truncation attribute reference. In this case we replace:
8753 -- ityp (ftyp'Truncation (x))
8759 -- with the Float_Truncate flag set, which is more efficient
8763 Relocate_Node (First (Expressions (Operand))));
8764 Set_Float_Truncate (N, True);
8768 end Simplify_Type_Conversion;
8770 -----------------------------
8771 -- Unique_Fixed_Point_Type --
8772 -----------------------------
8774 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
8775 T1 : Entity_Id := Empty;
8780 procedure Fixed_Point_Error;
8781 -- If true ambiguity, give details
8783 -----------------------
8784 -- Fixed_Point_Error --
8785 -----------------------
8787 procedure Fixed_Point_Error is
8789 Error_Msg_N ("ambiguous universal_fixed_expression", N);
8790 Error_Msg_NE ("\\possible interpretation as}", N, T1);
8791 Error_Msg_NE ("\\possible interpretation as}", N, T2);
8792 end Fixed_Point_Error;
8794 -- Start of processing for Unique_Fixed_Point_Type
8797 -- The operations on Duration are visible, so Duration is always a
8798 -- possible interpretation.
8800 T1 := Standard_Duration;
8802 -- Look for fixed-point types in enclosing scopes
8804 Scop := Current_Scope;
8805 while Scop /= Standard_Standard loop
8806 T2 := First_Entity (Scop);
8807 while Present (T2) loop
8808 if Is_Fixed_Point_Type (T2)
8809 and then Current_Entity (T2) = T2
8810 and then Scope (Base_Type (T2)) = Scop
8812 if Present (T1) then
8823 Scop := Scope (Scop);
8826 -- Look for visible fixed type declarations in the context
8828 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
8829 while Present (Item) loop
8830 if Nkind (Item) = N_With_Clause then
8831 Scop := Entity (Name (Item));
8832 T2 := First_Entity (Scop);
8833 while Present (T2) loop
8834 if Is_Fixed_Point_Type (T2)
8835 and then Scope (Base_Type (T2)) = Scop
8836 and then (Is_Potentially_Use_Visible (T2)
8837 or else In_Use (T2))
8839 if Present (T1) then
8854 if Nkind (N) = N_Real_Literal then
8855 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
8857 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
8861 end Unique_Fixed_Point_Type;
8863 ----------------------
8864 -- Valid_Conversion --
8865 ----------------------
8867 function Valid_Conversion
8870 Operand : Node_Id) return Boolean
8872 Target_Type : constant Entity_Id := Base_Type (Target);
8873 Opnd_Type : Entity_Id := Etype (Operand);
8875 function Conversion_Check
8877 Msg : String) return Boolean;
8878 -- Little routine to post Msg if Valid is False, returns Valid value
8880 function Valid_Tagged_Conversion
8881 (Target_Type : Entity_Id;
8882 Opnd_Type : Entity_Id) return Boolean;
8883 -- Specifically test for validity of tagged conversions
8885 function Valid_Array_Conversion return Boolean;
8886 -- Check index and component conformance, and accessibility levels
8887 -- if the component types are anonymous access types (Ada 2005)
8889 ----------------------
8890 -- Conversion_Check --
8891 ----------------------
8893 function Conversion_Check
8895 Msg : String) return Boolean
8899 Error_Msg_N (Msg, Operand);
8903 end Conversion_Check;
8905 ----------------------------
8906 -- Valid_Array_Conversion --
8907 ----------------------------
8909 function Valid_Array_Conversion return Boolean
8911 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
8912 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
8914 Opnd_Index : Node_Id;
8915 Opnd_Index_Type : Entity_Id;
8917 Target_Comp_Type : constant Entity_Id :=
8918 Component_Type (Target_Type);
8919 Target_Comp_Base : constant Entity_Id :=
8920 Base_Type (Target_Comp_Type);
8922 Target_Index : Node_Id;
8923 Target_Index_Type : Entity_Id;
8926 -- Error if wrong number of dimensions
8929 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
8932 ("incompatible number of dimensions for conversion", Operand);
8935 -- Number of dimensions matches
8938 -- Loop through indexes of the two arrays
8940 Target_Index := First_Index (Target_Type);
8941 Opnd_Index := First_Index (Opnd_Type);
8942 while Present (Target_Index) and then Present (Opnd_Index) loop
8943 Target_Index_Type := Etype (Target_Index);
8944 Opnd_Index_Type := Etype (Opnd_Index);
8946 -- Error if index types are incompatible
8948 if not (Is_Integer_Type (Target_Index_Type)
8949 and then Is_Integer_Type (Opnd_Index_Type))
8950 and then (Root_Type (Target_Index_Type)
8951 /= Root_Type (Opnd_Index_Type))
8954 ("incompatible index types for array conversion",
8959 Next_Index (Target_Index);
8960 Next_Index (Opnd_Index);
8963 -- If component types have same base type, all set
8965 if Target_Comp_Base = Opnd_Comp_Base then
8968 -- Here if base types of components are not the same. The only
8969 -- time this is allowed is if we have anonymous access types.
8971 -- The conversion of arrays of anonymous access types can lead
8972 -- to dangling pointers. AI-392 formalizes the accessibility
8973 -- checks that must be applied to such conversions to prevent
8974 -- out-of-scope references.
8977 (Ekind (Target_Comp_Base) = E_Anonymous_Access_Type
8979 Ekind (Target_Comp_Base) = E_Anonymous_Access_Subprogram_Type)
8980 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
8982 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
8984 if Type_Access_Level (Target_Type) <
8985 Type_Access_Level (Opnd_Type)
8987 if In_Instance_Body then
8988 Error_Msg_N ("?source array type " &
8989 "has deeper accessibility level than target", Operand);
8990 Error_Msg_N ("\?Program_Error will be raised at run time",
8993 Make_Raise_Program_Error (Sloc (N),
8994 Reason => PE_Accessibility_Check_Failed));
8995 Set_Etype (N, Target_Type);
8998 -- Conversion not allowed because of accessibility levels
9001 Error_Msg_N ("source array type " &
9002 "has deeper accessibility level than target", Operand);
9009 -- All other cases where component base types do not match
9013 ("incompatible component types for array conversion",
9018 -- Check that component subtypes statically match. For numeric
9019 -- types this means that both must be either constrained or
9020 -- unconstrained. For enumeration types the bounds must match.
9021 -- All of this is checked in Subtypes_Statically_Match.
9023 if not Subtypes_Statically_Match
9024 (Target_Comp_Type, Opnd_Comp_Type)
9027 ("component subtypes must statically match", Operand);
9033 end Valid_Array_Conversion;
9035 -----------------------------
9036 -- Valid_Tagged_Conversion --
9037 -----------------------------
9039 function Valid_Tagged_Conversion
9040 (Target_Type : Entity_Id;
9041 Opnd_Type : Entity_Id) return Boolean
9044 -- Upward conversions are allowed (RM 4.6(22))
9046 if Covers (Target_Type, Opnd_Type)
9047 or else Is_Ancestor (Target_Type, Opnd_Type)
9051 -- Downward conversion are allowed if the operand is class-wide
9054 elsif Is_Class_Wide_Type (Opnd_Type)
9055 and then Covers (Opnd_Type, Target_Type)
9059 elsif Covers (Opnd_Type, Target_Type)
9060 or else Is_Ancestor (Opnd_Type, Target_Type)
9063 Conversion_Check (False,
9064 "downward conversion of tagged objects not allowed");
9066 -- Ada 2005 (AI-251): The conversion to/from interface types is
9069 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
9072 -- If the operand is a class-wide type obtained through a limited_
9073 -- with clause, and the context includes the non-limited view, use
9074 -- it to determine whether the conversion is legal.
9076 elsif Is_Class_Wide_Type (Opnd_Type)
9077 and then From_With_Type (Opnd_Type)
9078 and then Present (Non_Limited_View (Etype (Opnd_Type)))
9079 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
9083 elsif Is_Access_Type (Opnd_Type)
9084 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
9090 ("invalid tagged conversion, not compatible with}",
9091 N, First_Subtype (Opnd_Type));
9094 end Valid_Tagged_Conversion;
9096 -- Start of processing for Valid_Conversion
9099 Check_Parameterless_Call (Operand);
9101 if Is_Overloaded (Operand) then
9110 -- Remove procedure calls, which syntactically cannot appear
9111 -- in this context, but which cannot be removed by type checking,
9112 -- because the context does not impose a type.
9114 -- When compiling for VMS, spurious ambiguities can be produced
9115 -- when arithmetic operations have a literal operand and return
9116 -- System.Address or a descendant of it. These ambiguities are
9117 -- otherwise resolved by the context, but for conversions there
9118 -- is no context type and the removal of the spurious operations
9119 -- must be done explicitly here.
9121 -- The node may be labelled overloaded, but still contain only
9122 -- one interpretation because others were discarded in previous
9123 -- filters. If this is the case, retain the single interpretation
9126 Get_First_Interp (Operand, I, It);
9127 Opnd_Type := It.Typ;
9128 Get_Next_Interp (I, It);
9131 and then Opnd_Type /= Standard_Void_Type
9133 -- More than one candidate interpretation is available
9135 Get_First_Interp (Operand, I, It);
9136 while Present (It.Typ) loop
9137 if It.Typ = Standard_Void_Type then
9141 if Present (System_Aux_Id)
9142 and then Is_Descendent_Of_Address (It.Typ)
9147 Get_Next_Interp (I, It);
9151 Get_First_Interp (Operand, I, It);
9156 Error_Msg_N ("illegal operand in conversion", Operand);
9160 Get_Next_Interp (I, It);
9162 if Present (It.Typ) then
9164 It1 := Disambiguate (Operand, I1, I, Any_Type);
9166 if It1 = No_Interp then
9167 Error_Msg_N ("ambiguous operand in conversion", Operand);
9169 Error_Msg_Sloc := Sloc (It.Nam);
9170 Error_Msg_N ("\\possible interpretation#!", Operand);
9172 Error_Msg_Sloc := Sloc (N1);
9173 Error_Msg_N ("\\possible interpretation#!", Operand);
9179 Set_Etype (Operand, It1.Typ);
9180 Opnd_Type := It1.Typ;
9186 if Is_Numeric_Type (Target_Type) then
9188 -- A universal fixed expression can be converted to any numeric type
9190 if Opnd_Type = Universal_Fixed then
9193 -- Also no need to check when in an instance or inlined body, because
9194 -- the legality has been established when the template was analyzed.
9195 -- Furthermore, numeric conversions may occur where only a private
9196 -- view of the operand type is visible at the instantiation point.
9197 -- This results in a spurious error if we check that the operand type
9198 -- is a numeric type.
9200 -- Note: in a previous version of this unit, the following tests were
9201 -- applied only for generated code (Comes_From_Source set to False),
9202 -- but in fact the test is required for source code as well, since
9203 -- this situation can arise in source code.
9205 elsif In_Instance or else In_Inlined_Body then
9208 -- Otherwise we need the conversion check
9211 return Conversion_Check
9212 (Is_Numeric_Type (Opnd_Type),
9213 "illegal operand for numeric conversion");
9218 elsif Is_Array_Type (Target_Type) then
9219 if not Is_Array_Type (Opnd_Type)
9220 or else Opnd_Type = Any_Composite
9221 or else Opnd_Type = Any_String
9224 ("illegal operand for array conversion", Operand);
9227 return Valid_Array_Conversion;
9230 -- Ada 2005 (AI-251): Anonymous access types where target references an
9233 elsif (Ekind (Target_Type) = E_General_Access_Type
9235 Ekind (Target_Type) = E_Anonymous_Access_Type)
9236 and then Is_Interface (Directly_Designated_Type (Target_Type))
9238 -- Check the static accessibility rule of 4.6(17). Note that the
9239 -- check is not enforced when within an instance body, since the RM
9240 -- requires such cases to be caught at run time.
9242 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
9243 if Type_Access_Level (Opnd_Type) >
9244 Type_Access_Level (Target_Type)
9246 -- In an instance, this is a run-time check, but one we know
9247 -- will fail, so generate an appropriate warning. The raise
9248 -- will be generated by Expand_N_Type_Conversion.
9250 if In_Instance_Body then
9252 ("?cannot convert local pointer to non-local access type",
9255 ("\?Program_Error will be raised at run time", Operand);
9258 ("cannot convert local pointer to non-local access type",
9263 -- Special accessibility checks are needed in the case of access
9264 -- discriminants declared for a limited type.
9266 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9267 and then not Is_Local_Anonymous_Access (Opnd_Type)
9269 -- When the operand is a selected access discriminant the check
9270 -- needs to be made against the level of the object denoted by
9271 -- the prefix of the selected name. (Object_Access_Level
9272 -- handles checking the prefix of the operand for this case.)
9274 if Nkind (Operand) = N_Selected_Component
9275 and then Object_Access_Level (Operand) >
9276 Type_Access_Level (Target_Type)
9278 -- In an instance, this is a run-time check, but one we
9279 -- know will fail, so generate an appropriate warning.
9280 -- The raise will be generated by Expand_N_Type_Conversion.
9282 if In_Instance_Body then
9284 ("?cannot convert access discriminant to non-local" &
9285 " access type", Operand);
9287 ("\?Program_Error will be raised at run time", Operand);
9290 ("cannot convert access discriminant to non-local" &
9291 " access type", Operand);
9296 -- The case of a reference to an access discriminant from
9297 -- within a limited type declaration (which will appear as
9298 -- a discriminal) is always illegal because the level of the
9299 -- discriminant is considered to be deeper than any (nameable)
9302 if Is_Entity_Name (Operand)
9303 and then not Is_Local_Anonymous_Access (Opnd_Type)
9304 and then (Ekind (Entity (Operand)) = E_In_Parameter
9305 or else Ekind (Entity (Operand)) = E_Constant)
9306 and then Present (Discriminal_Link (Entity (Operand)))
9309 ("discriminant has deeper accessibility level than target",
9318 -- General and anonymous access types
9320 elsif (Ekind (Target_Type) = E_General_Access_Type
9321 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
9324 (Is_Access_Type (Opnd_Type)
9325 and then Ekind (Opnd_Type) /=
9326 E_Access_Subprogram_Type
9327 and then Ekind (Opnd_Type) /=
9328 E_Access_Protected_Subprogram_Type,
9329 "must be an access-to-object type")
9331 if Is_Access_Constant (Opnd_Type)
9332 and then not Is_Access_Constant (Target_Type)
9335 ("access-to-constant operand type not allowed", Operand);
9339 -- Check the static accessibility rule of 4.6(17). Note that the
9340 -- check is not enforced when within an instance body, since the RM
9341 -- requires such cases to be caught at run time.
9343 if Ekind (Target_Type) /= E_Anonymous_Access_Type
9344 or else Is_Local_Anonymous_Access (Target_Type)
9346 if Type_Access_Level (Opnd_Type)
9347 > Type_Access_Level (Target_Type)
9349 -- In an instance, this is a run-time check, but one we
9350 -- know will fail, so generate an appropriate warning.
9351 -- The raise will be generated by Expand_N_Type_Conversion.
9353 if In_Instance_Body then
9355 ("?cannot convert local pointer to non-local access type",
9358 ("\?Program_Error will be raised at run time", Operand);
9361 -- Avoid generation of spurious error message
9363 if not Error_Posted (N) then
9365 ("cannot convert local pointer to non-local access type",
9372 -- Special accessibility checks are needed in the case of access
9373 -- discriminants declared for a limited type.
9375 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9376 and then not Is_Local_Anonymous_Access (Opnd_Type)
9379 -- When the operand is a selected access discriminant the check
9380 -- needs to be made against the level of the object denoted by
9381 -- the prefix of the selected name. (Object_Access_Level
9382 -- handles checking the prefix of the operand for this case.)
9384 if Nkind (Operand) = N_Selected_Component
9385 and then Object_Access_Level (Operand) >
9386 Type_Access_Level (Target_Type)
9388 -- In an instance, this is a run-time check, but one we
9389 -- know will fail, so generate an appropriate warning.
9390 -- The raise will be generated by Expand_N_Type_Conversion.
9392 if In_Instance_Body then
9394 ("?cannot convert access discriminant to non-local" &
9395 " access type", Operand);
9397 ("\?Program_Error will be raised at run time",
9402 ("cannot convert access discriminant to non-local" &
9403 " access type", Operand);
9408 -- The case of a reference to an access discriminant from
9409 -- within a limited type declaration (which will appear as
9410 -- a discriminal) is always illegal because the level of the
9411 -- discriminant is considered to be deeper than any (nameable)
9414 if Is_Entity_Name (Operand)
9415 and then (Ekind (Entity (Operand)) = E_In_Parameter
9416 or else Ekind (Entity (Operand)) = E_Constant)
9417 and then Present (Discriminal_Link (Entity (Operand)))
9420 ("discriminant has deeper accessibility level than target",
9428 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
9429 -- Helper function to handle limited views
9431 --------------------------
9432 -- Full_Designated_Type --
9433 --------------------------
9435 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
9436 Desig : constant Entity_Id := Designated_Type (T);
9438 if From_With_Type (Desig)
9439 and then Is_Incomplete_Type (Desig)
9440 and then Present (Non_Limited_View (Desig))
9442 return Non_Limited_View (Desig);
9446 end Full_Designated_Type;
9448 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
9449 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
9451 Same_Base : constant Boolean :=
9452 Base_Type (Target) = Base_Type (Opnd);
9455 if Is_Tagged_Type (Target) then
9456 return Valid_Tagged_Conversion (Target, Opnd);
9459 if not Same_Base then
9461 ("target designated type not compatible with }",
9462 N, Base_Type (Opnd));
9465 -- Ada 2005 AI-384: legality rule is symmetric in both
9466 -- designated types. The conversion is legal (with possible
9467 -- constraint check) if either designated type is
9470 elsif Subtypes_Statically_Match (Target, Opnd)
9472 (Has_Discriminants (Target)
9474 (not Is_Constrained (Opnd)
9475 or else not Is_Constrained (Target)))
9481 ("target designated subtype not compatible with }",
9488 -- Access to subprogram types. If the operand is an access parameter,
9489 -- the type has a deeper accessibility that any master, and cannot
9492 elsif (Ekind (Target_Type) = E_Access_Subprogram_Type
9494 Ekind (Target_Type) = E_Anonymous_Access_Subprogram_Type)
9495 and then No (Corresponding_Remote_Type (Opnd_Type))
9497 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
9498 and then Is_Entity_Name (Operand)
9499 and then Ekind (Entity (Operand)) = E_In_Parameter
9502 ("illegal attempt to store anonymous access to subprogram",
9505 ("\value has deeper accessibility than any master " &
9510 ("\use named access type for& instead of access parameter",
9511 Operand, Entity (Operand));
9514 -- Check that the designated types are subtype conformant
9516 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
9517 Old_Id => Designated_Type (Opnd_Type),
9520 -- Check the static accessibility rule of 4.6(20)
9522 if Type_Access_Level (Opnd_Type) >
9523 Type_Access_Level (Target_Type)
9526 ("operand type has deeper accessibility level than target",
9529 -- Check that if the operand type is declared in a generic body,
9530 -- then the target type must be declared within that same body
9531 -- (enforces last sentence of 4.6(20)).
9533 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
9535 O_Gen : constant Node_Id :=
9536 Enclosing_Generic_Body (Opnd_Type);
9541 T_Gen := Enclosing_Generic_Body (Target_Type);
9542 while Present (T_Gen) and then T_Gen /= O_Gen loop
9543 T_Gen := Enclosing_Generic_Body (T_Gen);
9546 if T_Gen /= O_Gen then
9548 ("target type must be declared in same generic body"
9549 & " as operand type", N);
9556 -- Remote subprogram access types
9558 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
9559 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
9561 -- It is valid to convert from one RAS type to another provided
9562 -- that their specification statically match.
9564 Check_Subtype_Conformant
9566 Designated_Type (Corresponding_Remote_Type (Target_Type)),
9568 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
9573 -- If both are tagged types, check legality of view conversions
9575 elsif Is_Tagged_Type (Target_Type)
9576 and then Is_Tagged_Type (Opnd_Type)
9578 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
9580 -- Types derived from the same root type are convertible
9582 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
9585 -- In an instance or an inlined body, there may be inconsistent
9586 -- views of the same type, or of types derived from a common root.
9588 elsif (In_Instance or In_Inlined_Body)
9590 Root_Type (Underlying_Type (Target_Type)) =
9591 Root_Type (Underlying_Type (Opnd_Type))
9595 -- Special check for common access type error case
9597 elsif Ekind (Target_Type) = E_Access_Type
9598 and then Is_Access_Type (Opnd_Type)
9600 Error_Msg_N ("target type must be general access type!", N);
9601 Error_Msg_NE ("add ALL to }!", N, Target_Type);
9606 Error_Msg_NE ("invalid conversion, not compatible with }",
9611 end Valid_Conversion;