[Ada] Remove duplicated routines for getting homonym number
diff mbox series

Message ID 20190919132819.GA41744@adacore.com
State New
Headers show
Series
  • [Ada] Remove duplicated routines for getting homonym number
Related show

Commit Message

Pierre-Marie de Rodat Sept. 19, 2019, 1:28 p.m. UTC
Routines Homonym_Number and Get_Homonym_Number were exactly the same,
except for minor style differences. Keep the one in Exp_Util; remove the
one in Exp_Dbug. No test attached, because semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-09-19  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* exp_dbug.ads, exp_dbug.adb (Get_Homonym_Number): Remove.
	(Append_Homonym_Number): Use Homonym_Number instead of
	Get_Homonym_Number.
	* exp_util.ads, exp_util.adb (Homonym_Number): Mirror style of
	the removed Get_Homonym_Number routine, i.e. initialize local
	objects at declaration and refine the type of result.
	* sem_util.adb (Add_Homonym_Suffix): Use Homonym_Number instead
	of Get_Homonym_Number.

Patch
diff mbox series

--- gcc/ada/exp_dbug.adb
+++ gcc/ada/exp_dbug.adb
@@ -27,6 +27,7 @@  with Alloc;
 with Atree;    use Atree;
 with Debug;    use Debug;
 with Einfo;    use Einfo;
+with Exp_Util; use Exp_Util;
 with Nlists;   use Nlists;
 with Nmake;    use Nmake;
 with Opt;      use Opt;
@@ -224,7 +225,7 @@  package body Exp_Dbug is
             Homonym_Numbers (Homonym_Len) := '_';
          end if;
 
-         Add_Nat_To_H (Get_Homonym_Number (E));
+         Add_Nat_To_H (Homonym_Number (E));
       end if;
    end Append_Homonym_Number;
 
@@ -1054,26 +1055,6 @@  package body Exp_Dbug is
       end loop;
    end Build_Subprogram_Instance_Renamings;
 
-   ------------------------
-   -- Get_Homonym_Number --
-   ------------------------
-
-   function Get_Homonym_Number (E : Entity_Id) return Pos is
-      H  : Entity_Id := Homonym (E);
-      Nr : Pos := 1;
-
-   begin
-      while Present (H) loop
-         if Scope (H) = Scope (E) then
-            Nr := Nr + 1;
-         end if;
-
-         H := Homonym (H);
-      end loop;
-
-      return Nr;
-   end Get_Homonym_Number;
-
    ------------------------------------
    -- Get_Secondary_DT_External_Name --
    ------------------------------------

--- gcc/ada/exp_dbug.ads
+++ gcc/ada/exp_dbug.ads
@@ -460,10 +460,6 @@  package Exp_Dbug is
    -- Subprograms for Handling Qualification --
    --------------------------------------------
 
-   function Get_Homonym_Number (E : Entity_Id) return Pos;
-   --  Return the homonym number for E, which is its position in the homonym
-   --  chain starting at 1. This is exported for use in GNATprove.
-
    procedure Qualify_Entity_Names (N : Node_Id);
    --  Given a node N, that represents a block, subprogram body, or package
    --  body or spec, or protected or task type, sets a fully qualified name

--- gcc/ada/exp_util.adb
+++ gcc/ada/exp_util.adb
@@ -6795,13 +6795,11 @@  package body Exp_Util is
    -- Homonym_Number --
    --------------------
 
-   function Homonym_Number (Subp : Entity_Id) return Nat is
-      Count : Nat;
-      Hom   : Entity_Id;
+   function Homonym_Number (Subp : Entity_Id) return Pos is
+      Hom   : Entity_Id := Homonym (Subp);
+      Count : Pos := 1;
 
    begin
-      Count := 1;
-      Hom := Homonym (Subp);
       while Present (Hom) loop
          if Scope (Hom) = Scope (Subp) then
             Count := Count + 1;

--- gcc/ada/exp_util.ads
+++ gcc/ada/exp_util.ads
@@ -734,7 +734,7 @@  package Exp_Util is
    --  pragmas at the start of the package declaration contains
    --    pragma Annotate (GNATprove, External_Axiomatization);
 
-   function Homonym_Number (Subp : Entity_Id) return Nat;
+   function Homonym_Number (Subp : Entity_Id) return Pos;
    --  Here subp is the entity for a subprogram. This routine returns the
    --  homonym number used to disambiguate overloaded subprograms in the same
    --  scope (the number is used as part of constructed names to make sure that

--- gcc/ada/sem_util.adb
+++ gcc/ada/sem_util.adb
@@ -33,7 +33,6 @@  with Elists;   use Elists;
 with Errout;   use Errout;
 with Erroutc;  use Erroutc;
 with Exp_Ch11; use Exp_Ch11;
-with Exp_Dbug; use Exp_Dbug;
 with Exp_Util; use Exp_Util;
 with Fname;    use Fname;
 with Freeze;   use Freeze;
@@ -26314,7 +26313,7 @@  package body Sem_Util is
 
          if Has_Homonym (U) then
             declare
-               N : constant Pos := Get_Homonym_Number (U);
+               N : constant Pos := Homonym_Number (U);
                S : constant String := N'Img;
             begin
                if N > 1 then