Patchwork [Ada] Cleanups for Namet.Initialize

login
register
mail settings
Submitter Arnaud Charlet
Date Sept. 9, 2010, 9:44 a.m.
Message ID <20100909094450.GA30840@adacore.com>
Download mbox | patch
Permalink /patch/64269/
State New
Headers show

Comments

Arnaud Charlet - Sept. 9, 2010, 9:44 a.m.
This patch does some cleanups for Namet. Initialize is now a dummy procedure
since package initialization is automatic. This cures the problem of multiple
calls to Initialize clobbering stuff. A new procedure Reinitialize is available
for forcing a reinitialization of the Namet tables.

No test, since no functional effect

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

2010-09-09  Robert Dewar  <dewar@adacore.com>

	* namet.adb (Initialize): Is now a dummy procedure
	(Reinitialize): New procedure
	Call Reinitialize from package initialization
	* namet.ads (Initialize): Is now a dummy procedure
	(Reinitialize): New procedure
	* clean.adb, gnat1drv.adb, gnatbind.adb, gnatcmd.adb, gnatlink.adb,
	gnatls.adb, gprep.adb, make.adb, prj-makr.adb: Remove obsolete call to
	Namet.Initialize.

Patch

Index: clean.adb
===================================================================
--- clean.adb	(revision 164000)
+++ clean.adb	(working copy)
@@ -1556,7 +1556,6 @@  package body Clean is
          --  Initialize some packages
 
          Csets.Initialize;
-         Namet.Initialize;
          Snames.Initialize;
 
          Project_Node_Tree := new Project_Node_Tree_Data;
Index: gnat1drv.adb
===================================================================
--- gnat1drv.adb	(revision 164000)
+++ gnat1drv.adb	(working copy)
@@ -610,7 +610,6 @@  begin
       Uintp.Initialize;
       Urealp.Initialize;
       Errout.Initialize;
-      Namet.Initialize;
       SCOs.Initialize;
       Snames.Initialize;
       Stringt.Initialize;
Index: gnatbind.adb
===================================================================
--- gnatbind.adb	(revision 164000)
+++ gnatbind.adb	(working copy)
@@ -583,13 +583,11 @@  begin
    Osint.Add_Default_Search_Dirs;
 
    --  Carry out package initializations. These are initializations which
-   --  might logically be performed at elaboration time, but Namet at least
-   --  can't be done that way (because it is used in the Compiler), and we
-   --  decide to be consistent. Like elaboration, the order in which these
-   --  calls are made is in some cases important.
+   --  might logically be performed at elaboration time, and we decide to be
+   --  consistent. Like elaboration, the order in which these calls are made
+   --  is in some cases important.
 
    Csets.Initialize;
-   Namet.Initialize;
    Snames.Initialize;
 
    --  Acquire target parameters
Index: gnatcmd.adb
===================================================================
--- gnatcmd.adb	(revision 164000)
+++ gnatcmd.adb	(working copy)
@@ -1320,9 +1320,7 @@  procedure GNATCmd is
 begin
    --  Initializations
 
-   Namet.Initialize;
    Csets.Initialize;
-
    Snames.Initialize;
 
    Project_Node_Tree := new Project_Node_Tree_Data;
Index: gnatlink.adb
===================================================================
--- gnatlink.adb	(revision 164000)
+++ gnatlink.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1996-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1996-2010, 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- --
@@ -1537,7 +1537,6 @@  begin
 
    --  Initialize packages to be used
 
-   Namet.Initialize;
    Csets.Initialize;
    Snames.Initialize;
 
@@ -1561,7 +1560,6 @@  begin
    --  the binder generated file
 
    if Compile_Bind_File and then Standard_Gcc then
-
       Initialize_ALI;
       Name_Len := Ali_File_Name'Length;
       Name_Buffer (1 .. Name_Len) := Ali_File_Name.all;
Index: gnatls.adb
===================================================================
--- gnatls.adb	(revision 164000)
+++ gnatls.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2010, 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- --
@@ -1524,7 +1524,6 @@  procedure Gnatls is
 begin
    --  Initialize standard packages
 
-   Namet.Initialize;
    Csets.Initialize;
    Snames.Initialize;
 
Index: gprep.adb
===================================================================
--- gprep.adb	(revision 164000)
+++ gprep.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2002-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 2002-2010, 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- --
@@ -172,7 +172,6 @@  package body GPrep is
       --  Do some initializations (order is important here!)
 
       Csets.Initialize;
