1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, 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 type
88 -- information recursively to the descendants of N. If the node is not
89 -- overloaded, its Etype is established in the first pass. If overloaded,
90 -- the Resolve routines set the correct type. For arith. operators, the
91 -- Etype is the base type of the context.
93 -- Note that Resolve_Attribute is separated off in Sem_Attr
95 function Bad_Unordered_Enumeration_Reference
97 T : Entity_Id) return Boolean;
98 -- Node N contains a potentially dubious reference to type T, either an
99 -- explicit comparison, or an explicit range. This function returns True
100 -- if the type T is an enumeration type for which No pragma Order has been
101 -- given, and the reference N is not in the same extended source unit as
102 -- the declaration of T.
104 procedure Check_Discriminant_Use (N : Node_Id);
105 -- Enforce the restrictions on the use of discriminants when constraining
106 -- a component of a discriminated type (record or concurrent type).
108 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
109 -- Given a node for an operator associated with type T, check that
110 -- the operator is visible. Operators all of whose operands are
111 -- universal must be checked for visibility during resolution
112 -- because their type is not determinable based on their operands.
114 procedure Check_Fully_Declared_Prefix
117 -- Check that the type of the prefix of a dereference is not incomplete
119 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
120 -- Given a call node, N, which is known to occur immediately within the
121 -- subprogram being called, determines whether it is a detectable case of
122 -- an infinite recursion, and if so, outputs appropriate messages. Returns
123 -- True if an infinite recursion is detected, and False otherwise.
125 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
126 -- If the type of the object being initialized uses the secondary stack
127 -- directly or indirectly, create a transient scope for the call to the
128 -- init proc. This is because we do not create transient scopes for the
129 -- initialization of individual components within the init proc itself.
130 -- Could be optimized away perhaps?
132 procedure Check_No_Direct_Boolean_Operators (N : Node_Id);
133 -- N is the node for a logical operator. If the operator is predefined, and
134 -- the root type of the operands is Standard.Boolean, then a check is made
135 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
136 -- the style check for Style_Check_Boolean_And_Or.
138 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
139 -- Determine whether E is an access type declared by an access declaration,
140 -- and not an (anonymous) allocator type.
142 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
143 -- Utility to check whether the entity for an operator is a predefined
144 -- operator, in which case the expression is left as an operator in the
145 -- tree (else it is rewritten into a call). An instance of an intrinsic
146 -- conversion operation may be given an operator name, but is not treated
147 -- like an operator. Note that an operator that is an imported back-end
148 -- builtin has convention Intrinsic, but is expected to be rewritten into
149 -- a call, so such an operator is not treated as predefined by this
152 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
153 -- If a default expression in entry call N depends on the discriminants
154 -- of the task, it must be replaced with a reference to the discriminant
155 -- of the task being called.
157 procedure Resolve_Op_Concat_Arg
162 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
163 -- concatenation operator. The operand is either of the array type or of
164 -- the component type. If the operand is an aggregate, and the component
165 -- type is composite, this is ambiguous if component type has aggregates.
167 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
168 -- Does the first part of the work of Resolve_Op_Concat
170 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
171 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
172 -- has been resolved. See Resolve_Op_Concat for details.
174 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
175 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
176 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
177 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id);
178 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
179 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
180 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id);
185 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
186 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
187 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
188 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
189 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
190 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
191 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
192 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
193 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
194 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
195 procedure Resolve_Quantified_Expression (N : Node_Id; Typ : Entity_Id);
196 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
197 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
198 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
199 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
200 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
201 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
202 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
203 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
204 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
205 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
206 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
207 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
208 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
210 function Operator_Kind
212 Is_Binary : Boolean) return Node_Kind;
213 -- Utility to map the name of an operator into the corresponding Node. Used
214 -- by other node rewriting procedures.
216 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
217 -- Resolve actuals of call, and add default expressions for missing ones.
218 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
219 -- called subprogram.
221 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
222 -- Called from Resolve_Call, when the prefix denotes an entry or element
223 -- of entry family. Actuals are resolved as for subprograms, and the node
224 -- is rebuilt as an entry call. Also called for protected operations. Typ
225 -- is the context type, which is used when the operation is a protected
226 -- function with no arguments, and the return value is indexed.
228 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
229 -- A call to a user-defined intrinsic operator is rewritten as a call to
230 -- the corresponding predefined operator, with suitable conversions. Note
231 -- that this applies only for intrinsic operators that denote predefined
232 -- operators, not ones that are intrinsic imports of back-end builtins.
234 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
235 -- Ditto, for unary operators (arithmetic ones and "not" on signed
236 -- integer types for VMS).
238 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
239 -- If an operator node resolves to a call to a user-defined operator,
240 -- rewrite the node as a function call.
242 procedure Make_Call_Into_Operator
246 -- Inverse transformation: if an operator is given in functional notation,
247 -- then after resolving the node, transform into an operator node, so
248 -- that operands are resolved properly. Recall that predefined operators
249 -- do not have a full signature and special resolution rules apply.
251 procedure Rewrite_Renamed_Operator
255 -- An operator can rename another, e.g. in an instantiation. In that
256 -- case, the proper operator node must be constructed and resolved.
258 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
259 -- The String_Literal_Subtype is built for all strings that are not
260 -- operands of a static concatenation operation. If the argument is
261 -- not a N_String_Literal node, then the call has no effect.
263 procedure Set_Slice_Subtype (N : Node_Id);
264 -- Build subtype of array type, with the range specified by the slice
266 procedure Simplify_Type_Conversion (N : Node_Id);
267 -- Called after N has been resolved and evaluated, but before range checks
268 -- have been applied. Currently simplifies a combination of floating-point
269 -- to integer conversion and Truncation attribute.
271 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
272 -- A universal_fixed expression in an universal context is unambiguous if
273 -- there is only one applicable fixed point type. Determining whether there
274 -- is only one requires a search over all visible entities, and happens
275 -- only in very pathological cases (see 6115-006).
277 function Valid_Conversion
280 Operand : Node_Id) return Boolean;
281 -- Verify legality rules given in 4.6 (8-23). Target is the target type
282 -- of the conversion, which may be an implicit conversion of an actual
283 -- parameter to an anonymous access type (in which case N denotes the
284 -- actual parameter and N = Operand).
286 -------------------------
287 -- Ambiguous_Character --
288 -------------------------
290 procedure Ambiguous_Character (C : Node_Id) is
294 if Nkind (C) = N_Character_Literal then
295 Error_Msg_N ("ambiguous character literal", C);
297 -- First the ones in Standard
299 Error_Msg_N ("\\possible interpretation: Character!", C);
300 Error_Msg_N ("\\possible interpretation: Wide_Character!", C);
302 -- Include Wide_Wide_Character in Ada 2005 mode
304 if Ada_Version >= Ada_2005 then
305 Error_Msg_N ("\\possible interpretation: Wide_Wide_Character!", C);
308 -- Now any other types that match
310 E := Current_Entity (C);
311 while Present (E) loop
312 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
316 end Ambiguous_Character;
318 -------------------------
319 -- Analyze_And_Resolve --
320 -------------------------
322 procedure Analyze_And_Resolve (N : Node_Id) is
326 end Analyze_And_Resolve;
328 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
332 end Analyze_And_Resolve;
334 -- Version withs check(s) suppressed
336 procedure Analyze_And_Resolve
341 Scop : constant Entity_Id := Current_Scope;
344 if Suppress = All_Checks then
346 Svg : constant Suppress_Array := Scope_Suppress;
348 Scope_Suppress := (others => True);
349 Analyze_And_Resolve (N, Typ);
350 Scope_Suppress := Svg;
355 Svg : constant Boolean := Scope_Suppress (Suppress);
358 Scope_Suppress (Suppress) := True;
359 Analyze_And_Resolve (N, Typ);
360 Scope_Suppress (Suppress) := Svg;
364 if Current_Scope /= Scop
365 and then Scope_Is_Transient
367 -- This can only happen if a transient scope was created for an inner
368 -- expression, which will be removed upon completion of the analysis
369 -- of an enclosing construct. The transient scope must have the
370 -- suppress status of the enclosing environment, not of this Analyze
373 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
376 end Analyze_And_Resolve;
378 procedure Analyze_And_Resolve
382 Scop : constant Entity_Id := Current_Scope;
385 if Suppress = All_Checks then
387 Svg : constant Suppress_Array := Scope_Suppress;
389 Scope_Suppress := (others => True);
390 Analyze_And_Resolve (N);
391 Scope_Suppress := Svg;
396 Svg : constant Boolean := Scope_Suppress (Suppress);
399 Scope_Suppress (Suppress) := True;
400 Analyze_And_Resolve (N);
401 Scope_Suppress (Suppress) := Svg;
405 if Current_Scope /= Scop
406 and then Scope_Is_Transient
408 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
411 end Analyze_And_Resolve;
413 ----------------------------------------
414 -- Bad_Unordered_Enumeration_Reference --
415 ----------------------------------------
417 function Bad_Unordered_Enumeration_Reference
419 T : Entity_Id) return Boolean
422 return Is_Enumeration_Type (T)
423 and then Comes_From_Source (N)
424 and then Warn_On_Unordered_Enumeration_Type
425 and then not Has_Pragma_Ordered (T)
426 and then not In_Same_Extended_Unit (N, T);
427 end Bad_Unordered_Enumeration_Reference;
429 ----------------------------
430 -- Check_Discriminant_Use --
431 ----------------------------
433 procedure Check_Discriminant_Use (N : Node_Id) is
434 PN : constant Node_Id := Parent (N);
435 Disc : constant Entity_Id := Entity (N);
440 -- Any use in a spec-expression is legal
442 if In_Spec_Expression then
445 elsif Nkind (PN) = N_Range then
447 -- Discriminant cannot be used to constrain a scalar type
451 if Nkind (P) = N_Range_Constraint
452 and then Nkind (Parent (P)) = N_Subtype_Indication
453 and then Nkind (Parent (Parent (P))) = N_Component_Definition
455 Error_Msg_N ("discriminant cannot constrain scalar type", N);
457 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
459 -- The following check catches the unusual case where a
460 -- discriminant appears within an index constraint that is part of
461 -- a larger expression within a constraint on a component, e.g. "C
462 -- : Int range 1 .. F (new A(1 .. D))". For now we only check case
463 -- of record components, and note that a similar check should also
464 -- apply in the case of discriminant constraints below. ???
466 -- Note that the check for N_Subtype_Declaration below is to
467 -- detect the valid use of discriminants in the constraints of a
468 -- subtype declaration when this subtype declaration appears
469 -- inside the scope of a record type (which is syntactically
470 -- illegal, but which may be created as part of derived type
471 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
474 if Ekind (Current_Scope) = E_Record_Type
475 and then Scope (Disc) = Current_Scope
477 (Nkind (Parent (P)) = N_Subtype_Indication
479 Nkind_In (Parent (Parent (P)), N_Component_Definition,
480 N_Subtype_Declaration)
481 and then Paren_Count (N) = 0)
484 ("discriminant must appear alone in component constraint", N);
488 -- Detect a common error:
490 -- type R (D : Positive := 100) is record
491 -- Name : String (1 .. D);
494 -- The default value causes an object of type R to be allocated
495 -- with room for Positive'Last characters. The RM does not mandate
496 -- the allocation of the maximum size, but that is what GNAT does
497 -- so we should warn the programmer that there is a problem.
499 Check_Large : declare
505 function Large_Storage_Type (T : Entity_Id) return Boolean;
506 -- Return True if type T has a large enough range that any
507 -- array whose index type covered the whole range of the type
508 -- would likely raise Storage_Error.
510 ------------------------
511 -- Large_Storage_Type --
512 ------------------------
514 function Large_Storage_Type (T : Entity_Id) return Boolean is
516 -- The type is considered large if its bounds are known at
517 -- compile time and if it requires at least as many bits as
518 -- a Positive to store the possible values.
520 return Compile_Time_Known_Value (Type_Low_Bound (T))
521 and then Compile_Time_Known_Value (Type_High_Bound (T))
523 Minimum_Size (T, Biased => True) >=
524 RM_Size (Standard_Positive);
525 end Large_Storage_Type;
527 -- Start of processing for Check_Large
530 -- Check that the Disc has a large range
532 if not Large_Storage_Type (Etype (Disc)) then
536 -- If the enclosing type is limited, we allocate only the
537 -- default value, not the maximum, and there is no need for
540 if Is_Limited_Type (Scope (Disc)) then
544 -- Check that it is the high bound
546 if N /= High_Bound (PN)
547 or else No (Discriminant_Default_Value (Disc))
552 -- Check the array allows a large range at this bound. First
557 if Nkind (SI) /= N_Subtype_Indication then
561 T := Entity (Subtype_Mark (SI));
563 if not Is_Array_Type (T) then
567 -- Next, find the dimension
569 TB := First_Index (T);
570 CB := First (Constraints (P));
572 and then Present (TB)
573 and then Present (CB)
584 -- Now, check the dimension has a large range
586 if not Large_Storage_Type (Etype (TB)) then
590 -- Warn about the danger
593 ("?creation of & object may raise Storage_Error!",
602 -- Legal case is in index or discriminant constraint
604 elsif Nkind_In (PN, N_Index_Or_Discriminant_Constraint,
605 N_Discriminant_Association)
607 if Paren_Count (N) > 0 then
609 ("discriminant in constraint must appear alone", N);
611 elsif Nkind (N) = N_Expanded_Name
612 and then Comes_From_Source (N)
615 ("discriminant must appear alone as a direct name", N);
620 -- Otherwise, context is an expression. It should not be within (i.e. a
621 -- subexpression of) a constraint for a component.
626 while not Nkind_In (P, N_Component_Declaration,
627 N_Subtype_Indication,
635 -- If the discriminant is used in an expression that is a bound of a
636 -- scalar type, an Itype is created and the bounds are attached to
637 -- its range, not to the original subtype indication. Such use is of
638 -- course a double fault.
640 if (Nkind (P) = N_Subtype_Indication
641 and then Nkind_In (Parent (P), N_Component_Definition,
642 N_Derived_Type_Definition)
643 and then D = Constraint (P))
645 -- The constraint itself may be given by a subtype indication,
646 -- rather than by a more common discrete range.
648 or else (Nkind (P) = N_Subtype_Indication
650 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
651 or else Nkind (P) = N_Entry_Declaration
652 or else Nkind (D) = N_Defining_Identifier
655 ("discriminant in constraint must appear alone", N);
658 end Check_Discriminant_Use;
660 --------------------------------
661 -- Check_For_Visible_Operator --
662 --------------------------------
664 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
666 if Is_Invisible_Operator (N, T) then
667 Error_Msg_NE -- CODEFIX
668 ("operator for} is not directly visible!", N, First_Subtype (T));
669 Error_Msg_N -- CODEFIX
670 ("use clause would make operation legal!", N);
672 end Check_For_Visible_Operator;
674 ----------------------------------
675 -- Check_Fully_Declared_Prefix --
676 ----------------------------------
678 procedure Check_Fully_Declared_Prefix
683 -- Check that the designated type of the prefix of a dereference is
684 -- not an incomplete type. This cannot be done unconditionally, because
685 -- dereferences of private types are legal in default expressions. This
686 -- case is taken care of in Check_Fully_Declared, called below. There
687 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
689 -- This consideration also applies to similar checks for allocators,
690 -- qualified expressions, and type conversions.
692 -- An additional exception concerns other per-object expressions that
693 -- are not directly related to component declarations, in particular
694 -- representation pragmas for tasks. These will be per-object
695 -- expressions if they depend on discriminants or some global entity.
696 -- If the task has access discriminants, the designated type may be
697 -- incomplete at the point the expression is resolved. This resolution
698 -- takes place within the body of the initialization procedure, where
699 -- the discriminant is replaced by its discriminal.
701 if Is_Entity_Name (Pref)
702 and then Ekind (Entity (Pref)) = E_In_Parameter
706 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
707 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
708 -- Analyze_Object_Renaming, and Freeze_Entity.
710 elsif Ada_Version >= Ada_2005
711 and then Is_Entity_Name (Pref)
712 and then Is_Access_Type (Etype (Pref))
713 and then Ekind (Directly_Designated_Type (Etype (Pref))) =
715 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Pref)))
719 Check_Fully_Declared (Typ, Parent (Pref));
721 end Check_Fully_Declared_Prefix;
723 ------------------------------
724 -- Check_Infinite_Recursion --
725 ------------------------------
727 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
731 function Same_Argument_List return Boolean;
732 -- Check whether list of actuals is identical to list of formals of
733 -- called function (which is also the enclosing scope).
735 ------------------------
736 -- Same_Argument_List --
737 ------------------------
739 function Same_Argument_List return Boolean is
745 if not Is_Entity_Name (Name (N)) then
748 Subp := Entity (Name (N));
751 F := First_Formal (Subp);
752 A := First_Actual (N);
753 while Present (F) and then Present (A) loop
754 if not Is_Entity_Name (A)
755 or else Entity (A) /= F
765 end Same_Argument_List;
767 -- Start of processing for Check_Infinite_Recursion
770 -- Special case, if this is a procedure call and is a call to the
771 -- current procedure with the same argument list, then this is for
772 -- sure an infinite recursion and we insert a call to raise SE.
774 if Is_List_Member (N)
775 and then List_Length (List_Containing (N)) = 1
776 and then Same_Argument_List
779 P : constant Node_Id := Parent (N);
781 if Nkind (P) = N_Handled_Sequence_Of_Statements
782 and then Nkind (Parent (P)) = N_Subprogram_Body
783 and then Is_Empty_List (Declarations (Parent (P)))
785 Error_Msg_N ("!?infinite recursion", N);
786 Error_Msg_N ("\!?Storage_Error will be raised at run time", N);
788 Make_Raise_Storage_Error (Sloc (N),
789 Reason => SE_Infinite_Recursion));
795 -- If not that special case, search up tree, quitting if we reach a
796 -- construct (e.g. a conditional) that tells us that this is not a
797 -- case for an infinite recursion warning.
803 -- If no parent, then we were not inside a subprogram, this can for
804 -- example happen when processing certain pragmas in a spec. Just
805 -- return False in this case.
811 -- Done if we get to subprogram body, this is definitely an infinite
812 -- recursion case if we did not find anything to stop us.
814 exit when Nkind (P) = N_Subprogram_Body;
816 -- If appearing in conditional, result is false
818 if Nkind_In (P, N_Or_Else,
822 N_Conditional_Expression,
827 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
828 and then C /= First (Statements (P))
830 -- If the call is the expression of a return statement and the
831 -- actuals are identical to the formals, it's worth a warning.
832 -- However, we skip this if there is an immediately preceding
833 -- raise statement, since the call is never executed.
835 -- Furthermore, this corresponds to a common idiom:
837 -- function F (L : Thing) return Boolean is
839 -- raise Program_Error;
843 -- for generating a stub function
845 if Nkind (Parent (N)) = N_Simple_Return_Statement
846 and then Same_Argument_List
848 exit when not Is_List_Member (Parent (N));
850 -- OK, return statement is in a statement list, look for raise
856 -- Skip past N_Freeze_Entity nodes generated by expansion
858 Nod := Prev (Parent (N));
860 and then Nkind (Nod) = N_Freeze_Entity
865 -- If no raise statement, give warning
867 exit when Nkind (Nod) /= N_Raise_Statement
869 (Nkind (Nod) not in N_Raise_xxx_Error
870 or else Present (Condition (Nod)));
881 Error_Msg_N ("!?possible infinite recursion", N);
882 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
885 end Check_Infinite_Recursion;
887 -------------------------------
888 -- Check_Initialization_Call --
889 -------------------------------
891 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
892 Typ : constant Entity_Id := Etype (First_Formal (Nam));
894 function Uses_SS (T : Entity_Id) return Boolean;
895 -- Check whether the creation of an object of the type will involve
896 -- use of the secondary stack. If T is a record type, this is true
897 -- if the expression for some component uses the secondary stack, e.g.
898 -- through a call to a function that returns an unconstrained value.
899 -- False if T is controlled, because cleanups occur elsewhere.
905 function Uses_SS (T : Entity_Id) return Boolean is
908 Full_Type : Entity_Id := Underlying_Type (T);
911 -- Normally we want to use the underlying type, but if it's not set
912 -- then continue with T.
914 if not Present (Full_Type) then
918 if Is_Controlled (Full_Type) then
921 elsif Is_Array_Type (Full_Type) then
922 return Uses_SS (Component_Type (Full_Type));
924 elsif Is_Record_Type (Full_Type) then
925 Comp := First_Component (Full_Type);
926 while Present (Comp) loop
927 if Ekind (Comp) = E_Component
928 and then Nkind (Parent (Comp)) = N_Component_Declaration
930 -- The expression for a dynamic component may be rewritten
931 -- as a dereference, so retrieve original node.
933 Expr := Original_Node (Expression (Parent (Comp)));
935 -- Return True if the expression is a call to a function
936 -- (including an attribute function such as Image, or a
937 -- user-defined operator) with a result that requires a
940 if (Nkind (Expr) = N_Function_Call
941 or else Nkind (Expr) in N_Op
942 or else (Nkind (Expr) = N_Attribute_Reference
943 and then Present (Expressions (Expr))))
944 and then Requires_Transient_Scope (Etype (Expr))
948 elsif Uses_SS (Etype (Comp)) then
953 Next_Component (Comp);
963 -- Start of processing for Check_Initialization_Call
966 -- Establish a transient scope if the type needs it
968 if Uses_SS (Typ) then
969 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
971 end Check_Initialization_Call;
973 ---------------------------------------
974 -- Check_No_Direct_Boolean_Operators --
975 ---------------------------------------
977 procedure Check_No_Direct_Boolean_Operators (N : Node_Id) is
979 if Scope (Entity (N)) = Standard_Standard
980 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
982 -- Restriction only applies to original source code
984 if Comes_From_Source (N) then
985 Check_Restriction (No_Direct_Boolean_Operators, N);
990 Check_Boolean_Operator (N);
992 end Check_No_Direct_Boolean_Operators;
994 ------------------------------
995 -- Check_Parameterless_Call --
996 ------------------------------
998 procedure Check_Parameterless_Call (N : Node_Id) is
1001 function Prefix_Is_Access_Subp return Boolean;
1002 -- If the prefix is of an access_to_subprogram type, the node must be
1003 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1004 -- interpretations are access to subprograms.
1006 ---------------------------
1007 -- Prefix_Is_Access_Subp --
1008 ---------------------------
1010 function Prefix_Is_Access_Subp return Boolean is
1015 -- If the context is an attribute reference that can apply to
1016 -- functions, this is never a parameterless call (RM 4.1.4(6)).
1018 if Nkind (Parent (N)) = N_Attribute_Reference
1019 and then (Attribute_Name (Parent (N)) = Name_Address or else
1020 Attribute_Name (Parent (N)) = Name_Code_Address or else
1021 Attribute_Name (Parent (N)) = Name_Access)
1026 if not Is_Overloaded (N) then
1028 Ekind (Etype (N)) = E_Subprogram_Type
1029 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
1031 Get_First_Interp (N, I, It);
1032 while Present (It.Typ) loop
1033 if Ekind (It.Typ) /= E_Subprogram_Type
1034 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
1039 Get_Next_Interp (I, It);
1044 end Prefix_Is_Access_Subp;
1046 -- Start of processing for Check_Parameterless_Call
1049 -- Defend against junk stuff if errors already detected
1051 if Total_Errors_Detected /= 0 then
1052 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
1054 elsif Nkind (N) in N_Has_Chars
1055 and then Chars (N) in Error_Name_Or_No_Name
1063 -- If the context expects a value, and the name is a procedure, this is
1064 -- most likely a missing 'Access. Don't try to resolve the parameterless
1065 -- call, error will be caught when the outer call is analyzed.
1067 if Is_Entity_Name (N)
1068 and then Ekind (Entity (N)) = E_Procedure
1069 and then not Is_Overloaded (N)
1071 Nkind_In (Parent (N), N_Parameter_Association,
1073 N_Procedure_Call_Statement)
1078 -- Rewrite as call if overloadable entity that is (or could be, in the
1079 -- overloaded case) a function call. If we know for sure that the entity
1080 -- is an enumeration literal, we do not rewrite it.
1082 -- If the entity is the name of an operator, it cannot be a call because
1083 -- operators cannot have default parameters. In this case, this must be
1084 -- a string whose contents coincide with an operator name. Set the kind
1085 -- of the node appropriately.
1087 if (Is_Entity_Name (N)
1088 and then Nkind (N) /= N_Operator_Symbol
1089 and then Is_Overloadable (Entity (N))
1090 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1091 or else Is_Overloaded (N)))
1093 -- Rewrite as call if it is an explicit dereference of an expression of
1094 -- a subprogram access type, and the subprogram type is not that of a
1095 -- procedure or entry.
1098 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1100 -- Rewrite as call if it is a selected component which is a function,
1101 -- this is the case of a call to a protected function (which may be
1102 -- overloaded with other protected operations).
1105 (Nkind (N) = N_Selected_Component
1106 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1108 (Ekind_In (Entity (Selector_Name (N)), E_Entry,
1110 and then Is_Overloaded (Selector_Name (N)))))
1112 -- If one of the above three conditions is met, rewrite as call. Apply
1113 -- the rewriting only once.
1116 if Nkind (Parent (N)) /= N_Function_Call
1117 or else N /= Name (Parent (N))
1119 Nam := New_Copy (N);
1121 -- If overloaded, overload set belongs to new copy
1123 Save_Interps (N, Nam);
1125 -- Change node to parameterless function call (note that the
1126 -- Parameter_Associations associations field is left set to Empty,
1127 -- its normal default value since there are no parameters)
1129 Change_Node (N, N_Function_Call);
1131 Set_Sloc (N, Sloc (Nam));
1135 elsif Nkind (N) = N_Parameter_Association then
1136 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1138 elsif Nkind (N) = N_Operator_Symbol then
1139 Change_Operator_Symbol_To_String_Literal (N);
1140 Set_Is_Overloaded (N, False);
1141 Set_Etype (N, Any_String);
1143 end Check_Parameterless_Call;
1145 -----------------------------
1146 -- Is_Definite_Access_Type --
1147 -----------------------------
1149 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1150 Btyp : constant Entity_Id := Base_Type (E);
1152 return Ekind (Btyp) = E_Access_Type
1153 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1154 and then Comes_From_Source (Btyp));
1155 end Is_Definite_Access_Type;
1157 ----------------------
1158 -- Is_Predefined_Op --
1159 ----------------------
1161 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1163 -- Predefined operators are intrinsic subprograms
1165 if not Is_Intrinsic_Subprogram (Nam) then
1169 -- A call to a back-end builtin is never a predefined operator
1171 if Is_Imported (Nam) and then Present (Interface_Name (Nam)) then
1175 return not Is_Generic_Instance (Nam)
1176 and then Chars (Nam) in Any_Operator_Name
1177 and then (No (Alias (Nam)) or else Is_Predefined_Op (Alias (Nam)));
1178 end Is_Predefined_Op;
1180 -----------------------------
1181 -- Make_Call_Into_Operator --
1182 -----------------------------
1184 procedure Make_Call_Into_Operator
1189 Op_Name : constant Name_Id := Chars (Op_Id);
1190 Act1 : Node_Id := First_Actual (N);
1191 Act2 : Node_Id := Next_Actual (Act1);
1192 Error : Boolean := False;
1193 Func : constant Entity_Id := Entity (Name (N));
1194 Is_Binary : constant Boolean := Present (Act2);
1196 Opnd_Type : Entity_Id;
1197 Orig_Type : Entity_Id := Empty;
1200 type Kind_Test is access function (E : Entity_Id) return Boolean;
1202 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1203 -- If the operand is not universal, and the operator is given by an
1204 -- expanded name, verify that the operand has an interpretation with a
1205 -- type defined in the given scope of the operator.
1207 function Type_In_P (Test : Kind_Test) return Entity_Id;
1208 -- Find a type of the given class in package Pack that contains the
1211 ---------------------------
1212 -- Operand_Type_In_Scope --
1213 ---------------------------
1215 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1216 Nod : constant Node_Id := Right_Opnd (Op_Node);
1221 if not Is_Overloaded (Nod) then
1222 return Scope (Base_Type (Etype (Nod))) = S;
1225 Get_First_Interp (Nod, I, It);
1226 while Present (It.Typ) loop
1227 if Scope (Base_Type (It.Typ)) = S then
1231 Get_Next_Interp (I, It);
1236 end Operand_Type_In_Scope;
1242 function Type_In_P (Test : Kind_Test) return Entity_Id is
1245 function In_Decl return Boolean;
1246 -- Verify that node is not part of the type declaration for the
1247 -- candidate type, which would otherwise be invisible.
1253 function In_Decl return Boolean is
1254 Decl_Node : constant Node_Id := Parent (E);
1260 if Etype (E) = Any_Type then
1263 elsif No (Decl_Node) then
1268 and then Nkind (N2) /= N_Compilation_Unit
1270 if N2 = Decl_Node then
1281 -- Start of processing for Type_In_P
1284 -- If the context type is declared in the prefix package, this is the
1285 -- desired base type.
1287 if Scope (Base_Type (Typ)) = Pack and then Test (Typ) then
1288 return Base_Type (Typ);
1291 E := First_Entity (Pack);
1292 while Present (E) loop
1294 and then not In_Decl
1306 -- Start of processing for Make_Call_Into_Operator
1309 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1314 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1315 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1316 Save_Interps (Act1, Left_Opnd (Op_Node));
1317 Save_Interps (Act2, Right_Opnd (Op_Node));
1318 Act1 := Left_Opnd (Op_Node);
1319 Act2 := Right_Opnd (Op_Node);
1324 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1325 Save_Interps (Act1, Right_Opnd (Op_Node));
1326 Act1 := Right_Opnd (Op_Node);
1329 -- If the operator is denoted by an expanded name, and the prefix is
1330 -- not Standard, but the operator is a predefined one whose scope is
1331 -- Standard, then this is an implicit_operator, inserted as an
1332 -- interpretation by the procedure of the same name. This procedure
1333 -- overestimates the presence of implicit operators, because it does
1334 -- not examine the type of the operands. Verify now that the operand
1335 -- type appears in the given scope. If right operand is universal,
1336 -- check the other operand. In the case of concatenation, either
1337 -- argument can be the component type, so check the type of the result.
1338 -- If both arguments are literals, look for a type of the right kind
1339 -- defined in the given scope. This elaborate nonsense is brought to
1340 -- you courtesy of b33302a. The type itself must be frozen, so we must
1341 -- find the type of the proper class in the given scope.
1343 -- A final wrinkle is the multiplication operator for fixed point types,
1344 -- which is defined in Standard only, and not in the scope of the
1345 -- fixed point type itself.
1347 if Nkind (Name (N)) = N_Expanded_Name then
1348 Pack := Entity (Prefix (Name (N)));
1350 -- If the entity being called is defined in the given package, it is
1351 -- a renaming of a predefined operator, and known to be legal.
1353 if Scope (Entity (Name (N))) = Pack
1354 and then Pack /= Standard_Standard
1358 -- Visibility does not need to be checked in an instance: if the
1359 -- operator was not visible in the generic it has been diagnosed
1360 -- already, else there is an implicit copy of it in the instance.
1362 elsif In_Instance then
1365 elsif (Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide)
1366 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1367 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1369 if Pack /= Standard_Standard then
1373 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1376 elsif Ada_Version >= Ada_2005
1377 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1378 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1383 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1385 if Op_Name = Name_Op_Concat then
1386 Opnd_Type := Base_Type (Typ);
1388 elsif (Scope (Opnd_Type) = Standard_Standard
1390 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1392 and then not Comes_From_Source (Opnd_Type))
1394 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1397 if Scope (Opnd_Type) = Standard_Standard then
1399 -- Verify that the scope contains a type that corresponds to
1400 -- the given literal. Optimize the case where Pack is Standard.
1402 if Pack /= Standard_Standard then
1404 if Opnd_Type = Universal_Integer then
1405 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1407 elsif Opnd_Type = Universal_Real then
1408 Orig_Type := Type_In_P (Is_Real_Type'Access);
1410 elsif Opnd_Type = Any_String then
1411 Orig_Type := Type_In_P (Is_String_Type'Access);
1413 elsif Opnd_Type = Any_Access then
1414 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1416 elsif Opnd_Type = Any_Composite then
1417 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1419 if Present (Orig_Type) then
1420 if Has_Private_Component (Orig_Type) then
1423 Set_Etype (Act1, Orig_Type);
1426 Set_Etype (Act2, Orig_Type);
1435 Error := No (Orig_Type);
1438 elsif Ekind (Opnd_Type) = E_Allocator_Type
1439 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1443 -- If the type is defined elsewhere, and the operator is not
1444 -- defined in the given scope (by a renaming declaration, e.g.)
1445 -- then this is an error as well. If an extension of System is
1446 -- present, and the type may be defined there, Pack must be
1449 elsif Scope (Opnd_Type) /= Pack
1450 and then Scope (Op_Id) /= Pack
1451 and then (No (System_Aux_Id)
1452 or else Scope (Opnd_Type) /= System_Aux_Id
1453 or else Pack /= Scope (System_Aux_Id))
1455 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1458 Error := not Operand_Type_In_Scope (Pack);
1461 elsif Pack = Standard_Standard
1462 and then not Operand_Type_In_Scope (Standard_Standard)
1469 Error_Msg_Node_2 := Pack;
1471 ("& not declared in&", N, Selector_Name (Name (N)));
1472 Set_Etype (N, Any_Type);
1475 -- Detect a mismatch between the context type and the result type
1476 -- in the named package, which is otherwise not detected if the
1477 -- operands are universal. Check is only needed if source entity is
1478 -- an operator, not a function that renames an operator.
1480 elsif Nkind (Parent (N)) /= N_Type_Conversion
1481 and then Ekind (Entity (Name (N))) = E_Operator
1482 and then Is_Numeric_Type (Typ)
1483 and then not Is_Universal_Numeric_Type (Typ)
1484 and then Scope (Base_Type (Typ)) /= Pack
1485 and then not In_Instance
1487 if Is_Fixed_Point_Type (Typ)
1488 and then (Op_Name = Name_Op_Multiply
1490 Op_Name = Name_Op_Divide)
1492 -- Already checked above
1496 -- Operator may be defined in an extension of System
1498 elsif Present (System_Aux_Id)
1499 and then Scope (Opnd_Type) = System_Aux_Id
1504 -- Could we use Wrong_Type here??? (this would require setting
1505 -- Etype (N) to the actual type found where Typ was expected).
1507 Error_Msg_NE ("expect }", N, Typ);
1512 Set_Chars (Op_Node, Op_Name);
1514 if not Is_Private_Type (Etype (N)) then
1515 Set_Etype (Op_Node, Base_Type (Etype (N)));
1517 Set_Etype (Op_Node, Etype (N));
1520 -- If this is a call to a function that renames a predefined equality,
1521 -- the renaming declaration provides a type that must be used to
1522 -- resolve the operands. This must be done now because resolution of
1523 -- the equality node will not resolve any remaining ambiguity, and it
1524 -- assumes that the first operand is not overloaded.
1526 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1527 and then Ekind (Func) = E_Function
1528 and then Is_Overloaded (Act1)
1530 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1531 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1534 Set_Entity (Op_Node, Op_Id);
1535 Generate_Reference (Op_Id, N, ' ');
1537 -- Do rewrite setting Comes_From_Source on the result if the original
1538 -- call came from source. Although it is not strictly the case that the
1539 -- operator as such comes from the source, logically it corresponds
1540 -- exactly to the function call in the source, so it should be marked
1541 -- this way (e.g. to make sure that validity checks work fine).
1544 CS : constant Boolean := Comes_From_Source (N);
1546 Rewrite (N, Op_Node);
1547 Set_Comes_From_Source (N, CS);
1550 -- If this is an arithmetic operator and the result type is private,
1551 -- the operands and the result must be wrapped in conversion to
1552 -- expose the underlying numeric type and expand the proper checks,
1553 -- e.g. on division.
1555 if Is_Private_Type (Typ) then
1557 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1558 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1559 Resolve_Intrinsic_Operator (N, Typ);
1561 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1562 Resolve_Intrinsic_Unary_Operator (N, Typ);
1570 end Make_Call_Into_Operator;
1576 function Operator_Kind
1578 Is_Binary : Boolean) return Node_Kind
1583 -- Use CASE statement or array???
1586 if Op_Name = Name_Op_And then
1588 elsif Op_Name = Name_Op_Or then
1590 elsif Op_Name = Name_Op_Xor then
1592 elsif Op_Name = Name_Op_Eq then
1594 elsif Op_Name = Name_Op_Ne then
1596 elsif Op_Name = Name_Op_Lt then
1598 elsif Op_Name = Name_Op_Le then
1600 elsif Op_Name = Name_Op_Gt then
1602 elsif Op_Name = Name_Op_Ge then
1604 elsif Op_Name = Name_Op_Add then
1606 elsif Op_Name = Name_Op_Subtract then
1607 Kind := N_Op_Subtract;
1608 elsif Op_Name = Name_Op_Concat then
1609 Kind := N_Op_Concat;
1610 elsif Op_Name = Name_Op_Multiply then
1611 Kind := N_Op_Multiply;
1612 elsif Op_Name = Name_Op_Divide then
1613 Kind := N_Op_Divide;
1614 elsif Op_Name = Name_Op_Mod then
1616 elsif Op_Name = Name_Op_Rem then
1618 elsif Op_Name = Name_Op_Expon then
1621 raise Program_Error;
1627 if Op_Name = Name_Op_Add then
1629 elsif Op_Name = Name_Op_Subtract then
1631 elsif Op_Name = Name_Op_Abs then
1633 elsif Op_Name = Name_Op_Not then
1636 raise Program_Error;
1643 ----------------------------
1644 -- Preanalyze_And_Resolve --
1645 ----------------------------
1647 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1648 Save_Full_Analysis : constant Boolean := Full_Analysis;
1651 Full_Analysis := False;
1652 Expander_Mode_Save_And_Set (False);
1654 -- We suppress all checks for this analysis, since the checks will
1655 -- be applied properly, and in the right location, when the default
1656 -- expression is reanalyzed and reexpanded later on.
1658 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1660 Expander_Mode_Restore;
1661 Full_Analysis := Save_Full_Analysis;
1662 end Preanalyze_And_Resolve;
1664 -- Version without context type
1666 procedure Preanalyze_And_Resolve (N : Node_Id) is
1667 Save_Full_Analysis : constant Boolean := Full_Analysis;
1670 Full_Analysis := False;
1671 Expander_Mode_Save_And_Set (False);
1674 Resolve (N, Etype (N), Suppress => All_Checks);
1676 Expander_Mode_Restore;
1677 Full_Analysis := Save_Full_Analysis;
1678 end Preanalyze_And_Resolve;
1680 ----------------------------------
1681 -- Replace_Actual_Discriminants --
1682 ----------------------------------
1684 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1685 Loc : constant Source_Ptr := Sloc (N);
1686 Tsk : Node_Id := Empty;
1688 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1694 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1698 if Nkind (Nod) = N_Identifier then
1699 Ent := Entity (Nod);
1702 and then Ekind (Ent) = E_Discriminant
1705 Make_Selected_Component (Loc,
1706 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1707 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1709 Set_Etype (Nod, Etype (Ent));
1717 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1719 -- Start of processing for Replace_Actual_Discriminants
1722 if not Expander_Active then
1726 if Nkind (Name (N)) = N_Selected_Component then
1727 Tsk := Prefix (Name (N));
1729 elsif Nkind (Name (N)) = N_Indexed_Component then
1730 Tsk := Prefix (Prefix (Name (N)));
1736 Replace_Discrs (Default);
1738 end Replace_Actual_Discriminants;
1744 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1745 Ambiguous : Boolean := False;
1746 Ctx_Type : Entity_Id := Typ;
1747 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1748 Err_Type : Entity_Id := Empty;
1749 Found : Boolean := False;
1752 I1 : Interp_Index := 0; -- prevent junk warning
1755 Seen : Entity_Id := Empty; -- prevent junk warning
1757 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1758 -- Determine whether a node comes from a predefined library unit or
1761 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1762 -- Try and fix up a literal so that it matches its expected type. New
1763 -- literals are manufactured if necessary to avoid cascaded errors.
1765 procedure Report_Ambiguous_Argument;
1766 -- Additional diagnostics when an ambiguous call has an ambiguous
1767 -- argument (typically a controlling actual).
1769 procedure Resolution_Failed;
1770 -- Called when attempt at resolving current expression fails
1772 ------------------------------------
1773 -- Comes_From_Predefined_Lib_Unit --
1774 -------------------------------------
1776 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1779 Sloc (Nod) = Standard_Location
1780 or else Is_Predefined_File_Name
1781 (Unit_File_Name (Get_Source_Unit (Sloc (Nod))));
1782 end Comes_From_Predefined_Lib_Unit;
1784 --------------------
1785 -- Patch_Up_Value --
1786 --------------------
1788 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1790 if Nkind (N) = N_Integer_Literal
1791 and then Is_Real_Type (Typ)
1794 Make_Real_Literal (Sloc (N),
1795 Realval => UR_From_Uint (Intval (N))));
1796 Set_Etype (N, Universal_Real);
1797 Set_Is_Static_Expression (N);
1799 elsif Nkind (N) = N_Real_Literal
1800 and then Is_Integer_Type (Typ)
1803 Make_Integer_Literal (Sloc (N),
1804 Intval => UR_To_Uint (Realval (N))));
1805 Set_Etype (N, Universal_Integer);
1806 Set_Is_Static_Expression (N);
1808 elsif Nkind (N) = N_String_Literal
1809 and then Is_Character_Type (Typ)
1811 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1813 Make_Character_Literal (Sloc (N),
1815 Char_Literal_Value =>
1816 UI_From_Int (Character'Pos ('A'))));
1817 Set_Etype (N, Any_Character);
1818 Set_Is_Static_Expression (N);
1820 elsif Nkind (N) /= N_String_Literal
1821 and then Is_String_Type (Typ)
1824 Make_String_Literal (Sloc (N),
1825 Strval => End_String));
1827 elsif Nkind (N) = N_Range then
1828 Patch_Up_Value (Low_Bound (N), Typ);
1829 Patch_Up_Value (High_Bound (N), Typ);
1833 -------------------------------
1834 -- Report_Ambiguous_Argument --
1835 -------------------------------
1837 procedure Report_Ambiguous_Argument is
1838 Arg : constant Node_Id := First (Parameter_Associations (N));
1843 if Nkind (Arg) = N_Function_Call
1844 and then Is_Entity_Name (Name (Arg))
1845 and then Is_Overloaded (Name (Arg))
1847 Error_Msg_NE ("ambiguous call to&", Arg, Name (Arg));
1849 -- Could use comments on what is going on here ???
1851 Get_First_Interp (Name (Arg), I, It);
1852 while Present (It.Nam) loop
1853 Error_Msg_Sloc := Sloc (It.Nam);
1855 if Nkind (Parent (It.Nam)) = N_Full_Type_Declaration then
1856 Error_Msg_N ("interpretation (inherited) #!", Arg);
1858 Error_Msg_N ("interpretation #!", Arg);
1861 Get_Next_Interp (I, It);
1864 end Report_Ambiguous_Argument;
1866 -----------------------
1867 -- Resolution_Failed --
1868 -----------------------
1870 procedure Resolution_Failed is
1872 Patch_Up_Value (N, Typ);
1874 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1875 Set_Is_Overloaded (N, False);
1877 -- The caller will return without calling the expander, so we need
1878 -- to set the analyzed flag. Note that it is fine to set Analyzed
1879 -- to True even if we are in the middle of a shallow analysis,
1880 -- (see the spec of sem for more details) since this is an error
1881 -- situation anyway, and there is no point in repeating the
1882 -- analysis later (indeed it won't work to repeat it later, since
1883 -- we haven't got a clear resolution of which entity is being
1886 Set_Analyzed (N, True);
1888 end Resolution_Failed;
1890 -- Start of processing for Resolve
1897 -- Access attribute on remote subprogram cannot be used for
1898 -- a non-remote access-to-subprogram type.
1900 if Nkind (N) = N_Attribute_Reference
1901 and then (Attribute_Name (N) = Name_Access or else
1902 Attribute_Name (N) = Name_Unrestricted_Access or else
1903 Attribute_Name (N) = Name_Unchecked_Access)
1904 and then Comes_From_Source (N)
1905 and then Is_Entity_Name (Prefix (N))
1906 and then Is_Subprogram (Entity (Prefix (N)))
1907 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1908 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1911 ("prefix must statically denote a non-remote subprogram", N);
1914 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1916 -- If the context is a Remote_Access_To_Subprogram, access attributes
1917 -- must be resolved with the corresponding fat pointer. There is no need
1918 -- to check for the attribute name since the return type of an
1919 -- attribute is never a remote type.
1921 if Nkind (N) = N_Attribute_Reference
1922 and then Comes_From_Source (N)
1923 and then (Is_Remote_Call_Interface (Typ) or else Is_Remote_Types (Typ))
1926 Attr : constant Attribute_Id :=
1927 Get_Attribute_Id (Attribute_Name (N));
1928 Pref : constant Node_Id := Prefix (N);
1931 Is_Remote : Boolean := True;
1934 -- Check that Typ is a remote access-to-subprogram type
1936 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1938 -- Prefix (N) must statically denote a remote subprogram
1939 -- declared in a package specification.
1941 if Attr = Attribute_Access then
1942 Decl := Unit_Declaration_Node (Entity (Pref));
1944 if Nkind (Decl) = N_Subprogram_Body then
1945 Spec := Corresponding_Spec (Decl);
1947 if not No (Spec) then
1948 Decl := Unit_Declaration_Node (Spec);
1952 Spec := Parent (Decl);
1954 if not Is_Entity_Name (Prefix (N))
1955 or else Nkind (Spec) /= N_Package_Specification
1957 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1961 ("prefix must statically denote a remote subprogram ",
1966 -- If we are generating code for a distributed program.
1967 -- perform semantic checks against the corresponding
1970 if (Attr = Attribute_Access or else
1971 Attr = Attribute_Unchecked_Access or else
1972 Attr = Attribute_Unrestricted_Access)
1973 and then Expander_Active
1974 and then Get_PCS_Name /= Name_No_DSA
1976 Check_Subtype_Conformant
1977 (New_Id => Entity (Prefix (N)),
1978 Old_Id => Designated_Type
1979 (Corresponding_Remote_Type (Typ)),
1983 Process_Remote_AST_Attribute (N, Typ);
1990 Debug_A_Entry ("resolving ", N);
1992 if Comes_From_Source (N) then
1993 if Is_Fixed_Point_Type (Typ) then
1994 Check_Restriction (No_Fixed_Point, N);
1996 elsif Is_Floating_Point_Type (Typ)
1997 and then Typ /= Universal_Real
1998 and then Typ /= Any_Real
2000 Check_Restriction (No_Floating_Point, N);
2004 -- Return if already analyzed
2006 if Analyzed (N) then
2007 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
2010 -- Return if type = Any_Type (previous error encountered)
2012 elsif Etype (N) = Any_Type then
2013 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
2017 Check_Parameterless_Call (N);
2019 -- If not overloaded, then we know the type, and all that needs doing
2020 -- is to check that this type is compatible with the context.
2022 if not Is_Overloaded (N) then
2023 Found := Covers (Typ, Etype (N));
2024 Expr_Type := Etype (N);
2026 -- In the overloaded case, we must select the interpretation that
2027 -- is compatible with the context (i.e. the type passed to Resolve)
2030 -- Loop through possible interpretations
2032 Get_First_Interp (N, I, It);
2033 Interp_Loop : while Present (It.Typ) loop
2035 -- We are only interested in interpretations that are compatible
2036 -- with the expected type, any other interpretations are ignored.
2038 if not Covers (Typ, It.Typ) then
2039 if Debug_Flag_V then
2040 Write_Str (" interpretation incompatible with context");
2045 -- Skip the current interpretation if it is disabled by an
2046 -- abstract operator. This action is performed only when the
2047 -- type against which we are resolving is the same as the
2048 -- type of the interpretation.
2050 if Ada_Version >= Ada_2005
2051 and then It.Typ = Typ
2052 and then Typ /= Universal_Integer
2053 and then Typ /= Universal_Real
2054 and then Present (It.Abstract_Op)
2059 -- First matching interpretation
2065 Expr_Type := It.Typ;
2067 -- Matching interpretation that is not the first, maybe an
2068 -- error, but there are some cases where preference rules are
2069 -- used to choose between the two possibilities. These and
2070 -- some more obscure cases are handled in Disambiguate.
2073 -- If the current statement is part of a predefined library
2074 -- unit, then all interpretations which come from user level
2075 -- packages should not be considered.
2078 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
2083 Error_Msg_Sloc := Sloc (Seen);
2084 It1 := Disambiguate (N, I1, I, Typ);
2086 -- Disambiguation has succeeded. Skip the remaining
2089 if It1 /= No_Interp then
2091 Expr_Type := It1.Typ;
2093 while Present (It.Typ) loop
2094 Get_Next_Interp (I, It);
2098 -- Before we issue an ambiguity complaint, check for
2099 -- the case of a subprogram call where at least one
2100 -- of the arguments is Any_Type, and if so, suppress
2101 -- the message, since it is a cascaded error.
2103 if Nkind_In (N, N_Function_Call,
2104 N_Procedure_Call_Statement)
2111 A := First_Actual (N);
2112 while Present (A) loop
2115 if Nkind (E) = N_Parameter_Association then
2116 E := Explicit_Actual_Parameter (E);
2119 if Etype (E) = Any_Type then
2120 if Debug_Flag_V then
2121 Write_Str ("Any_Type in call");
2132 elsif Nkind (N) in N_Binary_Op
2133 and then (Etype (Left_Opnd (N)) = Any_Type
2134 or else Etype (Right_Opnd (N)) = Any_Type)
2138 elsif Nkind (N) in N_Unary_Op
2139 and then Etype (Right_Opnd (N)) = Any_Type
2144 -- Not that special case, so issue message using the
2145 -- flag Ambiguous to control printing of the header
2146 -- message only at the start of an ambiguous set.
2148 if not Ambiguous then
2149 if Nkind (N) = N_Function_Call
2150 and then Nkind (Name (N)) = N_Explicit_Dereference
2153 ("ambiguous expression "
2154 & "(cannot resolve indirect call)!", N);
2156 Error_Msg_NE -- CODEFIX
2157 ("ambiguous expression (cannot resolve&)!",
2163 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2165 ("\\possible interpretation (inherited)#!", N);
2167 Error_Msg_N -- CODEFIX
2168 ("\\possible interpretation#!", N);
2172 (N, N_Procedure_Call_Statement, N_Function_Call)
2173 and then Present (Parameter_Associations (N))
2175 Report_Ambiguous_Argument;
2179 Error_Msg_Sloc := Sloc (It.Nam);
2181 -- By default, the error message refers to the candidate
2182 -- interpretation. But if it is a predefined operator, it
2183 -- is implicitly declared at the declaration of the type
2184 -- of the operand. Recover the sloc of that declaration
2185 -- for the error message.
2187 if Nkind (N) in N_Op
2188 and then Scope (It.Nam) = Standard_Standard
2189 and then not Is_Overloaded (Right_Opnd (N))
2190 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2193 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2195 if Comes_From_Source (Err_Type)
2196 and then Present (Parent (Err_Type))
2198 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2201 elsif Nkind (N) in N_Binary_Op
2202 and then Scope (It.Nam) = Standard_Standard
2203 and then not Is_Overloaded (Left_Opnd (N))
2204 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2207 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2209 if Comes_From_Source (Err_Type)
2210 and then Present (Parent (Err_Type))
2212 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2215 -- If this is an indirect call, use the subprogram_type
2216 -- in the message, to have a meaningful location. Also
2217 -- indicate if this is an inherited operation, created
2218 -- by a type declaration.
2220 elsif Nkind (N) = N_Function_Call
2221 and then Nkind (Name (N)) = N_Explicit_Dereference
2222 and then Is_Type (It.Nam)
2226 Sloc (Associated_Node_For_Itype (Err_Type));
2231 if Nkind (N) in N_Op
2232 and then Scope (It.Nam) = Standard_Standard
2233 and then Present (Err_Type)
2235 -- Special-case the message for universal_fixed
2236 -- operators, which are not declared with the type
2237 -- of the operand, but appear forever in Standard.
2239 if It.Typ = Universal_Fixed
2240 and then Scope (It.Nam) = Standard_Standard
2243 ("\\possible interpretation as " &
2244 "universal_fixed operation " &
2245 "(RM 4.5.5 (19))", N);
2248 ("\\possible interpretation (predefined)#!", N);
2252 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2255 ("\\possible interpretation (inherited)#!", N);
2257 Error_Msg_N -- CODEFIX
2258 ("\\possible interpretation#!", N);
2264 -- We have a matching interpretation, Expr_Type is the type
2265 -- from this interpretation, and Seen is the entity.
2267 -- For an operator, just set the entity name. The type will be
2268 -- set by the specific operator resolution routine.
2270 if Nkind (N) in N_Op then
2271 Set_Entity (N, Seen);
2272 Generate_Reference (Seen, N);
2274 elsif Nkind (N) = N_Case_Expression then
2275 Set_Etype (N, Expr_Type);
2277 elsif Nkind (N) = N_Character_Literal then
2278 Set_Etype (N, Expr_Type);
2280 elsif Nkind (N) = N_Conditional_Expression then
2281 Set_Etype (N, Expr_Type);
2283 -- For an explicit dereference, attribute reference, range,
2284 -- short-circuit form (which is not an operator node), or call
2285 -- with a name that is an explicit dereference, there is
2286 -- nothing to be done at this point.
2288 elsif Nkind_In (N, N_Explicit_Dereference,
2289 N_Attribute_Reference,
2291 N_Indexed_Component,
2294 N_Selected_Component,
2296 or else Nkind (Name (N)) = N_Explicit_Dereference
2300 -- For procedure or function calls, set the type of the name,
2301 -- and also the entity pointer for the prefix.
2303 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2304 and then Is_Entity_Name (Name (N))
2306 Set_Etype (Name (N), Expr_Type);
2307 Set_Entity (Name (N), Seen);
2308 Generate_Reference (Seen, Name (N));
2310 elsif Nkind (N) = N_Function_Call
2311 and then Nkind (Name (N)) = N_Selected_Component
2313 Set_Etype (Name (N), Expr_Type);
2314 Set_Entity (Selector_Name (Name (N)), Seen);
2315 Generate_Reference (Seen, Selector_Name (Name (N)));
2317 -- For all other cases, just set the type of the Name
2320 Set_Etype (Name (N), Expr_Type);
2327 -- Move to next interpretation
2329 exit Interp_Loop when No (It.Typ);
2331 Get_Next_Interp (I, It);
2332 end loop Interp_Loop;
2335 -- At this stage Found indicates whether or not an acceptable
2336 -- interpretation exists. If not, then we have an error, except that if
2337 -- the context is Any_Type as a result of some other error, then we
2338 -- suppress the error report.
2341 if Typ /= Any_Type then
2343 -- If type we are looking for is Void, then this is the procedure
2344 -- call case, and the error is simply that what we gave is not a
2345 -- procedure name (we think of procedure calls as expressions with
2346 -- types internally, but the user doesn't think of them this way!)
2348 if Typ = Standard_Void_Type then
2350 -- Special case message if function used as a procedure
2352 if Nkind (N) = N_Procedure_Call_Statement
2353 and then Is_Entity_Name (Name (N))
2354 and then Ekind (Entity (Name (N))) = E_Function
2357 ("cannot use function & in a procedure call",
2358 Name (N), Entity (Name (N)));
2360 -- Otherwise give general message (not clear what cases this
2361 -- covers, but no harm in providing for them!)
2364 Error_Msg_N ("expect procedure name in procedure call", N);
2369 -- Otherwise we do have a subexpression with the wrong type
2371 -- Check for the case of an allocator which uses an access type
2372 -- instead of the designated type. This is a common error and we
2373 -- specialize the message, posting an error on the operand of the
2374 -- allocator, complaining that we expected the designated type of
2377 elsif Nkind (N) = N_Allocator
2378 and then Ekind (Typ) in Access_Kind
2379 and then Ekind (Etype (N)) in Access_Kind
2380 and then Designated_Type (Etype (N)) = Typ
2382 Wrong_Type (Expression (N), Designated_Type (Typ));
2385 -- Check for view mismatch on Null in instances, for which the
2386 -- view-swapping mechanism has no identifier.
2388 elsif (In_Instance or else In_Inlined_Body)
2389 and then (Nkind (N) = N_Null)
2390 and then Is_Private_Type (Typ)
2391 and then Is_Access_Type (Full_View (Typ))
2393 Resolve (N, Full_View (Typ));
2397 -- Check for an aggregate. Sometimes we can get bogus aggregates
2398 -- from misuse of parentheses, and we are about to complain about
2399 -- the aggregate without even looking inside it.
2401 -- Instead, if we have an aggregate of type Any_Composite, then
2402 -- analyze and resolve the component fields, and then only issue
2403 -- another message if we get no errors doing this (otherwise
2404 -- assume that the errors in the aggregate caused the problem).
2406 elsif Nkind (N) = N_Aggregate
2407 and then Etype (N) = Any_Composite
2409 -- Disable expansion in any case. If there is a type mismatch
2410 -- it may be fatal to try to expand the aggregate. The flag
2411 -- would otherwise be set to false when the error is posted.
2413 Expander_Active := False;
2416 procedure Check_Aggr (Aggr : Node_Id);
2417 -- Check one aggregate, and set Found to True if we have a
2418 -- definite error in any of its elements
2420 procedure Check_Elmt (Aelmt : Node_Id);
2421 -- Check one element of aggregate and set Found to True if
2422 -- we definitely have an error in the element.
2428 procedure Check_Aggr (Aggr : Node_Id) is
2432 if Present (Expressions (Aggr)) then
2433 Elmt := First (Expressions (Aggr));
2434 while Present (Elmt) loop
2440 if Present (Component_Associations (Aggr)) then
2441 Elmt := First (Component_Associations (Aggr));
2442 while Present (Elmt) loop
2444 -- If this is a default-initialized component, then
2445 -- there is nothing to check. The box will be
2446 -- replaced by the appropriate call during late
2449 if not Box_Present (Elmt) then
2450 Check_Elmt (Expression (Elmt));
2462 procedure Check_Elmt (Aelmt : Node_Id) is
2464 -- If we have a nested aggregate, go inside it (to
2465 -- attempt a naked analyze-resolve of the aggregate can
2466 -- cause undesirable cascaded errors). Do not resolve
2467 -- expression if it needs a type from context, as for
2468 -- integer * fixed expression.
2470 if Nkind (Aelmt) = N_Aggregate then
2476 if not Is_Overloaded (Aelmt)
2477 and then Etype (Aelmt) /= Any_Fixed
2482 if Etype (Aelmt) = Any_Type then
2493 -- If an error message was issued already, Found got reset to
2494 -- True, so if it is still False, issue standard Wrong_Type msg.
2497 if Is_Overloaded (N)
2498 and then Nkind (N) = N_Function_Call
2501 Subp_Name : Node_Id;
2503 if Is_Entity_Name (Name (N)) then
2504 Subp_Name := Name (N);
2506 elsif Nkind (Name (N)) = N_Selected_Component then
2508 -- Protected operation: retrieve operation name
2510 Subp_Name := Selector_Name (Name (N));
2513 raise Program_Error;
2516 Error_Msg_Node_2 := Typ;
2517 Error_Msg_NE ("no visible interpretation of&" &
2518 " matches expected type&", N, Subp_Name);
2521 if All_Errors_Mode then
2523 Index : Interp_Index;
2527 Error_Msg_N ("\\possible interpretations:", N);
2529 Get_First_Interp (Name (N), Index, It);
2530 while Present (It.Nam) loop
2531 Error_Msg_Sloc := Sloc (It.Nam);
2532 Error_Msg_Node_2 := It.Nam;
2534 ("\\ type& for & declared#", N, It.Typ);
2535 Get_Next_Interp (Index, It);
2540 Error_Msg_N ("\use -gnatf for details", N);
2544 Wrong_Type (N, Typ);
2552 -- Test if we have more than one interpretation for the context
2554 elsif Ambiguous then
2558 -- Here we have an acceptable interpretation for the context
2561 -- Propagate type information and normalize tree for various
2562 -- predefined operations. If the context only imposes a class of
2563 -- types, rather than a specific type, propagate the actual type
2566 if Typ = Any_Integer or else
2567 Typ = Any_Boolean or else
2568 Typ = Any_Modular or else
2569 Typ = Any_Real or else
2572 Ctx_Type := Expr_Type;
2574 -- Any_Fixed is legal in a real context only if a specific fixed-
2575 -- point type is imposed. If Norman Cohen can be confused by this,
2576 -- it deserves a separate message.
2579 and then Expr_Type = Any_Fixed
2581 Error_Msg_N ("illegal context for mixed mode operation", N);
2582 Set_Etype (N, Universal_Real);
2583 Ctx_Type := Universal_Real;
2587 -- A user-defined operator is transformed into a function call at
2588 -- this point, so that further processing knows that operators are
2589 -- really operators (i.e. are predefined operators). User-defined
2590 -- operators that are intrinsic are just renamings of the predefined
2591 -- ones, and need not be turned into calls either, but if they rename
2592 -- a different operator, we must transform the node accordingly.
2593 -- Instantiations of Unchecked_Conversion are intrinsic but are
2594 -- treated as functions, even if given an operator designator.
2596 if Nkind (N) in N_Op
2597 and then Present (Entity (N))
2598 and then Ekind (Entity (N)) /= E_Operator
2601 if not Is_Predefined_Op (Entity (N)) then
2602 Rewrite_Operator_As_Call (N, Entity (N));
2604 elsif Present (Alias (Entity (N)))
2606 Nkind (Parent (Parent (Entity (N)))) =
2607 N_Subprogram_Renaming_Declaration
2609 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2611 -- If the node is rewritten, it will be fully resolved in
2612 -- Rewrite_Renamed_Operator.
2614 if Analyzed (N) then
2620 case N_Subexpr'(Nkind (N)) is
2622 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2624 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2626 when N_Short_Circuit
2627 => Resolve_Short_Circuit (N, Ctx_Type);
2629 when N_Attribute_Reference
2630 => Resolve_Attribute (N, Ctx_Type);
2632 when N_Case_Expression
2633 => Resolve_Case_Expression (N, Ctx_Type);
2635 when N_Character_Literal
2636 => Resolve_Character_Literal (N, Ctx_Type);
2638 when N_Conditional_Expression
2639 => Resolve_Conditional_Expression (N, Ctx_Type);
2641 when N_Expanded_Name
2642 => Resolve_Entity_Name (N, Ctx_Type);
2644 when N_Explicit_Dereference
2645 => Resolve_Explicit_Dereference (N, Ctx_Type);
2647 when N_Expression_With_Actions
2648 => Resolve_Expression_With_Actions (N, Ctx_Type);
2650 when N_Extension_Aggregate
2651 => Resolve_Extension_Aggregate (N, Ctx_Type);
2653 when N_Function_Call
2654 => Resolve_Call (N, Ctx_Type);
2657 => Resolve_Entity_Name (N, Ctx_Type);
2659 when N_Indexed_Component
2660 => Resolve_Indexed_Component (N, Ctx_Type);
2662 when N_Integer_Literal
2663 => Resolve_Integer_Literal (N, Ctx_Type);
2665 when N_Membership_Test
2666 => Resolve_Membership_Op (N, Ctx_Type);
2668 when N_Null => Resolve_Null (N, Ctx_Type);
2670 when N_Op_And | N_Op_Or | N_Op_Xor
2671 => Resolve_Logical_Op (N, Ctx_Type);
2673 when N_Op_Eq | N_Op_Ne
2674 => Resolve_Equality_Op (N, Ctx_Type);
2676 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2677 => Resolve_Comparison_Op (N, Ctx_Type);
2679 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2681 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2682 N_Op_Divide | N_Op_Mod | N_Op_Rem
2684 => Resolve_Arithmetic_Op (N, Ctx_Type);
2686 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2688 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2690 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2691 => Resolve_Unary_Op (N, Ctx_Type);
2693 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2695 when N_Procedure_Call_Statement
2696 => Resolve_Call (N, Ctx_Type);
2698 when N_Operator_Symbol
2699 => Resolve_Operator_Symbol (N, Ctx_Type);
2701 when N_Qualified_Expression
2702 => Resolve_Qualified_Expression (N, Ctx_Type);
2704 when N_Quantified_Expression
2705 => Resolve_Quantified_Expression (N, Ctx_Type);
2707 when N_Raise_xxx_Error
2708 => Set_Etype (N, Ctx_Type);
2710 when N_Range => Resolve_Range (N, Ctx_Type);
2713 => Resolve_Real_Literal (N, Ctx_Type);
2715 when N_Reference => Resolve_Reference (N, Ctx_Type);
2717 when N_Selected_Component
2718 => Resolve_Selected_Component (N, Ctx_Type);
2720 when N_Slice => Resolve_Slice (N, Ctx_Type);
2722 when N_String_Literal
2723 => Resolve_String_Literal (N, Ctx_Type);
2725 when N_Subprogram_Info
2726 => Resolve_Subprogram_Info (N, Ctx_Type);
2728 when N_Type_Conversion
2729 => Resolve_Type_Conversion (N, Ctx_Type);
2731 when N_Unchecked_Expression =>
2732 Resolve_Unchecked_Expression (N, Ctx_Type);
2734 when N_Unchecked_Type_Conversion =>
2735 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2738 -- If the subexpression was replaced by a non-subexpression, then
2739 -- all we do is to expand it. The only legitimate case we know of
2740 -- is converting procedure call statement to entry call statements,
2741 -- but there may be others, so we are making this test general.
2743 if Nkind (N) not in N_Subexpr then
2744 Debug_A_Exit ("resolving ", N, " (done)");
2749 -- AI05-144-2: Check dangerous order dependence within an expression
2750 -- that is not a subexpression. Exclude RHS of an assignment, because
2751 -- both sides may have side-effects and the check must be performed
2752 -- over the statement.
2754 if Nkind (Parent (N)) not in N_Subexpr
2755 and then Nkind (Parent (N)) /= N_Assignment_Statement
2756 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2758 Check_Order_Dependence;
2761 -- The expression is definitely NOT overloaded at this point, so
2762 -- we reset the Is_Overloaded flag to avoid any confusion when
2763 -- reanalyzing the node.
2765 Set_Is_Overloaded (N, False);
2767 -- Freeze expression type, entity if it is a name, and designated
2768 -- type if it is an allocator (RM 13.14(10,11,13)).
2770 -- Now that the resolution of the type of the node is complete, and
2771 -- we did not detect an error, we can expand this node. We skip the
2772 -- expand call if we are in a default expression, see section
2773 -- "Handling of Default Expressions" in Sem spec.
2775 Debug_A_Exit ("resolving ", N, " (done)");
2777 -- We unconditionally freeze the expression, even if we are in
2778 -- default expression mode (the Freeze_Expression routine tests this
2779 -- flag and only freezes static types if it is set).
2781 Freeze_Expression (N);
2783 -- Now we can do the expansion
2793 -- Version with check(s) suppressed
2795 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2797 if Suppress = All_Checks then
2799 Svg : constant Suppress_Array := Scope_Suppress;
2801 Scope_Suppress := (others => True);
2803 Scope_Suppress := Svg;
2808 Svg : constant Boolean := Scope_Suppress (Suppress);
2810 Scope_Suppress (Suppress) := True;
2812 Scope_Suppress (Suppress) := Svg;
2821 -- Version with implicit type
2823 procedure Resolve (N : Node_Id) is
2825 Resolve (N, Etype (N));
2828 ---------------------
2829 -- Resolve_Actuals --
2830 ---------------------
2832 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2833 Loc : constant Source_Ptr := Sloc (N);
2838 Prev : Node_Id := Empty;
2841 procedure Check_Argument_Order;
2842 -- Performs a check for the case where the actuals are all simple
2843 -- identifiers that correspond to the formal names, but in the wrong
2844 -- order, which is considered suspicious and cause for a warning.
2846 procedure Check_Prefixed_Call;
2847 -- If the original node is an overloaded call in prefix notation,
2848 -- insert an 'Access or a dereference as needed over the first actual.
2849 -- Try_Object_Operation has already verified that there is a valid
2850 -- interpretation, but the form of the actual can only be determined
2851 -- once the primitive operation is identified.
2853 procedure Insert_Default;
2854 -- If the actual is missing in a call, insert in the actuals list
2855 -- an instance of the default expression. The insertion is always
2856 -- a named association.
2858 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2859 -- Check whether T1 and T2, or their full views, are derived from a
2860 -- common type. Used to enforce the restrictions on array conversions
2863 function Static_Concatenation (N : Node_Id) return Boolean;
2864 -- Predicate to determine whether an actual that is a concatenation
2865 -- will be evaluated statically and does not need a transient scope.
2866 -- This must be determined before the actual is resolved and expanded
2867 -- because if needed the transient scope must be introduced earlier.
2869 --------------------------
2870 -- Check_Argument_Order --
2871 --------------------------
2873 procedure Check_Argument_Order is
2875 -- Nothing to do if no parameters, or original node is neither a
2876 -- function call nor a procedure call statement (happens in the
2877 -- operator-transformed-to-function call case), or the call does
2878 -- not come from source, or this warning is off.
2880 if not Warn_On_Parameter_Order
2881 or else No (Parameter_Associations (N))
2882 or else not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2884 or else not Comes_From_Source (N)
2890 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2893 -- Nothing to do if only one parameter
2899 -- Here if at least two arguments
2902 Actuals : array (1 .. Nargs) of Node_Id;
2906 Wrong_Order : Boolean := False;
2907 -- Set True if an out of order case is found
2910 -- Collect identifier names of actuals, fail if any actual is
2911 -- not a simple identifier, and record max length of name.
2913 Actual := First (Parameter_Associations (N));
2914 for J in Actuals'Range loop
2915 if Nkind (Actual) /= N_Identifier then
2918 Actuals (J) := Actual;
2923 -- If we got this far, all actuals are identifiers and the list
2924 -- of their names is stored in the Actuals array.
2926 Formal := First_Formal (Nam);
2927 for J in Actuals'Range loop
2929 -- If we ran out of formals, that's odd, probably an error
2930 -- which will be detected elsewhere, but abandon the search.
2936 -- If name matches and is in order OK
2938 if Chars (Formal) = Chars (Actuals (J)) then
2942 -- If no match, see if it is elsewhere in list and if so
2943 -- flag potential wrong order if type is compatible.
2945 for K in Actuals'Range loop
2946 if Chars (Formal) = Chars (Actuals (K))
2948 Has_Compatible_Type (Actuals (K), Etype (Formal))
2950 Wrong_Order := True;
2960 <<Continue>> Next_Formal (Formal);
2963 -- If Formals left over, also probably an error, skip warning
2965 if Present (Formal) then
2969 -- Here we give the warning if something was out of order
2973 ("actuals for this call may be in wrong order?", N);
2977 end Check_Argument_Order;
2979 -------------------------
2980 -- Check_Prefixed_Call --
2981 -------------------------
2983 procedure Check_Prefixed_Call is
2984 Act : constant Node_Id := First_Actual (N);
2985 A_Type : constant Entity_Id := Etype (Act);
2986 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
2987 Orig : constant Node_Id := Original_Node (N);
2991 -- Check whether the call is a prefixed call, with or without
2992 -- additional actuals.
2994 if Nkind (Orig) = N_Selected_Component
2996 (Nkind (Orig) = N_Indexed_Component
2997 and then Nkind (Prefix (Orig)) = N_Selected_Component
2998 and then Is_Entity_Name (Prefix (Prefix (Orig)))
2999 and then Is_Entity_Name (Act)
3000 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
3002 if Is_Access_Type (A_Type)
3003 and then not Is_Access_Type (F_Type)
3005 -- Introduce dereference on object in prefix
3008 Make_Explicit_Dereference (Sloc (Act),
3009 Prefix => Relocate_Node (Act));
3010 Rewrite (Act, New_A);
3013 elsif Is_Access_Type (F_Type)
3014 and then not Is_Access_Type (A_Type)
3016 -- Introduce an implicit 'Access in prefix
3018 if not Is_Aliased_View (Act) then
3020 ("object in prefixed call to& must be aliased"
3021 & " (RM-2005 4.3.1 (13))",
3026 Make_Attribute_Reference (Loc,
3027 Attribute_Name => Name_Access,
3028 Prefix => Relocate_Node (Act)));
3033 end Check_Prefixed_Call;
3035 --------------------
3036 -- Insert_Default --
3037 --------------------
3039 procedure Insert_Default is
3044 -- Missing argument in call, nothing to insert
3046 if No (Default_Value (F)) then
3050 -- Note that we do a full New_Copy_Tree, so that any associated
3051 -- Itypes are properly copied. This may not be needed any more,
3052 -- but it does no harm as a safety measure! Defaults of a generic
3053 -- formal may be out of bounds of the corresponding actual (see
3054 -- cc1311b) and an additional check may be required.
3059 New_Scope => Current_Scope,
3062 if Is_Concurrent_Type (Scope (Nam))
3063 and then Has_Discriminants (Scope (Nam))
3065 Replace_Actual_Discriminants (N, Actval);
3068 if Is_Overloadable (Nam)
3069 and then Present (Alias (Nam))
3071 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
3072 and then not Is_Tagged_Type (Etype (F))
3074 -- If default is a real literal, do not introduce a
3075 -- conversion whose effect may depend on the run-time
3076 -- size of universal real.
3078 if Nkind (Actval) = N_Real_Literal then
3079 Set_Etype (Actval, Base_Type (Etype (F)));
3081 Actval := Unchecked_Convert_To (Etype (F), Actval);
3085 if Is_Scalar_Type (Etype (F)) then
3086 Enable_Range_Check (Actval);
3089 Set_Parent (Actval, N);
3091 -- Resolve aggregates with their base type, to avoid scope
3092 -- anomalies: the subtype was first built in the subprogram
3093 -- declaration, and the current call may be nested.
3095 if Nkind (Actval) = N_Aggregate then
3096 Analyze_And_Resolve (Actval, Etype (F));
3098 Analyze_And_Resolve (Actval, Etype (Actval));
3102 Set_Parent (Actval, N);
3104 -- See note above concerning aggregates
3106 if Nkind (Actval) = N_Aggregate
3107 and then Has_Discriminants (Etype (Actval))
3109 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
3111 -- Resolve entities with their own type, which may differ from
3112 -- the type of a reference in a generic context (the view
3113 -- swapping mechanism did not anticipate the re-analysis of
3114 -- default values in calls).
3116 elsif Is_Entity_Name (Actval) then
3117 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
3120 Analyze_And_Resolve (Actval, Etype (Actval));
3124 -- If default is a tag indeterminate function call, propagate tag
3125 -- to obtain proper dispatching.
3127 if Is_Controlling_Formal (F)
3128 and then Nkind (Default_Value (F)) = N_Function_Call
3130 Set_Is_Controlling_Actual (Actval);
3135 -- If the default expression raises constraint error, then just
3136 -- silently replace it with an N_Raise_Constraint_Error node, since
3137 -- we already gave the warning on the subprogram spec. If node is
3138 -- already a Raise_Constraint_Error leave as is, to prevent loops in
3139 -- the warnings removal machinery.
3141 if Raises_Constraint_Error (Actval)
3142 and then Nkind (Actval) /= N_Raise_Constraint_Error
3145 Make_Raise_Constraint_Error (Loc,
3146 Reason => CE_Range_Check_Failed));
3147 Set_Raises_Constraint_Error (Actval);
3148 Set_Etype (Actval, Etype (F));
3152 Make_Parameter_Association (Loc,
3153 Explicit_Actual_Parameter => Actval,
3154 Selector_Name => Make_Identifier (Loc, Chars (F)));
3156 -- Case of insertion is first named actual
3158 if No (Prev) or else
3159 Nkind (Parent (Prev)) /= N_Parameter_Association
3161 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
3162 Set_First_Named_Actual (N, Actval);
3165 if No (Parameter_Associations (N)) then
3166 Set_Parameter_Associations (N, New_List (Assoc));
3168 Append (Assoc, Parameter_Associations (N));
3172 Insert_After (Prev, Assoc);
3175 -- Case of insertion is not first named actual
3178 Set_Next_Named_Actual
3179 (Assoc, Next_Named_Actual (Parent (Prev)));
3180 Set_Next_Named_Actual (Parent (Prev), Actval);
3181 Append (Assoc, Parameter_Associations (N));
3184 Mark_Rewrite_Insertion (Assoc);
3185 Mark_Rewrite_Insertion (Actval);
3194 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
3195 FT1 : Entity_Id := T1;
3196 FT2 : Entity_Id := T2;
3199 if Is_Private_Type (T1)
3200 and then Present (Full_View (T1))
3202 FT1 := Full_View (T1);
3205 if Is_Private_Type (T2)
3206 and then Present (Full_View (T2))
3208 FT2 := Full_View (T2);
3211 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3214 --------------------------
3215 -- Static_Concatenation --
3216 --------------------------
3218 function Static_Concatenation (N : Node_Id) return Boolean is
3221 when N_String_Literal =>
3226 -- Concatenation is static when both operands are static and
3227 -- the concatenation operator is a predefined one.
3229 return Scope (Entity (N)) = Standard_Standard
3231 Static_Concatenation (Left_Opnd (N))
3233 Static_Concatenation (Right_Opnd (N));
3236 if Is_Entity_Name (N) then
3238 Ent : constant Entity_Id := Entity (N);
3240 return Ekind (Ent) = E_Constant
3241 and then Present (Constant_Value (Ent))
3243 Is_Static_Expression (Constant_Value (Ent));
3250 end Static_Concatenation;
3252 -- Start of processing for Resolve_Actuals
3255 Check_Argument_Order;
3257 if Present (First_Actual (N)) then
3258 Check_Prefixed_Call;
3261 A := First_Actual (N);
3262 F := First_Formal (Nam);
3263 while Present (F) loop
3264 if No (A) and then Needs_No_Actuals (Nam) then
3267 -- If we have an error in any actual or formal, indicated by a type
3268 -- of Any_Type, then abandon resolution attempt, and set result type
3271 elsif (Present (A) and then Etype (A) = Any_Type)
3272 or else Etype (F) = Any_Type
3274 Set_Etype (N, Any_Type);
3278 -- Case where actual is present
3280 -- If the actual is an entity, generate a reference to it now. We
3281 -- do this before the actual is resolved, because a formal of some
3282 -- protected subprogram, or a task discriminant, will be rewritten
3283 -- during expansion, and the source entity reference may be lost.
3286 and then Is_Entity_Name (A)
3287 and then Comes_From_Source (N)
3289 Orig_A := Entity (A);
3291 if Present (Orig_A) then
3292 if Is_Formal (Orig_A)
3293 and then Ekind (F) /= E_In_Parameter
3295 Generate_Reference (Orig_A, A, 'm');
3297 elsif not Is_Overloaded (A) then
3298 Generate_Reference (Orig_A, A);
3304 and then (Nkind (Parent (A)) /= N_Parameter_Association
3305 or else Chars (Selector_Name (Parent (A))) = Chars (F))
3307 -- If style checking mode on, check match of formal name
3310 if Nkind (Parent (A)) = N_Parameter_Association then
3311 Check_Identifier (Selector_Name (Parent (A)), F);
3315 -- If the formal is Out or In_Out, do not resolve and expand the
3316 -- conversion, because it is subsequently expanded into explicit
3317 -- temporaries and assignments. However, the object of the
3318 -- conversion can be resolved. An exception is the case of tagged
3319 -- type conversion with a class-wide actual. In that case we want
3320 -- the tag check to occur and no temporary will be needed (no
3321 -- representation change can occur) and the parameter is passed by
3322 -- reference, so we go ahead and resolve the type conversion.
3323 -- Another exception is the case of reference to component or
3324 -- subcomponent of a bit-packed array, in which case we want to
3325 -- defer expansion to the point the in and out assignments are
3328 if Ekind (F) /= E_In_Parameter
3329 and then Nkind (A) = N_Type_Conversion
3330 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3332 if Ekind (F) = E_In_Out_Parameter
3333 and then Is_Array_Type (Etype (F))
3335 -- In a view conversion, the conversion must be legal in
3336 -- both directions, and thus both component types must be
3337 -- aliased, or neither (4.6 (8)).
3339 -- The extra rule in 4.6 (24.9.2) seems unduly restrictive:
3340 -- the privacy requirement should not apply to generic
3341 -- types, and should be checked in an instance. ARG query
3344 if Has_Aliased_Components (Etype (Expression (A))) /=
3345 Has_Aliased_Components (Etype (F))
3348 ("both component types in a view conversion must be"
3349 & " aliased, or neither", A);
3351 -- Comment here??? what set of cases???
3354 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3356 -- Check view conv between unrelated by ref array types
3358 if Is_By_Reference_Type (Etype (F))
3359 or else Is_By_Reference_Type (Etype (Expression (A)))
3362 ("view conversion between unrelated by reference " &
3363 "array types not allowed (\'A'I-00246)", A);
3365 -- In Ada 2005 mode, check view conversion component
3366 -- type cannot be private, tagged, or volatile. Note
3367 -- that we only apply this to source conversions. The
3368 -- generated code can contain conversions which are
3369 -- not subject to this test, and we cannot extract the
3370 -- component type in such cases since it is not present.
3372 elsif Comes_From_Source (A)
3373 and then Ada_Version >= Ada_2005
3376 Comp_Type : constant Entity_Id :=
3378 (Etype (Expression (A)));
3380 if (Is_Private_Type (Comp_Type)
3381 and then not Is_Generic_Type (Comp_Type))
3382 or else Is_Tagged_Type (Comp_Type)
3383 or else Is_Volatile (Comp_Type)
3386 ("component type of a view conversion cannot"
3387 & " be private, tagged, or volatile"
3396 -- Resolve expression if conversion is all OK
3398 if (Conversion_OK (A)
3399 or else Valid_Conversion (A, Etype (A), Expression (A)))
3400 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3402 Resolve (Expression (A));
3405 -- If the actual is a function call that returns a limited
3406 -- unconstrained object that needs finalization, create a
3407 -- transient scope for it, so that it can receive the proper
3408 -- finalization list.
3410 elsif Nkind (A) = N_Function_Call
3411 and then Is_Limited_Record (Etype (F))
3412 and then not Is_Constrained (Etype (F))
3413 and then Expander_Active
3414 and then (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3416 Establish_Transient_Scope (A, False);
3418 -- A small optimization: if one of the actuals is a concatenation
3419 -- create a block around a procedure call to recover stack space.
3420 -- This alleviates stack usage when several procedure calls in
3421 -- the same statement list use concatenation. We do not perform
3422 -- this wrapping for code statements, where the argument is a
3423 -- static string, and we want to preserve warnings involving
3424 -- sequences of such statements.
3426 elsif Nkind (A) = N_Op_Concat
3427 and then Nkind (N) = N_Procedure_Call_Statement
3428 and then Expander_Active
3430 not (Is_Intrinsic_Subprogram (Nam)
3431 and then Chars (Nam) = Name_Asm)
3432 and then not Static_Concatenation (A)
3434 Establish_Transient_Scope (A, False);
3435 Resolve (A, Etype (F));
3438 if Nkind (A) = N_Type_Conversion
3439 and then Is_Array_Type (Etype (F))
3440 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3442 (Is_Limited_Type (Etype (F))
3443 or else Is_Limited_Type (Etype (Expression (A))))
3446 ("conversion between unrelated limited array types " &
3447 "not allowed (\A\I-00246)", A);
3449 if Is_Limited_Type (Etype (F)) then
3450 Explain_Limited_Type (Etype (F), A);
3453 if Is_Limited_Type (Etype (Expression (A))) then
3454 Explain_Limited_Type (Etype (Expression (A)), A);
3458 -- (Ada 2005: AI-251): If the actual is an allocator whose
3459 -- directly designated type is a class-wide interface, we build
3460 -- an anonymous access type to use it as the type of the
3461 -- allocator. Later, when the subprogram call is expanded, if
3462 -- the interface has a secondary dispatch table the expander
3463 -- will add a type conversion to force the correct displacement
3466 if Nkind (A) = N_Allocator then
3468 DDT : constant Entity_Id :=
3469 Directly_Designated_Type (Base_Type (Etype (F)));
3471 New_Itype : Entity_Id;
3474 if Is_Class_Wide_Type (DDT)
3475 and then Is_Interface (DDT)
3477 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3478 Set_Etype (New_Itype, Etype (A));
3479 Set_Directly_Designated_Type (New_Itype,
3480 Directly_Designated_Type (Etype (A)));
3481 Set_Etype (A, New_Itype);
3484 -- Ada 2005, AI-162:If the actual is an allocator, the
3485 -- innermost enclosing statement is the master of the
3486 -- created object. This needs to be done with expansion
3487 -- enabled only, otherwise the transient scope will not
3488 -- be removed in the expansion of the wrapped construct.
3490 if (Is_Controlled (DDT) or else Has_Task (DDT))
3491 and then Expander_Active
3493 Establish_Transient_Scope (A, False);
3498 -- (Ada 2005): The call may be to a primitive operation of
3499 -- a tagged synchronized type, declared outside of the type.
3500 -- In this case the controlling actual must be converted to
3501 -- its corresponding record type, which is the formal type.
3502 -- The actual may be a subtype, either because of a constraint
3503 -- or because it is a generic actual, so use base type to
3504 -- locate concurrent type.
3506 F_Typ := Base_Type (Etype (F));
3508 if Is_Tagged_Type (F_Typ)
3509 and then (Is_Concurrent_Type (F_Typ)
3510 or else Is_Concurrent_Record_Type (F_Typ))
3512 -- If the actual is overloaded, look for an interpretation
3513 -- that has a synchronized type.
3515 if not Is_Overloaded (A) then
3516 A_Typ := Base_Type (Etype (A));
3520 Index : Interp_Index;
3524 Get_First_Interp (A, Index, It);
3525 while Present (It.Typ) loop
3526 if Is_Concurrent_Type (It.Typ)
3527 or else Is_Concurrent_Record_Type (It.Typ)
3529 A_Typ := Base_Type (It.Typ);
3533 Get_Next_Interp (Index, It);
3539 Full_A_Typ : Entity_Id;
3542 if Present (Full_View (A_Typ)) then
3543 Full_A_Typ := Base_Type (Full_View (A_Typ));
3545 Full_A_Typ := A_Typ;
3548 -- Tagged synchronized type (case 1): the actual is a
3551 if Is_Concurrent_Type (A_Typ)
3552 and then Corresponding_Record_Type (A_Typ) = F_Typ
3555 Unchecked_Convert_To
3556 (Corresponding_Record_Type (A_Typ), A));
3557 Resolve (A, Etype (F));
3559 -- Tagged synchronized type (case 2): the formal is a
3562 elsif Ekind (Full_A_Typ) = E_Record_Type
3564 (Corresponding_Concurrent_Type (Full_A_Typ))
3565 and then Is_Concurrent_Type (F_Typ)
3566 and then Present (Corresponding_Record_Type (F_Typ))
3567 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3569 Resolve (A, Corresponding_Record_Type (F_Typ));
3574 Resolve (A, Etype (F));
3579 -- not a synchronized operation.
3581 Resolve (A, Etype (F));
3588 if Comes_From_Source (Original_Node (N))
3589 and then Nkind_In (Original_Node (N), N_Function_Call,
3590 N_Procedure_Call_Statement)
3592 -- In formal mode, check that actual parameters matching
3593 -- formals of tagged types are objects (or ancestor type
3594 -- conversions of objects), not general expressions.
3596 if Is_Actual_Tagged_Parameter (A) then
3597 if Is_SPARK_Object_Reference (A) then
3600 elsif Nkind (A) = N_Type_Conversion then
3602 Operand : constant Node_Id := Expression (A);
3603 Operand_Typ : constant Entity_Id := Etype (Operand);
3604 Target_Typ : constant Entity_Id := A_Typ;
3607 if not Is_SPARK_Object_Reference (Operand) then
3608 Check_SPARK_Restriction
3609 ("object required", Operand);
3611 -- In formal mode, the only view conversions are those
3612 -- involving ancestor conversion of an extended type.
3615 (Is_Tagged_Type (Target_Typ)
3616 and then not Is_Class_Wide_Type (Target_Typ)
3617 and then Is_Tagged_Type (Operand_Typ)
3618 and then not Is_Class_Wide_Type (Operand_Typ)
3619 and then Is_Ancestor (Target_Typ, Operand_Typ))
3622 (F, E_Out_Parameter, E_In_Out_Parameter)
3624 Check_SPARK_Restriction
3625 ("ancestor conversion is the only permitted "
3626 & "view conversion", A);
3628 Check_SPARK_Restriction
3629 ("ancestor conversion required", A);
3638 Check_SPARK_Restriction ("object required", A);
3641 -- In formal mode, the only view conversions are those
3642 -- involving ancestor conversion of an extended type.
3644 elsif Nkind (A) = N_Type_Conversion
3645 and then Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter)
3647 Check_SPARK_Restriction
3648 ("ancestor conversion is the only permitted view "
3653 -- Save actual for subsequent check on order dependence, and
3654 -- indicate whether actual is modifiable. For AI05-0144-2.
3656 Save_Actual (A, Ekind (F) /= E_In_Parameter);
3658 -- For mode IN, if actual is an entity, and the type of the formal
3659 -- has warnings suppressed, then we reset Never_Set_In_Source for
3660 -- the calling entity. The reason for this is to catch cases like
3661 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3662 -- uses trickery to modify an IN parameter.
3664 if Ekind (F) = E_In_Parameter
3665 and then Is_Entity_Name (A)
3666 and then Present (Entity (A))
3667 and then Ekind (Entity (A)) = E_Variable
3668 and then Has_Warnings_Off (F_Typ)
3670 Set_Never_Set_In_Source (Entity (A), False);
3673 -- Perform error checks for IN and IN OUT parameters
3675 if Ekind (F) /= E_Out_Parameter then
3677 -- Check unset reference. For scalar parameters, it is clearly
3678 -- wrong to pass an uninitialized value as either an IN or
3679 -- IN-OUT parameter. For composites, it is also clearly an
3680 -- error to pass a completely uninitialized value as an IN
3681 -- parameter, but the case of IN OUT is trickier. We prefer
3682 -- not to give a warning here. For example, suppose there is
3683 -- a routine that sets some component of a record to False.
3684 -- It is perfectly reasonable to make this IN-OUT and allow
3685 -- either initialized or uninitialized records to be passed
3688 -- For partially initialized composite values, we also avoid
3689 -- warnings, since it is quite likely that we are passing a
3690 -- partially initialized value and only the initialized fields
3691 -- will in fact be read in the subprogram.
3693 if Is_Scalar_Type (A_Typ)
3694 or else (Ekind (F) = E_In_Parameter
3695 and then not Is_Partially_Initialized_Type (A_Typ))
3697 Check_Unset_Reference (A);
3700 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3701 -- actual to a nested call, since this is case of reading an
3702 -- out parameter, which is not allowed.
3704 if Ada_Version = Ada_83
3705 and then Is_Entity_Name (A)
3706 and then Ekind (Entity (A)) = E_Out_Parameter
3708 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3712 -- Case of OUT or IN OUT parameter
3714 if Ekind (F) /= E_In_Parameter then
3716 -- For an Out parameter, check for useless assignment. Note
3717 -- that we can't set Last_Assignment this early, because we may
3718 -- kill current values in Resolve_Call, and that call would
3719 -- clobber the Last_Assignment field.
3721 -- Note: call Warn_On_Useless_Assignment before doing the check
3722 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3723 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3724 -- reflects the last assignment, not this one!
3726 if Ekind (F) = E_Out_Parameter then
3727 if Warn_On_Modified_As_Out_Parameter (F)
3728 and then Is_Entity_Name (A)
3729 and then Present (Entity (A))
3730 and then Comes_From_Source (N)
3732 Warn_On_Useless_Assignment (Entity (A), A);
3736 -- Validate the form of the actual. Note that the call to
3737 -- Is_OK_Variable_For_Out_Formal generates the required
3738 -- reference in this case.
3740 if not Is_OK_Variable_For_Out_Formal (A) then
3741 Error_Msg_NE ("actual for& must be a variable", A, F);
3744 -- What's the following about???
3746 if Is_Entity_Name (A) then
3747 Kill_Checks (Entity (A));
3753 if Etype (A) = Any_Type then
3754 Set_Etype (N, Any_Type);
3758 -- Apply appropriate range checks for in, out, and in-out
3759 -- parameters. Out and in-out parameters also need a separate
3760 -- check, if there is a type conversion, to make sure the return
3761 -- value meets the constraints of the variable before the
3764 -- Gigi looks at the check flag and uses the appropriate types.
3765 -- For now since one flag is used there is an optimization which
3766 -- might not be done in the In Out case since Gigi does not do
3767 -- any analysis. More thought required about this ???
3769 if Ekind_In (F, E_In_Parameter, E_In_Out_Parameter) then
3771 -- Apply predicate checks, unless this is a call to the
3772 -- predicate check function itself, which would cause an
3773 -- infinite recursion.
3775 if not (Ekind (Nam) = E_Function
3776 and then Has_Predicates (Nam))
3778 Apply_Predicate_Check (A, F_Typ);
3781 -- Apply required constraint checks
3783 if Is_Scalar_Type (Etype (A)) then
3784 Apply_Scalar_Range_Check (A, F_Typ);
3786 elsif Is_Array_Type (Etype (A)) then
3787 Apply_Length_Check (A, F_Typ);
3789 elsif Is_Record_Type (F_Typ)
3790 and then Has_Discriminants (F_Typ)
3791 and then Is_Constrained (F_Typ)
3792 and then (not Is_Derived_Type (F_Typ)
3793 or else Comes_From_Source (Nam))
3795 Apply_Discriminant_Check (A, F_Typ);
3797 elsif Is_Access_Type (F_Typ)
3798 and then Is_Array_Type (Designated_Type (F_Typ))
3799 and then Is_Constrained (Designated_Type (F_Typ))
3801 Apply_Length_Check (A, F_Typ);
3803 elsif Is_Access_Type (F_Typ)
3804 and then Has_Discriminants (Designated_Type (F_Typ))
3805 and then Is_Constrained (Designated_Type (F_Typ))
3807 Apply_Discriminant_Check (A, F_Typ);
3810 Apply_Range_Check (A, F_Typ);
3813 -- Ada 2005 (AI-231): Note that the controlling parameter case
3814 -- already existed in Ada 95, which is partially checked
3815 -- elsewhere (see Checks), and we don't want the warning
3816 -- message to differ.
3818 if Is_Access_Type (F_Typ)
3819 and then Can_Never_Be_Null (F_Typ)
3820 and then Known_Null (A)
3822 if Is_Controlling_Formal (F) then
3823 Apply_Compile_Time_Constraint_Error
3825 Msg => "null value not allowed here?",
3826 Reason => CE_Access_Check_Failed);
3828 elsif Ada_Version >= Ada_2005 then
3829 Apply_Compile_Time_Constraint_Error
3831 Msg => "(Ada 2005) null not allowed in "
3832 & "null-excluding formal?",
3833 Reason => CE_Null_Not_Allowed);
3838 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter) then
3839 if Nkind (A) = N_Type_Conversion then
3840 if Is_Scalar_Type (A_Typ) then
3841 Apply_Scalar_Range_Check
3842 (Expression (A), Etype (Expression (A)), A_Typ);
3845 (Expression (A), Etype (Expression (A)), A_Typ);
3849 if Is_Scalar_Type (F_Typ) then
3850 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3851 elsif Is_Array_Type (F_Typ)
3852 and then Ekind (F) = E_Out_Parameter
3854 Apply_Length_Check (A, F_Typ);
3856 Apply_Range_Check (A, A_Typ, F_Typ);
3861 -- An actual associated with an access parameter is implicitly
3862 -- converted to the anonymous access type of the formal and must
3863 -- satisfy the legality checks for access conversions.
3865 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3866 if not Valid_Conversion (A, F_Typ, A) then
3868 ("invalid implicit conversion for access parameter", A);
3872 -- Check bad case of atomic/volatile argument (RM C.6(12))
3874 if Is_By_Reference_Type (Etype (F))
3875 and then Comes_From_Source (N)
3877 if Is_Atomic_Object (A)
3878 and then not Is_Atomic (Etype (F))
3881 ("cannot pass atomic argument to non-atomic formal",
3884 elsif Is_Volatile_Object (A)
3885 and then not Is_Volatile (Etype (F))
3888 ("cannot pass volatile argument to non-volatile formal",
3893 -- Check that subprograms don't have improper controlling
3894 -- arguments (RM 3.9.2 (9)).
3896 -- A primitive operation may have an access parameter of an
3897 -- incomplete tagged type, but a dispatching call is illegal
3898 -- if the type is still incomplete.
3900 if Is_Controlling_Formal (F) then
3901 Set_Is_Controlling_Actual (A);
3903 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3905 Desig : constant Entity_Id := Designated_Type (Etype (F));
3907 if Ekind (Desig) = E_Incomplete_Type
3908 and then No (Full_View (Desig))
3909 and then No (Non_Limited_View (Desig))
3912 ("premature use of incomplete type& " &
3913 "in dispatching call", A, Desig);
3918 elsif Nkind (A) = N_Explicit_Dereference then
3919 Validate_Remote_Access_To_Class_Wide_Type (A);
3922 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3923 and then not Is_Class_Wide_Type (F_Typ)
3924 and then not Is_Controlling_Formal (F)
3926 Error_Msg_N ("class-wide argument not allowed here!", A);
3928 if Is_Subprogram (Nam)
3929 and then Comes_From_Source (Nam)
3931 Error_Msg_Node_2 := F_Typ;
3933 ("& is not a dispatching operation of &!", A, Nam);
3936 elsif Is_Access_Type (A_Typ)
3937 and then Is_Access_Type (F_Typ)
3938 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3939 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3940 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3941 or else (Nkind (A) = N_Attribute_Reference
3943 Is_Class_Wide_Type (Etype (Prefix (A)))))
3944 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3945 and then not Is_Controlling_Formal (F)
3947 -- Disable these checks for call to imported C++ subprograms
3950 (Is_Entity_Name (Name (N))
3951 and then Is_Imported (Entity (Name (N)))
3952 and then Convention (Entity (Name (N))) = Convention_CPP)
3955 ("access to class-wide argument not allowed here!", A);
3957 if Is_Subprogram (Nam)
3958 and then Comes_From_Source (Nam)
3960 Error_Msg_Node_2 := Designated_Type (F_Typ);
3962 ("& is not a dispatching operation of &!", A, Nam);
3968 -- If it is a named association, treat the selector_name as a
3969 -- proper identifier, and mark the corresponding entity.
3971 if Nkind (Parent (A)) = N_Parameter_Association then
3972 Set_Entity (Selector_Name (Parent (A)), F);
3973 Generate_Reference (F, Selector_Name (Parent (A)));
3974 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3975 Generate_Reference (F_Typ, N, ' ');
3980 if Ekind (F) /= E_Out_Parameter then
3981 Check_Unset_Reference (A);
3986 -- Case where actual is not present
3994 end Resolve_Actuals;
3996 -----------------------
3997 -- Resolve_Allocator --
3998 -----------------------
4000 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
4001 E : constant Node_Id := Expression (N);
4003 Discrim : Entity_Id;
4006 Assoc : Node_Id := Empty;
4009 procedure Check_Allocator_Discrim_Accessibility
4010 (Disc_Exp : Node_Id;
4011 Alloc_Typ : Entity_Id);
4012 -- Check that accessibility level associated with an access discriminant
4013 -- initialized in an allocator by the expression Disc_Exp is not deeper
4014 -- than the level of the allocator type Alloc_Typ. An error message is
4015 -- issued if this condition is violated. Specialized checks are done for
4016 -- the cases of a constraint expression which is an access attribute or
4017 -- an access discriminant.
4019 function In_Dispatching_Context return Boolean;
4020 -- If the allocator is an actual in a call, it is allowed to be class-
4021 -- wide when the context is not because it is a controlling actual.
4023 procedure Propagate_Coextensions (Root : Node_Id);
4024 -- Propagate all nested coextensions which are located one nesting
4025 -- level down the tree to the node Root. Example:
4028 -- Level_1_Coextension
4029 -- Level_2_Coextension
4031 -- The algorithm is paired with delay actions done by the Expander. In
4032 -- the above example, assume all coextensions are controlled types.
4033 -- The cycle of analysis, resolution and expansion will yield:
4035 -- 1) Analyze Top_Record
4036 -- 2) Analyze Level_1_Coextension
4037 -- 3) Analyze Level_2_Coextension
4038 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
4040 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
4041 -- generated to capture the allocated object. Temp_1 is attached
4042 -- to the coextension chain of Level_2_Coextension.
4043 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
4044 -- coextension. A forward tree traversal is performed which finds
4045 -- Level_2_Coextension's list and copies its contents into its
4047 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
4048 -- generated to capture the allocated object. Temp_2 is attached
4049 -- to the coextension chain of Level_1_Coextension. Currently, the
4050 -- contents of the list are [Temp_2, Temp_1].
4051 -- 8) Resolve Top_Record. A forward tree traversal is performed which
4052 -- finds Level_1_Coextension's list and copies its contents into
4054 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
4055 -- Temp_2 and attach them to Top_Record's finalization list.
4057 -------------------------------------------
4058 -- Check_Allocator_Discrim_Accessibility --
4059 -------------------------------------------
4061 procedure Check_Allocator_Discrim_Accessibility
4062 (Disc_Exp : Node_Id;
4063 Alloc_Typ : Entity_Id)
4066 if Type_Access_Level (Etype (Disc_Exp)) >
4067 Type_Access_Level (Alloc_Typ)
4070 ("operand type has deeper level than allocator type", Disc_Exp);
4072 -- When the expression is an Access attribute the level of the prefix
4073 -- object must not be deeper than that of the allocator's type.
4075 elsif Nkind (Disc_Exp) = N_Attribute_Reference
4076 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
4078 and then Object_Access_Level (Prefix (Disc_Exp))
4079 > Type_Access_Level (Alloc_Typ)
4082 ("prefix of attribute has deeper level than allocator type",
4085 -- When the expression is an access discriminant the check is against
4086 -- the level of the prefix object.
4088 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
4089 and then Nkind (Disc_Exp) = N_Selected_Component
4090 and then Object_Access_Level (Prefix (Disc_Exp))
4091 > Type_Access_Level (Alloc_Typ)
4094 ("access discriminant has deeper level than allocator type",
4097 -- All other cases are legal
4102 end Check_Allocator_Discrim_Accessibility;
4104 ----------------------------
4105 -- In_Dispatching_Context --
4106 ----------------------------
4108 function In_Dispatching_Context return Boolean is
4109 Par : constant Node_Id := Parent (N);
4111 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
4112 and then Is_Entity_Name (Name (Par))
4113 and then Is_Dispatching_Operation (Entity (Name (Par)));
4114 end In_Dispatching_Context;
4116 ----------------------------
4117 -- Propagate_Coextensions --
4118 ----------------------------
4120 procedure Propagate_Coextensions (Root : Node_Id) is
4122 procedure Copy_List (From : Elist_Id; To : Elist_Id);
4123 -- Copy the contents of list From into list To, preserving the
4124 -- order of elements.
4126 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
4127 -- Recognize an allocator or a rewritten allocator node and add it
4128 -- along with its nested coextensions to the list of Root.
4134 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
4135 From_Elmt : Elmt_Id;
4137 From_Elmt := First_Elmt (From);
4138 while Present (From_Elmt) loop
4139 Append_Elmt (Node (From_Elmt), To);
4140 Next_Elmt (From_Elmt);
4144 -----------------------
4145 -- Process_Allocator --
4146 -----------------------
4148 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
4149 Orig_Nod : Node_Id := Nod;
4152 -- This is a possible rewritten subtype indication allocator. Any
4153 -- nested coextensions will appear as discriminant constraints.
4155 if Nkind (Nod) = N_Identifier
4156 and then Present (Original_Node (Nod))
4157 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
4161 Discr_Elmt : Elmt_Id;
4164 if Is_Record_Type (Entity (Nod)) then
4166 First_Elmt (Discriminant_Constraint (Entity (Nod)));
4167 while Present (Discr_Elmt) loop
4168 Discr := Node (Discr_Elmt);
4170 if Nkind (Discr) = N_Identifier
4171 and then Present (Original_Node (Discr))
4172 and then Nkind (Original_Node (Discr)) = N_Allocator
4173 and then Present (Coextensions (
4174 Original_Node (Discr)))
4176 if No (Coextensions (Root)) then
4177 Set_Coextensions (Root, New_Elmt_List);
4181 (From => Coextensions (Original_Node (Discr)),
4182 To => Coextensions (Root));
4185 Next_Elmt (Discr_Elmt);
4188 -- There is no need to continue the traversal of this
4189 -- subtree since all the information has already been
4196 -- Case of either a stand alone allocator or a rewritten allocator
4197 -- with an aggregate.
4200 if Present (Original_Node (Nod)) then
4201 Orig_Nod := Original_Node (Nod);
4204 if Nkind (Orig_Nod) = N_Allocator then
4206 -- Propagate the list of nested coextensions to the Root
4207 -- allocator. This is done through list copy since a single
4208 -- allocator may have multiple coextensions. Do not touch
4209 -- coextensions roots.
4211 if not Is_Coextension_Root (Orig_Nod)
4212 and then Present (Coextensions (Orig_Nod))
4214 if No (Coextensions (Root)) then
4215 Set_Coextensions (Root, New_Elmt_List);
4219 (From => Coextensions (Orig_Nod),
4220 To => Coextensions (Root));
4223 -- There is no need to continue the traversal of this
4224 -- subtree since all the information has already been
4231 -- Keep on traversing, looking for the next allocator
4234 end Process_Allocator;
4236 procedure Process_Allocators is
4237 new Traverse_Proc (Process_Allocator);
4239 -- Start of processing for Propagate_Coextensions
4242 Process_Allocators (Expression (Root));
4243 end Propagate_Coextensions;
4245 -- Start of processing for Resolve_Allocator
4248 -- Replace general access with specific type
4250 if Ekind (Etype (N)) = E_Allocator_Type then
4251 Set_Etype (N, Base_Type (Typ));
4254 if Is_Abstract_Type (Typ) then
4255 Error_Msg_N ("type of allocator cannot be abstract", N);
4258 -- For qualified expression, resolve the expression using the
4259 -- given subtype (nothing to do for type mark, subtype indication)
4261 if Nkind (E) = N_Qualified_Expression then
4262 if Is_Class_Wide_Type (Etype (E))
4263 and then not Is_Class_Wide_Type (Designated_Type (Typ))
4264 and then not In_Dispatching_Context
4267 ("class-wide allocator not allowed for this access type", N);
4270 Resolve (Expression (E), Etype (E));
4271 Check_Unset_Reference (Expression (E));
4273 -- A qualified expression requires an exact match of the type,
4274 -- class-wide matching is not allowed.
4276 if (Is_Class_Wide_Type (Etype (Expression (E)))
4277 or else Is_Class_Wide_Type (Etype (E)))
4278 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
4280 Wrong_Type (Expression (E), Etype (E));
4283 -- A special accessibility check is needed for allocators that
4284 -- constrain access discriminants. The level of the type of the
4285 -- expression used to constrain an access discriminant cannot be
4286 -- deeper than the type of the allocator (in contrast to access
4287 -- parameters, where the level of the actual can be arbitrary).
4289 -- We can't use Valid_Conversion to perform this check because
4290 -- in general the type of the allocator is unrelated to the type
4291 -- of the access discriminant.
4293 if Ekind (Typ) /= E_Anonymous_Access_Type
4294 or else Is_Local_Anonymous_Access (Typ)
4296 Subtyp := Entity (Subtype_Mark (E));
4298 Aggr := Original_Node (Expression (E));
4300 if Has_Discriminants (Subtyp)
4301 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
4303 Discrim := First_Discriminant (Base_Type (Subtyp));
4305 -- Get the first component expression of the aggregate
4307 if Present (Expressions (Aggr)) then
4308 Disc_Exp := First (Expressions (Aggr));
4310 elsif Present (Component_Associations (Aggr)) then
4311 Assoc := First (Component_Associations (Aggr));
4313 if Present (Assoc) then
4314 Disc_Exp := Expression (Assoc);
4323 while Present (Discrim) and then Present (Disc_Exp) loop
4324 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4325 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4328 Next_Discriminant (Discrim);
4330 if Present (Discrim) then
4331 if Present (Assoc) then
4333 Disc_Exp := Expression (Assoc);
4335 elsif Present (Next (Disc_Exp)) then
4339 Assoc := First (Component_Associations (Aggr));
4341 if Present (Assoc) then
4342 Disc_Exp := Expression (Assoc);
4352 -- For a subtype mark or subtype indication, freeze the subtype
4355 Freeze_Expression (E);
4357 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
4359 ("initialization required for access-to-constant allocator", N);
4362 -- A special accessibility check is needed for allocators that
4363 -- constrain access discriminants. The level of the type of the
4364 -- expression used to constrain an access discriminant cannot be
4365 -- deeper than the type of the allocator (in contrast to access
4366 -- parameters, where the level of the actual can be arbitrary).
4367 -- We can't use Valid_Conversion to perform this check because
4368 -- in general the type of the allocator is unrelated to the type
4369 -- of the access discriminant.
4371 if Nkind (Original_Node (E)) = N_Subtype_Indication
4372 and then (Ekind (Typ) /= E_Anonymous_Access_Type
4373 or else Is_Local_Anonymous_Access (Typ))
4375 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
4377 if Has_Discriminants (Subtyp) then
4378 Discrim := First_Discriminant (Base_Type (Subtyp));
4379 Constr := First (Constraints (Constraint (Original_Node (E))));
4380 while Present (Discrim) and then Present (Constr) loop
4381 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4382 if Nkind (Constr) = N_Discriminant_Association then
4383 Disc_Exp := Original_Node (Expression (Constr));
4385 Disc_Exp := Original_Node (Constr);
4388 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4391 Next_Discriminant (Discrim);
4398 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4399 -- check that the level of the type of the created object is not deeper
4400 -- than the level of the allocator's access type, since extensions can
4401 -- now occur at deeper levels than their ancestor types. This is a
4402 -- static accessibility level check; a run-time check is also needed in
4403 -- the case of an initialized allocator with a class-wide argument (see
4404 -- Expand_Allocator_Expression).
4406 if Ada_Version >= Ada_2005
4407 and then Is_Class_Wide_Type (Designated_Type (Typ))
4410 Exp_Typ : Entity_Id;
4413 if Nkind (E) = N_Qualified_Expression then
4414 Exp_Typ := Etype (E);
4415 elsif Nkind (E) = N_Subtype_Indication then
4416 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4418 Exp_Typ := Entity (E);
4421 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4422 if In_Instance_Body then
4423 Error_Msg_N ("?type in allocator has deeper level than" &
4424 " designated class-wide type", E);
4425 Error_Msg_N ("\?Program_Error will be raised at run time",
4428 Make_Raise_Program_Error (Sloc (N),
4429 Reason => PE_Accessibility_Check_Failed));
4432 -- Do not apply Ada 2005 accessibility checks on a class-wide
4433 -- allocator if the type given in the allocator is a formal
4434 -- type. A run-time check will be performed in the instance.
4436 elsif not Is_Generic_Type (Exp_Typ) then
4437 Error_Msg_N ("type in allocator has deeper level than" &
4438 " designated class-wide type", E);
4444 -- Check for allocation from an empty storage pool
4446 if No_Pool_Assigned (Typ) then
4447 Error_Msg_N ("allocation from empty storage pool!", N);
4449 -- If the context is an unchecked conversion, as may happen within an
4450 -- inlined subprogram, the allocator is being resolved with its own
4451 -- anonymous type. In that case, if the target type has a specific
4452 -- storage pool, it must be inherited explicitly by the allocator type.
4454 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4455 and then No (Associated_Storage_Pool (Typ))
4457 Set_Associated_Storage_Pool
4458 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4461 if Ekind (Etype (N)) = E_Anonymous_Access_Type then
4462 Check_Restriction (No_Anonymous_Allocators, N);
4465 -- An erroneous allocator may be rewritten as a raise Program_Error
4468 if Nkind (N) = N_Allocator then
4470 -- An anonymous access discriminant is the definition of a
4473 if Ekind (Typ) = E_Anonymous_Access_Type
4474 and then Nkind (Associated_Node_For_Itype (Typ)) =
4475 N_Discriminant_Specification
4477 -- Avoid marking an allocator as a dynamic coextension if it is
4478 -- within a static construct.
4480 if not Is_Static_Coextension (N) then
4481 Set_Is_Dynamic_Coextension (N);
4484 -- Cleanup for potential static coextensions
4487 Set_Is_Dynamic_Coextension (N, False);
4488 Set_Is_Static_Coextension (N, False);
4491 -- There is no need to propagate any nested coextensions if they
4492 -- are marked as static since they will be rewritten on the spot.
4494 if not Is_Static_Coextension (N) then
4495 Propagate_Coextensions (N);
4498 end Resolve_Allocator;
4500 ---------------------------
4501 -- Resolve_Arithmetic_Op --
4502 ---------------------------
4504 -- Used for resolving all arithmetic operators except exponentiation
4506 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4507 L : constant Node_Id := Left_Opnd (N);
4508 R : constant Node_Id := Right_Opnd (N);
4509 TL : constant Entity_Id := Base_Type (Etype (L));
4510 TR : constant Entity_Id := Base_Type (Etype (R));
4514 B_Typ : constant Entity_Id := Base_Type (Typ);
4515 -- We do the resolution using the base type, because intermediate values
4516 -- in expressions always are of the base type, not a subtype of it.
4518 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4519 -- Returns True if N is in a context that expects "any real type"
4521 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4522 -- Return True iff given type is Integer or universal real/integer
4524 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4525 -- Choose type of integer literal in fixed-point operation to conform
4526 -- to available fixed-point type. T is the type of the other operand,
4527 -- which is needed to determine the expected type of N.
4529 procedure Set_Operand_Type (N : Node_Id);
4530 -- Set operand type to T if universal
4532 -------------------------------
4533 -- Expected_Type_Is_Any_Real --
4534 -------------------------------
4536 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4538 -- N is the expression after "delta" in a fixed_point_definition;
4541 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4542 N_Decimal_Fixed_Point_Definition,
4544 -- N is one of the bounds in a real_range_specification;
4547 N_Real_Range_Specification,
4549 -- N is the expression of a delta_constraint;
4552 N_Delta_Constraint);
4553 end Expected_Type_Is_Any_Real;
4555 -----------------------------
4556 -- Is_Integer_Or_Universal --
4557 -----------------------------
4559 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4561 Index : Interp_Index;
4565 if not Is_Overloaded (N) then
4567 return Base_Type (T) = Base_Type (Standard_Integer)
4568 or else T = Universal_Integer
4569 or else T = Universal_Real;
4571 Get_First_Interp (N, Index, It);
4572 while Present (It.Typ) loop
4573 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4574 or else It.Typ = Universal_Integer
4575 or else It.Typ = Universal_Real
4580 Get_Next_Interp (Index, It);
4585 end Is_Integer_Or_Universal;
4587 ----------------------------
4588 -- Set_Mixed_Mode_Operand --
4589 ----------------------------
4591 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4592 Index : Interp_Index;
4596 if Universal_Interpretation (N) = Universal_Integer then
4598 -- A universal integer literal is resolved as standard integer
4599 -- except in the case of a fixed-point result, where we leave it
4600 -- as universal (to be handled by Exp_Fixd later on)
4602 if Is_Fixed_Point_Type (T) then
4603 Resolve (N, Universal_Integer);
4605 Resolve (N, Standard_Integer);
4608 elsif Universal_Interpretation (N) = Universal_Real
4609 and then (T = Base_Type (Standard_Integer)
4610 or else T = Universal_Integer
4611 or else T = Universal_Real)
4613 -- A universal real can appear in a fixed-type context. We resolve
4614 -- the literal with that context, even though this might raise an
4615 -- exception prematurely (the other operand may be zero).
4619 elsif Etype (N) = Base_Type (Standard_Integer)
4620 and then T = Universal_Real
4621 and then Is_Overloaded (N)
4623 -- Integer arg in mixed-mode operation. Resolve with universal
4624 -- type, in case preference rule must be applied.
4626 Resolve (N, Universal_Integer);
4629 and then B_Typ /= Universal_Fixed
4631 -- Not a mixed-mode operation, resolve with context
4635 elsif Etype (N) = Any_Fixed then
4637 -- N may itself be a mixed-mode operation, so use context type
4641 elsif Is_Fixed_Point_Type (T)
4642 and then B_Typ = Universal_Fixed
4643 and then Is_Overloaded (N)
4645 -- Must be (fixed * fixed) operation, operand must have one
4646 -- compatible interpretation.
4648 Resolve (N, Any_Fixed);
4650 elsif Is_Fixed_Point_Type (B_Typ)
4651 and then (T = Universal_Real
4652 or else Is_Fixed_Point_Type (T))
4653 and then Is_Overloaded (N)
4655 -- C * F(X) in a fixed context, where C is a real literal or a
4656 -- fixed-point expression. F must have either a fixed type
4657 -- interpretation or an integer interpretation, but not both.
4659 Get_First_Interp (N, Index, It);
4660 while Present (It.Typ) loop
4661 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
4669 if Analyzed (N) then
4670 Error_Msg_N ("ambiguous operand in fixed operation", N);
4672 Resolve (N, It.Typ);
4676 Get_Next_Interp (Index, It);
4679 -- Reanalyze the literal with the fixed type of the context. If
4680 -- context is Universal_Fixed, we are within a conversion, leave
4681 -- the literal as a universal real because there is no usable
4682 -- fixed type, and the target of the conversion plays no role in
4696 if B_Typ = Universal_Fixed
4697 and then Nkind (Op2) = N_Real_Literal
4699 T2 := Universal_Real;
4704 Set_Analyzed (Op2, False);
4711 end Set_Mixed_Mode_Operand;
4713 ----------------------
4714 -- Set_Operand_Type --
4715 ----------------------
4717 procedure Set_Operand_Type (N : Node_Id) is
4719 if Etype (N) = Universal_Integer
4720 or else Etype (N) = Universal_Real
4724 end Set_Operand_Type;
4726 -- Start of processing for Resolve_Arithmetic_Op
4729 if Comes_From_Source (N)
4730 and then Ekind (Entity (N)) = E_Function
4731 and then Is_Imported (Entity (N))
4732 and then Is_Intrinsic_Subprogram (Entity (N))
4734 Resolve_Intrinsic_Operator (N, Typ);
4737 -- Special-case for mixed-mode universal expressions or fixed point type
4738 -- operation: each argument is resolved separately. The same treatment
4739 -- is required if one of the operands of a fixed point operation is
4740 -- universal real, since in this case we don't do a conversion to a
4741 -- specific fixed-point type (instead the expander handles the case).
4743 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4744 and then Present (Universal_Interpretation (L))
4745 and then Present (Universal_Interpretation (R))
4747 Resolve (L, Universal_Interpretation (L));
4748 Resolve (R, Universal_Interpretation (R));
4749 Set_Etype (N, B_Typ);
4751 elsif (B_Typ = Universal_Real
4752 or else Etype (N) = Universal_Fixed
4753 or else (Etype (N) = Any_Fixed
4754 and then Is_Fixed_Point_Type (B_Typ))
4755 or else (Is_Fixed_Point_Type (B_Typ)
4756 and then (Is_Integer_Or_Universal (L)
4758 Is_Integer_Or_Universal (R))))
4759 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4761 if TL = Universal_Integer or else TR = Universal_Integer then
4762 Check_For_Visible_Operator (N, B_Typ);
4765 -- If context is a fixed type and one operand is integer, the other
4766 -- is resolved with the type of the context.
4768 if Is_Fixed_Point_Type (B_Typ)
4769 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4770 or else TL = Universal_Integer)
4775 elsif Is_Fixed_Point_Type (B_Typ)
4776 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4777 or else TR = Universal_Integer)
4783 Set_Mixed_Mode_Operand (L, TR);
4784 Set_Mixed_Mode_Operand (R, TL);
4787 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4788 -- multiplying operators from being used when the expected type is
4789 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4790 -- some cases where the expected type is actually Any_Real;
4791 -- Expected_Type_Is_Any_Real takes care of that case.
4793 if Etype (N) = Universal_Fixed
4794 or else Etype (N) = Any_Fixed
4796 if B_Typ = Universal_Fixed
4797 and then not Expected_Type_Is_Any_Real (N)
4798 and then not Nkind_In (Parent (N), N_Type_Conversion,
4799 N_Unchecked_Type_Conversion)
4801 Error_Msg_N ("type cannot be determined from context!", N);
4802 Error_Msg_N ("\explicit conversion to result type required", N);
4804 Set_Etype (L, Any_Type);
4805 Set_Etype (R, Any_Type);
4808 if Ada_Version = Ada_83
4809 and then Etype (N) = Universal_Fixed
4811 Nkind_In (Parent (N), N_Type_Conversion,
4812 N_Unchecked_Type_Conversion)
4815 ("(Ada 83) fixed-point operation "
4816 & "needs explicit conversion", N);
4819 -- The expected type is "any real type" in contexts like
4821 -- 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 is
4844 -- 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, a multiplication or division with operands of fixed point
4891 -- types shall be qualified or explicitly converted to identify the
4894 if (Is_Fixed_Point_Type (Etype (L))
4895 or else Is_Fixed_Point_Type (Etype (R)))
4896 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4898 not Nkind_In (Parent (N), N_Qualified_Expression, N_Type_Conversion)
4900 Check_SPARK_Restriction
4901 ("operation should be qualified or explicitly converted", N);
4904 -- Set overflow and division checking bit. Much cleverer code needed
4905 -- here eventually and perhaps the Resolve routines should be separated
4906 -- for the various arithmetic operations, since they will need
4907 -- different processing. ???
4909 if Nkind (N) in N_Op then
4910 if not Overflow_Checks_Suppressed (Etype (N)) then
4911 Enable_Overflow_Check (N);
4914 -- Give warning if explicit division by zero
4916 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4917 and then not Division_Checks_Suppressed (Etype (N))
4919 Rop := Right_Opnd (N);
4921 if Compile_Time_Known_Value (Rop)
4922 and then ((Is_Integer_Type (Etype (Rop))
4923 and then Expr_Value (Rop) = Uint_0)
4925 (Is_Real_Type (Etype (Rop))
4926 and then Expr_Value_R (Rop) = Ureal_0))
4928 -- Specialize the warning message according to the operation
4932 Apply_Compile_Time_Constraint_Error
4933 (N, "division by zero?", CE_Divide_By_Zero,
4934 Loc => Sloc (Right_Opnd (N)));
4937 Apply_Compile_Time_Constraint_Error
4938 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4939 Loc => Sloc (Right_Opnd (N)));
4942 Apply_Compile_Time_Constraint_Error
4943 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4944 Loc => Sloc (Right_Opnd (N)));
4946 -- Division by zero can only happen with division, rem,
4947 -- and mod operations.
4950 raise Program_Error;
4953 -- Otherwise just set the flag to check at run time
4956 Activate_Division_Check (N);
4960 -- If Restriction No_Implicit_Conditionals is active, then it is
4961 -- violated if either operand can be negative for mod, or for rem
4962 -- if both operands can be negative.
4964 if Restriction_Check_Required (No_Implicit_Conditionals)
4965 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4974 -- Set if corresponding operand might be negative
4978 (Left_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4979 LNeg := (not OK) or else Lo < 0;
4982 (Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4983 RNeg := (not OK) or else Lo < 0;
4985 -- Check if we will be generating conditionals. There are two
4986 -- cases where that can happen, first for REM, the only case
4987 -- is largest negative integer mod -1, where the division can
4988 -- overflow, but we still have to give the right result. The
4989 -- front end generates a test for this annoying case. Here we
4990 -- just test if both operands can be negative (that's what the
4991 -- expander does, so we match its logic here).
4993 -- The second case is mod where either operand can be negative.
4994 -- In this case, the back end has to generate additional tests.
4996 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4998 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
5000 Check_Restriction (No_Implicit_Conditionals, N);
5006 Check_Unset_Reference (L);
5007 Check_Unset_Reference (R);
5008 end Resolve_Arithmetic_Op;
5014 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
5015 Loc : constant Source_Ptr := Sloc (N);
5016 Subp : constant Node_Id := Name (N);
5024 function Same_Or_Aliased_Subprograms
5026 E : Entity_Id) return Boolean;
5027 -- Returns True if the subprogram entity S is the same as E or else
5028 -- S is an alias of E.
5030 ---------------------------------
5031 -- Same_Or_Aliased_Subprograms --
5032 ---------------------------------
5034 function Same_Or_Aliased_Subprograms
5036 E : Entity_Id) return Boolean
5038 Subp_Alias : constant Entity_Id := Alias (S);
5041 or else (Present (Subp_Alias) and then Subp_Alias = E);
5042 end Same_Or_Aliased_Subprograms;
5044 -- Start of processing for Resolve_Call
5047 -- The context imposes a unique interpretation with type Typ on a
5048 -- procedure or function call. Find the entity of the subprogram that
5049 -- yields the expected type, and propagate the corresponding formal
5050 -- constraints on the actuals. The caller has established that an
5051 -- interpretation exists, and emitted an error if not unique.
5053 -- First deal with the case of a call to an access-to-subprogram,
5054 -- dereference made explicit in Analyze_Call.
5056 if Ekind (Etype (Subp)) = E_Subprogram_Type then
5057 if not Is_Overloaded (Subp) then
5058 Nam := Etype (Subp);
5061 -- Find the interpretation whose type (a subprogram type) has a
5062 -- return type that is compatible with the context. Analysis of
5063 -- the node has established that one exists.
5067 Get_First_Interp (Subp, I, It);
5068 while Present (It.Typ) loop
5069 if Covers (Typ, Etype (It.Typ)) then
5074 Get_Next_Interp (I, It);
5078 raise Program_Error;
5082 -- If the prefix is not an entity, then resolve it
5084 if not Is_Entity_Name (Subp) then
5085 Resolve (Subp, Nam);
5088 -- For an indirect call, we always invalidate checks, since we do not
5089 -- know whether the subprogram is local or global. Yes we could do
5090 -- better here, e.g. by knowing that there are no local subprograms,
5091 -- but it does not seem worth the effort. Similarly, we kill all
5092 -- knowledge of current constant values.
5094 Kill_Current_Values;
5096 -- If this is a procedure call which is really an entry call, do
5097 -- the conversion of the procedure call to an entry call. Protected
5098 -- operations use the same circuitry because the name in the call
5099 -- can be an arbitrary expression with special resolution rules.
5101 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
5102 or else (Is_Entity_Name (Subp)
5103 and then Ekind (Entity (Subp)) = E_Entry)
5105 Resolve_Entry_Call (N, Typ);
5106 Check_Elab_Call (N);
5108 -- Kill checks and constant values, as above for indirect case
5109 -- Who knows what happens when another task is activated?
5111 Kill_Current_Values;
5114 -- Normal subprogram call with name established in Resolve
5116 elsif not (Is_Type (Entity (Subp))) then
5117 Nam := Entity (Subp);
5118 Set_Entity_With_Style_Check (Subp, Nam);
5120 -- Otherwise we must have the case of an overloaded call
5123 pragma Assert (Is_Overloaded (Subp));
5125 -- Initialize Nam to prevent warning (we know it will be assigned
5126 -- in the loop below, but the compiler does not know that).
5130 Get_First_Interp (Subp, I, It);
5131 while Present (It.Typ) loop
5132 if Covers (Typ, It.Typ) then
5134 Set_Entity_With_Style_Check (Subp, Nam);
5138 Get_Next_Interp (I, It);
5142 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
5143 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
5144 and then Nkind (Subp) /= N_Explicit_Dereference
5145 and then Present (Parameter_Associations (N))
5147 -- The prefix is a parameterless function call that returns an access
5148 -- to subprogram. If parameters are present in the current call, add
5149 -- add an explicit dereference. We use the base type here because
5150 -- within an instance these may be subtypes.
5152 -- The dereference is added either in Analyze_Call or here. Should
5153 -- be consolidated ???
5155 Set_Is_Overloaded (Subp, False);
5156 Set_Etype (Subp, Etype (Nam));
5157 Insert_Explicit_Dereference (Subp);
5158 Nam := Designated_Type (Etype (Nam));
5159 Resolve (Subp, Nam);
5162 -- Check that a call to Current_Task does not occur in an entry body
5164 if Is_RTE (Nam, RE_Current_Task) then
5173 -- Exclude calls that occur within the default of a formal
5174 -- parameter of the entry, since those are evaluated outside
5177 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
5179 if Nkind (P) = N_Entry_Body
5180 or else (Nkind (P) = N_Subprogram_Body
5181 and then Is_Entry_Barrier_Function (P))
5185 ("?& should not be used in entry body (RM C.7(17))",
5188 ("\Program_Error will be raised at run time?", N, Nam);
5190 Make_Raise_Program_Error (Loc,
5191 Reason => PE_Current_Task_In_Entry_Body));
5192 Set_Etype (N, Rtype);
5199 -- Check that a procedure call does not occur in the context of the
5200 -- entry call statement of a conditional or timed entry call. Note that
5201 -- the case of a call to a subprogram renaming of an entry will also be
5202 -- rejected. The test for N not being an N_Entry_Call_Statement is
5203 -- defensive, covering the possibility that the processing of entry
5204 -- calls might reach this point due to later modifications of the code
5207 if Nkind (Parent (N)) = N_Entry_Call_Alternative
5208 and then Nkind (N) /= N_Entry_Call_Statement
5209 and then Entry_Call_Statement (Parent (N)) = N
5211 if Ada_Version < Ada_2005 then
5212 Error_Msg_N ("entry call required in select statement", N);
5214 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5215 -- for a procedure_or_entry_call, the procedure_name or
5216 -- procedure_prefix of the procedure_call_statement shall denote
5217 -- an entry renamed by a procedure, or (a view of) a primitive
5218 -- subprogram of a limited interface whose first parameter is
5219 -- a controlling parameter.
5221 elsif Nkind (N) = N_Procedure_Call_Statement
5222 and then not Is_Renamed_Entry (Nam)
5223 and then not Is_Controlling_Limited_Procedure (Nam)
5226 ("entry call or dispatching primitive of interface required", N);
5230 -- Check that this is not a call to a protected procedure or entry from
5231 -- within a protected function.
5233 if Ekind (Current_Scope) = E_Function
5234 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
5235 and then Ekind (Nam) /= E_Function
5236 and then Scope (Nam) = Scope (Current_Scope)
5238 Error_Msg_N ("within protected function, protected " &
5239 "object is constant", N);
5240 Error_Msg_N ("\cannot call operation that may modify it", N);
5243 -- Freeze the subprogram name if not in a spec-expression. Note that we
5244 -- freeze procedure calls as well as function calls. Procedure calls are
5245 -- not frozen according to the rules (RM 13.14(14)) because it is
5246 -- impossible to have a procedure call to a non-frozen procedure in pure
5247 -- Ada, but in the code that we generate in the expander, this rule
5248 -- needs extending because we can generate procedure calls that need
5251 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
5252 Freeze_Expression (Subp);
5255 -- For a predefined operator, the type of the result is the type imposed
5256 -- by context, except for a predefined operation on universal fixed.
5257 -- Otherwise The type of the call is the type returned by the subprogram
5260 if Is_Predefined_Op (Nam) then
5261 if Etype (N) /= Universal_Fixed then
5265 -- If the subprogram returns an array type, and the context requires the
5266 -- component type of that array type, the node is really an indexing of
5267 -- the parameterless call. Resolve as such. A pathological case occurs
5268 -- when the type of the component is an access to the array type. In
5269 -- this case the call is truly ambiguous.
5271 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
5273 ((Is_Array_Type (Etype (Nam))
5274 and then Covers (Typ, Component_Type (Etype (Nam))))
5275 or else (Is_Access_Type (Etype (Nam))
5276 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 Restriction_Check_Required (No_Specific_Termination_Handlers)
5706 and then (Is_RTE (Nam, RE_Set_Specific_Handler)
5708 Is_RTE (Nam, RE_Specific_Handler))
5710 Check_Restriction (No_Specific_Termination_Handlers, N);
5712 elsif Is_RTE (Nam, RE_Abort_Task) then
5713 Check_Potentially_Blocking_Operation (N);
5716 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
5717 -- timing event violates restriction No_Relative_Delay (AI-0211). We
5718 -- need to check the second argument to determine whether it is an
5719 -- absolute or relative timing event.
5721 if Restriction_Check_Required (No_Relative_Delay)
5722 and then Is_RTE (Nam, RE_Set_Handler)
5723 and then Is_RTE (Etype (Next_Actual (First_Actual (N))), RE_Time_Span)
5725 Check_Restriction (No_Relative_Delay, N);
5728 -- Issue an error for a call to an eliminated subprogram. We skip this
5729 -- in a spec expression, e.g. a call in a default parameter value, since
5730 -- we are not really doing a call at this time. That's important because
5731 -- the spec expression may itself belong to an eliminated subprogram.
5733 if not In_Spec_Expression then
5734 Check_For_Eliminated_Subprogram (Subp, Nam);
5737 -- In formal mode, the primitive operations of a tagged type or type
5738 -- extension do not include functions that return the tagged type.
5740 -- Commented out as the call to Is_Inherited_Operation_For_Type may
5741 -- cause an error because the type entity of the parent node of
5742 -- Entity (Name (N) may not be set. ???
5743 -- So why not just add a guard ???
5745 -- if Nkind (N) = N_Function_Call
5746 -- and then Is_Tagged_Type (Etype (N))
5747 -- and then Is_Entity_Name (Name (N))
5748 -- and then Is_Inherited_Operation_For_Type
5749 -- (Entity (Name (N)), Etype (N))
5751 -- Check_SPARK_Restriction ("function not inherited", N);
5754 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
5755 -- class-wide and the call dispatches on result in a context that does
5756 -- not provide a tag, the call raises Program_Error.
5758 if Nkind (N) = N_Function_Call
5759 and then In_Instance
5760 and then Is_Generic_Actual_Type (Typ)
5761 and then Is_Class_Wide_Type (Typ)
5762 and then Has_Controlling_Result (Nam)
5763 and then Nkind (Parent (N)) = N_Object_Declaration
5765 -- Verify that none of the formals are controlling
5768 Call_OK : Boolean := False;
5772 F := First_Formal (Nam);
5773 while Present (F) loop
5774 if Is_Controlling_Formal (F) then
5783 Error_Msg_N ("!? cannot determine tag of result", N);
5784 Error_Msg_N ("!? Program_Error will be raised", N);
5786 Make_Raise_Program_Error (Sloc (N),
5787 Reason => PE_Explicit_Raise));
5792 -- All done, evaluate call and deal with elaboration issues
5795 Check_Elab_Call (N);
5796 Warn_On_Overlapping_Actuals (Nam, N);
5799 -----------------------------
5800 -- Resolve_Case_Expression --
5801 -----------------------------
5803 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id) is
5807 Alt := First (Alternatives (N));
5808 while Present (Alt) loop
5809 Resolve (Expression (Alt), Typ);
5814 Eval_Case_Expression (N);
5815 end Resolve_Case_Expression;
5817 -------------------------------
5818 -- Resolve_Character_Literal --
5819 -------------------------------
5821 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5822 B_Typ : constant Entity_Id := Base_Type (Typ);
5826 -- Verify that the character does belong to the type of the context
5828 Set_Etype (N, B_Typ);
5829 Eval_Character_Literal (N);
5831 -- Wide_Wide_Character literals must always be defined, since the set
5832 -- of wide wide character literals is complete, i.e. if a character
5833 -- literal is accepted by the parser, then it is OK for wide wide
5834 -- character (out of range character literals are rejected).
5836 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5839 -- Always accept character literal for type Any_Character, which
5840 -- occurs in error situations and in comparisons of literals, both
5841 -- of which should accept all literals.
5843 elsif B_Typ = Any_Character then
5846 -- For Standard.Character or a type derived from it, check that the
5847 -- literal is in range.
5849 elsif Root_Type (B_Typ) = Standard_Character then
5850 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5854 -- For Standard.Wide_Character or a type derived from it, check that the
5855 -- literal is in range.
5857 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5858 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5862 -- For Standard.Wide_Wide_Character or a type derived from it, we
5863 -- know the literal is in range, since the parser checked!
5865 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5868 -- If the entity is already set, this has already been resolved in a
5869 -- generic context, or comes from expansion. Nothing else to do.
5871 elsif Present (Entity (N)) then
5874 -- Otherwise we have a user defined character type, and we can use the
5875 -- standard visibility mechanisms to locate the referenced entity.
5878 C := Current_Entity (N);
5879 while Present (C) loop
5880 if Etype (C) = B_Typ then
5881 Set_Entity_With_Style_Check (N, C);
5882 Generate_Reference (C, N);
5890 -- If we fall through, then the literal does not match any of the
5891 -- entries of the enumeration type. This isn't just a constraint error
5892 -- situation, it is an illegality (see RM 4.2).
5895 ("character not defined for }", N, First_Subtype (B_Typ));
5896 end Resolve_Character_Literal;
5898 ---------------------------
5899 -- Resolve_Comparison_Op --
5900 ---------------------------
5902 -- Context requires a boolean type, and plays no role in resolution.
5903 -- Processing identical to that for equality operators. The result type is
5904 -- the base type, which matters when pathological subtypes of booleans with
5905 -- limited ranges are used.
5907 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5908 L : constant Node_Id := Left_Opnd (N);
5909 R : constant Node_Id := Right_Opnd (N);
5913 -- If this is an intrinsic operation which is not predefined, use the
5914 -- types of its declared arguments to resolve the possibly overloaded
5915 -- operands. Otherwise the operands are unambiguous and specify the
5918 if Scope (Entity (N)) /= Standard_Standard then
5919 T := Etype (First_Entity (Entity (N)));
5922 T := Find_Unique_Type (L, R);
5924 if T = Any_Fixed then
5925 T := Unique_Fixed_Point_Type (L);
5929 Set_Etype (N, Base_Type (Typ));
5930 Generate_Reference (T, N, ' ');
5932 -- Skip remaining processing if already set to Any_Type
5934 if T = Any_Type then
5938 -- Deal with other error cases
5940 if T = Any_String or else
5941 T = Any_Composite or else
5944 if T = Any_Character then
5945 Ambiguous_Character (L);
5947 Error_Msg_N ("ambiguous operands for comparison", N);
5950 Set_Etype (N, Any_Type);
5954 -- Resolve the operands if types OK
5958 Check_Unset_Reference (L);
5959 Check_Unset_Reference (R);
5960 Generate_Operator_Reference (N, T);
5961 Check_Low_Bound_Tested (N);
5963 -- In SPARK, ordering operators <, <=, >, >= are not defined for Boolean
5964 -- types or array types except String.
5966 if Is_Boolean_Type (T) then
5967 Mark_Non_ALFA_Subprogram;
5968 Check_SPARK_Restriction
5969 ("comparison is not defined on Boolean type", N);
5971 elsif Is_Array_Type (T) then
5972 Mark_Non_ALFA_Subprogram;
5974 if Base_Type (T) /= Standard_String then
5975 Check_SPARK_Restriction
5976 ("comparison is not defined on array types other than String",
5984 -- Check comparison on unordered enumeration
5986 if Comes_From_Source (N)
5987 and then Bad_Unordered_Enumeration_Reference (N, Etype (L))
5989 Error_Msg_N ("comparison on unordered enumeration type?", N);
5992 -- Evaluate the relation (note we do this after the above check since
5993 -- this Eval call may change N to True/False.
5995 Eval_Relational_Op (N);
5996 end Resolve_Comparison_Op;
5998 ------------------------------------
5999 -- Resolve_Conditional_Expression --
6000 ------------------------------------
6002 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
6003 Condition : constant Node_Id := First (Expressions (N));
6004 Then_Expr : constant Node_Id := Next (Condition);
6005 Else_Expr : Node_Id := Next (Then_Expr);
6008 Resolve (Condition, Any_Boolean);
6009 Resolve (Then_Expr, Typ);
6011 -- If ELSE expression present, just resolve using the determined type
6013 if Present (Else_Expr) then
6014 Resolve (Else_Expr, Typ);
6016 -- If no ELSE expression is present, root type must be Standard.Boolean
6017 -- and we provide a Standard.True result converted to the appropriate
6018 -- Boolean type (in case it is a derived boolean type).
6020 elsif Root_Type (Typ) = Standard_Boolean then
6022 Convert_To (Typ, New_Occurrence_Of (Standard_True, Sloc (N)));
6023 Analyze_And_Resolve (Else_Expr, Typ);
6024 Append_To (Expressions (N), Else_Expr);
6027 Error_Msg_N ("can only omit ELSE expression in Boolean case", N);
6028 Append_To (Expressions (N), Error);
6032 Eval_Conditional_Expression (N);
6033 end Resolve_Conditional_Expression;
6035 -----------------------------------------
6036 -- Resolve_Discrete_Subtype_Indication --
6037 -----------------------------------------
6039 procedure Resolve_Discrete_Subtype_Indication
6047 Analyze (Subtype_Mark (N));
6048 S := Entity (Subtype_Mark (N));
6050 if Nkind (Constraint (N)) /= N_Range_Constraint then
6051 Error_Msg_N ("expect range constraint for discrete type", N);
6052 Set_Etype (N, Any_Type);
6055 R := Range_Expression (Constraint (N));
6063 if Base_Type (S) /= Base_Type (Typ) then
6065 ("expect subtype of }", N, First_Subtype (Typ));
6067 -- Rewrite the constraint as a range of Typ
6068 -- to allow compilation to proceed further.
6071 Rewrite (Low_Bound (R),
6072 Make_Attribute_Reference (Sloc (Low_Bound (R)),
6073 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
6074 Attribute_Name => Name_First));
6075 Rewrite (High_Bound (R),
6076 Make_Attribute_Reference (Sloc (High_Bound (R)),
6077 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
6078 Attribute_Name => Name_First));
6082 Set_Etype (N, Etype (R));
6084 -- Additionally, we must check that the bounds are compatible
6085 -- with the given subtype, which might be different from the
6086 -- type of the context.
6088 Apply_Range_Check (R, S);
6090 -- ??? If the above check statically detects a Constraint_Error
6091 -- it replaces the offending bound(s) of the range R with a
6092 -- Constraint_Error node. When the itype which uses these bounds
6093 -- is frozen the resulting call to Duplicate_Subexpr generates
6094 -- a new temporary for the bounds.
6096 -- Unfortunately there are other itypes that are also made depend
6097 -- on these bounds, so when Duplicate_Subexpr is called they get
6098 -- a forward reference to the newly created temporaries and Gigi
6099 -- aborts on such forward references. This is probably sign of a
6100 -- more fundamental problem somewhere else in either the order of
6101 -- itype freezing or the way certain itypes are constructed.
6103 -- To get around this problem we call Remove_Side_Effects right
6104 -- away if either bounds of R are a Constraint_Error.
6107 L : constant Node_Id := Low_Bound (R);
6108 H : constant Node_Id := High_Bound (R);
6111 if Nkind (L) = N_Raise_Constraint_Error then
6112 Remove_Side_Effects (L);
6115 if Nkind (H) = N_Raise_Constraint_Error then
6116 Remove_Side_Effects (H);
6120 Check_Unset_Reference (Low_Bound (R));
6121 Check_Unset_Reference (High_Bound (R));
6124 end Resolve_Discrete_Subtype_Indication;
6126 -------------------------
6127 -- Resolve_Entity_Name --
6128 -------------------------
6130 -- Used to resolve identifiers and expanded names
6132 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
6133 E : constant Entity_Id := Entity (N);
6136 -- If garbage from errors, set to Any_Type and return
6138 if No (E) and then Total_Errors_Detected /= 0 then
6139 Set_Etype (N, Any_Type);
6143 -- Replace named numbers by corresponding literals. Note that this is
6144 -- the one case where Resolve_Entity_Name must reset the Etype, since
6145 -- it is currently marked as universal.
6147 if Ekind (E) = E_Named_Integer then
6149 Eval_Named_Integer (N);
6151 elsif Ekind (E) = E_Named_Real then
6153 Eval_Named_Real (N);
6155 -- For enumeration literals, we need to make sure that a proper style
6156 -- check is done, since such literals are overloaded, and thus we did
6157 -- not do a style check during the first phase of analysis.
6159 elsif Ekind (E) = E_Enumeration_Literal then
6160 Set_Entity_With_Style_Check (N, E);
6161 Eval_Entity_Name (N);
6163 -- Case of subtype name appearing as an operand in expression
6165 elsif Is_Type (E) then
6167 -- Allow use of subtype if it is a concurrent type where we are
6168 -- currently inside the body. This will eventually be expanded into a
6169 -- call to Self (for tasks) or _object (for protected objects). Any
6170 -- other use of a subtype is invalid.
6172 if Is_Concurrent_Type (E)
6173 and then In_Open_Scopes (E)
6177 -- Any other use is an error
6181 ("invalid use of subtype mark in expression or call", N);
6184 -- Check discriminant use if entity is discriminant in current scope,
6185 -- i.e. discriminant of record or concurrent type currently being
6186 -- analyzed. Uses in corresponding body are unrestricted.
6188 elsif Ekind (E) = E_Discriminant
6189 and then Scope (E) = Current_Scope
6190 and then not Has_Completion (Current_Scope)
6192 Check_Discriminant_Use (N);
6194 -- A parameterless generic function cannot appear in a context that
6195 -- requires resolution.
6197 elsif Ekind (E) = E_Generic_Function then
6198 Error_Msg_N ("illegal use of generic function", N);
6200 elsif Ekind (E) = E_Out_Parameter
6201 and then Ada_Version = Ada_83
6202 and then (Nkind (Parent (N)) in N_Op
6203 or else (Nkind (Parent (N)) = N_Assignment_Statement
6204 and then N = Expression (Parent (N)))
6205 or else Nkind (Parent (N)) = N_Explicit_Dereference)
6207 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
6209 -- In all other cases, just do the possible static evaluation
6212 -- A deferred constant that appears in an expression must have a
6213 -- completion, unless it has been removed by in-place expansion of
6216 if Ekind (E) = E_Constant
6217 and then Comes_From_Source (E)
6218 and then No (Constant_Value (E))
6219 and then Is_Frozen (Etype (E))
6220 and then not In_Spec_Expression
6221 and then not Is_Imported (E)
6223 if No_Initialization (Parent (E))
6224 or else (Present (Full_View (E))
6225 and then No_Initialization (Parent (Full_View (E))))
6230 "deferred constant is frozen before completion", N);
6234 Eval_Entity_Name (N);
6236 end Resolve_Entity_Name;
6242 procedure Resolve_Entry (Entry_Name : Node_Id) is
6243 Loc : constant Source_Ptr := Sloc (Entry_Name);
6251 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
6252 -- If the bounds of the entry family being called depend on task
6253 -- discriminants, build a new index subtype where a discriminant is
6254 -- replaced with the value of the discriminant of the target task.
6255 -- The target task is the prefix of the entry name in the call.
6257 -----------------------
6258 -- Actual_Index_Type --
6259 -----------------------
6261 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
6262 Typ : constant Entity_Id := Entry_Index_Type (E);
6263 Tsk : constant Entity_Id := Scope (E);
6264 Lo : constant Node_Id := Type_Low_Bound (Typ);
6265 Hi : constant Node_Id := Type_High_Bound (Typ);
6268 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
6269 -- If the bound is given by a discriminant, replace with a reference
6270 -- to the discriminant of the same name in the target task. If the
6271 -- entry name is the target of a requeue statement and the entry is
6272 -- in the current protected object, the bound to be used is the
6273 -- discriminal of the object (see Apply_Range_Checks for details of
6274 -- the transformation).
6276 -----------------------------
6277 -- Actual_Discriminant_Ref --
6278 -----------------------------
6280 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
6281 Typ : constant Entity_Id := Etype (Bound);
6285 Remove_Side_Effects (Bound);
6287 if not Is_Entity_Name (Bound)
6288 or else Ekind (Entity (Bound)) /= E_Discriminant
6292 elsif Is_Protected_Type (Tsk)
6293 and then In_Open_Scopes (Tsk)
6294 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
6296 -- Note: here Bound denotes a discriminant of the corresponding
6297 -- record type tskV, whose discriminal is a formal of the
6298 -- init-proc tskVIP. What we want is the body discriminal,
6299 -- which is associated to the discriminant of the original
6300 -- concurrent type tsk.
6302 return New_Occurrence_Of
6303 (Find_Body_Discriminal (Entity (Bound)), Loc);
6307 Make_Selected_Component (Loc,
6308 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
6309 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
6314 end Actual_Discriminant_Ref;
6316 -- Start of processing for Actual_Index_Type
6319 if not Has_Discriminants (Tsk)
6320 or else (not Is_Entity_Name (Lo) and then not Is_Entity_Name (Hi))
6322 return Entry_Index_Type (E);
6325 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
6326 Set_Etype (New_T, Base_Type (Typ));
6327 Set_Size_Info (New_T, Typ);
6328 Set_RM_Size (New_T, RM_Size (Typ));
6329 Set_Scalar_Range (New_T,
6330 Make_Range (Sloc (Entry_Name),
6331 Low_Bound => Actual_Discriminant_Ref (Lo),
6332 High_Bound => Actual_Discriminant_Ref (Hi)));
6336 end Actual_Index_Type;
6338 -- Start of processing of Resolve_Entry
6341 -- Find name of entry being called, and resolve prefix of name with its
6342 -- own type. The prefix can be overloaded, and the name and signature of
6343 -- the entry must be taken into account.
6345 if Nkind (Entry_Name) = N_Indexed_Component then
6347 -- Case of dealing with entry family within the current tasks
6349 E_Name := Prefix (Entry_Name);
6352 E_Name := Entry_Name;
6355 if Is_Entity_Name (E_Name) then
6357 -- Entry call to an entry (or entry family) in the current task. This
6358 -- is legal even though the task will deadlock. Rewrite as call to
6361 -- This can also be a call to an entry in an enclosing task. If this
6362 -- is a single task, we have to retrieve its name, because the scope
6363 -- of the entry is the task type, not the object. If the enclosing
6364 -- task is a task type, the identity of the task is given by its own
6367 -- Finally this can be a requeue on an entry of the same task or
6368 -- protected object.
6370 S := Scope (Entity (E_Name));
6372 for J in reverse 0 .. Scope_Stack.Last loop
6373 if Is_Task_Type (Scope_Stack.Table (J).Entity)
6374 and then not Comes_From_Source (S)
6376 -- S is an enclosing task or protected object. The concurrent
6377 -- declaration has been converted into a type declaration, and
6378 -- the object itself has an object declaration that follows
6379 -- the type in the same declarative part.
6381 Tsk := Next_Entity (S);
6382 while Etype (Tsk) /= S loop
6389 elsif S = Scope_Stack.Table (J).Entity then
6391 -- Call to current task. Will be transformed into call to Self
6399 Make_Selected_Component (Loc,
6400 Prefix => New_Occurrence_Of (S, Loc),
6402 New_Occurrence_Of (Entity (E_Name), Loc));
6403 Rewrite (E_Name, New_N);
6406 elsif Nkind (Entry_Name) = N_Selected_Component
6407 and then Is_Overloaded (Prefix (Entry_Name))
6409 -- Use the entry name (which must be unique at this point) to find
6410 -- the prefix that returns the corresponding task/protected type.
6413 Pref : constant Node_Id := Prefix (Entry_Name);
6414 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
6419 Get_First_Interp (Pref, I, It);
6420 while Present (It.Typ) loop
6421 if Scope (Ent) = It.Typ then
6422 Set_Etype (Pref, It.Typ);
6426 Get_Next_Interp (I, It);
6431 if Nkind (Entry_Name) = N_Selected_Component then
6432 Resolve (Prefix (Entry_Name));
6434 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6435 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6436 Resolve (Prefix (Prefix (Entry_Name)));
6437 Index := First (Expressions (Entry_Name));
6438 Resolve (Index, Entry_Index_Type (Nam));
6440 -- Up to this point the expression could have been the actual in a
6441 -- simple entry call, and be given by a named association.
6443 if Nkind (Index) = N_Parameter_Association then
6444 Error_Msg_N ("expect expression for entry index", Index);
6446 Apply_Range_Check (Index, Actual_Index_Type (Nam));
6451 ------------------------
6452 -- Resolve_Entry_Call --
6453 ------------------------
6455 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
6456 Entry_Name : constant Node_Id := Name (N);
6457 Loc : constant Source_Ptr := Sloc (Entry_Name);
6459 First_Named : Node_Id;
6466 -- We kill all checks here, because it does not seem worth the effort to
6467 -- do anything better, an entry call is a big operation.
6471 -- Processing of the name is similar for entry calls and protected
6472 -- operation calls. Once the entity is determined, we can complete
6473 -- the resolution of the actuals.
6475 -- The selector may be overloaded, in the case of a protected object
6476 -- with overloaded functions. The type of the context is used for
6479 if Nkind (Entry_Name) = N_Selected_Component
6480 and then Is_Overloaded (Selector_Name (Entry_Name))
6481 and then Typ /= Standard_Void_Type
6488 Get_First_Interp (Selector_Name (Entry_Name), I, It);
6489 while Present (It.Typ) loop
6490 if Covers (Typ, It.Typ) then
6491 Set_Entity (Selector_Name (Entry_Name), It.Nam);
6492 Set_Etype (Entry_Name, It.Typ);
6494 Generate_Reference (It.Typ, N, ' ');
6497 Get_Next_Interp (I, It);
6502 Resolve_Entry (Entry_Name);
6504 if Nkind (Entry_Name) = N_Selected_Component then
6506 -- Simple entry call
6508 Nam := Entity (Selector_Name (Entry_Name));
6509 Obj := Prefix (Entry_Name);
6510 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
6512 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6514 -- Call to member of entry family
6516 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6517 Obj := Prefix (Prefix (Entry_Name));
6518 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
6521 -- We cannot in general check the maximum depth of protected entry calls
6522 -- at compile time. But we can tell that any protected entry call at all
6523 -- violates a specified nesting depth of zero.
6525 if Is_Protected_Type (Scope (Nam)) then
6526 Check_Restriction (Max_Entry_Queue_Length, N);
6529 -- Use context type to disambiguate a protected function that can be
6530 -- called without actuals and that returns an array type, and where the
6531 -- argument list may be an indexing of the returned value.
6533 if Ekind (Nam) = E_Function
6534 and then Needs_No_Actuals (Nam)
6535 and then Present (Parameter_Associations (N))
6537 ((Is_Array_Type (Etype (Nam))
6538 and then Covers (Typ, Component_Type (Etype (Nam))))
6540 or else (Is_Access_Type (Etype (Nam))
6541 and then Is_Array_Type (Designated_Type (Etype (Nam)))
6545 Component_Type (Designated_Type (Etype (Nam))))))
6548 Index_Node : Node_Id;
6552 Make_Indexed_Component (Loc,
6554 Make_Function_Call (Loc, Name => Relocate_Node (Entry_Name)),
6555 Expressions => Parameter_Associations (N));
6557 -- Since we are correcting a node classification error made by the
6558 -- parser, we call Replace rather than Rewrite.
6560 Replace (N, Index_Node);
6561 Set_Etype (Prefix (N), Etype (Nam));
6563 Resolve_Indexed_Component (N, Typ);
6568 if Ekind_In (Nam, E_Entry, E_Entry_Family)
6569 and then Present (PPC_Wrapper (Nam))
6570 and then Current_Scope /= PPC_Wrapper (Nam)
6572 -- Rewrite as call to the precondition wrapper, adding the task
6573 -- object to the list of actuals. If the call is to a member of an
6574 -- entry family, include the index as well.
6578 New_Actuals : List_Id;
6581 New_Actuals := New_List (Obj);
6583 if Nkind (Entry_Name) = N_Indexed_Component then
6584 Append_To (New_Actuals,
6585 New_Copy_Tree (First (Expressions (Entry_Name))));
6588 Append_List (Parameter_Associations (N), New_Actuals);
6590 Make_Procedure_Call_Statement (Loc,
6592 New_Occurrence_Of (PPC_Wrapper (Nam), Loc),
6593 Parameter_Associations => New_Actuals);
6594 Rewrite (N, New_Call);
6595 Analyze_And_Resolve (N);
6600 -- The operation name may have been overloaded. Order the actuals
6601 -- according to the formals of the resolved entity, and set the return
6602 -- type to that of the operation.
6605 Normalize_Actuals (N, Nam, False, Norm_OK);
6606 pragma Assert (Norm_OK);
6607 Set_Etype (N, Etype (Nam));
6610 Resolve_Actuals (N, Nam);
6612 -- Create a call reference to the entry
6614 Generate_Reference (Nam, Entry_Name, 's');
6616 if Ekind_In (Nam, E_Entry, E_Entry_Family) then
6617 Check_Potentially_Blocking_Operation (N);
6620 -- Verify that a procedure call cannot masquerade as an entry
6621 -- call where an entry call is expected.
6623 if Ekind (Nam) = E_Procedure then
6624 if Nkind (Parent (N)) = N_Entry_Call_Alternative
6625 and then N = Entry_Call_Statement (Parent (N))
6627 Error_Msg_N ("entry call required in select statement", N);
6629 elsif Nkind (Parent (N)) = N_Triggering_Alternative
6630 and then N = Triggering_Statement (Parent (N))
6632 Error_Msg_N ("triggering statement cannot be procedure call", N);
6634 elsif Ekind (Scope (Nam)) = E_Task_Type
6635 and then not In_Open_Scopes (Scope (Nam))
6637 Error_Msg_N ("task has no entry with this name", Entry_Name);
6641 -- After resolution, entry calls and protected procedure calls are
6642 -- changed into entry calls, for expansion. The structure of the node
6643 -- does not change, so it can safely be done in place. Protected
6644 -- function calls must keep their structure because they are
6647 if Ekind (Nam) /= E_Function then
6649 -- A protected operation that is not a function may modify the
6650 -- corresponding object, and cannot apply to a constant. If this
6651 -- is an internal call, the prefix is the type itself.
6653 if Is_Protected_Type (Scope (Nam))
6654 and then not Is_Variable (Obj)
6655 and then (not Is_Entity_Name (Obj)
6656 or else not Is_Type (Entity (Obj)))
6659 ("prefix of protected procedure or entry call must be variable",
6663 Actuals := Parameter_Associations (N);
6664 First_Named := First_Named_Actual (N);
6667 Make_Entry_Call_Statement (Loc,
6669 Parameter_Associations => Actuals));
6671 Set_First_Named_Actual (N, First_Named);
6672 Set_Analyzed (N, True);
6674 -- Protected functions can return on the secondary stack, in which
6675 -- case we must trigger the transient scope mechanism.
6677 elsif Expander_Active
6678 and then Requires_Transient_Scope (Etype (Nam))
6680 Establish_Transient_Scope (N, Sec_Stack => True);
6682 end Resolve_Entry_Call;
6684 -------------------------
6685 -- Resolve_Equality_Op --
6686 -------------------------
6688 -- Both arguments must have the same type, and the boolean context does
6689 -- not participate in the resolution. The first pass verifies that the
6690 -- interpretation is not ambiguous, and the type of the left argument is
6691 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6692 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6693 -- though they carry a single (universal) type. Diagnose this case here.
6695 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6696 L : constant Node_Id := Left_Opnd (N);
6697 R : constant Node_Id := Right_Opnd (N);
6698 T : Entity_Id := Find_Unique_Type (L, R);
6700 procedure Check_Conditional_Expression (Cond : Node_Id);
6701 -- The resolution rule for conditional expressions requires that each
6702 -- such must have a unique type. This means that if several dependent
6703 -- expressions are of a non-null anonymous access type, and the context
6704 -- does not impose an expected type (as can be the case in an equality
6705 -- operation) the expression must be rejected.
6707 function Find_Unique_Access_Type return Entity_Id;
6708 -- In the case of allocators, make a last-ditch attempt to find a single
6709 -- access type with the right designated type. This is semantically
6710 -- dubious, and of no interest to any real code, but c48008a makes it
6713 ----------------------------------
6714 -- Check_Conditional_Expression --
6715 ----------------------------------
6717 procedure Check_Conditional_Expression (Cond : Node_Id) is
6718 Then_Expr : Node_Id;
6719 Else_Expr : Node_Id;
6722 if Nkind (Cond) = N_Conditional_Expression then
6723 Then_Expr := Next (First (Expressions (Cond)));
6724 Else_Expr := Next (Then_Expr);
6726 if Nkind (Then_Expr) /= N_Null
6727 and then Nkind (Else_Expr) /= N_Null
6730 ("cannot determine type of conditional expression", Cond);
6733 end Check_Conditional_Expression;
6735 -----------------------------
6736 -- Find_Unique_Access_Type --
6737 -----------------------------
6739 function Find_Unique_Access_Type return Entity_Id is
6745 if Ekind (Etype (R)) = E_Allocator_Type then
6746 Acc := Designated_Type (Etype (R));
6747 elsif Ekind (Etype (L)) = E_Allocator_Type then
6748 Acc := Designated_Type (Etype (L));
6754 while S /= Standard_Standard loop
6755 E := First_Entity (S);
6756 while Present (E) loop
6758 and then Is_Access_Type (E)
6759 and then Ekind (E) /= E_Allocator_Type
6760 and then Designated_Type (E) = Base_Type (Acc)
6772 end Find_Unique_Access_Type;
6774 -- Start of processing for Resolve_Equality_Op
6777 Set_Etype (N, Base_Type (Typ));
6778 Generate_Reference (T, N, ' ');
6780 if T = Any_Fixed then
6781 T := Unique_Fixed_Point_Type (L);
6784 if T /= Any_Type then
6785 if T = Any_String or else
6786 T = Any_Composite or else
6789 if T = Any_Character then
6790 Ambiguous_Character (L);
6792 Error_Msg_N ("ambiguous operands for equality", N);
6795 Set_Etype (N, Any_Type);
6798 elsif T = Any_Access
6799 or else Ekind_In (T, E_Allocator_Type, E_Access_Attribute_Type)
6801 T := Find_Unique_Access_Type;
6804 Error_Msg_N ("ambiguous operands for equality", N);
6805 Set_Etype (N, Any_Type);
6809 -- Conditional expressions must have a single type, and if the
6810 -- context does not impose one the dependent expressions cannot
6811 -- be anonymous access types.
6813 elsif Ada_Version >= Ada_2012
6814 and then Ekind_In (Etype (L), E_Anonymous_Access_Type,
6815 E_Anonymous_Access_Subprogram_Type)
6816 and then Ekind_In (Etype (R), E_Anonymous_Access_Type,
6817 E_Anonymous_Access_Subprogram_Type)
6819 Check_Conditional_Expression (L);
6820 Check_Conditional_Expression (R);
6826 -- In SPARK, equality operators = and /= for array types other than
6827 -- String are only defined when, for each index position, the
6828 -- operands have equal static bounds.
6830 if Is_Array_Type (T) then
6831 Mark_Non_ALFA_Subprogram;
6833 -- Protect call to Matching_Static_Array_Bounds to avoid costly
6834 -- operation if not needed.
6836 if Restriction_Check_Required (SPARK)
6837 and then Base_Type (T) /= Standard_String
6838 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
6839 and then Etype (L) /= Any_Composite -- or else L in error
6840 and then Etype (R) /= Any_Composite -- or else R in error
6841 and then not Matching_Static_Array_Bounds (Etype (L), Etype (R))
6843 Check_SPARK_Restriction
6844 ("array types should have matching static bounds", N);
6848 -- If the unique type is a class-wide type then it will be expanded
6849 -- into a dispatching call to the predefined primitive. Therefore we
6850 -- check here for potential violation of such restriction.
6852 if Is_Class_Wide_Type (T) then
6853 Check_Restriction (No_Dispatching_Calls, N);
6856 if Warn_On_Redundant_Constructs
6857 and then Comes_From_Source (N)
6858 and then Is_Entity_Name (R)
6859 and then Entity (R) = Standard_True
6860 and then Comes_From_Source (R)
6862 Error_Msg_N -- CODEFIX
6863 ("?comparison with True is redundant!", R);
6866 Check_Unset_Reference (L);
6867 Check_Unset_Reference (R);
6868 Generate_Operator_Reference (N, T);
6869 Check_Low_Bound_Tested (N);
6871 -- If this is an inequality, it may be the implicit inequality
6872 -- created for a user-defined operation, in which case the corres-
6873 -- ponding equality operation is not intrinsic, and the operation
6874 -- cannot be constant-folded. Else fold.
6876 if Nkind (N) = N_Op_Eq
6877 or else Comes_From_Source (Entity (N))
6878 or else Ekind (Entity (N)) = E_Operator
6879 or else Is_Intrinsic_Subprogram
6880 (Corresponding_Equality (Entity (N)))
6882 Eval_Relational_Op (N);
6884 elsif Nkind (N) = N_Op_Ne
6885 and then Is_Abstract_Subprogram (Entity (N))
6887 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6890 -- Ada 2005: If one operand is an anonymous access type, convert the
6891 -- other operand to it, to ensure that the underlying types match in
6892 -- the back-end. Same for access_to_subprogram, and the conversion
6893 -- verifies that the types are subtype conformant.
6895 -- We apply the same conversion in the case one of the operands is a
6896 -- private subtype of the type of the other.
6898 -- Why the Expander_Active test here ???
6902 (Ekind_In (T, E_Anonymous_Access_Type,
6903 E_Anonymous_Access_Subprogram_Type)
6904 or else Is_Private_Type (T))
6906 if Etype (L) /= T then
6908 Make_Unchecked_Type_Conversion (Sloc (L),
6909 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6910 Expression => Relocate_Node (L)));
6911 Analyze_And_Resolve (L, T);
6914 if (Etype (R)) /= T then
6916 Make_Unchecked_Type_Conversion (Sloc (R),
6917 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6918 Expression => Relocate_Node (R)));
6919 Analyze_And_Resolve (R, T);
6923 end Resolve_Equality_Op;
6925 ----------------------------------
6926 -- Resolve_Explicit_Dereference --
6927 ----------------------------------
6929 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6930 Loc : constant Source_Ptr := Sloc (N);
6932 P : constant Node_Id := Prefix (N);
6937 Check_Fully_Declared_Prefix (Typ, P);
6939 if Is_Overloaded (P) then
6941 -- Use the context type to select the prefix that has the correct
6944 Get_First_Interp (P, I, It);
6945 while Present (It.Typ) loop
6946 exit when Is_Access_Type (It.Typ)
6947 and then Covers (Typ, Designated_Type (It.Typ));
6948 Get_Next_Interp (I, It);
6951 if Present (It.Typ) then
6952 Resolve (P, It.Typ);
6954 -- If no interpretation covers the designated type of the prefix,
6955 -- this is the pathological case where not all implementations of
6956 -- the prefix allow the interpretation of the node as a call. Now
6957 -- that the expected type is known, Remove other interpretations
6958 -- from prefix, rewrite it as a call, and resolve again, so that
6959 -- the proper call node is generated.
6961 Get_First_Interp (P, I, It);
6962 while Present (It.Typ) loop
6963 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6967 Get_Next_Interp (I, It);
6971 Make_Function_Call (Loc,
6973 Make_Explicit_Dereference (Loc,
6975 Parameter_Associations => New_List);
6977 Save_Interps (N, New_N);
6979 Analyze_And_Resolve (N, Typ);
6983 Set_Etype (N, Designated_Type (It.Typ));
6989 if Is_Access_Type (Etype (P)) then
6990 Apply_Access_Check (N);
6993 -- If the designated type is a packed unconstrained array type, and the
6994 -- explicit dereference is not in the context of an attribute reference,
6995 -- then we must compute and set the actual subtype, since it is needed
6996 -- by Gigi. The reason we exclude the attribute case is that this is
6997 -- handled fine by Gigi, and in fact we use such attributes to build the
6998 -- actual subtype. We also exclude generated code (which builds actual
6999 -- subtypes directly if they are needed).
7001 if Is_Array_Type (Etype (N))
7002 and then Is_Packed (Etype (N))
7003 and then not Is_Constrained (Etype (N))
7004 and then Nkind (Parent (N)) /= N_Attribute_Reference
7005 and then Comes_From_Source (N)
7007 Set_Etype (N, Get_Actual_Subtype (N));
7010 -- Note: No Eval processing is required for an explicit dereference,
7011 -- because such a name can never be static.
7013 end Resolve_Explicit_Dereference;
7015 -------------------------------------
7016 -- Resolve_Expression_With_Actions --
7017 -------------------------------------
7019 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id) is
7022 end Resolve_Expression_With_Actions;
7024 -------------------------------
7025 -- Resolve_Indexed_Component --
7026 -------------------------------
7028 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
7029 Name : constant Node_Id := Prefix (N);
7031 Array_Type : Entity_Id := Empty; -- to prevent junk warning
7035 if Is_Overloaded (Name) then
7037 -- Use the context type to select the prefix that yields the correct
7043 I1 : Interp_Index := 0;
7044 P : constant Node_Id := Prefix (N);
7045 Found : Boolean := False;
7048 Get_First_Interp (P, I, It);
7049 while Present (It.Typ) loop
7050 if (Is_Array_Type (It.Typ)
7051 and then Covers (Typ, Component_Type (It.Typ)))
7052 or else (Is_Access_Type (It.Typ)
7053 and then Is_Array_Type (Designated_Type (It.Typ))
7057 Component_Type (Designated_Type (It.Typ))))
7060 It := Disambiguate (P, I1, I, Any_Type);
7062 if It = No_Interp then
7063 Error_Msg_N ("ambiguous prefix for indexing", N);
7069 Array_Type := It.Typ;
7075 Array_Type := It.Typ;
7080 Get_Next_Interp (I, It);
7085 Array_Type := Etype (Name);
7088 Resolve (Name, Array_Type);
7089 Array_Type := Get_Actual_Subtype_If_Available (Name);
7091 -- If prefix is access type, dereference to get real array type.
7092 -- Note: we do not apply an access check because the expander always
7093 -- introduces an explicit dereference, and the check will happen there.
7095 if Is_Access_Type (Array_Type) then
7096 Array_Type := Designated_Type (Array_Type);
7099 -- If name was overloaded, set component type correctly now
7100 -- If a misplaced call to an entry family (which has no index types)
7101 -- return. Error will be diagnosed from calling context.
7103 if Is_Array_Type (Array_Type) then
7104 Set_Etype (N, Component_Type (Array_Type));
7109 Index := First_Index (Array_Type);
7110 Expr := First (Expressions (N));
7112 -- The prefix may have resolved to a string literal, in which case its
7113 -- etype has a special representation. This is only possible currently
7114 -- if the prefix is a static concatenation, written in functional
7117 if Ekind (Array_Type) = E_String_Literal_Subtype then
7118 Resolve (Expr, Standard_Positive);
7121 while Present (Index) and Present (Expr) loop
7122 Resolve (Expr, Etype (Index));
7123 Check_Unset_Reference (Expr);
7125 if Is_Scalar_Type (Etype (Expr)) then
7126 Apply_Scalar_Range_Check (Expr, Etype (Index));
7128 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
7136 -- Do not generate the warning on suspicious index if we are analyzing
7137 -- package Ada.Tags; otherwise we will report the warning with the
7138 -- Prims_Ptr field of the dispatch table.
7140 if Scope (Etype (Prefix (N))) = Standard_Standard
7142 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
7145 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
7146 Eval_Indexed_Component (N);
7149 -- If the array type is atomic, and is packed, and we are in a left side
7150 -- context, then this is worth a warning, since we have a situation
7151 -- where the access to the component may cause extra read/writes of
7152 -- the atomic array object, which could be considered unexpected.
7154 if Nkind (N) = N_Indexed_Component
7155 and then (Is_Atomic (Array_Type)
7156 or else (Is_Entity_Name (Prefix (N))
7157 and then Is_Atomic (Entity (Prefix (N)))))
7158 and then Is_Bit_Packed_Array (Array_Type)
7161 Error_Msg_N ("?assignment to component of packed atomic array",
7163 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
7166 end Resolve_Indexed_Component;
7168 -----------------------------
7169 -- Resolve_Integer_Literal --
7170 -----------------------------
7172 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
7175 Eval_Integer_Literal (N);
7176 end Resolve_Integer_Literal;
7178 --------------------------------
7179 -- Resolve_Intrinsic_Operator --
7180 --------------------------------
7182 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
7183 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
7185 Orig_Op : constant Entity_Id := Entity (N);
7190 -- We must preserve the original entity in a generic setting, so that
7191 -- the legality of the operation can be verified in an instance.
7193 if not Expander_Active then
7198 while Scope (Op) /= Standard_Standard loop
7200 pragma Assert (Present (Op));
7204 Set_Is_Overloaded (N, False);
7206 -- If the operand type is private, rewrite with suitable conversions on
7207 -- the operands and the result, to expose the proper underlying numeric
7210 if Is_Private_Type (Typ) then
7211 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
7213 if Nkind (N) = N_Op_Expon then
7214 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
7216 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7219 if Nkind (Arg1) = N_Type_Conversion then
7220 Save_Interps (Left_Opnd (N), Expression (Arg1));
7223 if Nkind (Arg2) = N_Type_Conversion then
7224 Save_Interps (Right_Opnd (N), Expression (Arg2));
7227 Set_Left_Opnd (N, Arg1);
7228 Set_Right_Opnd (N, Arg2);
7230 Set_Etype (N, Btyp);
7231 Rewrite (N, Unchecked_Convert_To (Typ, N));
7234 elsif Typ /= Etype (Left_Opnd (N))
7235 or else Typ /= Etype (Right_Opnd (N))
7237 -- Add explicit conversion where needed, and save interpretations in
7238 -- case operands are overloaded. If the context is a VMS operation,
7239 -- assert that the conversion is legal (the operands have the proper
7240 -- types to select the VMS intrinsic). Note that in rare cases the
7241 -- VMS operators may be visible, but the default System is being used
7242 -- and Address is a private type.
7244 Arg1 := Convert_To (Typ, Left_Opnd (N));
7245 Arg2 := Convert_To (Typ, Right_Opnd (N));
7247 if Nkind (Arg1) = N_Type_Conversion then
7248 Save_Interps (Left_Opnd (N), Expression (Arg1));
7250 if Is_VMS_Operator (Orig_Op) then
7251 Set_Conversion_OK (Arg1);
7254 Save_Interps (Left_Opnd (N), Arg1);
7257 if Nkind (Arg2) = N_Type_Conversion then
7258 Save_Interps (Right_Opnd (N), Expression (Arg2));
7260 if Is_VMS_Operator (Orig_Op) then
7261 Set_Conversion_OK (Arg2);
7264 Save_Interps (Right_Opnd (N), Arg2);
7267 Rewrite (Left_Opnd (N), Arg1);
7268 Rewrite (Right_Opnd (N), Arg2);
7271 Resolve_Arithmetic_Op (N, Typ);
7274 Resolve_Arithmetic_Op (N, Typ);
7276 end Resolve_Intrinsic_Operator;
7278 --------------------------------------
7279 -- Resolve_Intrinsic_Unary_Operator --
7280 --------------------------------------
7282 procedure Resolve_Intrinsic_Unary_Operator
7286 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
7292 while Scope (Op) /= Standard_Standard loop
7294 pragma Assert (Present (Op));
7299 if Is_Private_Type (Typ) then
7300 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7301 Save_Interps (Right_Opnd (N), Expression (Arg2));
7303 Set_Right_Opnd (N, Arg2);
7305 Set_Etype (N, Btyp);
7306 Rewrite (N, Unchecked_Convert_To (Typ, N));
7310 Resolve_Unary_Op (N, Typ);
7312 end Resolve_Intrinsic_Unary_Operator;
7314 ------------------------
7315 -- Resolve_Logical_Op --
7316 ------------------------
7318 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
7322 Check_No_Direct_Boolean_Operators (N);
7324 -- Predefined operations on scalar types yield the base type. On the
7325 -- other hand, logical operations on arrays yield the type of the
7326 -- arguments (and the context).
7328 if Is_Array_Type (Typ) then
7331 B_Typ := Base_Type (Typ);
7334 -- OK if this is a VMS-specific intrinsic operation
7336 if Is_VMS_Operator (Entity (N)) then
7339 -- The following test is required because the operands of the operation
7340 -- may be literals, in which case the resulting type appears to be
7341 -- compatible with a signed integer type, when in fact it is compatible
7342 -- only with modular types. If the context itself is universal, the
7343 -- operation is illegal.
7345 elsif not Valid_Boolean_Arg (Typ) then
7346 Error_Msg_N ("invalid context for logical operation", N);
7347 Set_Etype (N, Any_Type);
7350 elsif Typ = Any_Modular then
7352 ("no modular type available in this context", N);
7353 Set_Etype (N, Any_Type);
7356 elsif Is_Modular_Integer_Type (Typ)
7357 and then Etype (Left_Opnd (N)) = Universal_Integer
7358 and then Etype (Right_Opnd (N)) = Universal_Integer
7360 Check_For_Visible_Operator (N, B_Typ);
7363 Resolve (Left_Opnd (N), B_Typ);
7364 Resolve (Right_Opnd (N), B_Typ);
7366 Check_Unset_Reference (Left_Opnd (N));
7367 Check_Unset_Reference (Right_Opnd (N));
7369 Set_Etype (N, B_Typ);
7370 Generate_Operator_Reference (N, B_Typ);
7371 Eval_Logical_Op (N);
7373 -- In SPARK, logical operations AND, OR and XOR for arrays are defined
7374 -- only when both operands have same static lower and higher bounds. Of
7375 -- course the types have to match, so only check if operands are
7376 -- compatible and the node itself has no errors.
7378 if Is_Array_Type (B_Typ)
7379 and then Nkind (N) in N_Binary_Op
7381 Mark_Non_ALFA_Subprogram;
7384 Left_Typ : constant Node_Id := Etype (Left_Opnd (N));
7385 Right_Typ : constant Node_Id := Etype (Right_Opnd (N));
7387 -- Protect call to Matching_Static_Array_Bounds to avoid costly
7388 -- operation if not needed.
7390 if Restriction_Check_Required (SPARK)
7391 and then Base_Type (Left_Typ) = Base_Type (Right_Typ)
7392 and then Left_Typ /= Any_Composite -- or Left_Opnd in error
7393 and then Right_Typ /= Any_Composite -- or Right_Opnd in error
7394 and then not Matching_Static_Array_Bounds (Left_Typ, Right_Typ)
7396 Check_SPARK_Restriction
7397 ("array types should have matching static bounds", N);
7401 end Resolve_Logical_Op;
7403 ---------------------------
7404 -- Resolve_Membership_Op --
7405 ---------------------------
7407 -- The context can only be a boolean type, and does not determine the
7408 -- arguments. Arguments should be unambiguous, but the preference rule for
7409 -- universal types applies.
7411 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
7412 pragma Warnings (Off, Typ);
7414 L : constant Node_Id := Left_Opnd (N);
7415 R : constant Node_Id := Right_Opnd (N);
7418 procedure Resolve_Set_Membership;
7419 -- Analysis has determined a unique type for the left operand. Use it to
7420 -- resolve the disjuncts.
7422 ----------------------------
7423 -- Resolve_Set_Membership --
7424 ----------------------------
7426 procedure Resolve_Set_Membership is
7430 Resolve (L, Etype (L));
7432 Alt := First (Alternatives (N));
7433 while Present (Alt) loop
7435 -- Alternative is an expression, a range
7436 -- or a subtype mark.
7438 if not Is_Entity_Name (Alt)
7439 or else not Is_Type (Entity (Alt))
7441 Resolve (Alt, Etype (L));
7446 end Resolve_Set_Membership;
7448 -- Start of processing for Resolve_Membership_Op
7451 if L = Error or else R = Error then
7455 if Present (Alternatives (N)) then
7456 Resolve_Set_Membership;
7459 elsif not Is_Overloaded (R)
7461 (Etype (R) = Universal_Integer
7463 Etype (R) = Universal_Real)
7464 and then Is_Overloaded (L)
7468 -- Ada 2005 (AI-251): Support the following case:
7470 -- type I is interface;
7471 -- type T is tagged ...
7473 -- function Test (O : I'Class) is
7475 -- return O in T'Class.
7478 -- In this case we have nothing else to do. The membership test will be
7479 -- done at run time.
7481 elsif Ada_Version >= Ada_2005
7482 and then Is_Class_Wide_Type (Etype (L))
7483 and then Is_Interface (Etype (L))
7484 and then Is_Class_Wide_Type (Etype (R))
7485 and then not Is_Interface (Etype (R))
7489 T := Intersect_Types (L, R);
7492 -- If mixed-mode operations are present and operands are all literal,
7493 -- the only interpretation involves Duration, which is probably not
7494 -- the intention of the programmer.
7496 if T = Any_Fixed then
7497 T := Unique_Fixed_Point_Type (N);
7499 if T = Any_Type then
7505 Check_Unset_Reference (L);
7507 if Nkind (R) = N_Range
7508 and then not Is_Scalar_Type (T)
7510 Error_Msg_N ("scalar type required for range", R);
7513 if Is_Entity_Name (R) then
7514 Freeze_Expression (R);
7517 Check_Unset_Reference (R);
7520 Eval_Membership_Op (N);
7521 end Resolve_Membership_Op;
7527 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
7528 Loc : constant Source_Ptr := Sloc (N);
7531 -- Handle restriction against anonymous null access values This
7532 -- restriction can be turned off using -gnatdj.
7534 -- Ada 2005 (AI-231): Remove restriction
7536 if Ada_Version < Ada_2005
7537 and then not Debug_Flag_J
7538 and then Ekind (Typ) = E_Anonymous_Access_Type
7539 and then Comes_From_Source (N)
7541 -- In the common case of a call which uses an explicitly null value
7542 -- for an access parameter, give specialized error message.
7544 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
7548 ("null is not allowed as argument for an access parameter", N);
7550 -- Standard message for all other cases (are there any?)
7554 ("null cannot be of an anonymous access type", N);
7558 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
7559 -- assignment to a null-excluding object
7561 if Ada_Version >= Ada_2005
7562 and then Can_Never_Be_Null (Typ)
7563 and then Nkind (Parent (N)) = N_Assignment_Statement
7565 if not Inside_Init_Proc then
7567 (Compile_Time_Constraint_Error (N,
7568 "(Ada 2005) null not allowed in null-excluding objects?"),
7569 Make_Raise_Constraint_Error (Loc,
7570 Reason => CE_Access_Check_Failed));
7573 Make_Raise_Constraint_Error (Loc,
7574 Reason => CE_Access_Check_Failed));
7578 -- In a distributed context, null for a remote access to subprogram may
7579 -- need to be replaced with a special record aggregate. In this case,
7580 -- return after having done the transformation.
7582 if (Ekind (Typ) = E_Record_Type
7583 or else Is_Remote_Access_To_Subprogram_Type (Typ))
7584 and then Remote_AST_Null_Value (N, Typ)
7589 -- The null literal takes its type from the context
7594 -----------------------
7595 -- Resolve_Op_Concat --
7596 -----------------------
7598 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
7600 -- We wish to avoid deep recursion, because concatenations are often
7601 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
7602 -- operands nonrecursively until we find something that is not a simple
7603 -- concatenation (A in this case). We resolve that, and then walk back
7604 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
7605 -- to do the rest of the work at each level. The Parent pointers allow
7606 -- us to avoid recursion, and thus avoid running out of memory. See also
7607 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
7613 -- The following code is equivalent to:
7615 -- Resolve_Op_Concat_First (NN, Typ);
7616 -- Resolve_Op_Concat_Arg (N, ...);
7617 -- Resolve_Op_Concat_Rest (N, Typ);
7619 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
7620 -- operand is a concatenation.
7622 -- Walk down left operands
7625 Resolve_Op_Concat_First (NN, Typ);
7626 Op1 := Left_Opnd (NN);
7627 exit when not (Nkind (Op1) = N_Op_Concat
7628 and then not Is_Array_Type (Component_Type (Typ))
7629 and then Entity (Op1) = Entity (NN));
7633 -- Now (given the above example) NN is A&B and Op1 is A
7635 -- First resolve Op1 ...
7637 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
7639 -- ... then walk NN back up until we reach N (where we started), calling
7640 -- Resolve_Op_Concat_Rest along the way.
7643 Resolve_Op_Concat_Rest (NN, Typ);
7648 if Base_Type (Etype (N)) /= Standard_String then
7649 Check_SPARK_Restriction
7650 ("result of concatenation should have type String", N);
7652 end Resolve_Op_Concat;
7654 ---------------------------
7655 -- Resolve_Op_Concat_Arg --
7656 ---------------------------
7658 procedure Resolve_Op_Concat_Arg
7664 Btyp : constant Entity_Id := Base_Type (Typ);
7665 Ctyp : constant Entity_Id := Component_Type (Typ);
7670 or else (not Is_Overloaded (Arg)
7671 and then Etype (Arg) /= Any_Composite
7672 and then Covers (Ctyp, Etype (Arg)))
7674 Resolve (Arg, Ctyp);
7676 Resolve (Arg, Btyp);
7679 -- If both Array & Array and Array & Component are visible, there is a
7680 -- potential ambiguity that must be reported.
7682 elsif Has_Compatible_Type (Arg, Ctyp) then
7683 if Nkind (Arg) = N_Aggregate
7684 and then Is_Composite_Type (Ctyp)
7686 if Is_Private_Type (Ctyp) then
7687 Resolve (Arg, Btyp);
7689 -- If the operation is user-defined and not overloaded use its
7690 -- profile. The operation may be a renaming, in which case it has
7691 -- been rewritten, and we want the original profile.
7693 elsif not Is_Overloaded (N)
7694 and then Comes_From_Source (Entity (Original_Node (N)))
7695 and then Ekind (Entity (Original_Node (N))) = E_Function
7699 (Next_Formal (First_Formal (Entity (Original_Node (N))))));
7702 -- Otherwise an aggregate may match both the array type and the
7706 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
7707 Set_Etype (Arg, Any_Type);
7711 if Is_Overloaded (Arg)
7712 and then Has_Compatible_Type (Arg, Typ)
7713 and then Etype (Arg) /= Any_Type
7721 Get_First_Interp (Arg, I, It);
7723 Get_Next_Interp (I, It);
7725 -- Special-case the error message when the overloading is
7726 -- caused by a function that yields an array and can be
7727 -- called without parameters.
7729 if It.Nam = Func then
7730 Error_Msg_Sloc := Sloc (Func);
7731 Error_Msg_N ("ambiguous call to function#", Arg);
7733 ("\\interpretation as call yields&", Arg, Typ);
7735 ("\\interpretation as indexing of call yields&",
7736 Arg, Component_Type (Typ));
7739 Error_Msg_N ("ambiguous operand for concatenation!", Arg);
7741 Get_First_Interp (Arg, I, It);
7742 while Present (It.Nam) loop
7743 Error_Msg_Sloc := Sloc (It.Nam);
7745 if Base_Type (It.Typ) = Btyp
7747 Base_Type (It.Typ) = Base_Type (Ctyp)
7749 Error_Msg_N -- CODEFIX
7750 ("\\possible interpretation#", Arg);
7753 Get_Next_Interp (I, It);
7759 Resolve (Arg, Component_Type (Typ));
7761 if Nkind (Arg) = N_String_Literal then
7762 Set_Etype (Arg, Component_Type (Typ));
7765 if Arg = Left_Opnd (N) then
7766 Set_Is_Component_Left_Opnd (N);
7768 Set_Is_Component_Right_Opnd (N);
7773 Resolve (Arg, Btyp);
7776 -- Concatenation is restricted in SPARK: each operand must be either a
7777 -- string literal, the name of a string constant, a static character or
7778 -- string expression, or another concatenation. Arg cannot be a
7779 -- concatenation here as callers of Resolve_Op_Concat_Arg call it
7780 -- separately on each final operand, past concatenation operations.
7782 if Is_Character_Type (Etype (Arg)) then
7783 if not Is_Static_Expression (Arg) then
7784 Check_SPARK_Restriction
7785 ("character operand for concatenation should be static", N);
7788 elsif Is_String_Type (Etype (Arg)) then
7789 if not (Nkind_In (Arg, N_Identifier, N_Expanded_Name)
7790 and then Is_Constant_Object (Entity (Arg)))
7791 and then not Is_Static_Expression (Arg)
7793 Check_SPARK_Restriction
7794 ("string operand for concatenation should be static", N);
7797 -- Do not issue error on an operand that is neither a character nor a
7798 -- string, as the error is issued in Resolve_Op_Concat.
7804 Check_Unset_Reference (Arg);
7805 end Resolve_Op_Concat_Arg;
7807 -----------------------------
7808 -- Resolve_Op_Concat_First --
7809 -----------------------------
7811 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
7812 Btyp : constant Entity_Id := Base_Type (Typ);
7813 Op1 : constant Node_Id := Left_Opnd (N);
7814 Op2 : constant Node_Id := Right_Opnd (N);
7817 -- The parser folds an enormous sequence of concatenations of string
7818 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
7819 -- in the right operand. If the expression resolves to a predefined "&"
7820 -- operator, all is well. Otherwise, the parser's folding is wrong, so
7821 -- we give an error. See P_Simple_Expression in Par.Ch4.
7823 if Nkind (Op2) = N_String_Literal
7824 and then Is_Folded_In_Parser (Op2)
7825 and then Ekind (Entity (N)) = E_Function
7827 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
7828 and then String_Length (Strval (Op1)) = 0);
7829 Error_Msg_N ("too many user-defined concatenations", N);
7833 Set_Etype (N, Btyp);
7835 if Is_Limited_Composite (Btyp) then
7836 Error_Msg_N ("concatenation not available for limited array", N);
7837 Explain_Limited_Type (Btyp, N);
7839 end Resolve_Op_Concat_First;
7841 ----------------------------
7842 -- Resolve_Op_Concat_Rest --
7843 ----------------------------
7845 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
7846 Op1 : constant Node_Id := Left_Opnd (N);
7847 Op2 : constant Node_Id := Right_Opnd (N);
7850 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
7852 Generate_Operator_Reference (N, Typ);
7854 if Is_String_Type (Typ) then
7855 Eval_Concatenation (N);
7858 -- If this is not a static concatenation, but the result is a string
7859 -- type (and not an array of strings) ensure that static string operands
7860 -- have their subtypes properly constructed.
7862 if Nkind (N) /= N_String_Literal
7863 and then Is_Character_Type (Component_Type (Typ))
7865 Set_String_Literal_Subtype (Op1, Typ);
7866 Set_String_Literal_Subtype (Op2, Typ);
7868 end Resolve_Op_Concat_Rest;
7870 ----------------------
7871 -- Resolve_Op_Expon --
7872 ----------------------
7874 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
7875 B_Typ : constant Entity_Id := Base_Type (Typ);
7878 -- Catch attempts to do fixed-point exponentiation with universal
7879 -- operands, which is a case where the illegality is not caught during
7880 -- normal operator analysis.
7882 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
7883 Error_Msg_N ("exponentiation not available for fixed point", N);
7887 if Comes_From_Source (N)
7888 and then Ekind (Entity (N)) = E_Function
7889 and then Is_Imported (Entity (N))
7890 and then Is_Intrinsic_Subprogram (Entity (N))
7892 Resolve_Intrinsic_Operator (N, Typ);
7896 if Etype (Left_Opnd (N)) = Universal_Integer
7897 or else Etype (Left_Opnd (N)) = Universal_Real
7899 Check_For_Visible_Operator (N, B_Typ);
7902 -- We do the resolution using the base type, because intermediate values
7903 -- in expressions always are of the base type, not a subtype of it.
7905 Resolve (Left_Opnd (N), B_Typ);
7906 Resolve (Right_Opnd (N), Standard_Integer);
7908 Check_Unset_Reference (Left_Opnd (N));
7909 Check_Unset_Reference (Right_Opnd (N));
7911 Set_Etype (N, B_Typ);
7912 Generate_Operator_Reference (N, B_Typ);
7915 -- Set overflow checking bit. Much cleverer code needed here eventually
7916 -- and perhaps the Resolve routines should be separated for the various
7917 -- arithmetic operations, since they will need different processing. ???
7919 if Nkind (N) in N_Op then
7920 if not Overflow_Checks_Suppressed (Etype (N)) then
7921 Enable_Overflow_Check (N);
7924 end Resolve_Op_Expon;
7926 --------------------
7927 -- Resolve_Op_Not --
7928 --------------------
7930 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
7933 function Parent_Is_Boolean return Boolean;
7934 -- This function determines if the parent node is a boolean operator or
7935 -- operation (comparison op, membership test, or short circuit form) and
7936 -- the not in question is the left operand of this operation. Note that
7937 -- if the not is in parens, then false is returned.
7939 -----------------------
7940 -- Parent_Is_Boolean --
7941 -----------------------
7943 function Parent_Is_Boolean return Boolean is
7945 if Paren_Count (N) /= 0 then
7949 case Nkind (Parent (N)) is
7964 return Left_Opnd (Parent (N)) = N;
7970 end Parent_Is_Boolean;
7972 -- Start of processing for Resolve_Op_Not
7975 -- Predefined operations on scalar types yield the base type. On the
7976 -- other hand, logical operations on arrays yield the type of the
7977 -- arguments (and the context).
7979 if Is_Array_Type (Typ) then
7982 B_Typ := Base_Type (Typ);
7985 if Is_VMS_Operator (Entity (N)) then
7988 -- Straightforward case of incorrect arguments
7990 elsif not Valid_Boolean_Arg (Typ) then
7991 Error_Msg_N ("invalid operand type for operator&", N);
7992 Set_Etype (N, Any_Type);
7995 -- Special case of probable missing parens
7997 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7998 if Parent_Is_Boolean then
8000 ("operand of not must be enclosed in parentheses",
8004 ("no modular type available in this context", N);
8007 Set_Etype (N, Any_Type);
8010 -- OK resolution of NOT
8013 -- Warn if non-boolean types involved. This is a case like not a < b
8014 -- where a and b are modular, where we will get (not a) < b and most
8015 -- likely not (a < b) was intended.
8017 if Warn_On_Questionable_Missing_Parens
8018 and then not Is_Boolean_Type (Typ)
8019 and then Parent_Is_Boolean
8021 Error_Msg_N ("?not expression should be parenthesized here!", N);
8024 -- Warn on double negation if checking redundant constructs
8026 if Warn_On_Redundant_Constructs
8027 and then Comes_From_Source (N)
8028 and then Comes_From_Source (Right_Opnd (N))
8029 and then Root_Type (Typ) = Standard_Boolean
8030 and then Nkind (Right_Opnd (N)) = N_Op_Not
8032 Error_Msg_N ("redundant double negation?", N);
8035 -- Complete resolution and evaluation of NOT
8037 Resolve (Right_Opnd (N), B_Typ);
8038 Check_Unset_Reference (Right_Opnd (N));
8039 Set_Etype (N, B_Typ);
8040 Generate_Operator_Reference (N, B_Typ);
8045 -----------------------------
8046 -- Resolve_Operator_Symbol --
8047 -----------------------------
8049 -- Nothing to be done, all resolved already
8051 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
8052 pragma Warnings (Off, N);
8053 pragma Warnings (Off, Typ);
8057 end Resolve_Operator_Symbol;
8059 ----------------------------------
8060 -- Resolve_Qualified_Expression --
8061 ----------------------------------
8063 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
8064 pragma Warnings (Off, Typ);
8066 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
8067 Expr : constant Node_Id := Expression (N);
8070 Resolve (Expr, Target_Typ);
8072 -- Protect call to Matching_Static_Array_Bounds to avoid costly
8073 -- operation if not needed.
8075 if Restriction_Check_Required (SPARK)
8076 and then Is_Array_Type (Target_Typ)
8077 and then Is_Array_Type (Etype (Expr))
8078 and then Etype (Expr) /= Any_Composite -- or else Expr in error
8079 and then not Matching_Static_Array_Bounds (Target_Typ, Etype (Expr))
8081 Check_SPARK_Restriction
8082 ("array types should have matching static bounds", N);
8085 -- A qualified expression requires an exact match of the type, class-
8086 -- wide matching is not allowed. However, if the qualifying type is
8087 -- specific and the expression has a class-wide type, it may still be
8088 -- okay, since it can be the result of the expansion of a call to a
8089 -- dispatching function, so we also have to check class-wideness of the
8090 -- type of the expression's original node.
8092 if (Is_Class_Wide_Type (Target_Typ)
8094 (Is_Class_Wide_Type (Etype (Expr))
8095 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
8096 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
8098 Wrong_Type (Expr, Target_Typ);
8101 -- If the target type is unconstrained, then we reset the type of the
8102 -- result from the type of the expression. For other cases, the actual
8103 -- subtype of the expression is the target type.
8105 if Is_Composite_Type (Target_Typ)
8106 and then not Is_Constrained (Target_Typ)
8108 Set_Etype (N, Etype (Expr));
8111 Eval_Qualified_Expression (N);
8112 end Resolve_Qualified_Expression;
8114 -----------------------------------
8115 -- Resolve_Quantified_Expression --
8116 -----------------------------------
8118 procedure Resolve_Quantified_Expression (N : Node_Id; Typ : Entity_Id) is
8120 -- The loop structure is already resolved during its analysis, only the
8121 -- resolution of the condition needs to be done. Expansion is disabled
8122 -- so that checks and other generated code are inserted in the tree
8123 -- after expression has been rewritten as a loop.
8125 Expander_Mode_Save_And_Set (False);
8126 Resolve (Condition (N), Typ);
8127 Expander_Mode_Restore;
8128 end Resolve_Quantified_Expression;
8134 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
8135 L : constant Node_Id := Low_Bound (N);
8136 H : constant Node_Id := High_Bound (N);
8138 function First_Last_Ref return Boolean;
8139 -- Returns True if N is of the form X'First .. X'Last where X is the
8140 -- same entity for both attributes.
8142 --------------------
8143 -- First_Last_Ref --
8144 --------------------
8146 function First_Last_Ref return Boolean is
8147 Lorig : constant Node_Id := Original_Node (L);
8148 Horig : constant Node_Id := Original_Node (H);
8151 if Nkind (Lorig) = N_Attribute_Reference
8152 and then Nkind (Horig) = N_Attribute_Reference
8153 and then Attribute_Name (Lorig) = Name_First
8154 and then Attribute_Name (Horig) = Name_Last
8157 PL : constant Node_Id := Prefix (Lorig);
8158 PH : constant Node_Id := Prefix (Horig);
8160 if Is_Entity_Name (PL)
8161 and then Is_Entity_Name (PH)
8162 and then Entity (PL) = Entity (PH)
8172 -- Start of processing for Resolve_Range
8179 -- Check for inappropriate range on unordered enumeration type
8181 if Bad_Unordered_Enumeration_Reference (N, Typ)
8183 -- Exclude X'First .. X'Last if X is the same entity for both
8185 and then not First_Last_Ref
8187 Error_Msg ("subrange of unordered enumeration type?", Sloc (N));
8190 Check_Unset_Reference (L);
8191 Check_Unset_Reference (H);
8193 -- We have to check the bounds for being within the base range as
8194 -- required for a non-static context. Normally this is automatic and
8195 -- done as part of evaluating expressions, but the N_Range node is an
8196 -- exception, since in GNAT we consider this node to be a subexpression,
8197 -- even though in Ada it is not. The circuit in Sem_Eval could check for
8198 -- this, but that would put the test on the main evaluation path for
8201 Check_Non_Static_Context (L);
8202 Check_Non_Static_Context (H);
8204 -- Check for an ambiguous range over character literals. This will
8205 -- happen with a membership test involving only literals.
8207 if Typ = Any_Character then
8208 Ambiguous_Character (L);
8209 Set_Etype (N, Any_Type);
8213 -- If bounds are static, constant-fold them, so size computations are
8214 -- identical between front-end and back-end. Do not perform this
8215 -- transformation while analyzing generic units, as type information
8216 -- would be lost when reanalyzing the constant node in the instance.
8218 if Is_Discrete_Type (Typ) and then Expander_Active then
8219 if Is_OK_Static_Expression (L) then
8220 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
8223 if Is_OK_Static_Expression (H) then
8224 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
8229 --------------------------
8230 -- Resolve_Real_Literal --
8231 --------------------------
8233 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
8234 Actual_Typ : constant Entity_Id := Etype (N);
8237 -- Special processing for fixed-point literals to make sure that the
8238 -- value is an exact multiple of small where this is required. We skip
8239 -- this for the universal real case, and also for generic types.
8241 if Is_Fixed_Point_Type (Typ)
8242 and then Typ /= Universal_Fixed
8243 and then Typ /= Any_Fixed
8244 and then not Is_Generic_Type (Typ)
8247 Val : constant Ureal := Realval (N);
8248 Cintr : constant Ureal := Val / Small_Value (Typ);
8249 Cint : constant Uint := UR_Trunc (Cintr);
8250 Den : constant Uint := Norm_Den (Cintr);
8254 -- Case of literal is not an exact multiple of the Small
8258 -- For a source program literal for a decimal fixed-point type,
8259 -- this is statically illegal (RM 4.9(36)).
8261 if Is_Decimal_Fixed_Point_Type (Typ)
8262 and then Actual_Typ = Universal_Real
8263 and then Comes_From_Source (N)
8265 Error_Msg_N ("value has extraneous low order digits", N);
8268 -- Generate a warning if literal from source
8270 if Is_Static_Expression (N)
8271 and then Warn_On_Bad_Fixed_Value
8274 ("?static fixed-point value is not a multiple of Small!",
8278 -- Replace literal by a value that is the exact representation
8279 -- of a value of the type, i.e. a multiple of the small value,
8280 -- by truncation, since Machine_Rounds is false for all GNAT
8281 -- fixed-point types (RM 4.9(38)).
8283 Stat := Is_Static_Expression (N);
8285 Make_Real_Literal (Sloc (N),
8286 Realval => Small_Value (Typ) * Cint));
8288 Set_Is_Static_Expression (N, Stat);
8291 -- In all cases, set the corresponding integer field
8293 Set_Corresponding_Integer_Value (N, Cint);
8297 -- Now replace the actual type by the expected type as usual
8300 Eval_Real_Literal (N);
8301 end Resolve_Real_Literal;
8303 -----------------------
8304 -- Resolve_Reference --
8305 -----------------------
8307 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
8308 P : constant Node_Id := Prefix (N);
8311 -- Replace general access with specific type
8313 if Ekind (Etype (N)) = E_Allocator_Type then
8314 Set_Etype (N, Base_Type (Typ));
8317 Resolve (P, Designated_Type (Etype (N)));
8319 -- If we are taking the reference of a volatile entity, then treat it as
8320 -- a potential modification of this entity. This is too conservative,
8321 -- but necessary because remove side effects can cause transformations
8322 -- of normal assignments into reference sequences that otherwise fail to
8323 -- notice the modification.
8325 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
8326 Note_Possible_Modification (P, Sure => False);
8328 end Resolve_Reference;
8330 --------------------------------
8331 -- Resolve_Selected_Component --
8332 --------------------------------
8334 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
8336 Comp1 : Entity_Id := Empty; -- prevent junk warning
8337 P : constant Node_Id := Prefix (N);
8338 S : constant Node_Id := Selector_Name (N);
8339 T : Entity_Id := Etype (P);
8341 I1 : Interp_Index := 0; -- prevent junk warning
8346 function Init_Component return Boolean;
8347 -- Check whether this is the initialization of a component within an
8348 -- init proc (by assignment or call to another init proc). If true,
8349 -- there is no need for a discriminant check.
8351 --------------------
8352 -- Init_Component --
8353 --------------------
8355 function Init_Component return Boolean is
8357 return Inside_Init_Proc
8358 and then Nkind (Prefix (N)) = N_Identifier
8359 and then Chars (Prefix (N)) = Name_uInit
8360 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
8363 -- Start of processing for Resolve_Selected_Component
8366 if Is_Overloaded (P) then
8368 -- Use the context type to select the prefix that has a selector
8369 -- of the correct name and type.
8372 Get_First_Interp (P, I, It);
8374 Search : while Present (It.Typ) loop
8375 if Is_Access_Type (It.Typ) then
8376 T := Designated_Type (It.Typ);
8381 -- Locate selected component. For a private prefix the selector
8382 -- can denote a discriminant.
8384 if Is_Record_Type (T) or else Is_Private_Type (T) then
8386 -- The visible components of a class-wide type are those of
8389 if Is_Class_Wide_Type (T) then
8393 Comp := First_Entity (T);
8394 while Present (Comp) loop
8395 if Chars (Comp) = Chars (S)
8396 and then Covers (Etype (Comp), Typ)
8405 It := Disambiguate (P, I1, I, Any_Type);
8407 if It = No_Interp then
8409 ("ambiguous prefix for selected component", N);
8416 -- There may be an implicit dereference. Retrieve
8417 -- designated record type.
8419 if Is_Access_Type (It1.Typ) then
8420 T := Designated_Type (It1.Typ);
8425 if Scope (Comp1) /= T then
8427 -- Resolution chooses the new interpretation.
8428 -- Find the component with the right name.
8430 Comp1 := First_Entity (T);
8431 while Present (Comp1)
8432 and then Chars (Comp1) /= Chars (S)
8434 Comp1 := Next_Entity (Comp1);
8443 Comp := Next_Entity (Comp);
8447 Get_Next_Interp (I, It);
8450 Resolve (P, It1.Typ);
8452 Set_Entity_With_Style_Check (S, Comp1);
8455 -- Resolve prefix with its type
8460 -- Generate cross-reference. We needed to wait until full overloading
8461 -- resolution was complete to do this, since otherwise we can't tell if
8462 -- we are an lvalue or not.
8464 if May_Be_Lvalue (N) then
8465 Generate_Reference (Entity (S), S, 'm');
8467 Generate_Reference (Entity (S), S, 'r');
8470 -- If prefix is an access type, the node will be transformed into an
8471 -- explicit dereference during expansion. The type of the node is the
8472 -- designated type of that of the prefix.
8474 if Is_Access_Type (Etype (P)) then
8475 T := Designated_Type (Etype (P));
8476 Check_Fully_Declared_Prefix (T, P);
8481 if Has_Discriminants (T)
8482 and then Ekind_In (Entity (S), E_Component, E_Discriminant)
8483 and then Present (Original_Record_Component (Entity (S)))
8484 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
8485 and then Present (Discriminant_Checking_Func
8486 (Original_Record_Component (Entity (S))))
8487 and then not Discriminant_Checks_Suppressed (T)
8488 and then not Init_Component
8490 Set_Do_Discriminant_Check (N);
8493 if Ekind (Entity (S)) = E_Void then
8494 Error_Msg_N ("premature use of component", S);
8497 -- If the prefix is a record conversion, this may be a renamed
8498 -- discriminant whose bounds differ from those of the original
8499 -- one, so we must ensure that a range check is performed.
8501 if Nkind (P) = N_Type_Conversion
8502 and then Ekind (Entity (S)) = E_Discriminant
8503 and then Is_Discrete_Type (Typ)
8505 Set_Etype (N, Base_Type (Typ));
8508 -- Note: No Eval processing is required, because the prefix is of a
8509 -- record type, or protected type, and neither can possibly be static.
8511 -- If the array type is atomic, and is packed, and we are in a left side
8512 -- context, then this is worth a warning, since we have a situation
8513 -- where the access to the component may cause extra read/writes of the
8514 -- atomic array object, which could be considered unexpected.
8516 if Nkind (N) = N_Selected_Component
8517 and then (Is_Atomic (T)
8518 or else (Is_Entity_Name (Prefix (N))
8519 and then Is_Atomic (Entity (Prefix (N)))))
8520 and then Is_Packed (T)
8523 Error_Msg_N ("?assignment to component of packed atomic record",
8525 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
8528 end Resolve_Selected_Component;
8534 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
8535 B_Typ : constant Entity_Id := Base_Type (Typ);
8536 L : constant Node_Id := Left_Opnd (N);
8537 R : constant Node_Id := Right_Opnd (N);
8540 -- We do the resolution using the base type, because intermediate values
8541 -- in expressions always are of the base type, not a subtype of it.
8544 Resolve (R, Standard_Natural);
8546 Check_Unset_Reference (L);
8547 Check_Unset_Reference (R);
8549 Set_Etype (N, B_Typ);
8550 Generate_Operator_Reference (N, B_Typ);
8554 ---------------------------
8555 -- Resolve_Short_Circuit --
8556 ---------------------------
8558 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
8559 B_Typ : constant Entity_Id := Base_Type (Typ);
8560 L : constant Node_Id := Left_Opnd (N);
8561 R : constant Node_Id := Right_Opnd (N);
8567 -- Check for issuing warning for always False assert/check, this happens
8568 -- when assertions are turned off, in which case the pragma Assert/Check
8569 -- was transformed into:
8571 -- if False and then <condition> then ...
8573 -- and we detect this pattern
8575 if Warn_On_Assertion_Failure
8576 and then Is_Entity_Name (R)
8577 and then Entity (R) = Standard_False
8578 and then Nkind (Parent (N)) = N_If_Statement
8579 and then Nkind (N) = N_And_Then
8580 and then Is_Entity_Name (L)
8581 and then Entity (L) = Standard_False
8584 Orig : constant Node_Id := Original_Node (Parent (N));
8587 if Nkind (Orig) = N_Pragma
8588 and then Pragma_Name (Orig) = Name_Assert
8590 -- Don't want to warn if original condition is explicit False
8593 Expr : constant Node_Id :=
8596 (First (Pragma_Argument_Associations (Orig))));
8598 if Is_Entity_Name (Expr)
8599 and then Entity (Expr) = Standard_False
8603 -- Issue warning. We do not want the deletion of the
8604 -- IF/AND-THEN to take this message with it. We achieve
8605 -- this by making sure that the expanded code points to
8606 -- the Sloc of the expression, not the original pragma.
8609 ("?assertion would fail at run time!",
8611 (First (Pragma_Argument_Associations (Orig))));
8615 -- Similar processing for Check pragma
8617 elsif Nkind (Orig) = N_Pragma
8618 and then Pragma_Name (Orig) = Name_Check
8620 -- Don't want to warn if original condition is explicit False
8623 Expr : constant Node_Id :=
8627 (Pragma_Argument_Associations (Orig)))));
8629 if Is_Entity_Name (Expr)
8630 and then Entity (Expr) = Standard_False
8635 ("?check would fail at run time!",
8637 (Last (Pragma_Argument_Associations (Orig))));
8644 -- Continue with processing of short circuit
8646 Check_Unset_Reference (L);
8647 Check_Unset_Reference (R);
8649 Set_Etype (N, B_Typ);
8650 Eval_Short_Circuit (N);
8651 end Resolve_Short_Circuit;
8657 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
8658 Name : constant Node_Id := Prefix (N);
8659 Drange : constant Node_Id := Discrete_Range (N);
8660 Array_Type : Entity_Id := Empty;
8664 if Is_Overloaded (Name) then
8666 -- Use the context type to select the prefix that yields the correct
8671 I1 : Interp_Index := 0;
8673 P : constant Node_Id := Prefix (N);
8674 Found : Boolean := False;
8677 Get_First_Interp (P, I, It);
8678 while Present (It.Typ) loop
8679 if (Is_Array_Type (It.Typ)
8680 and then Covers (Typ, It.Typ))
8681 or else (Is_Access_Type (It.Typ)
8682 and then Is_Array_Type (Designated_Type (It.Typ))
8683 and then Covers (Typ, Designated_Type (It.Typ)))
8686 It := Disambiguate (P, I1, I, Any_Type);
8688 if It = No_Interp then
8689 Error_Msg_N ("ambiguous prefix for slicing", N);
8694 Array_Type := It.Typ;
8699 Array_Type := It.Typ;
8704 Get_Next_Interp (I, It);
8709 Array_Type := Etype (Name);
8712 Resolve (Name, Array_Type);
8714 if Is_Access_Type (Array_Type) then
8715 Apply_Access_Check (N);
8716 Array_Type := Designated_Type (Array_Type);
8718 -- If the prefix is an access to an unconstrained array, we must use
8719 -- the actual subtype of the object to perform the index checks. The
8720 -- object denoted by the prefix is implicit in the node, so we build
8721 -- an explicit representation for it in order to compute the actual
8724 if not Is_Constrained (Array_Type) then
8725 Remove_Side_Effects (Prefix (N));
8728 Obj : constant Node_Id :=
8729 Make_Explicit_Dereference (Sloc (N),
8730 Prefix => New_Copy_Tree (Prefix (N)));
8732 Set_Etype (Obj, Array_Type);
8733 Set_Parent (Obj, Parent (N));
8734 Array_Type := Get_Actual_Subtype (Obj);
8738 elsif Is_Entity_Name (Name)
8739 or else Nkind (Name) = N_Explicit_Dereference
8740 or else (Nkind (Name) = N_Function_Call
8741 and then not Is_Constrained (Etype (Name)))
8743 Array_Type := Get_Actual_Subtype (Name);
8745 -- If the name is a selected component that depends on discriminants,
8746 -- build an actual subtype for it. This can happen only when the name
8747 -- itself is overloaded; otherwise the actual subtype is created when
8748 -- the selected component is analyzed.
8750 elsif Nkind (Name) = N_Selected_Component
8751 and then Full_Analysis
8752 and then Depends_On_Discriminant (First_Index (Array_Type))
8755 Act_Decl : constant Node_Id :=
8756 Build_Actual_Subtype_Of_Component (Array_Type, Name);
8758 Insert_Action (N, Act_Decl);
8759 Array_Type := Defining_Identifier (Act_Decl);
8762 -- Maybe this should just be "else", instead of checking for the
8763 -- specific case of slice??? This is needed for the case where the
8764 -- prefix is an Image attribute, which gets expanded to a slice, and so
8765 -- has a constrained subtype which we want to use for the slice range
8766 -- check applied below (the range check won't get done if the
8767 -- unconstrained subtype of the 'Image is used).
8769 elsif Nkind (Name) = N_Slice then
8770 Array_Type := Etype (Name);
8773 -- If name was overloaded, set slice type correctly now
8775 Set_Etype (N, Array_Type);
8777 -- If the range is specified by a subtype mark, no resolution is
8778 -- necessary. Else resolve the bounds, and apply needed checks.
8780 if not Is_Entity_Name (Drange) then
8781 Index := First_Index (Array_Type);
8782 Resolve (Drange, Base_Type (Etype (Index)));
8784 if Nkind (Drange) = N_Range then
8786 -- Ensure that side effects in the bounds are properly handled
8788 Force_Evaluation (Low_Bound (Drange));
8789 Force_Evaluation (High_Bound (Drange));
8791 -- Do not apply the range check to nodes associated with the
8792 -- frontend expansion of the dispatch table. We first check
8793 -- if Ada.Tags is already loaded to avoid the addition of an
8794 -- undesired dependence on such run-time unit.
8796 if not Tagged_Type_Expansion
8798 (RTU_Loaded (Ada_Tags)
8799 and then Nkind (Prefix (N)) = N_Selected_Component
8800 and then Present (Entity (Selector_Name (Prefix (N))))
8801 and then Entity (Selector_Name (Prefix (N))) =
8802 RTE_Record_Component (RE_Prims_Ptr))
8804 Apply_Range_Check (Drange, Etype (Index));
8809 Set_Slice_Subtype (N);
8811 -- Check bad use of type with predicates
8813 if Has_Predicates (Etype (Drange)) then
8814 Bad_Predicated_Subtype_Use
8815 ("subtype& has predicate, not allowed in slice",
8816 Drange, Etype (Drange));
8818 -- Otherwise here is where we check suspicious indexes
8820 elsif Nkind (Drange) = N_Range then
8821 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
8822 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
8828 ----------------------------
8829 -- Resolve_String_Literal --
8830 ----------------------------
8832 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
8833 C_Typ : constant Entity_Id := Component_Type (Typ);
8834 R_Typ : constant Entity_Id := Root_Type (C_Typ);
8835 Loc : constant Source_Ptr := Sloc (N);
8836 Str : constant String_Id := Strval (N);
8837 Strlen : constant Nat := String_Length (Str);
8838 Subtype_Id : Entity_Id;
8839 Need_Check : Boolean;
8842 -- For a string appearing in a concatenation, defer creation of the
8843 -- string_literal_subtype until the end of the resolution of the
8844 -- concatenation, because the literal may be constant-folded away. This
8845 -- is a useful optimization for long concatenation expressions.
8847 -- If the string is an aggregate built for a single character (which
8848 -- happens in a non-static context) or a is null string to which special
8849 -- checks may apply, we build the subtype. Wide strings must also get a
8850 -- string subtype if they come from a one character aggregate. Strings
8851 -- generated by attributes might be static, but it is often hard to
8852 -- determine whether the enclosing context is static, so we generate
8853 -- subtypes for them as well, thus losing some rarer optimizations ???
8854 -- Same for strings that come from a static conversion.
8857 (Strlen = 0 and then Typ /= Standard_String)
8858 or else Nkind (Parent (N)) /= N_Op_Concat
8859 or else (N /= Left_Opnd (Parent (N))
8860 and then N /= Right_Opnd (Parent (N)))
8861 or else ((Typ = Standard_Wide_String
8862 or else Typ = Standard_Wide_Wide_String)
8863 and then Nkind (Original_Node (N)) /= N_String_Literal);
8865 -- If the resolving type is itself a string literal subtype, we can just
8866 -- reuse it, since there is no point in creating another.
8868 if Ekind (Typ) = E_String_Literal_Subtype then
8871 elsif Nkind (Parent (N)) = N_Op_Concat
8872 and then not Need_Check
8873 and then not Nkind_In (Original_Node (N), N_Character_Literal,
8874 N_Attribute_Reference,
8875 N_Qualified_Expression,
8880 -- Otherwise we must create a string literal subtype. Note that the
8881 -- whole idea of string literal subtypes is simply to avoid the need
8882 -- for building a full fledged array subtype for each literal.
8885 Set_String_Literal_Subtype (N, Typ);
8886 Subtype_Id := Etype (N);
8889 if Nkind (Parent (N)) /= N_Op_Concat
8892 Set_Etype (N, Subtype_Id);
8893 Eval_String_Literal (N);
8896 if Is_Limited_Composite (Typ)
8897 or else Is_Private_Composite (Typ)
8899 Error_Msg_N ("string literal not available for private array", N);
8900 Set_Etype (N, Any_Type);
8904 -- The validity of a null string has been checked in the call to
8905 -- Eval_String_Literal.
8910 -- Always accept string literal with component type Any_Character, which
8911 -- occurs in error situations and in comparisons of literals, both of
8912 -- which should accept all literals.
8914 elsif R_Typ = Any_Character then
8917 -- If the type is bit-packed, then we always transform the string
8918 -- literal into a full fledged aggregate.
8920 elsif Is_Bit_Packed_Array (Typ) then
8923 -- Deal with cases of Wide_Wide_String, Wide_String, and String
8926 -- For Standard.Wide_Wide_String, or any other type whose component
8927 -- type is Standard.Wide_Wide_Character, we know that all the
8928 -- characters in the string must be acceptable, since the parser
8929 -- accepted the characters as valid character literals.
8931 if R_Typ = Standard_Wide_Wide_Character then
8934 -- For the case of Standard.String, or any other type whose component
8935 -- type is Standard.Character, we must make sure that there are no
8936 -- wide characters in the string, i.e. that it is entirely composed
8937 -- of characters in range of type Character.
8939 -- If the string literal is the result of a static concatenation, the
8940 -- test has already been performed on the components, and need not be
8943 elsif R_Typ = Standard_Character
8944 and then Nkind (Original_Node (N)) /= N_Op_Concat
8946 for J in 1 .. Strlen loop
8947 if not In_Character_Range (Get_String_Char (Str, J)) then
8949 -- If we are out of range, post error. This is one of the
8950 -- very few places that we place the flag in the middle of
8951 -- a token, right under the offending wide character. Not
8952 -- quite clear if this is right wrt wide character encoding
8953 -- sequences, but it's only an error message!
8956 ("literal out of range of type Standard.Character",
8957 Source_Ptr (Int (Loc) + J));
8962 -- For the case of Standard.Wide_String, or any other type whose
8963 -- component type is Standard.Wide_Character, we must make sure that
8964 -- there are no wide characters in the string, i.e. that it is
8965 -- entirely composed of characters in range of type Wide_Character.
8967 -- If the string literal is the result of a static concatenation,
8968 -- the test has already been performed on the components, and need
8971 elsif R_Typ = Standard_Wide_Character
8972 and then Nkind (Original_Node (N)) /= N_Op_Concat
8974 for J in 1 .. Strlen loop
8975 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
8977 -- If we are out of range, post error. This is one of the
8978 -- very few places that we place the flag in the middle of
8979 -- a token, right under the offending wide character.
8981 -- This is not quite right, because characters in general
8982 -- will take more than one character position ???
8985 ("literal out of range of type Standard.Wide_Character",
8986 Source_Ptr (Int (Loc) + J));
8991 -- If the root type is not a standard character, then we will convert
8992 -- the string into an aggregate and will let the aggregate code do
8993 -- the checking. Standard Wide_Wide_Character is also OK here.
8999 -- See if the component type of the array corresponding to the string
9000 -- has compile time known bounds. If yes we can directly check
9001 -- whether the evaluation of the string will raise constraint error.
9002 -- Otherwise we need to transform the string literal into the
9003 -- corresponding character aggregate and let the aggregate code do
9006 if Is_Standard_Character_Type (R_Typ) then
9008 -- Check for the case of full range, where we are definitely OK
9010 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
9014 -- Here the range is not the complete base type range, so check
9017 Comp_Typ_Lo : constant Node_Id :=
9018 Type_Low_Bound (Component_Type (Typ));
9019 Comp_Typ_Hi : constant Node_Id :=
9020 Type_High_Bound (Component_Type (Typ));
9025 if Compile_Time_Known_Value (Comp_Typ_Lo)
9026 and then Compile_Time_Known_Value (Comp_Typ_Hi)
9028 for J in 1 .. Strlen loop
9029 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
9031 if Char_Val < Expr_Value (Comp_Typ_Lo)
9032 or else Char_Val > Expr_Value (Comp_Typ_Hi)
9034 Apply_Compile_Time_Constraint_Error
9035 (N, "character out of range?", CE_Range_Check_Failed,
9036 Loc => Source_Ptr (Int (Loc) + J));
9046 -- If we got here we meed to transform the string literal into the
9047 -- equivalent qualified positional array aggregate. This is rather
9048 -- heavy artillery for this situation, but it is hard work to avoid.
9051 Lits : constant List_Id := New_List;
9052 P : Source_Ptr := Loc + 1;
9056 -- Build the character literals, we give them source locations that
9057 -- correspond to the string positions, which is a bit tricky given
9058 -- the possible presence of wide character escape sequences.
9060 for J in 1 .. Strlen loop
9061 C := Get_String_Char (Str, J);
9062 Set_Character_Literal_Name (C);
9065 Make_Character_Literal (P,
9067 Char_Literal_Value => UI_From_CC (C)));
9069 if In_Character_Range (C) then
9072 -- Should we have a call to Skip_Wide here ???
9081 Make_Qualified_Expression (Loc,
9082 Subtype_Mark => New_Reference_To (Typ, Loc),
9084 Make_Aggregate (Loc, Expressions => Lits)));
9086 Analyze_And_Resolve (N, Typ);
9088 end Resolve_String_Literal;
9090 -----------------------------
9091 -- Resolve_Subprogram_Info --
9092 -----------------------------
9094 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
9097 end Resolve_Subprogram_Info;
9099 -----------------------------
9100 -- Resolve_Type_Conversion --
9101 -----------------------------
9103 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
9104 Conv_OK : constant Boolean := Conversion_OK (N);
9105 Operand : constant Node_Id := Expression (N);
9106 Operand_Typ : constant Entity_Id := Etype (Operand);
9107 Target_Typ : constant Entity_Id := Etype (N);
9112 Test_Redundant : Boolean := Warn_On_Redundant_Constructs;
9113 -- Set to False to suppress cases where we want to suppress the test
9114 -- for redundancy to avoid possible false positives on this warning.
9118 and then not Valid_Conversion (N, Target_Typ, Operand)
9123 -- If the Operand Etype is Universal_Fixed, then the conversion is
9124 -- never redundant. We need this check because by the time we have
9125 -- finished the rather complex transformation, the conversion looks
9126 -- redundant when it is not.
9128 if Operand_Typ = Universal_Fixed then
9129 Test_Redundant := False;
9131 -- If the operand is marked as Any_Fixed, then special processing is
9132 -- required. This is also a case where we suppress the test for a
9133 -- redundant conversion, since most certainly it is not redundant.
9135 elsif Operand_Typ = Any_Fixed then
9136 Test_Redundant := False;
9138 -- Mixed-mode operation involving a literal. Context must be a fixed
9139 -- type which is applied to the literal subsequently.
9141 if Is_Fixed_Point_Type (Typ) then
9142 Set_Etype (Operand, Universal_Real);
9144 elsif Is_Numeric_Type (Typ)
9145 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
9146 and then (Etype (Right_Opnd (Operand)) = Universal_Real
9148 Etype (Left_Opnd (Operand)) = Universal_Real)
9150 -- Return if expression is ambiguous
9152 if Unique_Fixed_Point_Type (N) = Any_Type then
9155 -- If nothing else, the available fixed type is Duration
9158 Set_Etype (Operand, Standard_Duration);
9161 -- Resolve the real operand with largest available precision
9163 if Etype (Right_Opnd (Operand)) = Universal_Real then
9164 Rop := New_Copy_Tree (Right_Opnd (Operand));
9166 Rop := New_Copy_Tree (Left_Opnd (Operand));
9169 Resolve (Rop, Universal_Real);
9171 -- If the operand is a literal (it could be a non-static and
9172 -- illegal exponentiation) check whether the use of Duration
9173 -- is potentially inaccurate.
9175 if Nkind (Rop) = N_Real_Literal
9176 and then Realval (Rop) /= Ureal_0
9177 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
9180 ("?universal real operand can only " &
9181 "be interpreted as Duration!",
9184 ("\?precision will be lost in the conversion!", Rop);
9187 elsif Is_Numeric_Type (Typ)
9188 and then Nkind (Operand) in N_Op
9189 and then Unique_Fixed_Point_Type (N) /= Any_Type
9191 Set_Etype (Operand, Standard_Duration);
9194 Error_Msg_N ("invalid context for mixed mode operation", N);
9195 Set_Etype (Operand, Any_Type);
9202 -- In SPARK, a type conversion between array types should be restricted
9203 -- to types which have matching static bounds.
9205 -- Protect call to Matching_Static_Array_Bounds to avoid costly
9206 -- operation if not needed.
9208 if Restriction_Check_Required (SPARK)
9209 and then Is_Array_Type (Target_Typ)
9210 and then Is_Array_Type (Operand_Typ)
9211 and then Operand_Typ /= Any_Composite -- or else Operand in error
9212 and then not Matching_Static_Array_Bounds (Target_Typ, Operand_Typ)
9214 Check_SPARK_Restriction
9215 ("array types should have matching static bounds", N);
9218 -- In formal mode, the operand of an ancestor type conversion must be an
9219 -- object (not an expression).
9221 if Is_Tagged_Type (Target_Typ)
9222 and then not Is_Class_Wide_Type (Target_Typ)
9223 and then Is_Tagged_Type (Operand_Typ)
9224 and then not Is_Class_Wide_Type (Operand_Typ)
9225 and then Is_Ancestor (Target_Typ, Operand_Typ)
9226 and then not Is_SPARK_Object_Reference (Operand)
9228 Check_SPARK_Restriction ("object required", Operand);
9231 -- Note: we do the Eval_Type_Conversion call before applying the
9232 -- required checks for a subtype conversion. This is important, since
9233 -- both are prepared under certain circumstances to change the type
9234 -- conversion to a constraint error node, but in the case of
9235 -- Eval_Type_Conversion this may reflect an illegality in the static
9236 -- case, and we would miss the illegality (getting only a warning
9237 -- message), if we applied the type conversion checks first.
9239 Eval_Type_Conversion (N);
9241 -- Even when evaluation is not possible, we may be able to simplify the
9242 -- conversion or its expression. This needs to be done before applying
9243 -- checks, since otherwise the checks may use the original expression
9244 -- and defeat the simplifications. This is specifically the case for
9245 -- elimination of the floating-point Truncation attribute in
9246 -- float-to-int conversions.
9248 Simplify_Type_Conversion (N);
9250 -- If after evaluation we still have a type conversion, then we may need
9251 -- to apply checks required for a subtype conversion.
9253 -- Skip these type conversion checks if universal fixed operands
9254 -- operands involved, since range checks are handled separately for
9255 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
9257 if Nkind (N) = N_Type_Conversion
9258 and then not Is_Generic_Type (Root_Type (Target_Typ))
9259 and then Target_Typ /= Universal_Fixed
9260 and then Operand_Typ /= Universal_Fixed
9262 Apply_Type_Conversion_Checks (N);
9265 -- Issue warning for conversion of simple object to its own type. We
9266 -- have to test the original nodes, since they may have been rewritten
9267 -- by various optimizations.
9269 Orig_N := Original_Node (N);
9271 -- Here we test for a redundant conversion if the warning mode is
9272 -- active (and was not locally reset), and we have a type conversion
9273 -- from source not appearing in a generic instance.
9276 and then Nkind (Orig_N) = N_Type_Conversion
9277 and then Comes_From_Source (Orig_N)
9278 and then not In_Instance
9280 Orig_N := Original_Node (Expression (Orig_N));
9281 Orig_T := Target_Typ;
9283 -- If the node is part of a larger expression, the Target_Type
9284 -- may not be the original type of the node if the context is a
9285 -- condition. Recover original type to see if conversion is needed.
9287 if Is_Boolean_Type (Orig_T)
9288 and then Nkind (Parent (N)) in N_Op
9290 Orig_T := Etype (Parent (N));
9293 -- If we have an entity name, then give the warning if the entity
9294 -- is the right type, or if it is a loop parameter covered by the
9295 -- original type (that's needed because loop parameters have an
9296 -- odd subtype coming from the bounds).
9298 if (Is_Entity_Name (Orig_N)
9300 (Etype (Entity (Orig_N)) = Orig_T
9302 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
9303 and then Covers (Orig_T, Etype (Entity (Orig_N))))))
9305 -- If not an entity, then type of expression must match
9307 or else Etype (Orig_N) = Orig_T
9309 -- One more check, do not give warning if the analyzed conversion
9310 -- has an expression with non-static bounds, and the bounds of the
9311 -- target are static. This avoids junk warnings in cases where the
9312 -- conversion is necessary to establish staticness, for example in
9313 -- a case statement.
9315 if not Is_OK_Static_Subtype (Operand_Typ)
9316 and then Is_OK_Static_Subtype (Target_Typ)
9320 -- Finally, if this type conversion occurs in a context requiring
9321 -- a prefix, and the expression is a qualified expression then the
9322 -- type conversion is not redundant, since a qualified expression
9323 -- is not a prefix, whereas a type conversion is. For example, "X
9324 -- := T'(Funx(...)).Y;" is illegal because a selected component
9325 -- requires a prefix, but a type conversion makes it legal: "X :=
9326 -- T(T'(Funx(...))).Y;"
9328 -- In Ada 2012, a qualified expression is a name, so this idiom is
9329 -- no longer needed, but we still suppress the warning because it
9330 -- seems unfriendly for warnings to pop up when you switch to the
9331 -- newer language version.
9333 elsif Nkind (Orig_N) = N_Qualified_Expression
9334 and then Nkind_In (Parent (N), N_Attribute_Reference,
9335 N_Indexed_Component,
9336 N_Selected_Component,
9338 N_Explicit_Dereference)
9342 -- Here we give the redundant conversion warning. If it is an
9343 -- entity, give the name of the entity in the message. If not,
9344 -- just mention the expression.
9347 if Is_Entity_Name (Orig_N) then
9348 Error_Msg_Node_2 := Orig_T;
9349 Error_Msg_NE -- CODEFIX
9350 ("?redundant conversion, & is of type &!",
9351 N, Entity (Orig_N));
9354 ("?redundant conversion, expression is of type&!",
9361 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
9362 -- No need to perform any interface conversion if the type of the
9363 -- expression coincides with the target type.
9365 if Ada_Version >= Ada_2005
9366 and then Expander_Active
9367 and then Operand_Typ /= Target_Typ
9370 Opnd : Entity_Id := Operand_Typ;
9371 Target : Entity_Id := Target_Typ;
9374 if Is_Access_Type (Opnd) then
9375 Opnd := Designated_Type (Opnd);
9378 if Is_Access_Type (Target_Typ) then
9379 Target := Designated_Type (Target);
9382 if Opnd = Target then
9385 -- Conversion from interface type
9387 elsif Is_Interface (Opnd) then
9389 -- Ada 2005 (AI-217): Handle entities from limited views
9391 if From_With_Type (Opnd) then
9392 Error_Msg_Qual_Level := 99;
9393 Error_Msg_NE -- CODEFIX
9394 ("missing WITH clause on package &", N,
9395 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
9397 ("type conversions require visibility of the full view",
9400 elsif From_With_Type (Target)
9402 (Is_Access_Type (Target_Typ)
9403 and then Present (Non_Limited_View (Etype (Target))))
9405 Error_Msg_Qual_Level := 99;
9406 Error_Msg_NE -- CODEFIX
9407 ("missing WITH clause on package &", N,
9408 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
9410 ("type conversions require visibility of the full view",
9414 Expand_Interface_Conversion (N, Is_Static => False);
9417 -- Conversion to interface type
9419 elsif Is_Interface (Target) then
9423 if Ekind_In (Opnd, E_Protected_Subtype, E_Task_Subtype) then
9424 Opnd := Etype (Opnd);
9427 if not Interface_Present_In_Ancestor
9431 if Is_Class_Wide_Type (Opnd) then
9433 -- The static analysis is not enough to know if the
9434 -- interface is implemented or not. Hence we must pass
9435 -- the work to the expander to generate code to evaluate
9436 -- the conversion at run time.
9438 Expand_Interface_Conversion (N, Is_Static => False);
9441 Error_Msg_Name_1 := Chars (Etype (Target));
9442 Error_Msg_Name_2 := Chars (Opnd);
9444 ("wrong interface conversion (% is not a progenitor " &
9449 Expand_Interface_Conversion (N);
9454 end Resolve_Type_Conversion;
9456 ----------------------
9457 -- Resolve_Unary_Op --
9458 ----------------------
9460 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
9461 B_Typ : constant Entity_Id := Base_Type (Typ);
9462 R : constant Node_Id := Right_Opnd (N);
9468 if Is_Modular_Integer_Type (Typ) and then Nkind (N) /= N_Op_Not then
9469 Error_Msg_Name_1 := Chars (Typ);
9470 Check_SPARK_Restriction
9471 ("unary operator not defined for modular type%", N);
9474 -- Deal with intrinsic unary operators
9476 if Comes_From_Source (N)
9477 and then Ekind (Entity (N)) = E_Function
9478 and then Is_Imported (Entity (N))
9479 and then Is_Intrinsic_Subprogram (Entity (N))
9481 Resolve_Intrinsic_Unary_Operator (N, Typ);
9485 -- Deal with universal cases
9487 if Etype (R) = Universal_Integer
9489 Etype (R) = Universal_Real
9491 Check_For_Visible_Operator (N, B_Typ);
9494 Set_Etype (N, B_Typ);
9497 -- Generate warning for expressions like abs (x mod 2)
9499 if Warn_On_Redundant_Constructs
9500 and then Nkind (N) = N_Op_Abs
9502 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
9504 if OK and then Hi >= Lo and then Lo >= 0 then
9505 Error_Msg_N -- CODEFIX
9506 ("?abs applied to known non-negative value has no effect", N);
9510 -- Deal with reference generation
9512 Check_Unset_Reference (R);
9513 Generate_Operator_Reference (N, B_Typ);
9516 -- Set overflow checking bit. Much cleverer code needed here eventually
9517 -- and perhaps the Resolve routines should be separated for the various
9518 -- arithmetic operations, since they will need different processing ???
9520 if Nkind (N) in N_Op then
9521 if not Overflow_Checks_Suppressed (Etype (N)) then
9522 Enable_Overflow_Check (N);
9526 -- Generate warning for expressions like -5 mod 3 for integers. No need
9527 -- to worry in the floating-point case, since parens do not affect the
9528 -- result so there is no point in giving in a warning.
9531 Norig : constant Node_Id := Original_Node (N);
9540 if Warn_On_Questionable_Missing_Parens
9541 and then Comes_From_Source (Norig)
9542 and then Is_Integer_Type (Typ)
9543 and then Nkind (Norig) = N_Op_Minus
9545 Rorig := Original_Node (Right_Opnd (Norig));
9547 -- We are looking for cases where the right operand is not
9548 -- parenthesized, and is a binary operator, multiply, divide, or
9549 -- mod. These are the cases where the grouping can affect results.
9551 if Paren_Count (Rorig) = 0
9552 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
9554 -- For mod, we always give the warning, since the value is
9555 -- affected by the parenthesization (e.g. (-5) mod 315 /=
9556 -- -(5 mod 315)). But for the other cases, the only concern is
9557 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
9558 -- overflows, but (-2) * 64 does not). So we try to give the
9559 -- message only when overflow is possible.
9561 if Nkind (Rorig) /= N_Op_Mod
9562 and then Compile_Time_Known_Value (R)
9564 Val := Expr_Value (R);
9566 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
9567 HB := Expr_Value (Type_High_Bound (Typ));
9569 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
9572 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
9573 LB := Expr_Value (Type_Low_Bound (Typ));
9575 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
9578 -- Note that the test below is deliberately excluding the
9579 -- largest negative number, since that is a potentially
9580 -- troublesome case (e.g. -2 * x, where the result is the
9581 -- largest negative integer has an overflow with 2 * x).
9583 if Val > LB and then Val <= HB then
9588 -- For the multiplication case, the only case we have to worry
9589 -- about is when (-a)*b is exactly the largest negative number
9590 -- so that -(a*b) can cause overflow. This can only happen if
9591 -- a is a power of 2, and more generally if any operand is a
9592 -- constant that is not a power of 2, then the parentheses
9593 -- cannot affect whether overflow occurs. We only bother to
9594 -- test the left most operand
9596 -- Loop looking at left operands for one that has known value
9599 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
9600 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
9601 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
9603 -- Operand value of 0 or 1 skips warning
9608 -- Otherwise check power of 2, if power of 2, warn, if
9609 -- anything else, skip warning.
9612 while Lval /= 2 loop
9613 if Lval mod 2 = 1 then
9624 -- Keep looking at left operands
9626 Opnd := Left_Opnd (Opnd);
9629 -- For rem or "/" we can only have a problematic situation
9630 -- if the divisor has a value of minus one or one. Otherwise
9631 -- overflow is impossible (divisor > 1) or we have a case of
9632 -- division by zero in any case.
9634 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
9635 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
9636 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
9641 -- If we fall through warning should be issued
9644 ("?unary minus expression should be parenthesized here!", N);
9648 end Resolve_Unary_Op;
9650 ----------------------------------
9651 -- Resolve_Unchecked_Expression --
9652 ----------------------------------
9654 procedure Resolve_Unchecked_Expression
9659 Resolve (Expression (N), Typ, Suppress => All_Checks);
9661 end Resolve_Unchecked_Expression;
9663 ---------------------------------------
9664 -- Resolve_Unchecked_Type_Conversion --
9665 ---------------------------------------
9667 procedure Resolve_Unchecked_Type_Conversion
9671 pragma Warnings (Off, Typ);
9673 Operand : constant Node_Id := Expression (N);
9674 Opnd_Type : constant Entity_Id := Etype (Operand);
9677 -- Resolve operand using its own type
9679 Resolve (Operand, Opnd_Type);
9680 Eval_Unchecked_Conversion (N);
9681 end Resolve_Unchecked_Type_Conversion;
9683 ------------------------------
9684 -- Rewrite_Operator_As_Call --
9685 ------------------------------
9687 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
9688 Loc : constant Source_Ptr := Sloc (N);
9689 Actuals : constant List_Id := New_List;
9693 if Nkind (N) in N_Binary_Op then
9694 Append (Left_Opnd (N), Actuals);
9697 Append (Right_Opnd (N), Actuals);
9700 Make_Function_Call (Sloc => Loc,
9701 Name => New_Occurrence_Of (Nam, Loc),
9702 Parameter_Associations => Actuals);
9704 Preserve_Comes_From_Source (New_N, N);
9705 Preserve_Comes_From_Source (Name (New_N), N);
9707 Set_Etype (N, Etype (Nam));
9708 end Rewrite_Operator_As_Call;
9710 ------------------------------
9711 -- Rewrite_Renamed_Operator --
9712 ------------------------------
9714 procedure Rewrite_Renamed_Operator
9719 Nam : constant Name_Id := Chars (Op);
9720 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
9724 -- Rewrite the operator node using the real operator, not its renaming.
9725 -- Exclude user-defined intrinsic operations of the same name, which are
9726 -- treated separately and rewritten as calls.
9728 if Ekind (Op) /= E_Function or else Chars (N) /= Nam then
9729 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
9730 Set_Chars (Op_Node, Nam);
9731 Set_Etype (Op_Node, Etype (N));
9732 Set_Entity (Op_Node, Op);
9733 Set_Right_Opnd (Op_Node, Right_Opnd (N));
9735 -- Indicate that both the original entity and its renaming are
9736 -- referenced at this point.
9738 Generate_Reference (Entity (N), N);
9739 Generate_Reference (Op, N);
9742 Set_Left_Opnd (Op_Node, Left_Opnd (N));
9745 Rewrite (N, Op_Node);
9747 -- If the context type is private, add the appropriate conversions so
9748 -- that the operator is applied to the full view. This is done in the
9749 -- routines that resolve intrinsic operators.
9751 if Is_Intrinsic_Subprogram (Op)
9752 and then Is_Private_Type (Typ)
9755 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
9756 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
9757 Resolve_Intrinsic_Operator (N, Typ);
9759 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
9760 Resolve_Intrinsic_Unary_Operator (N, Typ);
9767 elsif Ekind (Op) = E_Function and then Is_Intrinsic_Subprogram (Op) then
9769 -- Operator renames a user-defined operator of the same name. Use the
9770 -- original operator in the node, which is the one Gigi knows about.
9773 Set_Is_Overloaded (N, False);
9775 end Rewrite_Renamed_Operator;
9777 -----------------------
9778 -- Set_Slice_Subtype --
9779 -----------------------
9781 -- Build an implicit subtype declaration to represent the type delivered by
9782 -- the slice. This is an abbreviated version of an array subtype. We define
9783 -- an index subtype for the slice, using either the subtype name or the
9784 -- discrete range of the slice. To be consistent with index usage elsewhere
9785 -- we create a list header to hold the single index. This list is not
9786 -- otherwise attached to the syntax tree.
9788 procedure Set_Slice_Subtype (N : Node_Id) is
9789 Loc : constant Source_Ptr := Sloc (N);
9790 Index_List : constant List_Id := New_List;
9792 Index_Subtype : Entity_Id;
9793 Index_Type : Entity_Id;
9794 Slice_Subtype : Entity_Id;
9795 Drange : constant Node_Id := Discrete_Range (N);
9798 if Is_Entity_Name (Drange) then
9799 Index_Subtype := Entity (Drange);
9802 -- We force the evaluation of a range. This is definitely needed in
9803 -- the renamed case, and seems safer to do unconditionally. Note in
9804 -- any case that since we will create and insert an Itype referring
9805 -- to this range, we must make sure any side effect removal actions
9806 -- are inserted before the Itype definition.
9808 if Nkind (Drange) = N_Range then
9809 Force_Evaluation (Low_Bound (Drange));
9810 Force_Evaluation (High_Bound (Drange));
9813 Index_Type := Base_Type (Etype (Drange));
9815 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9817 -- Take a new copy of Drange (where bounds have been rewritten to
9818 -- reference side-effect-free names). Using a separate tree ensures
9819 -- that further expansion (e.g. while rewriting a slice assignment
9820 -- into a FOR loop) does not attempt to remove side effects on the
9821 -- bounds again (which would cause the bounds in the index subtype
9822 -- definition to refer to temporaries before they are defined) (the
9823 -- reason is that some names are considered side effect free here
9824 -- for the subtype, but not in the context of a loop iteration
9827 Set_Scalar_Range (Index_Subtype, New_Copy_Tree (Drange));
9828 Set_Parent (Scalar_Range (Index_Subtype), Index_Subtype);
9829 Set_Etype (Index_Subtype, Index_Type);
9830 Set_Size_Info (Index_Subtype, Index_Type);
9831 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9834 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
9836 Index := New_Occurrence_Of (Index_Subtype, Loc);
9837 Set_Etype (Index, Index_Subtype);
9838 Append (Index, Index_List);
9840 Set_First_Index (Slice_Subtype, Index);
9841 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
9842 Set_Is_Constrained (Slice_Subtype, True);
9844 Check_Compile_Time_Size (Slice_Subtype);
9846 -- The Etype of the existing Slice node is reset to this slice subtype.
9847 -- Its bounds are obtained from its first index.
9849 Set_Etype (N, Slice_Subtype);
9851 -- For packed slice subtypes, freeze immediately (except in the case of
9852 -- being in a "spec expression" where we never freeze when we first see
9855 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
9856 Freeze_Itype (Slice_Subtype, N);
9858 -- For all other cases insert an itype reference in the slice's actions
9859 -- so that the itype is frozen at the proper place in the tree (i.e. at
9860 -- the point where actions for the slice are analyzed). Note that this
9861 -- is different from freezing the itype immediately, which might be
9862 -- premature (e.g. if the slice is within a transient scope). This needs
9863 -- to be done only if expansion is enabled.
9865 elsif Expander_Active then
9866 Ensure_Defined (Typ => Slice_Subtype, N => N);
9868 end Set_Slice_Subtype;
9870 --------------------------------
9871 -- Set_String_Literal_Subtype --
9872 --------------------------------
9874 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
9875 Loc : constant Source_Ptr := Sloc (N);
9876 Low_Bound : constant Node_Id :=
9877 Type_Low_Bound (Etype (First_Index (Typ)));
9878 Subtype_Id : Entity_Id;
9881 if Nkind (N) /= N_String_Literal then
9885 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
9886 Set_String_Literal_Length (Subtype_Id, UI_From_Int
9887 (String_Length (Strval (N))));
9888 Set_Etype (Subtype_Id, Base_Type (Typ));
9889 Set_Is_Constrained (Subtype_Id);
9890 Set_Etype (N, Subtype_Id);
9892 if Is_OK_Static_Expression (Low_Bound) then
9894 -- The low bound is set from the low bound of the corresponding index
9895 -- type. Note that we do not store the high bound in the string literal
9896 -- subtype, but it can be deduced if necessary from the length and the
9899 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
9902 -- If the lower bound is not static we create a range for the string
9903 -- literal, using the index type and the known length of the literal.
9904 -- The index type is not necessarily Positive, so the upper bound is
9905 -- computed as T'Val (T'Pos (Low_Bound) + L - 1)
9908 Index_List : constant List_Id := New_List;
9909 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
9911 High_Bound : constant Node_Id :=
9912 Make_Attribute_Reference (Loc,
9913 Attribute_Name => Name_Val,
9915 New_Occurrence_Of (Index_Type, Loc),
9916 Expressions => New_List (
9919 Make_Attribute_Reference (Loc,
9920 Attribute_Name => Name_Pos,
9922 New_Occurrence_Of (Index_Type, Loc),
9924 New_List (New_Copy_Tree (Low_Bound))),
9926 Make_Integer_Literal (Loc,
9927 String_Length (Strval (N)) - 1))));
9929 Array_Subtype : Entity_Id;
9930 Index_Subtype : Entity_Id;
9935 if Is_Integer_Type (Index_Type) then
9936 Set_String_Literal_Low_Bound
9937 (Subtype_Id, Make_Integer_Literal (Loc, 1));
9940 -- If the index type is an enumeration type, build bounds
9941 -- expression with attributes.
9943 Set_String_Literal_Low_Bound
9945 Make_Attribute_Reference (Loc,
9946 Attribute_Name => Name_First,
9948 New_Occurrence_Of (Base_Type (Index_Type), Loc)));
9949 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Index_Type);
9952 Analyze_And_Resolve (String_Literal_Low_Bound (Subtype_Id));
9954 -- Build bona fide subtype for the string, and wrap it in an
9955 -- unchecked conversion, because the backend expects the
9956 -- String_Literal_Subtype to have a static lower bound.
9959 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9960 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
9961 Set_Scalar_Range (Index_Subtype, Drange);
9962 Set_Parent (Drange, N);
9963 Analyze_And_Resolve (Drange, Index_Type);
9965 -- In the context, the Index_Type may already have a constraint,
9966 -- so use common base type on string subtype. The base type may
9967 -- be used when generating attributes of the string, for example
9968 -- in the context of a slice assignment.
9970 Set_Etype (Index_Subtype, Base_Type (Index_Type));
9971 Set_Size_Info (Index_Subtype, Index_Type);
9972 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9974 Array_Subtype := Create_Itype (E_Array_Subtype, N);
9976 Index := New_Occurrence_Of (Index_Subtype, Loc);
9977 Set_Etype (Index, Index_Subtype);
9978 Append (Index, Index_List);
9980 Set_First_Index (Array_Subtype, Index);
9981 Set_Etype (Array_Subtype, Base_Type (Typ));
9982 Set_Is_Constrained (Array_Subtype, True);
9985 Make_Unchecked_Type_Conversion (Loc,
9986 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
9987 Expression => Relocate_Node (N)));
9988 Set_Etype (N, Array_Subtype);
9991 end Set_String_Literal_Subtype;
9993 ------------------------------
9994 -- Simplify_Type_Conversion --
9995 ------------------------------
9997 procedure Simplify_Type_Conversion (N : Node_Id) is
9999 if Nkind (N) = N_Type_Conversion then
10001 Operand : constant Node_Id := Expression (N);
10002 Target_Typ : constant Entity_Id := Etype (N);
10003 Opnd_Typ : constant Entity_Id := Etype (Operand);
10006 if Is_Floating_Point_Type (Opnd_Typ)
10008 (Is_Integer_Type (Target_Typ)
10009 or else (Is_Fixed_Point_Type (Target_Typ)
10010 and then Conversion_OK (N)))
10011 and then Nkind (Operand) = N_Attribute_Reference
10012 and then Attribute_Name (Operand) = Name_Truncation
10014 -- Special processing required if the conversion is the expression
10015 -- of a Truncation attribute reference. In this case we replace:
10017 -- ityp (ftyp'Truncation (x))
10023 -- with the Float_Truncate flag set, which is more efficient.
10027 Relocate_Node (First (Expressions (Operand))));
10028 Set_Float_Truncate (N, True);
10032 end Simplify_Type_Conversion;
10034 -----------------------------
10035 -- Unique_Fixed_Point_Type --
10036 -----------------------------
10038 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
10039 T1 : Entity_Id := Empty;
10044 procedure Fixed_Point_Error;
10045 -- Give error messages for true ambiguity. Messages are posted on node
10046 -- N, and entities T1, T2 are the possible interpretations.
10048 -----------------------
10049 -- Fixed_Point_Error --
10050 -----------------------
10052 procedure Fixed_Point_Error is
10054 Error_Msg_N ("ambiguous universal_fixed_expression", N);
10055 Error_Msg_NE ("\\possible interpretation as}", N, T1);
10056 Error_Msg_NE ("\\possible interpretation as}", N, T2);
10057 end Fixed_Point_Error;
10059 -- Start of processing for Unique_Fixed_Point_Type
10062 -- The operations on Duration are visible, so Duration is always a
10063 -- possible interpretation.
10065 T1 := Standard_Duration;
10067 -- Look for fixed-point types in enclosing scopes
10069 Scop := Current_Scope;
10070 while Scop /= Standard_Standard loop
10071 T2 := First_Entity (Scop);
10072 while Present (T2) loop
10073 if Is_Fixed_Point_Type (T2)
10074 and then Current_Entity (T2) = T2
10075 and then Scope (Base_Type (T2)) = Scop
10077 if Present (T1) then
10088 Scop := Scope (Scop);
10091 -- Look for visible fixed type declarations in the context
10093 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
10094 while Present (Item) loop
10095 if Nkind (Item) = N_With_Clause then
10096 Scop := Entity (Name (Item));
10097 T2 := First_Entity (Scop);
10098 while Present (T2) loop
10099 if Is_Fixed_Point_Type (T2)
10100 and then Scope (Base_Type (T2)) = Scop
10101 and then (Is_Potentially_Use_Visible (T2) or else In_Use (T2))
10103 if Present (T1) then
10118 if Nkind (N) = N_Real_Literal then
10119 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
10121 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
10125 end Unique_Fixed_Point_Type;
10127 ----------------------
10128 -- Valid_Conversion --
10129 ----------------------
10131 function Valid_Conversion
10133 Target : Entity_Id;
10134 Operand : Node_Id) return Boolean
10136 Target_Type : constant Entity_Id := Base_Type (Target);
10137 Opnd_Type : Entity_Id := Etype (Operand);
10139 function Conversion_Check
10141 Msg : String) return Boolean;
10142 -- Little routine to post Msg if Valid is False, returns Valid value
10144 function Valid_Tagged_Conversion
10145 (Target_Type : Entity_Id;
10146 Opnd_Type : Entity_Id) return Boolean;
10147 -- Specifically test for validity of tagged conversions
10149 function Valid_Array_Conversion return Boolean;
10150 -- Check index and component conformance, and accessibility levels if
10151 -- the component types are anonymous access types (Ada 2005).
10153 ----------------------
10154 -- Conversion_Check --
10155 ----------------------
10157 function Conversion_Check
10159 Msg : String) return Boolean
10163 Error_Msg_N (Msg, Operand);
10167 end Conversion_Check;
10169 ----------------------------
10170 -- Valid_Array_Conversion --
10171 ----------------------------
10173 function Valid_Array_Conversion return Boolean
10175 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
10176 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
10178 Opnd_Index : Node_Id;
10179 Opnd_Index_Type : Entity_Id;
10181 Target_Comp_Type : constant Entity_Id :=
10182 Component_Type (Target_Type);
10183 Target_Comp_Base : constant Entity_Id :=
10184 Base_Type (Target_Comp_Type);
10186 Target_Index : Node_Id;
10187 Target_Index_Type : Entity_Id;
10190 -- Error if wrong number of dimensions
10193 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
10196 ("incompatible number of dimensions for conversion", Operand);
10199 -- Number of dimensions matches
10202 -- Loop through indexes of the two arrays
10204 Target_Index := First_Index (Target_Type);
10205 Opnd_Index := First_Index (Opnd_Type);
10206 while Present (Target_Index) and then Present (Opnd_Index) loop
10207 Target_Index_Type := Etype (Target_Index);
10208 Opnd_Index_Type := Etype (Opnd_Index);
10210 -- Error if index types are incompatible
10212 if not (Is_Integer_Type (Target_Index_Type)
10213 and then Is_Integer_Type (Opnd_Index_Type))
10214 and then (Root_Type (Target_Index_Type)
10215 /= Root_Type (Opnd_Index_Type))
10218 ("incompatible index types for array conversion",
10223 Next_Index (Target_Index);
10224 Next_Index (Opnd_Index);
10227 -- If component types have same base type, all set
10229 if Target_Comp_Base = Opnd_Comp_Base then
10232 -- Here if base types of components are not the same. The only
10233 -- time this is allowed is if we have anonymous access types.
10235 -- The conversion of arrays of anonymous access types can lead
10236 -- to dangling pointers. AI-392 formalizes the accessibility
10237 -- checks that must be applied to such conversions to prevent
10238 -- out-of-scope references.
10241 (Target_Comp_Base, E_Anonymous_Access_Type,
10242 E_Anonymous_Access_Subprogram_Type)
10243 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
10245 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
10247 if Type_Access_Level (Target_Type) <
10248 Type_Access_Level (Opnd_Type)
10250 if In_Instance_Body then
10251 Error_Msg_N ("?source array type " &
10252 "has deeper accessibility level than target", Operand);
10253 Error_Msg_N ("\?Program_Error will be raised at run time",
10256 Make_Raise_Program_Error (Sloc (N),
10257 Reason => PE_Accessibility_Check_Failed));
10258 Set_Etype (N, Target_Type);
10261 -- Conversion not allowed because of accessibility levels
10264 Error_Msg_N ("source array type " &
10265 "has deeper accessibility level than target", Operand);
10273 -- All other cases where component base types do not match
10277 ("incompatible component types for array conversion",
10282 -- Check that component subtypes statically match. For numeric
10283 -- types this means that both must be either constrained or
10284 -- unconstrained. For enumeration types the bounds must match.
10285 -- All of this is checked in Subtypes_Statically_Match.
10287 if not Subtypes_Statically_Match
10288 (Target_Comp_Type, Opnd_Comp_Type)
10291 ("component subtypes must statically match", Operand);
10297 end Valid_Array_Conversion;
10299 -----------------------------
10300 -- Valid_Tagged_Conversion --
10301 -----------------------------
10303 function Valid_Tagged_Conversion
10304 (Target_Type : Entity_Id;
10305 Opnd_Type : Entity_Id) return Boolean
10308 -- Upward conversions are allowed (RM 4.6(22))
10310 if Covers (Target_Type, Opnd_Type)
10311 or else Is_Ancestor (Target_Type, Opnd_Type)
10315 -- Downward conversion are allowed if the operand is class-wide
10318 elsif Is_Class_Wide_Type (Opnd_Type)
10319 and then Covers (Opnd_Type, Target_Type)
10323 elsif Covers (Opnd_Type, Target_Type)
10324 or else Is_Ancestor (Opnd_Type, Target_Type)
10327 Conversion_Check (False,
10328 "downward conversion of tagged objects not allowed");
10330 -- Ada 2005 (AI-251): The conversion to/from interface types is
10333 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
10336 -- If the operand is a class-wide type obtained through a limited_
10337 -- with clause, and the context includes the non-limited view, use
10338 -- it to determine whether the conversion is legal.
10340 elsif Is_Class_Wide_Type (Opnd_Type)
10341 and then From_With_Type (Opnd_Type)
10342 and then Present (Non_Limited_View (Etype (Opnd_Type)))
10343 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
10347 elsif Is_Access_Type (Opnd_Type)
10348 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
10354 ("invalid tagged conversion, not compatible with}",
10355 N, First_Subtype (Opnd_Type));
10358 end Valid_Tagged_Conversion;
10360 -- Start of processing for Valid_Conversion
10363 Check_Parameterless_Call (Operand);
10365 if Is_Overloaded (Operand) then
10375 -- Remove procedure calls, which syntactically cannot appear in
10376 -- this context, but which cannot be removed by type checking,
10377 -- because the context does not impose a type.
10379 -- When compiling for VMS, spurious ambiguities can be produced
10380 -- when arithmetic operations have a literal operand and return
10381 -- System.Address or a descendant of it. These ambiguities are
10382 -- otherwise resolved by the context, but for conversions there
10383 -- is no context type and the removal of the spurious operations
10384 -- must be done explicitly here.
10386 -- The node may be labelled overloaded, but still contain only one
10387 -- interpretation because others were discarded earlier. If this
10388 -- is the case, retain the single interpretation if legal.
10390 Get_First_Interp (Operand, I, It);
10391 Opnd_Type := It.Typ;
10392 Get_Next_Interp (I, It);
10394 if Present (It.Typ)
10395 and then Opnd_Type /= Standard_Void_Type
10397 -- More than one candidate interpretation is available
10399 Get_First_Interp (Operand, I, It);
10400 while Present (It.Typ) loop
10401 if It.Typ = Standard_Void_Type then
10405 if Present (System_Aux_Id)
10406 and then Is_Descendent_Of_Address (It.Typ)
10411 Get_Next_Interp (I, It);
10415 Get_First_Interp (Operand, I, It);
10419 if No (It.Typ) then
10420 Error_Msg_N ("illegal operand in conversion", Operand);
10424 Get_Next_Interp (I, It);
10426 if Present (It.Typ) then
10429 It1 := Disambiguate (Operand, I1, I, Any_Type);
10431 if It1 = No_Interp then
10432 Error_Msg_N ("ambiguous operand in conversion", Operand);
10434 -- If the interpretation involves a standard operator, use
10435 -- the location of the type, which may be user-defined.
10437 if Sloc (It.Nam) = Standard_Location then
10438 Error_Msg_Sloc := Sloc (It.Typ);
10440 Error_Msg_Sloc := Sloc (It.Nam);
10443 Error_Msg_N -- CODEFIX
10444 ("\\possible interpretation#!", Operand);
10446 if Sloc (N1) = Standard_Location then
10447 Error_Msg_Sloc := Sloc (T1);
10449 Error_Msg_Sloc := Sloc (N1);
10452 Error_Msg_N -- CODEFIX
10453 ("\\possible interpretation#!", Operand);
10459 Set_Etype (Operand, It1.Typ);
10460 Opnd_Type := It1.Typ;
10466 if Is_Numeric_Type (Target_Type) then
10468 -- A universal fixed expression can be converted to any numeric type
10470 if Opnd_Type = Universal_Fixed then
10473 -- Also no need to check when in an instance or inlined body, because
10474 -- the legality has been established when the template was analyzed.
10475 -- Furthermore, numeric conversions may occur where only a private
10476 -- view of the operand type is visible at the instantiation point.
10477 -- This results in a spurious error if we check that the operand type
10478 -- is a numeric type.
10480 -- Note: in a previous version of this unit, the following tests were
10481 -- applied only for generated code (Comes_From_Source set to False),
10482 -- but in fact the test is required for source code as well, since
10483 -- this situation can arise in source code.
10485 elsif In_Instance or else In_Inlined_Body then
10488 -- Otherwise we need the conversion check
10491 return Conversion_Check
10492 (Is_Numeric_Type (Opnd_Type),
10493 "illegal operand for numeric conversion");
10498 elsif Is_Array_Type (Target_Type) then
10499 if not Is_Array_Type (Opnd_Type)
10500 or else Opnd_Type = Any_Composite
10501 or else Opnd_Type = Any_String
10503 Error_Msg_N ("illegal operand for array conversion", Operand);
10506 return Valid_Array_Conversion;
10509 -- Ada 2005 (AI-251): Anonymous access types where target references an
10512 elsif Ekind_In (Target_Type, E_General_Access_Type,
10513 E_Anonymous_Access_Type)
10514 and then Is_Interface (Directly_Designated_Type (Target_Type))
10516 -- Check the static accessibility rule of 4.6(17). Note that the
10517 -- check is not enforced when within an instance body, since the
10518 -- RM requires such cases to be caught at run time.
10520 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
10521 if Type_Access_Level (Opnd_Type) >
10522 Type_Access_Level (Target_Type)
10524 -- In an instance, this is a run-time check, but one we know
10525 -- will fail, so generate an appropriate warning. The raise
10526 -- will be generated by Expand_N_Type_Conversion.
10528 if In_Instance_Body then
10530 ("?cannot convert local pointer to non-local access type",
10533 ("\?Program_Error will be raised at run time", Operand);
10536 ("cannot convert local pointer to non-local access type",
10541 -- Special accessibility checks are needed in the case of access
10542 -- discriminants declared for a limited type.
10544 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10545 and then not Is_Local_Anonymous_Access (Opnd_Type)
10547 -- When the operand is a selected access discriminant the check
10548 -- needs to be made against the level of the object denoted by
10549 -- the prefix of the selected name (Object_Access_Level handles
10550 -- checking the prefix of the operand for this case).
10552 if Nkind (Operand) = N_Selected_Component
10553 and then Object_Access_Level (Operand) >
10554 Type_Access_Level (Target_Type)
10556 -- In an instance, this is a run-time check, but one we know
10557 -- will fail, so generate an appropriate warning. The raise
10558 -- will be generated by Expand_N_Type_Conversion.
10560 if In_Instance_Body then
10562 ("?cannot convert access discriminant to non-local" &
10563 " access type", Operand);
10565 ("\?Program_Error will be raised at run time", Operand);
10568 ("cannot convert access discriminant to non-local" &
10569 " access type", Operand);
10574 -- The case of a reference to an access discriminant from
10575 -- within a limited type declaration (which will appear as
10576 -- a discriminal) is always illegal because the level of the
10577 -- discriminant is considered to be deeper than any (nameable)
10580 if Is_Entity_Name (Operand)
10581 and then not Is_Local_Anonymous_Access (Opnd_Type)
10583 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10584 and then Present (Discriminal_Link (Entity (Operand)))
10587 ("discriminant has deeper accessibility level than target",
10596 -- General and anonymous access types
10598 elsif Ekind_In (Target_Type, E_General_Access_Type,
10599 E_Anonymous_Access_Type)
10602 (Is_Access_Type (Opnd_Type)
10604 Ekind_In (Opnd_Type, E_Access_Subprogram_Type,
10605 E_Access_Protected_Subprogram_Type),
10606 "must be an access-to-object type")
10608 if Is_Access_Constant (Opnd_Type)
10609 and then not Is_Access_Constant (Target_Type)
10612 ("access-to-constant operand type not allowed", Operand);
10616 -- Check the static accessibility rule of 4.6(17). Note that the
10617 -- check is not enforced when within an instance body, since the RM
10618 -- requires such cases to be caught at run time.
10620 if Ekind (Target_Type) /= E_Anonymous_Access_Type
10621 or else Is_Local_Anonymous_Access (Target_Type)
10623 if Type_Access_Level (Opnd_Type)
10624 > Type_Access_Level (Target_Type)
10626 -- In an instance, this is a run-time check, but one we know
10627 -- will fail, so generate an appropriate warning. The raise
10628 -- will be generated by Expand_N_Type_Conversion.
10630 if In_Instance_Body then
10632 ("?cannot convert local pointer to non-local access type",
10635 ("\?Program_Error will be raised at run time", Operand);
10638 -- Avoid generation of spurious error message
10640 if not Error_Posted (N) then
10642 ("cannot convert local pointer to non-local access type",
10649 -- Special accessibility checks are needed in the case of access
10650 -- discriminants declared for a limited type.
10652 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10653 and then not Is_Local_Anonymous_Access (Opnd_Type)
10655 -- When the operand is a selected access discriminant the check
10656 -- needs to be made against the level of the object denoted by
10657 -- the prefix of the selected name (Object_Access_Level handles
10658 -- checking the prefix of the operand for this case).
10660 if Nkind (Operand) = N_Selected_Component
10661 and then Object_Access_Level (Operand) >
10662 Type_Access_Level (Target_Type)
10664 -- In an instance, this is a run-time check, but one we know
10665 -- will fail, so generate an appropriate warning. The raise
10666 -- will be generated by Expand_N_Type_Conversion.
10668 if In_Instance_Body then
10670 ("?cannot convert access discriminant to non-local" &
10671 " access type", Operand);
10673 ("\?Program_Error will be raised at run time",
10678 ("cannot convert access discriminant to non-local" &
10679 " access type", Operand);
10684 -- The case of a reference to an access discriminant from
10685 -- within a limited type declaration (which will appear as
10686 -- a discriminal) is always illegal because the level of the
10687 -- discriminant is considered to be deeper than any (nameable)
10690 if Is_Entity_Name (Operand)
10692 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10693 and then Present (Discriminal_Link (Entity (Operand)))
10696 ("discriminant has deeper accessibility level than target",
10703 -- In the presence of limited_with clauses we have to use non-limited
10704 -- views, if available.
10706 Check_Limited : declare
10707 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
10708 -- Helper function to handle limited views
10710 --------------------------
10711 -- Full_Designated_Type --
10712 --------------------------
10714 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
10715 Desig : constant Entity_Id := Designated_Type (T);
10718 -- Handle the limited view of a type
10720 if Is_Incomplete_Type (Desig)
10721 and then From_With_Type (Desig)
10722 and then Present (Non_Limited_View (Desig))
10724 return Available_View (Desig);
10728 end Full_Designated_Type;
10730 -- Local Declarations
10732 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
10733 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
10735 Same_Base : constant Boolean :=
10736 Base_Type (Target) = Base_Type (Opnd);
10738 -- Start of processing for Check_Limited
10741 if Is_Tagged_Type (Target) then
10742 return Valid_Tagged_Conversion (Target, Opnd);
10745 if not Same_Base then
10747 ("target designated type not compatible with }",
10748 N, Base_Type (Opnd));
10751 -- Ada 2005 AI-384: legality rule is symmetric in both
10752 -- designated types. The conversion is legal (with possible
10753 -- constraint check) if either designated type is
10756 elsif Subtypes_Statically_Match (Target, Opnd)
10758 (Has_Discriminants (Target)
10760 (not Is_Constrained (Opnd)
10761 or else not Is_Constrained (Target)))
10763 -- Special case, if Value_Size has been used to make the
10764 -- sizes different, the conversion is not allowed even
10765 -- though the subtypes statically match.
10767 if Known_Static_RM_Size (Target)
10768 and then Known_Static_RM_Size (Opnd)
10769 and then RM_Size (Target) /= RM_Size (Opnd)
10772 ("target designated subtype not compatible with }",
10775 ("\because sizes of the two designated subtypes differ",
10779 -- Normal case where conversion is allowed
10787 ("target designated subtype not compatible with }",
10794 -- Access to subprogram types. If the operand is an access parameter,
10795 -- the type has a deeper accessibility that any master, and cannot be
10796 -- assigned. We must make an exception if the conversion is part of an
10797 -- assignment and the target is the return object of an extended return
10798 -- statement, because in that case the accessibility check takes place
10799 -- after the return.
10801 elsif Is_Access_Subprogram_Type (Target_Type)
10802 and then No (Corresponding_Remote_Type (Opnd_Type))
10804 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
10805 and then Is_Entity_Name (Operand)
10806 and then Ekind (Entity (Operand)) = E_In_Parameter
10808 (Nkind (Parent (N)) /= N_Assignment_Statement
10809 or else not Is_Entity_Name (Name (Parent (N)))
10810 or else not Is_Return_Object (Entity (Name (Parent (N)))))
10813 ("illegal attempt to store anonymous access to subprogram",
10816 ("\value has deeper accessibility than any master " &
10817 "(RM 3.10.2 (13))",
10821 ("\use named access type for& instead of access parameter",
10822 Operand, Entity (Operand));
10825 -- Check that the designated types are subtype conformant
10827 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
10828 Old_Id => Designated_Type (Opnd_Type),
10831 -- Check the static accessibility rule of 4.6(20)
10833 if Type_Access_Level (Opnd_Type) >
10834 Type_Access_Level (Target_Type)
10837 ("operand type has deeper accessibility level than target",
10840 -- Check that if the operand type is declared in a generic body,
10841 -- then the target type must be declared within that same body
10842 -- (enforces last sentence of 4.6(20)).
10844 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
10846 O_Gen : constant Node_Id :=
10847 Enclosing_Generic_Body (Opnd_Type);
10852 T_Gen := Enclosing_Generic_Body (Target_Type);
10853 while Present (T_Gen) and then T_Gen /= O_Gen loop
10854 T_Gen := Enclosing_Generic_Body (T_Gen);
10857 if T_Gen /= O_Gen then
10859 ("target type must be declared in same generic body"
10860 & " as operand type", N);
10867 -- Remote subprogram access types
10869 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
10870 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
10872 -- It is valid to convert from one RAS type to another provided
10873 -- that their specification statically match.
10875 Check_Subtype_Conformant
10877 Designated_Type (Corresponding_Remote_Type (Target_Type)),
10879 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
10884 -- If both are tagged types, check legality of view conversions
10886 elsif Is_Tagged_Type (Target_Type)
10888 Is_Tagged_Type (Opnd_Type)
10890 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
10892 -- Types derived from the same root type are convertible
10894 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
10897 -- In an instance or an inlined body, there may be inconsistent views of
10898 -- the same type, or of types derived from a common root.
10900 elsif (In_Instance or In_Inlined_Body)
10902 Root_Type (Underlying_Type (Target_Type)) =
10903 Root_Type (Underlying_Type (Opnd_Type))
10907 -- Special check for common access type error case
10909 elsif Ekind (Target_Type) = E_Access_Type
10910 and then Is_Access_Type (Opnd_Type)
10912 Error_Msg_N ("target type must be general access type!", N);
10913 Error_Msg_NE -- CODEFIX
10914 ("add ALL to }!", N, Target_Type);
10918 Error_Msg_NE ("invalid conversion, not compatible with }",
10922 end Valid_Conversion;