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