* config/rs6000/rs6000.c (rs6000_option_override_internal): Do not
[official-gcc.git] / gcc / ada / sem_res.adb
blob5095088f0bcb9d07bb610a78e592ccfcb8a8c53c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ R E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
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 Errout; use Errout;
32 with Expander; use Expander;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Ch6; use Exp_Ch6;
35 with Exp_Ch7; use Exp_Ch7;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Fname; use Fname;
39 with Freeze; use Freeze;
40 with Itypes; use Itypes;
41 with Lib; use Lib;
42 with Lib.Xref; use Lib.Xref;
43 with Namet; use Namet;
44 with Nmake; use Nmake;
45 with Nlists; use Nlists;
46 with Opt; use Opt;
47 with Output; use Output;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Rtsfind; use Rtsfind;
51 with Sem; use Sem;
52 with Sem_Aux; use Sem_Aux;
53 with Sem_Aggr; use Sem_Aggr;
54 with Sem_Attr; use Sem_Attr;
55 with Sem_Cat; use Sem_Cat;
56 with Sem_Ch4; use Sem_Ch4;
57 with Sem_Ch6; use Sem_Ch6;
58 with Sem_Ch8; use Sem_Ch8;
59 with Sem_Ch13; use Sem_Ch13;
60 with Sem_Dim; use Sem_Dim;
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 Targparm; use Targparm;
69 with Sem_Type; use Sem_Type;
70 with Sem_Warn; use Sem_Warn;
71 with Sinfo; use Sinfo;
72 with Sinfo.CN; use Sinfo.CN;
73 with Snames; use Snames;
74 with Stand; use Stand;
75 with Stringt; use Stringt;
76 with Style; use Style;
77 with Tbuild; use Tbuild;
78 with Uintp; use Uintp;
79 with Urealp; use Urealp;
81 package body Sem_Res is
83 -----------------------
84 -- Local Subprograms --
85 -----------------------
87 -- Second pass (top-down) type checking and overload resolution procedures
88 -- Typ is the type required by context. These procedures propagate the type
89 -- information recursively to the descendants of N. If the node is not
90 -- overloaded, its Etype is established in the first pass. If overloaded,
91 -- the Resolve routines set the correct type. For arith. operators, the
92 -- Etype is the base type of the context.
94 -- Note that Resolve_Attribute is separated off in Sem_Attr
96 function Bad_Unordered_Enumeration_Reference
97 (N : Node_Id;
98 T : Entity_Id) return Boolean;
99 -- Node N contains a potentially dubious reference to type T, either an
100 -- explicit comparison, or an explicit range. This function returns True
101 -- if the type T is an enumeration type for which No pragma Order has been
102 -- given, and the reference N is not in the same extended source unit as
103 -- the declaration of T.
105 procedure Check_Discriminant_Use (N : Node_Id);
106 -- Enforce the restrictions on the use of discriminants when constraining
107 -- a component of a discriminated type (record or concurrent type).
109 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
110 -- Given a node for an operator associated with type T, check that
111 -- the operator is visible. Operators all of whose operands are
112 -- universal must be checked for visibility during resolution
113 -- because their type is not determinable based on their operands.
115 procedure Check_Fully_Declared_Prefix
116 (Typ : Entity_Id;
117 Pref : Node_Id);
118 -- Check that the type of the prefix of a dereference is not incomplete
120 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
121 -- Given a call node, N, which is known to occur immediately within the
122 -- subprogram being called, determines whether it is a detectable case of
123 -- an infinite recursion, and if so, outputs appropriate messages. Returns
124 -- True if an infinite recursion is detected, and False otherwise.
126 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
127 -- If the type of the object being initialized uses the secondary stack
128 -- directly or indirectly, create a transient scope for the call to the
129 -- init proc. This is because we do not create transient scopes for the
130 -- initialization of individual components within the init proc itself.
131 -- Could be optimized away perhaps?
133 procedure Check_No_Direct_Boolean_Operators (N : Node_Id);
134 -- N is the node for a logical operator. If the operator is predefined, and
135 -- the root type of the operands is Standard.Boolean, then a check is made
136 -- for restriction No_Direct_Boolean_Operators. This procedure also handles
137 -- the style check for Style_Check_Boolean_And_Or.
139 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
140 -- Determine whether E is an access type declared by an access declaration,
141 -- and not an (anonymous) allocator type.
143 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
144 -- Utility to check whether the entity for an operator is a predefined
145 -- operator, in which case the expression is left as an operator in the
146 -- tree (else it is rewritten into a call). An instance of an intrinsic
147 -- conversion operation may be given an operator name, but is not treated
148 -- like an operator. Note that an operator that is an imported back-end
149 -- builtin has convention Intrinsic, but is expected to be rewritten into
150 -- a call, so such an operator is not treated as predefined by this
151 -- predicate.
153 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
154 -- If a default expression in entry call N depends on the discriminants
155 -- of the task, it must be replaced with a reference to the discriminant
156 -- of the task being called.
158 procedure Resolve_Op_Concat_Arg
159 (N : Node_Id;
160 Arg : Node_Id;
161 Typ : Entity_Id;
162 Is_Comp : Boolean);
163 -- Internal procedure for Resolve_Op_Concat to resolve one operand of
164 -- concatenation operator. The operand is either of the array type or of
165 -- the component type. If the operand is an aggregate, and the component
166 -- type is composite, this is ambiguous if component type has aggregates.
168 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id);
169 -- Does the first part of the work of Resolve_Op_Concat
171 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id);
172 -- Does the "rest" of the work of Resolve_Op_Concat, after the left operand
173 -- has been resolved. See Resolve_Op_Concat for details.
175 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
176 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
177 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
178 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id);
179 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
180 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
181 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
182 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
183 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
184 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id);
185 procedure Resolve_If_Expression (N : Node_Id; Typ : Entity_Id);
186 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
187 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
188 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
189 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
190 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
191 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
192 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
193 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
194 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
195 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
196 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
197 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
198 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
199 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
200 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
201 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
202 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
203 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
204 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
205 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
206 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
207 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
208 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
210 function Operator_Kind
211 (Op_Name : Name_Id;
212 Is_Binary : Boolean) return Node_Kind;
213 -- Utility to map the name of an operator into the corresponding Node. Used
214 -- by other node rewriting procedures.
216 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
217 -- Resolve actuals of call, and add default expressions for missing ones.
218 -- N is the Node_Id for the subprogram call, and Nam is the entity of the
219 -- called subprogram.
221 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
222 -- Called from Resolve_Call, when the prefix denotes an entry or element
223 -- of entry family. Actuals are resolved as for subprograms, and the node
224 -- is rebuilt as an entry call. Also called for protected operations. Typ
225 -- is the context type, which is used when the operation is a protected
226 -- function with no arguments, and the return value is indexed.
228 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
229 -- A call to a user-defined intrinsic operator is rewritten as a call to
230 -- the corresponding predefined operator, with suitable conversions. Note
231 -- that this applies only for intrinsic operators that denote predefined
232 -- operators, not ones that are intrinsic imports of back-end builtins.
234 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
235 -- Ditto, for unary operators (arithmetic ones and "not" on signed
236 -- integer types for VMS).
238 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
239 -- If an operator node resolves to a call to a user-defined operator,
240 -- rewrite the node as a function call.
242 procedure Make_Call_Into_Operator
243 (N : Node_Id;
244 Typ : Entity_Id;
245 Op_Id : Entity_Id);
246 -- Inverse transformation: if an operator is given in functional notation,
247 -- then after resolving the node, transform into an operator node, so
248 -- that operands are resolved properly. Recall that predefined operators
249 -- do not have a full signature and special resolution rules apply.
251 procedure Rewrite_Renamed_Operator
252 (N : Node_Id;
253 Op : Entity_Id;
254 Typ : Entity_Id);
255 -- An operator can rename another, e.g. in an instantiation. In that
256 -- case, the proper operator node must be constructed and resolved.
258 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
259 -- The String_Literal_Subtype is built for all strings that are not
260 -- operands of a static concatenation operation. If the argument is
261 -- not a N_String_Literal node, then the call has no effect.
263 procedure Set_Slice_Subtype (N : Node_Id);
264 -- Build subtype of array type, with the range specified by the slice
266 procedure Simplify_Type_Conversion (N : Node_Id);
267 -- Called after N has been resolved and evaluated, but before range checks
268 -- have been applied. Currently simplifies a combination of floating-point
269 -- to integer conversion and Truncation attribute.
271 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
272 -- A universal_fixed expression in an universal context is unambiguous if
273 -- there is only one applicable fixed point type. Determining whether there
274 -- is only one requires a search over all visible entities, and happens
275 -- only in very pathological cases (see 6115-006).
277 -------------------------
278 -- Ambiguous_Character --
279 -------------------------
281 procedure Ambiguous_Character (C : Node_Id) is
282 E : Entity_Id;
284 begin
285 if Nkind (C) = N_Character_Literal then
286 Error_Msg_N ("ambiguous character literal", C);
288 -- First the ones in Standard
290 Error_Msg_N ("\\possible interpretation: Character!", C);
291 Error_Msg_N ("\\possible interpretation: Wide_Character!", C);
293 -- Include Wide_Wide_Character in Ada 2005 mode
295 if Ada_Version >= Ada_2005 then
296 Error_Msg_N ("\\possible interpretation: Wide_Wide_Character!", C);
297 end if;
299 -- Now any other types that match
301 E := Current_Entity (C);
302 while Present (E) loop
303 Error_Msg_NE ("\\possible interpretation:}!", C, Etype (E));
304 E := Homonym (E);
305 end loop;
306 end if;
307 end Ambiguous_Character;
309 -------------------------
310 -- Analyze_And_Resolve --
311 -------------------------
313 procedure Analyze_And_Resolve (N : Node_Id) is
314 begin
315 Analyze (N);
316 Resolve (N);
317 end Analyze_And_Resolve;
319 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
320 begin
321 Analyze (N);
322 Resolve (N, Typ);
323 end Analyze_And_Resolve;
325 -- Versions with check(s) suppressed
327 procedure Analyze_And_Resolve
328 (N : Node_Id;
329 Typ : Entity_Id;
330 Suppress : Check_Id)
332 Scop : constant Entity_Id := Current_Scope;
334 begin
335 if Suppress = All_Checks then
336 declare
337 Svg : constant Suppress_Record := Scope_Suppress;
338 begin
339 Scope_Suppress := Suppress_All;
340 Analyze_And_Resolve (N, Typ);
341 Scope_Suppress := Svg;
342 end;
344 elsif Suppress = Overflow_Check then
345 declare
346 Svg : constant Overflow_Check_Type :=
347 Scope_Suppress.Overflow_Checks_General;
348 Sva : constant Overflow_Check_Type :=
349 Scope_Suppress.Overflow_Checks_Assertions;
350 begin
351 Scope_Suppress.Overflow_Checks_General := Suppressed;
352 Scope_Suppress.Overflow_Checks_Assertions := Suppressed;
353 Analyze_And_Resolve (N, Typ);
354 Scope_Suppress.Overflow_Checks_General := Svg;
355 Scope_Suppress.Overflow_Checks_Assertions := Sva;
356 end;
358 else
359 declare
360 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
361 begin
362 Scope_Suppress.Suppress (Suppress) := True;
363 Analyze_And_Resolve (N, Typ);
364 Scope_Suppress.Suppress (Suppress) := Svg;
365 end;
366 end if;
368 if Current_Scope /= Scop
369 and then Scope_Is_Transient
370 then
371 -- This can only happen if a transient scope was created for an inner
372 -- expression, which will be removed upon completion of the analysis
373 -- of an enclosing construct. The transient scope must have the
374 -- suppress status of the enclosing environment, not of this Analyze
375 -- call.
377 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
378 Scope_Suppress;
379 end if;
380 end Analyze_And_Resolve;
382 procedure Analyze_And_Resolve
383 (N : Node_Id;
384 Suppress : Check_Id)
386 Scop : constant Entity_Id := Current_Scope;
388 begin
389 if Suppress = All_Checks then
390 declare
391 Svg : constant Suppress_Record := Scope_Suppress;
392 begin
393 Scope_Suppress := Suppress_All;
394 Analyze_And_Resolve (N);
395 Scope_Suppress := Svg;
396 end;
398 elsif Suppress = Overflow_Check then
399 declare
400 Svg : constant Overflow_Check_Type :=
401 Scope_Suppress.Overflow_Checks_General;
402 Sva : constant Overflow_Check_Type :=
403 Scope_Suppress.Overflow_Checks_Assertions;
404 begin
405 Scope_Suppress.Overflow_Checks_General := Suppressed;
406 Scope_Suppress.Overflow_Checks_Assertions := Suppressed;
407 Analyze_And_Resolve (N);
408 Scope_Suppress.Overflow_Checks_General := Svg;
409 Scope_Suppress.Overflow_Checks_Assertions := Sva;
410 end;
412 else
413 declare
414 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
415 begin
416 Scope_Suppress.Suppress (Suppress) := True;
417 Analyze_And_Resolve (N);
418 Scope_Suppress.Suppress (Suppress) := Svg;
419 end;
420 end if;
422 if Current_Scope /= Scop and then Scope_Is_Transient then
423 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
424 Scope_Suppress;
425 end if;
426 end Analyze_And_Resolve;
428 ----------------------------------------
429 -- Bad_Unordered_Enumeration_Reference --
430 ----------------------------------------
432 function Bad_Unordered_Enumeration_Reference
433 (N : Node_Id;
434 T : Entity_Id) return Boolean
436 begin
437 return Is_Enumeration_Type (T)
438 and then Comes_From_Source (N)
439 and then Warn_On_Unordered_Enumeration_Type
440 and then not Has_Pragma_Ordered (T)
441 and then not In_Same_Extended_Unit (N, T);
442 end Bad_Unordered_Enumeration_Reference;
444 ----------------------------
445 -- Check_Discriminant_Use --
446 ----------------------------
448 procedure Check_Discriminant_Use (N : Node_Id) is
449 PN : constant Node_Id := Parent (N);
450 Disc : constant Entity_Id := Entity (N);
451 P : Node_Id;
452 D : Node_Id;
454 begin
455 -- Any use in a spec-expression is legal
457 if In_Spec_Expression then
458 null;
460 elsif Nkind (PN) = N_Range then
462 -- Discriminant cannot be used to constrain a scalar type
464 P := Parent (PN);
466 if Nkind (P) = N_Range_Constraint
467 and then Nkind (Parent (P)) = N_Subtype_Indication
468 and then Nkind (Parent (Parent (P))) = N_Component_Definition
469 then
470 Error_Msg_N ("discriminant cannot constrain scalar type", N);
472 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
474 -- The following check catches the unusual case where a
475 -- discriminant appears within an index constraint that is part of
476 -- a larger expression within a constraint on a component, e.g. "C
477 -- : Int range 1 .. F (new A(1 .. D))". For now we only check case
478 -- of record components, and note that a similar check should also
479 -- apply in the case of discriminant constraints below. ???
481 -- Note that the check for N_Subtype_Declaration below is to
482 -- detect the valid use of discriminants in the constraints of a
483 -- subtype declaration when this subtype declaration appears
484 -- inside the scope of a record type (which is syntactically
485 -- illegal, but which may be created as part of derived type
486 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
487 -- for more info.
489 if Ekind (Current_Scope) = E_Record_Type
490 and then Scope (Disc) = Current_Scope
491 and then not
492 (Nkind (Parent (P)) = N_Subtype_Indication
493 and then
494 Nkind_In (Parent (Parent (P)), N_Component_Definition,
495 N_Subtype_Declaration)
496 and then Paren_Count (N) = 0)
497 then
498 Error_Msg_N
499 ("discriminant must appear alone in component constraint", N);
500 return;
501 end if;
503 -- Detect a common error:
505 -- type R (D : Positive := 100) is record
506 -- Name : String (1 .. D);
507 -- end record;
509 -- The default value causes an object of type R to be allocated
510 -- with room for Positive'Last characters. The RM does not mandate
511 -- the allocation of the maximum size, but that is what GNAT does
512 -- so we should warn the programmer that there is a problem.
514 Check_Large : declare
515 SI : Node_Id;
516 T : Entity_Id;
517 TB : Node_Id;
518 CB : Entity_Id;
520 function Large_Storage_Type (T : Entity_Id) return Boolean;
521 -- Return True if type T has a large enough range that any
522 -- array whose index type covered the whole range of the type
523 -- would likely raise Storage_Error.
525 ------------------------
526 -- Large_Storage_Type --
527 ------------------------
529 function Large_Storage_Type (T : Entity_Id) return Boolean is
530 begin
531 -- The type is considered large if its bounds are known at
532 -- compile time and if it requires at least as many bits as
533 -- a Positive to store the possible values.
535 return Compile_Time_Known_Value (Type_Low_Bound (T))
536 and then Compile_Time_Known_Value (Type_High_Bound (T))
537 and then
538 Minimum_Size (T, Biased => True) >=
539 RM_Size (Standard_Positive);
540 end Large_Storage_Type;
542 -- Start of processing for Check_Large
544 begin
545 -- Check that the Disc has a large range
547 if not Large_Storage_Type (Etype (Disc)) then
548 goto No_Danger;
549 end if;
551 -- If the enclosing type is limited, we allocate only the
552 -- default value, not the maximum, and there is no need for
553 -- a warning.
555 if Is_Limited_Type (Scope (Disc)) then
556 goto No_Danger;
557 end if;
559 -- Check that it is the high bound
561 if N /= High_Bound (PN)
562 or else No (Discriminant_Default_Value (Disc))
563 then
564 goto No_Danger;
565 end if;
567 -- Check the array allows a large range at this bound. First
568 -- find the array
570 SI := Parent (P);
572 if Nkind (SI) /= N_Subtype_Indication then
573 goto No_Danger;
574 end if;
576 T := Entity (Subtype_Mark (SI));
578 if not Is_Array_Type (T) then
579 goto No_Danger;
580 end if;
582 -- Next, find the dimension
584 TB := First_Index (T);
585 CB := First (Constraints (P));
586 while True
587 and then Present (TB)
588 and then Present (CB)
589 and then CB /= PN
590 loop
591 Next_Index (TB);
592 Next (CB);
593 end loop;
595 if CB /= PN then
596 goto No_Danger;
597 end if;
599 -- Now, check the dimension has a large range
601 if not Large_Storage_Type (Etype (TB)) then
602 goto No_Danger;
603 end if;
605 -- Warn about the danger
607 Error_Msg_N
608 ("?creation of & object may raise Storage_Error!",
609 Scope (Disc));
611 <<No_Danger>>
612 null;
614 end Check_Large;
615 end if;
617 -- Legal case is in index or discriminant constraint
619 elsif Nkind_In (PN, N_Index_Or_Discriminant_Constraint,
620 N_Discriminant_Association)
621 then
622 if Paren_Count (N) > 0 then
623 Error_Msg_N
624 ("discriminant in constraint must appear alone", N);
626 elsif Nkind (N) = N_Expanded_Name
627 and then Comes_From_Source (N)
628 then
629 Error_Msg_N
630 ("discriminant must appear alone as a direct name", N);
631 end if;
633 return;
635 -- Otherwise, context is an expression. It should not be within (i.e. a
636 -- subexpression of) a constraint for a component.
638 else
639 D := PN;
640 P := Parent (PN);
641 while not Nkind_In (P, N_Component_Declaration,
642 N_Subtype_Indication,
643 N_Entry_Declaration)
644 loop
645 D := P;
646 P := Parent (P);
647 exit when No (P);
648 end loop;
650 -- If the discriminant is used in an expression that is a bound of a
651 -- scalar type, an Itype is created and the bounds are attached to
652 -- its range, not to the original subtype indication. Such use is of
653 -- course a double fault.
655 if (Nkind (P) = N_Subtype_Indication
656 and then Nkind_In (Parent (P), N_Component_Definition,
657 N_Derived_Type_Definition)
658 and then D = Constraint (P))
660 -- The constraint itself may be given by a subtype indication,
661 -- rather than by a more common discrete range.
663 or else (Nkind (P) = N_Subtype_Indication
664 and then
665 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
666 or else Nkind (P) = N_Entry_Declaration
667 or else Nkind (D) = N_Defining_Identifier
668 then
669 Error_Msg_N
670 ("discriminant in constraint must appear alone", N);
671 end if;
672 end if;
673 end Check_Discriminant_Use;
675 --------------------------------
676 -- Check_For_Visible_Operator --
677 --------------------------------
679 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
680 begin
681 if Is_Invisible_Operator (N, T) then
682 Error_Msg_NE -- CODEFIX
683 ("operator for} is not directly visible!", N, First_Subtype (T));
684 Error_Msg_N -- CODEFIX
685 ("use clause would make operation legal!", N);
686 end if;
687 end Check_For_Visible_Operator;
689 ----------------------------------
690 -- Check_Fully_Declared_Prefix --
691 ----------------------------------
693 procedure Check_Fully_Declared_Prefix
694 (Typ : Entity_Id;
695 Pref : Node_Id)
697 begin
698 -- Check that the designated type of the prefix of a dereference is
699 -- not an incomplete type. This cannot be done unconditionally, because
700 -- dereferences of private types are legal in default expressions. This
701 -- case is taken care of in Check_Fully_Declared, called below. There
702 -- are also 2005 cases where it is legal for the prefix to be unfrozen.
704 -- This consideration also applies to similar checks for allocators,
705 -- qualified expressions, and type conversions.
707 -- An additional exception concerns other per-object expressions that
708 -- are not directly related to component declarations, in particular
709 -- representation pragmas for tasks. These will be per-object
710 -- expressions if they depend on discriminants or some global entity.
711 -- If the task has access discriminants, the designated type may be
712 -- incomplete at the point the expression is resolved. This resolution
713 -- takes place within the body of the initialization procedure, where
714 -- the discriminant is replaced by its discriminal.
716 if Is_Entity_Name (Pref)
717 and then Ekind (Entity (Pref)) = E_In_Parameter
718 then
719 null;
721 -- Ada 2005 (AI-326): Tagged incomplete types allowed. The wrong usages
722 -- are handled by Analyze_Access_Attribute, Analyze_Assignment,
723 -- Analyze_Object_Renaming, and Freeze_Entity.
725 elsif Ada_Version >= Ada_2005
726 and then Is_Entity_Name (Pref)
727 and then Is_Access_Type (Etype (Pref))
728 and then Ekind (Directly_Designated_Type (Etype (Pref))) =
729 E_Incomplete_Type
730 and then Is_Tagged_Type (Directly_Designated_Type (Etype (Pref)))
731 then
732 null;
733 else
734 Check_Fully_Declared (Typ, Parent (Pref));
735 end if;
736 end Check_Fully_Declared_Prefix;
738 ------------------------------
739 -- Check_Infinite_Recursion --
740 ------------------------------
742 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
743 P : Node_Id;
744 C : Node_Id;
746 function Same_Argument_List return Boolean;
747 -- Check whether list of actuals is identical to list of formals of
748 -- called function (which is also the enclosing scope).
750 ------------------------
751 -- Same_Argument_List --
752 ------------------------
754 function Same_Argument_List return Boolean is
755 A : Node_Id;
756 F : Entity_Id;
757 Subp : Entity_Id;
759 begin
760 if not Is_Entity_Name (Name (N)) then
761 return False;
762 else
763 Subp := Entity (Name (N));
764 end if;
766 F := First_Formal (Subp);
767 A := First_Actual (N);
768 while Present (F) and then Present (A) loop
769 if not Is_Entity_Name (A)
770 or else Entity (A) /= F
771 then
772 return False;
773 end if;
775 Next_Actual (A);
776 Next_Formal (F);
777 end loop;
779 return True;
780 end Same_Argument_List;
782 -- Start of processing for Check_Infinite_Recursion
784 begin
785 -- Special case, if this is a procedure call and is a call to the
786 -- current procedure with the same argument list, then this is for
787 -- sure an infinite recursion and we insert a call to raise SE.
789 if Is_List_Member (N)
790 and then List_Length (List_Containing (N)) = 1
791 and then Same_Argument_List
792 then
793 declare
794 P : constant Node_Id := Parent (N);
795 begin
796 if Nkind (P) = N_Handled_Sequence_Of_Statements
797 and then Nkind (Parent (P)) = N_Subprogram_Body
798 and then Is_Empty_List (Declarations (Parent (P)))
799 then
800 Error_Msg_N ("!?infinite recursion", N);
801 Error_Msg_N ("\!?Storage_Error will be raised at run time", N);
802 Insert_Action (N,
803 Make_Raise_Storage_Error (Sloc (N),
804 Reason => SE_Infinite_Recursion));
805 return True;
806 end if;
807 end;
808 end if;
810 -- If not that special case, search up tree, quitting if we reach a
811 -- construct (e.g. a conditional) that tells us that this is not a
812 -- case for an infinite recursion warning.
814 C := N;
815 loop
816 P := Parent (C);
818 -- If no parent, then we were not inside a subprogram, this can for
819 -- example happen when processing certain pragmas in a spec. Just
820 -- return False in this case.
822 if No (P) then
823 return False;
824 end if;
826 -- Done if we get to subprogram body, this is definitely an infinite
827 -- recursion case if we did not find anything to stop us.
829 exit when Nkind (P) = N_Subprogram_Body;
831 -- If appearing in conditional, result is false
833 if Nkind_In (P, N_Or_Else,
834 N_And_Then,
835 N_Case_Expression,
836 N_Case_Statement,
837 N_If_Expression,
838 N_If_Statement)
839 then
840 return False;
842 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
843 and then C /= First (Statements (P))
844 then
845 -- If the call is the expression of a return statement and the
846 -- actuals are identical to the formals, it's worth a warning.
847 -- However, we skip this if there is an immediately preceding
848 -- raise statement, since the call is never executed.
850 -- Furthermore, this corresponds to a common idiom:
852 -- function F (L : Thing) return Boolean is
853 -- begin
854 -- raise Program_Error;
855 -- return F (L);
856 -- end F;
858 -- for generating a stub function
860 if Nkind (Parent (N)) = N_Simple_Return_Statement
861 and then Same_Argument_List
862 then
863 exit when not Is_List_Member (Parent (N));
865 -- OK, return statement is in a statement list, look for raise
867 declare
868 Nod : Node_Id;
870 begin
871 -- Skip past N_Freeze_Entity nodes generated by expansion
873 Nod := Prev (Parent (N));
874 while Present (Nod)
875 and then Nkind (Nod) = N_Freeze_Entity
876 loop
877 Prev (Nod);
878 end loop;
880 -- If no raise statement, give warning. We look at the
881 -- original node, because in the case of "raise ... with
882 -- ...", the node has been transformed into a call.
884 exit when Nkind (Original_Node (Nod)) /= N_Raise_Statement
885 and then
886 (Nkind (Nod) not in N_Raise_xxx_Error
887 or else Present (Condition (Nod)));
888 end;
889 end if;
891 return False;
893 else
894 C := P;
895 end if;
896 end loop;
898 Error_Msg_N ("!?possible infinite recursion", N);
899 Error_Msg_N ("\!?Storage_Error may be raised at run time", N);
901 return True;
902 end Check_Infinite_Recursion;
904 -------------------------------
905 -- Check_Initialization_Call --
906 -------------------------------
908 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
909 Typ : constant Entity_Id := Etype (First_Formal (Nam));
911 function Uses_SS (T : Entity_Id) return Boolean;
912 -- Check whether the creation of an object of the type will involve
913 -- use of the secondary stack. If T is a record type, this is true
914 -- if the expression for some component uses the secondary stack, e.g.
915 -- through a call to a function that returns an unconstrained value.
916 -- False if T is controlled, because cleanups occur elsewhere.
918 -------------
919 -- Uses_SS --
920 -------------
922 function Uses_SS (T : Entity_Id) return Boolean is
923 Comp : Entity_Id;
924 Expr : Node_Id;
925 Full_Type : Entity_Id := Underlying_Type (T);
927 begin
928 -- Normally we want to use the underlying type, but if it's not set
929 -- then continue with T.
931 if not Present (Full_Type) then
932 Full_Type := T;
933 end if;
935 if Is_Controlled (Full_Type) then
936 return False;
938 elsif Is_Array_Type (Full_Type) then
939 return Uses_SS (Component_Type (Full_Type));
941 elsif Is_Record_Type (Full_Type) then
942 Comp := First_Component (Full_Type);
943 while Present (Comp) loop
944 if Ekind (Comp) = E_Component
945 and then Nkind (Parent (Comp)) = N_Component_Declaration
946 then
947 -- The expression for a dynamic component may be rewritten
948 -- as a dereference, so retrieve original node.
950 Expr := Original_Node (Expression (Parent (Comp)));
952 -- Return True if the expression is a call to a function
953 -- (including an attribute function such as Image, or a
954 -- user-defined operator) with a result that requires a
955 -- transient scope.
957 if (Nkind (Expr) = N_Function_Call
958 or else Nkind (Expr) in N_Op
959 or else (Nkind (Expr) = N_Attribute_Reference
960 and then Present (Expressions (Expr))))
961 and then Requires_Transient_Scope (Etype (Expr))
962 then
963 return True;
965 elsif Uses_SS (Etype (Comp)) then
966 return True;
967 end if;
968 end if;
970 Next_Component (Comp);
971 end loop;
973 return False;
975 else
976 return False;
977 end if;
978 end Uses_SS;
980 -- Start of processing for Check_Initialization_Call
982 begin
983 -- Establish a transient scope if the type needs it
985 if Uses_SS (Typ) then
986 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
987 end if;
988 end Check_Initialization_Call;
990 ---------------------------------------
991 -- Check_No_Direct_Boolean_Operators --
992 ---------------------------------------
994 procedure Check_No_Direct_Boolean_Operators (N : Node_Id) is
995 begin
996 if Scope (Entity (N)) = Standard_Standard
997 and then Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean
998 then
999 -- Restriction only applies to original source code
1001 if Comes_From_Source (N) then
1002 Check_Restriction (No_Direct_Boolean_Operators, N);
1003 end if;
1004 end if;
1006 if Style_Check then
1007 Check_Boolean_Operator (N);
1008 end if;
1009 end Check_No_Direct_Boolean_Operators;
1011 ------------------------------
1012 -- Check_Parameterless_Call --
1013 ------------------------------
1015 procedure Check_Parameterless_Call (N : Node_Id) is
1016 Nam : Node_Id;
1018 function Prefix_Is_Access_Subp return Boolean;
1019 -- If the prefix is of an access_to_subprogram type, the node must be
1020 -- rewritten as a call. Ditto if the prefix is overloaded and all its
1021 -- interpretations are access to subprograms.
1023 ---------------------------
1024 -- Prefix_Is_Access_Subp --
1025 ---------------------------
1027 function Prefix_Is_Access_Subp return Boolean is
1028 I : Interp_Index;
1029 It : Interp;
1031 begin
1032 -- If the context is an attribute reference that can apply to
1033 -- functions, this is never a parameterless call (RM 4.1.4(6)).
1035 if Nkind (Parent (N)) = N_Attribute_Reference
1036 and then (Attribute_Name (Parent (N)) = Name_Address or else
1037 Attribute_Name (Parent (N)) = Name_Code_Address or else
1038 Attribute_Name (Parent (N)) = Name_Access)
1039 then
1040 return False;
1041 end if;
1043 if not Is_Overloaded (N) then
1044 return
1045 Ekind (Etype (N)) = E_Subprogram_Type
1046 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type;
1047 else
1048 Get_First_Interp (N, I, It);
1049 while Present (It.Typ) loop
1050 if Ekind (It.Typ) /= E_Subprogram_Type
1051 or else Base_Type (Etype (It.Typ)) = Standard_Void_Type
1052 then
1053 return False;
1054 end if;
1056 Get_Next_Interp (I, It);
1057 end loop;
1059 return True;
1060 end if;
1061 end Prefix_Is_Access_Subp;
1063 -- Start of processing for Check_Parameterless_Call
1065 begin
1066 -- Defend against junk stuff if errors already detected
1068 if Total_Errors_Detected /= 0 then
1069 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
1070 return;
1071 elsif Nkind (N) in N_Has_Chars
1072 and then Chars (N) in Error_Name_Or_No_Name
1073 then
1074 return;
1075 end if;
1077 Require_Entity (N);
1078 end if;
1080 -- If the context expects a value, and the name is a procedure, this is
1081 -- most likely a missing 'Access. Don't try to resolve the parameterless
1082 -- call, error will be caught when the outer call is analyzed.
1084 if Is_Entity_Name (N)
1085 and then Ekind (Entity (N)) = E_Procedure
1086 and then not Is_Overloaded (N)
1087 and then
1088 Nkind_In (Parent (N), N_Parameter_Association,
1089 N_Function_Call,
1090 N_Procedure_Call_Statement)
1091 then
1092 return;
1093 end if;
1095 -- Rewrite as call if overloadable entity that is (or could be, in the
1096 -- overloaded case) a function call. If we know for sure that the entity
1097 -- is an enumeration literal, we do not rewrite it.
1099 -- If the entity is the name of an operator, it cannot be a call because
1100 -- operators cannot have default parameters. In this case, this must be
1101 -- a string whose contents coincide with an operator name. Set the kind
1102 -- of the node appropriately.
1104 if (Is_Entity_Name (N)
1105 and then Nkind (N) /= N_Operator_Symbol
1106 and then Is_Overloadable (Entity (N))
1107 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
1108 or else Is_Overloaded (N)))
1110 -- Rewrite as call if it is an explicit dereference of an expression of
1111 -- a subprogram access type, and the subprogram type is not that of a
1112 -- procedure or entry.
1114 or else
1115 (Nkind (N) = N_Explicit_Dereference and then Prefix_Is_Access_Subp)
1117 -- Rewrite as call if it is a selected component which is a function,
1118 -- this is the case of a call to a protected function (which may be
1119 -- overloaded with other protected operations).
1121 or else
1122 (Nkind (N) = N_Selected_Component
1123 and then (Ekind (Entity (Selector_Name (N))) = E_Function
1124 or else
1125 (Ekind_In (Entity (Selector_Name (N)), E_Entry,
1126 E_Procedure)
1127 and then Is_Overloaded (Selector_Name (N)))))
1129 -- If one of the above three conditions is met, rewrite as call. Apply
1130 -- the rewriting only once.
1132 then
1133 if Nkind (Parent (N)) /= N_Function_Call
1134 or else N /= Name (Parent (N))
1135 then
1137 -- This may be a prefixed call that was not fully analyzed, e.g.
1138 -- an actual in an instance.
1140 if Ada_Version >= Ada_2005
1141 and then Nkind (N) = N_Selected_Component
1142 and then Is_Dispatching_Operation (Entity (Selector_Name (N)))
1143 then
1144 Analyze_Selected_Component (N);
1146 if Nkind (N) /= N_Selected_Component then
1147 return;
1148 end if;
1149 end if;
1151 Nam := New_Copy (N);
1153 -- If overloaded, overload set belongs to new copy
1155 Save_Interps (N, Nam);
1157 -- Change node to parameterless function call (note that the
1158 -- Parameter_Associations associations field is left set to Empty,
1159 -- its normal default value since there are no parameters)
1161 Change_Node (N, N_Function_Call);
1162 Set_Name (N, Nam);
1163 Set_Sloc (N, Sloc (Nam));
1164 Analyze_Call (N);
1165 end if;
1167 elsif Nkind (N) = N_Parameter_Association then
1168 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
1170 elsif Nkind (N) = N_Operator_Symbol then
1171 Change_Operator_Symbol_To_String_Literal (N);
1172 Set_Is_Overloaded (N, False);
1173 Set_Etype (N, Any_String);
1174 end if;
1175 end Check_Parameterless_Call;
1177 -----------------------------
1178 -- Is_Definite_Access_Type --
1179 -----------------------------
1181 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
1182 Btyp : constant Entity_Id := Base_Type (E);
1183 begin
1184 return Ekind (Btyp) = E_Access_Type
1185 or else (Ekind (Btyp) = E_Access_Subprogram_Type
1186 and then Comes_From_Source (Btyp));
1187 end Is_Definite_Access_Type;
1189 ----------------------
1190 -- Is_Predefined_Op --
1191 ----------------------
1193 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
1194 begin
1195 -- Predefined operators are intrinsic subprograms
1197 if not Is_Intrinsic_Subprogram (Nam) then
1198 return False;
1199 end if;
1201 -- A call to a back-end builtin is never a predefined operator
1203 if Is_Imported (Nam) and then Present (Interface_Name (Nam)) then
1204 return False;
1205 end if;
1207 return not Is_Generic_Instance (Nam)
1208 and then Chars (Nam) in Any_Operator_Name
1209 and then (No (Alias (Nam)) or else Is_Predefined_Op (Alias (Nam)));
1210 end Is_Predefined_Op;
1212 -----------------------------
1213 -- Make_Call_Into_Operator --
1214 -----------------------------
1216 procedure Make_Call_Into_Operator
1217 (N : Node_Id;
1218 Typ : Entity_Id;
1219 Op_Id : Entity_Id)
1221 Op_Name : constant Name_Id := Chars (Op_Id);
1222 Act1 : Node_Id := First_Actual (N);
1223 Act2 : Node_Id := Next_Actual (Act1);
1224 Error : Boolean := False;
1225 Func : constant Entity_Id := Entity (Name (N));
1226 Is_Binary : constant Boolean := Present (Act2);
1227 Op_Node : Node_Id;
1228 Opnd_Type : Entity_Id;
1229 Orig_Type : Entity_Id := Empty;
1230 Pack : Entity_Id;
1232 type Kind_Test is access function (E : Entity_Id) return Boolean;
1234 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
1235 -- If the operand is not universal, and the operator is given by an
1236 -- expanded name, verify that the operand has an interpretation with a
1237 -- type defined in the given scope of the operator.
1239 function Type_In_P (Test : Kind_Test) return Entity_Id;
1240 -- Find a type of the given class in package Pack that contains the
1241 -- operator.
1243 ---------------------------
1244 -- Operand_Type_In_Scope --
1245 ---------------------------
1247 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
1248 Nod : constant Node_Id := Right_Opnd (Op_Node);
1249 I : Interp_Index;
1250 It : Interp;
1252 begin
1253 if not Is_Overloaded (Nod) then
1254 return Scope (Base_Type (Etype (Nod))) = S;
1256 else
1257 Get_First_Interp (Nod, I, It);
1258 while Present (It.Typ) loop
1259 if Scope (Base_Type (It.Typ)) = S then
1260 return True;
1261 end if;
1263 Get_Next_Interp (I, It);
1264 end loop;
1266 return False;
1267 end if;
1268 end Operand_Type_In_Scope;
1270 ---------------
1271 -- Type_In_P --
1272 ---------------
1274 function Type_In_P (Test : Kind_Test) return Entity_Id is
1275 E : Entity_Id;
1277 function In_Decl return Boolean;
1278 -- Verify that node is not part of the type declaration for the
1279 -- candidate type, which would otherwise be invisible.
1281 -------------
1282 -- In_Decl --
1283 -------------
1285 function In_Decl return Boolean is
1286 Decl_Node : constant Node_Id := Parent (E);
1287 N2 : Node_Id;
1289 begin
1290 N2 := N;
1292 if Etype (E) = Any_Type then
1293 return True;
1295 elsif No (Decl_Node) then
1296 return False;
1298 else
1299 while Present (N2)
1300 and then Nkind (N2) /= N_Compilation_Unit
1301 loop
1302 if N2 = Decl_Node then
1303 return True;
1304 else
1305 N2 := Parent (N2);
1306 end if;
1307 end loop;
1309 return False;
1310 end if;
1311 end In_Decl;
1313 -- Start of processing for Type_In_P
1315 begin
1316 -- If the context type is declared in the prefix package, this is the
1317 -- desired base type.
1319 if Scope (Base_Type (Typ)) = Pack and then Test (Typ) then
1320 return Base_Type (Typ);
1322 else
1323 E := First_Entity (Pack);
1324 while Present (E) loop
1325 if Test (E)
1326 and then not In_Decl
1327 then
1328 return E;
1329 end if;
1331 Next_Entity (E);
1332 end loop;
1334 return Empty;
1335 end if;
1336 end Type_In_P;
1338 -- Start of processing for Make_Call_Into_Operator
1340 begin
1341 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1343 -- Binary operator
1345 if Is_Binary then
1346 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1347 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1348 Save_Interps (Act1, Left_Opnd (Op_Node));
1349 Save_Interps (Act2, Right_Opnd (Op_Node));
1350 Act1 := Left_Opnd (Op_Node);
1351 Act2 := Right_Opnd (Op_Node);
1353 -- Unary operator
1355 else
1356 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1357 Save_Interps (Act1, Right_Opnd (Op_Node));
1358 Act1 := Right_Opnd (Op_Node);
1359 end if;
1361 -- If the operator is denoted by an expanded name, and the prefix is
1362 -- not Standard, but the operator is a predefined one whose scope is
1363 -- Standard, then this is an implicit_operator, inserted as an
1364 -- interpretation by the procedure of the same name. This procedure
1365 -- overestimates the presence of implicit operators, because it does
1366 -- not examine the type of the operands. Verify now that the operand
1367 -- type appears in the given scope. If right operand is universal,
1368 -- check the other operand. In the case of concatenation, either
1369 -- argument can be the component type, so check the type of the result.
1370 -- If both arguments are literals, look for a type of the right kind
1371 -- defined in the given scope. This elaborate nonsense is brought to
1372 -- you courtesy of b33302a. The type itself must be frozen, so we must
1373 -- find the type of the proper class in the given scope.
1375 -- A final wrinkle is the multiplication operator for fixed point types,
1376 -- which is defined in Standard only, and not in the scope of the
1377 -- fixed point type itself.
1379 if Nkind (Name (N)) = N_Expanded_Name then
1380 Pack := Entity (Prefix (Name (N)));
1382 -- If the entity being called is defined in the given package, it is
1383 -- a renaming of a predefined operator, and known to be legal.
1385 if Scope (Entity (Name (N))) = Pack
1386 and then Pack /= Standard_Standard
1387 then
1388 null;
1390 -- Visibility does not need to be checked in an instance: if the
1391 -- operator was not visible in the generic it has been diagnosed
1392 -- already, else there is an implicit copy of it in the instance.
1394 elsif In_Instance then
1395 null;
1397 elsif (Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide)
1398 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1399 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1400 then
1401 if Pack /= Standard_Standard then
1402 Error := True;
1403 end if;
1405 -- Ada 2005 AI-420: Predefined equality on Universal_Access is
1406 -- available.
1408 elsif Ada_Version >= Ada_2005
1409 and then (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1410 and then Ekind (Etype (Act1)) = E_Anonymous_Access_Type
1411 then
1412 null;
1414 else
1415 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1417 if Op_Name = Name_Op_Concat then
1418 Opnd_Type := Base_Type (Typ);
1420 elsif (Scope (Opnd_Type) = Standard_Standard
1421 and then Is_Binary)
1422 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1423 and then Is_Binary
1424 and then not Comes_From_Source (Opnd_Type))
1425 then
1426 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1427 end if;
1429 if Scope (Opnd_Type) = Standard_Standard then
1431 -- Verify that the scope contains a type that corresponds to
1432 -- the given literal. Optimize the case where Pack is Standard.
1434 if Pack /= Standard_Standard then
1436 if Opnd_Type = Universal_Integer then
1437 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1439 elsif Opnd_Type = Universal_Real then
1440 Orig_Type := Type_In_P (Is_Real_Type'Access);
1442 elsif Opnd_Type = Any_String then
1443 Orig_Type := Type_In_P (Is_String_Type'Access);
1445 elsif Opnd_Type = Any_Access then
1446 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1448 elsif Opnd_Type = Any_Composite then
1449 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1451 if Present (Orig_Type) then
1452 if Has_Private_Component (Orig_Type) then
1453 Orig_Type := Empty;
1454 else
1455 Set_Etype (Act1, Orig_Type);
1457 if Is_Binary then
1458 Set_Etype (Act2, Orig_Type);
1459 end if;
1460 end if;
1461 end if;
1463 else
1464 Orig_Type := Empty;
1465 end if;
1467 Error := No (Orig_Type);
1468 end if;
1470 elsif Ekind (Opnd_Type) = E_Allocator_Type
1471 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1472 then
1473 Error := True;
1475 -- If the type is defined elsewhere, and the operator is not
1476 -- defined in the given scope (by a renaming declaration, e.g.)
1477 -- then this is an error as well. If an extension of System is
1478 -- present, and the type may be defined there, Pack must be
1479 -- System itself.
1481 elsif Scope (Opnd_Type) /= Pack
1482 and then Scope (Op_Id) /= Pack
1483 and then (No (System_Aux_Id)
1484 or else Scope (Opnd_Type) /= System_Aux_Id
1485 or else Pack /= Scope (System_Aux_Id))
1486 then
1487 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1488 Error := True;
1489 else
1490 Error := not Operand_Type_In_Scope (Pack);
1491 end if;
1493 elsif Pack = Standard_Standard
1494 and then not Operand_Type_In_Scope (Standard_Standard)
1495 then
1496 Error := True;
1497 end if;
1498 end if;
1500 if Error then
1501 Error_Msg_Node_2 := Pack;
1502 Error_Msg_NE
1503 ("& not declared in&", N, Selector_Name (Name (N)));
1504 Set_Etype (N, Any_Type);
1505 return;
1507 -- Detect a mismatch between the context type and the result type
1508 -- in the named package, which is otherwise not detected if the
1509 -- operands are universal. Check is only needed if source entity is
1510 -- an operator, not a function that renames an operator.
1512 elsif Nkind (Parent (N)) /= N_Type_Conversion
1513 and then Ekind (Entity (Name (N))) = E_Operator
1514 and then Is_Numeric_Type (Typ)
1515 and then not Is_Universal_Numeric_Type (Typ)
1516 and then Scope (Base_Type (Typ)) /= Pack
1517 and then not In_Instance
1518 then
1519 if Is_Fixed_Point_Type (Typ)
1520 and then (Op_Name = Name_Op_Multiply
1521 or else
1522 Op_Name = Name_Op_Divide)
1523 then
1524 -- Already checked above
1526 null;
1528 -- Operator may be defined in an extension of System
1530 elsif Present (System_Aux_Id)
1531 and then Scope (Opnd_Type) = System_Aux_Id
1532 then
1533 null;
1535 else
1536 -- Could we use Wrong_Type here??? (this would require setting
1537 -- Etype (N) to the actual type found where Typ was expected).
1539 Error_Msg_NE ("expect }", N, Typ);
1540 end if;
1541 end if;
1542 end if;
1544 Set_Chars (Op_Node, Op_Name);
1546 if not Is_Private_Type (Etype (N)) then
1547 Set_Etype (Op_Node, Base_Type (Etype (N)));
1548 else
1549 Set_Etype (Op_Node, Etype (N));
1550 end if;
1552 -- If this is a call to a function that renames a predefined equality,
1553 -- the renaming declaration provides a type that must be used to
1554 -- resolve the operands. This must be done now because resolution of
1555 -- the equality node will not resolve any remaining ambiguity, and it
1556 -- assumes that the first operand is not overloaded.
1558 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1559 and then Ekind (Func) = E_Function
1560 and then Is_Overloaded (Act1)
1561 then
1562 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1563 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1564 end if;
1566 Set_Entity (Op_Node, Op_Id);
1567 Generate_Reference (Op_Id, N, ' ');
1569 -- Do rewrite setting Comes_From_Source on the result if the original
1570 -- call came from source. Although it is not strictly the case that the
1571 -- operator as such comes from the source, logically it corresponds
1572 -- exactly to the function call in the source, so it should be marked
1573 -- this way (e.g. to make sure that validity checks work fine).
1575 declare
1576 CS : constant Boolean := Comes_From_Source (N);
1577 begin
1578 Rewrite (N, Op_Node);
1579 Set_Comes_From_Source (N, CS);
1580 end;
1582 -- If this is an arithmetic operator and the result type is private,
1583 -- the operands and the result must be wrapped in conversion to
1584 -- expose the underlying numeric type and expand the proper checks,
1585 -- e.g. on division.
1587 if Is_Private_Type (Typ) then
1588 case Nkind (N) is
1589 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1590 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1591 Resolve_Intrinsic_Operator (N, Typ);
1593 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1594 Resolve_Intrinsic_Unary_Operator (N, Typ);
1596 when others =>
1597 Resolve (N, Typ);
1598 end case;
1599 else
1600 Resolve (N, Typ);
1601 end if;
1602 end Make_Call_Into_Operator;
1604 -------------------
1605 -- Operator_Kind --
1606 -------------------
1608 function Operator_Kind
1609 (Op_Name : Name_Id;
1610 Is_Binary : Boolean) return Node_Kind
1612 Kind : Node_Kind;
1614 begin
1615 -- Use CASE statement or array???
1617 if Is_Binary then
1618 if Op_Name = Name_Op_And then
1619 Kind := N_Op_And;
1620 elsif Op_Name = Name_Op_Or then
1621 Kind := N_Op_Or;
1622 elsif Op_Name = Name_Op_Xor then
1623 Kind := N_Op_Xor;
1624 elsif Op_Name = Name_Op_Eq then
1625 Kind := N_Op_Eq;
1626 elsif Op_Name = Name_Op_Ne then
1627 Kind := N_Op_Ne;
1628 elsif Op_Name = Name_Op_Lt then
1629 Kind := N_Op_Lt;
1630 elsif Op_Name = Name_Op_Le then
1631 Kind := N_Op_Le;
1632 elsif Op_Name = Name_Op_Gt then
1633 Kind := N_Op_Gt;
1634 elsif Op_Name = Name_Op_Ge then
1635 Kind := N_Op_Ge;
1636 elsif Op_Name = Name_Op_Add then
1637 Kind := N_Op_Add;
1638 elsif Op_Name = Name_Op_Subtract then
1639 Kind := N_Op_Subtract;
1640 elsif Op_Name = Name_Op_Concat then
1641 Kind := N_Op_Concat;
1642 elsif Op_Name = Name_Op_Multiply then
1643 Kind := N_Op_Multiply;
1644 elsif Op_Name = Name_Op_Divide then
1645 Kind := N_Op_Divide;
1646 elsif Op_Name = Name_Op_Mod then
1647 Kind := N_Op_Mod;
1648 elsif Op_Name = Name_Op_Rem then
1649 Kind := N_Op_Rem;
1650 elsif Op_Name = Name_Op_Expon then
1651 Kind := N_Op_Expon;
1652 else
1653 raise Program_Error;
1654 end if;
1656 -- Unary operators
1658 else
1659 if Op_Name = Name_Op_Add then
1660 Kind := N_Op_Plus;
1661 elsif Op_Name = Name_Op_Subtract then
1662 Kind := N_Op_Minus;
1663 elsif Op_Name = Name_Op_Abs then
1664 Kind := N_Op_Abs;
1665 elsif Op_Name = Name_Op_Not then
1666 Kind := N_Op_Not;
1667 else
1668 raise Program_Error;
1669 end if;
1670 end if;
1672 return Kind;
1673 end Operator_Kind;
1675 ----------------------------
1676 -- Preanalyze_And_Resolve --
1677 ----------------------------
1679 procedure Preanalyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1680 Save_Full_Analysis : constant Boolean := Full_Analysis;
1682 begin
1683 Full_Analysis := False;
1684 Expander_Mode_Save_And_Set (False);
1686 -- We suppress all checks for this analysis, since the checks will
1687 -- be applied properly, and in the right location, when the default
1688 -- expression is reanalyzed and reexpanded later on.
1690 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1692 Expander_Mode_Restore;
1693 Full_Analysis := Save_Full_Analysis;
1694 end Preanalyze_And_Resolve;
1696 -- Version without context type
1698 procedure Preanalyze_And_Resolve (N : Node_Id) is
1699 Save_Full_Analysis : constant Boolean := Full_Analysis;
1701 begin
1702 Full_Analysis := False;
1703 Expander_Mode_Save_And_Set (False);
1705 Analyze (N);
1706 Resolve (N, Etype (N), Suppress => All_Checks);
1708 Expander_Mode_Restore;
1709 Full_Analysis := Save_Full_Analysis;
1710 end Preanalyze_And_Resolve;
1712 ----------------------------------
1713 -- Replace_Actual_Discriminants --
1714 ----------------------------------
1716 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1717 Loc : constant Source_Ptr := Sloc (N);
1718 Tsk : Node_Id := Empty;
1720 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1721 -- Comment needed???
1723 -------------------
1724 -- Process_Discr --
1725 -------------------
1727 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1728 Ent : Entity_Id;
1730 begin
1731 if Nkind (Nod) = N_Identifier then
1732 Ent := Entity (Nod);
1734 if Present (Ent)
1735 and then Ekind (Ent) = E_Discriminant
1736 then
1737 Rewrite (Nod,
1738 Make_Selected_Component (Loc,
1739 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1740 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1742 Set_Etype (Nod, Etype (Ent));
1743 end if;
1745 end if;
1747 return OK;
1748 end Process_Discr;
1750 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1752 -- Start of processing for Replace_Actual_Discriminants
1754 begin
1755 if not Full_Expander_Active then
1756 return;
1757 end if;
1759 if Nkind (Name (N)) = N_Selected_Component then
1760 Tsk := Prefix (Name (N));
1762 elsif Nkind (Name (N)) = N_Indexed_Component then
1763 Tsk := Prefix (Prefix (Name (N)));
1764 end if;
1766 if No (Tsk) then
1767 return;
1768 else
1769 Replace_Discrs (Default);
1770 end if;
1771 end Replace_Actual_Discriminants;
1773 -------------
1774 -- Resolve --
1775 -------------
1777 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1778 Ambiguous : Boolean := False;
1779 Ctx_Type : Entity_Id := Typ;
1780 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1781 Err_Type : Entity_Id := Empty;
1782 Found : Boolean := False;
1783 From_Lib : Boolean;
1784 I : Interp_Index;
1785 I1 : Interp_Index := 0; -- prevent junk warning
1786 It : Interp;
1787 It1 : Interp;
1788 Seen : Entity_Id := Empty; -- prevent junk warning
1790 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean;
1791 -- Determine whether a node comes from a predefined library unit or
1792 -- Standard.
1794 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1795 -- Try and fix up a literal so that it matches its expected type. New
1796 -- literals are manufactured if necessary to avoid cascaded errors.
1798 function Proper_Current_Scope return Entity_Id;
1799 -- Return the current scope. Skip loop scopes created for the purpose of
1800 -- quantified expression analysis since those do not appear in the tree.
1802 procedure Report_Ambiguous_Argument;
1803 -- Additional diagnostics when an ambiguous call has an ambiguous
1804 -- argument (typically a controlling actual).
1806 procedure Resolution_Failed;
1807 -- Called when attempt at resolving current expression fails
1809 ------------------------------------
1810 -- Comes_From_Predefined_Lib_Unit --
1811 -------------------------------------
1813 function Comes_From_Predefined_Lib_Unit (Nod : Node_Id) return Boolean is
1814 begin
1815 return
1816 Sloc (Nod) = Standard_Location
1817 or else Is_Predefined_File_Name
1818 (Unit_File_Name (Get_Source_Unit (Sloc (Nod))));
1819 end Comes_From_Predefined_Lib_Unit;
1821 --------------------
1822 -- Patch_Up_Value --
1823 --------------------
1825 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1826 begin
1827 if Nkind (N) = N_Integer_Literal and then Is_Real_Type (Typ) then
1828 Rewrite (N,
1829 Make_Real_Literal (Sloc (N),
1830 Realval => UR_From_Uint (Intval (N))));
1831 Set_Etype (N, Universal_Real);
1832 Set_Is_Static_Expression (N);
1834 elsif Nkind (N) = N_Real_Literal and then Is_Integer_Type (Typ) then
1835 Rewrite (N,
1836 Make_Integer_Literal (Sloc (N),
1837 Intval => UR_To_Uint (Realval (N))));
1838 Set_Etype (N, Universal_Integer);
1839 Set_Is_Static_Expression (N);
1841 elsif Nkind (N) = N_String_Literal
1842 and then Is_Character_Type (Typ)
1843 then
1844 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1845 Rewrite (N,
1846 Make_Character_Literal (Sloc (N),
1847 Chars => Name_Find,
1848 Char_Literal_Value =>
1849 UI_From_Int (Character'Pos ('A'))));
1850 Set_Etype (N, Any_Character);
1851 Set_Is_Static_Expression (N);
1853 elsif Nkind (N) /= N_String_Literal and then Is_String_Type (Typ) then
1854 Rewrite (N,
1855 Make_String_Literal (Sloc (N),
1856 Strval => End_String));
1858 elsif Nkind (N) = N_Range then
1859 Patch_Up_Value (Low_Bound (N), Typ);
1860 Patch_Up_Value (High_Bound (N), Typ);
1861 end if;
1862 end Patch_Up_Value;
1864 --------------------------
1865 -- Proper_Current_Scope --
1866 --------------------------
1868 function Proper_Current_Scope return Entity_Id is
1869 S : Entity_Id := Current_Scope;
1871 begin
1872 while Present (S) loop
1874 -- Skip a loop scope created for quantified expression analysis
1876 if Ekind (S) = E_Loop
1877 and then Nkind (Parent (S)) = N_Quantified_Expression
1878 then
1879 S := Scope (S);
1880 else
1881 exit;
1882 end if;
1883 end loop;
1885 return S;
1886 end Proper_Current_Scope;
1888 -------------------------------
1889 -- Report_Ambiguous_Argument --
1890 -------------------------------
1892 procedure Report_Ambiguous_Argument is
1893 Arg : constant Node_Id := First (Parameter_Associations (N));
1894 I : Interp_Index;
1895 It : Interp;
1897 begin
1898 if Nkind (Arg) = N_Function_Call
1899 and then Is_Entity_Name (Name (Arg))
1900 and then Is_Overloaded (Name (Arg))
1901 then
1902 Error_Msg_NE ("ambiguous call to&", Arg, Name (Arg));
1904 -- Could use comments on what is going on here???
1906 Get_First_Interp (Name (Arg), I, It);
1907 while Present (It.Nam) loop
1908 Error_Msg_Sloc := Sloc (It.Nam);
1910 if Nkind (Parent (It.Nam)) = N_Full_Type_Declaration then
1911 Error_Msg_N ("interpretation (inherited) #!", Arg);
1912 else
1913 Error_Msg_N ("interpretation #!", Arg);
1914 end if;
1916 Get_Next_Interp (I, It);
1917 end loop;
1918 end if;
1919 end Report_Ambiguous_Argument;
1921 -----------------------
1922 -- Resolution_Failed --
1923 -----------------------
1925 procedure Resolution_Failed is
1926 begin
1927 Patch_Up_Value (N, Typ);
1928 Set_Etype (N, Typ);
1929 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1930 Set_Is_Overloaded (N, False);
1932 -- The caller will return without calling the expander, so we need
1933 -- to set the analyzed flag. Note that it is fine to set Analyzed
1934 -- to True even if we are in the middle of a shallow analysis,
1935 -- (see the spec of sem for more details) since this is an error
1936 -- situation anyway, and there is no point in repeating the
1937 -- analysis later (indeed it won't work to repeat it later, since
1938 -- we haven't got a clear resolution of which entity is being
1939 -- referenced.)
1941 Set_Analyzed (N, True);
1942 return;
1943 end Resolution_Failed;
1945 -- Start of processing for Resolve
1947 begin
1948 if N = Error then
1949 return;
1950 end if;
1952 -- Access attribute on remote subprogram cannot be used for a non-remote
1953 -- access-to-subprogram type.
1955 if Nkind (N) = N_Attribute_Reference
1956 and then (Attribute_Name (N) = Name_Access or else
1957 Attribute_Name (N) = Name_Unrestricted_Access or else
1958 Attribute_Name (N) = Name_Unchecked_Access)
1959 and then Comes_From_Source (N)
1960 and then Is_Entity_Name (Prefix (N))
1961 and then Is_Subprogram (Entity (Prefix (N)))
1962 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1963 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1964 then
1965 Error_Msg_N
1966 ("prefix must statically denote a non-remote subprogram", N);
1967 end if;
1969 From_Lib := Comes_From_Predefined_Lib_Unit (N);
1971 -- If the context is a Remote_Access_To_Subprogram, access attributes
1972 -- must be resolved with the corresponding fat pointer. There is no need
1973 -- to check for the attribute name since the return type of an
1974 -- attribute is never a remote type.
1976 if Nkind (N) = N_Attribute_Reference
1977 and then Comes_From_Source (N)
1978 and then (Is_Remote_Call_Interface (Typ) or else Is_Remote_Types (Typ))
1979 then
1980 declare
1981 Attr : constant Attribute_Id :=
1982 Get_Attribute_Id (Attribute_Name (N));
1983 Pref : constant Node_Id := Prefix (N);
1984 Decl : Node_Id;
1985 Spec : Node_Id;
1986 Is_Remote : Boolean := True;
1988 begin
1989 -- Check that Typ is a remote access-to-subprogram type
1991 if Is_Remote_Access_To_Subprogram_Type (Typ) then
1993 -- Prefix (N) must statically denote a remote subprogram
1994 -- declared in a package specification.
1996 if Attr = Attribute_Access or else
1997 Attr = Attribute_Unchecked_Access or else
1998 Attr = Attribute_Unrestricted_Access
1999 then
2000 Decl := Unit_Declaration_Node (Entity (Pref));
2002 if Nkind (Decl) = N_Subprogram_Body then
2003 Spec := Corresponding_Spec (Decl);
2005 if not No (Spec) then
2006 Decl := Unit_Declaration_Node (Spec);
2007 end if;
2008 end if;
2010 Spec := Parent (Decl);
2012 if not Is_Entity_Name (Prefix (N))
2013 or else Nkind (Spec) /= N_Package_Specification
2014 or else
2015 not Is_Remote_Call_Interface (Defining_Entity (Spec))
2016 then
2017 Is_Remote := False;
2018 Error_Msg_N
2019 ("prefix must statically denote a remote subprogram ",
2021 end if;
2023 -- If we are generating code in distributed mode, perform
2024 -- semantic checks against corresponding remote entities.
2026 if Full_Expander_Active
2027 and then Get_PCS_Name /= Name_No_DSA
2028 then
2029 Check_Subtype_Conformant
2030 (New_Id => Entity (Prefix (N)),
2031 Old_Id => Designated_Type
2032 (Corresponding_Remote_Type (Typ)),
2033 Err_Loc => N);
2035 if Is_Remote then
2036 Process_Remote_AST_Attribute (N, Typ);
2037 end if;
2038 end if;
2039 end if;
2040 end if;
2041 end;
2042 end if;
2044 Debug_A_Entry ("resolving ", N);
2046 if Debug_Flag_V then
2047 Write_Overloads (N);
2048 end if;
2050 if Comes_From_Source (N) then
2051 if Is_Fixed_Point_Type (Typ) then
2052 Check_Restriction (No_Fixed_Point, N);
2054 elsif Is_Floating_Point_Type (Typ)
2055 and then Typ /= Universal_Real
2056 and then Typ /= Any_Real
2057 then
2058 Check_Restriction (No_Floating_Point, N);
2059 end if;
2060 end if;
2062 -- Return if already analyzed
2064 if Analyzed (N) then
2065 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
2066 Analyze_Dimension (N);
2067 return;
2069 -- Return if type = Any_Type (previous error encountered)
2071 elsif Etype (N) = Any_Type then
2072 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
2073 return;
2074 end if;
2076 Check_Parameterless_Call (N);
2078 -- If not overloaded, then we know the type, and all that needs doing
2079 -- is to check that this type is compatible with the context.
2081 if not Is_Overloaded (N) then
2082 Found := Covers (Typ, Etype (N));
2083 Expr_Type := Etype (N);
2085 -- In the overloaded case, we must select the interpretation that
2086 -- is compatible with the context (i.e. the type passed to Resolve)
2088 else
2089 -- Loop through possible interpretations
2091 Get_First_Interp (N, I, It);
2092 Interp_Loop : while Present (It.Typ) loop
2094 if Debug_Flag_V then
2095 Write_Str ("Interp: ");
2096 Write_Interp (It);
2097 end if;
2099 -- We are only interested in interpretations that are compatible
2100 -- with the expected type, any other interpretations are ignored.
2102 if not Covers (Typ, It.Typ) then
2103 if Debug_Flag_V then
2104 Write_Str (" interpretation incompatible with context");
2105 Write_Eol;
2106 end if;
2108 else
2109 -- Skip the current interpretation if it is disabled by an
2110 -- abstract operator. This action is performed only when the
2111 -- type against which we are resolving is the same as the
2112 -- type of the interpretation.
2114 if Ada_Version >= Ada_2005
2115 and then It.Typ = Typ
2116 and then Typ /= Universal_Integer
2117 and then Typ /= Universal_Real
2118 and then Present (It.Abstract_Op)
2119 then
2120 if Debug_Flag_V then
2121 Write_Line ("Skip.");
2122 end if;
2124 goto Continue;
2125 end if;
2127 -- First matching interpretation
2129 if not Found then
2130 Found := True;
2131 I1 := I;
2132 Seen := It.Nam;
2133 Expr_Type := It.Typ;
2135 -- Matching interpretation that is not the first, maybe an
2136 -- error, but there are some cases where preference rules are
2137 -- used to choose between the two possibilities. These and
2138 -- some more obscure cases are handled in Disambiguate.
2140 else
2141 -- If the current statement is part of a predefined library
2142 -- unit, then all interpretations which come from user level
2143 -- packages should not be considered.
2145 if From_Lib
2146 and then not Comes_From_Predefined_Lib_Unit (It.Nam)
2147 then
2148 goto Continue;
2149 end if;
2151 Error_Msg_Sloc := Sloc (Seen);
2152 It1 := Disambiguate (N, I1, I, Typ);
2154 -- Disambiguation has succeeded. Skip the remaining
2155 -- interpretations.
2157 if It1 /= No_Interp then
2158 Seen := It1.Nam;
2159 Expr_Type := It1.Typ;
2161 while Present (It.Typ) loop
2162 Get_Next_Interp (I, It);
2163 end loop;
2165 else
2166 -- Before we issue an ambiguity complaint, check for
2167 -- the case of a subprogram call where at least one
2168 -- of the arguments is Any_Type, and if so, suppress
2169 -- the message, since it is a cascaded error.
2171 if Nkind (N) in N_Subprogram_Call then
2172 declare
2173 A : Node_Id;
2174 E : Node_Id;
2176 begin
2177 A := First_Actual (N);
2178 while Present (A) loop
2179 E := A;
2181 if Nkind (E) = N_Parameter_Association then
2182 E := Explicit_Actual_Parameter (E);
2183 end if;
2185 if Etype (E) = Any_Type then
2186 if Debug_Flag_V then
2187 Write_Str ("Any_Type in call");
2188 Write_Eol;
2189 end if;
2191 exit Interp_Loop;
2192 end if;
2194 Next_Actual (A);
2195 end loop;
2196 end;
2198 elsif Nkind (N) in N_Binary_Op
2199 and then (Etype (Left_Opnd (N)) = Any_Type
2200 or else Etype (Right_Opnd (N)) = Any_Type)
2201 then
2202 exit Interp_Loop;
2204 elsif Nkind (N) in N_Unary_Op
2205 and then Etype (Right_Opnd (N)) = Any_Type
2206 then
2207 exit Interp_Loop;
2208 end if;
2210 -- Not that special case, so issue message using the
2211 -- flag Ambiguous to control printing of the header
2212 -- message only at the start of an ambiguous set.
2214 if not Ambiguous then
2215 if Nkind (N) = N_Function_Call
2216 and then Nkind (Name (N)) = N_Explicit_Dereference
2217 then
2218 Error_Msg_N
2219 ("ambiguous expression "
2220 & "(cannot resolve indirect call)!", N);
2221 else
2222 Error_Msg_NE -- CODEFIX
2223 ("ambiguous expression (cannot resolve&)!",
2224 N, It.Nam);
2225 end if;
2227 Ambiguous := True;
2229 if Nkind (Parent (Seen)) = N_Full_Type_Declaration then
2230 Error_Msg_N
2231 ("\\possible interpretation (inherited)#!", N);
2232 else
2233 Error_Msg_N -- CODEFIX
2234 ("\\possible interpretation#!", N);
2235 end if;
2237 if Nkind (N) in N_Subprogram_Call
2238 and then Present (Parameter_Associations (N))
2239 then
2240 Report_Ambiguous_Argument;
2241 end if;
2242 end if;
2244 Error_Msg_Sloc := Sloc (It.Nam);
2246 -- By default, the error message refers to the candidate
2247 -- interpretation. But if it is a predefined operator, it
2248 -- is implicitly declared at the declaration of the type
2249 -- of the operand. Recover the sloc of that declaration
2250 -- for the error message.
2252 if Nkind (N) in N_Op
2253 and then Scope (It.Nam) = Standard_Standard
2254 and then not Is_Overloaded (Right_Opnd (N))
2255 and then Scope (Base_Type (Etype (Right_Opnd (N)))) /=
2256 Standard_Standard
2257 then
2258 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
2260 if Comes_From_Source (Err_Type)
2261 and then Present (Parent (Err_Type))
2262 then
2263 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2264 end if;
2266 elsif Nkind (N) in N_Binary_Op
2267 and then Scope (It.Nam) = Standard_Standard
2268 and then not Is_Overloaded (Left_Opnd (N))
2269 and then Scope (Base_Type (Etype (Left_Opnd (N)))) /=
2270 Standard_Standard
2271 then
2272 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
2274 if Comes_From_Source (Err_Type)
2275 and then Present (Parent (Err_Type))
2276 then
2277 Error_Msg_Sloc := Sloc (Parent (Err_Type));
2278 end if;
2280 -- If this is an indirect call, use the subprogram_type
2281 -- in the message, to have a meaningful location. Also
2282 -- indicate if this is an inherited operation, created
2283 -- by a type declaration.
2285 elsif Nkind (N) = N_Function_Call
2286 and then Nkind (Name (N)) = N_Explicit_Dereference
2287 and then Is_Type (It.Nam)
2288 then
2289 Err_Type := It.Nam;
2290 Error_Msg_Sloc :=
2291 Sloc (Associated_Node_For_Itype (Err_Type));
2292 else
2293 Err_Type := Empty;
2294 end if;
2296 if Nkind (N) in N_Op
2297 and then Scope (It.Nam) = Standard_Standard
2298 and then Present (Err_Type)
2299 then
2300 -- Special-case the message for universal_fixed
2301 -- operators, which are not declared with the type
2302 -- of the operand, but appear forever in Standard.
2304 if It.Typ = Universal_Fixed
2305 and then Scope (It.Nam) = Standard_Standard
2306 then
2307 Error_Msg_N
2308 ("\\possible interpretation as " &
2309 "universal_fixed operation " &
2310 "(RM 4.5.5 (19))", N);
2311 else
2312 Error_Msg_N
2313 ("\\possible interpretation (predefined)#!", N);
2314 end if;
2316 elsif
2317 Nkind (Parent (It.Nam)) = N_Full_Type_Declaration
2318 then
2319 Error_Msg_N
2320 ("\\possible interpretation (inherited)#!", N);
2321 else
2322 Error_Msg_N -- CODEFIX
2323 ("\\possible interpretation#!", N);
2324 end if;
2326 end if;
2327 end if;
2329 -- We have a matching interpretation, Expr_Type is the type
2330 -- from this interpretation, and Seen is the entity.
2332 -- For an operator, just set the entity name. The type will be
2333 -- set by the specific operator resolution routine.
2335 if Nkind (N) in N_Op then
2336 Set_Entity (N, Seen);
2337 Generate_Reference (Seen, N);
2339 elsif Nkind (N) = N_Case_Expression then
2340 Set_Etype (N, Expr_Type);
2342 elsif Nkind (N) = N_Character_Literal then
2343 Set_Etype (N, Expr_Type);
2345 elsif Nkind (N) = N_If_Expression then
2346 Set_Etype (N, Expr_Type);
2348 -- AI05-0139-2: Expression is overloaded because type has
2349 -- implicit dereference. If type matches context, no implicit
2350 -- dereference is involved.
2352 elsif Has_Implicit_Dereference (Expr_Type) then
2353 Set_Etype (N, Expr_Type);
2354 Set_Is_Overloaded (N, False);
2355 exit Interp_Loop;
2357 elsif Is_Overloaded (N)
2358 and then Present (It.Nam)
2359 and then Ekind (It.Nam) = E_Discriminant
2360 and then Has_Implicit_Dereference (It.Nam)
2361 then
2362 Build_Explicit_Dereference (N, It.Nam);
2364 -- For an explicit dereference, attribute reference, range,
2365 -- short-circuit form (which is not an operator node), or call
2366 -- with a name that is an explicit dereference, there is
2367 -- nothing to be done at this point.
2369 elsif Nkind_In (N, N_Explicit_Dereference,
2370 N_Attribute_Reference,
2371 N_And_Then,
2372 N_Indexed_Component,
2373 N_Or_Else,
2374 N_Range,
2375 N_Selected_Component,
2376 N_Slice)
2377 or else Nkind (Name (N)) = N_Explicit_Dereference
2378 then
2379 null;
2381 -- For procedure or function calls, set the type of the name,
2382 -- and also the entity pointer for the prefix.
2384 elsif Nkind (N) in N_Subprogram_Call
2385 and then Is_Entity_Name (Name (N))
2386 then
2387 Set_Etype (Name (N), Expr_Type);
2388 Set_Entity (Name (N), Seen);
2389 Generate_Reference (Seen, Name (N));
2391 elsif Nkind (N) = N_Function_Call
2392 and then Nkind (Name (N)) = N_Selected_Component
2393 then
2394 Set_Etype (Name (N), Expr_Type);
2395 Set_Entity (Selector_Name (Name (N)), Seen);
2396 Generate_Reference (Seen, Selector_Name (Name (N)));
2398 -- For all other cases, just set the type of the Name
2400 else
2401 Set_Etype (Name (N), Expr_Type);
2402 end if;
2404 end if;
2406 <<Continue>>
2408 -- Move to next interpretation
2410 exit Interp_Loop when No (It.Typ);
2412 Get_Next_Interp (I, It);
2413 end loop Interp_Loop;
2414 end if;
2416 -- At this stage Found indicates whether or not an acceptable
2417 -- interpretation exists. If not, then we have an error, except that if
2418 -- the context is Any_Type as a result of some other error, then we
2419 -- suppress the error report.
2421 if not Found then
2422 if Typ /= Any_Type then
2424 -- If type we are looking for is Void, then this is the procedure
2425 -- call case, and the error is simply that what we gave is not a
2426 -- procedure name (we think of procedure calls as expressions with
2427 -- types internally, but the user doesn't think of them this way!)
2429 if Typ = Standard_Void_Type then
2431 -- Special case message if function used as a procedure
2433 if Nkind (N) = N_Procedure_Call_Statement
2434 and then Is_Entity_Name (Name (N))
2435 and then Ekind (Entity (Name (N))) = E_Function
2436 then
2437 Error_Msg_NE
2438 ("cannot use function & in a procedure call",
2439 Name (N), Entity (Name (N)));
2441 -- Otherwise give general message (not clear what cases this
2442 -- covers, but no harm in providing for them!)
2444 else
2445 Error_Msg_N ("expect procedure name in procedure call", N);
2446 end if;
2448 Found := True;
2450 -- Otherwise we do have a subexpression with the wrong type
2452 -- Check for the case of an allocator which uses an access type
2453 -- instead of the designated type. This is a common error and we
2454 -- specialize the message, posting an error on the operand of the
2455 -- allocator, complaining that we expected the designated type of
2456 -- the allocator.
2458 elsif Nkind (N) = N_Allocator
2459 and then Ekind (Typ) in Access_Kind
2460 and then Ekind (Etype (N)) in Access_Kind
2461 and then Designated_Type (Etype (N)) = Typ
2462 then
2463 Wrong_Type (Expression (N), Designated_Type (Typ));
2464 Found := True;
2466 -- Check for view mismatch on Null in instances, for which the
2467 -- view-swapping mechanism has no identifier.
2469 elsif (In_Instance or else In_Inlined_Body)
2470 and then (Nkind (N) = N_Null)
2471 and then Is_Private_Type (Typ)
2472 and then Is_Access_Type (Full_View (Typ))
2473 then
2474 Resolve (N, Full_View (Typ));
2475 Set_Etype (N, Typ);
2476 return;
2478 -- Check for an aggregate. Sometimes we can get bogus aggregates
2479 -- from misuse of parentheses, and we are about to complain about
2480 -- the aggregate without even looking inside it.
2482 -- Instead, if we have an aggregate of type Any_Composite, then
2483 -- analyze and resolve the component fields, and then only issue
2484 -- another message if we get no errors doing this (otherwise
2485 -- assume that the errors in the aggregate caused the problem).
2487 elsif Nkind (N) = N_Aggregate
2488 and then Etype (N) = Any_Composite
2489 then
2490 -- Disable expansion in any case. If there is a type mismatch
2491 -- it may be fatal to try to expand the aggregate. The flag
2492 -- would otherwise be set to false when the error is posted.
2494 Expander_Active := False;
2496 declare
2497 procedure Check_Aggr (Aggr : Node_Id);
2498 -- Check one aggregate, and set Found to True if we have a
2499 -- definite error in any of its elements
2501 procedure Check_Elmt (Aelmt : Node_Id);
2502 -- Check one element of aggregate and set Found to True if
2503 -- we definitely have an error in the element.
2505 ----------------
2506 -- Check_Aggr --
2507 ----------------
2509 procedure Check_Aggr (Aggr : Node_Id) is
2510 Elmt : Node_Id;
2512 begin
2513 if Present (Expressions (Aggr)) then
2514 Elmt := First (Expressions (Aggr));
2515 while Present (Elmt) loop
2516 Check_Elmt (Elmt);
2517 Next (Elmt);
2518 end loop;
2519 end if;
2521 if Present (Component_Associations (Aggr)) then
2522 Elmt := First (Component_Associations (Aggr));
2523 while Present (Elmt) loop
2525 -- If this is a default-initialized component, then
2526 -- there is nothing to check. The box will be
2527 -- replaced by the appropriate call during late
2528 -- expansion.
2530 if not Box_Present (Elmt) then
2531 Check_Elmt (Expression (Elmt));
2532 end if;
2534 Next (Elmt);
2535 end loop;
2536 end if;
2537 end Check_Aggr;
2539 ----------------
2540 -- Check_Elmt --
2541 ----------------
2543 procedure Check_Elmt (Aelmt : Node_Id) is
2544 begin
2545 -- If we have a nested aggregate, go inside it (to
2546 -- attempt a naked analyze-resolve of the aggregate can
2547 -- cause undesirable cascaded errors). Do not resolve
2548 -- expression if it needs a type from context, as for
2549 -- integer * fixed expression.
2551 if Nkind (Aelmt) = N_Aggregate then
2552 Check_Aggr (Aelmt);
2554 else
2555 Analyze (Aelmt);
2557 if not Is_Overloaded (Aelmt)
2558 and then Etype (Aelmt) /= Any_Fixed
2559 then
2560 Resolve (Aelmt);
2561 end if;
2563 if Etype (Aelmt) = Any_Type then
2564 Found := True;
2565 end if;
2566 end if;
2567 end Check_Elmt;
2569 begin
2570 Check_Aggr (N);
2571 end;
2572 end if;
2574 -- If an error message was issued already, Found got reset to
2575 -- True, so if it is still False, issue standard Wrong_Type msg.
2577 if not Found then
2578 if Is_Overloaded (N)
2579 and then Nkind (N) = N_Function_Call
2580 then
2581 declare
2582 Subp_Name : Node_Id;
2583 begin
2584 if Is_Entity_Name (Name (N)) then
2585 Subp_Name := Name (N);
2587 elsif Nkind (Name (N)) = N_Selected_Component then
2589 -- Protected operation: retrieve operation name
2591 Subp_Name := Selector_Name (Name (N));
2593 else
2594 raise Program_Error;
2595 end if;
2597 Error_Msg_Node_2 := Typ;
2598 Error_Msg_NE ("no visible interpretation of&" &
2599 " matches expected type&", N, Subp_Name);
2600 end;
2602 if All_Errors_Mode then
2603 declare
2604 Index : Interp_Index;
2605 It : Interp;
2607 begin
2608 Error_Msg_N ("\\possible interpretations:", N);
2610 Get_First_Interp (Name (N), Index, It);
2611 while Present (It.Nam) loop
2612 Error_Msg_Sloc := Sloc (It.Nam);
2613 Error_Msg_Node_2 := It.Nam;
2614 Error_Msg_NE
2615 ("\\ type& for & declared#", N, It.Typ);
2616 Get_Next_Interp (Index, It);
2617 end loop;
2618 end;
2620 else
2621 Error_Msg_N ("\use -gnatf for details", N);
2622 end if;
2624 else
2625 Wrong_Type (N, Typ);
2626 end if;
2627 end if;
2628 end if;
2630 Resolution_Failed;
2631 return;
2633 -- Test if we have more than one interpretation for the context
2635 elsif Ambiguous then
2636 Resolution_Failed;
2637 return;
2639 -- Only one intepretation
2641 else
2642 -- In Ada 2005, if we have something like "X : T := 2 + 2;", where
2643 -- the "+" on T is abstract, and the operands are of universal type,
2644 -- the above code will have (incorrectly) resolved the "+" to the
2645 -- universal one in Standard. Therefore check for this case and give
2646 -- an error. We can't do this earlier, because it would cause legal
2647 -- cases to get errors (when some other type has an abstract "+").
2649 if Ada_Version >= Ada_2005
2650 and then Nkind (N) in N_Op
2651 and then Is_Overloaded (N)
2652 and then Is_Universal_Numeric_Type (Etype (Entity (N)))
2653 then
2654 Get_First_Interp (N, I, It);
2655 while Present (It.Typ) loop
2656 if Present (It.Abstract_Op) and then
2657 Etype (It.Abstract_Op) = Typ
2658 then
2659 Error_Msg_NE
2660 ("cannot call abstract subprogram &!", N, It.Abstract_Op);
2661 return;
2662 end if;
2664 Get_Next_Interp (I, It);
2665 end loop;
2666 end if;
2668 -- Here we have an acceptable interpretation for the context
2670 -- Propagate type information and normalize tree for various
2671 -- predefined operations. If the context only imposes a class of
2672 -- types, rather than a specific type, propagate the actual type
2673 -- downward.
2675 if Typ = Any_Integer or else
2676 Typ = Any_Boolean or else
2677 Typ = Any_Modular or else
2678 Typ = Any_Real or else
2679 Typ = Any_Discrete
2680 then
2681 Ctx_Type := Expr_Type;
2683 -- Any_Fixed is legal in a real context only if a specific fixed-
2684 -- point type is imposed. If Norman Cohen can be confused by this,
2685 -- it deserves a separate message.
2687 if Typ = Any_Real
2688 and then Expr_Type = Any_Fixed
2689 then
2690 Error_Msg_N ("illegal context for mixed mode operation", N);
2691 Set_Etype (N, Universal_Real);
2692 Ctx_Type := Universal_Real;
2693 end if;
2694 end if;
2696 -- A user-defined operator is transformed into a function call at
2697 -- this point, so that further processing knows that operators are
2698 -- really operators (i.e. are predefined operators). User-defined
2699 -- operators that are intrinsic are just renamings of the predefined
2700 -- ones, and need not be turned into calls either, but if they rename
2701 -- a different operator, we must transform the node accordingly.
2702 -- Instantiations of Unchecked_Conversion are intrinsic but are
2703 -- treated as functions, even if given an operator designator.
2705 if Nkind (N) in N_Op
2706 and then Present (Entity (N))
2707 and then Ekind (Entity (N)) /= E_Operator
2708 then
2710 if not Is_Predefined_Op (Entity (N)) then
2711 Rewrite_Operator_As_Call (N, Entity (N));
2713 elsif Present (Alias (Entity (N)))
2714 and then
2715 Nkind (Parent (Parent (Entity (N)))) =
2716 N_Subprogram_Renaming_Declaration
2717 then
2718 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2720 -- If the node is rewritten, it will be fully resolved in
2721 -- Rewrite_Renamed_Operator.
2723 if Analyzed (N) then
2724 return;
2725 end if;
2726 end if;
2727 end if;
2729 case N_Subexpr'(Nkind (N)) is
2731 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2733 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2735 when N_Short_Circuit
2736 => Resolve_Short_Circuit (N, Ctx_Type);
2738 when N_Attribute_Reference
2739 => Resolve_Attribute (N, Ctx_Type);
2741 when N_Case_Expression
2742 => Resolve_Case_Expression (N, Ctx_Type);
2744 when N_Character_Literal
2745 => Resolve_Character_Literal (N, Ctx_Type);
2747 when N_Expanded_Name
2748 => Resolve_Entity_Name (N, Ctx_Type);
2750 when N_Explicit_Dereference
2751 => Resolve_Explicit_Dereference (N, Ctx_Type);
2753 when N_Expression_With_Actions
2754 => Resolve_Expression_With_Actions (N, Ctx_Type);
2756 when N_Extension_Aggregate
2757 => Resolve_Extension_Aggregate (N, Ctx_Type);
2759 when N_Function_Call
2760 => Resolve_Call (N, Ctx_Type);
2762 when N_Identifier
2763 => Resolve_Entity_Name (N, Ctx_Type);
2765 when N_If_Expression
2766 => Resolve_If_Expression (N, Ctx_Type);
2768 when N_Indexed_Component
2769 => Resolve_Indexed_Component (N, Ctx_Type);
2771 when N_Integer_Literal
2772 => Resolve_Integer_Literal (N, Ctx_Type);
2774 when N_Membership_Test
2775 => Resolve_Membership_Op (N, Ctx_Type);
2777 when N_Null => Resolve_Null (N, Ctx_Type);
2779 when N_Op_And | N_Op_Or | N_Op_Xor
2780 => Resolve_Logical_Op (N, Ctx_Type);
2782 when N_Op_Eq | N_Op_Ne
2783 => Resolve_Equality_Op (N, Ctx_Type);
2785 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2786 => Resolve_Comparison_Op (N, Ctx_Type);
2788 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2790 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2791 N_Op_Divide | N_Op_Mod | N_Op_Rem
2793 => Resolve_Arithmetic_Op (N, Ctx_Type);
2795 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2797 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2799 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2800 => Resolve_Unary_Op (N, Ctx_Type);
2802 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2804 when N_Procedure_Call_Statement
2805 => Resolve_Call (N, Ctx_Type);
2807 when N_Operator_Symbol
2808 => Resolve_Operator_Symbol (N, Ctx_Type);
2810 when N_Qualified_Expression
2811 => Resolve_Qualified_Expression (N, Ctx_Type);
2813 when N_Quantified_Expression => null;
2815 when N_Raise_xxx_Error
2816 => Set_Etype (N, Ctx_Type);
2818 when N_Range => Resolve_Range (N, Ctx_Type);
2820 when N_Real_Literal
2821 => Resolve_Real_Literal (N, Ctx_Type);
2823 when N_Reference => Resolve_Reference (N, Ctx_Type);
2825 when N_Selected_Component
2826 => Resolve_Selected_Component (N, Ctx_Type);
2828 when N_Slice => Resolve_Slice (N, Ctx_Type);
2830 when N_String_Literal
2831 => Resolve_String_Literal (N, Ctx_Type);
2833 when N_Subprogram_Info
2834 => Resolve_Subprogram_Info (N, Ctx_Type);
2836 when N_Type_Conversion
2837 => Resolve_Type_Conversion (N, Ctx_Type);
2839 when N_Unchecked_Expression =>
2840 Resolve_Unchecked_Expression (N, Ctx_Type);
2842 when N_Unchecked_Type_Conversion =>
2843 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2844 end case;
2846 -- Ada 2012 (AI05-0149): Apply an (implicit) conversion to an
2847 -- expression of an anonymous access type that occurs in the context
2848 -- of a named general access type, except when the expression is that
2849 -- of a membership test. This ensures proper legality checking in
2850 -- terms of allowed conversions (expressions that would be illegal to
2851 -- convert implicitly are allowed in membership tests).
2853 if Ada_Version >= Ada_2012
2854 and then Ekind (Ctx_Type) = E_General_Access_Type
2855 and then Ekind (Etype (N)) = E_Anonymous_Access_Type
2856 and then Nkind (Parent (N)) not in N_Membership_Test
2857 then
2858 Rewrite (N, Convert_To (Ctx_Type, Relocate_Node (N)));
2859 Analyze_And_Resolve (N, Ctx_Type);
2860 end if;
2862 -- If the subexpression was replaced by a non-subexpression, then
2863 -- all we do is to expand it. The only legitimate case we know of
2864 -- is converting procedure call statement to entry call statements,
2865 -- but there may be others, so we are making this test general.
2867 if Nkind (N) not in N_Subexpr then
2868 Debug_A_Exit ("resolving ", N, " (done)");
2869 Expand (N);
2870 return;
2871 end if;
2873 -- AI05-144-2: Check dangerous order dependence within an expression
2874 -- that is not a subexpression. Exclude RHS of an assignment, because
2875 -- both sides may have side-effects and the check must be performed
2876 -- over the statement.
2878 if Nkind (Parent (N)) not in N_Subexpr
2879 and then Nkind (Parent (N)) /= N_Assignment_Statement
2880 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
2881 then
2882 Check_Order_Dependence;
2883 end if;
2885 -- The expression is definitely NOT overloaded at this point, so
2886 -- we reset the Is_Overloaded flag to avoid any confusion when
2887 -- reanalyzing the node.
2889 Set_Is_Overloaded (N, False);
2891 -- Freeze expression type, entity if it is a name, and designated
2892 -- type if it is an allocator (RM 13.14(10,11,13)).
2894 -- Now that the resolution of the type of the node is complete, and
2895 -- we did not detect an error, we can expand this node. We skip the
2896 -- expand call if we are in a default expression, see section
2897 -- "Handling of Default Expressions" in Sem spec.
2899 Debug_A_Exit ("resolving ", N, " (done)");
2901 -- We unconditionally freeze the expression, even if we are in
2902 -- default expression mode (the Freeze_Expression routine tests this
2903 -- flag and only freezes static types if it is set).
2905 -- Ada 2012 (AI05-177): Expression functions do not freeze. Only
2906 -- their use (in an expanded call) freezes.
2908 if Ekind (Proper_Current_Scope) /= E_Function
2909 or else Nkind (Original_Node (Unit_Declaration_Node
2910 (Proper_Current_Scope))) /= N_Expression_Function
2911 then
2912 Freeze_Expression (N);
2913 end if;
2915 -- Now we can do the expansion
2917 Expand (N);
2918 end if;
2919 end Resolve;
2921 -------------
2922 -- Resolve --
2923 -------------
2925 -- Version with check(s) suppressed
2927 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2928 begin
2929 if Suppress = All_Checks then
2930 declare
2931 Svg : constant Suppress_Record := Scope_Suppress;
2932 begin
2933 Scope_Suppress := Suppress_All;
2934 Resolve (N, Typ);
2935 Scope_Suppress := Svg;
2936 end;
2938 else
2939 declare
2940 Svg : constant Boolean := Scope_Suppress.Suppress (Suppress);
2941 begin
2942 Scope_Suppress.Suppress (Suppress) := True;
2943 Resolve (N, Typ);
2944 Scope_Suppress.Suppress (Suppress) := Svg;
2945 end;
2946 end if;
2947 end Resolve;
2949 -------------
2950 -- Resolve --
2951 -------------
2953 -- Version with implicit type
2955 procedure Resolve (N : Node_Id) is
2956 begin
2957 Resolve (N, Etype (N));
2958 end Resolve;
2960 ---------------------
2961 -- Resolve_Actuals --
2962 ---------------------
2964 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2965 Loc : constant Source_Ptr := Sloc (N);
2966 A : Node_Id;
2967 F : Entity_Id;
2968 A_Typ : Entity_Id;
2969 F_Typ : Entity_Id;
2970 Prev : Node_Id := Empty;
2971 Orig_A : Node_Id;
2973 procedure Check_Argument_Order;
2974 -- Performs a check for the case where the actuals are all simple
2975 -- identifiers that correspond to the formal names, but in the wrong
2976 -- order, which is considered suspicious and cause for a warning.
2978 procedure Check_Prefixed_Call;
2979 -- If the original node is an overloaded call in prefix notation,
2980 -- insert an 'Access or a dereference as needed over the first actual.
2981 -- Try_Object_Operation has already verified that there is a valid
2982 -- interpretation, but the form of the actual can only be determined
2983 -- once the primitive operation is identified.
2985 procedure Insert_Default;
2986 -- If the actual is missing in a call, insert in the actuals list
2987 -- an instance of the default expression. The insertion is always
2988 -- a named association.
2990 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2991 -- Check whether T1 and T2, or their full views, are derived from a
2992 -- common type. Used to enforce the restrictions on array conversions
2993 -- of AI95-00246.
2995 function Static_Concatenation (N : Node_Id) return Boolean;
2996 -- Predicate to determine whether an actual that is a concatenation
2997 -- will be evaluated statically and does not need a transient scope.
2998 -- This must be determined before the actual is resolved and expanded
2999 -- because if needed the transient scope must be introduced earlier.
3001 --------------------------
3002 -- Check_Argument_Order --
3003 --------------------------
3005 procedure Check_Argument_Order is
3006 begin
3007 -- Nothing to do if no parameters, or original node is neither a
3008 -- function call nor a procedure call statement (happens in the
3009 -- operator-transformed-to-function call case), or the call does
3010 -- not come from source, or this warning is off.
3012 if not Warn_On_Parameter_Order
3013 or else No (Parameter_Associations (N))
3014 or else Nkind (Original_Node (N)) not in N_Subprogram_Call
3015 or else not Comes_From_Source (N)
3016 then
3017 return;
3018 end if;
3020 declare
3021 Nargs : constant Nat := List_Length (Parameter_Associations (N));
3023 begin
3024 -- Nothing to do if only one parameter
3026 if Nargs < 2 then
3027 return;
3028 end if;
3030 -- Here if at least two arguments
3032 declare
3033 Actuals : array (1 .. Nargs) of Node_Id;
3034 Actual : Node_Id;
3035 Formal : Node_Id;
3037 Wrong_Order : Boolean := False;
3038 -- Set True if an out of order case is found
3040 begin
3041 -- Collect identifier names of actuals, fail if any actual is
3042 -- not a simple identifier, and record max length of name.
3044 Actual := First (Parameter_Associations (N));
3045 for J in Actuals'Range loop
3046 if Nkind (Actual) /= N_Identifier then
3047 return;
3048 else
3049 Actuals (J) := Actual;
3050 Next (Actual);
3051 end if;
3052 end loop;
3054 -- If we got this far, all actuals are identifiers and the list
3055 -- of their names is stored in the Actuals array.
3057 Formal := First_Formal (Nam);
3058 for J in Actuals'Range loop
3060 -- If we ran out of formals, that's odd, probably an error
3061 -- which will be detected elsewhere, but abandon the search.
3063 if No (Formal) then
3064 return;
3065 end if;
3067 -- If name matches and is in order OK
3069 if Chars (Formal) = Chars (Actuals (J)) then
3070 null;
3072 else
3073 -- If no match, see if it is elsewhere in list and if so
3074 -- flag potential wrong order if type is compatible.
3076 for K in Actuals'Range loop
3077 if Chars (Formal) = Chars (Actuals (K))
3078 and then
3079 Has_Compatible_Type (Actuals (K), Etype (Formal))
3080 then
3081 Wrong_Order := True;
3082 goto Continue;
3083 end if;
3084 end loop;
3086 -- No match
3088 return;
3089 end if;
3091 <<Continue>> Next_Formal (Formal);
3092 end loop;
3094 -- If Formals left over, also probably an error, skip warning
3096 if Present (Formal) then
3097 return;
3098 end if;
3100 -- Here we give the warning if something was out of order
3102 if Wrong_Order then
3103 Error_Msg_N
3104 ("actuals for this call may be in wrong order?", N);
3105 end if;
3106 end;
3107 end;
3108 end Check_Argument_Order;
3110 -------------------------
3111 -- Check_Prefixed_Call --
3112 -------------------------
3114 procedure Check_Prefixed_Call is
3115 Act : constant Node_Id := First_Actual (N);
3116 A_Type : constant Entity_Id := Etype (Act);
3117 F_Type : constant Entity_Id := Etype (First_Formal (Nam));
3118 Orig : constant Node_Id := Original_Node (N);
3119 New_A : Node_Id;
3121 begin
3122 -- Check whether the call is a prefixed call, with or without
3123 -- additional actuals.
3125 if Nkind (Orig) = N_Selected_Component
3126 or else
3127 (Nkind (Orig) = N_Indexed_Component
3128 and then Nkind (Prefix (Orig)) = N_Selected_Component
3129 and then Is_Entity_Name (Prefix (Prefix (Orig)))
3130 and then Is_Entity_Name (Act)
3131 and then Chars (Act) = Chars (Prefix (Prefix (Orig))))
3132 then
3133 if Is_Access_Type (A_Type)
3134 and then not Is_Access_Type (F_Type)
3135 then
3136 -- Introduce dereference on object in prefix
3138 New_A :=
3139 Make_Explicit_Dereference (Sloc (Act),
3140 Prefix => Relocate_Node (Act));
3141 Rewrite (Act, New_A);
3142 Analyze (Act);
3144 elsif Is_Access_Type (F_Type)
3145 and then not Is_Access_Type (A_Type)
3146 then
3147 -- Introduce an implicit 'Access in prefix
3149 if not Is_Aliased_View (Act) then
3150 Error_Msg_NE
3151 ("object in prefixed call to& must be aliased"
3152 & " (RM-2005 4.3.1 (13))",
3153 Prefix (Act), Nam);
3154 end if;
3156 Rewrite (Act,
3157 Make_Attribute_Reference (Loc,
3158 Attribute_Name => Name_Access,
3159 Prefix => Relocate_Node (Act)));
3160 end if;
3162 Analyze (Act);
3163 end if;
3164 end Check_Prefixed_Call;
3166 --------------------
3167 -- Insert_Default --
3168 --------------------
3170 procedure Insert_Default is
3171 Actval : Node_Id;
3172 Assoc : Node_Id;
3174 begin
3175 -- Missing argument in call, nothing to insert
3177 if No (Default_Value (F)) then
3178 return;
3180 else
3181 -- Note that we do a full New_Copy_Tree, so that any associated
3182 -- Itypes are properly copied. This may not be needed any more,
3183 -- but it does no harm as a safety measure! Defaults of a generic
3184 -- formal may be out of bounds of the corresponding actual (see
3185 -- cc1311b) and an additional check may be required.
3187 Actval :=
3188 New_Copy_Tree
3189 (Default_Value (F),
3190 New_Scope => Current_Scope,
3191 New_Sloc => Loc);
3193 if Is_Concurrent_Type (Scope (Nam))
3194 and then Has_Discriminants (Scope (Nam))
3195 then
3196 Replace_Actual_Discriminants (N, Actval);
3197 end if;
3199 if Is_Overloadable (Nam)
3200 and then Present (Alias (Nam))
3201 then
3202 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
3203 and then not Is_Tagged_Type (Etype (F))
3204 then
3205 -- If default is a real literal, do not introduce a
3206 -- conversion whose effect may depend on the run-time
3207 -- size of universal real.
3209 if Nkind (Actval) = N_Real_Literal then
3210 Set_Etype (Actval, Base_Type (Etype (F)));
3211 else
3212 Actval := Unchecked_Convert_To (Etype (F), Actval);
3213 end if;
3214 end if;
3216 if Is_Scalar_Type (Etype (F)) then
3217 Enable_Range_Check (Actval);
3218 end if;
3220 Set_Parent (Actval, N);
3222 -- Resolve aggregates with their base type, to avoid scope
3223 -- anomalies: the subtype was first built in the subprogram
3224 -- declaration, and the current call may be nested.
3226 if Nkind (Actval) = N_Aggregate then
3227 Analyze_And_Resolve (Actval, Etype (F));
3228 else
3229 Analyze_And_Resolve (Actval, Etype (Actval));
3230 end if;
3232 else
3233 Set_Parent (Actval, N);
3235 -- See note above concerning aggregates
3237 if Nkind (Actval) = N_Aggregate
3238 and then Has_Discriminants (Etype (Actval))
3239 then
3240 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
3242 -- Resolve entities with their own type, which may differ from
3243 -- the type of a reference in a generic context (the view
3244 -- swapping mechanism did not anticipate the re-analysis of
3245 -- default values in calls).
3247 elsif Is_Entity_Name (Actval) then
3248 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
3250 else
3251 Analyze_And_Resolve (Actval, Etype (Actval));
3252 end if;
3253 end if;
3255 -- If default is a tag indeterminate function call, propagate tag
3256 -- to obtain proper dispatching.
3258 if Is_Controlling_Formal (F)
3259 and then Nkind (Default_Value (F)) = N_Function_Call
3260 then
3261 Set_Is_Controlling_Actual (Actval);
3262 end if;
3264 end if;
3266 -- If the default expression raises constraint error, then just
3267 -- silently replace it with an N_Raise_Constraint_Error node, since
3268 -- we already gave the warning on the subprogram spec. If node is
3269 -- already a Raise_Constraint_Error leave as is, to prevent loops in
3270 -- the warnings removal machinery.
3272 if Raises_Constraint_Error (Actval)
3273 and then Nkind (Actval) /= N_Raise_Constraint_Error
3274 then
3275 Rewrite (Actval,
3276 Make_Raise_Constraint_Error (Loc,
3277 Reason => CE_Range_Check_Failed));
3278 Set_Raises_Constraint_Error (Actval);
3279 Set_Etype (Actval, Etype (F));
3280 end if;
3282 Assoc :=
3283 Make_Parameter_Association (Loc,
3284 Explicit_Actual_Parameter => Actval,
3285 Selector_Name => Make_Identifier (Loc, Chars (F)));
3287 -- Case of insertion is first named actual
3289 if No (Prev) or else
3290 Nkind (Parent (Prev)) /= N_Parameter_Association
3291 then
3292 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
3293 Set_First_Named_Actual (N, Actval);
3295 if No (Prev) then
3296 if No (Parameter_Associations (N)) then
3297 Set_Parameter_Associations (N, New_List (Assoc));
3298 else
3299 Append (Assoc, Parameter_Associations (N));
3300 end if;
3302 else
3303 Insert_After (Prev, Assoc);
3304 end if;
3306 -- Case of insertion is not first named actual
3308 else
3309 Set_Next_Named_Actual
3310 (Assoc, Next_Named_Actual (Parent (Prev)));
3311 Set_Next_Named_Actual (Parent (Prev), Actval);
3312 Append (Assoc, Parameter_Associations (N));
3313 end if;
3315 Mark_Rewrite_Insertion (Assoc);
3316 Mark_Rewrite_Insertion (Actval);
3318 Prev := Actval;
3319 end Insert_Default;
3321 -------------------
3322 -- Same_Ancestor --
3323 -------------------
3325 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
3326 FT1 : Entity_Id := T1;
3327 FT2 : Entity_Id := T2;
3329 begin
3330 if Is_Private_Type (T1)
3331 and then Present (Full_View (T1))
3332 then
3333 FT1 := Full_View (T1);
3334 end if;
3336 if Is_Private_Type (T2)
3337 and then Present (Full_View (T2))
3338 then
3339 FT2 := Full_View (T2);
3340 end if;
3342 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
3343 end Same_Ancestor;
3345 --------------------------
3346 -- Static_Concatenation --
3347 --------------------------
3349 function Static_Concatenation (N : Node_Id) return Boolean is
3350 begin
3351 case Nkind (N) is
3352 when N_String_Literal =>
3353 return True;
3355 when N_Op_Concat =>
3357 -- Concatenation is static when both operands are static and
3358 -- the concatenation operator is a predefined one.
3360 return Scope (Entity (N)) = Standard_Standard
3361 and then
3362 Static_Concatenation (Left_Opnd (N))
3363 and then
3364 Static_Concatenation (Right_Opnd (N));
3366 when others =>
3367 if Is_Entity_Name (N) then
3368 declare
3369 Ent : constant Entity_Id := Entity (N);
3370 begin
3371 return Ekind (Ent) = E_Constant
3372 and then Present (Constant_Value (Ent))
3373 and then
3374 Is_Static_Expression (Constant_Value (Ent));
3375 end;
3377 else
3378 return False;
3379 end if;
3380 end case;
3381 end Static_Concatenation;
3383 -- Start of processing for Resolve_Actuals
3385 begin
3386 Check_Argument_Order;
3388 if Present (First_Actual (N)) then
3389 Check_Prefixed_Call;
3390 end if;
3392 A := First_Actual (N);
3393 F := First_Formal (Nam);
3394 while Present (F) loop
3395 if No (A) and then Needs_No_Actuals (Nam) then
3396 null;
3398 -- If we have an error in any actual or formal, indicated by a type
3399 -- of Any_Type, then abandon resolution attempt, and set result type
3400 -- to Any_Type.
3402 elsif (Present (A) and then Etype (A) = Any_Type)
3403 or else Etype (F) = Any_Type
3404 then
3405 Set_Etype (N, Any_Type);
3406 return;
3407 end if;
3409 -- Case where actual is present
3411 -- If the actual is an entity, generate a reference to it now. We
3412 -- do this before the actual is resolved, because a formal of some
3413 -- protected subprogram, or a task discriminant, will be rewritten
3414 -- during expansion, and the source entity reference may be lost.
3416 if Present (A)
3417 and then Is_Entity_Name (A)
3418 and then Comes_From_Source (N)
3419 then
3420 Orig_A := Entity (A);
3422 if Present (Orig_A) then
3423 if Is_Formal (Orig_A)
3424 and then Ekind (F) /= E_In_Parameter
3425 then
3426 Generate_Reference (Orig_A, A, 'm');
3428 elsif not Is_Overloaded (A) then
3429 Generate_Reference (Orig_A, A);
3430 end if;
3431 end if;
3432 end if;
3434 if Present (A)
3435 and then (Nkind (Parent (A)) /= N_Parameter_Association
3436 or else Chars (Selector_Name (Parent (A))) = Chars (F))
3437 then
3438 -- If style checking mode on, check match of formal name
3440 if Style_Check then
3441 if Nkind (Parent (A)) = N_Parameter_Association then
3442 Check_Identifier (Selector_Name (Parent (A)), F);
3443 end if;
3444 end if;
3446 -- If the formal is Out or In_Out, do not resolve and expand the
3447 -- conversion, because it is subsequently expanded into explicit
3448 -- temporaries and assignments. However, the object of the
3449 -- conversion can be resolved. An exception is the case of tagged
3450 -- type conversion with a class-wide actual. In that case we want
3451 -- the tag check to occur and no temporary will be needed (no
3452 -- representation change can occur) and the parameter is passed by
3453 -- reference, so we go ahead and resolve the type conversion.
3454 -- Another exception is the case of reference to component or
3455 -- subcomponent of a bit-packed array, in which case we want to
3456 -- defer expansion to the point the in and out assignments are
3457 -- performed.
3459 if Ekind (F) /= E_In_Parameter
3460 and then Nkind (A) = N_Type_Conversion
3461 and then not Is_Class_Wide_Type (Etype (Expression (A)))
3462 then
3463 if Ekind (F) = E_In_Out_Parameter
3464 and then Is_Array_Type (Etype (F))
3465 then
3466 -- In a view conversion, the conversion must be legal in
3467 -- both directions, and thus both component types must be
3468 -- aliased, or neither (4.6 (8)).
3470 -- The extra rule in 4.6 (24.9.2) seems unduly restrictive:
3471 -- the privacy requirement should not apply to generic
3472 -- types, and should be checked in an instance. ARG query
3473 -- is in order ???
3475 if Has_Aliased_Components (Etype (Expression (A))) /=
3476 Has_Aliased_Components (Etype (F))
3477 then
3478 Error_Msg_N
3479 ("both component types in a view conversion must be"
3480 & " aliased, or neither", A);
3482 -- Comment here??? what set of cases???
3484 elsif
3485 not Same_Ancestor (Etype (F), Etype (Expression (A)))
3486 then
3487 -- Check view conv between unrelated by ref array types
3489 if Is_By_Reference_Type (Etype (F))
3490 or else Is_By_Reference_Type (Etype (Expression (A)))
3491 then
3492 Error_Msg_N
3493 ("view conversion between unrelated by reference " &
3494 "array types not allowed (\'A'I-00246)", A);
3496 -- In Ada 2005 mode, check view conversion component
3497 -- type cannot be private, tagged, or volatile. Note
3498 -- that we only apply this to source conversions. The
3499 -- generated code can contain conversions which are
3500 -- not subject to this test, and we cannot extract the
3501 -- component type in such cases since it is not present.
3503 elsif Comes_From_Source (A)
3504 and then Ada_Version >= Ada_2005
3505 then
3506 declare
3507 Comp_Type : constant Entity_Id :=
3508 Component_Type
3509 (Etype (Expression (A)));
3510 begin
3511 if (Is_Private_Type (Comp_Type)
3512 and then not Is_Generic_Type (Comp_Type))
3513 or else Is_Tagged_Type (Comp_Type)
3514 or else Is_Volatile (Comp_Type)
3515 then
3516 Error_Msg_N
3517 ("component type of a view conversion cannot"
3518 & " be private, tagged, or volatile"
3519 & " (RM 4.6 (24))",
3520 Expression (A));
3521 end if;
3522 end;
3523 end if;
3524 end if;
3525 end if;
3527 -- Resolve expression if conversion is all OK
3529 if (Conversion_OK (A)
3530 or else Valid_Conversion (A, Etype (A), Expression (A)))
3531 and then not Is_Ref_To_Bit_Packed_Array (Expression (A))
3532 then
3533 Resolve (Expression (A));
3534 end if;
3536 -- If the actual is a function call that returns a limited
3537 -- unconstrained object that needs finalization, create a
3538 -- transient scope for it, so that it can receive the proper
3539 -- finalization list.
3541 elsif Nkind (A) = N_Function_Call
3542 and then Is_Limited_Record (Etype (F))
3543 and then not Is_Constrained (Etype (F))
3544 and then Full_Expander_Active
3545 and then (Is_Controlled (Etype (F)) or else Has_Task (Etype (F)))
3546 then
3547 Establish_Transient_Scope (A, False);
3548 Resolve (A, Etype (F));
3550 -- A small optimization: if one of the actuals is a concatenation
3551 -- create a block around a procedure call to recover stack space.
3552 -- This alleviates stack usage when several procedure calls in
3553 -- the same statement list use concatenation. We do not perform
3554 -- this wrapping for code statements, where the argument is a
3555 -- static string, and we want to preserve warnings involving
3556 -- sequences of such statements.
3558 elsif Nkind (A) = N_Op_Concat
3559 and then Nkind (N) = N_Procedure_Call_Statement
3560 and then Full_Expander_Active
3561 and then
3562 not (Is_Intrinsic_Subprogram (Nam)
3563 and then Chars (Nam) = Name_Asm)
3564 and then not Static_Concatenation (A)
3565 then
3566 Establish_Transient_Scope (A, False);
3567 Resolve (A, Etype (F));
3569 else
3570 if Nkind (A) = N_Type_Conversion
3571 and then Is_Array_Type (Etype (F))
3572 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
3573 and then
3574 (Is_Limited_Type (Etype (F))
3575 or else Is_Limited_Type (Etype (Expression (A))))
3576 then
3577 Error_Msg_N
3578 ("conversion between unrelated limited array types " &
3579 "not allowed (\A\I-00246)", A);
3581 if Is_Limited_Type (Etype (F)) then
3582 Explain_Limited_Type (Etype (F), A);
3583 end if;
3585 if Is_Limited_Type (Etype (Expression (A))) then
3586 Explain_Limited_Type (Etype (Expression (A)), A);
3587 end if;
3588 end if;
3590 -- (Ada 2005: AI-251): If the actual is an allocator whose
3591 -- directly designated type is a class-wide interface, we build
3592 -- an anonymous access type to use it as the type of the
3593 -- allocator. Later, when the subprogram call is expanded, if
3594 -- the interface has a secondary dispatch table the expander
3595 -- will add a type conversion to force the correct displacement
3596 -- of the pointer.
3598 if Nkind (A) = N_Allocator then
3599 declare
3600 DDT : constant Entity_Id :=
3601 Directly_Designated_Type (Base_Type (Etype (F)));
3603 New_Itype : Entity_Id;
3605 begin
3606 if Is_Class_Wide_Type (DDT)
3607 and then Is_Interface (DDT)
3608 then
3609 New_Itype := Create_Itype (E_Anonymous_Access_Type, A);
3610 Set_Etype (New_Itype, Etype (A));
3611 Set_Directly_Designated_Type (New_Itype,
3612 Directly_Designated_Type (Etype (A)));
3613 Set_Etype (A, New_Itype);
3614 end if;
3616 -- Ada 2005, AI-162:If the actual is an allocator, the
3617 -- innermost enclosing statement is the master of the
3618 -- created object. This needs to be done with expansion
3619 -- enabled only, otherwise the transient scope will not
3620 -- be removed in the expansion of the wrapped construct.
3622 if (Is_Controlled (DDT) or else Has_Task (DDT))
3623 and then Full_Expander_Active
3624 then
3625 Establish_Transient_Scope (A, False);
3626 end if;
3627 end;
3628 end if;
3630 -- (Ada 2005): The call may be to a primitive operation of
3631 -- a tagged synchronized type, declared outside of the type.
3632 -- In this case the controlling actual must be converted to
3633 -- its corresponding record type, which is the formal type.
3634 -- The actual may be a subtype, either because of a constraint
3635 -- or because it is a generic actual, so use base type to
3636 -- locate concurrent type.
3638 F_Typ := Base_Type (Etype (F));
3640 if Is_Tagged_Type (F_Typ)
3641 and then (Is_Concurrent_Type (F_Typ)
3642 or else Is_Concurrent_Record_Type (F_Typ))
3643 then
3644 -- If the actual is overloaded, look for an interpretation
3645 -- that has a synchronized type.
3647 if not Is_Overloaded (A) then
3648 A_Typ := Base_Type (Etype (A));
3650 else
3651 declare
3652 Index : Interp_Index;
3653 It : Interp;
3655 begin
3656 Get_First_Interp (A, Index, It);
3657 while Present (It.Typ) loop
3658 if Is_Concurrent_Type (It.Typ)
3659 or else Is_Concurrent_Record_Type (It.Typ)
3660 then
3661 A_Typ := Base_Type (It.Typ);
3662 exit;
3663 end if;
3665 Get_Next_Interp (Index, It);
3666 end loop;
3667 end;
3668 end if;
3670 declare
3671 Full_A_Typ : Entity_Id;
3673 begin
3674 if Present (Full_View (A_Typ)) then
3675 Full_A_Typ := Base_Type (Full_View (A_Typ));
3676 else
3677 Full_A_Typ := A_Typ;
3678 end if;
3680 -- Tagged synchronized type (case 1): the actual is a
3681 -- concurrent type.
3683 if Is_Concurrent_Type (A_Typ)
3684 and then Corresponding_Record_Type (A_Typ) = F_Typ
3685 then
3686 Rewrite (A,
3687 Unchecked_Convert_To
3688 (Corresponding_Record_Type (A_Typ), A));
3689 Resolve (A, Etype (F));
3691 -- Tagged synchronized type (case 2): the formal is a
3692 -- concurrent type.
3694 elsif Ekind (Full_A_Typ) = E_Record_Type
3695 and then Present
3696 (Corresponding_Concurrent_Type (Full_A_Typ))
3697 and then Is_Concurrent_Type (F_Typ)
3698 and then Present (Corresponding_Record_Type (F_Typ))
3699 and then Full_A_Typ = Corresponding_Record_Type (F_Typ)
3700 then
3701 Resolve (A, Corresponding_Record_Type (F_Typ));
3703 -- Common case
3705 else
3706 Resolve (A, Etype (F));
3707 end if;
3708 end;
3709 else
3711 -- not a synchronized operation.
3713 Resolve (A, Etype (F));
3714 end if;
3715 end if;
3717 A_Typ := Etype (A);
3718 F_Typ := Etype (F);
3720 if Comes_From_Source (Original_Node (N))
3721 and then Nkind_In (Original_Node (N), N_Function_Call,
3722 N_Procedure_Call_Statement)
3723 then
3724 -- In formal mode, check that actual parameters matching
3725 -- formals of tagged types are objects (or ancestor type
3726 -- conversions of objects), not general expressions.
3728 if Is_Actual_Tagged_Parameter (A) then
3729 if Is_SPARK_Object_Reference (A) then
3730 null;
3732 elsif Nkind (A) = N_Type_Conversion then
3733 declare
3734 Operand : constant Node_Id := Expression (A);
3735 Operand_Typ : constant Entity_Id := Etype (Operand);
3736 Target_Typ : constant Entity_Id := A_Typ;
3738 begin
3739 if not Is_SPARK_Object_Reference (Operand) then
3740 Check_SPARK_Restriction
3741 ("object required", Operand);
3743 -- In formal mode, the only view conversions are those
3744 -- involving ancestor conversion of an extended type.
3746 elsif not
3747 (Is_Tagged_Type (Target_Typ)
3748 and then not Is_Class_Wide_Type (Target_Typ)
3749 and then Is_Tagged_Type (Operand_Typ)
3750 and then not Is_Class_Wide_Type (Operand_Typ)
3751 and then Is_Ancestor (Target_Typ, Operand_Typ))
3752 then
3753 if Ekind_In
3754 (F, E_Out_Parameter, E_In_Out_Parameter)
3755 then
3756 Check_SPARK_Restriction
3757 ("ancestor conversion is the only permitted "
3758 & "view conversion", A);
3759 else
3760 Check_SPARK_Restriction
3761 ("ancestor conversion required", A);
3762 end if;
3764 else
3765 null;
3766 end if;
3767 end;
3769 else
3770 Check_SPARK_Restriction ("object required", A);
3771 end if;
3773 -- In formal mode, the only view conversions are those
3774 -- involving ancestor conversion of an extended type.
3776 elsif Nkind (A) = N_Type_Conversion
3777 and then Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter)
3778 then
3779 Check_SPARK_Restriction
3780 ("ancestor conversion is the only permitted view "
3781 & "conversion", A);
3782 end if;
3783 end if;
3785 -- Save actual for subsequent check on order dependence, and
3786 -- indicate whether actual is modifiable. For AI05-0144-2.
3788 -- If this is a call to a reference function that is the result
3789 -- of expansion, as in element iterator loops, this does not lead
3790 -- to a dangerous order dependence: only subsequent use of the
3791 -- denoted element might, in some enclosing call.
3793 if not Has_Implicit_Dereference (Etype (Nam))
3794 or else Comes_From_Source (N)
3795 then
3796 Save_Actual (A, Ekind (F) /= E_In_Parameter);
3797 end if;
3799 -- For mode IN, if actual is an entity, and the type of the formal
3800 -- has warnings suppressed, then we reset Never_Set_In_Source for
3801 -- the calling entity. The reason for this is to catch cases like
3802 -- GNAT.Spitbol.Patterns.Vstring_Var where the called subprogram
3803 -- uses trickery to modify an IN parameter.
3805 if Ekind (F) = E_In_Parameter
3806 and then Is_Entity_Name (A)
3807 and then Present (Entity (A))
3808 and then Ekind (Entity (A)) = E_Variable
3809 and then Has_Warnings_Off (F_Typ)
3810 then
3811 Set_Never_Set_In_Source (Entity (A), False);
3812 end if;
3814 -- Perform error checks for IN and IN OUT parameters
3816 if Ekind (F) /= E_Out_Parameter then
3818 -- Check unset reference. For scalar parameters, it is clearly
3819 -- wrong to pass an uninitialized value as either an IN or
3820 -- IN-OUT parameter. For composites, it is also clearly an
3821 -- error to pass a completely uninitialized value as an IN
3822 -- parameter, but the case of IN OUT is trickier. We prefer
3823 -- not to give a warning here. For example, suppose there is
3824 -- a routine that sets some component of a record to False.
3825 -- It is perfectly reasonable to make this IN-OUT and allow
3826 -- either initialized or uninitialized records to be passed
3827 -- in this case.
3829 -- For partially initialized composite values, we also avoid
3830 -- warnings, since it is quite likely that we are passing a
3831 -- partially initialized value and only the initialized fields
3832 -- will in fact be read in the subprogram.
3834 if Is_Scalar_Type (A_Typ)
3835 or else (Ekind (F) = E_In_Parameter
3836 and then not Is_Partially_Initialized_Type (A_Typ))
3837 then
3838 Check_Unset_Reference (A);
3839 end if;
3841 -- In Ada 83 we cannot pass an OUT parameter as an IN or IN OUT
3842 -- actual to a nested call, since this is case of reading an
3843 -- out parameter, which is not allowed.
3845 if Ada_Version = Ada_83
3846 and then Is_Entity_Name (A)
3847 and then Ekind (Entity (A)) = E_Out_Parameter
3848 then
3849 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
3850 end if;
3851 end if;
3853 -- Case of OUT or IN OUT parameter
3855 if Ekind (F) /= E_In_Parameter then
3857 -- For an Out parameter, check for useless assignment. Note
3858 -- that we can't set Last_Assignment this early, because we may
3859 -- kill current values in Resolve_Call, and that call would
3860 -- clobber the Last_Assignment field.
3862 -- Note: call Warn_On_Useless_Assignment before doing the check
3863 -- below for Is_OK_Variable_For_Out_Formal so that the setting
3864 -- of Referenced_As_LHS/Referenced_As_Out_Formal properly
3865 -- reflects the last assignment, not this one!
3867 if Ekind (F) = E_Out_Parameter then
3868 if Warn_On_Modified_As_Out_Parameter (F)
3869 and then Is_Entity_Name (A)
3870 and then Present (Entity (A))
3871 and then Comes_From_Source (N)
3872 then
3873 Warn_On_Useless_Assignment (Entity (A), A);
3874 end if;
3875 end if;
3877 -- Validate the form of the actual. Note that the call to
3878 -- Is_OK_Variable_For_Out_Formal generates the required
3879 -- reference in this case.
3881 -- A call to an initialization procedure for an aggregate
3882 -- component may initialize a nested component of a constant
3883 -- designated object. In this context the object is variable.
3885 if not Is_OK_Variable_For_Out_Formal (A)
3886 and then not Is_Init_Proc (Nam)
3887 then
3888 Error_Msg_NE ("actual for& must be a variable", A, F);
3889 end if;
3891 -- What's the following about???
3893 if Is_Entity_Name (A) then
3894 Kill_Checks (Entity (A));
3895 else
3896 Kill_All_Checks;
3897 end if;
3898 end if;
3900 if Etype (A) = Any_Type then
3901 Set_Etype (N, Any_Type);
3902 return;
3903 end if;
3905 -- Apply appropriate range checks for in, out, and in-out
3906 -- parameters. Out and in-out parameters also need a separate
3907 -- check, if there is a type conversion, to make sure the return
3908 -- value meets the constraints of the variable before the
3909 -- conversion.
3911 -- Gigi looks at the check flag and uses the appropriate types.
3912 -- For now since one flag is used there is an optimization which
3913 -- might not be done in the In Out case since Gigi does not do
3914 -- any analysis. More thought required about this ???
3916 if Ekind_In (F, E_In_Parameter, E_In_Out_Parameter) then
3918 -- Apply predicate checks, unless this is a call to the
3919 -- predicate check function itself, which would cause an
3920 -- infinite recursion.
3922 if not (Ekind (Nam) = E_Function
3923 and then Has_Predicates (Nam))
3924 then
3925 Apply_Predicate_Check (A, F_Typ);
3926 end if;
3928 -- Apply required constraint checks
3930 if Is_Scalar_Type (Etype (A)) then
3931 Apply_Scalar_Range_Check (A, F_Typ);
3933 elsif Is_Array_Type (Etype (A)) then
3934 Apply_Length_Check (A, F_Typ);
3936 elsif Is_Record_Type (F_Typ)
3937 and then Has_Discriminants (F_Typ)
3938 and then Is_Constrained (F_Typ)
3939 and then (not Is_Derived_Type (F_Typ)
3940 or else Comes_From_Source (Nam))
3941 then
3942 Apply_Discriminant_Check (A, F_Typ);
3944 elsif Is_Access_Type (F_Typ)
3945 and then Is_Array_Type (Designated_Type (F_Typ))
3946 and then Is_Constrained (Designated_Type (F_Typ))
3947 then
3948 Apply_Length_Check (A, F_Typ);
3950 elsif Is_Access_Type (F_Typ)
3951 and then Has_Discriminants (Designated_Type (F_Typ))
3952 and then Is_Constrained (Designated_Type (F_Typ))
3953 then
3954 Apply_Discriminant_Check (A, F_Typ);
3956 else
3957 Apply_Range_Check (A, F_Typ);
3958 end if;
3960 -- Ada 2005 (AI-231): Note that the controlling parameter case
3961 -- already existed in Ada 95, which is partially checked
3962 -- elsewhere (see Checks), and we don't want the warning
3963 -- message to differ.
3965 if Is_Access_Type (F_Typ)
3966 and then Can_Never_Be_Null (F_Typ)
3967 and then Known_Null (A)
3968 then
3969 if Is_Controlling_Formal (F) then
3970 Apply_Compile_Time_Constraint_Error
3971 (N => A,
3972 Msg => "null value not allowed here?",
3973 Reason => CE_Access_Check_Failed);
3975 elsif Ada_Version >= Ada_2005 then
3976 Apply_Compile_Time_Constraint_Error
3977 (N => A,
3978 Msg => "(Ada 2005) null not allowed in "
3979 & "null-excluding formal?",
3980 Reason => CE_Null_Not_Allowed);
3981 end if;
3982 end if;
3983 end if;
3985 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter) then
3986 if Nkind (A) = N_Type_Conversion then
3987 if Is_Scalar_Type (A_Typ) then
3988 Apply_Scalar_Range_Check
3989 (Expression (A), Etype (Expression (A)), A_Typ);
3990 else
3991 Apply_Range_Check
3992 (Expression (A), Etype (Expression (A)), A_Typ);
3993 end if;
3995 else
3996 if Is_Scalar_Type (F_Typ) then
3997 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
3998 elsif Is_Array_Type (F_Typ)
3999 and then Ekind (F) = E_Out_Parameter
4000 then
4001 Apply_Length_Check (A, F_Typ);
4002 else
4003 Apply_Range_Check (A, A_Typ, F_Typ);
4004 end if;
4005 end if;
4006 end if;
4008 -- An actual associated with an access parameter is implicitly
4009 -- converted to the anonymous access type of the formal and must
4010 -- satisfy the legality checks for access conversions.
4012 if Ekind (F_Typ) = E_Anonymous_Access_Type then
4013 if not Valid_Conversion (A, F_Typ, A) then
4014 Error_Msg_N
4015 ("invalid implicit conversion for access parameter", A);
4016 end if;
4018 -- If the actual is an access selected component of a variable,
4019 -- the call may modify its designated object. It is reasonable
4020 -- to treat this as a potential modification of the enclosing
4021 -- record, to prevent spurious warnings that it should be
4022 -- declared as a constant, because intuitively programmers
4023 -- regard the designated subcomponent as part of the record.
4025 if Nkind (A) = N_Selected_Component
4026 and then Is_Entity_Name (Prefix (A))
4027 and then not Is_Constant_Object (Entity (Prefix (A)))
4028 then
4029 Note_Possible_Modification (A, Sure => False);
4030 end if;
4031 end if;
4033 -- Check bad case of atomic/volatile argument (RM C.6(12))
4035 if Is_By_Reference_Type (Etype (F))
4036 and then Comes_From_Source (N)
4037 then
4038 if Is_Atomic_Object (A)
4039 and then not Is_Atomic (Etype (F))
4040 then
4041 Error_Msg_NE
4042 ("cannot pass atomic argument to non-atomic formal&",
4043 A, F);
4045 elsif Is_Volatile_Object (A)
4046 and then not Is_Volatile (Etype (F))
4047 then
4048 Error_Msg_NE
4049 ("cannot pass volatile argument to non-volatile formal&",
4050 A, F);
4051 end if;
4052 end if;
4054 -- Check that subprograms don't have improper controlling
4055 -- arguments (RM 3.9.2 (9)).
4057 -- A primitive operation may have an access parameter of an
4058 -- incomplete tagged type, but a dispatching call is illegal
4059 -- if the type is still incomplete.
4061 if Is_Controlling_Formal (F) then
4062 Set_Is_Controlling_Actual (A);
4064 if Ekind (Etype (F)) = E_Anonymous_Access_Type then
4065 declare
4066 Desig : constant Entity_Id := Designated_Type (Etype (F));
4067 begin
4068 if Ekind (Desig) = E_Incomplete_Type
4069 and then No (Full_View (Desig))
4070 and then No (Non_Limited_View (Desig))
4071 then
4072 Error_Msg_NE
4073 ("premature use of incomplete type& " &
4074 "in dispatching call", A, Desig);
4075 end if;
4076 end;
4077 end if;
4079 elsif Nkind (A) = N_Explicit_Dereference then
4080 Validate_Remote_Access_To_Class_Wide_Type (A);
4081 end if;
4083 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
4084 and then not Is_Class_Wide_Type (F_Typ)
4085 and then not Is_Controlling_Formal (F)
4086 then
4087 Error_Msg_N ("class-wide argument not allowed here!", A);
4089 if Is_Subprogram (Nam)
4090 and then Comes_From_Source (Nam)
4091 then
4092 Error_Msg_Node_2 := F_Typ;
4093 Error_Msg_NE
4094 ("& is not a dispatching operation of &!", A, Nam);
4095 end if;
4097 -- Apply the checks described in 3.10.2(27): if the context is a
4098 -- specific access-to-object, the actual cannot be class-wide.
4099 -- Use base type to exclude access_to_subprogram cases.
4101 elsif Is_Access_Type (A_Typ)
4102 and then Is_Access_Type (F_Typ)
4103 and then not Is_Access_Subprogram_Type (Base_Type (F_Typ))
4104 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
4105 or else (Nkind (A) = N_Attribute_Reference
4106 and then
4107 Is_Class_Wide_Type (Etype (Prefix (A)))))
4108 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
4109 and then not Is_Controlling_Formal (F)
4111 -- Disable these checks for call to imported C++ subprograms
4113 and then not
4114 (Is_Entity_Name (Name (N))
4115 and then Is_Imported (Entity (Name (N)))
4116 and then Convention (Entity (Name (N))) = Convention_CPP)
4117 then
4118 Error_Msg_N
4119 ("access to class-wide argument not allowed here!", A);
4121 if Is_Subprogram (Nam) and then Comes_From_Source (Nam) then
4122 Error_Msg_Node_2 := Designated_Type (F_Typ);
4123 Error_Msg_NE
4124 ("& is not a dispatching operation of &!", A, Nam);
4125 end if;
4126 end if;
4128 Eval_Actual (A);
4130 -- If it is a named association, treat the selector_name as a
4131 -- proper identifier, and mark the corresponding entity. Ignore
4132 -- this reference in Alfa mode, as it refers to an entity not in
4133 -- scope at the point of reference, so the reference should be
4134 -- ignored for computing effects of subprograms.
4136 if Nkind (Parent (A)) = N_Parameter_Association
4137 and then not Alfa_Mode
4138 then
4139 Set_Entity (Selector_Name (Parent (A)), F);
4140 Generate_Reference (F, Selector_Name (Parent (A)));
4141 Set_Etype (Selector_Name (Parent (A)), F_Typ);
4142 Generate_Reference (F_Typ, N, ' ');
4143 end if;
4145 Prev := A;
4147 if Ekind (F) /= E_Out_Parameter then
4148 Check_Unset_Reference (A);
4149 end if;
4151 Next_Actual (A);
4153 -- Case where actual is not present
4155 else
4156 Insert_Default;
4157 end if;
4159 Next_Formal (F);
4160 end loop;
4161 end Resolve_Actuals;
4163 -----------------------
4164 -- Resolve_Allocator --
4165 -----------------------
4167 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
4168 Desig_T : constant Entity_Id := Designated_Type (Typ);
4169 E : constant Node_Id := Expression (N);
4170 Subtyp : Entity_Id;
4171 Discrim : Entity_Id;
4172 Constr : Node_Id;
4173 Aggr : Node_Id;
4174 Assoc : Node_Id := Empty;
4175 Disc_Exp : Node_Id;
4177 procedure Check_Allocator_Discrim_Accessibility
4178 (Disc_Exp : Node_Id;
4179 Alloc_Typ : Entity_Id);
4180 -- Check that accessibility level associated with an access discriminant
4181 -- initialized in an allocator by the expression Disc_Exp is not deeper
4182 -- than the level of the allocator type Alloc_Typ. An error message is
4183 -- issued if this condition is violated. Specialized checks are done for
4184 -- the cases of a constraint expression which is an access attribute or
4185 -- an access discriminant.
4187 function In_Dispatching_Context return Boolean;
4188 -- If the allocator is an actual in a call, it is allowed to be class-
4189 -- wide when the context is not because it is a controlling actual.
4191 -------------------------------------------
4192 -- Check_Allocator_Discrim_Accessibility --
4193 -------------------------------------------
4195 procedure Check_Allocator_Discrim_Accessibility
4196 (Disc_Exp : Node_Id;
4197 Alloc_Typ : Entity_Id)
4199 begin
4200 if Type_Access_Level (Etype (Disc_Exp)) >
4201 Deepest_Type_Access_Level (Alloc_Typ)
4202 then
4203 Error_Msg_N
4204 ("operand type has deeper level than allocator type", Disc_Exp);
4206 -- When the expression is an Access attribute the level of the prefix
4207 -- object must not be deeper than that of the allocator's type.
4209 elsif Nkind (Disc_Exp) = N_Attribute_Reference
4210 and then Get_Attribute_Id (Attribute_Name (Disc_Exp)) =
4211 Attribute_Access
4212 and then Object_Access_Level (Prefix (Disc_Exp)) >
4213 Deepest_Type_Access_Level (Alloc_Typ)
4214 then
4215 Error_Msg_N
4216 ("prefix of attribute has deeper level than allocator type",
4217 Disc_Exp);
4219 -- When the expression is an access discriminant the check is against
4220 -- the level of the prefix object.
4222 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
4223 and then Nkind (Disc_Exp) = N_Selected_Component
4224 and then Object_Access_Level (Prefix (Disc_Exp)) >
4225 Deepest_Type_Access_Level (Alloc_Typ)
4226 then
4227 Error_Msg_N
4228 ("access discriminant has deeper level than allocator type",
4229 Disc_Exp);
4231 -- All other cases are legal
4233 else
4234 null;
4235 end if;
4236 end Check_Allocator_Discrim_Accessibility;
4238 ----------------------------
4239 -- In_Dispatching_Context --
4240 ----------------------------
4242 function In_Dispatching_Context return Boolean is
4243 Par : constant Node_Id := Parent (N);
4245 begin
4246 return Nkind (Par) in N_Subprogram_Call
4247 and then Is_Entity_Name (Name (Par))
4248 and then Is_Dispatching_Operation (Entity (Name (Par)));
4249 end In_Dispatching_Context;
4251 -- Start of processing for Resolve_Allocator
4253 begin
4254 -- Replace general access with specific type
4256 if Ekind (Etype (N)) = E_Allocator_Type then
4257 Set_Etype (N, Base_Type (Typ));
4258 end if;
4260 if Is_Abstract_Type (Typ) then
4261 Error_Msg_N ("type of allocator cannot be abstract", N);
4262 end if;
4264 -- For qualified expression, resolve the expression using the
4265 -- given subtype (nothing to do for type mark, subtype indication)
4267 if Nkind (E) = N_Qualified_Expression then
4268 if Is_Class_Wide_Type (Etype (E))
4269 and then not Is_Class_Wide_Type (Desig_T)
4270 and then not In_Dispatching_Context
4271 then
4272 Error_Msg_N
4273 ("class-wide allocator not allowed for this access type", N);
4274 end if;
4276 Resolve (Expression (E), Etype (E));
4277 Check_Unset_Reference (Expression (E));
4279 -- A qualified expression requires an exact match of the type,
4280 -- class-wide matching is not allowed.
4282 if (Is_Class_Wide_Type (Etype (Expression (E)))
4283 or else Is_Class_Wide_Type (Etype (E)))
4284 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
4285 then
4286 Wrong_Type (Expression (E), Etype (E));
4287 end if;
4289 -- Calls to build-in-place functions are not currently supported in
4290 -- allocators for access types associated with a simple storage pool.
4291 -- Supporting such allocators may require passing additional implicit
4292 -- parameters to build-in-place functions (or a significant revision
4293 -- of the current b-i-p implementation to unify the handling for
4294 -- multiple kinds of storage pools). ???
4296 if Is_Immutably_Limited_Type (Desig_T)
4297 and then Nkind (Expression (E)) = N_Function_Call
4298 then
4299 declare
4300 Pool : constant Entity_Id :=
4301 Associated_Storage_Pool (Root_Type (Typ));
4302 begin
4303 if Present (Pool)
4304 and then
4305 Present (Get_Rep_Pragma
4306 (Etype (Pool), Name_Simple_Storage_Pool_Type))
4307 then
4308 Error_Msg_N
4309 ("limited function calls not yet supported in simple " &
4310 "storage pool allocators", Expression (E));
4311 end if;
4312 end;
4313 end if;
4315 -- A special accessibility check is needed for allocators that
4316 -- constrain access discriminants. The level of the type of the
4317 -- expression used to constrain an access discriminant cannot be
4318 -- deeper than the type of the allocator (in contrast to access
4319 -- parameters, where the level of the actual can be arbitrary).
4321 -- We can't use Valid_Conversion to perform this check because
4322 -- in general the type of the allocator is unrelated to the type
4323 -- of the access discriminant.
4325 if Ekind (Typ) /= E_Anonymous_Access_Type
4326 or else Is_Local_Anonymous_Access (Typ)
4327 then
4328 Subtyp := Entity (Subtype_Mark (E));
4330 Aggr := Original_Node (Expression (E));
4332 if Has_Discriminants (Subtyp)
4333 and then Nkind_In (Aggr, N_Aggregate, N_Extension_Aggregate)
4334 then
4335 Discrim := First_Discriminant (Base_Type (Subtyp));
4337 -- Get the first component expression of the aggregate
4339 if Present (Expressions (Aggr)) then
4340 Disc_Exp := First (Expressions (Aggr));
4342 elsif Present (Component_Associations (Aggr)) then
4343 Assoc := First (Component_Associations (Aggr));
4345 if Present (Assoc) then
4346 Disc_Exp := Expression (Assoc);
4347 else
4348 Disc_Exp := Empty;
4349 end if;
4351 else
4352 Disc_Exp := Empty;
4353 end if;
4355 while Present (Discrim) and then Present (Disc_Exp) loop
4356 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4357 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4358 end if;
4360 Next_Discriminant (Discrim);
4362 if Present (Discrim) then
4363 if Present (Assoc) then
4364 Next (Assoc);
4365 Disc_Exp := Expression (Assoc);
4367 elsif Present (Next (Disc_Exp)) then
4368 Next (Disc_Exp);
4370 else
4371 Assoc := First (Component_Associations (Aggr));
4373 if Present (Assoc) then
4374 Disc_Exp := Expression (Assoc);
4375 else
4376 Disc_Exp := Empty;
4377 end if;
4378 end if;
4379 end if;
4380 end loop;
4381 end if;
4382 end if;
4384 -- For a subtype mark or subtype indication, freeze the subtype
4386 else
4387 Freeze_Expression (E);
4389 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
4390 Error_Msg_N
4391 ("initialization required for access-to-constant allocator", N);
4392 end if;
4394 -- A special accessibility check is needed for allocators that
4395 -- constrain access discriminants. The level of the type of the
4396 -- expression used to constrain an access discriminant cannot be
4397 -- deeper than the type of the allocator (in contrast to access
4398 -- parameters, where the level of the actual can be arbitrary).
4399 -- We can't use Valid_Conversion to perform this check because
4400 -- in general the type of the allocator is unrelated to the type
4401 -- of the access discriminant.
4403 if Nkind (Original_Node (E)) = N_Subtype_Indication
4404 and then (Ekind (Typ) /= E_Anonymous_Access_Type
4405 or else Is_Local_Anonymous_Access (Typ))
4406 then
4407 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
4409 if Has_Discriminants (Subtyp) then
4410 Discrim := First_Discriminant (Base_Type (Subtyp));
4411 Constr := First (Constraints (Constraint (Original_Node (E))));
4412 while Present (Discrim) and then Present (Constr) loop
4413 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
4414 if Nkind (Constr) = N_Discriminant_Association then
4415 Disc_Exp := Original_Node (Expression (Constr));
4416 else
4417 Disc_Exp := Original_Node (Constr);
4418 end if;
4420 Check_Allocator_Discrim_Accessibility (Disc_Exp, Typ);
4421 end if;
4423 Next_Discriminant (Discrim);
4424 Next (Constr);
4425 end loop;
4426 end if;
4427 end if;
4428 end if;
4430 -- Ada 2005 (AI-344): A class-wide allocator requires an accessibility
4431 -- check that the level of the type of the created object is not deeper
4432 -- than the level of the allocator's access type, since extensions can
4433 -- now occur at deeper levels than their ancestor types. This is a
4434 -- static accessibility level check; a run-time check is also needed in
4435 -- the case of an initialized allocator with a class-wide argument (see
4436 -- Expand_Allocator_Expression).
4438 if Ada_Version >= Ada_2005
4439 and then Is_Class_Wide_Type (Desig_T)
4440 then
4441 declare
4442 Exp_Typ : Entity_Id;
4444 begin
4445 if Nkind (E) = N_Qualified_Expression then
4446 Exp_Typ := Etype (E);
4447 elsif Nkind (E) = N_Subtype_Indication then
4448 Exp_Typ := Entity (Subtype_Mark (Original_Node (E)));
4449 else
4450 Exp_Typ := Entity (E);
4451 end if;
4453 if Type_Access_Level (Exp_Typ) >
4454 Deepest_Type_Access_Level (Typ)
4455 then
4456 if In_Instance_Body then
4457 Error_Msg_N ("?type in allocator has deeper level than" &
4458 " designated class-wide type", E);
4459 Error_Msg_N ("\?Program_Error will be raised at run time",
4461 Rewrite (N,
4462 Make_Raise_Program_Error (Sloc (N),
4463 Reason => PE_Accessibility_Check_Failed));
4464 Set_Etype (N, Typ);
4466 -- Do not apply Ada 2005 accessibility checks on a class-wide
4467 -- allocator if the type given in the allocator is a formal
4468 -- type. A run-time check will be performed in the instance.
4470 elsif not Is_Generic_Type (Exp_Typ) then
4471 Error_Msg_N ("type in allocator has deeper level than" &
4472 " designated class-wide type", E);
4473 end if;
4474 end if;
4475 end;
4476 end if;
4478 -- Check for allocation from an empty storage pool
4480 if No_Pool_Assigned (Typ) then
4481 Error_Msg_N ("allocation from empty storage pool!", N);
4483 -- If the context is an unchecked conversion, as may happen within an
4484 -- inlined subprogram, the allocator is being resolved with its own
4485 -- anonymous type. In that case, if the target type has a specific
4486 -- storage pool, it must be inherited explicitly by the allocator type.
4488 elsif Nkind (Parent (N)) = N_Unchecked_Type_Conversion
4489 and then No (Associated_Storage_Pool (Typ))
4490 then
4491 Set_Associated_Storage_Pool
4492 (Typ, Associated_Storage_Pool (Etype (Parent (N))));
4493 end if;
4495 if Ekind (Etype (N)) = E_Anonymous_Access_Type then
4496 Check_Restriction (No_Anonymous_Allocators, N);
4497 end if;
4499 -- Check that an allocator with task parts isn't for a nested access
4500 -- type when restriction No_Task_Hierarchy applies.
4502 if not Is_Library_Level_Entity (Base_Type (Typ))
4503 and then Has_Task (Base_Type (Desig_T))
4504 then
4505 Check_Restriction (No_Task_Hierarchy, N);
4506 end if;
4508 -- An erroneous allocator may be rewritten as a raise Program_Error
4509 -- statement.
4511 if Nkind (N) = N_Allocator then
4513 -- An anonymous access discriminant is the definition of a
4514 -- coextension.
4516 if Ekind (Typ) = E_Anonymous_Access_Type
4517 and then Nkind (Associated_Node_For_Itype (Typ)) =
4518 N_Discriminant_Specification
4519 then
4520 declare
4521 Discr : constant Entity_Id :=
4522 Defining_Identifier (Associated_Node_For_Itype (Typ));
4524 begin
4525 -- Ada 2012 AI05-0052: If the designated type of the allocator
4526 -- is limited, then the allocator shall not be used to define
4527 -- the value of an access discriminant unless the discriminated
4528 -- type is immutably limited.
4530 if Ada_Version >= Ada_2012
4531 and then Is_Limited_Type (Desig_T)
4532 and then not Is_Immutably_Limited_Type (Scope (Discr))
4533 then
4534 Error_Msg_N
4535 ("only immutably limited types can have anonymous "
4536 & "access discriminants designating a limited type", N);
4537 end if;
4538 end;
4540 -- Avoid marking an allocator as a dynamic coextension if it is
4541 -- within a static construct.
4543 if not Is_Static_Coextension (N) then
4544 Set_Is_Dynamic_Coextension (N);
4545 end if;
4547 -- Cleanup for potential static coextensions
4549 else
4550 Set_Is_Dynamic_Coextension (N, False);
4551 Set_Is_Static_Coextension (N, False);
4552 end if;
4553 end if;
4555 -- Report a simple error: if the designated object is a local task,
4556 -- its body has not been seen yet, and its activation will fail an
4557 -- elaboration check.
4559 if Is_Task_Type (Desig_T)
4560 and then Scope (Base_Type (Desig_T)) = Current_Scope
4561 and then Is_Compilation_Unit (Current_Scope)
4562 and then Ekind (Current_Scope) = E_Package
4563 and then not In_Package_Body (Current_Scope)
4564 then
4565 Error_Msg_N ("?cannot activate task before body seen", N);
4566 Error_Msg_N ("\?Program_Error will be raised at run time", N);
4567 end if;
4569 -- Ada 2012 (AI05-0111-3): Detect an attempt to allocate a task or a
4570 -- type with a task component on a subpool. This action must raise
4571 -- Program_Error at runtime.
4573 if Ada_Version >= Ada_2012
4574 and then Nkind (N) = N_Allocator
4575 and then Present (Subpool_Handle_Name (N))
4576 and then Has_Task (Desig_T)
4577 then
4578 Error_Msg_N ("?cannot allocate task on subpool", N);
4579 Error_Msg_N ("\?Program_Error will be raised at run time", N);
4581 Rewrite (N,
4582 Make_Raise_Program_Error (Sloc (N),
4583 Reason => PE_Explicit_Raise));
4584 Set_Etype (N, Typ);
4585 end if;
4586 end Resolve_Allocator;
4588 ---------------------------
4589 -- Resolve_Arithmetic_Op --
4590 ---------------------------
4592 -- Used for resolving all arithmetic operators except exponentiation
4594 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
4595 L : constant Node_Id := Left_Opnd (N);
4596 R : constant Node_Id := Right_Opnd (N);
4597 TL : constant Entity_Id := Base_Type (Etype (L));
4598 TR : constant Entity_Id := Base_Type (Etype (R));
4599 T : Entity_Id;
4600 Rop : Node_Id;
4602 B_Typ : constant Entity_Id := Base_Type (Typ);
4603 -- We do the resolution using the base type, because intermediate values
4604 -- in expressions always are of the base type, not a subtype of it.
4606 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean;
4607 -- Returns True if N is in a context that expects "any real type"
4609 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
4610 -- Return True iff given type is Integer or universal real/integer
4612 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
4613 -- Choose type of integer literal in fixed-point operation to conform
4614 -- to available fixed-point type. T is the type of the other operand,
4615 -- which is needed to determine the expected type of N.
4617 procedure Set_Operand_Type (N : Node_Id);
4618 -- Set operand type to T if universal
4620 -------------------------------
4621 -- Expected_Type_Is_Any_Real --
4622 -------------------------------
4624 function Expected_Type_Is_Any_Real (N : Node_Id) return Boolean is
4625 begin
4626 -- N is the expression after "delta" in a fixed_point_definition;
4627 -- see RM-3.5.9(6):
4629 return Nkind_In (Parent (N), N_Ordinary_Fixed_Point_Definition,
4630 N_Decimal_Fixed_Point_Definition,
4632 -- N is one of the bounds in a real_range_specification;
4633 -- see RM-3.5.7(5):
4635 N_Real_Range_Specification,
4637 -- N is the expression of a delta_constraint;
4638 -- see RM-J.3(3):
4640 N_Delta_Constraint);
4641 end Expected_Type_Is_Any_Real;
4643 -----------------------------
4644 -- Is_Integer_Or_Universal --
4645 -----------------------------
4647 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
4648 T : Entity_Id;
4649 Index : Interp_Index;
4650 It : Interp;
4652 begin
4653 if not Is_Overloaded (N) then
4654 T := Etype (N);
4655 return Base_Type (T) = Base_Type (Standard_Integer)
4656 or else T = Universal_Integer
4657 or else T = Universal_Real;
4658 else
4659 Get_First_Interp (N, Index, It);
4660 while Present (It.Typ) loop
4661 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
4662 or else It.Typ = Universal_Integer
4663 or else It.Typ = Universal_Real
4664 then
4665 return True;
4666 end if;
4668 Get_Next_Interp (Index, It);
4669 end loop;
4670 end if;
4672 return False;
4673 end Is_Integer_Or_Universal;
4675 ----------------------------
4676 -- Set_Mixed_Mode_Operand --
4677 ----------------------------
4679 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
4680 Index : Interp_Index;
4681 It : Interp;
4683 begin
4684 if Universal_Interpretation (N) = Universal_Integer then
4686 -- A universal integer literal is resolved as standard integer
4687 -- except in the case of a fixed-point result, where we leave it
4688 -- as universal (to be handled by Exp_Fixd later on)
4690 if Is_Fixed_Point_Type (T) then
4691 Resolve (N, Universal_Integer);
4692 else
4693 Resolve (N, Standard_Integer);
4694 end if;
4696 elsif Universal_Interpretation (N) = Universal_Real
4697 and then (T = Base_Type (Standard_Integer)
4698 or else T = Universal_Integer
4699 or else T = Universal_Real)
4700 then
4701 -- A universal real can appear in a fixed-type context. We resolve
4702 -- the literal with that context, even though this might raise an
4703 -- exception prematurely (the other operand may be zero).
4705 Resolve (N, B_Typ);
4707 elsif Etype (N) = Base_Type (Standard_Integer)
4708 and then T = Universal_Real
4709 and then Is_Overloaded (N)
4710 then
4711 -- Integer arg in mixed-mode operation. Resolve with universal
4712 -- type, in case preference rule must be applied.
4714 Resolve (N, Universal_Integer);
4716 elsif Etype (N) = T
4717 and then B_Typ /= Universal_Fixed
4718 then
4719 -- Not a mixed-mode operation, resolve with context
4721 Resolve (N, B_Typ);
4723 elsif Etype (N) = Any_Fixed then
4725 -- N may itself be a mixed-mode operation, so use context type
4727 Resolve (N, B_Typ);
4729 elsif Is_Fixed_Point_Type (T)
4730 and then B_Typ = Universal_Fixed
4731 and then Is_Overloaded (N)
4732 then
4733 -- Must be (fixed * fixed) operation, operand must have one
4734 -- compatible interpretation.
4736 Resolve (N, Any_Fixed);
4738 elsif Is_Fixed_Point_Type (B_Typ)
4739 and then (T = Universal_Real
4740 or else Is_Fixed_Point_Type (T))
4741 and then Is_Overloaded (N)
4742 then
4743 -- C * F(X) in a fixed context, where C is a real literal or a
4744 -- fixed-point expression. F must have either a fixed type
4745 -- interpretation or an integer interpretation, but not both.
4747 Get_First_Interp (N, Index, It);
4748 while Present (It.Typ) loop
4749 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
4750 if Analyzed (N) then
4751 Error_Msg_N ("ambiguous operand in fixed operation", N);
4752 else
4753 Resolve (N, Standard_Integer);
4754 end if;
4756 elsif Is_Fixed_Point_Type (It.Typ) then
4757 if Analyzed (N) then
4758 Error_Msg_N ("ambiguous operand in fixed operation", N);
4759 else
4760 Resolve (N, It.Typ);
4761 end if;
4762 end if;
4764 Get_Next_Interp (Index, It);
4765 end loop;
4767 -- Reanalyze the literal with the fixed type of the context. If
4768 -- context is Universal_Fixed, we are within a conversion, leave
4769 -- the literal as a universal real because there is no usable
4770 -- fixed type, and the target of the conversion plays no role in
4771 -- the resolution.
4773 declare
4774 Op2 : Node_Id;
4775 T2 : Entity_Id;
4777 begin
4778 if N = L then
4779 Op2 := R;
4780 else
4781 Op2 := L;
4782 end if;
4784 if B_Typ = Universal_Fixed
4785 and then Nkind (Op2) = N_Real_Literal
4786 then
4787 T2 := Universal_Real;
4788 else
4789 T2 := B_Typ;
4790 end if;
4792 Set_Analyzed (Op2, False);
4793 Resolve (Op2, T2);
4794 end;
4796 else
4797 Resolve (N);
4798 end if;
4799 end Set_Mixed_Mode_Operand;
4801 ----------------------
4802 -- Set_Operand_Type --
4803 ----------------------
4805 procedure Set_Operand_Type (N : Node_Id) is
4806 begin
4807 if Etype (N) = Universal_Integer
4808 or else Etype (N) = Universal_Real
4809 then
4810 Set_Etype (N, T);
4811 end if;
4812 end Set_Operand_Type;
4814 -- Start of processing for Resolve_Arithmetic_Op
4816 begin
4817 if Comes_From_Source (N)
4818 and then Ekind (Entity (N)) = E_Function
4819 and then Is_Imported (Entity (N))
4820 and then Is_Intrinsic_Subprogram (Entity (N))
4821 then
4822 Resolve_Intrinsic_Operator (N, Typ);
4823 return;
4825 -- Special-case for mixed-mode universal expressions or fixed point type
4826 -- operation: each argument is resolved separately. The same treatment
4827 -- is required if one of the operands of a fixed point operation is
4828 -- universal real, since in this case we don't do a conversion to a
4829 -- specific fixed-point type (instead the expander handles the case).
4831 -- Set the type of the node to its universal interpretation because
4832 -- legality checks on an exponentiation operand need the context.
4834 elsif (B_Typ = Universal_Integer or else B_Typ = Universal_Real)
4835 and then Present (Universal_Interpretation (L))
4836 and then Present (Universal_Interpretation (R))
4837 then
4838 Set_Etype (N, B_Typ);
4839 Resolve (L, Universal_Interpretation (L));
4840 Resolve (R, Universal_Interpretation (R));
4842 elsif (B_Typ = Universal_Real
4843 or else Etype (N) = Universal_Fixed
4844 or else (Etype (N) = Any_Fixed
4845 and then Is_Fixed_Point_Type (B_Typ))
4846 or else (Is_Fixed_Point_Type (B_Typ)
4847 and then (Is_Integer_Or_Universal (L)
4848 or else
4849 Is_Integer_Or_Universal (R))))
4850 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4851 then
4852 if TL = Universal_Integer or else TR = Universal_Integer then
4853 Check_For_Visible_Operator (N, B_Typ);
4854 end if;
4856 -- If context is a fixed type and one operand is integer, the other
4857 -- is resolved with the type of the context.
4859 if Is_Fixed_Point_Type (B_Typ)
4860 and then (Base_Type (TL) = Base_Type (Standard_Integer)
4861 or else TL = Universal_Integer)
4862 then
4863 Resolve (R, B_Typ);
4864 Resolve (L, TL);
4866 elsif Is_Fixed_Point_Type (B_Typ)
4867 and then (Base_Type (TR) = Base_Type (Standard_Integer)
4868 or else TR = Universal_Integer)
4869 then
4870 Resolve (L, B_Typ);
4871 Resolve (R, TR);
4873 else
4874 Set_Mixed_Mode_Operand (L, TR);
4875 Set_Mixed_Mode_Operand (R, TL);
4876 end if;
4878 -- Check the rule in RM05-4.5.5(19.1/2) disallowing universal_fixed
4879 -- multiplying operators from being used when the expected type is
4880 -- also universal_fixed. Note that B_Typ will be Universal_Fixed in
4881 -- some cases where the expected type is actually Any_Real;
4882 -- Expected_Type_Is_Any_Real takes care of that case.
4884 if Etype (N) = Universal_Fixed
4885 or else Etype (N) = Any_Fixed
4886 then
4887 if B_Typ = Universal_Fixed
4888 and then not Expected_Type_Is_Any_Real (N)
4889 and then not Nkind_In (Parent (N), N_Type_Conversion,
4890 N_Unchecked_Type_Conversion)
4891 then
4892 Error_Msg_N ("type cannot be determined from context!", N);
4893 Error_Msg_N ("\explicit conversion to result type required", N);
4895 Set_Etype (L, Any_Type);
4896 Set_Etype (R, Any_Type);
4898 else
4899 if Ada_Version = Ada_83
4900 and then Etype (N) = Universal_Fixed
4901 and then not
4902 Nkind_In (Parent (N), N_Type_Conversion,
4903 N_Unchecked_Type_Conversion)
4904 then
4905 Error_Msg_N
4906 ("(Ada 83) fixed-point operation "
4907 & "needs explicit conversion", N);
4908 end if;
4910 -- The expected type is "any real type" in contexts like
4912 -- type T is delta <universal_fixed-expression> ...
4914 -- in which case we need to set the type to Universal_Real
4915 -- so that static expression evaluation will work properly.
4917 if Expected_Type_Is_Any_Real (N) then
4918 Set_Etype (N, Universal_Real);
4919 else
4920 Set_Etype (N, B_Typ);
4921 end if;
4922 end if;
4924 elsif Is_Fixed_Point_Type (B_Typ)
4925 and then (Is_Integer_Or_Universal (L)
4926 or else Nkind (L) = N_Real_Literal
4927 or else Nkind (R) = N_Real_Literal
4928 or else Is_Integer_Or_Universal (R))
4929 then
4930 Set_Etype (N, B_Typ);
4932 elsif Etype (N) = Any_Fixed then
4934 -- If no previous errors, this is only possible if one operand is
4935 -- overloaded and the context is universal. Resolve as such.
4937 Set_Etype (N, B_Typ);
4938 end if;
4940 else
4941 if (TL = Universal_Integer or else TL = Universal_Real)
4942 and then
4943 (TR = Universal_Integer or else TR = Universal_Real)
4944 then
4945 Check_For_Visible_Operator (N, B_Typ);
4946 end if;
4948 -- If the context is Universal_Fixed and the operands are also
4949 -- universal fixed, this is an error, unless there is only one
4950 -- applicable fixed_point type (usually Duration).
4952 if B_Typ = Universal_Fixed and then Etype (L) = Universal_Fixed then
4953 T := Unique_Fixed_Point_Type (N);
4955 if T = Any_Type then
4956 Set_Etype (N, T);
4957 return;
4958 else
4959 Resolve (L, T);
4960 Resolve (R, T);
4961 end if;
4963 else
4964 Resolve (L, B_Typ);
4965 Resolve (R, B_Typ);
4966 end if;
4968 -- If one of the arguments was resolved to a non-universal type.
4969 -- label the result of the operation itself with the same type.
4970 -- Do the same for the universal argument, if any.
4972 T := Intersect_Types (L, R);
4973 Set_Etype (N, Base_Type (T));
4974 Set_Operand_Type (L);
4975 Set_Operand_Type (R);
4976 end if;
4978 Generate_Operator_Reference (N, Typ);
4979 Analyze_Dimension (N);
4980 Eval_Arithmetic_Op (N);
4982 -- In SPARK, a multiplication or division with operands of fixed point
4983 -- types shall be qualified or explicitly converted to identify the
4984 -- result type.
4986 if (Is_Fixed_Point_Type (Etype (L))
4987 or else Is_Fixed_Point_Type (Etype (R)))
4988 and then Nkind_In (N, N_Op_Multiply, N_Op_Divide)
4989 and then
4990 not Nkind_In (Parent (N), N_Qualified_Expression, N_Type_Conversion)
4991 then
4992 Check_SPARK_Restriction
4993 ("operation should be qualified or explicitly converted", N);
4994 end if;
4996 -- Set overflow and division checking bit
4998 if Nkind (N) in N_Op then
4999 if not Overflow_Checks_Suppressed (Etype (N)) then
5000 Enable_Overflow_Check (N);
5001 end if;
5003 -- Give warning if explicit division by zero
5005 if Nkind_In (N, N_Op_Divide, N_Op_Rem, N_Op_Mod)
5006 and then not Division_Checks_Suppressed (Etype (N))
5007 then
5008 Rop := Right_Opnd (N);
5010 if Compile_Time_Known_Value (Rop)
5011 and then ((Is_Integer_Type (Etype (Rop))
5012 and then Expr_Value (Rop) = Uint_0)
5013 or else
5014 (Is_Real_Type (Etype (Rop))
5015 and then Expr_Value_R (Rop) = Ureal_0))
5016 then
5017 -- Specialize the warning message according to the operation.
5018 -- The following warnings are for the case
5020 case Nkind (N) is
5021 when N_Op_Divide =>
5023 -- For division, we have two cases, for float division
5024 -- of an unconstrained float type, on a machine where
5025 -- Machine_Overflows is false, we don't get an exception
5026 -- at run-time, but rather an infinity or Nan. The Nan
5027 -- case is pretty obscure, so just warn about infinities.
5029 if Is_Floating_Point_Type (Typ)
5030 and then not Is_Constrained (Typ)
5031 and then not Machine_Overflows_On_Target
5032 then
5033 Error_Msg_N
5034 ("float division by zero, " &
5035 "may generate '+'/'- infinity?", Right_Opnd (N));
5037 -- For all other cases, we get a Constraint_Error
5039 else
5040 Apply_Compile_Time_Constraint_Error
5041 (N, "division by zero?", CE_Divide_By_Zero,
5042 Loc => Sloc (Right_Opnd (N)));
5043 end if;
5045 when N_Op_Rem =>
5046 Apply_Compile_Time_Constraint_Error
5047 (N, "rem with zero divisor?", CE_Divide_By_Zero,
5048 Loc => Sloc (Right_Opnd (N)));
5050 when N_Op_Mod =>
5051 Apply_Compile_Time_Constraint_Error
5052 (N, "mod with zero divisor?", CE_Divide_By_Zero,
5053 Loc => Sloc (Right_Opnd (N)));
5055 -- Division by zero can only happen with division, rem,
5056 -- and mod operations.
5058 when others =>
5059 raise Program_Error;
5060 end case;
5062 -- Otherwise just set the flag to check at run time
5064 else
5065 Activate_Division_Check (N);
5066 end if;
5067 end if;
5069 -- If Restriction No_Implicit_Conditionals is active, then it is
5070 -- violated if either operand can be negative for mod, or for rem
5071 -- if both operands can be negative.
5073 if Restriction_Check_Required (No_Implicit_Conditionals)
5074 and then Nkind_In (N, N_Op_Rem, N_Op_Mod)
5075 then
5076 declare
5077 Lo : Uint;
5078 Hi : Uint;
5079 OK : Boolean;
5081 LNeg : Boolean;
5082 RNeg : Boolean;
5083 -- Set if corresponding operand might be negative
5085 begin
5086 Determine_Range
5087 (Left_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
5088 LNeg := (not OK) or else Lo < 0;
5090 Determine_Range
5091 (Right_Opnd (N), OK, Lo, Hi, Assume_Valid => True);
5092 RNeg := (not OK) or else Lo < 0;
5094 -- Check if we will be generating conditionals. There are two
5095 -- cases where that can happen, first for REM, the only case
5096 -- is largest negative integer mod -1, where the division can
5097 -- overflow, but we still have to give the right result. The
5098 -- front end generates a test for this annoying case. Here we
5099 -- just test if both operands can be negative (that's what the
5100 -- expander does, so we match its logic here).
5102 -- The second case is mod where either operand can be negative.
5103 -- In this case, the back end has to generate additional tests.
5105 if (Nkind (N) = N_Op_Rem and then (LNeg and RNeg))
5106 or else
5107 (Nkind (N) = N_Op_Mod and then (LNeg or RNeg))
5108 then
5109 Check_Restriction (No_Implicit_Conditionals, N);
5110 end if;
5111 end;
5112 end if;
5113 end if;
5115 Check_Unset_Reference (L);
5116 Check_Unset_Reference (R);
5117 end Resolve_Arithmetic_Op;
5119 ------------------
5120 -- Resolve_Call --
5121 ------------------
5123 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
5124 Loc : constant Source_Ptr := Sloc (N);
5125 Subp : constant Node_Id := Name (N);
5126 Nam : Entity_Id;
5127 I : Interp_Index;
5128 It : Interp;
5129 Norm_OK : Boolean;
5130 Scop : Entity_Id;
5131 Rtype : Entity_Id;
5133 function Same_Or_Aliased_Subprograms
5134 (S : Entity_Id;
5135 E : Entity_Id) return Boolean;
5136 -- Returns True if the subprogram entity S is the same as E or else
5137 -- S is an alias of E.
5139 ---------------------------------
5140 -- Same_Or_Aliased_Subprograms --
5141 ---------------------------------
5143 function Same_Or_Aliased_Subprograms
5144 (S : Entity_Id;
5145 E : Entity_Id) return Boolean
5147 Subp_Alias : constant Entity_Id := Alias (S);
5148 begin
5149 return S = E
5150 or else (Present (Subp_Alias) and then Subp_Alias = E);
5151 end Same_Or_Aliased_Subprograms;
5153 -- Start of processing for Resolve_Call
5155 begin
5156 -- The context imposes a unique interpretation with type Typ on a
5157 -- procedure or function call. Find the entity of the subprogram that
5158 -- yields the expected type, and propagate the corresponding formal
5159 -- constraints on the actuals. The caller has established that an
5160 -- interpretation exists, and emitted an error if not unique.
5162 -- First deal with the case of a call to an access-to-subprogram,
5163 -- dereference made explicit in Analyze_Call.
5165 if Ekind (Etype (Subp)) = E_Subprogram_Type then
5166 if not Is_Overloaded (Subp) then
5167 Nam := Etype (Subp);
5169 else
5170 -- Find the interpretation whose type (a subprogram type) has a
5171 -- return type that is compatible with the context. Analysis of
5172 -- the node has established that one exists.
5174 Nam := Empty;
5176 Get_First_Interp (Subp, I, It);
5177 while Present (It.Typ) loop
5178 if Covers (Typ, Etype (It.Typ)) then
5179 Nam := It.Typ;
5180 exit;
5181 end if;
5183 Get_Next_Interp (I, It);
5184 end loop;
5186 if No (Nam) then
5187 raise Program_Error;
5188 end if;
5189 end if;
5191 -- If the prefix is not an entity, then resolve it
5193 if not Is_Entity_Name (Subp) then
5194 Resolve (Subp, Nam);
5195 end if;
5197 -- For an indirect call, we always invalidate checks, since we do not
5198 -- know whether the subprogram is local or global. Yes we could do
5199 -- better here, e.g. by knowing that there are no local subprograms,
5200 -- but it does not seem worth the effort. Similarly, we kill all
5201 -- knowledge of current constant values.
5203 Kill_Current_Values;
5205 -- If this is a procedure call which is really an entry call, do
5206 -- the conversion of the procedure call to an entry call. Protected
5207 -- operations use the same circuitry because the name in the call
5208 -- can be an arbitrary expression with special resolution rules.
5210 elsif Nkind_In (Subp, N_Selected_Component, N_Indexed_Component)
5211 or else (Is_Entity_Name (Subp)
5212 and then Ekind (Entity (Subp)) = E_Entry)
5213 then
5214 Resolve_Entry_Call (N, Typ);
5215 Check_Elab_Call (N);
5217 -- Kill checks and constant values, as above for indirect case
5218 -- Who knows what happens when another task is activated?
5220 Kill_Current_Values;
5221 return;
5223 -- Normal subprogram call with name established in Resolve
5225 elsif not (Is_Type (Entity (Subp))) then
5226 Nam := Entity (Subp);
5227 Set_Entity_With_Style_Check (Subp, Nam);
5229 -- Otherwise we must have the case of an overloaded call
5231 else
5232 pragma Assert (Is_Overloaded (Subp));
5234 -- Initialize Nam to prevent warning (we know it will be assigned
5235 -- in the loop below, but the compiler does not know that).
5237 Nam := Empty;
5239 Get_First_Interp (Subp, I, It);
5240 while Present (It.Typ) loop
5241 if Covers (Typ, It.Typ) then
5242 Nam := It.Nam;
5243 Set_Entity_With_Style_Check (Subp, Nam);
5244 exit;
5245 end if;
5247 Get_Next_Interp (I, It);
5248 end loop;
5249 end if;
5251 if Is_Access_Subprogram_Type (Base_Type (Etype (Nam)))
5252 and then not Is_Access_Subprogram_Type (Base_Type (Typ))
5253 and then Nkind (Subp) /= N_Explicit_Dereference
5254 and then Present (Parameter_Associations (N))
5255 then
5256 -- The prefix is a parameterless function call that returns an access
5257 -- to subprogram. If parameters are present in the current call, add
5258 -- add an explicit dereference. We use the base type here because
5259 -- within an instance these may be subtypes.
5261 -- The dereference is added either in Analyze_Call or here. Should
5262 -- be consolidated ???
5264 Set_Is_Overloaded (Subp, False);
5265 Set_Etype (Subp, Etype (Nam));
5266 Insert_Explicit_Dereference (Subp);
5267 Nam := Designated_Type (Etype (Nam));
5268 Resolve (Subp, Nam);
5269 end if;
5271 -- Check that a call to Current_Task does not occur in an entry body
5273 if Is_RTE (Nam, RE_Current_Task) then
5274 declare
5275 P : Node_Id;
5277 begin
5278 P := N;
5279 loop
5280 P := Parent (P);
5282 -- Exclude calls that occur within the default of a formal
5283 -- parameter of the entry, since those are evaluated outside
5284 -- of the body.
5286 exit when No (P) or else Nkind (P) = N_Parameter_Specification;
5288 if Nkind (P) = N_Entry_Body
5289 or else (Nkind (P) = N_Subprogram_Body
5290 and then Is_Entry_Barrier_Function (P))
5291 then
5292 Rtype := Etype (N);
5293 Error_Msg_NE
5294 ("?& should not be used in entry body (RM C.7(17))",
5295 N, Nam);
5296 Error_Msg_NE
5297 ("\Program_Error will be raised at run time?", N, Nam);
5298 Rewrite (N,
5299 Make_Raise_Program_Error (Loc,
5300 Reason => PE_Current_Task_In_Entry_Body));
5301 Set_Etype (N, Rtype);
5302 return;
5303 end if;
5304 end loop;
5305 end;
5306 end if;
5308 -- Check that a procedure call does not occur in the context of the
5309 -- entry call statement of a conditional or timed entry call. Note that
5310 -- the case of a call to a subprogram renaming of an entry will also be
5311 -- rejected. The test for N not being an N_Entry_Call_Statement is
5312 -- defensive, covering the possibility that the processing of entry
5313 -- calls might reach this point due to later modifications of the code
5314 -- above.
5316 if Nkind (Parent (N)) = N_Entry_Call_Alternative
5317 and then Nkind (N) /= N_Entry_Call_Statement
5318 and then Entry_Call_Statement (Parent (N)) = N
5319 then
5320 if Ada_Version < Ada_2005 then
5321 Error_Msg_N ("entry call required in select statement", N);
5323 -- Ada 2005 (AI-345): If a procedure_call_statement is used
5324 -- for a procedure_or_entry_call, the procedure_name or
5325 -- procedure_prefix of the procedure_call_statement shall denote
5326 -- an entry renamed by a procedure, or (a view of) a primitive
5327 -- subprogram of a limited interface whose first parameter is
5328 -- a controlling parameter.
5330 elsif Nkind (N) = N_Procedure_Call_Statement
5331 and then not Is_Renamed_Entry (Nam)
5332 and then not Is_Controlling_Limited_Procedure (Nam)
5333 then
5334 Error_Msg_N
5335 ("entry call or dispatching primitive of interface required", N);
5336 end if;
5337 end if;
5339 -- Check that this is not a call to a protected procedure or entry from
5340 -- within a protected function.
5342 Check_Internal_Protected_Use (N, Nam);
5344 -- Freeze the subprogram name if not in a spec-expression. Note that we
5345 -- freeze procedure calls as well as function calls. Procedure calls are
5346 -- not frozen according to the rules (RM 13.14(14)) because it is
5347 -- impossible to have a procedure call to a non-frozen procedure in pure
5348 -- Ada, but in the code that we generate in the expander, this rule
5349 -- needs extending because we can generate procedure calls that need
5350 -- freezing.
5352 -- In Ada 2012, expression functions may be called within pre/post
5353 -- conditions of subsequent functions or expression functions. Such
5354 -- calls do not freeze when they appear within generated bodies, which
5355 -- would place the freeze node in the wrong scope. An expression
5356 -- function is frozen in the usual fashion, by the appearance of a real
5357 -- body, or at the end of a declarative part.
5359 if Is_Entity_Name (Subp) and then not In_Spec_Expression
5360 and then
5361 (not Is_Expression_Function (Entity (Subp))
5362 or else Scope (Entity (Subp)) = Current_Scope)
5363 then
5364 Freeze_Expression (Subp);
5365 end if;
5367 -- For a predefined operator, the type of the result is the type imposed
5368 -- by context, except for a predefined operation on universal fixed.
5369 -- Otherwise The type of the call is the type returned by the subprogram
5370 -- being called.
5372 if Is_Predefined_Op (Nam) then
5373 if Etype (N) /= Universal_Fixed then
5374 Set_Etype (N, Typ);
5375 end if;
5377 -- If the subprogram returns an array type, and the context requires the
5378 -- component type of that array type, the node is really an indexing of
5379 -- the parameterless call. Resolve as such. A pathological case occurs
5380 -- when the type of the component is an access to the array type. In
5381 -- this case the call is truly ambiguous.
5383 elsif (Needs_No_Actuals (Nam) or else Needs_One_Actual (Nam))
5384 and then
5385 ((Is_Array_Type (Etype (Nam))
5386 and then Covers (Typ, Component_Type (Etype (Nam))))
5387 or else (Is_Access_Type (Etype (Nam))
5388 and then Is_Array_Type (Designated_Type (Etype (Nam)))
5389 and then
5390 Covers
5391 (Typ,
5392 Component_Type (Designated_Type (Etype (Nam))))))
5393 then
5394 declare
5395 Index_Node : Node_Id;
5396 New_Subp : Node_Id;
5397 Ret_Type : constant Entity_Id := Etype (Nam);
5399 begin
5400 if Is_Access_Type (Ret_Type)
5401 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
5402 then
5403 Error_Msg_N
5404 ("cannot disambiguate function call and indexing", N);
5405 else
5406 New_Subp := Relocate_Node (Subp);
5407 Set_Entity (Subp, Nam);
5409 if (Is_Array_Type (Ret_Type)
5410 and then Component_Type (Ret_Type) /= Any_Type)
5411 or else
5412 (Is_Access_Type (Ret_Type)
5413 and then
5414 Component_Type (Designated_Type (Ret_Type)) /= Any_Type)
5415 then
5416 if Needs_No_Actuals (Nam) then
5418 -- Indexed call to a parameterless function
5420 Index_Node :=
5421 Make_Indexed_Component (Loc,
5422 Prefix =>
5423 Make_Function_Call (Loc,
5424 Name => New_Subp),
5425 Expressions => Parameter_Associations (N));
5426 else
5427 -- An Ada 2005 prefixed call to a primitive operation
5428 -- whose first parameter is the prefix. This prefix was
5429 -- prepended to the parameter list, which is actually a
5430 -- list of indexes. Remove the prefix in order to build
5431 -- the proper indexed component.
5433 Index_Node :=
5434 Make_Indexed_Component (Loc,
5435 Prefix =>
5436 Make_Function_Call (Loc,
5437 Name => New_Subp,
5438 Parameter_Associations =>
5439 New_List
5440 (Remove_Head (Parameter_Associations (N)))),
5441 Expressions => Parameter_Associations (N));
5442 end if;
5444 -- Preserve the parenthesis count of the node
5446 Set_Paren_Count (Index_Node, Paren_Count (N));
5448 -- Since we are correcting a node classification error made
5449 -- by the parser, we call Replace rather than Rewrite.
5451 Replace (N, Index_Node);
5453 Set_Etype (Prefix (N), Ret_Type);
5454 Set_Etype (N, Typ);
5455 Resolve_Indexed_Component (N, Typ);
5456 Check_Elab_Call (Prefix (N));
5457 end if;
5458 end if;
5460 return;
5461 end;
5463 else
5464 Set_Etype (N, Etype (Nam));
5465 end if;
5467 -- In the case where the call is to an overloaded subprogram, Analyze
5468 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
5469 -- such a case Normalize_Actuals needs to be called once more to order
5470 -- the actuals correctly. Otherwise the call will have the ordering
5471 -- given by the last overloaded subprogram whether this is the correct
5472 -- one being called or not.
5474 if Is_Overloaded (Subp) then
5475 Normalize_Actuals (N, Nam, False, Norm_OK);
5476 pragma Assert (Norm_OK);
5477 end if;
5479 -- In any case, call is fully resolved now. Reset Overload flag, to
5480 -- prevent subsequent overload resolution if node is analyzed again
5482 Set_Is_Overloaded (Subp, False);
5483 Set_Is_Overloaded (N, False);
5485 -- If we are calling the current subprogram from immediately within its
5486 -- body, then that is the case where we can sometimes detect cases of
5487 -- infinite recursion statically. Do not try this in case restriction
5488 -- No_Recursion is in effect anyway, and do it only for source calls.
5490 if Comes_From_Source (N) then
5491 Scop := Current_Scope;
5493 -- Issue warning for possible infinite recursion in the absence
5494 -- of the No_Recursion restriction.
5496 if Same_Or_Aliased_Subprograms (Nam, Scop)
5497 and then not Restriction_Active (No_Recursion)
5498 and then Check_Infinite_Recursion (N)
5499 then
5500 -- Here we detected and flagged an infinite recursion, so we do
5501 -- not need to test the case below for further warnings. Also we
5502 -- are all done if we now have a raise SE node.
5504 if Nkind (N) = N_Raise_Storage_Error then
5505 return;
5506 end if;
5508 -- If call is to immediately containing subprogram, then check for
5509 -- the case of a possible run-time detectable infinite recursion.
5511 else
5512 Scope_Loop : while Scop /= Standard_Standard loop
5513 if Same_Or_Aliased_Subprograms (Nam, Scop) then
5515 -- Although in general case, recursion is not statically
5516 -- checkable, the case of calling an immediately containing
5517 -- subprogram is easy to catch.
5519 Check_Restriction (No_Recursion, N);
5521 -- If the recursive call is to a parameterless subprogram,
5522 -- then even if we can't statically detect infinite
5523 -- recursion, this is pretty suspicious, and we output a
5524 -- warning. Furthermore, we will try later to detect some
5525 -- cases here at run time by expanding checking code (see
5526 -- Detect_Infinite_Recursion in package Exp_Ch6).
5528 -- If the recursive call is within a handler, do not emit a
5529 -- warning, because this is a common idiom: loop until input
5530 -- is correct, catch illegal input in handler and restart.
5532 if No (First_Formal (Nam))
5533 and then Etype (Nam) = Standard_Void_Type
5534 and then not Error_Posted (N)
5535 and then Nkind (Parent (N)) /= N_Exception_Handler
5536 then
5537 -- For the case of a procedure call. We give the message
5538 -- only if the call is the first statement in a sequence
5539 -- of statements, or if all previous statements are
5540 -- simple assignments. This is simply a heuristic to
5541 -- decrease false positives, without losing too many good
5542 -- warnings. The idea is that these previous statements
5543 -- may affect global variables the procedure depends on.
5544 -- We also exclude raise statements, that may arise from
5545 -- constraint checks and are probably unrelated to the
5546 -- intended control flow.
5548 if Nkind (N) = N_Procedure_Call_Statement
5549 and then Is_List_Member (N)
5550 then
5551 declare
5552 P : Node_Id;
5553 begin
5554 P := Prev (N);
5555 while Present (P) loop
5556 if not Nkind_In (P,
5557 N_Assignment_Statement,
5558 N_Raise_Constraint_Error)
5559 then
5560 exit Scope_Loop;
5561 end if;
5563 Prev (P);
5564 end loop;
5565 end;
5566 end if;
5568 -- Do not give warning if we are in a conditional context
5570 declare
5571 K : constant Node_Kind := Nkind (Parent (N));
5572 begin
5573 if (K = N_Loop_Statement
5574 and then Present (Iteration_Scheme (Parent (N))))
5575 or else K = N_If_Statement
5576 or else K = N_Elsif_Part
5577 or else K = N_Case_Statement_Alternative
5578 then
5579 exit Scope_Loop;
5580 end if;
5581 end;
5583 -- Here warning is to be issued
5585 Set_Has_Recursive_Call (Nam);
5586 Error_Msg_N
5587 ("?possible infinite recursion!", N);
5588 Error_Msg_N
5589 ("\?Storage_Error may be raised at run time!", N);
5590 end if;
5592 exit Scope_Loop;
5593 end if;
5595 Scop := Scope (Scop);
5596 end loop Scope_Loop;
5597 end if;
5598 end if;
5600 -- Check obsolescent reference to Ada.Characters.Handling subprogram
5602 Check_Obsolescent_2005_Entity (Nam, Subp);
5604 -- If subprogram name is a predefined operator, it was given in
5605 -- functional notation. Replace call node with operator node, so
5606 -- that actuals can be resolved appropriately.
5608 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
5609 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
5610 return;
5612 elsif Present (Alias (Nam))
5613 and then Is_Predefined_Op (Alias (Nam))
5614 then
5615 Resolve_Actuals (N, Nam);
5616 Make_Call_Into_Operator (N, Typ, Alias (Nam));
5617 return;
5618 end if;
5620 -- Create a transient scope if the resulting type requires it
5622 -- There are several notable exceptions:
5624 -- a) In init procs, the transient scope overhead is not needed, and is
5625 -- even incorrect when the call is a nested initialization call for a
5626 -- component whose expansion may generate adjust calls. However, if the
5627 -- call is some other procedure call within an initialization procedure
5628 -- (for example a call to Create_Task in the init_proc of the task
5629 -- run-time record) a transient scope must be created around this call.
5631 -- b) Enumeration literal pseudo-calls need no transient scope
5633 -- c) Intrinsic subprograms (Unchecked_Conversion and source info
5634 -- functions) do not use the secondary stack even though the return
5635 -- type may be unconstrained.
5637 -- d) Calls to a build-in-place function, since such functions may
5638 -- allocate their result directly in a target object, and cases where
5639 -- the result does get allocated in the secondary stack are checked for
5640 -- within the specialized Exp_Ch6 procedures for expanding those
5641 -- build-in-place calls.
5643 -- e) If the subprogram is marked Inline_Always, then even if it returns
5644 -- an unconstrained type the call does not require use of the secondary
5645 -- stack. However, inlining will only take place if the body to inline
5646 -- is already present. It may not be available if e.g. the subprogram is
5647 -- declared in a child instance.
5649 -- If this is an initialization call for a type whose construction
5650 -- uses the secondary stack, and it is not a nested call to initialize
5651 -- a component, we do need to create a transient scope for it. We
5652 -- check for this by traversing the type in Check_Initialization_Call.
5654 if Is_Inlined (Nam)
5655 and then Has_Pragma_Inline_Always (Nam)
5656 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5657 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5658 and then not Debug_Flag_Dot_K
5659 then
5660 null;
5662 elsif Is_Inlined (Nam)
5663 and then Has_Pragma_Inline (Nam)
5664 and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration
5665 and then Present (Body_To_Inline (Unit_Declaration_Node (Nam)))
5666 and then Debug_Flag_Dot_K
5667 then
5668 null;
5670 elsif Ekind (Nam) = E_Enumeration_Literal
5671 or else Is_Build_In_Place_Function (Nam)
5672 or else Is_Intrinsic_Subprogram (Nam)
5673 then
5674 null;
5676 elsif Full_Expander_Active
5677 and then Is_Type (Etype (Nam))
5678 and then Requires_Transient_Scope (Etype (Nam))
5679 and then
5680 (not Within_Init_Proc
5681 or else
5682 (not Is_Init_Proc (Nam) and then Ekind (Nam) /= E_Function))
5683 then
5684 Establish_Transient_Scope (N, Sec_Stack => True);
5686 -- If the call appears within the bounds of a loop, it will
5687 -- be rewritten and reanalyzed, nothing left to do here.
5689 if Nkind (N) /= N_Function_Call then
5690 return;
5691 end if;
5693 elsif Is_Init_Proc (Nam)
5694 and then not Within_Init_Proc
5695 then
5696 Check_Initialization_Call (N, Nam);
5697 end if;
5699 -- A protected function cannot be called within the definition of the
5700 -- enclosing protected type.
5702 if Is_Protected_Type (Scope (Nam))
5703 and then In_Open_Scopes (Scope (Nam))
5704 and then not Has_Completion (Scope (Nam))
5705 then
5706 Error_Msg_NE
5707 ("& cannot be called before end of protected definition", N, Nam);
5708 end if;
5710 -- Propagate interpretation to actuals, and add default expressions
5711 -- where needed.
5713 if Present (First_Formal (Nam)) then
5714 Resolve_Actuals (N, Nam);
5716 -- Overloaded literals are rewritten as function calls, for purpose of
5717 -- resolution. After resolution, we can replace the call with the
5718 -- literal itself.
5720 elsif Ekind (Nam) = E_Enumeration_Literal then
5721 Copy_Node (Subp, N);
5722 Resolve_Entity_Name (N, Typ);
5724 -- Avoid validation, since it is a static function call
5726 Generate_Reference (Nam, Subp);
5727 return;
5728 end if;
5730 -- If the subprogram is not global, then kill all saved values and
5731 -- checks. This is a bit conservative, since in many cases we could do
5732 -- better, but it is not worth the effort. Similarly, we kill constant
5733 -- values. However we do not need to do this for internal entities
5734 -- (unless they are inherited user-defined subprograms), since they
5735 -- are not in the business of molesting local values.
5737 -- If the flag Suppress_Value_Tracking_On_Calls is set, then we also
5738 -- kill all checks and values for calls to global subprograms. This
5739 -- takes care of the case where an access to a local subprogram is
5740 -- taken, and could be passed directly or indirectly and then called
5741 -- from almost any context.
5743 -- Note: we do not do this step till after resolving the actuals. That
5744 -- way we still take advantage of the current value information while
5745 -- scanning the actuals.
5747 -- We suppress killing values if we are processing the nodes associated
5748 -- with N_Freeze_Entity nodes. Otherwise the declaration of a tagged
5749 -- type kills all the values as part of analyzing the code that
5750 -- initializes the dispatch tables.
5752 if Inside_Freezing_Actions = 0
5753 and then (not Is_Library_Level_Entity (Nam)
5754 or else Suppress_Value_Tracking_On_Call
5755 (Nearest_Dynamic_Scope (Current_Scope)))
5756 and then (Comes_From_Source (Nam)
5757 or else (Present (Alias (Nam))
5758 and then Comes_From_Source (Alias (Nam))))
5759 then
5760 Kill_Current_Values;
5761 end if;
5763 -- If we are warning about unread OUT parameters, this is the place to
5764 -- set Last_Assignment for OUT and IN OUT parameters. We have to do this
5765 -- after the above call to Kill_Current_Values (since that call clears
5766 -- the Last_Assignment field of all local variables).
5768 if (Warn_On_Modified_Unread or Warn_On_All_Unread_Out_Parameters)
5769 and then Comes_From_Source (N)
5770 and then In_Extended_Main_Source_Unit (N)
5771 then
5772 declare
5773 F : Entity_Id;
5774 A : Node_Id;
5776 begin
5777 F := First_Formal (Nam);
5778 A := First_Actual (N);
5779 while Present (F) and then Present (A) loop
5780 if Ekind_In (F, E_Out_Parameter, E_In_Out_Parameter)
5781 and then Warn_On_Modified_As_Out_Parameter (F)
5782 and then Is_Entity_Name (A)
5783 and then Present (Entity (A))
5784 and then Comes_From_Source (N)
5785 and then Safe_To_Capture_Value (N, Entity (A))
5786 then
5787 Set_Last_Assignment (Entity (A), A);
5788 end if;
5790 Next_Formal (F);
5791 Next_Actual (A);
5792 end loop;
5793 end;
5794 end if;
5796 -- If the subprogram is a primitive operation, check whether or not
5797 -- it is a correct dispatching call.
5799 if Is_Overloadable (Nam)
5800 and then Is_Dispatching_Operation (Nam)
5801 then
5802 Check_Dispatching_Call (N);
5804 elsif Ekind (Nam) /= E_Subprogram_Type
5805 and then Is_Abstract_Subprogram (Nam)
5806 and then not In_Instance
5807 then
5808 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
5809 end if;
5811 -- If this is a dispatching call, generate the appropriate reference,
5812 -- for better source navigation in GPS.
5814 if Is_Overloadable (Nam)
5815 and then Present (Controlling_Argument (N))
5816 then
5817 Generate_Reference (Nam, Subp, 'R');
5819 -- Normal case, not a dispatching call: generate a call reference
5821 else
5822 Generate_Reference (Nam, Subp, 's');
5823 end if;
5825 if Is_Intrinsic_Subprogram (Nam) then
5826 Check_Intrinsic_Call (N);
5827 end if;
5829 -- Check for violation of restriction No_Specific_Termination_Handlers
5830 -- and warn on a potentially blocking call to Abort_Task.
5832 if Restriction_Check_Required (No_Specific_Termination_Handlers)
5833 and then (Is_RTE (Nam, RE_Set_Specific_Handler)
5834 or else
5835 Is_RTE (Nam, RE_Specific_Handler))
5836 then
5837 Check_Restriction (No_Specific_Termination_Handlers, N);
5839 elsif Is_RTE (Nam, RE_Abort_Task) then
5840 Check_Potentially_Blocking_Operation (N);
5841 end if;
5843 -- A call to Ada.Real_Time.Timing_Events.Set_Handler to set a relative
5844 -- timing event violates restriction No_Relative_Delay (AI-0211). We
5845 -- need to check the second argument to determine whether it is an
5846 -- absolute or relative timing event.
5848 if Restriction_Check_Required (No_Relative_Delay)
5849 and then Is_RTE (Nam, RE_Set_Handler)
5850 and then Is_RTE (Etype (Next_Actual (First_Actual (N))), RE_Time_Span)
5851 then
5852 Check_Restriction (No_Relative_Delay, N);
5853 end if;
5855 -- Issue an error for a call to an eliminated subprogram. This routine
5856 -- will not perform the check if the call appears within a default
5857 -- expression.
5859 Check_For_Eliminated_Subprogram (Subp, Nam);
5861 -- In formal mode, the primitive operations of a tagged type or type
5862 -- extension do not include functions that return the tagged type.
5864 -- Commented out as the call to Is_Inherited_Operation_For_Type may
5865 -- cause an error because the type entity of the parent node of
5866 -- Entity (Name (N) may not be set. ???
5867 -- So why not just add a guard ???
5869 -- if Nkind (N) = N_Function_Call
5870 -- and then Is_Tagged_Type (Etype (N))
5871 -- and then Is_Entity_Name (Name (N))
5872 -- and then Is_Inherited_Operation_For_Type
5873 -- (Entity (Name (N)), Etype (N))
5874 -- then
5875 -- Check_SPARK_Restriction ("function not inherited", N);
5876 -- end if;
5878 -- Implement rule in 12.5.1 (23.3/2): In an instance, if the actual is
5879 -- class-wide and the call dispatches on result in a context that does
5880 -- not provide a tag, the call raises Program_Error.
5882 if Nkind (N) = N_Function_Call
5883 and then In_Instance
5884 and then Is_Generic_Actual_Type (Typ)
5885 and then Is_Class_Wide_Type (Typ)
5886 and then Has_Controlling_Result (Nam)
5887 and then Nkind (Parent (N)) = N_Object_Declaration
5888 then
5889 -- Verify that none of the formals are controlling
5891 declare
5892 Call_OK : Boolean := False;
5893 F : Entity_Id;
5895 begin
5896 F := First_Formal (Nam);
5897 while Present (F) loop
5898 if Is_Controlling_Formal (F) then
5899 Call_OK := True;
5900 exit;
5901 end if;
5903 Next_Formal (F);
5904 end loop;
5906 if not Call_OK then
5907 Error_Msg_N ("!? cannot determine tag of result", N);
5908 Error_Msg_N ("!? Program_Error will be raised", N);
5909 Insert_Action (N,
5910 Make_Raise_Program_Error (Sloc (N),
5911 Reason => PE_Explicit_Raise));
5912 end if;
5913 end;
5914 end if;
5916 -- Check the dimensions of the actuals in the call. For function calls,
5917 -- propagate the dimensions from the returned type to N.
5919 Analyze_Dimension_Call (N, Nam);
5921 -- All done, evaluate call and deal with elaboration issues
5923 Eval_Call (N);
5924 Check_Elab_Call (N);
5925 Warn_On_Overlapping_Actuals (Nam, N);
5926 end Resolve_Call;
5928 -----------------------------
5929 -- Resolve_Case_Expression --
5930 -----------------------------
5932 procedure Resolve_Case_Expression (N : Node_Id; Typ : Entity_Id) is
5933 Alt : Node_Id;
5935 begin
5936 Alt := First (Alternatives (N));
5937 while Present (Alt) loop
5938 Resolve (Expression (Alt), Typ);
5939 Next (Alt);
5940 end loop;
5942 Set_Etype (N, Typ);
5943 Eval_Case_Expression (N);
5945 -- If we still have a case expression, and overflow checks are enabled
5946 -- in MINIMIZED or ELIMINATED modes, then set Do_Overflow_Check to
5947 -- ensure that we handle overflow for dependent expressions.
5949 if Nkind (N) = N_Case_Expression
5950 and then Overflow_Check_Mode (Typ) in Minimized_Or_Eliminated
5951 then
5952 Set_Do_Overflow_Check (N);
5953 end if;
5954 end Resolve_Case_Expression;
5956 -------------------------------
5957 -- Resolve_Character_Literal --
5958 -------------------------------
5960 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
5961 B_Typ : constant Entity_Id := Base_Type (Typ);
5962 C : Entity_Id;
5964 begin
5965 -- Verify that the character does belong to the type of the context
5967 Set_Etype (N, B_Typ);
5968 Eval_Character_Literal (N);
5970 -- Wide_Wide_Character literals must always be defined, since the set
5971 -- of wide wide character literals is complete, i.e. if a character
5972 -- literal is accepted by the parser, then it is OK for wide wide
5973 -- character (out of range character literals are rejected).
5975 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
5976 return;
5978 -- Always accept character literal for type Any_Character, which
5979 -- occurs in error situations and in comparisons of literals, both
5980 -- of which should accept all literals.
5982 elsif B_Typ = Any_Character then
5983 return;
5985 -- For Standard.Character or a type derived from it, check that the
5986 -- literal is in range.
5988 elsif Root_Type (B_Typ) = Standard_Character then
5989 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5990 return;
5991 end if;
5993 -- For Standard.Wide_Character or a type derived from it, check that the
5994 -- literal is in range.
5996 elsif Root_Type (B_Typ) = Standard_Wide_Character then
5997 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
5998 return;
5999 end if;
6001 -- For Standard.Wide_Wide_Character or a type derived from it, we
6002 -- know the literal is in range, since the parser checked!
6004 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
6005 return;
6007 -- If the entity is already set, this has already been resolved in a
6008 -- generic context, or comes from expansion. Nothing else to do.
6010 elsif Present (Entity (N)) then
6011 return;
6013 -- Otherwise we have a user defined character type, and we can use the
6014 -- standard visibility mechanisms to locate the referenced entity.
6016 else
6017 C := Current_Entity (N);
6018 while Present (C) loop
6019 if Etype (C) = B_Typ then
6020 Set_Entity_With_Style_Check (N, C);
6021 Generate_Reference (C, N);
6022 return;
6023 end if;
6025 C := Homonym (C);
6026 end loop;
6027 end if;
6029 -- If we fall through, then the literal does not match any of the
6030 -- entries of the enumeration type. This isn't just a constraint error
6031 -- situation, it is an illegality (see RM 4.2).
6033 Error_Msg_NE
6034 ("character not defined for }", N, First_Subtype (B_Typ));
6035 end Resolve_Character_Literal;
6037 ---------------------------
6038 -- Resolve_Comparison_Op --
6039 ---------------------------
6041 -- Context requires a boolean type, and plays no role in resolution.
6042 -- Processing identical to that for equality operators. The result type is
6043 -- the base type, which matters when pathological subtypes of booleans with
6044 -- limited ranges are used.
6046 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
6047 L : constant Node_Id := Left_Opnd (N);
6048 R : constant Node_Id := Right_Opnd (N);
6049 T : Entity_Id;
6051 begin
6052 -- If this is an intrinsic operation which is not predefined, use the
6053 -- types of its declared arguments to resolve the possibly overloaded
6054 -- operands. Otherwise the operands are unambiguous and specify the
6055 -- expected type.
6057 if Scope (Entity (N)) /= Standard_Standard then
6058 T := Etype (First_Entity (Entity (N)));
6060 else
6061 T := Find_Unique_Type (L, R);
6063 if T = Any_Fixed then
6064 T := Unique_Fixed_Point_Type (L);
6065 end if;
6066 end if;
6068 Set_Etype (N, Base_Type (Typ));
6069 Generate_Reference (T, N, ' ');
6071 -- Skip remaining processing if already set to Any_Type
6073 if T = Any_Type then
6074 return;
6075 end if;
6077 -- Deal with other error cases
6079 if T = Any_String or else
6080 T = Any_Composite or else
6081 T = Any_Character
6082 then
6083 if T = Any_Character then
6084 Ambiguous_Character (L);
6085 else
6086 Error_Msg_N ("ambiguous operands for comparison", N);
6087 end if;
6089 Set_Etype (N, Any_Type);
6090 return;
6091 end if;
6093 -- Resolve the operands if types OK
6095 Resolve (L, T);
6096 Resolve (R, T);
6097 Check_Unset_Reference (L);
6098 Check_Unset_Reference (R);
6099 Generate_Operator_Reference (N, T);
6100 Check_Low_Bound_Tested (N);
6102 -- In SPARK, ordering operators <, <=, >, >= are not defined for Boolean
6103 -- types or array types except String.
6105 if Is_Boolean_Type (T) then
6106 Check_SPARK_Restriction
6107 ("comparison is not defined on Boolean type", N);
6109 elsif Is_Array_Type (T)
6110 and then Base_Type (T) /= Standard_String
6111 then
6112 Check_SPARK_Restriction
6113 ("comparison is not defined on array types other than String", N);
6114 end if;
6116 -- Check comparison on unordered enumeration
6118 if Comes_From_Source (N)
6119 and then Bad_Unordered_Enumeration_Reference (N, Etype (L))
6120 then
6121 Error_Msg_N ("comparison on unordered enumeration type?", N);
6122 end if;
6124 -- Evaluate the relation (note we do this after the above check since
6125 -- this Eval call may change N to True/False.
6127 Analyze_Dimension (N);
6128 Eval_Relational_Op (N);
6129 end Resolve_Comparison_Op;
6131 -----------------------------------------
6132 -- Resolve_Discrete_Subtype_Indication --
6133 -----------------------------------------
6135 procedure Resolve_Discrete_Subtype_Indication
6136 (N : Node_Id;
6137 Typ : Entity_Id)
6139 R : Node_Id;
6140 S : Entity_Id;
6142 begin
6143 Analyze (Subtype_Mark (N));
6144 S := Entity (Subtype_Mark (N));
6146 if Nkind (Constraint (N)) /= N_Range_Constraint then
6147 Error_Msg_N ("expect range constraint for discrete type", N);
6148 Set_Etype (N, Any_Type);
6150 else
6151 R := Range_Expression (Constraint (N));
6153 if R = Error then
6154 return;
6155 end if;
6157 Analyze (R);
6159 if Base_Type (S) /= Base_Type (Typ) then
6160 Error_Msg_NE
6161 ("expect subtype of }", N, First_Subtype (Typ));
6163 -- Rewrite the constraint as a range of Typ
6164 -- to allow compilation to proceed further.
6166 Set_Etype (N, Typ);
6167 Rewrite (Low_Bound (R),
6168 Make_Attribute_Reference (Sloc (Low_Bound (R)),
6169 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
6170 Attribute_Name => Name_First));
6171 Rewrite (High_Bound (R),
6172 Make_Attribute_Reference (Sloc (High_Bound (R)),
6173 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
6174 Attribute_Name => Name_First));
6176 else
6177 Resolve (R, Typ);
6178 Set_Etype (N, Etype (R));
6180 -- Additionally, we must check that the bounds are compatible
6181 -- with the given subtype, which might be different from the
6182 -- type of the context.
6184 Apply_Range_Check (R, S);
6186 -- ??? If the above check statically detects a Constraint_Error
6187 -- it replaces the offending bound(s) of the range R with a
6188 -- Constraint_Error node. When the itype which uses these bounds
6189 -- is frozen the resulting call to Duplicate_Subexpr generates
6190 -- a new temporary for the bounds.
6192 -- Unfortunately there are other itypes that are also made depend
6193 -- on these bounds, so when Duplicate_Subexpr is called they get
6194 -- a forward reference to the newly created temporaries and Gigi
6195 -- aborts on such forward references. This is probably sign of a
6196 -- more fundamental problem somewhere else in either the order of
6197 -- itype freezing or the way certain itypes are constructed.
6199 -- To get around this problem we call Remove_Side_Effects right
6200 -- away if either bounds of R are a Constraint_Error.
6202 declare
6203 L : constant Node_Id := Low_Bound (R);
6204 H : constant Node_Id := High_Bound (R);
6206 begin
6207 if Nkind (L) = N_Raise_Constraint_Error then
6208 Remove_Side_Effects (L);
6209 end if;
6211 if Nkind (H) = N_Raise_Constraint_Error then
6212 Remove_Side_Effects (H);
6213 end if;
6214 end;
6216 Check_Unset_Reference (Low_Bound (R));
6217 Check_Unset_Reference (High_Bound (R));
6218 end if;
6219 end if;
6220 end Resolve_Discrete_Subtype_Indication;
6222 -------------------------
6223 -- Resolve_Entity_Name --
6224 -------------------------
6226 -- Used to resolve identifiers and expanded names
6228 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
6229 E : constant Entity_Id := Entity (N);
6231 begin
6232 -- If garbage from errors, set to Any_Type and return
6234 if No (E) and then Total_Errors_Detected /= 0 then
6235 Set_Etype (N, Any_Type);
6236 return;
6237 end if;
6239 -- Replace named numbers by corresponding literals. Note that this is
6240 -- the one case where Resolve_Entity_Name must reset the Etype, since
6241 -- it is currently marked as universal.
6243 if Ekind (E) = E_Named_Integer then
6244 Set_Etype (N, Typ);
6245 Eval_Named_Integer (N);
6247 elsif Ekind (E) = E_Named_Real then
6248 Set_Etype (N, Typ);
6249 Eval_Named_Real (N);
6251 -- For enumeration literals, we need to make sure that a proper style
6252 -- check is done, since such literals are overloaded, and thus we did
6253 -- not do a style check during the first phase of analysis.
6255 elsif Ekind (E) = E_Enumeration_Literal then
6256 Set_Entity_With_Style_Check (N, E);
6257 Eval_Entity_Name (N);
6259 -- Case of subtype name appearing as an operand in expression
6261 elsif Is_Type (E) then
6263 -- Allow use of subtype if it is a concurrent type where we are
6264 -- currently inside the body. This will eventually be expanded into a
6265 -- call to Self (for tasks) or _object (for protected objects). Any
6266 -- other use of a subtype is invalid.
6268 if Is_Concurrent_Type (E)
6269 and then In_Open_Scopes (E)
6270 then
6271 null;
6273 -- Any other use is an error
6275 else
6276 Error_Msg_N
6277 ("invalid use of subtype mark in expression or call", N);
6278 end if;
6280 -- Check discriminant use if entity is discriminant in current scope,
6281 -- i.e. discriminant of record or concurrent type currently being
6282 -- analyzed. Uses in corresponding body are unrestricted.
6284 elsif Ekind (E) = E_Discriminant
6285 and then Scope (E) = Current_Scope
6286 and then not Has_Completion (Current_Scope)
6287 then
6288 Check_Discriminant_Use (N);
6290 -- A parameterless generic function cannot appear in a context that
6291 -- requires resolution.
6293 elsif Ekind (E) = E_Generic_Function then
6294 Error_Msg_N ("illegal use of generic function", N);
6296 elsif Ekind (E) = E_Out_Parameter
6297 and then Ada_Version = Ada_83
6298 and then (Nkind (Parent (N)) in N_Op
6299 or else (Nkind (Parent (N)) = N_Assignment_Statement
6300 and then N = Expression (Parent (N)))
6301 or else Nkind (Parent (N)) = N_Explicit_Dereference)
6302 then
6303 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
6305 -- In all other cases, just do the possible static evaluation
6307 else
6308 -- A deferred constant that appears in an expression must have a
6309 -- completion, unless it has been removed by in-place expansion of
6310 -- an aggregate.
6312 if Ekind (E) = E_Constant
6313 and then Comes_From_Source (E)
6314 and then No (Constant_Value (E))
6315 and then Is_Frozen (Etype (E))
6316 and then not In_Spec_Expression
6317 and then not Is_Imported (E)
6318 then
6319 if No_Initialization (Parent (E))
6320 or else (Present (Full_View (E))
6321 and then No_Initialization (Parent (Full_View (E))))
6322 then
6323 null;
6324 else
6325 Error_Msg_N (
6326 "deferred constant is frozen before completion", N);
6327 end if;
6328 end if;
6330 Eval_Entity_Name (N);
6331 end if;
6332 end Resolve_Entity_Name;
6334 -------------------
6335 -- Resolve_Entry --
6336 -------------------
6338 procedure Resolve_Entry (Entry_Name : Node_Id) is
6339 Loc : constant Source_Ptr := Sloc (Entry_Name);
6340 Nam : Entity_Id;
6341 New_N : Node_Id;
6342 S : Entity_Id;
6343 Tsk : Entity_Id;
6344 E_Name : Node_Id;
6345 Index : Node_Id;
6347 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
6348 -- If the bounds of the entry family being called depend on task
6349 -- discriminants, build a new index subtype where a discriminant is
6350 -- replaced with the value of the discriminant of the target task.
6351 -- The target task is the prefix of the entry name in the call.
6353 -----------------------
6354 -- Actual_Index_Type --
6355 -----------------------
6357 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
6358 Typ : constant Entity_Id := Entry_Index_Type (E);
6359 Tsk : constant Entity_Id := Scope (E);
6360 Lo : constant Node_Id := Type_Low_Bound (Typ);
6361 Hi : constant Node_Id := Type_High_Bound (Typ);
6362 New_T : Entity_Id;
6364 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
6365 -- If the bound is given by a discriminant, replace with a reference
6366 -- to the discriminant of the same name in the target task. If the
6367 -- entry name is the target of a requeue statement and the entry is
6368 -- in the current protected object, the bound to be used is the
6369 -- discriminal of the object (see Apply_Range_Checks for details of
6370 -- the transformation).
6372 -----------------------------
6373 -- Actual_Discriminant_Ref --
6374 -----------------------------
6376 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
6377 Typ : constant Entity_Id := Etype (Bound);
6378 Ref : Node_Id;
6380 begin
6381 Remove_Side_Effects (Bound);
6383 if not Is_Entity_Name (Bound)
6384 or else Ekind (Entity (Bound)) /= E_Discriminant
6385 then
6386 return Bound;
6388 elsif Is_Protected_Type (Tsk)
6389 and then In_Open_Scopes (Tsk)
6390 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
6391 then
6392 -- Note: here Bound denotes a discriminant of the corresponding
6393 -- record type tskV, whose discriminal is a formal of the
6394 -- init-proc tskVIP. What we want is the body discriminal,
6395 -- which is associated to the discriminant of the original
6396 -- concurrent type tsk.
6398 return New_Occurrence_Of
6399 (Find_Body_Discriminal (Entity (Bound)), Loc);
6401 else
6402 Ref :=
6403 Make_Selected_Component (Loc,
6404 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
6405 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
6406 Analyze (Ref);
6407 Resolve (Ref, Typ);
6408 return Ref;
6409 end if;
6410 end Actual_Discriminant_Ref;
6412 -- Start of processing for Actual_Index_Type
6414 begin
6415 if not Has_Discriminants (Tsk)
6416 or else (not Is_Entity_Name (Lo) and then not Is_Entity_Name (Hi))
6417 then
6418 return Entry_Index_Type (E);
6420 else
6421 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
6422 Set_Etype (New_T, Base_Type (Typ));
6423 Set_Size_Info (New_T, Typ);
6424 Set_RM_Size (New_T, RM_Size (Typ));
6425 Set_Scalar_Range (New_T,
6426 Make_Range (Sloc (Entry_Name),
6427 Low_Bound => Actual_Discriminant_Ref (Lo),
6428 High_Bound => Actual_Discriminant_Ref (Hi)));
6430 return New_T;
6431 end if;
6432 end Actual_Index_Type;
6434 -- Start of processing of Resolve_Entry
6436 begin
6437 -- Find name of entry being called, and resolve prefix of name with its
6438 -- own type. The prefix can be overloaded, and the name and signature of
6439 -- the entry must be taken into account.
6441 if Nkind (Entry_Name) = N_Indexed_Component then
6443 -- Case of dealing with entry family within the current tasks
6445 E_Name := Prefix (Entry_Name);
6447 else
6448 E_Name := Entry_Name;
6449 end if;
6451 if Is_Entity_Name (E_Name) then
6453 -- Entry call to an entry (or entry family) in the current task. This
6454 -- is legal even though the task will deadlock. Rewrite as call to
6455 -- current task.
6457 -- This can also be a call to an entry in an enclosing task. If this
6458 -- is a single task, we have to retrieve its name, because the scope
6459 -- of the entry is the task type, not the object. If the enclosing
6460 -- task is a task type, the identity of the task is given by its own
6461 -- self variable.
6463 -- Finally this can be a requeue on an entry of the same task or
6464 -- protected object.
6466 S := Scope (Entity (E_Name));
6468 for J in reverse 0 .. Scope_Stack.Last loop
6469 if Is_Task_Type (Scope_Stack.Table (J).Entity)
6470 and then not Comes_From_Source (S)
6471 then
6472 -- S is an enclosing task or protected object. The concurrent
6473 -- declaration has been converted into a type declaration, and
6474 -- the object itself has an object declaration that follows
6475 -- the type in the same declarative part.
6477 Tsk := Next_Entity (S);
6478 while Etype (Tsk) /= S loop
6479 Next_Entity (Tsk);
6480 end loop;
6482 S := Tsk;
6483 exit;
6485 elsif S = Scope_Stack.Table (J).Entity then
6487 -- Call to current task. Will be transformed into call to Self
6489 exit;
6491 end if;
6492 end loop;
6494 New_N :=
6495 Make_Selected_Component (Loc,
6496 Prefix => New_Occurrence_Of (S, Loc),
6497 Selector_Name =>
6498 New_Occurrence_Of (Entity (E_Name), Loc));
6499 Rewrite (E_Name, New_N);
6500 Analyze (E_Name);
6502 elsif Nkind (Entry_Name) = N_Selected_Component
6503 and then Is_Overloaded (Prefix (Entry_Name))
6504 then
6505 -- Use the entry name (which must be unique at this point) to find
6506 -- the prefix that returns the corresponding task/protected type.
6508 declare
6509 Pref : constant Node_Id := Prefix (Entry_Name);
6510 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
6511 I : Interp_Index;
6512 It : Interp;
6514 begin
6515 Get_First_Interp (Pref, I, It);
6516 while Present (It.Typ) loop
6517 if Scope (Ent) = It.Typ then
6518 Set_Etype (Pref, It.Typ);
6519 exit;
6520 end if;
6522 Get_Next_Interp (I, It);
6523 end loop;
6524 end;
6525 end if;
6527 if Nkind (Entry_Name) = N_Selected_Component then
6528 Resolve (Prefix (Entry_Name));
6530 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6531 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6532 Resolve (Prefix (Prefix (Entry_Name)));
6533 Index := First (Expressions (Entry_Name));
6534 Resolve (Index, Entry_Index_Type (Nam));
6536 -- Up to this point the expression could have been the actual in a
6537 -- simple entry call, and be given by a named association.
6539 if Nkind (Index) = N_Parameter_Association then
6540 Error_Msg_N ("expect expression for entry index", Index);
6541 else
6542 Apply_Range_Check (Index, Actual_Index_Type (Nam));
6543 end if;
6544 end if;
6545 end Resolve_Entry;
6547 ------------------------
6548 -- Resolve_Entry_Call --
6549 ------------------------
6551 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
6552 Entry_Name : constant Node_Id := Name (N);
6553 Loc : constant Source_Ptr := Sloc (Entry_Name);
6554 Actuals : List_Id;
6555 First_Named : Node_Id;
6556 Nam : Entity_Id;
6557 Norm_OK : Boolean;
6558 Obj : Node_Id;
6559 Was_Over : Boolean;
6561 begin
6562 -- We kill all checks here, because it does not seem worth the effort to
6563 -- do anything better, an entry call is a big operation.
6565 Kill_All_Checks;
6567 -- Processing of the name is similar for entry calls and protected
6568 -- operation calls. Once the entity is determined, we can complete
6569 -- the resolution of the actuals.
6571 -- The selector may be overloaded, in the case of a protected object
6572 -- with overloaded functions. The type of the context is used for
6573 -- resolution.
6575 if Nkind (Entry_Name) = N_Selected_Component
6576 and then Is_Overloaded (Selector_Name (Entry_Name))
6577 and then Typ /= Standard_Void_Type
6578 then
6579 declare
6580 I : Interp_Index;
6581 It : Interp;
6583 begin
6584 Get_First_Interp (Selector_Name (Entry_Name), I, It);
6585 while Present (It.Typ) loop
6586 if Covers (Typ, It.Typ) then
6587 Set_Entity (Selector_Name (Entry_Name), It.Nam);
6588 Set_Etype (Entry_Name, It.Typ);
6590 Generate_Reference (It.Typ, N, ' ');
6591 end if;
6593 Get_Next_Interp (I, It);
6594 end loop;
6595 end;
6596 end if;
6598 Resolve_Entry (Entry_Name);
6600 if Nkind (Entry_Name) = N_Selected_Component then
6602 -- Simple entry call
6604 Nam := Entity (Selector_Name (Entry_Name));
6605 Obj := Prefix (Entry_Name);
6606 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
6608 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
6610 -- Call to member of entry family
6612 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
6613 Obj := Prefix (Prefix (Entry_Name));
6614 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
6615 end if;
6617 -- We cannot in general check the maximum depth of protected entry calls
6618 -- at compile time. But we can tell that any protected entry call at all
6619 -- violates a specified nesting depth of zero.
6621 if Is_Protected_Type (Scope (Nam)) then
6622 Check_Restriction (Max_Entry_Queue_Length, N);
6623 end if;
6625 -- Use context type to disambiguate a protected function that can be
6626 -- called without actuals and that returns an array type, and where the
6627 -- argument list may be an indexing of the returned value.
6629 if Ekind (Nam) = E_Function
6630 and then Needs_No_Actuals (Nam)
6631 and then Present (Parameter_Associations (N))
6632 and then
6633 ((Is_Array_Type (Etype (Nam))
6634 and then Covers (Typ, Component_Type (Etype (Nam))))
6636 or else (Is_Access_Type (Etype (Nam))
6637 and then Is_Array_Type (Designated_Type (Etype (Nam)))
6638 and then
6639 Covers
6640 (Typ,
6641 Component_Type (Designated_Type (Etype (Nam))))))
6642 then
6643 declare
6644 Index_Node : Node_Id;
6646 begin
6647 Index_Node :=
6648 Make_Indexed_Component (Loc,
6649 Prefix =>
6650 Make_Function_Call (Loc, Name => Relocate_Node (Entry_Name)),
6651 Expressions => Parameter_Associations (N));
6653 -- Since we are correcting a node classification error made by the
6654 -- parser, we call Replace rather than Rewrite.
6656 Replace (N, Index_Node);
6657 Set_Etype (Prefix (N), Etype (Nam));
6658 Set_Etype (N, Typ);
6659 Resolve_Indexed_Component (N, Typ);
6660 return;
6661 end;
6662 end if;
6664 if Ekind_In (Nam, E_Entry, E_Entry_Family)
6665 and then Present (PPC_Wrapper (Nam))
6666 and then Current_Scope /= PPC_Wrapper (Nam)
6667 then
6668 -- Rewrite as call to the precondition wrapper, adding the task
6669 -- object to the list of actuals. If the call is to a member of an
6670 -- entry family, include the index as well.
6672 declare
6673 New_Call : Node_Id;
6674 New_Actuals : List_Id;
6676 begin
6677 New_Actuals := New_List (Obj);
6679 if Nkind (Entry_Name) = N_Indexed_Component then
6680 Append_To (New_Actuals,
6681 New_Copy_Tree (First (Expressions (Entry_Name))));
6682 end if;
6684 Append_List (Parameter_Associations (N), New_Actuals);
6685 New_Call :=
6686 Make_Procedure_Call_Statement (Loc,
6687 Name =>
6688 New_Occurrence_Of (PPC_Wrapper (Nam), Loc),
6689 Parameter_Associations => New_Actuals);
6690 Rewrite (N, New_Call);
6691 Analyze_And_Resolve (N);
6692 return;
6693 end;
6694 end if;
6696 -- The operation name may have been overloaded. Order the actuals
6697 -- according to the formals of the resolved entity, and set the return
6698 -- type to that of the operation.
6700 if Was_Over then
6701 Normalize_Actuals (N, Nam, False, Norm_OK);
6702 pragma Assert (Norm_OK);
6703 Set_Etype (N, Etype (Nam));
6704 end if;
6706 Resolve_Actuals (N, Nam);
6707 Check_Internal_Protected_Use (N, Nam);
6709 -- Create a call reference to the entry
6711 Generate_Reference (Nam, Entry_Name, 's');
6713 if Ekind_In (Nam, E_Entry, E_Entry_Family) then
6714 Check_Potentially_Blocking_Operation (N);
6715 end if;
6717 -- Verify that a procedure call cannot masquerade as an entry
6718 -- call where an entry call is expected.
6720 if Ekind (Nam) = E_Procedure then
6721 if Nkind (Parent (N)) = N_Entry_Call_Alternative
6722 and then N = Entry_Call_Statement (Parent (N))
6723 then
6724 Error_Msg_N ("entry call required in select statement", N);
6726 elsif Nkind (Parent (N)) = N_Triggering_Alternative
6727 and then N = Triggering_Statement (Parent (N))
6728 then
6729 Error_Msg_N ("triggering statement cannot be procedure call", N);
6731 elsif Ekind (Scope (Nam)) = E_Task_Type
6732 and then not In_Open_Scopes (Scope (Nam))
6733 then
6734 Error_Msg_N ("task has no entry with this name", Entry_Name);
6735 end if;
6736 end if;
6738 -- After resolution, entry calls and protected procedure calls are
6739 -- changed into entry calls, for expansion. The structure of the node
6740 -- does not change, so it can safely be done in place. Protected
6741 -- function calls must keep their structure because they are
6742 -- subexpressions.
6744 if Ekind (Nam) /= E_Function then
6746 -- A protected operation that is not a function may modify the
6747 -- corresponding object, and cannot apply to a constant. If this
6748 -- is an internal call, the prefix is the type itself.
6750 if Is_Protected_Type (Scope (Nam))
6751 and then not Is_Variable (Obj)
6752 and then (not Is_Entity_Name (Obj)
6753 or else not Is_Type (Entity (Obj)))
6754 then
6755 Error_Msg_N
6756 ("prefix of protected procedure or entry call must be variable",
6757 Entry_Name);
6758 end if;
6760 Actuals := Parameter_Associations (N);
6761 First_Named := First_Named_Actual (N);
6763 Rewrite (N,
6764 Make_Entry_Call_Statement (Loc,
6765 Name => Entry_Name,
6766 Parameter_Associations => Actuals));
6768 Set_First_Named_Actual (N, First_Named);
6769 Set_Analyzed (N, True);
6771 -- Protected functions can return on the secondary stack, in which
6772 -- case we must trigger the transient scope mechanism.
6774 elsif Full_Expander_Active
6775 and then Requires_Transient_Scope (Etype (Nam))
6776 then
6777 Establish_Transient_Scope (N, Sec_Stack => True);
6778 end if;
6779 end Resolve_Entry_Call;
6781 -------------------------
6782 -- Resolve_Equality_Op --
6783 -------------------------
6785 -- Both arguments must have the same type, and the boolean context does
6786 -- not participate in the resolution. The first pass verifies that the
6787 -- interpretation is not ambiguous, and the type of the left argument is
6788 -- correctly set, or is Any_Type in case of ambiguity. If both arguments
6789 -- are strings or aggregates, allocators, or Null, they are ambiguous even
6790 -- though they carry a single (universal) type. Diagnose this case here.
6792 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
6793 L : constant Node_Id := Left_Opnd (N);
6794 R : constant Node_Id := Right_Opnd (N);
6795 T : Entity_Id := Find_Unique_Type (L, R);
6797 procedure Check_If_Expression (Cond : Node_Id);
6798 -- The resolution rule for if expressions requires that each such must
6799 -- have a unique type. This means that if several dependent expressions
6800 -- are of a non-null anonymous access type, and the context does not
6801 -- impose an expected type (as can be the case in an equality operation)
6802 -- the expression must be rejected.
6804 function Find_Unique_Access_Type return Entity_Id;
6805 -- In the case of allocators, make a last-ditch attempt to find a single
6806 -- access type with the right designated type. This is semantically
6807 -- dubious, and of no interest to any real code, but c48008a makes it
6808 -- all worthwhile.
6810 -------------------------
6811 -- Check_If_Expression --
6812 -------------------------
6814 procedure Check_If_Expression (Cond : Node_Id) is
6815 Then_Expr : Node_Id;
6816 Else_Expr : Node_Id;
6818 begin
6819 if Nkind (Cond) = N_If_Expression then
6820 Then_Expr := Next (First (Expressions (Cond)));
6821 Else_Expr := Next (Then_Expr);
6823 if Nkind (Then_Expr) /= N_Null
6824 and then Nkind (Else_Expr) /= N_Null
6825 then
6826 Error_Msg_N ("cannot determine type of if expression", Cond);
6827 end if;
6828 end if;
6829 end Check_If_Expression;
6831 -----------------------------
6832 -- Find_Unique_Access_Type --
6833 -----------------------------
6835 function Find_Unique_Access_Type return Entity_Id is
6836 Acc : Entity_Id;
6837 E : Entity_Id;
6838 S : Entity_Id;
6840 begin
6841 if Ekind (Etype (R)) = E_Allocator_Type then
6842 Acc := Designated_Type (Etype (R));
6843 elsif Ekind (Etype (L)) = E_Allocator_Type then
6844 Acc := Designated_Type (Etype (L));
6845 else
6846 return Empty;
6847 end if;
6849 S := Current_Scope;
6850 while S /= Standard_Standard loop
6851 E := First_Entity (S);
6852 while Present (E) loop
6853 if Is_Type (E)
6854 and then Is_Access_Type (E)
6855 and then Ekind (E) /= E_Allocator_Type
6856 and then Designated_Type (E) = Base_Type (Acc)
6857 then
6858 return E;
6859 end if;
6861 Next_Entity (E);
6862 end loop;
6864 S := Scope (S);
6865 end loop;
6867 return Empty;
6868 end Find_Unique_Access_Type;
6870 -- Start of processing for Resolve_Equality_Op
6872 begin
6873 Set_Etype (N, Base_Type (Typ));
6874 Generate_Reference (T, N, ' ');
6876 if T = Any_Fixed then
6877 T := Unique_Fixed_Point_Type (L);
6878 end if;
6880 if T /= Any_Type then
6881 if T = Any_String or else
6882 T = Any_Composite or else
6883 T = Any_Character
6884 then
6885 if T = Any_Character then
6886 Ambiguous_Character (L);
6887 else
6888 Error_Msg_N ("ambiguous operands for equality", N);
6889 end if;
6891 Set_Etype (N, Any_Type);
6892 return;
6894 elsif T = Any_Access
6895 or else Ekind_In (T, E_Allocator_Type, E_Access_Attribute_Type)
6896 then
6897 T := Find_Unique_Access_Type;
6899 if No (T) then
6900 Error_Msg_N ("ambiguous operands for equality", N);
6901 Set_Etype (N, Any_Type);
6902 return;
6903 end if;
6905 -- If expressions must have a single type, and if the context does
6906 -- not impose one the dependent expressions cannot be anonymous
6907 -- access types.
6909 -- Why no similar processing for case expressions???
6911 elsif Ada_Version >= Ada_2012
6912 and then Ekind_In (Etype (L), E_Anonymous_Access_Type,
6913 E_Anonymous_Access_Subprogram_Type)
6914 and then Ekind_In (Etype (R), E_Anonymous_Access_Type,
6915 E_Anonymous_Access_Subprogram_Type)
6916 then
6917 Check_If_Expression (L);
6918 Check_If_Expression (R);
6919 end if;
6921 Resolve (L, T);
6922 Resolve (R, T);
6924 -- In SPARK, equality operators = and /= for array types other than
6925 -- String are only defined when, for each index position, the
6926 -- operands have equal static bounds.
6928 if Is_Array_Type (T) then
6930 -- Protect call to Matching_Static_Array_Bounds to avoid costly
6931 -- operation if not needed.
6933 if Restriction_Check_Required (SPARK)
6934 and then Base_Type (T) /= Standard_String
6935 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
6936 and then Etype (L) /= Any_Composite -- or else L in error
6937 and then Etype (R) /= Any_Composite -- or else R in error
6938 and then not Matching_Static_Array_Bounds (Etype (L), Etype (R))
6939 then
6940 Check_SPARK_Restriction
6941 ("array types should have matching static bounds", N);
6942 end if;
6943 end if;
6945 -- If the unique type is a class-wide type then it will be expanded
6946 -- into a dispatching call to the predefined primitive. Therefore we
6947 -- check here for potential violation of such restriction.
6949 if Is_Class_Wide_Type (T) then
6950 Check_Restriction (No_Dispatching_Calls, N);
6951 end if;
6953 if Warn_On_Redundant_Constructs
6954 and then Comes_From_Source (N)
6955 and then Is_Entity_Name (R)
6956 and then Entity (R) = Standard_True
6957 and then Comes_From_Source (R)
6958 then
6959 Error_Msg_N -- CODEFIX
6960 ("?comparison with True is redundant!", R);
6961 end if;
6963 Check_Unset_Reference (L);
6964 Check_Unset_Reference (R);
6965 Generate_Operator_Reference (N, T);
6966 Check_Low_Bound_Tested (N);
6968 -- If this is an inequality, it may be the implicit inequality
6969 -- created for a user-defined operation, in which case the corres-
6970 -- ponding equality operation is not intrinsic, and the operation
6971 -- cannot be constant-folded. Else fold.
6973 if Nkind (N) = N_Op_Eq
6974 or else Comes_From_Source (Entity (N))
6975 or else Ekind (Entity (N)) = E_Operator
6976 or else Is_Intrinsic_Subprogram
6977 (Corresponding_Equality (Entity (N)))
6978 then
6979 Analyze_Dimension (N);
6980 Eval_Relational_Op (N);
6982 elsif Nkind (N) = N_Op_Ne
6983 and then Is_Abstract_Subprogram (Entity (N))
6984 then
6985 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
6986 end if;
6988 -- Ada 2005: If one operand is an anonymous access type, convert the
6989 -- other operand to it, to ensure that the underlying types match in
6990 -- the back-end. Same for access_to_subprogram, and the conversion
6991 -- verifies that the types are subtype conformant.
6993 -- We apply the same conversion in the case one of the operands is a
6994 -- private subtype of the type of the other.
6996 -- Why the Expander_Active test here ???
6998 if Full_Expander_Active
6999 and then
7000 (Ekind_In (T, E_Anonymous_Access_Type,
7001 E_Anonymous_Access_Subprogram_Type)
7002 or else Is_Private_Type (T))
7003 then
7004 if Etype (L) /= T then
7005 Rewrite (L,
7006 Make_Unchecked_Type_Conversion (Sloc (L),
7007 Subtype_Mark => New_Occurrence_Of (T, Sloc (L)),
7008 Expression => Relocate_Node (L)));
7009 Analyze_And_Resolve (L, T);
7010 end if;
7012 if (Etype (R)) /= T then
7013 Rewrite (R,
7014 Make_Unchecked_Type_Conversion (Sloc (R),
7015 Subtype_Mark => New_Occurrence_Of (Etype (L), Sloc (R)),
7016 Expression => Relocate_Node (R)));
7017 Analyze_And_Resolve (R, T);
7018 end if;
7019 end if;
7020 end if;
7021 end Resolve_Equality_Op;
7023 ----------------------------------
7024 -- Resolve_Explicit_Dereference --
7025 ----------------------------------
7027 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
7028 Loc : constant Source_Ptr := Sloc (N);
7029 New_N : Node_Id;
7030 P : constant Node_Id := Prefix (N);
7032 P_Typ : Entity_Id;
7033 -- The candidate prefix type, if overloaded
7035 I : Interp_Index;
7036 It : Interp;
7038 begin
7039 Check_Fully_Declared_Prefix (Typ, P);
7040 P_Typ := Empty;
7042 if Is_Overloaded (P) then
7044 -- Use the context type to select the prefix that has the correct
7045 -- designated type. Keep the first match, which will be the inner-
7046 -- most.
7048 Get_First_Interp (P, I, It);
7050 while Present (It.Typ) loop
7051 if Is_Access_Type (It.Typ)
7052 and then Covers (Typ, Designated_Type (It.Typ))
7053 then
7054 if No (P_Typ) then
7055 P_Typ := It.Typ;
7056 end if;
7058 -- Remove access types that do not match, but preserve access
7059 -- to subprogram interpretations, in case a further dereference
7060 -- is needed (see below).
7062 elsif Ekind (It.Typ) /= E_Access_Subprogram_Type then
7063 Remove_Interp (I);
7064 end if;
7066 Get_Next_Interp (I, It);
7067 end loop;
7069 if Present (P_Typ) then
7070 Resolve (P, P_Typ);
7071 Set_Etype (N, Designated_Type (P_Typ));
7073 else
7074 -- If no interpretation covers the designated type of the prefix,
7075 -- this is the pathological case where not all implementations of
7076 -- the prefix allow the interpretation of the node as a call. Now
7077 -- that the expected type is known, Remove other interpretations
7078 -- from prefix, rewrite it as a call, and resolve again, so that
7079 -- the proper call node is generated.
7081 Get_First_Interp (P, I, It);
7082 while Present (It.Typ) loop
7083 if Ekind (It.Typ) /= E_Access_Subprogram_Type then
7084 Remove_Interp (I);
7085 end if;
7087 Get_Next_Interp (I, It);
7088 end loop;
7090 New_N :=
7091 Make_Function_Call (Loc,
7092 Name =>
7093 Make_Explicit_Dereference (Loc,
7094 Prefix => P),
7095 Parameter_Associations => New_List);
7097 Save_Interps (N, New_N);
7098 Rewrite (N, New_N);
7099 Analyze_And_Resolve (N, Typ);
7100 return;
7101 end if;
7103 -- If not overloaded, resolve P with its own type
7105 else
7106 Resolve (P);
7107 end if;
7109 if Is_Access_Type (Etype (P)) then
7110 Apply_Access_Check (N);
7111 end if;
7113 -- If the designated type is a packed unconstrained array type, and the
7114 -- explicit dereference is not in the context of an attribute reference,
7115 -- then we must compute and set the actual subtype, since it is needed
7116 -- by Gigi. The reason we exclude the attribute case is that this is
7117 -- handled fine by Gigi, and in fact we use such attributes to build the
7118 -- actual subtype. We also exclude generated code (which builds actual
7119 -- subtypes directly if they are needed).
7121 if Is_Array_Type (Etype (N))
7122 and then Is_Packed (Etype (N))
7123 and then not Is_Constrained (Etype (N))
7124 and then Nkind (Parent (N)) /= N_Attribute_Reference
7125 and then Comes_From_Source (N)
7126 then
7127 Set_Etype (N, Get_Actual_Subtype (N));
7128 end if;
7130 -- Note: No Eval processing is required for an explicit dereference,
7131 -- because such a name can never be static.
7133 end Resolve_Explicit_Dereference;
7135 -------------------------------------
7136 -- Resolve_Expression_With_Actions --
7137 -------------------------------------
7139 procedure Resolve_Expression_With_Actions (N : Node_Id; Typ : Entity_Id) is
7140 begin
7141 Set_Etype (N, Typ);
7142 end Resolve_Expression_With_Actions;
7144 ---------------------------
7145 -- Resolve_If_Expression --
7146 ---------------------------
7148 procedure Resolve_If_Expression (N : Node_Id; Typ : Entity_Id) is
7149 Condition : constant Node_Id := First (Expressions (N));
7150 Then_Expr : constant Node_Id := Next (Condition);
7151 Else_Expr : Node_Id := Next (Then_Expr);
7152 Else_Typ : Entity_Id;
7153 Then_Typ : Entity_Id;
7155 begin
7156 Resolve (Condition, Any_Boolean);
7157 Resolve (Then_Expr, Typ);
7158 Then_Typ := Etype (Then_Expr);
7160 -- When the "then" expression is of a scalar type different from the
7161 -- result type, then insert a conversion to ensure the generation of
7162 -- a constraint check.
7164 if Is_Scalar_Type (Then_Typ)
7165 and then Base_Type (Then_Typ) /= Base_Type (Typ)
7166 then
7167 Rewrite (Then_Expr, Convert_To (Typ, Then_Expr));
7168 Analyze_And_Resolve (Then_Expr, Typ);
7169 end if;
7171 -- If ELSE expression present, just resolve using the determined type
7173 if Present (Else_Expr) then
7174 Resolve (Else_Expr, Typ);
7175 Else_Typ := Etype (Else_Expr);
7177 if Is_Scalar_Type (Else_Typ)
7178 and then Else_Typ /= Typ
7179 then
7180 Rewrite (Else_Expr, Convert_To (Typ, Else_Expr));
7181 Analyze_And_Resolve (Else_Expr, Typ);
7182 end if;
7184 -- If no ELSE expression is present, root type must be Standard.Boolean
7185 -- and we provide a Standard.True result converted to the appropriate
7186 -- Boolean type (in case it is a derived boolean type).
7188 elsif Root_Type (Typ) = Standard_Boolean then
7189 Else_Expr :=
7190 Convert_To (Typ, New_Occurrence_Of (Standard_True, Sloc (N)));
7191 Analyze_And_Resolve (Else_Expr, Typ);
7192 Append_To (Expressions (N), Else_Expr);
7194 else
7195 Error_Msg_N ("can only omit ELSE expression in Boolean case", N);
7196 Append_To (Expressions (N), Error);
7197 end if;
7199 Set_Etype (N, Typ);
7200 Eval_If_Expression (N);
7202 -- If we still have a if expression, and overflow checks are enabled in
7203 -- MINIMIZED or ELIMINATED modes, then set Do_Overflow_Check to ensure
7204 -- that we handle overflow for dependent expressions.
7206 if Nkind (N) = N_If_Expression
7207 and then Overflow_Check_Mode (Typ) in Minimized_Or_Eliminated
7208 then
7209 Set_Do_Overflow_Check (N);
7210 end if;
7211 end Resolve_If_Expression;
7213 -------------------------------
7214 -- Resolve_Indexed_Component --
7215 -------------------------------
7217 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
7218 Name : constant Node_Id := Prefix (N);
7219 Expr : Node_Id;
7220 Array_Type : Entity_Id := Empty; -- to prevent junk warning
7221 Index : Node_Id;
7223 begin
7224 if Is_Overloaded (Name) then
7226 -- Use the context type to select the prefix that yields the correct
7227 -- component type.
7229 declare
7230 I : Interp_Index;
7231 It : Interp;
7232 I1 : Interp_Index := 0;
7233 P : constant Node_Id := Prefix (N);
7234 Found : Boolean := False;
7236 begin
7237 Get_First_Interp (P, I, It);
7238 while Present (It.Typ) loop
7239 if (Is_Array_Type (It.Typ)
7240 and then Covers (Typ, Component_Type (It.Typ)))
7241 or else (Is_Access_Type (It.Typ)
7242 and then Is_Array_Type (Designated_Type (It.Typ))
7243 and then
7244 Covers
7245 (Typ,
7246 Component_Type (Designated_Type (It.Typ))))
7247 then
7248 if Found then
7249 It := Disambiguate (P, I1, I, Any_Type);
7251 if It = No_Interp then
7252 Error_Msg_N ("ambiguous prefix for indexing", N);
7253 Set_Etype (N, Typ);
7254 return;
7256 else
7257 Found := True;
7258 Array_Type := It.Typ;
7259 I1 := I;
7260 end if;
7262 else
7263 Found := True;
7264 Array_Type := It.Typ;
7265 I1 := I;
7266 end if;
7267 end if;
7269 Get_Next_Interp (I, It);
7270 end loop;
7271 end;
7273 else
7274 Array_Type := Etype (Name);
7275 end if;
7277 Resolve (Name, Array_Type);
7278 Array_Type := Get_Actual_Subtype_If_Available (Name);
7280 -- If prefix is access type, dereference to get real array type.
7281 -- Note: we do not apply an access check because the expander always
7282 -- introduces an explicit dereference, and the check will happen there.
7284 if Is_Access_Type (Array_Type) then
7285 Array_Type := Designated_Type (Array_Type);
7286 end if;
7288 -- If name was overloaded, set component type correctly now
7289 -- If a misplaced call to an entry family (which has no index types)
7290 -- return. Error will be diagnosed from calling context.
7292 if Is_Array_Type (Array_Type) then
7293 Set_Etype (N, Component_Type (Array_Type));
7294 else
7295 return;
7296 end if;
7298 Index := First_Index (Array_Type);
7299 Expr := First (Expressions (N));
7301 -- The prefix may have resolved to a string literal, in which case its
7302 -- etype has a special representation. This is only possible currently
7303 -- if the prefix is a static concatenation, written in functional
7304 -- notation.
7306 if Ekind (Array_Type) = E_String_Literal_Subtype then
7307 Resolve (Expr, Standard_Positive);
7309 else
7310 while Present (Index) and Present (Expr) loop
7311 Resolve (Expr, Etype (Index));
7312 Check_Unset_Reference (Expr);
7314 if Is_Scalar_Type (Etype (Expr)) then
7315 Apply_Scalar_Range_Check (Expr, Etype (Index));
7316 else
7317 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
7318 end if;
7320 Next_Index (Index);
7321 Next (Expr);
7322 end loop;
7323 end if;
7325 Analyze_Dimension (N);
7327 -- Do not generate the warning on suspicious index if we are analyzing
7328 -- package Ada.Tags; otherwise we will report the warning with the
7329 -- Prims_Ptr field of the dispatch table.
7331 if Scope (Etype (Prefix (N))) = Standard_Standard
7332 or else not
7333 Is_RTU (Cunit_Entity (Get_Source_Unit (Etype (Prefix (N)))),
7334 Ada_Tags)
7335 then
7336 Warn_On_Suspicious_Index (Name, First (Expressions (N)));
7337 Eval_Indexed_Component (N);
7338 end if;
7340 -- If the array type is atomic, and is packed, and we are in a left side
7341 -- context, then this is worth a warning, since we have a situation
7342 -- where the access to the component may cause extra read/writes of
7343 -- the atomic array object, which could be considered unexpected.
7345 if Nkind (N) = N_Indexed_Component
7346 and then (Is_Atomic (Array_Type)
7347 or else (Is_Entity_Name (Prefix (N))
7348 and then Is_Atomic (Entity (Prefix (N)))))
7349 and then Is_Bit_Packed_Array (Array_Type)
7350 and then Is_LHS (N)
7351 then
7352 Error_Msg_N ("?assignment to component of packed atomic array",
7353 Prefix (N));
7354 Error_Msg_N ("?\may cause unexpected accesses to atomic object",
7355 Prefix (N));
7356 end if;
7357 end Resolve_Indexed_Component;
7359 -----------------------------
7360 -- Resolve_Integer_Literal --
7361 -----------------------------
7363 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
7364 begin
7365 Set_Etype (N, Typ);
7366 Eval_Integer_Literal (N);
7367 end Resolve_Integer_Literal;
7369 --------------------------------
7370 -- Resolve_Intrinsic_Operator --
7371 --------------------------------
7373 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
7374 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
7375 Op : Entity_Id;
7376 Orig_Op : constant Entity_Id := Entity (N);
7377 Arg1 : Node_Id;
7378 Arg2 : Node_Id;
7380 function Convert_Operand (Opnd : Node_Id) return Node_Id;
7381 -- If the operand is a literal, it cannot be the expression in a
7382 -- conversion. Use a qualified expression instead.
7384 function Convert_Operand (Opnd : Node_Id) return Node_Id is
7385 Loc : constant Source_Ptr := Sloc (Opnd);
7386 Res : Node_Id;
7387 begin
7388 if Nkind_In (Opnd, N_Integer_Literal, N_Real_Literal) then
7389 Res :=
7390 Make_Qualified_Expression (Loc,
7391 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
7392 Expression => Relocate_Node (Opnd));
7393 Analyze (Res);
7395 else
7396 Res := Unchecked_Convert_To (Btyp, Opnd);
7397 end if;
7399 return Res;
7400 end Convert_Operand;
7402 -- Start of processing for Resolve_Intrinsic_Operator
7404 begin
7405 -- We must preserve the original entity in a generic setting, so that
7406 -- the legality of the operation can be verified in an instance.
7408 if not Full_Expander_Active then
7409 return;
7410 end if;
7412 Op := Entity (N);
7413 while Scope (Op) /= Standard_Standard loop
7414 Op := Homonym (Op);
7415 pragma Assert (Present (Op));
7416 end loop;
7418 Set_Entity (N, Op);
7419 Set_Is_Overloaded (N, False);
7421 -- If the result or operand types are private, rewrite with unchecked
7422 -- conversions on the operands and the result, to expose the proper
7423 -- underlying numeric type.
7425 if Is_Private_Type (Typ)
7426 or else Is_Private_Type (Etype (Left_Opnd (N)))
7427 or else Is_Private_Type (Etype (Right_Opnd (N)))
7428 then
7429 Arg1 := Convert_Operand (Left_Opnd (N));
7430 -- Unchecked_Convert_To (Btyp, Left_Opnd (N));
7431 -- What on earth is this commented out fragment of code???
7433 if Nkind (N) = N_Op_Expon then
7434 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
7435 else
7436 Arg2 := Convert_Operand (Right_Opnd (N));
7437 end if;
7439 if Nkind (Arg1) = N_Type_Conversion then
7440 Save_Interps (Left_Opnd (N), Expression (Arg1));
7441 end if;
7443 if Nkind (Arg2) = N_Type_Conversion then
7444 Save_Interps (Right_Opnd (N), Expression (Arg2));
7445 end if;
7447 Set_Left_Opnd (N, Arg1);
7448 Set_Right_Opnd (N, Arg2);
7450 Set_Etype (N, Btyp);
7451 Rewrite (N, Unchecked_Convert_To (Typ, N));
7452 Resolve (N, Typ);
7454 elsif Typ /= Etype (Left_Opnd (N))
7455 or else Typ /= Etype (Right_Opnd (N))
7456 then
7457 -- Add explicit conversion where needed, and save interpretations in
7458 -- case operands are overloaded. If the context is a VMS operation,
7459 -- assert that the conversion is legal (the operands have the proper
7460 -- types to select the VMS intrinsic). Note that in rare cases the
7461 -- VMS operators may be visible, but the default System is being used
7462 -- and Address is a private type.
7464 Arg1 := Convert_To (Typ, Left_Opnd (N));
7465 Arg2 := Convert_To (Typ, Right_Opnd (N));
7467 if Nkind (Arg1) = N_Type_Conversion then
7468 Save_Interps (Left_Opnd (N), Expression (Arg1));
7470 if Is_VMS_Operator (Orig_Op) then
7471 Set_Conversion_OK (Arg1);
7472 end if;
7473 else
7474 Save_Interps (Left_Opnd (N), Arg1);
7475 end if;
7477 if Nkind (Arg2) = N_Type_Conversion then
7478 Save_Interps (Right_Opnd (N), Expression (Arg2));
7480 if Is_VMS_Operator (Orig_Op) then
7481 Set_Conversion_OK (Arg2);
7482 end if;
7483 else
7484 Save_Interps (Right_Opnd (N), Arg2);
7485 end if;
7487 Rewrite (Left_Opnd (N), Arg1);
7488 Rewrite (Right_Opnd (N), Arg2);
7489 Analyze (Arg1);
7490 Analyze (Arg2);
7491 Resolve_Arithmetic_Op (N, Typ);
7493 else
7494 Resolve_Arithmetic_Op (N, Typ);
7495 end if;
7496 end Resolve_Intrinsic_Operator;
7498 --------------------------------------
7499 -- Resolve_Intrinsic_Unary_Operator --
7500 --------------------------------------
7502 procedure Resolve_Intrinsic_Unary_Operator
7503 (N : Node_Id;
7504 Typ : Entity_Id)
7506 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
7507 Op : Entity_Id;
7508 Arg2 : Node_Id;
7510 begin
7511 Op := Entity (N);
7512 while Scope (Op) /= Standard_Standard loop
7513 Op := Homonym (Op);
7514 pragma Assert (Present (Op));
7515 end loop;
7517 Set_Entity (N, Op);
7519 if Is_Private_Type (Typ) then
7520 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
7521 Save_Interps (Right_Opnd (N), Expression (Arg2));
7523 Set_Right_Opnd (N, Arg2);
7525 Set_Etype (N, Btyp);
7526 Rewrite (N, Unchecked_Convert_To (Typ, N));
7527 Resolve (N, Typ);
7529 else
7530 Resolve_Unary_Op (N, Typ);
7531 end if;
7532 end Resolve_Intrinsic_Unary_Operator;
7534 ------------------------
7535 -- Resolve_Logical_Op --
7536 ------------------------
7538 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
7539 B_Typ : Entity_Id;
7541 begin
7542 Check_No_Direct_Boolean_Operators (N);
7544 -- Predefined operations on scalar types yield the base type. On the
7545 -- other hand, logical operations on arrays yield the type of the
7546 -- arguments (and the context).
7548 if Is_Array_Type (Typ) then
7549 B_Typ := Typ;
7550 else
7551 B_Typ := Base_Type (Typ);
7552 end if;
7554 -- OK if this is a VMS-specific intrinsic operation
7556 if Is_VMS_Operator (Entity (N)) then
7557 null;
7559 -- The following test is required because the operands of the operation
7560 -- may be literals, in which case the resulting type appears to be
7561 -- compatible with a signed integer type, when in fact it is compatible
7562 -- only with modular types. If the context itself is universal, the
7563 -- operation is illegal.
7565 elsif not Valid_Boolean_Arg (Typ) then
7566 Error_Msg_N ("invalid context for logical operation", N);
7567 Set_Etype (N, Any_Type);
7568 return;
7570 elsif Typ = Any_Modular then
7571 Error_Msg_N
7572 ("no modular type available in this context", N);
7573 Set_Etype (N, Any_Type);
7574 return;
7576 elsif Is_Modular_Integer_Type (Typ)
7577 and then Etype (Left_Opnd (N)) = Universal_Integer
7578 and then Etype (Right_Opnd (N)) = Universal_Integer
7579 then
7580 Check_For_Visible_Operator (N, B_Typ);
7581 end if;
7583 -- Replace AND by AND THEN, or OR by OR ELSE, if Short_Circuit_And_Or
7584 -- is active and the result type is standard Boolean (do not mess with
7585 -- ops that return a nonstandard Boolean type, because something strange
7586 -- is going on).
7588 -- Note: you might expect this replacement to be done during expansion,
7589 -- but that doesn't work, because when the pragma Short_Circuit_And_Or
7590 -- is used, no part of the right operand of an "and" or "or" operator
7591 -- should be executed if the left operand would short-circuit the
7592 -- evaluation of the corresponding "and then" or "or else". If we left
7593 -- the replacement to expansion time, then run-time checks associated
7594 -- with such operands would be evaluated unconditionally, due to being
7595 -- before the condition prior to the rewriting as short-circuit forms
7596 -- during expansion.
7598 if Short_Circuit_And_Or
7599 and then B_Typ = Standard_Boolean
7600 and then Nkind_In (N, N_Op_And, N_Op_Or)
7601 then
7602 if Nkind (N) = N_Op_And then
7603 Rewrite (N,
7604 Make_And_Then (Sloc (N),
7605 Left_Opnd => Relocate_Node (Left_Opnd (N)),
7606 Right_Opnd => Relocate_Node (Right_Opnd (N))));
7607 Analyze_And_Resolve (N, B_Typ);
7609 -- Case of OR changed to OR ELSE
7611 else
7612 Rewrite (N,
7613 Make_Or_Else (Sloc (N),
7614 Left_Opnd => Relocate_Node (Left_Opnd (N)),
7615 Right_Opnd => Relocate_Node (Right_Opnd (N))));
7616 Analyze_And_Resolve (N, B_Typ);
7617 end if;
7619 -- Return now, since analysis of the rewritten ops will take care of
7620 -- other reference bookkeeping and expression folding.
7622 return;
7623 end if;
7625 Resolve (Left_Opnd (N), B_Typ);
7626 Resolve (Right_Opnd (N), B_Typ);
7628 Check_Unset_Reference (Left_Opnd (N));
7629 Check_Unset_Reference (Right_Opnd (N));
7631 Set_Etype (N, B_Typ);
7632 Generate_Operator_Reference (N, B_Typ);
7633 Eval_Logical_Op (N);
7635 -- In SPARK, logical operations AND, OR and XOR for arrays are defined
7636 -- only when both operands have same static lower and higher bounds. Of
7637 -- course the types have to match, so only check if operands are
7638 -- compatible and the node itself has no errors.
7640 if Is_Array_Type (B_Typ)
7641 and then Nkind (N) in N_Binary_Op
7642 then
7643 declare
7644 Left_Typ : constant Node_Id := Etype (Left_Opnd (N));
7645 Right_Typ : constant Node_Id := Etype (Right_Opnd (N));
7647 begin
7648 -- Protect call to Matching_Static_Array_Bounds to avoid costly
7649 -- operation if not needed.
7651 if Restriction_Check_Required (SPARK)
7652 and then Base_Type (Left_Typ) = Base_Type (Right_Typ)
7653 and then Left_Typ /= Any_Composite -- or Left_Opnd in error
7654 and then Right_Typ /= Any_Composite -- or Right_Opnd in error
7655 and then not Matching_Static_Array_Bounds (Left_Typ, Right_Typ)
7656 then
7657 Check_SPARK_Restriction
7658 ("array types should have matching static bounds", N);
7659 end if;
7660 end;
7661 end if;
7662 end Resolve_Logical_Op;
7664 ---------------------------
7665 -- Resolve_Membership_Op --
7666 ---------------------------
7668 -- The context can only be a boolean type, and does not determine the
7669 -- arguments. Arguments should be unambiguous, but the preference rule for
7670 -- universal types applies.
7672 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
7673 pragma Warnings (Off, Typ);
7675 L : constant Node_Id := Left_Opnd (N);
7676 R : constant Node_Id := Right_Opnd (N);
7677 T : Entity_Id;
7679 procedure Resolve_Set_Membership;
7680 -- Analysis has determined a unique type for the left operand. Use it to
7681 -- resolve the disjuncts.
7683 ----------------------------
7684 -- Resolve_Set_Membership --
7685 ----------------------------
7687 procedure Resolve_Set_Membership is
7688 Alt : Node_Id;
7690 begin
7691 Resolve (L, Etype (L));
7693 Alt := First (Alternatives (N));
7694 while Present (Alt) loop
7696 -- Alternative is an expression, a range
7697 -- or a subtype mark.
7699 if not Is_Entity_Name (Alt)
7700 or else not Is_Type (Entity (Alt))
7701 then
7702 Resolve (Alt, Etype (L));
7703 end if;
7705 Next (Alt);
7706 end loop;
7707 end Resolve_Set_Membership;
7709 -- Start of processing for Resolve_Membership_Op
7711 begin
7712 if L = Error or else R = Error then
7713 return;
7714 end if;
7716 if Present (Alternatives (N)) then
7717 Resolve_Set_Membership;
7718 return;
7720 elsif not Is_Overloaded (R)
7721 and then
7722 (Etype (R) = Universal_Integer
7723 or else
7724 Etype (R) = Universal_Real)
7725 and then Is_Overloaded (L)
7726 then
7727 T := Etype (R);
7729 -- Ada 2005 (AI-251): Support the following case:
7731 -- type I is interface;
7732 -- type T is tagged ...
7734 -- function Test (O : I'Class) is
7735 -- begin
7736 -- return O in T'Class.
7737 -- end Test;
7739 -- In this case we have nothing else to do. The membership test will be
7740 -- done at run time.
7742 elsif Ada_Version >= Ada_2005
7743 and then Is_Class_Wide_Type (Etype (L))
7744 and then Is_Interface (Etype (L))
7745 and then Is_Class_Wide_Type (Etype (R))
7746 and then not Is_Interface (Etype (R))
7747 then
7748 return;
7749 else
7750 T := Intersect_Types (L, R);
7751 end if;
7753 -- If mixed-mode operations are present and operands are all literal,
7754 -- the only interpretation involves Duration, which is probably not
7755 -- the intention of the programmer.
7757 if T = Any_Fixed then
7758 T := Unique_Fixed_Point_Type (N);
7760 if T = Any_Type then
7761 return;
7762 end if;
7763 end if;
7765 Resolve (L, T);
7766 Check_Unset_Reference (L);
7768 if Nkind (R) = N_Range
7769 and then not Is_Scalar_Type (T)
7770 then
7771 Error_Msg_N ("scalar type required for range", R);
7772 end if;
7774 if Is_Entity_Name (R) then
7775 Freeze_Expression (R);
7776 else
7777 Resolve (R, T);
7778 Check_Unset_Reference (R);
7779 end if;
7781 Eval_Membership_Op (N);
7782 end Resolve_Membership_Op;
7784 ------------------
7785 -- Resolve_Null --
7786 ------------------
7788 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
7789 Loc : constant Source_Ptr := Sloc (N);
7791 begin
7792 -- Handle restriction against anonymous null access values This
7793 -- restriction can be turned off using -gnatdj.
7795 -- Ada 2005 (AI-231): Remove restriction
7797 if Ada_Version < Ada_2005
7798 and then not Debug_Flag_J
7799 and then Ekind (Typ) = E_Anonymous_Access_Type
7800 and then Comes_From_Source (N)
7801 then
7802 -- In the common case of a call which uses an explicitly null value
7803 -- for an access parameter, give specialized error message.
7805 if Nkind (Parent (N)) in N_Subprogram_Call then
7806 Error_Msg_N
7807 ("null is not allowed as argument for an access parameter", N);
7809 -- Standard message for all other cases (are there any?)
7811 else
7812 Error_Msg_N
7813 ("null cannot be of an anonymous access type", N);
7814 end if;
7815 end if;
7817 -- Ada 2005 (AI-231): Generate the null-excluding check in case of
7818 -- assignment to a null-excluding object
7820 if Ada_Version >= Ada_2005
7821 and then Can_Never_Be_Null (Typ)
7822 and then Nkind (Parent (N)) = N_Assignment_Statement
7823 then
7824 if not Inside_Init_Proc then
7825 Insert_Action
7826 (Compile_Time_Constraint_Error (N,
7827 "(Ada 2005) null not allowed in null-excluding objects?"),
7828 Make_Raise_Constraint_Error (Loc,
7829 Reason => CE_Access_Check_Failed));
7830 else
7831 Insert_Action (N,
7832 Make_Raise_Constraint_Error (Loc,
7833 Reason => CE_Access_Check_Failed));
7834 end if;
7835 end if;
7837 -- In a distributed context, null for a remote access to subprogram may
7838 -- need to be replaced with a special record aggregate. In this case,
7839 -- return after having done the transformation.
7841 if (Ekind (Typ) = E_Record_Type
7842 or else Is_Remote_Access_To_Subprogram_Type (Typ))
7843 and then Remote_AST_Null_Value (N, Typ)
7844 then
7845 return;
7846 end if;
7848 -- The null literal takes its type from the context
7850 Set_Etype (N, Typ);
7851 end Resolve_Null;
7853 -----------------------
7854 -- Resolve_Op_Concat --
7855 -----------------------
7857 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
7859 -- We wish to avoid deep recursion, because concatenations are often
7860 -- deeply nested, as in A&B&...&Z. Therefore, we walk down the left
7861 -- operands nonrecursively until we find something that is not a simple
7862 -- concatenation (A in this case). We resolve that, and then walk back
7863 -- up the tree following Parent pointers, calling Resolve_Op_Concat_Rest
7864 -- to do the rest of the work at each level. The Parent pointers allow
7865 -- us to avoid recursion, and thus avoid running out of memory. See also
7866 -- Sem_Ch4.Analyze_Concatenation, where a similar approach is used.
7868 NN : Node_Id := N;
7869 Op1 : Node_Id;
7871 begin
7872 -- The following code is equivalent to:
7874 -- Resolve_Op_Concat_First (NN, Typ);
7875 -- Resolve_Op_Concat_Arg (N, ...);
7876 -- Resolve_Op_Concat_Rest (N, Typ);
7878 -- where the Resolve_Op_Concat_Arg call recurses back here if the left
7879 -- operand is a concatenation.
7881 -- Walk down left operands
7883 loop
7884 Resolve_Op_Concat_First (NN, Typ);
7885 Op1 := Left_Opnd (NN);
7886 exit when not (Nkind (Op1) = N_Op_Concat
7887 and then not Is_Array_Type (Component_Type (Typ))
7888 and then Entity (Op1) = Entity (NN));
7889 NN := Op1;
7890 end loop;
7892 -- Now (given the above example) NN is A&B and Op1 is A
7894 -- First resolve Op1 ...
7896 Resolve_Op_Concat_Arg (NN, Op1, Typ, Is_Component_Left_Opnd (NN));
7898 -- ... then walk NN back up until we reach N (where we started), calling
7899 -- Resolve_Op_Concat_Rest along the way.
7901 loop
7902 Resolve_Op_Concat_Rest (NN, Typ);
7903 exit when NN = N;
7904 NN := Parent (NN);
7905 end loop;
7907 if Base_Type (Etype (N)) /= Standard_String then
7908 Check_SPARK_Restriction
7909 ("result of concatenation should have type String", N);
7910 end if;
7911 end Resolve_Op_Concat;
7913 ---------------------------
7914 -- Resolve_Op_Concat_Arg --
7915 ---------------------------
7917 procedure Resolve_Op_Concat_Arg
7918 (N : Node_Id;
7919 Arg : Node_Id;
7920 Typ : Entity_Id;
7921 Is_Comp : Boolean)
7923 Btyp : constant Entity_Id := Base_Type (Typ);
7924 Ctyp : constant Entity_Id := Component_Type (Typ);
7926 begin
7927 if In_Instance then
7928 if Is_Comp
7929 or else (not Is_Overloaded (Arg)
7930 and then Etype (Arg) /= Any_Composite
7931 and then Covers (Ctyp, Etype (Arg)))
7932 then
7933 Resolve (Arg, Ctyp);
7934 else
7935 Resolve (Arg, Btyp);
7936 end if;
7938 -- If both Array & Array and Array & Component are visible, there is a
7939 -- potential ambiguity that must be reported.
7941 elsif Has_Compatible_Type (Arg, Ctyp) then
7942 if Nkind (Arg) = N_Aggregate
7943 and then Is_Composite_Type (Ctyp)
7944 then
7945 if Is_Private_Type (Ctyp) then
7946 Resolve (Arg, Btyp);
7948 -- If the operation is user-defined and not overloaded use its
7949 -- profile. The operation may be a renaming, in which case it has
7950 -- been rewritten, and we want the original profile.
7952 elsif not Is_Overloaded (N)
7953 and then Comes_From_Source (Entity (Original_Node (N)))
7954 and then Ekind (Entity (Original_Node (N))) = E_Function
7955 then
7956 Resolve (Arg,
7957 Etype
7958 (Next_Formal (First_Formal (Entity (Original_Node (N))))));
7959 return;
7961 -- Otherwise an aggregate may match both the array type and the
7962 -- component type.
7964 else
7965 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
7966 Set_Etype (Arg, Any_Type);
7967 end if;
7969 else
7970 if Is_Overloaded (Arg)
7971 and then Has_Compatible_Type (Arg, Typ)
7972 and then Etype (Arg) /= Any_Type
7973 then
7974 declare
7975 I : Interp_Index;
7976 It : Interp;
7977 Func : Entity_Id;
7979 begin
7980 Get_First_Interp (Arg, I, It);
7981 Func := It.Nam;
7982 Get_Next_Interp (I, It);
7984 -- Special-case the error message when the overloading is
7985 -- caused by a function that yields an array and can be
7986 -- called without parameters.
7988 if It.Nam = Func then
7989 Error_Msg_Sloc := Sloc (Func);
7990 Error_Msg_N ("ambiguous call to function#", Arg);
7991 Error_Msg_NE
7992 ("\\interpretation as call yields&", Arg, Typ);
7993 Error_Msg_NE
7994 ("\\interpretation as indexing of call yields&",
7995 Arg, Component_Type (Typ));
7997 else
7998 Error_Msg_N ("ambiguous operand for concatenation!", Arg);
8000 Get_First_Interp (Arg, I, It);
8001 while Present (It.Nam) loop
8002 Error_Msg_Sloc := Sloc (It.Nam);
8004 if Base_Type (It.Typ) = Btyp
8005 or else
8006 Base_Type (It.Typ) = Base_Type (Ctyp)
8007 then
8008 Error_Msg_N -- CODEFIX
8009 ("\\possible interpretation#", Arg);
8010 end if;
8012 Get_Next_Interp (I, It);
8013 end loop;
8014 end if;
8015 end;
8016 end if;
8018 Resolve (Arg, Component_Type (Typ));
8020 if Nkind (Arg) = N_String_Literal then
8021 Set_Etype (Arg, Component_Type (Typ));
8022 end if;
8024 if Arg = Left_Opnd (N) then
8025 Set_Is_Component_Left_Opnd (N);
8026 else
8027 Set_Is_Component_Right_Opnd (N);
8028 end if;
8029 end if;
8031 else
8032 Resolve (Arg, Btyp);
8033 end if;
8035 -- Concatenation is restricted in SPARK: each operand must be either a
8036 -- string literal, the name of a string constant, a static character or
8037 -- string expression, or another concatenation. Arg cannot be a
8038 -- concatenation here as callers of Resolve_Op_Concat_Arg call it
8039 -- separately on each final operand, past concatenation operations.
8041 if Is_Character_Type (Etype (Arg)) then
8042 if not Is_Static_Expression (Arg) then
8043 Check_SPARK_Restriction
8044 ("character operand for concatenation should be static", Arg);
8045 end if;
8047 elsif Is_String_Type (Etype (Arg)) then
8048 if not (Nkind_In (Arg, N_Identifier, N_Expanded_Name)
8049 and then Is_Constant_Object (Entity (Arg)))
8050 and then not Is_Static_Expression (Arg)
8051 then
8052 Check_SPARK_Restriction
8053 ("string operand for concatenation should be static", Arg);
8054 end if;
8056 -- Do not issue error on an operand that is neither a character nor a
8057 -- string, as the error is issued in Resolve_Op_Concat.
8059 else
8060 null;
8061 end if;
8063 Check_Unset_Reference (Arg);
8064 end Resolve_Op_Concat_Arg;
8066 -----------------------------
8067 -- Resolve_Op_Concat_First --
8068 -----------------------------
8070 procedure Resolve_Op_Concat_First (N : Node_Id; Typ : Entity_Id) is
8071 Btyp : constant Entity_Id := Base_Type (Typ);
8072 Op1 : constant Node_Id := Left_Opnd (N);
8073 Op2 : constant Node_Id := Right_Opnd (N);
8075 begin
8076 -- The parser folds an enormous sequence of concatenations of string
8077 -- literals into "" & "...", where the Is_Folded_In_Parser flag is set
8078 -- in the right operand. If the expression resolves to a predefined "&"
8079 -- operator, all is well. Otherwise, the parser's folding is wrong, so
8080 -- we give an error. See P_Simple_Expression in Par.Ch4.
8082 if Nkind (Op2) = N_String_Literal
8083 and then Is_Folded_In_Parser (Op2)
8084 and then Ekind (Entity (N)) = E_Function
8085 then
8086 pragma Assert (Nkind (Op1) = N_String_Literal -- should be ""
8087 and then String_Length (Strval (Op1)) = 0);
8088 Error_Msg_N ("too many user-defined concatenations", N);
8089 return;
8090 end if;
8092 Set_Etype (N, Btyp);
8094 if Is_Limited_Composite (Btyp) then
8095 Error_Msg_N ("concatenation not available for limited array", N);
8096 Explain_Limited_Type (Btyp, N);
8097 end if;
8098 end Resolve_Op_Concat_First;
8100 ----------------------------
8101 -- Resolve_Op_Concat_Rest --
8102 ----------------------------
8104 procedure Resolve_Op_Concat_Rest (N : Node_Id; Typ : Entity_Id) is
8105 Op1 : constant Node_Id := Left_Opnd (N);
8106 Op2 : constant Node_Id := Right_Opnd (N);
8108 begin
8109 Resolve_Op_Concat_Arg (N, Op2, Typ, Is_Component_Right_Opnd (N));
8111 Generate_Operator_Reference (N, Typ);
8113 if Is_String_Type (Typ) then
8114 Eval_Concatenation (N);
8115 end if;
8117 -- If this is not a static concatenation, but the result is a string
8118 -- type (and not an array of strings) ensure that static string operands
8119 -- have their subtypes properly constructed.
8121 if Nkind (N) /= N_String_Literal
8122 and then Is_Character_Type (Component_Type (Typ))
8123 then
8124 Set_String_Literal_Subtype (Op1, Typ);
8125 Set_String_Literal_Subtype (Op2, Typ);
8126 end if;
8127 end Resolve_Op_Concat_Rest;
8129 ----------------------
8130 -- Resolve_Op_Expon --
8131 ----------------------
8133 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
8134 B_Typ : constant Entity_Id := Base_Type (Typ);
8136 begin
8137 -- Catch attempts to do fixed-point exponentiation with universal
8138 -- operands, which is a case where the illegality is not caught during
8139 -- normal operator analysis.
8141 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
8142 Error_Msg_N ("exponentiation not available for fixed point", N);
8143 return;
8145 elsif Nkind (Parent (N)) in N_Op
8146 and then Is_Fixed_Point_Type (Etype (Parent (N)))
8147 and then Etype (N) = Universal_Real
8148 and then Comes_From_Source (N)
8149 then
8150 Error_Msg_N ("exponentiation not available for fixed point", N);
8151 return;
8152 end if;
8154 if Comes_From_Source (N)
8155 and then Ekind (Entity (N)) = E_Function
8156 and then Is_Imported (Entity (N))
8157 and then Is_Intrinsic_Subprogram (Entity (N))
8158 then
8159 Resolve_Intrinsic_Operator (N, Typ);
8160 return;
8161 end if;
8163 if Etype (Left_Opnd (N)) = Universal_Integer
8164 or else Etype (Left_Opnd (N)) = Universal_Real
8165 then
8166 Check_For_Visible_Operator (N, B_Typ);
8167 end if;
8169 -- We do the resolution using the base type, because intermediate values
8170 -- in expressions always are of the base type, not a subtype of it.
8172 Resolve (Left_Opnd (N), B_Typ);
8173 Resolve (Right_Opnd (N), Standard_Integer);
8175 Check_Unset_Reference (Left_Opnd (N));
8176 Check_Unset_Reference (Right_Opnd (N));
8178 Set_Etype (N, B_Typ);
8179 Generate_Operator_Reference (N, B_Typ);
8181 Analyze_Dimension (N);
8183 if Ada_Version >= Ada_2012 and then Has_Dimension_System (B_Typ) then
8184 -- Evaluate the exponentiation operator for dimensioned type
8186 Eval_Op_Expon_For_Dimensioned_Type (N, B_Typ);
8187 else
8188 Eval_Op_Expon (N);
8189 end if;
8191 -- Set overflow checking bit. Much cleverer code needed here eventually
8192 -- and perhaps the Resolve routines should be separated for the various
8193 -- arithmetic operations, since they will need different processing. ???
8195 if Nkind (N) in N_Op then
8196 if not Overflow_Checks_Suppressed (Etype (N)) then
8197 Enable_Overflow_Check (N);
8198 end if;
8199 end if;
8200 end Resolve_Op_Expon;
8202 --------------------
8203 -- Resolve_Op_Not --
8204 --------------------
8206 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
8207 B_Typ : Entity_Id;
8209 function Parent_Is_Boolean return Boolean;
8210 -- This function determines if the parent node is a boolean operator or
8211 -- operation (comparison op, membership test, or short circuit form) and
8212 -- the not in question is the left operand of this operation. Note that
8213 -- if the not is in parens, then false is returned.
8215 -----------------------
8216 -- Parent_Is_Boolean --
8217 -----------------------
8219 function Parent_Is_Boolean return Boolean is
8220 begin
8221 if Paren_Count (N) /= 0 then
8222 return False;
8224 else
8225 case Nkind (Parent (N)) is
8226 when N_Op_And |
8227 N_Op_Eq |
8228 N_Op_Ge |
8229 N_Op_Gt |
8230 N_Op_Le |
8231 N_Op_Lt |
8232 N_Op_Ne |
8233 N_Op_Or |
8234 N_Op_Xor |
8235 N_In |
8236 N_Not_In |
8237 N_And_Then |
8238 N_Or_Else =>
8240 return Left_Opnd (Parent (N)) = N;
8242 when others =>
8243 return False;
8244 end case;
8245 end if;
8246 end Parent_Is_Boolean;
8248 -- Start of processing for Resolve_Op_Not
8250 begin
8251 -- Predefined operations on scalar types yield the base type. On the
8252 -- other hand, logical operations on arrays yield the type of the
8253 -- arguments (and the context).
8255 if Is_Array_Type (Typ) then
8256 B_Typ := Typ;
8257 else
8258 B_Typ := Base_Type (Typ);
8259 end if;
8261 if Is_VMS_Operator (Entity (N)) then
8262 null;
8264 -- Straightforward case of incorrect arguments
8266 elsif not Valid_Boolean_Arg (Typ) then
8267 Error_Msg_N ("invalid operand type for operator&", N);
8268 Set_Etype (N, Any_Type);
8269 return;
8271 -- Special case of probable missing parens
8273 elsif Typ = Universal_Integer or else Typ = Any_Modular then
8274 if Parent_Is_Boolean then
8275 Error_Msg_N
8276 ("operand of not must be enclosed in parentheses",
8277 Right_Opnd (N));
8278 else
8279 Error_Msg_N
8280 ("no modular type available in this context", N);
8281 end if;
8283 Set_Etype (N, Any_Type);
8284 return;
8286 -- OK resolution of NOT
8288 else
8289 -- Warn if non-boolean types involved. This is a case like not a < b
8290 -- where a and b are modular, where we will get (not a) < b and most
8291 -- likely not (a < b) was intended.
8293 if Warn_On_Questionable_Missing_Parens
8294 and then not Is_Boolean_Type (Typ)
8295 and then Parent_Is_Boolean
8296 then
8297 Error_Msg_N ("?not expression should be parenthesized here!", N);
8298 end if;
8300 -- Warn on double negation if checking redundant constructs
8302 if Warn_On_Redundant_Constructs
8303 and then Comes_From_Source (N)
8304 and then Comes_From_Source (Right_Opnd (N))
8305 and then Root_Type (Typ) = Standard_Boolean
8306 and then Nkind (Right_Opnd (N)) = N_Op_Not
8307 then
8308 Error_Msg_N ("redundant double negation?", N);
8309 end if;
8311 -- Complete resolution and evaluation of NOT
8313 Resolve (Right_Opnd (N), B_Typ);
8314 Check_Unset_Reference (Right_Opnd (N));
8315 Set_Etype (N, B_Typ);
8316 Generate_Operator_Reference (N, B_Typ);
8317 Eval_Op_Not (N);
8318 end if;
8319 end Resolve_Op_Not;
8321 -----------------------------
8322 -- Resolve_Operator_Symbol --
8323 -----------------------------
8325 -- Nothing to be done, all resolved already
8327 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
8328 pragma Warnings (Off, N);
8329 pragma Warnings (Off, Typ);
8331 begin
8332 null;
8333 end Resolve_Operator_Symbol;
8335 ----------------------------------
8336 -- Resolve_Qualified_Expression --
8337 ----------------------------------
8339 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
8340 pragma Warnings (Off, Typ);
8342 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
8343 Expr : constant Node_Id := Expression (N);
8345 begin
8346 Resolve (Expr, Target_Typ);
8348 -- Protect call to Matching_Static_Array_Bounds to avoid costly
8349 -- operation if not needed.
8351 if Restriction_Check_Required (SPARK)
8352 and then Is_Array_Type (Target_Typ)
8353 and then Is_Array_Type (Etype (Expr))
8354 and then Etype (Expr) /= Any_Composite -- or else Expr in error
8355 and then not Matching_Static_Array_Bounds (Target_Typ, Etype (Expr))
8356 then
8357 Check_SPARK_Restriction
8358 ("array types should have matching static bounds", N);
8359 end if;
8361 -- A qualified expression requires an exact match of the type, class-
8362 -- wide matching is not allowed. However, if the qualifying type is
8363 -- specific and the expression has a class-wide type, it may still be
8364 -- okay, since it can be the result of the expansion of a call to a
8365 -- dispatching function, so we also have to check class-wideness of the
8366 -- type of the expression's original node.
8368 if (Is_Class_Wide_Type (Target_Typ)
8369 or else
8370 (Is_Class_Wide_Type (Etype (Expr))
8371 and then Is_Class_Wide_Type (Etype (Original_Node (Expr)))))
8372 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
8373 then
8374 Wrong_Type (Expr, Target_Typ);
8375 end if;
8377 -- If the target type is unconstrained, then we reset the type of the
8378 -- result from the type of the expression. For other cases, the actual
8379 -- subtype of the expression is the target type.
8381 if Is_Composite_Type (Target_Typ)
8382 and then not Is_Constrained (Target_Typ)
8383 then
8384 Set_Etype (N, Etype (Expr));
8385 end if;
8387 Analyze_Dimension (N);
8388 Eval_Qualified_Expression (N);
8389 end Resolve_Qualified_Expression;
8391 -------------------
8392 -- Resolve_Range --
8393 -------------------
8395 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
8396 L : constant Node_Id := Low_Bound (N);
8397 H : constant Node_Id := High_Bound (N);
8399 function First_Last_Ref return Boolean;
8400 -- Returns True if N is of the form X'First .. X'Last where X is the
8401 -- same entity for both attributes.
8403 --------------------
8404 -- First_Last_Ref --
8405 --------------------
8407 function First_Last_Ref return Boolean is
8408 Lorig : constant Node_Id := Original_Node (L);
8409 Horig : constant Node_Id := Original_Node (H);
8411 begin
8412 if Nkind (Lorig) = N_Attribute_Reference
8413 and then Nkind (Horig) = N_Attribute_Reference
8414 and then Attribute_Name (Lorig) = Name_First
8415 and then Attribute_Name (Horig) = Name_Last
8416 then
8417 declare
8418 PL : constant Node_Id := Prefix (Lorig);
8419 PH : constant Node_Id := Prefix (Horig);
8420 begin
8421 if Is_Entity_Name (PL)
8422 and then Is_Entity_Name (PH)
8423 and then Entity (PL) = Entity (PH)
8424 then
8425 return True;
8426 end if;
8427 end;
8428 end if;
8430 return False;
8431 end First_Last_Ref;
8433 -- Start of processing for Resolve_Range
8435 begin
8436 Set_Etype (N, Typ);
8437 Resolve (L, Typ);
8438 Resolve (H, Typ);
8440 -- Check for inappropriate range on unordered enumeration type
8442 if Bad_Unordered_Enumeration_Reference (N, Typ)
8444 -- Exclude X'First .. X'Last if X is the same entity for both
8446 and then not First_Last_Ref
8447 then
8448 Error_Msg ("subrange of unordered enumeration type?", Sloc (N));
8449 end if;
8451 Check_Unset_Reference (L);
8452 Check_Unset_Reference (H);
8454 -- We have to check the bounds for being within the base range as
8455 -- required for a non-static context. Normally this is automatic and
8456 -- done as part of evaluating expressions, but the N_Range node is an
8457 -- exception, since in GNAT we consider this node to be a subexpression,
8458 -- even though in Ada it is not. The circuit in Sem_Eval could check for
8459 -- this, but that would put the test on the main evaluation path for
8460 -- expressions.
8462 Check_Non_Static_Context (L);
8463 Check_Non_Static_Context (H);
8465 -- Check for an ambiguous range over character literals. This will
8466 -- happen with a membership test involving only literals.
8468 if Typ = Any_Character then
8469 Ambiguous_Character (L);
8470 Set_Etype (N, Any_Type);
8471 return;
8472 end if;
8474 -- If bounds are static, constant-fold them, so size computations are
8475 -- identical between front-end and back-end. Do not perform this
8476 -- transformation while analyzing generic units, as type information
8477 -- would be lost when reanalyzing the constant node in the instance.
8479 if Is_Discrete_Type (Typ) and then Full_Expander_Active then
8480 if Is_OK_Static_Expression (L) then
8481 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
8482 end if;
8484 if Is_OK_Static_Expression (H) then
8485 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
8486 end if;
8487 end if;
8488 end Resolve_Range;
8490 --------------------------
8491 -- Resolve_Real_Literal --
8492 --------------------------
8494 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
8495 Actual_Typ : constant Entity_Id := Etype (N);
8497 begin
8498 -- Special processing for fixed-point literals to make sure that the
8499 -- value is an exact multiple of small where this is required. We skip
8500 -- this for the universal real case, and also for generic types.
8502 if Is_Fixed_Point_Type (Typ)
8503 and then Typ /= Universal_Fixed
8504 and then Typ /= Any_Fixed
8505 and then not Is_Generic_Type (Typ)
8506 then
8507 declare
8508 Val : constant Ureal := Realval (N);
8509 Cintr : constant Ureal := Val / Small_Value (Typ);
8510 Cint : constant Uint := UR_Trunc (Cintr);
8511 Den : constant Uint := Norm_Den (Cintr);
8512 Stat : Boolean;
8514 begin
8515 -- Case of literal is not an exact multiple of the Small
8517 if Den /= 1 then
8519 -- For a source program literal for a decimal fixed-point type,
8520 -- this is statically illegal (RM 4.9(36)).
8522 if Is_Decimal_Fixed_Point_Type (Typ)
8523 and then Actual_Typ = Universal_Real
8524 and then Comes_From_Source (N)
8525 then
8526 Error_Msg_N ("value has extraneous low order digits", N);
8527 end if;
8529 -- Generate a warning if literal from source
8531 if Is_Static_Expression (N)
8532 and then Warn_On_Bad_Fixed_Value
8533 then
8534 Error_Msg_N
8535 ("?static fixed-point value is not a multiple of Small!",
8537 end if;
8539 -- Replace literal by a value that is the exact representation
8540 -- of a value of the type, i.e. a multiple of the small value,
8541 -- by truncation, since Machine_Rounds is false for all GNAT
8542 -- fixed-point types (RM 4.9(38)).
8544 Stat := Is_Static_Expression (N);
8545 Rewrite (N,
8546 Make_Real_Literal (Sloc (N),
8547 Realval => Small_Value (Typ) * Cint));
8549 Set_Is_Static_Expression (N, Stat);
8550 end if;
8552 -- In all cases, set the corresponding integer field
8554 Set_Corresponding_Integer_Value (N, Cint);
8555 end;
8556 end if;
8558 -- Now replace the actual type by the expected type as usual
8560 Set_Etype (N, Typ);
8561 Eval_Real_Literal (N);
8562 end Resolve_Real_Literal;
8564 -----------------------
8565 -- Resolve_Reference --
8566 -----------------------
8568 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
8569 P : constant Node_Id := Prefix (N);
8571 begin
8572 -- Replace general access with specific type
8574 if Ekind (Etype (N)) = E_Allocator_Type then
8575 Set_Etype (N, Base_Type (Typ));
8576 end if;
8578 Resolve (P, Designated_Type (Etype (N)));
8580 -- If we are taking the reference of a volatile entity, then treat it as
8581 -- a potential modification of this entity. This is too conservative,
8582 -- but necessary because remove side effects can cause transformations
8583 -- of normal assignments into reference sequences that otherwise fail to
8584 -- notice the modification.
8586 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
8587 Note_Possible_Modification (P, Sure => False);
8588 end if;
8589 end Resolve_Reference;
8591 --------------------------------
8592 -- Resolve_Selected_Component --
8593 --------------------------------
8595 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
8596 Comp : Entity_Id;
8597 Comp1 : Entity_Id := Empty; -- prevent junk warning
8598 P : constant Node_Id := Prefix (N);
8599 S : constant Node_Id := Selector_Name (N);
8600 T : Entity_Id := Etype (P);
8601 I : Interp_Index;
8602 I1 : Interp_Index := 0; -- prevent junk warning
8603 It : Interp;
8604 It1 : Interp;
8605 Found : Boolean;
8607 function Init_Component return Boolean;
8608 -- Check whether this is the initialization of a component within an
8609 -- init proc (by assignment or call to another init proc). If true,
8610 -- there is no need for a discriminant check.
8612 --------------------
8613 -- Init_Component --
8614 --------------------
8616 function Init_Component return Boolean is
8617 begin
8618 return Inside_Init_Proc
8619 and then Nkind (Prefix (N)) = N_Identifier
8620 and then Chars (Prefix (N)) = Name_uInit
8621 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
8622 end Init_Component;
8624 -- Start of processing for Resolve_Selected_Component
8626 begin
8627 if Is_Overloaded (P) then
8629 -- Use the context type to select the prefix that has a selector
8630 -- of the correct name and type.
8632 Found := False;
8633 Get_First_Interp (P, I, It);
8635 Search : while Present (It.Typ) loop
8636 if Is_Access_Type (It.Typ) then
8637 T := Designated_Type (It.Typ);
8638 else
8639 T := It.Typ;
8640 end if;
8642 -- Locate selected component. For a private prefix the selector
8643 -- can denote a discriminant.
8645 if Is_Record_Type (T) or else Is_Private_Type (T) then
8647 -- The visible components of a class-wide type are those of
8648 -- the root type.
8650 if Is_Class_Wide_Type (T) then
8651 T := Etype (T);
8652 end if;
8654 Comp := First_Entity (T);
8655 while Present (Comp) loop
8656 if Chars (Comp) = Chars (S)
8657 and then Covers (Etype (Comp), Typ)
8658 then
8659 if not Found then
8660 Found := True;
8661 I1 := I;
8662 It1 := It;
8663 Comp1 := Comp;
8665 else
8666 It := Disambiguate (P, I1, I, Any_Type);
8668 if It = No_Interp then
8669 Error_Msg_N
8670 ("ambiguous prefix for selected component", N);
8671 Set_Etype (N, Typ);
8672 return;
8674 else
8675 It1 := It;
8677 -- There may be an implicit dereference. Retrieve
8678 -- designated record type.
8680 if Is_Access_Type (It1.Typ) then
8681 T := Designated_Type (It1.Typ);
8682 else
8683 T := It1.Typ;
8684 end if;
8686 if Scope (Comp1) /= T then
8688 -- Resolution chooses the new interpretation.
8689 -- Find the component with the right name.
8691 Comp1 := First_Entity (T);
8692 while Present (Comp1)
8693 and then Chars (Comp1) /= Chars (S)
8694 loop
8695 Comp1 := Next_Entity (Comp1);
8696 end loop;
8697 end if;
8699 exit Search;
8700 end if;
8701 end if;
8702 end if;
8704 Comp := Next_Entity (Comp);
8705 end loop;
8706 end if;
8708 Get_Next_Interp (I, It);
8709 end loop Search;
8711 Resolve (P, It1.Typ);
8712 Set_Etype (N, Typ);
8713 Set_Entity_With_Style_Check (S, Comp1);
8715 else
8716 -- Resolve prefix with its type
8718 Resolve (P, T);
8719 end if;
8721 -- Generate cross-reference. We needed to wait until full overloading
8722 -- resolution was complete to do this, since otherwise we can't tell if
8723 -- we are an lvalue or not.
8725 if May_Be_Lvalue (N) then
8726 Generate_Reference (Entity (S), S, 'm');
8727 else
8728 Generate_Reference (Entity (S), S, 'r');
8729 end if;
8731 -- If prefix is an access type, the node will be transformed into an
8732 -- explicit dereference during expansion. The type of the node is the
8733 -- designated type of that of the prefix.
8735 if Is_Access_Type (Etype (P)) then
8736 T := Designated_Type (Etype (P));
8737 Check_Fully_Declared_Prefix (T, P);
8738 else
8739 T := Etype (P);
8740 end if;
8742 if Has_Discriminants (T)
8743 and then Ekind_In (Entity (S), E_Component, E_Discriminant)
8744 and then Present (Original_Record_Component (Entity (S)))
8745 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
8746 and then Present (Discriminant_Checking_Func
8747 (Original_Record_Component (Entity (S))))
8748 and then not Discriminant_Checks_Suppressed (T)
8749 and then not Init_Component
8750 then
8751 Set_Do_Discriminant_Check (N);
8752 end if;
8754 if Ekind (Entity (S)) = E_Void then
8755 Error_Msg_N ("premature use of component", S);
8756 end if;
8758 -- If the prefix is a record conversion, this may be a renamed
8759 -- discriminant whose bounds differ from those of the original
8760 -- one, so we must ensure that a range check is performed.
8762 if Nkind (P) = N_Type_Conversion
8763 and then Ekind (Entity (S)) = E_Discriminant
8764 and then Is_Discrete_Type (Typ)
8765 then
8766 Set_Etype (N, Base_Type (Typ));
8767 end if;
8769 -- Note: No Eval processing is required, because the prefix is of a
8770 -- record type, or protected type, and neither can possibly be static.
8772 -- If the array type is atomic, and is packed, and we are in a left side
8773 -- context, then this is worth a warning, since we have a situation
8774 -- where the access to the component may cause extra read/writes of the
8775 -- atomic array object, which could be considered unexpected.
8777 if Nkind (N) = N_Selected_Component
8778 and then (Is_Atomic (T)
8779 or else (Is_Entity_Name (Prefix (N))
8780 and then Is_Atomic (Entity (Prefix (N)))))
8781 and then Is_Packed (T)
8782 and then Is_LHS (N)
8783 then
8784 Error_Msg_N
8785 ("?assignment to component of packed atomic record", Prefix (N));
8786 Error_Msg_N
8787 ("?\may cause unexpected accesses to atomic object", Prefix (N));
8788 end if;
8790 Analyze_Dimension (N);
8791 end Resolve_Selected_Component;
8793 -------------------
8794 -- Resolve_Shift --
8795 -------------------
8797 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
8798 B_Typ : constant Entity_Id := Base_Type (Typ);
8799 L : constant Node_Id := Left_Opnd (N);
8800 R : constant Node_Id := Right_Opnd (N);
8802 begin
8803 -- We do the resolution using the base type, because intermediate values
8804 -- in expressions always are of the base type, not a subtype of it.
8806 Resolve (L, B_Typ);
8807 Resolve (R, Standard_Natural);
8809 Check_Unset_Reference (L);
8810 Check_Unset_Reference (R);
8812 Set_Etype (N, B_Typ);
8813 Generate_Operator_Reference (N, B_Typ);
8814 Eval_Shift (N);
8815 end Resolve_Shift;
8817 ---------------------------
8818 -- Resolve_Short_Circuit --
8819 ---------------------------
8821 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
8822 B_Typ : constant Entity_Id := Base_Type (Typ);
8823 L : constant Node_Id := Left_Opnd (N);
8824 R : constant Node_Id := Right_Opnd (N);
8826 begin
8827 Resolve (L, B_Typ);
8828 Resolve (R, B_Typ);
8830 -- Check for issuing warning for always False assert/check, this happens
8831 -- when assertions are turned off, in which case the pragma Assert/Check
8832 -- was transformed into:
8834 -- if False and then <condition> then ...
8836 -- and we detect this pattern
8838 if Warn_On_Assertion_Failure
8839 and then Is_Entity_Name (R)
8840 and then Entity (R) = Standard_False
8841 and then Nkind (Parent (N)) = N_If_Statement
8842 and then Nkind (N) = N_And_Then
8843 and then Is_Entity_Name (L)
8844 and then Entity (L) = Standard_False
8845 then
8846 declare
8847 Orig : constant Node_Id := Original_Node (Parent (N));
8849 begin
8850 if Nkind (Orig) = N_Pragma
8851 and then Pragma_Name (Orig) = Name_Assert
8852 then
8853 -- Don't want to warn if original condition is explicit False
8855 declare
8856 Expr : constant Node_Id :=
8857 Original_Node
8858 (Expression
8859 (First (Pragma_Argument_Associations (Orig))));
8860 begin
8861 if Is_Entity_Name (Expr)
8862 and then Entity (Expr) = Standard_False
8863 then
8864 null;
8865 else
8866 -- Issue warning. We do not want the deletion of the
8867 -- IF/AND-THEN to take this message with it. We achieve
8868 -- this by making sure that the expanded code points to
8869 -- the Sloc of the expression, not the original pragma.
8871 -- Note: Use Error_Msg_F here rather than Error_Msg_N.
8872 -- The source location of the expression is not usually
8873 -- the best choice here. For example, it gets located on
8874 -- the last AND keyword in a chain of boolean expressiond
8875 -- AND'ed together. It is best to put the message on the
8876 -- first character of the assertion, which is the effect
8877 -- of the First_Node call here.
8879 Error_Msg_F
8880 ("?assertion would fail at run time!",
8881 Expression
8882 (First (Pragma_Argument_Associations (Orig))));
8883 end if;
8884 end;
8886 -- Similar processing for Check pragma
8888 elsif Nkind (Orig) = N_Pragma
8889 and then Pragma_Name (Orig) = Name_Check
8890 then
8891 -- Don't want to warn if original condition is explicit False
8893 declare
8894 Expr : constant Node_Id :=
8895 Original_Node
8896 (Expression
8897 (Next (First
8898 (Pragma_Argument_Associations (Orig)))));
8899 begin
8900 if Is_Entity_Name (Expr)
8901 and then Entity (Expr) = Standard_False
8902 then
8903 null;
8905 -- Post warning
8907 else
8908 -- Again use Error_Msg_F rather than Error_Msg_N, see
8909 -- comment above for an explanation of why we do this.
8911 Error_Msg_F
8912 ("?check would fail at run time!",
8913 Expression
8914 (Last (Pragma_Argument_Associations (Orig))));
8915 end if;
8916 end;
8917 end if;
8918 end;
8919 end if;
8921 -- Continue with processing of short circuit
8923 Check_Unset_Reference (L);
8924 Check_Unset_Reference (R);
8926 Set_Etype (N, B_Typ);
8927 Eval_Short_Circuit (N);
8928 end Resolve_Short_Circuit;
8930 -------------------
8931 -- Resolve_Slice --
8932 -------------------
8934 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
8935 Drange : constant Node_Id := Discrete_Range (N);
8936 Name : constant Node_Id := Prefix (N);
8937 Array_Type : Entity_Id := Empty;
8938 Index_Type : Entity_Id;
8940 begin
8941 if Is_Overloaded (Name) then
8943 -- Use the context type to select the prefix that yields the correct
8944 -- array type.
8946 declare
8947 I : Interp_Index;
8948 I1 : Interp_Index := 0;
8949 It : Interp;
8950 P : constant Node_Id := Prefix (N);
8951 Found : Boolean := False;
8953 begin
8954 Get_First_Interp (P, I, It);
8955 while Present (It.Typ) loop
8956 if (Is_Array_Type (It.Typ)
8957 and then Covers (Typ, It.Typ))
8958 or else (Is_Access_Type (It.Typ)
8959 and then Is_Array_Type (Designated_Type (It.Typ))
8960 and then Covers (Typ, Designated_Type (It.Typ)))
8961 then
8962 if Found then
8963 It := Disambiguate (P, I1, I, Any_Type);
8965 if It = No_Interp then
8966 Error_Msg_N ("ambiguous prefix for slicing", N);
8967 Set_Etype (N, Typ);
8968 return;
8969 else
8970 Found := True;
8971 Array_Type := It.Typ;
8972 I1 := I;
8973 end if;
8974 else
8975 Found := True;
8976 Array_Type := It.Typ;
8977 I1 := I;
8978 end if;
8979 end if;
8981 Get_Next_Interp (I, It);
8982 end loop;
8983 end;
8985 else
8986 Array_Type := Etype (Name);
8987 end if;
8989 Resolve (Name, Array_Type);
8991 if Is_Access_Type (Array_Type) then
8992 Apply_Access_Check (N);
8993 Array_Type := Designated_Type (Array_Type);
8995 -- If the prefix is an access to an unconstrained array, we must use
8996 -- the actual subtype of the object to perform the index checks. The
8997 -- object denoted by the prefix is implicit in the node, so we build
8998 -- an explicit representation for it in order to compute the actual
8999 -- subtype.
9001 if not Is_Constrained (Array_Type) then
9002 Remove_Side_Effects (Prefix (N));
9004 declare
9005 Obj : constant Node_Id :=
9006 Make_Explicit_Dereference (Sloc (N),
9007 Prefix => New_Copy_Tree (Prefix (N)));
9008 begin
9009 Set_Etype (Obj, Array_Type);
9010 Set_Parent (Obj, Parent (N));
9011 Array_Type := Get_Actual_Subtype (Obj);
9012 end;
9013 end if;
9015 elsif Is_Entity_Name (Name)
9016 or else Nkind (Name) = N_Explicit_Dereference
9017 or else (Nkind (Name) = N_Function_Call
9018 and then not Is_Constrained (Etype (Name)))
9019 then
9020 Array_Type := Get_Actual_Subtype (Name);
9022 -- If the name is a selected component that depends on discriminants,
9023 -- build an actual subtype for it. This can happen only when the name
9024 -- itself is overloaded; otherwise the actual subtype is created when
9025 -- the selected component is analyzed.
9027 elsif Nkind (Name) = N_Selected_Component
9028 and then Full_Analysis
9029 and then Depends_On_Discriminant (First_Index (Array_Type))
9030 then
9031 declare
9032 Act_Decl : constant Node_Id :=
9033 Build_Actual_Subtype_Of_Component (Array_Type, Name);
9034 begin
9035 Insert_Action (N, Act_Decl);
9036 Array_Type := Defining_Identifier (Act_Decl);
9037 end;
9039 -- Maybe this should just be "else", instead of checking for the
9040 -- specific case of slice??? This is needed for the case where the
9041 -- prefix is an Image attribute, which gets expanded to a slice, and so
9042 -- has a constrained subtype which we want to use for the slice range
9043 -- check applied below (the range check won't get done if the
9044 -- unconstrained subtype of the 'Image is used).
9046 elsif Nkind (Name) = N_Slice then
9047 Array_Type := Etype (Name);
9048 end if;
9050 -- If name was overloaded, set slice type correctly now
9052 Set_Etype (N, Array_Type);
9054 -- If the range is specified by a subtype mark, no resolution is
9055 -- necessary. Else resolve the bounds, and apply needed checks.
9057 if not Is_Entity_Name (Drange) then
9058 if Ekind (Array_Type) = E_String_Literal_Subtype then
9059 Index_Type := Etype (String_Literal_Low_Bound (Array_Type));
9060 else
9061 Index_Type := Etype (First_Index (Array_Type));
9062 end if;
9064 Resolve (Drange, Base_Type (Index_Type));
9066 if Nkind (Drange) = N_Range then
9068 -- Ensure that side effects in the bounds are properly handled
9070 Force_Evaluation (Low_Bound (Drange));
9071 Force_Evaluation (High_Bound (Drange));
9073 -- Do not apply the range check to nodes associated with the
9074 -- frontend expansion of the dispatch table. We first check
9075 -- if Ada.Tags is already loaded to avoid the addition of an
9076 -- undesired dependence on such run-time unit.
9078 if not Tagged_Type_Expansion
9079 or else not
9080 (RTU_Loaded (Ada_Tags)
9081 and then Nkind (Prefix (N)) = N_Selected_Component
9082 and then Present (Entity (Selector_Name (Prefix (N))))
9083 and then Entity (Selector_Name (Prefix (N))) =
9084 RTE_Record_Component (RE_Prims_Ptr))
9085 then
9086 Apply_Range_Check (Drange, Index_Type);
9087 end if;
9088 end if;
9089 end if;
9091 Set_Slice_Subtype (N);
9093 -- Check bad use of type with predicates
9095 if Has_Predicates (Etype (Drange)) then
9096 Bad_Predicated_Subtype_Use
9097 ("subtype& has predicate, not allowed in slice",
9098 Drange, Etype (Drange));
9100 -- Otherwise here is where we check suspicious indexes
9102 elsif Nkind (Drange) = N_Range then
9103 Warn_On_Suspicious_Index (Name, Low_Bound (Drange));
9104 Warn_On_Suspicious_Index (Name, High_Bound (Drange));
9105 end if;
9107 Analyze_Dimension (N);
9108 Eval_Slice (N);
9109 end Resolve_Slice;
9111 ----------------------------
9112 -- Resolve_String_Literal --
9113 ----------------------------
9115 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
9116 C_Typ : constant Entity_Id := Component_Type (Typ);
9117 R_Typ : constant Entity_Id := Root_Type (C_Typ);
9118 Loc : constant Source_Ptr := Sloc (N);
9119 Str : constant String_Id := Strval (N);
9120 Strlen : constant Nat := String_Length (Str);
9121 Subtype_Id : Entity_Id;
9122 Need_Check : Boolean;
9124 begin
9125 -- For a string appearing in a concatenation, defer creation of the
9126 -- string_literal_subtype until the end of the resolution of the
9127 -- concatenation, because the literal may be constant-folded away. This
9128 -- is a useful optimization for long concatenation expressions.
9130 -- If the string is an aggregate built for a single character (which
9131 -- happens in a non-static context) or a is null string to which special
9132 -- checks may apply, we build the subtype. Wide strings must also get a
9133 -- string subtype if they come from a one character aggregate. Strings
9134 -- generated by attributes might be static, but it is often hard to
9135 -- determine whether the enclosing context is static, so we generate
9136 -- subtypes for them as well, thus losing some rarer optimizations ???
9137 -- Same for strings that come from a static conversion.
9139 Need_Check :=
9140 (Strlen = 0 and then Typ /= Standard_String)
9141 or else Nkind (Parent (N)) /= N_Op_Concat
9142 or else (N /= Left_Opnd (Parent (N))
9143 and then N /= Right_Opnd (Parent (N)))
9144 or else ((Typ = Standard_Wide_String
9145 or else Typ = Standard_Wide_Wide_String)
9146 and then Nkind (Original_Node (N)) /= N_String_Literal);
9148 -- If the resolving type is itself a string literal subtype, we can just
9149 -- reuse it, since there is no point in creating another.
9151 if Ekind (Typ) = E_String_Literal_Subtype then
9152 Subtype_Id := Typ;
9154 elsif Nkind (Parent (N)) = N_Op_Concat
9155 and then not Need_Check
9156 and then not Nkind_In (Original_Node (N), N_Character_Literal,
9157 N_Attribute_Reference,
9158 N_Qualified_Expression,
9159 N_Type_Conversion)
9160 then
9161 Subtype_Id := Typ;
9163 -- Otherwise we must create a string literal subtype. Note that the
9164 -- whole idea of string literal subtypes is simply to avoid the need
9165 -- for building a full fledged array subtype for each literal.
9167 else
9168 Set_String_Literal_Subtype (N, Typ);
9169 Subtype_Id := Etype (N);
9170 end if;
9172 if Nkind (Parent (N)) /= N_Op_Concat
9173 or else Need_Check
9174 then
9175 Set_Etype (N, Subtype_Id);
9176 Eval_String_Literal (N);
9177 end if;
9179 if Is_Limited_Composite (Typ)
9180 or else Is_Private_Composite (Typ)
9181 then
9182 Error_Msg_N ("string literal not available for private array", N);
9183 Set_Etype (N, Any_Type);
9184 return;
9185 end if;
9187 -- The validity of a null string has been checked in the call to
9188 -- Eval_String_Literal.
9190 if Strlen = 0 then
9191 return;
9193 -- Always accept string literal with component type Any_Character, which
9194 -- occurs in error situations and in comparisons of literals, both of
9195 -- which should accept all literals.
9197 elsif R_Typ = Any_Character then
9198 return;
9200 -- If the type is bit-packed, then we always transform the string
9201 -- literal into a full fledged aggregate.
9203 elsif Is_Bit_Packed_Array (Typ) then
9204 null;
9206 -- Deal with cases of Wide_Wide_String, Wide_String, and String
9208 else
9209 -- For Standard.Wide_Wide_String, or any other type whose component
9210 -- type is Standard.Wide_Wide_Character, we know that all the
9211 -- characters in the string must be acceptable, since the parser
9212 -- accepted the characters as valid character literals.
9214 if R_Typ = Standard_Wide_Wide_Character then
9215 null;
9217 -- For the case of Standard.String, or any other type whose component
9218 -- type is Standard.Character, we must make sure that there are no
9219 -- wide characters in the string, i.e. that it is entirely composed
9220 -- of characters in range of type Character.
9222 -- If the string literal is the result of a static concatenation, the
9223 -- test has already been performed on the components, and need not be
9224 -- repeated.
9226 elsif R_Typ = Standard_Character
9227 and then Nkind (Original_Node (N)) /= N_Op_Concat
9228 then
9229 for J in 1 .. Strlen loop
9230 if not In_Character_Range (Get_String_Char (Str, J)) then
9232 -- If we are out of range, post error. This is one of the
9233 -- very few places that we place the flag in the middle of
9234 -- a token, right under the offending wide character. Not
9235 -- quite clear if this is right wrt wide character encoding
9236 -- sequences, but it's only an error message!
9238 Error_Msg
9239 ("literal out of range of type Standard.Character",
9240 Source_Ptr (Int (Loc) + J));
9241 return;
9242 end if;
9243 end loop;
9245 -- For the case of Standard.Wide_String, or any other type whose
9246 -- component type is Standard.Wide_Character, we must make sure that
9247 -- there are no wide characters in the string, i.e. that it is
9248 -- entirely composed of characters in range of type Wide_Character.
9250 -- If the string literal is the result of a static concatenation,
9251 -- the test has already been performed on the components, and need
9252 -- not be repeated.
9254 elsif R_Typ = Standard_Wide_Character
9255 and then Nkind (Original_Node (N)) /= N_Op_Concat
9256 then
9257 for J in 1 .. Strlen loop
9258 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
9260 -- If we are out of range, post error. This is one of the
9261 -- very few places that we place the flag in the middle of
9262 -- a token, right under the offending wide character.
9264 -- This is not quite right, because characters in general
9265 -- will take more than one character position ???
9267 Error_Msg
9268 ("literal out of range of type Standard.Wide_Character",
9269 Source_Ptr (Int (Loc) + J));
9270 return;
9271 end if;
9272 end loop;
9274 -- If the root type is not a standard character, then we will convert
9275 -- the string into an aggregate and will let the aggregate code do
9276 -- the checking. Standard Wide_Wide_Character is also OK here.
9278 else
9279 null;
9280 end if;
9282 -- See if the component type of the array corresponding to the string
9283 -- has compile time known bounds. If yes we can directly check
9284 -- whether the evaluation of the string will raise constraint error.
9285 -- Otherwise we need to transform the string literal into the
9286 -- corresponding character aggregate and let the aggregate code do
9287 -- the checking.
9289 if Is_Standard_Character_Type (R_Typ) then
9291 -- Check for the case of full range, where we are definitely OK
9293 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
9294 return;
9295 end if;
9297 -- Here the range is not the complete base type range, so check
9299 declare
9300 Comp_Typ_Lo : constant Node_Id :=
9301 Type_Low_Bound (Component_Type (Typ));
9302 Comp_Typ_Hi : constant Node_Id :=
9303 Type_High_Bound (Component_Type (Typ));
9305 Char_Val : Uint;
9307 begin
9308 if Compile_Time_Known_Value (Comp_Typ_Lo)
9309 and then Compile_Time_Known_Value (Comp_Typ_Hi)
9310 then
9311 for J in 1 .. Strlen loop
9312 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
9314 if Char_Val < Expr_Value (Comp_Typ_Lo)
9315 or else Char_Val > Expr_Value (Comp_Typ_Hi)
9316 then
9317 Apply_Compile_Time_Constraint_Error
9318 (N, "character out of range?", CE_Range_Check_Failed,
9319 Loc => Source_Ptr (Int (Loc) + J));
9320 end if;
9321 end loop;
9323 return;
9324 end if;
9325 end;
9326 end if;
9327 end if;
9329 -- If we got here we meed to transform the string literal into the
9330 -- equivalent qualified positional array aggregate. This is rather
9331 -- heavy artillery for this situation, but it is hard work to avoid.
9333 declare
9334 Lits : constant List_Id := New_List;
9335 P : Source_Ptr := Loc + 1;
9336 C : Char_Code;
9338 begin
9339 -- Build the character literals, we give them source locations that
9340 -- correspond to the string positions, which is a bit tricky given
9341 -- the possible presence of wide character escape sequences.
9343 for J in 1 .. Strlen loop
9344 C := Get_String_Char (Str, J);
9345 Set_Character_Literal_Name (C);
9347 Append_To (Lits,
9348 Make_Character_Literal (P,
9349 Chars => Name_Find,
9350 Char_Literal_Value => UI_From_CC (C)));
9352 if In_Character_Range (C) then
9353 P := P + 1;
9355 -- Should we have a call to Skip_Wide here ???
9357 -- ??? else
9358 -- Skip_Wide (P);
9360 end if;
9361 end loop;
9363 Rewrite (N,
9364 Make_Qualified_Expression (Loc,
9365 Subtype_Mark => New_Reference_To (Typ, Loc),
9366 Expression =>
9367 Make_Aggregate (Loc, Expressions => Lits)));
9369 Analyze_And_Resolve (N, Typ);
9370 end;
9371 end Resolve_String_Literal;
9373 -----------------------------
9374 -- Resolve_Subprogram_Info --
9375 -----------------------------
9377 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
9378 begin
9379 Set_Etype (N, Typ);
9380 end Resolve_Subprogram_Info;
9382 -----------------------------
9383 -- Resolve_Type_Conversion --
9384 -----------------------------
9386 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
9387 Conv_OK : constant Boolean := Conversion_OK (N);
9388 Operand : constant Node_Id := Expression (N);
9389 Operand_Typ : constant Entity_Id := Etype (Operand);
9390 Target_Typ : constant Entity_Id := Etype (N);
9391 Rop : Node_Id;
9392 Orig_N : Node_Id;
9393 Orig_T : Node_Id;
9395 Test_Redundant : Boolean := Warn_On_Redundant_Constructs;
9396 -- Set to False to suppress cases where we want to suppress the test
9397 -- for redundancy to avoid possible false positives on this warning.
9399 begin
9400 if not Conv_OK
9401 and then not Valid_Conversion (N, Target_Typ, Operand)
9402 then
9403 return;
9404 end if;
9406 -- If the Operand Etype is Universal_Fixed, then the conversion is
9407 -- never redundant. We need this check because by the time we have
9408 -- finished the rather complex transformation, the conversion looks
9409 -- redundant when it is not.
9411 if Operand_Typ = Universal_Fixed then
9412 Test_Redundant := False;
9414 -- If the operand is marked as Any_Fixed, then special processing is
9415 -- required. This is also a case where we suppress the test for a
9416 -- redundant conversion, since most certainly it is not redundant.
9418 elsif Operand_Typ = Any_Fixed then
9419 Test_Redundant := False;
9421 -- Mixed-mode operation involving a literal. Context must be a fixed
9422 -- type which is applied to the literal subsequently.
9424 if Is_Fixed_Point_Type (Typ) then
9425 Set_Etype (Operand, Universal_Real);
9427 elsif Is_Numeric_Type (Typ)
9428 and then Nkind_In (Operand, N_Op_Multiply, N_Op_Divide)
9429 and then (Etype (Right_Opnd (Operand)) = Universal_Real
9430 or else
9431 Etype (Left_Opnd (Operand)) = Universal_Real)
9432 then
9433 -- Return if expression is ambiguous
9435 if Unique_Fixed_Point_Type (N) = Any_Type then
9436 return;
9438 -- If nothing else, the available fixed type is Duration
9440 else
9441 Set_Etype (Operand, Standard_Duration);
9442 end if;
9444 -- Resolve the real operand with largest available precision
9446 if Etype (Right_Opnd (Operand)) = Universal_Real then
9447 Rop := New_Copy_Tree (Right_Opnd (Operand));
9448 else
9449 Rop := New_Copy_Tree (Left_Opnd (Operand));
9450 end if;
9452 Resolve (Rop, Universal_Real);
9454 -- If the operand is a literal (it could be a non-static and
9455 -- illegal exponentiation) check whether the use of Duration
9456 -- is potentially inaccurate.
9458 if Nkind (Rop) = N_Real_Literal
9459 and then Realval (Rop) /= Ureal_0
9460 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
9461 then
9462 Error_Msg_N
9463 ("?universal real operand can only " &
9464 "be interpreted as Duration!",
9465 Rop);
9466 Error_Msg_N
9467 ("\?precision will be lost in the conversion!", Rop);
9468 end if;
9470 elsif Is_Numeric_Type (Typ)
9471 and then Nkind (Operand) in N_Op
9472 and then Unique_Fixed_Point_Type (N) /= Any_Type
9473 then
9474 Set_Etype (Operand, Standard_Duration);
9476 else
9477 Error_Msg_N ("invalid context for mixed mode operation", N);
9478 Set_Etype (Operand, Any_Type);
9479 return;
9480 end if;
9481 end if;
9483 Resolve (Operand);
9485 -- In SPARK, a type conversion between array types should be restricted
9486 -- to types which have matching static bounds.
9488 -- Protect call to Matching_Static_Array_Bounds to avoid costly
9489 -- operation if not needed.
9491 if Restriction_Check_Required (SPARK)
9492 and then Is_Array_Type (Target_Typ)
9493 and then Is_Array_Type (Operand_Typ)
9494 and then Operand_Typ /= Any_Composite -- or else Operand in error
9495 and then not Matching_Static_Array_Bounds (Target_Typ, Operand_Typ)
9496 then
9497 Check_SPARK_Restriction
9498 ("array types should have matching static bounds", N);
9499 end if;
9501 -- In formal mode, the operand of an ancestor type conversion must be an
9502 -- object (not an expression).
9504 if Is_Tagged_Type (Target_Typ)
9505 and then not Is_Class_Wide_Type (Target_Typ)
9506 and then Is_Tagged_Type (Operand_Typ)
9507 and then not Is_Class_Wide_Type (Operand_Typ)
9508 and then Is_Ancestor (Target_Typ, Operand_Typ)
9509 and then not Is_SPARK_Object_Reference (Operand)
9510 then
9511 Check_SPARK_Restriction ("object required", Operand);
9512 end if;
9514 Analyze_Dimension (N);
9516 -- Note: we do the Eval_Type_Conversion call before applying the
9517 -- required checks for a subtype conversion. This is important, since
9518 -- both are prepared under certain circumstances to change the type
9519 -- conversion to a constraint error node, but in the case of
9520 -- Eval_Type_Conversion this may reflect an illegality in the static
9521 -- case, and we would miss the illegality (getting only a warning
9522 -- message), if we applied the type conversion checks first.
9524 Eval_Type_Conversion (N);
9526 -- Even when evaluation is not possible, we may be able to simplify the
9527 -- conversion or its expression. This needs to be done before applying
9528 -- checks, since otherwise the checks may use the original expression
9529 -- and defeat the simplifications. This is specifically the case for
9530 -- elimination of the floating-point Truncation attribute in
9531 -- float-to-int conversions.
9533 Simplify_Type_Conversion (N);
9535 -- If after evaluation we still have a type conversion, then we may need
9536 -- to apply checks required for a subtype conversion.
9538 -- Skip these type conversion checks if universal fixed operands
9539 -- operands involved, since range checks are handled separately for
9540 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
9542 if Nkind (N) = N_Type_Conversion
9543 and then not Is_Generic_Type (Root_Type (Target_Typ))
9544 and then Target_Typ /= Universal_Fixed
9545 and then Operand_Typ /= Universal_Fixed
9546 then
9547 Apply_Type_Conversion_Checks (N);
9548 end if;
9550 -- Issue warning for conversion of simple object to its own type. We
9551 -- have to test the original nodes, since they may have been rewritten
9552 -- by various optimizations.
9554 Orig_N := Original_Node (N);
9556 -- Here we test for a redundant conversion if the warning mode is
9557 -- active (and was not locally reset), and we have a type conversion
9558 -- from source not appearing in a generic instance.
9560 if Test_Redundant
9561 and then Nkind (Orig_N) = N_Type_Conversion
9562 and then Comes_From_Source (Orig_N)
9563 and then not In_Instance
9564 then
9565 Orig_N := Original_Node (Expression (Orig_N));
9566 Orig_T := Target_Typ;
9568 -- If the node is part of a larger expression, the Target_Type
9569 -- may not be the original type of the node if the context is a
9570 -- condition. Recover original type to see if conversion is needed.
9572 if Is_Boolean_Type (Orig_T)
9573 and then Nkind (Parent (N)) in N_Op
9574 then
9575 Orig_T := Etype (Parent (N));
9576 end if;
9578 -- If we have an entity name, then give the warning if the entity
9579 -- is the right type, or if it is a loop parameter covered by the
9580 -- original type (that's needed because loop parameters have an
9581 -- odd subtype coming from the bounds).
9583 if (Is_Entity_Name (Orig_N)
9584 and then
9585 (Etype (Entity (Orig_N)) = Orig_T
9586 or else
9587 (Ekind (Entity (Orig_N)) = E_Loop_Parameter
9588 and then Covers (Orig_T, Etype (Entity (Orig_N))))))
9590 -- If not an entity, then type of expression must match
9592 or else Etype (Orig_N) = Orig_T
9593 then
9594 -- One more check, do not give warning if the analyzed conversion
9595 -- has an expression with non-static bounds, and the bounds of the
9596 -- target are static. This avoids junk warnings in cases where the
9597 -- conversion is necessary to establish staticness, for example in
9598 -- a case statement.
9600 if not Is_OK_Static_Subtype (Operand_Typ)
9601 and then Is_OK_Static_Subtype (Target_Typ)
9602 then
9603 null;
9605 -- Finally, if this type conversion occurs in a context requiring
9606 -- a prefix, and the expression is a qualified expression then the
9607 -- type conversion is not redundant, since a qualified expression
9608 -- is not a prefix, whereas a type conversion is. For example, "X
9609 -- := T'(Funx(...)).Y;" is illegal because a selected component
9610 -- requires a prefix, but a type conversion makes it legal: "X :=
9611 -- T(T'(Funx(...))).Y;"
9613 -- In Ada 2012, a qualified expression is a name, so this idiom is
9614 -- no longer needed, but we still suppress the warning because it
9615 -- seems unfriendly for warnings to pop up when you switch to the
9616 -- newer language version.
9618 elsif Nkind (Orig_N) = N_Qualified_Expression
9619 and then Nkind_In (Parent (N), N_Attribute_Reference,
9620 N_Indexed_Component,
9621 N_Selected_Component,
9622 N_Slice,
9623 N_Explicit_Dereference)
9624 then
9625 null;
9627 -- Here we give the redundant conversion warning. If it is an
9628 -- entity, give the name of the entity in the message. If not,
9629 -- just mention the expression.
9631 else
9632 if Is_Entity_Name (Orig_N) then
9633 Error_Msg_Node_2 := Orig_T;
9634 Error_Msg_NE -- CODEFIX
9635 ("?redundant conversion, & is of type &!",
9636 N, Entity (Orig_N));
9637 else
9638 Error_Msg_NE
9639 ("?redundant conversion, expression is of type&!",
9640 N, Orig_T);
9641 end if;
9642 end if;
9643 end if;
9644 end if;
9646 -- Ada 2005 (AI-251): Handle class-wide interface type conversions.
9647 -- No need to perform any interface conversion if the type of the
9648 -- expression coincides with the target type.
9650 if Ada_Version >= Ada_2005
9651 and then Full_Expander_Active
9652 and then Operand_Typ /= Target_Typ
9653 then
9654 declare
9655 Opnd : Entity_Id := Operand_Typ;
9656 Target : Entity_Id := Target_Typ;
9658 begin
9659 if Is_Access_Type (Opnd) then
9660 Opnd := Designated_Type (Opnd);
9661 end if;
9663 if Is_Access_Type (Target_Typ) then
9664 Target := Designated_Type (Target);
9665 end if;
9667 if Opnd = Target then
9668 null;
9670 -- Conversion from interface type
9672 elsif Is_Interface (Opnd) then
9674 -- Ada 2005 (AI-217): Handle entities from limited views
9676 if From_With_Type (Opnd) then
9677 Error_Msg_Qual_Level := 99;
9678 Error_Msg_NE -- CODEFIX
9679 ("missing WITH clause on package &", N,
9680 Cunit_Entity (Get_Source_Unit (Base_Type (Opnd))));
9681 Error_Msg_N
9682 ("type conversions require visibility of the full view",
9685 elsif From_With_Type (Target)
9686 and then not
9687 (Is_Access_Type (Target_Typ)
9688 and then Present (Non_Limited_View (Etype (Target))))
9689 then
9690 Error_Msg_Qual_Level := 99;
9691 Error_Msg_NE -- CODEFIX
9692 ("missing WITH clause on package &", N,
9693 Cunit_Entity (Get_Source_Unit (Base_Type (Target))));
9694 Error_Msg_N
9695 ("type conversions require visibility of the full view",
9698 else
9699 Expand_Interface_Conversion (N, Is_Static => False);
9700 end if;
9702 -- Conversion to interface type
9704 elsif Is_Interface (Target) then
9706 -- Handle subtypes
9708 if Ekind_In (Opnd, E_Protected_Subtype, E_Task_Subtype) then
9709 Opnd := Etype (Opnd);
9710 end if;
9712 if not Interface_Present_In_Ancestor
9713 (Typ => Opnd,
9714 Iface => Target)
9715 then
9716 if Is_Class_Wide_Type (Opnd) then
9718 -- The static analysis is not enough to know if the
9719 -- interface is implemented or not. Hence we must pass
9720 -- the work to the expander to generate code to evaluate
9721 -- the conversion at run time.
9723 Expand_Interface_Conversion (N, Is_Static => False);
9725 else
9726 Error_Msg_Name_1 := Chars (Etype (Target));
9727 Error_Msg_Name_2 := Chars (Opnd);
9728 Error_Msg_N
9729 ("wrong interface conversion (% is not a progenitor " &
9730 "of %)", N);
9731 end if;
9733 else
9734 Expand_Interface_Conversion (N);
9735 end if;
9736 end if;
9737 end;
9738 end if;
9740 -- Ada 2012: if target type has predicates, the result requires a
9741 -- predicate check. If the context is a call to another predicate
9742 -- check we must prevent infinite recursion.
9744 if Has_Predicates (Target_Typ) then
9745 if Nkind (Parent (N)) = N_Function_Call
9746 and then Present (Name (Parent (N)))
9747 and then Has_Predicates (Entity (Name (Parent (N))))
9748 then
9749 null;
9751 else
9752 Apply_Predicate_Check (N, Target_Typ);
9753 end if;
9754 end if;
9755 end Resolve_Type_Conversion;
9757 ----------------------
9758 -- Resolve_Unary_Op --
9759 ----------------------
9761 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
9762 B_Typ : constant Entity_Id := Base_Type (Typ);
9763 R : constant Node_Id := Right_Opnd (N);
9764 OK : Boolean;
9765 Lo : Uint;
9766 Hi : Uint;
9768 begin
9769 if Is_Modular_Integer_Type (Typ) and then Nkind (N) /= N_Op_Not then
9770 Error_Msg_Name_1 := Chars (Typ);
9771 Check_SPARK_Restriction
9772 ("unary operator not defined for modular type%", N);
9773 end if;
9775 -- Deal with intrinsic unary operators
9777 if Comes_From_Source (N)
9778 and then Ekind (Entity (N)) = E_Function
9779 and then Is_Imported (Entity (N))
9780 and then Is_Intrinsic_Subprogram (Entity (N))
9781 then
9782 Resolve_Intrinsic_Unary_Operator (N, Typ);
9783 return;
9784 end if;
9786 -- Deal with universal cases
9788 if Etype (R) = Universal_Integer
9789 or else
9790 Etype (R) = Universal_Real
9791 then
9792 Check_For_Visible_Operator (N, B_Typ);
9793 end if;
9795 Set_Etype (N, B_Typ);
9796 Resolve (R, B_Typ);
9798 -- Generate warning for expressions like abs (x mod 2)
9800 if Warn_On_Redundant_Constructs
9801 and then Nkind (N) = N_Op_Abs
9802 then
9803 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
9805 if OK and then Hi >= Lo and then Lo >= 0 then
9806 Error_Msg_N -- CODEFIX
9807 ("?abs applied to known non-negative value has no effect", N);
9808 end if;
9809 end if;
9811 -- Deal with reference generation
9813 Check_Unset_Reference (R);
9814 Generate_Operator_Reference (N, B_Typ);
9815 Analyze_Dimension (N);
9816 Eval_Unary_Op (N);
9818 -- Set overflow checking bit. Much cleverer code needed here eventually
9819 -- and perhaps the Resolve routines should be separated for the various
9820 -- arithmetic operations, since they will need different processing ???
9822 if Nkind (N) in N_Op then
9823 if not Overflow_Checks_Suppressed (Etype (N)) then
9824 Enable_Overflow_Check (N);
9825 end if;
9826 end if;
9828 -- Generate warning for expressions like -5 mod 3 for integers. No need
9829 -- to worry in the floating-point case, since parens do not affect the
9830 -- result so there is no point in giving in a warning.
9832 declare
9833 Norig : constant Node_Id := Original_Node (N);
9834 Rorig : Node_Id;
9835 Val : Uint;
9836 HB : Uint;
9837 LB : Uint;
9838 Lval : Uint;
9839 Opnd : Node_Id;
9841 begin
9842 if Warn_On_Questionable_Missing_Parens
9843 and then Comes_From_Source (Norig)
9844 and then Is_Integer_Type (Typ)
9845 and then Nkind (Norig) = N_Op_Minus
9846 then
9847 Rorig := Original_Node (Right_Opnd (Norig));
9849 -- We are looking for cases where the right operand is not
9850 -- parenthesized, and is a binary operator, multiply, divide, or
9851 -- mod. These are the cases where the grouping can affect results.
9853 if Paren_Count (Rorig) = 0
9854 and then Nkind_In (Rorig, N_Op_Mod, N_Op_Multiply, N_Op_Divide)
9855 then
9856 -- For mod, we always give the warning, since the value is
9857 -- affected by the parenthesization (e.g. (-5) mod 315 /=
9858 -- -(5 mod 315)). But for the other cases, the only concern is
9859 -- overflow, e.g. for the case of 8 big signed (-(2 * 64)
9860 -- overflows, but (-2) * 64 does not). So we try to give the
9861 -- message only when overflow is possible.
9863 if Nkind (Rorig) /= N_Op_Mod
9864 and then Compile_Time_Known_Value (R)
9865 then
9866 Val := Expr_Value (R);
9868 if Compile_Time_Known_Value (Type_High_Bound (Typ)) then
9869 HB := Expr_Value (Type_High_Bound (Typ));
9870 else
9871 HB := Expr_Value (Type_High_Bound (Base_Type (Typ)));
9872 end if;
9874 if Compile_Time_Known_Value (Type_Low_Bound (Typ)) then
9875 LB := Expr_Value (Type_Low_Bound (Typ));
9876 else
9877 LB := Expr_Value (Type_Low_Bound (Base_Type (Typ)));
9878 end if;
9880 -- Note that the test below is deliberately excluding the
9881 -- largest negative number, since that is a potentially
9882 -- troublesome case (e.g. -2 * x, where the result is the
9883 -- largest negative integer has an overflow with 2 * x).
9885 if Val > LB and then Val <= HB then
9886 return;
9887 end if;
9888 end if;
9890 -- For the multiplication case, the only case we have to worry
9891 -- about is when (-a)*b is exactly the largest negative number
9892 -- so that -(a*b) can cause overflow. This can only happen if
9893 -- a is a power of 2, and more generally if any operand is a
9894 -- constant that is not a power of 2, then the parentheses
9895 -- cannot affect whether overflow occurs. We only bother to
9896 -- test the left most operand
9898 -- Loop looking at left operands for one that has known value
9900 Opnd := Rorig;
9901 Opnd_Loop : while Nkind (Opnd) = N_Op_Multiply loop
9902 if Compile_Time_Known_Value (Left_Opnd (Opnd)) then
9903 Lval := UI_Abs (Expr_Value (Left_Opnd (Opnd)));
9905 -- Operand value of 0 or 1 skips warning
9907 if Lval <= 1 then
9908 return;
9910 -- Otherwise check power of 2, if power of 2, warn, if
9911 -- anything else, skip warning.
9913 else
9914 while Lval /= 2 loop
9915 if Lval mod 2 = 1 then
9916 return;
9917 else
9918 Lval := Lval / 2;
9919 end if;
9920 end loop;
9922 exit Opnd_Loop;
9923 end if;
9924 end if;
9926 -- Keep looking at left operands
9928 Opnd := Left_Opnd (Opnd);
9929 end loop Opnd_Loop;
9931 -- For rem or "/" we can only have a problematic situation
9932 -- if the divisor has a value of minus one or one. Otherwise
9933 -- overflow is impossible (divisor > 1) or we have a case of
9934 -- division by zero in any case.
9936 if Nkind_In (Rorig, N_Op_Divide, N_Op_Rem)
9937 and then Compile_Time_Known_Value (Right_Opnd (Rorig))
9938 and then UI_Abs (Expr_Value (Right_Opnd (Rorig))) /= 1
9939 then
9940 return;
9941 end if;
9943 -- If we fall through warning should be issued
9945 Error_Msg_N
9946 ("?unary minus expression should be parenthesized here!", N);
9947 end if;
9948 end if;
9949 end;
9950 end Resolve_Unary_Op;
9952 ----------------------------------
9953 -- Resolve_Unchecked_Expression --
9954 ----------------------------------
9956 procedure Resolve_Unchecked_Expression
9957 (N : Node_Id;
9958 Typ : Entity_Id)
9960 begin
9961 Resolve (Expression (N), Typ, Suppress => All_Checks);
9962 Set_Etype (N, Typ);
9963 end Resolve_Unchecked_Expression;
9965 ---------------------------------------
9966 -- Resolve_Unchecked_Type_Conversion --
9967 ---------------------------------------
9969 procedure Resolve_Unchecked_Type_Conversion
9970 (N : Node_Id;
9971 Typ : Entity_Id)
9973 pragma Warnings (Off, Typ);
9975 Operand : constant Node_Id := Expression (N);
9976 Opnd_Type : constant Entity_Id := Etype (Operand);
9978 begin
9979 -- Resolve operand using its own type
9981 Resolve (Operand, Opnd_Type);
9982 Analyze_Dimension (N);
9983 Eval_Unchecked_Conversion (N);
9984 end Resolve_Unchecked_Type_Conversion;
9986 ------------------------------
9987 -- Rewrite_Operator_As_Call --
9988 ------------------------------
9990 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
9991 Loc : constant Source_Ptr := Sloc (N);
9992 Actuals : constant List_Id := New_List;
9993 New_N : Node_Id;
9995 begin
9996 if Nkind (N) in N_Binary_Op then
9997 Append (Left_Opnd (N), Actuals);
9998 end if;
10000 Append (Right_Opnd (N), Actuals);
10002 New_N :=
10003 Make_Function_Call (Sloc => Loc,
10004 Name => New_Occurrence_Of (Nam, Loc),
10005 Parameter_Associations => Actuals);
10007 Preserve_Comes_From_Source (New_N, N);
10008 Preserve_Comes_From_Source (Name (New_N), N);
10009 Rewrite (N, New_N);
10010 Set_Etype (N, Etype (Nam));
10011 end Rewrite_Operator_As_Call;
10013 ------------------------------
10014 -- Rewrite_Renamed_Operator --
10015 ------------------------------
10017 procedure Rewrite_Renamed_Operator
10018 (N : Node_Id;
10019 Op : Entity_Id;
10020 Typ : Entity_Id)
10022 Nam : constant Name_Id := Chars (Op);
10023 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
10024 Op_Node : Node_Id;
10026 begin
10027 -- Rewrite the operator node using the real operator, not its renaming.
10028 -- Exclude user-defined intrinsic operations of the same name, which are
10029 -- treated separately and rewritten as calls.
10031 if Ekind (Op) /= E_Function or else Chars (N) /= Nam then
10032 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
10033 Set_Chars (Op_Node, Nam);
10034 Set_Etype (Op_Node, Etype (N));
10035 Set_Entity (Op_Node, Op);
10036 Set_Right_Opnd (Op_Node, Right_Opnd (N));
10038 -- Indicate that both the original entity and its renaming are
10039 -- referenced at this point.
10041 Generate_Reference (Entity (N), N);
10042 Generate_Reference (Op, N);
10044 if Is_Binary then
10045 Set_Left_Opnd (Op_Node, Left_Opnd (N));
10046 end if;
10048 Rewrite (N, Op_Node);
10050 -- If the context type is private, add the appropriate conversions so
10051 -- that the operator is applied to the full view. This is done in the
10052 -- routines that resolve intrinsic operators.
10054 if Is_Intrinsic_Subprogram (Op)
10055 and then Is_Private_Type (Typ)
10056 then
10057 case Nkind (N) is
10058 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
10059 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
10060 Resolve_Intrinsic_Operator (N, Typ);
10062 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
10063 Resolve_Intrinsic_Unary_Operator (N, Typ);
10065 when others =>
10066 Resolve (N, Typ);
10067 end case;
10068 end if;
10070 elsif Ekind (Op) = E_Function and then Is_Intrinsic_Subprogram (Op) then
10072 -- Operator renames a user-defined operator of the same name. Use the
10073 -- original operator in the node, which is the one Gigi knows about.
10075 Set_Entity (N, Op);
10076 Set_Is_Overloaded (N, False);
10077 end if;
10078 end Rewrite_Renamed_Operator;
10080 -----------------------
10081 -- Set_Slice_Subtype --
10082 -----------------------
10084 -- Build an implicit subtype declaration to represent the type delivered by
10085 -- the slice. This is an abbreviated version of an array subtype. We define
10086 -- an index subtype for the slice, using either the subtype name or the
10087 -- discrete range of the slice. To be consistent with index usage elsewhere
10088 -- we create a list header to hold the single index. This list is not
10089 -- otherwise attached to the syntax tree.
10091 procedure Set_Slice_Subtype (N : Node_Id) is
10092 Loc : constant Source_Ptr := Sloc (N);
10093 Index_List : constant List_Id := New_List;
10094 Index : Node_Id;
10095 Index_Subtype : Entity_Id;
10096 Index_Type : Entity_Id;
10097 Slice_Subtype : Entity_Id;
10098 Drange : constant Node_Id := Discrete_Range (N);
10100 begin
10101 if Is_Entity_Name (Drange) then
10102 Index_Subtype := Entity (Drange);
10104 else
10105 -- We force the evaluation of a range. This is definitely needed in
10106 -- the renamed case, and seems safer to do unconditionally. Note in
10107 -- any case that since we will create and insert an Itype referring
10108 -- to this range, we must make sure any side effect removal actions
10109 -- are inserted before the Itype definition.
10111 if Nkind (Drange) = N_Range then
10112 Force_Evaluation (Low_Bound (Drange));
10113 Force_Evaluation (High_Bound (Drange));
10114 end if;
10116 Index_Type := Base_Type (Etype (Drange));
10118 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
10120 -- Take a new copy of Drange (where bounds have been rewritten to
10121 -- reference side-effect-free names). Using a separate tree ensures
10122 -- that further expansion (e.g. while rewriting a slice assignment
10123 -- into a FOR loop) does not attempt to remove side effects on the
10124 -- bounds again (which would cause the bounds in the index subtype
10125 -- definition to refer to temporaries before they are defined) (the
10126 -- reason is that some names are considered side effect free here
10127 -- for the subtype, but not in the context of a loop iteration
10128 -- scheme).
10130 Set_Scalar_Range (Index_Subtype, New_Copy_Tree (Drange));
10131 Set_Parent (Scalar_Range (Index_Subtype), Index_Subtype);
10132 Set_Etype (Index_Subtype, Index_Type);
10133 Set_Size_Info (Index_Subtype, Index_Type);
10134 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
10135 end if;
10137 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
10139 Index := New_Occurrence_Of (Index_Subtype, Loc);
10140 Set_Etype (Index, Index_Subtype);
10141 Append (Index, Index_List);
10143 Set_First_Index (Slice_Subtype, Index);
10144 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
10145 Set_Is_Constrained (Slice_Subtype, True);
10147 Check_Compile_Time_Size (Slice_Subtype);
10149 -- The Etype of the existing Slice node is reset to this slice subtype.
10150 -- Its bounds are obtained from its first index.
10152 Set_Etype (N, Slice_Subtype);
10154 -- For packed slice subtypes, freeze immediately (except in the case of
10155 -- being in a "spec expression" where we never freeze when we first see
10156 -- the expression).
10158 if Is_Packed (Slice_Subtype) and not In_Spec_Expression then
10159 Freeze_Itype (Slice_Subtype, N);
10161 -- For all other cases insert an itype reference in the slice's actions
10162 -- so that the itype is frozen at the proper place in the tree (i.e. at
10163 -- the point where actions for the slice are analyzed). Note that this
10164 -- is different from freezing the itype immediately, which might be
10165 -- premature (e.g. if the slice is within a transient scope). This needs
10166 -- to be done only if expansion is enabled.
10168 elsif Full_Expander_Active then
10169 Ensure_Defined (Typ => Slice_Subtype, N => N);
10170 end if;
10171 end Set_Slice_Subtype;
10173 --------------------------------
10174 -- Set_String_Literal_Subtype --
10175 --------------------------------
10177 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
10178 Loc : constant Source_Ptr := Sloc (N);
10179 Low_Bound : constant Node_Id :=
10180 Type_Low_Bound (Etype (First_Index (Typ)));
10181 Subtype_Id : Entity_Id;
10183 begin
10184 if Nkind (N) /= N_String_Literal then
10185 return;
10186 end if;
10188 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
10189 Set_String_Literal_Length (Subtype_Id, UI_From_Int
10190 (String_Length (Strval (N))));
10191 Set_Etype (Subtype_Id, Base_Type (Typ));
10192 Set_Is_Constrained (Subtype_Id);
10193 Set_Etype (N, Subtype_Id);
10195 -- The low bound is set from the low bound of the corresponding index
10196 -- type. Note that we do not store the high bound in the string literal
10197 -- subtype, but it can be deduced if necessary from the length and the
10198 -- low bound.
10200 if Is_OK_Static_Expression (Low_Bound) then
10201 Set_String_Literal_Low_Bound (Subtype_Id, Low_Bound);
10203 -- If the lower bound is not static we create a range for the string
10204 -- literal, using the index type and the known length of the literal.
10205 -- The index type is not necessarily Positive, so the upper bound is
10206 -- computed as T'Val (T'Pos (Low_Bound) + L - 1).
10208 else
10209 declare
10210 Index_List : constant List_Id := New_List;
10211 Index_Type : constant Entity_Id := Etype (First_Index (Typ));
10212 High_Bound : constant Node_Id :=
10213 Make_Attribute_Reference (Loc,
10214 Attribute_Name => Name_Val,
10215 Prefix =>
10216 New_Occurrence_Of (Index_Type, Loc),
10217 Expressions => New_List (
10218 Make_Op_Add (Loc,
10219 Left_Opnd =>
10220 Make_Attribute_Reference (Loc,
10221 Attribute_Name => Name_Pos,
10222 Prefix =>
10223 New_Occurrence_Of (Index_Type, Loc),
10224 Expressions =>
10225 New_List (New_Copy_Tree (Low_Bound))),
10226 Right_Opnd =>
10227 Make_Integer_Literal (Loc,
10228 String_Length (Strval (N)) - 1))));
10230 Array_Subtype : Entity_Id;
10231 Drange : Node_Id;
10232 Index : Node_Id;
10233 Index_Subtype : Entity_Id;
10235 begin
10236 if Is_Integer_Type (Index_Type) then
10237 Set_String_Literal_Low_Bound
10238 (Subtype_Id, Make_Integer_Literal (Loc, 1));
10240 else
10241 -- If the index type is an enumeration type, build bounds
10242 -- expression with attributes.
10244 Set_String_Literal_Low_Bound
10245 (Subtype_Id,
10246 Make_Attribute_Reference (Loc,
10247 Attribute_Name => Name_First,
10248 Prefix =>
10249 New_Occurrence_Of (Base_Type (Index_Type), Loc)));
10250 Set_Etype (String_Literal_Low_Bound (Subtype_Id), Index_Type);
10251 end if;
10253 Analyze_And_Resolve (String_Literal_Low_Bound (Subtype_Id));
10255 -- Build bona fide subtype for the string, and wrap it in an
10256 -- unchecked conversion, because the backend expects the
10257 -- String_Literal_Subtype to have a static lower bound.
10259 Index_Subtype :=
10260 Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
10261 Drange := Make_Range (Loc, New_Copy_Tree (Low_Bound), High_Bound);
10262 Set_Scalar_Range (Index_Subtype, Drange);
10263 Set_Parent (Drange, N);
10264 Analyze_And_Resolve (Drange, Index_Type);
10266 -- In the context, the Index_Type may already have a constraint,
10267 -- so use common base type on string subtype. The base type may
10268 -- be used when generating attributes of the string, for example
10269 -- in the context of a slice assignment.
10271 Set_Etype (Index_Subtype, Base_Type (Index_Type));
10272 Set_Size_Info (Index_Subtype, Index_Type);
10273 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
10275 Array_Subtype := Create_Itype (E_Array_Subtype, N);
10277 Index := New_Occurrence_Of (Index_Subtype, Loc);
10278 Set_Etype (Index, Index_Subtype);
10279 Append (Index, Index_List);
10281 Set_First_Index (Array_Subtype, Index);
10282 Set_Etype (Array_Subtype, Base_Type (Typ));
10283 Set_Is_Constrained (Array_Subtype, True);
10285 Rewrite (N,
10286 Make_Unchecked_Type_Conversion (Loc,
10287 Subtype_Mark => New_Occurrence_Of (Array_Subtype, Loc),
10288 Expression => Relocate_Node (N)));
10289 Set_Etype (N, Array_Subtype);
10290 end;
10291 end if;
10292 end Set_String_Literal_Subtype;
10294 ------------------------------
10295 -- Simplify_Type_Conversion --
10296 ------------------------------
10298 procedure Simplify_Type_Conversion (N : Node_Id) is
10299 begin
10300 if Nkind (N) = N_Type_Conversion then
10301 declare
10302 Operand : constant Node_Id := Expression (N);
10303 Target_Typ : constant Entity_Id := Etype (N);
10304 Opnd_Typ : constant Entity_Id := Etype (Operand);
10306 begin
10307 if Is_Floating_Point_Type (Opnd_Typ)
10308 and then
10309 (Is_Integer_Type (Target_Typ)
10310 or else (Is_Fixed_Point_Type (Target_Typ)
10311 and then Conversion_OK (N)))
10312 and then Nkind (Operand) = N_Attribute_Reference
10313 and then Attribute_Name (Operand) = Name_Truncation
10315 -- Special processing required if the conversion is the expression
10316 -- of a Truncation attribute reference. In this case we replace:
10318 -- ityp (ftyp'Truncation (x))
10320 -- by
10322 -- ityp (x)
10324 -- with the Float_Truncate flag set, which is more efficient.
10326 then
10327 Rewrite (Operand,
10328 Relocate_Node (First (Expressions (Operand))));
10329 Set_Float_Truncate (N, True);
10330 end if;
10331 end;
10332 end if;
10333 end Simplify_Type_Conversion;
10335 -----------------------------
10336 -- Unique_Fixed_Point_Type --
10337 -----------------------------
10339 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
10340 T1 : Entity_Id := Empty;
10341 T2 : Entity_Id;
10342 Item : Node_Id;
10343 Scop : Entity_Id;
10345 procedure Fixed_Point_Error;
10346 -- Give error messages for true ambiguity. Messages are posted on node
10347 -- N, and entities T1, T2 are the possible interpretations.
10349 -----------------------
10350 -- Fixed_Point_Error --
10351 -----------------------
10353 procedure Fixed_Point_Error is
10354 begin
10355 Error_Msg_N ("ambiguous universal_fixed_expression", N);
10356 Error_Msg_NE ("\\possible interpretation as}", N, T1);
10357 Error_Msg_NE ("\\possible interpretation as}", N, T2);
10358 end Fixed_Point_Error;
10360 -- Start of processing for Unique_Fixed_Point_Type
10362 begin
10363 -- The operations on Duration are visible, so Duration is always a
10364 -- possible interpretation.
10366 T1 := Standard_Duration;
10368 -- Look for fixed-point types in enclosing scopes
10370 Scop := Current_Scope;
10371 while Scop /= Standard_Standard loop
10372 T2 := First_Entity (Scop);
10373 while Present (T2) loop
10374 if Is_Fixed_Point_Type (T2)
10375 and then Current_Entity (T2) = T2
10376 and then Scope (Base_Type (T2)) = Scop
10377 then
10378 if Present (T1) then
10379 Fixed_Point_Error;
10380 return Any_Type;
10381 else
10382 T1 := T2;
10383 end if;
10384 end if;
10386 Next_Entity (T2);
10387 end loop;
10389 Scop := Scope (Scop);
10390 end loop;
10392 -- Look for visible fixed type declarations in the context
10394 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
10395 while Present (Item) loop
10396 if Nkind (Item) = N_With_Clause then
10397 Scop := Entity (Name (Item));
10398 T2 := First_Entity (Scop);
10399 while Present (T2) loop
10400 if Is_Fixed_Point_Type (T2)
10401 and then Scope (Base_Type (T2)) = Scop
10402 and then (Is_Potentially_Use_Visible (T2) or else In_Use (T2))
10403 then
10404 if Present (T1) then
10405 Fixed_Point_Error;
10406 return Any_Type;
10407 else
10408 T1 := T2;
10409 end if;
10410 end if;
10412 Next_Entity (T2);
10413 end loop;
10414 end if;
10416 Next (Item);
10417 end loop;
10419 if Nkind (N) = N_Real_Literal then
10420 Error_Msg_NE ("?real literal interpreted as }!", N, T1);
10421 else
10422 Error_Msg_NE ("?universal_fixed expression interpreted as }!", N, T1);
10423 end if;
10425 return T1;
10426 end Unique_Fixed_Point_Type;
10428 ----------------------
10429 -- Valid_Conversion --
10430 ----------------------
10432 function Valid_Conversion
10433 (N : Node_Id;
10434 Target : Entity_Id;
10435 Operand : Node_Id;
10436 Report_Errs : Boolean := True) return Boolean
10438 Target_Type : constant Entity_Id := Base_Type (Target);
10439 Opnd_Type : Entity_Id := Etype (Operand);
10441 function Conversion_Check
10442 (Valid : Boolean;
10443 Msg : String) return Boolean;
10444 -- Little routine to post Msg if Valid is False, returns Valid value
10446 -- The following are badly named, this kind of overloading is actively
10447 -- confusing in reading code, please rename to something like
10448 -- Error_Msg_N_If_Reporting ???
10450 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id);
10451 -- If Report_Errs, then calls Errout.Error_Msg_N with its arguments
10453 procedure Error_Msg_NE
10454 (Msg : String;
10455 N : Node_Or_Entity_Id;
10456 E : Node_Or_Entity_Id);
10457 -- If Report_Errs, then calls Errout.Error_Msg_NE with its arguments
10459 function Valid_Tagged_Conversion
10460 (Target_Type : Entity_Id;
10461 Opnd_Type : Entity_Id) return Boolean;
10462 -- Specifically test for validity of tagged conversions
10464 function Valid_Array_Conversion return Boolean;
10465 -- Check index and component conformance, and accessibility levels if
10466 -- the component types are anonymous access types (Ada 2005).
10468 ----------------------
10469 -- Conversion_Check --
10470 ----------------------
10472 function Conversion_Check
10473 (Valid : Boolean;
10474 Msg : String) return Boolean
10476 begin
10477 if not Valid
10479 -- A generic unit has already been analyzed and we have verified
10480 -- that a particular conversion is OK in that context. Since the
10481 -- instance is reanalyzed without relying on the relationships
10482 -- established during the analysis of the generic, it is possible
10483 -- to end up with inconsistent views of private types. Do not emit
10484 -- the error message in such cases. The rest of the machinery in
10485 -- Valid_Conversion still ensures the proper compatibility of
10486 -- target and operand types.
10488 and then not In_Instance
10489 then
10490 Error_Msg_N (Msg, Operand);
10491 end if;
10493 return Valid;
10494 end Conversion_Check;
10496 -----------------
10497 -- Error_Msg_N --
10498 -----------------
10500 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
10501 begin
10502 if Report_Errs then
10503 Errout.Error_Msg_N (Msg, N);
10504 end if;
10505 end Error_Msg_N;
10507 ------------------
10508 -- Error_Msg_NE --
10509 ------------------
10511 procedure Error_Msg_NE
10512 (Msg : String;
10513 N : Node_Or_Entity_Id;
10514 E : Node_Or_Entity_Id)
10516 begin
10517 if Report_Errs then
10518 Errout.Error_Msg_NE (Msg, N, E);
10519 end if;
10520 end Error_Msg_NE;
10522 ----------------------------
10523 -- Valid_Array_Conversion --
10524 ----------------------------
10526 function Valid_Array_Conversion return Boolean
10528 Opnd_Comp_Type : constant Entity_Id := Component_Type (Opnd_Type);
10529 Opnd_Comp_Base : constant Entity_Id := Base_Type (Opnd_Comp_Type);
10531 Opnd_Index : Node_Id;
10532 Opnd_Index_Type : Entity_Id;
10534 Target_Comp_Type : constant Entity_Id :=
10535 Component_Type (Target_Type);
10536 Target_Comp_Base : constant Entity_Id :=
10537 Base_Type (Target_Comp_Type);
10539 Target_Index : Node_Id;
10540 Target_Index_Type : Entity_Id;
10542 begin
10543 -- Error if wrong number of dimensions
10546 Number_Dimensions (Target_Type) /= Number_Dimensions (Opnd_Type)
10547 then
10548 Error_Msg_N
10549 ("incompatible number of dimensions for conversion", Operand);
10550 return False;
10552 -- Number of dimensions matches
10554 else
10555 -- Loop through indexes of the two arrays
10557 Target_Index := First_Index (Target_Type);
10558 Opnd_Index := First_Index (Opnd_Type);
10559 while Present (Target_Index) and then Present (Opnd_Index) loop
10560 Target_Index_Type := Etype (Target_Index);
10561 Opnd_Index_Type := Etype (Opnd_Index);
10563 -- Error if index types are incompatible
10565 if not (Is_Integer_Type (Target_Index_Type)
10566 and then Is_Integer_Type (Opnd_Index_Type))
10567 and then (Root_Type (Target_Index_Type)
10568 /= Root_Type (Opnd_Index_Type))
10569 then
10570 Error_Msg_N
10571 ("incompatible index types for array conversion",
10572 Operand);
10573 return False;
10574 end if;
10576 Next_Index (Target_Index);
10577 Next_Index (Opnd_Index);
10578 end loop;
10580 -- If component types have same base type, all set
10582 if Target_Comp_Base = Opnd_Comp_Base then
10583 null;
10585 -- Here if base types of components are not the same. The only
10586 -- time this is allowed is if we have anonymous access types.
10588 -- The conversion of arrays of anonymous access types can lead
10589 -- to dangling pointers. AI-392 formalizes the accessibility
10590 -- checks that must be applied to such conversions to prevent
10591 -- out-of-scope references.
10593 elsif Ekind_In
10594 (Target_Comp_Base, E_Anonymous_Access_Type,
10595 E_Anonymous_Access_Subprogram_Type)
10596 and then Ekind (Opnd_Comp_Base) = Ekind (Target_Comp_Base)
10597 and then
10598 Subtypes_Statically_Match (Target_Comp_Type, Opnd_Comp_Type)
10599 then
10600 if Type_Access_Level (Target_Type) <
10601 Deepest_Type_Access_Level (Opnd_Type)
10602 then
10603 if In_Instance_Body then
10604 Error_Msg_N
10605 ("?source array type has " &
10606 "deeper accessibility level than target", Operand);
10607 Error_Msg_N
10608 ("\?Program_Error will be raised at run time",
10609 Operand);
10610 Rewrite (N,
10611 Make_Raise_Program_Error (Sloc (N),
10612 Reason => PE_Accessibility_Check_Failed));
10613 Set_Etype (N, Target_Type);
10614 return False;
10616 -- Conversion not allowed because of accessibility levels
10618 else
10619 Error_Msg_N
10620 ("source array type has " &
10621 "deeper accessibility level than target", Operand);
10622 return False;
10623 end if;
10625 else
10626 null;
10627 end if;
10629 -- All other cases where component base types do not match
10631 else
10632 Error_Msg_N
10633 ("incompatible component types for array conversion",
10634 Operand);
10635 return False;
10636 end if;
10638 -- Check that component subtypes statically match. For numeric
10639 -- types this means that both must be either constrained or
10640 -- unconstrained. For enumeration types the bounds must match.
10641 -- All of this is checked in Subtypes_Statically_Match.
10643 if not Subtypes_Statically_Match
10644 (Target_Comp_Type, Opnd_Comp_Type)
10645 then
10646 Error_Msg_N
10647 ("component subtypes must statically match", Operand);
10648 return False;
10649 end if;
10650 end if;
10652 return True;
10653 end Valid_Array_Conversion;
10655 -----------------------------
10656 -- Valid_Tagged_Conversion --
10657 -----------------------------
10659 function Valid_Tagged_Conversion
10660 (Target_Type : Entity_Id;
10661 Opnd_Type : Entity_Id) return Boolean
10663 begin
10664 -- Upward conversions are allowed (RM 4.6(22))
10666 if Covers (Target_Type, Opnd_Type)
10667 or else Is_Ancestor (Target_Type, Opnd_Type)
10668 then
10669 return True;
10671 -- Downward conversion are allowed if the operand is class-wide
10672 -- (RM 4.6(23)).
10674 elsif Is_Class_Wide_Type (Opnd_Type)
10675 and then Covers (Opnd_Type, Target_Type)
10676 then
10677 return True;
10679 elsif Covers (Opnd_Type, Target_Type)
10680 or else Is_Ancestor (Opnd_Type, Target_Type)
10681 then
10682 return
10683 Conversion_Check (False,
10684 "downward conversion of tagged objects not allowed");
10686 -- Ada 2005 (AI-251): The conversion to/from interface types is
10687 -- always valid
10689 elsif Is_Interface (Target_Type) or else Is_Interface (Opnd_Type) then
10690 return True;
10692 -- If the operand is a class-wide type obtained through a limited_
10693 -- with clause, and the context includes the non-limited view, use
10694 -- it to determine whether the conversion is legal.
10696 elsif Is_Class_Wide_Type (Opnd_Type)
10697 and then From_With_Type (Opnd_Type)
10698 and then Present (Non_Limited_View (Etype (Opnd_Type)))
10699 and then Is_Interface (Non_Limited_View (Etype (Opnd_Type)))
10700 then
10701 return True;
10703 elsif Is_Access_Type (Opnd_Type)
10704 and then Is_Interface (Directly_Designated_Type (Opnd_Type))
10705 then
10706 return True;
10708 else
10709 Error_Msg_NE
10710 ("invalid tagged conversion, not compatible with}",
10711 N, First_Subtype (Opnd_Type));
10712 return False;
10713 end if;
10714 end Valid_Tagged_Conversion;
10716 -- Start of processing for Valid_Conversion
10718 begin
10719 Check_Parameterless_Call (Operand);
10721 if Is_Overloaded (Operand) then
10722 declare
10723 I : Interp_Index;
10724 I1 : Interp_Index;
10725 It : Interp;
10726 It1 : Interp;
10727 N1 : Entity_Id;
10728 T1 : Entity_Id;
10730 begin
10731 -- Remove procedure calls, which syntactically cannot appear in
10732 -- this context, but which cannot be removed by type checking,
10733 -- because the context does not impose a type.
10735 -- When compiling for VMS, spurious ambiguities can be produced
10736 -- when arithmetic operations have a literal operand and return
10737 -- System.Address or a descendant of it. These ambiguities are
10738 -- otherwise resolved by the context, but for conversions there
10739 -- is no context type and the removal of the spurious operations
10740 -- must be done explicitly here.
10742 -- The node may be labelled overloaded, but still contain only one
10743 -- interpretation because others were discarded earlier. If this
10744 -- is the case, retain the single interpretation if legal.
10746 Get_First_Interp (Operand, I, It);
10747 Opnd_Type := It.Typ;
10748 Get_Next_Interp (I, It);
10750 if Present (It.Typ)
10751 and then Opnd_Type /= Standard_Void_Type
10752 then
10753 -- More than one candidate interpretation is available
10755 Get_First_Interp (Operand, I, It);
10756 while Present (It.Typ) loop
10757 if It.Typ = Standard_Void_Type then
10758 Remove_Interp (I);
10759 end if;
10761 if Present (System_Aux_Id)
10762 and then Is_Descendent_Of_Address (It.Typ)
10763 then
10764 Remove_Interp (I);
10765 end if;
10767 Get_Next_Interp (I, It);
10768 end loop;
10769 end if;
10771 Get_First_Interp (Operand, I, It);
10772 I1 := I;
10773 It1 := It;
10775 if No (It.Typ) then
10776 Error_Msg_N ("illegal operand in conversion", Operand);
10777 return False;
10778 end if;
10780 Get_Next_Interp (I, It);
10782 if Present (It.Typ) then
10783 N1 := It1.Nam;
10784 T1 := It1.Typ;
10785 It1 := Disambiguate (Operand, I1, I, Any_Type);
10787 if It1 = No_Interp then
10788 Error_Msg_N ("ambiguous operand in conversion", Operand);
10790 -- If the interpretation involves a standard operator, use
10791 -- the location of the type, which may be user-defined.
10793 if Sloc (It.Nam) = Standard_Location then
10794 Error_Msg_Sloc := Sloc (It.Typ);
10795 else
10796 Error_Msg_Sloc := Sloc (It.Nam);
10797 end if;
10799 Error_Msg_N -- CODEFIX
10800 ("\\possible interpretation#!", Operand);
10802 if Sloc (N1) = Standard_Location then
10803 Error_Msg_Sloc := Sloc (T1);
10804 else
10805 Error_Msg_Sloc := Sloc (N1);
10806 end if;
10808 Error_Msg_N -- CODEFIX
10809 ("\\possible interpretation#!", Operand);
10811 return False;
10812 end if;
10813 end if;
10815 Set_Etype (Operand, It1.Typ);
10816 Opnd_Type := It1.Typ;
10817 end;
10818 end if;
10820 -- Numeric types
10822 if Is_Numeric_Type (Target_Type) then
10824 -- A universal fixed expression can be converted to any numeric type
10826 if Opnd_Type = Universal_Fixed then
10827 return True;
10829 -- Also no need to check when in an instance or inlined body, because
10830 -- the legality has been established when the template was analyzed.
10831 -- Furthermore, numeric conversions may occur where only a private
10832 -- view of the operand type is visible at the instantiation point.
10833 -- This results in a spurious error if we check that the operand type
10834 -- is a numeric type.
10836 -- Note: in a previous version of this unit, the following tests were
10837 -- applied only for generated code (Comes_From_Source set to False),
10838 -- but in fact the test is required for source code as well, since
10839 -- this situation can arise in source code.
10841 elsif In_Instance or else In_Inlined_Body then
10842 return True;
10844 -- Otherwise we need the conversion check
10846 else
10847 return Conversion_Check
10848 (Is_Numeric_Type (Opnd_Type),
10849 "illegal operand for numeric conversion");
10850 end if;
10852 -- Array types
10854 elsif Is_Array_Type (Target_Type) then
10855 if not Is_Array_Type (Opnd_Type)
10856 or else Opnd_Type = Any_Composite
10857 or else Opnd_Type = Any_String
10858 then
10859 Error_Msg_N ("illegal operand for array conversion", Operand);
10860 return False;
10861 else
10862 return Valid_Array_Conversion;
10863 end if;
10865 -- Ada 2005 (AI-251): Anonymous access types where target references an
10866 -- interface type.
10868 elsif Ekind_In (Target_Type, E_General_Access_Type,
10869 E_Anonymous_Access_Type)
10870 and then Is_Interface (Directly_Designated_Type (Target_Type))
10871 then
10872 -- Check the static accessibility rule of 4.6(17). Note that the
10873 -- check is not enforced when within an instance body, since the
10874 -- RM requires such cases to be caught at run time.
10876 -- If the operand is a rewriting of an allocator no check is needed
10877 -- because there are no accessibility issues.
10879 if Nkind (Original_Node (N)) = N_Allocator then
10880 null;
10882 elsif Ekind (Target_Type) /= E_Anonymous_Access_Type then
10883 if Type_Access_Level (Opnd_Type) >
10884 Deepest_Type_Access_Level (Target_Type)
10885 then
10886 -- In an instance, this is a run-time check, but one we know
10887 -- will fail, so generate an appropriate warning. The raise
10888 -- will be generated by Expand_N_Type_Conversion.
10890 if In_Instance_Body then
10891 Error_Msg_N
10892 ("?cannot convert local pointer to non-local access type",
10893 Operand);
10894 Error_Msg_N
10895 ("\?Program_Error will be raised at run time", Operand);
10897 else
10898 Error_Msg_N
10899 ("cannot convert local pointer to non-local access type",
10900 Operand);
10901 return False;
10902 end if;
10904 -- Special accessibility checks are needed in the case of access
10905 -- discriminants declared for a limited type.
10907 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
10908 and then not Is_Local_Anonymous_Access (Opnd_Type)
10909 then
10910 -- When the operand is a selected access discriminant the check
10911 -- needs to be made against the level of the object denoted by
10912 -- the prefix of the selected name (Object_Access_Level handles
10913 -- checking the prefix of the operand for this case).
10915 if Nkind (Operand) = N_Selected_Component
10916 and then Object_Access_Level (Operand) >
10917 Deepest_Type_Access_Level (Target_Type)
10918 then
10919 -- In an instance, this is a run-time check, but one we know
10920 -- will fail, so generate an appropriate warning. The raise
10921 -- will be generated by Expand_N_Type_Conversion.
10923 if In_Instance_Body then
10924 Error_Msg_N
10925 ("?cannot convert access discriminant to non-local" &
10926 " access type", Operand);
10927 Error_Msg_N
10928 ("\?Program_Error will be raised at run time", Operand);
10929 else
10930 Error_Msg_N
10931 ("cannot convert access discriminant to non-local" &
10932 " access type", Operand);
10933 return False;
10934 end if;
10935 end if;
10937 -- The case of a reference to an access discriminant from
10938 -- within a limited type declaration (which will appear as
10939 -- a discriminal) is always illegal because the level of the
10940 -- discriminant is considered to be deeper than any (nameable)
10941 -- access type.
10943 if Is_Entity_Name (Operand)
10944 and then not Is_Local_Anonymous_Access (Opnd_Type)
10945 and then
10946 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
10947 and then Present (Discriminal_Link (Entity (Operand)))
10948 then
10949 Error_Msg_N
10950 ("discriminant has deeper accessibility level than target",
10951 Operand);
10952 return False;
10953 end if;
10954 end if;
10955 end if;
10957 return True;
10959 -- General and anonymous access types
10961 elsif Ekind_In (Target_Type, E_General_Access_Type,
10962 E_Anonymous_Access_Type)
10963 and then
10964 Conversion_Check
10965 (Is_Access_Type (Opnd_Type)
10966 and then not
10967 Ekind_In (Opnd_Type, E_Access_Subprogram_Type,
10968 E_Access_Protected_Subprogram_Type),
10969 "must be an access-to-object type")
10970 then
10971 if Is_Access_Constant (Opnd_Type)
10972 and then not Is_Access_Constant (Target_Type)
10973 then
10974 Error_Msg_N
10975 ("access-to-constant operand type not allowed", Operand);
10976 return False;
10977 end if;
10979 -- Check the static accessibility rule of 4.6(17). Note that the
10980 -- check is not enforced when within an instance body, since the RM
10981 -- requires such cases to be caught at run time.
10983 if Ekind (Target_Type) /= E_Anonymous_Access_Type
10984 or else Is_Local_Anonymous_Access (Target_Type)
10985 or else Nkind (Associated_Node_For_Itype (Target_Type)) =
10986 N_Object_Declaration
10987 then
10988 -- Ada 2012 (AI05-0149): Perform legality checking on implicit
10989 -- conversions from an anonymous access type to a named general
10990 -- access type. Such conversions are not allowed in the case of
10991 -- access parameters and stand-alone objects of an anonymous
10992 -- access type. The implicit conversion case is recognized by
10993 -- testing that Comes_From_Source is False and that it's been
10994 -- rewritten. The Comes_From_Source test isn't sufficient because
10995 -- nodes in inlined calls to predefined library routines can have
10996 -- Comes_From_Source set to False. (Is there a better way to test
10997 -- for implicit conversions???)
10999 if Ada_Version >= Ada_2012
11000 and then not Comes_From_Source (N)
11001 and then N /= Original_Node (N)
11002 and then Ekind (Target_Type) = E_General_Access_Type
11003 and then Ekind (Opnd_Type) = E_Anonymous_Access_Type
11004 then
11005 if Is_Itype (Opnd_Type) then
11007 -- Implicit conversions aren't allowed for objects of an
11008 -- anonymous access type, since such objects have nonstatic
11009 -- levels in Ada 2012.
11011 if Nkind (Associated_Node_For_Itype (Opnd_Type)) =
11012 N_Object_Declaration
11013 then
11014 Error_Msg_N
11015 ("implicit conversion of stand-alone anonymous " &
11016 "access object not allowed", Operand);
11017 return False;
11019 -- Implicit conversions aren't allowed for anonymous access
11020 -- parameters. The "not Is_Local_Anonymous_Access_Type" test
11021 -- is done to exclude anonymous access results.
11023 elsif not Is_Local_Anonymous_Access (Opnd_Type)
11024 and then Nkind_In (Associated_Node_For_Itype (Opnd_Type),
11025 N_Function_Specification,
11026 N_Procedure_Specification)
11027 then
11028 Error_Msg_N
11029 ("implicit conversion of anonymous access formal " &
11030 "not allowed", Operand);
11031 return False;
11033 -- This is a case where there's an enclosing object whose
11034 -- to which the "statically deeper than" relationship does
11035 -- not apply (such as an access discriminant selected from
11036 -- a dereference of an access parameter).
11038 elsif Object_Access_Level (Operand)
11039 = Scope_Depth (Standard_Standard)
11040 then
11041 Error_Msg_N
11042 ("implicit conversion of anonymous access value " &
11043 "not allowed", Operand);
11044 return False;
11046 -- In other cases, the level of the operand's type must be
11047 -- statically less deep than that of the target type, else
11048 -- implicit conversion is disallowed (by RM12-8.6(27.1/3)).
11050 elsif Type_Access_Level (Opnd_Type) >
11051 Deepest_Type_Access_Level (Target_Type)
11052 then
11053 Error_Msg_N
11054 ("implicit conversion of anonymous access value " &
11055 "violates accessibility", Operand);
11056 return False;
11057 end if;
11058 end if;
11060 elsif Type_Access_Level (Opnd_Type) >
11061 Deepest_Type_Access_Level (Target_Type)
11062 then
11063 -- In an instance, this is a run-time check, but one we know
11064 -- will fail, so generate an appropriate warning. The raise
11065 -- will be generated by Expand_N_Type_Conversion.
11067 if In_Instance_Body then
11068 Error_Msg_N
11069 ("?cannot convert local pointer to non-local access type",
11070 Operand);
11071 Error_Msg_N
11072 ("\?Program_Error will be raised at run time", Operand);
11074 else
11075 -- Avoid generation of spurious error message
11077 if not Error_Posted (N) then
11078 Error_Msg_N
11079 ("cannot convert local pointer to non-local access type",
11080 Operand);
11081 end if;
11083 return False;
11084 end if;
11086 -- Special accessibility checks are needed in the case of access
11087 -- discriminants declared for a limited type.
11089 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type
11090 and then not Is_Local_Anonymous_Access (Opnd_Type)
11091 then
11092 -- When the operand is a selected access discriminant the check
11093 -- needs to be made against the level of the object denoted by
11094 -- the prefix of the selected name (Object_Access_Level handles
11095 -- checking the prefix of the operand for this case).
11097 if Nkind (Operand) = N_Selected_Component
11098 and then Object_Access_Level (Operand) >
11099 Deepest_Type_Access_Level (Target_Type)
11100 then
11101 -- In an instance, this is a run-time check, but one we know
11102 -- will fail, so generate an appropriate warning. The raise
11103 -- will be generated by Expand_N_Type_Conversion.
11105 if In_Instance_Body then
11106 Error_Msg_N
11107 ("?cannot convert access discriminant to non-local" &
11108 " access type", Operand);
11109 Error_Msg_N
11110 ("\?Program_Error will be raised at run time",
11111 Operand);
11113 else
11114 Error_Msg_N
11115 ("cannot convert access discriminant to non-local" &
11116 " access type", Operand);
11117 return False;
11118 end if;
11119 end if;
11121 -- The case of a reference to an access discriminant from
11122 -- within a limited type declaration (which will appear as
11123 -- a discriminal) is always illegal because the level of the
11124 -- discriminant is considered to be deeper than any (nameable)
11125 -- access type.
11127 if Is_Entity_Name (Operand)
11128 and then
11129 Ekind_In (Entity (Operand), E_In_Parameter, E_Constant)
11130 and then Present (Discriminal_Link (Entity (Operand)))
11131 then
11132 Error_Msg_N
11133 ("discriminant has deeper accessibility level than target",
11134 Operand);
11135 return False;
11136 end if;
11137 end if;
11138 end if;
11140 -- In the presence of limited_with clauses we have to use non-limited
11141 -- views, if available.
11143 Check_Limited : declare
11144 function Full_Designated_Type (T : Entity_Id) return Entity_Id;
11145 -- Helper function to handle limited views
11147 --------------------------
11148 -- Full_Designated_Type --
11149 --------------------------
11151 function Full_Designated_Type (T : Entity_Id) return Entity_Id is
11152 Desig : constant Entity_Id := Designated_Type (T);
11154 begin
11155 -- Handle the limited view of a type
11157 if Is_Incomplete_Type (Desig)
11158 and then From_With_Type (Desig)
11159 and then Present (Non_Limited_View (Desig))
11160 then
11161 return Available_View (Desig);
11162 else
11163 return Desig;
11164 end if;
11165 end Full_Designated_Type;
11167 -- Local Declarations
11169 Target : constant Entity_Id := Full_Designated_Type (Target_Type);
11170 Opnd : constant Entity_Id := Full_Designated_Type (Opnd_Type);
11172 Same_Base : constant Boolean :=
11173 Base_Type (Target) = Base_Type (Opnd);
11175 -- Start of processing for Check_Limited
11177 begin
11178 if Is_Tagged_Type (Target) then
11179 return Valid_Tagged_Conversion (Target, Opnd);
11181 else
11182 if not Same_Base then
11183 Error_Msg_NE
11184 ("target designated type not compatible with }",
11185 N, Base_Type (Opnd));
11186 return False;
11188 -- Ada 2005 AI-384: legality rule is symmetric in both
11189 -- designated types. The conversion is legal (with possible
11190 -- constraint check) if either designated type is
11191 -- unconstrained.
11193 elsif Subtypes_Statically_Match (Target, Opnd)
11194 or else
11195 (Has_Discriminants (Target)
11196 and then
11197 (not Is_Constrained (Opnd)
11198 or else not Is_Constrained (Target)))
11199 then
11200 -- Special case, if Value_Size has been used to make the
11201 -- sizes different, the conversion is not allowed even
11202 -- though the subtypes statically match.
11204 if Known_Static_RM_Size (Target)
11205 and then Known_Static_RM_Size (Opnd)
11206 and then RM_Size (Target) /= RM_Size (Opnd)
11207 then
11208 Error_Msg_NE
11209 ("target designated subtype not compatible with }",
11210 N, Opnd);
11211 Error_Msg_NE
11212 ("\because sizes of the two designated subtypes differ",
11213 N, Opnd);
11214 return False;
11216 -- Normal case where conversion is allowed
11218 else
11219 return True;
11220 end if;
11222 else
11223 Error_Msg_NE
11224 ("target designated subtype not compatible with }",
11225 N, Opnd);
11226 return False;
11227 end if;
11228 end if;
11229 end Check_Limited;
11231 -- Access to subprogram types. If the operand is an access parameter,
11232 -- the type has a deeper accessibility that any master, and cannot be
11233 -- assigned. We must make an exception if the conversion is part of an
11234 -- assignment and the target is the return object of an extended return
11235 -- statement, because in that case the accessibility check takes place
11236 -- after the return.
11238 elsif Is_Access_Subprogram_Type (Target_Type)
11239 and then No (Corresponding_Remote_Type (Opnd_Type))
11240 then
11241 if Ekind (Base_Type (Opnd_Type)) = E_Anonymous_Access_Subprogram_Type
11242 and then Is_Entity_Name (Operand)
11243 and then Ekind (Entity (Operand)) = E_In_Parameter
11244 and then
11245 (Nkind (Parent (N)) /= N_Assignment_Statement
11246 or else not Is_Entity_Name (Name (Parent (N)))
11247 or else not Is_Return_Object (Entity (Name (Parent (N)))))
11248 then
11249 Error_Msg_N
11250 ("illegal attempt to store anonymous access to subprogram",
11251 Operand);
11252 Error_Msg_N
11253 ("\value has deeper accessibility than any master " &
11254 "(RM 3.10.2 (13))",
11255 Operand);
11257 Error_Msg_NE
11258 ("\use named access type for& instead of access parameter",
11259 Operand, Entity (Operand));
11260 end if;
11262 -- Check that the designated types are subtype conformant
11264 Check_Subtype_Conformant (New_Id => Designated_Type (Target_Type),
11265 Old_Id => Designated_Type (Opnd_Type),
11266 Err_Loc => N);
11268 -- Check the static accessibility rule of 4.6(20)
11270 if Type_Access_Level (Opnd_Type) >
11271 Deepest_Type_Access_Level (Target_Type)
11272 then
11273 Error_Msg_N
11274 ("operand type has deeper accessibility level than target",
11275 Operand);
11277 -- Check that if the operand type is declared in a generic body,
11278 -- then the target type must be declared within that same body
11279 -- (enforces last sentence of 4.6(20)).
11281 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
11282 declare
11283 O_Gen : constant Node_Id :=
11284 Enclosing_Generic_Body (Opnd_Type);
11286 T_Gen : Node_Id;
11288 begin
11289 T_Gen := Enclosing_Generic_Body (Target_Type);
11290 while Present (T_Gen) and then T_Gen /= O_Gen loop
11291 T_Gen := Enclosing_Generic_Body (T_Gen);
11292 end loop;
11294 if T_Gen /= O_Gen then
11295 Error_Msg_N
11296 ("target type must be declared in same generic body"
11297 & " as operand type", N);
11298 end if;
11299 end;
11300 end if;
11302 return True;
11304 -- Remote subprogram access types
11306 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
11307 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
11308 then
11309 -- It is valid to convert from one RAS type to another provided
11310 -- that their specification statically match.
11312 Check_Subtype_Conformant
11313 (New_Id =>
11314 Designated_Type (Corresponding_Remote_Type (Target_Type)),
11315 Old_Id =>
11316 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
11317 Err_Loc =>
11319 return True;
11321 -- If it was legal in the generic, it's legal in the instance
11323 elsif In_Instance_Body then
11324 return True;
11326 -- If both are tagged types, check legality of view conversions
11328 elsif Is_Tagged_Type (Target_Type)
11329 and then
11330 Is_Tagged_Type (Opnd_Type)
11331 then
11332 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
11334 -- Types derived from the same root type are convertible
11336 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
11337 return True;
11339 -- In an instance or an inlined body, there may be inconsistent views of
11340 -- the same type, or of types derived from a common root.
11342 elsif (In_Instance or In_Inlined_Body)
11343 and then
11344 Root_Type (Underlying_Type (Target_Type)) =
11345 Root_Type (Underlying_Type (Opnd_Type))
11346 then
11347 return True;
11349 -- Special check for common access type error case
11351 elsif Ekind (Target_Type) = E_Access_Type
11352 and then Is_Access_Type (Opnd_Type)
11353 then
11354 Error_Msg_N ("target type must be general access type!", N);
11355 Error_Msg_NE -- CODEFIX
11356 ("add ALL to }!", N, Target_Type);
11357 return False;
11359 else
11360 Error_Msg_NE ("invalid conversion, not compatible with }",
11361 N, Opnd_Type);
11362 return False;
11363 end if;
11364 end Valid_Conversion;
11366 end Sem_Res;