OSDN Git Service

Patch to fix -mcpu=G5 interface to EH runtime library.
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_ch4.adb
index 9e97e71..ba7e46a 100644 (file)
@@ -6,8 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                                                                          --
---          Copyright (C) 1992-2002, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2004, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
 -- MA 02111-1307, USA.                                                      --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
--- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
 --                                                                          --
 ------------------------------------------------------------------------------
 
 with Atree;    use Atree;
+with Checks;   use Checks;
 with Debug;    use Debug;
 with Einfo;    use Einfo;
+with Elists;   use Elists;
 with Errout;   use Errout;
 with Exp_Util; use Exp_Util;
-with Hostparm; use Hostparm;
+with Fname;    use Fname;
 with Itypes;   use Itypes;
+with Lib;      use Lib;
 with Lib.Xref; use Lib.Xref;
 with Namet;    use Namet;
 with Nlists;   use Nlists;
@@ -39,6 +41,7 @@ with Nmake;    use Nmake;
 with Opt;      use Opt;
 with Output;   use Output;
 with Restrict; use Restrict;
+with Rident;   use Rident;
 with Sem;      use Sem;
 with Sem_Cat;  use Sem_Cat;
 with Sem_Ch3;  use Sem_Ch3;
@@ -93,10 +96,6 @@ package body Sem_Ch4 is
    --  for equality, membership, and comparison operators with overloaded
    --  arguments, list possible interpretations.
 
