OSDN Git Service

2007-04-20 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / elists.adb
index e3a6098..243b184 100644 (file)
@@ -6,8 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                                                                          --
---          Copyright (C) 1992-2001 Free Software Foundation, Inc.          --
+--          Copyright (C) 1992-2007, 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- --
@@ -17,8 +16,8 @@
 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
 -- for  more details.  You should have  received  a copy of the GNU General --
 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, USA.                                                      --
+-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
+-- Boston, MA 02110-1301, USA.                                              --
 --                                                                          --
 -- As a special exception,  if other files  instantiate  generics from this --
 -- unit, or you link  this unit with other files  to produce an executable, --
@@ -80,9 +79,9 @@ package body Elists is
    --  is the last item in the list. The Node field points to the node which
    --  is referenced by the corresponding list entry.
 
-   --------------------------
-   --  Element List Tables --
-   --------------------------
+   -------------------------
+   -- Element List Tables --
+   -------------------------
 
    type Elist_Header is record
       First : Elmt_Id;
@@ -91,20 +90,20 @@ package body Elists is
 
    package Elists is new Table.Table (
      Table_Component_Type => Elist_Header,
-     Table_Index_Type     => Elist_Id,
+     Table_Index_Type     => Elist_Id'Base,
      Table_Low_Bound      => First_Elist_Id,
      Table_Initial        => Alloc.Elists_Initial,
      Table_Increment      => Alloc.Elists_Increment,
      Table_Name           => "Elists");
 
    type Elmt_Item is record
-      Node : Node_Id;
+      Node : Node_Or_Entity_Id;
       Next : Union_Id;
    end record;
 
    package Elmts is new Table.Table (
      Table_Component_Type => Elmt_Item,
-     Table_Index_Type     => Elmt_Id,
+     Table_Index_Type     => Elmt_Id'Base,
      Table_Low_Bound      => First_Elmt_Id,
      Table_Initial        => Alloc.Elmts_Initial,
      Table_Increment      => Alloc.Elmts_Increment,
@@ -114,12 +113,12 @@ package body Elists is
    -- Append_Elmt --
    -----------------
 
-   procedure Append_Elmt (Node : Node_Id; To : Elist_Id) is
+   procedure Append_Elmt (N : Node_Or_Entity_Id; To : Elist_Id) is
       L : constant Elmt_Id := Elists.Table (To).Last;
 
    begin
       Elmts.Increment_Last;
-      Elmts.Table (Elmts.Last).Node := Node;
+      Elmts.Table (Elmts.Last).Node := N;
       Elmts.Table (Elmts.Last).Next := Union_Id (To);
 
       if L = No_Elmt then
@@ -135,12 +134,32 @@ package body Elists is
          Write_Int (Int (Elmts.Last));
          Write_Str (" to list Elist_Id = ");
          Write_Int (Int (To));
-         Write_Str (" referencing Node_Id = ");
-         Write_Int (Int (Node));
+         Write_Str (" referencing Node_Or_Entity_Id = ");
+         Write_Int (Int (N));
          Write_Eol;
       end if;
    end Append_Elmt;
 
+   ------------------------
+   -- Append_Unique_Elmt --
+   ------------------------
+
+   procedure Append_Unique_Elmt (N : Node_Or_Entity_Id; To : Elist_Id) is
+      Elmt : Elmt_Id;
+   begin
+      Elmt := First_Elmt (To);
+      loop
+         if No (Elmt) then
+            Append_Elmt (N, To);
+            return;
+         elsif Node (Elmt) = N then
+            return;
+         else
+            Next_Elmt (Elmt);
+         end if;
+      end loop;
+   end Append_Unique_Elmt;
+
    --------------------
    -- Elists_Address --
    --------------------
@@ -183,21 +202,20 @@ package body Elists is
    -- Insert_Elmt_After --
    -----------------------
 
-   procedure Insert_Elmt_After (Node : Node_Id; Elmt : Elmt_Id) is
-      N : constant Union_Id := Elmts.Table (Elmt).Next;
+   procedure Insert_Elmt_After (N : Node_Or_Entity_Id; Elmt : Elmt_Id) is
+      Nxt : constant Union_Id := Elmts.Table (Elmt).Next;
 
    begin
-
       pragma Assert (Elmt /= No_Elmt);
 
       Elmts.Increment_Last;
-      Elmts.Table (Elmts.Last).Node := Node;
-      Elmts.Table (Elmts.Last).Next := N;
+      Elmts.Table (Elmts.Last).Node := N;
+      Elmts.Table (Elmts.Last).Next := Nxt;
 
       Elmts.Table (Elmt).Next := Union_Id (Elmts.Last);
 
-      if N in Elist_Range then
-         Elists.Table (Elist_Id (N)).Last := Elmts.Last;
+      if Nxt in Elist_Range then
+         Elists.Table (Elist_Id (Nxt)).Last := Elmts.Last;
       end if;
    end Insert_Elmt_After;
 
@@ -302,11 +320,11 @@ package body Elists is
       return Elmt = No_Elmt;
    end No;
 
-   -----------
+   ----------
    -- Node --
-   -----------
+   ----------
 
-   function Node (Elmt : Elmt_Id) return Node_Id is
+   function Node (Elmt : Elmt_Id) return Node_Or_Entity_Id is
    begin
       if Elmt = No_Elmt then
          return Empty;
@@ -328,12 +346,12 @@ package body Elists is
    -- Prepend_Elmt --
    ------------------
 
-   procedure Prepend_Elmt (Node : Node_Id; To : Elist_Id) is
+   procedure Prepend_Elmt (N : Node_Or_Entity_Id; To : Elist_Id) is
       F : constant Elmt_Id := Elists.Table (To).First;
 
    begin
       Elmts.Increment_Last;
-      Elmts.Table (Elmts.Last).Node := Node;
+      Elmts.Table (Elmts.Last).Node := N;
 
       if F = No_Elmt then
          Elists.Table (To).Last := Elmts.Last;
@@ -343,7 +361,6 @@ package body Elists is
       end if;
 
       Elists.Table (To).First  := Elmts.Last;
-
    end Prepend_Elmt;
 
    -------------
@@ -440,7 +457,7 @@ package body Elists is
    -- Replace_Elmt --
    ------------------
 
-   procedure Replace_Elmt (Elmt : Elmt_Id; New_Node : Node_Id) is
+   procedure Replace_Elmt (Elmt : Elmt_Id; New_Node : Node_Or_Entity_Id) is
    begin
       Elmts.Table (Elmt).Node := New_Node;
    end Replace_Elmt;
@@ -465,4 +482,14 @@ package body Elists is
       Elmts.Tree_Write;
    end Tree_Write;
 
+   ------------
+   -- Unlock --
+   ------------
+
+   procedure Unlock is
+   begin
+      Elists.Locked := False;
+      Elmts.Locked := False;
+   end Unlock;
+
 end Elists;