1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Debug_A; use Debug_A;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Ch6; use Exp_Ch6;
36 with Exp_Ch7; use Exp_Ch7;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
41 with Itypes; use Itypes;
43 with Lib.Xref; use Lib.Xref;
44 with Namet; use Namet;
45 with Nmake; use Nmake;
46 with Nlists; use Nlists;
48 with Output; use Output;
49 with Restrict; use Restrict;
50 with Rident; use Rident;
51 with Rtsfind; use Rtsfind;
53 with Sem_Aux; use Sem_Aux;
54 with Sem_Aggr; use Sem_Aggr;
55 with Sem_Attr; use Sem_Attr;
56 with Sem_Cat; use Sem_Cat;
57 with Sem_Ch4; use Sem_Ch4;
58 with Sem_Ch6; use Sem_Ch6;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Elab; use Sem_Elab;
65 with Sem_Eval; use Sem_Eval;
66 with Sem_Intr; use Sem_Intr;
67 with Sem_Util; use Sem_Util;
68 with Sem_Type; use Sem_Type;
69 with Sem_Warn; use Sem_Warn;
70 with Sinfo; use Sinfo;
71 with Sinfo.CN; use Sinfo.CN;
72 with Snames; use Snames;
73 with Stand; use Stand;
74 with Stringt; use Stringt;
75 with Style; use Style;
76 with Tbuild; use Tbuild;
77 with Uintp; use Uintp;
78 with Urealp; use Urealp;
80 package body Sem_Res is
82 -----------------------
83 -- Local Subprograms --
84 -----------------------
86 -- Second pass (top-down) type checking and overload resolution procedures
87 -- Typ is the type required by context. These procedures propagate the
88 -- type information recursively to the descendants of N. If the node
89 -- is not overloaded, its Etype is established in the first pass. If
90 -- overloaded, the Resolve routines set the correct type. For arith.
91 -- operators, the Etype is the base type of the context.
93 -- Note that Resolve_Attribute is separated off in Sem_Attr
95 function Matching_Static_Array_Bounds
97 R_Typ : Node_Id) return Boolean;
98 -- L_Typ and R_Typ are two array types. Returns True when they have the
99 -- same dimension, and, for each index position, the same static bounds.
101 function Bad_Unordered_Enumeration_Reference
103 T : Entity_Id) return Boolean;
104 -- Node N contains a potentially dubious reference to type T, either an
105 -- explicit comparison, or an explicit range. This function returns True
106 -- if the type T is an enumeration type for which No pragma Order has been
107 -- given, and the reference N is not in the same extended source unit as
108 -- the declaration of T.
110 procedure Check_Discriminant_Use (N : Node_Id);
111 -- Enforce the restrictions on the use of discriminants when constraining
112 -- a component of a discriminated type (record or concurrent type).
114 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
115 -- Given a node for an operator associated with type T, check that
116 -- the operator is visible. Operators all of whose operands are
117 -- universal must be checked for visibility during resolution
118 -- because their type is not determinable based on their operands.
120 procedure Check_Fully_Declared_Prefix
123 -- Check that the type of the prefix of a dereference is not incomplete
125 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
126 -- Given a call node, N, which is known to occur immediately within the
127 -- subprogram being called, determines whether it is a detectable case of
128 -- an infinite recursion, and if so, outputs appropriate messages. Returns
129 -- True if an infinite recursion is detected, and False otherwise.
131 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
132 -- If the type of the object being initialized uses the secondary stack
133 -- directly or indirectly, create a transient scope for the call to the
134 -- init proc. This is because we do not create transient scopes for the
135 -- initialization of individual components within the init proc itself.
136 -- Could be optimized away perhaps?
138 procedure Check_No_Direct_Boolean_Operators (N : Node_Id);
139 -- N is the node for a logical operator. If the operator is predefined, and
140 -- the root type of the operands is Standard.Boolean, then a check is made
141 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
142 -- the style check for Style_Check_Boolean_And_Or.
144 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
145 -- Determine whether E is an access type declared by an access
146 -- declaration, and not an (anonymous) allocator type.
148 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
149 -- Utility to check whether the entity for an operator is a predefined
150 -- operator, in which case the expression is left as an operator in the
151 -- tree (else it is rewritten into a call). An instance of an intrinsic
152 -- conversion operation may be given an operator name, but is not treated
153 -- like an operator. Note that an operator that is an imported back-end
154 -- builtin has convention Intrinsic, but is expected to be rewritten into
155 -- a call, so such an operator is not treated as predefined by this
158 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
159 -- If a default expression in entry call N depends on the discriminants
160 -- of the task, it must be replaced with a reference to the discriminant
161 -- of the task being called.
163 procedure Resolve_Op_Concat_Arg
168 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
169 -- concatenation operator. The operand is either of the array type or of
170 -- the component type. If the operand is an aggregate, and the component
171 -- type is composite, this is ambiguous if component type has aggregates.
173 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
174 -- Does the first part of the work of Resolve_Op_Concat
176 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
177 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
178 -- has been resolved. See Resolve_Op_Concat for details.
180 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
185 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
186 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
187 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
188 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
189 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
190 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id);
191 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
192 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
193 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
194 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
195 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
196 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
197 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
198 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
199 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
200 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
201 procedure Resolve_Quantified_Expression (N : Node_Id; Typ : Entity_Id);
202 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
203 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
204 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
205 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
206 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
207 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
208 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
209 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
210 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
211 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
212 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
213 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
214 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
216 function Operator_Kind
218 Is_Binary : Boolean) return Node_Kind;
219 -- Utility to map the name of an operator into the corresponding Node. Used
220 -- by other node rewriting procedures.
222 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
223 -- Resolve actuals of call, and add default expressions for missing ones.
224 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
225 -- called subprogram.
227 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
228 -- Called from Resolve_Call, when the prefix denotes an entry or element
229 -- of entry family. Actuals are resolved as for subprograms, and the node
230 -- is rebuilt as an entry call. Also called for protected operations. Typ
231 -- is the context type, which is used when the operation is a protected
232 -- function with no arguments, and the return value is indexed.
234 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
235 -- A call to a user-defined intrinsic operator is rewritten as a call
236 -- to the corresponding predefined operator, with suitable conversions.
237 -- Note that this applies only for intrinsic operators that denote
238 -- predefined operators, not operators that are intrinsic imports of
239 -- back-end builtins.
241 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
242 -- Ditto, for unary operators (arithmetic ones and "not" on signed
243 -- integer types for VMS).
245 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
246 -- If an operator node resolves to a call to a user-defined operator,
247 -- rewrite the node as a function call.
249 procedure Make_Call_Into_Operator
253 -- Inverse transformation: if an operator is given in functional notation,
254 -- then after resolving the node, transform into an operator node, so
255 -- that operands are resolved properly. Recall that predefined operators
256 -- do not have a full signature and special resolution rules apply.
258 procedure Rewrite_Renamed_Operator
262 -- An operator can rename another, e.g. in an instantiation. In that
263 -- case, the proper operator node must be constructed and resolved.
265 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
266 -- The String_Literal_Subtype is built for all strings that are not
267 -- operands of a static concatenation operation. If the argument is
268 -- not a N_String_Literal node, then the call has no effect.
270 procedure Set_Slice_Subtype (N : Node_Id);
271 -- Build subtype of array type, with the range specified by the slice
273 procedure Simplify_Type_Conversion (N : Node_Id);
274 -- Called after N has been resolved and evaluated, but before range checks
275 -- have been applied. Currently simplifies a combination of floating-point
276 -- to integer conversion and Truncation attribute.
278 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
279 -- A universal_fixed expression in an universal context is unambiguous
280 -- if there is only one applicable fixed point type. Determining whether
281 -- there is only one requires a search over all visible entities, and
282 -- happens only in very pathological cases (see 6115-006).
284 function Valid_Conversion
287 Operand : Node_Id) return Boolean;
288 -- Verify legality rules given in 4.6 (8-23). Target is the target
289 -- type of the conversion, which may be an implicit conversion of
290 -- an actual parameter to an anonymous access type (in which case
291 -- N denotes the actual parameter and N = Operand).
293 -------------------------
294 -- Ambiguous_Character --
295 -------------------------
297 procedure Ambiguous_Character (C : Node_Id) is
301 if Nkind (C) = N_Character_Literal then
302 Error_Msg_N ("ambiguous character literal", C);
304 -- First the ones in Standard
306 Error_Msg_N ("\\possible interpretation: Character!", C);
307 Error_Msg_N ("\\possible interpretation: Wide_Character!", C);
309 -- Include Wide_Wide_Character in Ada 2005 mode
311 if Ada_Version >= Ada_2005 then
312 Error_Msg_N ("\\possible interpretation: Wide_Wide_Character!", C);
315 -- Now any other types that match
317 E := Current_Entity (C);
318 while Present (E) loop
319 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
323 end Ambiguous_Character;
325 -------------------------
326 -- Analyze_And_Resolve --
327 -------------------------
329 procedure Analyze_And_Resolve (N : Node_Id) is
333 end Analyze_And_Resolve;
335 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
339 end Analyze_And_Resolve;
341 -- Version withs check(s) suppressed
343 procedure Analyze_And_Resolve
348 Scop : constant Entity_Id := Current_Scope;
351 if Suppress = All_Checks then
353 Svg : constant Suppress_Array := Scope_Suppress;
355 Scope_Suppress := (others => True);
356 Analyze_And_Resolve (N, Typ);
357 Scope_Suppress := Svg;
362 Svg : constant Boolean := Scope_Suppress (Suppress);
365 Scope_Suppress (Suppress) := True;
366 Analyze_And_Resolve (N, Typ);
367 Scope_Suppress (Suppress) := Svg;
371 if Current_Scope /= Scop
372 and then Scope_Is_Transient
374 -- This can only happen if a transient scope was created
375 -- for an inner expression, which will be removed upon
376 -- completion of the analysis of an enclosing construct.
377 -- The transient scope must have the suppress status of
378 -- the enclosing environment, not of this Analyze call.
380 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
383 end Analyze_And_Resolve;
385 procedure Analyze_And_Resolve
389 Scop : constant Entity_Id := Current_Scope;
392 if Suppress = All_Checks then
394 Svg : constant Suppress_Array := Scope_Suppress;
396 Scope_Suppress := (others => True);
397 Analyze_And_Resolve (N);
398 Scope_Suppress := Svg;
403 Svg : constant Boolean := Scope_Suppress (Suppress);
406 Scope_Suppress (Suppress) := True;
407 Analyze_And_Resolve (N);
408 Scope_Suppress (Suppress) := Svg;
412 if Current_Scope /= Scop
413 and then Scope_Is_Transient
415 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
418 end Analyze_And_Resolve;
420 ----------------------------------------
421 -- Bad_Unordered_Enumeration_Reference --
422 ----------------------------------------
424 function Bad_Unordered_Enumeration_Reference
426 T : Entity_Id) return Boolean
429 return Is_Enumeration_Type (T)
430 and then Comes_From_Source (N)
431 and then Warn_On_Unordered_Enumeration_Type
432 and then not Has_Pragma_Ordered (T)
433 and then not In_Same_Extended_Unit (N, T);
434 end Bad_Unordered_Enumeration_Reference;
436 ----------------------------
437 -- Check_Discriminant_Use --
438 ----------------------------
440 procedure Check_Discriminant_Use (N : Node_Id) is
441 PN : constant Node_Id := Parent (N);
442 Disc : constant Entity_Id := Entity (N);
447 -- Any use in a spec-expression is legal
449 if In_Spec_Expression then
452 elsif Nkind (PN) = N_Range then
454 -- Discriminant cannot be used to constrain a scalar type
458 if Nkind (P) = N_Range_Constraint
459 and then Nkind (Parent (P)) = N_Subtype_Indication
460 and then Nkind (Parent (Parent (P))) = N_Component_Definition
462 Error_Msg_N ("discriminant cannot constrain scalar type", N);
464 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
466 -- The following check catches the unusual case where
467 -- a discriminant appears within an index constraint
468 -- that is part of a larger expression within a constraint
469 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
470 -- For now we only check case of record components, and
471 -- note that a similar check should also apply in the
472 -- case of discriminant constraints below. ???
474 -- Note that the check for N_Subtype_Declaration below is to
475 -- detect the valid use of discriminants in the constraints of a
476 -- subtype declaration when this subtype declaration appears
477 -- inside the scope of a record type (which is syntactically
478 -- illegal, but which may be created as part of derived type
479 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
482 if Ekind (Current_Scope) = E_Record_Type
483 and then Scope (Disc) = Current_Scope
485 (Nkind (Parent (P)) = N_Subtype_Indication
487 Nkind_In (Parent (Parent (P)), N_Component_Definition,
488 N_Subtype_Declaration)
489 and then Paren_Count (N) = 0)
492 ("discriminant must appear alone in component constraint", N);
496 -- Detect a common error:
498 -- type R (D : Positive := 100) is record
499 -- Name : String (1 .. D);
502 -- The default value causes an object of type R to be allocated
503 -- with room for Positive'Last characters. The RM does not mandate
504 -- the allocation of the maximum size, but that is what GNAT does
505 -- so we should warn the programmer that there is a problem.
507 Check_Large : declare
513 function Large_Storage_Type (T : Entity_Id) return Boolean;
514 -- Return True if type T has a large enough range that
515 -- any array whose index type covered the whole range of
516 -- the type would likely raise Storage_Error.
518 ------------------------
519 -- Large_Storage_Type --
520 ------------------------
522 function Large_Storage_Type (T : Entity_Id) return Boolean is
524 -- The type is considered large if its bounds are known at
525 -- compile time and if it requires at least as many bits as
526 -- a Positive to store the possible values.
528 return Compile_Time_Known_Value (Type_Low_Bound (T))
529 and then Compile_Time_Known_Value (Type_High_Bound (T))
531 Minimum_Size (T, Biased => True) >=
532 RM_Size (Standard_Positive);
533 end Large_Storage_Type;
535 -- Start of processing for Check_Large
538 -- Check that the Disc has a large range
540 if not Large_Storage_Type (Etype (Disc)) then
544 -- If the enclosing type is limited, we allocate only the
545 -- default value, not the maximum, and there is no need for
548 if Is_Limited_Type (Scope (Disc)) then
552 -- Check that it is the high bound
554 if N /= High_Bound (PN)
555 or else No (Discriminant_Default_Value (Disc))
560 -- Check the array allows a large range at this bound.
561 -- First find the array
565 if Nkind (SI) /= N_Subtype_Indication then
569 T := Entity (Subtype_Mark (SI));
571 if not Is_Array_Type (T) then
575 -- Next, find the dimension
577 TB := First_Index (T);
578 CB := First (Constraints (P));
580 and then Present (TB)
581 and then Present (CB)
592 -- Now, check the dimension has a large range
594 if not Large_Storage_Type (Etype (TB)) then
598 -- Warn about the danger
601 ("?creation of & object may raise Storage_Error!",
610 -- Legal case is in index or discriminant constraint
612 elsif Nkind_In (PN, N_Index_Or_Discriminant_Constraint,
613 N_Discriminant_Association)
615 if Paren_Count (N) > 0 then
617 ("discriminant in constraint must appear alone", N);
619 elsif Nkind (N) = N_Expanded_Name
620 and then Comes_From_Source (N)
623 ("discriminant must appear alone as a direct name", N);
628 -- Otherwise, context is an expression. It should not be within
629 -- (i.e. a subexpression of) a constraint for a component.
634 while not Nkind_In (P, N_Component_Declaration,
635 N_Subtype_Indication,
643 -- If the discriminant is used in an expression that is a bound
644 -- of a scalar type, an Itype is created and the bounds are attached
645 -- to its range, not to the original subtype indication. Such use
646 -- is of course a double fault.
648 if (Nkind (P) = N_Subtype_Indication
649 and then Nkind_In (Parent (P), N_Component_Definition,
650 N_Derived_Type_Definition)
651 and then D = Constraint (P))
653 -- The constraint itself may be given by a subtype indication,
654 -- rather than by a more common discrete range.
656 or else (Nkind (P) = N_Subtype_Indication
658 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
659 or else Nkind (P) = N_Entry_Declaration
660 or else Nkind (D) = N_Defining_Identifier
663 ("discriminant in constraint must appear alone", N);
666 end Check_Discriminant_Use;
668 --------------------------------
669 -- Check_For_Visible_Operator --
670 --------------------------------
672 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
674 if Is_Invisible_Operator (N, T) then
675 Error_Msg_NE -- CODEFIX
676 ("operator for} is not directly visible!", N, First_Subtype (T));
677 Error_Msg_N -- CODEFIX
678 ("use clause would make operation legal!", N);
680 end Check_For_Visible_Operator;
682 ----------------------------------
683 -- Check_Fully_Declared_Prefix --
684 ----------------------------------
686 procedure Check_Fully_Declared_Prefix
691 -- Check that the designated type of the prefix of a dereference is
692 -- not an incomplete type. This cannot be done unconditionally, because
693 -- dereferences of private types are legal in default expressions. This
694 -- case is taken care of in Check_Fully_Declared, called below. There
695 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
697 -- This consideration also applies to similar checks for allocators,
698 -- qualified expressions, and type conversions.
700 -- An additional exception concerns other per-object expressions that
701 -- are not directly related to component declarations, in particular
702 -- representation pragmas for tasks. These will be per-object
703 -- expressions if they depend on discriminants or some global entity.
704 -- If the task has access discriminants, the designated type may be
705 -- incomplete at the point the expression is resolved. This resolution
706 -- takes place within the body of the initialization procedure, where
707 -- the discriminant is replaced by its discriminal.
709 if Is_Entity_Name (Pref)
710 and then Ekind (Entity (Pref)) = E_In_Parameter
714 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
715 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
716 -- Analyze_Object_Renaming, and Freeze_Entity.
718 elsif Ada_Version >= Ada_2005
719 and then Is_Entity_Name (Pref)
720 and then Is_Access_Type (Etype (Pref))
721 and then Ekind (Directly_Designated_Type (Etype (Pref))) =
723 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Pref)))
727 Check_Fully_Declared (Typ, Parent (Pref));
729 end Check_Fully_Declared_Prefix;
731 ------------------------------
732 -- Check_Infinite_Recursion --
733 ------------------------------
735 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
739 function Same_Argument_List return Boolean;
740 -- Check whether list of actuals is identical to list of formals
741 -- of called function (which is also the enclosing scope).
743 ------------------------
744 -- Same_Argument_List --
745 ------------------------
747 function Same_Argument_List return Boolean is
753 if not Is_Entity_Name (Name (N)) then
756 Subp := Entity (Name (N));
759 F := First_Formal (Subp);
760 A := First_Actual (N);
761 while Present (F) and then Present (A) loop
762 if not Is_Entity_Name (A)
763 or else Entity (A) /= F
773 end Same_Argument_List;
775 -- Start of processing for Check_Infinite_Recursion
778 -- Special case, if this is a procedure call and is a call to the
779 -- current procedure with the same argument list, then this is for
780 -- sure an infinite recursion and we insert a call to raise SE.
782 if Is_List_Member (N)
783 and then List_Length (List_Containing (N)) = 1
784 and then Same_Argument_List
787 P : constant Node_Id := Parent (N);
789 if Nkind (P) = N_Handled_Sequence_Of_Statements
790 and then Nkind (Parent (P)) = N_Subprogram_Body
791 and then Is_Empty_List (Declarations (Parent (P)))
793 Error_Msg_N ("!?infinite recursion", N);
794 Error_Msg_N ("\!?Storage_Error will be raised at run time", N);
796 Make_Raise_Storage_Error (Sloc (N),
797 Reason => SE_Infinite_Recursion));
803 -- If not that special case, search up tree, quitting if we reach a
804 -- construct (e.g. a conditional) that tells us that this is not a
805 -- case for an infinite recursion warning.
811 -- If no parent, then we were not inside a subprogram, this can for
812 -- example happen when processing certain pragmas in a spec. Just
813 -- return False in this case.
819 -- Done if we get to subprogram body, this is definitely an infinite
820 -- recursion case if we did not find anything to stop us.
822 exit when Nkind (P) = N_Subprogram_Body;
824 -- If appearing in conditional, result is false
826 if Nkind_In (P, N_Or_Else,
830 N_Conditional_Expression,
835 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
836 and then C /= First (Statements (P))
838 -- If the call is the expression of a return statement and the
839 -- actuals are identical to the formals, it's worth a warning.
840 -- However, we skip this if there is an immediately preceding
841 -- raise statement, since the call is never executed.
843 -- Furthermore, this corresponds to a common idiom:
845 -- function F (L : Thing) return Boolean is
847 -- raise Program_Error;
851 -- for generating a stub function
853 if Nkind (Parent (N)) = N_Simple_Return_Statement
854 and then Same_Argument_List
856 exit when not Is_List_Member (Parent (N));
858 -- OK, return statement is in a statement list, look for raise
864 -- Skip past N_Freeze_Entity nodes generated by expansion
866 Nod := Prev (Parent (N));
868 and then Nkind (Nod) = N_Freeze_Entity
873 -- If no raise statement, give warning
875 exit when Nkind (Nod) /= N_Raise_Statement
877 (Nkind (Nod) not in N_Raise_xxx_Error
878 or else Present (Condition (Nod)));
889 Error_Msg_N ("!?possible infinite recursion", N);
890 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
893 end Check_Infinite_Recursion;
895 -------------------------------
896 -- Check_Initialization_Call --
897 -------------------------------
899 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
900 Typ : constant Entity_Id := Etype (First_Formal (Nam));
902 function Uses_SS (T : Entity_Id) return Boolean;
903 -- Check whether the creation of an object of the type will involve
904 -- use of the secondary stack. If T is a record type, this is true
905 -- if the expression for some component uses the secondary stack, e.g.
906 -- through a call to a function that returns an unconstrained value.
907 -- False if T is controlled, because cleanups occur elsewhere.
913 function Uses_SS (T : Entity_Id) return Boolean is
916 Full_Type : Entity_Id := Underlying_Type (T);
919 -- Normally we want to use the underlying type, but if it's not set
920 -- then continue with T.
922 if not Present (Full_Type) then
926 if Is_Controlled (Full_Type) then
929 elsif Is_Array_Type (Full_Type) then
930 return Uses_SS (Component_Type (Full_Type));
932 elsif Is_Record_Type (Full_Type) then
933 Comp := First_Component (Full_Type);
934 while Present (Comp) loop
935 if Ekind (Comp) = E_Component
936 and then Nkind (Parent (Comp)) = N_Component_Declaration
938 -- The expression for a dynamic component may be rewritten
939 -- as a dereference, so retrieve original node.
941 Expr := Original_Node (Expression (Parent (Comp)));
943 -- Return True if the expression is a call to a function
944 -- (including an attribute function such as Image, or a
945 -- user-defined operator) with a result that requires a
948 if (Nkind (Expr) = N_Function_Call
949 or else Nkind (Expr) in N_Op
950 or else (Nkind (Expr) = N_Attribute_Reference
951 and then Present (Expressions (Expr))))
952 and then Requires_Transient_Scope (Etype (Expr))
956 elsif Uses_SS (Etype (Comp)) then
961 Next_Component (Comp);
971 -- Start of processing for Check_Initialization_Call
974 -- Establish a transient scope if the type needs it
976 if Uses_SS (Typ) then
977 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
979 end Check_Initialization_Call;
981 ---------------------------------------
982 -- Check_No_Direct_Boolean_Operators --
983 ---------------------------------------
985 procedure Check_No_Direct_Boolean_Operators (N : Node_Id) is
987 if Scope (Entity (N)) = Standard_Standard
988 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
990 -- Restriction only applies to original source code
992 if Comes_From_Source (N) then
993 Check_Restriction (No_Direct_Boolean_Operators, N);
998 Check_Boolean_Operator (N);
1000 end Check_No_Direct_Boolean_Operators;
1002 ------------------------------
1003 -- Check_Parameterless_Call --
1004 ------------------------------
1006 procedure Check_Parameterless_Call (N : Node_Id) is
1009 function Prefix_Is_Access_Subp return Boolean;
1010 -- If the prefix is of an access_to_subprogram type, the node must be
1011 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1012 -- interpretations are access to subprograms.
1014 ---------------------------
1015 -- Prefix_Is_Access_Subp --
1016 ---------------------------
1018 function Prefix_Is_Access_Subp return Boolean is
1023 -- If the context is an attribute reference that can apply to
1024 -- functions, this is never a parameterless call (RM 4.1.4(6)).
1026 if Nkind (Parent (N)) = N_Attribute_Reference
1027 and then (Attribute_Name (Parent (N)) = Name_Address
1028 or else Attribute_Name (Parent (N)) = Name_Code_Address
1029 or else Attribute_Name (Parent (N)) = Name_Access)
1034 if not Is_Overloaded (N) then
1036 Ekind (Etype (N)) = E_Subprogram_Type
1037 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
1039 Get_First_Interp (N, I, It);
1040 while Present (It.Typ) loop
1041 if Ekind (It.Typ) /= E_Subprogram_Type
1042 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
1047 Get_Next_Interp (I, It);
1052 end Prefix_Is_Access_Subp;
1054 -- Start of processing for Check_Parameterless_Call
1057 -- Defend against junk stuff if errors already detected
1059 if Total_Errors_Detected /= 0 then
1060 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
1062 elsif Nkind (N) in N_Has_Chars
1063 and then Chars (N) in Error_Name_Or_No_Name
1071 -- If the context expects a value, and the name is a procedure, this is
1072 -- most likely a missing 'Access. Don't try to resolve the parameterless
1073 -- call, error will be caught when the outer call is analyzed.
1075 if Is_Entity_Name (N)
1076 and then Ekind (Entity (N)) = E_Procedure
1077 and then not Is_Overloaded (N)
1079 Nkind_In (Parent (N), N_Parameter_Association,
1081 N_Procedure_Call_Statement)
1086 -- Rewrite as call if overloadable entity that is (or could be, in the
1087 -- overloaded case) a function call. If we know for sure that the entity
1088 -- is an enumeration literal, we do not rewrite it.
1090 -- If the entity is the name of an operator, it cannot be a call because
1091 -- operators cannot have default parameters. In this case, this must be
1092 -- a string whose contents coincide with an operator name. Set the kind
1093 -- of the node appropriately.
1095 if (Is_Entity_Name (N)
1096 and then Nkind (N) /= N_Operator_Symbol
1097 and then Is_Overloadable (Entity (N))
1098 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1099 or else Is_Overloaded (N)))
1101 -- Rewrite as call if it is an explicit dereference of an expression of
1102 -- a subprogram access type, and the subprogram type is not that of a
1103 -- procedure or entry.
1106 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1108 -- Rewrite as call if it is a selected component which is a function,
1109 -- this is the case of a call to a protected function (which may be
1110 -- overloaded with other protected operations).
1113 (Nkind (N) = N_Selected_Component
1114 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1116 (Ekind_In (Entity (Selector_Name (N)), E_Entry,
1118 and then Is_Overloaded (Selector_Name (N)))))
1120 -- If one of the above three conditions is met, rewrite as call.
1121 -- Apply the rewriting only once.
1124 if Nkind (Parent (N)) /= N_Function_Call
1125 or else N /= Name (Parent (N))
1127 Nam := New_Copy (N);
1129 -- If overloaded, overload set belongs to new copy
1131 Save_Interps (N, Nam);
1133 -- Change node to parameterless function call (note that the
1134 -- Parameter_Associations associations field is left set to Empty,
1135 -- its normal default value since there are no parameters)
1137 Change_Node (N, N_Function_Call);
1139 Set_Sloc (N, Sloc (Nam));
1143 elsif Nkind (N) = N_Parameter_Association then
1144 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1146 elsif Nkind (N) = N_Operator_Symbol then
1147 Change_Operator_Symbol_To_String_Literal (N);
1148 Set_Is_Overloaded (N, False);
1149 Set_Etype (N, Any_String);
1151 end Check_Parameterless_Call;
1153 -----------------------------
1154 -- Is_Definite_Access_Type --
1155 -----------------------------
1157 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1158 Btyp : constant Entity_Id := Base_Type (E);
1160 return Ekind (Btyp) = E_Access_Type
1161 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1162 and then Comes_From_Source (Btyp));
1163 end Is_Definite_Access_Type;
1165 ----------------------
1166 -- Is_Predefined_Op --
1167 ----------------------
1169 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1171 -- Predefined operators are intrinsic subprograms
1173 if not Is_Intrinsic_Subprogram (Nam) then
1177 -- A call to a back-end builtin is never a predefined operator
1179 if Is_Imported (Nam) and then Present (Interface_Name (Nam)) then
1183 return not Is_Generic_Instance (Nam)
1184 and then Chars (Nam) in Any_Operator_Name
1185 and then (No (Alias (Nam)) or else Is_Predefined_Op (Alias (Nam)));
1186 end Is_Predefined_Op;
1188 -----------------------------
1189 -- Make_Call_Into_Operator --
1190 -----------------------------
1192 procedure Make_Call_Into_Operator
1197 Op_Name : constant Name_Id := Chars (Op_Id);
1198 Act1 : Node_Id := First_Actual (N);
1199 Act2 : Node_Id := Next_Actual (Act1);
1200 Error : Boolean := False;
1201 Func : constant Entity_Id := Entity (Name (N));
1202 Is_Binary : constant Boolean := Present (Act2);
1204 Opnd_Type : Entity_Id;
1205 Orig_Type : Entity_Id := Empty;
1208 type Kind_Test is access function (E : Entity_Id) return Boolean;
1210 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1211 -- If the operand is not universal, and the operator is given by an
1212 -- expanded name, verify that the operand has an interpretation with a
1213 -- type defined in the given scope of the operator.
1215 function Type_In_P (Test : Kind_Test) return Entity_Id;
1216 -- Find a type of the given class in package Pack that contains the
1219 ---------------------------
1220 -- Operand_Type_In_Scope --
1221 ---------------------------
1223 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1224 Nod : constant Node_Id := Right_Opnd (Op_Node);
1229 if not Is_Overloaded (Nod) then
1230 return Scope (Base_Type (Etype (Nod))) = S;
1233 Get_First_Interp (Nod, I, It);
1234 while Present (It.Typ) loop
1235 if Scope (Base_Type (It.Typ)) = S then
1239 Get_Next_Interp (I, It);
1244 end Operand_Type_In_Scope;
1250 function Type_In_P (Test : Kind_Test) return Entity_Id is
1253 function In_Decl return Boolean;
1254 -- Verify that node is not part of the type declaration for the
1255 -- candidate type, which would otherwise be invisible.
1261 function In_Decl return Boolean is
1262 Decl_Node : constant Node_Id := Parent (E);
1268 if Etype (E) = Any_Type then
1271 elsif No (Decl_Node) then
1276 and then Nkind (N2) /= N_Compilation_Unit
1278 if N2 = Decl_Node then
1289 -- Start of processing for Type_In_P
1292 -- If the context type is declared in the prefix package, this is the
1293 -- desired base type.
1295 if Scope (Base_Type (Typ)) = Pack and then Test (Typ) then
1296 return Base_Type (Typ);
1299 E := First_Entity (Pack);
1300 while Present (E) loop
1302 and then not In_Decl
1314 -- Start of processing for Make_Call_Into_Operator
1317 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1322 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1323 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1324 Save_Interps (Act1, Left_Opnd (Op_Node));
1325 Save_Interps (Act2, Right_Opnd (Op_Node));
1326 Act1 := Left_Opnd (Op_Node);
1327 Act2 := Right_Opnd (Op_Node);
1332 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1333 Save_Interps (Act1, Right_Opnd (Op_Node));
1334 Act1 := Right_Opnd (Op_Node);
1337 -- If the operator is denoted by an expanded name, and the prefix is
1338 -- not Standard, but the operator is a predefined one whose scope is
1339 -- Standard, then this is an implicit_operator, inserted as an
1340 -- interpretation by the procedure of the same name. This procedure
1341 -- overestimates the presence of implicit operators, because it does
1342 -- not examine the type of the operands. Verify now that the operand
1343 -- type appears in the given scope. If right operand is universal,
1344 -- check the other operand. In the case of concatenation, either
1345 -- argument can be the component type, so check the type of the result.
1346 -- If both arguments are literals, look for a type of the right kind
1347 -- defined in the given scope. This elaborate nonsense is brought to
1348 -- you courtesy of b33302a. The type itself must be frozen, so we must
1349 -- find the type of the proper class in the given scope.
1351 -- A final wrinkle is the multiplication operator for fixed point types,
1352 -- which is defined in Standard only, and not in the scope of the
1353 -- fixed point type itself.
1355 if Nkind (Name (N)) = N_Expanded_Name then
1356 Pack := Entity (Prefix (Name (N)));
1358 -- If the entity being called is defined in the given package, it is
1359 -- a renaming of a predefined operator, and known to be legal.
1361 if Scope (Entity (Name (N))) = Pack
1362 and then Pack /= Standard_Standard
1366 -- Visibility does not need to be checked in an instance: if the
1367 -- operator was not visible in the generic it has been diagnosed
1368 -- already, else there is an implicit copy of it in the instance.
1370 elsif In_Instance then
1373 elsif (Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide)
1374 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1375 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1377 if Pack /= Standard_Standard then
1381 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1384 elsif Ada_Version >= Ada_2005
1385 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1386 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1391 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1393 if Op_Name = Name_Op_Concat then
1394 Opnd_Type := Base_Type (Typ);
1396 elsif (Scope (Opnd_Type) = Standard_Standard
1398 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1400 and then not Comes_From_Source (Opnd_Type))
1402 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1405 if Scope (Opnd_Type) = Standard_Standard then
1407 -- Verify that the scope contains a type that corresponds to
1408 -- the given literal. Optimize the case where Pack is Standard.
1410 if Pack /= Standard_Standard then
1412 if Opnd_Type = Universal_Integer then
1413 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1415 elsif Opnd_Type = Universal_Real then
1416 Orig_Type := Type_In_P (Is_Real_Type'Access);
1418 elsif Opnd_Type = Any_String then
1419 Orig_Type := Type_In_P (Is_String_Type'Access);
1421 elsif Opnd_Type = Any_Access then
1422 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1424 elsif Opnd_Type = Any_Composite then
1425 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1427 if Present (Orig_Type) then
1428 if Has_Private_Component (Orig_Type) then
1431 Set_Etype (Act1, Orig_Type);
1434 Set_Etype (Act2, Orig_Type);
1443 Error := No (Orig_Type);
1446 elsif Ekind (Opnd_Type) = E_Allocator_Type
1447 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1451 -- If the type is defined elsewhere, and the operator is not
1452 -- defined in the given scope (by a renaming declaration, e.g.)
1453 -- then this is an error as well. If an extension of System is
1454 -- present, and the type may be defined there, Pack must be
1457 elsif Scope (Opnd_Type) /= Pack
1458 and then Scope (Op_Id) /= Pack
1459 and then (No (System_Aux_Id)
1460 or else Scope (Opnd_Type) /= System_Aux_Id
1461 or else Pack /= Scope (System_Aux_Id))
1463 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1466 Error := not Operand_Type_In_Scope (Pack);
1469 elsif Pack = Standard_Standard
1470 and then not Operand_Type_In_Scope (Standard_Standard)
1477 Error_Msg_Node_2 := Pack;
1479 ("& not declared in&", N, Selector_Name (Name (N)));
1480 Set_Etype (N, Any_Type);
1483 -- Detect a mismatch between the context type and the result type
1484 -- in the named package, which is otherwise not detected if the
1485 -- operands are universal. Check is only needed if source entity is
1486 -- an operator, not a function that renames an operator.
1488 elsif Nkind (Parent (N)) /= N_Type_Conversion
1489 and then Ekind (Entity (Name (N))) = E_Operator
1490 and then Is_Numeric_Type (Typ)
1491 and then not Is_Universal_Numeric_Type (Typ)
1492 and then Scope (Base_Type (Typ)) /= Pack
1493 and then not In_Instance
1495 if Is_Fixed_Point_Type (Typ)
1496 and then (Op_Name = Name_Op_Multiply
1498 Op_Name = Name_Op_Divide)
1500 -- Already checked above
1504 -- Operator may be defined in an extension of System
1506 elsif Present (System_Aux_Id)
1507 and then Scope (Opnd_Type) = System_Aux_Id
1512 -- Could we use Wrong_Type here??? (this would require setting
1513 -- Etype (N) to the actual type found where Typ was expected).
1515 Error_Msg_NE ("expect }", N, Typ);
1520 Set_Chars (Op_Node, Op_Name);
1522 if not Is_Private_Type (Etype (N)) then
1523 Set_Etype (Op_Node, Base_Type (Etype (N)));
1525 Set_Etype (Op_Node, Etype (N));
1528 -- If this is a call to a function that renames a predefined equality,
1529 -- the renaming declaration provides a type that must be used to
1530 -- resolve the operands. This must be done now because resolution of
1531 -- the equality node will not resolve any remaining ambiguity, and it
1532 -- assumes that the first operand is not overloaded.
1534 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1535 and then Ekind (Func) = E_Function
1536 and then Is_Overloaded (Act1)
1538 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1539 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1542 Set_Entity (Op_Node, Op_Id);
1543 Generate_Reference (Op_Id, N, ' ');
1545 -- Do rewrite setting Comes_From_Source on the result if the original
1546 -- call came from source. Although it is not strictly the case that the
1547 -- operator as such comes from the source, logically it corresponds
1548 -- exactly to the function call in the source, so it should be marked
1549 -- this way (e.g. to make sure that validity checks work fine).
1552 CS : constant Boolean := Comes_From_Source (N);
1554 Rewrite (N, Op_Node);
1555 Set_Comes_From_Source (N, CS);
1558 -- If this is an arithmetic operator and the result type is private,
1559 -- the operands and the result must be wrapped in conversion to
1560 -- expose the underlying numeric type and expand the proper checks,
1561 -- e.g. on division.
1563 if Is_Private_Type (Typ) then
1565 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1566 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1567 Resolve_Intrinsic_Operator (N, Typ);
1569 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1570 Resolve_Intrinsic_Unary_Operator (N, Typ);
1578 end Make_Call_Into_Operator;
1580 ----------------------------------
1581 -- Matching_Static_Array_Bounds --
1582 ----------------------------------
1584 function Matching_Static_Array_Bounds
1586 R_Typ : Node_Id) return Boolean
1588 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
1589 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
1599 if L_Ndims /= R_Ndims then
1603 -- Unconstrained types do not have static bounds
1605 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
1609 L_Index := First_Index (L_Typ);
1610 R_Index := First_Index (R_Typ);
1612 for Indx in 1 .. L_Ndims loop
1613 Get_Index_Bounds (L_Index, L_Low, L_High);
1614 Get_Index_Bounds (R_Index, R_Low, R_High);
1617 and then Is_Static_Expression (L_Low)
1618 and then Is_Static_Expression (L_High)
1619 and then Is_Static_Expression (R_Low)
1620 and then Is_Static_Expression (R_High)
1621 and then Expr_Value (L_Low) = Expr_Value (R_Low)
1622 and then Expr_Value (L_High) = Expr_Value (R_High)
1624 -- Matching so far, continue with next index
1637 end Matching_Static_Array_Bounds;
1643 function Operator_Kind
1645 Is_Binary : Boolean) return Node_Kind
1650 -- Use CASE statement or array???
1653 if Op_Name = Name_Op_And then
1655 elsif Op_Name = Name_Op_Or then
1657 elsif Op_Name = Name_Op_Xor then
1659 elsif Op_Name = Name_Op_Eq then
1661 elsif Op_Name = Name_Op_Ne then
1663 elsif Op_Name = Name_Op_Lt then
1665 elsif Op_Name = Name_Op_Le then
1667 elsif Op_Name = Name_Op_Gt then
1669 elsif Op_Name = Name_Op_Ge then
1671 elsif Op_Name = Name_Op_Add then
1673 elsif Op_Name = Name_Op_Subtract then
1674 Kind := N_Op_Subtract;
1675 elsif Op_Name = Name_Op_Concat then
1676 Kind := N_Op_Concat;
1677 elsif Op_Name = Name_Op_Multiply then
1678 Kind := N_Op_Multiply;
1679 elsif Op_Name = Name_Op_Divide then
1680 Kind := N_Op_Divide;
1681 elsif Op_Name = Name_Op_Mod then
1683 elsif Op_Name = Name_Op_Rem then
1685 elsif Op_Name = Name_Op_Expon then
1688 raise Program_Error;
1694 if Op_Name = Name_Op_Add then
1696 elsif Op_Name = Name_Op_Subtract then
1698 elsif Op_Name = Name_Op_Abs then
1700 elsif Op_Name = Name_Op_Not then
1703 raise Program_Error;
1710 ----------------------------
1711 -- Preanalyze_And_Resolve --
1712 ----------------------------
1714 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1715 Save_Full_Analysis : constant Boolean := Full_Analysis;
1718 Full_Analysis := False;
1719 Expander_Mode_Save_And_Set (False);
1721 -- We suppress all checks for this analysis, since the checks will
1722 -- be applied properly, and in the right location, when the default
1723 -- expression is reanalyzed and reexpanded later on.
1725 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1727 Expander_Mode_Restore;
1728 Full_Analysis := Save_Full_Analysis;
1729 end Preanalyze_And_Resolve;
1731 -- Version without context type
1733 procedure Preanalyze_And_Resolve (N : Node_Id) is
1734 Save_Full_Analysis : constant Boolean := Full_Analysis;
1737 Full_Analysis := False;
1738 Expander_Mode_Save_And_Set (False);
1741 Resolve (N, Etype (N), Suppress => All_Checks);
1743 Expander_Mode_Restore;
1744 Full_Analysis := Save_Full_Analysis;
1745 end Preanalyze_And_Resolve;
1747 ----------------------------------
1748 -- Replace_Actual_Discriminants --
1749 ----------------------------------
1751 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1752 Loc : constant Source_Ptr := Sloc (N);
1753 Tsk : Node_Id := Empty;
1755 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1761 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1765 if Nkind (Nod) = N_Identifier then
1766 Ent := Entity (Nod);
1769 and then Ekind (Ent) = E_Discriminant
1772 Make_Selected_Component (Loc,
1773 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1774 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1776 Set_Etype (Nod, Etype (Ent));
1784 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1786 -- Start of processing for Replace_Actual_Discriminants
1789 if not Expander_Active then
1793 if Nkind (Name (N)) = N_Selected_Component then
1794 Tsk := Prefix (Name (N));
1796 elsif Nkind (Name (N)) = N_Indexed_Component then
1797 Tsk := Prefix (Prefix (Name (N)));
1803 Replace_Discrs (Default);
1805 end Replace_Actual_Discriminants;
1811 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1812 Ambiguous : Boolean := False;
1813 Ctx_Type : Entity_Id := Typ;
1814 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1815 Err_Type : Entity_Id := Empty;
1816 Found : Boolean := False;
1819 I1 : Interp_Index := 0; -- prevent junk warning
1822 Seen : Entity_Id := Empty; -- prevent junk warning
1824 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1825 -- Determine whether a node comes from a predefined library unit or
1828 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1829 -- Try and fix up a literal so that it matches its expected type. New
1830 -- literals are manufactured if necessary to avoid cascaded errors.
1832 procedure Report_Ambiguous_Argument;
1833 -- Additional diagnostics when an ambiguous call has an ambiguous
1834 -- argument (typically a controlling actual).
1836 procedure Resolution_Failed;
1837 -- Called when attempt at resolving current expression fails
1839 ------------------------------------
1840 -- Comes_From_Predefined_Lib_Unit --
1841 -------------------------------------
1843 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1846 Sloc (Nod) = Standard_Location
1847 or else Is_Predefined_File_Name (Unit_File_Name (
1848 Get_Source_Unit (Sloc (Nod))));
1849 end Comes_From_Predefined_Lib_Unit;
1851 --------------------
1852 -- Patch_Up_Value --
1853 --------------------
1855 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1857 if Nkind (N) = N_Integer_Literal
1858 and then Is_Real_Type (Typ)
1861 Make_Real_Literal (Sloc (N),
1862 Realval => UR_From_Uint (Intval (N))));
1863 Set_Etype (N, Universal_Real);
1864 Set_Is_Static_Expression (N);
1866 elsif Nkind (N) = N_Real_Literal
1867 and then Is_Integer_Type (Typ)
1870 Make_Integer_Literal (Sloc (N),
1871 Intval => UR_To_Uint (Realval (N))));
1872 Set_Etype (N, Universal_Integer);
1873 Set_Is_Static_Expression (N);
1875 elsif Nkind (N) = N_String_Literal
1876 and then Is_Character_Type (Typ)
1878 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1880 Make_Character_Literal (Sloc (N),
1882 Char_Literal_Value =>
1883 UI_From_Int (Character'Pos ('A'))));
1884 Set_Etype (N, Any_Character);
1885 Set_Is_Static_Expression (N);
1887 elsif Nkind (N) /= N_String_Literal
1888 and then Is_String_Type (Typ)
1891 Make_String_Literal (Sloc (N),
1892 Strval => End_String));
1894 elsif Nkind (N) = N_Range then
1895 Patch_Up_Value (Low_Bound (N), Typ);
1896 Patch_Up_Value (High_Bound (N), Typ);
1900 -------------------------------
1901 -- Report_Ambiguous_Argument --
1902 -------------------------------
1904 procedure Report_Ambiguous_Argument is
1905 Arg : constant Node_Id := First (Parameter_Associations (N));
1910 if Nkind (Arg) = N_Function_Call
1911 and then Is_Entity_Name (Name (Arg))
1912 and then Is_Overloaded (Name (Arg))
1914 Error_Msg_NE ("ambiguous call to&", Arg, Name (Arg));
1916 -- Could use comments on what is going on here ???
1918 Get_First_Interp (Name (Arg), I, It);
1919 while Present (It.Nam) loop
1920 Error_Msg_Sloc := Sloc (It.Nam);
1922 if Nkind (Parent (It.Nam)) = N_Full_Type_Declaration then
1923 Error_Msg_N ("interpretation (inherited) #!", Arg);
1925 Error_Msg_N ("interpretation #!", Arg);
1928 Get_Next_Interp (I, It);
1931 end Report_Ambiguous_Argument;
1933 -----------------------
1934 -- Resolution_Failed --
1935 -----------------------
1937 procedure Resolution_Failed is
1939 Patch_Up_Value (N, Typ);
1941 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1942 Set_Is_Overloaded (N, False);
1944 -- The caller will return without calling the expander, so we need
1945 -- to set the analyzed flag. Note that it is fine to set Analyzed
1946 -- to True even if we are in the middle of a shallow analysis,
1947 -- (see the spec of sem for more details) since this is an error
1948 -- situation anyway, and there is no point in repeating the
1949 -- analysis later (indeed it won't work to repeat it later, since
1950 -- we haven't got a clear resolution of which entity is being
1953 Set_Analyzed (N, True);
1955 end Resolution_Failed;
1957 -- Start of processing for Resolve
1964 -- Access attribute on remote subprogram cannot be used for
1965 -- a non-remote access-to-subprogram type.
1967 if Nkind (N) = N_Attribute_Reference
1968 and then (Attribute_Name (N) = Name_Access
1969 or else Attribute_Name (N) = Name_Unrestricted_Access
1970 or else Attribute_Name (N) = Name_Unchecked_Access)
1971 and then Comes_From_Source (N)
1972 and then Is_Entity_Name (Prefix (N))
1973 and then Is_Subprogram (Entity (Prefix (N)))
1974 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1975 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1978 ("prefix must statically denote a non-remote subprogram", N);
1981 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1983 -- If the context is a Remote_Access_To_Subprogram, access attributes
1984 -- must be resolved with the corresponding fat pointer. There is no need
1985 -- to check for the attribute name since the return type of an
1986 -- attribute is never a remote type.
1988 if Nkind (N) = N_Attribute_Reference
1989 and then Comes_From_Source (N)
1990 and then (Is_Remote_Call_Interface (Typ)
1991 or else Is_Remote_Types (Typ))
1994 Attr : constant Attribute_Id :=
1995 Get_Attribute_Id (Attribute_Name (N));
1996 Pref : constant Node_Id := Prefix (N);
1999 Is_Remote : Boolean := True;
2002 -- Check that Typ is a remote access-to-subprogram type
2004 if Is_Remote_Access_To_Subprogram_Type (Typ) then
2006 -- Prefix (N) must statically denote a remote subprogram
2007 -- declared in a package specification.
2009 if Attr = Attribute_Access then
2010 Decl := Unit_Declaration_Node (Entity (Pref));
2012 if Nkind (Decl) = N_Subprogram_Body then
2013 Spec := Corresponding_Spec (Decl);
2015 if not No (Spec) then
2016 Decl := Unit_Declaration_Node (Spec);
2020 Spec := Parent (Decl);
2022 if not Is_Entity_Name (Prefix (N))
2023 or else Nkind (Spec) /= N_Package_Specification
2025 not Is_Remote_Call_Interface (Defining_Entity (Spec))
2029 ("prefix must statically denote a remote subprogram ",
2034 -- If we are generating code for a distributed program.
2035 -- perform semantic checks against the corresponding
2038 if (Attr = Attribute_Access
2039 or else Attr = Attribute_Unchecked_Access
2040 or else Attr = Attribute_Unrestricted_Access)
2041 and then Expander_Active
2042 and then Get_PCS_Name /= Name_No_DSA
2044 Check_Subtype_Conformant
2045 (New_Id => Entity (Prefix (N)),
2046 Old_Id => Designated_Type
2047 (Corresponding_Remote_Type (Typ)),
2051 Process_Remote_AST_Attribute (N, Typ);
2058 Debug_A_Entry ("resolving ", N);
2060 if Comes_From_Source (N) then
2061 if Is_Fixed_Point_Type (Typ) then
2062 Check_Restriction (No_Fixed_Point, N);
2064 elsif Is_Floating_Point_Type (Typ)
2065 and then Typ /= Universal_Real
2066 and then Typ /= Any_Real
2068 Check_Restriction (No_Floating_Point, N);
2072 -- Return if already analyzed
2074 if Analyzed (N) then
2075 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
2078 -- Return if type = Any_Type (previous error encountered)
2080 elsif Etype (N) = Any_Type then
2081 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
2085 Check_Parameterless_Call (N);
2087 -- If not overloaded, then we know the type, and all that needs doing
2088 -- is to check that this type is compatible with the context.
2090 if not Is_Overloaded (N) then
2091 Found := Covers (Typ, Etype (N));
2092 Expr_Type := Etype (N);
2094 -- In the overloaded case, we must select the interpretation that
2095 -- is compatible with the context (i.e. the type passed to Resolve)
2098 -- Loop through possible interpretations
2100 Get_First_Interp (N, I, It);
2101 Interp_Loop : while Present (It.Typ) loop
2103 -- We are only interested in interpretations that are compatible
2104 -- with the expected type, any other interpretations are ignored.
2106 if not Covers (Typ, It.Typ) then
2107 if Debug_Flag_V then
2108 Write_Str (" interpretation incompatible with context");
2113 -- Skip the current interpretation if it is disabled by an
2114 -- abstract operator. This action is performed only when the
2115 -- type against which we are resolving is the same as the
2116 -- type of the interpretation.
2118 if Ada_Version >= Ada_2005
2119 and then It.Typ = Typ
2120 and then Typ /= Universal_Integer
2121 and then Typ /= Universal_Real
2122 and then Present (It.Abstract_Op)
2127 -- First matching interpretation
2133 Expr_Type := It.Typ;
2135 -- Matching interpretation that is not the first, maybe an
2136 -- error, but there are some cases where preference rules are
2137 -- used to choose between the two possibilities. These and
2138 -- some more obscure cases are handled in Disambiguate.
2141 -- If the current statement is part of a predefined library
2142 -- unit, then all interpretations which come from user level
2143 -- packages should not be considered.
2146 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
2151 Error_Msg_Sloc := Sloc (Seen);
2152 It1 := Disambiguate (N, I1, I, Typ);
2154 -- Disambiguation has succeeded. Skip the remaining
2157 if It1 /= No_Interp then
2159 Expr_Type := It1.Typ;
2161 while Present (It.Typ) loop
2162 Get_Next_Interp (I, It);
2166 -- Before we issue an ambiguity complaint, check for
2167 -- the case of a subprogram call where at least one
2168 -- of the arguments is Any_Type, and if so, suppress
2169 -- the message, since it is a cascaded error.
2171 if Nkind_In (N, N_Function_Call,
2172 N_Procedure_Call_Statement)
2179 A := First_Actual (N);
2180 while Present (A) loop
2183 if Nkind (E) = N_Parameter_Association then
2184 E := Explicit_Actual_Parameter (E);
2187 if Etype (E) = Any_Type then
2188 if Debug_Flag_V then
2189 Write_Str ("Any_Type in call");
2200 elsif Nkind (N) in N_Binary_Op
2201 and then (Etype (Left_Opnd (N)) = Any_Type
2202 or else Etype (Right_Opnd (N)) = Any_Type)
2206 elsif Nkind (N) in N_Unary_Op
2207 and then Etype (Right_Opnd (N)) = Any_Type
2212 -- Not that special case, so issue message using the
2213 -- flag Ambiguous to control printing of the header
2214 -- message only at the start of an ambiguous set.
2216 if not Ambiguous then
2217 if Nkind (N) = N_Function_Call
2218 and then Nkind (Name (N)) = N_Explicit_Dereference
2221 ("ambiguous expression "
2222 & "(cannot resolve indirect call)!", N);
2224 Error_Msg_NE -- CODEFIX
2225 ("ambiguous expression (cannot resolve&)!",
2231 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2233 ("\\possible interpretation (inherited)#!", N);
2235 Error_Msg_N -- CODEFIX
2236 ("\\possible interpretation#!", N);
2240 (N, N_Procedure_Call_Statement, N_Function_Call)
2241 and then Present (Parameter_Associations (N))
2243 Report_Ambiguous_Argument;
2247 Error_Msg_Sloc := Sloc (It.Nam);
2249 -- By default, the error message refers to the candidate
2250 -- interpretation. But if it is a predefined operator, it
2251 -- is implicitly declared at the declaration of the type
2252 -- of the operand. Recover the sloc of that declaration
2253 -- for the error message.
2255 if Nkind (N) in N_Op
2256 and then Scope (It.Nam) = Standard_Standard
2257 and then not Is_Overloaded (Right_Opnd (N))
2258 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2261 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2263 if Comes_From_Source (Err_Type)
2264 and then Present (Parent (Err_Type))
2266 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2269 elsif Nkind (N) in N_Binary_Op
2270 and then Scope (It.Nam) = Standard_Standard
2271 and then not Is_Overloaded (Left_Opnd (N))
2272 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2275 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2277 if Comes_From_Source (Err_Type)
2278 and then Present (Parent (Err_Type))
2280 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2283 -- If this is an indirect call, use the subprogram_type
2284 -- in the message, to have a meaningful location.
2285 -- Also indicate if this is an inherited operation,
2286 -- created by a type declaration.
2288 elsif Nkind (N) = N_Function_Call
2289 and then Nkind (Name (N)) = N_Explicit_Dereference
2290 and then Is_Type (It.Nam)
2294 Sloc (Associated_Node_For_Itype (Err_Type));
2299 if Nkind (N) in N_Op
2300 and then Scope (It.Nam) = Standard_Standard
2301 and then Present (Err_Type)
2303 -- Special-case the message for universal_fixed
2304 -- operators, which are not declared with the type
2305 -- of the operand, but appear forever in Standard.
2307 if It.Typ = Universal_Fixed
2308 and then Scope (It.Nam) = Standard_Standard
2311 ("\\possible interpretation as " &
2312 "universal_fixed operation " &
2313 "(RM 4.5.5 (19))", N);
2316 ("\\possible interpretation (predefined)#!", N);
2320 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2323 ("\\possible interpretation (inherited)#!", N);
2325 Error_Msg_N -- CODEFIX
2326 ("\\possible interpretation#!", N);
2332 -- We have a matching interpretation, Expr_Type is the type
2333 -- from this interpretation, and Seen is the entity.
2335 -- For an operator, just set the entity name. The type will be
2336 -- set by the specific operator resolution routine.
2338 if Nkind (N) in N_Op then
2339 Set_Entity (N, Seen);
2340 Generate_Reference (Seen, N);
2342 elsif Nkind (N) = N_Case_Expression then
2343 Set_Etype (N, Expr_Type);
2345 elsif Nkind (N) = N_Character_Literal then
2346 Set_Etype (N, Expr_Type);
2348 elsif Nkind (N) = N_Conditional_Expression then
2349 Set_Etype (N, Expr_Type);
2351 -- For an explicit dereference, attribute reference, range,
2352 -- short-circuit form (which is not an operator node), or call
2353 -- with a name that is an explicit dereference, there is
2354 -- nothing to be done at this point.
2356 elsif Nkind_In (N, N_Explicit_Dereference,
2357 N_Attribute_Reference,
2359 N_Indexed_Component,
2362 N_Selected_Component,
2364 or else Nkind (Name (N)) = N_Explicit_Dereference
2368 -- For procedure or function calls, set the type of the name,
2369 -- and also the entity pointer for the prefix.
2371 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2372 and then Is_Entity_Name (Name (N))
2374 Set_Etype (Name (N), Expr_Type);
2375 Set_Entity (Name (N), Seen);
2376 Generate_Reference (Seen, Name (N));
2378 elsif Nkind (N) = N_Function_Call
2379 and then Nkind (Name (N)) = N_Selected_Component
2381 Set_Etype (Name (N), Expr_Type);
2382 Set_Entity (Selector_Name (Name (N)), Seen);
2383 Generate_Reference (Seen, Selector_Name (Name (N)));
2385 -- For all other cases, just set the type of the Name
2388 Set_Etype (Name (N), Expr_Type);
2395 -- Move to next interpretation
2397 exit Interp_Loop when No (It.Typ);
2399 Get_Next_Interp (I, It);
2400 end loop Interp_Loop;
2403 -- At this stage Found indicates whether or not an acceptable
2404 -- interpretation exists. If not, then we have an error, except that if
2405 -- the context is Any_Type as a result of some other error, then we
2406 -- suppress the error report.
2409 if Typ /= Any_Type then
2411 -- If type we are looking for is Void, then this is the procedure
2412 -- call case, and the error is simply that what we gave is not a
2413 -- procedure name (we think of procedure calls as expressions with
2414 -- types internally, but the user doesn't think of them this way!)
2416 if Typ = Standard_Void_Type then
2418 -- Special case message if function used as a procedure
2420 if Nkind (N) = N_Procedure_Call_Statement
2421 and then Is_Entity_Name (Name (N))
2422 and then Ekind (Entity (Name (N))) = E_Function
2425 ("cannot use function & in a procedure call",
2426 Name (N), Entity (Name (N)));
2428 -- Otherwise give general message (not clear what cases this
2429 -- covers, but no harm in providing for them!)
2432 Error_Msg_N ("expect procedure name in procedure call", N);
2437 -- Otherwise we do have a subexpression with the wrong type
2439 -- Check for the case of an allocator which uses an access type
2440 -- instead of the designated type. This is a common error and we
2441 -- specialize the message, posting an error on the operand of the
2442 -- allocator, complaining that we expected the designated type of
2445 elsif Nkind (N) = N_Allocator
2446 and then Ekind (Typ) in Access_Kind
2447 and then Ekind (Etype (N)) in Access_Kind
2448 and then Designated_Type (Etype (N)) = Typ
2450 Wrong_Type (Expression (N), Designated_Type (Typ));
2453 -- Check for view mismatch on Null in instances, for which the
2454 -- view-swapping mechanism has no identifier.
2456 elsif (In_Instance or else In_Inlined_Body)
2457 and then (Nkind (N) = N_Null)
2458 and then Is_Private_Type (Typ)
2459 and then Is_Access_Type (Full_View (Typ))
2461 Resolve (N, Full_View (Typ));
2465 -- Check for an aggregate. Sometimes we can get bogus aggregates
2466 -- from misuse of parentheses, and we are about to complain about
2467 -- the aggregate without even looking inside it.
2469 -- Instead, if we have an aggregate of type Any_Composite, then
2470 -- analyze and resolve the component fields, and then only issue
2471 -- another message if we get no errors doing this (otherwise
2472 -- assume that the errors in the aggregate caused the problem).
2474 elsif Nkind (N) = N_Aggregate
2475 and then Etype (N) = Any_Composite
2477 -- Disable expansion in any case. If there is a type mismatch
2478 -- it may be fatal to try to expand the aggregate. The flag
2479 -- would otherwise be set to false when the error is posted.
2481 Expander_Active := False;
2484 procedure Check_Aggr (Aggr : Node_Id);
2485 -- Check one aggregate, and set Found to True if we have a
2486 -- definite error in any of its elements
2488 procedure Check_Elmt (Aelmt : Node_Id);
2489 -- Check one element of aggregate and set Found to True if
2490 -- we definitely have an error in the element.
2496 procedure Check_Aggr (Aggr : Node_Id) is
2500 if Present (Expressions (Aggr)) then
2501 Elmt := First (Expressions (Aggr));
2502 while Present (Elmt) loop
2508 if Present (Component_Associations (Aggr)) then
2509 Elmt := First (Component_Associations (Aggr));
2510 while Present (Elmt) loop
2512 -- If this is a default-initialized component, then
2513 -- there is nothing to check. The box will be
2514 -- replaced by the appropriate call during late
2517 if not Box_Present (Elmt) then
2518 Check_Elmt (Expression (Elmt));
2530 procedure Check_Elmt (Aelmt : Node_Id) is
2532 -- If we have a nested aggregate, go inside it (to
2533 -- attempt a naked analyze-resolve of the aggregate
2534 -- can cause undesirable cascaded errors). Do not
2535 -- resolve expression if it needs a type from context,
2536 -- as for integer * fixed expression.
2538 if Nkind (Aelmt) = N_Aggregate then
2544 if not Is_Overloaded (Aelmt)
2545 and then Etype (Aelmt) /= Any_Fixed
2550 if Etype (Aelmt) = Any_Type then
2561 -- If an error message was issued already, Found got reset
2562 -- to True, so if it is still False, issue the standard
2563 -- Wrong_Type message.
2566 if Is_Overloaded (N)
2567 and then Nkind (N) = N_Function_Call
2570 Subp_Name : Node_Id;
2572 if Is_Entity_Name (Name (N)) then
2573 Subp_Name := Name (N);
2575 elsif Nkind (Name (N)) = N_Selected_Component then
2577 -- Protected operation: retrieve operation name
2579 Subp_Name := Selector_Name (Name (N));
2581 raise Program_Error;
2584 Error_Msg_Node_2 := Typ;
2585 Error_Msg_NE ("no visible interpretation of&" &
2586 " matches expected type&", N, Subp_Name);
2589 if All_Errors_Mode then
2591 Index : Interp_Index;
2595 Error_Msg_N ("\\possible interpretations:", N);
2597 Get_First_Interp (Name (N), Index, It);
2598 while Present (It.Nam) loop
2599 Error_Msg_Sloc := Sloc (It.Nam);
2600 Error_Msg_Node_2 := It.Nam;
2602 ("\\ type& for & declared#", N, It.Typ);
2603 Get_Next_Interp (Index, It);
2608 Error_Msg_N ("\use -gnatf for details", N);
2611 Wrong_Type (N, Typ);
2619 -- Test if we have more than one interpretation for the context
2621 elsif Ambiguous then
2625 -- Here we have an acceptable interpretation for the context
2628 -- Propagate type information and normalize tree for various
2629 -- predefined operations. If the context only imposes a class of
2630 -- types, rather than a specific type, propagate the actual type
2633 if Typ = Any_Integer
2634 or else Typ = Any_Boolean
2635 or else Typ = Any_Modular
2636 or else Typ = Any_Real
2637 or else Typ = Any_Discrete
2639 Ctx_Type := Expr_Type;
2641 -- Any_Fixed is legal in a real context only if a specific
2642 -- fixed point type is imposed. If Norman Cohen can be
2643 -- confused by this, it deserves a separate message.
2646 and then Expr_Type = Any_Fixed
2648 Error_Msg_N ("illegal context for mixed mode operation", N);
2649 Set_Etype (N, Universal_Real);
2650 Ctx_Type := Universal_Real;
2654 -- A user-defined operator is transformed into a function call at
2655 -- this point, so that further processing knows that operators are
2656 -- really operators (i.e. are predefined operators). User-defined
2657 -- operators that are intrinsic are just renamings of the predefined
2658 -- ones, and need not be turned into calls either, but if they rename
2659 -- a different operator, we must transform the node accordingly.
2660 -- Instantiations of Unchecked_Conversion are intrinsic but are
2661 -- treated as functions, even if given an operator designator.
2663 if Nkind (N) in N_Op
2664 and then Present (Entity (N))
2665 and then Ekind (Entity (N)) /= E_Operator
2668 if not Is_Predefined_Op (Entity (N)) then
2669 Rewrite_Operator_As_Call (N, Entity (N));
2671 elsif Present (Alias (Entity (N)))
2673 Nkind (Parent (Parent (Entity (N)))) =
2674 N_Subprogram_Renaming_Declaration
2676 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2678 -- If the node is rewritten, it will be fully resolved in
2679 -- Rewrite_Renamed_Operator.
2681 if Analyzed (N) then
2687 case N_Subexpr'(Nkind (N)) is
2689 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2691 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2693 when N_Short_Circuit
2694 => Resolve_Short_Circuit (N, Ctx_Type);
2696 when N_Attribute_Reference
2697 => Resolve_Attribute (N, Ctx_Type);
2699 when N_Case_Expression
2700 => Resolve_Case_Expression (N, Ctx_Type);
2702 when N_Character_Literal
2703 => Resolve_Character_Literal (N, Ctx_Type);
2705 when N_Conditional_Expression
2706 => Resolve_Conditional_Expression (N, Ctx_Type);
2708 when N_Expanded_Name
2709 => Resolve_Entity_Name (N, Ctx_Type);
2711 when N_Explicit_Dereference
2712 => Resolve_Explicit_Dereference (N, Ctx_Type);
2714 when N_Expression_With_Actions
2715 => Resolve_Expression_With_Actions (N, Ctx_Type);
2717 when N_Extension_Aggregate
2718 => Resolve_Extension_Aggregate (N, Ctx_Type);
2720 when N_Function_Call
2721 => Resolve_Call (N, Ctx_Type);
2724 => Resolve_Entity_Name (N, Ctx_Type);
2726 when N_Indexed_Component
2727 => Resolve_Indexed_Component (N, Ctx_Type);
2729 when N_Integer_Literal
2730 => Resolve_Integer_Literal (N, Ctx_Type);
2732 when N_Membership_Test
2733 => Resolve_Membership_Op (N, Ctx_Type);
2735 when N_Null => Resolve_Null (N, Ctx_Type);
2737 when N_Op_And | N_Op_Or | N_Op_Xor
2738 => Resolve_Logical_Op (N, Ctx_Type);
2740 when N_Op_Eq | N_Op_Ne
2741 => Resolve_Equality_Op (N, Ctx_Type);
2743 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2744 => Resolve_Comparison_Op (N, Ctx_Type);
2746 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2748 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2749 N_Op_Divide | N_Op_Mod | N_Op_Rem
2751 => Resolve_Arithmetic_Op (N, Ctx_Type);
2753 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2755 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2757 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2758 => Resolve_Unary_Op (N, Ctx_Type);
2760 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2762 when N_Procedure_Call_Statement
2763 => Resolve_Call (N, Ctx_Type);
2765 when N_Operator_Symbol
2766 => Resolve_Operator_Symbol (N, Ctx_Type);
2768 when N_Qualified_Expression
2769 => Resolve_Qualified_Expression (N, Ctx_Type);
2771 when N_Quantified_Expression
2772 => Resolve_Quantified_Expression (N, Ctx_Type);
2774 when N_Raise_xxx_Error
2775 => Set_Etype (N, Ctx_Type);
2777 when N_Range => Resolve_Range (N, Ctx_Type);
2780 => Resolve_Real_Literal (N, Ctx_Type);
2782 when N_Reference => Resolve_Reference (N, Ctx_Type);
2784 when N_Selected_Component
2785 => Resolve_Selected_Component (N, Ctx_Type);
2787 when N_Slice => Resolve_Slice (N, Ctx_Type);
2789 when N_String_Literal
2790 => Resolve_String_Literal (N, Ctx_Type);
2792 when N_Subprogram_Info
2793 => Resolve_Subprogram_Info (N, Ctx_Type);
2795 when N_Type_Conversion
2796 => Resolve_Type_Conversion (N, Ctx_Type);
2798 when N_Unchecked_Expression =>
2799 Resolve_Unchecked_Expression (N, Ctx_Type);
2801 when N_Unchecked_Type_Conversion =>
2802 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2805 -- If the subexpression was replaced by a non-subexpression, then
2806 -- all we do is to expand it. The only legitimate case we know of
2807 -- is converting procedure call statement to entry call statements,
2808 -- but there may be others, so we are making this test general.
2810 if Nkind (N) not in N_Subexpr then
2811 Debug_A_Exit ("resolving ", N, " (done)");
2816 -- AI05-144-2: Check dangerous order dependence within an expression
2817 -- that is not a subexpression. Exclude RHS of an assignment, because
2818 -- both sides may have side-effects and the check must be performed
2819 -- over the statement.
2821 if Nkind (Parent (N)) not in N_Subexpr
2822 and then Nkind (Parent (N)) /= N_Assignment_Statement
2823 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2825 Check_Order_Dependence;
2828 -- The expression is definitely NOT overloaded at this point, so
2829 -- we reset the Is_Overloaded flag to avoid any confusion when
2830 -- reanalyzing the node.
2832 Set_Is_Overloaded (N, False);
2834 -- Freeze expression type, entity if it is a name, and designated
2835 -- type if it is an allocator (RM 13.14(10,11,13)).
2837 -- Now that the resolution of the type of the node is complete,
2838 -- and we did not detect an error, we can expand this node. We
2839 -- skip the expand call if we are in a default expression, see
2840 -- section "Handling of Default Expressions" in Sem spec.
2842 Debug_A_Exit ("resolving ", N, " (done)");
2844 -- We unconditionally freeze the expression, even if we are in
2845 -- default expression mode (the Freeze_Expression routine tests
2846 -- this flag and only freezes static types if it is set).
2848 Freeze_Expression (N);
2850 -- Now we can do the expansion
2860 -- Version with check(s) suppressed
2862 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2864 if Suppress = All_Checks then
2866 Svg : constant Suppress_Array := Scope_Suppress;
2868 Scope_Suppress := (others => True);
2870 Scope_Suppress := Svg;
2875 Svg : constant Boolean := Scope_Suppress (Suppress);
2877 Scope_Suppress (Suppress) := True;
2879 Scope_Suppress (Suppress) := Svg;
2888 -- Version with implicit type
2890 procedure Resolve (N : Node_Id) is
2892 Resolve (N, Etype (N));
2895 ---------------------
2896 -- Resolve_Actuals --
2897 ---------------------
2899 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2900 Loc : constant Source_Ptr := Sloc (N);
2905 Prev : Node_Id := Empty;
2908 procedure Check_Argument_Order;
2909 -- Performs a check for the case where the actuals are all simple
2910 -- identifiers that correspond to the formal names, but in the wrong
2911 -- order, which is considered suspicious and cause for a warning.
2913 procedure Check_Prefixed_Call;
2914 -- If the original node is an overloaded call in prefix notation,
2915 -- insert an 'Access or a dereference as needed over the first actual.
2916 -- Try_Object_Operation has already verified that there is a valid
2917 -- interpretation, but the form of the actual can only be determined
2918 -- once the primitive operation is identified.
2920 procedure Insert_Default;
2921 -- If the actual is missing in a call, insert in the actuals list
2922 -- an instance of the default expression. The insertion is always
2923 -- a named association.
2925 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2926 -- Check whether T1 and T2, or their full views, are derived from a
2927 -- common type. Used to enforce the restrictions on array conversions
2930 function Static_Concatenation (N : Node_Id) return Boolean;
2931 -- Predicate to determine whether an actual that is a concatenation
2932 -- will be evaluated statically and does not need a transient scope.
2933 -- This must be determined before the actual is resolved and expanded
2934 -- because if needed the transient scope must be introduced earlier.
2936 --------------------------
2937 -- Check_Argument_Order --
2938 --------------------------
2940 procedure Check_Argument_Order is
2942 -- Nothing to do if no parameters, or original node is neither a
2943 -- function call nor a procedure call statement (happens in the
2944 -- operator-transformed-to-function call case), or the call does
2945 -- not come from source, or this warning is off.
2947 if not Warn_On_Parameter_Order
2949 No (Parameter_Associations (N))
2951 not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2954 not Comes_From_Source (N)
2960 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2963 -- Nothing to do if only one parameter
2969 -- Here if at least two arguments
2972 Actuals : array (1 .. Nargs) of Node_Id;
2976 Wrong_Order : Boolean := False;
2977 -- Set True if an out of order case is found
2980 -- Collect identifier names of actuals, fail if any actual is
2981 -- not a simple identifier, and record max length of name.
2983 Actual := First (Parameter_Associations (N));
2984 for J in Actuals'Range loop
2985 if Nkind (Actual) /= N_Identifier then
2988 Actuals (J) := Actual;
2993 -- If we got this far, all actuals are identifiers and the list
2994 -- of their names is stored in the Actuals array.
2996 Formal := First_Formal (Nam);
2997 for J in Actuals'Range loop
2999 -- If we ran out of formals, that's odd, probably an error
3000 -- which will be detected elsewhere, but abandon the search.
3006 -- If name matches and is in order OK
3008 if Chars (Formal) = Chars (Actuals (J)) then
3012 -- If no match, see if it is elsewhere in list and if so
3013 -- flag potential wrong order if type is compatible.
3015 for K in Actuals'Range loop
3016 if Chars (Formal) = Chars (Actuals (K))
3018 Has_Compatible_Type (Actuals (K), Etype (Formal))
3020 Wrong_Order := True;
3030 <<Continue>> Next_Formal (Formal);
3033 -- If Formals left over, also probably an error, skip warning
3035 if Present (Formal) then
3039 -- Here we give the warning if something was out of order
3043 ("actuals for this call may be in wrong order?", N);
3047 end Check_Argument_Order;
3049 -------------------------
3050 -- Check_Prefixed_Call --
3051 -------------------------
3053 procedure Check_Prefixed_Call is
3054 Act : constant Node_Id := First_Actual (N);
3055 A_Type : constant Entity_Id := Etype (Act);
3056 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
3057 Orig : constant Node_Id := Original_Node (N);
3061 -- Check whether the call is a prefixed call, with or without
3062 -- additional actuals.
3064 if Nkind (Orig) = N_Selected_Component
3066 (Nkind (Orig) = N_Indexed_Component
3067 and then Nkind (Prefix (Orig)) = N_Selected_Component
3068 and then Is_Entity_Name (Prefix (Prefix (Orig)))
3069 and then Is_Entity_Name (Act)
3070 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
3072 if Is_Access_Type (A_Type)
3073 and then not Is_Access_Type (F_Type)
3075 -- Introduce dereference on object in prefix
3078 Make_Explicit_Dereference (Sloc (Act),
3079 Prefix => Relocate_Node (Act));
3080 Rewrite (Act, New_A);
3083 elsif Is_Access_Type (F_Type)
3084 and then not Is_Access_Type (A_Type)
3086 -- Introduce an implicit 'Access in prefix
3088 if not Is_Aliased_View (Act) then
3090 ("object in prefixed call to& must be aliased"
3091 & " (RM-2005 4.3.1 (13))",
3096 Make_Attribute_Reference (Loc,
3097 Attribute_Name => Name_Access,
3098 Prefix => Relocate_Node (Act)));
3103 end Check_Prefixed_Call;
3105 --------------------
3106 -- Insert_Default --
3107 --------------------
3109 procedure Insert_Default is
3114 -- Missing argument in call, nothing to insert
3116 if No (Default_Value (F)) then
3120 -- Note that we do a full New_Copy_Tree, so that any associated
3121 -- Itypes are properly copied. This may not be needed any more,
3122 -- but it does no harm as a safety measure! Defaults of a generic
3123 -- formal may be out of bounds of the corresponding actual (see
3124 -- cc1311b) and an additional check may be required.
3129 New_Scope => Current_Scope,
3132 if Is_Concurrent_Type (Scope (Nam))
3133 and then Has_Discriminants (Scope (Nam))
3135 Replace_Actual_Discriminants (N, Actval);
3138 if Is_Overloadable (Nam)
3139 and then Present (Alias (Nam))
3141 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
3142 and then not Is_Tagged_Type (Etype (F))
3144 -- If default is a real literal, do not introduce a
3145 -- conversion whose effect may depend on the run-time
3146 -- size of universal real.
3148 if Nkind (Actval) = N_Real_Literal then
3149 Set_Etype (Actval, Base_Type (Etype (F)));
3151 Actval := Unchecked_Convert_To (Etype (F), Actval);
3155 if Is_Scalar_Type (Etype (F)) then
3156 Enable_Range_Check (Actval);
3159 Set_Parent (Actval, N);
3161 -- Resolve aggregates with their base type, to avoid scope
3162 -- anomalies: the subtype was first built in the subprogram
3163 -- declaration, and the current call may be nested.
3165 if Nkind (Actval) = N_Aggregate then
3166 Analyze_And_Resolve (Actval, Etype (F));
3168 Analyze_And_Resolve (Actval, Etype (Actval));
3172 Set_Parent (Actval, N);
3174 -- See note above concerning aggregates
3176 if Nkind (Actval) = N_Aggregate
3177 and then Has_Discriminants (Etype (Actval))
3179 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
3181 -- Resolve entities with their own type, which may differ
3182 -- from the type of a reference in a generic context (the
3183 -- view swapping mechanism did not anticipate the re-analysis
3184 -- of default values in calls).
3186 elsif Is_Entity_Name (Actval) then
3187 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
3190 Analyze_And_Resolve (Actval, Etype (Actval));
3194 -- If default is a tag indeterminate function call, propagate
3195 -- tag to obtain proper dispatching.
3197 if Is_Controlling_Formal (F)
3198 and then Nkind (Default_Value (F)) = N_Function_Call
3200 Set_Is_Controlling_Actual (Actval);
3205 -- If the default expression raises constraint error, then just
3206 -- silently replace it with an N_Raise_Constraint_Error node,
3207 -- since we already gave the warning on the subprogram spec.
3208 -- If node is already a Raise_Constraint_Error leave as is, to
3209 -- prevent loops in the warnings removal machinery.
3211 if Raises_Constraint_Error (Actval)
3212 and then Nkind (Actval) /= N_Raise_Constraint_Error
3215 Make_Raise_Constraint_Error (Loc,
3216 Reason => CE_Range_Check_Failed));
3217 Set_Raises_Constraint_Error (Actval);
3218 Set_Etype (Actval, Etype (F));
3222 Make_Parameter_Association (Loc,
3223 Explicit_Actual_Parameter => Actval,
3224 Selector_Name => Make_Identifier (Loc, Chars (F)));
3226 -- Case of insertion is first named actual
3228 if No (Prev) or else
3229 Nkind (Parent (Prev)) /= N_Parameter_Association
3231 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
3232 Set_First_Named_Actual (N, Actval);
3235 if No (Parameter_Associations (N)) then
3236 Set_Parameter_Associations (N, New_List (Assoc));
3238 Append (Assoc, Parameter_Associations (N));
3242 Insert_After (Prev, Assoc);
3245 -- Case of insertion is not first named actual
3248 Set_Next_Named_Actual
3249 (Assoc, Next_Named_Actual (Parent (Prev)));
3250 Set_Next_Named_Actual (Parent (Prev), Actval);
3251 Append (Assoc, Parameter_Associations (N));
3254 Mark_Rewrite_Insertion (Assoc);
3255 Mark_Rewrite_Insertion (Actval);
3264 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
3265 FT1 : Entity_Id := T1;
3266 FT2 : Entity_Id := T2;
3269 if Is_Private_Type (T1)
3270 and then Present (Full_View (T1))
3272 FT1 := Full_View (T1);
3275 if Is_Private_Type (T2)
3276 and then Present (Full_View (T2))
3278 FT2 := Full_View (T2);
3281 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3284 --------------------------
3285 -- Static_Concatenation --
3286 --------------------------
3288 function Static_Concatenation (N : Node_Id) return Boolean is
3291 when N_String_Literal =>
3296 -- Concatenation is static when both operands are static
3297 -- and the concatenation operator is a predefined one.
3299 return Scope (Entity (N)) = Standard_Standard
3301 Static_Concatenation (Left_Opnd (N))
3303 Static_Concatenation (Right_Opnd (N));
3306 if Is_Entity_Name (N) then
3308 Ent : constant Entity_Id := Entity (N);
3310 return Ekind (Ent) = E_Constant
3311 and then Present (Constant_Value (Ent))
3313 Is_Static_Expression (Constant_Value (Ent));
3320 end Static_Concatenation;
3322 -- Start of processing for Resolve_Actuals
3325 Check_Argument_Order;
3327 if Present (First_Actual (N)) then
3328 Check_Prefixed_Call;
3331 A := First_Actual (N);
3332 F := First_Formal (Nam);
3333 while Present (F) loop
3334 if No (A) and then Needs_No_Actuals (Nam) then
3337 -- If we have an error in any actual or formal, indicated by a type
3338 -- of Any_Type, then abandon resolution attempt, and set result type
3341 elsif (Present (A) and then Etype (A) = Any_Type)
3342 or else Etype (F) = Any_Type
3344 Set_Etype (N, Any_Type);
3348 -- Case where actual is present
3350 -- If the actual is an entity, generate a reference to it now. We
3351 -- do this before the actual is resolved, because a formal of some
3352 -- protected subprogram, or a task discriminant, will be rewritten
3353 -- during expansion, and the reference to the source entity may
3357 and then Is_Entity_Name (A)
3358 and then Comes_From_Source (N)
3360 Orig_A := Entity (A);
3362 if Present (Orig_A) then
3363 if Is_Formal (Orig_A)
3364 and then Ekind (F) /= E_In_Parameter
3366 Generate_Reference (Orig_A, A, 'm');
3367 elsif not Is_Overloaded (A) then
3368 Generate_Reference (Orig_A, A);
3374 and then (Nkind (Parent (A)) /= N_Parameter_Association
3376 Chars (Selector_Name (Parent (A))) = Chars (F))
3378 -- If style checking mode on, check match of formal name
3381 if Nkind (Parent (A)) = N_Parameter_Association then
3382 Check_Identifier (Selector_Name (Parent (A)), F);
3386 -- If the formal is Out or In_Out, do not resolve and expand the
3387 -- conversion, because it is subsequently expanded into explicit
3388 -- temporaries and assignments. However, the object of the
3389 -- conversion can be resolved. An exception is the case of tagged
3390 -- type conversion with a class-wide actual. In that case we want
3391 -- the tag check to occur and no temporary will be needed (no
3392 -- representation change can occur) and the parameter is passed by
3393 -- reference, so we go ahead and resolve the type conversion.
3394 -- Another exception is the case of reference to component or
3395 -- subcomponent of a bit-packed array, in which case we want to
3396 -- defer expansion to the point the in and out assignments are
3399 if Ekind (F) /= E_In_Parameter
3400 and then Nkind (A) = N_Type_Conversion
3401 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3403 if Ekind (F) = E_In_Out_Parameter
3404 and then Is_Array_Type (Etype (F))
3406 -- In a view conversion, the conversion must be legal in
3407 -- both directions, and thus both component types must be
3408 -- aliased, or neither (4.6 (8)).
3410 -- The extra rule in 4.6 (24.9.2) seems unduly restrictive:
3411 -- the privacy requirement should not apply to generic
3412 -- types, and should be checked in an instance. ARG query
3415 if Has_Aliased_Components (Etype (Expression (A))) /=
3416 Has_Aliased_Components (Etype (F))
3419 ("both component types in a view conversion must be"
3420 & " aliased, or neither", A);
3422 -- Comment here??? what set of cases???
3425 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3427 -- Check view conv between unrelated by ref array types
3429 if Is_By_Reference_Type (Etype (F))
3430 or else Is_By_Reference_Type (Etype (Expression (A)))
3433 ("view conversion between unrelated by reference " &
3434 "array types not allowed (\'A'I-00246)", A);
3436 -- In Ada 2005 mode, check view conversion component
3437 -- type cannot be private, tagged, or volatile. Note
3438 -- that we only apply this to source conversions. The
3439 -- generated code can contain conversions which are
3440 -- not subject to this test, and we cannot extract the
3441 -- component type in such cases since it is not present.
3443 elsif Comes_From_Source (A)
3444 and then Ada_Version >= Ada_2005
3447 Comp_Type : constant Entity_Id :=
3449 (Etype (Expression (A)));
3451 if (Is_Private_Type (Comp_Type)
3452 and then not Is_Generic_Type (Comp_Type))
3453 or else Is_Tagged_Type (Comp_Type)
3454 or else Is_Volatile (Comp_Type)
3457 ("component type of a view conversion cannot"
3458 & " be private, tagged, or volatile"
3467 -- Resolve expression if conversion is all OK
3469 if (Conversion_OK (A)
3470 or else Valid_Conversion (A, Etype (A), Expression (A)))
3471 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3473 Resolve (Expression (A));
3476 -- If the actual is a function call that returns a limited
3477 -- unconstrained object that needs finalization, create a
3478 -- transient scope for it, so that it can receive the proper
3479 -- finalization list.
3481 elsif Nkind (A) = N_Function_Call
3482 and then Is_Limited_Record (Etype (F))
3483 and then not Is_Constrained (Etype (F))
3484 and then Expander_Active
3486 (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3488 Establish_Transient_Scope (A, False);
3490 -- A small optimization: if one of the actuals is a concatenation
3491 -- create a block around a procedure call to recover stack space.
3492 -- This alleviates stack usage when several procedure calls in
3493 -- the same statement list use concatenation. We do not perform
3494 -- this wrapping for code statements, where the argument is a
3495 -- static string, and we want to preserve warnings involving
3496 -- sequences of such statements.
3498 elsif Nkind (A) = N_Op_Concat
3499 and then Nkind (N) = N_Procedure_Call_Statement
3500 and then Expander_Active
3502 not (Is_Intrinsic_Subprogram (Nam)
3503 and then Chars (Nam) = Name_Asm)
3504 and then not Static_Concatenation (A)
3506 Establish_Transient_Scope (A, False);
3507 Resolve (A, Etype (F));
3510 if Nkind (A) = N_Type_Conversion
3511 and then Is_Array_Type (Etype (F))
3512 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3514 (Is_Limited_Type (Etype (F))
3515 or else Is_Limited_Type (Etype (Expression (A))))
3518 ("conversion between unrelated limited array types " &
3519 "not allowed (\A\I-00246)", A);
3521 if Is_Limited_Type (Etype (F)) then
3522 Explain_Limited_Type (Etype (F), A);
3525 if Is_Limited_Type (Etype (Expression (A))) then
3526 Explain_Limited_Type (Etype (Expression (A)), A);
3530 -- (Ada 2005: AI-251): If the actual is an allocator whose
3531 -- directly designated type is a class-wide interface, we build
3532 -- an anonymous access type to use it as the type of the
3533 -- allocator. Later, when the subprogram call is expanded, if
3534 -- the interface has a secondary dispatch table the expander
3535 -- will add a type conversion to force the correct displacement
3538 if Nkind (A) = N_Allocator then
3540 DDT : constant Entity_Id :=
3541 Directly_Designated_Type (Base_Type (Etype (F)));
3543 New_Itype : Entity_Id;
3546 if Is_Class_Wide_Type (DDT)
3547 and then Is_Interface (DDT)
3549 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3550 Set_Etype (New_Itype, Etype (A));
3551 Set_Directly_Designated_Type (New_Itype,
3552 Directly_Designated_Type (Etype (A)));
3553 Set_Etype (A, New_Itype);
3556 -- Ada 2005, AI-162:If the actual is an allocator, the
3557 -- innermost enclosing statement is the master of the
3558 -- created object. This needs to be done with expansion
3559 -- enabled only, otherwise the transient scope will not
3560 -- be removed in the expansion of the wrapped construct.
3562 if (Is_Controlled (DDT) or else Has_Task (DDT))
3563 and then Expander_Active
3565 Establish_Transient_Scope (A, False);
3570 -- (Ada 2005): The call may be to a primitive operation of
3571 -- a tagged synchronized type, declared outside of the type.
3572 -- In this case the controlling actual must be converted to
3573 -- its corresponding record type, which is the formal type.
3574 -- The actual may be a subtype, either because of a constraint
3575 -- or because it is a generic actual, so use base type to
3576 -- locate concurrent type.
3578 A_Typ := Base_Type (Etype (A));
3579 F_Typ := Base_Type (Etype (F));
3582 Full_A_Typ : Entity_Id;
3585 if Present (Full_View (A_Typ)) then
3586 Full_A_Typ := Base_Type (Full_View (A_Typ));
3588 Full_A_Typ := A_Typ;
3591 -- Tagged synchronized type (case 1): the actual is a
3594 if Is_Concurrent_Type (A_Typ)
3595 and then Corresponding_Record_Type (A_Typ) = F_Typ
3598 Unchecked_Convert_To
3599 (Corresponding_Record_Type (A_Typ), A));
3600 Resolve (A, Etype (F));
3602 -- Tagged synchronized type (case 2): the formal is a
3605 elsif Ekind (Full_A_Typ) = E_Record_Type
3607 (Corresponding_Concurrent_Type (Full_A_Typ))
3608 and then Is_Concurrent_Type (F_Typ)
3609 and then Present (Corresponding_Record_Type (F_Typ))
3610 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3612 Resolve (A, Corresponding_Record_Type (F_Typ));
3617 Resolve (A, Etype (F));
3625 -- In SPARK or ALFA, the only view conversions are those involving
3626 -- ancestor conversion of an extended type.
3628 if Formal_Verification_Mode
3629 and then Comes_From_Source (Original_Node (A))
3630 and then Nkind (A) = N_Type_Conversion
3631 and then Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter)
3634 Operand : constant Node_Id := Expression (A);
3635 Operand_Typ : constant Entity_Id := Etype (Operand);
3636 Target_Typ : constant Entity_Id := A_Typ;
3638 if not (Is_Tagged_Type (Target_Typ)
3639 and then not Is_Class_Wide_Type (Target_Typ)
3640 and then Is_Tagged_Type (Operand_Typ)
3641 and then not Is_Class_Wide_Type (Operand_Typ)
3642 and then Is_Ancestor (Target_Typ, Operand_Typ))
3644 Error_Msg_F ("|~~ancestor conversion is the only "
3645 & "view conversion", A);
3650 -- Save actual for subsequent check on order dependence, and
3651 -- indicate whether actual is modifiable. For AI05-0144-2.
3653 Save_Actual (A, Ekind (F) /= E_In_Parameter);
3655 -- For mode IN, if actual is an entity, and the type of the formal
3656 -- has warnings suppressed, then we reset Never_Set_In_Source for
3657 -- the calling entity. The reason for this is to catch cases like
3658 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3659 -- uses trickery to modify an IN parameter.
3661 if Ekind (F) = E_In_Parameter
3662 and then Is_Entity_Name (A)
3663 and then Present (Entity (A))
3664 and then Ekind (Entity (A)) = E_Variable
3665 and then Has_Warnings_Off (F_Typ)
3667 Set_Never_Set_In_Source (Entity (A), False);
3670 -- Perform error checks for IN and IN OUT parameters
3672 if Ekind (F) /= E_Out_Parameter then
3674 -- Check unset reference. For scalar parameters, it is clearly
3675 -- wrong to pass an uninitialized value as either an IN or
3676 -- IN-OUT parameter. For composites, it is also clearly an
3677 -- error to pass a completely uninitialized value as an IN
3678 -- parameter, but the case of IN OUT is trickier. We prefer
3679 -- not to give a warning here. For example, suppose there is
3680 -- a routine that sets some component of a record to False.
3681 -- It is perfectly reasonable to make this IN-OUT and allow
3682 -- either initialized or uninitialized records to be passed
3685 -- For partially initialized composite values, we also avoid
3686 -- warnings, since it is quite likely that we are passing a
3687 -- partially initialized value and only the initialized fields
3688 -- will in fact be read in the subprogram.
3690 if Is_Scalar_Type (A_Typ)
3691 or else (Ekind (F) = E_In_Parameter
3692 and then not Is_Partially_Initialized_Type (A_Typ))
3694 Check_Unset_Reference (A);
3697 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3698 -- actual to a nested call, since this is case of reading an
3699 -- out parameter, which is not allowed.
3701 if Ada_Version = Ada_83
3702 and then Is_Entity_Name (A)
3703 and then Ekind (Entity (A)) = E_Out_Parameter
3705 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3709 -- Case of OUT or IN OUT parameter
3711 if Ekind (F) /= E_In_Parameter then
3713 -- For an Out parameter, check for useless assignment. Note
3714 -- that we can't set Last_Assignment this early, because we may
3715 -- kill current values in Resolve_Call, and that call would
3716 -- clobber the Last_Assignment field.
3718 -- Note: call Warn_On_Useless_Assignment before doing the check
3719 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3720 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3721 -- reflects the last assignment, not this one!
3723 if Ekind (F) = E_Out_Parameter then
3724 if Warn_On_Modified_As_Out_Parameter (F)
3725 and then Is_Entity_Name (A)
3726 and then Present (Entity (A))
3727 and then Comes_From_Source (N)
3729 Warn_On_Useless_Assignment (Entity (A), A);
3733 -- Validate the form of the actual. Note that the call to
3734 -- Is_OK_Variable_For_Out_Formal generates the required
3735 -- reference in this case.
3737 if not Is_OK_Variable_For_Out_Formal (A) then
3738 Error_Msg_NE ("actual for& must be a variable", A, F);
3741 -- What's the following about???
3743 if Is_Entity_Name (A) then
3744 Kill_Checks (Entity (A));
3750 if Etype (A) = Any_Type then
3751 Set_Etype (N, Any_Type);
3755 -- Apply appropriate range checks for in, out, and in-out
3756 -- parameters. Out and in-out parameters also need a separate
3757 -- check, if there is a type conversion, to make sure the return
3758 -- value meets the constraints of the variable before the
3761 -- Gigi looks at the check flag and uses the appropriate types.
3762 -- For now since one flag is used there is an optimization which
3763 -- might not be done in the In Out case since Gigi does not do
3764 -- any analysis. More thought required about this ???
3766 if Ekind_In (F, E_In_Parameter, E_In_Out_Parameter) then
3768 -- Apply predicate checks, unless this is a call to the
3769 -- predicate check function itself, which would cause an
3770 -- infinite recursion.
3772 if not (Ekind (Nam) = E_Function
3773 and then Has_Predicates (Nam))
3775 Apply_Predicate_Check (A, F_Typ);
3778 -- Apply required constraint checks
3780 if Is_Scalar_Type (Etype (A)) then
3781 Apply_Scalar_Range_Check (A, F_Typ);
3783 elsif Is_Array_Type (Etype (A)) then
3784 Apply_Length_Check (A, F_Typ);
3786 elsif Is_Record_Type (F_Typ)
3787 and then Has_Discriminants (F_Typ)
3788 and then Is_Constrained (F_Typ)
3789 and then (not Is_Derived_Type (F_Typ)
3790 or else Comes_From_Source (Nam))
3792 Apply_Discriminant_Check (A, F_Typ);
3794 elsif Is_Access_Type (F_Typ)
3795 and then Is_Array_Type (Designated_Type (F_Typ))
3796 and then Is_Constrained (Designated_Type (F_Typ))
3798 Apply_Length_Check (A, F_Typ);
3800 elsif Is_Access_Type (F_Typ)
3801 and then Has_Discriminants (Designated_Type (F_Typ))
3802 and then Is_Constrained (Designated_Type (F_Typ))
3804 Apply_Discriminant_Check (A, F_Typ);
3807 Apply_Range_Check (A, F_Typ);
3810 -- Ada 2005 (AI-231): Note that the controlling parameter case
3811 -- already existed in Ada 95, which is partially checked
3812 -- elsewhere (see Checks), and we don't want the warning
3813 -- message to differ.
3815 if Is_Access_Type (F_Typ)
3816 and then Can_Never_Be_Null (F_Typ)
3817 and then Known_Null (A)
3819 if Is_Controlling_Formal (F) then
3820 Apply_Compile_Time_Constraint_Error
3822 Msg => "null value not allowed here?",
3823 Reason => CE_Access_Check_Failed);
3825 elsif Ada_Version >= Ada_2005 then
3826 Apply_Compile_Time_Constraint_Error
3828 Msg => "(Ada 2005) null not allowed in "
3829 & "null-excluding formal?",
3830 Reason => CE_Null_Not_Allowed);
3835 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter) then
3836 if Nkind (A) = N_Type_Conversion then
3837 if Is_Scalar_Type (A_Typ) then
3838 Apply_Scalar_Range_Check
3839 (Expression (A), Etype (Expression (A)), A_Typ);
3842 (Expression (A), Etype (Expression (A)), A_Typ);
3846 if Is_Scalar_Type (F_Typ) then
3847 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3849 elsif Is_Array_Type (F_Typ)
3850 and then Ekind (F) = E_Out_Parameter
3852 Apply_Length_Check (A, F_Typ);
3855 Apply_Range_Check (A, A_Typ, F_Typ);
3860 -- An actual associated with an access parameter is implicitly
3861 -- converted to the anonymous access type of the formal and must
3862 -- satisfy the legality checks for access conversions.
3864 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3865 if not Valid_Conversion (A, F_Typ, A) then
3867 ("invalid implicit conversion for access parameter", A);
3871 -- Check bad case of atomic/volatile argument (RM C.6(12))
3873 if Is_By_Reference_Type (Etype (F))
3874 and then Comes_From_Source (N)
3876 if Is_Atomic_Object (A)
3877 and then not Is_Atomic (Etype (F))
3880 ("cannot pass atomic argument to non-atomic formal",
3883 elsif Is_Volatile_Object (A)
3884 and then not Is_Volatile (Etype (F))
3887 ("cannot pass volatile argument to non-volatile formal",
3892 -- Check that subprograms don't have improper controlling
3893 -- arguments (RM 3.9.2 (9)).
3895 -- A primitive operation may have an access parameter of an
3896 -- incomplete tagged type, but a dispatching call is illegal
3897 -- if the type is still incomplete.
3899 if Is_Controlling_Formal (F) then
3900 Set_Is_Controlling_Actual (A);
3902 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3904 Desig : constant Entity_Id := Designated_Type (Etype (F));
3906 if Ekind (Desig) = E_Incomplete_Type
3907 and then No (Full_View (Desig))
3908 and then No (Non_Limited_View (Desig))
3911 ("premature use of incomplete type& " &
3912 "in dispatching call", A, Desig);
3917 elsif Nkind (A) = N_Explicit_Dereference then
3918 Validate_Remote_Access_To_Class_Wide_Type (A);
3921 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3922 and then not Is_Class_Wide_Type (F_Typ)
3923 and then not Is_Controlling_Formal (F)
3925 Error_Msg_N ("class-wide argument not allowed here!", A);
3927 if Is_Subprogram (Nam)
3928 and then Comes_From_Source (Nam)
3930 Error_Msg_Node_2 := F_Typ;
3932 ("& is not a dispatching operation of &!", A, Nam);
3935 elsif Is_Access_Type (A_Typ)
3936 and then Is_Access_Type (F_Typ)
3937 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3938 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3939 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3940 or else (Nkind (A) = N_Attribute_Reference
3942 Is_Class_Wide_Type (Etype (Prefix (A)))))
3943 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3944 and then not Is_Controlling_Formal (F)
3946 -- Disable these checks for call to imported C++ subprograms
3949 (Is_Entity_Name (Name (N))
3950 and then Is_Imported (Entity (Name (N)))
3951 and then Convention (Entity (Name (N))) = Convention_CPP)
3954 ("access to class-wide argument not allowed here!", A);
3956 if Is_Subprogram (Nam)
3957 and then Comes_From_Source (Nam)
3959 Error_Msg_Node_2 := Designated_Type (F_Typ);
3961 ("& is not a dispatching operation of &!", A, Nam);
3967 -- If it is a named association, treat the selector_name as a
3968 -- proper identifier, and mark the corresponding entity.
3970 if Nkind (Parent (A)) = N_Parameter_Association then
3971 Set_Entity (Selector_Name (Parent (A)), F);
3972 Generate_Reference (F, Selector_Name (Parent (A)));
3973 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3974 Generate_Reference (F_Typ, N, ' ');
3979 if Ekind (F) /= E_Out_Parameter then
3980 Check_Unset_Reference (A);
3985 -- Case where actual is not present
3993 end Resolve_Actuals;
3995 -----------------------
3996 -- Resolve_Allocator --
3997 -----------------------
3999 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
4000 E : constant Node_Id := Expression (N);
4002 Discrim : Entity_Id;
4005 Assoc : Node_Id := Empty;
4008 procedure Check_Allocator_Discrim_Accessibility
4009 (Disc_Exp : Node_Id;
4010 Alloc_Typ : Entity_Id);
4011 -- Check that accessibility level associated with an access discriminant
4012 -- initialized in an allocator by the expression Disc_Exp is not deeper
4013 -- than the level of the allocator type Alloc_Typ. An error message is
4014 -- issued if this condition is violated. Specialized checks are done for
4015 -- the cases of a constraint expression which is an access attribute or
4016 -- an access discriminant.
4018 function In_Dispatching_Context return Boolean;
4019 -- If the allocator is an actual in a call, it is allowed to be class-
4020 -- wide when the context is not because it is a controlling actual.
4022 procedure Propagate_Coextensions (Root : Node_Id);
4023 -- Propagate all nested coextensions which are located one nesting
4024 -- level down the tree to the node Root. Example:
4027 -- Level_1_Coextension
4028 -- Level_2_Coextension
4030 -- The algorithm is paired with delay actions done by the Expander. In
4031 -- the above example, assume all coextensions are controlled types.
4032 -- The cycle of analysis, resolution and expansion will yield:
4034 -- 1) Analyze Top_Record
4035 -- 2) Analyze Level_1_Coextension
4036 -- 3) Analyze Level_2_Coextension
4037 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
4039 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
4040 -- generated to capture the allocated object. Temp_1 is attached
4041 -- to the coextension chain of Level_2_Coextension.
4042 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
4043 -- coextension. A forward tree traversal is performed which finds
4044 -- Level_2_Coextension's list and copies its contents into its
4046 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
4047 -- generated to capture the allocated object. Temp_2 is attached
4048 -- to the coextension chain of Level_1_Coextension. Currently, the
4049 -- contents of the list are [Temp_2, Temp_1].
4050 -- 8) Resolve Top_Record. A forward tree traversal is performed which
4051 -- finds Level_1_Coextension's list and copies its contents into
4053 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
4054 -- Temp_2 and attach them to Top_Record's finalization list.
4056 -------------------------------------------
4057 -- Check_Allocator_Discrim_Accessibility --
4058 -------------------------------------------
4060 procedure Check_Allocator_Discrim_Accessibility
4061 (Disc_Exp : Node_Id;
4062 Alloc_Typ : Entity_Id)
4065 if Type_Access_Level (Etype (Disc_Exp)) >
4066 Type_Access_Level (Alloc_Typ)
4069 ("operand type has deeper level than allocator type", Disc_Exp);
4071 -- When the expression is an Access attribute the level of the prefix
4072 -- object must not be deeper than that of the allocator's type.
4074 elsif Nkind (Disc_Exp) = N_Attribute_Reference
4075 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
4077 and then Object_Access_Level (Prefix (Disc_Exp))
4078 > Type_Access_Level (Alloc_Typ)
4081 ("prefix of attribute has deeper level than allocator type",
4084 -- When the expression is an access discriminant the check is against
4085 -- the level of the prefix object.
4087 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
4088 and then Nkind (Disc_Exp) = N_Selected_Component
4089 and then Object_Access_Level (Prefix (Disc_Exp))
4090 > Type_Access_Level (Alloc_Typ)
4093 ("access discriminant has deeper level than allocator type",
4096 -- All other cases are legal
4101 end Check_Allocator_Discrim_Accessibility;
4103 ----------------------------
4104 -- In_Dispatching_Context --
4105 ----------------------------
4107 function In_Dispatching_Context return Boolean is
4108 Par : constant Node_Id := Parent (N);
4110 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
4111 and then Is_Entity_Name (Name (Par))
4112 and then Is_Dispatching_Operation (Entity (Name (Par)));
4113 end In_Dispatching_Context;
4115 ----------------------------
4116 -- Propagate_Coextensions --
4117 ----------------------------
4119 procedure Propagate_Coextensions (Root : Node_Id) is
4121 procedure Copy_List (From : Elist_Id; To : Elist_Id);
4122 -- Copy the contents of list From into list To, preserving the
4123 -- order of elements.
4125 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
4126 -- Recognize an allocator or a rewritten allocator node and add it
4127 -- along with its nested coextensions to the list of Root.
4133 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
4134 From_Elmt : Elmt_Id;
4136 From_Elmt := First_Elmt (From);
4137 while Present (From_Elmt) loop
4138 Append_Elmt (Node (From_Elmt), To);
4139 Next_Elmt (From_Elmt);
4143 -----------------------
4144 -- Process_Allocator --
4145 -----------------------
4147 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
4148 Orig_Nod : Node_Id := Nod;
4151 -- This is a possible rewritten subtype indication allocator. Any
4152 -- nested coextensions will appear as discriminant constraints.
4154 if Nkind (Nod) = N_Identifier
4155 and then Present (Original_Node (Nod))
4156 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
4160 Discr_Elmt : Elmt_Id;
4163 if Is_Record_Type (Entity (Nod)) then
4165 First_Elmt (Discriminant_Constraint (Entity (Nod)));
4166 while Present (Discr_Elmt) loop
4167 Discr := Node (Discr_Elmt);
4169 if Nkind (Discr) = N_Identifier
4170 and then Present (Original_Node (Discr))
4171 and then Nkind (Original_Node (Discr)) = N_Allocator
4172 and then Present (Coextensions (
4173 Original_Node (Discr)))
4175 if No (Coextensions (Root)) then
4176 Set_Coextensions (Root, New_Elmt_List);
4180 (From => Coextensions (Original_Node (Discr)),
4181 To => Coextensions (Root));
4184 Next_Elmt (Discr_Elmt);
4187 -- There is no need to continue the traversal of this
4188 -- subtree since all the information has already been
4195 -- Case of either a stand alone allocator or a rewritten allocator
4196 -- with an aggregate.
4199 if Present (Original_Node (Nod)) then
4200 Orig_Nod := Original_Node (Nod);
4203 if Nkind (Orig_Nod) = N_Allocator then
4205 -- Propagate the list of nested coextensions to the Root
4206 -- allocator. This is done through list copy since a single
4207 -- allocator may have multiple coextensions. Do not touch
4208 -- coextensions roots.
4210 if not Is_Coextension_Root (Orig_Nod)
4211 and then Present (Coextensions (Orig_Nod))
4213 if No (Coextensions (Root)) then
4214 Set_Coextensions (Root, New_Elmt_List);
4218 (From => Coextensions (Orig_Nod),
4219 To => Coextensions (Root));
4222 -- There is no need to continue the traversal of this
4223 -- subtree since all the information has already been
4230 -- Keep on traversing, looking for the next allocator
4233 end Process_Allocator;
4235 procedure Process_Allocators is
4236 new Traverse_Proc (Process_Allocator);
4238 -- Start of processing for Propagate_Coextensions
4241 Process_Allocators (Expression (Root));
4242 end Propagate_Coextensions;
4244 -- Start of processing for Resolve_Allocator
4247 -- Replace general access with specific type
4249 if Ekind (Etype (N)) = E_Allocator_Type then
4250 Set_Etype (N, Base_Type (Typ));
4253 if Is_Abstract_Type (Typ) then
4254 Error_Msg_N ("type of allocator cannot be abstract", N);
4257 -- For qualified expression, resolve the expression using the
4258 -- given subtype (nothing to do for type mark, subtype indication)
4260 if Nkind (E) = N_Qualified_Expression then
4261 if Is_Class_Wide_Type (Etype (E))
4262 and then not Is_Class_Wide_Type (Designated_Type (Typ))
4263 and then not In_Dispatching_Context
4266 ("class-wide allocator not allowed for this access type", N);
4269 Resolve (Expression (E), Etype (E));
4270 Check_Unset_Reference (Expression (E));
4272 -- A qualified expression requires an exact match of the type,
4273 -- class-wide matching is not allowed.
4275 if (Is_Class_Wide_Type (Etype (Expression (E)))
4276 or else Is_Class_Wide_Type (Etype (E)))
4277 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
4279 Wrong_Type (Expression (E), Etype (E));
4282 -- A special accessibility check is needed for allocators that
4283 -- constrain access discriminants. The level of the type of the
4284 -- expression used to constrain an access discriminant cannot be
4285 -- deeper than the type of the allocator (in contrast to access
4286 -- parameters, where the level of the actual can be arbitrary).
4288 -- We can't use Valid_Conversion to perform this check because
4289 -- in general the type of the allocator is unrelated to the type
4290 -- of the access discriminant.
4292 if Ekind (Typ) /= E_Anonymous_Access_Type
4293 or else Is_Local_Anonymous_Access (Typ)
4295 Subtyp := Entity (Subtype_Mark (E));
4297 Aggr := Original_Node (Expression (E));
4299 if Has_Discriminants (Subtyp)
4300 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
4302 Discrim := First_Discriminant (Base_Type (Subtyp));
4304 -- Get the first component expression of the aggregate
4306 if Present (Expressions (Aggr)) then
4307 Disc_Exp := First (Expressions (Aggr));
4309 elsif Present (Component_Associations (Aggr)) then
4310 Assoc := First (Component_Associations (Aggr));
4312 if Present (Assoc) then
4313 Disc_Exp := Expression (Assoc);
4322 while Present (Discrim) and then Present (Disc_Exp) loop
4323 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4324 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4327 Next_Discriminant (Discrim);
4329 if Present (Discrim) then
4330 if Present (Assoc) then
4332 Disc_Exp := Expression (Assoc);
4334 elsif Present (Next (Disc_Exp)) then
4338 Assoc := First (Component_Associations (Aggr));
4340 if Present (Assoc) then
4341 Disc_Exp := Expression (Assoc);
4351 -- For a subtype mark or subtype indication, freeze the subtype
4354 Freeze_Expression (E);
4356 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
4358 ("initialization required for access-to-constant allocator", N);
4361 -- A special accessibility check is needed for allocators that
4362 -- constrain access discriminants. The level of the type of the
4363 -- expression used to constrain an access discriminant cannot be
4364 -- deeper than the type of the allocator (in contrast to access
4365 -- parameters, where the level of the actual can be arbitrary).
4366 -- We can't use Valid_Conversion to perform this check because
4367 -- in general the type of the allocator is unrelated to the type
4368 -- of the access discriminant.
4370 if Nkind (Original_Node (E)) = N_Subtype_Indication
4371 and then (Ekind (Typ) /= E_Anonymous_Access_Type
4372 or else Is_Local_Anonymous_Access (Typ))
4374 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
4376 if Has_Discriminants (Subtyp) then
4377 Discrim := First_Discriminant (Base_Type (Subtyp));
4378 Constr := First (Constraints (Constraint (Original_Node (E))));
4379 while Present (Discrim) and then Present (Constr) loop
4380 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4381 if Nkind (Constr) = N_Discriminant_Association then
4382 Disc_Exp := Original_Node (Expression (Constr));
4384 Disc_Exp := Original_Node (Constr);
4387 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4390 Next_Discriminant (Discrim);
4397 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4398 -- check that the level of the type of the created object is not deeper
4399 -- than the level of the allocator's access type, since extensions can
4400 -- now occur at deeper levels than their ancestor types. This is a
4401 -- static accessibility level check; a run-time check is also needed in
4402 -- the case of an initialized allocator with a class-wide argument (see
4403 -- Expand_Allocator_Expression).
4405 if Ada_Version >= Ada_2005
4406 and then Is_Class_Wide_Type (Designated_Type (Typ))
4409 Exp_Typ : Entity_Id;
4412 if Nkind (E) = N_Qualified_Expression then
4413 Exp_Typ := Etype (E);
4414 elsif Nkind (E) = N_Subtype_Indication then
4415 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4417 Exp_Typ := Entity (E);
4420 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4421 if In_Instance_Body then
4422 Error_Msg_N ("?type in allocator has deeper level than" &
4423 " designated class-wide type", E);
4424 Error_Msg_N ("\?Program_Error will be raised at run time",
4427 Make_Raise_Program_Error (Sloc (N),
4428 Reason => PE_Accessibility_Check_Failed));
4431 -- Do not apply Ada 2005 accessibility checks on a class-wide
4432 -- allocator if the type given in the allocator is a formal
4433 -- type. A run-time check will be performed in the instance.
4435 elsif not Is_Generic_Type (Exp_Typ) then
4436 Error_Msg_N ("type in allocator has deeper level than" &
4437 " designated class-wide type", E);
4443 -- Check for allocation from an empty storage pool
4445 if No_Pool_Assigned (Typ) then
4446 Error_Msg_N ("allocation from empty storage pool!", N);
4448 -- If the context is an unchecked conversion, as may happen within
4449 -- an inlined subprogram, the allocator is being resolved with its
4450 -- own anonymous type. In that case, if the target type has a specific
4451 -- storage pool, it must be inherited explicitly by the allocator type.
4453 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4454 and then No (Associated_Storage_Pool (Typ))
4456 Set_Associated_Storage_Pool
4457 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4460 if Ekind (Etype (N)) = E_Anonymous_Access_Type then
4461 Check_Restriction (No_Anonymous_Allocators, N);
4464 -- An erroneous allocator may be rewritten as a raise Program_Error
4467 if Nkind (N) = N_Allocator then
4469 -- An anonymous access discriminant is the definition of a
4472 if Ekind (Typ) = E_Anonymous_Access_Type
4473 and then Nkind (Associated_Node_For_Itype (Typ)) =
4474 N_Discriminant_Specification
4476 -- Avoid marking an allocator as a dynamic coextension if it is
4477 -- within a static construct.
4479 if not Is_Static_Coextension (N) then
4480 Set_Is_Dynamic_Coextension (N);
4483 -- Cleanup for potential static coextensions
4486 Set_Is_Dynamic_Coextension (N, False);
4487 Set_Is_Static_Coextension (N, False);
4490 -- There is no need to propagate any nested coextensions if they
4491 -- are marked as static since they will be rewritten on the spot.
4493 if not Is_Static_Coextension (N) then
4494 Propagate_Coextensions (N);
4497 end Resolve_Allocator;
4499 ---------------------------
4500 -- Resolve_Arithmetic_Op --
4501 ---------------------------
4503 -- Used for resolving all arithmetic operators except exponentiation
4505 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4506 L : constant Node_Id := Left_Opnd (N);
4507 R : constant Node_Id := Right_Opnd (N);
4508 TL : constant Entity_Id := Base_Type (Etype (L));
4509 TR : constant Entity_Id := Base_Type (Etype (R));
4513 B_Typ : constant Entity_Id := Base_Type (Typ);
4514 -- We do the resolution using the base type, because intermediate values
4515 -- in expressions always are of the base type, not a subtype of it.
4517 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4518 -- Returns True if N is in a context that expects "any real type"
4520 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4521 -- Return True iff given type is Integer or universal real/integer
4523 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4524 -- Choose type of integer literal in fixed-point operation to conform
4525 -- to available fixed-point type. T is the type of the other operand,
4526 -- which is needed to determine the expected type of N.
4528 procedure Set_Operand_Type (N : Node_Id);
4529 -- Set operand type to T if universal
4531 -------------------------------
4532 -- Expected_Type_Is_Any_Real --
4533 -------------------------------
4535 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4537 -- N is the expression after "delta" in a fixed_point_definition;
4540 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4541 N_Decimal_Fixed_Point_Definition,
4543 -- N is one of the bounds in a real_range_specification;
4546 N_Real_Range_Specification,
4548 -- N is the expression of a delta_constraint;
4551 N_Delta_Constraint);
4552 end Expected_Type_Is_Any_Real;
4554 -----------------------------
4555 -- Is_Integer_Or_Universal --
4556 -----------------------------
4558 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4560 Index : Interp_Index;
4564 if not Is_Overloaded (N) then
4566 return Base_Type (T) = Base_Type (Standard_Integer)
4567 or else T = Universal_Integer
4568 or else T = Universal_Real;
4570 Get_First_Interp (N, Index, It);
4571 while Present (It.Typ) loop
4572 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4573 or else It.Typ = Universal_Integer
4574 or else It.Typ = Universal_Real
4579 Get_Next_Interp (Index, It);
4584 end Is_Integer_Or_Universal;
4586 ----------------------------
4587 -- Set_Mixed_Mode_Operand --
4588 ----------------------------
4590 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4591 Index : Interp_Index;
4595 if Universal_Interpretation (N) = Universal_Integer then
4597 -- A universal integer literal is resolved as standard integer
4598 -- except in the case of a fixed-point result, where we leave it
4599 -- as universal (to be handled by Exp_Fixd later on)
4601 if Is_Fixed_Point_Type (T) then
4602 Resolve (N, Universal_Integer);
4604 Resolve (N, Standard_Integer);
4607 elsif Universal_Interpretation (N) = Universal_Real
4608 and then (T = Base_Type (Standard_Integer)
4609 or else T = Universal_Integer
4610 or else T = Universal_Real)
4612 -- A universal real can appear in a fixed-type context. We resolve
4613 -- the literal with that context, even though this might raise an
4614 -- exception prematurely (the other operand may be zero).
4618 elsif Etype (N) = Base_Type (Standard_Integer)
4619 and then T = Universal_Real
4620 and then Is_Overloaded (N)
4622 -- Integer arg in mixed-mode operation. Resolve with universal
4623 -- type, in case preference rule must be applied.
4625 Resolve (N, Universal_Integer);
4628 and then B_Typ /= Universal_Fixed
4630 -- Not a mixed-mode operation, resolve with context
4634 elsif Etype (N) = Any_Fixed then
4636 -- N may itself be a mixed-mode operation, so use context type
4640 elsif Is_Fixed_Point_Type (T)
4641 and then B_Typ = Universal_Fixed
4642 and then Is_Overloaded (N)
4644 -- Must be (fixed * fixed) operation, operand must have one
4645 -- compatible interpretation.
4647 Resolve (N, Any_Fixed);
4649 elsif Is_Fixed_Point_Type (B_Typ)
4650 and then (T = Universal_Real
4651 or else Is_Fixed_Point_Type (T))
4652 and then Is_Overloaded (N)
4654 -- C * F(X) in a fixed context, where C is a real literal or a
4655 -- fixed-point expression. F must have either a fixed type
4656 -- interpretation or an integer interpretation, but not both.
4658 Get_First_Interp (N, Index, It);
4659 while Present (It.Typ) loop
4660 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4662 if Analyzed (N) then
4663 Error_Msg_N ("ambiguous operand in fixed operation", N);
4665 Resolve (N, Standard_Integer);
4668 elsif Is_Fixed_Point_Type (It.Typ) then
4670 if Analyzed (N) then
4671 Error_Msg_N ("ambiguous operand in fixed operation", N);
4673 Resolve (N, It.Typ);
4677 Get_Next_Interp (Index, It);
4680 -- Reanalyze the literal with the fixed type of the context. If
4681 -- context is Universal_Fixed, we are within a conversion, leave
4682 -- the literal as a universal real because there is no usable
4683 -- fixed type, and the target of the conversion plays no role in
4697 if B_Typ = Universal_Fixed
4698 and then Nkind (Op2) = N_Real_Literal
4700 T2 := Universal_Real;
4705 Set_Analyzed (Op2, False);
4712 end Set_Mixed_Mode_Operand;
4714 ----------------------
4715 -- Set_Operand_Type --
4716 ----------------------
4718 procedure Set_Operand_Type (N : Node_Id) is
4720 if Etype (N) = Universal_Integer
4721 or else Etype (N) = Universal_Real
4725 end Set_Operand_Type;
4727 -- Start of processing for Resolve_Arithmetic_Op
4730 if Comes_From_Source (N)
4731 and then Ekind (Entity (N)) = E_Function
4732 and then Is_Imported (Entity (N))
4733 and then Is_Intrinsic_Subprogram (Entity (N))
4735 Resolve_Intrinsic_Operator (N, Typ);
4738 -- Special-case for mixed-mode universal expressions or fixed point
4739 -- type operation: each argument is resolved separately. The same
4740 -- treatment is required if one of the operands of a fixed point
4741 -- operation is universal real, since in this case we don't do a
4742 -- conversion to a specific fixed-point type (instead the expander
4743 -- takes care of the case).
4745 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4746 and then Present (Universal_Interpretation (L))
4747 and then Present (Universal_Interpretation (R))
4749 Resolve (L, Universal_Interpretation (L));
4750 Resolve (R, Universal_Interpretation (R));
4751 Set_Etype (N, B_Typ);
4753 elsif (B_Typ = Universal_Real
4754 or else Etype (N) = Universal_Fixed
4755 or else (Etype (N) = Any_Fixed
4756 and then Is_Fixed_Point_Type (B_Typ))
4757 or else (Is_Fixed_Point_Type (B_Typ)
4758 and then (Is_Integer_Or_Universal (L)
4760 Is_Integer_Or_Universal (R))))
4761 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4763 if TL = Universal_Integer or else TR = Universal_Integer then
4764 Check_For_Visible_Operator (N, B_Typ);
4767 -- If context is a fixed type and one operand is integer, the
4768 -- other is resolved with the type of the context.
4770 if Is_Fixed_Point_Type (B_Typ)
4771 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4772 or else TL = Universal_Integer)
4777 elsif Is_Fixed_Point_Type (B_Typ)
4778 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4779 or else TR = Universal_Integer)
4785 Set_Mixed_Mode_Operand (L, TR);
4786 Set_Mixed_Mode_Operand (R, TL);
4789 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4790 -- multiplying operators from being used when the expected type is
4791 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4792 -- some cases where the expected type is actually Any_Real;
4793 -- Expected_Type_Is_Any_Real takes care of that case.
4795 if Etype (N) = Universal_Fixed
4796 or else Etype (N) = Any_Fixed
4798 if B_Typ = Universal_Fixed
4799 and then not Expected_Type_Is_Any_Real (N)
4800 and then not Nkind_In (Parent (N), N_Type_Conversion,
4801 N_Unchecked_Type_Conversion)
4803 Error_Msg_N ("type cannot be determined from context!", N);
4804 Error_Msg_N ("\explicit conversion to result type required", N);
4806 Set_Etype (L, Any_Type);
4807 Set_Etype (R, Any_Type);
4810 if Ada_Version = Ada_83
4811 and then Etype (N) = Universal_Fixed
4813 Nkind_In (Parent (N), N_Type_Conversion,
4814 N_Unchecked_Type_Conversion)
4817 ("(Ada 83) fixed-point operation "
4818 & "needs explicit conversion", N);
4821 -- The expected type is "any real type" in contexts like
4822 -- type T is delta <universal_fixed-expression> ...
4823 -- in which case we need to set the type to Universal_Real
4824 -- so that static expression evaluation will work properly.
4826 if Expected_Type_Is_Any_Real (N) then
4827 Set_Etype (N, Universal_Real);
4829 Set_Etype (N, B_Typ);
4833 elsif Is_Fixed_Point_Type (B_Typ)
4834 and then (Is_Integer_Or_Universal (L)
4835 or else Nkind (L) = N_Real_Literal
4836 or else Nkind (R) = N_Real_Literal
4837 or else Is_Integer_Or_Universal (R))
4839 Set_Etype (N, B_Typ);
4841 elsif Etype (N) = Any_Fixed then
4843 -- If no previous errors, this is only possible if one operand
4844 -- is overloaded and the context is universal. Resolve as such.
4846 Set_Etype (N, B_Typ);
4850 if (TL = Universal_Integer or else TL = Universal_Real)
4852 (TR = Universal_Integer or else TR = Universal_Real)
4854 Check_For_Visible_Operator (N, B_Typ);
4857 -- If the context is Universal_Fixed and the operands are also
4858 -- universal fixed, this is an error, unless there is only one
4859 -- applicable fixed_point type (usually Duration).
4861 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4862 T := Unique_Fixed_Point_Type (N);
4864 if T = Any_Type then
4877 -- If one of the arguments was resolved to a non-universal type.
4878 -- label the result of the operation itself with the same type.
4879 -- Do the same for the universal argument, if any.
4881 T := Intersect_Types (L, R);
4882 Set_Etype (N, Base_Type (T));
4883 Set_Operand_Type (L);
4884 Set_Operand_Type (R);
4887 Generate_Operator_Reference (N, Typ);
4888 Eval_Arithmetic_Op (N);
4890 -- In SPARK and ALFA, a multiplication or division with operands of
4891 -- fixed point types shall be qualified or explicitly converted to
4892 -- identify the result type.
4894 if Formal_Verification_Mode
4895 and then (Is_Fixed_Point_Type (Etype (L))
4896 or else Is_Fixed_Point_Type (Etype (R)))
4897 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4899 not Nkind_In (Parent (N), N_Qualified_Expression, N_Type_Conversion)
4902 ("|~~operation should be qualified or explicitly converted", N);
4905 -- Set overflow and division checking bit. Much cleverer code needed
4906 -- here eventually and perhaps the Resolve routines should be separated
4907 -- for the various arithmetic operations, since they will need
4908 -- different processing. ???
4910 if Nkind (N) in N_Op then
4911 if not Overflow_Checks_Suppressed (Etype (N)) then
4912 Enable_Overflow_Check (N);
4915 -- Give warning if explicit division by zero
4917 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4918 and then not Division_Checks_Suppressed (Etype (N))
4920 Rop := Right_Opnd (N);
4922 if Compile_Time_Known_Value (Rop)
4923 and then ((Is_Integer_Type (Etype (Rop))
4924 and then Expr_Value (Rop) = Uint_0)
4926 (Is_Real_Type (Etype (Rop))
4927 and then Expr_Value_R (Rop) = Ureal_0))
4929 -- Specialize the warning message according to the operation
4933 Apply_Compile_Time_Constraint_Error
4934 (N, "division by zero?", CE_Divide_By_Zero,
4935 Loc => Sloc (Right_Opnd (N)));
4938 Apply_Compile_Time_Constraint_Error
4939 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4940 Loc => Sloc (Right_Opnd (N)));
4943 Apply_Compile_Time_Constraint_Error
4944 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4945 Loc => Sloc (Right_Opnd (N)));
4947 -- Division by zero can only happen with division, rem,
4948 -- and mod operations.
4951 raise Program_Error;
4954 -- Otherwise just set the flag to check at run time
4957 Activate_Division_Check (N);
4961 -- If Restriction No_Implicit_Conditionals is active, then it is
4962 -- violated if either operand can be negative for mod, or for rem
4963 -- if both operands can be negative.
4965 if Restriction_Check_Required (No_Implicit_Conditionals)
4966 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4975 -- Set if corresponding operand might be negative
4979 (Left_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4980 LNeg := (not OK) or else Lo < 0;
4983 (Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4984 RNeg := (not OK) or else Lo < 0;
4986 -- Check if we will be generating conditionals. There are two
4987 -- cases where that can happen, first for REM, the only case
4988 -- is largest negative integer mod -1, where the division can
4989 -- overflow, but we still have to give the right result. The
4990 -- front end generates a test for this annoying case. Here we
4991 -- just test if both operands can be negative (that's what the
4992 -- expander does, so we match its logic here).
4994 -- The second case is mod where either operand can be negative.
4995 -- In this case, the back end has to generate additional tests.
4997 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4999 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
5001 Check_Restriction (No_Implicit_Conditionals, N);
5007 Check_Unset_Reference (L);
5008 Check_Unset_Reference (R);
5009 end Resolve_Arithmetic_Op;
5015 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
5016 Loc : constant Source_Ptr := Sloc (N);
5017 Subp : constant Node_Id := Name (N);
5025 function Same_Or_Aliased_Subprograms
5027 E : Entity_Id) return Boolean;
5028 -- Returns True if the subprogram entity S is the same as E or else
5029 -- S is an alias of E.
5031 ---------------------------------
5032 -- Same_Or_Aliased_Subprograms --
5033 ---------------------------------
5035 function Same_Or_Aliased_Subprograms
5037 E : Entity_Id) return Boolean
5039 Subp_Alias : constant Entity_Id := Alias (S);
5042 or else (Present (Subp_Alias) and then Subp_Alias = E);
5043 end Same_Or_Aliased_Subprograms;
5045 -- Start of processing for Resolve_Call
5048 -- The context imposes a unique interpretation with type Typ on a
5049 -- procedure or function call. Find the entity of the subprogram that
5050 -- yields the expected type, and propagate the corresponding formal
5051 -- constraints on the actuals. The caller has established that an
5052 -- interpretation exists, and emitted an error if not unique.
5054 -- First deal with the case of a call to an access-to-subprogram,
5055 -- dereference made explicit in Analyze_Call.
5057 if Ekind (Etype (Subp)) = E_Subprogram_Type then
5058 if not Is_Overloaded (Subp) then
5059 Nam := Etype (Subp);
5062 -- Find the interpretation whose type (a subprogram type) has a
5063 -- return type that is compatible with the context. Analysis of
5064 -- the node has established that one exists.
5068 Get_First_Interp (Subp, I, It);
5069 while Present (It.Typ) loop
5070 if Covers (Typ, Etype (It.Typ)) then
5075 Get_Next_Interp (I, It);
5079 raise Program_Error;
5083 -- If the prefix is not an entity, then resolve it
5085 if not Is_Entity_Name (Subp) then
5086 Resolve (Subp, Nam);
5089 -- For an indirect call, we always invalidate checks, since we do not
5090 -- know whether the subprogram is local or global. Yes we could do
5091 -- better here, e.g. by knowing that there are no local subprograms,
5092 -- but it does not seem worth the effort. Similarly, we kill all
5093 -- knowledge of current constant values.
5095 Kill_Current_Values;
5097 -- If this is a procedure call which is really an entry call, do
5098 -- the conversion of the procedure call to an entry call. Protected
5099 -- operations use the same circuitry because the name in the call
5100 -- can be an arbitrary expression with special resolution rules.
5102 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
5103 or else (Is_Entity_Name (Subp)
5104 and then Ekind (Entity (Subp)) = E_Entry)
5106 Resolve_Entry_Call (N, Typ);
5107 Check_Elab_Call (N);
5109 -- Kill checks and constant values, as above for indirect case
5110 -- Who knows what happens when another task is activated?
5112 Kill_Current_Values;
5115 -- Normal subprogram call with name established in Resolve
5117 elsif not (Is_Type (Entity (Subp))) then
5118 Nam := Entity (Subp);
5119 Set_Entity_With_Style_Check (Subp, Nam);
5121 -- Otherwise we must have the case of an overloaded call
5124 pragma Assert (Is_Overloaded (Subp));
5126 -- Initialize Nam to prevent warning (we know it will be assigned
5127 -- in the loop below, but the compiler does not know that).
5131 Get_First_Interp (Subp, I, It);
5132 while Present (It.Typ) loop
5133 if Covers (Typ, It.Typ) then
5135 Set_Entity_With_Style_Check (Subp, Nam);
5139 Get_Next_Interp (I, It);
5143 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
5144 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
5145 and then Nkind (Subp) /= N_Explicit_Dereference
5146 and then Present (Parameter_Associations (N))
5148 -- The prefix is a parameterless function call that returns an access
5149 -- to subprogram. If parameters are present in the current call, add
5150 -- add an explicit dereference. We use the base type here because
5151 -- within an instance these may be subtypes.
5153 -- The dereference is added either in Analyze_Call or here. Should
5154 -- be consolidated ???
5156 Set_Is_Overloaded (Subp, False);
5157 Set_Etype (Subp, Etype (Nam));
5158 Insert_Explicit_Dereference (Subp);
5159 Nam := Designated_Type (Etype (Nam));
5160 Resolve (Subp, Nam);
5163 -- Check that a call to Current_Task does not occur in an entry body
5165 if Is_RTE (Nam, RE_Current_Task) then
5174 -- Exclude calls that occur within the default of a formal
5175 -- parameter of the entry, since those are evaluated outside
5178 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
5180 if Nkind (P) = N_Entry_Body
5181 or else (Nkind (P) = N_Subprogram_Body
5182 and then Is_Entry_Barrier_Function (P))
5186 ("?& should not be used in entry body (RM C.7(17))",
5189 ("\Program_Error will be raised at run time?", N, Nam);
5191 Make_Raise_Program_Error (Loc,
5192 Reason => PE_Current_Task_In_Entry_Body));
5193 Set_Etype (N, Rtype);
5200 -- Check that a procedure call does not occur in the context of the
5201 -- entry call statement of a conditional or timed entry call. Note that
5202 -- the case of a call to a subprogram renaming of an entry will also be
5203 -- rejected. The test for N not being an N_Entry_Call_Statement is
5204 -- defensive, covering the possibility that the processing of entry
5205 -- calls might reach this point due to later modifications of the code
5208 if Nkind (Parent (N)) = N_Entry_Call_Alternative
5209 and then Nkind (N) /= N_Entry_Call_Statement
5210 and then Entry_Call_Statement (Parent (N)) = N
5212 if Ada_Version < Ada_2005 then
5213 Error_Msg_N ("entry call required in select statement", N);
5215 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5216 -- for a procedure_or_entry_call, the procedure_name or
5217 -- procedure_prefix of the procedure_call_statement shall denote
5218 -- an entry renamed by a procedure, or (a view of) a primitive
5219 -- subprogram of a limited interface whose first parameter is
5220 -- a controlling parameter.
5222 elsif Nkind (N) = N_Procedure_Call_Statement
5223 and then not Is_Renamed_Entry (Nam)
5224 and then not Is_Controlling_Limited_Procedure (Nam)
5227 ("entry call or dispatching primitive of interface required", N);
5231 -- Check that this is not a call to a protected procedure or entry from
5232 -- within a protected function.
5234 if Ekind (Current_Scope) = E_Function
5235 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
5236 and then Ekind (Nam) /= E_Function
5237 and then Scope (Nam) = Scope (Current_Scope)
5239 Error_Msg_N ("within protected function, protected " &
5240 "object is constant", N);
5241 Error_Msg_N ("\cannot call operation that may modify it", N);
5244 -- Freeze the subprogram name if not in a spec-expression. Note that we
5245 -- freeze procedure calls as well as function calls. Procedure calls are
5246 -- not frozen according to the rules (RM 13.14(14)) because it is
5247 -- impossible to have a procedure call to a non-frozen procedure in pure
5248 -- Ada, but in the code that we generate in the expander, this rule
5249 -- needs extending because we can generate procedure calls that need
5252 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
5253 Freeze_Expression (Subp);
5256 -- For a predefined operator, the type of the result is the type imposed
5257 -- by context, except for a predefined operation on universal fixed.
5258 -- Otherwise The type of the call is the type returned by the subprogram
5261 if Is_Predefined_Op (Nam) then
5262 if Etype (N) /= Universal_Fixed then
5266 -- If the subprogram returns an array type, and the context requires the
5267 -- component type of that array type, the node is really an indexing of
5268 -- the parameterless call. Resolve as such. A pathological case occurs
5269 -- when the type of the component is an access to the array type. In
5270 -- this case the call is truly ambiguous.
5272 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
5274 ((Is_Array_Type (Etype (Nam))
5275 and then Covers (Typ, Component_Type (Etype (Nam))))
5276 or else (Is_Access_Type (Etype (Nam))
5277 and then Is_Array_Type (Designated_Type (Etype (Nam)))
5280 Component_Type (Designated_Type (Etype (Nam))))))
5283 Index_Node : Node_Id;
5285 Ret_Type : constant Entity_Id := Etype (Nam);
5288 if Is_Access_Type (Ret_Type)
5289 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
5292 ("cannot disambiguate function call and indexing", N);
5294 New_Subp := Relocate_Node (Subp);
5295 Set_Entity (Subp, Nam);
5297 if (Is_Array_Type (Ret_Type)
5298 and then Component_Type (Ret_Type) /= Any_Type)
5300 (Is_Access_Type (Ret_Type)
5302 Component_Type (Designated_Type (Ret_Type)) /= Any_Type)
5304 if Needs_No_Actuals (Nam) then
5306 -- Indexed call to a parameterless function
5309 Make_Indexed_Component (Loc,
5311 Make_Function_Call (Loc,
5313 Expressions => Parameter_Associations (N));
5315 -- An Ada 2005 prefixed call to a primitive operation
5316 -- whose first parameter is the prefix. This prefix was
5317 -- prepended to the parameter list, which is actually a
5318 -- list of indexes. Remove the prefix in order to build
5319 -- the proper indexed component.
5322 Make_Indexed_Component (Loc,
5324 Make_Function_Call (Loc,
5326 Parameter_Associations =>
5328 (Remove_Head (Parameter_Associations (N)))),
5329 Expressions => Parameter_Associations (N));
5332 -- Preserve the parenthesis count of the node
5334 Set_Paren_Count (Index_Node, Paren_Count (N));
5336 -- Since we are correcting a node classification error made
5337 -- by the parser, we call Replace rather than Rewrite.
5339 Replace (N, Index_Node);
5341 Set_Etype (Prefix (N), Ret_Type);
5343 Resolve_Indexed_Component (N, Typ);
5344 Check_Elab_Call (Prefix (N));
5352 Set_Etype (N, Etype (Nam));
5355 -- In the case where the call is to an overloaded subprogram, Analyze
5356 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5357 -- such a case Normalize_Actuals needs to be called once more to order
5358 -- the actuals correctly. Otherwise the call will have the ordering
5359 -- given by the last overloaded subprogram whether this is the correct
5360 -- one being called or not.
5362 if Is_Overloaded (Subp) then
5363 Normalize_Actuals (N, Nam, False, Norm_OK);
5364 pragma Assert (Norm_OK);
5367 -- In any case, call is fully resolved now. Reset Overload flag, to
5368 -- prevent subsequent overload resolution if node is analyzed again
5370 Set_Is_Overloaded (Subp, False);
5371 Set_Is_Overloaded (N, False);
5373 -- If we are calling the current subprogram from immediately within its
5374 -- body, then that is the case where we can sometimes detect cases of
5375 -- infinite recursion statically. Do not try this in case restriction
5376 -- No_Recursion is in effect anyway, and do it only for source calls.
5378 if Comes_From_Source (N) then
5379 Scop := Current_Scope;
5381 -- Issue warning for possible infinite recursion in the absence
5382 -- of the No_Recursion restriction.
5384 if Same_Or_Aliased_Subprograms (Nam, Scop)
5385 and then not Restriction_Active (No_Recursion)
5386 and then Check_Infinite_Recursion (N)
5388 -- Here we detected and flagged an infinite recursion, so we do
5389 -- not need to test the case below for further warnings. Also we
5390 -- are all done if we now have a raise SE node.
5392 if Nkind (N) = N_Raise_Storage_Error then
5396 -- If call is to immediately containing subprogram, then check for
5397 -- the case of a possible run-time detectable infinite recursion.
5400 Scope_Loop : while Scop /= Standard_Standard loop
5401 if Same_Or_Aliased_Subprograms (Nam, Scop) then
5403 -- Although in general case, recursion is not statically
5404 -- checkable, the case of calling an immediately containing
5405 -- subprogram is easy to catch.
5407 Check_Restriction (No_Recursion, N);
5409 -- If the recursive call is to a parameterless subprogram,
5410 -- then even if we can't statically detect infinite
5411 -- recursion, this is pretty suspicious, and we output a
5412 -- warning. Furthermore, we will try later to detect some
5413 -- cases here at run time by expanding checking code (see
5414 -- Detect_Infinite_Recursion in package Exp_Ch6).
5416 -- If the recursive call is within a handler, do not emit a
5417 -- warning, because this is a common idiom: loop until input
5418 -- is correct, catch illegal input in handler and restart.
5420 if No (First_Formal (Nam))
5421 and then Etype (Nam) = Standard_Void_Type
5422 and then not Error_Posted (N)
5423 and then Nkind (Parent (N)) /= N_Exception_Handler
5425 -- For the case of a procedure call. We give the message
5426 -- only if the call is the first statement in a sequence
5427 -- of statements, or if all previous statements are
5428 -- simple assignments. This is simply a heuristic to
5429 -- decrease false positives, without losing too many good
5430 -- warnings. The idea is that these previous statements
5431 -- may affect global variables the procedure depends on.
5433 if Nkind (N) = N_Procedure_Call_Statement
5434 and then Is_List_Member (N)
5440 while Present (P) loop
5441 if Nkind (P) /= N_Assignment_Statement then
5450 -- Do not give warning if we are in a conditional context
5453 K : constant Node_Kind := Nkind (Parent (N));
5455 if (K = N_Loop_Statement
5456 and then Present (Iteration_Scheme (Parent (N))))
5457 or else K = N_If_Statement
5458 or else K = N_Elsif_Part
5459 or else K = N_Case_Statement_Alternative
5465 -- Here warning is to be issued
5467 Set_Has_Recursive_Call (Nam);
5469 ("?possible infinite recursion!", N);
5471 ("\?Storage_Error may be raised at run time!", N);
5477 Scop := Scope (Scop);
5478 end loop Scope_Loop;
5482 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5484 Check_Obsolescent_2005_Entity (Nam, Subp);
5486 -- If subprogram name is a predefined operator, it was given in
5487 -- functional notation. Replace call node with operator node, so
5488 -- that actuals can be resolved appropriately.
5490 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5491 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5494 elsif Present (Alias (Nam))
5495 and then Is_Predefined_Op (Alias (Nam))
5497 Resolve_Actuals (N, Nam);
5498 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5502 -- Create a transient scope if the resulting type requires it
5504 -- There are several notable exceptions:
5506 -- a) In init procs, the transient scope overhead is not needed, and is
5507 -- even incorrect when the call is a nested initialization call for a
5508 -- component whose expansion may generate adjust calls. However, if the
5509 -- call is some other procedure call within an initialization procedure
5510 -- (for example a call to Create_Task in the init_proc of the task
5511 -- run-time record) a transient scope must be created around this call.
5513 -- b) Enumeration literal pseudo-calls need no transient scope
5515 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5516 -- functions) do not use the secondary stack even though the return
5517 -- type may be unconstrained.
5519 -- d) Calls to a build-in-place function, since such functions may
5520 -- allocate their result directly in a target object, and cases where
5521 -- the result does get allocated in the secondary stack are checked for
5522 -- within the specialized Exp_Ch6 procedures for expanding those
5523 -- build-in-place calls.
5525 -- e) If the subprogram is marked Inline_Always, then even if it returns
5526 -- an unconstrained type the call does not require use of the secondary
5527 -- stack. However, inlining will only take place if the body to inline
5528 -- is already present. It may not be available if e.g. the subprogram is
5529 -- declared in a child instance.
5531 -- If this is an initialization call for a type whose construction
5532 -- uses the secondary stack, and it is not a nested call to initialize
5533 -- a component, we do need to create a transient scope for it. We
5534 -- check for this by traversing the type in Check_Initialization_Call.
5537 and then Has_Pragma_Inline_Always (Nam)
5538 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5539 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5543 elsif Ekind (Nam) = E_Enumeration_Literal
5544 or else Is_Build_In_Place_Function (Nam)
5545 or else Is_Intrinsic_Subprogram (Nam)
5549 elsif Expander_Active
5550 and then Is_Type (Etype (Nam))
5551 and then Requires_Transient_Scope (Etype (Nam))
5553 (not Within_Init_Proc
5555 (not Is_Init_Proc (Nam) and then Ekind (Nam) /= E_Function))
5557 Establish_Transient_Scope (N, Sec_Stack => True);
5559 -- If the call appears within the bounds of a loop, it will
5560 -- be rewritten and reanalyzed, nothing left to do here.
5562 if Nkind (N) /= N_Function_Call then
5566 elsif Is_Init_Proc (Nam)
5567 and then not Within_Init_Proc
5569 Check_Initialization_Call (N, Nam);
5572 -- A protected function cannot be called within the definition of the
5573 -- enclosing protected type.
5575 if Is_Protected_Type (Scope (Nam))
5576 and then In_Open_Scopes (Scope (Nam))
5577 and then not Has_Completion (Scope (Nam))
5580 ("& cannot be called before end of protected definition", N, Nam);
5583 -- Propagate interpretation to actuals, and add default expressions
5586 if Present (First_Formal (Nam)) then
5587 Resolve_Actuals (N, Nam);
5589 -- Overloaded literals are rewritten as function calls, for purpose of
5590 -- resolution. After resolution, we can replace the call with the
5593 elsif Ekind (Nam) = E_Enumeration_Literal then
5594 Copy_Node (Subp, N);
5595 Resolve_Entity_Name (N, Typ);
5597 -- Avoid validation, since it is a static function call
5599 Generate_Reference (Nam, Subp);
5603 -- If the subprogram is not global, then kill all saved values and
5604 -- checks. This is a bit conservative, since in many cases we could do
5605 -- better, but it is not worth the effort. Similarly, we kill constant
5606 -- values. However we do not need to do this for internal entities
5607 -- (unless they are inherited user-defined subprograms), since they
5608 -- are not in the business of molesting local values.
5610 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5611 -- kill all checks and values for calls to global subprograms. This
5612 -- takes care of the case where an access to a local subprogram is
5613 -- taken, and could be passed directly or indirectly and then called
5614 -- from almost any context.
5616 -- Note: we do not do this step till after resolving the actuals. That
5617 -- way we still take advantage of the current value information while
5618 -- scanning the actuals.
5620 -- We suppress killing values if we are processing the nodes associated
5621 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5622 -- type kills all the values as part of analyzing the code that
5623 -- initializes the dispatch tables.
5625 if Inside_Freezing_Actions = 0
5626 and then (not Is_Library_Level_Entity (Nam)
5627 or else Suppress_Value_Tracking_On_Call
5628 (Nearest_Dynamic_Scope (Current_Scope)))
5629 and then (Comes_From_Source (Nam)
5630 or else (Present (Alias (Nam))
5631 and then Comes_From_Source (Alias (Nam))))
5633 Kill_Current_Values;
5636 -- If we are warning about unread OUT parameters, this is the place to
5637 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5638 -- after the above call to Kill_Current_Values (since that call clears
5639 -- the Last_Assignment field of all local variables).
5641 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5642 and then Comes_From_Source (N)
5643 and then In_Extended_Main_Source_Unit (N)
5650 F := First_Formal (Nam);
5651 A := First_Actual (N);
5652 while Present (F) and then Present (A) loop
5653 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter)
5654 and then Warn_On_Modified_As_Out_Parameter (F)
5655 and then Is_Entity_Name (A)
5656 and then Present (Entity (A))
5657 and then Comes_From_Source (N)
5658 and then Safe_To_Capture_Value (N, Entity (A))
5660 Set_Last_Assignment (Entity (A), A);
5669 -- If the subprogram is a primitive operation, check whether or not
5670 -- it is a correct dispatching call.
5672 if Is_Overloadable (Nam)
5673 and then Is_Dispatching_Operation (Nam)
5675 Check_Dispatching_Call (N);
5677 elsif Ekind (Nam) /= E_Subprogram_Type
5678 and then Is_Abstract_Subprogram (Nam)
5679 and then not In_Instance
5681 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5684 -- If this is a dispatching call, generate the appropriate reference,
5685 -- for better source navigation in GPS.
5687 if Is_Overloadable (Nam)
5688 and then Present (Controlling_Argument (N))
5690 Generate_Reference (Nam, Subp, 'R');
5692 -- Normal case, not a dispatching call. Generate a call reference.
5695 Generate_Reference (Nam, Subp, 's');
5698 if Is_Intrinsic_Subprogram (Nam) then
5699 Check_Intrinsic_Call (N);
5702 -- Check for violation of restriction No_Specific_Termination_Handlers
5703 -- and warn on a potentially blocking call to Abort_Task.
5705 if Is_RTE (Nam, RE_Set_Specific_Handler)
5707 Is_RTE (Nam, RE_Specific_Handler)
5709 Check_Restriction (No_Specific_Termination_Handlers, N);
5711 elsif Is_RTE (Nam, RE_Abort_Task) then
5712 Check_Potentially_Blocking_Operation (N);
5715 -- A call to Ada.Real_Time.Timing_Events.Set_Handler violates
5716 -- restriction No_Relative_Delay (AI-0211).
5718 if Is_RTE (Nam, RE_Set_Handler) then
5719 Check_Restriction (No_Relative_Delay, N);
5722 -- Issue an error for a call to an eliminated subprogram. We skip this
5723 -- in a spec expression, e.g. a call in a default parameter value, since
5724 -- we are not really doing a call at this time. That's important because
5725 -- the spec expression may itself belong to an eliminated subprogram.
5727 if not In_Spec_Expression then
5728 Check_For_Eliminated_Subprogram (Subp, Nam);
5731 -- All done, evaluate call and deal with elaboration issues
5734 Check_Elab_Call (N);
5735 Warn_On_Overlapping_Actuals (Nam, N);
5738 -----------------------------
5739 -- Resolve_Case_Expression --
5740 -----------------------------
5742 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id) is
5746 Alt := First (Alternatives (N));
5747 while Present (Alt) loop
5748 Resolve (Expression (Alt), Typ);
5753 Eval_Case_Expression (N);
5754 end Resolve_Case_Expression;
5756 -------------------------------
5757 -- Resolve_Character_Literal --
5758 -------------------------------
5760 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5761 B_Typ : constant Entity_Id := Base_Type (Typ);
5765 -- Verify that the character does belong to the type of the context
5767 Set_Etype (N, B_Typ);
5768 Eval_Character_Literal (N);
5770 -- Wide_Wide_Character literals must always be defined, since the set
5771 -- of wide wide character literals is complete, i.e. if a character
5772 -- literal is accepted by the parser, then it is OK for wide wide
5773 -- character (out of range character literals are rejected).
5775 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5778 -- Always accept character literal for type Any_Character, which
5779 -- occurs in error situations and in comparisons of literals, both
5780 -- of which should accept all literals.
5782 elsif B_Typ = Any_Character then
5785 -- For Standard.Character or a type derived from it, check that
5786 -- the literal is in range
5788 elsif Root_Type (B_Typ) = Standard_Character then
5789 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5793 -- For Standard.Wide_Character or a type derived from it, check
5794 -- that the literal is in range
5796 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5797 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5801 -- For Standard.Wide_Wide_Character or a type derived from it, we
5802 -- know the literal is in range, since the parser checked!
5804 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5807 -- If the entity is already set, this has already been resolved in a
5808 -- generic context, or comes from expansion. Nothing else to do.
5810 elsif Present (Entity (N)) then
5813 -- Otherwise we have a user defined character type, and we can use the
5814 -- standard visibility mechanisms to locate the referenced entity.
5817 C := Current_Entity (N);
5818 while Present (C) loop
5819 if Etype (C) = B_Typ then
5820 Set_Entity_With_Style_Check (N, C);
5821 Generate_Reference (C, N);
5829 -- If we fall through, then the literal does not match any of the
5830 -- entries of the enumeration type. This isn't just a constraint
5831 -- error situation, it is an illegality (see RM 4.2).
5834 ("character not defined for }", N, First_Subtype (B_Typ));
5835 end Resolve_Character_Literal;
5837 ---------------------------
5838 -- Resolve_Comparison_Op --
5839 ---------------------------
5841 -- Context requires a boolean type, and plays no role in resolution.
5842 -- Processing identical to that for equality operators. The result
5843 -- type is the base type, which matters when pathological subtypes of
5844 -- booleans with limited ranges are used.
5846 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5847 L : constant Node_Id := Left_Opnd (N);
5848 R : constant Node_Id := Right_Opnd (N);
5852 -- If this is an intrinsic operation which is not predefined, use the
5853 -- types of its declared arguments to resolve the possibly overloaded
5854 -- operands. Otherwise the operands are unambiguous and specify the
5857 if Scope (Entity (N)) /= Standard_Standard then
5858 T := Etype (First_Entity (Entity (N)));
5861 T := Find_Unique_Type (L, R);
5863 if T = Any_Fixed then
5864 T := Unique_Fixed_Point_Type (L);
5868 Set_Etype (N, Base_Type (Typ));
5869 Generate_Reference (T, N, ' ');
5871 -- Skip remaining processing if already set to Any_Type
5873 if T = Any_Type then
5877 -- Deal with other error cases
5879 if T = Any_String or else
5880 T = Any_Composite or else
5883 if T = Any_Character then
5884 Ambiguous_Character (L);
5886 Error_Msg_N ("ambiguous operands for comparison", N);
5889 Set_Etype (N, Any_Type);
5893 -- Resolve the operands if types OK
5897 Check_Unset_Reference (L);
5898 Check_Unset_Reference (R);
5899 Generate_Operator_Reference (N, T);
5900 Check_Low_Bound_Tested (N);
5902 -- In SPARK or ALFA, ordering operators <, <=, >, >= are not defined
5903 -- for Boolean types or array types except String.
5905 if Formal_Verification_Mode
5906 and then Comes_From_Source (Original_Node (N))
5908 if Is_Boolean_Type (T) then
5909 Error_Msg_F ("|~~comparison is not defined on Boolean type", N);
5910 elsif Is_Array_Type (T)
5911 and then Base_Type (T) /= Standard_String
5914 ("|~~comparison is not defined on array type except String", N);
5918 -- Check comparison on unordered enumeration
5920 if Comes_From_Source (N)
5921 and then Bad_Unordered_Enumeration_Reference (N, Etype (L))
5923 Error_Msg_N ("comparison on unordered enumeration type?", N);
5926 -- Evaluate the relation (note we do this after the above check
5927 -- since this Eval call may change N to True/False.
5929 Eval_Relational_Op (N);
5930 end Resolve_Comparison_Op;
5932 ------------------------------------
5933 -- Resolve_Conditional_Expression --
5934 ------------------------------------
5936 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
5937 Condition : constant Node_Id := First (Expressions (N));
5938 Then_Expr : constant Node_Id := Next (Condition);
5939 Else_Expr : Node_Id := Next (Then_Expr);
5942 Resolve (Condition, Any_Boolean);
5943 Resolve (Then_Expr, Typ);
5945 -- If ELSE expression present, just resolve using the determined type
5947 if Present (Else_Expr) then
5948 Resolve (Else_Expr, Typ);
5950 -- If no ELSE expression is present, root type must be Standard.Boolean
5951 -- and we provide a Standard.True result converted to the appropriate
5952 -- Boolean type (in case it is a derived boolean type).
5954 elsif Root_Type (Typ) = Standard_Boolean then
5956 Convert_To (Typ, New_Occurrence_Of (Standard_True, Sloc (N)));
5957 Analyze_And_Resolve (Else_Expr, Typ);
5958 Append_To (Expressions (N), Else_Expr);
5961 Error_Msg_N ("can only omit ELSE expression in Boolean case", N);
5962 Append_To (Expressions (N), Error);
5966 Eval_Conditional_Expression (N);
5967 end Resolve_Conditional_Expression;
5969 -----------------------------------------
5970 -- Resolve_Discrete_Subtype_Indication --
5971 -----------------------------------------
5973 procedure Resolve_Discrete_Subtype_Indication
5981 Analyze (Subtype_Mark (N));
5982 S := Entity (Subtype_Mark (N));
5984 if Nkind (Constraint (N)) /= N_Range_Constraint then
5985 Error_Msg_N ("expect range constraint for discrete type", N);
5986 Set_Etype (N, Any_Type);
5989 R := Range_Expression (Constraint (N));
5997 if Base_Type (S) /= Base_Type (Typ) then
5999 ("expect subtype of }", N, First_Subtype (Typ));
6001 -- Rewrite the constraint as a range of Typ
6002 -- to allow compilation to proceed further.
6005 Rewrite (Low_Bound (R),
6006 Make_Attribute_Reference (Sloc (Low_Bound (R)),
6007 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
6008 Attribute_Name => Name_First));
6009 Rewrite (High_Bound (R),
6010 Make_Attribute_Reference (Sloc (High_Bound (R)),
6011 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
6012 Attribute_Name => Name_First));
6016 Set_Etype (N, Etype (R));
6018 -- Additionally, we must check that the bounds are compatible
6019 -- with the given subtype, which might be different from the
6020 -- type of the context.
6022 Apply_Range_Check (R, S);
6024 -- ??? If the above check statically detects a Constraint_Error
6025 -- it replaces the offending bound(s) of the range R with a
6026 -- Constraint_Error node. When the itype which uses these bounds
6027 -- is frozen the resulting call to Duplicate_Subexpr generates
6028 -- a new temporary for the bounds.
6030 -- Unfortunately there are other itypes that are also made depend
6031 -- on these bounds, so when Duplicate_Subexpr is called they get
6032 -- a forward reference to the newly created temporaries and Gigi
6033 -- aborts on such forward references. This is probably sign of a
6034 -- more fundamental problem somewhere else in either the order of
6035 -- itype freezing or the way certain itypes are constructed.
6037 -- To get around this problem we call Remove_Side_Effects right
6038 -- away if either bounds of R are a Constraint_Error.
6041 L : constant Node_Id := Low_Bound (R);
6042 H : constant Node_Id := High_Bound (R);
6045 if Nkind (L) = N_Raise_Constraint_Error then
6046 Remove_Side_Effects (L);
6049 if Nkind (H) = N_Raise_Constraint_Error then
6050 Remove_Side_Effects (H);
6054 Check_Unset_Reference (Low_Bound (R));
6055 Check_Unset_Reference (High_Bound (R));
6058 end Resolve_Discrete_Subtype_Indication;
6060 -------------------------
6061 -- Resolve_Entity_Name --
6062 -------------------------
6064 -- Used to resolve identifiers and expanded names
6066 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
6067 E : constant Entity_Id := Entity (N);
6070 -- If garbage from errors, set to Any_Type and return
6072 if No (E) and then Total_Errors_Detected /= 0 then
6073 Set_Etype (N, Any_Type);
6077 -- Replace named numbers by corresponding literals. Note that this is
6078 -- the one case where Resolve_Entity_Name must reset the Etype, since
6079 -- it is currently marked as universal.
6081 if Ekind (E) = E_Named_Integer then
6083 Eval_Named_Integer (N);
6085 elsif Ekind (E) = E_Named_Real then
6087 Eval_Named_Real (N);
6089 -- For enumeration literals, we need to make sure that a proper style
6090 -- check is done, since such literals are overloaded, and thus we did
6091 -- not do a style check during the first phase of analysis.
6093 elsif Ekind (E) = E_Enumeration_Literal then
6094 Set_Entity_With_Style_Check (N, E);
6095 Eval_Entity_Name (N);
6097 -- Case of subtype name appearing as an operand in expression
6099 elsif Is_Type (E) then
6101 -- Allow use of subtype if it is a concurrent type where we are
6102 -- currently inside the body. This will eventually be expanded into a
6103 -- call to Self (for tasks) or _object (for protected objects). Any
6104 -- other use of a subtype is invalid.
6106 if Is_Concurrent_Type (E)
6107 and then In_Open_Scopes (E)
6111 -- Any other use is an error
6115 ("invalid use of subtype mark in expression or call", N);
6118 -- Check discriminant use if entity is discriminant in current scope,
6119 -- i.e. discriminant of record or concurrent type currently being
6120 -- analyzed. Uses in corresponding body are unrestricted.
6122 elsif Ekind (E) = E_Discriminant
6123 and then Scope (E) = Current_Scope
6124 and then not Has_Completion (Current_Scope)
6126 Check_Discriminant_Use (N);
6128 -- A parameterless generic function cannot appear in a context that
6129 -- requires resolution.
6131 elsif Ekind (E) = E_Generic_Function then
6132 Error_Msg_N ("illegal use of generic function", N);
6134 elsif Ekind (E) = E_Out_Parameter
6135 and then Ada_Version = Ada_83
6136 and then (Nkind (Parent (N)) in N_Op
6137 or else (Nkind (Parent (N)) = N_Assignment_Statement
6138 and then N = Expression (Parent (N)))
6139 or else Nkind (Parent (N)) = N_Explicit_Dereference)
6141 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
6143 -- In all other cases, just do the possible static evaluation
6146 -- A deferred constant that appears in an expression must have a
6147 -- completion, unless it has been removed by in-place expansion of
6150 if Ekind (E) = E_Constant
6151 and then Comes_From_Source (E)
6152 and then No (Constant_Value (E))
6153 and then Is_Frozen (Etype (E))
6154 and then not In_Spec_Expression
6155 and then not Is_Imported (E)
6157 if No_Initialization (Parent (E))
6158 or else (Present (Full_View (E))
6159 and then No_Initialization (Parent (Full_View (E))))
6164 "deferred constant is frozen before completion", N);
6168 Eval_Entity_Name (N);
6170 end Resolve_Entity_Name;
6176 procedure Resolve_Entry (Entry_Name : Node_Id) is
6177 Loc : constant Source_Ptr := Sloc (Entry_Name);
6185 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
6186 -- If the bounds of the entry family being called depend on task
6187 -- discriminants, build a new index subtype where a discriminant is
6188 -- replaced with the value of the discriminant of the target task.
6189 -- The target task is the prefix of the entry name in the call.
6191 -----------------------
6192 -- Actual_Index_Type --
6193 -----------------------
6195 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
6196 Typ : constant Entity_Id := Entry_Index_Type (E);
6197 Tsk : constant Entity_Id := Scope (E);
6198 Lo : constant Node_Id := Type_Low_Bound (Typ);
6199 Hi : constant Node_Id := Type_High_Bound (Typ);
6202 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
6203 -- If the bound is given by a discriminant, replace with a reference
6204 -- to the discriminant of the same name in the target task. If the
6205 -- entry name is the target of a requeue statement and the entry is
6206 -- in the current protected object, the bound to be used is the
6207 -- discriminal of the object (see Apply_Range_Checks for details of
6208 -- the transformation).
6210 -----------------------------
6211 -- Actual_Discriminant_Ref --
6212 -----------------------------
6214 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
6215 Typ : constant Entity_Id := Etype (Bound);
6219 Remove_Side_Effects (Bound);
6221 if not Is_Entity_Name (Bound)
6222 or else Ekind (Entity (Bound)) /= E_Discriminant
6226 elsif Is_Protected_Type (Tsk)
6227 and then In_Open_Scopes (Tsk)
6228 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
6230 -- Note: here Bound denotes a discriminant of the corresponding
6231 -- record type tskV, whose discriminal is a formal of the
6232 -- init-proc tskVIP. What we want is the body discriminal,
6233 -- which is associated to the discriminant of the original
6234 -- concurrent type tsk.
6236 return New_Occurrence_Of
6237 (Find_Body_Discriminal (Entity (Bound)), Loc);
6241 Make_Selected_Component (Loc,
6242 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
6243 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
6248 end Actual_Discriminant_Ref;
6250 -- Start of processing for Actual_Index_Type
6253 if not Has_Discriminants (Tsk)
6254 or else (not Is_Entity_Name (Lo)
6256 not Is_Entity_Name (Hi))
6258 return Entry_Index_Type (E);
6261 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
6262 Set_Etype (New_T, Base_Type (Typ));
6263 Set_Size_Info (New_T, Typ);
6264 Set_RM_Size (New_T, RM_Size (Typ));
6265 Set_Scalar_Range (New_T,
6266 Make_Range (Sloc (Entry_Name),
6267 Low_Bound => Actual_Discriminant_Ref (Lo),
6268 High_Bound => Actual_Discriminant_Ref (Hi)));
6272 end Actual_Index_Type;
6274 -- Start of processing of Resolve_Entry
6277 -- Find name of entry being called, and resolve prefix of name
6278 -- with its own type. The prefix can be overloaded, and the name
6279 -- and signature of the entry must be taken into account.
6281 if Nkind (Entry_Name) = N_Indexed_Component then
6283 -- Case of dealing with entry family within the current tasks
6285 E_Name := Prefix (Entry_Name);
6288 E_Name := Entry_Name;
6291 if Is_Entity_Name (E_Name) then
6293 -- Entry call to an entry (or entry family) in the current task. This
6294 -- is legal even though the task will deadlock. Rewrite as call to
6297 -- This can also be a call to an entry in an enclosing task. If this
6298 -- is a single task, we have to retrieve its name, because the scope
6299 -- of the entry is the task type, not the object. If the enclosing
6300 -- task is a task type, the identity of the task is given by its own
6303 -- Finally this can be a requeue on an entry of the same task or
6304 -- protected object.
6306 S := Scope (Entity (E_Name));
6308 for J in reverse 0 .. Scope_Stack.Last loop
6309 if Is_Task_Type (Scope_Stack.Table (J).Entity)
6310 and then not Comes_From_Source (S)
6312 -- S is an enclosing task or protected object. The concurrent
6313 -- declaration has been converted into a type declaration, and
6314 -- the object itself has an object declaration that follows
6315 -- the type in the same declarative part.
6317 Tsk := Next_Entity (S);
6318 while Etype (Tsk) /= S loop
6325 elsif S = Scope_Stack.Table (J).Entity then
6327 -- Call to current task. Will be transformed into call to Self
6335 Make_Selected_Component (Loc,
6336 Prefix => New_Occurrence_Of (S, Loc),
6338 New_Occurrence_Of (Entity (E_Name), Loc));
6339 Rewrite (E_Name, New_N);
6342 elsif Nkind (Entry_Name) = N_Selected_Component
6343 and then Is_Overloaded (Prefix (Entry_Name))
6345 -- Use the entry name (which must be unique at this point) to find
6346 -- the prefix that returns the corresponding task type or protected
6350 Pref : constant Node_Id := Prefix (Entry_Name);
6351 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
6356 Get_First_Interp (Pref, I, It);
6357 while Present (It.Typ) loop
6358 if Scope (Ent) = It.Typ then
6359 Set_Etype (Pref, It.Typ);
6363 Get_Next_Interp (I, It);
6368 if Nkind (Entry_Name) = N_Selected_Component then
6369 Resolve (Prefix (Entry_Name));
6371 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6372 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6373 Resolve (Prefix (Prefix (Entry_Name)));
6374 Index := First (Expressions (Entry_Name));
6375 Resolve (Index, Entry_Index_Type (Nam));
6377 -- Up to this point the expression could have been the actual in a
6378 -- simple entry call, and be given by a named association.
6380 if Nkind (Index) = N_Parameter_Association then
6381 Error_Msg_N ("expect expression for entry index", Index);
6383 Apply_Range_Check (Index, Actual_Index_Type (Nam));
6388 ------------------------
6389 -- Resolve_Entry_Call --
6390 ------------------------
6392 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
6393 Entry_Name : constant Node_Id := Name (N);
6394 Loc : constant Source_Ptr := Sloc (Entry_Name);
6396 First_Named : Node_Id;
6403 -- We kill all checks here, because it does not seem worth the effort to
6404 -- do anything better, an entry call is a big operation.
6408 -- Processing of the name is similar for entry calls and protected
6409 -- operation calls. Once the entity is determined, we can complete
6410 -- the resolution of the actuals.
6412 -- The selector may be overloaded, in the case of a protected object
6413 -- with overloaded functions. The type of the context is used for
6416 if Nkind (Entry_Name) = N_Selected_Component
6417 and then Is_Overloaded (Selector_Name (Entry_Name))
6418 and then Typ /= Standard_Void_Type
6425 Get_First_Interp (Selector_Name (Entry_Name), I, It);
6426 while Present (It.Typ) loop
6427 if Covers (Typ, It.Typ) then
6428 Set_Entity (Selector_Name (Entry_Name), It.Nam);
6429 Set_Etype (Entry_Name, It.Typ);
6431 Generate_Reference (It.Typ, N, ' ');
6434 Get_Next_Interp (I, It);
6439 Resolve_Entry (Entry_Name);
6441 if Nkind (Entry_Name) = N_Selected_Component then
6443 -- Simple entry call
6445 Nam := Entity (Selector_Name (Entry_Name));
6446 Obj := Prefix (Entry_Name);
6447 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
6449 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6451 -- Call to member of entry family
6453 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6454 Obj := Prefix (Prefix (Entry_Name));
6455 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
6458 -- We cannot in general check the maximum depth of protected entry
6459 -- calls at compile time. But we can tell that any protected entry
6460 -- call at all violates a specified nesting depth of zero.
6462 if Is_Protected_Type (Scope (Nam)) then
6463 Check_Restriction (Max_Entry_Queue_Length, N);
6466 -- Use context type to disambiguate a protected function that can be
6467 -- called without actuals and that returns an array type, and where
6468 -- the argument list may be an indexing of the returned value.
6470 if Ekind (Nam) = E_Function
6471 and then Needs_No_Actuals (Nam)
6472 and then Present (Parameter_Associations (N))
6474 ((Is_Array_Type (Etype (Nam))
6475 and then Covers (Typ, Component_Type (Etype (Nam))))
6477 or else (Is_Access_Type (Etype (Nam))
6478 and then Is_Array_Type (Designated_Type (Etype (Nam)))
6479 and then Covers (Typ,
6480 Component_Type (Designated_Type (Etype (Nam))))))
6483 Index_Node : Node_Id;
6487 Make_Indexed_Component (Loc,
6489 Make_Function_Call (Loc,
6490 Name => Relocate_Node (Entry_Name)),
6491 Expressions => Parameter_Associations (N));
6493 -- Since we are correcting a node classification error made by
6494 -- the parser, we call Replace rather than Rewrite.
6496 Replace (N, Index_Node);
6497 Set_Etype (Prefix (N), Etype (Nam));
6499 Resolve_Indexed_Component (N, Typ);
6504 if Ekind_In (Nam, E_Entry, E_Entry_Family)
6505 and then Present (PPC_Wrapper (Nam))
6506 and then Current_Scope /= PPC_Wrapper (Nam)
6508 -- Rewrite as call to the precondition wrapper, adding the task
6509 -- object to the list of actuals. If the call is to a member of
6510 -- an entry family, include the index as well.
6514 New_Actuals : List_Id;
6516 New_Actuals := New_List (Obj);
6518 if Nkind (Entry_Name) = N_Indexed_Component then
6519 Append_To (New_Actuals,
6520 New_Copy_Tree (First (Expressions (Entry_Name))));
6523 Append_List (Parameter_Associations (N), New_Actuals);
6525 Make_Procedure_Call_Statement (Loc,
6527 New_Occurrence_Of (PPC_Wrapper (Nam), Loc),
6528 Parameter_Associations => New_Actuals);
6529 Rewrite (N, New_Call);
6530 Analyze_And_Resolve (N);
6535 -- The operation name may have been overloaded. Order the actuals
6536 -- according to the formals of the resolved entity, and set the
6537 -- return type to that of the operation.
6540 Normalize_Actuals (N, Nam, False, Norm_OK);
6541 pragma Assert (Norm_OK);
6542 Set_Etype (N, Etype (Nam));
6545 Resolve_Actuals (N, Nam);
6547 -- Create a call reference to the entry
6549 Generate_Reference (Nam, Entry_Name, 's');
6551 if Ekind_In (Nam, E_Entry, E_Entry_Family) then
6552 Check_Potentially_Blocking_Operation (N);
6555 -- Verify that a procedure call cannot masquerade as an entry
6556 -- call where an entry call is expected.
6558 if Ekind (Nam) = E_Procedure then
6559 if Nkind (Parent (N)) = N_Entry_Call_Alternative
6560 and then N = Entry_Call_Statement (Parent (N))
6562 Error_Msg_N ("entry call required in select statement", N);
6564 elsif Nkind (Parent (N)) = N_Triggering_Alternative
6565 and then N = Triggering_Statement (Parent (N))
6567 Error_Msg_N ("triggering statement cannot be procedure call", N);
6569 elsif Ekind (Scope (Nam)) = E_Task_Type
6570 and then not In_Open_Scopes (Scope (Nam))
6572 Error_Msg_N ("task has no entry with this name", Entry_Name);
6576 -- After resolution, entry calls and protected procedure calls are
6577 -- changed into entry calls, for expansion. The structure of the node
6578 -- does not change, so it can safely be done in place. Protected
6579 -- function calls must keep their structure because they are
6582 if Ekind (Nam) /= E_Function then
6584 -- A protected operation that is not a function may modify the
6585 -- corresponding object, and cannot apply to a constant. If this
6586 -- is an internal call, the prefix is the type itself.
6588 if Is_Protected_Type (Scope (Nam))
6589 and then not Is_Variable (Obj)
6590 and then (not Is_Entity_Name (Obj)
6591 or else not Is_Type (Entity (Obj)))
6594 ("prefix of protected procedure or entry call must be variable",
6598 Actuals := Parameter_Associations (N);
6599 First_Named := First_Named_Actual (N);
6602 Make_Entry_Call_Statement (Loc,
6604 Parameter_Associations => Actuals));
6606 Set_First_Named_Actual (N, First_Named);
6607 Set_Analyzed (N, True);
6609 -- Protected functions can return on the secondary stack, in which
6610 -- case we must trigger the transient scope mechanism.
6612 elsif Expander_Active
6613 and then Requires_Transient_Scope (Etype (Nam))
6615 Establish_Transient_Scope (N, Sec_Stack => True);
6617 end Resolve_Entry_Call;
6619 -------------------------
6620 -- Resolve_Equality_Op --
6621 -------------------------
6623 -- Both arguments must have the same type, and the boolean context does
6624 -- not participate in the resolution. The first pass verifies that the
6625 -- interpretation is not ambiguous, and the type of the left argument is
6626 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6627 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6628 -- though they carry a single (universal) type. Diagnose this case here.
6630 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6631 L : constant Node_Id := Left_Opnd (N);
6632 R : constant Node_Id := Right_Opnd (N);
6633 T : Entity_Id := Find_Unique_Type (L, R);
6635 procedure Check_Conditional_Expression (Cond : Node_Id);
6636 -- The resolution rule for conditional expressions requires that each
6637 -- such must have a unique type. This means that if several dependent
6638 -- expressions are of a non-null anonymous access type, and the context
6639 -- does not impose an expected type (as can be the case in an equality
6640 -- operation) the expression must be rejected.
6642 function Find_Unique_Access_Type return Entity_Id;
6643 -- In the case of allocators, make a last-ditch attempt to find a single
6644 -- access type with the right designated type. This is semantically
6645 -- dubious, and of no interest to any real code, but c48008a makes it
6648 ----------------------------------
6649 -- Check_Conditional_Expression --
6650 ----------------------------------
6652 procedure Check_Conditional_Expression (Cond : Node_Id) is
6653 Then_Expr : Node_Id;
6654 Else_Expr : Node_Id;
6657 if Nkind (Cond) = N_Conditional_Expression then
6658 Then_Expr := Next (First (Expressions (Cond)));
6659 Else_Expr := Next (Then_Expr);
6661 if Nkind (Then_Expr) /= N_Null
6662 and then Nkind (Else_Expr) /= N_Null
6665 ("cannot determine type of conditional expression", Cond);
6668 end Check_Conditional_Expression;
6670 -----------------------------
6671 -- Find_Unique_Access_Type --
6672 -----------------------------
6674 function Find_Unique_Access_Type return Entity_Id is
6680 if Ekind (Etype (R)) = E_Allocator_Type then
6681 Acc := Designated_Type (Etype (R));
6682 elsif Ekind (Etype (L)) = E_Allocator_Type then
6683 Acc := Designated_Type (Etype (L));
6689 while S /= Standard_Standard loop
6690 E := First_Entity (S);
6691 while Present (E) loop
6693 and then Is_Access_Type (E)
6694 and then Ekind (E) /= E_Allocator_Type
6695 and then Designated_Type (E) = Base_Type (Acc)
6707 end Find_Unique_Access_Type;
6709 -- Start of processing for Resolve_Equality_Op
6712 Set_Etype (N, Base_Type (Typ));
6713 Generate_Reference (T, N, ' ');
6715 if T = Any_Fixed then
6716 T := Unique_Fixed_Point_Type (L);
6719 if T /= Any_Type then
6721 or else T = Any_Composite
6722 or else T = Any_Character
6724 if T = Any_Character then
6725 Ambiguous_Character (L);
6727 Error_Msg_N ("ambiguous operands for equality", N);
6730 Set_Etype (N, Any_Type);
6733 elsif T = Any_Access
6734 or else Ekind_In (T, E_Allocator_Type, E_Access_Attribute_Type)
6736 T := Find_Unique_Access_Type;
6739 Error_Msg_N ("ambiguous operands for equality", N);
6740 Set_Etype (N, Any_Type);
6744 -- Conditional expressions must have a single type, and if the
6745 -- context does not impose one the dependent expressions cannot
6746 -- be anonymous access types.
6748 elsif Ada_Version >= Ada_2012
6749 and then Ekind_In (Etype (L), E_Anonymous_Access_Type,
6750 E_Anonymous_Access_Subprogram_Type)
6751 and then Ekind_In (Etype (R), E_Anonymous_Access_Type,
6752 E_Anonymous_Access_Subprogram_Type)
6754 Check_Conditional_Expression (L);
6755 Check_Conditional_Expression (R);
6761 -- In SPARK or ALFA, equality operators = and /= for array types
6762 -- other than String are only defined when, for each index position,
6763 -- the operands have equal static bounds.
6765 if Formal_Verification_Mode
6766 and then Comes_From_Source (Original_Node (N))
6767 and then Is_Array_Type (T)
6768 and then Base_Type (T) /= Standard_String
6769 and then not Matching_Static_Array_Bounds (Etype (L), Etype (R))
6772 ("|~~array types should have matching static bounds", N);
6775 -- If the unique type is a class-wide type then it will be expanded
6776 -- into a dispatching call to the predefined primitive. Therefore we
6777 -- check here for potential violation of such restriction.
6779 if Is_Class_Wide_Type (T) then
6780 Check_Restriction (No_Dispatching_Calls, N);
6783 if Warn_On_Redundant_Constructs
6784 and then Comes_From_Source (N)
6785 and then Is_Entity_Name (R)
6786 and then Entity (R) = Standard_True
6787 and then Comes_From_Source (R)
6789 Error_Msg_N -- CODEFIX
6790 ("?comparison with True is redundant!", R);
6793 Check_Unset_Reference (L);
6794 Check_Unset_Reference (R);
6795 Generate_Operator_Reference (N, T);
6796 Check_Low_Bound_Tested (N);
6798 -- If this is an inequality, it may be the implicit inequality
6799 -- created for a user-defined operation, in which case the corres-
6800 -- ponding equality operation is not intrinsic, and the operation
6801 -- cannot be constant-folded. Else fold.
6803 if Nkind (N) = N_Op_Eq
6804 or else Comes_From_Source (Entity (N))
6805 or else Ekind (Entity (N)) = E_Operator
6806 or else Is_Intrinsic_Subprogram
6807 (Corresponding_Equality (Entity (N)))
6809 Eval_Relational_Op (N);
6811 elsif Nkind (N) = N_Op_Ne
6812 and then Is_Abstract_Subprogram (Entity (N))
6814 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6817 -- Ada 2005: If one operand is an anonymous access type, convert the
6818 -- other operand to it, to ensure that the underlying types match in
6819 -- the back-end. Same for access_to_subprogram, and the conversion
6820 -- verifies that the types are subtype conformant.
6822 -- We apply the same conversion in the case one of the operands is a
6823 -- private subtype of the type of the other.
6825 -- Why the Expander_Active test here ???
6829 (Ekind_In (T, E_Anonymous_Access_Type,
6830 E_Anonymous_Access_Subprogram_Type)
6831 or else Is_Private_Type (T))
6833 if Etype (L) /= T then
6835 Make_Unchecked_Type_Conversion (Sloc (L),
6836 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6837 Expression => Relocate_Node (L)));
6838 Analyze_And_Resolve (L, T);
6841 if (Etype (R)) /= T then
6843 Make_Unchecked_Type_Conversion (Sloc (R),
6844 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6845 Expression => Relocate_Node (R)));
6846 Analyze_And_Resolve (R, T);
6850 end Resolve_Equality_Op;
6852 ----------------------------------
6853 -- Resolve_Explicit_Dereference --
6854 ----------------------------------
6856 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6857 Loc : constant Source_Ptr := Sloc (N);
6859 P : constant Node_Id := Prefix (N);
6864 Check_Fully_Declared_Prefix (Typ, P);
6866 if Is_Overloaded (P) then
6868 -- Use the context type to select the prefix that has the correct
6871 Get_First_Interp (P, I, It);
6872 while Present (It.Typ) loop
6873 exit when Is_Access_Type (It.Typ)
6874 and then Covers (Typ, Designated_Type (It.Typ));
6875 Get_Next_Interp (I, It);
6878 if Present (It.Typ) then
6879 Resolve (P, It.Typ);
6881 -- If no interpretation covers the designated type of the prefix,
6882 -- this is the pathological case where not all implementations of
6883 -- the prefix allow the interpretation of the node as a call. Now
6884 -- that the expected type is known, Remove other interpretations
6885 -- from prefix, rewrite it as a call, and resolve again, so that
6886 -- the proper call node is generated.
6888 Get_First_Interp (P, I, It);
6889 while Present (It.Typ) loop
6890 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6894 Get_Next_Interp (I, It);
6898 Make_Function_Call (Loc,
6900 Make_Explicit_Dereference (Loc,
6902 Parameter_Associations => New_List);
6904 Save_Interps (N, New_N);
6906 Analyze_And_Resolve (N, Typ);
6910 Set_Etype (N, Designated_Type (It.Typ));
6916 if Is_Access_Type (Etype (P)) then
6917 Apply_Access_Check (N);
6920 -- If the designated type is a packed unconstrained array type, and the
6921 -- explicit dereference is not in the context of an attribute reference,
6922 -- then we must compute and set the actual subtype, since it is needed
6923 -- by Gigi. The reason we exclude the attribute case is that this is
6924 -- handled fine by Gigi, and in fact we use such attributes to build the
6925 -- actual subtype. We also exclude generated code (which builds actual
6926 -- subtypes directly if they are needed).
6928 if Is_Array_Type (Etype (N))
6929 and then Is_Packed (Etype (N))
6930 and then not Is_Constrained (Etype (N))
6931 and then Nkind (Parent (N)) /= N_Attribute_Reference
6932 and then Comes_From_Source (N)
6934 Set_Etype (N, Get_Actual_Subtype (N));
6937 -- Note: No Eval processing is required for an explicit dereference,
6938 -- because such a name can never be static.
6940 end Resolve_Explicit_Dereference;
6942 -------------------------------------
6943 -- Resolve_Expression_With_Actions --
6944 -------------------------------------
6946 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id) is
6949 end Resolve_Expression_With_Actions;
6951 -------------------------------
6952 -- Resolve_Indexed_Component --
6953 -------------------------------
6955 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
6956 Name : constant Node_Id := Prefix (N);
6958 Array_Type : Entity_Id := Empty; -- to prevent junk warning
6962 if Is_Overloaded (Name) then
6964 -- Use the context type to select the prefix that yields the correct
6970 I1 : Interp_Index := 0;
6971 P : constant Node_Id := Prefix (N);
6972 Found : Boolean := False;
6975 Get_First_Interp (P, I, It);
6976 while Present (It.Typ) loop
6977 if (Is_Array_Type (It.Typ)
6978 and then Covers (Typ, Component_Type (It.Typ)))
6979 or else (Is_Access_Type (It.Typ)
6980 and then Is_Array_Type (Designated_Type (It.Typ))
6982 (Typ, Component_Type (Designated_Type (It.Typ))))
6985 It := Disambiguate (P, I1, I, Any_Type);
6987 if It = No_Interp then
6988 Error_Msg_N ("ambiguous prefix for indexing", N);
6994 Array_Type := It.Typ;
7000 Array_Type := It.Typ;
7005 Get_Next_Interp (I, It);
7010 Array_Type := Etype (Name);
7013 Resolve (Name, Array_Type);
7014 Array_Type := Get_Actual_Subtype_If_Available (Name);
7016 -- If prefix is access type, dereference to get real array type.
7017 -- Note: we do not apply an access check because the expander always
7018 -- introduces an explicit dereference, and the check will happen there.
7020 if Is_Access_Type (Array_Type) then
7021 Array_Type := Designated_Type (Array_Type);
7024 -- If name was overloaded, set component type correctly now
7025 -- If a misplaced call to an entry family (which has no index types)
7026 -- return. Error will be diagnosed from calling context.
7028 if Is_Array_Type (Array_Type) then
7029 Set_Etype (N, Component_Type (Array_Type));
7034 Index := First_Index (Array_Type);
7035 Expr := First (Expressions (N));
7037 -- The prefix may have resolved to a string literal, in which case its
7038 -- etype has a special representation. This is only possible currently
7039 -- if the prefix is a static concatenation, written in functional
7042 if Ekind (Array_Type) = E_String_Literal_Subtype then
7043 Resolve (Expr, Standard_Positive);
7046 while Present (Index) and Present (Expr) loop
7047 Resolve (Expr, Etype (Index));
7048 Check_Unset_Reference (Expr);
7050 if Is_Scalar_Type (Etype (Expr)) then
7051 Apply_Scalar_Range_Check (Expr, Etype (Index));
7053 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
7061 -- Do not generate the warning on suspicious index if we are analyzing
7062 -- package Ada.Tags; otherwise we will report the warning with the
7063 -- Prims_Ptr field of the dispatch table.
7065 if Scope (Etype (Prefix (N))) = Standard_Standard
7067 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
7070 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
7071 Eval_Indexed_Component (N);
7074 -- If the array type is atomic, and is packed, and we are in a left side
7075 -- context, then this is worth a warning, since we have a situation
7076 -- where the access to the component may cause extra read/writes of
7077 -- the atomic array object, which could be considered unexpected.
7079 if Nkind (N) = N_Indexed_Component
7080 and then (Is_Atomic (Array_Type)
7081 or else (Is_Entity_Name (Prefix (N))
7082 and then Is_Atomic (Entity (Prefix (N)))))
7083 and then Is_Bit_Packed_Array (Array_Type)
7086 Error_Msg_N ("?assignment to component of packed atomic array",
7088 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
7091 end Resolve_Indexed_Component;
7093 -----------------------------
7094 -- Resolve_Integer_Literal --
7095 -----------------------------
7097 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
7100 Eval_Integer_Literal (N);
7101 end Resolve_Integer_Literal;
7103 --------------------------------
7104 -- Resolve_Intrinsic_Operator --
7105 --------------------------------
7107 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
7108 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
7110 Orig_Op : constant Entity_Id := Entity (N);
7115 -- We must preserve the original entity in a generic setting, so that
7116 -- the legality of the operation can be verified in an instance.
7118 if not Expander_Active then
7123 while Scope (Op) /= Standard_Standard loop
7125 pragma Assert (Present (Op));
7129 Set_Is_Overloaded (N, False);
7131 -- If the operand type is private, rewrite with suitable conversions on
7132 -- the operands and the result, to expose the proper underlying numeric
7135 if Is_Private_Type (Typ) then
7136 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
7138 if Nkind (N) = N_Op_Expon then
7139 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
7141 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7144 if Nkind (Arg1) = N_Type_Conversion then
7145 Save_Interps (Left_Opnd (N), Expression (Arg1));
7148 if Nkind (Arg2) = N_Type_Conversion then
7149 Save_Interps (Right_Opnd (N), Expression (Arg2));
7152 Set_Left_Opnd (N, Arg1);
7153 Set_Right_Opnd (N, Arg2);
7155 Set_Etype (N, Btyp);
7156 Rewrite (N, Unchecked_Convert_To (Typ, N));
7159 elsif Typ /= Etype (Left_Opnd (N))
7160 or else Typ /= Etype (Right_Opnd (N))
7162 -- Add explicit conversion where needed, and save interpretations in
7163 -- case operands are overloaded. If the context is a VMS operation,
7164 -- assert that the conversion is legal (the operands have the proper
7165 -- types to select the VMS intrinsic). Note that in rare cases the
7166 -- VMS operators may be visible, but the default System is being used
7167 -- and Address is a private type.
7169 Arg1 := Convert_To (Typ, Left_Opnd (N));
7170 Arg2 := Convert_To (Typ, Right_Opnd (N));
7172 if Nkind (Arg1) = N_Type_Conversion then
7173 Save_Interps (Left_Opnd (N), Expression (Arg1));
7175 if Is_VMS_Operator (Orig_Op) then
7176 Set_Conversion_OK (Arg1);
7179 Save_Interps (Left_Opnd (N), Arg1);
7182 if Nkind (Arg2) = N_Type_Conversion then
7183 Save_Interps (Right_Opnd (N), Expression (Arg2));
7185 if Is_VMS_Operator (Orig_Op) then
7186 Set_Conversion_OK (Arg2);
7189 Save_Interps (Right_Opnd (N), Arg2);
7192 Rewrite (Left_Opnd (N), Arg1);
7193 Rewrite (Right_Opnd (N), Arg2);
7196 Resolve_Arithmetic_Op (N, Typ);
7199 Resolve_Arithmetic_Op (N, Typ);
7201 end Resolve_Intrinsic_Operator;
7203 --------------------------------------
7204 -- Resolve_Intrinsic_Unary_Operator --
7205 --------------------------------------
7207 procedure Resolve_Intrinsic_Unary_Operator
7211 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
7217 while Scope (Op) /= Standard_Standard loop
7219 pragma Assert (Present (Op));
7224 if Is_Private_Type (Typ) then
7225 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7226 Save_Interps (Right_Opnd (N), Expression (Arg2));
7228 Set_Right_Opnd (N, Arg2);
7230 Set_Etype (N, Btyp);
7231 Rewrite (N, Unchecked_Convert_To (Typ, N));
7235 Resolve_Unary_Op (N, Typ);
7237 end Resolve_Intrinsic_Unary_Operator;
7239 ------------------------
7240 -- Resolve_Logical_Op --
7241 ------------------------
7243 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
7247 Check_No_Direct_Boolean_Operators (N);
7249 -- Predefined operations on scalar types yield the base type. On the
7250 -- other hand, logical operations on arrays yield the type of the
7251 -- arguments (and the context).
7253 if Is_Array_Type (Typ) then
7256 B_Typ := Base_Type (Typ);
7259 -- OK if this is a VMS-specific intrinsic operation
7261 if Is_VMS_Operator (Entity (N)) then
7264 -- The following test is required because the operands of the operation
7265 -- may be literals, in which case the resulting type appears to be
7266 -- compatible with a signed integer type, when in fact it is compatible
7267 -- only with modular types. If the context itself is universal, the
7268 -- operation is illegal.
7270 elsif not Valid_Boolean_Arg (Typ) then
7271 Error_Msg_N ("invalid context for logical operation", N);
7272 Set_Etype (N, Any_Type);
7275 elsif Typ = Any_Modular then
7277 ("no modular type available in this context", N);
7278 Set_Etype (N, Any_Type);
7280 elsif Is_Modular_Integer_Type (Typ)
7281 and then Etype (Left_Opnd (N)) = Universal_Integer
7282 and then Etype (Right_Opnd (N)) = Universal_Integer
7284 Check_For_Visible_Operator (N, B_Typ);
7287 Resolve (Left_Opnd (N), B_Typ);
7288 Resolve (Right_Opnd (N), B_Typ);
7290 Check_Unset_Reference (Left_Opnd (N));
7291 Check_Unset_Reference (Right_Opnd (N));
7293 Set_Etype (N, B_Typ);
7294 Generate_Operator_Reference (N, B_Typ);
7295 Eval_Logical_Op (N);
7297 -- In SPARK or ALFA, logical operations AND, OR and XOR for arrays are
7298 -- defined only when both operands have same static lower and higher
7301 if Formal_Verification_Mode
7302 and then Comes_From_Source (Original_Node (N))
7303 and then Is_Array_Type (B_Typ)
7304 and then not Matching_Static_Array_Bounds (Etype (Left_Opnd (N)),
7305 Etype (Right_Opnd (N)))
7307 Error_Msg_F ("|~~array types should have matching static bounds", N);
7310 end Resolve_Logical_Op;
7312 ---------------------------
7313 -- Resolve_Membership_Op --
7314 ---------------------------
7316 -- The context can only be a boolean type, and does not determine
7317 -- the arguments. Arguments should be unambiguous, but the preference
7318 -- rule for universal types applies.
7320 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
7321 pragma Warnings (Off, Typ);
7323 L : constant Node_Id := Left_Opnd (N);
7324 R : constant Node_Id := Right_Opnd (N);
7327 procedure Resolve_Set_Membership;
7328 -- Analysis has determined a unique type for the left operand.
7329 -- Use it to resolve the disjuncts.
7331 ----------------------------
7332 -- Resolve_Set_Membership --
7333 ----------------------------
7335 procedure Resolve_Set_Membership is
7339 Resolve (L, Etype (L));
7341 Alt := First (Alternatives (N));
7342 while Present (Alt) loop
7344 -- Alternative is an expression, a range
7345 -- or a subtype mark.
7347 if not Is_Entity_Name (Alt)
7348 or else not Is_Type (Entity (Alt))
7350 Resolve (Alt, Etype (L));
7355 end Resolve_Set_Membership;
7357 -- Start of processing for Resolve_Membership_Op
7360 if L = Error or else R = Error then
7364 if Present (Alternatives (N)) then
7365 Resolve_Set_Membership;
7368 elsif not Is_Overloaded (R)
7370 (Etype (R) = Universal_Integer or else
7371 Etype (R) = Universal_Real)
7372 and then Is_Overloaded (L)
7376 -- Ada 2005 (AI-251): Support the following case:
7378 -- type I is interface;
7379 -- type T is tagged ...
7381 -- function Test (O : I'Class) is
7383 -- return O in T'Class.
7386 -- In this case we have nothing else to do. The membership test will be
7387 -- done at run time.
7389 elsif Ada_Version >= Ada_2005
7390 and then Is_Class_Wide_Type (Etype (L))
7391 and then Is_Interface (Etype (L))
7392 and then Is_Class_Wide_Type (Etype (R))
7393 and then not Is_Interface (Etype (R))
7398 T := Intersect_Types (L, R);
7401 -- If mixed-mode operations are present and operands are all literal,
7402 -- the only interpretation involves Duration, which is probably not
7403 -- the intention of the programmer.
7405 if T = Any_Fixed then
7406 T := Unique_Fixed_Point_Type (N);
7408 if T = Any_Type then
7414 Check_Unset_Reference (L);
7416 if Nkind (R) = N_Range
7417 and then not Is_Scalar_Type (T)
7419 Error_Msg_N ("scalar type required for range", R);
7422 if Is_Entity_Name (R) then
7423 Freeze_Expression (R);
7426 Check_Unset_Reference (R);
7429 Eval_Membership_Op (N);
7430 end Resolve_Membership_Op;
7436 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
7437 Loc : constant Source_Ptr := Sloc (N);
7440 -- Handle restriction against anonymous null access values This
7441 -- restriction can be turned off using -gnatdj.
7443 -- Ada 2005 (AI-231): Remove restriction
7445 if Ada_Version < Ada_2005
7446 and then not Debug_Flag_J
7447 and then Ekind (Typ) = E_Anonymous_Access_Type
7448 and then Comes_From_Source (N)
7450 -- In the common case of a call which uses an explicitly null value
7451 -- for an access parameter, give specialized error message.
7453 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
7457 ("null is not allowed as argument for an access parameter", N);
7459 -- Standard message for all other cases (are there any?)
7463 ("null cannot be of an anonymous access type", N);
7467 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
7468 -- assignment to a null-excluding object
7470 if Ada_Version >= Ada_2005
7471 and then Can_Never_Be_Null (Typ)
7472 and then Nkind (Parent (N)) = N_Assignment_Statement
7474 if not Inside_Init_Proc then
7476 (Compile_Time_Constraint_Error (N,
7477 "(Ada 2005) null not allowed in null-excluding objects?"),
7478 Make_Raise_Constraint_Error (Loc,
7479 Reason => CE_Access_Check_Failed));
7482 Make_Raise_Constraint_Error (Loc,
7483 Reason => CE_Access_Check_Failed));
7487 -- In a distributed context, null for a remote access to subprogram may
7488 -- need to be replaced with a special record aggregate. In this case,
7489 -- return after having done the transformation.
7491 if (Ekind (Typ) = E_Record_Type
7492 or else Is_Remote_Access_To_Subprogram_Type (Typ))
7493 and then Remote_AST_Null_Value (N, Typ)
7498 -- The null literal takes its type from the context
7503 -----------------------
7504 -- Resolve_Op_Concat --
7505 -----------------------
7507 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
7509 -- We wish to avoid deep recursion, because concatenations are often
7510 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
7511 -- operands nonrecursively until we find something that is not a simple
7512 -- concatenation (A in this case). We resolve that, and then walk back
7513 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
7514 -- to do the rest of the work at each level. The Parent pointers allow
7515 -- us to avoid recursion, and thus avoid running out of memory. See also
7516 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
7522 -- The following code is equivalent to:
7524 -- Resolve_Op_Concat_First (NN, Typ);
7525 -- Resolve_Op_Concat_Arg (N, ...);
7526 -- Resolve_Op_Concat_Rest (N, Typ);
7528 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
7529 -- operand is a concatenation.
7531 -- Walk down left operands
7534 Resolve_Op_Concat_First (NN, Typ);
7535 Op1 := Left_Opnd (NN);
7536 exit when not (Nkind (Op1) = N_Op_Concat
7537 and then not Is_Array_Type (Component_Type (Typ))
7538 and then Entity (Op1) = Entity (NN));
7542 -- Now (given the above example) NN is A&B and Op1 is A
7544 -- First resolve Op1 ...
7546 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
7548 -- ... then walk NN back up until we reach N (where we started), calling
7549 -- Resolve_Op_Concat_Rest along the way.
7552 Resolve_Op_Concat_Rest (NN, Typ);
7557 if Formal_Verification_Mode
7558 and then Base_Type (Etype (N)) /= Standard_String
7560 Error_Msg_F ("|~~result of concatenation should have type String", N);
7562 end Resolve_Op_Concat;
7564 ---------------------------
7565 -- Resolve_Op_Concat_Arg --
7566 ---------------------------
7568 procedure Resolve_Op_Concat_Arg
7574 Btyp : constant Entity_Id := Base_Type (Typ);
7579 or else (not Is_Overloaded (Arg)
7580 and then Etype (Arg) /= Any_Composite
7581 and then Covers (Component_Type (Typ), Etype (Arg)))
7583 Resolve (Arg, Component_Type (Typ));
7585 Resolve (Arg, Btyp);
7588 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
7589 if Nkind (Arg) = N_Aggregate
7590 and then Is_Composite_Type (Component_Type (Typ))
7592 if Is_Private_Type (Component_Type (Typ)) then
7593 Resolve (Arg, Btyp);
7595 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
7596 Set_Etype (Arg, Any_Type);
7600 if Is_Overloaded (Arg)
7601 and then Has_Compatible_Type (Arg, Typ)
7602 and then Etype (Arg) /= Any_Type
7610 Get_First_Interp (Arg, I, It);
7612 Get_Next_Interp (I, It);
7614 -- Special-case the error message when the overloading is
7615 -- caused by a function that yields an array and can be
7616 -- called without parameters.
7618 if It.Nam = Func then
7619 Error_Msg_Sloc := Sloc (Func);
7620 Error_Msg_N ("ambiguous call to function#", Arg);
7622 ("\\interpretation as call yields&", Arg, Typ);
7624 ("\\interpretation as indexing of call yields&",
7625 Arg, Component_Type (Typ));
7629 ("ambiguous operand for concatenation!", Arg);
7630 Get_First_Interp (Arg, I, It);
7631 while Present (It.Nam) loop
7632 Error_Msg_Sloc := Sloc (It.Nam);
7634 if Base_Type (It.Typ) = Base_Type (Typ)
7635 or else Base_Type (It.Typ) =
7636 Base_Type (Component_Type (Typ))
7638 Error_Msg_N -- CODEFIX
7639 ("\\possible interpretation#", Arg);
7642 Get_Next_Interp (I, It);
7648 Resolve (Arg, Component_Type (Typ));
7650 if Nkind (Arg) = N_String_Literal then
7651 Set_Etype (Arg, Component_Type (Typ));
7654 if Arg = Left_Opnd (N) then
7655 Set_Is_Component_Left_Opnd (N);
7657 Set_Is_Component_Right_Opnd (N);
7662 Resolve (Arg, Btyp);
7665 -- Concatenation is restricted in SPARK or ALFA: each operand must be
7666 -- either a string literal, a static character expression, or another
7667 -- concatenation. Arg cannot be a concatenation here as callers of
7668 -- Resolve_Op_Concat_Arg call it separately on each final operand, past
7669 -- concatenation operations.
7671 if Formal_Verification_Mode then
7672 if Is_Character_Type (Etype (Arg)) then
7673 if not Is_Static_Expression (Arg) then
7674 Error_Msg_F ("|~~character operand for concatenation should be "
7678 elsif Is_String_Type (Etype (Arg)) then
7679 if Nkind (Arg) /= N_String_Literal then
7680 Error_Msg_F ("|~~string operand for concatenation should be "
7684 -- Do not issue error on an operand that is neither a character nor
7685 -- a string, as the error is issued in Resolve_Op_Concat.
7692 Check_Unset_Reference (Arg);
7693 end Resolve_Op_Concat_Arg;
7695 -----------------------------
7696 -- Resolve_Op_Concat_First --
7697 -----------------------------
7699 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
7700 Btyp : constant Entity_Id := Base_Type (Typ);
7701 Op1 : constant Node_Id := Left_Opnd (N);
7702 Op2 : constant Node_Id := Right_Opnd (N);
7705 -- The parser folds an enormous sequence of concatenations of string
7706 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
7707 -- in the right operand. If the expression resolves to a predefined "&"
7708 -- operator, all is well. Otherwise, the parser's folding is wrong, so
7709 -- we give an error. See P_Simple_Expression in Par.Ch4.
7711 if Nkind (Op2) = N_String_Literal
7712 and then Is_Folded_In_Parser (Op2)
7713 and then Ekind (Entity (N)) = E_Function
7715 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
7716 and then String_Length (Strval (Op1)) = 0);
7717 Error_Msg_N ("too many user-defined concatenations", N);
7721 Set_Etype (N, Btyp);
7723 if Is_Limited_Composite (Btyp) then
7724 Error_Msg_N ("concatenation not available for limited array", N);
7725 Explain_Limited_Type (Btyp, N);
7727 end Resolve_Op_Concat_First;
7729 ----------------------------
7730 -- Resolve_Op_Concat_Rest --
7731 ----------------------------
7733 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
7734 Op1 : constant Node_Id := Left_Opnd (N);
7735 Op2 : constant Node_Id := Right_Opnd (N);
7738 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
7740 Generate_Operator_Reference (N, Typ);
7742 if Is_String_Type (Typ) then
7743 Eval_Concatenation (N);
7746 -- If this is not a static concatenation, but the result is a string
7747 -- type (and not an array of strings) ensure that static string operands
7748 -- have their subtypes properly constructed.
7750 if Nkind (N) /= N_String_Literal
7751 and then Is_Character_Type (Component_Type (Typ))
7753 Set_String_Literal_Subtype (Op1, Typ);
7754 Set_String_Literal_Subtype (Op2, Typ);
7756 end Resolve_Op_Concat_Rest;
7758 ----------------------
7759 -- Resolve_Op_Expon --
7760 ----------------------
7762 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
7763 B_Typ : constant Entity_Id := Base_Type (Typ);
7766 -- Catch attempts to do fixed-point exponentiation with universal
7767 -- operands, which is a case where the illegality is not caught during
7768 -- normal operator analysis.
7770 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
7771 Error_Msg_N ("exponentiation not available for fixed point", N);
7775 if Comes_From_Source (N)
7776 and then Ekind (Entity (N)) = E_Function
7777 and then Is_Imported (Entity (N))
7778 and then Is_Intrinsic_Subprogram (Entity (N))
7780 Resolve_Intrinsic_Operator (N, Typ);
7784 if Etype (Left_Opnd (N)) = Universal_Integer
7785 or else Etype (Left_Opnd (N)) = Universal_Real
7787 Check_For_Visible_Operator (N, B_Typ);
7790 -- We do the resolution using the base type, because intermediate values
7791 -- in expressions always are of the base type, not a subtype of it.
7793 Resolve (Left_Opnd (N), B_Typ);
7794 Resolve (Right_Opnd (N), Standard_Integer);
7796 Check_Unset_Reference (Left_Opnd (N));
7797 Check_Unset_Reference (Right_Opnd (N));
7799 Set_Etype (N, B_Typ);
7800 Generate_Operator_Reference (N, B_Typ);
7803 -- Set overflow checking bit. Much cleverer code needed here eventually
7804 -- and perhaps the Resolve routines should be separated for the various
7805 -- arithmetic operations, since they will need different processing. ???
7807 if Nkind (N) in N_Op then
7808 if not Overflow_Checks_Suppressed (Etype (N)) then
7809 Enable_Overflow_Check (N);
7812 end Resolve_Op_Expon;
7814 --------------------
7815 -- Resolve_Op_Not --
7816 --------------------
7818 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
7821 function Parent_Is_Boolean return Boolean;
7822 -- This function determines if the parent node is a boolean operator
7823 -- or operation (comparison op, membership test, or short circuit form)
7824 -- and the not in question is the left operand of this operation.
7825 -- Note that if the not is in parens, then false is returned.
7827 -----------------------
7828 -- Parent_Is_Boolean --
7829 -----------------------
7831 function Parent_Is_Boolean return Boolean is
7833 if Paren_Count (N) /= 0 then
7837 case Nkind (Parent (N)) is
7852 return Left_Opnd (Parent (N)) = N;
7858 end Parent_Is_Boolean;
7860 -- Start of processing for Resolve_Op_Not
7863 -- Predefined operations on scalar types yield the base type. On the
7864 -- other hand, logical operations on arrays yield the type of the
7865 -- arguments (and the context).
7867 if Is_Array_Type (Typ) then
7870 B_Typ := Base_Type (Typ);
7873 if Is_VMS_Operator (Entity (N)) then
7876 -- Straightforward case of incorrect arguments
7878 elsif not Valid_Boolean_Arg (Typ) then
7879 Error_Msg_N ("invalid operand type for operator&", N);
7880 Set_Etype (N, Any_Type);
7883 -- Special case of probable missing parens
7885 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7886 if Parent_Is_Boolean then
7888 ("operand of not must be enclosed in parentheses",
7892 ("no modular type available in this context", N);
7895 Set_Etype (N, Any_Type);
7898 -- OK resolution of not
7901 -- Warn if non-boolean types involved. This is a case like not a < b
7902 -- where a and b are modular, where we will get (not a) < b and most
7903 -- likely not (a < b) was intended.
7905 if Warn_On_Questionable_Missing_Parens
7906 and then not Is_Boolean_Type (Typ)
7907 and then Parent_Is_Boolean
7909 Error_Msg_N ("?not expression should be parenthesized here!", N);
7912 -- Warn on double negation if checking redundant constructs
7914 if Warn_On_Redundant_Constructs
7915 and then Comes_From_Source (N)
7916 and then Comes_From_Source (Right_Opnd (N))
7917 and then Root_Type (Typ) = Standard_Boolean
7918 and then Nkind (Right_Opnd (N)) = N_Op_Not
7920 Error_Msg_N ("redundant double negation?", N);
7923 -- Complete resolution and evaluation of NOT
7925 Resolve (Right_Opnd (N), B_Typ);
7926 Check_Unset_Reference (Right_Opnd (N));
7927 Set_Etype (N, B_Typ);
7928 Generate_Operator_Reference (N, B_Typ);
7933 -----------------------------
7934 -- Resolve_Operator_Symbol --
7935 -----------------------------
7937 -- Nothing to be done, all resolved already
7939 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
7940 pragma Warnings (Off, N);
7941 pragma Warnings (Off, Typ);
7945 end Resolve_Operator_Symbol;
7947 ----------------------------------
7948 -- Resolve_Qualified_Expression --
7949 ----------------------------------
7951 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
7952 pragma Warnings (Off, Typ);
7954 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
7955 Expr : constant Node_Id := Expression (N);
7958 Resolve (Expr, Target_Typ);
7960 if Formal_Verification_Mode
7961 and then Comes_From_Source (Original_Node (N))
7962 and then Is_Array_Type (Target_Typ)
7963 and then Is_Array_Type (Etype (Expr))
7964 and then not Matching_Static_Array_Bounds (Target_Typ, Etype (Expr))
7966 Error_Msg_F ("|~~array types should have matching static bounds", N);
7969 -- A qualified expression requires an exact match of the type,
7970 -- class-wide matching is not allowed. However, if the qualifying
7971 -- type is specific and the expression has a class-wide type, it
7972 -- may still be okay, since it can be the result of the expansion
7973 -- of a call to a dispatching function, so we also have to check
7974 -- class-wideness of the type of the expression's original node.
7976 if (Is_Class_Wide_Type (Target_Typ)
7978 (Is_Class_Wide_Type (Etype (Expr))
7979 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
7980 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
7982 Wrong_Type (Expr, Target_Typ);
7985 -- If the target type is unconstrained, then we reset the type of the
7986 -- result from the type of the expression. For other cases, the actual
7987 -- subtype of the expression is the target type.
7989 if Is_Composite_Type (Target_Typ)
7990 and then not Is_Constrained (Target_Typ)
7992 Set_Etype (N, Etype (Expr));
7995 Eval_Qualified_Expression (N);
7996 end Resolve_Qualified_Expression;
7998 -----------------------------------
7999 -- Resolve_Quantified_Expression --
8000 -----------------------------------
8002 procedure Resolve_Quantified_Expression (N : Node_Id; Typ : Entity_Id) is
8004 -- The loop structure is already resolved during its analysis, only the
8005 -- resolution of the condition needs to be done. Expansion is disabled
8006 -- so that checks and other generated code are inserted in the tree
8007 -- after expression has been rewritten as a loop.
8009 Expander_Mode_Save_And_Set (False);
8010 Resolve (Condition (N), Typ);
8011 Expander_Mode_Restore;
8012 end Resolve_Quantified_Expression;
8018 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
8019 L : constant Node_Id := Low_Bound (N);
8020 H : constant Node_Id := High_Bound (N);
8022 function First_Last_Ref return Boolean;
8023 -- Returns True if N is of the form X'First .. X'Last where X is the
8024 -- same entity for both attributes.
8026 --------------------
8027 -- First_Last_Ref --
8028 --------------------
8030 function First_Last_Ref return Boolean is
8031 Lorig : constant Node_Id := Original_Node (L);
8032 Horig : constant Node_Id := Original_Node (H);
8035 if Nkind (Lorig) = N_Attribute_Reference
8036 and then Nkind (Horig) = N_Attribute_Reference
8037 and then Attribute_Name (Lorig) = Name_First
8038 and then Attribute_Name (Horig) = Name_Last
8041 PL : constant Node_Id := Prefix (Lorig);
8042 PH : constant Node_Id := Prefix (Horig);
8044 if Is_Entity_Name (PL)
8045 and then Is_Entity_Name (PH)
8046 and then Entity (PL) = Entity (PH)
8056 -- Start of processing for Resolve_Range
8063 -- Check for inappropriate range on unordered enumeration type
8065 if Bad_Unordered_Enumeration_Reference (N, Typ)
8067 -- Exclude X'First .. X'Last if X is the same entity for both
8069 and then not First_Last_Ref
8071 Error_Msg ("subrange of unordered enumeration type?", Sloc (N));
8074 Check_Unset_Reference (L);
8075 Check_Unset_Reference (H);
8077 -- We have to check the bounds for being within the base range as
8078 -- required for a non-static context. Normally this is automatic and
8079 -- done as part of evaluating expressions, but the N_Range node is an
8080 -- exception, since in GNAT we consider this node to be a subexpression,
8081 -- even though in Ada it is not. The circuit in Sem_Eval could check for
8082 -- this, but that would put the test on the main evaluation path for
8085 Check_Non_Static_Context (L);
8086 Check_Non_Static_Context (H);
8088 -- Check for an ambiguous range over character literals. This will
8089 -- happen with a membership test involving only literals.
8091 if Typ = Any_Character then
8092 Ambiguous_Character (L);
8093 Set_Etype (N, Any_Type);
8097 -- If bounds are static, constant-fold them, so size computations
8098 -- are identical between front-end and back-end. Do not perform this
8099 -- transformation while analyzing generic units, as type information
8100 -- would then be lost when reanalyzing the constant node in the
8103 if Is_Discrete_Type (Typ) and then Expander_Active then
8104 if Is_OK_Static_Expression (L) then
8105 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
8108 if Is_OK_Static_Expression (H) then
8109 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
8114 --------------------------
8115 -- Resolve_Real_Literal --
8116 --------------------------
8118 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
8119 Actual_Typ : constant Entity_Id := Etype (N);
8122 -- Special processing for fixed-point literals to make sure that the
8123 -- value is an exact multiple of small where this is required. We
8124 -- skip this for the universal real case, and also for generic types.
8126 if Is_Fixed_Point_Type (Typ)
8127 and then Typ /= Universal_Fixed
8128 and then Typ /= Any_Fixed
8129 and then not Is_Generic_Type (Typ)
8132 Val : constant Ureal := Realval (N);
8133 Cintr : constant Ureal := Val / Small_Value (Typ);
8134 Cint : constant Uint := UR_Trunc (Cintr);
8135 Den : constant Uint := Norm_Den (Cintr);
8139 -- Case of literal is not an exact multiple of the Small
8143 -- For a source program literal for a decimal fixed-point
8144 -- type, this is statically illegal (RM 4.9(36)).
8146 if Is_Decimal_Fixed_Point_Type (Typ)
8147 and then Actual_Typ = Universal_Real
8148 and then Comes_From_Source (N)
8150 Error_Msg_N ("value has extraneous low order digits", N);
8153 -- Generate a warning if literal from source
8155 if Is_Static_Expression (N)
8156 and then Warn_On_Bad_Fixed_Value
8159 ("?static fixed-point value is not a multiple of Small!",
8163 -- Replace literal by a value that is the exact representation
8164 -- of a value of the type, i.e. a multiple of the small value,
8165 -- by truncation, since Machine_Rounds is false for all GNAT
8166 -- fixed-point types (RM 4.9(38)).
8168 Stat := Is_Static_Expression (N);
8170 Make_Real_Literal (Sloc (N),
8171 Realval => Small_Value (Typ) * Cint));
8173 Set_Is_Static_Expression (N, Stat);
8176 -- In all cases, set the corresponding integer field
8178 Set_Corresponding_Integer_Value (N, Cint);
8182 -- Now replace the actual type by the expected type as usual
8185 Eval_Real_Literal (N);
8186 end Resolve_Real_Literal;
8188 -----------------------
8189 -- Resolve_Reference --
8190 -----------------------
8192 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
8193 P : constant Node_Id := Prefix (N);
8196 -- Replace general access with specific type
8198 if Ekind (Etype (N)) = E_Allocator_Type then
8199 Set_Etype (N, Base_Type (Typ));
8202 Resolve (P, Designated_Type (Etype (N)));
8204 -- If we are taking the reference of a volatile entity, then treat
8205 -- it as a potential modification of this entity. This is much too
8206 -- conservative, but is necessary because remove side effects can
8207 -- result in transformations of normal assignments into reference
8208 -- sequences that otherwise fail to notice the modification.
8210 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
8211 Note_Possible_Modification (P, Sure => False);
8213 end Resolve_Reference;
8215 --------------------------------
8216 -- Resolve_Selected_Component --
8217 --------------------------------
8219 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
8221 Comp1 : Entity_Id := Empty; -- prevent junk warning
8222 P : constant Node_Id := Prefix (N);
8223 S : constant Node_Id := Selector_Name (N);
8224 T : Entity_Id := Etype (P);
8226 I1 : Interp_Index := 0; -- prevent junk warning
8231 function Init_Component return Boolean;
8232 -- Check whether this is the initialization of a component within an
8233 -- init proc (by assignment or call to another init proc). If true,
8234 -- there is no need for a discriminant check.
8236 --------------------
8237 -- Init_Component --
8238 --------------------
8240 function Init_Component return Boolean is
8242 return Inside_Init_Proc
8243 and then Nkind (Prefix (N)) = N_Identifier
8244 and then Chars (Prefix (N)) = Name_uInit
8245 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
8248 -- Start of processing for Resolve_Selected_Component
8251 if Is_Overloaded (P) then
8253 -- Use the context type to select the prefix that has a selector
8254 -- of the correct name and type.
8257 Get_First_Interp (P, I, It);
8259 Search : while Present (It.Typ) loop
8260 if Is_Access_Type (It.Typ) then
8261 T := Designated_Type (It.Typ);
8266 if Is_Record_Type (T) then
8268 -- The visible components of a class-wide type are those of
8271 if Is_Class_Wide_Type (T) then
8275 Comp := First_Entity (T);
8276 while Present (Comp) loop
8277 if Chars (Comp) = Chars (S)
8278 and then Covers (Etype (Comp), Typ)
8287 It := Disambiguate (P, I1, I, Any_Type);
8289 if It = No_Interp then
8291 ("ambiguous prefix for selected component", N);
8298 -- There may be an implicit dereference. Retrieve
8299 -- designated record type.
8301 if Is_Access_Type (It1.Typ) then
8302 T := Designated_Type (It1.Typ);
8307 if Scope (Comp1) /= T then
8309 -- Resolution chooses the new interpretation.
8310 -- Find the component with the right name.
8312 Comp1 := First_Entity (T);
8313 while Present (Comp1)
8314 and then Chars (Comp1) /= Chars (S)
8316 Comp1 := Next_Entity (Comp1);
8325 Comp := Next_Entity (Comp);
8329 Get_Next_Interp (I, It);
8332 Resolve (P, It1.Typ);
8334 Set_Entity_With_Style_Check (S, Comp1);
8337 -- Resolve prefix with its type
8342 -- Generate cross-reference. We needed to wait until full overloading
8343 -- resolution was complete to do this, since otherwise we can't tell if
8344 -- we are an lvalue or not.
8346 if May_Be_Lvalue (N) then
8347 Generate_Reference (Entity (S), S, 'm');
8349 Generate_Reference (Entity (S), S, 'r');
8352 -- If prefix is an access type, the node will be transformed into an
8353 -- explicit dereference during expansion. The type of the node is the
8354 -- designated type of that of the prefix.
8356 if Is_Access_Type (Etype (P)) then
8357 T := Designated_Type (Etype (P));
8358 Check_Fully_Declared_Prefix (T, P);
8363 if Has_Discriminants (T)
8364 and then Ekind_In (Entity (S), E_Component, E_Discriminant)
8365 and then Present (Original_Record_Component (Entity (S)))
8366 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
8367 and then Present (Discriminant_Checking_Func
8368 (Original_Record_Component (Entity (S))))
8369 and then not Discriminant_Checks_Suppressed (T)
8370 and then not Init_Component
8372 Set_Do_Discriminant_Check (N);
8375 if Ekind (Entity (S)) = E_Void then
8376 Error_Msg_N ("premature use of component", S);
8379 -- If the prefix is a record conversion, this may be a renamed
8380 -- discriminant whose bounds differ from those of the original
8381 -- one, so we must ensure that a range check is performed.
8383 if Nkind (P) = N_Type_Conversion
8384 and then Ekind (Entity (S)) = E_Discriminant
8385 and then Is_Discrete_Type (Typ)
8387 Set_Etype (N, Base_Type (Typ));
8390 -- Note: No Eval processing is required, because the prefix is of a
8391 -- record type, or protected type, and neither can possibly be static.
8393 -- If the array type is atomic, and is packed, and we are in a left side
8394 -- context, then this is worth a warning, since we have a situation
8395 -- where the access to the component may cause extra read/writes of
8396 -- the atomic array object, which could be considered unexpected.
8398 if Nkind (N) = N_Selected_Component
8399 and then (Is_Atomic (T)
8400 or else (Is_Entity_Name (Prefix (N))
8401 and then Is_Atomic (Entity (Prefix (N)))))
8402 and then Is_Packed (T)
8405 Error_Msg_N ("?assignment to component of packed atomic record",
8407 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
8410 end Resolve_Selected_Component;
8416 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
8417 B_Typ : constant Entity_Id := Base_Type (Typ);
8418 L : constant Node_Id := Left_Opnd (N);
8419 R : constant Node_Id := Right_Opnd (N);
8422 -- We do the resolution using the base type, because intermediate values
8423 -- in expressions always are of the base type, not a subtype of it.
8426 Resolve (R, Standard_Natural);
8428 Check_Unset_Reference (L);
8429 Check_Unset_Reference (R);
8431 Set_Etype (N, B_Typ);
8432 Generate_Operator_Reference (N, B_Typ);
8436 ---------------------------
8437 -- Resolve_Short_Circuit --
8438 ---------------------------
8440 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
8441 B_Typ : constant Entity_Id := Base_Type (Typ);
8442 L : constant Node_Id := Left_Opnd (N);
8443 R : constant Node_Id := Right_Opnd (N);
8449 -- Check for issuing warning for always False assert/check, this happens
8450 -- when assertions are turned off, in which case the pragma Assert/Check
8451 -- was transformed into:
8453 -- if False and then <condition> then ...
8455 -- and we detect this pattern
8457 if Warn_On_Assertion_Failure
8458 and then Is_Entity_Name (R)
8459 and then Entity (R) = Standard_False
8460 and then Nkind (Parent (N)) = N_If_Statement
8461 and then Nkind (N) = N_And_Then
8462 and then Is_Entity_Name (L)
8463 and then Entity (L) = Standard_False
8466 Orig : constant Node_Id := Original_Node (Parent (N));
8469 if Nkind (Orig) = N_Pragma
8470 and then Pragma_Name (Orig) = Name_Assert
8472 -- Don't want to warn if original condition is explicit False
8475 Expr : constant Node_Id :=
8478 (First (Pragma_Argument_Associations (Orig))));
8480 if Is_Entity_Name (Expr)
8481 and then Entity (Expr) = Standard_False
8485 -- Issue warning. We do not want the deletion of the
8486 -- IF/AND-THEN to take this message with it. We achieve
8487 -- this by making sure that the expanded code points to
8488 -- the Sloc of the expression, not the original pragma.
8491 ("?assertion would fail at run time!",
8493 (First (Pragma_Argument_Associations (Orig))));
8497 -- Similar processing for Check pragma
8499 elsif Nkind (Orig) = N_Pragma
8500 and then Pragma_Name (Orig) = Name_Check
8502 -- Don't want to warn if original condition is explicit False
8505 Expr : constant Node_Id :=
8509 (Pragma_Argument_Associations (Orig)))));
8511 if Is_Entity_Name (Expr)
8512 and then Entity (Expr) = Standard_False
8517 ("?check would fail at run time!",
8519 (Last (Pragma_Argument_Associations (Orig))));
8526 -- Continue with processing of short circuit
8528 Check_Unset_Reference (L);
8529 Check_Unset_Reference (R);
8531 Set_Etype (N, B_Typ);
8532 Eval_Short_Circuit (N);
8533 end Resolve_Short_Circuit;
8539 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
8540 Name : constant Node_Id := Prefix (N);
8541 Drange : constant Node_Id := Discrete_Range (N);
8542 Array_Type : Entity_Id := Empty;
8546 if Is_Overloaded (Name) then
8548 -- Use the context type to select the prefix that yields the correct
8553 I1 : Interp_Index := 0;
8555 P : constant Node_Id := Prefix (N);
8556 Found : Boolean := False;
8559 Get_First_Interp (P, I, It);
8560 while Present (It.Typ) loop
8561 if (Is_Array_Type (It.Typ)
8562 and then Covers (Typ, It.Typ))
8563 or else (Is_Access_Type (It.Typ)
8564 and then Is_Array_Type (Designated_Type (It.Typ))
8565 and then Covers (Typ, Designated_Type (It.Typ)))
8568 It := Disambiguate (P, I1, I, Any_Type);
8570 if It = No_Interp then
8571 Error_Msg_N ("ambiguous prefix for slicing", N);
8576 Array_Type := It.Typ;
8581 Array_Type := It.Typ;
8586 Get_Next_Interp (I, It);
8591 Array_Type := Etype (Name);
8594 Resolve (Name, Array_Type);
8596 if Is_Access_Type (Array_Type) then
8597 Apply_Access_Check (N);
8598 Array_Type := Designated_Type (Array_Type);
8600 -- If the prefix is an access to an unconstrained array, we must use
8601 -- the actual subtype of the object to perform the index checks. The
8602 -- object denoted by the prefix is implicit in the node, so we build
8603 -- an explicit representation for it in order to compute the actual
8606 if not Is_Constrained (Array_Type) then
8607 Remove_Side_Effects (Prefix (N));
8610 Obj : constant Node_Id :=
8611 Make_Explicit_Dereference (Sloc (N),
8612 Prefix => New_Copy_Tree (Prefix (N)));
8614 Set_Etype (Obj, Array_Type);
8615 Set_Parent (Obj, Parent (N));
8616 Array_Type := Get_Actual_Subtype (Obj);
8620 elsif Is_Entity_Name (Name)
8621 or else Nkind (Name) = N_Explicit_Dereference
8622 or else (Nkind (Name) = N_Function_Call
8623 and then not Is_Constrained (Etype (Name)))
8625 Array_Type := Get_Actual_Subtype (Name);
8627 -- If the name is a selected component that depends on discriminants,
8628 -- build an actual subtype for it. This can happen only when the name
8629 -- itself is overloaded; otherwise the actual subtype is created when
8630 -- the selected component is analyzed.
8632 elsif Nkind (Name) = N_Selected_Component
8633 and then Full_Analysis
8634 and then Depends_On_Discriminant (First_Index (Array_Type))
8637 Act_Decl : constant Node_Id :=
8638 Build_Actual_Subtype_Of_Component (Array_Type, Name);
8640 Insert_Action (N, Act_Decl);
8641 Array_Type := Defining_Identifier (Act_Decl);
8644 -- Maybe this should just be "else", instead of checking for the
8645 -- specific case of slice??? This is needed for the case where
8646 -- the prefix is an Image attribute, which gets expanded to a
8647 -- slice, and so has a constrained subtype which we want to use
8648 -- for the slice range check applied below (the range check won't
8649 -- get done if the unconstrained subtype of the 'Image is used).
8651 elsif Nkind (Name) = N_Slice then
8652 Array_Type := Etype (Name);
8655 -- If name was overloaded, set slice type correctly now
8657 Set_Etype (N, Array_Type);
8659 -- If the range is specified by a subtype mark, no resolution is
8660 -- necessary. Else resolve the bounds, and apply needed checks.
8662 if not Is_Entity_Name (Drange) then
8663 Index := First_Index (Array_Type);
8664 Resolve (Drange, Base_Type (Etype (Index)));
8666 if Nkind (Drange) = N_Range then
8668 -- Ensure that side effects in the bounds are properly handled
8670 Remove_Side_Effects (Low_Bound (Drange), Variable_Ref => True);
8671 Remove_Side_Effects (High_Bound (Drange), Variable_Ref => True);
8673 -- Do not apply the range check to nodes associated with the
8674 -- frontend expansion of the dispatch table. We first check
8675 -- if Ada.Tags is already loaded to avoid the addition of an
8676 -- undesired dependence on such run-time unit.
8678 if not Tagged_Type_Expansion
8680 (RTU_Loaded (Ada_Tags)
8681 and then Nkind (Prefix (N)) = N_Selected_Component
8682 and then Present (Entity (Selector_Name (Prefix (N))))
8683 and then Entity (Selector_Name (Prefix (N))) =
8684 RTE_Record_Component (RE_Prims_Ptr))
8686 Apply_Range_Check (Drange, Etype (Index));
8691 Set_Slice_Subtype (N);
8693 -- Check bad use of type with predicates
8695 if Has_Predicates (Etype (Drange)) then
8696 Bad_Predicated_Subtype_Use
8697 ("subtype& has predicate, not allowed in slice",
8698 Drange, Etype (Drange));
8700 -- Otherwise here is where we check suspicious indexes
8702 elsif Nkind (Drange) = N_Range then
8703 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
8704 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
8710 ----------------------------
8711 -- Resolve_String_Literal --
8712 ----------------------------
8714 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
8715 C_Typ : constant Entity_Id := Component_Type (Typ);
8716 R_Typ : constant Entity_Id := Root_Type (C_Typ);
8717 Loc : constant Source_Ptr := Sloc (N);
8718 Str : constant String_Id := Strval (N);
8719 Strlen : constant Nat := String_Length (Str);
8720 Subtype_Id : Entity_Id;
8721 Need_Check : Boolean;
8724 -- For a string appearing in a concatenation, defer creation of the
8725 -- string_literal_subtype until the end of the resolution of the
8726 -- concatenation, because the literal may be constant-folded away. This
8727 -- is a useful optimization for long concatenation expressions.
8729 -- If the string is an aggregate built for a single character (which
8730 -- happens in a non-static context) or a is null string to which special
8731 -- checks may apply, we build the subtype. Wide strings must also get a
8732 -- string subtype if they come from a one character aggregate. Strings
8733 -- generated by attributes might be static, but it is often hard to
8734 -- determine whether the enclosing context is static, so we generate
8735 -- subtypes for them as well, thus losing some rarer optimizations ???
8736 -- Same for strings that come from a static conversion.
8739 (Strlen = 0 and then Typ /= Standard_String)
8740 or else Nkind (Parent (N)) /= N_Op_Concat
8741 or else (N /= Left_Opnd (Parent (N))
8742 and then N /= Right_Opnd (Parent (N)))
8743 or else ((Typ = Standard_Wide_String
8744 or else Typ = Standard_Wide_Wide_String)
8745 and then Nkind (Original_Node (N)) /= N_String_Literal);
8747 -- If the resolving type is itself a string literal subtype, we can just
8748 -- reuse it, since there is no point in creating another.
8750 if Ekind (Typ) = E_String_Literal_Subtype then
8753 elsif Nkind (Parent (N)) = N_Op_Concat
8754 and then not Need_Check
8755 and then not Nkind_In (Original_Node (N), N_Character_Literal,
8756 N_Attribute_Reference,
8757 N_Qualified_Expression,
8762 -- Otherwise we must create a string literal subtype. Note that the
8763 -- whole idea of string literal subtypes is simply to avoid the need
8764 -- for building a full fledged array subtype for each literal.
8767 Set_String_Literal_Subtype (N, Typ);
8768 Subtype_Id := Etype (N);
8771 if Nkind (Parent (N)) /= N_Op_Concat
8774 Set_Etype (N, Subtype_Id);
8775 Eval_String_Literal (N);
8778 if Is_Limited_Composite (Typ)
8779 or else Is_Private_Composite (Typ)
8781 Error_Msg_N ("string literal not available for private array", N);
8782 Set_Etype (N, Any_Type);
8786 -- The validity of a null string has been checked in the call to
8787 -- Eval_String_Literal.
8792 -- Always accept string literal with component type Any_Character, which
8793 -- occurs in error situations and in comparisons of literals, both of
8794 -- which should accept all literals.
8796 elsif R_Typ = Any_Character then
8799 -- If the type is bit-packed, then we always transform the string
8800 -- literal into a full fledged aggregate.
8802 elsif Is_Bit_Packed_Array (Typ) then
8805 -- Deal with cases of Wide_Wide_String, Wide_String, and String
8808 -- For Standard.Wide_Wide_String, or any other type whose component
8809 -- type is Standard.Wide_Wide_Character, we know that all the
8810 -- characters in the string must be acceptable, since the parser
8811 -- accepted the characters as valid character literals.
8813 if R_Typ = Standard_Wide_Wide_Character then
8816 -- For the case of Standard.String, or any other type whose component
8817 -- type is Standard.Character, we must make sure that there are no
8818 -- wide characters in the string, i.e. that it is entirely composed
8819 -- of characters in range of type Character.
8821 -- If the string literal is the result of a static concatenation, the
8822 -- test has already been performed on the components, and need not be
8825 elsif R_Typ = Standard_Character
8826 and then Nkind (Original_Node (N)) /= N_Op_Concat
8828 for J in 1 .. Strlen loop
8829 if not In_Character_Range (Get_String_Char (Str, J)) then
8831 -- If we are out of range, post error. This is one of the
8832 -- very few places that we place the flag in the middle of
8833 -- a token, right under the offending wide character. Not
8834 -- quite clear if this is right wrt wide character encoding
8835 -- sequences, but it's only an error message!
8838 ("literal out of range of type Standard.Character",
8839 Source_Ptr (Int (Loc) + J));
8844 -- For the case of Standard.Wide_String, or any other type whose
8845 -- component type is Standard.Wide_Character, we must make sure that
8846 -- there are no wide characters in the string, i.e. that it is
8847 -- entirely composed of characters in range of type Wide_Character.
8849 -- If the string literal is the result of a static concatenation,
8850 -- the test has already been performed on the components, and need
8853 elsif R_Typ = Standard_Wide_Character
8854 and then Nkind (Original_Node (N)) /= N_Op_Concat
8856 for J in 1 .. Strlen loop
8857 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
8859 -- If we are out of range, post error. This is one of the
8860 -- very few places that we place the flag in the middle of
8861 -- a token, right under the offending wide character.
8863 -- This is not quite right, because characters in general
8864 -- will take more than one character position ???
8867 ("literal out of range of type Standard.Wide_Character",
8868 Source_Ptr (Int (Loc) + J));
8873 -- If the root type is not a standard character, then we will convert
8874 -- the string into an aggregate and will let the aggregate code do
8875 -- the checking. Standard Wide_Wide_Character is also OK here.
8881 -- See if the component type of the array corresponding to the string
8882 -- has compile time known bounds. If yes we can directly check
8883 -- whether the evaluation of the string will raise constraint error.
8884 -- Otherwise we need to transform the string literal into the
8885 -- corresponding character aggregate and let the aggregate
8886 -- code do the checking.
8888 if Is_Standard_Character_Type (R_Typ) then
8890 -- Check for the case of full range, where we are definitely OK
8892 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
8896 -- Here the range is not the complete base type range, so check
8899 Comp_Typ_Lo : constant Node_Id :=
8900 Type_Low_Bound (Component_Type (Typ));
8901 Comp_Typ_Hi : constant Node_Id :=
8902 Type_High_Bound (Component_Type (Typ));
8907 if Compile_Time_Known_Value (Comp_Typ_Lo)
8908 and then Compile_Time_Known_Value (Comp_Typ_Hi)
8910 for J in 1 .. Strlen loop
8911 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
8913 if Char_Val < Expr_Value (Comp_Typ_Lo)
8914 or else Char_Val > Expr_Value (Comp_Typ_Hi)
8916 Apply_Compile_Time_Constraint_Error
8917 (N, "character out of range?", CE_Range_Check_Failed,
8918 Loc => Source_Ptr (Int (Loc) + J));
8928 -- If we got here we meed to transform the string literal into the
8929 -- equivalent qualified positional array aggregate. This is rather
8930 -- heavy artillery for this situation, but it is hard work to avoid.
8933 Lits : constant List_Id := New_List;
8934 P : Source_Ptr := Loc + 1;
8938 -- Build the character literals, we give them source locations that
8939 -- correspond to the string positions, which is a bit tricky given
8940 -- the possible presence of wide character escape sequences.
8942 for J in 1 .. Strlen loop
8943 C := Get_String_Char (Str, J);
8944 Set_Character_Literal_Name (C);
8947 Make_Character_Literal (P,
8949 Char_Literal_Value => UI_From_CC (C)));
8951 if In_Character_Range (C) then
8954 -- Should we have a call to Skip_Wide here ???
8962 Make_Qualified_Expression (Loc,
8963 Subtype_Mark => New_Reference_To (Typ, Loc),
8965 Make_Aggregate (Loc, Expressions => Lits)));
8967 Analyze_And_Resolve (N, Typ);
8969 end Resolve_String_Literal;
8971 -----------------------------
8972 -- Resolve_Subprogram_Info --
8973 -----------------------------
8975 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
8978 end Resolve_Subprogram_Info;
8980 -----------------------------
8981 -- Resolve_Type_Conversion --
8982 -----------------------------
8984 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
8985 Conv_OK : constant Boolean := Conversion_OK (N);
8986 Operand : constant Node_Id := Expression (N);
8987 Operand_Typ : constant Entity_Id := Etype (Operand);
8988 Target_Typ : constant Entity_Id := Etype (N);
8993 Test_Redundant : Boolean := Warn_On_Redundant_Constructs;
8994 -- Set to False to suppress cases where we want to suppress the test
8995 -- for redundancy to avoid possible false positives on this warning.
8999 and then not Valid_Conversion (N, Target_Typ, Operand)
9004 -- If the Operand Etype is Universal_Fixed, then the conversion is
9005 -- never redundant. We need this check because by the time we have
9006 -- finished the rather complex transformation, the conversion looks
9007 -- redundant when it is not.
9009 if Operand_Typ = Universal_Fixed then
9010 Test_Redundant := False;
9012 -- If the operand is marked as Any_Fixed, then special processing is
9013 -- required. This is also a case where we suppress the test for a
9014 -- redundant conversion, since most certainly it is not redundant.
9016 elsif Operand_Typ = Any_Fixed then
9017 Test_Redundant := False;
9019 -- Mixed-mode operation involving a literal. Context must be a fixed
9020 -- type which is applied to the literal subsequently.
9022 if Is_Fixed_Point_Type (Typ) then
9023 Set_Etype (Operand, Universal_Real);
9025 elsif Is_Numeric_Type (Typ)
9026 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
9027 and then (Etype (Right_Opnd (Operand)) = Universal_Real
9029 Etype (Left_Opnd (Operand)) = Universal_Real)
9031 -- Return if expression is ambiguous
9033 if Unique_Fixed_Point_Type (N) = Any_Type then
9036 -- If nothing else, the available fixed type is Duration
9039 Set_Etype (Operand, Standard_Duration);
9042 -- Resolve the real operand with largest available precision
9044 if Etype (Right_Opnd (Operand)) = Universal_Real then
9045 Rop := New_Copy_Tree (Right_Opnd (Operand));
9047 Rop := New_Copy_Tree (Left_Opnd (Operand));
9050 Resolve (Rop, Universal_Real);
9052 -- If the operand is a literal (it could be a non-static and
9053 -- illegal exponentiation) check whether the use of Duration
9054 -- is potentially inaccurate.
9056 if Nkind (Rop) = N_Real_Literal
9057 and then Realval (Rop) /= Ureal_0
9058 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
9061 ("?universal real operand can only " &
9062 "be interpreted as Duration!",
9065 ("\?precision will be lost in the conversion!", Rop);
9068 elsif Is_Numeric_Type (Typ)
9069 and then Nkind (Operand) in N_Op
9070 and then Unique_Fixed_Point_Type (N) /= Any_Type
9072 Set_Etype (Operand, Standard_Duration);
9075 Error_Msg_N ("invalid context for mixed mode operation", N);
9076 Set_Etype (Operand, Any_Type);
9083 -- In SPARK or ALFA, a type conversion between array types should be
9084 -- restricted to types which have matching static bounds.
9086 if Formal_Verification_Mode
9087 and then Comes_From_Source (Original_Node (N))
9088 and then Is_Array_Type (Target_Typ)
9089 and then Is_Array_Type (Operand_Typ)
9090 and then not Matching_Static_Array_Bounds (Target_Typ, Operand_Typ)
9092 Error_Msg_F ("|~~array types should have matching static bounds", N);
9095 -- Note: we do the Eval_Type_Conversion call before applying the
9096 -- required checks for a subtype conversion. This is important, since
9097 -- both are prepared under certain circumstances to change the type
9098 -- conversion to a constraint error node, but in the case of
9099 -- Eval_Type_Conversion this may reflect an illegality in the static
9100 -- case, and we would miss the illegality (getting only a warning
9101 -- message), if we applied the type conversion checks first.
9103 Eval_Type_Conversion (N);
9105 -- Even when evaluation is not possible, we may be able to simplify the
9106 -- conversion or its expression. This needs to be done before applying
9107 -- checks, since otherwise the checks may use the original expression
9108 -- and defeat the simplifications. This is specifically the case for
9109 -- elimination of the floating-point Truncation attribute in
9110 -- float-to-int conversions.
9112 Simplify_Type_Conversion (N);
9114 -- If after evaluation we still have a type conversion, then we may need
9115 -- to apply checks required for a subtype conversion.
9117 -- Skip these type conversion checks if universal fixed operands
9118 -- operands involved, since range checks are handled separately for
9119 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
9121 if Nkind (N) = N_Type_Conversion
9122 and then not Is_Generic_Type (Root_Type (Target_Typ))
9123 and then Target_Typ /= Universal_Fixed
9124 and then Operand_Typ /= Universal_Fixed
9126 Apply_Type_Conversion_Checks (N);
9129 -- Issue warning for conversion of simple object to its own type. We
9130 -- have to test the original nodes, since they may have been rewritten
9131 -- by various optimizations.
9133 Orig_N := Original_Node (N);
9135 -- Here we test for a redundant conversion if the warning mode is
9136 -- active (and was not locally reset), and we have a type conversion
9137 -- from source not appearing in a generic instance.
9140 and then Nkind (Orig_N) = N_Type_Conversion
9141 and then Comes_From_Source (Orig_N)
9142 and then not In_Instance
9144 Orig_N := Original_Node (Expression (Orig_N));
9145 Orig_T := Target_Typ;
9147 -- If the node is part of a larger expression, the Target_Type
9148 -- may not be the original type of the node if the context is a
9149 -- condition. Recover original type to see if conversion is needed.
9151 if Is_Boolean_Type (Orig_T)
9152 and then Nkind (Parent (N)) in N_Op
9154 Orig_T := Etype (Parent (N));
9157 -- If we have an entity name, then give the warning if the entity
9158 -- is the right type, or if it is a loop parameter covered by the
9159 -- original type (that's needed because loop parameters have an
9160 -- odd subtype coming from the bounds).
9162 if (Is_Entity_Name (Orig_N)
9164 (Etype (Entity (Orig_N)) = Orig_T
9166 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
9167 and then Covers (Orig_T, Etype (Entity (Orig_N))))))
9169 -- If not an entity, then type of expression must match
9171 or else Etype (Orig_N) = Orig_T
9173 -- One more check, do not give warning if the analyzed conversion
9174 -- has an expression with non-static bounds, and the bounds of the
9175 -- target are static. This avoids junk warnings in cases where the
9176 -- conversion is necessary to establish staticness, for example in
9177 -- a case statement.
9179 if not Is_OK_Static_Subtype (Operand_Typ)
9180 and then Is_OK_Static_Subtype (Target_Typ)
9184 -- Finally, if this type conversion occurs in a context that
9185 -- requires a prefix, and the expression is a qualified expression
9186 -- then the type conversion is not redundant, because a qualified
9187 -- expression is not a prefix, whereas a type conversion is. For
9188 -- example, "X := T'(Funx(...)).Y;" is illegal because a selected
9189 -- component requires a prefix, but a type conversion makes it
9190 -- legal: "X := T(T'(Funx(...))).Y;"
9192 -- In Ada 2012, a qualified expression is a name, so this idiom is
9193 -- no longer needed, but we still suppress the warning because it
9194 -- seems unfriendly for warnings to pop up when you switch to the
9195 -- newer language version.
9197 elsif Nkind (Orig_N) = N_Qualified_Expression
9198 and then Nkind_In (Parent (N), N_Attribute_Reference,
9199 N_Indexed_Component,
9200 N_Selected_Component,
9202 N_Explicit_Dereference)
9206 -- Here we give the redundant conversion warning. If it is an
9207 -- entity, give the name of the entity in the message. If not,
9208 -- just mention the expression.
9211 if Is_Entity_Name (Orig_N) then
9212 Error_Msg_Node_2 := Orig_T;
9213 Error_Msg_NE -- CODEFIX
9214 ("?redundant conversion, & is of type &!",
9215 N, Entity (Orig_N));
9218 ("?redundant conversion, expression is of type&!",
9225 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
9226 -- No need to perform any interface conversion if the type of the
9227 -- expression coincides with the target type.
9229 if Ada_Version >= Ada_2005
9230 and then Expander_Active
9231 and then Operand_Typ /= Target_Typ
9234 Opnd : Entity_Id := Operand_Typ;
9235 Target : Entity_Id := Target_Typ;
9238 if Is_Access_Type (Opnd) then
9239 Opnd := Designated_Type (Opnd);
9242 if Is_Access_Type (Target_Typ) then
9243 Target := Designated_Type (Target);
9246 if Opnd = Target then
9249 -- Conversion from interface type
9251 elsif Is_Interface (Opnd) then
9253 -- Ada 2005 (AI-217): Handle entities from limited views
9255 if From_With_Type (Opnd) then
9256 Error_Msg_Qual_Level := 99;
9257 Error_Msg_NE -- CODEFIX
9258 ("missing WITH clause on package &", N,
9259 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
9261 ("type conversions require visibility of the full view",
9264 elsif From_With_Type (Target)
9266 (Is_Access_Type (Target_Typ)
9267 and then Present (Non_Limited_View (Etype (Target))))
9269 Error_Msg_Qual_Level := 99;
9270 Error_Msg_NE -- CODEFIX
9271 ("missing WITH clause on package &", N,
9272 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
9274 ("type conversions require visibility of the full view",
9278 Expand_Interface_Conversion (N, Is_Static => False);
9281 -- Conversion to interface type
9283 elsif Is_Interface (Target) then
9287 if Ekind_In (Opnd, E_Protected_Subtype, E_Task_Subtype) then
9288 Opnd := Etype (Opnd);
9291 if not Interface_Present_In_Ancestor
9295 if Is_Class_Wide_Type (Opnd) then
9297 -- The static analysis is not enough to know if the
9298 -- interface is implemented or not. Hence we must pass
9299 -- the work to the expander to generate code to evaluate
9300 -- the conversion at run time.
9302 Expand_Interface_Conversion (N, Is_Static => False);
9305 Error_Msg_Name_1 := Chars (Etype (Target));
9306 Error_Msg_Name_2 := Chars (Opnd);
9308 ("wrong interface conversion (% is not a progenitor " &
9313 Expand_Interface_Conversion (N);
9318 end Resolve_Type_Conversion;
9320 ----------------------
9321 -- Resolve_Unary_Op --
9322 ----------------------
9324 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
9325 B_Typ : constant Entity_Id := Base_Type (Typ);
9326 R : constant Node_Id := Right_Opnd (N);
9332 -- Deal with intrinsic unary operators
9334 if Comes_From_Source (N)
9335 and then Ekind (Entity (N)) = E_Function
9336 and then Is_Imported (Entity (N))
9337 and then Is_Intrinsic_Subprogram (Entity (N))
9339 Resolve_Intrinsic_Unary_Operator (N, Typ);
9343 -- Deal with universal cases
9345 if Etype (R) = Universal_Integer
9347 Etype (R) = Universal_Real
9349 Check_For_Visible_Operator (N, B_Typ);
9352 Set_Etype (N, B_Typ);
9355 -- Generate warning for expressions like abs (x mod 2)
9357 if Warn_On_Redundant_Constructs
9358 and then Nkind (N) = N_Op_Abs
9360 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
9362 if OK and then Hi >= Lo and then Lo >= 0 then
9363 Error_Msg_N -- CODEFIX
9364 ("?abs applied to known non-negative value has no effect", N);
9368 -- Deal with reference generation
9370 Check_Unset_Reference (R);
9371 Generate_Operator_Reference (N, B_Typ);
9374 -- Set overflow checking bit. Much cleverer code needed here eventually
9375 -- and perhaps the Resolve routines should be separated for the various
9376 -- arithmetic operations, since they will need different processing ???
9378 if Nkind (N) in N_Op then
9379 if not Overflow_Checks_Suppressed (Etype (N)) then
9380 Enable_Overflow_Check (N);
9384 -- Generate warning for expressions like -5 mod 3 for integers. No need
9385 -- to worry in the floating-point case, since parens do not affect the
9386 -- result so there is no point in giving in a warning.
9389 Norig : constant Node_Id := Original_Node (N);
9398 if Warn_On_Questionable_Missing_Parens
9399 and then Comes_From_Source (Norig)
9400 and then Is_Integer_Type (Typ)
9401 and then Nkind (Norig) = N_Op_Minus
9403 Rorig := Original_Node (Right_Opnd (Norig));
9405 -- We are looking for cases where the right operand is not
9406 -- parenthesized, and is a binary operator, multiply, divide, or
9407 -- mod. These are the cases where the grouping can affect results.
9409 if Paren_Count (Rorig) = 0
9410 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
9412 -- For mod, we always give the warning, since the value is
9413 -- affected by the parenthesization (e.g. (-5) mod 315 /=
9414 -- -(5 mod 315)). But for the other cases, the only concern is
9415 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
9416 -- overflows, but (-2) * 64 does not). So we try to give the
9417 -- message only when overflow is possible.
9419 if Nkind (Rorig) /= N_Op_Mod
9420 and then Compile_Time_Known_Value (R)
9422 Val := Expr_Value (R);
9424 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
9425 HB := Expr_Value (Type_High_Bound (Typ));
9427 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
9430 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
9431 LB := Expr_Value (Type_Low_Bound (Typ));
9433 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
9436 -- Note that the test below is deliberately excluding the
9437 -- largest negative number, since that is a potentially
9438 -- troublesome case (e.g. -2 * x, where the result is the
9439 -- largest negative integer has an overflow with 2 * x).
9441 if Val > LB and then Val <= HB then
9446 -- For the multiplication case, the only case we have to worry
9447 -- about is when (-a)*b is exactly the largest negative number
9448 -- so that -(a*b) can cause overflow. This can only happen if
9449 -- a is a power of 2, and more generally if any operand is a
9450 -- constant that is not a power of 2, then the parentheses
9451 -- cannot affect whether overflow occurs. We only bother to
9452 -- test the left most operand
9454 -- Loop looking at left operands for one that has known value
9457 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
9458 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
9459 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
9461 -- Operand value of 0 or 1 skips warning
9466 -- Otherwise check power of 2, if power of 2, warn, if
9467 -- anything else, skip warning.
9470 while Lval /= 2 loop
9471 if Lval mod 2 = 1 then
9482 -- Keep looking at left operands
9484 Opnd := Left_Opnd (Opnd);
9487 -- For rem or "/" we can only have a problematic situation
9488 -- if the divisor has a value of minus one or one. Otherwise
9489 -- overflow is impossible (divisor > 1) or we have a case of
9490 -- division by zero in any case.
9492 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
9493 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
9494 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
9499 -- If we fall through warning should be issued
9502 ("?unary minus expression should be parenthesized here!", N);
9506 end Resolve_Unary_Op;
9508 ----------------------------------
9509 -- Resolve_Unchecked_Expression --
9510 ----------------------------------
9512 procedure Resolve_Unchecked_Expression
9517 Resolve (Expression (N), Typ, Suppress => All_Checks);
9519 end Resolve_Unchecked_Expression;
9521 ---------------------------------------
9522 -- Resolve_Unchecked_Type_Conversion --
9523 ---------------------------------------
9525 procedure Resolve_Unchecked_Type_Conversion
9529 pragma Warnings (Off, Typ);
9531 Operand : constant Node_Id := Expression (N);
9532 Opnd_Type : constant Entity_Id := Etype (Operand);
9535 -- Resolve operand using its own type
9537 Resolve (Operand, Opnd_Type);
9538 Eval_Unchecked_Conversion (N);
9539 end Resolve_Unchecked_Type_Conversion;
9541 ------------------------------
9542 -- Rewrite_Operator_As_Call --
9543 ------------------------------
9545 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
9546 Loc : constant Source_Ptr := Sloc (N);
9547 Actuals : constant List_Id := New_List;
9551 if Nkind (N) in N_Binary_Op then
9552 Append (Left_Opnd (N), Actuals);
9555 Append (Right_Opnd (N), Actuals);
9558 Make_Function_Call (Sloc => Loc,
9559 Name => New_Occurrence_Of (Nam, Loc),
9560 Parameter_Associations => Actuals);
9562 Preserve_Comes_From_Source (New_N, N);
9563 Preserve_Comes_From_Source (Name (New_N), N);
9565 Set_Etype (N, Etype (Nam));
9566 end Rewrite_Operator_As_Call;
9568 ------------------------------
9569 -- Rewrite_Renamed_Operator --
9570 ------------------------------
9572 procedure Rewrite_Renamed_Operator
9577 Nam : constant Name_Id := Chars (Op);
9578 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
9582 -- Rewrite the operator node using the real operator, not its renaming.
9583 -- Exclude user-defined intrinsic operations of the same name, which are
9584 -- treated separately and rewritten as calls.
9586 if Ekind (Op) /= E_Function or else Chars (N) /= Nam then
9587 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
9588 Set_Chars (Op_Node, Nam);
9589 Set_Etype (Op_Node, Etype (N));
9590 Set_Entity (Op_Node, Op);
9591 Set_Right_Opnd (Op_Node, Right_Opnd (N));
9593 -- Indicate that both the original entity and its renaming are
9594 -- referenced at this point.
9596 Generate_Reference (Entity (N), N);
9597 Generate_Reference (Op, N);
9600 Set_Left_Opnd (Op_Node, Left_Opnd (N));
9603 Rewrite (N, Op_Node);
9605 -- If the context type is private, add the appropriate conversions so
9606 -- that the operator is applied to the full view. This is done in the
9607 -- routines that resolve intrinsic operators.
9609 if Is_Intrinsic_Subprogram (Op)
9610 and then Is_Private_Type (Typ)
9613 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
9614 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
9615 Resolve_Intrinsic_Operator (N, Typ);
9617 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
9618 Resolve_Intrinsic_Unary_Operator (N, Typ);
9625 elsif Ekind (Op) = E_Function and then Is_Intrinsic_Subprogram (Op) then
9627 -- Operator renames a user-defined operator of the same name. Use the
9628 -- original operator in the node, which is the one Gigi knows about.
9631 Set_Is_Overloaded (N, False);
9633 end Rewrite_Renamed_Operator;
9635 -----------------------
9636 -- Set_Slice_Subtype --
9637 -----------------------
9639 -- Build an implicit subtype declaration to represent the type delivered by
9640 -- the slice. This is an abbreviated version of an array subtype. We define
9641 -- an index subtype for the slice, using either the subtype name or the
9642 -- discrete range of the slice. To be consistent with index usage elsewhere
9643 -- we create a list header to hold the single index. This list is not
9644 -- otherwise attached to the syntax tree.
9646 procedure Set_Slice_Subtype (N : Node_Id) is
9647 Loc : constant Source_Ptr := Sloc (N);
9648 Index_List : constant List_Id := New_List;
9650 Index_Subtype : Entity_Id;
9651 Index_Type : Entity_Id;
9652 Slice_Subtype : Entity_Id;
9653 Drange : constant Node_Id := Discrete_Range (N);
9656 if Is_Entity_Name (Drange) then
9657 Index_Subtype := Entity (Drange);
9660 -- We force the evaluation of a range. This is definitely needed in
9661 -- the renamed case, and seems safer to do unconditionally. Note in
9662 -- any case that since we will create and insert an Itype referring
9663 -- to this range, we must make sure any side effect removal actions
9664 -- are inserted before the Itype definition.
9666 if Nkind (Drange) = N_Range then
9667 Force_Evaluation (Low_Bound (Drange));
9668 Force_Evaluation (High_Bound (Drange));
9671 Index_Type := Base_Type (Etype (Drange));
9673 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9675 -- Take a new copy of Drange (where bounds have been rewritten to
9676 -- reference side-effect-free names). Using a separate tree ensures
9677 -- that further expansion (e.g. while rewriting a slice assignment
9678 -- into a FOR loop) does not attempt to remove side effects on the
9679 -- bounds again (which would cause the bounds in the index subtype
9680 -- definition to refer to temporaries before they are defined) (the
9681 -- reason is that some names are considered side effect free here
9682 -- for the subtype, but not in the context of a loop iteration
9685 Set_Scalar_Range (Index_Subtype, New_Copy_Tree (Drange));
9686 Set_Parent (Scalar_Range (Index_Subtype), Index_Subtype);
9687 Set_Etype (Index_Subtype, Index_Type);
9688 Set_Size_Info (Index_Subtype, Index_Type);
9689 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9692 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
9694 Index := New_Occurrence_Of (Index_Subtype, Loc);
9695 Set_Etype (Index, Index_Subtype);
9696 Append (Index, Index_List);
9698 Set_First_Index (Slice_Subtype, Index);
9699 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
9700 Set_Is_Constrained (Slice_Subtype, True);
9702 Check_Compile_Time_Size (Slice_Subtype);
9704 -- The Etype of the existing Slice node is reset to this slice subtype.
9705 -- Its bounds are obtained from its first index.
9707 Set_Etype (N, Slice_Subtype);
9709 -- For packed slice subtypes, freeze immediately (except in the
9710 -- case of being in a "spec expression" where we never freeze
9711 -- when we first see the expression).
9713 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
9714 Freeze_Itype (Slice_Subtype, N);
9716 -- For all other cases insert an itype reference in the slice's actions
9717 -- so that the itype is frozen at the proper place in the tree (i.e. at
9718 -- the point where actions for the slice are analyzed). Note that this
9719 -- is different from freezing the itype immediately, which might be
9720 -- premature (e.g. if the slice is within a transient scope).
9723 Ensure_Defined (Typ => Slice_Subtype, N => N);
9725 end Set_Slice_Subtype;
9727 --------------------------------
9728 -- Set_String_Literal_Subtype --
9729 --------------------------------
9731 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
9732 Loc : constant Source_Ptr := Sloc (N);
9733 Low_Bound : constant Node_Id :=
9734 Type_Low_Bound (Etype (First_Index (Typ)));
9735 Subtype_Id : Entity_Id;
9738 if Nkind (N) /= N_String_Literal then
9742 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
9743 Set_String_Literal_Length (Subtype_Id, UI_From_Int
9744 (String_Length (Strval (N))));
9745 Set_Etype (Subtype_Id, Base_Type (Typ));
9746 Set_Is_Constrained (Subtype_Id);
9747 Set_Etype (N, Subtype_Id);
9749 if Is_OK_Static_Expression (Low_Bound) then
9751 -- The low bound is set from the low bound of the corresponding index
9752 -- type. Note that we do not store the high bound in the string literal
9753 -- subtype, but it can be deduced if necessary from the length and the
9756 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
9759 Set_String_Literal_Low_Bound
9760 (Subtype_Id, Make_Integer_Literal (Loc, 1));
9761 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Standard_Positive);
9763 -- Build bona fide subtype for the string, and wrap it in an
9764 -- unchecked conversion, because the backend expects the
9765 -- String_Literal_Subtype to have a static lower bound.
9768 Index_List : constant List_Id := New_List;
9769 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
9770 High_Bound : constant Node_Id :=
9772 Left_Opnd => New_Copy_Tree (Low_Bound),
9774 Make_Integer_Literal (Loc,
9775 String_Length (Strval (N)) - 1));
9776 Array_Subtype : Entity_Id;
9777 Index_Subtype : Entity_Id;
9783 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9784 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
9785 Set_Scalar_Range (Index_Subtype, Drange);
9786 Set_Parent (Drange, N);
9787 Analyze_And_Resolve (Drange, Index_Type);
9789 -- In the context, the Index_Type may already have a constraint,
9790 -- so use common base type on string subtype. The base type may
9791 -- be used when generating attributes of the string, for example
9792 -- in the context of a slice assignment.
9794 Set_Etype (Index_Subtype, Base_Type (Index_Type));
9795 Set_Size_Info (Index_Subtype, Index_Type);
9796 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9798 Array_Subtype := Create_Itype (E_Array_Subtype, N);
9800 Index := New_Occurrence_Of (Index_Subtype, Loc);
9801 Set_Etype (Index, Index_Subtype);
9802 Append (Index, Index_List);
9804 Set_First_Index (Array_Subtype, Index);
9805 Set_Etype (Array_Subtype, Base_Type (Typ));
9806 Set_Is_Constrained (Array_Subtype, True);
9809 Make_Unchecked_Type_Conversion (Loc,
9810 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
9811 Expression => Relocate_Node (N)));
9812 Set_Etype (N, Array_Subtype);
9815 end Set_String_Literal_Subtype;
9817 ------------------------------
9818 -- Simplify_Type_Conversion --
9819 ------------------------------
9821 procedure Simplify_Type_Conversion (N : Node_Id) is
9823 if Nkind (N) = N_Type_Conversion then
9825 Operand : constant Node_Id := Expression (N);
9826 Target_Typ : constant Entity_Id := Etype (N);
9827 Opnd_Typ : constant Entity_Id := Etype (Operand);
9830 if Is_Floating_Point_Type (Opnd_Typ)
9832 (Is_Integer_Type (Target_Typ)
9833 or else (Is_Fixed_Point_Type (Target_Typ)
9834 and then Conversion_OK (N)))
9835 and then Nkind (Operand) = N_Attribute_Reference
9836 and then Attribute_Name (Operand) = Name_Truncation
9838 -- Special processing required if the conversion is the expression
9839 -- of a Truncation attribute reference. In this case we replace:
9841 -- ityp (ftyp'Truncation (x))
9847 -- with the Float_Truncate flag set, which is more efficient.
9851 Relocate_Node (First (Expressions (Operand))));
9852 Set_Float_Truncate (N, True);
9856 end Simplify_Type_Conversion;
9858 -----------------------------
9859 -- Unique_Fixed_Point_Type --
9860 -----------------------------
9862 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
9863 T1 : Entity_Id := Empty;
9868 procedure Fixed_Point_Error;
9869 -- Give error messages for true ambiguity. Messages are posted on node
9870 -- N, and entities T1, T2 are the possible interpretations.
9872 -----------------------
9873 -- Fixed_Point_Error --
9874 -----------------------
9876 procedure Fixed_Point_Error is
9878 Error_Msg_N ("ambiguous universal_fixed_expression", N);
9879 Error_Msg_NE ("\\possible interpretation as}", N, T1);
9880 Error_Msg_NE ("\\possible interpretation as}", N, T2);
9881 end Fixed_Point_Error;
9883 -- Start of processing for Unique_Fixed_Point_Type
9886 -- The operations on Duration are visible, so Duration is always a
9887 -- possible interpretation.
9889 T1 := Standard_Duration;
9891 -- Look for fixed-point types in enclosing scopes
9893 Scop := Current_Scope;
9894 while Scop /= Standard_Standard loop
9895 T2 := First_Entity (Scop);
9896 while Present (T2) loop
9897 if Is_Fixed_Point_Type (T2)
9898 and then Current_Entity (T2) = T2
9899 and then Scope (Base_Type (T2)) = Scop
9901 if Present (T1) then
9912 Scop := Scope (Scop);
9915 -- Look for visible fixed type declarations in the context
9917 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
9918 while Present (Item) loop
9919 if Nkind (Item) = N_With_Clause then
9920 Scop := Entity (Name (Item));
9921 T2 := First_Entity (Scop);
9922 while Present (T2) loop
9923 if Is_Fixed_Point_Type (T2)
9924 and then Scope (Base_Type (T2)) = Scop
9925 and then (Is_Potentially_Use_Visible (T2)
9926 or else In_Use (T2))
9928 if Present (T1) then
9943 if Nkind (N) = N_Real_Literal then
9944 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
9946 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
9950 end Unique_Fixed_Point_Type;
9952 ----------------------
9953 -- Valid_Conversion --
9954 ----------------------
9956 function Valid_Conversion
9959 Operand : Node_Id) return Boolean
9961 Target_Type : constant Entity_Id := Base_Type (Target);
9962 Opnd_Type : Entity_Id := Etype (Operand);
9964 function Conversion_Check
9966 Msg : String) return Boolean;
9967 -- Little routine to post Msg if Valid is False, returns Valid value
9969 function Valid_Tagged_Conversion
9970 (Target_Type : Entity_Id;
9971 Opnd_Type : Entity_Id) return Boolean;
9972 -- Specifically test for validity of tagged conversions
9974 function Valid_Array_Conversion return Boolean;
9975 -- Check index and component conformance, and accessibility levels if
9976 -- the component types are anonymous access types (Ada 2005).
9978 ----------------------
9979 -- Conversion_Check --
9980 ----------------------
9982 function Conversion_Check
9984 Msg : String) return Boolean
9988 Error_Msg_N (Msg, Operand);
9992 end Conversion_Check;
9994 ----------------------------
9995 -- Valid_Array_Conversion --
9996 ----------------------------
9998 function Valid_Array_Conversion return Boolean
10000 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
10001 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
10003 Opnd_Index : Node_Id;
10004 Opnd_Index_Type : Entity_Id;
10006 Target_Comp_Type : constant Entity_Id :=
10007 Component_Type (Target_Type);
10008 Target_Comp_Base : constant Entity_Id :=
10009 Base_Type (Target_Comp_Type);
10011 Target_Index : Node_Id;
10012 Target_Index_Type : Entity_Id;
10015 -- Error if wrong number of dimensions
10018 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
10021 ("incompatible number of dimensions for conversion", Operand);
10024 -- Number of dimensions matches
10027 -- Loop through indexes of the two arrays
10029 Target_Index := First_Index (Target_Type);
10030 Opnd_Index := First_Index (Opnd_Type);
10031 while Present (Target_Index) and then Present (Opnd_Index) loop
10032 Target_Index_Type := Etype (Target_Index);
10033 Opnd_Index_Type := Etype (Opnd_Index);
10035 -- Error if index types are incompatible
10037 if not (Is_Integer_Type (Target_Index_Type)
10038 and then Is_Integer_Type (Opnd_Index_Type))
10039 and then (Root_Type (Target_Index_Type)
10040 /= Root_Type (Opnd_Index_Type))
10043 ("incompatible index types for array conversion",
10048 Next_Index (Target_Index);
10049 Next_Index (Opnd_Index);
10052 -- If component types have same base type, all set
10054 if Target_Comp_Base = Opnd_Comp_Base then
10057 -- Here if base types of components are not the same. The only
10058 -- time this is allowed is if we have anonymous access types.
10060 -- The conversion of arrays of anonymous access types can lead
10061 -- to dangling pointers. AI-392 formalizes the accessibility
10062 -- checks that must be applied to such conversions to prevent
10063 -- out-of-scope references.
10066 Ekind_In (Target_Comp_Base, E_Anonymous_Access_Type,
10067 E_Anonymous_Access_Subprogram_Type)
10068 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
10070 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
10072 if Type_Access_Level (Target_Type) <
10073 Type_Access_Level (Opnd_Type)
10075 if In_Instance_Body then
10076 Error_Msg_N ("?source array type " &
10077 "has deeper accessibility level than target", Operand);
10078 Error_Msg_N ("\?Program_Error will be raised at run time",
10081 Make_Raise_Program_Error (Sloc (N),
10082 Reason => PE_Accessibility_Check_Failed));
10083 Set_Etype (N, Target_Type);
10086 -- Conversion not allowed because of accessibility levels
10089 Error_Msg_N ("source array type " &
10090 "has deeper accessibility level than target", Operand);
10097 -- All other cases where component base types do not match
10101 ("incompatible component types for array conversion",
10106 -- Check that component subtypes statically match. For numeric
10107 -- types this means that both must be either constrained or
10108 -- unconstrained. For enumeration types the bounds must match.
10109 -- All of this is checked in Subtypes_Statically_Match.
10111 if not Subtypes_Statically_Match
10112 (Target_Comp_Type, Opnd_Comp_Type)
10115 ("component subtypes must statically match", Operand);
10121 end Valid_Array_Conversion;
10123 -----------------------------
10124 -- Valid_Tagged_Conversion --
10125 -----------------------------
10127 function Valid_Tagged_Conversion
10128 (Target_Type : Entity_Id;
10129 Opnd_Type : Entity_Id) return Boolean
10132 -- Upward conversions are allowed (RM 4.6(22))
10134 if Covers (Target_Type, Opnd_Type)
10135 or else Is_Ancestor (Target_Type, Opnd_Type)
10139 -- Downward conversion are allowed if the operand is class-wide
10142 elsif Is_Class_Wide_Type (Opnd_Type)
10143 and then Covers (Opnd_Type, Target_Type)
10147 elsif Covers (Opnd_Type, Target_Type)
10148 or else Is_Ancestor (Opnd_Type, Target_Type)
10151 Conversion_Check (False,
10152 "downward conversion of tagged objects not allowed");
10154 -- Ada 2005 (AI-251): The conversion to/from interface types is
10157 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
10160 -- If the operand is a class-wide type obtained through a limited_
10161 -- with clause, and the context includes the non-limited view, use
10162 -- it to determine whether the conversion is legal.
10164 elsif Is_Class_Wide_Type (Opnd_Type)
10165 and then From_With_Type (Opnd_Type)
10166 and then Present (Non_Limited_View (Etype (Opnd_Type)))
10167 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
10171 elsif Is_Access_Type (Opnd_Type)
10172 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
10178 ("invalid tagged conversion, not compatible with}",
10179 N, First_Subtype (Opnd_Type));
10182 end Valid_Tagged_Conversion;
10184 -- Start of processing for Valid_Conversion
10187 Check_Parameterless_Call (Operand);
10189 if Is_Overloaded (Operand) then
10199 -- Remove procedure calls, which syntactically cannot appear in
10200 -- this context, but which cannot be removed by type checking,
10201 -- because the context does not impose a type.
10203 -- When compiling for VMS, spurious ambiguities can be produced
10204 -- when arithmetic operations have a literal operand and return
10205 -- System.Address or a descendant of it. These ambiguities are
10206 -- otherwise resolved by the context, but for conversions there
10207 -- is no context type and the removal of the spurious operations
10208 -- must be done explicitly here.
10210 -- The node may be labelled overloaded, but still contain only one
10211 -- interpretation because others were discarded earlier. If this
10212 -- is the case, retain the single interpretation if legal.
10214 Get_First_Interp (Operand, I, It);
10215 Opnd_Type := It.Typ;
10216 Get_Next_Interp (I, It);
10218 if Present (It.Typ)
10219 and then Opnd_Type /= Standard_Void_Type
10221 -- More than one candidate interpretation is available
10223 Get_First_Interp (Operand, I, It);
10224 while Present (It.Typ) loop
10225 if It.Typ = Standard_Void_Type then
10229 if Present (System_Aux_Id)
10230 and then Is_Descendent_Of_Address (It.Typ)
10235 Get_Next_Interp (I, It);
10239 Get_First_Interp (Operand, I, It);
10243 if No (It.Typ) then
10244 Error_Msg_N ("illegal operand in conversion", Operand);
10248 Get_Next_Interp (I, It);
10250 if Present (It.Typ) then
10253 It1 := Disambiguate (Operand, I1, I, Any_Type);
10255 if It1 = No_Interp then
10256 Error_Msg_N ("ambiguous operand in conversion", Operand);
10258 -- If the interpretation involves a standard operator, use
10259 -- the location of the type, which may be user-defined.
10261 if Sloc (It.Nam) = Standard_Location then
10262 Error_Msg_Sloc := Sloc (It.Typ);
10264 Error_Msg_Sloc := Sloc (It.Nam);
10267 Error_Msg_N -- CODEFIX
10268 ("\\possible interpretation#!", Operand);
10270 if Sloc (N1) = Standard_Location then
10271 Error_Msg_Sloc := Sloc (T1);
10273 Error_Msg_Sloc := Sloc (N1);
10276 Error_Msg_N -- CODEFIX
10277 ("\\possible interpretation#!", Operand);
10283 Set_Etype (Operand, It1.Typ);
10284 Opnd_Type := It1.Typ;
10290 if Is_Numeric_Type (Target_Type) then
10292 -- A universal fixed expression can be converted to any numeric type
10294 if Opnd_Type = Universal_Fixed then
10297 -- Also no need to check when in an instance or inlined body, because
10298 -- the legality has been established when the template was analyzed.
10299 -- Furthermore, numeric conversions may occur where only a private
10300 -- view of the operand type is visible at the instantiation point.
10301 -- This results in a spurious error if we check that the operand type
10302 -- is a numeric type.
10304 -- Note: in a previous version of this unit, the following tests were
10305 -- applied only for generated code (Comes_From_Source set to False),
10306 -- but in fact the test is required for source code as well, since
10307 -- this situation can arise in source code.
10309 elsif In_Instance or else In_Inlined_Body then
10312 -- Otherwise we need the conversion check
10315 return Conversion_Check
10316 (Is_Numeric_Type (Opnd_Type),
10317 "illegal operand for numeric conversion");
10322 elsif Is_Array_Type (Target_Type) then
10323 if not Is_Array_Type (Opnd_Type)
10324 or else Opnd_Type = Any_Composite
10325 or else Opnd_Type = Any_String
10327 Error_Msg_N ("illegal operand for array conversion", Operand);
10330 return Valid_Array_Conversion;
10333 -- Ada 2005 (AI-251): Anonymous access types where target references an
10336 elsif Ekind_In (Target_Type, E_General_Access_Type,
10337 E_Anonymous_Access_Type)
10338 and then Is_Interface (Directly_Designated_Type (Target_Type))
10340 -- Check the static accessibility rule of 4.6(17). Note that the
10341 -- check is not enforced when within an instance body, since the
10342 -- RM requires such cases to be caught at run time.
10344 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
10345 if Type_Access_Level (Opnd_Type) >
10346 Type_Access_Level (Target_Type)
10348 -- In an instance, this is a run-time check, but one we know
10349 -- will fail, so generate an appropriate warning. The raise
10350 -- will be generated by Expand_N_Type_Conversion.
10352 if In_Instance_Body then
10354 ("?cannot convert local pointer to non-local access type",
10357 ("\?Program_Error will be raised at run time", Operand);
10360 ("cannot convert local pointer to non-local access type",
10365 -- Special accessibility checks are needed in the case of access
10366 -- discriminants declared for a limited type.
10368 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10369 and then not Is_Local_Anonymous_Access (Opnd_Type)
10371 -- When the operand is a selected access discriminant the check
10372 -- needs to be made against the level of the object denoted by
10373 -- the prefix of the selected name (Object_Access_Level handles
10374 -- checking the prefix of the operand for this case).
10376 if Nkind (Operand) = N_Selected_Component
10377 and then Object_Access_Level (Operand) >
10378 Type_Access_Level (Target_Type)
10380 -- In an instance, this is a run-time check, but one we know
10381 -- will fail, so generate an appropriate warning. The raise
10382 -- will be generated by Expand_N_Type_Conversion.
10384 if In_Instance_Body then
10386 ("?cannot convert access discriminant to non-local" &
10387 " access type", Operand);
10389 ("\?Program_Error will be raised at run time", Operand);
10392 ("cannot convert access discriminant to non-local" &
10393 " access type", Operand);
10398 -- The case of a reference to an access discriminant from
10399 -- within a limited type declaration (which will appear as
10400 -- a discriminal) is always illegal because the level of the
10401 -- discriminant is considered to be deeper than any (nameable)
10404 if Is_Entity_Name (Operand)
10405 and then not Is_Local_Anonymous_Access (Opnd_Type)
10407 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10408 and then Present (Discriminal_Link (Entity (Operand)))
10411 ("discriminant has deeper accessibility level than target",
10420 -- General and anonymous access types
10422 elsif Ekind_In (Target_Type, E_General_Access_Type,
10423 E_Anonymous_Access_Type)
10426 (Is_Access_Type (Opnd_Type)
10428 Ekind_In (Opnd_Type, E_Access_Subprogram_Type,
10429 E_Access_Protected_Subprogram_Type),
10430 "must be an access-to-object type")
10432 if Is_Access_Constant (Opnd_Type)
10433 and then not Is_Access_Constant (Target_Type)
10436 ("access-to-constant operand type not allowed", Operand);
10440 -- Check the static accessibility rule of 4.6(17). Note that the
10441 -- check is not enforced when within an instance body, since the RM
10442 -- requires such cases to be caught at run time.
10444 if Ekind (Target_Type) /= E_Anonymous_Access_Type
10445 or else Is_Local_Anonymous_Access (Target_Type)
10447 if Type_Access_Level (Opnd_Type)
10448 > Type_Access_Level (Target_Type)
10450 -- In an instance, this is a run-time check, but one we know
10451 -- will fail, so generate an appropriate warning. The raise
10452 -- will be generated by Expand_N_Type_Conversion.
10454 if In_Instance_Body then
10456 ("?cannot convert local pointer to non-local access type",
10459 ("\?Program_Error will be raised at run time", Operand);
10462 -- Avoid generation of spurious error message
10464 if not Error_Posted (N) then
10466 ("cannot convert local pointer to non-local access type",
10473 -- Special accessibility checks are needed in the case of access
10474 -- discriminants declared for a limited type.
10476 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10477 and then not Is_Local_Anonymous_Access (Opnd_Type)
10479 -- When the operand is a selected access discriminant the check
10480 -- needs to be made against the level of the object denoted by
10481 -- the prefix of the selected name (Object_Access_Level handles
10482 -- checking the prefix of the operand for this case).
10484 if Nkind (Operand) = N_Selected_Component
10485 and then Object_Access_Level (Operand) >
10486 Type_Access_Level (Target_Type)
10488 -- In an instance, this is a run-time check, but one we know
10489 -- will fail, so generate an appropriate warning. The raise
10490 -- will be generated by Expand_N_Type_Conversion.
10492 if In_Instance_Body then
10494 ("?cannot convert access discriminant to non-local" &
10495 " access type", Operand);
10497 ("\?Program_Error will be raised at run time",
10502 ("cannot convert access discriminant to non-local" &
10503 " access type", Operand);
10508 -- The case of a reference to an access discriminant from
10509 -- within a limited type declaration (which will appear as
10510 -- a discriminal) is always illegal because the level of the
10511 -- discriminant is considered to be deeper than any (nameable)
10514 if Is_Entity_Name (Operand)
10516 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10517 and then Present (Discriminal_Link (Entity (Operand)))
10520 ("discriminant has deeper accessibility level than target",
10527 -- In the presence of limited_with clauses we have to use non-limited
10528 -- views, if available.
10530 Check_Limited : declare
10531 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
10532 -- Helper function to handle limited views
10534 --------------------------
10535 -- Full_Designated_Type --
10536 --------------------------
10538 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
10539 Desig : constant Entity_Id := Designated_Type (T);
10542 -- Handle the limited view of a type
10544 if Is_Incomplete_Type (Desig)
10545 and then From_With_Type (Desig)
10546 and then Present (Non_Limited_View (Desig))
10548 return Available_View (Desig);
10552 end Full_Designated_Type;
10554 -- Local Declarations
10556 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
10557 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
10559 Same_Base : constant Boolean :=
10560 Base_Type (Target) = Base_Type (Opnd);
10562 -- Start of processing for Check_Limited
10565 if Is_Tagged_Type (Target) then
10566 return Valid_Tagged_Conversion (Target, Opnd);
10569 if not Same_Base then
10571 ("target designated type not compatible with }",
10572 N, Base_Type (Opnd));
10575 -- Ada 2005 AI-384: legality rule is symmetric in both
10576 -- designated types. The conversion is legal (with possible
10577 -- constraint check) if either designated type is
10580 elsif Subtypes_Statically_Match (Target, Opnd)
10582 (Has_Discriminants (Target)
10584 (not Is_Constrained (Opnd)
10585 or else not Is_Constrained (Target)))
10587 -- Special case, if Value_Size has been used to make the
10588 -- sizes different, the conversion is not allowed even
10589 -- though the subtypes statically match.
10591 if Known_Static_RM_Size (Target)
10592 and then Known_Static_RM_Size (Opnd)
10593 and then RM_Size (Target) /= RM_Size (Opnd)
10596 ("target designated subtype not compatible with }",
10599 ("\because sizes of the two designated subtypes differ",
10603 -- Normal case where conversion is allowed
10611 ("target designated subtype not compatible with }",
10618 -- Access to subprogram types. If the operand is an access parameter,
10619 -- the type has a deeper accessibility that any master, and cannot be
10620 -- assigned. We must make an exception if the conversion is part of an
10621 -- assignment and the target is the return object of an extended return
10622 -- statement, because in that case the accessibility check takes place
10623 -- after the return.
10625 elsif Is_Access_Subprogram_Type (Target_Type)
10626 and then No (Corresponding_Remote_Type (Opnd_Type))
10628 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
10629 and then Is_Entity_Name (Operand)
10630 and then Ekind (Entity (Operand)) = E_In_Parameter
10632 (Nkind (Parent (N)) /= N_Assignment_Statement
10633 or else not Is_Entity_Name (Name (Parent (N)))
10634 or else not Is_Return_Object (Entity (Name (Parent (N)))))
10637 ("illegal attempt to store anonymous access to subprogram",
10640 ("\value has deeper accessibility than any master " &
10641 "(RM 3.10.2 (13))",
10645 ("\use named access type for& instead of access parameter",
10646 Operand, Entity (Operand));
10649 -- Check that the designated types are subtype conformant
10651 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
10652 Old_Id => Designated_Type (Opnd_Type),
10655 -- Check the static accessibility rule of 4.6(20)
10657 if Type_Access_Level (Opnd_Type) >
10658 Type_Access_Level (Target_Type)
10661 ("operand type has deeper accessibility level than target",
10664 -- Check that if the operand type is declared in a generic body,
10665 -- then the target type must be declared within that same body
10666 -- (enforces last sentence of 4.6(20)).
10668 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
10670 O_Gen : constant Node_Id :=
10671 Enclosing_Generic_Body (Opnd_Type);
10676 T_Gen := Enclosing_Generic_Body (Target_Type);
10677 while Present (T_Gen) and then T_Gen /= O_Gen loop
10678 T_Gen := Enclosing_Generic_Body (T_Gen);
10681 if T_Gen /= O_Gen then
10683 ("target type must be declared in same generic body"
10684 & " as operand type", N);
10691 -- Remote subprogram access types
10693 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
10694 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
10696 -- It is valid to convert from one RAS type to another provided
10697 -- that their specification statically match.
10699 Check_Subtype_Conformant
10701 Designated_Type (Corresponding_Remote_Type (Target_Type)),
10703 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
10708 -- If both are tagged types, check legality of view conversions
10710 elsif Is_Tagged_Type (Target_Type)
10712 Is_Tagged_Type (Opnd_Type)
10714 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
10716 -- Types derived from the same root type are convertible
10718 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
10721 -- In an instance or an inlined body, there may be inconsistent views of
10722 -- the same type, or of types derived from a common root.
10724 elsif (In_Instance or In_Inlined_Body)
10726 Root_Type (Underlying_Type (Target_Type)) =
10727 Root_Type (Underlying_Type (Opnd_Type))
10731 -- Special check for common access type error case
10733 elsif Ekind (Target_Type) = E_Access_Type
10734 and then Is_Access_Type (Opnd_Type)
10736 Error_Msg_N ("target type must be general access type!", N);
10737 Error_Msg_NE -- CODEFIX
10738 ("add ALL to }!", N, Target_Type);
10742 Error_Msg_NE ("invalid conversion, not compatible with }",
10746 end Valid_Conversion;