-   procedure Insert_Explicit_Dereference (N : Node_Id);
-   --  In a context that requires a composite or subprogram type and
-   --  where a prefix is an access type, insert an explicit dereference.
-
    procedure Analyze_One_Call
       (N       : Node_Id;
        Nam     : Entity_Id;
@@ -213,11 +212,14 @@ package body Sem_Ch4 is
    --  for the type is not directly visible. The routine uses this type to emit
    --  a more informative message.
 
+   procedure Remove_Abstract_Operations (N : Node_Id);
+   --  Ada 2005: implementation of AI-310. An abstract non-dispatching
+   --  operation is not a candidate interpretation.
+
    function Try_Indexed_Call
-     (N      : Node_Id;
-      Nam    : Entity_Id;
-      Typ    : Entity_Id)
-      return   Boolean;
+     (N   : Node_Id;
+      Nam : Entity_Id;
+      Typ : Entity_Id) return Boolean;
    --  If a function has defaults for all its actuals, a call to it may
    --  in fact be an indexing on the result of the call. Try_Indexed_Call
    --  attempts the interpretation as an indexing, prior to analysis as
@@ -225,24 +227,28 @@ package body Sem_Ch4 is
    --  interpretations (same symbol but two different types).
 
    function Try_Indirect_Call
-     (N      : Node_Id;
-      Nam    : Entity_Id;
-      Typ    : Entity_Id)
-      return   Boolean;
+     (N   : Node_Id;
+      Nam : Entity_Id;
+      Typ : Entity_Id) return Boolean;
    --  Similarly, a function F that needs no actuals can return an access
    --  to a subprogram, and the call F (X)  interpreted as F.all (X). In
    --  this case the call may be overloaded with both interpretations.
 
+   function Try_Object_Operation (N : Node_Id) return Boolean;
+   --  Ada 2005 (AI-252): Give support to the object operation notation
+
    ------------------------
    -- Ambiguous_Operands --
    ------------------------
 
    procedure Ambiguous_Operands (N : Node_Id) is
-      procedure List_Interps (Opnd : Node_Id);
+      procedure List_Operand_Interps (Opnd : Node_Id);
 
-      procedure List_Interps (Opnd : Node_Id) is
-         Index : Interp_Index;
-         It    : Interp;
+      --------------------------
+      -- List_Operand_Interps --
+      --------------------------
+
+      procedure List_Operand_Interps (Opnd : Node_Id) is
          Nam   : Node_Id;
          Err   : Node_Id := N;
 
@@ -250,10 +256,8 @@ package body Sem_Ch4 is
          if Is_Overloaded (Opnd) then
             if Nkind (Opnd) in N_Op then
                Nam := Opnd;
-
             elsif Nkind (Opnd) = N_Function_Call then
                Nam := Name (Opnd);
-
             else
                return;
             end if;
@@ -271,24 +275,10 @@ package body Sem_Ch4 is
             Err := Opnd;
          end if;
 
-         Get_First_Interp (Nam, Index, It);
+         List_Interps (Nam, Err);
+      end List_Operand_Interps;
 
-         while Present (It.Nam) loop
-
-            if Scope (It.Nam) = Standard_Standard
-              and then Scope (It.Typ) /= Standard_Standard
-            then
-               Error_Msg_Sloc := Sloc (Parent (It.Typ));
-               Error_Msg_NE ("   & (inherited) declared#!", Err, It.Nam);
-
-            else
-               Error_Msg_Sloc := Sloc (It.Nam);
-               Error_Msg_NE ("   & declared#!", Err, It.Nam);
-            end if;
-
-            Get_Next_Interp (Index, It);
-         end loop;
-      end List_Interps;
+   --  Start of processing for Ambiguous_Operands
 
    begin
       if Nkind (N) = N_In
@@ -306,17 +296,10 @@ package body Sem_Ch4 is
       end if;
 
       if All_Errors_Mode then
-         List_Interps (Left_Opnd  (N));
-         List_Interps (Right_Opnd (N));
+         List_Operand_Interps (Left_Opnd  (N));
+         List_Operand_Interps (Right_Opnd (N));
       else
-
-         if OpenVMS then
-            Error_Msg_N (
-               "\use '/'R'E'P'O'R'T'_'E'R'R'O'R'S'='F'U'L'L for details",
-                N);
-         else
-            Error_Msg_N ("\use -gnatf for details", N);
-         end if;
+         Error_Msg_N ("\use -gnatf switch for details", N);
       end if;
    end Ambiguous_Operands;
 
@@ -357,15 +340,23 @@ package body Sem_Ch4 is
          Check_Fully_Declared (Type_Id, N);
          Set_Directly_Designated_Type (Acc_Type, Type_Id);
 
-         if Is_Protected_Type (Type_Id) then
-            Check_Restriction (No_Protected_Type_Allocators, N);
-         end if;
-
          if Is_Limited_Type (Type_Id)
            and then Comes_From_Source (N)
            and then not In_Instance_Body
          then
-            Error_Msg_N ("initialization not allowed for limited types", N);
+            --  Ada 2005 (AI-287): Do not post an error if the expression
+            --  corresponds to a limited aggregate. Limited aggregates
+            --  are checked in sem_aggr in a per-component manner
+            --  (compare with handling of Get_Value subprogram).
+
+            if Ada_Version >= Ada_05
+              and then Nkind (Expression (E)) = N_Aggregate
+            then
+               null;
+            else
+               Error_Msg_N ("initialization not allowed for limited types", N);
+               Explain_Limited_Type (Type_Id, N);
+            end if;
          end if;
 
          Analyze_And_Resolve (Expression (E), Type_Id);
@@ -386,6 +377,8 @@ package body Sem_Ch4 is
 
          Set_Etype  (E, Type_Id);
 
+      --  Case where no qualified expression is present
+
       else
          declare
             Def_Id : Entity_Id;
@@ -410,7 +403,7 @@ package body Sem_Ch4 is
                Find_Type (Subtype_Mark (E));
 
                if Is_Elementary_Type (Entity (Subtype_Mark (E))) then
-                  if not (Ada_83
+                  if not (Ada_Version = Ada_83
                            and then Is_Access_Type (Entity (Subtype_Mark (E))))
                   then
                      Error_Msg_N ("constraint not allowed here", E);
@@ -461,6 +454,22 @@ package body Sem_Ch4 is
             Set_Directly_Designated_Type (Acc_Type, Type_Id);
             Check_Fully_Declared (Type_Id, N);
 
+            --  Ada 2005 (AI-231)
+
+            if Can_Never_Be_Null (Type_Id) then
+               Error_Msg_N ("(Ada 2005) qualified expression required",
+                            Expression (N));
+            end if;
+
+            --  Check restriction against dynamically allocated protected
+            --  objects. Note that when limited aggregates are supported,
+            --  a similar test should be applied to an allocator with a
+            --  qualified expression ???
+
+            if Is_Protected_Type (Type_Id) then
+               Check_Restriction (No_Protected_Type_Allocators, N);
+            end if;
+
             --  Check for missing initialization. Skip this check if we already
             --  had errors on analyzing the allocator, since in that case these
             --  are probably cascaded errors
@@ -484,6 +493,8 @@ package body Sem_Ch4 is
       end if;
 
       if Has_Task (Designated_Type (Acc_Type)) then
+         Check_Restriction (No_Tasking, N);
+         Check_Restriction (Max_Tasks, N);
          Check_Restriction (No_Task_Allocators, N);
       end if;
 
@@ -493,11 +504,19 @@ package body Sem_Ch4 is
          Check_Restriction (No_Local_Allocators, N);
       end if;
 
+      --  Ada 2005 (AI-231): Static checks
+
+      if Ada_Version >= Ada_05
+        and then (Null_Exclusion_Present (N)
+                    or else Can_Never_Be_Null (Etype (N)))
+      then
+         Null_Exclusion_Static_Checks (N);
+      end if;
+
       if Serious_Errors_Detected > Sav_Errs then
          Set_Error_Posted (N);
          Set_Etype (N, Any_Type);
       end if;
-
    end Analyze_Allocator;
 
    ---------------------------
@@ -573,12 +592,12 @@ package body Sem_Ch4 is
    -- Analyze_Call --
    ------------------
 
-   --  Function, procedure, and entry calls are checked here. The Name
-   --  in the call may be overloaded. The actuals have been analyzed
-   --  and may themselves be overloaded. On exit from this procedure, the node
-   --  N may have zero, one or more interpretations. In the first case an error
-   --  message is produced. In the last case, the node is flagged as overloaded
-   --  and the interpretations are collected in All_Interp.
+   --  Function, procedure, and entry calls are checked here. The Name in
+   --  the call may be overloaded. The actuals have been analyzed and may
+   --  themselves be overloaded. On exit from this procedure, the node N
+   --  may have zero, one or more interpretations. In the first case an
+   --  error message is produced. In the last case, the node is flagged
+   --  as overloaded and the interpretations are collected in All_Interp.
 
    --  If the name is an Access_To_Subprogram, it cannot be overloaded, but
    --  the type-checking is similar to that of other calls.
@@ -662,12 +681,10 @@ package body Sem_Ch4 is
 
             if Nkind (Prefix (Nam)) = N_Selected_Component then
                Nam_Ent := Entity (Selector_Name (Prefix (Nam)));
-
             else
                Error_Msg_N ("name in call is not a callable entity", Nam);
                Set_Etype (N, Any_Type);
                return;
-
             end if;
 
          elsif not Is_Entity_Name (Nam) then
@@ -765,7 +782,9 @@ package body Sem_Ch4 is
             if Success then
                Set_Etype (Nam, It.Typ);
 
-            elsif Nkind (Name (N)) = N_Selected_Component then
+            elsif Nkind (Name (N)) = N_Selected_Component
+              or else Nkind (Name (N)) = N_Function_Call
+            then
                Remove_Interp (X);
             end if;
 
@@ -847,6 +866,8 @@ package body Sem_Ch4 is
             Generate_Reference (Entity (Nam), Nam);
 
             Set_Etype (Nam, Etype (Entity (Nam)));
+         else
+            Remove_Abstract_Operations (N);
          end if;
 
          End_Interp_List;
@@ -870,7 +891,6 @@ package body Sem_Ch4 is
       Analyze_Expression (R);
 
       if Present (Op_Id) then
-
          if Ekind (Op_Id) = E_Operator then
             Find_Comparison_Types (L, R, Op_Id, N);
          else
@@ -883,9 +903,7 @@ package body Sem_Ch4 is
 
       else
          Op_Id := Get_Name_Entity_Id (Chars (N));
-
          while Present (Op_Id) loop
-
             if Ekind (Op_Id) = E_Operator then
                Find_Comparison_Types (L, R, Op_Id, N);
             else
@@ -924,7 +942,9 @@ package body Sem_Ch4 is
 
       --  If the entity is present, the  node appears in an instance,
       --  and denotes a predefined concatenation operation. The resulting
-      --  type is obtained from the arguments when possible.
+      --  type is obtained from the arguments when possible. If the arguments
+      --  are aggregates, the array type and the concatenation type must be
+      --  visible.
 
       if Present (Op_Id) then
          if Ekind (Op_Id) = E_Operator then
@@ -942,8 +962,31 @@ package body Sem_Ch4 is
             then
                Add_One_Interp (N, Op_Id, RT);
 
-            else
+            --  If one operand is a string type or a user-defined array type,
+            --  and the other is a literal, result is of the specific type.
+
+            elsif
+              (Root_Type (LT) = Standard_String
+                 or else Scope (LT) /= Standard_Standard)
+              and then Etype (R) = Any_String
+            then
+               Add_One_Interp (N, Op_Id, LT);
+
+            elsif
+              (Root_Type (RT) = Standard_String
+                 or else Scope (RT) /= Standard_Standard)
+              and then Etype (L) = Any_String
+            then
+               Add_One_Interp (N, Op_Id, RT);
+
+            elsif not Is_Generic_Type (Etype (Op_Id)) then
                Add_One_Interp (N, Op_Id, Etype (Op_Id));
+
+            else
+               --  Type and its operations must be visible
+
+               Set_Entity (N, Empty);
+               Analyze_Concatenation (N);
             end if;
 
          else
@@ -952,7 +995,6 @@ package body Sem_Ch4 is
 
       else
          Op_Id  := Get_Name_Entity_Id (Name_Op_Concat);
-
          while Present (Op_Id) loop
             if Ekind (Op_Id) = E_Operator then
                Find_Concatenation_Types (L, R, Op_Id, N);
@@ -975,7 +1017,6 @@ package body Sem_Ch4 is
       Condition : constant Node_Id := First (Expressions (N));
       Then_Expr : constant Node_Id := Next (Condition);
       Else_Expr : constant Node_Id := Next (Then_Expr);
-
    begin
       Analyze_Expression (Condition);
       Analyze_Expression (Then_Expr);
@@ -988,10 +1029,10 @@ package body Sem_Ch4 is
    -------------------------
 
    procedure Analyze_Equality_Op (N : Node_Id) is
-      Loc    : constant Source_Ptr := Sloc (N);
-      L      : constant Node_Id := Left_Opnd (N);
-      R      : constant Node_Id := Right_Opnd (N);
-      Op_Id  : Entity_Id;
+      Loc   : constant Source_Ptr := Sloc (N);
+      L     : constant Node_Id := Left_Opnd (N);
+      R     : constant Node_Id := Right_Opnd (N);
+      Op_Id : Entity_Id;
 
    begin
       Set_Etype (N, Any_Type);
@@ -1012,7 +1053,6 @@ package body Sem_Ch4 is
       --  of the user-defined function.
 
       if Present (Entity (N)) then
-
          Op_Id := Entity (N);
 
          if Ekind (Op_Id) = E_Operator then
@@ -1022,7 +1062,6 @@ package body Sem_Ch4 is
          end if;
 
          if Is_Overloaded (L) then
-
             if Ekind (Op_Id) = E_Operator then
                Set_Etype (L, Intersect_Types (L, R));
             else
@@ -1032,9 +1071,7 @@ package body Sem_Ch4 is
 
       else
          Op_Id := Get_Name_Entity_Id (Chars (N));
-
          while Present (Op_Id) loop
-
             if Ekind (Op_Id) = E_Operator then
                Find_Equality_Types (L, R, Op_Id, N);
             else
@@ -1098,11 +1135,15 @@ package body Sem_Ch4 is
       New_N : Node_Id;
 
       function Is_Function_Type return Boolean;
-      --  Check whether node may be interpreted as an implicit function call.
+      --  Check whether node may be interpreted as an implicit function call
+
+      ----------------------
+      -- Is_Function_Type --
+      ----------------------
 
       function Is_Function_Type return Boolean is
-         I     : Interp_Index;
-         It    : Interp;
+         I  : Interp_Index;
+         It : Interp;
 
       begin
          if not Is_Overloaded (N) then
@@ -1126,6 +1167,8 @@ package body Sem_Ch4 is
          end if;
       end Is_Function_Type;
 
+   --  Start of processing for Analyze_Explicit_Deference
+
    begin
       Analyze (P);
       Set_Etype (N, Any_Type);
@@ -1223,7 +1266,6 @@ package body Sem_Ch4 is
 
          if Is_Overloaded (P) then
             Get_First_Interp (P, I, It);
-
             while Present (It.Nam) loop
                T := It.Typ;
 
@@ -1245,7 +1287,6 @@ package body Sem_Ch4 is
       --  (RM E.2.2(16)).
 
       Validate_Remote_Access_To_Class_Wide_Type (N);
-
    end Analyze_Explicit_Dereference;
 
    ------------------------
@@ -1263,12 +1304,12 @@ package body Sem_Ch4 is
    ------------------------------------
 
    procedure Analyze_Indexed_Component_Form (N : Node_Id) is
-      P   : constant Node_Id := Prefix (N);
-      Exprs : List_Id := Expressions (N);
-      Exp : Node_Id;
-      P_T : Entity_Id;
-      E   : Node_Id;
-      U_N : Entity_Id;
+      P     : constant Node_Id := Prefix (N);
+      Exprs : constant List_Id := Expressions (N);
+      Exp   : Node_Id;
+      P_T   : Entity_Id;
+      E     : Node_Id;
+      U_N   : Entity_Id;
 
       procedure Process_Function_Call;
       --  Prefix in indexed component form is an overloadable entity,
@@ -1299,8 +1340,8 @@ package body Sem_Ch4 is
          Change_Node (N, N_Function_Call);
          Set_Name (N, P);
          Set_Parameter_Associations (N, Exprs);
-         Actual := First (Parameter_Associations (N));
 
+         Actual := First (Parameter_Associations (N));
          while Present (Actual) loop
             Analyze (Actual);
             Check_Parameterless_Call (Actual);
@@ -1334,10 +1375,7 @@ package body Sem_Ch4 is
 
             if Is_Access_Type (Array_Type) then
                Array_Type := Designated_Type (Array_Type);
-
-               if Warn_On_Dereference then
-                  Error_Msg_N ("?implicit dereference", N);
-               end if;
+               Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
             end if;
 
             if Is_Array_Type (Array_Type) then
@@ -1436,7 +1474,6 @@ package body Sem_Ch4 is
                Error_Msg_N ("too many subscripts in array reference", Exp);
             end if;
          end if;
-
       end Process_Indexed_Component;
 
       ----------------------------------------
@@ -1446,7 +1483,6 @@ package body Sem_Ch4 is
       procedure Process_Indexed_Component_Or_Slice is
       begin
          Exp := First (Exprs);
-
          while Present (Exp) loop
             Analyze_Expression (Exp);
             Next (Exp);
@@ -1494,17 +1530,14 @@ package body Sem_Ch4 is
 
       begin
          Set_Etype (N, Any_Type);
-         Get_First_Interp (P, I, It);
 
+         Get_First_Interp (P, I, It);
          while Present (It.Nam) loop
             Typ := It.Typ;
 
             if Is_Access_Type (Typ) then
                Typ := Designated_Type (Typ);
-
-               if Warn_On_Dereference then
-                  Error_Msg_N ("?implicit dereference", N);
-               end if;
+               Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
             end if;
 
             if Is_Array_Type (Typ) then
@@ -1513,9 +1546,7 @@ package body Sem_Ch4 is
 
                Index := First_Index (Typ);
                Found := True;
-
                Exp := First (Exprs);
-
                while Present (Index) and then Present (Exp) loop
                   if Has_Compatible_Type (Exp, Etype (Index)) then
                      null;
@@ -1547,14 +1578,24 @@ package body Sem_Ch4 is
          End_Interp_List;
       end Process_Overloaded_Indexed_Component;
 
-   ------------------------------------
-   -- Analyze_Indexed_Component_Form --
-   ------------------------------------
+   --  Start of processing for Analyze_Indexed_Component_Form
 
    begin
       --  Get name of array, function or type
 
       Analyze (P);
+      if Nkind (N) = N_Function_Call
+        or else Nkind (N) = N_Procedure_Call_Statement
+      then
+         --  If P is an explicit dereference whose prefix is of a
+         --  remote access-to-subprogram type, then N has already
+         --  been rewritten as a subprogram call and analyzed.
+
+         return;
+      end if;
+
+      pragma Assert (Nkind (N) = N_Indexed_Component);
+
       P_T := Base_Type (Etype (P));
 
       if Is_Entity_Name (P)
@@ -1564,7 +1605,7 @@ package body Sem_Ch4 is
 
          if Ekind (U_N) in  Type_Kind then
 
-            --  Reformat node as a type conversion.
+            --  Reformat node as a type conversion
 
             E := Remove_Head (Exprs);
 
@@ -1597,10 +1638,9 @@ package body Sem_Ch4 is
 
             Process_Function_Call;
 
-         elsif Ekind (U_N) = E_Generic_Function
-           or else Ekind (U_N) = E_Generic_Procedure
-         then
-            --  A common beginner's (or C++ templates fan) error.
+         elsif Is_Generic_Subprogram (U_N) then
+
+            --  A common beginner's (or C++ templates fan) error
 
             Error_Msg_N ("generic subprogram cannot be called", N);
             Set_Etype (N, Any_Type);
@@ -1614,8 +1654,7 @@ package body Sem_Ch4 is
       --  an array or an access-to-subprogram.
 
       else
-
-         if (Ekind (P_T) = E_Subprogram_Type)
+         if Ekind (P_T) = E_Subprogram_Type
            or else (Is_Access_Type (P_T)
                      and then
                     Ekind (Designated_Type (P_T)) = E_Subprogram_Type)
@@ -1630,6 +1669,7 @@ package body Sem_Ch4 is
          else
             --  Indexed component, slice, or a call to a member of a family
             --  entry, which will be converted to an entry call later.
+
             Process_Indexed_Component_Or_Slice;
          end if;
       end if;
@@ -1696,6 +1736,10 @@ package body Sem_Ch4 is
       --  if there is more than one interpretation of the operands that is
       --  compatible with a membership test, the operation is ambiguous.
 
+      --------------------
+      -- Try_One_Interp --
+      --------------------
+
       procedure Try_One_Interp (T1 : Entity_Id) is
       begin
          if Has_Compatible_Type (R, T1) then
@@ -1788,7 +1832,6 @@ package body Sem_Ch4 is
 
       else
          Op_Id := Get_Name_Entity_Id (Chars (N));
-
          while Present (Op_Id) loop
             if Ekind (Op_Id) = E_Operator then
                Find_Negation_Types (R, Op_Id, N);
@@ -1803,9 +1846,9 @@ package body Sem_Ch4 is
       Operator_Check (N);
    end Analyze_Negation;
 
-   -------------------
-   --  Analyze_Null --
-   -------------------
+   ------------------
+   -- Analyze_Null --
+   ------------------
 
    procedure Analyze_Null (N : Node_Id) is
    begin
@@ -1830,15 +1873,15 @@ package body Sem_Ch4 is
       Subp_Type  : constant Entity_Id := Etype (Nam);
       Norm_OK    : Boolean;
 
-      procedure Set_Name;
+      procedure Indicate_Name_And_Type;
       --  If candidate interpretation matches, indicate name and type of
       --  result on call node.
 
-      --------------
-      -- Set_Name --
-      --------------
+      ----------------------------
+      -- Indicate_Name_And_Type --
+      ----------------------------
 
-      procedure Set_Name is
+      procedure Indicate_Name_And_Type is
       begin
          Add_One_Interp (N, Nam, Etype (Nam));
          Success := True;
@@ -1867,7 +1910,7 @@ package body Sem_Ch4 is
             Write_Int (Int (Nam));
             Write_Eol;
          end if;
-      end Set_Name;
+      end Indicate_Name_And_Type;
 
    --  Start of processing for Analyze_One_Call
 
@@ -1922,7 +1965,7 @@ package body Sem_Ch4 is
       then
          return;
 
-      --  Ditto for function calls in a procedure context.
+      --  Ditto for function calls in a procedure context
 
       elsif Nkind (N) = N_Procedure_Call_Statement
          and then Is_Overloaded (Name (N))
@@ -1935,10 +1978,9 @@ package body Sem_Ch4 is
          --  If Normalize succeeds, then there are default parameters for
          --  all formals.
 
-         Set_Name;
+         Indicate_Name_And_Type;
 
       elsif Ekind (Nam) = E_Operator then
-
          if Nkind (N) = N_Procedure_Call_Statement then
             return;
          end if;
@@ -1963,9 +2005,7 @@ package body Sem_Ch4 is
 
                begin
                   Get_First_Interp (Name (N), I, It);
-
                   while Present (It.Nam) loop
-
                      if Ekind (It.Nam) /= E_Operator
                         and then Hides_Op (It.Nam, Nam)
                         and then
@@ -2003,11 +2043,9 @@ package body Sem_Ch4 is
 
          Actual := First_Actual (N);
          Formal := First_Formal (Nam);
-
          while Present (Actual) and then Present (Formal) loop
-
-            if (Nkind (Parent (Actual)) /= N_Parameter_Association
-              or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal))
+            if Nkind (Parent (Actual)) /= N_Parameter_Association
+              or else Chars (Selector_Name (Parent (Actual))) = Chars (Formal)
             then
                if Has_Compatible_Type (Actual, Etype (Formal)) then
                   Next_Actual (Actual);
@@ -2025,7 +2063,6 @@ package body Sem_Ch4 is
                   end if;
 
                   if Report and not Is_Indexed then
-
                      Wrong_Type (Actual, Etype (Formal));
 
                      if Nkind (Actual) = N_Op_Eq
@@ -2037,7 +2074,7 @@ package body Sem_Ch4 is
 
                            if Chars (Left_Opnd (Actual)) = Chars (Formal) then
                               Error_Msg_N
-                                ("possible misspelling of `=>`!", Actual);
+                                ("possible misspelling of `='>`!", Actual);
                               exit;
                            end if;
 
@@ -2053,9 +2090,23 @@ package body Sem_Ch4 is
                           and then not Comes_From_Source (Nam)
                         then
                            Error_Msg_NE
-                             ("  ==> in call to &#(inherited)!", Actual, Nam);
+                             ("  =='> in call to &#(inherited)!", Actual, Nam);
+
+                        elsif Ekind (Nam) = E_Subprogram_Type then
+                           declare
+                              Access_To_Subprogram_Typ :
+                                constant Entity_Id :=
+                                  Defining_Identifier
+                                    (Associated_Node_For_Itype (Nam));
+                           begin
+                              Error_Msg_NE (
+                                "  =='> in call to dereference of &#!",
+                                Actual, Access_To_Subprogram_Typ);
+                           end;
+
                         else
-                           Error_Msg_NE ("  ==> in call to &#!", Actual, Nam);
+                           Error_Msg_NE ("  =='> in call to &#!", Actual, Nam);
+
                         end if;
                      end if;
                   end if;
@@ -2071,15 +2122,15 @@ package body Sem_Ch4 is
             end if;
          end loop;
 
-         --  On exit, all actuals match.
+         --  On exit, all actuals match
 
-         Set_Name;
+         Indicate_Name_And_Type;
       end if;
    end Analyze_One_Call;
 
-   ----------------------------
-   --  Analyze_Operator_Call --
-   ----------------------------
+   ---------------------------
+   -- Analyze_Operator_Call --
+   ---------------------------
 
    procedure Analyze_Operator_Call (N : Node_Id; Op_Id : Entity_Id) is
       Op_Name : constant Name_Id := Chars (Op_Id);
@@ -2087,14 +2138,13 @@ package body Sem_Ch4 is
       Act2    : constant Node_Id := Next_Actual (Act1);
 
    begin
+      --  Binary operator case
+
       if Present (Act2) then
 
-         --  Maybe binary operators
+         --  If more than two operands, then not binary operator after all
 
          if Present (Next_Actual (Act2)) then
-
-            --  Too many actuals for an operator
-
             return;
 
          elsif     Op_Name = Name_Op_Add
@@ -2134,9 +2184,9 @@ package body Sem_Ch4 is
             null;
          end if;
 
-      else
-         --  Unary operators
+      --  Unary operator case
 
+      else
          if Op_Name = Name_Op_Subtract or else
             Op_Name = Name_Op_Add      or else
             Op_Name = Name_Op_Abs
@@ -2161,35 +2211,28 @@ package body Sem_Ch4 is
    -------------------------------------------
 
    procedure Analyze_Overloaded_Selected_Component (N : Node_Id) is
+      Nam   : constant Node_Id := Prefix (N);
+      Sel   : constant Node_Id := Selector_Name (N);
       Comp  : Entity_Id;
-      Nam   : Node_Id := Prefix (N);
-      Sel   : Node_Id := Selector_Name (N);
       I     : Interp_Index;
       It    : Interp;
       T     : Entity_Id;
 
    begin
-      Get_First_Interp (Nam, I, It);
-
-      Set_Etype (Sel,  Any_Type);
+      Set_Etype (Sel, Any_Type);
 
+      Get_First_Interp (Nam, I, It);
       while Present (It.Typ) loop
          if Is_Access_Type (It.Typ) then
             T := Designated_Type (It.Typ);
-
-            if Warn_On_Dereference then
-               Error_Msg_N ("?implicit dereference", N);
-            end if;
-
+            Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
          else
             T := It.Typ;
          end if;
 
          if Is_Record_Type (T) then
             Comp := First_Entity (T);
-
             while Present (Comp) loop
-
                if Chars (Comp) = Chars (Sel)
                  and then Is_Visible_Component (Comp)
                then
@@ -2210,7 +2253,6 @@ package body Sem_Ch4 is
 
          elsif Is_Concurrent_Type (T) then
             Comp := First_Entity (T);
-
             while Present (Comp)
               and then Comp /= First_Private_Entity (T)
             loop
@@ -2231,10 +2273,8 @@ package body Sem_Ch4 is
 
                   if Is_Access_Type (Etype (Nam)) then
                      Insert_Explicit_Dereference (Nam);
-
-                     if Warn_On_Dereference then
-                        Error_Msg_N ("?implicit dereference", N);
-                     end if;
+                     Error_Msg_NW
+                       (Warn_On_Dereference, "?implicit dereference", N);
                   end if;
                end if;
 
@@ -2252,7 +2292,6 @@ package body Sem_Ch4 is
          Set_Entity (Sel, Any_Id);
          Set_Etype  (Sel, Any_Type);
       end if;
-
    end Analyze_Overloaded_Selected_Component;
 
    ----------------------------------
@@ -2271,8 +2310,8 @@ package body Sem_Ch4 is
       if T = Any_Type then
          return;
       end if;
-      Check_Fully_Declared (T, N);
 
+      Check_Fully_Declared (T, N);
       Analyze_Expression (Expression (N));
       Set_Etype  (N, T);
    end Analyze_Qualified_Expression;
@@ -2295,6 +2334,10 @@ package body Sem_Ch4 is
       --  Test one interpretation of the low bound against all those
       --  of the high bound.
 
+      procedure Check_Universal_Expression (N : Node_Id);
+      --  In Ada83, reject bounds of a universal range that are not
+      --  literals or entity names.
+
       -----------------------
       -- Check_Common_Type --
       -----------------------
@@ -2308,7 +2351,7 @@ package body Sem_Ch4 is
             then
                Add_One_Interp (N, Base_Type (T2), Base_Type (T2));
 
-            elsif (T1 = T2) then
+            elsif T1 = T2 then
                Add_One_Interp (N, T1, T1);
 
             else
@@ -2327,7 +2370,6 @@ package body Sem_Ch4 is
             Check_Common_Type (T, Etype (H));
          else
             Get_First_Interp (H, I2, It2);
-
             while Present (It2.Typ) loop
                Check_Common_Type (T, It2.Typ);
                Get_Next_Interp (I2, It2);
@@ -2335,6 +2377,21 @@ package body Sem_Ch4 is
          end if;
       end Check_High_Bound;
 
+      -----------------------------
+      -- Is_Universal_Expression --
+      -----------------------------
+
+      procedure Check_Universal_Expression (N : Node_Id) is
+      begin
+         if Etype (N) = Universal_Integer
+           and then Nkind (N) /= N_Integer_Literal
+           and then not Is_Entity_Name (N)
+           and then Nkind (N) /= N_Attribute_Reference
+         then
+            Error_Msg_N ("illegal bound in discrete range", N);
+         end if;
+      end Check_Universal_Expression;
+
    --  Start of processing for Analyze_Range
 
    begin
@@ -2350,7 +2407,6 @@ package body Sem_Ch4 is
             Check_High_Bound (Etype (L));
          else
             Get_First_Interp (L, I1, It1);
-
             while Present (It1.Typ) loop
                Check_High_Bound (It1.Typ);
                Get_Next_Interp (I1, It1);
@@ -2363,6 +2419,15 @@ package body Sem_Ch4 is
             Error_Msg_N ("incompatible types in range ", N);
          end if;
       end if;
+
+      if Ada_Version = Ada_83
+        and then
+          (Nkind (Parent (N)) = N_Loop_Parameter_Specification
+             or else Nkind (Parent (N)) = N_Constrained_Array_Definition)
+      then
+         Check_Universal_Expression (L);
+         Check_Universal_Expression (H);
+      end if;
    end Analyze_Range;
 
    -----------------------
@@ -2372,7 +2437,6 @@ package body Sem_Ch4 is
    procedure Analyze_Reference (N : Node_Id) is
       P        : constant Node_Id := Prefix (N);
       Acc_Type : Entity_Id;
-
    begin
       Analyze (P);
       Acc_Type := Create_Itype (E_Allocator_Type, N);
@@ -2422,7 +2486,7 @@ package body Sem_Ch4 is
          --  (Breaks 2129-008) ???.
 
          if Nkind (Name) = N_Function_Call then
-            Resolve (Name, Etype (Name));
+            Resolve (Name);
          end if;
 
          Prefix_Type := Etype (Name);
@@ -2445,9 +2509,7 @@ package body Sem_Ch4 is
          --  Normal case of selected component applied to access type
 
          else
-            if Warn_On_Dereference then
-               Error_Msg_N ("?implicit dereference", N);
-            end if;
+            Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
          end if;
 
          Prefix_Type := Designated_Type (Prefix_Type);
@@ -2490,10 +2552,7 @@ package body Sem_Ch4 is
 
          if Is_Access_Type (Etype (Name)) then
             Insert_Explicit_Dereference (Name);
-
-            if Warn_On_Dereference then
-               Error_Msg_N ("?implicit dereference", N);
-            end if;
+            Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
          end if;
 
       elsif Is_Record_Type (Prefix_Type) then
@@ -2501,7 +2560,6 @@ package body Sem_Ch4 is
          --  Find component with given name
 
          while Present (Comp) loop
-
             if Chars (Comp) = Chars (Sel)
               and then Is_Visible_Component (Comp)
             then
@@ -2511,7 +2569,7 @@ package body Sem_Ch4 is
                Set_Etype (Sel, Etype (Comp));
 
                if Ekind (Comp) = E_Discriminant then
-                  if Is_Unchecked_Union (Prefix_Type) then
+                  if Is_Unchecked_Union (Base_Type (Prefix_Type)) then
                      Error_Msg_N
                        ("cannot reference discriminant of Unchecked_Union",
                         Sel);
@@ -2530,7 +2588,7 @@ package body Sem_Ch4 is
                --  to duplicate this prefix and duplication is only allowed
                --  on fully resolved expressions.
 
-               Resolve (Name, Etype (Name));
+               Resolve (Name);
 
                --  We never need an actual subtype for the case of a selection
                --  for a indexed component of a non-packed array, since in
@@ -2568,7 +2626,7 @@ package body Sem_Ch4 is
                --  In all other cases, we currently build an actual subtype. It
                --  seems likely that many of these cases can be avoided, but
                --  right now, the front end makes direct references to the
-               --  bounds (e.g. in egnerating a length check), and if we do
+               --  bounds (e.g. in generating a length check), and if we do
                --  not make an actual subtype, we end up getting a direct
                --  reference to a discriminant which will not do.
 
@@ -2585,7 +2643,8 @@ package body Sem_Ch4 is
                      --  main attributes of the subtype.
 
                      declare
-                        Subt : Entity_Id := Defining_Identifier (Act_Decl);
+                        Subt : constant Entity_Id :=
+                                 Defining_Identifier (Act_Decl);
 
                      begin
                         Set_Etype (Subt, Base_Type (Etype (Comp)));
@@ -2601,6 +2660,20 @@ package body Sem_Ch4 is
             Next_Entity (Comp);
          end loop;
 
+         --  Ada 2005 (AI-252)
+
+         if Ada_Version >= Ada_05
+           and then Is_Tagged_Type (Prefix_Type)
+           and then Try_Object_Operation (N)
+         then
+            return;
+
+            --  If the transformation fails, it will be necessary
+            --  to redo the analysis with all errors enabled, to indicate
+            --  candidate interpretations and reasons for each failure ???
+
+         end if;
+
       elsif Is_Private_Type (Prefix_Type) then
 
          --  Allow access only to discriminants of the type. If the
@@ -2613,7 +2686,6 @@ package body Sem_Ch4 is
          end if;
 
          while Present (Comp) loop
-
             if Chars (Comp) = Chars (Sel) then
                if Ekind (Comp) = E_Discriminant then
                   Set_Entity_With_Style_Check (Sel, Comp);
@@ -2684,17 +2756,16 @@ package body Sem_Ch4 is
 
                if Is_Access_Type (Etype (Name)) then
                   Insert_Explicit_Dereference (Name);
-
-                  if Warn_On_Dereference then
-                     Error_Msg_N ("?implicit dereference", N);
-                  end if;
+                  Error_Msg_NW
+                    (Warn_On_Dereference, "?implicit dereference", N);
                end if;
             end if;
 
             <<Next_Comp>>
                Next_Entity (Comp);
                exit when not In_Scope
-                 and then Comp = First_Private_Entity (Prefix_Type);
+                 and then
+                   Comp = First_Private_Entity (Base_Type (Prefix_Type));
          end loop;
 
          Set_Is_Overloaded (N, Is_Overloaded (Sel));
@@ -2705,7 +2776,7 @@ package body Sem_Ch4 is
          Error_Msg_NE ("invalid prefix in selected component&", N, Sel);
       end if;
 
-      --  If N still has no type, the component is not defined in the prefix.
+      --  If N still has no type, the component is not defined in the prefix
 
       if Etype (N) = Any_Type then
 
@@ -2736,6 +2807,34 @@ package body Sem_Ch4 is
             Analyze_Selected_Component (N);
             return;
 
+         elsif Ekind (Prefix_Type) = E_Record_Subtype_With_Private
+           and then Is_Generic_Actual_Type (Prefix_Type)
+           and then Present (Full_View (Prefix_Type))
+         then
+            --  Similarly, if this the actual for a formal derived type, the
+            --  component inherited from the generic parent may not be visible
+            --  in the actual, but the selected component is legal.
+
+            declare
+               Comp : Entity_Id;
+
+            begin
+               Comp :=
+                 First_Component (Generic_Parent_Type (Parent (Prefix_Type)));
+               while Present (Comp) loop
+                  if Chars (Comp) = Chars (Sel) then
+                     Set_Entity_With_Style_Check (Sel, Comp);
+                     Set_Etype (Sel, Etype (Comp));
+                     Set_Etype (N,   Etype (Comp));
+                     exit;
+                  end if;
+
+                  Next_Component (Comp);
+               end loop;
+
+               pragma Assert (Etype (N) /= Any_Type);
+            end;
+
          else
             if Ekind (Prefix_Type) = E_Record_Subtype then
 
@@ -2747,9 +2846,7 @@ package body Sem_Ch4 is
                --  compilation error anyway.
 
                Comp := First_Component (Base_Type (Prefix_Type));
-
                while Present (Comp) loop
-
                   if Chars (Comp) = Chars (Sel)
                     and then Is_Visible_Component (Comp)
                   then
@@ -2851,6 +2948,10 @@ package body Sem_Ch4 is
       --  If the prefix is overloaded, select those interpretations that
       --  yield a one-dimensional array type.
 
+      ------------------------------
+      -- Analyze_Overloaded_Slice --
+      ------------------------------
+
       procedure Analyze_Overloaded_Slice is
          I   : Interp_Index;
          It  : Interp;
@@ -2858,17 +2959,14 @@ package body Sem_Ch4 is
 
       begin
          Set_Etype (N, Any_Type);
-         Get_First_Interp (P, I, It);
 
+         Get_First_Interp (P, I, It);
          while Present (It.Nam) loop
             Typ := It.Typ;
 
             if Is_Access_Type (Typ) then
                Typ := Designated_Type (Typ);
-
-               if Warn_On_Dereference then
-                  Error_Msg_N ("?implicit dereference", N);
-               end if;
+               Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
             end if;
 
             if Is_Array_Type (Typ)
@@ -2889,12 +2987,7 @@ package body Sem_Ch4 is
    --  Start of processing for Analyze_Slice
 
    begin
-      --  Analyze the prefix if not done already
-
-      if No (Etype (P)) then
-         Analyze (P);
-      end if;
-
+      Analyze (P);
       Analyze (D);
 
       if Is_Overloaded (P) then
@@ -2906,10 +2999,7 @@ package body Sem_Ch4 is
 
          if Is_Access_Type (Array_Type) then
             Array_Type := Designated_Type (Array_Type);
-
-            if Warn_On_Dereference then
-               Error_Msg_N ("?implicit dereference", N);
-            end if;
+            Error_Msg_NW (Warn_On_Dereference, "?implicit dereference", N);
          end if;
 
          if not Is_Array_Type (Array_Type) then
@@ -2984,7 +3074,7 @@ package body Sem_Ch4 is
          Error_Msg_N ("\use qualified expression instead", N);
 
       elsif Nkind (Expr) = N_Character_Literal then
-         if Ada_83 then
+         if Ada_Version = Ada_83 then
             Resolve (Expr, T);
          else
             Error_Msg_N ("argument of conversion cannot be character literal",
@@ -3001,7 +3091,6 @@ package body Sem_Ch4 is
          Error_Msg_N ("argument of conversion cannot be access", N);
          Error_Msg_N ("\use qualified expression instead", N);
       end if;
-
    end Analyze_Type_Conversion;
 
    ----------------------
@@ -3027,9 +3116,7 @@ package body Sem_Ch4 is
 
       else
          Op_Id := Get_Name_Entity_Id (Chars (N));
-
          while Present (Op_Id) loop
-
             if Ekind (Op_Id) = E_Operator then
                if No (Next_Entity (First_Entity (Op_Id))) then
                   Find_Unary_Types (R, Op_Id,  N);
@@ -3160,6 +3247,10 @@ package body Sem_Ch4 is
       function Specific_Type (T1, T2 : Entity_Id) return Entity_Id;
       --  Get specific type (i.e. non-universal type if there is one)
 
+      -------------------
+      -- Specific_Type --
+      -------------------
+
       function Specific_Type (T1, T2 : Entity_Id) return Entity_Id is
       begin
          if T1 = Universal_Integer or else T1 = Universal_Real then
@@ -3195,7 +3286,8 @@ package body Sem_Ch4 is
             --  from source and Fixed_As_Integer cannot apply.
 
             if Nkind (N) not in N_Op
-              or else not Treat_Fixed_As_Integer (N) then
+              or else not Treat_Fixed_As_Integer (N)
+            then
                Add_One_Interp (N, Op_Id, Universal_Fixed);
             end if;
 
@@ -3259,7 +3351,6 @@ package body Sem_Ch4 is
          end if;
 
       elsif Op_Name = Name_Op_Expon then
-
          if Is_Numeric_Type (T1)
            and then not Is_Fixed_Point_Type (T1)
            and then (Base_Type (T2) = Base_Type (Standard_Integer)
@@ -3306,24 +3397,23 @@ package body Sem_Ch4 is
       --  possible misspellings, these misspellings will be suggested as
       --  possible correction.
 
-      if not (Is_Private_Type (Prefix) or Is_Record_Type (Prefix)) then
+      if not (Is_Private_Type (Prefix) or else Is_Record_Type (Prefix)) then
+
          --  Concurrent types should be handled as well ???
+
          return;
       end if;
 
       Get_Name_String (Chars (Sel));
 
       declare
-         S  : constant String (1 .. Name_Len) :=
-                Name_Buffer (1 .. Name_Len);
+         S  : constant String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
 
       begin
          Comp  := First_Entity (Prefix);
-
          while Nr_Of_Suggestions <= Max_Suggestions
             and then Present (Comp)
          loop
-
             if Is_Visible_Component (Comp) then
                Get_Name_String (Chars (Comp));
 
@@ -3361,7 +3451,6 @@ package body Sem_Ch4 is
    function Defined_In_Scope (T : Entity_Id; S : Entity_Id) return Boolean
    is
       S1 : constant Entity_Id := Scope (Base_Type (T));
-
    begin
       return S1 = S
         or else (S1 = System_Aux_Id and then S = Scope (S1));
@@ -3372,16 +3461,22 @@ package body Sem_Ch4 is
    -------------------
 
    procedure Diagnose_Call (N : Node_Id; Nam : Node_Id) is
-      Actual  : Node_Id;
-      X       : Interp_Index;
-      It      : Interp;
-      Success : Boolean;
+      Actual           : Node_Id;
+      X                : Interp_Index;
+      It               : Interp;
+      Success          : Boolean;
+      Err_Mode         : Boolean;
+      New_Nam          : Node_Id;
+      Void_Interp_Seen : Boolean := False;
 
    begin
-      if Extensions_Allowed then
+      if Ada_Version >= Ada_05 then
          Actual := First_Actual (N);
-
          while Present (Actual) loop
+
+            --  Ada 2005 (AI-50217): Post an error in case of premature
+            --  usage of an entity from the limited view.
+
             if not Analyzed (Etype (Actual))
              and then From_With_Type (Etype (Actual))
             then
@@ -3396,37 +3491,41 @@ package body Sem_Ch4 is
          end loop;
       end if;
 
-      if All_Errors_Mode then
-
-         --   Analyze each candidate call again, with full error reporting
-         --   for each.
-
-         Error_Msg_N ("\no candidate interpretations "
-           & "match the actuals:!", Nam);
-
+      --   Analyze each candidate call again, with full error reporting
+      --   for each.
+
+      Error_Msg_N
+        ("no candidate interpretations match the actuals:!", Nam);
+      Err_Mode := All_Errors_Mode;
+      All_Errors_Mode := True;
+
+      --  If this is a call to an operation of a concurrent type,
+      --  the failed interpretations have been removed from the
+      --  name. Recover them to provide full diagnostics.
+
+      if Nkind (Parent (Nam)) = N_Selected_Component then
+         Set_Entity (Nam, Empty);
+         New_Nam := New_Copy_Tree (Parent (Nam));
+         Set_Is_Overloaded (New_Nam, False);
+         Set_Is_Overloaded (Selector_Name (New_Nam), False);
+         Set_Parent (New_Nam, Parent (Parent (Nam)));
+         Analyze_Selected_Component (New_Nam);
+         Get_First_Interp (Selector_Name (New_Nam), X, It);
+      else
          Get_First_Interp (Nam, X, It);
+      end if;
 
-         while Present (It.Nam) loop
-            Analyze_One_Call (N, It.Nam, True, Success);
-            Get_Next_Interp (X, It);
-         end loop;
-
-      else
-         if OpenVMS then
-            Error_Msg_N
-              ("invalid parameter list in call " &
-               "('/'R'E'P'O'R'T'_'E'R'R'O'R'S'='F'U'L'L for details)!",
-                Nam);
-         else
-            Error_Msg_N
-              ("invalid parameter list in call (use -gnatf for details)!",
-                Nam);
+      while Present (It.Nam) loop
+         if Etype (It.Nam) = Standard_Void_Type then
+            Void_Interp_Seen := True;
          end if;
-      end if;
+
+         Analyze_One_Call (N, It.Nam, True, Success);
+         Get_Next_Interp (X, It);
+      end loop;
 
       if Nkind (N) = N_Function_Call then
          Get_First_Interp (Nam, X, It);
-
          while Present (It.Nam) loop
             if Ekind (It.Nam) = E_Function
               or else Ekind (It.Nam) = E_Operator
@@ -3441,8 +3540,8 @@ package body Sem_Ch4 is
          --  more precise message. Ditto if this appears as the prefix
          --  of a selected component, which may be a lexical error.
 
-         Error_Msg_N (
-         "\context requires function call, found procedure name", Nam);
+         Error_Msg_N
+           ("\context requires function call, found procedure name", Nam);
 
          if Nkind (Parent (N)) = N_Selected_Component
            and then N = Prefix (Parent (N))
@@ -3450,7 +3549,15 @@ package body Sem_Ch4 is
             Error_Msg_N (
               "\period should probably be semicolon", Parent (N));
          end if;
+
+      elsif Nkind (N) = N_Procedure_Call_Statement
+        and then not Void_Interp_Seen
+      then
+         Error_Msg_N (
+         "\function name found in procedure call", Nam);
       end if;
+
+      All_Errors_Mode := Err_Mode;
    end Diagnose_Call;
 
    ---------------------------
@@ -3462,19 +3569,24 @@ package body Sem_Ch4 is
       Op_Id : Entity_Id;
       N     : Node_Id)
    is
-      Index1, Index2 : Interp_Index;
-      It1, It2 : Interp;
+      Index1 : Interp_Index;
+      Index2 : Interp_Index;
+      It1    : Interp;
+      It2    : Interp;
 
       procedure Check_Right_Argument (T : Entity_Id);
       --  Check right operand of operator
 
+      --------------------------
+      -- Check_Right_Argument --
+      --------------------------
+
       procedure Check_Right_Argument (T : Entity_Id) is
       begin
          if not Is_Overloaded (R) then
             Check_Arithmetic_Pair (T, Etype (R), Op_Id,  N);
          else
             Get_First_Interp (R, Index2, It2);
-
             while Present (It2.Typ) loop
                Check_Arithmetic_Pair (T, It2.Typ, Op_Id, N);
                Get_Next_Interp (Index2, It2);
@@ -3515,6 +3627,10 @@ package body Sem_Ch4 is
       --  Special case for logical operations one of whose operands is an
       --  integer literal. If both are literal the result is any modular type.
 
+      ----------------------------
+      -- Check_Numeric_Argument --
+      ----------------------------
+
       procedure Check_Numeric_Argument (T : Entity_Id) is
       begin
          if T = Universal_Integer then
@@ -3529,7 +3645,6 @@ package body Sem_Ch4 is
 
    begin
       if not Is_Overloaded (L) then
-
          if Etype (L) = Universal_Integer
            or else Etype (L) = Any_Modular
          then
@@ -3538,10 +3653,8 @@ package body Sem_Ch4 is
 
             else
                Get_First_Interp (R, Index, It);
-
                while Present (It.Typ) loop
                   Check_Numeric_Argument (It.Typ);
-
                   Get_Next_Interp (Index, It);
                end loop;
             end if;
@@ -3554,7 +3667,6 @@ package body Sem_Ch4 is
 
       else
          Get_First_Interp (L, Index, It);
-
          while Present (It.Typ) loop
             if Valid_Boolean_Arg (It.Typ)
               and then Has_Compatible_Type (R, It.Typ)
@@ -3589,6 +3701,10 @@ package body Sem_Ch4 is
       --  if there is more than one interpretation of the operands that is
       --  compatible with comparison, the operation is ambiguous.
 
+      --------------------
+      -- Try_One_Interp --
+      --------------------
+
       procedure Try_One_Interp (T1 : Entity_Id) is
       begin
 
@@ -3638,6 +3754,15 @@ package body Sem_Ch4 is
    --  Start processing for Find_Comparison_Types
 
    begin
+      --  If left operand is aggregate, the right operand has to
+      --  provide a usable type for it.
+
+      if Nkind (L) = N_Aggregate
+        and then Nkind (R) /= N_Aggregate
+      then
+         Find_Comparison_Types (R, L, Op_Id, N);
+         return;
+      end if;
 
       if Nkind (N) = N_Function_Call
          and then Nkind (Name (N)) = N_Expanded_Name
@@ -3660,7 +3785,6 @@ package body Sem_Ch4 is
 
       else
          Get_First_Interp (L, Index, It);
-
          while Present (It.Typ) loop
             Try_One_Interp (It.Typ);
             Get_Next_Interp (Index, It);
@@ -3679,7 +3803,7 @@ package body Sem_Ch4 is
       T1    : Entity_Id)
    is
       Index : Interp_Index;
-      It   : Interp;
+      It    : Interp;
 
    begin
       if T1 = Universal_Integer
@@ -3690,7 +3814,6 @@ package body Sem_Ch4 is
               (N, Op_Id, Standard_Boolean, Base_Type (Etype (R)));
          else
             Get_First_Interp (R, Index, It);
-
             while Present (It.Typ) loop
                if Covers (It.Typ, T1) then
                   Add_One_Interp
@@ -3755,9 +3878,12 @@ package body Sem_Ch4 is
       --  is ambiguous and an error can be emitted now, after trying to
       --  disambiguate, i.e. applying preference rules.
 
+      --------------------
+      -- Try_One_Interp --
+      --------------------
+
       procedure Try_One_Interp (T1 : Entity_Id) is
       begin
-
          --  If the operator is an expanded name, then the type of the operand
          --  must be defined in the corresponding scope. If the type is
          --  universal, the context will impose the correct type. An anonymous
@@ -3777,10 +3903,18 @@ package body Sem_Ch4 is
             return;
          end if;
 
+         --  Ada 2005 (AI-230): Keep restriction imposed by Ada 83 and 95:
+         --  Do not allow anonymous access types in equality operators.
+
+         if Ada_Version < Ada_05
+           and then Ekind (T1) = E_Anonymous_Access_Type
+         then
+            return;
+         end if;
+
          if T1 /= Standard_Void_Type
            and then not Is_Limited_Type (T1)
            and then not Is_Limited_Composite (T1)
-           and then Ekind (T1) /= E_Anonymous_Access_Type
            and then Has_Compatible_Type (R, T1)
          then
             if Found
@@ -3821,6 +3955,15 @@ package body Sem_Ch4 is
    --  Start of processing for Find_Equality_Types
 
    begin
+      --  If left operand is aggregate, the right operand has to
+      --  provide a usable type for it.
+
+      if Nkind (L) = N_Aggregate
+        and then Nkind (R) /= N_Aggregate
+      then
+         Find_Equality_Types (R, L, Op_Id, N);
+         return;
+      end if;
 
       if Nkind (N) = N_Function_Call
          and then Nkind (Name (N)) = N_Expanded_Name
@@ -3840,10 +3983,9 @@ package body Sem_Ch4 is
 
       if not Is_Overloaded (L) then
          Try_One_Interp (Etype (L));
-      else
 
+      else
          Get_First_Interp (L, Index, It);
-
          while Present (It.Typ) loop
             Try_One_Interp (It.Typ);
             Get_Next_Interp (Index, It);
@@ -3865,17 +4007,14 @@ package body Sem_Ch4 is
 
    begin
       if not Is_Overloaded (R) then
-
          if Etype (R) = Universal_Integer then
             Add_One_Interp (N, Op_Id, Any_Modular);
-
          elsif Valid_Boolean_Arg (Etype (R)) then
             Add_One_Interp (N, Op_Id, Etype (R));
          end if;
 
       else
          Get_First_Interp (R, Index, It);
-
          while Present (It.Typ) loop
             if Valid_Boolean_Arg (It.Typ) then
                Add_One_Interp (N, Op_Id, It.Typ);
@@ -3906,7 +4045,6 @@ package body Sem_Ch4 is
 
       else
          Get_First_Interp (R, Index, It);
-
          while Present (It.Typ) loop
             if Is_Numeric_Type (It.Typ) then
                Add_One_Interp (N, Op_Id, Base_Type (It.Typ));
@@ -3917,46 +4055,6 @@ package body Sem_Ch4 is
       end if;
    end Find_Unary_Types;
 
-   ---------------------------------
-   -- Insert_Explicit_Dereference --
-   ---------------------------------
-
-   procedure Insert_Explicit_Dereference (N : Node_Id) is
-      New_Prefix : Node_Id := Relocate_Node (N);
-      I          : Interp_Index;
-      It         : Interp;
-      T          : Entity_Id;
-
-   begin
-      Save_Interps (N, New_Prefix);
-      Rewrite (N,
-        Make_Explicit_Dereference (Sloc (N), Prefix => New_Prefix));
-
-      Set_Etype (N, Designated_Type (Etype (New_Prefix)));
-
-      if Is_Overloaded (New_Prefix) then
-
-         --  The deference is also overloaded, and its interpretations are the
-         --  designated types of the interpretations of the original node.
-
-         Set_Is_Overloaded (N);
-         Get_First_Interp (New_Prefix, I, It);
-
-         while Present (It.Nam) loop
-            T := It.Typ;
-
-            if Is_Access_Type (T) then
-               Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
-            end if;
-
-            Get_Next_Interp (I, It);
-         end loop;
-
-         End_Interp_List;
-      end if;
-
-   end Insert_Explicit_Dereference;
-
    ------------------
    -- Junk_Operand --
    ------------------
@@ -4044,6 +4142,8 @@ package body Sem_Ch4 is
 
    procedure Operator_Check (N : Node_Id) is
    begin
+      Remove_Abstract_Operations (N);
+
       --  Test for case of no interpretation found for operator
 
       if Etype (N) = Any_Type then
@@ -4069,14 +4169,13 @@ package body Sem_Ch4 is
             then
                return;
 
-            --  We explicitly check for the case of concatenation of
-            --  component with component to avoid reporting spurious
-            --  matching array types that might happen to be lurking
-            --  in distant packages (such as run-time packages). This
-            --  also prevents inconsistencies in the messages for certain
-            --  ACVC B tests, which can vary depending on types declared
-            --  in run-time interfaces. A further improvement, when
-            --  aggregates are present, is to look for a well-typed operand.
+            --  We explicitly check for the case of concatenation of component
+            --  with component to avoid reporting spurious matching array types
+            --  that might happen to be lurking in distant packages (such as
+            --  run-time packages). This also prevents inconsistencies in the
+            --  messages for certain ACVC B tests, which can vary depending on
+            --  types declared in run-time interfaces. Another improvement when
+            --  aggregates are present is to look for a well-typed operand.
 
             elsif Present (Candidate_Type)
               and then (Nkind (N) /= N_Op_Concat
@@ -4214,34 +4313,244 @@ package body Sem_Ch4 is
                return;
 
             else
-               Error_Msg_N ("invalid operand types for operator&", N);
+               if Nkind (N) in N_Binary_Op then
+                  if not Is_Overloaded (L)
+                    and then not Is_Overloaded (R)
+                    and then Base_Type (Etype (L)) = Base_Type (Etype (R))
+                  then
+                     Error_Msg_Node_2 := Etype (R);
+                     Error_Msg_N ("there is no applicable operator& for}", N);
 
-               if Nkind (N) in N_Binary_Op
-                 and then Nkind (N) /= N_Op_Concat
-               then
-                  Error_Msg_NE ("\left operand has}!",  N, Etype (L));
-                  Error_Msg_NE ("\right operand has}!", N, Etype (R));
+                  else
+                     Error_Msg_N ("invalid operand types for operator&", N);
+
+                     if Nkind (N) /= N_Op_Concat then
+                        Error_Msg_NE ("\left operand has}!",  N, Etype (L));
+                        Error_Msg_NE ("\right operand has}!", N, Etype (R));
+                     end if;
+                  end if;
                end if;
             end if;
          end;
       end if;
    end Operator_Check;
 
+   --------------------------------
+   -- Remove_Abstract_Operations --
+   --------------------------------
+
+   procedure Remove_Abstract_Operations (N : Node_Id) is
+      I            : Interp_Index;
+      It           : Interp;
+      Abstract_Op  : Entity_Id := Empty;
+
+      --  AI-310: If overloaded, remove abstract non-dispatching
+      --  operations. We activate this if either extensions are
+      --  enabled, or if the abstract operation in question comes
+      --  from a predefined file. This latter test allows us to
+      --  use abstract to make operations invisible to users. In
+      --  particular, if type Address is non-private and abstract
+      --  subprograms are used to hide its operators, they will be
+      --  truly hidden.
+
+      type Operand_Position is (First_Op, Second_Op);
+      Univ_Type : constant Entity_Id := Universal_Interpretation (N);
+
+      procedure Remove_Address_Interpretations (Op : Operand_Position);
+      --  Ambiguities may arise when the operands are literal and the
+      --  address operations in s-auxdec are visible. In that case, remove
+      --  the interpretation of a literal as Address, to retain the semantics
+      --  of Address as a private type.
+
+      ------------------------------------
+      -- Remove_Address_Interpretations --
+      ------------------------------------
+
+      procedure Remove_Address_Interpretations (Op : Operand_Position) is
+         Formal : Entity_Id;
+
+      begin
+         if Is_Overloaded (N) then
+            Get_First_Interp (N, I, It);
+            while Present (It.Nam) loop
+               Formal := First_Entity (It.Nam);
+
+               if Op = Second_Op then
+                  Formal := Next_Entity (Formal);
+               end if;
+
+               if Is_Descendent_Of_Address (Etype (Formal)) then
+                  Remove_Interp (I);
+               end if;
+
+               Get_Next_Interp (I, It);
+            end loop;
+         end if;
+      end Remove_Address_Interpretations;
+
+   --  Start of processing for Remove_Abstract_Operations
+
+   begin
+      if Is_Overloaded (N) then
+         Get_First_Interp (N, I, It);
+
+         while Present (It.Nam) loop
+            if not Is_Type (It.Nam)
+              and then Is_Abstract (It.Nam)
+              and then not Is_Dispatching_Operation (It.Nam)
+              and then
+                (Ada_Version >= Ada_05
+                   or else Is_Predefined_File_Name
+                             (Unit_File_Name (Get_Source_Unit (It.Nam))))
+
+            then
+               Abstract_Op := It.Nam;
+               Remove_Interp (I);
+               exit;
+            end if;
+
+            Get_Next_Interp (I, It);
+         end loop;
+
+         if No (Abstract_Op) then
+            return;
+
+         elsif Nkind (N) in N_Op then
+
+            --  Remove interpretations that treat literals as addresses.
+            --  This is never appropriate.
+
+            if Nkind (N) in N_Binary_Op then
+               declare
+                  U1 : constant Boolean :=
+                     Present (Universal_Interpretation (Right_Opnd (N)));
+                  U2 : constant Boolean :=
+                     Present (Universal_Interpretation (Left_Opnd (N)));
+
+               begin
+                  if U1 and then not U2 then
+                     Remove_Address_Interpretations (Second_Op);
+
+                  elsif U2 and then not U1 then
+                     Remove_Address_Interpretations (First_Op);
+                  end if;
+
+                  if not (U1 and U2) then
+
+                     --  Remove corresponding predefined operator, which is
+                     --  always added to the overload set.
+
+                     Get_First_Interp (N, I, It);
+                     while Present (It.Nam) loop
+                        if Scope (It.Nam) = Standard_Standard
+                          and then Base_Type (It.Typ) =
+                                   Base_Type (Etype (Abstract_Op))
+                        then
+                           Remove_Interp (I);
+                        end if;
+
+                        Get_Next_Interp (I, It);
+                     end loop;
+
+                  elsif Is_Overloaded (N)
+                    and then Present (Univ_Type)
+                  then
+                     --  If both operands have a universal interpretation,
+                     --  select the predefined operator and discard others.
+
+                     Get_First_Interp (N, I, It);
+
+                     while Present (It.Nam) loop
+                        if Scope (It.Nam) = Standard_Standard then
+                           Set_Etype (N, Univ_Type);
+                           Set_Entity (N, It.Nam);
+                           Set_Is_Overloaded (N, False);
+                           exit;
+                        end if;
+
+                        Get_Next_Interp (I, It);
+                     end loop;
+                  end if;
+               end;
+            end if;
+
+         elsif Nkind (N) = N_Function_Call
+           and then
+             (Nkind (Name (N)) = N_Operator_Symbol
+                or else
+                  (Nkind (Name (N)) = N_Expanded_Name
+                     and then
+                       Nkind (Selector_Name (Name (N))) = N_Operator_Symbol))
+         then
+
+            declare
+               Arg1 : constant Node_Id := First (Parameter_Associations (N));
+               U1   : constant Boolean :=
+                        Present (Universal_Interpretation (Arg1));
+               U2   : constant Boolean :=
+                        Present (Next (Arg1)) and then
+                        Present (Universal_Interpretation (Next (Arg1)));
+
+            begin
+               if U1 and then not U2 then
+                  Remove_Address_Interpretations (First_Op);
+
+               elsif U2 and then not U1 then
+                  Remove_Address_Interpretations (Second_Op);
+               end if;
+
+               if not (U1 and U2) then
+                  Get_First_Interp (N, I, It);
+                  while Present (It.Nam) loop
+                     if Scope (It.Nam) = Standard_Standard
+                       and then It.Typ = Base_Type (Etype (Abstract_Op))
+                     then
+                        Remove_Interp (I);
+                     end if;
+
+                     Get_Next_Interp (I, It);
+                  end loop;
+               end if;
+            end;
+         end if;
+
+         --  If the removal has left no valid interpretations, emit
+         --  error message now and label node as illegal.
+
+         if Present (Abstract_Op) then
+            Get_First_Interp (N, I, It);
+
+            if No (It.Nam) then
+
+               --  Removal of abstract operation left no viable candidate.
+
+               Set_Etype (N, Any_Type);
+               Error_Msg_Sloc := Sloc (Abstract_Op);
+               Error_Msg_NE
+                 ("cannot call abstract operation& declared#", N, Abstract_Op);
+            end if;
+         end if;
+      end if;
+   end Remove_Abstract_Operations;
+
    -----------------------
    -- Try_Indirect_Call --
    -----------------------
 
    function Try_Indirect_Call
-     (N      : Node_Id;
-      Nam    : Entity_Id;
-      Typ    : Entity_Id)
-      return   Boolean
+     (N   : Node_Id;
+      Nam : Entity_Id;
+      Typ : Entity_Id) return Boolean
    is
-      Actuals    : List_Id   := Parameter_Associations (N);
-      Actual     : Node_Id   := First (Actuals);
-      Formal     : Entity_Id := First_Formal (Designated_Type (Typ));
+      Actual  : Node_Id;
+      Formal  : Entity_Id;
+      Call_OK : Boolean;
 
    begin
+      Normalize_Actuals (N, Designated_Type (Typ), False, Call_OK);
+      Actual := First_Actual (N);
+      Formal := First_Formal (Designated_Type (Typ));
+
       while Present (Actual)
         and then Present (Formal)
       loop
@@ -4276,16 +4585,17 @@ package body Sem_Ch4 is
    ----------------------
 
    function Try_Indexed_Call
-     (N      : Node_Id;
-      Nam    : Entity_Id;
-      Typ    : Entity_Id)
-      return   Boolean
+     (N   : Node_Id;
+      Nam : Entity_Id;
+      Typ : Entity_Id) return Boolean
    is
-      Actuals    : List_Id   := Parameter_Associations (N);
-      Actual     : Node_Id   := First (Actuals);
-      Index      : Entity_Id := First_Index (Typ);
+      Actuals : constant List_Id   := Parameter_Associations (N);
+      Actual : Node_Id;
+      Index  : Entity_Id;
 
    begin
+      Actual := First (Actuals);
+      Index := First_Index (Typ);
       while Present (Actual)
         and then Present (Index)
       loop
@@ -4320,7 +4630,401 @@ package body Sem_Ch4 is
       else
          return False;
       end if;
-
    end Try_Indexed_Call;
 
+   --------------------------
+   -- Try_Object_Operation --
+   --------------------------
+
+   function Try_Object_Operation (N : Node_Id) return Boolean is
+      Loc      : constant Source_Ptr := Sloc (N);
+      Obj      : constant Node_Id := Prefix (N);
+      Obj_Type : Entity_Id := Etype (Obj);
+      Subprog  : constant Node_Id := Selector_Name (N);
+
+      Call_Node       : Node_Id;
+      Call_Node_Case  : Node_Id := Empty;
+      First_Actual    : Node_Id;
+      Node_To_Replace : Node_Id;
+
+      procedure Analyze_Actuals;
+      --  If the parent of N is a subprogram call, then analyze the actual
+      --  parameters of the parent of N.
+
+      procedure Complete_Object_Operation
+        (Call_Node       : Node_Id;
+         Node_To_Replace : Node_Id;
+         Subprog         : Node_Id);
+      --  Set Subprog as the name of Call_Node, replace Node_To_Replace with
+      --  Call_Node and reanalyze Node_To_Replace.
+
+      procedure Transform_Object_Operation
+        (Call_Node       : out Node_Id;
+         First_Actual    : Node_Id;
+         Node_To_Replace : out Node_Id;
+         Subprog         : Node_Id);
+      --  Transform Object.Operation (...) to Operation (Object, ...)
+      --  Call_Node is the resulting subprogram call node, First_Actual is
+      --  either the object Obj or an explicit dereference of Obj in certain
+      --  cases, Node_To_Replace is either N or the parent of N, and Subprog
+      --  is the subprogram we are trying to match.
+
+      function Try_Class_Wide_Operation
+        (Call_Node       : Node_Id;
+         Node_To_Replace : Node_Id) return Boolean;
+      --  Traverse all the ancestor types looking for a class-wide subprogram
+      --  that matches Subprog.
+
+      function Try_Primitive_Operation
+        (Call_Node       : Node_Id;
+         Node_To_Replace : Node_Id) return Boolean;
+      --  Traverse the list of primitive subprograms looking for a subprogram
+      --  than matches Subprog.
+
+      ---------------------
+      -- Analyze_Actuals --
+      ---------------------
+
+      procedure Analyze_Actuals is
+         Actual : Node_Id;
+
+      begin
+         if (Nkind (Parent (N)) = N_Procedure_Call_Statement
+               or else
+             Nkind (Parent (N)) = N_Function_Call)
+
+            --  Avoid recursive calls
+
+           and then N /= First (Parameter_Associations (Parent (N)))
+         then
+            Actual := First (Parameter_Associations (Parent (N)));
+            while Present (Actual) loop
+               Analyze (Actual);
+               Check_Parameterless_Call (Actual);
+               Next (Actual);
+
+            end loop;
+         end if;
+      end Analyze_Actuals;
+
+      -------------------------------
+      -- Complete_Object_Operation --
+      -------------------------------
+
+      procedure Complete_Object_Operation
+        (Call_Node       : Node_Id;
+         Node_To_Replace : Node_Id;
+         Subprog         : Node_Id)
+      is
+      begin
+         Set_Name (Call_Node, New_Copy_Tree (Subprog));
+         Set_Analyzed (Call_Node, False);
+         Replace (Node_To_Replace, Call_Node);
+         Analyze (Node_To_Replace);
+
+      end Complete_Object_Operation;
+
+      --------------------------------
+      -- Transform_Object_Operation --
+      --------------------------------
+
+      procedure Transform_Object_Operation
+        (Call_Node       : out Node_Id;
+         First_Actual    : Node_Id;
+         Node_To_Replace : out Node_Id;
+         Subprog         : Node_Id)
+      is
+         Actuals     : List_Id;
+         Parent_Node : constant Node_Id := Parent (N);
+
+      begin
+         Actuals := New_List (New_Copy_Tree (First_Actual));
+
+         if (Nkind (Parent_Node) = N_Function_Call
+               or else
+             Nkind (Parent_Node) = N_Procedure_Call_Statement)
+
+            --  Avoid recursive calls
+
+           and then N /= First (Parameter_Associations (Parent_Node))
+         then
+            Node_To_Replace := Parent_Node;
+
+            Append_List_To (Actuals,
+              New_Copy_List (Parameter_Associations (Parent_Node)));
+
+            if Nkind (Parent_Node) = N_Procedure_Call_Statement then
+               Call_Node :=
+                 Make_Procedure_Call_Statement (Loc,
+                   Name => New_Copy_Tree (Subprog),
+                   Parameter_Associations => Actuals);
+
+            else
+               pragma Assert (Nkind (Parent_Node) = N_Function_Call);
+
+               Call_Node :=
+                 Make_Function_Call (Loc,
+                   Name => New_Copy_Tree (Subprog),
+                   Parameter_Associations => Actuals);
+
+            end if;
+
+         --  Parameterless call
+
+         else
+            Node_To_Replace := N;
+
+            Call_Node :=
+               Make_Function_Call (Loc,
+                 Name => New_Copy_Tree (Subprog),
+                 Parameter_Associations => Actuals);
+
+         end if;
+      end Transform_Object_Operation;
+
+      ------------------------------
+      -- Try_Class_Wide_Operation --
+      ------------------------------
+
+      function Try_Class_Wide_Operation
+        (Call_Node       : Node_Id;
+         Node_To_Replace : Node_Id) return Boolean
+      is
+         Anc_Type : Entity_Id;
+         Dummy    : Node_Id;
+         Hom      : Entity_Id;
+         Hom_Ref  : Node_Id;
+         Success  : Boolean;
+
+      begin
+         --  Loop through ancestor types, traverse their homonym chains and
+         --  gather all interpretations of the subprogram.
+
+         Anc_Type := Obj_Type;
+         loop
+            Hom := Current_Entity (Subprog);
+            while Present (Hom) loop
+               if (Ekind (Hom) = E_Procedure
+                     or else
+                   Ekind (Hom) = E_Function)
+                 and then Present (First_Formal (Hom))
+                 and then Etype (First_Formal (Hom)) =
+                            Class_Wide_Type (Anc_Type)
+               then
+                  Hom_Ref := New_Reference_To (Hom, Loc);
+
+                  --  When both the type of the object and the type of the
+                  --  first formal of the primitive operation are tagged
+                  --  access types, we use a node with the object as first
+                  --  actual.
+
+                  if Is_Access_Type (Etype (Obj))
+                    and then Ekind (Etype (First_Formal (Hom))) =
+                               E_Anonymous_Access_Type
+                  then
+                     --  Allocate the node only once
+
+                     if not Present (Call_Node_Case) then
+                        Transform_Object_Operation (
+                          Call_Node       => Call_Node_Case,
+                          First_Actual    => Obj,
+                          Node_To_Replace => Dummy,
+                          Subprog         => Subprog);
+
+                        Set_Etype (Call_Node_Case, Any_Type);
+                        Set_Parent (Call_Node_Case, Parent (Node_To_Replace));
+                     end if;
+
+                     Set_Name (Call_Node_Case, Hom_Ref);
+
+                     Analyze_One_Call (
+                       N       => Call_Node_Case,
+                       Nam     => Hom,
+                       Report  => False,
+                       Success => Success);
+
+                     if Success then
+                        Complete_Object_Operation (
+                          Call_Node       => Call_Node_Case,
+                          Node_To_Replace => Node_To_Replace,
+                          Subprog         => Hom_Ref);
+
+                        return True;
+                     end if;
+
+                  --  ??? comment required
+
+                  else
+                     Set_Name (Call_Node, Hom_Ref);
+
+                     Analyze_One_Call (
+                       N       => Call_Node,
+                       Nam     => Hom,
+                       Report  => False,
+                       Success => Success);
+
+                     if Success then
+                        Complete_Object_Operation (
+                          Call_Node       => Call_Node,
+                          Node_To_Replace => Node_To_Replace,
+                          Subprog         => Hom_Ref);
+
+                        return True;
+                     end if;
+                  end if;
+               end if;
+
+               Hom := Homonym (Hom);
+            end loop;
+
+            --  Climb to ancestor type if there is one
+
+            exit when Etype (Anc_Type) = Anc_Type;
+            Anc_Type := Etype (Anc_Type);
+         end loop;
+
+         return False;
+      end Try_Class_Wide_Operation;
+
+      -----------------------------
+      -- Try_Primitive_Operation --
+      -----------------------------
+
+      function Try_Primitive_Operation
+        (Call_Node       : Node_Id;
+         Node_To_Replace : Node_Id) return Boolean
+      is
+         Dummy          : Node_Id;
+         Elmt           : Elmt_Id;
+         Prim_Op        : Entity_Id;
+         Prim_Op_Ref    : Node_Id;
+         Success        : Boolean;
+
+      begin
+         --  Look for the subprogram in the list of primitive operations.
+
+         Elmt := First_Elmt (Primitive_Operations (Obj_Type));
+         while Present (Elmt) loop
+            Prim_Op := Node (Elmt);
+
+            if Chars (Prim_Op) = Chars (Subprog)
+              and then Present (First_Formal (Prim_Op))
+            then
+               Prim_Op_Ref := New_Reference_To (Prim_Op, Loc);
+
+               --  When both the type of the object and the type of the first
+               --  formal of the primitive operation are tagged access types,
+               --  we use a node with the object as first actual.
+
+               if Is_Access_Type (Etype (Obj))
+                 and then Ekind (Etype (First_Formal (Prim_Op))) =
+                            E_Anonymous_Access_Type
+               then
+                  --  Allocate the node only once
+
+                  if not Present (Call_Node_Case) then
+                     Transform_Object_Operation (
+                       Call_Node       => Call_Node_Case,
+                       First_Actual    => Obj,
+                       Node_To_Replace => Dummy,
+                       Subprog         => Subprog);
+
+                     Set_Etype (Call_Node_Case, Any_Type);
+                     Set_Parent (Call_Node_Case, Parent (Node_To_Replace));
+                  end if;
+
+                  Set_Name (Call_Node_Case, Prim_Op_Ref);
+
+                  Analyze_One_Call (
+                    N       => Call_Node_Case,
+                    Nam     => Prim_Op,
+                    Report  => False,
+                    Success => Success);
+
+                  if Success then
+                     Complete_Object_Operation (
+                       Call_Node       => Call_Node_Case,
+                       Node_To_Replace => Node_To_Replace,
+                       Subprog         => Prim_Op_Ref);
+
+                     return True;
+                  end if;
+
+               --  Comment required ???
+
+               else
+                  Set_Name (Call_Node, Prim_Op_Ref);
+
+                  Analyze_One_Call (
+                    N       => Call_Node,
+                    Nam     => Prim_Op,
+                    Report  => False,
+                    Success => Success);
+
+                  if Success then
+                     Complete_Object_Operation (
+                       Call_Node       => Call_Node,
+                       Node_To_Replace => Node_To_Replace,
+                       Subprog         => Prim_Op_Ref);
+
+                     return True;
+                  end if;
+               end if;
+            end if;
+
+            Next_Elmt (Elmt);
+         end loop;
+
+         return False;
+      end Try_Primitive_Operation;
+
+   --  Start of processing for Try_Object_Operation
+
+   begin
+      if Is_Access_Type (Obj_Type) then
+         Obj_Type := Designated_Type (Obj_Type);
+      end if;
+
+      if Ekind (Obj_Type) = E_Private_Subtype then
+         Obj_Type := Base_Type (Obj_Type);
+      end if;
+
+      if Is_Class_Wide_Type (Obj_Type) then
+         Obj_Type := Etype (Class_Wide_Type (Obj_Type));
+      end if;
+
+      Analyze_Actuals;
+
+      --  If the object is of an Access type, explicit dereference is
+      --  required.
+
+      if Is_Access_Type (Etype (Obj)) then
+         First_Actual :=
+           Make_Explicit_Dereference (Sloc (Obj), Obj);
+         Set_Etype (First_Actual, Obj_Type);
+      else
+         First_Actual := Obj;
+      end if;
+
+      --  Build a subprogram call node
+
+      Transform_Object_Operation (
+        Call_Node       => Call_Node,
+        First_Actual    => First_Actual,
+        Node_To_Replace => Node_To_Replace,
+        Subprog         => Subprog);
+
+      Set_Etype (Call_Node, Any_Type);
+      Set_Parent (Call_Node, Parent (Node_To_Replace));
+
+      return
+         Try_Primitive_Operation
+           (Call_Node       => Call_Node,
+            Node_To_Replace => Node_To_Replace)
+        or else
+         Try_Class_Wide_Operation
+           (Call_Node       => Call_Node,
+            Node_To_Replace => Node_To_Replace);
+   end Try_Object_Operation;
+
 end Sem_Ch4;