OSDN Git Service

* a-filico.ads, a-filico.adb: fix incorrect header.
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_ch4.adb
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-2004, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Atree;    use Atree;
28 with Checks;   use Checks;
29 with Debug;    use Debug;
30 with Einfo;    use Einfo;
31 with Elists;   use Elists;
32 with Errout;   use Errout;
33 with Exp_Util; use Exp_Util;
34 with Fname;    use Fname;
35 with Itypes;   use Itypes;
36 with Lib;      use Lib;
37 with Lib.Xref; use Lib.Xref;
38 with Namet;    use Namet;
39 with Nlists;   use Nlists;
40 with Nmake;    use Nmake;
41 with Opt;      use Opt;
42 with Output;   use Output;
43 with Restrict; use Restrict;
44 with Rident;   use Rident;
45 with Sem;      use Sem;
46 with Sem_Cat;  use Sem_Cat;
47 with Sem_Ch3;  use Sem_Ch3;
48 with Sem_Ch8;  use Sem_Ch8;
49 with Sem_Dist; use Sem_Dist;
50 with Sem_Eval; use Sem_Eval;
51 with Sem_Res;  use Sem_Res;
52 with Sem_Util; use Sem_Util;
53 with Sem_Type; use Sem_Type;
54 with Stand;    use Stand;
55 with Sinfo;    use Sinfo;
56 with Snames;   use Snames;
57 with Tbuild;   use Tbuild;
58
59 with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
60
61 package body Sem_Ch4 is
62
63    -----------------------
64    -- Local Subprograms --
65    -----------------------
66
67    procedure Analyze_Expression (N : Node_Id);
68    --  For expressions that are not names, this is just a call to analyze.
69    --  If the expression is a name, it may be a call to a parameterless
70    --  function, and if so must be converted into an explicit call node
71    --  and analyzed as such. This deproceduring must be done during the first
72    --  pass of overload resolution, because otherwise a procedure call with
73    --  overloaded actuals may fail to resolve. See 4327-001 for an example.
74
75    procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
76    --  Analyze a call of the form "+"(x, y), etc. The prefix of the call
77    --  is an operator name or an expanded name whose selector is an operator
78    --  name, and one possible interpretation is as a predefined operator.
79
80    procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
81    --  If the prefix of a selected_component is overloaded, the proper
82    --  interpretation that yields a record type with the proper selector
83    --  name must be selected.
84
85    procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
86    --  Procedure to analyze a user defined binary operator, which is resolved
87    --  like a function, but instead of a list of actuals it is presented
88    --  with the left and right operands of an operator node.
89
90    procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
91    --  Procedure to analyze a user defined unary operator, which is resolved
92    --  like a function, but instead of a list of actuals, it is presented with
93    --  the operand of the operator node.
94
95    procedure Ambiguous_Operands (N : Node_Id);
96    --  for equality, membership, and comparison operators with overloaded
97    --  arguments, list possible interpretations.
98
99    procedure Analyze_One_Call
100       (N       : Node_Id;
101        Nam     : Entity_Id;
102        Report  : Boolean;
103        Success : out Boolean);
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.
108    --
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.
114
115    procedure Check_Misspelled_Selector
116      (Prefix : Entity_Id;
117       Sel    : Node_Id);
118    --  Give possible misspelling diagnostic if Sel is likely to be
119    --  a misspelling of one of the selectors of the Prefix.
120    --  This is called by Analyze_Selected_Component after producing
121    --  an invalid selector error message.
122
123    function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
124    --  Verify that type T is declared in scope S. Used to find intepretations
125    --  for operators given by expanded names. This is abstracted as a separate
126    --  function to handle extensions to System, where S is System, but T is
127    --  declared in the extension.
128
129    procedure Find_Arithmetic_Types
130      (L, R  : Node_Id;
131       Op_Id : Entity_Id;
132       N     : Node_Id);
133    --  L and R are the operands of an arithmetic operator. Find
134    --  consistent pairs of interpretations for L and R that have a
135    --  numeric type consistent with the semantics of the operator.
136
137    procedure Find_Comparison_Types
138      (L, R  : Node_Id;
139       Op_Id : Entity_Id;
140       N     : Node_Id);
141    --  L and R are operands of a comparison operator. Find consistent
142    --  pairs of interpretations for L and R.
143
144    procedure Find_Concatenation_Types
145      (L, R  : Node_Id;
146       Op_Id : Entity_Id;
147       N     : Node_Id);
148    --  For the four varieties of concatenation.
149
150    procedure Find_Equality_Types
151      (L, R  : Node_Id;
152       Op_Id : Entity_Id;
153       N     : Node_Id);
154    --  Ditto for equality operators.
155
156    procedure Find_Boolean_Types
157      (L, R  : Node_Id;
158       Op_Id : Entity_Id;
159       N     : Node_Id);
160    --  Ditto for binary logical operations.
161
162    procedure Find_Negation_Types
163      (R     : Node_Id;
164       Op_Id : Entity_Id;
165       N     : Node_Id);
166    --  Find consistent interpretation for operand of negation operator.
167
168    procedure Find_Non_Universal_Interpretations
169      (N     : Node_Id;
170       R     : Node_Id;
171       Op_Id : Entity_Id;
172       T1    : Entity_Id);
173    --  For equality and comparison operators, the result is always boolean,
174    --  and the legality of the operation is determined from the visibility
175    --  of the operand types. If one of the operands has a universal interpre-
176    --  tation,  the legality check uses some compatible non-universal
177    --  interpretation of the other operand. N can be an operator node, or
178    --  a function call whose name is an operator designator.
179
180    procedure Find_Unary_Types
181      (R     : Node_Id;
182       Op_Id : Entity_Id;
183       N     : Node_Id);
184    --  Unary arithmetic types: plus, minus, abs.
185
186    procedure Check_Arithmetic_Pair
187      (T1, T2 : Entity_Id;
188       Op_Id  : Entity_Id;
189       N      : Node_Id);
190    --  Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
191    --  types for left and right operand. Determine whether they constitute
192    --  a valid pair for the given operator, and record the corresponding
193    --  interpretation of the operator node. The node N may be an operator
194    --  node (the usual case) or a function call whose prefix is an operator
195    --  designator. In  both cases Op_Id is the operator name itself.
196
197    procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
198    --  Give detailed information on overloaded call where none of the
199    --  interpretations match. N is the call node, Nam the designator for
200    --  the overloaded entity being called.
201
202    function Junk_Operand (N : Node_Id) return Boolean;
203    --  Test for an operand that is an inappropriate entity (e.g. a package
204    --  name or a label). If so, issue an error message and return True. If
205    --  the operand is not an inappropriate entity kind, return False.
206
207    procedure Operator_Check (N : Node_Id);
208    --  Verify that an operator has received some valid interpretation.
209    --  If none was found, determine whether a use clause would make the
210    --  operation legal. The variable Candidate_Type (defined in Sem_Type) is
211    --  set for every type compatible with the operator, even if the operator
212    --  for the type is not directly visible. The routine uses this type to emit
213    --  a more informative message.
214
215    procedure Remove_Abstract_Operations (N : Node_Id);
216    --  Ada 2005: implementation of AI-310. An abstract non-dispatching
217    --  operation is not a candidate interpretation.
218
219    function Try_Indexed_Call
220      (N   : Node_Id;
221       Nam : Entity_Id;
222       Typ : Entity_Id) return Boolean;
223    --  If a function has defaults for all its actuals, a call to it may
224    --  in fact be an indexing on the result of the call. Try_Indexed_Call
225    --  attempts the interpretation as an indexing, prior to analysis as
226    --  a call. If both are possible,  the node is overloaded with both
227    --  interpretations (same symbol but two different types).
228
229    function Try_Indirect_Call
230      (N   : Node_Id;
231       Nam : Entity_Id;
232       Typ : Entity_Id) return Boolean;
233    --  Similarly, a function F that needs no actuals can return an access
234    --  to a subprogram, and the call F (X)  interpreted as F.all (X). In
235    --  this case the call may be overloaded with both interpretations.
236
237    function Try_Object_Operation (N : Node_Id) return Boolean;
238    --  Ada 2005 (AI-252): Give support to the object operation notation
239
240    ------------------------
241    -- Ambiguous_Operands --
242    ------------------------
243
244    procedure Ambiguous_Operands (N : Node_Id) is
245       procedure List_Operand_Interps (Opnd : Node_Id);
246
247       --------------------------
248       -- List_Operand_Interps --
249       --------------------------
250
251       procedure List_Operand_Interps (Opnd : Node_Id) is
252          Nam   : Node_Id;
253          Err   : Node_Id := N;
254
255       begin
256          if Is_Overloaded (Opnd) then
257             if Nkind (Opnd) in N_Op then
258                Nam := Opnd;
259             elsif Nkind (Opnd) = N_Function_Call then
260                Nam := Name (Opnd);
261             else
262                return;
263             end if;
264
265          else
266             return;
267          end if;
268
269          if Opnd = Left_Opnd (N) then
270             Error_Msg_N
271               ("\left operand has the following interpretations", N);
272          else
273             Error_Msg_N
274               ("\right operand has the following interpretations", N);
275             Err := Opnd;
276          end if;
277
278          List_Interps (Nam, Err);
279       end List_Operand_Interps;
280
281    --  Start of processing for Ambiguous_Operands
282
283    begin
284       if Nkind (N) = N_In
285         or else Nkind (N) = N_Not_In
286       then
287          Error_Msg_N ("ambiguous operands for membership",  N);
288
289       elsif Nkind (N) = N_Op_Eq
290         or else Nkind (N) = N_Op_Ne
291       then
292          Error_Msg_N ("ambiguous operands for equality",  N);
293
294       else
295          Error_Msg_N ("ambiguous operands for comparison",  N);
296       end if;
297
298       if All_Errors_Mode then
299          List_Operand_Interps (Left_Opnd  (N));
300          List_Operand_Interps (Right_Opnd (N));
301       else
302          Error_Msg_N ("\use -gnatf switch for details", N);
303       end if;
304    end Ambiguous_Operands;
305
306    -----------------------
307    -- Analyze_Aggregate --
308    -----------------------
309
310    --  Most of the analysis of Aggregates requires that the type be known,
311    --  and is therefore put off until resolution.
312
313    procedure Analyze_Aggregate (N : Node_Id) is
314    begin
315       if No (Etype (N)) then
316          Set_Etype (N, Any_Composite);
317       end if;
318    end Analyze_Aggregate;
319
320    -----------------------
321    -- Analyze_Allocator --
322    -----------------------
323
324    procedure Analyze_Allocator (N : Node_Id) is
325       Loc      : constant Source_Ptr := Sloc (N);
326       Sav_Errs : constant Nat        := Serious_Errors_Detected;
327       E        : Node_Id             := Expression (N);
328       Acc_Type : Entity_Id;
329       Type_Id  : Entity_Id;
330
331    begin
332       Check_Restriction (No_Allocators, N);
333
334       if Nkind (E) = N_Qualified_Expression then
335          Acc_Type := Create_Itype (E_Allocator_Type, N);
336          Set_Etype (Acc_Type, Acc_Type);
337          Init_Size_Align (Acc_Type);
338          Find_Type (Subtype_Mark (E));
339          Type_Id := Entity (Subtype_Mark (E));
340          Check_Fully_Declared (Type_Id, N);
341          Set_Directly_Designated_Type (Acc_Type, Type_Id);
342
343          if Is_Limited_Type (Type_Id)
344            and then Comes_From_Source (N)
345            and then not In_Instance_Body
346          then
347             --  Ada 2005 (AI-287): Do not post an error if the expression
348             --  corresponds to a limited aggregate. Limited aggregates
349             --  are checked in sem_aggr in a per-component manner
350             --  (compare with handling of Get_Value subprogram).
351
352             if Ada_Version >= Ada_05
353               and then Nkind (Expression (E)) = N_Aggregate
354             then
355                null;
356             else
357                Error_Msg_N ("initialization not allowed for limited types", N);
358                Explain_Limited_Type (Type_Id, N);
359             end if;
360          end if;
361
362          Analyze_And_Resolve (Expression (E), Type_Id);
363
364          --  A qualified expression requires an exact match of the type,
365          --  class-wide matching is not allowed.
366
367          if Is_Class_Wide_Type (Type_Id)
368            and then Base_Type (Etype (Expression (E))) /= Base_Type (Type_Id)
369          then
370             Wrong_Type (Expression (E), Type_Id);
371          end if;
372
373          Check_Non_Static_Context (Expression (E));
374
375          --  We don't analyze the qualified expression itself because it's
376          --  part of the allocator
377
378          Set_Etype  (E, Type_Id);
379
380       --  Case where no qualified expression is present
381
382       else
383          declare
384             Def_Id : Entity_Id;
385
386          begin
387             --  If the allocator includes a N_Subtype_Indication then a
388             --  constraint is present, otherwise the node is a subtype mark.
389             --  Introduce an explicit subtype declaration into the tree
390             --  defining some anonymous subtype and rewrite the allocator to
391             --  use this subtype rather than the subtype indication.
392
393             --  It is important to introduce the explicit subtype declaration
394             --  so that the bounds of the subtype indication are attached to
395             --  the tree in case the allocator is inside a generic unit.
396
397             if Nkind (E) = N_Subtype_Indication then
398
399                --  A constraint is only allowed for a composite type in Ada
400                --  95. In Ada 83, a constraint is also allowed for an
401                --  access-to-composite type, but the constraint is ignored.
402
403                Find_Type (Subtype_Mark (E));
404
405                if Is_Elementary_Type (Entity (Subtype_Mark (E))) then
406                   if not (Ada_Version = Ada_83
407                            and then Is_Access_Type (Entity (Subtype_Mark (E))))
408                   then
409                      Error_Msg_N ("constraint not allowed here", E);
410
411                      if Nkind (Constraint (E))
412                        = N_Index_Or_Discriminant_Constraint
413                      then
414                         Error_Msg_N
415                           ("\if qualified expression was meant, " &
416                               "use apostrophe", Constraint (E));
417                      end if;
418                   end if;
419
420                   --  Get rid of the bogus constraint:
421
422                   Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
423                   Analyze_Allocator (N);
424                   return;
425                end if;
426
427                if Expander_Active then
428                   Def_Id :=
429                     Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
430
431                   Insert_Action (E,
432                     Make_Subtype_Declaration (Loc,
433                       Defining_Identifier => Def_Id,
434                       Subtype_Indication  => Relocate_Node (E)));
435
436                   if Sav_Errs /= Serious_Errors_Detected
437                     and then Nkind (Constraint (E))
438                       = N_Index_Or_Discriminant_Constraint
439                   then
440                      Error_Msg_N
441                        ("if qualified expression was meant, " &
442                            "use apostrophe!", Constraint (E));
443                   end if;
444
445                   E := New_Occurrence_Of (Def_Id, Loc);
446                   Rewrite (Expression (N), E);
447                end if;
448             end if;
449
450             Type_Id := Process_Subtype (E, N);
451             Acc_Type := Create_Itype (E_Allocator_Type, N);
452             Set_Etype                    (Acc_Type, Acc_Type);
453             Init_Size_Align              (Acc_Type);
454             Set_Directly_Designated_Type (Acc_Type, Type_Id);
455             Check_Fully_Declared (Type_Id, N);
456
457             --  Ada 2005 (AI-231)
458
459             if Can_Never_Be_Null (Type_Id) then
460                Error_Msg_N ("(Ada 2005) qualified expression required",
461                             Expression (N));
462             end if;
463
464             --  Check restriction against dynamically allocated protected
465             --  objects. Note that when limited aggregates are supported,
466             --  a similar test should be applied to an allocator with a
467             --  qualified expression ???
468
469             if Is_Protected_Type (Type_Id) then
470                Check_Restriction (No_Protected_Type_Allocators, N);
471             end if;
472
473             --  Check for missing initialization. Skip this check if we already
474             --  had errors on analyzing the allocator, since in that case these
475             --  are probably cascaded errors
476
477             if Is_Indefinite_Subtype (Type_Id)
478               and then Serious_Errors_Detected = Sav_Errs
479             then
480                if Is_Class_Wide_Type (Type_Id) then
481                   Error_Msg_N
482                     ("initialization required in class-wide allocation", N);
483                else
484                   Error_Msg_N
485                     ("initialization required in unconstrained allocation", N);
486                end if;
487             end if;
488          end;
489       end if;
490
491       if Is_Abstract (Type_Id) then
492          Error_Msg_N ("cannot allocate abstract object", E);
493       end if;
494
495       if Has_Task (Designated_Type (Acc_Type)) then
496          Check_Restriction (No_Tasking, N);
497          Check_Restriction (Max_Tasks, N);
498          Check_Restriction (No_Task_Allocators, N);
499       end if;
500
501       Set_Etype (N, Acc_Type);
502
503       if not Is_Library_Level_Entity (Acc_Type) then
504          Check_Restriction (No_Local_Allocators, N);
505       end if;
506
507       --  Ada 2005 (AI-231): Static checks
508
509       if Ada_Version >= Ada_05
510         and then (Null_Exclusion_Present (N)
511                     or else Can_Never_Be_Null (Etype (N)))
512       then
513          Null_Exclusion_Static_Checks (N);
514       end if;
515
516       if Serious_Errors_Detected > Sav_Errs then
517          Set_Error_Posted (N);
518          Set_Etype (N, Any_Type);
519       end if;
520    end Analyze_Allocator;
521
522    ---------------------------
523    -- Analyze_Arithmetic_Op --
524    ---------------------------
525
526    procedure Analyze_Arithmetic_Op (N : Node_Id) is
527       L     : constant Node_Id := Left_Opnd (N);
528       R     : constant Node_Id := Right_Opnd (N);
529       Op_Id : Entity_Id;
530
531    begin
532       Candidate_Type := Empty;
533       Analyze_Expression (L);
534       Analyze_Expression (R);
535
536       --  If the entity is already set, the node is the instantiation of
537       --  a generic node with a non-local reference, or was manufactured
538       --  by a call to Make_Op_xxx. In either case the entity is known to
539       --  be valid, and we do not need to collect interpretations, instead
540       --  we just get the single possible interpretation.
541
542       Op_Id := Entity (N);
543
544       if Present (Op_Id) then
545          if Ekind (Op_Id) = E_Operator then
546
547             if (Nkind (N) = N_Op_Divide   or else
548                 Nkind (N) = N_Op_Mod      or else
549                 Nkind (N) = N_Op_Multiply or else
550                 Nkind (N) = N_Op_Rem)
551               and then Treat_Fixed_As_Integer (N)
552             then
553                null;
554             else
555                Set_Etype (N, Any_Type);
556                Find_Arithmetic_Types (L, R, Op_Id, N);
557             end if;
558
559          else
560             Set_Etype (N, Any_Type);
561             Add_One_Interp (N, Op_Id, Etype (Op_Id));
562          end if;
563
564       --  Entity is not already set, so we do need to collect interpretations
565
566       else
567          Op_Id := Get_Name_Entity_Id (Chars (N));
568          Set_Etype (N, Any_Type);
569
570          while Present (Op_Id) loop
571             if Ekind (Op_Id) = E_Operator
572               and then Present (Next_Entity (First_Entity (Op_Id)))
573             then
574                Find_Arithmetic_Types (L, R, Op_Id, N);
575
576             --  The following may seem superfluous, because an operator cannot
577             --  be generic, but this ignores the cleverness of the author of
578             --  ACVC bc1013a.
579
580             elsif Is_Overloadable (Op_Id) then
581                Analyze_User_Defined_Binary_Op (N, Op_Id);
582             end if;
583
584             Op_Id := Homonym (Op_Id);
585          end loop;
586       end if;
587
588       Operator_Check (N);
589    end Analyze_Arithmetic_Op;
590
591    ------------------
592    -- Analyze_Call --
593    ------------------
594
595    --  Function, procedure, and entry calls are checked here. The Name in
596    --  the call may be overloaded. The actuals have been analyzed and may
597    --  themselves be overloaded. On exit from this procedure, the node N
598    --  may have zero, one or more interpretations. In the first case an
599    --  error message is produced. In the last case, the node is flagged
600    --  as overloaded and the interpretations are collected in All_Interp.
601
602    --  If the name is an Access_To_Subprogram, it cannot be overloaded, but
603    --  the type-checking is similar to that of other calls.
604
605    procedure Analyze_Call (N : Node_Id) is
606       Actuals : constant List_Id := Parameter_Associations (N);
607       Nam     : Node_Id          := Name (N);
608       X       : Interp_Index;
609       It      : Interp;
610       Nam_Ent : Entity_Id;
611       Success : Boolean := False;
612
613       function Name_Denotes_Function return Boolean;
614       --  If the type of the name is an access to subprogram, this may be
615       --  the type of a name, or the return type of the function being called.
616       --  If the name is not an entity then it can denote a protected function.
617       --  Until we distinguish Etype from Return_Type, we must use this
618       --  routine to resolve the meaning of the name in the call.
619
620       ---------------------------
621       -- Name_Denotes_Function --
622       ---------------------------
623
624       function Name_Denotes_Function return Boolean is
625       begin
626          if Is_Entity_Name (Nam) then
627             return Ekind (Entity (Nam)) = E_Function;
628
629          elsif Nkind (Nam) = N_Selected_Component then
630             return Ekind (Entity (Selector_Name (Nam))) = E_Function;
631
632          else
633             return False;
634          end if;
635       end Name_Denotes_Function;
636
637    --  Start of processing for Analyze_Call
638
639    begin
640       --  Initialize the type of the result of the call to the error type,
641       --  which will be reset if the type is successfully resolved.
642
643       Set_Etype (N, Any_Type);
644
645       if not Is_Overloaded (Nam) then
646
647          --  Only one interpretation to check
648
649          if Ekind (Etype (Nam)) = E_Subprogram_Type then
650             Nam_Ent := Etype (Nam);
651
652          elsif Is_Access_Type (Etype (Nam))
653            and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
654            and then not Name_Denotes_Function
655          then
656             Nam_Ent := Designated_Type (Etype (Nam));
657             Insert_Explicit_Dereference (Nam);
658
659          --  Selected component case. Simple entry or protected operation,
660          --  where the entry name is given by the selector name.
661
662          elsif Nkind (Nam) = N_Selected_Component then
663             Nam_Ent := Entity (Selector_Name (Nam));
664
665             if Ekind (Nam_Ent) /= E_Entry
666               and then Ekind (Nam_Ent) /= E_Entry_Family
667               and then Ekind (Nam_Ent) /= E_Function
668               and then Ekind (Nam_Ent) /= E_Procedure
669             then
670                Error_Msg_N ("name in call is not a callable entity", Nam);
671                Set_Etype (N, Any_Type);
672                return;
673             end if;
674
675          --  If the name is an Indexed component, it can be a call to a member
676          --  of an entry family. The prefix must be a selected component whose
677          --  selector is the entry. Analyze_Procedure_Call normalizes several
678          --  kinds of call into this form.
679
680          elsif Nkind (Nam) = N_Indexed_Component then
681
682             if Nkind (Prefix (Nam)) = N_Selected_Component then
683                Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
684             else
685                Error_Msg_N ("name in call is not a callable entity", Nam);
686                Set_Etype (N, Any_Type);
687                return;
688             end if;
689
690          elsif not Is_Entity_Name (Nam) then
691             Error_Msg_N ("name in call is not a callable entity", Nam);
692             Set_Etype (N, Any_Type);
693             return;
694
695          else
696             Nam_Ent := Entity (Nam);
697
698             --  If no interpretations, give error message
699
700             if not Is_Overloadable (Nam_Ent) then
701                declare
702                   L : constant Boolean   := Is_List_Member (N);
703                   K : constant Node_Kind := Nkind (Parent (N));
704
705                begin
706                   --  If the node is in a list whose parent is not an
707                   --  expression then it must be an attempted procedure call.
708
709                   if L and then K not in N_Subexpr then
710                      if Ekind (Entity (Nam)) = E_Generic_Procedure then
711                         Error_Msg_NE
712                           ("must instantiate generic procedure& before call",
713                            Nam, Entity (Nam));
714                      else
715                         Error_Msg_N
716                           ("procedure or entry name expected", Nam);
717                      end if;
718
719                   --  Check for tasking cases where only an entry call will do
720
721                   elsif not L
722                     and then (K = N_Entry_Call_Alternative
723                                or else K = N_Triggering_Alternative)
724                   then
725                      Error_Msg_N ("entry name expected", Nam);
726
727                   --  Otherwise give general error message
728
729                   else
730                      Error_Msg_N ("invalid prefix in call", Nam);
731                   end if;
732
733                   return;
734                end;
735             end if;
736          end if;
737
738          Analyze_One_Call (N, Nam_Ent, True, Success);
739
740       else
741          --  An overloaded selected component must denote overloaded
742          --  operations of a concurrent type. The interpretations are
743          --  attached to the simple name of those operations.
744
745          if Nkind (Nam) = N_Selected_Component then
746             Nam := Selector_Name (Nam);
747          end if;
748
749          Get_First_Interp (Nam, X, It);
750
751          while Present (It.Nam) loop
752             Nam_Ent := It.Nam;
753
754             --  Name may be call that returns an access to subprogram, or more
755             --  generally an overloaded expression one of whose interpretations
756             --  yields an access to subprogram. If the name is an entity, we
757             --  do not dereference, because the node is a call that returns
758             --  the access type: note difference between f(x), where the call
759             --  may return an access subprogram type, and f(x)(y), where the
760             --  type returned by the call to f is implicitly dereferenced to
761             --  analyze the outer call.
762
763             if Is_Access_Type (Nam_Ent) then
764                Nam_Ent := Designated_Type (Nam_Ent);
765
766             elsif Is_Access_Type (Etype (Nam_Ent))
767               and then not Is_Entity_Name (Nam)
768               and then Ekind (Designated_Type (Etype (Nam_Ent)))
769                                                           = E_Subprogram_Type
770             then
771                Nam_Ent := Designated_Type (Etype (Nam_Ent));
772             end if;
773
774             Analyze_One_Call (N, Nam_Ent, False, Success);
775
776             --  If the interpretation succeeds, mark the proper type of the
777             --  prefix (any valid candidate will do). If not, remove the
778             --  candidate interpretation. This only needs to be done for
779             --  overloaded protected operations, for other entities disambi-
780             --  guation is done directly in Resolve.
781
782             if Success then
783                Set_Etype (Nam, It.Typ);
784
785             elsif Nkind (Name (N)) = N_Selected_Component
786               or else Nkind (Name (N)) = N_Function_Call
787             then
788                Remove_Interp (X);
789             end if;
790
791             Get_Next_Interp (X, It);
792          end loop;
793
794          --  If the name is the result of a function call, it can only
795          --  be a call to a function returning an access to subprogram.
796          --  Insert explicit dereference.
797
798          if Nkind (Nam) = N_Function_Call then
799             Insert_Explicit_Dereference (Nam);
800          end if;
801
802          if Etype (N) = Any_Type then
803
804             --  None of the interpretations is compatible with the actuals
805
806             Diagnose_Call (N, Nam);
807
808             --  Special checks for uninstantiated put routines
809
810             if Nkind (N) = N_Procedure_Call_Statement
811               and then Is_Entity_Name (Nam)
812               and then Chars (Nam) = Name_Put
813               and then List_Length (Actuals) = 1
814             then
815                declare
816                   Arg : constant Node_Id := First (Actuals);
817                   Typ : Entity_Id;
818
819                begin
820                   if Nkind (Arg) = N_Parameter_Association then
821                      Typ := Etype (Explicit_Actual_Parameter (Arg));
822                   else
823                      Typ := Etype (Arg);
824                   end if;
825
826                   if Is_Signed_Integer_Type (Typ) then
827                      Error_Msg_N
828                        ("possible missing instantiation of " &
829                           "'Text_'I'O.'Integer_'I'O!", Nam);
830
831                   elsif Is_Modular_Integer_Type (Typ) then
832                      Error_Msg_N
833                        ("possible missing instantiation of " &
834                           "'Text_'I'O.'Modular_'I'O!", Nam);
835
836                   elsif Is_Floating_Point_Type (Typ) then
837                      Error_Msg_N
838                        ("possible missing instantiation of " &
839                           "'Text_'I'O.'Float_'I'O!", Nam);
840
841                   elsif Is_Ordinary_Fixed_Point_Type (Typ) then
842                      Error_Msg_N
843                        ("possible missing instantiation of " &
844                           "'Text_'I'O.'Fixed_'I'O!", Nam);
845
846                   elsif Is_Decimal_Fixed_Point_Type (Typ) then
847                      Error_Msg_N
848                        ("possible missing instantiation of " &
849                           "'Text_'I'O.'Decimal_'I'O!", Nam);
850
851                   elsif Is_Enumeration_Type (Typ) then
852                      Error_Msg_N
853                        ("possible missing instantiation of " &
854                           "'Text_'I'O.'Enumeration_'I'O!", Nam);
855                   end if;
856                end;
857             end if;
858
859          elsif not Is_Overloaded (N)
860            and then Is_Entity_Name (Nam)
861          then
862             --  Resolution yields a single interpretation. Verify that
863             --  is has the proper capitalization.
864
865             Set_Entity_With_Style_Check (Nam, Entity (Nam));
866             Generate_Reference (Entity (Nam), Nam);
867
868             Set_Etype (Nam, Etype (Entity (Nam)));
869          else
870             Remove_Abstract_Operations (N);
871          end if;
872
873          End_Interp_List;
874       end if;
875    end Analyze_Call;
876
877    ---------------------------
878    -- Analyze_Comparison_Op --
879    ---------------------------
880
881    procedure Analyze_Comparison_Op (N : Node_Id) is
882       L     : constant Node_Id := Left_Opnd (N);
883       R     : constant Node_Id := Right_Opnd (N);
884       Op_Id : Entity_Id        := Entity (N);
885
886    begin
887       Set_Etype (N, Any_Type);
888       Candidate_Type := Empty;
889
890       Analyze_Expression (L);
891       Analyze_Expression (R);
892
893       if Present (Op_Id) then
894          if Ekind (Op_Id) = E_Operator then
895             Find_Comparison_Types (L, R, Op_Id, N);
896          else
897             Add_One_Interp (N, Op_Id, Etype (Op_Id));
898          end if;
899
900          if Is_Overloaded (L) then
901             Set_Etype (L, Intersect_Types (L, R));
902          end if;
903
904       else
905          Op_Id := Get_Name_Entity_Id (Chars (N));
906          while Present (Op_Id) loop
907             if Ekind (Op_Id) = E_Operator then
908                Find_Comparison_Types (L, R, Op_Id, N);
909             else
910                Analyze_User_Defined_Binary_Op (N, Op_Id);
911             end if;
912
913             Op_Id := Homonym (Op_Id);
914          end loop;
915       end if;
916
917       Operator_Check (N);
918    end Analyze_Comparison_Op;
919
920    ---------------------------
921    -- Analyze_Concatenation --
922    ---------------------------
923
924    --  If the only one-dimensional array type in scope is String,
925    --  this is the resulting type of the operation. Otherwise there
926    --  will be a concatenation operation defined for each user-defined
927    --  one-dimensional array.
928
929    procedure Analyze_Concatenation (N : Node_Id) is
930       L     : constant Node_Id := Left_Opnd (N);
931       R     : constant Node_Id := Right_Opnd (N);
932       Op_Id : Entity_Id        := Entity (N);
933       LT    : Entity_Id;
934       RT    : Entity_Id;
935
936    begin
937       Set_Etype (N, Any_Type);
938       Candidate_Type := Empty;
939
940       Analyze_Expression (L);
941       Analyze_Expression (R);
942
943       --  If the entity is present, the  node appears in an instance,
944       --  and denotes a predefined concatenation operation. The resulting
945       --  type is obtained from the arguments when possible. If the arguments
946       --  are aggregates, the array type and the concatenation type must be
947       --  visible.
948
949       if Present (Op_Id) then
950          if Ekind (Op_Id) = E_Operator then
951
952             LT := Base_Type (Etype (L));
953             RT := Base_Type (Etype (R));
954
955             if Is_Array_Type (LT)
956               and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
957             then
958                Add_One_Interp (N, Op_Id, LT);
959
960             elsif Is_Array_Type (RT)
961               and then LT = Base_Type (Component_Type (RT))
962             then
963                Add_One_Interp (N, Op_Id, RT);
964
965             --  If one operand is a string type or a user-defined array type,
966             --  and the other is a literal, result is of the specific type.
967
968             elsif
969               (Root_Type (LT) = Standard_String
970                  or else Scope (LT) /= Standard_Standard)
971               and then Etype (R) = Any_String
972             then
973                Add_One_Interp (N, Op_Id, LT);
974
975             elsif
976               (Root_Type (RT) = Standard_String
977                  or else Scope (RT) /= Standard_Standard)
978               and then Etype (L) = Any_String
979             then
980                Add_One_Interp (N, Op_Id, RT);
981
982             elsif not Is_Generic_Type (Etype (Op_Id)) then
983                Add_One_Interp (N, Op_Id, Etype (Op_Id));
984
985             else
986                --  Type and its operations must be visible
987
988                Set_Entity (N, Empty);
989                Analyze_Concatenation (N);
990             end if;
991
992          else
993             Add_One_Interp (N, Op_Id, Etype (Op_Id));
994          end if;
995
996       else
997          Op_Id  := Get_Name_Entity_Id (Name_Op_Concat);
998          while Present (Op_Id) loop
999             if Ekind (Op_Id) = E_Operator then
1000                Find_Concatenation_Types (L, R, Op_Id, N);
1001             else
1002                Analyze_User_Defined_Binary_Op (N, Op_Id);
1003             end if;
1004
1005             Op_Id := Homonym (Op_Id);
1006          end loop;
1007       end if;
1008
1009       Operator_Check (N);
1010    end Analyze_Concatenation;
1011
1012    ------------------------------------
1013    -- Analyze_Conditional_Expression --
1014    ------------------------------------
1015
1016    procedure Analyze_Conditional_Expression (N : Node_Id) is
1017       Condition : constant Node_Id := First (Expressions (N));
1018       Then_Expr : constant Node_Id := Next (Condition);
1019       Else_Expr : constant Node_Id := Next (Then_Expr);
1020    begin
1021       Analyze_Expression (Condition);
1022       Analyze_Expression (Then_Expr);
1023       Analyze_Expression (Else_Expr);
1024       Set_Etype (N, Etype (Then_Expr));
1025    end Analyze_Conditional_Expression;
1026
1027    -------------------------
1028    -- Analyze_Equality_Op --
1029    -------------------------
1030
1031    procedure Analyze_Equality_Op (N : Node_Id) is
1032       Loc   : constant Source_Ptr := Sloc (N);
1033       L     : constant Node_Id := Left_Opnd (N);
1034       R     : constant Node_Id := Right_Opnd (N);
1035       Op_Id : Entity_Id;
1036
1037    begin
1038       Set_Etype (N, Any_Type);
1039       Candidate_Type := Empty;
1040
1041       Analyze_Expression (L);
1042       Analyze_Expression (R);
1043
1044       --  If the entity is set, the node is a generic instance with a non-local
1045       --  reference to the predefined operator or to a user-defined function.
1046       --  It can also be an inequality that is expanded into the negation of a
1047       --  call to a user-defined equality operator.
1048
1049       --  For the predefined case, the result is Boolean, regardless of the
1050       --  type of the  operands. The operands may even be limited, if they are
1051       --  generic actuals. If they are overloaded, label the left argument with
1052       --  the common type that must be present, or with the type of the formal
1053       --  of the user-defined function.
1054
1055       if Present (Entity (N)) then
1056          Op_Id := Entity (N);
1057
1058          if Ekind (Op_Id) = E_Operator then
1059             Add_One_Interp (N, Op_Id, Standard_Boolean);
1060          else
1061             Add_One_Interp (N, Op_Id, Etype (Op_Id));
1062          end if;
1063
1064          if Is_Overloaded (L) then
1065             if Ekind (Op_Id) = E_Operator then
1066                Set_Etype (L, Intersect_Types (L, R));
1067             else
1068                Set_Etype (L, Etype (First_Formal (Op_Id)));
1069             end if;
1070          end if;
1071
1072       else
1073          Op_Id := Get_Name_Entity_Id (Chars (N));
1074          while Present (Op_Id) loop
1075             if Ekind (Op_Id) = E_Operator then
1076                Find_Equality_Types (L, R, Op_Id, N);
1077             else
1078                Analyze_User_Defined_Binary_Op (N, Op_Id);
1079             end if;
1080
1081             Op_Id := Homonym (Op_Id);
1082          end loop;
1083       end if;
1084
1085       --  If there was no match, and the operator is inequality, this may
1086       --  be a case where inequality has not been made explicit, as for
1087       --  tagged types. Analyze the node as the negation of an equality
1088       --  operation. This cannot be done earlier, because before analysis
1089       --  we cannot rule out the presence of an explicit inequality.
1090
1091       if Etype (N) = Any_Type
1092         and then Nkind (N) = N_Op_Ne
1093       then
1094          Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1095
1096          while Present (Op_Id) loop
1097
1098             if Ekind (Op_Id) = E_Operator then
1099                Find_Equality_Types (L, R, Op_Id, N);
1100             else
1101                Analyze_User_Defined_Binary_Op (N, Op_Id);
1102             end if;
1103
1104             Op_Id := Homonym (Op_Id);
1105          end loop;
1106
1107          if Etype (N) /= Any_Type then
1108             Op_Id := Entity (N);
1109
1110             Rewrite (N,
1111               Make_Op_Not (Loc,
1112                 Right_Opnd =>
1113                   Make_Op_Eq (Loc,
1114                     Left_Opnd =>  Relocate_Node (Left_Opnd (N)),
1115                     Right_Opnd => Relocate_Node (Right_Opnd (N)))));
1116
1117             Set_Entity (Right_Opnd (N), Op_Id);
1118             Analyze (N);
1119          end if;
1120       end if;
1121
1122       Operator_Check (N);
1123    end Analyze_Equality_Op;
1124
1125    ----------------------------------
1126    -- Analyze_Explicit_Dereference --
1127    ----------------------------------
1128
1129    procedure Analyze_Explicit_Dereference (N : Node_Id) is
1130       Loc   : constant Source_Ptr := Sloc (N);
1131       P     : constant Node_Id := Prefix (N);
1132       T     : Entity_Id;
1133       I     : Interp_Index;
1134       It    : Interp;
1135       New_N : Node_Id;
1136
1137       function Is_Function_Type return Boolean;
1138       --  Check whether node may be interpreted as an implicit function call
1139
1140       ----------------------
1141       -- Is_Function_Type --
1142       ----------------------
1143
1144       function Is_Function_Type return Boolean is
1145          I  : Interp_Index;
1146          It : Interp;
1147
1148       begin
1149          if not Is_Overloaded (N) then
1150             return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1151               and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1152
1153          else
1154             Get_First_Interp (N, I, It);
1155
1156             while Present (It.Nam) loop
1157                if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1158                  or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1159                then
1160                   return False;
1161                end if;
1162
1163                Get_Next_Interp (I, It);
1164             end loop;
1165
1166             return True;
1167          end if;
1168       end Is_Function_Type;
1169
1170    --  Start of processing for Analyze_Explicit_Deference
1171
1172    begin
1173       Analyze (P);
1174       Set_Etype (N, Any_Type);
1175
1176       --  Test for remote access to subprogram type, and if so return
1177       --  after rewriting the original tree.
1178
1179       if Remote_AST_E_Dereference (P) then
1180          return;
1181       end if;
1182
1183       --  Normal processing for other than remote access to subprogram type
1184
1185       if not Is_Overloaded (P) then
1186          if Is_Access_Type (Etype (P)) then
1187
1188             --  Set the Etype. We need to go thru Is_For_Access_Subtypes
1189             --  to avoid other problems caused by the Private_Subtype
1190             --  and it is safe to go to the Base_Type because this is the
1191             --  same as converting the access value to its Base_Type.
1192
1193             declare
1194                DT : Entity_Id := Designated_Type (Etype (P));
1195
1196             begin
1197                if Ekind (DT) = E_Private_Subtype
1198                  and then Is_For_Access_Subtype (DT)
1199                then
1200                   DT := Base_Type (DT);
1201                end if;
1202
1203                Set_Etype (N, DT);
1204             end;
1205
1206          elsif Etype (P) /= Any_Type then
1207             Error_Msg_N ("prefix of dereference must be an access type", N);
1208             return;
1209          end if;
1210
1211       else
1212          Get_First_Interp (P, I, It);
1213
1214          while Present (It.Nam) loop
1215             T := It.Typ;
1216
1217             if Is_Access_Type (T) then
1218                Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1219             end if;
1220
1221             Get_Next_Interp (I, It);
1222          end loop;
1223
1224          End_Interp_List;
1225
1226          --  Error if no interpretation of the prefix has an access type.
1227
1228          if Etype (N) = Any_Type then
1229             Error_Msg_N
1230               ("access type required in prefix of explicit dereference", P);
1231             Set_Etype (N, Any_Type);
1232             return;
1233          end if;
1234       end if;
1235
1236       if Is_Function_Type
1237         and then Nkind (Parent (N)) /= N_Indexed_Component
1238
1239         and then (Nkind (Parent (N)) /= N_Function_Call
1240                    or else N /= Name (Parent (N)))
1241
1242         and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1243                    or else N /= Name (Parent (N)))
1244
1245         and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1246         and then (Nkind (Parent (N)) /= N_Attribute_Reference
1247                     or else
1248                       (Attribute_Name (Parent (N)) /= Name_Address
1249                         and then
1250                        Attribute_Name (Parent (N)) /= Name_Access))
1251       then
1252          --  Name is a function call with no actuals, in a context that
1253          --  requires deproceduring (including as an actual in an enclosing
1254          --  function or procedure call). We can conceive of pathological cases
1255          --  where the prefix might include functions that return access to
1256          --  subprograms and others that return a regular type. Disambiguation
1257          --  of those will have to take place in Resolve. See e.g. 7117-014.
1258
1259          New_N :=
1260            Make_Function_Call (Loc,
1261            Name => Make_Explicit_Dereference (Loc, P),
1262            Parameter_Associations => New_List);
1263
1264          --  If the prefix is overloaded, remove operations that have formals,
1265          --  we know that this is a parameterless call.
1266
1267          if Is_Overloaded (P) then
1268             Get_First_Interp (P, I, It);
1269             while Present (It.Nam) loop
1270                T := It.Typ;
1271
1272                if No (First_Formal (Base_Type (Designated_Type (T)))) then
1273                   Set_Etype (P, T);
1274                else
1275                   Remove_Interp (I);
1276                end if;
1277
1278                Get_Next_Interp (I, It);
1279             end loop;
1280          end if;
1281
1282          Rewrite (N, New_N);
1283          Analyze (N);
1284       end if;
1285
1286       --  A value of remote access-to-class-wide must not be dereferenced
1287       --  (RM E.2.2(16)).
1288
1289       Validate_Remote_Access_To_Class_Wide_Type (N);
1290    end Analyze_Explicit_Dereference;
1291
1292    ------------------------
1293    -- Analyze_Expression --
1294    ------------------------
1295
1296    procedure Analyze_Expression (N : Node_Id) is
1297    begin
1298       Analyze (N);
1299       Check_Parameterless_Call (N);
1300    end Analyze_Expression;
1301
1302    ------------------------------------
1303    -- Analyze_Indexed_Component_Form --
1304    ------------------------------------
1305
1306    procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1307       P     : constant Node_Id := Prefix (N);
1308       Exprs : constant List_Id := Expressions (N);
1309       Exp   : Node_Id;
1310       P_T   : Entity_Id;
1311       E     : Node_Id;
1312       U_N   : Entity_Id;
1313
1314       procedure Process_Function_Call;
1315       --  Prefix in indexed component form is an overloadable entity,
1316       --  so the node is a function call. Reformat it as such.
1317
1318       procedure Process_Indexed_Component;
1319       --  Prefix in indexed component form is actually an indexed component.
1320       --  This routine processes it, knowing that the prefix is already
1321       --  resolved.
1322
1323       procedure Process_Indexed_Component_Or_Slice;
1324       --  An indexed component with a single index may designate a slice if
1325       --  the index is a subtype mark. This routine disambiguates these two
1326       --  cases by resolving the prefix to see if it is a subtype mark.
1327
1328       procedure Process_Overloaded_Indexed_Component;
1329       --  If the prefix of an indexed component is overloaded, the proper
1330       --  interpretation is selected by the index types and the context.
1331
1332       ---------------------------
1333       -- Process_Function_Call --
1334       ---------------------------
1335
1336       procedure Process_Function_Call is
1337          Actual : Node_Id;
1338
1339       begin
1340          Change_Node (N, N_Function_Call);
1341          Set_Name (N, P);
1342          Set_Parameter_Associations (N, Exprs);
1343
1344          Actual := First (Parameter_Associations (N));
1345          while Present (Actual) loop
1346             Analyze (Actual);
1347             Check_Parameterless_Call (Actual);
1348             Next_Actual (Actual);
1349          end loop;
1350
1351          Analyze_Call (N);
1352       end Process_Function_Call;
1353
1354       -------------------------------
1355       -- Process_Indexed_Component --
1356       -------------------------------
1357
1358       procedure Process_Indexed_Component is
1359          Exp          : Node_Id;
1360          Array_Type   : Entity_Id;
1361          Index        : Node_Id;
1362          Entry_Family : Entity_Id;
1363
1364       begin
1365          Exp := First (Exprs);
1366
1367          if Is_Overloaded (P) then
1368             Process_Overloaded_Indexed_Component;
1369
1370          else
1371             Array_Type := Etype (P);
1372
1373             --  Prefix must be appropriate for an array type.
1374             --  Dereference the prefix if it is an access type.
1375
1376             if Is_Access_Type (Array_Type) then
1377                Array_Type := Designated_Type (Array_Type);
1378                Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1379             end if;
1380
1381             if Is_Array_Type (Array_Type) then
1382                null;
1383
1384             elsif (Is_Entity_Name (P)
1385                      and then
1386                    Ekind (Entity (P)) = E_Entry_Family)
1387                or else
1388                  (Nkind (P) = N_Selected_Component
1389                     and then
1390                   Is_Entity_Name (Selector_Name (P))
1391                     and then
1392                   Ekind (Entity (Selector_Name (P))) = E_Entry_Family)
1393             then
1394                if Is_Entity_Name (P) then
1395                   Entry_Family := Entity (P);
1396                else
1397                   Entry_Family := Entity (Selector_Name (P));
1398                end if;
1399
1400                Analyze (Exp);
1401                Set_Etype (N, Any_Type);
1402
1403                if not Has_Compatible_Type
1404                  (Exp, Entry_Index_Type (Entry_Family))
1405                then
1406                   Error_Msg_N ("invalid index type in entry name", N);
1407
1408                elsif Present (Next (Exp)) then
1409                   Error_Msg_N ("too many subscripts in entry reference", N);
1410
1411                else
1412                   Set_Etype (N,  Etype (P));
1413                end if;
1414
1415                return;
1416
1417             elsif Is_Record_Type (Array_Type)
1418               and then Remote_AST_I_Dereference (P)
1419             then
1420                return;
1421
1422             elsif Array_Type = Any_Type then
1423                Set_Etype (N, Any_Type);
1424                return;
1425
1426             --  Here we definitely have a bad indexing
1427
1428             else
1429                if Nkind (Parent (N)) = N_Requeue_Statement
1430                  and then
1431                    ((Is_Entity_Name (P)
1432                         and then Ekind (Entity (P)) = E_Entry)
1433                     or else
1434                      (Nkind (P) = N_Selected_Component
1435                        and then Is_Entity_Name (Selector_Name (P))
1436                        and then Ekind (Entity (Selector_Name (P))) = E_Entry))
1437                then
1438                   Error_Msg_N
1439                     ("REQUEUE does not permit parameters", First (Exprs));
1440
1441                elsif Is_Entity_Name (P)
1442                  and then Etype (P) = Standard_Void_Type
1443                then
1444                   Error_Msg_NE ("incorrect use of&", P, Entity (P));
1445
1446                else
1447                   Error_Msg_N ("array type required in indexed component", P);
1448                end if;
1449
1450                Set_Etype (N, Any_Type);
1451                return;
1452             end if;
1453
1454             Index := First_Index (Array_Type);
1455
1456             while Present (Index) and then Present (Exp) loop
1457                if not Has_Compatible_Type (Exp, Etype (Index)) then
1458                   Wrong_Type (Exp, Etype (Index));
1459                   Set_Etype (N, Any_Type);
1460                   return;
1461                end if;
1462
1463                Next_Index (Index);
1464                Next (Exp);
1465             end loop;
1466
1467             Set_Etype (N, Component_Type (Array_Type));
1468
1469             if Present (Index) then
1470                Error_Msg_N
1471                  ("too few subscripts in array reference", First (Exprs));
1472
1473             elsif Present (Exp) then
1474                Error_Msg_N ("too many subscripts in array reference", Exp);
1475             end if;
1476          end if;
1477       end Process_Indexed_Component;
1478
1479       ----------------------------------------
1480       -- Process_Indexed_Component_Or_Slice --
1481       ----------------------------------------
1482
1483       procedure Process_Indexed_Component_Or_Slice is
1484       begin
1485          Exp := First (Exprs);
1486          while Present (Exp) loop
1487             Analyze_Expression (Exp);
1488             Next (Exp);
1489          end loop;
1490
1491          Exp := First (Exprs);
1492
1493          --  If one index is present, and it is a subtype name, then the
1494          --  node denotes a slice (note that the case of an explicit range
1495          --  for a slice was already built as an N_Slice node in the first
1496          --  place, so that case is not handled here).
1497
1498          --  We use a replace rather than a rewrite here because this is one
1499          --  of the cases in which the tree built by the parser is plain wrong.
1500
1501          if No (Next (Exp))
1502            and then Is_Entity_Name (Exp)
1503            and then Is_Type (Entity (Exp))
1504          then
1505             Replace (N,
1506                Make_Slice (Sloc (N),
1507                  Prefix => P,
1508                  Discrete_Range => New_Copy (Exp)));
1509             Analyze (N);
1510
1511          --  Otherwise (more than one index present, or single index is not
1512          --  a subtype name), then we have the indexed component case.
1513
1514          else
1515             Process_Indexed_Component;
1516          end if;
1517       end Process_Indexed_Component_Or_Slice;
1518
1519       ------------------------------------------
1520       -- Process_Overloaded_Indexed_Component --
1521       ------------------------------------------
1522
1523       procedure Process_Overloaded_Indexed_Component is
1524          Exp   : Node_Id;
1525          I     : Interp_Index;
1526          It    : Interp;
1527          Typ   : Entity_Id;
1528          Index : Node_Id;
1529          Found : Boolean;
1530
1531       begin
1532          Set_Etype (N, Any_Type);
1533
1534          Get_First_Interp (P, I, It);
1535          while Present (It.Nam) loop
1536             Typ := It.Typ;
1537
1538             if Is_Access_Type (Typ) then
1539                Typ := Designated_Type (Typ);
1540                Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1541             end if;
1542
1543             if Is_Array_Type (Typ) then
1544
1545                --  Got a candidate: verify that index types are compatible
1546
1547                Index := First_Index (Typ);
1548                Found := True;
1549                Exp := First (Exprs);
1550                while Present (Index) and then Present (Exp) loop
1551                   if Has_Compatible_Type (Exp, Etype (Index)) then
1552                      null;
1553                   else
1554                      Found := False;
1555                      Remove_Interp (I);
1556                      exit;
1557                   end if;
1558
1559                   Next_Index (Index);
1560                   Next (Exp);
1561                end loop;
1562
1563                if Found and then No (Index) and then No (Exp) then
1564                   Add_One_Interp (N,
1565                      Etype (Component_Type (Typ)),
1566                      Etype (Component_Type (Typ)));
1567                end if;
1568             end if;
1569
1570             Get_Next_Interp (I, It);
1571          end loop;
1572
1573          if Etype (N) = Any_Type then
1574             Error_Msg_N ("no legal interpetation for indexed component", N);
1575             Set_Is_Overloaded (N, False);
1576          end if;
1577
1578          End_Interp_List;
1579       end Process_Overloaded_Indexed_Component;
1580
1581    --  Start of processing for Analyze_Indexed_Component_Form
1582
1583    begin
1584       --  Get name of array, function or type
1585
1586       Analyze (P);
1587       if Nkind (N) = N_Function_Call
1588         or else Nkind (N) = N_Procedure_Call_Statement
1589       then
1590          --  If P is an explicit dereference whose prefix is of a
1591          --  remote access-to-subprogram type, then N has already
1592          --  been rewritten as a subprogram call and analyzed.
1593
1594          return;
1595       end if;
1596
1597       pragma Assert (Nkind (N) = N_Indexed_Component);
1598
1599       P_T := Base_Type (Etype (P));
1600
1601       if Is_Entity_Name (P)
1602         or else Nkind (P) = N_Operator_Symbol
1603       then
1604          U_N := Entity (P);
1605
1606          if Ekind (U_N) in Type_Kind then
1607
1608             --  Reformat node as a type conversion
1609
1610             E := Remove_Head (Exprs);
1611
1612             if Present (First (Exprs)) then
1613                Error_Msg_N
1614                 ("argument of type conversion must be single expression", N);
1615             end if;
1616
1617             Change_Node (N, N_Type_Conversion);
1618             Set_Subtype_Mark (N, P);
1619             Set_Etype (N, U_N);
1620             Set_Expression (N, E);
1621
1622             --  After changing the node, call for the specific Analysis
1623             --  routine directly, to avoid a double call to the expander.
1624
1625             Analyze_Type_Conversion (N);
1626             return;
1627          end if;
1628
1629          if Is_Overloadable (U_N) then
1630             Process_Function_Call;
1631
1632          elsif Ekind (Etype (P)) = E_Subprogram_Type
1633            or else (Is_Access_Type (Etype (P))
1634                       and then
1635                     Ekind (Designated_Type (Etype (P))) = E_Subprogram_Type)
1636          then
1637             --  Call to access_to-subprogram with possible implicit dereference
1638
1639             Process_Function_Call;
1640
1641          elsif Is_Generic_Subprogram (U_N) then
1642
1643             --  A common beginner's (or C++ templates fan) error
1644
1645             Error_Msg_N ("generic subprogram cannot be called", N);
1646             Set_Etype (N, Any_Type);
1647             return;
1648
1649          else
1650             Process_Indexed_Component_Or_Slice;
1651          end if;
1652
1653       --  If not an entity name, prefix is an expression that may denote
1654       --  an array or an access-to-subprogram.
1655
1656       else
1657          if Ekind (P_T) = E_Subprogram_Type
1658            or else (Is_Access_Type (P_T)
1659                      and then
1660                     Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1661          then
1662             Process_Function_Call;
1663
1664          elsif Nkind (P) = N_Selected_Component
1665            and then Ekind (Entity (Selector_Name (P))) = E_Function
1666          then
1667             Process_Function_Call;
1668
1669          else
1670             --  Indexed component, slice, or a call to a member of a family
1671             --  entry, which will be converted to an entry call later.
1672
1673             Process_Indexed_Component_Or_Slice;
1674          end if;
1675       end if;
1676    end Analyze_Indexed_Component_Form;
1677
1678    ------------------------
1679    -- Analyze_Logical_Op --
1680    ------------------------
1681
1682    procedure Analyze_Logical_Op (N : Node_Id) is
1683       L     : constant Node_Id := Left_Opnd (N);
1684       R     : constant Node_Id := Right_Opnd (N);
1685       Op_Id : Entity_Id := Entity (N);
1686
1687    begin
1688       Set_Etype (N, Any_Type);
1689       Candidate_Type := Empty;
1690
1691       Analyze_Expression (L);
1692       Analyze_Expression (R);
1693
1694       if Present (Op_Id) then
1695
1696          if Ekind (Op_Id) = E_Operator then
1697             Find_Boolean_Types (L, R, Op_Id, N);
1698          else
1699             Add_One_Interp (N, Op_Id, Etype (Op_Id));
1700          end if;
1701
1702       else
1703          Op_Id := Get_Name_Entity_Id (Chars (N));
1704
1705          while Present (Op_Id) loop
1706             if Ekind (Op_Id) = E_Operator then
1707                Find_Boolean_Types (L, R, Op_Id, N);
1708             else
1709                Analyze_User_Defined_Binary_Op (N, Op_Id);
1710             end if;
1711
1712             Op_Id := Homonym (Op_Id);
1713          end loop;
1714       end if;
1715
1716       Operator_Check (N);
1717    end Analyze_Logical_Op;
1718
1719    ---------------------------
1720    -- Analyze_Membership_Op --
1721    ---------------------------
1722
1723    procedure Analyze_Membership_Op (N : Node_Id) is
1724       L     : constant Node_Id := Left_Opnd (N);
1725       R     : constant Node_Id := Right_Opnd (N);
1726
1727       Index : Interp_Index;
1728       It    : Interp;
1729       Found : Boolean := False;
1730       I_F   : Interp_Index;
1731       T_F   : Entity_Id;
1732
1733       procedure Try_One_Interp (T1 : Entity_Id);
1734       --  Routine to try one proposed interpretation. Note that the context
1735       --  of the operation plays no role in resolving the arguments, so that
1736       --  if there is more than one interpretation of the operands that is
1737       --  compatible with a membership test, the operation is ambiguous.
1738
1739       --------------------
1740       -- Try_One_Interp --
1741       --------------------
1742
1743       procedure Try_One_Interp (T1 : Entity_Id) is
1744       begin
1745          if Has_Compatible_Type (R, T1) then
1746             if Found
1747               and then Base_Type (T1) /= Base_Type (T_F)
1748             then
1749                It := Disambiguate (L, I_F, Index, Any_Type);
1750
1751                if It = No_Interp then
1752                   Ambiguous_Operands (N);
1753                   Set_Etype (L, Any_Type);
1754                   return;
1755
1756                else
1757                   T_F := It.Typ;
1758                end if;
1759
1760             else
1761                Found := True;
1762                T_F   := T1;
1763                I_F   := Index;
1764             end if;
1765
1766             Set_Etype (L, T_F);
1767          end if;
1768
1769       end Try_One_Interp;
1770
1771    --  Start of processing for Analyze_Membership_Op
1772
1773    begin
1774       Analyze_Expression (L);
1775
1776       if Nkind (R) = N_Range
1777         or else (Nkind (R) = N_Attribute_Reference
1778                   and then Attribute_Name (R) = Name_Range)
1779       then
1780          Analyze (R);
1781
1782          if not Is_Overloaded (L) then
1783             Try_One_Interp (Etype (L));
1784
1785          else
1786             Get_First_Interp (L, Index, It);
1787
1788             while Present (It.Typ) loop
1789                Try_One_Interp (It.Typ);
1790                Get_Next_Interp (Index, It);
1791             end loop;
1792          end if;
1793
1794       --  If not a range, it can only be a subtype mark, or else there
1795       --  is a more basic error, to be diagnosed in Find_Type.
1796
1797       else
1798          Find_Type (R);
1799
1800          if Is_Entity_Name (R) then
1801             Check_Fully_Declared (Entity (R), R);
1802          end if;
1803       end if;
1804
1805       --  Compatibility between expression and subtype mark or range is
1806       --  checked during resolution. The result of the operation is Boolean
1807       --  in any case.
1808
1809       Set_Etype (N, Standard_Boolean);
1810    end Analyze_Membership_Op;
1811
1812    ----------------------
1813    -- Analyze_Negation --
1814    ----------------------
1815
1816    procedure Analyze_Negation (N : Node_Id) is
1817       R     : constant Node_Id := Right_Opnd (N);
1818       Op_Id : Entity_Id := Entity (N);
1819
1820    begin
1821       Set_Etype (N, Any_Type);
1822       Candidate_Type := Empty;
1823
1824       Analyze_Expression (R);
1825
1826       if Present (Op_Id) then
1827          if Ekind (Op_Id) = E_Operator then
1828             Find_Negation_Types (R, Op_Id, N);
1829          else
1830             Add_One_Interp (N, Op_Id, Etype (Op_Id));
1831          end if;
1832
1833       else
1834          Op_Id := Get_Name_Entity_Id (Chars (N));
1835          while Present (Op_Id) loop
1836             if Ekind (Op_Id) = E_Operator then
1837                Find_Negation_Types (R, Op_Id, N);
1838             else
1839                Analyze_User_Defined_Unary_Op (N, Op_Id);
1840             end if;
1841
1842             Op_Id := Homonym (Op_Id);
1843          end loop;
1844       end if;
1845
1846       Operator_Check (N);
1847    end Analyze_Negation;
1848
1849    ------------------
1850    -- Analyze_Null --
1851    ------------------
1852
1853    procedure Analyze_Null (N : Node_Id) is
1854    begin
1855       Set_Etype (N, Any_Access);
1856    end Analyze_Null;
1857
1858    ----------------------
1859    -- Analyze_One_Call --
1860    ----------------------
1861
1862    procedure Analyze_One_Call
1863       (N       : Node_Id;
1864        Nam     : Entity_Id;
1865        Report  : Boolean;
1866        Success : out Boolean)
1867    is
1868       Actuals    : constant List_Id   := Parameter_Associations (N);
1869       Prev_T     : constant Entity_Id := Etype (N);
1870       Formal     : Entity_Id;
1871       Actual     : Node_Id;
1872       Is_Indexed : Boolean := False;
1873       Subp_Type  : constant Entity_Id := Etype (Nam);
1874       Norm_OK    : Boolean;
1875
1876       procedure Indicate_Name_And_Type;
1877       --  If candidate interpretation matches, indicate name and type of
1878       --  result on call node.
1879
1880       ----------------------------
1881       -- Indicate_Name_And_Type --
1882       ----------------------------
1883
1884       procedure Indicate_Name_And_Type is
1885       begin
1886          Add_One_Interp (N, Nam, Etype (Nam));
1887          Success := True;
1888
1889          --  If the prefix of the call is a name, indicate the entity
1890          --  being called. If it is not a name,  it is an expression that
1891          --  denotes an access to subprogram or else an entry or family. In
1892          --  the latter case, the name is a selected component, and the entity
1893          --  being called is noted on the selector.
1894
1895          if not Is_Type (Nam) then
1896             if Is_Entity_Name (Name (N))
1897               or else Nkind (Name (N)) = N_Operator_Symbol
1898             then
1899                Set_Entity (Name (N), Nam);
1900
1901             elsif Nkind (Name (N)) = N_Selected_Component then
1902                Set_Entity (Selector_Name (Name (N)),  Nam);
1903             end if;
1904          end if;
1905
1906          if Debug_Flag_E and not Report then
1907             Write_Str (" Overloaded call ");
1908             Write_Int (Int (N));
1909             Write_Str (" compatible with ");
1910             Write_Int (Int (Nam));
1911             Write_Eol;
1912          end if;
1913       end Indicate_Name_And_Type;
1914
1915    --  Start of processing for Analyze_One_Call
1916
1917    begin
1918       Success := False;
1919
1920       --  If the subprogram has no formals, or if all the formals have
1921       --  defaults, and the return type is an array type, the node may
1922       --  denote an indexing of the result of a parameterless call.
1923
1924       if Needs_No_Actuals (Nam)
1925         and then Present (Actuals)
1926       then
1927          if Is_Array_Type (Subp_Type) then
1928             Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type);
1929
1930          elsif Is_Access_Type (Subp_Type)
1931            and then Is_Array_Type (Designated_Type (Subp_Type))
1932          then
1933             Is_Indexed :=
1934               Try_Indexed_Call (N, Nam, Designated_Type (Subp_Type));
1935
1936          elsif Is_Access_Type (Subp_Type)
1937            and then Ekind (Designated_Type (Subp_Type))  = E_Subprogram_Type
1938          then
1939             Is_Indexed := Try_Indirect_Call (N, Nam, Subp_Type);
1940          end if;
1941
1942       end if;
1943
1944       Normalize_Actuals (N, Nam, (Report and not Is_Indexed), Norm_OK);
1945
1946       if not Norm_OK then
1947
1948          --  Mismatch in number or names of parameters
1949
1950          if Debug_Flag_E then
1951             Write_Str (" normalization fails in call ");
1952             Write_Int (Int (N));
1953             Write_Str (" with subprogram ");
1954             Write_Int (Int (Nam));
1955             Write_Eol;
1956          end if;
1957
1958       --  If the context expects a function call, discard any interpretation
1959       --  that is a procedure. If the node is not overloaded, leave as is for
1960       --  better error reporting when type mismatch is found.
1961
1962       elsif Nkind (N) = N_Function_Call
1963         and then Is_Overloaded (Name (N))
1964         and then Ekind (Nam) = E_Procedure
1965       then
1966          return;
1967
1968       --  Ditto for function calls in a procedure context
1969
1970       elsif Nkind (N) = N_Procedure_Call_Statement
1971          and then Is_Overloaded (Name (N))
1972          and then Etype (Nam) /= Standard_Void_Type
1973       then
1974          return;
1975
1976       elsif not Present (Actuals) then
1977
1978          --  If Normalize succeeds, then there are default parameters for
1979          --  all formals.
1980
1981          Indicate_Name_And_Type;
1982
1983       elsif Ekind (Nam) = E_Operator then
1984          if Nkind (N) = N_Procedure_Call_Statement then
1985             return;
1986          end if;
1987
1988          --  This can occur when the prefix of the call is an operator
1989          --  name or an expanded name whose selector is an operator name.
1990
1991          Analyze_Operator_Call (N, Nam);
1992
1993          if Etype (N) /= Prev_T then
1994
1995             --  There may be a user-defined operator that hides the
1996             --  current interpretation. We must check for this independently
1997             --  of the analysis of the call with the user-defined operation,
1998             --  because the parameter names may be wrong and yet the hiding
1999             --  takes place. Fixes b34014o.
2000
2001             if Is_Overloaded (Name (N)) then
2002                declare
2003                   I  : Interp_Index;
2004                   It : Interp;
2005
2006                begin
2007                   Get_First_Interp (Name (N), I, It);
2008                   while Present (It.Nam) loop
2009                      if Ekind (It.Nam) /= E_Operator
2010                         and then Hides_Op (It.Nam, Nam)
2011                         and then
2012                           Has_Compatible_Type
2013                             (First_Actual (N), Etype (First_Formal (It.Nam)))
2014                         and then (No (Next_Actual (First_Actual (N)))
2015                            or else Has_Compatible_Type
2016                             (Next_Actual (First_Actual (N)),
2017                              Etype (Next_Formal (First_Formal (It.Nam)))))
2018                      then
2019                         Set_Etype (N, Prev_T);
2020                         return;
2021                      end if;
2022
2023                      Get_Next_Interp (I, It);
2024                   end loop;
2025                end;
2026             end if;
2027
2028             --  If operator matches formals, record its name on the call.
2029             --  If the operator is overloaded, Resolve will select the
2030             --  correct one from the list of interpretations. The call
2031             --  node itself carries the first candidate.
2032
2033             Set_Entity (Name (N), Nam);
2034             Success := True;
2035
2036          elsif Report and then Etype (N) = Any_Type then
2037             Error_Msg_N ("incompatible arguments for operator", N);
2038          end if;
2039
2040       else
2041          --  Normalize_Actuals has chained the named associations in the
2042          --  correct order of the formals.
2043
2044          Actual := First_Actual (N);
2045          Formal := First_Formal (Nam);
2046          while Present (Actual) and then Present (Formal) loop
2047             if Nkind (Parent (Actual)) /= N_Parameter_Association
2048               or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2049             then
2050                if Has_Compatible_Type (Actual, Etype (Formal)) then
2051                   Next_Actual (Actual);
2052                   Next_Formal (Formal);
2053
2054                else
2055                   if Debug_Flag_E then
2056                      Write_Str (" type checking fails in call ");
2057                      Write_Int (Int (N));
2058                      Write_Str (" with formal ");
2059                      Write_Int (Int (Formal));
2060                      Write_Str (" in subprogram ");
2061                      Write_Int (Int (Nam));
2062                      Write_Eol;
2063                   end if;
2064
2065                   if Report and not Is_Indexed then
2066                      Wrong_Type (Actual, Etype (Formal));
2067
2068                      if Nkind (Actual) = N_Op_Eq
2069                        and then Nkind (Left_Opnd (Actual)) = N_Identifier
2070                      then
2071                         Formal := First_Formal (Nam);
2072
2073                         while Present (Formal) loop
2074
2075                            if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2076                               Error_Msg_N
2077                                 ("possible misspelling of `='>`!", Actual);
2078                               exit;
2079                            end if;
2080
2081                            Next_Formal (Formal);
2082                         end loop;
2083                      end if;
2084
2085                      if All_Errors_Mode then
2086                         Error_Msg_Sloc := Sloc (Nam);
2087
2088                         if Is_Overloadable (Nam)
2089                           and then Present (Alias (Nam))
2090                           and then not Comes_From_Source (Nam)
2091                         then
2092                            Error_Msg_NE
2093                              ("  =='> in call to &#(inherited)!", Actual, Nam);
2094
2095                         elsif Ekind (Nam) = E_Subprogram_Type then
2096                            declare
2097                               Access_To_Subprogram_Typ :
2098                                 constant Entity_Id :=
2099                                   Defining_Identifier
2100                                     (Associated_Node_For_Itype (Nam));
2101                            begin
2102                               Error_Msg_NE (
2103                                 "  =='> in call to dereference of &#!",
2104                                 Actual, Access_To_Subprogram_Typ);
2105                            end;
2106
2107                         else
2108                            Error_Msg_NE ("  =='> in call to &#!", Actual, Nam);
2109
2110                         end if;
2111                      end if;
2112                   end if;
2113
2114                   return;
2115                end if;
2116
2117             else
2118                --  Normalize_Actuals has verified that a default value exists
2119                --  for this formal. Current actual names a subsequent formal.
2120
2121                Next_Formal (Formal);
2122             end if;
2123          end loop;
2124
2125          --  On exit, all actuals match
2126
2127          Indicate_Name_And_Type;
2128       end if;
2129    end Analyze_One_Call;
2130
2131    ---------------------------
2132    -- Analyze_Operator_Call --
2133    ---------------------------
2134
2135    procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2136       Op_Name : constant Name_Id := Chars (Op_Id);
2137       Act1    : constant Node_Id := First_Actual (N);
2138       Act2    : constant Node_Id := Next_Actual (Act1);
2139
2140    begin
2141       --  Binary operator case
2142
2143       if Present (Act2) then
2144
2145          --  If more than two operands, then not binary operator after all
2146
2147          if Present (Next_Actual (Act2)) then
2148             return;
2149
2150          elsif     Op_Name = Name_Op_Add
2151            or else Op_Name = Name_Op_Subtract
2152            or else Op_Name = Name_Op_Multiply
2153            or else Op_Name = Name_Op_Divide
2154            or else Op_Name = Name_Op_Mod
2155            or else Op_Name = Name_Op_Rem
2156            or else Op_Name = Name_Op_Expon
2157          then
2158             Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2159
2160          elsif     Op_Name =  Name_Op_And
2161            or else Op_Name = Name_Op_Or
2162            or else Op_Name = Name_Op_Xor
2163          then
2164             Find_Boolean_Types (Act1, Act2, Op_Id, N);
2165
2166          elsif     Op_Name = Name_Op_Lt
2167            or else Op_Name = Name_Op_Le
2168            or else Op_Name = Name_Op_Gt
2169            or else Op_Name = Name_Op_Ge
2170          then
2171             Find_Comparison_Types (Act1, Act2, Op_Id,  N);
2172
2173          elsif     Op_Name = Name_Op_Eq
2174            or else Op_Name = Name_Op_Ne
2175          then
2176             Find_Equality_Types (Act1, Act2, Op_Id,  N);
2177
2178          elsif     Op_Name = Name_Op_Concat then
2179             Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2180
2181          --  Is this else null correct, or should it be an abort???
2182
2183          else
2184             null;
2185          end if;
2186
2187       --  Unary operator case
2188
2189       else
2190          if Op_Name = Name_Op_Subtract or else
2191             Op_Name = Name_Op_Add      or else
2192             Op_Name = Name_Op_Abs
2193          then
2194             Find_Unary_Types (Act1, Op_Id, N);
2195
2196          elsif
2197             Op_Name = Name_Op_Not
2198          then
2199             Find_Negation_Types (Act1, Op_Id, N);
2200
2201          --  Is this else null correct, or should it be an abort???
2202
2203          else
2204             null;
2205          end if;
2206       end if;
2207    end Analyze_Operator_Call;
2208
2209    -------------------------------------------
2210    -- Analyze_Overloaded_Selected_Component --
2211    -------------------------------------------
2212
2213    procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2214       Nam   : constant Node_Id := Prefix (N);
2215       Sel   : constant Node_Id := Selector_Name (N);
2216       Comp  : Entity_Id;
2217       I     : Interp_Index;
2218       It    : Interp;
2219       T     : Entity_Id;
2220
2221    begin
2222       Set_Etype (Sel, Any_Type);
2223
2224       Get_First_Interp (Nam, I, It);
2225       while Present (It.Typ) loop
2226          if Is_Access_Type (It.Typ) then
2227             T := Designated_Type (It.Typ);
2228             Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2229          else
2230             T := It.Typ;
2231          end if;
2232
2233          if Is_Record_Type (T) then
2234             Comp := First_Entity (T);
2235             while Present (Comp) loop
2236                if Chars (Comp) = Chars (Sel)
2237                  and then Is_Visible_Component (Comp)
2238                then
2239                   Set_Entity_With_Style_Check (Sel, Comp);
2240                   Generate_Reference (Comp, Sel);
2241
2242                   Set_Etype (Sel, Etype (Comp));
2243                   Add_One_Interp (N, Etype (Comp), Etype (Comp));
2244
2245                   --  This also specifies a candidate to resolve the name.
2246                   --  Further overloading will be resolved from context.
2247
2248                   Set_Etype (Nam, It.Typ);
2249                end if;
2250
2251                Next_Entity (Comp);
2252             end loop;
2253
2254          elsif Is_Concurrent_Type (T) then
2255             Comp := First_Entity (T);
2256             while Present (Comp)
2257               and then Comp /= First_Private_Entity (T)
2258             loop
2259                if Chars (Comp) = Chars (Sel) then
2260                   if Is_Overloadable (Comp) then
2261                      Add_One_Interp (Sel, Comp, Etype (Comp));
2262                   else
2263                      Set_Entity_With_Style_Check (Sel, Comp);
2264                      Generate_Reference (Comp, Sel);
2265                   end if;
2266
2267                   Set_Etype (Sel, Etype (Comp));
2268                   Set_Etype (N,   Etype (Comp));
2269                   Set_Etype (Nam, It.Typ);
2270
2271                   --  For access type case, introduce explicit deference for
2272                   --  more uniform treatment of entry calls.
2273
2274                   if Is_Access_Type (Etype (Nam)) then
2275                      Insert_Explicit_Dereference (Nam);
2276                      Error_Msg_NW
2277                        (Warn_On_Dereference, "?implicit dereference", N);
2278                   end if;
2279                end if;
2280
2281                Next_Entity (Comp);
2282             end loop;
2283
2284             Set_Is_Overloaded (N, Is_Overloaded (Sel));
2285          end if;
2286
2287          Get_Next_Interp (I, It);
2288       end loop;
2289
2290       if Etype (N) = Any_Type then
2291          Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2292          Set_Entity (Sel, Any_Id);
2293          Set_Etype  (Sel, Any_Type);
2294       end if;
2295    end Analyze_Overloaded_Selected_Component;
2296
2297    ----------------------------------
2298    -- Analyze_Qualified_Expression --
2299    ----------------------------------
2300
2301    procedure Analyze_Qualified_Expression (N : Node_Id) is
2302       Mark : constant Entity_Id := Subtype_Mark (N);
2303       T    : Entity_Id;
2304
2305    begin
2306       Set_Etype (N, Any_Type);
2307       Find_Type (Mark);
2308       T := Entity (Mark);
2309
2310       if T = Any_Type then
2311          return;
2312       end if;
2313
2314       Check_Fully_Declared (T, N);
2315       Analyze_Expression (Expression (N));
2316       Set_Etype  (N, T);
2317    end Analyze_Qualified_Expression;
2318
2319    -------------------
2320    -- Analyze_Range --
2321    -------------------
2322
2323    procedure Analyze_Range (N : Node_Id) is
2324       L        : constant Node_Id := Low_Bound (N);
2325       H        : constant Node_Id := High_Bound (N);
2326       I1, I2   : Interp_Index;
2327       It1, It2 : Interp;
2328
2329       procedure Check_Common_Type (T1, T2 : Entity_Id);
2330       --  Verify the compatibility of two types,  and choose the
2331       --  non universal one if the other is universal.
2332
2333       procedure Check_High_Bound (T : Entity_Id);
2334       --  Test one interpretation of the low bound against all those
2335       --  of the high bound.
2336
2337       procedure Check_Universal_Expression (N : Node_Id);
2338       --  In Ada83, reject bounds of a universal range that are not
2339       --  literals or entity names.
2340
2341       -----------------------
2342       -- Check_Common_Type --
2343       -----------------------
2344
2345       procedure Check_Common_Type (T1, T2 : Entity_Id) is
2346       begin
2347          if Covers (T1, T2) or else Covers (T2, T1) then
2348             if T1 = Universal_Integer
2349               or else T1 = Universal_Real
2350               or else T1 = Any_Character
2351             then
2352                Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2353
2354             elsif T1 = T2 then
2355                Add_One_Interp (N, T1, T1);
2356
2357             else
2358                Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2359             end if;
2360          end if;
2361       end Check_Common_Type;
2362
2363       ----------------------
2364       -- Check_High_Bound --
2365       ----------------------
2366
2367       procedure Check_High_Bound (T : Entity_Id) is
2368       begin
2369          if not Is_Overloaded (H) then
2370             Check_Common_Type (T, Etype (H));
2371          else
2372             Get_First_Interp (H, I2, It2);
2373             while Present (It2.Typ) loop
2374                Check_Common_Type (T, It2.Typ);
2375                Get_Next_Interp (I2, It2);
2376             end loop;
2377          end if;
2378       end Check_High_Bound;
2379
2380       -----------------------------
2381       -- Is_Universal_Expression --
2382       -----------------------------
2383
2384       procedure Check_Universal_Expression (N : Node_Id) is
2385       begin
2386          if Etype (N) = Universal_Integer
2387            and then Nkind (N) /= N_Integer_Literal
2388            and then not Is_Entity_Name (N)
2389            and then Nkind (N) /= N_Attribute_Reference
2390          then
2391             Error_Msg_N ("illegal bound in discrete range", N);
2392          end if;
2393       end Check_Universal_Expression;
2394
2395    --  Start of processing for Analyze_Range
2396
2397    begin
2398       Set_Etype (N, Any_Type);
2399       Analyze_Expression (L);
2400       Analyze_Expression (H);
2401
2402       if Etype (L) = Any_Type or else Etype (H) = Any_Type then
2403          return;
2404
2405       else
2406          if not Is_Overloaded (L) then
2407             Check_High_Bound (Etype (L));
2408          else
2409             Get_First_Interp (L, I1, It1);
2410             while Present (It1.Typ) loop
2411                Check_High_Bound (It1.Typ);
2412                Get_Next_Interp (I1, It1);
2413             end loop;
2414          end if;
2415
2416          --  If result is Any_Type, then we did not find a compatible pair
2417
2418          if Etype (N) = Any_Type then
2419             Error_Msg_N ("incompatible types in range ", N);
2420          end if;
2421       end if;
2422
2423       if Ada_Version = Ada_83
2424         and then
2425           (Nkind (Parent (N)) = N_Loop_Parameter_Specification
2426              or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
2427       then
2428          Check_Universal_Expression (L);
2429          Check_Universal_Expression (H);
2430       end if;
2431    end Analyze_Range;
2432
2433    -----------------------
2434    -- Analyze_Reference --
2435    -----------------------
2436
2437    procedure Analyze_Reference (N : Node_Id) is
2438       P        : constant Node_Id := Prefix (N);
2439       Acc_Type : Entity_Id;
2440    begin
2441       Analyze (P);
2442       Acc_Type := Create_Itype (E_Allocator_Type, N);
2443       Set_Etype                    (Acc_Type,  Acc_Type);
2444       Init_Size_Align              (Acc_Type);
2445       Set_Directly_Designated_Type (Acc_Type, Etype (P));
2446       Set_Etype (N, Acc_Type);
2447    end Analyze_Reference;
2448
2449    --------------------------------
2450    -- Analyze_Selected_Component --
2451    --------------------------------
2452
2453    --  Prefix is a record type or a task or protected type. In the
2454    --  later case, the selector must denote a visible entry.
2455
2456    procedure Analyze_Selected_Component (N : Node_Id) is
2457       Name        : constant Node_Id := Prefix (N);
2458       Sel         : constant Node_Id := Selector_Name (N);
2459       Comp        : Entity_Id;
2460       Entity_List : Entity_Id;
2461       Prefix_Type : Entity_Id;
2462       Act_Decl    : Node_Id;
2463       In_Scope    : Boolean;
2464       Parent_N    : Node_Id;
2465
2466    --  Start of processing for Analyze_Selected_Component
2467
2468    begin
2469       Set_Etype (N, Any_Type);
2470
2471       if Is_Overloaded (Name) then
2472          Analyze_Overloaded_Selected_Component (N);
2473          return;
2474
2475       elsif Etype (Name) = Any_Type then
2476          Set_Entity (Sel, Any_Id);
2477          Set_Etype (Sel, Any_Type);
2478          return;
2479
2480       else
2481          --  Function calls that are prefixes of selected components must be
2482          --  fully resolved in case we need to build an actual subtype, or
2483          --  do some other operation requiring a fully resolved prefix.
2484
2485          --  Note: Resolving all Nkinds of nodes here doesn't work.
2486          --  (Breaks 2129-008) ???.
2487
2488          if Nkind (Name) = N_Function_Call then
2489             Resolve (Name);
2490          end if;
2491
2492          Prefix_Type := Etype (Name);
2493       end if;
2494
2495       if Is_Access_Type (Prefix_Type) then
2496
2497          --  A RACW object can never be used as prefix of a selected
2498          --  component since that means it is dereferenced without
2499          --  being a controlling operand of a dispatching operation
2500          --  (RM E.2.2(15)).
2501
2502          if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
2503            and then Comes_From_Source (N)
2504          then
2505             Error_Msg_N
2506               ("invalid dereference of a remote access to class-wide value",
2507                N);
2508
2509          --  Normal case of selected component applied to access type
2510
2511          else
2512             Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2513          end if;
2514
2515          Prefix_Type := Designated_Type (Prefix_Type);
2516       end if;
2517
2518       if Ekind (Prefix_Type) = E_Private_Subtype then
2519          Prefix_Type := Base_Type (Prefix_Type);
2520       end if;
2521
2522       Entity_List := Prefix_Type;
2523
2524       --  For class-wide types, use the entity list of the root type. This
2525       --  indirection is specially important for private extensions because
2526       --  only the root type get switched (not the class-wide type).
2527
2528       if Is_Class_Wide_Type (Prefix_Type) then
2529          Entity_List := Root_Type (Prefix_Type);
2530       end if;
2531
2532       Comp := First_Entity (Entity_List);
2533
2534       --  If the selector has an original discriminant, the node appears in
2535       --  an instance. Replace the discriminant with the corresponding one
2536       --  in the current discriminated type. For nested generics, this must
2537       --  be done transitively, so note the new original discriminant.
2538
2539       if Nkind (Sel) = N_Identifier
2540         and then Present (Original_Discriminant (Sel))
2541       then
2542          Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
2543
2544          --  Mark entity before rewriting, for completeness and because
2545          --  subsequent semantic checks might examine the original node.
2546
2547          Set_Entity (Sel, Comp);
2548          Rewrite (Selector_Name (N),
2549            New_Occurrence_Of (Comp, Sloc (N)));
2550          Set_Original_Discriminant (Selector_Name (N), Comp);
2551          Set_Etype (N, Etype (Comp));
2552
2553          if Is_Access_Type (Etype (Name)) then
2554             Insert_Explicit_Dereference (Name);
2555             Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2556          end if;
2557
2558       elsif Is_Record_Type (Prefix_Type) then
2559
2560          --  Find component with given name
2561
2562          while Present (Comp) loop
2563             if Chars (Comp) = Chars (Sel)
2564               and then Is_Visible_Component (Comp)
2565             then
2566                Set_Entity_With_Style_Check (Sel, Comp);
2567                Generate_Reference (Comp, Sel);
2568
2569                Set_Etype (Sel, Etype (Comp));
2570
2571                if Ekind (Comp) = E_Discriminant then
2572                   if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
2573                      Error_Msg_N
2574                        ("cannot reference discriminant of Unchecked_Union",
2575                         Sel);
2576                   end if;
2577
2578                   if Is_Generic_Type (Prefix_Type)
2579                        or else
2580                      Is_Generic_Type (Root_Type (Prefix_Type))
2581                   then
2582                      Set_Original_Discriminant (Sel, Comp);
2583                   end if;
2584                end if;
2585
2586                --  Resolve the prefix early otherwise it is not possible to
2587                --  build the actual subtype of the component: it may need
2588                --  to duplicate this prefix and duplication is only allowed
2589                --  on fully resolved expressions.
2590
2591                Resolve (Name);
2592
2593                --  We never need an actual subtype for the case of a selection
2594                --  for a indexed component of a non-packed array, since in
2595                --  this case gigi generates all the checks and can find the
2596                --  necessary bounds information.
2597
2598                --  We also do not need an actual subtype for the case of
2599                --  a first, last, length, or range attribute applied to a
2600                --  non-packed array, since gigi can again get the bounds in
2601                --  these cases (gigi cannot handle the packed case, since it
2602                --  has the bounds of the packed array type, not the original
2603                --  bounds of the type). However, if the prefix is itself a
2604                --  selected component, as in a.b.c (i), gigi may regard a.b.c
2605                --  as a dynamic-sized temporary, so we do generate an actual
2606                --  subtype for this case.
2607
2608                Parent_N := Parent (N);
2609
2610                if not Is_Packed (Etype (Comp))
2611                  and then
2612                    ((Nkind (Parent_N) = N_Indexed_Component
2613                       and then Nkind (Name) /= N_Selected_Component)
2614                      or else
2615                       (Nkind (Parent_N) = N_Attribute_Reference
2616                          and then (Attribute_Name (Parent_N) = Name_First
2617                                     or else
2618                                    Attribute_Name (Parent_N) = Name_Last
2619                                     or else
2620                                    Attribute_Name (Parent_N) = Name_Length
2621                                     or else
2622                                    Attribute_Name (Parent_N) = Name_Range)))
2623                then
2624                   Set_Etype (N, Etype (Comp));
2625
2626                --  In all other cases, we currently build an actual subtype. It
2627                --  seems likely that many of these cases can be avoided, but
2628                --  right now, the front end makes direct references to the
2629                --  bounds (e.g. in generating a length check), and if we do
2630                --  not make an actual subtype, we end up getting a direct
2631                --  reference to a discriminant which will not do.
2632
2633                else
2634                   Act_Decl :=
2635                     Build_Actual_Subtype_Of_Component (Etype (Comp), N);
2636                   Insert_Action (N, Act_Decl);
2637
2638                   if No (Act_Decl) then
2639                      Set_Etype (N, Etype (Comp));
2640
2641                   else
2642                      --  Component type depends on discriminants. Enter the
2643                      --  main attributes of the subtype.
2644
2645                      declare
2646                         Subt : constant Entity_Id :=
2647                                  Defining_Identifier (Act_Decl);
2648
2649                      begin
2650                         Set_Etype (Subt, Base_Type (Etype (Comp)));
2651                         Set_Ekind (Subt, Ekind (Etype (Comp)));
2652                         Set_Etype (N, Subt);
2653                      end;
2654                   end if;
2655                end if;
2656
2657                return;
2658             end if;
2659
2660             Next_Entity (Comp);
2661          end loop;
2662
2663          --  Ada 2005 (AI-252)
2664
2665          if Ada_Version >= Ada_05
2666            and then Is_Tagged_Type (Prefix_Type)
2667            and then Try_Object_Operation (N)
2668          then
2669             return;
2670
2671             --  If the transformation fails, it will be necessary
2672             --  to redo the analysis with all errors enabled, to indicate
2673             --  candidate interpretations and reasons for each failure ???
2674
2675          end if;
2676
2677       elsif Is_Private_Type (Prefix_Type) then
2678
2679          --  Allow access only to discriminants of the type. If the
2680          --  type has no full view, gigi uses the parent type for
2681          --  the components, so we do the same here.
2682
2683          if No (Full_View (Prefix_Type)) then
2684             Entity_List := Root_Type (Base_Type (Prefix_Type));
2685             Comp := First_Entity (Entity_List);
2686          end if;
2687
2688          while Present (Comp) loop
2689             if Chars (Comp) = Chars (Sel) then
2690                if Ekind (Comp) = E_Discriminant then
2691                   Set_Entity_With_Style_Check (Sel, Comp);
2692                   Generate_Reference (Comp, Sel);
2693
2694                   Set_Etype (Sel, Etype (Comp));
2695                   Set_Etype (N,   Etype (Comp));
2696
2697                   if Is_Generic_Type (Prefix_Type)
2698                     or else
2699                      Is_Generic_Type (Root_Type (Prefix_Type))
2700                   then
2701                      Set_Original_Discriminant (Sel, Comp);
2702                   end if;
2703
2704                else
2705                   Error_Msg_NE
2706                     ("invisible selector for }",
2707                      N, First_Subtype (Prefix_Type));
2708                   Set_Entity (Sel, Any_Id);
2709                   Set_Etype (N, Any_Type);
2710                end if;
2711
2712                return;
2713             end if;
2714
2715             Next_Entity (Comp);
2716          end loop;
2717
2718       elsif Is_Concurrent_Type (Prefix_Type) then
2719
2720          --  Prefix is concurrent type. Find visible operation with given name
2721          --  For a task, this can only include entries or discriminants if
2722          --  the task type is not an enclosing scope. If it is an enclosing
2723          --  scope (e.g. in an inner task) then all entities are visible, but
2724          --  the prefix must denote the enclosing scope, i.e. can only be
2725          --  a direct name or an expanded name.
2726
2727          Set_Etype (Sel,  Any_Type);
2728          In_Scope := In_Open_Scopes (Prefix_Type);
2729
2730          while Present (Comp) loop
2731             if Chars (Comp) = Chars (Sel) then
2732                if Is_Overloadable (Comp) then
2733                   Add_One_Interp (Sel, Comp, Etype (Comp));
2734
2735                elsif Ekind (Comp) = E_Discriminant
2736                  or else Ekind (Comp) = E_Entry_Family
2737                  or else (In_Scope
2738                    and then Is_Entity_Name (Name))
2739                then
2740                   Set_Entity_With_Style_Check (Sel, Comp);
2741                   Generate_Reference (Comp, Sel);
2742
2743                else
2744                   goto Next_Comp;
2745                end if;
2746
2747                Set_Etype (Sel, Etype (Comp));
2748                Set_Etype (N,   Etype (Comp));
2749
2750                if Ekind (Comp) = E_Discriminant then
2751                   Set_Original_Discriminant (Sel, Comp);
2752                end if;
2753
2754                --  For access type case, introduce explicit deference for
2755                --  more uniform treatment of entry calls.
2756
2757                if Is_Access_Type (Etype (Name)) then
2758                   Insert_Explicit_Dereference (Name);
2759                   Error_Msg_NW
2760                     (Warn_On_Dereference, "?implicit dereference", N);
2761                end if;
2762             end if;
2763
2764             <<Next_Comp>>
2765                Next_Entity (Comp);
2766                exit when not In_Scope
2767                  and then
2768                    Comp = First_Private_Entity (Base_Type (Prefix_Type));
2769          end loop;
2770
2771          Set_Is_Overloaded (N, Is_Overloaded (Sel));
2772
2773       else
2774          --  Invalid prefix
2775
2776          Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
2777       end if;
2778
2779       --  If N still has no type, the component is not defined in the prefix
2780
2781       if Etype (N) = Any_Type then
2782
2783          --  If the prefix is a single concurrent object, use its name in
2784          --  the error message, rather than that of its anonymous type.
2785
2786          if Is_Concurrent_Type (Prefix_Type)
2787            and then Is_Internal_Name (Chars (Prefix_Type))
2788            and then not Is_Derived_Type (Prefix_Type)
2789            and then Is_Entity_Name (Name)
2790          then
2791
2792             Error_Msg_Node_2 := Entity (Name);
2793             Error_Msg_NE ("no selector& for&", N, Sel);
2794
2795             Check_Misspelled_Selector (Entity_List, Sel);
2796
2797          elsif Is_Generic_Type (Prefix_Type)
2798            and then Ekind (Prefix_Type) = E_Record_Type_With_Private
2799            and then Prefix_Type /= Etype (Prefix_Type)
2800            and then Is_Record_Type (Etype (Prefix_Type))
2801          then
2802             --  If this is a derived formal type, the parent may have a
2803             --  different visibility at this point. Try for an inherited
2804             --  component before reporting an error.
2805
2806             Set_Etype (Prefix (N), Etype (Prefix_Type));
2807             Analyze_Selected_Component (N);
2808             return;
2809
2810          elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
2811            and then Is_Generic_Actual_Type (Prefix_Type)
2812            and then Present (Full_View (Prefix_Type))
2813          then
2814             --  Similarly, if this the actual for a formal derived type, the
2815             --  component inherited from the generic parent may not be visible
2816             --  in the actual, but the selected component is legal.
2817
2818             declare
2819                Comp : Entity_Id;
2820
2821             begin
2822                Comp :=
2823                  First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
2824                while Present (Comp) loop
2825                   if Chars (Comp) = Chars (Sel) then
2826                      Set_Entity_With_Style_Check (Sel, Comp);
2827                      Set_Etype (Sel, Etype (Comp));
2828                      Set_Etype (N,   Etype (Comp));
2829                      exit;
2830                   end if;
2831
2832                   Next_Component (Comp);
2833                end loop;
2834
2835                pragma Assert (Etype (N) /= Any_Type);
2836             end;
2837
2838          else
2839             if Ekind (Prefix_Type) = E_Record_Subtype then
2840
2841                --  Check whether this is a component of the base type
2842                --  which is absent from a statically constrained subtype.
2843                --  This will raise constraint error at run-time, but is
2844                --  not a compile-time error. When the selector is illegal
2845                --  for base type as well fall through and generate a
2846                --  compilation error anyway.
2847
2848                Comp := First_Component (Base_Type (Prefix_Type));
2849                while Present (Comp) loop
2850                   if Chars (Comp) = Chars (Sel)
2851                     and then Is_Visible_Component (Comp)
2852                   then
2853                      Set_Entity_With_Style_Check (Sel, Comp);
2854                      Generate_Reference (Comp, Sel);
2855                      Set_Etype (Sel, Etype (Comp));
2856                      Set_Etype (N,   Etype (Comp));
2857
2858                      --  Emit appropriate message. Gigi will replace the
2859                      --  node subsequently with the appropriate Raise.
2860
2861                      Apply_Compile_Time_Constraint_Error
2862                        (N, "component not present in }?",
2863                         CE_Discriminant_Check_Failed,
2864                         Ent => Prefix_Type, Rep => False);
2865                      Set_Raises_Constraint_Error (N);
2866                      return;
2867                   end if;
2868
2869                   Next_Component (Comp);
2870                end loop;
2871
2872             end if;
2873
2874             Error_Msg_Node_2 := First_Subtype (Prefix_Type);
2875             Error_Msg_NE ("no selector& for}", N, Sel);
2876
2877             Check_Misspelled_Selector (Entity_List, Sel);
2878
2879          end if;
2880
2881          Set_Entity (Sel, Any_Id);
2882          Set_Etype (Sel, Any_Type);
2883       end if;
2884    end Analyze_Selected_Component;
2885
2886    ---------------------------
2887    -- Analyze_Short_Circuit --
2888    ---------------------------
2889
2890    procedure Analyze_Short_Circuit (N : Node_Id) is
2891       L   : constant Node_Id := Left_Opnd  (N);
2892       R   : constant Node_Id := Right_Opnd (N);
2893       Ind : Interp_Index;
2894       It  : Interp;
2895
2896    begin
2897       Analyze_Expression (L);
2898       Analyze_Expression (R);
2899       Set_Etype (N, Any_Type);
2900
2901       if not Is_Overloaded (L) then
2902
2903          if Root_Type (Etype (L)) = Standard_Boolean
2904            and then Has_Compatible_Type (R, Etype (L))
2905          then
2906             Add_One_Interp (N, Etype (L), Etype (L));
2907          end if;
2908
2909       else
2910          Get_First_Interp (L, Ind, It);
2911
2912          while Present (It.Typ) loop
2913             if Root_Type (It.Typ) = Standard_Boolean
2914               and then Has_Compatible_Type (R, It.Typ)
2915             then
2916                Add_One_Interp (N, It.Typ, It.Typ);
2917             end if;
2918
2919             Get_Next_Interp (Ind, It);
2920          end loop;
2921       end if;
2922
2923       --  Here we have failed to find an interpretation. Clearly we
2924       --  know that it is not the case that both operands can have
2925       --  an interpretation of Boolean, but this is by far the most
2926       --  likely intended interpretation. So we simply resolve both
2927       --  operands as Booleans, and at least one of these resolutions
2928       --  will generate an error message, and we do not need to give
2929       --  a further error message on the short circuit operation itself.
2930
2931       if Etype (N) = Any_Type then
2932          Resolve (L, Standard_Boolean);
2933          Resolve (R, Standard_Boolean);
2934          Set_Etype (N, Standard_Boolean);
2935       end if;
2936    end Analyze_Short_Circuit;
2937
2938    -------------------
2939    -- Analyze_Slice --
2940    -------------------
2941
2942    procedure Analyze_Slice (N : Node_Id) is
2943       P          : constant Node_Id := Prefix (N);
2944       D          : constant Node_Id := Discrete_Range (N);
2945       Array_Type : Entity_Id;
2946
2947       procedure Analyze_Overloaded_Slice;
2948       --  If the prefix is overloaded, select those interpretations that
2949       --  yield a one-dimensional array type.
2950
2951       ------------------------------
2952       -- Analyze_Overloaded_Slice --
2953       ------------------------------
2954
2955       procedure Analyze_Overloaded_Slice is
2956          I   : Interp_Index;
2957          It  : Interp;
2958          Typ : Entity_Id;
2959
2960       begin
2961          Set_Etype (N, Any_Type);
2962
2963          Get_First_Interp (P, I, It);
2964          while Present (It.Nam) loop
2965             Typ := It.Typ;
2966
2967             if Is_Access_Type (Typ) then
2968                Typ := Designated_Type (Typ);
2969                Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2970             end if;
2971
2972             if Is_Array_Type (Typ)
2973               and then Number_Dimensions (Typ) = 1
2974               and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
2975             then
2976                Add_One_Interp (N, Typ, Typ);
2977             end if;
2978
2979             Get_Next_Interp (I, It);
2980          end loop;
2981
2982          if Etype (N) = Any_Type then
2983             Error_Msg_N ("expect array type in prefix of slice",  N);
2984          end if;
2985       end Analyze_Overloaded_Slice;
2986
2987    --  Start of processing for Analyze_Slice
2988
2989    begin
2990       Analyze (P);
2991       Analyze (D);
2992
2993       if Is_Overloaded (P) then
2994          Analyze_Overloaded_Slice;
2995
2996       else
2997          Array_Type := Etype (P);
2998          Set_Etype (N, Any_Type);
2999
3000          if Is_Access_Type (Array_Type) then
3001             Array_Type := Designated_Type (Array_Type);
3002             Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3003          end if;
3004
3005          if not Is_Array_Type (Array_Type) then
3006             Wrong_Type (P, Any_Array);
3007
3008          elsif Number_Dimensions (Array_Type) > 1 then
3009             Error_Msg_N
3010               ("type is not one-dimensional array in slice prefix", N);
3011
3012          elsif not
3013            Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
3014          then
3015             Wrong_Type (D, Etype (First_Index (Array_Type)));
3016
3017          else
3018             Set_Etype (N, Array_Type);
3019          end if;
3020       end if;
3021    end Analyze_Slice;
3022
3023    -----------------------------
3024    -- Analyze_Type_Conversion --
3025    -----------------------------
3026
3027    procedure Analyze_Type_Conversion (N : Node_Id) is
3028       Expr : constant Node_Id := Expression (N);
3029       T    : Entity_Id;
3030
3031    begin
3032       --  If Conversion_OK is set, then the Etype is already set, and the
3033       --  only processing required is to analyze the expression. This is
3034       --  used to construct certain "illegal" conversions which are not
3035       --  allowed by Ada semantics, but can be handled OK by Gigi, see
3036       --  Sinfo for further details.
3037
3038       if Conversion_OK (N) then
3039          Analyze (Expr);
3040          return;
3041       end if;
3042
3043       --  Otherwise full type analysis is required, as well as some semantic
3044       --  checks to make sure the argument of the conversion is appropriate.
3045
3046       Find_Type (Subtype_Mark (N));
3047       T := Entity (Subtype_Mark (N));
3048       Set_Etype (N, T);
3049       Check_Fully_Declared (T, N);
3050       Analyze_Expression (Expr);
3051       Validate_Remote_Type_Type_Conversion (N);
3052
3053       --  Only remaining step is validity checks on the argument. These
3054       --  are skipped if the conversion does not come from the source.
3055
3056       if not Comes_From_Source (N) then
3057          return;
3058
3059       elsif Nkind (Expr) = N_Null then
3060          Error_Msg_N ("argument of conversion cannot be null", N);
3061          Error_Msg_N ("\use qualified expression instead", N);
3062          Set_Etype (N, Any_Type);
3063
3064       elsif Nkind (Expr) = N_Aggregate then
3065          Error_Msg_N ("argument of conversion cannot be aggregate", N);
3066          Error_Msg_N ("\use qualified expression instead", N);
3067
3068       elsif Nkind (Expr) = N_Allocator then
3069          Error_Msg_N ("argument of conversion cannot be an allocator", N);
3070          Error_Msg_N ("\use qualified expression instead", N);
3071
3072       elsif Nkind (Expr) = N_String_Literal then
3073          Error_Msg_N ("argument of conversion cannot be string literal", N);
3074          Error_Msg_N ("\use qualified expression instead", N);
3075
3076       elsif Nkind (Expr) = N_Character_Literal then
3077          if Ada_Version = Ada_83 then
3078             Resolve (Expr, T);
3079          else
3080             Error_Msg_N ("argument of conversion cannot be character literal",
3081               N);
3082             Error_Msg_N ("\use qualified expression instead", N);
3083          end if;
3084
3085       elsif Nkind (Expr) = N_Attribute_Reference
3086         and then
3087           (Attribute_Name (Expr) = Name_Access            or else
3088            Attribute_Name (Expr) = Name_Unchecked_Access  or else
3089            Attribute_Name (Expr) = Name_Unrestricted_Access)
3090       then
3091          Error_Msg_N ("argument of conversion cannot be access", N);
3092          Error_Msg_N ("\use qualified expression instead", N);
3093       end if;
3094    end Analyze_Type_Conversion;
3095
3096    ----------------------
3097    -- Analyze_Unary_Op --
3098    ----------------------
3099
3100    procedure Analyze_Unary_Op (N : Node_Id) is
3101       R     : constant Node_Id := Right_Opnd (N);
3102       Op_Id : Entity_Id := Entity (N);
3103
3104    begin
3105       Set_Etype (N, Any_Type);
3106       Candidate_Type := Empty;
3107
3108       Analyze_Expression (R);
3109
3110       if Present (Op_Id) then
3111          if Ekind (Op_Id) = E_Operator then
3112             Find_Unary_Types (R, Op_Id,  N);
3113          else
3114             Add_One_Interp (N, Op_Id, Etype (Op_Id));
3115          end if;
3116
3117       else
3118          Op_Id := Get_Name_Entity_Id (Chars (N));
3119          while Present (Op_Id) loop
3120             if Ekind (Op_Id) = E_Operator then
3121                if No (Next_Entity (First_Entity (Op_Id))) then
3122                   Find_Unary_Types (R, Op_Id,  N);
3123                end if;
3124
3125             elsif Is_Overloadable (Op_Id) then
3126                Analyze_User_Defined_Unary_Op (N, Op_Id);
3127             end if;
3128
3129             Op_Id := Homonym (Op_Id);
3130          end loop;
3131       end if;
3132
3133       Operator_Check (N);
3134    end Analyze_Unary_Op;
3135
3136    ----------------------------------
3137    -- Analyze_Unchecked_Expression --
3138    ----------------------------------
3139
3140    procedure Analyze_Unchecked_Expression (N : Node_Id) is
3141    begin
3142       Analyze (Expression (N), Suppress => All_Checks);
3143       Set_Etype (N, Etype (Expression (N)));
3144       Save_Interps (Expression (N), N);
3145    end Analyze_Unchecked_Expression;
3146
3147    ---------------------------------------
3148    -- Analyze_Unchecked_Type_Conversion --
3149    ---------------------------------------
3150
3151    procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
3152    begin
3153       Find_Type (Subtype_Mark (N));
3154       Analyze_Expression (Expression (N));
3155       Set_Etype (N, Entity (Subtype_Mark (N)));
3156    end Analyze_Unchecked_Type_Conversion;
3157
3158    ------------------------------------
3159    -- Analyze_User_Defined_Binary_Op --
3160    ------------------------------------
3161
3162    procedure Analyze_User_Defined_Binary_Op
3163      (N     : Node_Id;
3164       Op_Id : Entity_Id)
3165    is
3166    begin
3167       --  Only do analysis if the operator Comes_From_Source, since otherwise
3168       --  the operator was generated by the expander, and all such operators
3169       --  always refer to the operators in package Standard.
3170
3171       if Comes_From_Source (N) then
3172          declare
3173             F1 : constant Entity_Id := First_Formal (Op_Id);
3174             F2 : constant Entity_Id := Next_Formal (F1);
3175
3176          begin
3177             --  Verify that Op_Id is a visible binary function. Note that since
3178             --  we know Op_Id is overloaded, potentially use visible means use
3179             --  visible for sure (RM 9.4(11)).
3180
3181             if Ekind (Op_Id) = E_Function
3182               and then Present (F2)
3183               and then (Is_Immediately_Visible (Op_Id)
3184                          or else Is_Potentially_Use_Visible (Op_Id))
3185               and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
3186               and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
3187             then
3188                Add_One_Interp (N, Op_Id, Etype (Op_Id));
3189
3190                if Debug_Flag_E then
3191                   Write_Str ("user defined operator ");
3192                   Write_Name (Chars (Op_Id));
3193                   Write_Str (" on node ");
3194                   Write_Int (Int (N));
3195                   Write_Eol;
3196                end if;
3197             end if;
3198          end;
3199       end if;
3200    end Analyze_User_Defined_Binary_Op;
3201
3202    -----------------------------------
3203    -- Analyze_User_Defined_Unary_Op --
3204    -----------------------------------
3205
3206    procedure Analyze_User_Defined_Unary_Op
3207      (N     : Node_Id;
3208       Op_Id : Entity_Id)
3209    is
3210    begin
3211       --  Only do analysis if the operator Comes_From_Source, since otherwise
3212       --  the operator was generated by the expander, and all such operators
3213       --  always refer to the operators in package Standard.
3214
3215       if Comes_From_Source (N) then
3216          declare
3217             F : constant Entity_Id := First_Formal (Op_Id);
3218
3219          begin
3220             --  Verify that Op_Id is a visible unary function. Note that since
3221             --  we know Op_Id is overloaded, potentially use visible means use
3222             --  visible for sure (RM 9.4(11)).
3223
3224             if Ekind (Op_Id) = E_Function
3225               and then No (Next_Formal (F))
3226               and then (Is_Immediately_Visible (Op_Id)
3227                          or else Is_Potentially_Use_Visible (Op_Id))
3228               and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
3229             then
3230                Add_One_Interp (N, Op_Id, Etype (Op_Id));
3231             end if;
3232          end;
3233       end if;
3234    end Analyze_User_Defined_Unary_Op;
3235
3236    ---------------------------
3237    -- Check_Arithmetic_Pair --
3238    ---------------------------
3239
3240    procedure Check_Arithmetic_Pair
3241      (T1, T2 : Entity_Id;
3242       Op_Id  : Entity_Id;
3243       N      : Node_Id)
3244    is
3245       Op_Name : constant Name_Id   := Chars (Op_Id);
3246
3247       function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
3248       --  Get specific type (i.e. non-universal type if there is one)
3249
3250       -------------------
3251       -- Specific_Type --
3252       -------------------
3253
3254       function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
3255       begin
3256          if T1 = Universal_Integer or else T1 = Universal_Real then
3257             return Base_Type (T2);
3258          else
3259             return Base_Type (T1);
3260          end if;
3261       end Specific_Type;
3262
3263    --  Start of processing for Check_Arithmetic_Pair
3264
3265    begin
3266       if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
3267
3268          if Is_Numeric_Type (T1)
3269            and then Is_Numeric_Type (T2)
3270            and then (Covers (T1, T2) or else Covers (T2, T1))
3271          then
3272             Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3273          end if;
3274
3275       elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
3276
3277          if Is_Fixed_Point_Type (T1)
3278            and then (Is_Fixed_Point_Type (T2)
3279                        or else T2 = Universal_Real)
3280          then
3281             --  If Treat_Fixed_As_Integer is set then the Etype is already set
3282             --  and no further processing is required (this is the case of an
3283             --  operator constructed by Exp_Fixd for a fixed point operation)
3284             --  Otherwise add one interpretation with universal fixed result
3285             --  If the operator is given in  functional notation, it comes
3286             --  from source and Fixed_As_Integer cannot apply.
3287
3288             if Nkind (N) not in N_Op
3289               or else not Treat_Fixed_As_Integer (N)
3290             then
3291                Add_One_Interp (N, Op_Id, Universal_Fixed);
3292             end if;
3293
3294          elsif Is_Fixed_Point_Type (T2)
3295            and then (Nkind (N) not in N_Op
3296                       or else not Treat_Fixed_As_Integer (N))
3297            and then T1 = Universal_Real
3298          then
3299             Add_One_Interp (N, Op_Id, Universal_Fixed);
3300
3301          elsif Is_Numeric_Type (T1)
3302            and then Is_Numeric_Type (T2)
3303            and then (Covers (T1, T2) or else Covers (T2, T1))
3304          then
3305             Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3306
3307          elsif Is_Fixed_Point_Type (T1)
3308            and then (Base_Type (T2) = Base_Type (Standard_Integer)
3309                        or else T2 = Universal_Integer)
3310          then
3311             Add_One_Interp (N, Op_Id, T1);
3312
3313          elsif T2 = Universal_Real
3314            and then Base_Type (T1) = Base_Type (Standard_Integer)
3315            and then Op_Name = Name_Op_Multiply
3316          then
3317             Add_One_Interp (N, Op_Id, Any_Fixed);
3318
3319          elsif T1 = Universal_Real
3320            and then Base_Type (T2) = Base_Type (Standard_Integer)
3321          then
3322             Add_One_Interp (N, Op_Id, Any_Fixed);
3323
3324          elsif Is_Fixed_Point_Type (T2)
3325            and then (Base_Type (T1) = Base_Type (Standard_Integer)
3326                        or else T1 = Universal_Integer)
3327            and then Op_Name = Name_Op_Multiply
3328          then
3329             Add_One_Interp (N, Op_Id, T2);
3330
3331          elsif T1 = Universal_Real and then T2 = Universal_Integer then
3332             Add_One_Interp (N, Op_Id, T1);
3333
3334          elsif T2 = Universal_Real
3335            and then T1 = Universal_Integer
3336            and then Op_Name = Name_Op_Multiply
3337          then
3338             Add_One_Interp (N, Op_Id, T2);
3339          end if;
3340
3341       elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
3342
3343          --  Note: The fixed-point operands case with Treat_Fixed_As_Integer
3344          --  set does not require any special processing, since the Etype is
3345          --  already set (case of operation constructed by Exp_Fixed).
3346
3347          if Is_Integer_Type (T1)
3348            and then (Covers (T1, T2) or else Covers (T2, T1))
3349          then
3350             Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
3351          end if;
3352
3353       elsif Op_Name = Name_Op_Expon then
3354          if Is_Numeric_Type (T1)
3355            and then not Is_Fixed_Point_Type (T1)
3356            and then (Base_Type (T2) = Base_Type (Standard_Integer)
3357                       or else T2 = Universal_Integer)
3358          then
3359             Add_One_Interp (N, Op_Id, Base_Type (T1));
3360          end if;
3361
3362       else pragma Assert (Nkind (N) in N_Op_Shift);
3363
3364          --  If not one of the predefined operators, the node may be one
3365          --  of the intrinsic functions. Its kind is always specific, and
3366          --  we can use it directly, rather than the name of the operation.
3367
3368          if Is_Integer_Type (T1)
3369            and then (Base_Type (T2) = Base_Type (Standard_Integer)
3370                       or else T2 = Universal_Integer)
3371          then
3372             Add_One_Interp (N, Op_Id, Base_Type (T1));
3373          end if;
3374       end if;
3375    end Check_Arithmetic_Pair;
3376
3377    -------------------------------
3378    -- Check_Misspelled_Selector --
3379    -------------------------------
3380
3381    procedure Check_Misspelled_Selector
3382      (Prefix : Entity_Id;
3383       Sel    : Node_Id)
3384    is
3385       Max_Suggestions   : constant := 2;
3386       Nr_Of_Suggestions : Natural := 0;
3387
3388       Suggestion_1 : Entity_Id := Empty;
3389       Suggestion_2 : Entity_Id := Empty;
3390
3391       Comp : Entity_Id;
3392
3393    begin
3394       --  All the components of the prefix of selector Sel are matched
3395       --  against  Sel and a count is maintained of possible misspellings.
3396       --  When at the end of the analysis there are one or two (not more!)
3397       --  possible misspellings, these misspellings will be suggested as
3398       --  possible correction.
3399
3400       if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
3401
3402          --  Concurrent types should be handled as well ???
3403
3404          return;
3405       end if;
3406
3407       Get_Name_String (Chars (Sel));
3408
3409       declare
3410          S  : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
3411
3412       begin
3413          Comp  := First_Entity (Prefix);
3414          while Nr_Of_Suggestions <= Max_Suggestions
3415             and then Present (Comp)
3416          loop
3417             if Is_Visible_Component (Comp) then
3418                Get_Name_String (Chars (Comp));
3419
3420                if Is_Bad_Spelling_Of (Name_Buffer (1 .. Name_Len), S) then
3421                   Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
3422
3423                   case Nr_Of_Suggestions is
3424                      when 1      => Suggestion_1 := Comp;
3425                      when 2      => Suggestion_2 := Comp;
3426                      when others => exit;
3427                   end case;
3428                end if;
3429             end if;
3430
3431             Comp := Next_Entity (Comp);
3432          end loop;
3433
3434          --  Report at most two suggestions
3435
3436          if Nr_Of_Suggestions = 1 then
3437             Error_Msg_NE ("\possible misspelling of&", Sel, Suggestion_1);
3438
3439          elsif Nr_Of_Suggestions = 2 then
3440             Error_Msg_Node_2 := Suggestion_2;
3441             Error_Msg_NE ("\possible misspelling of& or&",
3442               Sel, Suggestion_1);
3443          end if;
3444       end;
3445    end Check_Misspelled_Selector;
3446
3447    ----------------------
3448    -- Defined_In_Scope --
3449    ----------------------
3450
3451    function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
3452    is
3453       S1 : constant Entity_Id := Scope (Base_Type (T));
3454    begin
3455       return S1 = S
3456         or else (S1 = System_Aux_Id and then S = Scope (S1));
3457    end Defined_In_Scope;
3458
3459    -------------------
3460    -- Diagnose_Call --
3461    -------------------
3462
3463    procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
3464       Actual           : Node_Id;
3465       X                : Interp_Index;
3466       It               : Interp;
3467       Success          : Boolean;
3468       Err_Mode         : Boolean;
3469       New_Nam          : Node_Id;
3470       Void_Interp_Seen : Boolean := False;
3471
3472    begin
3473       if Ada_Version >= Ada_05 then
3474          Actual := First_Actual (N);
3475          while Present (Actual) loop
3476
3477             --  Ada 2005 (AI-50217): Post an error in case of premature
3478             --  usage of an entity from the limited view.
3479
3480             if not Analyzed (Etype (Actual))
3481              and then From_With_Type (Etype (Actual))
3482             then
3483                Error_Msg_Qual_Level := 1;
3484                Error_Msg_NE
3485                 ("missing with_clause for scope of imported type&",
3486                   Actual, Etype (Actual));
3487                Error_Msg_Qual_Level := 0;
3488             end if;
3489
3490             Next_Actual (Actual);
3491          end loop;
3492       end if;
3493
3494       --   Analyze each candidate call again, with full error reporting
3495       --   for each.
3496
3497       Error_Msg_N
3498         ("no candidate interpretations match the actuals:!", Nam);
3499       Err_Mode := All_Errors_Mode;
3500       All_Errors_Mode := True;
3501
3502       --  If this is a call to an operation of a concurrent type,
3503       --  the failed interpretations have been removed from the
3504       --  name. Recover them to provide full diagnostics.
3505
3506       if Nkind (Parent (Nam)) = N_Selected_Component then
3507          Set_Entity (Nam, Empty);
3508          New_Nam := New_Copy_Tree (Parent (Nam));
3509          Set_Is_Overloaded (New_Nam, False);
3510          Set_Is_Overloaded (Selector_Name (New_Nam), False);
3511          Set_Parent (New_Nam, Parent (Parent (Nam)));
3512          Analyze_Selected_Component (New_Nam);
3513          Get_First_Interp (Selector_Name (New_Nam), X, It);
3514       else
3515          Get_First_Interp (Nam, X, It);
3516       end if;
3517
3518       while Present (It.Nam) loop
3519          if Etype (It.Nam) = Standard_Void_Type then
3520             Void_Interp_Seen := True;
3521          end if;
3522
3523          Analyze_One_Call (N, It.Nam, True, Success);
3524          Get_Next_Interp (X, It);
3525       end loop;
3526
3527       if Nkind (N) = N_Function_Call then
3528          Get_First_Interp (Nam, X, It);
3529          while Present (It.Nam) loop
3530             if Ekind (It.Nam) = E_Function
3531               or else Ekind (It.Nam) = E_Operator
3532             then
3533                return;
3534             else
3535                Get_Next_Interp (X, It);
3536             end if;
3537          end loop;
3538
3539          --  If all interpretations are procedures, this deserves a
3540          --  more precise message. Ditto if this appears as the prefix
3541          --  of a selected component, which may be a lexical error.
3542
3543          Error_Msg_N
3544            ("\context requires function call, found procedure name", Nam);
3545
3546          if Nkind (Parent (N)) = N_Selected_Component
3547            and then N = Prefix (Parent (N))
3548          then
3549             Error_Msg_N (
3550               "\period should probably be semicolon", Parent (N));
3551          end if;
3552
3553       elsif Nkind (N) = N_Procedure_Call_Statement
3554         and then not Void_Interp_Seen
3555       then
3556          Error_Msg_N (
3557          "\function name found in procedure call", Nam);
3558       end if;
3559
3560       All_Errors_Mode := Err_Mode;
3561    end Diagnose_Call;
3562
3563    ---------------------------
3564    -- Find_Arithmetic_Types --
3565    ---------------------------
3566
3567    procedure Find_Arithmetic_Types
3568      (L, R  : Node_Id;
3569       Op_Id : Entity_Id;
3570       N     : Node_Id)
3571    is
3572       Index1 : Interp_Index;
3573       Index2 : Interp_Index;
3574       It1    : Interp;
3575       It2    : Interp;
3576
3577       procedure Check_Right_Argument (T : Entity_Id);
3578       --  Check right operand of operator
3579
3580       --------------------------
3581       -- Check_Right_Argument --
3582       --------------------------
3583
3584       procedure Check_Right_Argument (T : Entity_Id) is
3585       begin
3586          if not Is_Overloaded (R) then
3587             Check_Arithmetic_Pair (T, Etype (R), Op_Id,  N);
3588          else
3589             Get_First_Interp (R, Index2, It2);
3590             while Present (It2.Typ) loop
3591                Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
3592                Get_Next_Interp (Index2, It2);
3593             end loop;
3594          end if;
3595       end Check_Right_Argument;
3596
3597    --  Start processing for Find_Arithmetic_Types
3598
3599    begin
3600       if not Is_Overloaded (L) then
3601          Check_Right_Argument (Etype (L));
3602
3603       else
3604          Get_First_Interp (L, Index1, It1);
3605
3606          while Present (It1.Typ) loop
3607             Check_Right_Argument (It1.Typ);
3608             Get_Next_Interp (Index1, It1);
3609          end loop;
3610       end if;
3611
3612    end Find_Arithmetic_Types;
3613
3614    ------------------------
3615    -- Find_Boolean_Types --
3616    ------------------------
3617
3618    procedure Find_Boolean_Types
3619      (L, R  : Node_Id;
3620       Op_Id : Entity_Id;
3621       N     : Node_Id)
3622    is
3623       Index : Interp_Index;
3624       It    : Interp;
3625
3626       procedure Check_Numeric_Argument (T : Entity_Id);
3627       --  Special case for logical operations one of whose operands is an
3628       --  integer literal. If both are literal the result is any modular type.
3629
3630       ----------------------------
3631       -- Check_Numeric_Argument --
3632       ----------------------------
3633
3634       procedure Check_Numeric_Argument (T : Entity_Id) is
3635       begin
3636          if T = Universal_Integer then
3637             Add_One_Interp (N, Op_Id, Any_Modular);
3638
3639          elsif Is_Modular_Integer_Type (T) then
3640             Add_One_Interp (N, Op_Id, T);
3641          end if;
3642       end Check_Numeric_Argument;
3643
3644    --  Start of processing for Find_Boolean_Types
3645
3646    begin
3647       if not Is_Overloaded (L) then
3648          if Etype (L) = Universal_Integer
3649            or else Etype (L) = Any_Modular
3650          then
3651             if not Is_Overloaded (R) then
3652                Check_Numeric_Argument (Etype (R));
3653
3654             else
3655                Get_First_Interp (R, Index, It);
3656                while Present (It.Typ) loop
3657                   Check_Numeric_Argument (It.Typ);
3658                   Get_Next_Interp (Index, It);
3659                end loop;
3660             end if;
3661
3662          elsif Valid_Boolean_Arg (Etype (L))
3663            and then Has_Compatible_Type (R, Etype (L))
3664          then
3665             Add_One_Interp (N, Op_Id, Etype (L));
3666          end if;
3667
3668       else
3669          Get_First_Interp (L, Index, It);
3670          while Present (It.Typ) loop
3671             if Valid_Boolean_Arg (It.Typ)
3672               and then Has_Compatible_Type (R, It.Typ)
3673             then
3674                Add_One_Interp (N, Op_Id, It.Typ);
3675             end if;
3676
3677             Get_Next_Interp (Index, It);
3678          end loop;
3679       end if;
3680    end Find_Boolean_Types;
3681
3682    ---------------------------
3683    -- Find_Comparison_Types --
3684    ---------------------------
3685
3686    procedure Find_Comparison_Types
3687      (L, R  : Node_Id;
3688       Op_Id : Entity_Id;
3689       N     : Node_Id)
3690    is
3691       Index : Interp_Index;
3692       It    : Interp;
3693       Found : Boolean := False;
3694       I_F   : Interp_Index;
3695       T_F   : Entity_Id;
3696       Scop  : Entity_Id := Empty;
3697
3698       procedure Try_One_Interp (T1 : Entity_Id);
3699       --  Routine to try one proposed interpretation. Note that the context
3700       --  of the operator plays no role in resolving the arguments, so that
3701       --  if there is more than one interpretation of the operands that is
3702       --  compatible with comparison, the operation is ambiguous.
3703
3704       --------------------
3705       -- Try_One_Interp --
3706       --------------------
3707
3708       procedure Try_One_Interp (T1 : Entity_Id) is
3709       begin
3710
3711          --  If the operator is an expanded name, then the type of the operand
3712          --  must be defined in the corresponding scope. If the type is
3713          --  universal, the context will impose the correct type.
3714
3715          if Present (Scop)
3716             and then not Defined_In_Scope (T1, Scop)
3717             and then T1 /= Universal_Integer
3718             and then T1 /= Universal_Real
3719             and then T1 /= Any_String
3720             and then T1 /= Any_Composite
3721          then
3722             return;
3723          end if;
3724
3725          if Valid_Comparison_Arg (T1)
3726            and then Has_Compatible_Type (R, T1)
3727          then
3728             if Found
3729               and then Base_Type (T1) /= Base_Type (T_F)
3730             then
3731                It := Disambiguate (L, I_F, Index, Any_Type);
3732
3733                if It = No_Interp then
3734                   Ambiguous_Operands (N);
3735                   Set_Etype (L, Any_Type);
3736                   return;
3737
3738                else
3739                   T_F := It.Typ;
3740                end if;
3741
3742             else
3743                Found := True;
3744                T_F   := T1;
3745                I_F   := Index;
3746             end if;
3747
3748             Set_Etype (L, T_F);
3749             Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3750
3751          end if;
3752       end Try_One_Interp;
3753
3754    --  Start processing for Find_Comparison_Types
3755
3756    begin
3757       --  If left operand is aggregate, the right operand has to
3758       --  provide a usable type for it.
3759
3760       if Nkind (L) = N_Aggregate
3761         and then Nkind (R) /= N_Aggregate
3762       then
3763          Find_Comparison_Types (R, L, Op_Id, N);
3764          return;
3765       end if;
3766
3767       if Nkind (N) = N_Function_Call
3768          and then Nkind (Name (N)) = N_Expanded_Name
3769       then
3770          Scop := Entity (Prefix (Name (N)));
3771
3772          --  The prefix may be a package renaming, and the subsequent test
3773          --  requires the original package.
3774
3775          if Ekind (Scop) = E_Package
3776            and then Present (Renamed_Entity (Scop))
3777          then
3778             Scop := Renamed_Entity (Scop);
3779             Set_Entity (Prefix (Name (N)), Scop);
3780          end if;
3781       end if;
3782
3783       if not Is_Overloaded (L) then
3784          Try_One_Interp (Etype (L));
3785
3786       else
3787          Get_First_Interp (L, Index, It);
3788          while Present (It.Typ) loop
3789             Try_One_Interp (It.Typ);
3790             Get_Next_Interp (Index, It);
3791          end loop;
3792       end if;
3793    end Find_Comparison_Types;
3794
3795    ----------------------------------------
3796    -- Find_Non_Universal_Interpretations --
3797    ----------------------------------------
3798
3799    procedure Find_Non_Universal_Interpretations
3800      (N     : Node_Id;
3801       R     : Node_Id;
3802       Op_Id : Entity_Id;
3803       T1    : Entity_Id)
3804    is
3805       Index : Interp_Index;
3806       It    : Interp;
3807
3808    begin
3809       if T1 = Universal_Integer
3810         or else T1 = Universal_Real
3811       then
3812          if not Is_Overloaded (R) then
3813             Add_One_Interp
3814               (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
3815          else
3816             Get_First_Interp (R, Index, It);
3817             while Present (It.Typ) loop
3818                if Covers (It.Typ, T1) then
3819                   Add_One_Interp
3820                     (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
3821                end if;
3822
3823                Get_Next_Interp (Index, It);
3824             end loop;
3825          end if;
3826       else
3827          Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
3828       end if;
3829    end Find_Non_Universal_Interpretations;
3830
3831    ------------------------------
3832    -- Find_Concatenation_Types --
3833    ------------------------------
3834
3835    procedure Find_Concatenation_Types
3836      (L, R  : Node_Id;
3837       Op_Id : Entity_Id;
3838       N     : Node_Id)
3839    is
3840       Op_Type : constant Entity_Id := Etype (Op_Id);
3841
3842    begin
3843       if Is_Array_Type (Op_Type)
3844         and then not Is_Limited_Type (Op_Type)
3845
3846         and then (Has_Compatible_Type (L, Op_Type)
3847                     or else
3848                   Has_Compatible_Type (L, Component_Type (Op_Type)))
3849
3850         and then (Has_Compatible_Type (R, Op_Type)
3851                     or else
3852                   Has_Compatible_Type (R, Component_Type (Op_Type)))
3853       then
3854          Add_One_Interp (N, Op_Id, Op_Type);
3855       end if;
3856    end Find_Concatenation_Types;
3857
3858    -------------------------
3859    -- Find_Equality_Types --
3860    -------------------------
3861
3862    procedure Find_Equality_Types
3863      (L, R  : Node_Id;
3864       Op_Id : Entity_Id;
3865       N     : Node_Id)
3866    is
3867       Index : Interp_Index;
3868       It    : Interp;
3869       Found : Boolean := False;
3870       I_F   : Interp_Index;
3871       T_F   : Entity_Id;
3872       Scop  : Entity_Id := Empty;
3873
3874       procedure Try_One_Interp (T1 : Entity_Id);
3875       --  The context of the operator plays no role in resolving the
3876       --  arguments,  so that if there is more than one interpretation
3877       --  of the operands that is compatible with equality, the construct
3878       --  is ambiguous and an error can be emitted now, after trying to
3879       --  disambiguate, i.e. applying preference rules.
3880
3881       --------------------
3882       -- Try_One_Interp --
3883       --------------------
3884
3885       procedure Try_One_Interp (T1 : Entity_Id) is
3886       begin
3887          --  If the operator is an expanded name, then the type of the operand
3888          --  must be defined in the corresponding scope. If the type is
3889          --  universal, the context will impose the correct type. An anonymous
3890          --  type for a 'Access reference is also universal in this sense, as
3891          --  the actual type is obtained from context.
3892
3893          if Present (Scop)
3894             and then not Defined_In_Scope (T1, Scop)
3895             and then T1 /= Universal_Integer
3896             and then T1 /= Universal_Real
3897             and then T1 /= Any_Access
3898             and then T1 /= Any_String
3899             and then T1 /= Any_Composite
3900             and then (Ekind (T1) /= E_Access_Subprogram_Type
3901                         or else Comes_From_Source (T1))
3902          then
3903             return;
3904          end if;
3905
3906          --  Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
3907          --  Do not allow anonymous access types in equality operators.
3908
3909          if Ada_Version < Ada_05
3910            and then Ekind (T1) = E_Anonymous_Access_Type
3911          then
3912             return;
3913          end if;
3914
3915          if T1 /= Standard_Void_Type
3916            and then not Is_Limited_Type (T1)
3917            and then not Is_Limited_Composite (T1)
3918            and then Has_Compatible_Type (R, T1)
3919          then
3920             if Found
3921               and then Base_Type (T1) /= Base_Type (T_F)
3922             then
3923                It := Disambiguate (L, I_F, Index, Any_Type);
3924
3925                if It = No_Interp then
3926                   Ambiguous_Operands (N);
3927                   Set_Etype (L, Any_Type);
3928                   return;
3929
3930                else
3931                   T_F := It.Typ;
3932                end if;
3933
3934             else
3935                Found := True;
3936                T_F   := T1;
3937                I_F   := Index;
3938             end if;
3939
3940             if not Analyzed (L) then
3941                Set_Etype (L, T_F);
3942             end if;
3943
3944             Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
3945
3946             if Etype (N) = Any_Type then
3947
3948                --  Operator was not visible.
3949
3950                Found := False;
3951             end if;
3952          end if;
3953       end Try_One_Interp;
3954
3955    --  Start of processing for Find_Equality_Types
3956
3957    begin
3958       --  If left operand is aggregate, the right operand has to
3959       --  provide a usable type for it.
3960
3961       if Nkind (L) = N_Aggregate
3962         and then Nkind (R) /= N_Aggregate
3963       then
3964          Find_Equality_Types (R, L, Op_Id, N);
3965          return;
3966       end if;
3967
3968       if Nkind (N) = N_Function_Call
3969          and then Nkind (Name (N)) = N_Expanded_Name
3970       then
3971          Scop := Entity (Prefix (Name (N)));
3972
3973          --  The prefix may be a package renaming, and the subsequent test
3974          --  requires the original package.
3975
3976          if Ekind (Scop) = E_Package
3977            and then Present (Renamed_Entity (Scop))
3978          then
3979             Scop := Renamed_Entity (Scop);
3980             Set_Entity (Prefix (Name (N)), Scop);
3981          end if;
3982       end if;
3983
3984       if not Is_Overloaded (L) then
3985          Try_One_Interp (Etype (L));
3986
3987       else
3988          Get_First_Interp (L, Index, It);
3989          while Present (It.Typ) loop
3990             Try_One_Interp (It.Typ);
3991             Get_Next_Interp (Index, It);
3992          end loop;
3993       end if;
3994    end Find_Equality_Types;
3995
3996    -------------------------
3997    -- Find_Negation_Types --
3998    -------------------------
3999
4000    procedure Find_Negation_Types
4001      (R     : Node_Id;
4002       Op_Id : Entity_Id;
4003       N     : Node_Id)
4004    is
4005       Index : Interp_Index;
4006       It    : Interp;
4007
4008    begin
4009       if not Is_Overloaded (R) then
4010          if Etype (R) = Universal_Integer then
4011             Add_One_Interp (N, Op_Id, Any_Modular);
4012          elsif Valid_Boolean_Arg (Etype (R)) then
4013             Add_One_Interp (N, Op_Id, Etype (R));
4014          end if;
4015
4016       else
4017          Get_First_Interp (R, Index, It);
4018          while Present (It.Typ) loop
4019             if Valid_Boolean_Arg (It.Typ) then
4020                Add_One_Interp (N, Op_Id, It.Typ);
4021             end if;
4022
4023             Get_Next_Interp (Index, It);
4024          end loop;
4025       end if;
4026    end Find_Negation_Types;
4027
4028    ----------------------
4029    -- Find_Unary_Types --
4030    ----------------------
4031
4032    procedure Find_Unary_Types
4033      (R     : Node_Id;
4034       Op_Id : Entity_Id;
4035       N     : Node_Id)
4036    is
4037       Index : Interp_Index;
4038       It    : Interp;
4039
4040    begin
4041       if not Is_Overloaded (R) then
4042          if Is_Numeric_Type (Etype (R)) then
4043             Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
4044          end if;
4045
4046       else
4047          Get_First_Interp (R, Index, It);
4048          while Present (It.Typ) loop
4049             if Is_Numeric_Type (It.Typ) then
4050                Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
4051             end if;
4052
4053             Get_Next_Interp (Index, It);
4054          end loop;
4055       end if;
4056    end Find_Unary_Types;
4057
4058    ------------------
4059    -- Junk_Operand --
4060    ------------------
4061
4062    function Junk_Operand (N : Node_Id) return Boolean is
4063       Enode : Node_Id;
4064
4065    begin
4066       if Error_Posted (N) then
4067          return False;
4068       end if;
4069
4070       --  Get entity to be tested
4071
4072       if Is_Entity_Name (N)
4073         and then Present (Entity (N))
4074       then
4075          Enode := N;
4076
4077       --  An odd case, a procedure name gets converted to a very peculiar
4078       --  function call, and here is where we detect this happening.
4079
4080       elsif Nkind (N) = N_Function_Call
4081         and then Is_Entity_Name (Name (N))
4082         and then Present (Entity (Name (N)))
4083       then
4084          Enode := Name (N);
4085
4086       --  Another odd case, there are at least some cases of selected
4087       --  components where the selected component is not marked as having
4088       --  an entity, even though the selector does have an entity
4089
4090       elsif Nkind (N) = N_Selected_Component
4091         and then Present (Entity (Selector_Name (N)))
4092       then
4093          Enode := Selector_Name (N);
4094
4095       else
4096          return False;
4097       end if;
4098
4099       --  Now test the entity we got to see if it a bad case
4100
4101       case Ekind (Entity (Enode)) is
4102
4103          when E_Package =>
4104             Error_Msg_N
4105               ("package name cannot be used as operand", Enode);
4106
4107          when Generic_Unit_Kind =>
4108             Error_Msg_N
4109               ("generic unit name cannot be used as operand", Enode);
4110
4111          when Type_Kind =>
4112             Error_Msg_N
4113               ("subtype name cannot be used as operand", Enode);
4114
4115          when Entry_Kind =>
4116             Error_Msg_N
4117               ("entry name cannot be used as operand", Enode);
4118
4119          when E_Procedure =>
4120             Error_Msg_N
4121               ("procedure name cannot be used as operand", Enode);
4122
4123          when E_Exception =>
4124             Error_Msg_N
4125               ("exception name cannot be used as operand", Enode);
4126
4127          when E_Block | E_Label | E_Loop =>
4128             Error_Msg_N
4129               ("label name cannot be used as operand", Enode);
4130
4131          when others =>
4132             return False;
4133
4134       end case;
4135
4136       return True;
4137    end Junk_Operand;
4138
4139    --------------------
4140    -- Operator_Check --
4141    --------------------
4142
4143    procedure Operator_Check (N : Node_Id) is
4144    begin
4145       Remove_Abstract_Operations (N);
4146
4147       --  Test for case of no interpretation found for operator
4148
4149       if Etype (N) = Any_Type then
4150          declare
4151             L : Node_Id;
4152             R : Node_Id;
4153
4154          begin
4155             R := Right_Opnd (N);
4156
4157             if Nkind (N) in N_Binary_Op then
4158                L := Left_Opnd (N);
4159             else
4160                L := Empty;
4161             end if;
4162
4163             --  If either operand has no type, then don't complain further,
4164             --  since this simply means that we have a propragated error.
4165
4166             if R = Error
4167               or else Etype (R) = Any_Type
4168               or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
4169             then
4170                return;
4171
4172             --  We explicitly check for the case of concatenation of component
4173             --  with component to avoid reporting spurious matching array types
4174             --  that might happen to be lurking in distant packages (such as
4175             --  run-time packages). This also prevents inconsistencies in the
4176             --  messages for certain ACVC B tests, which can vary depending on
4177             --  types declared in run-time interfaces. Another improvement when
4178             --  aggregates are present is to look for a well-typed operand.
4179
4180             elsif Present (Candidate_Type)
4181               and then (Nkind (N) /= N_Op_Concat
4182                          or else Is_Array_Type (Etype (L))
4183                          or else Is_Array_Type (Etype (R)))
4184             then
4185
4186                if Nkind (N) = N_Op_Concat then
4187                   if Etype (L) /= Any_Composite
4188                     and then Is_Array_Type (Etype (L))
4189                   then
4190                      Candidate_Type := Etype (L);
4191
4192                   elsif Etype (R) /= Any_Composite
4193                     and then Is_Array_Type (Etype (R))
4194                   then
4195                      Candidate_Type := Etype (R);
4196                   end if;
4197                end if;
4198
4199                Error_Msg_NE
4200                  ("operator for} is not directly visible!",
4201                   N, First_Subtype (Candidate_Type));
4202                Error_Msg_N ("use clause would make operation legal!",  N);
4203                return;
4204
4205             --  If either operand is a junk operand (e.g. package name), then
4206             --  post appropriate error messages, but do not complain further.
4207
4208             --  Note that the use of OR in this test instead of OR ELSE
4209             --  is quite deliberate, we may as well check both operands
4210             --  in the binary operator case.
4211
4212             elsif Junk_Operand (R)
4213               or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
4214             then
4215                return;
4216
4217             --  If we have a logical operator, one of whose operands is
4218             --  Boolean, then we know that the other operand cannot resolve
4219             --  to Boolean (since we got no interpretations), but in that
4220             --  case we pretty much know that the other operand should be
4221             --  Boolean, so resolve it that way (generating an error)
4222
4223             elsif Nkind (N) = N_Op_And
4224                     or else
4225                   Nkind (N) = N_Op_Or
4226                     or else
4227                   Nkind (N) = N_Op_Xor
4228             then
4229                if Etype (L) = Standard_Boolean then
4230                   Resolve (R, Standard_Boolean);
4231                   return;
4232                elsif Etype (R) = Standard_Boolean then
4233                   Resolve (L, Standard_Boolean);
4234                   return;
4235                end if;
4236
4237             --  For an arithmetic operator or comparison operator, if one
4238             --  of the operands is numeric, then we know the other operand
4239             --  is not the same numeric type. If it is a non-numeric type,
4240             --  then probably it is intended to match the other operand.
4241
4242             elsif Nkind (N) = N_Op_Add      or else
4243                   Nkind (N) = N_Op_Divide   or else
4244                   Nkind (N) = N_Op_Ge       or else
4245                   Nkind (N) = N_Op_Gt       or else
4246                   Nkind (N) = N_Op_Le       or else
4247                   Nkind (N) = N_Op_Lt       or else
4248                   Nkind (N) = N_Op_Mod      or else
4249                   Nkind (N) = N_Op_Multiply or else
4250                   Nkind (N) = N_Op_Rem      or else
4251                   Nkind (N) = N_Op_Subtract
4252             then
4253                if Is_Numeric_Type (Etype (L))
4254                  and then not Is_Numeric_Type (Etype (R))
4255                then
4256                   Resolve (R, Etype (L));
4257                   return;
4258
4259                elsif Is_Numeric_Type (Etype (R))
4260                  and then not Is_Numeric_Type (Etype (L))
4261                then
4262                   Resolve (L, Etype (R));
4263                   return;
4264                end if;
4265
4266             --  Comparisons on A'Access are common enough to deserve a
4267             --  special message.
4268
4269             elsif (Nkind (N) = N_Op_Eq  or else
4270                    Nkind (N) = N_Op_Ne)
4271                and then Ekind (Etype (L)) = E_Access_Attribute_Type
4272                and then Ekind (Etype (R)) = E_Access_Attribute_Type
4273             then
4274                Error_Msg_N
4275                  ("two access attributes cannot be compared directly", N);
4276                Error_Msg_N
4277                  ("\they must be converted to an explicit type for comparison",
4278                    N);
4279                return;
4280
4281             --  Another one for C programmers
4282
4283             elsif Nkind (N) = N_Op_Concat
4284               and then Valid_Boolean_Arg (Etype (L))
4285               and then Valid_Boolean_Arg (Etype (R))
4286             then
4287                Error_Msg_N ("invalid operands for concatenation", N);
4288                Error_Msg_N ("\maybe AND was meant", N);
4289                return;
4290
4291             --  A special case for comparison of access parameter with null
4292
4293             elsif Nkind (N) = N_Op_Eq
4294               and then Is_Entity_Name (L)
4295               and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
4296               and then Nkind (Parameter_Type (Parent (Entity (L)))) =
4297                                                   N_Access_Definition
4298               and then Nkind (R) = N_Null
4299             then
4300                Error_Msg_N ("access parameter is not allowed to be null", L);
4301                Error_Msg_N ("\(call would raise Constraint_Error)", L);
4302                return;
4303             end if;
4304
4305             --  If we fall through then just give general message. Note
4306             --  that in the following messages, if the operand is overloaded
4307             --  we choose an arbitrary type to complain about, but that is
4308             --  probably more useful than not giving a type at all.
4309
4310             if Nkind (N) in N_Unary_Op then
4311                Error_Msg_Node_2 := Etype (R);
4312                Error_Msg_N ("operator& not defined for}", N);
4313                return;
4314
4315             else
4316                if Nkind (N) in N_Binary_Op then
4317                   if not Is_Overloaded (L)
4318                     and then not Is_Overloaded (R)
4319                     and then Base_Type (Etype (L)) = Base_Type (Etype (R))
4320                   then
4321                      Error_Msg_Node_2 := Etype (R);
4322                      Error_Msg_N ("there is no applicable operator& for}", N);
4323
4324                   else
4325                      Error_Msg_N ("invalid operand types for operator&", N);
4326
4327                      if Nkind (N) /= N_Op_Concat then
4328                         Error_Msg_NE ("\left operand has}!",  N, Etype (L));
4329                         Error_Msg_NE ("\right operand has}!", N, Etype (R));
4330                      end if;
4331                   end if;
4332                end if;
4333             end if;
4334          end;
4335       end if;
4336    end Operator_Check;
4337
4338    --------------------------------
4339    -- Remove_Abstract_Operations --
4340    --------------------------------
4341
4342    procedure Remove_Abstract_Operations (N : Node_Id) is
4343       I            : Interp_Index;
4344       It           : Interp;
4345       Abstract_Op  : Entity_Id := Empty;
4346
4347       --  AI-310: If overloaded, remove abstract non-dispatching
4348       --  operations. We activate this if either extensions are
4349       --  enabled, or if the abstract operation in question comes
4350       --  from a predefined file. This latter test allows us to
4351       --  use abstract to make operations invisible to users. In
4352       --  particular, if type Address is non-private and abstract
4353       --  subprograms are used to hide its operators, they will be
4354       --  truly hidden.
4355
4356       type Operand_Position is (First_Op, Second_Op);
4357       Univ_Type : constant Entity_Id := Universal_Interpretation (N);
4358
4359       procedure Remove_Address_Interpretations (Op : Operand_Position);
4360       --  Ambiguities may arise when the operands are literal and the
4361       --  address operations in s-auxdec are visible. In that case, remove
4362       --  the interpretation of a literal as Address, to retain the semantics
4363       --  of Address as a private type.
4364
4365       ------------------------------------
4366       -- Remove_Address_Interpretations --
4367       ------------------------------------
4368
4369       procedure Remove_Address_Interpretations (Op : Operand_Position) is
4370          Formal : Entity_Id;
4371
4372       begin
4373          if Is_Overloaded (N) then
4374             Get_First_Interp (N, I, It);
4375             while Present (It.Nam) loop
4376                Formal := First_Entity (It.Nam);
4377
4378                if Op = Second_Op then
4379                   Formal := Next_Entity (Formal);
4380                end if;
4381
4382                if Is_Descendent_Of_Address (Etype (Formal)) then
4383                   Remove_Interp (I);
4384                end if;
4385
4386                Get_Next_Interp (I, It);
4387             end loop;
4388          end if;
4389       end Remove_Address_Interpretations;
4390
4391    --  Start of processing for Remove_Abstract_Operations
4392
4393    begin
4394       if Is_Overloaded (N) then
4395          Get_First_Interp (N, I, It);
4396
4397          while Present (It.Nam) loop
4398             if not Is_Type (It.Nam)
4399               and then Is_Abstract (It.Nam)
4400               and then not Is_Dispatching_Operation (It.Nam)
4401               and then
4402                 (Ada_Version >= Ada_05
4403                    or else Is_Predefined_File_Name
4404                              (Unit_File_Name (Get_Source_Unit (It.Nam))))
4405
4406             then
4407                Abstract_Op := It.Nam;
4408                Remove_Interp (I);
4409                exit;
4410             end if;
4411
4412             Get_Next_Interp (I, It);
4413          end loop;
4414
4415          if No (Abstract_Op) then
4416             return;
4417
4418          elsif Nkind (N) in N_Op then
4419
4420             --  Remove interpretations that treat literals as addresses.
4421             --  This is never appropriate.
4422
4423             if Nkind (N) in N_Binary_Op then
4424                declare
4425                   U1 : constant Boolean :=
4426                      Present (Universal_Interpretation (Right_Opnd (N)));
4427                   U2 : constant Boolean :=
4428                      Present (Universal_Interpretation (Left_Opnd (N)));
4429
4430                begin
4431                   if U1 and then not U2 then
4432                      Remove_Address_Interpretations (Second_Op);
4433
4434                   elsif U2 and then not U1 then
4435                      Remove_Address_Interpretations (First_Op);
4436                   end if;
4437
4438                   if not (U1 and U2) then
4439
4440                      --  Remove corresponding predefined operator, which is
4441                      --  always added to the overload set.
4442
4443                      Get_First_Interp (N, I, It);
4444                      while Present (It.Nam) loop
4445                         if Scope (It.Nam) = Standard_Standard
4446                           and then Base_Type (It.Typ) =
4447                                    Base_Type (Etype (Abstract_Op))
4448                         then
4449                            Remove_Interp (I);
4450                         end if;
4451
4452                         Get_Next_Interp (I, It);
4453                      end loop;
4454
4455                   elsif Is_Overloaded (N)
4456                     and then Present (Univ_Type)
4457                   then
4458                      --  If both operands have a universal interpretation,
4459                      --  select the predefined operator and discard others.
4460
4461                      Get_First_Interp (N, I, It);
4462
4463                      while Present (It.Nam) loop
4464                         if Scope (It.Nam) = Standard_Standard then
4465                            Set_Etype (N, Univ_Type);
4466                            Set_Entity (N, It.Nam);
4467                            Set_Is_Overloaded (N, False);
4468                            exit;
4469                         end if;
4470
4471                         Get_Next_Interp (I, It);
4472                      end loop;
4473                   end if;
4474                end;
4475             end if;
4476
4477          elsif Nkind (N) = N_Function_Call
4478            and then
4479              (Nkind (Name (N)) = N_Operator_Symbol
4480                 or else
4481                   (Nkind (Name (N)) = N_Expanded_Name
4482                      and then
4483                        Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
4484          then
4485
4486             declare
4487                Arg1 : constant Node_Id := First (Parameter_Associations (N));
4488                U1   : constant Boolean :=
4489                         Present (Universal_Interpretation (Arg1));
4490                U2   : constant Boolean :=
4491                         Present (Next (Arg1)) and then
4492                         Present (Universal_Interpretation (Next (Arg1)));
4493
4494             begin
4495                if U1 and then not U2 then
4496                   Remove_Address_Interpretations (First_Op);
4497
4498                elsif U2 and then not U1 then
4499                   Remove_Address_Interpretations (Second_Op);
4500                end if;
4501
4502                if not (U1 and U2) then
4503                   Get_First_Interp (N, I, It);
4504                   while Present (It.Nam) loop
4505                      if Scope (It.Nam) = Standard_Standard
4506                        and then It.Typ = Base_Type (Etype (Abstract_Op))
4507                      then
4508                         Remove_Interp (I);
4509                      end if;
4510
4511                      Get_Next_Interp (I, It);
4512                   end loop;
4513                end if;
4514             end;
4515          end if;
4516
4517          --  If the removal has left no valid interpretations, emit
4518          --  error message now and label node as illegal.
4519
4520          if Present (Abstract_Op) then
4521             Get_First_Interp (N, I, It);
4522
4523             if No (It.Nam) then
4524
4525                --  Removal of abstract operation left no viable candidate.
4526
4527                Set_Etype (N, Any_Type);
4528                Error_Msg_Sloc := Sloc (Abstract_Op);
4529                Error_Msg_NE
4530                  ("cannot call abstract operation& declared#", N, Abstract_Op);
4531             end if;
4532          end if;
4533       end if;
4534    end Remove_Abstract_Operations;
4535
4536    -----------------------
4537    -- Try_Indirect_Call --
4538    -----------------------
4539
4540    function Try_Indirect_Call
4541      (N   : Node_Id;
4542       Nam : Entity_Id;
4543       Typ : Entity_Id) return Boolean
4544    is
4545       Actual  : Node_Id;
4546       Formal  : Entity_Id;
4547       Call_OK : Boolean;
4548
4549    begin
4550       Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
4551       Actual := First_Actual (N);
4552       Formal := First_Formal (Designated_Type (Typ));
4553
4554       while Present (Actual)
4555         and then Present (Formal)
4556       loop
4557          if not Has_Compatible_Type (Actual, Etype (Formal)) then
4558             return False;
4559          end if;
4560
4561          Next (Actual);
4562          Next_Formal (Formal);
4563       end loop;
4564
4565       if No (Actual) and then No (Formal) then
4566          Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
4567
4568          --  Nam is a candidate interpretation for the name in the call,
4569          --  if it is not an indirect call.
4570
4571          if not Is_Type (Nam)
4572             and then Is_Entity_Name (Name (N))
4573          then
4574             Set_Entity (Name (N), Nam);
4575          end if;
4576
4577          return True;
4578       else
4579          return False;
4580       end if;
4581    end Try_Indirect_Call;
4582
4583    ----------------------
4584    -- Try_Indexed_Call --
4585    ----------------------
4586
4587    function Try_Indexed_Call
4588      (N   : Node_Id;
4589       Nam : Entity_Id;
4590       Typ : Entity_Id) return Boolean
4591    is
4592       Actuals : constant List_Id   := Parameter_Associations (N);
4593       Actual : Node_Id;
4594       Index  : Entity_Id;
4595
4596    begin
4597       Actual := First (Actuals);
4598       Index := First_Index (Typ);
4599       while Present (Actual)
4600         and then Present (Index)
4601       loop
4602          --  If the parameter list has a named association, the expression
4603          --  is definitely a call and not an indexed component.
4604
4605          if Nkind (Actual) = N_Parameter_Association then
4606             return False;
4607          end if;
4608
4609          if not Has_Compatible_Type (Actual, Etype (Index)) then
4610             return False;
4611          end if;
4612
4613          Next (Actual);
4614          Next_Index (Index);
4615       end loop;
4616
4617       if No (Actual) and then No (Index) then
4618          Add_One_Interp (N, Nam, Component_Type (Typ));
4619
4620          --  Nam is a candidate interpretation for the name in the call,
4621          --  if it is not an indirect call.
4622
4623          if not Is_Type (Nam)
4624             and then Is_Entity_Name (Name (N))
4625          then
4626             Set_Entity (Name (N), Nam);
4627          end if;
4628
4629          return True;
4630       else
4631          return False;
4632       end if;
4633    end Try_Indexed_Call;
4634
4635    --------------------------
4636    -- Try_Object_Operation --
4637    --------------------------
4638
4639    function Try_Object_Operation (N : Node_Id) return Boolean is
4640       K               : constant Node_Kind  := Nkind (Parent (N));
4641       Loc             : constant Source_Ptr := Sloc (N);
4642       Is_Subprg_Call  : constant Boolean    := K = N_Procedure_Call_Statement
4643                                                 or else K = N_Function_Call;
4644       Obj             : constant Node_Id    := Prefix (N);
4645       Subprog         : constant Node_Id    := Selector_Name (N);
4646
4647       Actual          : Node_Id;
4648       Call_Node       : Node_Id;
4649       Call_Node_Case  : Node_Id := Empty;
4650       First_Actual    : Node_Id;
4651       Node_To_Replace : Node_Id;
4652       Obj_Type        : Entity_Id := Etype (Obj);
4653
4654       procedure Complete_Object_Operation
4655         (Call_Node       : Node_Id;
4656          Node_To_Replace : Node_Id;
4657          Subprog         : Node_Id);
4658       --  Set Subprog as the name of Call_Node, replace Node_To_Replace with
4659       --  Call_Node and reanalyze Node_To_Replace.
4660
4661       procedure Transform_Object_Operation
4662         (Call_Node       : out Node_Id;
4663          First_Actual    : Node_Id;
4664          Node_To_Replace : out Node_Id;
4665          Subprog         : Node_Id);
4666       --  Transform Object.Operation (...) to Operation (Object, ...)
4667       --  Call_Node is the resulting subprogram call node, First_Actual is
4668       --  either the object Obj or an explicit dereference of Obj in certain
4669       --  cases, Node_To_Replace is either N or the parent of N, and Subprog
4670       --  is the subprogram we are trying to match.
4671
4672       function Try_Class_Wide_Operation
4673         (Call_Node       : Node_Id;
4674          Node_To_Replace : Node_Id) return Boolean;
4675       --  Traverse all the ancestor types looking for a class-wide subprogram
4676       --  that matches Subprog.
4677
4678       function Try_Primitive_Operation
4679         (Call_Node       : Node_Id;
4680          Node_To_Replace : Node_Id) return Boolean;
4681       --  Traverse the list of primitive subprograms looking for a subprogram
4682       --  than matches Subprog.
4683
4684       -------------------------------
4685       -- Complete_Object_Operation --
4686       -------------------------------
4687
4688       procedure Complete_Object_Operation
4689         (Call_Node       : Node_Id;
4690          Node_To_Replace : Node_Id;
4691          Subprog         : Node_Id)
4692       is
4693       begin
4694          Set_Name (Call_Node, New_Copy_Tree (Subprog));
4695          Set_Analyzed (Call_Node, False);
4696          Replace (Node_To_Replace, Call_Node);
4697          Analyze (Node_To_Replace);
4698
4699       end Complete_Object_Operation;
4700
4701       --------------------------------
4702       -- Transform_Object_Operation --
4703       --------------------------------
4704
4705       procedure Transform_Object_Operation
4706         (Call_Node       : out Node_Id;
4707          First_Actual    : Node_Id;
4708          Node_To_Replace : out Node_Id;
4709          Subprog         : Node_Id)
4710       is
4711          Actuals     : List_Id;
4712          Parent_Node : constant Node_Id := Parent (N);
4713
4714       begin
4715          Actuals := New_List (New_Copy_Tree (First_Actual));
4716
4717          if (Nkind (Parent_Node) = N_Function_Call
4718                or else
4719              Nkind (Parent_Node) = N_Procedure_Call_Statement)
4720
4721             --  Avoid recursive calls
4722
4723            and then N /= First (Parameter_Associations (Parent_Node))
4724          then
4725             Node_To_Replace := Parent_Node;
4726
4727             Append_List_To (Actuals,
4728               New_Copy_List (Parameter_Associations (Parent_Node)));
4729
4730             if Nkind (Parent_Node) = N_Procedure_Call_Statement then
4731                Call_Node :=
4732                  Make_Procedure_Call_Statement (Loc,
4733                    Name => New_Copy_Tree (Subprog),
4734                    Parameter_Associations => Actuals);
4735
4736             else
4737                pragma Assert (Nkind (Parent_Node) = N_Function_Call);
4738
4739                Call_Node :=
4740                  Make_Function_Call (Loc,
4741                    Name => New_Copy_Tree (Subprog),
4742                    Parameter_Associations => Actuals);
4743
4744             end if;
4745
4746          --  Parameterless call
4747
4748          else
4749             Node_To_Replace := N;
4750
4751             Call_Node :=
4752                Make_Function_Call (Loc,
4753                  Name => New_Copy_Tree (Subprog),
4754                  Parameter_Associations => Actuals);
4755
4756          end if;
4757       end Transform_Object_Operation;
4758
4759       ------------------------------
4760       -- Try_Class_Wide_Operation --
4761       ------------------------------
4762
4763       function Try_Class_Wide_Operation
4764         (Call_Node       : Node_Id;
4765          Node_To_Replace : Node_Id) return Boolean
4766       is
4767          Anc_Type : Entity_Id;
4768          Dummy    : Node_Id;
4769          Hom      : Entity_Id;
4770          Hom_Ref  : Node_Id;
4771          Success  : Boolean;
4772
4773       begin
4774          --  Loop through ancestor types, traverse their homonym chains and
4775          --  gather all interpretations of the subprogram.
4776
4777          Anc_Type := Obj_Type;
4778          loop
4779             Hom := Current_Entity (Subprog);
4780             while Present (Hom) loop
4781                if (Ekind (Hom) = E_Procedure
4782                      or else
4783                    Ekind (Hom) = E_Function)
4784                  and then Present (First_Formal (Hom))
4785                  and then Etype (First_Formal (Hom)) =
4786                             Class_Wide_Type (Anc_Type)
4787                then
4788                   Hom_Ref := New_Reference_To (Hom, Loc);
4789
4790                   --  When both the type of the object and the type of the
4791                   --  first formal of the primitive operation are tagged
4792                   --  access types, we use a node with the object as first
4793                   --  actual.
4794
4795                   if Is_Access_Type (Etype (Obj))
4796                     and then Ekind (Etype (First_Formal (Hom))) =
4797                                E_Anonymous_Access_Type
4798                   then
4799                      --  Allocate the node only once
4800
4801                      if not Present (Call_Node_Case) then
4802                         Transform_Object_Operation (
4803                           Call_Node       => Call_Node_Case,
4804                           First_Actual    => Obj,
4805                           Node_To_Replace => Dummy,
4806                           Subprog         => Subprog);
4807
4808                         Set_Etype (Call_Node_Case, Any_Type);
4809                         Set_Parent (Call_Node_Case, Parent (Node_To_Replace));
4810                      end if;
4811
4812                      Set_Name (Call_Node_Case, Hom_Ref);
4813
4814                      Analyze_One_Call (
4815                        N       => Call_Node_Case,
4816                        Nam     => Hom,
4817                        Report  => False,
4818                        Success => Success);
4819
4820                      if Success then
4821                         Complete_Object_Operation (
4822                           Call_Node       => Call_Node_Case,
4823                           Node_To_Replace => Node_To_Replace,
4824                           Subprog         => Hom_Ref);
4825
4826                         return True;
4827                      end if;
4828
4829                   --  ??? comment required
4830
4831                   else
4832                      Set_Name (Call_Node, Hom_Ref);
4833
4834                      Analyze_One_Call (
4835                        N       => Call_Node,
4836                        Nam     => Hom,
4837                        Report  => False,
4838                        Success => Success);
4839
4840                      if Success then
4841                         Complete_Object_Operation (
4842                           Call_Node       => Call_Node,
4843                           Node_To_Replace => Node_To_Replace,
4844                           Subprog         => Hom_Ref);
4845
4846                         return True;
4847                      end if;
4848                   end if;
4849                end if;
4850
4851                Hom := Homonym (Hom);
4852             end loop;
4853
4854             --  Climb to ancestor type if there is one
4855
4856             exit when Etype (Anc_Type) = Anc_Type;
4857             Anc_Type := Etype (Anc_Type);
4858          end loop;
4859
4860          return False;
4861       end Try_Class_Wide_Operation;
4862
4863       -----------------------------
4864       -- Try_Primitive_Operation --
4865       -----------------------------
4866
4867       function Try_Primitive_Operation
4868         (Call_Node       : Node_Id;
4869          Node_To_Replace : Node_Id) return Boolean
4870       is
4871          Dummy          : Node_Id;
4872          Elmt           : Elmt_Id;
4873          Prim_Op        : Entity_Id;
4874          Prim_Op_Ref    : Node_Id;
4875          Success        : Boolean;
4876
4877       begin
4878          --  Look for the subprogram in the list of primitive operations.
4879
4880          Elmt := First_Elmt (Primitive_Operations (Obj_Type));
4881          while Present (Elmt) loop
4882             Prim_Op := Node (Elmt);
4883
4884             if Chars (Prim_Op) = Chars (Subprog)
4885               and then Present (First_Formal (Prim_Op))
4886             then
4887                Prim_Op_Ref := New_Reference_To (Prim_Op, Loc);
4888
4889                --  When both the type of the object and the type of the first
4890                --  formal of the primitive operation are tagged access types,
4891                --  we use a node with the object as first actual.
4892
4893                if Is_Access_Type (Etype (Obj))
4894                  and then Ekind (Etype (First_Formal (Prim_Op))) =
4895                             E_Anonymous_Access_Type
4896                then
4897                   --  Allocate the node only once
4898
4899                   if not Present (Call_Node_Case) then
4900                      Transform_Object_Operation (
4901                        Call_Node       => Call_Node_Case,
4902                        First_Actual    => Obj,
4903                        Node_To_Replace => Dummy,
4904                        Subprog         => Subprog);
4905
4906                      Set_Etype (Call_Node_Case, Any_Type);
4907                      Set_Parent (Call_Node_Case, Parent (Node_To_Replace));
4908                   end if;
4909
4910                   Set_Name (Call_Node_Case, Prim_Op_Ref);
4911
4912                   Analyze_One_Call (
4913                     N       => Call_Node_Case,
4914                     Nam     => Prim_Op,
4915                     Report  => False,
4916                     Success => Success);
4917
4918                   if Success then
4919                      Complete_Object_Operation (
4920                        Call_Node       => Call_Node_Case,
4921                        Node_To_Replace => Node_To_Replace,
4922                        Subprog         => Prim_Op_Ref);
4923
4924                      return True;
4925                   end if;
4926
4927                --  Comment required ???
4928
4929                else
4930                   Set_Name (Call_Node, Prim_Op_Ref);
4931
4932                   Analyze_One_Call (
4933                     N       => Call_Node,
4934                     Nam     => Prim_Op,
4935                     Report  => False,
4936                     Success => Success);
4937
4938                   if Success then
4939                      Complete_Object_Operation (
4940                        Call_Node       => Call_Node,
4941                        Node_To_Replace => Node_To_Replace,
4942                        Subprog         => Prim_Op_Ref);
4943
4944                      return True;
4945                   end if;
4946                end if;
4947             end if;
4948
4949             Next_Elmt (Elmt);
4950          end loop;
4951
4952          return False;
4953       end Try_Primitive_Operation;
4954
4955    --  Start of processing for Try_Object_Operation
4956
4957    begin
4958       if Is_Access_Type (Obj_Type) then
4959          Obj_Type := Designated_Type (Obj_Type);
4960       end if;
4961
4962       if Ekind (Obj_Type) = E_Private_Subtype then
4963          Obj_Type := Base_Type (Obj_Type);
4964       end if;
4965
4966       if Is_Class_Wide_Type (Obj_Type) then
4967          Obj_Type := Etype (Class_Wide_Type (Obj_Type));
4968       end if;
4969
4970       --  Analyze the actuals in case of subprogram call
4971
4972       if Is_Subprg_Call and then N = Name (Parent (N)) then
4973          Actual := First (Parameter_Associations (Parent (N)));
4974          while Present (Actual) loop
4975             Analyze (Actual);
4976             Check_Parameterless_Call (Actual);
4977             Next (Actual);
4978          end loop;
4979       end if;
4980
4981       --  If the object is of an Access type, explicit dereference is
4982       --  required.
4983
4984       if Is_Access_Type (Etype (Obj)) then
4985          First_Actual :=
4986            Make_Explicit_Dereference (Sloc (Obj), Obj);
4987          Set_Etype (First_Actual, Obj_Type);
4988       else
4989          First_Actual := Obj;
4990       end if;
4991
4992       --  Build a subprogram call node
4993
4994       Transform_Object_Operation (
4995         Call_Node       => Call_Node,
4996         First_Actual    => First_Actual,
4997         Node_To_Replace => Node_To_Replace,
4998         Subprog         => Subprog);
4999
5000       Set_Etype (Call_Node, Any_Type);
5001       Set_Parent (Call_Node, Parent (Node_To_Replace));
5002
5003       return
5004          Try_Primitive_Operation
5005            (Call_Node       => Call_Node,
5006             Node_To_Replace => Node_To_Replace)
5007         or else
5008          Try_Class_Wide_Operation
5009            (Call_Node       => Call_Node,
5010             Node_To_Replace => Node_To_Replace);
5011    end Try_Object_Operation;
5012
5013 end Sem_Ch4;