sinput.ads, sinput.adb (Build_Location_String): Take a parameter instead of using...
authorBob Duff <duff@adacore.com>
Mon, 18 Apr 2016 10:48:33 +0000 (10:48 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 18 Apr 2016 10:48:33 +0000 (12:48 +0200)
2016-04-18  Bob Duff  <duff@adacore.com>

* sinput.ads, sinput.adb (Build_Location_String): Take a
parameter instead of using a global variable.  The function
version no longer destroys the Name_Buffer.
* stringt.ads, stringt.adb (String_From_Name_Buffer): Take a
parameter, which defaults to the Global_Name_Buffer, so some
calls can avoid the global.
* exp_ch11.adb, exp_intr.adb: Use new interfaces above
to avoid using globals. All but one call to Build_Location_String
avoids the global. Only one call to String_From_Name_Buffer
avoids it.

From-SVN: r235126

gcc/ada/ChangeLog
gcc/ada/exp_ch11.adb
gcc/ada/exp_intr.adb
gcc/ada/sinput.adb
gcc/ada/sinput.ads
gcc/ada/stringt.adb
gcc/ada/stringt.ads

index 143a6a10309eef12989a197e6ae0a3bcadf310f9..1fc22a7e12ab51f3cab776f163d92a6d20abb60d 100644 (file)
@@ -1,3 +1,16 @@
+2016-04-18  Bob Duff  <duff@adacore.com>
+
+       * sinput.ads, sinput.adb (Build_Location_String): Take a
+       parameter instead of using a global variable.  The function
+       version no longer destroys the Name_Buffer.
+       * stringt.ads, stringt.adb (String_From_Name_Buffer): Take a
+       parameter, which defaults to the Global_Name_Buffer, so some
+       calls can avoid the global.
+       * exp_ch11.adb, exp_intr.adb: Use new interfaces above
+       to avoid using globals. All but one call to Build_Location_String
+       avoids the global. Only one call to String_From_Name_Buffer
+       avoids it.
+
 2016-04-18  Hristian Kirtchev  <kirtchev@adacore.com>
 
        * namet.adb, namet.ads, exp_unst.adb: Minor reformatting.
index 89dd350ffbacc21f46d4f9b931053c804515cc9e..653007c63c60d0b6ec857948fac3fed1953b8567 100644 (file)
@@ -1658,10 +1658,10 @@ package body Exp_Ch11 is
       if Present (Name (N)) then
          declare
             Id : Entity_Id := Entity (Name (N));
+            Buf : Bounded_String;
 
          begin
-            Name_Len := 0;
-            Build_Location_String (Loc);
+            Build_Location_String (Buf, Loc);
 
             --  If the exception is a renaming, use the exception that it
             --  renames (which might be a predefined exception, e.g.).
@@ -1679,19 +1679,17 @@ package body Exp_Ch11 is
                --  Suppress_Exception_Locations is set for this unit.
 
                if Opt.Exception_Locations_Suppressed then
-                  Name_Len := 1;
-               else
-                  Name_Len := Name_Len + 1;
+                  Buf.Length := 0;
                end if;
 
-               Name_Buffer (Name_Len) := ASCII.NUL;
+               Append (Buf, ASCII.NUL);
             end if;
 
             if Opt.Exception_Locations_Suppressed then
-               Name_Len := 0;
+               Buf.Length := 0;
             end if;
 
-            Str := String_From_Name_Buffer;
+            Str := String_From_Name_Buffer (Buf);
 
             --  Convert raise to call to the Raise_Exception routine
 
index f0307821c0826b84ea9380811b0a27e60907cbed..8b2d1f2bdb7b7807ec929218c9040e6d2b47f1b6 100644 (file)
@@ -145,7 +145,7 @@ package body Exp_Intr is
               (Reference_Name (Get_Source_File_Index (Loc)));
 
          when Name_Source_Location =>
-            Build_Location_String (Loc);
+            Build_Location_String (Global_Name_Buffer, Loc);
 
          when Name_Enclosing_Entity =>
 
index 1c8232d1c83aa87654f71d519e99962ab49e36a7..0800f3196a68b6d0d1f2938d74bdff8821011de0 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2014, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2015, 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- --
@@ -221,33 +221,31 @@ package body Sinput is
    -- Build_Location_String --
    ---------------------------
 
-   procedure Build_Location_String (Loc : Source_Ptr) is
-      Ptr : Source_Ptr;
+   procedure Build_Location_String
+     (Buf : in out Bounded_String;
+      Loc : Source_Ptr)
+   is
+      Ptr : Source_Ptr := Loc;
 
    begin
       --  Loop through instantiations
 
-      Ptr := Loc;
       loop
-         Get_Name_String_And_Append
-           (Reference_Name (Get_Source_File_Index (Ptr)));
-         Add_Char_To_Name_Buffer (':');
-         Add_Nat_To_Name_Buffer (Nat (Get_Logical_Line_Number (Ptr)));
+         Append (Buf, Reference_Name (Get_Source_File_Index (Ptr)));
+         Append (Buf, ':');
+         Append (Buf, Nat (Get_Logical_Line_Number (Ptr)));
 
          Ptr := Instantiation_Location (Ptr);
          exit when Ptr = No_Location;
-         Add_Str_To_Name_Buffer (" instantiated at ");
+         Append (Buf, " instantiated at ");
       end loop;
-
-      Name_Buffer (Name_Len + 1) := NUL;
-      return;
    end Build_Location_String;
 
    function Build_Location_String (Loc : Source_Ptr) return String is
+      Buf : Bounded_String;
    begin
-      Name_Len := 0;
-      Build_Location_String (Loc);
-      return Name_Buffer (1 .. Name_Len);
+      Build_Location_String (Buf, Loc);
+      return +Buf;
    end Build_Location_String;
 
    -------------------
index f1a27245afc599666c53274cd72e1689b3b0b50c..18bc1b1efdb110864987350155cdbe09a50f5076 100644 (file)
@@ -536,18 +536,17 @@ package Sinput is
    --  The caller has checked that a Line_Terminator character precedes P so
    --  that there definitely is a previous line in the source buffer.
 
-   procedure Build_Location_String (Loc : Source_Ptr);
+   procedure Build_Location_String
+     (Buf : in out Bounded_String;
+      Loc : Source_Ptr);
    --  This function builds a string literal of the form "name:line", where
    --  name is the file name corresponding to Loc, and line is the line number.
-   --  In the event that instantiations are involved, additional suffixes of
-   --  the same form are appended after the separating string " instantiated at
-   --  ". The returned string is appended to the Name_Buffer, terminated by
-   --  ASCII.NUL, with Name_Length indicating the length not including the
-   --  terminating Nul.
+   --  If instantiations are involved, additional suffixes of the same form are
+   --  appended after the separating string " instantiated at ". The returned
+   --  string is appended to Buf.
 
    function Build_Location_String (Loc : Source_Ptr) return String;
-   --  Functional form returning a string, which does not include a terminating
-   --  null character. The contents of Name_Buffer is destroyed.
+   --  Functional form returning a String
 
    procedure Check_For_BOM;
    --  Check if the current source starts with a BOM. Scan_Ptr needs to be at
index 5a0c89c7d04f5bd80eb71dae9f3d6711ca0ab597..b4d85629908a8a279b45afc1b1c5cf0f1c4fc95c 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2013, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2015, 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- --
@@ -30,7 +30,6 @@
 ------------------------------------------------------------------------------
 
 with Alloc;
-with Namet;  use Namet;
 with Output; use Output;
 with Table;
 
@@ -307,14 +306,11 @@ package body Stringt is
    -- String_From_Name_Buffer --
    -----------------------------
 
-   function String_From_Name_Buffer return String_Id is
+   function String_From_Name_Buffer
+     (Buf : Bounded_String := Global_Name_Buffer) return String_Id is
    begin
       Start_String;
-
-      for J in 1 .. Name_Len loop
-         Store_String_Char (Get_Char_Code (Name_Buffer (J)));
-      end loop;
-
+      Store_String_Chars (+Buf);
       return End_String;
    end String_From_Name_Buffer;
 
index 92b74e2c049e7e46a2afbff3895aad7dcb9c1f78..c48f2b9def863914693ae6339d2c19fa7e6191d7 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2013, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2015, 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- --
@@ -29,6 +29,7 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
+with Namet;  use Namet;
 with System; use System;
 with Types;  use Types;
 
@@ -131,10 +132,9 @@ package Stringt is
    function String_Chars_Address return System.Address;
    --  Return address of String_Chars table (used by Back_End call to Gigi)
 
-   function String_From_Name_Buffer return String_Id;
-   --  Given a name stored in Namet.Name_Buffer (length in Namet.Name_Len),
-   --  returns a string of the corresponding value. The value in Name_Buffer
-   --  is unchanged, and the cases of letters are unchanged.
+   function String_From_Name_Buffer
+     (Buf : Bounded_String := Global_Name_Buffer) return String_Id;
+   --  Given a name stored in Buf, returns a string of the corresponding value.
 
    function Strings_Address return System.Address;
    --  Return address of Strings table (used by Back_End call to Gigi)