LAD Project: the VALDESC Module


Summary: The VALDESC object serves the following purpose. It represents a set of values. All members of that set must have the same valtype (see the value module for the set of legal valtypes).

A set may be represented by

Either ENUM: an explicitly represented finite set of values

Or BOUNDED: an upper and lower bound over a vector space

Even if a set is bounded, it might perhaps contain only a small finite number of values. In that case, or if the valdesc is ENUM, we say the valdesc is SMALLFINITE.

A valdesc may, optionally, have a default value associated with it.

If a valdesc has type sequence, then the number of elements in the sequence is important, and all set-members denoted by the valdesc must consist of tuples of the same length, with each subcomponent recursively of the same type. An enhancement to this module may eventually relax this to allow variable-length sets of a given type.


valdesc *mk_bounded_valdesc(value *lo,value *hi,[value] *default_val);
default_value may be NULL to indicate no default. If non-null, it must lie between lo and hi inclusive. Args are COPIED in.
valdesc *mk_enumerated_valdesc(sequence *seq,int default_index);
default_index may be -ve to indicate no default value. The [sequence] is COPIED in.
int primtype_of_valdesc(valdesc *vd);
bool valdesc_is_bounded(valdesc *vd);
bool valdesc_is_smallfinite(valdesc *vd);
sequence *mk_sequence_from_valdesc(valdesc *vd);
Precondition: vd must be smallfinite or enumerated
value *valdesc_lo_bound(valdesc *vd);
value *valdesc_hi_bound(valdesc *vd);
Precondition: vd must be bounded for either of the above two. The above two do not return copies, they return POINTERS to user-must-notmodify values stored in vd.
value *valdesc_sequence_size(valdesc *vd);
Precondition: primtype_of_valdesc(vd) equals SEQUENCE_TYPE.

If this function returns -1, that (somewhat obscurely) denotes the fact that the result may have any number of elements.

If this function returns a non-negative number, than that number specifies the size that the valdesc must have.

value *valdesc_default(valdesc *vd);
Returns the default value if it exists. If no default value, returns NULL. Does not return copies: returns POINTER to user-must-notmodify value stored in vd.
void fprintf_valdesc(FILE *s,char *m1,valdesc *vd,char *m2);
void free_valdesc(valdesc *vd);