home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
sa104os2.zip
/
SATHR104.ZIP
/
SATHER
/
COMPILER
/
IDENT.SA
< prev
next >
Wrap
Text File
|
1994-12-22
|
5KB
|
128 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". <----------
-- ident.sa: Identifier related classes.
-------------------------------------------------------------------
-- IDENT: Representation of identifiers in the Sather compiler.
-- IDENT_TBL: A table mapping strings to identifiers.
-------------------------------------------------------------------
value class IDENT < $HASH, $IS_EQ{IDENT} is
-- Representation of identifiers in the Sather compiler.
-- A value class with one attribute: a pointer to a string containing
-- the identifier. The string objects are uniquely associated with
-- the string, so SI_IDENT equality can be used to test for string
-- equality.
attr str:STR; -- The string represented by self.
create(s:STR):SAME is
-- Create a new identifier for the string `s'.
r:SAME; return r.str(s) end;
is_eq(i:SAME):BOOL is
-- Test whether self is the same identifier as `i'.
return SYS::ob_eq(str,i.str) end;
is_neq(i:SAME):BOOL is
-- Test whether self is the same identifier as `i'.
return ~SYS::ob_eq(str,i.str) end;
is_iter:BOOL is
-- True if self is the name of an iter (ends with a "!").
return ~void(str) and str[str.size-1]='!' end;
str_in(s:FSTR):FSTR is
-- Append the string represented by self to `s'.
return s + str end;
hash:INT is
-- MBK, SYS::id(str) by itself not that good a hash.
x::=SYS::id(str);
return (x*1664525) + 1013904223; -- Numerical Recipes in C, p 284
end;
end; -- value class IDENT
-------------------------------------------------------------------
class IDENT_TBL is
-- A table mapping strings to identifiers.
-- get_query(s:STR):IDENT to get identifier if present.
-- insert(i:IDENT):SAME to add a new identifier.
include FQSET{STR,IDENT};
query_test(s:STR, i:IDENT):BOOL is
-- True if `i' represents `s'.
return s=i.str end;
query_hash(s:STR):INT is
-- Hash value for the string `s'.
return s.hash end;
elt_hash(i:IDENT):INT is
-- Hash value for the identifier `i'.
return i.str.hash end;
end; -- class IDENT_TBL
-------------------------------------------------------------------
class IDENT_BUILTIN is
-- Cache for quick access to the built-in identifers.
attr dollar_OB_ident, ARR_ident, INT_ident, INTI_ident, FLT_ident,
FLTD_ident, FLTDX_ident, FLTX_ident, plus_ident, minus_ident,
times_ident, div_ident, pow_ident, mod_ident, is_lt_ident,
is_leq_ident, is_gt_ident, is_geq_ident, negate_ident, not_ident,
AVAL_ident, AREF_ident, aget_ident, aset_ident, call_ident,
call_bang_ident, create_ident, ARRAY_ident, self_ident,
invariant_ident, asize_ident, main_ident, is_eq_ident,
is_neq_ident:IDENT;
create (p:PROG):SAME is
-- A new cache for the builtin identifiers.
r::=new;
r.dollar_OB_ident:=p.ident_for("$OB");
r.ARR_ident:=p.ident_for("ARR");
r.INT_ident:=p.ident_for("INT");
r.INTI_ident:=p.ident_for("INTI");
r.FLT_ident:=p.ident_for("FLT");
r.FLTD_ident:=p.ident_for("FLTD");
r.FLTDX_ident:=p.ident_for("FLTDX");
r.FLTX_ident:=p.ident_for("FLTX");
r.plus_ident:=p.ident_for("plus");
r.minus_ident:=p.ident_for("minus");
r.times_ident:=p.ident_for("times");
r.div_ident:=p.ident_for("div");
r.pow_ident:=p.ident_for("pow");
r.mod_ident:=p.ident_for("mod");
r.is_lt_ident:=p.ident_for("is_lt");
r.is_leq_ident:=p.ident_for("is_leq");
r.is_gt_ident:=p.ident_for("is_gt");
r.is_geq_ident:=p.ident_for("is_geq");
r.negate_ident:=p.ident_for("negate");
r.not_ident:=p.ident_for("not");
r.AVAL_ident:=p.ident_for("AVAL");
r.AREF_ident:=p.ident_for("AREF");
r.aget_ident:=p.ident_for("aget");
r.aset_ident:=p.ident_for("aset");
r.call_ident:=p.ident_for("call");
r.call_bang_ident:=p.ident_for("call!");
r.create_ident:=p.ident_for("create");
r.ARRAY_ident:=p.ident_for("ARRAY");
r.self_ident:=p.ident_for("self");
r.invariant_ident:=p.ident_for("invariant");
r.asize_ident:=p.ident_for("asize");
r.main_ident:=p.ident_for("main");
r.is_eq_ident:=p.ident_for("is_eq");
r.is_neq_ident:=p.ident_for("is_neq");
return r end;
end; -- class IDENT_BUILTIN
-------------------------------------------------------------------