OSDN Git Service

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