------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1994 by International Computer Science Institute            --
-- This file is part of the GNU Sather package. It is free software; you may --
-- redistribute  and/or modify it under the terms of the  GNU General Public --
-- License (GPL)  as  published  by the  Free  Software  Foundation;  either --
-- version 2 of the license, or (at your option) any later version.          --
-- This  program  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/GPL for more details.        --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- global.sa: Globals in the Sather compiler.

class GLOBAL_TBL is
   -- A table of global variables for the Sather compiler.
   
   attr tbl:FMAP{$TP,FMAP{IDENT,AM_SHARED_EXPR}};
      -- Maps from types to hmaps from idents to globals.
   attr prog:PROG;		-- The program this is for.
   attr top_sort:FLIST{AM_SHARED_EXPR};
      -- List of globals in an order they can be initialized.

   create(p:PROG):SAME is
      -- A new table for the program `p'.
      return new end; 
   
   get(name:IDENT, tp:$TP):AM_SHARED_EXPR is
      -- Retrieve the global with the name `name' in the type `tp'
      -- if present, otherwise return void.
      m::=tbl.get(tp);
      if ~void(m) then return m.get(name) end;
      return void end;

   insert(g:AM_SHARED_EXPR) is
      -- Insert the global `g' into the table.
      m::=tbl.get(g.class_tp);      
      m:=m.insert(g.name,g);
      tbl:=tbl.insert(g.class_tp,m);
      top_sort:=top_sort.push(g);
   end;
   
end;

-------------------------------------------------------------------
