const.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. <----------
-- $AM_CONST: Supertype for compiler constants.
-- AM_CONST: Implementation to be included by $AM_CONST nodes.
-- AM_VOID_CONST: Representation of "void".
-- AM_ARR_CONST: Representation of constant ARRAY{T} objects.
-- AM_BOOL_CONST: Representation of constant BOOL's.
-- AM_CHAR_CONST: Representation of constant CHAR objects.
-- AM_STR_CONST: Representation of constant strings.
-- AM_INT_CONST: Representation of constant INT objects.
-- AM_INTI_CONST: Representation of constant INTI objects.
-- AM_FLT_CONST: Representation of constant FLT objects.
-- AM_FLTD_CONST: Representation of constant FLTD objects.
-- AM_FLTX_CONST: Representation of constant FLTX objects.
-- AM_FLTDX_CONST: Representation of constant FLTDX.
-- AM_FLTI_CONST: Representation of constant FLTI objects.
abstract class $AM_CONST < $AM_EXPR
abstract class $AM_CONST < $AM_EXPR is
-- Supertype for compiler constants.
end;
class AM_CONST < $AM_CONST
class AM_CONST < $AM_CONST is
-- Implementation to be included by $AM_CONST nodes.
include AM_EXPR;
attr tp_at:$TP;
tp:$TP is return tp_at end; -- AM_ARR_CONST::tp_at
copy:$AM_EXPR is return self end;
-- all constants can be optimized
can_invar_opt(prog:PROG):BOOL is return true end;
end;
class AM_VOID_CONST < $AM_CONST
class AM_VOID_CONST < $AM_CONST is
-- Representation of "void".
include AM_CONST;
is_eq(a:$OB):BOOL is
typecase a
when AM_VOID_CONST then return true;
else return false;
end;
end;
hash:INT is
return 12648273; -- some constant random for hashing this
end;
end;
class AM_ARR_CONST < $AM_CONST
class AM_ARR_CONST < $AM_CONST is
-- Representation of constant ARRAY{T} objects.
include AM_CONST;
attr elt_tp:TP_CLASS; -- The type of the contained elements.
attr elts:ARRAY{$AM_CONST}; -- The array elements.
is_eq(a:$OB):BOOL is
typecase a
when AM_ARR_CONST then
if elts.asize /= a.elts.asize then return false end;-- AM_ARR_CONST::elts ARRAY{1}::asize INT::is_eq AM_ARR_CONST::elts ARRAY{1}::asize BOOL::not
loop i::=elts.asize.times!;-- AM_ARR_CONST::elts ARRAY{1}::asize INT::times!
if ~(elts[i]=a.elts[i]) then return false end;-- AM_ARR_CONST::elts ARRAY{1}::aget AM_ARR_CONST::elts ARRAY{1}::aget BOOL::not
end;
return true;
else return false;
end;
end;
hash:INT is
htemp ::= 21857; -- some random hash start value
loop i::= elts.asize.times!;-- AM_ARR_CONST::elts ARRAY{1}::asize INT::times!
htemp := htemp.hash; -- mix up the hash value a bit-- INT::hash
htemp := htemp.bxor(elts[i].hash);-- INT::bxor AM_ARR_CONST::elts ARRAY{1}::aget
end;
return htemp;
end;
end;
class AM_BOOL_CONST < $AM_CONST
class AM_BOOL_CONST < $AM_CONST is
-- Representation of constant BOOL's.
include AM_CONST;
attr val:BOOL; -- The boolean value.
create(src:SFILE_ID):SAME is
-- Create a new boolean constant with source `src'.
r::=new; r.source:=src; return r end;-- AM_BOOL_CONST::source
is_eq(a:$OB): BOOL is
typecase a
when AM_BOOL_CONST then return val = a.val;-- AM_BOOL_CONST::val BOOL::is_eq AM_BOOL_CONST::val
else return false;
end;
end;
hash:INT is
if val then-- AM_BOOL_CONST::val
return 1294812094; -- return two different const hash values
else
return 1284721945;
end;
end;
end;
class AM_CHAR_CONST < $AM_CONST
class AM_CHAR_CONST < $AM_CONST is
-- Representation of constant CHAR objects. Uses `bval' if the program
-- being compiled uses the same sized characters as the compiler,
-- val otherwise. Can tell by checking whether `val' is void.
include AM_CONST;
attr bval:CHAR; -- The character, if the compiled
-- program uses the same representation as the compiler.
attr val:INTI; -- The value of the char, if non-void.
create(t:AS_CHAR_LIT_EXPR):SAME is
-- Create a new character constant for the tree form `t'. Must
-- change this if the target has a different format.
r::=new; r.source:=t.source; r.bval:=t.val.char; return r end;-- AM_CHAR_CONST::source AS_CHAR_LIT_EXPR::source AM_CHAR_CONST::bval AS_CHAR_LIT_EXPR::val INT::char
is_eq(a:$OB):BOOL is
typecase a
when AM_CHAR_CONST then
if void(val) then-- AM_CHAR_CONST::val
return bval = a.bval;-- AM_CHAR_CONST::bval CHAR::is_eq AM_CHAR_CONST::bval
else
return val = a.val;-- AM_CHAR_CONST::val INTI::is_eq AM_CHAR_CONST::val
end;
else return false;
end;
end;
hash:INT is
if void(val) then-- AM_CHAR_CONST::val
return bval.hash;-- AM_CHAR_CONST::bval CHAR::hash
else
return val.hash;-- AM_CHAR_CONST::val INTI::hash
end;
end;
end;
class AM_STR_CONST < $AM_CONST
class AM_STR_CONST < $AM_CONST is
-- Representation of constant strings.
include AM_CONST;
attr bval:STR; -- The string if the compiler's are
-- the same as the compiled program.
create:SAME is return new; end;
create(t:AS_STR_LIT_EXPR):SAME is
-- Create a string constant for tree form `t'. Must change this
-- if the target has a different format.
r::=new; r.source:=t.source; r.bval:=t.s; return r end;-- AM_STR_CONST::source AS_STR_LIT_EXPR::source AM_STR_CONST::bval AS_STR_LIT_EXPR::s
create_from_str(src:SFILE_ID, str:STR):SAME is
-- Create a string constant for tree form `t'. Must change this
-- if the target has a different format.
r::=new; r.source:=src; r.bval:=str; return r end;
is_eq(a:$OB):BOOL is
typecase a
when AM_STR_CONST then return bval = a.bval;-- AM_STR_CONST::bval STR::is_eq AM_STR_CONST::bval
else return false;
end;
end;
hash:INT is
return bval.hash;-- AM_STR_CONST::bval STR::hash
end;
end;
class AM_INT_CONST < $AM_CONST
class AM_INT_CONST < $AM_CONST is
-- Representation of constant INT objects. Uses `bval' if the program
-- being compiled uses the same sized integers as the compiler,
-- val otherwise. Can tell by checking whether `val' is void.
include AM_CONST;
attr val:INTI; -- The bits of the integer, if non-void.
create(t:AS_INT_LIT_EXPR):SAME is
-- Create a new integer constant for the tree form `t'. Must
-- change this is the target has a different format.
r::=new; r.source:=t.source; r.val:=t.val; return r end;-- AM_INT_CONST::source AS_INT_LIT_EXPR::source AM_INT_CONST::val AS_INT_LIT_EXPR::val
is_eq(a:$OB):BOOL is
typecase a
when AM_INT_CONST then
return val = a.val;-- AM_INT_CONST::val INTI::is_eq AM_INT_CONST::val
else return false;
end;
end;
hash:INT is
return val.hash;-- AM_INT_CONST::val INTI::hash
end;
end;
class AM_INTI_CONST < $AM_CONST
class AM_INTI_CONST < $AM_CONST is
-- Representation of constant INTI objects.
include AM_CONST;
attr val:INTI; -- The integer.
create(t:AS_INT_LIT_EXPR):SAME is
-- Create a new infinite precision integer constant for the
-- tree form `t'
r::=new; r.source:=t.source; r.val:=t.val; return r end;-- AM_INTI_CONST::source AS_INT_LIT_EXPR::source AM_INTI_CONST::val AS_INT_LIT_EXPR::val
is_eq(a:$OB):BOOL is
typecase a
when AM_INTI_CONST then return val = a.val;-- AM_INTI_CONST::val INTI::is_eq AM_INTI_CONST::val
else return false;
end;
end;
hash:INT is
return val.hash;-- AM_INTI_CONST::val INTI::hash
end;
end;
class AM_FLT_CONST < $AM_CONST
class AM_FLT_CONST < $AM_CONST is
-- Representation of constant FLT objects.
include AM_CONST;
attr val:RAT; -- The value.
create(t:AS_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;-- AM_FLT_CONST::source AS_FLT_LIT_EXPR::source AM_FLT_CONST::val AS_FLT_LIT_EXPR::val
return r end;
is_eq(a:$OB):BOOL is
typecase a
when AM_FLT_CONST then return val = a.val;-- AM_FLT_CONST::val RAT::is_eq AM_FLT_CONST::val
else return false;
end;
end;
hash:INT is
return val.hash;-- AM_FLT_CONST::val RAT::hash
end;
end;
class AM_FLTD_CONST < $AM_CONST
class AM_FLTD_CONST < $AM_CONST is
-- Representation of constant FLTD objects.
include AM_CONST;
attr val:RAT; -- The value.
create(t:AS_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;-- AM_FLTD_CONST::source AS_FLT_LIT_EXPR::source AM_FLTD_CONST::val AS_FLT_LIT_EXPR::val
return r end;
is_eq(a:$OB):BOOL is
typecase a
when AM_FLTD_CONST then return val = a.val;-- AM_FLTD_CONST::val RAT::is_eq AM_FLTD_CONST::val
else return false;
end;
end;
hash:INT is
return val.hash;-- AM_FLTD_CONST::val RAT::hash
end;
end;
class AM_FLTX_CONST < $AM_CONST
class AM_FLTX_CONST < $AM_CONST is
-- Representation of constant FLTX objects by their mantissa and
-- exponent.
include AM_CONST;
attr val:RAT; -- The value.
create(t:AS_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;-- AM_FLTX_CONST::source AS_FLT_LIT_EXPR::source AM_FLTX_CONST::val AS_FLT_LIT_EXPR::val
return r end;
is_eq(a:$OB):BOOL is
typecase a
when AM_FLTX_CONST then return val = a.val;-- AM_FLTX_CONST::val RAT::is_eq AM_FLTX_CONST::val
else return false;
end;
end;
hash:INT is
return val.hash;-- AM_FLTX_CONST::val RAT::hash
end;
end;
class AM_FLTDX_CONST < $AM_CONST
class AM_FLTDX_CONST < $AM_CONST is
-- Representation of constant FLTDX objects by their mantissa and
-- exponent.
include AM_CONST;
attr val:RAT; -- The value.
create(t:AS_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;-- AM_FLTDX_CONST::source AS_FLT_LIT_EXPR::source AM_FLTDX_CONST::val AS_FLT_LIT_EXPR::val
return r end;
is_eq(a:$OB):BOOL is
typecase a
when AM_FLTDX_CONST then return val = a.val;-- AM_FLTDX_CONST::val RAT::is_eq AM_FLTDX_CONST::val
else return false;
end;
end;
hash:INT is
return val.hash;-- AM_FLTDX_CONST::val RAT::hash
end;
end;
class AM_FLTI_CONST < $AM_CONST
class AM_FLTI_CONST < $AM_CONST is
-- Representation of constant FLTI objects by their mantissa and
-- exponent.
include AM_CONST;
attr val:RAT; -- The value.
create(t:AS_FLT_LIT_EXPR):SAME is
-- Create a new floating point constant for the tree form `t'.
r::=new; r.source:=t.source; r.val:=t.val;-- AM_FLTI_CONST::source AS_FLT_LIT_EXPR::source AM_FLTI_CONST::val AS_FLT_LIT_EXPR::val
return r end;
end;