-      Namet.Initialize;
       Snames.Initialize;
       Stringt.Initialize;
       Prep.Initialize;
Index: make.adb
===================================================================
--- make.adb	(revision 164000)
+++ make.adb	(working copy)
@@ -6725,7 +6725,7 @@  package body Make is
 
       Check_Object_Consistency := True;
 
-      --  Package initializations. The order of calls is important here
+      --  Package initializations (the order of calls is important here)
 
       Output.Set_Standard_Error;
 
@@ -6734,8 +6734,6 @@  package body Make is
       Linker_Switches.Init;
 
       Csets.Initialize;
-      Namet.Initialize;
-
       Snames.Initialize;
 
       Prj.Initialize (Project_Tree);
Index: namet.adb
===================================================================
--- namet.adb	(revision 164000)
+++ namet.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2010, 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- --
@@ -864,29 +864,7 @@  package body Namet is
 
    procedure Initialize is
    begin
-      Name_Chars.Init;
-      Name_Entries.Init;
-
-      --  Initialize entries for one character names
-
-      for C in Character loop
-         Name_Entries.Append
-           ((Name_Chars_Index      => Name_Chars.Last,
-             Name_Len              => 1,
-             Byte_Info             => 0,
-             Int_Info              => 0,
-             Name_Has_No_Encodings => True,
-             Hash_Link             => No_Name));
-
-         Name_Chars.Append (C);
-         Name_Chars.Append (ASCII.NUL);
-      end loop;
-
-      --  Clear hash table
-
-      for J in Hash_Index_Type loop
-         Hash_Table (J) := No_Name;
-      end loop;
+      null;
    end Initialize;
 
    ----------------------
@@ -1133,6 +1111,37 @@  package body Namet is
       end if;
    end Name_Find;
 
+   ------------------
+   -- Reinitialize --
+   ------------------
+
+   procedure Reinitialize is
+   begin
+      Name_Chars.Init;
+      Name_Entries.Init;
+
+      --  Initialize entries for one character names
+
+      for C in Character loop
+         Name_Entries.Append
+           ((Name_Chars_Index      => Name_Chars.Last,
+             Name_Len              => 1,
+             Byte_Info             => 0,
+             Int_Info              => 0,
+             Name_Has_No_Encodings => True,
+             Hash_Link             => No_Name));
+
+         Name_Chars.Append (C);
+         Name_Chars.Append (ASCII.NUL);
+      end loop;
+
+      --  Clear hash table
+
+      for J in Hash_Index_Type loop
+         Hash_Table (J) := No_Name;
+      end loop;
+   end Reinitialize;
+
    ----------------------
    -- Reset_Name_Table --
    ----------------------
@@ -1399,4 +1408,8 @@  package body Namet is
       end if;
    end Write_Name_Decoded;
 
+--  Package initialization, initialize tables
+
+begin
+   Reinitialize;
 end Namet;
Index: namet.ads
===================================================================
--- namet.ads	(revision 164000)
+++ namet.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2010, 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- --
@@ -239,14 +239,20 @@  package Namet is
    --  is, it starts with an upper case O).
 
    procedure Initialize;
-   --  Initializes the names table, including initializing the first 26
-   --  entries in the table (for the 1-character lower case names a-z) Note
-   --  that Initialize must not be called if Tree_Read is used.
+   --  This is a dummy procedure. It is retained for easy compatibility with
+   --  clients who used to call Initialize when this call was required. Now
+   --  initialization is performed automatically during package elaboration.
+   --  Note that this change fixes problems which existed prior to the change
+   --  of Initialize being called more than once. See also Reinitialize which
+   --  allows reinitialiation of the tables.
 
    procedure Lock;
    --  Lock name tables before calling back end. We reserve some extra space
    --  before locking to avoid unnecessary inefficiencies when we unlock.
 
+   procedure Reinitialize;
+   --  Clears the name tables and removes all existing entries from the table.
+
    procedure Unlock;
    --  Unlocks the name table to allow use of the extra space reserved by the
    --  call to Lock. See gnat1drv for details of the need for this.
Index: prj-makr.adb
===================================================================
--- prj-makr.adb	(revision 164000)
+++ prj-makr.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2009, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2010, 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- --
@@ -792,7 +792,6 @@  package body Prj.Makr is
       --  Do some needed initializations
 
       Csets.Initialize;
-      Namet.Initialize;
       Snames.Initialize;
       Prj.Initialize (No_Project_Tree);
       Prj.Tree.Initialize (Tree);