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 >
Wrap
Text File
|
1995-02-13
|
9KB
|
220 lines
-- Copyright (C) International Computer Science Institute, 1994. COPYRIGHT --
-- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
-- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in --
-- the file "Doc/License" of the Sather distribution. The license is also --
-- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA. --
--------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
-- elt.sa: Class elements.
-------------------------------------------------------------------
-- ELT: An element of a class in the Sather compiler.
-- ELT_TBL: A table of class elements retrievable by name.
-------------------------------------------------------------------
class ELT is
-- An element of a class in the Sather compiler. We avoid copying
-- any source trees and computing much for code which isn't used.
attr sig:SIG; -- The signature of the element.
attr srcsig:SIG; -- The signature of this routine or iter
-- in the class it originally came from. Used to detect built-in ops.
attr tr:$TR_CLASS_ELT; -- The source tree for this element.
-- This may be a routine or iter definition or an attribute
-- definition. Whether this refers to the reader or the writer
-- is determined from the signature. The element may have a
-- different name or "private" status from the source because
-- of renaming.
attr con:TP_CONTEXT; -- The context within which the types in
-- this element should be resolved. The same context can be shared
-- between elements. An element finds its prog here, too.
attr is_private:BOOL; -- True if private. Explicit because of
-- "private" and "readonly" includes.
attr is_external:BOOL; -- True if this is in an external
-- class (with or without a body).
create(sig:SIG, srcsig:SIG, tr:$TR_CLASS_ELT, con:TP_CONTEXT,
is_private:BOOL):SAME
-- A new element with the specified attributes. If any of the
-- attributes is void then prints an error message and returns
-- void.
pre ~void(sig) and ~void(srcsig) and ~void(tr) and ~void(con) is
r::=new; r.sig:=sig; r.srcsig:=srcsig; r.tr:=tr;
r.con:=con; r.is_private:=is_private; return r end;
prog:PROG
-- The program that this element belongs to.
pre ~void(self) is
return con.prog end;
name:IDENT
-- The name of the feature represented by this element.
pre ~void(self) is
return sig.name end;
ret:$TP
-- The return type, if any.
pre ~void(self) is
return sig.ret end;
tp:$TP
-- The type this element comes from.
pre ~void(self) and ~void(sig) is
return sig.tp end;
impl:IMPL
-- The implementation object for this element.
pre ~void(self) is
r::=prog.impl_tbl.impl_of(tp);
if void(r) then
#OUT + "Compiler error, ELT::impl with sig: " + sig.str +
"returns void."; return void end;
return r end;
is_iter:BOOL
-- True if self is an iter.
pre ~void(self) is
return sig.is_iter end;
is_shared_writer:BOOL is
-- True if self is the writer routine for a shared attribute.
if ~sig.is_shared_writer_sig then return false end;
ltr::=tr;
typecase ltr
when TR_SHARED_DEF then return true
-- else return false end end; -- NLP
else; end; return false; end; -- NLP
is_attr_writer:BOOL is
-- True if self is the writer routine for an object attribute.
if ~sig.is_attr_writer_sig then return false end;
ltr::=tr;
typecase ltr
when TR_ATTR_DEF then return true
-- else return false end end; -- NLP
else; end; return false; end; -- NLP
is_attr_reader:BOOL is
-- True if self is the reader routine for an object attribute.
if ~sig.is_reader_sig then return false end;
ltr::=tr;
typecase ltr
when TR_ATTR_DEF then return true
-- else return false end end; -- NLP
else; end; return false; end; -- NLP
is_const_reader:BOOL is
-- True if self is the reader routine for a constant attribute.
if ~sig.is_reader_sig then return false end;
ltr::=tr;
typecase ltr
when TR_CONST_DEF then return true
-- else return false end end; -- NLP
else; end; return false; end; -- NLP
is_shared_reader:BOOL is
-- True if self is the reader routine for a shared attribute.
if ~sig.is_reader_sig then return false end;
ltr::=tr;
typecase ltr
when TR_SHARED_DEF then return true
-- else return false end end; -- NLP
else; end; return false; end; -- NLP
is_abstract:BOOL is
-- True if this element is a routine or iter without a body.
ltr::=tr;
typecase ltr
when TR_ROUT_DEF then return ltr.is_abstract
-- else return false end end; -- NLP
else; end; return false; end; -- NLP
is_attr_access:BOOL is
-- True if this element is a reader or a writer for a
-- constant, shared, or object attribute.
ltr::=tr;
typecase ltr
when TR_SHARED_DEF then return true
when TR_CONST_DEF then return true
when TR_ATTR_DEF then return true
-- else return false end end; -- NLP
else; end; return false; end; -- NLP
is_invariant:BOOL is
-- True if this element describes a routine of the form
-- `invariant:BOOL'.
return sig.is_invariant end;
conflicts_with(e:SAME):BOOL is
-- True if the signature of self conflicts with the signature of
-- `e'. This is a symmetric relationship.
return sig.conflicts_with(e.sig) end;
end; -- class ELT
-------------------------------------------------------------------
class ELT_TBL is
-- A table of class elements retrievable by name.
--
-- `get_query!(i:IDENT):ELT' yields each element named by `i'.
-- `test(e:ELT):BOOL' tests for the given element.
-- `insert(e:ELT):SAME' inserts an element.
-- `delete(e:ELT):SAME' deletes an element.
-- `elt!:ELT' yields each element.
include FQSET{IDENT,ELT};
query_test(name:IDENT, e:ELT):BOOL is
-- True if `e' is an element with the name `name'.
if void(e) then return false end;
return e.sig.name=name end;
query_hash(i:IDENT):INT is
-- A hash value computed from the name `i'.
return i.hash end;
elt_hash(e:ELT):INT is
-- A hash value computed from the name of an element.
return e.sig.name.hash end;
elt_conflicting_with(e:ELT):ELT
-- Returns an element of self that conflicts with `e' if one
-- exists, otherwise returns void.
pre ~void(e) is
loop r::=get_query!(e.name);
if r.conflicts_with(e) then return r end end;
return void end;
elt_same_name_as(e:ELT):ELT
-- Returns an element of self that has the same name as `e' if one
-- exists, otherwise returns void.
pre ~void(e) is
loop return get_query!(e.name) end;
return void end;
ifc:IFC is
-- The interface of this set of elements.
if void(self) or hsize=0 then return void end;
st:SIG_TBL; sig:SIG;
loop sig:=elt!.sig; st:=st.insert(sig) end;
return #(st,sig.tp) end;
public_ifc:IFC is
-- The public interface of this set of elements.
st:SIG_TBL; if void(self) or hsize=0 then return void end;
e:ELT;
loop e:=elt!;
if ~e.is_private then st:=st.insert(e.sig) end end;
return #(st,e.sig.tp) end;
elt_with_sig(s:SIG):ELT
-- Return an element from this table with the signature `s'
-- if present, void if not.
pre ~void(s) is
loop r::=get_query!(s.name);
if s.is_eq(r.sig) then return r end end;
return void end;
end; -- class ELT_TBL
-------------------------------------------------------------------