home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / COMPILER / ELT.SA < prev    next >
Text File  |  1995-02-13  |  9KB  |  220 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. -- elt.sa: Class elements.
  9. -------------------------------------------------------------------
  10. -- ELT: An element of a class in the Sather compiler. 
  11. -- ELT_TBL: A table of class elements retrievable by name.
  12. -------------------------------------------------------------------
  13. class ELT is
  14.    -- An element of a class in the Sather compiler. We avoid copying
  15.    -- any source trees and computing much for code which isn't used.
  16.    
  17.    attr sig:SIG;        -- The signature of the element.
  18.    attr srcsig:SIG;        -- The signature of this routine or iter
  19.       -- in the class it originally came from. Used to detect built-in ops.
  20.    attr tr:$TR_CLASS_ELT;    -- The source tree for this element.
  21.       -- This may be a routine or iter definition or an attribute
  22.       -- definition. Whether this refers to the reader or the writer
  23.       -- is determined from the signature. The element may have a 
  24.       -- different name or "private" status from the source because
  25.       -- of renaming. 
  26.    attr con:TP_CONTEXT;        -- The context within which the types in
  27.       -- this element should be resolved. The same context can be shared
  28.       -- between elements. An element finds its prog here, too.
  29.    attr is_private:BOOL;    -- True if private. Explicit because of 
  30.       -- "private" and "readonly" includes.
  31.    attr is_external:BOOL;    -- True if this is in an external 
  32.       -- class (with or without a body).
  33.  
  34.    create(sig:SIG, srcsig:SIG, tr:$TR_CLASS_ELT, con:TP_CONTEXT, 
  35.       is_private:BOOL):SAME 
  36.       -- A new element with the specified attributes. If any of the 
  37.       -- attributes is void then prints an error message and returns
  38.       -- void.
  39.       pre ~void(sig) and ~void(srcsig) and ~void(tr) and ~void(con) is
  40.       r::=new; r.sig:=sig; r.srcsig:=srcsig; r.tr:=tr;
  41.       r.con:=con; r.is_private:=is_private; return r end;
  42.    
  43.    prog:PROG 
  44.       -- The program that this element belongs to.
  45.       pre ~void(self) is      
  46.       return con.prog end;
  47.    
  48.    name:IDENT 
  49.       -- The name of the feature represented by this element.
  50.       pre ~void(self) is
  51.       return sig.name end;
  52.    
  53.    ret:$TP 
  54.       -- The return type, if any.
  55.       pre ~void(self) is      
  56.       return sig.ret end;
  57.  
  58.    tp:$TP 
  59.       -- The type this element comes from.
  60.       pre ~void(self) and ~void(sig) is      
  61.       return sig.tp end;
  62.  
  63.    impl:IMPL 
  64.       -- The implementation object for this element.
  65.       pre ~void(self) is
  66.       r::=prog.impl_tbl.impl_of(tp);
  67.       if void(r) then
  68.      #OUT + "Compiler error, ELT::impl with sig: " + sig.str +
  69.      "returns void."; return void end; 
  70.       return r end;
  71.    
  72.    is_iter:BOOL 
  73.       -- True if self is an iter.
  74.       pre ~void(self) is
  75.       return sig.is_iter end;
  76.  
  77.    is_shared_writer:BOOL is
  78.       -- True if self is the writer routine for a shared attribute.
  79.       if ~sig.is_shared_writer_sig then return false end;
  80.       ltr::=tr;
  81.       typecase ltr
  82.       when TR_SHARED_DEF then return true
  83. --    else return false end end;                                                -- NLP
  84.       else; end; return false; end;                                             -- NLP
  85.    
  86.    is_attr_writer:BOOL is
  87.       -- True if self is the writer routine for an object attribute.
  88.       if ~sig.is_attr_writer_sig then return false end;
  89.       ltr::=tr;
  90.       typecase ltr
  91.       when TR_ATTR_DEF then return true
  92. --    else return false end end;                                                -- NLP
  93.       else; end; return false; end;                                             -- NLP
  94.  
  95.    is_attr_reader:BOOL is
  96.       -- True if self is the reader routine for an object attribute.
  97.       if ~sig.is_reader_sig then return false end;
  98.       ltr::=tr;
  99.       typecase ltr
  100.       when TR_ATTR_DEF then return true
  101. --    else return false end end;                                                -- NLP
  102.       else; end; return false; end;                                             -- NLP
  103.       
  104.    is_const_reader:BOOL is
  105.       -- True if self is the reader routine for a constant attribute.
  106.       if ~sig.is_reader_sig then return false end;
  107.       ltr::=tr;
  108.       typecase ltr
  109.       when TR_CONST_DEF then return true
  110. --    else return false end end;                                                -- NLP
  111.       else; end; return false; end;                                             -- NLP
  112.  
  113.    is_shared_reader:BOOL is
  114.       -- True if self is the reader routine for a shared attribute.
  115.       if ~sig.is_reader_sig then return false end;
  116.       ltr::=tr;
  117.       typecase ltr
  118.       when TR_SHARED_DEF then return true
  119. --    else return false end end;                                                -- NLP
  120.       else; end; return false; end;                                             -- NLP
  121.    
  122.    is_abstract:BOOL is 
  123.       -- True if this element is a routine or iter without a body.
  124.       ltr::=tr;
  125.       typecase ltr
  126.       when TR_ROUT_DEF then return ltr.is_abstract 
  127. --    else return false end end;                                                -- NLP
  128.       else; end; return false; end;                                             -- NLP
  129.       
  130.    is_attr_access:BOOL is
  131.       -- True if this element is a reader or a writer for a 
  132.       -- constant, shared, or object attribute.
  133.       ltr::=tr;      
  134.       typecase ltr
  135.       when TR_SHARED_DEF then return true
  136.       when TR_CONST_DEF then return true
  137.       when TR_ATTR_DEF then return true
  138. --    else return false end end;                                                -- NLP
  139.       else; end; return false; end;                                             -- NLP
  140.  
  141.    is_invariant:BOOL is
  142.       -- True if this element describes a routine of the form
  143.       -- `invariant:BOOL'.
  144.       return sig.is_invariant end;
  145.    
  146.    conflicts_with(e:SAME):BOOL is
  147.       -- True if the signature of self conflicts with the signature of
  148.       -- `e'. This is a symmetric relationship.
  149.       return sig.conflicts_with(e.sig) end;
  150.    
  151. end; -- class ELT
  152.  
  153. -------------------------------------------------------------------
  154. class ELT_TBL is
  155.    -- A table of class elements retrievable by name.
  156.    -- 
  157.    -- `get_query!(i:IDENT):ELT' yields each element named by `i'.
  158.    -- `test(e:ELT):BOOL' tests for the given element.
  159.    -- `insert(e:ELT):SAME' inserts an element.
  160.    -- `delete(e:ELT):SAME' deletes an element.
  161.    -- `elt!:ELT' yields each element.
  162.    
  163.    include FQSET{IDENT,ELT};
  164.    
  165.    query_test(name:IDENT, e:ELT):BOOL is
  166.       -- True if `e' is an element with the name `name'.
  167.       if void(e) then return false end;
  168.       return e.sig.name=name end;
  169.    
  170.    query_hash(i:IDENT):INT is
  171.       -- A hash value computed from the name `i'.
  172.       return i.hash end;
  173.  
  174.    elt_hash(e:ELT):INT is
  175.       -- A hash value computed from the name of an element.
  176.       
  177.       return e.sig.name.hash end;
  178.  
  179.    elt_conflicting_with(e:ELT):ELT 
  180.       -- Returns an element of self that conflicts with `e' if one 
  181.       -- exists, otherwise returns void.
  182.       pre ~void(e) is
  183.       loop r::=get_query!(e.name);
  184.      if r.conflicts_with(e) then return r end end;
  185.       return void end;
  186.  
  187.    elt_same_name_as(e:ELT):ELT 
  188.       -- Returns an element of self that has the same name as `e' if one 
  189.       -- exists, otherwise returns void.
  190.       pre ~void(e) is
  191.       loop return get_query!(e.name) end;
  192.       return void end;
  193.    
  194.    ifc:IFC is
  195.       -- The interface of this set of elements.
  196.       if void(self) or hsize=0 then return void end;
  197.       st:SIG_TBL; sig:SIG;
  198.       loop sig:=elt!.sig; st:=st.insert(sig) end;
  199.       return #(st,sig.tp) end;
  200.    
  201.    public_ifc:IFC is
  202.       -- The public interface of this set of elements.
  203.       st:SIG_TBL; if void(self) or hsize=0 then return void end;
  204.       e:ELT;
  205.       loop e:=elt!;
  206.      if ~e.is_private then st:=st.insert(e.sig) end end;
  207.       return #(st,e.sig.tp) end;
  208.  
  209.    elt_with_sig(s:SIG):ELT 
  210.       -- Return an element from this table with the signature `s'
  211.       -- if present, void if not.
  212.       pre ~void(s) is
  213.       loop r::=get_query!(s.name);
  214.      if s.is_eq(r.sig) then return r end end;
  215.       return void end;
  216.  
  217. end; -- class ELT_TBL
  218.    
  219. -------------------------------------------------------------------
  220.