![]() |
Section 8.2.1.2: |
![]() |
This abstract class defines a state component which is a set of all instantiations of objects of any class sub-typing from this class in addition to the vdm model types used wherever this class name is used. Note that SAME has to be an instantiated class, not an abstract one.
types SAME = object_type ; $BIT_PATTERN = set of object_type state multi : $BIT_PATTERN inv multi_types == forall obj | obj in set multi_types & sub_type($BIT_PATTERN,obj)
NOTE | See the important note about vdm state in the notes on vdm-sl usage in this specification. |
This abstract class models the concept of an object to which no semantics is attached, other than bit-pattern equality. Features are specified to manipulate objects as a whole and to modify individual bits - as well as to convert to a numeric value.
This feature provides an 'empty' object of asize bits all of which have the value clearbit. Where an object with all bits set is desired then this feature and the bit_invert one defined below could be used.
null | : SAME |
null() res : SAME
Since this is a creation operation the pre-condition is vacuously true.
post forall elem | elem in set elems res & elem = clearbit
This feature returns an object all of the bits of which have the value clearbit.
This feature is a potentially narrowing operation in which only the asize bits with the lowest indices in the sequence are placed into the value returned. The bit-pattern is identical to the bit-pattern in self for those eight bits.
octet(self : SAME) res : OCTET
Since the definition of this feature deliberately limits the range of the result, the pre-condition is vacuously true.
post forall index in set inds res & self(index) = res(index)
This feature returns the octet which contains the eight bits of self with the indices 0 to 7.
This feature may be either narrowing or widening, unused bits being ignored if narrowing and additional bits being clearbit if widening.
hextet(self : SAME) res : HEXTET
Since the definition of this feature deliberately limits the range of the result, the pre-condition is vacuously true.
post let bits : seq of BIT be st bits = cases self : (len self > 16) -> forall index in set inds bits self(index) = bits(index), (len self = 16) -> self, (len self < 16) -> self ^ null()(asize + 1, ..., 16) in res = bits
This feature returns the hextet object which contains the lowest sixteen bits of self - extended with clear bits if self does not contain sixteen bits - with the indices 0 to 15.
This feature may be either narrowing or widening, unused bits being ignored if narrowing and additional bits being clearbit if widening.
quad(self : SAME) res : QUADBITS
Since the definition of this feature deliberately limits the range of the result, the pre-condition is vacuously true.
post let bits : seq of BIT be st bits = cases self : (len self > 32) -> forall index in set inds bits self(index) = bits(index), (len self = 32) -> self, (len self < 32) -> self ^ null()(asize + 1, ..., 32) in res = bits
This feature returns the thirty-two bit wide object which contains the lowest thirty-two bits of self - extended with clear bits if self does not contain thirty-two bits - with the indices 0 to 31.
This conversion routine to a cardinal number takes the number of bits required to form a cardinal number (or all bits if less than that number of bits) and returns the number formed.
card(self : SAME) res : CARD
Since the definition of this feature deliberately limits the range of the result, the pre-condition is vacuously true.
Note that the value num_bits is that value defined by the implementation in accordance with Section 4.2 of this specification.
post let bits : seq of BIT be st bits = cases self : (len self > num_bits) -> forall index in set inds bits self(index) = bits(index), (len self = num_bits) -> self, (len self < num_bits) -> self ^ null(asize + 1, ..., num_bits) in res = loc_res
This feature returns the cardinal number formed by taking the bit-pattern of self in the lowest indexed bit positions in the result extended with clear bits to make up the number of bits required in a cardinal number.
This conversion routine to a character uses up to 31 bits from self (see ISO/IEC 10646-1:2000 referred to in Section 2 for the rationale behind this).
char(self : SAME) res : CHAR
pre let maxcode = UNICODE.card(UNICODE.Invalid) in card(self) < maxcode
Note that the definition of the class UNICODE gives asize in terms of octets - as per the international standard.
post let maxbits = UNICODE.asize * OCTET.Octet_Bits - 1 in let bits : seq of BIT = cases self : self(index) = bits(index), (len self = 31) -> self, (len self < 31) -> self ^ null(asize + 1, ..., 31) in let loc_res : CHAR be st loc_res = bits in res = loc_res
This feature returns the bit-pattern of self as an object of type CHAR with which, however, no particular culture-dependent semantics are associated.
This conversion routine to an integer number takes the number of bits required to form a signed integer number (or all bits if less than that number of bits) and returns the number formed.
int(self : SAME) res : INT
Since the definition of this feature deliberately limits the range of the result, the pre-condition is vacuously true.
Note that the value num_bits is that value defined by the implementation in accordance with Section 4.2 of this specification.
post let bits : seq of BIT be st bits = cases self : (len self > num_bits) -> forall idx | idx in set inds bits self(idx) = bits(idx), (len self = num_bits) -> self, (len self < num_bits) -> self ^ null(asize + 1, ..., num_bits) in let loc_res : INT be st loc_res = bits in res = loc_res
This feature returns a signed integer number formed by taking the bit-pattern of self in the lowest indexed bit positions in the result extended with clear bits to make up the number of bits required in an integer number.
Since there is no iterator over individual bits, this routine provides the facility for obtaining individual bit values.
bit(self : SAME, index : CARD) res : BIT
preindex < asize
In the following it should be remembered that Sather indices start at zero while indices for vdm sequences start at one.
post res = bits(index + 1)
This feature returns the value of the bit indexed by the given parameter.
Since there is no iterator over individual bits, this routine provides the facility for setting individual bit values.
alter(self : SAME, index : CARD, val : BIT) res : SAME
preindex < asize
In the following it should be remembered that Sather indices start at zero while indices for vdm sequences start at one.
post forall idx | idx in set {1, ..., index, index + 2, ..., (len bits)} self(idx) = res(idx) and res(index + 1) = val
This feature returns a new object containing the same bit-pattern as self except for the one indexed by the first argument which has been set to val.
This feature enables slices of arbitrary numbers of bits to be extracted as the indicated number of bits at the low bit end of a new object of the same size.
slice(self : SAME, lsb : CARD, count : CARD) res : SAME
prelsb < asize and count > 0 and lsb + count <= asize
In the following it should be remembered that Sather indices start at zero while indices for vdm sequences start at one.
post let loc_bits : seq of BIT be st loc_bits = self in let head ^ wanted ^ tail = loc_bits be st len head = lsb and len wanted = count in let loc_res : seq of BIT = res be st loc_res = wanted ^ null_bits and forall bit : BIT | bit in set dom null_bits & bit = clearbit
This feature returns a new object containing the indicated bit count bits extracted from self starting at the bit indicated (indexing from zero) in the bits 0 to count - 1 of the result.
This feature enables slices of arbitrary numbers of bits to be inserted into self at the indicated position in a new object of the same size - no other bits having been altered.
slice2(self : SAME, lsb : CARD, count : CARD, val : SAME) res : SAME
prelsb < asize and count > 0 and lsb + count <= asize
In the following it should be remembered that Sather indices start at zero while indices for vdm sequences start at one.
post let loc_bits : seq of BIT = self in let head ^ changed ^ tail = loc_bits be st len head = lsb and len changed = count in let loc_val : seq of BIT = val in let val_head ^ rest = loc_val be st len val_head = count in let loc_res : seq of BIT = res be st loc_res = head ^ val_head ^ tail
This feature returns a new object containing the same bit-pattern as self except for the indicated number of bits starting at the given bit index - which have the bit-pattern corresponding to the count sequence of bits from index 0 upwards of val.
This is an indexed version of the similarly named predicate in the pervasive class BIT, returning true if the relevant bit is set.
set(self : SAME,index : CARD) res : BOOL
pre index < asize
post res = (self(idx) = setbit)
This predicate returns true if and only if the indexed bit of self has the value setbit and vice versa.
This is an indexed version of the similarly named predicate in the pervasive class BIT, returning true if the relevant bit is clear.
clear(self : SAME,index : CARD) res : BOOL
pre index < asize
post res = (self(idx) = clearbit)
This predicate returns true if and only if the indexed bit of self has the value clearbit and vice versa.
This feature inverts all of the bits of self, setbits becoming clearbits and vice versa.
bit_invert | : SAME |
bit_invert(self : SAME) res : SAME
Since the domain of the argument and the domain of the result are identical, the pre-condition is vacuously true.
post forall idx | idx in set inds self & ((res(idx) = setbit) and (self(idx) = clearbit)) or ((res(idx) = clearbit) and (self(idx) = setbit))
This feature returns the result of setting each bit of self which has the value setbit to clearbit and each bit of self which has the value clearbit to setbit.
This feature is the classic bit manipulation operation in which each result bit is set only if the corresponding bits of both self and other are set.
bit_and | ( |
other : SAME | |
) : SAME |
bit_and(self : SAME, other : SAME) res : SAME
Since the range of each individual bit result and the domain of the arguments are the same, the pre-condition is vacuously true.
post forall idx | idx in set inds self & ((self(idx) = setbit) and (other(idx) = setbit) and (res(idx) = setbit)) or (res(idx) = clearbit)
This feature returns the result of applying the logical and operation to each individual bit of self and the corresponding bit of other. If both corresponding bits have the value setbit then the corresponding bit of the result will be setbit, otherwise clearbit.
This feature is the classic bit manipulation operation in which each result bit is set if either of the corresponding bits of self and other are set.
bit_or | ( |
other : SAME | |
) : SAME |
bit_or(self : SAME, other : SAME) res : SAME
Since the range of each individual bit result and the domain of the arguments are the same, the pre-condition is vacuously true.
post forall idx | idx in set inds self & (((self(idx) = setbit) or (other(idx) = setbit)) and (res(idx) = setbit)) or (res(idx) = clearbit)
This feature returns the result of applying the logical or operation to each individual bit of self and the corresponding bit of other. If either corresponding bits have the value setbit then the corresponding bit of the result will be setbit, otherwise clearbit.
This feature is the classic bit manipulation operation in which each result bit is set only if the corresponding bit of self and other have different values.
bit_xor | ( |
other : SAME | |
) : SAME |
bit_xor(self : SAME, other : SAME) res : SAME
Since the range of each individual bit result and the domain of the arguments are the same, the pre-condition is vacuously true.
post forall idx | idx in set inds self & ((((self(idx) = setbit) and (other(idx) = clearbit)) or ((self(idx) = clearbit) and (other(idx) = setbit))) and (res(idx) = setbit)) or (res(idx) = clearbit)
This feature returns the result of applying the logical xor operation to each individual bit of self and the corresponding bit of other. If both corresponding bits have different values then the corresponding bit of the result will be setbit, otherwise clearbit.
This feature is a 'logical' left shift of the bits in self.
left(self : SAME, places : CARD) res : SAME
pre places <= asize
post ((places = asize) and (res = null)) or let used = self(places + 1, ..., asize), empty = null(1, ..., places) in res = empty ^ used
This feature returns the object which results from shifting the bit-pattern of self left (towards higher indices) by the number of places indicated, filling vacated positions by the value clearbit.
This feature is a 'logical' right shift of the bits in self.
left(self : SAME, places : CARD) res : SAME
pre places <= asize
post ((places = asize) and (res = null)) or let used = self(places + 1, ..., asize), empty = null(1, ..., places) in res = used ^ empty
This feature returns the object which results from shifting the bit-pattern of self right (towards lower indices) by the number of places indicated, filling vacated positions by the value clearbit.
This feature returns the index of the highest bit of self which has the given value (either setbit or clearbit).
highest(self : SAME, val : BIT) res : CARD
Since the domain of the result is greater than the domain of indices of self the pre-condition is vacuously true.
post forall idx | idx in set inds self & self(idx) <> val and (res = CARD.maxval)) or ((self(res + 1) = val) and ((res = (asize - 1)) or (forall idx | idx in set (inds self)(res + 2, ..., asize) & self(idx) <> val
This feature returns the index of the highest bit which has the value given by the argument - or CARD::maxval if no bit has that value.
This feature returns the index of the highest bit of self which has the value setbit.
Note that the name here has been changed since name overloading is not possible in vdm.
highest2(self : SAME) res : CARD
Since the domain of the result is greater than the domain of indices of self, the pre-condition is vacuously true.
post forall idx in set inds self & self(idx) <> setbit and (res = CARD.maxval)) or ((self(res + 1) = setbit) and ((res = (asize - 1)) or (forall idx in set (inds self)(res + 2, ..., asize) & self(idx) <> setbit
This feature returns the index of the highest bit which has the value setbit - or CARD::maxval if no bit is set.
This feature returns the index of the lowest bit of self which has the given value (either setbit or clearbit).
lowest(self : SAME, val : BIT) res : CARD
Since the domain of the result is greater than the domain of indices of self, the pre-condition is vacuously true.
post forall idx | idx in set inds self & self(idx) <> val and (res = CARD.nil)) or ((self(res + 1) = val) and ((res = 0)) or (forall idx | idx in set (inds self)(1, ..., res) & self(idx) <> val
This feature returns the index of the lowest bit which has the value given by the argument - or CARD::maxval if no bit has that value.
This feature returns the index of the lowest bit of self which has the value setbit.
Note that the name here has been changed since name overloading is not possible in vdm.
lowest2(self : SAME) res : CARD
Since the domain of the result is greater than the domain of indices of self, the pre-condition is vacuously true.
post forall idx | idx in set inds self & self(idx) <> setbit and (res = CARD.maxval)) or ((self(res + 1) = setbit) and ((res = 0) or (forall idx | idx in set (inds self)(1, ..., res) & self(idx) <> setbit
This feature returns the index of the lowest bit which has the value setbit - or CARD::maxval if no bit is set.
This is the first of two features of this name which return a text string representation of the bit-pattern as a sequence of hexa-decimal digits.
hex_str(self : SAME, lib : LIBCHARS) res : STR
Since the domain of self is smaller than the domain for the result and the lib argument is not an optional type, the pre-condition is vacuously true.
post let str_size = (asize + 1) mod 4 in forall idx in set inds res & LIBCHARS.hex_card(lib,res(idx)) = let bitidx = (idx - 1) * 4 + 1 in card(self(bitidx, ..., bitidx + 3))
This feature returns a hexadecimal text string representation of self using the given encoding and repertoire. Each character of the string is a hexadecimal digit for a corresponding sub-sequence of four bits from self. No prefix or suffix of any kind is to be included.
This second string representation feature uses the execution environment default culture, encoding and repertoire to determine the actual representation characters.
Note that the name of this formal signature has been changed since there is no name overloading in vdm.
hex_str2(self : SAME, lib : LIBCHARS) res : STR
Since the domain of self is smaller than the domain for the result and the lib argument is not an optional type, the pre-condition is vacuously true.
post let str_size = (asize + 1) mod 4 in forall idx | idx in set inds res & LIBCHARS.hex_card(LIBCHARS.default,res(idx)) = let bitidx = (idx - 1) * 4 + 1 in card(self(bitidx, ..., bitidx + 3))
This feature returns a hexadecimal text string representation of self using the default encoding and repertoire. Each character of the string is a hexadecimal digit for a corresponding sub-sequence of four bits from self. No prefix or suffix of any kind is to be included.
![]() |
Language Index | ![]() |
Library Index | ![]() |
Binary Index |
Comments or enquiries should be made to
Keith
Hopper. Page last modified: Monday, 28 May 2001. |
![]() |