bool.sa
Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
-------------------------> GNU Sather - sourcefile <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute and/or modify it under the terms of the GNU Library General --
-- Public License (LGPL) as published by the Free Software Foundation; --
-- either version 2 of the license, or (at your option) any later version. --
-- This library is distributed in the hope that it will be useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details. --
-- The license text is also available from: Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --
--------------> Please email comments to <bug-sather@gnu.org> <--------------
immutable class BOOL < $IS_EQ, $IMMUTABLE, $OPTION, $ANCHORED_FMT
immutable class BOOL < $IS_EQ, $IMMUTABLE, $OPTION, $ANCHORED_FMT is
-- This class is defined in the Sather language. Boolean expressions
-- are used to provide control of the flow of program execution. The calss
-- provides the functionality of the Boolean logic domain. BOOL objects
-- represent boolean values and are equal either to `true' or to `false'.
-- The boolean operators `and' and `or' are language primitives. This
-- class defines operators for the entire Boolean algebra.
-- NOTE 1. There is no language defined value for 'true' and 'false'.
-- An implementation is not required to use any particular bit-pattern
-- in carrying out Boolean expression evaluation. However, it is
-- required to store false and true in Boolean objects in a consistent
-- manner.
--
-- 2. This implementation converts true to the numeric value one and
-- false to the numeric value zero
-- Version 1.1 Sep 98. Copyright K Hopper, U of Waikato
-- Development History
-- -------------------
-- Date Who By Detail
-- ---- ------ ------
-- 3 Jan 97 kh Original from std Sather distrib.
-- 28 Sep 98 kh Factored out BOOL_STR
include COMPARABLE ;
include BINARY ;
include BOOL_STR ;
create(
oct : OCTET
) : SAME is
-- This routine returns the truth value corresponding to the bit-pattern
-- in oct.
return oct.card = true.card
end ;
build(
cursor : BIN_CURSOR
) : SAME
pre ~void(cursor)
and (cursor.remaining > 0)
post true
is
-- This routine returns the truth value corresponding to the bit-pattern
-- in the next string element of the cursor.
return create(cursor.get_item)
end ;
binstr : BINSTR
pre true
post result.size = 1
is
-- This routine returns a single element binary string which contains
-- the compiler dependent binary representation for self.
return BINSTR::create(OCTET::create(self.card))
end ;
not : SAME
pre true
post result.nand(self)
is
-- This routine returns the logical complement of itself, ie
--
-- if self then
-- return false
-- else
-- return true
-- end
--
-- Built-in to this implementation.
builtin BOOL_NOT
end ;
xnor(
other : SAME
) : SAME is
-- This predicate returns true if and only if self and other have the
-- same logical value. Built-in to this implementation.
builtin BOOL_IS_EQ
end ;
is_eq(
other : SAME
) : SAME is
-- This predicate returns true if and only if self and other are the
-- same logical value. Equivalent to xnor above. Built-in to this
-- implementation.
builtin BOOL_IS_EQ
end ;
is_eq(
other : $OB
) : SAME is
-- This predicate returns true if and only if self and other are the
-- same logical value. Equivalent to xnor above.
typecase other
when SAME then
return is_eq(other)
else
return false
end
end ;
xor(
other : SAME
) : SAME is
-- This predicate returns the result of carrying out an exclusive or
-- operation of self with other. It is the same as '/='!
return self /= other
end ;
nand(
other : SAME
) : SAME is
-- This predicate returns the logical complement of self anded with
-- other.
return ~(self and other)
end ;
nor(
other : SAME
) : SAME is
-- This predicate returns the complement of the result of oring self
-- and other.
return ~(self or other)
end ;
implies(
other : SAME
) : SAME is
-- This predicate returns true if and only if self implies other! This
-- is the same as nand_not!
return not or other
end ;
and_rout(
other : SAME
) : SAME is
-- This predicate is a version of "self and other" which is useful when
-- making bound routines.
return self and other
end ;
or_rout(
other : SAME
) : SAME is
-- This predicate is a version of "self or other" which is useful when
-- making bound routines.
return self or other
end ;
and_not(
other : SAME
) : SAME is
-- This predicate returns the result of slef and the complement of other.
return self and ~other
end ;
or_not(
other : SAME
) : SAME is
-- This predicate returns the result of oring self with the complement
-- of other.
return self or ~other
end ;
nand_not(
other : SAME
) : SAME is
-- This predicate returns the result of self nanded with the complenent
-- of other. This is the same as the complement of self or other.
return not or other
end ;
nor_not(
other : SAME
) : SAME is
-- This predicate returns the result of noring self with the complement
-- of other. This is the same as the complement of self and other.
return not and other
end ;
card : CARD is
-- This routine provides a compiler-dependent result which is either
-- the numeric value 0 or 1 for either true and false or the inverse.
-- It is included for internal as well as occasional external use. Built-in
-- to this implementation.
builtin BOOL_CARD
end ;
end ; -- BOOL