ident.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- Copyright (C) International Computer Science Institute, 1995.  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.

immutable class IDENT < $HASH

immutable class IDENT < $HASH is -- Representation of identifiers in the Sather compiler. -- A immutable 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. Note that IDENTs use a shared (global) table, so -- they aren't reentrant. include COMPARABLE; shared tmp_count:INT; private shared ident_tbl:IDENT_TBL; readonly attr str:STR; -- The string represented by self. create(s:STR):IDENT is -- The identifier corresonding to the string `s'. if void(s) then return void; end; i::=ident_tbl.get_query(s); -- IDENT::ident_tbl IDENT_TBL::get_query if void(i) then i:=i.str(s);-- IDENT::str ident_tbl:=ident_tbl.insert(i) end; -- IDENT::ident_tbl IDENT::ident_tbl IDENT_TBL::insert return i end; str(i:INT): STR -- Returns a name with a list of empty parameters. is res: STR; if i = 0 then return str end;-- INT::is_eq IDENT::str loop i.times!;-- INT::times! res := res + ",".separate!("_");-- STR::plus STR::separate! end; return str + "{" + res + "}";-- IDENT::str STR::plus STR::plus STR::plus end; is_eq(i:SAME):BOOL is -- Test whether self is the same identifier as `i'. return SYS::ob_eq(str,i.str) end;-- SYS::ob_eq IDENT::str IDENT::str 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;-- IDENT::str BOOL::not IDENT::str IDENT::str STR::size INT::minus CHAR::is_eq 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);-- SYS::id IDENT::str -- Numerical Recipes in C, p 284 return (x.mtimes(1664525)).mplus(1013904223);-- INT::mtimes INT::mplus end; next_tmp(oldident:STR):STR is ret ::= #STR;-- STR::create ret := "_pS_"+oldident+"_"+tmp_count.str;-- STR::plus STR::plus IDENT::tmp_count INT::str tmp_count := tmp_count + 1;-- IDENT::tmp_count IDENT::tmp_count INT::plus return ret; end; end; -- immutable class IDENT

class IDENT_TBL

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;-- STR::is_eq IDENT::str query_hash(s:STR):INT is -- Hash value for the string `s'. return s.hash end;-- STR::hash elt_hash(i:IDENT):INT is -- Hash value for the identifier `i'. return i.str.hash end;-- IDENT::str STR::hash end; -- class IDENT_TBL

class IDENT_BUILTIN

class IDENT_BUILTIN is -- Cache for quick access to the built-in identifers. readonly shared 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, ret_ident, -- Ivin. invariant_ident, asize_ident, main_ident, is_eq_ident, is_neq_ident, ob_eq_ident, bang_ident, SYS_ident, --FORTRAN STUFF F_INTEGER_ident, F_REAL_ident, F_INTEGER_ARR_ident, F_REAL_ARR_ident:IDENT; init is -- Construct the built-in identifiers. dollar_OB_ident:=#IDENT("$OB");-- IDENT_BUILTIN::dollar_OB_ident IDENT::create ARR_ident:=#IDENT("ARR");-- IDENT_BUILTIN::ARR_ident IDENT::create INT_ident:=#IDENT("INT");-- IDENT_BUILTIN::INT_ident IDENT::create INTI_ident:=#IDENT("INTI");-- IDENT_BUILTIN::INTI_ident IDENT::create FLT_ident:=#IDENT("FLT");-- IDENT_BUILTIN::FLT_ident IDENT::create FLTD_ident:=#IDENT("FLTD");-- IDENT_BUILTIN::FLTD_ident IDENT::create FLTDX_ident:=#IDENT("FLTDX");-- IDENT_BUILTIN::FLTDX_ident IDENT::create FLTX_ident:=#IDENT("FLTX");-- IDENT_BUILTIN::FLTX_ident IDENT::create -- FORTRAN stuff F_INTEGER_ident := #IDENT("F_INTEGER");-- IDENT_BUILTIN::F_INTEGER_ident IDENT::create F_REAL_ident := #IDENT("F_REAL");-- IDENT_BUILTIN::F_REAL_ident IDENT::create -- F_INTEGER_ARR_ident := #IDENT("F_INTEGER_ARR"); -- F_REAL_ARR_ident := #IDENT("F_REAL_ARR"); plus_ident:=#IDENT("plus");-- IDENT_BUILTIN::plus_ident IDENT::create minus_ident:=#IDENT("minus");-- IDENT_BUILTIN::minus_ident IDENT::create times_ident:=#IDENT("times");-- IDENT_BUILTIN::times_ident IDENT::create div_ident:=#IDENT("div");-- IDENT_BUILTIN::div_ident IDENT::create pow_ident:=#IDENT("pow");-- IDENT_BUILTIN::pow_ident IDENT::create mod_ident:=#IDENT("mod");-- IDENT_BUILTIN::mod_ident IDENT::create is_lt_ident:=#IDENT("is_lt");-- IDENT_BUILTIN::is_lt_ident IDENT::create is_leq_ident:=#IDENT("is_leq");-- IDENT_BUILTIN::is_leq_ident IDENT::create is_gt_ident:=#IDENT("is_gt");-- IDENT_BUILTIN::is_gt_ident IDENT::create is_geq_ident:=#IDENT("is_geq");-- IDENT_BUILTIN::is_geq_ident IDENT::create negate_ident:=#IDENT("negate");-- IDENT_BUILTIN::negate_ident IDENT::create not_ident:=#IDENT("not");-- IDENT_BUILTIN::not_ident IDENT::create AVAL_ident:=#IDENT("AVAL");-- IDENT_BUILTIN::AVAL_ident IDENT::create AREF_ident:=#IDENT("AREF");-- IDENT_BUILTIN::AREF_ident IDENT::create aget_ident:=#IDENT("aget"); -- IDENT_BUILTIN::aget_ident IDENT::create aset_ident:=#IDENT("aset"); -- IDENT_BUILTIN::aset_ident IDENT::create call_ident:=#IDENT("call"); -- IDENT_BUILTIN::call_ident IDENT::create call_bang_ident:=#IDENT("call!"); -- IDENT_BUILTIN::call_bang_ident IDENT::create create_ident:=#IDENT("create"); -- IDENT_BUILTIN::create_ident IDENT::create ARRAY_ident:=#IDENT("ARRAY"); -- IDENT_BUILTIN::ARRAY_ident IDENT::create ret_ident:=#IDENT("ret_val"); -- IDENT_BUILTIN::ret_ident IDENT::create self_ident:=#IDENT("self"); -- IDENT_BUILTIN::self_ident IDENT::create invariant_ident:=#IDENT("invariant"); -- IDENT_BUILTIN::invariant_ident IDENT::create asize_ident:=#IDENT("asize"); -- IDENT_BUILTIN::asize_ident IDENT::create main_ident:=#IDENT("main"); -- IDENT_BUILTIN::main_ident IDENT::create is_eq_ident:=#IDENT("is_eq"); -- IDENT_BUILTIN::is_eq_ident IDENT::create is_neq_ident:=#IDENT("is_neq"); -- IDENT_BUILTIN::is_neq_ident IDENT::create ob_eq_ident:=#IDENT("ob_eq");-- IDENT_BUILTIN::ob_eq_ident IDENT::create bang_ident:=#IDENT("!");-- IDENT_BUILTIN::bang_ident IDENT::create SYS_ident:=#IDENT("SYS");-- IDENT_BUILTIN::SYS_ident IDENT::create end; end; -- class IDENT_BUILTIN