From patchwork Tue Apr 25 08:56:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 754646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wBxsv37H4z9s7x for ; Tue, 25 Apr 2017 18:57:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="l+b4OOkI"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=SMGryVJiySGXUrh+hgI/ymQSdrlTlB0LVhL3rn2y+1Ta9JHVAG b8AHXP9xRncK3FVNg93fpgoA7AHtLPoDc/L2sOmEAeT94g9Ud43OzeT6d/AhZ1CE 0Z+uuf+HLyFOHDdkqN/h8tlqEMwAQ19bEEroQYnC/RpdM9o5dehaVhiNw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=6IN8YjmSEVd/gmXfFXC2q3bpGbM=; b=l+b4OOkIAPJLB1KHoYko lVJzw1iVG9DTQZvS+R1qXdhUgru69maBuDg59r1xWau0XDuO2U9j3gGZLwFlLt6y OyXFOEcH2igTK6JDyE0y9LxtIwj0MDbB+gI7wj5Bgzbv+0XjFW+9JHk166T9O9CG Qsa9AvN6AOnJ8VJ7fhFGBqU= Received: (qmail 33073 invoked by alias); 25 Apr 2017 08:56:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 33032 invoked by uid 89); 25 Apr 2017 08:56:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, T_FILL_THIS_FORM_SHORT autolearn=ham version=3.3.2 spammy= X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 08:56:54 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id D6C0F3536; Tue, 25 Apr 2017 04:56:54 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id XMf6VGs0xzZC; Tue, 25 Apr 2017 04:56:54 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [205.232.38.10]) by rock.gnat.com (Postfix) with ESMTP id C62A1350D; Tue, 25 Apr 2017 04:56:54 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id BF35D521; Tue, 25 Apr 2017 04:56:54 -0400 (EDT) Date: Tue, 25 Apr 2017 04:56:54 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Bob Duff Subject: [Ada] Remove uses of global variables from Sem_Prag Message-ID: <20170425085654.GA47355@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch cleans up some uses of global variables in Sem_Prag. No change in behavior; no test available. Tested on x86_64-pc-linux-gnu, committed on trunk 2017-04-25 Bob Duff * sem_prag.adb: Remove suspicious uses of Name_Buf. * stringt.ads, stringt.adb, exp_dbug.adb, sem_dim.adb: Remove Add_String_To_Name_Buffer, to avoid using the global Name_Buf. Add String_To_Name with no side effects. Index: sem_dim.adb =================================================================== --- sem_dim.adb (revision 247135) +++ sem_dim.adb (working copy) @@ -2521,8 +2521,9 @@ Add_Str_To_Name_Buffer ("has dimension "); end if; - Add_String_To_Name_Buffer - (From_Dim_To_Str_Of_Dim_Symbols (Dims_Of_N, System, True)); + Append + (Global_Name_Buffer, + From_Dim_To_Str_Of_Dim_Symbols (Dims_Of_N, System, True)); -- N is dimensionless @@ -2562,12 +2563,12 @@ Name_Len := 0; - Add_String_To_Name_Buffer (String_From_Numeric_Literal (N)); + Append (Global_Name_Buffer, String_From_Numeric_Literal (N)); -- Insert a blank between the literal and the symbol Add_Str_To_Name_Buffer (" "); - Add_String_To_Name_Buffer (Symbol_Of (Typ)); + Append (Global_Name_Buffer, Symbol_Of (Typ)); Error_Msg_Name_1 := Name_Find; Error_Msg_N ("assumed to be%%??", N); Index: stringt.adb =================================================================== --- stringt.adb (revision 247135) +++ stringt.adb (working copy) @@ -75,15 +75,10 @@ -- Release to get a snapshot of the tables and to restore them to their -- previous situation. - ------------------------------- - -- Add_String_To_Name_Buffer -- - ------------------------------- + ------------ + -- Append -- + ------------ - procedure Add_String_To_Name_Buffer (S : String_Id) is - begin - Append (Global_Name_Buffer, S); - end Add_String_To_Name_Buffer; - procedure Append (Buf : in out Bounded_String; S : String_Id) is begin for X in 1 .. String_Length (S) loop @@ -324,6 +319,17 @@ return Strings.Table (Id).Length; end String_Length; + -------------------- + -- String_To_Name -- + -------------------- + + function String_To_Name (S : String_Id) return Name_Id is + Buf : Bounded_String; + begin + Append (Buf, S); + return Name_Find (Buf); + end String_To_Name; + --------------------------- -- String_To_Name_Buffer -- --------------------------- Index: stringt.ads =================================================================== --- stringt.ads (revision 247135) +++ stringt.ads (working copy) @@ -47,9 +47,9 @@ -- is implemented in the scanner. -- There is no guarantee that hashing is used in the implementation, although --- it maybe. This means that the caller cannot count on having the same Id +-- it may be. This means that the caller cannot count on having the same Id -- value for two identical strings stored separately and also cannot count on --- the two Id values being different. +-- the two such Id values being different. Null_String_Id : String_Id; -- Gets set to a null string with length zero @@ -119,18 +119,18 @@ function String_Equal (L, R : String_Id) return Boolean; -- Determines if two string literals represent the same string - procedure String_To_Name_Buffer (S : String_Id); - -- Place characters of given string in Name_Buffer, setting Name_Len. - -- Error if any characters are out of Character range. Does not attempt - -- to do any encoding of any characters. + function String_To_Name (S : String_Id) return Name_Id; + -- Convert String_Id to Name_Id procedure Append (Buf : in out Bounded_String; S : String_Id); -- Append characters of given string to Buf. Error if any characters are - -- out of Character range. Does not attempt to do any encoding of any + -- out of Character range. Does not attempt to do any encoding of -- characters. - procedure Add_String_To_Name_Buffer (S : String_Id); - -- Same as Append (Global_Name_Buffer, S) + procedure String_To_Name_Buffer (S : String_Id); + -- Place characters of given string in Name_Buffer, setting Name_Len. + -- Error if any characters are out of Character range. Does not attempt + -- to do any encoding of any characters. function String_Chars_Address return System.Address; -- Return address of String_Chars table (used by Back_End call to Gigi) Index: sem_prag.adb =================================================================== --- sem_prag.adb (revision 247148) +++ sem_prag.adb (working copy) @@ -5941,9 +5941,7 @@ procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is begin - Name_Buffer (1 .. Id'Length) := Id; - Name_Len := Id'Length; - Check_Optional_Identifier (Arg, Name_Find); + Check_Optional_Identifier (Arg, Name_Find (Id)); end Check_Optional_Identifier; ------------------------------------- @@ -8300,8 +8298,7 @@ Nam : Name_Id; begin - String_To_Name_Buffer (Strval (Expression (Arg3))); - Nam := Name_Find; + Nam := String_To_Name (Strval (Expression (Arg3))); Elmt := First_Elmt (Predefined_Float_Types); while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop @@ -9223,8 +9220,7 @@ begin if Prag_Id = Pragma_Import then - String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam))); - Nam := Name_Find; + Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam))); E := Entity_Id (Get_Name_Table_Int (Nam)); if Nam /= Chars (Subprogram_Def) @@ -10273,32 +10269,18 @@ -- No_Dependence => Ada.Execution_Time.Group_Budget -- No_Dependence => Ada.Execution_Time.Timers - -- ??? The use of Name_Buffer here is suspicious. The names should - -- be registered in snames.ads-tmpl and used to build the qualified - -- names of units. - if Ada_Version >= Ada_2005 then - Name_Buffer (1 .. 3) := "ada"; - Name_Len := 3; + Pref_Id := Make_Identifier (Loc, Name_Find ("ada")); + Sel_Id := Make_Identifier (Loc, Name_Find ("execution_time")); - Pref_Id := Make_Identifier (Loc, Name_Find); - - Name_Buffer (1 .. 14) := "execution_time"; - Name_Len := 14; - - Sel_Id := Make_Identifier (Loc, Name_Find); - Pref := Make_Selected_Component (Sloc => Loc, Prefix => Pref_Id, Selector_Name => Sel_Id); - Name_Buffer (1 .. 13) := "group_budgets"; - Name_Len := 13; + Sel_Id := Make_Identifier (Loc, Name_Find ("group_budgets")); - Sel_Id := Make_Identifier (Loc, Name_Find); - Nod := Make_Selected_Component (Sloc => Loc, @@ -10310,11 +10292,8 @@ Warn => Treat_Restrictions_As_Warnings, Profile => Ravenscar); - Name_Buffer (1 .. 6) := "timers"; - Name_Len := 6; + Sel_Id := Make_Identifier (Loc, Name_Find ("timers")); - Sel_Id := Make_Identifier (Loc, Name_Find); - Nod := Make_Selected_Component (Sloc => Loc, @@ -10332,27 +10311,17 @@ -- No_Dependence => System.Multiprocessors.Dispatching_Domains if Ada_Version >= Ada_2012 then - Name_Buffer (1 .. 6) := "system"; - Name_Len := 6; + Pref_Id := Make_Identifier (Loc, Name_Find ("system")); + Sel_Id := Make_Identifier (Loc, Name_Find ("multiprocessors")); - Pref_Id := Make_Identifier (Loc, Name_Find); - - Name_Buffer (1 .. 15) := "multiprocessors"; - Name_Len := 15; - - Sel_Id := Make_Identifier (Loc, Name_Find); - Pref := Make_Selected_Component (Sloc => Loc, Prefix => Pref_Id, Selector_Name => Sel_Id); - Name_Buffer (1 .. 19) := "dispatching_domains"; - Name_Len := 19; + Sel_Id := Make_Identifier (Loc, Name_Find ("dispatching_domains")); - Sel_Id := Make_Identifier (Loc, Name_Find); - Nod := Make_Selected_Component (Sloc => Loc, Index: exp_dbug.adb =================================================================== --- exp_dbug.adb (revision 247135) +++ exp_dbug.adb (working copy) @@ -800,7 +800,7 @@ and then No (Address_Clause (E)) and then not Has_Suffix then - Add_String_To_Name_Buffer (Strval (Interface_Name (E))); + Append (Global_Name_Buffer, Strval (Interface_Name (E))); -- All other cases besides the interface name case