Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / ada / sem_res.adb
blobaf752663422a7073cd2aaed3bd705c44696e2f77
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-2005, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Debug_A; use Debug_A;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
33 with Expander; use Expander;
34 with Exp_Ch7; use Exp_Ch7;
35 with Exp_Tss; use Exp_Tss;
36 with Exp_Util; use Exp_Util;
37 with Freeze; use Freeze;
38 with Itypes; use Itypes;
39 with Lib; use Lib;
40 with Lib.Xref; use Lib.Xref;
41 with Namet; use Namet;
42 with Nmake; use Nmake;
43 with Nlists; use Nlists;
44 with Opt; use Opt;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
49 with Sem; use Sem;
50 with Sem_Aggr; use Sem_Aggr;
51 with Sem_Attr; use Sem_Attr;
52 with Sem_Cat; use Sem_Cat;
53 with Sem_Ch4; use Sem_Ch4;
54 with Sem_Ch6; use Sem_Ch6;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Dist; use Sem_Dist;
58 with Sem_Elab; use Sem_Elab;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Intr; use Sem_Intr;
61 with Sem_Util; use Sem_Util;
62 with Sem_Type; use Sem_Type;
63 with Sem_Warn; use Sem_Warn;
64 with Sinfo; use Sinfo;
65 with Snames; use Snames;
66 with Stand; use Stand;
67 with Stringt; use Stringt;
68 with Targparm; use Targparm;
69 with Tbuild; use Tbuild;
70 with Uintp; use Uintp;
71 with Urealp; use Urealp;
73 package body Sem_Res is
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 -- Second pass (top-down) type checking and overload resolution procedures
80 -- Typ is the type required by context. These procedures propagate the
81 -- type information recursively to the descendants of N. If the node
82 -- is not overloaded, its Etype is established in the first pass. If
83 -- overloaded, the Resolve routines set the correct type. For arith.
84 -- operators, the Etype is the base type of the context.
86 -- Note that Resolve_Attribute is separated off in Sem_Attr
88 procedure Ambiguous_Character (C : Node_Id);
89 -- Give list of candidate interpretations when a character literal cannot
90 -- be resolved.
92 procedure Check_Direct_Boolean_Op (N : Node_Id);
93 -- N is a binary operator node which may possibly operate on Boolean
94 -- operands. If the operator does have Boolean operands, then a call is
95 -- made to check the restriction No_Direct_Boolean_Operators.
97 procedure Check_Discriminant_Use (N : Node_Id);
98 -- Enforce the restrictions on the use of discriminants when constraining
99 -- a component of a discriminated type (record or concurrent type).
101 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id);
102 -- Given a node for an operator associated with type T, check that
103 -- the operator is visible. Operators all of whose operands are
104 -- universal must be checked for visibility during resolution
105 -- because their type is not determinable based on their operands.
107 function Check_Infinite_Recursion (N : Node_Id) return Boolean;
108 -- Given a call node, N, which is known to occur immediately within the
109 -- subprogram being called, determines whether it is a detectable case of
110 -- an infinite recursion, and if so, outputs appropriate messages. Returns
111 -- True if an infinite recursion is detected, and False otherwise.
113 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id);
114 -- If the type of the object being initialized uses the secondary stack
115 -- directly or indirectly, create a transient scope for the call to the
116 -- init proc. This is because we do not create transient scopes for the
117 -- initialization of individual components within the init proc itself.
118 -- Could be optimized away perhaps?
120 function Is_Predefined_Op (Nam : Entity_Id) return Boolean;
121 -- Utility to check whether the name in the call is a predefined
122 -- operator, in which case the call is made into an operator node.
123 -- An instance of an intrinsic conversion operation may be given
124 -- an operator name, but is not treated like an operator.
126 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id);
127 -- If a default expression in entry call N depends on the discriminants
128 -- of the task, it must be replaced with a reference to the discriminant
129 -- of the task being called.
131 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id);
132 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id);
133 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id);
134 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id);
135 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id);
136 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id);
137 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id);
138 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id);
139 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id);
140 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id);
141 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id);
142 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id);
143 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id);
144 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id);
145 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id);
146 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id);
147 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id);
148 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id);
149 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id);
150 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id);
151 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id);
152 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id);
153 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id);
154 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id);
155 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id);
156 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id);
157 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id);
158 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id);
159 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id);
160 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id);
161 procedure Resolve_Unchecked_Expression (N : Node_Id; Typ : Entity_Id);
162 procedure Resolve_Unchecked_Type_Conversion (N : Node_Id; Typ : Entity_Id);
164 function Operator_Kind
165 (Op_Name : Name_Id;
166 Is_Binary : Boolean) return Node_Kind;
167 -- Utility to map the name of an operator into the corresponding Node. Used
168 -- by other node rewriting procedures.
170 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id);
171 -- Resolve actuals of call, and add default expressions for missing ones.
173 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id);
174 -- Called from Resolve_Call, when the prefix denotes an entry or element
175 -- of entry family. Actuals are resolved as for subprograms, and the node
176 -- is rebuilt as an entry call. Also called for protected operations. Typ
177 -- is the context type, which is used when the operation is a protected
178 -- function with no arguments, and the return value is indexed.
180 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id);
181 -- A call to a user-defined intrinsic operator is rewritten as a call
182 -- to the corresponding predefined operator, with suitable conversions.
184 procedure Resolve_Intrinsic_Unary_Operator (N : Node_Id; Typ : Entity_Id);
185 -- Ditto, for unary operators (only arithmetic ones).
187 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id);
188 -- If an operator node resolves to a call to a user-defined operator,
189 -- rewrite the node as a function call.
191 procedure Make_Call_Into_Operator
192 (N : Node_Id;
193 Typ : Entity_Id;
194 Op_Id : Entity_Id);
195 -- Inverse transformation: if an operator is given in functional notation,
196 -- then after resolving the node, transform into an operator node, so
197 -- that operands are resolved properly. Recall that predefined operators
198 -- do not have a full signature and special resolution rules apply.
200 procedure Rewrite_Renamed_Operator
201 (N : Node_Id;
202 Op : Entity_Id;
203 Typ : Entity_Id);
204 -- An operator can rename another, e.g. in an instantiation. In that
205 -- case, the proper operator node must be constructed and resolved.
207 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id);
208 -- The String_Literal_Subtype is built for all strings that are not
209 -- operands of a static concatenation operation. If the argument is
210 -- not a N_String_Literal node, then the call has no effect.
212 procedure Set_Slice_Subtype (N : Node_Id);
213 -- Build subtype of array type, with the range specified by the slice
215 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id;
216 -- A universal_fixed expression in an universal context is unambiguous
217 -- if there is only one applicable fixed point type. Determining whether
218 -- there is only one requires a search over all visible entities, and
219 -- happens only in very pathological cases (see 6115-006).
221 function Valid_Conversion
222 (N : Node_Id;
223 Target : Entity_Id;
224 Operand : Node_Id) return Boolean;
225 -- Verify legality rules given in 4.6 (8-23). Target is the target
226 -- type of the conversion, which may be an implicit conversion of
227 -- an actual parameter to an anonymous access type (in which case
228 -- N denotes the actual parameter and N = Operand).
230 -------------------------
231 -- Ambiguous_Character --
232 -------------------------
234 procedure Ambiguous_Character (C : Node_Id) is
235 E : Entity_Id;
237 begin
238 if Nkind (C) = N_Character_Literal then
239 Error_Msg_N ("ambiguous character literal", C);
240 Error_Msg_N
241 ("\possible interpretations: Character, Wide_Character!", C);
243 E := Current_Entity (C);
245 if Present (E) then
247 while Present (E) loop
248 Error_Msg_NE ("\possible interpretation:}!", C, Etype (E));
249 E := Homonym (E);
250 end loop;
251 end if;
252 end if;
253 end Ambiguous_Character;
255 -------------------------
256 -- Analyze_And_Resolve --
257 -------------------------
259 procedure Analyze_And_Resolve (N : Node_Id) is
260 begin
261 Analyze (N);
262 Resolve (N);
263 end Analyze_And_Resolve;
265 procedure Analyze_And_Resolve (N : Node_Id; Typ : Entity_Id) is
266 begin
267 Analyze (N);
268 Resolve (N, Typ);
269 end Analyze_And_Resolve;
271 -- Version withs check(s) suppressed
273 procedure Analyze_And_Resolve
274 (N : Node_Id;
275 Typ : Entity_Id;
276 Suppress : Check_Id)
278 Scop : constant Entity_Id := Current_Scope;
280 begin
281 if Suppress = All_Checks then
282 declare
283 Svg : constant Suppress_Array := Scope_Suppress;
285 begin
286 Scope_Suppress := (others => True);
287 Analyze_And_Resolve (N, Typ);
288 Scope_Suppress := Svg;
289 end;
291 else
292 declare
293 Svg : constant Boolean := Scope_Suppress (Suppress);
295 begin
296 Scope_Suppress (Suppress) := True;
297 Analyze_And_Resolve (N, Typ);
298 Scope_Suppress (Suppress) := Svg;
299 end;
300 end if;
302 if Current_Scope /= Scop
303 and then Scope_Is_Transient
304 then
305 -- This can only happen if a transient scope was created
306 -- for an inner expression, which will be removed upon
307 -- completion of the analysis of an enclosing construct.
308 -- The transient scope must have the suppress status of
309 -- the enclosing environment, not of this Analyze call.
311 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
312 Scope_Suppress;
313 end if;
314 end Analyze_And_Resolve;
316 procedure Analyze_And_Resolve
317 (N : Node_Id;
318 Suppress : Check_Id)
320 Scop : constant Entity_Id := Current_Scope;
322 begin
323 if Suppress = All_Checks then
324 declare
325 Svg : constant Suppress_Array := Scope_Suppress;
327 begin
328 Scope_Suppress := (others => True);
329 Analyze_And_Resolve (N);
330 Scope_Suppress := Svg;
331 end;
333 else
334 declare
335 Svg : constant Boolean := Scope_Suppress (Suppress);
337 begin
338 Scope_Suppress (Suppress) := True;
339 Analyze_And_Resolve (N);
340 Scope_Suppress (Suppress) := Svg;
341 end;
342 end if;
344 if Current_Scope /= Scop
345 and then Scope_Is_Transient
346 then
347 Scope_Stack.Table (Scope_Stack.Last).Save_Scope_Suppress :=
348 Scope_Suppress;
349 end if;
350 end Analyze_And_Resolve;
352 -----------------------------
353 -- Check_Direct_Boolean_Op --
354 -----------------------------
356 procedure Check_Direct_Boolean_Op (N : Node_Id) is
357 begin
358 if Root_Type (Etype (Left_Opnd (N))) = Standard_Boolean then
359 Check_Restriction (No_Direct_Boolean_Operators, N);
360 end if;
361 end Check_Direct_Boolean_Op;
363 ----------------------------
364 -- Check_Discriminant_Use --
365 ----------------------------
367 procedure Check_Discriminant_Use (N : Node_Id) is
368 PN : constant Node_Id := Parent (N);
369 Disc : constant Entity_Id := Entity (N);
370 P : Node_Id;
371 D : Node_Id;
373 begin
374 -- Any use in a default expression is legal.
376 if In_Default_Expression then
377 null;
379 elsif Nkind (PN) = N_Range then
381 -- Discriminant cannot be used to constrain a scalar type.
383 P := Parent (PN);
385 if Nkind (P) = N_Range_Constraint
386 and then Nkind (Parent (P)) = N_Subtype_Indication
387 and then Nkind (Parent (Parent (P))) = N_Component_Definition
388 then
389 Error_Msg_N ("discriminant cannot constrain scalar type", N);
391 elsif Nkind (P) = N_Index_Or_Discriminant_Constraint then
393 -- The following check catches the unusual case where
394 -- a discriminant appears within an index constraint
395 -- that is part of a larger expression within a constraint
396 -- on a component, e.g. "C : Int range 1 .. F (new A(1 .. D))".
397 -- For now we only check case of record components, and
398 -- note that a similar check should also apply in the
399 -- case of discriminant constraints below. ???
401 -- Note that the check for N_Subtype_Declaration below is to
402 -- detect the valid use of discriminants in the constraints of a
403 -- subtype declaration when this subtype declaration appears
404 -- inside the scope of a record type (which is syntactically
405 -- illegal, but which may be created as part of derived type
406 -- processing for records). See Sem_Ch3.Build_Derived_Record_Type
407 -- for more info.
409 if Ekind (Current_Scope) = E_Record_Type
410 and then Scope (Disc) = Current_Scope
411 and then not
412 (Nkind (Parent (P)) = N_Subtype_Indication
413 and then
414 (Nkind (Parent (Parent (P))) = N_Component_Definition
415 or else
416 Nkind (Parent (Parent (P))) = N_Subtype_Declaration)
417 and then Paren_Count (N) = 0)
418 then
419 Error_Msg_N
420 ("discriminant must appear alone in component constraint", N);
421 return;
422 end if;
424 -- Detect a common beginner error:
426 -- type R (D : Positive := 100) is record
427 -- Name : String (1 .. D);
428 -- end record;
430 -- The default value causes an object of type R to be
431 -- allocated with room for Positive'Last characters.
433 declare
434 SI : Node_Id;
435 T : Entity_Id;
436 TB : Node_Id;
437 CB : Entity_Id;
439 function Large_Storage_Type (T : Entity_Id) return Boolean;
440 -- Return True if type T has a large enough range that
441 -- any array whose index type covered the whole range of
442 -- the type would likely raise Storage_Error.
444 ------------------------
445 -- Large_Storage_Type --
446 ------------------------
448 function Large_Storage_Type (T : Entity_Id) return Boolean is
449 begin
450 return
451 T = Standard_Integer
452 or else
453 T = Standard_Positive
454 or else
455 T = Standard_Natural;
456 end Large_Storage_Type;
458 begin
459 -- Check that the Disc has a large range
461 if not Large_Storage_Type (Etype (Disc)) then
462 goto No_Danger;
463 end if;
465 -- If the enclosing type is limited, we allocate only the
466 -- default value, not the maximum, and there is no need for
467 -- a warning.
469 if Is_Limited_Type (Scope (Disc)) then
470 goto No_Danger;
471 end if;
473 -- Check that it is the high bound
475 if N /= High_Bound (PN)
476 or else not Present (Discriminant_Default_Value (Disc))
477 then
478 goto No_Danger;
479 end if;
481 -- Check the array allows a large range at this bound.
482 -- First find the array
484 SI := Parent (P);
486 if Nkind (SI) /= N_Subtype_Indication then
487 goto No_Danger;
488 end if;
490 T := Entity (Subtype_Mark (SI));
492 if not Is_Array_Type (T) then
493 goto No_Danger;
494 end if;
496 -- Next, find the dimension
498 TB := First_Index (T);
499 CB := First (Constraints (P));
500 while True
501 and then Present (TB)
502 and then Present (CB)
503 and then CB /= PN
504 loop
505 Next_Index (TB);
506 Next (CB);
507 end loop;
509 if CB /= PN then
510 goto No_Danger;
511 end if;
513 -- Now, check the dimension has a large range
515 if not Large_Storage_Type (Etype (TB)) then
516 goto No_Danger;
517 end if;
519 -- Warn about the danger
521 Error_Msg_N
522 ("creation of & object may raise Storage_Error?",
523 Scope (Disc));
525 <<No_Danger>>
526 null;
528 end;
529 end if;
531 -- Legal case is in index or discriminant constraint
533 elsif Nkind (PN) = N_Index_Or_Discriminant_Constraint
534 or else Nkind (PN) = N_Discriminant_Association
535 then
536 if Paren_Count (N) > 0 then
537 Error_Msg_N
538 ("discriminant in constraint must appear alone", N);
539 end if;
541 return;
543 -- Otherwise, context is an expression. It should not be within
544 -- (i.e. a subexpression of) a constraint for a component.
546 else
547 D := PN;
548 P := Parent (PN);
550 while Nkind (P) /= N_Component_Declaration
551 and then Nkind (P) /= N_Subtype_Indication
552 and then Nkind (P) /= N_Entry_Declaration
553 loop
554 D := P;
555 P := Parent (P);
556 exit when No (P);
557 end loop;
559 -- If the discriminant is used in an expression that is a bound
560 -- of a scalar type, an Itype is created and the bounds are attached
561 -- to its range, not to the original subtype indication. Such use
562 -- is of course a double fault.
564 if (Nkind (P) = N_Subtype_Indication
565 and then
566 (Nkind (Parent (P)) = N_Component_Definition
567 or else
568 Nkind (Parent (P)) = N_Derived_Type_Definition)
569 and then D = Constraint (P))
571 -- The constraint itself may be given by a subtype indication,
572 -- rather than by a more common discrete range.
574 or else (Nkind (P) = N_Subtype_Indication
575 and then
576 Nkind (Parent (P)) = N_Index_Or_Discriminant_Constraint)
577 or else Nkind (P) = N_Entry_Declaration
578 or else Nkind (D) = N_Defining_Identifier
579 then
580 Error_Msg_N
581 ("discriminant in constraint must appear alone", N);
582 end if;
583 end if;
584 end Check_Discriminant_Use;
586 --------------------------------
587 -- Check_For_Visible_Operator --
588 --------------------------------
590 procedure Check_For_Visible_Operator (N : Node_Id; T : Entity_Id) is
591 begin
592 if Is_Invisible_Operator (N, T) then
593 Error_Msg_NE
594 ("operator for} is not directly visible!", N, First_Subtype (T));
595 Error_Msg_N ("use clause would make operation legal!", N);
596 end if;
597 end Check_For_Visible_Operator;
599 ------------------------------
600 -- Check_Infinite_Recursion --
601 ------------------------------
603 function Check_Infinite_Recursion (N : Node_Id) return Boolean is
604 P : Node_Id;
605 C : Node_Id;
607 function Same_Argument_List return Boolean;
608 -- Check whether list of actuals is identical to list of formals
609 -- of called function (which is also the enclosing scope).
611 ------------------------
612 -- Same_Argument_List --
613 ------------------------
615 function Same_Argument_List return Boolean is
616 A : Node_Id;
617 F : Entity_Id;
618 Subp : Entity_Id;
620 begin
621 if not Is_Entity_Name (Name (N)) then
622 return False;
623 else
624 Subp := Entity (Name (N));
625 end if;
627 F := First_Formal (Subp);
628 A := First_Actual (N);
630 while Present (F) and then Present (A) loop
631 if not Is_Entity_Name (A)
632 or else Entity (A) /= F
633 then
634 return False;
635 end if;
637 Next_Actual (A);
638 Next_Formal (F);
639 end loop;
641 return True;
642 end Same_Argument_List;
644 -- Start of processing for Check_Infinite_Recursion
646 begin
647 -- Loop moving up tree, quitting if something tells us we are
648 -- definitely not in an infinite recursion situation.
650 C := N;
651 loop
652 P := Parent (C);
653 exit when Nkind (P) = N_Subprogram_Body;
655 if Nkind (P) = N_Or_Else or else
656 Nkind (P) = N_And_Then or else
657 Nkind (P) = N_If_Statement or else
658 Nkind (P) = N_Case_Statement
659 then
660 return False;
662 elsif Nkind (P) = N_Handled_Sequence_Of_Statements
663 and then C /= First (Statements (P))
664 then
665 -- If the call is the expression of a return statement and
666 -- the actuals are identical to the formals, it's worth a
667 -- warning. However, we skip this if there is an immediately
668 -- preceding raise statement, since the call is never executed.
670 -- Furthermore, this corresponds to a common idiom:
672 -- function F (L : Thing) return Boolean is
673 -- begin
674 -- raise Program_Error;
675 -- return F (L);
676 -- end F;
678 -- for generating a stub function
680 if Nkind (Parent (N)) = N_Return_Statement
681 and then Same_Argument_List
682 then
683 exit when not Is_List_Member (Parent (N))
684 or else (Nkind (Prev (Parent (N))) /= N_Raise_Statement
685 and then
686 (Nkind (Prev (Parent (N))) not in N_Raise_xxx_Error
687 or else
688 Present (Condition (Prev (Parent (N))))));
689 end if;
691 return False;
693 else
694 C := P;
695 end if;
696 end loop;
698 Error_Msg_N ("possible infinite recursion?", N);
699 Error_Msg_N ("\Storage_Error may be raised at run time?", N);
701 return True;
702 end Check_Infinite_Recursion;
704 -------------------------------
705 -- Check_Initialization_Call --
706 -------------------------------
708 procedure Check_Initialization_Call (N : Entity_Id; Nam : Entity_Id) is
709 Typ : constant Entity_Id := Etype (First_Formal (Nam));
711 function Uses_SS (T : Entity_Id) return Boolean;
712 -- Check whether the creation of an object of the type will involve
713 -- use of the secondary stack. If T is a record type, this is true
714 -- if the expression for some component uses the secondary stack, eg.
715 -- through a call to a function that returns an unconstrained value.
716 -- False if T is controlled, because cleanups occur elsewhere.
718 -------------
719 -- Uses_SS --
720 -------------
722 function Uses_SS (T : Entity_Id) return Boolean is
723 Comp : Entity_Id;
724 Expr : Node_Id;
726 begin
727 if Is_Controlled (T) then
728 return False;
730 elsif Is_Array_Type (T) then
731 return Uses_SS (Component_Type (T));
733 elsif Is_Record_Type (T) then
734 Comp := First_Component (T);
736 while Present (Comp) loop
738 if Ekind (Comp) = E_Component
739 and then Nkind (Parent (Comp)) = N_Component_Declaration
740 then
741 Expr := Expression (Parent (Comp));
743 -- The expression for a dynamic component may be
744 -- rewritten as a dereference. Retrieve original
745 -- call.
747 if Nkind (Original_Node (Expr)) = N_Function_Call
748 and then Requires_Transient_Scope (Etype (Expr))
749 then
750 return True;
752 elsif Uses_SS (Etype (Comp)) then
753 return True;
754 end if;
755 end if;
757 Next_Component (Comp);
758 end loop;
760 return False;
762 else
763 return False;
764 end if;
765 end Uses_SS;
767 -- Start of processing for Check_Initialization_Call
769 begin
770 -- Nothing to do if functions do not use the secondary stack for
771 -- returns (i.e. they use a depressed stack pointer instead).
773 if Functions_Return_By_DSP_On_Target then
774 return;
776 -- Otherwise establish a transient scope if the type needs it
778 elsif Uses_SS (Typ) then
779 Establish_Transient_Scope (First_Actual (N), Sec_Stack => True);
780 end if;
781 end Check_Initialization_Call;
783 ------------------------------
784 -- Check_Parameterless_Call --
785 ------------------------------
787 procedure Check_Parameterless_Call (N : Node_Id) is
788 Nam : Node_Id;
790 begin
791 -- Defend against junk stuff if errors already detected
793 if Total_Errors_Detected /= 0 then
794 if Nkind (N) in N_Has_Etype and then Etype (N) = Any_Type then
795 return;
796 elsif Nkind (N) in N_Has_Chars
797 and then Chars (N) in Error_Name_Or_No_Name
798 then
799 return;
800 end if;
802 Require_Entity (N);
803 end if;
805 -- If the context expects a value, and the name is a procedure,
806 -- this is most likely a missing 'Access. Do not try to resolve
807 -- the parameterless call, error will be caught when the outer
808 -- call is analyzed.
810 if Is_Entity_Name (N)
811 and then Ekind (Entity (N)) = E_Procedure
812 and then not Is_Overloaded (N)
813 and then
814 (Nkind (Parent (N)) = N_Parameter_Association
815 or else Nkind (Parent (N)) = N_Function_Call
816 or else Nkind (Parent (N)) = N_Procedure_Call_Statement)
817 then
818 return;
819 end if;
821 -- Rewrite as call if overloadable entity that is (or could be, in
822 -- the overloaded case) a function call. If we know for sure that
823 -- the entity is an enumeration literal, we do not rewrite it.
825 if (Is_Entity_Name (N)
826 and then Is_Overloadable (Entity (N))
827 and then (Ekind (Entity (N)) /= E_Enumeration_Literal
828 or else Is_Overloaded (N)))
830 -- Rewrite as call if it is an explicit deference of an expression of
831 -- a subprogram access type, and the suprogram type is not that of a
832 -- procedure or entry.
834 or else
835 (Nkind (N) = N_Explicit_Dereference
836 and then Ekind (Etype (N)) = E_Subprogram_Type
837 and then Base_Type (Etype (Etype (N))) /= Standard_Void_Type)
839 -- Rewrite as call if it is a selected component which is a function,
840 -- this is the case of a call to a protected function (which may be
841 -- overloaded with other protected operations).
843 or else
844 (Nkind (N) = N_Selected_Component
845 and then (Ekind (Entity (Selector_Name (N))) = E_Function
846 or else
847 ((Ekind (Entity (Selector_Name (N))) = E_Entry
848 or else
849 Ekind (Entity (Selector_Name (N))) = E_Procedure)
850 and then Is_Overloaded (Selector_Name (N)))))
852 -- If one of the above three conditions is met, rewrite as call.
853 -- Apply the rewriting only once.
855 then
856 if Nkind (Parent (N)) /= N_Function_Call
857 or else N /= Name (Parent (N))
858 then
859 Nam := New_Copy (N);
861 -- If overloaded, overload set belongs to new copy.
863 Save_Interps (N, Nam);
865 -- Change node to parameterless function call (note that the
866 -- Parameter_Associations associations field is left set to Empty,
867 -- its normal default value since there are no parameters)
869 Change_Node (N, N_Function_Call);
870 Set_Name (N, Nam);
871 Set_Sloc (N, Sloc (Nam));
872 Analyze_Call (N);
873 end if;
875 elsif Nkind (N) = N_Parameter_Association then
876 Check_Parameterless_Call (Explicit_Actual_Parameter (N));
877 end if;
878 end Check_Parameterless_Call;
880 ----------------------
881 -- Is_Predefined_Op --
882 ----------------------
884 function Is_Predefined_Op (Nam : Entity_Id) return Boolean is
885 begin
886 return Is_Intrinsic_Subprogram (Nam)
887 and then not Is_Generic_Instance (Nam)
888 and then Chars (Nam) in Any_Operator_Name
889 and then (No (Alias (Nam))
890 or else Is_Predefined_Op (Alias (Nam)));
891 end Is_Predefined_Op;
893 -----------------------------
894 -- Make_Call_Into_Operator --
895 -----------------------------
897 procedure Make_Call_Into_Operator
898 (N : Node_Id;
899 Typ : Entity_Id;
900 Op_Id : Entity_Id)
902 Op_Name : constant Name_Id := Chars (Op_Id);
903 Act1 : Node_Id := First_Actual (N);
904 Act2 : Node_Id := Next_Actual (Act1);
905 Error : Boolean := False;
906 Func : constant Entity_Id := Entity (Name (N));
907 Is_Binary : constant Boolean := Present (Act2);
908 Op_Node : Node_Id;
909 Opnd_Type : Entity_Id;
910 Orig_Type : Entity_Id := Empty;
911 Pack : Entity_Id;
913 type Kind_Test is access function (E : Entity_Id) return Boolean;
915 function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
916 -- Determine whether E is an access type declared by an access decla-
917 -- ration, and not an (anonymous) allocator type.
919 function Operand_Type_In_Scope (S : Entity_Id) return Boolean;
920 -- If the operand is not universal, and the operator is given by a
921 -- expanded name, verify that the operand has an interpretation with
922 -- a type defined in the given scope of the operator.
924 function Type_In_P (Test : Kind_Test) return Entity_Id;
925 -- Find a type of the given class in the package Pack that contains
926 -- the operator.
928 -----------------------------
929 -- Is_Definite_Access_Type --
930 -----------------------------
932 function Is_Definite_Access_Type (E : Entity_Id) return Boolean is
933 Btyp : constant Entity_Id := Base_Type (E);
934 begin
935 return Ekind (Btyp) = E_Access_Type
936 or else (Ekind (Btyp) = E_Access_Subprogram_Type
937 and then Comes_From_Source (Btyp));
938 end Is_Definite_Access_Type;
940 ---------------------------
941 -- Operand_Type_In_Scope --
942 ---------------------------
944 function Operand_Type_In_Scope (S : Entity_Id) return Boolean is
945 Nod : constant Node_Id := Right_Opnd (Op_Node);
946 I : Interp_Index;
947 It : Interp;
949 begin
950 if not Is_Overloaded (Nod) then
951 return Scope (Base_Type (Etype (Nod))) = S;
953 else
954 Get_First_Interp (Nod, I, It);
956 while Present (It.Typ) loop
958 if Scope (Base_Type (It.Typ)) = S then
959 return True;
960 end if;
962 Get_Next_Interp (I, It);
963 end loop;
965 return False;
966 end if;
967 end Operand_Type_In_Scope;
969 ---------------
970 -- Type_In_P --
971 ---------------
973 function Type_In_P (Test : Kind_Test) return Entity_Id is
974 E : Entity_Id;
976 function In_Decl return Boolean;
977 -- Verify that node is not part of the type declaration for the
978 -- candidate type, which would otherwise be invisible.
980 -------------
981 -- In_Decl --
982 -------------
984 function In_Decl return Boolean is
985 Decl_Node : constant Node_Id := Parent (E);
986 N2 : Node_Id;
988 begin
989 N2 := N;
991 if Etype (E) = Any_Type then
992 return True;
994 elsif No (Decl_Node) then
995 return False;
997 else
998 while Present (N2)
999 and then Nkind (N2) /= N_Compilation_Unit
1000 loop
1001 if N2 = Decl_Node then
1002 return True;
1003 else
1004 N2 := Parent (N2);
1005 end if;
1006 end loop;
1008 return False;
1009 end if;
1010 end In_Decl;
1012 -- Start of processing for Type_In_P
1014 begin
1015 -- If the context type is declared in the prefix package, this
1016 -- is the desired base type.
1018 if Scope (Base_Type (Typ)) = Pack
1019 and then Test (Typ)
1020 then
1021 return Base_Type (Typ);
1023 else
1024 E := First_Entity (Pack);
1026 while Present (E) loop
1028 if Test (E)
1029 and then not In_Decl
1030 then
1031 return E;
1032 end if;
1034 Next_Entity (E);
1035 end loop;
1037 return Empty;
1038 end if;
1039 end Type_In_P;
1041 -- Start of processing for Make_Call_Into_Operator
1043 begin
1044 Op_Node := New_Node (Operator_Kind (Op_Name, Is_Binary), Sloc (N));
1046 -- Binary operator
1048 if Is_Binary then
1049 Set_Left_Opnd (Op_Node, Relocate_Node (Act1));
1050 Set_Right_Opnd (Op_Node, Relocate_Node (Act2));
1051 Save_Interps (Act1, Left_Opnd (Op_Node));
1052 Save_Interps (Act2, Right_Opnd (Op_Node));
1053 Act1 := Left_Opnd (Op_Node);
1054 Act2 := Right_Opnd (Op_Node);
1056 -- Unary operator
1058 else
1059 Set_Right_Opnd (Op_Node, Relocate_Node (Act1));
1060 Save_Interps (Act1, Right_Opnd (Op_Node));
1061 Act1 := Right_Opnd (Op_Node);
1062 end if;
1064 -- If the operator is denoted by an expanded name, and the prefix is
1065 -- not Standard, but the operator is a predefined one whose scope is
1066 -- Standard, then this is an implicit_operator, inserted as an
1067 -- interpretation by the procedure of the same name. This procedure
1068 -- overestimates the presence of implicit operators, because it does
1069 -- not examine the type of the operands. Verify now that the operand
1070 -- type appears in the given scope. If right operand is universal,
1071 -- check the other operand. In the case of concatenation, either
1072 -- argument can be the component type, so check the type of the result.
1073 -- If both arguments are literals, look for a type of the right kind
1074 -- defined in the given scope. This elaborate nonsense is brought to
1075 -- you courtesy of b33302a. The type itself must be frozen, so we must
1076 -- find the type of the proper class in the given scope.
1078 -- A final wrinkle is the multiplication operator for fixed point
1079 -- types, which is defined in Standard only, and not in the scope of
1080 -- the fixed_point type itself.
1082 if Nkind (Name (N)) = N_Expanded_Name then
1083 Pack := Entity (Prefix (Name (N)));
1085 -- If the entity being called is defined in the given package,
1086 -- it is a renaming of a predefined operator, and known to be
1087 -- legal.
1089 if Scope (Entity (Name (N))) = Pack
1090 and then Pack /= Standard_Standard
1091 then
1092 null;
1094 elsif (Op_Name = Name_Op_Multiply
1095 or else Op_Name = Name_Op_Divide)
1096 and then Is_Fixed_Point_Type (Etype (Left_Opnd (Op_Node)))
1097 and then Is_Fixed_Point_Type (Etype (Right_Opnd (Op_Node)))
1098 then
1099 if Pack /= Standard_Standard then
1100 Error := True;
1101 end if;
1103 else
1104 Opnd_Type := Base_Type (Etype (Right_Opnd (Op_Node)));
1106 if Op_Name = Name_Op_Concat then
1107 Opnd_Type := Base_Type (Typ);
1109 elsif (Scope (Opnd_Type) = Standard_Standard
1110 and then Is_Binary)
1111 or else (Nkind (Right_Opnd (Op_Node)) = N_Attribute_Reference
1112 and then Is_Binary
1113 and then not Comes_From_Source (Opnd_Type))
1114 then
1115 Opnd_Type := Base_Type (Etype (Left_Opnd (Op_Node)));
1116 end if;
1118 if Scope (Opnd_Type) = Standard_Standard then
1120 -- Verify that the scope contains a type that corresponds to
1121 -- the given literal. Optimize the case where Pack is Standard.
1123 if Pack /= Standard_Standard then
1125 if Opnd_Type = Universal_Integer then
1126 Orig_Type := Type_In_P (Is_Integer_Type'Access);
1128 elsif Opnd_Type = Universal_Real then
1129 Orig_Type := Type_In_P (Is_Real_Type'Access);
1131 elsif Opnd_Type = Any_String then
1132 Orig_Type := Type_In_P (Is_String_Type'Access);
1134 elsif Opnd_Type = Any_Access then
1135 Orig_Type := Type_In_P (Is_Definite_Access_Type'Access);
1137 elsif Opnd_Type = Any_Composite then
1138 Orig_Type := Type_In_P (Is_Composite_Type'Access);
1140 if Present (Orig_Type) then
1141 if Has_Private_Component (Orig_Type) then
1142 Orig_Type := Empty;
1143 else
1144 Set_Etype (Act1, Orig_Type);
1146 if Is_Binary then
1147 Set_Etype (Act2, Orig_Type);
1148 end if;
1149 end if;
1150 end if;
1152 else
1153 Orig_Type := Empty;
1154 end if;
1156 Error := No (Orig_Type);
1157 end if;
1159 elsif Ekind (Opnd_Type) = E_Allocator_Type
1160 and then No (Type_In_P (Is_Definite_Access_Type'Access))
1161 then
1162 Error := True;
1164 -- If the type is defined elsewhere, and the operator is not
1165 -- defined in the given scope (by a renaming declaration, e.g.)
1166 -- then this is an error as well. If an extension of System is
1167 -- present, and the type may be defined there, Pack must be
1168 -- System itself.
1170 elsif Scope (Opnd_Type) /= Pack
1171 and then Scope (Op_Id) /= Pack
1172 and then (No (System_Aux_Id)
1173 or else Scope (Opnd_Type) /= System_Aux_Id
1174 or else Pack /= Scope (System_Aux_Id))
1175 then
1176 if not Is_Overloaded (Right_Opnd (Op_Node)) then
1177 Error := True;
1178 else
1179 Error := not Operand_Type_In_Scope (Pack);
1180 end if;
1182 elsif Pack = Standard_Standard
1183 and then not Operand_Type_In_Scope (Standard_Standard)
1184 then
1185 Error := True;
1186 end if;
1187 end if;
1189 if Error then
1190 Error_Msg_Node_2 := Pack;
1191 Error_Msg_NE
1192 ("& not declared in&", N, Selector_Name (Name (N)));
1193 Set_Etype (N, Any_Type);
1194 return;
1195 end if;
1196 end if;
1198 Set_Chars (Op_Node, Op_Name);
1200 if not Is_Private_Type (Etype (N)) then
1201 Set_Etype (Op_Node, Base_Type (Etype (N)));
1202 else
1203 Set_Etype (Op_Node, Etype (N));
1204 end if;
1206 -- If this is a call to a function that renames a predefined equality,
1207 -- the renaming declaration provides a type that must be used to
1208 -- resolve the operands. This must be done now because resolution of
1209 -- the equality node will not resolve any remaining ambiguity, and it
1210 -- assumes that the first operand is not overloaded.
1212 if (Op_Name = Name_Op_Eq or else Op_Name = Name_Op_Ne)
1213 and then Ekind (Func) = E_Function
1214 and then Is_Overloaded (Act1)
1215 then
1216 Resolve (Act1, Base_Type (Etype (First_Formal (Func))));
1217 Resolve (Act2, Base_Type (Etype (First_Formal (Func))));
1218 end if;
1220 Set_Entity (Op_Node, Op_Id);
1221 Generate_Reference (Op_Id, N, ' ');
1222 Rewrite (N, Op_Node);
1224 -- If this is an arithmetic operator and the result type is private,
1225 -- the operands and the result must be wrapped in conversion to
1226 -- expose the underlying numeric type and expand the proper checks,
1227 -- e.g. on division.
1229 if Is_Private_Type (Typ) then
1230 case Nkind (N) is
1231 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
1232 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
1233 Resolve_Intrinsic_Operator (N, Typ);
1235 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
1236 Resolve_Intrinsic_Unary_Operator (N, Typ);
1238 when others =>
1239 Resolve (N, Typ);
1240 end case;
1241 else
1242 Resolve (N, Typ);
1243 end if;
1245 -- For predefined operators on literals, the operation freezes
1246 -- their type.
1248 if Present (Orig_Type) then
1249 Set_Etype (Act1, Orig_Type);
1250 Freeze_Expression (Act1);
1251 end if;
1252 end Make_Call_Into_Operator;
1254 -------------------
1255 -- Operator_Kind --
1256 -------------------
1258 function Operator_Kind
1259 (Op_Name : Name_Id;
1260 Is_Binary : Boolean) return Node_Kind
1262 Kind : Node_Kind;
1264 begin
1265 if Is_Binary then
1266 if Op_Name = Name_Op_And then Kind := N_Op_And;
1267 elsif Op_Name = Name_Op_Or then Kind := N_Op_Or;
1268 elsif Op_Name = Name_Op_Xor then Kind := N_Op_Xor;
1269 elsif Op_Name = Name_Op_Eq then Kind := N_Op_Eq;
1270 elsif Op_Name = Name_Op_Ne then Kind := N_Op_Ne;
1271 elsif Op_Name = Name_Op_Lt then Kind := N_Op_Lt;
1272 elsif Op_Name = Name_Op_Le then Kind := N_Op_Le;
1273 elsif Op_Name = Name_Op_Gt then Kind := N_Op_Gt;
1274 elsif Op_Name = Name_Op_Ge then Kind := N_Op_Ge;
1275 elsif Op_Name = Name_Op_Add then Kind := N_Op_Add;
1276 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Subtract;
1277 elsif Op_Name = Name_Op_Concat then Kind := N_Op_Concat;
1278 elsif Op_Name = Name_Op_Multiply then Kind := N_Op_Multiply;
1279 elsif Op_Name = Name_Op_Divide then Kind := N_Op_Divide;
1280 elsif Op_Name = Name_Op_Mod then Kind := N_Op_Mod;
1281 elsif Op_Name = Name_Op_Rem then Kind := N_Op_Rem;
1282 elsif Op_Name = Name_Op_Expon then Kind := N_Op_Expon;
1283 else
1284 raise Program_Error;
1285 end if;
1287 -- Unary operators
1289 else
1290 if Op_Name = Name_Op_Add then Kind := N_Op_Plus;
1291 elsif Op_Name = Name_Op_Subtract then Kind := N_Op_Minus;
1292 elsif Op_Name = Name_Op_Abs then Kind := N_Op_Abs;
1293 elsif Op_Name = Name_Op_Not then Kind := N_Op_Not;
1294 else
1295 raise Program_Error;
1296 end if;
1297 end if;
1299 return Kind;
1300 end Operator_Kind;
1302 -----------------------------
1303 -- Pre_Analyze_And_Resolve --
1304 -----------------------------
1306 procedure Pre_Analyze_And_Resolve (N : Node_Id; T : Entity_Id) is
1307 Save_Full_Analysis : constant Boolean := Full_Analysis;
1309 begin
1310 Full_Analysis := False;
1311 Expander_Mode_Save_And_Set (False);
1313 -- We suppress all checks for this analysis, since the checks will
1314 -- be applied properly, and in the right location, when the default
1315 -- expression is reanalyzed and reexpanded later on.
1317 Analyze_And_Resolve (N, T, Suppress => All_Checks);
1319 Expander_Mode_Restore;
1320 Full_Analysis := Save_Full_Analysis;
1321 end Pre_Analyze_And_Resolve;
1323 -- Version without context type.
1325 procedure Pre_Analyze_And_Resolve (N : Node_Id) is
1326 Save_Full_Analysis : constant Boolean := Full_Analysis;
1328 begin
1329 Full_Analysis := False;
1330 Expander_Mode_Save_And_Set (False);
1332 Analyze (N);
1333 Resolve (N, Etype (N), Suppress => All_Checks);
1335 Expander_Mode_Restore;
1336 Full_Analysis := Save_Full_Analysis;
1337 end Pre_Analyze_And_Resolve;
1339 ----------------------------------
1340 -- Replace_Actual_Discriminants --
1341 ----------------------------------
1343 procedure Replace_Actual_Discriminants (N : Node_Id; Default : Node_Id) is
1344 Loc : constant Source_Ptr := Sloc (N);
1345 Tsk : Node_Id := Empty;
1347 function Process_Discr (Nod : Node_Id) return Traverse_Result;
1349 -------------------
1350 -- Process_Discr --
1351 -------------------
1353 function Process_Discr (Nod : Node_Id) return Traverse_Result is
1354 Ent : Entity_Id;
1356 begin
1357 if Nkind (Nod) = N_Identifier then
1358 Ent := Entity (Nod);
1360 if Present (Ent)
1361 and then Ekind (Ent) = E_Discriminant
1362 then
1363 Rewrite (Nod,
1364 Make_Selected_Component (Loc,
1365 Prefix => New_Copy_Tree (Tsk, New_Sloc => Loc),
1366 Selector_Name => Make_Identifier (Loc, Chars (Ent))));
1368 Set_Etype (Nod, Etype (Ent));
1369 end if;
1371 end if;
1373 return OK;
1374 end Process_Discr;
1376 procedure Replace_Discrs is new Traverse_Proc (Process_Discr);
1378 -- Start of processing for Replace_Actual_Discriminants
1380 begin
1381 if not Expander_Active then
1382 return;
1383 end if;
1385 if Nkind (Name (N)) = N_Selected_Component then
1386 Tsk := Prefix (Name (N));
1388 elsif Nkind (Name (N)) = N_Indexed_Component then
1389 Tsk := Prefix (Prefix (Name (N)));
1390 end if;
1392 if No (Tsk) then
1393 return;
1394 else
1395 Replace_Discrs (Default);
1396 end if;
1397 end Replace_Actual_Discriminants;
1399 -------------
1400 -- Resolve --
1401 -------------
1403 procedure Resolve (N : Node_Id; Typ : Entity_Id) is
1404 I : Interp_Index;
1405 I1 : Interp_Index := 0; -- prevent junk warning
1406 It : Interp;
1407 It1 : Interp;
1408 Found : Boolean := False;
1409 Seen : Entity_Id := Empty; -- prevent junk warning
1410 Ctx_Type : Entity_Id := Typ;
1411 Expr_Type : Entity_Id := Empty; -- prevent junk warning
1412 Err_Type : Entity_Id := Empty;
1413 Ambiguous : Boolean := False;
1415 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id);
1416 -- Try and fix up a literal so that it matches its expected type. New
1417 -- literals are manufactured if necessary to avoid cascaded errors.
1419 procedure Resolution_Failed;
1420 -- Called when attempt at resolving current expression fails
1422 --------------------
1423 -- Patch_Up_Value --
1424 --------------------
1426 procedure Patch_Up_Value (N : Node_Id; Typ : Entity_Id) is
1427 begin
1428 if Nkind (N) = N_Integer_Literal
1429 and then Is_Real_Type (Typ)
1430 then
1431 Rewrite (N,
1432 Make_Real_Literal (Sloc (N),
1433 Realval => UR_From_Uint (Intval (N))));
1434 Set_Etype (N, Universal_Real);
1435 Set_Is_Static_Expression (N);
1437 elsif Nkind (N) = N_Real_Literal
1438 and then Is_Integer_Type (Typ)
1439 then
1440 Rewrite (N,
1441 Make_Integer_Literal (Sloc (N),
1442 Intval => UR_To_Uint (Realval (N))));
1443 Set_Etype (N, Universal_Integer);
1444 Set_Is_Static_Expression (N);
1445 elsif Nkind (N) = N_String_Literal
1446 and then Is_Character_Type (Typ)
1447 then
1448 Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
1449 Rewrite (N,
1450 Make_Character_Literal (Sloc (N),
1451 Chars => Name_Find,
1452 Char_Literal_Value =>
1453 UI_From_Int (Character'Pos ('A'))));
1454 Set_Etype (N, Any_Character);
1455 Set_Is_Static_Expression (N);
1457 elsif Nkind (N) /= N_String_Literal
1458 and then Is_String_Type (Typ)
1459 then
1460 Rewrite (N,
1461 Make_String_Literal (Sloc (N),
1462 Strval => End_String));
1464 elsif Nkind (N) = N_Range then
1465 Patch_Up_Value (Low_Bound (N), Typ);
1466 Patch_Up_Value (High_Bound (N), Typ);
1467 end if;
1468 end Patch_Up_Value;
1470 -----------------------
1471 -- Resolution_Failed --
1472 -----------------------
1474 procedure Resolution_Failed is
1475 begin
1476 Patch_Up_Value (N, Typ);
1477 Set_Etype (N, Typ);
1478 Debug_A_Exit ("resolving ", N, " (done, resolution failed)");
1479 Set_Is_Overloaded (N, False);
1481 -- The caller will return without calling the expander, so we need
1482 -- to set the analyzed flag. Note that it is fine to set Analyzed
1483 -- to True even if we are in the middle of a shallow analysis,
1484 -- (see the spec of sem for more details) since this is an error
1485 -- situation anyway, and there is no point in repeating the
1486 -- analysis later (indeed it won't work to repeat it later, since
1487 -- we haven't got a clear resolution of which entity is being
1488 -- referenced.)
1490 Set_Analyzed (N, True);
1491 return;
1492 end Resolution_Failed;
1494 -- Start of processing for Resolve
1496 begin
1497 if N = Error then
1498 return;
1499 end if;
1501 -- Access attribute on remote subprogram cannot be used for
1502 -- a non-remote access-to-subprogram type.
1504 if Nkind (N) = N_Attribute_Reference
1505 and then (Attribute_Name (N) = Name_Access
1506 or else Attribute_Name (N) = Name_Unrestricted_Access
1507 or else Attribute_Name (N) = Name_Unchecked_Access)
1508 and then Comes_From_Source (N)
1509 and then Is_Entity_Name (Prefix (N))
1510 and then Is_Subprogram (Entity (Prefix (N)))
1511 and then Is_Remote_Call_Interface (Entity (Prefix (N)))
1512 and then not Is_Remote_Access_To_Subprogram_Type (Typ)
1513 then
1514 Error_Msg_N
1515 ("prefix must statically denote a non-remote subprogram", N);
1516 end if;
1518 -- If the context is a Remote_Access_To_Subprogram, access attributes
1519 -- must be resolved with the corresponding fat pointer. There is no need
1520 -- to check for the attribute name since the return type of an
1521 -- attribute is never a remote type.
1523 if Nkind (N) = N_Attribute_Reference
1524 and then Comes_From_Source (N)
1525 and then (Is_Remote_Call_Interface (Typ)
1526 or else Is_Remote_Types (Typ))
1527 then
1528 declare
1529 Attr : constant Attribute_Id :=
1530 Get_Attribute_Id (Attribute_Name (N));
1531 Pref : constant Node_Id := Prefix (N);
1532 Decl : Node_Id;
1533 Spec : Node_Id;
1534 Is_Remote : Boolean := True;
1536 begin
1537 -- Check that Typ is a fat pointer with a reference to a RAS as
1538 -- original access type.
1541 (Ekind (Typ) = E_Access_Subprogram_Type
1542 and then Present (Equivalent_Type (Typ)))
1543 or else
1544 (Ekind (Typ) = E_Record_Type
1545 and then Present (Corresponding_Remote_Type (Typ)))
1547 then
1548 -- Prefix (N) must statically denote a remote subprogram
1549 -- declared in a package specification.
1551 if Attr = Attribute_Access then
1552 Decl := Unit_Declaration_Node (Entity (Pref));
1554 if Nkind (Decl) = N_Subprogram_Body then
1555 Spec := Corresponding_Spec (Decl);
1557 if not No (Spec) then
1558 Decl := Unit_Declaration_Node (Spec);
1559 end if;
1560 end if;
1562 Spec := Parent (Decl);
1564 if not Is_Entity_Name (Prefix (N))
1565 or else Nkind (Spec) /= N_Package_Specification
1566 or else
1567 not Is_Remote_Call_Interface (Defining_Entity (Spec))
1568 then
1569 Is_Remote := False;
1570 Error_Msg_N
1571 ("prefix must statically denote a remote subprogram ",
1573 end if;
1574 end if;
1576 -- If we are generating code for a distributed program.
1577 -- perform semantic checks against the corresponding
1578 -- remote entities.
1580 if (Attr = Attribute_Access
1581 or else Attr = Attribute_Unchecked_Access
1582 or else Attr = Attribute_Unrestricted_Access)
1583 and then Expander_Active
1584 then
1585 Check_Subtype_Conformant
1586 (New_Id => Entity (Prefix (N)),
1587 Old_Id => Designated_Type
1588 (Corresponding_Remote_Type (Typ)),
1589 Err_Loc => N);
1590 if Is_Remote then
1591 Process_Remote_AST_Attribute (N, Typ);
1592 end if;
1593 end if;
1594 end if;
1595 end;
1596 end if;
1598 Debug_A_Entry ("resolving ", N);
1600 if Comes_From_Source (N) then
1601 if Is_Fixed_Point_Type (Typ) then
1602 Check_Restriction (No_Fixed_Point, N);
1604 elsif Is_Floating_Point_Type (Typ)
1605 and then Typ /= Universal_Real
1606 and then Typ /= Any_Real
1607 then
1608 Check_Restriction (No_Floating_Point, N);
1609 end if;
1610 end if;
1612 -- Return if already analyzed
1614 if Analyzed (N) then
1615 Debug_A_Exit ("resolving ", N, " (done, already analyzed)");
1616 return;
1618 -- Return if type = Any_Type (previous error encountered)
1620 elsif Etype (N) = Any_Type then
1621 Debug_A_Exit ("resolving ", N, " (done, Etype = Any_Type)");
1622 return;
1623 end if;
1625 Check_Parameterless_Call (N);
1627 -- If not overloaded, then we know the type, and all that needs doing
1628 -- is to check that this type is compatible with the context.
1630 if not Is_Overloaded (N) then
1631 Found := Covers (Typ, Etype (N));
1632 Expr_Type := Etype (N);
1634 -- In the overloaded case, we must select the interpretation that
1635 -- is compatible with the context (i.e. the type passed to Resolve)
1637 else
1638 Get_First_Interp (N, I, It);
1640 -- Loop through possible interpretations
1642 Interp_Loop : while Present (It.Typ) loop
1644 -- We are only interested in interpretations that are compatible
1645 -- with the expected type, any other interpretations are ignored
1647 if not Covers (Typ, It.Typ) then
1648 if Debug_Flag_V then
1649 Write_Str (" interpretation incompatible with context");
1650 Write_Eol;
1651 end if;
1653 else
1654 -- First matching interpretation
1656 if not Found then
1657 Found := True;
1658 I1 := I;
1659 Seen := It.Nam;
1660 Expr_Type := It.Typ;
1662 -- Matching interpretation that is not the first, maybe an
1663 -- error, but there are some cases where preference rules are
1664 -- used to choose between the two possibilities. These and
1665 -- some more obscure cases are handled in Disambiguate.
1667 else
1668 Error_Msg_Sloc := Sloc (Seen);
1669 It1 := Disambiguate (N, I1, I, Typ);
1671 -- Disambiguation has succeeded. Skip the remaining
1672 -- interpretations.
1674 if It1 /= No_Interp then
1675 Seen := It1.Nam;
1676 Expr_Type := It1.Typ;
1678 while Present (It.Typ) loop
1679 Get_Next_Interp (I, It);
1680 end loop;
1682 else
1683 -- Before we issue an ambiguity complaint, check for
1684 -- the case of a subprogram call where at least one
1685 -- of the arguments is Any_Type, and if so, suppress
1686 -- the message, since it is a cascaded error.
1688 if Nkind (N) = N_Function_Call
1689 or else Nkind (N) = N_Procedure_Call_Statement
1690 then
1691 declare
1692 A : Node_Id := First_Actual (N);
1693 E : Node_Id;
1695 begin
1696 while Present (A) loop
1697 E := A;
1699 if Nkind (E) = N_Parameter_Association then
1700 E := Explicit_Actual_Parameter (E);
1701 end if;
1703 if Etype (E) = Any_Type then
1704 if Debug_Flag_V then
1705 Write_Str ("Any_Type in call");
1706 Write_Eol;
1707 end if;
1709 exit Interp_Loop;
1710 end if;
1712 Next_Actual (A);
1713 end loop;
1714 end;
1716 elsif Nkind (N) in N_Binary_Op
1717 and then (Etype (Left_Opnd (N)) = Any_Type
1718 or else Etype (Right_Opnd (N)) = Any_Type)
1719 then
1720 exit Interp_Loop;
1722 elsif Nkind (N) in N_Unary_Op
1723 and then Etype (Right_Opnd (N)) = Any_Type
1724 then
1725 exit Interp_Loop;
1726 end if;
1728 -- Not that special case, so issue message using the
1729 -- flag Ambiguous to control printing of the header
1730 -- message only at the start of an ambiguous set.
1732 if not Ambiguous then
1733 Error_Msg_NE
1734 ("ambiguous expression (cannot resolve&)!",
1735 N, It.Nam);
1737 Error_Msg_N
1738 ("possible interpretation#!", N);
1739 Ambiguous := True;
1740 end if;
1742 Error_Msg_Sloc := Sloc (It.Nam);
1744 -- By default, the error message refers to the candidate
1745 -- interpretation. But if it is a predefined operator,
1746 -- it is implicitly declared at the declaration of
1747 -- the type of the operand. Recover the sloc of that
1748 -- declaration for the error message.
1750 if Nkind (N) in N_Op
1751 and then Scope (It.Nam) = Standard_Standard
1752 and then not Is_Overloaded (Right_Opnd (N))
1753 and then Scope (Base_Type (Etype (Right_Opnd (N))))
1754 /= Standard_Standard
1755 then
1756 Err_Type := First_Subtype (Etype (Right_Opnd (N)));
1758 if Comes_From_Source (Err_Type)
1759 and then Present (Parent (Err_Type))
1760 then
1761 Error_Msg_Sloc := Sloc (Parent (Err_Type));
1762 end if;
1764 elsif Nkind (N) in N_Binary_Op
1765 and then Scope (It.Nam) = Standard_Standard
1766 and then not Is_Overloaded (Left_Opnd (N))
1767 and then Scope (Base_Type (Etype (Left_Opnd (N))))
1768 /= Standard_Standard
1769 then
1770 Err_Type := First_Subtype (Etype (Left_Opnd (N)));
1772 if Comes_From_Source (Err_Type)
1773 and then Present (Parent (Err_Type))
1774 then
1775 Error_Msg_Sloc := Sloc (Parent (Err_Type));
1776 end if;
1777 else
1778 Err_Type := Empty;
1779 end if;
1781 if Nkind (N) in N_Op
1782 and then Scope (It.Nam) = Standard_Standard
1783 and then Present (Err_Type)
1784 then
1785 Error_Msg_N
1786 ("possible interpretation (predefined)#!", N);
1787 else
1788 Error_Msg_N ("possible interpretation#!", N);
1789 end if;
1791 end if;
1792 end if;
1794 -- We have a matching interpretation, Expr_Type is the
1795 -- type from this interpretation, and Seen is the entity.
1797 -- For an operator, just set the entity name. The type will
1798 -- be set by the specific operator resolution routine.
1800 if Nkind (N) in N_Op then
1801 Set_Entity (N, Seen);
1802 Generate_Reference (Seen, N);
1804 elsif Nkind (N) = N_Character_Literal then
1805 Set_Etype (N, Expr_Type);
1807 -- For an explicit dereference, attribute reference, range,
1808 -- short-circuit form (which is not an operator node),
1809 -- or a call with a name that is an explicit dereference,
1810 -- there is nothing to be done at this point.
1812 elsif Nkind (N) = N_Explicit_Dereference
1813 or else Nkind (N) = N_Attribute_Reference
1814 or else Nkind (N) = N_And_Then
1815 or else Nkind (N) = N_Indexed_Component
1816 or else Nkind (N) = N_Or_Else
1817 or else Nkind (N) = N_Range
1818 or else Nkind (N) = N_Selected_Component
1819 or else Nkind (N) = N_Slice
1820 or else Nkind (Name (N)) = N_Explicit_Dereference
1821 then
1822 null;
1824 -- For procedure or function calls, set the type of the
1825 -- name, and also the entity pointer for the prefix
1827 elsif (Nkind (N) = N_Procedure_Call_Statement
1828 or else Nkind (N) = N_Function_Call)
1829 and then (Is_Entity_Name (Name (N))
1830 or else Nkind (Name (N)) = N_Operator_Symbol)
1831 then
1832 Set_Etype (Name (N), Expr_Type);
1833 Set_Entity (Name (N), Seen);
1834 Generate_Reference (Seen, Name (N));
1836 elsif Nkind (N) = N_Function_Call
1837 and then Nkind (Name (N)) = N_Selected_Component
1838 then
1839 Set_Etype (Name (N), Expr_Type);
1840 Set_Entity (Selector_Name (Name (N)), Seen);
1841 Generate_Reference (Seen, Selector_Name (Name (N)));
1843 -- For all other cases, just set the type of the Name
1845 else
1846 Set_Etype (Name (N), Expr_Type);
1847 end if;
1849 end if;
1851 -- Move to next interpretation
1853 exit Interp_Loop when not Present (It.Typ);
1855 Get_Next_Interp (I, It);
1856 end loop Interp_Loop;
1857 end if;
1859 -- At this stage Found indicates whether or not an acceptable
1860 -- interpretation exists. If not, then we have an error, except
1861 -- that if the context is Any_Type as a result of some other error,
1862 -- then we suppress the error report.
1864 if not Found then
1865 if Typ /= Any_Type then
1867 -- If type we are looking for is Void, then this is the
1868 -- procedure call case, and the error is simply that what
1869 -- we gave is not a procedure name (we think of procedure
1870 -- calls as expressions with types internally, but the user
1871 -- doesn't think of them this way!)
1873 if Typ = Standard_Void_Type then
1875 -- Special case message if function used as a procedure
1877 if Nkind (N) = N_Procedure_Call_Statement
1878 and then Is_Entity_Name (Name (N))
1879 and then Ekind (Entity (Name (N))) = E_Function
1880 then
1881 Error_Msg_NE
1882 ("cannot use function & in a procedure call",
1883 Name (N), Entity (Name (N)));
1885 -- Otherwise give general message (not clear what cases
1886 -- this covers, but no harm in providing for them!)
1888 else
1889 Error_Msg_N ("expect procedure name in procedure call", N);
1890 end if;
1892 Found := True;
1894 -- Otherwise we do have a subexpression with the wrong type
1896 -- Check for the case of an allocator which uses an access
1897 -- type instead of the designated type. This is a common
1898 -- error and we specialize the message, posting an error
1899 -- on the operand of the allocator, complaining that we
1900 -- expected the designated type of the allocator.
1902 elsif Nkind (N) = N_Allocator
1903 and then Ekind (Typ) in Access_Kind
1904 and then Ekind (Etype (N)) in Access_Kind
1905 and then Designated_Type (Etype (N)) = Typ
1906 then
1907 Wrong_Type (Expression (N), Designated_Type (Typ));
1908 Found := True;
1910 -- Check for view mismatch on Null in instances, for
1911 -- which the view-swapping mechanism has no identifier.
1913 elsif (In_Instance or else In_Inlined_Body)
1914 and then (Nkind (N) = N_Null)
1915 and then Is_Private_Type (Typ)
1916 and then Is_Access_Type (Full_View (Typ))
1917 then
1918 Resolve (N, Full_View (Typ));
1919 Set_Etype (N, Typ);
1920 return;
1922 -- Check for an aggregate. Sometimes we can get bogus
1923 -- aggregates from misuse of parentheses, and we are
1924 -- about to complain about the aggregate without even
1925 -- looking inside it.
1927 -- Instead, if we have an aggregate of type Any_Composite,
1928 -- then analyze and resolve the component fields, and then
1929 -- only issue another message if we get no errors doing
1930 -- this (otherwise assume that the errors in the aggregate
1931 -- caused the problem).
1933 elsif Nkind (N) = N_Aggregate
1934 and then Etype (N) = Any_Composite
1935 then
1936 -- Disable expansion in any case. If there is a type mismatch
1937 -- it may be fatal to try to expand the aggregate. The flag
1938 -- would otherwise be set to false when the error is posted.
1940 Expander_Active := False;
1942 declare
1943 procedure Check_Aggr (Aggr : Node_Id);
1944 -- Check one aggregate, and set Found to True if we
1945 -- have a definite error in any of its elements
1947 procedure Check_Elmt (Aelmt : Node_Id);
1948 -- Check one element of aggregate and set Found to
1949 -- True if we definitely have an error in the element.
1951 procedure Check_Aggr (Aggr : Node_Id) is
1952 Elmt : Node_Id;
1954 begin
1955 if Present (Expressions (Aggr)) then
1956 Elmt := First (Expressions (Aggr));
1957 while Present (Elmt) loop
1958 Check_Elmt (Elmt);
1959 Next (Elmt);
1960 end loop;
1961 end if;
1963 if Present (Component_Associations (Aggr)) then
1964 Elmt := First (Component_Associations (Aggr));
1965 while Present (Elmt) loop
1966 Check_Elmt (Expression (Elmt));
1967 Next (Elmt);
1968 end loop;
1969 end if;
1970 end Check_Aggr;
1972 ----------------
1973 -- Check_Elmt --
1974 ----------------
1976 procedure Check_Elmt (Aelmt : Node_Id) is
1977 begin
1978 -- If we have a nested aggregate, go inside it (to
1979 -- attempt a naked analyze-resolve of the aggregate
1980 -- can cause undesirable cascaded errors). Do not
1981 -- resolve expression if it needs a type from context,
1982 -- as for integer * fixed expression.
1984 if Nkind (Aelmt) = N_Aggregate then
1985 Check_Aggr (Aelmt);
1987 else
1988 Analyze (Aelmt);
1990 if not Is_Overloaded (Aelmt)
1991 and then Etype (Aelmt) /= Any_Fixed
1992 then
1993 Resolve (Aelmt);
1994 end if;
1996 if Etype (Aelmt) = Any_Type then
1997 Found := True;
1998 end if;
1999 end if;
2000 end Check_Elmt;
2002 begin
2003 Check_Aggr (N);
2004 end;
2005 end if;
2007 -- If an error message was issued already, Found got reset
2008 -- to True, so if it is still False, issue the standard
2009 -- Wrong_Type message.
2011 if not Found then
2012 if Is_Overloaded (N)
2013 and then Nkind (N) = N_Function_Call
2014 then
2015 declare
2016 Subp_Name : Node_Id;
2017 begin
2018 if Is_Entity_Name (Name (N)) then
2019 Subp_Name := Name (N);
2021 elsif Nkind (Name (N)) = N_Selected_Component then
2023 -- Protected operation: retrieve operation name.
2025 Subp_Name := Selector_Name (Name (N));
2026 else
2027 raise Program_Error;
2028 end if;
2030 Error_Msg_Node_2 := Typ;
2031 Error_Msg_NE ("no visible interpretation of&" &
2032 " matches expected type&", N, Subp_Name);
2033 end;
2035 if All_Errors_Mode then
2036 declare
2037 Index : Interp_Index;
2038 It : Interp;
2040 begin
2041 Error_Msg_N ("\possible interpretations:", N);
2042 Get_First_Interp (Name (N), Index, It);
2044 while Present (It.Nam) loop
2046 Error_Msg_Sloc := Sloc (It.Nam);
2047 Error_Msg_Node_2 := It.Typ;
2048 Error_Msg_NE ("\& declared#, type&",
2049 N, It.Nam);
2051 Get_Next_Interp (Index, It);
2052 end loop;
2053 end;
2054 else
2055 Error_Msg_N ("\use -gnatf for details", N);
2056 end if;
2057 else
2058 Wrong_Type (N, Typ);
2059 end if;
2060 end if;
2061 end if;
2063 Resolution_Failed;
2064 return;
2066 -- Test if we have more than one interpretation for the context
2068 elsif Ambiguous then
2069 Resolution_Failed;
2070 return;
2072 -- Here we have an acceptable interpretation for the context
2074 else
2075 -- Propagate type information and normalize tree for various
2076 -- predefined operations. If the context only imposes a class of
2077 -- types, rather than a specific type, propagate the actual type
2078 -- downward.
2080 if Typ = Any_Integer
2081 or else Typ = Any_Boolean
2082 or else Typ = Any_Modular
2083 or else Typ = Any_Real
2084 or else Typ = Any_Discrete
2085 then
2086 Ctx_Type := Expr_Type;
2088 -- Any_Fixed is legal in a real context only if a specific
2089 -- fixed point type is imposed. If Norman Cohen can be
2090 -- confused by this, it deserves a separate message.
2092 if Typ = Any_Real
2093 and then Expr_Type = Any_Fixed
2094 then
2095 Error_Msg_N ("Illegal context for mixed mode operation", N);
2096 Set_Etype (N, Universal_Real);
2097 Ctx_Type := Universal_Real;
2098 end if;
2099 end if;
2101 -- A user-defined operator is tranformed into a function call at
2102 -- this point, so that further processing knows that operators are
2103 -- really operators (i.e. are predefined operators). User-defined
2104 -- operators that are intrinsic are just renamings of the predefined
2105 -- ones, and need not be turned into calls either, but if they rename
2106 -- a different operator, we must transform the node accordingly.
2107 -- Instantiations of Unchecked_Conversion are intrinsic but are
2108 -- treated as functions, even if given an operator designator.
2110 if Nkind (N) in N_Op
2111 and then Present (Entity (N))
2112 and then Ekind (Entity (N)) /= E_Operator
2113 then
2115 if not Is_Predefined_Op (Entity (N)) then
2116 Rewrite_Operator_As_Call (N, Entity (N));
2118 elsif Present (Alias (Entity (N)))
2119 and then
2120 Nkind (Parent (Parent (Entity (N))))
2121 = N_Subprogram_Renaming_Declaration
2122 then
2123 Rewrite_Renamed_Operator (N, Alias (Entity (N)), Typ);
2125 -- If the node is rewritten, it will be fully resolved in
2126 -- Rewrite_Renamed_Operator.
2128 if Analyzed (N) then
2129 return;
2130 end if;
2131 end if;
2132 end if;
2134 case N_Subexpr'(Nkind (N)) is
2136 when N_Aggregate => Resolve_Aggregate (N, Ctx_Type);
2138 when N_Allocator => Resolve_Allocator (N, Ctx_Type);
2140 when N_And_Then | N_Or_Else
2141 => Resolve_Short_Circuit (N, Ctx_Type);
2143 when N_Attribute_Reference
2144 => Resolve_Attribute (N, Ctx_Type);
2146 when N_Character_Literal
2147 => Resolve_Character_Literal (N, Ctx_Type);
2149 when N_Conditional_Expression
2150 => Resolve_Conditional_Expression (N, Ctx_Type);
2152 when N_Expanded_Name
2153 => Resolve_Entity_Name (N, Ctx_Type);
2155 when N_Extension_Aggregate
2156 => Resolve_Extension_Aggregate (N, Ctx_Type);
2158 when N_Explicit_Dereference
2159 => Resolve_Explicit_Dereference (N, Ctx_Type);
2161 when N_Function_Call
2162 => Resolve_Call (N, Ctx_Type);
2164 when N_Identifier
2165 => Resolve_Entity_Name (N, Ctx_Type);
2167 when N_In | N_Not_In
2168 => Resolve_Membership_Op (N, Ctx_Type);
2170 when N_Indexed_Component
2171 => Resolve_Indexed_Component (N, Ctx_Type);
2173 when N_Integer_Literal
2174 => Resolve_Integer_Literal (N, Ctx_Type);
2176 when N_Null => Resolve_Null (N, Ctx_Type);
2178 when N_Op_And | N_Op_Or | N_Op_Xor
2179 => Resolve_Logical_Op (N, Ctx_Type);
2181 when N_Op_Eq | N_Op_Ne
2182 => Resolve_Equality_Op (N, Ctx_Type);
2184 when N_Op_Lt | N_Op_Le | N_Op_Gt | N_Op_Ge
2185 => Resolve_Comparison_Op (N, Ctx_Type);
2187 when N_Op_Not => Resolve_Op_Not (N, Ctx_Type);
2189 when N_Op_Add | N_Op_Subtract | N_Op_Multiply |
2190 N_Op_Divide | N_Op_Mod | N_Op_Rem
2192 => Resolve_Arithmetic_Op (N, Ctx_Type);
2194 when N_Op_Concat => Resolve_Op_Concat (N, Ctx_Type);
2196 when N_Op_Expon => Resolve_Op_Expon (N, Ctx_Type);
2198 when N_Op_Plus | N_Op_Minus | N_Op_Abs
2199 => Resolve_Unary_Op (N, Ctx_Type);
2201 when N_Op_Shift => Resolve_Shift (N, Ctx_Type);
2203 when N_Procedure_Call_Statement
2204 => Resolve_Call (N, Ctx_Type);
2206 when N_Operator_Symbol
2207 => Resolve_Operator_Symbol (N, Ctx_Type);
2209 when N_Qualified_Expression
2210 => Resolve_Qualified_Expression (N, Ctx_Type);
2212 when N_Raise_xxx_Error
2213 => Set_Etype (N, Ctx_Type);
2215 when N_Range => Resolve_Range (N, Ctx_Type);
2217 when N_Real_Literal
2218 => Resolve_Real_Literal (N, Ctx_Type);
2220 when N_Reference => Resolve_Reference (N, Ctx_Type);
2222 when N_Selected_Component
2223 => Resolve_Selected_Component (N, Ctx_Type);
2225 when N_Slice => Resolve_Slice (N, Ctx_Type);
2227 when N_String_Literal
2228 => Resolve_String_Literal (N, Ctx_Type);
2230 when N_Subprogram_Info
2231 => Resolve_Subprogram_Info (N, Ctx_Type);
2233 when N_Type_Conversion
2234 => Resolve_Type_Conversion (N, Ctx_Type);
2236 when N_Unchecked_Expression =>
2237 Resolve_Unchecked_Expression (N, Ctx_Type);
2239 when N_Unchecked_Type_Conversion =>
2240 Resolve_Unchecked_Type_Conversion (N, Ctx_Type);
2242 end case;
2244 -- If the subexpression was replaced by a non-subexpression, then
2245 -- all we do is to expand it. The only legitimate case we know of
2246 -- is converting procedure call statement to entry call statements,
2247 -- but there may be others, so we are making this test general.
2249 if Nkind (N) not in N_Subexpr then
2250 Debug_A_Exit ("resolving ", N, " (done)");
2251 Expand (N);
2252 return;
2253 end if;
2255 -- The expression is definitely NOT overloaded at this point, so
2256 -- we reset the Is_Overloaded flag to avoid any confusion when
2257 -- reanalyzing the node.
2259 Set_Is_Overloaded (N, False);
2261 -- Freeze expression type, entity if it is a name, and designated
2262 -- type if it is an allocator (RM 13.14(10,11,13)).
2264 -- Now that the resolution of the type of the node is complete,
2265 -- and we did not detect an error, we can expand this node. We
2266 -- skip the expand call if we are in a default expression, see
2267 -- section "Handling of Default Expressions" in Sem spec.
2269 Debug_A_Exit ("resolving ", N, " (done)");
2271 -- We unconditionally freeze the expression, even if we are in
2272 -- default expression mode (the Freeze_Expression routine tests
2273 -- this flag and only freezes static types if it is set).
2275 Freeze_Expression (N);
2277 -- Now we can do the expansion
2279 Expand (N);
2280 end if;
2281 end Resolve;
2283 -------------
2284 -- Resolve --
2285 -------------
2287 -- Version with check(s) suppressed
2289 procedure Resolve (N : Node_Id; Typ : Entity_Id; Suppress : Check_Id) is
2290 begin
2291 if Suppress = All_Checks then
2292 declare
2293 Svg : constant Suppress_Array := Scope_Suppress;
2295 begin
2296 Scope_Suppress := (others => True);
2297 Resolve (N, Typ);
2298 Scope_Suppress := Svg;
2299 end;
2301 else
2302 declare
2303 Svg : constant Boolean := Scope_Suppress (Suppress);
2305 begin
2306 Scope_Suppress (Suppress) := True;
2307 Resolve (N, Typ);
2308 Scope_Suppress (Suppress) := Svg;
2309 end;
2310 end if;
2311 end Resolve;
2313 -------------
2314 -- Resolve --
2315 -------------
2317 -- Version with implicit type
2319 procedure Resolve (N : Node_Id) is
2320 begin
2321 Resolve (N, Etype (N));
2322 end Resolve;
2324 ---------------------
2325 -- Resolve_Actuals --
2326 ---------------------
2328 procedure Resolve_Actuals (N : Node_Id; Nam : Entity_Id) is
2329 Loc : constant Source_Ptr := Sloc (N);
2330 A : Node_Id;
2331 F : Entity_Id;
2332 A_Typ : Entity_Id;
2333 F_Typ : Entity_Id;
2334 Prev : Node_Id := Empty;
2336 procedure Insert_Default;
2337 -- If the actual is missing in a call, insert in the actuals list
2338 -- an instance of the default expression. The insertion is always
2339 -- a named association.
2341 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean;
2342 -- Check whether T1 and T2, or their full views, are derived from a
2343 -- common type. Used to enforce the restrictions on array conversions
2344 -- of AI95-00246.
2346 --------------------
2347 -- Insert_Default --
2348 --------------------
2350 procedure Insert_Default is
2351 Actval : Node_Id;
2352 Assoc : Node_Id;
2354 begin
2355 -- Missing argument in call, nothing to insert
2357 if No (Default_Value (F)) then
2358 return;
2360 else
2361 -- Note that we do a full New_Copy_Tree, so that any associated
2362 -- Itypes are properly copied. This may not be needed any more,
2363 -- but it does no harm as a safety measure! Defaults of a generic
2364 -- formal may be out of bounds of the corresponding actual (see
2365 -- cc1311b) and an additional check may be required.
2367 Actval := New_Copy_Tree (Default_Value (F),
2368 New_Scope => Current_Scope, New_Sloc => Loc);
2370 if Is_Concurrent_Type (Scope (Nam))
2371 and then Has_Discriminants (Scope (Nam))
2372 then
2373 Replace_Actual_Discriminants (N, Actval);
2374 end if;
2376 if Is_Overloadable (Nam)
2377 and then Present (Alias (Nam))
2378 then
2379 if Base_Type (Etype (F)) /= Base_Type (Etype (Actval))
2380 and then not Is_Tagged_Type (Etype (F))
2381 then
2382 -- If default is a real literal, do not introduce a
2383 -- conversion whose effect may depend on the run-time
2384 -- size of universal real.
2386 if Nkind (Actval) = N_Real_Literal then
2387 Set_Etype (Actval, Base_Type (Etype (F)));
2388 else
2389 Actval := Unchecked_Convert_To (Etype (F), Actval);
2390 end if;
2391 end if;
2393 if Is_Scalar_Type (Etype (F)) then
2394 Enable_Range_Check (Actval);
2395 end if;
2397 Set_Parent (Actval, N);
2399 -- Resolve aggregates with their base type, to avoid scope
2400 -- anomalies: the subtype was first built in the suprogram
2401 -- declaration, and the current call may be nested.
2403 if Nkind (Actval) = N_Aggregate
2404 and then Has_Discriminants (Etype (Actval))
2405 then
2406 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2407 else
2408 Analyze_And_Resolve (Actval, Etype (Actval));
2409 end if;
2411 else
2412 Set_Parent (Actval, N);
2414 -- See note above concerning aggregates.
2416 if Nkind (Actval) = N_Aggregate
2417 and then Has_Discriminants (Etype (Actval))
2418 then
2419 Analyze_And_Resolve (Actval, Base_Type (Etype (Actval)));
2421 -- Resolve entities with their own type, which may differ
2422 -- from the type of a reference in a generic context (the
2423 -- view swapping mechanism did not anticipate the re-analysis
2424 -- of default values in calls).
2426 elsif Is_Entity_Name (Actval) then
2427 Analyze_And_Resolve (Actval, Etype (Entity (Actval)));
2429 else
2430 Analyze_And_Resolve (Actval, Etype (Actval));
2431 end if;
2432 end if;
2434 -- If default is a tag indeterminate function call, propagate
2435 -- tag to obtain proper dispatching.
2437 if Is_Controlling_Formal (F)
2438 and then Nkind (Default_Value (F)) = N_Function_Call
2439 then
2440 Set_Is_Controlling_Actual (Actval);
2441 end if;
2443 end if;
2445 -- If the default expression raises constraint error, then just
2446 -- silently replace it with an N_Raise_Constraint_Error node,
2447 -- since we already gave the warning on the subprogram spec.
2449 if Raises_Constraint_Error (Actval) then
2450 Rewrite (Actval,
2451 Make_Raise_Constraint_Error (Loc,
2452 Reason => CE_Range_Check_Failed));
2453 Set_Raises_Constraint_Error (Actval);
2454 Set_Etype (Actval, Etype (F));
2455 end if;
2457 Assoc :=
2458 Make_Parameter_Association (Loc,
2459 Explicit_Actual_Parameter => Actval,
2460 Selector_Name => Make_Identifier (Loc, Chars (F)));
2462 -- Case of insertion is first named actual
2464 if No (Prev) or else
2465 Nkind (Parent (Prev)) /= N_Parameter_Association
2466 then
2467 Set_Next_Named_Actual (Assoc, First_Named_Actual (N));
2468 Set_First_Named_Actual (N, Actval);
2470 if No (Prev) then
2471 if not Present (Parameter_Associations (N)) then
2472 Set_Parameter_Associations (N, New_List (Assoc));
2473 else
2474 Append (Assoc, Parameter_Associations (N));
2475 end if;
2477 else
2478 Insert_After (Prev, Assoc);
2479 end if;
2481 -- Case of insertion is not first named actual
2483 else
2484 Set_Next_Named_Actual
2485 (Assoc, Next_Named_Actual (Parent (Prev)));
2486 Set_Next_Named_Actual (Parent (Prev), Actval);
2487 Append (Assoc, Parameter_Associations (N));
2488 end if;
2490 Mark_Rewrite_Insertion (Assoc);
2491 Mark_Rewrite_Insertion (Actval);
2493 Prev := Actval;
2494 end Insert_Default;
2496 -------------------
2497 -- Same_Ancestor --
2498 -------------------
2500 function Same_Ancestor (T1, T2 : Entity_Id) return Boolean is
2501 FT1 : Entity_Id := T1;
2502 FT2 : Entity_Id := T2;
2504 begin
2505 if Is_Private_Type (T1)
2506 and then Present (Full_View (T1))
2507 then
2508 FT1 := Full_View (T1);
2509 end if;
2511 if Is_Private_Type (T2)
2512 and then Present (Full_View (T2))
2513 then
2514 FT2 := Full_View (T2);
2515 end if;
2517 return Root_Type (Base_Type (FT1)) = Root_Type (Base_Type (FT2));
2518 end Same_Ancestor;
2520 -- Start of processing for Resolve_Actuals
2522 begin
2523 A := First_Actual (N);
2524 F := First_Formal (Nam);
2526 while Present (F) loop
2527 if No (A) and then Needs_No_Actuals (Nam) then
2528 null;
2530 -- If we have an error in any actual or formal, indicated by
2531 -- a type of Any_Type, then abandon resolution attempt, and
2532 -- set result type to Any_Type.
2534 elsif (Present (A) and then Etype (A) = Any_Type)
2535 or else Etype (F) = Any_Type
2536 then
2537 Set_Etype (N, Any_Type);
2538 return;
2539 end if;
2541 if Present (A)
2542 and then (Nkind (Parent (A)) /= N_Parameter_Association
2543 or else
2544 Chars (Selector_Name (Parent (A))) = Chars (F))
2545 then
2546 -- If the formal is Out or In_Out, do not resolve and expand the
2547 -- conversion, because it is subsequently expanded into explicit
2548 -- temporaries and assignments. However, the object of the
2549 -- conversion can be resolved. An exception is the case of
2550 -- a tagged type conversion with a class-wide actual. In that
2551 -- case we want the tag check to occur and no temporary will
2552 -- will be needed (no representation change can occur) and
2553 -- the parameter is passed by reference, so we go ahead and
2554 -- resolve the type conversion.
2556 if Ekind (F) /= E_In_Parameter
2557 and then Nkind (A) = N_Type_Conversion
2558 and then not Is_Class_Wide_Type (Etype (Expression (A)))
2559 then
2560 if Ekind (F) = E_In_Out_Parameter
2561 and then Is_Array_Type (Etype (F))
2562 then
2563 if Has_Aliased_Components (Etype (Expression (A)))
2564 /= Has_Aliased_Components (Etype (F))
2565 then
2566 Error_Msg_N
2567 ("both component types in a view conversion must be"
2568 & " aliased, or neither", A);
2570 elsif not Same_Ancestor (Etype (F), Etype (Expression (A)))
2571 and then
2572 (Is_By_Reference_Type (Etype (F))
2573 or else Is_By_Reference_Type (Etype (Expression (A))))
2574 then
2575 Error_Msg_N
2576 ("view conversion between unrelated by_reference "
2577 & "array types not allowed (\A\I-00246)?", A);
2578 end if;
2579 end if;
2581 if Conversion_OK (A)
2582 or else Valid_Conversion (A, Etype (A), Expression (A))
2583 then
2584 Resolve (Expression (A));
2585 end if;
2587 else
2588 if Nkind (A) = N_Type_Conversion
2589 and then Is_Array_Type (Etype (F))
2590 and then not Same_Ancestor (Etype (F), Etype (Expression (A)))
2591 and then
2592 (Is_Limited_Type (Etype (F))
2593 or else Is_Limited_Type (Etype (Expression (A))))
2594 then
2595 Error_Msg_N
2596 ("Conversion between unrelated limited array types "
2597 & "not allowed (\A\I-00246)?", A);
2599 -- Disable explanation (which produces additional errors)
2600 -- until AI is approved and warning becomes an error.
2602 -- if Is_Limited_Type (Etype (F)) then
2603 -- Explain_Limited_Type (Etype (F), A);
2604 -- end if;
2606 -- if Is_Limited_Type (Etype (Expression (A))) then
2607 -- Explain_Limited_Type (Etype (Expression (A)), A);
2608 -- end if;
2609 end if;
2611 Resolve (A, Etype (F));
2612 end if;
2614 A_Typ := Etype (A);
2615 F_Typ := Etype (F);
2617 -- Perform error checks for IN and IN OUT parameters
2619 if Ekind (F) /= E_Out_Parameter then
2621 -- Check unset reference. For scalar parameters, it is clearly
2622 -- wrong to pass an uninitialized value as either an IN or
2623 -- IN-OUT parameter. For composites, it is also clearly an
2624 -- error to pass a completely uninitialized value as an IN
2625 -- parameter, but the case of IN OUT is trickier. We prefer
2626 -- not to give a warning here. For example, suppose there is
2627 -- a routine that sets some component of a record to False.
2628 -- It is perfectly reasonable to make this IN-OUT and allow
2629 -- either initialized or uninitialized records to be passed
2630 -- in this case.
2632 -- For partially initialized composite values, we also avoid
2633 -- warnings, since it is quite likely that we are passing a
2634 -- partially initialized value and only the initialized fields
2635 -- will in fact be read in the subprogram.
2637 if Is_Scalar_Type (A_Typ)
2638 or else (Ekind (F) = E_In_Parameter
2639 and then not Is_Partially_Initialized_Type (A_Typ))
2640 then
2641 Check_Unset_Reference (A);
2642 end if;
2644 -- In Ada 83 we cannot pass an OUT parameter as an IN
2645 -- or IN OUT actual to a nested call, since this is a
2646 -- case of reading an out parameter, which is not allowed.
2648 if Ada_Version = Ada_83
2649 and then Is_Entity_Name (A)
2650 and then Ekind (Entity (A)) = E_Out_Parameter
2651 then
2652 Error_Msg_N ("(Ada 83) illegal reading of out parameter", A);
2653 end if;
2654 end if;
2656 if Ekind (F) /= E_In_Parameter
2657 and then not Is_OK_Variable_For_Out_Formal (A)
2658 then
2659 Error_Msg_NE ("actual for& must be a variable", A, F);
2661 if Is_Entity_Name (A) then
2662 Kill_Checks (Entity (A));
2663 else
2664 Kill_All_Checks;
2665 end if;
2666 end if;
2668 if Etype (A) = Any_Type then
2669 Set_Etype (N, Any_Type);
2670 return;
2671 end if;
2673 -- Apply appropriate range checks for in, out, and in-out
2674 -- parameters. Out and in-out parameters also need a separate
2675 -- check, if there is a type conversion, to make sure the return
2676 -- value meets the constraints of the variable before the
2677 -- conversion.
2679 -- Gigi looks at the check flag and uses the appropriate types.
2680 -- For now since one flag is used there is an optimization which
2681 -- might not be done in the In Out case since Gigi does not do
2682 -- any analysis. More thought required about this ???
2684 if Ekind (F) = E_In_Parameter
2685 or else Ekind (F) = E_In_Out_Parameter
2686 then
2687 if Is_Scalar_Type (Etype (A)) then
2688 Apply_Scalar_Range_Check (A, F_Typ);
2690 elsif Is_Array_Type (Etype (A)) then
2691 Apply_Length_Check (A, F_Typ);
2693 elsif Is_Record_Type (F_Typ)
2694 and then Has_Discriminants (F_Typ)
2695 and then Is_Constrained (F_Typ)
2696 and then (not Is_Derived_Type (F_Typ)
2697 or else Comes_From_Source (Nam))
2698 then
2699 Apply_Discriminant_Check (A, F_Typ);
2701 elsif Is_Access_Type (F_Typ)
2702 and then Is_Array_Type (Designated_Type (F_Typ))
2703 and then Is_Constrained (Designated_Type (F_Typ))
2704 then
2705 Apply_Length_Check (A, F_Typ);
2707 elsif Is_Access_Type (F_Typ)
2708 and then Has_Discriminants (Designated_Type (F_Typ))
2709 and then Is_Constrained (Designated_Type (F_Typ))
2710 then
2711 Apply_Discriminant_Check (A, F_Typ);
2713 else
2714 Apply_Range_Check (A, F_Typ);
2715 end if;
2717 -- Ada 2005 (AI-231)
2719 if Ada_Version >= Ada_05
2720 and then Is_Access_Type (F_Typ)
2721 and then (Can_Never_Be_Null (F)
2722 or else Can_Never_Be_Null (F_Typ))
2723 then
2724 if Nkind (A) = N_Null then
2725 Apply_Compile_Time_Constraint_Error
2726 (N => A,
2727 Msg => "(Ada 2005) NULL not allowed in "
2728 & "null-excluding formal?",
2729 Reason => CE_Null_Not_Allowed);
2730 end if;
2731 end if;
2732 end if;
2734 if Ekind (F) = E_Out_Parameter
2735 or else Ekind (F) = E_In_Out_Parameter
2736 then
2737 if Nkind (A) = N_Type_Conversion then
2738 if Is_Scalar_Type (A_Typ) then
2739 Apply_Scalar_Range_Check
2740 (Expression (A), Etype (Expression (A)), A_Typ);
2741 else
2742 Apply_Range_Check
2743 (Expression (A), Etype (Expression (A)), A_Typ);
2744 end if;
2746 else
2747 if Is_Scalar_Type (F_Typ) then
2748 Apply_Scalar_Range_Check (A, A_Typ, F_Typ);
2750 elsif Is_Array_Type (F_Typ)
2751 and then Ekind (F) = E_Out_Parameter
2752 then
2753 Apply_Length_Check (A, F_Typ);
2755 else
2756 Apply_Range_Check (A, A_Typ, F_Typ);
2757 end if;
2758 end if;
2759 end if;
2761 -- An actual associated with an access parameter is implicitly
2762 -- converted to the anonymous access type of the formal and
2763 -- must satisfy the legality checks for access conversions.
2765 if Ekind (F_Typ) = E_Anonymous_Access_Type then
2766 if not Valid_Conversion (A, F_Typ, A) then
2767 Error_Msg_N
2768 ("invalid implicit conversion for access parameter", A);
2769 end if;
2770 end if;
2772 -- Check bad case of atomic/volatile argument (RM C.6(12))
2774 if Is_By_Reference_Type (Etype (F))
2775 and then Comes_From_Source (N)
2776 then
2777 if Is_Atomic_Object (A)
2778 and then not Is_Atomic (Etype (F))
2779 then
2780 Error_Msg_N
2781 ("cannot pass atomic argument to non-atomic formal",
2784 elsif Is_Volatile_Object (A)
2785 and then not Is_Volatile (Etype (F))
2786 then
2787 Error_Msg_N
2788 ("cannot pass volatile argument to non-volatile formal",
2790 end if;
2791 end if;
2793 -- Check that subprograms don't have improper controlling
2794 -- arguments (RM 3.9.2 (9))
2796 if Is_Controlling_Formal (F) then
2797 Set_Is_Controlling_Actual (A);
2798 elsif Nkind (A) = N_Explicit_Dereference then
2799 Validate_Remote_Access_To_Class_Wide_Type (A);
2800 end if;
2802 if (Is_Class_Wide_Type (A_Typ) or else Is_Dynamically_Tagged (A))
2803 and then not Is_Class_Wide_Type (F_Typ)
2804 and then not Is_Controlling_Formal (F)
2805 then
2806 Error_Msg_N ("class-wide argument not allowed here!", A);
2808 if Is_Subprogram (Nam)
2809 and then Comes_From_Source (Nam)
2810 then
2811 Error_Msg_Node_2 := F_Typ;
2812 Error_Msg_NE
2813 ("& is not a dispatching operation of &!", A, Nam);
2814 end if;
2816 elsif Is_Access_Type (A_Typ)
2817 and then Is_Access_Type (F_Typ)
2818 and then Ekind (F_Typ) /= E_Access_Subprogram_Type
2819 and then (Is_Class_Wide_Type (Designated_Type (A_Typ))
2820 or else (Nkind (A) = N_Attribute_Reference
2821 and then
2822 Is_Class_Wide_Type (Etype (Prefix (A)))))
2823 and then not Is_Class_Wide_Type (Designated_Type (F_Typ))
2824 and then not Is_Controlling_Formal (F)
2825 then
2826 Error_Msg_N
2827 ("access to class-wide argument not allowed here!", A);
2829 if Is_Subprogram (Nam)
2830 and then Comes_From_Source (Nam)
2831 then
2832 Error_Msg_Node_2 := Designated_Type (F_Typ);
2833 Error_Msg_NE
2834 ("& is not a dispatching operation of &!", A, Nam);
2835 end if;
2836 end if;
2838 Eval_Actual (A);
2840 -- If it is a named association, treat the selector_name as
2841 -- a proper identifier, and mark the corresponding entity.
2843 if Nkind (Parent (A)) = N_Parameter_Association then
2844 Set_Entity (Selector_Name (Parent (A)), F);
2845 Generate_Reference (F, Selector_Name (Parent (A)));
2846 Set_Etype (Selector_Name (Parent (A)), F_Typ);
2847 Generate_Reference (F_Typ, N, ' ');
2848 end if;
2850 Prev := A;
2852 if Ekind (F) /= E_Out_Parameter then
2853 Check_Unset_Reference (A);
2854 end if;
2856 Next_Actual (A);
2858 -- Case where actual is not present
2860 else
2861 Insert_Default;
2862 end if;
2864 Next_Formal (F);
2865 end loop;
2866 end Resolve_Actuals;
2868 -----------------------
2869 -- Resolve_Allocator --
2870 -----------------------
2872 procedure Resolve_Allocator (N : Node_Id; Typ : Entity_Id) is
2873 E : constant Node_Id := Expression (N);
2874 Subtyp : Entity_Id;
2875 Discrim : Entity_Id;
2876 Constr : Node_Id;
2877 Disc_Exp : Node_Id;
2879 function In_Dispatching_Context return Boolean;
2880 -- If the allocator is an actual in a call, it is allowed to be
2881 -- class-wide when the context is not because it is a controlling
2882 -- actual.
2884 ----------------------------
2885 -- In_Dispatching_Context --
2886 ----------------------------
2888 function In_Dispatching_Context return Boolean is
2889 Par : constant Node_Id := Parent (N);
2891 begin
2892 return (Nkind (Par) = N_Function_Call
2893 or else Nkind (Par) = N_Procedure_Call_Statement)
2894 and then Is_Entity_Name (Name (Par))
2895 and then Is_Dispatching_Operation (Entity (Name (Par)));
2896 end In_Dispatching_Context;
2898 -- Start of processing for Resolve_Allocator
2900 begin
2901 -- Replace general access with specific type
2903 if Ekind (Etype (N)) = E_Allocator_Type then
2904 Set_Etype (N, Base_Type (Typ));
2905 end if;
2907 if Is_Abstract (Typ) then
2908 Error_Msg_N ("type of allocator cannot be abstract", N);
2909 end if;
2911 -- For qualified expression, resolve the expression using the
2912 -- given subtype (nothing to do for type mark, subtype indication)
2914 if Nkind (E) = N_Qualified_Expression then
2915 if Is_Class_Wide_Type (Etype (E))
2916 and then not Is_Class_Wide_Type (Designated_Type (Typ))
2917 and then not In_Dispatching_Context
2918 then
2919 Error_Msg_N
2920 ("class-wide allocator not allowed for this access type", N);
2921 end if;
2923 Resolve (Expression (E), Etype (E));
2924 Check_Unset_Reference (Expression (E));
2926 -- A qualified expression requires an exact match of the type,
2927 -- class-wide matching is not allowed.
2929 if (Is_Class_Wide_Type (Etype (Expression (E)))
2930 or else Is_Class_Wide_Type (Etype (E)))
2931 and then Base_Type (Etype (Expression (E))) /= Base_Type (Etype (E))
2932 then
2933 Wrong_Type (Expression (E), Etype (E));
2934 end if;
2936 -- For a subtype mark or subtype indication, freeze the subtype
2938 else
2939 Freeze_Expression (E);
2941 if Is_Access_Constant (Typ) and then not No_Initialization (N) then
2942 Error_Msg_N
2943 ("initialization required for access-to-constant allocator", N);
2944 end if;
2946 -- A special accessibility check is needed for allocators that
2947 -- constrain access discriminants. The level of the type of the
2948 -- expression used to contrain an access discriminant cannot be
2949 -- deeper than the type of the allocator (in constrast to access
2950 -- parameters, where the level of the actual can be arbitrary).
2951 -- We can't use Valid_Conversion to perform this check because
2952 -- in general the type of the allocator is unrelated to the type
2953 -- of the access discriminant. Note that specialized checks are
2954 -- needed for the cases of a constraint expression which is an
2955 -- access attribute or an access discriminant.
2957 if Nkind (Original_Node (E)) = N_Subtype_Indication
2958 and then Ekind (Typ) /= E_Anonymous_Access_Type
2959 then
2960 Subtyp := Entity (Subtype_Mark (Original_Node (E)));
2962 if Has_Discriminants (Subtyp) then
2963 Discrim := First_Discriminant (Base_Type (Subtyp));
2964 Constr := First (Constraints (Constraint (Original_Node (E))));
2966 while Present (Discrim) and then Present (Constr) loop
2967 if Ekind (Etype (Discrim)) = E_Anonymous_Access_Type then
2968 if Nkind (Constr) = N_Discriminant_Association then
2969 Disc_Exp := Original_Node (Expression (Constr));
2970 else
2971 Disc_Exp := Original_Node (Constr);
2972 end if;
2974 if Type_Access_Level (Etype (Disc_Exp))
2975 > Type_Access_Level (Typ)
2976 then
2977 Error_Msg_N
2978 ("operand type has deeper level than allocator type",
2979 Disc_Exp);
2981 elsif Nkind (Disc_Exp) = N_Attribute_Reference
2982 and then Get_Attribute_Id (Attribute_Name (Disc_Exp))
2983 = Attribute_Access
2984 and then Object_Access_Level (Prefix (Disc_Exp))
2985 > Type_Access_Level (Typ)
2986 then
2987 Error_Msg_N
2988 ("prefix of attribute has deeper level than"
2989 & " allocator type", Disc_Exp);
2991 -- When the operand is an access discriminant the check
2992 -- is against the level of the prefix object.
2994 elsif Ekind (Etype (Disc_Exp)) = E_Anonymous_Access_Type
2995 and then Nkind (Disc_Exp) = N_Selected_Component
2996 and then Object_Access_Level (Prefix (Disc_Exp))
2997 > Type_Access_Level (Typ)
2998 then
2999 Error_Msg_N
3000 ("access discriminant has deeper level than"
3001 & " allocator type", Disc_Exp);
3002 end if;
3003 end if;
3004 Next_Discriminant (Discrim);
3005 Next (Constr);
3006 end loop;
3007 end if;
3008 end if;
3009 end if;
3011 -- Check for allocation from an empty storage pool
3013 if No_Pool_Assigned (Typ) then
3014 declare
3015 Loc : constant Source_Ptr := Sloc (N);
3017 begin
3018 Error_Msg_N ("?allocation from empty storage pool!", N);
3019 Error_Msg_N ("?Storage_Error will be raised at run time!", N);
3020 Insert_Action (N,
3021 Make_Raise_Storage_Error (Loc,
3022 Reason => SE_Empty_Storage_Pool));
3023 end;
3024 end if;
3025 end Resolve_Allocator;
3027 ---------------------------
3028 -- Resolve_Arithmetic_Op --
3029 ---------------------------
3031 -- Used for resolving all arithmetic operators except exponentiation
3033 procedure Resolve_Arithmetic_Op (N : Node_Id; Typ : Entity_Id) is
3034 L : constant Node_Id := Left_Opnd (N);
3035 R : constant Node_Id := Right_Opnd (N);
3036 TL : constant Entity_Id := Base_Type (Etype (L));
3037 TR : constant Entity_Id := Base_Type (Etype (R));
3038 T : Entity_Id;
3039 Rop : Node_Id;
3041 B_Typ : constant Entity_Id := Base_Type (Typ);
3042 -- We do the resolution using the base type, because intermediate values
3043 -- in expressions always are of the base type, not a subtype of it.
3045 function Is_Integer_Or_Universal (N : Node_Id) return Boolean;
3046 -- Return True iff given type is Integer or universal real/integer
3048 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id);
3049 -- Choose type of integer literal in fixed-point operation to conform
3050 -- to available fixed-point type. T is the type of the other operand,
3051 -- which is needed to determine the expected type of N.
3053 procedure Set_Operand_Type (N : Node_Id);
3054 -- Set operand type to T if universal
3056 -----------------------------
3057 -- Is_Integer_Or_Universal --
3058 -----------------------------
3060 function Is_Integer_Or_Universal (N : Node_Id) return Boolean is
3061 T : Entity_Id;
3062 Index : Interp_Index;
3063 It : Interp;
3065 begin
3066 if not Is_Overloaded (N) then
3067 T := Etype (N);
3068 return Base_Type (T) = Base_Type (Standard_Integer)
3069 or else T = Universal_Integer
3070 or else T = Universal_Real;
3071 else
3072 Get_First_Interp (N, Index, It);
3074 while Present (It.Typ) loop
3076 if Base_Type (It.Typ) = Base_Type (Standard_Integer)
3077 or else It.Typ = Universal_Integer
3078 or else It.Typ = Universal_Real
3079 then
3080 return True;
3081 end if;
3083 Get_Next_Interp (Index, It);
3084 end loop;
3085 end if;
3087 return False;
3088 end Is_Integer_Or_Universal;
3090 ----------------------------
3091 -- Set_Mixed_Mode_Operand --
3092 ----------------------------
3094 procedure Set_Mixed_Mode_Operand (N : Node_Id; T : Entity_Id) is
3095 Index : Interp_Index;
3096 It : Interp;
3098 begin
3099 if Universal_Interpretation (N) = Universal_Integer then
3101 -- A universal integer literal is resolved as standard integer
3102 -- except in the case of a fixed-point result, where we leave
3103 -- it as universal (to be handled by Exp_Fixd later on)
3105 if Is_Fixed_Point_Type (T) then
3106 Resolve (N, Universal_Integer);
3107 else
3108 Resolve (N, Standard_Integer);
3109 end if;
3111 elsif Universal_Interpretation (N) = Universal_Real
3112 and then (T = Base_Type (Standard_Integer)
3113 or else T = Universal_Integer
3114 or else T = Universal_Real)
3115 then
3116 -- A universal real can appear in a fixed-type context. We resolve
3117 -- the literal with that context, even though this might raise an
3118 -- exception prematurely (the other operand may be zero).
3120 Resolve (N, B_Typ);
3122 elsif Etype (N) = Base_Type (Standard_Integer)
3123 and then T = Universal_Real
3124 and then Is_Overloaded (N)
3125 then
3126 -- Integer arg in mixed-mode operation. Resolve with universal
3127 -- type, in case preference rule must be applied.
3129 Resolve (N, Universal_Integer);
3131 elsif Etype (N) = T
3132 and then B_Typ /= Universal_Fixed
3133 then
3134 -- Not a mixed-mode operation. Resolve with context.
3136 Resolve (N, B_Typ);
3138 elsif Etype (N) = Any_Fixed then
3140 -- N may itself be a mixed-mode operation, so use context type.
3142 Resolve (N, B_Typ);
3144 elsif Is_Fixed_Point_Type (T)
3145 and then B_Typ = Universal_Fixed
3146 and then Is_Overloaded (N)
3147 then
3148 -- Must be (fixed * fixed) operation, operand must have one
3149 -- compatible interpretation.
3151 Resolve (N, Any_Fixed);
3153 elsif Is_Fixed_Point_Type (B_Typ)
3154 and then (T = Universal_Real
3155 or else Is_Fixed_Point_Type (T))
3156 and then Is_Overloaded (N)
3157 then
3158 -- C * F(X) in a fixed context, where C is a real literal or a
3159 -- fixed-point expression. F must have either a fixed type
3160 -- interpretation or an integer interpretation, but not both.
3162 Get_First_Interp (N, Index, It);
3164 while Present (It.Typ) loop
3165 if Base_Type (It.Typ) = Base_Type (Standard_Integer) then
3167 if Analyzed (N) then
3168 Error_Msg_N ("ambiguous operand in fixed operation", N);
3169 else
3170 Resolve (N, Standard_Integer);
3171 end if;
3173 elsif Is_Fixed_Point_Type (It.Typ) then
3175 if Analyzed (N) then
3176 Error_Msg_N ("ambiguous operand in fixed operation", N);
3177 else
3178 Resolve (N, It.Typ);
3179 end if;
3180 end if;
3182 Get_Next_Interp (Index, It);
3183 end loop;
3185 -- Reanalyze the literal with the fixed type of the context.
3186 -- If context is Universal_Fixed, we are within a conversion,
3187 -- leave the literal as a universal real because there is no
3188 -- usable fixed type, and the target of the conversion plays
3189 -- no role in the resolution.
3191 declare
3192 Op2 : Node_Id;
3193 T2 : Entity_Id;
3195 begin
3196 if N = L then
3197 Op2 := R;
3198 else
3199 Op2 := L;
3200 end if;
3202 if B_Typ = Universal_Fixed
3203 and then Nkind (Op2) = N_Real_Literal
3204 then
3205 T2 := Universal_Real;
3206 else
3207 T2 := B_Typ;
3208 end if;
3210 Set_Analyzed (Op2, False);
3211 Resolve (Op2, T2);
3212 end;
3214 else
3215 Resolve (N);
3216 end if;
3217 end Set_Mixed_Mode_Operand;
3219 ----------------------
3220 -- Set_Operand_Type --
3221 ----------------------
3223 procedure Set_Operand_Type (N : Node_Id) is
3224 begin
3225 if Etype (N) = Universal_Integer
3226 or else Etype (N) = Universal_Real
3227 then
3228 Set_Etype (N, T);
3229 end if;
3230 end Set_Operand_Type;
3232 -- Start of processing for Resolve_Arithmetic_Op
3234 begin
3235 if Comes_From_Source (N)
3236 and then Ekind (Entity (N)) = E_Function
3237 and then Is_Imported (Entity (N))
3238 and then Is_Intrinsic_Subprogram (Entity (N))
3239 then
3240 Resolve_Intrinsic_Operator (N, Typ);
3241 return;
3243 -- Special-case for mixed-mode universal expressions or fixed point
3244 -- type operation: each argument is resolved separately. The same
3245 -- treatment is required if one of the operands of a fixed point
3246 -- operation is universal real, since in this case we don't do a
3247 -- conversion to a specific fixed-point type (instead the expander
3248 -- takes care of the case).
3250 elsif (B_Typ = Universal_Integer
3251 or else B_Typ = Universal_Real)
3252 and then Present (Universal_Interpretation (L))
3253 and then Present (Universal_Interpretation (R))
3254 then
3255 Resolve (L, Universal_Interpretation (L));
3256 Resolve (R, Universal_Interpretation (R));
3257 Set_Etype (N, B_Typ);
3259 elsif (B_Typ = Universal_Real
3260 or else Etype (N) = Universal_Fixed
3261 or else (Etype (N) = Any_Fixed
3262 and then Is_Fixed_Point_Type (B_Typ))
3263 or else (Is_Fixed_Point_Type (B_Typ)
3264 and then (Is_Integer_Or_Universal (L)
3265 or else
3266 Is_Integer_Or_Universal (R))))
3267 and then (Nkind (N) = N_Op_Multiply or else
3268 Nkind (N) = N_Op_Divide)
3269 then
3270 if TL = Universal_Integer or else TR = Universal_Integer then
3271 Check_For_Visible_Operator (N, B_Typ);
3272 end if;
3274 -- If context is a fixed type and one operand is integer, the
3275 -- other is resolved with the type of the context.
3277 if Is_Fixed_Point_Type (B_Typ)
3278 and then (Base_Type (TL) = Base_Type (Standard_Integer)
3279 or else TL = Universal_Integer)
3280 then
3281 Resolve (R, B_Typ);
3282 Resolve (L, TL);
3284 elsif Is_Fixed_Point_Type (B_Typ)
3285 and then (Base_Type (TR) = Base_Type (Standard_Integer)
3286 or else TR = Universal_Integer)
3287 then
3288 Resolve (L, B_Typ);
3289 Resolve (R, TR);
3291 else
3292 Set_Mixed_Mode_Operand (L, TR);
3293 Set_Mixed_Mode_Operand (R, TL);
3294 end if;
3296 if Etype (N) = Universal_Fixed
3297 or else Etype (N) = Any_Fixed
3298 then
3299 if B_Typ = Universal_Fixed
3300 and then Nkind (Parent (N)) /= N_Type_Conversion
3301 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3302 then
3303 Error_Msg_N
3304 ("type cannot be determined from context!", N);
3305 Error_Msg_N
3306 ("\explicit conversion to result type required", N);
3308 Set_Etype (L, Any_Type);
3309 Set_Etype (R, Any_Type);
3311 else
3312 if Ada_Version = Ada_83
3313 and then Etype (N) = Universal_Fixed
3314 and then Nkind (Parent (N)) /= N_Type_Conversion
3315 and then Nkind (Parent (N)) /= N_Unchecked_Type_Conversion
3316 then
3317 Error_Msg_N
3318 ("(Ada 83) fixed-point operation " &
3319 "needs explicit conversion",
3321 end if;
3323 Set_Etype (N, B_Typ);
3324 end if;
3326 elsif Is_Fixed_Point_Type (B_Typ)
3327 and then (Is_Integer_Or_Universal (L)
3328 or else Nkind (L) = N_Real_Literal
3329 or else Nkind (R) = N_Real_Literal
3330 or else
3331 Is_Integer_Or_Universal (R))
3332 then
3333 Set_Etype (N, B_Typ);
3335 elsif Etype (N) = Any_Fixed then
3337 -- If no previous errors, this is only possible if one operand
3338 -- is overloaded and the context is universal. Resolve as such.
3340 Set_Etype (N, B_Typ);
3341 end if;
3343 else
3344 if (TL = Universal_Integer or else TL = Universal_Real)
3345 and then (TR = Universal_Integer or else TR = Universal_Real)
3346 then
3347 Check_For_Visible_Operator (N, B_Typ);
3348 end if;
3350 -- If the context is Universal_Fixed and the operands are also
3351 -- universal fixed, this is an error, unless there is only one
3352 -- applicable fixed_point type (usually duration).
3354 if B_Typ = Universal_Fixed
3355 and then Etype (L) = Universal_Fixed
3356 then
3357 T := Unique_Fixed_Point_Type (N);
3359 if T = Any_Type then
3360 Set_Etype (N, T);
3361 return;
3362 else
3363 Resolve (L, T);
3364 Resolve (R, T);
3365 end if;
3367 else
3368 Resolve (L, B_Typ);
3369 Resolve (R, B_Typ);
3370 end if;
3372 -- If one of the arguments was resolved to a non-universal type.
3373 -- label the result of the operation itself with the same type.
3374 -- Do the same for the universal argument, if any.
3376 T := Intersect_Types (L, R);
3377 Set_Etype (N, Base_Type (T));
3378 Set_Operand_Type (L);
3379 Set_Operand_Type (R);
3380 end if;
3382 Generate_Operator_Reference (N, Typ);
3383 Eval_Arithmetic_Op (N);
3385 -- Set overflow and division checking bit. Much cleverer code needed
3386 -- here eventually and perhaps the Resolve routines should be separated
3387 -- for the various arithmetic operations, since they will need
3388 -- different processing. ???
3390 if Nkind (N) in N_Op then
3391 if not Overflow_Checks_Suppressed (Etype (N)) then
3392 Enable_Overflow_Check (N);
3393 end if;
3395 -- Give warning if explicit division by zero
3397 if (Nkind (N) = N_Op_Divide
3398 or else Nkind (N) = N_Op_Rem
3399 or else Nkind (N) = N_Op_Mod)
3400 and then not Division_Checks_Suppressed (Etype (N))
3401 then
3402 Rop := Right_Opnd (N);
3404 if Compile_Time_Known_Value (Rop)
3405 and then ((Is_Integer_Type (Etype (Rop))
3406 and then Expr_Value (Rop) = Uint_0)
3407 or else
3408 (Is_Real_Type (Etype (Rop))
3409 and then Expr_Value_R (Rop) = Ureal_0))
3410 then
3411 Apply_Compile_Time_Constraint_Error
3412 (N, "division by zero?", CE_Divide_By_Zero,
3413 Loc => Sloc (Right_Opnd (N)));
3415 -- Otherwise just set the flag to check at run time
3417 else
3418 Set_Do_Division_Check (N);
3419 end if;
3420 end if;
3421 end if;
3423 Check_Unset_Reference (L);
3424 Check_Unset_Reference (R);
3425 end Resolve_Arithmetic_Op;
3427 ------------------
3428 -- Resolve_Call --
3429 ------------------
3431 procedure Resolve_Call (N : Node_Id; Typ : Entity_Id) is
3432 Loc : constant Source_Ptr := Sloc (N);
3433 Subp : constant Node_Id := Name (N);
3434 Nam : Entity_Id;
3435 I : Interp_Index;
3436 It : Interp;
3437 Norm_OK : Boolean;
3438 Scop : Entity_Id;
3439 W : Node_Id;
3441 begin
3442 -- The context imposes a unique interpretation with type Typ on
3443 -- a procedure or function call. Find the entity of the subprogram
3444 -- that yields the expected type, and propagate the corresponding
3445 -- formal constraints on the actuals. The caller has established
3446 -- that an interpretation exists, and emitted an error if not unique.
3448 -- First deal with the case of a call to an access-to-subprogram,
3449 -- dereference made explicit in Analyze_Call.
3451 if Ekind (Etype (Subp)) = E_Subprogram_Type then
3452 if not Is_Overloaded (Subp) then
3453 Nam := Etype (Subp);
3455 else
3456 -- Find the interpretation whose type (a subprogram type)
3457 -- has a return type that is compatible with the context.
3458 -- Analysis of the node has established that one exists.
3460 Get_First_Interp (Subp, I, It);
3461 Nam := Empty;
3463 while Present (It.Typ) loop
3464 if Covers (Typ, Etype (It.Typ)) then
3465 Nam := It.Typ;
3466 exit;
3467 end if;
3469 Get_Next_Interp (I, It);
3470 end loop;
3472 if No (Nam) then
3473 raise Program_Error;
3474 end if;
3475 end if;
3477 -- If the prefix is not an entity, then resolve it
3479 if not Is_Entity_Name (Subp) then
3480 Resolve (Subp, Nam);
3481 end if;
3483 -- For an indirect call, we always invalidate checks, since we
3484 -- do not know whether the subprogram is local or global. Yes
3485 -- we could do better here, e.g. by knowing that there are no
3486 -- local subprograms, but it does not seem worth the effort.
3487 -- Similarly, we kill al knowledge of current constant values.
3489 Kill_Current_Values;
3491 -- If this is a procedure call which is really an entry call, do
3492 -- the conversion of the procedure call to an entry call. Protected
3493 -- operations use the same circuitry because the name in the call
3494 -- can be an arbitrary expression with special resolution rules.
3496 elsif Nkind (Subp) = N_Selected_Component
3497 or else Nkind (Subp) = N_Indexed_Component
3498 or else (Is_Entity_Name (Subp)
3499 and then Ekind (Entity (Subp)) = E_Entry)
3500 then
3501 Resolve_Entry_Call (N, Typ);
3502 Check_Elab_Call (N);
3504 -- Kill checks and constant values, as above for indirect case
3505 -- Who knows what happens when another task is activated?
3507 Kill_Current_Values;
3508 return;
3510 -- Normal subprogram call with name established in Resolve
3512 elsif not (Is_Type (Entity (Subp))) then
3513 Nam := Entity (Subp);
3514 Set_Entity_With_Style_Check (Subp, Nam);
3515 Generate_Reference (Nam, Subp);
3517 -- Otherwise we must have the case of an overloaded call
3519 else
3520 pragma Assert (Is_Overloaded (Subp));
3521 Nam := Empty; -- We know that it will be assigned in loop below.
3523 Get_First_Interp (Subp, I, It);
3525 while Present (It.Typ) loop
3526 if Covers (Typ, It.Typ) then
3527 Nam := It.Nam;
3528 Set_Entity_With_Style_Check (Subp, Nam);
3529 Generate_Reference (Nam, Subp);
3530 exit;
3531 end if;
3533 Get_Next_Interp (I, It);
3534 end loop;
3535 end if;
3537 -- Check that a call to Current_Task does not occur in an entry body
3539 if Is_RTE (Nam, RE_Current_Task) then
3540 declare
3541 P : Node_Id;
3543 begin
3544 P := N;
3545 loop
3546 P := Parent (P);
3547 exit when No (P);
3549 if Nkind (P) = N_Entry_Body then
3550 Error_Msg_NE
3551 ("& should not be used in entry body ('R'M C.7(17))",
3552 N, Nam);
3553 exit;
3554 end if;
3555 end loop;
3556 end;
3557 end if;
3559 -- Cannot call thread body directly
3561 if Is_Thread_Body (Nam) then
3562 Error_Msg_N ("cannot call thread body directly", N);
3563 end if;
3565 -- If the subprogram is not global, then kill all checks. This is
3566 -- a bit conservative, since in many cases we could do better, but
3567 -- it is not worth the effort. Similarly, we kill constant values.
3568 -- However we do not need to do this for internal entities (unless
3569 -- they are inherited user-defined subprograms), since they are not
3570 -- in the business of molesting global values.
3572 if not Is_Library_Level_Entity (Nam)
3573 and then (Comes_From_Source (Nam)
3574 or else (Present (Alias (Nam))
3575 and then Comes_From_Source (Alias (Nam))))
3576 then
3577 Kill_Current_Values;
3578 end if;
3580 -- Check for call to obsolescent subprogram
3582 if Warn_On_Obsolescent_Feature
3583 and then Is_Subprogram (Nam)
3584 and then Is_Obsolescent (Nam)
3585 then
3586 Error_Msg_NE ("call to obsolescent subprogram&?", N, Nam);
3588 -- Output additional warning if present
3590 W := Obsolescent_Warning (Nam);
3592 if Present (W) then
3593 Name_Buffer (1) := '|';
3594 Name_Buffer (2) := '?';
3595 Name_Len := 2;
3597 -- Add characters to message, protecting all of them
3599 for J in 1 .. String_Length (Strval (W)) loop
3600 Add_Char_To_Name_Buffer (''');
3601 Add_Char_To_Name_Buffer
3602 (Get_Character (Get_String_Char (Strval (W), J)));
3603 end loop;
3605 Error_Msg_N (Name_Buffer (1 .. Name_Len), N);
3606 end if;
3607 end if;
3609 -- Check that a procedure call does not occur in the context
3610 -- of the entry call statement of a conditional or timed
3611 -- entry call. Note that the case of a call to a subprogram
3612 -- renaming of an entry will also be rejected. The test
3613 -- for N not being an N_Entry_Call_Statement is defensive,
3614 -- covering the possibility that the processing of entry
3615 -- calls might reach this point due to later modifications
3616 -- of the code above.
3618 if Nkind (Parent (N)) = N_Entry_Call_Alternative
3619 and then Nkind (N) /= N_Entry_Call_Statement
3620 and then Entry_Call_Statement (Parent (N)) = N
3621 then
3622 Error_Msg_N ("entry call required in select statement", N);
3623 end if;
3625 -- Check that this is not a call to a protected procedure or
3626 -- entry from within a protected function.
3628 if Ekind (Current_Scope) = E_Function
3629 and then Ekind (Scope (Current_Scope)) = E_Protected_Type
3630 and then Ekind (Nam) /= E_Function
3631 and then Scope (Nam) = Scope (Current_Scope)
3632 then
3633 Error_Msg_N ("within protected function, protected " &
3634 "object is constant", N);
3635 Error_Msg_N ("\cannot call operation that may modify it", N);
3636 end if;
3638 -- Freeze the subprogram name if not in default expression. Note
3639 -- that we freeze procedure calls as well as function calls.
3640 -- Procedure calls are not frozen according to the rules (RM
3641 -- 13.14(14)) because it is impossible to have a procedure call to
3642 -- a non-frozen procedure in pure Ada, but in the code that we
3643 -- generate in the expander, this rule needs extending because we
3644 -- can generate procedure calls that need freezing.
3646 if Is_Entity_Name (Subp) and then not In_Default_Expression then
3647 Freeze_Expression (Subp);
3648 end if;
3650 -- For a predefined operator, the type of the result is the type
3651 -- imposed by context, except for a predefined operation on universal
3652 -- fixed. Otherwise The type of the call is the type returned by the
3653 -- subprogram being called.
3655 if Is_Predefined_Op (Nam) then
3656 if Etype (N) /= Universal_Fixed then
3657 Set_Etype (N, Typ);
3658 end if;
3660 -- If the subprogram returns an array type, and the context
3661 -- requires the component type of that array type, the node is
3662 -- really an indexing of the parameterless call. Resolve as such.
3663 -- A pathological case occurs when the type of the component is
3664 -- an access to the array type. In this case the call is truly
3665 -- ambiguous.
3667 elsif Needs_No_Actuals (Nam)
3668 and then
3669 ((Is_Array_Type (Etype (Nam))
3670 and then Covers (Typ, Component_Type (Etype (Nam))))
3671 or else (Is_Access_Type (Etype (Nam))
3672 and then Is_Array_Type (Designated_Type (Etype (Nam)))
3673 and then
3674 Covers (Typ,
3675 Component_Type (Designated_Type (Etype (Nam))))))
3676 then
3677 declare
3678 Index_Node : Node_Id;
3679 New_Subp : Node_Id;
3680 Ret_Type : constant Entity_Id := Etype (Nam);
3682 begin
3683 if Is_Access_Type (Ret_Type)
3684 and then Ret_Type = Component_Type (Designated_Type (Ret_Type))
3685 then
3686 Error_Msg_N
3687 ("cannot disambiguate function call and indexing", N);
3688 else
3689 New_Subp := Relocate_Node (Subp);
3690 Set_Entity (Subp, Nam);
3692 if Component_Type (Ret_Type) /= Any_Type then
3693 Index_Node :=
3694 Make_Indexed_Component (Loc,
3695 Prefix =>
3696 Make_Function_Call (Loc,
3697 Name => New_Subp),
3698 Expressions => Parameter_Associations (N));
3700 -- Since we are correcting a node classification error made
3701 -- by the parser, we call Replace rather than Rewrite.
3703 Replace (N, Index_Node);
3704 Set_Etype (Prefix (N), Ret_Type);
3705 Set_Etype (N, Typ);
3706 Resolve_Indexed_Component (N, Typ);
3707 Check_Elab_Call (Prefix (N));
3708 end if;
3709 end if;
3711 return;
3712 end;
3714 else
3715 Set_Etype (N, Etype (Nam));
3716 end if;
3718 -- In the case where the call is to an overloaded subprogram, Analyze
3719 -- calls Normalize_Actuals once per overloaded subprogram. Therefore in
3720 -- such a case Normalize_Actuals needs to be called once more to order
3721 -- the actuals correctly. Otherwise the call will have the ordering
3722 -- given by the last overloaded subprogram whether this is the correct
3723 -- one being called or not.
3725 if Is_Overloaded (Subp) then
3726 Normalize_Actuals (N, Nam, False, Norm_OK);
3727 pragma Assert (Norm_OK);
3728 end if;
3730 -- In any case, call is fully resolved now. Reset Overload flag, to
3731 -- prevent subsequent overload resolution if node is analyzed again
3733 Set_Is_Overloaded (Subp, False);
3734 Set_Is_Overloaded (N, False);
3736 -- If we are calling the current subprogram from immediately within
3737 -- its body, then that is the case where we can sometimes detect
3738 -- cases of infinite recursion statically. Do not try this in case
3739 -- restriction No_Recursion is in effect anyway.
3741 Scop := Current_Scope;
3743 if Nam = Scop
3744 and then not Restriction_Active (No_Recursion)
3745 and then Check_Infinite_Recursion (N)
3746 then
3747 -- Here we detected and flagged an infinite recursion, so we do
3748 -- not need to test the case below for further warnings.
3750 null;
3752 -- If call is to immediately containing subprogram, then check for
3753 -- the case of a possible run-time detectable infinite recursion.
3755 else
3756 while Scop /= Standard_Standard loop
3757 if Nam = Scop then
3758 -- Although in general recursion is not statically checkable,
3759 -- the case of calling an immediately containing subprogram
3760 -- is easy to catch.
3762 Check_Restriction (No_Recursion, N);
3764 -- If the recursive call is to a parameterless procedure, then
3765 -- even if we can't statically detect infinite recursion, this
3766 -- is pretty suspicious, and we output a warning. Furthermore,
3767 -- we will try later to detect some cases here at run time by
3768 -- expanding checking code (see Detect_Infinite_Recursion in
3769 -- package Exp_Ch6).
3771 -- If the recursive call is within a handler we do not emit a
3772 -- warning, because this is a common idiom: loop until input
3773 -- is correct, catch illegal input in handler and restart.
3775 if No (First_Formal (Nam))
3776 and then Etype (Nam) = Standard_Void_Type
3777 and then not Error_Posted (N)
3778 and then Nkind (Parent (N)) /= N_Exception_Handler
3779 then
3780 Set_Has_Recursive_Call (Nam);
3781 Error_Msg_N ("possible infinite recursion?", N);
3782 Error_Msg_N ("Storage_Error may be raised at run time?", N);
3783 end if;
3785 exit;
3786 end if;
3788 Scop := Scope (Scop);
3789 end loop;
3790 end if;
3792 -- If subprogram name is a predefined operator, it was given in
3793 -- functional notation. Replace call node with operator node, so
3794 -- that actuals can be resolved appropriately.
3796 if Is_Predefined_Op (Nam) or else Ekind (Nam) = E_Operator then
3797 Make_Call_Into_Operator (N, Typ, Entity (Name (N)));
3798 return;
3800 elsif Present (Alias (Nam))
3801 and then Is_Predefined_Op (Alias (Nam))
3802 then
3803 Resolve_Actuals (N, Nam);
3804 Make_Call_Into_Operator (N, Typ, Alias (Nam));
3805 return;
3806 end if;
3808 -- Create a transient scope if the resulting type requires it
3810 -- There are 3 notable exceptions: in init procs, the transient scope
3811 -- overhead is not needed and even incorrect due to the actual expansion
3812 -- of adjust calls; the second case is enumeration literal pseudo calls,
3813 -- the other case is intrinsic subprograms (Unchecked_Conversion and
3814 -- source information functions) that do not use the secondary stack
3815 -- even though the return type is unconstrained.
3817 -- If this is an initialization call for a type whose initialization
3818 -- uses the secondary stack, we also need to create a transient scope
3819 -- for it, precisely because we will not do it within the init proc
3820 -- itself.
3822 if Expander_Active
3823 and then Is_Type (Etype (Nam))
3824 and then Requires_Transient_Scope (Etype (Nam))
3825 and then Ekind (Nam) /= E_Enumeration_Literal
3826 and then not Within_Init_Proc
3827 and then not Is_Intrinsic_Subprogram (Nam)
3828 then
3829 Establish_Transient_Scope
3830 (N, Sec_Stack => not Functions_Return_By_DSP_On_Target);
3832 -- If the call appears within the bounds of a loop, it will
3833 -- be rewritten and reanalyzed, nothing left to do here.
3835 if Nkind (N) /= N_Function_Call then
3836 return;
3837 end if;
3839 elsif Is_Init_Proc (Nam)
3840 and then not Within_Init_Proc
3841 then
3842 Check_Initialization_Call (N, Nam);
3843 end if;
3845 -- A protected function cannot be called within the definition of the
3846 -- enclosing protected type.
3848 if Is_Protected_Type (Scope (Nam))
3849 and then In_Open_Scopes (Scope (Nam))
3850 and then not Has_Completion (Scope (Nam))
3851 then
3852 Error_Msg_NE
3853 ("& cannot be called before end of protected definition", N, Nam);
3854 end if;
3856 -- Propagate interpretation to actuals, and add default expressions
3857 -- where needed.
3859 if Present (First_Formal (Nam)) then
3860 Resolve_Actuals (N, Nam);
3862 -- Overloaded literals are rewritten as function calls, for
3863 -- purpose of resolution. After resolution, we can replace
3864 -- the call with the literal itself.
3866 elsif Ekind (Nam) = E_Enumeration_Literal then
3867 Copy_Node (Subp, N);
3868 Resolve_Entity_Name (N, Typ);
3870 -- Avoid validation, since it is a static function call
3872 return;
3873 end if;
3875 -- If the subprogram is a primitive operation, check whether or not
3876 -- it is a correct dispatching call.
3878 if Is_Overloadable (Nam)
3879 and then Is_Dispatching_Operation (Nam)
3880 then
3881 Check_Dispatching_Call (N);
3883 elsif Is_Abstract (Nam)
3884 and then not In_Instance
3885 then
3886 Error_Msg_NE ("cannot call abstract subprogram &!", N, Nam);
3887 end if;
3889 if Is_Intrinsic_Subprogram (Nam) then
3890 Check_Intrinsic_Call (N);
3891 end if;
3893 Eval_Call (N);
3894 Check_Elab_Call (N);
3895 end Resolve_Call;
3897 -------------------------------
3898 -- Resolve_Character_Literal --
3899 -------------------------------
3901 procedure Resolve_Character_Literal (N : Node_Id; Typ : Entity_Id) is
3902 B_Typ : constant Entity_Id := Base_Type (Typ);
3903 C : Entity_Id;
3905 begin
3906 -- Verify that the character does belong to the type of the context
3908 Set_Etype (N, B_Typ);
3909 Eval_Character_Literal (N);
3911 -- Wide_Wide_Character literals must always be defined, since the set
3912 -- of wide wide character literals is complete, i.e. if a character
3913 -- literal is accepted by the parser, then it is OK for wide wide
3914 -- character (out of range character literals are rejected).
3916 if Root_Type (B_Typ) = Standard_Wide_Wide_Character then
3917 return;
3919 -- Always accept character literal for type Any_Character, which
3920 -- occurs in error situations and in comparisons of literals, both
3921 -- of which should accept all literals.
3923 elsif B_Typ = Any_Character then
3924 return;
3926 -- For Standard.Character or a type derived from it, check that
3927 -- the literal is in range
3929 elsif Root_Type (B_Typ) = Standard_Character then
3930 if In_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
3931 return;
3932 end if;
3934 -- For Standard.Wide_Character or a type derived from it, check
3935 -- that the literal is in range
3937 elsif Root_Type (B_Typ) = Standard_Wide_Character then
3938 if In_Wide_Character_Range (UI_To_CC (Char_Literal_Value (N))) then
3939 return;
3940 end if;
3942 -- For Standard.Wide_Wide_Character or a type derived from it, we
3943 -- know the literal is in range, since the parser checked!
3945 elsif Root_Type (B_Typ) = Standard_Wide_Wide_Character then
3946 return;
3948 -- If the entity is already set, this has already been resolved in
3949 -- a generic context, or comes from expansion. Nothing else to do.
3951 elsif Present (Entity (N)) then
3952 return;
3954 -- Otherwise we have a user defined character type, and we can use
3955 -- the standard visibility mechanisms to locate the referenced entity
3957 else
3958 C := Current_Entity (N);
3960 while Present (C) loop
3961 if Etype (C) = B_Typ then
3962 Set_Entity_With_Style_Check (N, C);
3963 Generate_Reference (C, N);
3964 return;
3965 end if;
3967 C := Homonym (C);
3968 end loop;
3969 end if;
3971 -- If we fall through, then the literal does not match any of the
3972 -- entries of the enumeration type. This isn't just a constraint
3973 -- error situation, it is an illegality (see RM 4.2).
3975 Error_Msg_NE
3976 ("character not defined for }", N, First_Subtype (B_Typ));
3977 end Resolve_Character_Literal;
3979 ---------------------------
3980 -- Resolve_Comparison_Op --
3981 ---------------------------
3983 -- Context requires a boolean type, and plays no role in resolution.
3984 -- Processing identical to that for equality operators. The result
3985 -- type is the base type, which matters when pathological subtypes of
3986 -- booleans with limited ranges are used.
3988 procedure Resolve_Comparison_Op (N : Node_Id; Typ : Entity_Id) is
3989 L : constant Node_Id := Left_Opnd (N);
3990 R : constant Node_Id := Right_Opnd (N);
3991 T : Entity_Id;
3993 begin
3994 Check_Direct_Boolean_Op (N);
3996 -- If this is an intrinsic operation which is not predefined, use
3997 -- the types of its declared arguments to resolve the possibly
3998 -- overloaded operands. Otherwise the operands are unambiguous and
3999 -- specify the expected type.
4001 if Scope (Entity (N)) /= Standard_Standard then
4002 T := Etype (First_Entity (Entity (N)));
4003 else
4004 T := Find_Unique_Type (L, R);
4006 if T = Any_Fixed then
4007 T := Unique_Fixed_Point_Type (L);
4008 end if;
4009 end if;
4011 Set_Etype (N, Base_Type (Typ));
4012 Generate_Reference (T, N, ' ');
4014 if T /= Any_Type then
4015 if T = Any_String
4016 or else T = Any_Composite
4017 or else T = Any_Character
4018 then
4019 if T = Any_Character then
4020 Ambiguous_Character (L);
4021 else
4022 Error_Msg_N ("ambiguous operands for comparison", N);
4023 end if;
4025 Set_Etype (N, Any_Type);
4026 return;
4028 else
4029 Resolve (L, T);
4030 Resolve (R, T);
4031 Check_Unset_Reference (L);
4032 Check_Unset_Reference (R);
4033 Generate_Operator_Reference (N, T);
4034 Eval_Relational_Op (N);
4035 end if;
4036 end if;
4037 end Resolve_Comparison_Op;
4039 ------------------------------------
4040 -- Resolve_Conditional_Expression --
4041 ------------------------------------
4043 procedure Resolve_Conditional_Expression (N : Node_Id; Typ : Entity_Id) is
4044 Condition : constant Node_Id := First (Expressions (N));
4045 Then_Expr : constant Node_Id := Next (Condition);
4046 Else_Expr : constant Node_Id := Next (Then_Expr);
4048 begin
4049 Resolve (Condition, Standard_Boolean);
4050 Resolve (Then_Expr, Typ);
4051 Resolve (Else_Expr, Typ);
4053 Set_Etype (N, Typ);
4054 Eval_Conditional_Expression (N);
4055 end Resolve_Conditional_Expression;
4057 -----------------------------------------
4058 -- Resolve_Discrete_Subtype_Indication --
4059 -----------------------------------------
4061 procedure Resolve_Discrete_Subtype_Indication
4062 (N : Node_Id;
4063 Typ : Entity_Id)
4065 R : Node_Id;
4066 S : Entity_Id;
4068 begin
4069 Analyze (Subtype_Mark (N));
4070 S := Entity (Subtype_Mark (N));
4072 if Nkind (Constraint (N)) /= N_Range_Constraint then
4073 Error_Msg_N ("expect range constraint for discrete type", N);
4074 Set_Etype (N, Any_Type);
4076 else
4077 R := Range_Expression (Constraint (N));
4079 if R = Error then
4080 return;
4081 end if;
4083 Analyze (R);
4085 if Base_Type (S) /= Base_Type (Typ) then
4086 Error_Msg_NE
4087 ("expect subtype of }", N, First_Subtype (Typ));
4089 -- Rewrite the constraint as a range of Typ
4090 -- to allow compilation to proceed further.
4092 Set_Etype (N, Typ);
4093 Rewrite (Low_Bound (R),
4094 Make_Attribute_Reference (Sloc (Low_Bound (R)),
4095 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4096 Attribute_Name => Name_First));
4097 Rewrite (High_Bound (R),
4098 Make_Attribute_Reference (Sloc (High_Bound (R)),
4099 Prefix => New_Occurrence_Of (Typ, Sloc (R)),
4100 Attribute_Name => Name_First));
4102 else
4103 Resolve (R, Typ);
4104 Set_Etype (N, Etype (R));
4106 -- Additionally, we must check that the bounds are compatible
4107 -- with the given subtype, which might be different from the
4108 -- type of the context.
4110 Apply_Range_Check (R, S);
4112 -- ??? If the above check statically detects a Constraint_Error
4113 -- it replaces the offending bound(s) of the range R with a
4114 -- Constraint_Error node. When the itype which uses these bounds
4115 -- is frozen the resulting call to Duplicate_Subexpr generates
4116 -- a new temporary for the bounds.
4118 -- Unfortunately there are other itypes that are also made depend
4119 -- on these bounds, so when Duplicate_Subexpr is called they get
4120 -- a forward reference to the newly created temporaries and Gigi
4121 -- aborts on such forward references. This is probably sign of a
4122 -- more fundamental problem somewhere else in either the order of
4123 -- itype freezing or the way certain itypes are constructed.
4125 -- To get around this problem we call Remove_Side_Effects right
4126 -- away if either bounds of R are a Constraint_Error.
4128 declare
4129 L : constant Node_Id := Low_Bound (R);
4130 H : constant Node_Id := High_Bound (R);
4132 begin
4133 if Nkind (L) = N_Raise_Constraint_Error then
4134 Remove_Side_Effects (L);
4135 end if;
4137 if Nkind (H) = N_Raise_Constraint_Error then
4138 Remove_Side_Effects (H);
4139 end if;
4140 end;
4142 Check_Unset_Reference (Low_Bound (R));
4143 Check_Unset_Reference (High_Bound (R));
4144 end if;
4145 end if;
4146 end Resolve_Discrete_Subtype_Indication;
4148 -------------------------
4149 -- Resolve_Entity_Name --
4150 -------------------------
4152 -- Used to resolve identifiers and expanded names
4154 procedure Resolve_Entity_Name (N : Node_Id; Typ : Entity_Id) is
4155 E : constant Entity_Id := Entity (N);
4157 begin
4158 -- If garbage from errors, set to Any_Type and return
4160 if No (E) and then Total_Errors_Detected /= 0 then
4161 Set_Etype (N, Any_Type);
4162 return;
4163 end if;
4165 -- Replace named numbers by corresponding literals. Note that this is
4166 -- the one case where Resolve_Entity_Name must reset the Etype, since
4167 -- it is currently marked as universal.
4169 if Ekind (E) = E_Named_Integer then
4170 Set_Etype (N, Typ);
4171 Eval_Named_Integer (N);
4173 elsif Ekind (E) = E_Named_Real then
4174 Set_Etype (N, Typ);
4175 Eval_Named_Real (N);
4177 -- Allow use of subtype only if it is a concurrent type where we are
4178 -- currently inside the body. This will eventually be expanded
4179 -- into a call to Self (for tasks) or _object (for protected
4180 -- objects). Any other use of a subtype is invalid.
4182 elsif Is_Type (E) then
4183 if Is_Concurrent_Type (E)
4184 and then In_Open_Scopes (E)
4185 then
4186 null;
4187 else
4188 Error_Msg_N
4189 ("Invalid use of subtype mark in expression or call", N);
4190 end if;
4192 -- Check discriminant use if entity is discriminant in current scope,
4193 -- i.e. discriminant of record or concurrent type currently being
4194 -- analyzed. Uses in corresponding body are unrestricted.
4196 elsif Ekind (E) = E_Discriminant
4197 and then Scope (E) = Current_Scope
4198 and then not Has_Completion (Current_Scope)
4199 then
4200 Check_Discriminant_Use (N);
4202 -- A parameterless generic function cannot appear in a context that
4203 -- requires resolution.
4205 elsif Ekind (E) = E_Generic_Function then
4206 Error_Msg_N ("illegal use of generic function", N);
4208 elsif Ekind (E) = E_Out_Parameter
4209 and then Ada_Version = Ada_83
4210 and then (Nkind (Parent (N)) in N_Op
4211 or else (Nkind (Parent (N)) = N_Assignment_Statement
4212 and then N = Expression (Parent (N)))
4213 or else Nkind (Parent (N)) = N_Explicit_Dereference)
4214 then
4215 Error_Msg_N ("(Ada 83) illegal reading of out parameter", N);
4217 -- In all other cases, just do the possible static evaluation
4219 else
4220 -- A deferred constant that appears in an expression must have
4221 -- a completion, unless it has been removed by in-place expansion
4222 -- of an aggregate.
4224 if Ekind (E) = E_Constant
4225 and then Comes_From_Source (E)
4226 and then No (Constant_Value (E))
4227 and then Is_Frozen (Etype (E))
4228 and then not In_Default_Expression
4229 and then not Is_Imported (E)
4230 then
4232 if No_Initialization (Parent (E))
4233 or else (Present (Full_View (E))
4234 and then No_Initialization (Parent (Full_View (E))))
4235 then
4236 null;
4237 else
4238 Error_Msg_N (
4239 "deferred constant is frozen before completion", N);
4240 end if;
4241 end if;
4243 Eval_Entity_Name (N);
4244 end if;
4245 end Resolve_Entity_Name;
4247 -------------------
4248 -- Resolve_Entry --
4249 -------------------
4251 procedure Resolve_Entry (Entry_Name : Node_Id) is
4252 Loc : constant Source_Ptr := Sloc (Entry_Name);
4253 Nam : Entity_Id;
4254 New_N : Node_Id;
4255 S : Entity_Id;
4256 Tsk : Entity_Id;
4257 E_Name : Node_Id;
4258 Index : Node_Id;
4260 function Actual_Index_Type (E : Entity_Id) return Entity_Id;
4261 -- If the bounds of the entry family being called depend on task
4262 -- discriminants, build a new index subtype where a discriminant is
4263 -- replaced with the value of the discriminant of the target task.
4264 -- The target task is the prefix of the entry name in the call.
4266 -----------------------
4267 -- Actual_Index_Type --
4268 -----------------------
4270 function Actual_Index_Type (E : Entity_Id) return Entity_Id is
4271 Typ : constant Entity_Id := Entry_Index_Type (E);
4272 Tsk : constant Entity_Id := Scope (E);
4273 Lo : constant Node_Id := Type_Low_Bound (Typ);
4274 Hi : constant Node_Id := Type_High_Bound (Typ);
4275 New_T : Entity_Id;
4277 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id;
4278 -- If the bound is given by a discriminant, replace with a reference
4279 -- to the discriminant of the same name in the target task.
4280 -- If the entry name is the target of a requeue statement and the
4281 -- entry is in the current protected object, the bound to be used
4282 -- is the discriminal of the object (see apply_range_checks for
4283 -- details of the transformation).
4285 -----------------------------
4286 -- Actual_Discriminant_Ref --
4287 -----------------------------
4289 function Actual_Discriminant_Ref (Bound : Node_Id) return Node_Id is
4290 Typ : constant Entity_Id := Etype (Bound);
4291 Ref : Node_Id;
4293 begin
4294 Remove_Side_Effects (Bound);
4296 if not Is_Entity_Name (Bound)
4297 or else Ekind (Entity (Bound)) /= E_Discriminant
4298 then
4299 return Bound;
4301 elsif Is_Protected_Type (Tsk)
4302 and then In_Open_Scopes (Tsk)
4303 and then Nkind (Parent (Entry_Name)) = N_Requeue_Statement
4304 then
4305 return New_Occurrence_Of (Discriminal (Entity (Bound)), Loc);
4307 else
4308 Ref :=
4309 Make_Selected_Component (Loc,
4310 Prefix => New_Copy_Tree (Prefix (Prefix (Entry_Name))),
4311 Selector_Name => New_Occurrence_Of (Entity (Bound), Loc));
4312 Analyze (Ref);
4313 Resolve (Ref, Typ);
4314 return Ref;
4315 end if;
4316 end Actual_Discriminant_Ref;
4318 -- Start of processing for Actual_Index_Type
4320 begin
4321 if not Has_Discriminants (Tsk)
4322 or else (not Is_Entity_Name (Lo)
4323 and then not Is_Entity_Name (Hi))
4324 then
4325 return Entry_Index_Type (E);
4327 else
4328 New_T := Create_Itype (Ekind (Typ), Parent (Entry_Name));
4329 Set_Etype (New_T, Base_Type (Typ));
4330 Set_Size_Info (New_T, Typ);
4331 Set_RM_Size (New_T, RM_Size (Typ));
4332 Set_Scalar_Range (New_T,
4333 Make_Range (Sloc (Entry_Name),
4334 Low_Bound => Actual_Discriminant_Ref (Lo),
4335 High_Bound => Actual_Discriminant_Ref (Hi)));
4337 return New_T;
4338 end if;
4339 end Actual_Index_Type;
4341 -- Start of processing of Resolve_Entry
4343 begin
4344 -- Find name of entry being called, and resolve prefix of name
4345 -- with its own type. The prefix can be overloaded, and the name
4346 -- and signature of the entry must be taken into account.
4348 if Nkind (Entry_Name) = N_Indexed_Component then
4350 -- Case of dealing with entry family within the current tasks
4352 E_Name := Prefix (Entry_Name);
4354 else
4355 E_Name := Entry_Name;
4356 end if;
4358 if Is_Entity_Name (E_Name) then
4359 -- Entry call to an entry (or entry family) in the current task.
4360 -- This is legal even though the task will deadlock. Rewrite as
4361 -- call to current task.
4363 -- This can also be a call to an entry in an enclosing task.
4364 -- If this is a single task, we have to retrieve its name,
4365 -- because the scope of the entry is the task type, not the
4366 -- object. If the enclosing task is a task type, the identity
4367 -- of the task is given by its own self variable.
4369 -- Finally this can be a requeue on an entry of the same task
4370 -- or protected object.
4372 S := Scope (Entity (E_Name));
4374 for J in reverse 0 .. Scope_Stack.Last loop
4376 if Is_Task_Type (Scope_Stack.Table (J).Entity)
4377 and then not Comes_From_Source (S)
4378 then
4379 -- S is an enclosing task or protected object. The concurrent
4380 -- declaration has been converted into a type declaration, and
4381 -- the object itself has an object declaration that follows
4382 -- the type in the same declarative part.
4384 Tsk := Next_Entity (S);
4386 while Etype (Tsk) /= S loop
4387 Next_Entity (Tsk);
4388 end loop;
4390 S := Tsk;
4391 exit;
4393 elsif S = Scope_Stack.Table (J).Entity then
4395 -- Call to current task. Will be transformed into call to Self
4397 exit;
4399 end if;
4400 end loop;
4402 New_N :=
4403 Make_Selected_Component (Loc,
4404 Prefix => New_Occurrence_Of (S, Loc),
4405 Selector_Name =>
4406 New_Occurrence_Of (Entity (E_Name), Loc));
4407 Rewrite (E_Name, New_N);
4408 Analyze (E_Name);
4410 elsif Nkind (Entry_Name) = N_Selected_Component
4411 and then Is_Overloaded (Prefix (Entry_Name))
4412 then
4413 -- Use the entry name (which must be unique at this point) to
4414 -- find the prefix that returns the corresponding task type or
4415 -- protected type.
4417 declare
4418 Pref : constant Node_Id := Prefix (Entry_Name);
4419 Ent : constant Entity_Id := Entity (Selector_Name (Entry_Name));
4420 I : Interp_Index;
4421 It : Interp;
4423 begin
4424 Get_First_Interp (Pref, I, It);
4426 while Present (It.Typ) loop
4428 if Scope (Ent) = It.Typ then
4429 Set_Etype (Pref, It.Typ);
4430 exit;
4431 end if;
4433 Get_Next_Interp (I, It);
4434 end loop;
4435 end;
4436 end if;
4438 if Nkind (Entry_Name) = N_Selected_Component then
4439 Resolve (Prefix (Entry_Name));
4441 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4442 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4443 Resolve (Prefix (Prefix (Entry_Name)));
4444 Index := First (Expressions (Entry_Name));
4445 Resolve (Index, Entry_Index_Type (Nam));
4447 -- Up to this point the expression could have been the actual
4448 -- in a simple entry call, and be given by a named association.
4450 if Nkind (Index) = N_Parameter_Association then
4451 Error_Msg_N ("expect expression for entry index", Index);
4452 else
4453 Apply_Range_Check (Index, Actual_Index_Type (Nam));
4454 end if;
4455 end if;
4456 end Resolve_Entry;
4458 ------------------------
4459 -- Resolve_Entry_Call --
4460 ------------------------
4462 procedure Resolve_Entry_Call (N : Node_Id; Typ : Entity_Id) is
4463 Entry_Name : constant Node_Id := Name (N);
4464 Loc : constant Source_Ptr := Sloc (Entry_Name);
4465 Actuals : List_Id;
4466 First_Named : Node_Id;
4467 Nam : Entity_Id;
4468 Norm_OK : Boolean;
4469 Obj : Node_Id;
4470 Was_Over : Boolean;
4472 begin
4473 -- We kill all checks here, because it does not seem worth the
4474 -- effort to do anything better, an entry call is a big operation.
4476 Kill_All_Checks;
4478 -- Processing of the name is similar for entry calls and protected
4479 -- operation calls. Once the entity is determined, we can complete
4480 -- the resolution of the actuals.
4482 -- The selector may be overloaded, in the case of a protected object
4483 -- with overloaded functions. The type of the context is used for
4484 -- resolution.
4486 if Nkind (Entry_Name) = N_Selected_Component
4487 and then Is_Overloaded (Selector_Name (Entry_Name))
4488 and then Typ /= Standard_Void_Type
4489 then
4490 declare
4491 I : Interp_Index;
4492 It : Interp;
4494 begin
4495 Get_First_Interp (Selector_Name (Entry_Name), I, It);
4497 while Present (It.Typ) loop
4499 if Covers (Typ, It.Typ) then
4500 Set_Entity (Selector_Name (Entry_Name), It.Nam);
4501 Set_Etype (Entry_Name, It.Typ);
4503 Generate_Reference (It.Typ, N, ' ');
4504 end if;
4506 Get_Next_Interp (I, It);
4507 end loop;
4508 end;
4509 end if;
4511 Resolve_Entry (Entry_Name);
4513 if Nkind (Entry_Name) = N_Selected_Component then
4515 -- Simple entry call.
4517 Nam := Entity (Selector_Name (Entry_Name));
4518 Obj := Prefix (Entry_Name);
4519 Was_Over := Is_Overloaded (Selector_Name (Entry_Name));
4521 else pragma Assert (Nkind (Entry_Name) = N_Indexed_Component);
4523 -- Call to member of entry family.
4525 Nam := Entity (Selector_Name (Prefix (Entry_Name)));
4526 Obj := Prefix (Prefix (Entry_Name));
4527 Was_Over := Is_Overloaded (Selector_Name (Prefix (Entry_Name)));
4528 end if;
4530 -- We cannot in general check the maximum depth of protected entry
4531 -- calls at compile time. But we can tell that any protected entry
4532 -- call at all violates a specified nesting depth of zero.
4534 if Is_Protected_Type (Scope (Nam)) then
4535 Check_Restriction (Max_Entry_Queue_Length, N);
4536 end if;
4538 -- Use context type to disambiguate a protected function that can be
4539 -- called without actuals and that returns an array type, and where
4540 -- the argument list may be an indexing of the returned value.
4542 if Ekind (Nam) = E_Function
4543 and then Needs_No_Actuals (Nam)
4544 and then Present (Parameter_Associations (N))
4545 and then
4546 ((Is_Array_Type (Etype (Nam))
4547 and then Covers (Typ, Component_Type (Etype (Nam))))
4549 or else (Is_Access_Type (Etype (Nam))
4550 and then Is_Array_Type (Designated_Type (Etype (Nam)))
4551 and then Covers (Typ,
4552 Component_Type (Designated_Type (Etype (Nam))))))
4553 then
4554 declare
4555 Index_Node : Node_Id;
4557 begin
4558 Index_Node :=
4559 Make_Indexed_Component (Loc,
4560 Prefix =>
4561 Make_Function_Call (Loc,
4562 Name => Relocate_Node (Entry_Name)),
4563 Expressions => Parameter_Associations (N));
4565 -- Since we are correcting a node classification error made by
4566 -- the parser, we call Replace rather than Rewrite.
4568 Replace (N, Index_Node);
4569 Set_Etype (Prefix (N), Etype (Nam));
4570 Set_Etype (N, Typ);
4571 Resolve_Indexed_Component (N, Typ);
4572 return;
4573 end;
4574 end if;
4576 -- The operation name may have been overloaded. Order the actuals
4577 -- according to the formals of the resolved entity, and set the
4578 -- return type to that of the operation.
4580 if Was_Over then
4581 Normalize_Actuals (N, Nam, False, Norm_OK);
4582 pragma Assert (Norm_OK);
4583 Set_Etype (N, Etype (Nam));
4584 end if;
4586 Resolve_Actuals (N, Nam);
4587 Generate_Reference (Nam, Entry_Name);
4589 if Ekind (Nam) = E_Entry
4590 or else Ekind (Nam) = E_Entry_Family
4591 then
4592 Check_Potentially_Blocking_Operation (N);
4593 end if;
4595 -- Verify that a procedure call cannot masquerade as an entry
4596 -- call where an entry call is expected.
4598 if Ekind (Nam) = E_Procedure then
4599 if Nkind (Parent (N)) = N_Entry_Call_Alternative
4600 and then N = Entry_Call_Statement (Parent (N))
4601 then
4602 Error_Msg_N ("entry call required in select statement", N);
4604 elsif Nkind (Parent (N)) = N_Triggering_Alternative
4605 and then N = Triggering_Statement (Parent (N))
4606 then
4607 Error_Msg_N ("triggering statement cannot be procedure call", N);
4609 elsif Ekind (Scope (Nam)) = E_Task_Type
4610 and then not In_Open_Scopes (Scope (Nam))
4611 then
4612 Error_Msg_N ("Task has no entry with this name", Entry_Name);
4613 end if;
4614 end if;
4616 -- After resolution, entry calls and protected procedure calls
4617 -- are changed into entry calls, for expansion. The structure
4618 -- of the node does not change, so it can safely be done in place.
4619 -- Protected function calls must keep their structure because they
4620 -- are subexpressions.
4622 if Ekind (Nam) /= E_Function then
4624 -- A protected operation that is not a function may modify the
4625 -- corresponding object, and cannot apply to a constant.
4626 -- If this is an internal call, the prefix is the type itself.
4628 if Is_Protected_Type (Scope (Nam))
4629 and then not Is_Variable (Obj)
4630 and then (not Is_Entity_Name (Obj)
4631 or else not Is_Type (Entity (Obj)))
4632 then
4633 Error_Msg_N
4634 ("prefix of protected procedure or entry call must be variable",
4635 Entry_Name);
4636 end if;
4638 Actuals := Parameter_Associations (N);
4639 First_Named := First_Named_Actual (N);
4641 Rewrite (N,
4642 Make_Entry_Call_Statement (Loc,
4643 Name => Entry_Name,
4644 Parameter_Associations => Actuals));
4646 Set_First_Named_Actual (N, First_Named);
4647 Set_Analyzed (N, True);
4649 -- Protected functions can return on the secondary stack, in which
4650 -- case we must trigger the transient scope mechanism
4652 elsif Expander_Active
4653 and then Requires_Transient_Scope (Etype (Nam))
4654 then
4655 Establish_Transient_Scope (N,
4656 Sec_Stack => not Functions_Return_By_DSP_On_Target);
4657 end if;
4658 end Resolve_Entry_Call;
4660 -------------------------
4661 -- Resolve_Equality_Op --
4662 -------------------------
4664 -- Both arguments must have the same type, and the boolean context
4665 -- does not participate in the resolution. The first pass verifies
4666 -- that the interpretation is not ambiguous, and the type of the left
4667 -- argument is correctly set, or is Any_Type in case of ambiguity.
4668 -- If both arguments are strings or aggregates, allocators, or Null,
4669 -- they are ambiguous even though they carry a single (universal) type.
4670 -- Diagnose this case here.
4672 procedure Resolve_Equality_Op (N : Node_Id; Typ : Entity_Id) is
4673 L : constant Node_Id := Left_Opnd (N);
4674 R : constant Node_Id := Right_Opnd (N);
4675 T : Entity_Id := Find_Unique_Type (L, R);
4677 function Find_Unique_Access_Type return Entity_Id;
4678 -- In the case of allocators, make a last-ditch attempt to find a single
4679 -- access type with the right designated type. This is semantically
4680 -- dubious, and of no interest to any real code, but c48008a makes it
4681 -- all worthwhile.
4683 -----------------------------
4684 -- Find_Unique_Access_Type --
4685 -----------------------------
4687 function Find_Unique_Access_Type return Entity_Id is
4688 Acc : Entity_Id;
4689 E : Entity_Id;
4690 S : Entity_Id := Current_Scope;
4692 begin
4693 if Ekind (Etype (R)) = E_Allocator_Type then
4694 Acc := Designated_Type (Etype (R));
4696 elsif Ekind (Etype (L)) = E_Allocator_Type then
4697 Acc := Designated_Type (Etype (L));
4699 else
4700 return Empty;
4701 end if;
4703 while S /= Standard_Standard loop
4704 E := First_Entity (S);
4706 while Present (E) loop
4708 if Is_Type (E)
4709 and then Is_Access_Type (E)
4710 and then Ekind (E) /= E_Allocator_Type
4711 and then Designated_Type (E) = Base_Type (Acc)
4712 then
4713 return E;
4714 end if;
4716 Next_Entity (E);
4717 end loop;
4719 S := Scope (S);
4720 end loop;
4722 return Empty;
4723 end Find_Unique_Access_Type;
4725 -- Start of processing for Resolve_Equality_Op
4727 begin
4728 Check_Direct_Boolean_Op (N);
4730 Set_Etype (N, Base_Type (Typ));
4731 Generate_Reference (T, N, ' ');
4733 if T = Any_Fixed then
4734 T := Unique_Fixed_Point_Type (L);
4735 end if;
4737 if T /= Any_Type then
4739 if T = Any_String
4740 or else T = Any_Composite
4741 or else T = Any_Character
4742 then
4744 if T = Any_Character then
4745 Ambiguous_Character (L);
4746 else
4747 Error_Msg_N ("ambiguous operands for equality", N);
4748 end if;
4750 Set_Etype (N, Any_Type);
4751 return;
4753 elsif T = Any_Access
4754 or else Ekind (T) = E_Allocator_Type
4755 then
4756 T := Find_Unique_Access_Type;
4758 if No (T) then
4759 Error_Msg_N ("ambiguous operands for equality", N);
4760 Set_Etype (N, Any_Type);
4761 return;
4762 end if;
4763 end if;
4765 Resolve (L, T);
4766 Resolve (R, T);
4768 if Warn_On_Redundant_Constructs
4769 and then Comes_From_Source (N)
4770 and then Is_Entity_Name (R)
4771 and then Entity (R) = Standard_True
4772 and then Comes_From_Source (R)
4773 then
4774 Error_Msg_N ("comparison with True is redundant?", R);
4775 end if;
4777 Check_Unset_Reference (L);
4778 Check_Unset_Reference (R);
4779 Generate_Operator_Reference (N, T);
4781 -- If this is an inequality, it may be the implicit inequality
4782 -- created for a user-defined operation, in which case the corres-
4783 -- ponding equality operation is not intrinsic, and the operation
4784 -- cannot be constant-folded. Else fold.
4786 if Nkind (N) = N_Op_Eq
4787 or else Comes_From_Source (Entity (N))
4788 or else Ekind (Entity (N)) = E_Operator
4789 or else Is_Intrinsic_Subprogram
4790 (Corresponding_Equality (Entity (N)))
4791 then
4792 Eval_Relational_Op (N);
4793 elsif Nkind (N) = N_Op_Ne
4794 and then Is_Abstract (Entity (N))
4795 then
4796 Error_Msg_NE ("cannot call abstract subprogram &!", N, Entity (N));
4797 end if;
4798 end if;
4799 end Resolve_Equality_Op;
4801 ----------------------------------
4802 -- Resolve_Explicit_Dereference --
4803 ----------------------------------
4805 procedure Resolve_Explicit_Dereference (N : Node_Id; Typ : Entity_Id) is
4806 P : constant Node_Id := Prefix (N);
4807 I : Interp_Index;
4808 It : Interp;
4810 begin
4811 -- Now that we know the type, check that this is not a
4812 -- dereference of an uncompleted type. Note that this
4813 -- is not entirely correct, because dereferences of
4814 -- private types are legal in default expressions.
4815 -- This consideration also applies to similar checks
4816 -- for allocators, qualified expressions, and type
4817 -- conversions. ???
4819 Check_Fully_Declared (Typ, N);
4821 if Is_Overloaded (P) then
4823 -- Use the context type to select the prefix that has the
4824 -- correct designated type.
4826 Get_First_Interp (P, I, It);
4827 while Present (It.Typ) loop
4828 exit when Is_Access_Type (It.Typ)
4829 and then Covers (Typ, Designated_Type (It.Typ));
4831 Get_Next_Interp (I, It);
4832 end loop;
4834 Resolve (P, It.Typ);
4835 Set_Etype (N, Designated_Type (It.Typ));
4837 else
4838 Resolve (P);
4839 end if;
4841 if Is_Access_Type (Etype (P)) then
4842 Apply_Access_Check (N);
4843 end if;
4845 -- If the designated type is a packed unconstrained array type,
4846 -- and the explicit dereference is not in the context of an
4847 -- attribute reference, then we must compute and set the actual
4848 -- subtype, since it is needed by Gigi. The reason we exclude
4849 -- the attribute case is that this is handled fine by Gigi, and
4850 -- in fact we use such attributes to build the actual subtype.
4851 -- We also exclude generated code (which builds actual subtypes
4852 -- directly if they are needed).
4854 if Is_Array_Type (Etype (N))
4855 and then Is_Packed (Etype (N))
4856 and then not Is_Constrained (Etype (N))
4857 and then Nkind (Parent (N)) /= N_Attribute_Reference
4858 and then Comes_From_Source (N)
4859 then
4860 Set_Etype (N, Get_Actual_Subtype (N));
4861 end if;
4863 -- Note: there is no Eval processing required for an explicit
4864 -- deference, because the type is known to be an allocators, and
4865 -- allocator expressions can never be static.
4867 end Resolve_Explicit_Dereference;
4869 -------------------------------
4870 -- Resolve_Indexed_Component --
4871 -------------------------------
4873 procedure Resolve_Indexed_Component (N : Node_Id; Typ : Entity_Id) is
4874 Name : constant Node_Id := Prefix (N);
4875 Expr : Node_Id;
4876 Array_Type : Entity_Id := Empty; -- to prevent junk warning
4877 Index : Node_Id;
4879 begin
4880 if Is_Overloaded (Name) then
4882 -- Use the context type to select the prefix that yields the
4883 -- correct component type.
4885 declare
4886 I : Interp_Index;
4887 It : Interp;
4888 I1 : Interp_Index := 0;
4889 P : constant Node_Id := Prefix (N);
4890 Found : Boolean := False;
4892 begin
4893 Get_First_Interp (P, I, It);
4895 while Present (It.Typ) loop
4897 if (Is_Array_Type (It.Typ)
4898 and then Covers (Typ, Component_Type (It.Typ)))
4899 or else (Is_Access_Type (It.Typ)
4900 and then Is_Array_Type (Designated_Type (It.Typ))
4901 and then Covers
4902 (Typ, Component_Type (Designated_Type (It.Typ))))
4903 then
4904 if Found then
4905 It := Disambiguate (P, I1, I, Any_Type);
4907 if It = No_Interp then
4908 Error_Msg_N ("ambiguous prefix for indexing", N);
4909 Set_Etype (N, Typ);
4910 return;
4912 else
4913 Found := True;
4914 Array_Type := It.Typ;
4915 I1 := I;
4916 end if;
4918 else
4919 Found := True;
4920 Array_Type := It.Typ;
4921 I1 := I;
4922 end if;
4923 end if;
4925 Get_Next_Interp (I, It);
4926 end loop;
4927 end;
4929 else
4930 Array_Type := Etype (Name);
4931 end if;
4933 Resolve (Name, Array_Type);
4934 Array_Type := Get_Actual_Subtype_If_Available (Name);
4936 -- If prefix is access type, dereference to get real array type.
4937 -- Note: we do not apply an access check because the expander always
4938 -- introduces an explicit dereference, and the check will happen there.
4940 if Is_Access_Type (Array_Type) then
4941 Array_Type := Designated_Type (Array_Type);
4942 end if;
4944 -- If name was overloaded, set component type correctly now.
4946 Set_Etype (N, Component_Type (Array_Type));
4948 Index := First_Index (Array_Type);
4949 Expr := First (Expressions (N));
4951 -- The prefix may have resolved to a string literal, in which case
4952 -- its etype has a special representation. This is only possible
4953 -- currently if the prefix is a static concatenation, written in
4954 -- functional notation.
4956 if Ekind (Array_Type) = E_String_Literal_Subtype then
4957 Resolve (Expr, Standard_Positive);
4959 else
4960 while Present (Index) and Present (Expr) loop
4961 Resolve (Expr, Etype (Index));
4962 Check_Unset_Reference (Expr);
4964 if Is_Scalar_Type (Etype (Expr)) then
4965 Apply_Scalar_Range_Check (Expr, Etype (Index));
4966 else
4967 Apply_Range_Check (Expr, Get_Actual_Subtype (Index));
4968 end if;
4970 Next_Index (Index);
4971 Next (Expr);
4972 end loop;
4973 end if;
4975 Eval_Indexed_Component (N);
4976 end Resolve_Indexed_Component;
4978 -----------------------------
4979 -- Resolve_Integer_Literal --
4980 -----------------------------
4982 procedure Resolve_Integer_Literal (N : Node_Id; Typ : Entity_Id) is
4983 begin
4984 Set_Etype (N, Typ);
4985 Eval_Integer_Literal (N);
4986 end Resolve_Integer_Literal;
4988 --------------------------------
4989 -- Resolve_Intrinsic_Operator --
4990 --------------------------------
4992 procedure Resolve_Intrinsic_Operator (N : Node_Id; Typ : Entity_Id) is
4993 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
4994 Op : Entity_Id;
4995 Arg1 : Node_Id;
4996 Arg2 : Node_Id;
4998 begin
4999 Op := Entity (N);
5001 while Scope (Op) /= Standard_Standard loop
5002 Op := Homonym (Op);
5003 pragma Assert (Present (Op));
5004 end loop;
5006 Set_Entity (N, Op);
5007 Set_Is_Overloaded (N, False);
5009 -- If the operand type is private, rewrite with suitable
5010 -- conversions on the operands and the result, to expose
5011 -- the proper underlying numeric type.
5013 if Is_Private_Type (Typ) then
5014 Arg1 := Unchecked_Convert_To (Btyp, Left_Opnd (N));
5016 if Nkind (N) = N_Op_Expon then
5017 Arg2 := Unchecked_Convert_To (Standard_Integer, Right_Opnd (N));
5018 else
5019 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5020 end if;
5022 Save_Interps (Left_Opnd (N), Expression (Arg1));
5023 Save_Interps (Right_Opnd (N), Expression (Arg2));
5025 Set_Left_Opnd (N, Arg1);
5026 Set_Right_Opnd (N, Arg2);
5028 Set_Etype (N, Btyp);
5029 Rewrite (N, Unchecked_Convert_To (Typ, N));
5030 Resolve (N, Typ);
5032 elsif Typ /= Etype (Left_Opnd (N))
5033 or else Typ /= Etype (Right_Opnd (N))
5034 then
5035 -- Add explicit conversion where needed, and save interpretations
5036 -- in case operands are overloaded.
5038 Arg1 := Convert_To (Typ, Left_Opnd (N));
5039 Arg2 := Convert_To (Typ, Right_Opnd (N));
5041 if Nkind (Arg1) = N_Type_Conversion then
5042 Save_Interps (Left_Opnd (N), Expression (Arg1));
5043 else
5044 Save_Interps (Left_Opnd (N), Arg1);
5045 end if;
5047 if Nkind (Arg2) = N_Type_Conversion then
5048 Save_Interps (Right_Opnd (N), Expression (Arg2));
5049 else
5050 Save_Interps (Right_Opnd (N), Arg2);
5051 end if;
5053 Rewrite (Left_Opnd (N), Arg1);
5054 Rewrite (Right_Opnd (N), Arg2);
5055 Analyze (Arg1);
5056 Analyze (Arg2);
5057 Resolve_Arithmetic_Op (N, Typ);
5059 else
5060 Resolve_Arithmetic_Op (N, Typ);
5061 end if;
5062 end Resolve_Intrinsic_Operator;
5064 --------------------------------------
5065 -- Resolve_Intrinsic_Unary_Operator --
5066 --------------------------------------
5068 procedure Resolve_Intrinsic_Unary_Operator
5069 (N : Node_Id;
5070 Typ : Entity_Id)
5072 Btyp : constant Entity_Id := Base_Type (Underlying_Type (Typ));
5073 Op : Entity_Id;
5074 Arg2 : Node_Id;
5076 begin
5077 Op := Entity (N);
5079 while Scope (Op) /= Standard_Standard loop
5080 Op := Homonym (Op);
5081 pragma Assert (Present (Op));
5082 end loop;
5084 Set_Entity (N, Op);
5086 if Is_Private_Type (Typ) then
5087 Arg2 := Unchecked_Convert_To (Btyp, Right_Opnd (N));
5088 Save_Interps (Right_Opnd (N), Expression (Arg2));
5090 Set_Right_Opnd (N, Arg2);
5092 Set_Etype (N, Btyp);
5093 Rewrite (N, Unchecked_Convert_To (Typ, N));
5094 Resolve (N, Typ);
5096 else
5097 Resolve_Unary_Op (N, Typ);
5098 end if;
5099 end Resolve_Intrinsic_Unary_Operator;
5101 ------------------------
5102 -- Resolve_Logical_Op --
5103 ------------------------
5105 procedure Resolve_Logical_Op (N : Node_Id; Typ : Entity_Id) is
5106 B_Typ : Entity_Id;
5108 begin
5109 Check_Direct_Boolean_Op (N);
5111 -- Predefined operations on scalar types yield the base type. On
5112 -- the other hand, logical operations on arrays yield the type of
5113 -- the arguments (and the context).
5115 if Is_Array_Type (Typ) then
5116 B_Typ := Typ;
5117 else
5118 B_Typ := Base_Type (Typ);
5119 end if;
5121 -- The following test is required because the operands of the operation
5122 -- may be literals, in which case the resulting type appears to be
5123 -- compatible with a signed integer type, when in fact it is compatible
5124 -- only with modular types. If the context itself is universal, the
5125 -- operation is illegal.
5127 if not Valid_Boolean_Arg (Typ) then
5128 Error_Msg_N ("invalid context for logical operation", N);
5129 Set_Etype (N, Any_Type);
5130 return;
5132 elsif Typ = Any_Modular then
5133 Error_Msg_N
5134 ("no modular type available in this context", N);
5135 Set_Etype (N, Any_Type);
5136 return;
5137 elsif Is_Modular_Integer_Type (Typ)
5138 and then Etype (Left_Opnd (N)) = Universal_Integer
5139 and then Etype (Right_Opnd (N)) = Universal_Integer
5140 then
5141 Check_For_Visible_Operator (N, B_Typ);
5142 end if;
5144 Resolve (Left_Opnd (N), B_Typ);
5145 Resolve (Right_Opnd (N), B_Typ);
5147 Check_Unset_Reference (Left_Opnd (N));
5148 Check_Unset_Reference (Right_Opnd (N));
5150 Set_Etype (N, B_Typ);
5151 Generate_Operator_Reference (N, B_Typ);
5152 Eval_Logical_Op (N);
5153 end Resolve_Logical_Op;
5155 ---------------------------
5156 -- Resolve_Membership_Op --
5157 ---------------------------
5159 -- The context can only be a boolean type, and does not determine
5160 -- the arguments. Arguments should be unambiguous, but the preference
5161 -- rule for universal types applies.
5163 procedure Resolve_Membership_Op (N : Node_Id; Typ : Entity_Id) is
5164 pragma Warnings (Off, Typ);
5166 L : constant Node_Id := Left_Opnd (N);
5167 R : constant Node_Id := Right_Opnd (N);
5168 T : Entity_Id;
5170 begin
5171 if L = Error or else R = Error then
5172 return;
5173 end if;
5175 if not Is_Overloaded (R)
5176 and then
5177 (Etype (R) = Universal_Integer or else
5178 Etype (R) = Universal_Real)
5179 and then Is_Overloaded (L)
5180 then
5181 T := Etype (R);
5182 else
5183 T := Intersect_Types (L, R);
5184 end if;
5186 Resolve (L, T);
5187 Check_Unset_Reference (L);
5189 if Nkind (R) = N_Range
5190 and then not Is_Scalar_Type (T)
5191 then
5192 Error_Msg_N ("scalar type required for range", R);
5193 end if;
5195 if Is_Entity_Name (R) then
5196 Freeze_Expression (R);
5197 else
5198 Resolve (R, T);
5199 Check_Unset_Reference (R);
5200 end if;
5202 Eval_Membership_Op (N);
5203 end Resolve_Membership_Op;
5205 ------------------
5206 -- Resolve_Null --
5207 ------------------
5209 procedure Resolve_Null (N : Node_Id; Typ : Entity_Id) is
5210 begin
5211 -- Handle restriction against anonymous null access values
5212 -- This restriction can be turned off using -gnatdh.
5214 -- Ada 2005 (AI-231): Remove restriction
5216 if Ada_Version < Ada_05
5217 and then not Debug_Flag_J
5218 and then Ekind (Typ) = E_Anonymous_Access_Type
5219 and then Comes_From_Source (N)
5220 then
5221 -- In the common case of a call which uses an explicitly null
5222 -- value for an access parameter, give specialized error msg
5224 if Nkind (Parent (N)) = N_Procedure_Call_Statement
5225 or else
5226 Nkind (Parent (N)) = N_Function_Call
5227 then
5228 Error_Msg_N
5229 ("null is not allowed as argument for an access parameter", N);
5231 -- Standard message for all other cases (are there any?)
5233 else
5234 Error_Msg_N
5235 ("null cannot be of an anonymous access type", N);
5236 end if;
5237 end if;
5239 -- In a distributed context, null for a remote access to subprogram
5240 -- may need to be replaced with a special record aggregate. In this
5241 -- case, return after having done the transformation.
5243 if (Ekind (Typ) = E_Record_Type
5244 or else Is_Remote_Access_To_Subprogram_Type (Typ))
5245 and then Remote_AST_Null_Value (N, Typ)
5246 then
5247 return;
5248 end if;
5250 -- The null literal takes its type from the context.
5252 Set_Etype (N, Typ);
5253 end Resolve_Null;
5255 -----------------------
5256 -- Resolve_Op_Concat --
5257 -----------------------
5259 procedure Resolve_Op_Concat (N : Node_Id; Typ : Entity_Id) is
5260 Btyp : constant Entity_Id := Base_Type (Typ);
5261 Op1 : constant Node_Id := Left_Opnd (N);
5262 Op2 : constant Node_Id := Right_Opnd (N);
5264 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean);
5265 -- Internal procedure to resolve one operand of concatenation operator.
5266 -- The operand is either of the array type or of the component type.
5267 -- If the operand is an aggregate, and the component type is composite,
5268 -- this is ambiguous if component type has aggregates.
5270 -------------------------------
5271 -- Resolve_Concatenation_Arg --
5272 -------------------------------
5274 procedure Resolve_Concatenation_Arg (Arg : Node_Id; Is_Comp : Boolean) is
5275 begin
5276 if In_Instance then
5277 if Is_Comp
5278 or else (not Is_Overloaded (Arg)
5279 and then Etype (Arg) /= Any_Composite
5280 and then Covers (Component_Type (Typ), Etype (Arg)))
5281 then
5282 Resolve (Arg, Component_Type (Typ));
5283 else
5284 Resolve (Arg, Btyp);
5285 end if;
5287 elsif Has_Compatible_Type (Arg, Component_Type (Typ)) then
5289 if Nkind (Arg) = N_Aggregate
5290 and then Is_Composite_Type (Component_Type (Typ))
5291 then
5292 if Is_Private_Type (Component_Type (Typ)) then
5293 Resolve (Arg, Btyp);
5295 else
5296 Error_Msg_N ("ambiguous aggregate must be qualified", Arg);
5297 Set_Etype (Arg, Any_Type);
5298 end if;
5300 else
5301 if Is_Overloaded (Arg)
5302 and then Has_Compatible_Type (Arg, Typ)
5303 and then Etype (Arg) /= Any_Type
5304 then
5305 Error_Msg_N ("ambiguous operand for concatenation!", Arg);
5307 declare
5308 I : Interp_Index;
5309 It : Interp;
5311 begin
5312 Get_First_Interp (Arg, I, It);
5314 while Present (It.Nam) loop
5316 if Base_Type (Etype (It.Nam)) = Base_Type (Typ)
5317 or else Base_Type (Etype (It.Nam)) =
5318 Base_Type (Component_Type (Typ))
5319 then
5320 Error_Msg_Sloc := Sloc (It.Nam);
5321 Error_Msg_N ("\possible interpretation#", Arg);
5322 end if;
5324 Get_Next_Interp (I, It);
5325 end loop;
5326 end;
5327 end if;
5329 Resolve (Arg, Component_Type (Typ));
5331 if Nkind (Arg) = N_String_Literal then
5332 Set_Etype (Arg, Component_Type (Typ));
5333 end if;
5335 if Arg = Left_Opnd (N) then
5336 Set_Is_Component_Left_Opnd (N);
5337 else
5338 Set_Is_Component_Right_Opnd (N);
5339 end if;
5340 end if;
5342 else
5343 Resolve (Arg, Btyp);
5344 end if;
5346 Check_Unset_Reference (Arg);
5347 end Resolve_Concatenation_Arg;
5349 -- Start of processing for Resolve_Op_Concat
5351 begin
5352 Set_Etype (N, Btyp);
5354 if Is_Limited_Composite (Btyp) then
5355 Error_Msg_N ("concatenation not available for limited array", N);
5356 Explain_Limited_Type (Btyp, N);
5357 end if;
5359 -- If the operands are themselves concatenations, resolve them as
5360 -- such directly. This removes several layers of recursion and allows
5361 -- GNAT to handle larger multiple concatenations.
5363 if Nkind (Op1) = N_Op_Concat
5364 and then not Is_Array_Type (Component_Type (Typ))
5365 and then Entity (Op1) = Entity (N)
5366 then
5367 Resolve_Op_Concat (Op1, Typ);
5368 else
5369 Resolve_Concatenation_Arg
5370 (Op1, Is_Component_Left_Opnd (N));
5371 end if;
5373 if Nkind (Op2) = N_Op_Concat
5374 and then not Is_Array_Type (Component_Type (Typ))
5375 and then Entity (Op2) = Entity (N)
5376 then
5377 Resolve_Op_Concat (Op2, Typ);
5378 else
5379 Resolve_Concatenation_Arg
5380 (Op2, Is_Component_Right_Opnd (N));
5381 end if;
5383 Generate_Operator_Reference (N, Typ);
5385 if Is_String_Type (Typ) then
5386 Eval_Concatenation (N);
5387 end if;
5389 -- If this is not a static concatenation, but the result is a
5390 -- string type (and not an array of strings) insure that static
5391 -- string operands have their subtypes properly constructed.
5393 if Nkind (N) /= N_String_Literal
5394 and then Is_Character_Type (Component_Type (Typ))
5395 then
5396 Set_String_Literal_Subtype (Op1, Typ);
5397 Set_String_Literal_Subtype (Op2, Typ);
5398 end if;
5399 end Resolve_Op_Concat;
5401 ----------------------
5402 -- Resolve_Op_Expon --
5403 ----------------------
5405 procedure Resolve_Op_Expon (N : Node_Id; Typ : Entity_Id) is
5406 B_Typ : constant Entity_Id := Base_Type (Typ);
5408 begin
5409 -- Catch attempts to do fixed-point exponentation with universal
5410 -- operands, which is a case where the illegality is not caught
5411 -- during normal operator analysis.
5413 if Is_Fixed_Point_Type (Typ) and then Comes_From_Source (N) then
5414 Error_Msg_N ("exponentiation not available for fixed point", N);
5415 return;
5416 end if;
5418 if Comes_From_Source (N)
5419 and then Ekind (Entity (N)) = E_Function
5420 and then Is_Imported (Entity (N))
5421 and then Is_Intrinsic_Subprogram (Entity (N))
5422 then
5423 Resolve_Intrinsic_Operator (N, Typ);
5424 return;
5425 end if;
5427 if Etype (Left_Opnd (N)) = Universal_Integer
5428 or else Etype (Left_Opnd (N)) = Universal_Real
5429 then
5430 Check_For_Visible_Operator (N, B_Typ);
5431 end if;
5433 -- We do the resolution using the base type, because intermediate values
5434 -- in expressions always are of the base type, not a subtype of it.
5436 Resolve (Left_Opnd (N), B_Typ);
5437 Resolve (Right_Opnd (N), Standard_Integer);
5439 Check_Unset_Reference (Left_Opnd (N));
5440 Check_Unset_Reference (Right_Opnd (N));
5442 Set_Etype (N, B_Typ);
5443 Generate_Operator_Reference (N, B_Typ);
5444 Eval_Op_Expon (N);
5446 -- Set overflow checking bit. Much cleverer code needed here eventually
5447 -- and perhaps the Resolve routines should be separated for the various
5448 -- arithmetic operations, since they will need different processing. ???
5450 if Nkind (N) in N_Op then
5451 if not Overflow_Checks_Suppressed (Etype (N)) then
5452 Enable_Overflow_Check (N);
5453 end if;
5454 end if;
5455 end Resolve_Op_Expon;
5457 --------------------
5458 -- Resolve_Op_Not --
5459 --------------------
5461 procedure Resolve_Op_Not (N : Node_Id; Typ : Entity_Id) is
5462 B_Typ : Entity_Id;
5464 function Parent_Is_Boolean return Boolean;
5465 -- This function determines if the parent node is a boolean operator
5466 -- or operation (comparison op, membership test, or short circuit form)
5467 -- and the not in question is the left operand of this operation.
5468 -- Note that if the not is in parens, then false is returned.
5470 function Parent_Is_Boolean return Boolean is
5471 begin
5472 if Paren_Count (N) /= 0 then
5473 return False;
5475 else
5476 case Nkind (Parent (N)) is
5477 when N_Op_And |
5478 N_Op_Eq |
5479 N_Op_Ge |
5480 N_Op_Gt |
5481 N_Op_Le |
5482 N_Op_Lt |
5483 N_Op_Ne |
5484 N_Op_Or |
5485 N_Op_Xor |
5486 N_In |
5487 N_Not_In |
5488 N_And_Then |
5489 N_Or_Else =>
5491 return Left_Opnd (Parent (N)) = N;
5493 when others =>
5494 return False;
5495 end case;
5496 end if;
5497 end Parent_Is_Boolean;
5499 -- Start of processing for Resolve_Op_Not
5501 begin
5502 -- Predefined operations on scalar types yield the base type. On
5503 -- the other hand, logical operations on arrays yield the type of
5504 -- the arguments (and the context).
5506 if Is_Array_Type (Typ) then
5507 B_Typ := Typ;
5508 else
5509 B_Typ := Base_Type (Typ);
5510 end if;
5512 if not Valid_Boolean_Arg (Typ) then
5513 Error_Msg_N ("invalid operand type for operator&", N);
5514 Set_Etype (N, Any_Type);
5515 return;
5517 elsif Typ = Universal_Integer or else Typ = Any_Modular then
5518 if Parent_Is_Boolean then
5519 Error_Msg_N
5520 ("operand of not must be enclosed in parentheses",
5521 Right_Opnd (N));
5522 else
5523 Error_Msg_N
5524 ("no modular type available in this context", N);
5525 end if;
5527 Set_Etype (N, Any_Type);
5528 return;
5530 else
5531 if not Is_Boolean_Type (Typ)
5532 and then Parent_Is_Boolean
5533 then
5534 Error_Msg_N ("?not expression should be parenthesized here", N);
5535 end if;
5537 Resolve (Right_Opnd (N), B_Typ);
5538 Check_Unset_Reference (Right_Opnd (N));
5539 Set_Etype (N, B_Typ);
5540 Generate_Operator_Reference (N, B_Typ);
5541 Eval_Op_Not (N);
5542 end if;
5543 end Resolve_Op_Not;
5545 -----------------------------
5546 -- Resolve_Operator_Symbol --
5547 -----------------------------
5549 -- Nothing to be done, all resolved already
5551 procedure Resolve_Operator_Symbol (N : Node_Id; Typ : Entity_Id) is
5552 pragma Warnings (Off, N);
5553 pragma Warnings (Off, Typ);
5555 begin
5556 null;
5557 end Resolve_Operator_Symbol;
5559 ----------------------------------
5560 -- Resolve_Qualified_Expression --
5561 ----------------------------------
5563 procedure Resolve_Qualified_Expression (N : Node_Id; Typ : Entity_Id) is
5564 pragma Warnings (Off, Typ);
5566 Target_Typ : constant Entity_Id := Entity (Subtype_Mark (N));
5567 Expr : constant Node_Id := Expression (N);
5569 begin
5570 Resolve (Expr, Target_Typ);
5572 -- A qualified expression requires an exact match of the type,
5573 -- class-wide matching is not allowed.
5575 if Is_Class_Wide_Type (Target_Typ)
5576 and then Base_Type (Etype (Expr)) /= Base_Type (Target_Typ)
5577 then
5578 Wrong_Type (Expr, Target_Typ);
5579 end if;
5581 -- If the target type is unconstrained, then we reset the type of
5582 -- the result from the type of the expression. For other cases, the
5583 -- actual subtype of the expression is the target type.
5585 if Is_Composite_Type (Target_Typ)
5586 and then not Is_Constrained (Target_Typ)
5587 then
5588 Set_Etype (N, Etype (Expr));
5589 end if;
5591 Eval_Qualified_Expression (N);
5592 end Resolve_Qualified_Expression;
5594 -------------------
5595 -- Resolve_Range --
5596 -------------------
5598 procedure Resolve_Range (N : Node_Id; Typ : Entity_Id) is
5599 L : constant Node_Id := Low_Bound (N);
5600 H : constant Node_Id := High_Bound (N);
5602 begin
5603 Set_Etype (N, Typ);
5604 Resolve (L, Typ);
5605 Resolve (H, Typ);
5607 Check_Unset_Reference (L);
5608 Check_Unset_Reference (H);
5610 -- We have to check the bounds for being within the base range as
5611 -- required for a non-static context. Normally this is automatic
5612 -- and done as part of evaluating expressions, but the N_Range
5613 -- node is an exception, since in GNAT we consider this node to
5614 -- be a subexpression, even though in Ada it is not. The circuit
5615 -- in Sem_Eval could check for this, but that would put the test
5616 -- on the main evaluation path for expressions.
5618 Check_Non_Static_Context (L);
5619 Check_Non_Static_Context (H);
5621 -- If bounds are static, constant-fold them, so size computations
5622 -- are identical between front-end and back-end. Do not perform this
5623 -- transformation while analyzing generic units, as type information
5624 -- would then be lost when reanalyzing the constant node in the
5625 -- instance.
5627 if Is_Discrete_Type (Typ) and then Expander_Active then
5628 if Is_OK_Static_Expression (L) then
5629 Fold_Uint (L, Expr_Value (L), Is_Static_Expression (L));
5630 end if;
5632 if Is_OK_Static_Expression (H) then
5633 Fold_Uint (H, Expr_Value (H), Is_Static_Expression (H));
5634 end if;
5635 end if;
5636 end Resolve_Range;
5638 --------------------------
5639 -- Resolve_Real_Literal --
5640 --------------------------
5642 procedure Resolve_Real_Literal (N : Node_Id; Typ : Entity_Id) is
5643 Actual_Typ : constant Entity_Id := Etype (N);
5645 begin
5646 -- Special processing for fixed-point literals to make sure that the
5647 -- value is an exact multiple of small where this is required. We
5648 -- skip this for the universal real case, and also for generic types.
5650 if Is_Fixed_Point_Type (Typ)
5651 and then Typ /= Universal_Fixed
5652 and then Typ /= Any_Fixed
5653 and then not Is_Generic_Type (Typ)
5654 then
5655 declare
5656 Val : constant Ureal := Realval (N);
5657 Cintr : constant Ureal := Val / Small_Value (Typ);
5658 Cint : constant Uint := UR_Trunc (Cintr);
5659 Den : constant Uint := Norm_Den (Cintr);
5660 Stat : Boolean;
5662 begin
5663 -- Case of literal is not an exact multiple of the Small
5665 if Den /= 1 then
5667 -- For a source program literal for a decimal fixed-point
5668 -- type, this is statically illegal (RM 4.9(36)).
5670 if Is_Decimal_Fixed_Point_Type (Typ)
5671 and then Actual_Typ = Universal_Real
5672 and then Comes_From_Source (N)
5673 then
5674 Error_Msg_N ("value has extraneous low order digits", N);
5675 end if;
5677 -- Replace literal by a value that is the exact representation
5678 -- of a value of the type, i.e. a multiple of the small value,
5679 -- by truncation, since Machine_Rounds is false for all GNAT
5680 -- fixed-point types (RM 4.9(38)).
5682 Stat := Is_Static_Expression (N);
5683 Rewrite (N,
5684 Make_Real_Literal (Sloc (N),
5685 Realval => Small_Value (Typ) * Cint));
5687 Set_Is_Static_Expression (N, Stat);
5688 end if;
5690 -- In all cases, set the corresponding integer field
5692 Set_Corresponding_Integer_Value (N, Cint);
5693 end;
5694 end if;
5696 -- Now replace the actual type by the expected type as usual
5698 Set_Etype (N, Typ);
5699 Eval_Real_Literal (N);
5700 end Resolve_Real_Literal;
5702 -----------------------
5703 -- Resolve_Reference --
5704 -----------------------
5706 procedure Resolve_Reference (N : Node_Id; Typ : Entity_Id) is
5707 P : constant Node_Id := Prefix (N);
5709 begin
5710 -- Replace general access with specific type
5712 if Ekind (Etype (N)) = E_Allocator_Type then
5713 Set_Etype (N, Base_Type (Typ));
5714 end if;
5716 Resolve (P, Designated_Type (Etype (N)));
5718 -- If we are taking the reference of a volatile entity, then treat
5719 -- it as a potential modification of this entity. This is much too
5720 -- conservative, but is necessary because remove side effects can
5721 -- result in transformations of normal assignments into reference
5722 -- sequences that otherwise fail to notice the modification.
5724 if Is_Entity_Name (P) and then Treat_As_Volatile (Entity (P)) then
5725 Note_Possible_Modification (P);
5726 end if;
5727 end Resolve_Reference;
5729 --------------------------------
5730 -- Resolve_Selected_Component --
5731 --------------------------------
5733 procedure Resolve_Selected_Component (N : Node_Id; Typ : Entity_Id) is
5734 Comp : Entity_Id;
5735 Comp1 : Entity_Id := Empty; -- prevent junk warning
5736 P : constant Node_Id := Prefix (N);
5737 S : constant Node_Id := Selector_Name (N);
5738 T : Entity_Id := Etype (P);
5739 I : Interp_Index;
5740 I1 : Interp_Index := 0; -- prevent junk warning
5741 It : Interp;
5742 It1 : Interp;
5743 Found : Boolean;
5745 function Init_Component return Boolean;
5746 -- Check whether this is the initialization of a component within an
5747 -- init proc (by assignment or call to another init proc). If true,
5748 -- there is no need for a discriminant check.
5750 --------------------
5751 -- Init_Component --
5752 --------------------
5754 function Init_Component return Boolean is
5755 begin
5756 return Inside_Init_Proc
5757 and then Nkind (Prefix (N)) = N_Identifier
5758 and then Chars (Prefix (N)) = Name_uInit
5759 and then Nkind (Parent (Parent (N))) = N_Case_Statement_Alternative;
5760 end Init_Component;
5762 -- Start of processing for Resolve_Selected_Component
5764 begin
5765 if Is_Overloaded (P) then
5767 -- Use the context type to select the prefix that has a selector
5768 -- of the correct name and type.
5770 Found := False;
5771 Get_First_Interp (P, I, It);
5773 Search : while Present (It.Typ) loop
5774 if Is_Access_Type (It.Typ) then
5775 T := Designated_Type (It.Typ);
5776 else
5777 T := It.Typ;
5778 end if;
5780 if Is_Record_Type (T) then
5781 Comp := First_Entity (T);
5783 while Present (Comp) loop
5785 if Chars (Comp) = Chars (S)
5786 and then Covers (Etype (Comp), Typ)
5787 then
5788 if not Found then
5789 Found := True;
5790 I1 := I;
5791 It1 := It;
5792 Comp1 := Comp;
5794 else
5795 It := Disambiguate (P, I1, I, Any_Type);
5797 if It = No_Interp then
5798 Error_Msg_N
5799 ("ambiguous prefix for selected component", N);
5800 Set_Etype (N, Typ);
5801 return;
5803 else
5804 It1 := It;
5806 if Scope (Comp1) /= It1.Typ then
5808 -- Resolution chooses the new interpretation.
5809 -- Find the component with the right name.
5811 Comp1 := First_Entity (It1.Typ);
5813 while Present (Comp1)
5814 and then Chars (Comp1) /= Chars (S)
5815 loop
5816 Comp1 := Next_Entity (Comp1);
5817 end loop;
5818 end if;
5820 exit Search;
5821 end if;
5822 end if;
5823 end if;
5825 Comp := Next_Entity (Comp);
5826 end loop;
5828 end if;
5830 Get_Next_Interp (I, It);
5831 end loop Search;
5833 Resolve (P, It1.Typ);
5834 Set_Etype (N, Typ);
5835 Set_Entity (S, Comp1);
5837 else
5838 -- Resolve prefix with its type
5840 Resolve (P, T);
5841 end if;
5843 -- If prefix is an access type, the node will be transformed into
5844 -- an explicit dereference during expansion. The type of the node
5845 -- is the designated type of that of the prefix.
5847 if Is_Access_Type (Etype (P)) then
5848 T := Designated_Type (Etype (P));
5849 else
5850 T := Etype (P);
5851 end if;
5853 if Has_Discriminants (T)
5854 and then (Ekind (Entity (S)) = E_Component
5855 or else
5856 Ekind (Entity (S)) = E_Discriminant)
5857 and then Present (Original_Record_Component (Entity (S)))
5858 and then Ekind (Original_Record_Component (Entity (S))) = E_Component
5859 and then Present (Discriminant_Checking_Func
5860 (Original_Record_Component (Entity (S))))
5861 and then not Discriminant_Checks_Suppressed (T)
5862 and then not Init_Component
5863 then
5864 Set_Do_Discriminant_Check (N);
5865 end if;
5867 if Ekind (Entity (S)) = E_Void then
5868 Error_Msg_N ("premature use of component", S);
5869 end if;
5871 -- If the prefix is a record conversion, this may be a renamed
5872 -- discriminant whose bounds differ from those of the original
5873 -- one, so we must ensure that a range check is performed.
5875 if Nkind (P) = N_Type_Conversion
5876 and then Ekind (Entity (S)) = E_Discriminant
5877 and then Is_Discrete_Type (Typ)
5878 then
5879 Set_Etype (N, Base_Type (Typ));
5880 end if;
5882 -- Note: No Eval processing is required, because the prefix is of a
5883 -- record type, or protected type, and neither can possibly be static.
5885 end Resolve_Selected_Component;
5887 -------------------
5888 -- Resolve_Shift --
5889 -------------------
5891 procedure Resolve_Shift (N : Node_Id; Typ : Entity_Id) is
5892 B_Typ : constant Entity_Id := Base_Type (Typ);
5893 L : constant Node_Id := Left_Opnd (N);
5894 R : constant Node_Id := Right_Opnd (N);
5896 begin
5897 -- We do the resolution using the base type, because intermediate values
5898 -- in expressions always are of the base type, not a subtype of it.
5900 Resolve (L, B_Typ);
5901 Resolve (R, Standard_Natural);
5903 Check_Unset_Reference (L);
5904 Check_Unset_Reference (R);
5906 Set_Etype (N, B_Typ);
5907 Generate_Operator_Reference (N, B_Typ);
5908 Eval_Shift (N);
5909 end Resolve_Shift;
5911 ---------------------------
5912 -- Resolve_Short_Circuit --
5913 ---------------------------
5915 procedure Resolve_Short_Circuit (N : Node_Id; Typ : Entity_Id) is
5916 B_Typ : constant Entity_Id := Base_Type (Typ);
5917 L : constant Node_Id := Left_Opnd (N);
5918 R : constant Node_Id := Right_Opnd (N);
5920 begin
5921 Resolve (L, B_Typ);
5922 Resolve (R, B_Typ);
5924 Check_Unset_Reference (L);
5925 Check_Unset_Reference (R);
5927 Set_Etype (N, B_Typ);
5928 Eval_Short_Circuit (N);
5929 end Resolve_Short_Circuit;
5931 -------------------
5932 -- Resolve_Slice --
5933 -------------------
5935 procedure Resolve_Slice (N : Node_Id; Typ : Entity_Id) is
5936 Name : constant Node_Id := Prefix (N);
5937 Drange : constant Node_Id := Discrete_Range (N);
5938 Array_Type : Entity_Id := Empty;
5939 Index : Node_Id;
5941 begin
5942 if Is_Overloaded (Name) then
5944 -- Use the context type to select the prefix that yields the
5945 -- correct array type.
5947 declare
5948 I : Interp_Index;
5949 I1 : Interp_Index := 0;
5950 It : Interp;
5951 P : constant Node_Id := Prefix (N);
5952 Found : Boolean := False;
5954 begin
5955 Get_First_Interp (P, I, It);
5957 while Present (It.Typ) loop
5959 if (Is_Array_Type (It.Typ)
5960 and then Covers (Typ, It.Typ))
5961 or else (Is_Access_Type (It.Typ)
5962 and then Is_Array_Type (Designated_Type (It.Typ))
5963 and then Covers (Typ, Designated_Type (It.Typ)))
5964 then
5965 if Found then
5966 It := Disambiguate (P, I1, I, Any_Type);
5968 if It = No_Interp then
5969 Error_Msg_N ("ambiguous prefix for slicing", N);
5970 Set_Etype (N, Typ);
5971 return;
5972 else
5973 Found := True;
5974 Array_Type := It.Typ;
5975 I1 := I;
5976 end if;
5977 else
5978 Found := True;
5979 Array_Type := It.Typ;
5980 I1 := I;
5981 end if;
5982 end if;
5984 Get_Next_Interp (I, It);
5985 end loop;
5986 end;
5988 else
5989 Array_Type := Etype (Name);
5990 end if;
5992 Resolve (Name, Array_Type);
5994 if Is_Access_Type (Array_Type) then
5995 Apply_Access_Check (N);
5996 Array_Type := Designated_Type (Array_Type);
5998 -- If the prefix is an access to an unconstrained array, we must
5999 -- use the actual subtype of the object to perform the index checks.
6000 -- The object denoted by the prefix is implicit in the node, so we
6001 -- build an explicit representation for it in order to compute the
6002 -- actual subtype.
6004 if not Is_Constrained (Array_Type) then
6005 Remove_Side_Effects (Prefix (N));
6007 declare
6008 Obj : constant Node_Id :=
6009 Make_Explicit_Dereference (Sloc (N),
6010 Prefix => New_Copy_Tree (Prefix (N)));
6011 begin
6012 Set_Etype (Obj, Array_Type);
6013 Set_Parent (Obj, Parent (N));
6014 Array_Type := Get_Actual_Subtype (Obj);
6015 end;
6016 end if;
6018 elsif Is_Entity_Name (Name)
6019 or else (Nkind (Name) = N_Function_Call
6020 and then not Is_Constrained (Etype (Name)))
6021 then
6022 Array_Type := Get_Actual_Subtype (Name);
6023 end if;
6025 -- If name was overloaded, set slice type correctly now
6027 Set_Etype (N, Array_Type);
6029 -- If the range is specified by a subtype mark, no resolution
6030 -- is necessary. Else resolve the bounds, and apply needed checks.
6032 if not Is_Entity_Name (Drange) then
6033 Index := First_Index (Array_Type);
6034 Resolve (Drange, Base_Type (Etype (Index)));
6036 if Nkind (Drange) = N_Range then
6037 Apply_Range_Check (Drange, Etype (Index));
6038 end if;
6039 end if;
6041 Set_Slice_Subtype (N);
6042 Eval_Slice (N);
6043 end Resolve_Slice;
6045 ----------------------------
6046 -- Resolve_String_Literal --
6047 ----------------------------
6049 procedure Resolve_String_Literal (N : Node_Id; Typ : Entity_Id) is
6050 C_Typ : constant Entity_Id := Component_Type (Typ);
6051 R_Typ : constant Entity_Id := Root_Type (C_Typ);
6052 Loc : constant Source_Ptr := Sloc (N);
6053 Str : constant String_Id := Strval (N);
6054 Strlen : constant Nat := String_Length (Str);
6055 Subtype_Id : Entity_Id;
6056 Need_Check : Boolean;
6058 begin
6059 -- For a string appearing in a concatenation, defer creation of the
6060 -- string_literal_subtype until the end of the resolution of the
6061 -- concatenation, because the literal may be constant-folded away.
6062 -- This is a useful optimization for long concatenation expressions.
6064 -- If the string is an aggregate built for a single character (which
6065 -- happens in a non-static context) or a is null string to which special
6066 -- checks may apply, we build the subtype. Wide strings must also get
6067 -- a string subtype if they come from a one character aggregate. Strings
6068 -- generated by attributes might be static, but it is often hard to
6069 -- determine whether the enclosing context is static, so we generate
6070 -- subtypes for them as well, thus losing some rarer optimizations ???
6071 -- Same for strings that come from a static conversion.
6073 Need_Check :=
6074 (Strlen = 0 and then Typ /= Standard_String)
6075 or else Nkind (Parent (N)) /= N_Op_Concat
6076 or else (N /= Left_Opnd (Parent (N))
6077 and then N /= Right_Opnd (Parent (N)))
6078 or else ((Typ = Standard_Wide_String
6079 or else Typ = Standard_Wide_Wide_String)
6080 and then Nkind (Original_Node (N)) /= N_String_Literal);
6082 -- If the resolving type is itself a string literal subtype, we
6083 -- can just reuse it, since there is no point in creating another.
6085 if Ekind (Typ) = E_String_Literal_Subtype then
6086 Subtype_Id := Typ;
6088 elsif Nkind (Parent (N)) = N_Op_Concat
6089 and then not Need_Check
6090 and then Nkind (Original_Node (N)) /= N_Character_Literal
6091 and then Nkind (Original_Node (N)) /= N_Attribute_Reference
6092 and then Nkind (Original_Node (N)) /= N_Qualified_Expression
6093 and then Nkind (Original_Node (N)) /= N_Type_Conversion
6094 then
6095 Subtype_Id := Typ;
6097 -- Otherwise we must create a string literal subtype. Note that the
6098 -- whole idea of string literal subtypes is simply to avoid the need
6099 -- for building a full fledged array subtype for each literal.
6100 else
6101 Set_String_Literal_Subtype (N, Typ);
6102 Subtype_Id := Etype (N);
6103 end if;
6105 if Nkind (Parent (N)) /= N_Op_Concat
6106 or else Need_Check
6107 then
6108 Set_Etype (N, Subtype_Id);
6109 Eval_String_Literal (N);
6110 end if;
6112 if Is_Limited_Composite (Typ)
6113 or else Is_Private_Composite (Typ)
6114 then
6115 Error_Msg_N ("string literal not available for private array", N);
6116 Set_Etype (N, Any_Type);
6117 return;
6118 end if;
6120 -- The validity of a null string has been checked in the
6121 -- call to Eval_String_Literal.
6123 if Strlen = 0 then
6124 return;
6126 -- Always accept string literal with component type Any_Character,
6127 -- which occurs in error situations and in comparisons of literals,
6128 -- both of which should accept all literals.
6130 elsif R_Typ = Any_Character then
6131 return;
6133 -- If the type is bit-packed, then we always tranform the string
6134 -- literal into a full fledged aggregate.
6136 elsif Is_Bit_Packed_Array (Typ) then
6137 null;
6139 -- Deal with cases of Wide_Wide_String, Wide_String, and String
6141 else
6142 -- For Standard.Wide_Wide_String, or any other type whose component
6143 -- type is Standard.Wide_Wide_Character, we know that all the
6144 -- characters in the string must be acceptable, since the parser
6145 -- accepted the characters as valid character literals.
6147 if R_Typ = Standard_Wide_Wide_Character then
6148 null;
6150 -- For the case of Standard.String, or any other type whose
6151 -- component type is Standard.Character, we must make sure that
6152 -- there are no wide characters in the string, i.e. that it is
6153 -- entirely composed of characters in range of type Character.
6155 -- If the string literal is the result of a static concatenation,
6156 -- the test has already been performed on the components, and need
6157 -- not be repeated.
6159 elsif R_Typ = Standard_Character
6160 and then Nkind (Original_Node (N)) /= N_Op_Concat
6161 then
6162 for J in 1 .. Strlen loop
6163 if not In_Character_Range (Get_String_Char (Str, J)) then
6165 -- If we are out of range, post error. This is one of the
6166 -- very few places that we place the flag in the middle of
6167 -- a token, right under the offending wide character.
6169 Error_Msg
6170 ("literal out of range of type Standard.Character",
6171 Source_Ptr (Int (Loc) + J));
6172 return;
6173 end if;
6174 end loop;
6176 -- For the case of Standard.Wide_String, or any other type whose
6177 -- component type is Standard.Wide_Character, we must make sure that
6178 -- there are no wide characters in the string, i.e. that it is
6179 -- entirely composed of characters in range of type Wide_Character.
6181 -- If the string literal is the result of a static concatenation,
6182 -- the test has already been performed on the components, and need
6183 -- not be repeated.
6185 elsif R_Typ = Standard_Wide_Character
6186 and then Nkind (Original_Node (N)) /= N_Op_Concat
6187 then
6188 for J in 1 .. Strlen loop
6189 if not In_Wide_Character_Range (Get_String_Char (Str, J)) then
6191 -- If we are out of range, post error. This is one of the
6192 -- very few places that we place the flag in the middle of
6193 -- a token, right under the offending wide character.
6195 -- This is not quite right, because characters in general
6196 -- will take more than one character position ???
6198 Error_Msg
6199 ("literal out of range of type Standard.Wide_Character",
6200 Source_Ptr (Int (Loc) + J));
6201 return;
6202 end if;
6203 end loop;
6205 -- If the root type is not a standard character, then we will convert
6206 -- the string into an aggregate and will let the aggregate code do
6207 -- the checking. Standard Wide_Wide_Character is also OK here.
6209 else
6210 null;
6211 end if;
6213 -- See if the component type of the array corresponding to the
6214 -- string has compile time known bounds. If yes we can directly
6215 -- check whether the evaluation of the string will raise constraint
6216 -- error. Otherwise we need to transform the string literal into
6217 -- the corresponding character aggregate and let the aggregate
6218 -- code do the checking.
6220 if R_Typ = Standard_Character
6221 or else R_Typ = Standard_Wide_Character
6222 or else R_Typ = Standard_Wide_Wide_Character
6223 then
6224 -- Check for the case of full range, where we are definitely OK
6226 if Component_Type (Typ) = Base_Type (Component_Type (Typ)) then
6227 return;
6228 end if;
6230 -- Here the range is not the complete base type range, so check
6232 declare
6233 Comp_Typ_Lo : constant Node_Id :=
6234 Type_Low_Bound (Component_Type (Typ));
6235 Comp_Typ_Hi : constant Node_Id :=
6236 Type_High_Bound (Component_Type (Typ));
6238 Char_Val : Uint;
6240 begin
6241 if Compile_Time_Known_Value (Comp_Typ_Lo)
6242 and then Compile_Time_Known_Value (Comp_Typ_Hi)
6243 then
6244 for J in 1 .. Strlen loop
6245 Char_Val := UI_From_Int (Int (Get_String_Char (Str, J)));
6247 if Char_Val < Expr_Value (Comp_Typ_Lo)
6248 or else Char_Val > Expr_Value (Comp_Typ_Hi)
6249 then
6250 Apply_Compile_Time_Constraint_Error
6251 (N, "character out of range?", CE_Range_Check_Failed,
6252 Loc => Source_Ptr (Int (Loc) + J));
6253 end if;
6254 end loop;
6256 return;
6257 end if;
6258 end;
6259 end if;
6260 end if;
6262 -- If we got here we meed to transform the string literal into the
6263 -- equivalent qualified positional array aggregate. This is rather
6264 -- heavy artillery for this situation, but it is hard work to avoid.
6266 declare
6267 Lits : constant List_Id := New_List;
6268 P : Source_Ptr := Loc + 1;
6269 C : Char_Code;
6271 begin
6272 -- Build the character literals, we give them source locations
6273 -- that correspond to the string positions, which is a bit tricky
6274 -- given the possible presence of wide character escape sequences.
6276 for J in 1 .. Strlen loop
6277 C := Get_String_Char (Str, J);
6278 Set_Character_Literal_Name (C);
6280 Append_To (Lits,
6281 Make_Character_Literal (P,
6282 Chars => Name_Find,
6283 Char_Literal_Value => UI_From_CC (C)));
6285 if In_Character_Range (C) then
6286 P := P + 1;
6288 -- Should we have a call to Skip_Wide here ???
6289 -- ??? else
6290 -- Skip_Wide (P);
6292 end if;
6293 end loop;
6295 Rewrite (N,
6296 Make_Qualified_Expression (Loc,
6297 Subtype_Mark => New_Reference_To (Typ, Loc),
6298 Expression =>
6299 Make_Aggregate (Loc, Expressions => Lits)));
6301 Analyze_And_Resolve (N, Typ);
6302 end;
6303 end Resolve_String_Literal;
6305 -----------------------------
6306 -- Resolve_Subprogram_Info --
6307 -----------------------------
6309 procedure Resolve_Subprogram_Info (N : Node_Id; Typ : Entity_Id) is
6310 begin
6311 Set_Etype (N, Typ);
6312 end Resolve_Subprogram_Info;
6314 -----------------------------
6315 -- Resolve_Type_Conversion --
6316 -----------------------------
6318 procedure Resolve_Type_Conversion (N : Node_Id; Typ : Entity_Id) is
6319 Target_Type : constant Entity_Id := Etype (N);
6320 Conv_OK : constant Boolean := Conversion_OK (N);
6321 Operand : Node_Id;
6322 Opnd_Type : Entity_Id;
6323 Rop : Node_Id;
6324 Orig_N : Node_Id;
6325 Orig_T : Node_Id;
6327 begin
6328 Operand := Expression (N);
6330 if not Conv_OK
6331 and then not Valid_Conversion (N, Target_Type, Operand)
6332 then
6333 return;
6334 end if;
6336 if Etype (Operand) = Any_Fixed then
6338 -- Mixed-mode operation involving a literal. Context must be a fixed
6339 -- type which is applied to the literal subsequently.
6341 if Is_Fixed_Point_Type (Typ) then
6342 Set_Etype (Operand, Universal_Real);
6344 elsif Is_Numeric_Type (Typ)
6345 and then (Nkind (Operand) = N_Op_Multiply
6346 or else Nkind (Operand) = N_Op_Divide)
6347 and then (Etype (Right_Opnd (Operand)) = Universal_Real
6348 or else Etype (Left_Opnd (Operand)) = Universal_Real)
6349 then
6350 if Unique_Fixed_Point_Type (N) = Any_Type then
6351 return; -- expression is ambiguous.
6352 else
6353 -- If nothing else, the available fixed type is Duration.
6355 Set_Etype (Operand, Standard_Duration);
6356 end if;
6358 -- Resolve the real operand with largest available precision.
6360 if Etype (Right_Opnd (Operand)) = Universal_Real then
6361 Rop := New_Copy_Tree (Right_Opnd (Operand));
6362 else
6363 Rop := New_Copy_Tree (Left_Opnd (Operand));
6364 end if;
6366 Resolve (Rop, Standard_Long_Long_Float);
6368 -- If the operand is a literal (it could be a non-static and
6369 -- illegal exponentiation) check whether the use of Duration
6370 -- is potentially inaccurate.
6372 if Nkind (Rop) = N_Real_Literal
6373 and then Realval (Rop) /= Ureal_0
6374 and then abs (Realval (Rop)) < Delta_Value (Standard_Duration)
6375 then
6376 Error_Msg_N ("universal real operand can only be interpreted?",
6377 Rop);
6378 Error_Msg_N ("\as Duration, and will lose precision?", Rop);
6379 end if;
6381 elsif Is_Numeric_Type (Typ)
6382 and then Nkind (Operand) in N_Op
6383 and then Unique_Fixed_Point_Type (N) /= Any_Type
6384 then
6385 Set_Etype (Operand, Standard_Duration);
6387 else
6388 Error_Msg_N ("invalid context for mixed mode operation", N);
6389 Set_Etype (Operand, Any_Type);
6390 return;
6391 end if;
6392 end if;
6394 Opnd_Type := Etype (Operand);
6395 Resolve (Operand);
6397 -- Note: we do the Eval_Type_Conversion call before applying the
6398 -- required checks for a subtype conversion. This is important,
6399 -- since both are prepared under certain circumstances to change
6400 -- the type conversion to a constraint error node, but in the case
6401 -- of Eval_Type_Conversion this may reflect an illegality in the
6402 -- static case, and we would miss the illegality (getting only a
6403 -- warning message), if we applied the type conversion checks first.
6405 Eval_Type_Conversion (N);
6407 -- If after evaluation, we still have a type conversion, then we
6408 -- may need to apply checks required for a subtype conversion.
6410 -- Skip these type conversion checks if universal fixed operands
6411 -- operands involved, since range checks are handled separately for
6412 -- these cases (in the appropriate Expand routines in unit Exp_Fixd).
6414 if Nkind (N) = N_Type_Conversion
6415 and then not Is_Generic_Type (Root_Type (Target_Type))
6416 and then Target_Type /= Universal_Fixed
6417 and then Opnd_Type /= Universal_Fixed
6418 then
6419 Apply_Type_Conversion_Checks (N);
6420 end if;
6422 -- Issue warning for conversion of simple object to its own type
6423 -- We have to test the original nodes, since they may have been
6424 -- rewritten by various optimizations.
6426 Orig_N := Original_Node (N);
6428 if Warn_On_Redundant_Constructs
6429 and then Comes_From_Source (Orig_N)
6430 and then Nkind (Orig_N) = N_Type_Conversion
6431 and then not In_Instance
6432 then
6433 Orig_N := Original_Node (Expression (Orig_N));
6434 Orig_T := Target_Type;
6436 -- If the node is part of a larger expression, the Target_Type
6437 -- may not be the original type of the node if the context is a
6438 -- condition. Recover original type to see if conversion is needed.
6440 if Is_Boolean_Type (Orig_T)
6441 and then Nkind (Parent (N)) in N_Op
6442 then
6443 Orig_T := Etype (Parent (N));
6444 end if;
6446 if Is_Entity_Name (Orig_N)
6447 and then Etype (Entity (Orig_N)) = Orig_T
6448 then
6449 Error_Msg_NE
6450 ("?useless conversion, & has this type", N, Entity (Orig_N));
6451 end if;
6452 end if;
6453 end Resolve_Type_Conversion;
6455 ----------------------
6456 -- Resolve_Unary_Op --
6457 ----------------------
6459 procedure Resolve_Unary_Op (N : Node_Id; Typ : Entity_Id) is
6460 B_Typ : constant Entity_Id := Base_Type (Typ);
6461 R : constant Node_Id := Right_Opnd (N);
6462 OK : Boolean;
6463 Lo : Uint;
6464 Hi : Uint;
6466 begin
6467 -- Generate warning for expressions like abs (x mod 2)
6469 if Warn_On_Redundant_Constructs
6470 and then Nkind (N) = N_Op_Abs
6471 then
6472 Determine_Range (Right_Opnd (N), OK, Lo, Hi);
6474 if OK and then Hi >= Lo and then Lo >= 0 then
6475 Error_Msg_N
6476 ("?abs applied to known non-negative value has no effect", N);
6477 end if;
6478 end if;
6480 -- Generate warning for expressions like -5 mod 3
6482 if Paren_Count (N) = 0
6483 and then Nkind (N) = N_Op_Minus
6484 and then Nkind (Right_Opnd (N)) = N_Op_Mod
6485 and then Comes_From_Source (N)
6486 then
6487 Error_Msg_N
6488 ("?unary minus expression should be parenthesized here", N);
6489 end if;
6491 if Comes_From_Source (N)
6492 and then Ekind (Entity (N)) = E_Function
6493 and then Is_Imported (Entity (N))
6494 and then Is_Intrinsic_Subprogram (Entity (N))
6495 then
6496 Resolve_Intrinsic_Unary_Operator (N, Typ);
6497 return;
6498 end if;
6500 if Etype (R) = Universal_Integer
6501 or else Etype (R) = Universal_Real
6502 then
6503 Check_For_Visible_Operator (N, B_Typ);
6504 end if;
6506 Set_Etype (N, B_Typ);
6507 Resolve (R, B_Typ);
6509 Check_Unset_Reference (R);
6510 Generate_Operator_Reference (N, B_Typ);
6511 Eval_Unary_Op (N);
6513 -- Set overflow checking bit. Much cleverer code needed here eventually
6514 -- and perhaps the Resolve routines should be separated for the various
6515 -- arithmetic operations, since they will need different processing ???
6517 if Nkind (N) in N_Op then
6518 if not Overflow_Checks_Suppressed (Etype (N)) then
6519 Enable_Overflow_Check (N);
6520 end if;
6521 end if;
6522 end Resolve_Unary_Op;
6524 ----------------------------------
6525 -- Resolve_Unchecked_Expression --
6526 ----------------------------------
6528 procedure Resolve_Unchecked_Expression
6529 (N : Node_Id;
6530 Typ : Entity_Id)
6532 begin
6533 Resolve (Expression (N), Typ, Suppress => All_Checks);
6534 Set_Etype (N, Typ);
6535 end Resolve_Unchecked_Expression;
6537 ---------------------------------------
6538 -- Resolve_Unchecked_Type_Conversion --
6539 ---------------------------------------
6541 procedure Resolve_Unchecked_Type_Conversion
6542 (N : Node_Id;
6543 Typ : Entity_Id)
6545 pragma Warnings (Off, Typ);
6547 Operand : constant Node_Id := Expression (N);
6548 Opnd_Type : constant Entity_Id := Etype (Operand);
6550 begin
6551 -- Resolve operand using its own type.
6553 Resolve (Operand, Opnd_Type);
6554 Eval_Unchecked_Conversion (N);
6556 end Resolve_Unchecked_Type_Conversion;
6558 ------------------------------
6559 -- Rewrite_Operator_As_Call --
6560 ------------------------------
6562 procedure Rewrite_Operator_As_Call (N : Node_Id; Nam : Entity_Id) is
6563 Loc : constant Source_Ptr := Sloc (N);
6564 Actuals : constant List_Id := New_List;
6565 New_N : Node_Id;
6567 begin
6568 if Nkind (N) in N_Binary_Op then
6569 Append (Left_Opnd (N), Actuals);
6570 end if;
6572 Append (Right_Opnd (N), Actuals);
6574 New_N :=
6575 Make_Function_Call (Sloc => Loc,
6576 Name => New_Occurrence_Of (Nam, Loc),
6577 Parameter_Associations => Actuals);
6579 Preserve_Comes_From_Source (New_N, N);
6580 Preserve_Comes_From_Source (Name (New_N), N);
6581 Rewrite (N, New_N);
6582 Set_Etype (N, Etype (Nam));
6583 end Rewrite_Operator_As_Call;
6585 ------------------------------
6586 -- Rewrite_Renamed_Operator --
6587 ------------------------------
6589 procedure Rewrite_Renamed_Operator
6590 (N : Node_Id;
6591 Op : Entity_Id;
6592 Typ : Entity_Id)
6594 Nam : constant Name_Id := Chars (Op);
6595 Is_Binary : constant Boolean := Nkind (N) in N_Binary_Op;
6596 Op_Node : Node_Id;
6598 begin
6599 -- Rewrite the operator node using the real operator, not its
6600 -- renaming. Exclude user-defined intrinsic operations of the same
6601 -- name, which are treated separately and rewritten as calls.
6603 if Ekind (Op) /= E_Function
6604 or else Chars (N) /= Nam
6605 then
6606 Op_Node := New_Node (Operator_Kind (Nam, Is_Binary), Sloc (N));
6607 Set_Chars (Op_Node, Nam);
6608 Set_Etype (Op_Node, Etype (N));
6609 Set_Entity (Op_Node, Op);
6610 Set_Right_Opnd (Op_Node, Right_Opnd (N));
6612 -- Indicate that both the original entity and its renaming
6613 -- are referenced at this point.
6615 Generate_Reference (Entity (N), N);
6616 Generate_Reference (Op, N);
6618 if Is_Binary then
6619 Set_Left_Opnd (Op_Node, Left_Opnd (N));
6620 end if;
6622 Rewrite (N, Op_Node);
6624 -- If the context type is private, add the appropriate conversions
6625 -- so that the operator is applied to the full view. This is done
6626 -- in the routines that resolve intrinsic operators,
6628 if Is_Intrinsic_Subprogram (Op)
6629 and then Is_Private_Type (Typ)
6630 then
6631 case Nkind (N) is
6632 when N_Op_Add | N_Op_Subtract | N_Op_Multiply | N_Op_Divide |
6633 N_Op_Expon | N_Op_Mod | N_Op_Rem =>
6634 Resolve_Intrinsic_Operator (N, Typ);
6636 when N_Op_Plus | N_Op_Minus | N_Op_Abs =>
6637 Resolve_Intrinsic_Unary_Operator (N, Typ);
6639 when others =>
6640 Resolve (N, Typ);
6641 end case;
6642 end if;
6644 elsif Ekind (Op) = E_Function
6645 and then Is_Intrinsic_Subprogram (Op)
6646 then
6647 -- Operator renames a user-defined operator of the same name. Use
6648 -- the original operator in the node, which is the one that gigi
6649 -- knows about.
6651 Set_Entity (N, Op);
6652 Set_Is_Overloaded (N, False);
6653 end if;
6654 end Rewrite_Renamed_Operator;
6656 -----------------------
6657 -- Set_Slice_Subtype --
6658 -----------------------
6660 -- Build an implicit subtype declaration to represent the type delivered
6661 -- by the slice. This is an abbreviated version of an array subtype. We
6662 -- define an index subtype for the slice, using either the subtype name
6663 -- or the discrete range of the slice. To be consistent with index usage
6664 -- elsewhere, we create a list header to hold the single index. This list
6665 -- is not otherwise attached to the syntax tree.
6667 procedure Set_Slice_Subtype (N : Node_Id) is
6668 Loc : constant Source_Ptr := Sloc (N);
6669 Index_List : constant List_Id := New_List;
6670 Index : Node_Id;
6671 Index_Subtype : Entity_Id;
6672 Index_Type : Entity_Id;
6673 Slice_Subtype : Entity_Id;
6674 Drange : constant Node_Id := Discrete_Range (N);
6676 begin
6677 if Is_Entity_Name (Drange) then
6678 Index_Subtype := Entity (Drange);
6680 else
6681 -- We force the evaluation of a range. This is definitely needed in
6682 -- the renamed case, and seems safer to do unconditionally. Note in
6683 -- any case that since we will create and insert an Itype referring
6684 -- to this range, we must make sure any side effect removal actions
6685 -- are inserted before the Itype definition.
6687 if Nkind (Drange) = N_Range then
6688 Force_Evaluation (Low_Bound (Drange));
6689 Force_Evaluation (High_Bound (Drange));
6690 end if;
6692 Index_Type := Base_Type (Etype (Drange));
6694 Index_Subtype := Create_Itype (Subtype_Kind (Ekind (Index_Type)), N);
6696 Set_Scalar_Range (Index_Subtype, Drange);
6697 Set_Etype (Index_Subtype, Index_Type);
6698 Set_Size_Info (Index_Subtype, Index_Type);
6699 Set_RM_Size (Index_Subtype, RM_Size (Index_Type));
6700 end if;
6702 Slice_Subtype := Create_Itype (E_Array_Subtype, N);
6704 Index := New_Occurrence_Of (Index_Subtype, Loc);
6705 Set_Etype (Index, Index_Subtype);
6706 Append (Index, Index_List);
6708 Set_First_Index (Slice_Subtype, Index);
6709 Set_Etype (Slice_Subtype, Base_Type (Etype (N)));
6710 Set_Is_Constrained (Slice_Subtype, True);
6711 Init_Size_Align (Slice_Subtype);
6713 Check_Compile_Time_Size (Slice_Subtype);
6715 -- The Etype of the existing Slice node is reset to this slice
6716 -- subtype. Its bounds are obtained from its first index.
6718 Set_Etype (N, Slice_Subtype);
6720 -- In the packed case, this must be immediately frozen
6722 -- Couldn't we always freeze here??? and if we did, then the above
6723 -- call to Check_Compile_Time_Size could be eliminated, which would
6724 -- be nice, because then that routine could be made private to Freeze.
6726 if Is_Packed (Slice_Subtype) and not In_Default_Expression then
6727 Freeze_Itype (Slice_Subtype, N);
6728 end if;
6730 end Set_Slice_Subtype;
6732 --------------------------------
6733 -- Set_String_Literal_Subtype --
6734 --------------------------------
6736 procedure Set_String_Literal_Subtype (N : Node_Id; Typ : Entity_Id) is
6737 Subtype_Id : Entity_Id;
6739 begin
6740 if Nkind (N) /= N_String_Literal then
6741 return;
6742 else
6743 Subtype_Id := Create_Itype (E_String_Literal_Subtype, N);
6744 end if;
6746 Set_String_Literal_Length (Subtype_Id, UI_From_Int
6747 (String_Length (Strval (N))));
6748 Set_Etype (Subtype_Id, Base_Type (Typ));
6749 Set_Is_Constrained (Subtype_Id);
6751 -- The low bound is set from the low bound of the corresponding
6752 -- index type. Note that we do not store the high bound in the
6753 -- string literal subtype, but it can be deduced if necssary
6754 -- from the length and the low bound.
6756 Set_String_Literal_Low_Bound
6757 (Subtype_Id, Type_Low_Bound (Etype (First_Index (Typ))));
6759 Set_Etype (N, Subtype_Id);
6760 end Set_String_Literal_Subtype;
6762 -----------------------------
6763 -- Unique_Fixed_Point_Type --
6764 -----------------------------
6766 function Unique_Fixed_Point_Type (N : Node_Id) return Entity_Id is
6767 T1 : Entity_Id := Empty;
6768 T2 : Entity_Id;
6769 Item : Node_Id;
6770 Scop : Entity_Id;
6772 procedure Fixed_Point_Error;
6773 -- If true ambiguity, give details.
6775 procedure Fixed_Point_Error is
6776 begin
6777 Error_Msg_N ("ambiguous universal_fixed_expression", N);
6778 Error_Msg_NE ("\possible interpretation as}", N, T1);
6779 Error_Msg_NE ("\possible interpretation as}", N, T2);
6780 end Fixed_Point_Error;
6782 begin
6783 -- The operations on Duration are visible, so Duration is always a
6784 -- possible interpretation.
6786 T1 := Standard_Duration;
6788 -- Look for fixed-point types in enclosing scopes.
6790 Scop := Current_Scope;
6791 while Scop /= Standard_Standard loop
6792 T2 := First_Entity (Scop);
6794 while Present (T2) loop
6795 if Is_Fixed_Point_Type (T2)
6796 and then Current_Entity (T2) = T2
6797 and then Scope (Base_Type (T2)) = Scop
6798 then
6799 if Present (T1) then
6800 Fixed_Point_Error;
6801 return Any_Type;
6802 else
6803 T1 := T2;
6804 end if;
6805 end if;
6807 Next_Entity (T2);
6808 end loop;
6810 Scop := Scope (Scop);
6811 end loop;
6813 -- Look for visible fixed type declarations in the context.
6815 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
6816 while Present (Item) loop
6817 if Nkind (Item) = N_With_Clause then
6818 Scop := Entity (Name (Item));
6819 T2 := First_Entity (Scop);
6821 while Present (T2) loop
6822 if Is_Fixed_Point_Type (T2)
6823 and then Scope (Base_Type (T2)) = Scop
6824 and then (Is_Potentially_Use_Visible (T2)
6825 or else In_Use (T2))
6826 then
6827 if Present (T1) then
6828 Fixed_Point_Error;
6829 return Any_Type;
6830 else
6831 T1 := T2;
6832 end if;
6833 end if;
6835 Next_Entity (T2);
6836 end loop;
6837 end if;
6839 Next (Item);
6840 end loop;
6842 if Nkind (N) = N_Real_Literal then
6843 Error_Msg_NE ("real literal interpreted as }?", N, T1);
6845 else
6846 Error_Msg_NE ("universal_fixed expression interpreted as }?", N, T1);
6847 end if;
6849 return T1;
6850 end Unique_Fixed_Point_Type;
6852 ----------------------
6853 -- Valid_Conversion --
6854 ----------------------
6856 function Valid_Conversion
6857 (N : Node_Id;
6858 Target : Entity_Id;
6859 Operand : Node_Id) return Boolean
6861 Target_Type : constant Entity_Id := Base_Type (Target);
6862 Opnd_Type : Entity_Id := Etype (Operand);
6864 function Conversion_Check
6865 (Valid : Boolean;
6866 Msg : String) return Boolean;
6867 -- Little routine to post Msg if Valid is False, returns Valid value
6869 function Valid_Tagged_Conversion
6870 (Target_Type : Entity_Id;
6871 Opnd_Type : Entity_Id) return Boolean;
6872 -- Specifically test for validity of tagged conversions
6874 ----------------------
6875 -- Conversion_Check --
6876 ----------------------
6878 function Conversion_Check
6879 (Valid : Boolean;
6880 Msg : String) return Boolean
6882 begin
6883 if not Valid then
6884 Error_Msg_N (Msg, Operand);
6885 end if;
6887 return Valid;
6888 end Conversion_Check;
6890 -----------------------------
6891 -- Valid_Tagged_Conversion --
6892 -----------------------------
6894 function Valid_Tagged_Conversion
6895 (Target_Type : Entity_Id;
6896 Opnd_Type : Entity_Id) return Boolean
6898 begin
6899 -- Upward conversions are allowed (RM 4.6(22)).
6901 if Covers (Target_Type, Opnd_Type)
6902 or else Is_Ancestor (Target_Type, Opnd_Type)
6903 then
6904 return True;
6906 -- Downward conversion are allowed if the operand is
6907 -- is class-wide (RM 4.6(23)).
6909 elsif Is_Class_Wide_Type (Opnd_Type)
6910 and then Covers (Opnd_Type, Target_Type)
6911 then
6912 return True;
6914 elsif Covers (Opnd_Type, Target_Type)
6915 or else Is_Ancestor (Opnd_Type, Target_Type)
6916 then
6917 return
6918 Conversion_Check (False,
6919 "downward conversion of tagged objects not allowed");
6920 else
6921 Error_Msg_NE
6922 ("invalid tagged conversion, not compatible with}",
6923 N, First_Subtype (Opnd_Type));
6924 return False;
6925 end if;
6926 end Valid_Tagged_Conversion;
6928 -- Start of processing for Valid_Conversion
6930 begin
6931 Check_Parameterless_Call (Operand);
6933 if Is_Overloaded (Operand) then
6934 declare
6935 I : Interp_Index;
6936 I1 : Interp_Index;
6937 It : Interp;
6938 It1 : Interp;
6939 N1 : Entity_Id;
6941 begin
6942 -- Remove procedure calls, which syntactically cannot appear
6943 -- in this context, but which cannot be removed by type checking,
6944 -- because the context does not impose a type.
6946 Get_First_Interp (Operand, I, It);
6948 while Present (It.Typ) loop
6950 if It.Typ = Standard_Void_Type then
6951 Remove_Interp (I);
6952 end if;
6954 Get_Next_Interp (I, It);
6955 end loop;
6957 Get_First_Interp (Operand, I, It);
6958 I1 := I;
6959 It1 := It;
6961 if No (It.Typ) then
6962 Error_Msg_N ("illegal operand in conversion", Operand);
6963 return False;
6964 end if;
6966 Get_Next_Interp (I, It);
6968 if Present (It.Typ) then
6969 N1 := It1.Nam;
6970 It1 := Disambiguate (Operand, I1, I, Any_Type);
6972 if It1 = No_Interp then
6973 Error_Msg_N ("ambiguous operand in conversion", Operand);
6975 Error_Msg_Sloc := Sloc (It.Nam);
6976 Error_Msg_N ("possible interpretation#!", Operand);
6978 Error_Msg_Sloc := Sloc (N1);
6979 Error_Msg_N ("possible interpretation#!", Operand);
6981 return False;
6982 end if;
6983 end if;
6985 Set_Etype (Operand, It1.Typ);
6986 Opnd_Type := It1.Typ;
6987 end;
6988 end if;
6990 if Chars (Current_Scope) = Name_Unchecked_Conversion then
6992 -- This check is dubious, what if there were a user defined
6993 -- scope whose name was Unchecked_Conversion ???
6995 return True;
6997 elsif Is_Numeric_Type (Target_Type) then
6998 if Opnd_Type = Universal_Fixed then
6999 return True;
7001 elsif (In_Instance or else In_Inlined_Body)
7002 and then not Comes_From_Source (N)
7003 then
7004 return True;
7006 else
7007 return Conversion_Check (Is_Numeric_Type (Opnd_Type),
7008 "illegal operand for numeric conversion");
7009 end if;
7011 elsif Is_Array_Type (Target_Type) then
7012 if not Is_Array_Type (Opnd_Type)
7013 or else Opnd_Type = Any_Composite
7014 or else Opnd_Type = Any_String
7015 then
7016 Error_Msg_N
7017 ("illegal operand for array conversion", Operand);
7018 return False;
7020 elsif Number_Dimensions (Target_Type) /=
7021 Number_Dimensions (Opnd_Type)
7022 then
7023 Error_Msg_N
7024 ("incompatible number of dimensions for conversion", Operand);
7025 return False;
7027 else
7028 declare
7029 Target_Index : Node_Id := First_Index (Target_Type);
7030 Opnd_Index : Node_Id := First_Index (Opnd_Type);
7032 Target_Index_Type : Entity_Id;
7033 Opnd_Index_Type : Entity_Id;
7035 Target_Comp_Type : constant Entity_Id :=
7036 Component_Type (Target_Type);
7037 Opnd_Comp_Type : constant Entity_Id :=
7038 Component_Type (Opnd_Type);
7040 begin
7041 while Present (Target_Index) and then Present (Opnd_Index) loop
7042 Target_Index_Type := Etype (Target_Index);
7043 Opnd_Index_Type := Etype (Opnd_Index);
7045 if not (Is_Integer_Type (Target_Index_Type)
7046 and then Is_Integer_Type (Opnd_Index_Type))
7047 and then (Root_Type (Target_Index_Type)
7048 /= Root_Type (Opnd_Index_Type))
7049 then
7050 Error_Msg_N
7051 ("incompatible index types for array conversion",
7052 Operand);
7053 return False;
7054 end if;
7056 Next_Index (Target_Index);
7057 Next_Index (Opnd_Index);
7058 end loop;
7060 if Base_Type (Target_Comp_Type) /=
7061 Base_Type (Opnd_Comp_Type)
7062 then
7063 Error_Msg_N
7064 ("incompatible component types for array conversion",
7065 Operand);
7066 return False;
7068 elsif
7069 Is_Constrained (Target_Comp_Type)
7070 /= Is_Constrained (Opnd_Comp_Type)
7071 or else not Subtypes_Statically_Match
7072 (Target_Comp_Type, Opnd_Comp_Type)
7073 then
7074 Error_Msg_N
7075 ("component subtypes must statically match", Operand);
7076 return False;
7078 end if;
7079 end;
7080 end if;
7082 return True;
7084 elsif (Ekind (Target_Type) = E_General_Access_Type
7085 or else Ekind (Target_Type) = E_Anonymous_Access_Type)
7086 and then
7087 Conversion_Check
7088 (Is_Access_Type (Opnd_Type)
7089 and then Ekind (Opnd_Type) /=
7090 E_Access_Subprogram_Type
7091 and then Ekind (Opnd_Type) /=
7092 E_Access_Protected_Subprogram_Type,
7093 "must be an access-to-object type")
7094 then
7095 if Is_Access_Constant (Opnd_Type)
7096 and then not Is_Access_Constant (Target_Type)
7097 then
7098 Error_Msg_N
7099 ("access-to-constant operand type not allowed", Operand);
7100 return False;
7101 end if;
7103 -- Check the static accessibility rule of 4.6(17). Note that
7104 -- the check is not enforced when within an instance body, since
7105 -- the RM requires such cases to be caught at run time.
7107 if Ekind (Target_Type) /= E_Anonymous_Access_Type then
7108 if Type_Access_Level (Opnd_Type)
7109 > Type_Access_Level (Target_Type)
7110 then
7111 -- In an instance, this is a run-time check, but one we
7112 -- know will fail, so generate an appropriate warning.
7113 -- The raise will be generated by Expand_N_Type_Conversion.
7115 if In_Instance_Body then
7116 Error_Msg_N
7117 ("?cannot convert local pointer to non-local access type",
7118 Operand);
7119 Error_Msg_N
7120 ("?Program_Error will be raised at run time", Operand);
7122 else
7123 Error_Msg_N
7124 ("cannot convert local pointer to non-local access type",
7125 Operand);
7126 return False;
7127 end if;
7129 elsif Ekind (Opnd_Type) = E_Anonymous_Access_Type then
7131 -- When the operand is a selected access discriminant
7132 -- the check needs to be made against the level of the
7133 -- object denoted by the prefix of the selected name.
7134 -- (Object_Access_Level handles checking the prefix
7135 -- of the operand for this case.)
7137 if Nkind (Operand) = N_Selected_Component
7138 and then Object_Access_Level (Operand)
7139 > Type_Access_Level (Target_Type)
7140 then
7141 -- In an instance, this is a run-time check, but one we
7142 -- know will fail, so generate an appropriate warning.
7143 -- The raise will be generated by Expand_N_Type_Conversion.
7145 if In_Instance_Body then
7146 Error_Msg_N
7147 ("?cannot convert access discriminant to non-local" &
7148 " access type", Operand);
7149 Error_Msg_N
7150 ("?Program_Error will be raised at run time", Operand);
7152 else
7153 Error_Msg_N
7154 ("cannot convert access discriminant to non-local" &
7155 " access type", Operand);
7156 return False;
7157 end if;
7158 end if;
7160 -- The case of a reference to an access discriminant
7161 -- from within a type declaration (which will appear
7162 -- as a discriminal) is always illegal because the
7163 -- level of the discriminant is considered to be
7164 -- deeper than any (namable) access type.
7166 if Is_Entity_Name (Operand)
7167 and then (Ekind (Entity (Operand)) = E_In_Parameter
7168 or else Ekind (Entity (Operand)) = E_Constant)
7169 and then Present (Discriminal_Link (Entity (Operand)))
7170 then
7171 Error_Msg_N
7172 ("discriminant has deeper accessibility level than target",
7173 Operand);
7174 return False;
7175 end if;
7176 end if;
7177 end if;
7179 declare
7180 Target : constant Entity_Id := Designated_Type (Target_Type);
7181 Opnd : constant Entity_Id := Designated_Type (Opnd_Type);
7183 begin
7184 if Is_Tagged_Type (Target) then
7185 return Valid_Tagged_Conversion (Target, Opnd);
7187 else
7188 if Base_Type (Target) /= Base_Type (Opnd) then
7189 Error_Msg_NE
7190 ("target designated type not compatible with }",
7191 N, Base_Type (Opnd));
7192 return False;
7194 -- Ada 2005 AI-384: legality rule is symmetric in both
7195 -- designated types. The conversion is legal (with possible
7196 -- constraint check) if either designated type is
7197 -- unconstrained.
7199 elsif Subtypes_Statically_Match (Target, Opnd)
7200 or else
7201 (Has_Discriminants (Target)
7202 and then
7203 (not Is_Constrained (Opnd)
7204 or else not Is_Constrained (Target)))
7205 then
7206 return True;
7208 else
7209 Error_Msg_NE
7210 ("target designated subtype not compatible with }",
7211 N, Opnd);
7212 return False;
7213 end if;
7214 end if;
7215 end;
7217 elsif (Ekind (Target_Type) = E_Access_Subprogram_Type
7218 or else
7219 Ekind (Target_Type) = E_Anonymous_Access_Subprogram_Type)
7220 and then Conversion_Check
7221 (Ekind (Base_Type (Opnd_Type)) = E_Access_Subprogram_Type,
7222 "illegal operand for access subprogram conversion")
7223 then
7224 -- Check that the designated types are subtype conformant
7226 if not Subtype_Conformant (Designated_Type (Opnd_Type),
7227 Designated_Type (Target_Type))
7228 then
7229 Error_Msg_N
7230 ("operand type is not subtype conformant with target type",
7231 Operand);
7232 end if;
7234 -- Check the static accessibility rule of 4.6(20)
7236 if Type_Access_Level (Opnd_Type) >
7237 Type_Access_Level (Target_Type)
7238 then
7239 Error_Msg_N
7240 ("operand type has deeper accessibility level than target",
7241 Operand);
7243 -- Check that if the operand type is declared in a generic body,
7244 -- then the target type must be declared within that same body
7245 -- (enforces last sentence of 4.6(20)).
7247 elsif Present (Enclosing_Generic_Body (Opnd_Type)) then
7248 declare
7249 O_Gen : constant Node_Id :=
7250 Enclosing_Generic_Body (Opnd_Type);
7252 T_Gen : Node_Id :=
7253 Enclosing_Generic_Body (Target_Type);
7255 begin
7256 while Present (T_Gen) and then T_Gen /= O_Gen loop
7257 T_Gen := Enclosing_Generic_Body (T_Gen);
7258 end loop;
7260 if T_Gen /= O_Gen then
7261 Error_Msg_N
7262 ("target type must be declared in same generic body"
7263 & " as operand type", N);
7264 end if;
7265 end;
7266 end if;
7268 return True;
7270 elsif Is_Remote_Access_To_Subprogram_Type (Target_Type)
7271 and then Is_Remote_Access_To_Subprogram_Type (Opnd_Type)
7272 then
7273 -- It is valid to convert from one RAS type to another provided
7274 -- that their specification statically match.
7276 Check_Subtype_Conformant
7277 (New_Id =>
7278 Designated_Type (Corresponding_Remote_Type (Target_Type)),
7279 Old_Id =>
7280 Designated_Type (Corresponding_Remote_Type (Opnd_Type)),
7281 Err_Loc =>
7283 return True;
7285 elsif Is_Tagged_Type (Target_Type) then
7286 return Valid_Tagged_Conversion (Target_Type, Opnd_Type);
7288 -- Types derived from the same root type are convertible.
7290 elsif Root_Type (Target_Type) = Root_Type (Opnd_Type) then
7291 return True;
7293 -- In an instance, there may be inconsistent views of the same
7294 -- type, or types derived from the same type.
7296 elsif In_Instance
7297 and then Underlying_Type (Target_Type) = Underlying_Type (Opnd_Type)
7298 then
7299 return True;
7301 -- Special check for common access type error case
7303 elsif Ekind (Target_Type) = E_Access_Type
7304 and then Is_Access_Type (Opnd_Type)
7305 then
7306 Error_Msg_N ("target type must be general access type!", N);
7307 Error_Msg_NE ("add ALL to }!", N, Target_Type);
7309 return False;
7311 else
7312 Error_Msg_NE ("invalid conversion, not compatible with }",
7313 N, Opnd_Type);
7315 return False;
7316 end if;
7317 end Valid_Conversion;
7319 end Sem_Res;