aval.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 AVAL{T}

immutable class AVAL{T} is -- This class is defined by the Sather language to encapsulateasses which -- include this class must redefine asize to get a non-trivia the concept of -- a value array, the components of which are themselves immutable. -- -- Together with the language defined class BIT this is the fundamental -- class for the construction of objects. All feature names begin with "a" to -- minimize name conflicts when included. -- NOTE NONE OF THE 'acopy' FEATURES ARE IMPLEMENTED. IT HAS NOT YET BEEN -- DECIDED WHETHER OR NOT THEY SHOULD BE!!!!! -- Version 1.2 Jan 00. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 16 Dec 96 kh Original from standard Sather dist. -- 3 Jan 97 kh Converted to use cardinals. -- 10 Jan 00 kh 'acopy' features commented out. const asize : CARD := 0 ; -- The number of elements of type T in self. This must be redefined as -- a constant in the including class. -- NOTE A version of the compiler which compiles to C language source code -- will generate a standard constant, plus a #define with the name of -- the class and _ASIZE appended (eg AVALINT_ASIZE). Apart from this -- special macro this constant is not special to the compiler. aget( index : CARD ) : T pre (index <= (asize - 1)) post result = [index] is -- This routine returns the element of self with the given index builtin AVAL_AGET end ; aset( ind : CARD, val : T ) pre (ind <= (asize - 1)) post self[ind] = val is -- This routine sets the component with the given index set to val builtin AVAL_ASET end ; --acopy_from( -- beg : CARD, -- src : SAME -- ) : SAME -- pre (beg <= (asize - 1)) -- post true -- forall(inds member {0..(beg - 1)} | initial[inds] = self[inds] -- and forall(inds member {beg..(beg + src.size - 1)} : -- inds member(0..(asize - 1)} | -- initial[inds] = src[inds - beg] -- and forall(inds member {(beg + src.size)..(asize - 1)} | -- initial[inds] = self[inds] -- is -- This routine returns a copy of self modified by copying elements from -- src into locations with indices starting at beg -- builtin AVAL_ACOPY_BEG --end ; --acopy_from( -- beg, -- num : CARD, -- src : SAME -- ) : SAME -- pre ~void(self) -- and (beg <= (asize - 1)) -- and (num <= (asize - beg)) -- post true -- forall(inds member {0..(beg - 1)} | initial[inds] = self[inds] -- and forall(inds member {beg..(beg + num)} : -- inds member(0..(asize - 1)} | -- initial[inds] = src[inds - beg] -- and forall(inds member {(beg + num)..(asize - 1)} | -- initial[inds] = self[inds] -- is -- This routine returns a copy of self modified by copying num elements -- from src into locations with indices starting at beg -- builtin AVAL_ACOPY_BEG_NUM --end ; --acopy_from( -- beg, -- num, -- srcbeg : CARD, -- src : SAME -- ) : SAME -- pre (beg <= (asize - 1)) -- and (num <= (asize - beg)) -- and (srcbeg >= src.asize) -- and (num <= (src.asize - srcbeg)) -- post true -- forall(inds member {0..(beg - 1)} | initial[inds] = self[inds] -- and forall(inds member {beg..(beg + num)} : -- inds member(0..(asize - 1)} | -- initial[inds] = src[inds - srcbeg] -- and forall(inds member {(beg + num)..(asize - 1)} | -- initial[inds] = self[inds] -- is -- This routine returns a copy of self modified by copying num elements -- from src starting at index srcbeg into locations with indices starting at -- beg -- builtin AVAL_ACOPY_BEG_NUM_SRCBEG --end ; aind! : CARD pre ~void(self) post result < asize -- or the iter has quit! is -- This iter yields the indices of self in order. builtin AVAL_AINDB end ; aelt! : T pre ~void(self) post true -- [aind!] = result is -- This iter yields each element of self in order builtin AVAL_AELTB end ; aelt!( once beg : CARD ) : T pre ~void(self) and (beg <= (asize - 1)) post true -- [aind! + beg] = result is -- This iter yields each element of self starting at beg builtin AVAL_AELT_BEGB end ; aelt!( once beg, once num : CARD ) : T pre ~void(self) and (beg <= (asize - 1)) and (num <= (asize - beg)) post true -- [aind! + beg] = result is -- This iter yields num successive elements of self starting at index -- beg builtin AVAL_AELT_BEG_NUMB end ; private is_legal_aelts_arg( beg, num : CARD, step : INT ) : BOOL is -- This private predicate returns true if and only if the arguments are -- legal values for the aelt iter below. return beg <= (asize - 1) and (((step > INT::zero) and (num <= ((asize - 1) - beg + step.card)/step.card)) or ((step < INT::zero) and (beg >= (-step).card) and (num <= (beg - (-step).card)/(-step).card))) end ; aelt!( once beg, once num : CARD, once step : INT ) : T pre is_legal_aelts_arg(beg,num,step) post true -- [((aind!.int * step) + beg.int).card] = result is -- This iter yields num elements of self starting at beg and stepping -- by step, which must not be zero builtin AVAL_AELT_BEG_NUM_STEPB end ; end ; -- AVAL{T}