Commit ea102799 by Bob Duff Committed by Arnaud Charlet

sinput.ads, sinput.adb (Build_Location_String): Take a parameter instead of…

sinput.ads, sinput.adb (Build_Location_String): Take a parameter instead of using a global variable.

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
parent bd717ec9
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> 2016-04-18 Hristian Kirtchev <kirtchev@adacore.com>
* namet.adb, namet.ads, exp_unst.adb: Minor reformatting. * namet.adb, namet.ads, exp_unst.adb: Minor reformatting.
......
...@@ -1658,10 +1658,10 @@ package body Exp_Ch11 is ...@@ -1658,10 +1658,10 @@ package body Exp_Ch11 is
if Present (Name (N)) then if Present (Name (N)) then
declare declare
Id : Entity_Id := Entity (Name (N)); Id : Entity_Id := Entity (Name (N));
Buf : Bounded_String;
begin begin
Name_Len := 0; Build_Location_String (Buf, Loc);
Build_Location_String (Loc);
-- If the exception is a renaming, use the exception that it -- If the exception is a renaming, use the exception that it
-- renames (which might be a predefined exception, e.g.). -- renames (which might be a predefined exception, e.g.).
...@@ -1679,19 +1679,17 @@ package body Exp_Ch11 is ...@@ -1679,19 +1679,17 @@ package body Exp_Ch11 is
-- Suppress_Exception_Locations is set for this unit. -- Suppress_Exception_Locations is set for this unit.
if Opt.Exception_Locations_Suppressed then if Opt.Exception_Locations_Suppressed then
Name_Len := 1; Buf.Length := 0;
else
Name_Len := Name_Len + 1;
end if; end if;
Name_Buffer (Name_Len) := ASCII.NUL; Append (Buf, ASCII.NUL);
end if; end if;
if Opt.Exception_Locations_Suppressed then if Opt.Exception_Locations_Suppressed then
Name_Len := 0; Buf.Length := 0;
end if; end if;
Str := String_From_Name_Buffer; Str := String_From_Name_Buffer (Buf);
-- Convert raise to call to the Raise_Exception routine -- Convert raise to call to the Raise_Exception routine
......
...@@ -145,7 +145,7 @@ package body Exp_Intr is ...@@ -145,7 +145,7 @@ package body Exp_Intr is
(Reference_Name (Get_Source_File_Index (Loc))); (Reference_Name (Get_Source_File_Index (Loc)));
when Name_Source_Location => when Name_Source_Location =>
Build_Location_String (Loc); Build_Location_String (Global_Name_Buffer, Loc);
when Name_Enclosing_Entity => when Name_Enclosing_Entity =>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- 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 -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -221,33 +221,31 @@ package body Sinput is ...@@ -221,33 +221,31 @@ package body Sinput is
-- Build_Location_String -- -- Build_Location_String --
--------------------------- ---------------------------
procedure Build_Location_String (Loc : Source_Ptr) is procedure Build_Location_String
Ptr : Source_Ptr; (Buf : in out Bounded_String;
Loc : Source_Ptr)
is
Ptr : Source_Ptr := Loc;
begin begin
-- Loop through instantiations -- Loop through instantiations
Ptr := Loc;
loop loop
Get_Name_String_And_Append Append (Buf, Reference_Name (Get_Source_File_Index (Ptr)));
(Reference_Name (Get_Source_File_Index (Ptr))); Append (Buf, ':');
Add_Char_To_Name_Buffer (':'); Append (Buf, Nat (Get_Logical_Line_Number (Ptr)));
Add_Nat_To_Name_Buffer (Nat (Get_Logical_Line_Number (Ptr)));
Ptr := Instantiation_Location (Ptr); Ptr := Instantiation_Location (Ptr);
exit when Ptr = No_Location; exit when Ptr = No_Location;
Add_Str_To_Name_Buffer (" instantiated at "); Append (Buf, " instantiated at ");
end loop; end loop;
Name_Buffer (Name_Len + 1) := NUL;
return;
end Build_Location_String; end Build_Location_String;
function Build_Location_String (Loc : Source_Ptr) return String is function Build_Location_String (Loc : Source_Ptr) return String is
Buf : Bounded_String;
begin begin
Name_Len := 0; Build_Location_String (Buf, Loc);
Build_Location_String (Loc); return +Buf;
return Name_Buffer (1 .. Name_Len);
end Build_Location_String; end Build_Location_String;
------------------- -------------------
......
...@@ -536,18 +536,17 @@ package Sinput is ...@@ -536,18 +536,17 @@ package Sinput is
-- The caller has checked that a Line_Terminator character precedes P so -- The caller has checked that a Line_Terminator character precedes P so
-- that there definitely is a previous line in the source buffer. -- 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 -- 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. -- name is the file name corresponding to Loc, and line is the line number.
-- In the event that instantiations are involved, additional suffixes of -- If instantiations are involved, additional suffixes of the same form are
-- the same form are appended after the separating string " instantiated at -- appended after the separating string " instantiated at ". The returned
-- ". The returned string is appended to the Name_Buffer, terminated by -- string is appended to Buf.
-- ASCII.NUL, with Name_Length indicating the length not including the
-- terminating Nul.
function Build_Location_String (Loc : Source_Ptr) return String; function Build_Location_String (Loc : Source_Ptr) return String;
-- Functional form returning a string, which does not include a terminating -- Functional form returning a String
-- null character. The contents of Name_Buffer is destroyed.
procedure Check_For_BOM; procedure Check_For_BOM;
-- Check if the current source starts with a BOM. Scan_Ptr needs to be at -- Check if the current source starts with a BOM. Scan_Ptr needs to be at
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- 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 -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Alloc; with Alloc;
with Namet; use Namet;
with Output; use Output; with Output; use Output;
with Table; with Table;
...@@ -307,14 +306,11 @@ package body Stringt is ...@@ -307,14 +306,11 @@ package body Stringt is
-- String_From_Name_Buffer -- -- 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 begin
Start_String; Start_String;
Store_String_Chars (+Buf);
for J in 1 .. Name_Len loop
Store_String_Char (Get_Char_Code (Name_Buffer (J)));
end loop;
return End_String; return End_String;
end String_From_Name_Buffer; end String_From_Name_Buffer;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- 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 -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
-- -- -- --
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
with Namet; use Namet;
with System; use System; with System; use System;
with Types; use Types; with Types; use Types;
...@@ -131,10 +132,9 @@ package Stringt is ...@@ -131,10 +132,9 @@ package Stringt is
function String_Chars_Address return System.Address; function String_Chars_Address return System.Address;
-- Return address of String_Chars table (used by Back_End call to Gigi) -- Return address of String_Chars table (used by Back_End call to Gigi)
function String_From_Name_Buffer return String_Id; function String_From_Name_Buffer
-- Given a name stored in Namet.Name_Buffer (length in Namet.Name_Len), (Buf : Bounded_String := Global_Name_Buffer) return String_Id;
-- returns a string of the corresponding value. The value in Name_Buffer -- Given a name stored in Buf, returns a string of the corresponding value.
-- is unchanged, and the cases of letters are unchanged.
function Strings_Address return System.Address; function Strings_Address return System.Address;
-- Return address of Strings table (used by Back_End call to Gigi) -- Return address of Strings table (used by Back_End call to Gigi)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment