OSDN Git Service

2010-06-17 Robert Dewar <dewar@adacore.com>
[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-2009, 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 3,  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 COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 with Atree;    use Atree;
27 with Debug;    use Debug;
28 with Einfo;    use Einfo;
29 with Elists;   use Elists;
30 with Errout;   use Errout;
31 with Exp_Util; use Exp_Util;
32 with Fname;    use Fname;
33 with Itypes;   use Itypes;
34 with Lib;      use Lib;
35 with Lib.Xref; use Lib.Xref;
36 with Namet;    use Namet;
37 with Namet.Sp; use Namet.Sp;
38 with Nlists;   use Nlists;
39 with Nmake;    use Nmake;
40 with Opt;      use Opt;
41 with Output;   use Output;
42 with Restrict; use Restrict;
43 with Rident;   use Rident;
44 with Sem;      use Sem;
45 with Sem_Aux;  use Sem_Aux;
46 with Sem_Cat;  use Sem_Cat;
47 with Sem_Ch3;  use Sem_Ch3;
48 with Sem_Ch6;  use Sem_Ch6;
49 with Sem_Ch8;  use Sem_Ch8;
50 with Sem_SCIL; use Sem_SCIL;
51 with Sem_Disp; use Sem_Disp;
52 with Sem_Dist; use Sem_Dist;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Res;  use Sem_Res;
55 with Sem_Util; use Sem_Util;
56 with Sem_Type; use Sem_Type;
57 with Stand;    use Stand;
58 with Sinfo;    use Sinfo;
59 with Snames;   use Snames;
60 with Tbuild;   use Tbuild;
61
62 package body Sem_Ch4 is
63
64    -----------------------
65    -- Local Subprograms --
66    -----------------------
67
68    procedure Analyze_Concatenation_Rest (N : Node_Id);
69    --  Does the "rest" of the work of Analyze_Concatenation, after the left
70    --  operand has been analyzed. See Analyze_Concatenation for details.
71
72    procedure Analyze_Expression (N : Node_Id);
73    --  For expressions that are not names, this is just a call to analyze.
74    --  If the expression is a name, it may be a call to a parameterless
75    --  function, and if so must be converted into an explicit call node
76    --  and analyzed as such. This deproceduring must be done during the first
77    --  pass of overload resolution, because otherwise a procedure call with
78    --  overloaded actuals may fail to resolve.
79
80    procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id);
81    --  Analyze a call of the form "+"(x, y), etc. The prefix of the call
82    --  is an operator name or an expanded name whose selector is an operator
83    --  name, and one possible interpretation is as a predefined operator.
84
85    procedure Analyze_Overloaded_Selected_Component (N : Node_Id);
86    --  If the prefix of a selected_component is overloaded, the proper
87    --  interpretation that yields a record type with the proper selector
88    --  name must be selected.
89
90    procedure Analyze_User_Defined_Binary_Op (N : Node_Id; Op_Id : Entity_Id);
91    --  Procedure to analyze a user defined binary operator, which is resolved
92    --  like a function, but instead of a list of actuals it is presented
93    --  with the left and right operands of an operator node.
94
95    procedure Analyze_User_Defined_Unary_Op (N : Node_Id; Op_Id : Entity_Id);
96    --  Procedure to analyze a user defined unary operator, which is resolved
97    --  like a function, but instead of a list of actuals, it is presented with
98    --  the operand of the operator node.
99
100    procedure Ambiguous_Operands (N : Node_Id);
101    --  for equality, membership, and comparison operators with overloaded
102    --  arguments, list possible interpretations.
103
104    procedure Analyze_One_Call
105       (N          : Node_Id;
106        Nam        : Entity_Id;
107        Report     : Boolean;
108        Success    : out Boolean;
109        Skip_First : Boolean := False);
110    --  Check one interpretation of an overloaded subprogram name for
111    --  compatibility with the types of the actuals in a call. If there is a
112    --  single interpretation which does not match, post error if Report is
113    --  set to True.
114    --
115    --  Nam is the entity that provides the formals against which the actuals
116    --  are checked. Nam is either the name of a subprogram, or the internal
117    --  subprogram type constructed for an access_to_subprogram. If the actuals
118    --  are compatible with Nam, then Nam is added to the list of candidate
119    --  interpretations for N, and Success is set to True.
120    --
121    --  The flag Skip_First is used when analyzing a call that was rewritten
122    --  from object notation. In this case the first actual may have to receive
123    --  an explicit dereference, depending on the first formal of the operation
124    --  being called. The caller will have verified that the object is legal
125    --  for the call. If the remaining parameters match, the first parameter
126    --  will rewritten as a dereference if needed, prior to completing analysis.
127
128    procedure Check_Misspelled_Selector
129      (Prefix : Entity_Id;
130       Sel    : Node_Id);
131    --  Give possible misspelling diagnostic if Sel is likely to be a mis-
132    --  spelling of one of the selectors of the Prefix. This is called by
133    --  Analyze_Selected_Component after producing an invalid selector error
134    --  message.
135
136    function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean;
137    --  Verify that type T is declared in scope S. Used to find interpretations
138    --  for operators given by expanded names. This is abstracted as a separate
139    --  function to handle extensions to System, where S is System, but T is
140    --  declared in the extension.
141
142    procedure Find_Arithmetic_Types
143      (L, R  : Node_Id;
144       Op_Id : Entity_Id;
145       N     : Node_Id);
146    --  L and R are the operands of an arithmetic operator. Find
147    --  consistent pairs of interpretations for L and R that have a
148    --  numeric type consistent with the semantics of the operator.
149
150    procedure Find_Comparison_Types
151      (L, R  : Node_Id;
152       Op_Id : Entity_Id;
153       N     : Node_Id);
154    --  L and R are operands of a comparison operator. Find consistent
155    --  pairs of interpretations for L and R.
156
157    procedure Find_Concatenation_Types
158      (L, R  : Node_Id;
159       Op_Id : Entity_Id;
160       N     : Node_Id);
161    --  For the four varieties of concatenation
162
163    procedure Find_Equality_Types
164      (L, R  : Node_Id;
165       Op_Id : Entity_Id;
166       N     : Node_Id);
167    --  Ditto for equality operators
168
169    procedure Find_Boolean_Types
170      (L, R  : Node_Id;
171       Op_Id : Entity_Id;
172       N     : Node_Id);
173    --  Ditto for binary logical operations
174
175    procedure Find_Negation_Types
176      (R     : Node_Id;
177       Op_Id : Entity_Id;
178       N     : Node_Id);
179    --  Find consistent interpretation for operand of negation operator
180
181    procedure Find_Non_Universal_Interpretations
182      (N     : Node_Id;
183       R     : Node_Id;
184       Op_Id : Entity_Id;
185       T1    : Entity_Id);
186    --  For equality and comparison operators, the result is always boolean,
187    --  and the legality of the operation is determined from the visibility
188    --  of the operand types. If one of the operands has a universal interpre-
189    --  tation,  the legality check uses some compatible non-universal
190    --  interpretation of the other operand. N can be an operator node, or
191    --  a function call whose name is an operator designator.
192
193    function Find_Primitive_Operation (N : Node_Id) return Boolean;
194    --  Find candidate interpretations for the name Obj.Proc when it appears
195    --  in a subprogram renaming declaration.
196
197    procedure Find_Unary_Types
198      (R     : Node_Id;
199       Op_Id : Entity_Id;
200       N     : Node_Id);
201    --  Unary arithmetic types: plus, minus, abs
202
203    procedure Check_Arithmetic_Pair
204      (T1, T2 : Entity_Id;
205       Op_Id  : Entity_Id;
206       N      : Node_Id);
207    --  Subsidiary procedure to Find_Arithmetic_Types. T1 and T2 are valid
208    --  types for left and right operand. Determine whether they constitute
209    --  a valid pair for the given operator, and record the corresponding
210    --  interpretation of the operator node. The node N may be an operator
211    --  node (the usual case) or a function call whose prefix is an operator
212    --  designator. In both cases Op_Id is the operator name itself.
213
214    procedure Diagnose_Call (N : Node_Id; Nam : Node_Id);
215    --  Give detailed information on overloaded call where none of the
216    --  interpretations match. N is the call node, Nam the designator for
217    --  the overloaded entity being called.
218
219    function Junk_Operand (N : Node_Id) return Boolean;
220    --  Test for an operand that is an inappropriate entity (e.g. a package
221    --  name or a label). If so, issue an error message and return True. If
222    --  the operand is not an inappropriate entity kind, return False.
223
224    procedure Operator_Check (N : Node_Id);
225    --  Verify that an operator has received some valid interpretation. If none
226    --  was found, determine whether a use clause would make the operation
227    --  legal. The variable Candidate_Type (defined in Sem_Type) is set for
228    --  every type compatible with the operator, even if the operator for the
229    --  type is not directly visible. The routine uses this type to emit a more
230    --  informative message.
231
232    function Process_Implicit_Dereference_Prefix
233      (E : Entity_Id;
234       P : Node_Id) return Entity_Id;
235    --  Called when P is the prefix of an implicit dereference, denoting an
236    --  object E. The function returns the designated type of the prefix, taking
237    --  into account that the designated type of an anonymous access type may be
238    --  a limited view, when the non-limited view is visible.
239    --  If in semantics only mode (-gnatc or generic), the function also records
240    --  that the prefix is a reference to E, if any. Normally, such a reference
241    --  is generated only when the implicit dereference is expanded into an
242    --  explicit one, but for consistency we must generate the reference when
243    --  expansion is disabled as well.
244
245    procedure Remove_Abstract_Operations (N : Node_Id);
246    --  Ada 2005: implementation of AI-310. An abstract non-dispatching
247    --  operation is not a candidate interpretation.
248
249    function Try_Indexed_Call
250      (N          : Node_Id;
251       Nam        : Entity_Id;
252       Typ        : Entity_Id;
253       Skip_First : Boolean) return Boolean;
254    --  If a function has defaults for all its actuals, a call to it may in fact
255    --  be an indexing on the result of the call. Try_Indexed_Call attempts the
256    --  interpretation as an indexing, prior to analysis as a call. If both are
257    --  possible, the node is overloaded with both interpretations (same symbol
258    --  but two different types). If the call is written in prefix form, the
259    --  prefix becomes the first parameter in the call, and only the remaining
260    --  actuals must be checked for the presence of defaults.
261
262    function Try_Indirect_Call
263      (N   : Node_Id;
264       Nam : Entity_Id;
265       Typ : Entity_Id) return Boolean;
266    --  Similarly, a function F that needs no actuals can return an access to a
267    --  subprogram, and the call F (X) interpreted as F.all (X). In this case
268    --  the call may be overloaded with both interpretations.
269
270    function Try_Object_Operation (N : Node_Id) return Boolean;
271    --  Ada 2005 (AI-252): Support the object.operation notation
272
273    procedure wpo (T : Entity_Id);
274    pragma Warnings (Off, wpo);
275    --  Used for debugging: obtain list of primitive operations even if
276    --  type is not frozen and dispatch table is not built yet.
277
278    ------------------------
279    -- Ambiguous_Operands --
280    ------------------------
281
282    procedure Ambiguous_Operands (N : Node_Id) is
283       procedure List_Operand_Interps (Opnd : Node_Id);
284
285       --------------------------
286       -- List_Operand_Interps --
287       --------------------------
288
289       procedure List_Operand_Interps (Opnd : Node_Id) is
290          Nam   : Node_Id;
291          Err   : Node_Id := N;
292
293       begin
294          if Is_Overloaded (Opnd) then
295             if Nkind (Opnd) in N_Op then
296                Nam := Opnd;
297             elsif Nkind (Opnd) = N_Function_Call then
298                Nam := Name (Opnd);
299             else
300                return;
301             end if;
302
303          else
304             return;
305          end if;
306
307          if Opnd = Left_Opnd (N) then
308             Error_Msg_N
309               ("\left operand has the following interpretations", N);
310          else
311             Error_Msg_N
312               ("\right operand has the following interpretations", N);
313             Err := Opnd;
314          end if;
315
316          List_Interps (Nam, Err);
317       end List_Operand_Interps;
318
319    --  Start of processing for Ambiguous_Operands
320
321    begin
322       if Nkind (N) in N_Membership_Test then
323          Error_Msg_N ("ambiguous operands for membership",  N);
324
325       elsif Nkind_In (N, N_Op_Eq, N_Op_Ne) then
326          Error_Msg_N ("ambiguous operands for equality",  N);
327
328       else
329          Error_Msg_N ("ambiguous operands for comparison",  N);
330       end if;
331
332       if All_Errors_Mode then
333          List_Operand_Interps (Left_Opnd  (N));
334          List_Operand_Interps (Right_Opnd (N));
335       else
336          Error_Msg_N ("\use -gnatf switch for details", N);
337       end if;
338    end Ambiguous_Operands;
339
340    -----------------------
341    -- Analyze_Aggregate --
342    -----------------------
343
344    --  Most of the analysis of Aggregates requires that the type be known,
345    --  and is therefore put off until resolution.
346
347    procedure Analyze_Aggregate (N : Node_Id) is
348    begin
349       if No (Etype (N)) then
350          Set_Etype (N, Any_Composite);
351       end if;
352    end Analyze_Aggregate;
353
354    -----------------------
355    -- Analyze_Allocator --
356    -----------------------
357
358    procedure Analyze_Allocator (N : Node_Id) is
359       Loc      : constant Source_Ptr := Sloc (N);
360       Sav_Errs : constant Nat        := Serious_Errors_Detected;
361       E        : Node_Id             := Expression (N);
362       Acc_Type : Entity_Id;
363       Type_Id  : Entity_Id;
364
365    begin
366       --  In accordance with H.4(7), the No_Allocators restriction only applies
367       --  to user-written allocators.
368
369       if Comes_From_Source (N) then
370          Check_Restriction (No_Allocators, N);
371       end if;
372
373       if Nkind (E) = N_Qualified_Expression then
374          Acc_Type := Create_Itype (E_Allocator_Type, N);
375          Set_Etype (Acc_Type, Acc_Type);
376          Find_Type (Subtype_Mark (E));
377
378          --  Analyze the qualified expression, and apply the name resolution
379          --  rule given in  4.7 (3).
380
381          Analyze (E);
382          Type_Id := Etype (E);
383          Set_Directly_Designated_Type (Acc_Type, Type_Id);
384
385          Resolve (Expression (E), Type_Id);
386
387          if Is_Limited_Type (Type_Id)
388            and then Comes_From_Source (N)
389            and then not In_Instance_Body
390          then
391             if not OK_For_Limited_Init (Type_Id, Expression (E)) then
392                Error_Msg_N ("initialization not allowed for limited types", N);
393                Explain_Limited_Type (Type_Id, N);
394             end if;
395          end if;
396
397          --  A qualified expression requires an exact match of the type,
398          --  class-wide matching is not allowed.
399
400          --  if Is_Class_Wide_Type (Type_Id)
401          --    and then Base_Type
402          --       (Etype (Expression (E))) /= Base_Type (Type_Id)
403          --  then
404          --     Wrong_Type (Expression (E), Type_Id);
405          --  end if;
406
407          Check_Non_Static_Context (Expression (E));
408
409          --  We don't analyze the qualified expression itself because it's
410          --  part of the allocator
411
412          Set_Etype  (E, Type_Id);
413
414       --  Case where allocator has a subtype indication
415
416       else
417          declare
418             Def_Id   : Entity_Id;
419             Base_Typ : Entity_Id;
420
421          begin
422             --  If the allocator includes a N_Subtype_Indication then a
423             --  constraint is present, otherwise the node is a subtype mark.
424             --  Introduce an explicit subtype declaration into the tree
425             --  defining some anonymous subtype and rewrite the allocator to
426             --  use this subtype rather than the subtype indication.
427
428             --  It is important to introduce the explicit subtype declaration
429             --  so that the bounds of the subtype indication are attached to
430             --  the tree in case the allocator is inside a generic unit.
431
432             if Nkind (E) = N_Subtype_Indication then
433
434                --  A constraint is only allowed for a composite type in Ada
435                --  95. In Ada 83, a constraint is also allowed for an
436                --  access-to-composite type, but the constraint is ignored.
437
438                Find_Type (Subtype_Mark (E));
439                Base_Typ := Entity (Subtype_Mark (E));
440
441                if Is_Elementary_Type (Base_Typ) then
442                   if not (Ada_Version = Ada_83
443                            and then Is_Access_Type (Base_Typ))
444                   then
445                      Error_Msg_N ("constraint not allowed here", E);
446
447                      if Nkind (Constraint (E)) =
448                        N_Index_Or_Discriminant_Constraint
449                      then
450                         Error_Msg_N -- CODEFIX
451                           ("\if qualified expression was meant, " &
452                               "use apostrophe", Constraint (E));
453                      end if;
454                   end if;
455
456                   --  Get rid of the bogus constraint:
457
458                   Rewrite (E, New_Copy_Tree (Subtype_Mark (E)));
459                   Analyze_Allocator (N);
460                   return;
461
462                --  Ada 2005, AI-363: if the designated type has a constrained
463                --  partial view, it cannot receive a discriminant constraint,
464                --  and the allocated object is unconstrained.
465
466                elsif Ada_Version >= Ada_05
467                  and then Has_Constrained_Partial_View (Base_Typ)
468                then
469                   Error_Msg_N
470                     ("constraint no allowed when type " &
471                       "has a constrained partial view", Constraint (E));
472                end if;
473
474                if Expander_Active then
475                   Def_Id :=
476                     Make_Defining_Identifier (Loc, New_Internal_Name ('S'));
477
478                   Insert_Action (E,
479                     Make_Subtype_Declaration (Loc,
480                       Defining_Identifier => Def_Id,
481                       Subtype_Indication  => Relocate_Node (E)));
482
483                   if Sav_Errs /= Serious_Errors_Detected
484                     and then Nkind (Constraint (E)) =
485                                N_Index_Or_Discriminant_Constraint
486                   then
487                      Error_Msg_N -- CODEFIX
488                        ("if qualified expression was meant, " &
489                            "use apostrophe!", Constraint (E));
490                   end if;
491
492                   E := New_Occurrence_Of (Def_Id, Loc);
493                   Rewrite (Expression (N), E);
494                end if;
495             end if;
496
497             Type_Id := Process_Subtype (E, N);
498             Acc_Type := Create_Itype (E_Allocator_Type, N);
499             Set_Etype                    (Acc_Type, Acc_Type);
500             Set_Directly_Designated_Type (Acc_Type, Type_Id);
501             Check_Fully_Declared (Type_Id, N);
502
503             --  Ada 2005 (AI-231): If the designated type is itself an access
504             --  type that excludes null, its default initialization will
505             --  be a null object, and we can insert an unconditional raise
506             --  before the allocator.
507
508             if Can_Never_Be_Null (Type_Id) then
509                declare
510                   Not_Null_Check : constant Node_Id :=
511                                      Make_Raise_Constraint_Error (Sloc (E),
512                                        Reason => CE_Null_Not_Allowed);
513                begin
514                   if Expander_Active then
515                      Insert_Action (N, Not_Null_Check);
516                      Analyze (Not_Null_Check);
517                   else
518                      Error_Msg_N ("null value not allowed here?", E);
519                   end if;
520                end;
521             end if;
522
523             --  Check restriction against dynamically allocated protected
524             --  objects. Note that when limited aggregates are supported,
525             --  a similar test should be applied to an allocator with a
526             --  qualified expression ???
527
528             if Is_Protected_Type (Type_Id) then
529                Check_Restriction (No_Protected_Type_Allocators, N);
530             end if;
531
532             --  Check for missing initialization. Skip this check if we already
533             --  had errors on analyzing the allocator, since in that case these
534             --  are probably cascaded errors.
535
536             if Is_Indefinite_Subtype (Type_Id)
537               and then Serious_Errors_Detected = Sav_Errs
538             then
539                if Is_Class_Wide_Type (Type_Id) then
540                   Error_Msg_N
541                     ("initialization required in class-wide allocation", N);
542                else
543                   if Ada_Version < Ada_05
544                     and then Is_Limited_Type (Type_Id)
545                   then
546                      Error_Msg_N ("unconstrained allocation not allowed", N);
547
548                      if Is_Array_Type (Type_Id) then
549                         Error_Msg_N
550                           ("\constraint with array bounds required", N);
551
552                      elsif Has_Unknown_Discriminants (Type_Id) then
553                         null;
554
555                      else pragma Assert (Has_Discriminants (Type_Id));
556                         Error_Msg_N
557                           ("\constraint with discriminant values required", N);
558                      end if;
559
560                   --  Limited Ada 2005 and general non-limited case
561
562                   else
563                      Error_Msg_N
564                        ("uninitialized unconstrained allocation not allowed",
565                         N);
566
567                      if Is_Array_Type (Type_Id) then
568                         Error_Msg_N
569                           ("\qualified expression or constraint with " &
570                            "array bounds required", N);
571
572                      elsif Has_Unknown_Discriminants (Type_Id) then
573                         Error_Msg_N ("\qualified expression required", N);
574
575                      else pragma Assert (Has_Discriminants (Type_Id));
576                         Error_Msg_N
577                           ("\qualified expression or constraint with " &
578                            "discriminant values required", N);
579                      end if;
580                   end if;
581                end if;
582             end if;
583          end;
584       end if;
585
586       if Is_Abstract_Type (Type_Id) then
587          Error_Msg_N ("cannot allocate abstract object", E);
588       end if;
589
590       if Has_Task (Designated_Type (Acc_Type)) then
591          Check_Restriction (No_Tasking, N);
592          Check_Restriction (Max_Tasks, N);
593          Check_Restriction (No_Task_Allocators, N);
594       end if;
595
596       --  If the No_Streams restriction is set, check that the type of the
597       --  object is not, and does not contain, any subtype derived from
598       --  Ada.Streams.Root_Stream_Type. Note that we guard the call to
599       --  Has_Stream just for efficiency reasons. There is no point in
600       --  spending time on a Has_Stream check if the restriction is not set.
601
602       if Restrictions.Set (No_Streams) then
603          if Has_Stream (Designated_Type (Acc_Type)) then
604             Check_Restriction (No_Streams, N);
605          end if;
606       end if;
607
608       Set_Etype (N, Acc_Type);
609
610       if not Is_Library_Level_Entity (Acc_Type) then
611          Check_Restriction (No_Local_Allocators, N);
612       end if;
613
614       if Serious_Errors_Detected > Sav_Errs then
615          Set_Error_Posted (N);
616          Set_Etype (N, Any_Type);
617       end if;
618    end Analyze_Allocator;
619
620    ---------------------------
621    -- Analyze_Arithmetic_Op --
622    ---------------------------
623
624    procedure Analyze_Arithmetic_Op (N : Node_Id) is
625       L     : constant Node_Id := Left_Opnd (N);
626       R     : constant Node_Id := Right_Opnd (N);
627       Op_Id : Entity_Id;
628
629    begin
630       Candidate_Type := Empty;
631       Analyze_Expression (L);
632       Analyze_Expression (R);
633
634       --  If the entity is already set, the node is the instantiation of a
635       --  generic node with a non-local reference, or was manufactured by a
636       --  call to Make_Op_xxx. In either case the entity is known to be valid,
637       --  and we do not need to collect interpretations, instead we just get
638       --  the single possible interpretation.
639
640       Op_Id := Entity (N);
641
642       if Present (Op_Id) then
643          if Ekind (Op_Id) = E_Operator then
644
645             if Nkind_In (N, N_Op_Divide, N_Op_Mod, N_Op_Multiply, N_Op_Rem)
646               and then Treat_Fixed_As_Integer (N)
647             then
648                null;
649             else
650                Set_Etype (N, Any_Type);
651                Find_Arithmetic_Types (L, R, Op_Id, N);
652             end if;
653
654          else
655             Set_Etype (N, Any_Type);
656             Add_One_Interp (N, Op_Id, Etype (Op_Id));
657          end if;
658
659       --  Entity is not already set, so we do need to collect interpretations
660
661       else
662          Op_Id := Get_Name_Entity_Id (Chars (N));
663          Set_Etype (N, Any_Type);
664
665          while Present (Op_Id) loop
666             if Ekind (Op_Id) = E_Operator
667               and then Present (Next_Entity (First_Entity (Op_Id)))
668             then
669                Find_Arithmetic_Types (L, R, Op_Id, N);
670
671             --  The following may seem superfluous, because an operator cannot
672             --  be generic, but this ignores the cleverness of the author of
673             --  ACVC bc1013a.
674
675             elsif Is_Overloadable (Op_Id) then
676                Analyze_User_Defined_Binary_Op (N, Op_Id);
677             end if;
678
679             Op_Id := Homonym (Op_Id);
680          end loop;
681       end if;
682
683       Operator_Check (N);
684    end Analyze_Arithmetic_Op;
685
686    ------------------
687    -- Analyze_Call --
688    ------------------
689
690    --  Function, procedure, and entry calls are checked here. The Name in
691    --  the call may be overloaded. The actuals have been analyzed and may
692    --  themselves be overloaded. On exit from this procedure, the node N
693    --  may have zero, one or more interpretations. In the first case an
694    --  error message is produced. In the last case, the node is flagged
695    --  as overloaded and the interpretations are collected in All_Interp.
696
697    --  If the name is an Access_To_Subprogram, it cannot be overloaded, but
698    --  the type-checking is similar to that of other calls.
699
700    procedure Analyze_Call (N : Node_Id) is
701       Actuals : constant List_Id := Parameter_Associations (N);
702       Nam     : Node_Id;
703       X       : Interp_Index;
704       It      : Interp;
705       Nam_Ent : Entity_Id;
706       Success : Boolean := False;
707
708       Deref : Boolean := False;
709       --  Flag indicates whether an interpretation of the prefix is a
710       --  parameterless call that returns an access_to_subprogram.
711
712       function Name_Denotes_Function return Boolean;
713       --  If the type of the name is an access to subprogram, this may be the
714       --  type of a name, or the return type of the function being called. If
715       --  the name is not an entity then it can denote a protected function.
716       --  Until we distinguish Etype from Return_Type, we must use this routine
717       --  to resolve the meaning of the name in the call.
718
719       procedure No_Interpretation;
720       --  Output error message when no valid interpretation exists
721
722       ---------------------------
723       -- Name_Denotes_Function --
724       ---------------------------
725
726       function Name_Denotes_Function return Boolean is
727       begin
728          if Is_Entity_Name (Nam) then
729             return Ekind (Entity (Nam)) = E_Function;
730
731          elsif Nkind (Nam) = N_Selected_Component then
732             return Ekind (Entity (Selector_Name (Nam))) = E_Function;
733
734          else
735             return False;
736          end if;
737       end Name_Denotes_Function;
738
739       -----------------------
740       -- No_Interpretation --
741       -----------------------
742
743       procedure No_Interpretation is
744          L : constant Boolean   := Is_List_Member (N);
745          K : constant Node_Kind := Nkind (Parent (N));
746
747       begin
748          --  If the node is in a list whose parent is not an expression then it
749          --  must be an attempted procedure call.
750
751          if L and then K not in N_Subexpr then
752             if Ekind (Entity (Nam)) = E_Generic_Procedure then
753                Error_Msg_NE
754                  ("must instantiate generic procedure& before call",
755                   Nam, Entity (Nam));
756             else
757                Error_Msg_N
758                  ("procedure or entry name expected", Nam);
759             end if;
760
761          --  Check for tasking cases where only an entry call will do
762
763          elsif not L
764            and then Nkind_In (K, N_Entry_Call_Alternative,
765                                  N_Triggering_Alternative)
766          then
767             Error_Msg_N ("entry name expected", Nam);
768
769          --  Otherwise give general error message
770
771          else
772             Error_Msg_N ("invalid prefix in call", Nam);
773          end if;
774       end No_Interpretation;
775
776    --  Start of processing for Analyze_Call
777
778    begin
779       --  Initialize the type of the result of the call to the error type,
780       --  which will be reset if the type is successfully resolved.
781
782       Set_Etype (N, Any_Type);
783
784       Nam := Name (N);
785
786       if not Is_Overloaded (Nam) then
787
788          --  Only one interpretation to check
789
790          if Ekind (Etype (Nam)) = E_Subprogram_Type then
791             Nam_Ent := Etype (Nam);
792
793          --  If the prefix is an access_to_subprogram, this may be an indirect
794          --  call. This is the case if the name in the call is not an entity
795          --  name, or if it is a function name in the context of a procedure
796          --  call. In this latter case, we have a call to a parameterless
797          --  function that returns a pointer_to_procedure which is the entity
798          --  being called. Finally, F (X) may be a call to a parameterless
799          --  function that returns a pointer to a function with parameters.
800
801          elsif Is_Access_Type (Etype (Nam))
802            and then Ekind (Designated_Type (Etype (Nam))) = E_Subprogram_Type
803            and then
804              (not Name_Denotes_Function
805                 or else Nkind (N) = N_Procedure_Call_Statement
806                 or else
807                   (Nkind (Parent (N)) /= N_Explicit_Dereference
808                      and then Is_Entity_Name (Nam)
809                      and then No (First_Formal (Entity (Nam)))
810                      and then Present (Actuals)))
811          then
812             Nam_Ent := Designated_Type (Etype (Nam));
813             Insert_Explicit_Dereference (Nam);
814
815          --  Selected component case. Simple entry or protected operation,
816          --  where the entry name is given by the selector name.
817
818          elsif Nkind (Nam) = N_Selected_Component then
819             Nam_Ent := Entity (Selector_Name (Nam));
820
821             if not Ekind_In (Nam_Ent, E_Entry,
822                                       E_Entry_Family,
823                                       E_Function,
824                                       E_Procedure)
825             then
826                Error_Msg_N ("name in call is not a callable entity", Nam);
827                Set_Etype (N, Any_Type);
828                return;
829             end if;
830
831          --  If the name is an Indexed component, it can be a call to a member
832          --  of an entry family. The prefix must be a selected component whose
833          --  selector is the entry. Analyze_Procedure_Call normalizes several
834          --  kinds of call into this form.
835
836          elsif Nkind (Nam) = N_Indexed_Component then
837             if Nkind (Prefix (Nam)) = N_Selected_Component then
838                Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
839             else
840                Error_Msg_N ("name in call is not a callable entity", Nam);
841                Set_Etype (N, Any_Type);
842                return;
843             end if;
844
845          elsif not Is_Entity_Name (Nam) then
846             Error_Msg_N ("name in call is not a callable entity", Nam);
847             Set_Etype (N, Any_Type);
848             return;
849
850          else
851             Nam_Ent := Entity (Nam);
852
853             --  If no interpretations, give error message
854
855             if not Is_Overloadable (Nam_Ent) then
856                No_Interpretation;
857                return;
858             end if;
859          end if;
860
861          --  Operations generated for RACW stub types are called only through
862          --  dispatching, and can never be the static interpretation of a call.
863
864          if Is_RACW_Stub_Type_Operation (Nam_Ent) then
865             No_Interpretation;
866             return;
867          end if;
868
869          Analyze_One_Call (N, Nam_Ent, True, Success);
870
871          --  If this is an indirect call, the return type of the access_to
872          --  subprogram may be an incomplete type. At the point of the call,
873          --  use the full type if available, and at the same time update
874          --  the return type of the access_to_subprogram.
875
876          if Success
877            and then Nkind (Nam) = N_Explicit_Dereference
878            and then Ekind (Etype (N)) = E_Incomplete_Type
879            and then Present (Full_View (Etype (N)))
880          then
881             Set_Etype (N, Full_View (Etype (N)));
882             Set_Etype (Nam_Ent, Etype (N));
883          end if;
884
885       else
886          --  An overloaded selected component must denote overloaded operations
887          --  of a concurrent type. The interpretations are attached to the
888          --  simple name of those operations.
889
890          if Nkind (Nam) = N_Selected_Component then
891             Nam := Selector_Name (Nam);
892          end if;
893
894          Get_First_Interp (Nam, X, It);
895
896          while Present (It.Nam) loop
897             Nam_Ent := It.Nam;
898             Deref   := False;
899
900             --  Name may be call that returns an access to subprogram, or more
901             --  generally an overloaded expression one of whose interpretations
902             --  yields an access to subprogram. If the name is an entity, we
903             --  do not dereference, because the node is a call that returns
904             --  the access type: note difference between f(x), where the call
905             --  may return an access subprogram type, and f(x)(y), where the
906             --  type returned by the call to f is implicitly dereferenced to
907             --  analyze the outer call.
908
909             if Is_Access_Type (Nam_Ent) then
910                Nam_Ent := Designated_Type (Nam_Ent);
911
912             elsif Is_Access_Type (Etype (Nam_Ent))
913               and then
914                 (not Is_Entity_Name (Nam)
915                    or else Nkind (N) = N_Procedure_Call_Statement)
916               and then Ekind (Designated_Type (Etype (Nam_Ent)))
917                                                           = E_Subprogram_Type
918             then
919                Nam_Ent := Designated_Type (Etype (Nam_Ent));
920
921                if Is_Entity_Name (Nam) then
922                   Deref := True;
923                end if;
924             end if;
925
926             --  If the call has been rewritten from a prefixed call, the first
927             --  parameter has been analyzed, but may need a subsequent
928             --  dereference, so skip its analysis now.
929
930             if N /= Original_Node (N)
931               and then Nkind (Original_Node (N)) = Nkind (N)
932               and then Nkind (Name (N)) /= Nkind (Name (Original_Node (N)))
933               and then Present (Parameter_Associations (N))
934               and then Present (Etype (First (Parameter_Associations (N))))
935             then
936                Analyze_One_Call
937                  (N, Nam_Ent, False, Success, Skip_First => True);
938             else
939                Analyze_One_Call (N, Nam_Ent, False, Success);
940             end if;
941
942             --  If the interpretation succeeds, mark the proper type of the
943             --  prefix (any valid candidate will do). If not, remove the
944             --  candidate interpretation. This only needs to be done for
945             --  overloaded protected operations, for other entities disambi-
946             --  guation is done directly in Resolve.
947
948             if Success then
949                if Deref
950                  and then Nkind (Parent (N)) /= N_Explicit_Dereference
951                then
952                   Set_Entity (Nam, It.Nam);
953                   Insert_Explicit_Dereference (Nam);
954                   Set_Etype (Nam, Nam_Ent);
955
956                else
957                   Set_Etype (Nam, It.Typ);
958                end if;
959
960             elsif Nkind_In (Name (N), N_Selected_Component,
961                                       N_Function_Call)
962             then
963                Remove_Interp (X);
964             end if;
965
966             Get_Next_Interp (X, It);
967          end loop;
968
969          --  If the name is the result of a function call, it can only
970          --  be a call to a function returning an access to subprogram.
971          --  Insert explicit dereference.
972
973          if Nkind (Nam) = N_Function_Call then
974             Insert_Explicit_Dereference (Nam);
975          end if;
976
977          if Etype (N) = Any_Type then
978
979             --  None of the interpretations is compatible with the actuals
980
981             Diagnose_Call (N, Nam);
982
983             --  Special checks for uninstantiated put routines
984
985             if Nkind (N) = N_Procedure_Call_Statement
986               and then Is_Entity_Name (Nam)
987               and then Chars (Nam) = Name_Put
988               and then List_Length (Actuals) = 1
989             then
990                declare
991                   Arg : constant Node_Id := First (Actuals);
992                   Typ : Entity_Id;
993
994                begin
995                   if Nkind (Arg) = N_Parameter_Association then
996                      Typ := Etype (Explicit_Actual_Parameter (Arg));
997                   else
998                      Typ := Etype (Arg);
999                   end if;
1000
1001                   if Is_Signed_Integer_Type (Typ) then
1002                      Error_Msg_N
1003                        ("possible missing instantiation of " &
1004                           "'Text_'I'O.'Integer_'I'O!", Nam);
1005
1006                   elsif Is_Modular_Integer_Type (Typ) then
1007                      Error_Msg_N
1008                        ("possible missing instantiation of " &
1009                           "'Text_'I'O.'Modular_'I'O!", Nam);
1010
1011                   elsif Is_Floating_Point_Type (Typ) then
1012                      Error_Msg_N
1013                        ("possible missing instantiation of " &
1014                           "'Text_'I'O.'Float_'I'O!", Nam);
1015
1016                   elsif Is_Ordinary_Fixed_Point_Type (Typ) then
1017                      Error_Msg_N
1018                        ("possible missing instantiation of " &
1019                           "'Text_'I'O.'Fixed_'I'O!", Nam);
1020
1021                   elsif Is_Decimal_Fixed_Point_Type (Typ) then
1022                      Error_Msg_N
1023                        ("possible missing instantiation of " &
1024                           "'Text_'I'O.'Decimal_'I'O!", Nam);
1025
1026                   elsif Is_Enumeration_Type (Typ) then
1027                      Error_Msg_N
1028                        ("possible missing instantiation of " &
1029                           "'Text_'I'O.'Enumeration_'I'O!", Nam);
1030                   end if;
1031                end;
1032             end if;
1033
1034          elsif not Is_Overloaded (N)
1035            and then Is_Entity_Name (Nam)
1036          then
1037             --  Resolution yields a single interpretation. Verify that the
1038             --  reference has capitalization consistent with the declaration.
1039
1040             Set_Entity_With_Style_Check (Nam, Entity (Nam));
1041             Generate_Reference (Entity (Nam), Nam);
1042
1043             Set_Etype (Nam, Etype (Entity (Nam)));
1044          else
1045             Remove_Abstract_Operations (N);
1046          end if;
1047
1048          End_Interp_List;
1049       end if;
1050    end Analyze_Call;
1051
1052    ---------------------------
1053    -- Analyze_Comparison_Op --
1054    ---------------------------
1055
1056    procedure Analyze_Comparison_Op (N : Node_Id) is
1057       L     : constant Node_Id := Left_Opnd (N);
1058       R     : constant Node_Id := Right_Opnd (N);
1059       Op_Id : Entity_Id        := Entity (N);
1060
1061    begin
1062       Set_Etype (N, Any_Type);
1063       Candidate_Type := Empty;
1064
1065       Analyze_Expression (L);
1066       Analyze_Expression (R);
1067
1068       if Present (Op_Id) then
1069          if Ekind (Op_Id) = E_Operator then
1070             Find_Comparison_Types (L, R, Op_Id, N);
1071          else
1072             Add_One_Interp (N, Op_Id, Etype (Op_Id));
1073          end if;
1074
1075          if Is_Overloaded (L) then
1076             Set_Etype (L, Intersect_Types (L, R));
1077          end if;
1078
1079       else
1080          Op_Id := Get_Name_Entity_Id (Chars (N));
1081          while Present (Op_Id) loop
1082             if Ekind (Op_Id) = E_Operator then
1083                Find_Comparison_Types (L, R, Op_Id, N);
1084             else
1085                Analyze_User_Defined_Binary_Op (N, Op_Id);
1086             end if;
1087
1088             Op_Id := Homonym (Op_Id);
1089          end loop;
1090       end if;
1091
1092       Operator_Check (N);
1093    end Analyze_Comparison_Op;
1094
1095    ---------------------------
1096    -- Analyze_Concatenation --
1097    ---------------------------
1098
1099    procedure Analyze_Concatenation (N : Node_Id) is
1100
1101       --  We wish to avoid deep recursion, because concatenations are often
1102       --  deeply nested, as in A&B&...&Z. Therefore, we walk down the left
1103       --  operands nonrecursively until we find something that is not a
1104       --  concatenation (A in this case), or has already been analyzed. We
1105       --  analyze that, and then walk back up the tree following Parent
1106       --  pointers, calling Analyze_Concatenation_Rest to do the rest of the
1107       --  work at each level. The Parent pointers allow us to avoid recursion,
1108       --  and thus avoid running out of memory.
1109
1110       NN : Node_Id := N;
1111       L  : Node_Id;
1112
1113    begin
1114       Candidate_Type := Empty;
1115
1116       --  The following code is equivalent to:
1117
1118       --    Set_Etype (N, Any_Type);
1119       --    Analyze_Expression (Left_Opnd (N));
1120       --    Analyze_Concatenation_Rest (N);
1121
1122       --  where the Analyze_Expression call recurses back here if the left
1123       --  operand is a concatenation.
1124
1125       --  Walk down left operands
1126
1127       loop
1128          Set_Etype (NN, Any_Type);
1129          L := Left_Opnd (NN);
1130          exit when Nkind (L) /= N_Op_Concat or else Analyzed (L);
1131          NN := L;
1132       end loop;
1133
1134       --  Now (given the above example) NN is A&B and L is A
1135
1136       --  First analyze L ...
1137
1138       Analyze_Expression (L);
1139
1140       --  ... then walk NN back up until we reach N (where we started), calling
1141       --  Analyze_Concatenation_Rest along the way.
1142
1143       loop
1144          Analyze_Concatenation_Rest (NN);
1145          exit when NN = N;
1146          NN := Parent (NN);
1147       end loop;
1148    end Analyze_Concatenation;
1149
1150    --------------------------------
1151    -- Analyze_Concatenation_Rest --
1152    --------------------------------
1153
1154    --  If the only one-dimensional array type in scope is String,
1155    --  this is the resulting type of the operation. Otherwise there
1156    --  will be a concatenation operation defined for each user-defined
1157    --  one-dimensional array.
1158
1159    procedure Analyze_Concatenation_Rest (N : Node_Id) is
1160       L     : constant Node_Id := Left_Opnd (N);
1161       R     : constant Node_Id := Right_Opnd (N);
1162       Op_Id : Entity_Id        := Entity (N);
1163       LT    : Entity_Id;
1164       RT    : Entity_Id;
1165
1166    begin
1167       Analyze_Expression (R);
1168
1169       --  If the entity is present, the node appears in an instance, and
1170       --  denotes a predefined concatenation operation. The resulting type is
1171       --  obtained from the arguments when possible. If the arguments are
1172       --  aggregates, the array type and the concatenation type must be
1173       --  visible.
1174
1175       if Present (Op_Id) then
1176          if Ekind (Op_Id) = E_Operator then
1177             LT := Base_Type (Etype (L));
1178             RT := Base_Type (Etype (R));
1179
1180             if Is_Array_Type (LT)
1181               and then (RT = LT or else RT = Base_Type (Component_Type (LT)))
1182             then
1183                Add_One_Interp (N, Op_Id, LT);
1184
1185             elsif Is_Array_Type (RT)
1186               and then LT = Base_Type (Component_Type (RT))
1187             then
1188                Add_One_Interp (N, Op_Id, RT);
1189
1190             --  If one operand is a string type or a user-defined array type,
1191             --  and the other is a literal, result is of the specific type.
1192
1193             elsif
1194               (Root_Type (LT) = Standard_String
1195                  or else Scope (LT) /= Standard_Standard)
1196               and then Etype (R) = Any_String
1197             then
1198                Add_One_Interp (N, Op_Id, LT);
1199
1200             elsif
1201               (Root_Type (RT) = Standard_String
1202                  or else Scope (RT) /= Standard_Standard)
1203               and then Etype (L) = Any_String
1204             then
1205                Add_One_Interp (N, Op_Id, RT);
1206
1207             elsif not Is_Generic_Type (Etype (Op_Id)) then
1208                Add_One_Interp (N, Op_Id, Etype (Op_Id));
1209
1210             else
1211                --  Type and its operations must be visible
1212
1213                Set_Entity (N, Empty);
1214                Analyze_Concatenation (N);
1215             end if;
1216
1217          else
1218             Add_One_Interp (N, Op_Id, Etype (Op_Id));
1219          end if;
1220
1221       else
1222          Op_Id := Get_Name_Entity_Id (Name_Op_Concat);
1223          while Present (Op_Id) loop
1224             if Ekind (Op_Id) = E_Operator then
1225
1226                --  Do not consider operators declared in dead code, they can
1227                --  not be part of the resolution.
1228
1229                if Is_Eliminated (Op_Id) then
1230                   null;
1231                else
1232                   Find_Concatenation_Types (L, R, Op_Id, N);
1233                end if;
1234
1235             else
1236                Analyze_User_Defined_Binary_Op (N, Op_Id);
1237             end if;
1238
1239             Op_Id := Homonym (Op_Id);
1240          end loop;
1241       end if;
1242
1243       Operator_Check (N);
1244    end Analyze_Concatenation_Rest;
1245
1246    ------------------------------------
1247    -- Analyze_Conditional_Expression --
1248    ------------------------------------
1249
1250    procedure Analyze_Conditional_Expression (N : Node_Id) is
1251       Condition : constant Node_Id := First (Expressions (N));
1252       Then_Expr : constant Node_Id := Next (Condition);
1253       Else_Expr : constant Node_Id := Next (Then_Expr);
1254
1255    begin
1256       if Comes_From_Source (N) then
1257          Check_Compiler_Unit (N);
1258       end if;
1259
1260       Analyze_Expression (Condition);
1261       Analyze_Expression (Then_Expr);
1262
1263       if Present (Else_Expr) then
1264          Analyze_Expression (Else_Expr);
1265       end if;
1266
1267       if not Is_Overloaded (Then_Expr) then
1268          Set_Etype (N, Etype (Then_Expr));
1269       else
1270          declare
1271             I  : Interp_Index;
1272             It : Interp;
1273
1274          begin
1275             Set_Etype (N, Any_Type);
1276             Get_First_Interp (Then_Expr, I, It);
1277             while Present (It.Nam) loop
1278                if Has_Compatible_Type (Else_Expr, It.Typ) then
1279                   Add_One_Interp (N, It.Typ, It.Typ);
1280                end if;
1281
1282                Get_Next_Interp (I, It);
1283             end loop;
1284          end;
1285       end if;
1286    end Analyze_Conditional_Expression;
1287
1288    -------------------------
1289    -- Analyze_Equality_Op --
1290    -------------------------
1291
1292    procedure Analyze_Equality_Op (N : Node_Id) is
1293       Loc   : constant Source_Ptr := Sloc (N);
1294       L     : constant Node_Id := Left_Opnd (N);
1295       R     : constant Node_Id := Right_Opnd (N);
1296       Op_Id : Entity_Id;
1297
1298    begin
1299       Set_Etype (N, Any_Type);
1300       Candidate_Type := Empty;
1301
1302       Analyze_Expression (L);
1303       Analyze_Expression (R);
1304
1305       --  If the entity is set, the node is a generic instance with a non-local
1306       --  reference to the predefined operator or to a user-defined function.
1307       --  It can also be an inequality that is expanded into the negation of a
1308       --  call to a user-defined equality operator.
1309
1310       --  For the predefined case, the result is Boolean, regardless of the
1311       --  type of the  operands. The operands may even be limited, if they are
1312       --  generic actuals. If they are overloaded, label the left argument with
1313       --  the common type that must be present, or with the type of the formal
1314       --  of the user-defined function.
1315
1316       if Present (Entity (N)) then
1317          Op_Id := Entity (N);
1318
1319          if Ekind (Op_Id) = E_Operator then
1320             Add_One_Interp (N, Op_Id, Standard_Boolean);
1321          else
1322             Add_One_Interp (N, Op_Id, Etype (Op_Id));
1323          end if;
1324
1325          if Is_Overloaded (L) then
1326             if Ekind (Op_Id) = E_Operator then
1327                Set_Etype (L, Intersect_Types (L, R));
1328             else
1329                Set_Etype (L, Etype (First_Formal (Op_Id)));
1330             end if;
1331          end if;
1332
1333       else
1334          Op_Id := Get_Name_Entity_Id (Chars (N));
1335          while Present (Op_Id) loop
1336             if Ekind (Op_Id) = E_Operator then
1337                Find_Equality_Types (L, R, Op_Id, N);
1338             else
1339                Analyze_User_Defined_Binary_Op (N, Op_Id);
1340             end if;
1341
1342             Op_Id := Homonym (Op_Id);
1343          end loop;
1344       end if;
1345
1346       --  If there was no match, and the operator is inequality, this may
1347       --  be a case where inequality has not been made explicit, as for
1348       --  tagged types. Analyze the node as the negation of an equality
1349       --  operation. This cannot be done earlier, because before analysis
1350       --  we cannot rule out the presence of an explicit inequality.
1351
1352       if Etype (N) = Any_Type
1353         and then Nkind (N) = N_Op_Ne
1354       then
1355          Op_Id := Get_Name_Entity_Id (Name_Op_Eq);
1356          while Present (Op_Id) loop
1357             if Ekind (Op_Id) = E_Operator then
1358                Find_Equality_Types (L, R, Op_Id, N);
1359             else
1360                Analyze_User_Defined_Binary_Op (N, Op_Id);
1361             end if;
1362
1363             Op_Id := Homonym (Op_Id);
1364          end loop;
1365
1366          if Etype (N) /= Any_Type then
1367             Op_Id := Entity (N);
1368
1369             Rewrite (N,
1370               Make_Op_Not (Loc,
1371                 Right_Opnd =>
1372                   Make_Op_Eq (Loc,
1373                     Left_Opnd  => Left_Opnd (N),
1374                     Right_Opnd => Right_Opnd (N))));
1375
1376             Set_Entity (Right_Opnd (N), Op_Id);
1377             Analyze (N);
1378          end if;
1379       end if;
1380
1381       Operator_Check (N);
1382    end Analyze_Equality_Op;
1383
1384    ----------------------------------
1385    -- Analyze_Explicit_Dereference --
1386    ----------------------------------
1387
1388    procedure Analyze_Explicit_Dereference (N : Node_Id) is
1389       Loc   : constant Source_Ptr := Sloc (N);
1390       P     : constant Node_Id := Prefix (N);
1391       T     : Entity_Id;
1392       I     : Interp_Index;
1393       It    : Interp;
1394       New_N : Node_Id;
1395
1396       function Is_Function_Type return Boolean;
1397       --  Check whether node may be interpreted as an implicit function call
1398
1399       ----------------------
1400       -- Is_Function_Type --
1401       ----------------------
1402
1403       function Is_Function_Type return Boolean is
1404          I  : Interp_Index;
1405          It : Interp;
1406
1407       begin
1408          if not Is_Overloaded (N) then
1409             return Ekind (Base_Type (Etype (N))) = E_Subprogram_Type
1410               and then Etype (Base_Type (Etype (N))) /= Standard_Void_Type;
1411
1412          else
1413             Get_First_Interp (N, I, It);
1414             while Present (It.Nam) loop
1415                if Ekind (Base_Type (It.Typ)) /= E_Subprogram_Type
1416                  or else Etype (Base_Type (It.Typ)) = Standard_Void_Type
1417                then
1418                   return False;
1419                end if;
1420
1421                Get_Next_Interp (I, It);
1422             end loop;
1423
1424             return True;
1425          end if;
1426       end Is_Function_Type;
1427
1428    --  Start of processing for Analyze_Explicit_Dereference
1429
1430    begin
1431       Analyze (P);
1432       Set_Etype (N, Any_Type);
1433
1434       --  Test for remote access to subprogram type, and if so return
1435       --  after rewriting the original tree.
1436
1437       if Remote_AST_E_Dereference (P) then
1438          return;
1439       end if;
1440
1441       --  Normal processing for other than remote access to subprogram type
1442
1443       if not Is_Overloaded (P) then
1444          if Is_Access_Type (Etype (P)) then
1445
1446             --  Set the Etype. We need to go through Is_For_Access_Subtypes to
1447             --  avoid other problems caused by the Private_Subtype and it is
1448             --  safe to go to the Base_Type because this is the same as
1449             --  converting the access value to its Base_Type.
1450
1451             declare
1452                DT : Entity_Id := Designated_Type (Etype (P));
1453
1454             begin
1455                if Ekind (DT) = E_Private_Subtype
1456                  and then Is_For_Access_Subtype (DT)
1457                then
1458                   DT := Base_Type (DT);
1459                end if;
1460
1461                --  An explicit dereference is a legal occurrence of an
1462                --  incomplete type imported through a limited_with clause,
1463                --  if the full view is visible.
1464
1465                if From_With_Type (DT)
1466                  and then not From_With_Type (Scope (DT))
1467                  and then
1468                    (Is_Immediately_Visible (Scope (DT))
1469                      or else
1470                        (Is_Child_Unit (Scope (DT))
1471                           and then Is_Visible_Child_Unit (Scope (DT))))
1472                then
1473                   Set_Etype (N, Available_View (DT));
1474
1475                else
1476                   Set_Etype (N, DT);
1477                end if;
1478             end;
1479
1480          elsif Etype (P) /= Any_Type then
1481             Error_Msg_N ("prefix of dereference must be an access type", N);
1482             return;
1483          end if;
1484
1485       else
1486          Get_First_Interp (P, I, It);
1487          while Present (It.Nam) loop
1488             T := It.Typ;
1489
1490             if Is_Access_Type (T) then
1491                Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
1492             end if;
1493
1494             Get_Next_Interp (I, It);
1495          end loop;
1496
1497          --  Error if no interpretation of the prefix has an access type
1498
1499          if Etype (N) = Any_Type then
1500             Error_Msg_N
1501               ("access type required in prefix of explicit dereference", P);
1502             Set_Etype (N, Any_Type);
1503             return;
1504          end if;
1505       end if;
1506
1507       if Is_Function_Type
1508         and then Nkind (Parent (N)) /= N_Indexed_Component
1509
1510         and then (Nkind (Parent (N)) /= N_Function_Call
1511                    or else N /= Name (Parent (N)))
1512
1513         and then (Nkind (Parent (N)) /= N_Procedure_Call_Statement
1514                    or else N /= Name (Parent (N)))
1515
1516         and then Nkind (Parent (N)) /= N_Subprogram_Renaming_Declaration
1517         and then (Nkind (Parent (N)) /= N_Attribute_Reference
1518                     or else
1519                       (Attribute_Name (Parent (N)) /= Name_Address
1520                         and then
1521                        Attribute_Name (Parent (N)) /= Name_Access))
1522       then
1523          --  Name is a function call with no actuals, in a context that
1524          --  requires deproceduring (including as an actual in an enclosing
1525          --  function or procedure call). There are some pathological cases
1526          --  where the prefix might include functions that return access to
1527          --  subprograms and others that return a regular type. Disambiguation
1528          --  of those has to take place in Resolve.
1529
1530          New_N :=
1531            Make_Function_Call (Loc,
1532            Name => Make_Explicit_Dereference (Loc, P),
1533            Parameter_Associations => New_List);
1534
1535          --  If the prefix is overloaded, remove operations that have formals,
1536          --  we know that this is a parameterless call.
1537
1538          if Is_Overloaded (P) then
1539             Get_First_Interp (P, I, It);
1540             while Present (It.Nam) loop
1541                T := It.Typ;
1542
1543                if No (First_Formal (Base_Type (Designated_Type (T)))) then
1544                   Set_Etype (P, T);
1545                else
1546                   Remove_Interp (I);
1547                end if;
1548
1549                Get_Next_Interp (I, It);
1550             end loop;
1551          end if;
1552
1553          Rewrite (N, New_N);
1554          Analyze (N);
1555
1556       elsif not Is_Function_Type
1557         and then Is_Overloaded (N)
1558       then
1559          --  The prefix may include access to subprograms and other access
1560          --  types. If the context selects the interpretation that is a
1561          --  function call (not a procedure call) we cannot rewrite the node
1562          --  yet, but we include the result of the call interpretation.
1563
1564          Get_First_Interp (N, I, It);
1565          while Present (It.Nam) loop
1566             if Ekind (Base_Type (It.Typ)) = E_Subprogram_Type
1567                and then Etype (Base_Type (It.Typ)) /= Standard_Void_Type
1568                and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1569             then
1570                Add_One_Interp (N, Etype (It.Typ), Etype (It.Typ));
1571             end if;
1572
1573             Get_Next_Interp (I, It);
1574          end loop;
1575       end if;
1576
1577       --  A value of remote access-to-class-wide must not be dereferenced
1578       --  (RM E.2.2(16)).
1579
1580       Validate_Remote_Access_To_Class_Wide_Type (N);
1581    end Analyze_Explicit_Dereference;
1582
1583    ------------------------
1584    -- Analyze_Expression --
1585    ------------------------
1586
1587    procedure Analyze_Expression (N : Node_Id) is
1588    begin
1589       Analyze (N);
1590       Check_Parameterless_Call (N);
1591    end Analyze_Expression;
1592
1593    ------------------------------------
1594    -- Analyze_Indexed_Component_Form --
1595    ------------------------------------
1596
1597    procedure Analyze_Indexed_Component_Form (N : Node_Id) is
1598       P     : constant Node_Id := Prefix (N);
1599       Exprs : constant List_Id := Expressions (N);
1600       Exp   : Node_Id;
1601       P_T   : Entity_Id;
1602       E     : Node_Id;
1603       U_N   : Entity_Id;
1604
1605       procedure Process_Function_Call;
1606       --  Prefix in indexed component form is an overloadable entity,
1607       --  so the node is a function call. Reformat it as such.
1608
1609       procedure Process_Indexed_Component;
1610       --  Prefix in indexed component form is actually an indexed component.
1611       --  This routine processes it, knowing that the prefix is already
1612       --  resolved.
1613
1614       procedure Process_Indexed_Component_Or_Slice;
1615       --  An indexed component with a single index may designate a slice if
1616       --  the index is a subtype mark. This routine disambiguates these two
1617       --  cases by resolving the prefix to see if it is a subtype mark.
1618
1619       procedure Process_Overloaded_Indexed_Component;
1620       --  If the prefix of an indexed component is overloaded, the proper
1621       --  interpretation is selected by the index types and the context.
1622
1623       ---------------------------
1624       -- Process_Function_Call --
1625       ---------------------------
1626
1627       procedure Process_Function_Call is
1628          Actual : Node_Id;
1629
1630       begin
1631          Change_Node (N, N_Function_Call);
1632          Set_Name (N, P);
1633          Set_Parameter_Associations (N, Exprs);
1634
1635          --  Analyze actuals prior to analyzing the call itself
1636
1637          Actual := First (Parameter_Associations (N));
1638          while Present (Actual) loop
1639             Analyze (Actual);
1640             Check_Parameterless_Call (Actual);
1641
1642             --  Move to next actual. Note that we use Next, not Next_Actual
1643             --  here. The reason for this is a bit subtle. If a function call
1644             --  includes named associations, the parser recognizes the node as
1645             --  a call, and it is analyzed as such. If all associations are
1646             --  positional, the parser builds an indexed_component node, and
1647             --  it is only after analysis of the prefix that the construct
1648             --  is recognized as a call, in which case Process_Function_Call
1649             --  rewrites the node and analyzes the actuals. If the list of
1650             --  actuals is malformed, the parser may leave the node as an
1651             --  indexed component (despite the presence of named associations).
1652             --  The iterator Next_Actual is equivalent to Next if the list is
1653             --  positional, but follows the normalized chain of actuals when
1654             --  named associations are present. In this case normalization has
1655             --  not taken place, and actuals remain unanalyzed, which leads to
1656             --  subsequent crashes or loops if there is an attempt to continue
1657             --  analysis of the program.
1658
1659             Next (Actual);
1660          end loop;
1661
1662          Analyze_Call (N);
1663       end Process_Function_Call;
1664
1665       -------------------------------
1666       -- Process_Indexed_Component --
1667       -------------------------------
1668
1669       procedure Process_Indexed_Component is
1670          Exp        : Node_Id;
1671          Array_Type : Entity_Id;
1672          Index      : Node_Id;
1673          Pent       : Entity_Id := Empty;
1674
1675       begin
1676          Exp := First (Exprs);
1677
1678          if Is_Overloaded (P) then
1679             Process_Overloaded_Indexed_Component;
1680
1681          else
1682             Array_Type := Etype (P);
1683
1684             if Is_Entity_Name (P) then
1685                Pent := Entity (P);
1686             elsif Nkind (P) = N_Selected_Component
1687               and then Is_Entity_Name (Selector_Name (P))
1688             then
1689                Pent := Entity (Selector_Name (P));
1690             end if;
1691
1692             --  Prefix must be appropriate for an array type, taking into
1693             --  account a possible implicit dereference.
1694
1695             if Is_Access_Type (Array_Type) then
1696                Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1697                Array_Type := Process_Implicit_Dereference_Prefix (Pent, P);
1698             end if;
1699
1700             if Is_Array_Type (Array_Type) then
1701                null;
1702
1703             elsif Present (Pent) and then Ekind (Pent) = E_Entry_Family then
1704                Analyze (Exp);
1705                Set_Etype (N, Any_Type);
1706
1707                if not Has_Compatible_Type
1708                  (Exp, Entry_Index_Type (Pent))
1709                then
1710                   Error_Msg_N ("invalid index type in entry name", N);
1711
1712                elsif Present (Next (Exp)) then
1713                   Error_Msg_N ("too many subscripts in entry reference", N);
1714
1715                else
1716                   Set_Etype (N,  Etype (P));
1717                end if;
1718
1719                return;
1720
1721             elsif Is_Record_Type (Array_Type)
1722               and then Remote_AST_I_Dereference (P)
1723             then
1724                return;
1725
1726             elsif Array_Type = Any_Type then
1727                Set_Etype (N, Any_Type);
1728
1729                --  In most cases the analysis of the prefix will have emitted
1730                --  an error already, but if the prefix may be interpreted as a
1731                --  call in prefixed notation, the report is left to the caller.
1732                --  To prevent cascaded errors, report only if no previous ones.
1733
1734                if Serious_Errors_Detected = 0 then
1735                   Error_Msg_N ("invalid prefix in indexed component", P);
1736
1737                   if Nkind (P) = N_Expanded_Name then
1738                      Error_Msg_NE ("\& is not visible", P, Selector_Name (P));
1739                   end if;
1740                end if;
1741
1742                return;
1743
1744             --  Here we definitely have a bad indexing
1745
1746             else
1747                if Nkind (Parent (N)) = N_Requeue_Statement
1748                  and then Present (Pent) and then Ekind (Pent) = E_Entry
1749                then
1750                   Error_Msg_N
1751                     ("REQUEUE does not permit parameters", First (Exprs));
1752
1753                elsif Is_Entity_Name (P)
1754                  and then Etype (P) = Standard_Void_Type
1755                then
1756                   Error_Msg_NE ("incorrect use of&", P, Entity (P));
1757
1758                else
1759                   Error_Msg_N ("array type required in indexed component", P);
1760                end if;
1761
1762                Set_Etype (N, Any_Type);
1763                return;
1764             end if;
1765
1766             Index := First_Index (Array_Type);
1767             while Present (Index) and then Present (Exp) loop
1768                if not Has_Compatible_Type (Exp, Etype (Index)) then
1769                   Wrong_Type (Exp, Etype (Index));
1770                   Set_Etype (N, Any_Type);
1771                   return;
1772                end if;
1773
1774                Next_Index (Index);
1775                Next (Exp);
1776             end loop;
1777
1778             Set_Etype (N, Component_Type (Array_Type));
1779
1780             if Present (Index) then
1781                Error_Msg_N
1782                  ("too few subscripts in array reference", First (Exprs));
1783
1784             elsif Present (Exp) then
1785                Error_Msg_N ("too many subscripts in array reference", Exp);
1786             end if;
1787          end if;
1788       end Process_Indexed_Component;
1789
1790       ----------------------------------------
1791       -- Process_Indexed_Component_Or_Slice --
1792       ----------------------------------------
1793
1794       procedure Process_Indexed_Component_Or_Slice is
1795       begin
1796          Exp := First (Exprs);
1797          while Present (Exp) loop
1798             Analyze_Expression (Exp);
1799             Next (Exp);
1800          end loop;
1801
1802          Exp := First (Exprs);
1803
1804          --  If one index is present, and it is a subtype name, then the
1805          --  node denotes a slice (note that the case of an explicit range
1806          --  for a slice was already built as an N_Slice node in the first
1807          --  place, so that case is not handled here).
1808
1809          --  We use a replace rather than a rewrite here because this is one
1810          --  of the cases in which the tree built by the parser is plain wrong.
1811
1812          if No (Next (Exp))
1813            and then Is_Entity_Name (Exp)
1814            and then Is_Type (Entity (Exp))
1815          then
1816             Replace (N,
1817                Make_Slice (Sloc (N),
1818                  Prefix => P,
1819                  Discrete_Range => New_Copy (Exp)));
1820             Analyze (N);
1821
1822          --  Otherwise (more than one index present, or single index is not
1823          --  a subtype name), then we have the indexed component case.
1824
1825          else
1826             Process_Indexed_Component;
1827          end if;
1828       end Process_Indexed_Component_Or_Slice;
1829
1830       ------------------------------------------
1831       -- Process_Overloaded_Indexed_Component --
1832       ------------------------------------------
1833
1834       procedure Process_Overloaded_Indexed_Component is
1835          Exp   : Node_Id;
1836          I     : Interp_Index;
1837          It    : Interp;
1838          Typ   : Entity_Id;
1839          Index : Node_Id;
1840          Found : Boolean;
1841
1842       begin
1843          Set_Etype (N, Any_Type);
1844
1845          Get_First_Interp (P, I, It);
1846          while Present (It.Nam) loop
1847             Typ := It.Typ;
1848
1849             if Is_Access_Type (Typ) then
1850                Typ := Designated_Type (Typ);
1851                Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
1852             end if;
1853
1854             if Is_Array_Type (Typ) then
1855
1856                --  Got a candidate: verify that index types are compatible
1857
1858                Index := First_Index (Typ);
1859                Found := True;
1860                Exp := First (Exprs);
1861                while Present (Index) and then Present (Exp) loop
1862                   if Has_Compatible_Type (Exp, Etype (Index)) then
1863                      null;
1864                   else
1865                      Found := False;
1866                      Remove_Interp (I);
1867                      exit;
1868                   end if;
1869
1870                   Next_Index (Index);
1871                   Next (Exp);
1872                end loop;
1873
1874                if Found and then No (Index) and then No (Exp) then
1875                   Add_One_Interp (N,
1876                      Etype (Component_Type (Typ)),
1877                      Etype (Component_Type (Typ)));
1878                end if;
1879             end if;
1880
1881             Get_Next_Interp (I, It);
1882          end loop;
1883
1884          if Etype (N) = Any_Type then
1885             Error_Msg_N ("no legal interpretation for indexed component", N);
1886             Set_Is_Overloaded (N, False);
1887          end if;
1888
1889          End_Interp_List;
1890       end Process_Overloaded_Indexed_Component;
1891
1892    --  Start of processing for Analyze_Indexed_Component_Form
1893
1894    begin
1895       --  Get name of array, function or type
1896
1897       Analyze (P);
1898
1899       if Nkind_In (N, N_Function_Call, N_Procedure_Call_Statement) then
1900
1901          --  If P is an explicit dereference whose prefix is of a
1902          --  remote access-to-subprogram type, then N has already
1903          --  been rewritten as a subprogram call and analyzed.
1904
1905          return;
1906       end if;
1907
1908       pragma Assert (Nkind (N) = N_Indexed_Component);
1909
1910       P_T := Base_Type (Etype (P));
1911
1912       if Is_Entity_Name (P)
1913         or else Nkind (P) = N_Operator_Symbol
1914       then
1915          U_N := Entity (P);
1916
1917          if Is_Type (U_N) then
1918
1919             --  Reformat node as a type conversion
1920
1921             E := Remove_Head (Exprs);
1922
1923             if Present (First (Exprs)) then
1924                Error_Msg_N
1925                 ("argument of type conversion must be single expression", N);
1926             end if;
1927
1928             Change_Node (N, N_Type_Conversion);
1929             Set_Subtype_Mark (N, P);
1930             Set_Etype (N, U_N);
1931             Set_Expression (N, E);
1932
1933             --  After changing the node, call for the specific Analysis
1934             --  routine directly, to avoid a double call to the expander.
1935
1936             Analyze_Type_Conversion (N);
1937             return;
1938          end if;
1939
1940          if Is_Overloadable (U_N) then
1941             Process_Function_Call;
1942
1943          elsif Ekind (Etype (P)) = E_Subprogram_Type
1944            or else (Is_Access_Type (Etype (P))
1945                       and then
1946                         Ekind (Designated_Type (Etype (P))) =
1947                                                    E_Subprogram_Type)
1948          then
1949             --  Call to access_to-subprogram with possible implicit dereference
1950
1951             Process_Function_Call;
1952
1953          elsif Is_Generic_Subprogram (U_N) then
1954
1955             --  A common beginner's (or C++ templates fan) error
1956
1957             Error_Msg_N ("generic subprogram cannot be called", N);
1958             Set_Etype (N, Any_Type);
1959             return;
1960
1961          else
1962             Process_Indexed_Component_Or_Slice;
1963          end if;
1964
1965       --  If not an entity name, prefix is an expression that may denote
1966       --  an array or an access-to-subprogram.
1967
1968       else
1969          if Ekind (P_T) = E_Subprogram_Type
1970            or else (Is_Access_Type (P_T)
1971                      and then
1972                        Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
1973          then
1974             Process_Function_Call;
1975
1976          elsif Nkind (P) = N_Selected_Component
1977            and then Is_Overloadable (Entity (Selector_Name (P)))
1978          then
1979             Process_Function_Call;
1980
1981          else
1982             --  Indexed component, slice, or a call to a member of a family
1983             --  entry, which will be converted to an entry call later.
1984
1985             Process_Indexed_Component_Or_Slice;
1986          end if;
1987       end if;
1988    end Analyze_Indexed_Component_Form;
1989
1990    ------------------------
1991    -- Analyze_Logical_Op --
1992    ------------------------
1993
1994    procedure Analyze_Logical_Op (N : Node_Id) is
1995       L     : constant Node_Id := Left_Opnd (N);
1996       R     : constant Node_Id := Right_Opnd (N);
1997       Op_Id : Entity_Id := Entity (N);
1998
1999    begin
2000       Set_Etype (N, Any_Type);
2001       Candidate_Type := Empty;
2002
2003       Analyze_Expression (L);
2004       Analyze_Expression (R);
2005
2006       if Present (Op_Id) then
2007
2008          if Ekind (Op_Id) = E_Operator then
2009             Find_Boolean_Types (L, R, Op_Id, N);
2010          else
2011             Add_One_Interp (N, Op_Id, Etype (Op_Id));
2012          end if;
2013
2014       else
2015          Op_Id := Get_Name_Entity_Id (Chars (N));
2016          while Present (Op_Id) loop
2017             if Ekind (Op_Id) = E_Operator then
2018                Find_Boolean_Types (L, R, Op_Id, N);
2019             else
2020                Analyze_User_Defined_Binary_Op (N, Op_Id);
2021             end if;
2022
2023             Op_Id := Homonym (Op_Id);
2024          end loop;
2025       end if;
2026
2027       Operator_Check (N);
2028    end Analyze_Logical_Op;
2029
2030    ---------------------------
2031    -- Analyze_Membership_Op --
2032    ---------------------------
2033
2034    procedure Analyze_Membership_Op (N : Node_Id) is
2035       L     : constant Node_Id := Left_Opnd (N);
2036       R     : constant Node_Id := Right_Opnd (N);
2037
2038       Index : Interp_Index;
2039       It    : Interp;
2040       Found : Boolean := False;
2041       I_F   : Interp_Index;
2042       T_F   : Entity_Id;
2043
2044       procedure Try_One_Interp (T1 : Entity_Id);
2045       --  Routine to try one proposed interpretation. Note that the context
2046       --  of the operation plays no role in resolving the arguments, so that
2047       --  if there is more than one interpretation of the operands that is
2048       --  compatible with a membership test, the operation is ambiguous.
2049
2050       --------------------
2051       -- Try_One_Interp --
2052       --------------------
2053
2054       procedure Try_One_Interp (T1 : Entity_Id) is
2055       begin
2056          if Has_Compatible_Type (R, T1) then
2057             if Found
2058               and then Base_Type (T1) /= Base_Type (T_F)
2059             then
2060                It := Disambiguate (L, I_F, Index, Any_Type);
2061
2062                if It = No_Interp then
2063                   Ambiguous_Operands (N);
2064                   Set_Etype (L, Any_Type);
2065                   return;
2066
2067                else
2068                   T_F := It.Typ;
2069                end if;
2070
2071             else
2072                Found := True;
2073                T_F   := T1;
2074                I_F   := Index;
2075             end if;
2076
2077             Set_Etype (L, T_F);
2078          end if;
2079       end Try_One_Interp;
2080
2081       procedure Analyze_Set_Membership;
2082       --  If a set of alternatives is present, analyze each and find the
2083       --  common type to which they must all resolve.
2084
2085       ----------------------------
2086       -- Analyze_Set_Membership --
2087       ----------------------------
2088
2089       procedure Analyze_Set_Membership is
2090          Alt               : Node_Id;
2091          Index             : Interp_Index;
2092          It                : Interp;
2093          Candidate_Interps : Node_Id;
2094          Common_Type       : Entity_Id := Empty;
2095
2096       begin
2097          Analyze (L);
2098          Candidate_Interps := L;
2099
2100          if not Is_Overloaded (L) then
2101             Common_Type := Etype (L);
2102
2103             Alt := First (Alternatives (N));
2104             while Present (Alt) loop
2105                Analyze (Alt);
2106
2107                if not Has_Compatible_Type (Alt, Common_Type) then
2108                   Wrong_Type (Alt, Common_Type);
2109                end if;
2110
2111                Next (Alt);
2112             end loop;
2113
2114          else
2115             Alt := First (Alternatives (N));
2116             while Present (Alt) loop
2117                Analyze (Alt);
2118                if not Is_Overloaded (Alt) then
2119                   Common_Type := Etype (Alt);
2120
2121                else
2122                   Get_First_Interp (Alt, Index, It);
2123                   while Present (It.Typ) loop
2124                      if not
2125                        Has_Compatible_Type (Candidate_Interps, It.Typ)
2126                      then
2127                         Remove_Interp (Index);
2128                      end if;
2129
2130                      Get_Next_Interp (Index, It);
2131                   end loop;
2132
2133                   Get_First_Interp (Alt, Index, It);
2134
2135                   if No (It.Typ) then
2136                      Error_Msg_N ("alternative has no legal type", Alt);
2137                      return;
2138                   end if;
2139
2140                   --  If alternative is not overloaded, we have a unique type
2141                   --  for all of them.
2142
2143                   Set_Etype (Alt, It.Typ);
2144                   Get_Next_Interp (Index, It);
2145
2146                   if No (It.Typ) then
2147                      Set_Is_Overloaded (Alt, False);
2148                      Common_Type := Etype (Alt);
2149                   end if;
2150
2151                   Candidate_Interps := Alt;
2152                end if;
2153
2154                Next (Alt);
2155             end loop;
2156          end if;
2157
2158          Set_Etype (N, Standard_Boolean);
2159
2160          if Present (Common_Type) then
2161             Set_Etype (L, Common_Type);
2162             Set_Is_Overloaded (L, False);
2163
2164          else
2165             Error_Msg_N ("cannot resolve membership operation", N);
2166          end if;
2167       end Analyze_Set_Membership;
2168
2169    --  Start of processing for Analyze_Membership_Op
2170
2171    begin
2172       Analyze_Expression (L);
2173
2174       if No (R)
2175         and then Extensions_Allowed
2176       then
2177          Analyze_Set_Membership;
2178          return;
2179       end if;
2180
2181       if Nkind (R) = N_Range
2182         or else (Nkind (R) = N_Attribute_Reference
2183                   and then Attribute_Name (R) = Name_Range)
2184       then
2185          Analyze (R);
2186
2187          if not Is_Overloaded (L) then
2188             Try_One_Interp (Etype (L));
2189
2190          else
2191             Get_First_Interp (L, Index, It);
2192             while Present (It.Typ) loop
2193                Try_One_Interp (It.Typ);
2194                Get_Next_Interp (Index, It);
2195             end loop;
2196          end if;
2197
2198       --  If not a range, it can only be a subtype mark, or else there
2199       --  is a more basic error, to be diagnosed in Find_Type.
2200
2201       else
2202          Find_Type (R);
2203
2204          if Is_Entity_Name (R) then
2205             Check_Fully_Declared (Entity (R), R);
2206          end if;
2207       end if;
2208
2209       --  Compatibility between expression and subtype mark or range is
2210       --  checked during resolution. The result of the operation is Boolean
2211       --  in any case.
2212
2213       Set_Etype (N, Standard_Boolean);
2214
2215       if Comes_From_Source (N)
2216         and then Present (Right_Opnd (N))
2217         and then Is_CPP_Class (Etype (Etype (Right_Opnd (N))))
2218       then
2219          Error_Msg_N ("membership test not applicable to cpp-class types", N);
2220       end if;
2221    end Analyze_Membership_Op;
2222
2223    ----------------------
2224    -- Analyze_Negation --
2225    ----------------------
2226
2227    procedure Analyze_Negation (N : Node_Id) is
2228       R     : constant Node_Id := Right_Opnd (N);
2229       Op_Id : Entity_Id := Entity (N);
2230
2231    begin
2232       Set_Etype (N, Any_Type);
2233       Candidate_Type := Empty;
2234
2235       Analyze_Expression (R);
2236
2237       if Present (Op_Id) then
2238          if Ekind (Op_Id) = E_Operator then
2239             Find_Negation_Types (R, Op_Id, N);
2240          else
2241             Add_One_Interp (N, Op_Id, Etype (Op_Id));
2242          end if;
2243
2244       else
2245          Op_Id := Get_Name_Entity_Id (Chars (N));
2246          while Present (Op_Id) loop
2247             if Ekind (Op_Id) = E_Operator then
2248                Find_Negation_Types (R, Op_Id, N);
2249             else
2250                Analyze_User_Defined_Unary_Op (N, Op_Id);
2251             end if;
2252
2253             Op_Id := Homonym (Op_Id);
2254          end loop;
2255       end if;
2256
2257       Operator_Check (N);
2258    end Analyze_Negation;
2259
2260    ------------------
2261    -- Analyze_Null --
2262    ------------------
2263
2264    procedure Analyze_Null (N : Node_Id) is
2265    begin
2266       Set_Etype (N, Any_Access);
2267    end Analyze_Null;
2268
2269    ----------------------
2270    -- Analyze_One_Call --
2271    ----------------------
2272
2273    procedure Analyze_One_Call
2274       (N          : Node_Id;
2275        Nam        : Entity_Id;
2276        Report     : Boolean;
2277        Success    : out Boolean;
2278        Skip_First : Boolean := False)
2279    is
2280       Actuals : constant List_Id   := Parameter_Associations (N);
2281       Prev_T  : constant Entity_Id := Etype (N);
2282
2283       Must_Skip  : constant Boolean := Skip_First
2284                      or else Nkind (Original_Node (N)) = N_Selected_Component
2285                      or else
2286                        (Nkind (Original_Node (N)) = N_Indexed_Component
2287                           and then Nkind (Prefix (Original_Node (N)))
2288                             = N_Selected_Component);
2289       --  The first formal must be omitted from the match when trying to find
2290       --  a primitive operation that is a possible interpretation, and also
2291       --  after the call has been rewritten, because the corresponding actual
2292       --  is already known to be compatible, and because this may be an
2293       --  indexing of a call with default parameters.
2294
2295       Formal      : Entity_Id;
2296       Actual      : Node_Id;
2297       Is_Indexed  : Boolean := False;
2298       Is_Indirect : Boolean := False;
2299       Subp_Type   : constant Entity_Id := Etype (Nam);
2300       Norm_OK     : Boolean;
2301
2302       function Operator_Hidden_By (Fun : Entity_Id) return Boolean;
2303       --  There may be a user-defined operator that hides the current
2304       --  interpretation. We must check for this independently of the
2305       --  analysis of the call with the user-defined operation, because
2306       --  the parameter names may be wrong and yet the hiding takes place.
2307       --  This fixes a problem with ACATS test B34014O.
2308       --
2309       --  When the type Address is a visible integer type, and the DEC
2310       --  system extension is visible, the predefined operator may be
2311       --  hidden as well, by one of the address operations in auxdec.
2312       --  Finally, The abstract operations on address do not hide the
2313       --  predefined operator (this is the purpose of making them abstract).
2314
2315       procedure Indicate_Name_And_Type;
2316       --  If candidate interpretation matches, indicate name and type of
2317       --  result on call node.
2318
2319       ----------------------------
2320       -- Indicate_Name_And_Type --
2321       ----------------------------
2322
2323       procedure Indicate_Name_And_Type is
2324       begin
2325          Add_One_Interp (N, Nam, Etype (Nam));
2326          Success := True;
2327
2328          --  If the prefix of the call is a name, indicate the entity
2329          --  being called. If it is not a name,  it is an expression that
2330          --  denotes an access to subprogram or else an entry or family. In
2331          --  the latter case, the name is a selected component, and the entity
2332          --  being called is noted on the selector.
2333
2334          if not Is_Type (Nam) then
2335             if Is_Entity_Name (Name (N))
2336               or else Nkind (Name (N)) = N_Operator_Symbol
2337             then
2338                Set_Entity (Name (N), Nam);
2339
2340             elsif Nkind (Name (N)) = N_Selected_Component then
2341                Set_Entity (Selector_Name (Name (N)),  Nam);
2342             end if;
2343          end if;
2344
2345          if Debug_Flag_E and not Report then
2346             Write_Str (" Overloaded call ");
2347             Write_Int (Int (N));
2348             Write_Str (" compatible with ");
2349             Write_Int (Int (Nam));
2350             Write_Eol;
2351          end if;
2352       end Indicate_Name_And_Type;
2353
2354       ------------------------
2355       -- Operator_Hidden_By --
2356       ------------------------
2357
2358       function Operator_Hidden_By (Fun : Entity_Id) return Boolean is
2359          Act1  : constant Node_Id   := First_Actual (N);
2360          Act2  : constant Node_Id   := Next_Actual (Act1);
2361          Form1 : constant Entity_Id := First_Formal (Fun);
2362          Form2 : constant Entity_Id := Next_Formal (Form1);
2363
2364       begin
2365          if Ekind (Fun) /= E_Function
2366            or else Is_Abstract_Subprogram (Fun)
2367          then
2368             return False;
2369
2370          elsif not Has_Compatible_Type (Act1, Etype (Form1)) then
2371             return False;
2372
2373          elsif Present (Form2) then
2374             if
2375               No (Act2) or else not Has_Compatible_Type (Act2, Etype (Form2))
2376             then
2377                return False;
2378             end if;
2379
2380          elsif Present (Act2) then
2381             return False;
2382          end if;
2383
2384          --  Now we know that the arity of the operator matches the function,
2385          --  and the function call is a valid interpretation. The function
2386          --  hides the operator if it has the right signature, or if one of
2387          --  its operands is a non-abstract operation on Address when this is
2388          --  a visible integer type.
2389
2390          return Hides_Op (Fun, Nam)
2391            or else Is_Descendent_Of_Address (Etype (Form1))
2392            or else
2393              (Present (Form2)
2394                and then Is_Descendent_Of_Address (Etype (Form2)));
2395       end Operator_Hidden_By;
2396
2397    --  Start of processing for Analyze_One_Call
2398
2399    begin
2400       Success := False;
2401
2402       --  If the subprogram has no formals or if all the formals have defaults,
2403       --  and the return type is an array type, the node may denote an indexing
2404       --  of the result of a parameterless call. In Ada 2005, the subprogram
2405       --  may have one non-defaulted formal, and the call may have been written
2406       --  in prefix notation, so that the rebuilt parameter list has more than
2407       --  one actual.
2408
2409       if not Is_Overloadable (Nam)
2410         and then Ekind (Nam) /= E_Subprogram_Type
2411         and then Ekind (Nam) /= E_Entry_Family
2412       then
2413          return;
2414       end if;
2415
2416       --  An indexing requires at least one actual
2417
2418       if not Is_Empty_List (Actuals)
2419         and then
2420           (Needs_No_Actuals (Nam)
2421             or else
2422               (Needs_One_Actual (Nam)
2423                  and then Present (Next_Actual (First (Actuals)))))
2424       then
2425          if Is_Array_Type (Subp_Type) then
2426             Is_Indexed := Try_Indexed_Call (N, Nam, Subp_Type, Must_Skip);
2427
2428          elsif Is_Access_Type (Subp_Type)
2429            and then Is_Array_Type (Designated_Type (Subp_Type))
2430          then
2431             Is_Indexed :=
2432               Try_Indexed_Call
2433                 (N, Nam, Designated_Type (Subp_Type), Must_Skip);
2434
2435          --  The prefix can also be a parameterless function that returns an
2436          --  access to subprogram, in which case this is an indirect call.
2437          --  If this succeeds, an explicit dereference is added later on,
2438          --  in Analyze_Call or Resolve_Call.
2439
2440          elsif Is_Access_Type (Subp_Type)
2441            and then Ekind (Designated_Type (Subp_Type)) = E_Subprogram_Type
2442          then
2443             Is_Indirect := Try_Indirect_Call (N, Nam, Subp_Type);
2444          end if;
2445
2446       end if;
2447
2448       --  If the call has been transformed into a slice, it is of the form
2449       --  F (Subtype) where F is parameterless. The node has been rewritten in
2450       --  Try_Indexed_Call and there is nothing else to do.
2451
2452       if Is_Indexed
2453         and then  Nkind (N) = N_Slice
2454       then
2455          return;
2456       end if;
2457
2458       Normalize_Actuals
2459         (N, Nam, (Report and not Is_Indexed and not Is_Indirect), Norm_OK);
2460
2461       if not Norm_OK then
2462
2463          --  If an indirect call is a possible interpretation, indicate
2464          --  success to the caller.
2465
2466          if Is_Indirect then
2467             Success := True;
2468             return;
2469
2470          --  Mismatch in number or names of parameters
2471
2472          elsif Debug_Flag_E then
2473             Write_Str (" normalization fails in call ");
2474             Write_Int (Int (N));
2475             Write_Str (" with subprogram ");
2476             Write_Int (Int (Nam));
2477             Write_Eol;
2478          end if;
2479
2480       --  If the context expects a function call, discard any interpretation
2481       --  that is a procedure. If the node is not overloaded, leave as is for
2482       --  better error reporting when type mismatch is found.
2483
2484       elsif Nkind (N) = N_Function_Call
2485         and then Is_Overloaded (Name (N))
2486         and then Ekind (Nam) = E_Procedure
2487       then
2488          return;
2489
2490       --  Ditto for function calls in a procedure context
2491
2492       elsif Nkind (N) = N_Procedure_Call_Statement
2493          and then Is_Overloaded (Name (N))
2494          and then Etype (Nam) /= Standard_Void_Type
2495       then
2496          return;
2497
2498       elsif No (Actuals) then
2499
2500          --  If Normalize succeeds, then there are default parameters for
2501          --  all formals.
2502
2503          Indicate_Name_And_Type;
2504
2505       elsif Ekind (Nam) = E_Operator then
2506          if Nkind (N) = N_Procedure_Call_Statement then
2507             return;
2508          end if;
2509
2510          --  This can occur when the prefix of the call is an operator
2511          --  name or an expanded name whose selector is an operator name.
2512
2513          Analyze_Operator_Call (N, Nam);
2514
2515          if Etype (N) /= Prev_T then
2516
2517             --  Check that operator is not hidden by a function interpretation
2518
2519             if Is_Overloaded (Name (N)) then
2520                declare
2521                   I  : Interp_Index;
2522                   It : Interp;
2523
2524                begin
2525                   Get_First_Interp (Name (N), I, It);
2526                   while Present (It.Nam) loop
2527                      if Operator_Hidden_By (It.Nam) then
2528                         Set_Etype (N, Prev_T);
2529                         return;
2530                      end if;
2531
2532                      Get_Next_Interp (I, It);
2533                   end loop;
2534                end;
2535             end if;
2536
2537             --  If operator matches formals, record its name on the call.
2538             --  If the operator is overloaded, Resolve will select the
2539             --  correct one from the list of interpretations. The call
2540             --  node itself carries the first candidate.
2541
2542             Set_Entity (Name (N), Nam);
2543             Success := True;
2544
2545          elsif Report and then Etype (N) = Any_Type then
2546             Error_Msg_N ("incompatible arguments for operator", N);
2547          end if;
2548
2549       else
2550          --  Normalize_Actuals has chained the named associations in the
2551          --  correct order of the formals.
2552
2553          Actual := First_Actual (N);
2554          Formal := First_Formal (Nam);
2555
2556          --  If we are analyzing a call rewritten from object notation,
2557          --  skip first actual, which may be rewritten later as an
2558          --  explicit dereference.
2559
2560          if Must_Skip then
2561             Next_Actual (Actual);
2562             Next_Formal (Formal);
2563          end if;
2564
2565          while Present (Actual) and then Present (Formal) loop
2566             if Nkind (Parent (Actual)) /= N_Parameter_Association
2567               or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
2568             then
2569                --  The actual can be compatible with the formal, but we must
2570                --  also check that the context is not an address type that is
2571                --  visibly an integer type, as is the case in VMS_64. In this
2572                --  case the use of literals is illegal, except in the body of
2573                --  descendents of system, where arithmetic operations on
2574                --  address are of course used.
2575
2576                if Has_Compatible_Type (Actual, Etype (Formal))
2577                  and then
2578                   (Etype (Actual) /= Universal_Integer
2579                     or else not Is_Descendent_Of_Address (Etype (Formal))
2580                     or else
2581                       Is_Predefined_File_Name
2582                         (Unit_File_Name (Get_Source_Unit (N))))
2583                then
2584                   Next_Actual (Actual);
2585                   Next_Formal (Formal);
2586
2587                else
2588                   if Debug_Flag_E then
2589                      Write_Str (" type checking fails in call ");
2590                      Write_Int (Int (N));
2591                      Write_Str (" with formal ");
2592                      Write_Int (Int (Formal));
2593                      Write_Str (" in subprogram ");
2594                      Write_Int (Int (Nam));
2595                      Write_Eol;
2596                   end if;
2597
2598                   if Report and not Is_Indexed and not Is_Indirect then
2599
2600                      --  Ada 2005 (AI-251): Complete the error notification
2601                      --  to help new Ada 2005 users.
2602
2603                      if Is_Class_Wide_Type (Etype (Formal))
2604                        and then Is_Interface (Etype (Etype (Formal)))
2605                        and then not Interface_Present_In_Ancestor
2606                                       (Typ   => Etype (Actual),
2607                                        Iface => Etype (Etype (Formal)))
2608                      then
2609                         Error_Msg_NE
2610                           ("(Ada 2005) does not implement interface }",
2611                            Actual, Etype (Etype (Formal)));
2612                      end if;
2613
2614                      Wrong_Type (Actual, Etype (Formal));
2615
2616                      if Nkind (Actual) = N_Op_Eq
2617                        and then Nkind (Left_Opnd (Actual)) = N_Identifier
2618                      then
2619                         Formal := First_Formal (Nam);
2620                         while Present (Formal) loop
2621                            if Chars (Left_Opnd (Actual)) = Chars (Formal) then
2622                               Error_Msg_N -- CODEFIX
2623                                 ("possible misspelling of `='>`!", Actual);
2624                               exit;
2625                            end if;
2626
2627                            Next_Formal (Formal);
2628                         end loop;
2629                      end if;
2630
2631                      if All_Errors_Mode then
2632                         Error_Msg_Sloc := Sloc (Nam);
2633
2634                         if Is_Overloadable (Nam)
2635                           and then Present (Alias (Nam))
2636                           and then not Comes_From_Source (Nam)
2637                         then
2638                            Error_Msg_NE
2639                              ("\\  =='> in call to inherited operation & #!",
2640                               Actual, Nam);
2641
2642                         elsif Ekind (Nam) = E_Subprogram_Type then
2643                            declare
2644                               Access_To_Subprogram_Typ :
2645                                 constant Entity_Id :=
2646                                   Defining_Identifier
2647                                     (Associated_Node_For_Itype (Nam));
2648                            begin
2649                               Error_Msg_NE (
2650                                 "\\  =='> in call to dereference of &#!",
2651                                 Actual, Access_To_Subprogram_Typ);
2652                            end;
2653
2654                         else
2655                            Error_Msg_NE
2656                              ("\\  =='> in call to &#!", Actual, Nam);
2657
2658                         end if;
2659                      end if;
2660                   end if;
2661
2662                   return;
2663                end if;
2664
2665             else
2666                --  Normalize_Actuals has verified that a default value exists
2667                --  for this formal. Current actual names a subsequent formal.
2668
2669                Next_Formal (Formal);
2670             end if;
2671          end loop;
2672
2673          --  On exit, all actuals match
2674
2675          Indicate_Name_And_Type;
2676       end if;
2677    end Analyze_One_Call;
2678
2679    ---------------------------
2680    -- Analyze_Operator_Call --
2681    ---------------------------
2682
2683    procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
2684       Op_Name : constant Name_Id := Chars (Op_Id);
2685       Act1    : constant Node_Id := First_Actual (N);
2686       Act2    : constant Node_Id := Next_Actual (Act1);
2687
2688    begin
2689       --  Binary operator case
2690
2691       if Present (Act2) then
2692
2693          --  If more than two operands, then not binary operator after all
2694
2695          if Present (Next_Actual (Act2)) then
2696             return;
2697
2698          elsif     Op_Name = Name_Op_Add
2699            or else Op_Name = Name_Op_Subtract
2700            or else Op_Name = Name_Op_Multiply
2701            or else Op_Name = Name_Op_Divide
2702            or else Op_Name = Name_Op_Mod
2703            or else Op_Name = Name_Op_Rem
2704            or else Op_Name = Name_Op_Expon
2705          then
2706             Find_Arithmetic_Types (Act1, Act2, Op_Id, N);
2707
2708          elsif     Op_Name =  Name_Op_And
2709            or else Op_Name = Name_Op_Or
2710            or else Op_Name = Name_Op_Xor
2711          then
2712             Find_Boolean_Types (Act1, Act2, Op_Id, N);
2713
2714          elsif     Op_Name = Name_Op_Lt
2715            or else Op_Name = Name_Op_Le
2716            or else Op_Name = Name_Op_Gt
2717            or else Op_Name = Name_Op_Ge
2718          then
2719             Find_Comparison_Types (Act1, Act2, Op_Id,  N);
2720
2721          elsif     Op_Name = Name_Op_Eq
2722            or else Op_Name = Name_Op_Ne
2723          then
2724             Find_Equality_Types (Act1, Act2, Op_Id,  N);
2725
2726          elsif     Op_Name = Name_Op_Concat then
2727             Find_Concatenation_Types (Act1, Act2, Op_Id, N);
2728
2729          --  Is this else null correct, or should it be an abort???
2730
2731          else
2732             null;
2733          end if;
2734
2735       --  Unary operator case
2736
2737       else
2738          if Op_Name = Name_Op_Subtract or else
2739             Op_Name = Name_Op_Add      or else
2740             Op_Name = Name_Op_Abs
2741          then
2742             Find_Unary_Types (Act1, Op_Id, N);
2743
2744          elsif
2745             Op_Name = Name_Op_Not
2746          then
2747             Find_Negation_Types (Act1, Op_Id, N);
2748
2749          --  Is this else null correct, or should it be an abort???
2750
2751          else
2752             null;
2753          end if;
2754       end if;
2755    end Analyze_Operator_Call;
2756
2757    -------------------------------------------
2758    -- Analyze_Overloaded_Selected_Component --
2759    -------------------------------------------
2760
2761    procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
2762       Nam   : constant Node_Id := Prefix (N);
2763       Sel   : constant Node_Id := Selector_Name (N);
2764       Comp  : Entity_Id;
2765       I     : Interp_Index;
2766       It    : Interp;
2767       T     : Entity_Id;
2768
2769    begin
2770       Set_Etype (Sel, Any_Type);
2771
2772       Get_First_Interp (Nam, I, It);
2773       while Present (It.Typ) loop
2774          if Is_Access_Type (It.Typ) then
2775             T := Designated_Type (It.Typ);
2776             Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
2777          else
2778             T := It.Typ;
2779          end if;
2780
2781          if Is_Record_Type (T) then
2782
2783             --  If the prefix is a class-wide type, the visible components are
2784             --  those of the base type.
2785
2786             if Is_Class_Wide_Type (T) then
2787                T := Etype (T);
2788             end if;
2789
2790             Comp := First_Entity (T);
2791             while Present (Comp) loop
2792                if Chars (Comp) = Chars (Sel)
2793                  and then Is_Visible_Component (Comp)
2794                then
2795
2796                   --  AI05-105:  if the context is an object renaming with
2797                   --  an anonymous access type, the expected type of the
2798                   --  object must be anonymous. This is a name resolution rule.
2799
2800                   if Nkind (Parent (N)) /= N_Object_Renaming_Declaration
2801                     or else No (Access_Definition (Parent (N)))
2802                     or else Ekind (Etype (Comp)) = E_Anonymous_Access_Type
2803                     or else
2804                       Ekind (Etype (Comp)) = E_Anonymous_Access_Subprogram_Type
2805                   then
2806                      Set_Entity (Sel, Comp);
2807                      Set_Etype (Sel, Etype (Comp));
2808                      Add_One_Interp (N, Etype (Comp), Etype (Comp));
2809
2810                      --  This also specifies a candidate to resolve the name.
2811                      --  Further overloading will be resolved from context.
2812                      --  The selector name itself does not carry overloading
2813                      --  information.
2814
2815                      Set_Etype (Nam, It.Typ);
2816
2817                   else
2818                      --  Named access type in the context of a renaming
2819                      --  declaration with an access definition. Remove
2820                      --  inapplicable candidate.
2821
2822                      Remove_Interp (I);
2823                   end if;
2824                end if;
2825
2826                Next_Entity (Comp);
2827             end loop;
2828
2829          elsif Is_Concurrent_Type (T) then
2830             Comp := First_Entity (T);
2831             while Present (Comp)
2832               and then Comp /= First_Private_Entity (T)
2833             loop
2834                if Chars (Comp) = Chars (Sel) then
2835                   if Is_Overloadable (Comp) then
2836                      Add_One_Interp (Sel, Comp, Etype (Comp));
2837                   else
2838                      Set_Entity_With_Style_Check (Sel, Comp);
2839                      Generate_Reference (Comp, Sel);
2840                   end if;
2841
2842                   Set_Etype (Sel, Etype (Comp));
2843                   Set_Etype (N,   Etype (Comp));
2844                   Set_Etype (Nam, It.Typ);
2845
2846                   --  For access type case, introduce explicit dereference for
2847                   --  more uniform treatment of entry calls. Do this only once
2848                   --  if several interpretations yield an access type.
2849
2850                   if Is_Access_Type (Etype (Nam))
2851                     and then Nkind (Nam) /= N_Explicit_Dereference
2852                   then
2853                      Insert_Explicit_Dereference (Nam);
2854                      Error_Msg_NW
2855                        (Warn_On_Dereference, "?implicit dereference", N);
2856                   end if;
2857                end if;
2858
2859                Next_Entity (Comp);
2860             end loop;
2861
2862             Set_Is_Overloaded (N, Is_Overloaded (Sel));
2863          end if;
2864
2865          Get_Next_Interp (I, It);
2866       end loop;
2867
2868       if Etype (N) = Any_Type
2869         and then not Try_Object_Operation (N)
2870       then
2871          Error_Msg_NE ("undefined selector& for overloaded prefix", N, Sel);
2872          Set_Entity (Sel, Any_Id);
2873          Set_Etype  (Sel, Any_Type);
2874       end if;
2875    end Analyze_Overloaded_Selected_Component;
2876
2877    ----------------------------------
2878    -- Analyze_Qualified_Expression --
2879    ----------------------------------
2880
2881    procedure Analyze_Qualified_Expression (N : Node_Id) is
2882       Mark : constant Entity_Id := Subtype_Mark (N);
2883       Expr : constant Node_Id   := Expression (N);
2884       I    : Interp_Index;
2885       It   : Interp;
2886       T    : Entity_Id;
2887
2888    begin
2889       Analyze_Expression (Expr);
2890
2891       Set_Etype (N, Any_Type);
2892       Find_Type (Mark);
2893       T := Entity (Mark);
2894       Set_Etype (N, T);
2895
2896       if T = Any_Type then
2897          return;
2898       end if;
2899
2900       Check_Fully_Declared (T, N);
2901
2902       --  If expected type is class-wide, check for exact match before
2903       --  expansion, because if the expression is a dispatching call it
2904       --  may be rewritten as explicit dereference with class-wide result.
2905       --  If expression is overloaded, retain only interpretations that
2906       --  will yield exact matches.
2907
2908       if Is_Class_Wide_Type (T) then
2909          if not Is_Overloaded (Expr) then
2910             if  Base_Type (Etype (Expr)) /= Base_Type (T) then
2911                if Nkind (Expr) = N_Aggregate then
2912                   Error_Msg_N ("type of aggregate cannot be class-wide", Expr);
2913                else
2914                   Wrong_Type (Expr, T);
2915                end if;
2916             end if;
2917
2918          else
2919             Get_First_Interp (Expr, I, It);
2920
2921             while Present (It.Nam) loop
2922                if Base_Type (It.Typ) /= Base_Type (T) then
2923                   Remove_Interp (I);
2924                end if;
2925
2926                Get_Next_Interp (I, It);
2927             end loop;
2928          end if;
2929       end if;
2930
2931       Set_Etype  (N, T);
2932    end Analyze_Qualified_Expression;
2933
2934    -------------------
2935    -- Analyze_Range --
2936    -------------------
2937
2938    procedure Analyze_Range (N : Node_Id) is
2939       L        : constant Node_Id := Low_Bound (N);
2940       H        : constant Node_Id := High_Bound (N);
2941       I1, I2   : Interp_Index;
2942       It1, It2 : Interp;
2943
2944       procedure Check_Common_Type (T1, T2 : Entity_Id);
2945       --  Verify the compatibility of two types,  and choose the
2946       --  non universal one if the other is universal.
2947
2948       procedure Check_High_Bound (T : Entity_Id);
2949       --  Test one interpretation of the low bound against all those
2950       --  of the high bound.
2951
2952       procedure Check_Universal_Expression (N : Node_Id);
2953       --  In Ada83, reject bounds of a universal range that are not
2954       --  literals or entity names.
2955
2956       -----------------------
2957       -- Check_Common_Type --
2958       -----------------------
2959
2960       procedure Check_Common_Type (T1, T2 : Entity_Id) is
2961       begin
2962          if Covers (T1 => T1, T2 => T2)
2963               or else
2964             Covers (T1 => T2, T2 => T1)
2965          then
2966             if T1 = Universal_Integer
2967               or else T1 = Universal_Real
2968               or else T1 = Any_Character
2969             then
2970                Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
2971
2972             elsif T1 = T2 then
2973                Add_One_Interp (N, T1, T1);
2974
2975             else
2976                Add_One_Interp (N, Base_Type (T1), Base_Type (T1));
2977             end if;
2978          end if;
2979       end Check_Common_Type;
2980
2981       ----------------------
2982       -- Check_High_Bound --
2983       ----------------------
2984
2985       procedure Check_High_Bound (T : Entity_Id) is
2986       begin
2987          if not Is_Overloaded (H) then
2988             Check_Common_Type (T, Etype (H));
2989          else
2990             Get_First_Interp (H, I2, It2);
2991             while Present (It2.Typ) loop
2992                Check_Common_Type (T, It2.Typ);
2993                Get_Next_Interp (I2, It2);
2994             end loop;
2995          end if;
2996       end Check_High_Bound;
2997
2998       -----------------------------
2999       -- Is_Universal_Expression --
3000       -----------------------------
3001
3002       procedure Check_Universal_Expression (N : Node_Id) is
3003       begin
3004          if Etype (N) = Universal_Integer
3005            and then Nkind (N) /= N_Integer_Literal
3006            and then not Is_Entity_Name (N)
3007            and then Nkind (N) /= N_Attribute_Reference
3008          then
3009             Error_Msg_N ("illegal bound in discrete range", N);
3010          end if;
3011       end Check_Universal_Expression;
3012
3013    --  Start of processing for Analyze_Range
3014
3015    begin
3016       Set_Etype (N, Any_Type);
3017       Analyze_Expression (L);
3018       Analyze_Expression (H);
3019
3020       if Etype (L) = Any_Type or else Etype (H) = Any_Type then
3021          return;
3022
3023       else
3024          if not Is_Overloaded (L) then
3025             Check_High_Bound (Etype (L));
3026          else
3027             Get_First_Interp (L, I1, It1);
3028             while Present (It1.Typ) loop
3029                Check_High_Bound (It1.Typ);
3030                Get_Next_Interp (I1, It1);
3031             end loop;
3032          end if;
3033
3034          --  If result is Any_Type, then we did not find a compatible pair
3035
3036          if Etype (N) = Any_Type then
3037             Error_Msg_N ("incompatible types in range ", N);
3038          end if;
3039       end if;
3040
3041       if Ada_Version = Ada_83
3042         and then
3043           (Nkind (Parent (N)) = N_Loop_Parameter_Specification
3044              or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
3045       then
3046          Check_Universal_Expression (L);
3047          Check_Universal_Expression (H);
3048       end if;
3049    end Analyze_Range;
3050
3051    -----------------------
3052    -- Analyze_Reference --
3053    -----------------------
3054
3055    procedure Analyze_Reference (N : Node_Id) is
3056       P        : constant Node_Id := Prefix (N);
3057       E        : Entity_Id;
3058       T        : Entity_Id;
3059       Acc_Type : Entity_Id;
3060
3061    begin
3062       Analyze (P);
3063
3064       --  An interesting error check, if we take the 'Reference of an object
3065       --  for which a pragma Atomic or Volatile has been given, and the type
3066       --  of the object is not Atomic or Volatile, then we are in trouble. The
3067       --  problem is that no trace of the atomic/volatile status will remain
3068       --  for the backend to respect when it deals with the resulting pointer,
3069       --  since the pointer type will not be marked atomic (it is a pointer to
3070       --  the base type of the object).
3071
3072       --  It is not clear if that can ever occur, but in case it does, we will
3073       --  generate an error message. Not clear if this message can ever be
3074       --  generated, and pretty clear that it represents a bug if it is, still
3075       --  seems worth checking!
3076
3077       T := Etype (P);
3078
3079       if Is_Entity_Name (P)
3080         and then Is_Object_Reference (P)
3081       then
3082          E := Entity (P);
3083          T := Etype (P);
3084
3085          if (Has_Atomic_Components   (E)
3086                and then not Has_Atomic_Components   (T))
3087            or else
3088             (Has_Volatile_Components (E)
3089                and then not Has_Volatile_Components (T))
3090            or else (Is_Atomic   (E) and then not Is_Atomic   (T))
3091            or else (Is_Volatile (E) and then not Is_Volatile (T))
3092          then
3093             Error_Msg_N ("cannot take reference to Atomic/Volatile object", N);
3094          end if;
3095       end if;
3096
3097       --  Carry on with normal processing
3098
3099       Acc_Type := Create_Itype (E_Allocator_Type, N);
3100       Set_Etype (Acc_Type,  Acc_Type);
3101       Set_Directly_Designated_Type (Acc_Type, Etype (P));
3102       Set_Etype (N, Acc_Type);
3103    end Analyze_Reference;
3104
3105    --------------------------------
3106    -- Analyze_Selected_Component --
3107    --------------------------------
3108
3109    --  Prefix is a record type or a task or protected type. In the
3110    --  later case, the selector must denote a visible entry.
3111
3112    procedure Analyze_Selected_Component (N : Node_Id) is
3113       Name          : constant Node_Id := Prefix (N);
3114       Sel           : constant Node_Id := Selector_Name (N);
3115       Act_Decl      : Node_Id;
3116       Comp          : Entity_Id;
3117       Has_Candidate : Boolean := False;
3118       In_Scope      : Boolean;
3119       Parent_N      : Node_Id;
3120       Pent          : Entity_Id := Empty;
3121       Prefix_Type   : Entity_Id;
3122
3123       Type_To_Use : Entity_Id;
3124       --  In most cases this is the Prefix_Type, but if the Prefix_Type is
3125       --  a class-wide type, we use its root type, whose components are
3126       --  present in the class-wide type.
3127
3128       function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean;
3129       --  It is known that the parent of N denotes a subprogram call. Comp
3130       --  is an overloadable component of the concurrent type of the prefix.
3131       --  Determine whether all formals of the parent of N and Comp are mode
3132       --  conformant. If the parent node is not analyzed yet it may be an
3133       --  indexed component rather than a function call.
3134
3135       ------------------------------
3136       -- Has_Mode_Conformant_Spec --
3137       ------------------------------
3138
3139       function Has_Mode_Conformant_Spec (Comp : Entity_Id) return Boolean is
3140          Comp_Param : Entity_Id;
3141          Param      : Node_Id;
3142          Param_Typ  : Entity_Id;
3143
3144       begin
3145          Comp_Param := First_Formal (Comp);
3146
3147          if Nkind (Parent (N)) = N_Indexed_Component then
3148             Param := First (Expressions (Parent (N)));
3149          else
3150             Param := First (Parameter_Associations (Parent (N)));
3151          end if;
3152
3153          while Present (Comp_Param)
3154            and then Present (Param)
3155          loop
3156             Param_Typ := Find_Parameter_Type (Param);
3157
3158             if Present (Param_Typ)
3159               and then
3160                 not Conforming_Types
3161                      (Etype (Comp_Param), Param_Typ, Mode_Conformant)
3162             then
3163                return False;
3164             end if;
3165
3166             Next_Formal (Comp_Param);
3167             Next (Param);
3168          end loop;
3169
3170          --  One of the specs has additional formals
3171
3172          if Present (Comp_Param) or else Present (Param) then
3173             return False;
3174          end if;
3175
3176          return True;
3177       end Has_Mode_Conformant_Spec;
3178
3179    --  Start of processing for Analyze_Selected_Component
3180
3181    begin
3182       Set_Etype (N, Any_Type);
3183
3184       if Is_Overloaded (Name) then
3185          Analyze_Overloaded_Selected_Component (N);
3186          return;
3187
3188       elsif Etype (Name) = Any_Type then
3189          Set_Entity (Sel, Any_Id);
3190          Set_Etype (Sel, Any_Type);
3191          return;
3192
3193       else
3194          Prefix_Type := Etype (Name);
3195       end if;
3196
3197       if Is_Access_Type (Prefix_Type) then
3198
3199          --  A RACW object can never be used as prefix of a selected
3200          --  component since that means it is dereferenced without
3201          --  being a controlling operand of a dispatching operation
3202          --  (RM E.2.2(16/1)). Before reporting an error, we must check
3203          --  whether this is actually a dispatching call in prefix form.
3204
3205          if Is_Remote_Access_To_Class_Wide_Type (Prefix_Type)
3206            and then Comes_From_Source (N)
3207          then
3208             if Try_Object_Operation (N) then
3209                return;
3210             else
3211                Error_Msg_N
3212                  ("invalid dereference of a remote access-to-class-wide value",
3213                   N);
3214             end if;
3215
3216          --  Normal case of selected component applied to access type
3217
3218          else
3219             Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3220
3221             if Is_Entity_Name (Name) then
3222                Pent := Entity (Name);
3223             elsif Nkind (Name) = N_Selected_Component
3224               and then Is_Entity_Name (Selector_Name (Name))
3225             then
3226                Pent := Entity (Selector_Name (Name));
3227             end if;
3228
3229             Prefix_Type := Process_Implicit_Dereference_Prefix (Pent, Name);
3230          end if;
3231
3232       --  If we have an explicit dereference of a remote access-to-class-wide
3233       --  value, then issue an error (see RM-E.2.2(16/1)). However we first
3234       --  have to check for the case of a prefix that is a controlling operand
3235       --  of a prefixed dispatching call, as the dereference is legal in that
3236       --  case. Normally this condition is checked in Validate_Remote_Access_
3237       --  To_Class_Wide_Type, but we have to defer the checking for selected
3238       --  component prefixes because of the prefixed dispatching call case.
3239       --  Note that implicit dereferences are checked for this just above.
3240
3241       elsif Nkind (Name) = N_Explicit_Dereference
3242         and then Is_Remote_Access_To_Class_Wide_Type (Etype (Prefix (Name)))
3243         and then Comes_From_Source (N)
3244       then
3245          if Try_Object_Operation (N) then
3246             return;
3247          else
3248             Error_Msg_N
3249               ("invalid dereference of a remote access-to-class-wide value",
3250                N);
3251          end if;
3252       end if;
3253
3254       --  (Ada 2005): if the prefix is the limited view of a type, and
3255       --  the context already includes the full view, use the full view
3256       --  in what follows, either to retrieve a component of to find
3257       --  a primitive operation. If the prefix is an explicit dereference,
3258       --  set the type of the prefix to reflect this transformation.
3259       --  If the non-limited view is itself an incomplete type, get the
3260       --  full view if available.
3261
3262       if Is_Incomplete_Type (Prefix_Type)
3263         and then From_With_Type (Prefix_Type)
3264         and then Present (Non_Limited_View (Prefix_Type))
3265       then
3266          Prefix_Type := Get_Full_View (Non_Limited_View (Prefix_Type));
3267
3268          if Nkind (N) = N_Explicit_Dereference then
3269             Set_Etype (Prefix (N), Prefix_Type);
3270          end if;
3271
3272       elsif Ekind (Prefix_Type) = E_Class_Wide_Type
3273         and then From_With_Type (Prefix_Type)
3274         and then Present (Non_Limited_View (Etype (Prefix_Type)))
3275       then
3276          Prefix_Type :=
3277            Class_Wide_Type (Non_Limited_View (Etype (Prefix_Type)));
3278
3279          if Nkind (N) = N_Explicit_Dereference then
3280             Set_Etype (Prefix (N), Prefix_Type);
3281          end if;
3282       end if;
3283
3284       if Ekind (Prefix_Type) = E_Private_Subtype then
3285          Prefix_Type := Base_Type (Prefix_Type);
3286       end if;
3287
3288       Type_To_Use := Prefix_Type;
3289
3290       --  For class-wide types, use the entity list of the root type. This
3291       --  indirection is specially important for private extensions because
3292       --  only the root type get switched (not the class-wide type).
3293
3294       if Is_Class_Wide_Type (Prefix_Type) then
3295          Type_To_Use := Root_Type (Prefix_Type);
3296       end if;
3297
3298       Comp := First_Entity (Type_To_Use);
3299
3300       --  If the selector has an original discriminant, the node appears in
3301       --  an instance. Replace the discriminant with the corresponding one
3302       --  in the current discriminated type. For nested generics, this must
3303       --  be done transitively, so note the new original discriminant.
3304
3305       if Nkind (Sel) = N_Identifier
3306         and then Present (Original_Discriminant (Sel))
3307       then
3308          Comp := Find_Corresponding_Discriminant (Sel, Prefix_Type);
3309
3310          --  Mark entity before rewriting, for completeness and because
3311          --  subsequent semantic checks might examine the original node.
3312
3313          Set_Entity (Sel, Comp);
3314          Rewrite (Selector_Name (N),
3315            New_Occurrence_Of (Comp, Sloc (N)));
3316          Set_Original_Discriminant (Selector_Name (N), Comp);
3317          Set_Etype (N, Etype (Comp));
3318
3319          if Is_Access_Type (Etype (Name)) then
3320             Insert_Explicit_Dereference (Name);
3321             Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3322          end if;
3323
3324       elsif Is_Record_Type (Prefix_Type) then
3325
3326          --  Find component with given name
3327
3328          while Present (Comp) loop
3329             if Chars (Comp) = Chars (Sel)
3330               and then Is_Visible_Component (Comp)
3331             then
3332                Set_Entity_With_Style_Check (Sel, Comp);
3333                Set_Etype (Sel, Etype (Comp));
3334
3335                if Ekind (Comp) = E_Discriminant then
3336                   if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
3337                      Error_Msg_N
3338                        ("cannot reference discriminant of Unchecked_Union",
3339                         Sel);
3340                   end if;
3341
3342                   if Is_Generic_Type (Prefix_Type)
3343                        or else
3344                      Is_Generic_Type (Root_Type (Prefix_Type))
3345                   then
3346                      Set_Original_Discriminant (Sel, Comp);
3347                   end if;
3348                end if;
3349
3350                --  Resolve the prefix early otherwise it is not possible to
3351                --  build the actual subtype of the component: it may need
3352                --  to duplicate this prefix and duplication is only allowed
3353                --  on fully resolved expressions.
3354
3355                Resolve (Name);
3356
3357                --  Ada 2005 (AI-50217): Check wrong use of incomplete types or
3358                --  subtypes in a package specification.
3359                --  Example:
3360
3361                --    limited with Pkg;
3362                --    package Pkg is
3363                --       type Acc_Inc is access Pkg.T;
3364                --       X : Acc_Inc;
3365                --       N : Natural := X.all.Comp;  --  ERROR, limited view
3366                --    end Pkg;                       --  Comp is not visible
3367
3368                if Nkind (Name) = N_Explicit_Dereference
3369                  and then From_With_Type (Etype (Prefix (Name)))
3370                  and then not Is_Potentially_Use_Visible (Etype (Name))
3371                  and then Nkind (Parent (Cunit_Entity (Current_Sem_Unit))) =
3372                             N_Package_Specification
3373                then
3374                   Error_Msg_NE
3375                     ("premature usage of incomplete}", Prefix (Name),
3376                      Etype (Prefix (Name)));
3377                end if;
3378
3379                --  We never need an actual subtype for the case of a selection
3380                --  for a indexed component of a non-packed array, since in
3381                --  this case gigi generates all the checks and can find the
3382                --  necessary bounds information.
3383
3384                --  We also do not need an actual subtype for the case of
3385                --  a first, last, length, or range attribute applied to a
3386                --  non-packed array, since gigi can again get the bounds in
3387                --  these cases (gigi cannot handle the packed case, since it
3388                --  has the bounds of the packed array type, not the original
3389                --  bounds of the type). However, if the prefix is itself a
3390                --  selected component, as in a.b.c (i), gigi may regard a.b.c
3391                --  as a dynamic-sized temporary, so we do generate an actual
3392                --  subtype for this case.
3393
3394                Parent_N := Parent (N);
3395
3396                if not Is_Packed (Etype (Comp))
3397                  and then
3398                    ((Nkind (Parent_N) = N_Indexed_Component
3399                        and then Nkind (Name) /= N_Selected_Component)
3400                      or else
3401                       (Nkind (Parent_N) = N_Attribute_Reference
3402                          and then (Attribute_Name (Parent_N) = Name_First
3403                                      or else
3404                                    Attribute_Name (Parent_N) = Name_Last
3405                                      or else
3406                                    Attribute_Name (Parent_N) = Name_Length
3407                                      or else
3408                                    Attribute_Name (Parent_N) = Name_Range)))
3409                then
3410                   Set_Etype (N, Etype (Comp));
3411
3412                --  If full analysis is not enabled, we do not generate an
3413                --  actual subtype, because in the absence of expansion
3414                --  reference to a formal of a protected type, for example,
3415                --  will not be properly transformed, and will lead to
3416                --  out-of-scope references in gigi.
3417
3418                --  In all other cases, we currently build an actual subtype.
3419                --  It seems likely that many of these cases can be avoided,
3420                --  but right now, the front end makes direct references to the
3421                --  bounds (e.g. in generating a length check), and if we do
3422                --  not make an actual subtype, we end up getting a direct
3423                --  reference to a discriminant, which will not do.
3424
3425                elsif Full_Analysis then
3426                   Act_Decl :=
3427                     Build_Actual_Subtype_Of_Component (Etype (Comp), N);
3428                   Insert_Action (N, Act_Decl);
3429
3430                   if No (Act_Decl) then
3431                      Set_Etype (N, Etype (Comp));
3432
3433                   else
3434                      --  Component type depends on discriminants. Enter the
3435                      --  main attributes of the subtype.
3436
3437                      declare
3438                         Subt : constant Entity_Id :=
3439                                  Defining_Identifier (Act_Decl);
3440
3441                      begin
3442                         Set_Etype (Subt, Base_Type (Etype (Comp)));
3443                         Set_Ekind (Subt, Ekind (Etype (Comp)));
3444                         Set_Etype (N, Subt);
3445                      end;
3446                   end if;
3447
3448                --  If Full_Analysis not enabled, just set the Etype
3449
3450                else
3451                   Set_Etype (N, Etype (Comp));
3452                end if;
3453
3454                return;
3455             end if;
3456
3457             --  If the prefix is a private extension, check only the visible
3458             --  components of the partial view. This must include the tag,
3459             --  which can appear in expanded code in a tag check.
3460
3461             if Ekind (Type_To_Use) = E_Record_Type_With_Private
3462               and then  Chars (Selector_Name (N)) /= Name_uTag
3463             then
3464                exit when Comp = Last_Entity (Type_To_Use);
3465             end if;
3466
3467             Next_Entity (Comp);
3468          end loop;
3469
3470          --  Ada 2005 (AI-252): The selected component can be interpreted as
3471          --  a prefixed view of a subprogram. Depending on the context, this is
3472          --  either a name that can appear in a renaming declaration, or part
3473          --  of an enclosing call given in prefix form.
3474
3475          --  Ada 2005 (AI05-0030): In the case of dispatching requeue, the
3476          --  selected component should resolve to a name.
3477
3478          if Ada_Version >= Ada_05
3479            and then Is_Tagged_Type (Prefix_Type)
3480            and then not Is_Concurrent_Type (Prefix_Type)
3481          then
3482             if Nkind (Parent (N)) = N_Generic_Association
3483               or else Nkind (Parent (N)) = N_Requeue_Statement
3484               or else Nkind (Parent (N)) = N_Subprogram_Renaming_Declaration
3485             then
3486                if Find_Primitive_Operation (N) then
3487                   return;
3488                end if;
3489
3490             elsif Try_Object_Operation (N) then
3491                return;
3492             end if;
3493
3494             --  If the transformation fails, it will be necessary to redo the
3495             --  analysis with all errors enabled, to indicate candidate
3496             --  interpretations and reasons for each failure ???
3497
3498          end if;
3499
3500       elsif Is_Private_Type (Prefix_Type) then
3501
3502          --  Allow access only to discriminants of the type. If the type has
3503          --  no full view, gigi uses the parent type for the components, so we
3504          --  do the same here.
3505
3506          if No (Full_View (Prefix_Type)) then
3507             Type_To_Use := Root_Type (Base_Type (Prefix_Type));
3508             Comp := First_Entity (Type_To_Use);
3509          end if;
3510
3511          while Present (Comp) loop
3512             if Chars (Comp) = Chars (Sel) then
3513                if Ekind (Comp) = E_Discriminant then
3514                   Set_Entity_With_Style_Check (Sel, Comp);
3515                   Generate_Reference (Comp, Sel);
3516
3517                   Set_Etype (Sel, Etype (Comp));
3518                   Set_Etype (N,   Etype (Comp));
3519
3520                   if Is_Generic_Type (Prefix_Type)
3521                     or else Is_Generic_Type (Root_Type (Prefix_Type))
3522                   then
3523                      Set_Original_Discriminant (Sel, Comp);
3524                   end if;
3525
3526                --  Before declaring an error, check whether this is tagged
3527                --  private type and a call to a primitive operation.
3528
3529                elsif Ada_Version >= Ada_05
3530                  and then Is_Tagged_Type (Prefix_Type)
3531                  and then Try_Object_Operation (N)
3532                then
3533                   return;
3534
3535                else
3536                   Error_Msg_NE
3537                     ("invisible selector for }",
3538                      N, First_Subtype (Prefix_Type));
3539                   Set_Entity (Sel, Any_Id);
3540                   Set_Etype (N, Any_Type);
3541                end if;
3542
3543                return;
3544             end if;
3545
3546             Next_Entity (Comp);
3547          end loop;
3548
3549       elsif Is_Concurrent_Type (Prefix_Type) then
3550
3551          --  Find visible operation with given name. For a protected type,
3552          --  the possible candidates are discriminants, entries or protected
3553          --  procedures. For a task type, the set can only include entries or
3554          --  discriminants if the task type is not an enclosing scope. If it
3555          --  is an enclosing scope (e.g. in an inner task) then all entities
3556          --  are visible, but the prefix must denote the enclosing scope, i.e.
3557          --  can only be a direct name or an expanded name.
3558
3559          Set_Etype (Sel, Any_Type);
3560          In_Scope := In_Open_Scopes (Prefix_Type);
3561
3562          while Present (Comp) loop
3563             if Chars (Comp) = Chars (Sel) then
3564                if Is_Overloadable (Comp) then
3565                   Add_One_Interp (Sel, Comp, Etype (Comp));
3566
3567                   --  If the prefix is tagged, the correct interpretation may
3568                   --  lie in the primitive or class-wide operations of the
3569                   --  type. Perform a simple conformance check to determine
3570                   --  whether Try_Object_Operation should be invoked even if
3571                   --  a visible entity is found.
3572
3573                   if Is_Tagged_Type (Prefix_Type)
3574                     and then
3575                       Nkind_In (Parent (N), N_Procedure_Call_Statement,
3576                                             N_Function_Call,
3577                                             N_Indexed_Component)
3578                     and then Has_Mode_Conformant_Spec (Comp)
3579                   then
3580                      Has_Candidate := True;
3581                   end if;
3582
3583                elsif Ekind_In (Comp, E_Discriminant, E_Entry_Family)
3584                  or else (In_Scope and then Is_Entity_Name (Name))
3585                then
3586                   Set_Entity_With_Style_Check (Sel, Comp);
3587                   Generate_Reference (Comp, Sel);
3588
3589                else
3590                   goto Next_Comp;
3591                end if;
3592
3593                Set_Etype (Sel, Etype (Comp));
3594                Set_Etype (N,   Etype (Comp));
3595
3596                if Ekind (Comp) = E_Discriminant then
3597                   Set_Original_Discriminant (Sel, Comp);
3598                end if;
3599
3600                --  For access type case, introduce explicit dereference for
3601                --  more uniform treatment of entry calls.
3602
3603                if Is_Access_Type (Etype (Name)) then
3604                   Insert_Explicit_Dereference (Name);
3605                   Error_Msg_NW
3606                     (Warn_On_Dereference, "?implicit dereference", N);
3607                end if;
3608             end if;
3609
3610             <<Next_Comp>>
3611                Next_Entity (Comp);
3612                exit when not In_Scope
3613                  and then
3614                    Comp = First_Private_Entity (Base_Type (Prefix_Type));
3615          end loop;
3616
3617          --  If there is no visible entity with the given name or none of the
3618          --  visible entities are plausible interpretations, check whether
3619          --  there is some other primitive operation with that name.
3620
3621          if Ada_Version >= Ada_05
3622            and then Is_Tagged_Type (Prefix_Type)
3623          then
3624             if (Etype (N) = Any_Type
3625                   or else not Has_Candidate)
3626               and then Try_Object_Operation (N)
3627             then
3628                return;
3629
3630             --  If the context is not syntactically a procedure call, it
3631             --  may be a call to a primitive function declared outside of
3632             --  the synchronized type.
3633
3634             --  If the context is a procedure call, there might still be
3635             --  an overloading between an entry and a primitive procedure
3636             --  declared outside of the synchronized type, called in prefix
3637             --  notation. This is harder to disambiguate because in one case
3638             --  the controlling formal is implicit ???
3639
3640             elsif Nkind (Parent (N)) /= N_Procedure_Call_Statement
3641               and then Nkind (Parent (N)) /= N_Indexed_Component
3642               and then Try_Object_Operation (N)
3643             then
3644                return;
3645             end if;
3646          end if;
3647
3648          Set_Is_Overloaded (N, Is_Overloaded (Sel));
3649
3650       else
3651          --  Invalid prefix
3652
3653          Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
3654       end if;
3655
3656       --  If N still has no type, the component is not defined in the prefix
3657
3658       if Etype (N) = Any_Type then
3659
3660          --  If the prefix is a single concurrent object, use its name in the
3661          --  error message, rather than that of its anonymous type.
3662
3663          if Is_Concurrent_Type (Prefix_Type)
3664            and then Is_Internal_Name (Chars (Prefix_Type))
3665            and then not Is_Derived_Type (Prefix_Type)
3666            and then Is_Entity_Name (Name)
3667          then
3668
3669             Error_Msg_Node_2 := Entity (Name);
3670             Error_Msg_NE ("no selector& for&", N, Sel);
3671
3672             Check_Misspelled_Selector (Type_To_Use, Sel);
3673
3674          elsif Is_Generic_Type (Prefix_Type)
3675            and then Ekind (Prefix_Type) = E_Record_Type_With_Private
3676            and then Prefix_Type /= Etype (Prefix_Type)
3677            and then Is_Record_Type (Etype (Prefix_Type))
3678          then
3679             --  If this is a derived formal type, the parent may have
3680             --  different visibility at this point. Try for an inherited
3681             --  component before reporting an error.
3682
3683             Set_Etype (Prefix (N), Etype (Prefix_Type));
3684             Analyze_Selected_Component (N);
3685             return;
3686
3687          elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
3688            and then Is_Generic_Actual_Type (Prefix_Type)
3689            and then Present (Full_View (Prefix_Type))
3690          then
3691             --  Similarly, if this the actual for a formal derived type, the
3692             --  component inherited from the generic parent may not be visible
3693             --  in the actual, but the selected component is legal.
3694
3695             declare
3696                Comp : Entity_Id;
3697
3698             begin
3699                Comp :=
3700                  First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
3701                while Present (Comp) loop
3702                   if Chars (Comp) = Chars (Sel) then
3703                      Set_Entity_With_Style_Check (Sel, Comp);
3704                      Set_Etype (Sel, Etype (Comp));
3705                      Set_Etype (N,   Etype (Comp));
3706                      return;
3707                   end if;
3708
3709                   Next_Component (Comp);
3710                end loop;
3711
3712                pragma Assert (Etype (N) /= Any_Type);
3713             end;
3714
3715          else
3716             if Ekind (Prefix_Type) = E_Record_Subtype then
3717
3718                --  Check whether this is a component of the base type
3719                --  which is absent from a statically constrained subtype.
3720                --  This will raise constraint error at run-time, but is
3721                --  not a compile-time error. When the selector is illegal
3722                --  for base type as well fall through and generate a
3723                --  compilation error anyway.
3724
3725                Comp := First_Component (Base_Type (Prefix_Type));
3726                while Present (Comp) loop
3727                   if Chars (Comp) = Chars (Sel)
3728                     and then Is_Visible_Component (Comp)
3729                   then
3730                      Set_Entity_With_Style_Check (Sel, Comp);
3731                      Generate_Reference (Comp, Sel);
3732                      Set_Etype (Sel, Etype (Comp));
3733                      Set_Etype (N,   Etype (Comp));
3734
3735                      --  Emit appropriate message. Gigi will replace the
3736                      --  node subsequently with the appropriate Raise.
3737
3738                      Apply_Compile_Time_Constraint_Error
3739                        (N, "component not present in }?",
3740                         CE_Discriminant_Check_Failed,
3741                         Ent => Prefix_Type, Rep => False);
3742                      Set_Raises_Constraint_Error (N);
3743                      return;
3744                   end if;
3745
3746                   Next_Component (Comp);
3747                end loop;
3748
3749             end if;
3750
3751             Error_Msg_Node_2 := First_Subtype (Prefix_Type);
3752             Error_Msg_NE ("no selector& for}", N, Sel);
3753
3754             Check_Misspelled_Selector (Type_To_Use, Sel);
3755          end if;
3756
3757          Set_Entity (Sel, Any_Id);
3758          Set_Etype (Sel, Any_Type);
3759       end if;
3760    end Analyze_Selected_Component;
3761
3762    ---------------------------
3763    -- Analyze_Short_Circuit --
3764    ---------------------------
3765
3766    procedure Analyze_Short_Circuit (N : Node_Id) is
3767       L   : constant Node_Id := Left_Opnd  (N);
3768       R   : constant Node_Id := Right_Opnd (N);
3769       Ind : Interp_Index;
3770       It  : Interp;
3771
3772    begin
3773       Analyze_Expression (L);
3774       Analyze_Expression (R);
3775       Set_Etype (N, Any_Type);
3776
3777       if not Is_Overloaded (L) then
3778          if Root_Type (Etype (L)) = Standard_Boolean
3779            and then Has_Compatible_Type (R, Etype (L))
3780          then
3781             Add_One_Interp (N, Etype (L), Etype (L));
3782          end if;
3783
3784       else
3785          Get_First_Interp (L, Ind, It);
3786          while Present (It.Typ) loop
3787             if Root_Type (It.Typ) = Standard_Boolean
3788               and then Has_Compatible_Type (R, It.Typ)
3789             then
3790                Add_One_Interp (N, It.Typ, It.Typ);
3791             end if;
3792
3793             Get_Next_Interp (Ind, It);
3794          end loop;
3795       end if;
3796
3797       --  Here we have failed to find an interpretation. Clearly we know that
3798       --  it is not the case that both operands can have an interpretation of
3799       --  Boolean, but this is by far the most likely intended interpretation.
3800       --  So we simply resolve both operands as Booleans, and at least one of
3801       --  these resolutions will generate an error message, and we do not need
3802       --  to give another error message on the short circuit operation itself.
3803
3804       if Etype (N) = Any_Type then
3805          Resolve (L, Standard_Boolean);
3806          Resolve (R, Standard_Boolean);
3807          Set_Etype (N, Standard_Boolean);
3808       end if;
3809    end Analyze_Short_Circuit;
3810
3811    -------------------
3812    -- Analyze_Slice --
3813    -------------------
3814
3815    procedure Analyze_Slice (N : Node_Id) is
3816       P          : constant Node_Id := Prefix (N);
3817       D          : constant Node_Id := Discrete_Range (N);
3818       Array_Type : Entity_Id;
3819
3820       procedure Analyze_Overloaded_Slice;
3821       --  If the prefix is overloaded, select those interpretations that
3822       --  yield a one-dimensional array type.
3823
3824       ------------------------------
3825       -- Analyze_Overloaded_Slice --
3826       ------------------------------
3827
3828       procedure Analyze_Overloaded_Slice is
3829          I   : Interp_Index;
3830          It  : Interp;
3831          Typ : Entity_Id;
3832
3833       begin
3834          Set_Etype (N, Any_Type);
3835
3836          Get_First_Interp (P, I, It);
3837          while Present (It.Nam) loop
3838             Typ := It.Typ;
3839
3840             if Is_Access_Type (Typ) then
3841                Typ := Designated_Type (Typ);
3842                Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3843             end if;
3844
3845             if Is_Array_Type (Typ)
3846               and then Number_Dimensions (Typ) = 1
3847               and then Has_Compatible_Type (D, Etype (First_Index (Typ)))
3848             then
3849                Add_One_Interp (N, Typ, Typ);
3850             end if;
3851
3852             Get_Next_Interp (I, It);
3853          end loop;
3854
3855          if Etype (N) = Any_Type then
3856             Error_Msg_N ("expect array type in prefix of slice",  N);
3857          end if;
3858       end Analyze_Overloaded_Slice;
3859
3860    --  Start of processing for Analyze_Slice
3861
3862    begin
3863       Analyze (P);
3864       Analyze (D);
3865
3866       if Is_Overloaded (P) then
3867          Analyze_Overloaded_Slice;
3868
3869       else
3870          Array_Type := Etype (P);
3871          Set_Etype (N, Any_Type);
3872
3873          if Is_Access_Type (Array_Type) then
3874             Array_Type := Designated_Type (Array_Type);
3875             Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
3876          end if;
3877
3878          if not Is_Array_Type (Array_Type) then
3879             Wrong_Type (P, Any_Array);
3880
3881          elsif Number_Dimensions (Array_Type) > 1 then
3882             Error_Msg_N
3883               ("type is not one-dimensional array in slice prefix", N);
3884
3885          elsif not
3886            Has_Compatible_Type (D, Etype (First_Index (Array_Type)))
3887          then
3888             Wrong_Type (D, Etype (First_Index (Array_Type)));
3889
3890          else
3891             Set_Etype (N, Array_Type);
3892          end if;
3893       end if;
3894    end Analyze_Slice;
3895
3896    -----------------------------
3897    -- Analyze_Type_Conversion --
3898    -----------------------------
3899
3900    procedure Analyze_Type_Conversion (N : Node_Id) is
3901       Expr : constant Node_Id := Expression (N);
3902       T    : Entity_Id;
3903
3904    begin
3905       --  Check if the expression is a function call for which we need to
3906       --  adjust a SCIL dispatching node.
3907
3908       if Generate_SCIL
3909         and then Nkind (Expr) = N_Function_Call
3910       then
3911          Adjust_SCIL_Node (N, Expr);
3912       end if;
3913
3914       --  If Conversion_OK is set, then the Etype is already set, and the
3915       --  only processing required is to analyze the expression. This is
3916       --  used to construct certain "illegal" conversions which are not
3917       --  allowed by Ada semantics, but can be handled OK by Gigi, see
3918       --  Sinfo for further details.
3919
3920       if Conversion_OK (N) then
3921          Analyze (Expr);
3922          return;
3923       end if;
3924
3925       --  Otherwise full type analysis is required, as well as some semantic
3926       --  checks to make sure the argument of the conversion is appropriate.
3927
3928       Find_Type (Subtype_Mark (N));
3929       T := Entity (Subtype_Mark (N));
3930       Set_Etype (N, T);
3931       Check_Fully_Declared (T, N);
3932       Analyze_Expression (Expr);
3933       Validate_Remote_Type_Type_Conversion (N);
3934
3935       --  Only remaining step is validity checks on the argument. These
3936       --  are skipped if the conversion does not come from the source.
3937
3938       if not Comes_From_Source (N) then
3939          return;
3940
3941       --  If there was an error in a generic unit, no need to replicate the
3942       --  error message. Conversely, constant-folding in the generic may
3943       --  transform the argument of a conversion into a string literal, which
3944       --  is legal. Therefore the following tests are not performed in an
3945       --  instance.
3946
3947       elsif In_Instance then
3948          return;
3949
3950       elsif Nkind (Expr) = N_Null then
3951          Error_Msg_N ("argument of conversion cannot be null", N);
3952          Error_Msg_N ("\use qualified expression instead", N);
3953          Set_Etype (N, Any_Type);
3954
3955       elsif Nkind (Expr) = N_Aggregate then
3956          Error_Msg_N ("argument of conversion cannot be aggregate", N);
3957          Error_Msg_N ("\use qualified expression instead", N);
3958
3959       elsif Nkind (Expr) = N_Allocator then
3960          Error_Msg_N ("argument of conversion cannot be an allocator", N);
3961          Error_Msg_N ("\use qualified expression instead", N);
3962
3963       elsif Nkind (Expr) = N_String_Literal then
3964          Error_Msg_N ("argument of conversion cannot be string literal", N);
3965          Error_Msg_N ("\use qualified expression instead", N);
3966
3967       elsif Nkind (Expr) = N_Character_Literal then
3968          if Ada_Version = Ada_83 then
3969             Resolve (Expr, T);
3970          else
3971             Error_Msg_N ("argument of conversion cannot be character literal",
3972               N);
3973             Error_Msg_N ("\use qualified expression instead", N);
3974          end if;
3975
3976       elsif Nkind (Expr) = N_Attribute_Reference
3977         and then
3978           (Attribute_Name (Expr) = Name_Access            or else
3979            Attribute_Name (Expr) = Name_Unchecked_Access  or else
3980            Attribute_Name (Expr) = Name_Unrestricted_Access)
3981       then
3982          Error_Msg_N ("argument of conversion cannot be access", N);
3983          Error_Msg_N ("\use qualified expression instead", N);
3984       end if;
3985    end Analyze_Type_Conversion;
3986
3987    ----------------------
3988    -- Analyze_Unary_Op --
3989    ----------------------
3990
3991    procedure Analyze_Unary_Op (N : Node_Id) is
3992       R     : constant Node_Id := Right_Opnd (N);
3993       Op_Id : Entity_Id := Entity (N);
3994
3995    begin
3996       Set_Etype (N, Any_Type);
3997       Candidate_Type := Empty;
3998
3999       Analyze_Expression (R);
4000
4001       if Present (Op_Id) then
4002          if Ekind (Op_Id) = E_Operator then
4003             Find_Unary_Types (R, Op_Id,  N);
4004          else
4005             Add_One_Interp (N, Op_Id, Etype (Op_Id));
4006          end if;
4007
4008       else
4009          Op_Id := Get_Name_Entity_Id (Chars (N));
4010          while Present (Op_Id) loop
4011             if Ekind (Op_Id) = E_Operator then
4012                if No (Next_Entity (First_Entity (Op_Id))) then
4013                   Find_Unary_Types (R, Op_Id,  N);
4014                end if;
4015
4016             elsif Is_Overloadable (Op_Id) then
4017                Analyze_User_Defined_Unary_Op (N, Op_Id);
4018             end if;
4019
4020             Op_Id := Homonym (Op_Id);
4021          end loop;
4022       end if;
4023
4024       Operator_Check (N);
4025    end Analyze_Unary_Op;
4026
4027    ----------------------------------
4028    -- Analyze_Unchecked_Expression --
4029    ----------------------------------
4030
4031    procedure Analyze_Unchecked_Expression (N : Node_Id) is
4032    begin
4033       Analyze (Expression (N), Suppress => All_Checks);
4034       Set_Etype (N, Etype (Expression (N)));
4035       Save_Interps (Expression (N), N);
4036    end Analyze_Unchecked_Expression;
4037
4038    ---------------------------------------
4039    -- Analyze_Unchecked_Type_Conversion --
4040    ---------------------------------------
4041
4042    procedure Analyze_Unchecked_Type_Conversion (N : Node_Id) is
4043    begin
4044       Find_Type (Subtype_Mark (N));
4045       Analyze_Expression (Expression (N));
4046       Set_Etype (N, Entity (Subtype_Mark (N)));
4047    end Analyze_Unchecked_Type_Conversion;
4048
4049    ------------------------------------
4050    -- Analyze_User_Defined_Binary_Op --
4051    ------------------------------------
4052
4053    procedure Analyze_User_Defined_Binary_Op
4054      (N     : Node_Id;
4055       Op_Id : Entity_Id)
4056    is
4057    begin
4058       --  Only do analysis if the operator Comes_From_Source, since otherwise
4059       --  the operator was generated by the expander, and all such operators
4060       --  always refer to the operators in package Standard.
4061
4062       if Comes_From_Source (N) then
4063          declare
4064             F1 : constant Entity_Id := First_Formal (Op_Id);
4065             F2 : constant Entity_Id := Next_Formal (F1);
4066
4067          begin
4068             --  Verify that Op_Id is a visible binary function. Note that since
4069             --  we know Op_Id is overloaded, potentially use visible means use
4070             --  visible for sure (RM 9.4(11)).
4071
4072             if Ekind (Op_Id) = E_Function
4073               and then Present (F2)
4074               and then (Is_Immediately_Visible (Op_Id)
4075                          or else Is_Potentially_Use_Visible (Op_Id))
4076               and then Has_Compatible_Type (Left_Opnd (N), Etype (F1))
4077               and then Has_Compatible_Type (Right_Opnd (N), Etype (F2))
4078             then
4079                Add_One_Interp (N, Op_Id, Etype (Op_Id));
4080
4081                --  If the left operand is overloaded, indicate that the
4082                --  current type is a viable candidate. This is redundant
4083                --  in most cases, but for equality and comparison operators
4084                --  where the context does not impose a type on the operands,
4085                --  setting the proper type is necessary to avoid subsequent
4086                --  ambiguities during resolution, when both user-defined and
4087                --  predefined operators may be candidates.
4088
4089                if Is_Overloaded (Left_Opnd (N)) then
4090                   Set_Etype (Left_Opnd (N), Etype (F1));
4091                end if;
4092
4093                if Debug_Flag_E then
4094                   Write_Str ("user defined operator ");
4095                   Write_Name (Chars (Op_Id));
4096                   Write_Str (" on node ");
4097                   Write_Int (Int (N));
4098                   Write_Eol;
4099                end if;
4100             end if;
4101          end;
4102       end if;
4103    end Analyze_User_Defined_Binary_Op;
4104
4105    -----------------------------------
4106    -- Analyze_User_Defined_Unary_Op --
4107    -----------------------------------
4108
4109    procedure Analyze_User_Defined_Unary_Op
4110      (N     : Node_Id;
4111       Op_Id : Entity_Id)
4112    is
4113    begin
4114       --  Only do analysis if the operator Comes_From_Source, since otherwise
4115       --  the operator was generated by the expander, and all such operators
4116       --  always refer to the operators in package Standard.
4117
4118       if Comes_From_Source (N) then
4119          declare
4120             F : constant Entity_Id := First_Formal (Op_Id);
4121
4122          begin
4123             --  Verify that Op_Id is a visible unary function. Note that since
4124             --  we know Op_Id is overloaded, potentially use visible means use
4125             --  visible for sure (RM 9.4(11)).
4126
4127             if Ekind (Op_Id) = E_Function
4128               and then No (Next_Formal (F))
4129               and then (Is_Immediately_Visible (Op_Id)
4130                          or else Is_Potentially_Use_Visible (Op_Id))
4131               and then Has_Compatible_Type (Right_Opnd (N), Etype (F))
4132             then
4133                Add_One_Interp (N, Op_Id, Etype (Op_Id));
4134             end if;
4135          end;
4136       end if;
4137    end Analyze_User_Defined_Unary_Op;
4138
4139    ---------------------------
4140    -- Check_Arithmetic_Pair --
4141    ---------------------------
4142
4143    procedure Check_Arithmetic_Pair
4144      (T1, T2 : Entity_Id;
4145       Op_Id  : Entity_Id;
4146       N      : Node_Id)
4147    is
4148       Op_Name : constant Name_Id := Chars (Op_Id);
4149
4150       function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean;
4151       --  Check whether the fixed-point type Typ has a user-defined operator
4152       --  (multiplication or division) that should hide the corresponding
4153       --  predefined operator. Used to implement Ada 2005 AI-264, to make
4154       --  such operators more visible and therefore useful.
4155
4156       --  If the name of the operation is an expanded name with prefix
4157       --  Standard, the predefined universal fixed operator is available,
4158       --  as specified by AI-420 (RM 4.5.5 (19.1/2)).
4159
4160       function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
4161       --  Get specific type (i.e. non-universal type if there is one)
4162
4163       ------------------
4164       -- Has_Fixed_Op --
4165       ------------------
4166
4167       function Has_Fixed_Op (Typ : Entity_Id; Op : Entity_Id) return Boolean is
4168          Bas : constant Entity_Id := Base_Type (Typ);
4169          Ent : Entity_Id;
4170          F1  : Entity_Id;
4171          F2  : Entity_Id;
4172
4173       begin
4174          --  If the universal_fixed operation is given explicitly the rule
4175          --  concerning primitive operations of the type do not apply.
4176
4177          if Nkind (N) = N_Function_Call
4178            and then Nkind (Name (N)) = N_Expanded_Name
4179            and then Entity (Prefix (Name (N))) = Standard_Standard
4180          then
4181             return False;
4182          end if;
4183
4184          --  The operation is treated as primitive if it is declared in the
4185          --  same scope as the type, and therefore on the same entity chain.
4186
4187          Ent := Next_Entity (Typ);
4188          while Present (Ent) loop
4189             if Chars (Ent) = Chars (Op) then
4190                F1 := First_Formal (Ent);
4191                F2 := Next_Formal (F1);
4192
4193                --  The operation counts as primitive if either operand or
4194                --  result are of the given base type, and both operands are
4195                --  fixed point types.
4196
4197                if (Base_Type (Etype (F1)) = Bas
4198                     and then Is_Fixed_Point_Type (Etype (F2)))
4199
4200                  or else
4201                    (Base_Type (Etype (F2)) = Bas
4202                      and then Is_Fixed_Point_Type (Etype (F1)))
4203
4204                  or else
4205                    (Base_Type (Etype (Ent)) = Bas
4206                      and then Is_Fixed_Point_Type (Etype (F1))
4207                      and then Is_Fixed_Point_Type (Etype (F2)))
4208                then
4209                   return True;
4210                end if;
4211             end if;
4212
4213             Next_Entity (Ent);
4214          end loop;
4215
4216          return False;
4217       end Has_Fixed_Op;
4218
4219       -------------------
4220       -- Specific_Type --
4221       -------------------
4222
4223       function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
4224       begin
4225          if T1 = Universal_Integer or else T1 = Universal_Real then
4226             return Base_Type (T2);
4227          else
4228             return Base_Type (T1);
4229          end if;
4230       end Specific_Type;
4231
4232    --  Start of processing for Check_Arithmetic_Pair
4233
4234    begin
4235       if Op_Name = Name_Op_Add or else Op_Name = Name_Op_Subtract then
4236
4237          if Is_Numeric_Type (T1)
4238            and then Is_Numeric_Type (T2)
4239            and then (Covers (T1 => T1, T2 => T2)
4240                        or else
4241                      Covers (T1 => T2, T2 => T1))
4242          then
4243             Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4244          end if;
4245
4246       elsif Op_Name = Name_Op_Multiply or else Op_Name = Name_Op_Divide then
4247
4248          if Is_Fixed_Point_Type (T1)
4249            and then (Is_Fixed_Point_Type (T2)
4250                        or else T2 = Universal_Real)
4251          then
4252             --  If Treat_Fixed_As_Integer is set then the Etype is already set
4253             --  and no further processing is required (this is the case of an
4254             --  operator constructed by Exp_Fixd for a fixed point operation)
4255             --  Otherwise add one interpretation with universal fixed result
4256             --  If the operator is given in  functional notation, it comes
4257             --  from source and Fixed_As_Integer cannot apply.
4258
4259             if (Nkind (N) not in N_Op
4260                  or else not Treat_Fixed_As_Integer (N))
4261               and then
4262                 (not Has_Fixed_Op (T1, Op_Id)
4263                   or else Nkind (Parent (N)) = N_Type_Conversion)
4264             then
4265                Add_One_Interp (N, Op_Id, Universal_Fixed);
4266             end if;
4267
4268          elsif Is_Fixed_Point_Type (T2)
4269            and then (Nkind (N) not in N_Op
4270                       or else not Treat_Fixed_As_Integer (N))
4271            and then T1 = Universal_Real
4272            and then
4273              (not Has_Fixed_Op (T1, Op_Id)
4274                or else Nkind (Parent (N)) = N_Type_Conversion)
4275          then
4276             Add_One_Interp (N, Op_Id, Universal_Fixed);
4277
4278          elsif Is_Numeric_Type (T1)
4279            and then Is_Numeric_Type (T2)
4280            and then (Covers (T1 => T1, T2 => T2)
4281                        or else
4282                      Covers (T1 => T2, T2 => T1))
4283          then
4284             Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4285
4286          elsif Is_Fixed_Point_Type (T1)
4287            and then (Base_Type (T2) = Base_Type (Standard_Integer)
4288                        or else T2 = Universal_Integer)
4289          then
4290             Add_One_Interp (N, Op_Id, T1);
4291
4292          elsif T2 = Universal_Real
4293            and then Base_Type (T1) = Base_Type (Standard_Integer)
4294            and then Op_Name = Name_Op_Multiply
4295          then
4296             Add_One_Interp (N, Op_Id, Any_Fixed);
4297
4298          elsif T1 = Universal_Real
4299            and then Base_Type (T2) = Base_Type (Standard_Integer)
4300          then
4301             Add_One_Interp (N, Op_Id, Any_Fixed);
4302
4303          elsif Is_Fixed_Point_Type (T2)
4304            and then (Base_Type (T1) = Base_Type (Standard_Integer)
4305                        or else T1 = Universal_Integer)
4306            and then Op_Name = Name_Op_Multiply
4307          then
4308             Add_One_Interp (N, Op_Id, T2);
4309
4310          elsif T1 = Universal_Real and then T2 = Universal_Integer then
4311             Add_One_Interp (N, Op_Id, T1);
4312
4313          elsif T2 = Universal_Real
4314            and then T1 = Universal_Integer
4315            and then Op_Name = Name_Op_Multiply
4316          then
4317             Add_One_Interp (N, Op_Id, T2);
4318          end if;
4319
4320       elsif Op_Name = Name_Op_Mod or else Op_Name = Name_Op_Rem then
4321
4322          --  Note: The fixed-point operands case with Treat_Fixed_As_Integer
4323          --  set does not require any special processing, since the Etype is
4324          --  already set (case of operation constructed by Exp_Fixed).
4325
4326          if Is_Integer_Type (T1)
4327            and then (Covers (T1 => T1, T2 => T2)
4328                        or else
4329                      Covers (T1 => T2, T2 => T1))
4330          then
4331             Add_One_Interp (N, Op_Id, Specific_Type (T1, T2));
4332          end if;
4333
4334       elsif Op_Name = Name_Op_Expon then
4335          if Is_Numeric_Type (T1)
4336            and then not Is_Fixed_Point_Type (T1)
4337            and then (Base_Type (T2) = Base_Type (Standard_Integer)
4338                       or else T2 = Universal_Integer)
4339          then
4340             Add_One_Interp (N, Op_Id, Base_Type (T1));
4341          end if;
4342
4343       else pragma Assert (Nkind (N) in N_Op_Shift);
4344
4345          --  If not one of the predefined operators, the node may be one
4346          --  of the intrinsic functions. Its kind is always specific, and
4347          --  we can use it directly, rather than the name of the operation.
4348
4349          if Is_Integer_Type (T1)
4350            and then (Base_Type (T2) = Base_Type (Standard_Integer)
4351                       or else T2 = Universal_Integer)
4352          then
4353             Add_One_Interp (N, Op_Id, Base_Type (T1));
4354          end if;
4355       end if;
4356    end Check_Arithmetic_Pair;
4357
4358    -------------------------------
4359    -- Check_Misspelled_Selector --
4360    -------------------------------
4361
4362    procedure Check_Misspelled_Selector
4363      (Prefix : Entity_Id;
4364       Sel    : Node_Id)
4365    is
4366       Max_Suggestions   : constant := 2;
4367       Nr_Of_Suggestions : Natural := 0;
4368
4369       Suggestion_1 : Entity_Id := Empty;
4370       Suggestion_2 : Entity_Id := Empty;
4371
4372       Comp : Entity_Id;
4373
4374    begin
4375       --  All the components of the prefix of selector Sel are matched
4376       --  against  Sel and a count is maintained of possible misspellings.
4377       --  When at the end of the analysis there are one or two (not more!)
4378       --  possible misspellings, these misspellings will be suggested as
4379       --  possible correction.
4380
4381       if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
4382
4383          --  Concurrent types should be handled as well ???
4384
4385          return;
4386       end if;
4387
4388       Comp  := First_Entity (Prefix);
4389       while Nr_Of_Suggestions <= Max_Suggestions and then Present (Comp) loop
4390          if Is_Visible_Component (Comp) then
4391             if Is_Bad_Spelling_Of (Chars (Comp), Chars (Sel)) then
4392                Nr_Of_Suggestions := Nr_Of_Suggestions + 1;
4393
4394                case Nr_Of_Suggestions is
4395                   when 1      => Suggestion_1 := Comp;
4396                   when 2      => Suggestion_2 := Comp;
4397                   when others => exit;
4398                end case;
4399             end if;
4400          end if;
4401
4402          Comp := Next_Entity (Comp);
4403       end loop;
4404
4405       --  Report at most two suggestions
4406
4407       if Nr_Of_Suggestions = 1 then
4408          Error_Msg_NE -- CODEFIX
4409            ("\possible misspelling of&", Sel, Suggestion_1);
4410
4411       elsif Nr_Of_Suggestions = 2 then
4412          Error_Msg_Node_2 := Suggestion_2;
4413          Error_Msg_NE -- CODEFIX
4414            ("\possible misspelling of& or&", Sel, Suggestion_1);
4415       end if;
4416    end Check_Misspelled_Selector;
4417
4418    ----------------------
4419    -- Defined_In_Scope --
4420    ----------------------
4421
4422    function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
4423    is
4424       S1 : constant Entity_Id := Scope (Base_Type (T));
4425    begin
4426       return S1 = S
4427         or else (S1 = System_Aux_Id and then S = Scope (S1));
4428    end Defined_In_Scope;
4429
4430    -------------------
4431    -- Diagnose_Call --
4432    -------------------
4433
4434    procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
4435       Actual           : Node_Id;
4436       X                : Interp_Index;
4437       It               : Interp;
4438       Err_Mode         : Boolean;
4439       New_Nam          : Node_Id;
4440       Void_Interp_Seen : Boolean := False;
4441
4442       Success : Boolean;
4443       pragma Warnings (Off, Boolean);
4444
4445    begin
4446       if Ada_Version >= Ada_05 then
4447          Actual := First_Actual (N);
4448          while Present (Actual) loop
4449
4450             --  Ada 2005 (AI-50217): Post an error in case of premature
4451             --  usage of an entity from the limited view.
4452
4453             if not Analyzed (Etype (Actual))
4454              and then From_With_Type (Etype (Actual))
4455             then
4456                Error_Msg_Qual_Level := 1;
4457                Error_Msg_NE
4458                 ("missing with_clause for scope of imported type&",
4459                   Actual, Etype (Actual));
4460                Error_Msg_Qual_Level := 0;
4461             end if;
4462
4463             Next_Actual (Actual);
4464          end loop;
4465       end if;
4466
4467       --   Analyze each candidate call again, with full error reporting
4468       --   for each.
4469
4470       Error_Msg_N
4471         ("no candidate interpretations match the actuals:!", Nam);
4472       Err_Mode := All_Errors_Mode;
4473       All_Errors_Mode := True;
4474
4475       --  If this is a call to an operation of a concurrent type,
4476       --  the failed interpretations have been removed from the
4477       --  name. Recover them to provide full diagnostics.
4478
4479       if Nkind (Parent (Nam)) = N_Selected_Component then
4480          Set_Entity (Nam, Empty);
4481          New_Nam := New_Copy_Tree (Parent (Nam));
4482          Set_Is_Overloaded (New_Nam, False);
4483          Set_Is_Overloaded (Selector_Name (New_Nam), False);
4484          Set_Parent (New_Nam, Parent (Parent (Nam)));
4485          Analyze_Selected_Component (New_Nam);
4486          Get_First_Interp (Selector_Name (New_Nam), X, It);
4487       else
4488          Get_First_Interp (Nam, X, It);
4489       end if;
4490
4491       while Present (It.Nam) loop
4492          if Etype (It.Nam) = Standard_Void_Type then
4493             Void_Interp_Seen := True;
4494          end if;
4495
4496          Analyze_One_Call (N, It.Nam, True, Success);
4497          Get_Next_Interp (X, It);
4498       end loop;
4499
4500       if Nkind (N) = N_Function_Call then
4501          Get_First_Interp (Nam, X, It);
4502          while Present (It.Nam) loop
4503             if Ekind_In (It.Nam, E_Function, E_Operator) then
4504                return;
4505             else
4506                Get_Next_Interp (X, It);
4507             end if;
4508          end loop;
4509
4510          --  If all interpretations are procedures, this deserves a
4511          --  more precise message. Ditto if this appears as the prefix
4512          --  of a selected component, which may be a lexical error.
4513
4514          Error_Msg_N
4515            ("\context requires function call, found procedure name", Nam);
4516
4517          if Nkind (Parent (N)) = N_Selected_Component
4518            and then N = Prefix (Parent (N))
4519          then
4520             Error_Msg_N -- CODEFIX
4521               ("\period should probably be semicolon", Parent (N));
4522          end if;
4523
4524       elsif Nkind (N) = N_Procedure_Call_Statement
4525         and then not Void_Interp_Seen
4526       then
4527          Error_Msg_N (
4528          "\function name found in procedure call", Nam);
4529       end if;
4530
4531       All_Errors_Mode := Err_Mode;
4532    end Diagnose_Call;
4533
4534    ---------------------------
4535    -- Find_Arithmetic_Types --
4536    ---------------------------
4537
4538    procedure Find_Arithmetic_Types
4539      (L, R  : Node_Id;
4540       Op_Id : Entity_Id;
4541       N     : Node_Id)
4542    is
4543       Index1 : Interp_Index;
4544       Index2 : Interp_Index;
4545       It1    : Interp;
4546       It2    : Interp;
4547
4548       procedure Check_Right_Argument (T : Entity_Id);
4549       --  Check right operand of operator
4550
4551       --------------------------
4552       -- Check_Right_Argument --
4553       --------------------------
4554
4555       procedure Check_Right_Argument (T : Entity_Id) is
4556       begin
4557          if not Is_Overloaded (R) then
4558             Check_Arithmetic_Pair (T, Etype (R), Op_Id,  N);
4559          else
4560             Get_First_Interp (R, Index2, It2);
4561             while Present (It2.Typ) loop
4562                Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
4563                Get_Next_Interp (Index2, It2);
4564             end loop;
4565          end if;
4566       end Check_Right_Argument;
4567
4568    --  Start of processing for Find_Arithmetic_Types
4569
4570    begin
4571       if not Is_Overloaded (L) then
4572          Check_Right_Argument (Etype (L));
4573
4574       else
4575          Get_First_Interp (L, Index1, It1);
4576          while Present (It1.Typ) loop
4577             Check_Right_Argument (It1.Typ);
4578             Get_Next_Interp (Index1, It1);
4579          end loop;
4580       end if;
4581
4582    end Find_Arithmetic_Types;
4583
4584    ------------------------
4585    -- Find_Boolean_Types --
4586    ------------------------
4587
4588    procedure Find_Boolean_Types
4589      (L, R  : Node_Id;
4590       Op_Id : Entity_Id;
4591       N     : Node_Id)
4592    is
4593       Index : Interp_Index;
4594       It    : Interp;
4595
4596       procedure Check_Numeric_Argument (T : Entity_Id);
4597       --  Special case for logical operations one of whose operands is an
4598       --  integer literal. If both are literal the result is any modular type.
4599
4600       ----------------------------
4601       -- Check_Numeric_Argument --
4602       ----------------------------
4603
4604       procedure Check_Numeric_Argument (T : Entity_Id) is
4605       begin
4606          if T = Universal_Integer then
4607             Add_One_Interp (N, Op_Id, Any_Modular);
4608
4609          elsif Is_Modular_Integer_Type (T) then
4610             Add_One_Interp (N, Op_Id, T);
4611          end if;
4612       end Check_Numeric_Argument;
4613
4614    --  Start of processing for Find_Boolean_Types
4615
4616    begin
4617       if not Is_Overloaded (L) then
4618          if Etype (L) = Universal_Integer
4619            or else Etype (L) = Any_Modular
4620          then
4621             if not Is_Overloaded (R) then
4622                Check_Numeric_Argument (Etype (R));
4623
4624             else
4625                Get_First_Interp (R, Index, It);
4626                while Present (It.Typ) loop
4627                   Check_Numeric_Argument (It.Typ);
4628                   Get_Next_Interp (Index, It);
4629                end loop;
4630             end if;
4631
4632          --  If operands are aggregates, we must assume that they may be
4633          --  boolean arrays, and leave disambiguation for the second pass.
4634          --  If only one is an aggregate, verify that the other one has an
4635          --  interpretation as a boolean array
4636
4637          elsif Nkind (L) = N_Aggregate then
4638             if Nkind (R) = N_Aggregate then
4639                Add_One_Interp (N, Op_Id, Etype (L));
4640
4641             elsif not Is_Overloaded (R) then
4642                if Valid_Boolean_Arg (Etype (R)) then
4643                   Add_One_Interp (N, Op_Id, Etype (R));
4644                end if;
4645
4646             else
4647                Get_First_Interp (R, Index, It);
4648                while Present (It.Typ) loop
4649                   if Valid_Boolean_Arg (It.Typ) then
4650                      Add_One_Interp (N, Op_Id, It.Typ);
4651                   end if;
4652
4653                   Get_Next_Interp (Index, It);
4654                end loop;
4655             end if;
4656
4657          elsif Valid_Boolean_Arg (Etype (L))
4658            and then Has_Compatible_Type (R, Etype (L))
4659          then
4660             Add_One_Interp (N, Op_Id, Etype (L));
4661          end if;
4662
4663       else
4664          Get_First_Interp (L, Index, It);
4665          while Present (It.Typ) loop
4666             if Valid_Boolean_Arg (It.Typ)
4667               and then Has_Compatible_Type (R, It.Typ)
4668             then
4669                Add_One_Interp (N, Op_Id, It.Typ);
4670             end if;
4671
4672             Get_Next_Interp (Index, It);
4673          end loop;
4674       end if;
4675    end Find_Boolean_Types;
4676
4677    ---------------------------
4678    -- Find_Comparison_Types --
4679    ---------------------------
4680
4681    procedure Find_Comparison_Types
4682      (L, R  : Node_Id;
4683       Op_Id : Entity_Id;
4684       N     : Node_Id)
4685    is
4686       Index : Interp_Index;
4687       It    : Interp;
4688       Found : Boolean := False;
4689       I_F   : Interp_Index;
4690       T_F   : Entity_Id;
4691       Scop  : Entity_Id := Empty;
4692
4693       procedure Try_One_Interp (T1 : Entity_Id);
4694       --  Routine to try one proposed interpretation. Note that the context
4695       --  of the operator plays no role in resolving the arguments, so that
4696       --  if there is more than one interpretation of the operands that is
4697       --  compatible with comparison, the operation is ambiguous.
4698
4699       --------------------
4700       -- Try_One_Interp --
4701       --------------------
4702
4703       procedure Try_One_Interp (T1 : Entity_Id) is
4704       begin
4705
4706          --  If the operator is an expanded name, then the type of the operand
4707          --  must be defined in the corresponding scope. If the type is
4708          --  universal, the context will impose the correct type.
4709
4710          if Present (Scop)
4711             and then not Defined_In_Scope (T1, Scop)
4712             and then T1 /= Universal_Integer
4713             and then T1 /= Universal_Real
4714             and then T1 /= Any_String
4715             and then T1 /= Any_Composite
4716          then
4717             return;
4718          end if;
4719
4720          if Valid_Comparison_Arg (T1)
4721            and then Has_Compatible_Type (R, T1)
4722          then
4723             if Found
4724               and then Base_Type (T1) /= Base_Type (T_F)
4725             then
4726                It := Disambiguate (L, I_F, Index, Any_Type);
4727
4728                if It = No_Interp then
4729                   Ambiguous_Operands (N);
4730                   Set_Etype (L, Any_Type);
4731                   return;
4732
4733                else
4734                   T_F := It.Typ;
4735                end if;
4736
4737             else
4738                Found := True;
4739                T_F   := T1;
4740                I_F   := Index;
4741             end if;
4742
4743             Set_Etype (L, T_F);
4744             Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4745
4746          end if;
4747       end Try_One_Interp;
4748
4749    --  Start of processing for Find_Comparison_Types
4750
4751    begin
4752       --  If left operand is aggregate, the right operand has to
4753       --  provide a usable type for it.
4754
4755       if Nkind (L) = N_Aggregate
4756         and then Nkind (R) /= N_Aggregate
4757       then
4758          Find_Comparison_Types (L => R, R => L, Op_Id => Op_Id, N => N);
4759          return;
4760       end if;
4761
4762       if Nkind (N) = N_Function_Call
4763          and then Nkind (Name (N)) = N_Expanded_Name
4764       then
4765          Scop := Entity (Prefix (Name (N)));
4766
4767          --  The prefix may be a package renaming, and the subsequent test
4768          --  requires the original package.
4769
4770          if Ekind (Scop) = E_Package
4771            and then Present (Renamed_Entity (Scop))
4772          then
4773             Scop := Renamed_Entity (Scop);
4774             Set_Entity (Prefix (Name (N)), Scop);
4775          end if;
4776       end if;
4777
4778       if not Is_Overloaded (L) then
4779          Try_One_Interp (Etype (L));
4780
4781       else
4782          Get_First_Interp (L, Index, It);
4783          while Present (It.Typ) loop
4784             Try_One_Interp (It.Typ);
4785             Get_Next_Interp (Index, It);
4786          end loop;
4787       end if;
4788    end Find_Comparison_Types;
4789
4790    ----------------------------------------
4791    -- Find_Non_Universal_Interpretations --
4792    ----------------------------------------
4793
4794    procedure Find_Non_Universal_Interpretations
4795      (N     : Node_Id;
4796       R     : Node_Id;
4797       Op_Id : Entity_Id;
4798       T1    : Entity_Id)
4799    is
4800       Index : Interp_Index;
4801       It    : Interp;
4802
4803    begin
4804       if T1 = Universal_Integer
4805         or else T1 = Universal_Real
4806       then
4807          if not Is_Overloaded (R) then
4808             Add_One_Interp
4809               (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
4810          else
4811             Get_First_Interp (R, Index, It);
4812             while Present (It.Typ) loop
4813                if Covers (It.Typ, T1) then
4814                   Add_One_Interp
4815                     (N, Op_Id, Standard_Boolean, Base_Type (It.Typ));
4816                end if;
4817
4818                Get_Next_Interp (Index, It);
4819             end loop;
4820          end if;
4821       else
4822          Add_One_Interp (N, Op_Id, Standard_Boolean, Base_Type (T1));
4823       end if;
4824    end Find_Non_Universal_Interpretations;
4825
4826    ------------------------------
4827    -- Find_Concatenation_Types --
4828    ------------------------------
4829
4830    procedure Find_Concatenation_Types
4831      (L, R  : Node_Id;
4832       Op_Id : Entity_Id;
4833       N     : Node_Id)
4834    is
4835       Op_Type : constant Entity_Id := Etype (Op_Id);
4836
4837    begin
4838       if Is_Array_Type (Op_Type)
4839         and then not Is_Limited_Type (Op_Type)
4840
4841         and then (Has_Compatible_Type (L, Op_Type)
4842                     or else
4843                   Has_Compatible_Type (L, Component_Type (Op_Type)))
4844
4845         and then (Has_Compatible_Type (R, Op_Type)
4846                     or else
4847                   Has_Compatible_Type (R, Component_Type (Op_Type)))
4848       then
4849          Add_One_Interp (N, Op_Id, Op_Type);
4850       end if;
4851    end Find_Concatenation_Types;
4852
4853    -------------------------
4854    -- Find_Equality_Types --
4855    -------------------------
4856
4857    procedure Find_Equality_Types
4858      (L, R  : Node_Id;
4859       Op_Id : Entity_Id;
4860       N     : Node_Id)
4861    is
4862       Index : Interp_Index;
4863       It    : Interp;
4864       Found : Boolean := False;
4865       I_F   : Interp_Index;
4866       T_F   : Entity_Id;
4867       Scop  : Entity_Id := Empty;
4868
4869       procedure Try_One_Interp (T1 : Entity_Id);
4870       --  The context of the equality operator plays no role in resolving the
4871       --  arguments, so that if there is more than one interpretation of the
4872       --  operands that is compatible with equality, the construct is ambiguous
4873       --  and an error can be emitted now, after trying to disambiguate, i.e.
4874       --  applying preference rules.
4875
4876       --------------------
4877       -- Try_One_Interp --
4878       --------------------
4879
4880       procedure Try_One_Interp (T1 : Entity_Id) is
4881          Bas : constant Entity_Id := Base_Type (T1);
4882
4883       begin
4884          --  If the operator is an expanded name, then the type of the operand
4885          --  must be defined in the corresponding scope. If the type is
4886          --  universal, the context will impose the correct type. An anonymous
4887          --  type for a 'Access reference is also universal in this sense, as
4888          --  the actual type is obtained from context.
4889          --  In Ada 2005, the equality operator for anonymous access types
4890          --  is declared in Standard, and preference rules apply to it.
4891
4892          if Present (Scop) then
4893             if Defined_In_Scope (T1, Scop)
4894               or else T1 = Universal_Integer
4895               or else T1 = Universal_Real
4896               or else T1 = Any_Access
4897               or else T1 = Any_String
4898               or else T1 = Any_Composite
4899               or else (Ekind (T1) = E_Access_Subprogram_Type
4900                         and then not Comes_From_Source (T1))
4901             then
4902                null;
4903
4904             elsif Ekind (T1) = E_Anonymous_Access_Type
4905               and then Scop = Standard_Standard
4906             then
4907                null;
4908
4909             else
4910                --  The scope does not contain an operator for the type
4911
4912                return;
4913             end if;
4914
4915          --  If we have infix notation, the operator must be usable.
4916          --  Within an instance, if the type is already established we
4917          --  know it is correct.
4918          --  In Ada 2005, the equality on anonymous access types is declared
4919          --  in Standard, and is always visible.
4920
4921          elsif In_Open_Scopes (Scope (Bas))
4922            or else Is_Potentially_Use_Visible (Bas)
4923            or else In_Use (Bas)
4924            or else (In_Use (Scope (Bas))
4925                      and then not Is_Hidden (Bas))
4926            or else (In_Instance
4927                      and then First_Subtype (T1) = First_Subtype (Etype (R)))
4928            or else Ekind (T1) = E_Anonymous_Access_Type
4929          then
4930             null;
4931
4932          else
4933             --  Save candidate type for subsquent error message, if any
4934
4935             if not Is_Limited_Type (T1) then
4936                Candidate_Type := T1;
4937             end if;
4938
4939             return;
4940          end if;
4941
4942          --  Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
4943          --  Do not allow anonymous access types in equality operators.
4944
4945          if Ada_Version < Ada_05
4946            and then Ekind (T1) = E_Anonymous_Access_Type
4947          then
4948             return;
4949          end if;
4950
4951          if T1 /= Standard_Void_Type
4952            and then not Is_Limited_Type (T1)
4953            and then not Is_Limited_Composite (T1)
4954            and then Has_Compatible_Type (R, T1)
4955          then
4956             if Found
4957               and then Base_Type (T1) /= Base_Type (T_F)
4958             then
4959                It := Disambiguate (L, I_F, Index, Any_Type);
4960
4961                if It = No_Interp then
4962                   Ambiguous_Operands (N);
4963                   Set_Etype (L, Any_Type);
4964                   return;
4965
4966                else
4967                   T_F := It.Typ;
4968                end if;
4969
4970             else
4971                Found := True;
4972                T_F   := T1;
4973                I_F   := Index;
4974             end if;
4975
4976             if not Analyzed (L) then
4977                Set_Etype (L, T_F);
4978             end if;
4979
4980             Find_Non_Universal_Interpretations (N, R, Op_Id, T1);
4981
4982             --  Case of operator was not visible, Etype still set to Any_Type
4983
4984             if Etype (N) = Any_Type then
4985                Found := False;
4986             end if;
4987
4988          elsif Scop = Standard_Standard
4989            and then Ekind (T1) = E_Anonymous_Access_Type
4990          then
4991             Found := True;
4992          end if;
4993       end Try_One_Interp;
4994
4995    --  Start of processing for Find_Equality_Types
4996
4997    begin
4998       --  If left operand is aggregate, the right operand has to
4999       --  provide a usable type for it.
5000
5001       if Nkind (L) = N_Aggregate
5002         and then Nkind (R) /= N_Aggregate
5003       then
5004          Find_Equality_Types (L => R, R => L, Op_Id => Op_Id, N => N);
5005          return;
5006       end if;
5007
5008       if Nkind (N) = N_Function_Call
5009          and then Nkind (Name (N)) = N_Expanded_Name
5010       then
5011          Scop := Entity (Prefix (Name (N)));
5012
5013          --  The prefix may be a package renaming, and the subsequent test
5014          --  requires the original package.
5015
5016          if Ekind (Scop) = E_Package
5017            and then Present (Renamed_Entity (Scop))
5018          then
5019             Scop := Renamed_Entity (Scop);
5020             Set_Entity (Prefix (Name (N)), Scop);
5021          end if;
5022       end if;
5023
5024       if not Is_Overloaded (L) then
5025          Try_One_Interp (Etype (L));
5026
5027       else
5028          Get_First_Interp (L, Index, It);
5029          while Present (It.Typ) loop
5030             Try_One_Interp (It.Typ);
5031             Get_Next_Interp (Index, It);
5032          end loop;
5033       end if;
5034    end Find_Equality_Types;
5035
5036    -------------------------
5037    -- Find_Negation_Types --
5038    -------------------------
5039
5040    procedure Find_Negation_Types
5041      (R     : Node_Id;
5042       Op_Id : Entity_Id;
5043       N     : Node_Id)
5044    is
5045       Index : Interp_Index;
5046       It    : Interp;
5047
5048    begin
5049       if not Is_Overloaded (R) then
5050          if Etype (R) = Universal_Integer then
5051             Add_One_Interp (N, Op_Id, Any_Modular);
5052          elsif Valid_Boolean_Arg (Etype (R)) then
5053             Add_One_Interp (N, Op_Id, Etype (R));
5054          end if;
5055
5056       else
5057          Get_First_Interp (R, Index, It);
5058          while Present (It.Typ) loop
5059             if Valid_Boolean_Arg (It.Typ) then
5060                Add_One_Interp (N, Op_Id, It.Typ);
5061             end if;
5062
5063             Get_Next_Interp (Index, It);
5064          end loop;
5065       end if;
5066    end Find_Negation_Types;
5067
5068    ------------------------------
5069    -- Find_Primitive_Operation --
5070    ------------------------------
5071
5072    function Find_Primitive_Operation (N : Node_Id) return Boolean is
5073       Obj : constant Node_Id := Prefix (N);
5074       Op  : constant Node_Id := Selector_Name (N);
5075
5076       Prim  : Elmt_Id;
5077       Prims : Elist_Id;
5078       Typ   : Entity_Id;
5079
5080    begin
5081       Set_Etype (Op, Any_Type);
5082
5083       if Is_Access_Type (Etype (Obj)) then
5084          Typ := Designated_Type (Etype (Obj));
5085       else
5086          Typ := Etype (Obj);
5087       end if;
5088
5089       if Is_Class_Wide_Type (Typ) then
5090          Typ := Root_Type (Typ);
5091       end if;
5092
5093       Prims := Primitive_Operations (Typ);
5094
5095       Prim := First_Elmt (Prims);
5096       while Present (Prim) loop
5097          if Chars (Node (Prim)) = Chars (Op) then
5098             Add_One_Interp (Op, Node (Prim), Etype (Node (Prim)));
5099             Set_Etype (N, Etype (Node (Prim)));
5100          end if;
5101
5102          Next_Elmt (Prim);
5103       end loop;
5104
5105       --  Now look for class-wide operations of the type or any of its
5106       --  ancestors by iterating over the homonyms of the selector.
5107
5108       declare
5109          Cls_Type : constant Entity_Id := Class_Wide_Type (Typ);
5110          Hom      : Entity_Id;
5111
5112       begin
5113          Hom := Current_Entity (Op);
5114          while Present (Hom) loop
5115             if (Ekind (Hom) = E_Procedure
5116                   or else
5117                 Ekind (Hom) = E_Function)
5118               and then Scope (Hom) = Scope (Typ)
5119               and then Present (First_Formal (Hom))
5120               and then
5121                 (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
5122                   or else
5123                     (Is_Access_Type (Etype (First_Formal (Hom)))
5124                        and then
5125                          Ekind (Etype (First_Formal (Hom))) =
5126                            E_Anonymous_Access_Type
5127                        and then
5128                          Base_Type
5129                            (Designated_Type (Etype (First_Formal (Hom)))) =
5130                                                                 Cls_Type))
5131             then
5132                Add_One_Interp (Op, Hom, Etype (Hom));
5133                Set_Etype (N, Etype (Hom));
5134             end if;
5135
5136             Hom := Homonym (Hom);
5137          end loop;
5138       end;
5139
5140       return Etype (Op) /= Any_Type;
5141    end Find_Primitive_Operation;
5142
5143    ----------------------
5144    -- Find_Unary_Types --
5145    ----------------------
5146
5147    procedure Find_Unary_Types
5148      (R     : Node_Id;
5149       Op_Id : Entity_Id;
5150       N     : Node_Id)
5151    is
5152       Index : Interp_Index;
5153       It    : Interp;
5154
5155    begin
5156       if not Is_Overloaded (R) then
5157          if Is_Numeric_Type (Etype (R)) then
5158             Add_One_Interp (N, Op_Id, Base_Type (Etype (R)));
5159          end if;
5160
5161       else
5162          Get_First_Interp (R, Index, It);
5163          while Present (It.Typ) loop
5164             if Is_Numeric_Type (It.Typ) then
5165                Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
5166             end if;
5167
5168             Get_Next_Interp (Index, It);
5169          end loop;
5170       end if;
5171    end Find_Unary_Types;
5172
5173    ------------------
5174    -- Junk_Operand --
5175    ------------------
5176
5177    function Junk_Operand (N : Node_Id) return Boolean is
5178       Enode : Node_Id;
5179
5180    begin
5181       if Error_Posted (N) then
5182          return False;
5183       end if;
5184
5185       --  Get entity to be tested
5186
5187       if Is_Entity_Name (N)
5188         and then Present (Entity (N))
5189       then
5190          Enode := N;
5191
5192       --  An odd case, a procedure name gets converted to a very peculiar
5193       --  function call, and here is where we detect this happening.
5194
5195       elsif Nkind (N) = N_Function_Call
5196         and then Is_Entity_Name (Name (N))
5197         and then Present (Entity (Name (N)))
5198       then
5199          Enode := Name (N);
5200
5201       --  Another odd case, there are at least some cases of selected
5202       --  components where the selected component is not marked as having
5203       --  an entity, even though the selector does have an entity
5204
5205       elsif Nkind (N) = N_Selected_Component
5206         and then Present (Entity (Selector_Name (N)))
5207       then
5208          Enode := Selector_Name (N);
5209
5210       else
5211          return False;
5212       end if;
5213
5214       --  Now test the entity we got to see if it is a bad case
5215
5216       case Ekind (Entity (Enode)) is
5217
5218          when E_Package =>
5219             Error_Msg_N
5220               ("package name cannot be used as operand", Enode);
5221
5222          when Generic_Unit_Kind =>
5223             Error_Msg_N
5224               ("generic unit name cannot be used as operand", Enode);
5225
5226          when Type_Kind =>
5227             Error_Msg_N
5228               ("subtype name cannot be used as operand", Enode);
5229
5230          when Entry_Kind =>
5231             Error_Msg_N
5232               ("entry name cannot be used as operand", Enode);
5233
5234          when E_Procedure =>
5235             Error_Msg_N
5236               ("procedure name cannot be used as operand", Enode);
5237
5238          when E_Exception =>
5239             Error_Msg_N
5240               ("exception name cannot be used as operand", Enode);
5241
5242          when E_Block | E_Label | E_Loop =>
5243             Error_Msg_N
5244               ("label name cannot be used as operand", Enode);
5245
5246          when others =>
5247             return False;
5248
5249       end case;
5250
5251       return True;
5252    end Junk_Operand;
5253
5254    --------------------
5255    -- Operator_Check --
5256    --------------------
5257
5258    procedure Operator_Check (N : Node_Id) is
5259    begin
5260       Remove_Abstract_Operations (N);
5261
5262       --  Test for case of no interpretation found for operator
5263
5264       if Etype (N) = Any_Type then
5265          declare
5266             L     : Node_Id;
5267             R     : Node_Id;
5268             Op_Id : Entity_Id := Empty;
5269
5270          begin
5271             R := Right_Opnd (N);
5272
5273             if Nkind (N) in N_Binary_Op then
5274                L := Left_Opnd (N);
5275             else
5276                L := Empty;
5277             end if;
5278
5279             --  If either operand has no type, then don't complain further,
5280             --  since this simply means that we have a propagated error.
5281
5282             if R = Error
5283               or else Etype (R) = Any_Type
5284               or else (Nkind (N) in N_Binary_Op and then Etype (L) = Any_Type)
5285             then
5286                return;
5287
5288             --  We explicitly check for the case of concatenation of component
5289             --  with component to avoid reporting spurious matching array types
5290             --  that might happen to be lurking in distant packages (such as
5291             --  run-time packages). This also prevents inconsistencies in the
5292             --  messages for certain ACVC B tests, which can vary depending on
5293             --  types declared in run-time interfaces. Another improvement when
5294             --  aggregates are present is to look for a well-typed operand.
5295
5296             elsif Present (Candidate_Type)
5297               and then (Nkind (N) /= N_Op_Concat
5298                          or else Is_Array_Type (Etype (L))
5299                          or else Is_Array_Type (Etype (R)))
5300             then
5301
5302                if Nkind (N) = N_Op_Concat then
5303                   if Etype (L) /= Any_Composite
5304                     and then Is_Array_Type (Etype (L))
5305                   then
5306                      Candidate_Type := Etype (L);
5307
5308                   elsif Etype (R) /= Any_Composite
5309                     and then Is_Array_Type (Etype (R))
5310                   then
5311                      Candidate_Type := Etype (R);
5312                   end if;
5313                end if;
5314
5315                Error_Msg_NE
5316                  ("operator for} is not directly visible!",
5317                   N, First_Subtype (Candidate_Type));
5318                Error_Msg_N ("use clause would make operation legal!",  N);
5319                return;
5320
5321             --  If either operand is a junk operand (e.g. package name), then
5322             --  post appropriate error messages, but do not complain further.
5323
5324             --  Note that the use of OR in this test instead of OR ELSE is
5325             --  quite deliberate, we may as well check both operands in the
5326             --  binary operator case.
5327
5328             elsif Junk_Operand (R)
5329               or (Nkind (N) in N_Binary_Op and then Junk_Operand (L))
5330             then
5331                return;
5332
5333             --  If we have a logical operator, one of whose operands is
5334             --  Boolean, then we know that the other operand cannot resolve to
5335             --  Boolean (since we got no interpretations), but in that case we
5336             --  pretty much know that the other operand should be Boolean, so
5337             --  resolve it that way (generating an error)
5338
5339             elsif Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor) then
5340                if Etype (L) = Standard_Boolean then
5341                   Resolve (R, Standard_Boolean);
5342                   return;
5343                elsif Etype (R) = Standard_Boolean then
5344                   Resolve (L, Standard_Boolean);
5345                   return;
5346                end if;
5347
5348             --  For an arithmetic operator or comparison operator, if one
5349             --  of the operands is numeric, then we know the other operand
5350             --  is not the same numeric type. If it is a non-numeric type,
5351             --  then probably it is intended to match the other operand.
5352
5353             elsif Nkind_In (N, N_Op_Add,
5354                                N_Op_Divide,
5355                                N_Op_Ge,
5356                                N_Op_Gt,
5357                                N_Op_Le)
5358               or else
5359                   Nkind_In (N, N_Op_Lt,
5360                                N_Op_Mod,
5361                                N_Op_Multiply,
5362                                N_Op_Rem,
5363                                N_Op_Subtract)
5364             then
5365                if Is_Numeric_Type (Etype (L))
5366                  and then not Is_Numeric_Type (Etype (R))
5367                then
5368                   Resolve (R, Etype (L));
5369                   return;
5370
5371                elsif Is_Numeric_Type (Etype (R))
5372                  and then not Is_Numeric_Type (Etype (L))
5373                then
5374                   Resolve (L, Etype (R));
5375                   return;
5376                end if;
5377
5378             --  Comparisons on A'Access are common enough to deserve a
5379             --  special message.
5380
5381             elsif Nkind_In (N, N_Op_Eq, N_Op_Ne)
5382                and then Ekind (Etype (L)) = E_Access_Attribute_Type
5383                and then Ekind (Etype (R)) = E_Access_Attribute_Type
5384             then
5385                Error_Msg_N
5386                  ("two access attributes cannot be compared directly", N);
5387                Error_Msg_N
5388                  ("\use qualified expression for one of the operands",
5389                    N);
5390                return;
5391
5392             --  Another one for C programmers
5393
5394             elsif Nkind (N) = N_Op_Concat
5395               and then Valid_Boolean_Arg (Etype (L))
5396               and then Valid_Boolean_Arg (Etype (R))
5397             then
5398                Error_Msg_N ("invalid operands for concatenation", N);
5399                Error_Msg_N -- CODEFIX
5400                  ("\maybe AND was meant", N);
5401                return;
5402
5403             --  A special case for comparison of access parameter with null
5404
5405             elsif Nkind (N) = N_Op_Eq
5406               and then Is_Entity_Name (L)
5407               and then Nkind (Parent (Entity (L))) = N_Parameter_Specification
5408               and then Nkind (Parameter_Type (Parent (Entity (L)))) =
5409                                                   N_Access_Definition
5410               and then Nkind (R) = N_Null
5411             then
5412                Error_Msg_N ("access parameter is not allowed to be null", L);
5413                Error_Msg_N ("\(call would raise Constraint_Error)", L);
5414                return;
5415
5416             --  Another special case for exponentiation, where the right
5417             --  operand must be Natural, independently of the base.
5418
5419             elsif Nkind (N) = N_Op_Expon
5420               and then Is_Numeric_Type (Etype (L))
5421               and then not Is_Overloaded (R)
5422               and then
5423                 First_Subtype (Base_Type (Etype (R))) /= Standard_Integer
5424               and then Base_Type (Etype (R)) /= Universal_Integer
5425             then
5426                Error_Msg_NE
5427                  ("exponent must be of type Natural, found}", R, Etype (R));
5428                return;
5429             end if;
5430
5431             --  If we fall through then just give general message. Note that in
5432             --  the following messages, if the operand is overloaded we choose
5433             --  an arbitrary type to complain about, but that is probably more
5434             --  useful than not giving a type at all.
5435
5436             if Nkind (N) in N_Unary_Op then
5437                Error_Msg_Node_2 := Etype (R);
5438                Error_Msg_N ("operator& not defined for}", N);
5439                return;
5440
5441             else
5442                if Nkind (N) in N_Binary_Op then
5443                   if not Is_Overloaded (L)
5444                     and then not Is_Overloaded (R)
5445                     and then Base_Type (Etype (L)) = Base_Type (Etype (R))
5446                   then
5447                      Error_Msg_Node_2 := First_Subtype (Etype (R));
5448                      Error_Msg_N ("there is no applicable operator& for}", N);
5449
5450                   else
5451                      --  Another attempt to find a fix: one of the candidate
5452                      --  interpretations may not be use-visible. This has
5453                      --  already been checked for predefined operators, so
5454                      --  we examine only user-defined functions.
5455
5456                      Op_Id := Get_Name_Entity_Id (Chars (N));
5457
5458                      while Present (Op_Id) loop
5459                         if Ekind (Op_Id) /= E_Operator
5460                           and then Is_Overloadable (Op_Id)
5461                         then
5462                            if not Is_Immediately_Visible (Op_Id)
5463                              and then not In_Use (Scope (Op_Id))
5464                              and then not Is_Abstract_Subprogram (Op_Id)
5465                              and then not Is_Hidden (Op_Id)
5466                              and then Ekind (Scope (Op_Id)) = E_Package
5467                              and then
5468                                Has_Compatible_Type
5469                                  (L, Etype (First_Formal (Op_Id)))
5470                              and then Present
5471                               (Next_Formal (First_Formal (Op_Id)))
5472                              and then
5473                                Has_Compatible_Type
5474                                  (R,
5475                                   Etype (Next_Formal (First_Formal (Op_Id))))
5476                            then
5477                               Error_Msg_N
5478                                 ("No legal interpretation for operator&", N);
5479                               Error_Msg_NE
5480                                 ("\use clause on& would make operation legal",
5481                                    N, Scope (Op_Id));
5482                               exit;
5483                            end if;
5484                         end if;
5485
5486                         Op_Id := Homonym (Op_Id);
5487                      end loop;
5488
5489                      if No (Op_Id) then
5490                         Error_Msg_N ("invalid operand types for operator&", N);
5491
5492                         if Nkind (N) /= N_Op_Concat then
5493                            Error_Msg_NE ("\left operand has}!",  N, Etype (L));
5494                            Error_Msg_NE ("\right operand has}!", N, Etype (R));
5495                         end if;
5496                      end if;
5497                   end if;
5498                end if;
5499             end if;
5500          end;
5501       end if;
5502    end Operator_Check;
5503
5504    -----------------------------------------
5505    -- Process_Implicit_Dereference_Prefix --
5506    -----------------------------------------
5507
5508    function Process_Implicit_Dereference_Prefix
5509      (E : Entity_Id;
5510       P : Entity_Id) return Entity_Id
5511    is
5512       Ref : Node_Id;
5513       Typ : constant Entity_Id := Designated_Type (Etype (P));
5514
5515    begin
5516       if Present (E)
5517         and then (Operating_Mode = Check_Semantics or else not Expander_Active)
5518       then
5519          --  We create a dummy reference to E to ensure that the reference
5520          --  is not considered as part of an assignment (an implicit
5521          --  dereference can never assign to its prefix). The Comes_From_Source
5522          --  attribute needs to be propagated for accurate warnings.
5523
5524          Ref := New_Reference_To (E, Sloc (P));
5525          Set_Comes_From_Source (Ref, Comes_From_Source (P));
5526          Generate_Reference (E, Ref);
5527       end if;
5528
5529       --  An implicit dereference is a legal occurrence of an
5530       --  incomplete type imported through a limited_with clause,
5531       --  if the full view is visible.
5532
5533       if From_With_Type (Typ)
5534         and then not From_With_Type (Scope (Typ))
5535         and then
5536           (Is_Immediately_Visible (Scope (Typ))
5537             or else
5538               (Is_Child_Unit (Scope (Typ))
5539                  and then Is_Visible_Child_Unit (Scope (Typ))))
5540       then
5541          return Available_View (Typ);
5542       else
5543          return Typ;
5544       end if;
5545
5546    end Process_Implicit_Dereference_Prefix;
5547
5548    --------------------------------
5549    -- Remove_Abstract_Operations --
5550    --------------------------------
5551
5552    procedure Remove_Abstract_Operations (N : Node_Id) is
5553       Abstract_Op    : Entity_Id := Empty;
5554       Address_Kludge : Boolean := False;
5555       I              : Interp_Index;
5556       It             : Interp;
5557
5558       --  AI-310: If overloaded, remove abstract non-dispatching operations. We
5559       --  activate this if either extensions are enabled, or if the abstract
5560       --  operation in question comes from a predefined file. This latter test
5561       --  allows us to use abstract to make operations invisible to users. In
5562       --  particular, if type Address is non-private and abstract subprograms
5563       --  are used to hide its operators, they will be truly hidden.
5564
5565       type Operand_Position is (First_Op, Second_Op);
5566       Univ_Type : constant Entity_Id := Universal_Interpretation (N);
5567
5568       procedure Remove_Address_Interpretations (Op : Operand_Position);
5569       --  Ambiguities may arise when the operands are literal and the address
5570       --  operations in s-auxdec are visible. In that case, remove the
5571       --  interpretation of a literal as Address, to retain the semantics of
5572       --  Address as a private type.
5573
5574       ------------------------------------
5575       -- Remove_Address_Interpretations --
5576       ------------------------------------
5577
5578       procedure Remove_Address_Interpretations (Op : Operand_Position) is
5579          Formal : Entity_Id;
5580
5581       begin
5582          if Is_Overloaded (N) then
5583             Get_First_Interp (N, I, It);
5584             while Present (It.Nam) loop
5585                Formal := First_Entity (It.Nam);
5586
5587                if Op = Second_Op then
5588                   Formal := Next_Entity (Formal);
5589                end if;
5590
5591                if Is_Descendent_Of_Address (Etype (Formal)) then
5592                   Address_Kludge := True;
5593                   Remove_Interp (I);
5594                end if;
5595
5596                Get_Next_Interp (I, It);
5597             end loop;
5598          end if;
5599       end Remove_Address_Interpretations;
5600
5601    --  Start of processing for Remove_Abstract_Operations
5602
5603    begin
5604       if Is_Overloaded (N) then
5605          Get_First_Interp (N, I, It);
5606
5607          while Present (It.Nam) loop
5608             if Is_Overloadable (It.Nam)
5609               and then Is_Abstract_Subprogram (It.Nam)
5610               and then not Is_Dispatching_Operation (It.Nam)
5611             then
5612                Abstract_Op := It.Nam;
5613
5614                if Is_Descendent_Of_Address (It.Typ) then
5615                   Address_Kludge := True;
5616                   Remove_Interp (I);
5617                   exit;
5618
5619                --  In Ada 2005, this operation does not participate in Overload
5620                --  resolution. If the operation is defined in a predefined
5621                --  unit, it is one of the operations declared abstract in some
5622                --  variants of System, and it must be removed as well.
5623
5624                elsif Ada_Version >= Ada_05
5625                  or else Is_Predefined_File_Name
5626                            (Unit_File_Name (Get_Source_Unit (It.Nam)))
5627                then
5628                   Remove_Interp (I);
5629                   exit;
5630                end if;
5631             end if;
5632
5633             Get_Next_Interp (I, It);
5634          end loop;
5635
5636          if No (Abstract_Op) then
5637
5638             --  If some interpretation yields an integer type, it is still
5639             --  possible that there are address interpretations. Remove them
5640             --  if one operand is a literal, to avoid spurious ambiguities
5641             --  on systems where Address is a visible integer type.
5642
5643             if Is_Overloaded (N)
5644               and then Nkind (N) in N_Op
5645               and then Is_Integer_Type (Etype (N))
5646             then
5647                if Nkind (N) in N_Binary_Op then
5648                   if Nkind (Right_Opnd (N)) = N_Integer_Literal then
5649                      Remove_Address_Interpretations (Second_Op);
5650
5651                   elsif Nkind (Right_Opnd (N)) = N_Integer_Literal then
5652                      Remove_Address_Interpretations (First_Op);
5653                   end if;
5654                end if;
5655             end if;
5656
5657          elsif Nkind (N) in N_Op then
5658
5659             --  Remove interpretations that treat literals as addresses. This
5660             --  is never appropriate, even when Address is defined as a visible
5661             --  Integer type. The reason is that we would really prefer Address
5662             --  to behave as a private type, even in this case, which is there
5663             --  only to accommodate oddities of VMS address sizes. If Address
5664             --  is a visible integer type, we get lots of overload ambiguities.
5665
5666             if Nkind (N) in N_Binary_Op then
5667                declare
5668                   U1 : constant Boolean :=
5669                      Present (Universal_Interpretation (Right_Opnd (N)));
5670                   U2 : constant Boolean :=
5671                      Present (Universal_Interpretation (Left_Opnd (N)));
5672
5673                begin
5674                   if U1 then
5675                      Remove_Address_Interpretations (Second_Op);
5676                   end if;
5677
5678                   if U2 then
5679                      Remove_Address_Interpretations (First_Op);
5680                   end if;
5681
5682                   if not (U1 and U2) then
5683
5684                      --  Remove corresponding predefined operator, which is
5685                      --  always added to the overload set.
5686
5687                      Get_First_Interp (N, I, It);
5688                      while Present (It.Nam) loop
5689                         if Scope (It.Nam) = Standard_Standard
5690                           and then Base_Type (It.Typ) =
5691                                    Base_Type (Etype (Abstract_Op))
5692                         then
5693                            Remove_Interp (I);
5694                         end if;
5695
5696                         Get_Next_Interp (I, It);
5697                      end loop;
5698
5699                   elsif Is_Overloaded (N)
5700                     and then Present (Univ_Type)
5701                   then
5702                      --  If both operands have a universal interpretation,
5703                      --  it is still necessary to remove interpretations that
5704                      --  yield Address. Any remaining ambiguities will be
5705                      --  removed in Disambiguate.
5706
5707                      Get_First_Interp (N, I, It);
5708                      while Present (It.Nam) loop
5709                         if Is_Descendent_Of_Address (It.Typ) then
5710                            Remove_Interp (I);
5711
5712                         elsif not Is_Type (It.Nam) then
5713                            Set_Entity (N, It.Nam);
5714                         end if;
5715
5716                         Get_Next_Interp (I, It);
5717                      end loop;
5718                   end if;
5719                end;
5720             end if;
5721
5722          elsif Nkind (N) = N_Function_Call
5723            and then
5724              (Nkind (Name (N)) = N_Operator_Symbol
5725                 or else
5726                   (Nkind (Name (N)) = N_Expanded_Name
5727                      and then
5728                        Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
5729          then
5730
5731             declare
5732                Arg1 : constant Node_Id := First (Parameter_Associations (N));
5733                U1   : constant Boolean :=
5734                         Present (Universal_Interpretation (Arg1));
5735                U2   : constant Boolean :=
5736                         Present (Next (Arg1)) and then
5737                         Present (Universal_Interpretation (Next (Arg1)));
5738
5739             begin
5740                if U1 then
5741                   Remove_Address_Interpretations (First_Op);
5742                end if;
5743
5744                if U2 then
5745                   Remove_Address_Interpretations (Second_Op);
5746                end if;
5747
5748                if not (U1 and U2) then
5749                   Get_First_Interp (N, I, It);
5750                   while Present (It.Nam) loop
5751                      if Scope (It.Nam) = Standard_Standard
5752                        and then It.Typ = Base_Type (Etype (Abstract_Op))
5753                      then
5754                         Remove_Interp (I);
5755                      end if;
5756
5757                      Get_Next_Interp (I, It);
5758                   end loop;
5759                end if;
5760             end;
5761          end if;
5762
5763          --  If the removal has left no valid interpretations, emit an error
5764          --  message now and label node as illegal.
5765
5766          if Present (Abstract_Op) then
5767             Get_First_Interp (N, I, It);
5768
5769             if No (It.Nam) then
5770
5771                --  Removal of abstract operation left no viable candidate
5772
5773                Set_Etype (N, Any_Type);
5774                Error_Msg_Sloc := Sloc (Abstract_Op);
5775                Error_Msg_NE
5776                  ("cannot call abstract operation& declared#", N, Abstract_Op);
5777
5778             --  In Ada 2005, an abstract operation may disable predefined
5779             --  operators. Since the context is not yet known, we mark the
5780             --  predefined operators as potentially hidden. Do not include
5781             --  predefined operators when addresses are involved since this
5782             --  case is handled separately.
5783
5784             elsif Ada_Version >= Ada_05
5785               and then not Address_Kludge
5786             then
5787                while Present (It.Nam) loop
5788                   if Is_Numeric_Type (It.Typ)
5789                     and then Scope (It.Typ) = Standard_Standard
5790                   then
5791                      Set_Abstract_Op (I, Abstract_Op);
5792                   end if;
5793
5794                   Get_Next_Interp (I, It);
5795                end loop;
5796             end if;
5797          end if;
5798       end if;
5799    end Remove_Abstract_Operations;
5800
5801    -----------------------
5802    -- Try_Indirect_Call --
5803    -----------------------
5804
5805    function Try_Indirect_Call
5806      (N   : Node_Id;
5807       Nam : Entity_Id;
5808       Typ : Entity_Id) return Boolean
5809    is
5810       Actual : Node_Id;
5811       Formal : Entity_Id;
5812
5813       Call_OK : Boolean;
5814       pragma Warnings (Off, Call_OK);
5815
5816    begin
5817       Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
5818
5819       Actual := First_Actual (N);
5820       Formal := First_Formal (Designated_Type (Typ));
5821       while Present (Actual) and then Present (Formal) loop
5822          if not Has_Compatible_Type (Actual, Etype (Formal)) then
5823             return False;
5824          end if;
5825
5826          Next (Actual);
5827          Next_Formal (Formal);
5828       end loop;
5829
5830       if No (Actual) and then No (Formal) then
5831          Add_One_Interp (N, Nam, Etype (Designated_Type (Typ)));
5832
5833          --  Nam is a candidate interpretation for the name in the call,
5834          --  if it is not an indirect call.
5835
5836          if not Is_Type (Nam)
5837             and then Is_Entity_Name (Name (N))
5838          then
5839             Set_Entity (Name (N), Nam);
5840          end if;
5841
5842          return True;
5843       else
5844          return False;
5845       end if;
5846    end Try_Indirect_Call;
5847
5848    ----------------------
5849    -- Try_Indexed_Call --
5850    ----------------------
5851
5852    function Try_Indexed_Call
5853      (N          : Node_Id;
5854       Nam        : Entity_Id;
5855       Typ        : Entity_Id;
5856       Skip_First : Boolean) return Boolean
5857    is
5858       Loc     : constant Source_Ptr := Sloc (N);
5859       Actuals : constant List_Id    := Parameter_Associations (N);
5860       Actual  : Node_Id;
5861       Index   : Entity_Id;
5862
5863    begin
5864       Actual := First (Actuals);
5865
5866       --  If the call was originally written in prefix form, skip the first
5867       --  actual, which is obviously not defaulted.
5868
5869       if Skip_First then
5870          Next (Actual);
5871       end if;
5872
5873       Index := First_Index (Typ);
5874       while Present (Actual) and then Present (Index) loop
5875
5876          --  If the parameter list has a named association, the expression
5877          --  is definitely a call and not an indexed component.
5878
5879          if Nkind (Actual) = N_Parameter_Association then
5880             return False;
5881          end if;
5882
5883          if Is_Entity_Name (Actual)
5884            and then Is_Type (Entity (Actual))
5885            and then No (Next (Actual))
5886          then
5887             Rewrite (N,
5888               Make_Slice (Loc,
5889                 Prefix => Make_Function_Call (Loc,
5890                   Name => Relocate_Node (Name (N))),
5891                 Discrete_Range =>
5892                   New_Occurrence_Of (Entity (Actual), Sloc (Actual))));
5893
5894             Analyze (N);
5895             return True;
5896
5897          elsif not Has_Compatible_Type (Actual, Etype (Index)) then
5898             return False;
5899          end if;
5900
5901          Next (Actual);
5902          Next_Index (Index);
5903       end loop;
5904
5905       if No (Actual) and then No (Index) then
5906          Add_One_Interp (N, Nam, Component_Type (Typ));
5907
5908          --  Nam is a candidate interpretation for the name in the call,
5909          --  if it is not an indirect call.
5910
5911          if not Is_Type (Nam)
5912             and then Is_Entity_Name (Name (N))
5913          then
5914             Set_Entity (Name (N), Nam);
5915          end if;
5916
5917          return True;
5918       else
5919          return False;
5920       end if;
5921    end Try_Indexed_Call;
5922
5923    --------------------------
5924    -- Try_Object_Operation --
5925    --------------------------
5926
5927    function Try_Object_Operation (N : Node_Id) return Boolean is
5928       K              : constant Node_Kind  := Nkind (Parent (N));
5929       Is_Subprg_Call : constant Boolean    := Nkind_In
5930                                                (K, N_Procedure_Call_Statement,
5931                                                    N_Function_Call);
5932       Loc            : constant Source_Ptr := Sloc (N);
5933       Obj            : constant Node_Id    := Prefix (N);
5934       Subprog        : constant Node_Id    :=
5935                          Make_Identifier (Sloc (Selector_Name (N)),
5936                            Chars => Chars (Selector_Name (N)));
5937       --  Identifier on which possible interpretations will be collected
5938
5939       Report_Error : Boolean := False;
5940       --  If no candidate interpretation matches the context, redo the
5941       --  analysis with error enabled to provide additional information.
5942
5943       Actual          : Node_Id;
5944       Candidate       : Entity_Id := Empty;
5945       New_Call_Node   : Node_Id := Empty;
5946       Node_To_Replace : Node_Id;
5947       Obj_Type        : Entity_Id := Etype (Obj);
5948       Success         : Boolean := False;
5949
5950       function Valid_Candidate
5951         (Success : Boolean;
5952          Call    : Node_Id;
5953          Subp    : Entity_Id) return Entity_Id;
5954       --  If the subprogram is a valid interpretation, record it, and add
5955       --  to the list of interpretations of Subprog.
5956
5957       procedure Complete_Object_Operation
5958         (Call_Node       : Node_Id;
5959          Node_To_Replace : Node_Id);
5960       --  Make Subprog the name of Call_Node, replace Node_To_Replace with
5961       --  Call_Node, insert the object (or its dereference) as the first actual
5962       --  in the call, and complete the analysis of the call.
5963
5964       procedure Report_Ambiguity (Op : Entity_Id);
5965       --  If a prefixed procedure call is ambiguous, indicate whether the
5966       --  call includes an implicit dereference or an implicit 'Access.
5967
5968       procedure Transform_Object_Operation
5969         (Call_Node       : out Node_Id;
5970          Node_To_Replace : out Node_Id);
5971       --  Transform Obj.Operation (X, Y,,) into Operation (Obj, X, Y ..)
5972       --  Call_Node is the resulting subprogram call, Node_To_Replace is
5973       --  either N or the parent of N, and Subprog is a reference to the
5974       --  subprogram we are trying to match.
5975
5976       function Try_Class_Wide_Operation
5977         (Call_Node       : Node_Id;
5978          Node_To_Replace : Node_Id) return Boolean;
5979       --  Traverse all ancestor types looking for a class-wide subprogram
5980       --  for which the current operation is a valid non-dispatching call.
5981
5982       procedure Try_One_Prefix_Interpretation (T : Entity_Id);
5983       --  If prefix is overloaded, its interpretation may include different
5984       --  tagged types, and we must examine the primitive operations and
5985       --  the class-wide operations of each in order to find candidate
5986       --  interpretations for the call as a whole.
5987
5988       function Try_Primitive_Operation
5989         (Call_Node       : Node_Id;
5990          Node_To_Replace : Node_Id) return Boolean;
5991       --  Traverse the list of primitive subprograms looking for a dispatching
5992       --  operation for which the current node is a valid call .
5993
5994       ---------------------
5995       -- Valid_Candidate --
5996       ---------------------
5997
5998       function Valid_Candidate
5999         (Success : Boolean;
6000          Call    : Node_Id;
6001          Subp    : Entity_Id) return Entity_Id
6002       is
6003          Arr_Type  : Entity_Id;
6004          Comp_Type : Entity_Id;
6005
6006       begin
6007          --  If the subprogram is a valid interpretation, record it in global
6008          --  variable Subprog, to collect all possible overloadings.
6009
6010          if Success then
6011             if Subp /= Entity (Subprog) then
6012                Add_One_Interp (Subprog, Subp, Etype (Subp));
6013             end if;
6014          end if;
6015
6016          --  If the call may be an indexed call, retrieve component type of
6017          --  resulting expression, and add possible interpretation.
6018
6019          Arr_Type  := Empty;
6020          Comp_Type := Empty;
6021
6022          if Nkind (Call) = N_Function_Call
6023            and then Nkind (Parent (N)) = N_Indexed_Component
6024            and then Needs_One_Actual (Subp)
6025          then
6026             if Is_Array_Type (Etype (Subp)) then
6027                Arr_Type := Etype (Subp);
6028
6029             elsif Is_Access_Type (Etype (Subp))
6030               and then Is_Array_Type (Designated_Type (Etype (Subp)))
6031             then
6032                Arr_Type := Designated_Type (Etype (Subp));
6033             end if;
6034          end if;
6035
6036          if Present (Arr_Type) then
6037
6038             --  Verify that the actuals (excluding the object)
6039             --  match the types of the indices.
6040
6041             declare
6042                Actual : Node_Id;
6043                Index  : Node_Id;
6044
6045             begin
6046                Actual := Next (First_Actual (Call));
6047                Index  := First_Index (Arr_Type);
6048                while Present (Actual) and then Present (Index) loop
6049                   if not Has_Compatible_Type (Actual, Etype (Index)) then
6050                      Arr_Type := Empty;
6051                      exit;
6052                   end if;
6053
6054                   Next_Actual (Actual);
6055                   Next_Index  (Index);
6056                end loop;
6057
6058                if No (Actual)
6059                   and then No (Index)
6060                   and then Present (Arr_Type)
6061                then
6062                   Comp_Type := Component_Type (Arr_Type);
6063                end if;
6064             end;
6065
6066             if Present (Comp_Type)
6067               and then Etype (Subprog) /= Comp_Type
6068             then
6069                Add_One_Interp (Subprog, Subp, Comp_Type);
6070             end if;
6071          end if;
6072
6073          if Etype (Call) /= Any_Type then
6074             return Subp;
6075          else
6076             return Empty;
6077          end if;
6078       end Valid_Candidate;
6079
6080       -------------------------------
6081       -- Complete_Object_Operation --
6082       -------------------------------
6083
6084       procedure Complete_Object_Operation
6085         (Call_Node       : Node_Id;
6086          Node_To_Replace : Node_Id)
6087       is
6088          Control      : constant Entity_Id := First_Formal (Entity (Subprog));
6089          Formal_Type  : constant Entity_Id := Etype (Control);
6090          First_Actual : Node_Id;
6091
6092       begin
6093          --  Place the name of the operation, with its interpretations,
6094          --  on the rewritten call.
6095
6096          Set_Name (Call_Node, Subprog);
6097
6098          First_Actual := First (Parameter_Associations (Call_Node));
6099
6100          --  For cross-reference purposes, treat the new node as being in
6101          --  the source if the original one is.
6102
6103          Set_Comes_From_Source (Subprog, Comes_From_Source (N));
6104          Set_Comes_From_Source (Call_Node, Comes_From_Source (N));
6105
6106          if Nkind (N) = N_Selected_Component
6107            and then not Inside_A_Generic
6108          then
6109             Set_Entity (Selector_Name (N), Entity (Subprog));
6110          end if;
6111
6112          --  If need be, rewrite first actual as an explicit dereference
6113          --  If the call is overloaded, the rewriting can only be done
6114          --  once the primitive operation is identified.
6115
6116          if Is_Overloaded (Subprog) then
6117
6118             --  The prefix itself may be overloaded, and its interpretations
6119             --  must be propagated to the new actual in the call.
6120
6121             if Is_Overloaded (Obj) then
6122                Save_Interps (Obj, First_Actual);
6123             end if;
6124
6125             Rewrite (First_Actual, Obj);
6126
6127          elsif not Is_Access_Type (Formal_Type)
6128            and then Is_Access_Type (Etype (Obj))
6129          then
6130             Rewrite (First_Actual,
6131               Make_Explicit_Dereference (Sloc (Obj), Obj));
6132             Analyze (First_Actual);
6133
6134             --  If we need to introduce an explicit dereference, verify that
6135             --  the resulting actual is compatible with the mode of the formal.
6136
6137             if Ekind (First_Formal (Entity (Subprog))) /= E_In_Parameter
6138               and then Is_Access_Constant (Etype (Obj))
6139             then
6140                Error_Msg_NE
6141                  ("expect variable in call to&", Prefix (N), Entity (Subprog));
6142             end if;
6143
6144          --  Conversely, if the formal is an access parameter and the object
6145          --  is not, replace the actual with a 'Access reference. Its analysis
6146          --  will check that the object is aliased.
6147
6148          elsif Is_Access_Type (Formal_Type)
6149            and then not Is_Access_Type (Etype (Obj))
6150          then
6151             --  A special case: A.all'access is illegal if A is an access to a
6152             --  constant and the context requires an access to a variable.
6153
6154             if not Is_Access_Constant (Formal_Type) then
6155                if (Nkind (Obj) = N_Explicit_Dereference
6156                     and then Is_Access_Constant (Etype (Prefix (Obj))))
6157                  or else not Is_Variable (Obj)
6158                then
6159                   Error_Msg_NE
6160                     ("actual for& must be a variable", Obj, Control);
6161                end if;
6162             end if;
6163
6164             Rewrite (First_Actual,
6165               Make_Attribute_Reference (Loc,
6166                 Attribute_Name => Name_Access,
6167                 Prefix => Relocate_Node (Obj)));
6168
6169             if not Is_Aliased_View (Obj) then
6170                Error_Msg_NE
6171                  ("object in prefixed call to& must be aliased"
6172                       & " (RM-2005 4.3.1 (13))",
6173                  Prefix (First_Actual), Subprog);
6174             end if;
6175
6176             Analyze (First_Actual);
6177
6178          else
6179             if Is_Overloaded (Obj) then
6180                Save_Interps (Obj, First_Actual);
6181             end if;
6182
6183             Rewrite (First_Actual, Obj);
6184          end if;
6185
6186          Rewrite (Node_To_Replace, Call_Node);
6187
6188          --  Propagate the interpretations collected in subprog to the new
6189          --  function call node, to be resolved from context.
6190
6191          if Is_Overloaded (Subprog) then
6192             Save_Interps (Subprog, Node_To_Replace);
6193
6194          else
6195             Analyze (Node_To_Replace);
6196
6197             --  If the operation has been rewritten into a call, which may
6198             --  get subsequently an explicit dereference, preserve the
6199             --  type on the original node (selected component or indexed
6200             --  component) for subsequent legality tests, e.g. Is_Variable.
6201             --  which examines the original node.
6202
6203             if Nkind (Node_To_Replace) = N_Function_Call then
6204                Set_Etype
6205                  (Original_Node (Node_To_Replace), Etype (Node_To_Replace));
6206             end if;
6207          end if;
6208       end Complete_Object_Operation;
6209
6210       ----------------------
6211       -- Report_Ambiguity --
6212       ----------------------
6213
6214       procedure Report_Ambiguity (Op : Entity_Id) is
6215          Access_Formal : constant Boolean :=
6216                            Is_Access_Type (Etype (First_Formal (Op)));
6217          Access_Actual : constant Boolean :=
6218                            Is_Access_Type (Etype (Prefix (N)));
6219
6220       begin
6221          Error_Msg_Sloc := Sloc (Op);
6222
6223          if Access_Formal and then not Access_Actual then
6224             if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6225                Error_Msg_N
6226                  ("\possible interpretation"
6227                    & " (inherited, with implicit 'Access) #", N);
6228             else
6229                Error_Msg_N
6230                  ("\possible interpretation (with implicit 'Access) #", N);
6231             end if;
6232
6233          elsif not Access_Formal and then Access_Actual then
6234             if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6235                Error_Msg_N
6236                  ("\possible interpretation"
6237                    & " ( inherited, with implicit dereference) #", N);
6238             else
6239                Error_Msg_N
6240                  ("\possible interpretation (with implicit dereference) #", N);
6241             end if;
6242
6243          else
6244             if Nkind (Parent (Op)) = N_Full_Type_Declaration then
6245                Error_Msg_N ("\possible interpretation (inherited)#", N);
6246             else
6247                Error_Msg_N -- CODEFIX
6248                  ("\possible interpretation#", N);
6249             end if;
6250          end if;
6251       end Report_Ambiguity;
6252
6253       --------------------------------
6254       -- Transform_Object_Operation --
6255       --------------------------------
6256
6257       procedure Transform_Object_Operation
6258         (Call_Node       : out Node_Id;
6259          Node_To_Replace : out Node_Id)
6260       is
6261          Dummy : constant Node_Id := New_Copy (Obj);
6262          --  Placeholder used as a first parameter in the call, replaced
6263          --  eventually by the proper object.
6264
6265          Parent_Node : constant Node_Id := Parent (N);
6266
6267          Actual  : Node_Id;
6268          Actuals : List_Id;
6269
6270       begin
6271          --  Common case covering 1) Call to a procedure and 2) Call to a
6272          --  function that has some additional actuals.
6273
6274          if Nkind_In (Parent_Node, N_Function_Call,
6275                                    N_Procedure_Call_Statement)
6276
6277             --  N is a selected component node containing the name of the
6278             --  subprogram. If N is not the name of the parent node we must
6279             --  not replace the parent node by the new construct. This case
6280             --  occurs when N is a parameterless call to a subprogram that
6281             --  is an actual parameter of a call to another subprogram. For
6282             --  example:
6283             --            Some_Subprogram (..., Obj.Operation, ...)
6284
6285             and then Name (Parent_Node) = N
6286          then
6287             Node_To_Replace := Parent_Node;
6288
6289             Actuals := Parameter_Associations (Parent_Node);
6290
6291             if Present (Actuals) then
6292                Prepend (Dummy, Actuals);
6293             else
6294                Actuals := New_List (Dummy);
6295             end if;
6296
6297             if Nkind (Parent_Node) = N_Procedure_Call_Statement then
6298                Call_Node :=
6299                  Make_Procedure_Call_Statement (Loc,
6300                    Name => New_Copy (Subprog),
6301                    Parameter_Associations => Actuals);
6302
6303             else
6304                Call_Node :=
6305                  Make_Function_Call (Loc,
6306                    Name => New_Copy (Subprog),
6307                    Parameter_Associations => Actuals);
6308
6309             end if;
6310
6311          --  Before analysis, a function call appears as an indexed component
6312          --  if there are no named associations.
6313
6314          elsif Nkind (Parent_Node) =  N_Indexed_Component
6315            and then N = Prefix (Parent_Node)
6316          then
6317             Node_To_Replace := Parent_Node;
6318
6319             Actuals := Expressions (Parent_Node);
6320
6321             Actual := First (Actuals);
6322             while Present (Actual) loop
6323                Analyze (Actual);
6324                Next (Actual);
6325             end loop;
6326
6327             Prepend (Dummy, Actuals);
6328
6329             Call_Node :=
6330                Make_Function_Call (Loc,
6331                  Name => New_Copy (Subprog),
6332                  Parameter_Associations => Actuals);
6333
6334          --  Parameterless call: Obj.F is rewritten as F (Obj)
6335
6336          else
6337             Node_To_Replace := N;
6338
6339             Call_Node :=
6340                Make_Function_Call (Loc,
6341                  Name => New_Copy (Subprog),
6342                  Parameter_Associations => New_List (Dummy));
6343          end if;
6344       end Transform_Object_Operation;
6345
6346       ------------------------------
6347       -- Try_Class_Wide_Operation --
6348       ------------------------------
6349
6350       function Try_Class_Wide_Operation
6351         (Call_Node       : Node_Id;
6352          Node_To_Replace : Node_Id) return Boolean
6353       is
6354          Anc_Type    : Entity_Id;
6355          Matching_Op : Entity_Id := Empty;
6356          Error       : Boolean;
6357
6358          procedure Traverse_Homonyms
6359            (Anc_Type : Entity_Id;
6360             Error    : out Boolean);
6361          --  Traverse the homonym chain of the subprogram searching for those
6362          --  homonyms whose first formal has the Anc_Type's class-wide type,
6363          --  or an anonymous access type designating the class-wide type. If
6364          --  an ambiguity is detected, then Error is set to True.
6365
6366          procedure Traverse_Interfaces
6367            (Anc_Type : Entity_Id;
6368             Error    : out Boolean);
6369          --  Traverse the list of interfaces, if any, associated with Anc_Type
6370          --  and search for acceptable class-wide homonyms associated with each
6371          --  interface. If an ambiguity is detected, then Error is set to True.
6372
6373          -----------------------
6374          -- Traverse_Homonyms --
6375          -----------------------
6376
6377          procedure Traverse_Homonyms
6378            (Anc_Type : Entity_Id;
6379             Error    : out Boolean)
6380          is
6381             Cls_Type    : Entity_Id;
6382             Hom         : Entity_Id;
6383             Hom_Ref     : Node_Id;
6384             Success     : Boolean;
6385
6386          begin
6387             Error := False;
6388
6389             Cls_Type := Class_Wide_Type (Anc_Type);
6390
6391             Hom := Current_Entity (Subprog);
6392
6393             --  Find operation whose first parameter is of the class-wide
6394             --  type, a subtype thereof, or an anonymous access to same.
6395
6396             while Present (Hom) loop
6397                if (Ekind (Hom) = E_Procedure
6398                      or else
6399                    Ekind (Hom) = E_Function)
6400                  and then Scope (Hom) = Scope (Anc_Type)
6401                  and then Present (First_Formal (Hom))
6402                  and then
6403                    (Base_Type (Etype (First_Formal (Hom))) = Cls_Type
6404                      or else
6405                        (Is_Access_Type (Etype (First_Formal (Hom)))
6406                           and then
6407                             Ekind (Etype (First_Formal (Hom))) =
6408                               E_Anonymous_Access_Type
6409                           and then
6410                             Base_Type
6411                               (Designated_Type (Etype (First_Formal (Hom)))) =
6412                                                                    Cls_Type))
6413                then
6414                   Set_Etype (Call_Node, Any_Type);
6415                   Set_Is_Overloaded (Call_Node, False);
6416                   Success := False;
6417
6418                   if No (Matching_Op) then
6419                      Hom_Ref := New_Reference_To (Hom, Sloc (Subprog));
6420                      Set_Etype (Call_Node, Any_Type);
6421                      Set_Parent (Call_Node, Parent (Node_To_Replace));
6422
6423                      Set_Name (Call_Node, Hom_Ref);
6424
6425                      Analyze_One_Call
6426                        (N          => Call_Node,
6427                         Nam        => Hom,
6428                         Report     => Report_Error,
6429                         Success    => Success,
6430                         Skip_First => True);
6431
6432                      Matching_Op :=
6433                        Valid_Candidate (Success, Call_Node, Hom);
6434
6435                   else
6436                      Analyze_One_Call
6437                        (N          => Call_Node,
6438                         Nam        => Hom,
6439                         Report     => Report_Error,
6440                         Success    => Success,
6441                         Skip_First => True);
6442
6443                      if Present (Valid_Candidate (Success, Call_Node, Hom))
6444                        and then Nkind (Call_Node) /= N_Function_Call
6445                      then
6446                         Error_Msg_NE ("ambiguous call to&", N, Hom);
6447                         Report_Ambiguity (Matching_Op);
6448                         Report_Ambiguity (Hom);
6449                         Error := True;
6450                         return;
6451                      end if;
6452                   end if;
6453                end if;
6454
6455                Hom := Homonym (Hom);
6456             end loop;
6457          end Traverse_Homonyms;
6458
6459          -------------------------
6460          -- Traverse_Interfaces --
6461          -------------------------
6462
6463          procedure Traverse_Interfaces
6464            (Anc_Type : Entity_Id;
6465             Error    : out Boolean)
6466          is
6467             Intface_List : constant List_Id :=
6468                              Abstract_Interface_List (Anc_Type);
6469             Intface      : Node_Id;
6470
6471          begin
6472             Error := False;
6473
6474             if Is_Non_Empty_List (Intface_List) then
6475                Intface := First (Intface_List);
6476                while Present (Intface) loop
6477
6478                   --  Look for acceptable class-wide homonyms associated with
6479                   --  the interface.
6480
6481                   Traverse_Homonyms (Etype (Intface), Error);
6482
6483                   if Error then
6484                      return;
6485                   end if;
6486
6487                   --  Continue the search by looking at each of the interface's
6488                   --  associated interface ancestors.
6489
6490                   Traverse_Interfaces (Etype (Intface), Error);
6491
6492                   if Error then
6493                      return;
6494                   end if;
6495
6496                   Next (Intface);
6497                end loop;
6498             end if;
6499          end Traverse_Interfaces;
6500
6501       --  Start of processing for Try_Class_Wide_Operation
6502
6503       begin
6504          --  Loop through ancestor types (including interfaces), traversing
6505          --  the homonym chain of the subprogram, trying out those homonyms
6506          --  whose first formal has the class-wide type of the ancestor, or
6507          --  an anonymous access type designating the class-wide type.
6508
6509          Anc_Type := Obj_Type;
6510          loop
6511             --  Look for a match among homonyms associated with the ancestor
6512
6513             Traverse_Homonyms (Anc_Type, Error);
6514
6515             if Error then
6516                return True;
6517             end if;
6518
6519             --  Continue the search for matches among homonyms associated with
6520             --  any interfaces implemented by the ancestor.
6521
6522             Traverse_Interfaces (Anc_Type, Error);
6523
6524             if Error then
6525                return True;
6526             end if;
6527
6528             exit when Etype (Anc_Type) = Anc_Type;
6529             Anc_Type := Etype (Anc_Type);
6530          end loop;
6531
6532          if Present (Matching_Op) then
6533             Set_Etype (Call_Node, Etype (Matching_Op));
6534          end if;
6535
6536          return Present (Matching_Op);
6537       end Try_Class_Wide_Operation;
6538
6539       -----------------------------------
6540       -- Try_One_Prefix_Interpretation --
6541       -----------------------------------
6542
6543       procedure Try_One_Prefix_Interpretation (T : Entity_Id) is
6544       begin
6545          Obj_Type := T;
6546
6547          if Is_Access_Type (Obj_Type) then
6548             Obj_Type := Designated_Type (Obj_Type);
6549          end if;
6550
6551          if Ekind (Obj_Type) = E_Private_Subtype then
6552             Obj_Type := Base_Type (Obj_Type);
6553          end if;
6554
6555          if Is_Class_Wide_Type (Obj_Type) then
6556             Obj_Type := Etype (Class_Wide_Type (Obj_Type));
6557          end if;
6558
6559          --  The type may have be obtained through a limited_with clause,
6560          --  in which case the primitive operations are available on its
6561          --  non-limited view. If still incomplete, retrieve full view.
6562
6563          if Ekind (Obj_Type) = E_Incomplete_Type
6564            and then From_With_Type (Obj_Type)
6565          then
6566             Obj_Type := Get_Full_View (Non_Limited_View (Obj_Type));
6567          end if;
6568
6569          --  If the object is not tagged, or the type is still an incomplete
6570          --  type, this is not a prefixed call.
6571
6572          if not Is_Tagged_Type (Obj_Type)
6573            or else Is_Incomplete_Type (Obj_Type)
6574          then
6575             return;
6576          end if;
6577
6578          if Try_Primitive_Operation
6579               (Call_Node       => New_Call_Node,
6580                Node_To_Replace => Node_To_Replace)
6581            or else
6582              Try_Class_Wide_Operation
6583                (Call_Node       => New_Call_Node,
6584                 Node_To_Replace => Node_To_Replace)
6585          then
6586             null;
6587          end if;
6588       end Try_One_Prefix_Interpretation;
6589
6590       -----------------------------
6591       -- Try_Primitive_Operation --
6592       -----------------------------
6593
6594       function Try_Primitive_Operation
6595         (Call_Node       : Node_Id;
6596          Node_To_Replace : Node_Id) return Boolean
6597       is
6598          Elmt        : Elmt_Id;
6599          Prim_Op     : Entity_Id;
6600          Matching_Op : Entity_Id := Empty;
6601          Prim_Op_Ref : Node_Id   := Empty;
6602
6603          Corr_Type   : Entity_Id := Empty;
6604          --  If the prefix is a synchronized type, the controlling type of
6605          --  the primitive operation is the corresponding record type, else
6606          --  this is the object type itself.
6607
6608          Success     : Boolean   := False;
6609
6610          function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id;
6611          --  For tagged types the candidate interpretations are found in
6612          --  the list of primitive operations of the type and its ancestors.
6613          --  For formal tagged types we have to find the operations declared
6614          --  in the same scope as the type (including in the generic formal
6615          --  part) because the type itself carries no primitive operations,
6616          --  except for formal derived types that inherit the operations of
6617          --  the parent and progenitors.
6618          --  If the context is a generic subprogram body, the generic formals
6619          --  are visible by name, but are not in the entity list of the
6620          --  subprogram because that list starts with the subprogram formals.
6621          --  We retrieve the candidate operations from the generic declaration.
6622
6623          function Is_Private_Overriding (Op : Entity_Id) return Boolean;
6624          --  An operation that overrides an inherited operation in the private
6625          --  part of its package may be hidden, but if the inherited operation
6626          --  is visible a direct call to it will dispatch to the private one,
6627          --  which is therefore a valid candidate.
6628
6629          function Valid_First_Argument_Of (Op : Entity_Id) return Boolean;
6630          --  Verify that the prefix, dereferenced if need be, is a valid
6631          --  controlling argument in a call to Op. The remaining actuals
6632          --  are checked in the subsequent call to Analyze_One_Call.
6633
6634          ------------------------------
6635          -- Collect_Generic_Type_Ops --
6636          ------------------------------
6637
6638          function Collect_Generic_Type_Ops (T : Entity_Id) return Elist_Id is
6639             Bas        : constant Entity_Id := Base_Type (T);
6640             Candidates : constant Elist_Id := New_Elmt_List;
6641             Subp       : Entity_Id;
6642             Formal     : Entity_Id;
6643
6644             procedure Check_Candidate;
6645             --  The operation is a candidate if its first parameter is a
6646             --  controlling operand of the desired type.
6647
6648             -----------------------
6649             --  Check_Candidate; --
6650             -----------------------
6651
6652             procedure Check_Candidate is
6653             begin
6654                Formal := First_Formal (Subp);
6655
6656                if Present (Formal)
6657                  and then Is_Controlling_Formal (Formal)
6658                  and then
6659                    (Base_Type (Etype (Formal)) = Bas
6660                      or else
6661                        (Is_Access_Type (Etype (Formal))
6662                          and then Designated_Type (Etype (Formal)) = Bas))
6663                then
6664                   Append_Elmt (Subp, Candidates);
6665                end if;
6666             end Check_Candidate;
6667
6668          --  Start of processing for Collect_Generic_Type_Ops
6669
6670          begin
6671             if Is_Derived_Type (T) then
6672                return Primitive_Operations (T);
6673
6674             elsif Ekind_In (Scope (T), E_Procedure, E_Function) then
6675
6676                --  Scan the list of generic formals to find subprograms
6677                --  that may have a first controlling formal of the type.
6678
6679                declare
6680                   Decl : Node_Id;
6681
6682                begin
6683                   Decl :=
6684                     First (Generic_Formal_Declarations
6685                             (Unit_Declaration_Node (Scope (T))));
6686                   while Present (Decl) loop
6687                      if Nkind (Decl) in N_Formal_Subprogram_Declaration then
6688                         Subp := Defining_Entity (Decl);
6689                         Check_Candidate;
6690                      end if;
6691
6692                      Next (Decl);
6693                   end loop;
6694                end;
6695
6696                return Candidates;
6697
6698             else
6699                --  Scan the list of entities declared in the same scope as
6700                --  the type. In general this will be an open scope, given that
6701                --  the call we are analyzing can only appear within a generic
6702                --  declaration or body (either the one that declares T, or a
6703                --  child unit).
6704
6705                Subp := First_Entity (Scope (T));
6706                while Present (Subp) loop
6707                   if Is_Overloadable (Subp) then
6708                      Check_Candidate;
6709                   end if;
6710
6711                   Next_Entity (Subp);
6712                end loop;
6713
6714                return Candidates;
6715             end if;
6716          end Collect_Generic_Type_Ops;
6717
6718          ---------------------------
6719          -- Is_Private_Overriding --
6720          ---------------------------
6721
6722          function Is_Private_Overriding (Op : Entity_Id) return Boolean is
6723             Visible_Op : constant Entity_Id := Homonym (Op);
6724
6725          begin
6726             return Present (Visible_Op)
6727               and then Scope (Op) = Scope (Visible_Op)
6728               and then not Comes_From_Source (Visible_Op)
6729               and then Alias (Visible_Op) = Op
6730               and then not Is_Hidden (Visible_Op);
6731          end Is_Private_Overriding;
6732
6733          -----------------------------
6734          -- Valid_First_Argument_Of --
6735          -----------------------------
6736
6737          function Valid_First_Argument_Of (Op : Entity_Id) return Boolean is
6738             Typ : Entity_Id := Etype (First_Formal (Op));
6739
6740          begin
6741             if Is_Concurrent_Type (Typ)
6742               and then Present (Corresponding_Record_Type (Typ))
6743             then
6744                Typ := Corresponding_Record_Type (Typ);
6745             end if;
6746
6747             --  Simple case. Object may be a subtype of the tagged type or
6748             --  may be the corresponding record of a synchronized type.
6749
6750             return Obj_Type = Typ
6751               or else Base_Type (Obj_Type) = Typ
6752               or else Corr_Type = Typ
6753
6754                --  Prefix can be dereferenced
6755
6756               or else
6757                 (Is_Access_Type (Corr_Type)
6758                   and then Designated_Type (Corr_Type) = Typ)
6759
6760                --  Formal is an access parameter, for which the object
6761                --  can provide an access.
6762
6763               or else
6764                 (Ekind (Typ) = E_Anonymous_Access_Type
6765                   and then Designated_Type (Typ) = Base_Type (Corr_Type));
6766          end Valid_First_Argument_Of;
6767
6768       --  Start of processing for Try_Primitive_Operation
6769
6770       begin
6771          --  Look for subprograms in the list of primitive operations. The name
6772          --  must be identical, and the kind of call indicates the expected
6773          --  kind of operation (function or procedure). If the type is a
6774          --  (tagged) synchronized type, the primitive ops are attached to the
6775          --  corresponding record (base) type.
6776
6777          if Is_Concurrent_Type (Obj_Type) then
6778             if not Present (Corresponding_Record_Type (Obj_Type)) then
6779                return False;
6780             end if;
6781
6782             Corr_Type := Base_Type (Corresponding_Record_Type (Obj_Type));
6783             Elmt := First_Elmt (Primitive_Operations (Corr_Type));
6784
6785          elsif not Is_Generic_Type (Obj_Type) then
6786             Corr_Type := Obj_Type;
6787             Elmt := First_Elmt (Primitive_Operations (Obj_Type));
6788
6789          else
6790             Corr_Type := Obj_Type;
6791             Elmt := First_Elmt (Collect_Generic_Type_Ops (Obj_Type));
6792          end if;
6793
6794          while Present (Elmt) loop
6795             Prim_Op := Node (Elmt);
6796
6797             if Chars (Prim_Op) = Chars (Subprog)
6798               and then Present (First_Formal (Prim_Op))
6799               and then Valid_First_Argument_Of (Prim_Op)
6800               and then
6801                 (Nkind (Call_Node) = N_Function_Call)
6802                    = (Ekind (Prim_Op) = E_Function)
6803             then
6804                --  Ada 2005 (AI-251): If this primitive operation corresponds
6805                --  with an immediate ancestor interface there is no need to add
6806                --  it to the list of interpretations; the corresponding aliased
6807                --  primitive is also in this list of primitive operations and
6808                --  will be used instead.
6809
6810                if (Present (Interface_Alias (Prim_Op))
6811                     and then Is_Ancestor (Find_Dispatching_Type
6812                                             (Alias (Prim_Op)), Corr_Type))
6813
6814                  --  Do not consider hidden primitives unless the type is in an
6815                  --  open scope or we are within an instance, where visibility
6816                  --  is known to be correct, or else if this is an overriding
6817                  --  operation in the private part for an inherited operation.
6818
6819                  or else (Is_Hidden (Prim_Op)
6820                            and then not Is_Immediately_Visible (Obj_Type)
6821                            and then not In_Instance
6822                            and then not Is_Private_Overriding (Prim_Op))
6823                then
6824                   goto Continue;
6825                end if;
6826
6827                Set_Etype (Call_Node, Any_Type);
6828                Set_Is_Overloaded (Call_Node, False);
6829
6830                if No (Matching_Op) then
6831                   Prim_Op_Ref := New_Reference_To (Prim_Op, Sloc (Subprog));
6832                   Candidate := Prim_Op;
6833
6834                   Set_Parent (Call_Node, Parent (Node_To_Replace));
6835
6836                   Set_Name (Call_Node, Prim_Op_Ref);
6837                   Success := False;
6838
6839                   Analyze_One_Call
6840                     (N          => Call_Node,
6841                      Nam        => Prim_Op,
6842                      Report     => Report_Error,
6843                      Success    => Success,
6844                      Skip_First => True);
6845
6846                   Matching_Op := Valid_Candidate (Success, Call_Node, Prim_Op);
6847
6848                --  More than one interpretation, collect for subsequent
6849                --  disambiguation. If this is a procedure call and there
6850                --  is another match, report ambiguity now.
6851
6852                else
6853                   Analyze_One_Call
6854                     (N          => Call_Node,
6855                      Nam        => Prim_Op,
6856                      Report     => Report_Error,
6857                      Success    => Success,
6858                      Skip_First => True);
6859
6860                   if Present (Valid_Candidate (Success, Call_Node, Prim_Op))
6861                     and then Nkind (Call_Node) /= N_Function_Call
6862                   then
6863                      Error_Msg_NE ("ambiguous call to&", N, Prim_Op);
6864                      Report_Ambiguity (Matching_Op);
6865                      Report_Ambiguity (Prim_Op);
6866                      return True;
6867                   end if;
6868                end if;
6869             end if;
6870
6871             <<Continue>>
6872             Next_Elmt (Elmt);
6873          end loop;
6874
6875          if Present (Matching_Op) then
6876             Set_Etype (Call_Node, Etype (Matching_Op));
6877          end if;
6878
6879          return Present (Matching_Op);
6880       end Try_Primitive_Operation;
6881
6882    --  Start of processing for Try_Object_Operation
6883
6884    begin
6885       Analyze_Expression (Obj);
6886
6887       --  Analyze the actuals if node is known to be a subprogram call
6888
6889       if Is_Subprg_Call and then N = Name (Parent (N)) then
6890          Actual := First (Parameter_Associations (Parent (N)));
6891          while Present (Actual) loop
6892             Analyze_Expression (Actual);
6893             Next (Actual);
6894          end loop;
6895       end if;
6896
6897       --  Build a subprogram call node, using a copy of Obj as its first
6898       --  actual. This is a placeholder, to be replaced by an explicit
6899       --  dereference when needed.
6900
6901       Transform_Object_Operation
6902         (Call_Node       => New_Call_Node,
6903          Node_To_Replace => Node_To_Replace);
6904
6905       Set_Etype (New_Call_Node, Any_Type);
6906       Set_Etype (Subprog, Any_Type);
6907       Set_Parent (New_Call_Node, Parent (Node_To_Replace));
6908
6909       if not Is_Overloaded (Obj) then
6910          Try_One_Prefix_Interpretation (Obj_Type);
6911
6912       else
6913          declare
6914             I  : Interp_Index;
6915             It : Interp;
6916          begin
6917             Get_First_Interp (Obj, I, It);
6918             while Present (It.Nam) loop
6919                Try_One_Prefix_Interpretation (It.Typ);
6920                Get_Next_Interp (I, It);
6921             end loop;
6922          end;
6923       end if;
6924
6925       if Etype (New_Call_Node) /= Any_Type then
6926          Complete_Object_Operation
6927            (Call_Node       => New_Call_Node,
6928             Node_To_Replace => Node_To_Replace);
6929          return True;
6930
6931       elsif Present (Candidate) then
6932
6933          --  The argument list is not type correct. Re-analyze with error
6934          --  reporting enabled, and use one of the possible candidates.
6935          --  In All_Errors_Mode, re-analyze all failed interpretations.
6936
6937          if All_Errors_Mode then
6938             Report_Error := True;
6939             if Try_Primitive_Operation
6940                 (Call_Node       => New_Call_Node,
6941                  Node_To_Replace => Node_To_Replace)
6942
6943               or else
6944                 Try_Class_Wide_Operation
6945                   (Call_Node       => New_Call_Node,
6946                    Node_To_Replace => Node_To_Replace)
6947             then
6948                null;
6949             end if;
6950
6951          else
6952             Analyze_One_Call
6953               (N          => New_Call_Node,
6954                Nam        => Candidate,
6955                Report     => True,
6956                Success    => Success,
6957                Skip_First => True);
6958          end if;
6959
6960          --  No need for further errors
6961
6962          return True;
6963
6964       else
6965          --  There was no candidate operation, so report it as an error
6966          --  in the caller: Analyze_Selected_Component.
6967
6968          return False;
6969       end if;
6970    end Try_Object_Operation;
6971
6972    ---------
6973    -- wpo --
6974    ---------
6975
6976    procedure wpo (T : Entity_Id) is
6977       Op : Entity_Id;
6978       E  : Elmt_Id;
6979
6980    begin
6981       if not Is_Tagged_Type (T) then
6982          return;
6983       end if;
6984
6985       E := First_Elmt (Primitive_Operations (Base_Type (T)));
6986       while Present (E) loop
6987          Op := Node (E);
6988          Write_Int (Int (Op));
6989          Write_Str (" === ");
6990          Write_Name (Chars (Op));
6991          Write_Str (" in ");
6992          Write_Name (Chars (Scope (Op)));
6993          Next_Elmt (E);
6994          Write_Eol;
6995       end loop;
6996    end wpo;
6997
6998 end Sem_Ch4;