home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / COMPILER / GLOBAL.SA < prev    next >
Text File  |  1994-11-15  |  2KB  |  42 lines

  1. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  2. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  3. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  4. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  5. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  6. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  7.  
  8. -- global.sa: Globals in the Sather compiler.
  9. -------------------------------------------------------------------
  10.  
  11. class GLOBAL_TBL is
  12.    -- A table of global variables for the Sather compiler.
  13.    
  14.    attr tbl:FMAP{$TP,FMAP{IDENT,AM_GLOBAL_EXPR}};
  15.       -- Maps from types to hmaps from idents to globals.
  16.    attr prog:PROG;        -- The program this is for.
  17.    attr top_sort:FLIST{AM_GLOBAL_EXPR};
  18.       -- List of globals in an order they can be initialized.
  19.  
  20.    create(p:PROG):SAME is
  21.       -- A new table for the program `p'.
  22.       return new end; 
  23.    
  24.    get(name:IDENT, tp:$TP):AM_GLOBAL_EXPR is
  25.       -- Retrieve the global with the name `name' in the type `tp'
  26.       -- if present, otherwise return void.
  27.       m::=tbl.get(tp);
  28.       if ~void(m) then return m.get(name) end;
  29.       return void end;
  30.  
  31.    insert(g:AM_GLOBAL_EXPR) is
  32.       -- Insert the global `g' into the table.
  33.       m::=tbl.get(g.class_tp);      
  34.       m:=m.insert(g.name,g);
  35.       tbl:=tbl.insert(g.class_tp,m);
  36.       top_sort:=top_sort.push(g);
  37.    end;
  38.    
  39. end;
  40.  
  41. -------------------------------------------------------------------
  42.