types More...
Go to the source code of this file.
Variables | |
ptr_definition * | gamma_table = NULL |
types
These routines implement type encoding using the "Transitive Closure" binary encoding algorithm.
Definition in file types.c.
void all_sorts | ( | ) |
all_sorts
ALL_SORTS() Build a list of all sorts (except nothing) in nothing->parents.
Definition at line 759 of file types.c.
References cons(), first_definition, wl_definition::next, nothing, wl_definition::parents, wl_definition::type_def, and type_it.
void assert_args_not_eval | ( | ptr_node | n | ) |
assert_args_not_eval
n | - ptr_node n |
ASSERT_ARGS_NOT_EVAL(n) Mark all the nodes in the attribute tree N as having unevaluated arguments, if they are functions or predicates.
Definition at line 294 of file types.c.
References wl_node::data, deref_ptr, wl_definition::evaluate_args, FALSE, wl_definition::keyword, wl_node::left, wl_node::right, wl_keyword::symbol, wl_psi_term::type, wl_definition::type_def, type_it, and warningline().
void assert_attributes | ( | ptr_psi_term | t | ) |
assert_attributes
t | - ptr_psi_term t |
ASSERT_ATTRIBUTES(t) T is of the form ':: type(attributes) | pred', the attributes must be appended to T's definition, and will be propagated after ENCODING to T's subtypes.
Definition at line 500 of file types.c.
References add_rule(), wl_psi_term::attr_list, deref_ptr, Errorline(), function_it, get_two_args(), wl_definition::keyword, NULL, predicate_it, wl_keyword::symbol, TRUE, wl_psi_term::type, wl_definition::type_def, type_it, types_modified, and wl_const_3.
void assert_complicated_type | ( | ptr_psi_term | t | ) |
assert_complicated_type
t | - ptr_psi_term t |
ASSERT_COMPLICATED_TYPE This deals with all the type declarations of the form:
a(attr) <| b. % (a<|b) a(attr) <| b | pred.
a(attr) <| {b;c;d}. % (a<|b, a<|c, a<|d) a(attr) <| {b;c;d} | pred.
a := b(attr). % (a<|b) a := b(attr) | pred.
a := {b(attr1);c(attr2);d(attr3)}. % (b<|a,c<|a,d<|a) a := {b(attr1);c(attr2);d(attr3)} | pred.
Definition at line 405 of file types.c.
References add_rule(), assert_less(), assert_ok, wl_psi_term::attr_list, deref_ptr, disjunction, equ_tok, Errorline(), FALSE, get_two_args(), wl_definition::keyword, nil, NULL, wl_keyword::symbol, TRUE, wl_psi_term::type, type_it, and warningline().
void assert_delay_check | ( | ptr_node | n | ) |
assert_delay_check
n | - ptr_node n |
ASSERT_DELAY_CHECK(n) Assert that the types in the attribute tree N will have their properties checked only when they have attributes. If they have no attributes, then no properties are checked.
Definition at line 326 of file types.c.
References wl_definition::always_check, wl_node::data, deref_ptr, FALSE, wl_node::left, wl_node::right, and wl_psi_term::type.
long assert_less | ( | ptr_psi_term | t1, |
ptr_psi_term | t2 | ||
) |
assert_less
t1 | - ptr_psi_term t1 |
t2 | - ptr_psi_term t2 |
ASSERT_LESS(t1,t2) Assert that T1 <| T2. Return false if some sort of error occurred.
Definition at line 200 of file types.c.
References deref_ptr, Errorline(), FALSE, function_it, wl_definition::keyword, make_type_link(), predicate_it, redefine(), wl_keyword::symbol, top, TRUE, wl_psi_term::type, wl_definition::type_def, type_it, types_modified, and wl_psi_term::value_3.
void assert_protected | ( | ptr_node | n, |
long | prot | ||
) |
assert_protected
n | - ptr_node n |
prot | - long prot |
ASSERT_PROTECTED(n,prot) Mark all the nodes in the attribute tree N with protect flag prot.
Definition at line 255 of file types.c.
References wl_node::data, wl_definition::date, deref_ptr, wl_definition::keyword, wl_node::left, MAX_BUILT_INS, wl_definition::protected, wl_node::right, wl_definition::rule, wl_keyword::symbol, wl_psi_term::type, wl_definition::type_def, type_it, and warningline().
void assert_type | ( | ptr_psi_term | t | ) |
assert_type
t | - ptr_psi_term t |
ASSERT_TYPE(t) T is the psi_term <|(type1,type2). Add that to the type-definitions.
Definition at line 372 of file types.c.
References assert_less(), assert_ok, wl_psi_term::attr_list, Errorline(), get_two_args(), and NULL.
long bit_length | ( | ptr_int_list | c | ) |
bit_length
c | - ptr_int_list c |
BIT_LENGTH(c) Returns the number of bits needed to code C. That is the rank of the first non NULL bit of C.
Examples: C= 1001001000 result=7 C= 10000 result=1 C= 0000000 result=0
Definition at line 1753 of file types.c.
References INT_SIZE, wl_int_list::next, and wl_int_list::value_1.
void clear_already_loaded | ( | ptr_node | n | ) |
clear_already_loaded
n | - ptr_node n |
CLEAR_ALREADY_LOADED() Clear the 'already_loaded' flags in all symbol table entries. Done at each top level prompt.
Definition at line 351 of file types.c.
References wl_definition::already_loaded, wl_node::data, FALSE, wl_node::left, and wl_node::right.
void clear_coding | ( | ) |
clear_coding
CLEAR_CODING() Clear the bit-vector coding of the sorts.
Definition at line 727 of file types.c.
References wl_definition::code, first_definition, wl_definition::next, NOT_CODED, wl_definition::type_def, and type_it.
ptr_int_list cons | ( | GENERIC | v, |
ptr_int_list | l | ||
) |
cons
v | - GENERIC v |
l | - ptr_int_list l |
CONS(value,list) Returns the list [VALUE|LIST]
Definition at line 179 of file types.c.
References HEAP_ALLOC, wl_int_list::next, and wl_int_list::value_1.
ptr_int_list copyTypeCode | ( | ptr_int_list | u | ) |
copyTypeCode
u | - ptr_int_list u |
copyTypeCode(code) returns copy of code on the heap
Definition at line 808 of file types.c.
References HEAP_ALLOC, wl_int_list::next, NULL, or_codes(), and wl_int_list::value_1.
long count_sorts | ( | long | c0 | ) |
count_sorts
c0 | - long c0 |
COUNT_SORTS(c) Count the number of sorts in the symbol table T. Overestimates in the module version. RM: Jan 21 1993 No longer !! RM: Feb 3 1993
Definition at line 710 of file types.c.
References first_definition, wl_definition::next, wl_definition::type_def, and type_it.
ptr_int_list decode | ( | ptr_int_list | c | ) |
decode
c | - ptr_int_list c |
DECODE(c) Returns a list of the symbol names which make up the disjunction whose code is C.
Definition at line 1784 of file types.c.
References bit_length(), wl_definition::code, cons(), wl_int_list::next, NULL, STACK_ALLOC, and wl_int_list::value_1.
void encode_types | ( | ) |
encode_types
ENCODE_TYPES() This routine performs type-coding using transitive closure. First any previous coding is undone. Then a new encryption is performed.
Some of these routines loop indefinitely if there is a circular type definition (an error should be reported but it isn't implemented (but it's quite easy to do)).
Definition at line 1091 of file types.c.
References all_sorts(), built_in, wl_definition::children, clear_coding(), wl_definition::code, cons(), count_sorts(), equalize_codes(), Errorline(), FALSE, heap_alloc(), inherit_always_check(), integer, wl_definition::keyword, least_sorts(), lf_false, lf_true, make_sys_type_links(), make_type_link(), wl_int_list::next, NOT_CODED, nothing, NULL, or_codes(), overlap_type(), wl_definition::parents, perr(), propagate_definitions(), quoted_string, real, wl_keyword::symbol, top, traceline(), TRUE, two_to_the(), type_count, type_cyclicity(), types_done, types_modified, and wl_int_list::value_1.
void equalize_codes | ( | int | len | ) |
equalize_codes
len | - int len |
EQUALIZE_CODES(w) Make sure all codes are w words long, by increasing the length of the shorter ones. This simplifies greatly the bitvector manipulation routines. This operation should be done after encoding. For correct operation, w>=maximum number of words used for a code.
Definition at line 859 of file types.c.
References assert, wl_definition::code, first_definition, HEAP_ALLOC, wl_int_list::next, wl_definition::next, NULL, wl_definition::type_def, and type_it.
void find_adults | ( | ) |
find_adults
FIND_ADULTS() Returns the list of all the maximal types (apart from top) in the symbol table. That is, types which have no parents. This routine modifies the global variable 'adults'.
Definition at line 549 of file types.c.
References adults, first_definition, HEAP_ALLOC, wl_int_list::next, wl_definition::next, NULL, wl_definition::parents, wl_definition::type_def, type_it, and wl_int_list::value_1.
long glb | ( | ptr_definition | t1, |
ptr_definition | t2, | ||
ptr_definition * | t3, | ||
ptr_int_list * | c3 | ||
) |
glb
t1 | - ptr_definition t1 |
t2 | - ptr_definition t2 |
t3 | - ptr_definition *t3 |
c3 | - ptr_int_list *c3 |
GLB(t1,t2,t3) This function returns the Greatest Lower Bound of two types T1 and T2 in T3.
T3 = T1 /\ T2
If T3 is not a simple type then C3 is its code, and T3=NULL.
It also does some type comparing, and returns
0 if T3 = bottom 1 if T1 = T2 2 if T1 <| T2 ( T3 = T1 ) 3 if T1 |> T2 ( T3 = T2 ) 4 otherwise ( T3 strictly <| T1 and T3 strictly <| T2 )
These results are used for knowing when to inherit properties or release residuations. The t3 field is NULL iff a new type is needed to represent the result.
RM: May 7 1993 Fixed bug in when multiple word code
Definition at line 1481 of file types.c.
References wl_definition::code, FALSE, wl_int_list::next, NOT_CODED, nothing, NULL, STACK_ALLOC, top, TRUE, and wl_int_list::value_1.
glb_code
f1 | - long f1 |
c1 | - GENERIC c1 |
f2 | - long f2 |
c2 | - GENERIC c2 |
f3 | - long *f3 |
c3 | - GENERIC *c3 |
GLB_CODE(f1,c1,f2,c2,f3,c3) (21.9) Calculate glb of two type codes C1 and C2, put result in C3. Return a result value (see comments of glb(..)).
Sorts are stored as a 'Variant Record': f1==TRUE: c1 is a ptr_definition (an interned symbol). f1==FALSE: c1 is a ptr_int_list (a sort code). The result (f3,c3) is also in this format. This is needed to correctly handle psi-terms that don't have a sort code (for example, functions, predicates, and singleton sorts). The routine handles a bunch of special cases that keep f3==TRUE. Other than that, it is almost a replica of the inner loop of glb(..).
Definition at line 1351 of file types.c.
References wl_definition::code, FALSE, wl_int_list::next, NOT_CODED, NULL, STACK_ALLOC, top, TRUE, and wl_int_list::value_1.
glb_value
result | - long result |
f | - long f |
c | - GENERIC c |
value1 | - GENERIC value1 |
value2 | - GENERIC value2 |
value | - GENERIC *value |
GLB_VALUE(result,f,c,value1,value2,value) Do the comparison of the value fields of two psi-terms. This is used in conjunction with glb_code to correctly implement completeness for disequality for psi-terms with non-NULL value fields. This must be preceded by a call to glb_code, since it uses the outputs of that call.
result result of preceding glb_code call (non-NULL iff non-empty intersec.) f,c sort intersection (sortflag & code) of preceding glb_code call. value1 value field of first psi-term. value2 value field of second psi-term. value output value field (if any).
Definition at line 1290 of file types.c.
References wl_definition::code, FALSE, NULL, quoted_string, REAL, real, sub_CodeType(), and TRUE.
void inherit_always_check | ( | ) |
inherit_always_check
INHERIT_ALWAYS_CHECK() The 'always_check' flag, if false, should be propagated to a sort's children. This routine does a closure on this propagation operation for all declared sorts.
Definition at line 1068 of file types.c.
References FALSE, and one_pass_always_check().
void insert_own_prop | ( | ptr_definition | d | ) |
insert_own_prop
d | - ptr_definition d |
INSERT_OWN_PROP(definition) Append a type's "rules" (i.e. its own attr. & constr.) to its property list. The property list also contains the type's code. A type's attributes and constraints are stored in the 'rule' field of the definition.
Definition at line 575 of file types.c.
References wl_pair_list::aaaa_2, wl_pair_list::bbbb_2, children, FALSE, HEAP_ALLOC, wl_int_list::next, wl_definition::next, wl_pair_list::next, NULL, wl_definition::properties, wl_definition::rule, TRUE, and wl_int_list::value_1.
void insert_prop | ( | ptr_definition | d, |
ptr_triple_list | prop | ||
) |
insert_prop
d | - ptr_definition d |
prop | - ptr_triple_list prop |
INSERT_PROP(definition,prop) Append the properties to the definition if they aren't already present.
Definition at line 620 of file types.c.
References wl_triple_list::aaaa_4, wl_triple_list::bbbb_4, wl_triple_list::cccc_4, children, FALSE, HEAP_ALLOC, wl_int_list::next, wl_definition::next, wl_triple_list::next, NULL, wl_definition::properties, TRUE, and wl_int_list::value_1.
void least_sorts | ( | ) |
void least_sorts()
LEAST_SORTS() Build the list of terminals (i.e. sorts with no children) in nothing->parents.
Definition at line 743 of file types.c.
References wl_definition::children, cons(), first_definition, wl_definition::next, nothing, NULL, wl_definition::parents, wl_definition::type_def, and type_it.
void make_type_link | ( | ptr_definition | t1, |
ptr_definition | t2 | ||
) |
make_type_link
t1 | - ptr_definition t1 |
t2 | - ptr_definition t2 |
MAKE_TYPE_LINK(t1,t2) Assert that T1 <| T2, this is used to initialise the built_in type relations so that nothing really horrible happens if the user modifies built-in types such as INT or LIST. This routine also makes sure that top has no links.
Definition at line 901 of file types.c.
References wl_definition::children, cons(), wl_definition::parents, top, and type_member().
long matches | ( | ptr_definition | t1, |
ptr_definition | t2, | ||
long * | smaller | ||
) |
matches
t1 | - ptr_definition t1 |
t2 | - ptr_definition t2 |
smaller | - long *smaller |
MATCHES(t1,t2,s) Returns TRUE if GLB(t1,t2)!=bottom. Sets S to TRUE if type T1 is <| than type T2, that is if T1 matches T2.
Definition at line 1666 of file types.c.
References wl_definition::code, FALSE, wl_int_list::next, NOT_CODED, top, TRUE, and wl_int_list::value_1.
void one_pass_always_check | ( | long * | ch | ) |
one_pass_always_check
ch | - long *ch ONE_PASS_ALWAYS_CHECK(ch)Go through the symbol table & propagate all FALSE always_check flags of all sorts to their children. Return a TRUE flag if a change was made somewhere (for the closure calculation). |
Definition at line 1049 of file types.c.
References wl_definition::always_check, first_definition, wl_definition::next, propagate_always_check(), wl_definition::type_def, and type_it.
void or_codes | ( | ptr_int_list | u, |
ptr_int_list | v | ||
) |
or_codes
u | - ptr_int_list u |
v | - ptr_int_list v |
OR_CODES(code1,code2) Performs CODE1 := CODE1 or CODE2, 'or' being the binary logical operator on bits.
Definition at line 831 of file types.c.
References HEAP_ALLOC, wl_int_list::next, NULL, and wl_int_list::value_1.
long overlap_type | ( | ptr_definition | t1, |
ptr_definition | t2 | ||
) |
overlap_type
t1 | - ptr_definition t1 |
t2 | - ptr_definition t2 |
OVERLAP_TYPE(t1,t2) This function returns TRUE if GLB(t1,t2)!=bottom. This is essentially the same thing as GLB, only it's faster 'cause we don't care about the resulting code.
Definition at line 1579 of file types.c.
References wl_definition::code, FALSE, wl_int_list::next, NOT_CODED, top, TRUE, and wl_int_list::value_1.
void perr_sort | ( | ptr_definition | d | ) |
perr_sort
d | - ptr_definition d |
Definition at line 933 of file types.c.
References wl_definition::keyword, perr_s(), and wl_keyword::symbol.
void perr_sort_cycle | ( | ptr_int_list | anc | ) |
perr_sort_cycle
anc | - ptr_int_list anc |
Definition at line 959 of file types.c.
References perr(), perr_sort(), perr_sort_list(), and wl_int_list::value_1.
void perr_sort_list | ( | ptr_int_list | anc | ) |
perr_sort_list
anc | - ptr_int_list anc |
Definition at line 944 of file types.c.
References wl_int_list::next, perr(), perr_sort(), and wl_int_list::value_1.
void print_codes | ( | ) |
print_codes
PRINT_CODES() Print all the codes.
Definition at line 1256 of file types.c.
References outputline(), and type_count.
void print_def_type | ( | def_type | t | ) |
print_def_type
t | - def_type t |
PRINT_DEF_TYPE(t) This prints type T to stderr, where T=predicate, function or type.
Definition at line 24 of file types.c.
References function_it, global_it, perr(), predicate_it, and type_it.
void propagate_always_check | ( | ptr_definition | d, |
long * | ch | ||
) |
propagate_always_check
d | - ptr_definition d |
ch | - long *ch |
PROPAGATE_ALWAYS_CHECK(d,ch) Recursively set the always_check flag to 'FALSE' for all d's children. Continue until encountering only 'FALSE' values. Return a TRUE flag if a change was made somewhere (for the closure calculation).
Definition at line 1022 of file types.c.
References wl_definition::always_check, wl_definition::children, FALSE, wl_int_list::next, TRUE, and wl_int_list::value_1.
void propagate_definitions | ( | ) |
propagate_definitions
PROPAGATE_DEFINITIONS() This routine propagates the definition (attributes,predicates) of a type to all its sons.
Definition at line 662 of file types.c.
References adults, wl_definition::children, children, find_adults(), insert_own_prop(), insert_prop(), wl_int_list::next, NULL, wl_definition::properties, and wl_int_list::value_1.
long redefine | ( | ptr_psi_term | t | ) |
redefine
t | - ptr_psi_term t |
REDEFINE(t) This decides whether a definition (a sort, function, or predicate) may be extended or not.
Definition at line 104 of file types.c.
References wl_definition::children, wl_keyword::combined_name, wl_definition::date, deref_ptr, Errorline(), FALSE, file_date, wl_definition::keyword, MAX_BUILT_INS, wl_definition::parents, wl_definition::protected, remove_cycles(), wl_definition::rule, wl_keyword::symbol, TRUE, wl_psi_term::type, wl_definition::type_def, type_it, undef_it, warningflag, warningline(), and yes_or_no().
void remove_cycles | ( | ptr_definition | d, |
ptr_int_list * | dl | ||
) |
remove_cycles
d | - ptr_definition d |
dl | - ptr_int_list *dl |
Remove references to d in d's children or parents
Definition at line 85 of file types.c.
References wl_int_list::next.
long strict_matches | ( | ptr_psi_term | t1, |
ptr_psi_term | t2, | ||
long * | smaller | ||
) |
strict_matches
t1 | - ptr_psi_term t1 |
t2 | - ptr_psi_term t2 |
smaller | - long *smaller |
STRICT_MATCHES(t1,t2,s) Almost the same as matches, except that S is set to TRUE only if the type of t1 is strictly less than the type of t2. Because of the implementation of ints, reals, strings, and lists, this has to take the value field into account, and thus must be passed the whole psi-term.
Definition at line 1713 of file types.c.
References FALSE, matches(), NULL, TRUE, wl_psi_term::type, and wl_psi_term::value_3.
long sub_CodeType | ( | ptr_int_list | c1, |
ptr_int_list | c2 | ||
) |
sub_CodeType
c1 | - ptr_int_list c1 |
c2 | - ptr_int_list c2 |
SUB_CodeType(c1,c2) Return TRUE if code C1 is <| than type C2, that is if type represented by code C1 matches type represented by C2.
We already know that t1 and t2 are not top.
Definition at line 1618 of file types.c.
References FALSE, wl_int_list::next, NOT_CODED, TRUE, and wl_int_list::value_1.
long sub_type | ( | ptr_definition | t1, |
ptr_definition | t2 | ||
) |
sub_type
t1 | - ptr_definition t1 |
t2 | - ptr_definition t2 |
SUB_TYPE(t1,t2) Return TRUE if type T1 is <| than type T2, that is if T1 matches T2.
Definition at line 1642 of file types.c.
References wl_definition::code, FALSE, sub_CodeType(), top, and TRUE.
ptr_int_list two_to_the | ( | long | p | ) |
two_to_the
p | - long p |
TWO_TO_THE(p) Return the code worth 2^p.
Definition at line 776 of file types.c.
References HEAP_ALLOC, INT_SIZE, wl_int_list::next, NULL, and wl_int_list::value_1.
long type_cyclicity | ( | ptr_definition | d, |
ptr_int_list | anc | ||
) |
type_cyclicity
d | - ptr_definition d |
anc | - ptr_int_list anc |
TYPE_CYCLICITY(d,anc) Check cyclicity of type hierarchy. If cyclic, return a TRUE error condition and print an error message with a cycle.
Definition at line 977 of file types.c.
References wl_definition::code, Errorline(), exit_life(), FALSE, wl_int_list::next, NOT_CODED, wl_definition::parents, perr(), perr_sort_cycle(), TRUE, type_member(), and wl_int_list::value_1.
long type_member | ( | ptr_definition | t, |
ptr_int_list | tlst | ||
) |
type_member
t | - ptr_definition t |
tlst | - ptr_int_list tlst |
TYPE_MEMBER(t,tlst) Return TRUE iff type t is in the list tlst.
Definition at line 918 of file types.c.
References FALSE, wl_int_list::next, TRUE, and wl_int_list::value_1.
long yes_or_no | ( | ) |
yes_or_no
Confirm an important change
Definition at line 50 of file types.c.
References EOLN, input_state, open_input_file(), perr(), prompt, read_char(), and restore_state().
ptr_definition* gamma_table = NULL |