* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / sem_ch4.adb
blob1f8eb2155c382a254fc001467639b48b2bb63f7d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ C H 4 --
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Util; use Exp_Util;
33 with Fname; use Fname;
34 with Itypes; use Itypes;
35 with Lib; use Lib;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
40 with Opt; use Opt;
41 with Output; use Output;
42 with Restrict; use Restrict;
43 with Rident; use Rident;
44 with Sem; use Sem;
45 with Sem_Cat; use Sem_Cat;
46 with Sem_Ch3; use Sem_Ch3;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Dist; use Sem_Dist;
49 with Sem_Eval; use Sem_Eval;
50 with Sem_Res; use Sem_Res;
51 with Sem_Util; use Sem_Util;
52 with Sem_Type; use Sem_Type;
53 with Stand; use Stand;
54 with Sinfo; use Sinfo;
55 with Snames; use Snames;
56 with Tbuild; use Tbuild;
58 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
60 package body Sem_Ch4 is
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 procedure Analyze_Expression (N : Node_Id);
67 -- For expressions that are not names, this is just a call to analyze.
68 -- If the expression is a name, it may be a call to a parameterless
69 -- function, and if so must be converted into an explicit call node
70 -- and analyzed as such. This deproceduring must be done during the first
71 -- pass of overload resolution, because otherwise a procedure call with
72 -- overloaded actuals may fail to resolve. See 4327-001 for an example.
74 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
75 -- Analyze a call of the form "+"(x, y), etc. The prefix of the call
76 -- is an operator name or an expanded name whose selector is an operator
77 -- name, and one possible interpretation is as a predefined operator.
79 procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
80 -- If the prefix of a selected_component is overloaded, the proper
81 -- interpretation that yields a record type with the proper selector
82 -- name must be selected.
84 procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
85 -- Procedure to analyze a user defined binary operator, which is resolved
86 -- like a function, but instead of a list of actuals it is presented
87 -- with the left and right operands of an operator node.
89 procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
90 -- Procedure to analyze a user defined unary operator, which is resolved
91 -- like a function, but instead of a list of actuals, it is presented with
92 -- the operand of the operator node.
94 procedure Ambiguous_Operands (N : Node_Id);
95 -- for equality, membership, and comparison operators with overloaded
96 -- arguments, list possible interpretations.
98 procedure Analyze_One_Call
99 (N : Node_Id;
100 Nam : Entity_Id;
101 Report : Boolean;
102 Success : out Boolean;
103 Skip_First : Boolean := False);
104 -- Check one interpretation of an overloaded subprogram name for
105 -- compatibility with the types of the actuals in a call. If there is a
106 -- single interpretation which does not match, post error if Report is
107 -- set to True.
109 -- Nam is the entity that provides the formals against which the actuals
110 -- are checked. Nam is either the name of a subprogram, or the internal
111 -- subprogram type constructed for an access_to_subprogram. If the actuals
112 -- are compatible with Nam, then Nam is added to the list of candidate
113 -- interpretations for N, and Success is set to True.
115 -- The flag Skip_First is used when analyzing a call that was rewritten
116 -- from object notation. In this case the first actual may have to receive
117 -- an explicit dereference, depending on the first formal of the operation
118 -- being called. The caller will have verified that the object is legal
119 -- for the call. If the remaining parameters match, the first parameter
120 -- will rewritten as a dereference if needed, prior to completing analysis.
122 procedure Check_Misspelled_Selector
123 (Prefix : Entity_Id;
124 Sel : Node_Id);
125 -- Give possible misspelling diagnostic if Sel is likely to be
126 -- a misspelling of one of the selectors of the Prefix.
127 -- This is called by Analyze_Selected_Component after producing
128 -- an invalid selector error message.
130 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
131 -- Verify that type T is declared in scope S. Used to find intepretations
132 -- for operators given by expanded names. This is abstracted as a separate
133 -- function to handle extensions to System, where S is System, but T is
134 -- declared in the extension.
136 procedure Find_Arithmetic_Types
137 (L, R : Node_Id;
138 Op_Id : Entity_Id;
139 N : Node_Id);
140 -- L and R are the operands of an arithmetic operator. Find
141 -- consistent pairs of interpretations for L and R that have a
142 -- numeric type consistent with the semantics of the operator.
144 procedure Find_Comparison_Types
145 (L, R : Node_Id;
146 Op_Id : Entity_Id;
147 N : Node_Id);
148 -- L and R are operands of a comparison operator. Find consistent
149 -- pairs of interpretations for L and R.
151 procedure Find_Concatenation_Types
152 (L, R : Node_Id;
153 Op_Id : Entity_Id;
154 N : Node_Id);
155 -- For the four varieties of concatenation
157 procedure Find_Equality_Types
158 (L, R : Node_Id;
159 Op_Id : Entity_Id;
160 N : Node_Id);
161 -- Ditto for equality operators
163 procedure Find_Boolean_Types
164 (L, R : Node_Id;
165 Op_Id : Entity_Id;
166 N : Node_Id);
167 -- Ditto for binary logical operations
169 procedure Find_Negation_Types
170 (R : Node_Id;
171 Op_Id : Entity_Id;
172 N : Node_Id);
173 -- Find consistent interpretation for operand of negation operator
175 procedure Find_Non_Universal_Interpretations
176 (N : Node_Id;
177 R : Node_Id;
178 Op_Id : Entity_Id;
179 T1 : Entity_Id);
180 -- For equality and comparison operators, the result is always boolean,
181 -- and the legality of the operation is determined from the visibility
182 -- of the operand types. If one of the operands has a universal interpre-
183 -- tation, the legality check uses some compatible non-universal
184 -- interpretation of the other operand. N can be an operator node, or
185 -- a function call whose name is an operator designator.
187 procedure Find_Unary_Types
188 (R : Node_Id;
189 Op_Id : Entity_Id;
190 N : Node_Id);
191 -- Unary arithmetic types: plus, minus, abs
193 procedure Check_Arithmetic_Pair
194 (T1, T2 : Entity_Id;
195 Op_Id : Entity_Id;
196 N : Node_Id);
197 -- Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
198 -- types for left and right operand. Determine whether they constitute
199 -- a valid pair for the given operator, and record the corresponding
200 -- interpretation of the operator node. The node N may be an operator
201 -- node (the usual case) or a function call whose prefix is an operator
202 -- designator. In both cases Op_Id is the operator name itself.
204 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
205 -- Give detailed information on overloaded call where none of the
206 -- interpretations match. N is the call node, Nam the designator for
207 -- the overloaded entity being called.
209 function Junk_Operand (N : Node_Id) return Boolean;
210 -- Test for an operand that is an inappropriate entity (e.g. a package
211 -- name or a label). If so, issue an error message and return True. If
212 -- the operand is not an inappropriate entity kind, return False.
214 procedure Operator_Check (N : Node_Id);
215 -- Verify that an operator has received some valid interpretation. If none
216 -- was found, determine whether a use clause would make the operation
217 -- legal. The variable Candidate_Type (defined in Sem_Type) is set for
218 -- every type compatible with the operator, even if the operator for the
219 -- type is not directly visible. The routine uses this type to emit a more
220 -- informative message.
222 procedure Process_Implicit_Dereference_Prefix
223 (E : Entity_Id;
224 P : Node_Id);
225 -- Called when P is the prefix of an implicit dereference, denoting an
226 -- object E. If in semantics only mode (-gnatc or generic), record that is
227 -- a reference to E. Normally, such a reference is generated only when the
228 -- implicit dereference is expanded into an explicit one. E may be empty,
229 -- in which case this procedure does nothing.
231 procedure Remove_Abstract_Operations (N : Node_Id);
232 -- Ada 2005: implementation of AI-310. An abstract non-dispatching
233 -- operation is not a candidate interpretation.
235 function Try_Indexed_Call
236 (N : Node_Id;
237 Nam : Entity_Id;
238 Typ : Entity_Id) return Boolean;
239 -- If a function has defaults for all its actuals, a call to it may
240 -- in fact be an indexing on the result of the call. Try_Indexed_Call
241 -- attempts the interpretation as an indexing, prior to analysis as
242 -- a call. If both are possible, the node is overloaded with both
243 -- interpretations (same symbol but two different types).
245 function Try_Indirect_Call
246 (N : Node_Id;
247 Nam : Entity_Id;
248 Typ : Entity_Id) return Boolean;
249 -- Similarly, a function F that needs no actuals can return an access
250 -- to a subprogram, and the call F (X) interpreted as F.all (X). In
251 -- this case the call may be overloaded with both interpretations.
253 function Try_Object_Operation (N : Node_Id) return Boolean;
254 -- Ada 2005 (AI-252): Give support to the object operation notation
256 ------------------------
257 -- Ambiguous_Operands --
258 ------------------------
260 procedure Ambiguous_Operands (N : Node_Id) is
261 procedure List_Operand_Interps (Opnd : Node_Id);
263 --------------------------
264 -- List_Operand_Interps --
265 --------------------------
267 procedure List_Operand_Interps (Opnd : Node_Id) is
268 Nam : Node_Id;
269 Err : Node_Id := N;
271 begin
272 if Is_Overloaded (Opnd) then
273 if Nkind (Opnd) in N_Op then
274 Nam := Opnd;
275 elsif Nkind (Opnd) = N_Function_Call then
276 Nam := Name (Opnd);
277 else
278 return;
279 end if;
281 else
282 return;
283 end if;
285 if Opnd = Left_Opnd (N) then
286 Error_Msg_N
287 ("\left operand has the following interpretations", N);
288 else
289 Error_Msg_N
290 ("\right operand has the following interpretations", N);
291 Err := Opnd;
292 end if;
294 List_Interps (Nam, Err);
295 end List_Operand_Interps;
297 -- Start of processing for Ambiguous_Operands
299 begin
300 if Nkind (N) = N_In
301 or else Nkind (N) = N_Not_In
302 then
303 Error_Msg_N ("ambiguous operands for membership", N);
305 elsif Nkind (N) = N_Op_Eq
306 or else Nkind (N) = N_Op_Ne
307 then
308 Error_Msg_N ("ambiguous operands for equality", N);
310 else
311 Error_Msg_N ("ambiguous operands for comparison", N);
312 end if;
314 if All_Errors_Mode then
315 List_Operand_Interps (Left_Opnd (N));
316 List_Operand_Interps (Right_Opnd (N));
317 else
318 Error_Msg_N ("\use -gnatf switch for details", N);
319 end if;
320 end Ambiguous_Operands;
322 -----------------------
323 -- Analyze_Aggregate --
324 -----------------------
326 -- Most of the analysis of Aggregates requires that the type be known,
327 -- and is therefore put off until resolution.
329 procedure Analyze_Aggregate (N : Node_Id) is
330 begin
331 if No (Etype (N)) then
332 Set_Etype (N, Any_Composite);
333 end if;
334 end Analyze_Aggregate;
336 -----------------------
337 -- Analyze_Allocator --
338 -----------------------
340 procedure Analyze_Allocator (N : Node_Id) is
341 Loc : constant Source_Ptr := Sloc (N);
342 Sav_Errs : constant Nat := Serious_Errors_Detected;
343 E : Node_Id := Expression (N);
344 Acc_Type : Entity_Id;
345 Type_Id : Entity_Id;
347 begin
348 Check_Restriction (No_Allocators, N);
350 if Nkind (E) = N_Qualified_Expression then
351 Acc_Type := Create_Itype (E_Allocator_Type, N);
352 Set_Etype (Acc_Type, Acc_Type);
353 Init_Size_Align (Acc_Type);
354 Find_Type (Subtype_Mark (E));
355 Type_Id := Entity (Subtype_Mark (E));
356 Check_Fully_Declared (Type_Id, N);
357 Set_Directly_Designated_Type (Acc_Type, Type_Id);
359 if Is_Limited_Type (Type_Id)
360 and then Comes_From_Source (N)
361 and then not In_Instance_Body
362 then
363 -- Ada 2005 (AI-287): Do not post an error if the expression
364 -- corresponds to a limited aggregate. Limited aggregates
365 -- are checked in sem_aggr in a per-component manner
366 -- (compare with handling of Get_Value subprogram).
368 if Ada_Version >= Ada_05
369 and then Nkind (Expression (E)) = N_Aggregate
370 then
371 null;
372 else
373 Error_Msg_N ("initialization not allowed for limited types", N);
374 Explain_Limited_Type (Type_Id, N);
375 end if;
376 end if;
378 Analyze_And_Resolve (Expression (E), Type_Id);
380 -- A qualified expression requires an exact match of the type,
381 -- class-wide matching is not allowed.
383 if Is_Class_Wide_Type (Type_Id)
384 and then Base_Type (Etype (Expression (E))) /= Base_Type (Type_Id)
385 then
386 Wrong_Type (Expression (E), Type_Id);
387 end if;
389 Check_Non_Static_Context (Expression (E));
391 -- We don't analyze the qualified expression itself because it's
392 -- part of the allocator
394 Set_Etype (E, Type_Id);
396 -- Case where no qualified expression is present
398 else
399 declare
400 Def_Id : Entity_Id;
401 Base_Typ : Entity_Id;
403 begin
404 -- If the allocator includes a N_Subtype_Indication then a
405 -- constraint is present, otherwise the node is a subtype mark.
406 -- Introduce an explicit subtype declaration into the tree
407 -- defining some anonymous subtype and rewrite the allocator to
408 -- use this subtype rather than the subtype indication.
410 -- It is important to introduce the explicit subtype declaration
411 -- so that the bounds of the subtype indication are attached to
412 -- the tree in case the allocator is inside a generic unit.
414 if Nkind (E) = N_Subtype_Indication then
416 -- A constraint is only allowed for a composite type in Ada
417 -- 95. In Ada 83, a constraint is also allowed for an
418 -- access-to-composite type, but the constraint is ignored.
420 Find_Type (Subtype_Mark (E));
421 Base_Typ := Entity (Subtype_Mark (E));
423 if Is_Elementary_Type (Base_Typ) then
424 if not (Ada_Version = Ada_83
425 and then Is_Access_Type (Base_Typ))
426 then
427 Error_Msg_N ("constraint not allowed here", E);
429 if Nkind (Constraint (E))
430 = N_Index_Or_Discriminant_Constraint
431 then
432 Error_Msg_N
433 ("\if qualified expression was meant, " &
434 "use apostrophe", Constraint (E));
435 end if;
436 end if;
438 -- Get rid of the bogus constraint:
440 Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
441 Analyze_Allocator (N);
442 return;
444 -- Ada 2005, AI-363: if the designated type has a constrained
445 -- partial view, it cannot receive a discriminant constraint,
446 -- and the allocated object is unconstrained.
448 elsif Ada_Version >= Ada_05
449 and then Has_Constrained_Partial_View (Base_Typ)
450 then
451 Error_Msg_N
452 ("constraint no allowed when type " &
453 "has a constrained partial view", Constraint (E));
454 end if;
456 if Expander_Active then
457 Def_Id :=
458 Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
460 Insert_Action (E,
461 Make_Subtype_Declaration (Loc,
462 Defining_Identifier => Def_Id,
463 Subtype_Indication => Relocate_Node (E)));
465 if Sav_Errs /= Serious_Errors_Detected
466 and then Nkind (Constraint (E))
467 = N_Index_Or_Discriminant_Constraint
468 then
469 Error_Msg_N
470 ("if qualified expression was meant, " &
471 "use apostrophe!", Constraint (E));
472 end if;
474 E := New_Occurrence_Of (Def_Id, Loc);
475 Rewrite (Expression (N), E);
476 end if;
477 end if;
479 Type_Id := Process_Subtype (E, N);
480 Acc_Type := Create_Itype (E_Allocator_Type, N);
481 Set_Etype (Acc_Type, Acc_Type);
482 Init_Size_Align (Acc_Type);
483 Set_Directly_Designated_Type (Acc_Type, Type_Id);
484 Check_Fully_Declared (Type_Id, N);
486 -- Ada 2005 (AI-231)
488 if Can_Never_Be_Null (Type_Id) then
489 Error_Msg_N ("(Ada 2005) qualified expression required",
490 Expression (N));
491 end if;
493 -- Check restriction against dynamically allocated protected
494 -- objects. Note that when limited aggregates are supported,
495 -- a similar test should be applied to an allocator with a
496 -- qualified expression ???
498 if Is_Protected_Type (Type_Id) then
499 Check_Restriction (No_Protected_Type_Allocators, N);
500 end if;
502 -- Check for missing initialization. Skip this check if we already
503 -- had errors on analyzing the allocator, since in that case these
504 -- are probably cascaded errors
506 if Is_Indefinite_Subtype (Type_Id)
507 and then Serious_Errors_Detected = Sav_Errs
508 then
509 if Is_Class_Wide_Type (Type_Id) then
510 Error_Msg_N
511 ("initialization required in class-wide allocation", N);
512 else
513 Error_Msg_N
514 ("initialization required in unconstrained allocation", N);
515 end if;
516 end if;
517 end;
518 end if;
520 if Is_Abstract (Type_Id) then
521 Error_Msg_N ("cannot allocate abstract object", E);
522 end if;
524 if Has_Task (Designated_Type (Acc_Type)) then
525 Check_Restriction (No_Tasking, N);
526 Check_Restriction (Max_Tasks, N);
527 Check_Restriction (No_Task_Allocators, N);
528 end if;
530 -- If the No_Streams restriction is set, check that the type of the
531 -- object is not, and does not contain, any subtype derived from
532 -- Ada.Streams.Root_Stream_Type. Note that we guard the call to
533 -- Has_Stream just for efficiency reasons. There is no point in
534 -- spending time on a Has_Stream check if the restriction is not set.
536 if Restrictions.Set (No_Streams) then
537 if Has_Stream (Designated_Type (Acc_Type)) then
538 Check_Restriction (No_Streams, N);
539 end if;
540 end if;
542 Set_Etype (N, Acc_Type);
544 if not Is_Library_Level_Entity (Acc_Type) then
545 Check_Restriction (No_Local_Allocators, N);
546 end if;
548 if Serious_Errors_Detected > Sav_Errs then
549 Set_Error_Posted (N);
550 Set_Etype (N, Any_Type);
551 end if;
552 end Analyze_Allocator;
554 ---------------------------
555 -- Analyze_Arithmetic_Op --
556 ---------------------------
558 procedure Analyze_Arithmetic_Op (N : Node_Id) is
559 L : constant Node_Id := Left_Opnd (N);
560 R : constant Node_Id := Right_Opnd (N);
561 Op_Id : Entity_Id;
563 begin
564 Candidate_Type := Empty;
565 Analyze_Expression (L);
566 Analyze_Expression (R);
568 -- If the entity is already set, the node is the instantiation of
569 -- a generic node with a non-local reference, or was manufactured
570 -- by a call to Make_Op_xxx. In either case the entity is known to
571 -- be valid, and we do not need to collect interpretations, instead
572 -- we just get the single possible interpretation.
574 Op_Id := Entity (N);
576 if Present (Op_Id) then
577 if Ekind (Op_Id) = E_Operator then
579 if (Nkind (N) = N_Op_Divide or else
580 Nkind (N) = N_Op_Mod or else
581 Nkind (N) = N_Op_Multiply or else
582 Nkind (N) = N_Op_Rem)
583 and then Treat_Fixed_As_Integer (N)
584 then
585 null;
586 else
587 Set_Etype (N, Any_Type);
588 Find_Arithmetic_Types (L, R, Op_Id, N);
589 end if;
591 else
592 Set_Etype (N, Any_Type);
593 Add_One_Interp (N, Op_Id, Etype (Op_Id));
594 end if;
596 -- Entity is not already set, so we do need to collect interpretations
598 else
599 Op_Id := Get_Name_Entity_Id (Chars (N));
600 Set_Etype (N, Any_Type);
602 while Present (Op_Id) loop
603 if Ekind (Op_Id) = E_Operator
604 and then Present (Next_Entity (First_Entity (Op_Id)))
605 then
606 Find_Arithmetic_Types (L, R, Op_Id, N);
608 -- The following may seem superfluous, because an operator cannot
609 -- be generic, but this ignores the cleverness of the author of
610 -- ACVC bc1013a.
612 elsif Is_Overloadable (Op_Id) then
613 Analyze_User_Defined_Binary_Op (N, Op_Id);
614 end if;
616 Op_Id := Homonym (Op_Id);
617 end loop;
618 end if;
620 Operator_Check (N);
621 end Analyze_Arithmetic_Op;
623 ------------------
624 -- Analyze_Call --
625 ------------------
627 -- Function, procedure, and entry calls are checked here. The Name in
628 -- the call may be overloaded. The actuals have been analyzed and may
629 -- themselves be overloaded. On exit from this procedure, the node N
630 -- may have zero, one or more interpretations. In the first case an
631 -- error message is produced. In the last case, the node is flagged
632 -- as overloaded and the interpretations are collected in All_Interp.
634 -- If the name is an Access_To_Subprogram, it cannot be overloaded, but
635 -- the type-checking is similar to that of other calls.
637 procedure Analyze_Call (N : Node_Id) is
638 Actuals : constant List_Id := Parameter_Associations (N);
639 Nam : Node_Id := Name (N);
640 X : Interp_Index;
641 It : Interp;
642 Nam_Ent : Entity_Id;
643 Success : Boolean := False;
645 function Name_Denotes_Function return Boolean;
646 -- If the type of the name is an access to subprogram, this may be
647 -- the type of a name, or the return type of the function being called.
648 -- If the name is not an entity then it can denote a protected function.
649 -- Until we distinguish Etype from Return_Type, we must use this
650 -- routine to resolve the meaning of the name in the call.
652 ---------------------------
653 -- Name_Denotes_Function --
654 ---------------------------
656 function Name_Denotes_Function return Boolean is
657 begin
658 if Is_Entity_Name (Nam) then
659 return Ekind (Entity (Nam)) = E_Function;
661 elsif Nkind (Nam) = N_Selected_Component then
662 return Ekind (Entity (Selector_Name (Nam))) = E_Function;
664 else
665 return False;
666 end if;
667 end Name_Denotes_Function;
669 -- Start of processing for Analyze_Call
671 begin
672 -- Initialize the type of the result of the call to the error type,
673 -- which will be reset if the type is successfully resolved.
675 Set_Etype (N, Any_Type);
677 if not Is_Overloaded (Nam) then
679 -- Only one interpretation to check
681 if Ekind (Etype (Nam)) = E_Subprogram_Type then
682 Nam_Ent := Etype (Nam);
684 -- If the prefix is an access_to_subprogram, this may be an indirect
685 -- call. This is the case if the name in the call is not an entity
686 -- name, or if it is a function name in the context of a procedure
687 -- call. In this latter case, we have a call to a parameterless
688 -- function that returns a pointer_to_procedure which is the entity
689 -- being called.
691 elsif Is_Access_Type (Etype (Nam))
692 and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
693 and then
694 (not Name_Denotes_Function
695 or else Nkind (N) = N_Procedure_Call_Statement)
696 then
697 Nam_Ent := Designated_Type (Etype (Nam));
698 Insert_Explicit_Dereference (Nam);
700 -- Selected component case. Simple entry or protected operation,
701 -- where the entry name is given by the selector name.
703 elsif Nkind (Nam) = N_Selected_Component then
704 Nam_Ent := Entity (Selector_Name (Nam));
706 if Ekind (Nam_Ent) /= E_Entry
707 and then Ekind (Nam_Ent) /= E_Entry_Family
708 and then Ekind (Nam_Ent) /= E_Function
709 and then Ekind (Nam_Ent) /= E_Procedure
710 then
711 Error_Msg_N ("name in call is not a callable entity", Nam);
712 Set_Etype (N, Any_Type);
713 return;
714 end if;
716 -- If the name is an Indexed component, it can be a call to a member
717 -- of an entry family. The prefix must be a selected component whose
718 -- selector is the entry. Analyze_Procedure_Call normalizes several
719 -- kinds of call into this form.
721 elsif Nkind (Nam) = N_Indexed_Component then
723 if Nkind (Prefix (Nam)) = N_Selected_Component then
724 Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
725 else
726 Error_Msg_N ("name in call is not a callable entity", Nam);
727 Set_Etype (N, Any_Type);
728 return;
729 end if;
731 elsif not Is_Entity_Name (Nam) then
732 Error_Msg_N ("name in call is not a callable entity", Nam);
733 Set_Etype (N, Any_Type);
734 return;
736 else
737 Nam_Ent := Entity (Nam);
739 -- If no interpretations, give error message
741 if not Is_Overloadable (Nam_Ent) then
742 declare
743 L : constant Boolean := Is_List_Member (N);
744 K : constant Node_Kind := Nkind (Parent (N));
746 begin
747 -- If the node is in a list whose parent is not an
748 -- expression then it must be an attempted procedure call.
750 if L and then K not in N_Subexpr then
751 if Ekind (Entity (Nam)) = E_Generic_Procedure then
752 Error_Msg_NE
753 ("must instantiate generic procedure& before call",
754 Nam, Entity (Nam));
755 else
756 Error_Msg_N
757 ("procedure or entry name expected", Nam);
758 end if;
760 -- Check for tasking cases where only an entry call will do
762 elsif not L
763 and then (K = N_Entry_Call_Alternative
764 or else K = N_Triggering_Alternative)
765 then
766 Error_Msg_N ("entry name expected", Nam);
768 -- Otherwise give general error message
770 else
771 Error_Msg_N ("invalid prefix in call", Nam);
772 end if;
774 return;
775 end;
776 end if;
777 end if;
779 Analyze_One_Call (N, Nam_Ent, True, Success);
781 -- If this is an indirect call, the return type of the access_to
782 -- subprogram may be an incomplete type. At the point of the call,
783 -- use the full type if available, and at the same time update
784 -- the return type of the access_to_subprogram.
786 if Success
787 and then Nkind (Nam) = N_Explicit_Dereference
788 and then Ekind (Etype (N)) = E_Incomplete_Type
789 and then Present (Full_View (Etype (N)))
790 then
791 Set_Etype (N, Full_View (Etype (N)));
792 Set_Etype (Nam_Ent, Etype (N));
793 end if;
795 else
796 -- An overloaded selected component must denote overloaded
797 -- operations of a concurrent type. The interpretations are
798 -- attached to the simple name of those operations.
800 if Nkind (Nam) = N_Selected_Component then
801 Nam := Selector_Name (Nam);
802 end if;
804 Get_First_Interp (Nam, X, It);
806 while Present (It.Nam) loop
807 Nam_Ent := It.Nam;
809 -- Name may be call that returns an access to subprogram, or more
810 -- generally an overloaded expression one of whose interpretations
811 -- yields an access to subprogram. If the name is an entity, we
812 -- do not dereference, because the node is a call that returns
813 -- the access type: note difference between f(x), where the call
814 -- may return an access subprogram type, and f(x)(y), where the
815 -- type returned by the call to f is implicitly dereferenced to
816 -- analyze the outer call.
818 if Is_Access_Type (Nam_Ent) then
819 Nam_Ent := Designated_Type (Nam_Ent);
821 elsif Is_Access_Type (Etype (Nam_Ent))
822 and then not Is_Entity_Name (Nam)
823 and then Ekind (Designated_Type (Etype (Nam_Ent)))
824 = E_Subprogram_Type
825 then
826 Nam_Ent := Designated_Type (Etype (Nam_Ent));
827 end if;
829 Analyze_One_Call (N, Nam_Ent, False, Success);
831 -- If the interpretation succeeds, mark the proper type of the
832 -- prefix (any valid candidate will do). If not, remove the
833 -- candidate interpretation. This only needs to be done for
834 -- overloaded protected operations, for other entities disambi-
835 -- guation is done directly in Resolve.
837 if Success then
838 Set_Etype (Nam, It.Typ);
840 elsif Nkind (Name (N)) = N_Selected_Component
841 or else Nkind (Name (N)) = N_Function_Call
842 then
843 Remove_Interp (X);
844 end if;
846 Get_Next_Interp (X, It);
847 end loop;
849 -- If the name is the result of a function call, it can only
850 -- be a call to a function returning an access to subprogram.
851 -- Insert explicit dereference.
853 if Nkind (Nam) = N_Function_Call then
854 Insert_Explicit_Dereference (Nam);
855 end if;
857 if Etype (N) = Any_Type then
859 -- None of the interpretations is compatible with the actuals
861 Diagnose_Call (N, Nam);
863 -- Special checks for uninstantiated put routines
865 if Nkind (N) = N_Procedure_Call_Statement
866 and then Is_Entity_Name (Nam)
867 and then Chars (Nam) = Name_Put
868 and then List_Length (Actuals) = 1
869 then
870 declare
871 Arg : constant Node_Id := First (Actuals);
872 Typ : Entity_Id;
874 begin
875 if Nkind (Arg) = N_Parameter_Association then
876 Typ := Etype (Explicit_Actual_Parameter (Arg));
877 else
878 Typ := Etype (Arg);
879 end if;
881 if Is_Signed_Integer_Type (Typ) then
882 Error_Msg_N
883 ("possible missing instantiation of " &
884 "'Text_'I'O.'Integer_'I'O!", Nam);
886 elsif Is_Modular_Integer_Type (Typ) then
887 Error_Msg_N
888 ("possible missing instantiation of " &
889 "'Text_'I'O.'Modular_'I'O!", Nam);
891 elsif Is_Floating_Point_Type (Typ) then
892 Error_Msg_N
893 ("possible missing instantiation of " &
894 "'Text_'I'O.'Float_'I'O!", Nam);
896 elsif Is_Ordinary_Fixed_Point_Type (Typ) then
897 Error_Msg_N
898 ("possible missing instantiation of " &
899 "'Text_'I'O.'Fixed_'I'O!", Nam);
901 elsif Is_Decimal_Fixed_Point_Type (Typ) then
902 Error_Msg_N
903 ("possible missing instantiation of " &
904 "'Text_'I'O.'Decimal_'I'O!", Nam);
906 elsif Is_Enumeration_Type (Typ) then
907 Error_Msg_N
908 ("possible missing instantiation of " &
909 "'Text_'I'O.'Enumeration_'I'O!", Nam);
910 end if;
911 end;
912 end if;
914 elsif not Is_Overloaded (N)
915 and then Is_Entity_Name (Nam)
916 then
917 -- Resolution yields a single interpretation. Verify that
918 -- is has the proper capitalization.
920 Set_Entity_With_Style_Check (Nam, Entity (Nam));
921 Generate_Reference (Entity (Nam), Nam);
923 Set_Etype (Nam, Etype (Entity (Nam)));
924 else
925 Remove_Abstract_Operations (N);
926 end if;
928 End_Interp_List;
929 end if;
930 end Analyze_Call;
932 ---------------------------
933 -- Analyze_Comparison_Op --
934 ---------------------------
936 procedure Analyze_Comparison_Op (N : Node_Id) is
937 L : constant Node_Id := Left_Opnd (N);
938 R : constant Node_Id := Right_Opnd (N);
939 Op_Id : Entity_Id := Entity (N);
941 begin
942 Set_Etype (N, Any_Type);
943 Candidate_Type := Empty;
945 Analyze_Expression (L);
946 Analyze_Expression (R);
948 if Present (Op_Id) then
949 if Ekind (Op_Id) = E_Operator then
950 Find_Comparison_Types (L, R, Op_Id, N);
951 else
952 Add_One_Interp (N, Op_Id, Etype (Op_Id));
953 end if;
955 if Is_Overloaded (L) then
956 Set_Etype (L, Intersect_Types (L, R));
957 end if;
959 else
960 Op_Id := Get_Name_Entity_Id (Chars (N));
961 while Present (Op_Id) loop
962 if Ekind (Op_Id) = E_Operator then
963 Find_Comparison_Types (L, R, Op_Id, N);
964 else
965 Analyze_User_Defined_Binary_Op (N, Op_Id);
966 end if;
968 Op_Id := Homonym (Op_Id);
969 end loop;
970 end if;
972 Operator_Check (N);
973 end Analyze_Comparison_Op;
975 ---------------------------
976 -- Analyze_Concatenation --
977 ---------------------------
979 -- If the only one-dimensional array type in scope is String,
980 -- this is the resulting type of the operation. Otherwise there
981 -- will be a concatenation operation defined for each user-defined
982 -- one-dimensional array.
984 procedure Analyze_Concatenation (N : Node_Id) is
985 L : constant Node_Id := Left_Opnd (N);
986 R : constant Node_Id := Right_Opnd (N);
987 Op_Id : Entity_Id := Entity (N);
988 LT : Entity_Id;
989 RT : Entity_Id;
991 begin
992 Set_Etype (N, Any_Type);
993 Candidate_Type := Empty;
995 Analyze_Expression (L);
996 Analyze_Expression (R);
998 -- If the entity is present, the node appears in an instance,
999 -- and denotes a predefined concatenation operation. The resulting
1000 -- type is obtained from the arguments when possible. If the arguments
1001 -- are aggregates, the array type and the concatenation type must be
1002 -- visible.
1004 if Present (Op_Id) then
1005 if Ekind (Op_Id) = E_Operator then
1007 LT := Base_Type (Etype (L));
1008 RT := Base_Type (Etype (R));
1010 if Is_Array_Type (LT)
1011 and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1012 then
1013 Add_One_Interp (N, Op_Id, LT);
1015 elsif Is_Array_Type (RT)
1016 and then LT = Base_Type (Component_Type (RT))
1017 then
1018 Add_One_Interp (N, Op_Id, RT);
1020 -- If one operand is a string type or a user-defined array type,
1021 -- and the other is a literal, result is of the specific type.
1023 elsif
1024 (Root_Type (LT) = Standard_String
1025 or else Scope (LT) /= Standard_Standard)
1026 and then Etype (R) = Any_String
1027 then
1028 Add_One_Interp (N, Op_Id, LT);
1030 elsif
1031 (Root_Type (RT) = Standard_String
1032 or else Scope (RT) /= Standard_Standard)
1033 and then Etype (L) = Any_String
1034 then
1035 Add_One_Interp (N, Op_Id, RT);
1037 elsif not Is_Generic_Type (Etype (Op_Id)) then
1038 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1040 else
1041 -- Type and its operations must be visible
1043 Set_Entity (N, Empty);
1044 Analyze_Concatenation (N);
1045 end if;
1047 else
1048 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1049 end if;
1051 else
1052 Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1053 while Present (Op_Id) loop
1054 if Ekind (Op_Id) = E_Operator then
1056 -- Do not consider operators declared in dead code, they can
1057 -- not be part of the resolution.
1059 if Is_Eliminated (Op_Id) then
1060 null;
1061 else
1062 Find_Concatenation_Types (L, R, Op_Id, N);
1063 end if;
1065 else
1066 Analyze_User_Defined_Binary_Op (N, Op_Id);
1067 end if;
1069 Op_Id := Homonym (Op_Id);
1070 end loop;
1071 end if;
1073 Operator_Check (N);
1074 end Analyze_Concatenation;
1076 ------------------------------------
1077 -- Analyze_Conditional_Expression --
1078 ------------------------------------
1080 procedure Analyze_Conditional_Expression (N : Node_Id) is
1081 Condition : constant Node_Id := First (Expressions (N));
1082 Then_Expr : constant Node_Id := Next (Condition);
1083 Else_Expr : constant Node_Id := Next (Then_Expr);
1084 begin
1085 Analyze_Expression (Condition);
1086 Analyze_Expression (Then_Expr);
1087 Analyze_Expression (Else_Expr);
1088 Set_Etype (N, Etype (Then_Expr));
1089 end Analyze_Conditional_Expression;
1091 -------------------------
1092 -- Analyze_Equality_Op --
1093 -------------------------
1095 procedure Analyze_Equality_Op (N : Node_Id) is
1096 Loc : constant Source_Ptr := Sloc (N);
1097 L : constant Node_Id := Left_Opnd (N);
1098 R : constant Node_Id := Right_Opnd (N);
1099 Op_Id : Entity_Id;
1101 begin
1102 Set_Etype (N, Any_Type);
1103 Candidate_Type := Empty;
1105 Analyze_Expression (L);
1106 Analyze_Expression (R);
1108 -- If the entity is set, the node is a generic instance with a non-local
1109 -- reference to the predefined operator or to a user-defined function.
1110 -- It can also be an inequality that is expanded into the negation of a
1111 -- call to a user-defined equality operator.
1113 -- For the predefined case, the result is Boolean, regardless of the
1114 -- type of the operands. The operands may even be limited, if they are
1115 -- generic actuals. If they are overloaded, label the left argument with
1116 -- the common type that must be present, or with the type of the formal
1117 -- of the user-defined function.
1119 if Present (Entity (N)) then
1120 Op_Id := Entity (N);
1122 if Ekind (Op_Id) = E_Operator then
1123 Add_One_Interp (N, Op_Id, Standard_Boolean);
1124 else
1125 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1126 end if;
1128 if Is_Overloaded (L) then
1129 if Ekind (Op_Id) = E_Operator then
1130 Set_Etype (L, Intersect_Types (L, R));
1131 else
1132 Set_Etype (L, Etype (First_Formal (Op_Id)));
1133 end if;
1134 end if;
1136 else
1137 Op_Id := Get_Name_Entity_Id (Chars (N));
1138 while Present (Op_Id) loop
1139 if Ekind (Op_Id) = E_Operator then
1140 Find_Equality_Types (L, R, Op_Id, N);
1141 else
1142 Analyze_User_Defined_Binary_Op (N, Op_Id);
1143 end if;
1145 Op_Id := Homonym (Op_Id);
1146 end loop;
1147 end if;
1149 -- If there was no match, and the operator is inequality, this may
1150 -- be a case where inequality has not been made explicit, as for
1151 -- tagged types. Analyze the node as the negation of an equality
1152 -- operation. This cannot be done earlier, because before analysis
1153 -- we cannot rule out the presence of an explicit inequality.
1155 if Etype (N) = Any_Type
1156 and then Nkind (N) = N_Op_Ne
1157 then
1158 Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1160 while Present (Op_Id) loop
1162 if Ekind (Op_Id) = E_Operator then
1163 Find_Equality_Types (L, R, Op_Id, N);
1164 else
1165 Analyze_User_Defined_Binary_Op (N, Op_Id);
1166 end if;
1168 Op_Id := Homonym (Op_Id);
1169 end loop;
1171 if Etype (N) /= Any_Type then
1172 Op_Id := Entity (N);
1174 Rewrite (N,
1175 Make_Op_Not (Loc,
1176 Right_Opnd =>
1177 Make_Op_Eq (Loc,
1178 Left_Opnd => Relocate_Node (Left_Opnd (N)),
1179 Right_Opnd => Relocate_Node (Right_Opnd (N)))));
1181 Set_Entity (Right_Opnd (N), Op_Id);
1182 Analyze (N);
1183 end if;
1184 end if;
1186 Operator_Check (N);
1187 end Analyze_Equality_Op;
1189 ----------------------------------
1190 -- Analyze_Explicit_Dereference --
1191 ----------------------------------
1193 procedure Analyze_Explicit_Dereference (N : Node_Id) is
1194 Loc : constant Source_Ptr := Sloc (N);
1195 P : constant Node_Id := Prefix (N);
1196 T : Entity_Id;
1197 I : Interp_Index;
1198 It : Interp;
1199 New_N : Node_Id;
1201 function Is_Function_Type return Boolean;
1202 -- Check whether node may be interpreted as an implicit function call
1204 ----------------------
1205 -- Is_Function_Type --
1206 ----------------------
1208 function Is_Function_Type return Boolean is
1209 I : Interp_Index;
1210 It : Interp;
1212 begin
1213 if not Is_Overloaded (N) then
1214 return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1215 and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1217 else
1218 Get_First_Interp (N, I, It);
1220 while Present (It.Nam) loop
1221 if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1222 or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1223 then
1224 return False;
1225 end if;
1227 Get_Next_Interp (I, It);
1228 end loop;
1230 return True;
1231 end if;
1232 end Is_Function_Type;
1234 -- Start of processing for Analyze_Explicit_Dereference
1236 begin
1237 Analyze (P);
1238 Set_Etype (N, Any_Type);
1240 -- Test for remote access to subprogram type, and if so return
1241 -- after rewriting the original tree.
1243 if Remote_AST_E_Dereference (P) then
1244 return;
1245 end if;
1247 -- Normal processing for other than remote access to subprogram type
1249 if not Is_Overloaded (P) then
1250 if Is_Access_Type (Etype (P)) then
1252 -- Set the Etype. We need to go thru Is_For_Access_Subtypes
1253 -- to avoid other problems caused by the Private_Subtype
1254 -- and it is safe to go to the Base_Type because this is the
1255 -- same as converting the access value to its Base_Type.
1257 declare
1258 DT : Entity_Id := Designated_Type (Etype (P));
1260 begin
1261 if Ekind (DT) = E_Private_Subtype
1262 and then Is_For_Access_Subtype (DT)
1263 then
1264 DT := Base_Type (DT);
1265 end if;
1267 Set_Etype (N, DT);
1268 end;
1270 elsif Etype (P) /= Any_Type then
1271 Error_Msg_N ("prefix of dereference must be an access type", N);
1272 return;
1273 end if;
1275 else
1276 Get_First_Interp (P, I, It);
1278 while Present (It.Nam) loop
1279 T := It.Typ;
1281 if Is_Access_Type (T) then
1282 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1283 end if;
1285 Get_Next_Interp (I, It);
1286 end loop;
1288 -- Error if no interpretation of the prefix has an access type
1290 if Etype (N) = Any_Type then
1291 Error_Msg_N
1292 ("access type required in prefix of explicit dereference", P);
1293 Set_Etype (N, Any_Type);
1294 return;
1295 end if;
1296 end if;
1298 if Is_Function_Type
1299 and then Nkind (Parent (N)) /= N_Indexed_Component
1301 and then (Nkind (Parent (N)) /= N_Function_Call
1302 or else N /= Name (Parent (N)))
1304 and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1305 or else N /= Name (Parent (N)))
1307 and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1308 and then (Nkind (Parent (N)) /= N_Attribute_Reference
1309 or else
1310 (Attribute_Name (Parent (N)) /= Name_Address
1311 and then
1312 Attribute_Name (Parent (N)) /= Name_Access))
1313 then
1314 -- Name is a function call with no actuals, in a context that
1315 -- requires deproceduring (including as an actual in an enclosing
1316 -- function or procedure call). There are some pathological cases
1317 -- where the prefix might include functions that return access to
1318 -- subprograms and others that return a regular type. Disambiguation
1319 -- of those has to take place in Resolve.
1320 -- See e.g. 7117-014 and E317-001.
1322 New_N :=
1323 Make_Function_Call (Loc,
1324 Name => Make_Explicit_Dereference (Loc, P),
1325 Parameter_Associations => New_List);
1327 -- If the prefix is overloaded, remove operations that have formals,
1328 -- we know that this is a parameterless call.
1330 if Is_Overloaded (P) then
1331 Get_First_Interp (P, I, It);
1332 while Present (It.Nam) loop
1333 T := It.Typ;
1335 if No (First_Formal (Base_Type (Designated_Type (T)))) then
1336 Set_Etype (P, T);
1337 else
1338 Remove_Interp (I);
1339 end if;
1341 Get_Next_Interp (I, It);
1342 end loop;
1343 end if;
1345 Rewrite (N, New_N);
1346 Analyze (N);
1348 elsif not Is_Function_Type
1349 and then Is_Overloaded (N)
1350 then
1351 -- The prefix may include access to subprograms and other access
1352 -- types. If the context selects the interpretation that is a call,
1353 -- we cannot rewrite the node yet, but we include the result of
1354 -- the call interpretation.
1356 Get_First_Interp (N, I, It);
1357 while Present (It.Nam) loop
1358 if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1359 and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1360 then
1361 Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1362 end if;
1364 Get_Next_Interp (I, It);
1365 end loop;
1366 end if;
1368 -- A value of remote access-to-class-wide must not be dereferenced
1369 -- (RM E.2.2(16)).
1371 Validate_Remote_Access_To_Class_Wide_Type (N);
1372 end Analyze_Explicit_Dereference;
1374 ------------------------
1375 -- Analyze_Expression --
1376 ------------------------
1378 procedure Analyze_Expression (N : Node_Id) is
1379 begin
1380 Analyze (N);
1381 Check_Parameterless_Call (N);
1382 end Analyze_Expression;
1384 ------------------------------------
1385 -- Analyze_Indexed_Component_Form --
1386 ------------------------------------
1388 procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1389 P : constant Node_Id := Prefix (N);
1390 Exprs : constant List_Id := Expressions (N);
1391 Exp : Node_Id;
1392 P_T : Entity_Id;
1393 E : Node_Id;
1394 U_N : Entity_Id;
1396 procedure Process_Function_Call;
1397 -- Prefix in indexed component form is an overloadable entity,
1398 -- so the node is a function call. Reformat it as such.
1400 procedure Process_Indexed_Component;
1401 -- Prefix in indexed component form is actually an indexed component.
1402 -- This routine processes it, knowing that the prefix is already
1403 -- resolved.
1405 procedure Process_Indexed_Component_Or_Slice;
1406 -- An indexed component with a single index may designate a slice if
1407 -- the index is a subtype mark. This routine disambiguates these two
1408 -- cases by resolving the prefix to see if it is a subtype mark.
1410 procedure Process_Overloaded_Indexed_Component;
1411 -- If the prefix of an indexed component is overloaded, the proper
1412 -- interpretation is selected by the index types and the context.
1414 ---------------------------
1415 -- Process_Function_Call --
1416 ---------------------------
1418 procedure Process_Function_Call is
1419 Actual : Node_Id;
1421 begin
1422 Change_Node (N, N_Function_Call);
1423 Set_Name (N, P);
1424 Set_Parameter_Associations (N, Exprs);
1426 Actual := First (Parameter_Associations (N));
1427 while Present (Actual) loop
1428 Analyze (Actual);
1429 Check_Parameterless_Call (Actual);
1430 Next_Actual (Actual);
1431 end loop;
1433 Analyze_Call (N);
1434 end Process_Function_Call;
1436 -------------------------------
1437 -- Process_Indexed_Component --
1438 -------------------------------
1440 procedure Process_Indexed_Component is
1441 Exp : Node_Id;
1442 Array_Type : Entity_Id;
1443 Index : Node_Id;
1444 Pent : Entity_Id := Empty;
1446 begin
1447 Exp := First (Exprs);
1449 if Is_Overloaded (P) then
1450 Process_Overloaded_Indexed_Component;
1452 else
1453 Array_Type := Etype (P);
1455 if Is_Entity_Name (P) then
1456 Pent := Entity (P);
1457 elsif Nkind (P) = N_Selected_Component
1458 and then Is_Entity_Name (Selector_Name (P))
1459 then
1460 Pent := Entity (Selector_Name (P));
1461 end if;
1463 -- Prefix must be appropriate for an array type, taking into
1464 -- account a possible implicit dereference.
1466 if Is_Access_Type (Array_Type) then
1467 Array_Type := Designated_Type (Array_Type);
1468 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1469 Process_Implicit_Dereference_Prefix (Pent, P);
1470 end if;
1472 if Is_Array_Type (Array_Type) then
1473 null;
1475 elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
1476 Analyze (Exp);
1477 Set_Etype (N, Any_Type);
1479 if not Has_Compatible_Type
1480 (Exp, Entry_Index_Type (Pent))
1481 then
1482 Error_Msg_N ("invalid index type in entry name", N);
1484 elsif Present (Next (Exp)) then
1485 Error_Msg_N ("too many subscripts in entry reference", N);
1487 else
1488 Set_Etype (N, Etype (P));
1489 end if;
1491 return;
1493 elsif Is_Record_Type (Array_Type)
1494 and then Remote_AST_I_Dereference (P)
1495 then
1496 return;
1498 elsif Array_Type = Any_Type then
1499 Set_Etype (N, Any_Type);
1500 return;
1502 -- Here we definitely have a bad indexing
1504 else
1505 if Nkind (Parent (N)) = N_Requeue_Statement
1506 and then Present (Pent) and then Ekind (Pent) = E_Entry
1507 then
1508 Error_Msg_N
1509 ("REQUEUE does not permit parameters", First (Exprs));
1511 elsif Is_Entity_Name (P)
1512 and then Etype (P) = Standard_Void_Type
1513 then
1514 Error_Msg_NE ("incorrect use of&", P, Entity (P));
1516 else
1517 Error_Msg_N ("array type required in indexed component", P);
1518 end if;
1520 Set_Etype (N, Any_Type);
1521 return;
1522 end if;
1524 Index := First_Index (Array_Type);
1526 while Present (Index) and then Present (Exp) loop
1527 if not Has_Compatible_Type (Exp, Etype (Index)) then
1528 Wrong_Type (Exp, Etype (Index));
1529 Set_Etype (N, Any_Type);
1530 return;
1531 end if;
1533 Next_Index (Index);
1534 Next (Exp);
1535 end loop;
1537 Set_Etype (N, Component_Type (Array_Type));
1539 if Present (Index) then
1540 Error_Msg_N
1541 ("too few subscripts in array reference", First (Exprs));
1543 elsif Present (Exp) then
1544 Error_Msg_N ("too many subscripts in array reference", Exp);
1545 end if;
1546 end if;
1547 end Process_Indexed_Component;
1549 ----------------------------------------
1550 -- Process_Indexed_Component_Or_Slice --
1551 ----------------------------------------
1553 procedure Process_Indexed_Component_Or_Slice is
1554 begin
1555 Exp := First (Exprs);
1556 while Present (Exp) loop
1557 Analyze_Expression (Exp);
1558 Next (Exp);
1559 end loop;
1561 Exp := First (Exprs);
1563 -- If one index is present, and it is a subtype name, then the
1564 -- node denotes a slice (note that the case of an explicit range
1565 -- for a slice was already built as an N_Slice node in the first
1566 -- place, so that case is not handled here).
1568 -- We use a replace rather than a rewrite here because this is one
1569 -- of the cases in which the tree built by the parser is plain wrong.
1571 if No (Next (Exp))
1572 and then Is_Entity_Name (Exp)
1573 and then Is_Type (Entity (Exp))
1574 then
1575 Replace (N,
1576 Make_Slice (Sloc (N),
1577 Prefix => P,
1578 Discrete_Range => New_Copy (Exp)));
1579 Analyze (N);
1581 -- Otherwise (more than one index present, or single index is not
1582 -- a subtype name), then we have the indexed component case.
1584 else
1585 Process_Indexed_Component;
1586 end if;
1587 end Process_Indexed_Component_Or_Slice;
1589 ------------------------------------------
1590 -- Process_Overloaded_Indexed_Component --
1591 ------------------------------------------
1593 procedure Process_Overloaded_Indexed_Component is
1594 Exp : Node_Id;
1595 I : Interp_Index;
1596 It : Interp;
1597 Typ : Entity_Id;
1598 Index : Node_Id;
1599 Found : Boolean;
1601 begin
1602 Set_Etype (N, Any_Type);
1604 Get_First_Interp (P, I, It);
1605 while Present (It.Nam) loop
1606 Typ := It.Typ;
1608 if Is_Access_Type (Typ) then
1609 Typ := Designated_Type (Typ);
1610 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1611 end if;
1613 if Is_Array_Type (Typ) then
1615 -- Got a candidate: verify that index types are compatible
1617 Index := First_Index (Typ);
1618 Found := True;
1619 Exp := First (Exprs);
1620 while Present (Index) and then Present (Exp) loop
1621 if Has_Compatible_Type (Exp, Etype (Index)) then
1622 null;
1623 else
1624 Found := False;
1625 Remove_Interp (I);
1626 exit;
1627 end if;
1629 Next_Index (Index);
1630 Next (Exp);
1631 end loop;
1633 if Found and then No (Index) and then No (Exp) then
1634 Add_One_Interp (N,
1635 Etype (Component_Type (Typ)),
1636 Etype (Component_Type (Typ)));
1637 end if;
1638 end if;
1640 Get_Next_Interp (I, It);
1641 end loop;
1643 if Etype (N) = Any_Type then
1644 Error_Msg_N ("no legal interpetation for indexed component", N);
1645 Set_Is_Overloaded (N, False);
1646 end if;
1648 End_Interp_List;
1649 end Process_Overloaded_Indexed_Component;
1651 -- Start of processing for Analyze_Indexed_Component_Form
1653 begin
1654 -- Get name of array, function or type
1656 Analyze (P);
1657 if Nkind (N) = N_Function_Call
1658 or else Nkind (N) = N_Procedure_Call_Statement
1659 then
1660 -- If P is an explicit dereference whose prefix is of a
1661 -- remote access-to-subprogram type, then N has already
1662 -- been rewritten as a subprogram call and analyzed.
1664 return;
1665 end if;
1667 pragma Assert (Nkind (N) = N_Indexed_Component);
1669 P_T := Base_Type (Etype (P));
1671 if Is_Entity_Name (P)
1672 or else Nkind (P) = N_Operator_Symbol
1673 then
1674 U_N := Entity (P);
1676 if Ekind (U_N) in Type_Kind then
1678 -- Reformat node as a type conversion
1680 E := Remove_Head (Exprs);
1682 if Present (First (Exprs)) then
1683 Error_Msg_N
1684 ("argument of type conversion must be single expression", N);
1685 end if;
1687 Change_Node (N, N_Type_Conversion);
1688 Set_Subtype_Mark (N, P);
1689 Set_Etype (N, U_N);
1690 Set_Expression (N, E);
1692 -- After changing the node, call for the specific Analysis
1693 -- routine directly, to avoid a double call to the expander.
1695 Analyze_Type_Conversion (N);
1696 return;
1697 end if;
1699 if Is_Overloadable (U_N) then
1700 Process_Function_Call;
1702 elsif Ekind (Etype (P)) = E_Subprogram_Type
1703 or else (Is_Access_Type (Etype (P))
1704 and then
1705 Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
1706 then
1707 -- Call to access_to-subprogram with possible implicit dereference
1709 Process_Function_Call;
1711 elsif Is_Generic_Subprogram (U_N) then
1713 -- A common beginner's (or C++ templates fan) error
1715 Error_Msg_N ("generic subprogram cannot be called", N);
1716 Set_Etype (N, Any_Type);
1717 return;
1719 else
1720 Process_Indexed_Component_Or_Slice;
1721 end if;
1723 -- If not an entity name, prefix is an expression that may denote
1724 -- an array or an access-to-subprogram.
1726 else
1727 if Ekind (P_T) = E_Subprogram_Type
1728 or else (Is_Access_Type (P_T)
1729 and then
1730 Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1731 then
1732 Process_Function_Call;
1734 elsif Nkind (P) = N_Selected_Component
1735 and then Is_Overloadable (Entity (Selector_Name (P)))
1736 then
1737 Process_Function_Call;
1739 else
1740 -- Indexed component, slice, or a call to a member of a family
1741 -- entry, which will be converted to an entry call later.
1743 Process_Indexed_Component_Or_Slice;
1744 end if;
1745 end if;
1746 end Analyze_Indexed_Component_Form;
1748 ------------------------
1749 -- Analyze_Logical_Op --
1750 ------------------------
1752 procedure Analyze_Logical_Op (N : Node_Id) is
1753 L : constant Node_Id := Left_Opnd (N);
1754 R : constant Node_Id := Right_Opnd (N);
1755 Op_Id : Entity_Id := Entity (N);
1757 begin
1758 Set_Etype (N, Any_Type);
1759 Candidate_Type := Empty;
1761 Analyze_Expression (L);
1762 Analyze_Expression (R);
1764 if Present (Op_Id) then
1766 if Ekind (Op_Id) = E_Operator then
1767 Find_Boolean_Types (L, R, Op_Id, N);
1768 else
1769 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1770 end if;
1772 else
1773 Op_Id := Get_Name_Entity_Id (Chars (N));
1775 while Present (Op_Id) loop
1776 if Ekind (Op_Id) = E_Operator then
1777 Find_Boolean_Types (L, R, Op_Id, N);
1778 else
1779 Analyze_User_Defined_Binary_Op (N, Op_Id);
1780 end if;
1782 Op_Id := Homonym (Op_Id);
1783 end loop;
1784 end if;
1786 Operator_Check (N);
1787 end Analyze_Logical_Op;
1789 ---------------------------
1790 -- Analyze_Membership_Op --
1791 ---------------------------
1793 procedure Analyze_Membership_Op (N : Node_Id) is
1794 L : constant Node_Id := Left_Opnd (N);
1795 R : constant Node_Id := Right_Opnd (N);
1797 Index : Interp_Index;
1798 It : Interp;
1799 Found : Boolean := False;
1800 I_F : Interp_Index;
1801 T_F : Entity_Id;
1803 procedure Try_One_Interp (T1 : Entity_Id);
1804 -- Routine to try one proposed interpretation. Note that the context
1805 -- of the operation plays no role in resolving the arguments, so that
1806 -- if there is more than one interpretation of the operands that is
1807 -- compatible with a membership test, the operation is ambiguous.
1809 --------------------
1810 -- Try_One_Interp --
1811 --------------------
1813 procedure Try_One_Interp (T1 : Entity_Id) is
1814 begin
1815 if Has_Compatible_Type (R, T1) then
1816 if Found
1817 and then Base_Type (T1) /= Base_Type (T_F)
1818 then
1819 It := Disambiguate (L, I_F, Index, Any_Type);
1821 if It = No_Interp then
1822 Ambiguous_Operands (N);
1823 Set_Etype (L, Any_Type);
1824 return;
1826 else
1827 T_F := It.Typ;
1828 end if;
1830 else
1831 Found := True;
1832 T_F := T1;
1833 I_F := Index;
1834 end if;
1836 Set_Etype (L, T_F);
1837 end if;
1839 end Try_One_Interp;
1841 -- Start of processing for Analyze_Membership_Op
1843 begin
1844 Analyze_Expression (L);
1846 if Nkind (R) = N_Range
1847 or else (Nkind (R) = N_Attribute_Reference
1848 and then Attribute_Name (R) = Name_Range)
1849 then
1850 Analyze (R);
1852 if not Is_Overloaded (L) then
1853 Try_One_Interp (Etype (L));
1855 else
1856 Get_First_Interp (L, Index, It);
1858 while Present (It.Typ) loop
1859 Try_One_Interp (It.Typ);
1860 Get_Next_Interp (Index, It);
1861 end loop;
1862 end if;
1864 -- If not a range, it can only be a subtype mark, or else there
1865 -- is a more basic error, to be diagnosed in Find_Type.
1867 else
1868 Find_Type (R);
1870 if Is_Entity_Name (R) then
1871 Check_Fully_Declared (Entity (R), R);
1872 end if;
1873 end if;
1875 -- Compatibility between expression and subtype mark or range is
1876 -- checked during resolution. The result of the operation is Boolean
1877 -- in any case.
1879 Set_Etype (N, Standard_Boolean);
1880 end Analyze_Membership_Op;
1882 ----------------------
1883 -- Analyze_Negation --
1884 ----------------------
1886 procedure Analyze_Negation (N : Node_Id) is
1887 R : constant Node_Id := Right_Opnd (N);
1888 Op_Id : Entity_Id := Entity (N);
1890 begin
1891 Set_Etype (N, Any_Type);
1892 Candidate_Type := Empty;
1894 Analyze_Expression (R);
1896 if Present (Op_Id) then
1897 if Ekind (Op_Id) = E_Operator then
1898 Find_Negation_Types (R, Op_Id, N);
1899 else
1900 Add_One_Interp (N, Op_Id, Etype (Op_Id));
1901 end if;
1903 else
1904 Op_Id := Get_Name_Entity_Id (Chars (N));
1905 while Present (Op_Id) loop
1906 if Ekind (Op_Id) = E_Operator then
1907 Find_Negation_Types (R, Op_Id, N);
1908 else
1909 Analyze_User_Defined_Unary_Op (N, Op_Id);
1910 end if;
1912 Op_Id := Homonym (Op_Id);
1913 end loop;
1914 end if;
1916 Operator_Check (N);
1917 end Analyze_Negation;
1919 ------------------
1920 -- Analyze_Null --
1921 ------------------
1923 procedure Analyze_Null (N : Node_Id) is
1924 begin
1925 Set_Etype (N, Any_Access);
1926 end Analyze_Null;
1928 ----------------------
1929 -- Analyze_One_Call --
1930 ----------------------
1932 procedure Analyze_One_Call
1933 (N : Node_Id;
1934 Nam : Entity_Id;
1935 Report : Boolean;
1936 Success : out Boolean;
1937 Skip_First : Boolean := False)
1939 Actuals : constant List_Id := Parameter_Associations (N);
1940 Prev_T : constant Entity_Id := Etype (N);
1941 Formal : Entity_Id;
1942 Actual : Node_Id;
1943 Is_Indexed : Boolean := False;
1944 Subp_Type : constant Entity_Id := Etype (Nam);
1945 Norm_OK : Boolean;
1947 procedure Indicate_Name_And_Type;
1948 -- If candidate interpretation matches, indicate name and type of
1949 -- result on call node.
1951 ----------------------------
1952 -- Indicate_Name_And_Type --
1953 ----------------------------
1955 procedure Indicate_Name_And_Type is
1956 begin
1957 Add_One_Interp (N, Nam, Etype (Nam));
1958 Success := True;
1960 -- If the prefix of the call is a name, indicate the entity
1961 -- being called. If it is not a name, it is an expression that
1962 -- denotes an access to subprogram or else an entry or family. In
1963 -- the latter case, the name is a selected component, and the entity
1964 -- being called is noted on the selector.
1966 if not Is_Type (Nam) then
1967 if Is_Entity_Name (Name (N))
1968 or else Nkind (Name (N)) = N_Operator_Symbol
1969 then
1970 Set_Entity (Name (N), Nam);
1972 elsif Nkind (Name (N)) = N_Selected_Component then
1973 Set_Entity (Selector_Name (Name (N)), Nam);
1974 end if;
1975 end if;
1977 if Debug_Flag_E and not Report then
1978 Write_Str (" Overloaded call ");
1979 Write_Int (Int (N));
1980 Write_Str (" compatible with ");
1981 Write_Int (Int (Nam));
1982 Write_Eol;
1983 end if;
1984 end Indicate_Name_And_Type;
1986 -- Start of processing for Analyze_One_Call
1988 begin
1989 Success := False;
1991 -- If the subprogram has no formals, or if all the formals have
1992 -- defaults, and the return type is an array type, the node may
1993 -- denote an indexing of the result of a parameterless call.
1995 if Needs_No_Actuals (Nam)
1996 and then Present (Actuals)
1997 then
1998 if Is_Array_Type (Subp_Type) then
1999 Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type);
2001 elsif Is_Access_Type (Subp_Type)
2002 and then Is_Array_Type (Designated_Type (Subp_Type))
2003 then
2004 Is_Indexed :=
2005 Try_Indexed_Call (N, Nam, Designated_Type (Subp_Type));
2007 -- The prefix can also be a parameterless function that returns an
2008 -- access to subprogram. in which case this is an indirect call.
2010 elsif Is_Access_Type (Subp_Type)
2011 and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2012 then
2013 Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
2014 end if;
2016 end if;
2018 Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
2020 if not Norm_OK then
2022 -- Mismatch in number or names of parameters
2024 if Debug_Flag_E then
2025 Write_Str (" normalization fails in call ");
2026 Write_Int (Int (N));
2027 Write_Str (" with subprogram ");
2028 Write_Int (Int (Nam));
2029 Write_Eol;
2030 end if;
2032 -- If the context expects a function call, discard any interpretation
2033 -- that is a procedure. If the node is not overloaded, leave as is for
2034 -- better error reporting when type mismatch is found.
2036 elsif Nkind (N) = N_Function_Call
2037 and then Is_Overloaded (Name (N))
2038 and then Ekind (Nam) = E_Procedure
2039 then
2040 return;
2042 -- Ditto for function calls in a procedure context
2044 elsif Nkind (N) = N_Procedure_Call_Statement
2045 and then Is_Overloaded (Name (N))
2046 and then Etype (Nam) /= Standard_Void_Type
2047 then
2048 return;
2050 elsif not Present (Actuals) then
2052 -- If Normalize succeeds, then there are default parameters for
2053 -- all formals.
2055 Indicate_Name_And_Type;
2057 elsif Ekind (Nam) = E_Operator then
2058 if Nkind (N) = N_Procedure_Call_Statement then
2059 return;
2060 end if;
2062 -- This can occur when the prefix of the call is an operator
2063 -- name or an expanded name whose selector is an operator name.
2065 Analyze_Operator_Call (N, Nam);
2067 if Etype (N) /= Prev_T then
2069 -- There may be a user-defined operator that hides the
2070 -- current interpretation. We must check for this independently
2071 -- of the analysis of the call with the user-defined operation,
2072 -- because the parameter names may be wrong and yet the hiding
2073 -- takes place. Fixes b34014o.
2075 if Is_Overloaded (Name (N)) then
2076 declare
2077 I : Interp_Index;
2078 It : Interp;
2080 begin
2081 Get_First_Interp (Name (N), I, It);
2082 while Present (It.Nam) loop
2083 if Ekind (It.Nam) /= E_Operator
2084 and then Hides_Op (It.Nam, Nam)
2085 and then
2086 Has_Compatible_Type
2087 (First_Actual (N), Etype (First_Formal (It.Nam)))
2088 and then (No (Next_Actual (First_Actual (N)))
2089 or else Has_Compatible_Type
2090 (Next_Actual (First_Actual (N)),
2091 Etype (Next_Formal (First_Formal (It.Nam)))))
2092 then
2093 Set_Etype (N, Prev_T);
2094 return;
2095 end if;
2097 Get_Next_Interp (I, It);
2098 end loop;
2099 end;
2100 end if;
2102 -- If operator matches formals, record its name on the call.
2103 -- If the operator is overloaded, Resolve will select the
2104 -- correct one from the list of interpretations. The call
2105 -- node itself carries the first candidate.
2107 Set_Entity (Name (N), Nam);
2108 Success := True;
2110 elsif Report and then Etype (N) = Any_Type then
2111 Error_Msg_N ("incompatible arguments for operator", N);
2112 end if;
2114 else
2115 -- Normalize_Actuals has chained the named associations in the
2116 -- correct order of the formals.
2118 Actual := First_Actual (N);
2119 Formal := First_Formal (Nam);
2121 -- If we are analyzing a call rewritten from object notation,
2122 -- skip first actual, which may be rewritten later as an
2123 -- explicit dereference.
2125 if Skip_First then
2126 Next_Actual (Actual);
2127 Next_Formal (Formal);
2128 end if;
2130 while Present (Actual) and then Present (Formal) loop
2131 if Nkind (Parent (Actual)) /= N_Parameter_Association
2132 or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2133 then
2134 if Has_Compatible_Type (Actual, Etype (Formal)) then
2135 Next_Actual (Actual);
2136 Next_Formal (Formal);
2138 else
2139 if Debug_Flag_E then
2140 Write_Str (" type checking fails in call ");
2141 Write_Int (Int (N));
2142 Write_Str (" with formal ");
2143 Write_Int (Int (Formal));
2144 Write_Str (" in subprogram ");
2145 Write_Int (Int (Nam));
2146 Write_Eol;
2147 end if;
2149 if Report and not Is_Indexed then
2151 -- Ada 2005 (AI-251): Complete the error notification
2152 -- to help new Ada 2005 users
2154 if Is_Class_Wide_Type (Etype (Formal))
2155 and then Is_Interface (Etype (Etype (Formal)))
2156 and then not Interface_Present_In_Ancestor
2157 (Typ => Etype (Actual),
2158 Iface => Etype (Etype (Formal)))
2159 then
2160 Error_Msg_NE
2161 ("(Ada 2005) does not implement interface }",
2162 Actual, Etype (Etype (Formal)));
2163 end if;
2165 Wrong_Type (Actual, Etype (Formal));
2167 if Nkind (Actual) = N_Op_Eq
2168 and then Nkind (Left_Opnd (Actual)) = N_Identifier
2169 then
2170 Formal := First_Formal (Nam);
2172 while Present (Formal) loop
2174 if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2175 Error_Msg_N
2176 ("possible misspelling of `='>`!", Actual);
2177 exit;
2178 end if;
2180 Next_Formal (Formal);
2181 end loop;
2182 end if;
2184 if All_Errors_Mode then
2185 Error_Msg_Sloc := Sloc (Nam);
2187 if Is_Overloadable (Nam)
2188 and then Present (Alias (Nam))
2189 and then not Comes_From_Source (Nam)
2190 then
2191 Error_Msg_NE
2192 (" =='> in call to &#(inherited)!", Actual, Nam);
2194 elsif Ekind (Nam) = E_Subprogram_Type then
2195 declare
2196 Access_To_Subprogram_Typ :
2197 constant Entity_Id :=
2198 Defining_Identifier
2199 (Associated_Node_For_Itype (Nam));
2200 begin
2201 Error_Msg_NE (
2202 " =='> in call to dereference of &#!",
2203 Actual, Access_To_Subprogram_Typ);
2204 end;
2206 else
2207 Error_Msg_NE (" =='> in call to &#!", Actual, Nam);
2209 end if;
2210 end if;
2211 end if;
2213 return;
2214 end if;
2216 else
2217 -- Normalize_Actuals has verified that a default value exists
2218 -- for this formal. Current actual names a subsequent formal.
2220 Next_Formal (Formal);
2221 end if;
2222 end loop;
2224 -- On exit, all actuals match
2226 Indicate_Name_And_Type;
2227 end if;
2228 end Analyze_One_Call;
2230 ---------------------------
2231 -- Analyze_Operator_Call --
2232 ---------------------------
2234 procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2235 Op_Name : constant Name_Id := Chars (Op_Id);
2236 Act1 : constant Node_Id := First_Actual (N);
2237 Act2 : constant Node_Id := Next_Actual (Act1);
2239 begin
2240 -- Binary operator case
2242 if Present (Act2) then
2244 -- If more than two operands, then not binary operator after all
2246 if Present (Next_Actual (Act2)) then
2247 return;
2249 elsif Op_Name = Name_Op_Add
2250 or else Op_Name = Name_Op_Subtract
2251 or else Op_Name = Name_Op_Multiply
2252 or else Op_Name = Name_Op_Divide
2253 or else Op_Name = Name_Op_Mod
2254 or else Op_Name = Name_Op_Rem
2255 or else Op_Name = Name_Op_Expon
2256 then
2257 Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2259 elsif Op_Name = Name_Op_And
2260 or else Op_Name = Name_Op_Or
2261 or else Op_Name = Name_Op_Xor
2262 then
2263 Find_Boolean_Types (Act1, Act2, Op_Id, N);
2265 elsif Op_Name = Name_Op_Lt
2266 or else Op_Name = Name_Op_Le
2267 or else Op_Name = Name_Op_Gt
2268 or else Op_Name = Name_Op_Ge
2269 then
2270 Find_Comparison_Types (Act1, Act2, Op_Id, N);
2272 elsif Op_Name = Name_Op_Eq
2273 or else Op_Name = Name_Op_Ne
2274 then
2275 Find_Equality_Types (Act1, Act2, Op_Id, N);
2277 elsif Op_Name = Name_Op_Concat then
2278 Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2280 -- Is this else null correct, or should it be an abort???
2282 else
2283 null;
2284 end if;
2286 -- Unary operator case
2288 else
2289 if Op_Name = Name_Op_Subtract or else
2290 Op_Name = Name_Op_Add or else
2291 Op_Name = Name_Op_Abs
2292 then
2293 Find_Unary_Types (Act1, Op_Id, N);
2295 elsif
2296 Op_Name = Name_Op_Not
2297 then
2298 Find_Negation_Types (Act1, Op_Id, N);
2300 -- Is this else null correct, or should it be an abort???
2302 else
2303 null;
2304 end if;
2305 end if;
2306 end Analyze_Operator_Call;
2308 -------------------------------------------
2309 -- Analyze_Overloaded_Selected_Component --
2310 -------------------------------------------
2312 procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2313 Nam : constant Node_Id := Prefix (N);
2314 Sel : constant Node_Id := Selector_Name (N);
2315 Comp : Entity_Id;
2316 I : Interp_Index;
2317 It : Interp;
2318 T : Entity_Id;
2320 begin
2321 Set_Etype (Sel, Any_Type);
2323 Get_First_Interp (Nam, I, It);
2324 while Present (It.Typ) loop
2325 if Is_Access_Type (It.Typ) then
2326 T := Designated_Type (It.Typ);
2327 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2328 else
2329 T := It.Typ;
2330 end if;
2332 if Is_Record_Type (T) then
2333 Comp := First_Entity (T);
2334 while Present (Comp) loop
2335 if Chars (Comp) = Chars (Sel)
2336 and then Is_Visible_Component (Comp)
2337 then
2338 Set_Entity_With_Style_Check (Sel, Comp);
2339 Generate_Reference (Comp, Sel);
2341 Set_Etype (Sel, Etype (Comp));
2342 Add_One_Interp (N, Etype (Comp), Etype (Comp));
2344 -- This also specifies a candidate to resolve the name.
2345 -- Further overloading will be resolved from context.
2347 Set_Etype (Nam, It.Typ);
2348 end if;
2350 Next_Entity (Comp);
2351 end loop;
2353 elsif Is_Concurrent_Type (T) then
2354 Comp := First_Entity (T);
2355 while Present (Comp)
2356 and then Comp /= First_Private_Entity (T)
2357 loop
2358 if Chars (Comp) = Chars (Sel) then
2359 if Is_Overloadable (Comp) then
2360 Add_One_Interp (Sel, Comp, Etype (Comp));
2361 else
2362 Set_Entity_With_Style_Check (Sel, Comp);
2363 Generate_Reference (Comp, Sel);
2364 end if;
2366 Set_Etype (Sel, Etype (Comp));
2367 Set_Etype (N, Etype (Comp));
2368 Set_Etype (Nam, It.Typ);
2370 -- For access type case, introduce explicit deference for
2371 -- more uniform treatment of entry calls.
2373 if Is_Access_Type (Etype (Nam)) then
2374 Insert_Explicit_Dereference (Nam);
2375 Error_Msg_NW
2376 (Warn_On_Dereference, "?implicit dereference", N);
2377 end if;
2378 end if;
2380 Next_Entity (Comp);
2381 end loop;
2383 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2384 end if;
2386 Get_Next_Interp (I, It);
2387 end loop;
2389 if Etype (N) = Any_Type then
2390 Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2391 Set_Entity (Sel, Any_Id);
2392 Set_Etype (Sel, Any_Type);
2393 end if;
2394 end Analyze_Overloaded_Selected_Component;
2396 ----------------------------------
2397 -- Analyze_Qualified_Expression --
2398 ----------------------------------
2400 procedure Analyze_Qualified_Expression (N : Node_Id) is
2401 Mark : constant Entity_Id := Subtype_Mark (N);
2402 T : Entity_Id;
2404 begin
2405 Set_Etype (N, Any_Type);
2406 Find_Type (Mark);
2407 T := Entity (Mark);
2409 if T = Any_Type then
2410 return;
2411 end if;
2413 Check_Fully_Declared (T, N);
2414 Analyze_Expression (Expression (N));
2415 Set_Etype (N, T);
2416 end Analyze_Qualified_Expression;
2418 -------------------
2419 -- Analyze_Range --
2420 -------------------
2422 procedure Analyze_Range (N : Node_Id) is
2423 L : constant Node_Id := Low_Bound (N);
2424 H : constant Node_Id := High_Bound (N);
2425 I1, I2 : Interp_Index;
2426 It1, It2 : Interp;
2428 procedure Check_Common_Type (T1, T2 : Entity_Id);
2429 -- Verify the compatibility of two types, and choose the
2430 -- non universal one if the other is universal.
2432 procedure Check_High_Bound (T : Entity_Id);
2433 -- Test one interpretation of the low bound against all those
2434 -- of the high bound.
2436 procedure Check_Universal_Expression (N : Node_Id);
2437 -- In Ada83, reject bounds of a universal range that are not
2438 -- literals or entity names.
2440 -----------------------
2441 -- Check_Common_Type --
2442 -----------------------
2444 procedure Check_Common_Type (T1, T2 : Entity_Id) is
2445 begin
2446 if Covers (T1, T2) or else Covers (T2, T1) then
2447 if T1 = Universal_Integer
2448 or else T1 = Universal_Real
2449 or else T1 = Any_Character
2450 then
2451 Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2453 elsif T1 = T2 then
2454 Add_One_Interp (N, T1, T1);
2456 else
2457 Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2458 end if;
2459 end if;
2460 end Check_Common_Type;
2462 ----------------------
2463 -- Check_High_Bound --
2464 ----------------------
2466 procedure Check_High_Bound (T : Entity_Id) is
2467 begin
2468 if not Is_Overloaded (H) then
2469 Check_Common_Type (T, Etype (H));
2470 else
2471 Get_First_Interp (H, I2, It2);
2472 while Present (It2.Typ) loop
2473 Check_Common_Type (T, It2.Typ);
2474 Get_Next_Interp (I2, It2);
2475 end loop;
2476 end if;
2477 end Check_High_Bound;
2479 -----------------------------
2480 -- Is_Universal_Expression --
2481 -----------------------------
2483 procedure Check_Universal_Expression (N : Node_Id) is
2484 begin
2485 if Etype (N) = Universal_Integer
2486 and then Nkind (N) /= N_Integer_Literal
2487 and then not Is_Entity_Name (N)
2488 and then Nkind (N) /= N_Attribute_Reference
2489 then
2490 Error_Msg_N ("illegal bound in discrete range", N);
2491 end if;
2492 end Check_Universal_Expression;
2494 -- Start of processing for Analyze_Range
2496 begin
2497 Set_Etype (N, Any_Type);
2498 Analyze_Expression (L);
2499 Analyze_Expression (H);
2501 if Etype (L) = Any_Type or else Etype (H) = Any_Type then
2502 return;
2504 else
2505 if not Is_Overloaded (L) then
2506 Check_High_Bound (Etype (L));
2507 else
2508 Get_First_Interp (L, I1, It1);
2509 while Present (It1.Typ) loop
2510 Check_High_Bound (It1.Typ);
2511 Get_Next_Interp (I1, It1);
2512 end loop;
2513 end if;
2515 -- If result is Any_Type, then we did not find a compatible pair
2517 if Etype (N) = Any_Type then
2518 Error_Msg_N ("incompatible types in range ", N);
2519 end if;
2520 end if;
2522 if Ada_Version = Ada_83
2523 and then
2524 (Nkind (Parent (N)) = N_Loop_Parameter_Specification
2525 or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
2526 then
2527 Check_Universal_Expression (L);
2528 Check_Universal_Expression (H);
2529 end if;
2530 end Analyze_Range;
2532 -----------------------
2533 -- Analyze_Reference --
2534 -----------------------
2536 procedure Analyze_Reference (N : Node_Id) is
2537 P : constant Node_Id := Prefix (N);
2538 Acc_Type : Entity_Id;
2539 begin
2540 Analyze (P);
2541 Acc_Type := Create_Itype (E_Allocator_Type, N);
2542 Set_Etype (Acc_Type, Acc_Type);
2543 Init_Size_Align (Acc_Type);
2544 Set_Directly_Designated_Type (Acc_Type, Etype (P));
2545 Set_Etype (N, Acc_Type);
2546 end Analyze_Reference;
2548 --------------------------------
2549 -- Analyze_Selected_Component --
2550 --------------------------------
2552 -- Prefix is a record type or a task or protected type. In the
2553 -- later case, the selector must denote a visible entry.
2555 procedure Analyze_Selected_Component (N : Node_Id) is
2556 Name : constant Node_Id := Prefix (N);
2557 Sel : constant Node_Id := Selector_Name (N);
2558 Comp : Entity_Id;
2559 Entity_List : Entity_Id;
2560 Prefix_Type : Entity_Id;
2561 Pent : Entity_Id := Empty;
2562 Act_Decl : Node_Id;
2563 In_Scope : Boolean;
2564 Parent_N : Node_Id;
2566 -- Start of processing for Analyze_Selected_Component
2568 begin
2569 Set_Etype (N, Any_Type);
2571 if Is_Overloaded (Name) then
2572 Analyze_Overloaded_Selected_Component (N);
2573 return;
2575 elsif Etype (Name) = Any_Type then
2576 Set_Entity (Sel, Any_Id);
2577 Set_Etype (Sel, Any_Type);
2578 return;
2580 else
2581 Prefix_Type := Etype (Name);
2582 end if;
2584 if Is_Access_Type (Prefix_Type) then
2586 -- A RACW object can never be used as prefix of a selected
2587 -- component since that means it is dereferenced without
2588 -- being a controlling operand of a dispatching operation
2589 -- (RM E.2.2(15)).
2591 if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
2592 and then Comes_From_Source (N)
2593 then
2594 Error_Msg_N
2595 ("invalid dereference of a remote access to class-wide value",
2598 -- Normal case of selected component applied to access type
2600 else
2601 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2603 if Is_Entity_Name (Name) then
2604 Pent := Entity (Name);
2605 elsif Nkind (Name) = N_Selected_Component
2606 and then Is_Entity_Name (Selector_Name (Name))
2607 then
2608 Pent := Entity (Selector_Name (Name));
2609 end if;
2611 Process_Implicit_Dereference_Prefix (Pent, Name);
2612 end if;
2614 Prefix_Type := Designated_Type (Prefix_Type);
2615 end if;
2617 if Ekind (Prefix_Type) = E_Private_Subtype then
2618 Prefix_Type := Base_Type (Prefix_Type);
2619 end if;
2621 Entity_List := Prefix_Type;
2623 -- For class-wide types, use the entity list of the root type. This
2624 -- indirection is specially important for private extensions because
2625 -- only the root type get switched (not the class-wide type).
2627 if Is_Class_Wide_Type (Prefix_Type) then
2628 Entity_List := Root_Type (Prefix_Type);
2629 end if;
2631 Comp := First_Entity (Entity_List);
2633 -- If the selector has an original discriminant, the node appears in
2634 -- an instance. Replace the discriminant with the corresponding one
2635 -- in the current discriminated type. For nested generics, this must
2636 -- be done transitively, so note the new original discriminant.
2638 if Nkind (Sel) = N_Identifier
2639 and then Present (Original_Discriminant (Sel))
2640 then
2641 Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
2643 -- Mark entity before rewriting, for completeness and because
2644 -- subsequent semantic checks might examine the original node.
2646 Set_Entity (Sel, Comp);
2647 Rewrite (Selector_Name (N),
2648 New_Occurrence_Of (Comp, Sloc (N)));
2649 Set_Original_Discriminant (Selector_Name (N), Comp);
2650 Set_Etype (N, Etype (Comp));
2652 if Is_Access_Type (Etype (Name)) then
2653 Insert_Explicit_Dereference (Name);
2654 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2655 end if;
2657 elsif Is_Record_Type (Prefix_Type) then
2659 -- Find component with given name
2661 while Present (Comp) loop
2662 if Chars (Comp) = Chars (Sel)
2663 and then Is_Visible_Component (Comp)
2664 then
2665 Set_Entity_With_Style_Check (Sel, Comp);
2666 Generate_Reference (Comp, Sel);
2668 Set_Etype (Sel, Etype (Comp));
2670 if Ekind (Comp) = E_Discriminant then
2671 if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
2672 Error_Msg_N
2673 ("cannot reference discriminant of Unchecked_Union",
2674 Sel);
2675 end if;
2677 if Is_Generic_Type (Prefix_Type)
2678 or else
2679 Is_Generic_Type (Root_Type (Prefix_Type))
2680 then
2681 Set_Original_Discriminant (Sel, Comp);
2682 end if;
2683 end if;
2685 -- Resolve the prefix early otherwise it is not possible to
2686 -- build the actual subtype of the component: it may need
2687 -- to duplicate this prefix and duplication is only allowed
2688 -- on fully resolved expressions.
2690 Resolve (Name);
2692 -- Ada 2005 (AI-50217): Check wrong use of incomplete type.
2693 -- Example:
2695 -- limited with Pkg;
2696 -- package Pkg is
2697 -- type Acc_Inc is access Pkg.T;
2698 -- X : Acc_Inc;
2699 -- N : Natural := X.all.Comp; -- ERROR
2700 -- end Pkg;
2702 if Nkind (Name) = N_Explicit_Dereference
2703 and then From_With_Type (Etype (Prefix (Name)))
2704 and then not Is_Potentially_Use_Visible (Etype (Name))
2705 then
2706 Error_Msg_NE
2707 ("premature usage of incomplete}", Prefix (Name),
2708 Etype (Prefix (Name)));
2709 end if;
2711 -- We never need an actual subtype for the case of a selection
2712 -- for a indexed component of a non-packed array, since in
2713 -- this case gigi generates all the checks and can find the
2714 -- necessary bounds information.
2716 -- We also do not need an actual subtype for the case of
2717 -- a first, last, length, or range attribute applied to a
2718 -- non-packed array, since gigi can again get the bounds in
2719 -- these cases (gigi cannot handle the packed case, since it
2720 -- has the bounds of the packed array type, not the original
2721 -- bounds of the type). However, if the prefix is itself a
2722 -- selected component, as in a.b.c (i), gigi may regard a.b.c
2723 -- as a dynamic-sized temporary, so we do generate an actual
2724 -- subtype for this case.
2726 Parent_N := Parent (N);
2728 if not Is_Packed (Etype (Comp))
2729 and then
2730 ((Nkind (Parent_N) = N_Indexed_Component
2731 and then Nkind (Name) /= N_Selected_Component)
2732 or else
2733 (Nkind (Parent_N) = N_Attribute_Reference
2734 and then (Attribute_Name (Parent_N) = Name_First
2735 or else
2736 Attribute_Name (Parent_N) = Name_Last
2737 or else
2738 Attribute_Name (Parent_N) = Name_Length
2739 or else
2740 Attribute_Name (Parent_N) = Name_Range)))
2741 then
2742 Set_Etype (N, Etype (Comp));
2744 -- If full analysis is not enabled, we do not generate an
2745 -- actual subtype, because in the absence of expansion
2746 -- reference to a formal of a protected type, for example,
2747 -- will not be properly transformed, and will lead to
2748 -- out-of-scope references in gigi.
2750 -- In all other cases, we currently build an actual subtype.
2751 -- It seems likely that many of these cases can be avoided,
2752 -- but right now, the front end makes direct references to the
2753 -- bounds (e.g. in generating a length check), and if we do
2754 -- not make an actual subtype, we end up getting a direct
2755 -- reference to a discriminant, which will not do.
2757 elsif Full_Analysis then
2758 Act_Decl :=
2759 Build_Actual_Subtype_Of_Component (Etype (Comp), N);
2760 Insert_Action (N, Act_Decl);
2762 if No (Act_Decl) then
2763 Set_Etype (N, Etype (Comp));
2765 else
2766 -- Component type depends on discriminants. Enter the
2767 -- main attributes of the subtype.
2769 declare
2770 Subt : constant Entity_Id :=
2771 Defining_Identifier (Act_Decl);
2773 begin
2774 Set_Etype (Subt, Base_Type (Etype (Comp)));
2775 Set_Ekind (Subt, Ekind (Etype (Comp)));
2776 Set_Etype (N, Subt);
2777 end;
2778 end if;
2780 -- If Full_Analysis not enabled, just set the Etype
2782 else
2783 Set_Etype (N, Etype (Comp));
2784 end if;
2786 return;
2787 end if;
2789 Next_Entity (Comp);
2790 end loop;
2792 -- Ada 2005 (AI-252)
2794 if Ada_Version >= Ada_05
2795 and then Is_Tagged_Type (Prefix_Type)
2796 and then Try_Object_Operation (N)
2797 then
2798 return;
2800 -- If the transformation fails, it will be necessary to redo the
2801 -- analysis with all errors enabled, to indicate candidate
2802 -- interpretations and reasons for each failure ???
2804 end if;
2806 elsif Is_Private_Type (Prefix_Type) then
2808 -- Allow access only to discriminants of the type. If the type has
2809 -- no full view, gigi uses the parent type for the components, so we
2810 -- do the same here.
2812 if No (Full_View (Prefix_Type)) then
2813 Entity_List := Root_Type (Base_Type (Prefix_Type));
2814 Comp := First_Entity (Entity_List);
2815 end if;
2817 while Present (Comp) loop
2818 if Chars (Comp) = Chars (Sel) then
2819 if Ekind (Comp) = E_Discriminant then
2820 Set_Entity_With_Style_Check (Sel, Comp);
2821 Generate_Reference (Comp, Sel);
2823 Set_Etype (Sel, Etype (Comp));
2824 Set_Etype (N, Etype (Comp));
2826 if Is_Generic_Type (Prefix_Type)
2827 or else
2828 Is_Generic_Type (Root_Type (Prefix_Type))
2829 then
2830 Set_Original_Discriminant (Sel, Comp);
2831 end if;
2833 else
2834 Error_Msg_NE
2835 ("invisible selector for }",
2836 N, First_Subtype (Prefix_Type));
2837 Set_Entity (Sel, Any_Id);
2838 Set_Etype (N, Any_Type);
2839 end if;
2841 return;
2842 end if;
2844 Next_Entity (Comp);
2845 end loop;
2847 elsif Is_Concurrent_Type (Prefix_Type) then
2849 -- Prefix is concurrent type. Find visible operation with given name
2850 -- For a task, this can only include entries or discriminants if the
2851 -- task type is not an enclosing scope. If it is an enclosing scope
2852 -- (e.g. in an inner task) then all entities are visible, but the
2853 -- prefix must denote the enclosing scope, i.e. can only be a direct
2854 -- name or an expanded name.
2856 Set_Etype (Sel, Any_Type);
2857 In_Scope := In_Open_Scopes (Prefix_Type);
2859 while Present (Comp) loop
2860 if Chars (Comp) = Chars (Sel) then
2861 if Is_Overloadable (Comp) then
2862 Add_One_Interp (Sel, Comp, Etype (Comp));
2864 elsif Ekind (Comp) = E_Discriminant
2865 or else Ekind (Comp) = E_Entry_Family
2866 or else (In_Scope
2867 and then Is_Entity_Name (Name))
2868 then
2869 Set_Entity_With_Style_Check (Sel, Comp);
2870 Generate_Reference (Comp, Sel);
2872 else
2873 goto Next_Comp;
2874 end if;
2876 Set_Etype (Sel, Etype (Comp));
2877 Set_Etype (N, Etype (Comp));
2879 if Ekind (Comp) = E_Discriminant then
2880 Set_Original_Discriminant (Sel, Comp);
2881 end if;
2883 -- For access type case, introduce explicit deference for more
2884 -- uniform treatment of entry calls.
2886 if Is_Access_Type (Etype (Name)) then
2887 Insert_Explicit_Dereference (Name);
2888 Error_Msg_NW
2889 (Warn_On_Dereference, "?implicit dereference", N);
2890 end if;
2891 end if;
2893 <<Next_Comp>>
2894 Next_Entity (Comp);
2895 exit when not In_Scope
2896 and then
2897 Comp = First_Private_Entity (Base_Type (Prefix_Type));
2898 end loop;
2900 Set_Is_Overloaded (N, Is_Overloaded (Sel));
2902 else
2903 -- Invalid prefix
2905 Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
2906 end if;
2908 -- If N still has no type, the component is not defined in the prefix
2910 if Etype (N) = Any_Type then
2912 -- If the prefix is a single concurrent object, use its name in the
2913 -- error message, rather than that of its anonymous type.
2915 if Is_Concurrent_Type (Prefix_Type)
2916 and then Is_Internal_Name (Chars (Prefix_Type))
2917 and then not Is_Derived_Type (Prefix_Type)
2918 and then Is_Entity_Name (Name)
2919 then
2921 Error_Msg_Node_2 := Entity (Name);
2922 Error_Msg_NE ("no selector& for&", N, Sel);
2924 Check_Misspelled_Selector (Entity_List, Sel);
2926 elsif Is_Generic_Type (Prefix_Type)
2927 and then Ekind (Prefix_Type) = E_Record_Type_With_Private
2928 and then Prefix_Type /= Etype (Prefix_Type)
2929 and then Is_Record_Type (Etype (Prefix_Type))
2930 then
2931 -- If this is a derived formal type, the parent may have
2932 -- different visibility at this point. Try for an inherited
2933 -- component before reporting an error.
2935 Set_Etype (Prefix (N), Etype (Prefix_Type));
2936 Analyze_Selected_Component (N);
2937 return;
2939 elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
2940 and then Is_Generic_Actual_Type (Prefix_Type)
2941 and then Present (Full_View (Prefix_Type))
2942 then
2943 -- Similarly, if this the actual for a formal derived type, the
2944 -- component inherited from the generic parent may not be visible
2945 -- in the actual, but the selected component is legal.
2947 declare
2948 Comp : Entity_Id;
2950 begin
2951 Comp :=
2952 First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
2953 while Present (Comp) loop
2954 if Chars (Comp) = Chars (Sel) then
2955 Set_Entity_With_Style_Check (Sel, Comp);
2956 Set_Etype (Sel, Etype (Comp));
2957 Set_Etype (N, Etype (Comp));
2958 exit;
2959 end if;
2961 Next_Component (Comp);
2962 end loop;
2964 pragma Assert (Etype (N) /= Any_Type);
2965 end;
2967 else
2968 if Ekind (Prefix_Type) = E_Record_Subtype then
2970 -- Check whether this is a component of the base type
2971 -- which is absent from a statically constrained subtype.
2972 -- This will raise constraint error at run-time, but is
2973 -- not a compile-time error. When the selector is illegal
2974 -- for base type as well fall through and generate a
2975 -- compilation error anyway.
2977 Comp := First_Component (Base_Type (Prefix_Type));
2978 while Present (Comp) loop
2979 if Chars (Comp) = Chars (Sel)
2980 and then Is_Visible_Component (Comp)
2981 then
2982 Set_Entity_With_Style_Check (Sel, Comp);
2983 Generate_Reference (Comp, Sel);
2984 Set_Etype (Sel, Etype (Comp));
2985 Set_Etype (N, Etype (Comp));
2987 -- Emit appropriate message. Gigi will replace the
2988 -- node subsequently with the appropriate Raise.
2990 Apply_Compile_Time_Constraint_Error
2991 (N, "component not present in }?",
2992 CE_Discriminant_Check_Failed,
2993 Ent => Prefix_Type, Rep => False);
2994 Set_Raises_Constraint_Error (N);
2995 return;
2996 end if;
2998 Next_Component (Comp);
2999 end loop;
3001 end if;
3003 Error_Msg_Node_2 := First_Subtype (Prefix_Type);
3004 Error_Msg_NE ("no selector& for}", N, Sel);
3006 Check_Misspelled_Selector (Entity_List, Sel);
3008 end if;
3010 Set_Entity (Sel, Any_Id);
3011 Set_Etype (Sel, Any_Type);
3012 end if;
3013 end Analyze_Selected_Component;
3015 ---------------------------
3016 -- Analyze_Short_Circuit --
3017 ---------------------------
3019 procedure Analyze_Short_Circuit (N : Node_Id) is
3020 L : constant Node_Id := Left_Opnd (N);
3021 R : constant Node_Id := Right_Opnd (N);
3022 Ind : Interp_Index;
3023 It : Interp;
3025 begin
3026 Analyze_Expression (L);
3027 Analyze_Expression (R);
3028 Set_Etype (N, Any_Type);
3030 if not Is_Overloaded (L) then
3032 if Root_Type (Etype (L)) = Standard_Boolean
3033 and then Has_Compatible_Type (R, Etype (L))
3034 then
3035 Add_One_Interp (N, Etype (L), Etype (L));
3036 end if;
3038 else
3039 Get_First_Interp (L, Ind, It);
3041 while Present (It.Typ) loop
3042 if Root_Type (It.Typ) = Standard_Boolean
3043 and then Has_Compatible_Type (R, It.Typ)
3044 then
3045 Add_One_Interp (N, It.Typ, It.Typ);
3046 end if;
3048 Get_Next_Interp (Ind, It);
3049 end loop;
3050 end if;
3052 -- Here we have failed to find an interpretation. Clearly we
3053 -- know that it is not the case that both operands can have
3054 -- an interpretation of Boolean, but this is by far the most
3055 -- likely intended interpretation. So we simply resolve both
3056 -- operands as Booleans, and at least one of these resolutions
3057 -- will generate an error message, and we do not need to give
3058 -- a further error message on the short circuit operation itself.
3060 if Etype (N) = Any_Type then
3061 Resolve (L, Standard_Boolean);
3062 Resolve (R, Standard_Boolean);
3063 Set_Etype (N, Standard_Boolean);
3064 end if;
3065 end Analyze_Short_Circuit;
3067 -------------------
3068 -- Analyze_Slice --
3069 -------------------
3071 procedure Analyze_Slice (N : Node_Id) is
3072 P : constant Node_Id := Prefix (N);
3073 D : constant Node_Id := Discrete_Range (N);
3074 Array_Type : Entity_Id;
3076 procedure Analyze_Overloaded_Slice;
3077 -- If the prefix is overloaded, select those interpretations that
3078 -- yield a one-dimensional array type.
3080 ------------------------------
3081 -- Analyze_Overloaded_Slice --
3082 ------------------------------
3084 procedure Analyze_Overloaded_Slice is
3085 I : Interp_Index;
3086 It : Interp;
3087 Typ : Entity_Id;
3089 begin
3090 Set_Etype (N, Any_Type);
3092 Get_First_Interp (P, I, It);
3093 while Present (It.Nam) loop
3094 Typ := It.Typ;
3096 if Is_Access_Type (Typ) then
3097 Typ := Designated_Type (Typ);
3098 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3099 end if;
3101 if Is_Array_Type (Typ)
3102 and then Number_Dimensions (Typ) = 1
3103 and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
3104 then
3105 Add_One_Interp (N, Typ, Typ);
3106 end if;
3108 Get_Next_Interp (I, It);
3109 end loop;
3111 if Etype (N) = Any_Type then
3112 Error_Msg_N ("expect array type in prefix of slice", N);
3113 end if;
3114 end Analyze_Overloaded_Slice;
3116 -- Start of processing for Analyze_Slice
3118 begin
3119 Analyze (P);
3120 Analyze (D);
3122 if Is_Overloaded (P) then
3123 Analyze_Overloaded_Slice;
3125 else
3126 Array_Type := Etype (P);
3127 Set_Etype (N, Any_Type);
3129 if Is_Access_Type (Array_Type) then
3130 Array_Type := Designated_Type (Array_Type);
3131 Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3132 end if;
3134 if not Is_Array_Type (Array_Type) then
3135 Wrong_Type (P, Any_Array);
3137 elsif Number_Dimensions (Array_Type) > 1 then
3138 Error_Msg_N
3139 ("type is not one-dimensional array in slice prefix", N);
3141 elsif not
3142 Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
3143 then
3144 Wrong_Type (D, Etype (First_Index (Array_Type)));
3146 else
3147 Set_Etype (N, Array_Type);
3148 end if;
3149 end if;
3150 end Analyze_Slice;
3152 -----------------------------
3153 -- Analyze_Type_Conversion --
3154 -----------------------------
3156 procedure Analyze_Type_Conversion (N : Node_Id) is
3157 Expr : constant Node_Id := Expression (N);
3158 T : Entity_Id;
3160 begin
3161 -- If Conversion_OK is set, then the Etype is already set, and the
3162 -- only processing required is to analyze the expression. This is
3163 -- used to construct certain "illegal" conversions which are not
3164 -- allowed by Ada semantics, but can be handled OK by Gigi, see
3165 -- Sinfo for further details.
3167 if Conversion_OK (N) then
3168 Analyze (Expr);
3169 return;
3170 end if;
3172 -- Otherwise full type analysis is required, as well as some semantic
3173 -- checks to make sure the argument of the conversion is appropriate.
3175 Find_Type (Subtype_Mark (N));
3176 T := Entity (Subtype_Mark (N));
3177 Set_Etype (N, T);
3178 Check_Fully_Declared (T, N);
3179 Analyze_Expression (Expr);
3180 Validate_Remote_Type_Type_Conversion (N);
3182 -- Only remaining step is validity checks on the argument. These
3183 -- are skipped if the conversion does not come from the source.
3185 if not Comes_From_Source (N) then
3186 return;
3188 elsif Nkind (Expr) = N_Null then
3189 Error_Msg_N ("argument of conversion cannot be null", N);
3190 Error_Msg_N ("\use qualified expression instead", N);
3191 Set_Etype (N, Any_Type);
3193 elsif Nkind (Expr) = N_Aggregate then
3194 Error_Msg_N ("argument of conversion cannot be aggregate", N);
3195 Error_Msg_N ("\use qualified expression instead", N);
3197 elsif Nkind (Expr) = N_Allocator then
3198 Error_Msg_N ("argument of conversion cannot be an allocator", N);
3199 Error_Msg_N ("\use qualified expression instead", N);
3201 elsif Nkind (Expr) = N_String_Literal then
3202 Error_Msg_N ("argument of conversion cannot be string literal", N);
3203 Error_Msg_N ("\use qualified expression instead", N);
3205 elsif Nkind (Expr) = N_Character_Literal then
3206 if Ada_Version = Ada_83 then
3207 Resolve (Expr, T);
3208 else
3209 Error_Msg_N ("argument of conversion cannot be character literal",
3211 Error_Msg_N ("\use qualified expression instead", N);
3212 end if;
3214 elsif Nkind (Expr) = N_Attribute_Reference
3215 and then
3216 (Attribute_Name (Expr) = Name_Access or else
3217 Attribute_Name (Expr) = Name_Unchecked_Access or else
3218 Attribute_Name (Expr) = Name_Unrestricted_Access)
3219 then
3220 Error_Msg_N ("argument of conversion cannot be access", N);
3221 Error_Msg_N ("\use qualified expression instead", N);
3222 end if;
3223 end Analyze_Type_Conversion;
3225 ----------------------
3226 -- Analyze_Unary_Op --
3227 ----------------------
3229 procedure Analyze_Unary_Op (N : Node_Id) is
3230 R : constant Node_Id := Right_Opnd (N);
3231 Op_Id : Entity_Id := Entity (N);
3233 begin
3234 Set_Etype (N, Any_Type);
3235 Candidate_Type := Empty;
3237 Analyze_Expression (R);
3239 if Present (Op_Id) then
3240 if Ekind (Op_Id) = E_Operator then
3241 Find_Unary_Types (R, Op_Id, N);
3242 else
3243 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3244 end if;
3246 else
3247 Op_Id := Get_Name_Entity_Id (Chars (N));
3248 while Present (Op_Id) loop
3249 if Ekind (Op_Id) = E_Operator then
3250 if No (Next_Entity (First_Entity (Op_Id))) then
3251 Find_Unary_Types (R, Op_Id, N);
3252 end if;
3254 elsif Is_Overloadable (Op_Id) then
3255 Analyze_User_Defined_Unary_Op (N, Op_Id);
3256 end if;
3258 Op_Id := Homonym (Op_Id);
3259 end loop;
3260 end if;
3262 Operator_Check (N);
3263 end Analyze_Unary_Op;
3265 ----------------------------------
3266 -- Analyze_Unchecked_Expression --
3267 ----------------------------------
3269 procedure Analyze_Unchecked_Expression (N : Node_Id) is
3270 begin
3271 Analyze (Expression (N), Suppress => All_Checks);
3272 Set_Etype (N, Etype (Expression (N)));
3273 Save_Interps (Expression (N), N);
3274 end Analyze_Unchecked_Expression;
3276 ---------------------------------------
3277 -- Analyze_Unchecked_Type_Conversion --
3278 ---------------------------------------
3280 procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
3281 begin
3282 Find_Type (Subtype_Mark (N));
3283 Analyze_Expression (Expression (N));
3284 Set_Etype (N, Entity (Subtype_Mark (N)));
3285 end Analyze_Unchecked_Type_Conversion;
3287 ------------------------------------
3288 -- Analyze_User_Defined_Binary_Op --
3289 ------------------------------------
3291 procedure Analyze_User_Defined_Binary_Op
3292 (N : Node_Id;
3293 Op_Id : Entity_Id)
3295 begin
3296 -- Only do analysis if the operator Comes_From_Source, since otherwise
3297 -- the operator was generated by the expander, and all such operators
3298 -- always refer to the operators in package Standard.
3300 if Comes_From_Source (N) then
3301 declare
3302 F1 : constant Entity_Id := First_Formal (Op_Id);
3303 F2 : constant Entity_Id := Next_Formal (F1);
3305 begin
3306 -- Verify that Op_Id is a visible binary function. Note that since
3307 -- we know Op_Id is overloaded, potentially use visible means use
3308 -- visible for sure (RM 9.4(11)).
3310 if Ekind (Op_Id) = E_Function
3311 and then Present (F2)
3312 and then (Is_Immediately_Visible (Op_Id)
3313 or else Is_Potentially_Use_Visible (Op_Id))
3314 and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
3315 and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
3316 then
3317 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3319 if Debug_Flag_E then
3320 Write_Str ("user defined operator ");
3321 Write_Name (Chars (Op_Id));
3322 Write_Str (" on node ");
3323 Write_Int (Int (N));
3324 Write_Eol;
3325 end if;
3326 end if;
3327 end;
3328 end if;
3329 end Analyze_User_Defined_Binary_Op;
3331 -----------------------------------
3332 -- Analyze_User_Defined_Unary_Op --
3333 -----------------------------------
3335 procedure Analyze_User_Defined_Unary_Op
3336 (N : Node_Id;
3337 Op_Id : Entity_Id)
3339 begin
3340 -- Only do analysis if the operator Comes_From_Source, since otherwise
3341 -- the operator was generated by the expander, and all such operators
3342 -- always refer to the operators in package Standard.
3344 if Comes_From_Source (N) then
3345 declare
3346 F : constant Entity_Id := First_Formal (Op_Id);
3348 begin
3349 -- Verify that Op_Id is a visible unary function. Note that since
3350 -- we know Op_Id is overloaded, potentially use visible means use
3351 -- visible for sure (RM 9.4(11)).
3353 if Ekind (Op_Id) = E_Function
3354 and then No (Next_Formal (F))
3355 and then (Is_Immediately_Visible (Op_Id)
3356 or else Is_Potentially_Use_Visible (Op_Id))
3357 and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
3358 then
3359 Add_One_Interp (N, Op_Id, Etype (Op_Id));
3360 end if;
3361 end;
3362 end if;
3363 end Analyze_User_Defined_Unary_Op;
3365 ---------------------------
3366 -- Check_Arithmetic_Pair --
3367 ---------------------------
3369 procedure Check_Arithmetic_Pair
3370 (T1, T2 : Entity_Id;
3371 Op_Id : Entity_Id;
3372 N : Node_Id)
3374 Op_Name : constant Name_Id := Chars (Op_Id);
3376 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
3377 -- Check whether the fixed-point type Typ has a user-defined operator
3378 -- (multiplication or division) that should hide the corresponding
3379 -- predefined operator. Used to implement Ada 2005 AI-264, to make
3380 -- such operators more visible and therefore useful.
3382 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
3383 -- Get specific type (i.e. non-universal type if there is one)
3385 ------------------
3386 -- Has_Fixed_Op --
3387 ------------------
3389 function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
3390 Ent : Entity_Id;
3391 F1 : Entity_Id;
3392 F2 : Entity_Id;
3394 begin
3395 -- The operation is treated as primitive if it is declared in the
3396 -- same scope as the type, and therefore on the same entity chain.
3398 Ent := Next_Entity (Typ);
3399 while Present (Ent) loop
3400 if Chars (Ent) = Chars (Op) then
3401 F1 := First_Formal (Ent);
3402 F2 := Next_Formal (F1);
3404 -- The operation counts as primitive if either operand or
3405 -- result are of the given type, and both operands are fixed
3406 -- point types.
3408 if (Etype (F1) = Typ
3409 and then Is_Fixed_Point_Type (Etype (F2)))
3411 or else
3412 (Etype (F2) = Typ
3413 and then Is_Fixed_Point_Type (Etype (F1)))
3415 or else
3416 (Etype (Ent) = Typ
3417 and then Is_Fixed_Point_Type (Etype (F1))
3418 and then Is_Fixed_Point_Type (Etype (F2)))
3419 then
3420 return True;
3421 end if;
3422 end if;
3424 Next_Entity (Ent);
3425 end loop;
3427 return False;
3428 end Has_Fixed_Op;
3430 -------------------
3431 -- Specific_Type --
3432 -------------------
3434 function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
3435 begin
3436 if T1 = Universal_Integer or else T1 = Universal_Real then
3437 return Base_Type (T2);
3438 else
3439 return Base_Type (T1);
3440 end if;
3441 end Specific_Type;
3443 -- Start of processing for Check_Arithmetic_Pair
3445 begin
3446 if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
3448 if Is_Numeric_Type (T1)
3449 and then Is_Numeric_Type (T2)
3450 and then (Covers (T1, T2) or else Covers (T2, T1))
3451 then
3452 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3453 end if;
3455 elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
3457 if Is_Fixed_Point_Type (T1)
3458 and then (Is_Fixed_Point_Type (T2)
3459 or else T2 = Universal_Real)
3460 then
3461 -- If Treat_Fixed_As_Integer is set then the Etype is already set
3462 -- and no further processing is required (this is the case of an
3463 -- operator constructed by Exp_Fixd for a fixed point operation)
3464 -- Otherwise add one interpretation with universal fixed result
3465 -- If the operator is given in functional notation, it comes
3466 -- from source and Fixed_As_Integer cannot apply.
3468 if (Nkind (N) not in N_Op
3469 or else not Treat_Fixed_As_Integer (N))
3470 and then
3471 (not (Ada_Version >= Ada_05 and then Has_Fixed_Op (T1, Op_Id))
3472 or else Nkind (Parent (N)) = N_Type_Conversion)
3473 then
3474 Add_One_Interp (N, Op_Id, Universal_Fixed);
3475 end if;
3477 elsif Is_Fixed_Point_Type (T2)
3478 and then (Nkind (N) not in N_Op
3479 or else not Treat_Fixed_As_Integer (N))
3480 and then T1 = Universal_Real
3481 and then
3482 (not (Ada_Version >= Ada_05 and then Has_Fixed_Op (T1, Op_Id))
3483 or else Nkind (Parent (N)) = N_Type_Conversion)
3484 then
3485 Add_One_Interp (N, Op_Id, Universal_Fixed);
3487 elsif Is_Numeric_Type (T1)
3488 and then Is_Numeric_Type (T2)
3489 and then (Covers (T1, T2) or else Covers (T2, T1))
3490 then
3491 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3493 elsif Is_Fixed_Point_Type (T1)
3494 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3495 or else T2 = Universal_Integer)
3496 then
3497 Add_One_Interp (N, Op_Id, T1);
3499 elsif T2 = Universal_Real
3500 and then Base_Type (T1) = Base_Type (Standard_Integer)
3501 and then Op_Name = Name_Op_Multiply
3502 then
3503 Add_One_Interp (N, Op_Id, Any_Fixed);
3505 elsif T1 = Universal_Real
3506 and then Base_Type (T2) = Base_Type (Standard_Integer)
3507 then
3508 Add_One_Interp (N, Op_Id, Any_Fixed);
3510 elsif Is_Fixed_Point_Type (T2)
3511 and then (Base_Type (T1) = Base_Type (Standard_Integer)
3512 or else T1 = Universal_Integer)
3513 and then Op_Name = Name_Op_Multiply
3514 then
3515 Add_One_Interp (N, Op_Id, T2);
3517 elsif T1 = Universal_Real and then T2 = Universal_Integer then
3518 Add_One_Interp (N, Op_Id, T1);
3520 elsif T2 = Universal_Real
3521 and then T1 = Universal_Integer
3522 and then Op_Name = Name_Op_Multiply
3523 then
3524 Add_One_Interp (N, Op_Id, T2);
3525 end if;
3527 elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
3529 -- Note: The fixed-point operands case with Treat_Fixed_As_Integer
3530 -- set does not require any special processing, since the Etype is
3531 -- already set (case of operation constructed by Exp_Fixed).
3533 if Is_Integer_Type (T1)
3534 and then (Covers (T1, T2) or else Covers (T2, T1))
3535 then
3536 Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3537 end if;
3539 elsif Op_Name = Name_Op_Expon then
3540 if Is_Numeric_Type (T1)
3541 and then not Is_Fixed_Point_Type (T1)
3542 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3543 or else T2 = Universal_Integer)
3544 then
3545 Add_One_Interp (N, Op_Id, Base_Type (T1));
3546 end if;
3548 else pragma Assert (Nkind (N) in N_Op_Shift);
3550 -- If not one of the predefined operators, the node may be one
3551 -- of the intrinsic functions. Its kind is always specific, and
3552 -- we can use it directly, rather than the name of the operation.
3554 if Is_Integer_Type (T1)
3555 and then (Base_Type (T2) = Base_Type (Standard_Integer)
3556 or else T2 = Universal_Integer)
3557 then
3558 Add_One_Interp (N, Op_Id, Base_Type (T1));
3559 end if;
3560 end if;
3561 end Check_Arithmetic_Pair;
3563 -------------------------------
3564 -- Check_Misspelled_Selector --
3565 -------------------------------
3567 procedure Check_Misspelled_Selector
3568 (Prefix : Entity_Id;
3569 Sel : Node_Id)
3571 Max_Suggestions : constant := 2;
3572 Nr_Of_Suggestions : Natural := 0;
3574 Suggestion_1 : Entity_Id := Empty;
3575 Suggestion_2 : Entity_Id := Empty;
3577 Comp : Entity_Id;
3579 begin
3580 -- All the components of the prefix of selector Sel are matched
3581 -- against Sel and a count is maintained of possible misspellings.
3582 -- When at the end of the analysis there are one or two (not more!)
3583 -- possible misspellings, these misspellings will be suggested as
3584 -- possible correction.
3586 if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
3588 -- Concurrent types should be handled as well ???
3590 return;
3591 end if;
3593 Get_Name_String (Chars (Sel));
3595 declare
3596 S : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3598 begin
3599 Comp := First_Entity (Prefix);
3600 while Nr_Of_Suggestions <= Max_Suggestions
3601 and then Present (Comp)
3602 loop
3603 if Is_Visible_Component (Comp) then
3604 Get_Name_String (Chars (Comp));
3606 if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
3607 Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
3609 case Nr_Of_Suggestions is
3610 when 1 => Suggestion_1 := Comp;
3611 when 2 => Suggestion_2 := Comp;
3612 when others => exit;
3613 end case;
3614 end if;
3615 end if;
3617 Comp := Next_Entity (Comp);
3618 end loop;
3620 -- Report at most two suggestions
3622 if Nr_Of_Suggestions = 1 then
3623 Error_Msg_NE ("\possible misspelling of&", Sel, Suggestion_1);
3625 elsif Nr_Of_Suggestions = 2 then
3626 Error_Msg_Node_2 := Suggestion_2;
3627 Error_Msg_NE ("\possible misspelling of& or&",
3628 Sel, Suggestion_1);
3629 end if;
3630 end;
3631 end Check_Misspelled_Selector;
3633 ----------------------
3634 -- Defined_In_Scope --
3635 ----------------------
3637 function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
3639 S1 : constant Entity_Id := Scope (Base_Type (T));
3640 begin
3641 return S1 = S
3642 or else (S1 = System_Aux_Id and then S = Scope (S1));
3643 end Defined_In_Scope;
3645 -------------------
3646 -- Diagnose_Call --
3647 -------------------
3649 procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
3650 Actual : Node_Id;
3651 X : Interp_Index;
3652 It : Interp;
3653 Success : Boolean;
3654 Err_Mode : Boolean;
3655 New_Nam : Node_Id;
3656 Void_Interp_Seen : Boolean := False;
3658 begin
3659 if Ada_Version >= Ada_05 then
3660 Actual := First_Actual (N);
3661 while Present (Actual) loop
3663 -- Ada 2005 (AI-50217): Post an error in case of premature
3664 -- usage of an entity from the limited view.
3666 if not Analyzed (Etype (Actual))
3667 and then From_With_Type (Etype (Actual))
3668 then
3669 Error_Msg_Qual_Level := 1;
3670 Error_Msg_NE
3671 ("missing with_clause for scope of imported type&",
3672 Actual, Etype (Actual));
3673 Error_Msg_Qual_Level := 0;
3674 end if;
3676 Next_Actual (Actual);
3677 end loop;
3678 end if;
3680 -- Analyze each candidate call again, with full error reporting
3681 -- for each.
3683 Error_Msg_N
3684 ("no candidate interpretations match the actuals:!", Nam);
3685 Err_Mode := All_Errors_Mode;
3686 All_Errors_Mode := True;
3688 -- If this is a call to an operation of a concurrent type,
3689 -- the failed interpretations have been removed from the
3690 -- name. Recover them to provide full diagnostics.
3692 if Nkind (Parent (Nam)) = N_Selected_Component then
3693 Set_Entity (Nam, Empty);
3694 New_Nam := New_Copy_Tree (Parent (Nam));
3695 Set_Is_Overloaded (New_Nam, False);
3696 Set_Is_Overloaded (Selector_Name (New_Nam), False);
3697 Set_Parent (New_Nam, Parent (Parent (Nam)));
3698 Analyze_Selected_Component (New_Nam);
3699 Get_First_Interp (Selector_Name (New_Nam), X, It);
3700 else
3701 Get_First_Interp (Nam, X, It);
3702 end if;
3704 while Present (It.Nam) loop
3705 if Etype (It.Nam) = Standard_Void_Type then
3706 Void_Interp_Seen := True;
3707 end if;
3709 Analyze_One_Call (N, It.Nam, True, Success);
3710 Get_Next_Interp (X, It);
3711 end loop;
3713 if Nkind (N) = N_Function_Call then
3714 Get_First_Interp (Nam, X, It);
3715 while Present (It.Nam) loop
3716 if Ekind (It.Nam) = E_Function
3717 or else Ekind (It.Nam) = E_Operator
3718 then
3719 return;
3720 else
3721 Get_Next_Interp (X, It);
3722 end if;
3723 end loop;
3725 -- If all interpretations are procedures, this deserves a
3726 -- more precise message. Ditto if this appears as the prefix
3727 -- of a selected component, which may be a lexical error.
3729 Error_Msg_N
3730 ("\context requires function call, found procedure name", Nam);
3732 if Nkind (Parent (N)) = N_Selected_Component
3733 and then N = Prefix (Parent (N))
3734 then
3735 Error_Msg_N (
3736 "\period should probably be semicolon", Parent (N));
3737 end if;
3739 elsif Nkind (N) = N_Procedure_Call_Statement
3740 and then not Void_Interp_Seen
3741 then
3742 Error_Msg_N (
3743 "\function name found in procedure call", Nam);
3744 end if;
3746 All_Errors_Mode := Err_Mode;
3747 end Diagnose_Call;
3749 ---------------------------
3750 -- Find_Arithmetic_Types --
3751 ---------------------------
3753 procedure Find_Arithmetic_Types
3754 (L, R : Node_Id;
3755 Op_Id : Entity_Id;
3756 N : Node_Id)
3758 Index1 : Interp_Index;
3759 Index2 : Interp_Index;
3760 It1 : Interp;
3761 It2 : Interp;
3763 procedure Check_Right_Argument (T : Entity_Id);
3764 -- Check right operand of operator
3766 --------------------------
3767 -- Check_Right_Argument --
3768 --------------------------
3770 procedure Check_Right_Argument (T : Entity_Id) is
3771 begin
3772 if not Is_Overloaded (R) then
3773 Check_Arithmetic_Pair (T, Etype (R), Op_Id, N);
3774 else
3775 Get_First_Interp (R, Index2, It2);
3776 while Present (It2.Typ) loop
3777 Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
3778 Get_Next_Interp (Index2, It2);
3779 end loop;
3780 end if;
3781 end Check_Right_Argument;
3783 -- Start processing for Find_Arithmetic_Types
3785 begin
3786 if not Is_Overloaded (L) then
3787 Check_Right_Argument (Etype (L));
3789 else
3790 Get_First_Interp (L, Index1, It1);
3792 while Present (It1.Typ) loop
3793 Check_Right_Argument (It1.Typ);
3794 Get_Next_Interp (Index1, It1);
3795 end loop;
3796 end if;
3798 end Find_Arithmetic_Types;
3800 ------------------------
3801 -- Find_Boolean_Types --
3802 ------------------------
3804 procedure Find_Boolean_Types
3805 (L, R : Node_Id;
3806 Op_Id : Entity_Id;
3807 N : Node_Id)
3809 Index : Interp_Index;
3810 It : Interp;
3812 procedure Check_Numeric_Argument (T : Entity_Id);
3813 -- Special case for logical operations one of whose operands is an
3814 -- integer literal. If both are literal the result is any modular type.
3816 ----------------------------
3817 -- Check_Numeric_Argument --
3818 ----------------------------
3820 procedure Check_Numeric_Argument (T : Entity_Id) is
3821 begin
3822 if T = Universal_Integer then
3823 Add_One_Interp (N, Op_Id, Any_Modular);
3825 elsif Is_Modular_Integer_Type (T) then
3826 Add_One_Interp (N, Op_Id, T);
3827 end if;
3828 end Check_Numeric_Argument;
3830 -- Start of processing for Find_Boolean_Types
3832 begin
3833 if not Is_Overloaded (L) then
3834 if Etype (L) = Universal_Integer
3835 or else Etype (L) = Any_Modular
3836 then
3837 if not Is_Overloaded (R) then
3838 Check_Numeric_Argument (Etype (R));
3840 else
3841 Get_First_Interp (R, Index, It);
3842 while Present (It.Typ) loop
3843 Check_Numeric_Argument (It.Typ);
3844 Get_Next_Interp (Index, It);
3845 end loop;
3846 end if;
3848 elsif Valid_Boolean_Arg (Etype (L))
3849 and then Has_Compatible_Type (R, Etype (L))
3850 then
3851 Add_One_Interp (N, Op_Id, Etype (L));
3852 end if;
3854 else
3855 Get_First_Interp (L, Index, It);
3856 while Present (It.Typ) loop
3857 if Valid_Boolean_Arg (It.Typ)
3858 and then Has_Compatible_Type (R, It.Typ)
3859 then
3860 Add_One_Interp (N, Op_Id, It.Typ);
3861 end if;
3863 Get_Next_Interp (Index, It);
3864 end loop;
3865 end if;
3866 end Find_Boolean_Types;
3868 ---------------------------
3869 -- Find_Comparison_Types --
3870 ---------------------------
3872 procedure Find_Comparison_Types
3873 (L, R : Node_Id;
3874 Op_Id : Entity_Id;
3875 N : Node_Id)
3877 Index : Interp_Index;
3878 It : Interp;
3879 Found : Boolean := False;
3880 I_F : Interp_Index;
3881 T_F : Entity_Id;
3882 Scop : Entity_Id := Empty;
3884 procedure Try_One_Interp (T1 : Entity_Id);
3885 -- Routine to try one proposed interpretation. Note that the context
3886 -- of the operator plays no role in resolving the arguments, so that
3887 -- if there is more than one interpretation of the operands that is
3888 -- compatible with comparison, the operation is ambiguous.
3890 --------------------
3891 -- Try_One_Interp --
3892 --------------------
3894 procedure Try_One_Interp (T1 : Entity_Id) is
3895 begin
3897 -- If the operator is an expanded name, then the type of the operand
3898 -- must be defined in the corresponding scope. If the type is
3899 -- universal, the context will impose the correct type.
3901 if Present (Scop)
3902 and then not Defined_In_Scope (T1, Scop)
3903 and then T1 /= Universal_Integer
3904 and then T1 /= Universal_Real
3905 and then T1 /= Any_String
3906 and then T1 /= Any_Composite
3907 then
3908 return;
3909 end if;
3911 if Valid_Comparison_Arg (T1)
3912 and then Has_Compatible_Type (R, T1)
3913 then
3914 if Found
3915 and then Base_Type (T1) /= Base_Type (T_F)
3916 then
3917 It := Disambiguate (L, I_F, Index, Any_Type);
3919 if It = No_Interp then
3920 Ambiguous_Operands (N);
3921 Set_Etype (L, Any_Type);
3922 return;
3924 else
3925 T_F := It.Typ;
3926 end if;
3928 else
3929 Found := True;
3930 T_F := T1;
3931 I_F := Index;
3932 end if;
3934 Set_Etype (L, T_F);
3935 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3937 end if;
3938 end Try_One_Interp;
3940 -- Start processing for Find_Comparison_Types
3942 begin
3943 -- If left operand is aggregate, the right operand has to
3944 -- provide a usable type for it.
3946 if Nkind (L) = N_Aggregate
3947 and then Nkind (R) /= N_Aggregate
3948 then
3949 Find_Comparison_Types (R, L, Op_Id, N);
3950 return;
3951 end if;
3953 if Nkind (N) = N_Function_Call
3954 and then Nkind (Name (N)) = N_Expanded_Name
3955 then
3956 Scop := Entity (Prefix (Name (N)));
3958 -- The prefix may be a package renaming, and the subsequent test
3959 -- requires the original package.
3961 if Ekind (Scop) = E_Package
3962 and then Present (Renamed_Entity (Scop))
3963 then
3964 Scop := Renamed_Entity (Scop);
3965 Set_Entity (Prefix (Name (N)), Scop);
3966 end if;
3967 end if;
3969 if not Is_Overloaded (L) then
3970 Try_One_Interp (Etype (L));
3972 else
3973 Get_First_Interp (L, Index, It);
3974 while Present (It.Typ) loop
3975 Try_One_Interp (It.Typ);
3976 Get_Next_Interp (Index, It);
3977 end loop;
3978 end if;
3979 end Find_Comparison_Types;
3981 ----------------------------------------
3982 -- Find_Non_Universal_Interpretations --
3983 ----------------------------------------
3985 procedure Find_Non_Universal_Interpretations
3986 (N : Node_Id;
3987 R : Node_Id;
3988 Op_Id : Entity_Id;
3989 T1 : Entity_Id)
3991 Index : Interp_Index;
3992 It : Interp;
3994 begin
3995 if T1 = Universal_Integer
3996 or else T1 = Universal_Real
3997 then
3998 if not Is_Overloaded (R) then
3999 Add_One_Interp
4000 (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
4001 else
4002 Get_First_Interp (R, Index, It);
4003 while Present (It.Typ) loop
4004 if Covers (It.Typ, T1) then
4005 Add_One_Interp
4006 (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
4007 end if;
4009 Get_Next_Interp (Index, It);
4010 end loop;
4011 end if;
4012 else
4013 Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
4014 end if;
4015 end Find_Non_Universal_Interpretations;
4017 ------------------------------
4018 -- Find_Concatenation_Types --
4019 ------------------------------
4021 procedure Find_Concatenation_Types
4022 (L, R : Node_Id;
4023 Op_Id : Entity_Id;
4024 N : Node_Id)
4026 Op_Type : constant Entity_Id := Etype (Op_Id);
4028 begin
4029 if Is_Array_Type (Op_Type)
4030 and then not Is_Limited_Type (Op_Type)
4032 and then (Has_Compatible_Type (L, Op_Type)
4033 or else
4034 Has_Compatible_Type (L, Component_Type (Op_Type)))
4036 and then (Has_Compatible_Type (R, Op_Type)
4037 or else
4038 Has_Compatible_Type (R, Component_Type (Op_Type)))
4039 then
4040 Add_One_Interp (N, Op_Id, Op_Type);
4041 end if;
4042 end Find_Concatenation_Types;
4044 -------------------------
4045 -- Find_Equality_Types --
4046 -------------------------
4048 procedure Find_Equality_Types
4049 (L, R : Node_Id;
4050 Op_Id : Entity_Id;
4051 N : Node_Id)
4053 Index : Interp_Index;
4054 It : Interp;
4055 Found : Boolean := False;
4056 I_F : Interp_Index;
4057 T_F : Entity_Id;
4058 Scop : Entity_Id := Empty;
4060 procedure Try_One_Interp (T1 : Entity_Id);
4061 -- The context of the operator plays no role in resolving the
4062 -- arguments, so that if there is more than one interpretation
4063 -- of the operands that is compatible with equality, the construct
4064 -- is ambiguous and an error can be emitted now, after trying to
4065 -- disambiguate, i.e. applying preference rules.
4067 --------------------
4068 -- Try_One_Interp --
4069 --------------------
4071 procedure Try_One_Interp (T1 : Entity_Id) is
4072 begin
4073 -- If the operator is an expanded name, then the type of the operand
4074 -- must be defined in the corresponding scope. If the type is
4075 -- universal, the context will impose the correct type. An anonymous
4076 -- type for a 'Access reference is also universal in this sense, as
4077 -- the actual type is obtained from context.
4079 if Present (Scop)
4080 and then not Defined_In_Scope (T1, Scop)
4081 and then T1 /= Universal_Integer
4082 and then T1 /= Universal_Real
4083 and then T1 /= Any_Access
4084 and then T1 /= Any_String
4085 and then T1 /= Any_Composite
4086 and then (Ekind (T1) /= E_Access_Subprogram_Type
4087 or else Comes_From_Source (T1))
4088 then
4089 return;
4090 end if;
4092 -- Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
4093 -- Do not allow anonymous access types in equality operators.
4095 if Ada_Version < Ada_05
4096 and then Ekind (T1) = E_Anonymous_Access_Type
4097 then
4098 return;
4099 end if;
4101 if T1 /= Standard_Void_Type
4102 and then not Is_Limited_Type (T1)
4103 and then not Is_Limited_Composite (T1)
4104 and then Has_Compatible_Type (R, T1)
4105 then
4106 if Found
4107 and then Base_Type (T1) /= Base_Type (T_F)
4108 then
4109 It := Disambiguate (L, I_F, Index, Any_Type);
4111 if It = No_Interp then
4112 Ambiguous_Operands (N);
4113 Set_Etype (L, Any_Type);
4114 return;
4116 else
4117 T_F := It.Typ;
4118 end if;
4120 else
4121 Found := True;
4122 T_F := T1;
4123 I_F := Index;
4124 end if;
4126 if not Analyzed (L) then
4127 Set_Etype (L, T_F);
4128 end if;
4130 Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4132 -- Case of operator was not visible, Etype still set to Any_Type
4134 if Etype (N) = Any_Type then
4135 Found := False;
4136 end if;
4137 end if;
4138 end Try_One_Interp;
4140 -- Start of processing for Find_Equality_Types
4142 begin
4143 -- If left operand is aggregate, the right operand has to
4144 -- provide a usable type for it.
4146 if Nkind (L) = N_Aggregate
4147 and then Nkind (R) /= N_Aggregate
4148 then
4149 Find_Equality_Types (R, L, Op_Id, N);
4150 return;
4151 end if;
4153 if Nkind (N) = N_Function_Call
4154 and then Nkind (Name (N)) = N_Expanded_Name
4155 then
4156 Scop := Entity (Prefix (Name (N)));
4158 -- The prefix may be a package renaming, and the subsequent test
4159 -- requires the original package.
4161 if Ekind (Scop) = E_Package
4162 and then Present (Renamed_Entity (Scop))
4163 then
4164 Scop := Renamed_Entity (Scop);
4165 Set_Entity (Prefix (Name (N)), Scop);
4166 end if;
4167 end if;
4169 if not Is_Overloaded (L) then
4170 Try_One_Interp (Etype (L));
4172 else
4173 Get_First_Interp (L, Index, It);
4174 while Present (It.Typ) loop
4175 Try_One_Interp (It.Typ);
4176 Get_Next_Interp (Index, It);
4177 end loop;
4178 end if;
4179 end Find_Equality_Types;
4181 -------------------------
4182 -- Find_Negation_Types --
4183 -------------------------
4185 procedure Find_Negation_Types
4186 (R : Node_Id;
4187 Op_Id : Entity_Id;
4188 N : Node_Id)
4190 Index : Interp_Index;
4191 It : Interp;
4193 begin
4194 if not Is_Overloaded (R) then
4195 if Etype (R) = Universal_Integer then
4196 Add_One_Interp (N, Op_Id, Any_Modular);
4197 elsif Valid_Boolean_Arg (Etype (R)) then
4198 Add_One_Interp (N, Op_Id, Etype (R));
4199 end if;
4201 else
4202 Get_First_Interp (R, Index, It);
4203 while Present (It.Typ) loop
4204 if Valid_Boolean_Arg (It.Typ) then
4205 Add_One_Interp (N, Op_Id, It.Typ);
4206 end if;
4208 Get_Next_Interp (Index, It);
4209 end loop;
4210 end if;
4211 end Find_Negation_Types;
4213 ----------------------
4214 -- Find_Unary_Types --
4215 ----------------------
4217 procedure Find_Unary_Types
4218 (R : Node_Id;
4219 Op_Id : Entity_Id;
4220 N : Node_Id)
4222 Index : Interp_Index;
4223 It : Interp;
4225 begin
4226 if not Is_Overloaded (R) then
4227 if Is_Numeric_Type (Etype (R)) then
4228 Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
4229 end if;
4231 else
4232 Get_First_Interp (R, Index, It);
4233 while Present (It.Typ) loop
4234 if Is_Numeric_Type (It.Typ) then
4235 Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
4236 end if;
4238 Get_Next_Interp (Index, It);
4239 end loop;
4240 end if;
4241 end Find_Unary_Types;
4243 ------------------
4244 -- Junk_Operand --
4245 ------------------
4247 function Junk_Operand (N : Node_Id) return Boolean is
4248 Enode : Node_Id;
4250 begin
4251 if Error_Posted (N) then
4252 return False;
4253 end if;
4255 -- Get entity to be tested
4257 if Is_Entity_Name (N)
4258 and then Present (Entity (N))
4259 then
4260 Enode := N;
4262 -- An odd case, a procedure name gets converted to a very peculiar
4263 -- function call, and here is where we detect this happening.
4265 elsif Nkind (N) = N_Function_Call
4266 and then Is_Entity_Name (Name (N))
4267 and then Present (Entity (Name (N)))
4268 then
4269 Enode := Name (N);
4271 -- Another odd case, there are at least some cases of selected
4272 -- components where the selected component is not marked as having
4273 -- an entity, even though the selector does have an entity
4275 elsif Nkind (N) = N_Selected_Component
4276 and then Present (Entity (Selector_Name (N)))
4277 then
4278 Enode := Selector_Name (N);
4280 else
4281 return False;
4282 end if;
4284 -- Now test the entity we got to see if it a bad case
4286 case Ekind (Entity (Enode)) is
4288 when E_Package =>
4289 Error_Msg_N
4290 ("package name cannot be used as operand", Enode);
4292 when Generic_Unit_Kind =>
4293 Error_Msg_N
4294 ("generic unit name cannot be used as operand", Enode);
4296 when Type_Kind =>
4297 Error_Msg_N
4298 ("subtype name cannot be used as operand", Enode);
4300 when Entry_Kind =>
4301 Error_Msg_N
4302 ("entry name cannot be used as operand", Enode);
4304 when E_Procedure =>
4305 Error_Msg_N
4306 ("procedure name cannot be used as operand", Enode);
4308 when E_Exception =>
4309 Error_Msg_N
4310 ("exception name cannot be used as operand", Enode);
4312 when E_Block | E_Label | E_Loop =>
4313 Error_Msg_N
4314 ("label name cannot be used as operand", Enode);
4316 when others =>
4317 return False;
4319 end case;
4321 return True;
4322 end Junk_Operand;
4324 --------------------
4325 -- Operator_Check --
4326 --------------------
4328 procedure Operator_Check (N : Node_Id) is
4329 begin
4330 Remove_Abstract_Operations (N);
4332 -- Test for case of no interpretation found for operator
4334 if Etype (N) = Any_Type then
4335 declare
4336 L : Node_Id;
4337 R : Node_Id;
4339 begin
4340 R := Right_Opnd (N);
4342 if Nkind (N) in N_Binary_Op then
4343 L := Left_Opnd (N);
4344 else
4345 L := Empty;
4346 end if;
4348 -- If either operand has no type, then don't complain further,
4349 -- since this simply means that we have a propragated error.
4351 if R = Error
4352 or else Etype (R) = Any_Type
4353 or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
4354 then
4355 return;
4357 -- We explicitly check for the case of concatenation of component
4358 -- with component to avoid reporting spurious matching array types
4359 -- that might happen to be lurking in distant packages (such as
4360 -- run-time packages). This also prevents inconsistencies in the
4361 -- messages for certain ACVC B tests, which can vary depending on
4362 -- types declared in run-time interfaces. Another improvement when
4363 -- aggregates are present is to look for a well-typed operand.
4365 elsif Present (Candidate_Type)
4366 and then (Nkind (N) /= N_Op_Concat
4367 or else Is_Array_Type (Etype (L))
4368 or else Is_Array_Type (Etype (R)))
4369 then
4371 if Nkind (N) = N_Op_Concat then
4372 if Etype (L) /= Any_Composite
4373 and then Is_Array_Type (Etype (L))
4374 then
4375 Candidate_Type := Etype (L);
4377 elsif Etype (R) /= Any_Composite
4378 and then Is_Array_Type (Etype (R))
4379 then
4380 Candidate_Type := Etype (R);
4381 end if;
4382 end if;
4384 Error_Msg_NE
4385 ("operator for} is not directly visible!",
4386 N, First_Subtype (Candidate_Type));
4387 Error_Msg_N ("use clause would make operation legal!", N);
4388 return;
4390 -- If either operand is a junk operand (e.g. package name), then
4391 -- post appropriate error messages, but do not complain further.
4393 -- Note that the use of OR in this test instead of OR ELSE
4394 -- is quite deliberate, we may as well check both operands
4395 -- in the binary operator case.
4397 elsif Junk_Operand (R)
4398 or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
4399 then
4400 return;
4402 -- If we have a logical operator, one of whose operands is
4403 -- Boolean, then we know that the other operand cannot resolve
4404 -- to Boolean (since we got no interpretations), but in that
4405 -- case we pretty much know that the other operand should be
4406 -- Boolean, so resolve it that way (generating an error)
4408 elsif Nkind (N) = N_Op_And
4409 or else
4410 Nkind (N) = N_Op_Or
4411 or else
4412 Nkind (N) = N_Op_Xor
4413 then
4414 if Etype (L) = Standard_Boolean then
4415 Resolve (R, Standard_Boolean);
4416 return;
4417 elsif Etype (R) = Standard_Boolean then
4418 Resolve (L, Standard_Boolean);
4419 return;
4420 end if;
4422 -- For an arithmetic operator or comparison operator, if one
4423 -- of the operands is numeric, then we know the other operand
4424 -- is not the same numeric type. If it is a non-numeric type,
4425 -- then probably it is intended to match the other operand.
4427 elsif Nkind (N) = N_Op_Add or else
4428 Nkind (N) = N_Op_Divide or else
4429 Nkind (N) = N_Op_Ge or else
4430 Nkind (N) = N_Op_Gt or else
4431 Nkind (N) = N_Op_Le or else
4432 Nkind (N) = N_Op_Lt or else
4433 Nkind (N) = N_Op_Mod or else
4434 Nkind (N) = N_Op_Multiply or else
4435 Nkind (N) = N_Op_Rem or else
4436 Nkind (N) = N_Op_Subtract
4437 then
4438 if Is_Numeric_Type (Etype (L))
4439 and then not Is_Numeric_Type (Etype (R))
4440 then
4441 Resolve (R, Etype (L));
4442 return;
4444 elsif Is_Numeric_Type (Etype (R))
4445 and then not Is_Numeric_Type (Etype (L))
4446 then
4447 Resolve (L, Etype (R));
4448 return;
4449 end if;
4451 -- Comparisons on A'Access are common enough to deserve a
4452 -- special message.
4454 elsif (Nkind (N) = N_Op_Eq or else
4455 Nkind (N) = N_Op_Ne)
4456 and then Ekind (Etype (L)) = E_Access_Attribute_Type
4457 and then Ekind (Etype (R)) = E_Access_Attribute_Type
4458 then
4459 Error_Msg_N
4460 ("two access attributes cannot be compared directly", N);
4461 Error_Msg_N
4462 ("\they must be converted to an explicit type for comparison",
4464 return;
4466 -- Another one for C programmers
4468 elsif Nkind (N) = N_Op_Concat
4469 and then Valid_Boolean_Arg (Etype (L))
4470 and then Valid_Boolean_Arg (Etype (R))
4471 then
4472 Error_Msg_N ("invalid operands for concatenation", N);
4473 Error_Msg_N ("\maybe AND was meant", N);
4474 return;
4476 -- A special case for comparison of access parameter with null
4478 elsif Nkind (N) = N_Op_Eq
4479 and then Is_Entity_Name (L)
4480 and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
4481 and then Nkind (Parameter_Type (Parent (Entity (L)))) =
4482 N_Access_Definition
4483 and then Nkind (R) = N_Null
4484 then
4485 Error_Msg_N ("access parameter is not allowed to be null", L);
4486 Error_Msg_N ("\(call would raise Constraint_Error)", L);
4487 return;
4488 end if;
4490 -- If we fall through then just give general message. Note
4491 -- that in the following messages, if the operand is overloaded
4492 -- we choose an arbitrary type to complain about, but that is
4493 -- probably more useful than not giving a type at all.
4495 if Nkind (N) in N_Unary_Op then
4496 Error_Msg_Node_2 := Etype (R);
4497 Error_Msg_N ("operator& not defined for}", N);
4498 return;
4500 else
4501 if Nkind (N) in N_Binary_Op then
4502 if not Is_Overloaded (L)
4503 and then not Is_Overloaded (R)
4504 and then Base_Type (Etype (L)) = Base_Type (Etype (R))
4505 then
4506 Error_Msg_Node_2 := First_Subtype (Etype (R));
4507 Error_Msg_N ("there is no applicable operator& for}", N);
4509 else
4510 Error_Msg_N ("invalid operand types for operator&", N);
4512 if Nkind (N) /= N_Op_Concat then
4513 Error_Msg_NE ("\left operand has}!", N, Etype (L));
4514 Error_Msg_NE ("\right operand has}!", N, Etype (R));
4515 end if;
4516 end if;
4517 end if;
4518 end if;
4519 end;
4520 end if;
4521 end Operator_Check;
4523 -----------------------------------------
4524 -- Process_Implicit_Dereference_Prefix --
4525 -----------------------------------------
4527 procedure Process_Implicit_Dereference_Prefix
4528 (E : Entity_Id;
4529 P : Entity_Id)
4531 Ref : Node_Id;
4533 begin
4534 if Present (E)
4535 and then (Operating_Mode = Check_Semantics or else not Expander_Active)
4536 then
4537 -- We create a dummy reference to E to ensure that the reference
4538 -- is not considered as part of an assignment (an implicit
4539 -- dereference can never assign to its prefix). The Comes_From_Source
4540 -- attribute needs to be propagated for accurate warnings.
4542 Ref := New_Reference_To (E, Sloc (P));
4543 Set_Comes_From_Source (Ref, Comes_From_Source (P));
4544 Generate_Reference (E, Ref);
4545 end if;
4546 end Process_Implicit_Dereference_Prefix;
4548 --------------------------------
4549 -- Remove_Abstract_Operations --
4550 --------------------------------
4552 procedure Remove_Abstract_Operations (N : Node_Id) is
4553 I : Interp_Index;
4554 It : Interp;
4555 Abstract_Op : Entity_Id := Empty;
4557 -- AI-310: If overloaded, remove abstract non-dispatching
4558 -- operations. We activate this if either extensions are
4559 -- enabled, or if the abstract operation in question comes
4560 -- from a predefined file. This latter test allows us to
4561 -- use abstract to make operations invisible to users. In
4562 -- particular, if type Address is non-private and abstract
4563 -- subprograms are used to hide its operators, they will be
4564 -- truly hidden.
4566 type Operand_Position is (First_Op, Second_Op);
4567 Univ_Type : constant Entity_Id := Universal_Interpretation (N);
4569 procedure Remove_Address_Interpretations (Op : Operand_Position);
4570 -- Ambiguities may arise when the operands are literal and the
4571 -- address operations in s-auxdec are visible. In that case, remove
4572 -- the interpretation of a literal as Address, to retain the semantics
4573 -- of Address as a private type.
4575 ------------------------------------
4576 -- Remove_Address_Interpretations --
4577 ------------------------------------
4579 procedure Remove_Address_Interpretations (Op : Operand_Position) is
4580 Formal : Entity_Id;
4582 begin
4583 if Is_Overloaded (N) then
4584 Get_First_Interp (N, I, It);
4585 while Present (It.Nam) loop
4586 Formal := First_Entity (It.Nam);
4588 if Op = Second_Op then
4589 Formal := Next_Entity (Formal);
4590 end if;
4592 if Is_Descendent_Of_Address (Etype (Formal)) then
4593 Remove_Interp (I);
4594 end if;
4596 Get_Next_Interp (I, It);
4597 end loop;
4598 end if;
4599 end Remove_Address_Interpretations;
4601 -- Start of processing for Remove_Abstract_Operations
4603 begin
4604 if Is_Overloaded (N) then
4605 Get_First_Interp (N, I, It);
4607 while Present (It.Nam) loop
4608 if not Is_Type (It.Nam)
4609 and then Is_Abstract (It.Nam)
4610 and then not Is_Dispatching_Operation (It.Nam)
4611 and then
4612 (Ada_Version >= Ada_05
4613 or else Is_Predefined_File_Name
4614 (Unit_File_Name (Get_Source_Unit (It.Nam))))
4616 then
4617 Abstract_Op := It.Nam;
4618 Remove_Interp (I);
4619 exit;
4620 end if;
4622 Get_Next_Interp (I, It);
4623 end loop;
4625 if No (Abstract_Op) then
4626 return;
4628 elsif Nkind (N) in N_Op then
4630 -- Remove interpretations that treat literals as addresses.
4631 -- This is never appropriate.
4633 if Nkind (N) in N_Binary_Op then
4634 declare
4635 U1 : constant Boolean :=
4636 Present (Universal_Interpretation (Right_Opnd (N)));
4637 U2 : constant Boolean :=
4638 Present (Universal_Interpretation (Left_Opnd (N)));
4640 begin
4641 if U1 and then not U2 then
4642 Remove_Address_Interpretations (Second_Op);
4644 elsif U2 and then not U1 then
4645 Remove_Address_Interpretations (First_Op);
4646 end if;
4648 if not (U1 and U2) then
4650 -- Remove corresponding predefined operator, which is
4651 -- always added to the overload set.
4653 Get_First_Interp (N, I, It);
4654 while Present (It.Nam) loop
4655 if Scope (It.Nam) = Standard_Standard
4656 and then Base_Type (It.Typ) =
4657 Base_Type (Etype (Abstract_Op))
4658 then
4659 Remove_Interp (I);
4660 end if;
4662 Get_Next_Interp (I, It);
4663 end loop;
4665 elsif Is_Overloaded (N)
4666 and then Present (Univ_Type)
4667 then
4668 -- If both operands have a universal interpretation,
4669 -- select the predefined operator and discard others.
4671 Get_First_Interp (N, I, It);
4673 while Present (It.Nam) loop
4674 if Scope (It.Nam) = Standard_Standard then
4675 Set_Etype (N, Univ_Type);
4676 Set_Entity (N, It.Nam);
4677 Set_Is_Overloaded (N, False);
4678 exit;
4679 end if;
4681 Get_Next_Interp (I, It);
4682 end loop;
4683 end if;
4684 end;
4685 end if;
4687 elsif Nkind (N) = N_Function_Call
4688 and then
4689 (Nkind (Name (N)) = N_Operator_Symbol
4690 or else
4691 (Nkind (Name (N)) = N_Expanded_Name
4692 and then
4693 Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
4694 then
4696 declare
4697 Arg1 : constant Node_Id := First (Parameter_Associations (N));
4698 U1 : constant Boolean :=
4699 Present (Universal_Interpretation (Arg1));
4700 U2 : constant Boolean :=
4701 Present (Next (Arg1)) and then
4702 Present (Universal_Interpretation (Next (Arg1)));
4704 begin
4705 if U1 and then not U2 then
4706 Remove_Address_Interpretations (First_Op);
4708 elsif U2 and then not U1 then
4709 Remove_Address_Interpretations (Second_Op);
4710 end if;
4712 if not (U1 and U2) then
4713 Get_First_Interp (N, I, It);
4714 while Present (It.Nam) loop
4715 if Scope (It.Nam) = Standard_Standard
4716 and then It.Typ = Base_Type (Etype (Abstract_Op))
4717 then
4718 Remove_Interp (I);
4719 end if;
4721 Get_Next_Interp (I, It);
4722 end loop;
4723 end if;
4724 end;
4725 end if;
4727 -- If the removal has left no valid interpretations, emit
4728 -- error message now and label node as illegal.
4730 if Present (Abstract_Op) then
4731 Get_First_Interp (N, I, It);
4733 if No (It.Nam) then
4735 -- Removal of abstract operation left no viable candidate
4737 Set_Etype (N, Any_Type);
4738 Error_Msg_Sloc := Sloc (Abstract_Op);
4739 Error_Msg_NE
4740 ("cannot call abstract operation& declared#", N, Abstract_Op);
4741 end if;
4742 end if;
4743 end if;
4744 end Remove_Abstract_Operations;
4746 -----------------------
4747 -- Try_Indirect_Call --
4748 -----------------------
4750 function Try_Indirect_Call
4751 (N : Node_Id;
4752 Nam : Entity_Id;
4753 Typ : Entity_Id) return Boolean
4755 Actual : Node_Id;
4756 Formal : Entity_Id;
4757 Call_OK : Boolean;
4759 begin
4760 Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
4761 Actual := First_Actual (N);
4762 Formal := First_Formal (Designated_Type (Typ));
4764 while Present (Actual)
4765 and then Present (Formal)
4766 loop
4767 if not Has_Compatible_Type (Actual, Etype (Formal)) then
4768 return False;
4769 end if;
4771 Next (Actual);
4772 Next_Formal (Formal);
4773 end loop;
4775 if No (Actual) and then No (Formal) then
4776 Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
4778 -- Nam is a candidate interpretation for the name in the call,
4779 -- if it is not an indirect call.
4781 if not Is_Type (Nam)
4782 and then Is_Entity_Name (Name (N))
4783 then
4784 Set_Entity (Name (N), Nam);
4785 end if;
4787 return True;
4788 else
4789 return False;
4790 end if;
4791 end Try_Indirect_Call;
4793 ----------------------
4794 -- Try_Indexed_Call --
4795 ----------------------
4797 function Try_Indexed_Call
4798 (N : Node_Id;
4799 Nam : Entity_Id;
4800 Typ : Entity_Id) return Boolean
4802 Actuals : constant List_Id := Parameter_Associations (N);
4803 Actual : Node_Id;
4804 Index : Entity_Id;
4806 begin
4807 Actual := First (Actuals);
4808 Index := First_Index (Typ);
4809 while Present (Actual)
4810 and then Present (Index)
4811 loop
4812 -- If the parameter list has a named association, the expression
4813 -- is definitely a call and not an indexed component.
4815 if Nkind (Actual) = N_Parameter_Association then
4816 return False;
4817 end if;
4819 if not Has_Compatible_Type (Actual, Etype (Index)) then
4820 return False;
4821 end if;
4823 Next (Actual);
4824 Next_Index (Index);
4825 end loop;
4827 if No (Actual) and then No (Index) then
4828 Add_One_Interp (N, Nam, Component_Type (Typ));
4830 -- Nam is a candidate interpretation for the name in the call,
4831 -- if it is not an indirect call.
4833 if not Is_Type (Nam)
4834 and then Is_Entity_Name (Name (N))
4835 then
4836 Set_Entity (Name (N), Nam);
4837 end if;
4839 return True;
4840 else
4841 return False;
4842 end if;
4843 end Try_Indexed_Call;
4845 --------------------------
4846 -- Try_Object_Operation --
4847 --------------------------
4849 function Try_Object_Operation (N : Node_Id) return Boolean is
4850 K : constant Node_Kind := Nkind (Parent (N));
4851 Loc : constant Source_Ptr := Sloc (N);
4852 Is_Subprg_Call : constant Boolean := K = N_Procedure_Call_Statement
4853 or else K = N_Function_Call;
4854 Obj : constant Node_Id := Prefix (N);
4855 Subprog : constant Node_Id := Selector_Name (N);
4857 Actual : Node_Id;
4858 New_Call_Node : Node_Id := Empty;
4859 Node_To_Replace : Node_Id;
4860 Obj_Type : Entity_Id := Etype (Obj);
4862 procedure Complete_Object_Operation
4863 (Call_Node : Node_Id;
4864 Node_To_Replace : Node_Id;
4865 Subprog : Node_Id);
4866 -- Make Subprog the name of Call_Node, replace Node_To_Replace with
4867 -- Call_Node, insert the object (or its dereference) as the first actual
4868 -- in the call, and complete the analysis of the call.
4870 procedure Transform_Object_Operation
4871 (Call_Node : out Node_Id;
4872 Node_To_Replace : out Node_Id;
4873 Subprog : Node_Id);
4874 -- Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
4875 -- Call_Node is the resulting subprogram call,
4876 -- Node_To_Replace is either N or the parent of N, and Subprog
4877 -- is a reference to the subprogram we are trying to match.
4879 function Try_Class_Wide_Operation
4880 (Call_Node : Node_Id;
4881 Node_To_Replace : Node_Id) return Boolean;
4882 -- Traverse all ancestor types looking for a class-wide subprogram
4883 -- for which the current operation is a valid non-dispatching call.
4885 function Try_Primitive_Operation
4886 (Call_Node : Node_Id;
4887 Node_To_Replace : Node_Id) return Boolean;
4888 -- Traverse the list of primitive subprograms looking for a dispatching
4889 -- operation for which the current node is a valid call .
4891 -------------------------------
4892 -- Complete_Object_Operation --
4893 -------------------------------
4895 procedure Complete_Object_Operation
4896 (Call_Node : Node_Id;
4897 Node_To_Replace : Node_Id;
4898 Subprog : Node_Id)
4900 First_Actual : Node_Id;
4902 begin
4903 First_Actual := First (Parameter_Associations (Call_Node));
4904 Set_Name (Call_Node, Subprog);
4906 if Nkind (N) = N_Selected_Component
4907 and then not Inside_A_Generic
4908 then
4909 Set_Entity (Selector_Name (N), Entity (Subprog));
4910 end if;
4912 -- If need be, rewrite first actual as an explicit dereference
4914 if not Is_Access_Type (Etype (First_Formal (Entity (Subprog))))
4915 and then Is_Access_Type (Etype (Obj))
4916 then
4917 Rewrite (First_Actual,
4918 Make_Explicit_Dereference (Sloc (Obj), Obj));
4919 Analyze (First_Actual);
4920 else
4921 Rewrite (First_Actual, Obj);
4922 end if;
4924 Rewrite (Node_To_Replace, Call_Node);
4925 Analyze (Node_To_Replace);
4926 end Complete_Object_Operation;
4928 --------------------------------
4929 -- Transform_Object_Operation --
4930 --------------------------------
4932 procedure Transform_Object_Operation
4933 (Call_Node : out Node_Id;
4934 Node_To_Replace : out Node_Id;
4935 Subprog : Node_Id)
4937 Parent_Node : constant Node_Id := Parent (N);
4939 Dummy : constant Node_Id := New_Copy (Obj);
4940 -- Placeholder used as a first parameter in the call, replaced
4941 -- eventually by the proper object.
4943 Actuals : List_Id;
4944 Actual : Node_Id;
4946 begin
4947 -- Common case covering 1) Call to a procedure and 2) Call to a
4948 -- function that has some additional actuals.
4950 if (Nkind (Parent_Node) = N_Function_Call
4951 or else
4952 Nkind (Parent_Node) = N_Procedure_Call_Statement)
4954 -- N is a selected component node containing the name of the
4955 -- subprogram. If N is not the name of the parent node we must
4956 -- not replace the parent node by the new construct. This case
4957 -- occurs when N is a parameterless call to a subprogram that
4958 -- is an actual parameter of a call to another subprogram. For
4959 -- example:
4960 -- Some_Subprogram (..., Obj.Operation, ...)
4962 and then Name (Parent_Node) = N
4963 then
4964 Node_To_Replace := Parent_Node;
4966 Actuals := Parameter_Associations (Parent_Node);
4968 if Present (Actuals) then
4969 Prepend (Dummy, Actuals);
4970 else
4971 Actuals := New_List (Dummy);
4972 end if;
4974 if Nkind (Parent_Node) = N_Procedure_Call_Statement then
4975 Call_Node :=
4976 Make_Procedure_Call_Statement (Loc,
4977 Name => New_Copy_Tree (Subprog),
4978 Parameter_Associations => Actuals);
4980 else
4981 Call_Node :=
4982 Make_Function_Call (Loc,
4983 Name => New_Copy_Tree (Subprog),
4984 Parameter_Associations => Actuals);
4986 end if;
4988 -- Before analysis, the function call appears as an indexed component
4989 -- if there are no named associations.
4991 elsif Nkind (Parent_Node) = N_Indexed_Component
4992 and then N = Prefix (Parent_Node)
4993 then
4994 Node_To_Replace := Parent_Node;
4996 Actuals := Expressions (Parent_Node);
4998 Actual := First (Actuals);
4999 while Present (Actual) loop
5000 Analyze (Actual);
5001 Next (Actual);
5002 end loop;
5004 Prepend (Dummy, Actuals);
5006 Call_Node :=
5007 Make_Function_Call (Loc,
5008 Name => New_Copy_Tree (Subprog),
5009 Parameter_Associations => Actuals);
5011 -- Parameterless call: Obj.F is rewritten as F (Obj)
5013 else
5014 Node_To_Replace := N;
5016 Call_Node :=
5017 Make_Function_Call (Loc,
5018 Name => New_Copy_Tree (Subprog),
5019 Parameter_Associations => New_List (Dummy));
5020 end if;
5021 end Transform_Object_Operation;
5023 ------------------------------
5024 -- Try_Class_Wide_Operation --
5025 ------------------------------
5027 function Try_Class_Wide_Operation
5028 (Call_Node : Node_Id;
5029 Node_To_Replace : Node_Id) return Boolean
5031 Anc_Type : Entity_Id;
5032 Hom : Entity_Id;
5033 Hom_Ref : Node_Id;
5034 Success : Boolean;
5036 begin
5037 -- Loop through ancestor types, traverse the homonym chain of the
5038 -- subprogram, and try out those homonyms whose first formal has the
5039 -- class-wide type of the ancestor.
5041 -- Should we verify that it is declared in the same package as the
5042 -- ancestor type ???
5044 Anc_Type := Obj_Type;
5046 loop
5047 Hom := Current_Entity (Subprog);
5048 while Present (Hom) loop
5049 if (Ekind (Hom) = E_Procedure
5050 or else
5051 Ekind (Hom) = E_Function)
5052 and then Present (First_Formal (Hom))
5053 and then Etype (First_Formal (Hom)) =
5054 Class_Wide_Type (Anc_Type)
5055 then
5056 Hom_Ref := New_Reference_To (Hom, Loc);
5058 Set_Etype (Call_Node, Any_Type);
5059 Set_Parent (Call_Node, Parent (Node_To_Replace));
5061 Set_Name (Call_Node, Hom_Ref);
5063 Analyze_One_Call
5064 (N => Call_Node,
5065 Nam => Hom,
5066 Report => False,
5067 Success => Success,
5068 Skip_First => True);
5070 if Success then
5072 -- Reformat into the proper call
5074 Complete_Object_Operation
5075 (Call_Node => Call_Node,
5076 Node_To_Replace => Node_To_Replace,
5077 Subprog => Hom_Ref);
5079 return True;
5080 end if;
5081 end if;
5083 Hom := Homonym (Hom);
5084 end loop;
5086 -- Examine other ancestor types
5088 exit when Etype (Anc_Type) = Anc_Type;
5089 Anc_Type := Etype (Anc_Type);
5090 end loop;
5092 -- Nothing matched
5094 return False;
5095 end Try_Class_Wide_Operation;
5097 -----------------------------
5098 -- Try_Primitive_Operation --
5099 -----------------------------
5101 function Try_Primitive_Operation
5102 (Call_Node : Node_Id;
5103 Node_To_Replace : Node_Id) return Boolean
5105 Elmt : Elmt_Id;
5106 Prim_Op : Entity_Id;
5107 Prim_Op_Ref : Node_Id;
5108 Success : Boolean;
5110 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
5111 -- Verify that the prefix, dereferenced if need be, is a valid
5112 -- controlling argument in a call to Op. The remaining actuals
5113 -- are checked in the subsequent call to Analyze_One_Call.
5115 -----------------------------
5116 -- Valid_First_Argument_Of --
5117 -----------------------------
5119 function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
5120 Typ : constant Entity_Id := Etype (First_Formal (Op));
5122 begin
5123 -- Simple case
5125 return Base_Type (Obj_Type) = Typ
5127 -- Prefix can be dereferenced
5129 or else
5130 (Is_Access_Type (Obj_Type)
5131 and then Designated_Type (Obj_Type) = Typ)
5133 -- Formal is an access parameter, for which the object
5134 -- can provide an access.
5136 or else
5137 (Ekind (Typ) = E_Anonymous_Access_Type
5138 and then Designated_Type (Typ) = Obj_Type);
5139 end Valid_First_Argument_Of;
5141 -- Start of processing for Try_Primitive_Operation
5143 begin
5144 -- Look for the subprogram in the list of primitive operations
5146 Elmt := First_Elmt (Primitive_Operations (Obj_Type));
5147 while Present (Elmt) loop
5148 Prim_Op := Node (Elmt);
5150 if Chars (Prim_Op) = Chars (Subprog)
5151 and then Present (First_Formal (Prim_Op))
5152 and then Valid_First_Argument_Of (Prim_Op)
5153 then
5154 Prim_Op_Ref := New_Reference_To (Prim_Op, Loc);
5156 Set_Etype (Call_Node, Any_Type);
5157 Set_Parent (Call_Node, Parent (Node_To_Replace));
5159 Set_Name (Call_Node, Prim_Op_Ref);
5161 Analyze_One_Call
5162 (N => Call_Node,
5163 Nam => Prim_Op,
5164 Report => False,
5165 Success => Success,
5166 Skip_First => True);
5168 if Success then
5169 Complete_Object_Operation
5170 (Call_Node => Call_Node,
5171 Node_To_Replace => Node_To_Replace,
5172 Subprog => Prim_Op_Ref);
5174 return True;
5175 end if;
5176 end if;
5178 Next_Elmt (Elmt);
5179 end loop;
5181 return False;
5182 end Try_Primitive_Operation;
5184 -- Start of processing for Try_Object_Operation
5186 begin
5187 if Is_Access_Type (Obj_Type) then
5188 Obj_Type := Designated_Type (Obj_Type);
5189 end if;
5191 if Ekind (Obj_Type) = E_Private_Subtype then
5192 Obj_Type := Base_Type (Obj_Type);
5193 end if;
5195 if Is_Class_Wide_Type (Obj_Type) then
5196 Obj_Type := Etype (Class_Wide_Type (Obj_Type));
5197 end if;
5199 -- The type may have be obtained through a limited_with clause,
5200 -- in which case the primitive operations are available on its
5201 -- non-limited view.
5203 if Ekind (Obj_Type) = E_Incomplete_Type
5204 and then From_With_Type (Obj_Type)
5205 then
5206 Obj_Type := Non_Limited_View (Obj_Type);
5207 end if;
5209 if not Is_Tagged_Type (Obj_Type) then
5210 return False;
5211 end if;
5213 -- Analyze the actuals if node is know to be a subprogram call
5215 if Is_Subprg_Call and then N = Name (Parent (N)) then
5216 Actual := First (Parameter_Associations (Parent (N)));
5217 while Present (Actual) loop
5218 Analyze_Expression (Actual);
5219 Next (Actual);
5220 end loop;
5221 end if;
5223 Analyze_Expression (Obj);
5225 -- Build a subprogram call node, using a copy of Obj as its first
5226 -- actual. This is a placeholder, to be replaced by an explicit
5227 -- dereference when needed.
5229 Transform_Object_Operation
5230 (Call_Node => New_Call_Node,
5231 Node_To_Replace => Node_To_Replace,
5232 Subprog => Subprog);
5234 Set_Etype (New_Call_Node, Any_Type);
5235 Set_Parent (New_Call_Node, Parent (Node_To_Replace));
5237 return
5238 Try_Primitive_Operation
5239 (Call_Node => New_Call_Node,
5240 Node_To_Replace => Node_To_Replace)
5242 or else
5243 Try_Class_Wide_Operation
5244 (Call_Node => New_Call_Node,
5245 Node_To_Replace => Node_To_Replace);
5246 end Try_Object_Operation;
5248 end Sem_Ch4;