OSDN Git Service

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