Sather Home Page

Section 8.16.1.6:
$FSTRING

This page contains the definition of the two generic $FSTRING abstract classes.

abstract class $FSTRING{ELT < $IS_EQ} < $FSTRINGS, $FLISTS{ELT}

Inheritance map

$IS_EQ $ELT $HASH $FSTRINGS

Formal Definitions

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 ;

$FSTRING_ELT = set of object_type

state
multi : $FSTRING_ELT
   inv multi_types ==
      forall obj | obj in set multi_types &
         sub_type($FSTRING_ELT,obj)
NOTE See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstract class characterises the concept of all forms of mutable string whether binary, text or other as sequences of the argument class (elements) which must sub-type from $IS_EQ.

This class defines NO features of its own.



abstract class $FSTRING{
ELT < $IS_EQ,
STP < $STRING{ELT},
FSTP < $FSTRING{ELT}
} < $FSTRING{ELT}, $BINARY

Inheritance map

$IS_EQ $ELT $HASH $FSTRINGS $STRINGS $FSTRING{ELT} $STRING{ELT} $BINARY $ELT{ELT}

Formal Definitions

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 ;

$FSTRING_ELT_FTP_STP = set of object_type

state
multi : $FSTRING_ELT_FTP_STP
   inv multi_types ==
      forall obj in set multi_types &
         sub_type($FSTRING_ELT_FTP_STP,obj)
NOTE See the important note about vdm state in the notes on vdm-sl usage in this specification.

This abstract class characterises the concept of mutable non-text strings as sequences of the argument class (elements) which must sub-type from $IS_EQ. The second and third class arguments are the 'corresponding' mutable ($FSTRINGS{ELT}) and immutable (sub-typing from this abstract class) string classes.


acopy

This feature carries out a bit copying operation from the given source into self. Copying stops when the source is exhausted or self is full - whichever occurs first.

acopy (
source : STP
)
Formal Signature
acopy(self : SAME, src : STP)
Pre-condition
pre len src > 0
Post-condition
post let loc_size =
if len src < len self then len src else len self end in self(1, ..., loc_size) = src(1, ..., loc_size)

This routine carries out a bit-pattern copy of the given string into self either until no more bits of self are available or until the source string is exhausted, whichever occurs first.


acopy

This feature carries out a bit copying operation from the given source into self. Copying stops when the source is exhausted or self is full - whichever occurs first.

acopy (
source : SAME
)
Formal Signature
acopy2(self : SAME, src : SAME)
Pre-condition
pre len src > 0
Post-condition
post let loc_size =
            if len src < len self then
               len src
            else
               len self
            end in
      self(1, ..., loc_size) = src(1, ..., loc_size)

This routine carries out a bit-pattern copy of the given string into self either until no more bits of self are available or until the source string is exhausted, whichever occurs first.


acopyn

This feature carries out a bit copying operation from the given source into self. Copying stops when the count is exhausted, the source is exhausted or self is full - whichever occurs first.

acopyn (
source : STP,
count : CARD
)
Formal Signature
acopyn(self : SAME, src : STP, count : CARD)
Pre-condition
pre len src > 0
Post-condition
post let loc_size =
            if (len src < len self
            and len src < count) then
               len src
            elseif len self < count then 
               len self
            else
               count
            end in
      self(1, ..., loc_size) = src(1, ..., loc_size)

This routine carries out a bit-pattern copy of the given string into self either until the count is exhausted, no more bits of self are available or until the source string is exhausted, whichever occurs first.


acopyn

This feature carries out a bit copying operation from the given source into self. Copying stops when either the count is exhausted, the source is exhausted or self is full - whichever occurs first.

acopyn (
source : SAME,
count : CARD
)
Formal Signature
acopyn2(self : SAME, src : SAME, count : CARD)
Pre-condition
pre len src > 0
Post-condition
post let loc_size =
            if (len src < len self
                  and len src < count) then
               len src
            elseif len self < count then 
               len self
            else
               count
            end in
      self(1, ..., loc_size) = src(1, ..., loc_size)

This routine carries out a bit-pattern copy of the given string into self either until count is exhausted, no more bits of self are available or until the source string is exhausted, whichever occurs first.


acopy

This feature carries out a bit copying operation from the given source into self starting at the indicated index position in self. Copying stops when the count is exhausted, the source is exhausted or self is full - whichever occurs first.

acopy (
start_index : CARD
source : STP,
)
Formal Signature
acopy3(self : SAME, start_index : CARD, src : STP)
Pre-condition
pre len src > 0
      and start_index < len self
Post-condition
post let loc_size =
            if len src < (len self - start_index) then
               len src
            else
               len self - start_index
            end in
      self(start_index, ..., loc_size) = src(1, ..., loc_size)

This routine carries out a bit-pattern copy of the given string into self starting at the given index position in self either until no more bits of self are available or until the source string is exhausted, whichever occurs first.


acopy

This feature carries out a bit copying operation from the given source into self starting at the position begin in self. Copying stops when the source is exhausted or self is full - whichever occurs first.

acopy (
start_index : CARD
source : SAME,
)
Formal Signature
acopy4(self : SAME, begin : CARD, src : SAME)
Pre-condition
pre len src > 0
      and begin < len self
Post-condition
post let loc_size =
            if len src < (len self - start_index) then
               len src
            else
               len self - start_index
            end in
      self(start_index, ..., loc_size) = src(1, ..., loc_size)

This routine carries out a bit-pattern copy of the given string into self starting at the specified index position in self either until no more bits of self are available or until the source string is exhausted, whichever occurs first.


Auxiliary Functions

In order to specify the string appending operations below, the following two auxiliary functions need to be specified. The first function makes use of the second recursively to determine the minimum length for the result of some concatenation. This in turn uses the feature is_full inherited from $FLISTS.

functions

new_length : SAME * SAME -> CARD
new_length(self,other) ==
self.loc + extend(self,other)

extend : SAME * SAME -> CARD
extend(head,tail) ==
   if is_full(head) then
      tail.loc
   else
      let new_head = plus(head, hd tail) in
            if tl tail = [] then
               0
            else
               1 + extend(new_head, tl tail)
            end
   end

The extend function uses a short cut so that if the original string should become full then the extra space needed is merely what would be needed by the remainder of the tail - if empty nothing or a recursive call to the function.


plus

This is the first of three features which are provided for appending new elements to the string. It is provided for appending a single elemnt, returning the string having done so. Note that the string returned will be a new string if the buffer of self is full when invoked.

plus (
val : ELT
) : SAME
Formal Signature
plus(self : SAME, val : ELT) res : SAME
Pre-condition

Since neither of the arguments is optional, this pre-condition is vacuously true.

Post-condition

Note that this post-condition makes use of the feature is_full inherited from $FLISTS.

post let res = (if is_full(self) then
            let new_len : CARD be st new_len > loc in
               create(new_len) 
         else
            self
         end) in
      res = self~ ^ [val]>
      and loc(res) = loc(self~) + 1

This feature appends the given element onto the end of the sequence of elements in self, returning an object of the same type. This object returned may be self or it may be a new object.


plus

This version of string concatenation is provided to append a mutable string tp self, returning the string having done so. Note that the string returned will be a new string if the buffer of self is not large enough to contain the string to be appended when invoked.

plus (
val : SAME
) : SAME
Formal Signature
plus2(self : SAME, val : SAME) res : SAME
Pre-condition

Since neither of the arguments is optional, this pre-condition is vacuously true.

Post-condition

Note that this post-condition makes use of the feature is_full inherited from $FLISTS in addition to the auxiliary function new_length specified for this abstraction.

post let res = (let new_len : CARD = new_length(self,other) in
            if new_len > self.loc then
               create(new_len) 
            else
               self
            end) in
      res = self~ ^ val>
      and res.loc = (self~.loc + val.loc)

This feature appends the given element onto the end of the sequence of elements in self, returning an object of the same type. This object returned may be self or it may be a new object.


plus

This version of string concatenation is provided to append a mutable string tp self, returning the string having done so. Note that the string returned will be a new string if the buffer of self is not large enough to contain the string to be appended when invoked.

plus (
val : STP
) : SAME
Formal Signature
plus3(self : SAME, val : STP) res : SAME
Pre-condition

Since neither of the arguments is optional, this pre-condition is vacuously true.

Post-condition

Note that this post-condition makes use of the feature is_full inherited from $FLISTS in addition to the auxiliary function new_length specified for this abstraction.

post let res = (let new_len : CARD = new_length(self,other) in
            if new_len > self.loc then
               create(new_len) 
            else
               self
            end) in
      res = self~ ^ val>
      and res.loc = (self~.loc + val.loc)

This feature appends the given element onto the end of the sequence of elements in self, returning an object of the same type. This object returned may be self or it may be a new object.


Language Index Library Index String Index
Comments or enquiries should be made toKeith Hopper.
Page last modified: Wednesday, 4 April 2001.
Produced with Amaya