1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Debug_A; use Debug_A;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Ch6; use Exp_Ch6;
36 with Exp_Ch7; use Exp_Ch7;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Fname; use Fname;
40 with Freeze; use Freeze;
41 with Itypes; use Itypes;
43 with Lib.Xref; use Lib.Xref;
44 with Namet; use Namet;
45 with Nmake; use Nmake;
46 with Nlists; use Nlists;
48 with Output; use Output;
49 with Restrict; use Restrict;
50 with Rident; use Rident;
51 with Rtsfind; use Rtsfind;
53 with Sem_Aux; use Sem_Aux;
54 with Sem_Aggr; use Sem_Aggr;
55 with Sem_Attr; use Sem_Attr;
56 with Sem_Cat; use Sem_Cat;
57 with Sem_Ch4; use Sem_Ch4;
58 with Sem_Ch6; use Sem_Ch6;
59 with Sem_Ch8; use Sem_Ch8;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Elab; use Sem_Elab;
65 with Sem_Eval; use Sem_Eval;
66 with Sem_Intr; use Sem_Intr;
67 with Sem_Util; use Sem_Util;
68 with Sem_Type; use Sem_Type;
69 with Sem_Warn; use Sem_Warn;
70 with Sinfo; use Sinfo;
71 with Snames; use Snames;
72 with Stand; use Stand;
73 with Stringt; use Stringt;
74 with Style; use Style;
75 with Tbuild; use Tbuild;
76 with Uintp; use Uintp;
77 with Urealp; use Urealp;
79 package body Sem_Res is
81 -----------------------
82 -- Local Subprograms --
83 -----------------------
85 -- Second pass (top-down) type checking and overload resolution procedures
86 -- Typ is the type required by context. These procedures propagate the
87 -- type information recursively to the descendants of N. If the node
88 -- is not overloaded, its Etype is established in the first pass. If
89 -- overloaded, the Resolve routines set the correct type. For arith.
90 -- operators, the Etype is the base type of the context.
92 -- Note that Resolve_Attribute is separated off in Sem_Attr
94 function Bad_Unordered_Enumeration_Reference
96 T : Entity_Id) return Boolean;
97 -- Node N contains a potentially dubious reference to type T, either an
98 -- explicit comparison, or an explicit range. This function returns True
99 -- if the type T is an enumeration type for which No pragma Order has been
100 -- given, and the reference N is not in the same extended source unit as
101 -- the declaration of T.
103 procedure Check_Discriminant_Use (N : Node_Id);
104 -- Enforce the restrictions on the use of discriminants when constraining
105 -- a component of a discriminated type (record or concurrent type).
107 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
108 -- Given a node for an operator associated with type T, check that
109 -- the operator is visible. Operators all of whose operands are
110 -- universal must be checked for visibility during resolution
111 -- because their type is not determinable based on their operands.
113 procedure Check_Fully_Declared_Prefix
116 -- Check that the type of the prefix of a dereference is not incomplete
118 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
119 -- Given a call node, N, which is known to occur immediately within the
120 -- subprogram being called, determines whether it is a detectable case of
121 -- an infinite recursion, and if so, outputs appropriate messages. Returns
122 -- True if an infinite recursion is detected, and False otherwise.
124 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
125 -- If the type of the object being initialized uses the secondary stack
126 -- directly or indirectly, create a transient scope for the call to the
127 -- init proc. This is because we do not create transient scopes for the
128 -- initialization of individual components within the init proc itself.
129 -- Could be optimized away perhaps?
131 procedure Check_No_Direct_Boolean_Operators (N : Node_Id);
132 -- N is the node for a logical operator. If the operator is predefined, and
133 -- the root type of the operands is Standard.Boolean, then a check is made
134 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
135 -- the style check for Style_Check_Boolean_And_Or.
137 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
138 -- Determine whether E is an access type declared by an access
139 -- declaration, and not an (anonymous) allocator type.
141 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
142 -- Utility to check whether the entity for an operator is a predefined
143 -- operator, in which case the expression is left as an operator in the
144 -- tree (else it is rewritten into a call). An instance of an intrinsic
145 -- conversion operation may be given an operator name, but is not treated
146 -- like an operator. Note that an operator that is an imported back-end
147 -- builtin has convention Intrinsic, but is expected to be rewritten into
148 -- a call, so such an operator is not treated as predefined by this
151 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
152 -- If a default expression in entry call N depends on the discriminants
153 -- of the task, it must be replaced with a reference to the discriminant
154 -- of the task being called.
156 procedure Resolve_Op_Concat_Arg
161 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
162 -- concatenation operator. The operand is either of the array type or of
163 -- the component type. If the operand is an aggregate, and the component
164 -- type is composite, this is ambiguous if component type has aggregates.
166 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
167 -- Does the first part of the work of Resolve_Op_Concat
169 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
170 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
171 -- has been resolved. See Resolve_Op_Concat for details.
173 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
174 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
175 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
176 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id);
177 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
178 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
179 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
180 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
185 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
186 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
187 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
188 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
189 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
190 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
191 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
192 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
193 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
194 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
195 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
196 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
197 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
198 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
199 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
200 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
201 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
202 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
203 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
204 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
205 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
206 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
208 function Operator_Kind
210 Is_Binary : Boolean) return Node_Kind;
211 -- Utility to map the name of an operator into the corresponding Node. Used
212 -- by other node rewriting procedures.
214 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
215 -- Resolve actuals of call, and add default expressions for missing ones.
216 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
217 -- called subprogram.
219 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
220 -- Called from Resolve_Call, when the prefix denotes an entry or element
221 -- of entry family. Actuals are resolved as for subprograms, and the node
222 -- is rebuilt as an entry call. Also called for protected operations. Typ
223 -- is the context type, which is used when the operation is a protected
224 -- function with no arguments, and the return value is indexed.
226 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
227 -- A call to a user-defined intrinsic operator is rewritten as a call
228 -- to the corresponding predefined operator, with suitable conversions.
229 -- Note that this applies only for intrinsic operators that denote
230 -- predefined operators, not operators that are intrinsic imports of
231 -- back-end builtins.
233 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
234 -- Ditto, for unary operators (arithmetic ones and "not" on signed
235 -- integer types for VMS).
237 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
238 -- If an operator node resolves to a call to a user-defined operator,
239 -- rewrite the node as a function call.
241 procedure Make_Call_Into_Operator
245 -- Inverse transformation: if an operator is given in functional notation,
246 -- then after resolving the node, transform into an operator node, so
247 -- that operands are resolved properly. Recall that predefined operators
248 -- do not have a full signature and special resolution rules apply.
250 procedure Rewrite_Renamed_Operator
254 -- An operator can rename another, e.g. in an instantiation. In that
255 -- case, the proper operator node must be constructed and resolved.
257 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
258 -- The String_Literal_Subtype is built for all strings that are not
259 -- operands of a static concatenation operation. If the argument is
260 -- not a N_String_Literal node, then the call has no effect.
262 procedure Set_Slice_Subtype (N : Node_Id);
263 -- Build subtype of array type, with the range specified by the slice
265 procedure Simplify_Type_Conversion (N : Node_Id);
266 -- Called after N has been resolved and evaluated, but before range checks
267 -- have been applied. Currently simplifies a combination of floating-point
268 -- to integer conversion and Truncation attribute.
270 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
271 -- A universal_fixed expression in an universal context is unambiguous
272 -- if there is only one applicable fixed point type. Determining whether
273 -- there is only one requires a search over all visible entities, and
274 -- happens only in very pathological cases (see 6115-006).
276 function Valid_Conversion
279 Operand : Node_Id) return Boolean;
280 -- Verify legality rules given in 4.6 (8-23). Target is the target
281 -- type of the conversion, which may be an implicit conversion of
282 -- an actual parameter to an anonymous access type (in which case
283 -- N denotes the actual parameter and N = Operand).
285 -------------------------
286 -- Ambiguous_Character --
287 -------------------------
289 procedure Ambiguous_Character (C : Node_Id) is
293 if Nkind (C) = N_Character_Literal then
294 Error_Msg_N ("ambiguous character literal", C);
296 -- First the ones in Standard
298 Error_Msg_N ("\\possible interpretation: Character!", C);
299 Error_Msg_N ("\\possible interpretation: Wide_Character!", C);
301 -- Include Wide_Wide_Character in Ada 2005 mode
303 if Ada_Version >= Ada_05 then
304 Error_Msg_N ("\\possible interpretation: Wide_Wide_Character!", C);
307 -- Now any other types that match
309 E := Current_Entity (C);
310 while Present (E) loop
311 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
315 end Ambiguous_Character;
317 -------------------------
318 -- Analyze_And_Resolve --
319 -------------------------
321 procedure Analyze_And_Resolve (N : Node_Id) is
325 end Analyze_And_Resolve;
327 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
331 end Analyze_And_Resolve;
333 -- Version withs check(s) suppressed
335 procedure Analyze_And_Resolve
340 Scop : constant Entity_Id := Current_Scope;
343 if Suppress = All_Checks then
345 Svg : constant Suppress_Array := Scope_Suppress;
347 Scope_Suppress := (others => True);
348 Analyze_And_Resolve (N, Typ);
349 Scope_Suppress := Svg;
354 Svg : constant Boolean := Scope_Suppress (Suppress);
357 Scope_Suppress (Suppress) := True;
358 Analyze_And_Resolve (N, Typ);
359 Scope_Suppress (Suppress) := Svg;
363 if Current_Scope /= Scop
364 and then Scope_Is_Transient
366 -- This can only happen if a transient scope was created
367 -- for an inner expression, which will be removed upon
368 -- completion of the analysis of an enclosing construct.
369 -- The transient scope must have the suppress status of
370 -- the enclosing environment, not of this Analyze call.
372 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
375 end Analyze_And_Resolve;
377 procedure Analyze_And_Resolve
381 Scop : constant Entity_Id := Current_Scope;
384 if Suppress = All_Checks then
386 Svg : constant Suppress_Array := Scope_Suppress;
388 Scope_Suppress := (others => True);
389 Analyze_And_Resolve (N);
390 Scope_Suppress := Svg;
395 Svg : constant Boolean := Scope_Suppress (Suppress);
398 Scope_Suppress (Suppress) := True;
399 Analyze_And_Resolve (N);
400 Scope_Suppress (Suppress) := Svg;
404 if Current_Scope /= Scop
405 and then Scope_Is_Transient
407 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
410 end Analyze_And_Resolve;
412 ----------------------------------------
413 -- Bad_Unordered_Enumeration_Reference --
414 ----------------------------------------
416 function Bad_Unordered_Enumeration_Reference
418 T : Entity_Id) return Boolean
421 return Is_Enumeration_Type (T)
422 and then Comes_From_Source (N)
423 and then Warn_On_Unordered_Enumeration_Type
424 and then not Has_Pragma_Ordered (T)
425 and then not In_Same_Extended_Unit (N, T);
426 end Bad_Unordered_Enumeration_Reference;
428 ----------------------------
429 -- Check_Discriminant_Use --
430 ----------------------------
432 procedure Check_Discriminant_Use (N : Node_Id) is
433 PN : constant Node_Id := Parent (N);
434 Disc : constant Entity_Id := Entity (N);
439 -- Any use in a spec-expression is legal
441 if In_Spec_Expression then
444 elsif Nkind (PN) = N_Range then
446 -- Discriminant cannot be used to constrain a scalar type
450 if Nkind (P) = N_Range_Constraint
451 and then Nkind (Parent (P)) = N_Subtype_Indication
452 and then Nkind (Parent (Parent (P))) = N_Component_Definition
454 Error_Msg_N ("discriminant cannot constrain scalar type", N);
456 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
458 -- The following check catches the unusual case where
459 -- a discriminant appears within an index constraint
460 -- that is part of a larger expression within a constraint
461 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
462 -- For now we only check case of record components, and
463 -- note that a similar check should also apply in the
464 -- 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
507 -- any array whose index type covered the whole range of
508 -- the type 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.
553 -- First find the array
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
621 -- (i.e. a 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
636 -- of a scalar type, an Itype is created and the bounds are attached
637 -- to its range, not to the original subtype indication. Such use
638 -- is of 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_05
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
733 -- of 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,
825 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
826 and then C /= First (Statements (P))
828 -- If the call is the expression of a return statement and the
829 -- actuals are identical to the formals, it's worth a warning.
830 -- However, we skip this if there is an immediately preceding
831 -- raise statement, since the call is never executed.
833 -- Furthermore, this corresponds to a common idiom:
835 -- function F (L : Thing) return Boolean is
837 -- raise Program_Error;
841 -- for generating a stub function
843 if Nkind (Parent (N)) = N_Simple_Return_Statement
844 and then Same_Argument_List
846 exit when not Is_List_Member (Parent (N));
848 -- OK, return statement is in a statement list, look for raise
854 -- Skip past N_Freeze_Entity nodes generated by expansion
856 Nod := Prev (Parent (N));
858 and then Nkind (Nod) = N_Freeze_Entity
863 -- If no raise statement, give warning
865 exit when Nkind (Nod) /= N_Raise_Statement
867 (Nkind (Nod) not in N_Raise_xxx_Error
868 or else Present (Condition (Nod)));
879 Error_Msg_N ("!?possible infinite recursion", N);
880 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
883 end Check_Infinite_Recursion;
885 -------------------------------
886 -- Check_Initialization_Call --
887 -------------------------------
889 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
890 Typ : constant Entity_Id := Etype (First_Formal (Nam));
892 function Uses_SS (T : Entity_Id) return Boolean;
893 -- Check whether the creation of an object of the type will involve
894 -- use of the secondary stack. If T is a record type, this is true
895 -- if the expression for some component uses the secondary stack, e.g.
896 -- through a call to a function that returns an unconstrained value.
897 -- False if T is controlled, because cleanups occur elsewhere.
903 function Uses_SS (T : Entity_Id) return Boolean is
906 Full_Type : Entity_Id := Underlying_Type (T);
909 -- Normally we want to use the underlying type, but if it's not set
910 -- then continue with T.
912 if not Present (Full_Type) then
916 if Is_Controlled (Full_Type) then
919 elsif Is_Array_Type (Full_Type) then
920 return Uses_SS (Component_Type (Full_Type));
922 elsif Is_Record_Type (Full_Type) then
923 Comp := First_Component (Full_Type);
924 while Present (Comp) loop
925 if Ekind (Comp) = E_Component
926 and then Nkind (Parent (Comp)) = N_Component_Declaration
928 -- The expression for a dynamic component may be rewritten
929 -- as a dereference, so retrieve original node.
931 Expr := Original_Node (Expression (Parent (Comp)));
933 -- Return True if the expression is a call to a function
934 -- (including an attribute function such as Image, or a
935 -- user-defined operator) with a result that requires a
938 if (Nkind (Expr) = N_Function_Call
939 or else Nkind (Expr) in N_Op
940 or else (Nkind (Expr) = N_Attribute_Reference
941 and then Present (Expressions (Expr))))
942 and then Requires_Transient_Scope (Etype (Expr))
946 elsif Uses_SS (Etype (Comp)) then
951 Next_Component (Comp);
961 -- Start of processing for Check_Initialization_Call
964 -- Establish a transient scope if the type needs it
966 if Uses_SS (Typ) then
967 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
969 end Check_Initialization_Call;
971 ---------------------------------------
972 -- Check_No_Direct_Boolean_Operators --
973 ---------------------------------------
975 procedure Check_No_Direct_Boolean_Operators (N : Node_Id) is
977 if Scope (Entity (N)) = Standard_Standard
978 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
980 -- Restriction only applies to original source code
982 if Comes_From_Source (N) then
983 Check_Restriction (No_Direct_Boolean_Operators, N);
988 Check_Boolean_Operator (N);
990 end Check_No_Direct_Boolean_Operators;
992 ------------------------------
993 -- Check_Parameterless_Call --
994 ------------------------------
996 procedure Check_Parameterless_Call (N : Node_Id) is
999 function Prefix_Is_Access_Subp return Boolean;
1000 -- If the prefix is of an access_to_subprogram type, the node must be
1001 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1002 -- interpretations are access to subprograms.
1004 ---------------------------
1005 -- Prefix_Is_Access_Subp --
1006 ---------------------------
1008 function Prefix_Is_Access_Subp return Boolean is
1013 if not Is_Overloaded (N) then
1015 Ekind (Etype (N)) = E_Subprogram_Type
1016 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
1018 Get_First_Interp (N, I, It);
1019 while Present (It.Typ) loop
1020 if Ekind (It.Typ) /= E_Subprogram_Type
1021 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
1026 Get_Next_Interp (I, It);
1031 end Prefix_Is_Access_Subp;
1033 -- Start of processing for Check_Parameterless_Call
1036 -- Defend against junk stuff if errors already detected
1038 if Total_Errors_Detected /= 0 then
1039 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
1041 elsif Nkind (N) in N_Has_Chars
1042 and then Chars (N) in Error_Name_Or_No_Name
1050 -- If the context expects a value, and the name is a procedure, this is
1051 -- most likely a missing 'Access. Don't try to resolve the parameterless
1052 -- call, error will be caught when the outer call is analyzed.
1054 if Is_Entity_Name (N)
1055 and then Ekind (Entity (N)) = E_Procedure
1056 and then not Is_Overloaded (N)
1058 Nkind_In (Parent (N), N_Parameter_Association,
1060 N_Procedure_Call_Statement)
1065 -- Rewrite as call if overloadable entity that is (or could be, in the
1066 -- overloaded case) a function call. If we know for sure that the entity
1067 -- is an enumeration literal, we do not rewrite it.
1069 if (Is_Entity_Name (N)
1070 and then Is_Overloadable (Entity (N))
1071 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1072 or else Is_Overloaded (N)))
1074 -- Rewrite as call if it is an explicit dereference of an expression of
1075 -- a subprogram access type, and the subprogram type is not that of a
1076 -- procedure or entry.
1079 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1081 -- Rewrite as call if it is a selected component which is a function,
1082 -- this is the case of a call to a protected function (which may be
1083 -- overloaded with other protected operations).
1086 (Nkind (N) = N_Selected_Component
1087 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1089 (Ekind_In (Entity (Selector_Name (N)), E_Entry,
1091 and then Is_Overloaded (Selector_Name (N)))))
1093 -- If one of the above three conditions is met, rewrite as call.
1094 -- Apply the rewriting only once.
1097 if Nkind (Parent (N)) /= N_Function_Call
1098 or else N /= Name (Parent (N))
1100 Nam := New_Copy (N);
1102 -- If overloaded, overload set belongs to new copy
1104 Save_Interps (N, Nam);
1106 -- Change node to parameterless function call (note that the
1107 -- Parameter_Associations associations field is left set to Empty,
1108 -- its normal default value since there are no parameters)
1110 Change_Node (N, N_Function_Call);
1112 Set_Sloc (N, Sloc (Nam));
1116 elsif Nkind (N) = N_Parameter_Association then
1117 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1119 end Check_Parameterless_Call;
1121 -----------------------------
1122 -- Is_Definite_Access_Type --
1123 -----------------------------
1125 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1126 Btyp : constant Entity_Id := Base_Type (E);
1128 return Ekind (Btyp) = E_Access_Type
1129 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1130 and then Comes_From_Source (Btyp));
1131 end Is_Definite_Access_Type;
1133 ----------------------
1134 -- Is_Predefined_Op --
1135 ----------------------
1137 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1139 -- Predefined operators are intrinsic subprograms
1141 if not Is_Intrinsic_Subprogram (Nam) then
1145 -- A call to a back-end builtin is never a predefined operator
1147 if Is_Imported (Nam) and then Present (Interface_Name (Nam)) then
1151 return not Is_Generic_Instance (Nam)
1152 and then Chars (Nam) in Any_Operator_Name
1153 and then (No (Alias (Nam)) or else Is_Predefined_Op (Alias (Nam)));
1154 end Is_Predefined_Op;
1156 -----------------------------
1157 -- Make_Call_Into_Operator --
1158 -----------------------------
1160 procedure Make_Call_Into_Operator
1165 Op_Name : constant Name_Id := Chars (Op_Id);
1166 Act1 : Node_Id := First_Actual (N);
1167 Act2 : Node_Id := Next_Actual (Act1);
1168 Error : Boolean := False;
1169 Func : constant Entity_Id := Entity (Name (N));
1170 Is_Binary : constant Boolean := Present (Act2);
1172 Opnd_Type : Entity_Id;
1173 Orig_Type : Entity_Id := Empty;
1176 type Kind_Test is access function (E : Entity_Id) return Boolean;
1178 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1179 -- If the operand is not universal, and the operator is given by a
1180 -- expanded name, verify that the operand has an interpretation with
1181 -- a type defined in the given scope of the operator.
1183 function Type_In_P (Test : Kind_Test) return Entity_Id;
1184 -- Find a type of the given class in the package Pack that contains
1187 ---------------------------
1188 -- Operand_Type_In_Scope --
1189 ---------------------------
1191 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1192 Nod : constant Node_Id := Right_Opnd (Op_Node);
1197 if not Is_Overloaded (Nod) then
1198 return Scope (Base_Type (Etype (Nod))) = S;
1201 Get_First_Interp (Nod, I, It);
1202 while Present (It.Typ) loop
1203 if Scope (Base_Type (It.Typ)) = S then
1207 Get_Next_Interp (I, It);
1212 end Operand_Type_In_Scope;
1218 function Type_In_P (Test : Kind_Test) return Entity_Id is
1221 function In_Decl return Boolean;
1222 -- Verify that node is not part of the type declaration for the
1223 -- candidate type, which would otherwise be invisible.
1229 function In_Decl return Boolean is
1230 Decl_Node : constant Node_Id := Parent (E);
1236 if Etype (E) = Any_Type then
1239 elsif No (Decl_Node) then
1244 and then Nkind (N2) /= N_Compilation_Unit
1246 if N2 = Decl_Node then
1257 -- Start of processing for Type_In_P
1260 -- If the context type is declared in the prefix package, this
1261 -- is the desired base type.
1263 if Scope (Base_Type (Typ)) = Pack
1266 return Base_Type (Typ);
1269 E := First_Entity (Pack);
1270 while Present (E) loop
1272 and then not In_Decl
1284 -- Start of processing for Make_Call_Into_Operator
1287 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1292 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1293 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1294 Save_Interps (Act1, Left_Opnd (Op_Node));
1295 Save_Interps (Act2, Right_Opnd (Op_Node));
1296 Act1 := Left_Opnd (Op_Node);
1297 Act2 := Right_Opnd (Op_Node);
1302 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1303 Save_Interps (Act1, Right_Opnd (Op_Node));
1304 Act1 := Right_Opnd (Op_Node);
1307 -- If the operator is denoted by an expanded name, and the prefix is
1308 -- not Standard, but the operator is a predefined one whose scope is
1309 -- Standard, then this is an implicit_operator, inserted as an
1310 -- interpretation by the procedure of the same name. This procedure
1311 -- overestimates the presence of implicit operators, because it does
1312 -- not examine the type of the operands. Verify now that the operand
1313 -- type appears in the given scope. If right operand is universal,
1314 -- check the other operand. In the case of concatenation, either
1315 -- argument can be the component type, so check the type of the result.
1316 -- If both arguments are literals, look for a type of the right kind
1317 -- defined in the given scope. This elaborate nonsense is brought to
1318 -- you courtesy of b33302a. The type itself must be frozen, so we must
1319 -- find the type of the proper class in the given scope.
1321 -- A final wrinkle is the multiplication operator for fixed point types,
1322 -- which is defined in Standard only, and not in the scope of the
1323 -- fixed_point type itself.
1325 if Nkind (Name (N)) = N_Expanded_Name then
1326 Pack := Entity (Prefix (Name (N)));
1328 -- If the entity being called is defined in the given package, it is
1329 -- a renaming of a predefined operator, and known to be legal.
1331 if Scope (Entity (Name (N))) = Pack
1332 and then Pack /= Standard_Standard
1336 -- Visibility does not need to be checked in an instance: if the
1337 -- operator was not visible in the generic it has been diagnosed
1338 -- already, else there is an implicit copy of it in the instance.
1340 elsif In_Instance then
1343 elsif (Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide)
1344 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1345 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1347 if Pack /= Standard_Standard then
1351 -- Ada 2005, AI-420: Predefined equality on Universal_Access is
1354 elsif Ada_Version >= Ada_05
1355 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1356 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1361 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1363 if Op_Name = Name_Op_Concat then
1364 Opnd_Type := Base_Type (Typ);
1366 elsif (Scope (Opnd_Type) = Standard_Standard
1368 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1370 and then not Comes_From_Source (Opnd_Type))
1372 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1375 if Scope (Opnd_Type) = Standard_Standard then
1377 -- Verify that the scope contains a type that corresponds to
1378 -- the given literal. Optimize the case where Pack is Standard.
1380 if Pack /= Standard_Standard then
1382 if Opnd_Type = Universal_Integer then
1383 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1385 elsif Opnd_Type = Universal_Real then
1386 Orig_Type := Type_In_P (Is_Real_Type'Access);
1388 elsif Opnd_Type = Any_String then
1389 Orig_Type := Type_In_P (Is_String_Type'Access);
1391 elsif Opnd_Type = Any_Access then
1392 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1394 elsif Opnd_Type = Any_Composite then
1395 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1397 if Present (Orig_Type) then
1398 if Has_Private_Component (Orig_Type) then
1401 Set_Etype (Act1, Orig_Type);
1404 Set_Etype (Act2, Orig_Type);
1413 Error := No (Orig_Type);
1416 elsif Ekind (Opnd_Type) = E_Allocator_Type
1417 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1421 -- If the type is defined elsewhere, and the operator is not
1422 -- defined in the given scope (by a renaming declaration, e.g.)
1423 -- then this is an error as well. If an extension of System is
1424 -- present, and the type may be defined there, Pack must be
1427 elsif Scope (Opnd_Type) /= Pack
1428 and then Scope (Op_Id) /= Pack
1429 and then (No (System_Aux_Id)
1430 or else Scope (Opnd_Type) /= System_Aux_Id
1431 or else Pack /= Scope (System_Aux_Id))
1433 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1436 Error := not Operand_Type_In_Scope (Pack);
1439 elsif Pack = Standard_Standard
1440 and then not Operand_Type_In_Scope (Standard_Standard)
1447 Error_Msg_Node_2 := Pack;
1449 ("& not declared in&", N, Selector_Name (Name (N)));
1450 Set_Etype (N, Any_Type);
1453 -- Detect a mismatch between the context type and the result type
1454 -- in the named package, which is otherwise not detected if the
1455 -- operands are universal. Check is only needed if source entity is
1456 -- an operator, not a function that renames an operator.
1458 elsif Nkind (Parent (N)) /= N_Type_Conversion
1459 and then Ekind (Entity (Name (N))) = E_Operator
1460 and then Is_Numeric_Type (Typ)
1461 and then not Is_Universal_Numeric_Type (Typ)
1462 and then Scope (Base_Type (Typ)) /= Pack
1463 and then not In_Instance
1465 if Is_Fixed_Point_Type (Typ)
1466 and then (Op_Name = Name_Op_Multiply
1468 Op_Name = Name_Op_Divide)
1470 -- Already checked above
1474 -- Operator may be defined in an extension of System
1476 elsif Present (System_Aux_Id)
1477 and then Scope (Opnd_Type) = System_Aux_Id
1482 -- Could we use Wrong_Type here??? (this would require setting
1483 -- Etype (N) to the actual type found where Typ was expected).
1485 Error_Msg_NE ("expect }", N, Typ);
1490 Set_Chars (Op_Node, Op_Name);
1492 if not Is_Private_Type (Etype (N)) then
1493 Set_Etype (Op_Node, Base_Type (Etype (N)));
1495 Set_Etype (Op_Node, Etype (N));
1498 -- If this is a call to a function that renames a predefined equality,
1499 -- the renaming declaration provides a type that must be used to
1500 -- resolve the operands. This must be done now because resolution of
1501 -- the equality node will not resolve any remaining ambiguity, and it
1502 -- assumes that the first operand is not overloaded.
1504 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1505 and then Ekind (Func) = E_Function
1506 and then Is_Overloaded (Act1)
1508 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1509 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1512 Set_Entity (Op_Node, Op_Id);
1513 Generate_Reference (Op_Id, N, ' ');
1515 -- Do rewrite setting Comes_From_Source on the result if the original
1516 -- call came from source. Although it is not strictly the case that the
1517 -- operator as such comes from the source, logically it corresponds
1518 -- exactly to the function call in the source, so it should be marked
1519 -- this way (e.g. to make sure that validity checks work fine).
1522 CS : constant Boolean := Comes_From_Source (N);
1524 Rewrite (N, Op_Node);
1525 Set_Comes_From_Source (N, CS);
1528 -- If this is an arithmetic operator and the result type is private,
1529 -- the operands and the result must be wrapped in conversion to
1530 -- expose the underlying numeric type and expand the proper checks,
1531 -- e.g. on division.
1533 if Is_Private_Type (Typ) then
1535 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1536 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1537 Resolve_Intrinsic_Operator (N, Typ);
1539 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1540 Resolve_Intrinsic_Unary_Operator (N, Typ);
1548 end Make_Call_Into_Operator;
1554 function Operator_Kind
1556 Is_Binary : Boolean) return Node_Kind
1562 if Op_Name = Name_Op_And then
1564 elsif Op_Name = Name_Op_Or then
1566 elsif Op_Name = Name_Op_Xor then
1568 elsif Op_Name = Name_Op_Eq then
1570 elsif Op_Name = Name_Op_Ne then
1572 elsif Op_Name = Name_Op_Lt then
1574 elsif Op_Name = Name_Op_Le then
1576 elsif Op_Name = Name_Op_Gt then
1578 elsif Op_Name = Name_Op_Ge then
1580 elsif Op_Name = Name_Op_Add then
1582 elsif Op_Name = Name_Op_Subtract then
1583 Kind := N_Op_Subtract;
1584 elsif Op_Name = Name_Op_Concat then
1585 Kind := N_Op_Concat;
1586 elsif Op_Name = Name_Op_Multiply then
1587 Kind := N_Op_Multiply;
1588 elsif Op_Name = Name_Op_Divide then
1589 Kind := N_Op_Divide;
1590 elsif Op_Name = Name_Op_Mod then
1592 elsif Op_Name = Name_Op_Rem then
1594 elsif Op_Name = Name_Op_Expon then
1597 raise Program_Error;
1603 if Op_Name = Name_Op_Add then
1605 elsif Op_Name = Name_Op_Subtract then
1607 elsif Op_Name = Name_Op_Abs then
1609 elsif Op_Name = Name_Op_Not then
1612 raise Program_Error;
1619 ----------------------------
1620 -- Preanalyze_And_Resolve --
1621 ----------------------------
1623 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1624 Save_Full_Analysis : constant Boolean := Full_Analysis;
1627 Full_Analysis := False;
1628 Expander_Mode_Save_And_Set (False);
1630 -- We suppress all checks for this analysis, since the checks will
1631 -- be applied properly, and in the right location, when the default
1632 -- expression is reanalyzed and reexpanded later on.
1634 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1636 Expander_Mode_Restore;
1637 Full_Analysis := Save_Full_Analysis;
1638 end Preanalyze_And_Resolve;
1640 -- Version without context type
1642 procedure Preanalyze_And_Resolve (N : Node_Id) is
1643 Save_Full_Analysis : constant Boolean := Full_Analysis;
1646 Full_Analysis := False;
1647 Expander_Mode_Save_And_Set (False);
1650 Resolve (N, Etype (N), Suppress => All_Checks);
1652 Expander_Mode_Restore;
1653 Full_Analysis := Save_Full_Analysis;
1654 end Preanalyze_And_Resolve;
1656 ----------------------------------
1657 -- Replace_Actual_Discriminants --
1658 ----------------------------------
1660 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1661 Loc : constant Source_Ptr := Sloc (N);
1662 Tsk : Node_Id := Empty;
1664 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1670 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1674 if Nkind (Nod) = N_Identifier then
1675 Ent := Entity (Nod);
1678 and then Ekind (Ent) = E_Discriminant
1681 Make_Selected_Component (Loc,
1682 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1683 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1685 Set_Etype (Nod, Etype (Ent));
1693 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1695 -- Start of processing for Replace_Actual_Discriminants
1698 if not Expander_Active then
1702 if Nkind (Name (N)) = N_Selected_Component then
1703 Tsk := Prefix (Name (N));
1705 elsif Nkind (Name (N)) = N_Indexed_Component then
1706 Tsk := Prefix (Prefix (Name (N)));
1712 Replace_Discrs (Default);
1714 end Replace_Actual_Discriminants;
1720 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1721 Ambiguous : Boolean := False;
1722 Ctx_Type : Entity_Id := Typ;
1723 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1724 Err_Type : Entity_Id := Empty;
1725 Found : Boolean := False;
1728 I1 : Interp_Index := 0; -- prevent junk warning
1731 Seen : Entity_Id := Empty; -- prevent junk warning
1733 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1734 -- Determine whether a node comes from a predefined library unit or
1737 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1738 -- Try and fix up a literal so that it matches its expected type. New
1739 -- literals are manufactured if necessary to avoid cascaded errors.
1741 procedure Report_Ambiguous_Argument;
1742 -- Additional diagnostics when an ambiguous call has an ambiguous
1743 -- argument (typically a controlling actual).
1745 procedure Resolution_Failed;
1746 -- Called when attempt at resolving current expression fails
1748 ------------------------------------
1749 -- Comes_From_Predefined_Lib_Unit --
1750 -------------------------------------
1752 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1755 Sloc (Nod) = Standard_Location
1756 or else Is_Predefined_File_Name (Unit_File_Name (
1757 Get_Source_Unit (Sloc (Nod))));
1758 end Comes_From_Predefined_Lib_Unit;
1760 --------------------
1761 -- Patch_Up_Value --
1762 --------------------
1764 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1766 if Nkind (N) = N_Integer_Literal
1767 and then Is_Real_Type (Typ)
1770 Make_Real_Literal (Sloc (N),
1771 Realval => UR_From_Uint (Intval (N))));
1772 Set_Etype (N, Universal_Real);
1773 Set_Is_Static_Expression (N);
1775 elsif Nkind (N) = N_Real_Literal
1776 and then Is_Integer_Type (Typ)
1779 Make_Integer_Literal (Sloc (N),
1780 Intval => UR_To_Uint (Realval (N))));
1781 Set_Etype (N, Universal_Integer);
1782 Set_Is_Static_Expression (N);
1784 elsif Nkind (N) = N_String_Literal
1785 and then Is_Character_Type (Typ)
1787 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1789 Make_Character_Literal (Sloc (N),
1791 Char_Literal_Value =>
1792 UI_From_Int (Character'Pos ('A'))));
1793 Set_Etype (N, Any_Character);
1794 Set_Is_Static_Expression (N);
1796 elsif Nkind (N) /= N_String_Literal
1797 and then Is_String_Type (Typ)
1800 Make_String_Literal (Sloc (N),
1801 Strval => End_String));
1803 elsif Nkind (N) = N_Range then
1804 Patch_Up_Value (Low_Bound (N), Typ);
1805 Patch_Up_Value (High_Bound (N), Typ);
1809 -------------------------------
1810 -- Report_Ambiguous_Argument --
1811 -------------------------------
1813 procedure Report_Ambiguous_Argument is
1814 Arg : constant Node_Id := First (Parameter_Associations (N));
1819 if Nkind (Arg) = N_Function_Call
1820 and then Is_Entity_Name (Name (Arg))
1821 and then Is_Overloaded (Name (Arg))
1823 Error_Msg_NE ("ambiguous call to&", Arg, Name (Arg));
1825 -- Could use comments on what is going on here ???
1827 Get_First_Interp (Name (Arg), I, It);
1828 while Present (It.Nam) loop
1829 Error_Msg_Sloc := Sloc (It.Nam);
1831 if Nkind (Parent (It.Nam)) = N_Full_Type_Declaration then
1832 Error_Msg_N ("interpretation (inherited) #!", Arg);
1834 Error_Msg_N ("interpretation #!", Arg);
1837 Get_Next_Interp (I, It);
1840 end Report_Ambiguous_Argument;
1842 -----------------------
1843 -- Resolution_Failed --
1844 -----------------------
1846 procedure Resolution_Failed is
1848 Patch_Up_Value (N, Typ);
1850 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1851 Set_Is_Overloaded (N, False);
1853 -- The caller will return without calling the expander, so we need
1854 -- to set the analyzed flag. Note that it is fine to set Analyzed
1855 -- to True even if we are in the middle of a shallow analysis,
1856 -- (see the spec of sem for more details) since this is an error
1857 -- situation anyway, and there is no point in repeating the
1858 -- analysis later (indeed it won't work to repeat it later, since
1859 -- we haven't got a clear resolution of which entity is being
1862 Set_Analyzed (N, True);
1864 end Resolution_Failed;
1866 -- Start of processing for Resolve
1873 -- Access attribute on remote subprogram cannot be used for
1874 -- a non-remote access-to-subprogram type.
1876 if Nkind (N) = N_Attribute_Reference
1877 and then (Attribute_Name (N) = Name_Access
1878 or else Attribute_Name (N) = Name_Unrestricted_Access
1879 or else Attribute_Name (N) = Name_Unchecked_Access)
1880 and then Comes_From_Source (N)
1881 and then Is_Entity_Name (Prefix (N))
1882 and then Is_Subprogram (Entity (Prefix (N)))
1883 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1884 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1887 ("prefix must statically denote a non-remote subprogram", N);
1890 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1892 -- If the context is a Remote_Access_To_Subprogram, access attributes
1893 -- must be resolved with the corresponding fat pointer. There is no need
1894 -- to check for the attribute name since the return type of an
1895 -- attribute is never a remote type.
1897 if Nkind (N) = N_Attribute_Reference
1898 and then Comes_From_Source (N)
1899 and then (Is_Remote_Call_Interface (Typ)
1900 or else Is_Remote_Types (Typ))
1903 Attr : constant Attribute_Id :=
1904 Get_Attribute_Id (Attribute_Name (N));
1905 Pref : constant Node_Id := Prefix (N);
1908 Is_Remote : Boolean := True;
1911 -- Check that Typ is a remote access-to-subprogram type
1913 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1915 -- Prefix (N) must statically denote a remote subprogram
1916 -- declared in a package specification.
1918 if Attr = Attribute_Access then
1919 Decl := Unit_Declaration_Node (Entity (Pref));
1921 if Nkind (Decl) = N_Subprogram_Body then
1922 Spec := Corresponding_Spec (Decl);
1924 if not No (Spec) then
1925 Decl := Unit_Declaration_Node (Spec);
1929 Spec := Parent (Decl);
1931 if not Is_Entity_Name (Prefix (N))
1932 or else Nkind (Spec) /= N_Package_Specification
1934 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1938 ("prefix must statically denote a remote subprogram ",
1943 -- If we are generating code for a distributed program.
1944 -- perform semantic checks against the corresponding
1947 if (Attr = Attribute_Access
1948 or else Attr = Attribute_Unchecked_Access
1949 or else Attr = Attribute_Unrestricted_Access)
1950 and then Expander_Active
1951 and then Get_PCS_Name /= Name_No_DSA
1953 Check_Subtype_Conformant
1954 (New_Id => Entity (Prefix (N)),
1955 Old_Id => Designated_Type
1956 (Corresponding_Remote_Type (Typ)),
1960 Process_Remote_AST_Attribute (N, Typ);
1967 Debug_A_Entry ("resolving ", N);
1969 if Comes_From_Source (N) then
1970 if Is_Fixed_Point_Type (Typ) then
1971 Check_Restriction (No_Fixed_Point, N);
1973 elsif Is_Floating_Point_Type (Typ)
1974 and then Typ /= Universal_Real
1975 and then Typ /= Any_Real
1977 Check_Restriction (No_Floating_Point, N);
1981 -- Return if already analyzed
1983 if Analyzed (N) then
1984 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1987 -- Return if type = Any_Type (previous error encountered)
1989 elsif Etype (N) = Any_Type then
1990 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1994 Check_Parameterless_Call (N);
1996 -- If not overloaded, then we know the type, and all that needs doing
1997 -- is to check that this type is compatible with the context.
1999 if not Is_Overloaded (N) then
2000 Found := Covers (Typ, Etype (N));
2001 Expr_Type := Etype (N);
2003 -- In the overloaded case, we must select the interpretation that
2004 -- is compatible with the context (i.e. the type passed to Resolve)
2007 -- Loop through possible interpretations
2009 Get_First_Interp (N, I, It);
2010 Interp_Loop : while Present (It.Typ) loop
2012 -- We are only interested in interpretations that are compatible
2013 -- with the expected type, any other interpretations are ignored.
2015 if not Covers (Typ, It.Typ) then
2016 if Debug_Flag_V then
2017 Write_Str (" interpretation incompatible with context");
2022 -- Skip the current interpretation if it is disabled by an
2023 -- abstract operator. This action is performed only when the
2024 -- type against which we are resolving is the same as the
2025 -- type of the interpretation.
2027 if Ada_Version >= Ada_05
2028 and then It.Typ = Typ
2029 and then Typ /= Universal_Integer
2030 and then Typ /= Universal_Real
2031 and then Present (It.Abstract_Op)
2036 -- First matching interpretation
2042 Expr_Type := It.Typ;
2044 -- Matching interpretation that is not the first, maybe an
2045 -- error, but there are some cases where preference rules are
2046 -- used to choose between the two possibilities. These and
2047 -- some more obscure cases are handled in Disambiguate.
2050 -- If the current statement is part of a predefined library
2051 -- unit, then all interpretations which come from user level
2052 -- packages should not be considered.
2055 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
2060 Error_Msg_Sloc := Sloc (Seen);
2061 It1 := Disambiguate (N, I1, I, Typ);
2063 -- Disambiguation has succeeded. Skip the remaining
2066 if It1 /= No_Interp then
2068 Expr_Type := It1.Typ;
2070 while Present (It.Typ) loop
2071 Get_Next_Interp (I, It);
2075 -- Before we issue an ambiguity complaint, check for
2076 -- the case of a subprogram call where at least one
2077 -- of the arguments is Any_Type, and if so, suppress
2078 -- the message, since it is a cascaded error.
2080 if Nkind_In (N, N_Function_Call,
2081 N_Procedure_Call_Statement)
2088 A := First_Actual (N);
2089 while Present (A) loop
2092 if Nkind (E) = N_Parameter_Association then
2093 E := Explicit_Actual_Parameter (E);
2096 if Etype (E) = Any_Type then
2097 if Debug_Flag_V then
2098 Write_Str ("Any_Type in call");
2109 elsif Nkind (N) in N_Binary_Op
2110 and then (Etype (Left_Opnd (N)) = Any_Type
2111 or else Etype (Right_Opnd (N)) = Any_Type)
2115 elsif Nkind (N) in N_Unary_Op
2116 and then Etype (Right_Opnd (N)) = Any_Type
2121 -- Not that special case, so issue message using the
2122 -- flag Ambiguous to control printing of the header
2123 -- message only at the start of an ambiguous set.
2125 if not Ambiguous then
2126 if Nkind (N) = N_Function_Call
2127 and then Nkind (Name (N)) = N_Explicit_Dereference
2130 ("ambiguous expression "
2131 & "(cannot resolve indirect call)!", N);
2133 Error_Msg_NE -- CODEFIX
2134 ("ambiguous expression (cannot resolve&)!",
2140 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2142 ("\\possible interpretation (inherited)#!", N);
2144 Error_Msg_N -- CODEFIX
2145 ("\\possible interpretation#!", N);
2149 (N, N_Procedure_Call_Statement, N_Function_Call)
2150 and then Present (Parameter_Associations (N))
2152 Report_Ambiguous_Argument;
2156 Error_Msg_Sloc := Sloc (It.Nam);
2158 -- By default, the error message refers to the candidate
2159 -- interpretation. But if it is a predefined operator, it
2160 -- is implicitly declared at the declaration of the type
2161 -- of the operand. Recover the sloc of that declaration
2162 -- for the error message.
2164 if Nkind (N) in N_Op
2165 and then Scope (It.Nam) = Standard_Standard
2166 and then not Is_Overloaded (Right_Opnd (N))
2167 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2170 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2172 if Comes_From_Source (Err_Type)
2173 and then Present (Parent (Err_Type))
2175 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2178 elsif Nkind (N) in N_Binary_Op
2179 and then Scope (It.Nam) = Standard_Standard
2180 and then not Is_Overloaded (Left_Opnd (N))
2181 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2184 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2186 if Comes_From_Source (Err_Type)
2187 and then Present (Parent (Err_Type))
2189 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2192 -- If this is an indirect call, use the subprogram_type
2193 -- in the message, to have a meaningful location.
2194 -- Also indicate if this is an inherited operation,
2195 -- created by a type declaration.
2197 elsif Nkind (N) = N_Function_Call
2198 and then Nkind (Name (N)) = N_Explicit_Dereference
2199 and then Is_Type (It.Nam)
2203 Sloc (Associated_Node_For_Itype (Err_Type));
2208 if Nkind (N) in N_Op
2209 and then Scope (It.Nam) = Standard_Standard
2210 and then Present (Err_Type)
2212 -- Special-case the message for universal_fixed
2213 -- operators, which are not declared with the type
2214 -- of the operand, but appear forever in Standard.
2216 if It.Typ = Universal_Fixed
2217 and then Scope (It.Nam) = Standard_Standard
2220 ("\\possible interpretation as " &
2221 "universal_fixed operation " &
2222 "(RM 4.5.5 (19))", N);
2225 ("\\possible interpretation (predefined)#!", N);
2229 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2232 ("\\possible interpretation (inherited)#!", N);
2234 Error_Msg_N -- CODEFIX
2235 ("\\possible interpretation#!", N);
2241 -- We have a matching interpretation, Expr_Type is the type
2242 -- from this interpretation, and Seen is the entity.
2244 -- For an operator, just set the entity name. The type will be
2245 -- set by the specific operator resolution routine.
2247 if Nkind (N) in N_Op then
2248 Set_Entity (N, Seen);
2249 Generate_Reference (Seen, N);
2251 elsif Nkind (N) = N_Case_Expression then
2252 Set_Etype (N, Expr_Type);
2254 elsif Nkind (N) = N_Character_Literal then
2255 Set_Etype (N, Expr_Type);
2257 elsif Nkind (N) = N_Conditional_Expression then
2258 Set_Etype (N, Expr_Type);
2260 -- For an explicit dereference, attribute reference, range,
2261 -- short-circuit form (which is not an operator node), or call
2262 -- with a name that is an explicit dereference, there is
2263 -- nothing to be done at this point.
2265 elsif Nkind_In (N, N_Explicit_Dereference,
2266 N_Attribute_Reference,
2268 N_Indexed_Component,
2271 N_Selected_Component,
2273 or else Nkind (Name (N)) = N_Explicit_Dereference
2277 -- For procedure or function calls, set the type of the name,
2278 -- and also the entity pointer for the prefix.
2280 elsif Nkind_In (N, N_Procedure_Call_Statement, N_Function_Call)
2281 and then (Is_Entity_Name (Name (N))
2282 or else Nkind (Name (N)) = N_Operator_Symbol)
2284 Set_Etype (Name (N), Expr_Type);
2285 Set_Entity (Name (N), Seen);
2286 Generate_Reference (Seen, Name (N));
2288 elsif Nkind (N) = N_Function_Call
2289 and then Nkind (Name (N)) = N_Selected_Component
2291 Set_Etype (Name (N), Expr_Type);
2292 Set_Entity (Selector_Name (Name (N)), Seen);
2293 Generate_Reference (Seen, Selector_Name (Name (N)));
2295 -- For all other cases, just set the type of the Name
2298 Set_Etype (Name (N), Expr_Type);
2305 -- Move to next interpretation
2307 exit Interp_Loop when No (It.Typ);
2309 Get_Next_Interp (I, It);
2310 end loop Interp_Loop;
2313 -- At this stage Found indicates whether or not an acceptable
2314 -- interpretation exists. If not, then we have an error, except that if
2315 -- the context is Any_Type as a result of some other error, then we
2316 -- suppress the error report.
2319 if Typ /= Any_Type then
2321 -- If type we are looking for is Void, then this is the procedure
2322 -- call case, and the error is simply that what we gave is not a
2323 -- procedure name (we think of procedure calls as expressions with
2324 -- types internally, but the user doesn't think of them this way!)
2326 if Typ = Standard_Void_Type then
2328 -- Special case message if function used as a procedure
2330 if Nkind (N) = N_Procedure_Call_Statement
2331 and then Is_Entity_Name (Name (N))
2332 and then Ekind (Entity (Name (N))) = E_Function
2335 ("cannot use function & in a procedure call",
2336 Name (N), Entity (Name (N)));
2338 -- Otherwise give general message (not clear what cases this
2339 -- covers, but no harm in providing for them!)
2342 Error_Msg_N ("expect procedure name in procedure call", N);
2347 -- Otherwise we do have a subexpression with the wrong type
2349 -- Check for the case of an allocator which uses an access type
2350 -- instead of the designated type. This is a common error and we
2351 -- specialize the message, posting an error on the operand of the
2352 -- allocator, complaining that we expected the designated type of
2355 elsif Nkind (N) = N_Allocator
2356 and then Ekind (Typ) in Access_Kind
2357 and then Ekind (Etype (N)) in Access_Kind
2358 and then Designated_Type (Etype (N)) = Typ
2360 Wrong_Type (Expression (N), Designated_Type (Typ));
2363 -- Check for view mismatch on Null in instances, for which the
2364 -- view-swapping mechanism has no identifier.
2366 elsif (In_Instance or else In_Inlined_Body)
2367 and then (Nkind (N) = N_Null)
2368 and then Is_Private_Type (Typ)
2369 and then Is_Access_Type (Full_View (Typ))
2371 Resolve (N, Full_View (Typ));
2375 -- Check for an aggregate. Sometimes we can get bogus aggregates
2376 -- from misuse of parentheses, and we are about to complain about
2377 -- the aggregate without even looking inside it.
2379 -- Instead, if we have an aggregate of type Any_Composite, then
2380 -- analyze and resolve the component fields, and then only issue
2381 -- another message if we get no errors doing this (otherwise
2382 -- assume that the errors in the aggregate caused the problem).
2384 elsif Nkind (N) = N_Aggregate
2385 and then Etype (N) = Any_Composite
2387 -- Disable expansion in any case. If there is a type mismatch
2388 -- it may be fatal to try to expand the aggregate. The flag
2389 -- would otherwise be set to false when the error is posted.
2391 Expander_Active := False;
2394 procedure Check_Aggr (Aggr : Node_Id);
2395 -- Check one aggregate, and set Found to True if we have a
2396 -- definite error in any of its elements
2398 procedure Check_Elmt (Aelmt : Node_Id);
2399 -- Check one element of aggregate and set Found to True if
2400 -- we definitely have an error in the element.
2406 procedure Check_Aggr (Aggr : Node_Id) is
2410 if Present (Expressions (Aggr)) then
2411 Elmt := First (Expressions (Aggr));
2412 while Present (Elmt) loop
2418 if Present (Component_Associations (Aggr)) then
2419 Elmt := First (Component_Associations (Aggr));
2420 while Present (Elmt) loop
2422 -- If this is a default-initialized component, then
2423 -- there is nothing to check. The box will be
2424 -- replaced by the appropriate call during late
2427 if not Box_Present (Elmt) then
2428 Check_Elmt (Expression (Elmt));
2440 procedure Check_Elmt (Aelmt : Node_Id) is
2442 -- If we have a nested aggregate, go inside it (to
2443 -- attempt a naked analyze-resolve of the aggregate
2444 -- can cause undesirable cascaded errors). Do not
2445 -- resolve expression if it needs a type from context,
2446 -- as for integer * fixed expression.
2448 if Nkind (Aelmt) = N_Aggregate then
2454 if not Is_Overloaded (Aelmt)
2455 and then Etype (Aelmt) /= Any_Fixed
2460 if Etype (Aelmt) = Any_Type then
2471 -- If an error message was issued already, Found got reset
2472 -- to True, so if it is still False, issue the standard
2473 -- Wrong_Type message.
2476 if Is_Overloaded (N)
2477 and then Nkind (N) = N_Function_Call
2480 Subp_Name : Node_Id;
2482 if Is_Entity_Name (Name (N)) then
2483 Subp_Name := Name (N);
2485 elsif Nkind (Name (N)) = N_Selected_Component then
2487 -- Protected operation: retrieve operation name
2489 Subp_Name := Selector_Name (Name (N));
2491 raise Program_Error;
2494 Error_Msg_Node_2 := Typ;
2495 Error_Msg_NE ("no visible interpretation of&" &
2496 " matches expected type&", N, Subp_Name);
2499 if All_Errors_Mode then
2501 Index : Interp_Index;
2505 Error_Msg_N ("\\possible interpretations:", N);
2507 Get_First_Interp (Name (N), Index, It);
2508 while Present (It.Nam) loop
2509 Error_Msg_Sloc := Sloc (It.Nam);
2510 Error_Msg_Node_2 := It.Nam;
2512 ("\\ type& for & declared#", N, It.Typ);
2513 Get_Next_Interp (Index, It);
2518 Error_Msg_N ("\use -gnatf for details", N);
2521 Wrong_Type (N, Typ);
2529 -- Test if we have more than one interpretation for the context
2531 elsif Ambiguous then
2535 -- Here we have an acceptable interpretation for the context
2538 -- Propagate type information and normalize tree for various
2539 -- predefined operations. If the context only imposes a class of
2540 -- types, rather than a specific type, propagate the actual type
2543 if Typ = Any_Integer
2544 or else Typ = Any_Boolean
2545 or else Typ = Any_Modular
2546 or else Typ = Any_Real
2547 or else Typ = Any_Discrete
2549 Ctx_Type := Expr_Type;
2551 -- Any_Fixed is legal in a real context only if a specific
2552 -- fixed point type is imposed. If Norman Cohen can be
2553 -- confused by this, it deserves a separate message.
2556 and then Expr_Type = Any_Fixed
2558 Error_Msg_N ("illegal context for mixed mode operation", N);
2559 Set_Etype (N, Universal_Real);
2560 Ctx_Type := Universal_Real;
2564 -- A user-defined operator is transformed into a function call at
2565 -- this point, so that further processing knows that operators are
2566 -- really operators (i.e. are predefined operators). User-defined
2567 -- operators that are intrinsic are just renamings of the predefined
2568 -- ones, and need not be turned into calls either, but if they rename
2569 -- a different operator, we must transform the node accordingly.
2570 -- Instantiations of Unchecked_Conversion are intrinsic but are
2571 -- treated as functions, even if given an operator designator.
2573 if Nkind (N) in N_Op
2574 and then Present (Entity (N))
2575 and then Ekind (Entity (N)) /= E_Operator
2578 if not Is_Predefined_Op (Entity (N)) then
2579 Rewrite_Operator_As_Call (N, Entity (N));
2581 elsif Present (Alias (Entity (N)))
2583 Nkind (Parent (Parent (Entity (N)))) =
2584 N_Subprogram_Renaming_Declaration
2586 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2588 -- If the node is rewritten, it will be fully resolved in
2589 -- Rewrite_Renamed_Operator.
2591 if Analyzed (N) then
2597 case N_Subexpr'(Nkind (N)) is
2599 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2601 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2603 when N_Short_Circuit
2604 => Resolve_Short_Circuit (N, Ctx_Type);
2606 when N_Attribute_Reference
2607 => Resolve_Attribute (N, Ctx_Type);
2609 when N_Case_Expression
2610 => Resolve_Case_Expression (N, Ctx_Type);
2612 when N_Character_Literal
2613 => Resolve_Character_Literal (N, Ctx_Type);
2615 when N_Conditional_Expression
2616 => Resolve_Conditional_Expression (N, Ctx_Type);
2618 when N_Expanded_Name
2619 => Resolve_Entity_Name (N, Ctx_Type);
2621 when N_Explicit_Dereference
2622 => Resolve_Explicit_Dereference (N, Ctx_Type);
2624 when N_Expression_With_Actions
2625 => Resolve_Expression_With_Actions (N, Ctx_Type);
2627 when N_Extension_Aggregate
2628 => Resolve_Extension_Aggregate (N, Ctx_Type);
2630 when N_Function_Call
2631 => Resolve_Call (N, Ctx_Type);
2634 => Resolve_Entity_Name (N, Ctx_Type);
2636 when N_Indexed_Component
2637 => Resolve_Indexed_Component (N, Ctx_Type);
2639 when N_Integer_Literal
2640 => Resolve_Integer_Literal (N, Ctx_Type);
2642 when N_Membership_Test
2643 => Resolve_Membership_Op (N, Ctx_Type);
2645 when N_Null => Resolve_Null (N, Ctx_Type);
2647 when N_Op_And | N_Op_Or | N_Op_Xor
2648 => Resolve_Logical_Op (N, Ctx_Type);
2650 when N_Op_Eq | N_Op_Ne
2651 => Resolve_Equality_Op (N, Ctx_Type);
2653 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2654 => Resolve_Comparison_Op (N, Ctx_Type);
2656 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2658 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2659 N_Op_Divide | N_Op_Mod | N_Op_Rem
2661 => Resolve_Arithmetic_Op (N, Ctx_Type);
2663 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2665 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2667 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2668 => Resolve_Unary_Op (N, Ctx_Type);
2670 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2672 when N_Procedure_Call_Statement
2673 => Resolve_Call (N, Ctx_Type);
2675 when N_Operator_Symbol
2676 => Resolve_Operator_Symbol (N, Ctx_Type);
2678 when N_Qualified_Expression
2679 => Resolve_Qualified_Expression (N, Ctx_Type);
2681 when N_Raise_xxx_Error
2682 => Set_Etype (N, Ctx_Type);
2684 when N_Range => Resolve_Range (N, Ctx_Type);
2687 => Resolve_Real_Literal (N, Ctx_Type);
2689 when N_Reference => Resolve_Reference (N, Ctx_Type);
2691 when N_Selected_Component
2692 => Resolve_Selected_Component (N, Ctx_Type);
2694 when N_Slice => Resolve_Slice (N, Ctx_Type);
2696 when N_String_Literal
2697 => Resolve_String_Literal (N, Ctx_Type);
2699 when N_Subprogram_Info
2700 => Resolve_Subprogram_Info (N, Ctx_Type);
2702 when N_Type_Conversion
2703 => Resolve_Type_Conversion (N, Ctx_Type);
2705 when N_Unchecked_Expression =>
2706 Resolve_Unchecked_Expression (N, Ctx_Type);
2708 when N_Unchecked_Type_Conversion =>
2709 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2712 -- If the subexpression was replaced by a non-subexpression, then
2713 -- all we do is to expand it. The only legitimate case we know of
2714 -- is converting procedure call statement to entry call statements,
2715 -- but there may be others, so we are making this test general.
2717 if Nkind (N) not in N_Subexpr then
2718 Debug_A_Exit ("resolving ", N, " (done)");
2723 -- The expression is definitely NOT overloaded at this point, so
2724 -- we reset the Is_Overloaded flag to avoid any confusion when
2725 -- reanalyzing the node.
2727 Set_Is_Overloaded (N, False);
2729 -- Freeze expression type, entity if it is a name, and designated
2730 -- type if it is an allocator (RM 13.14(10,11,13)).
2732 -- Now that the resolution of the type of the node is complete,
2733 -- and we did not detect an error, we can expand this node. We
2734 -- skip the expand call if we are in a default expression, see
2735 -- section "Handling of Default Expressions" in Sem spec.
2737 Debug_A_Exit ("resolving ", N, " (done)");
2739 -- We unconditionally freeze the expression, even if we are in
2740 -- default expression mode (the Freeze_Expression routine tests
2741 -- this flag and only freezes static types if it is set).
2743 Freeze_Expression (N);
2745 -- Now we can do the expansion
2755 -- Version with check(s) suppressed
2757 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2759 if Suppress = All_Checks then
2761 Svg : constant Suppress_Array := Scope_Suppress;
2763 Scope_Suppress := (others => True);
2765 Scope_Suppress := Svg;
2770 Svg : constant Boolean := Scope_Suppress (Suppress);
2772 Scope_Suppress (Suppress) := True;
2774 Scope_Suppress (Suppress) := Svg;
2783 -- Version with implicit type
2785 procedure Resolve (N : Node_Id) is
2787 Resolve (N, Etype (N));
2790 ---------------------
2791 -- Resolve_Actuals --
2792 ---------------------
2794 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2795 Loc : constant Source_Ptr := Sloc (N);
2800 Prev : Node_Id := Empty;
2803 procedure Check_Argument_Order;
2804 -- Performs a check for the case where the actuals are all simple
2805 -- identifiers that correspond to the formal names, but in the wrong
2806 -- order, which is considered suspicious and cause for a warning.
2808 procedure Check_Prefixed_Call;
2809 -- If the original node is an overloaded call in prefix notation,
2810 -- insert an 'Access or a dereference as needed over the first actual.
2811 -- Try_Object_Operation has already verified that there is a valid
2812 -- interpretation, but the form of the actual can only be determined
2813 -- once the primitive operation is identified.
2815 procedure Insert_Default;
2816 -- If the actual is missing in a call, insert in the actuals list
2817 -- an instance of the default expression. The insertion is always
2818 -- a named association.
2820 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2821 -- Check whether T1 and T2, or their full views, are derived from a
2822 -- common type. Used to enforce the restrictions on array conversions
2825 function Static_Concatenation (N : Node_Id) return Boolean;
2826 -- Predicate to determine whether an actual that is a concatenation
2827 -- will be evaluated statically and does not need a transient scope.
2828 -- This must be determined before the actual is resolved and expanded
2829 -- because if needed the transient scope must be introduced earlier.
2831 --------------------------
2832 -- Check_Argument_Order --
2833 --------------------------
2835 procedure Check_Argument_Order is
2837 -- Nothing to do if no parameters, or original node is neither a
2838 -- function call nor a procedure call statement (happens in the
2839 -- operator-transformed-to-function call case), or the call does
2840 -- not come from source, or this warning is off.
2842 if not Warn_On_Parameter_Order
2844 No (Parameter_Associations (N))
2846 not Nkind_In (Original_Node (N), N_Procedure_Call_Statement,
2849 not Comes_From_Source (N)
2855 Nargs : constant Nat := List_Length (Parameter_Associations (N));
2858 -- Nothing to do if only one parameter
2864 -- Here if at least two arguments
2867 Actuals : array (1 .. Nargs) of Node_Id;
2871 Wrong_Order : Boolean := False;
2872 -- Set True if an out of order case is found
2875 -- Collect identifier names of actuals, fail if any actual is
2876 -- not a simple identifier, and record max length of name.
2878 Actual := First (Parameter_Associations (N));
2879 for J in Actuals'Range loop
2880 if Nkind (Actual) /= N_Identifier then
2883 Actuals (J) := Actual;
2888 -- If we got this far, all actuals are identifiers and the list
2889 -- of their names is stored in the Actuals array.
2891 Formal := First_Formal (Nam);
2892 for J in Actuals'Range loop
2894 -- If we ran out of formals, that's odd, probably an error
2895 -- which will be detected elsewhere, but abandon the search.
2901 -- If name matches and is in order OK
2903 if Chars (Formal) = Chars (Actuals (J)) then
2907 -- If no match, see if it is elsewhere in list and if so
2908 -- flag potential wrong order if type is compatible.
2910 for K in Actuals'Range loop
2911 if Chars (Formal) = Chars (Actuals (K))
2913 Has_Compatible_Type (Actuals (K), Etype (Formal))
2915 Wrong_Order := True;
2925 <<Continue>> Next_Formal (Formal);
2928 -- If Formals left over, also probably an error, skip warning
2930 if Present (Formal) then
2934 -- Here we give the warning if something was out of order
2938 ("actuals for this call may be in wrong order?", N);
2942 end Check_Argument_Order;
2944 -------------------------
2945 -- Check_Prefixed_Call --
2946 -------------------------
2948 procedure Check_Prefixed_Call is
2949 Act : constant Node_Id := First_Actual (N);
2950 A_Type : constant Entity_Id := Etype (Act);
2951 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
2952 Orig : constant Node_Id := Original_Node (N);
2956 -- Check whether the call is a prefixed call, with or without
2957 -- additional actuals.
2959 if Nkind (Orig) = N_Selected_Component
2961 (Nkind (Orig) = N_Indexed_Component
2962 and then Nkind (Prefix (Orig)) = N_Selected_Component
2963 and then Is_Entity_Name (Prefix (Prefix (Orig)))
2964 and then Is_Entity_Name (Act)
2965 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
2967 if Is_Access_Type (A_Type)
2968 and then not Is_Access_Type (F_Type)
2970 -- Introduce dereference on object in prefix
2973 Make_Explicit_Dereference (Sloc (Act),
2974 Prefix => Relocate_Node (Act));
2975 Rewrite (Act, New_A);
2978 elsif Is_Access_Type (F_Type)
2979 and then not Is_Access_Type (A_Type)
2981 -- Introduce an implicit 'Access in prefix
2983 if not Is_Aliased_View (Act) then
2985 ("object in prefixed call to& must be aliased"
2986 & " (RM-2005 4.3.1 (13))",
2991 Make_Attribute_Reference (Loc,
2992 Attribute_Name => Name_Access,
2993 Prefix => Relocate_Node (Act)));
2998 end Check_Prefixed_Call;
3000 --------------------
3001 -- Insert_Default --
3002 --------------------
3004 procedure Insert_Default is
3009 -- Missing argument in call, nothing to insert
3011 if No (Default_Value (F)) then
3015 -- Note that we do a full New_Copy_Tree, so that any associated
3016 -- Itypes are properly copied. This may not be needed any more,
3017 -- but it does no harm as a safety measure! Defaults of a generic
3018 -- formal may be out of bounds of the corresponding actual (see
3019 -- cc1311b) and an additional check may be required.
3024 New_Scope => Current_Scope,
3027 if Is_Concurrent_Type (Scope (Nam))
3028 and then Has_Discriminants (Scope (Nam))
3030 Replace_Actual_Discriminants (N, Actval);
3033 if Is_Overloadable (Nam)
3034 and then Present (Alias (Nam))
3036 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
3037 and then not Is_Tagged_Type (Etype (F))
3039 -- If default is a real literal, do not introduce a
3040 -- conversion whose effect may depend on the run-time
3041 -- size of universal real.
3043 if Nkind (Actval) = N_Real_Literal then
3044 Set_Etype (Actval, Base_Type (Etype (F)));
3046 Actval := Unchecked_Convert_To (Etype (F), Actval);
3050 if Is_Scalar_Type (Etype (F)) then
3051 Enable_Range_Check (Actval);
3054 Set_Parent (Actval, N);
3056 -- Resolve aggregates with their base type, to avoid scope
3057 -- anomalies: the subtype was first built in the subprogram
3058 -- declaration, and the current call may be nested.
3060 if Nkind (Actval) = N_Aggregate then
3061 Analyze_And_Resolve (Actval, Etype (F));
3063 Analyze_And_Resolve (Actval, Etype (Actval));
3067 Set_Parent (Actval, N);
3069 -- See note above concerning aggregates
3071 if Nkind (Actval) = N_Aggregate
3072 and then Has_Discriminants (Etype (Actval))
3074 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
3076 -- Resolve entities with their own type, which may differ
3077 -- from the type of a reference in a generic context (the
3078 -- view swapping mechanism did not anticipate the re-analysis
3079 -- of default values in calls).
3081 elsif Is_Entity_Name (Actval) then
3082 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
3085 Analyze_And_Resolve (Actval, Etype (Actval));
3089 -- If default is a tag indeterminate function call, propagate
3090 -- tag to obtain proper dispatching.
3092 if Is_Controlling_Formal (F)
3093 and then Nkind (Default_Value (F)) = N_Function_Call
3095 Set_Is_Controlling_Actual (Actval);
3100 -- If the default expression raises constraint error, then just
3101 -- silently replace it with an N_Raise_Constraint_Error node,
3102 -- since we already gave the warning on the subprogram spec.
3104 if Raises_Constraint_Error (Actval) then
3106 Make_Raise_Constraint_Error (Loc,
3107 Reason => CE_Range_Check_Failed));
3108 Set_Raises_Constraint_Error (Actval);
3109 Set_Etype (Actval, Etype (F));
3113 Make_Parameter_Association (Loc,
3114 Explicit_Actual_Parameter => Actval,
3115 Selector_Name => Make_Identifier (Loc, Chars (F)));
3117 -- Case of insertion is first named actual
3119 if No (Prev) or else
3120 Nkind (Parent (Prev)) /= N_Parameter_Association
3122 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
3123 Set_First_Named_Actual (N, Actval);
3126 if No (Parameter_Associations (N)) then
3127 Set_Parameter_Associations (N, New_List (Assoc));
3129 Append (Assoc, Parameter_Associations (N));
3133 Insert_After (Prev, Assoc);
3136 -- Case of insertion is not first named actual
3139 Set_Next_Named_Actual
3140 (Assoc, Next_Named_Actual (Parent (Prev)));
3141 Set_Next_Named_Actual (Parent (Prev), Actval);
3142 Append (Assoc, Parameter_Associations (N));
3145 Mark_Rewrite_Insertion (Assoc);
3146 Mark_Rewrite_Insertion (Actval);
3155 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
3156 FT1 : Entity_Id := T1;
3157 FT2 : Entity_Id := T2;
3160 if Is_Private_Type (T1)
3161 and then Present (Full_View (T1))
3163 FT1 := Full_View (T1);
3166 if Is_Private_Type (T2)
3167 and then Present (Full_View (T2))
3169 FT2 := Full_View (T2);
3172 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3175 --------------------------
3176 -- Static_Concatenation --
3177 --------------------------
3179 function Static_Concatenation (N : Node_Id) return Boolean is
3182 when N_String_Literal =>
3187 -- Concatenation is static when both operands are static
3188 -- and the concatenation operator is a predefined one.
3190 return Scope (Entity (N)) = Standard_Standard
3192 Static_Concatenation (Left_Opnd (N))
3194 Static_Concatenation (Right_Opnd (N));
3197 if Is_Entity_Name (N) then
3199 Ent : constant Entity_Id := Entity (N);
3201 return Ekind (Ent) = E_Constant
3202 and then Present (Constant_Value (Ent))
3204 Is_Static_Expression (Constant_Value (Ent));
3211 end Static_Concatenation;
3213 -- Start of processing for Resolve_Actuals
3216 Check_Argument_Order;
3218 if Present (First_Actual (N)) then
3219 Check_Prefixed_Call;
3222 A := First_Actual (N);
3223 F := First_Formal (Nam);
3224 while Present (F) loop
3225 if No (A) and then Needs_No_Actuals (Nam) then
3228 -- If we have an error in any actual or formal, indicated by a type
3229 -- of Any_Type, then abandon resolution attempt, and set result type
3232 elsif (Present (A) and then Etype (A) = Any_Type)
3233 or else Etype (F) = Any_Type
3235 Set_Etype (N, Any_Type);
3239 -- Case where actual is present
3241 -- If the actual is an entity, generate a reference to it now. We
3242 -- do this before the actual is resolved, because a formal of some
3243 -- protected subprogram, or a task discriminant, will be rewritten
3244 -- during expansion, and the reference to the source entity may
3248 and then Is_Entity_Name (A)
3249 and then Comes_From_Source (N)
3251 Orig_A := Entity (A);
3253 if Present (Orig_A) then
3254 if Is_Formal (Orig_A)
3255 and then Ekind (F) /= E_In_Parameter
3257 Generate_Reference (Orig_A, A, 'm');
3258 elsif not Is_Overloaded (A) then
3259 Generate_Reference (Orig_A, A);
3265 and then (Nkind (Parent (A)) /= N_Parameter_Association
3267 Chars (Selector_Name (Parent (A))) = Chars (F))
3269 -- If style checking mode on, check match of formal name
3272 if Nkind (Parent (A)) = N_Parameter_Association then
3273 Check_Identifier (Selector_Name (Parent (A)), F);
3277 -- If the formal is Out or In_Out, do not resolve and expand the
3278 -- conversion, because it is subsequently expanded into explicit
3279 -- temporaries and assignments. However, the object of the
3280 -- conversion can be resolved. An exception is the case of tagged
3281 -- type conversion with a class-wide actual. In that case we want
3282 -- the tag check to occur and no temporary will be needed (no
3283 -- representation change can occur) and the parameter is passed by
3284 -- reference, so we go ahead and resolve the type conversion.
3285 -- Another exception is the case of reference to component or
3286 -- subcomponent of a bit-packed array, in which case we want to
3287 -- defer expansion to the point the in and out assignments are
3290 if Ekind (F) /= E_In_Parameter
3291 and then Nkind (A) = N_Type_Conversion
3292 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3294 if Ekind (F) = E_In_Out_Parameter
3295 and then Is_Array_Type (Etype (F))
3297 if Has_Aliased_Components (Etype (Expression (A)))
3298 /= Has_Aliased_Components (Etype (F))
3301 -- In a view conversion, the conversion must be legal in
3302 -- both directions, and thus both component types must be
3303 -- aliased, or neither (4.6 (8)).
3305 -- The additional rule 4.6 (24.9.2) seems unduly
3306 -- restrictive: the privacy requirement should not apply
3307 -- to generic types, and should be checked in an
3308 -- instance. ARG query is in order ???
3311 ("both component types in a view conversion must be"
3312 & " aliased, or neither", A);
3315 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3317 if Is_By_Reference_Type (Etype (F))
3318 or else Is_By_Reference_Type (Etype (Expression (A)))
3321 ("view conversion between unrelated by reference " &
3322 "array types not allowed (\'A'I-00246)", A);
3325 Comp_Type : constant Entity_Id :=
3327 (Etype (Expression (A)));
3329 if Comes_From_Source (A)
3330 and then Ada_Version >= Ada_05
3332 ((Is_Private_Type (Comp_Type)
3333 and then not Is_Generic_Type (Comp_Type))
3334 or else Is_Tagged_Type (Comp_Type)
3335 or else Is_Volatile (Comp_Type))
3338 ("component type of a view conversion cannot"
3339 & " be private, tagged, or volatile"
3348 if (Conversion_OK (A)
3349 or else Valid_Conversion (A, Etype (A), Expression (A)))
3350 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3352 Resolve (Expression (A));
3355 -- If the actual is a function call that returns a limited
3356 -- unconstrained object that needs finalization, create a
3357 -- transient scope for it, so that it can receive the proper
3358 -- finalization list.
3360 elsif Nkind (A) = N_Function_Call
3361 and then Is_Limited_Record (Etype (F))
3362 and then not Is_Constrained (Etype (F))
3363 and then Expander_Active
3365 (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3367 Establish_Transient_Scope (A, False);
3369 -- A small optimization: if one of the actuals is a concatenation
3370 -- create a block around a procedure call to recover stack space.
3371 -- This alleviates stack usage when several procedure calls in
3372 -- the same statement list use concatenation. We do not perform
3373 -- this wrapping for code statements, where the argument is a
3374 -- static string, and we want to preserve warnings involving
3375 -- sequences of such statements.
3377 elsif Nkind (A) = N_Op_Concat
3378 and then Nkind (N) = N_Procedure_Call_Statement
3379 and then Expander_Active
3381 not (Is_Intrinsic_Subprogram (Nam)
3382 and then Chars (Nam) = Name_Asm)
3383 and then not Static_Concatenation (A)
3385 Establish_Transient_Scope (A, False);
3386 Resolve (A, Etype (F));
3389 if Nkind (A) = N_Type_Conversion
3390 and then Is_Array_Type (Etype (F))
3391 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3393 (Is_Limited_Type (Etype (F))
3394 or else Is_Limited_Type (Etype (Expression (A))))
3397 ("conversion between unrelated limited array types " &
3398 "not allowed (\A\I-00246)", A);
3400 if Is_Limited_Type (Etype (F)) then
3401 Explain_Limited_Type (Etype (F), A);
3404 if Is_Limited_Type (Etype (Expression (A))) then
3405 Explain_Limited_Type (Etype (Expression (A)), A);
3409 -- (Ada 2005: AI-251): If the actual is an allocator whose
3410 -- directly designated type is a class-wide interface, we build
3411 -- an anonymous access type to use it as the type of the
3412 -- allocator. Later, when the subprogram call is expanded, if
3413 -- the interface has a secondary dispatch table the expander
3414 -- will add a type conversion to force the correct displacement
3417 if Nkind (A) = N_Allocator then
3419 DDT : constant Entity_Id :=
3420 Directly_Designated_Type (Base_Type (Etype (F)));
3422 New_Itype : Entity_Id;
3425 if Is_Class_Wide_Type (DDT)
3426 and then Is_Interface (DDT)
3428 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3429 Set_Etype (New_Itype, Etype (A));
3430 Set_Directly_Designated_Type (New_Itype,
3431 Directly_Designated_Type (Etype (A)));
3432 Set_Etype (A, New_Itype);
3435 -- Ada 2005, AI-162:If the actual is an allocator, the
3436 -- innermost enclosing statement is the master of the
3437 -- created object. This needs to be done with expansion
3438 -- enabled only, otherwise the transient scope will not
3439 -- be removed in the expansion of the wrapped construct.
3441 if (Is_Controlled (DDT) or else Has_Task (DDT))
3442 and then Expander_Active
3444 Establish_Transient_Scope (A, False);
3449 -- (Ada 2005): The call may be to a primitive operation of
3450 -- a tagged synchronized type, declared outside of the type.
3451 -- In this case the controlling actual must be converted to
3452 -- its corresponding record type, which is the formal type.
3453 -- The actual may be a subtype, either because of a constraint
3454 -- or because it is a generic actual, so use base type to
3455 -- locate concurrent type.
3457 A_Typ := Base_Type (Etype (A));
3458 F_Typ := Base_Type (Etype (F));
3461 Full_A_Typ : Entity_Id;
3464 if Present (Full_View (A_Typ)) then
3465 Full_A_Typ := Base_Type (Full_View (A_Typ));
3467 Full_A_Typ := A_Typ;
3470 -- Tagged synchronized type (case 1): the actual is a
3473 if Is_Concurrent_Type (A_Typ)
3474 and then Corresponding_Record_Type (A_Typ) = F_Typ
3477 Unchecked_Convert_To
3478 (Corresponding_Record_Type (A_Typ), A));
3479 Resolve (A, Etype (F));
3481 -- Tagged synchronized type (case 2): the formal is a
3484 elsif Ekind (Full_A_Typ) = E_Record_Type
3486 (Corresponding_Concurrent_Type (Full_A_Typ))
3487 and then Is_Concurrent_Type (F_Typ)
3488 and then Present (Corresponding_Record_Type (F_Typ))
3489 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3491 Resolve (A, Corresponding_Record_Type (F_Typ));
3496 Resolve (A, Etype (F));
3504 -- Save actual for subsequent check on order dependence,
3505 -- and indicate whether actual is modifiable. For AI05-0144
3508 -- Ekind (F) /= E_In_Parameter or else Is_Access_Type (F_Typ));
3509 -- Why is this code commented out ???
3511 -- For mode IN, if actual is an entity, and the type of the formal
3512 -- has warnings suppressed, then we reset Never_Set_In_Source for
3513 -- the calling entity. The reason for this is to catch cases like
3514 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3515 -- uses trickery to modify an IN parameter.
3517 if Ekind (F) = E_In_Parameter
3518 and then Is_Entity_Name (A)
3519 and then Present (Entity (A))
3520 and then Ekind (Entity (A)) = E_Variable
3521 and then Has_Warnings_Off (F_Typ)
3523 Set_Never_Set_In_Source (Entity (A), False);
3526 -- Perform error checks for IN and IN OUT parameters
3528 if Ekind (F) /= E_Out_Parameter then
3530 -- Check unset reference. For scalar parameters, it is clearly
3531 -- wrong to pass an uninitialized value as either an IN or
3532 -- IN-OUT parameter. For composites, it is also clearly an
3533 -- error to pass a completely uninitialized value as an IN
3534 -- parameter, but the case of IN OUT is trickier. We prefer
3535 -- not to give a warning here. For example, suppose there is
3536 -- a routine that sets some component of a record to False.
3537 -- It is perfectly reasonable to make this IN-OUT and allow
3538 -- either initialized or uninitialized records to be passed
3541 -- For partially initialized composite values, we also avoid
3542 -- warnings, since it is quite likely that we are passing a
3543 -- partially initialized value and only the initialized fields
3544 -- will in fact be read in the subprogram.
3546 if Is_Scalar_Type (A_Typ)
3547 or else (Ekind (F) = E_In_Parameter
3548 and then not Is_Partially_Initialized_Type (A_Typ))
3550 Check_Unset_Reference (A);
3553 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3554 -- actual to a nested call, since this is case of reading an
3555 -- out parameter, which is not allowed.
3557 if Ada_Version = Ada_83
3558 and then Is_Entity_Name (A)
3559 and then Ekind (Entity (A)) = E_Out_Parameter
3561 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3565 -- Case of OUT or IN OUT parameter
3567 if Ekind (F) /= E_In_Parameter then
3569 -- For an Out parameter, check for useless assignment. Note
3570 -- that we can't set Last_Assignment this early, because we may
3571 -- kill current values in Resolve_Call, and that call would
3572 -- clobber the Last_Assignment field.
3574 -- Note: call Warn_On_Useless_Assignment before doing the check
3575 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3576 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3577 -- reflects the last assignment, not this one!
3579 if Ekind (F) = E_Out_Parameter then
3580 if Warn_On_Modified_As_Out_Parameter (F)
3581 and then Is_Entity_Name (A)
3582 and then Present (Entity (A))
3583 and then Comes_From_Source (N)
3585 Warn_On_Useless_Assignment (Entity (A), A);
3589 -- Validate the form of the actual. Note that the call to
3590 -- Is_OK_Variable_For_Out_Formal generates the required
3591 -- reference in this case.
3593 if not Is_OK_Variable_For_Out_Formal (A) then
3594 Error_Msg_NE ("actual for& must be a variable", A, F);
3597 -- What's the following about???
3599 if Is_Entity_Name (A) then
3600 Kill_Checks (Entity (A));
3606 if Etype (A) = Any_Type then
3607 Set_Etype (N, Any_Type);
3611 -- Apply appropriate range checks for in, out, and in-out
3612 -- parameters. Out and in-out parameters also need a separate
3613 -- check, if there is a type conversion, to make sure the return
3614 -- value meets the constraints of the variable before the
3617 -- Gigi looks at the check flag and uses the appropriate types.
3618 -- For now since one flag is used there is an optimization which
3619 -- might not be done in the In Out case since Gigi does not do
3620 -- any analysis. More thought required about this ???
3622 if Ekind_In (F, E_In_Parameter, E_In_Out_Parameter) then
3623 if Is_Scalar_Type (Etype (A)) then
3624 Apply_Scalar_Range_Check (A, F_Typ);
3626 elsif Is_Array_Type (Etype (A)) then
3627 Apply_Length_Check (A, F_Typ);
3629 elsif Is_Record_Type (F_Typ)
3630 and then Has_Discriminants (F_Typ)
3631 and then Is_Constrained (F_Typ)
3632 and then (not Is_Derived_Type (F_Typ)
3633 or else Comes_From_Source (Nam))
3635 Apply_Discriminant_Check (A, F_Typ);
3637 elsif Is_Access_Type (F_Typ)
3638 and then Is_Array_Type (Designated_Type (F_Typ))
3639 and then Is_Constrained (Designated_Type (F_Typ))
3641 Apply_Length_Check (A, F_Typ);
3643 elsif Is_Access_Type (F_Typ)
3644 and then Has_Discriminants (Designated_Type (F_Typ))
3645 and then Is_Constrained (Designated_Type (F_Typ))
3647 Apply_Discriminant_Check (A, F_Typ);
3650 Apply_Range_Check (A, F_Typ);
3653 -- Ada 2005 (AI-231)
3655 if Ada_Version >= Ada_05
3656 and then Is_Access_Type (F_Typ)
3657 and then Can_Never_Be_Null (F_Typ)
3658 and then Known_Null (A)
3660 Apply_Compile_Time_Constraint_Error
3662 Msg => "(Ada 2005) null not allowed in "
3663 & "null-excluding formal?",
3664 Reason => CE_Null_Not_Allowed);
3668 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter) then
3669 if Nkind (A) = N_Type_Conversion then
3670 if Is_Scalar_Type (A_Typ) then
3671 Apply_Scalar_Range_Check
3672 (Expression (A), Etype (Expression (A)), A_Typ);
3675 (Expression (A), Etype (Expression (A)), A_Typ);
3679 if Is_Scalar_Type (F_Typ) then
3680 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3682 elsif Is_Array_Type (F_Typ)
3683 and then Ekind (F) = E_Out_Parameter
3685 Apply_Length_Check (A, F_Typ);
3688 Apply_Range_Check (A, A_Typ, F_Typ);
3693 -- An actual associated with an access parameter is implicitly
3694 -- converted to the anonymous access type of the formal and must
3695 -- satisfy the legality checks for access conversions.
3697 if Ekind (F_Typ) = E_Anonymous_Access_Type then
3698 if not Valid_Conversion (A, F_Typ, A) then
3700 ("invalid implicit conversion for access parameter", A);
3704 -- Check bad case of atomic/volatile argument (RM C.6(12))
3706 if Is_By_Reference_Type (Etype (F))
3707 and then Comes_From_Source (N)
3709 if Is_Atomic_Object (A)
3710 and then not Is_Atomic (Etype (F))
3713 ("cannot pass atomic argument to non-atomic formal",
3716 elsif Is_Volatile_Object (A)
3717 and then not Is_Volatile (Etype (F))
3720 ("cannot pass volatile argument to non-volatile formal",
3725 -- Check that subprograms don't have improper controlling
3726 -- arguments (RM 3.9.2 (9)).
3728 -- A primitive operation may have an access parameter of an
3729 -- incomplete tagged type, but a dispatching call is illegal
3730 -- if the type is still incomplete.
3732 if Is_Controlling_Formal (F) then
3733 Set_Is_Controlling_Actual (A);
3735 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
3737 Desig : constant Entity_Id := Designated_Type (Etype (F));
3739 if Ekind (Desig) = E_Incomplete_Type
3740 and then No (Full_View (Desig))
3741 and then No (Non_Limited_View (Desig))
3744 ("premature use of incomplete type& " &
3745 "in dispatching call", A, Desig);
3750 elsif Nkind (A) = N_Explicit_Dereference then
3751 Validate_Remote_Access_To_Class_Wide_Type (A);
3754 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
3755 and then not Is_Class_Wide_Type (F_Typ)
3756 and then not Is_Controlling_Formal (F)
3758 Error_Msg_N ("class-wide argument not allowed here!", A);
3760 if Is_Subprogram (Nam)
3761 and then Comes_From_Source (Nam)
3763 Error_Msg_Node_2 := F_Typ;
3765 ("& is not a dispatching operation of &!", A, Nam);
3768 elsif Is_Access_Type (A_Typ)
3769 and then Is_Access_Type (F_Typ)
3770 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
3771 and then Ekind (F_Typ) /= E_Anonymous_Access_Subprogram_Type
3772 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
3773 or else (Nkind (A) = N_Attribute_Reference
3775 Is_Class_Wide_Type (Etype (Prefix (A)))))
3776 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
3777 and then not Is_Controlling_Formal (F)
3779 -- Disable these checks for call to imported C++ subprograms
3782 (Is_Entity_Name (Name (N))
3783 and then Is_Imported (Entity (Name (N)))
3784 and then Convention (Entity (Name (N))) = Convention_CPP)
3787 ("access to class-wide argument not allowed here!", A);
3789 if Is_Subprogram (Nam)
3790 and then Comes_From_Source (Nam)
3792 Error_Msg_Node_2 := Designated_Type (F_Typ);
3794 ("& is not a dispatching operation of &!", A, Nam);
3800 -- If it is a named association, treat the selector_name as
3801 -- a proper identifier, and mark the corresponding entity.
3803 if Nkind (Parent (A)) = N_Parameter_Association then
3804 Set_Entity (Selector_Name (Parent (A)), F);
3805 Generate_Reference (F, Selector_Name (Parent (A)));
3806 Set_Etype (Selector_Name (Parent (A)), F_Typ);
3807 Generate_Reference (F_Typ, N, ' ');
3812 if Ekind (F) /= E_Out_Parameter then
3813 Check_Unset_Reference (A);
3818 -- Case where actual is not present
3826 end Resolve_Actuals;
3828 -----------------------
3829 -- Resolve_Allocator --
3830 -----------------------
3832 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
3833 E : constant Node_Id := Expression (N);
3835 Discrim : Entity_Id;
3838 Assoc : Node_Id := Empty;
3841 procedure Check_Allocator_Discrim_Accessibility
3842 (Disc_Exp : Node_Id;
3843 Alloc_Typ : Entity_Id);
3844 -- Check that accessibility level associated with an access discriminant
3845 -- initialized in an allocator by the expression Disc_Exp is not deeper
3846 -- than the level of the allocator type Alloc_Typ. An error message is
3847 -- issued if this condition is violated. Specialized checks are done for
3848 -- the cases of a constraint expression which is an access attribute or
3849 -- an access discriminant.
3851 function In_Dispatching_Context return Boolean;
3852 -- If the allocator is an actual in a call, it is allowed to be class-
3853 -- wide when the context is not because it is a controlling actual.
3855 procedure Propagate_Coextensions (Root : Node_Id);
3856 -- Propagate all nested coextensions which are located one nesting
3857 -- level down the tree to the node Root. Example:
3860 -- Level_1_Coextension
3861 -- Level_2_Coextension
3863 -- The algorithm is paired with delay actions done by the Expander. In
3864 -- the above example, assume all coextensions are controlled types.
3865 -- The cycle of analysis, resolution and expansion will yield:
3867 -- 1) Analyze Top_Record
3868 -- 2) Analyze Level_1_Coextension
3869 -- 3) Analyze Level_2_Coextension
3870 -- 4) Resolve Level_2_Coextension. The allocator is marked as a
3872 -- 5) Expand Level_2_Coextension. A temporary variable Temp_1 is
3873 -- generated to capture the allocated object. Temp_1 is attached
3874 -- to the coextension chain of Level_2_Coextension.
3875 -- 6) Resolve Level_1_Coextension. The allocator is marked as a
3876 -- coextension. A forward tree traversal is performed which finds
3877 -- Level_2_Coextension's list and copies its contents into its
3879 -- 7) Expand Level_1_Coextension. A temporary variable Temp_2 is
3880 -- generated to capture the allocated object. Temp_2 is attached
3881 -- to the coextension chain of Level_1_Coextension. Currently, the
3882 -- contents of the list are [Temp_2, Temp_1].
3883 -- 8) Resolve Top_Record. A forward tree traversal is performed which
3884 -- finds Level_1_Coextension's list and copies its contents into
3886 -- 9) Expand Top_Record. Generate finalization calls for Temp_1 and
3887 -- Temp_2 and attach them to Top_Record's finalization list.
3889 -------------------------------------------
3890 -- Check_Allocator_Discrim_Accessibility --
3891 -------------------------------------------
3893 procedure Check_Allocator_Discrim_Accessibility
3894 (Disc_Exp : Node_Id;
3895 Alloc_Typ : Entity_Id)
3898 if Type_Access_Level (Etype (Disc_Exp)) >
3899 Type_Access_Level (Alloc_Typ)
3902 ("operand type has deeper level than allocator type", Disc_Exp);
3904 -- When the expression is an Access attribute the level of the prefix
3905 -- object must not be deeper than that of the allocator's type.
3907 elsif Nkind (Disc_Exp) = N_Attribute_Reference
3908 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
3910 and then Object_Access_Level (Prefix (Disc_Exp))
3911 > Type_Access_Level (Alloc_Typ)
3914 ("prefix of attribute has deeper level than allocator type",
3917 -- When the expression is an access discriminant the check is against
3918 -- the level of the prefix object.
3920 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
3921 and then Nkind (Disc_Exp) = N_Selected_Component
3922 and then Object_Access_Level (Prefix (Disc_Exp))
3923 > Type_Access_Level (Alloc_Typ)
3926 ("access discriminant has deeper level than allocator type",
3929 -- All other cases are legal
3934 end Check_Allocator_Discrim_Accessibility;
3936 ----------------------------
3937 -- In_Dispatching_Context --
3938 ----------------------------
3940 function In_Dispatching_Context return Boolean is
3941 Par : constant Node_Id := Parent (N);
3943 return Nkind_In (Par, N_Function_Call, N_Procedure_Call_Statement)
3944 and then Is_Entity_Name (Name (Par))
3945 and then Is_Dispatching_Operation (Entity (Name (Par)));
3946 end In_Dispatching_Context;
3948 ----------------------------
3949 -- Propagate_Coextensions --
3950 ----------------------------
3952 procedure Propagate_Coextensions (Root : Node_Id) is
3954 procedure Copy_List (From : Elist_Id; To : Elist_Id);
3955 -- Copy the contents of list From into list To, preserving the
3956 -- order of elements.
3958 function Process_Allocator (Nod : Node_Id) return Traverse_Result;
3959 -- Recognize an allocator or a rewritten allocator node and add it
3960 -- along with its nested coextensions to the list of Root.
3966 procedure Copy_List (From : Elist_Id; To : Elist_Id) is
3967 From_Elmt : Elmt_Id;
3969 From_Elmt := First_Elmt (From);
3970 while Present (From_Elmt) loop
3971 Append_Elmt (Node (From_Elmt), To);
3972 Next_Elmt (From_Elmt);
3976 -----------------------
3977 -- Process_Allocator --
3978 -----------------------
3980 function Process_Allocator (Nod : Node_Id) return Traverse_Result is
3981 Orig_Nod : Node_Id := Nod;
3984 -- This is a possible rewritten subtype indication allocator. Any
3985 -- nested coextensions will appear as discriminant constraints.
3987 if Nkind (Nod) = N_Identifier
3988 and then Present (Original_Node (Nod))
3989 and then Nkind (Original_Node (Nod)) = N_Subtype_Indication
3993 Discr_Elmt : Elmt_Id;
3996 if Is_Record_Type (Entity (Nod)) then
3998 First_Elmt (Discriminant_Constraint (Entity (Nod)));
3999 while Present (Discr_Elmt) loop
4000 Discr := Node (Discr_Elmt);
4002 if Nkind (Discr) = N_Identifier
4003 and then Present (Original_Node (Discr))
4004 and then Nkind (Original_Node (Discr)) = N_Allocator
4005 and then Present (Coextensions (
4006 Original_Node (Discr)))
4008 if No (Coextensions (Root)) then
4009 Set_Coextensions (Root, New_Elmt_List);
4013 (From => Coextensions (Original_Node (Discr)),
4014 To => Coextensions (Root));
4017 Next_Elmt (Discr_Elmt);
4020 -- There is no need to continue the traversal of this
4021 -- subtree since all the information has already been
4028 -- Case of either a stand alone allocator or a rewritten allocator
4029 -- with an aggregate.
4032 if Present (Original_Node (Nod)) then
4033 Orig_Nod := Original_Node (Nod);
4036 if Nkind (Orig_Nod) = N_Allocator then
4038 -- Propagate the list of nested coextensions to the Root
4039 -- allocator. This is done through list copy since a single
4040 -- allocator may have multiple coextensions. Do not touch
4041 -- coextensions roots.
4043 if not Is_Coextension_Root (Orig_Nod)
4044 and then Present (Coextensions (Orig_Nod))
4046 if No (Coextensions (Root)) then
4047 Set_Coextensions (Root, New_Elmt_List);
4051 (From => Coextensions (Orig_Nod),
4052 To => Coextensions (Root));
4055 -- There is no need to continue the traversal of this
4056 -- subtree since all the information has already been
4063 -- Keep on traversing, looking for the next allocator
4066 end Process_Allocator;
4068 procedure Process_Allocators is
4069 new Traverse_Proc (Process_Allocator);
4071 -- Start of processing for Propagate_Coextensions
4074 Process_Allocators (Expression (Root));
4075 end Propagate_Coextensions;
4077 -- Start of processing for Resolve_Allocator
4080 -- Replace general access with specific type
4082 if Ekind (Etype (N)) = E_Allocator_Type then
4083 Set_Etype (N, Base_Type (Typ));
4086 if Is_Abstract_Type (Typ) then
4087 Error_Msg_N ("type of allocator cannot be abstract", N);
4090 -- For qualified expression, resolve the expression using the
4091 -- given subtype (nothing to do for type mark, subtype indication)
4093 if Nkind (E) = N_Qualified_Expression then
4094 if Is_Class_Wide_Type (Etype (E))
4095 and then not Is_Class_Wide_Type (Designated_Type (Typ))
4096 and then not In_Dispatching_Context
4099 ("class-wide allocator not allowed for this access type", N);
4102 Resolve (Expression (E), Etype (E));
4103 Check_Unset_Reference (Expression (E));
4105 -- A qualified expression requires an exact match of the type,
4106 -- class-wide matching is not allowed.
4108 if (Is_Class_Wide_Type (Etype (Expression (E)))
4109 or else Is_Class_Wide_Type (Etype (E)))
4110 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
4112 Wrong_Type (Expression (E), Etype (E));
4115 -- A special accessibility check is needed for allocators that
4116 -- constrain access discriminants. The level of the type of the
4117 -- expression used to constrain an access discriminant cannot be
4118 -- deeper than the type of the allocator (in contrast to access
4119 -- parameters, where the level of the actual can be arbitrary).
4121 -- We can't use Valid_Conversion to perform this check because
4122 -- in general the type of the allocator is unrelated to the type
4123 -- of the access discriminant.
4125 if Ekind (Typ) /= E_Anonymous_Access_Type
4126 or else Is_Local_Anonymous_Access (Typ)
4128 Subtyp := Entity (Subtype_Mark (E));
4130 Aggr := Original_Node (Expression (E));
4132 if Has_Discriminants (Subtyp)
4133 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
4135 Discrim := First_Discriminant (Base_Type (Subtyp));
4137 -- Get the first component expression of the aggregate
4139 if Present (Expressions (Aggr)) then
4140 Disc_Exp := First (Expressions (Aggr));
4142 elsif Present (Component_Associations (Aggr)) then
4143 Assoc := First (Component_Associations (Aggr));
4145 if Present (Assoc) then
4146 Disc_Exp := Expression (Assoc);
4155 while Present (Discrim) and then Present (Disc_Exp) loop
4156 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4157 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4160 Next_Discriminant (Discrim);
4162 if Present (Discrim) then
4163 if Present (Assoc) then
4165 Disc_Exp := Expression (Assoc);
4167 elsif Present (Next (Disc_Exp)) then
4171 Assoc := First (Component_Associations (Aggr));
4173 if Present (Assoc) then
4174 Disc_Exp := Expression (Assoc);
4184 -- For a subtype mark or subtype indication, freeze the subtype
4187 Freeze_Expression (E);
4189 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
4191 ("initialization required for access-to-constant allocator", N);
4194 -- A special accessibility check is needed for allocators that
4195 -- constrain access discriminants. The level of the type of the
4196 -- expression used to constrain an access discriminant cannot be
4197 -- deeper than the type of the allocator (in contrast to access
4198 -- parameters, where the level of the actual can be arbitrary).
4199 -- We can't use Valid_Conversion to perform this check because
4200 -- in general the type of the allocator is unrelated to the type
4201 -- of the access discriminant.
4203 if Nkind (Original_Node (E)) = N_Subtype_Indication
4204 and then (Ekind (Typ) /= E_Anonymous_Access_Type
4205 or else Is_Local_Anonymous_Access (Typ))
4207 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
4209 if Has_Discriminants (Subtyp) then
4210 Discrim := First_Discriminant (Base_Type (Subtyp));
4211 Constr := First (Constraints (Constraint (Original_Node (E))));
4212 while Present (Discrim) and then Present (Constr) loop
4213 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4214 if Nkind (Constr) = N_Discriminant_Association then
4215 Disc_Exp := Original_Node (Expression (Constr));
4217 Disc_Exp := Original_Node (Constr);
4220 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4223 Next_Discriminant (Discrim);
4230 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4231 -- check that the level of the type of the created object is not deeper
4232 -- than the level of the allocator's access type, since extensions can
4233 -- now occur at deeper levels than their ancestor types. This is a
4234 -- static accessibility level check; a run-time check is also needed in
4235 -- the case of an initialized allocator with a class-wide argument (see
4236 -- Expand_Allocator_Expression).
4238 if Ada_Version >= Ada_05
4239 and then Is_Class_Wide_Type (Designated_Type (Typ))
4242 Exp_Typ : Entity_Id;
4245 if Nkind (E) = N_Qualified_Expression then
4246 Exp_Typ := Etype (E);
4247 elsif Nkind (E) = N_Subtype_Indication then
4248 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4250 Exp_Typ := Entity (E);
4253 if Type_Access_Level (Exp_Typ) > Type_Access_Level (Typ) then
4254 if In_Instance_Body then
4255 Error_Msg_N ("?type in allocator has deeper level than" &
4256 " designated class-wide type", E);
4257 Error_Msg_N ("\?Program_Error will be raised at run time",
4260 Make_Raise_Program_Error (Sloc (N),
4261 Reason => PE_Accessibility_Check_Failed));
4264 -- Do not apply Ada 2005 accessibility checks on a class-wide
4265 -- allocator if the type given in the allocator is a formal
4266 -- type. A run-time check will be performed in the instance.
4268 elsif not Is_Generic_Type (Exp_Typ) then
4269 Error_Msg_N ("type in allocator has deeper level than" &
4270 " designated class-wide type", E);
4276 -- Check for allocation from an empty storage pool
4278 if No_Pool_Assigned (Typ) then
4280 Loc : constant Source_Ptr := Sloc (N);
4282 Error_Msg_N ("?allocation from empty storage pool!", N);
4283 Error_Msg_N ("\?Storage_Error will be raised at run time!", N);
4285 Make_Raise_Storage_Error (Loc,
4286 Reason => SE_Empty_Storage_Pool));
4289 -- If the context is an unchecked conversion, as may happen within
4290 -- an inlined subprogram, the allocator is being resolved with its
4291 -- own anonymous type. In that case, if the target type has a specific
4292 -- storage pool, it must be inherited explicitly by the allocator type.
4294 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4295 and then No (Associated_Storage_Pool (Typ))
4297 Set_Associated_Storage_Pool
4298 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4301 -- An erroneous allocator may be rewritten as a raise Program_Error
4304 if Nkind (N) = N_Allocator then
4306 -- An anonymous access discriminant is the definition of a
4309 if Ekind (Typ) = E_Anonymous_Access_Type
4310 and then Nkind (Associated_Node_For_Itype (Typ)) =
4311 N_Discriminant_Specification
4313 -- Avoid marking an allocator as a dynamic coextension if it is
4314 -- within a static construct.
4316 if not Is_Static_Coextension (N) then
4317 Set_Is_Dynamic_Coextension (N);
4320 -- Cleanup for potential static coextensions
4323 Set_Is_Dynamic_Coextension (N, False);
4324 Set_Is_Static_Coextension (N, False);
4327 -- There is no need to propagate any nested coextensions if they
4328 -- are marked as static since they will be rewritten on the spot.
4330 if not Is_Static_Coextension (N) then
4331 Propagate_Coextensions (N);
4334 end Resolve_Allocator;
4336 ---------------------------
4337 -- Resolve_Arithmetic_Op --
4338 ---------------------------
4340 -- Used for resolving all arithmetic operators except exponentiation
4342 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4343 L : constant Node_Id := Left_Opnd (N);
4344 R : constant Node_Id := Right_Opnd (N);
4345 TL : constant Entity_Id := Base_Type (Etype (L));
4346 TR : constant Entity_Id := Base_Type (Etype (R));
4350 B_Typ : constant Entity_Id := Base_Type (Typ);
4351 -- We do the resolution using the base type, because intermediate values
4352 -- in expressions always are of the base type, not a subtype of it.
4354 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4355 -- Returns True if N is in a context that expects "any real type"
4357 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4358 -- Return True iff given type is Integer or universal real/integer
4360 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4361 -- Choose type of integer literal in fixed-point operation to conform
4362 -- to available fixed-point type. T is the type of the other operand,
4363 -- which is needed to determine the expected type of N.
4365 procedure Set_Operand_Type (N : Node_Id);
4366 -- Set operand type to T if universal
4368 -------------------------------
4369 -- Expected_Type_Is_Any_Real --
4370 -------------------------------
4372 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4374 -- N is the expression after "delta" in a fixed_point_definition;
4377 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4378 N_Decimal_Fixed_Point_Definition,
4380 -- N is one of the bounds in a real_range_specification;
4383 N_Real_Range_Specification,
4385 -- N is the expression of a delta_constraint;
4388 N_Delta_Constraint);
4389 end Expected_Type_Is_Any_Real;
4391 -----------------------------
4392 -- Is_Integer_Or_Universal --
4393 -----------------------------
4395 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4397 Index : Interp_Index;
4401 if not Is_Overloaded (N) then
4403 return Base_Type (T) = Base_Type (Standard_Integer)
4404 or else T = Universal_Integer
4405 or else T = Universal_Real;
4407 Get_First_Interp (N, Index, It);
4408 while Present (It.Typ) loop
4409 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4410 or else It.Typ = Universal_Integer
4411 or else It.Typ = Universal_Real
4416 Get_Next_Interp (Index, It);
4421 end Is_Integer_Or_Universal;
4423 ----------------------------
4424 -- Set_Mixed_Mode_Operand --
4425 ----------------------------
4427 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4428 Index : Interp_Index;
4432 if Universal_Interpretation (N) = Universal_Integer then
4434 -- A universal integer literal is resolved as standard integer
4435 -- except in the case of a fixed-point result, where we leave it
4436 -- as universal (to be handled by Exp_Fixd later on)
4438 if Is_Fixed_Point_Type (T) then
4439 Resolve (N, Universal_Integer);
4441 Resolve (N, Standard_Integer);
4444 elsif Universal_Interpretation (N) = Universal_Real
4445 and then (T = Base_Type (Standard_Integer)
4446 or else T = Universal_Integer
4447 or else T = Universal_Real)
4449 -- A universal real can appear in a fixed-type context. We resolve
4450 -- the literal with that context, even though this might raise an
4451 -- exception prematurely (the other operand may be zero).
4455 elsif Etype (N) = Base_Type (Standard_Integer)
4456 and then T = Universal_Real
4457 and then Is_Overloaded (N)
4459 -- Integer arg in mixed-mode operation. Resolve with universal
4460 -- type, in case preference rule must be applied.
4462 Resolve (N, Universal_Integer);
4465 and then B_Typ /= Universal_Fixed
4467 -- Not a mixed-mode operation, resolve with context
4471 elsif Etype (N) = Any_Fixed then
4473 -- N may itself be a mixed-mode operation, so use context type
4477 elsif Is_Fixed_Point_Type (T)
4478 and then B_Typ = Universal_Fixed
4479 and then Is_Overloaded (N)
4481 -- Must be (fixed * fixed) operation, operand must have one
4482 -- compatible interpretation.
4484 Resolve (N, Any_Fixed);
4486 elsif Is_Fixed_Point_Type (B_Typ)
4487 and then (T = Universal_Real
4488 or else Is_Fixed_Point_Type (T))
4489 and then Is_Overloaded (N)
4491 -- C * F(X) in a fixed context, where C is a real literal or a
4492 -- fixed-point expression. F must have either a fixed type
4493 -- interpretation or an integer interpretation, but not both.
4495 Get_First_Interp (N, Index, It);
4496 while Present (It.Typ) loop
4497 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4499 if Analyzed (N) then
4500 Error_Msg_N ("ambiguous operand in fixed operation", N);
4502 Resolve (N, Standard_Integer);
4505 elsif Is_Fixed_Point_Type (It.Typ) then
4507 if Analyzed (N) then
4508 Error_Msg_N ("ambiguous operand in fixed operation", N);
4510 Resolve (N, It.Typ);
4514 Get_Next_Interp (Index, It);
4517 -- Reanalyze the literal with the fixed type of the context. If
4518 -- context is Universal_Fixed, we are within a conversion, leave
4519 -- the literal as a universal real because there is no usable
4520 -- fixed type, and the target of the conversion plays no role in
4534 if B_Typ = Universal_Fixed
4535 and then Nkind (Op2) = N_Real_Literal
4537 T2 := Universal_Real;
4542 Set_Analyzed (Op2, False);
4549 end Set_Mixed_Mode_Operand;
4551 ----------------------
4552 -- Set_Operand_Type --
4553 ----------------------
4555 procedure Set_Operand_Type (N : Node_Id) is
4557 if Etype (N) = Universal_Integer
4558 or else Etype (N) = Universal_Real
4562 end Set_Operand_Type;
4564 -- Start of processing for Resolve_Arithmetic_Op
4567 if Comes_From_Source (N)
4568 and then Ekind (Entity (N)) = E_Function
4569 and then Is_Imported (Entity (N))
4570 and then Is_Intrinsic_Subprogram (Entity (N))
4572 Resolve_Intrinsic_Operator (N, Typ);
4575 -- Special-case for mixed-mode universal expressions or fixed point
4576 -- type operation: each argument is resolved separately. The same
4577 -- treatment is required if one of the operands of a fixed point
4578 -- operation is universal real, since in this case we don't do a
4579 -- conversion to a specific fixed-point type (instead the expander
4580 -- takes care of the case).
4582 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4583 and then Present (Universal_Interpretation (L))
4584 and then Present (Universal_Interpretation (R))
4586 Resolve (L, Universal_Interpretation (L));
4587 Resolve (R, Universal_Interpretation (R));
4588 Set_Etype (N, B_Typ);
4590 elsif (B_Typ = Universal_Real
4591 or else Etype (N) = Universal_Fixed
4592 or else (Etype (N) = Any_Fixed
4593 and then Is_Fixed_Point_Type (B_Typ))
4594 or else (Is_Fixed_Point_Type (B_Typ)
4595 and then (Is_Integer_Or_Universal (L)
4597 Is_Integer_Or_Universal (R))))
4598 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4600 if TL = Universal_Integer or else TR = Universal_Integer then
4601 Check_For_Visible_Operator (N, B_Typ);
4604 -- If context is a fixed type and one operand is integer, the
4605 -- other is resolved with the type of the context.
4607 if Is_Fixed_Point_Type (B_Typ)
4608 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4609 or else TL = Universal_Integer)
4614 elsif Is_Fixed_Point_Type (B_Typ)
4615 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4616 or else TR = Universal_Integer)
4622 Set_Mixed_Mode_Operand (L, TR);
4623 Set_Mixed_Mode_Operand (R, TL);
4626 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4627 -- multiplying operators from being used when the expected type is
4628 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4629 -- some cases where the expected type is actually Any_Real;
4630 -- Expected_Type_Is_Any_Real takes care of that case.
4632 if Etype (N) = Universal_Fixed
4633 or else Etype (N) = Any_Fixed
4635 if B_Typ = Universal_Fixed
4636 and then not Expected_Type_Is_Any_Real (N)
4637 and then not Nkind_In (Parent (N), N_Type_Conversion,
4638 N_Unchecked_Type_Conversion)
4640 Error_Msg_N ("type cannot be determined from context!", N);
4641 Error_Msg_N ("\explicit conversion to result type required", N);
4643 Set_Etype (L, Any_Type);
4644 Set_Etype (R, Any_Type);
4647 if Ada_Version = Ada_83
4648 and then Etype (N) = Universal_Fixed
4650 Nkind_In (Parent (N), N_Type_Conversion,
4651 N_Unchecked_Type_Conversion)
4654 ("(Ada 83) fixed-point operation "
4655 & "needs explicit conversion", N);
4658 -- The expected type is "any real type" in contexts like
4659 -- type T is delta <universal_fixed-expression> ...
4660 -- in which case we need to set the type to Universal_Real
4661 -- so that static expression evaluation will work properly.
4663 if Expected_Type_Is_Any_Real (N) then
4664 Set_Etype (N, Universal_Real);
4666 Set_Etype (N, B_Typ);
4670 elsif Is_Fixed_Point_Type (B_Typ)
4671 and then (Is_Integer_Or_Universal (L)
4672 or else Nkind (L) = N_Real_Literal
4673 or else Nkind (R) = N_Real_Literal
4674 or else Is_Integer_Or_Universal (R))
4676 Set_Etype (N, B_Typ);
4678 elsif Etype (N) = Any_Fixed then
4680 -- If no previous errors, this is only possible if one operand
4681 -- is overloaded and the context is universal. Resolve as such.
4683 Set_Etype (N, B_Typ);
4687 if (TL = Universal_Integer or else TL = Universal_Real)
4689 (TR = Universal_Integer or else TR = Universal_Real)
4691 Check_For_Visible_Operator (N, B_Typ);
4694 -- If the context is Universal_Fixed and the operands are also
4695 -- universal fixed, this is an error, unless there is only one
4696 -- applicable fixed_point type (usually Duration).
4698 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4699 T := Unique_Fixed_Point_Type (N);
4701 if T = Any_Type then
4714 -- If one of the arguments was resolved to a non-universal type.
4715 -- label the result of the operation itself with the same type.
4716 -- Do the same for the universal argument, if any.
4718 T := Intersect_Types (L, R);
4719 Set_Etype (N, Base_Type (T));
4720 Set_Operand_Type (L);
4721 Set_Operand_Type (R);
4724 Generate_Operator_Reference (N, Typ);
4725 Eval_Arithmetic_Op (N);
4727 -- Set overflow and division checking bit. Much cleverer code needed
4728 -- here eventually and perhaps the Resolve routines should be separated
4729 -- for the various arithmetic operations, since they will need
4730 -- different processing. ???
4732 if Nkind (N) in N_Op then
4733 if not Overflow_Checks_Suppressed (Etype (N)) then
4734 Enable_Overflow_Check (N);
4737 -- Give warning if explicit division by zero
4739 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
4740 and then not Division_Checks_Suppressed (Etype (N))
4742 Rop := Right_Opnd (N);
4744 if Compile_Time_Known_Value (Rop)
4745 and then ((Is_Integer_Type (Etype (Rop))
4746 and then Expr_Value (Rop) = Uint_0)
4748 (Is_Real_Type (Etype (Rop))
4749 and then Expr_Value_R (Rop) = Ureal_0))
4751 -- Specialize the warning message according to the operation
4755 Apply_Compile_Time_Constraint_Error
4756 (N, "division by zero?", CE_Divide_By_Zero,
4757 Loc => Sloc (Right_Opnd (N)));
4760 Apply_Compile_Time_Constraint_Error
4761 (N, "rem with zero divisor?", CE_Divide_By_Zero,
4762 Loc => Sloc (Right_Opnd (N)));
4765 Apply_Compile_Time_Constraint_Error
4766 (N, "mod with zero divisor?", CE_Divide_By_Zero,
4767 Loc => Sloc (Right_Opnd (N)));
4769 -- Division by zero can only happen with division, rem,
4770 -- and mod operations.
4773 raise Program_Error;
4776 -- Otherwise just set the flag to check at run time
4779 Activate_Division_Check (N);
4783 -- If Restriction No_Implicit_Conditionals is active, then it is
4784 -- violated if either operand can be negative for mod, or for rem
4785 -- if both operands can be negative.
4787 if Restriction_Check_Required (No_Implicit_Conditionals)
4788 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
4797 -- Set if corresponding operand might be negative
4801 (Left_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4802 LNeg := (not OK) or else Lo < 0;
4805 (Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
4806 RNeg := (not OK) or else Lo < 0;
4808 -- Check if we will be generating conditionals. There are two
4809 -- cases where that can happen, first for REM, the only case
4810 -- is largest negative integer mod -1, where the division can
4811 -- overflow, but we still have to give the right result. The
4812 -- front end generates a test for this annoying case. Here we
4813 -- just test if both operands can be negative (that's what the
4814 -- expander does, so we match its logic here).
4816 -- The second case is mod where either operand can be negative.
4817 -- In this case, the back end has to generate additonal tests.
4819 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
4821 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
4823 Check_Restriction (No_Implicit_Conditionals, N);
4829 Check_Unset_Reference (L);
4830 Check_Unset_Reference (R);
4831 end Resolve_Arithmetic_Op;
4837 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
4838 Loc : constant Source_Ptr := Sloc (N);
4839 Subp : constant Node_Id := Name (N);
4847 function Same_Or_Aliased_Subprograms
4849 E : Entity_Id) return Boolean;
4850 -- Returns True if the subprogram entity S is the same as E or else
4851 -- S is an alias of E.
4853 ---------------------------------
4854 -- Same_Or_Aliased_Subprograms --
4855 ---------------------------------
4857 function Same_Or_Aliased_Subprograms
4859 E : Entity_Id) return Boolean
4861 Subp_Alias : constant Entity_Id := Alias (S);
4864 or else (Present (Subp_Alias) and then Subp_Alias = E);
4865 end Same_Or_Aliased_Subprograms;
4867 -- Start of processing for Resolve_Call
4870 -- The context imposes a unique interpretation with type Typ on a
4871 -- procedure or function call. Find the entity of the subprogram that
4872 -- yields the expected type, and propagate the corresponding formal
4873 -- constraints on the actuals. The caller has established that an
4874 -- interpretation exists, and emitted an error if not unique.
4876 -- First deal with the case of a call to an access-to-subprogram,
4877 -- dereference made explicit in Analyze_Call.
4879 if Ekind (Etype (Subp)) = E_Subprogram_Type then
4880 if not Is_Overloaded (Subp) then
4881 Nam := Etype (Subp);
4884 -- Find the interpretation whose type (a subprogram type) has a
4885 -- return type that is compatible with the context. Analysis of
4886 -- the node has established that one exists.
4890 Get_First_Interp (Subp, I, It);
4891 while Present (It.Typ) loop
4892 if Covers (Typ, Etype (It.Typ)) then
4897 Get_Next_Interp (I, It);
4901 raise Program_Error;
4905 -- If the prefix is not an entity, then resolve it
4907 if not Is_Entity_Name (Subp) then
4908 Resolve (Subp, Nam);
4911 -- For an indirect call, we always invalidate checks, since we do not
4912 -- know whether the subprogram is local or global. Yes we could do
4913 -- better here, e.g. by knowing that there are no local subprograms,
4914 -- but it does not seem worth the effort. Similarly, we kill all
4915 -- knowledge of current constant values.
4917 Kill_Current_Values;
4919 -- If this is a procedure call which is really an entry call, do
4920 -- the conversion of the procedure call to an entry call. Protected
4921 -- operations use the same circuitry because the name in the call
4922 -- can be an arbitrary expression with special resolution rules.
4924 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
4925 or else (Is_Entity_Name (Subp)
4926 and then Ekind (Entity (Subp)) = E_Entry)
4928 Resolve_Entry_Call (N, Typ);
4929 Check_Elab_Call (N);
4931 -- Kill checks and constant values, as above for indirect case
4932 -- Who knows what happens when another task is activated?
4934 Kill_Current_Values;
4937 -- Normal subprogram call with name established in Resolve
4939 elsif not (Is_Type (Entity (Subp))) then
4940 Nam := Entity (Subp);
4941 Set_Entity_With_Style_Check (Subp, Nam);
4943 -- Otherwise we must have the case of an overloaded call
4946 pragma Assert (Is_Overloaded (Subp));
4948 -- Initialize Nam to prevent warning (we know it will be assigned
4949 -- in the loop below, but the compiler does not know that).
4953 Get_First_Interp (Subp, I, It);
4954 while Present (It.Typ) loop
4955 if Covers (Typ, It.Typ) then
4957 Set_Entity_With_Style_Check (Subp, Nam);
4961 Get_Next_Interp (I, It);
4965 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
4966 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
4967 and then Nkind (Subp) /= N_Explicit_Dereference
4968 and then Present (Parameter_Associations (N))
4970 -- The prefix is a parameterless function call that returns an access
4971 -- to subprogram. If parameters are present in the current call, add
4972 -- add an explicit dereference. We use the base type here because
4973 -- within an instance these may be subtypes.
4975 -- The dereference is added either in Analyze_Call or here. Should
4976 -- be consolidated ???
4978 Set_Is_Overloaded (Subp, False);
4979 Set_Etype (Subp, Etype (Nam));
4980 Insert_Explicit_Dereference (Subp);
4981 Nam := Designated_Type (Etype (Nam));
4982 Resolve (Subp, Nam);
4985 -- Check that a call to Current_Task does not occur in an entry body
4987 if Is_RTE (Nam, RE_Current_Task) then
4996 -- Exclude calls that occur within the default of a formal
4997 -- parameter of the entry, since those are evaluated outside
5000 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
5002 if Nkind (P) = N_Entry_Body
5003 or else (Nkind (P) = N_Subprogram_Body
5004 and then Is_Entry_Barrier_Function (P))
5008 ("?& should not be used in entry body (RM C.7(17))",
5011 ("\Program_Error will be raised at run time?", N, Nam);
5013 Make_Raise_Program_Error (Loc,
5014 Reason => PE_Current_Task_In_Entry_Body));
5015 Set_Etype (N, Rtype);
5022 -- Check that a procedure call does not occur in the context of the
5023 -- entry call statement of a conditional or timed entry call. Note that
5024 -- the case of a call to a subprogram renaming of an entry will also be
5025 -- rejected. The test for N not being an N_Entry_Call_Statement is
5026 -- defensive, covering the possibility that the processing of entry
5027 -- calls might reach this point due to later modifications of the code
5030 if Nkind (Parent (N)) = N_Entry_Call_Alternative
5031 and then Nkind (N) /= N_Entry_Call_Statement
5032 and then Entry_Call_Statement (Parent (N)) = N
5034 if Ada_Version < Ada_05 then
5035 Error_Msg_N ("entry call required in select statement", N);
5037 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5038 -- for a procedure_or_entry_call, the procedure_name or
5039 -- procedure_prefix of the procedure_call_statement shall denote
5040 -- an entry renamed by a procedure, or (a view of) a primitive
5041 -- subprogram of a limited interface whose first parameter is
5042 -- a controlling parameter.
5044 elsif Nkind (N) = N_Procedure_Call_Statement
5045 and then not Is_Renamed_Entry (Nam)
5046 and then not Is_Controlling_Limited_Procedure (Nam)
5049 ("entry call or dispatching primitive of interface required", N);
5053 -- Check that this is not a call to a protected procedure or entry from
5054 -- within a protected function.
5056 if Ekind (Current_Scope) = E_Function
5057 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
5058 and then Ekind (Nam) /= E_Function
5059 and then Scope (Nam) = Scope (Current_Scope)
5061 Error_Msg_N ("within protected function, protected " &
5062 "object is constant", N);
5063 Error_Msg_N ("\cannot call operation that may modify it", N);
5066 -- Freeze the subprogram name if not in a spec-expression. Note that we
5067 -- freeze procedure calls as well as function calls. Procedure calls are
5068 -- not frozen according to the rules (RM 13.14(14)) because it is
5069 -- impossible to have a procedure call to a non-frozen procedure in pure
5070 -- Ada, but in the code that we generate in the expander, this rule
5071 -- needs extending because we can generate procedure calls that need
5074 if Is_Entity_Name (Subp) and then not In_Spec_Expression then
5075 Freeze_Expression (Subp);
5078 -- For a predefined operator, the type of the result is the type imposed
5079 -- by context, except for a predefined operation on universal fixed.
5080 -- Otherwise The type of the call is the type returned by the subprogram
5083 if Is_Predefined_Op (Nam) then
5084 if Etype (N) /= Universal_Fixed then
5088 -- If the subprogram returns an array type, and the context requires the
5089 -- component type of that array type, the node is really an indexing of
5090 -- the parameterless call. Resolve as such. A pathological case occurs
5091 -- when the type of the component is an access to the array type. In
5092 -- this case the call is truly ambiguous.
5094 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
5096 ((Is_Array_Type (Etype (Nam))
5097 and then Covers (Typ, Component_Type (Etype (Nam))))
5098 or else (Is_Access_Type (Etype (Nam))
5099 and then Is_Array_Type (Designated_Type (Etype (Nam)))
5102 Component_Type (Designated_Type (Etype (Nam))))))
5105 Index_Node : Node_Id;
5107 Ret_Type : constant Entity_Id := Etype (Nam);
5110 if Is_Access_Type (Ret_Type)
5111 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
5114 ("cannot disambiguate function call and indexing", N);
5116 New_Subp := Relocate_Node (Subp);
5117 Set_Entity (Subp, Nam);
5119 if (Is_Array_Type (Ret_Type)
5120 and then Component_Type (Ret_Type) /= Any_Type)
5122 (Is_Access_Type (Ret_Type)
5124 Component_Type (Designated_Type (Ret_Type)) /= Any_Type)
5126 if Needs_No_Actuals (Nam) then
5128 -- Indexed call to a parameterless function
5131 Make_Indexed_Component (Loc,
5133 Make_Function_Call (Loc,
5135 Expressions => Parameter_Associations (N));
5137 -- An Ada 2005 prefixed call to a primitive operation
5138 -- whose first parameter is the prefix. This prefix was
5139 -- prepended to the parameter list, which is actually a
5140 -- list of indices. Remove the prefix in order to build
5141 -- the proper indexed component.
5144 Make_Indexed_Component (Loc,
5146 Make_Function_Call (Loc,
5148 Parameter_Associations =>
5150 (Remove_Head (Parameter_Associations (N)))),
5151 Expressions => Parameter_Associations (N));
5154 -- Preserve the parenthesis count of the node
5156 Set_Paren_Count (Index_Node, Paren_Count (N));
5158 -- Since we are correcting a node classification error made
5159 -- by the parser, we call Replace rather than Rewrite.
5161 Replace (N, Index_Node);
5163 Set_Etype (Prefix (N), Ret_Type);
5165 Resolve_Indexed_Component (N, Typ);
5166 Check_Elab_Call (Prefix (N));
5174 Set_Etype (N, Etype (Nam));
5177 -- In the case where the call is to an overloaded subprogram, Analyze
5178 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5179 -- such a case Normalize_Actuals needs to be called once more to order
5180 -- the actuals correctly. Otherwise the call will have the ordering
5181 -- given by the last overloaded subprogram whether this is the correct
5182 -- one being called or not.
5184 if Is_Overloaded (Subp) then
5185 Normalize_Actuals (N, Nam, False, Norm_OK);
5186 pragma Assert (Norm_OK);
5189 -- In any case, call is fully resolved now. Reset Overload flag, to
5190 -- prevent subsequent overload resolution if node is analyzed again
5192 Set_Is_Overloaded (Subp, False);
5193 Set_Is_Overloaded (N, False);
5195 -- If we are calling the current subprogram from immediately within its
5196 -- body, then that is the case where we can sometimes detect cases of
5197 -- infinite recursion statically. Do not try this in case restriction
5198 -- No_Recursion is in effect anyway, and do it only for source calls.
5200 if Comes_From_Source (N) then
5201 Scop := Current_Scope;
5203 -- Issue warning for possible infinite recursion in the absence
5204 -- of the No_Recursion restriction.
5206 if Same_Or_Aliased_Subprograms (Nam, Scop)
5207 and then not Restriction_Active (No_Recursion)
5208 and then Check_Infinite_Recursion (N)
5210 -- Here we detected and flagged an infinite recursion, so we do
5211 -- not need to test the case below for further warnings. Also if
5212 -- we now have a raise SE node, we are all done.
5214 if Nkind (N) = N_Raise_Storage_Error then
5218 -- If call is to immediately containing subprogram, then check for
5219 -- the case of a possible run-time detectable infinite recursion.
5222 Scope_Loop : while Scop /= Standard_Standard loop
5223 if Same_Or_Aliased_Subprograms (Nam, Scop) then
5225 -- Although in general case, recursion is not statically
5226 -- checkable, the case of calling an immediately containing
5227 -- subprogram is easy to catch.
5229 Check_Restriction (No_Recursion, N);
5231 -- If the recursive call is to a parameterless subprogram,
5232 -- then even if we can't statically detect infinite
5233 -- recursion, this is pretty suspicious, and we output a
5234 -- warning. Furthermore, we will try later to detect some
5235 -- cases here at run time by expanding checking code (see
5236 -- Detect_Infinite_Recursion in package Exp_Ch6).
5238 -- If the recursive call is within a handler, do not emit a
5239 -- warning, because this is a common idiom: loop until input
5240 -- is correct, catch illegal input in handler and restart.
5242 if No (First_Formal (Nam))
5243 and then Etype (Nam) = Standard_Void_Type
5244 and then not Error_Posted (N)
5245 and then Nkind (Parent (N)) /= N_Exception_Handler
5247 -- For the case of a procedure call. We give the message
5248 -- only if the call is the first statement in a sequence
5249 -- of statements, or if all previous statements are
5250 -- simple assignments. This is simply a heuristic to
5251 -- decrease false positives, without losing too many good
5252 -- warnings. The idea is that these previous statements
5253 -- may affect global variables the procedure depends on.
5255 if Nkind (N) = N_Procedure_Call_Statement
5256 and then Is_List_Member (N)
5262 while Present (P) loop
5263 if Nkind (P) /= N_Assignment_Statement then
5272 -- Do not give warning if we are in a conditional context
5275 K : constant Node_Kind := Nkind (Parent (N));
5277 if (K = N_Loop_Statement
5278 and then Present (Iteration_Scheme (Parent (N))))
5279 or else K = N_If_Statement
5280 or else K = N_Elsif_Part
5281 or else K = N_Case_Statement_Alternative
5287 -- Here warning is to be issued
5289 Set_Has_Recursive_Call (Nam);
5291 ("?possible infinite recursion!", N);
5293 ("\?Storage_Error may be raised at run time!", N);
5299 Scop := Scope (Scop);
5300 end loop Scope_Loop;
5304 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5306 Check_Obsolescent_2005_Entity (Nam, Subp);
5308 -- If subprogram name is a predefined operator, it was given in
5309 -- functional notation. Replace call node with operator node, so
5310 -- that actuals can be resolved appropriately.
5312 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5313 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5316 elsif Present (Alias (Nam))
5317 and then Is_Predefined_Op (Alias (Nam))
5319 Resolve_Actuals (N, Nam);
5320 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5324 -- Create a transient scope if the resulting type requires it
5326 -- There are several notable exceptions:
5328 -- a) In init procs, the transient scope overhead is not needed, and is
5329 -- even incorrect when the call is a nested initialization call for a
5330 -- component whose expansion may generate adjust calls. However, if the
5331 -- call is some other procedure call within an initialization procedure
5332 -- (for example a call to Create_Task in the init_proc of the task
5333 -- run-time record) a transient scope must be created around this call.
5335 -- b) Enumeration literal pseudo-calls need no transient scope
5337 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5338 -- functions) do not use the secondary stack even though the return
5339 -- type may be unconstrained.
5341 -- d) Calls to a build-in-place function, since such functions may
5342 -- allocate their result directly in a target object, and cases where
5343 -- the result does get allocated in the secondary stack are checked for
5344 -- within the specialized Exp_Ch6 procedures for expanding those
5345 -- build-in-place calls.
5347 -- e) If the subprogram is marked Inline_Always, then even if it returns
5348 -- an unconstrained type the call does not require use of the secondary
5349 -- stack. However, inlining will only take place if the body to inline
5350 -- is already present. It may not be available if e.g. the subprogram is
5351 -- declared in a child instance.
5353 -- If this is an initialization call for a type whose construction
5354 -- uses the secondary stack, and it is not a nested call to initialize
5355 -- a component, we do need to create a transient scope for it. We
5356 -- check for this by traversing the type in Check_Initialization_Call.
5359 and then Has_Pragma_Inline_Always (Nam)
5360 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5361 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5365 elsif Ekind (Nam) = E_Enumeration_Literal
5366 or else Is_Build_In_Place_Function (Nam)
5367 or else Is_Intrinsic_Subprogram (Nam)
5371 elsif Expander_Active
5372 and then Is_Type (Etype (Nam))
5373 and then Requires_Transient_Scope (Etype (Nam))
5375 (not Within_Init_Proc
5377 (not Is_Init_Proc (Nam) and then Ekind (Nam) /= E_Function))
5379 Establish_Transient_Scope (N, Sec_Stack => True);
5381 -- If the call appears within the bounds of a loop, it will
5382 -- be rewritten and reanalyzed, nothing left to do here.
5384 if Nkind (N) /= N_Function_Call then
5388 elsif Is_Init_Proc (Nam)
5389 and then not Within_Init_Proc
5391 Check_Initialization_Call (N, Nam);
5394 -- A protected function cannot be called within the definition of the
5395 -- enclosing protected type.
5397 if Is_Protected_Type (Scope (Nam))
5398 and then In_Open_Scopes (Scope (Nam))
5399 and then not Has_Completion (Scope (Nam))
5402 ("& cannot be called before end of protected definition", N, Nam);
5405 -- Propagate interpretation to actuals, and add default expressions
5408 if Present (First_Formal (Nam)) then
5409 Resolve_Actuals (N, Nam);
5411 -- Overloaded literals are rewritten as function calls, for purpose of
5412 -- resolution. After resolution, we can replace the call with the
5415 elsif Ekind (Nam) = E_Enumeration_Literal then
5416 Copy_Node (Subp, N);
5417 Resolve_Entity_Name (N, Typ);
5419 -- Avoid validation, since it is a static function call
5421 Generate_Reference (Nam, Subp);
5425 -- If the subprogram is not global, then kill all saved values and
5426 -- checks. This is a bit conservative, since in many cases we could do
5427 -- better, but it is not worth the effort. Similarly, we kill constant
5428 -- values. However we do not need to do this for internal entities
5429 -- (unless they are inherited user-defined subprograms), since they
5430 -- are not in the business of molesting local values.
5432 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5433 -- kill all checks and values for calls to global subprograms. This
5434 -- takes care of the case where an access to a local subprogram is
5435 -- taken, and could be passed directly or indirectly and then called
5436 -- from almost any context.
5438 -- Note: we do not do this step till after resolving the actuals. That
5439 -- way we still take advantage of the current value information while
5440 -- scanning the actuals.
5442 -- We suppress killing values if we are processing the nodes associated
5443 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5444 -- type kills all the values as part of analyzing the code that
5445 -- initializes the dispatch tables.
5447 if Inside_Freezing_Actions = 0
5448 and then (not Is_Library_Level_Entity (Nam)
5449 or else Suppress_Value_Tracking_On_Call
5450 (Nearest_Dynamic_Scope (Current_Scope)))
5451 and then (Comes_From_Source (Nam)
5452 or else (Present (Alias (Nam))
5453 and then Comes_From_Source (Alias (Nam))))
5455 Kill_Current_Values;
5458 -- If we are warning about unread OUT parameters, this is the place to
5459 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5460 -- after the above call to Kill_Current_Values (since that call clears
5461 -- the Last_Assignment field of all local variables).
5463 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5464 and then Comes_From_Source (N)
5465 and then In_Extended_Main_Source_Unit (N)
5472 F := First_Formal (Nam);
5473 A := First_Actual (N);
5474 while Present (F) and then Present (A) loop
5475 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter)
5476 and then Warn_On_Modified_As_Out_Parameter (F)
5477 and then Is_Entity_Name (A)
5478 and then Present (Entity (A))
5479 and then Comes_From_Source (N)
5480 and then Safe_To_Capture_Value (N, Entity (A))
5482 Set_Last_Assignment (Entity (A), A);
5491 -- If the subprogram is a primitive operation, check whether or not
5492 -- it is a correct dispatching call.
5494 if Is_Overloadable (Nam)
5495 and then Is_Dispatching_Operation (Nam)
5497 Check_Dispatching_Call (N);
5499 elsif Ekind (Nam) /= E_Subprogram_Type
5500 and then Is_Abstract_Subprogram (Nam)
5501 and then not In_Instance
5503 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5506 -- If this is a dispatching call, generate the appropriate reference,
5507 -- for better source navigation in GPS.
5509 if Is_Overloadable (Nam)
5510 and then Present (Controlling_Argument (N))
5512 Generate_Reference (Nam, Subp, 'R');
5514 -- Normal case, not a dispatching call
5517 Generate_Reference (Nam, Subp);
5520 if Is_Intrinsic_Subprogram (Nam) then
5521 Check_Intrinsic_Call (N);
5524 -- Check for violation of restriction No_Specific_Termination_Handlers
5525 -- and warn on a potentially blocking call to Abort_Task.
5527 if Is_RTE (Nam, RE_Set_Specific_Handler)
5529 Is_RTE (Nam, RE_Specific_Handler)
5531 Check_Restriction (No_Specific_Termination_Handlers, N);
5533 elsif Is_RTE (Nam, RE_Abort_Task) then
5534 Check_Potentially_Blocking_Operation (N);
5537 -- Issue an error for a call to an eliminated subprogram. We skip this
5538 -- in a spec expression, e.g. a call in a default parameter value, since
5539 -- we are not really doing a call at this time. That's important because
5540 -- the spec expression may itself belong to an eliminated subprogram.
5542 if not In_Spec_Expression then
5543 Check_For_Eliminated_Subprogram (Subp, Nam);
5546 -- All done, evaluate call and deal with elaboration issues
5549 Check_Elab_Call (N);
5550 Warn_On_Overlapping_Actuals (Nam, N);
5553 -----------------------------
5554 -- Resolve_Case_Expression --
5555 -----------------------------
5557 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id) is
5561 Alt := First (Alternatives (N));
5562 while Present (Alt) loop
5563 Resolve (Expression (Alt), Typ);
5568 Eval_Case_Expression (N);
5569 end Resolve_Case_Expression;
5571 -------------------------------
5572 -- Resolve_Character_Literal --
5573 -------------------------------
5575 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5576 B_Typ : constant Entity_Id := Base_Type (Typ);
5580 -- Verify that the character does belong to the type of the context
5582 Set_Etype (N, B_Typ);
5583 Eval_Character_Literal (N);
5585 -- Wide_Wide_Character literals must always be defined, since the set
5586 -- of wide wide character literals is complete, i.e. if a character
5587 -- literal is accepted by the parser, then it is OK for wide wide
5588 -- character (out of range character literals are rejected).
5590 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5593 -- Always accept character literal for type Any_Character, which
5594 -- occurs in error situations and in comparisons of literals, both
5595 -- of which should accept all literals.
5597 elsif B_Typ = Any_Character then
5600 -- For Standard.Character or a type derived from it, check that
5601 -- the literal is in range
5603 elsif Root_Type (B_Typ) = Standard_Character then
5604 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5608 -- For Standard.Wide_Character or a type derived from it, check
5609 -- that the literal is in range
5611 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5612 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5616 -- For Standard.Wide_Wide_Character or a type derived from it, we
5617 -- know the literal is in range, since the parser checked!
5619 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5622 -- If the entity is already set, this has already been resolved in a
5623 -- generic context, or comes from expansion. Nothing else to do.
5625 elsif Present (Entity (N)) then
5628 -- Otherwise we have a user defined character type, and we can use the
5629 -- standard visibility mechanisms to locate the referenced entity.
5632 C := Current_Entity (N);
5633 while Present (C) loop
5634 if Etype (C) = B_Typ then
5635 Set_Entity_With_Style_Check (N, C);
5636 Generate_Reference (C, N);
5644 -- If we fall through, then the literal does not match any of the
5645 -- entries of the enumeration type. This isn't just a constraint
5646 -- error situation, it is an illegality (see RM 4.2).
5649 ("character not defined for }", N, First_Subtype (B_Typ));
5650 end Resolve_Character_Literal;
5652 ---------------------------
5653 -- Resolve_Comparison_Op --
5654 ---------------------------
5656 -- Context requires a boolean type, and plays no role in resolution.
5657 -- Processing identical to that for equality operators. The result
5658 -- type is the base type, which matters when pathological subtypes of
5659 -- booleans with limited ranges are used.
5661 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
5662 L : constant Node_Id := Left_Opnd (N);
5663 R : constant Node_Id := Right_Opnd (N);
5667 -- If this is an intrinsic operation which is not predefined, use the
5668 -- types of its declared arguments to resolve the possibly overloaded
5669 -- operands. Otherwise the operands are unambiguous and specify the
5672 if Scope (Entity (N)) /= Standard_Standard then
5673 T := Etype (First_Entity (Entity (N)));
5676 T := Find_Unique_Type (L, R);
5678 if T = Any_Fixed then
5679 T := Unique_Fixed_Point_Type (L);
5683 Set_Etype (N, Base_Type (Typ));
5684 Generate_Reference (T, N, ' ');
5686 -- Skip remaining processing if already set to Any_Type
5688 if T = Any_Type then
5692 -- Deal with other error cases
5694 if T = Any_String or else
5695 T = Any_Composite or else
5698 if T = Any_Character then
5699 Ambiguous_Character (L);
5701 Error_Msg_N ("ambiguous operands for comparison", N);
5704 Set_Etype (N, Any_Type);
5708 -- Resolve the operands if types OK
5712 Check_Unset_Reference (L);
5713 Check_Unset_Reference (R);
5714 Generate_Operator_Reference (N, T);
5715 Check_Low_Bound_Tested (N);
5717 -- Check comparison on unordered enumeration
5719 if Comes_From_Source (N)
5720 and then Bad_Unordered_Enumeration_Reference (N, Etype (L))
5722 Error_Msg_N ("comparison on unordered enumeration type?", N);
5725 -- Evaluate the relation (note we do this after the above check
5726 -- since this Eval call may change N to True/False.
5728 Eval_Relational_Op (N);
5729 end Resolve_Comparison_Op;
5731 ------------------------------------
5732 -- Resolve_Conditional_Expression --
5733 ------------------------------------
5735 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
5736 Condition : constant Node_Id := First (Expressions (N));
5737 Then_Expr : constant Node_Id := Next (Condition);
5738 Else_Expr : Node_Id := Next (Then_Expr);
5741 Resolve (Condition, Any_Boolean);
5742 Resolve (Then_Expr, Typ);
5744 -- If ELSE expression present, just resolve using the determined type
5746 if Present (Else_Expr) then
5747 Resolve (Else_Expr, Typ);
5749 -- If no ELSE expression is present, root type must be Standard.Boolean
5750 -- and we provide a Standard.True result converted to the appropriate
5751 -- Boolean type (in case it is a derived boolean type).
5753 elsif Root_Type (Typ) = Standard_Boolean then
5755 Convert_To (Typ, New_Occurrence_Of (Standard_True, Sloc (N)));
5756 Analyze_And_Resolve (Else_Expr, Typ);
5757 Append_To (Expressions (N), Else_Expr);
5760 Error_Msg_N ("can only omit ELSE expression in Boolean case", N);
5761 Append_To (Expressions (N), Error);
5765 Eval_Conditional_Expression (N);
5766 end Resolve_Conditional_Expression;
5768 -----------------------------------------
5769 -- Resolve_Discrete_Subtype_Indication --
5770 -----------------------------------------
5772 procedure Resolve_Discrete_Subtype_Indication
5780 Analyze (Subtype_Mark (N));
5781 S := Entity (Subtype_Mark (N));
5783 if Nkind (Constraint (N)) /= N_Range_Constraint then
5784 Error_Msg_N ("expect range constraint for discrete type", N);
5785 Set_Etype (N, Any_Type);
5788 R := Range_Expression (Constraint (N));
5796 if Base_Type (S) /= Base_Type (Typ) then
5798 ("expect subtype of }", N, First_Subtype (Typ));
5800 -- Rewrite the constraint as a range of Typ
5801 -- to allow compilation to proceed further.
5804 Rewrite (Low_Bound (R),
5805 Make_Attribute_Reference (Sloc (Low_Bound (R)),
5806 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5807 Attribute_Name => Name_First));
5808 Rewrite (High_Bound (R),
5809 Make_Attribute_Reference (Sloc (High_Bound (R)),
5810 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
5811 Attribute_Name => Name_First));
5815 Set_Etype (N, Etype (R));
5817 -- Additionally, we must check that the bounds are compatible
5818 -- with the given subtype, which might be different from the
5819 -- type of the context.
5821 Apply_Range_Check (R, S);
5823 -- ??? If the above check statically detects a Constraint_Error
5824 -- it replaces the offending bound(s) of the range R with a
5825 -- Constraint_Error node. When the itype which uses these bounds
5826 -- is frozen the resulting call to Duplicate_Subexpr generates
5827 -- a new temporary for the bounds.
5829 -- Unfortunately there are other itypes that are also made depend
5830 -- on these bounds, so when Duplicate_Subexpr is called they get
5831 -- a forward reference to the newly created temporaries and Gigi
5832 -- aborts on such forward references. This is probably sign of a
5833 -- more fundamental problem somewhere else in either the order of
5834 -- itype freezing or the way certain itypes are constructed.
5836 -- To get around this problem we call Remove_Side_Effects right
5837 -- away if either bounds of R are a Constraint_Error.
5840 L : constant Node_Id := Low_Bound (R);
5841 H : constant Node_Id := High_Bound (R);
5844 if Nkind (L) = N_Raise_Constraint_Error then
5845 Remove_Side_Effects (L);
5848 if Nkind (H) = N_Raise_Constraint_Error then
5849 Remove_Side_Effects (H);
5853 Check_Unset_Reference (Low_Bound (R));
5854 Check_Unset_Reference (High_Bound (R));
5857 end Resolve_Discrete_Subtype_Indication;
5859 -------------------------
5860 -- Resolve_Entity_Name --
5861 -------------------------
5863 -- Used to resolve identifiers and expanded names
5865 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
5866 E : constant Entity_Id := Entity (N);
5869 -- If garbage from errors, set to Any_Type and return
5871 if No (E) and then Total_Errors_Detected /= 0 then
5872 Set_Etype (N, Any_Type);
5876 -- Replace named numbers by corresponding literals. Note that this is
5877 -- the one case where Resolve_Entity_Name must reset the Etype, since
5878 -- it is currently marked as universal.
5880 if Ekind (E) = E_Named_Integer then
5882 Eval_Named_Integer (N);
5884 elsif Ekind (E) = E_Named_Real then
5886 Eval_Named_Real (N);
5888 -- For enumeration literals, we need to make sure that a proper style
5889 -- check is done, since such literals are overloaded, and thus we did
5890 -- not do a style check during the first phase of analysis.
5892 elsif Ekind (E) = E_Enumeration_Literal then
5893 Set_Entity_With_Style_Check (N, E);
5894 Eval_Entity_Name (N);
5896 -- Allow use of subtype only if it is a concurrent type where we are
5897 -- currently inside the body. This will eventually be expanded into a
5898 -- call to Self (for tasks) or _object (for protected objects). Any
5899 -- other use of a subtype is invalid.
5901 elsif Is_Type (E) then
5902 if Is_Concurrent_Type (E)
5903 and then In_Open_Scopes (E)
5908 ("invalid use of subtype mark in expression or call", N);
5911 -- Check discriminant use if entity is discriminant in current scope,
5912 -- i.e. discriminant of record or concurrent type currently being
5913 -- analyzed. Uses in corresponding body are unrestricted.
5915 elsif Ekind (E) = E_Discriminant
5916 and then Scope (E) = Current_Scope
5917 and then not Has_Completion (Current_Scope)
5919 Check_Discriminant_Use (N);
5921 -- A parameterless generic function cannot appear in a context that
5922 -- requires resolution.
5924 elsif Ekind (E) = E_Generic_Function then
5925 Error_Msg_N ("illegal use of generic function", N);
5927 elsif Ekind (E) = E_Out_Parameter
5928 and then Ada_Version = Ada_83
5929 and then (Nkind (Parent (N)) in N_Op
5930 or else (Nkind (Parent (N)) = N_Assignment_Statement
5931 and then N = Expression (Parent (N)))
5932 or else Nkind (Parent (N)) = N_Explicit_Dereference)
5934 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
5936 -- In all other cases, just do the possible static evaluation
5939 -- A deferred constant that appears in an expression must have a
5940 -- completion, unless it has been removed by in-place expansion of
5943 if Ekind (E) = E_Constant
5944 and then Comes_From_Source (E)
5945 and then No (Constant_Value (E))
5946 and then Is_Frozen (Etype (E))
5947 and then not In_Spec_Expression
5948 and then not Is_Imported (E)
5950 if No_Initialization (Parent (E))
5951 or else (Present (Full_View (E))
5952 and then No_Initialization (Parent (Full_View (E))))
5957 "deferred constant is frozen before completion", N);
5961 Eval_Entity_Name (N);
5963 end Resolve_Entity_Name;
5969 procedure Resolve_Entry (Entry_Name : Node_Id) is
5970 Loc : constant Source_Ptr := Sloc (Entry_Name);
5978 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
5979 -- If the bounds of the entry family being called depend on task
5980 -- discriminants, build a new index subtype where a discriminant is
5981 -- replaced with the value of the discriminant of the target task.
5982 -- The target task is the prefix of the entry name in the call.
5984 -----------------------
5985 -- Actual_Index_Type --
5986 -----------------------
5988 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
5989 Typ : constant Entity_Id := Entry_Index_Type (E);
5990 Tsk : constant Entity_Id := Scope (E);
5991 Lo : constant Node_Id := Type_Low_Bound (Typ);
5992 Hi : constant Node_Id := Type_High_Bound (Typ);
5995 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
5996 -- If the bound is given by a discriminant, replace with a reference
5997 -- to the discriminant of the same name in the target task. If the
5998 -- entry name is the target of a requeue statement and the entry is
5999 -- in the current protected object, the bound to be used is the
6000 -- discriminal of the object (see Apply_Range_Checks for details of
6001 -- the transformation).
6003 -----------------------------
6004 -- Actual_Discriminant_Ref --
6005 -----------------------------
6007 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
6008 Typ : constant Entity_Id := Etype (Bound);
6012 Remove_Side_Effects (Bound);
6014 if not Is_Entity_Name (Bound)
6015 or else Ekind (Entity (Bound)) /= E_Discriminant
6019 elsif Is_Protected_Type (Tsk)
6020 and then In_Open_Scopes (Tsk)
6021 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
6023 -- Note: here Bound denotes a discriminant of the corresponding
6024 -- record type tskV, whose discriminal is a formal of the
6025 -- init-proc tskVIP. What we want is the body discriminal,
6026 -- which is associated to the discriminant of the original
6027 -- concurrent type tsk.
6029 return New_Occurrence_Of
6030 (Find_Body_Discriminal (Entity (Bound)), Loc);
6034 Make_Selected_Component (Loc,
6035 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
6036 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
6041 end Actual_Discriminant_Ref;
6043 -- Start of processing for Actual_Index_Type
6046 if not Has_Discriminants (Tsk)
6047 or else (not Is_Entity_Name (Lo)
6049 not Is_Entity_Name (Hi))
6051 return Entry_Index_Type (E);
6054 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
6055 Set_Etype (New_T, Base_Type (Typ));
6056 Set_Size_Info (New_T, Typ);
6057 Set_RM_Size (New_T, RM_Size (Typ));
6058 Set_Scalar_Range (New_T,
6059 Make_Range (Sloc (Entry_Name),
6060 Low_Bound => Actual_Discriminant_Ref (Lo),
6061 High_Bound => Actual_Discriminant_Ref (Hi)));
6065 end Actual_Index_Type;
6067 -- Start of processing of Resolve_Entry
6070 -- Find name of entry being called, and resolve prefix of name
6071 -- with its own type. The prefix can be overloaded, and the name
6072 -- and signature of the entry must be taken into account.
6074 if Nkind (Entry_Name) = N_Indexed_Component then
6076 -- Case of dealing with entry family within the current tasks
6078 E_Name := Prefix (Entry_Name);
6081 E_Name := Entry_Name;
6084 if Is_Entity_Name (E_Name) then
6086 -- Entry call to an entry (or entry family) in the current task. This
6087 -- is legal even though the task will deadlock. Rewrite as call to
6090 -- This can also be a call to an entry in an enclosing task. If this
6091 -- is a single task, we have to retrieve its name, because the scope
6092 -- of the entry is the task type, not the object. If the enclosing
6093 -- task is a task type, the identity of the task is given by its own
6096 -- Finally this can be a requeue on an entry of the same task or
6097 -- protected object.
6099 S := Scope (Entity (E_Name));
6101 for J in reverse 0 .. Scope_Stack.Last loop
6102 if Is_Task_Type (Scope_Stack.Table (J).Entity)
6103 and then not Comes_From_Source (S)
6105 -- S is an enclosing task or protected object. The concurrent
6106 -- declaration has been converted into a type declaration, and
6107 -- the object itself has an object declaration that follows
6108 -- the type in the same declarative part.
6110 Tsk := Next_Entity (S);
6111 while Etype (Tsk) /= S loop
6118 elsif S = Scope_Stack.Table (J).Entity then
6120 -- Call to current task. Will be transformed into call to Self
6128 Make_Selected_Component (Loc,
6129 Prefix => New_Occurrence_Of (S, Loc),
6131 New_Occurrence_Of (Entity (E_Name), Loc));
6132 Rewrite (E_Name, New_N);
6135 elsif Nkind (Entry_Name) = N_Selected_Component
6136 and then Is_Overloaded (Prefix (Entry_Name))
6138 -- Use the entry name (which must be unique at this point) to find
6139 -- the prefix that returns the corresponding task type or protected
6143 Pref : constant Node_Id := Prefix (Entry_Name);
6144 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
6149 Get_First_Interp (Pref, I, It);
6150 while Present (It.Typ) loop
6151 if Scope (Ent) = It.Typ then
6152 Set_Etype (Pref, It.Typ);
6156 Get_Next_Interp (I, It);
6161 if Nkind (Entry_Name) = N_Selected_Component then
6162 Resolve (Prefix (Entry_Name));
6164 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6165 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6166 Resolve (Prefix (Prefix (Entry_Name)));
6167 Index := First (Expressions (Entry_Name));
6168 Resolve (Index, Entry_Index_Type (Nam));
6170 -- Up to this point the expression could have been the actual in a
6171 -- simple entry call, and be given by a named association.
6173 if Nkind (Index) = N_Parameter_Association then
6174 Error_Msg_N ("expect expression for entry index", Index);
6176 Apply_Range_Check (Index, Actual_Index_Type (Nam));
6181 ------------------------
6182 -- Resolve_Entry_Call --
6183 ------------------------
6185 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
6186 Entry_Name : constant Node_Id := Name (N);
6187 Loc : constant Source_Ptr := Sloc (Entry_Name);
6189 First_Named : Node_Id;
6196 -- We kill all checks here, because it does not seem worth the effort to
6197 -- do anything better, an entry call is a big operation.
6201 -- Processing of the name is similar for entry calls and protected
6202 -- operation calls. Once the entity is determined, we can complete
6203 -- the resolution of the actuals.
6205 -- The selector may be overloaded, in the case of a protected object
6206 -- with overloaded functions. The type of the context is used for
6209 if Nkind (Entry_Name) = N_Selected_Component
6210 and then Is_Overloaded (Selector_Name (Entry_Name))
6211 and then Typ /= Standard_Void_Type
6218 Get_First_Interp (Selector_Name (Entry_Name), I, It);
6219 while Present (It.Typ) loop
6220 if Covers (Typ, It.Typ) then
6221 Set_Entity (Selector_Name (Entry_Name), It.Nam);
6222 Set_Etype (Entry_Name, It.Typ);
6224 Generate_Reference (It.Typ, N, ' ');
6227 Get_Next_Interp (I, It);
6232 Resolve_Entry (Entry_Name);
6234 if Nkind (Entry_Name) = N_Selected_Component then
6236 -- Simple entry call
6238 Nam := Entity (Selector_Name (Entry_Name));
6239 Obj := Prefix (Entry_Name);
6240 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
6242 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6244 -- Call to member of entry family
6246 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6247 Obj := Prefix (Prefix (Entry_Name));
6248 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
6251 -- We cannot in general check the maximum depth of protected entry
6252 -- calls at compile time. But we can tell that any protected entry
6253 -- call at all violates a specified nesting depth of zero.
6255 if Is_Protected_Type (Scope (Nam)) then
6256 Check_Restriction (Max_Entry_Queue_Length, N);
6259 -- Use context type to disambiguate a protected function that can be
6260 -- called without actuals and that returns an array type, and where
6261 -- the argument list may be an indexing of the returned value.
6263 if Ekind (Nam) = E_Function
6264 and then Needs_No_Actuals (Nam)
6265 and then Present (Parameter_Associations (N))
6267 ((Is_Array_Type (Etype (Nam))
6268 and then Covers (Typ, Component_Type (Etype (Nam))))
6270 or else (Is_Access_Type (Etype (Nam))
6271 and then Is_Array_Type (Designated_Type (Etype (Nam)))
6272 and then Covers (Typ,
6273 Component_Type (Designated_Type (Etype (Nam))))))
6276 Index_Node : Node_Id;
6280 Make_Indexed_Component (Loc,
6282 Make_Function_Call (Loc,
6283 Name => Relocate_Node (Entry_Name)),
6284 Expressions => Parameter_Associations (N));
6286 -- Since we are correcting a node classification error made by
6287 -- the parser, we call Replace rather than Rewrite.
6289 Replace (N, Index_Node);
6290 Set_Etype (Prefix (N), Etype (Nam));
6292 Resolve_Indexed_Component (N, Typ);
6297 -- The operation name may have been overloaded. Order the actuals
6298 -- according to the formals of the resolved entity, and set the
6299 -- return type to that of the operation.
6302 Normalize_Actuals (N, Nam, False, Norm_OK);
6303 pragma Assert (Norm_OK);
6304 Set_Etype (N, Etype (Nam));
6307 Resolve_Actuals (N, Nam);
6308 Generate_Reference (Nam, Entry_Name);
6310 if Ekind_In (Nam, E_Entry, E_Entry_Family) then
6311 Check_Potentially_Blocking_Operation (N);
6314 -- Verify that a procedure call cannot masquerade as an entry
6315 -- call where an entry call is expected.
6317 if Ekind (Nam) = E_Procedure then
6318 if Nkind (Parent (N)) = N_Entry_Call_Alternative
6319 and then N = Entry_Call_Statement (Parent (N))
6321 Error_Msg_N ("entry call required in select statement", N);
6323 elsif Nkind (Parent (N)) = N_Triggering_Alternative
6324 and then N = Triggering_Statement (Parent (N))
6326 Error_Msg_N ("triggering statement cannot be procedure call", N);
6328 elsif Ekind (Scope (Nam)) = E_Task_Type
6329 and then not In_Open_Scopes (Scope (Nam))
6331 Error_Msg_N ("task has no entry with this name", Entry_Name);
6335 -- After resolution, entry calls and protected procedure calls are
6336 -- changed into entry calls, for expansion. The structure of the node
6337 -- does not change, so it can safely be done in place. Protected
6338 -- function calls must keep their structure because they are
6341 if Ekind (Nam) /= E_Function then
6343 -- A protected operation that is not a function may modify the
6344 -- corresponding object, and cannot apply to a constant. If this
6345 -- is an internal call, the prefix is the type itself.
6347 if Is_Protected_Type (Scope (Nam))
6348 and then not Is_Variable (Obj)
6349 and then (not Is_Entity_Name (Obj)
6350 or else not Is_Type (Entity (Obj)))
6353 ("prefix of protected procedure or entry call must be variable",
6357 Actuals := Parameter_Associations (N);
6358 First_Named := First_Named_Actual (N);
6361 Make_Entry_Call_Statement (Loc,
6363 Parameter_Associations => Actuals));
6365 Set_First_Named_Actual (N, First_Named);
6366 Set_Analyzed (N, True);
6368 -- Protected functions can return on the secondary stack, in which
6369 -- case we must trigger the transient scope mechanism.
6371 elsif Expander_Active
6372 and then Requires_Transient_Scope (Etype (Nam))
6374 Establish_Transient_Scope (N, Sec_Stack => True);
6376 end Resolve_Entry_Call;
6378 -------------------------
6379 -- Resolve_Equality_Op --
6380 -------------------------
6382 -- Both arguments must have the same type, and the boolean context does
6383 -- not participate in the resolution. The first pass verifies that the
6384 -- interpretation is not ambiguous, and the type of the left argument is
6385 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6386 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6387 -- though they carry a single (universal) type. Diagnose this case here.
6389 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6390 L : constant Node_Id := Left_Opnd (N);
6391 R : constant Node_Id := Right_Opnd (N);
6392 T : Entity_Id := Find_Unique_Type (L, R);
6394 procedure Check_Conditional_Expression (Cond : Node_Id);
6395 -- The resolution rule for conditional expressions requires that each
6396 -- such must have a unique type. This means that if several dependent
6397 -- expressions are of a non-null anonymous access type, and the context
6398 -- does not impose an expected type (as can be the case in an equality
6399 -- operation) the expression must be rejected.
6401 function Find_Unique_Access_Type return Entity_Id;
6402 -- In the case of allocators, make a last-ditch attempt to find a single
6403 -- access type with the right designated type. This is semantically
6404 -- dubious, and of no interest to any real code, but c48008a makes it
6407 ----------------------------------
6408 -- Check_Conditional_Expression --
6409 ----------------------------------
6411 procedure Check_Conditional_Expression (Cond : Node_Id) is
6412 Then_Expr : Node_Id;
6413 Else_Expr : Node_Id;
6416 if Nkind (Cond) = N_Conditional_Expression then
6417 Then_Expr := Next (First (Expressions (Cond)));
6418 Else_Expr := Next (Then_Expr);
6420 if Nkind (Then_Expr) /= N_Null
6421 and then Nkind (Else_Expr) /= N_Null
6424 ("cannot determine type of conditional expression", Cond);
6427 end Check_Conditional_Expression;
6429 -----------------------------
6430 -- Find_Unique_Access_Type --
6431 -----------------------------
6433 function Find_Unique_Access_Type return Entity_Id is
6439 if Ekind (Etype (R)) = E_Allocator_Type then
6440 Acc := Designated_Type (Etype (R));
6441 elsif Ekind (Etype (L)) = E_Allocator_Type then
6442 Acc := Designated_Type (Etype (L));
6448 while S /= Standard_Standard loop
6449 E := First_Entity (S);
6450 while Present (E) loop
6452 and then Is_Access_Type (E)
6453 and then Ekind (E) /= E_Allocator_Type
6454 and then Designated_Type (E) = Base_Type (Acc)
6466 end Find_Unique_Access_Type;
6468 -- Start of processing for Resolve_Equality_Op
6471 Set_Etype (N, Base_Type (Typ));
6472 Generate_Reference (T, N, ' ');
6474 if T = Any_Fixed then
6475 T := Unique_Fixed_Point_Type (L);
6478 if T /= Any_Type then
6480 or else T = Any_Composite
6481 or else T = Any_Character
6483 if T = Any_Character then
6484 Ambiguous_Character (L);
6486 Error_Msg_N ("ambiguous operands for equality", N);
6489 Set_Etype (N, Any_Type);
6492 elsif T = Any_Access
6493 or else Ekind_In (T, E_Allocator_Type, E_Access_Attribute_Type)
6495 T := Find_Unique_Access_Type;
6498 Error_Msg_N ("ambiguous operands for equality", N);
6499 Set_Etype (N, Any_Type);
6503 -- Conditional expressions must have a single type, and if the
6504 -- context does not impose one the dependent expressions cannot
6505 -- be anonymous access types.
6507 elsif Ada_Version >= Ada_2012
6508 and then Ekind_In (Etype (L),
6509 E_Anonymous_Access_Type,
6510 E_Anonymous_Access_Subprogram_Type)
6512 and then Ekind_In (Etype (R),
6513 E_Anonymous_Access_Type,
6514 E_Anonymous_Access_Subprogram_Type)
6516 Check_Conditional_Expression (L);
6517 Check_Conditional_Expression (R);
6523 -- If the unique type is a class-wide type then it will be expanded
6524 -- into a dispatching call to the predefined primitive. Therefore we
6525 -- check here for potential violation of such restriction.
6527 if Is_Class_Wide_Type (T) then
6528 Check_Restriction (No_Dispatching_Calls, N);
6531 if Warn_On_Redundant_Constructs
6532 and then Comes_From_Source (N)
6533 and then Is_Entity_Name (R)
6534 and then Entity (R) = Standard_True
6535 and then Comes_From_Source (R)
6537 Error_Msg_N -- CODEFIX
6538 ("?comparison with True is redundant!", R);
6541 Check_Unset_Reference (L);
6542 Check_Unset_Reference (R);
6543 Generate_Operator_Reference (N, T);
6544 Check_Low_Bound_Tested (N);
6546 -- If this is an inequality, it may be the implicit inequality
6547 -- created for a user-defined operation, in which case the corres-
6548 -- ponding equality operation is not intrinsic, and the operation
6549 -- cannot be constant-folded. Else fold.
6551 if Nkind (N) = N_Op_Eq
6552 or else Comes_From_Source (Entity (N))
6553 or else Ekind (Entity (N)) = E_Operator
6554 or else Is_Intrinsic_Subprogram
6555 (Corresponding_Equality (Entity (N)))
6557 Eval_Relational_Op (N);
6559 elsif Nkind (N) = N_Op_Ne
6560 and then Is_Abstract_Subprogram (Entity (N))
6562 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6565 -- Ada 2005: If one operand is an anonymous access type, convert the
6566 -- other operand to it, to ensure that the underlying types match in
6567 -- the back-end. Same for access_to_subprogram, and the conversion
6568 -- verifies that the types are subtype conformant.
6570 -- We apply the same conversion in the case one of the operands is a
6571 -- private subtype of the type of the other.
6573 -- Why the Expander_Active test here ???
6577 (Ekind_In (T, E_Anonymous_Access_Type,
6578 E_Anonymous_Access_Subprogram_Type)
6579 or else Is_Private_Type (T))
6581 if Etype (L) /= T then
6583 Make_Unchecked_Type_Conversion (Sloc (L),
6584 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
6585 Expression => Relocate_Node (L)));
6586 Analyze_And_Resolve (L, T);
6589 if (Etype (R)) /= T then
6591 Make_Unchecked_Type_Conversion (Sloc (R),
6592 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
6593 Expression => Relocate_Node (R)));
6594 Analyze_And_Resolve (R, T);
6598 end Resolve_Equality_Op;
6600 ----------------------------------
6601 -- Resolve_Explicit_Dereference --
6602 ----------------------------------
6604 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
6605 Loc : constant Source_Ptr := Sloc (N);
6607 P : constant Node_Id := Prefix (N);
6612 Check_Fully_Declared_Prefix (Typ, P);
6614 if Is_Overloaded (P) then
6616 -- Use the context type to select the prefix that has the correct
6619 Get_First_Interp (P, I, It);
6620 while Present (It.Typ) loop
6621 exit when Is_Access_Type (It.Typ)
6622 and then Covers (Typ, Designated_Type (It.Typ));
6623 Get_Next_Interp (I, It);
6626 if Present (It.Typ) then
6627 Resolve (P, It.Typ);
6629 -- If no interpretation covers the designated type of the prefix,
6630 -- this is the pathological case where not all implementations of
6631 -- the prefix allow the interpretation of the node as a call. Now
6632 -- that the expected type is known, Remove other interpretations
6633 -- from prefix, rewrite it as a call, and resolve again, so that
6634 -- the proper call node is generated.
6636 Get_First_Interp (P, I, It);
6637 while Present (It.Typ) loop
6638 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
6642 Get_Next_Interp (I, It);
6646 Make_Function_Call (Loc,
6648 Make_Explicit_Dereference (Loc,
6650 Parameter_Associations => New_List);
6652 Save_Interps (N, New_N);
6654 Analyze_And_Resolve (N, Typ);
6658 Set_Etype (N, Designated_Type (It.Typ));
6664 if Is_Access_Type (Etype (P)) then
6665 Apply_Access_Check (N);
6668 -- If the designated type is a packed unconstrained array type, and the
6669 -- explicit dereference is not in the context of an attribute reference,
6670 -- then we must compute and set the actual subtype, since it is needed
6671 -- by Gigi. The reason we exclude the attribute case is that this is
6672 -- handled fine by Gigi, and in fact we use such attributes to build the
6673 -- actual subtype. We also exclude generated code (which builds actual
6674 -- subtypes directly if they are needed).
6676 if Is_Array_Type (Etype (N))
6677 and then Is_Packed (Etype (N))
6678 and then not Is_Constrained (Etype (N))
6679 and then Nkind (Parent (N)) /= N_Attribute_Reference
6680 and then Comes_From_Source (N)
6682 Set_Etype (N, Get_Actual_Subtype (N));
6685 -- Note: No Eval processing is required for an explicit dereference,
6686 -- because such a name can never be static.
6688 end Resolve_Explicit_Dereference;
6690 -------------------------------------
6691 -- Resolve_Expression_With_Actions --
6692 -------------------------------------
6694 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id) is
6697 end Resolve_Expression_With_Actions;
6699 -------------------------------
6700 -- Resolve_Indexed_Component --
6701 -------------------------------
6703 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
6704 Name : constant Node_Id := Prefix (N);
6706 Array_Type : Entity_Id := Empty; -- to prevent junk warning
6710 if Is_Overloaded (Name) then
6712 -- Use the context type to select the prefix that yields the correct
6718 I1 : Interp_Index := 0;
6719 P : constant Node_Id := Prefix (N);
6720 Found : Boolean := False;
6723 Get_First_Interp (P, I, It);
6724 while Present (It.Typ) loop
6725 if (Is_Array_Type (It.Typ)
6726 and then Covers (Typ, Component_Type (It.Typ)))
6727 or else (Is_Access_Type (It.Typ)
6728 and then Is_Array_Type (Designated_Type (It.Typ))
6730 (Typ, Component_Type (Designated_Type (It.Typ))))
6733 It := Disambiguate (P, I1, I, Any_Type);
6735 if It = No_Interp then
6736 Error_Msg_N ("ambiguous prefix for indexing", N);
6742 Array_Type := It.Typ;
6748 Array_Type := It.Typ;
6753 Get_Next_Interp (I, It);
6758 Array_Type := Etype (Name);
6761 Resolve (Name, Array_Type);
6762 Array_Type := Get_Actual_Subtype_If_Available (Name);
6764 -- If prefix is access type, dereference to get real array type.
6765 -- Note: we do not apply an access check because the expander always
6766 -- introduces an explicit dereference, and the check will happen there.
6768 if Is_Access_Type (Array_Type) then
6769 Array_Type := Designated_Type (Array_Type);
6772 -- If name was overloaded, set component type correctly now
6773 -- If a misplaced call to an entry family (which has no index types)
6774 -- return. Error will be diagnosed from calling context.
6776 if Is_Array_Type (Array_Type) then
6777 Set_Etype (N, Component_Type (Array_Type));
6782 Index := First_Index (Array_Type);
6783 Expr := First (Expressions (N));
6785 -- The prefix may have resolved to a string literal, in which case its
6786 -- etype has a special representation. This is only possible currently
6787 -- if the prefix is a static concatenation, written in functional
6790 if Ekind (Array_Type) = E_String_Literal_Subtype then
6791 Resolve (Expr, Standard_Positive);
6794 while Present (Index) and Present (Expr) loop
6795 Resolve (Expr, Etype (Index));
6796 Check_Unset_Reference (Expr);
6798 if Is_Scalar_Type (Etype (Expr)) then
6799 Apply_Scalar_Range_Check (Expr, Etype (Index));
6801 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
6809 -- Do not generate the warning on suspicious index if we are analyzing
6810 -- package Ada.Tags; otherwise we will report the warning with the
6811 -- Prims_Ptr field of the dispatch table.
6813 if Scope (Etype (Prefix (N))) = Standard_Standard
6815 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
6818 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
6819 Eval_Indexed_Component (N);
6822 -- If the array type is atomic, and is packed, and we are in a left side
6823 -- context, then this is worth a warning, since we have a situation
6824 -- where the access to the component may cause extra read/writes of
6825 -- the atomic array object, which could be considered unexpected.
6827 if Nkind (N) = N_Indexed_Component
6828 and then (Is_Atomic (Array_Type)
6829 or else (Is_Entity_Name (Prefix (N))
6830 and then Is_Atomic (Entity (Prefix (N)))))
6831 and then Is_Bit_Packed_Array (Array_Type)
6834 Error_Msg_N ("?assignment to component of packed atomic array",
6836 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
6839 end Resolve_Indexed_Component;
6841 -----------------------------
6842 -- Resolve_Integer_Literal --
6843 -----------------------------
6845 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
6848 Eval_Integer_Literal (N);
6849 end Resolve_Integer_Literal;
6851 --------------------------------
6852 -- Resolve_Intrinsic_Operator --
6853 --------------------------------
6855 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
6856 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6858 Orig_Op : constant Entity_Id := Entity (N);
6863 -- We must preserve the original entity in a generic setting, so that
6864 -- the legality of the operation can be verified in an instance.
6866 if not Expander_Active then
6871 while Scope (Op) /= Standard_Standard loop
6873 pragma Assert (Present (Op));
6877 Set_Is_Overloaded (N, False);
6879 -- If the operand type is private, rewrite with suitable conversions on
6880 -- the operands and the result, to expose the proper underlying numeric
6883 if Is_Private_Type (Typ) then
6884 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
6886 if Nkind (N) = N_Op_Expon then
6887 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
6889 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6892 if Nkind (Arg1) = N_Type_Conversion then
6893 Save_Interps (Left_Opnd (N), Expression (Arg1));
6896 if Nkind (Arg2) = N_Type_Conversion then
6897 Save_Interps (Right_Opnd (N), Expression (Arg2));
6900 Set_Left_Opnd (N, Arg1);
6901 Set_Right_Opnd (N, Arg2);
6903 Set_Etype (N, Btyp);
6904 Rewrite (N, Unchecked_Convert_To (Typ, N));
6907 elsif Typ /= Etype (Left_Opnd (N))
6908 or else Typ /= Etype (Right_Opnd (N))
6910 -- Add explicit conversion where needed, and save interpretations in
6911 -- case operands are overloaded. If the context is a VMS operation,
6912 -- assert that the conversion is legal (the operands have the proper
6913 -- types to select the VMS intrinsic). Note that in rare cases the
6914 -- VMS operators may be visible, but the default System is being used
6915 -- and Address is a private type.
6917 Arg1 := Convert_To (Typ, Left_Opnd (N));
6918 Arg2 := Convert_To (Typ, Right_Opnd (N));
6920 if Nkind (Arg1) = N_Type_Conversion then
6921 Save_Interps (Left_Opnd (N), Expression (Arg1));
6923 if Is_VMS_Operator (Orig_Op) then
6924 Set_Conversion_OK (Arg1);
6927 Save_Interps (Left_Opnd (N), Arg1);
6930 if Nkind (Arg2) = N_Type_Conversion then
6931 Save_Interps (Right_Opnd (N), Expression (Arg2));
6933 if Is_VMS_Operator (Orig_Op) then
6934 Set_Conversion_OK (Arg2);
6937 Save_Interps (Right_Opnd (N), Arg2);
6940 Rewrite (Left_Opnd (N), Arg1);
6941 Rewrite (Right_Opnd (N), Arg2);
6944 Resolve_Arithmetic_Op (N, Typ);
6947 Resolve_Arithmetic_Op (N, Typ);
6949 end Resolve_Intrinsic_Operator;
6951 --------------------------------------
6952 -- Resolve_Intrinsic_Unary_Operator --
6953 --------------------------------------
6955 procedure Resolve_Intrinsic_Unary_Operator
6959 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
6965 while Scope (Op) /= Standard_Standard loop
6967 pragma Assert (Present (Op));
6972 if Is_Private_Type (Typ) then
6973 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
6974 Save_Interps (Right_Opnd (N), Expression (Arg2));
6976 Set_Right_Opnd (N, Arg2);
6978 Set_Etype (N, Btyp);
6979 Rewrite (N, Unchecked_Convert_To (Typ, N));
6983 Resolve_Unary_Op (N, Typ);
6985 end Resolve_Intrinsic_Unary_Operator;
6987 ------------------------
6988 -- Resolve_Logical_Op --
6989 ------------------------
6991 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
6995 Check_No_Direct_Boolean_Operators (N);
6997 -- Predefined operations on scalar types yield the base type. On the
6998 -- other hand, logical operations on arrays yield the type of the
6999 -- arguments (and the context).
7001 if Is_Array_Type (Typ) then
7004 B_Typ := Base_Type (Typ);
7007 -- OK if this is a VMS-specific intrinsic operation
7009 if Is_VMS_Operator (Entity (N)) then
7012 -- The following test is required because the operands of the operation
7013 -- may be literals, in which case the resulting type appears to be
7014 -- compatible with a signed integer type, when in fact it is compatible
7015 -- only with modular types. If the context itself is universal, the
7016 -- operation is illegal.
7018 elsif not Valid_Boolean_Arg (Typ) then
7019 Error_Msg_N ("invalid context for logical operation", N);
7020 Set_Etype (N, Any_Type);
7023 elsif Typ = Any_Modular then
7025 ("no modular type available in this context", N);
7026 Set_Etype (N, Any_Type);
7028 elsif Is_Modular_Integer_Type (Typ)
7029 and then Etype (Left_Opnd (N)) = Universal_Integer
7030 and then Etype (Right_Opnd (N)) = Universal_Integer
7032 Check_For_Visible_Operator (N, B_Typ);
7035 Resolve (Left_Opnd (N), B_Typ);
7036 Resolve (Right_Opnd (N), B_Typ);
7038 Check_Unset_Reference (Left_Opnd (N));
7039 Check_Unset_Reference (Right_Opnd (N));
7041 Set_Etype (N, B_Typ);
7042 Generate_Operator_Reference (N, B_Typ);
7043 Eval_Logical_Op (N);
7044 end Resolve_Logical_Op;
7046 ---------------------------
7047 -- Resolve_Membership_Op --
7048 ---------------------------
7050 -- The context can only be a boolean type, and does not determine
7051 -- the arguments. Arguments should be unambiguous, but the preference
7052 -- rule for universal types applies.
7054 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
7055 pragma Warnings (Off, Typ);
7057 L : constant Node_Id := Left_Opnd (N);
7058 R : constant Node_Id := Right_Opnd (N);
7061 procedure Resolve_Set_Membership;
7062 -- Analysis has determined a unique type for the left operand.
7063 -- Use it to resolve the disjuncts.
7065 ----------------------------
7066 -- Resolve_Set_Membership --
7067 ----------------------------
7069 procedure Resolve_Set_Membership is
7073 Resolve (L, Etype (L));
7075 Alt := First (Alternatives (N));
7076 while Present (Alt) loop
7078 -- Alternative is an expression, a range
7079 -- or a subtype mark.
7081 if not Is_Entity_Name (Alt)
7082 or else not Is_Type (Entity (Alt))
7084 Resolve (Alt, Etype (L));
7089 end Resolve_Set_Membership;
7091 -- Start of processing for Resolve_Membership_Op
7094 if L = Error or else R = Error then
7098 if Present (Alternatives (N)) then
7099 Resolve_Set_Membership;
7102 elsif not Is_Overloaded (R)
7104 (Etype (R) = Universal_Integer or else
7105 Etype (R) = Universal_Real)
7106 and then Is_Overloaded (L)
7110 -- Ada 2005 (AI-251): Support the following case:
7112 -- type I is interface;
7113 -- type T is tagged ...
7115 -- function Test (O : I'Class) is
7117 -- return O in T'Class.
7120 -- In this case we have nothing else to do. The membership test will be
7121 -- done at run-time.
7123 elsif Ada_Version >= Ada_05
7124 and then Is_Class_Wide_Type (Etype (L))
7125 and then Is_Interface (Etype (L))
7126 and then Is_Class_Wide_Type (Etype (R))
7127 and then not Is_Interface (Etype (R))
7132 T := Intersect_Types (L, R);
7135 -- If mixed-mode operations are present and operands are all literal,
7136 -- the only interpretation involves Duration, which is probably not
7137 -- the intention of the programmer.
7139 if T = Any_Fixed then
7140 T := Unique_Fixed_Point_Type (N);
7142 if T = Any_Type then
7148 Check_Unset_Reference (L);
7150 if Nkind (R) = N_Range
7151 and then not Is_Scalar_Type (T)
7153 Error_Msg_N ("scalar type required for range", R);
7156 if Is_Entity_Name (R) then
7157 Freeze_Expression (R);
7160 Check_Unset_Reference (R);
7163 Eval_Membership_Op (N);
7164 end Resolve_Membership_Op;
7170 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
7171 Loc : constant Source_Ptr := Sloc (N);
7174 -- Handle restriction against anonymous null access values This
7175 -- restriction can be turned off using -gnatdj.
7177 -- Ada 2005 (AI-231): Remove restriction
7179 if Ada_Version < Ada_05
7180 and then not Debug_Flag_J
7181 and then Ekind (Typ) = E_Anonymous_Access_Type
7182 and then Comes_From_Source (N)
7184 -- In the common case of a call which uses an explicitly null value
7185 -- for an access parameter, give specialized error message.
7187 if Nkind_In (Parent (N), N_Procedure_Call_Statement,
7191 ("null is not allowed as argument for an access parameter", N);
7193 -- Standard message for all other cases (are there any?)
7197 ("null cannot be of an anonymous access type", N);
7201 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
7202 -- assignment to a null-excluding object
7204 if Ada_Version >= Ada_05
7205 and then Can_Never_Be_Null (Typ)
7206 and then Nkind (Parent (N)) = N_Assignment_Statement
7208 if not Inside_Init_Proc then
7210 (Compile_Time_Constraint_Error (N,
7211 "(Ada 2005) null not allowed in null-excluding objects?"),
7212 Make_Raise_Constraint_Error (Loc,
7213 Reason => CE_Access_Check_Failed));
7216 Make_Raise_Constraint_Error (Loc,
7217 Reason => CE_Access_Check_Failed));
7221 -- In a distributed context, null for a remote access to subprogram may
7222 -- need to be replaced with a special record aggregate. In this case,
7223 -- return after having done the transformation.
7225 if (Ekind (Typ) = E_Record_Type
7226 or else Is_Remote_Access_To_Subprogram_Type (Typ))
7227 and then Remote_AST_Null_Value (N, Typ)
7232 -- The null literal takes its type from the context
7237 -----------------------
7238 -- Resolve_Op_Concat --
7239 -----------------------
7241 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
7243 -- We wish to avoid deep recursion, because concatenations are often
7244 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
7245 -- operands nonrecursively until we find something that is not a simple
7246 -- concatenation (A in this case). We resolve that, and then walk back
7247 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
7248 -- to do the rest of the work at each level. The Parent pointers allow
7249 -- us to avoid recursion, and thus avoid running out of memory. See also
7250 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
7256 -- The following code is equivalent to:
7258 -- Resolve_Op_Concat_First (NN, Typ);
7259 -- Resolve_Op_Concat_Arg (N, ...);
7260 -- Resolve_Op_Concat_Rest (N, Typ);
7262 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
7263 -- operand is a concatenation.
7265 -- Walk down left operands
7268 Resolve_Op_Concat_First (NN, Typ);
7269 Op1 := Left_Opnd (NN);
7270 exit when not (Nkind (Op1) = N_Op_Concat
7271 and then not Is_Array_Type (Component_Type (Typ))
7272 and then Entity (Op1) = Entity (NN));
7276 -- Now (given the above example) NN is A&B and Op1 is A
7278 -- First resolve Op1 ...
7280 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
7282 -- ... then walk NN back up until we reach N (where we started), calling
7283 -- Resolve_Op_Concat_Rest along the way.
7286 Resolve_Op_Concat_Rest (NN, Typ);
7290 end Resolve_Op_Concat;
7292 ---------------------------
7293 -- Resolve_Op_Concat_Arg --
7294 ---------------------------
7296 procedure Resolve_Op_Concat_Arg
7302 Btyp : constant Entity_Id := Base_Type (Typ);
7307 or else (not Is_Overloaded (Arg)
7308 and then Etype (Arg) /= Any_Composite
7309 and then Covers (Component_Type (Typ), Etype (Arg)))
7311 Resolve (Arg, Component_Type (Typ));
7313 Resolve (Arg, Btyp);
7316 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
7317 if Nkind (Arg) = N_Aggregate
7318 and then Is_Composite_Type (Component_Type (Typ))
7320 if Is_Private_Type (Component_Type (Typ)) then
7321 Resolve (Arg, Btyp);
7323 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
7324 Set_Etype (Arg, Any_Type);
7328 if Is_Overloaded (Arg)
7329 and then Has_Compatible_Type (Arg, Typ)
7330 and then Etype (Arg) /= Any_Type
7338 Get_First_Interp (Arg, I, It);
7340 Get_Next_Interp (I, It);
7342 -- Special-case the error message when the overloading is
7343 -- caused by a function that yields an array and can be
7344 -- called without parameters.
7346 if It.Nam = Func then
7347 Error_Msg_Sloc := Sloc (Func);
7348 Error_Msg_N ("ambiguous call to function#", Arg);
7350 ("\\interpretation as call yields&", Arg, Typ);
7352 ("\\interpretation as indexing of call yields&",
7353 Arg, Component_Type (Typ));
7357 ("ambiguous operand for concatenation!", Arg);
7358 Get_First_Interp (Arg, I, It);
7359 while Present (It.Nam) loop
7360 Error_Msg_Sloc := Sloc (It.Nam);
7362 if Base_Type (It.Typ) = Base_Type (Typ)
7363 or else Base_Type (It.Typ) =
7364 Base_Type (Component_Type (Typ))
7366 Error_Msg_N -- CODEFIX
7367 ("\\possible interpretation#", Arg);
7370 Get_Next_Interp (I, It);
7376 Resolve (Arg, Component_Type (Typ));
7378 if Nkind (Arg) = N_String_Literal then
7379 Set_Etype (Arg, Component_Type (Typ));
7382 if Arg = Left_Opnd (N) then
7383 Set_Is_Component_Left_Opnd (N);
7385 Set_Is_Component_Right_Opnd (N);
7390 Resolve (Arg, Btyp);
7393 Check_Unset_Reference (Arg);
7394 end Resolve_Op_Concat_Arg;
7396 -----------------------------
7397 -- Resolve_Op_Concat_First --
7398 -----------------------------
7400 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
7401 Btyp : constant Entity_Id := Base_Type (Typ);
7402 Op1 : constant Node_Id := Left_Opnd (N);
7403 Op2 : constant Node_Id := Right_Opnd (N);
7406 -- The parser folds an enormous sequence of concatenations of string
7407 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
7408 -- in the right operand. If the expression resolves to a predefined "&"
7409 -- operator, all is well. Otherwise, the parser's folding is wrong, so
7410 -- we give an error. See P_Simple_Expression in Par.Ch4.
7412 if Nkind (Op2) = N_String_Literal
7413 and then Is_Folded_In_Parser (Op2)
7414 and then Ekind (Entity (N)) = E_Function
7416 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
7417 and then String_Length (Strval (Op1)) = 0);
7418 Error_Msg_N ("too many user-defined concatenations", N);
7422 Set_Etype (N, Btyp);
7424 if Is_Limited_Composite (Btyp) then
7425 Error_Msg_N ("concatenation not available for limited array", N);
7426 Explain_Limited_Type (Btyp, N);
7428 end Resolve_Op_Concat_First;
7430 ----------------------------
7431 -- Resolve_Op_Concat_Rest --
7432 ----------------------------
7434 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
7435 Op1 : constant Node_Id := Left_Opnd (N);
7436 Op2 : constant Node_Id := Right_Opnd (N);
7439 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
7441 Generate_Operator_Reference (N, Typ);
7443 if Is_String_Type (Typ) then
7444 Eval_Concatenation (N);
7447 -- If this is not a static concatenation, but the result is a string
7448 -- type (and not an array of strings) ensure that static string operands
7449 -- have their subtypes properly constructed.
7451 if Nkind (N) /= N_String_Literal
7452 and then Is_Character_Type (Component_Type (Typ))
7454 Set_String_Literal_Subtype (Op1, Typ);
7455 Set_String_Literal_Subtype (Op2, Typ);
7457 end Resolve_Op_Concat_Rest;
7459 ----------------------
7460 -- Resolve_Op_Expon --
7461 ----------------------
7463 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
7464 B_Typ : constant Entity_Id := Base_Type (Typ);
7467 -- Catch attempts to do fixed-point exponentiation with universal
7468 -- operands, which is a case where the illegality is not caught during
7469 -- normal operator analysis.
7471 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
7472 Error_Msg_N ("exponentiation not available for fixed point", N);
7476 if Comes_From_Source (N)
7477 and then Ekind (Entity (N)) = E_Function
7478 and then Is_Imported (Entity (N))
7479 and then Is_Intrinsic_Subprogram (Entity (N))
7481 Resolve_Intrinsic_Operator (N, Typ);
7485 if Etype (Left_Opnd (N)) = Universal_Integer
7486 or else Etype (Left_Opnd (N)) = Universal_Real
7488 Check_For_Visible_Operator (N, B_Typ);
7491 -- We do the resolution using the base type, because intermediate values
7492 -- in expressions always are of the base type, not a subtype of it.
7494 Resolve (Left_Opnd (N), B_Typ);
7495 Resolve (Right_Opnd (N), Standard_Integer);
7497 Check_Unset_Reference (Left_Opnd (N));
7498 Check_Unset_Reference (Right_Opnd (N));
7500 Set_Etype (N, B_Typ);
7501 Generate_Operator_Reference (N, B_Typ);
7504 -- Set overflow checking bit. Much cleverer code needed here eventually
7505 -- and perhaps the Resolve routines should be separated for the various
7506 -- arithmetic operations, since they will need different processing. ???
7508 if Nkind (N) in N_Op then
7509 if not Overflow_Checks_Suppressed (Etype (N)) then
7510 Enable_Overflow_Check (N);
7513 end Resolve_Op_Expon;
7515 --------------------
7516 -- Resolve_Op_Not --
7517 --------------------
7519 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
7522 function Parent_Is_Boolean return Boolean;
7523 -- This function determines if the parent node is a boolean operator
7524 -- or operation (comparison op, membership test, or short circuit form)
7525 -- and the not in question is the left operand of this operation.
7526 -- Note that if the not is in parens, then false is returned.
7528 -----------------------
7529 -- Parent_Is_Boolean --
7530 -----------------------
7532 function Parent_Is_Boolean return Boolean is
7534 if Paren_Count (N) /= 0 then
7538 case Nkind (Parent (N)) is
7553 return Left_Opnd (Parent (N)) = N;
7559 end Parent_Is_Boolean;
7561 -- Start of processing for Resolve_Op_Not
7564 -- Predefined operations on scalar types yield the base type. On the
7565 -- other hand, logical operations on arrays yield the type of the
7566 -- arguments (and the context).
7568 if Is_Array_Type (Typ) then
7571 B_Typ := Base_Type (Typ);
7574 if Is_VMS_Operator (Entity (N)) then
7577 -- Straightforward case of incorrect arguments
7579 elsif not Valid_Boolean_Arg (Typ) then
7580 Error_Msg_N ("invalid operand type for operator&", N);
7581 Set_Etype (N, Any_Type);
7584 -- Special case of probable missing parens
7586 elsif Typ = Universal_Integer or else Typ = Any_Modular then
7587 if Parent_Is_Boolean then
7589 ("operand of not must be enclosed in parentheses",
7593 ("no modular type available in this context", N);
7596 Set_Etype (N, Any_Type);
7599 -- OK resolution of not
7602 -- Warn if non-boolean types involved. This is a case like not a < b
7603 -- where a and b are modular, where we will get (not a) < b and most
7604 -- likely not (a < b) was intended.
7606 if Warn_On_Questionable_Missing_Parens
7607 and then not Is_Boolean_Type (Typ)
7608 and then Parent_Is_Boolean
7610 Error_Msg_N ("?not expression should be parenthesized here!", N);
7613 -- Warn on double negation if checking redundant constructs
7615 if Warn_On_Redundant_Constructs
7616 and then Comes_From_Source (N)
7617 and then Comes_From_Source (Right_Opnd (N))
7618 and then Root_Type (Typ) = Standard_Boolean
7619 and then Nkind (Right_Opnd (N)) = N_Op_Not
7621 Error_Msg_N ("redundant double negation?", N);
7624 -- Complete resolution and evaluation of NOT
7626 Resolve (Right_Opnd (N), B_Typ);
7627 Check_Unset_Reference (Right_Opnd (N));
7628 Set_Etype (N, B_Typ);
7629 Generate_Operator_Reference (N, B_Typ);
7634 -----------------------------
7635 -- Resolve_Operator_Symbol --
7636 -----------------------------
7638 -- Nothing to be done, all resolved already
7640 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
7641 pragma Warnings (Off, N);
7642 pragma Warnings (Off, Typ);
7646 end Resolve_Operator_Symbol;
7648 ----------------------------------
7649 -- Resolve_Qualified_Expression --
7650 ----------------------------------
7652 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
7653 pragma Warnings (Off, Typ);
7655 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
7656 Expr : constant Node_Id := Expression (N);
7659 Resolve (Expr, Target_Typ);
7661 -- A qualified expression requires an exact match of the type,
7662 -- class-wide matching is not allowed. However, if the qualifying
7663 -- type is specific and the expression has a class-wide type, it
7664 -- may still be okay, since it can be the result of the expansion
7665 -- of a call to a dispatching function, so we also have to check
7666 -- class-wideness of the type of the expression's original node.
7668 if (Is_Class_Wide_Type (Target_Typ)
7670 (Is_Class_Wide_Type (Etype (Expr))
7671 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
7672 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
7674 Wrong_Type (Expr, Target_Typ);
7677 -- If the target type is unconstrained, then we reset the type of
7678 -- the result from the type of the expression. For other cases, the
7679 -- actual subtype of the expression is the target type.
7681 if Is_Composite_Type (Target_Typ)
7682 and then not Is_Constrained (Target_Typ)
7684 Set_Etype (N, Etype (Expr));
7687 Eval_Qualified_Expression (N);
7688 end Resolve_Qualified_Expression;
7694 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
7695 L : constant Node_Id := Low_Bound (N);
7696 H : constant Node_Id := High_Bound (N);
7698 function First_Last_Ref return Boolean;
7699 -- Returns True if N is of the form X'First .. X'Last where X is the
7700 -- same entity for both attributes.
7702 --------------------
7703 -- First_Last_Ref --
7704 --------------------
7706 function First_Last_Ref return Boolean is
7707 Lorig : constant Node_Id := Original_Node (L);
7708 Horig : constant Node_Id := Original_Node (H);
7711 if Nkind (Lorig) = N_Attribute_Reference
7712 and then Nkind (Horig) = N_Attribute_Reference
7713 and then Attribute_Name (Lorig) = Name_First
7714 and then Attribute_Name (Horig) = Name_Last
7717 PL : constant Node_Id := Prefix (Lorig);
7718 PH : constant Node_Id := Prefix (Horig);
7720 if Is_Entity_Name (PL)
7721 and then Is_Entity_Name (PH)
7722 and then Entity (PL) = Entity (PH)
7732 -- Start of processing for Resolve_Range
7739 -- Check for inappropriate range on unordered enumeration type
7741 if Bad_Unordered_Enumeration_Reference (N, Typ)
7743 -- Exclude X'First .. X'Last if X is the same entity for both
7745 and then not First_Last_Ref
7747 Error_Msg ("subrange of unordered enumeration type?", Sloc (N));
7750 Check_Unset_Reference (L);
7751 Check_Unset_Reference (H);
7753 -- We have to check the bounds for being within the base range as
7754 -- required for a non-static context. Normally this is automatic and
7755 -- done as part of evaluating expressions, but the N_Range node is an
7756 -- exception, since in GNAT we consider this node to be a subexpression,
7757 -- even though in Ada it is not. The circuit in Sem_Eval could check for
7758 -- this, but that would put the test on the main evaluation path for
7761 Check_Non_Static_Context (L);
7762 Check_Non_Static_Context (H);
7764 -- Check for an ambiguous range over character literals. This will
7765 -- happen with a membership test involving only literals.
7767 if Typ = Any_Character then
7768 Ambiguous_Character (L);
7769 Set_Etype (N, Any_Type);
7773 -- If bounds are static, constant-fold them, so size computations
7774 -- are identical between front-end and back-end. Do not perform this
7775 -- transformation while analyzing generic units, as type information
7776 -- would then be lost when reanalyzing the constant node in the
7779 if Is_Discrete_Type (Typ) and then Expander_Active then
7780 if Is_OK_Static_Expression (L) then
7781 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
7784 if Is_OK_Static_Expression (H) then
7785 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
7790 --------------------------
7791 -- Resolve_Real_Literal --
7792 --------------------------
7794 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
7795 Actual_Typ : constant Entity_Id := Etype (N);
7798 -- Special processing for fixed-point literals to make sure that the
7799 -- value is an exact multiple of small where this is required. We
7800 -- skip this for the universal real case, and also for generic types.
7802 if Is_Fixed_Point_Type (Typ)
7803 and then Typ /= Universal_Fixed
7804 and then Typ /= Any_Fixed
7805 and then not Is_Generic_Type (Typ)
7808 Val : constant Ureal := Realval (N);
7809 Cintr : constant Ureal := Val / Small_Value (Typ);
7810 Cint : constant Uint := UR_Trunc (Cintr);
7811 Den : constant Uint := Norm_Den (Cintr);
7815 -- Case of literal is not an exact multiple of the Small
7819 -- For a source program literal for a decimal fixed-point
7820 -- type, this is statically illegal (RM 4.9(36)).
7822 if Is_Decimal_Fixed_Point_Type (Typ)
7823 and then Actual_Typ = Universal_Real
7824 and then Comes_From_Source (N)
7826 Error_Msg_N ("value has extraneous low order digits", N);
7829 -- Generate a warning if literal from source
7831 if Is_Static_Expression (N)
7832 and then Warn_On_Bad_Fixed_Value
7835 ("?static fixed-point value is not a multiple of Small!",
7839 -- Replace literal by a value that is the exact representation
7840 -- of a value of the type, i.e. a multiple of the small value,
7841 -- by truncation, since Machine_Rounds is false for all GNAT
7842 -- fixed-point types (RM 4.9(38)).
7844 Stat := Is_Static_Expression (N);
7846 Make_Real_Literal (Sloc (N),
7847 Realval => Small_Value (Typ) * Cint));
7849 Set_Is_Static_Expression (N, Stat);
7852 -- In all cases, set the corresponding integer field
7854 Set_Corresponding_Integer_Value (N, Cint);
7858 -- Now replace the actual type by the expected type as usual
7861 Eval_Real_Literal (N);
7862 end Resolve_Real_Literal;
7864 -----------------------
7865 -- Resolve_Reference --
7866 -----------------------
7868 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
7869 P : constant Node_Id := Prefix (N);
7872 -- Replace general access with specific type
7874 if Ekind (Etype (N)) = E_Allocator_Type then
7875 Set_Etype (N, Base_Type (Typ));
7878 Resolve (P, Designated_Type (Etype (N)));
7880 -- If we are taking the reference of a volatile entity, then treat
7881 -- it as a potential modification of this entity. This is much too
7882 -- conservative, but is necessary because remove side effects can
7883 -- result in transformations of normal assignments into reference
7884 -- sequences that otherwise fail to notice the modification.
7886 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
7887 Note_Possible_Modification (P, Sure => False);
7889 end Resolve_Reference;
7891 --------------------------------
7892 -- Resolve_Selected_Component --
7893 --------------------------------
7895 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
7897 Comp1 : Entity_Id := Empty; -- prevent junk warning
7898 P : constant Node_Id := Prefix (N);
7899 S : constant Node_Id := Selector_Name (N);
7900 T : Entity_Id := Etype (P);
7902 I1 : Interp_Index := 0; -- prevent junk warning
7907 function Init_Component return Boolean;
7908 -- Check whether this is the initialization of a component within an
7909 -- init proc (by assignment or call to another init proc). If true,
7910 -- there is no need for a discriminant check.
7912 --------------------
7913 -- Init_Component --
7914 --------------------
7916 function Init_Component return Boolean is
7918 return Inside_Init_Proc
7919 and then Nkind (Prefix (N)) = N_Identifier
7920 and then Chars (Prefix (N)) = Name_uInit
7921 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
7924 -- Start of processing for Resolve_Selected_Component
7927 if Is_Overloaded (P) then
7929 -- Use the context type to select the prefix that has a selector
7930 -- of the correct name and type.
7933 Get_First_Interp (P, I, It);
7935 Search : while Present (It.Typ) loop
7936 if Is_Access_Type (It.Typ) then
7937 T := Designated_Type (It.Typ);
7942 if Is_Record_Type (T) then
7944 -- The visible components of a class-wide type are those of
7947 if Is_Class_Wide_Type (T) then
7951 Comp := First_Entity (T);
7952 while Present (Comp) loop
7953 if Chars (Comp) = Chars (S)
7954 and then Covers (Etype (Comp), Typ)
7963 It := Disambiguate (P, I1, I, Any_Type);
7965 if It = No_Interp then
7967 ("ambiguous prefix for selected component", N);
7974 -- There may be an implicit dereference. Retrieve
7975 -- designated record type.
7977 if Is_Access_Type (It1.Typ) then
7978 T := Designated_Type (It1.Typ);
7983 if Scope (Comp1) /= T then
7985 -- Resolution chooses the new interpretation.
7986 -- Find the component with the right name.
7988 Comp1 := First_Entity (T);
7989 while Present (Comp1)
7990 and then Chars (Comp1) /= Chars (S)
7992 Comp1 := Next_Entity (Comp1);
8001 Comp := Next_Entity (Comp);
8005 Get_Next_Interp (I, It);
8008 Resolve (P, It1.Typ);
8010 Set_Entity_With_Style_Check (S, Comp1);
8013 -- Resolve prefix with its type
8018 -- Generate cross-reference. We needed to wait until full overloading
8019 -- resolution was complete to do this, since otherwise we can't tell if
8020 -- we are an lvalue or not.
8022 if May_Be_Lvalue (N) then
8023 Generate_Reference (Entity (S), S, 'm');
8025 Generate_Reference (Entity (S), S, 'r');
8028 -- If prefix is an access type, the node will be transformed into an
8029 -- explicit dereference during expansion. The type of the node is the
8030 -- designated type of that of the prefix.
8032 if Is_Access_Type (Etype (P)) then
8033 T := Designated_Type (Etype (P));
8034 Check_Fully_Declared_Prefix (T, P);
8039 if Has_Discriminants (T)
8040 and then Ekind_In (Entity (S), E_Component, E_Discriminant)
8041 and then Present (Original_Record_Component (Entity (S)))
8042 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
8043 and then Present (Discriminant_Checking_Func
8044 (Original_Record_Component (Entity (S))))
8045 and then not Discriminant_Checks_Suppressed (T)
8046 and then not Init_Component
8048 Set_Do_Discriminant_Check (N);
8051 if Ekind (Entity (S)) = E_Void then
8052 Error_Msg_N ("premature use of component", S);
8055 -- If the prefix is a record conversion, this may be a renamed
8056 -- discriminant whose bounds differ from those of the original
8057 -- one, so we must ensure that a range check is performed.
8059 if Nkind (P) = N_Type_Conversion
8060 and then Ekind (Entity (S)) = E_Discriminant
8061 and then Is_Discrete_Type (Typ)
8063 Set_Etype (N, Base_Type (Typ));
8066 -- Note: No Eval processing is required, because the prefix is of a
8067 -- record type, or protected type, and neither can possibly be static.
8069 -- If the array type is atomic, and is packed, and we are in a left side
8070 -- context, then this is worth a warning, since we have a situation
8071 -- where the access to the component may cause extra read/writes of
8072 -- the atomic array object, which could be considered unexpected.
8074 if Nkind (N) = N_Selected_Component
8075 and then (Is_Atomic (T)
8076 or else (Is_Entity_Name (Prefix (N))
8077 and then Is_Atomic (Entity (Prefix (N)))))
8078 and then Is_Packed (T)
8081 Error_Msg_N ("?assignment to component of packed atomic record",
8083 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
8086 end Resolve_Selected_Component;
8092 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
8093 B_Typ : constant Entity_Id := Base_Type (Typ);
8094 L : constant Node_Id := Left_Opnd (N);
8095 R : constant Node_Id := Right_Opnd (N);
8098 -- We do the resolution using the base type, because intermediate values
8099 -- in expressions always are of the base type, not a subtype of it.
8102 Resolve (R, Standard_Natural);
8104 Check_Unset_Reference (L);
8105 Check_Unset_Reference (R);
8107 Set_Etype (N, B_Typ);
8108 Generate_Operator_Reference (N, B_Typ);
8112 ---------------------------
8113 -- Resolve_Short_Circuit --
8114 ---------------------------
8116 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
8117 B_Typ : constant Entity_Id := Base_Type (Typ);
8118 L : constant Node_Id := Left_Opnd (N);
8119 R : constant Node_Id := Right_Opnd (N);
8122 -- Why are the calls to Check_Order_Dependence commented out ???
8124 -- Check_Order_Dependence; -- For AI05-0144
8126 -- Check_Order_Dependence; -- For AI05-0144
8128 -- Check for issuing warning for always False assert/check, this happens
8129 -- when assertions are turned off, in which case the pragma Assert/Check
8130 -- was transformed into:
8132 -- if False and then <condition> then ...
8134 -- and we detect this pattern
8136 if Warn_On_Assertion_Failure
8137 and then Is_Entity_Name (R)
8138 and then Entity (R) = Standard_False
8139 and then Nkind (Parent (N)) = N_If_Statement
8140 and then Nkind (N) = N_And_Then
8141 and then Is_Entity_Name (L)
8142 and then Entity (L) = Standard_False
8145 Orig : constant Node_Id := Original_Node (Parent (N));
8148 if Nkind (Orig) = N_Pragma
8149 and then Pragma_Name (Orig) = Name_Assert
8151 -- Don't want to warn if original condition is explicit False
8154 Expr : constant Node_Id :=
8157 (First (Pragma_Argument_Associations (Orig))));
8159 if Is_Entity_Name (Expr)
8160 and then Entity (Expr) = Standard_False
8164 -- Issue warning. We do not want the deletion of the
8165 -- IF/AND-THEN to take this message with it. We achieve
8166 -- this by making sure that the expanded code points to
8167 -- the Sloc of the expression, not the original pragma.
8170 ("?assertion would fail at run-time!",
8172 (First (Pragma_Argument_Associations (Orig))));
8176 -- Similar processing for Check pragma
8178 elsif Nkind (Orig) = N_Pragma
8179 and then Pragma_Name (Orig) = Name_Check
8181 -- Don't want to warn if original condition is explicit False
8184 Expr : constant Node_Id :=
8188 (Pragma_Argument_Associations (Orig)))));
8190 if Is_Entity_Name (Expr)
8191 and then Entity (Expr) = Standard_False
8196 ("?check would fail at run-time!",
8198 (Last (Pragma_Argument_Associations (Orig))));
8205 -- Continue with processing of short circuit
8207 Check_Unset_Reference (L);
8208 Check_Unset_Reference (R);
8210 Set_Etype (N, B_Typ);
8211 Eval_Short_Circuit (N);
8212 end Resolve_Short_Circuit;
8218 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
8219 Name : constant Node_Id := Prefix (N);
8220 Drange : constant Node_Id := Discrete_Range (N);
8221 Array_Type : Entity_Id := Empty;
8225 if Is_Overloaded (Name) then
8227 -- Use the context type to select the prefix that yields the correct
8232 I1 : Interp_Index := 0;
8234 P : constant Node_Id := Prefix (N);
8235 Found : Boolean := False;
8238 Get_First_Interp (P, I, It);
8239 while Present (It.Typ) loop
8240 if (Is_Array_Type (It.Typ)
8241 and then Covers (Typ, It.Typ))
8242 or else (Is_Access_Type (It.Typ)
8243 and then Is_Array_Type (Designated_Type (It.Typ))
8244 and then Covers (Typ, Designated_Type (It.Typ)))
8247 It := Disambiguate (P, I1, I, Any_Type);
8249 if It = No_Interp then
8250 Error_Msg_N ("ambiguous prefix for slicing", N);
8255 Array_Type := It.Typ;
8260 Array_Type := It.Typ;
8265 Get_Next_Interp (I, It);
8270 Array_Type := Etype (Name);
8273 Resolve (Name, Array_Type);
8275 if Is_Access_Type (Array_Type) then
8276 Apply_Access_Check (N);
8277 Array_Type := Designated_Type (Array_Type);
8279 -- If the prefix is an access to an unconstrained array, we must use
8280 -- the actual subtype of the object to perform the index checks. The
8281 -- object denoted by the prefix is implicit in the node, so we build
8282 -- an explicit representation for it in order to compute the actual
8285 if not Is_Constrained (Array_Type) then
8286 Remove_Side_Effects (Prefix (N));
8289 Obj : constant Node_Id :=
8290 Make_Explicit_Dereference (Sloc (N),
8291 Prefix => New_Copy_Tree (Prefix (N)));
8293 Set_Etype (Obj, Array_Type);
8294 Set_Parent (Obj, Parent (N));
8295 Array_Type := Get_Actual_Subtype (Obj);
8299 elsif Is_Entity_Name (Name)
8300 or else Nkind (Name) = N_Explicit_Dereference
8301 or else (Nkind (Name) = N_Function_Call
8302 and then not Is_Constrained (Etype (Name)))
8304 Array_Type := Get_Actual_Subtype (Name);
8306 -- If the name is a selected component that depends on discriminants,
8307 -- build an actual subtype for it. This can happen only when the name
8308 -- itself is overloaded; otherwise the actual subtype is created when
8309 -- the selected component is analyzed.
8311 elsif Nkind (Name) = N_Selected_Component
8312 and then Full_Analysis
8313 and then Depends_On_Discriminant (First_Index (Array_Type))
8316 Act_Decl : constant Node_Id :=
8317 Build_Actual_Subtype_Of_Component (Array_Type, Name);
8319 Insert_Action (N, Act_Decl);
8320 Array_Type := Defining_Identifier (Act_Decl);
8323 -- Maybe this should just be "else", instead of checking for the
8324 -- specific case of slice??? This is needed for the case where
8325 -- the prefix is an Image attribute, which gets expanded to a
8326 -- slice, and so has a constrained subtype which we want to use
8327 -- for the slice range check applied below (the range check won't
8328 -- get done if the unconstrained subtype of the 'Image is used).
8330 elsif Nkind (Name) = N_Slice then
8331 Array_Type := Etype (Name);
8334 -- If name was overloaded, set slice type correctly now
8336 Set_Etype (N, Array_Type);
8338 -- If the range is specified by a subtype mark, no resolution is
8339 -- necessary. Else resolve the bounds, and apply needed checks.
8341 if not Is_Entity_Name (Drange) then
8342 Index := First_Index (Array_Type);
8343 Resolve (Drange, Base_Type (Etype (Index)));
8345 if Nkind (Drange) = N_Range
8347 -- Do not apply the range check to nodes associated with the
8348 -- frontend expansion of the dispatch table. We first check
8349 -- if Ada.Tags is already loaded to void the addition of an
8350 -- undesired dependence on such run-time unit.
8353 (not Tagged_Type_Expansion
8355 (RTU_Loaded (Ada_Tags)
8356 and then Nkind (Prefix (N)) = N_Selected_Component
8357 and then Present (Entity (Selector_Name (Prefix (N))))
8358 and then Entity (Selector_Name (Prefix (N))) =
8359 RTE_Record_Component (RE_Prims_Ptr)))
8361 Apply_Range_Check (Drange, Etype (Index));
8365 Set_Slice_Subtype (N);
8367 if Nkind (Drange) = N_Range then
8368 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
8369 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
8375 ----------------------------
8376 -- Resolve_String_Literal --
8377 ----------------------------
8379 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
8380 C_Typ : constant Entity_Id := Component_Type (Typ);
8381 R_Typ : constant Entity_Id := Root_Type (C_Typ);
8382 Loc : constant Source_Ptr := Sloc (N);
8383 Str : constant String_Id := Strval (N);
8384 Strlen : constant Nat := String_Length (Str);
8385 Subtype_Id : Entity_Id;
8386 Need_Check : Boolean;
8389 -- For a string appearing in a concatenation, defer creation of the
8390 -- string_literal_subtype until the end of the resolution of the
8391 -- concatenation, because the literal may be constant-folded away. This
8392 -- is a useful optimization for long concatenation expressions.
8394 -- If the string is an aggregate built for a single character (which
8395 -- happens in a non-static context) or a is null string to which special
8396 -- checks may apply, we build the subtype. Wide strings must also get a
8397 -- string subtype if they come from a one character aggregate. Strings
8398 -- generated by attributes might be static, but it is often hard to
8399 -- determine whether the enclosing context is static, so we generate
8400 -- subtypes for them as well, thus losing some rarer optimizations ???
8401 -- Same for strings that come from a static conversion.
8404 (Strlen = 0 and then Typ /= Standard_String)
8405 or else Nkind (Parent (N)) /= N_Op_Concat
8406 or else (N /= Left_Opnd (Parent (N))
8407 and then N /= Right_Opnd (Parent (N)))
8408 or else ((Typ = Standard_Wide_String
8409 or else Typ = Standard_Wide_Wide_String)
8410 and then Nkind (Original_Node (N)) /= N_String_Literal);
8412 -- If the resolving type is itself a string literal subtype, we can just
8413 -- reuse it, since there is no point in creating another.
8415 if Ekind (Typ) = E_String_Literal_Subtype then
8418 elsif Nkind (Parent (N)) = N_Op_Concat
8419 and then not Need_Check
8420 and then not Nkind_In (Original_Node (N), N_Character_Literal,
8421 N_Attribute_Reference,
8422 N_Qualified_Expression,
8427 -- Otherwise we must create a string literal subtype. Note that the
8428 -- whole idea of string literal subtypes is simply to avoid the need
8429 -- for building a full fledged array subtype for each literal.
8432 Set_String_Literal_Subtype (N, Typ);
8433 Subtype_Id := Etype (N);
8436 if Nkind (Parent (N)) /= N_Op_Concat
8439 Set_Etype (N, Subtype_Id);
8440 Eval_String_Literal (N);
8443 if Is_Limited_Composite (Typ)
8444 or else Is_Private_Composite (Typ)
8446 Error_Msg_N ("string literal not available for private array", N);
8447 Set_Etype (N, Any_Type);
8451 -- The validity of a null string has been checked in the call to
8452 -- Eval_String_Literal.
8457 -- Always accept string literal with component type Any_Character, which
8458 -- occurs in error situations and in comparisons of literals, both of
8459 -- which should accept all literals.
8461 elsif R_Typ = Any_Character then
8464 -- If the type is bit-packed, then we always transform the string
8465 -- literal into a full fledged aggregate.
8467 elsif Is_Bit_Packed_Array (Typ) then
8470 -- Deal with cases of Wide_Wide_String, Wide_String, and String
8473 -- For Standard.Wide_Wide_String, or any other type whose component
8474 -- type is Standard.Wide_Wide_Character, we know that all the
8475 -- characters in the string must be acceptable, since the parser
8476 -- accepted the characters as valid character literals.
8478 if R_Typ = Standard_Wide_Wide_Character then
8481 -- For the case of Standard.String, or any other type whose component
8482 -- type is Standard.Character, we must make sure that there are no
8483 -- wide characters in the string, i.e. that it is entirely composed
8484 -- of characters in range of type Character.
8486 -- If the string literal is the result of a static concatenation, the
8487 -- test has already been performed on the components, and need not be
8490 elsif R_Typ = Standard_Character
8491 and then Nkind (Original_Node (N)) /= N_Op_Concat
8493 for J in 1 .. Strlen loop
8494 if not In_Character_Range (Get_String_Char (Str, J)) then
8496 -- If we are out of range, post error. This is one of the
8497 -- very few places that we place the flag in the middle of
8498 -- a token, right under the offending wide character. Not
8499 -- quite clear if this is right wrt wide character encoding
8500 -- sequences, but it's only an error message!
8503 ("literal out of range of type Standard.Character",
8504 Source_Ptr (Int (Loc) + J));
8509 -- For the case of Standard.Wide_String, or any other type whose
8510 -- component type is Standard.Wide_Character, we must make sure that
8511 -- there are no wide characters in the string, i.e. that it is
8512 -- entirely composed of characters in range of type Wide_Character.
8514 -- If the string literal is the result of a static concatenation,
8515 -- the test has already been performed on the components, and need
8518 elsif R_Typ = Standard_Wide_Character
8519 and then Nkind (Original_Node (N)) /= N_Op_Concat
8521 for J in 1 .. Strlen loop
8522 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
8524 -- If we are out of range, post error. This is one of the
8525 -- very few places that we place the flag in the middle of
8526 -- a token, right under the offending wide character.
8528 -- This is not quite right, because characters in general
8529 -- will take more than one character position ???
8532 ("literal out of range of type Standard.Wide_Character",
8533 Source_Ptr (Int (Loc) + J));
8538 -- If the root type is not a standard character, then we will convert
8539 -- the string into an aggregate and will let the aggregate code do
8540 -- the checking. Standard Wide_Wide_Character is also OK here.
8546 -- See if the component type of the array corresponding to the string
8547 -- has compile time known bounds. If yes we can directly check
8548 -- whether the evaluation of the string will raise constraint error.
8549 -- Otherwise we need to transform the string literal into the
8550 -- corresponding character aggregate and let the aggregate
8551 -- code do the checking.
8553 if Is_Standard_Character_Type (R_Typ) then
8555 -- Check for the case of full range, where we are definitely OK
8557 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
8561 -- Here the range is not the complete base type range, so check
8564 Comp_Typ_Lo : constant Node_Id :=
8565 Type_Low_Bound (Component_Type (Typ));
8566 Comp_Typ_Hi : constant Node_Id :=
8567 Type_High_Bound (Component_Type (Typ));
8572 if Compile_Time_Known_Value (Comp_Typ_Lo)
8573 and then Compile_Time_Known_Value (Comp_Typ_Hi)
8575 for J in 1 .. Strlen loop
8576 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
8578 if Char_Val < Expr_Value (Comp_Typ_Lo)
8579 or else Char_Val > Expr_Value (Comp_Typ_Hi)
8581 Apply_Compile_Time_Constraint_Error
8582 (N, "character out of range?", CE_Range_Check_Failed,
8583 Loc => Source_Ptr (Int (Loc) + J));
8593 -- If we got here we meed to transform the string literal into the
8594 -- equivalent qualified positional array aggregate. This is rather
8595 -- heavy artillery for this situation, but it is hard work to avoid.
8598 Lits : constant List_Id := New_List;
8599 P : Source_Ptr := Loc + 1;
8603 -- Build the character literals, we give them source locations that
8604 -- correspond to the string positions, which is a bit tricky given
8605 -- the possible presence of wide character escape sequences.
8607 for J in 1 .. Strlen loop
8608 C := Get_String_Char (Str, J);
8609 Set_Character_Literal_Name (C);
8612 Make_Character_Literal (P,
8614 Char_Literal_Value => UI_From_CC (C)));
8616 if In_Character_Range (C) then
8619 -- Should we have a call to Skip_Wide here ???
8627 Make_Qualified_Expression (Loc,
8628 Subtype_Mark => New_Reference_To (Typ, Loc),
8630 Make_Aggregate (Loc, Expressions => Lits)));
8632 Analyze_And_Resolve (N, Typ);
8634 end Resolve_String_Literal;
8636 -----------------------------
8637 -- Resolve_Subprogram_Info --
8638 -----------------------------
8640 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
8643 end Resolve_Subprogram_Info;
8645 -----------------------------
8646 -- Resolve_Type_Conversion --
8647 -----------------------------
8649 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
8650 Conv_OK : constant Boolean := Conversion_OK (N);
8651 Operand : constant Node_Id := Expression (N);
8652 Operand_Typ : constant Entity_Id := Etype (Operand);
8653 Target_Typ : constant Entity_Id := Etype (N);
8660 and then not Valid_Conversion (N, Target_Typ, Operand)
8665 if Etype (Operand) = Any_Fixed then
8667 -- Mixed-mode operation involving a literal. Context must be a fixed
8668 -- type which is applied to the literal subsequently.
8670 if Is_Fixed_Point_Type (Typ) then
8671 Set_Etype (Operand, Universal_Real);
8673 elsif Is_Numeric_Type (Typ)
8674 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
8675 and then (Etype (Right_Opnd (Operand)) = Universal_Real
8677 Etype (Left_Opnd (Operand)) = Universal_Real)
8679 -- Return if expression is ambiguous
8681 if Unique_Fixed_Point_Type (N) = Any_Type then
8684 -- If nothing else, the available fixed type is Duration
8687 Set_Etype (Operand, Standard_Duration);
8690 -- Resolve the real operand with largest available precision
8692 if Etype (Right_Opnd (Operand)) = Universal_Real then
8693 Rop := New_Copy_Tree (Right_Opnd (Operand));
8695 Rop := New_Copy_Tree (Left_Opnd (Operand));
8698 Resolve (Rop, Universal_Real);
8700 -- If the operand is a literal (it could be a non-static and
8701 -- illegal exponentiation) check whether the use of Duration
8702 -- is potentially inaccurate.
8704 if Nkind (Rop) = N_Real_Literal
8705 and then Realval (Rop) /= Ureal_0
8706 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
8709 ("?universal real operand can only " &
8710 "be interpreted as Duration!",
8713 ("\?precision will be lost in the conversion!", Rop);
8716 elsif Is_Numeric_Type (Typ)
8717 and then Nkind (Operand) in N_Op
8718 and then Unique_Fixed_Point_Type (N) /= Any_Type
8720 Set_Etype (Operand, Standard_Duration);
8723 Error_Msg_N ("invalid context for mixed mode operation", N);
8724 Set_Etype (Operand, Any_Type);
8731 -- Note: we do the Eval_Type_Conversion call before applying the
8732 -- required checks for a subtype conversion. This is important, since
8733 -- both are prepared under certain circumstances to change the type
8734 -- conversion to a constraint error node, but in the case of
8735 -- Eval_Type_Conversion this may reflect an illegality in the static
8736 -- case, and we would miss the illegality (getting only a warning
8737 -- message), if we applied the type conversion checks first.
8739 Eval_Type_Conversion (N);
8741 -- Even when evaluation is not possible, we may be able to simplify the
8742 -- conversion or its expression. This needs to be done before applying
8743 -- checks, since otherwise the checks may use the original expression
8744 -- and defeat the simplifications. This is specifically the case for
8745 -- elimination of the floating-point Truncation attribute in
8746 -- float-to-int conversions.
8748 Simplify_Type_Conversion (N);
8750 -- If after evaluation we still have a type conversion, then we may need
8751 -- to apply checks required for a subtype conversion.
8753 -- Skip these type conversion checks if universal fixed operands
8754 -- operands involved, since range checks are handled separately for
8755 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
8757 if Nkind (N) = N_Type_Conversion
8758 and then not Is_Generic_Type (Root_Type (Target_Typ))
8759 and then Target_Typ /= Universal_Fixed
8760 and then Operand_Typ /= Universal_Fixed
8762 Apply_Type_Conversion_Checks (N);
8765 -- Issue warning for conversion of simple object to its own type. We
8766 -- have to test the original nodes, since they may have been rewritten
8767 -- by various optimizations.
8769 Orig_N := Original_Node (N);
8771 if Warn_On_Redundant_Constructs
8772 and then Comes_From_Source (Orig_N)
8773 and then Nkind (Orig_N) = N_Type_Conversion
8774 and then not In_Instance
8776 Orig_N := Original_Node (Expression (Orig_N));
8777 Orig_T := Target_Typ;
8779 -- If the node is part of a larger expression, the Target_Type
8780 -- may not be the original type of the node if the context is a
8781 -- condition. Recover original type to see if conversion is needed.
8783 if Is_Boolean_Type (Orig_T)
8784 and then Nkind (Parent (N)) in N_Op
8786 Orig_T := Etype (Parent (N));
8789 if Is_Entity_Name (Orig_N)
8791 (Etype (Entity (Orig_N)) = Orig_T
8793 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
8794 and then Covers (Orig_T, Etype (Entity (Orig_N)))))
8796 -- One more check, do not give warning if the analyzed conversion
8797 -- has an expression with non-static bounds, and the bounds of the
8798 -- target are static. This avoids junk warnings in cases where the
8799 -- conversion is necessary to establish staticness, for example in
8800 -- a case statement.
8802 if not Is_OK_Static_Subtype (Operand_Typ)
8803 and then Is_OK_Static_Subtype (Target_Typ)
8807 -- Here we give the redundant conversion warning
8810 Error_Msg_Node_2 := Orig_T;
8811 Error_Msg_NE -- CODEFIX
8812 ("?redundant conversion, & is of type &!",
8813 N, Entity (Orig_N));
8818 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
8819 -- No need to perform any interface conversion if the type of the
8820 -- expression coincides with the target type.
8822 if Ada_Version >= Ada_05
8823 and then Expander_Active
8824 and then Operand_Typ /= Target_Typ
8827 Opnd : Entity_Id := Operand_Typ;
8828 Target : Entity_Id := Target_Typ;
8831 if Is_Access_Type (Opnd) then
8832 Opnd := Designated_Type (Opnd);
8835 if Is_Access_Type (Target_Typ) then
8836 Target := Designated_Type (Target);
8839 if Opnd = Target then
8842 -- Conversion from interface type
8844 elsif Is_Interface (Opnd) then
8846 -- Ada 2005 (AI-217): Handle entities from limited views
8848 if From_With_Type (Opnd) then
8849 Error_Msg_Qual_Level := 99;
8850 Error_Msg_NE -- CODEFIX
8851 ("missing WITH clause on package &", N,
8852 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
8854 ("type conversions require visibility of the full view",
8857 elsif From_With_Type (Target)
8859 (Is_Access_Type (Target_Typ)
8860 and then Present (Non_Limited_View (Etype (Target))))
8862 Error_Msg_Qual_Level := 99;
8863 Error_Msg_NE -- CODEFIX
8864 ("missing WITH clause on package &", N,
8865 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
8867 ("type conversions require visibility of the full view",
8871 Expand_Interface_Conversion (N, Is_Static => False);
8874 -- Conversion to interface type
8876 elsif Is_Interface (Target) then
8880 if Ekind_In (Opnd, E_Protected_Subtype, E_Task_Subtype) then
8881 Opnd := Etype (Opnd);
8884 if not Interface_Present_In_Ancestor
8888 if Is_Class_Wide_Type (Opnd) then
8890 -- The static analysis is not enough to know if the
8891 -- interface is implemented or not. Hence we must pass
8892 -- the work to the expander to generate code to evaluate
8893 -- the conversion at run-time.
8895 Expand_Interface_Conversion (N, Is_Static => False);
8898 Error_Msg_Name_1 := Chars (Etype (Target));
8899 Error_Msg_Name_2 := Chars (Opnd);
8901 ("wrong interface conversion (% is not a progenitor " &
8906 Expand_Interface_Conversion (N);
8911 end Resolve_Type_Conversion;
8913 ----------------------
8914 -- Resolve_Unary_Op --
8915 ----------------------
8917 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
8918 B_Typ : constant Entity_Id := Base_Type (Typ);
8919 R : constant Node_Id := Right_Opnd (N);
8925 -- Deal with intrinsic unary operators
8927 if Comes_From_Source (N)
8928 and then Ekind (Entity (N)) = E_Function
8929 and then Is_Imported (Entity (N))
8930 and then Is_Intrinsic_Subprogram (Entity (N))
8932 Resolve_Intrinsic_Unary_Operator (N, Typ);
8936 -- Deal with universal cases
8938 if Etype (R) = Universal_Integer
8940 Etype (R) = Universal_Real
8942 Check_For_Visible_Operator (N, B_Typ);
8945 Set_Etype (N, B_Typ);
8948 -- Generate warning for expressions like abs (x mod 2)
8950 if Warn_On_Redundant_Constructs
8951 and then Nkind (N) = N_Op_Abs
8953 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
8955 if OK and then Hi >= Lo and then Lo >= 0 then
8956 Error_Msg_N -- CODEFIX
8957 ("?abs applied to known non-negative value has no effect", N);
8961 -- Deal with reference generation
8963 Check_Unset_Reference (R);
8964 Generate_Operator_Reference (N, B_Typ);
8967 -- Set overflow checking bit. Much cleverer code needed here eventually
8968 -- and perhaps the Resolve routines should be separated for the various
8969 -- arithmetic operations, since they will need different processing ???
8971 if Nkind (N) in N_Op then
8972 if not Overflow_Checks_Suppressed (Etype (N)) then
8973 Enable_Overflow_Check (N);
8977 -- Generate warning for expressions like -5 mod 3 for integers. No need
8978 -- to worry in the floating-point case, since parens do not affect the
8979 -- result so there is no point in giving in a warning.
8982 Norig : constant Node_Id := Original_Node (N);
8991 if Warn_On_Questionable_Missing_Parens
8992 and then Comes_From_Source (Norig)
8993 and then Is_Integer_Type (Typ)
8994 and then Nkind (Norig) = N_Op_Minus
8996 Rorig := Original_Node (Right_Opnd (Norig));
8998 -- We are looking for cases where the right operand is not
8999 -- parenthesized, and is a binary operator, multiply, divide, or
9000 -- mod. These are the cases where the grouping can affect results.
9002 if Paren_Count (Rorig) = 0
9003 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
9005 -- For mod, we always give the warning, since the value is
9006 -- affected by the parenthesization (e.g. (-5) mod 315 /=
9007 -- -(5 mod 315)). But for the other cases, the only concern is
9008 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
9009 -- overflows, but (-2) * 64 does not). So we try to give the
9010 -- message only when overflow is possible.
9012 if Nkind (Rorig) /= N_Op_Mod
9013 and then Compile_Time_Known_Value (R)
9015 Val := Expr_Value (R);
9017 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
9018 HB := Expr_Value (Type_High_Bound (Typ));
9020 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
9023 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
9024 LB := Expr_Value (Type_Low_Bound (Typ));
9026 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
9029 -- Note that the test below is deliberately excluding the
9030 -- largest negative number, since that is a potentially
9031 -- troublesome case (e.g. -2 * x, where the result is the
9032 -- largest negative integer has an overflow with 2 * x).
9034 if Val > LB and then Val <= HB then
9039 -- For the multiplication case, the only case we have to worry
9040 -- about is when (-a)*b is exactly the largest negative number
9041 -- so that -(a*b) can cause overflow. This can only happen if
9042 -- a is a power of 2, and more generally if any operand is a
9043 -- constant that is not a power of 2, then the parentheses
9044 -- cannot affect whether overflow occurs. We only bother to
9045 -- test the left most operand
9047 -- Loop looking at left operands for one that has known value
9050 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
9051 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
9052 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
9054 -- Operand value of 0 or 1 skips warning
9059 -- Otherwise check power of 2, if power of 2, warn, if
9060 -- anything else, skip warning.
9063 while Lval /= 2 loop
9064 if Lval mod 2 = 1 then
9075 -- Keep looking at left operands
9077 Opnd := Left_Opnd (Opnd);
9080 -- For rem or "/" we can only have a problematic situation
9081 -- if the divisor has a value of minus one or one. Otherwise
9082 -- overflow is impossible (divisor > 1) or we have a case of
9083 -- division by zero in any case.
9085 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
9086 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
9087 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
9092 -- If we fall through warning should be issued
9095 ("?unary minus expression should be parenthesized here!", N);
9099 end Resolve_Unary_Op;
9101 ----------------------------------
9102 -- Resolve_Unchecked_Expression --
9103 ----------------------------------
9105 procedure Resolve_Unchecked_Expression
9110 Resolve (Expression (N), Typ, Suppress => All_Checks);
9112 end Resolve_Unchecked_Expression;
9114 ---------------------------------------
9115 -- Resolve_Unchecked_Type_Conversion --
9116 ---------------------------------------
9118 procedure Resolve_Unchecked_Type_Conversion
9122 pragma Warnings (Off, Typ);
9124 Operand : constant Node_Id := Expression (N);
9125 Opnd_Type : constant Entity_Id := Etype (Operand);
9128 -- Resolve operand using its own type
9130 Resolve (Operand, Opnd_Type);
9131 Eval_Unchecked_Conversion (N);
9133 end Resolve_Unchecked_Type_Conversion;
9135 ------------------------------
9136 -- Rewrite_Operator_As_Call --
9137 ------------------------------
9139 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
9140 Loc : constant Source_Ptr := Sloc (N);
9141 Actuals : constant List_Id := New_List;
9145 if Nkind (N) in N_Binary_Op then
9146 Append (Left_Opnd (N), Actuals);
9149 Append (Right_Opnd (N), Actuals);
9152 Make_Function_Call (Sloc => Loc,
9153 Name => New_Occurrence_Of (Nam, Loc),
9154 Parameter_Associations => Actuals);
9156 Preserve_Comes_From_Source (New_N, N);
9157 Preserve_Comes_From_Source (Name (New_N), N);
9159 Set_Etype (N, Etype (Nam));
9160 end Rewrite_Operator_As_Call;
9162 ------------------------------
9163 -- Rewrite_Renamed_Operator --
9164 ------------------------------
9166 procedure Rewrite_Renamed_Operator
9171 Nam : constant Name_Id := Chars (Op);
9172 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
9176 -- Rewrite the operator node using the real operator, not its renaming.
9177 -- Exclude user-defined intrinsic operations of the same name, which are
9178 -- treated separately and rewritten as calls.
9180 if Ekind (Op) /= E_Function or else Chars (N) /= Nam then
9181 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
9182 Set_Chars (Op_Node, Nam);
9183 Set_Etype (Op_Node, Etype (N));
9184 Set_Entity (Op_Node, Op);
9185 Set_Right_Opnd (Op_Node, Right_Opnd (N));
9187 -- Indicate that both the original entity and its renaming are
9188 -- referenced at this point.
9190 Generate_Reference (Entity (N), N);
9191 Generate_Reference (Op, N);
9194 Set_Left_Opnd (Op_Node, Left_Opnd (N));
9197 Rewrite (N, Op_Node);
9199 -- If the context type is private, add the appropriate conversions
9200 -- so that the operator is applied to the full view. This is done
9201 -- in the routines that resolve intrinsic operators,
9203 if Is_Intrinsic_Subprogram (Op)
9204 and then Is_Private_Type (Typ)
9207 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
9208 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
9209 Resolve_Intrinsic_Operator (N, Typ);
9211 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
9212 Resolve_Intrinsic_Unary_Operator (N, Typ);
9219 elsif Ekind (Op) = E_Function and then Is_Intrinsic_Subprogram (Op) then
9221 -- Operator renames a user-defined operator of the same name. Use
9222 -- the original operator in the node, which is the one that Gigi
9226 Set_Is_Overloaded (N, False);
9228 end Rewrite_Renamed_Operator;
9230 -----------------------
9231 -- Set_Slice_Subtype --
9232 -----------------------
9234 -- Build an implicit subtype declaration to represent the type delivered
9235 -- by the slice. This is an abbreviated version of an array subtype. We
9236 -- define an index subtype for the slice, using either the subtype name
9237 -- or the discrete range of the slice. To be consistent with index usage
9238 -- elsewhere, we create a list header to hold the single index. This list
9239 -- is not otherwise attached to the syntax tree.
9241 procedure Set_Slice_Subtype (N : Node_Id) is
9242 Loc : constant Source_Ptr := Sloc (N);
9243 Index_List : constant List_Id := New_List;
9245 Index_Subtype : Entity_Id;
9246 Index_Type : Entity_Id;
9247 Slice_Subtype : Entity_Id;
9248 Drange : constant Node_Id := Discrete_Range (N);
9251 if Is_Entity_Name (Drange) then
9252 Index_Subtype := Entity (Drange);
9255 -- We force the evaluation of a range. This is definitely needed in
9256 -- the renamed case, and seems safer to do unconditionally. Note in
9257 -- any case that since we will create and insert an Itype referring
9258 -- to this range, we must make sure any side effect removal actions
9259 -- are inserted before the Itype definition.
9261 if Nkind (Drange) = N_Range then
9262 Force_Evaluation (Low_Bound (Drange));
9263 Force_Evaluation (High_Bound (Drange));
9266 Index_Type := Base_Type (Etype (Drange));
9268 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9270 -- Take a new copy of Drange (where bounds have been rewritten to
9271 -- reference side-effect-vree names). Using a separate tree ensures
9272 -- that further expansion (e.g while rewriting a slice assignment
9273 -- into a FOR loop) does not attempt to remove side effects on the
9274 -- bounds again (which would cause the bounds in the index subtype
9275 -- definition to refer to temporaries before they are defined) (the
9276 -- reason is that some names are considered side effect free here
9277 -- for the subtype, but not in the context of a loop iteration
9280 Set_Scalar_Range (Index_Subtype, New_Copy_Tree (Drange));
9281 Set_Etype (Index_Subtype, Index_Type);
9282 Set_Size_Info (Index_Subtype, Index_Type);
9283 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9286 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
9288 Index := New_Occurrence_Of (Index_Subtype, Loc);
9289 Set_Etype (Index, Index_Subtype);
9290 Append (Index, Index_List);
9292 Set_First_Index (Slice_Subtype, Index);
9293 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
9294 Set_Is_Constrained (Slice_Subtype, True);
9296 Check_Compile_Time_Size (Slice_Subtype);
9298 -- The Etype of the existing Slice node is reset to this slice subtype.
9299 -- Its bounds are obtained from its first index.
9301 Set_Etype (N, Slice_Subtype);
9303 -- For packed slice subtypes, freeze immediately (except in the
9304 -- case of being in a "spec expression" where we never freeze
9305 -- when we first see the expression).
9307 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
9308 Freeze_Itype (Slice_Subtype, N);
9310 -- For all other cases insert an itype reference in the slice's actions
9311 -- so that the itype is frozen at the proper place in the tree (i.e. at
9312 -- the point where actions for the slice are analyzed). Note that this
9313 -- is different from freezing the itype immediately, which might be
9314 -- premature (e.g. if the slice is within a transient scope).
9317 Ensure_Defined (Typ => Slice_Subtype, N => N);
9319 end Set_Slice_Subtype;
9321 --------------------------------
9322 -- Set_String_Literal_Subtype --
9323 --------------------------------
9325 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
9326 Loc : constant Source_Ptr := Sloc (N);
9327 Low_Bound : constant Node_Id :=
9328 Type_Low_Bound (Etype (First_Index (Typ)));
9329 Subtype_Id : Entity_Id;
9332 if Nkind (N) /= N_String_Literal then
9336 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
9337 Set_String_Literal_Length (Subtype_Id, UI_From_Int
9338 (String_Length (Strval (N))));
9339 Set_Etype (Subtype_Id, Base_Type (Typ));
9340 Set_Is_Constrained (Subtype_Id);
9341 Set_Etype (N, Subtype_Id);
9343 if Is_OK_Static_Expression (Low_Bound) then
9345 -- The low bound is set from the low bound of the corresponding
9346 -- index type. Note that we do not store the high bound in the
9347 -- string literal subtype, but it can be deduced if necessary
9348 -- from the length and the low bound.
9350 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
9353 Set_String_Literal_Low_Bound
9354 (Subtype_Id, Make_Integer_Literal (Loc, 1));
9355 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Standard_Positive);
9357 -- Build bona fide subtype for the string, and wrap it in an
9358 -- unchecked conversion, because the backend expects the
9359 -- String_Literal_Subtype to have a static lower bound.
9362 Index_List : constant List_Id := New_List;
9363 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
9364 High_Bound : constant Node_Id :=
9366 Left_Opnd => New_Copy_Tree (Low_Bound),
9368 Make_Integer_Literal (Loc,
9369 String_Length (Strval (N)) - 1));
9370 Array_Subtype : Entity_Id;
9371 Index_Subtype : Entity_Id;
9377 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
9378 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
9379 Set_Scalar_Range (Index_Subtype, Drange);
9380 Set_Parent (Drange, N);
9381 Analyze_And_Resolve (Drange, Index_Type);
9383 -- In the context, the Index_Type may already have a constraint,
9384 -- so use common base type on string subtype. The base type may
9385 -- be used when generating attributes of the string, for example
9386 -- in the context of a slice assignment.
9388 Set_Etype (Index_Subtype, Base_Type (Index_Type));
9389 Set_Size_Info (Index_Subtype, Index_Type);
9390 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
9392 Array_Subtype := Create_Itype (E_Array_Subtype, N);
9394 Index := New_Occurrence_Of (Index_Subtype, Loc);
9395 Set_Etype (Index, Index_Subtype);
9396 Append (Index, Index_List);
9398 Set_First_Index (Array_Subtype, Index);
9399 Set_Etype (Array_Subtype, Base_Type (Typ));
9400 Set_Is_Constrained (Array_Subtype, True);
9403 Make_Unchecked_Type_Conversion (Loc,
9404 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
9405 Expression => Relocate_Node (N)));
9406 Set_Etype (N, Array_Subtype);
9409 end Set_String_Literal_Subtype;
9411 ------------------------------
9412 -- Simplify_Type_Conversion --
9413 ------------------------------
9415 procedure Simplify_Type_Conversion (N : Node_Id) is
9417 if Nkind (N) = N_Type_Conversion then
9419 Operand : constant Node_Id := Expression (N);
9420 Target_Typ : constant Entity_Id := Etype (N);
9421 Opnd_Typ : constant Entity_Id := Etype (Operand);
9424 if Is_Floating_Point_Type (Opnd_Typ)
9426 (Is_Integer_Type (Target_Typ)
9427 or else (Is_Fixed_Point_Type (Target_Typ)
9428 and then Conversion_OK (N)))
9429 and then Nkind (Operand) = N_Attribute_Reference
9430 and then Attribute_Name (Operand) = Name_Truncation
9432 -- Special processing required if the conversion is the expression
9433 -- of a Truncation attribute reference. In this case we replace:
9435 -- ityp (ftyp'Truncation (x))
9441 -- with the Float_Truncate flag set, which is more efficient
9445 Relocate_Node (First (Expressions (Operand))));
9446 Set_Float_Truncate (N, True);
9450 end Simplify_Type_Conversion;
9452 -----------------------------
9453 -- Unique_Fixed_Point_Type --
9454 -----------------------------
9456 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
9457 T1 : Entity_Id := Empty;
9462 procedure Fixed_Point_Error;
9463 -- Give error messages for true ambiguity. Messages are posted on node
9464 -- N, and entities T1, T2 are the possible interpretations.
9466 -----------------------
9467 -- Fixed_Point_Error --
9468 -----------------------
9470 procedure Fixed_Point_Error is
9472 Error_Msg_N ("ambiguous universal_fixed_expression", N);
9473 Error_Msg_NE ("\\possible interpretation as}", N, T1);
9474 Error_Msg_NE ("\\possible interpretation as}", N, T2);
9475 end Fixed_Point_Error;
9477 -- Start of processing for Unique_Fixed_Point_Type
9480 -- The operations on Duration are visible, so Duration is always a
9481 -- possible interpretation.
9483 T1 := Standard_Duration;
9485 -- Look for fixed-point types in enclosing scopes
9487 Scop := Current_Scope;
9488 while Scop /= Standard_Standard loop
9489 T2 := First_Entity (Scop);
9490 while Present (T2) loop
9491 if Is_Fixed_Point_Type (T2)
9492 and then Current_Entity (T2) = T2
9493 and then Scope (Base_Type (T2)) = Scop
9495 if Present (T1) then
9506 Scop := Scope (Scop);
9509 -- Look for visible fixed type declarations in the context
9511 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
9512 while Present (Item) loop
9513 if Nkind (Item) = N_With_Clause then
9514 Scop := Entity (Name (Item));
9515 T2 := First_Entity (Scop);
9516 while Present (T2) loop
9517 if Is_Fixed_Point_Type (T2)
9518 and then Scope (Base_Type (T2)) = Scop
9519 and then (Is_Potentially_Use_Visible (T2)
9520 or else In_Use (T2))
9522 if Present (T1) then
9537 if Nkind (N) = N_Real_Literal then
9538 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
9540 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
9544 end Unique_Fixed_Point_Type;
9546 ----------------------
9547 -- Valid_Conversion --
9548 ----------------------
9550 function Valid_Conversion
9553 Operand : Node_Id) return Boolean
9555 Target_Type : constant Entity_Id := Base_Type (Target);
9556 Opnd_Type : Entity_Id := Etype (Operand);
9558 function Conversion_Check
9560 Msg : String) return Boolean;
9561 -- Little routine to post Msg if Valid is False, returns Valid value
9563 function Valid_Tagged_Conversion
9564 (Target_Type : Entity_Id;
9565 Opnd_Type : Entity_Id) return Boolean;
9566 -- Specifically test for validity of tagged conversions
9568 function Valid_Array_Conversion return Boolean;
9569 -- Check index and component conformance, and accessibility levels
9570 -- if the component types are anonymous access types (Ada 2005)
9572 ----------------------
9573 -- Conversion_Check --
9574 ----------------------
9576 function Conversion_Check
9578 Msg : String) return Boolean
9582 Error_Msg_N (Msg, Operand);
9586 end Conversion_Check;
9588 ----------------------------
9589 -- Valid_Array_Conversion --
9590 ----------------------------
9592 function Valid_Array_Conversion return Boolean
9594 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
9595 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
9597 Opnd_Index : Node_Id;
9598 Opnd_Index_Type : Entity_Id;
9600 Target_Comp_Type : constant Entity_Id :=
9601 Component_Type (Target_Type);
9602 Target_Comp_Base : constant Entity_Id :=
9603 Base_Type (Target_Comp_Type);
9605 Target_Index : Node_Id;
9606 Target_Index_Type : Entity_Id;
9609 -- Error if wrong number of dimensions
9612 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
9615 ("incompatible number of dimensions for conversion", Operand);
9618 -- Number of dimensions matches
9621 -- Loop through indexes of the two arrays
9623 Target_Index := First_Index (Target_Type);
9624 Opnd_Index := First_Index (Opnd_Type);
9625 while Present (Target_Index) and then Present (Opnd_Index) loop
9626 Target_Index_Type := Etype (Target_Index);
9627 Opnd_Index_Type := Etype (Opnd_Index);
9629 -- Error if index types are incompatible
9631 if not (Is_Integer_Type (Target_Index_Type)
9632 and then Is_Integer_Type (Opnd_Index_Type))
9633 and then (Root_Type (Target_Index_Type)
9634 /= Root_Type (Opnd_Index_Type))
9637 ("incompatible index types for array conversion",
9642 Next_Index (Target_Index);
9643 Next_Index (Opnd_Index);
9646 -- If component types have same base type, all set
9648 if Target_Comp_Base = Opnd_Comp_Base then
9651 -- Here if base types of components are not the same. The only
9652 -- time this is allowed is if we have anonymous access types.
9654 -- The conversion of arrays of anonymous access types can lead
9655 -- to dangling pointers. AI-392 formalizes the accessibility
9656 -- checks that must be applied to such conversions to prevent
9657 -- out-of-scope references.
9660 Ekind_In (Target_Comp_Base, E_Anonymous_Access_Type,
9661 E_Anonymous_Access_Subprogram_Type)
9662 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
9664 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
9666 if Type_Access_Level (Target_Type) <
9667 Type_Access_Level (Opnd_Type)
9669 if In_Instance_Body then
9670 Error_Msg_N ("?source array type " &
9671 "has deeper accessibility level than target", Operand);
9672 Error_Msg_N ("\?Program_Error will be raised at run time",
9675 Make_Raise_Program_Error (Sloc (N),
9676 Reason => PE_Accessibility_Check_Failed));
9677 Set_Etype (N, Target_Type);
9680 -- Conversion not allowed because of accessibility levels
9683 Error_Msg_N ("source array type " &
9684 "has deeper accessibility level than target", Operand);
9691 -- All other cases where component base types do not match
9695 ("incompatible component types for array conversion",
9700 -- Check that component subtypes statically match. For numeric
9701 -- types this means that both must be either constrained or
9702 -- unconstrained. For enumeration types the bounds must match.
9703 -- All of this is checked in Subtypes_Statically_Match.
9705 if not Subtypes_Statically_Match
9706 (Target_Comp_Type, Opnd_Comp_Type)
9709 ("component subtypes must statically match", Operand);
9715 end Valid_Array_Conversion;
9717 -----------------------------
9718 -- Valid_Tagged_Conversion --
9719 -----------------------------
9721 function Valid_Tagged_Conversion
9722 (Target_Type : Entity_Id;
9723 Opnd_Type : Entity_Id) return Boolean
9726 -- Upward conversions are allowed (RM 4.6(22))
9728 if Covers (Target_Type, Opnd_Type)
9729 or else Is_Ancestor (Target_Type, Opnd_Type)
9733 -- Downward conversion are allowed if the operand is class-wide
9736 elsif Is_Class_Wide_Type (Opnd_Type)
9737 and then Covers (Opnd_Type, Target_Type)
9741 elsif Covers (Opnd_Type, Target_Type)
9742 or else Is_Ancestor (Opnd_Type, Target_Type)
9745 Conversion_Check (False,
9746 "downward conversion of tagged objects not allowed");
9748 -- Ada 2005 (AI-251): The conversion to/from interface types is
9751 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
9754 -- If the operand is a class-wide type obtained through a limited_
9755 -- with clause, and the context includes the non-limited view, use
9756 -- it to determine whether the conversion is legal.
9758 elsif Is_Class_Wide_Type (Opnd_Type)
9759 and then From_With_Type (Opnd_Type)
9760 and then Present (Non_Limited_View (Etype (Opnd_Type)))
9761 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
9765 elsif Is_Access_Type (Opnd_Type)
9766 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
9772 ("invalid tagged conversion, not compatible with}",
9773 N, First_Subtype (Opnd_Type));
9776 end Valid_Tagged_Conversion;
9778 -- Start of processing for Valid_Conversion
9781 Check_Parameterless_Call (Operand);
9783 if Is_Overloaded (Operand) then
9793 -- Remove procedure calls, which syntactically cannot appear in
9794 -- this context, but which cannot be removed by type checking,
9795 -- because the context does not impose a type.
9797 -- When compiling for VMS, spurious ambiguities can be produced
9798 -- when arithmetic operations have a literal operand and return
9799 -- System.Address or a descendant of it. These ambiguities are
9800 -- otherwise resolved by the context, but for conversions there
9801 -- is no context type and the removal of the spurious operations
9802 -- must be done explicitly here.
9804 -- The node may be labelled overloaded, but still contain only
9805 -- one interpretation because others were discarded in previous
9806 -- filters. If this is the case, retain the single interpretation
9809 Get_First_Interp (Operand, I, It);
9810 Opnd_Type := It.Typ;
9811 Get_Next_Interp (I, It);
9814 and then Opnd_Type /= Standard_Void_Type
9816 -- More than one candidate interpretation is available
9818 Get_First_Interp (Operand, I, It);
9819 while Present (It.Typ) loop
9820 if It.Typ = Standard_Void_Type then
9824 if Present (System_Aux_Id)
9825 and then Is_Descendent_Of_Address (It.Typ)
9830 Get_Next_Interp (I, It);
9834 Get_First_Interp (Operand, I, It);
9839 Error_Msg_N ("illegal operand in conversion", Operand);
9843 Get_Next_Interp (I, It);
9845 if Present (It.Typ) then
9848 It1 := Disambiguate (Operand, I1, I, Any_Type);
9850 if It1 = No_Interp then
9851 Error_Msg_N ("ambiguous operand in conversion", Operand);
9853 -- If the interpretation involves a standard operator, use
9854 -- the location of the type, which may be user-defined.
9856 if Sloc (It.Nam) = Standard_Location then
9857 Error_Msg_Sloc := Sloc (It.Typ);
9859 Error_Msg_Sloc := Sloc (It.Nam);
9862 Error_Msg_N -- CODEFIX
9863 ("\\possible interpretation#!", Operand);
9865 if Sloc (N1) = Standard_Location then
9866 Error_Msg_Sloc := Sloc (T1);
9868 Error_Msg_Sloc := Sloc (N1);
9871 Error_Msg_N -- CODEFIX
9872 ("\\possible interpretation#!", Operand);
9878 Set_Etype (Operand, It1.Typ);
9879 Opnd_Type := It1.Typ;
9885 if Is_Numeric_Type (Target_Type) then
9887 -- A universal fixed expression can be converted to any numeric type
9889 if Opnd_Type = Universal_Fixed then
9892 -- Also no need to check when in an instance or inlined body, because
9893 -- the legality has been established when the template was analyzed.
9894 -- Furthermore, numeric conversions may occur where only a private
9895 -- view of the operand type is visible at the instantiation point.
9896 -- This results in a spurious error if we check that the operand type
9897 -- is a numeric type.
9899 -- Note: in a previous version of this unit, the following tests were
9900 -- applied only for generated code (Comes_From_Source set to False),
9901 -- but in fact the test is required for source code as well, since
9902 -- this situation can arise in source code.
9904 elsif In_Instance or else In_Inlined_Body then
9907 -- Otherwise we need the conversion check
9910 return Conversion_Check
9911 (Is_Numeric_Type (Opnd_Type),
9912 "illegal operand for numeric conversion");
9917 elsif Is_Array_Type (Target_Type) then
9918 if not Is_Array_Type (Opnd_Type)
9919 or else Opnd_Type = Any_Composite
9920 or else Opnd_Type = Any_String
9923 ("illegal operand for array conversion", Operand);
9926 return Valid_Array_Conversion;
9929 -- Ada 2005 (AI-251): Anonymous access types where target references an
9932 elsif Ekind_In (Target_Type, E_General_Access_Type,
9933 E_Anonymous_Access_Type)
9934 and then Is_Interface (Directly_Designated_Type (Target_Type))
9936 -- Check the static accessibility rule of 4.6(17). Note that the
9937 -- check is not enforced when within an instance body, since the
9938 -- RM requires such cases to be caught at run time.
9940 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
9941 if Type_Access_Level (Opnd_Type) >
9942 Type_Access_Level (Target_Type)
9944 -- In an instance, this is a run-time check, but one we know
9945 -- will fail, so generate an appropriate warning. The raise
9946 -- will be generated by Expand_N_Type_Conversion.
9948 if In_Instance_Body then
9950 ("?cannot convert local pointer to non-local access type",
9953 ("\?Program_Error will be raised at run time", Operand);
9956 ("cannot convert local pointer to non-local access type",
9961 -- Special accessibility checks are needed in the case of access
9962 -- discriminants declared for a limited type.
9964 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
9965 and then not Is_Local_Anonymous_Access (Opnd_Type)
9967 -- When the operand is a selected access discriminant the check
9968 -- needs to be made against the level of the object denoted by
9969 -- the prefix of the selected name (Object_Access_Level handles
9970 -- checking the prefix of the operand for this case).
9972 if Nkind (Operand) = N_Selected_Component
9973 and then Object_Access_Level (Operand) >
9974 Type_Access_Level (Target_Type)
9976 -- In an instance, this is a run-time check, but one we know
9977 -- will fail, so generate an appropriate warning. The raise
9978 -- will be generated by Expand_N_Type_Conversion.
9980 if In_Instance_Body then
9982 ("?cannot convert access discriminant to non-local" &
9983 " access type", Operand);
9985 ("\?Program_Error will be raised at run time", Operand);
9988 ("cannot convert access discriminant to non-local" &
9989 " access type", Operand);
9994 -- The case of a reference to an access discriminant from
9995 -- within a limited type declaration (which will appear as
9996 -- a discriminal) is always illegal because the level of the
9997 -- discriminant is considered to be deeper than any (nameable)
10000 if Is_Entity_Name (Operand)
10001 and then not Is_Local_Anonymous_Access (Opnd_Type)
10003 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10004 and then Present (Discriminal_Link (Entity (Operand)))
10007 ("discriminant has deeper accessibility level than target",
10016 -- General and anonymous access types
10018 elsif Ekind_In (Target_Type, E_General_Access_Type,
10019 E_Anonymous_Access_Type)
10022 (Is_Access_Type (Opnd_Type)
10024 Ekind_In (Opnd_Type, E_Access_Subprogram_Type,
10025 E_Access_Protected_Subprogram_Type),
10026 "must be an access-to-object type")
10028 if Is_Access_Constant (Opnd_Type)
10029 and then not Is_Access_Constant (Target_Type)
10032 ("access-to-constant operand type not allowed", Operand);
10036 -- Check the static accessibility rule of 4.6(17). Note that the
10037 -- check is not enforced when within an instance body, since the RM
10038 -- requires such cases to be caught at run time.
10040 if Ekind (Target_Type) /= E_Anonymous_Access_Type
10041 or else Is_Local_Anonymous_Access (Target_Type)
10043 if Type_Access_Level (Opnd_Type)
10044 > Type_Access_Level (Target_Type)
10046 -- In an instance, this is a run-time check, but one we know
10047 -- will fail, so generate an appropriate warning. The raise
10048 -- will be generated by Expand_N_Type_Conversion.
10050 if In_Instance_Body then
10052 ("?cannot convert local pointer to non-local access type",
10055 ("\?Program_Error will be raised at run time", Operand);
10058 -- Avoid generation of spurious error message
10060 if not Error_Posted (N) then
10062 ("cannot convert local pointer to non-local access type",
10069 -- Special accessibility checks are needed in the case of access
10070 -- discriminants declared for a limited type.
10072 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10073 and then not Is_Local_Anonymous_Access (Opnd_Type)
10075 -- When the operand is a selected access discriminant the check
10076 -- needs to be made against the level of the object denoted by
10077 -- the prefix of the selected name (Object_Access_Level handles
10078 -- checking the prefix of the operand for this case).
10080 if Nkind (Operand) = N_Selected_Component
10081 and then Object_Access_Level (Operand) >
10082 Type_Access_Level (Target_Type)
10084 -- In an instance, this is a run-time check, but one we know
10085 -- will fail, so generate an appropriate warning. The raise
10086 -- will be generated by Expand_N_Type_Conversion.
10088 if In_Instance_Body then
10090 ("?cannot convert access discriminant to non-local" &
10091 " access type", Operand);
10093 ("\?Program_Error will be raised at run time",
10098 ("cannot convert access discriminant to non-local" &
10099 " access type", Operand);
10104 -- The case of a reference to an access discriminant from
10105 -- within a limited type declaration (which will appear as
10106 -- a discriminal) is always illegal because the level of the
10107 -- discriminant is considered to be deeper than any (nameable)
10110 if Is_Entity_Name (Operand)
10112 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10113 and then Present (Discriminal_Link (Entity (Operand)))
10116 ("discriminant has deeper accessibility level than target",
10123 -- In the presence of limited_with clauses we have to use non-limited
10124 -- views, if available.
10126 Check_Limited : declare
10127 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
10128 -- Helper function to handle limited views
10130 --------------------------
10131 -- Full_Designated_Type --
10132 --------------------------
10134 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
10135 Desig : constant Entity_Id := Designated_Type (T);
10138 -- Handle the limited view of a type
10140 if Is_Incomplete_Type (Desig)
10141 and then From_With_Type (Desig)
10142 and then Present (Non_Limited_View (Desig))
10144 return Available_View (Desig);
10148 end Full_Designated_Type;
10150 -- Local Declarations
10152 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
10153 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
10155 Same_Base : constant Boolean :=
10156 Base_Type (Target) = Base_Type (Opnd);
10158 -- Start of processing for Check_Limited
10161 if Is_Tagged_Type (Target) then
10162 return Valid_Tagged_Conversion (Target, Opnd);
10165 if not Same_Base then
10167 ("target designated type not compatible with }",
10168 N, Base_Type (Opnd));
10171 -- Ada 2005 AI-384: legality rule is symmetric in both
10172 -- designated types. The conversion is legal (with possible
10173 -- constraint check) if either designated type is
10176 elsif Subtypes_Statically_Match (Target, Opnd)
10178 (Has_Discriminants (Target)
10180 (not Is_Constrained (Opnd)
10181 or else not Is_Constrained (Target)))
10183 -- Special case, if Value_Size has been used to make the
10184 -- sizes different, the conversion is not allowed even
10185 -- though the subtypes statically match.
10187 if Known_Static_RM_Size (Target)
10188 and then Known_Static_RM_Size (Opnd)
10189 and then RM_Size (Target) /= RM_Size (Opnd)
10192 ("target designated subtype not compatible with }",
10195 ("\because sizes of the two designated subtypes differ",
10199 -- Normal case where conversion is allowed
10207 ("target designated subtype not compatible with }",
10214 -- Access to subprogram types. If the operand is an access parameter,
10215 -- the type has a deeper accessibility that any master, and cannot
10216 -- be assigned. We must make an exception if the conversion is part
10217 -- of an assignment and the target is the return object of an extended
10218 -- return statement, because in that case the accessibility check
10219 -- takes place after the return.
10221 elsif Is_Access_Subprogram_Type (Target_Type)
10222 and then No (Corresponding_Remote_Type (Opnd_Type))
10224 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
10225 and then Is_Entity_Name (Operand)
10226 and then Ekind (Entity (Operand)) = E_In_Parameter
10228 (Nkind (Parent (N)) /= N_Assignment_Statement
10229 or else not Is_Entity_Name (Name (Parent (N)))
10230 or else not Is_Return_Object (Entity (Name (Parent (N)))))
10233 ("illegal attempt to store anonymous access to subprogram",
10236 ("\value has deeper accessibility than any master " &
10237 "(RM 3.10.2 (13))",
10241 ("\use named access type for& instead of access parameter",
10242 Operand, Entity (Operand));
10245 -- Check that the designated types are subtype conformant
10247 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
10248 Old_Id => Designated_Type (Opnd_Type),
10251 -- Check the static accessibility rule of 4.6(20)
10253 if Type_Access_Level (Opnd_Type) >
10254 Type_Access_Level (Target_Type)
10257 ("operand type has deeper accessibility level than target",
10260 -- Check that if the operand type is declared in a generic body,
10261 -- then the target type must be declared within that same body
10262 -- (enforces last sentence of 4.6(20)).
10264 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
10266 O_Gen : constant Node_Id :=
10267 Enclosing_Generic_Body (Opnd_Type);
10272 T_Gen := Enclosing_Generic_Body (Target_Type);
10273 while Present (T_Gen) and then T_Gen /= O_Gen loop
10274 T_Gen := Enclosing_Generic_Body (T_Gen);
10277 if T_Gen /= O_Gen then
10279 ("target type must be declared in same generic body"
10280 & " as operand type", N);
10287 -- Remote subprogram access types
10289 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
10290 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
10292 -- It is valid to convert from one RAS type to another provided
10293 -- that their specification statically match.
10295 Check_Subtype_Conformant
10297 Designated_Type (Corresponding_Remote_Type (Target_Type)),
10299 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
10304 -- If both are tagged types, check legality of view conversions
10306 elsif Is_Tagged_Type (Target_Type)
10307 and then Is_Tagged_Type (Opnd_Type)
10309 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
10311 -- Types derived from the same root type are convertible
10313 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
10316 -- In an instance or an inlined body, there may be inconsistent
10317 -- views of the same type, or of types derived from a common root.
10319 elsif (In_Instance or In_Inlined_Body)
10321 Root_Type (Underlying_Type (Target_Type)) =
10322 Root_Type (Underlying_Type (Opnd_Type))
10326 -- Special check for common access type error case
10328 elsif Ekind (Target_Type) = E_Access_Type
10329 and then Is_Access_Type (Opnd_Type)
10331 Error_Msg_N ("target type must be general access type!", N);
10332 Error_Msg_NE -- CODEFIX
10333 ("add ALL to }!", N, Target_Type);
10337 Error_Msg_NE ("invalid conversion, not compatible with }",
10341 end Valid_Conversion;